Skip to content

Commit 4ecb80d

Browse files
committed
Remove trampoline, pass ret and unwind when handling intrinsics
1 parent 607339f commit 4ecb80d

File tree

7 files changed

+13
-23
lines changed

7 files changed

+13
-23
lines changed

src/libpanic_unwind/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ cfg_if::cfg_if! {
3939
if #[cfg(miri)] {
4040
#[path = "miri.rs"]
4141
mod imp;
42-
// Export this at the root of the crate so that Miri
43-
// has a stable palce to look it up
44-
pub use imp::miri_panic_trampoline;
4542
} else if #[cfg(target_os = "emscripten")] {
4643
#[path = "emcc.rs"]
4744
mod imp;

src/libpanic_unwind/miri.rs

-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,3 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
2121
fn rust_eh_personality() {
2222
unsafe { core::intrinsics::abort() }
2323
}
24-
25-
// A dummy helper function for Miri.
26-
// Used to push an empty stack frame when we start unwinding
27-
#[cfg(miri)]
28-
pub fn miri_panic_trampoline() {}

src/librustc_mir/const_eval.rs

+2
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
376376
instance: ty::Instance<'tcx>,
377377
args: &[OpTy<'tcx>],
378378
dest: Option<PlaceTy<'tcx>>,
379+
_ret: Option<mir::BasicBlock>,
380+
_unwind: Option<mir::BasicBlock>
379381
) -> InterpResult<'tcx> {
380382
if ecx.emulate_intrinsic(span, instance, args, dest)? {
381383
return Ok(());

src/librustc_mir/interpret/eval_context.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -585,21 +585,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
585585
"tried to pop a stack frame, but there were none",
586586
);
587587
let stack_pop_info = M::stack_pop(self, frame.extra, unwinding)?;
588-
match (unwinding, stack_pop_info) {
589-
(true, StackPopInfo::StartUnwinding) =>
590-
bug!("Attempted to start unwinding while already unwinding!"),
591-
(false, StackPopInfo::StopUnwinding) =>
592-
bug!("Attempted to stop unwinding while there is no unwinding!"),
593-
_ => {}
588+
if let (false, StackPopInfo::StopUnwinding) = (unwinding, stack_pop_info) {
589+
bug!("Attempted to stop unwinding while there is no unwinding!");
594590
}
595591

596592
// Now where do we jump next?
597593

598594
// Determine if we leave this function normally or via unwinding.
599-
let cur_unwinding = match stack_pop_info {
600-
StackPopInfo::StartUnwinding => true,
601-
StackPopInfo::StopUnwinding => false,
602-
_ => unwinding
595+
let cur_unwinding = if let StackPopInfo::StopUnwinding = stack_pop_info {
596+
false
597+
} else {
598+
unwinding
603599
};
604600

605601
// Usually we want to clean up (deallocate locals), but in a few rare cases we don't.

src/librustc_mir/interpret/machine.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ use super::{
2020
/// to provide further control over the popping of the stack frame
2121
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
2222
pub enum StackPopInfo {
23-
/// Indicates that we have just started unwinding
24-
/// as the result of panic
25-
StartUnwinding,
26-
2723
/// Indicates that no special handling should be
2824
/// done - we'll either return normally or unwind
2925
/// based on the terminator for the function
@@ -177,6 +173,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
177173
instance: ty::Instance<'tcx>,
178174
args: &[OpTy<'tcx, Self::PointerTag>],
179175
dest: Option<PlaceTy<'tcx, Self::PointerTag>>,
176+
ret: Option<mir::BasicBlock>,
177+
unwind: Option<mir::BasicBlock>,
180178
) -> InterpResult<'tcx>;
181179

182180
/// Called for read access to a foreign static item.

src/librustc_mir/interpret/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
265265
match instance.def {
266266
ty::InstanceDef::Intrinsic(..) => {
267267
let old_stack = self.cur_frame();
268-
M::call_intrinsic(self, span, instance, args, dest)?;
268+
M::call_intrinsic(self, span, instance, args, dest, ret, unwind)?;
269269
// No stack frame gets pushed, the main loop will just act as if the
270270
// call completed.
271271
if ret.is_some() {

src/librustc_mir/transform/const_prop.rs

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
164164
_instance: ty::Instance<'tcx>,
165165
_args: &[OpTy<'tcx>],
166166
_dest: Option<PlaceTy<'tcx>>,
167+
_ret: Option<BasicBlock>,
168+
_unwind: Option<BasicBlock>
167169
) -> InterpResult<'tcx> {
168170
throw_unsup_format!("calling intrinsics isn't supported in ConstProp");
169171
}

0 commit comments

Comments
 (0)