Commit b0832fe1 by Jakub Jelinek Committed by Jakub Jelinek

tree.h (expand_expr_stmt_value): Add maybe_last argument.

	* tree.h (expand_expr_stmt_value): Add maybe_last argument.
	* c-common.h (genrtl_expr_stmt_value): Likewise.
	* stmt.c (expand_expr_stmt): Pass 1 as maybe_last.
	(expand_expr_stmt_value): Add maybe_last argument.
	Don't warn about statement with no effect if it is the last statement
	in expression statement.
	* c-semantics.c (genrtl_expr_stmt): Pass 1 as maybe_last.
	(genrtl_expr_stmt_value): Add maybe_last argument, pass it down to
	expand_expr_stmt_value.
	(expand_stmt) [EXPR_STMT]: Pass 1 as maybe_last to
	genrtl_expr_stmt_value if t is the last EXPR_STMT in its scope.
	* expr.c (expand_expr) [LABELED_BLOCK_EXPR, LOOP_EXPR]: Pass 1
	as maybe_last to expand_expr_stmt_value.

	* gcc.dg/20020104-1.c: New test.

From-SVN: r48541
parent 81550d0e
2002-01-04 Jakub Jelinek <jakub@redhat.com>
* tree.h (expand_expr_stmt_value): Add maybe_last argument.
* c-common.h (genrtl_expr_stmt_value): Likewise.
* stmt.c (expand_expr_stmt): Pass 1 as maybe_last.
(expand_expr_stmt_value): Add maybe_last argument.
Don't warn about statement with no effect if it is the last statement
in expression statement.
* c-semantics.c (genrtl_expr_stmt): Pass 1 as maybe_last.
(genrtl_expr_stmt_value): Add maybe_last argument, pass it down to
expand_expr_stmt_value.
(expand_stmt) [EXPR_STMT]: Pass 1 as maybe_last to
genrtl_expr_stmt_value if t is the last EXPR_STMT in its scope.
* expr.c (expand_expr) [LABELED_BLOCK_EXPR, LOOP_EXPR]: Pass 1
as maybe_last to expand_expr_stmt_value.
Fri Jan 4 11:45:05 2002 Jeffrey A Law (law@redhat.com) Fri Jan 4 11:45:05 2002 Jeffrey A Law (law@redhat.com)
* c-common.c (c_expand_start_cond): Expect the IF_STMT node to * c-common.c (c_expand_start_cond): Expect the IF_STMT node to
......
...@@ -721,7 +721,7 @@ extern void add_c_tree_codes PARAMS ((void)); ...@@ -721,7 +721,7 @@ extern void add_c_tree_codes PARAMS ((void));
extern void genrtl_do_pushlevel PARAMS ((void)); extern void genrtl_do_pushlevel PARAMS ((void));
extern void genrtl_goto_stmt PARAMS ((tree)); extern void genrtl_goto_stmt PARAMS ((tree));
extern void genrtl_expr_stmt PARAMS ((tree)); extern void genrtl_expr_stmt PARAMS ((tree));
extern void genrtl_expr_stmt_value PARAMS ((tree, int)); extern void genrtl_expr_stmt_value PARAMS ((tree, int, int));
extern void genrtl_decl_stmt PARAMS ((tree)); extern void genrtl_decl_stmt PARAMS ((tree));
extern void genrtl_if_stmt PARAMS ((tree)); extern void genrtl_if_stmt PARAMS ((tree));
extern void genrtl_while_stmt PARAMS ((tree)); extern void genrtl_while_stmt PARAMS ((tree));
......
...@@ -313,18 +313,20 @@ void ...@@ -313,18 +313,20 @@ void
genrtl_expr_stmt (expr) genrtl_expr_stmt (expr)
tree expr; tree expr;
{ {
genrtl_expr_stmt_value (expr, -1); genrtl_expr_stmt_value (expr, -1, 1);
} }
/* Generate the RTL for EXPR, which is an EXPR_STMT. WANT_VALUE tells /* Generate the RTL for EXPR, which is an EXPR_STMT. WANT_VALUE tells
whether to (1) save the value of the expression, (0) discard it or whether to (1) save the value of the expression, (0) discard it or
(-1) use expr_stmts_for_value to tell. The use of -1 is (-1) use expr_stmts_for_value to tell. The use of -1 is
deprecated, and retained only for backward compatibility. */ deprecated, and retained only for backward compatibility.
MAYBE_LAST is non-zero if this EXPR_STMT might be the last statement
in expression statement. */
void void
genrtl_expr_stmt_value (expr, want_value) genrtl_expr_stmt_value (expr, want_value, maybe_last)
tree expr; tree expr;
int want_value; int want_value, maybe_last;
{ {
if (expr != NULL_TREE) if (expr != NULL_TREE)
{ {
...@@ -334,7 +336,7 @@ genrtl_expr_stmt_value (expr, want_value) ...@@ -334,7 +336,7 @@ genrtl_expr_stmt_value (expr, want_value)
expand_start_target_temps (); expand_start_target_temps ();
if (expr != error_mark_node) if (expr != error_mark_node)
expand_expr_stmt_value (expr, want_value); expand_expr_stmt_value (expr, want_value, maybe_last);
if (stmts_are_full_exprs_p ()) if (stmts_are_full_exprs_p ())
expand_end_target_temps (); expand_end_target_temps ();
...@@ -763,7 +765,10 @@ expand_stmt (t) ...@@ -763,7 +765,10 @@ expand_stmt (t)
break; break;
case EXPR_STMT: case EXPR_STMT:
genrtl_expr_stmt_value (EXPR_STMT_EXPR (t), TREE_ADDRESSABLE (t)); genrtl_expr_stmt_value (EXPR_STMT_EXPR (t), TREE_ADDRESSABLE (t),
TREE_CHAIN (t) == NULL
|| (TREE_CODE (TREE_CHAIN (t)) == SCOPE_STMT
&& TREE_CHAIN (TREE_CHAIN (t)) == NULL));
break; break;
case DECL_STMT: case DECL_STMT:
......
...@@ -6453,7 +6453,7 @@ expand_expr (exp, target, tmode, modifier) ...@@ -6453,7 +6453,7 @@ expand_expr (exp, target, tmode, modifier)
case LABELED_BLOCK_EXPR: case LABELED_BLOCK_EXPR:
if (LABELED_BLOCK_BODY (exp)) if (LABELED_BLOCK_BODY (exp))
expand_expr_stmt_value (LABELED_BLOCK_BODY (exp), 0); expand_expr_stmt_value (LABELED_BLOCK_BODY (exp), 0, 1);
/* Should perhaps use expand_label, but this is simpler and safer. */ /* Should perhaps use expand_label, but this is simpler and safer. */
do_pending_stack_adjust (); do_pending_stack_adjust ();
emit_label (label_rtx (LABELED_BLOCK_LABEL (exp))); emit_label (label_rtx (LABELED_BLOCK_LABEL (exp)));
...@@ -6468,7 +6468,7 @@ expand_expr (exp, target, tmode, modifier) ...@@ -6468,7 +6468,7 @@ expand_expr (exp, target, tmode, modifier)
case LOOP_EXPR: case LOOP_EXPR:
push_temp_slots (); push_temp_slots ();
expand_start_loop (1); expand_start_loop (1);
expand_expr_stmt_value (TREE_OPERAND (exp, 0), 0); expand_expr_stmt_value (TREE_OPERAND (exp, 0), 0, 1);
expand_end_loop (); expand_end_loop ();
pop_temp_slots (); pop_temp_slots ();
......
...@@ -2190,7 +2190,7 @@ void ...@@ -2190,7 +2190,7 @@ void
expand_expr_stmt (exp) expand_expr_stmt (exp)
tree exp; tree exp;
{ {
expand_expr_stmt_value (exp, -1); expand_expr_stmt_value (exp, -1, 1);
} }
/* Generate RTL to evaluate the expression EXP. WANT_VALUE tells /* Generate RTL to evaluate the expression EXP. WANT_VALUE tells
...@@ -2199,9 +2199,9 @@ expand_expr_stmt (exp) ...@@ -2199,9 +2199,9 @@ expand_expr_stmt (exp)
deprecated, and retained only for backward compatibility. */ deprecated, and retained only for backward compatibility. */
void void
expand_expr_stmt_value (exp, want_value) expand_expr_stmt_value (exp, want_value, maybe_last)
tree exp; tree exp;
int want_value; int want_value, maybe_last;
{ {
rtx value; rtx value;
tree type; tree type;
...@@ -2211,8 +2211,10 @@ expand_expr_stmt_value (exp, want_value) ...@@ -2211,8 +2211,10 @@ expand_expr_stmt_value (exp, want_value)
/* If -W, warn about statements with no side effects, /* If -W, warn about statements with no side effects,
except for an explicit cast to void (e.g. for assert()), and except for an explicit cast to void (e.g. for assert()), and
except inside a ({...}) where they may be useful. */ except for last statement in ({...}) where they may be useful. */
if (! want_value && exp != error_mark_node) if (! want_value
&& (expr_stmts_for_value == 0 || ! maybe_last)
&& exp != error_mark_node)
{ {
if (! TREE_SIDE_EFFECTS (exp)) if (! TREE_SIDE_EFFECTS (exp))
{ {
......
2002-01-04 Jakub Jelinek <jakub@redhat.com>
* gcc.dg/20020104-1.c: New test.
2002-01-04 Hans-Peter Nilsson <hp@bitrange.com> 2002-01-04 Hans-Peter Nilsson <hp@bitrange.com>
* gcc.dg/20020103-1.c: Fix typo in target selector. * gcc.dg/20020103-1.c: Fix typo in target selector.
......
/* Test whether statement with no effect warnings are not given for last
statements inside of statement expression. */
/* { dg-do compile } */
/* { dg-options "-O -Wall" } */
void bar (char *p, char *q);
int main()
{
char foo [32], *p;
({
void *s = (foo);
__builtin_memset (s, '\0', sizeof (foo));
s; /* { dg-warning "no effect" "statement with no effect warning" } */
s; /* { dg-bogus "no effect" "bogus statement with no effect warning" } */
});
p = foo;
p; /* { dg-warning "no effect" "statement with no effect warning" } */
bar (foo, p);
return 0;
}
...@@ -2720,7 +2720,7 @@ extern void expand_fixups PARAMS ((rtx)); ...@@ -2720,7 +2720,7 @@ extern void expand_fixups PARAMS ((rtx));
extern tree expand_start_stmt_expr PARAMS ((void)); extern tree expand_start_stmt_expr PARAMS ((void));
extern tree expand_end_stmt_expr PARAMS ((tree)); extern tree expand_end_stmt_expr PARAMS ((tree));
extern void expand_expr_stmt PARAMS ((tree)); extern void expand_expr_stmt PARAMS ((tree));
extern void expand_expr_stmt_value PARAMS ((tree, int)); extern void expand_expr_stmt_value PARAMS ((tree, int, int));
extern int warn_if_unused_value PARAMS ((tree)); extern int warn_if_unused_value PARAMS ((tree));
extern void expand_decl_init PARAMS ((tree)); extern void expand_decl_init PARAMS ((tree));
extern void clear_last_expr PARAMS ((void)); extern void clear_last_expr PARAMS ((void));
......
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