r202457 - -fdump-record-layouts: Sort nvbases by offset before printing them
Reid Kleckner
reid at kleckner.net
Thu Feb 27 17:03:10 PST 2014
Author: rnk
Date: Thu Feb 27 19:03:09 2014
New Revision: 202457
URL: http://llvm.org/viewvc/llvm-project?rev=202457&view=rev
Log:
-fdump-record-layouts: Sort nvbases by offset before printing them
It makes our -fdump-record-layouts a little more sane.
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/test/Layout/ms-x86-primary-bases.cpp
cfe/trunk/test/Layout/ms-x86-vfvb-alignment.cpp
cfe/trunk/test/Sema/ms_class_layout.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=202457&r1=202456&r2=202457&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Thu Feb 27 19:03:09 2014
@@ -3102,19 +3102,34 @@ static void DumpCXXRecordLayout(raw_ostr
OS << '(' << *RD << " vftable pointer)\n";
}
- // Dump (non-virtual) bases
+ // Collect nvbases.
+ SmallVector<const CXXRecordDecl *, 4> Bases;
for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
- E = RD->bases_end(); I != E; ++I) {
+ E = RD->bases_end();
+ I != E; ++I) {
assert(!I->getType()->isDependentType() &&
"Cannot layout class with dependent bases.");
- if (I->isVirtual())
- continue;
+ if (!I->isVirtual())
+ Bases.push_back(I->getType()->getAsCXXRecordDecl());
+ }
- const CXXRecordDecl *Base =
- cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
+ // Sort nvbases by offset.
+ struct BaseOffsetComparator {
+ const ASTRecordLayout &RL;
+ BaseOffsetComparator(const ASTRecordLayout &RL) : RL(RL) {}
+ bool operator()(const CXXRecordDecl *L, const CXXRecordDecl *R) const {
+ return RL.getBaseClassOffset(L) < RL.getBaseClassOffset(R);
+ }
+ };
+ BaseOffsetComparator Cmp(Layout);
+ std::stable_sort(Bases.begin(), Bases.end(), Cmp);
+ // Dump (non-virtual) bases
+ for (SmallVectorImpl<const CXXRecordDecl *>::iterator I = Bases.begin(),
+ E = Bases.end();
+ I != E; ++I) {
+ const CXXRecordDecl *Base = *I;
CharUnits BaseOffset = Offset + Layout.getBaseClassOffset(Base);
-
DumpCXXRecordLayout(OS, Base, C, BaseOffset, IndentLevel,
Base == PrimaryBase ? "(primary base)" : "(base)",
/*IncludeVirtualBases=*/false);
Modified: cfe/trunk/test/Layout/ms-x86-primary-bases.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Layout/ms-x86-primary-bases.cpp?rev=202457&r1=202456&r2=202457&view=diff
==============================================================================
--- cfe/trunk/test/Layout/ms-x86-primary-bases.cpp (original)
+++ cfe/trunk/test/Layout/ms-x86-primary-bases.cpp Thu Feb 27 19:03:09 2014
@@ -170,11 +170,11 @@ struct AX : B0X, B1X { int a; AX() : a(0
// CHECK: *** Dumping AST Record Layout
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct AX
-// CHECK-NEXT: 8 | struct B0X (base)
-// CHECK-NEXT: 8 | int a
// CHECK-NEXT: 0 | struct B1X (primary base)
// CHECK-NEXT: 0 | (B1X vftable pointer)
// CHECK-NEXT: 4 | int a
+// CHECK-NEXT: 8 | struct B0X (base)
+// CHECK-NEXT: 8 | int a
// CHECK-NEXT: 12 | int a
// CHECK-NEXT: | [sizeof=16, align=4
// CHECK-NEXT: | nvsize=16, nvalign=4]
@@ -182,11 +182,11 @@ struct AX : B0X, B1X { int a; AX() : a(0
// CHECK-X64: *** Dumping AST Record Layout
// CHECK-X64: *** Dumping AST Record Layout
// CHECK-X64-NEXT: 0 | struct AX
-// CHECK-X64-NEXT: 16 | struct B0X (base)
-// CHECK-X64-NEXT: 16 | int a
// CHECK-X64-NEXT: 0 | struct B1X (primary base)
// CHECK-X64-NEXT: 0 | (B1X vftable pointer)
// CHECK-X64-NEXT: 8 | int a
+// CHECK-X64-NEXT: 16 | struct B0X (base)
+// CHECK-X64-NEXT: 16 | int a
// CHECK-X64-NEXT: 20 | int a
// CHECK-X64-NEXT: | [sizeof=24, align=8
// CHECK-X64-NEXT: | nvsize=24, nvalign=8]
@@ -195,21 +195,21 @@ struct BX : B0X, B1X { int a; BX() : a(0
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct BX
-// CHECK-NEXT: 8 | struct B0X (base)
-// CHECK-NEXT: 8 | int a
// CHECK-NEXT: 0 | struct B1X (primary base)
// CHECK-NEXT: 0 | (B1X vftable pointer)
// CHECK-NEXT: 4 | int a
+// CHECK-NEXT: 8 | struct B0X (base)
+// CHECK-NEXT: 8 | int a
// CHECK-NEXT: 12 | int a
// CHECK-NEXT: | [sizeof=16, align=4
// CHECK-NEXT: | nvsize=16, nvalign=4]
// CHECK-X64: *** Dumping AST Record Layout
// CHECK-X64-NEXT: 0 | struct BX
-// CHECK-X64-NEXT: 16 | struct B0X (base)
-// CHECK-X64-NEXT: 16 | int a
// CHECK-X64-NEXT: 0 | struct B1X (primary base)
// CHECK-X64-NEXT: 0 | (B1X vftable pointer)
// CHECK-X64-NEXT: 8 | int a
+// CHECK-X64-NEXT: 16 | struct B0X (base)
+// CHECK-X64-NEXT: 16 | int a
// CHECK-X64-NEXT: 20 | int a
// CHECK-X64-NEXT: | [sizeof=24, align=8
// CHECK-X64-NEXT: | nvsize=24, nvalign=8]
Modified: cfe/trunk/test/Layout/ms-x86-vfvb-alignment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Layout/ms-x86-vfvb-alignment.cpp?rev=202457&r1=202456&r2=202457&view=diff
==============================================================================
--- cfe/trunk/test/Layout/ms-x86-vfvb-alignment.cpp (original)
+++ cfe/trunk/test/Layout/ms-x86-vfvb-alignment.cpp Thu Feb 27 19:03:09 2014
@@ -200,12 +200,12 @@ struct G : B2, B6, virtual B1 { int a; G
// CHECK: *** Dumping AST Record Layout
// CHECK: *** Dumping AST Record Layout
// CHECK-NEXT: 0 | struct G
-// CHECK-NEXT: 8 | struct B2 (base)
-// CHECK-NEXT: 8 | (B2 vbtable pointer)
-// CHECK-NEXT: 12 | int a
// CHECK-NEXT: 0 | struct B6 (primary base)
// CHECK-NEXT: 0 | (B6 vftable pointer)
// CHECK-NEXT: 4 | int a
+// CHECK-NEXT: 8 | struct B2 (base)
+// CHECK-NEXT: 8 | (B2 vbtable pointer)
+// CHECK-NEXT: 12 | int a
// CHECK-NEXT: 16 | int a
// CHECK-NEXT: 20 | struct B1 (virtual base)
// CHECK-NEXT: 20 | char a
@@ -214,12 +214,12 @@ struct G : B2, B6, virtual B1 { int a; G
// CHECK-X64: *** Dumping AST Record Layout
// CHECK-X64: *** Dumping AST Record Layout
// CHECK-X64-NEXT: 0 | struct G
-// CHECK-X64-NEXT: 16 | struct B2 (base)
-// CHECK-X64-NEXT: 16 | (B2 vbtable pointer)
-// CHECK-X64-NEXT: 24 | int a
// CHECK-X64-NEXT: 0 | struct B6 (primary base)
// CHECK-X64-NEXT: 0 | (B6 vftable pointer)
// CHECK-X64-NEXT: 8 | int a
+// CHECK-X64-NEXT: 16 | struct B2 (base)
+// CHECK-X64-NEXT: 16 | (B2 vbtable pointer)
+// CHECK-X64-NEXT: 24 | int a
// CHECK-X64-NEXT: 32 | int a
// CHECK-X64-NEXT: 40 | struct B1 (virtual base)
// CHECK-X64-NEXT: 40 | char a
Modified: cfe/trunk/test/Sema/ms_class_layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ms_class_layout.cpp?rev=202457&r1=202456&r2=202457&view=diff
==============================================================================
--- cfe/trunk/test/Sema/ms_class_layout.cpp (original)
+++ cfe/trunk/test/Sema/ms_class_layout.cpp Thu Feb 27 19:03:09 2014
@@ -470,12 +470,12 @@ int main() {
// CHECK: %struct.DV = type { %struct.BV }
// CHECK: 0 | struct EV
-// CHECK-NEXT: 4 | struct CV (base)
-// CHECK-NEXT: 4 | (CV vbtable pointer)
// CHECK-NEXT: 0 | struct DV (primary base)
// CHECK-NEXT: 0 | struct BV (primary base)
// CHECK-NEXT: 0 | struct AV (primary base)
// CHECK-NEXT: 0 | (AV vftable pointer)
+// CHECK-NEXT: 4 | struct CV (base)
+// CHECK-NEXT: 4 | (CV vbtable pointer)
// CHECK-NEXT: 8 | (vtordisp for vbase BV)
// CHECK-NEXT: 12 | struct BV (virtual base)
// CHECK-NEXT: 12 | struct AV (primary base)
More information about the cfe-commits
mailing list