Skip to content

Commit 1e35088

Browse files
committed
fix unsized extern types
1 parent 3188d24 commit 1e35088

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/librustc_mir/interpret/operand.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
232232
&self,
233233
mplace: MPlaceTy<'tcx>,
234234
) -> EvalResult<'tcx, Option<Value>> {
235-
debug_assert_eq!(mplace.extra.is_some(), mplace.layout.is_unsized());
236-
if mplace.extra.is_some() {
235+
if mplace.layout.is_unsized() {
237236
// Dont touch unsized
238237
return Ok(None);
239238
}

src/librustc_mir/interpret/place.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub struct MemPlace {
3232
pub ptr: Scalar,
3333
pub align: Align,
3434
/// Metadata for unsized places. Interpretation is up to the type.
35+
/// Must not be present for sized types, but can be missing for unsized types
36+
/// (e.g. `extern type`).
3537
pub extra: Option<Scalar>,
3638
}
3739

@@ -236,11 +238,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
236238
) -> EvalResult<'tcx, MPlaceTy<'tcx>> {
237239
let pointee_type = val.layout.ty.builtin_deref(true).unwrap().ty;
238240
let layout = self.layout_of(pointee_type)?;
239-
let mplace = if layout.is_unsized() {
240-
let (ptr, extra) = val.to_scalar_pair()?;
241-
MemPlace { ptr, align: layout.align, extra: Some(extra) }
242-
} else {
243-
MemPlace { ptr: val.to_scalar()?, align: layout.align, extra: None }
241+
let align = layout.align;
242+
let mplace = match *val {
243+
Value::Scalar(ptr) =>
244+
MemPlace { ptr: ptr.not_undef()?, align, extra: None },
245+
Value::ScalarPair(ptr, extra) =>
246+
MemPlace { ptr: ptr.not_undef()?, align, extra: Some(extra.not_undef()?) },
244247
};
245248
Ok(MPlaceTy { mplace, layout })
246249
}

0 commit comments

Comments
 (0)