authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-02-08 20:33:45+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-02-09 10:28:48+01:00
loge5ce87f1b198bfcb022e9ea91f2a9a58b1b75026
tree19edf20a27751a4c96a2c5a63f9328de1923bd52
parent4d1e5ef730630badf92a613cdc57a42d2321df12

stage2: handle decl ref to void types

Fixes behavior test 1914

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

src/codegen.zig+6-11
......@@ -487,19 +487,14 @@ fn lowerDeclRef(
487487 return Result{ .appended = {} };
488488 }
489489
490 const target = bin_file.options.target;
491 const ptr_width = target.cpu.arch.ptrBitWidth();
490492 const is_fn_body = decl.ty.zigTypeTag() == .Fn;
491493 if (!is_fn_body and !decl.ty.hasRuntimeBits()) {
492 return Result{
493 .fail = try ErrorMsg.create(
494 bin_file.allocator,
495 src_loc,
496 "TODO handle void types when lowering decl ref",
497 .{},
498 ),
499 };
494 try code.writer().writeByteNTimes(0xaa, @divExact(ptr_width, 8));
495 return Result{ .appended = {} };
500496 }
501497
502 if (decl.analysis != .complete) return error.AnalysisFail;
503498 decl.markAlive();
504499 const vaddr = vaddr: {
505500 if (bin_file.cast(link.File.MachO)) |macho_file| {
......@@ -510,8 +505,8 @@ fn lowerDeclRef(
510505 break :vaddr bin_file.getDeclVAddr(decl);
511506 };
512507
513 const endian = bin_file.options.target.cpu.arch.endian();
514 switch (bin_file.options.target.cpu.arch.ptrBitWidth()) {
508 const endian = target.cpu.arch.endian();
509 switch (ptr_width) {
515510 16 => mem.writeInt(u16, try code.addManyAsArray(2), @intCast(u16, vaddr), endian),
516511 32 => mem.writeInt(u32, try code.addManyAsArray(4), @intCast(u32, vaddr), endian),
517512 64 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian),
test/behavior/bugs/1914.zig-4
......@@ -13,8 +13,6 @@ const a = A{ .b_list_pointer = &b_list };
1313
1414test "segfault bug" {
1515 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
16 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
17 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1816 const assert = std.debug.assert;
1917 const obj = B{ .a_pointer = &a };
2018 assert(obj.a_pointer == &a); // this makes zig crash
......@@ -31,8 +29,6 @@ pub const B2 = struct {
3129var b_value = B2{ .pointer_array = &[_]*A2{} };
3230
3331test "basic stuff" {
34 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
35 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
3632 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
3733 std.debug.assert(&b_value == &b_value);
3834}