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(
207207 .bytes => {
208208 // TODO populate .debug_info for the array
209209 const payload = typed_value.val.castTag(.bytes).?;
210 if (typed_value.ty.sentinel()) |sentinel| {
211 try code.ensureUnusedCapacity(payload.data.len + 1);
212 code.appendSliceAssumeCapacity(payload.data);
213 switch (try generateSymbol(bin_file, src_loc, .{
214 .ty = typed_value.ty.elemType(),
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 }
210 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());
211 // The bytes payload already includes the sentinel, if any
212 try code.ensureUnusedCapacity(len);
213 code.appendSliceAssumeCapacity(payload.data[0..len]);
214 return Result{ .appended = {} };
227215 },
228216 .aggregate => {
229217 // TODO populate .debug_info for the array
230218 const elem_vals = typed_value.val.castTag(.aggregate).?.data;
231219 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| {
233222 switch (try generateSymbol(bin_file, src_loc, .{
234223 .ty = elem_ty,
235224 .val = elem_val,
test/behavior/bugs/11165.zig+8-2
......@@ -1,6 +1,9 @@
11const builtin = @import("builtin");
22
33test "bytes" {
4 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
5 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
6
47 const S = struct {
58 a: u32,
69 c: [5]u8,
......@@ -16,11 +19,14 @@ test "bytes" {
1619 };
1720 _ = s_1;
1821
19 const u_2 = U{ .s = s_1 };
22 var u_2 = U{ .s = s_1 };
2023 _ = u_2;
2124}
2225
2326test "aggregate" {
27 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
28 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
29
2430 const S = struct {
2531 a: u32,
2632 c: [5]u8,
......@@ -37,6 +43,6 @@ test "aggregate" {
3743 };
3844 _ = s_1;
3945
40 const u_2 = U{ .s = s_1 };
46 var u_2 = U{ .s = s_1 };
4147 _ = u_2;
4248}