Skip to content

Commit

Permalink
Rollup merge of rust-lang#69830 - RalfJung:miri-invalid-terminator, r…
Browse files Browse the repository at this point in the history
…=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
  • Loading branch information
Centril authored Mar 11, 2020
2 parents 7210c6c + 911c75f commit 75429bc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/librustc_mir/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_mir/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/librustc_mir/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(())
Expand Down
1 change: 1 addition & 0 deletions src/librustc_span/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ symbols! {
abi_unadjusted,
abi_vectorcall,
abi_x86_interrupt,
abort,
aborts,
address,
add_with_overflow,
Expand Down

0 comments on commit 75429bc

Please sign in to comment.