From 94a084a4b45afe0bb8c1b1206184d4d0db4f4ec0 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 19 Aug 2013 21:28:31 -0400 Subject: [PATCH] Fix crash(!) by using the *Rust fn type* not the extern fn type cc #3678 --- src/librustc/middle/trans/foreign.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 5586f1183ef..bd4e50e01b5 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -21,6 +21,7 @@ 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; @@ -399,7 +400,29 @@ fn build_rust_fn(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(),