Author: arnolds Date: Wed Jun 21 16:43:40 2017 New Revision: 305956 URL: http://llvm.org/viewvc/llvm-project?rev=305956&view=rev Log: SwiftCC: Perform physical layout when computing coercion types
We need to take type alignment padding into account whe computing physical layouts. The layout must be compatible with the input layout, offsets are defined in terms of offsets within a packed struct which are computed in terms of the alloc size of a type. Usingthe store size we would insert padding for the following type for example: struct { int3 v; long long l; } __attribute((packed)) On x86-64 int3 is padded to int4 alignment. The swiftcc type would be <{ <3 x float>, [4 x i8], i64 }> which is not compatible with <{ <3 x float>, i64 }>. The latter has i64 at offset 16 and the former at offset 20. rdar://32618125 Modified: cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp cfe/trunk/test/CodeGen/64bit-swiftcall.c Modified: cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp?rev=305956&r1=305955&r2=305956&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp (original) +++ cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp Wed Jun 21 16:43:40 2017 @@ -57,6 +57,10 @@ static CharUnits getTypeStoreSize(CodeGe return CharUnits::fromQuantity(CGM.getDataLayout().getTypeStoreSize(type)); } +static CharUnits getTypeAllocSize(CodeGenModule &CGM, llvm::Type *type) { + return CharUnits::fromQuantity(CGM.getDataLayout().getTypeAllocSize(type)); +} + void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) { // Deal with various aggregate types as special cases: @@ -542,7 +546,9 @@ SwiftAggLowering::getCoerceAndExpandType packed = true; elts.push_back(entry.Type); - lastEnd = entry.End; + + lastEnd = entry.Begin + getTypeAllocSize(CGM, entry.Type); + assert(entry.End <= lastEnd); } // We don't need to adjust 'packed' to deal with possible tail padding Modified: cfe/trunk/test/CodeGen/64bit-swiftcall.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/64bit-swiftcall.c?rev=305956&r1=305955&r2=305956&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/64bit-swiftcall.c (original) +++ cfe/trunk/test/CodeGen/64bit-swiftcall.c Wed Jun 21 16:43:40 2017 @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=X86-64 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM64 @@ -1014,3 +1015,20 @@ typedef struct { TEST(struct_v1f3) // ARM64-LABEL: define swiftcc { <2 x float>, float } @return_struct_v1f3() // ARM64-LABEL: define swiftcc void @take_struct_v1f3(<2 x float>, float) + +typedef struct { + int3 vect; + unsigned long long val; +} __attribute__((packed)) padded_alloc_size_vector; +TEST(padded_alloc_size_vector) +// X86-64-LABEL: take_padded_alloc_size_vector(<3 x i32>, i64) +// X86-64-NOT: [4 x i8] +// x86-64: ret void + +typedef union { + float f1; + float3 fv2; +} union_hom_fp_partial2; +TEST(union_hom_fp_partial2) +// X86-64-LABEL: take_union_hom_fp_partial2(i64, float) +// ARM64-LABEL: take_union_hom_fp_partial2(i64, float) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits