Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test

From: Andrew Morton

Date: Fri Nov 07 2025 - 19:08:56 EST


On Fri, 7 Nov 2025 10:27:27 +0100 "David Hildenbrand (Red Hat)" <david@xxxxxxxxxx> wrote:

> On 06.11.25 13:02, Ankit Khushwaha wrote:
> > On Thu, Nov 06, 2025 at 12:18:57PM +0100, David Hildenbrand (Red Hat) wrote:
> >> On 06.11.25 11:49, Ankit Khushwaha wrote:
> >>> Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment'
> >>> triggers following warning:
> >>>
> >>> mremap_test.c:1035:31: warning: pointer comparison always evaluates to
> >>> false [-Wtautological-compare]
> >>> 1035 | if (addr + c.dest_alignment < addr) {
> >>> | ^
> >>>
> >>> typecasting 'addr' to 'unsigned long long' to fix pointer comparison.
> >>
> >> With which compiler are you seeing this?
> >
> > Hi David,
> >
> > clang version 20.1.8 (Fedora 20.1.8-4.fc42) raised this warning.
> >
> > To reproduce:
> > make -C tools/testing/selftests/mm CC=clang
>
> Thanks, and thanks to Lorenzo for the details.
>
> Acked-by: David Hildenbrand (Red Hat) <david@xxxxxxxxxx>

I must say, applying this would be an unhappy life event.

if (void* + ulong < void*)

makes perfect sense in a world which permits void* arithmetic (ie,
ours). So what the heck is clang doing??

If we do

void *addr2 = addr + c.dest_alignment;
if (addr2 < addr)
...

then which statement warns, and why?