Skip to content

Commit 8575acf

Browse files
committedJan 21, 2015
Disable aborting at FFI boundary in foreign-abi rust functions
1 parent e3ab8cb commit 8575acf

File tree

3 files changed

+7
-105
lines changed

3 files changed

+7
-105
lines changed
 

‎src/librustc_trans/trans/base.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2901,7 +2901,8 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
29012901
let ty = ty::node_id_to_type(ccx.tcx(), ni.id);
29022902
let name = foreign::link_name(&*ni);
29032903
let llfn = foreign::register_foreign_item_fn(ccx, abi, ty, &name.get()[]);
2904-
foreign::add_abi_attributes(ccx, llfn, abi, &ni.attrs[]);
2904+
// FIXME(aatch) Re-enable pending RFC
2905+
//foreign::add_abi_attributes(ccx, llfn, abi, &ni.attrs[]);
29052906
llfn
29062907
}
29072908
ast::ForeignItemStatic(..) => {

‎src/librustc_trans/trans/foreign.rs

+5-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -639,7 +639,7 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
639639
llrustfn: ValueRef,
640640
llwrapfn: ValueRef,
641641
tys: &ForeignTypes<'tcx>,
642-
t: Ty<'tcx>, attrs: &[ast::Attribute]) {
642+
t: Ty<'tcx>, _attrs: &[ast::Attribute]) {
643643
let _icx = push_ctxt(
644644
"foreign::trans_rust_fn_with_foreign_abi::build_wrap_fn");
645645
let tcx = ccx.tcx();
@@ -816,42 +816,10 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
816816
// Perform the call itself
817817
debug!("calling llrustfn = {}, t = {}",
818818
ccx.tn().val_to_string(llrustfn), t.repr(ccx.tcx()));
819+
// FIXME(aatch) Wrap the call in a try-catch and handle unwinding
820+
// pending RFC
819821
let attributes = base::get_fn_llvm_attributes(ccx, t);
820-
let llrust_ret_val = if attr::contains_name(attrs, "can_unwind") {
821-
debug!("fn can unwind - using call");
822-
builder.call(llrustfn, llrust_args.as_slice(), Some(attributes))
823-
} else {
824-
debug!("fn can't unwind - using invoke");
825-
// Create the landing pad and the return blocks
826-
let ptr = "catch\0".as_ptr();
827-
let catch_block = llvm::LLVMAppendBasicBlockInContext(ccx.llcx(), llwrapfn,
828-
ptr as *const _);
829-
830-
let ptr = "return\0".as_ptr();
831-
let return_block = llvm::LLVMAppendBasicBlockInContext(ccx.llcx(), llwrapfn,
832-
ptr as *const _);
833-
834-
835-
let llrust_ret_val = builder.invoke(llrustfn, llrust_args.as_slice(),
836-
return_block, catch_block,
837-
Some(attributes));
838-
839-
// Populate the landing pad
840-
builder.position_at_end(catch_block);
841-
let pad_ty = Type::struct_(ccx, &[Type::i8p(ccx), Type::i32(ccx)], false);
842-
let llpersonality = base::get_eh_personality(ccx);
843-
844-
let pad_ret_val = builder.landing_pad(pad_ty, llpersonality, 1us);
845-
builder.add_clause(pad_ret_val, C_null(Type::i8p(ccx)));
846-
let trap = ccx.get_intrinsic(&("llvm.trap"));
847-
builder.call(trap, &[], None);
848-
builder.unreachable();
849-
850-
builder.position_at_end(return_block);
851-
852-
llrust_ret_val
853-
854-
};
822+
let llrust_ret_val = builder.call(llrustfn, llrust_args.as_slice(), Some(attributes));
855823

856824
// Get the return value where the foreign fn expects it.
857825
let llforeign_ret_ty = match tys.fn_ty.ret_ty.cast {

‎src/test/run-pass/ffi-unwinding.rs

-67
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.