[llvm] [bazel] Use `additional_compiler_inputs` to handle include scanning for TargetPassRegistry.inc (PR #199201)

Jordan Rupprecht via llvm-commits llvm-commits at lists.llvm.org
Fri May 22 04:59:37 PDT 2026


https://github.com/rupprecht created https://github.com/llvm/llvm-project/pull/199201

This use of using `#include` with a macro breaks include scanning, for example:

* `GET_PASS_REGISTRY` defined here: https://github.com/llvm/llvm-project/blob/5c853423f4f9e7296b7596b7f3ccade481686bfd/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp#L603
* `GET_PASS_REGISTRY` included here: https://github.com/llvm/llvm-project/blob/5c853423f4f9e7296b7596b7f3ccade481686bfd/llvm/include/llvm/Passes/TargetPassRegistry.inc#L60

When include scanning is enabled, the `PassRegistry.def` gets omitted because it the include scanner does not handle this case. Providing it via `additional_compiler_inputs` ensures it is included even in that case.

>From 379e87a6703d198549e2ca7477b64da260dfd0c4 Mon Sep 17 00:00:00 2001
From: Jordan Rupprecht <rupprecht at google.com>
Date: Fri, 22 May 2026 04:51:59 -0700
Subject: [PATCH] Add additional_compiler_inputs

---
 utils/bazel/llvm-project-overlay/llvm/BUILD.bazel | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
index 1bab2d62595bc..c59fac601a90d 100644
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -3907,6 +3907,20 @@ gentbl_cc_library(
             allow_empty = True,
         ),
         hdrs = ["lib/Target/" + target["name"] + "/" + target["short_name"] + ".h"],
+        # The TargetMachine files use this pattern:
+        #
+        # // In FooTargetMachine.cpp
+        # #define GET_PASS_REGISTRY "FooPassRegistry.def"
+        # #include "llvm/Passes/TargetPassRegistry.inc"
+        #
+        # // In TargetPassRegistry.inc
+        # #include GET_PASS_REGISTRY
+        #
+        # This breaks when using include scanning, so include them explicitly here.
+        additional_compiler_inputs = glob(
+            ["lib/Target/" + target["name"] + "/*.def"],
+            allow_empty = True,
+        ),
         copts = llvm_copts,
         features = [
             "-layering_check",



More information about the llvm-commits mailing list