about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-09-08 16:34:56 +0200
committerGitHub <noreply@github.com>2025-09-08 16:34:56 +0200
commit9a1feef5d8305b78a2b4955e322c2aaf628bd02b (patch)
treedbef0c0554b611194fe8f6971117d177aebcd51a /compiler/rustc_mir_transform/src
parent1e46fa94a3d53e3dbdc870658e440287eb12f617 (diff)
parent91241a1d255bde9d1bc3399c1c1f779bb17f1cfa (diff)
downloadrust-9a1feef5d8305b78a2b4955e322c2aaf628bd02b.tar.gz
rust-9a1feef5d8305b78a2b4955e322c2aaf628bd02b.zip
Rollup merge of #146298 - cjgillot:gvn-derefer, r=nnethercote
GVN: Ensure indirect is first projection in try_as_place.

I haven't found any report for this bug on existing code, but managed to trigger it with rust-lang/rust#143333
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/gvn.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs
index f867c130efb..bf6aa800d20 100644
--- a/compiler/rustc_mir_transform/src/gvn.rs
+++ b/compiler/rustc_mir_transform/src/gvn.rs
@@ -1644,6 +1644,11 @@ impl<'tcx> VnState<'_, 'tcx> {
                 let place =
                     Place { local, projection: self.tcx.mk_place_elems(projection.as_slice()) };
                 return Some(place);
+            } else if projection.last() == Some(&PlaceElem::Deref) {
+                // `Deref` can only be the first projection in a place.
+                // If we are here, we failed to find a local, and we already have a `Deref`.
+                // Trying to add projections will only result in an ill-formed place.
+                return None;
             } else if let Value::Projection(pointer, proj) = *self.get(index)
                 && (allow_complex_projection || proj.is_stable_offset())
                 && let Some(proj) = self.try_as_place_elem(self.ty(index), proj, loc)