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

Co-authored-by: Cody Tapscott <topolarity@tapscott.me>
This commit is contained in:
Mitchell Hashimoto 2022-03-14 20:00:17 -07:00
parent a859f94644
commit 67647154c1
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
2 changed files with 15 additions and 20 deletions

View File

@ -207,29 +207,18 @@ pub fn generateSymbol(
.bytes => {
// TODO populate .debug_info for the array
const payload = typed_value.val.castTag(.bytes).?;
if (typed_value.ty.sentinel()) |sentinel| {
try code.ensureUnusedCapacity(payload.data.len + 1);
code.appendSliceAssumeCapacity(payload.data);
switch (try generateSymbol(bin_file, src_loc, .{
.ty = typed_value.ty.elemType(),
.val = sentinel,
}, code, debug_output, reloc_info)) {
.appended => return Result{ .appended = {} },
.externally_managed => |slice| {
code.appendSliceAssumeCapacity(slice);
return Result{ .appended = {} };
},
.fail => |em| return Result{ .fail = em },
}
} else {
return Result{ .externally_managed = payload.data };
}
const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());
// The bytes payload already includes the sentinel, if any
try code.ensureUnusedCapacity(len);
code.appendSliceAssumeCapacity(payload.data[0..len]);
return Result{ .appended = {} };
},
.aggregate => {
// TODO populate .debug_info for the array
const elem_vals = typed_value.val.castTag(.aggregate).?.data;
const elem_ty = typed_value.ty.elemType();
for (elem_vals) |elem_val| {
const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());
for (elem_vals[0..len]) |elem_val| {
switch (try generateSymbol(bin_file, src_loc, .{
.ty = elem_ty,
.val = elem_val,

View File

@ -1,6 +1,9 @@
const builtin = @import("builtin");
test "bytes" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
const S = struct {
a: u32,
c: [5]u8,
@ -16,11 +19,14 @@ test "bytes" {
};
_ = s_1;
const u_2 = U{ .s = s_1 };
var u_2 = U{ .s = s_1 };
_ = u_2;
}
test "aggregate" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
const S = struct {
a: u32,
c: [5]u8,
@ -37,6 +43,6 @@ test "aggregate" {
};
_ = s_1;
const u_2 = U{ .s = s_1 };
var u_2 = U{ .s = s_1 };
_ = u_2;
}