aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseStmt.cpp
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2023-04-04 14:05:13 +0100
committerRichard Sandiford <richard.sandiford@arm.com>2023-05-31 10:43:10 +0100
commit33ee5c4663465022ffe288817968e90064d88a09 (patch)
tree759265a484e00dca99223fa4ac68fdd548f22a1c /clang/lib/Parse/ParseStmt.cpp
parent301eb6b68f30074ee3a90e2dfbd11dfd87076323 (diff)
downloadllvm-33ee5c4663465022ffe288817968e90064d88a09.zip
llvm-33ee5c4663465022ffe288817968e90064d88a09.tar.gz
llvm-33ee5c4663465022ffe288817968e90064d88a09.tar.bz2
[clang] Add Parse and Sema support for RegularKeyword attributes
This patch adds the Parse and Sema support for RegularKeyword attributes, following on from a previous patch that added Attr.td support. The patch is quite large. However, nothing outside the tests is specific to the first RegularKeyword attribute (__arm_streaming). The patch should therefore be a one-off, up-front cost. Other attributes just need an entry in Attr.td and the usual Sema support. The approach taken in the patch is that the keywords can be used with any language version. If standard attributes were added in language version Y, the keyword rules for version X<Y are the same as they were for version Y (to the extent possible). Any extensions beyond Y are handled in the same way for both keywords and attributes. This ensures that existing C++11 successors like C++17 are not treated differently from versions that have yet to be defined. Some notes on the implementation: * The patch emits errors rather than warnings for diagnostics that relate to keywords. * Where possible, the patch drops “attribute” from diagnostics relating to keywords. * One exception to the previous point is that warnings about C++ extensions do still mention attributes. The use there seemed OK since the diagnostics are noting a change in the production rules. * If a diagnostic string needs to be different for keywords and attributes, the patch standardizes on passing the attribute/ name/token followed by 0 for attributes and 1 for keywords. * Although the patch updates warn_attribute_wrong_decl_type_str, warn_attribute_wrong_decl_type, and warn_attribute_wrong_decl_type, only the error forms of these strings are used for keywords. * I couldn't trigger the warnings in checkUnusedDeclAttributes, even for existing attributes. An assert on the warnings caused no failures in the testsuite. I think in practice all standard attributes would be diagnosed before this. * The patch drops a call to standardAttributesAllowed in ParseFunctionDeclarator. This is because MaybeParseCXX11Attributes checks the same thing itself, where appropriate. * The new tests are based on c2x-attributes.c and cxx0x-attributes.cpp. The C++ test also incorporates a version of cxx11-base-spec-attributes.cpp. The FIXMEs are carried across from the originals. Differential Revision: https://reviews.llvm.org/D148702
Diffstat (limited to 'clang/lib/Parse/ParseStmt.cpp')
-rw-r--r--clang/lib/Parse/ParseStmt.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index bde9df0..aea810e 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -335,7 +335,12 @@ Retry:
case tok::kw_asm: {
for (const ParsedAttr &AL : CXX11Attrs)
- Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
+ // Could be relaxed if asm-related regular keyword attributes are
+ // added later.
+ (AL.isRegularKeywordAttribute()
+ ? Diag(AL.getRange().getBegin(), diag::err_keyword_not_allowed)
+ : Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored))
+ << AL;
// Prevent these from being interpreted as statement attributes later on.
CXX11Attrs.clear();
ProhibitAttributes(GNUAttrs);