diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-05-04 12:37:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-04 12:37:22 +0200 |
| commit | ceb7b5e70e696cf8d4e6294a112bf23c356ffece (patch) | |
| tree | ccc7f5152973272edeae6282298e2ba624fda988 /compiler/rustc_const_eval/src/const_eval/machine.rs | |
| parent | cc51f91455847436fdf2c2634a39e50063453524 (diff) | |
| parent | 4e97c6c5c77fa165e46b7cb1f77917ebf38ad20f (diff) | |
| download | rust-ceb7b5e70e696cf8d4e6294a112bf23c356ffece.tar.gz rust-ceb7b5e70e696cf8d4e6294a112bf23c356ffece.zip | |
Rollup merge of #124293 - oli-obk:miri_intrinsic_fallback_body, r=RalfJung
Let miri and const eval execute intrinsics' fallback bodies fixes https://github.com/rust-lang/miri/issues/3397 r? ``@RalfJung``
Diffstat (limited to 'compiler/rustc_const_eval/src/const_eval/machine.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/const_eval/machine.rs | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index dd835279df3..e9cf5a3d769 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -459,16 +459,26 @@ 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. We can't handle any of them (that are not already + // handled above), but check if there is 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, + })); }; match intrinsic_name { sym::ptr_guaranteed_cmp => { @@ -536,14 +546,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( |
