[clang] [clang][bytecode] Use tailcalls via `[[clang::musttail]]` (PR #173756)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 14 18:48:34 PST 2026


Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/173756 at github.com>


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- clang/lib/AST/ByteCode/Interp.cpp clang/lib/AST/ExprConstant.cpp clang/utils/TableGen/ClangOpcodesEmitter.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index cb63e0f72..59ffb018d 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -2375,8 +2375,6 @@ bool FinishInitGlobal(InterpState &S, CodePtr OpPC) {
 #pragma optimize("", off)
 #endif
 
-
-
 bool InterpNext(InterpState &S, CodePtr &PC);
 
 bool Interpret(InterpState &S) {
@@ -2408,15 +2406,10 @@ bool Interpret(InterpState &S) {
   }
 }
 
-
-
-
 #define GET_INTERPFNS_
 #include "Opcodes.inc"
 #undef GET_INTERPFNS_
 
-
-
 using InterpFn = bool (*)(InterpState &, CodePtr &PC);
 
 const InterpFn InterpFunctions[] = {
@@ -2425,7 +2418,6 @@ const InterpFn InterpFunctions[] = {
 #undef GET_INTERPFNS
 };
 
-
 bool InterpNext(InterpState &S, CodePtr &PC) {
   auto Op = PC.read<Opcode>();
   auto Fn = InterpFunctions[Op];
diff --git a/clang/utils/TableGen/ClangOpcodesEmitter.cpp b/clang/utils/TableGen/ClangOpcodesEmitter.cpp
index 4d05d781d..3a94f1450 100644
--- a/clang/utils/TableGen/ClangOpcodesEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpcodesEmitter.cpp
@@ -114,14 +114,14 @@ void ClangOpcodesEmitter::EmitEnum(raw_ostream &OS, StringRef N,
 }
 
 void ClangOpcodesEmitter::EmitInterpFns_(raw_ostream &OS, StringRef N,
-                                     const Record *R) {
+                                         const Record *R) {
   OS << "#ifdef GET_INTERPFNS_\n";
-  Enumerate(R, N, [&](ArrayRef<const Record *>TS, const Twine &ID) {
+  Enumerate(R, N, [&](ArrayRef<const Record *> TS, const Twine &ID) {
     OS << "static bool Interp_" << ID << "(InterpState &S, CodePtr &PC) {\n";
 
-              bool CanReturn = R->getValueAsBit("CanReturn");
+    bool CanReturn = R->getValueAsBit("CanReturn");
     const auto &Args = R->getValueAsListOfDefs("Args");
-              bool ChangesPC = R->getValueAsBit("ChangesPC");
+    bool ChangesPC = R->getValueAsBit("ChangesPC");
 
     OS << "{\n";
 
@@ -137,30 +137,28 @@ void ClangOpcodesEmitter::EmitInterpFns_(raw_ostream &OS, StringRef N,
       else
         OS << "  const auto V" << I;
       OS << " = ";
-      OS << "ReadArg<" << Arg->getValueAsString("Name")
-         << ">(S, PC);\n";
+      OS << "ReadArg<" << Arg->getValueAsString("Name") << ">(S, PC);\n";
     }
 
+    OS << "  if (!" << N;
+    PrintTypes(OS, TS);
+    OS << "(S";
+    // OS << ", OpPC";
+    if (ChangesPC)
+      OS << ", PC";
+    else
+      OS << ", OpPC";
+    for (size_t I = 0, N = Args.size(); I < N; ++I)
+      OS << ", V" << I;
+    OS << "))\n";
+    OS << "    return false;\n";
 
-              OS << "  if (!" << N;
-              PrintTypes(OS, TS);
-              OS << "(S";
-                // OS << ", OpPC";
-              if (ChangesPC)
-                OS << ", PC";
-              else
-                OS << ", OpPC";
-              for (size_t I = 0, N = Args.size(); I < N; ++I)
-                OS << ", V" << I;
-              OS << "))\n";
-              OS << "    return false;\n";
-
-              OS << "}\n";
+    OS << "}\n";
 
-              if (!CanReturn)
-                OS << "[[clang::musttail]] return InterpNext(S, PC);\n";
-              else
-                OS << " return true;\n";
+    if (!CanReturn)
+      OS << "[[clang::musttail]] return InterpNext(S, PC);\n";
+    else
+      OS << " return true;\n";
     // OS << "  return false;\n";
 
     OS << "}\n";
@@ -168,10 +166,8 @@ void ClangOpcodesEmitter::EmitInterpFns_(raw_ostream &OS, StringRef N,
   OS << "#endif\n";
 }
 
-
-
 void ClangOpcodesEmitter::EmitInterpFns(raw_ostream &OS, StringRef N,
-                                     const Record *R) {
+                                        const Record *R) {
   OS << "#ifdef GET_INTERPFNS\n";
   Enumerate(R, N, [&OS](ArrayRef<const Record *>, const Twine &ID) {
     OS << "&Interp_" << ID << ",\n";

``````````

</details>


https://github.com/llvm/llvm-project/pull/173756


More information about the cfe-commits mailing list