re PR c/5482 (cyclone-0.2, ICE in emit_move_insn, at expr.c:2746)
authorJakub Jelinek <jakub@redhat.com>
Wed, 6 Feb 2002 19:32:04 +0000 (20:32 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 6 Feb 2002 19:32:04 +0000 (20:32 +0100)
PR c/5482:
* c-common.c (c_expand_expr) [STMT_EXPR]: If last expression is not
EXPR_STMT, but COMPOUND_STMT, recurse into it.

* gcc.c-torture/execute/20020206-1.c: New test.

From-SVN: r49549

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20020206-1.c [new file with mode: 0644]

index f9b074459de14a2db8eadfbf81be72a777cc57e8..86fc062969355805afcf1f259ac2003938c8791e 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/5482:
+       * c-common.c (c_expand_expr) [STMT_EXPR]: If last expression is not
+       EXPR_STMT, but COMPOUND_STMT, recurse into it.
+
 2002-02-06  Richard Henderson  <rth@redhat.com>
 
        * cfganal.c (keep_with_call_p): Source for fixed_reg dest must
index bbccf4a5092da7ee00b1995046a1b1ba74e476b3..dd535ed7365e753d39223c5ffda1f3f4d872c99d 100644 (file)
@@ -3466,22 +3466,32 @@ c_expand_expr (exp, target, tmode, modifier)
 
        /* If we want the result of this expression, find the last
            EXPR_STMT in the COMPOUND_STMT and mark it as addressable.  */
-       if (target != const0_rtx
-           && TREE_CODE (STMT_EXPR_STMT (exp)) == COMPOUND_STMT
-           && TREE_CODE (COMPOUND_BODY (STMT_EXPR_STMT (exp))) == SCOPE_STMT)
+       if (target != const0_rtx)
          {
-           tree expr = COMPOUND_BODY (STMT_EXPR_STMT (exp));
-           tree last = TREE_CHAIN (expr);
+           tree expr = STMT_EXPR_STMT (exp);
+           tree last;
 
-           while (TREE_CHAIN (last))
+           while (TREE_CODE (expr) == COMPOUND_STMT
+                  && TREE_CODE (COMPOUND_BODY (expr)) == SCOPE_STMT)
              {
-               expr = last;
-               last = TREE_CHAIN (last);
+               expr = COMPOUND_BODY (expr);
+               last = TREE_CHAIN (expr);
+
+               while (TREE_CHAIN (last))
+                 {
+                   expr = last;
+                   last = TREE_CHAIN (last);
+                 }
+
+               if (TREE_CODE (last) != SCOPE_STMT)
+                 abort ();
+
+               if (TREE_CODE (expr) == EXPR_STMT)
+                 {
+                   TREE_ADDRESSABLE (expr) = 1;
+                   break;
+                 }
              }
-
-           if (TREE_CODE (last) == SCOPE_STMT
-               && TREE_CODE (expr) == EXPR_STMT)
-             TREE_ADDRESSABLE (expr) = 1;
          }
 
        expand_stmt (STMT_EXPR_STMT (exp));
index 30b219e906aa295adb198260ca1fe29eeac256b2..8cf3dc49e2bbb1f978987af0f257065d396fa155 100644 (file)
@@ -1,5 +1,7 @@
 2002-02-06  Jakub Jelinek  <jakub@redhat.com>
 
+       * gcc.c-torture/execute/20020206-1.c: New test.
+
        PR optimization/5429:
        * gcc.c-torture/compile/20020206-1.c: New test.
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/20020206-1.c b/gcc/testsuite/gcc.c-torture/execute/20020206-1.c
new file mode 100644 (file)
index 0000000..93147c9
--- /dev/null
@@ -0,0 +1,29 @@
+/* This testcase ICEd because c_expand_expr did not mark statement expression
+   return value as one which shouldn't be ignored.  */
+
+struct A {
+  unsigned int a, b, c;
+};
+
+extern void abort (void);
+extern void exit (int);
+
+struct A bar (void)
+{
+  return (struct A) { 176, 52, 31 };
+}
+
+void baz (struct A *a)
+{
+  if (a->a != 176 || a->b != 52 || a->c != 31)
+    abort ();
+}
+
+int main ()
+{
+  struct A d;
+
+  d = ({ { bar (); } });
+  baz (&d);
+  exit (0);
+}