[PATCH v2 0/7] Replace "__auto_type" with "auto"

H. Peter Anvin posted 7 patches 2 months, 2 weeks ago
arch/nios2/include/asm/uaccess.h                        |  8 ++++----
arch/x86/include/asm/bug.h                              |  2 +-
arch/x86/include/asm/string_64.h                        |  6 +++---
arch/x86/include/asm/uaccess_64.h                       |  2 +-
fs/proc/inode.c                                         | 16 ++++++++--------
include/linux/cleanup.h                                 |  6 +++---
include/linux/compiler.h                                |  2 +-
include/linux/compiler_types.h                          | 13 +++++++++++++
include/linux/minmax.h                                  |  6 +++---
tools/testing/selftests/bpf/prog_tests/socket_helpers.h |  9 +++++++--
tools/virtio/linux/compiler.h                           |  2 +-
11 files changed, 45 insertions(+), 27 deletions(-)
[PATCH v2 0/7] Replace "__auto_type" with "auto"
Posted by H. Peter Anvin 2 months, 2 weeks ago
"auto" was defined as a keyword back in the K&R days, but as a storage
type specifier.  No one ever used it, since it was and is the default
storage type for local variables.

C++11 recycled the keyword to allow a type to be declared based on the
type of an initializer.  This was finally adopted into standard C in
C23.

gcc and clang provide the "__auto_type" alias keyword as an extension
for pre-C23, however, there is no reason to pollute the bulk of the
source base with this temporary keyword; instead define "auto" as a
macro unless the compiler is running in C23+ mode.

This macro is added in <linux/compiler_types.h> because that header is
included in some of the tools headers, wheres <linux/compiler.h> is
not as it has a bunch of very kernel-specific things in it.

Changes in v2:

- Restore indentation of macro backslashes (David Laight)
- arch/nios2: Replace an adjacent typeof() with a similar "auto" construct
  (Linus Torvalds)
- fs/proc/inode.c: change "__auto_type" to "const auto" (Alexey Dobriyan)

--- 
 arch/nios2/include/asm/uaccess.h                        |  8 ++++----
 arch/x86/include/asm/bug.h                              |  2 +-
 arch/x86/include/asm/string_64.h                        |  6 +++---
 arch/x86/include/asm/uaccess_64.h                       |  2 +-
 fs/proc/inode.c                                         | 16 ++++++++--------
 include/linux/cleanup.h                                 |  6 +++---
 include/linux/compiler.h                                |  2 +-
 include/linux/compiler_types.h                          | 13 +++++++++++++
 include/linux/minmax.h                                  |  6 +++---
 tools/testing/selftests/bpf/prog_tests/socket_helpers.h |  9 +++++++--
 tools/virtio/linux/compiler.h                           |  2 +-
 11 files changed, 45 insertions(+), 27 deletions(-)
Re: [PATCH v2 0/7] Replace "__auto_type" with "auto"
Posted by Kees Cook 2 months, 2 weeks ago

On July 19, 2025 11:50:37 PM PDT, "H. Peter Anvin" <hpa@zytor.com> wrote:
>"auto" was defined as a keyword back in the K&R days, but as a storage
>type specifier.  No one ever used it, since it was and is the default
>storage type for local variables.
>
>C++11 recycled the keyword to allow a type to be declared based on the
>type of an initializer.  This was finally adopted into standard C in
>C23.
>
>gcc and clang provide the "__auto_type" alias keyword as an extension
>for pre-C23, however, there is no reason to pollute the bulk of the
>source base with this temporary keyword; instead define "auto" as a
>macro unless the compiler is running in C23+ mode.

Yeah, this is good. We have typeof() used extensively in macros all over. I'll try this for fortify macros and see if we see any binary output changes...

-- 
Kees Cook