Skip to content

Commit e08391c

Browse files
committed
auto merge of #9699 : thestinger/rust/immediate, r=huonw,luqmana
struct Foo; fn foo() -> Foo { Foo } Before: ; Function Attrs: nounwind readnone uwtable define void @_ZN3foo18he8ca29755dedebbaf4v0.0E(%struct.Foo* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture) #0 { "function top level": ret void } After: ; Function Attrs: nounwind readnone uwtable define %struct.Foo @_ZN3foo18he8ca29755dedebbaf4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 { "function top level": ret %struct.Foo undef }
2 parents 6d59898 + f504461 commit e08391c

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/librustc/middle/trans/common.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,11 @@ pub fn type_is_immediate(ccx: &mut CrateContext, ty: ty::t) -> bool {
6969
if simple {
7070
return true;
7171
}
72-
// FIXME: #9651: C-like enums should also be immediate
73-
if ty::type_is_c_like_enum(ccx.tcx, ty) {
74-
return false;
75-
}
7672
match ty::get(ty).sty {
7773
// FIXME: #9651: small `ty_struct` should also be immediate
74+
ty::ty_struct(def_id, ref substs) => {
75+
ty::struct_fields(tcx, def_id, substs).is_empty()
76+
}
7877
ty::ty_enum(*) | ty::ty_tup(*) => {
7978
let llty = sizing_type_of(ccx, ty);
8079
llsize_of_alloc(ccx, llty) <= llsize_of_alloc(ccx, ccx.int_type)

src/librustc/middle/trans/expr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,9 @@ fn trans_imm_cast(bcx: @mut Block, expr: &ast::Expr,
17271727
(cast_enum, cast_float) => {
17281728
let bcx = bcx;
17291729
let repr = adt::represent_type(ccx, t_in);
1730-
let lldiscrim_a = adt::trans_get_discr(bcx, repr, llexpr);
1730+
let slot = Alloca(bcx, ll_t_in, "");
1731+
Store(bcx, llexpr, slot);
1732+
let lldiscrim_a = adt::trans_get_discr(bcx, repr, slot);
17311733
match k_out {
17321734
cast_integral => int_cast(bcx, ll_t_out,
17331735
val_ty(lldiscrim_a),

src/librustc/middle/trans/foreign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub fn trans_native_call(bcx: @mut Block,
222222
// Ensure that we always have the Rust value indirectly,
223223
// because it makes bitcasting easier.
224224
if !rust_indirect {
225-
let scratch = base::alloca(bcx, arg_tys[i].ty, "__arg");
225+
let scratch = base::alloca(bcx, type_of::type_of(ccx, fn_sig.inputs[i]), "__arg");
226226
Store(bcx, llarg_rust, scratch);
227227
llarg_rust = scratch;
228228
}

src/librustc/middle/trans/intrinsic.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
use back::{abi};
1414
use lib::llvm::{SequentiallyConsistent, Acquire, Release, Xchg};
15-
use lib::llvm::{ValueRef, Pointer};
15+
use lib::llvm::{ValueRef, Pointer, Array, Struct};
1616
use lib;
1717
use middle::trans::base::*;
1818
use middle::trans::build::*;
@@ -333,8 +333,12 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
333333
(Pointer, other) | (other, Pointer) if other != Pointer => {
334334
let tmp = Alloca(bcx, llouttype, "");
335335
Store(bcx, llsrcval, PointerCast(bcx, tmp, llintype.ptr_to()));
336-
let ll_load = Load(bcx, tmp);
337-
Ret(bcx, ll_load);
336+
Ret(bcx, Load(bcx, tmp));
337+
}
338+
(Array, _) | (_, Array) | (Struct, _) | (_, Struct) => {
339+
let tmp = Alloca(bcx, llouttype, "");
340+
Store(bcx, llsrcval, PointerCast(bcx, tmp, llintype.ptr_to()));
341+
Ret(bcx, Load(bcx, tmp));
338342
}
339343
_ => {
340344
let llbitcast = BitCast(bcx, llsrcval, llouttype);

0 commit comments

Comments
 (0)