RE: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.

From: David Laight
Date: Sun Jul 30 2023 - 10:56:38 EST


From: kernel test robot
> Sent: 29 July 2023 03:01
>
> kernel test robot noticed the following build errors:
>
...)
> compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git
> 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
> reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290943.ODVeyeK6-
> lkp@xxxxxxxxx/reproduce)
>
...
> >> mm/percpu.c:3102:10: error: static assertion expression is not an integral constant expression
> base = min(ptr, base);
> ^~~~~~~~~~~~~~
... ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
> include/linux/minmax.h:23:2: note: expanded from macro '__types_ok'
> (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
> ^
...
> mm/percpu.c:3102:10: note: cast that performs the conversions of a reinterpret_cast is not allowed
> in a constant expression

That is a C++ error that seems to have crept into C.
The relevant definition is:

#define is_signed_type(type) (((type)(-1)) < (type)1)

This seems to have been fixed in clang 16.0.0.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)