[PATCH] D53986: [lto] Fix a crash caused by accessing an empty ValueInfo

Tom Roeder via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 1 10:45:59 PDT 2018


tmroeder created this revision.
tmroeder added a reviewer: pcc.
Herald added subscribers: arphaman, dexonsmith, inglorion, mehdi_amini.

ModuleSummaryIndex::exportToDot crashes when linking the Linux kernel under ThinLTO using LLVMgold.so. This appears to be due to the exportToDot function trying to get the GUID of an empty ValueInfo. This commit changes some functions internal to the ModuleSummaryIndex implementation to make them robust to cases where a GlobalValue::GUID does not map to a ValueInfo.

Unfortunately, I don't have a good test case for this, since I can currently only reproduce it when trying to build the Linux kernel. In particular, I don't know this LTO code well anymore, so I don't know if this is a symptom of a deeper problem.


Repository:
  rL LLVM

https://reviews.llvm.org/D53986

Files:
  lib/IR/ModuleSummaryIndex.cpp


Index: lib/IR/ModuleSummaryIndex.cpp
===================================================================
--- lib/IR/ModuleSummaryIndex.cpp
+++ lib/IR/ModuleSummaryIndex.cpp
@@ -198,9 +198,12 @@
          ", ffl: " + fflagsToString(FS->fflags());
 }
 
+static std::string getNodeVisualName(GlobalValue::GUID Id) {
+  return std::string("@") + std::to_string(Id);
+}
+
 static std::string getNodeVisualName(const ValueInfo &VI) {
-  return VI.name().empty() ? std::string("@") + std::to_string(VI.getGUID())
-                           : VI.name().str();
+  return VI.name().empty() ? getNodeVisualName(VI.getGUID()) : VI.name().str();
 }
 
 static std::string getNodeLabel(const ValueInfo &VI, GlobalValueSummary *GVS) {
@@ -221,9 +224,9 @@
 // specific module associated with it. Typically this is function
 // or variable defined in native object or library.
 static void defineExternalNode(raw_ostream &OS, const char *Pfx,
-                               const ValueInfo &VI) {
-  auto StrId = std::to_string(VI.getGUID());
-  OS << "  " << StrId << " [label=\"" << getNodeVisualName(VI)
+                               GlobalValue::GUID Id) {
+  auto StrId = std::to_string(Id);
+  OS << "  " << StrId << " [label=\"" << getNodeVisualName(Id)
      << "\"]; // defined externally\n";
 }
 
@@ -330,7 +333,7 @@
   for (auto &E : CrossModuleEdges) {
     auto &ModList = NodeMap[E.Dst];
     if (ModList.empty()) {
-      defineExternalNode(OS, "  ", getValueInfo(E.Dst));
+      defineExternalNode(OS, "  ", E.Dst);
       // Add fake module to the list to draw an edge to an external node
       // in the loop below.
       ModList.push_back(-1);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53986.172177.patch
Type: text/x-patch
Size: 1651 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181101/f5a10934/attachment.bin>


More information about the llvm-commits mailing list