File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed
compiler/rustc_mir_transform/src Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -117,8 +117,10 @@ impl<'tcx> Visitor<'tcx> for SsaLocals {
117117 self . assignments [ local] . insert ( LocationExtended :: Plain ( loc) ) ;
118118 self . assignment_order . push ( local) ;
119119 }
120- PlaceContext :: MutatingUse ( _) => self . assignments [ local] = Set1 :: Many ,
121- // Immutable borrows and AddressOf are taken into account in `SsaLocals::new` by
120+ // Anything can happen with raw pointers, so remove them.
121+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: AddressOf )
122+ | PlaceContext :: MutatingUse ( _) => self . assignments [ local] = Set1 :: Many ,
123+ // Immutable borrows are taken into account in `SsaLocals::new` by
122124 // removing non-freeze locals.
123125 PlaceContext :: NonMutatingUse ( _) => {
124126 let set = & mut self . assignments [ local] ;
Original file line number Diff line number Diff line change 1+ - // MIR for `f` before CopyProp
2+ + // MIR for `f` after CopyProp
3+
4+ fn f(_1: bool) -> bool {
5+ let mut _0: bool; // return place in scope 0 at $DIR/mutate_through_pointer.rs:+0:18: +0:22
6+ let mut _2: bool; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
7+ let mut _3: *const bool; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
8+ let mut _4: *mut bool; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
9+
10+ bb0: {
11+ _2 = _1; // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
12+ _3 = &raw const _2; // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
13+ _4 = &raw mut (*_3); // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
14+ (*_4) = const false; // scope 0 at $DIR/mutate_through_pointer.rs:+5:9: +5:20
15+ _0 = _1; // scope 0 at $DIR/mutate_through_pointer.rs:+6:9: +6:16
16+ return; // scope 0 at $DIR/mutate_through_pointer.rs:+7:9: +7:17
17+ }
18+ }
19+
Original file line number Diff line number Diff line change 1+ #![ feature( custom_mir, core_intrinsics) ]
2+ #![ allow( unused_assignments) ]
3+ extern crate core;
4+ use core:: intrinsics:: mir:: * ;
5+
6+ #[ custom_mir( dialect = "analysis" , phase = "post-cleanup" ) ]
7+ fn f ( c : bool ) -> bool {
8+ mir ! ( {
9+ let a = c;
10+ let p = core:: ptr:: addr_of!( a) ;
11+ let p2 = core:: ptr:: addr_of_mut!( * p) ;
12+ * p2 = false ;
13+ RET = c;
14+ Return ( )
15+ } )
16+ }
17+
18+ fn main ( ) {
19+ assert_eq ! ( true , f( true ) ) ;
20+ }
21+
22+ // EMIT_MIR mutate_through_pointer.f.CopyProp.diff
You can’t perform that action at this time.
0 commit comments