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

* Re: [PATCH] Fix some -Wunreachable-code issues
  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
  0 siblings, 1 reply; 13+ messages in thread
From: Jason R Thorpe @ 2002-11-02 16:47 UTC (permalink / raw)
  To: John David Anglin; +Cc: gcc-patches, jakub, rth

On Sat, Nov 02, 2002 at 01:06:54PM -0500, John David Anglin wrote:

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

I wonder if PR 3846 is related?

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

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

* Re: [PATCH] Fix some -Wunreachable-code issues
  2002-11-02 16:47 ` Jason R Thorpe
@ 2002-11-02 17:10   ` John David Anglin
  2002-11-03 15:30     ` Richard Henderson
                       ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: John David Anglin @ 2002-11-02 17:10 UTC (permalink / raw)
  To: Jason R Thorpe; +Cc: gcc-patches, jakub, rth

> On Sat, Nov 02, 2002 at 01:06:54PM -0500, John David Anglin wrote:
> 
>  > Possibly, contains_insn should only be set to 1 after seeing the first note?
> 
> I wonder if PR 3846 is related?

I can't duplicate the PR on hppa2.0w-hp-hpux11.11 or hppa64-hp-hpux11.11.
Jakub's patch might have fixed this PR.

I have now done a complete bootstrap of the enclosed patch on
hppa64-hp-hpux11.11.  There are no regressions and it fixes the
failure of -Wunreachable-1.c.

Ok for main?

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

2002-11-02  John David Anglin  <dave@hiauly1.hia.nrc.ca>

	* jump.c (never_reached_warning): Don't set contains_insn until the
	first line note is seen.

Index: jump.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/jump.c,v
retrieving revision 1.212
diff -u -3 -p -r1.212 jump.c
--- jump.c	30 Sep 2002 19:35:16 -0000	1.212
+++ jump.c	2 Nov 2002 18:22:56 -0000
@@ -1917,7 +1917,7 @@ never_reached_warning (avoided_insn, fin
 	}
       else if (INSN_P (insn))
 	{
-	  if (reached_end)
+	  if (reached_end || a_line_note == NULL)
 	    break;
 	  contains_insn = 1;
 	}

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

* Re: [PATCH] Fix some -Wunreachable-code issues
  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
  2 siblings, 0 replies; 13+ messages in thread
From: Richard Henderson @ 2002-11-03 15:30 UTC (permalink / raw)
  To: John David Anglin; +Cc: Jason R Thorpe, gcc-patches, jakub

On Sat, Nov 02, 2002 at 08:10:19PM -0500, John David Anglin wrote:
> 	* jump.c (never_reached_warning): Don't set contains_insn until the
> 	first line note is seen.

Ok.


r~

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

* Re: [PATCH] Fix some -Wunreachable-code issues
  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
  2 siblings, 0 replies; 13+ messages in thread
From: Jason R Thorpe @ 2002-11-05 14:08 UTC (permalink / raw)
  To: John David Anglin; +Cc: gcc-patches, jakub, rth

On Sat, Nov 02, 2002 at 08:10:19PM -0500, John David Anglin wrote:

 > I can't duplicate the PR on hppa2.0w-hp-hpux11.11 or hppa64-hp-hpux11.11.
 > Jakub's patch might have fixed this PR.

Ah, I think I know why that PR doesn't trip anymore -- there is no
comparison in the for() statement.  I had filed another PR containing
a Duff's Device, which Richard closed as a duplicate.  The test case
in my PR still causes a bogus warning.

I'm writing up a few testsuite tests using a Duff's Device, and will
post them shortly.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

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

* Re: [PATCH] Fix some -Wunreachable-code issues
  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 15:22       ` John David Anglin
  2 siblings, 2 replies; 13+ messages in thread
From: Jason R Thorpe @ 2002-11-05 15:15 UTC (permalink / raw)
  To: John David Anglin; +Cc: gcc-patches, jakub, rth

[-- Attachment #1: Type: text/plain, Size: 1153 bytes --]

On Sat, Nov 02, 2002 at 08:10:19PM -0500, John David Anglin wrote:

 > > I wonder if PR 3846 is related?
 > 
 > I can't duplicate the PR on hppa2.0w-hp-hpux11.11 or hppa64-hp-hpux11.11.
 > Jakub's patch might have fixed this PR.

Here are 3 Duff's device tests:

	1. Loop start before first label, no comparison in for()
	   statement.  PR 3846.  This test no longer fails (guess
	   the PR should be closed).

	2. Loop start before first label, comparison in while()
	   statement.  PR 5230 (which was closed as a duplicate
	   of 3846, but I think I'll reopen, since this still
	   produces a bogus warning).  This test fails.  It is
	   a regression relative to 2.95.3, which does not produce
	   a warning for this code.  The warning is bogus; the
	   while() statement is clearly reachable, since the loop
	   eventually terminates.

	3. Loop start after first label.  This is basically the
	   code from Tom Duff's original usenet posting about it.
	   This test does not fail.

OK for mainline?

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

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

[-- Attachment #2: duff-test-patch --]
[-- Type: text/plain, Size: 3869 bytes --]

Index: gcc.dg/duff-1.c
===================================================================
RCS file: gcc.dg/duff-1.c
diff -N gcc.dg/duff-1.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc.dg/duff-1.c	5 Nov 2002 23:07:36 -0000
***************
*** 0 ****
--- 1,50 ----
+ /* Duff's device is legal C; test to make sure the compiler
+    doesn't complain about it.
+ 
+    Jason Thorpe <thorpej@wasabisystems.com>
+    Derived from PR 3846.  */
+ 
+ /* { dg-do run } */
+ /* { dg-options "-O2" } */
+ 
+ extern void abort (void);
+ extern void exit (int);
+ 
+ typedef __SIZE_TYPE__ size_t;
+ extern int memcmp (const void *, const void *, size_t);
+ 
+ void
+ duffcpy (char *dst, const char *src, unsigned long size)
+ {
+   switch (size & 3)
+     {
+     for (;;)
+       {
+ 	*dst++ = *src++;
+     case 3:
+ 	*dst++ = *src++;
+     case 2:
+ 	*dst++ = *src++;
+     case 1:
+ 	*dst++ = *src++;
+     case 0:
+ 	if (size <= 3)
+ 	  break;
+ 	size -= 4;
+       }
+     }
+ }
+ 
+ const char testpat[] = "The quick brown fox jumped over the lazy dog.";
+ 
+ int
+ main()
+ {
+   char buf[64];
+ 
+   duffcpy (buf, testpat, sizeof (testpat));
+   if (memcmp (buf, testpat, sizeof (testpat)) != 0)
+     abort ();
+ 
+   exit (0);
+ }
Index: gcc.dg/duff-2.c
===================================================================
RCS file: gcc.dg/duff-2.c
diff -N gcc.dg/duff-2.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc.dg/duff-2.c	5 Nov 2002 23:07:36 -0000
***************
*** 0 ****
--- 1,53 ----
+ /* Duff's device is legal C; test to make sure the compiler
+    doesn't complain about it.
+ 
+    Jason Thorpe <thorpej@wasabisystems.com>
+    Derived from the BSD Telnet Kerberos 4 checksum routine.
+    See also PR 5230.  */
+ 
+ /* { dg-do run } */
+ /* { dg-options "-O2" } */
+ 
+ extern void abort (void);
+ extern void exit (int);
+ 
+ int
+ cksum (const unsigned char *src, unsigned long size)
+ {
+   int ck = 0;
+ 
+   switch (size & 3)
+     {
+     while (size > 0)
+       {
+     case 0:
+ 	ck ^= (int)*src++ << 24;
+ 	--size;
+     case 3:
+ 	ck ^= (int)*src++ << 16;
+ 	--size;
+     case 2:
+ 	ck ^= (int)*src++ << 8;
+ 	--size;
+     case 1:
+ 	ck ^= (int)*src++;
+ 	--size;
+       }
+     }
+ 
+   return ck;
+ }
+ 
+ const char testpat[] = "The quick brown fox jumped over the lazy dog.";
+ 
+ int
+ main()
+ {
+   int ck;
+ 
+   ck = cksum ((const unsigned char *) testpat, sizeof (testpat));
+   if (ck != 925902908)
+     abort ();
+ 
+   exit (0);
+ }
Index: gcc.dg/duff-3.c
===================================================================
RCS file: gcc.dg/duff-3.c
diff -N gcc.dg/duff-3.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc.dg/duff-3.c	5 Nov 2002 23:07:36 -0000
***************
*** 0 ****
--- 1,47 ----
+ /* Duff's device is legal C; test to make sure the compiler
+    doesn't complain about it.
+ 
+    Jason Thorpe <thorpej@wasabisystems.com>
+    Derived from Tom Duff's original usenet message about the device.  */
+ 
+ /* { dg-do run } */
+ /* { dg-options "-O2" } */
+ 
+ extern void abort (void);
+ extern void exit (int);
+ 
+ typedef __SIZE_TYPE__ size_t;
+ extern int memcmp (const void *, const void *, size_t);
+ 
+ void
+ duffcpy (char *dst, const char *src, unsigned long size)
+ {
+   unsigned long n = (size + 7) / 8;
+ 
+   switch (size % 8)
+     {
+     case 0:	do {	*dst++ = *src++;
+     case 7:		*dst++ = *src++;
+     case 6:		*dst++ = *src++;
+     case 5:		*dst++ = *src++;
+     case 4:		*dst++ = *src++;
+     case 3:		*dst++ = *src++;
+     case 2:		*dst++ = *src++;
+     case 1:		*dst++ = *src++;
+ 		} while (--n > 0);
+     }
+ }
+ 
+ const char testpat[] = "The quick brown fox jumped over the lazy dog.";
+ 
+ int
+ main()
+ {
+   char buf[64];
+ 
+   duffcpy (buf, testpat, sizeof (testpat));
+   if (memcmp (buf, testpat, sizeof (testpat)) != 0)
+     abort ();
+ 
+   exit (0);
+ }

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

* Re: [PATCH] Fix some -Wunreachable-code issues
  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-05 15:22       ` John David Anglin
  1 sibling, 1 reply; 13+ messages in thread
From: Richard Henderson @ 2002-11-05 15:20 UTC (permalink / raw)
  To: Jason R Thorpe, John David Anglin, gcc-patches, jakub

On Tue, Nov 05, 2002 at 03:15:16PM -0800, Jason R Thorpe wrote:
> 	* gcc.dg/duff-1.c: New test.
> 	* gcc.dg/duff-2.c: New test.
> 	* gcc.dg/duff-3.c: New test.

Nearly.

> + 	ck ^= (int)*src++ << 24;

Fails for INT_MAX < 0x7fffffff.  Should check limits.h
and chose either int or long.


r~

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

* Re: [PATCH] Fix some -Wunreachable-code issues
  2002-11-05 15:15     ` Jason R Thorpe
  2002-11-05 15:20       ` Richard Henderson
@ 2002-11-05 15:22       ` John David Anglin
  2002-11-05 19:25         ` Jason R Thorpe
  1 sibling, 1 reply; 13+ messages in thread
From: John David Anglin @ 2002-11-05 15:22 UTC (permalink / raw)
  To: Jason R Thorpe; +Cc: gcc-patches, jakub, rth

> Here are 3 Duff's device tests:
> 
> 	1. Loop start before first label, no comparison in for()
> 	   statement.  PR 3846.  This test no longer fails (guess
> 	   the PR should be closed).
> 
> 	2. Loop start before first label, comparison in while()
> 	   statement.  PR 5230 (which was closed as a duplicate
> 	   of 3846, but I think I'll reopen, since this still
> 	   produces a bogus warning).  This test fails.  It is
> 	   a regression relative to 2.95.3, which does not produce
> 	   a warning for this code.  The warning is bogus; the
> 	   while() statement is clearly reachable, since the loop
> 	   eventually terminates.

There was I believe a suggested fix with PR 3846.  Was this looked at?

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

* Re: [PATCH] Fix some -Wunreachable-code issues
  2002-11-05 15:20       ` Richard Henderson
@ 2002-11-05 18:42         ` Jason R Thorpe
  2002-11-18 14:16           ` Richard Henderson
  0 siblings, 1 reply; 13+ messages in thread
From: Jason R Thorpe @ 2002-11-05 18:42 UTC (permalink / raw)
  To: Richard Henderson, John David Anglin, gcc-patches, jakub

[-- Attachment #1: Type: text/plain, Size: 330 bytes --]

On Tue, Nov 05, 2002 at 03:20:02PM -0800, Richard Henderson wrote:

 > Fails for INT_MAX < 0x7fffffff.  Should check limits.h
 > and chose either int or long.

D'oh.  Fixed thus.

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

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

[-- Attachment #2: duff-test-patch --]
[-- Type: text/plain, Size: 4021 bytes --]

Index: gcc.dg/duff-1.c
===================================================================
RCS file: gcc.dg/duff-1.c
diff -N gcc.dg/duff-1.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc.dg/duff-1.c	6 Nov 2002 02:35:33 -0000
***************
*** 0 ****
--- 1,50 ----
+ /* Duff's device is legal C; test to make sure the compiler
+    doesn't complain about it.
+ 
+    Jason Thorpe <thorpej@wasabisystems.com>
+    Derived from PR 3846.  */
+ 
+ /* { dg-do run } */
+ /* { dg-options "-O2" } */
+ 
+ extern void abort (void);
+ extern void exit (int);
+ 
+ typedef __SIZE_TYPE__ size_t;
+ extern int memcmp (const void *, const void *, size_t);
+ 
+ void
+ duffcpy (char *dst, const char *src, unsigned long size)
+ {
+   switch (size & 3)
+     {
+     for (;;)
+       {
+ 	*dst++ = *src++;
+     case 3:
+ 	*dst++ = *src++;
+     case 2:
+ 	*dst++ = *src++;
+     case 1:
+ 	*dst++ = *src++;
+     case 0:
+ 	if (size <= 3)
+ 	  break;
+ 	size -= 4;
+       }
+     }
+ }
+ 
+ const char testpat[] = "The quick brown fox jumped over the lazy dog.";
+ 
+ int
+ main()
+ {
+   char buf[64];
+ 
+   duffcpy (buf, testpat, sizeof (testpat));
+   if (memcmp (buf, testpat, sizeof (testpat)) != 0)
+     abort ();
+ 
+   exit (0);
+ }
Index: gcc.dg/duff-2.c
===================================================================
RCS file: gcc.dg/duff-2.c
diff -N gcc.dg/duff-2.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc.dg/duff-2.c	6 Nov 2002 02:35:33 -0000
***************
*** 0 ****
--- 1,60 ----
+ /* Duff's device is legal C; test to make sure the compiler
+    doesn't complain about it.
+ 
+    Jason Thorpe <thorpej@wasabisystems.com>
+    Derived from the BSD Telnet Kerberos 4 checksum routine.
+    See also PR 5230.  */
+ 
+ /* { dg-do run } */
+ /* { dg-options "-O2" } */
+ 
+ extern void abort (void);
+ extern void exit (int);
+ 
+ #if __INT_MAX__ >= 2147483647
+ /* At least 32-bit integers. */
+ typedef int type32;
+ #else
+ typedef long type32;
+ #endif
+ 
+ type32
+ cksum (const unsigned char *src, unsigned long size)
+ {
+   type32 ck = 0;
+ 
+   switch (size & 3)
+     {
+     while (size > 0)
+       {
+     case 0:
+ 	ck ^= (type32)*src++ << 24;
+ 	--size;
+     case 3:
+ 	ck ^= (type32)*src++ << 16;
+ 	--size;
+     case 2:
+ 	ck ^= (type32)*src++ << 8;
+ 	--size;
+     case 1:
+ 	ck ^= (type32)*src++;
+ 	--size;
+       }
+     }
+ 
+   return ck;
+ }
+ 
+ const char testpat[] = "The quick brown fox jumped over the lazy dog.";
+ 
+ int
+ main()
+ {
+   type32 ck;
+ 
+   ck = cksum ((const unsigned char *) testpat, sizeof (testpat));
+   if (ck != 925902908)
+     abort ();
+ 
+   exit (0);
+ }
Index: gcc.dg/duff-3.c
===================================================================
RCS file: gcc.dg/duff-3.c
diff -N gcc.dg/duff-3.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc.dg/duff-3.c	6 Nov 2002 02:35:33 -0000
***************
*** 0 ****
--- 1,47 ----
+ /* Duff's device is legal C; test to make sure the compiler
+    doesn't complain about it.
+ 
+    Jason Thorpe <thorpej@wasabisystems.com>
+    Derived from Tom Duff's original usenet message about the device.  */
+ 
+ /* { dg-do run } */
+ /* { dg-options "-O2" } */
+ 
+ extern void abort (void);
+ extern void exit (int);
+ 
+ typedef __SIZE_TYPE__ size_t;
+ extern int memcmp (const void *, const void *, size_t);
+ 
+ void
+ duffcpy (char *dst, const char *src, unsigned long size)
+ {
+   unsigned long n = (size + 7) / 8;
+ 
+   switch (size % 8)
+     {
+     case 0:	do {	*dst++ = *src++;
+     case 7:		*dst++ = *src++;
+     case 6:		*dst++ = *src++;
+     case 5:		*dst++ = *src++;
+     case 4:		*dst++ = *src++;
+     case 3:		*dst++ = *src++;
+     case 2:		*dst++ = *src++;
+     case 1:		*dst++ = *src++;
+ 		} while (--n > 0);
+     }
+ }
+ 
+ const char testpat[] = "The quick brown fox jumped over the lazy dog.";
+ 
+ int
+ main()
+ {
+   char buf[64];
+ 
+   duffcpy (buf, testpat, sizeof (testpat));
+   if (memcmp (buf, testpat, sizeof (testpat)) != 0)
+     abort ();
+ 
+   exit (0);
+ }

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

* Re: [PATCH] Fix some -Wunreachable-code issues
  2002-11-05 15:22       ` John David Anglin
@ 2002-11-05 19:25         ` Jason R Thorpe
  0 siblings, 0 replies; 13+ messages in thread
From: Jason R Thorpe @ 2002-11-05 19:25 UTC (permalink / raw)
  To: John David Anglin; +Cc: gcc-patches, jakub, rth

On Tue, Nov 05, 2002 at 06:22:45PM -0500, John David Anglin wrote:

 > There was I believe a suggested fix with PR 3846.  Was this looked at?

The suggested fix is to conditionalize that particular warning on
warn_notreached, such that the warning would only happen with
-Wunreachable-code.  But I don't think that is the correct fix for
this particular problem, since the code in question is, in fact,
reachable.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

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

* Re: [PATCH] Fix some -Wunreachable-code issues
  2002-11-05 18:42         ` Jason R Thorpe
@ 2002-11-18 14:16           ` Richard Henderson
  0 siblings, 0 replies; 13+ messages in thread
From: Richard Henderson @ 2002-11-18 14:16 UTC (permalink / raw)
  To: Jason R Thorpe, John David Anglin, gcc-patches, jakub

On Tue, Nov 05, 2002 at 06:42:03PM -0800, Jason R Thorpe wrote:
> On Tue, Nov 05, 2002 at 03:20:02PM -0800, Richard Henderson wrote:
> 
>  > Fails for INT_MAX < 0x7fffffff.  Should check limits.h
>  > and chose either int or long.
> 
> D'oh.  Fixed thus.
> 
> 	* gcc.dg/duff-1.c: New test.
> 	* gcc.dg/duff-2.c: New test.
> 	* gcc.dg/duff-3.c: New test.

Ok.


r~

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

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

On Tue, Feb 12, 2002 at 06:12:20PM +0100, Jakub Jelinek wrote:
> 	* 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.

Ok.


r~

^ 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).