aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DIBuilder.cpp
diff options
context:
space:
mode:
authorVladislav Dzhidzhoev <vdzhidzhoev@accesssoftek.com>2023-07-18 14:22:46 +0200
committerVladislav Dzhidzhoev <vdzhidzhoev@accesssoftek.com>2023-11-02 17:44:52 +0100
commit3b449bd46a11a55a40cbc0016a99b202fa05248e (patch)
tree2f43becc4e0cd830b15db5c075ff5b9c6a378610 /llvm/lib/IR/DIBuilder.cpp
parent98bd0d9dd2da0edec15b5eb7acb480c47c4594cc (diff)
downloadllvm-3b449bd46a11a55a40cbc0016a99b202fa05248e.zip
llvm-3b449bd46a11a55a40cbc0016a99b202fa05248e.tar.gz
llvm-3b449bd46a11a55a40cbc0016a99b202fa05248e.tar.bz2
[DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)
RFC https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544 Similar to imported declarations, the patch tracks function-local types in DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with the aforementioned metadata change and provided a support of function-local types scoped within a lexical block. The patch assumes that DICompileUnit's 'enums field' no longer tracks local types and DwarfDebug would assert if any locally-scoped types get placed there. Reviewed By: jmmartinez Authored-by: Kristina Bessonova <kbessonova@accesssoftek.com> Differential Revision: https://reviews.llvm.org/D144006
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r--llvm/lib/IR/DIBuilder.cpp37
1 files changed, 27 insertions, 10 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 1ce8c17..d3e618b 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -31,7 +31,7 @@ DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU)
AllowUnresolvedNodes(AllowUnresolvedNodes) {
if (CUNode) {
if (const auto &ETs = CUNode->getEnumTypes())
- AllEnumTypes.assign(ETs.begin(), ETs.end());
+ EnumTypes.assign(ETs.begin(), ETs.end());
if (const auto &RTs = CUNode->getRetainedTypes())
AllRetainTypes.assign(RTs.begin(), RTs.end());
if (const auto &GVs = CUNode->getGlobalVariables())
@@ -68,10 +68,10 @@ void DIBuilder::finalize() {
return;
}
- if (!AllEnumTypes.empty())
+ if (!EnumTypes.empty())
CUNode->replaceEnumTypes(MDTuple::get(
- VMContext, SmallVector<Metadata *, 16>(AllEnumTypes.begin(),
- AllEnumTypes.end())));
+ VMContext, SmallVector<Metadata *, 16>(EnumTypes.begin(),
+ EnumTypes.end())));
SmallVector<Metadata *, 16> RetainValues;
// Declarations and definitions of the same type may be retained. Some
@@ -336,10 +336,13 @@ DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name,
DIScope *Context, uint32_t AlignInBits,
DINode::DIFlags Flags,
DINodeArray Annotations) {
- return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
- LineNo, getNonCompileUnitScope(Context), Ty, 0,
- AlignInBits, 0, std::nullopt, Flags, nullptr,
- Annotations);
+ auto *T =
+ DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File, LineNo,
+ getNonCompileUnitScope(Context), Ty, 0, AlignInBits, 0,
+ std::nullopt, Flags, nullptr, Annotations);
+ if (isa_and_nonnull<DILocalScope>(Context))
+ getSubprogramNodesTrackingVector(Context).emplace_back(T);
+ return T;
}
DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) {
@@ -487,6 +490,8 @@ DICompositeType *DIBuilder::createClassType(
OffsetInBits, Flags, Elements, 0, VTableHolder,
cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
trackIfUnresolved(R);
+ if (isa_and_nonnull<DILocalScope>(Context))
+ getSubprogramNodesTrackingVector(Context).emplace_back(R);
return R;
}
@@ -500,6 +505,8 @@ DICompositeType *DIBuilder::createStructType(
getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier);
trackIfUnresolved(R);
+ if (isa_and_nonnull<DILocalScope>(Context))
+ getSubprogramNodesTrackingVector(Context).emplace_back(R);
return R;
}
@@ -512,6 +519,8 @@ DICompositeType *DIBuilder::createUnionType(
getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier);
trackIfUnresolved(R);
+ if (isa_and_nonnull<DILocalScope>(Scope))
+ getSubprogramNodesTrackingVector(Scope).emplace_back(R);
return R;
}
@@ -544,7 +553,10 @@ DICompositeType *DIBuilder::createEnumerationType(
getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, nullptr,
nullptr, UniqueIdentifier);
- AllEnumTypes.emplace_back(CTy);
+ if (isa_and_nonnull<DILocalScope>(Scope))
+ getSubprogramNodesTrackingVector(Scope).emplace_back(CTy);
+ else
+ EnumTypes.emplace_back(CTy);
trackIfUnresolved(CTy);
return CTy;
}
@@ -625,7 +637,8 @@ void DIBuilder::retainType(DIScope *T) {
assert((isa<DIType>(T) || (isa<DISubprogram>(T) &&
cast<DISubprogram>(T)->isDefinition() == false)) &&
"Expected type or subprogram declaration");
- AllRetainTypes.emplace_back(T);
+ if (!isa_and_nonnull<DILocalScope>(T->getScope()))
+ AllRetainTypes.emplace_back(T);
}
DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; }
@@ -642,6 +655,8 @@ DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope,
SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
nullptr, nullptr, UniqueIdentifier);
trackIfUnresolved(RetTy);
+ if (isa_and_nonnull<DILocalScope>(Scope))
+ getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
return RetTy;
}
@@ -658,6 +673,8 @@ DICompositeType *DIBuilder::createReplaceableCompositeType(
nullptr, Annotations)
.release();
trackIfUnresolved(RetTy);
+ if (isa_and_nonnull<DILocalScope>(Scope))
+ getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
return RetTy;
}