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
This commit is contained in:
Matthias Krüger 2025-09-08 16:34:56 +02:00 committed by GitHub
commit 9a1feef5d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)