Skip to content

Commit 4aaf02c

Browse files
committed
---
yaml --- r: 180131 b: refs/heads/tmp c: 0047f8b h: refs/heads/master i: 180129: 6bf0fb1 180127: 87190ad v: v3
1 parent 0be4346 commit 4aaf02c

File tree

5 files changed

+91
-8
lines changed

5 files changed

+91
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 44a287e6eb22ec3c2a687fc156813577464017f7
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 3bca5f23aa8ac7a9e27ec582e05c2420313515d7
37+
refs/heads/tmp: 0047f8bbd8f94c7ba54d42eb7272c89a48d6ae54

branches/tmp/src/librustc_trans/trans/foreign.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,14 +670,19 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
670670
}
671671
};
672672

673+
let rustfn_ty = Type::from_ref(llvm::LLVMTypeOf(llrustfn)).element_type();
674+
let mut rust_param_tys = rustfn_ty.func_params().into_iter();
673675
// Push Rust return pointer, using null if it will be unused.
674676
let rust_uses_outptr = match tys.fn_sig.output {
675677
ty::FnConverging(ret_ty) => type_of::return_uses_outptr(ccx, ret_ty),
676678
ty::FnDiverging => false
677679
};
678680
let return_alloca: Option<ValueRef>;
679-
let llrust_ret_ty = tys.llsig.llret_ty;
680-
let llrust_retptr_ty = llrust_ret_ty.ptr_to();
681+
let llrust_ret_ty = if rust_uses_outptr {
682+
rust_param_tys.next().expect("Missing return type!").element_type()
683+
} else {
684+
rustfn_ty.return_type()
685+
};
681686
if rust_uses_outptr {
682687
// Rust expects to use an outpointer. If the foreign fn
683688
// also uses an outpointer, we can reuse it, but the types
@@ -689,7 +694,7 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
689694
debug!("out pointer, foreign={}",
690695
ccx.tn().val_to_string(llforeign_outptr));
691696
let llrust_retptr =
692-
builder.bitcast(llforeign_outptr, llrust_retptr_ty);
697+
builder.bitcast(llforeign_outptr, llrust_ret_ty.ptr_to());
693698
debug!("out pointer, foreign={} (casted)",
694699
ccx.tn().val_to_string(llrust_retptr));
695700
llrust_args.push(llrust_retptr);
@@ -721,8 +726,13 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
721726
// a pointer and Rust does not or vice versa.
722727
for i in 0..tys.fn_sig.inputs.len() {
723728
let rust_ty = tys.fn_sig.inputs[i];
724-
let llrust_ty = tys.llsig.llarg_tys[i];
725729
let rust_indirect = type_of::arg_is_indirect(ccx, rust_ty);
730+
let llty = rust_param_tys.next().expect("Not enough parameter types!");
731+
let llrust_ty = if rust_indirect {
732+
llty.element_type()
733+
} else {
734+
llty
735+
};
726736
let llforeign_arg_ty = tys.fn_ty.arg_tys[i];
727737
let foreign_indirect = llforeign_arg_ty.is_indirect();
728738

@@ -838,7 +848,7 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
838848
// Foreign ABI requires an out pointer, but Rust doesn't.
839849
// Store Rust return value.
840850
let llforeign_outptr_casted =
841-
builder.bitcast(llforeign_outptr, llrust_retptr_ty);
851+
builder.bitcast(llforeign_outptr, llrust_ret_ty.ptr_to());
842852
builder.store(llrust_ret_val, llforeign_outptr_casted);
843853
builder.ret_void();
844854
}

branches/tmp/src/libstd/num/f32.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl Float for f32 {
173173
#[inline]
174174
fn exp(self) -> f32 { num::Float::exp(self) }
175175
#[inline]
176-
fn exp2(self) -> f32 { num::Float::exp(self) }
176+
fn exp2(self) -> f32 { num::Float::exp2(self) }
177177
#[inline]
178178
fn ln(self) -> f32 { num::Float::ln(self) }
179179
#[inline]
@@ -554,6 +554,33 @@ mod tests {
554554
assert_approx_eq!((-1.7f32).fract(), -0.7f32);
555555
}
556556

557+
#[test]
558+
fn test_exp() {
559+
assert_eq!(1.0, 0.0f32.exp());
560+
assert_approx_eq!(2.718282, 1.0f32.exp());
561+
assert_approx_eq!(148.413162, 5.0f32.exp());
562+
563+
let inf: f32 = Float::infinity();
564+
let neg_inf: f32 = Float::neg_infinity();
565+
let nan: f32 = Float::nan();
566+
assert_eq!(inf, inf.exp());
567+
assert_eq!(0.0, neg_inf.exp());
568+
assert!(nan.exp().is_nan());
569+
}
570+
571+
#[test]
572+
fn test_exp2() {
573+
assert_eq!(32.0, 5.0f32.exp2());
574+
assert_eq!(1.0, 0.0f32.exp2());
575+
576+
let inf: f32 = Float::infinity();
577+
let neg_inf: f32 = Float::neg_infinity();
578+
let nan: f32 = Float::nan();
579+
assert_eq!(inf, inf.exp2());
580+
assert_eq!(0.0, neg_inf.exp2());
581+
assert!(nan.exp2().is_nan());
582+
}
583+
557584
#[test]
558585
fn test_asinh() {
559586
assert_eq!(0.0f32.asinh(), 0.0f32);

branches/tmp/src/libstd/num/f64.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl Float for f64 {
183183
#[inline]
184184
fn exp(self) -> f64 { num::Float::exp(self) }
185185
#[inline]
186-
fn exp2(self) -> f64 { num::Float::exp(self) }
186+
fn exp2(self) -> f64 { num::Float::exp2(self) }
187187
#[inline]
188188
fn ln(self) -> f64 { num::Float::ln(self) }
189189
#[inline]
@@ -563,6 +563,33 @@ mod tests {
563563
assert_approx_eq!((-1.7f64).fract(), -0.7f64);
564564
}
565565

566+
#[test]
567+
fn test_exp() {
568+
assert_eq!(1.0, 0.0f64.exp());
569+
assert_approx_eq!(2.718282, 1.0f64.exp());
570+
assert_approx_eq!(148.413159, 5.0f64.exp());
571+
572+
let inf: f64 = Float::infinity();
573+
let neg_inf: f64 = Float::neg_infinity();
574+
let nan: f64 = Float::nan();
575+
assert_eq!(inf, inf.exp());
576+
assert_eq!(0.0, neg_inf.exp());
577+
assert!(nan.exp().is_nan());
578+
}
579+
580+
#[test]
581+
fn test_exp2() {
582+
assert_eq!(32.0, 5.0f64.exp2());
583+
assert_eq!(1.0, 0.0f64.exp2());
584+
585+
let inf: f64 = Float::infinity();
586+
let neg_inf: f64 = Float::neg_infinity();
587+
let nan: f64 = Float::nan();
588+
assert_eq!(inf, inf.exp2());
589+
assert_eq!(0.0, neg_inf.exp2());
590+
assert!(nan.exp2().is_nan());
591+
}
592+
566593
#[test]
567594
fn test_asinh() {
568595
assert_eq!(0.0f64.asinh(), 0.0f64);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[repr(C)]
12+
pub struct Foo(u32);
13+
14+
// ICE trigger, bad handling of differing types between rust and external ABIs
15+
pub extern fn bar() -> Foo {
16+
Foo(0)
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)