[compiler-rt] [scudo] Relax MemtagTag.SelectRandomTag. (PR #68048)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 2 15:51:03 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
<details>
<summary>Changes</summary>
As it turns out, PRNGs have varying quality.
Relax the test to accept less-then-perfect tag distribution.
---
Full diff: https://github.com/llvm/llvm-project/pull/68048.diff
1 Files Affected:
- (modified) compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp (+9-1)
``````````diff
diff --git a/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp b/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp
index 2488e04856bd972..fd277f962a9aaac 100644
--- a/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp
@@ -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);
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/68048
More information about the llvm-commits
mailing list