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 b672e792f2
commit 5b78308689
1 changed files with 6 additions and 2 deletions

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);
}
}