Commit 1cf537c5 by Jakub Jelinek Committed by Jakub Jelinek

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
parent 8f94053d
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> 2002-02-07 Richard Henderson <rth@redhat.com>
* loop.c (strength_reduce): Sink final_value when not * loop.c (strength_reduce): Sink final_value when not
......
...@@ -3466,32 +3466,22 @@ c_expand_expr (exp, target, tmode, modifier) ...@@ -3466,32 +3466,22 @@ c_expand_expr (exp, target, tmode, modifier)
/* If we want the result of this expression, find the last /* If we want the result of this expression, find the last
EXPR_STMT in the COMPOUND_STMT and mark it as addressable. */ 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 expr = COMPOUND_BODY (STMT_EXPR_STMT (exp));
tree last; tree last = TREE_CHAIN (expr);
while (TREE_CODE (expr) == COMPOUND_STMT while (TREE_CHAIN (last))
&& TREE_CODE (COMPOUND_BODY (expr)) == SCOPE_STMT)
{ {
expr = COMPOUND_BODY (expr); expr = last;
last = TREE_CHAIN (expr); last = TREE_CHAIN (last);
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)); expand_stmt (STMT_EXPR_STMT (exp));
......
...@@ -2172,6 +2172,7 @@ compstmt_primary_start: ...@@ -2172,6 +2172,7 @@ compstmt_primary_start:
compstmt: compstmt_start compstmt_nostart compstmt: compstmt_start compstmt_nostart
{ RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); { RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
last_expr_type = NULL_TREE;
$$ = $1; } $$ = $1; }
; ;
......
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> 2002-02-07 Nathan Sidwell <nathan@codesourcery.com>
Rename instantiate_type_flags to tsubst_flags_t & expand use. Rename instantiate_type_flags to tsubst_flags_t & expand use.
......
...@@ -1592,7 +1592,7 @@ primary: ...@@ -1592,7 +1592,7 @@ primary:
pedwarn ("ISO C++ forbids braced-groups within expressions"); pedwarn ("ISO C++ forbids braced-groups within expressions");
$<ttype>$ = begin_stmt_expr (); $<ttype>$ = begin_stmt_expr ();
} }
compstmt ')' compstmt_or_stmtexpr ')'
{ $$ = finish_stmt_expr ($<ttype>2); } { $$ = finish_stmt_expr ($<ttype>2); }
/* Koenig lookup support /* Koenig lookup support
We could store lastiddecl in $1 to avoid another lookup, We could store lastiddecl in $1 to avoid another lookup,
...@@ -1717,7 +1717,7 @@ primary_no_id: ...@@ -1717,7 +1717,7 @@ primary_no_id:
YYERROR; YYERROR;
} }
$<ttype>$ = expand_start_stmt_expr (); } $<ttype>$ = expand_start_stmt_expr (); }
compstmt ')' compstmt_or_stmtexpr ')'
{ if (pedantic) { if (pedantic)
pedwarn ("ISO C++ forbids braced-groups within expressions"); pedwarn ("ISO C++ forbids braced-groups within expressions");
$$ = expand_end_stmt_expr ($<ttype>2); } $$ = expand_end_stmt_expr ($<ttype>2); }
...@@ -3324,7 +3324,7 @@ label_decl: ...@@ -3324,7 +3324,7 @@ label_decl:
} }
; ;
compstmt: compstmt_or_stmtexpr:
save_lineno '{' save_lineno '{'
{ $<ttype>$ = begin_compound_stmt (0); } { $<ttype>$ = begin_compound_stmt (0); }
compstmtend compstmtend
...@@ -3332,6 +3332,11 @@ compstmt: ...@@ -3332,6 +3332,11 @@ compstmt:
finish_compound_stmt (0, $<ttype>3); } finish_compound_stmt (0, $<ttype>3); }
; ;
compstmt:
compstmt_or_stmtexpr
{ last_expr_type = NULL_TREE; }
;
simple_if: simple_if:
IF IF
{ $<ttype>$ = begin_if_stmt (); { $<ttype>$ = begin_if_stmt ();
......
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> 2002-02-07 Richard Henderson <rth@redhat.com>
* gcc.dg/debug/dwarf2-1.c (foo): Return a value. * gcc.dg/debug/dwarf2-1.c (foo): Return a value.
......
/* This testcase ICEd because c_expand_expr did not mark statement expression
return value as one which shouldn't be ignored. */
struct A { struct A {
unsigned int a, b, c; unsigned int a, b, c;
}; };
...@@ -23,7 +20,7 @@ int main () ...@@ -23,7 +20,7 @@ int main ()
{ {
struct A d; struct A d;
d = ({ { bar (); } }); d = ({ ({ bar (); }); });
baz (&d); baz (&d);
exit (0); exit (0);
} }
/* 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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment