From ee8d6b96cec22857c609a0ff439e237a6c4fccc5 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 25 Feb 2014 18:08:48 +0000 Subject: [PATCH] MS ABI: Just use getTypeInfoInChars to get the field size This was changed to use manual desugaring and multiplication in r201832 and fixed for multi-dimensional arrays in r201917. However, it breaks down in the presence of typedefs. Rather than attempting to handle all the desugaring, just go back to calling the generic type info code. This was discovered while compiling SIInstrWaits.cpp in the R600 backend. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202175 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/RecordLayoutBuilder.cpp | 14 ++++---------- test/Layout/ms-x86-basic-layout.cpp | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index 731f197fe0..d27255ecc8 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -2261,6 +2261,8 @@ MicrosoftRecordLayoutBuilder::ElementInfo MicrosoftRecordLayoutBuilder::getAdjustedElementInfo( const FieldDecl *FD) { ElementInfo Info; + llvm::tie(Info.Size, Info.Alignment) = + Context.getTypeInfoInChars(FD->getType()); // Respect align attributes. CharUnits FieldRequiredAlignment = Context.toCharUnitsFromBits(FD->getMaxAlignment()); @@ -2269,19 +2271,11 @@ MicrosoftRecordLayoutBuilder::getAdjustedElementInfo( FD->getType()->getBaseElementTypeUnsafe()->getAs()) { const ASTRecordLayout &Layout = Context.getASTRecordLayout(RT->getDecl()); // Get the element info for a layout, respecting pack. - Info = getAdjustedElementInfo(Layout, false); - // If the field is an array type, scale it's size properly. - for (const ConstantArrayType *CAT = - dyn_cast(FD->getType()); CAT; - CAT = dyn_cast(CAT->getElementType())) - Info.Size = Info.Size * (int64_t)CAT->getSize().getZExtValue(); + Info.Alignment = getAdjustedElementInfo(Layout, false).Alignment; // Capture required alignment as a side-effect. RequiredAlignment = std::max(RequiredAlignment, Layout.getRequiredAlignment()); - } - else { - llvm::tie(Info.Size, Info.Alignment) = - Context.getTypeInfoInChars(FD->getType()); + } else { if (FD->isBitField() && FD->getMaxAlignment() != 0) Info.Alignment = std::max(Info.Alignment, FieldRequiredAlignment); // Respect pragma pack. diff --git a/test/Layout/ms-x86-basic-layout.cpp b/test/Layout/ms-x86-basic-layout.cpp index c522de84b2..c7501a6cbb 100644 --- a/test/Layout/ms-x86-basic-layout.cpp +++ b/test/Layout/ms-x86-basic-layout.cpp @@ -800,6 +800,22 @@ struct ArrayOfArrayFieldOfRecords { // CHECK-X64-NEXT: | [sizeof=16, align=4 // CHECK-X64-NEXT: | nvsize=16, nvalign=4] +struct RecordArrayTypedef { + typedef A4 ArrayTy[2]; + ArrayTy InlineElts[2]; +}; + +// CHECK: *** Dumping AST Record Layout +// CHECK-NEXT: 0 | struct RecordArrayTypedef +// CHECK-NEXT: 0 | ArrayTy [2] InlineElts +// CHECK-NEXT: | [sizeof=16, align=4 +// CHECK-NEXT: | nvsize=16, nvalign=4] +// CHECK-X64: *** Dumping AST Record Layout +// CHECK-X64-NEXT: 0 | struct RecordArrayTypedef +// CHECK-X64-NEXT: 0 | ArrayTy [2] InlineElts +// CHECK-X64-NEXT: | [sizeof=16, align=4 +// CHECK-X64-NEXT: | nvsize=16, nvalign=4] + int a[ sizeof(TestF0)+ sizeof(TestF1)+ @@ -823,4 +839,5 @@ sizeof(F5)+ sizeof(F6)+ sizeof(ArrayFieldOfRecords)+ sizeof(ArrayOfArrayFieldOfRecords)+ +sizeof(RecordArrayTypedef)+ 0]; -- 2.40.0