2005-08-09 James A. Morrison <phython@gcc.gnu.org>
authorphython <phython@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 9 Aug 2005 04:21:26 +0000 (04:21 +0000)
committerphython <phython@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 9 Aug 2005 04:21:26 +0000 (04:21 +0000)
        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.

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

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr23165.c [new file with mode: 0644]

index 751668f..a712bb9 100644 (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
index 9078730..29d9067 100644 (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 ();
        }
     }
 
index 57681cd..7a0cbd5 100644 (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.
diff --git a/gcc/testsuite/gcc.dg/pr23165.c b/gcc/testsuite/gcc.dg/pr23165.c
new file mode 100644 (file)
index 0000000..2c63eb1
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-Wextra" } */
+void foo (void)
+{
+       if (0)
+         a: ; /* { dg-warning "empty body in an if-statement" } */
+
+
+}