Skip to content

Commit 48ee816

Browse files
committed
auto merge of #16346 : vadimcn/rust/win64-cabi, r=brson
This fixes run-pass/extern-pass-TwoU64s.rs run-pass/extern-pass-empty.rs run-pass/extern-return-TwoU64s.rs
2 parents beda30e + d1e03b3 commit 48ee816

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

src/librustc/middle/trans/cabi.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ use std::option;
1313
use middle::trans::context::CrateContext;
1414
use middle::trans::cabi_x86;
1515
use middle::trans::cabi_x86_64;
16+
use middle::trans::cabi_x86_win64;
1617
use middle::trans::cabi_arm;
1718
use middle::trans::cabi_mips;
1819
use middle::trans::type_::Type;
1920
use syntax::abi::{X86, X86_64, Arm, Mips, Mipsel};
21+
use syntax::abi::{OsWin32};
2022

2123
#[deriving(Clone, PartialEq)]
2224
pub enum ArgKind {
@@ -107,7 +109,12 @@ pub fn compute_abi_info(ccx: &CrateContext,
107109
ret_def: bool) -> FnType {
108110
match ccx.sess().targ_cfg.arch {
109111
X86 => cabi_x86::compute_abi_info(ccx, atys, rty, ret_def),
110-
X86_64 => cabi_x86_64::compute_abi_info(ccx, atys, rty, ret_def),
112+
X86_64 =>
113+
if ccx.sess().targ_cfg.os == OsWin32 {
114+
cabi_x86_win64::compute_abi_info(ccx, atys, rty, ret_def)
115+
} else {
116+
cabi_x86_64::compute_abi_info(ccx, atys, rty, ret_def)
117+
},
111118
Arm => cabi_arm::compute_abi_info(ccx, atys, rty, ret_def),
112119
Mips => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
113120
Mipsel => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2013 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+
use llvm::*;
12+
use super::cabi::*;
13+
use super::common::*;
14+
use super::machine::*;
15+
use middle::trans::type_::Type;
16+
17+
// Win64 ABI: http://msdn.microsoft.com/en-us/library/zthk2dkh.aspx
18+
19+
pub fn compute_abi_info(ccx: &CrateContext,
20+
atys: &[Type],
21+
rty: Type,
22+
ret_def: bool) -> FnType {
23+
let mut arg_tys = Vec::new();
24+
25+
let ret_ty;
26+
if !ret_def {
27+
ret_ty = ArgType::direct(Type::void(ccx), None, None, None);
28+
} else if rty.kind() == Struct {
29+
ret_ty = match llsize_of_alloc(ccx, rty) {
30+
1 => ArgType::direct(rty, Some(Type::i8(ccx)), None, None),
31+
2 => ArgType::direct(rty, Some(Type::i16(ccx)), None, None),
32+
4 => ArgType::direct(rty, Some(Type::i32(ccx)), None, None),
33+
8 => ArgType::direct(rty, Some(Type::i64(ccx)), None, None),
34+
_ => ArgType::indirect(rty, Some(StructRetAttribute))
35+
};
36+
} else {
37+
let attr = if rty == Type::i1(ccx) { Some(ZExtAttribute) } else { None };
38+
ret_ty = ArgType::direct(rty, None, None, attr);
39+
}
40+
41+
for &t in atys.iter() {
42+
let ty = match t.kind() {
43+
Struct => {
44+
match llsize_of_alloc(ccx, t) {
45+
1 => ArgType::direct(rty, Some(Type::i8(ccx)), None, None),
46+
2 => ArgType::direct(rty, Some(Type::i16(ccx)), None, None),
47+
4 => ArgType::direct(rty, Some(Type::i32(ccx)), None, None),
48+
8 => ArgType::direct(rty, Some(Type::i64(ccx)), None, None),
49+
_ => ArgType::indirect(t, Some(ByValAttribute))
50+
}
51+
}
52+
_ => {
53+
let attr = if t == Type::i1(ccx) { Some(ZExtAttribute) } else { None };
54+
ArgType::direct(t, None, None, attr)
55+
}
56+
};
57+
arg_tys.push(ty);
58+
}
59+
60+
return FnType {
61+
arg_tys: arg_tys,
62+
ret_ty: ret_ty,
63+
};
64+
}

src/librustc/middle/trans/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub mod meth;
3131
pub mod cabi;
3232
pub mod cabi_x86;
3333
pub mod cabi_x86_64;
34+
pub mod cabi_x86_win64;
3435
pub mod cabi_arm;
3536
pub mod cabi_mips;
3637
pub mod foreign;

0 commit comments

Comments
 (0)