@@ -288,7 +288,7 @@ impl<'tcx> GotocCtx<'tcx> {
288288 } } ;
289289 }
290290
291- // Intrinsics which encode a value known during compilation (e.g., `size_of`)
291+ // Intrinsics which encode a value known during compilation
292292 macro_rules! codegen_intrinsic_const {
293293 ( ) => { {
294294 let value = self
@@ -611,7 +611,7 @@ impl<'tcx> GotocCtx<'tcx> {
611611 loc,
612612 ) ,
613613 "simd_xor" => codegen_intrinsic_binop ! ( bitxor) ,
614- "size_of" => codegen_intrinsic_const ! ( ) ,
614+ "size_of" => unreachable ! ( ) ,
615615 "size_of_val" => codegen_size_align ! ( size) ,
616616 "sqrtf32" => unstable_codegen ! ( codegen_simple_intrinsic!( Sqrtf ) ) ,
617617 "sqrtf64" => unstable_codegen ! ( codegen_simple_intrinsic!( Sqrt ) ) ,
@@ -1183,7 +1183,8 @@ impl<'tcx> GotocCtx<'tcx> {
11831183 let dst = fargs. remove ( 0 ) . cast_to ( Type :: void_pointer ( ) ) ;
11841184 let val = fargs. remove ( 0 ) . cast_to ( Type :: void_pointer ( ) ) ;
11851185 let layout = self . layout_of ( ty) ;
1186- let sz = Expr :: int_constant ( layout. size . bytes ( ) , Type :: size_t ( ) ) ;
1186+ let sz = Expr :: int_constant ( layout. size . bytes ( ) , Type :: size_t ( ) )
1187+ . with_size_of_annotation ( self . codegen_ty ( ty) ) ;
11871188 let e = BuiltinFn :: Memcmp
11881189 . call ( vec ! [ dst, val, sz] , loc)
11891190 . eq ( Type :: c_int ( ) . zero ( ) )
@@ -1267,11 +1268,12 @@ impl<'tcx> GotocCtx<'tcx> {
12671268 /// This function computes the size and alignment of a dynamically-sized type.
12681269 /// The implementations follows closely the SSA implementation found in
12691270 /// `rustc_codegen_ssa::glue::size_and_align_of_dst`.
1270- fn size_and_align_of_dst ( & self , t : Ty < ' tcx > , arg : Expr ) -> SizeAlign {
1271+ fn size_and_align_of_dst ( & mut self , t : Ty < ' tcx > , arg : Expr ) -> SizeAlign {
12711272 let layout = self . layout_of ( t) ;
12721273 let usizet = Type :: size_t ( ) ;
12731274 if !layout. is_unsized ( ) {
1274- let size = Expr :: int_constant ( layout. size . bytes_usize ( ) , Type :: size_t ( ) ) ;
1275+ let size = Expr :: int_constant ( layout. size . bytes_usize ( ) , Type :: size_t ( ) )
1276+ . with_size_of_annotation ( self . codegen_ty ( t) ) ;
12751277 let align = Expr :: int_constant ( layout. align . abi . bytes ( ) , usizet) ;
12761278 return SizeAlign { size, align } ;
12771279 }
@@ -1294,6 +1296,7 @@ impl<'tcx> GotocCtx<'tcx> {
12941296 // The info in this case is the length of the str, so the size is that
12951297 // times the unit size.
12961298 let size = Expr :: int_constant ( unit. size . bytes_usize ( ) , Type :: size_t ( ) )
1299+ . with_size_of_annotation ( self . codegen_ty ( * unit_t) )
12971300 . mul ( arg. member ( "len" , & self . symbol_table ) ) ;
12981301 let align = Expr :: int_constant ( layout. align . abi . bytes ( ) , usizet) ;
12991302 SizeAlign { size, align }
@@ -1316,7 +1319,8 @@ impl<'tcx> GotocCtx<'tcx> {
13161319 // FIXME: We assume they are aligned according to the machine-preferred alignment given by layout abi.
13171320 let n = layout. fields . count ( ) - 1 ;
13181321 let sized_size =
1319- Expr :: int_constant ( layout. fields . offset ( n) . bytes ( ) , Type :: size_t ( ) ) ;
1322+ Expr :: int_constant ( layout. fields . offset ( n) . bytes ( ) , Type :: size_t ( ) )
1323+ . with_size_of_annotation ( self . codegen_ty ( t) ) ;
13201324 let sized_align = Expr :: int_constant ( layout. align . abi . bytes ( ) , Type :: size_t ( ) ) ;
13211325
13221326 // Call this function recursively to compute the size and align for the last field.
@@ -1724,7 +1728,7 @@ impl<'tcx> GotocCtx<'tcx> {
17241728 /// * The result expression of the computation.
17251729 /// * An assertion statement to ensure the operation has not overflowed.
17261730 fn count_in_bytes (
1727- & self ,
1731+ & mut self ,
17281732 count : Expr ,
17291733 ty : Ty < ' tcx > ,
17301734 res_ty : Type ,
@@ -1733,7 +1737,8 @@ impl<'tcx> GotocCtx<'tcx> {
17331737 ) -> ( Expr , Stmt ) {
17341738 assert ! ( res_ty. is_integer( ) ) ;
17351739 let layout = self . layout_of ( ty) ;
1736- let size_of_elem = Expr :: int_constant ( layout. size . bytes ( ) , res_ty) ;
1740+ let size_of_elem = Expr :: int_constant ( layout. size . bytes ( ) , res_ty)
1741+ . with_size_of_annotation ( self . codegen_ty ( ty) ) ;
17371742 let size_of_count_elems = count. mul_overflow ( size_of_elem) ;
17381743 let message =
17391744 format ! ( "{intrinsic}: attempt to compute number in bytes which would overflow" ) ;
0 commit comments