Skip to content

Inline asm! only checked when used #80440

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

Closed
phil-opp opened this issue Dec 28, 2020 · 3 comments
Closed

Inline asm! only checked when used #80440

phil-opp opened this issue Dec 28, 2020 · 3 comments
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@phil-opp
Copy link
Contributor

I tried this code:

#![feature(asm)]

fn main() {
    // errors if the following line is uncommented
    // foo()
}

pub fn foo() {
    unsafe {
        asm!("xchgfoobarbaz bx, bx");
    }
}

(playground)

I expected to see this happen: Compilation error because xchgfoobarbaz is not a valid assembly instruction.

Instead, this happened: The code compiles without errors or warnings. A compile error only occurs if the foo() call is uncommented in main.

Meta

Nightly version on playground: 2020-12-22 bb1fbbf

Originally reported by @tomaka in rust-osdev/x86_64#218.

@phil-opp phil-opp added the C-bug Category: This is a bug. label Dec 28, 2020
@jonas-schievink jonas-schievink added A-inline-assembly Area: Inline assembly (`asm!(…)`) F-asm `#![feature(asm)]` (not `llvm_asm`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 28, 2020
@Aaron1011
Copy link
Member

In general, I don't think it's possible to solve this. The 'invalid instruction mnemonic' error comes from LLVM - if the asm! call occurs in a generic function, then we have no way of generating LLVM IR if it's not called (and therefore monomorphized) at least once.

@asquared31415
Copy link
Contributor

If I'm not mistaken, this is a duplicate of #36718 (though its title and original code are no longer entirely correct)

@Amanieu
Copy link
Member

Amanieu commented Feb 4, 2022

Closing as duplicate of #36718.

@Amanieu Amanieu closed this as completed Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) 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

5 participants