about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-10-08 08:46:14 +0200
committerRalf Jung <post@ralfj.de>2024-10-10 08:33:07 +0200
commit7e21dce98c795f98d781894a9180cfcb59b3cd97 (patch)
tree5cf6bd2e0fe0dc5e0d9ef08753ff44feb7f015db
parent66fda4a8469464c428e750c5503953f52f14023e (diff)
downloadrust-7e21dce98c795f98d781894a9180cfcb59b3cd97.tar.gz
rust-7e21dce98c795f98d781894a9180cfcb59b3cd97.zip
remove handle_unsupported_foreign_item helper
-rw-r--r--src/tools/miri/src/helpers.rs16
-rw-r--r--src/tools/miri/src/shims/foreign_items.rs12
-rw-r--r--src/tools/miri/src/shims/unix/linux/foreign_items.rs5
-rw-r--r--src/tools/miri/tests/panic/unsupported_syscall.rs9
-rw-r--r--src/tools/miri/tests/panic/unsupported_syscall.stderr4
5 files changed, 10 insertions, 36 deletions
diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs
index 013bfe03aaf..8bd429deefc 100644
--- a/src/tools/miri/src/helpers.rs
+++ b/src/tools/miri/src/helpers.rs
@@ -14,7 +14,6 @@ use rustc_index::IndexVec;
 use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
 use rustc_middle::middle::dependency_format::Linkage;
 use rustc_middle::middle::exported_symbols::ExportedSymbol;
-use rustc_middle::mir;
 use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, MaybeResult, TyAndLayout};
 use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, UintTy};
 use rustc_session::config::CrateType;
@@ -949,21 +948,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
         crate_name == "std" || crate_name == "std_miri_test"
     }
 
-    /// Handler that should be called when an unsupported foreign item is encountered.
-    /// This function will either panic within the context of the emulated application
-    /// or return an error in the Miri process context
-    fn handle_unsupported_foreign_item(&mut self, error_msg: String) -> InterpResult<'tcx, ()> {
-        let this = self.eval_context_mut();
-        if this.machine.panic_on_unsupported {
-            // message is slightly different here to make automated analysis easier
-            let error_msg = format!("unsupported Miri functionality: {error_msg}");
-            this.start_panic(error_msg.as_ref(), mir::UnwindAction::Continue)?;
-            interp_ok(())
-        } else {
-            throw_machine_stop!(TerminationInfo::UnsupportedForeignItem(error_msg));
-        }
-    }
-
     fn check_abi_and_shim_symbol_clash(
         &mut self,
         abi: Abi,
diff --git a/src/tools/miri/src/shims/foreign_items.rs b/src/tools/miri/src/shims/foreign_items.rs
index 78b07f68b44..1a6c5e9112f 100644
--- a/src/tools/miri/src/shims/foreign_items.rs
+++ b/src/tools/miri/src/shims/foreign_items.rs
@@ -83,11 +83,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
                     return interp_ok(Some(body));
                 }
 
-                this.handle_unsupported_foreign_item(format!(
+                let error_msg = format!(
                     "can't call foreign function `{link_name}` on OS `{os}`",
                     os = this.tcx.sess.target.os,
-                ))?;
-                return interp_ok(None);
+                );
+                if this.machine.panic_on_unsupported {
+                    // message is slightly different here to make automated analysis easier
+                    let error_msg = format!("unsupported Miri functionality: {error_msg}");
+                    this.start_panic(error_msg.as_ref(), mir::UnwindAction::Continue)?;
+                } else {
+                    throw_machine_stop!(TerminationInfo::UnsupportedForeignItem(error_msg));
+                }
             }
         }
 
diff --git a/src/tools/miri/src/shims/unix/linux/foreign_items.rs b/src/tools/miri/src/shims/unix/linux/foreign_items.rs
index 2a72004378e..2f3e1f29dd2 100644
--- a/src/tools/miri/src/shims/unix/linux/foreign_items.rs
+++ b/src/tools/miri/src/shims/unix/linux/foreign_items.rs
@@ -168,10 +168,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
                         this.write_int(result.to_i32()?, dest)?;
                     }
                     id => {
-                        this.handle_unsupported_foreign_item(format!(
-                            "can't execute syscall with ID {id}"
-                        ))?;
-                        return interp_ok(EmulateItemResult::AlreadyJumped);
+                        throw_unsup_format!("can't execute syscall with ID {id}");
                     }
                 }
             }
diff --git a/src/tools/miri/tests/panic/unsupported_syscall.rs b/src/tools/miri/tests/panic/unsupported_syscall.rs
deleted file mode 100644
index bbb076b169a..00000000000
--- a/src/tools/miri/tests/panic/unsupported_syscall.rs
+++ /dev/null
@@ -1,9 +0,0 @@
-//@ignore-target: windows # no `syscall` on Windows
-//@ignore-target: apple # `syscall` is not supported on macOS
-//@compile-flags: -Zmiri-panic-on-unsupported
-
-fn main() {
-    unsafe {
-        libc::syscall(0);
-    }
-}
diff --git a/src/tools/miri/tests/panic/unsupported_syscall.stderr b/src/tools/miri/tests/panic/unsupported_syscall.stderr
deleted file mode 100644
index e9b2b5b6652..00000000000
--- a/src/tools/miri/tests/panic/unsupported_syscall.stderr
+++ /dev/null
@@ -1,4 +0,0 @@
-thread 'main' panicked at tests/panic/unsupported_syscall.rs:LL:CC:
-unsupported Miri functionality: can't execute syscall with ID 0
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
-note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect