]> granicus.if.org Git - clang/commitdiff
MS ABI: Just use getTypeInfoInChars to get the field size
authorReid Kleckner <reid@kleckner.net>
Tue, 25 Feb 2014 18:08:48 +0000 (18:08 +0000)
committerReid Kleckner <reid@kleckner.net>
Tue, 25 Feb 2014 18:08:48 +0000 (18:08 +0000)
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
test/Layout/ms-x86-basic-layout.cpp

index 731f197fe083408410db88a9e8a375c7d7d61a83..d27255ecc8ded6eafc2ca82767493237a4cdba0f 100644 (file)
@@ -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<RecordType>()) {
     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<ConstantArrayType>(FD->getType()); CAT; 
-         CAT = dyn_cast<ConstantArrayType>(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.
index c522de84b288ca84cc31625991b2a245ce66cb79..c7501a6cbb2e5e8594411940830c9c4345669f4b 100644 (file)
@@ -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];