[llvm-pdbdump] Re-write the record layout code to be more resilient.

This reworks the way virtual bases are handled, and also the way
padding is detected across multiple levels of aggregates, producing
a much more accurate result.

llvm-svn: 301203
diff --git a/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp b/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp
index 9f213a4..81ef261 100644
--- a/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp
+++ b/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp
@@ -58,25 +58,11 @@
   prettyPrintClassOutro(Layout);
 }
 
-static void printBase(LinePrinter &Printer, const PDBSymbolTypeBaseClass &Base,
-                      uint32_t &CurIndex, uint32_t TotalBaseCount,
-                      bool IsVirtual) {
-  Printer << " ";
-  WithColor(Printer, PDB_ColorItem::Keyword).get() << Base.getAccess();
-  if (IsVirtual)
-    WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual";
-  WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base.getName();
-  if (++CurIndex < TotalBaseCount) {
-    Printer.NewLine();
-    Printer << ",";
-  }
-}
-
 void ClassDefinitionDumper::prettyPrintClassIntro(const ClassLayout &Layout) {
   DumpedAnything = false;
   Printer.NewLine();
 
-  uint32_t Size = Layout.getClassSize();
+  uint32_t Size = Layout.getSize();
   const PDBSymbolTypeUDT &Class = Layout.getClass();
 
   WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " ";
@@ -84,19 +70,22 @@
   WithColor(Printer, PDB_ColorItem::Comment).get() << " [sizeof = " << Size
                                                    << "]";
   uint32_t BaseCount = Layout.bases().size();
-  uint32_t VBaseCount = Layout.vbases().size();
-  uint32_t TotalBaseCount = BaseCount + VBaseCount;
-  if (TotalBaseCount > 0) {
+  if (BaseCount > 0) {
     Printer.Indent();
-    Printer.NewLine();
-    Printer << ":";
-    uint32_t BaseIndex = 0;
+    char NextSeparator = ':';
     for (auto BC : Layout.bases()) {
       const auto &Base = BC->getBase();
-      printBase(Printer, Base, BaseIndex, TotalBaseCount, false);
-    }
-    for (auto &BC : Layout.vbases()) {
-      printBase(Printer, *BC, BaseIndex, TotalBaseCount, true);
+      if (Base.isIndirectVirtualBaseClass())
+        continue;
+
+      Printer.NewLine();
+      Printer << NextSeparator << " ";
+      WithColor(Printer, PDB_ColorItem::Keyword).get() << Base.getAccess();
+      if (BC->isVirtualBase())
+        WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual";
+
+      WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base.getName();
+      NextSeparator = ',';
     }
 
     Printer.Unindent();
@@ -114,7 +103,7 @@
   Printer.NewLine();
   if (Layout.deepPaddingSize() > 0) {
     APFloat Pct(100.0 * (double)Layout.deepPaddingSize() /
-                (double)Layout.getClassSize());
+                (double)Layout.getSize());
     SmallString<8> PctStr;
     Pct.toString(PctStr, 4);
     WithColor(Printer, PDB_ColorItem::Padding).get()