zig
zig copied to clipboard
Inline assembly errors lose source location so it' hard to understand where error is
Zig Version
0.13.0-dev.46+3648d7df1
Steps to Reproduce and Observed Output
- Save this to some file, i.e. inline_assembly_error_message.zig
inline fn rdtsc() u64 {
var hi: u64 = 0;
var low: u64 = 0;
//Changing the following to rdtsc fixes the bug
asm volatile (
\\rdtsc
: [low] "={eax}" (low),
[hi] "={edx}" (hi),
);
return (@as(u64, hi) << 32) | @as(u64, low);
}
pub fn main() void {
_ = rdtsc();
}
- compile it for some platform which doesn't support the assembly above
zig build-exe -target aarch64-macos-none inline_assembly_error_message.zig
- output will be
❯ zig build-exe -target aarch64-macos-none inline_assembly_error_message.zig
LLVM Emit Object... error: couldn't allocate output register for constraint '{eax}'
I think it's general problem with inline assembly?
I was able to get similar error just by writing nonsense
zig build-exe -target aarch64-macos-none inline_assembly_error_message.zig
LLVM Emit Object... error: <inline asm>:1:2: unrecognized instruction mnemonic
rdtsc
observe how it lost filename too
Expected Output
❯ zig build-exe -target aarch64-macos-none inline_assembly_error_message.zig
LLVM Emit Object... error: couldn't allocate output register for constraint '{eax}'
at inline_assembly_error_message.zig:8 // so it should include source location
Duplicate of #246 I believe.