Skip to content
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

Variable is both used and unused when assigning asm!() to it #89305

Closed
jonas-schievink opened this issue Sep 27, 2021 · 0 comments · Fixed by #89311
Closed

Variable is both used and unused when assigning asm!() to it #89305

jonas-schievink opened this issue Sep 27, 2021 · 0 comments · Fixed by #89311
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`)

Comments

@jonas-schievink
Copy link
Contributor

#![feature(asm)]

fn main() {
    unsafe {
        let x: () = asm!("nop");
    }
}
warning: unused variable: `x`
 --> src/main.rs:5:13
  |
5 |         let x: () = asm!("nop");
  |             ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` on by default

error[E0381]: use of possibly-uninitialized variable: `x`
 --> src/main.rs:5:13
  |
5 |         let x: () = asm!("nop");
  |             ^ use of possibly-uninitialized `x`
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) A-inline-assembly Area: Inline assembly (`asm!(…)`) labels Sep 27, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 29, 2021
Add unit assignment to MIR for `asm!()`

Fixes rust-lang#89305. `ExprKind::LlvmInlineAsm` gets a `push_assign_unit()` here:
https://github.com/rust-lang/rust/blob/2b6ed3b675475abc01ce7e68bb75b457f0c85684/compiler/rustc_mir_build/src/build/expr/into.rs#L475-L479

The same should probably happen for `ExprKind::InlineAsm`, which fixes the "use of possibly-uninitialized variable" error described in rust-lang#89305.
@bors bors closed this as completed in c5f8675 Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant