From 7853e320e23e2e576369fb5d9e01060babfe4012 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 26 Dec 2013 14:54:11 +0000 Subject: [PATCH] Removing some unneeded code, and a diagnostic that was obsoleted. The type has already been determined to be a ValueDecl by virtue of the attribute subjects. Added some test case coverage as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198046 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclAttr.cpp | 34 +++++++++----------- test/SemaCXX/warn-thread-safety-analysis.cpp | 12 +++++++ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 56df48230c..72a0ddbe77 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(D)) { - QualType QT = vd->getType(); - if (QT->isAnyPointerType()) - return true; - - if (const RecordType *RT = QT->getAs()) { - // 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(D); + QualType QT = vd->getType(); + if (QT->isAnyPointerType()) + return true; - if (threadSafetyCheckIsSmartPointer(S, RT)) - return true; - } + if (const RecordType *RT = QT->getAs()) { + // 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 ce6250d6da..6b0159064b 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}} + } +} -- 2.40.0