Bug 1024318 - Fix warnings in mfbt/tests/ and mark as FAIL_ON_WARNINGS. r=Waldo
authorChris Peterson <cpeterson@mozilla.com>
Sat, 14 Jun 2014 12:47:01 -0700
changeset 209558 315b89ffbe126c61f653cb54957d5ab3f475c45c
parent 209557 d5a6e235e674eeba12c0d48314233b7985b0d8e2
child 209559 057973613987672beacba1843afb30bb2f466623
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1024318
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1024318 - Fix warnings in mfbt/tests/ and mark as FAIL_ON_WARNINGS. r=Waldo
mfbt/TypeTraits.h
mfbt/tests/TestBinarySearch.cpp
mfbt/tests/TestEndian.cpp
mfbt/tests/TestPoisonArea.cpp
mfbt/tests/moz.build
--- a/mfbt/TypeTraits.h
+++ b/mfbt/TypeTraits.h
@@ -389,25 +389,27 @@ struct IsEmptyHelper
  */
 template<typename T>
 struct IsEmpty : detail::IsEmptyHelper<typename RemoveCV<T>::Type>
 {};
 
 
 namespace detail {
 
-template<typename T, bool = IsFloatingPoint<T>::value>
+template<typename T,
+         bool = IsFloatingPoint<T>::value,
+         typename NoCV = typename RemoveCV<T>::Type>
 struct IsSignedHelper;
 
-template<typename T>
-struct IsSignedHelper<T, true> : TrueType {};
+template<typename T, typename NoCV>
+struct IsSignedHelper<T, true, NoCV> : TrueType {};
 
-template<typename T>
-struct IsSignedHelper<T, false>
-  : IntegralConstant<bool, IsArithmetic<T>::value && T(-1) < T(1)>
+template<typename T, typename NoCV>
+struct IsSignedHelper<T, false, NoCV>
+  : IntegralConstant<bool, IsArithmetic<T>::value && NoCV(-1) < NoCV(1)>
 {};
 
 } // namespace detail
 
 /**
  * IsSigned determines whether a type is a signed arithmetic type.  |char| is
  * considered a signed type if it has the same representation as |signed char|.
  *
@@ -419,28 +421,29 @@ struct IsSignedHelper<T, false>
  * mozilla::IsSigned<unsigned char>::value is false;
  * mozilla::IsSigned<float>::value is true.
  */
 template<typename T>
 struct IsSigned : detail::IsSignedHelper<T> {};
 
 namespace detail {
 
-template<typename T, bool = IsFloatingPoint<T>::value>
+template<typename T,
+         bool = IsFloatingPoint<T>::value,
+         typename NoCV = typename RemoveCV<T>::Type>
 struct IsUnsignedHelper;
 
-template<typename T>
-struct IsUnsignedHelper<T, true> : FalseType {};
+template<typename T, typename NoCV>
+struct IsUnsignedHelper<T, true, NoCV> : FalseType {};
 
-template<typename T>
-struct IsUnsignedHelper<T, false>
+template<typename T, typename NoCV>
+struct IsUnsignedHelper<T, false, NoCV>
   : IntegralConstant<bool,
                      IsArithmetic<T>::value &&
-                     (IsSame<typename RemoveCV<T>::Type, bool>::value ||
-                      T(1) < T(-1))>
+                     (IsSame<NoCV, bool>::value || NoCV(1) < NoCV(-1))>
 {};
 
 } // namespace detail
 
 /**
  * IsUnsigned determines whether a type is an unsigned arithmetic type.
  *
  * Don't use this if the type might be user-defined!  You might or might not get
--- a/mfbt/tests/TestBinarySearch.cpp
+++ b/mfbt/tests/TestBinarySearch.cpp
@@ -29,47 +29,48 @@ int main()
   size_t m;
 
   Vector<int> v1;
   v1.append(2);
   v1.append(4);
   v1.append(6);
   v1.append(8);
 
-  MOZ_ASSERT(!BinarySearch(v1, 0, v1.length(), 1, &m) && m == 0);
-  MOZ_ASSERT( BinarySearch(v1, 0, v1.length(), 2, &m) && m == 0);
-  MOZ_ASSERT(!BinarySearch(v1, 0, v1.length(), 3, &m) && m == 1);
-  MOZ_ASSERT( BinarySearch(v1, 0, v1.length(), 4, &m) && m == 1);
-  MOZ_ASSERT(!BinarySearch(v1, 0, v1.length(), 5, &m) && m == 2);
-  MOZ_ASSERT( BinarySearch(v1, 0, v1.length(), 6, &m) && m == 2);
-  MOZ_ASSERT(!BinarySearch(v1, 0, v1.length(), 7, &m) && m == 3);
-  MOZ_ASSERT( BinarySearch(v1, 0, v1.length(), 8, &m) && m == 3);
-  MOZ_ASSERT(!BinarySearch(v1, 0, v1.length(), 9, &m) && m == 4);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 0, v1.length(), 1, &m) && m == 0);
+  MOZ_RELEASE_ASSERT( BinarySearch(v1, 0, v1.length(), 2, &m) && m == 0);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 0, v1.length(), 3, &m) && m == 1);
+  MOZ_RELEASE_ASSERT( BinarySearch(v1, 0, v1.length(), 4, &m) && m == 1);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 0, v1.length(), 5, &m) && m == 2);
+  MOZ_RELEASE_ASSERT( BinarySearch(v1, 0, v1.length(), 6, &m) && m == 2);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 0, v1.length(), 7, &m) && m == 3);
+  MOZ_RELEASE_ASSERT( BinarySearch(v1, 0, v1.length(), 8, &m) && m == 3);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 0, v1.length(), 9, &m) && m == 4);
 
-  MOZ_ASSERT(!BinarySearch(v1, 1, 3, 1, &m) && m == 1);
-  MOZ_ASSERT(!BinarySearch(v1, 1, 3, 2, &m) && m == 1);
-  MOZ_ASSERT(!BinarySearch(v1, 1, 3, 3, &m) && m == 1);
-  MOZ_ASSERT( BinarySearch(v1, 1, 3, 4, &m) && m == 1);
-  MOZ_ASSERT(!BinarySearch(v1, 1, 3, 5, &m) && m == 2);
-  MOZ_ASSERT( BinarySearch(v1, 1, 3, 6, &m) && m == 2);
-  MOZ_ASSERT(!BinarySearch(v1, 1, 3, 7, &m) && m == 3);
-  MOZ_ASSERT(!BinarySearch(v1, 1, 3, 8, &m) && m == 3);
-  MOZ_ASSERT(!BinarySearch(v1, 1, 3, 9, &m) && m == 3);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 1, 3, 1, &m) && m == 1);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 1, 3, 2, &m) && m == 1);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 1, 3, 3, &m) && m == 1);
+  MOZ_RELEASE_ASSERT( BinarySearch(v1, 1, 3, 4, &m) && m == 1);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 1, 3, 5, &m) && m == 2);
+  MOZ_RELEASE_ASSERT( BinarySearch(v1, 1, 3, 6, &m) && m == 2);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 1, 3, 7, &m) && m == 3);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 1, 3, 8, &m) && m == 3);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 1, 3, 9, &m) && m == 3);
 
-  MOZ_ASSERT(!BinarySearch(v1, 0, 0, 0, &m) && m == 0);
-  MOZ_ASSERT(!BinarySearch(v1, 0, 0, 9, &m) && m == 0);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 0, 0, 0, &m) && m == 0);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v1, 0, 0, 9, &m) && m == 0);
 
   Vector<int> v2;
-  MOZ_ASSERT(!BinarySearch(v2, 0, 0, 0, &m) && m == 0);
-  MOZ_ASSERT(!BinarySearch(v2, 0, 0, 9, &m) && m == 0);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v2, 0, 0, 0, &m) && m == 0);
+  MOZ_RELEASE_ASSERT(!BinarySearch(v2, 0, 0, 9, &m) && m == 0);
 
   Vector<Person> v3;
   v3.append(Person(2, 42));
   v3.append(Person(4, 13));
   v3.append(Person(6, 360));
-  MOZ_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 1, &m) && m == 0);
-  MOZ_ASSERT( BinarySearch(GetAge(v3), 0, v3.length(), 2, &m) && m == 0);
-  MOZ_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 3, &m) && m == 1);
-  MOZ_ASSERT( BinarySearch(GetAge(v3), 0, v3.length(), 4, &m) && m == 1);
-  MOZ_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 5, &m) && m == 2);
-  MOZ_ASSERT( BinarySearch(GetAge(v3), 0, v3.length(), 6, &m) && m == 2);
-  MOZ_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 7, &m) && m == 3);
+
+  MOZ_RELEASE_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 1, &m) && m == 0);
+  MOZ_RELEASE_ASSERT( BinarySearch(GetAge(v3), 0, v3.length(), 2, &m) && m == 0);
+  MOZ_RELEASE_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 3, &m) && m == 1);
+  MOZ_RELEASE_ASSERT( BinarySearch(GetAge(v3), 0, v3.length(), 4, &m) && m == 1);
+  MOZ_RELEASE_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 5, &m) && m == 2);
+  MOZ_RELEASE_ASSERT( BinarySearch(GetAge(v3), 0, v3.length(), 6, &m) && m == 2);
+  MOZ_RELEASE_ASSERT(!BinarySearch(GetAge(v3), 0, v3.length(), 7, &m) && m == 3);
 }
--- a/mfbt/tests/TestEndian.cpp
+++ b/mfbt/tests/TestEndian.cpp
@@ -330,19 +330,19 @@ main()
   MOZ_RELEASE_ASSERT(BigEndian::readInt16(&signed_bytes[0]) == int16_t(0xf1f2));
 
   MOZ_RELEASE_ASSERT(LittleEndian::readInt32(&signed_bytes[0]) == int32_t(0xf4f3f2f1));
   MOZ_RELEASE_ASSERT(BigEndian::readInt32(&signed_bytes[0]) == int32_t(0xf1f2f3f4));
 
   MOZ_RELEASE_ASSERT(LittleEndian::readInt64(&signed_bytes[0]) == int64_t(0xf8f7f6f5f4f3f2f1LL));
   MOZ_RELEASE_ASSERT(BigEndian::readInt64(&signed_bytes[0]) == int64_t(0xf1f2f3f4f5f6f7f8LL));
 
-  LittleEndian::writeInt16(&buffer[0], 0xf2f1);
+  LittleEndian::writeInt16(&buffer[0], int16_t(0xf2f1));
   MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int16_t)) == 0);
-  BigEndian::writeInt16(&buffer[0], 0xf1f2);
+  BigEndian::writeInt16(&buffer[0], int16_t(0xf1f2));
   MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int16_t)) == 0);
 
   LittleEndian::writeInt32(&buffer[0], 0xf4f3f2f1);
   MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int32_t)) == 0);
   BigEndian::writeInt32(&buffer[0], 0xf1f2f3f4);
   MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int32_t)) == 0);
 
   LittleEndian::writeInt64(&buffer[0], 0xf8f7f6f5f4f3f2f1LL);
--- a/mfbt/tests/TestPoisonArea.cpp
+++ b/mfbt/tests/TestPoisonArea.cpp
@@ -193,40 +193,43 @@ StrW32Error(DWORD errcode)
   while (errmsg[n] == '\r' || errmsg[n] == '\n') n--;
   errmsg[n+1] = '\0';
   return errmsg;
 }
 #define LastErrMsg() (StrW32Error(GetLastError()))
 
 // Because we use VirtualAlloc in MEM_RESERVE mode, the "page size" we want
 // is the allocation granularity.
-static SYSTEM_INFO _sinfo;
-#undef PAGESIZE
-#define PAGESIZE (_sinfo.dwAllocationGranularity)
+static SYSTEM_INFO sInfo_;
 
+static inline uint32_t
+PageSize()
+{
+  return sInfo_.dwAllocationGranularity;
+}
 
 static void *
 ReserveRegion(uintptr_t request, bool accessible)
 {
-  return VirtualAlloc((void *)request, PAGESIZE,
+  return VirtualAlloc((void *)request, PageSize(),
                       accessible ? MEM_RESERVE|MEM_COMMIT : MEM_RESERVE,
                       accessible ? PAGE_EXECUTE_READWRITE : PAGE_NOACCESS);
 }
 
 static void
 ReleaseRegion(void *page)
 {
-  VirtualFree(page, PAGESIZE, MEM_RELEASE);
+  VirtualFree(page, PageSize(), MEM_RELEASE);
 }
 
 static bool
 ProbeRegion(uintptr_t page)
 {
-  if (page >= (uintptr_t)_sinfo.lpMaximumApplicationAddress &&
-      page + PAGESIZE >= (uintptr_t)_sinfo.lpMaximumApplicationAddress) {
+  if (page >= (uintptr_t)sInfo_.lpMaximumApplicationAddress &&
+      page + PageSize() >= (uintptr_t)sInfo_.lpMaximumApplicationAddress) {
     return true;
   } else {
     return false;
   }
 }
 
 static bool
 MakeRegionExecutable(void *)
@@ -236,66 +239,71 @@ MakeRegionExecutable(void *)
 
 #undef MAP_FAILED
 #define MAP_FAILED 0
 
 #else // Unix
 
 #define LastErrMsg() (strerror(errno))
 
-static unsigned long _pagesize;
-#define PAGESIZE _pagesize
+static unsigned long unixPageSize;
+
+static inline unsigned long
+PageSize()
+{
+  return unixPageSize;
+}
 
 static void *
 ReserveRegion(uintptr_t request, bool accessible)
 {
-  return mmap(reinterpret_cast<void*>(request), PAGESIZE,
+  return mmap(reinterpret_cast<void*>(request), PageSize(),
               accessible ? PROT_READ|PROT_WRITE : PROT_NONE,
               MAP_PRIVATE|MAP_ANON, -1, 0);
 }
 
 static void
 ReleaseRegion(void *page)
 {
-  munmap(page, PAGESIZE);
+  munmap(page, PageSize());
 }
 
 static bool
 ProbeRegion(uintptr_t page)
 {
-  if (madvise(reinterpret_cast<void*>(page), PAGESIZE, MADV_NORMAL)) {
+  if (madvise(reinterpret_cast<void*>(page), PageSize(), MADV_NORMAL)) {
     return true;
   } else {
     return false;
   }
 }
 
 static int
 MakeRegionExecutable(void *page)
 {
-  return mprotect((caddr_t)page, PAGESIZE, PROT_READ|PROT_WRITE|PROT_EXEC);
+  return mprotect((caddr_t)page, PageSize(), PROT_READ|PROT_WRITE|PROT_EXEC);
 }
 
 #endif
 
 static uintptr_t
 ReservePoisonArea()
 {
   if (sizeof(uintptr_t) == 8) {
     // Use the hardware-inaccessible region.
     // We have to avoid 64-bit constants and shifts by 32 bits, since this
     // code is compiled in 32-bit mode, although it is never executed there.
     uintptr_t result = (((uintptr_t(0x7FFFFFFFu) << 31) << 1 |
                          uintptr_t(0xF0DEAFFFu)) &
-                        ~uintptr_t(PAGESIZE-1));
+                        ~uintptr_t(PageSize()-1));
     printf("INFO | poison area assumed at 0x%.*" PRIxPTR "\n", SIZxPTR, result);
     return result;
   } else {
     // First see if we can allocate the preferred poison address from the OS.
-    uintptr_t candidate = (0xF0DEAFFF & ~(PAGESIZE-1));
+    uintptr_t candidate = (0xF0DEAFFF & ~(PageSize()-1));
     void *result = ReserveRegion(candidate, false);
     if (result == (void *)candidate) {
       // success - inaccessible page allocated
       printf("INFO | poison area allocated at 0x%.*" PRIxPTR
              " (preferred addr)\n", SIZxPTR, (uintptr_t)result);
       return candidate;
     }
 
@@ -358,17 +366,17 @@ ReserveNegativeControl()
   void *result = ReserveRegion(0, true);
   if (result == MAP_FAILED) {
     printf("ERROR | allocating negative control | %s\n", LastErrMsg());
     return 0;
   }
 
   // Fill the page with return instructions.
   RETURN_INSTR_TYPE *p = (RETURN_INSTR_TYPE *)result;
-  RETURN_INSTR_TYPE *limit = (RETURN_INSTR_TYPE *)(((char *)result) + PAGESIZE);
+  RETURN_INSTR_TYPE *limit = (RETURN_INSTR_TYPE *)(((char *)result) + PageSize());
   while (p < limit)
     *p++ = RETURN_INSTR;
 
   // Now mark it executable as well as readable and writable.
   // (mmap(PROT_EXEC) may fail when applied to anonymous memory.)
 
   if (MakeRegionExecutable(result)) {
     printf("ERROR | making negative control executable | %s\n", LastErrMsg());
@@ -422,19 +430,19 @@ TestPage(const char *pagelabel, uintptr_
   const char *oplabel;
   uintptr_t opaddr;
 
   bool failed = false;
   for (unsigned int test = 0; test < 3; test++) {
     switch (test) {
       // The execute test must be done before the write test, because the
       // write test will clobber memory at the target address.
-    case 0: oplabel = "reading"; opaddr = pageaddr + PAGESIZE/2 - 1; break;
-    case 1: oplabel = "executing"; opaddr = pageaddr + PAGESIZE/2; break;
-    case 2: oplabel = "writing"; opaddr = pageaddr + PAGESIZE/2 - 1; break;
+    case 0: oplabel = "reading"; opaddr = pageaddr + PageSize()/2 - 1; break;
+    case 1: oplabel = "executing"; opaddr = pageaddr + PageSize()/2; break;
+    case 2: oplabel = "writing"; opaddr = pageaddr + PageSize()/2 - 1; break;
     default: abort();
     }
 
 #ifdef _WIN32
     BOOL badptr;
 
     switch (test) {
     case 0: badptr = IsBadReadPtr((const void*)opaddr, 1); break;
@@ -514,19 +522,19 @@ TestPage(const char *pagelabel, uintptr_
   }
   return failed;
 }
 
 int
 main()
 {
 #ifdef _WIN32
-  GetSystemInfo(&_sinfo);
+  GetSystemInfo(&sInfo_);
 #else
-  _pagesize = sysconf(_SC_PAGESIZE);
+  unixPageSize = sysconf(_SC_PAGESIZE);
 #endif
 
   uintptr_t ncontrol = ReserveNegativeControl();
   uintptr_t pcontrol = ReservePositiveControl();
   uintptr_t poison = ReservePoisonArea();
 
   if (!ncontrol || !pcontrol || !poison)
     return 2;
--- a/mfbt/tests/moz.build
+++ b/mfbt/tests/moz.build
@@ -30,8 +30,16 @@ if not CONFIG['MOZ_ASAN']:
     CPP_UNIT_TESTS += [
         'TestPoisonArea.cpp',
     ]
 
 # Since we link directly with MFBT object files, define IMPL_MFBT
 DEFINES['IMPL_MFBT'] = True
 
 DISABLE_STL_WRAPPING = True
+
+if CONFIG['_MSC_VER']:
+  CXXFLAGS += [
+    '-wd4275', # non dll-interface class used as base for dll-interface class
+    '-wd4530', # C++ exception handler used, but unwind semantics are not enabled
+  ]
+
+FAIL_ON_WARNINGS = True