1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

Add optional allocator to YAML code to avoid leaking lld atoms.

In lld we allocate atoms on an allocator and so don't run their
destructors.  This means we also shouldn't allocate memory inside
them without that also being on an allocator.

Reviewed by Lang Hames and Rafael Espindola.

llvm-svn: 263676
This commit is contained in:
Pete Cooper 2016-03-16 23:29:31 +00:00
parent 06bf736d1f
commit b5fd804a2c

View File

@ -894,12 +894,16 @@ private:
// to [de]normalize an object for use with YAML conversion.
template <typename TNorm, typename TFinal>
struct MappingNormalizationHeap {
MappingNormalizationHeap(IO &i_o, TFinal &Obj)
MappingNormalizationHeap(IO &i_o, TFinal &Obj,
llvm::BumpPtrAllocator *allocator = nullptr)
: io(i_o), BufPtr(nullptr), Result(Obj) {
if ( io.outputting() ) {
BufPtr = new (&Buffer) TNorm(io, Obj);
}
else {
else if (allocator) {
BufPtr = allocator->Allocate<TNorm>();
new (BufPtr) TNorm(io);
} else {
BufPtr = new TNorm(io);
}
}