85359c
2017-05-30  Jakub Jelinek  <jakub@redhat.com>
85359c
 
85359c
 	Backported from mainline
85359c
	2016-12-21  Jakub Jelinek  <jakub@redhat.com>
85359c
85359c
	PR c/77767
85359c
	* c-decl.c (grokdeclarator): If *expr is non-NULL, append expression
85359c
	to *expr instead of overwriting it.
85359c
85359c
	* gcc.c-torture/execute/pr77767.c: New test.
85359c
85359c
--- gcc/c/c-decl.c
85359c
+++ gcc/c/c-decl.c
85359c
@@ -5409,11 +5409,21 @@ grokdeclarator (const struct c_declarator *declarator,
85359c
   if (TREE_CODE (type) == ERROR_MARK)
85359c
     return error_mark_node;
85359c
   if (expr == NULL)
85359c
-    expr = &expr_dummy;
85359c
+    {
85359c
+      expr = &expr_dummy;
85359c
+      expr_dummy = NULL_TREE;
85359c
+    }
85359c
   if (expr_const_operands == NULL)
85359c
     expr_const_operands = &expr_const_operands_dummy;
85359c
 
85359c
-  *expr = declspecs->expr;
85359c
+  if (declspecs->expr)
85359c
+    {
85359c
+      if (*expr)
85359c
+	*expr = build2 (COMPOUND_EXPR, TREE_TYPE (declspecs->expr), *expr,
85359c
+			declspecs->expr);
85359c
+      else
85359c
+	*expr = declspecs->expr;
85359c
+    }
85359c
   *expr_const_operands = declspecs->expr_const_operands;
85359c
 
85359c
   if (decl_context == FUNCDEF)
85359c
--- /dev/null
85359c
+++ gcc/testsuite/gcc.c-torture/execute/pr77767.c
85359c
@@ -0,0 +1,16 @@
85359c
+/* PR c/77767 */
85359c
+
85359c
+void
85359c
+foo (int a, int b[a++], int c, int d[c++])
85359c
+{
85359c
+  if (a != 2 || c != 2)
85359c
+    __builtin_abort ();
85359c
+}
85359c
+
85359c
+int
85359c
+main ()
85359c
+{
85359c
+  int e[10];
85359c
+  foo (1, e, 1, e);
85359c
+  return 0;
85359c
+}