Blame SOURCES/gcc48-pr77767.patch

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