summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeLesley Hutchins <delesley@google.com>2012-04-23 16:45:01 +0000
committerDeLesley Hutchins <delesley@google.com>2012-04-23 16:45:01 +0000
commit70b5e8eefc7ed340d12c7acd2b777c2bb319041e (patch)
tree74820f2e670ce041b2398fd6e20f027ceae55655
parent39f39ff4b7d0eead8580f8f27489240fcb2e444a (diff)
downloadbcm5719-llvm-70b5e8eefc7ed340d12c7acd2b777c2bb319041e.tar.gz
bcm5719-llvm-70b5e8eefc7ed340d12c7acd2b777c2bb319041e.zip
Thread-safety analysis: support new "pointer to member" syntax for
existentially quantified lock expressions. llvm-svn: 155357
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp14
-rw-r--r--clang/test/SemaCXX/warn-thread-safety-parsing.cpp15
2 files changed, 28 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 843d5a47316..27980bd541f 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -313,7 +313,11 @@ static void checkAttrArgsAreLockableObjs(Sema &S, Decl *D,
continue;
}
- if (isa<StringLiteral>(ArgExp)) {
+ if (StringLiteral *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
+ // Ignore empty strings without warnings
+ if (StrLit->getLength() == 0)
+ continue;
+
// We allow constant strings to be used as a placeholder for expressions
// that are not valid C++ syntax, but warn that they are ignored.
S.Diag(Attr.getLoc(), diag::warn_thread_attribute_ignored) <<
@@ -323,6 +327,14 @@ static void checkAttrArgsAreLockableObjs(Sema &S, Decl *D,
QualType ArgTy = ArgExp->getType();
+ // A pointer to member expression of the form &MyClass::mu is treated
+ // specially -- we need to look at the type of the member.
+ if (UnaryOperator *UOp = dyn_cast<UnaryOperator>(ArgExp))
+ if (UOp->getOpcode() == UO_AddrOf)
+ if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
+ if (DRE->getDecl()->isCXXInstanceMember())
+ ArgTy = DRE->getDecl()->getType();
+
// First see if we can just cast to record type, or point to record type.
const RecordType *RT = getRecordType(ArgTy);
diff --git a/clang/test/SemaCXX/warn-thread-safety-parsing.cpp b/clang/test/SemaCXX/warn-thread-safety-parsing.cpp
index a9e58dd8728..ac7737d4ac2 100644
--- a/clang/test/SemaCXX/warn-thread-safety-parsing.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-parsing.cpp
@@ -1341,5 +1341,20 @@ class Foo {
}
+namespace PointerToMemberTest {
+
+class Graph {
+public:
+ Mu mu_;
+};
+
+class Node {
+public:
+ void foo() EXCLUSIVE_LOCKS_REQUIRED(&Graph::mu_);
+ int a GUARDED_BY(&Graph::mu_);
+};
+
+}
+
} // end namespace TestMultiDecl
OpenPOWER on IntegriCloud