[compiler-rt] [scudo] Relax MemtagTag.SelectRandomTag. (PR #68048)

Evgenii Stepanov via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 3 13:13:30 PDT 2023


================
@@ -120,7 +120,15 @@ TEST_F(MemtagTest, SelectRandomTag) {
     uptr Tags = 0;
     for (uptr I = 0; I < 100000; ++I)
       Tags = Tags | (1u << extractTag(selectRandomTag(Ptr, 0)));
-    EXPECT_EQ(0xfffeull, Tags);
+    // std::popcnt is C++20
+    int PopCnt = 0;
+    while (Tags) {
+      PopCnt += Tags & 1;
+      Tags >>= 1;
+    }
+    // Random tags are not always very random, and this test is not about PRNG
+    // quality.  Anything above half would be satisfactory.
+    EXPECT_GE(PopCnt, 8);
----------------
eugenis wrote:

I'd rather not create a potential compiler dependency to save 2 lines of code in a test.

https://github.com/llvm/llvm-project/pull/68048


More information about the llvm-commits mailing list