Skip to content

Commit 9c5ab4d

Browse files
committed
Redo this. The compile unit iterator has the unhelpful behavior
of skipping entries that are there.
1 parent 7b86e0c commit 9c5ab4d

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,15 @@ void CodeViewDebug::beginModule(Module *M) {
625625
if (Asm->hasDebugInfo()) {
626626
Node = *M->debug_compile_units_begin();
627627
} else {
628-
auto DebugCompileUnits = MMI->getModule()->debug_compile_units();
629-
if (DebugCompileUnits.empty())
630-
return;
631-
632628
// When emitting only compiler information, we may have only NoDebug CUs,
633629
// which would be skipped by debug_compile_units_begin.
634-
Node = *DebugCompileUnits.begin();
630+
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
631+
if (CUs->operands().empty()) {
632+
Asm = nullptr;
633+
return;
634+
}
635+
636+
Node = *CUs->operands().begin();
635637
}
636638
const auto *CU = cast<DICompileUnit>(Node);
637639
DISourceLanguageName Lang = CU->getSourceLanguage();
@@ -903,18 +905,19 @@ void CodeViewDebug::emitCompilerInformation() {
903905
OS.AddComment("CPUType");
904906
OS.emitInt16(static_cast<uint64_t>(TheCPU));
905907

908+
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
909+
906910
StringRef CompilerVersion = "0";
907-
auto CUs = MMI->getModule()->debug_compile_units();
908-
if (!CUs.empty()) {
909-
const MDNode *Node = *CUs.begin();
911+
if (!CUs->operands().empty()) {
912+
const MDNode *Node = *CUs->operands().begin();
910913
const auto *CU = cast<DICompileUnit>(Node);
911-
912914
CompilerVersion = CU->getProducer();
913-
Version FrontVer = parseVersion(CompilerVersion);
914-
OS.AddComment("Frontend version");
915-
for (int N : FrontVer.Part) {
916-
OS.emitInt16(N);
917-
}
915+
}
916+
917+
Version FrontVer = parseVersion(CompilerVersion);
918+
OS.AddComment("Frontend version");
919+
for (int N : FrontVer.Part) {
920+
OS.emitInt16(N);
918921
}
919922

920923
// Some Microsoft tools, like Binscope, expect a backend version number of at
@@ -954,11 +957,8 @@ void CodeViewDebug::emitBuildInfo() {
954957
// not clear if the compiler path should refer to the executable for the
955958
// frontend or the backend. Leave it blank for now.
956959
TypeIndex BuildInfoArgs[BuildInfoRecord::MaxArgs] = {};
957-
auto CUs = MMI->getModule()->debug_compile_units();
958-
if (CUs.empty())
959-
return;
960-
961-
const MDNode *Node = *CUs.begin(); // FIXME: Multiple CUs.
960+
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
961+
const MDNode *Node = *CUs->operands().begin(); // FIXME: Multiple CUs.
962962
const auto *CU = cast<DICompileUnit>(Node);
963963
const DIFile *MainSourceFile = CU->getFile();
964964
BuildInfoArgs[BuildInfoRecord::CurrentDirectory] =

llvm/test/DebugInfo/X86/codeview-empty-dbg-cu-crash.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
; CHECK-NEXT: .short 4412 # Record kind: S_COMPILE3
2020
; CHECK-NEXT: .long 3 # Flags and language
2121
; CHECK-NEXT: .short 208 # CPUType
22+
; CHECK-NEXT: .short 0 # Frontend version
23+
; CHECK-NEXT: .short 0
24+
; CHECK-NEXT: .short 0
25+
; CHECK-NEXT: .short 0
2226
; CHECK-NEXT: .short 22000 # Backend version
2327
; CHECK-NEXT: .short 0
2428
; CHECK-NEXT: .short 0
@@ -28,8 +32,6 @@
2832
; CHECK-NEXT: .Ltmp5:
2933
; CHECK-NEXT: .Ltmp1:
3034
; CHECK-NEXT: .p2align 2, 0x0
31-
; CHECK-NEXT: .cv_filechecksums # File index to string table offset subsection
32-
; CHECK-NEXT: .cv_stringtable # String table
3335

3436
!llvm.dbg.cu = !{}
3537
!llvm.module.flags = !{!0}

0 commit comments

Comments
 (0)