[cfe-commits] r41520 - /cfe/trunk/AST/CFG.cpp

Ted Kremenek kremenek at apple.com
Mon Aug 27 14:54:42 PDT 2007


Author: kremenek
Date: Mon Aug 27 16:54:41 2007
New Revision: 41520

URL: http://llvm.org/viewvc/llvm-project?rev=41520&view=rev
Log:
Added support for short-circuit '&&' and '||' operators in source-level CFGs.

Modified:
    cfe/trunk/AST/CFG.cpp

Modified: cfe/trunk/AST/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/CFG.cpp?rev=41520&r1=41519&r2=41520&view=diff

==============================================================================
--- cfe/trunk/AST/CFG.cpp (original)
+++ cfe/trunk/AST/CFG.cpp Mon Aug 27 16:54:41 2007
@@ -210,6 +210,37 @@
       Block->setTerminator(C);
       return addStmt(C->getCond());
     }
+    
+    case Stmt::ParenExprClass:
+      return WalkAST(cast<ParenExpr>(S)->getSubExpr(),AlwaysAddStmt);
+    
+    case Stmt::BinaryOperatorClass: {
+      BinaryOperator* B = cast<BinaryOperator>(S);
+
+      if (B->isLogicalOp()) { // && or ||
+        CFGBlock* ConfluenceBlock = (Block) ? Block : createBlock();  
+        ConfluenceBlock->appendStmt(B);
+        FinishBlock(ConfluenceBlock);
+
+        // create the block evaluating the LHS
+        CFGBlock* LHSBlock = createBlock(false);
+        LHSBlock->addSuccessor(ConfluenceBlock);
+        LHSBlock->setTerminator(B);        
+        
+        // create the block evaluating the RHS
+        Succ = ConfluenceBlock;
+        Block = NULL;
+        CFGBlock* RHSBlock = Visit(B->getRHS());
+        LHSBlock->addSuccessor(RHSBlock);
+        
+        // Generate the blocks for evaluating the LHS.
+        Block = LHSBlock;
+        return addStmt(B->getLHS());                                    
+      }    
+
+      // Fall through to the default case.
+    }
+    
     default:
       if (AlwaysAddStmt) Block->appendStmt(S);
       return WalkAST_VisitChildren(S);
@@ -218,8 +249,7 @@
 
 /// WalkAST_VisitChildren - Utility method to call WalkAST on the
 ///  children of a Stmt.
-CFGBlock* CFGBuilder::WalkAST_VisitChildren(Stmt* S)
-{
+CFGBlock* CFGBuilder::WalkAST_VisitChildren(Stmt* S) {
   CFGBlock* B = Block;
   for (Stmt::child_iterator I = S->child_begin(), E = S->child_end() ;
        I != E; ++I)
@@ -833,11 +863,10 @@
     OS << '\n';
   }
   
-  void VisitConditionalOperator(ConditionalOperator* C) {
-    C->printPretty(OS);
+  void VisitExpr(Expr* E) {
+    E->printPretty(OS);
     OS << '\n';
-  }
-                                                     
+  }                                                       
 };
 } // end anonymous namespace
 





More information about the cfe-commits mailing list