From: Ted Kremenek Date: Tue, 11 Sep 2007 21:29:43 +0000 (+0000) Subject: Fixed bug where ternary expressions and GCC-style conditional expressions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f50ec1026d23282d94699f079ffb5edb9dfd951f;p=clang 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 93ee6f449d..c1f96ceed3 100644 --- a/AST/CFG.cpp +++ b/AST/CFG.cpp @@ -116,6 +116,7 @@ private: 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 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* S, bool AlwaysAddStmt = false) { 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 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* S, bool AlwaysAddStmt = false) { 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 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* S, bool AlwaysAddStmt = false) { if (AlwaysAddStmt) Block->appendStmt(S); return Block; } + + case Stmt::CallExprClass: + return WalkAST_VisitCallExpr(cast(S)); case Stmt::StmtExprClass: return WalkAST_VisitStmtExpr(cast(S)); @@ -358,6 +366,14 @@ CFGBlock* CFGBuilder::WalkAST_VisitStmtExpr(StmtExpr* S) { 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 @@ CFGBlock* CFGBuilder::VisitIfStmt(IfStmt* I) { // 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