linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()
@ 2020-06-18 22:26 Luc Van Oostenryck
  2020-06-19  8:23 ` Will Deacon
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Luc Van Oostenryck @ 2020-06-18 22:26 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: linux-kernel, Luc Van Oostenryck, Marco Elver, Borislav Petkov,
	Will Deacon

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 <elver@google.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Will Deacon <will@kernel.org>
Link: https://marc.info/?l=linux-sparse&m=159233481816454
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()
  2020-06-18 22:26 [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof() Luc Van Oostenryck
@ 2020-06-19  8:23 ` Will Deacon
  2020-06-19  9:51 ` Marco Elver
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2020-06-19  8:23 UTC (permalink / raw)
  To: Luc Van Oostenryck
  Cc: Linus Torvalds, linux-kernel, Marco Elver, Borislav Petkov

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 <elver@google.com>
> Cc: Borislav Petkov <bp@suse.de>
> Cc: Will Deacon <will@kernel.org>
> Link: https://marc.info/?l=linux-sparse&m=159233481816454
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> ---
>  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 <will@kernel.org>

Will

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()
  2020-06-18 22:26 [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof() Luc Van Oostenryck
  2020-06-19  8:23 ` Will Deacon
@ 2020-06-19  9:51 ` Marco Elver
  2020-06-19 14:12   ` Luc Van Oostenryck
  2020-06-19 18:26 ` Linus Torvalds
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Marco Elver @ 2020-06-19  9:51 UTC (permalink / raw)
  To: Luc Van Oostenryck
  Cc: Linus Torvalds, linux-kernel, Borislav Petkov, Will Deacon

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 <elver@google.com>
> Cc: Borislav Petkov <bp@suse.de>
> Cc: Will Deacon <will@kernel.org>
> Link: https://marc.info/?l=linux-sparse&m=159233481816454
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>

Definitely support this change, so in principle:

	Acked-by: Marco Elver <elver@google.com>

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()
  2020-06-19  9:51 ` Marco Elver
@ 2020-06-19 14:12   ` Luc Van Oostenryck
  0 siblings, 0 replies; 8+ messages in thread
From: Luc Van Oostenryck @ 2020-06-19 14:12 UTC (permalink / raw)
  To: Marco Elver; +Cc: Linus Torvalds, linux-kernel, Borislav Petkov, Will Deacon

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 <elver@google.com>
> > Cc: Borislav Petkov <bp@suse.de>
> > Cc: Will Deacon <will@kernel.org>
> > Link: https://marc.info/?l=linux-sparse&m=159233481816454
> > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> 
> Definitely support this change, so in principle:
> 
> 	Acked-by: Marco Elver <elver@google.com>
> 
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()
  2020-06-18 22:26 [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof() Luc Van Oostenryck
  2020-06-19  8:23 ` Will Deacon
  2020-06-19  9:51 ` Marco Elver
@ 2020-06-19 18:26 ` Linus Torvalds
  2020-06-19 19:08   ` Luc Van Oostenryck
  2020-06-20  4:32 ` kernel test robot
  2020-07-08 19:02 ` Linus Torvalds
  4 siblings, 1 reply; 8+ messages in thread
From: Linus Torvalds @ 2020-06-19 18:26 UTC (permalink / raw)
  To: Luc Van Oostenryck
  Cc: Linux Kernel Mailing List, Marco Elver, Borislav Petkov, Will Deacon

On Thu, Jun 18, 2020 at 3:26 PM Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()
  2020-06-19 18:26 ` Linus Torvalds
@ 2020-06-19 19:08   ` Luc Van Oostenryck
  0 siblings, 0 replies; 8+ messages in thread
From: Luc Van Oostenryck @ 2020-06-19 19:08 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Linux Kernel Mailing List, Marco Elver, Borislav Petkov, Will Deacon

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
> <luc.vanoostenryck@gmail.com> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()
  2020-06-18 22:26 [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof() Luc Van Oostenryck
                   ` (2 preceding siblings ...)
  2020-06-19 18:26 ` Linus Torvalds
@ 2020-06-20  4:32 ` kernel test robot
  2020-07-08 19:02 ` Linus Torvalds
  4 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2020-06-20  4:32 UTC (permalink / raw)
  To: Luc Van Oostenryck, Linus Torvalds
  Cc: kbuild-all, LKML, Luc Van Oostenryck, Marco Elver,
	Borislav Petkov, Will Deacon

[-- Attachment #1: Type: text/plain, Size: 2293 bytes --]

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 <lkp@intel.com>

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@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33379 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof()
  2020-06-18 22:26 [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof() Luc Van Oostenryck
                   ` (3 preceding siblings ...)
  2020-06-20  4:32 ` kernel test robot
@ 2020-07-08 19:02 ` Linus Torvalds
  4 siblings, 0 replies; 8+ messages in thread
From: Linus Torvalds @ 2020-07-08 19:02 UTC (permalink / raw)
  To: Luc Van Oostenryck
  Cc: Linux Kernel Mailing List, Marco Elver, Borislav Petkov, Will Deacon

On Thu, Jun 18, 2020 at 3:26 PM Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-07-08 19:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-18 22:26 [PATCH] sparse: use the _Generic() version of __unqual_scalar_typeof() Luc Van Oostenryck
2020-06-19  8:23 ` Will Deacon
2020-06-19  9:51 ` Marco Elver
2020-06-19 14:12   ` Luc Van Oostenryck
2020-06-19 18:26 ` Linus Torvalds
2020-06-19 19:08   ` Luc Van Oostenryck
2020-06-20  4:32 ` kernel test robot
2020-07-08 19:02 ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).