sparse: use the _Generic() version of __unqual_scalar_typeof()
PATCH 1/1 sparse: use the _Generic() version of __unqual_scalar_typeof()
If the file is being checked with sparse, use the version of __unqual_scalar_typeof() using _Generic(), leaving the unoptimized version only for the oldest versions of GCC.
This reverts commit
b398ace5d2ea ("compiler_types.h: Use unoptimized __unqual_scalar_typeof for sparse")
Note: a recent version of sparse will be needed (minimum v0.6.2-rc2
or later than 2020-05-28).
--- include/linux/compiler_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/compiler_types.h +1 -1
@@ -254,7 +254,7 @@ struct ftrace_likely_data {* __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving * non-scalar types unchanged. */ -#if (defined(CONFIG_CC_IS_GCC ) &&CONFIG_GCC_VERSION <40900 ) || defined(__CHECKER__) +#if defined(CONFIG_CC_IS_GCC ) &&CONFIG_GCC_VERSION <40900 /* * We build this out of a couple of helper macros in a vain attempt to * help you keep your lunch down while reading it.
Signature · 1 line
2.27.0
Quoted 24 lines · Luc Van Oostenryck
If the file is being checked with sparse, use the version of
__unqual_scalar_typeof()using_Generic(), leaving the unoptimized version only for the oldest versions of GCC.This reverts commit
b398ace5d2ea("compiler_types.h: Use unoptimized__unqual_scalar_typeoffor sparse")Note: a recent version of sparse will be needed (minimum v0.6.2-rc2
or later than 2020-05-28).Cc Marco Elver <[email protected]>Cc Borislav Petkov <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Luc Van Oostenryck <[email protected]>--- include/linux/compiler_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/compiler_types.h +0
-0
include/linux/compiler_types.h struct ftrace_likely_data { · line 260
Quoted 8 lines
include/linux/compiler_types.h +1
-1@@ -254,7 +254,7 @@ struct ftrace_likely_data {* __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving * non-scalar types unchanged. */ -#if (defined(CONFIG_CC_IS_GCC ) &&CONFIG_GCC_VERSION <40900 ) || defined(__CHECKER__) +#if defined(CONFIG_CC_IS_GCC ) &&CONFIG_GCC_VERSION <40900 /* * We build this out of a couple of helper macros in a vain attempt to * help you keep your lunch down while reading it.
If you don't mind forcing people to update sparse, then:
Will
Quoted 7 lines · Luc Van Oostenryck
If the file is being checked with sparse, use the version of
__unqual_scalar_typeof()using_Generic(), leaving the unoptimized version only for the oldest versions of GCC.This reverts commit
b398ace5d2ea("compiler_types.h: Use unoptimized__unqual_scalar_typeoffor sparse")
Quoted 8 lines
Note: a recent version of sparse will be needed (minimum v0.6.2-rc2
or later than 2020-05-28).Cc Marco Elver <[email protected]>Cc Borislav Petkov <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Luc Van Oostenryck <[email protected]>
Definitely support this change, so in principle:
But, I think sparse still isn't entirely happy with all legal uses of _Generic. Running latest sparse on:
void test_Generic_conversion(void)
{
#define TEST_WITH_QUALIFIER(type, selection_type) \
do { \
type var = 0; \
_Generic(var, selection_type: (void (*)(type))0)(var); \
} while (0)
/* Expect no errors. */
TEST_WITH_QUALIFIER(const int, int);
TEST_WITH_QUALIFIER(volatile int, int);
TEST_WITH_QUALIFIER(_Atomic int, int);
TEST_WITH_QUALIFIER(register int, int);
}results in
generic-test.c:9:9: error: no generic selection for 'int const var' generic-test.c:10:9: error: no generic selection for 'int volatile var' generic-test.c:11:9: error: no generic selection for 'int [atomic] var'
Whereas GCC or Clang accept this as expected. I can't find the standardese right now, but in [1] we have:
"[...] The conversion is performed in type domain only: it discards the top-level cvr-qualifiers and atomicity and applies array-to-pointer/function-to-pointer transformations to the type of the controlling expression [...]"
[1] https://en.cppreference.com/w/c/language/generic
Thanks,
-- Marco
Quoted 17 lines · Marco Elver
Quoted 7 lines · Luc Van Oostenryck
If the file is being checked with sparse, use the version of
__unqual_scalar_typeof()using_Generic(), leaving the unoptimized version only for the oldest versions of GCC.This reverts commit
b398ace5d2ea("compiler_types.h: Use unoptimized__unqual_scalar_typeoffor sparse")Quoted 8 lines
Note: a recent version of sparse will be needed (minimum v0.6.2-rc2
or later than 2020-05-28).Cc Marco Elver <[email protected]>Cc Borislav Petkov <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Luc Van Oostenryck <[email protected]>
Quoted 6 lines
Definitely support this change, so in principle:
Acked-by Marco Elver <[email protected]>But, I think sparse still isn't entirely happy with all legal uses of
_Generic. Running latest sparse on:
Indeed.
Quoted 9 lines
Whereas GCC or Clang accept this as expected. I can't find the standardese right now, but in [1] we have:
"[...] The conversion is performed in type domain only: it discards the top-level cvr-qualifiers and atomicity and applies array-to-pointer/function-to-pointer transformations to the type of the controlling expression [...]"
Yes, these are the rules following the resolution of DR481, which are now used for C17 and also by gcc & clang for C11 but were not present the C11 standard.
This should be fixed now but I'm waiting for the tests results.
Thanks for reporting this.
-- Luc
Quoted 3 lines · Luc Van Oostenryck
Note: a recent version of sparse will be needed (minimum v0.6.2-rc2
or later than 2020-05-28).
Ok, it sounds like this turns out to be even more recent than that, with the fixes for _Generic.
So i think I'll delay this until 5.9. Mind reminding me?
Linus
Quoted 10 lines · Linus Torvalds
Quoted 3 lines · Luc Van Oostenryck
Note: a recent version of sparse will be needed (minimum v0.6.2-rc2
or later than 2020-05-28).Ok, it sounds like this turns out to be even more recent than that, with the fixes for
_Generic.So i think I'll delay this until 5.9. Mind reminding me?
Sure. No problem.
-- Luc
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi Luc,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linux/master]
[also build test WARNING on linus/master v5.8-rc1 next-20200618] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Luc-Van-Oostenryck/sparse-use-the-_Generic-version-of-__unqual_scalar_typeof/20200619-062703 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 1b5044021070efa3259f3e9548dc35d1eb6aa844 config: i386-randconfig-m021-20200620 (attached as .config) compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
If you fix the issue, kindly add following tag as appropriate
New smatch warnings:kernel/sched/debug.c:965 proc_sched_show_task() warn: inconsistent indenting
Old smatch warnings:include/linux/sched/clock.h:84 local_clock() warn: ignoring unreachable code.
vim +965 kernel/sched/debug.c
43ae34cb4cd650d kernel/sched_debug.c Ingo Molnar 2007-07-09 963
43ae34cb4cd650d kernel/sched_debug.c Ingo Molnar 2007-07-09 964 {
29d7b90c1503574 kernel/sched_debug.c Ingo Molnar 2008-11-16 @965 unsigned int this_cpu = raw_smp_processor_id();
43ae34cb4cd650d kernel/sched_debug.c Ingo Molnar 2007-07-09 966 u64 t0, t1;
43ae34cb4cd650d kernel/sched_debug.c Ingo Molnar 2007-07-09 967
29d7b90c1503574 kernel/sched_debug.c Ingo Molnar 2008-11-16 968 t0 = cpu_clock(this_cpu);
29d7b90c1503574 kernel/sched_debug.c Ingo Molnar 2008-11-16 969 t1 = cpu_clock(this_cpu);
9e3bf9469c29f7e kernel/sched/debug.c Valentin Schneider 2020-02-26 970 __PS("clock-delta", t1-t0);
43ae34cb4cd650d kernel/sched_debug.c Ingo Molnar 2007-07-09 971 }
b32e86b4301e345 kernel/sched/debug.c Ingo Molnar 2013-10-07 972
b32e86b4301e345 kernel/sched/debug.c Ingo Molnar 2013-10-07 973 sched_show_numa(p, m);
43ae34cb4cd650d kernel/sched_debug.c Ingo Molnar 2007-07-09 974 }
43ae34cb4cd650d kernel/sched_debug.c Ingo Molnar 2007-07-09 975 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 4 lines · Luc Van Oostenryck
If the file is being checked with sparse, use the version of
__unqual_scalar_typeof()using_Generic(), leaving the unoptimized version only for the oldest versions of GCC.
Side note: for unrelated reasons I decided to try to just raise the gcc minimum to 4.9, which then makes this patch redundant. The old non-_Generic() case simply doesn't exist any more.
Of course, maybe somebody screams about having to use some gcc-4.8 version in their environment so much that I'll revert it, but I doubt it. gcc-4.8 had lots of problems.
Linus