2020-06-18 23:02:48

by Luc Van Oostenryck

[permalink] [raw]
Subject: [PATCH] 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).

Cc: Marco Elver <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Will Deacon <[email protected]>
Link: https://marc.info/?l=linux-sparse&m=159233481816454
Signed-off-by: Luc Van Oostenryck <[email protected]>
---
include/linux/compiler_types.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index e368384445b6..e34a1080f36b 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -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.
--
2.27.0


2020-06-19 08:26:42

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()

On Fri, Jun 19, 2020 at 12:26:20AM +0200, Luc Van Oostenryck wrote:
> 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).
>
> Cc: Marco Elver <[email protected]>
> Cc: Borislav Petkov <[email protected]>
> Cc: Will Deacon <[email protected]>
> Link: https://marc.info/?l=linux-sparse&m=159233481816454
> Signed-off-by: Luc Van Oostenryck <[email protected]>
> ---
> include/linux/compiler_types.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
> index e368384445b6..e34a1080f36b 100644
> --- a/include/linux/compiler_types.h
> +++ b/include/linux/compiler_types.h
> @@ -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:

Acked-by: Will Deacon <[email protected]>

Will

2020-06-19 09:55:32

by Marco Elver

[permalink] [raw]
Subject: Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()

On Fri, Jun 19, 2020 at 12:26AM +0200, Luc Van Oostenryck wrote:
> 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).
>
> Cc: Marco Elver <[email protected]>
> Cc: Borislav Petkov <[email protected]>
> Cc: Will Deacon <[email protected]>
> Link: https://marc.info/?l=linux-sparse&m=159233481816454
> Signed-off-by: Luc Van Oostenryck <[email protected]>

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:

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

2020-06-19 14:15:09

by Luc Van Oostenryck

[permalink] [raw]
Subject: Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()

On Fri, Jun 19, 2020 at 11:51:05AM +0200, Marco Elver wrote:
> On Fri, Jun 19, 2020 at 12:26AM +0200, Luc Van Oostenryck wrote:
> > 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).
> >
> > Cc: Marco Elver <[email protected]>
> > Cc: Borislav Petkov <[email protected]>
> > Cc: Will Deacon <[email protected]>
> > Link: https://marc.info/?l=linux-sparse&m=159233481816454
> > Signed-off-by: Luc Van Oostenryck <[email protected]>
>
> 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.

> 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

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

2020-06-20 04:25:20

by Linus Torvalds

[permalink] [raw]
Subject: Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()

On Thu, Jun 18, 2020 at 3:26 PM Luc Van Oostenryck
<[email protected]> wrote:
>
> 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

2020-06-20 04:30:09

by Luc Van Oostenryck

[permalink] [raw]
Subject: Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()

On Fri, Jun 19, 2020 at 11:26:59AM -0700, Linus Torvalds wrote:
> On Thu, Jun 18, 2020 at 3:26 PM Luc Van Oostenryck
> <[email protected]> wrote:
> >
> > 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

2020-06-20 05:13:28

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()

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
Reported-by: kernel test robot <[email protected]>

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/[email protected]


Attachments:
(No filename) (2.28 kB)
.config.gz (32.60 kB)
Download all attachments

2020-07-08 19:03:29

by Linus Torvalds

[permalink] [raw]
Subject: Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()

On Thu, Jun 18, 2020 at 3:26 PM Luc Van Oostenryck
<[email protected]> wrote:
>
> 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