xen/treewide: More typeof() -> auto conversions
PATCH 1/1 xen/treewide: More typeof() -> auto conversions
All of these are simple cases of using typeof() to avoid multiple parameter evaluation. Using auto avoids multiple textural expansion also.
No functional change.
---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
There's an oddity with SMCCC. 4 or fewer args strictly use unsigned long for ouput types where 5 or more use a dynamic type. I've left it as-was, but it looks wrong.
https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2287583251
--- xen/arch/arm/include/asm/smccc.h | 26 +++---- xen/arch/x86/include/asm/alternative-call.h | 84 ++++++++++----------- xen/common/bitops.c | 2 +- xen/include/xen/bitops.h | 4 +- xen/include/xen/nospec.h | 4 +- xen/include/xen/self-tests.h | 4 +- 6 files changed, 62 insertions(+), 62 deletions(-)
xen/arch/arm/include/asm/smccc.h +13 -13
@@ -129,7 +129,7 @@ struct arm_smccc_res { register unsigned long r3 ASM_REG(3)#define __declare_arg_1 (a0, a1, res) \ - typeof(a1) __a1 = (a1); \ + auto __a1 = (a1); \ struct arm_smccc_res *___res = (res); \ register unsigned long r0 ASM_REG(0) = (uint32_t)(a0); \ register unsigned long r1 ASM_REG(1) = __a1; \
@@ -137,8 +137,8 @@ struct arm_smccc_res { register unsigned long r3 ASM_REG(3)#define __declare_arg_2 (a0, a1, a2, res) \ - typeof(a1) __a1 = (a1); \ - typeof(a2) __a2 = (a2); \ + auto __a1 = (a1); \ + auto __a2 = (a2); \ struct arm_smccc_res *___res = (res); \ register unsigned long r0 ASM_REG(0) = (uint32_t)(a0); \ register unsigned long r1 ASM_REG(1) = __a1; \
@@ -146,9 +146,9 @@ struct arm_smccc_res { register unsigned long r3 ASM_REG(3)#define __declare_arg_3 (a0, a1, a2, a3, res) \ - typeof(a1) __a1 = (a1); \ - typeof(a2) __a2 = (a2); \ - typeof(a3) __a3 = (a3); \ + auto __a1 = (a1); \ + auto __a2 = (a2); \ + auto __a3 = (a3); \ struct arm_smccc_res *___res = (res); \ register unsigned long r0 ASM_REG(0) = (uint32_t)(a0); \ register unsigned long r1 ASM_REG(1) = __a1; \
@@ -156,24 +156,24 @@ struct arm_smccc_res { register unsigned long r3 ASM_REG(3) = __a3#define __declare_arg_4 (a0, a1, a2, a3, a4, res) \ - typeof(a4) __a4 = (a4); \ + auto __a4 = (a4); \ __declare_arg_3(a0, a1, a2, a3, res); \ register unsigned long r4 ASM_REG(4) = __a4#define __declare_arg_5 (a0, a1, a2, a3, a4, a5, res) \ - typeof(a5) __a5 = (a5); \ + auto __a5 = (a5); \ __declare_arg_4(a0, a1, a2, a3, a4, res); \ - register typeof(a5) r5 ASM_REG(5) = __a5 + register auto r5 ASM_REG(5) = __a5#define __declare_arg_6 (a0, a1, a2, a3, a4, a5, a6, res) \ - typeof(a6) __a6 = (a6); \ + auto __a6 = (a6); \ __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ - register typeof(a6) r6 ASM_REG(6) = __a6 + register auto r6 ASM_REG(6) = __a6#define __declare_arg_7 (a0, a1, a2, a3, a4, a5, a6, a7, res) \ - typeof(a7) __a7 = (a7); \ + auto __a7 = (a7); \ __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ - register typeof(a7) r7 ASM_REG(7) = __a7 + register auto r7 ASM_REG(7) = __a7#define ___declare_args (count, ...) __declare_arg_ ## count(__VA_ARGS__)#define __declare_args (count, ...) ___declare_args(count, __VA_ARGS__)
xen/arch/x86/include/asm/alternative-call.h +42 -42
156 lines not on this page · raw message
xen/common/bitops.c +1 -1
@@ -147,7 +147,7 @@ static void __init test_for_each_set_bit(void)* A copy of @val is taken internally. */ #define for_each_set_bit_reverse (iter, val) \ - for ( typeof(val) __v = (val); __v; __v = 0 ) \ + for ( auto __v = (val); __v; __v = 0 ) \ for ( unsigned int (iter); \ __v && ((iter) = fls_g(__v) - 1, true); \ __clear_bit(iter, &__v) )
xen/include/xen/bitops.h +2 -2
@@ -299,7 +299,7 @@ static always_inline attr_const unsigned int fls64(uint64_t x)* A copy of @val is taken internally. */ #define for_each_set_bit (iter, val) \ - for ( typeof(val) __v = (val); __v; __v = 0 ) \ + for ( auto __v = (val); __v; __v = 0 ) \ for ( unsigned int (iter); \ __v && ((iter) = ffs_g(__v) - 1, true); \ __v &= __v - 1 )
@@ -310,7 +310,7 @@ static always_inline attr_const unsigned int fls64(uint64_t x)*/ #define multiple_bits_set (x) \ ({ \ - typeof(x) _v = (x); \ + auto _v = (x); \ (_v & (_v - 1)) != 0; \ })
xen/include/xen/nospec.h +2 -2
@@ -51,8 +51,8 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,*/ #define array_index_nospec (index, size) \ ({ \ - typeof(index) _i = (index); \ - typeof(size) _s = (size); \ + auto _i = (index); \ + auto _s = (size); \ unsigned long _mask = array_index_mask_nospec(_i, _s); \ \ BUILD_BUG_ON(sizeof(_i) > sizeof(long)); \
xen/include/xen/self-tests.h +2 -2
@@ -18,7 +18,7 @@*/ #define COMPILE_CHECK (fn, val, res) \ do { \ - typeof(fn(val)) real = fn(val); \ + auto real = fn(val); \ \ if ( !__builtin_constant_p(real) ) \ BUILD_ERROR("'" STR(fn(val)) "' not compile-time constant"); \
@@ -36,7 +36,7 @@*/ #define RUNTIME_CHECK (fn, val, res) \ do { \ - typeof(fn(val)) real = fn(HIDE(val)); \ + auto real = fn(HIDE(val)); \ \ if ( real != (res) ) \ panic("%s: %s(%s) expected %u, got %u\n", \
Signature · 1 line
2.39.5
Quoted 6 lines · Andrew Cooper
All of these are simple cases of using
typeof()to avoid multiple parameter evaluation. Using auto avoids multiple textural expansion also.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
All of these are simple cases of using
typeof()to avoid multiple parameter evaluation. Using auto avoids multiple textural expansion also.No functional change.
Signed-off-by Andrew Cooper <[email protected]>Acked-by Jan Beulich <[email protected]>
Thanks.
While I've got people's attentions, there's a secondary pattern we use that's a bit less clear to convert.
typeof(a) *_ptr_a = &a;
With auto, you're required to write this as:
auto _ptr_a = &a;
rather than the more-nomal-looking:
auto *_ptr_a = &a;
So far I've only found two examples, and I'm debating leaving them as are seeing as auto (in this form) is still a new concept to most.
Thoughts?
~Andrew
Quoted 23 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
All of these are simple cases of using
typeof()to avoid multiple parameter evaluation. Using auto avoids multiple textural expansion also.No functional change.
Signed-off-by Andrew Cooper <[email protected]>Acked-by Jan Beulich <[email protected]>Thanks.
While I've got people's attentions, there's a secondary pattern we use that's a bit less clear to convert.
typeof(a)
*_ptr_a= &a;With auto, you're required to write this as:
auto
_ptr_a= &a;rather than the more-nomal-looking:
Quoted 7 lines
auto
*_ptr_a= &a;So far I've only found two examples, and I'm debating leaving them as are seeing as auto (in this form) is still a new concept to most.
Thoughts?
If already we're moving to the use of auto, I think such want converting as well. "auto" meaning "type of rhs", this necessarily implies absence of pointer-ness in the type. Really, is "auto *" actually a construct which could make sense in some specific situation? This and the rhs type are (seemingly) guaranteed to conflict.
Jan
Hi Andrew,
Quoted 8 lines · Andrew Cooper
All of these are simple cases of using
typeof()to avoid multiple parameter evaluation. Using auto avoids multiple textural expansion also.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Compiles and boot on arm:
For arm:
Quoted 10 lines
---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
Quoted 3 lines
There's an oddity with SMCCC. 4 or fewer args strictly use unsigned long for ouput types where 5 or more use a dynamic type. I've left it as-was, but it looks wrong.
I will have a look at that, thanks for the notice.
Bertrand
Quoted 326 lines
https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2287583251
---xen/arch/arm/include/asm/smccc.h | 26 +++---- xen/arch/x86/include/asm/alternative-call.h | 84 ++++++++++----------- xen/common/bitops.c | 2 +- xen/include/xen/bitops.h | 4 +- xen/include/xen/nospec.h | 4 +- xen/include/xen/self-tests.h | 4 +- 6 files changed, 62 insertions(+), 62 deletions(-)xen/arch/arm/include/asm/smccc.h +13
-13@@ -129,7 +129,7 @@ struct arm_smccc_res { register unsigned long r3 ASM_REG(3)#define __declare_arg_1 (a0, a1, res) \ - typeof(a1) __a1 = (a1); \ + auto __a1 = (a1); \ struct arm_smccc_res *___res = (res); \ register unsigned long r0 ASM_REG(0) = (uint32_t)(a0); \ register unsigned long r1 ASM_REG(1) = __a1; \@@ -137,8 +137,8 @@ struct arm_smccc_res { register unsigned long r3 ASM_REG(3)#define __declare_arg_2 (a0, a1, a2, res) \ - typeof(a1) __a1 = (a1); \ - typeof(a2) __a2 = (a2); \ + auto __a1 = (a1); \ + auto __a2 = (a2); \ struct arm_smccc_res *___res = (res); \ register unsigned long r0 ASM_REG(0) = (uint32_t)(a0); \ register unsigned long r1 ASM_REG(1) = __a1; \@@ -146,9 +146,9 @@ struct arm_smccc_res { register unsigned long r3 ASM_REG(3)#define __declare_arg_3 (a0, a1, a2, a3, res) \ - typeof(a1) __a1 = (a1); \ - typeof(a2) __a2 = (a2); \ - typeof(a3) __a3 = (a3); \ + auto __a1 = (a1); \ + auto __a2 = (a2); \ + auto __a3 = (a3); \ struct arm_smccc_res *___res = (res); \ register unsigned long r0 ASM_REG(0) = (uint32_t)(a0); \ register unsigned long r1 ASM_REG(1) = __a1; \@@ -156,24 +156,24 @@ struct arm_smccc_res { register unsigned long r3 ASM_REG(3) = __a3#define __declare_arg_4 (a0, a1, a2, a3, a4, res) \ - typeof(a4) __a4 = (a4); \ + auto __a4 = (a4); \ __declare_arg_3(a0, a1, a2, a3, res); \ register unsigned long r4 ASM_REG(4) = __a4#define __declare_arg_5 (a0, a1, a2, a3, a4, a5, res) \ - typeof(a5) __a5 = (a5); \ + auto __a5 = (a5); \ __declare_arg_4(a0, a1, a2, a3, a4, res); \ - register typeof(a5) r5 ASM_REG(5) = __a5 + register auto r5 ASM_REG(5) = __a5#define __declare_arg_6 (a0, a1, a2, a3, a4, a5, a6, res) \ - typeof(a6) __a6 = (a6); \ + auto __a6 = (a6); \ __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ - register typeof(a6) r6 ASM_REG(6) = __a6 + register auto r6 ASM_REG(6) = __a6#define __declare_arg_7 (a0, a1, a2, a3, a4, a5, a6, a7, res) \ - typeof(a7) __a7 = (a7); \ + auto __a7 = (a7); \ __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ - register typeof(a7) r7 ASM_REG(7) = __a7 + register auto r7 ASM_REG(7) = __a7#define ___declare_args (count, ...) __declare_arg_ ## count(__VA_ARGS__)#define __declare_args (count, ...) ___declare_args(count, __VA_ARGS__)xen/arch/x86/include/asm/alternative-call.h +42
-42@@ -111,7 +111,7 @@ struct alt_call { })#define alternative_vcall1 (func, arg) ({ \ - typeof(arg) v1_ = (arg); \ + auto v1_ = (arg); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_NO_ARG2; \ (void)sizeof(func(arg)); \@@ -119,15 +119,15 @@ struct alt_call { })#define alternative_call1 (func, arg) ({ \ - typeof(arg) v1_ = (arg); \ + auto v1_ = (arg); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_NO_ARG2; \ alternative_callN(1, typeof(func(arg)), func); \ })#define alternative_vcall2 (func, arg1, arg2) ({ \ - typeof(arg1) v1_ = (arg1); \ - typeof(arg2) v2_ = (arg2); \ + auto v1_ = (arg1); \ + auto v2_ = (arg2); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_ARG(v2_, 2); \ ALT_CALL_NO_ARG3; \@@ -136,8 +136,8 @@ struct alt_call { })#define alternative_call2 (func, arg1, arg2) ({ \ - typeof(arg1) v1_ = (arg1); \ - typeof(arg2) v2_ = (arg2); \ + auto v1_ = (arg1); \ + auto v2_ = (arg2); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_ARG(v2_, 2); \ ALT_CALL_NO_ARG3; \@@ -145,9 +145,9 @@ struct alt_call { })#define alternative_vcall3 (func, arg1, arg2, arg3) ({ \ - typeof(arg1) v1_ = (arg1); \ - typeof(arg2) v2_ = (arg2); \ - typeof(arg3) v3_ = (arg3); \ + auto v1_ = (arg1); \ + auto v2_ = (arg2); \ + auto v3_ = (arg3); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_ARG(v2_, 2); \ ALT_CALL_ARG(v3_, 3); \@@ -157,9 +157,9 @@ struct alt_call { })#define alternative_call3 (func, arg1, arg2, arg3) ({ \ - typeof(arg1) v1_ = (arg1); \ - typeof(arg2) v2_ = (arg2); \ - typeof(arg3) v3_ = (arg3); \ + auto v1_ = (arg1); \ + auto v2_ = (arg2); \ + auto v3_ = (arg3); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_ARG(v2_, 2); \ ALT_CALL_ARG(v3_, 3); \@@ -169,10 +169,10 @@ struct alt_call { })#define alternative_vcall4 (func, arg1, arg2, arg3, arg4) ({ \ - typeof(arg1) v1_ = (arg1); \ - typeof(arg2) v2_ = (arg2); \ - typeof(arg3) v3_ = (arg3); \ - typeof(arg4) v4_ = (arg4); \ + auto v1_ = (arg1); \ + auto v2_ = (arg2); \ + auto v3_ = (arg3); \ + auto v4_ = (arg4); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_ARG(v2_, 2); \ ALT_CALL_ARG(v3_, 3); \@@ -183,10 +183,10 @@ struct alt_call { })#define alternative_call4 (func, arg1, arg2, arg3, arg4) ({ \ - typeof(arg1) v1_ = (arg1); \ - typeof(arg2) v2_ = (arg2); \ - typeof(arg3) v3_ = (arg3); \ - typeof(arg4) v4_ = (arg4); \ + auto v1_ = (arg1); \ + auto v2_ = (arg2); \ + auto v3_ = (arg3); \ + auto v4_ = (arg4); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_ARG(v2_, 2); \ ALT_CALL_ARG(v3_, 3); \@@ -198,11 +198,11 @@ struct alt_call { })#define alternative_vcall5 (func, arg1, arg2, arg3, arg4, arg5) ({ \ - typeof(arg1) v1_ = (arg1); \ - typeof(arg2) v2_ = (arg2); \ - typeof(arg3) v3_ = (arg3); \ - typeof(arg4) v4_ = (arg4); \ - typeof(arg5) v5_ = (arg5); \ + auto v1_ = (arg1); \ + auto v2_ = (arg2); \ + auto v3_ = (arg3); \ + auto v4_ = (arg4); \ + auto v5_ = (arg5); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_ARG(v2_, 2); \ ALT_CALL_ARG(v3_, 3); \@@ -214,11 +214,11 @@ struct alt_call { })#define alternative_call5 (func, arg1, arg2, arg3, arg4, arg5) ({ \ - typeof(arg1) v1_ = (arg1); \ - typeof(arg2) v2_ = (arg2); \ - typeof(arg3) v3_ = (arg3); \ - typeof(arg4) v4_ = (arg4); \ - typeof(arg5) v5_ = (arg5); \ + auto v1_ = (arg1); \ + auto v2_ = (arg2); \ + auto v3_ = (arg3); \ + auto v4_ = (arg4); \ + auto v5_ = (arg5); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_ARG(v2_, 2); \ ALT_CALL_ARG(v3_, 3); \@@ -231,12 +231,12 @@ struct alt_call { })#define alternative_vcall6 (func, arg1, arg2, arg3, arg4, arg5, arg6) ({ \ - typeof(arg1) v1_ = (arg1); \ - typeof(arg2) v2_ = (arg2); \ - typeof(arg3) v3_ = (arg3); \ - typeof(arg4) v4_ = (arg4); \ - typeof(arg5) v5_ = (arg5); \ - typeof(arg6) v6_ = (arg6); \ + auto v1_ = (arg1); \ + auto v2_ = (arg2); \ + auto v3_ = (arg3); \ + auto v4_ = (arg4); \ + auto v5_ = (arg5); \ + auto v6_ = (arg6); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_ARG(v2_, 2); \ ALT_CALL_ARG(v3_, 3); \@@ -248,12 +248,12 @@ struct alt_call { })#define alternative_call6 (func, arg1, arg2, arg3, arg4, arg5, arg6) ({ \ - typeof(arg1) v1_ = (arg1); \ - typeof(arg2) v2_ = (arg2); \ - typeof(arg3) v3_ = (arg3); \ - typeof(arg4) v4_ = (arg4); \ - typeof(arg5) v5_ = (arg5); \ - typeof(arg6) v6_ = (arg6); \ + auto v1_ = (arg1); \ + auto v2_ = (arg2); \ + auto v3_ = (arg3); \ + auto v4_ = (arg4); \ + auto v5_ = (arg5); \ + auto v6_ = (arg6); \ ALT_CALL_ARG(v1_, 1); \ ALT_CALL_ARG(v2_, 2); \ ALT_CALL_ARG(v3_, 3); \xen/common/bitops.c +1
-1@@ -147,7 +147,7 @@ static void __init test_for_each_set_bit(void)* A copy of @val is taken internally. */ #define for_each_set_bit_reverse (iter, val) \ - for ( typeof(val) __v = (val); __v; __v = 0 ) \ + for ( auto __v = (val); __v; __v = 0 ) \ for ( unsigned int (iter); \ __v && ((iter) = fls_g(__v) - 1, true); \ __clear_bit(iter, &__v) )xen/include/xen/bitops.h +2
-2@@ -299,7 +299,7 @@ static always_inline attr_const unsigned int fls64(uint64_t x)* A copy of @val is taken internally. */ #define for_each_set_bit (iter, val) \ - for ( typeof(val) __v = (val); __v; __v = 0 ) \ + for ( auto __v = (val); __v; __v = 0 ) \ for ( unsigned int (iter); \ __v && ((iter) = ffs_g(__v) - 1, true); \ __v &= __v - 1 )@@ -310,7 +310,7 @@ static always_inline attr_const unsigned int fls64(uint64_t x)*/ #define multiple_bits_set (x) \ ({ \ - typeof(x) _v = (x); \ + auto _v = (x); \ (_v & (_v - 1)) != 0; \ })xen/include/xen/nospec.h +2
-2@@ -51,8 +51,8 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,*/ #define array_index_nospec (index, size) \ ({ \ - typeof(index) _i = (index); \ - typeof(size) _s = (size); \ + auto _i = (index); \ + auto _s = (size); \ unsigned long _mask = array_index_mask_nospec(_i, _s); \ \ BUILD_BUG_ON(sizeof(_i) > sizeof(long)); \xen/include/xen/self-tests.h +2
-2@@ -18,7 +18,7 @@*/ #define COMPILE_CHECK (fn, val, res) \ do { \ - typeof(fn(val)) real = fn(val); \ + auto real = fn(val); \ \ if ( !__builtin_constant_p(real) ) \ BUILD_ERROR("'" STR(fn(val)) "' not compile-time constant"); \@@ -36,7 +36,7 @@*/ #define RUNTIME_CHECK (fn, val, res) \ do { \ - typeof(fn(val)) real = fn(HIDE(val)); \ + auto real = fn(HIDE(val)); \ \ if ( real != (res) ) \ panic("%s: %s(%s) expected %u, got %u\n", \Signature · 1 line
2.39.5