diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-05-31 17:28:24 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2023-05-31 17:28:24 +0000 |
| commit | f74695b01005e63583c32f0334ee8eb9557dec00 (patch) | |
| tree | ea6935de1b0b21f40e3bd74cb31e0be9a2850f1d /compiler/rustc_mir_transform/src | |
| parent | e11e4081df2a23914e1552b82b8e4b8c7bc457cb (diff) | |
| download | rust-f74695b01005e63583c32f0334ee8eb9557dec00.tar.gz rust-f74695b01005e63583c32f0334ee8eb9557dec00.zip | |
Document handling of StorageDead.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/const_prop.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 39e26e4a8e4..40c7b5a1645 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -889,6 +889,21 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> { StatementKind::StorageLive(local) => { Self::remove_const(&mut self.ecx, local); } + // We do not need to mark dead locals as such. For `FullConstProp` locals, + // this allows to propagate the single assigned value in this case: + // ``` + // let x = SOME_CONST; + // if a { + // f(copy x); + // StorageDead(x); + // } else { + // g(copy x); + // StorageDead(x); + // } + // ``` + // + // This may propagate a constant where the local would be uninit or dead. + // In both cases, this does not matter, as those reads would be UB anyway. _ => {} } } |
