Introduce PlaceContext::may_observe_address.
This commit is contained in:
committed by
Camille Gillot
parent
bea625f327
commit
4e7a068c9a
@@ -1415,6 +1415,24 @@ impl PlaceContext {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if this place context may be used to know the address of the given place.
|
||||||
|
#[inline]
|
||||||
|
pub fn may_observe_address(self) -> bool {
|
||||||
|
matches!(
|
||||||
|
self,
|
||||||
|
PlaceContext::NonMutatingUse(
|
||||||
|
NonMutatingUseContext::SharedBorrow
|
||||||
|
| NonMutatingUseContext::RawBorrow
|
||||||
|
| NonMutatingUseContext::FakeBorrow
|
||||||
|
) | PlaceContext::MutatingUse(
|
||||||
|
MutatingUseContext::Drop
|
||||||
|
| MutatingUseContext::Borrow
|
||||||
|
| MutatingUseContext::RawBorrow
|
||||||
|
| MutatingUseContext::AsmOutput
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `true` if this place context represents a storage live or storage dead marker.
|
/// Returns `true` if this place context represents a storage live or storage dead marker.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_storage_marker(self) -> bool {
|
pub fn is_storage_marker(self) -> bool {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet, StdEntry};
|
|||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_index::IndexVec;
|
use rustc_index::IndexVec;
|
||||||
use rustc_index::bit_set::DenseBitSet;
|
use rustc_index::bit_set::DenseBitSet;
|
||||||
use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor};
|
use rustc_middle::mir::visit::{PlaceContext, Visitor};
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
@@ -917,12 +917,7 @@ pub fn excluded_locals(body: &Body<'_>) -> DenseBitSet<Local> {
|
|||||||
|
|
||||||
impl<'tcx> Visitor<'tcx> for Collector {
|
impl<'tcx> Visitor<'tcx> for Collector {
|
||||||
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
|
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
|
||||||
if (context.is_borrow()
|
if context.may_observe_address() && !place.is_indirect() {
|
||||||
|| context.is_address_of()
|
|
||||||
|| context.is_drop()
|
|
||||||
|| context == PlaceContext::MutatingUse(MutatingUseContext::AsmOutput))
|
|
||||||
&& !place.is_indirect()
|
|
||||||
{
|
|
||||||
// A pointer to a place could be used to access other places with the same local,
|
// A pointer to a place could be used to access other places with the same local,
|
||||||
// hence we have to exclude the local completely.
|
// hence we have to exclude the local completely.
|
||||||
self.result.insert(place.local);
|
self.result.insert(place.local);
|
||||||
|
|||||||
@@ -225,6 +225,9 @@ impl SsaVisitor<'_, '_> {
|
|||||||
|
|
||||||
impl<'tcx> Visitor<'tcx> for SsaVisitor<'_, 'tcx> {
|
impl<'tcx> Visitor<'tcx> for SsaVisitor<'_, 'tcx> {
|
||||||
fn visit_local(&mut self, local: Local, ctxt: PlaceContext, loc: Location) {
|
fn visit_local(&mut self, local: Local, ctxt: PlaceContext, loc: Location) {
|
||||||
|
if ctxt.may_observe_address() {
|
||||||
|
self.borrowed_locals.insert(local);
|
||||||
|
}
|
||||||
match ctxt {
|
match ctxt {
|
||||||
PlaceContext::MutatingUse(MutatingUseContext::Projection)
|
PlaceContext::MutatingUse(MutatingUseContext::Projection)
|
||||||
| PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) => bug!(),
|
| PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) => bug!(),
|
||||||
@@ -237,7 +240,6 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor<'_, 'tcx> {
|
|||||||
PlaceContext::NonMutatingUse(
|
PlaceContext::NonMutatingUse(
|
||||||
NonMutatingUseContext::SharedBorrow | NonMutatingUseContext::FakeBorrow,
|
NonMutatingUseContext::SharedBorrow | NonMutatingUseContext::FakeBorrow,
|
||||||
) => {
|
) => {
|
||||||
self.borrowed_locals.insert(local);
|
|
||||||
self.check_dominates(local, loc);
|
self.check_dominates(local, loc);
|
||||||
self.direct_uses[local] += 1;
|
self.direct_uses[local] += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user