12
12
//! will still not cause any further changes.
13
13
//!
14
14
15
- use crate :: util:: is_disaligned ;
15
+ use crate :: util:: is_within_packed ;
16
16
use rustc_index:: bit_set:: BitSet ;
17
17
use rustc_middle:: mir:: visit:: Visitor ;
18
18
use rustc_middle:: mir:: * ;
@@ -32,8 +32,6 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
32
32
. iterate_to_fixpoint ( )
33
33
. into_results_cursor ( body) ;
34
34
35
- let param_env = tcx. param_env_reveal_all_normalized ( body. source . def_id ( ) ) ;
36
-
37
35
// For blocks with a call terminator, if an argument copy can be turned into a move,
38
36
// record it as (block, argument index).
39
37
let mut call_operands_to_move = Vec :: new ( ) ;
@@ -52,7 +50,11 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
52
50
&& !place. is_indirect ( )
53
51
&& !borrowed. contains ( place. local )
54
52
&& !state. contains ( place. local )
55
- && !is_disaligned ( tcx, body, param_env, place)
53
+ // If `place` is a projection of a disaligned field in a packed ADT,
54
+ // the move may be codegened as a pointer to that field.
55
+ // Using that disaligned pointer may trigger UB in the callee,
56
+ // so do nothing.
57
+ && is_within_packed ( tcx, body, place) . is_none ( )
56
58
{
57
59
call_operands_to_move. push ( ( bb, index) ) ;
58
60
}
0 commit comments