@@ -459,16 +459,26 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
459459 dest : & MPlaceTy < ' tcx , Self :: Provenance > ,
460460 target : Option < mir:: BasicBlock > ,
461461 _unwind : mir:: UnwindAction ,
462- ) -> InterpResult < ' tcx > {
462+ ) -> InterpResult < ' tcx , Option < ty :: Instance < ' tcx > > > {
463463 // Shared intrinsics.
464464 if ecx. emulate_intrinsic ( instance, args, dest, target) ? {
465- return Ok ( ( ) ) ;
465+ return Ok ( None ) ;
466466 }
467467 let intrinsic_name = ecx. tcx . item_name ( instance. def_id ( ) ) ;
468468
469469 // CTFE-specific intrinsics.
470470 let Some ( ret) = target else {
471- throw_unsup_format ! ( "intrinsic `{intrinsic_name}` is not supported at compile-time" ) ;
471+ // Handle diverging intrinsics. We can't handle any of them (that are not already
472+ // handled above), but check if there is a fallback body.
473+ if ecx. tcx . intrinsic ( instance. def_id ( ) ) . unwrap ( ) . must_be_overridden {
474+ throw_unsup_format ! (
475+ "intrinsic `{intrinsic_name}` is not supported at compile-time"
476+ ) ;
477+ }
478+ return Ok ( Some ( ty:: Instance {
479+ def : ty:: InstanceDef :: Item ( instance. def_id ( ) ) ,
480+ args : instance. args ,
481+ } ) ) ;
472482 } ;
473483 match intrinsic_name {
474484 sym:: ptr_guaranteed_cmp => {
@@ -536,14 +546,21 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
536546 // not the optimization stage.)
537547 sym:: is_val_statically_known => ecx. write_scalar ( Scalar :: from_bool ( false ) , dest) ?,
538548 _ => {
539- throw_unsup_format ! (
540- "intrinsic `{intrinsic_name}` is not supported at compile-time"
541- ) ;
549+ // We haven't handled the intrinsic, let's see if we can use a fallback body.
550+ if ecx. tcx . intrinsic ( instance. def_id ( ) ) . unwrap ( ) . must_be_overridden {
551+ throw_unsup_format ! (
552+ "intrinsic `{intrinsic_name}` is not supported at compile-time"
553+ ) ;
554+ }
555+ return Ok ( Some ( ty:: Instance {
556+ def : ty:: InstanceDef :: Item ( instance. def_id ( ) ) ,
557+ args : instance. args ,
558+ } ) ) ;
542559 }
543560 }
544561
545562 ecx. go_to_block ( ret) ;
546- Ok ( ( ) )
563+ Ok ( None )
547564 }
548565
549566 fn assert_panic (
0 commit comments