Author: Anders Waldenborg Date: 2023-03-13T16:47:51+01:00 New Revision: 446f78092ffa75274866ec40411a1c0dbec2f13d
URL: https://github.com/llvm/llvm-project/commit/446f78092ffa75274866ec40411a1c0dbec2f13d DIFF: https://github.com/llvm/llvm-project/commit/446f78092ffa75274866ec40411a1c0dbec2f13d.diff LOG: [clang] Extract ParsedAttrInfo::hasSpelling method (NFC) This intends to simplify this checking when it is done in more places. No functional change intended. Differential Revision: https://reviews.llvm.org/D145769 Added: Modified: clang/include/clang/Basic/ParsedAttrInfo.h clang/lib/Sema/ParsedAttr.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/ParsedAttrInfo.h b/clang/include/clang/Basic/ParsedAttrInfo.h index 788c960b01bf..4444f12de9ce 100644 --- a/clang/include/clang/Basic/ParsedAttrInfo.h +++ b/clang/include/clang/Basic/ParsedAttrInfo.h @@ -88,6 +88,13 @@ struct ParsedAttrInfo { public: virtual ~ParsedAttrInfo() = default; + /// Check if this attribute has specified spelling. + bool hasSpelling(AttributeCommonInfo::Syntax Syntax, StringRef Name) const { + return llvm::any_of(Spellings, [&](const Spelling &S) { + return (S.Syntax == Syntax && S.NormalizedFullName == Name); + }); + } + /// Check if this attribute appertains to D, and issue a diagnostic if not. virtual bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr, const Decl *D) const { diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp index 50191d45b100..2af688fb58c8 100644 --- a/clang/lib/Sema/ParsedAttr.cpp +++ b/clang/lib/Sema/ParsedAttr.cpp @@ -126,9 +126,8 @@ const ParsedAttrInfo &ParsedAttrInfo::get(const AttributeCommonInfo &A) { SyntaxUsed = AttributeCommonInfo::AS_Keyword; for (auto &Ptr : getAttributePluginInstances()) - for (auto &S : Ptr->Spellings) - if (S.Syntax == SyntaxUsed && S.NormalizedFullName == FullName) - return *Ptr; + if (Ptr->hasSpelling(SyntaxUsed, FullName)) + return *Ptr; // If we failed to find a match then return a default ParsedAttrInfo. static const ParsedAttrInfo DefaultParsedAttrInfo( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits