[clang] 765cd7a - [clang][TableGen] suppress macro emission when trait spelling is empty (#246180)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 28 05:38:29 PST 2026
Author: Matthias Wippich
Date: 2026-11-28T14:38:23+01:00
New Revision: 765cd7a687f1325e8f7c2b1dc46de9c1facf578e
URL: https://github.com/llvm/llvm-project/commit/765cd7a687f1325e8f7c2b1dc46de9c1facf578e
DIFF: https://github.com/llvm/llvm-project/commit/765cd7a687f1325e8f7c2b1dc46de9c1facf578e.diff
LOG: [clang][TableGen] suppress macro emission when trait spelling is empty (#246180)
Trait definitions in BuiltinTraits.td can have an empty associated
`Spelling`. This makes them internal traits that do not map to a builtin
recognized by the parser. This is still useful, since it allows us to
map a standard library spelling (such as
`std::is_trivially_copy_constructible`) to an internal-use trait and
reuse existing machinery for more detailed diagnostics.
Currently we only have one such trait `IsDeducible`. All of the current
uses of the macros generated from BuiltinTraits.td define the
`TYPE_TRAIT*` macros roughly like this
```cpp
#define TYPE_TRAIT_1(Spelling, Name, Key) \
case tok::kw_##Spelling: \
/* ... */
#define TYPE_TRAIT_2(Spelling, Name, Key) \
case tok::kw_##Spelling: \
/* ... */
#define TYPE_TRAIT_N(Spelling, Name, Key) \
case tok::kw_##Spelling: \
/* ... */
```
For these expansions, Spelling must be non-empty.
Due to this, more than one internal trait leads to potentially
generating multiple cases for `tok::kw_` and redefinitions of `kw_` in
`tok::TokenKind`. This patch addresses it by suppressing emission of the
macros for internal traits.
This issue was first noticed in
https://github.com/llvm/llvm-project/pull/225487#discussion_r4693652195.
Added:
Modified:
clang/utils/TableGen/ClangBuiltinTraitsEmitter.cpp
Removed:
################################################################################
diff --git a/clang/utils/TableGen/ClangBuiltinTraitsEmitter.cpp b/clang/utils/TableGen/ClangBuiltinTraitsEmitter.cpp
index 09fbbcc522c50f..b61f4488b9a9b5 100644
--- a/clang/utils/TableGen/ClangBuiltinTraitsEmitter.cpp
+++ b/clang/utils/TableGen/ClangBuiltinTraitsEmitter.cpp
@@ -99,8 +99,10 @@ void emitMacroDefs(const RecordKeeper &Records, raw_ostream &OS) {
const auto Traits = getAllDerivedDefsInDeclOrder(Records, "Trait");
const auto Aliases = getAllDerivedDefsInDeclOrder(Records, "Alias");
- for (const Record *R : concat<const Record *const>(Traits, Aliases))
- emitMacro(R, OS);
+ for (const Record *R : concat<const Record *const>(Traits, Aliases)) {
+ if (!R->getValueAsString("Spelling").empty())
+ emitMacro(R, OS);
+ }
for (const auto &[MacroName, _] : reverse(MacroDefs))
OS << "#undef " << MacroName << "\n";
More information about the cfe-commits
mailing list