about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-04-26 18:48:34 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-04-26 19:01:30 -0700
commit05587ebdff53def560e04e853fbb3c272fa586d6 (patch)
treee7137bf6ac7405636b93d0775b25c5f5aaaba638 /src
parent532a65485dc2f6a18a81c513c3abfbb34cb88e65 (diff)
downloadrust-05587ebdff53def560e04e853fbb3c272fa586d6.tar.gz
rust-05587ebdff53def560e04e853fbb3c272fa586d6.zip
rustc: Ignore the return value of native functions that return nil. stage1 can build libstd now, though it leaks.
Diffstat (limited to 'src')
-rw-r--r--src/comp/middle/trans.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index a36821a7a6f..f789a216c17 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -6557,6 +6557,11 @@ fn decl_native_fn_and_pair(@crate_ctxt ccx,
         ty.ty_fn_args(ccx.tcx, fn_type),
         ty.ty_fn_ret(ccx.tcx, fn_type), num_ty_param);
 
+    // FIXME: If the returned type is not nil, then we assume it's 32 bits
+    // wide. This is obviously wildly unsafe. We should have a better FFI
+    // that allows types of different sizes to be returned.
+    auto rty_is_nil = ty.type_is_nil(ccx.tcx, ty.ty_fn_ret(ccx.tcx, fn_type));
+
     let vec[ValueRef] call_args = vec();
     auto arg_n = 3u;
     auto pass_task;
@@ -6635,7 +6640,11 @@ fn decl_native_fn_and_pair(@crate_ctxt ccx,
         rptr = bcx.build.BitCast(fcx.llretptr, T_ptr(T_i32()));
     }
 
-    bcx.build.Store(r, rptr);
+    // We don't store the return value if it's nil, to avoid stomping on a nil
+    // pointer. This is the only concession made to non-i32 return values. See
+    // the FIXME above.
+    if (!rty_is_nil) { bcx.build.Store(r, rptr); }
+
     bcx.build.RetVoid();
 
     // Tie up the llallocas -> lltop edge.