Stabilize the output of the dwarf accelerator tables. Fixes a comparison
authorEric Christopher <echristo@apple.com>
Tue, 15 Nov 2011 23:37:17 +0000 (23:37 +0000)
committerEric Christopher <echristo@apple.com>
Tue, 15 Nov 2011 23:37:17 +0000 (23:37 +0000)
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

index a3a24887615eab7a8ccd3eb0228c7cb314490178..6c77a631a924e6dc3339febec975defd4277a855 100644 (file)
@@ -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<uint32_t>::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<DIEArray>::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());