Skip to content

Commit 67a8c16

Browse files
committed
Complete for_each_aliasing_place.
1 parent 9af191f commit 67a8c16

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

compiler/rustc_middle/src/mir/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,14 @@ impl<'tcx> PlaceRef<'tcx> {
16401640
}
16411641
}
16421642

1643+
/// Returns `true` if this `Place` contains a `Deref` projection.
1644+
///
1645+
/// If `Place::is_indirect` returns false, the caller knows that the `Place` refers to the
1646+
/// same region of memory as its base.
1647+
pub fn is_indirect(&self) -> bool {
1648+
self.projection.iter().any(|elem| elem.is_indirect())
1649+
}
1650+
16431651
/// If MirPhase >= Derefered and if projection contains Deref,
16441652
/// It's guaranteed to be in the first place
16451653
pub fn has_deref(&self) -> bool {

compiler/rustc_mir_dataflow/src/value_analysis.rs

+7
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,10 @@ impl Map {
780780
tail_elem: Option<TrackElem>,
781781
f: &mut impl FnMut(PlaceIndex),
782782
) {
783+
if place.is_indirect() {
784+
// We do not track indirect places.
785+
return;
786+
}
783787
let Some(&Some(mut index)) = self.locals.get(place.local) else {
784788
// The local is not tracked at all, so it does not alias anything.
785789
return;
@@ -790,6 +794,9 @@ impl Map {
790794
.map(|&elem| elem.try_into())
791795
.chain(tail_elem.map(Ok).into_iter());
792796
for elem in elems {
797+
// A field aliases the parent place.
798+
f(index);
799+
793800
let Ok(elem) = elem else { return };
794801
let sub = self.apply(index, elem);
795802
if let TrackElem::Variant(..) | TrackElem::Discriminant = elem {

0 commit comments

Comments
 (0)