[PATCH] D99809: Use tablegen to diagnose mutually exclusive attributes

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 2 11:55:51 PDT 2021


aaron.ballman created this revision.
aaron.ballman added a reviewer: rsmith.
aaron.ballman requested review of this revision.
Herald added a project: clang.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99809

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/ParsedAttr.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/Sema/attr-coldhot.c
  clang/test/Sema/attr-disable-tail-calls.c
  clang/test/Sema/internal_linkage.c
  clang/test/SemaCXX/attr-speculative-load-hardening.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99809.335000.patch
Type: text/x-patch
Size: 38218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210402/eb870ada/attachment-0001.bin>


More information about the cfe-commits mailing list