Skip to content

Commit

Permalink
[Clang] Fix build with GCC 14 on ARM (#78704)
Browse files Browse the repository at this point in the history
GCC 14 defines `__arm_streaming` as a macro expanding to
`[[arm::streaming]]`. Due to the nested macro use, this gets expanded
prior to concatenation.

It doesn't look like C++ has a really clean way to prevent macro
expansion. The best I have found is to use `EMPTY ## X` where `EMPTY` is
an empty macro argument, so this is the hack I'm implementing here.

Fixes #78691.
  • Loading branch information
nikic committed Jan 19, 2024
1 parent 5a7f9a5 commit d54dfdd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/AttributeCommonInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ inline bool doesKeywordAttributeTakeArgs(tok::TokenKind Kind) {
switch (Kind) {
default:
return false;
#define KEYWORD_ATTRIBUTE(NAME, HASARG) \
#define KEYWORD_ATTRIBUTE(NAME, HASARG, ...) \
case tok::kw_##NAME: \
return HASARG;
#include "clang/Basic/RegularKeywordAttrInfo.inc"
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,9 @@ KEYWORD(__builtin_available , KEYALL)
KEYWORD(__builtin_sycl_unique_stable_name, KEYSYCL)

// Keywords defined by Attr.td.
// The "EMPTY ## X" is used to prevent early macro-expansion of the keyword.
#ifndef KEYWORD_ATTRIBUTE
#define KEYWORD_ATTRIBUTE(X, ...) KEYWORD(X, KEYALL)
#define KEYWORD_ATTRIBUTE(X, HASARG, EMPTY) KEYWORD(EMPTY ## X, KEYALL)
#endif
#include "clang/Basic/RegularKeywordAttrInfo.inc"

Expand Down
2 changes: 1 addition & 1 deletion clang/utils/TableGen/ClangAttrEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3589,7 +3589,7 @@ void EmitClangRegularKeywordAttributeInfo(RecordKeeper &Records,

OS << "KEYWORD_ATTRIBUTE("
<< S.getSpellingRecord().getValueAsString("Name") << ", "
<< (HasArgs ? "true" : "false") << ")\n";
<< (HasArgs ? "true" : "false") << ", )\n";
}
OS << "#undef KEYWORD_ATTRIBUTE\n";
}
Expand Down

0 comments on commit d54dfdd

Please sign in to comment.