Skip to content

Commit c0042a9

Browse files
committed
Do not transmute immediates to non-immediates.
1 parent c9aba70 commit c0042a9

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
@@ -435,6 +435,16 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
435435
CastKind::Transmute => {
436436
let value = self.evaluated[value].as_ref()?;
437437
let to = self.ecx.layout_of(to).ok()?;
438+
// `offset` for immediates only supports scalar/scalar-pair ABIs,
439+
// so bail out if the target is not one.
440+
if value.as_mplace_or_imm().is_right() {
441+
match to.abi {
442+
Abi::Scalar(..) | Abi::ScalarPair(..) => {}
443+
_ if to.is_zst() => {}
444+
Abi::Aggregate { .. } if to.fields.count() == 0 => {}
445+
_ => return None,
446+
}
447+
}
438448
value.offset(Size::ZERO, to, &self.ecx).ok()?
439449
}
440450
_ => return None,

0 commit comments

Comments
 (0)