Skip to content

Commit 2b468af

Browse files
committed
improve attribute checking with a simplified helper
1 parent d89c879 commit 2b468af

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

clang/include/clang/Basic/AttributeCommonInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H
1616

1717
#include "clang/Basic/SourceLocation.h"
18+
#include "clang/Basic/TargetInfo.h"
1819
#include "clang/Basic/TokenKinds.h"
1920

2021
namespace clang {
@@ -248,6 +249,9 @@ class AttributeCommonInfo {
248249

249250
static AttrArgsInfo getCXX11AttrArgsInfo(const IdentifierInfo *Name);
250251

252+
static bool hasCXX11Attr(const IdentifierInfo *Name, const TargetInfo &Target,
253+
const LangOptions &LangOpts);
254+
251255
private:
252256
/// Get an index into the attribute spelling list
253257
/// defined in Attr.td. This index is used by an attribute

clang/lib/Basic/Attributes.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,24 @@ AttributeCommonInfo::getParsedKind(const IdentifierInfo *Name,
153153

154154
AttributeCommonInfo::AttrArgsInfo
155155
AttributeCommonInfo::getCXX11AttrArgsInfo(const IdentifierInfo *Name) {
156+
StringRef AttrName =
157+
normalizeAttrName(Name, /*NormalizedScopeName*/ "", Syntax::AS_CXX11);
156158
#define CXX11_ATTR_ARGS_INFO
157-
return llvm::StringSwitch<AttributeCommonInfo::AttrArgsInfo>(
158-
normalizeName(Name, /*Scope*/ nullptr, Syntax::AS_CXX11))
159+
return llvm::StringSwitch<AttributeCommonInfo::AttrArgsInfo>(AttrName)
159160
#include "clang/Basic/CXX11AttributeInfo.inc"
160161
.Default(AttributeCommonInfo::AttrArgsInfo::None);
161162
#undef CXX11_ATTR_ARGS_INFO
162163
}
163164

165+
bool AttributeCommonInfo::hasCXX11Attr(const IdentifierInfo *Name,
166+
const TargetInfo &Target,
167+
const LangOptions &LangOpts) {
168+
StringRef AttrName =
169+
normalizeAttrName(Name, /*NormalizedScopeName*/ "", Syntax::AS_CXX11);
170+
return hasAttributeImpl(Syntax::AS_CXX11, AttrName, /*ScopeName*/ "", Target,
171+
LangOpts) > 0;
172+
}
173+
164174
std::string AttributeCommonInfo::getNormalizedFullName() const {
165175
return static_cast<std::string>(
166176
normalizeName(getAttrName(), getScopeName(), getSyntax()));

clang/lib/Lex/PPDirectives.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr,
179179
static bool isReservedCXXAttributeName(Preprocessor &PP, IdentifierInfo *II) {
180180
const LangOptions &Lang = PP.getLangOpts();
181181
if (Lang.CPlusPlus &&
182-
hasAttribute(AttributeCommonInfo::Syntax::AS_CXX11, /*Scope*/ nullptr, II,
183-
PP.getTargetInfo(), Lang) > 0) {
182+
AttributeCommonInfo::hasCXX11Attr(II, PP.getTargetInfo(), Lang)) {
184183
AttributeCommonInfo::AttrArgsInfo AttrArgsInfo =
185184
AttributeCommonInfo::getCXX11AttrArgsInfo(II);
186185
if (AttrArgsInfo == AttributeCommonInfo::AttrArgsInfo::Required)

0 commit comments

Comments
 (0)