aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorJeremy Morse <jeremy.morse@sony.com>2021-01-27 12:29:12 +0000
committerJeremy Morse <jeremy.morse@sony.com>2021-01-27 12:36:14 +0000
commitef0dcb506300dc9644e8000c6028d14214be9d97 (patch)
treebdfcdfc84a9ccaa02df283b9f109abb20fe99728 /llvm/lib
parentd7cc3a083fcea8c954702973eb6573732314b74a (diff)
downloadllvm-ef0dcb506300dc9644e8000c6028d14214be9d97.zip
llvm-ef0dcb506300dc9644e8000c6028d14214be9d97.tar.gz
llvm-ef0dcb506300dc9644e8000c6028d14214be9d97.tar.bz2
[DWARF] Create subprogram's DIE in DISubprogram's unit
This is a fix for PR48790. Over in D70350, subprogram DIEs were permitted to be shared between CUs. However, the creation of a subprogram DIE can be triggered early, from other CUs. The subprogram definition is then created in one CU, and when the function is actually emitted children are attached to the subprogram that expect to be in another CU. This breaks internal CU references in the children. Fix this by redirecting the creation of subprogram DIEs in getOrCreateContextDIE to the CU specified by it's DISubprogram definition. This ensures that the subprogram DIE is always created in the correct CU. Differential Revision: https://reviews.llvm.org/D94976
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h6
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp9
2 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index df19ef4..e082b11 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -465,9 +465,6 @@ private:
/// Construct a DIE for this abstract scope.
void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);
- /// Construct a DIE for the subprogram definition \p SP and return it.
- DIE &constructSubprogramDefinitionDIE(const DISubprogram *SP);
-
/// Construct DIEs for call site entries describing the calls in \p MF.
void constructCallSiteEntryDIEs(const DISubprogram &SP, DwarfCompileUnit &CU,
DIE &ScopeDIE, const MachineFunction &MF);
@@ -759,6 +756,9 @@ public:
/// * DW_FORM_data4 for 32-bit DWARFv3 and DWARFv2.
dwarf::Form getDwarfSectionOffsetForm() const;
+ /// Construct a DIE for the subprogram definition \p SP and return it.
+ DIE &constructSubprogramDefinitionDIE(const DISubprogram *SP);
+
/// Returns the previous CU that was being updated
const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 118b5fc..46161e7 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -521,8 +521,13 @@ DIE *DwarfUnit::getOrCreateContextDIE(const DIScope *Context) {
return getOrCreateTypeDIE(T);
if (auto *NS = dyn_cast<DINamespace>(Context))
return getOrCreateNameSpace(NS);
- if (auto *SP = dyn_cast<DISubprogram>(Context))
- return getOrCreateSubprogramDIE(SP);
+ if (auto *SP = dyn_cast<DISubprogram>(Context)) {
+ // Subprogram definitions should be created in the Unit that they specify,
+ // which might not be "this" unit when type definitions move around under
+ // LTO.
+ assert(SP->isDefinition());
+ return &DD->constructSubprogramDefinitionDIE(SP);
+ }
if (auto *M = dyn_cast<DIModule>(Context))
return getOrCreateModule(M);
return getDIE(Context);