diff options
| author | Eric Huss <eric@huss.org> | 2021-09-29 19:33:39 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-29 19:33:39 -0700 |
| commit | c5f8675291de47c5a189b750feb8cd2c3fef6f73 (patch) | |
| tree | ded416035cfedbef2b5a38990a41c7023d293c4b | |
| parent | 8dfe52293a61aaa4ff44b20d538c52ddc7834617 (diff) | |
| parent | cd0873b50276bca8bfcaf8d12beeb28d3fffb692 (diff) | |
| download | rust-c5f8675291de47c5a189b750feb8cd2c3fef6f73.tar.gz rust-c5f8675291de47c5a189b750feb8cd2c3fef6f73.zip | |
Rollup merge of #89311 - FabianWolff:issue-89305, r=oli-obk
Add unit assignment to MIR for `asm!()` Fixes #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 #89305.
| -rw-r--r-- | compiler/rustc_mir_build/src/build/expr/into.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/asm/issue-89305.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/asm/issue-89305.stderr | 15 |
3 files changed, 35 insertions, 3 deletions
diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index 1803a18441c..53868f28557 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -449,8 +449,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }) .collect(); - let destination = this.cfg.start_new_block(); + if !options.contains(InlineAsmOptions::NORETURN) { + this.cfg.push_assign_unit(block, source_info, destination, this.tcx); + } + let destination_block = this.cfg.start_new_block(); this.cfg.terminate( block, source_info, @@ -462,11 +465,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { destination: if options.contains(InlineAsmOptions::NORETURN) { None } else { - Some(destination) + Some(destination_block) }, }, ); - destination.unit() + destination_block.unit() } // These cases don't actually need a destination diff --git a/src/test/ui/asm/issue-89305.rs b/src/test/ui/asm/issue-89305.rs new file mode 100644 index 00000000000..bdcf3f305eb --- /dev/null +++ b/src/test/ui/asm/issue-89305.rs @@ -0,0 +1,14 @@ +// Regression test for #89305, where a variable was erroneously reported +// as both unused and possibly-uninitialized. + +// check-pass + +#![feature(asm)] +#![warn(unused)] + +fn main() { + unsafe { + let x: () = asm!("nop"); + //~^ WARNING: unused variable: `x` + } +} diff --git a/src/test/ui/asm/issue-89305.stderr b/src/test/ui/asm/issue-89305.stderr new file mode 100644 index 00000000000..9cc127b44d0 --- /dev/null +++ b/src/test/ui/asm/issue-89305.stderr @@ -0,0 +1,15 @@ +warning: unused variable: `x` + --> $DIR/issue-89305.rs:11:13 + | +LL | let x: () = asm!("nop"); + | ^ help: if this is intentional, prefix it with an underscore: `_x` + | +note: the lint level is defined here + --> $DIR/issue-89305.rs:7:9 + | +LL | #![warn(unused)] + | ^^^^^^ + = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]` + +warning: 1 warning emitted + |
