[compiler-rt] 5bf24f0 - [NFC][sanitizer] constexpr a few functions
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 24 18:37:36 PDT 2021
Author: Vitaly Buka
Date: 2021-10-24T18:37:23-07:00
New Revision: 5bf24f0581ee7ab9971b4050497375464b894c59
URL: https://github.com/llvm/llvm-project/commit/5bf24f0581ee7ab9971b4050497375464b894c59
DIFF: https://github.com/llvm/llvm-project/commit/5bf24f0581ee7ab9971b4050497375464b894c59.diff
LOG: [NFC][sanitizer] constexpr a few functions
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_common.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index 17c29c7504642..b720d99d0d9d4 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -385,9 +385,9 @@ unsigned char _BitScanReverse64(unsigned long *index, unsigned __int64 mask);
}
#endif
-inline uptr MostSignificantSetBitIndex(uptr x) {
+inline constexpr uptr MostSignificantSetBitIndex(uptr x) {
CHECK_NE(x, 0U);
- unsigned long up;
+ unsigned long up = 0;
#if !SANITIZER_WINDOWS || defined(__clang__) || defined(__GNUC__)
# ifdef _WIN64
up = SANITIZER_WORDSIZE - 1 - __builtin_clzll(x);
@@ -402,9 +402,9 @@ inline uptr MostSignificantSetBitIndex(uptr x) {
return up;
}
-inline uptr LeastSignificantSetBitIndex(uptr x) {
+inline constexpr uptr LeastSignificantSetBitIndex(uptr x) {
CHECK_NE(x, 0U);
- unsigned long up;
+ unsigned long up = 0;
#if !SANITIZER_WINDOWS || defined(__clang__) || defined(__GNUC__)
# ifdef _WIN64
up = __builtin_ctzll(x);
@@ -419,11 +419,9 @@ inline uptr LeastSignificantSetBitIndex(uptr x) {
return up;
}
-inline bool IsPowerOfTwo(uptr x) {
- return (x & (x - 1)) == 0;
-}
+inline constexpr bool IsPowerOfTwo(uptr x) { return (x & (x - 1)) == 0; }
-inline uptr RoundUpToPowerOfTwo(uptr size) {
+inline constexpr uptr RoundUpToPowerOfTwo(uptr size) {
CHECK(size);
if (IsPowerOfTwo(size)) return size;
@@ -433,20 +431,20 @@ inline uptr RoundUpToPowerOfTwo(uptr size) {
return 1ULL << (up + 1);
}
-inline uptr RoundUpTo(uptr size, uptr boundary) {
+inline constexpr uptr RoundUpTo(uptr size, uptr boundary) {
RAW_CHECK(IsPowerOfTwo(boundary));
return (size + boundary - 1) & ~(boundary - 1);
}
-inline uptr RoundDownTo(uptr x, uptr boundary) {
+inline constexpr uptr RoundDownTo(uptr x, uptr boundary) {
return x & ~(boundary - 1);
}
-inline bool IsAligned(uptr a, uptr alignment) {
+inline constexpr bool IsAligned(uptr a, uptr alignment) {
return (a & (alignment - 1)) == 0;
}
-inline uptr Log2(uptr x) {
+inline constexpr uptr Log2(uptr x) {
CHECK(IsPowerOfTwo(x));
return LeastSignificantSetBitIndex(x);
}
More information about the llvm-commits
mailing list