Fixed bug where ternary expressions and GCC-style conditional expressions 
where not reversing the order of their subexpression blocks.

Added feature where CallExprs are placed in their own statement slot in
a CFGBlock.  Thus we have a designated "return site" within a CFGBlock when
reasoning about function calls.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41866 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/CFG.cpp b/AST/CFG.cpp
index 93ee6f4..c1f96ce 100644
--- a/AST/CFG.cpp
+++ b/AST/CFG.cpp
@@ -116,6 +116,7 @@
   CFGBlock* WalkAST_VisitChildren(Stmt* S);
   CFGBlock* WalkAST_VisitVarDecl(VarDecl* D);
   CFGBlock* WalkAST_VisitStmtExpr(StmtExpr* S);
+  CFGBlock* WalkAST_VisitCallExpr(CallExpr* C);
   void FinishBlock(CFGBlock* B);
   
 };
@@ -231,10 +232,12 @@
       Succ = ConfluenceBlock;
       Block = NULL;
       CFGBlock* LHSBlock = Visit(C->getLHS());
+      FinishBlock(LHSBlock);
       
       Succ = ConfluenceBlock;
       Block = NULL;
       CFGBlock* RHSBlock = Visit(C->getRHS());
+      FinishBlock(RHSBlock);
       
       Block = createBlock(false);
       Block->addSuccessor(LHSBlock);
@@ -253,10 +256,12 @@
       Succ = ConfluenceBlock;
       Block = NULL;
       CFGBlock* LHSBlock = Visit(C->getLHS());
-      
+      FinishBlock(LHSBlock);
+
       Succ = ConfluenceBlock;
       Block = NULL;
       CFGBlock* RHSBlock = Visit(C->getRHS());
+      FinishBlock(RHSBlock);
       
       Block = createBlock(false);
       Block->addSuccessor(LHSBlock);
@@ -279,6 +284,9 @@
       if (AlwaysAddStmt) Block->appendStmt(S);
       return Block;
     }
+    
+    case Stmt::CallExprClass:
+      return WalkAST_VisitCallExpr(cast<CallExpr>(S));
       
     case Stmt::StmtExprClass:
       return WalkAST_VisitStmtExpr(cast<StmtExpr>(S));
@@ -358,6 +366,14 @@
   return VisitCompoundStmt(S->getSubStmt());  
 }
 
+/// WalkAST_VisitCallExpr - Utility method to handle function calls that
+///  are nested in expressions.  The idea is that each function call should
+///  appear as a distinct statement in the CFGBlock.
+CFGBlock* CFGBuilder::WalkAST_VisitCallExpr(CallExpr* C) {
+  Block->appendStmt(C);
+  return WalkAST_VisitChildren(C);
+}
+
 /// VisitStmt - Handle statements with no branching control flow.
 CFGBlock* CFGBuilder::VisitStmt(Stmt* Statement) {
   // We cannot assume that we are in the middle of a basic block, since
@@ -458,6 +474,7 @@
   // newly created blocks will be pointed to be "Block".
   return addStmt(I->getCond());
 }
+  
     
 CFGBlock* CFGBuilder::VisitReturnStmt(ReturnStmt* R) {
   // If we were in the middle of a block we stop processing that block