Skip to content

Commit a81fa9e

Browse files
committed
---
yaml --- r: 273255 b: refs/heads/beta c: 9e036c0 h: refs/heads/master i: 273253: 670c5a0 273251: d8229b6 273247: 216fd9f
1 parent 98506bd commit a81fa9e

File tree

3 files changed

+56
-33
lines changed

3 files changed

+56
-33
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 80d939fd22361cc8652cd4d7006fd1964d9ab699
26+
refs/heads/beta: 9e036c0ff0e8ba6018f9e0240064f7f7cf26885f
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

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

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,18 @@ impl FnType {
150150
abi: Abi,
151151
sig: &ty::FnSig<'tcx>,
152152
extra_args: &[Ty<'tcx>]) -> FnType {
153+
let mut fn_ty = FnType::unadjusted(ccx, abi, sig, extra_args);
154+
fn_ty.adjust_for_abi(ccx, abi, sig);
155+
fn_ty
156+
}
157+
158+
pub fn unadjusted<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
159+
abi: Abi,
160+
sig: &ty::FnSig<'tcx>,
161+
extra_args: &[Ty<'tcx>]) -> FnType {
153162
use self::Abi::*;
154163
let cconv = match ccx.sess().target.target.adjust_abi(abi) {
155-
RustIntrinsic => {
156-
// Intrinsics are emitted at the call site
157-
ccx.sess().bug("asked to compute FnType of intrinsic");
158-
}
159-
PlatformIntrinsic => {
160-
// Intrinsics are emitted at the call site
161-
ccx.sess().bug("asked to compute FnType of platform intrinsic");
162-
}
163-
164+
RustIntrinsic | PlatformIntrinsic |
164165
Rust | RustCall => llvm::CCallConv,
165166

166167
// It's the ABI's job to select this, not us.
@@ -309,14 +310,20 @@ impl FnType {
309310
}
310311
}
311312

312-
let mut fty = FnType {
313+
FnType {
313314
args: args,
314315
ret: ret,
315316
variadic: sig.variadic,
316317
cconv: cconv
317-
};
318+
}
319+
}
318320

319-
if abi == Rust || abi == RustCall {
321+
pub fn adjust_for_abi<'a, 'tcx>(&mut self,
322+
ccx: &CrateContext<'a, 'tcx>,
323+
abi: Abi,
324+
sig: &ty::FnSig<'tcx>) {
325+
if abi == Abi::Rust || abi == Abi::RustCall ||
326+
abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
320327
let fixup = |arg: &mut ArgType| {
321328
if !arg.ty.is_aggregate() {
322329
// Scalars and vectors, always immediate.
@@ -332,49 +339,48 @@ impl FnType {
332339
arg.cast = Some(Type::ix(ccx, size * 8));
333340
}
334341
};
335-
if fty.ret.ty != Type::void(ccx) {
336-
// Fat pointers are returned by-value.
342+
// Fat pointers are returned by-value.
343+
if !self.ret.is_ignore() {
337344
if !type_is_fat_ptr(ccx.tcx(), sig.output.unwrap()) {
338-
fixup(&mut fty.ret);
345+
fixup(&mut self.ret);
339346
}
340347
}
341-
for arg in &mut fty.args {
348+
for arg in &mut self.args {
349+
if arg.is_ignore() { continue; }
342350
fixup(arg);
343351
}
344-
if fty.ret.is_indirect() {
345-
fty.ret.attrs.set(llvm::Attribute::StructRet);
352+
if self.ret.is_indirect() {
353+
self.ret.attrs.set(llvm::Attribute::StructRet);
346354
}
347-
return fty;
355+
return;
348356
}
349357

350358
match &ccx.sess().target.target.arch[..] {
351-
"x86" => cabi_x86::compute_abi_info(ccx, &mut fty),
359+
"x86" => cabi_x86::compute_abi_info(ccx, self),
352360
"x86_64" => if ccx.sess().target.target.options.is_like_windows {
353-
cabi_x86_win64::compute_abi_info(ccx, &mut fty);
361+
cabi_x86_win64::compute_abi_info(ccx, self);
354362
} else {
355-
cabi_x86_64::compute_abi_info(ccx, &mut fty);
363+
cabi_x86_64::compute_abi_info(ccx, self);
356364
},
357-
"aarch64" => cabi_aarch64::compute_abi_info(ccx, &mut fty),
365+
"aarch64" => cabi_aarch64::compute_abi_info(ccx, self),
358366
"arm" => {
359367
let flavor = if ccx.sess().target.target.target_os == "ios" {
360368
cabi_arm::Flavor::Ios
361369
} else {
362370
cabi_arm::Flavor::General
363371
};
364-
cabi_arm::compute_abi_info(ccx, &mut fty, flavor);
372+
cabi_arm::compute_abi_info(ccx, self, flavor);
365373
},
366-
"mips" => cabi_mips::compute_abi_info(ccx, &mut fty),
367-
"powerpc" => cabi_powerpc::compute_abi_info(ccx, &mut fty),
368-
"powerpc64" => cabi_powerpc64::compute_abi_info(ccx, &mut fty),
369-
"asmjs" => cabi_asmjs::compute_abi_info(ccx, &mut fty),
374+
"mips" => cabi_mips::compute_abi_info(ccx, self),
375+
"powerpc" => cabi_powerpc::compute_abi_info(ccx, self),
376+
"powerpc64" => cabi_powerpc64::compute_abi_info(ccx, self),
377+
"asmjs" => cabi_asmjs::compute_abi_info(ccx, self),
370378
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a))
371379
}
372380

373-
if fty.ret.is_indirect() {
374-
fty.ret.attrs.set(llvm::Attribute::StructRet);
381+
if self.ret.is_indirect() {
382+
self.ret.attrs.set(llvm::Attribute::StructRet);
375383
}
376-
377-
fty
378384
}
379385

380386
pub fn llvm_type(&self, ccx: &CrateContext) -> Type {

branches/beta/src/librustc_trans/trans/callee.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,23 @@ impl<'tcx> Callee<'tcx> {
210210
}
211211
}
212212

213+
/// Get the abi::FnType for a direct call. Mainly deals with the fact
214+
/// that a Virtual call doesn't take the vtable, like its shim does.
215+
/// The extra argument types are for variadic (extern "C") functions.
216+
pub fn direct_fn_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>,
217+
extra_args: &[Ty<'tcx>]) -> FnType {
218+
let abi = self.ty.fn_abi();
219+
let sig = ccx.tcx().erase_late_bound_regions(self.ty.fn_sig());
220+
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
221+
let mut fn_ty = FnType::unadjusted(ccx, abi, &sig, extra_args);
222+
if let Virtual(_) = self.data {
223+
// Don't pass the vtable, it's not an argument of the virtual fn.
224+
fn_ty.args[1].ignore();
225+
}
226+
fn_ty.adjust_for_abi(ccx, abi, &sig);
227+
fn_ty
228+
}
229+
213230
/// This behemoth of a function translates function calls. Unfortunately, in
214231
/// order to generate more efficient LLVM output at -O0, it has quite a complex
215232
/// signature (refactoring this into two functions seems like a good idea).

0 commit comments

Comments
 (0)