[llvm] r271380 - Fix off-by-one error in max integer functions

John Regehr via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 03:10:50 PDT 2016


>  /// Gets the maximum value for a N-bit unsigned integer.
> -inline uint64_t maxUIntN(uint64_t N) { return UINT64_C(1) << N; }
> +inline uint64_t maxUIntN(uint64_t N) { return (UINT64_C(1) << N) - 1; }

This is still wrong unless N is guaranteed to be no greater than 63.

John


More information about the llvm-commits mailing list