@@ -17,6 +17,8 @@ use cbmc::goto_program::{
17
17
use cbmc:: MachineModel ;
18
18
use cbmc:: { btree_string_map, InternString , InternedString } ;
19
19
use num:: bigint:: BigInt ;
20
+ use rustc_abi:: FieldIdx ;
21
+ use rustc_index:: vec:: IndexVec ;
20
22
use rustc_middle:: mir:: { AggregateKind , BinOp , CastKind , NullOp , Operand , Place , Rvalue , UnOp } ;
21
23
use rustc_middle:: ty:: adjustment:: PointerCast ;
22
24
use rustc_middle:: ty:: layout:: LayoutOf ;
@@ -321,7 +323,11 @@ impl<'tcx> GotocCtx<'tcx> {
321
323
}
322
324
323
325
/// Create an initializer for a generator struct.
324
- fn codegen_rvalue_generator ( & mut self , operands : & [ Operand < ' tcx > ] , ty : Ty < ' tcx > ) -> Expr {
326
+ fn codegen_rvalue_generator (
327
+ & mut self ,
328
+ operands : & IndexVec < FieldIdx , Operand < ' tcx > > ,
329
+ ty : Ty < ' tcx > ,
330
+ ) -> Expr {
325
331
let layout = self . layout_of ( ty) ;
326
332
let discriminant_field = match & layout. variants {
327
333
Variants :: Multiple { tag_encoding : TagEncoding :: Direct , tag_field, .. } => tag_field,
@@ -341,7 +347,7 @@ impl<'tcx> GotocCtx<'tcx> {
341
347
if idx == * discriminant_field {
342
348
Expr :: int_constant ( 0 , self . codegen_ty ( field_ty) )
343
349
} else {
344
- self . codegen_operand ( & operands[ idx] )
350
+ self . codegen_operand ( & operands[ idx. into ( ) ] )
345
351
}
346
352
} )
347
353
. collect ( ) ,
@@ -358,7 +364,7 @@ impl<'tcx> GotocCtx<'tcx> {
358
364
fn codegen_rvalue_enum_aggregate (
359
365
& mut self ,
360
366
variant_index : VariantIdx ,
361
- operands : & [ Operand < ' tcx > ] ,
367
+ operands : & IndexVec < FieldIdx , Operand < ' tcx > > ,
362
368
res_ty : Ty < ' tcx > ,
363
369
loc : Location ,
364
370
) -> Expr {
@@ -400,7 +406,7 @@ impl<'tcx> GotocCtx<'tcx> {
400
406
variant_expr. typ ( ) . clone ( ) ,
401
407
fields
402
408
. index_by_increasing_offset ( )
403
- . map ( |idx| self . codegen_operand ( & operands[ idx] ) )
409
+ . map ( |idx| self . codegen_operand ( & operands[ idx. into ( ) ] ) )
404
410
. collect ( ) ,
405
411
& self . symbol_table ,
406
412
) ;
@@ -419,7 +425,7 @@ impl<'tcx> GotocCtx<'tcx> {
419
425
fn codegen_rvalue_aggregate (
420
426
& mut self ,
421
427
aggregate : & AggregateKind < ' tcx > ,
422
- operands : & [ Operand < ' tcx > ] ,
428
+ operands : & IndexVec < FieldIdx , Operand < ' tcx > > ,
423
429
res_ty : Ty < ' tcx > ,
424
430
loc : Location ,
425
431
) -> Expr {
@@ -449,8 +455,8 @@ impl<'tcx> GotocCtx<'tcx> {
449
455
let components = typ. lookup_components ( & self . symbol_table ) . unwrap ( ) ;
450
456
Expr :: union_expr (
451
457
typ,
452
- components[ active_field_index] . name ( ) ,
453
- self . codegen_operand ( & operands[ 0 ] ) ,
458
+ components[ active_field_index. as_usize ( ) ] . name ( ) ,
459
+ self . codegen_operand ( & operands[ 0usize . into ( ) ] ) ,
454
460
& self . symbol_table ,
455
461
)
456
462
}
@@ -464,7 +470,7 @@ impl<'tcx> GotocCtx<'tcx> {
464
470
. fields
465
471
. index_by_increasing_offset ( )
466
472
. map ( |idx| {
467
- let cgo = self . codegen_operand ( & operands[ idx] ) ;
473
+ let cgo = self . codegen_operand ( & operands[ idx. into ( ) ] ) ;
468
474
// The input operand might actually be a one-element array, as seen
469
475
// when running assess on firecracker.
470
476
if * cgo. typ ( ) == vector_element_type {
@@ -487,7 +493,7 @@ impl<'tcx> GotocCtx<'tcx> {
487
493
layout
488
494
. fields
489
495
. index_by_increasing_offset ( )
490
- . map ( |idx| self . codegen_operand ( & operands[ idx] ) )
496
+ . map ( |idx| self . codegen_operand ( & operands[ idx. into ( ) ] ) )
491
497
. collect ( ) ,
492
498
& self . symbol_table ,
493
499
)
@@ -537,6 +543,10 @@ impl<'tcx> GotocCtx<'tcx> {
537
543
let t = self . monomorphize ( * t) ;
538
544
self . codegen_pointer_cast ( k, e, t, loc)
539
545
}
546
+ Rvalue :: Cast ( CastKind :: Transmute , operand, ty) => {
547
+ let goto_typ = self . codegen_ty ( self . monomorphize ( * ty) ) ;
548
+ self . codegen_operand ( operand) . transmute_to ( goto_typ, & self . symbol_table )
549
+ }
540
550
Rvalue :: BinaryOp ( op, box ( ref e1, ref e2) ) => {
541
551
self . codegen_rvalue_binary_op ( op, e1, e2, loc)
542
552
}
@@ -636,7 +646,7 @@ impl<'tcx> GotocCtx<'tcx> {
636
646
// See also the cranelift backend:
637
647
// https://github.com/rust-lang/rust/blob/05d22212e89588e7c443cc6b9bc0e4e02fdfbc8d/compiler/rustc_codegen_cranelift/src/discriminant.rs#L116
638
648
let offset = match & layout. fields {
639
- FieldsShape :: Arbitrary { offsets, .. } => offsets[ 0 ] ,
649
+ FieldsShape :: Arbitrary { offsets, .. } => offsets[ 0usize . into ( ) ] ,
640
650
_ => unreachable ! ( "niche encoding must have arbitrary fields" ) ,
641
651
} ;
642
652
0 commit comments