diff options
author | Kristina Bessonova <kbessonova@accesssoftek.com> | 2022-11-03 10:27:10 +0200 |
---|---|---|
committer | Kristina Bessonova <kbessonova@accesssoftek.com> | 2022-11-03 10:28:38 +0200 |
commit | 4ecb2b8ef6be69b55d46ac274f3b7a7103219f98 (patch) | |
tree | daa66fe38ca5dd5388b57d6e32d844695f03a5fb /llvm/lib/IR/DIBuilder.cpp | |
parent | 9135137718bbb8322dc42a1026ce3f843bbeacc6 (diff) | |
download | llvm-4ecb2b8ef6be69b55d46ac274f3b7a7103219f98.zip llvm-4ecb2b8ef6be69b55d46ac274f3b7a7103219f98.tar.gz llvm-4ecb2b8ef6be69b55d46ac274f3b7a7103219f98.tar.bz2 |
[DebugInfo][Metadata] Make AllEnumTypes holding TrackingMDNodeRef
Having AllEnumtypes to be a vector of TrackingMDNodeRef makes it possible
to reflect changes in metadata in the vector if they took place before DIBuilder
being finalized.
Otherwise, we end up with heap-use-after-free because AllEnumTypes contains
metadata that no longer valid.
Consider a case where we have a class containing a definition of a enum,
so this enum has the class as a scope. For some reason (doesn't matter for
the current issue), we create a temporary debug metadata for this class, and
then resolve it while finalizing CGDebugInfo.
In the case of collision during uniqifying the temporary, we then need
to replace its uses with a new pointer. If a temporary's user is unique
(this is the enum mentioned above), we may need re-uniquefying it,
which may return a new pointer in the case of another collision.
If so, the pointer we stored in AllEnumTypes vector become dangling.
Making AllEnumTypes hodling TrackingMDNodeRef should solve this problem
(see debug-info-enum-metadata-collision.cpp test for details).
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D137067
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r-- | llvm/lib/IR/DIBuilder.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index fada07a..76d7ade 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -84,7 +84,9 @@ void DIBuilder::finalize() { } if (!AllEnumTypes.empty()) - CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes)); + CUNode->replaceEnumTypes(MDTuple::get( + VMContext, SmallVector<Metadata *, 16>(AllEnumTypes.begin(), + AllEnumTypes.end()))); SmallVector<Metadata *, 16> RetainValues; // Declarations and definitions of the same type may be retained. Some @@ -556,7 +558,7 @@ DICompositeType *DIBuilder::createEnumerationType( getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0, IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, nullptr, nullptr, UniqueIdentifier); - AllEnumTypes.push_back(CTy); + AllEnumTypes.emplace_back(CTy); trackIfUnresolved(CTy); return CTy; } |