Skip to content

Commit 86588db

Browse files
committed
Emit abstract subprogram DIE referenced from a global variable in the correct CU.
1 parent 6897990 commit 86588db

File tree

4 files changed

+66
-8
lines changed

4 files changed

+66
-8
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,8 +1836,12 @@ DIE *DwarfCompileUnit::getOrCreateSubprogramDIE(const DISubprogram *SP,
18361836
if (!F && SP->isDefinition()) {
18371837
F = DD->getLexicalScopes().getFunction(SP);
18381838

1839-
if (!F)
1840-
return &getCU().getOrCreateAbstractSubprogramDIE(SP);
1839+
if (!F) {
1840+
// SP may belong to another CU. Determine the CU similarly
1841+
// to DwarfDebug::constructAbstractSubprogramScopeDIE.
1842+
return &DD->getOrCreateAbstractSubprogramCU(SP, *this)
1843+
.getOrCreateAbstractSubprogramDIE(SP);
1844+
}
18411845
}
18421846

18431847
return DwarfUnit::getOrCreateSubprogramDIE(SP, F, Minimal);

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,16 @@ bool DwarfDebug::shareAcrossDWOCUs() const {
548548
return SplitDwarfCrossCuReferences;
549549
}
550550

551+
DwarfCompileUnit &
552+
DwarfDebug::getOrCreateAbstractSubprogramCU(const DISubprogram *SP,
553+
DwarfCompileUnit &SrcCU) {
554+
auto &CU = getOrCreateDwarfCompileUnit(SP->getUnit());
555+
if (CU.getSkeleton())
556+
return shareAcrossDWOCUs() ? CU : SrcCU;
557+
558+
return CU;
559+
}
560+
551561
void DwarfDebug::constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU,
552562
LexicalScope *Scope) {
553563
assert(Scope && Scope->getScopeNode());
@@ -559,14 +569,11 @@ void DwarfDebug::constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU,
559569
// Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
560570
// was inlined from another compile unit.
561571
auto &CU = getOrCreateDwarfCompileUnit(SP->getUnit());
562-
if (auto *SkelCU = CU.getSkeleton()) {
563-
(shareAcrossDWOCUs() ? CU : SrcCU)
564-
.constructAbstractSubprogramScopeDIE(Scope);
572+
auto &TargetCU = getOrCreateAbstractSubprogramCU(SP, SrcCU);
573+
TargetCU.constructAbstractSubprogramScopeDIE(Scope);
574+
if (auto *SkelCU = CU.getSkeleton())
565575
if (CU.getCUNode()->getSplitDebugInlining())
566576
SkelCU->constructAbstractSubprogramScopeDIE(Scope);
567-
} else {
568-
CU.constructAbstractSubprogramScopeDIE(Scope);
569-
}
570577
}
571578

572579
/// Represents a parameter whose call site value can be described by applying a

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,10 @@ class DwarfDebug : public DebugHandlerBase {
906906
return CUDieMap.lookup(Die);
907907
}
908908

909+
/// Find the matching DwarfCompileUnit for the given SP referenced from SrcCU.
910+
DwarfCompileUnit &getOrCreateAbstractSubprogramCU(const DISubprogram *SP,
911+
DwarfCompileUnit &SrcCU);
912+
909913
unsigned getStringTypeLoc(const DIStringType *ST) const {
910914
return StringTypeLocMap.lookup(ST);
911915
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
; RUN: llc --filetype=obj -O0 -o - %s | llvm-dwarfdump --verify -
2+
3+
; Check that abstract DIE for a subprogram referenced from another compile unit
4+
; is emitted in the correct CU.
5+
6+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
7+
target triple = "aarch64"
8+
9+
define void @a() !dbg !10 {
10+
br label %for.b.c.c, !dbg !13
11+
for.b.c.c:
12+
br label %for.b.c.c
13+
}
14+
15+
!llvm.dbg.cu = !{!0, !6}
16+
!llvm.module.flags = !{!8}
17+
18+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_20, file: !1, emissionKind: FullDebug, globals: !2)
19+
!1 = !DIFile(filename: "foo.cpp", directory: "")
20+
!2 = !{!3}
21+
!3 = !DIGlobalVariableExpression(var: !4, expr: !DIExpression())
22+
!4 = !DIGlobalVariable(type: !5)
23+
!5 = !DICompositeType(tag: DW_TAG_class_type)
24+
!6 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_20, file: !7, emissionKind: FullDebug)
25+
!7 = !DIFile(filename: "bar.cpp", directory: "")
26+
!8 = !{i32 2, !"Debug Info Version", i32 3}
27+
!10 = distinct !DISubprogram(type: !11, unit: !6)
28+
!11 = !DISubroutineType(types: !12)
29+
!12 = !{}
30+
!13 = !DILocation(scope: !14, inlinedAt: !15)
31+
!14 = distinct !DISubprogram(unit: !6)
32+
!15 = !DILocation(scope: !16, inlinedAt: !25)
33+
!16 = distinct !DISubprogram(type: !11, unit: !6, declaration: !17)
34+
!17 = !DISubprogram(scope: !5, type: !11, spFlags: DISPFlagOptimized, templateParams: !18)
35+
!18 = !{!19}
36+
!19 = !DITemplateTypeParameter(type: !20)
37+
!20 = !DICompositeType(tag: DW_TAG_class_type, scope: !21)
38+
!21 = distinct !DISubprogram(unit: !6, retainedNodes: !22)
39+
!22 = !{!23}
40+
!23 = !DILocalVariable(scope: !21, type: !24)
41+
!24 = !DIBasicType()
42+
!25 = !DILocation(scope: !21, inlinedAt: !26)
43+
!26 = !DILocation(scope: !10)

0 commit comments

Comments
 (0)