Skip to content

When declaring extern fns from external crates, use the correct abi #9196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2013
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
33 changes: 23 additions & 10 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use syntax::parse::token;
use syntax::parse::token::{special_idents};
use syntax::print::pprust::stmt_to_str;
use syntax::{ast, ast_util, codemap, ast_map};
use syntax::abi::{X86, X86_64, Arm, Mips};
use syntax::abi::{X86, X86_64, Arm, Mips, Rust, RustIntrinsic};
use syntax::visit;
use syntax::visit::Visitor;

Expand Down Expand Up @@ -813,15 +813,28 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t)
-> ValueRef {
let name = csearch::get_symbol(ccx.sess.cstore, did);
match ty::get(t).sty {
ty::ty_bare_fn(_) | ty::ty_closure(_) => {
let llty = type_of_fn_from_ty(ccx, t);
return get_extern_fn(&mut ccx.externs, ccx.llmod, name,
lib::llvm::CCallConv, llty);
}
_ => {
let llty = type_of(ccx, t);
return get_extern_const(&mut ccx.externs, ccx.llmod, name, llty);
}
ty::ty_bare_fn(ref fn_ty) => {
// Currently llvm_calling_convention triggers unimpl/bug on
// Rust/RustIntrinsic, so those two are handled specially here.
let cconv = match fn_ty.abis.for_arch(ccx.sess.targ_cfg.arch) {
Some(Rust) | Some(RustIntrinsic) => lib::llvm::CCallConv,
Some(*) | None => {
let c = foreign::llvm_calling_convention(ccx, fn_ty.abis);
c.unwrap_or(lib::llvm::CCallConv)
}
};
let llty = type_of_fn_from_ty(ccx, t);
return get_extern_fn(&mut ccx.externs, ccx.llmod, name, cconv, llty);
}
ty::ty_closure(_) => {
let llty = type_of_fn_from_ty(ccx, t);
return get_extern_fn(&mut ccx.externs, ccx.llmod, name,
lib::llvm::CCallConv, llty);
}
_ => {
let llty = type_of(ccx, t);
return get_extern_const(&mut ccx.externs, ccx.llmod, name, llty);
}
};
}

Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ struct LlvmSignature {
///////////////////////////////////////////////////////////////////////////
// Calls to external functions

fn llvm_calling_convention(ccx: @mut CrateContext,
abis: AbiSet)
-> Option<CallConv> {
pub fn llvm_calling_convention(ccx: &mut CrateContext,
abis: AbiSet) -> Option<CallConv> {
let arch = ccx.sess.targ_cfg.arch;
abis.for_arch(arch).map(|abi| {
match *abi {
Expand Down