Skip to content

Commit

Permalink
Fix crash(!) by using the *Rust fn type* not the extern fn type
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Aug 21, 2013
1 parent 4c75e92 commit 94a084a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/librustc/middle/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use middle::trans::cabi;
use middle::trans::build::*;
use middle::trans::builder::noname;
use middle::trans::common::*;
use middle::trans::llrepr::LlvmRepr;
use middle::trans::type_of::*;
use middle::trans::type_of;
use middle::ty;
Expand Down Expand Up @@ -399,7 +400,29 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: @mut CrateContext,
ccx, vec::append_one((*path).clone(), ast_map::path_name(
special_idents::clownshoe_abi
)));
let llty = type_of_fn_from_ty(ccx, t);

// Compute the LLVM type that the function would have if it
// were just a normal Rust function. This will be the type of
// the wrappee fn.
let llty = match ty::get(t).sty {
ty::ty_bare_fn(ref f) => {
assert!(!f.abis.is_rust() && !f.abis.is_intrinsic());
type_of_rust_fn(ccx, f.sig.inputs, f.sig.output)
}
_ => {
ccx.sess.bug(fmt!("build_rust_fn: extern fn %s has ty %s, \
expected a bare fn ty",
path.repr(tcx),
t.repr(tcx)));
}
};

debug!("build_rust_fn: path=%s id=%? t=%s llty=%s",
path.repr(tcx),
id,
t.repr(tcx),
llty.llrepr(ccx));

let llfndecl = base::decl_internal_cdecl_fn(ccx.llmod, ps, llty);
base::trans_fn(ccx,
(*path).clone(),
Expand Down

0 comments on commit 94a084a

Please sign in to comment.