@@ -55,14 +55,23 @@ fn insert_alignment_check<'tcx>(
5555 stmts. push ( Statement :: new ( source_info, StatementKind :: Assign ( Box :: new ( ( thin_ptr, rvalue) ) ) ) ) ;
5656
5757 // Transmute the pointer to a usize (equivalent to `ptr.addr()`).
58- let rvalue = Rvalue :: Cast ( CastKind :: Transmute , Operand :: Copy ( thin_ptr) , tcx. types . usize ) ;
58+ let rvalue = Rvalue :: Cast ( CastKind :: Transmute , Operand :: Move ( thin_ptr) , tcx. types . usize ) ;
5959 let addr = local_decls. push ( LocalDecl :: with_source_info ( tcx. types . usize , source_info) ) . into ( ) ;
6060 stmts. push ( Statement :: new ( source_info, StatementKind :: Assign ( Box :: new ( ( addr, rvalue) ) ) ) ) ;
6161
6262 // Get the alignment of the pointee
6363 let align_def_id = tcx. require_lang_item ( LangItem :: AlignOf , source_info. span ) ;
64+ let alignment_usize =
65+ local_decls. push ( LocalDecl :: with_source_info ( tcx. types . usize , source_info) ) . into ( ) ;
6466 let alignment =
6567 Operand :: unevaluated_constant ( tcx, align_def_id, & [ pointee_ty. into ( ) ] , source_info. span ) ;
68+ stmts. push ( Statement :: new (
69+ source_info,
70+ StatementKind :: Assign ( Box :: new ( (
71+ alignment_usize,
72+ Rvalue :: Cast ( CastKind :: Transmute , alignment. clone ( ) , tcx. types . usize ) ,
73+ ) ) ) ,
74+ ) ) ;
6675
6776 // Subtract 1 from the alignment to get the alignment mask
6877 let alignment_mask =
@@ -76,7 +85,7 @@ fn insert_alignment_check<'tcx>(
7685 source_info,
7786 StatementKind :: Assign ( Box :: new ( (
7887 alignment_mask,
79- Rvalue :: BinaryOp ( BinOp :: Sub , Box :: new ( ( alignment . clone ( ) , one) ) ) ,
88+ Rvalue :: BinaryOp ( BinOp :: SubUnchecked , Box :: new ( ( Operand :: Move ( alignment_usize ) , one) ) ) ,
8089 ) ) ) ,
8190 ) ) ;
8291
@@ -139,10 +148,10 @@ fn insert_alignment_check<'tcx>(
139148 // Emit a check that asserts on the alignment and otherwise triggers a
140149 // AssertKind::MisalignedPointerDereference.
141150 PointerCheck {
142- cond : Operand :: Copy ( is_ok) ,
151+ cond : Operand :: Move ( is_ok) ,
143152 assert_kind : Box :: new ( AssertKind :: MisalignedPointerDereference {
144153 required : alignment,
145- found : Operand :: Copy ( addr) ,
154+ found : Operand :: Move ( addr) ,
146155 } ) ,
147156 }
148157}
0 commit comments