summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-04-09 14:38:53 +0000
committerPavel Labath <labath@google.com>2018-04-09 14:38:53 +0000
commiteadfac87480b76f2069e41da9b92fe9f745fac8a (patch)
treed8b10e583630f313942e9185271305ccaba73e35
parentc1d6b5e458ed8d9f21b5548ef10c96dbdab9f476 (diff)
downloadbcm5719-llvm-eadfac87480b76f2069e41da9b92fe9f745fac8a.tar.gz
bcm5719-llvm-eadfac87480b76f2069e41da9b92fe9f745fac8a.zip
[CodeGen/AccelTable] Don't emit zero-CU name indexes
Summary: If an input DICompileUnit is completely empty (e.g., the result of running "clang -g" on an empty file), we don't bother emitting an empty DWARF CU. When we do that, we must make sure we don't also emit a DWARF v5 name index, as DWARF specifies that each index must reference at least one compilation unit. Reviewers: JDevlieghere, aprantl, dblaikie Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45435 llvm-svn: 329575
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp2
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp4
-rw-r--r--llvm/test/DebugInfo/Generic/debug-names-empty-cu.ll19
3 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
index d6cfbdb37e5..1107e020696 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
@@ -356,6 +356,8 @@ void AppleAccelTableEmitter::emit() const {
void Dwarf5AccelTableEmitter::Header::emit(
const Dwarf5AccelTableEmitter &Ctx) const {
+ assert(CompUnitCount > 0 && "Index must have at least one CU.");
+
AsmPrinter *Asm = Ctx.Asm;
Asm->OutStreamer->AddComment("Header: unit length");
Asm->EmitLabelDifference(Ctx.ContributionEnd, Ctx.ContributionStart,
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 5cd59b4da9e..177a094b68b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1468,6 +1468,10 @@ void DwarfDebug::emitAccel(AccelTableT &Accel, MCSection *Section,
}
void DwarfDebug::emitAccelDebugNames() {
+ // Don't emit anything if we have no compilation units to index.
+ if (getUnits().empty())
+ return;
+
Asm->OutStreamer->SwitchSection(
Asm->getObjFileLowering().getDwarfDebugNamesSection());
emitDWARF5AccelTable(Asm, AccelDebugNames, *this, getUnits());
diff --git a/llvm/test/DebugInfo/Generic/debug-names-empty-cu.ll b/llvm/test/DebugInfo/Generic/debug-names-empty-cu.ll
new file mode 100644
index 00000000000..d6ccaeca98b
--- /dev/null
+++ b/llvm/test/DebugInfo/Generic/debug-names-empty-cu.ll
@@ -0,0 +1,19 @@
+; REQUIRES: object-emission
+; RUN: %llc_dwarf -accel-tables=Dwarf -filetype=obj -o %t < %s
+; RUN: llvm-dwarfdump -debug-names %t | FileCheck %s
+; RUN: llvm-dwarfdump -debug-names -verify %t | FileCheck --check-prefix=VERIFY %s
+
+; CHECK-NOT: CU count: 0
+; VERIFY: No errors.
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 (trunk 329543) (llvm/trunk 329551)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "-", directory: "/tmp")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 7.0.0 (trunk 329543) (llvm/trunk 329551)"}
OpenPOWER on IntegriCloud