about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2023-12-17 22:30:20 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2024-02-09 21:01:57 +0000
commit304b4ad8b9899584c7b981dee3b72017ca101a3e (patch)
tree983fb118e80024ec8c4ccd728ac79085798363bd /compiler/rustc_mir_transform/src
parent1f544ca0cc3652aeca1d8dbe78d406533f691c1b (diff)
downloadrust-304b4ad8b9899584c7b981dee3b72017ca101a3e.tar.gz
rust-304b4ad8b9899584c7b981dee3b72017ca101a3e.zip
Compute unsizing casts in GVN.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-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 3e8e454fcaa..0ef3cdbb337 100644
--- a/compiler/rustc_mir_transform/src/gvn.rs
+++ b/compiler/rustc_mir_transform/src/gvn.rs
@@ -551,6 +551,16 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
                     }
                     value.offset(Size::ZERO, to, &self.ecx).ok()?
                 }
+                CastKind::PointerCoercion(ty::adjustment::PointerCoercion::Unsize) => {
+                    let src = self.evaluated[value].as_ref()?;
+                    let to = self.ecx.layout_of(to).ok()?;
+                    let dest = self.ecx.allocate(to, MemoryKind::Stack).ok()?;
+                    self.ecx.unsize_into(src, to, &dest.clone().into()).ok()?;
+                    self.ecx
+                        .alloc_mark_immutable(dest.ptr().provenance.unwrap().alloc_id())
+                        .ok()?;
+                    dest.into()
+                }
                 _ => return None,
             },
         };