Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
if return_type == void_type {
self.block.end_with_void_return(self.location)
} else {
let abort = self.context.get_builtin_function("abort");
self.block.add_eval(self.location, self.context.new_call(self.location, abort, &[]));
let trap = self.context.get_builtin_function("__builtin_trap");
self.block.add_eval(self.location, self.context.new_call(self.location, trap, &[]));
let return_value = self.new_temp(self.current_func(), self.location, return_type);
self.block.end_with_return(self.location, return_value)
}
Expand Down
7 changes: 1 addition & 6 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
let isize_type = usize_type;
let bool_type = context.new_type::<bool>();

let mut functions = FxHashMap::default();
let builtins = ["abort"];

for builtin in builtins.iter() {
functions.insert(builtin.to_string(), context.get_builtin_function(builtin));
}
let functions = FxHashMap::default();

let mut cx = Self {
int128_align: tcx
Expand Down
6 changes: 2 additions & 4 deletions src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
sym::round_ties_even_f64 => "rint",
sym::roundf32 => "roundf",
sym::roundf64 => "round",
sym::abort => "abort",
_ => return None,
};
Some(cx.context.get_builtin_function(gcc_name))
Expand Down Expand Up @@ -641,9 +640,8 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
}

fn abort(&mut self) {
let func = self.context.get_builtin_function("abort");
let func: RValue<'gcc> = unsafe { std::mem::transmute(func) };
self.call(self.type_void(), None, None, func, &[], None, None);
let func = self.context.get_builtin_function("__builtin_trap");
self.block.add_eval(self.location, self.context.new_call(self.location, func, &[]));
}

fn assume(&mut self, value: Self::Value) {
Expand Down
27 changes: 27 additions & 0 deletions tests/run/custom_abort.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Compiler:
//
// Run-time:
// status: 42

// Check that a program can define its own `abort`.

#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]

extern crate mini_core;
use mini_core::*;

#[no_mangle]
extern "C" fn abort() {
unsafe {
libc::exit(42);
}
}

#[no_mangle]
extern "C" fn main(_argc: i32, _argv: *const *const u8) -> i32 {
abort();
0
}
Loading