diff options
-rw-r--r-- | llvm/include/llvm/Support/MathExtras.h | 3 | ||||
-rw-r--r-- | llvm/unittests/Support/MathExtrasTest.cpp | 1 |
2 files changed, 4 insertions, 0 deletions
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h index f44fd19c544..b60732a9b34 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -316,6 +316,9 @@ inline bool isShiftedUInt(uint64_t x) { inline uint64_t maxUIntN(uint64_t N) { assert(N > 0 && N <= 64 && "integer width out of range"); + // uint64_t(1) << 64 is undefined behavior. + if (N == 64) + return std::numeric_limits<uint64_t>::max(); return (UINT64_C(1) << N) - 1; } diff --git a/llvm/unittests/Support/MathExtrasTest.cpp b/llvm/unittests/Support/MathExtrasTest.cpp index 04e16628e64..ef46311665d 100644 --- a/llvm/unittests/Support/MathExtrasTest.cpp +++ b/llvm/unittests/Support/MathExtrasTest.cpp @@ -131,6 +131,7 @@ TEST(MathExtras, minIntN) { TEST(MathExtras, maxUIntN) { EXPECT_EQ(0xffffULL, maxUIntN(16)); EXPECT_EQ(0xffffffffULL, maxUIntN(32)); + EXPECT_EQ(0xffffffffffffffffULL, maxUIntN(64)); EXPECT_EQ(1ULL, maxUIntN(1)); EXPECT_EQ(0x0fULL, maxUIntN(4)); } |