From: Justin Bogner Date: Fri, 4 Dec 2015 23:00:54 +0000 (+0000) Subject: CodeGen: Move the SlotIndexes BumpPtrAllocator before the list it allocates X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=a026cdc11a64e7c87b44d09a53c72fdf9e2163ea CodeGen: Move the SlotIndexes BumpPtrAllocator before the list it allocates When a `SlotIndexes` is destroyed, `ileAllocator` will currently be destructed before `IndexList`, but all of `IndexList`'s storage has been allocated by `ileAllocator`. This means we'll call destructors on garbage data, which is very bad. This can be avoided by putting the BumpPtrAllocator earlier in the class than anything it allocates. Unfortunately, I don't know how to test this. It depends very much on memory layout, and the only evidence I have that this is actually happening in practice are backtraces that might be explained by this. By inspection though, the code is obviously dangerous/wrong, and this is the right thing to do. I'll follow up later with a patch that calls clearAndLeakNodesUnsafely on the list, since there isn't much point in destructing them when they're allocated in a BPA anyway, but I figured it makes sense to commit the correctness fix separately from that optimization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254794 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/SlotIndexes.h b/include/llvm/CodeGen/SlotIndexes.h index bd3a9062fb9..5dc42e20deb 100644 --- a/include/llvm/CodeGen/SlotIndexes.h +++ b/include/llvm/CodeGen/SlotIndexes.h @@ -333,6 +333,8 @@ namespace llvm { /// This pass assigns indexes to each instruction. class SlotIndexes : public MachineFunctionPass { private: + // IndexListEntry allocator. + BumpPtrAllocator ileAllocator; typedef ilist IndexList; IndexList indexList; @@ -353,9 +355,6 @@ namespace llvm { /// and MBB id. SmallVector idx2MBBMap; - // IndexListEntry allocator. - BumpPtrAllocator ileAllocator; - IndexListEntry* createEntry(MachineInstr *mi, unsigned index) { IndexListEntry *entry = static_cast(