about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2023-09-23 07:23:14 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2023-10-25 06:46:47 +0000
commit9389373127705dd4ceb460e6e152cfb9126e6be5 (patch)
tree8a5f12541dc133aed1c70d95c2a035db2a1f94e0
parentdb9bd9bd8c42aa06d5d822a1f04bc2007601ca43 (diff)
downloadrust-9389373127705dd4ceb460e6e152cfb9126e6be5.tar.gz
rust-9389373127705dd4ceb460e6e152cfb9126e6be5.zip
Do not transmute immediates to non-immediates.
-rw-r--r--compiler/rustc_mir_transform/src/gvn.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs
index 7800aa63729..60ff1dd0d78 100644
--- a/compiler/rustc_mir_transform/src/gvn.rs
+++ b/compiler/rustc_mir_transform/src/gvn.rs
@@ -443,6 +443,16 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
                 CastKind::Transmute => {
                     let value = self.evaluated[value].as_ref()?;
                     let to = self.ecx.layout_of(to).ok()?;
+                    // `offset` for immediates only supports scalar/scalar-pair ABIs,
+                    // so bail out if the target is not one.
+                    if value.as_mplace_or_imm().is_right() {
+                        match to.abi {
+                            Abi::Scalar(..) | Abi::ScalarPair(..) => {}
+                            _ if to.is_zst() => {}
+                            Abi::Aggregate { .. } if to.fields.count() == 0 => {}
+                            _ => return None,
+                        }
+                    }
                     value.offset(Size::ZERO, to, &self.ecx).ok()?
                 }
                 _ => return None,