]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/77767 (Side-effect from VLA array parameters lost)
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 May 2017 07:51:58 +0000 (09:51 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 May 2017 07:51:58 +0000 (09:51 +0200)
Backported from mainline
2016-12-21  Jakub Jelinek  <jakub@redhat.com>

PR c/77767
* c-decl.c (grokdeclarator): If *expr is non-NULL, append expression
to *expr instead of overwriting it.

* gcc.c-torture/execute/pr77767.c: New test.

From-SVN: r248635

gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr77767.c [new file with mode: 0644]

index bdc6b43856f59bf1561f1f8bd3ec1a0bca1cb5f9..caf2a72a8d0cb00e9ba4b60b135c2ea6d38d08d0 100644 (file)
@@ -1,6 +1,12 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-12-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/77767
+       * c-decl.c (grokdeclarator): If *expr is non-NULL, append expression
+       to *expr instead of overwriting it.
+
        2016-08-12  Jakub Jelinek  <jakub@redhat.com>
                    Martin Liska  <mliska@suse.cz>
 
index 0737c400e2ea379a35619eb715dd7f6e6290ebaf..519a9791742634dbdb0d1504cbd7955d399a9384 100644 (file)
@@ -5409,11 +5409,21 @@ grokdeclarator (const struct c_declarator *declarator,
   if (TREE_CODE (type) == ERROR_MARK)
     return error_mark_node;
   if (expr == NULL)
-    expr = &expr_dummy;
+    {
+      expr = &expr_dummy;
+      expr_dummy = NULL_TREE;
+    }
   if (expr_const_operands == NULL)
     expr_const_operands = &expr_const_operands_dummy;
 
-  *expr = declspecs->expr;
+  if (declspecs->expr)
+    {
+      if (*expr)
+       *expr = build2 (COMPOUND_EXPR, TREE_TYPE (declspecs->expr), *expr,
+                       declspecs->expr);
+      else
+       *expr = declspecs->expr;
+    }
   *expr_const_operands = declspecs->expr_const_operands;
 
   if (decl_context == FUNCDEF)
index 4969e956b5f06867f0387ad3d70d007ccdc07757..ffd3164df19aab3c5a7cc0e9aad0dd30355ddc46 100644 (file)
@@ -1,6 +1,11 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-12-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/77767
+       * gcc.c-torture/execute/pr77767.c: New test.
+
        2016-12-13  Jakub Jelinek  <jakub@redhat.com>
 
        PR ipa/77905
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr77767.c b/gcc/testsuite/gcc.c-torture/execute/pr77767.c
new file mode 100644 (file)
index 0000000..21725a5
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR c/77767 */
+
+void
+foo (int a, int b[a++], int c, int d[c++])
+{
+  if (a != 2 || c != 2)
+    __builtin_abort ();
+}
+
+int
+main ()
+{
+  int e[10];
+  foo (1, e, 1, e);
+  return 0;
+}