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);
// 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]
// 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]
// 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]
// 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
// 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
// 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)