about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/builder.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-12-02 22:25:14 +0100
committerRalf Jung <post@ralfj.de>2023-12-03 08:11:15 +0100
commit5a20bac6b3ff61acc3cd68bed0eb3fa598181f17 (patch)
treed2fd3b80c9651b0630d3e6aee00c3d6cdacd2ffb /compiler/rustc_codegen_llvm/src/builder.rs
parent0908f173fd884ae90584e0b0bca83cb270c23936 (diff)
downloadrust-5a20bac6b3ff61acc3cd68bed0eb3fa598181f17.tar.gz
rust-5a20bac6b3ff61acc3cd68bed0eb3fa598181f17.zip
more targeted errors when extern types end up in places they should not
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/builder.rs')
-rw-r--r--compiler/rustc_codegen_llvm/src/builder.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs
index 7b259055d40..acd85dd9a2d 100644
--- a/compiler/rustc_codegen_llvm/src/builder.rs
+++ b/compiler/rustc_codegen_llvm/src/builder.rs
@@ -489,6 +489,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
 
     #[instrument(level = "trace", skip(self))]
     fn load_operand(&mut self, place: PlaceRef<'tcx, &'ll Value>) -> OperandRef<'tcx, &'ll Value> {
+        if place.layout.is_unsized() {
+            let tail = self.tcx.struct_tail_with_normalize(place.layout.ty, |ty| ty, || {});
+            if matches!(tail.kind(), ty::Foreign(..)) {
+                // Unsized locals and, at least conceptually, even unsized arguments must be copied
+                // around, which requires dynamically determining their size. Therefore, we cannot
+                // allow `extern` types here. Consult t-opsem before removing this check.
+                panic!("unsized locals must not be `extern` types");
+            }
+        }
         assert_eq!(place.llextra.is_some(), place.layout.is_unsized());
 
         if place.layout.is_zst() {