threads / patch / 53532

v2sparse: allow '{ 0 }' to be used without warnings

Subject: [PATCH v2] sparse: allow '{ 0 }' to be used without warnings

## tl;dr

4 messages between May 22, 2020 and May 31, 2020. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Luc Van Oostenryck· May 22, 2020, 00:25 UTC · lore

In standard C, '{ 0 }' can be used as an universal zero-initializer. However, Sparse complains if this is used on a type where the first member (possibly nested) is a pointer since Sparse purposely wants to warn when '0' is used to initialize a pointer type.

Legitimaly, it's desirable to be able to use '{ 0 }' as an idiom
without these warnings [1,2]. To allow this, an option have now
been added to Sparse:
    537e3e2dae univ-init: conditionally accept { 0 } without warnings
So, add this option to the SPARSE_FLAGS variable.
Note: The option have just been added to Sparse. So, to benefit
      now from this patch it's needed to use the latest Sparse
      source from kernel.org. The option will simply be ignored
      by older versions of Sparse.

[1] https://lore.kernel.org/r/e6796c60-a870-e761-3b07-b680f934c537@ramsayjones.plus.com [2] https://lore.kernel.org/r/xmqqd07xem9l.fsf@gitster.c.googlers.com

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
Change since v1:
* adapt the commit message to:
  - fix a typo
  - give a reference to the Spatch patch
  - add a note telling the latest Sparse source is needed to
    benefit from the patch but older versions won't complain.
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to Makefile +1 −1
diff --git a/Makefile b/Makefile
index 3d3a39fc19..69f065ef8c 100644
--- a/Makefile
+++ b/Makefile
@@ -1189,7 +1189,7 @@ PTHREAD_CFLAGS =
 
 # For the 'sparse' target
 SPARSE_FLAGS ?=
-SP_EXTRA_FLAGS =
+SP_EXTRA_FLAGS = -Wno-universal-initializer
 
 # For the 'coccicheck' target; setting SPATCH_BATCH_SIZE higher will
 # usually result in less CPU usage at the cost of higher peak memory.
-- 
2.26.2
Junio C Hamano· May 24, 2020, 16:17 UTC · re: Luc Van Oostenryck · lore

Re: [PATCH v2] sparse: allow '{ 0 }' to be used without warnings

Luc Van Oostenryck <luc.vanoostenryck@gmail.com> writes:
> Note: The option have just been added to Sparse. So, to benefit
>       now from this patch it's needed to use the latest Sparse
>       source from kernel.org. The option will simply be ignored
>       by older versions of Sparse.

The last sentence in this paragraph is very very much appreciated ;-)

Show 30 quoted lines
>
> [1] https://lore.kernel.org/r/e6796c60-a870-e761-3b07-b680f934c537@ramsayjones.plus.com
> [2] https://lore.kernel.org/r/xmqqd07xem9l.fsf@gitster.c.googlers.com
>
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> ---
>
> Change since v1:
> * adapt the commit message to:
>   - fix a typo
>   - give a reference to the Spatch patch
>   - add a note telling the latest Sparse source is needed to
>     benefit from the patch but older versions won't complain.
>
>  Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Makefile b/Makefile
> index 3d3a39fc19..69f065ef8c 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1189,7 +1189,7 @@ PTHREAD_CFLAGS =
>  
>  # For the 'sparse' target
>  SPARSE_FLAGS ?=
> -SP_EXTRA_FLAGS =
> +SP_EXTRA_FLAGS = -Wno-universal-initializer
>  
>  # For the 'coccicheck' target; setting SPATCH_BATCH_SIZE higher will
>  # usually result in less CPU usage at the cost of higher peak memory.
Luc Van Oostenryck· May 30, 2020, 16:24 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] sparse: allow '{ 0 }' to be used without warnings

Hi Junio,

I've now changed Sparse's default to not warn when using '{ 0 }'. This flag is thus now unneeded for Git and can be dropped (but it won't hurt to keep it).

-- Luc
Junio C Hamano· May 31, 2020, 16:48 UTC · re: Luc Van Oostenryck · lore

Re: [PATCH v2] sparse: allow '{ 0 }' to be used without warnings

Luc Van Oostenryck <luc.vanoostenryck@gmail.com> writes:
> I've now changed Sparse's default to not warn when using '{ 0 }'.
> This flag is thus now unneeded for Git and can be dropped
> (but it won't hurt to keep it).
Nice.  Thanks.

← back to recent threads