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

DeLesley Hutchins delesley at google.com
Fri Aug 31 15:09:54 PDT 2012


Author: delesley
Date: Fri Aug 31 17:09:53 2012
New Revision: 163028

URL: http://llvm.org/viewvc/llvm-project?rev=163028&view=rev
Log:
Thread-safety analysis: fix handling of LOCK_RETURNED attribute so that the
latest definition of a function is always used when computing lock expressions.

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=163028&r1=163027&r2=163028&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Fri Aug 31 17:09:53 2012
@@ -300,8 +300,9 @@
     } else if (CXXMemberCallExpr *CMCE = dyn_cast<CXXMemberCallExpr>(Exp)) {
       // When calling a function with a lock_returned attribute, replace
       // the function call with the expression in lock_returned.
-      if (LockReturnedAttr* At =
-            CMCE->getMethodDecl()->getAttr<LockReturnedAttr>()) {
+      CXXMethodDecl* MD =
+        cast<CXXMethodDecl>(CMCE->getMethodDecl()->getMostRecentDecl());
+      if (LockReturnedAttr* At = MD->getAttr<LockReturnedAttr>()) {
         CallingContext LRCallCtx(CMCE->getMethodDecl());
         LRCallCtx.SelfArg = CMCE->getImplicitObjectArgument();
         LRCallCtx.SelfArrow =
@@ -330,8 +331,9 @@
       NodeVec[Root].setSize(Sz + 1);
       return Sz + 1;
     } else if (CallExpr *CE = dyn_cast<CallExpr>(Exp)) {
-      if (LockReturnedAttr* At =
-            CE->getDirectCallee()->getAttr<LockReturnedAttr>()) {
+      FunctionDecl* FD =
+        cast<FunctionDecl>(CE->getDirectCallee()->getMostRecentDecl());
+      if (LockReturnedAttr* At = FD->getAttr<LockReturnedAttr>()) {
         CallingContext LRCallCtx(CE->getDirectCallee());
         LRCallCtx.NumArgs = CE->getNumArgs();
         LRCallCtx.FunArgs = CE->getArgs();

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=163028&r1=163027&r2=163028&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Fri Aug 31 17:09:53 2012
@@ -3145,3 +3145,48 @@
 } // end namespace StringIgnoreTest
 
 
+namespace LockReturnedScopeFix {
+
+class Base {
+protected:
+  struct Inner;
+  bool c;
+
+  const Mutex& getLock(const Inner* i);
+
+  void lockInner  (Inner* i) EXCLUSIVE_LOCK_FUNCTION(getLock(i));
+  void unlockInner(Inner* i) UNLOCK_FUNCTION(getLock(i));
+  void foo(Inner* i) EXCLUSIVE_LOCKS_REQUIRED(getLock(i));
+
+  void bar(Inner* i);
+};
+
+
+struct Base::Inner {
+  Mutex lock_;
+  void doSomething() EXCLUSIVE_LOCKS_REQUIRED(lock_);
+};
+
+
+const Mutex& Base::getLock(const Inner* i) LOCK_RETURNED(i->lock_) {
+  return i->lock_;
+}
+
+
+void Base::foo(Inner* i) {
+  i->doSomething();
+}
+
+void Base::bar(Inner* i) {
+  if (c) {
+    i->lock_.Lock();
+    unlockInner(i);
+  }
+  else {
+    lockInner(i);
+    i->lock_.Unlock();
+  }
+}
+
+} // end namespace LockReturnedScopeFix
+





More information about the cfe-commits mailing list