1212//! will still not cause any further changes.
1313//!
1414
15- use crate :: util:: is_disaligned ;
15+ use crate :: util:: is_within_packed ;
1616use rustc_index:: bit_set:: BitSet ;
1717use rustc_middle:: mir:: visit:: Visitor ;
1818use rustc_middle:: mir:: * ;
@@ -32,8 +32,6 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
3232 . iterate_to_fixpoint ( )
3333 . into_results_cursor ( body) ;
3434
35- let param_env = tcx. param_env_reveal_all_normalized ( body. source . def_id ( ) ) ;
36-
3735 // For blocks with a call terminator, if an argument copy can be turned into a move,
3836 // record it as (block, argument index).
3937 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
5250 && !place. is_indirect ( )
5351 && !borrowed. contains ( place. local )
5452 && !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 ( )
5658 {
5759 call_operands_to_move. push ( ( bb, index) ) ;
5860 }
0 commit comments