[llvm-commits] [llvm] r127975 - /llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp

Anders Carlsson andersca at mac.com
Sun Mar 20 13:16:44 PDT 2011


Author: andersca
Date: Sun Mar 20 15:16:43 2011
New Revision: 127975

URL: http://llvm.org/viewvc/llvm-project?rev=127975&view=rev
Log:
Don't segfault on mutual recursion, as pointed out by Frits.

Modified:
    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp

Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=127975&r1=127974&r2=127975&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Sun Mar 20 15:16:43 2011
@@ -2723,7 +2723,8 @@
 /// Note that we assume that other optimization passes have already simplified
 /// the code so we only look for a function with a single basic block, where
 /// the only allowed instructions are 'ret' or 'call' to empty C++ dtor.
-static bool cxxDtorIsEmpty(const Function& Fn) {
+static bool cxxDtorIsEmpty(const Function &Fn,
+                           SmallPtrSet<const Function *, 8> &CalledFunctions) {
   // FIXME: We could eliminate C++ destructors if they're readonly/readnone and
   // unwind, but that doesn't seem worth doing.
   if (Fn.isDeclaration())
@@ -2742,10 +2743,10 @@
         return false;
 
       // Don't treat recursive functions as empty.
-      if (CalledFn == &Fn)
+      if (!CalledFunctions.insert(CalledFn))
         return false;
 
-      if (!cxxDtorIsEmpty(*CalledFn))
+      if (!cxxDtorIsEmpty(*CalledFn, CalledFunctions))
         return false;
     } else if (isa<ReturnInst>(*I))
       return true;
@@ -2784,7 +2785,8 @@
     if (!DtorFn)
       continue;
 
-    if (!cxxDtorIsEmpty(*DtorFn))
+    SmallPtrSet<const Function *, 8> CalledFunctions;
+    if (!cxxDtorIsEmpty(*DtorFn, CalledFunctions))
       continue;
 
     // Just remove the call.





More information about the llvm-commits mailing list