diff options
| author | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2022-03-14 20:00:17 -0700 |
|---|---|---|
| committer | Mitchell Hashimoto <mitchell.hashimoto@gmail.com> | 2022-03-14 20:00:17 -0700 |
| commit | 67647154c1c307dcf34413d013e6cd4a1df81945 (patch) | |
| tree | 1db0b6fe61fe5dc9c261ca6551115cfd4f782b68 /src | |
| parent | a859f94644cb362d84d3f9d72bc02b00a75fc32a (diff) | |
| download | zig-67647154c1c307dcf34413d013e6cd4a1df81945.tar.gz zig-67647154c1c307dcf34413d013e6cd4a1df81945.zip | |
stage2: apply fix for #11165 to codegen.zig for native backends
Co-authored-by: Cody Tapscott <topolarity@tapscott.me>
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen.zig | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 1a30738b07..6d5e140dca 100644 --- a/src/codegen.zig +++ b/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, |
