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

global_asm! does not register location information to LLVM, resulting in suboptimal error reporting. #81751

Open
eddyb opened this issue Feb 4, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-inline-assembly Area: Inline assembly (`asm!(…)`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-enhancement Category: An issue proposing an enhancement or a PR with one. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@eddyb
Copy link
Member

eddyb commented Feb 4, 2021

Quick example (run on playground):

#![feature(asm, global_asm)]

global_asm!("GlobalThisIsNotAnInstruction");

fn main() {
    unsafe {
        asm!("MainThisIsNotAnInstruction");
    }
}

Current error output is:

error: invalid instruction mnemonic 'globalthisisnotaninstruction'
  |
note: instantiated into assembly here
 --> <inline asm>:1:1
  |
1 | GlobalThisIsNotAnInstruction
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: invalid instruction mnemonic 'mainthisisnotaninstruction'
 --> src/main.rs:7:15
  |
7 |         asm!("MainThisIsNotAnInstruction");
  |               ^
  |
note: instantiated into assembly here
 --> <inline asm>:2:2
  |
2 |     MainThisIsNotAnInstruction
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^

The reason asm! has location information is because it attaches !srcloc metadata on the call asm instruction, whereas global_asm! does nothing of the sort.

It's not clear from the LLVM documentation whether !srcloc (or something equivalent) is supported for module asm, so this might be blocked on LLVM implementing it in the first place.

This came up as @Jasper-Bekkers tried iimplementing AsmMethods::codegen_global_asm for rustc_codegen_spirv and noticed there was no Span being passed, and (presumably the more worrying aspect) that hir::GlobalAsm contains no Span either - it probably should (given that hir::InlineAsm has line_spans: &[Span]).

cc @Amanieu @mrhota

@eddyb eddyb added the A-inline-assembly Area: Inline assembly (`asm!(…)`) label Feb 4, 2021
@Amanieu
Copy link
Member

Amanieu commented Feb 4, 2021

It's not clear from the LLVM documentation whether !srcloc (or something equivalent) is supported for module asm

It isn't.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-enhancement Category: An issue proposing an enhancement or a PR with one. requires-nightly This issue requires a nightly compiler in some way. labels Feb 4, 2021
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-inline-assembly Area: Inline assembly (`asm!(…)`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-enhancement Category: An issue proposing an enhancement or a PR with one. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants