Blame SOURCES/gcc48-pr77767.patch

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