Skip to content

Commit 94a084a

Browse files
committed
Fix crash(!) by using the *Rust fn type* not the extern fn type
cc #3678
1 parent 4c75e92 commit 94a084a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/librustc/middle/trans/foreign.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use middle::trans::cabi;
2121
use middle::trans::build::*;
2222
use middle::trans::builder::noname;
2323
use middle::trans::common::*;
24+
use middle::trans::llrepr::LlvmRepr;
2425
use middle::trans::type_of::*;
2526
use middle::trans::type_of;
2627
use middle::ty;
@@ -399,7 +400,29 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: @mut CrateContext,
399400
ccx, vec::append_one((*path).clone(), ast_map::path_name(
400401
special_idents::clownshoe_abi
401402
)));
402-
let llty = type_of_fn_from_ty(ccx, t);
403+
404+
// Compute the LLVM type that the function would have if it
405+
// were just a normal Rust function. This will be the type of
406+
// the wrappee fn.
407+
let llty = match ty::get(t).sty {
408+
ty::ty_bare_fn(ref f) => {
409+
assert!(!f.abis.is_rust() && !f.abis.is_intrinsic());
410+
type_of_rust_fn(ccx, f.sig.inputs, f.sig.output)
411+
}
412+
_ => {
413+
ccx.sess.bug(fmt!("build_rust_fn: extern fn %s has ty %s, \
414+
expected a bare fn ty",
415+
path.repr(tcx),
416+
t.repr(tcx)));
417+
}
418+
};
419+
420+
debug!("build_rust_fn: path=%s id=%? t=%s llty=%s",
421+
path.repr(tcx),
422+
id,
423+
t.repr(tcx),
424+
llty.llrepr(ccx));
425+
403426
let llfndecl = base::decl_internal_cdecl_fn(ccx.llmod, ps, llty);
404427
base::trans_fn(ccx,
405428
(*path).clone(),

0 commit comments

Comments
 (0)