aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-03-20 00:11:11 -0400
committerGitHub <noreply@github.com>2019-03-20 00:11:11 -0400
commit2fdf69bc4082c49a571c0ee7bb7441d910def795 (patch)
tree85777989a8f3976826612d50204aa655a2b4d8fd /src/analyze.cpp
parentac34841270d34fb2f47ada2960d7281328ec7b25 (diff)
parentd669db76732a5137f9e37a22d08f5cba319a122d (diff)
downloadzig-2fdf69bc4082c49a571c0ee7bb7441d910def795.tar.gz
zig-2fdf69bc4082c49a571c0ee7bb7441d910def795.zip
Merge pull request #2079 from Sahnvour/issue-2050
Fixes c_ABI tests on windows
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index cadb5dfc01..c83327bbdf 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -6699,10 +6699,28 @@ Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents) {
}
}
-X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) {
- size_t ty_size = type_size(g, ty);
- if (get_codegen_ptr_type(ty) != nullptr)
- return X64CABIClass_INTEGER;
+static X64CABIClass type_windows_abi_x86_64_class(CodeGen *g, ZigType *ty, size_t ty_size) {
+ // https://docs.microsoft.com/en-gb/cpp/build/x64-calling-convention?view=vs-2017
+ switch (ty->id) {
+ case ZigTypeIdEnum:
+ case ZigTypeIdInt:
+ case ZigTypeIdBool:
+ return X64CABIClass_INTEGER;
+ case ZigTypeIdFloat:
+ case ZigTypeIdVector:
+ return X64CABIClass_SSE;
+ case ZigTypeIdStruct:
+ case ZigTypeIdUnion: {
+ if (ty_size <= 8)
+ return X64CABIClass_INTEGER;
+ return X64CABIClass_MEMORY;
+ }
+ default:
+ return X64CABIClass_Unknown;
+ }
+}
+
+static X64CABIClass type_system_V_abi_x86_64_class(CodeGen *g, ZigType *ty, size_t ty_size) {
switch (ty->id) {
case ZigTypeIdEnum:
case ZigTypeIdInt:
@@ -6770,6 +6788,18 @@ X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) {
}
}
+X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) {
+ const size_t ty_size = type_size(g, ty);
+ if (get_codegen_ptr_type(ty) != nullptr)
+ return X64CABIClass_INTEGER;
+
+ if (g->zig_target->os == OsWindows || g->zig_target->os == OsUefi) {
+ return type_windows_abi_x86_64_class(g, ty, ty_size);
+ } else {
+ return type_system_V_abi_x86_64_class(g, ty, ty_size);
+ }
+}
+
// NOTE this does not depend on x86_64
bool type_is_c_abi_int(CodeGen *g, ZigType *ty) {
return (ty->id == ZigTypeIdInt ||