diff options
author | DeLesley Hutchins <delesley@google.com> | 2012-04-23 18:39:55 +0000 |
---|---|---|
committer | DeLesley Hutchins <delesley@google.com> | 2012-04-23 18:39:55 +0000 |
commit | e09be231fab855fc3b002dc9aeaa993dc292c3e3 (patch) | |
tree | f498ffcfdd5f9bbacb96a0b268f156e059cf7281 /clang/lib/Sema/SemaDeclAttr.cpp | |
parent | af0f8bf5959e6b36823519044ee39a75e0aaceb0 (diff) | |
download | bcm5719-llvm-e09be231fab855fc3b002dc9aeaa993dc292c3e3.tar.gz bcm5719-llvm-e09be231fab855fc3b002dc9aeaa993dc292c3e3.zip |
Thread safety analysis: support the use of pt_guarded_by attributes
on smart pointers. Also adds test case for previous commit.
llvm-svn: 155379
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 27980bd541f..59c4373190e 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -238,6 +238,24 @@ static bool isIntOrBool(Expr *Exp) { return QT->isBooleanType() || QT->isIntegerType(); } + +// Check to see if the type is a smart pointer of some kind. We assume +// it's a smart pointer if it defines both operator-> and operator*. +static bool threadSafetyCheckIsSmartPointer(Sema &S, const QualType QT) { + if (const RecordType *RT = QT->getAs<RecordType>()) { + DeclContextLookupConstResult Res1 = RT->getDecl()->lookup( + S.Context.DeclarationNames.getCXXOperatorName(OO_Star)); + if (Res1.first == Res1.second) + return false; + + DeclContextLookupConstResult Res2 = RT->getDecl()->lookup( + S.Context.DeclarationNames.getCXXOperatorName(OO_Arrow)); + if (Res2.first != Res2.second) + return true; + } + return false; +} + /// /// \brief Check if passed in Decl is a pointer type. /// Note that this function may produce an error message. @@ -249,6 +267,10 @@ static bool threadSafetyCheckIsPointer(Sema &S, const Decl *D, QualType QT = vd->getType(); if (QT->isAnyPointerType()) return true; + + if (threadSafetyCheckIsSmartPointer(S, QT)) + return true; + S.Diag(Attr.getLoc(), diag::warn_thread_attribute_decl_not_pointer) << Attr.getName()->getName() << QT; } else { |