authorgravatar for mitchell.hashimoto@gmail.comMitchell Hashimoto <mitchell.hashimoto@gmail.com> 2022-03-14 20:00:17-07:00
committergravatar for mitchell.hashimoto@gmail.comMitchell Hashimoto <mitchell.hashimoto@gmail.com> 2022-03-14 20:00:17-07:00
log67647154c1c307dcf34413d013e6cd4a1df81945
tree1db0b6fe61fe5dc9c261ca6551115cfd4f782b68
parenta859f94644cb362d84d3f9d72bc02b00a75fc32a
signaturelock-open Commit is signed but in an unrecognized format.

stage2: apply fix for #11165 to codegen.zig for native backends

Co-authored-by: Cody Tapscott <topolarity@tapscott.me>

2 files changed, 15 insertions(+), 20 deletions(-)

src/codegen.zig+7-18
...@@ -207,29 +207,18 @@ pub fn generateSymbol(...@@ -207,29 +207,18 @@ pub fn generateSymbol(
207 .bytes => {207 .bytes => {
208 // TODO populate .debug_info for the array208 // TODO populate .debug_info for the array
209 const payload = typed_value.val.castTag(.bytes).?;209 const payload = typed_value.val.castTag(.bytes).?;
210 if (typed_value.ty.sentinel()) |sentinel| {210 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());
211 try code.ensureUnusedCapacity(payload.data.len + 1);211 // The bytes payload already includes the sentinel, if any
212 code.appendSliceAssumeCapacity(payload.data);212 try code.ensureUnusedCapacity(len);
213 switch (try generateSymbol(bin_file, src_loc, .{213 code.appendSliceAssumeCapacity(payload.data[0..len]);
214 .ty = typed_value.ty.elemType(),214 return Result{ .appended = {} };
215 .val = sentinel,
216 }, code, debug_output, reloc_info)) {
217 .appended => return Result{ .appended = {} },
218 .externally_managed => |slice| {
219 code.appendSliceAssumeCapacity(slice);
220 return Result{ .appended = {} };
221 },
222 .fail => |em| return Result{ .fail = em },
223 }
224 } else {
225 return Result{ .externally_managed = payload.data };
226 }
227 },215 },
228 .aggregate => {216 .aggregate => {
229 // TODO populate .debug_info for the array217 // TODO populate .debug_info for the array
230 const elem_vals = typed_value.val.castTag(.aggregate).?.data;218 const elem_vals = typed_value.val.castTag(.aggregate).?.data;
231 const elem_ty = typed_value.ty.elemType();219 const elem_ty = typed_value.ty.elemType();
232 for (elem_vals) |elem_val| {220 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());
221 for (elem_vals[0..len]) |elem_val| {
233 switch (try generateSymbol(bin_file, src_loc, .{222 switch (try generateSymbol(bin_file, src_loc, .{
234 .ty = elem_ty,223 .ty = elem_ty,
235 .val = elem_val,224 .val = elem_val,
test/behavior/bugs/11165.zig+8-2
...@@ -1,6 +1,9 @@...@@ -1,6 +1,9 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
22
3test "bytes" {3test "bytes" {
4 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
5 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
6
4 const S = struct {7 const S = struct {
5 a: u32,8 a: u32,
6 c: [5]u8,9 c: [5]u8,
...@@ -16,11 +19,14 @@ test "bytes" {...@@ -16,11 +19,14 @@ test "bytes" {
16 };19 };
17 _ = s_1;20 _ = s_1;
1821
19 const u_2 = U{ .s = s_1 };22 var u_2 = U{ .s = s_1 };
20 _ = u_2;23 _ = u_2;
21}24}
2225
23test "aggregate" {26test "aggregate" {
27 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
28 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
29
24 const S = struct {30 const S = struct {
25 a: u32,31 a: u32,
26 c: [5]u8,32 c: [5]u8,
...@@ -37,6 +43,6 @@ test "aggregate" {...@@ -37,6 +43,6 @@ test "aggregate" {
37 };43 };
38 _ = s_1;44 _ = s_1;
3945
40 const u_2 = U{ .s = s_1 };46 var u_2 = U{ .s = s_1 };
41 _ = u_2;47 _ = u_2;
42}48}