]> granicus.if.org Git - clang/commitdiff
Make -fdump-vtable-layouts also dump vtable indices for all virtual member functions...
authorAnders Carlsson <andersca@mac.com>
Sun, 10 Apr 2011 17:42:45 +0000 (17:42 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 10 Apr 2011 17:42:45 +0000 (17:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129250 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGVTables.cpp

index 72376efcc2ab4b868c2b54f205cf46ecc13eee2b..bc97b7463e8da7818f7c96061e2a66defd49f974 100644 (file)
@@ -2254,9 +2254,51 @@ void VTableBuilder::dumpLayout(llvm::raw_ostream& Out) {
       }
       
       Out << '\n';
+    }
+  }
+
+  // Compute the vtable indices for all the member functions.
+  // Store them in a map keyed by the index so we'll get a sorted table.
+  std::map<uint64_t, std::string> IndicesMap;
+
+  for (CXXRecordDecl::method_iterator i = MostDerivedClass->method_begin(),
+       e = MostDerivedClass->method_end(); i != e; ++i) {
+    const CXXMethodDecl *MD = *i;
+    
+    // We only want virtual member functions.
+    if (!MD->isVirtual())
+      continue;
 
+    std::string MethodName =
+      PredefinedExpr::ComputeName(PredefinedExpr::PrettyFunctionNoVirtual,
+                                  MD);
+
+    if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
+      IndicesMap[VTables.getMethodVTableIndex(GlobalDecl(DD, Dtor_Complete))] =
+        MethodName + " [complete]";
+      IndicesMap[VTables.getMethodVTableIndex(GlobalDecl(DD, Dtor_Deleting))] =
+        MethodName + " [deleting]";
+    } else {
+      IndicesMap[VTables.getMethodVTableIndex(MD)] = MethodName;
     }
   }
+
+  // Print the vtable indices for all the member functions.
+  if (!IndicesMap.empty()) {
+    Out << "VTable indices for '";
+    Out << MostDerivedClass->getQualifiedNameAsString();
+    Out << "' (" << IndicesMap.size() << " entries).\n";
+
+    for (std::map<uint64_t, std::string>::const_iterator I = IndicesMap.begin(),
+         E = IndicesMap.end(); I != E; ++I) {
+      uint64_t VTableIndex = I->first;
+      const std::string &MethodName = I->second;
+
+      Out << llvm::format(" %4u | ", VTableIndex) << MethodName << '\n';
+    }
+  }
+
+  Out << '\n';
 }
   
 }