__auto_type conversion for v6.19-rc1
H. Peter Anvin
reviewerHi Linus,
The following changes since commit c2f2b01b74be8b40a2173372bcd770723f87e7b2:
Merge tag 'i3c/for-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux (2025-12-08 11:25:14 +0900)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-auto.git
for you to fetch changes up to branch auto-type-for-6.19 (4ecc26fa585216f98d71411ce182f9e823d94c8c):
tools/virtio: replace "__auto_type" with "auto" (2025-12-08 15:32:15 -0800)
----------------------------------------------------------------
H. Peter Anvin (7):
compiler_types.h: add "auto" as a macro for "__auto_type" include/linux: change "__auto_type" to "auto"
fs/proc: replace "__auto_type" with "const auto" arch/nios2: replace "__auto_type" and adjacent equivalent with "auto" arch/x86: replace "__auto_type" with "auto" selftests/bpf: replace "__auto_type" with "auto" tools/virtio: replace "__auto_type" with "auto"
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 | 19 +++++++++---------- include/linux/cleanup.h | 6 +++--- include/linux/compiler.h | 2 +- include/linux/compiler_types.h | 13 +++++++++++++ include/linux/minmax.h | 6 +++--- .../testing/selftests/bpf/prog_tests/socket_helpers.h | 9 +++++++-- tools/virtio/linux/compiler.h | 2 +- 11 files changed, 46 insertions(+), 29 deletions(-)
arch/nios2/include/asm/uaccess.h +4 -4
@@ -172,15 +172,15 @@ do { \#define __put_user (x, ptr) \ ({ \ - __auto_type __pu_ptr = (ptr); \ - typeof(*__pu_ptr) __pu_val = (typeof(*__pu_ptr))(x); \ + auto __pu_ptr = (ptr); \ + auto __pu_val = (typeof(*__pu_ptr))(x); \ __put_user_common(__pu_val, __pu_ptr); \ })#define put_user (x, ptr) \ ({ \ - __auto_type __pu_ptr = (ptr); \ - typeof(*__pu_ptr) __pu_val = (typeof(*__pu_ptr))(x); \ + auto __pu_ptr = (ptr); \ + auto __pu_val = (typeof(*__pu_ptr))(x); \ access_ok(__pu_ptr, sizeof(*__pu_ptr)) ? \ __put_user_common(__pu_val, __pu_ptr) : \ -EFAULT; \
arch/x86/include/asm/bug.h +1 -1
@@ -129,7 +129,7 @@ do { \#define __WARN_FLAGS (cond_str, flags) \ do { \ - __auto_type __flags = BUGFLAG_WARNING|(flags); \ + auto __flags = BUGFLAG_WARNING|(flags); \ instrumentation_begin(); \ _BUG_FLAGS(cond_str, ASM_UD2, __flags, ARCH_WARN_REACHABLE); \ instrumentation_end(); \
arch/x86/include/asm/string_64.h +3 -3
@@ -31,7 +31,7 @@ KCFI_REFERENCE(__memset);#define __HAVE_ARCH_MEMSET16static inline void *memset16 (uint16_t *s,uint16_t v,size_t n) { -const __auto_type s0 = s; + const auto s0 = s; asmvolatile ("rep stosw" : "+D" (s), "+c" (n)
@@ -44,7 +44,7 @@ static inline void *memset16(uint16_t *s, uint16_t v, size_t n)#define __HAVE_ARCH_MEMSET32static inline void *memset32 (uint32_t *s,uint32_t v,size_t n) { -const __auto_type s0 = s; + const auto s0 = s; asmvolatile ("rep stosl" : "+D" (s), "+c" (n)
@@ -57,7 +57,7 @@ static inline void *memset32(uint32_t *s, uint32_t v, size_t n)#define __HAVE_ARCH_MEMSET64static inline void *memset64 (uint64_t *s,uint64_t v,size_t n) { -const __auto_type s0 = s; + const auto s0 = s; asmvolatile ("rep stosq" : "+D" (s), "+c" (n)
arch/x86/include/asm/uaccess_64.h +1 -1
@@ -72,7 +72,7 @@ static inline void __user *mask_user_address(const void __user *ptr)return ret; }#define masked_user_access_begin (x) ({ \ - __auto_type __masked_ptr = (x); \ + auto __masked_ptr = (x); \ __masked_ptr = mask_user_address(__masked_ptr); \ __uaccess_begin(); __masked_ptr; })
fs/proc/inode.c +9 -10
@@ -303,7 +303,7 @@ static ssize_t proc_reg_read_iter(struct kiocb *iocb, struct iov_iter *iter)static ssize_t pde_read (struct proc_dir_entry *pde,struct file *file,char __user *buf,size_t count,loff_t *ppos) { -__auto_type read = pde->proc_ops->proc_read; + const auto read = pde->proc_ops->proc_read;if (read)return read (file, buf, count, ppos);return -EIO ;
@@ -325,7 +325,7 @@ static ssize_t proc_reg_read(struct file *file, char __user *buf, size_t count,static ssize_t pde_write (struct proc_dir_entry *pde,struct file *file,const char __user *buf,size_t count,loff_t *ppos) { -__auto_type write = pde->proc_ops->proc_write; + const auto write = pde->proc_ops->proc_write;if (write)return write (file, buf, count, ppos);return -EIO ;
@@ -347,7 +347,7 @@ static ssize_t proc_reg_write(struct file *file, const char __user *buf, size_tstatic __poll_t pde_poll (struct proc_dir_entry *pde,struct file *file,struct poll_table_struct *pts) { -__auto_type poll = pde->proc_ops->proc_poll; + const auto poll = pde->proc_ops->proc_poll;if (poll)return poll (file, pts);return DEFAULT_POLLMASK ;
@@ -369,7 +369,7 @@ static __poll_t proc_reg_poll(struct file *file, struct poll_table_struct *pts)static long pde_ioctl (struct proc_dir_entry *pde,struct file *file,unsigned int cmd,unsigned long arg) { -__auto_type ioctl = pde->proc_ops->proc_ioctl; + const auto ioctl = pde->proc_ops->proc_ioctl;if (ioctl)return ioctl (file, cmd, arg);return -ENOTTY ;
@@ -392,7 +392,7 @@ static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigne#ifdef CONFIG_COMPAT static long pde_compat_ioctl (struct proc_dir_entry *pde,struct file *file,unsigned int cmd,unsigned long arg) { -__auto_type compat_ioctl = pde->proc_ops->proc_compat_ioctl; + const auto compat_ioctl = pde->proc_ops->proc_compat_ioctl;if (compat_ioctl)return compat_ioctl (file, cmd, arg);return -ENOTTY ;
@@ -414,7 +414,7 @@ static long proc_reg_compat_ioctl(struct file *file, unsigned int cmd, unsignedstatic int pde_mmap (struct proc_dir_entry *pde,struct file *file,struct vm_area_struct *vma) { -__auto_type mmap = pde->proc_ops->proc_mmap; + const auto mmap = pde->proc_ops->proc_mmap;if (mmap)return mmap (file, vma);return -EIO ;
@@ -497,7 +497,7 @@ static int proc_reg_open(struct inode *inode, struct file *file)if (!use_pde (pde))return -ENOENT ; -__auto_type release = pde->proc_ops->proc_release; + const auto release = pde->proc_ops->proc_release;if (release) { pdeo =kmem_cache_alloc (pde_opener_cache,GFP_KERNEL );if (!pdeo) {
@@ -534,10 +534,9 @@ static int proc_reg_release(struct inode *inode, struct file *file)struct pde_opener *pdeo;if (pde_is_permanent (pde)) { -__auto_type release = pde->proc_ops->proc_release; -if (release) { + const auto release = pde->proc_ops->proc_release; +if (release)return release (inode, file); - }return 0 ; }
include/linux/cleanup.h +3 -3
@@ -212,10 +212,10 @@#define __free (_name) __cleanup(__free_##_name) -#define __get_and_null (p, nullvalue) \ +#define __get_and_null (p, nullvalue) \ ({ \ - __auto_type __ptr = &(p); \ - __auto_type __val = *__ptr; \ + auto __ptr = &(p); \ + auto __val = *__ptr; \ *__ptr = nullvalue; \ __val; \ })
include/linux/compiler.h +1 -1
@@ -190,7 +190,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,#define data_race (expr) \ ({ \ __kcsan_disable_current(); \ - __auto_type __v = (expr); \ + auto __v = (expr); \ __kcsan_enable_current(); \ __v; \ })
include/linux/compiler_types.h +13 -0
@@ -13,6 +13,19 @@#ifndef __ASSEMBLY__ +/* +* C23 introduces "auto" as a standard way to define type-inferred +* variables, but "auto" has been a (useless) keyword even since K&R C, +* so it has always been "namespace reserved." +* +* Until at some future time we require C23 support, we need the gcc +* extension __auto_type, but there is no reason to put that elsewhere +* in the source code. +*/ +#if __STDC_VERSION__ <202311L +# define auto __auto_type +#endif +/* * Skipped when running bindgen due to a libclang issue; * see https://github.com/rust-lang/rust-bindgen/issues/2244.
include/linux/minmax.h +3 -3
@@ -89,7 +89,7 @@ __cmp_once_unique(op, type, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_))#define __careful_cmp_once (op, x, y, ux, uy) ({ \ - __auto_type ux = (x); __auto_type uy = (y); \ + auto ux = (x); auto uy = (y); \ BUILD_BUG_ON_MSG(!__types_ok(ux, uy), \ #op"("#x", "#y") signedness error"); \ __cmp(op, ux, uy); })
@@ -129,7 +129,7 @@ __careful_cmp(max, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull)#define __careful_op3 (op, x, y, z, ux, uy, uz) ({ \ - __auto_type ux = (x); __auto_type uy = (y);__auto_type uz = (z);\ + auto ux = (x); auto uy = (y); auto uz = (z); \ BUILD_BUG_ON_MSG(!__types_ok3(ux, uy, uz), \ #op"3("#x", "#y", "#z") signedness error"); \ __cmp(op, ux, __cmp(op, uy, uz)); })
@@ -203,7 +203,7 @@* This macro checks @val/@lo/@hi to make sure they have compatible * signedness. */ -#define clamp (val, lo, hi) __careful_clamp(__auto_type, val, lo, hi) +#define clamp (val, lo, hi) __careful_clamp(auto, val, lo, hi)/** * clamp_t - return a value clamped to a given range using a given type
tools/testing/selftests/bpf/prog_tests/socket_helpers.h +7 -2
@@ -17,11 +17,16 @@#define VMADDR_CID_LOCAL 1#endif +/* include/linux/compiler_types.h */ +#if __STDC_VERSION__ <202311L && !defined(auto) +# define auto __auto_type +#endif +/* include/linux/cleanup.h */ #define __get_and_null (p, nullvalue) \ ({ \ - __auto_type __ptr = &(p); \ - __auto_type __val = *__ptr; \ + auto __ptr = &(p); \ + auto __val = *__ptr; \ *__ptr = nullvalue; \ __val; \ })
tools/virtio/linux/compiler.h +1 -1
@@ -31,7 +31,7 @@*/ #define data_race (expr) \ ({ \ - __auto_type __v = (expr); \ + auto __v = (expr); \ __v; \ })
The pull request you sent on Mon, 8 Dec 2025 15:55:26 -0800:
The pull request you sent on Mon, 8 Dec 2025 15:55:26 -0800:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-auto.gitrefs/heads/master
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/b88b2f82fab45521cb32c0b737266d90a66a748f
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html
Hmm. I think pr-tracker-bot is being confused. This one just came in, and hasn't been merged yet.
That merge commit link is for the hwmon pull.
Linus
Quoted 7 lines · On Tue, 9 Dec 2025 at 09:14, <[email protected]> wrote:
The pull request you sent on Mon, 8 Dec 2025 15:55:26 -0800:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-auto.gitrefs/heads/masterhas been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/b88b2f82fab45521cb32c0b737266d90a66a748f
H. Peter Anvin
reviewerQuoted 6 lines · Linus Torvalds
Hmm. I think pr-tracker-bot is being confused. This one just came in, and hasn't been merged yet.
That merge commit link is for the hwmon pull.
Linus
Yeah, it commented on the master branch, which is of course ... yours.
-hpa
Quoted 2 lines · H. Peter Anvin
Yeah, it commented on the master branch, which is of course ... yours.
Ahh. It's because you didn't use the standard pull request format, and instead did the branch name elsewhere.
Which btw also messes with my "just cut and paste the address" thing, because now I'll cut-and-paste two different things.
"Poor Linus - all the pain he has to go through".
Linus "think of all those extra clicks" Torvalds
Quoted 4 lines · Linus Torvalds
Quoted 1 line
Yeah, it commented on the master branch, which is of course ... yours.
Ahh. It's because you didn't use the standard pull request format, and instead did the branch name elsewhere.
It seems almost every maintainer has their own script to send a pull request, even if many of them are wrapping git-request-pull.
I was just talking to Steve Rostedt earlier today about maybe teaching b4 how to do that so that at least any new incoming maintainers have a more streamlined way of sending a standard pull request in a format that is easy on both Linus and the pr-tracker-bot.
-K
Al Viro
maintainerQuoted 6 lines · H. Peter Anvin
Hi Linus,
The following changes since commit
c2f2b01b74be8b40a2173372bcd770723f87e7b2:Merge tag 'i3c/for-6.19' of
git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux(2025-12-08 11:25:14 +0900)
Quoted 8 lines
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-auto.gitfor you to fetch changes up to branch auto-type-for-6.19 (
4ecc26fa585216f98d71411ce182f9e823d94c8c):
tools/virtio: replace "__auto_type" with "auto" (2025-12-08 15:32:15 -0800)
Argh... teaching declaration parser in sparse to handle that is going to be fun, especially since there are corner cases where gcc and clang do not agree, even with --std=c23 --pedantic...
H. Peter Anvin
reviewerQuoted 11 lines · Al Viro
Quoted 10 lines · H. Peter Anvin
Hi Linus,
The following changes since commit
c2f2b01b74be8b40a2173372bcd770723f87e7b2:Merge tag 'i3c/for-6.19' of
git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux(2025-12-08 11:25:14 +0900)are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-auto.git
Quoted 8 lines
Quoted 4 lines
for you to fetch changes up to branch auto-type-for-6.19 (
4ecc26fa585216f98d71411ce182f9e823d94c8c):
tools/virtio: replace "__auto_type" with "auto" (2025-12-08 15:32:15 -0800)Argh... teaching declaration parser in sparse to handle that is going to be fun, especially since there are corner cases where gcc and clang do not agree, even with --std=c23 --pedantic...
Well, until sparse actually handles C23, this is just a macro. __auto_type is already in use.
Al Viro
maintainerQuoted 15 lines · H. Peter Anvin
Quoted 14 lines · Al Viro
Quoted 13 lines · H. Peter Anvin
Hi Linus,
The following changes since commit
c2f2b01b74be8b40a2173372bcd770723f87e7b2:Merge tag 'i3c/for-6.19' of
git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux(2025-12-08 11:25:14 +0900)are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-auto.gitfor you to fetch changes up to branch auto-type-for-6.19 (
4ecc26fa585216f98d71411ce182f9e823d94c8c):
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
tools/virtio: replace "__auto_type" with "auto" (2025-12-08 15:32:15 -0800)Argh... teaching declaration parser in sparse to handle that is going to be fun, especially since there are corner cases where gcc and clang do not agree, even with --std=c23 --pedantic...
Well, until sparse actually handles C23, this is just a macro.
__auto_typeis already in use.
Just anticipating the joy of getting declaration parser to deal with that properly - there's bunch of fun corner cases where this macro wouldn't cut it. Sure, the underlying semantics can be mapped onto __auto_type, but the actual syntax is bloody awful, especially when you mix the typedefs into it.
Speaking of other fun sparse stuff: __VA_OPT__ support needs to be added; I think I have it plotted down to reasonable details, will post in a day or two...
H. Peter Anvin
reviewerQuoted 30 lines · Al Viro
Quoted 15 lines · H. Peter Anvin
Quoted 14 lines · Al Viro
Quoted 13 lines · H. Peter Anvin
Hi Linus,
The following changes since commit
c2f2b01b74be8b40a2173372bcd770723f87e7b2:Merge tag 'i3c/for-6.19' of
git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux(2025-12-08 11:25:14 +0900)are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-auto.gitfor you to fetch changes up to branch auto-type-for-6.19 (
4ecc26fa585216f98d71411ce182f9e823d94c8c):Quoted 7 lines
Quoted 5 lines
Quoted 1 line
tools/virtio: replace "__auto_type" with "auto" (2025-12-08 15:32:15 -0800)Argh... teaching declaration parser in sparse to handle that is going to be fun, especially since there are corner cases where gcc and clang do not agree, even with --std=c23 --pedantic...
Well, until sparse actually handles C23, this is just a macro.
__auto_typeis already in use.Just anticipating the joy of getting declaration parser to deal with that properly - there's bunch of fun corner cases where this macro wouldn't cut it. Sure, the underlying semantics can be mapped onto
__auto_type, but the actual syntax is bloody awful, especially when you mix the typedefs into it.
Quoted 3 lines
Speaking of other fun sparse stuff:
__VA_OPT__support needs to be added; I think I have it plotted down to reasonable details, will post in a day or two...
Yeah... the C committee even admitted they botched the spec; the intent was for it to work "exactly like gcc __auto_type"...
Al Viro
maintainerQuoted 1 line · H. Peter Anvin
Yeah... the C committee even admitted they botched the spec; the intent was for it to work "exactly like gcc
__auto_type"...
BTW, speaking of C23 fun that is supported by gcc 8, but not by sparse:__has_include().
Do we want it? At the moment nothing in the kernel is using that thing. The main case for that would be <asm/something_optional.h>, and mostly it's dealt with by dummy asm-generic/something_optional.h and mandatory-y in asm-generic/Kbuild, but there are at least some cases where we have it guarded by ifdef, a-la
#ifdef CONFIG_ARCH_HAS_ELFCORE_COMPAT
#include <asm/elfcore-compat.h>
#endif
Linus? Seeing that I'm touching pre-process.c anyway for the sake of __VA_OPT__, adding that thing ought to be reasonably easy - a bit of work in expression_value(), the tricky part being where to stop the
scan: __has_include(< => scan to > and demand ) after it, __has_include(string literal => demand ) after it, __has_include(anything else => scan to matching ), and expand the collected tokens. The same dodge we use for #include ("anything potentially fishy in header-name and it's an UB, so one can simulate it with other pp-tokens") works here...
Quoted 6 lines · Al Viro
BTW, speaking of C23 fun that is supported by gcc 8, but not by sparse:
__has_include().Linus? Seeing that I'm touching
pre-process.canyway for the sake of__VA_OPT__, adding that thing ought to be reasonably easy
It sounds straightforward, and I'm certainly not going to object. I'm not sure how much we'd want to use it in the kernel: it might make it slightly easier to deal with various architectures and the "if the architecture has this header, use it, otherwise use the generic implementation" kinds of issues, but we do have fairly straightforward solutions for that already in our build system ('generic-y' and friends).
So I'm not convinced it really buys us anything - I suspect it's a lot more useful in "normal" projects that have to deal with non-standard system headers and possible lack of libraries etc etc. Our build environment is so self-sufficient that it's not nearly the same issue for the kernel.
Linus
Quoted 4 lines · H. Peter Anvin
git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-auto.gitfor you to fetch changes up to branch auto-type-for-6.19
Oh, and as I was going to merge this, I noticed it's not signed.
Let's not break our perfect recent record of using proper signed tags. when I know you have a pgp key and I even have it on my keyring.
Please?
Linus