Skip to content

Replace "__auto_type" with "auto" #9327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions arch/nios2/include/asm/uaccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/bug.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ do { \
*/
#define __WARN_FLAGS(flags) \
do { \
__auto_type __flags = BUGFLAG_WARNING|(flags); \
auto __flags = BUGFLAG_WARNING|(flags); \
instrumentation_begin(); \
_BUG_FLAGS(ASM_UD2, __flags, ANNOTATE_REACHABLE(1b)); \
instrumentation_end(); \
Expand Down
6 changes: 3 additions & 3 deletions arch/x86/include/asm/string_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ KCFI_REFERENCE(__memset);
#define __HAVE_ARCH_MEMSET16
static inline void *memset16(uint16_t *s, uint16_t v, size_t n)
{
const __auto_type s0 = s;
const auto s0 = s;
asm volatile (
"rep stosw"
: "+D" (s), "+c" (n)
Expand All @@ -44,7 +44,7 @@ static inline void *memset16(uint16_t *s, uint16_t v, size_t n)
#define __HAVE_ARCH_MEMSET32
static inline void *memset32(uint32_t *s, uint32_t v, size_t n)
{
const __auto_type s0 = s;
const auto s0 = s;
asm volatile (
"rep stosl"
: "+D" (s), "+c" (n)
Expand All @@ -57,7 +57,7 @@ static inline void *memset32(uint32_t *s, uint32_t v, size_t n)
#define __HAVE_ARCH_MEMSET64
static inline void *memset64(uint64_t *s, uint64_t v, size_t n)
{
const __auto_type s0 = s;
const auto s0 = s;
asm volatile (
"rep stosq"
: "+D" (s), "+c" (n)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/uaccess_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; })

Expand Down
16 changes: 8 additions & 8 deletions fs/proc/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
auto write = pde->proc_ops->proc_write;
if (write)
return write(file, buf, count, ppos);
return -EIO;
Expand All @@ -347,7 +347,7 @@ static ssize_t proc_reg_write(struct file *file, const char __user *buf, size_t

static __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;
auto poll = pde->proc_ops->proc_poll;
if (poll)
return poll(file, pts);
return DEFAULT_POLLMASK;
Expand All @@ -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;
auto ioctl = pde->proc_ops->proc_ioctl;
if (ioctl)
return ioctl(file, cmd, arg);
return -ENOTTY;
Expand All @@ -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;
auto compat_ioctl = pde->proc_ops->proc_compat_ioctl;
if (compat_ioctl)
return compat_ioctl(file, cmd, arg);
return -ENOTTY;
Expand All @@ -414,7 +414,7 @@ static long proc_reg_compat_ioctl(struct file *file, unsigned int cmd, unsigned

static int pde_mmap(struct proc_dir_entry *pde, struct file *file, struct vm_area_struct *vma)
{
__auto_type mmap = pde->proc_ops->proc_mmap;
auto mmap = pde->proc_ops->proc_mmap;
if (mmap)
return mmap(file, vma);
return -EIO;
Expand Down Expand Up @@ -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;
auto release = pde->proc_ops->proc_release;
if (release) {
pdeo = kmem_cache_alloc(pde_opener_cache, GFP_KERNEL);
if (!pdeo) {
Expand Down Expand Up @@ -534,7 +534,7 @@ 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;
auto release = pde->proc_ops->proc_release;
if (release) {
return release(inode, file);
}
Expand Down
6 changes: 3 additions & 3 deletions include/linux/cleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,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; \
})
Expand Down
2 changes: 1 addition & 1 deletion include/linux/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,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; \
})
Expand Down
13 changes: 13 additions & 0 deletions include/linux/compiler_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions include/linux/minmax.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); })
Expand Down Expand Up @@ -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)); })
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/socket_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
})
Expand Down
2 changes: 1 addition & 1 deletion tools/virtio/linux/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
#define data_race(expr) \
({ \
__auto_type __v = (expr); \
auto __v = (expr); \
__v; \
})

Expand Down
Loading