threads / patch / 53530

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

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

## tl;dr

3 messages between May 21, 2020 and May 21, 2020. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Luc Van Oostenryck· May 21, 2020, 21:45 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 idom without these warnings [1,2].

An option have now been added to Sparse to turn off such warnings. So, add this option to the SPARSE_FLAGS variable.

[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>
---
 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
Eric Sunshine· May 21, 2020, 21:50 UTC · re: Luc Van Oostenryck · lore

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

On Thu, May 21, 2020 at 5:46 PM Luc Van Oostenryck <luc.vanoostenryck@gmail.com> wrote:

Show 7 quoted lines
> 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 idom
> without these warnings [1,2].
s/idom/idiom/
> An option have now been added to Sparse to turn off such warnings.
> So, add this option to the SPARSE_FLAGS variable.

Do you have a reference to the commit or Sparse release notes which mention this new option? It might be nice to include it here in the commit message. Also, should this minimum Sparse version be mentioned somewhere in documentation so that people invoking the "sparse" makefile target aren't greeted with an error about -Wno-universal-initializer being an unrecognized option (assuming that older Sparse would complain about it)?

> [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>
Junio C Hamano· May 21, 2020, 22:08 UTC · re: Eric Sunshine · lore

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

Eric Sunshine <sunshine@sunshineco.com> writes:
Show 7 quoted lines
> Do you have a reference to the commit or Sparse release notes which
> mention this new option? It might be nice to include it here in the
> commit message. Also, should this minimum Sparse version be mentioned
> somewhere in documentation so that people invoking the "sparse"
> makefile target aren't greeted with an error about
> -Wno-universal-initializer being an unrecognized option (assuming that
> older Sparse would complain about it)?
Both sensible considerations.  Thanks for bringing them up.
Show 5 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>

← back to recent threads