]> git.lizzy.rs Git - rust.git/commitdiff
Adjust Miri to also require return places everywhere
authorJakob Degen <jakob.e.degen@gmail.com>
Sat, 21 May 2022 03:08:32 +0000 (23:08 -0400)
committerRalf Jung <post@ralfj.de>
Tue, 24 May 2022 15:16:36 +0000 (17:16 +0200)
16 files changed:
src/diagnostics.rs
src/eval.rs
src/helpers.rs
src/machine.rs
src/shims/dlsym.rs
src/shims/foreign_items.rs
src/shims/intrinsics.rs
src/shims/mod.rs
src/shims/panic.rs
src/shims/posix/dlsym.rs
src/shims/posix/linux/dlsym.rs
src/shims/posix/macos/dlsym.rs
src/shims/posix/thread.rs
src/shims/tls.rs
src/shims/windows/dlsym.rs
src/stacked_borrows.rs

index 8afcf851ba4e99d883ef2192e485c52427c3e8ed..527ff032d6703521ee9d78ef9f81ecc7062d100a 100644 (file)
@@ -275,7 +275,7 @@ pub fn report_error<'tcx, 'mir>(
     for (i, frame) in ecx.active_thread_stack().iter().enumerate() {
         trace!("-------------------");
         trace!("Frame {}", i);
-        trace!("    return: {:?}", frame.return_place.map(|p| *p));
+        trace!("    return: {:?}", *frame.return_place);
         for (i, local) in frame.locals.iter().enumerate() {
             trace!("    local {}: {:?}", i, local.value);
         }
index 430ff06cf15adb6d8b80da162db6b6fb21e6f57c..badda8f3bc3938910a652087d0970a1c2be100cf 100644 (file)
@@ -277,7 +277,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
                 start_instance,
                 Abi::Rust,
                 &[Scalar::from_pointer(main_ptr, &ecx).into(), argc.into(), argv],
-                Some(&ret_place.into()),
+                &ret_place.into(),
                 StackPopCleanup::Root { cleanup: true },
             )?;
         }
@@ -286,7 +286,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
                 entry_instance,
                 Abi::Rust,
                 &[argc.into(), argv],
-                Some(&ret_place.into()),
+                &ret_place.into(),
                 StackPopCleanup::Root { cleanup: true },
             )?;
         }
index 08b2fa98a2300eff37acc0fcacf73b61d688bd00..24c471a8b0ba8a21422fc5f10b7adb278d6f2f86 100644 (file)
@@ -240,7 +240,7 @@ fn call_function(
         f: ty::Instance<'tcx>,
         caller_abi: Abi,
         args: &[Immediate<Tag>],
-        dest: Option<&PlaceTy<'tcx, Tag>>,
+        dest: &PlaceTy<'tcx, Tag>,
         stack_pop: StackPopCleanup,
     ) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
index 0972699e7288666450c444fafc72275f6b372775..c5c884e8d7a04cf5115f009264c42801bc416209 100644 (file)
@@ -512,10 +512,11 @@ fn find_mir_or_eval_fn(
         instance: ty::Instance<'tcx>,
         abi: Abi,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
         unwind: StackPopUnwind,
     ) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
-        ecx.find_mir_or_eval_fn(instance, abi, args, ret, unwind)
+        ecx.find_mir_or_eval_fn(instance, abi, args, dest, ret, unwind)
     }
 
     #[inline(always)]
@@ -524,10 +525,11 @@ fn call_extra_fn(
         fn_val: Dlsym,
         abi: Abi,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
         _unwind: StackPopUnwind,
     ) -> InterpResult<'tcx> {
-        ecx.call_dlsym(fn_val, abi, args, ret)
+        ecx.call_dlsym(fn_val, abi, args, dest, ret)
     }
 
     #[inline(always)]
@@ -535,10 +537,11 @@ fn call_intrinsic(
         ecx: &mut MiriEvalContext<'mir, 'tcx>,
         instance: ty::Instance<'tcx>,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
         unwind: StackPopUnwind,
     ) -> InterpResult<'tcx> {
-        ecx.call_intrinsic(instance, args, ret, unwind)
+        ecx.call_intrinsic(instance, args, dest, ret, unwind)
     }
 
     #[inline(always)]
index 1855d65d6c504187f9ba5cae203368373b87cfbb..d83a309c3e1f703c31c13dc8b96877d81e0d4f53 100644 (file)
@@ -32,13 +32,15 @@ fn call_dlsym(
         dlsym: Dlsym,
         abi: Abi,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
     ) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
         match dlsym {
-            Dlsym::Posix(dlsym) => posix::EvalContextExt::call_dlsym(this, dlsym, abi, args, ret),
+            Dlsym::Posix(dlsym) =>
+                posix::EvalContextExt::call_dlsym(this, dlsym, abi, args, dest, ret),
             Dlsym::Windows(dlsym) =>
-                windows::EvalContextExt::call_dlsym(this, dlsym, abi, args, ret),
+                windows::EvalContextExt::call_dlsym(this, dlsym, abi, args, dest, ret),
         }
     }
 }
index 44bf4ba7e3696f464cb101a3362d2f58781d7d41..e978391801f1e72bb325c55d7922e7664e6d3a25 100644 (file)
@@ -232,7 +232,8 @@ fn emulate_foreign_item(
         def_id: DefId,
         abi: Abi,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
         unwind: StackPopUnwind,
     ) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
         let this = self.eval_context_mut();
@@ -240,7 +241,7 @@ fn emulate_foreign_item(
         let tcx = this.tcx.tcx;
 
         // First: functions that diverge.
-        let (dest, ret) = match ret {
+        let ret = match ret {
             None =>
                 match &*link_name.as_str() {
                     "miri_start_panic" => {
index a6f818c493e66f7ee2be3690fae1ff4c0bec1fbc..1f06971a3e70db0128c06876f4c3dc95f451bbe4 100644 (file)
@@ -22,19 +22,20 @@ fn call_intrinsic(
         &mut self,
         instance: ty::Instance<'tcx>,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
         _unwind: StackPopUnwind,
     ) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
 
-        if this.emulate_intrinsic(instance, args, ret)? {
+        if this.emulate_intrinsic(instance, args, dest, ret)? {
             return Ok(());
         }
 
         // All supported intrinsics have a return place.
         let intrinsic_name = this.tcx.item_name(instance.def_id());
         let intrinsic_name = intrinsic_name.as_str();
-        let (dest, ret) = match ret {
+        let ret = match ret {
             None => throw_unsup_format!("unimplemented (diverging) intrinsic: {}", intrinsic_name),
             Some(p) => p,
         };
index f003552434fe9a5c0548165c44dfa476f67c9106..926fcd5d040b8b35ec061b31cda253b3f83971de 100644 (file)
@@ -28,16 +28,17 @@ fn find_mir_or_eval_fn(
         instance: ty::Instance<'tcx>,
         abi: Abi,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
         unwind: StackPopUnwind,
     ) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
         let this = self.eval_context_mut();
-        trace!("eval_fn_call: {:#?}, {:?}", instance, ret.map(|p| p.0));
+        trace!("eval_fn_call: {:#?}, {:?}", instance, dest);
 
         // There are some more lang items we want to hook that CTFE does not hook (yet).
         if this.tcx.lang_items().align_offset_fn() == Some(instance.def.def_id()) {
             let [ptr, align] = check_arg_count(args)?;
-            if this.align_offset(ptr, align, ret, unwind)? {
+            if this.align_offset(ptr, align, dest, ret, unwind)? {
                 return Ok(None);
             }
         }
@@ -50,7 +51,7 @@ fn find_mir_or_eval_fn(
             // to run extra MIR), and Ok(Some(body)) if we found MIR to run for the
             // foreign function
             // Any needed call to `goto_block` will be performed by `emulate_foreign_item`.
-            return this.emulate_foreign_item(instance.def_id(), abi, args, ret, unwind);
+            return this.emulate_foreign_item(instance.def_id(), abi, args, dest, ret, unwind);
         }
 
         // Otherwise, load the MIR.
@@ -63,11 +64,12 @@ fn align_offset(
         &mut self,
         ptr_op: &OpTy<'tcx, Tag>,
         align_op: &OpTy<'tcx, Tag>,
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
         unwind: StackPopUnwind,
     ) -> InterpResult<'tcx, bool> {
         let this = self.eval_context_mut();
-        let (dest, ret) = ret.unwrap();
+        let ret = ret.unwrap();
 
         if this.machine.check_alignment != AlignmentCheck::Symbolic {
             // Just use actual implementation.
index f92e39048bc860d0adc60a8f87a82f644f02b396..ed6e72591dd002e331b3ab45193573854486dfc4 100644 (file)
@@ -96,7 +96,7 @@ fn handle_try(
             f_instance,
             Abi::Rust,
             &[data.into()],
-            Some(&ret_place),
+            &ret_place,
             // Directly return to caller.
             StackPopCleanup::Goto { ret: Some(ret), unwind: StackPopUnwind::Skip },
         )?;
@@ -153,7 +153,7 @@ fn handle_stack_pop(
                 f_instance,
                 Abi::Rust,
                 &[catch_unwind.data.into(), payload.into()],
-                Some(&ret_place),
+                &ret_place,
                 // Directly return to caller of `try`.
                 StackPopCleanup::Goto { ret: Some(catch_unwind.ret), unwind: StackPopUnwind::Skip },
             )?;
@@ -179,7 +179,7 @@ fn start_panic(&mut self, msg: &str, unwind: StackPopUnwind) -> InterpResult<'tc
             panic,
             Abi::Rust,
             &[msg.to_ref(this)],
-            None,
+            &MPlaceTy::dangling(this.machine.layouts.unit).into(),
             StackPopCleanup::Goto { ret: None, unwind },
         )
     }
@@ -208,7 +208,7 @@ fn assert_panic(
                     panic_bounds_check,
                     Abi::Rust,
                     &[index.into(), len.into()],
-                    None,
+                    &MPlaceTy::dangling(this.machine.layouts.unit).into(),
                     StackPopCleanup::Goto {
                         ret: None,
                         unwind: match unwind {
index b07bf91a69a54ffa18746f36afbe88deffd9cc49..0ea441e00e9ae291c5234cf1f6125fbc2fc686d2 100644 (file)
@@ -30,15 +30,16 @@ fn call_dlsym(
         dlsym: Dlsym,
         abi: Abi,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
     ) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
 
         this.check_abi(abi, Abi::C { unwind: false })?;
 
         match dlsym {
-            Dlsym::Linux(dlsym) => linux::EvalContextExt::call_dlsym(this, dlsym, args, ret),
-            Dlsym::MacOs(dlsym) => macos::EvalContextExt::call_dlsym(this, dlsym, args, ret),
+            Dlsym::Linux(dlsym) => linux::EvalContextExt::call_dlsym(this, dlsym, args, dest, ret),
+            Dlsym::MacOs(dlsym) => macos::EvalContextExt::call_dlsym(this, dlsym, args, dest, ret),
         }
     }
 }
index 1b7ac2754af7182ae415b6ab04d192e26826cfa5..a2d6570fe8d6410a2bcec1f5abcea6532cdc641e 100644 (file)
@@ -24,10 +24,11 @@ fn call_dlsym(
         &mut self,
         dlsym: Dlsym,
         _args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        _dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
     ) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
-        let (_dest, _ret) = ret.expect("we don't support any diverging dlsym");
+        let _ret = ret.expect("we don't support any diverging dlsym");
         assert!(this.tcx.sess.target.os == "linux");
 
         match dlsym {}
index 8ce56d35da653104707a98cf27bb619d52ecba07..9369548992e5390a82f9e344f81df1791cd374b8 100644 (file)
@@ -28,10 +28,11 @@ fn call_dlsym(
         &mut self,
         dlsym: Dlsym,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
     ) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
-        let (dest, ret) = ret.expect("we don't support any diverging dlsym");
+        let ret = ret.expect("we don't support any diverging dlsym");
         assert!(this.tcx.sess.target.os == "macos");
 
         match dlsym {
index 0b8684d39eb215eb59188d3023d8d572280a9a8b..88c3fb0bc8eab79467e9d994de97c9d41d48d000 100644 (file)
@@ -51,7 +51,7 @@ fn pthread_create(
             instance,
             Abi::C { unwind: false },
             &[*func_arg],
-            Some(&ret_place.into()),
+            &ret_place.into(),
             StackPopCleanup::Root { cleanup: true },
         )?;
 
index 3de739a8d048bece43c6b2edffef50413eac422a..87c8d7eadc3bbd7f271d8f24f4e7d438a1732c14 100644 (file)
@@ -258,7 +258,7 @@ fn schedule_windows_tls_dtors(&mut self) -> InterpResult<'tcx> {
             thread_callback,
             Abi::System { unwind: false },
             &[Scalar::null_ptr(this).into(), reason.into(), Scalar::null_ptr(this).into()],
-            Some(&ret_place),
+            &ret_place,
             StackPopCleanup::Root { cleanup: true },
         )?;
 
@@ -281,7 +281,7 @@ fn schedule_macos_tls_dtor(&mut self) -> InterpResult<'tcx, bool> {
                 instance,
                 Abi::C { unwind: false },
                 &[data.into()],
-                Some(&ret_place),
+                &ret_place,
                 StackPopCleanup::Root { cleanup: true },
             )?;
 
@@ -324,7 +324,7 @@ fn schedule_next_pthread_tls_dtor(&mut self) -> InterpResult<'tcx, bool> {
                 instance,
                 Abi::C { unwind: false },
                 &[ptr.into()],
-                Some(&ret_place),
+                &ret_place,
                 StackPopCleanup::Root { cleanup: true },
             )?;
 
index 865c01386045bf817985ad31178781533be5a130..b5408e492ce9c84e23b42c124c183f20f2042a2c 100644 (file)
@@ -31,10 +31,11 @@ fn call_dlsym(
         dlsym: Dlsym,
         abi: Abi,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
     ) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
-        let (dest, ret) = ret.expect("we don't support any diverging dlsym");
+        let ret = ret.expect("we don't support any diverging dlsym");
         assert!(this.tcx.sess.target.os == "windows");
 
         this.check_abi(abi, Abi::System { unwind: false })?;
index f137b861342a09748e14c9893629148da458a484..30a9cc265dce2bae4d56186c9c6c15b8ae14b03e 100644 (file)
@@ -930,12 +930,7 @@ fn qualify(ty: ty::Ty<'_>, kind: RetagKind) -> Option<(RefKind, bool)> {
     /// explicit. Also see https://github.com/rust-lang/rust/issues/71117.
     fn retag_return_place(&mut self) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
-        let return_place = if let Some(return_place) = this.frame_mut().return_place {
-            return_place
-        } else {
-            // No return place, nothing to do.
-            return Ok(());
-        };
+        let return_place = this.frame_mut().return_place;
         if return_place.layout.is_zst() {
             // There may not be any memory here, nothing to do.
             return Ok(());
@@ -955,7 +950,7 @@ fn retag_return_place(&mut self) -> InterpResult<'tcx> {
         )?;
         // And use reborrowed pointer for return place.
         let return_place = this.ref_to_mplace(&val)?;
-        this.frame_mut().return_place = Some(return_place.into());
+        this.frame_mut().return_place = return_place.into();
 
         Ok(())
     }