From 714296cb3177329eb42411b85ef5a7fc9696efc7 Mon Sep 17 00:00:00 2001 From: DeLesley Hutchins Date: Thu, 29 Dec 2011 00:56:48 +0000 Subject: [PATCH] Support for thread safety attributes on functions llvm-svn: 147331 --- clang/lib/Analysis/ThreadSafety.cpp | 7 ++++-- .../SemaCXX/warn-thread-safety-analysis.cpp | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index 005d45545f1c..a1a8f5a606af 100644 --- a/clang/lib/Analysis/ThreadSafety.cpp +++ b/clang/lib/Analysis/ThreadSafety.cpp @@ -147,6 +147,9 @@ class MutexID { Parent = CE->getImplicitObjectArgument(); NumArgs = CE->getNumArgs(); FunArgs = CE->getArgs(); + } else if (CallExpr *CE = dyn_cast(DeclExp)) { + NumArgs = CE->getNumArgs(); + FunArgs = CE->getArgs(); } else if (CXXConstructExpr *CE = dyn_cast(DeclExp)) { Parent = 0; // FIXME -- get the parent from DeclStmt NumArgs = CE->getNumArgs(); @@ -350,7 +353,7 @@ public: void VisitUnaryOperator(UnaryOperator *UO); void VisitBinaryOperator(BinaryOperator *BO); void VisitCastExpr(CastExpr *CE); - void VisitCXXMemberCallExpr(CXXMemberCallExpr *Exp); + void VisitCallExpr(CallExpr *Exp); void VisitCXXConstructExpr(CXXConstructExpr *Exp); void VisitDeclStmt(DeclStmt *S); }; @@ -647,7 +650,7 @@ void BuildLockset::VisitCastExpr(CastExpr *CE) { } -void BuildLockset::VisitCXXMemberCallExpr(CXXMemberCallExpr *Exp) { +void BuildLockset::VisitCallExpr(CallExpr *Exp) { NamedDecl *D = dyn_cast_or_null(Exp->getCalleeDecl()); if(!D || !D->hasAttrs()) return; diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp index 23dcd8d4a8f7..8219b982bc71 100644 --- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp +++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp @@ -1605,3 +1605,25 @@ struct TestScopedLockable { } // end namespace test_scoped_lockable +namespace FunctionAttrTest { + +class Foo { +public: + Mutex mu_; + int a GUARDED_BY(mu_); +}; + +Foo fooObj; + +void foo() EXCLUSIVE_LOCKS_REQUIRED(fooObj.mu_); + +void bar() { + foo(); // expected-warning {{calling function 'foo' requires exclusive lock on 'mu_'}} + fooObj.mu_.Lock(); + foo(); + fooObj.mu_.Unlock(); +} + +}; // end namespace FunctionAttrTest + +