aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DIBuilder.cpp
diff options
context:
space:
mode:
authorVladislav Dzhidzhoev <vdzhidzhoev@accesssoftek.com>2024-01-11 17:08:12 +0100
committerGitHub <noreply@github.com>2024-01-11 17:08:12 +0100
commitfc6faa1113e9069f41b5500db051210af0eea843 (patch)
tree105a76fe962bf21897f044fb563d7b5abd83a226 /llvm/lib/IR/DIBuilder.cpp
parent31ce0f1dda3caed829db09b9212eac54a8a28572 (diff)
downloadllvm-fc6faa1113e9069f41b5500db051210af0eea843.zip
llvm-fc6faa1113e9069f41b5500db051210af0eea843.tar.gz
llvm-fc6faa1113e9069f41b5500db051210af0eea843.tar.bz2
[CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (#75385)
- [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7) - [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions This is a follow-up for https://reviews.llvm.org/D144006, fixing a crash reported in Chromium (https://reviews.llvm.org/D144006#4651955). The first commit is added for convenience, as it has already been accepted. If DISubpogram was not cloned (e.g. we are cloning a function that has other functions inlined into it, and subprograms of the inlined functions are not supposed to be cloned), it doesn't make sense to clone its DILocalVariables as well. Otherwise get duplicated DILocalVariables not tracked in their subprogram's retainedNodes, that crash LTO with Chromium. This is meant to be committed along with https://reviews.llvm.org/D144006.
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r--llvm/lib/IR/DIBuilder.cpp39
1 files changed, 28 insertions, 11 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 62efaba..4125ab6 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())
- CUNode->replaceEnumTypes(MDTuple::get(
- VMContext, SmallVector<Metadata *, 16>(AllEnumTypes.begin(),
- AllEnumTypes.end())));
+ if (!EnumTypes.empty())
+ CUNode->replaceEnumTypes(
+ MDTuple::get(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, RunTimeLang, 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;
}
@@ -546,7 +555,10 @@ DIBuilder::createEnumerationType(DIScope *Scope, StringRef Name, DIFile *File,
getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements,
RunTimeLang, 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;
}
@@ -627,7 +639,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; }
@@ -644,6 +657,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;
}
@@ -660,6 +675,8 @@ DICompositeType *DIBuilder::createReplaceableCompositeType(
nullptr, Annotations)
.release();
trackIfUnresolved(RetTy);
+ if (isa_and_nonnull<DILocalScope>(Scope))
+ getSubprogramNodesTrackingVector(Scope).emplace_back(RetTy);
return RetTy;
}