lkml.org 
[lkml]   [2020]   [Feb]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2] drm/i915: Disable -Wtautological-constant-out-of-range-compare
From
Date
On 2020-02-11 9:39 p.m., Nathan Chancellor wrote:
> On Tue, Feb 11, 2020 at 10:41:48AM +0100, Michel Dänzer wrote:
>> On 2020-02-11 7:13 a.m., Nathan Chancellor wrote:
>>> A recent commit in clang added -Wtautological-compare to -Wall, which is
>>> enabled for i915 so we see the following warning:
>>>
>>> ../drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c:1485:22: warning:
>>> result of comparison of constant 576460752303423487 with expression of
>>> type 'unsigned int' is always false
>>> [-Wtautological-constant-out-of-range-compare]
>>> if (unlikely(remain > N_RELOC(ULONG_MAX)))
>>> ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
>>>
>>> This warning only happens on x86_64 but that check is relevant for
>>> 32-bit x86 so we cannot remove it.
>>
>> That's suprising. AFAICT N_RELOC(ULONG_MAX) works out to the same value
>> in both cases, and remain is a 32-bit value in both cases. How can it be
>> larger than N_RELOC(ULONG_MAX) on 32-bit (but not on 64-bit)?
>>
>
> Hi Michel,
>
> Can't this condition be true when UINT_MAX == ULONG_MAX?

Oh, right, I think I was wrongly thinking long had 64 bits even on 32-bit.


Anyway, this suggests a possible better solution:

#if UINT_MAX == ULONG_MAX
if (unlikely(remain > N_RELOC(ULONG_MAX)))
return -EINVAL;
#endif


Or if that can't be used for some reason, something like

if (unlikely((unsigned long)remain > N_RELOC(ULONG_MAX)))
return -EINVAL;

should silence the warning.


Either of these should be better than completely disabling the warning
for the whole file.


--
Earthling Michel Dänzer | https://redhat.com
Libre software enthusiast | Mesa and X developer

\
 
 \ /
  Last update: 2020-02-12 09:53    [W:0.082 / U:0.204 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site