diff options
| author | Aaron Ballman <aaron@aaronballman.com> | 2013-12-26 14:54:11 +0000 |
|---|---|---|
| committer | Aaron Ballman <aaron@aaronballman.com> | 2013-12-26 14:54:11 +0000 |
| commit | 553e68118f14cb1b864791e9eea5f23167e29dfe (patch) | |
| tree | a33da73f6c116080d023db8e0b28e4e8dc891144 /clang | |
| parent | 216a0ff5b3c8920301bad10b380e4a4ede235e08 (diff) | |
| download | bcm5719-llvm-553e68118f14cb1b864791e9eea5f23167e29dfe.tar.gz bcm5719-llvm-553e68118f14cb1b864791e9eea5f23167e29dfe.zip | |
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.
llvm-svn: 198046
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 34 | ||||
| -rw-r--r-- | clang/test/SemaCXX/warn-thread-safety-analysis.cpp | 12 |
2 files changed, 27 insertions, 19 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 56df48230cb..72a0ddbe77f 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/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/clang/test/SemaCXX/warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp index ce6250d6da9..6b0159064be 100644 --- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp +++ b/clang/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}} + } +} |

