c-common.c (c_expand_expr): Revert 2002-02-06 patch.

* c-common.c (c_expand_expr): Revert 2002-02-06 patch.
	* 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.

From-SVN: r49609
This commit is contained in:
Jakub Jelinek 2002-02-08 08:51:19 +01:00 committed by Jakub Jelinek
parent 8f94053d32
commit 1cf537c53e
8 changed files with 72 additions and 29 deletions

View 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

View 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));

View 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; }
;

View 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.

View 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 ();

View 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.

View 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);
}

View File

@ -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);
}