Title: [219181] trunk/Source/bmalloc
Revision
219181
Author
commit-qu...@webkit.org
Date
2017-07-05 19:30:40 -0700 (Wed, 05 Jul 2017)

Log Message

reinterpret_cast does not evaluate to constexpr
https://bugs.webkit.org/show_bug.cgi?id=173622

Patch by Daewoong Jang <daewoong.j...@navercorp.com> on 2017-07-05
Reviewed by Yusuke Suzuki.

* bmalloc/Algorithm.h:
(bmalloc::mask):
(bmalloc::roundUpToMultipleOf):

Modified Paths

Diff

Modified: trunk/Source/bmalloc/ChangeLog (219180 => 219181)


--- trunk/Source/bmalloc/ChangeLog	2017-07-06 02:29:05 UTC (rev 219180)
+++ trunk/Source/bmalloc/ChangeLog	2017-07-06 02:30:40 UTC (rev 219181)
@@ -1,3 +1,14 @@
+2017-07-05  Daewoong Jang  <daewoong.j...@navercorp.com>
+
+        reinterpret_cast does not evaluate to constexpr
+        https://bugs.webkit.org/show_bug.cgi?id=173622
+
+        Reviewed by Yusuke Suzuki.
+
+        * bmalloc/Algorithm.h:
+        (bmalloc::mask):
+        (bmalloc::roundUpToMultipleOf):
+
 2017-07-03  Andy Estes  <aes...@apple.com>
 
         [Xcode] Add an experimental setting to build with ccache

Modified: trunk/Source/bmalloc/bmalloc/Algorithm.h (219180 => 219181)


--- trunk/Source/bmalloc/bmalloc/Algorithm.h	2017-07-06 02:29:05 UTC (rev 219180)
+++ trunk/Source/bmalloc/bmalloc/Algorithm.h	2017-07-06 02:30:40 UTC (rev 219181)
@@ -50,9 +50,15 @@
 
 template<typename T> inline constexpr T mask(T value, uintptr_t mask)
 {
-    return reinterpret_cast<T>(reinterpret_cast<uintptr_t>(value) & mask);
+    static_assert(sizeof(T) == sizeof(uintptr_t), "sizeof(T) must be equal to sizeof(uintptr_t).");
+    return static_cast<T>(static_cast<uintptr_t>(value) & mask);
 }
 
+template<typename T> inline T* mask(T* value, uintptr_t mask)
+{
+    return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(value) & mask);
+}
+
 template<typename T> inline constexpr bool test(T value, uintptr_t mask)
 {
     return !!(reinterpret_cast<uintptr_t>(value) & mask);
@@ -66,15 +72,28 @@
 template<typename T> inline T roundUpToMultipleOf(size_t divisor, T x)
 {
     BASSERT(isPowerOfTwo(divisor));
-    return reinterpret_cast<T>((reinterpret_cast<uintptr_t>(x) + (divisor - 1)) & ~(divisor - 1));
+    static_assert(sizeof(T) == sizeof(uintptr_t), "sizeof(T) must be equal to sizeof(uintptr_t).");
+    return static_cast<T>((static_cast<uintptr_t>(x) + (divisor - 1)) & ~(divisor - 1));
 }
 
-template<size_t divisor, typename T> inline constexpr T roundUpToMultipleOf(T x)
+template<size_t divisor, typename T> inline T roundUpToMultipleOf(T x)
 {
     static_assert(isPowerOfTwo(divisor), "'divisor' must be a power of two.");
     return roundUpToMultipleOf(divisor, x);
 }
 
+template<typename T> inline T* roundUpToMultipleOf(size_t divisor, T* x)
+{
+    BASSERT(isPowerOfTwo(divisor));
+    return reinterpret_cast<T*>((reinterpret_cast<uintptr_t>(x) + (divisor - 1)) & ~(divisor - 1));
+}
+
+template<size_t divisor, typename T> inline T* roundUpToMultipleOf(T* x)
+{
+    static_assert(isPowerOfTwo(divisor), "'divisor' must be a power of two.");
+    return roundUpToMultipleOf(divisor, x);
+}
+
 template<typename T> inline T roundDownToMultipleOf(size_t divisor, T x)
 {
     BASSERT(isPowerOfTwo(divisor));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to