]> git.lizzy.rs Git - rust.git/blobdiff - src/helpers.rs
Detect `std` by checking if the crate defines `#[lang = "start"]` rather than string...
[rust.git] / src / helpers.rs
index 29fde55d86ddfbaa0ff66a11adabff0db21c722b..7f99aa1997068ae3099f0d01112423af4b71e488 100644 (file)
@@ -165,7 +165,7 @@ fn call_function(
         let this = self.eval_context_mut();
         let param_env = ty::ParamEnv::reveal_all(); // in Miri this is always the param_env we use... and this.param_env is private.
         let callee_abi = f.ty(*this.tcx, param_env).fn_sig(*this.tcx).abi();
-        if callee_abi != caller_abi {
+        if this.machine.enforce_abi && callee_abi != caller_abi {
             throw_ub_format!(
                 "calling a function with ABI {} using caller ABI {}",
                 callee_abi.name(),
@@ -616,6 +616,24 @@ fn read_wide_str(&self, sptr: Scalar<Tag>) -> InterpResult<'tcx, Vec<u16>> {
 
         Ok(wchars)
     }
+
+    /// Check that the ABI is what we expect.
+    fn check_abi<'a>(&self, abi: Abi, exp_abi: Abi) -> InterpResult<'a, ()> {
+        if self.eval_context_ref().machine.enforce_abi && abi != exp_abi {
+            throw_ub_format!(
+                "calling a function with ABI {} using caller ABI {}",
+                exp_abi.name(),
+                abi.name()
+            )
+        }
+        Ok(())
+    }
+
+    fn in_std(&self) -> bool {
+        let this = self.eval_context_ref();
+        this.tcx.def_path(this.frame().instance.def_id()).krate
+            == this.tcx.def_path(this.tcx.lang_items().start_fn().unwrap()).krate
+    }
 }
 
 /// Check that the number of args is what we expect.
@@ -631,19 +649,6 @@ pub fn check_arg_count<'a, 'tcx, const N: usize>(
     throw_ub_format!("incorrect number of arguments: got {}, expected {}", args.len(), N)
 }
 
-/// Check that the ABI is what we expect.
-pub fn check_abi<'a>(abi: Abi, exp_abi: Abi) -> InterpResult<'a, ()> {
-    if abi == exp_abi {
-        Ok(())
-    } else {
-        throw_ub_format!(
-            "calling a function with ABI {} using caller ABI {}",
-            exp_abi.name(),
-            abi.name()
-        )
-    }
-}
-
 pub fn isolation_error(name: &str) -> InterpResult<'static> {
     throw_machine_stop!(TerminationInfo::UnsupportedInIsolation(format!(
         "{} not available when isolation is enabled",