[PATCH] D95459: Add helper functionality for parsing different attribute syntaxes in arbitrary order

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 26 10:37:29 PST 2021


aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, dblaikie, jyknight, rjmccall.
aaron.ballman requested review of this revision.

In Clang today, we parse the different attribute syntaxes (`__attribute__`, `__declspec`, and `[[]]`) in a fairly rigid order. This leads to confusion for users when they guess the order incorrectly, and leads to bug reports like PR24559 or necessitates changes like D94788 <https://reviews.llvm.org/D94788>.

This patch adds a helper function to allow us to more easily parse attributes in arbitrary order, and then updates all of the places where we would parse two or more different syntaxes in a rigid order to use the helper method. The patch does not attempt to handle Microsoft attributes (`[]`) because those are ambiguous with other code constructs and we don't have any attributes that use the syntax.

There may be other places that could be modified to start accepting attributes with more arbitrary orders (such as in lambda expressions), but I think that effort is best left to follow-up work as we notice a need.


https://reviews.llvm.org/D95459

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/test/Parser/attr-order.cpp
  clang/test/SemaOpenCL/address-spaces.cl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95459.319345.patch
Type: text/x-patch
Size: 14615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210126/96cd8fdd/attachment.bin>


More information about the cfe-commits mailing list