File tree Expand file tree Collapse file tree 1 file changed +27
-3
lines changed
compiler/rustc_mir_transform/src Expand file tree Collapse file tree 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;
1212
1313impl < ' tcx > crate :: MirPass < ' tcx > for CheckAlignment {
1414 fn is_enabled ( & self , sess : & Session ) -> bool {
15- if sess. target . max_reliable_alignment ( ) < Align :: MAX {
16- return false ;
17- }
1815 sess. ub_checks ( )
1916 }
2017
@@ -87,6 +84,33 @@ fn insert_alignment_check<'tcx>(
8784 ) ) ) ,
8885 } ) ;
8986
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+
90114 // BitAnd the alignment mask with the pointer
91115 let alignment_bits =
92116 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