diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-12-01 00:43:10 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-12-01 00:43:10 +0100 |
commit | cc6534d40136b8afb5dcd878e58d106f31b51dd2 (patch) | |
tree | 45bebb503a52bf8726cdc05432ea9875c8ef1bdd /gcc/c | |
parent | 5de73c050e4dbb3dfc8705bf20199aedb090df20 (diff) | |
download | gcc-cc6534d40136b8afb5dcd878e58d106f31b51dd2.zip gcc-cc6534d40136b8afb5dcd878e58d106f31b51dd2.tar.gz gcc-cc6534d40136b8afb5dcd878e58d106f31b51dd2.tar.bz2 |
re PR c/83222 (Inconsistent "initializer element is not constant" error)
PR c/83222
* c-tree.h (decl_constant_value_1): Declare.
* c-typeck.c (decl_constant_value_1): New function.
(decl_constant_value): Use it.
* c-fold.c (c_fully_fold_internal): If in_init, use
decl_constant_value_1 instead of decl_constant_value.
* gcc.c-torture/compile/pr83222.c: New test.
From-SVN: r255285
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/c/c-fold.c | 5 | ||||
-rw-r--r-- | gcc/c/c-tree.h | 1 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 20 |
4 files changed, 28 insertions, 7 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 677b54c..90db38a 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,12 @@ +2017-12-01 Jakub Jelinek <jakub@redhat.com> + + PR c/83222 + * c-tree.h (decl_constant_value_1): Declare. + * c-typeck.c (decl_constant_value_1): New function. + (decl_constant_value): Use it. + * c-fold.c (c_fully_fold_internal): If in_init, use + decl_constant_value_1 instead of decl_constant_value. + 2017-11-30 Jakub Jelinek <jakub@redhat.com> * c-parser.c (c_parser_postfix_expression): Use ; instead of ;;. diff --git a/gcc/c/c-fold.c b/gcc/c/c-fold.c index 8895462..84ce543 100644 --- a/gcc/c/c-fold.c +++ b/gcc/c/c-fold.c @@ -167,7 +167,10 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands, /* Except for variables which we can optimize to its initializer. */ if (VAR_P (expr) && !lval && (optimize || in_init)) { - ret = decl_constant_value (expr); + if (in_init) + ret = decl_constant_value_1 (expr); + else + ret = decl_constant_value (expr); /* Avoid unwanted tree sharing between the initializer and current function's body where the tree can be modified e.g. by the gimplifier. */ diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 5fb57f2..cbc5e0e 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -640,6 +640,7 @@ extern struct c_expr default_function_array_read_conversion (location_t, struct c_expr); extern struct c_expr convert_lvalue_to_rvalue (location_t, struct c_expr, bool, bool); +extern tree decl_constant_value_1 (tree); extern void mark_exp_read (tree); extern tree composite_type (tree, tree); extern tree build_component_ref (location_t, tree, tree, location_t); diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 6846bc5..9222660 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -1832,13 +1832,10 @@ c_size_in_bytes (const_tree type) /* Return either DECL or its known constant value (if it has one). */ tree -decl_constant_value (tree decl) +decl_constant_value_1 (tree decl) { - if (/* Don't change a variable array bound or initial value to a constant - in a place where a variable is invalid. Note that DECL_INITIAL - isn't valid for a PARM_DECL. */ - current_function_decl != NULL_TREE - && TREE_CODE (decl) != PARM_DECL + if (/* Note that DECL_INITIAL isn't valid for a PARM_DECL. */ + TREE_CODE (decl) != PARM_DECL && !TREE_THIS_VOLATILE (decl) && TREE_READONLY (decl) && DECL_INITIAL (decl) != NULL_TREE @@ -1853,6 +1850,17 @@ decl_constant_value (tree decl) return decl; } +/* Return either DECL or its known constant value (if it has one). + Like the above, but always return decl outside of functions. */ + +tree +decl_constant_value (tree decl) +{ + /* Don't change a variable array bound or initial value to a constant + in a place where a variable is invalid. */ + return current_function_decl ? decl_constant_value_1 (decl) : decl; +} + /* Convert the array expression EXP to a pointer. */ static tree array_to_pointer_conversion (location_t loc, tree exp) |