diff options
author | Richard Henderson <rth@redhat.com> | 2004-09-09 10:36:42 -0700 |
---|---|---|
committer | Richard Henderson <rth@gcc.gnu.org> | 2004-09-09 10:36:42 -0700 |
commit | 116df7864046513771505f127b76411ecea0ede3 (patch) | |
tree | 554e99807d215b24b2560c87ef3c474674a53b96 | |
parent | 41374e13ac15863e80fff7c4b8731ab34b1921f9 (diff) | |
download | gcc-116df7864046513771505f127b76411ecea0ede3.zip gcc-116df7864046513771505f127b76411ecea0ede3.tar.gz gcc-116df7864046513771505f127b76411ecea0ede3.tar.bz2 |
re PR c/17322 (initializer folding broken)
PR c/17322
* c-typeck.c (valid_compound_expr_initializer): Use only
initializer_constant_valid_p, and not TREE_CONSTANT.
(digest_init): Likewise.
(output_init_element): Likewise.
From-SVN: r87245
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c-typeck.c | 34 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr17322.c | 5 |
3 files changed, 27 insertions, 20 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 43c658b..84a8c34 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2004-09-09 Richard Henderson <rth@redhat.com> + + PR c/17322 + * c-typeck.c (valid_compound_expr_initializer): Use only + initializer_constant_valid_p, and not TREE_CONSTANT. + (digest_init): Likewise. + (output_init_element): Likewise. + 2004-09-09 Giovanni Bajo <giovannibajo@gcc.gnu.org> * ra-build.c (copy_insn_p, remember_move, defuse_overlap_p_1, diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 1bab695..4cfd7ce 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -3737,8 +3737,7 @@ valid_compound_expr_initializer (tree value, tree endtype) return valid_compound_expr_initializer (TREE_OPERAND (value, 1), endtype); } - else if (! TREE_CONSTANT (value) - && ! initializer_constant_valid_p (value, endtype)) + else if (!initializer_constant_valid_p (value, endtype)) return error_mark_node; else return value; @@ -4166,16 +4165,8 @@ digest_init (tree type, tree init, bool strict_string, int require_constant) inside_init = error_mark_node; } else if (require_constant - && (!TREE_CONSTANT (inside_init) - /* This test catches things like `7 / 0' which - result in an expression for which TREE_CONSTANT - is true, but which is not actually something - that is a legal constant. We really should not - be using this function, because it is a part of - the back-end. Instead, the expression should - already have been turned into ERROR_MARK_NODE. */ - || !initializer_constant_valid_p (inside_init, - TREE_TYPE (inside_init)))) + && !initializer_constant_valid_p (inside_init, + TREE_TYPE (inside_init))) { error_init ("initializer element is not constant"); inside_init = error_mark_node; @@ -4203,7 +4194,8 @@ digest_init (tree type, tree init, bool strict_string, int require_constant) inside_init = error_mark_node; } else if (require_constant - && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0) + && !initializer_constant_valid_p (inside_init, + TREE_TYPE (inside_init))) { error_init ("initializer element is not computable at load time"); inside_init = error_mark_node; @@ -5585,21 +5577,23 @@ output_init_element (tree value, bool strict_string, tree type, tree field, constructor_erroneous = 1; else if (!TREE_CONSTANT (value)) constructor_constant = 0; - else if (initializer_constant_valid_p (value, TREE_TYPE (value)) == 0 + else if (!initializer_constant_valid_p (value, TREE_TYPE (value)) || ((TREE_CODE (constructor_type) == RECORD_TYPE || TREE_CODE (constructor_type) == UNION_TYPE) && DECL_C_BIT_FIELD (field) && TREE_CODE (value) != INTEGER_CST)) constructor_simple = 0; - if (require_constant_value && ! TREE_CONSTANT (value)) + if (!initializer_constant_valid_p (value, TREE_TYPE (value))) { - error_init ("initializer element is not constant"); - value = error_mark_node; + if (require_constant_value) + { + error_init ("initializer element is not constant"); + value = error_mark_node; + } + else if (require_constant_elements) + pedwarn ("initializer element is not computable at load time"); } - else if (require_constant_elements - && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0) - pedwarn ("initializer element is not computable at load time"); /* If this field is empty (and not at the end of structure), don't do anything other than checking the initializer. */ diff --git a/gcc/testsuite/gcc.dg/pr17322.c b/gcc/testsuite/gcc.dg/pr17322.c new file mode 100644 index 0000000..7057872 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr17322.c @@ -0,0 +1,5 @@ +/* PR 17322 */ + +struct s { int a; int b[1]; }; +struct s x; +int *y = ((struct s *)&x.a)->b; |