zig
zig copied to clipboard
Missing error for runtime `@ptrFromInt` to comptime-only type
Zig Version
0.13.0-dev.267+793f820b3
Steps to Reproduce and Observed Behavior
- Clone down this repo: https://github.com/silbinarywolf/Zig-PSP/tree/repro/mipsel-psp-sdk-llvm-bug
- Run
zig build - Exits with error code in release builds with no additional information.
See debug build output below.
Expected Behavior
I'd expect it to either compile successfully or give me a nicer error explaining what went wrong.
Investigation notes
Looks like this Zig-PSP code utilizes comptime{ asm() } directives in various places, and after inlining certain comptime executions of those assembly strings, and getting compilation to get further, I think the issue is these are falling over within comptime.
Debug output
In Debug build:
$ /c/zig/zig/stage3/bin/zig build
install
└─ install main
└─ zig build-exe main ReleaseSmall mipsel-freestanding failure
error: thread 9740 panic: attempt to use null value
C:\zig\zig\src\codegen\llvm.zig:4857:79: 0xba8976 in resolveInst (zig.exe.obj)
const llvm_val = try self.resolveValue((try self.air.value(inst, mod)).?);
^
C:\zig\zig\src\codegen\llvm.zig:5260:45: 0xbf0e6f in airCall (zig.exe.obj)
const llvm_fn = try self.resolveInst(pl_op.operand);
^
C:\zig\zig\src\codegen\llvm.zig:5041:55: 0x847cbe in genBody (zig.exe.obj)
.call => try self.airCall(inst, .auto),
^
C:\zig\zig\src\codegen\llvm.zig:5151:48: 0xbd4c8b in genBodyDebugScope (zig.exe.obj)
if (self.wip.strip) return self.genBody(body);
^
C:\zig\zig\src\codegen\llvm.zig:6009:35: 0xbdad75 in airCondBr (zig.exe.obj)
try self.genBodyDebugScope(null, then_body);
^
C:\zig\zig\src\codegen\llvm.zig:5021:54: 0x846fd9 in genBody (zig.exe.obj)
.cond_br => try self.airCondBr(inst),
^
C:\zig\zig\src\codegen\llvm.zig:5151:48: 0xbd4c8b in genBodyDebugScope (zig.exe.obj)
if (self.wip.strip) return self.genBody(body);
^
C:\zig\zig\src\codegen\llvm.zig:5950:35: 0xbd43ca in lowerBlock (zig.exe.obj)
try self.genBodyDebugScope(maybe_inline_func, body);
^
C:\zig\zig\src\codegen\llvm.zig:5920:31: 0xbd6c1b in airBlock (zig.exe.obj)
return self.lowerBlock(inst, null, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
^
C:\zig\zig\src\codegen\llvm.zig:5014:53: 0x846bd4 in genBody (zig.exe.obj)
.block => try self.airBlock(inst),
^
C:\zig\zig\src\codegen\llvm.zig:1740:19: 0x840e7e in updateFunc (zig.exe.obj)
fg.genBody(air.getMainBody()) catch |err| switch (err) {
^
C:\zig\zig\src\link\Elf.zig:2993:70: 0xb948d7 in updateFunc (zig.exe.obj)
if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
^
C:\zig\zig\src\link.zig:422:82: 0x85003f in updateFunc (zig.exe.obj)
return @as(*tag.Type(), @fieldParentPtr("base", base)).updateFunc(module, func_index, air, liveness);
^
C:\zig\zig\src\Module.zig:3219:22: 0x5b5dc9 in ensureFuncBodyAnalyzed (zig.exe.obj)
lf.updateFunc(zcu, func_index, air, liveness) catch |err| switch (err) {
^
C:\zig\zig\src\Compilation.zig:3414:42: 0x5b2bdb in processOneJob (zig.exe.obj)
module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
^
C:\zig\zig\src\Compilation.zig:3354:30: 0x3e7a2e in performAllTheWork (zig.exe.obj)
try processOneJob(comp, work_item, main_progress_node);
^
C:\zig\zig\src\Compilation.zig:2132:31: 0x3e32e3 in update (zig.exe.obj)
try comp.performAllTheWork(main_progress_node);
^
C:\zig\zig\src\main.zig:4091:36: 0x45f039 in serve (zig.exe.obj)
try comp.update(main_progress_node);
^
C:\zig\zig\src\main.zig:3368:22: 0x47c79f in buildOutputType (zig.exe.obj)
try serve(
^
C:\zig\zig\src\main.zig:262:31: 0x2b93f9 in mainArgs (zig.exe.obj)
return buildOutputType(gpa, arena, args, .{ .build = .Exe });
^
C:\zig\zig\src\main.zig:208:20: 0x2b6aae in main (zig.exe.obj)
return mainArgs(gpa, arena, args);
^
C:\zig\zig\lib\std\start.zig:497:75: 0x2b67da in main (zig.exe.obj)
return callMainWithArgs(@as(usize, @intCast(c_argc)), @as([*][*:0]u8, @ptrCast(c_argv)), envp);
^
C:\zig\zig\lib\libc\mingw\crt\crtexe.c:267:0: 0x2bd89a1 in __tmainCRTStartup (crt2.obj)
mainret = _tmain (argc, argv, envp);
C:\zig\zig\lib\libc\mingw\crt\crtexe.c:188:0: 0x2bd89fb in mainCRTStartup (crt2.obj)
ret = __tmainCRTStartup ();
???:?:?: 0x7ff95cc87343 in ??? (KERNEL32.DLL)
???:?:?: 0x7ff95df426b0 in ??? (ntdll.dll)
error: the following command exited with error code 3:
C:\zig\zig\stage3\bin\zig.exe build-exe -OReleaseSmall -target mipsel-freestanding -mcpu mips2+single_float -Mroot=D:\ZigProjects\Zig-PSP-Repro\src\main.zig --cache-dir D:\ZigProjects\Zig-PSP-Repro\zig-cache --global-cache-dir C:\Users\User\AppData\Local\zig --name main --listen=-
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install main transitive failure
└─ zig build-exe main ReleaseSmall mipsel-freestanding failure
error: the following build command failed with exit code 1:
D:\ZigProjects\Zig-PSP-Repro\zig-cache\o\b8e4e33615e00870368c45052146b4c8\build.exe C:\zig\zig\stage3\bin\zig.exe D:\ZigProjects\Zig-PSP-Repro D:\ZigProjects\Zig-PSP-Repro\zig-cache C:\Users\User\AppData\Local\zig --seed 0x9ce9bd08 -Zd8461fa9d950770a
Crash fixed by:
diff --git a/src/psp/sdk/pspguimpl.zig b/src/psp/sdk/pspguimpl.zig
index b835002..80e8903 100644
--- a/src/psp/sdk/pspguimpl.zig
+++ b/src/psp/sdk/pspguimpl.zig
@@ -8,7 +8,7 @@ test {
}
//Internals
-pub const GuCallback = ?fn (c_int) callconv(.C) void;
+pub const GuCallback = ?*const fn (c_int) callconv(.C) void;
const GuSettings = struct {
sig: GuCallback,
Will make a PR to fix the missing error shortly.
Thank you very much. I did try to like, print the file/line from resolveInst in llvm.zig but just... I could not figure out how to get that information out 😁