diff options
| author | DeLesley Hutchins <delesley@google.com> | 2014-04-07 22:56:24 +0000 |
|---|---|---|
| committer | DeLesley Hutchins <delesley@google.com> | 2014-04-07 22:56:24 +0000 |
| commit | d5fbd22d2670f84aea233c976c9e46fd3ca7488c (patch) | |
| tree | 32d3f4f86fbaacd164f31f217f6ed008c1dde5a0 /lib/Analysis/ThreadSafetyCommon.cpp | |
| parent | 7aff1941dc5798e56b76a40eb3589632e7c22230 (diff) | |
| download | clang-d5fbd22d2670f84aea233c976c9e46fd3ca7488c.tar.gz clang-d5fbd22d2670f84aea233c976c9e46fd3ca7488c.tar.bz2 clang-d5fbd22d2670f84aea233c976c9e46fd3ca7488c.tar.xz | |
Thread Safety Analysis: various fixes to new SExpr code.
Implemented ownership policy, updated to use nullptr, const-cleanup.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205745 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ThreadSafetyCommon.cpp')
| -rw-r--r-- | lib/Analysis/ThreadSafetyCommon.cpp | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/lib/Analysis/ThreadSafetyCommon.cpp b/lib/Analysis/ThreadSafetyCommon.cpp index cd416e57c9..7b9c91d351 100644 --- a/lib/Analysis/ThreadSafetyCommon.cpp +++ b/lib/Analysis/ThreadSafetyCommon.cpp @@ -312,26 +312,29 @@ til::SExpr *SExprBuilder::translateBinaryConditionalOperator( // Build a complete SCFG from a clang CFG. class SCFGBuilder : public CFGVisitor { public: - // return true if E should be included in the SCFG - bool includeExpr(til::SExpr* E) { + til::Variable *addStatement(til::SExpr* E, const Stmt *S) { if (!E) - return false; - if (E->opcode() == til::COP_Variable) - return false; - if (E->opcode() == til::COP_LiteralPtr) - return false; - return true; + return 0; + if (til::ThreadSafetyTIL::isTrivial(E)) + return 0; + + til::Variable *V = new (Arena) til::Variable(til::Variable::VK_Let, E); + V->setID(CurrentBlockID, CurrentVarID++); + CurrentBB->addInstr(V); + if (S) + BuildEx.insertStmt(S, V); + return V; } // Enter the CFG for Decl D, and perform any initial setup operations. void enterCFG(CFG *Cfg, const NamedDecl *D, const CFGBlock *First) { - Scfg = new til::SCFG(Arena, Cfg->getNumBlockIDs()); + Scfg = new (Arena) til::SCFG(Arena, Cfg->getNumBlockIDs()); CallCtx = new SExprBuilder::CallingContext(D); } // Enter a CFGBlock. void enterCFGBlock(const CFGBlock *B) { - CurrentBB = new til::BasicBlock(Arena, 0, B->size()); + CurrentBB = new (Arena) til::BasicBlock(Arena, 0, B->size()); CurrentBB->setBlockID(CurrentBlockID); CurrentVarID = 0; Scfg->add(CurrentBB); @@ -340,16 +343,17 @@ public: // Process an ordinary statement. void handleStatement(const Stmt *S) { til::SExpr *E = BuildEx.translate(S, CallCtx); - if (includeExpr(E)) { - til::Variable *V = new til::Variable(til::Variable::VK_Let, E); - V->setID(CurrentBlockID, CurrentVarID++); - CurrentBB->addInstr(V); - BuildEx.insertStmt(S, V); - } + addStatement(E, S); } // Process a destructor call - void handleDestructorCall(const VarDecl *VD, const CXXDestructorDecl *DD) {} + void handleDestructorCall(const VarDecl *VD, const CXXDestructorDecl *DD) { + til::SExpr *Sf = new (Arena) til::LiteralPtr(VD); + til::SExpr *Dr = new (Arena) til::LiteralPtr(DD); + til::SExpr *Ap = new (Arena) til::Apply(Dr, Sf); + til::SExpr *E = new (Arena) til::Call(Ap, 0); + addStatement(E, nullptr); + } // Process a successor edge. void handleSuccessor(const CFGBlock *Succ) {} @@ -364,12 +368,21 @@ public: } // Leave the CFG, and perform any final cleanup operations. - void exitCFG(const CFGBlock *Last) {} + void exitCFG(const CFGBlock *Last) { + if (CallCtx) { + delete CallCtx; + CallCtx = nullptr; + } + } SCFGBuilder(til::MemRegionRef A) : Arena(A), Scfg(0), CurrentBB(0), CurrentBlockID(0), - BuildEx(A, new SExprBuilder::StatementMap()) + CallCtx(0), SMap(new SExprBuilder::StatementMap()), + BuildEx(A, SMap) { } + ~SCFGBuilder() { + delete SMap; + } til::SCFG *getCFG() const { return Scfg; } @@ -380,8 +393,9 @@ private: unsigned CurrentBlockID; unsigned CurrentVarID; - SExprBuilder BuildEx; SExprBuilder::CallingContext *CallCtx; + SExprBuilder::StatementMap *SMap; + SExprBuilder BuildEx; }; |
