[lld] [llvm] [LLVM] Add missing #undef DEBUG_TYPE to headers that #define it (PR #188680)

Maksim Levental via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 25 22:51:49 PDT 2026


https://github.com/makslevental updated https://github.com/llvm/llvm-project/pull/188680

>From 0041bf488fda39d584d64121a6b58617ec4956d0 Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Wed, 25 Mar 2026 22:19:36 -0700
Subject: [PATCH 1/2] Add missing #undef DEBUG_TYPE to headers that #define it

Several headers define DEBUG_TYPE but never undefine it before the
closing include guard. This means any translation unit that includes
these headers (directly or transitively) gets the header's DEBUG_TYPE
leaked into its scope, which can silently override or conflict with
the file's own DEBUG_TYPE.

Add the missing #undef DEBUG_TYPE before the final #endif in each
affected header, matching the convention used by the majority of
LLVM/Clang/LLD headers that define DEBUG_TYPE.

Affected headers:
- lld/wasm/SyntheticSections.h
- llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
- llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h
- llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
- llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
- llvm/lib/IR/ConstantsContext.h
- llvm/tools/llvm-ir2vec/lib/Utils.h
- llvm/tools/llvm-mca/PipelinePrinter.h
- llvm/tools/llvm-mca/Views/InstructionInfoView.h
---
 lld/wasm/SyntheticSections.h                                    | 2 ++
 .../llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h      | 2 ++
 llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h         | 2 ++
 .../ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h   | 2 ++
 .../ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h  | 2 ++
 llvm/lib/IR/ConstantsContext.h                                  | 2 ++
 llvm/tools/llvm-ir2vec/lib/Utils.h                              | 2 ++
 llvm/tools/llvm-mca/PipelinePrinter.h                           | 2 ++
 llvm/tools/llvm-mca/Views/InstructionInfoView.h                 | 2 ++
 9 files changed, 18 insertions(+)

diff --git a/lld/wasm/SyntheticSections.h b/lld/wasm/SyntheticSections.h
index 2862b22da86b3..65c084f903703 100644
--- a/lld/wasm/SyntheticSections.h
+++ b/lld/wasm/SyntheticSections.h
@@ -492,4 +492,6 @@ extern OutStruct out;
 } // namespace wasm
 } // namespace lld
 
+#undef DEBUG_TYPE
+
 #endif
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h b/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
index d8d7ccc0bd7a7..da9807a9618d2 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
@@ -1580,4 +1580,6 @@ class LegalizationArtifactCombiner {
 
 } // namespace llvm
 
+#undef DEBUG_TYPE
+
 #endif // LLVM_CODEGEN_GLOBALISEL_LEGALIZATIONARTIFACTCOMBINER_H
diff --git a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h
index 50ba2f822d832..61bd569722a63 100644
--- a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h
+++ b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h
@@ -235,4 +235,6 @@ class GetImageBaseSymbol {
 } // end namespace jitlink
 } // end namespace llvm
 
+#undef DEBUG_TYPE
+
 #endif // LIB_EXECUTIONENGINE_JITLINK_COFFLINKGRAPHBUILDER_H
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
index 0d5afc289b8c5..33a174e4f373c 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
@@ -224,5 +224,7 @@ class RuntimeDyldCOFFI386 : public RuntimeDyldCOFF {
 
 }
 
+#undef DEBUG_TYPE
+
 #endif
 
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
index 19e42253ab1d7..c96e2cebe5e0b 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
@@ -345,4 +345,6 @@ class RuntimeDyldCOFFThumb : public RuntimeDyldCOFF {
 
 }
 
+#undef DEBUG_TYPE
+
 #endif
diff --git a/llvm/lib/IR/ConstantsContext.h b/llvm/lib/IR/ConstantsContext.h
index cc9bad431787c..555f75b2855ef 100644
--- a/llvm/lib/IR/ConstantsContext.h
+++ b/llvm/lib/IR/ConstantsContext.h
@@ -693,4 +693,6 @@ template <> inline void ConstantUniqueMap<InlineAsm>::freeConstants() {
 
 } // end namespace llvm
 
+#undef DEBUG_TYPE
+
 #endif // LLVM_LIB_IR_CONSTANTSCONTEXT_H
diff --git a/llvm/tools/llvm-ir2vec/lib/Utils.h b/llvm/tools/llvm-ir2vec/lib/Utils.h
index ae2f931a90cf9..d47874c68e4b0 100644
--- a/llvm/tools/llvm-ir2vec/lib/Utils.h
+++ b/llvm/tools/llvm-ir2vec/lib/Utils.h
@@ -218,4 +218,6 @@ struct MIRContext {
 
 } // namespace llvm
 
+#undef DEBUG_TYPE
+
 #endif // LLVM_TOOLS_LLVM_IR2VEC_UTILS_UTILS_H
diff --git a/llvm/tools/llvm-mca/PipelinePrinter.h b/llvm/tools/llvm-mca/PipelinePrinter.h
index d89e913f979f6..d1ebff14d58ba 100644
--- a/llvm/tools/llvm-mca/PipelinePrinter.h
+++ b/llvm/tools/llvm-mca/PipelinePrinter.h
@@ -66,4 +66,6 @@ class PipelinePrinter {
 } // namespace mca
 } // namespace llvm
 
+#undef DEBUG_TYPE
+
 #endif // LLVM_TOOLS_LLVM_MCA_PIPELINEPRINTER_H
diff --git a/llvm/tools/llvm-mca/Views/InstructionInfoView.h b/llvm/tools/llvm-mca/Views/InstructionInfoView.h
index 34c6fec46a6d5..e068088db4f50 100644
--- a/llvm/tools/llvm-mca/Views/InstructionInfoView.h
+++ b/llvm/tools/llvm-mca/Views/InstructionInfoView.h
@@ -109,4 +109,6 @@ class InstructionInfoView : public InstructionView {
 } // namespace mca
 } // namespace llvm
 
+#undef DEBUG_TYPE
+
 #endif

>From aa7a05a1fbebff785a953c78fbe92ee1b7144d35 Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Wed, 25 Mar 2026 22:49:33 -0700
Subject: [PATCH 2/2] Fix DebugInfo.cpp and Instructions.cpp after
 ConstantsContext.h #undef

Both files were relying on DEBUG_TYPE "ir" leaked from
ConstantsContext.h. Add explicit #define DEBUG_TYPE to each file.
---
 llvm/lib/IR/DebugInfo.cpp    | 4 +++-
 llvm/lib/IR/Instructions.cpp | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index d27c3a9a1548a..122a5151af0b0 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -41,6 +41,8 @@
 #include <cassert>
 #include <optional>
 
+#define DEBUG_TYPE "debug-info"
+
 using namespace llvm;
 using namespace llvm::at;
 using namespace llvm::dwarf;
@@ -2195,7 +2197,7 @@ static void emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest,
   LLVM_DEBUG(if (Assign) errs() << " > INSERT: " << *Assign << "\n");
 }
 
-#undef DEBUG_TYPE // Silence redefinition warning (from ConstantsContext.h).
+#undef DEBUG_TYPE
 #define DEBUG_TYPE "assignment-tracking"
 
 void at::trackAssignments(Function::iterator Start, Function::iterator End,
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 8a220c48acac8..cf396b563d2e8 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -51,6 +51,8 @@
 #include <optional>
 #include <vector>
 
+#define DEBUG_TYPE "instructions"
+
 using namespace llvm;
 
 static cl::opt<bool> DisableI2pP2iOpt(



More information about the llvm-commits mailing list