about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-08-06 18:40:37 +0200
committerRalf Jung <post@ralfj.de>2023-08-30 13:46:54 +0200
commita09df43d9fbbd21dfa2d872ff0671f80161c15f1 (patch)
treeb3ca505ef2f70da66910acad445d15c1bb8c4bc6 /src/tools
parentbdd5855b8e127f4a258b0bd90cd5d2dbade1b3cc (diff)
move marking-locals-live out of push_stack_frame, so it happens with argument passing
this entirely avoids even creating unsized locals in Immediate::Uninitialized state
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/miri/src/diagnostics.rs2
-rw-r--r--src/tools/miri/src/helpers.rs23
-rw-r--r--src/tools/miri/tests/fail/type-too-large.rs4
-rw-r--r--src/tools/miri/tests/fail/type-too-large.stderr4
-rw-r--r--src/tools/miri/tests/fail/unsized-local.stderr2
5 files changed, 16 insertions, 19 deletions
diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs
index 799a9a8e4be..75c6911bcbe 100644
--- a/src/tools/miri/src/diagnostics.rs
+++ b/src/tools/miri/src/diagnostics.rs
@@ -283,7 +283,7 @@ pub fn report_error<'tcx, 'mir>(
                 "resource exhaustion",
             Unsupported(
                 // We list only the ones that can actually happen.
-                UnsupportedOpInfo::Unsupported(_)
+                UnsupportedOpInfo::Unsupported(_) | UnsupportedOpInfo::UnsizedLocal
             ) =>
                 "unsupported operation",
             InvalidProgram(
diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs
index b5cc5c7e486..844827889a7 100644
--- a/src/tools/miri/src/helpers.rs
+++ b/src/tools/miri/src/helpers.rs
@@ -14,7 +14,7 @@ use rustc_middle::mir;
 use rustc_middle::ty::{
     self,
     layout::{IntegerExt as _, LayoutOf, TyAndLayout},
-    List, Ty, TyCtxt,
+    Ty, TyCtxt,
 };
 use rustc_span::{def_id::CrateNum, sym, Span, Symbol};
 use rustc_target::abi::{Align, FieldIdx, FieldsShape, Integer, Size, Variants};
@@ -282,13 +282,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
         Ok(ptr.addr().bytes() == 0)
     }
 
-    /// Get the `Place` for a local
-    fn local_place(&self, local: mir::Local) -> InterpResult<'tcx, PlaceTy<'tcx, Provenance>> {
-        let this = self.eval_context_ref();
-        let place = mir::Place { local, projection: List::empty() };
-        this.eval_place(place)
-    }
-
     /// Generate some random bytes, and write them to `dest`.
     fn gen_random(&mut self, ptr: Pointer<Option<Provenance>>, len: u64) -> InterpResult<'tcx> {
         // Some programs pass in a null pointer and a length of 0
@@ -350,17 +343,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
         // Initialize arguments.
         let mut callee_args = this.frame().body.args_iter();
         for arg in args {
-            let callee_arg = this.local_place(
-                callee_args
-                    .next()
-                    .ok_or_else(|| err_ub_format!("callee has fewer arguments than expected"))?,
-            )?;
+            let local = callee_args
+                .next()
+                .ok_or_else(|| err_ub_format!("callee has fewer arguments than expected"))?;
+            // Make the local live, and insert the initial value.
+            this.storage_live(local)?;
+            let callee_arg = this.local_to_place(this.frame_idx(), local)?;
             this.write_immediate(*arg, &callee_arg)?;
         }
         if callee_args.next().is_some() {
             throw_ub_format!("callee has more arguments than expected");
         }
 
+        // Initialize remaining locals.
+        this.storage_live_for_always_live_locals()?;
+
         Ok(())
     }
 
diff --git a/src/tools/miri/tests/fail/type-too-large.rs b/src/tools/miri/tests/fail/type-too-large.rs
index 21b272f8ec3..2e23b79d5f8 100644
--- a/src/tools/miri/tests/fail/type-too-large.rs
+++ b/src/tools/miri/tests/fail/type-too-large.rs
@@ -1,6 +1,6 @@
 //@ignore-32bit
 
 fn main() {
-    let _fat: [u8; (1 << 61) + (1 << 31)];
-    _fat = [0; (1u64 << 61) as usize + (1u64 << 31) as usize]; //~ ERROR: post-monomorphization error
+    let _fat: [u8; (1 << 61) + (1 << 31)]; //~ ERROR: post-monomorphization error
+    _fat = [0; (1u64 << 61) as usize + (1u64 << 31) as usize];
 }
diff --git a/src/tools/miri/tests/fail/type-too-large.stderr b/src/tools/miri/tests/fail/type-too-large.stderr
index cb1d725ec87..70891fcc22b 100644
--- a/src/tools/miri/tests/fail/type-too-large.stderr
+++ b/src/tools/miri/tests/fail/type-too-large.stderr
@@ -1,8 +1,8 @@
 error: post-monomorphization error: values of the type `[u8; 2305843011361177600]` are too big for the current architecture
   --> $DIR/type-too-large.rs:LL:CC
    |
-LL |     _fat = [0; (1u64 << 61) as usize + (1u64 << 31) as usize];
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ values of the type `[u8; 2305843011361177600]` are too big for the current architecture
+LL |     let _fat: [u8; (1 << 61) + (1 << 31)];
+   |         ^^^^ values of the type `[u8; 2305843011361177600]` are too big for the current architecture
    |
    = note: inside `main` at $DIR/type-too-large.rs:LL:CC
 
diff --git a/src/tools/miri/tests/fail/unsized-local.stderr b/src/tools/miri/tests/fail/unsized-local.stderr
index 66d93c6f503..07f94f3b91b 100644
--- a/src/tools/miri/tests/fail/unsized-local.stderr
+++ b/src/tools/miri/tests/fail/unsized-local.stderr
@@ -2,7 +2,7 @@ error: unsupported operation: unsized locals are not supported
   --> $DIR/unsized-local.rs:LL:CC
    |
 LL |     let x = *(Box::new(A) as Box<dyn Foo>);
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsized locals are not supported
+   |         ^ unsized locals are not supported
    |
    = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
    = note: BACKTRACE: