From 6416d8f1843f7c02d90ce4d73ab7c7d6542b3c57 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Mon, 11 May 2026 19:26:50 -0700 Subject: [PATCH] [TableGen] Emit the primary input file in -d depfile output This fixes a bug where old, but still supported, versions of CMake and ninja perpetually consider zero-include tablegen files to be out of date. It also matches what Clang and GCC do for regular C compilations. When a .td input has no `include` directives, the depfile produced by `-d` contains only `:` followed by zero dependencies. My version (3.27) of CMake's `cmake_transform_depfile` step then writes a 0-byte file, which old versions of ninja treat as a missing depfile and re-run the rule on every incremental build (e.g. Attributes.td, ValueTypes.td). Here's the effect on Attributes.inc.d: ``` $ cat ./build/include/llvm/IR/Attributes.inc.d Attributes.inc: $ cat ./build/include/llvm/IR/Attributes.inc.d Attributes.inc: /work/llvm-project/llvm/include/llvm/IR/Attributes.td ``` An LLM was used to help create this change. --- Backport of https://github.com/llvm/llvm-project/commit/05c0db7f0aa10f04dc545eef7b3768528523ca98 --- interpreter/llvm-project/llvm-project.tag | 3 +-- interpreter/llvm-project/llvm/lib/TableGen/Main.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/interpreter/llvm-project/llvm-project.tag b/interpreter/llvm-project/llvm-project.tag index 5237ff86dc1f2..a7f7e0b9b7783 100644 --- a/interpreter/llvm-project/llvm-project.tag +++ b/interpreter/llvm-project/llvm-project.tag @@ -1,2 +1 @@ -ROOT-llvm22-20260619-01 - +ROOT-llvm22-20260804-01 diff --git a/interpreter/llvm-project/llvm/lib/TableGen/Main.cpp b/interpreter/llvm-project/llvm/lib/TableGen/Main.cpp index ec4579f378dcb..99994f06c5512 100644 --- a/interpreter/llvm-project/llvm/lib/TableGen/Main.cpp +++ b/interpreter/llvm-project/llvm/lib/TableGen/Main.cpp @@ -97,6 +97,16 @@ static int createDependencyFile(const TGParser &Parser, const char *argv0) { return reportError(argv0, "error opening " + DependFilename + ":" + EC.message() + "\n"); DepOut.os() << OutputFilename << ":"; + + // Emit the primary input file as a dependency. This matches C compilers like + // Clang and GCC. Without it, a .td file with no `include` directives would + // produce a depfile listing zero dependencies. CMake's + // `cmake_transform_depfile` then collapses that to a 0-byte file, which Ninja + // treats as a missing depfile and re-runs the rule on every incremental + // build. + if (InputFilename != "-") + DepOut.os() << ' ' << InputFilename; + for (const auto &Dep : Parser.getDependencies()) { DepOut.os() << ' ' << Dep; }