Skip to content

Commit 9a1feef

Browse files
authored
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 #143333
2 parents 1e46fa9 + 91241a1 commit 9a1feef

File tree

1 file changed

+5
-0
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+5
-0
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,11 @@ impl<'tcx> VnState<'_, 'tcx> {
16441644
let place =
16451645
Place { local, projection: self.tcx.mk_place_elems(projection.as_slice()) };
16461646
return Some(place);
1647+
} else if projection.last() == Some(&PlaceElem::Deref) {
1648+
// `Deref` can only be the first projection in a place.
1649+
// If we are here, we failed to find a local, and we already have a `Deref`.
1650+
// Trying to add projections will only result in an ill-formed place.
1651+
return None;
16471652
} else if let Value::Projection(pointer, proj) = *self.get(index)
16481653
&& (allow_complex_projection || proj.is_stable_offset())
16491654
&& let Some(proj) = self.try_as_place_elem(self.ty(index), proj, loc)

0 commit comments

Comments
 (0)