Rollup merge of #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:

1d5241c962/src/librustc_codegen_ssa/mir/block.rs (L796)

1d5241c962/src/librustc_codegen_ssa/mir/mod.rs (L296)
This commit is contained in:
Mazdak Farrokhzad 2020-03-12 16:32:23 +01:00 committed by GitHub
commit fac7122682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 7 deletions

View File

@ -103,6 +103,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.write_scalar(location.ptr, dest)?;
}
sym::abort => {
M::abort(self)?;
}
sym::min_align_of
| sym::pref_align_of
| sym::needs_drop

View File

@ -169,6 +169,11 @@ pub trait Machine<'mir, 'tcx>: Sized {
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx>;
/// Called to evaluate `Abort` MIR terminator.
fn abort(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx, !> {
throw_unsup_format!("aborting execution is not supported");
}
/// Called for all binary operations where the LHS has pointer type.
///
/// Returns a (value, overflowed) pair if the operation succeeded

View File

@ -99,6 +99,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
}
Abort => {
M::abort(self)?;
}
// When we encounter Resume, we've finished unwinding
// cleanup for the current stack frame. We pop it in order
// to continue unwinding the next frame
@ -114,15 +118,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Unreachable => throw_ub!(Unreachable),
// These should never occur for MIR we actually run.
DropAndReplace { .. } | FalseEdges { .. } | FalseUnwind { .. } => {
DropAndReplace { .. }
| FalseEdges { .. }
| FalseUnwind { .. }
| Yield { .. }
| GeneratorDrop => {
bug!("{:#?} should have been eliminated by MIR pass", terminator.kind)
}
// These are not (yet) supported. It is unclear if they even can occur in
// MIR that we actually run.
Yield { .. } | GeneratorDrop | Abort => {
throw_unsup_format!("Unsupported terminator kind: {:#?}", terminator.kind)
}
}
Ok(())

View File

@ -120,6 +120,7 @@ symbols! {
abi_unadjusted,
abi_vectorcall,
abi_x86_interrupt,
abort,
aborts,
address,
add_with_overflow,