]> git.lizzy.rs Git - rust.git/commitdiff
remove hack for panics
authorChristian Poveda <git@christianpoveda.xyz>
Wed, 12 Feb 2020 00:00:41 +0000 (19:00 -0500)
committerChristian Poveda <git@christianpoveda.xyz>
Wed, 19 Feb 2020 22:48:15 +0000 (17:48 -0500)
src/shims/foreign_items.rs
src/shims/foreign_items/posix.rs
src/shims/foreign_items/posix/linux.rs
src/shims/foreign_items/posix/macos.rs
src/shims/foreign_items/windows.rs

index 59f9a8c63a7e2a74817c7ee49466b8b442aa3848..14e08f5181f527e151d3c1294a4320dfc29a819f 100644 (file)
@@ -170,17 +170,10 @@ fn emulate_foreign_item(
         };
 
         // Next: functions that return.
-        match link_name {
-            "__rust_maybe_catch_panic" => {
-                this.handle_catch_panic(args, dest, ret)?;
-                return Ok(None);
-            }
-
-            _ => this.emulate_foreign_item_by_name(link_name, args, dest)?,
-        };
-
-        this.dump_place(*dest);
-        this.go_to_block(ret);
+        if this.emulate_foreign_item_by_name(link_name, args, dest, ret)? {
+            this.dump_place(*dest);
+            this.go_to_block(ret);
+        }
 
         Ok(None)
     }
@@ -190,7 +183,8 @@ fn emulate_foreign_item_by_name(
         link_name: &str,
         args: &[OpTy<'tcx, Tag>],
         dest: PlaceTy<'tcx, Tag>,
-    ) -> InterpResult<'tcx> {
+        ret: mir::BasicBlock,
+    ) -> InterpResult<'tcx, bool> {
         let this = self.eval_context_mut();
 
         // Here we dispatch all the shims for foreign functions. If you have a platform specific
@@ -293,6 +287,11 @@ fn emulate_foreign_item_by_name(
                 this.write_scalar(new_ptr, dest)?;
             }
 
+            "__rust_maybe_catch_panic" => {
+                this.handle_catch_panic(args, dest, ret)?;
+                return Ok(false);
+            }
+
             "memcmp" => {
                 let left = this.read_scalar(args[0])?.not_undef()?;
                 let right = this.read_scalar(args[1])?.not_undef()?;
@@ -330,12 +329,6 @@ fn emulate_foreign_item_by_name(
                 }
             }
 
-
-            "rename" => {
-                let result = this.rename(args[0], args[1])?;
-                this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
-            }
-
             "strlen" => {
                 let ptr = this.read_scalar(args[0])?.not_undef()?;
                 let n = this.memory.read_c_str(ptr)?.len();
@@ -442,13 +435,13 @@ fn emulate_foreign_item_by_name(
             }
 
             _ => match this.tcx.sess.target.target.target_os.to_lowercase().as_str() {
-                "linux" | "macos" => posix::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest)?,
-                "windows" => windows::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest)?,
+                "linux" | "macos" => return posix::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret),
+                "windows" => return windows::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret),
                 target => throw_unsup_format!("The {} target platform is not supported", target),
             }
         };
 
-        Ok(())
+        Ok(true)
     }
 
     /// Evaluates the scalar at the specified path. Returns Some(val)
index f524e4df291eeb669125ccbde8094fa881d20102..746a0f25ebb1fbdd66806505ced30fd819c505ef 100644 (file)
@@ -2,6 +2,7 @@
 mod macos;
 
 use crate::*;
+use rustc::mir;
 use rustc::ty::layout::{Align, LayoutOf, Size};
 
 impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
@@ -11,7 +12,8 @@ fn emulate_foreign_item_by_name(
         link_name: &str,
         args: &[OpTy<'tcx, Tag>],
         dest: PlaceTy<'tcx, Tag>,
-    ) -> InterpResult<'tcx> {
+        ret: mir::BasicBlock,
+    ) -> InterpResult<'tcx, bool> {
         let this = self.eval_context_mut();
         let tcx = &{ this.tcx.tcx };
 
@@ -97,6 +99,11 @@ fn emulate_foreign_item_by_name(
                 this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
             }
 
+            "rename" => {
+                let result = this.rename(args[0], args[1])?;
+                this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
+            }
+
             "posix_memalign" => {
                 let ret = this.deref_operand(args[0])?;
                 let align = this.read_scalar(args[1])?.to_machine_usize(this)?;
@@ -325,14 +332,14 @@ fn emulate_foreign_item_by_name(
 
             _ => {
                 match this.tcx.sess.target.target.target_os.to_lowercase().as_str() {
-                    "linux" => linux::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest)?,
-                    "macos" => macos::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest)?,
+                    "linux" => return linux::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret),
+                    "macos" => return macos::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret),
                     _ => unreachable!(),
                 }
             }
         };
 
-        Ok(())
+        Ok(true)
     }
 }
 
index 7267cc1af8e5ca21bfdbfce89c261d531ceabb0c..27e42b0082e5a3e79573e4d7209ef5ab8d4a7b12 100644 (file)
@@ -1,4 +1,5 @@
 use crate::*;
+use rustc::mir;
 
 impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
 pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
@@ -7,7 +8,8 @@ fn emulate_foreign_item_by_name(
         link_name: &str,
         args: &[OpTy<'tcx, Tag>],
         dest: PlaceTy<'tcx, Tag>,
-    ) -> InterpResult<'tcx> {
+        _ret: mir::BasicBlock,
+    ) -> InterpResult<'tcx, bool> {
         let this = self.eval_context_mut();
 
         match link_name {
@@ -83,6 +85,6 @@ fn emulate_foreign_item_by_name(
             _ => throw_unsup_format!("can't call foreign function: {}", link_name),
         };
 
-        Ok(())
+        Ok(true)
     }
 }
index c4bfb98562dbd1c95473d878902f876058aac8ce..274248e8b54f7489f3bc14ccd4b69ff92a2a4f04 100644 (file)
@@ -1,4 +1,5 @@
 use crate::*;
+use rustc::mir;
 
 impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
 pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
@@ -7,7 +8,8 @@ fn emulate_foreign_item_by_name(
         link_name: &str,
         args: &[OpTy<'tcx, Tag>],
         dest: PlaceTy<'tcx, Tag>,
-    ) -> InterpResult<'tcx> {
+        _ret: mir::BasicBlock,
+    ) -> InterpResult<'tcx, bool> {
         let this = self.eval_context_mut();
 
         match link_name {
@@ -108,7 +110,7 @@ fn emulate_foreign_item_by_name(
             _ => throw_unsup_format!("can't call foreign function: {}", link_name),
         };
 
-        Ok(())
+        Ok(true)
     }
 }
 
index e16a89a126fd1d5d269f2084a59d296e8ae5c83f..b0d323439714a4d28ccc98ecd77350c4694a6aab 100644 (file)
@@ -1,4 +1,5 @@
 use crate::*;
+use rustc::mir;
 use rustc::ty::layout::Size;
 use std::iter;
 
@@ -9,7 +10,8 @@ fn emulate_foreign_item_by_name(
         link_name: &str,
         args: &[OpTy<'tcx, Tag>],
         dest: PlaceTy<'tcx, Tag>,
-    ) -> InterpResult<'tcx> {
+        _ret: mir::BasicBlock,
+    ) -> InterpResult<'tcx, bool> {
         let this = self.eval_context_mut();
         let tcx = &{ this.tcx.tcx };
 
@@ -197,7 +199,7 @@ fn emulate_foreign_item_by_name(
             _ => throw_unsup_format!("can't call foreign function: {}", link_name),
         }
 
-        Ok(())
+        Ok(true)
     }
 }