zig icon indicating copy to clipboard operation
zig copied to clipboard

Inline assembly errors lose source location so it' hard to understand where error is

Open mholub opened this issue 1 year ago • 1 comments

Zig Version

0.13.0-dev.46+3648d7df1

Steps to Reproduce and Observed Output

  1. 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();
}

  1. compile it for some platform which doesn't support the assembly above
zig build-exe -target aarch64-macos-none inline_assembly_error_message.zig
  1. 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

mholub avatar Apr 29 '24 18:04 mholub

Duplicate of #246 I believe.

Rexicon226 avatar Apr 29 '24 18:04 Rexicon226