Skip to content

Commit 7d7a650

Browse files
committed
Do not transmute immediates to non-immediates.
1 parent b1d41ab commit 7d7a650

File tree

1 file changed

+10
-0
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+10
-0
lines changed

compiler/rustc_mir_transform/src/gvn.rs

+10
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,16 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
429429
CastKind::Transmute => {
430430
let value = self.evaluated[value].as_ref()?;
431431
let to = self.ecx.layout_of(to).ok()?;
432+
// `offset` for immediates only supports scalar/scalar-pair ABIs,
433+
// so bail out if the target is not one.
434+
if value.as_mplace_or_imm().is_right() {
435+
match to.abi {
436+
Abi::Scalar(..) | Abi::ScalarPair(..) => {}
437+
_ if to.is_zst() => {}
438+
Abi::Aggregate { .. } if to.fields.count() == 0 => {}
439+
_ => return None,
440+
}
441+
}
432442
value.offset(Size::ZERO, to, &self.ecx).ok()?
433443
}
434444
_ => return None,

0 commit comments

Comments
 (0)