Skip to content

Commit 0d4b6f1

Browse files
committed
[sanitizer_common] Fix DenseMapCustomTest.DefaultMinReservedSizeTest on SPARC
As described in Issue llvm#53523, the `DenseMapCustomTest.DefaultMinReservedSizeTest` test FAILs on Solaris/SPARC (both 32 and 64-bit): /vol/llvm/src/llvm-project/local/compiler-rt/lib/sanitizer_common/tests/sanitizer_dense_map_test.cpp:399: Failure Expected: (MemorySize) != (Map.getMemorySize()), actual: 8192 vs 8192 This happens because SPARC, unlike many other CPUs, uses an 8 kB pagesize. Fixed by incorporating the pagesize into the calculations of `ExpectedInitialBucketCount` and derived values. Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and `x86_64-pc-linux-gnu`. Differential Revision: https://reviews.llvm.org/D118771
1 parent 7cca34a commit 0d4b6f1

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

compiler-rt/lib/sanitizer_common/tests/sanitizer_dense_map_test.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,10 @@ TEST(DenseMapCustomTest, EqualityComparison) {
365365
EXPECT_NE(M1, M3);
366366
}
367367

368+
const int ExpectedInitialBucketCount = GetPageSizeCached() / /* sizeof(KV) */ 8;
369+
368370
// Test for the default minimum size of a DenseMap
369371
TEST(DenseMapCustomTest, DefaultMinReservedSizeTest) {
370-
// IF THIS VALUE CHANGE, please update InitialSizeTest, InitFromIterator, and
371-
// ReserveTest as well!
372-
const int ExpectedInitialBucketCount = 512;
373372
// Formula from DenseMap::getMinBucketToReserveForEntries()
374373
const int ExpectedMaxInitialEntries = ExpectedInitialBucketCount * 3 / 4 - 1;
375374

@@ -410,9 +409,8 @@ TEST(DenseMapCustomTest, InitialSizeTest) {
410409
// Test a few different size, 341 is *not* a random choice: we need a value
411410
// that is 2/3 of a power of two to stress the grow() condition, and the power
412411
// of two has to be at least 512 because of minimum size allocation in the
413-
// DenseMap (see DefaultMinReservedSizeTest). 513 is a value just above the
414-
// 512 default init.
415-
for (auto Size : {1, 2, 48, 66, 341, 513}) {
412+
// DenseMap (see DefaultMinReservedSizeTest).
413+
for (auto Size : {1, 2, 48, 66, 341, ExpectedInitialBucketCount + 1}) {
416414
DenseMap<int, CountCopyAndMove> Map(Size);
417415
unsigned MemorySize = Map.getMemorySize();
418416
CountCopyAndMove::Copy = 0;
@@ -453,9 +451,8 @@ TEST(DenseMapCustomTest, ReserveTest) {
453451
// Test a few different size, 341 is *not* a random choice: we need a value
454452
// that is 2/3 of a power of two to stress the grow() condition, and the power
455453
// of two has to be at least 512 because of minimum size allocation in the
456-
// DenseMap (see DefaultMinReservedSizeTest). 513 is a value just above the
457-
// 512 default init.
458-
for (auto Size : {1, 2, 48, 66, 341, 513}) {
454+
// DenseMap (see DefaultMinReservedSizeTest).
455+
for (auto Size : {1, 2, 48, 66, 341, ExpectedInitialBucketCount + 1}) {
459456
DenseMap<int, CountCopyAndMove> Map;
460457
Map.reserve(Size);
461458
unsigned MemorySize = Map.getMemorySize();

0 commit comments

Comments
 (0)