about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-08-19 21:28:31 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-08-21 10:50:32 -0400
commit94a084a4b45afe0bb8c1b1206184d4d0db4f4ec0 (patch)
treea5c924670718d8f367c38b4c60d9232daf50d993
parent4c75e926126435c3ea65b027ea9669213cfdae33 (diff)
downloadrust-94a084a4b45afe0bb8c1b1206184d4d0db4f4ec0.tar.gz
rust-94a084a4b45afe0bb8c1b1206184d4d0db4f4ec0.zip
Fix crash(!) by using the *Rust fn type* not the extern fn type
cc #3678
-rw-r--r--src/librustc/middle/trans/foreign.rs25
1 files changed, 24 insertions, 1 deletions
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::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;
@@ -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(),