OSDN Git Service

* c-common.c (c_expand_expr): Revert 2002-02-06 patch.
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 8 Feb 2002 07:51:19 +0000 (07:51 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 8 Feb 2002 07:51:19 +0000 (07:51 +0000)
* c-parse.in (compstmt): Clear last_expr_type.

* parse.y (primary, primary_no_id): Use compstmt_or_stmtexpr
instead of compstmt.
(compstmt_or_stmtexpr): Renamed from compstmt.
(compstmt): In addition to compstmt_or_stmtexpr clear last_expr_type.

* gcc.c-torture/execute/20020206-1.c: Test whether nesting 2
expression statements work instead.
* gcc.dg/noncompile/20020207-1.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@49609 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-common.c
gcc/c-parse.in
gcc/cp/ChangeLog
gcc/cp/parse.y
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20020206-1.c
gcc/testsuite/gcc.dg/noncompile/20020207-1.c [new file with mode: 0644]

index 23bde4a..ab776ac 100644 (file)
@@ -1,3 +1,8 @@
+2002-02-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * c-common.c (c_expand_expr): Revert 2002-02-06 patch.
+       * c-parse.in (compstmt): Clear last_expr_type.
+
 2002-02-07  Richard Henderson  <rth@redhat.com>
 
        * loop.c (strength_reduce): Sink final_value when not
index 4b7946b..6b986d8 100644 (file)
@@ -3466,32 +3466,22 @@ 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)
+       if (target != const0_rtx
+           && TREE_CODE (STMT_EXPR_STMT (exp)) == COMPOUND_STMT
+           && TREE_CODE (COMPOUND_BODY (STMT_EXPR_STMT (exp))) == SCOPE_STMT)
          {
-           tree expr = STMT_EXPR_STMT (exp);
-           tree last;
+           tree expr = COMPOUND_BODY (STMT_EXPR_STMT (exp));
+           tree last = TREE_CHAIN (expr);
 
-           while (TREE_CODE (expr) == COMPOUND_STMT
-                  && TREE_CODE (COMPOUND_BODY (expr)) == SCOPE_STMT)
+           while (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;
-                 }
+               expr = last;
+               last = TREE_CHAIN (last);
              }
+
+           if (TREE_CODE (last) == SCOPE_STMT
+               && TREE_CODE (expr) == EXPR_STMT)
+             TREE_ADDRESSABLE (expr) = 1;
          }
 
        expand_stmt (STMT_EXPR_STMT (exp));
index 524d407..176041b 100644 (file)
@@ -2172,6 +2172,7 @@ compstmt_primary_start:
 
 compstmt: compstmt_start compstmt_nostart
                { RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); 
+                 last_expr_type = NULL_TREE;
                   $$ = $1; }
        ;
 
index ad7dd54..25bf9d9 100644 (file)
@@ -1,3 +1,10 @@
+2002-02-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * parse.y (primary, primary_no_id): Use compstmt_or_stmtexpr
+       instead of compstmt.
+       (compstmt_or_stmtexpr): Renamed from compstmt.
+       (compstmt): In addition to compstmt_or_stmtexpr clear last_expr_type.
+
 2002-02-07  Nathan Sidwell  <nathan@codesourcery.com>
 
        Rename instantiate_type_flags to tsubst_flags_t & expand use.
index 7941a89..7faeaba 100644 (file)
@@ -1592,7 +1592,7 @@ primary:
                    pedwarn ("ISO C++ forbids braced-groups within expressions");  
                  $<ttype>$ = begin_stmt_expr (); 
                }
-         compstmt ')'
+         compstmt_or_stmtexpr ')'
                { $$ = finish_stmt_expr ($<ttype>2); }
         /* Koenig lookup support
            We could store lastiddecl in $1 to avoid another lookup,
@@ -1717,7 +1717,7 @@ primary_no_id:
                      YYERROR;
                    }
                  $<ttype>$ = expand_start_stmt_expr (); }
-         compstmt ')'
+         compstmt_or_stmtexpr ')'
                { if (pedantic)
                    pedwarn ("ISO C++ forbids braced-groups within expressions");
                  $$ = expand_end_stmt_expr ($<ttype>2); }
@@ -3324,7 +3324,7 @@ label_decl:
                }
        ;
 
-compstmt:
+compstmt_or_stmtexpr:
          save_lineno '{'
                 { $<ttype>$ = begin_compound_stmt (0); }
          compstmtend 
@@ -3332,6 +3332,11 @@ compstmt:
                  finish_compound_stmt (0, $<ttype>3); }
        ;
 
+compstmt:
+         compstmt_or_stmtexpr
+               { last_expr_type = NULL_TREE; }
+       ;
+
 simple_if:
          IF
                { $<ttype>$ = begin_if_stmt ();
index c373f21..dbb5cef 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-08  Jakub Jelinek  <jakub@redhat.com>
+
+       * gcc.c-torture/execute/20020206-1.c: Test whether nesting 2
+       expression statements work instead.
+       * gcc.dg/noncompile/20020207-1.c: New test.
+
 2002-02-07  Richard Henderson  <rth@redhat.com>
 
        * gcc.dg/debug/dwarf2-1.c (foo): Return a value.
index 93147c9..8450800 100644 (file)
@@ -1,6 +1,3 @@
-/* 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;
 };
@@ -23,7 +20,7 @@ int main ()
 {
   struct A d;
 
-  d = ({ { bar (); } });
+  d = ({ ({ bar (); }); });
   baz (&d);
   exit (0);
 }
diff --git a/gcc/testsuite/gcc.dg/noncompile/20020207-1.c b/gcc/testsuite/gcc.dg/noncompile/20020207-1.c
new file mode 100644 (file)
index 0000000..945eb1b
--- /dev/null
@@ -0,0 +1,32 @@
+/* This testcase ICEd because statement expression type was set, but was not
+   as used.  */
+
+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 (); } });               /* { dg-error "void value" } */
+  d = ({ if (1) { bar (); } });                /* { dg-error "void value" } */
+  d = ({ while (0) { bar (); } });     /* { dg-error "void value" } */
+  d = ({ do { bar (); } while (0); }); /* { dg-error "void value" } */
+  baz (&d);
+  exit (0);
+}