Support for thread safety attributes on functions

llvm-svn: 147331
This commit is contained in:
DeLesley Hutchins 2011-12-29 00:56:48 +00:00
parent f97c521368
commit 714296cb31
2 changed files with 27 additions and 2 deletions

View File

@ -147,6 +147,9 @@ class MutexID {
Parent = CE->getImplicitObjectArgument();
NumArgs = CE->getNumArgs();
FunArgs = CE->getArgs();
} else if (CallExpr *CE = dyn_cast<CallExpr>(DeclExp)) {
NumArgs = CE->getNumArgs();
FunArgs = CE->getArgs();
} else if (CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(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<NamedDecl>(Exp->getCalleeDecl());
if(!D || !D->hasAttrs())
return;

View File

@ -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