r202175 - MS ABI: Just use getTypeInfoInChars to get the field size

Reid Kleckner reid at kleckner.net
Tue Feb 25 10:08:49 PST 2014


Author: rnk
Date: Tue Feb 25 12:08:48 2014
New Revision: 202175

URL: http://llvm.org/viewvc/llvm-project?rev=202175&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/test/Layout/ms-x86-basic-layout.cpp

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=202175&r1=202174&r2=202175&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Tue Feb 25 12:08:48 2014
@@ -2261,6 +2261,8 @@ MicrosoftRecordLayoutBuilder::ElementInf
 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::getAdjuste
       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.

Modified: cfe/trunk/test/Layout/ms-x86-basic-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Layout/ms-x86-basic-layout.cpp?rev=202175&r1=202174&r2=202175&view=diff
==============================================================================
--- cfe/trunk/test/Layout/ms-x86-basic-layout.cpp (original)
+++ cfe/trunk/test/Layout/ms-x86-basic-layout.cpp Tue Feb 25 12:08:48 2014
@@ -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];





More information about the cfe-commits mailing list