aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-parser.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2017-11-19 18:17:01 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2017-11-19 18:17:01 +0100
commitf9c59f7e9511856bd6dc13d2d4904ebd9249c095 (patch)
tree418d66f5607f88d0a122bfdd9c9fe4038f93d9f8 /gcc/c/c-parser.c
parent4397fc04e399e91fe53f0862fef41bb5b42a7c14 (diff)
downloadgcc-f9c59f7e9511856bd6dc13d2d4904ebd9249c095.zip
gcc-f9c59f7e9511856bd6dc13d2d4904ebd9249c095.tar.gz
gcc-f9c59f7e9511856bd6dc13d2d4904ebd9249c095.tar.bz2
re PR c/66618 (Failure to diagnose non-constant initializer for static object with -O1)
PR c/66618 PR c/69960 c-family/ * c-common.h (c_fully_fold): Add LVAL argument defaulted to false. c/ * c-parser.c (c_parser_omp_atomic): Pass true as LVAL to c_fully_fold where needed. * c-typeck.c (build_unary_op, build_modify_expr, build_asm_expr, handle_omp_array_sections): Likewise. (digest_init): Don't call decl_constant_value_for_optimization. * c-tree.h (decl_constant_value_for_optimization): Removed. * c-fold.c (c_fold_array_ref): New function. (c_fully_fold_internal): Add LVAL argument, propagate it through recursive calls. For VAR_P call decl_constant_value and unshare if not LVAL and either optimizing or IN_INIT. Remove decl_constant_value_for_optimization calls. If IN_INIT and not LVAL, fold ARRAY_REF with STRING_CST and INTEGER_CST operands. (c_fully_fold): Add LVAL argument, pass it through to c_fully_fold_internal. (decl_constant_value_for_optimization): Removed. cp/ * cp-gimplify.c (c_fully_fold): Add LVAL argument, call cp_fold_maybe_rvalue instead of cp_fold_rvalue and pass it !LVAL. testsuite/ * gcc.dg/pr69960.c: New test. * gcc.dg/pr66618.c: New test. * gcc.dg/pr66618-2.c: New test. From-SVN: r254930
Diffstat (limited to 'gcc/c/c-parser.c')
-rw-r--r--gcc/c/c-parser.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 3d90e28..bd5dd57 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -15312,7 +15312,7 @@ c_parser_omp_atomic (location_t loc, c_parser *parser)
case NOP_EXPR: /* atomic write */
v = c_parser_cast_expression (parser, NULL).value;
non_lvalue_p = !lvalue_p (v);
- v = c_fully_fold (v, false, NULL);
+ v = c_fully_fold (v, false, NULL, true);
if (v == error_mark_node)
goto saw_error;
if (non_lvalue_p)
@@ -15331,7 +15331,7 @@ c_parser_omp_atomic (location_t loc, c_parser *parser)
{
lhs = c_parser_cast_expression (parser, NULL).value;
non_lvalue_p = !lvalue_p (lhs);
- lhs = c_fully_fold (lhs, false, NULL);
+ lhs = c_fully_fold (lhs, false, NULL, true);
if (lhs == error_mark_node)
goto saw_error;
if (non_lvalue_p)
@@ -15357,7 +15357,7 @@ c_parser_omp_atomic (location_t loc, c_parser *parser)
{
v = c_parser_cast_expression (parser, NULL).value;
non_lvalue_p = !lvalue_p (v);
- v = c_fully_fold (v, false, NULL);
+ v = c_fully_fold (v, false, NULL, true);
if (v == error_mark_node)
goto saw_error;
if (non_lvalue_p)
@@ -15378,7 +15378,7 @@ restart:
lhs = expr.value;
expr = default_function_array_conversion (eloc, expr);
unfolded_lhs = expr.value;
- lhs = c_fully_fold (lhs, false, NULL);
+ lhs = c_fully_fold (lhs, false, NULL, true);
orig_lhs = lhs;
switch (TREE_CODE (lhs))
{
@@ -15518,15 +15518,19 @@ restart:
if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs))
{
opcode = TREE_CODE (rhs1);
- rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
- rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
+ rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL,
+ true);
+ rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL,
+ true);
goto stmt_done;
}
if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs))
{
opcode = TREE_CODE (rhs1);
- rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL);
- rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL);
+ rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL,
+ true);
+ rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL,
+ true);
swapped = !commutative_tree_code (opcode);
goto stmt_done;
}
@@ -15545,7 +15549,7 @@ restart:
lhs = NULL_TREE;
expr = default_function_array_read_conversion (eloc, expr);
unfolded_lhs1 = expr.value;
- lhs1 = c_fully_fold (unfolded_lhs1, false, NULL);
+ lhs1 = c_fully_fold (unfolded_lhs1, false, NULL, true);
rhs1 = NULL_TREE;
c_parser_consume_token (parser);
goto restart;
@@ -15554,7 +15558,7 @@ restart:
{
opcode = NOP_EXPR;
expr = default_function_array_read_conversion (eloc, expr);
- rhs = c_fully_fold (expr.value, false, NULL);
+ rhs = c_fully_fold (expr.value, false, NULL, true);
rhs1 = NULL_TREE;
goto stmt_done;
}
@@ -15575,7 +15579,7 @@ restart:
expr = c_parser_expression (parser);
expr = default_function_array_read_conversion (eloc, expr);
rhs = expr.value;
- rhs = c_fully_fold (rhs, false, NULL);
+ rhs = c_fully_fold (rhs, false, NULL, true);
break;
}
stmt_done:
@@ -15585,7 +15589,7 @@ stmt_done:
goto saw_error;
v = c_parser_cast_expression (parser, NULL).value;
non_lvalue_p = !lvalue_p (v);
- v = c_fully_fold (v, false, NULL);
+ v = c_fully_fold (v, false, NULL, true);
if (v == error_mark_node)
goto saw_error;
if (non_lvalue_p)
@@ -15597,7 +15601,7 @@ stmt_done:
lhs1 = expr.value;
expr = default_function_array_read_conversion (eloc, expr);
unfolded_lhs1 = expr.value;
- lhs1 = c_fully_fold (lhs1, false, NULL);
+ lhs1 = c_fully_fold (lhs1, false, NULL, true);
if (lhs1 == error_mark_node)
goto saw_error;
if (!lvalue_p (unfolded_lhs1))