diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-04-06 15:50:23 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-05-19 05:35:01 +0200 |
| commit | b1672eab399fdce2c050e8aa07767489a2071981 (patch) | |
| tree | 7a7edd535f4747c5e8f84dc6f1ab3181e50746a3 /validation/linear/struct-init-full.c | |
| parent | 816e13f57644116daf20debe548e3e53ec4e5073 (diff) | |
| download | sparse-dev-b1672eab399fdce2c050e8aa07767489a2071981.tar.gz | |
fix implicit zero initializer.
The C standard requires that, when initializing an aggregate, all
fieds not explicitly initialized shall be implicity zero-initialized
(more exactly "the same as objects that have static storage duration"
[6.7.9.21]).
Until now sparse didn't did this.
Fix this (when an initializer is present and the object not a scalar)
by first storing zeroes in the whole object before doing the
initialization of each fields explicitly initialized.
Note 1: this patch initialize the *whole* aggregate while the
standard only requires that existing fields are initialized.
Thanks to Linus to notice this.
Note 2: this implicit initialization is not needed if all fields are
explicitly initialized but is done anyway, for the moment.
Note 3: the code simplify nicely when there is a single field that is
initialized, much less so when there is several ones.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/linear/struct-init-full.c')
| -rw-r--r-- | validation/linear/struct-init-full.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/validation/linear/struct-init-full.c b/validation/linear/struct-init-full.c new file mode 100644 index 00000000..f1b03db7 --- /dev/null +++ b/validation/linear/struct-init-full.c @@ -0,0 +1,28 @@ +struct s { + int a, b, c; +}; + +struct s s_init_all(int a) +{ + struct s s = { .a = a, .b = 42, .c = 123, }; + return s; +} + +/* + * check-name: struct implicit init zero not needed + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-start +s_init_all: +.L4: + <entry-point> + store.32 %arg1 -> 0[s] + store.32 $42 -> 4[s] + store.32 $123 -> 8[s] + load.96 %r8 <- 0[s] + ret.96 %r8 + + + * check-output-end + */ |
