[PATCH] D99278: [clang][parser] Allow GNU-style attributes in struct declarations

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 24 09:41:16 PDT 2021


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, rsmith, rjmccall.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Sorry for the title, I'm not 100% sure that's even correct here.

This call to `ProhibitAttributes()` is dead code in the case of GNU-style attributes. They are needed in e.g. `clang/test/Parser/objcbridge-related-attribute.m`.

However, adding a `&& !getLangOpts().ObjC` to the if statement just before is also not sufficient since clang expects to parse GNU-style attributes at this place without diagnosing them as well, for example in `clang/test/Sema/struct-decl.c:71`. This ends up diagnosing the wrongly-placed `noreturn` attribute at a later stage.

Once `ProhibitAttributes()` works with GNU-style attributes the cases mentioned above (and tons of other cases) are being diagnosed as incorrect.

This change depends on https://reviews.llvm.org/D97362 landing first.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99278

Files:
  clang/lib/Parse/ParseDeclCXX.cpp


Index: clang/lib/Parse/ParseDeclCXX.cpp
===================================================================
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1933,7 +1933,7 @@
                                TemplateParams ? TemplateParams->size() : 0));
   } else {
     if (TUK != Sema::TUK_Declaration && TUK != Sema::TUK_Definition)
-      ProhibitAttributes(attrs);
+      ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed, /* DiagnoseEmptyAttrs=*/true);
 
     if (TUK == Sema::TUK_Definition &&
         TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99278.333022.patch
Type: text/x-patch
Size: 619 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210324/a0d2e05b/attachment.bin>


More information about the cfe-commits mailing list