diff options
author | Sergei Barannikov <barannikov88@gmail.com> | 2024-02-18 17:44:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-18 17:44:19 +0300 |
commit | 2d0137dd64017c34101f8a763fd8958c20acd6bb (patch) | |
tree | 252ae32b355a6488e1d57436c80aebd75509f3a7 /clang/lib/Parse/ParseDecl.cpp | |
parent | 3496927edcd0685807351ba88a7e2cfb006e1c0d (diff) | |
download | llvm-2d0137dd64017c34101f8a763fd8958c20acd6bb.zip llvm-2d0137dd64017c34101f8a763fd8958c20acd6bb.tar.gz llvm-2d0137dd64017c34101f8a763fd8958c20acd6bb.tar.bz2 |
[clang] Differentiate between identifier and string EnumArgument (#68550)
EnumArgument may be a string or an identifier. If it is a string, it
should be parsed as unevaluated string literal. Add IsString flag to
EnumArgument so that the parser can choose the correct parsing method.
Target-specific attributes that share spelling may have different
attribute "prototypes". For example, ARM's version of "interrupt"
attribute accepts a string enum, while MSP430's version accepts an
unsigned integer. Adjust ClangAttrEmitter so that the generated
`attributeStringLiteralListArg` returns the correct mask depending on
target triple.
It is worth noting that even after this change some string arguments are
still parsed as identifiers or, worse, as expressions. This is because
of some special logic in `ParseAttributeArgsCommon`. Fixing it is out of
scope of this patch.
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 0728113..edfab11 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -291,7 +291,7 @@ static bool attributeHasIdentifierArg(const IdentifierInfo &II) { /// Determine whether the given attribute has an identifier argument. static ParsedAttributeArgumentsProperties -attributeStringLiteralListArg(const IdentifierInfo &II) { +attributeStringLiteralListArg(const llvm::Triple &T, const IdentifierInfo &II) { #define CLANG_ATTR_STRING_LITERAL_ARG_LIST return llvm::StringSwitch<uint32_t>(normalizeAttrName(II.getName())) #include "clang/Parse/AttrParserStringSwitches.inc" @@ -550,7 +550,7 @@ unsigned Parser::ParseAttributeArgsCommon( ExprVector ParsedExprs; ParsedAttributeArgumentsProperties ArgProperties = - attributeStringLiteralListArg(*AttrName); + attributeStringLiteralListArg(getTargetInfo().getTriple(), *AttrName); if (ParseAttributeArgumentList(*AttrName, ParsedExprs, ArgProperties)) { SkipUntil(tok::r_paren, StopAtSemi); return 0; |