Skip to content

Commit

Permalink
Add intrinsics::unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
Keegan McAllister committed Oct 5, 2014
1 parent 1f3cda8 commit 401aeaf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libcore/intrinsics.rs
Expand Up @@ -250,6 +250,13 @@ extern "rust-intrinsic" {
/// Abort the execution of the process.
pub fn abort() -> !;

/// Tell LLVM that this point in the code is not reachable,
/// enabling further optimizations.
///
/// NB: This is very different from the `unreachable!()` macro!
#[cfg(not(stage0))]
pub fn unreachable() -> !;

/// Execute a breakpoint trap, for inspection by a debugger.
pub fn breakpoint();

Expand Down
4 changes: 4 additions & 0 deletions src/librustc/middle/trans/intrinsic.rs
Expand Up @@ -228,6 +228,10 @@ pub fn trans_intrinsic_call<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, node: ast::N
Unreachable(bcx);
v
}
(_, "unreachable") => {
Unreachable(bcx);
C_nil(ccx)
}
(_, "breakpoint") => {
let llfn = ccx.get_intrinsic(&("llvm.debugtrap"));
Call(bcx, llfn, [], None)
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -5589,6 +5589,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
} else {
match name.get() {
"abort" => (0, Vec::new(), ty::mk_bot()),
"unreachable" => (0, Vec::new(), ty::mk_bot()),
"breakpoint" => (0, Vec::new(), ty::mk_nil()),
"size_of" |
"pref_align_of" | "min_align_of" => (1u, Vec::new(), ty::mk_uint()),
Expand Down

0 comments on commit 401aeaf

Please sign in to comment.