`#[inline]` functions do not have their inline asm syntax checked
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#![no_std]
#[inline(always)]
pub fn checkasm() {
unsafe {
core::arch::asm!("nonsense");
}
}
#[unsafe(no_mangle)]
fn foo() {
// checkasm();
}
https://rust.godbolt.org/z/qWYnefq5a
I expected to see this happen: the lib would fail to compile
Instead, this happened: the lib compiles OK. But, if the function is actually called, then it does fail.
It is non-obvious that you can compile a library containing bad assembly if the function is marked inline(always).
See chat on Zulip: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/inline.28always.29.20caused.20inline.20assembly.20to.20not.20get.20checked/near/541817357
Meta
I've seen this on 1.89 in Godbolt and on my desktop.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the minimal #![no_std] example with #[inline(always)] and core::arch::asm!("nonsense"), both with and without a call to checkasm(). Investigate the compiler path that validates inline assembly for unused inline functions; done means the library is rejected for invalid assembly even when checkasm() is not called, with regression coverage for this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100