[cfe-commits] r142685 - in /cfe/trunk: lib/Analysis/ThreadSafety.cpp test/SemaCXX/warn-thread-safety-analysis.cpp

DeLesley Hutchins delesley at google.com
Fri Oct 21 13:51:27 PDT 2011


Author: delesley
Date: Fri Oct 21 15:51:27 2011
New Revision: 142685

URL: http://llvm.org/viewvc/llvm-project?rev=142685&view=rev
Log:
Added support for thread safety attributes on destructors.

Modified:
    cfe/trunk/lib/Analysis/ThreadSafety.cpp
    cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=142685&r1=142684&r2=142685&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Fri Oct 21 15:51:27 2011
@@ -227,6 +227,9 @@
       Parent = 0;  // FIXME -- get the parent from DeclStmt
       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".
@@ -879,8 +882,30 @@
     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);
+          CXXDestructorDecl *DD = const_cast<CXXDestructorDecl*>(
+            AD->getDestructorDecl(AC.getASTContext()));
+          if (!DD->hasAttrs())
+            break;
+
+          // Create a dummy expression,
+          VarDecl *VD = const_cast<VarDecl*>(AD->getVarDecl());
+          DeclRefExpr DRE(VD, VD->getType(), VK_LValue,
+                          AD->getTriggerStmt()->getLocEnd());
+          LocksetBuilder.handleCall(&DRE, DD);
+          break;
+        }
+        default:
+          break;
+      }
     }
     Exitset = LocksetBuilder.getLockset();
 

Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=142685&r1=142684&r2=142685&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Fri Oct 21 15:51:27 2011
@@ -1487,9 +1487,7 @@
   };
 
   void fooTest() {
-    // destructors not implemented yet...
-    Foo foo; // \
-    // expected-warning {{mutex 'fooMu' is still locked at the end of function}}
+    Foo foo;
     myVar = 0;
   }
 }
@@ -1500,7 +1498,7 @@
 class LOCKABLE MyLockable {
 public:
   MyLockable() __attribute__((exclusive_lock_function)) { }
-  ~MyLockable() __attribute__((unlock_function)) { }
+  ~MyLockable() { }
 };
 
 // create an empty lock expression





More information about the cfe-commits mailing list