This patch adds support for thread safety attributes on destructors. It does not yet handle the destruction of temporary objects.
http://codereview.appspot.com/5311048/ -DeLesley -- DeLesley Hutchins | Software Engineer | [email protected] | 505-206-0315
From 34bad1fba4319f4dd76cef1bf099ff7c9a0191e2 Mon Sep 17 00:00:00 2001 From: DeLesley Hutchins <[email protected]> Date: Wed, 19 Oct 2011 15:48:09 -0700 Subject: [PATCH] Added support for thread safety attributes on destructors. --- lib/Analysis/ThreadSafety.cpp | 27 +++++++++++++++++++++++++-- 1 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/Analysis/ThreadSafety.cpp b/lib/Analysis/ThreadSafety.cpp index b0cde9b..77994dd 100644 --- a/lib/Analysis/ThreadSafety.cpp +++ b/lib/Analysis/ThreadSafety.cpp @@ -224,6 +224,9 @@ class MutexID { Parent = 0; // FIXME -- is there a way to get the parent? NumArgs = CE->getNumArgs(); FunArgs = CE->getArgs(); + } else if (D && isa<CXXDestructorDecl>(D)) { + // There's no such thing as a "destructor call" in the AST. + Parent = DeclExp; } // If the attribute has no arguments, then assume the argument is "this". @@ -876,8 +879,28 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisContext &AC) { BuildLockset LocksetBuilder(Handler, Entryset, LocksetFactory); for (CFGBlock::const_iterator BI = CurrBlock->begin(), BE = CurrBlock->end(); BI != BE; ++BI) { - if (const CFGStmt *CfgStmt = dyn_cast<CFGStmt>(&*BI)) - LocksetBuilder.Visit(const_cast<Stmt*>(CfgStmt->getStmt())); + switch (BI->getKind()) { + case CFGElement::Statement: { + const CFGStmt *CS = cast<CFGStmt>(&*BI); + LocksetBuilder.Visit(const_cast<Stmt*>(CS->getStmt())); + break; + } + // Ignore BaseDtor, MemberDtor, and TemporaryDtor for now. + case CFGElement::AutomaticObjectDtor: { + const CFGAutomaticObjDtor *AD = cast<CFGAutomaticObjDtor>(&*BI); + VarDecl *VD = const_cast<VarDecl*>(AD->getVarDecl()); + CXXDestructorDecl *DD = const_cast<CXXDestructorDecl*>( + AD->getDestructorDecl(AC.getASTContext())); + + // Create a dummy expression, + DeclRefExpr DRE(VD, VD->getType(), VK_LValue, + AD->getTriggerStmt()->getLocEnd()); + LocksetBuilder.handleCall(&DRE, DD); + break; + } + default: + break; + } } Exitset = LocksetBuilder.getLockset(); -- 1.7.3.1
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
