summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp16
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h3
-rw-r--r--llvm/test/DebugInfo/lto-comp-dir.ll4
3 files changed, 17 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 8c499f84936..77765e12f81 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -674,7 +674,8 @@ void DwarfDebug::addGnuPubAttributes(DwarfUnit *U, DIE *D) const {
// Create new DwarfCompileUnit for the given metadata node with tag
// DW_TAG_compile_unit.
-DwarfCompileUnit *DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
+DwarfCompileUnit *DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit,
+ bool Singular) {
StringRef FN = DIUnit.getFilename();
CompilationDir = DIUnit.getDirectory();
@@ -682,8 +683,9 @@ DwarfCompileUnit *DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
DwarfCompileUnit *NewCU = new DwarfCompileUnit(
InfoHolder.getUnits().size(), Die, DIUnit, Asm, this, &InfoHolder);
InfoHolder.addUnit(NewCU);
- Asm->OutStreamer.getContext().setMCLineTableCompilationDir(
- NewCU->getUniqueID(), CompilationDir);
+ if (!Asm->OutStreamer.hasRawTextSupport() || Singular)
+ Asm->OutStreamer.getContext().setMCLineTableCompilationDir(
+ NewCU->getUniqueID(), CompilationDir);
NewCU->addString(Die, dwarf::DW_AT_producer, DIUnit.getProducer());
NewCU->addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
@@ -814,9 +816,13 @@ void DwarfDebug::beginModule() {
// Emit initial sections so we can reference labels later.
emitSectionLabels();
- for (MDNode *N : CU_Nodes->operands()) {
+ auto Operands = CU_Nodes->operands();
+
+ bool SingleCU = std::next(Operands.begin()) == Operands.end();
+
+ for (MDNode *N : Operands) {
DICompileUnit CUNode(N);
- DwarfCompileUnit *CU = constructDwarfCompileUnit(CUNode);
+ DwarfCompileUnit *CU = constructDwarfCompileUnit(CUNode, SingleCU);
DIArray ImportedEntities = CUNode.getImportedEntities();
for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
ScopesWithImportedEntities.push_back(std::make_pair(
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 7f4ed6e290a..71ff75d640a 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -630,7 +630,8 @@ class DwarfDebug : public AsmPrinterHandler {
/// \brief Create new DwarfCompileUnit for the given metadata node with tag
/// DW_TAG_compile_unit.
- DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit);
+ DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit,
+ bool Singular);
/// \brief Construct subprogram DIE.
void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
diff --git a/llvm/test/DebugInfo/lto-comp-dir.ll b/llvm/test/DebugInfo/lto-comp-dir.ll
index 88d6bf56aef..2637171d6a2 100644
--- a/llvm/test/DebugInfo/lto-comp-dir.ll
+++ b/llvm/test/DebugInfo/lto-comp-dir.ll
@@ -1,4 +1,5 @@
; RUN: %llc_dwarf < %s -filetype=obj | llvm-dwarfdump -debug-dump=line - | FileCheck %s
+; RUN: %llc_dwarf < %s -filetype=asm | FileCheck --check-prefix=ASM %s
; CHECK: .debug_line contents:
; CHECK-NEXT: Line table prologue:
@@ -11,6 +12,9 @@
; CHECK: file_names[ 1] 0 {{.*}} b.cpp
; CHECK-NOT: file_names
+; ASM: .file 1 "/tmp/dbginfo/a/a.cpp"
+; ASM: .file 2 "/tmp/dbginfo/b/b.cpp"
+
; Generated from the following source compiled to bitcode from within their
; respective directories (with debug info) and linked together with llvm-link
OpenPOWER on IntegriCloud