[Clang] Fix build with GCC 14 on ARM
authorEmanuele Rocca <emanuele.rocca@arm.com>
Mon, 9 Sep 2024 12:56:19 +0000 (14:56 +0200)
committerGianfranco Costamagna <locutusofborg@debian.org>
Mon, 9 Sep 2024 12:56:19 +0000 (14:56 +0200)
Origin: backport, https://github.com/llvm/llvm-project/pull/78704/commits/078c18de832328f743fb6e
Bug-Debian: https://bugs.debian.org/1077068
Forwarded: not-needed
Last-Update: 2024-08-29

Backport to LLVM 17 of a patch by Nikita Popov <npopov@redhat.com> merged in
the upstream main branch. The patch fixes a build issue on arm64 with GCC 14.
The additional changes to the for loop in ClangAttrEmitter.cpp have been taken
from the main branch and are needed for the HasArgs boolean.

Gbp-Pq: Name arm64-clang-gcc-14.patch

clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Basic/TokenKinds.h
clang/utils/TableGen/ClangAttrEmitter.cpp

index ef0dad0f2dcd9689783263f57e6a25cb891bbac9..4c3965ca24edf49182a2d232d1681522098bfb9c 100644 (file)
@@ -753,7 +753,7 @@ KEYWORD(__builtin_sycl_unique_stable_name, KEYSYCL)
 
 // Keywords defined by Attr.td.
 #ifndef KEYWORD_ATTRIBUTE
-#define KEYWORD_ATTRIBUTE(X) KEYWORD(X, KEYALL)
+#define KEYWORD_ATTRIBUTE(X, HASARG, EMPTY) KEYWORD(EMPTY ## X, KEYALL)
 #endif
 #include "clang/Basic/AttrTokenKinds.inc"
 
index e4857405bc7f4627c00359905521289fa466f435..988696b6d92bbdbb710c7e795613bdda91d12ac4 100644 (file)
@@ -109,7 +109,7 @@ bool isPragmaAnnotation(TokenKind K);
 
 inline constexpr bool isRegularKeywordAttribute(TokenKind K) {
   return (false
-#define KEYWORD_ATTRIBUTE(X) || (K == tok::kw_##X)
+#define KEYWORD_ATTRIBUTE(X, HASARG, EMPTY) || (K == tok::kw_##X)
 #include "clang/Basic/AttrTokenKinds.inc"
   );
 }
index b5813c6abc2b920c19b5fac60d45f938e6a2b197..3394e4d8594c958406ea837548e9a9441bdb7f26 100644 (file)
@@ -3423,14 +3423,14 @@ void EmitClangAttrTokenKinds(RecordKeeper &Records, raw_ostream &OS) {
   // Assume for now that the same token is not used in multiple regular
   // keyword attributes.
   for (auto *R : Records.getAllDerivedDefinitions("Attr"))
-    for (const auto &S : GetFlattenedSpellings(*R))
-      if (isRegularKeywordAttribute(S)) {
-        if (!R->getValueAsListOfDefs("Args").empty())
-          PrintError(R->getLoc(),
-                     "RegularKeyword attributes with arguments are not "
-                     "yet supported");
+    for (const auto &S : GetFlattenedSpellings(*R)) {
+      if (!isRegularKeywordAttribute(S))
+          continue;
+        std::vector<Record *> Args = R->getValueAsListOfDefs("Args");
+        bool HasArgs = llvm::any_of(Args, [](const Record *Arg) { return !Arg->getValueAsBit("Fake"); });
         OS << "KEYWORD_ATTRIBUTE("
-           << S.getSpellingRecord().getValueAsString("Name") << ")\n";
+           << S.getSpellingRecord().getValueAsString("Name") << ", "
+           << (HasArgs ? "true" : "false") << ", )\n";
       }
   OS << "#undef KEYWORD_ATTRIBUTE\n";
 }