@@ -7,10 +7,10 @@ use std::assert_matches::assert_matches;
77use rustc_abi:: { FieldIdx , HasDataLayout , Size } ;
88use rustc_apfloat:: ieee:: { Double , Half , Quad , Single } ;
99use rustc_middle:: mir:: interpret:: { CTFE_ALLOC_SALT , read_target_uint, write_target_uint} ;
10- use rustc_middle:: mir:: { self , BinOp , ConstValue , NonDivergingIntrinsic } ;
10+ use rustc_middle:: mir:: { self , BinOp , ConstValue , NonDivergingIntrinsic , NullOp } ;
1111use rustc_middle:: ty:: layout:: TyAndLayout ;
1212use rustc_middle:: ty:: { Ty , TyCtxt } ;
13- use rustc_middle:: { bug, ty} ;
13+ use rustc_middle:: { bug, err_inval , span_bug , ty} ;
1414use rustc_span:: { Symbol , sym} ;
1515use tracing:: trace;
1616
@@ -638,6 +638,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
638638 rustc_apfloat:: Round :: NearestTiesToEven ,
639639 ) ?,
640640
641+ sym:: unaligned_field_offset => self . unaligned_field_offset ( instance, dest) ?,
642+
641643 // Unsupported intrinsic: skip the return_to_block below.
642644 _ => return interp_ok ( false ) ,
643645 }
@@ -647,6 +649,25 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
647649 interp_ok ( true )
648650 }
649651
652+ fn unaligned_field_offset (
653+ & mut self ,
654+ instance : ty:: Instance < ' tcx > ,
655+ dest : & PlaceTy < ' tcx , M :: Provenance > ,
656+ ) -> InterpResult < ' tcx , ( ) > {
657+ assert_eq ! ( instance. args. len( ) , 1 ) ;
658+ let ty = instance. args . type_at ( 0 ) ;
659+ match ty. kind ( ) {
660+ & ty:: Field ( container, field_path) => {
661+ let offset = self . nullary_op ( NullOp :: OffsetOf ( field_path) , container) ?;
662+ self . write_immediate ( * offset, dest)
663+ }
664+ ty:: Alias ( ..) | ty:: Param ( ..) | ty:: Placeholder ( ..) | ty:: Infer ( ..) => {
665+ Err ( err_inval ! ( TooGeneric ) ) . into ( )
666+ }
667+ _ => span_bug ! ( self . cur_span( ) , "expected field representing type, found {ty}" ) ,
668+ }
669+ }
670+
650671 pub ( super ) fn eval_nondiverging_intrinsic (
651672 & mut self ,
652673 intrinsic : & NonDivergingIntrinsic < ' tcx > ,
0 commit comments