Index: Simple.h =================================================================== --- Simple.h +++ Simple.h @@ -175,10 +175,23 @@ } lld::SimpleReference *createSentinel() const { + // absence of allocator generally is not an issue. That might be useful for + // ilists of SimpleReferences created as temporatily local objects. + // They dont need to be allocated via BumpPtrAllocator + if (!_allocator) { + return new lld::SimpleReference(); + } + return new (*_allocator) lld::SimpleReference(); } - static void destroySentinel(lld::SimpleReference*) {} + void destroySentinel(lld::SimpleReference *sentinel) { + // the same situation as described above in createSentinel() + // there is no BumpPtrAllocator allocator sometimes and its fine. + if (!_allocator) { + delete sentinel; + } + } static lld::SimpleReference *provideInitialHead() { return nullptr; } @@ -267,28 +280,17 @@ /// Sort references in a canonical order (by offset, then by kind). void sortReferences() const { - // Cannot sort a linked list, so move elements into a temporary vector, - // sort the vector, then reconstruct the list. - llvm::SmallVector elements; - for (SimpleReference &node : _references) { - elements.push_back(&node); - } - std::sort(elements.begin(), elements.end(), - [] (const SimpleReference *lhs, const SimpleReference *rhs) -> bool { - uint64_t lhsOffset = lhs->offsetInAtom(); - uint64_t rhsOffset = rhs->offsetInAtom(); - if (rhsOffset != lhsOffset) - return (lhsOffset < rhsOffset); - if (rhs->kindNamespace() != lhs->kindNamespace()) - return (lhs->kindNamespace() < rhs->kindNamespace()); - if (rhs->kindArch() != lhs->kindArch()) - return (lhs->kindArch() < rhs->kindArch()); - return (lhs->kindValue() < rhs->kindValue()); - }); - _references.clearAndLeakNodesUnsafely(); - for (SimpleReference *node : elements) { - _references.push_back(node); - } + _references.sort([](SimpleReference &lhs, SimpleReference &rhs) -> bool { + uint64_t lhsOffset = lhs.offsetInAtom(); + uint64_t rhsOffset = rhs.offsetInAtom(); + if (rhsOffset != lhsOffset) + return (lhsOffset < rhsOffset); + if (rhs.kindNamespace() != lhs.kindNamespace()) + return (lhs.kindNamespace() < rhs.kindNamespace()); + if (rhs.kindArch() != lhs.kindArch()) + return (lhs.kindArch() < rhs.kindArch()); + return (lhs.kindValue() < rhs.kindValue()); + }); } void setOrdinal(uint64_t ord) { _ordinal = ord; }