From 45e2cf39a21b6317e01adff05a3c83c628913edc Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 14 Oct 2013 21:51:03 -0400 Subject: [PATCH] add an `abort` intrinsic This should be preferred to the libc `abort` function. --- src/librustc/middle/trans/intrinsic.rs | 5 +++++ src/librustc/middle/typeck/check/mod.rs | 1 + src/libstd/unstable/intrinsics.rs | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/librustc/middle/trans/intrinsic.rs b/src/librustc/middle/trans/intrinsic.rs index f081bef69fa..1b9ed862875 100644 --- a/src/librustc/middle/trans/intrinsic.rs +++ b/src/librustc/middle/trans/intrinsic.rs @@ -222,6 +222,11 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, } 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); diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index fad766f5066..27b5fd490e0 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -3585,6 +3585,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { } 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)), diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index 59b3c264b99..7cda2b109d9 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -171,6 +171,9 @@ pub trait TyVisitor { } 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;