aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linearize.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-04-06 15:50:23 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-05-19 05:35:01 +0200
commitb1672eab399fdce2c050e8aa07767489a2071981 (patch)
tree7a7edd535f4747c5e8f84dc6f1ab3181e50746a3 /linearize.c
parent816e13f57644116daf20debe548e3e53ec4e5073 (diff)
downloadsparse-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 'linearize.c')
-rw-r--r--linearize.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/linearize.c b/linearize.c
index 143f1042..e8a1628b 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1634,6 +1634,21 @@ static pseudo_t linearize_one_symbol(struct entrypoint *ep, struct symbol *sym)
sym->initialized = 1;
ad.address = symbol_pseudo(ep, sym);
+
+ if (sym->initializer && !is_scalar_type(sym)) {
+ // default zero initialization [6.7.9.21]
+ // FIXME: this init the whole aggregate while
+ // only the existing fields need to be initialized.
+ // FIXME: this init the whole aggregate even if
+ // all fields arelater explicitely initialized.
+ struct expression *expr = sym->initializer;
+ ad.pos = expr->pos;
+ ad.result_type = sym;
+ ad.source_type = base_type(sym);
+ ad.address = symbol_pseudo(ep, sym);
+ linearize_store_gen(ep, value_pseudo(0), &ad);
+ }
+
value = linearize_initializer(ep, sym->initializer, &ad);
finish_address_gen(ep, &ad);
return value;