aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimplify.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2005-08-23 09:28:26 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2005-08-23 09:28:26 +0200
commit73ed17ff80da57d02cdb33b0035d5e718ed39fa2 (patch)
treef384afa06e592a553c6af6af04e511b95114c8d8 /gcc/gimplify.c
parent18b10a7276e8d33f3f77ff80225adc4df16619d9 (diff)
downloadgcc-73ed17ff80da57d02cdb33b0035d5e718ed39fa2.zip
gcc-73ed17ff80da57d02cdb33b0035d5e718ed39fa2.tar.gz
gcc-73ed17ff80da57d02cdb33b0035d5e718ed39fa2.tar.bz2
re PR middle-end/22043 (Fields not initialized for automatic structs with flexible array members)
PR tree-optimization/22043 * tree.h (count_type_elements): Add ALLOW_FLEXARR argument. * expr.c (count_type_elements): Add ALLOW_FLEXARR argument. If ALLOW_FLEXARR, handle types ending with flexible array member. Pass false as second argument to recursive count_type_elements calls. (categorize_ctor_elements_1, mostly_zeros_p): Pass false as second argument to count_type_elements call. * tree-sra.c (decide_block_copy): Likewise. * gimplify.c (gimplify_init_constructor): If num_type_elements < 0 for a constant-sized object, set cleared as well. Pass true as second argument to count_type_elements call. * gcc.c-torture/execute/20050613-1.c: New test. From-SVN: r103389
Diffstat (limited to 'gcc/gimplify.c')
-rw-r--r--gcc/gimplify.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index a4ff3d2..9b34970 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -2706,13 +2706,18 @@ gimplify_init_constructor (tree *expr_p, tree *pre_p,
parts in, then generate code for the non-constant parts. */
/* TODO. There's code in cp/typeck.c to do this. */
- num_type_elements = count_type_elements (TREE_TYPE (ctor));
+ num_type_elements = count_type_elements (type, true);
+ /* If count_type_elements could not determine number of type elements
+ for a constant-sized object, assume clearing is needed.
+ Don't do this for variable-sized objects, as store_constructor
+ will ignore the clearing of variable-sized objects. */
+ if (num_type_elements < 0 && int_size_in_bytes (type) >= 0)
+ cleared = true;
/* If there are "lots" of zeros, then block clear the object first. */
- if (num_type_elements - num_nonzero_elements > CLEAR_RATIO
- && num_nonzero_elements < num_type_elements/4)
+ else if (num_type_elements - num_nonzero_elements > CLEAR_RATIO
+ && num_nonzero_elements < num_type_elements/4)
cleared = true;
-
/* ??? This bit ought not be needed. For any element not present
in the initializer, we should simply set them to zero. Except
we'd need to *find* the elements that are not present, and that