Blame SOURCES/gcc48-pr77767.patch

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