[llvm] r310547 - [LCG] Fix an assert in a on-scope-exit lambda that checked the contents

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 20:05:21 PDT 2017


Author: chandlerc
Date: Wed Aug  9 20:05:21 2017
New Revision: 310547

URL: http://llvm.org/viewvc/llvm-project?rev=310547&view=rev
Log:
[LCG] Fix an assert in a on-scope-exit lambda that checked the contents
of the returned value.

Checking the returned value from inside of a scoped exit isn't actually
valid. It happens to work when NRVO fires and the stars align, which
they reliably do with Clang but don't, for example, on MSVC builds.

Modified:
    llvm/trunk/lib/Analysis/LazyCallGraph.cpp

Modified: llvm/trunk/lib/Analysis/LazyCallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyCallGraph.cpp?rev=310547&r1=310546&r2=310547&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyCallGraph.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyCallGraph.cpp Wed Aug  9 20:05:21 2017
@@ -1105,14 +1105,10 @@ LazyCallGraph::RefSCC::removeInternalRef
   // or we return new RefSCCs and this RefSCC is dead.
   verify();
   auto VerifyOnExit = make_scope_exit([&]() {
-    if (Result.empty()) {
+    // If we didn't replace our RefSCC with new ones, check that this one
+    // remains valid.
+    if (G)
       verify();
-    } else {
-      assert(!G && "A dead RefSCC should have its graph pointer nulled.");
-      assert(SCCs.empty() && "A dead RefSCC should have no SCCs in it.");
-      for (RefSCC *RC : Result)
-        RC->verify();
-    }
   });
 #endif
 
@@ -1325,6 +1321,12 @@ LazyCallGraph::RefSCC::removeInternalRef
   SCCs.clear();
   SCCIndices.clear();
 
+#ifndef NDEBUG
+  // Verify the new RefSCCs we've built.
+  for (RefSCC *RC : Result)
+    RC->verify();
+#endif
+
   // Return the new list of SCCs.
   return Result;
 }




More information about the llvm-commits mailing list