ziglang/zig
262
5.9k
Fork
You've already forked zig
759

Compiler crash when building itself with -Ddev=sema -Doptimize=ReleaseFast #31080

Closed
opened 2026年02月01日 10:20:04 +01:00 by 1off · 7 comments
Contributor
Copy link

Zig Version

zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6

Steps to Reproduce and Observed Behavior

 ~/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Doptimize=ReleaseFast
install
└─ install zig
 └─ compile exe zig ReleaseFast native failure
error: process terminated with signal SEGV
failed command: /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build-exe --stack 48234496 -fno-sanitize-thread -OReleaseFast --dep aro --dep build_options -Mroot=/home/rad/lab/zig/src/main.zig -Maro=/home/rad/lab/zig/lib/compiler/aro/aro.zig -Mbuild_options=/home/rad/lab/zig/.zig-cache/c/e5eead726d7591be978b378eb4f144a5/options.zig --cache-dir /home/rad/lab/zig/.zig-cache --global-cache-dir /home/rad/.cache/zig --name zig --zig-lib-dir /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/ --listen=-
Build Summary: 1/4 steps succeeded (1 failed)
install transitive failure
└─ install zig transitive failure
 └─ compile exe zig ReleaseFast native failure
error: the following build command failed with exit code 1:
/home/rad/lab/zig/.zig-cache/o/f9bf9fe1996084cbbf3af2e7f7ac205e/build /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib /home/rad/lab/zig /home/rad/lab/zig/.zig-cache /home/rad/.cache/zig --seed 0xbe1c1da -Zf3e524a105e288ed -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Doptimize=ReleaseFast

These complete OK
❯ ~/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build -p sema-only -Dno-lib -Dno-langref -Ddev=sema
❯ ~/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Duse-llvm=true
❯ ~/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Doptimize=ReleaseSafe

Crash details:

stack trace from a build with `❯ ~/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build -p stage5 -Dno-lib -Dno-langref `
❯ ./stage5/bin/zig build -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Doptimize=ReleaseFast
install
└─ install zig
 └─ compile exe zig ReleaseFast native failure
error: Compiler crash context:
 Generating function 'Zcu.CodegenTaskPool.cancel'
 
 thread 33101 panic: reached unreachable code
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:180972:35: 0x3bce9e3 in getResolvedInstValue (main.zig)
 .none, .unreach, .dead => unreachable,
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187568:49: 0x5d08304 in tempFromOperand (main.zig)
 const tracking = cg.getResolvedInstValue(op_inst);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187586:97: 0x5cc5324 in tempsFromOperandsInner (main.zig)
 for (op_temps, 0.., op_refs) |*op_temp, op_index, op_ref| op_temp.* = try cg.tempFromOperand(op_ref, for (op_refs[0..op_index]) |prev_op_ref| {
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187597:34: 0x59ef326 in tempsFromOperands (main.zig)
 try cg.tempsFromOperandsInner(inst, &op_temps, &op_refs);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:2284:19: 0x5ce889e in genBodyBlock (main.zig)
 try cg.genBody(body);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:176407:26: 0x59878d9 in airCondBr (main.zig)
 try self.genBodyBlock(then_body);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:89023:41: 0x59c7eff in genBody (main.zig)
 .cond_br => try cg.airCondBr(inst),
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:176514:21: 0x596c0b9 in lowerBlock (main.zig)
 try self.genBody(body);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:67353:34: 0x59c40a2 in genBody (main.zig)
 try cg.lowerBlock(inst, block.body);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:2284:19: 0x5ce889e in genBodyBlock (main.zig)
 try cg.genBody(body);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:67363:36: 0x59c441f in genBody (main.zig)
 try cg.genBodyBlock(block.body);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:176514:21: 0x596c0b9 in lowerBlock (main.zig)
 try self.genBody(body);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:67353:34: 0x59c40a2 in genBody (main.zig)
 try cg.lowerBlock(inst, block.body);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:2263:19: 0x568d51a in genMainBody (main.zig)
 try cg.genBody(main_body[air_arg_count..]);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:2059:29: 0x531e84c in gen (main.zig)
 try self.genMainBody(zir, func_zir_inst, comptime_args, air_arg_count);
 ^
 /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:985:17: 0x4e7fd98 in generate (main.zig)
 function.gen(&file.zir.?, func_zir.inst, func.comptime_args, call_info.air_arg_count) catch |err| switch (err) {
 ^
 /home/rad/lab/zig/src/codegen.zig:163:45: 0x458aa45 in generateFunction (main.zig)
 const mir = try CodeGen.generate(lf, pt, src_loc, func_index, air, liveness);
 ^
 /home/rad/lab/zig/src/Zcu/PerThread.zig:4683:36: 0x3f321a7 in runCodegenInner (main.zig)
 return codegen.generateFunction(lf, pt, zcu.navSrcLoc(nav), func_index, air, &liveness) catch |err| switch (err) {
 ^
 /home/rad/lab/zig/src/Zcu/PerThread.zig:4559:43: 0x3832e15 in runCodegen (main.zig)
 const codegen_result = runCodegenInner(pt, func_index, air);
 ^
 /home/rad/lab/zig/src/Zcu.zig:4962:29: 0x31f6af0 in workerCodegenOwnedAir (main.zig)
 return pt.runCodegen(func_index, &air);
 ^
 /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/Io.zig:2052:13: 0x2c1752f in start (std.zig)
 result_casted.* = @call(.auto, function, args_casted.*);
 ^
 /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/Io/Threaded.zig:683:20: 0x1ae7c61 in start (std.zig)
 future.func(future.contextPointer(), future.resultPointer());
 ^
 /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/Io/Threaded.zig:1756:29: 0x1b9c27a in worker (std.zig)
 runnable.startFn(runnable, &thread, t);
 ^
 /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/Thread.zig:423:13: 0x1b4fbb5 in callFn__anon_31384 (std.zig)
 @call(.auto, f, args);
 ^
 /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/Thread.zig:1375:30: 0x1ae8e30 in entryFn (std.zig)
 return callFn(f, self.fn_args);
 ^
 /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/os/linux/x86_64.zig:105:5: 0x1b4fc95 in clone (std.zig)
 asm volatile (
 ^
 
error: process terminated with signal ABRT
failed command: /home/rad/lab/zig/build/stage5/bin/zig build-exe --stack 48234496 -fno-sanitize-thread -OReleaseFast --dep aro --dep build_options -Mroot=/home/rad/lab/zig/src/main.zig -Maro=/home/rad/lab/zig/lib/compiler/aro/aro.zig -Mbuild_options=/home/rad/lab/zig/.zig-cache/c/e5eead726d7591be978b378eb4f144a5/options.zig --cache-dir /home/rad/lab/zig/.zig-cache --global-cache-dir /home/rad/.cache/zig --name zig --zig-lib-dir /home/rad/lab/zig/lib/ --listen=-
Build Summary: 1/4 steps succeeded (1 failed)
install transitive failure
└─ install zig transitive failure
 └─ compile exe zig ReleaseFast native failure
error: the following build command failed with exit code 1:
/home/rad/lab/zig/.zig-cache/o/c1748430f8954726666da0bc81d5ad0a/build /home/rad/lab/zig/build/stage5/bin/zig /home/rad/lab/zig/lib /home/rad/lab/zig /home/rad/lab/zig/.zig-cache /home/rad/.cache/zig --seed 0x85593ce1 -Z9ecc91058833bd36 -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Doptimize=ReleaseFast
### Zig Version zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6 ### Steps to Reproduce and Observed Behavior ``` ~/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Doptimize=ReleaseFast install └─ install zig └─ compile exe zig ReleaseFast native failure error: process terminated with signal SEGV failed command: /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build-exe --stack 48234496 -fno-sanitize-thread -OReleaseFast --dep aro --dep build_options -Mroot=/home/rad/lab/zig/src/main.zig -Maro=/home/rad/lab/zig/lib/compiler/aro/aro.zig -Mbuild_options=/home/rad/lab/zig/.zig-cache/c/e5eead726d7591be978b378eb4f144a5/options.zig --cache-dir /home/rad/lab/zig/.zig-cache --global-cache-dir /home/rad/.cache/zig --name zig --zig-lib-dir /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/ --listen=- Build Summary: 1/4 steps succeeded (1 failed) install transitive failure └─ install zig transitive failure └─ compile exe zig ReleaseFast native failure error: the following build command failed with exit code 1: /home/rad/lab/zig/.zig-cache/o/f9bf9fe1996084cbbf3af2e7f7ac205e/build /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib /home/rad/lab/zig /home/rad/lab/zig/.zig-cache /home/rad/.cache/zig --seed 0xbe1c1da -Zf3e524a105e288ed -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Doptimize=ReleaseFast ``` These complete OK ❯ ~/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build -p sema-only -Dno-lib -Dno-langref -Ddev=sema ❯ ~/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Duse-llvm=true ❯ ~/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Doptimize=ReleaseSafe Crash details: <details> <summary>stack trace from a build with `❯ ~/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/zig build -p stage5 -Dno-lib -Dno-langref `</summary> ``` ❯ ./stage5/bin/zig build -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Doptimize=ReleaseFast install └─ install zig └─ compile exe zig ReleaseFast native failure error: Compiler crash context: Generating function 'Zcu.CodegenTaskPool.cancel' thread 33101 panic: reached unreachable code /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:180972:35: 0x3bce9e3 in getResolvedInstValue (main.zig) .none, .unreach, .dead => unreachable, ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187568:49: 0x5d08304 in tempFromOperand (main.zig) const tracking = cg.getResolvedInstValue(op_inst); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187586:97: 0x5cc5324 in tempsFromOperandsInner (main.zig) for (op_temps, 0.., op_refs) |*op_temp, op_index, op_ref| op_temp.* = try cg.tempFromOperand(op_ref, for (op_refs[0..op_index]) |prev_op_ref| { ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187597:34: 0x59ef326 in tempsFromOperands (main.zig) try cg.tempsFromOperandsInner(inst, &op_temps, &op_refs); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:2284:19: 0x5ce889e in genBodyBlock (main.zig) try cg.genBody(body); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:176407:26: 0x59878d9 in airCondBr (main.zig) try self.genBodyBlock(then_body); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:89023:41: 0x59c7eff in genBody (main.zig) .cond_br => try cg.airCondBr(inst), ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:176514:21: 0x596c0b9 in lowerBlock (main.zig) try self.genBody(body); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:67353:34: 0x59c40a2 in genBody (main.zig) try cg.lowerBlock(inst, block.body); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:2284:19: 0x5ce889e in genBodyBlock (main.zig) try cg.genBody(body); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:67363:36: 0x59c441f in genBody (main.zig) try cg.genBodyBlock(block.body); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:176514:21: 0x596c0b9 in lowerBlock (main.zig) try self.genBody(body); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:67353:34: 0x59c40a2 in genBody (main.zig) try cg.lowerBlock(inst, block.body); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:2263:19: 0x568d51a in genMainBody (main.zig) try cg.genBody(main_body[air_arg_count..]); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:2059:29: 0x531e84c in gen (main.zig) try self.genMainBody(zir, func_zir_inst, comptime_args, air_arg_count); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:985:17: 0x4e7fd98 in generate (main.zig) function.gen(&file.zir.?, func_zir.inst, func.comptime_args, call_info.air_arg_count) catch |err| switch (err) { ^ /home/rad/lab/zig/src/codegen.zig:163:45: 0x458aa45 in generateFunction (main.zig) const mir = try CodeGen.generate(lf, pt, src_loc, func_index, air, liveness); ^ /home/rad/lab/zig/src/Zcu/PerThread.zig:4683:36: 0x3f321a7 in runCodegenInner (main.zig) return codegen.generateFunction(lf, pt, zcu.navSrcLoc(nav), func_index, air, &liveness) catch |err| switch (err) { ^ /home/rad/lab/zig/src/Zcu/PerThread.zig:4559:43: 0x3832e15 in runCodegen (main.zig) const codegen_result = runCodegenInner(pt, func_index, air); ^ /home/rad/lab/zig/src/Zcu.zig:4962:29: 0x31f6af0 in workerCodegenOwnedAir (main.zig) return pt.runCodegen(func_index, &air); ^ /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/Io.zig:2052:13: 0x2c1752f in start (std.zig) result_casted.* = @call(.auto, function, args_casted.*); ^ /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/Io/Threaded.zig:683:20: 0x1ae7c61 in start (std.zig) future.func(future.contextPointer(), future.resultPointer()); ^ /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/Io/Threaded.zig:1756:29: 0x1b9c27a in worker (std.zig) runnable.startFn(runnable, &thread, t); ^ /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/Thread.zig:423:13: 0x1b4fbb5 in callFn__anon_31384 (std.zig) @call(.auto, f, args); ^ /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/Thread.zig:1375:30: 0x1ae8e30 in entryFn (std.zig) return callFn(f, self.fn_args); ^ /home/rad/Downloads/zig-x86_64-linux-0.16.0-dev.2623+27eec9bd6/lib/std/os/linux/x86_64.zig:105:5: 0x1b4fc95 in clone (std.zig) asm volatile ( ^ error: process terminated with signal ABRT failed command: /home/rad/lab/zig/build/stage5/bin/zig build-exe --stack 48234496 -fno-sanitize-thread -OReleaseFast --dep aro --dep build_options -Mroot=/home/rad/lab/zig/src/main.zig -Maro=/home/rad/lab/zig/lib/compiler/aro/aro.zig -Mbuild_options=/home/rad/lab/zig/.zig-cache/c/e5eead726d7591be978b378eb4f144a5/options.zig --cache-dir /home/rad/lab/zig/.zig-cache --global-cache-dir /home/rad/.cache/zig --name zig --zig-lib-dir /home/rad/lab/zig/lib/ --listen=- Build Summary: 1/4 steps succeeded (1 failed) install transitive failure └─ install zig transitive failure └─ compile exe zig ReleaseFast native failure error: the following build command failed with exit code 1: /home/rad/lab/zig/.zig-cache/o/c1748430f8954726666da0bc81d5ad0a/build /home/rad/lab/zig/build/stage5/bin/zig /home/rad/lab/zig/lib /home/rad/lab/zig /home/rad/lab/zig/.zig-cache /home/rad/.cache/zig --seed 0x85593ce1 -Z9ecc91058833bd36 -p sema-only -Dno-lib -Dno-langref -Ddev=sema -Doptimize=ReleaseFast ```
Author
Contributor
Copy link

Not a compiler bug, per se, unless Liveness is intended to elide those in Debug and ReleaseSafe modes.

At the time the project was coded to compile with -Ddev=sema (set as the default in build.zig), but nothing added/changed was/is related to linking/codegen, so I assumed Liveness was being unfairly eager.

Today I put all calls to linking/codegen behind a dev check and lo and behold :)

So I had to check -- The same crash/stack traces can be observed when building the stock zig compiler with -Ddev=sema -Doptimize=ReleaseFast

Not a compiler bug, per se, unless Liveness is intended to elide those in Debug and ReleaseSafe modes. At the time the project was coded to compile with -Ddev=sema (set as the default in build.zig), but nothing added/changed was/is related to linking/codegen, so I assumed Liveness was being unfairly eager. Today I put all calls to linking/codegen behind a `dev` check and lo and behold :) So I had to check -- The same crash/stack traces can be observed when building the stock zig compiler with -Ddev=sema -Doptimize=ReleaseFast
Owner
Copy link

I missed this issue before, sorry; but I'm really struggling to understand it from the issue text. There seem to be many different zig binaries involved, and I don't really understand when you're hitting this crash. Your first two "crash details" seem to just be showing that your project (which is itself a Zig compiler fork) is crashing, but the last is showing the normal compiler crashing while building your code. Is that last one what you're actually trying to show? So would I be correct in saying that given an official zig tarball, this is the situation:

$ zig build // ok
$ zig build -Duse-llvm // ok
$ zig build -Doptimize=ReleaseSafe // ok
$ zig build -Doptimize=ReleaseFast // crash!

(If I just blindly look at your stack traces it looks like an OPV bug in Sema, but per the above I'm not entirely sure if those traces are relevant...)

It'd be great if you could try to reword your Steps to Reproduce to be a little clearer.

I missed this issue before, sorry; but I'm really struggling to understand it from the issue text. There seem to be many different `zig` binaries involved, and I don't really understand when you're hitting this crash. Your first two "crash details" seem to just be showing that *your* project (which is itself a Zig compiler fork) is crashing, but the last is showing the normal compiler crashing while building your code. Is that last one what you're actually trying to show? So would I be correct in saying that given an official `zig` tarball, this is the situation: ``` $ zig build // ok $ zig build -Duse-llvm // ok $ zig build -Doptimize=ReleaseSafe // ok $ zig build -Doptimize=ReleaseFast // crash! ``` (If I just blindly look at your stack traces it looks like an OPV bug in Sema, but per the above I'm not entirely sure if those traces are relevant...) It'd be great if you could try to reword your Steps to Reproduce to be a little clearer.
Author
Contributor
Copy link

@mlugg wrote in #31080 (comment):

So would I be correct in saying that given an official zig tarball, this is the situation:

$ zig build // ok
$ zig build -Duse-llvm // ok
$ zig build -Doptimize=ReleaseSafe // ok
$ zig build -Doptimize=ReleaseFast // crash!

That's correct. All the examples are builds of the zig compiler building my project, which is a fork of the compiler, but defaults to -Ddev=sema.

I checked with the self-hosted and enable-llvm debug builds to rule them out as the source of the issue - it was obvious that they were tasked with generating a function that was marked .none/.unreach/.dead.

As you are familiar, the compiler puts functionality behind dev checks and .sema is not supposed to pull in linking/codegen fns, but there are no explicit dev checks and somehow that only matters when compiling with -Doptimize=ReleaseFast.

My perspective - I've solved my use case, and obviously nobody compiles zig with -Ddev=sema -Doptimize=ReleaseFast, so if this doesn't stand out as an bug this issue can be closed.

@mlugg wrote in https://codeberg.org/ziglang/zig/issues/31080#issuecomment-10693283: > So would I be correct in saying that given an official `zig` tarball, this is the situation: > > ```text > $ zig build // ok > $ zig build -Duse-llvm // ok > $ zig build -Doptimize=ReleaseSafe // ok > $ zig build -Doptimize=ReleaseFast // crash! > ``` That's correct. All the examples are builds of the zig compiler building my project, which is a fork of the compiler, but defaults to -Ddev=sema. I checked with the self-hosted and enable-llvm debug builds to rule them out as the source of the issue - it was obvious that they were tasked with generating a function that was marked `.none/.unreach/.dead`. As you are familiar, the compiler puts functionality behind [`dev`](https://codeberg.org/ziglang/zig/src/branch/master/src/dev.zig) checks and .sema is not supposed to pull in linking/codegen fns, but there are no explicit `dev` checks and somehow that only matters when compiling with -Doptimize=ReleaseFast. My perspective - I've solved my use case, and obviously nobody compiles zig with -Ddev=sema -Doptimize=ReleaseFast, so if this doesn't stand out as an bug this issue can be closed.
Owner
Copy link

A normal build of Zig (which was not itself compiled with -Ddev=sema) crashing is always a bug, regardless of what it's compiling, so I'm leaving this open. The fact that it crashes both the x86_64 backend and the LLVM backend is doubly bad: it makes it more difficult to work around, and probably indicates that we're doing something very wrong. I probably won't have time to look at this today, but I'll try to do so at some point soon.

A normal build of Zig (which was not *itself* compiled with `-Ddev=sema`) crashing is always a bug, regardless of what it's compiling, so I'm leaving this open. The fact that it crashes both the x86_64 backend *and* the LLVM backend is doubly bad: it makes it more difficult to work around, and probably indicates that we're doing something *very* wrong. I probably won't have time to look at this today, but I'll try to do so at some point soon.
1off changed title from (削除) Compiler crash when building my project with -Doptimize=ReleaseFast (削除ここまで) to Compiler crash when building itself with -Ddev=sema -Doptimize=ReleaseFast 2026年02月18日 12:52:50 +01:00
Author
Contributor
Copy link

I put together a repro

conststd=@import("std");constIo=std.Io;constTaskPool=struct{constResult=error{OutOfMemory}!Some;task_futures:[]Io.Future(Result),pubfncancel(pool:*TaskPool,io:std.Io)void{for(pool.task_futures,)|*future|{varsome=future.cancel(io)catchcontinue;some.deinit();}}};constTag=enum(u64){foo=0,bar=1,// doesn't make a differnce if defined or not_,};constSome=union{foo:if(false)struct{}elsenoreturn,bar:if(false)struct{}elsenoreturn,// No ReleaseFast crash if commented outpubinlinefntagSlice(comptimetag:Tag)[]constu8{returnswitch(tag){.foo=>"foo",else=>unreachable,};}fndeinit(some:*Some)void{consttag:Tag=.foo;switch(tag){inline.foo=>|t|@field(some,tagSlice(t)).deinit(),else=>unreachable,}return.foo;}};pubfnmain(init:std.process.Init)!void{vartpool:TaskPool=.{.task_futures=tryinit.arena.allocator().alloc(Io.Future(TaskPool.Result),10)};tpool.cancel(init.io);}
❯ zig build-exe ./src/main.zig
❯ zig build-exe ./src/main.zig -OReleaseFast
fish: Job 1, 'zig build-exe ./src/main.zig -O...' terminated by signal SIGSEGV (Address boundary error)
❯ ~/lab/zig/build/stage5/bin/zig build-exe ./src/main.zig -OReleaseFast
Compiler crash context:
Generating function 'main.TaskPool.cancel'
thread 80415 panic: reached unreachable code
/home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:180972:35: 0x3bce9e3 in getResolvedInstValue (main.zig)
 .none, .unreach, .dead => unreachable,
 ^
/home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187568:49: 0x5d08304 in tempFromOperand (main.zig)
 const tracking = cg.getResolvedInstValue(op_inst);
 ^
/home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187586:97: 0x5cc5324 in tempsFromOperandsInner (main.zig)
 for (op_temps, 0.., op_refs) |*op_temp, op_index, op_ref| op_temp.* = try cg.tempFromOperand(op_ref, for (op_refs[0..op_index]) |prev_op_ref| {
 ^
/home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187597:34: 0x59ef326 in tempsFromOperands (main.zig)
 try cg.tempsFromOperandsInner(inst, &op_temps, &op_refs);
 ^
/home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:2284:19: 0x5ce889e in genBodyBlock (main.zig)
 try cg.genBody(body);
{...}
I put together a repro ```zig const std = @import("std"); const Io = std.Io; const TaskPool = struct { const Result = error{OutOfMemory}!Some; task_futures: []Io.Future(Result), pub fn cancel(pool: *TaskPool, io: std.Io) void { for ( pool.task_futures, ) |*future| { var some = future.cancel(io) catch continue; some.deinit(); } } }; const Tag = enum(u64) { foo = 0, bar = 1, // doesn't make a differnce if defined or not _, }; const Some = union { foo: if (false) struct {} else noreturn, bar: if (false) struct {} else noreturn, // No ReleaseFast crash if commented out pub inline fn tagSlice(comptime tag: Tag) []const u8 { return switch (tag) { .foo => "foo", else => unreachable, }; } fn deinit(some: *Some) void { const tag: Tag = .foo; switch (tag) { inline .foo => |t| @field(some, tagSlice(t)).deinit(), else => unreachable, } return .foo; } }; pub fn main(init: std.process.Init) !void { var tpool: TaskPool = .{ .task_futures = try init.arena.allocator().alloc(Io.Future(TaskPool.Result), 10) }; tpool.cancel(init.io); } ``` ``` ❯ zig build-exe ./src/main.zig ❯ zig build-exe ./src/main.zig -OReleaseFast fish: Job 1, 'zig build-exe ./src/main.zig -O...' terminated by signal SIGSEGV (Address boundary error) ❯ ~/lab/zig/build/stage5/bin/zig build-exe ./src/main.zig -OReleaseFast Compiler crash context: Generating function 'main.TaskPool.cancel' thread 80415 panic: reached unreachable code /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:180972:35: 0x3bce9e3 in getResolvedInstValue (main.zig) .none, .unreach, .dead => unreachable, ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187568:49: 0x5d08304 in tempFromOperand (main.zig) const tracking = cg.getResolvedInstValue(op_inst); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187586:97: 0x5cc5324 in tempsFromOperandsInner (main.zig) for (op_temps, 0.., op_refs) |*op_temp, op_index, op_ref| op_temp.* = try cg.tempFromOperand(op_ref, for (op_refs[0..op_index]) |prev_op_ref| { ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:187597:34: 0x59ef326 in tempsFromOperands (main.zig) try cg.tempsFromOperandsInner(inst, &op_temps, &op_refs); ^ /home/rad/lab/zig/src/codegen/x86_64/CodeGen.zig:2284:19: 0x5ce889e in genBodyBlock (main.zig) try cg.genBody(body); {...} ```
Author
Contributor
Copy link

Can be closed as fixed by #31403

Can be closed as fixed by https://codeberg.org/ziglang/zig/pulls/31403
mlugg added this to the 0.16.0 milestone 2026年03月10日 23:05:41 +01:00
Owner
Copy link

Resolved by #31403.

Resolved by https://codeberg.org/ziglang/zig/pulls/31403.
Sign in to join this conversation.
No Branch/Tag specified
master
elfv2
spork8
restricted
0.16.x
panic-rewrite
parking-futex-lockfree
windows-Io-cleanup
Io-watch
ParseCommandLineOptions
windows-async-files
poll-ring
debug-file-leaks-differently
debug-file-leaks
ProcessPrng
elfv2-dyn
jobserver
threadtheft
io-threaded-no-queue
0.15.x
Io.net
comptime-allocator
restricted-function-pointers
cli
wasm-linker-writer
wrangle-writer-buffering
sha1-stream
async-await-demo
fixes
0.14.x
ast-node-methods
macos-debug-info
make-vs-configure
fuzz-macos
sans-aro
ArrayList-reserve
incr-bug
llvm-ir-nosanitize-metadata
ci-tarballs
ci-scripts
threadpool
0.12.x
new-pkg-hash
json-diagnostics
more-doctests
rework-comptime-mutation
0.11.x
ci-perf-comment
stage2-async
0.10.x
autofix
0.9.x
aro
hcs
0.8.x
0.7.x
0.16.0
0.15.2
0.15.1
0.15.0
0.14.1
0.14.0
0.12.1
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.9.1
0.9.0
0.8.1
0.8.0
0.7.1
0.7.0
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.1
0.1.0
Labels
Clear labels
abi/f32
abi/ilp32
abi/sf
accepted
This proposal is planned.
arch/21k
arch/6502
arch/aarch64
arch/alpha
arch/amdgcn
arch/arc
arch/arc32
arch/arc64
arch/arm
arch/avr
arch/bfin
arch/bpf
arch/colossus
arch/cris
arch/csky
arch/dlx
arch/epiphany
arch/fr30
arch/frv
arch/hexagon
arch/hppa
arch/hppa64
arch/ia64
arch/kalimba
arch/kvx
arch/lanai
arch/lm32
arch/loongarch32
arch/loongarch64
arch/m32r
arch/m68k
arch/m88k
arch/mcore
arch/microblaze
arch/mips
arch/mips64
arch/mmix
arch/moxie
arch/mrisc32
arch/msp430
arch/nds32
arch/ns32k
arch/nvptx
arch/or1k
arch/powerpc
arch/powerpc64
arch/propeller
arch/riscv32
arch/riscv64
arch/rl78
arch/rx
arch/s390x
arch/sh
arch/sparc
arch/sparc64
arch/spirv
arch/spu
arch/tricore
arch/v850
arch/vax
arch/vc4
arch/ve
arch/wasm
arch/x86
arch/x86_64
arch/xcore
arch/xtensa
autodoc
The web application for interactive documentation and generation of its assets.
backend/c
The C backend outputs C source code.
backend/llvm
The LLVM backend outputs an LLVM bitcode module.
backend/self-hosted
The self-hosted backends produce machine code directly.
binutils
Zig's included binary utilities: zig ar, zig dlltool, zig lib, zig ranlib, zig objcopy, and zig rc.
breaking
Implementing this issue could cause existing code to no longer compile or have different behavior.
build system
The Zig build system - zig build, std.Build, the build runner, and package management.
debug info
An issue related to debug information (e.g. DWARF) produced by the Zig compiler.
docs
An issue with documentation, e.g. the language reference or standard library doc comments.
error message
This issue points out an error message that is unhelpful and should be improved.
frontend
Tokenization, parsing, AstGen, ZonGen, Sema, Legalize, and Liveness.
fuzzing
An issue related to Zig's integrated fuzz testing.
incremental
Reuse of internal compiler state for faster compilation.
lib/c
This issue relates to Zig's libc implementation and/or vendored libcs.
lib/compiler-rt
This issue relates to Zig's compiler-rt library.
lib/cxx
This issue relates to Zig's vendored libc++ and/or libc++abi.
lib/std
This issue relates to Zig's standard library.
lib/tsan
This issue relates to Zig's vendored libtsan.
lib/ubsan-rt
This issue relates to Zig's ubsan-rt library.
lib/unwind
This issue relates to Zig's vendored libunwind.
linking
Zig's integrated object file and incremental linker.
miscompilation
The compiler reports success but produces semantically incorrect code.
os/android
os/contiki
os/dragonfly
os/driverkit
os/emscripten
os/freebsd
os/fuchsia
os/haiku
os/hermit
os/hurd
os/illumos
os/ios
os/linux
os/maccatalyst
os/macos
os/managarm
os/netbsd
os/ohos
os/openbsd
os/plan9
os/redox
os/rtems
os/serenity
os/tvos
os/uefi
os/visionos
os/wasi
os/watchos
os/windows
proposal
This issue suggests language modifications. If it also has the "accepted" label then it is planned.
release notes
This issue or pull request should be mentioned in the release notes.
testing
This issue is related to testing the compiler, standard library, or other parts of Zig.
zig cc
Zig as a drop-in C-family compiler.
zig fmt
The Zig source code formatter.
zig reduce
The Zig source code reduction tool.
bounty
https://ziglang.org/news/announcing-donor-bounties
bug
Observed behavior contradicts documented or intended behavior.
contributor-friendly
This issue is limited in scope and/or knowledge of project internals.
downstream
An issue with a third-party project that uses this project.
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
infra
An issue related to project infrastructure, e.g. continuous integration.
optimization
A task to improve performance and/or resource usage.
question
No questions on the issue tracker; use a community space instead.
regression
Something that used to work in a previous version stopped working
upstream
An issue with a third-party project that this project uses.
use case
Describes a real use case that is difficult or impossible, but does not propose a solution.
No labels
abi/f32
abi/ilp32
abi/sf
accepted
arch/21k
arch/6502
arch/aarch64
arch/alpha
arch/amdgcn
arch/arc
arch/arc32
arch/arc64
arch/arm
arch/avr
arch/bfin
arch/bpf
arch/colossus
arch/cris
arch/csky
arch/dlx
arch/epiphany
arch/fr30
arch/frv
arch/hexagon
arch/hppa
arch/hppa64
arch/ia64
arch/kalimba
arch/kvx
arch/lanai
arch/lm32
arch/loongarch32
arch/loongarch64
arch/m32r
arch/m68k
arch/m88k
arch/mcore
arch/microblaze
arch/mips
arch/mips64
arch/mmix
arch/moxie
arch/mrisc32
arch/msp430
arch/nds32
arch/ns32k
arch/nvptx
arch/or1k
arch/powerpc
arch/powerpc64
arch/propeller
arch/riscv32
arch/riscv64
arch/rl78
arch/rx
arch/s390x
arch/sh
arch/sparc
arch/sparc64
arch/spirv
arch/spu
arch/tricore
arch/v850
arch/vax
arch/vc4
arch/ve
arch/wasm
arch/x86
arch/x86_64
arch/xcore
arch/xtensa
autodoc
backend/c
backend/llvm
backend/self-hosted
binutils
breaking
build system
debug info
docs
error message
frontend
fuzzing
incremental
lib/c
lib/compiler-rt
lib/cxx
lib/std
lib/tsan
lib/ubsan-rt
lib/unwind
linking
miscompilation
os/android
os/contiki
os/dragonfly
os/driverkit
os/emscripten
os/freebsd
os/fuchsia
os/haiku
os/hermit
os/hurd
os/illumos
os/ios
os/linux
os/maccatalyst
os/macos
os/managarm
os/netbsd
os/ohos
os/openbsd
os/plan9
os/redox
os/rtems
os/serenity
os/tvos
os/uefi
os/visionos
os/wasi
os/watchos
os/windows
proposal
release notes
testing
zig cc
zig fmt
zig reduce
bounty
bug
contributor-friendly
downstream
enhancement
infra
optimization
question
regression
upstream
use case
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/zig#31080
Reference in a new issue
ziglang/zig
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?