From 8368f74c434db60c36a4044dfe80d4abee49ce27 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Tue, 15 Nov 2011 23:37:17 +0000 Subject: [PATCH] Stabilize the output of the dwarf accelerator tables. Fixes a comparison failure during bootstrap with it turned on. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144731 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp b/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp index a3a24887615..6c77a631a92 100644 --- a/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp @@ -60,7 +60,7 @@ void DwarfAccelTable::ComputeBucketCount(void) { uniques.resize(Data.size()); for (size_t i = 0, e = Data.size(); i < e; ++i) uniques[i] = Data[i]->HashValue; - std::sort(uniques.begin(), uniques.end()); + std::stable_sort(uniques.begin(), uniques.end()); std::vector::iterator p = std::unique(uniques.begin(), uniques.end()); uint32_t num = std::distance(uniques.begin(), p); @@ -73,6 +73,15 @@ void DwarfAccelTable::ComputeBucketCount(void) { Header.hashes_count = num; } +namespace { + // DIESorter - comparison predicate that sorts DIEs by their offset. + struct DIESorter { + bool operator()(DIE *A, DIE *B) const { + return A->getOffset() < B->getOffset(); + } + }; +} + void DwarfAccelTable::FinalizeTable(AsmPrinter *Asm, const char *Prefix) { // Create the individual hash data outputs. for (StringMap::iterator @@ -80,7 +89,7 @@ void DwarfAccelTable::FinalizeTable(AsmPrinter *Asm, const char *Prefix) { struct HashData *Entry = new HashData((*EI).getKeyData()); // Unique the entries. - std::sort((*EI).second.begin(), (*EI).second.end()); + std::stable_sort((*EI).second.begin(), (*EI).second.end(), DIESorter()); (*EI).second.erase(std::unique((*EI).second.begin(), (*EI).second.end()), (*EI).second.end()); -- 2.11.0