authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-08 21:11:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-08 21:11:53-07:00
loga67893b0e124b95f5e1fade0245fef7ebb28b190
tree434df2c1fe3c181ceb8114f6c8a46910768d1f4f
parente06ac9537e94cf4863de7ca64112d7a63af60008

stage1: fix x86_64-windows C ABI classification logic

16 bytes vectors are special cased because compiler-rt currently relies on this.

1 files changed, 50 insertions(+), 14 deletions(-)

src/stage1/analyze.cpp+50-14
......@@ -8279,23 +8279,53 @@ Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents_buf) {
82798279
82808280static X64CABIClass type_windows_abi_x86_64_class(CodeGen *g, ZigType *ty, size_t ty_size) {
82818281 // https://docs.microsoft.com/en-gb/cpp/build/x64-calling-convention?view=vs-2017
8282 switch (ty_size) {
8283 case 1:
8284 case 2:
8285 case 4:
8286 case 8:
8287 break;
8288 case 16:
8289 return (ty->id == ZigTypeIdVector) ? X64CABIClass_SSE : X64CABIClass_MEMORY;
8290 default:
8291 return X64CABIClass_MEMORY;
8292 }
82828293 switch (ty->id) {
8283 case ZigTypeIdEnum:
8294 case ZigTypeIdInvalid:
8295 case ZigTypeIdMetaType:
8296 case ZigTypeIdComptimeFloat:
8297 case ZigTypeIdComptimeInt:
8298 case ZigTypeIdNull:
8299 case ZigTypeIdUndefined:
8300 case ZigTypeIdBoundFn:
8301 case ZigTypeIdOpaque:
8302 case ZigTypeIdEnumLiteral:
8303 zig_unreachable();
8304
8305 case ZigTypeIdFn:
8306 case ZigTypeIdPointer:
82848307 case ZigTypeIdInt:
82858308 case ZigTypeIdBool:
8309 case ZigTypeIdEnum:
8310 case ZigTypeIdVoid:
8311 case ZigTypeIdUnreachable:
8312 case ZigTypeIdErrorSet:
8313 case ZigTypeIdErrorUnion:
8314 case ZigTypeIdStruct:
8315 case ZigTypeIdUnion:
8316 case ZigTypeIdOptional:
8317 case ZigTypeIdFnFrame:
8318 case ZigTypeIdAnyFrame:
82868319 return X64CABIClass_INTEGER;
8320
82878321 case ZigTypeIdFloat:
82888322 case ZigTypeIdVector:
82898323 return X64CABIClass_SSE;
8290 case ZigTypeIdStruct:
8291 case ZigTypeIdUnion: {
8292 if (ty_size <= 8)
8293 return X64CABIClass_INTEGER;
8294 return X64CABIClass_MEMORY;
8295 }
8296 default:
8324
8325 case ZigTypeIdArray:
82978326 return X64CABIClass_Unknown;
82988327 }
8328 zig_unreachable();
82998329}
83008330
83018331static X64CABIClass type_system_V_abi_x86_64_class(CodeGen *g, ZigType *ty, size_t ty_size) {
......@@ -8374,17 +8404,19 @@ static X64CABIClass type_system_V_abi_x86_64_class(CodeGen *g, ZigType *ty, size
83748404
83758405X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) {
83768406 Error err;
8377
83788407 const size_t ty_size = type_size(g, ty);
8408
8409 if (g->zig_target->os == OsWindows || g->zig_target->os == OsUefi) {
8410 return type_windows_abi_x86_64_class(g, ty, ty_size);
8411 }
8412
83798413 ZigType *ptr_type;
83808414 if ((err = get_codegen_ptr_type(g, ty, &ptr_type))) return X64CABIClass_Unknown;
83818415 if (ptr_type != nullptr)
83828416 return X64CABIClass_INTEGER;
83838417
8384 if (g->zig_target->os == OsWindows || g->zig_target->os == OsUefi) {
8385 return type_windows_abi_x86_64_class(g, ty, ty_size);
8386 } else if (g->zig_target->arch == ZigLLVM_aarch64 ||
8387 g->zig_target->arch == ZigLLVM_aarch64_be)
8418 if (g->zig_target->arch == ZigLLVM_aarch64 ||
8419 g->zig_target->arch == ZigLLVM_aarch64_be)
83888420 {
83898421 X64CABIClass result = type_system_V_abi_x86_64_class(g, ty, ty_size);
83908422 return (result == X64CABIClass_MEMORY) ? X64CABIClass_MEMORY_nobyval : result;
......@@ -8989,8 +9021,12 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
89899021 struct_type->data.structure.llvm_full_type_queue_index = SIZE_MAX;
89909022 }
89919023
8992 if (struct_type->abi_size <= 16 && (struct_type->data.structure.layout == ContainerLayoutExtern || struct_type->data.structure.layout == ContainerLayoutPacked))
9024 if (struct_type->abi_size <= 16 &&
9025 (struct_type->data.structure.layout == ContainerLayoutExtern ||
9026 struct_type->data.structure.layout == ContainerLayoutPacked))
9027 {
89939028 resolve_llvm_c_abi_type(g, struct_type);
9029 }
89949030}
89959031
89969032// This is to be used instead of void for debug info types, to avoid tripping