diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 56df48230cb7a8479bb7824d362e23eceddb9d9b..72a0ddbe77fce269b62d057845bbbf245f9d9805 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -379,28 +379,24 @@ static bool threadSafetyCheckIsSmartPointer(Sema &S, const RecordType* RT) { /// \return true if the Decl is a pointer type; false otherwise static bool threadSafetyCheckIsPointer(Sema &S, const Decl *D, const AttributeList &Attr) { - if (const ValueDecl *vd = dyn_cast<ValueDecl>(D)) { - QualType QT = vd->getType(); - if (QT->isAnyPointerType()) - return true; - - if (const RecordType *RT = QT->getAs<RecordType>()) { - // If it's an incomplete type, it could be a smart pointer; skip it. - // (We don't want to force template instantiation if we can avoid it, - // since that would alter the order in which templates are instantiated.) - if (RT->isIncompleteType()) - return true; + const ValueDecl *vd = cast<ValueDecl>(D); + QualType QT = vd->getType(); + if (QT->isAnyPointerType()) + return true; - if (threadSafetyCheckIsSmartPointer(S, RT)) - return true; - } + if (const RecordType *RT = QT->getAs<RecordType>()) { + // If it's an incomplete type, it could be a smart pointer; skip it. + // (We don't want to force template instantiation if we can avoid it, + // since that would alter the order in which templates are instantiated.) + if (RT->isIncompleteType()) + return true; - S.Diag(Attr.getLoc(), diag::warn_thread_attribute_decl_not_pointer) - << Attr.getName()->getName() << QT; - } else { - S.Diag(Attr.getLoc(), diag::err_attribute_can_be_applied_only_to_value_decl) - << Attr.getName(); + if (threadSafetyCheckIsSmartPointer(S, RT)) + return true; } + + S.Diag(Attr.getLoc(), diag::warn_thread_attribute_decl_not_pointer) + << Attr.getName()->getName() << QT; return false; } diff --git a/test/SemaCXX/warn-thread-safety-analysis.cpp b/test/SemaCXX/warn-thread-safety-analysis.cpp index ce6250d6da90592a8ccdbe8a7240df41df5541dc..6b0159064be4b31ecc43027a99e149db59e7c99a 100644 --- a/test/SemaCXX/warn-thread-safety-analysis.cpp +++ b/test/SemaCXX/warn-thread-safety-analysis.cpp @@ -4314,3 +4314,15 @@ class A { } // end namespace NonMemberCalleeICETest +namespace { + int i PT_GUARDED_BY(sls_mu); // expected-warning {{'pt_guarded_by' only applies to pointer types; type here is 'int'}} + int j PT_GUARDED_VAR; // expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}} + + void test() { + int i PT_GUARDED_BY(sls_mu); // expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}} + int j PT_GUARDED_VAR; // expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}} + + typedef int PT_GUARDED_BY(sls_mu) bad1; // expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}} + typedef int PT_GUARDED_VAR bad2; // expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}} + } +}