This is an archive of the discontinued LLVM Phabricator instance.

Add helper functionality for parsing different attribute syntaxes in arbitrary order
ClosedPublic

Authored by aaron.ballman on Jan 26 2021, 10:37 AM.

Details

Summary

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.

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.

Diff Detail

Event Timeline

aaron.ballman requested review of this revision.Jan 26 2021, 10:37 AM
aaron.ballman created this revision.
dblaikie accepted this revision.Jan 26 2021, 2:28 PM

Looks good to me! (welcome to wait for more eyes, if you like)

This revision is now accepted and ready to land.Jan 26 2021, 2:28 PM

Looks good to me! (welcome to wait for more eyes, if you like)

Thanks for the review! I think this is safe enough to land and I can deal with any concerns post-commit, so I've committed in 9f2c7effd7f386e95aff3358500bc30974d35b0d