Skip to content

Commit 75429bc

Browse files
authored
Rollup merge of rust-lang#69830 - RalfJung:miri-invalid-terminator, r=oli-obk
miri: ICE on invalid terminators We've run a lot of MIR in Miri (including some generators) and never seen these. @tmandry is it correct that `Yield` and `GeneratorDrop` get lowered away? @eddyb @oli-obk what's with this `Abort` that does not seem to ever actually exist? Codegen *does* seem to handle it, so I wonder why Miri can get away without that. In fact, codegen handles it twice: https://github.com/rust-lang/rust/blob/1d5241c96208ca7d925442b1a5fa45ad18717a6f/src/librustc_codegen_ssa/mir/block.rs#L796 https://github.com/rust-lang/rust/blob/1d5241c96208ca7d925442b1a5fa45ad18717a6f/src/librustc_codegen_ssa/mir/mod.rs#L296
2 parents 7210c6c + 911c75f commit 75429bc

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/librustc_mir/interpret/intrinsics.rs

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
103103
self.write_scalar(location.ptr, dest)?;
104104
}
105105

106+
sym::abort => {
107+
M::abort(self)?;
108+
}
109+
106110
sym::min_align_of
107111
| sym::pref_align_of
108112
| sym::needs_drop

src/librustc_mir/interpret/machine.rs

+5
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ pub trait Machine<'mir, 'tcx>: Sized {
169169
unwind: Option<mir::BasicBlock>,
170170
) -> InterpResult<'tcx>;
171171

172+
/// Called to evaluate `Abort` MIR terminator.
173+
fn abort(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx, !> {
174+
throw_unsup_format!("aborting execution is not supported");
175+
}
176+
172177
/// Called for all binary operations where the LHS has pointer type.
173178
///
174179
/// Returns a (value, overflowed) pair if the operation succeeded

src/librustc_mir/interpret/terminator.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9999
}
100100
}
101101

102+
Abort => {
103+
M::abort(self)?;
104+
}
105+
102106
// When we encounter Resume, we've finished unwinding
103107
// cleanup for the current stack frame. We pop it in order
104108
// to continue unwinding the next frame
@@ -114,15 +118,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
114118
Unreachable => throw_ub!(Unreachable),
115119

116120
// These should never occur for MIR we actually run.
117-
DropAndReplace { .. } | FalseEdges { .. } | FalseUnwind { .. } => {
121+
DropAndReplace { .. }
122+
| FalseEdges { .. }
123+
| FalseUnwind { .. }
124+
| Yield { .. }
125+
| GeneratorDrop => {
118126
bug!("{:#?} should have been eliminated by MIR pass", terminator.kind)
119127
}
120-
121-
// These are not (yet) supported. It is unclear if they even can occur in
122-
// MIR that we actually run.
123-
Yield { .. } | GeneratorDrop | Abort => {
124-
throw_unsup_format!("Unsupported terminator kind: {:#?}", terminator.kind)
125-
}
126128
}
127129

128130
Ok(())

src/librustc_span/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ symbols! {
120120
abi_unadjusted,
121121
abi_vectorcall,
122122
abi_x86_interrupt,
123+
abort,
123124
aborts,
124125
address,
125126
add_with_overflow,

0 commit comments

Comments
 (0)