The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Peter Anvin <hpa@zytor.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Arnd Bergmann <arnd@kernel.org>,
	Christoph Hellwig <hch@infradead.org>,
	"Jason A . Donenfeld" <Jason@zx2c4.com>,
	Herve Codina <herve.codina@bootlin.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Cc: Marco Elver <elver@google.com>, Will Deacon <will@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH next] minmax.h: Use auto for variables in __minmax_array()
Date: Sat, 7 Feb 2026 10:50:49 +0000	[thread overview]
Message-ID: <20260207105049.09c67177@pumpkin> (raw)
In-Reply-To: <20260206222554.676171-1-david.laight.linux@gmail.com>

On Fri,  6 Feb 2026 22:25:54 +0000
david.laight.linux@gmail.com wrote:

Cc the people discussing unqual_scalar_typeof() for arm64 LTO READ_ONCE().


> From: David Laight <david.laight.linux@gmail.com>
> 
> While 'auto __element = _array[--__len]' should remove 'const',
> gcc prior to version 11 are buggy and retain it.
> However forcing an integer promotion by adding zero does work.
> 
> Promoting signed/unsigned char and short to int doesn't matter here,
> that happens as soon as the value is used.
> 
> Type type of the result (for char/short arrays) changes, but the value
> will always be promoted to int before it is used (for any purpose) so
> it isn't even worth casting the type back - all that is likely to do
> is make the compiler explicitly mask it to 8/16 bits before it is
> immediately promoted back to int.
> 
> Signed-off-by: David Laight <david.laight.linux@gmail.com>
> ---
>  include/linux/minmax.h | 19 ++++++-------------
>  1 file changed, 6 insertions(+), 13 deletions(-)
> 
> diff --git a/include/linux/minmax.h b/include/linux/minmax.h
> index a0158db54a04..7d437f73a6d6 100644
> --- a/include/linux/minmax.h
> +++ b/include/linux/minmax.h
> @@ -239,20 +239,13 @@
>   * ...
>   * min = min_array(buff, nb_items);
>   * --- 8< ---
> - *
> - * The first typeof(&(array)[0]) is needed in order to support arrays of both
> - * 'int *buff' and 'int buff[N]' types.
> - *
> - * The array can be an array of const items.
> - * typeof() keeps the const qualifier. Use __unqual_scalar_typeof() in order
> - * to discard the const qualifier for the __element variable.
>   */
> -#define __minmax_array(op, array, len) ({				\
> -	typeof(&(array)[0]) __array = (array);				\
> -	typeof(len) __len = (len);					\
> -	__unqual_scalar_typeof(__array[0]) __element = __array[--__len];\
> -	while (__len--)							\
> -		__element = op(__element, __array[__len]);		\
> +#define __minmax_array(op, array, len) ({			\
> +	auto __array = &(array)[0];				\
> +	auto __len = len;					\
> +	auto __element = __array[--__len] + 0;			\
> +	while (__len--)						\
> +		__element = op(__element, __array[__len]);	\
>  	__element; })
>  
>  /**


  parent reply	other threads:[~2026-02-07 10:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-06 22:25 [PATCH next] minmax.h: Use auto for variables in __minmax_array() david.laight.linux
2026-02-06 22:41 ` Andrew Morton
2026-02-07 10:25   ` David Laight
2026-02-08  2:25     ` Andrew Morton
2026-02-08 11:33       ` David Laight
2026-02-07 10:50 ` David Laight [this message]
2026-02-10  1:38   ` Marco Elver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260207105049.09c67177@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=Jason@zx2c4.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@kernel.org \
    --cc=elver@google.com \
    --cc=hch@infradead.org \
    --cc=herve.codina@bootlin.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox