Skip to content

Commit 8ef3974

Browse files
author
hyd-dev
committed
Pass StackPopUnwind to eval_fn_call() and some other functions that are called by eval_fn_call()
1 parent 876fdcb commit 8ef3974

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

compiler/rustc_mir/src/const_eval/machine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_target::spec::abi::Abi;
1717

1818
use crate::interpret::{
1919
self, compile_time_machine, AllocId, Allocation, Frame, ImmTy, InterpCx, InterpResult, Memory,
20-
OpTy, PlaceTy, Pointer, Scalar,
20+
OpTy, PlaceTy, Pointer, Scalar, StackPopUnwind,
2121
};
2222

2323
use super::error::*;
@@ -223,7 +223,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
223223
_abi: Abi,
224224
args: &[OpTy<'tcx>],
225225
_ret: Option<(&PlaceTy<'tcx>, mir::BasicBlock)>,
226-
_unwind: Option<mir::BasicBlock>, // unwinding is not supported in consts
226+
_unwind: StackPopUnwind, // unwinding is not supported in consts
227227
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
228228
debug!("find_mir_or_eval_fn: {:?}", instance);
229229

@@ -263,7 +263,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
263263
instance: ty::Instance<'tcx>,
264264
args: &[OpTy<'tcx>],
265265
ret: Option<(&PlaceTy<'tcx>, mir::BasicBlock)>,
266-
_unwind: Option<mir::BasicBlock>,
266+
_unwind: StackPopUnwind,
267267
) -> InterpResult<'tcx> {
268268
// Shared intrinsics.
269269
if ecx.emulate_intrinsic(instance, args, ret)? {

compiler/rustc_mir/src/interpret/machine.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_target::spec::abi::Abi;
1414

1515
use super::{
1616
AllocId, Allocation, CheckInAllocMsg, Frame, ImmTy, InterpCx, InterpResult, LocalValue,
17-
MemPlace, Memory, MemoryKind, OpTy, Operand, PlaceTy, Pointer, Scalar,
17+
MemPlace, Memory, MemoryKind, OpTy, Operand, PlaceTy, Pointer, Scalar, StackPopUnwind,
1818
};
1919

2020
/// Data returned by Machine::stack_pop,
@@ -163,7 +163,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
163163
abi: Abi,
164164
args: &[OpTy<'tcx, Self::PointerTag>],
165165
ret: Option<(&PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
166-
unwind: Option<mir::BasicBlock>,
166+
unwind: StackPopUnwind,
167167
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>>;
168168

169169
/// Execute `fn_val`. It is the hook's responsibility to advance the instruction
@@ -174,7 +174,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
174174
abi: Abi,
175175
args: &[OpTy<'tcx, Self::PointerTag>],
176176
ret: Option<(&PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
177-
unwind: Option<mir::BasicBlock>,
177+
unwind: StackPopUnwind,
178178
) -> InterpResult<'tcx>;
179179

180180
/// Directly process an intrinsic without pushing a stack frame. It is the hook's
@@ -184,7 +184,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
184184
instance: ty::Instance<'tcx>,
185185
args: &[OpTy<'tcx, Self::PointerTag>],
186186
ret: Option<(&PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
187-
unwind: Option<mir::BasicBlock>,
187+
unwind: StackPopUnwind,
188188
) -> InterpResult<'tcx>;
189189

190190
/// Called to evaluate `Assert` MIR terminators that trigger a panic.
@@ -456,7 +456,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
456456
_abi: Abi,
457457
_args: &[OpTy<$tcx>],
458458
_ret: Option<(&PlaceTy<$tcx>, mir::BasicBlock)>,
459-
_unwind: Option<mir::BasicBlock>,
459+
_unwind: StackPopUnwind,
460460
) -> InterpResult<$tcx> {
461461
match fn_val {}
462462
}

compiler/rustc_mir/src/interpret/terminator.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,17 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
105105
}
106106
None => None,
107107
};
108-
self.eval_fn_call(fn_val, abi, &args[..], ret, *cleanup, can_unwind)?;
108+
self.eval_fn_call(
109+
fn_val,
110+
abi,
111+
&args[..],
112+
ret,
113+
if can_unwind {
114+
cleanup.map_or(StackPopUnwind::Skip, StackPopUnwind::Cleanup)
115+
} else {
116+
StackPopUnwind::NotAllowed
117+
},
118+
)?;
109119
// Sanity-check that `eval_fn_call` either pushed a new frame or
110120
// did a jump to another block.
111121
if self.frame_idx() == old_stack && self.frame().loc == old_loc {
@@ -235,8 +245,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
235245
caller_abi: Abi,
236246
args: &[OpTy<'tcx, M::PointerTag>],
237247
ret: Option<(&PlaceTy<'tcx, M::PointerTag>, mir::BasicBlock)>,
238-
unwind: Option<mir::BasicBlock>,
239-
can_unwind: bool,
248+
mut unwind: StackPopUnwind,
240249
) -> InterpResult<'tcx> {
241250
trace!("eval_fn_call: {:#?}", fn_val);
242251

@@ -306,22 +315,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
306315
check_abi(callee_abi)?;
307316
}
308317

309-
let can_unwind = can_unwind
318+
if !matches!(unwind, StackPopUnwind::NotAllowed)
310319
&& self
311-
.fn_can_unwind(self.tcx.codegen_fn_attrs(callee_def_id).flags, callee_abi);
320+
.fn_can_unwind(self.tcx.codegen_fn_attrs(callee_def_id).flags, callee_abi)
321+
{
322+
unwind = StackPopUnwind::NotAllowed;
323+
}
312324

313325
self.push_stack_frame(
314326
instance,
315327
body,
316328
ret.map(|p| p.0),
317-
StackPopCleanup::Goto {
318-
ret: ret.map(|p| p.1),
319-
unwind: match (unwind, can_unwind) {
320-
(Some(unwind), true) => StackPopUnwind::Cleanup(unwind),
321-
(None, true) => StackPopUnwind::Skip,
322-
(_, false) => StackPopUnwind::NotAllowed,
323-
},
324-
},
329+
StackPopCleanup::Goto { ret: ret.map(|p| p.1), unwind },
325330
)?;
326331

327332
// If an error is raised here, pop the frame again to get an accurate backtrace.
@@ -466,7 +471,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
466471
OpTy::from(ImmTy::from_immediate(receiver_place.ptr.into(), this_receiver_ptr));
467472
trace!("Patched self operand to {:#?}", args[0]);
468473
// recurse with concrete function
469-
self.eval_fn_call(drop_fn, caller_abi, &args, ret, unwind, can_unwind)
474+
self.eval_fn_call(drop_fn, caller_abi, &args, ret, unwind)
470475
}
471476
}
472477
}
@@ -505,8 +510,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
505510
Abi::Rust,
506511
&[arg.into()],
507512
Some((&dest.into(), target)),
508-
unwind,
509-
true,
513+
unwind.map_or(StackPopUnwind::Skip, StackPopUnwind::Cleanup),
510514
)
511515
}
512516
}

compiler/rustc_mir/src/transform/const_prop.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use crate::interpret::{
3333
self, compile_time_machine, AllocId, Allocation, ConstValue, CtfeValidationMode, Frame, ImmTy,
3434
Immediate, InterpCx, InterpResult, LocalState, LocalValue, MemPlace, Memory, MemoryKind, OpTy,
3535
Operand as InterpOperand, PlaceTy, Pointer, Scalar, ScalarMaybeUninit, StackPopCleanup,
36+
StackPopUnwind,
3637
};
3738
use crate::transform::MirPass;
3839

@@ -198,7 +199,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
198199
_abi: Abi,
199200
_args: &[OpTy<'tcx>],
200201
_ret: Option<(&PlaceTy<'tcx>, BasicBlock)>,
201-
_unwind: Option<BasicBlock>,
202+
_unwind: StackPopUnwind,
202203
) -> InterpResult<'tcx, Option<&'mir Body<'tcx>>> {
203204
Ok(None)
204205
}
@@ -208,7 +209,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
208209
_instance: ty::Instance<'tcx>,
209210
_args: &[OpTy<'tcx>],
210211
_ret: Option<(&PlaceTy<'tcx>, BasicBlock)>,
211-
_unwind: Option<BasicBlock>,
212+
_unwind: StackPopUnwind,
212213
) -> InterpResult<'tcx> {
213214
throw_machine_stop_str!("calling intrinsics isn't supported in ConstProp")
214215
}

0 commit comments

Comments
 (0)