@@ -288,7 +288,7 @@ impl<'tcx> GotocCtx<'tcx> {
288
288
} } ;
289
289
}
290
290
291
- // Intrinsics which encode a value known during compilation (e.g., `size_of`)
291
+ // Intrinsics which encode a value known during compilation
292
292
macro_rules! codegen_intrinsic_const {
293
293
( ) => { {
294
294
let value = self
@@ -611,7 +611,7 @@ impl<'tcx> GotocCtx<'tcx> {
611
611
loc,
612
612
) ,
613
613
"simd_xor" => codegen_intrinsic_binop ! ( bitxor) ,
614
- "size_of" => codegen_intrinsic_const ! ( ) ,
614
+ "size_of" => unreachable ! ( ) ,
615
615
"size_of_val" => codegen_size_align ! ( size) ,
616
616
"sqrtf32" => unstable_codegen ! ( codegen_simple_intrinsic!( Sqrtf ) ) ,
617
617
"sqrtf64" => unstable_codegen ! ( codegen_simple_intrinsic!( Sqrt ) ) ,
@@ -1183,7 +1183,8 @@ impl<'tcx> GotocCtx<'tcx> {
1183
1183
let dst = fargs. remove ( 0 ) . cast_to ( Type :: void_pointer ( ) ) ;
1184
1184
let val = fargs. remove ( 0 ) . cast_to ( Type :: void_pointer ( ) ) ;
1185
1185
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) ) ;
1187
1188
let e = BuiltinFn :: Memcmp
1188
1189
. call ( vec ! [ dst, val, sz] , loc)
1189
1190
. eq ( Type :: c_int ( ) . zero ( ) )
@@ -1267,11 +1268,12 @@ impl<'tcx> GotocCtx<'tcx> {
1267
1268
/// This function computes the size and alignment of a dynamically-sized type.
1268
1269
/// The implementations follows closely the SSA implementation found in
1269
1270
/// `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 {
1271
1272
let layout = self . layout_of ( t) ;
1272
1273
let usizet = Type :: size_t ( ) ;
1273
1274
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) ) ;
1275
1277
let align = Expr :: int_constant ( layout. align . abi . bytes ( ) , usizet) ;
1276
1278
return SizeAlign { size, align } ;
1277
1279
}
@@ -1294,6 +1296,7 @@ impl<'tcx> GotocCtx<'tcx> {
1294
1296
// The info in this case is the length of the str, so the size is that
1295
1297
// times the unit size.
1296
1298
let size = Expr :: int_constant ( unit. size . bytes_usize ( ) , Type :: size_t ( ) )
1299
+ . with_size_of_annotation ( self . codegen_ty ( * unit_t) )
1297
1300
. mul ( arg. member ( "len" , & self . symbol_table ) ) ;
1298
1301
let align = Expr :: int_constant ( layout. align . abi . bytes ( ) , usizet) ;
1299
1302
SizeAlign { size, align }
@@ -1316,7 +1319,8 @@ impl<'tcx> GotocCtx<'tcx> {
1316
1319
// FIXME: We assume they are aligned according to the machine-preferred alignment given by layout abi.
1317
1320
let n = layout. fields . count ( ) - 1 ;
1318
1321
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) ) ;
1320
1324
let sized_align = Expr :: int_constant ( layout. align . abi . bytes ( ) , Type :: size_t ( ) ) ;
1321
1325
1322
1326
// Call this function recursively to compute the size and align for the last field.
@@ -1724,7 +1728,7 @@ impl<'tcx> GotocCtx<'tcx> {
1724
1728
/// * The result expression of the computation.
1725
1729
/// * An assertion statement to ensure the operation has not overflowed.
1726
1730
fn count_in_bytes (
1727
- & self ,
1731
+ & mut self ,
1728
1732
count : Expr ,
1729
1733
ty : Ty < ' tcx > ,
1730
1734
res_ty : Type ,
@@ -1733,7 +1737,8 @@ impl<'tcx> GotocCtx<'tcx> {
1733
1737
) -> ( Expr , Stmt ) {
1734
1738
assert ! ( res_ty. is_integer( ) ) ;
1735
1739
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) ) ;
1737
1742
let size_of_count_elems = count. mul_overflow ( size_of_elem) ;
1738
1743
let message =
1739
1744
format ! ( "{intrinsic}: attempt to compute number in bytes which would overflow" ) ;
0 commit comments