]> git.lizzy.rs Git - rust.git/commitdiff
add an `abort` intrinsic
authorDaniel Micay <danielmicay@gmail.com>
Tue, 15 Oct 2013 01:51:03 +0000 (21:51 -0400)
committerDaniel Micay <danielmicay@gmail.com>
Tue, 15 Oct 2013 02:45:43 +0000 (22:45 -0400)
This should be preferred to the libc `abort` function.

src/librustc/middle/trans/intrinsic.rs
src/librustc/middle/typeck/check/mod.rs
src/libstd/unstable/intrinsics.rs

index f081bef69faae971ae6e1a4943b07d811f72ac2f..1b9ed862875a8b0ff7e98d8da7be3f9b2ec38c7a 100644 (file)
@@ -222,6 +222,11 @@ fn count_zeros_intrinsic(bcx: @mut Block, name: &'static str) {
     }
 
     match name {
+        "abort" => {
+            let llfn = bcx.ccx().intrinsics.get_copy(&("llvm.trap"));
+            Call(bcx, llfn, [], []);
+            RetVoid(bcx);
+        }
         "size_of" => {
             let tp_ty = substs.tys[0];
             let lltp_ty = type_of::type_of(ccx, tp_ty);
index fad766f5066d2938ddb201a3f19c8f80b060a6fe..27b5fd490e072bf4cc37190ffa84727c3fc14eac 100644 (file)
@@ -3585,6 +3585,7 @@ fn param(ccx: @mut CrateCtxt, n: uint) -> ty::t {
 
     } else {
         match name {
+            "abort"  => (0, ~[], ty::mk_bot()),
             "size_of" |
             "pref_align_of" | "min_align_of" => (1u, ~[], ty::mk_uint()),
             "init" => (1u, ~[], param(ccx, 0u)),
index 59b3c264b99f5541bb627677af4658940ce8fbe9..7cda2b109d9bc283333bf50ec42fd8594c1a372d 100644 (file)
@@ -171,6 +171,9 @@ fn visit_leave_fn(&mut self, purity: uint, proto: uint,
 }
 
 extern "rust-intrinsic" {
+    /// Abort the execution of the process.
+    #[cfg(not(stage0))]
+    pub fn abort() -> !;
 
     /// Atomic compare and exchange, sequentially consistent.
     pub fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;