Rust-GCC / gccrs

GCC Front-End for Rust
https://rust-gcc.github.io/
GNU General Public License v2.0
2.37k stars 152 forks source link

Typechecking of asm! failed in `let _` #3061

Closed badumbatish closed 1 month ago

badumbatish commented 3 months ago

I tried this code:

#![feature(rustc_attrs)]

#[rustc_builtin_macro]
macro_rules! asm {
    () => {}
}

fn main() {
    unsafe {
        let _ = asm!("nop");
    }
}

I expected to see this happen: Nothing should error out, as expected from rustc

Instead, this happened: gccrs errors out with

/home/workspace/gccrs/gcc/testsuite/rust/compile/inline_asm_compile_nop.rs:10:9: fatal error: failed to lookup variable declaration type
   10 |         let _ = asm!("nop");
      |         ^~~
compilation terminated.

From Arthur Cohen

the error that gccrs is spitting out, but not rustc, is due to typechecking. we haven't yet done any typechecking for HIR::InlineAsm nodes, so when the typechecker tries to check everything is okay for an HIR::LetStmt, it fails to lookup the type of the let's expression

Meta

badumbatish commented 3 months ago

the asm! returns () on default, and ! when the option(no_return) is added (from bjorn3)

badumbatish commented 1 month ago

closable by #3060