AST: Dump ASTRecordLayout objects when they are created with -fdump-record-layouts.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101815 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index a3c08d5..96e2e75 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -998,6 +998,11 @@
     ASTRecordLayoutBuilder::ComputeLayout(*this, D);
   ASTRecordLayouts[D] = NewEntry;
 
+  if (getLangOptions().DumpRecordLayouts) {
+    llvm::errs() << "\n*** Dumping AST Record Layout\n";
+    DumpRecordLayout(D, llvm::errs());
+  }
+
   return *NewEntry;
 }
 
diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp
index 3038d91..3782985 100644
--- a/lib/AST/RecordLayoutBuilder.cpp
+++ b/lib/AST/RecordLayoutBuilder.cpp
@@ -860,7 +860,7 @@
 ASTRecordLayoutBuilder::ComputeKeyFunction(const CXXRecordDecl *RD) {
   assert(RD->isDynamicClass() && "Class does not have any virtual methods!");
 
-  // If a class isnt' polymorphic it doesn't have a key function.
+  // If a class isn't polymorphic it doesn't have a key function.
   if (!RD->isPolymorphic())
     return 0;
 
@@ -983,17 +983,6 @@
                         "(primary virtual base)" : "(virtual base)",
                         /*IncludeVirtualBases=*/false);
   }
-}
-
-void ASTContext::DumpRecordLayout(const RecordDecl *RD,
-                                  llvm::raw_ostream &OS) {
-  const ASTRecordLayout &Info = getASTRecordLayout(RD);
-
-  if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
-    DumpCXXRecordLayout(OS, CXXRD, *this, 0, 0, 0,
-                        /*IncludeVirtualBases=*/true);
-  else
-    OS << getTypeDeclType(RD).getAsString();
 
   OS << "  sizeof=" << Info.getSize() / 8;
   OS << ", dsize=" << Info.getDataSize() / 8;
@@ -1002,3 +991,27 @@
   OS << ", nvalign=" << Info.getNonVirtualAlign() / 8 << '\n';
   OS << '\n';
 }
+
+void ASTContext::DumpRecordLayout(const RecordDecl *RD,
+                                  llvm::raw_ostream &OS) {
+  const ASTRecordLayout &Info = getASTRecordLayout(RD);
+
+  if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
+    return DumpCXXRecordLayout(OS, CXXRD, *this, 0, 0, 0,
+                               /*IncludeVirtualBases=*/true);
+
+  OS << "Type: " << getTypeDeclType(RD).getAsString() << "\n";
+  OS << "Record: ";
+  RD->dump();
+  OS << "\nLayout: ";
+  OS << "<ASTRecordLayout\n";
+  OS << "  Size:" << Info.getSize() << "\n";
+  OS << "  DataSize:" << Info.getDataSize() << "\n";
+  OS << "  Alignment:" << Info.getAlignment() << "\n";
+  OS << "  FieldOffsets: [";
+  for (unsigned i = 0, e = Info.getFieldCount(); i != e; ++i) {
+    if (i) OS << ", ";
+    OS << Info.getFieldOffset(i);
+  }
+  OS << "]>\n";
+}
diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp
index f056314..7b7394a 100644
--- a/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -566,7 +566,7 @@
 
   // Dump the layout, if requested.
   if (getContext().getLangOptions().DumpRecordLayouts) {
-    llvm::errs() << "\n*** Dumping Record Layout\n";
+    llvm::errs() << "\n*** Dumping IRgen Record Layout\n";
     llvm::errs() << "Record: ";
     D->dump();
     llvm::errs() << "\nLayout: ";