re PR c/23161 (Labels and empty statement warnings)

2005-08-09  James A. Morrison  <phython@gcc.gnu.org>

        PR c/23161
        PR c/23165
        * c-typeck.c (c_finish_if_stmt): Look into STATEMENT_LISTs to see
        if the if is really empty.

From-SVN: r102896
This commit is contained in:
James A. Morrison 2005-08-09 04:21:26 +00:00
parent 2ef571e2c2
commit f14e694e82
4 changed files with 41 additions and 10 deletions

View file

@ -1,3 +1,10 @@
2005-08-09 James A. Morrison <phython@gcc.gnu.org>
PR c/23161
PR c/23165
* c-typeck.c (c_finish_if_stmt): Look into STATEMENT_LISTs to see
if the if is really empty.
2005-08-09 Steven Bosscher <stevenb@suse.de>
PR tree-optimization/23234

View file

@ -7003,20 +7003,31 @@ c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
/* Diagnose ";" via the special empty statement node that we create. */
if (extra_warnings)
{
if (TREE_CODE (then_block) == NOP_EXPR && !TREE_TYPE (then_block))
tree *inner_then = &then_block, *inner_else = &else_block;
if (TREE_CODE (*inner_then) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (*inner_then))
inner_then = &STATEMENT_LIST_TAIL (*inner_then)->stmt;
if (*inner_else && TREE_CODE (*inner_else) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (*inner_else))
inner_else = &STATEMENT_LIST_TAIL (*inner_else)->stmt;
if (TREE_CODE (*inner_then) == NOP_EXPR && !TREE_TYPE (*inner_then))
{
if (!else_block)
if (!*inner_else)
warning (0, "%Hempty body in an if-statement",
EXPR_LOCUS (then_block));
then_block = alloc_stmt_list ();
EXPR_LOCUS (*inner_then));
*inner_then = alloc_stmt_list ();
}
if (else_block
&& TREE_CODE (else_block) == NOP_EXPR
&& !TREE_TYPE (else_block))
if (*inner_else
&& TREE_CODE (*inner_else) == NOP_EXPR
&& !TREE_TYPE (*inner_else))
{
warning (0, "%Hempty body in an else-statement",
EXPR_LOCUS (else_block));
else_block = alloc_stmt_list ();
EXPR_LOCUS (*inner_else));
*inner_else = alloc_stmt_list ();
}
}

View file

@ -1,4 +1,8 @@
2005-08-09 Stevem Bosscher <stevenb@suse.de>
2005-08-09 James A. Morrison <phython@gcc.gnu.org>
* gcc.dg/pr23165.c: New test.
2005-08-09 Steven Bosscher <stevenb@suse.de>
PR tree-optimization/23234
* gcc.dg/tree-ssa/pr23234.c: New test.

View file

@ -0,0 +1,9 @@
/* { dg-do compile } */
/* { dg-options "-Wextra" } */
void foo (void)
{
if (0)
a: ; /* { dg-warning "empty body in an if-statement" } */
}