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

Dylan McKay via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 03:32:28 PDT 2016


How do you think this should be handled? Assertion error?

On Thu, Jun 2, 2016 at 10:10 PM, John Regehr <regehr at cs.utah.edu> wrote:

>  /// 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160602/61e4ece4/attachment.html>


More information about the llvm-commits mailing list