[llvm-branch-commits] [llvm] eea67ba - [llvm-profgen][NFC] Fix test failure by making unwinder's output deterministic

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Dec 7 22:41:49 PST 2020


Author: wlei
Date: 2020-12-07T22:36:25-08:00
New Revision: eea67baf8706d82268d26e908cf5415c5af114ff

URL: https://github.com/llvm/llvm-project/commit/eea67baf8706d82268d26e908cf5415c5af114ff
DIFF: https://github.com/llvm/llvm-project/commit/eea67baf8706d82268d26e908cf5415c5af114ff.diff

LOG: [llvm-profgen][NFC] Fix test failure by making unwinder's output deterministic

Don't know why under Sanitizer build(asan/msan/ubsan), the `std::unordered_map<string, ...>`'s output order is reversed, make the regression test failed.

This change creates a workaround by using sorted container to make the output deterministic.

Reviewed By: hoy, wenlei

Differential Revision: https://reviews.llvm.org/D92816

Added: 
    

Modified: 
    llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
    llvm/tools/llvm-profgen/PerfReader.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
index 649e27e2a131..98767a9b29b7 100644
--- a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
+++ b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
@@ -10,13 +10,14 @@
 ; CHECK: 1: 14
 
 ; CHECK-UNWINDER: Binary(inline-cs-noprobe.perfbin)'s Range Counter:
-; CHECK-UNWINDER: main:1 @ foo:3.2 @ bar
-; CHECK-UNWINDER:   (6af, 6bb): 14
 ; CHECK-UNWINDER: main:1 @ foo
 ; CHECK-UNWINDER:   (670, 6ad): 1
 ; CHECK-UNWINDER:   (67e, 69b): 1
 ; CHECK-UNWINDER:   (67e, 6ad): 13
 ; CHECK-UNWINDER:   (6bd, 6c8): 14
+; CHECK-UNWINDER: main:1 @ foo:3.2 @ bar
+; CHECK-UNWINDER:   (6af, 6bb): 14
+
 
 ; CHECK-UNWINDER: Binary(inline-cs-noprobe.perfbin)'s Branch Counter:
 ; CHECK-UNWINDER: main:1 @ foo

diff  --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index e6625d11fd5f..6a0d54e2de87 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -199,7 +199,10 @@ ProfiledBinary *PerfReader::getBinary(uint64_t Address) {
 }
 
 static void printSampleCounter(ContextRangeCounter &Counter) {
-  for (auto Range : Counter) {
+  // Use ordered map to make the output deterministic
+  std::map<std::string, RangeSample> OrderedCounter(Counter.begin(),
+                                                    Counter.end());
+  for (auto Range : OrderedCounter) {
     outs() << Range.first << "\n";
     for (auto I : Range.second) {
       outs() << "  (" << format("%" PRIx64, I.first.first) << ", "


        


More information about the llvm-branch-commits mailing list