Skip to content

Commit

Permalink
Rollup merge of #69960 - RalfJung:abort, r=oli-obk
Browse files Browse the repository at this point in the history
miri engine: fix treatment of abort intrinsic

I screwed up in #69830 and added `abort` to the wrong block of intrinsics, namely the one that actually has a return place. So that branch was never actually reached.

r? @oli-obk
  • Loading branch information
JohnTitor committed Mar 13, 2020
2 parents 77263db + 13ea774 commit f2af2cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions src/librustc_mir/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let substs = instance.substs;
let intrinsic_name = self.tcx.item_name(instance.def_id());

// We currently do not handle any intrinsics that are *allowed* to diverge,
// but `transmute` could lack a return place in case of UB.
// First handle intrinsics without return place.
let (dest, ret) = match ret {
Some(p) => p,
None => match intrinsic_name {
sym::transmute => throw_ub!(Unreachable),
sym::transmute => throw_ub_format!("transmuting to uninhabited type"),
sym::abort => M::abort(self)?,
// Unsupported diverging intrinsic.
_ => return Ok(false),
},
Some(p) => p,
};

// Keep the patterns in this match ordered the same as the list in
Expand All @@ -103,10 +104,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: any use of this value will cause an error
LL | unsafe { std::mem::transmute(()) }
| ^^^^^^^^^^^^^^^^^^^^^^^
| |
| entering unreachable code
| transmuting to uninhabited type
| inside call to `foo` at $DIR/validate_uninhabited_zsts.rs:14:26
...
LL | const FOO: [Empty; 3] = [foo(); 3];
Expand Down

0 comments on commit f2af2cf

Please sign in to comment.