[PATCH] D22430: Don't do uint64_t(1) << 64 in maxUIntN.
Justin Lebar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 15 18:07:01 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL275656: Don't do uint64_t(1) << 64 in maxUIntN. (authored by jlebar).
Changed prior to commit:
https://reviews.llvm.org/D22430?vs=64213&id=64216#toc
Repository:
rL LLVM
https://reviews.llvm.org/D22430
Files:
llvm/trunk/include/llvm/Support/MathExtras.h
llvm/trunk/unittests/Support/MathExtrasTest.cpp
Index: llvm/trunk/include/llvm/Support/MathExtras.h
===================================================================
--- llvm/trunk/include/llvm/Support/MathExtras.h
+++ llvm/trunk/include/llvm/Support/MathExtras.h
@@ -316,6 +316,9 @@
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;
}
Index: llvm/trunk/unittests/Support/MathExtrasTest.cpp
===================================================================
--- llvm/trunk/unittests/Support/MathExtrasTest.cpp
+++ llvm/trunk/unittests/Support/MathExtrasTest.cpp
@@ -131,6 +131,7 @@
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));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22430.64216.patch
Type: text/x-patch
Size: 975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160716/6b81dba1/attachment.bin>
More information about the llvm-commits
mailing list