Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7d9c3ee

Browse files
committed
Introduce PlaceContext::may_observe_address.
1 parent 87eb56c commit 7d9c3ee

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

‎compiler/rustc_middle/src/mir/visit.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,23 @@ impl PlaceContext {
14151415
)
14161416
}
14171417

1418+
/// Returns `true` if this place context may be used to know the address of the given place.
1419+
pub fn may_observe_address(self) -> bool {
1420+
matches!(
1421+
self,
1422+
PlaceContext::NonMutatingUse(
1423+
NonMutatingUseContext::SharedBorrow
1424+
| NonMutatingUseContext::RawBorrow
1425+
| NonMutatingUseContext::FakeBorrow
1426+
) | PlaceContext::MutatingUse(
1427+
MutatingUseContext::Drop
1428+
| MutatingUseContext::Borrow
1429+
| MutatingUseContext::RawBorrow
1430+
| MutatingUseContext::AsmOutput
1431+
)
1432+
)
1433+
}
1434+
14181435
/// Returns `true` if this place context represents a storage live or storage dead marker.
14191436
#[inline]
14201437
pub fn is_storage_marker(self) -> bool {

‎compiler/rustc_mir_dataflow/src/value_analysis.rs‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet, StdEntry};
66
use rustc_data_structures::stack::ensure_sufficient_stack;
77
use rustc_index::IndexVec;
88
use rustc_index::bit_set::DenseBitSet;
9-
use rustc_middle::mir::visit::{MutatingUseContext,PlaceContext, Visitor};
9+
use rustc_middle::mir::visit::{PlaceContext, Visitor};
1010
use rustc_middle::mir::*;
1111
use rustc_middle::ty::{self, Ty, TyCtxt};
1212
use tracing::debug;
@@ -917,12 +917,7 @@ pub fn excluded_locals(body: &Body<'_>) -> DenseBitSet<Local> {
917917

918918
impl<'tcx> Visitor<'tcx> for Collector {
919919
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
920-
if (context.is_borrow()
921-
|| context.is_address_of()
922-
|| context.is_drop()
923-
|| context == PlaceContext::MutatingUse(MutatingUseContext::AsmOutput))
924-
&& !place.is_indirect()
925-
{
920+
if context.may_observe_address() && !place.is_indirect() {
926921
// A pointer to a place could be used to access other places with the same local,
927922
// hence we have to exclude the local completely.
928923
self.result.insert(place.local);

‎compiler/rustc_mir_transform/src/ssa.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ impl SsaVisitor<'_, '_> {
225225

226226
impl<'tcx> Visitor<'tcx> for SsaVisitor<'_, 'tcx> {
227227
fn visit_local(&mut self, local: Local, ctxt: PlaceContext, loc: Location) {
228+
if ctxt.may_observe_address() {
229+
self.borrowed_locals.insert(local);
230+
}
228231
match ctxt {
229232
PlaceContext::MutatingUse(MutatingUseContext::Projection)
230233
| PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) => bug!(),
@@ -237,7 +240,6 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor<'_, 'tcx> {
237240
PlaceContext::NonMutatingUse(
238241
NonMutatingUseContext::SharedBorrow | NonMutatingUseContext::FakeBorrow,
239242
) => {
240-
self.borrowed_locals.insert(local);
241243
self.check_dominates(local, loc);
242244
self.direct_uses[local] += 1;
243245
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /