re PR c/77767 (Side-effect from VLA array parameters lost)
authorJakub Jelinek <jakub@redhat.com>
Wed, 21 Dec 2016 00:07:49 +0000 (01:07 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 21 Dec 2016 00:07:49 +0000 (01:07 +0100)
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
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr77767.c [new file with mode: 0644]

index e17674f899ca715cca3af8a1777653013626e46f..65eb93db4df85bd52a8679ca57eb6af437e60f8c 100644 (file)
@@ -1,3 +1,9 @@
+2016-12-21  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <rguenther@suse.de>
 
        * gimple-parser.c (c_parser_gimple_compound_statement): Improve
index db293fe60d14460cd5bbf97dc33c67e872938a6a..eca94c5a101eaf8a73f64e7f20fe44d36ca93339 100644 (file)
@@ -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)
index ccf64d4d8a5cd75a3693f68057e9ac4141f816b4..f06c53c9430ca72801e36c16a1c03fe8c2aa6ca4 100644 (file)
@@ -1,3 +1,8 @@
+2016-12-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/77767
+       * gcc.c-torture/execute/pr77767.c: New test.
+
 2016-12-20  Pat Haugen  <pthaugen@us.ibm.com>
 
        * 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 (file)
index 0000000..21725a5
--- /dev/null
@@ -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;
+}