From: DeLesley Hutchins Date: Sat, 8 Dec 2012 03:46:30 +0000 (+0000) Subject: Thread-safety analysis: check member access on guarded non-primitive types. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0cfa1a5a1d2be8345046943e33b57d74d816b969;p=platform%2Fupstream%2Fllvm.git Thread-safety analysis: check member access on guarded non-primitive types. llvm-svn: 169669 --- diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index fdfd599..9c33a8e 100644 --- a/clang/lib/Analysis/ThreadSafety.cpp +++ b/clang/lib/Analysis/ThreadSafety.cpp @@ -1858,6 +1858,15 @@ void BuildLockset::checkAccess(const Expr *Exp, AccessKind AK) { return; } + if (Analyzer->Handler.issueBetaWarnings()) { + if (const MemberExpr *ME = dyn_cast(Exp)) { + if (ME->isArrow()) + checkPtAccess(ME->getBase(), AK); + else + checkAccess(ME->getBase(), AK); + } + } + const ValueDecl *D = getValueDecl(Exp); 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 c8552f9..19e2aa1 100644 --- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp +++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp @@ -3818,6 +3818,67 @@ private: Data* datap2_ PT_GUARDED_BY(mu_); }; - } // end namespace GuardedNonPrimitiveTypeTest + +namespace GuardedNonPrimitive_MemberAccess { + +class Cell { +public: + Cell(int i); + + void cellMethod(); + + int a; +}; + + +class Foo { +public: + int a; + Cell c GUARDED_BY(cell_mu_); + Cell* cp PT_GUARDED_BY(cell_mu_); + + void myMethod(); + + Mutex cell_mu_; +}; + + +class Bar { +private: + Mutex mu_; + Foo foo GUARDED_BY(mu_); + Foo* foop PT_GUARDED_BY(mu_); + + void test() { + foo.myMethod(); // expected-warning {{reading variable 'foo' requires locking 'mu_'}} + + int fa = foo.a; // expected-warning {{reading variable 'foo' requires locking 'mu_'}} + foo.a = fa; // expected-warning {{writing variable 'foo' requires locking 'mu_' exclusively}} + + fa = foop->a; // expected-warning {{reading the value pointed to by 'foop' requires locking 'mu_'}} + foop->a = fa; // expected-warning {{writing the value pointed to by 'foop' requires locking 'mu_' exclusively}} + + fa = (*foop).a; // expected-warning {{reading the value pointed to by 'foop' requires locking 'mu_'}} + (*foop).a = fa; // expected-warning {{writing the value pointed to by 'foop' requires locking 'mu_' exclusively}} + + foo.c = Cell(0); // expected-warning {{writing variable 'foo' requires locking 'mu_'}} \ + // expected-warning {{writing variable 'c' requires locking 'foo.cell_mu_' exclusively}} + foo.c.cellMethod(); // expected-warning {{reading variable 'foo' requires locking 'mu_'}} \ + // expected-warning {{reading variable 'c' requires locking 'foo.cell_mu_'}} + + foop->c = Cell(0); // expected-warning {{writing the value pointed to by 'foop' requires locking 'mu_'}} \ + // expected-warning {{writing variable 'c' requires locking 'foop->cell_mu_' exclusively}} + foop->c.cellMethod(); // expected-warning {{reading the value pointed to by 'foop' requires locking 'mu_'}} \ + // expected-warning {{reading variable 'c' requires locking 'foop->cell_mu_'}} + + (*foop).c = Cell(0); // expected-warning {{writing the value pointed to by 'foop' requires locking 'mu_'}} \ + // expected-warning {{writing variable 'c' requires locking 'foop->cell_mu_' exclusively}} + (*foop).c.cellMethod(); // expected-warning {{reading the value pointed to by 'foop' requires locking 'mu_'}} \ + // expected-warning {{reading variable 'c' requires locking 'foop->cell_mu_'}} + }; +}; + +} // namespace GuardedNonPrimitive_MemberAccess +