[patch] Avoid generating warnings for -O2 -Wunreachable-code

Eric Fisher joefoxreal@gmail.com
Wed Nov 4 05:38:00 GMT 2009


Hi,

This patch will avoid generating warnings for -O2 -Wunreachable-code,
and has been tested on my machine. Also two test cases need be
modified.

Is it OK?

Regards,
Eric

2009-11-04  Eric Fisher  <joefoxreal@gmail.com>

        * gcc/tree-ssa-loop-ivcanon.c: Set the statement locations as
UNKNOW_LOCATION to avoid generating warnings for -Wunreachable-code.
        * gcc.dg/Wunreachable-2.c: Remove xfail from dg-bogus.
        * gcc.dg/Wunreachable-8.c: Remove xfail from dg-bogus.

Index: tree-ssa-loop-ivcanon.c
===================================================================
--- tree-ssa-loop-ivcanon.c	(revision 153584)
+++ tree-ssa-loop-ivcanon.c	(working copy)
@@ -414,6 +414,24 @@ try_unroll_loop_completely (struct loop
       VEC_free (edge, heap, to_remove);
       free (wont_exit);
       free_original_copy_tables ();
+
+      /* The original loop body will be removed later.
+         Set the statement locations as UNKNOW_LOCATION to
+         avoid generating warnings for -Wunreachable-code. */
+      unsigned n = loop->num_nodes;
+      basic_block *bbs = get_loop_body (loop);
+      gcc_assert (n > 1);
+      gcc_assert (bbs[0] == loop->header);
+      for (i = 1; i < n; i++)
+        {
+          gimple_stmt_iterator gsi;
+          for (gsi = gsi_start_bb (bbs[i]); !gsi_end_p (gsi); gsi_next (&gsi))
+            {
+              gimple stmt = gsi_stmt (gsi);
+              gimple_set_location (stmt, UNKNOWN_LOCATION);
+            }
+        }
+      free (bbs);
     }

   cond = last_stmt (exit->src);

Index: testsuite/gcc.dg/Wunreachable-2.c
===================================================================
--- testsuite/gcc.dg/Wunreachable-2.c	(revision 153584)
+++ testsuite/gcc.dg/Wunreachable-2.c	(working copy)
@@ -9,8 +9,8 @@ void bar (void)
 {
   int i;

-  for (i = 0; i < 2; i++)  /* { dg-bogus "will never be executed" ""
{ xfail *-*-* } } */
-    if (! foo (a[i]))  /* { dg-bogus "will never be executed" "" {
xfail *-*-* } } */
+  for (i = 0; i < 2; i++)  /* { dg-bogus "will never be executed" } */
+    if (! foo (a[i]))  /* { dg-bogus "will never be executed" } */
       return;

   baz ();	/* { dg-bogus "will never be executed" } */

Index: testsuite/gcc.dg/Wunreachable-8.c
===================================================================
--- testsuite/gcc.dg/Wunreachable-8.c	(revision 153584)
+++ testsuite/gcc.dg/Wunreachable-8.c	(working copy)
@@ -4,9 +4,9 @@ float Factorial(float X)
 {
   float val = 1.0;
   int k,j;
-  for (k=1; k < 5; k++) /* { dg-bogus "will never be executed" "" {
xfail *-*-* } } */
+  for (k=1; k < 5; k++) /* { dg-bogus "will never be executed" } */
     {
-      val += 1.0; /* { dg-bogus "will never be executed" "" { xfail
*-*-* } } */
+      val += 1.0; /* { dg-bogus "will never be executed" } */
     }
   return (val); /* { dg-bogus "will never be executed" } */
 }


------- make check-gcc, before patched --------

XPASS: gcc.dg/Warray-bounds.c  (test for warnings, line 59)
XPASS: gcc.dg/Warray-bounds.c  (test for warnings, line 65)
XPASS: gcc.dg/Wunreachable-8.c  (test for bogus messages, line 7)
XPASS: gcc.dg/guality/example.c  -O0  execution test
XPASS: gcc.dg/guality/pr41353-1.c  -O0  line 28 j == 28 + 37
XPASS: gcc.dg/guality/pr41447-1.c  -O0  execution test
XPASS: gcc.dg/guality/pr41616-1.c  -O0  execution test
XPASS: gcc.dg/struct/wo_prof_array_through_pointer.c scan-ipa-dump
ipa_struct_reorg "Number of structures to transform is 1"

FAIL: gcc.dg/pr34668-1.c (internal compiler error)
FAIL: gcc.dg/pr34668-1.c (test for excess errors)
FAIL: gcc.dg/struct/wo_prof_double_malloc.c (internal compiler error)
FAIL: gcc.dg/struct/wo_prof_double_malloc.c (test for excess errors)
FAIL: gcc.target/i386/avx-vmovntdq-256-1.c (test for excess errors)
FAIL: gcc.target/i386/avx-vmovntpd-256-1.c (test for excess errors)
FAIL: gcc.target/i386/avx-vmovntps-256-1.c (test for excess errors)

                === gcc Summary ===

# of expected passes            60156
# of unexpected failures        7
# of unexpected successes       8
# of expected failures          239
# of unresolved testcases       4
# of unsupported tests          597

------- make check-gcc, after patched --------

XPASS: gcc.dg/Warray-bounds.c  (test for warnings, line 59)
XPASS: gcc.dg/Warray-bounds.c  (test for warnings, line 65)
XPASS: gcc.dg/guality/example.c  -O0  execution test
XPASS: gcc.dg/guality/pr41353-1.c  -O0  line 28 j == 28 + 37
XPASS: gcc.dg/guality/pr41447-1.c  -O0  execution test
XPASS: gcc.dg/guality/pr41616-1.c  -O0  execution test
XPASS: gcc.dg/struct/wo_prof_array_through_pointer.c scan-ipa-dump
ipa_struct_reorg "Number of structures to transform is 1"

FAIL: gcc.dg/pr34668-1.c (internal compiler error)
FAIL: gcc.dg/pr34668-1.c (test for excess errors)
FAIL: gcc.dg/struct/wo_prof_double_malloc.c (internal compiler error)
FAIL: gcc.dg/struct/wo_prof_double_malloc.c (test for excess errors)
FAIL: gcc.target/i386/avx-vmovntdq-256-1.c (test for excess errors)
FAIL: gcc.target/i386/avx-vmovntpd-256-1.c (test for excess errors)
FAIL: gcc.target/i386/avx-vmovntps-256-1.c (test for excess errors)

		=== gcc Summary ===

# of expected passes		60160
# of unexpected failures	7
# of unexpected successes	7
# of expected failures		236
# of unresolved testcases	4
# of unsupported tests		597
/media/E/svn-gcc/build-trunk/gcc/xgcc  version 4.5.0 20091027
(experimental) (GCC)



More information about the Gcc-patches mailing list