Skip to content

Commit cd0873b

Browse files
committed
Add unit assignment to MIR for asm!()
1 parent a0648ea commit cd0873b

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

compiler/rustc_mir_build/src/build/expr/into.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
449449
})
450450
.collect();
451451

452-
let destination = this.cfg.start_new_block();
452+
if !options.contains(InlineAsmOptions::NORETURN) {
453+
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
454+
}
453455

456+
let destination_block = this.cfg.start_new_block();
454457
this.cfg.terminate(
455458
block,
456459
source_info,
@@ -462,11 +465,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
462465
destination: if options.contains(InlineAsmOptions::NORETURN) {
463466
None
464467
} else {
465-
Some(destination)
468+
Some(destination_block)
466469
},
467470
},
468471
);
469-
destination.unit()
472+
destination_block.unit()
470473
}
471474

472475
// These cases don't actually need a destination

src/test/ui/asm/issue-89305.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for #89305, where a variable was erroneously reported
2+
// as both unused and possibly-uninitialized.
3+
4+
// check-pass
5+
6+
#![feature(asm)]
7+
#![warn(unused)]
8+
9+
fn main() {
10+
unsafe {
11+
let x: () = asm!("nop");
12+
//~^ WARNING: unused variable: `x`
13+
}
14+
}

src/test/ui/asm/issue-89305.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
warning: unused variable: `x`
2+
--> $DIR/issue-89305.rs:11:13
3+
|
4+
LL | let x: () = asm!("nop");
5+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-89305.rs:7:9
9+
|
10+
LL | #![warn(unused)]
11+
| ^^^^^^
12+
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
13+
14+
warning: 1 warning emitted
15+

0 commit comments

Comments
 (0)