zig icon indicating copy to clipboard operation
zig copied to clipboard

zig build test hangs in Sema beginning in 0.12.0-dev.3676+21a6a1b0f

Open scheibo opened this issue 10 months ago • 7 comments

Zig Version

0.12.0-dev.3676+21a6a1b0f

Steps to Reproduce and Observed Behavior

$ git clone https://github.com/pkmn/engine.git
<snip>
$ cd engine
$ git reset --hard 047d6e71f60dbbf8e645e5de491076cc3cdf3ea9
$ zig version
0.12.0-dev.3676+21a6a1b0f
$ zig build -Dlog -Dchance -Dcalc test
steps [8/17] zig test Debug native... Semantic Analysis [3862] ...

hangs indefinitely. also repros on 0.12 and the latest 0.13 nightly (0.13.0-dev.8+c352845e8)

Expected Behavior

works in 0.12.0-dev.3667+77abd3a96

$ zig version
0.12.0-dev.3667+77abd3a96
$ zig build -Dlog -Dchance -Dcalc test

(no output because tests successfully pass)

scheibo avatar Apr 22 '24 03:04 scheibo

Crashes during a comptime bitcast because 16 < 64.

thread 378235 panic: integer overflow
src/Sema/bitcast.zig:156:59: 0x9e4f48f in bitCastSpliceInner ()
        .{ val_ty.abiSize(zcu) * 8 - host_bits, host_bits - val_ty.bitSize(zcu) }
                                                          ^

jacobly0 avatar Apr 22 '24 03:04 jacobly0

Thanks @jacobly0. Is there an easy way to figure out which cast this might be/a way to work around it in the meantime? Not being able to build my project with the stable version of Zig is kind of disappointing.

scheibo avatar Apr 22 '24 18:04 scheibo

Sorry for the instability, this one's my fault. I'll look into it shortly. I should then be able to point you towards a workaround, and will hopefully get a fix up within a few days.

mlugg avatar Apr 22 '24 18:04 mlugg

here's the smallest repro I was able to do:

pub const Foo = packed struct(u32) {
    a: u16 = undefined,

    b: packed struct(u16) {
        c: u6 = 0,
        d: u10 = 0,
    },
};

pub fn main() !void {
    const f: Foo = .{ .b = .{ .c = 2 } };
    _ = f;
}

hope it helps!

Rexicon226 avatar Apr 23 '24 07:04 Rexicon226

I'm running into an issue I think might be the same problem. If I write a test like:

test "panic" {
    std.debug.panic("panic\n", .{});
}

and I run zig build test, it just hangs. If I've modified the source since the last run, it hangs looking like this:

$ zig build test
steps [3/5] zig test Debug native... LLVM Emit Object...

If instead I run zig build test to get the zig test invocation, and run zig test directly without the --listen, it at least prints:

Test [1/1] main.test.panic... thread 1865483 panic: panic

But then still hangs. When I attach gdb to the hanging test process this is the stack trace I get:

(gdb) thread apply all bt

Thread 1 (Thread 0xffff84dc0010 (LWP 1865776)):
#0  0x0000ffff84d66d14 in msync (addr=<optimized out>, length=4096, flags=1) at ../sysdeps/unix/sysv/linux/msync.c:25
#1  0x0000000001098624 in posix.msync (memory=..., flags=1) at /snap/zig/11354/lib/std/posix.zig:4698
#2  0x00000000010843d8 in debug.StackIterator.isValidMemory (address=281474931325088) at /snap/zig/11354/lib/std/debug.zig:691
#3  0x00000000010a8594 in dwarf.DwarfInfo.unwindFrame (di=0xffff84dbf1e8, context=0xfffffd4b7238, explicit_fde_offset=...) at /snap/zig/11354/lib/std/dwarf.zig:1702
#4  0x00000000010a729c in debug.StackIterator.next_unwind (self=0xfffffd4b7218) at /snap/zig/11354/lib/std/debug.zig:724
#5  0x0000000001098aac in debug.StackIterator.next_internal (self=0xfffffd4b7218) at /snap/zig/11354/lib/std/debug.zig:734
#6  0x00000000010849e4 in debug.StackIterator.next (self=0xfffffd4b7218) at /snap/zig/11354/lib/std/debug.zig:654
#7  0x000000000108472c in debug.writeCurrentStackTrace__anon_7768 (out_stream=..., debug_info=0x1117c10 <debug.self_debug_info>, tty_config=..., start_addr=...) at /snap/zig/11354/lib/std/debug.zig:795
#8  0x000000000104bf84 in debug.dumpCurrentStackTrace (start_addr=...) at /snap/zig/11354/lib/std/debug.zig:188
#9  0x0000000001042770 in debug.panicImpl (trace=0x0, first_trace_addr=..., msg=...) at /snap/zig/11354/lib/std/debug.zig:482
#10 0x0000000001041ad8 in builtin.default_panic (msg=..., error_return_trace=0x0, ret_addr=...) at /snap/zig/11354/lib/std/builtin.zig:845
#11 0x000000000104226c in debug.panicExtra__anon_1909 (trace=0x0, ret_addr=...) at /snap/zig/11354/lib/std/debug.zig:434
#12 0x0000000001041704 in debug.panic__anon_946 () at /snap/zig/11354/lib/std/debug.zig:409
#13 0x00000000010416dc in main.test.panic () at main.zig:1194
#14 0x000000000104b4e4 in test_runner.mainTerminal () at /snap/zig/11354/lib/compiler/test_runner.zig:158
#15 0x00000000010420b0 in test_runner.main () at /snap/zig/11354/lib/compiler/test_runner.zig:35
#16 0x0000000001041a58 in start.callMain () at /snap/zig/11354/lib/std/start.zig:501
#17 start.callMainWithArgs () at /snap/zig/11354/lib/std/start.zig:469
#18 start.main (c_argc=1, c_argv=0xfffffd4b9a48, c_envp=0xfffffd4b9a58) at /snap/zig/11354/lib/std/start.zig:484

If this does not seem like the same issue, please let me know and I'll open a new issue.

saltzm avatar May 20 '24 19:05 saltzm

Nevermind, this does not seem like the same issue. The only thing that's the same is that the panic causes a hang rather than a crash. I'll make a new issue

saltzm avatar May 20 '24 20:05 saltzm

@mlugg given 0.12.1/0.13 are to be released soon is it possible you'll get a chance to look at this before then? Would be great to not be broken on another major version. Thanks!

scheibo avatar May 22 '24 18:05 scheibo