Let miri and const eval execute intrinsics' fallback bodies
This commit is contained in:
parent
c65b2dc935
commit
351658ae66
9 changed files with 71 additions and 45 deletions
|
@ -105,7 +105,7 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for DummyMachine {
|
|||
_destination: &interpret::MPlaceTy<'tcx, Self::Provenance>,
|
||||
_target: Option<BasicBlock>,
|
||||
_unwind: UnwindAction,
|
||||
) -> interpret::InterpResult<'tcx> {
|
||||
) -> interpret::InterpResult<'tcx, Option<ty::Instance<'tcx>>> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
|
|
@ -459,16 +459,25 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
dest: &MPlaceTy<'tcx, Self::Provenance>,
|
||||
target: Option<mir::BasicBlock>,
|
||||
_unwind: mir::UnwindAction,
|
||||
) -> InterpResult<'tcx> {
|
||||
) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> {
|
||||
// Shared intrinsics.
|
||||
if ecx.emulate_intrinsic(instance, args, dest, target)? {
|
||||
return Ok(());
|
||||
return Ok(None);
|
||||
}
|
||||
let intrinsic_name = ecx.tcx.item_name(instance.def_id());
|
||||
|
||||
// CTFE-specific intrinsics.
|
||||
let Some(ret) = target else {
|
||||
throw_unsup_format!("intrinsic `{intrinsic_name}` is not supported at compile-time");
|
||||
// Handle diverging intrinsics.
|
||||
if ecx.tcx.intrinsic(instance.def_id()).unwrap().must_be_overridden {
|
||||
throw_unsup_format!(
|
||||
"intrinsic `{intrinsic_name}` is not supported at compile-time"
|
||||
);
|
||||
}
|
||||
return Ok(Some(ty::Instance {
|
||||
def: ty::InstanceDef::Item(instance.def_id()),
|
||||
args: instance.args,
|
||||
}));
|
||||
};
|
||||
match intrinsic_name {
|
||||
sym::ptr_guaranteed_cmp => {
|
||||
|
@ -536,14 +545,21 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
// not the optimization stage.)
|
||||
sym::is_val_statically_known => ecx.write_scalar(Scalar::from_bool(false), dest)?,
|
||||
_ => {
|
||||
throw_unsup_format!(
|
||||
"intrinsic `{intrinsic_name}` is not supported at compile-time"
|
||||
);
|
||||
// We haven't handled the intrinsic, let's see if we can use a fallback body.
|
||||
if ecx.tcx.intrinsic(instance.def_id()).unwrap().must_be_overridden {
|
||||
throw_unsup_format!(
|
||||
"intrinsic `{intrinsic_name}` is not supported at compile-time"
|
||||
);
|
||||
}
|
||||
return Ok(Some(ty::Instance {
|
||||
def: ty::InstanceDef::Item(instance.def_id()),
|
||||
args: instance.args,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
ecx.go_to_block(ret);
|
||||
Ok(())
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn assert_panic(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue