Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mholub opened this issue Apr 29, 2024 · 1 comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.

Comments

@mholub
Copy link

mholub commented Apr 29, 2024

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 mholub added the error message This issue points out an error message that is unhelpful and should be improved. label Apr 29, 2024
@Rexicon226
Copy link
Contributor

Duplicate of #246 I believe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
Development

No branches or pull requests

2 participants