Skip to content

Commit 0f7f574

Browse files
committed
Do not flatten derefs with ProjectionElem::Index.
1 parent b3e07a8 commit 0f7f574

File tree

1 file changed

+13
-2
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+13
-2
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,13 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
756756
&& let Some(v) = self.simplify_place_value(&mut pointee, location)
757757
{
758758
value = v;
759-
place_ref = pointee.project_deeper(&place.projection[index..], self.tcx).as_ref();
759+
// `pointee` holds a `Place`, so `ProjectionElem::Index` holds a `Local`.
760+
// That local is SSA, but we otherwise have no guarantee on that local's value at
761+
// the current location compared to its value where `pointee` was borrowed.
762+
if pointee.projection.iter().all(|elem| !matches!(elem, ProjectionElem::Index(_))) {
763+
place_ref =
764+
pointee.project_deeper(&place.projection[index..], self.tcx).as_ref();
765+
}
760766
}
761767
if let Some(local) = self.try_as_local(value, location) {
762768
// Both `local` and `Place { local: place.local, projection: projection[..index] }`
@@ -774,7 +780,12 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
774780
&& let Some(v) = self.simplify_place_value(&mut pointee, location)
775781
{
776782
value = v;
777-
place_ref = pointee.project_deeper(&[], self.tcx).as_ref();
783+
// `pointee` holds a `Place`, so `ProjectionElem::Index` holds a `Local`.
784+
// That local is SSA, but we otherwise have no guarantee on that local's value at
785+
// the current location compared to its value where `pointee` was borrowed.
786+
if pointee.projection.iter().all(|elem| !matches!(elem, ProjectionElem::Index(_))) {
787+
place_ref = pointee.project_deeper(&[], self.tcx).as_ref();
788+
}
778789
}
779790
if let Some(new_local) = self.try_as_local(value, location) {
780791
place_ref = PlaceRef { local: new_local, projection: &[] };

0 commit comments

Comments
 (0)