@@ -459,16 +459,26 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
459
459
dest : & MPlaceTy < ' tcx , Self :: Provenance > ,
460
460
target : Option < mir:: BasicBlock > ,
461
461
_unwind : mir:: UnwindAction ,
462
- ) -> InterpResult < ' tcx > {
462
+ ) -> InterpResult < ' tcx , Option < ty :: Instance < ' tcx > > > {
463
463
// Shared intrinsics.
464
464
if ecx. emulate_intrinsic ( instance, args, dest, target) ? {
465
- return Ok ( ( ) ) ;
465
+ return Ok ( None ) ;
466
466
}
467
467
let intrinsic_name = ecx. tcx . item_name ( instance. def_id ( ) ) ;
468
468
469
469
// CTFE-specific intrinsics.
470
470
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
+ } ) ) ;
472
482
} ;
473
483
match intrinsic_name {
474
484
sym:: ptr_guaranteed_cmp => {
@@ -536,14 +546,21 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
536
546
// not the optimization stage.)
537
547
sym:: is_val_statically_known => ecx. write_scalar ( Scalar :: from_bool ( false ) , dest) ?,
538
548
_ => {
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
+ } ) ) ;
542
559
}
543
560
}
544
561
545
562
ecx. go_to_block ( ret) ;
546
- Ok ( ( ) )
563
+ Ok ( None )
547
564
}
548
565
549
566
fn assert_panic (
0 commit comments