public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] Fix some -Wunreachable-code issues
@ 2002-11-02 10:07 John David Anglin
  2002-11-02 16:47 ` Jason R Thorpe
  0 siblings, 1 reply; 13+ messages in thread
From: John David Anglin @ 2002-11-02 10:07 UTC (permalink / raw)
  To: gcc-patches; +Cc: jakub, rth

I have have been working on implementing sibcalls on hppa64-hp-hpux11
and noticed that when sibcalls are enabled, Wunreachable-1.c fails
because of an extra warning:

/xxx/gnu/gcc-3.3/gcc/gcc/testsuite/gcc.dg/Wunreachable-1.c:12: warning: will never be executed

--- gcc/testsuite/gcc.dg/Wunreachable-1.c.jj    Tue Feb 12 17:54:33 2002
+++ gcc/testsuite/gcc.dg/Wunreachable-1.c       Tue Feb 12 17:53:17 2002
@@ -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;

This appears to fail because we have a different placement of notes on
hppa64-hp-hpux11* (I think because of the pic register restore after calls).

This is rtl on hppa64-hp-hpux11:

(note 96 20 19 2 [bb 2] NOTE_INSN_BASIC_BLOCK)

(insn 19 96 25 2 0000000000000000 (set (reg:DI 27 %r27)
        (reg:DI 68)) -1 (nil)
    (nil))

(note 25 19 26 2 ("/xxx/gnu/gcc-3.3/gcc/gcc/testsuite/gcc.dg/Wunreachable-1.c") 12)

(jump_insn 26 25 27 2 0000000000000000 (set (pc)
	(label_ref 87)) -1 (nil)
    (nil))

"note 96" is the avoided_insn and "jump_insn 26" is the finish insn.

On hppa-linux, we have:

(note 19 16 74 ("/home/dave/gcc-3.3/gcc/gcc/testsuite/gcc.dg/Wunreachable-1.c") 12)

(note 74 19 20 2 [bb 2] NOTE_INSN_BASIC_BLOCK)

(jump_insn 20 74 21 2 (nil) (set (pc)
        (label_ref 65)) -1 (nil)
    (nil))

Looking at the loop in never_reached_warning, we will have two avoided lines
and contains_insn will be true because of insn 19 on hppa64.

Possibly, contains_insn should only be set to 1 after seeing the first note?

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)

^ permalink raw reply	[flat|nested] 13+ messages in thread
* [PATCH] Fix some -Wunreachable-code issues
@ 2002-02-12  9:36 Jakub Jelinek
  2002-02-12 11:07 ` Richard Henderson
  0 siblings, 1 reply; 13+ messages in thread
From: Jakub Jelinek @ 2002-02-12  9:36 UTC (permalink / raw)
  To: rth; +Cc: gcc-patches

Hi!

gcc with -Wunreachable-code with all the cfg changes never warns for
obviously unreachable code while emits bogus warnings for reachable code
(even without inlining), while at least Wunreachable-2.c used to work
properly in gcc <= 3.0.x.
The issue is that never_reached_warning got completely out of sync with what
cfgrtl.c actually deletes.
never_reached_warning stopped on first CODE_LABEL, while flow_delete_block
deletes a basic block (CODE_LABEL might appear close to b->head ->
never_reached_warning wouldn't warn even if it should) or on the other side
there might not be any CODE_LABELs right after end of the basic block
(as can be seen in Wunreachable-2.c during tail call optimization).
Ok to commit if testing is ok?

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.

	* gcc.dg/Wunreachable-1.c: New test.
	* gcc.dg/Wunreachable-2.c: New test.

--- gcc/testsuite/gcc.dg/Wunreachable-1.c.jj	Tue Feb 12 17:54:33 2002
+++ gcc/testsuite/gcc.dg/Wunreachable-1.c	Tue Feb 12 17:53:17 2002
@@ -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 ();
+}
--- gcc/testsuite/gcc.dg/Wunreachable-2.c.jj	Tue Feb 12 17:56:37 2002
+++ gcc/testsuite/gcc.dg/Wunreachable-2.c	Tue Feb 12 17:56:22 2002
@@ -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 ();
+}
--- gcc/rtl.h.jj	Thu Jan 31 19:44:00 2002
+++ gcc/rtl.h	Tue Feb 12 17:19:51 2002
@@ -1808,7 +1808,7 @@ extern enum rtx_code reversed_comparison
 							     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));
 
--- gcc/jump.c.jj	Tue Dec 18 01:28:10 2001
+++ gcc/jump.c	Tue Feb 12 17:46:34 2002
@@ -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),
--- gcc/cse.c.jj	Thu Jan 24 23:37:04 2002
+++ gcc/cse.c	Tue Feb 12 17:23:02 2002
@@ -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.  */
--- gcc/cfgrtl.c.jj	Tue Feb  5 12:17:07 2002
+++ gcc/cfgrtl.c	Tue Feb 12 17:24:36 2002
@@ -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);

	Jakub

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2002-11-18 22:16 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-02 10:07 [PATCH] Fix some -Wunreachable-code issues John David Anglin
2002-11-02 16:47 ` Jason R Thorpe
2002-11-02 17:10   ` John David Anglin
2002-11-03 15:30     ` Richard Henderson
2002-11-05 14:08     ` Jason R Thorpe
2002-11-05 15:15     ` Jason R Thorpe
2002-11-05 15:20       ` Richard Henderson
2002-11-05 18:42         ` Jason R Thorpe
2002-11-18 14:16           ` Richard Henderson
2002-11-05 15:22       ` John David Anglin
2002-11-05 19:25         ` Jason R Thorpe
  -- strict thread matches above, loose matches on Subject: below --
2002-02-12  9:36 Jakub Jelinek
2002-02-12 11:07 ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).