ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.12k stars 2.56k forks source link

panic: referenced transitive analysis errors, but none actually emitted #21223

Closed andrewrk closed 1 month ago

andrewrk commented 2 months ago

Zig Version

0.14.0-dev.1342+1a178d499

Steps to Reproduce and Observed Behavior

$ git checkout incr-bug
$ stage4/bin/zig build -Dno-lib -Dno-bin --watch -fincremental --prominent-compile-errors
install
└─ zig build-exe zig Debug native 1 errors
error: the following command failed with 1 compilation errors:
/home/andy/dev/zig/build-release/stage4/bin/zig build-exe --stack 33554432 -fno-sanitize-thread -ODebug --dep aro --dep aro_translate_c --dep build_options -Mroot=/home/andy/dev/zig/src/main.zig -Maro=/home/andy/dev/zig/lib/compiler/aro/aro.zig --dep aro -Maro_translate_c=/home/andy/dev/zig/lib/compiler/aro_translate_c.zig -Mbuild_options=/home/andy/dev/zig/.zig-cache/c/ef1e8b4269c145ef15fae89ac792ff17/options.zig -fno-emit-bin --cache-dir /home/andy/dev/zig/.zig-cache --global-cache-dir /home/andy/.cache/zig --name zig --zig-lib-dir /home/andy/dev/zig/lib/ -fincremental --listen=- 
Build Summary: 1/3 steps succeeded; 1 failed
install transitive failure
└─ zig build-exe zig Debug native 1 errors
   └─ options success
/home/andy/dev/zig/src/codegen/llvm.zig:4853:44: error: use of undeclared identifier 'llvm_usize'
                    try o.builder.intValue(llvm_usize, self.nextPoiIndex()),
                                           ^~~~~~~~~~
watching 113 directories, 1 processes

Apply this diff:

--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -4850,7 +4850,7 @@ pub const FuncGen = struct {
                 // %1 = add i8 %0, 1, !dbg !30
                 // store i8 %1, ptr @__sancov_gen_, align 1, !dbg !30, !nosanitize !28
                 const ptr = try self.wip.gep(.inbounds, .i8, base_ptr, &.{
-                    try o.builder.intValue(llvm_usize, self.nextPoiIndex()),
+                    try o.builder.intValue(.i32, self.nextPoiIndex()),
                 }, "");
                 const counter = try self.wip.load(.normal, .i8, ptr, .default, "");
                 const one = try o.builder.intValue(.i8, 1);

Observe:

error: thread 567284 panic: referenced transitive analysis errors, but none actually emitted
/home/andy/dev/zig/src/Compilation.zig:3280:17: 0x59f1e9d in getAllErrorsAlloc (zig)
                @panic("referenced transitive analysis errors, but none actually emitted");
                ^
/home/andy/dev/zig/src/Compilation.zig:3290:44: 0x59f38a5 in totalErrorCount (zig)
    var errors = try comp.getAllErrorsAlloc();
                                           ^
/home/andy/dev/zig/src/Compilation.zig:2298:33: 0x5a1811b in update (zig)
    if (try comp.totalErrorCount() != 0) {
                                ^
/home/andy/dev/zig/src/main.zig:4156:32: 0x5a65ac1 in serve (zig)
                try comp.update(main_progress_node);
                               ^
/home/andy/dev/zig/src/main.zig:3453:22: 0x5a85771 in buildOutputType (zig)
            try serve(
                     ^
/home/andy/dev/zig/src/main.zig:258:31: 0x58d2ca6 in mainArgs (zig)
        return buildOutputType(gpa, arena, args, .{ .build = .Exe });
                              ^
/home/andy/dev/zig/src/main.zig:199:20: 0x58cfc75 in main (zig)
    return mainArgs(gpa, arena, args);
                   ^
/home/andy/dev/zig/lib/std/start.zig:615:37: 0x58cf79e in main (zig)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x7f31be55a10d in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7f31be55a10d` was not available, trace may be incomplete

error: the following command terminated unexpectedly:
/home/andy/dev/zig/build-release/stage4/bin/zig build-exe --stack 33554432 -fno-sanitize-thread -ODebug --dep aro --dep aro_translate_c --dep build_options -Mroot=/home/andy/dev/zig/src/main.zig -Maro=/home/andy/dev/zig/lib/compiler/aro/aro.zig --dep aro -Maro_translate_c=/home/andy/dev/zig/lib/compiler/aro_translate_c.zig -Mbuild_options=/home/andy/dev/zig/.zig-cache/c/ef1e8b4269c145ef15fae89ac792ff17/options.zig -fno-emit-bin --cache-dir /home/andy/dev/zig/.zig-cache --global-cache-dir /home/andy/.cache/zig --name zig --zig-lib-dir /home/andy/dev/zig/lib/ -fincremental --listen=- 
Build Summary: 1/3 steps succeeded; 1 failed
install transitive failure
└─ zig build-exe zig Debug native failure
watching 113 directories, 0 processes

Expected Behavior

install
└─ zig build-exe zig Debug native 1 errors
error: the following command failed with 1 compilation errors:
/home/andy/dev/zig/build-release/stage3/bin/zig build-exe --stack 33554432 -fno-sanitize-thread -ODebug --dep aro --dep aro_translate_c --dep build_options -Mroot=/home/andy/dev/zig/src/main.zig -Maro=/home/andy/dev/zig/lib/compiler/aro/aro.zig --dep aro -Maro_translate_c=/home/andy/dev/zig/lib/compiler/aro_translate_c.zig -Mbuild_options=/home/andy/dev/zig/.zig-cache/c/9626d1999fe13ecd8700573072d1d878/options.zig -fno-emit-bin --cache-dir /home/andy/dev/zig/.zig-cache --global-cache-dir /home/andy/.cache/zig --name zig --zig-lib-dir /home/andy/dev/zig/lib/ -fincremental --listen=- 
Build Summary: 1/3 steps succeeded; 1 failed
install transitive failure
└─ zig build-exe zig Debug native 1 errors
   └─ options success
/home/andy/dev/zig/src/codegen/llvm.zig:4848:29: error: expected optional type, found 'bool'
            .poi => if (self.fuzz) |base_ptr| {
                        ~~~~^~~~~
referenced by:
    updateFunc: /home/andy/dev/zig/src/codegen/llvm.zig:1683:19
    updateFunc: /home/andy/dev/zig/src/link/NvPtx.zig:87:36
    19 reference(s) hidden; use '-freference-trace=21' to see all references
watching 113 directories, 1 processes

Similar to #21185.

cc @mlugg

mlugg commented 1 month ago

The incr-bug branch has bitrotted, which will make this a little awkward to repro and fix. I'll do it if necessary, but if you're able to somehow trigger this on master, that'd be great @andrewrk

EDIT: never mind, it's actually super easy to repro!