diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-06-01 23:23:54 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-06-03 13:17:35 +0200 |
| commit | 3800353ba503dc700ee3803a6fa4729f03e702ff (patch) | |
| tree | 2d2f5dfef589d43712460d92cf7f883eb4cd81c4 /validation | |
| parent | 0ee050a84a2986193060a7cf2241e993fbfc4f30 (diff) | |
| download | sparse-dev-3800353ba503dc700ee3803a6fa4729f03e702ff.tar.gz | |
univ-init: scalar initializer needs some additional checks
Currently, -Wno-universal-initializer is simply implemented
by simply replacing '{ 0 }' by '{ }'.
However, this is a bit too simple when it concerns scalars
initialized with '{ 0 }' because:
* sparse & GCC issued warnings for empty scalar initializers
* initializing a pointer with '{ }' is extra bad.
So, restore the old behaviour for scalar initializers.
This is done by leaving '{ 0 }' as-is at parse time and changing
it as '{ }' only at evaluation time for compound initializers.
Fixes: 537e3e2daebd37d69447e65535fc94e82b38fc18
Thanks-to: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/Wuniv-init-ko.c | 17 | ||||
| -rw-r--r-- | validation/Wuniv-init-ok.c | 18 |
2 files changed, 35 insertions, 0 deletions
diff --git a/validation/Wuniv-init-ko.c b/validation/Wuniv-init-ko.c index 315c211a..1fb5669f 100644 --- a/validation/Wuniv-init-ko.c +++ b/validation/Wuniv-init-ko.c @@ -4,11 +4,28 @@ struct s { static struct s s = { 0 }; +static int a = { 0 }; +static int b = { }; +static int c = { 1, 2 }; +static struct s *ptr = { 0 }; + +struct o { + struct i { + int a; + }; +}; + +static struct o o = { 0 }; /* * check-name: univ-init-ko + * check-command: sparse -Wuniversal-initializer $file * * check-error-start Wuniv-init-ko.c:6:23: warning: Using plain integer as NULL pointer +Wuniv-init-ko.c:8:16: error: invalid initializer +Wuniv-init-ko.c:9:16: error: invalid initializer +Wuniv-init-ko.c:10:26: warning: Using plain integer as NULL pointer +Wuniv-init-ko.c:18:23: warning: missing braces around initializer * check-error-end */ diff --git a/validation/Wuniv-init-ok.c b/validation/Wuniv-init-ok.c index c3964751..1f0c3dcb 100644 --- a/validation/Wuniv-init-ok.c +++ b/validation/Wuniv-init-ok.c @@ -4,8 +4,26 @@ struct s { static struct s s = { 0 }; +static int a = { 0 }; +static int b = { }; +static int c = { 1, 2 }; +static struct s *ptr = { 0 }; + +struct o { + struct i { + int a; + }; +}; + +static struct o o = { 0 }; /* * check-name: univ-init-ok * check-command: sparse -Wno-universal-initializer $file + * + * check-error-start +Wuniv-init-ok.c:8:16: error: invalid initializer +Wuniv-init-ok.c:9:16: error: invalid initializer +Wuniv-init-ok.c:10:26: warning: Using plain integer as NULL pointer + * check-error-end */ |
