aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDeclAttr.cpp
diff options
context:
space:
mode:
authorDeLesley Hutchins <delesley@google.com>2012-04-23 18:39:55 +0000
committerDeLesley Hutchins <delesley@google.com>2012-04-23 18:39:55 +0000
commitaed9ea398a3fd8d488120728e2df4ac81c3b0c4b (patch)
treedaa661927d5fd357fdee7facbbc66c0e62dc9d2e /lib/Sema/SemaDeclAttr.cpp
parent6603ff85d415c2aa72579f1a247012b75bfc2a19 (diff)
Thread safety analysis: support the use of pt_guarded_by attributes
on smart pointers. Also adds test case for previous commit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155379 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclAttr.cpp')
-rw-r--r--lib/Sema/SemaDeclAttr.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 27980bd541..59c4373190 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/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 {