Skip to content

#[inline] functions do not have their inline asm syntax checked #147275

@jonathanpallant

Description

@jonathanpallant

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)A-monomorphizationArea: MonomorphizationC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions