[cfe-commits] r93962 - /cfe/trunk/lib/Analysis/CFG.cpp

Mike Stump mrs at apple.com
Tue Jan 19 17:15:35 PST 2010


Author: mrs
Date: Tue Jan 19 19:15:34 2010
New Revision: 93962

URL: http://llvm.org/viewvc/llvm-project?rev=93962&view=rev
Log:
Add an exceptional edge from the try terminated block to the outer EH
context (try or the Exit block) when there isn't a catch (...).

Improve CFG printing for catch (...).

Modified:
    cfe/trunk/lib/Analysis/CFG.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=93962&r1=93961&r2=93962&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Tue Jan 19 19:15:34 2010
@@ -1599,6 +1599,7 @@
   } else TrySuccessor = Succ;
 
   // Save the current "try" context.
+  CFGBlock *PrevTryTerminatedBlock = TryTerminatedBlock;
   SaveAndRestore<CFGBlock*> save_try(TryTerminatedBlock);
 
   // Create a new block that will contain the try statement.
@@ -1606,10 +1607,14 @@
   // Add the terminator in the try block.
   TryTerminatedBlock->setTerminator(Terminator);
 
+  bool HasCatchAll = false;
   for (unsigned h = 0; h <Terminator->getNumHandlers(); ++h) {
     // The code after the try is the implicit successor.
     Succ = TrySuccessor;
     CXXCatchStmt *CS = Terminator->getHandler(h);
+    if (CS->getExceptionDecl() == 0) {
+      HasCatchAll = true;
+    }
     Block = NULL;
     CFGBlock *CatchBlock = VisitCXXCatchStmt(CS);
     if (CatchBlock == 0)
@@ -1618,6 +1623,12 @@
     // statement.
     AddSuccessor(TryTerminatedBlock, CatchBlock);
   }
+  if (!HasCatchAll) {
+    if (PrevTryTerminatedBlock)
+      AddSuccessor(TryTerminatedBlock, PrevTryTerminatedBlock);
+    else
+      AddSuccessor(TryTerminatedBlock, &cfg->getExit());
+  }
 
   // The code after the try is the implicit successor.
   Succ = TrySuccessor;
@@ -2037,8 +2048,11 @@
       OS << "default";
     else if (CXXCatchStmt *CS = dyn_cast<CXXCatchStmt>(Label)) {
       OS << "catch (";
-      CS->getExceptionDecl()->print(OS, PrintingPolicy(Helper->getLangOpts()),
-        0);
+      if (CS->getExceptionDecl())
+        CS->getExceptionDecl()->print(OS, PrintingPolicy(Helper->getLangOpts()),
+                                      0);
+      else
+        OS << "...";
       OS << ")";
 
     } else





More information about the cfe-commits mailing list