[PATCH] D19227: [msan] Don't hardcode 4kiB page size in msan_test.cc.

Marcin Koƛcielnicki via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 18 15:26:37 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL266688: [msan] Don't hardcode 4kiB page size in msan_test.cc. (authored by koriakin).

Changed prior to commit:
  http://reviews.llvm.org/D19227?vs=54073&id=54127#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19227

Files:
  compiler-rt/trunk/lib/msan/tests/msan_test.cc

Index: compiler-rt/trunk/lib/msan/tests/msan_test.cc
===================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc
@@ -115,7 +115,14 @@
 # define SUPERUSER_GROUP "root"
 #endif
 
-const size_t kPageSize = 4096;
+// We cannot include sanitizer_common.h (it conflicts with public interface
+// headers), so just pull this function directly.
+
+namespace __sanitizer {
+uintptr_t GetPageSizeCached();
+}
+using __sanitizer::GetPageSizeCached;
+
 const size_t kMaxPathLength = 4096;
 
 typedef unsigned char      U1;
@@ -3225,28 +3232,30 @@
 #if !defined(__FreeBSD__)
 TEST(MemorySanitizer, memalign) {
   void *p = memalign(4096, 13);
-  EXPECT_EQ(0U, (uintptr_t)p % kPageSize);
+  EXPECT_EQ(0U, (uintptr_t)p % 4096);
   free(p);
 }
 #endif
 
 TEST(MemorySanitizer, valloc) {
   void *a = valloc(100);
-  EXPECT_EQ(0U, (uintptr_t)a % kPageSize);
+  uintptr_t PageSize = GetPageSizeCached();
+  EXPECT_EQ(0U, (uintptr_t)a % PageSize);
   free(a);
 }
 
 // There's no pvalloc() on FreeBSD.
 #if !defined(__FreeBSD__)
 TEST(MemorySanitizer, pvalloc) {
-  void *p = pvalloc(kPageSize + 100);
-  EXPECT_EQ(0U, (uintptr_t)p % kPageSize);
-  EXPECT_EQ(2 * kPageSize, __sanitizer_get_allocated_size(p));
+  uintptr_t PageSize = GetPageSizeCached();
+  void *p = pvalloc(PageSize + 100);
+  EXPECT_EQ(0U, (uintptr_t)p % PageSize);
+  EXPECT_EQ(2 * PageSize, __sanitizer_get_allocated_size(p));
   free(p);
 
   p = pvalloc(0);  // pvalloc(0) should allocate at least one page.
-  EXPECT_EQ(0U, (uintptr_t)p % kPageSize);
-  EXPECT_EQ(kPageSize, __sanitizer_get_allocated_size(p));
+  EXPECT_EQ(0U, (uintptr_t)p % PageSize);
+  EXPECT_EQ(PageSize, __sanitizer_get_allocated_size(p));
   free(p);
 }
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19227.54127.patch
Type: text/x-patch
Size: 1800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160418/878f0dcb/attachment.bin>


More information about the llvm-commits mailing list