Skip to content

Commit a4e9d9a

Browse files
committed
---
yaml --- r: 282014 b: refs/heads/stable c: 80d939f h: refs/heads/master
1 parent 4b5d7cc commit a4e9d9a

File tree

11 files changed

+67
-57
lines changed

11 files changed

+67
-57
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: 3c795e08d6f4a532f12f3f8e1837db5e0647f8b0
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 7454b5c61de7e4eb6ac0079d38d9a42d9f0d8539
32+
refs/heads/stable: 80d939fd22361cc8652cd4d7006fd1964d9ab699
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/librustc_trans/trans/abi.rs

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use llvm::{self, ValueRef};
12-
use trans::common::{return_type_is_void, type_is_fat_ptr};
12+
use trans::common::{type_is_fat_ptr, Block};
1313
use trans::context::CrateContext;
1414
use trans::cabi_x86;
1515
use trans::cabi_x86_64;
@@ -20,7 +20,7 @@ use trans::cabi_powerpc;
2020
use trans::cabi_powerpc64;
2121
use trans::cabi_mips;
2222
use trans::cabi_asmjs;
23-
use trans::machine::{llsize_of_alloc, llsize_of_real};
23+
use trans::machine::{llalign_of_min, llsize_of, llsize_of_real};
2424
use trans::type_::Type;
2525
use trans::type_of;
2626

@@ -97,6 +97,8 @@ impl ArgType {
9797
}
9898

9999
pub fn make_indirect(&mut self, ccx: &CrateContext) {
100+
assert_eq!(self.kind, ArgKind::Direct);
101+
100102
// Wipe old attributes, likely not valid through indirection.
101103
self.attrs = llvm::Attributes::default();
102104

@@ -113,6 +115,7 @@ impl ArgType {
113115
}
114116

115117
pub fn ignore(&mut self) {
118+
assert_eq!(self.kind, ArgKind::Direct);
116119
self.kind = ArgKind::Ignore;
117120
}
118121

@@ -200,39 +203,40 @@ impl FnType {
200203
arg.attrs.set(llvm::Attribute::ZExt);
201204
arg
202205
} else {
203-
ArgType::new(type_of::type_of(ccx, ty),
204-
type_of::sizing_type_of(ccx, ty))
206+
let mut arg = ArgType::new(type_of::type_of(ccx, ty),
207+
type_of::sizing_type_of(ccx, ty));
208+
if llsize_of_real(ccx, arg.ty) == 0 {
209+
arg.ignore();
210+
}
211+
arg
205212
}
206213
};
207214

208-
let mut ret = match sig.output {
209-
ty::FnConverging(ret_ty) if !return_type_is_void(ccx, ret_ty) => {
210-
arg_of(ret_ty)
211-
}
212-
_ => ArgType::new(Type::void(ccx), Type::void(ccx))
215+
let ret_ty = match sig.output {
216+
ty::FnConverging(ret_ty) => ret_ty,
217+
ty::FnDiverging => ccx.tcx().mk_nil()
213218
};
219+
let mut ret = arg_of(ret_ty);
220+
221+
if !type_is_fat_ptr(ccx.tcx(), ret_ty) {
222+
// The `noalias` attribute on the return value is useful to a
223+
// function ptr caller.
224+
if let ty::TyBox(_) = ret_ty.sty {
225+
// `Box` pointer return values never alias because ownership
226+
// is transferred
227+
ret.attrs.set(llvm::Attribute::NoAlias);
228+
}
214229

215-
if let ty::FnConverging(ret_ty) = sig.output {
216-
if !type_is_fat_ptr(ccx.tcx(), ret_ty) {
217-
// The `noalias` attribute on the return value is useful to a
218-
// function ptr caller.
219-
if let ty::TyBox(_) = ret_ty.sty {
220-
// `Box` pointer return values never alias because ownership
221-
// is transferred
222-
ret.attrs.set(llvm::Attribute::NoAlias);
223-
}
224-
225-
// We can also mark the return value as `dereferenceable` in certain cases
226-
match ret_ty.sty {
227-
// These are not really pointers but pairs, (pointer, len)
228-
ty::TyRef(_, ty::TypeAndMut { ty, .. }) |
229-
ty::TyBox(ty) => {
230-
let llty = type_of::sizing_type_of(ccx, ty);
231-
let llsz = llsize_of_real(ccx, llty);
232-
ret.attrs.set_dereferenceable(llsz);
233-
}
234-
_ => {}
230+
// We can also mark the return value as `dereferenceable` in certain cases
231+
match ret_ty.sty {
232+
// These are not really pointers but pairs, (pointer, len)
233+
ty::TyRef(_, ty::TypeAndMut { ty, .. }) |
234+
ty::TyBox(ty) => {
235+
let llty = type_of::sizing_type_of(ccx, ty);
236+
let llsz = llsize_of_real(ccx, llty);
237+
ret.attrs.set_dereferenceable(llsz);
235238
}
239+
_ => {}
236240
}
237241
}
238242

@@ -318,8 +322,8 @@ impl FnType {
318322
// Scalars and vectors, always immediate.
319323
return;
320324
}
321-
let size = llsize_of_alloc(ccx, arg.ty);
322-
if size > llsize_of_alloc(ccx, ccx.int_type()) {
325+
let size = llsize_of_real(ccx, arg.ty);
326+
if size > llsize_of_real(ccx, ccx.int_type()) {
323327
arg.make_indirect(ccx);
324328
} else if size > 0 {
325329
// We want to pass small aggregates as immediates, but using
@@ -376,7 +380,9 @@ impl FnType {
376380
pub fn llvm_type(&self, ccx: &CrateContext) -> Type {
377381
let mut llargument_tys = Vec::new();
378382

379-
let llreturn_ty = if self.ret.is_indirect() {
383+
let llreturn_ty = if self.ret.is_ignore() {
384+
Type::void(ccx)
385+
} else if self.ret.is_indirect() {
380386
llargument_tys.push(self.ret.original_ty.ptr_to());
381387
Type::void(ccx)
382388
} else {
@@ -410,7 +416,9 @@ impl FnType {
410416

411417
pub fn apply_attrs_llfn(&self, llfn: ValueRef) {
412418
let mut i = if self.ret.is_indirect() { 1 } else { 0 };
413-
self.ret.attrs.apply_llfn(i, llfn);
419+
if !self.ret.is_ignore() {
420+
self.ret.attrs.apply_llfn(i, llfn);
421+
}
414422
i += 1;
415423
for arg in &self.args {
416424
if !arg.is_ignore() {
@@ -423,7 +431,9 @@ impl FnType {
423431

424432
pub fn apply_attrs_callsite(&self, callsite: ValueRef) {
425433
let mut i = if self.ret.is_indirect() { 1 } else { 0 };
426-
self.ret.attrs.apply_callsite(i, callsite);
434+
if !self.ret.is_ignore() {
435+
self.ret.attrs.apply_callsite(i, callsite);
436+
}
427437
i += 1;
428438
for arg in &self.args {
429439
if !arg.is_ignore() {

branches/stable/src/librustc_trans/trans/cabi_aarch64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,12 @@ fn is_reg_ty(ty: Type) -> bool {
229229
}
230230

231231
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
232-
if fty.ret.ty != Type::void(ccx) {
232+
if !fty.ret.is_ignore() {
233233
classify_ret_ty(ccx, &mut fty.ret);
234234
}
235235

236236
for arg in &mut fty.args {
237+
if arg.is_ignore() { continue; }
237238
classify_arg_ty(ccx, arg);
238239
}
239240
}

branches/stable/src/librustc_trans/trans/cabi_arm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,12 @@ pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType, flavor: Flavor) {
179179
Flavor::Ios => ios_ty_align as TyAlignFn,
180180
};
181181

182-
if fty.ret.ty != Type::void(ccx) {
182+
if !fty.ret.is_ignore() {
183183
classify_ret_ty(ccx, &mut fty.ret, align_fn);
184184
}
185185

186186
for arg in &mut fty.args {
187+
if arg.is_ignore() { continue; }
187188
classify_arg_ty(ccx, arg, align_fn);
188189
}
189190
}

branches/stable/src/librustc_trans/trans/cabi_asmjs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use llvm::{Struct, Array, Attribute};
1414
use trans::abi::{FnType, ArgType};
1515
use trans::context::CrateContext;
16-
use trans::type_::Type;
1716

1817
// Data layout: e-p:32:32-i64:64-v128:32:128-n32-S128
1918

@@ -45,11 +44,12 @@ fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) {
4544
}
4645

4746
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
48-
if fty.ret.ty != Type::void(ccx) {
47+
if !fty.ret.is_ignore() {
4948
classify_ret_ty(ccx, &mut fty.ret);
5049
}
5150

5251
for arg in &mut fty.args {
52+
if arg.is_ignore() { continue; }
5353
classify_arg_ty(ccx, arg);
5454
}
5555
}

branches/stable/src/librustc_trans/trans/cabi_mips.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,13 @@ fn struct_ty(ccx: &CrateContext, ty: Type) -> Type {
146146
}
147147

148148
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
149-
if fty.ret.ty != Type::void(ccx) {
150-
if !is_reg_ty(fty.ret.ty) {
151-
fty.ret.make_indirect(ccx);
152-
}
149+
if !fty.ret.is_ignore() && !is_reg_ty(fty.ret.ty) {
150+
fty.ret.make_indirect(ccx);
153151
}
154152

155153
let mut offset = if fty.ret.is_indirect() { 4 } else { 0 };
156154
for arg in &mut fty.args {
155+
if arg.is_ignore() { continue; }
157156
classify_arg_ty(ccx, arg, &mut offset);
158157
}
159158
}

branches/stable/src/librustc_trans/trans/cabi_powerpc.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,13 @@ fn struct_ty(ccx: &CrateContext, ty: Type) -> Type {
141141
}
142142

143143
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
144-
if fty.ret.ty != Type::void(ccx) {
145-
if !is_reg_ty(fty.ret.ty) {
146-
fty.ret.make_indirect(ccx);
147-
}
144+
if !fty.ret.is_ignore() && !is_reg_ty(fty.ret.ty) {
145+
fty.ret.make_indirect(ccx);
148146
}
149147

150148
let mut offset = if fty.ret.is_indirect() { 4 } else { 0 };
151149
for arg in &mut fty.args {
150+
if arg.is_ignore() { continue; }
152151
classify_arg_ty(ccx, arg, &mut offset);
153152
}
154153
}

branches/stable/src/librustc_trans/trans/cabi_powerpc64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,12 @@ fn struct_ty(ccx: &CrateContext, ty: Type) -> Type {
232232
}
233233

234234
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
235-
if fty.ret.ty != Type::void(ccx) {
235+
if !fty.ret.is_ignore() {
236236
classify_ret_ty(ccx, &mut fty.ret);
237237
}
238238

239239
for arg in &mut fty.args {
240+
if arg.is_ignore() { continue; }
240241
classify_arg_ty(ccx, arg);
241242
}
242243
}

branches/stable/src/librustc_trans/trans/cabi_x86.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::common::*;
1515
use super::machine::*;
1616

1717
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
18-
if fty.ret.ty.kind() == Struct {
18+
if !fty.ret.is_ignore() && fty.ret.ty.kind() == Struct {
1919
// Returning a structure. Most often, this will use
2020
// a hidden first argument. On some platforms, though,
2121
// small structs are returned as integers.
@@ -38,13 +38,10 @@ pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
3838
}
3939

4040
for arg in &mut fty.args {
41+
if arg.is_ignore() { continue; }
4142
if arg.ty.kind() == Struct {
42-
if llsize_of_alloc(ccx, arg.ty) == 0 {
43-
arg.ignore();
44-
} else {
45-
arg.make_indirect(ccx);
46-
arg.attrs.set(Attribute::ByVal);
47-
}
43+
arg.make_indirect(ccx);
44+
arg.attrs.set(Attribute::ByVal);
4845
}
4946
}
5047
}

branches/stable/src/librustc_trans/trans/cabi_x86_64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
406406
let mut int_regs = 6; // RDI, RSI, RDX, RCX, R8, R9
407407
let mut sse_regs = 8; // XMM0-7
408408

409-
if fty.ret.ty != Type::void(ccx) {
409+
if !fty.ret.is_ignore() {
410410
x86_64_ty(ccx, &mut fty.ret, |cls| {
411411
if cls.is_ret_bysret() {
412412
// `sret` parameter thus one less register available
@@ -419,6 +419,7 @@ pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
419419
}
420420

421421
for arg in &mut fty.args {
422+
if arg.is_ignore() { continue; }
422423
x86_64_ty(ccx, arg, |cls| {
423424
let needed_int = cls.iter().filter(|&&c| c == Int).count() as isize;
424425
let needed_sse = cls.iter().filter(|c| c.is_sse()).count() as isize;

0 commit comments

Comments
 (0)