re PR c/23161 (Labels and empty statement warnings)
authorJames A. Morrison <phython@gcc.gnu.org>
Tue, 9 Aug 2005 04:21:26 +0000 (04:21 +0000)
committerJames A. Morrison <phython@gcc.gnu.org>
Tue, 9 Aug 2005 04:21:26 +0000 (04:21 +0000)
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

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

index 751668f29c3f4e680a55d54adb7e98bb1309d950..a712bb9d9ab9e5e0910fddb11e64155a2972b834 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 90787305ecfeacc844f5cf985119941ea69b53ea..29d90675a713e19bc47890f57d4527229315c873 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 57681cd9035361bcbca2a8c8d7f46ec0dd3856e6..7a0cbd5af738bd99affd2ea08428bd35adf018bb 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" } */
+
+
+}