Skip to content

Commit bd77ef5

Browse files
committed
Do not transmute immediates to non-immediates.
1 parent afe620f commit bd77ef5

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

0 commit comments

Comments
 (0)