@@ -3851,23 +3851,31 @@ fn trans_c_stack_native_call(bcx: @block_ctxt, f: @ast::expr,
3851
3851
check type_has_static_size ( ccx, ret_ty) ;
3852
3852
let llretty = type_of ( ccx, f. span , ret_ty) ;
3853
3853
3854
- // Allocate the argument bundle.
3855
- let llargbundlety = T_struct ( llargtys + [ llretty] ) ;
3856
- let llargbundlesz = llsize_of ( ccx, llargbundlety) ;
3857
- let llrawargbundle = Call ( bcx, ccx. upcalls . alloc_c_stack ,
3858
- [ llargbundlesz] ) ;
3859
- let llargbundle = PointerCast ( bcx, llrawargbundle, T_ptr ( llargbundlety) ) ;
3860
-
3861
- // Translate arguments and store into bundle.
3854
+ // Translate arguments.
3855
+ // n.b.: We must do this before allocating the argument
3856
+ // bundle in order to avoid problems with nested function calls.
3862
3857
let ( to_zero, to_revoke) = ( [ ] , [ ] ) ;
3863
3858
let i = 0 u, n = vec:: len ( args) ;
3859
+ let llargs = [ ] ;
3864
3860
while i < n {
3865
3861
let ty_arg = fn_arg_tys[ i] ;
3866
3862
let arg = args[ i] ;
3867
3863
let llargty = llargtys[ i] ;
3868
3864
let r = trans_arg_expr ( bcx, ty_arg, llargty, to_zero, to_revoke, arg) ;
3869
3865
bcx = r. bcx ;
3870
- store_inbounds ( bcx, r. val , llargbundle, [ 0 , i as int ] ) ;
3866
+ llargs += [ r. val ] ;
3867
+ i += 1 u;
3868
+ }
3869
+
3870
+ // Allocate the argument bundle and store arguments.
3871
+ let llargbundlety = T_struct ( llargtys + [ llretty] ) ;
3872
+ let llargbundlesz = llsize_of ( ccx, llargbundlety) ;
3873
+ let llrawargbundle = Call ( bcx, ccx. upcalls . alloc_c_stack ,
3874
+ [ llargbundlesz] ) ;
3875
+ let llargbundle = PointerCast ( bcx, llrawargbundle, T_ptr ( llargbundlety) ) ;
3876
+ i = 0 u;
3877
+ while i < n {
3878
+ store_inbounds ( bcx, llargs[ i] , llargbundle, [ 0 , i as int ] ) ;
3871
3879
i += 1 u;
3872
3880
}
3873
3881
0 commit comments