Bug 1365460 - Remove warning exceptions for MSVC and work around them. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 18 May 2017 12:13:34 +0900
changeset 580764 35b42ba287f246e0af397a777b1de404929b5ce9
parent 580763 eebb11f55dbd279b9500e7ea05cd03a5f865f53c
child 580765 22d5bb26065d6fe488d218be881a89e1a93571a5
push id59654
push userbmo:mh+mozilla@glandium.org
push dateThu, 18 May 2017 22:44:22 +0000
reviewersnjn
bugs1365460
milestone55.0a1
Bug 1365460 - Remove warning exceptions for MSVC and work around them. r?njn
memory/mozjemalloc/mozjemalloc.cpp
--- a/memory/mozjemalloc/mozjemalloc.cpp
+++ b/memory/mozjemalloc/mozjemalloc.cpp
@@ -150,18 +150,16 @@
 
 /* Some defines from the CRT internal headers that we need here. */
 #define _CRT_SPINCOUNT 5000
 #include <io.h>
 #include <windows.h>
 #include <intrin.h>
 #include <algorithm>
 
-#pragma warning( disable: 4267 4996 4146 )
-
 #define	SIZE_T_MAX SIZE_MAX
 #define	STDERR_FILENO 2
 
 #ifndef NO_TLS
 static unsigned long tlsIndex = 0xffffffff;
 #endif
 
 /* use MSVC intrinsics */
@@ -2032,17 +2030,17 @@ malloc_rtree_set(malloc_rtree_t *rtree, 
  * from upstream jemalloc 3.4.1 to fix Mozilla bug 956501. */
 
 /* Return the offset between a and the nearest aligned address at or below a. */
 #define        ALIGNMENT_ADDR2OFFSET(a, alignment)                                \
         ((size_t)((uintptr_t)(a) & (alignment - 1)))
 
 /* Return the smallest alignment multiple that is >= s. */
 #define        ALIGNMENT_CEILING(s, alignment)                                        \
-        (((s) + (alignment - 1)) & (-(alignment)))
+        (((s) + (alignment - 1)) & (~(alignment - 1)))
 
 static void *
 pages_trim(void *addr, size_t alloc_size, size_t leadsize, size_t size)
 {
         void *ret = (void *)((uintptr_t)addr + leadsize);
 
         MOZ_ASSERT(alloc_size >= leadsize + size);
 #ifdef MOZ_MEMORY_WINDOWS
@@ -3598,17 +3596,17 @@ ipalloc(size_t alignment, size_t size)
 	 *     96 |  1100000 |  32
 	 *    144 | 10100000 |  32
 	 *    192 | 11000000 |  64
 	 *
 	 * Depending on runtime settings, it is possible that arena_malloc()
 	 * will further round up to a power of two, but that never causes
 	 * correctness issues.
 	 */
-	ceil_size = (size + (alignment - 1)) & (-alignment);
+	ceil_size = ALIGNMENT_CEILING(size, alignment);
 	/*
 	 * (ceil_size < size) protects against the combination of maximal
 	 * alignment and size greater than maximal alignment.
 	 */
 	if (ceil_size < size) {
 		/* size_t overflow. */
 		return (NULL);
 	}