From d17680f342ef5407303d8c76f8faa0762f83c3f7 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 21 Dec 2016 01:07:49 +0100 Subject: [PATCH] re PR c/77767 (Side-effect from VLA array parameters lost) PR c/77767 * c-decl.c (grokdeclarator): If *expr is non-NULL, append expression to *expr instead of overwriting it. * gcc.c-torture/execute/pr77767.c: New test. From-SVN: r243832 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-decl.c | 14 ++++++++++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.c-torture/execute/pr77767.c | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr77767.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index e17674f899c..65eb93db4df 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2016-12-21 Jakub Jelinek + + PR c/77767 + * c-decl.c (grokdeclarator): If *expr is non-NULL, append expression + to *expr instead of overwriting it. + 2016-12-20 Richard Biener * gimple-parser.c (c_parser_gimple_compound_statement): Improve diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index db293fe60d1..eca94c5a101 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -5580,11 +5580,21 @@ grokdeclarator (const struct c_declarator *declarator, if (TREE_CODE (type) == ERROR_MARK) return error_mark_node; if (expr == NULL) - expr = &expr_dummy; + { + expr = &expr_dummy; + expr_dummy = NULL_TREE; + } if (expr_const_operands == NULL) expr_const_operands = &expr_const_operands_dummy; - *expr = declspecs->expr; + if (declspecs->expr) + { + if (*expr) + *expr = build2 (COMPOUND_EXPR, TREE_TYPE (declspecs->expr), *expr, + declspecs->expr); + else + *expr = declspecs->expr; + } *expr_const_operands = declspecs->expr_const_operands; if (decl_context == FUNCDEF) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ccf64d4d8a5..f06c53c9430 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-12-21 Jakub Jelinek + + PR c/77767 + * gcc.c-torture/execute/pr77767.c: New test. + 2016-12-20 Pat Haugen * gcc.dg/sms-3.c: Add -fno-sched-pressure for powerpc. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr77767.c b/gcc/testsuite/gcc.c-torture/execute/pr77767.c new file mode 100644 index 00000000000..21725a56bfe --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr77767.c @@ -0,0 +1,16 @@ +/* PR c/77767 */ + +void +foo (int a, int b[a++], int c, int d[c++]) +{ + if (a != 2 || c != 2) + __builtin_abort (); +} + +int +main () +{ + int e[10]; + foo (1, e, 1, e); + return 0; +}