[PATCH] D52352: llvm-diff: Fix crash on anonymous functions

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 21 05:10:23 PDT 2018


arsenm created this revision.
arsenm added a reviewer: rjmccall.
Herald added a subscriber: wdng.

Not sure what the correct behavior is for this.
Skip them and report how many there were.


https://reviews.llvm.org/D52352

Files:
  test/tools/llvm-diff/anon-func.ll
  tools/llvm-diff/DifferenceEngine.cpp


Index: tools/llvm-diff/DifferenceEngine.cpp
===================================================================
--- tools/llvm-diff/DifferenceEngine.cpp
+++ tools/llvm-diff/DifferenceEngine.cpp
@@ -686,9 +686,18 @@
   StringSet<> LNames;
   SmallVector<std::pair<Function*,Function*>, 20> Queue;
 
+  unsigned LeftAnonCount = 0;
+  unsigned RightAnonCount = 0;
+
   for (Module::iterator I = L->begin(), E = L->end(); I != E; ++I) {
     Function *LFn = &*I;
-    LNames.insert(LFn->getName());
+    StringRef Name = LFn->getName();
+    if (Name.empty()) {
+      ++LeftAnonCount;
+      continue;
+    }
+
+    LNames.insert(Name);
 
     if (Function *RFn = R->getFunction(LFn->getName()))
       Queue.push_back(std::make_pair(LFn, RFn));
@@ -698,10 +707,25 @@
 
   for (Module::iterator I = R->begin(), E = R->end(); I != E; ++I) {
     Function *RFn = &*I;
-    if (!LNames.count(RFn->getName()))
+    StringRef Name = RFn->getName();
+    if (Name.empty()) {
+      ++RightAnonCount;
+      continue;
+    }
+
+    if (!LNames.count(Name))
       logf("function %r exists only in right module") << RFn;
   }
 
+
+  if (LeftAnonCount != 0 || RightAnonCount != 0) {
+    SmallString<32> Tmp;
+    Twine Message = "not comparing " + Twine(LeftAnonCount) +
+      " anonymous functions in the left module and " + Twine(RightAnonCount) +
+      " in the right module";
+    logf(Message.toStringRef(Tmp));
+  }
+
   for (SmallVectorImpl<std::pair<Function*,Function*> >::iterator
          I = Queue.begin(), E = Queue.end(); I != E; ++I)
     diff(I->first, I->second);
Index: test/tools/llvm-diff/anon-func.ll
===================================================================
--- /dev/null
+++ test/tools/llvm-diff/anon-func.ll
@@ -0,0 +1,8 @@
+; RUN: llvm-diff %s %s 2>&1 | FileCheck %s
+
+; CHECK: not comparing 1 anonymous functions in the left module and 1 in the right module
+
+define void @0() {
+  ret void
+}
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52352.166455.patch
Type: text/x-patch
Size: 1926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180921/bbca4061/attachment.bin>


More information about the llvm-commits mailing list