[PATCH] D118771: [sanitizer_common] Fix DenseMapCustomTest.DefaultMinReservedSizeTest on SPARC

Rainer Orth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 2 03:42:21 PST 2022


ro created this revision.
ro added a reviewer: vitalybuka.
ro added a project: Sanitizers.
Herald added subscribers: pengfei, fedor.sergeev, jyknight.
ro requested review of this revision.
Herald added a subscriber: Sanitizers.

As described in Issue 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 8kB pagesize.

Fixed by incorporating  the pagesize into calculation of `ExpectedInitialBucketCount` and derived values.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and `x86_64-pc-linux-gnu`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118771

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


Index: compiler-rt/lib/sanitizer_common/tests/sanitizer_dense_map_test.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/tests/sanitizer_dense_map_test.cpp
+++ compiler-rt/lib/sanitizer_common/tests/sanitizer_dense_map_test.cpp
@@ -365,11 +365,10 @@
   EXPECT_NE(M1, M3);
 }
 
+const int ExpectedInitialBucketCount = GetPageSizeCached() / /* sizeof(KV) */ 8;
+
 // Test for the default minimum size of a DenseMap
 TEST(DenseMapCustomTest, DefaultMinReservedSizeTest) {
-  // IF THIS VALUE CHANGE, please update InitialSizeTest, InitFromIterator, and
-  // ReserveTest as well!
-  const int ExpectedInitialBucketCount = 512;
   // Formula from DenseMap::getMinBucketToReserveForEntries()
   const int ExpectedMaxInitialEntries = ExpectedInitialBucketCount * 3 / 4 - 1;
 
@@ -410,9 +409,8 @@
   // Test a few different size, 341 is *not* a random choice: we need a value
   // that is 2/3 of a power of two to stress the grow() condition, and the power
   // of two has to be at least 512 because of minimum size allocation in the
-  // DenseMap (see DefaultMinReservedSizeTest). 513 is a value just above the
-  // 512 default init.
-  for (auto Size : {1, 2, 48, 66, 341, 513}) {
+  // DenseMap (see DefaultMinReservedSizeTest).
+  for (auto Size : {1, 2, 48, 66, 341, ExpectedInitialBucketCount + 1}) {
     DenseMap<int, CountCopyAndMove> Map(Size);
     unsigned MemorySize = Map.getMemorySize();
     CountCopyAndMove::Copy = 0;
@@ -453,9 +451,8 @@
   // Test a few different size, 341 is *not* a random choice: we need a value
   // that is 2/3 of a power of two to stress the grow() condition, and the power
   // of two has to be at least 512 because of minimum size allocation in the
-  // DenseMap (see DefaultMinReservedSizeTest). 513 is a value just above the
-  // 512 default init.
-  for (auto Size : {1, 2, 48, 66, 341, 513}) {
+  // DenseMap (see DefaultMinReservedSizeTest).
+  for (auto Size : {1, 2, 48, 66, 341, ExpectedInitialBucketCount + 1}) {
     DenseMap<int, CountCopyAndMove> Map;
     Map.reserve(Size);
     unsigned MemorySize = Map.getMemorySize();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118771.405197.patch
Type: text/x-patch
Size: 2140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220202/74da7711/attachment.bin>


More information about the llvm-commits mailing list