This is an archive of the discontinued LLVM Phabricator instance.

Use tablegen to diagnose mutually exclusive attributes
ClosedPublic

Authored by aaron.ballman on Apr 2 2021, 11:55 AM.

Details

Summary

Currently, when one or more attributes are mutually exclusive, the developer adding the attribute has to manually emit diagnostics. In practice, this is highly error prone, especially for declaration attributes, because such checking is not trivial. Redeclarations require you to write a "merge" function to diagnose mutually exclusive attributes and most attributes get this wrong.

This patch introduces a table-generated way to specify that a group of two or more attributes are mutually exclusive: def : MutualExclusions<[Attr1, Attr2, Attr3]>;

This works for both statement and declaration attributes (but not type attributes) and the checking is done either from the common attribute diagnostic checking code or from within mergeDeclAttribute() when merging redeclarations.

Diff Detail

Event Timeline

aaron.ballman requested review of this revision.Apr 2 2021, 11:55 AM
aaron.ballman created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2021, 11:55 AM

@rsmith -- I am posting the review so that I can see how the CI pipeline likes the functionality (because this impacts so many different attributes), but I intend to commit it on my own authority once CI passes. Feel free to review it if you'd like and I'll address any concerns you have post-commit.

Correcting lint warnings, adding documentation for the new feature.

aaron.ballman accepted this revision.Apr 2 2021, 1:35 PM

Accepting on my own authority so I can close in a moment.

This revision is now accepted and ready to land.Apr 2 2021, 1:35 PM