[llvm] 4b31ad9 - [UEFI] Codeview do not crash when no llvm.dbg.cu (#174460)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 6 09:52:29 PST 2026
Author: Prabhu Rajasekaran
Date: 2026-01-06T09:52:24-08:00
New Revision: 4b31ad94e0da77692da577caf5b330bb599cd4bd
URL: https://github.com/llvm/llvm-project/commit/4b31ad94e0da77692da577caf5b330bb599cd4bd
DIFF: https://github.com/llvm/llvm-project/commit/4b31ad94e0da77692da577caf5b330bb599cd4bd.diff
LOG: [UEFI] Codeview do not crash when no llvm.dbg.cu (#174460)
PR #142970 Added for Windows targets to emit minimal codeview metadata
even when debug info is disabled. This crashes the backend for UEFI
x86_64-uefi triple as llvm.dbg.cu is expected unconditionally there.
Handling it correctly in AsmPrinter and adding a regression test.
Added:
llvm/test/DebugInfo/X86/uefi-no-codeview-crash.ll
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index dae31a3e2fac5..d96294e06d579 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -593,8 +593,8 @@ bool AsmPrinter::doInitialization(Module &M) {
bool EmitCodeView = M.getCodeViewFlag();
// On Windows targets, emit minimal CodeView compiler info even when debug
// info is disabled.
- if ((Target.isOSWindows() && M.getNamedMetadata("llvm.dbg.cu")) ||
- (Target.isUEFI() && EmitCodeView))
+ if ((Target.isOSWindows() || (Target.isUEFI() && EmitCodeView)) &&
+ M.getNamedMetadata("llvm.dbg.cu"))
Handlers.push_back(std::make_unique<CodeViewDebug>(this));
if (!EmitCodeView || M.getDwarfVersion()) {
if (hasDebugInfo()) {
diff --git a/llvm/test/DebugInfo/X86/uefi-no-codeview-crash.ll b/llvm/test/DebugInfo/X86/uefi-no-codeview-crash.ll
new file mode 100644
index 0000000000000..37ef201313ed6
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/uefi-no-codeview-crash.ll
@@ -0,0 +1,15 @@
+;; This test ensures that the backend does not crash when CodeView is enabled
+;; through module flags but llvm.dbg.cu is missing.
+
+; RUN: llc < %s -mtriple=x86_64-unknown-uefi | FileCheck %s
+
+define void @foo() {
+entry:
+ ret void
+}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 2, !"CodeView", i32 1}
+
+; CHECK-LABEL: foo:
+; CHECK: retq
More information about the llvm-commits
mailing list