Skip to content

Rust inline asm with generics and macros builds using --release, fails in debug #106838

Closed
@danlehmann

Description

@danlehmann

I tried this code:

use std::arch::{asm, global_asm};

global_asm!("
.macro test
.endm
");

fn function<const N: u32>() {
    unsafe {
        asm!("test", options(noreturn))
    }
}

fn main() {
    function::<1>()
}

I expected to see this happen: This code should work when compiling for release and debug.

Instead, this happened: It builds fine using --release. In debug mode, the inline assembler can't see the macro test.

I'd expect that either both Debug and Release work or that both fail equally.

~/CLionProjects/untitled1 % cargo run                                                   
   Compiling untitled1 v0.1.0 (/Users/daniel/CLionProjects/untitled1)
error: unrecognized instruction mnemonic, did you mean: tst?
  --> src/main.rs:11:15
   |
11 |         asm!("test", options(noreturn))
   |               ^
   |
note: instantiated into assembly here
  --> <inline asm>:1:2
   |
1  |     test
   |     ^

error: could not compile `untitled1` due to previous error



~/CLionProjects/untitled1 % cargo run --release
   Compiling untitled1 v0.1.0 (/Users/daniel/CLionProjects/untitled1)
    Finished release [optimized] target(s) in 0.10s
     Running `target/release/untitled1`

Meta

rustc --version --verbose:

rustc 1.68.0-nightly (3020239de 2023-01-09)
binary: rustc
commit-hash: 3020239de947ec52677e9b4e853a6a9fc073d1f9
commit-date: 2023-01-09
host: aarch64-apple-darwin
release: 1.68.0-nightly
LLVM version: 15.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions