File tree 1 file changed +27
-3
lines changed
compiler/rustc_mir_transform/src
1 file changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,6 @@ pub(super) struct CheckAlignment;
12
12
13
13
impl < ' tcx > crate :: MirPass < ' tcx > for CheckAlignment {
14
14
fn is_enabled ( & self , sess : & Session ) -> bool {
15
- if sess. target . max_reliable_alignment ( ) < Align :: MAX {
16
- return false ;
17
- }
18
15
sess. ub_checks ( )
19
16
}
20
17
@@ -87,6 +84,33 @@ fn insert_alignment_check<'tcx>(
87
84
) ) ) ,
88
85
} ) ;
89
86
87
+ // If this target does not have reliable alignment, further limit the mask by anding it with
88
+ // the mask for the highest reliable alignment.
89
+ #[ allow( irrefutable_let_patterns) ]
90
+ if let max_align = tcx. sess . target . max_reliable_alignment ( )
91
+ && max_align < Align :: MAX
92
+ {
93
+ let max_mask = max_align. bytes ( ) - 1 ;
94
+ let max_mask = Operand :: Constant ( Box :: new ( ConstOperand {
95
+ span : source_info. span ,
96
+ user_ty : None ,
97
+ const_ : Const :: Val (
98
+ ConstValue :: Scalar ( Scalar :: from_target_usize ( max_mask, & tcx) ) ,
99
+ tcx. types . usize ,
100
+ ) ,
101
+ } ) ) ;
102
+ stmts. push ( Statement {
103
+ source_info,
104
+ kind : StatementKind :: Assign ( Box :: new ( (
105
+ alignment_mask,
106
+ Rvalue :: BinaryOp (
107
+ BinOp :: BitAnd ,
108
+ Box :: new ( ( Operand :: Copy ( alignment_mask) , max_mask) ) ,
109
+ ) ,
110
+ ) ) ) ,
111
+ } ) ;
112
+ }
113
+
90
114
// BitAnd the alignment mask with the pointer
91
115
let alignment_bits =
92
116
local_decls. push ( LocalDecl :: with_source_info ( tcx. types . usize , source_info) ) . into ( ) ;
You can’t perform that action at this time.
0 commit comments