Index: include/llvm/Support/MathExtras.h =================================================================== --- include/llvm/Support/MathExtras.h +++ include/llvm/Support/MathExtras.h @@ -343,7 +343,9 @@ inline int64_t maxIntN(int64_t N) { assert(N > 0 && N <= 64 && "integer width out of range"); - return (INT64_C(1)<<(N-1)) - 1; + // This relies on two's complement wraparound when N == 64, so we cast to + // uint64_t to avoid UB. + return static_cast(INT64_C(1) << (N - 1)) - 1; } /// isUIntN - Checks if an unsigned integer fits into the given (dynamic)