Commit 67647154c1

Mitchell Hashimoto <mitchell.hashimoto@gmail.com>
2022-03-15 04:00:17
stage2: apply fix for #11165 to codegen.zig for native backends
Co-authored-by: Cody Tapscott <topolarity@tapscott.me>
1 parent a859f94
Changed files (2)
src
test
behavior
src/codegen.zig
@@ -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,
test/behavior/bugs/11165.zig
@@ -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;
 }