Skip to content

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

Open
@eddyb

Description

@eddyb

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-diagnosticsArea: Messages for errors, warnings, and lintsA-inline-assemblyArea: Inline assembly (`asm!(…)`)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions