about summary refs log tree commit diff
path: root/compiler/rustc_const_eval
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-04-27 12:22:21 +0200
committerRalf Jung <post@ralfj.de>2023-04-28 14:42:03 +0200
commit25e9b79060d67f1ac0dc2315ff627b6359192bfc (patch)
tree1c3d8482d9bb812b36263c7ee79771f694f164d4 /compiler/rustc_const_eval
parent8b8110e1469d459a196f6feb60d82dec48c3cfc2 (diff)
downloadrust-25e9b79060d67f1ac0dc2315ff627b6359192bfc.tar.gz
rust-25e9b79060d67f1ac0dc2315ff627b6359192bfc.zip
interpret: fail more gracefully on uninit unsized locals
Diffstat (limited to 'compiler/rustc_const_eval')
-rw-r--r--compiler/rustc_const_eval/src/const_eval/valtrees.rs2
-rw-r--r--compiler/rustc_const_eval/src/interpret/operand.rs6
2 files changed, 7 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs
index 4d54c01830b..b10f2e9f862 100644
--- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs
+++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs
@@ -337,7 +337,7 @@ fn valtree_into_mplace<'tcx>(
 
     match ty.kind() {
         ty::FnDef(_, _) => {
-            ecx.write_immediate(Immediate::Uninit, &place.into()).unwrap();
+            // Zero-sized type, nothing to do.
         }
         ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char => {
             let scalar_int = valtree.unwrap_leaf();
diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs
index 5310ef0bb3e..a7f66071fe2 100644
--- a/compiler/rustc_const_eval/src/interpret/operand.rs
+++ b/compiler/rustc_const_eval/src/interpret/operand.rs
@@ -245,6 +245,12 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
 impl<'tcx, Prov: Provenance> OpTy<'tcx, Prov> {
     pub fn len(&self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
         if self.layout.is_unsized() {
+            if matches!(self.op, Operand::Immediate(Immediate::Uninit)) {
+                // Uninit unsized places shouldn't occur. In the interpreter we have them
+                // temporarily for unsized arguments before their value is put in; in ConstProp they
+                // remain uninit and this code can actually be reached.
+                throw_inval!(UninitUnsizedLocal);
+            }
             // There are no unsized immediates.
             self.assert_mem_place().len(cx)
         } else {