Blame SOURCES/gcc48-pr77767.patch

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