Skip to content

Commit ac6497b

Browse files
committed
Do not transmute immediates to non-immediates.
1 parent ad27a2e commit ac6497b

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,16 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
443443
CastKind::Transmute => {
444444
let value = self.evaluated[value].as_ref()?;
445445
let to = self.ecx.layout_of(to).ok()?;
446+
// `offset` for immediates only supports scalar/scalar-pair ABIs,
447+
// so bail out if the target is not one.
448+
if value.as_mplace_or_imm().is_right() {
449+
match to.abi {
450+
Abi::Scalar(..) | Abi::ScalarPair(..) => {}
451+
_ if to.is_zst() => {}
452+
Abi::Aggregate { .. } if to.fields.count() == 0 => {}
453+
_ => return None,
454+
}
455+
}
446456
value.offset(Size::ZERO, to, &self.ecx).ok()?
447457
}
448458
_ => return None,

0 commit comments

Comments
 (0)