Skip to content
Permalink
Browse files

handle diverging functions forwarding their return place

  • Loading branch information
RalfJung committed Nov 27, 2019
1 parent 04e69e4 commit 3e7a5a4e0bdf13f504922c9e9b5c539cd57b576f
Showing with 16 additions and 15 deletions.
  1. +16 −15 src/librustc_mir/interpret/place.rs
@@ -651,20 +651,21 @@ where
use rustc::mir::PlaceBase;

let mut place_ty = match &place.base {
PlaceBase::Local(mir::RETURN_PLACE) => match self.frame().return_place {
Some(return_place) => {
// We use our layout to verify our assumption; caller will validate
// their layout on return.
PlaceTy {
place: *return_place,
layout: self.layout_of(
self.subst_from_frame_and_normalize_erasing_regions(
self.frame().body.return_ty()
)
)?,
}
PlaceBase::Local(mir::RETURN_PLACE) => {
// `return_place` has the *caller* layout, but we want to use our
// `layout to verify our assumption. The caller will validate
// their layout on return.
PlaceTy {
place: match self.frame().return_place {
Some(p) => *p,
None => Place::null(&*self),
},
layout: self.layout_of(
self.subst_from_frame_and_normalize_erasing_regions(
self.frame().body.return_ty()
)
)?,
}
None => throw_unsup!(InvalidNullPointerUsage),
},
PlaceBase::Local(local) => PlaceTy {
// This works even for dead/uninitialized locals; we check further when writing
@@ -791,8 +792,8 @@ where
// to handle padding properly, which is only correct if we never look at this data with the
// wrong type.

let ptr = match self.check_mplace_access(dest, None)
.expect("places should be checked on creation")
// Invalid places are a thing: the return place of a diverging function
let ptr = match self.check_mplace_access(dest, None)?
{
Some(ptr) => ptr,
None => return Ok(()), // zero-sized access

0 comments on commit 3e7a5a4

Please sign in to comment.
You can’t perform that action at this time.