[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 02:08:18 PDT 2016


Added tests as of r271505.

On Thu, Jun 2, 2016 at 10:20 AM, Dylan McKay <dylanmckay34 at gmail.com> wrote:

> Will do.
> On 2 Jun 2016 05:05, "David Blaikie" <dblaikie at gmail.com> wrote:
>
>> Please include/provide a test case - these could probably use a bunch of
>> unit tests.
>>
>> On Wed, Jun 1, 2016 at 4:15 AM, Dylan McKay via llvm-commits <
>> llvm-commits at lists.llvm.org> wrote:
>>
>>> Author: dylanmckay
>>> Date: Wed Jun  1 06:15:25 2016
>>> New Revision: 271380
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=271380&view=rev
>>> Log:
>>> Fix off-by-one error in max integer functions
>>>
>>> I recently added these functions, but implemented them poorly. This
>>> fixes that.
>>>
>>> Sorry for the spam.
>>>
>>> Modified:
>>>     llvm/trunk/include/llvm/Support/MathExtras.h
>>>
>>> Modified: llvm/trunk/include/llvm/Support/MathExtras.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MathExtras.h?rev=271380&r1=271379&r2=271380&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/include/llvm/Support/MathExtras.h (original)
>>> +++ llvm/trunk/include/llvm/Support/MathExtras.h Wed Jun  1 06:15:25 2016
>>> @@ -312,22 +312,22 @@ inline bool isShiftedUInt(uint64_t x) {
>>>  }
>>>
>>>  /// 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; }
>>>  /// Gets the minimum value for a N-bit signed integer.
>>>  inline int64_t minIntN(int64_t N) { return -(INT64_C(1)<<(N-1)); }
>>>  /// Gets the maximum value for a N-bit signed integer.
>>> -inline int64_t maxIntN(int64_t N) { return INT64_C(1)<<(N-1); }
>>> +inline int64_t maxIntN(int64_t N) { return (INT64_C(1)<<(N-1)) - 1; }
>>>
>>>  /// isUIntN - Checks if an unsigned integer fits into the given
>>> (dynamic)
>>>  /// bit width.
>>>  inline bool isUIntN(unsigned N, uint64_t x) {
>>> -  return N >= 64 || x < maxUIntN(N);
>>> +  return N >= 64 || x <= maxUIntN(N);
>>>  }
>>>
>>>  /// isIntN - Checks if an signed integer fits into the given (dynamic)
>>>  /// bit width.
>>>  inline bool isIntN(unsigned N, int64_t x) {
>>> -  return N >= 64 || (minIntN(N) <= x && x < maxIntN(N));
>>> +  return N >= 64 || (minIntN(N) <= x && x <= maxIntN(N));
>>>  }
>>>
>>>  /// isMask_32 - This function returns true if the argument is a
>>> non-empty
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160602/77121df3/attachment.html>


More information about the llvm-commits mailing list