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