summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2002-02-12 22:39:42 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2002-02-12 22:39:42 +0100
commit56d4428505c7dd85bf6a49dd9b22497331b39341 (patch)
treec47e31ee211f6ebb4c3412768ea592590252152c
parent34e68c86fb3567f1046c4136bfec656387029613 (diff)
downloadgcc-56d4428505c7dd85bf6a49dd9b22497331b39341.tar.gz
jump.c (never_reached_warning): Add finish argument.
* jump.c (never_reached_warning): Add finish argument. If finish is NULL, stop on CODE_LABEL, otherwise stop before first real insn after end. * rtl.h (never_reached_warning): Adjust prototype. * cse.c (cse_insn): Pass NULL as finish to never_reached_warning. * cfgrtl.c (flow_delete_block): Pass b->end as finish to never_reached_warning. * gcc.dg/Wunreachable-1.c: New test. * gcc.dg/Wunreachable-2.c: New test. From-SVN: r49713
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/cfgrtl.c2
-rw-r--r--gcc/cse.c2
-rw-r--r--gcc/jump.c23
-rw-r--r--gcc/rtl.h2
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/Wunreachable-1.c24
-rw-r--r--gcc/testsuite/gcc.dg/Wunreachable-2.c19
8 files changed, 76 insertions, 11 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3b3ea3bfaa1..b9940e88046 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2002-02-12 Jakub Jelinek <jakub@redhat.com>
+
+ * jump.c (never_reached_warning): Add finish argument.
+ If finish is NULL, stop on CODE_LABEL, otherwise stop before first
+ real insn after end.
+ * rtl.h (never_reached_warning): Adjust prototype.
+ * cse.c (cse_insn): Pass NULL as finish to never_reached_warning.
+ * cfgrtl.c (flow_delete_block): Pass b->end as finish to
+ never_reached_warning.
+
2002-02-12 Graham Stott <grahams@redhat.com>
* config/hp/pa.h (GO_IF_LEGITIMATE_ADDRESS): Fix typos.
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 42358b2ccf0..5b99ab237e2 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -338,7 +338,7 @@ flow_delete_block (b)
insn = b->head;
- never_reached_warning (insn);
+ never_reached_warning (insn, b->end);
if (GET_CODE (insn) == CODE_LABEL)
maybe_remove_eh_handler (insn);
diff --git a/gcc/cse.c b/gcc/cse.c
index ac9e8860d38..b88a84c2cea 100644
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -5795,7 +5795,7 @@ cse_insn (insn, libcall_insn)
else
INSN_CODE (insn) = -1;
- never_reached_warning (insn);
+ never_reached_warning (insn, NULL);
/* Do not bother deleting any unreachable code,
let jump/flow do that. */
diff --git a/gcc/jump.c b/gcc/jump.c
index fcb3c61800b..fc6bef07e48 100644
--- a/gcc/jump.c
+++ b/gcc/jump.c
@@ -1913,13 +1913,12 @@ delete_for_peephole (from, to)
so it's possible to get spurious warnings from this. */
void
-never_reached_warning (avoided_insn)
- rtx avoided_insn;
+never_reached_warning (avoided_insn, finish)
+ rtx avoided_insn, finish;
{
rtx insn;
rtx a_line_note = NULL;
- int two_avoided_lines = 0;
- int contains_insn = 0;
+ int two_avoided_lines = 0, contains_insn = 0, reached_end = 0;
if (! warn_notreached)
return;
@@ -1929,10 +1928,11 @@ never_reached_warning (avoided_insn)
for (insn = avoided_insn; insn != NULL; insn = NEXT_INSN (insn))
{
- if (GET_CODE (insn) == CODE_LABEL)
+ if (finish == NULL && GET_CODE (insn) == CODE_LABEL)
break;
- else if (GET_CODE (insn) == NOTE /* A line number note? */
- && NOTE_LINE_NUMBER (insn) >= 0)
+
+ if (GET_CODE (insn) == NOTE /* A line number note? */
+ && NOTE_LINE_NUMBER (insn) >= 0)
{
if (a_line_note == NULL)
a_line_note = insn;
@@ -1941,7 +1941,14 @@ never_reached_warning (avoided_insn)
!= NOTE_LINE_NUMBER (insn));
}
else if (INSN_P (insn))
- contains_insn = 1;
+ {
+ if (reached_end)
+ break;
+ contains_insn = 1;
+ }
+
+ if (insn == finish)
+ reached_end = 1;
}
if (two_avoided_lines && contains_insn)
warning_with_file_and_line (NOTE_SOURCE_FILE (a_line_note),
diff --git a/gcc/rtl.h b/gcc/rtl.h
index ef4c5f8f146..99fabfcb3ff 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -1808,7 +1808,7 @@ extern enum rtx_code reversed_comparison_code_parts PARAMS ((enum rtx_code,
rtx, rtx, rtx));
extern void delete_for_peephole PARAMS ((rtx, rtx));
extern int condjump_in_parallel_p PARAMS ((rtx));
-extern void never_reached_warning PARAMS ((rtx));
+extern void never_reached_warning PARAMS ((rtx, rtx));
extern void purge_line_number_notes PARAMS ((rtx));
extern void copy_loop_headers PARAMS ((rtx));
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2d3c7130f9a..d9766b06395 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2002-02-12 Jakub Jelinek <jakub@redhat.com>
+
+ * gcc.dg/Wunreachable-1.c: New test.
+ * gcc.dg/Wunreachable-2.c: New test.
+
2002-02-12 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/c90-const-expr-3.c, gcc.dg/c99-const-expr-3.c: New tests.
diff --git a/gcc/testsuite/gcc.dg/Wunreachable-1.c b/gcc/testsuite/gcc.dg/Wunreachable-1.c
new file mode 100644
index 00000000000..d6d59b481aa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wunreachable-1.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wunreachable-code" } */
+
+extern void foo (void);
+extern void baz (void);
+
+void bar (int i)
+{
+ if (i < 2)
+ {
+ baz ();
+ return;
+ }
+ else
+ {
+ if (i >= 4 && i <= 5)
+ foo ();
+ return;
+ }
+
+ baz (); /* { dg-warning "will never be executed" "" } */
+ baz ();
+ baz ();
+}
diff --git a/gcc/testsuite/gcc.dg/Wunreachable-2.c b/gcc/testsuite/gcc.dg/Wunreachable-2.c
new file mode 100644
index 00000000000..8242441b0be
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wunreachable-2.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wunreachable-code" } */
+
+extern int foo (const char *);
+extern void baz (void);
+const char *a[] = { "one", "two" };
+
+void bar (void)
+{
+ int i;
+
+ for (i = 0; i < 2; i++)
+ if (! foo (a[i]))
+ return;
+
+ baz (); /* { dg-bogus "will never be executed" } */
+ baz ();
+ baz ();
+}