This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

optimization/3846: -Wunreachable-code wrongly included in -Wall when using -O



>Number:         3846
>Category:       optimization
>Synopsis:       With -O, -Wall flags unreachable code when it should not
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 27 12:26:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        3.0
>Organization:
None
>Environment:
System: SunOS taiko 5.7 Generic_106541-10 sun4u sparc SUNW,UltraAX-MP
Architecture: sun4

host: sparc-sun-solaris2.7
build: sparc-sun-solaris2.7
target: sparc-sun-solaris2.7
configured with: /depot-common/src/gcc-3.0/configure  : (reconfigured) /depot-common/src/gcc-3.0/configure --prefix=/depot/pkg/gcc-3.0 : (reconfigured) /depot-common/src/gcc-3.0/configure --prefix=/depot/pkg/gcc-3.0
>Description:

When -O is used, specifying -Wall appears to include the -Wunreachable-code
option, even though the documentation says it should not:

	 This option is not made part of `-Wall' because in a debugging
     version of a program there is often substantial code which checks
     correct functioning of the program and is, hopefully, unreachable
     because the program does work.  Another common use of unreachable
     code is to provide behaviour which is selectable at compile-time.

>How-To-Repeat:

taiko:/depot/pkg/gcc-3.0/bin% gcc -v    
Reading specs from /depot/pkg/gcc-3.0/lib/gcc-lib/sparc-sun-solaris2.7/3.0/specs
Configured with: /depot-common/src/gcc-3.0/configure  : (reconfigured) /depot-common/src/gcc-3.0/configure --prefix=/depot/pkg/gcc-3.0 : (reconfigured) /depot-common/src/gcc-3.0/configure --prefix=/depot/pkg/gcc-3.0
Thread model: posix
gcc version 3.0
taiko:/depot/pkg/gcc-3.0/bin% cat duff.c
#include <stdlib.h>

void duffcpy(char *dest, const char *src, unsigned long size) {

    switch (size & 3) {
        for (;;) {
            *dest++ = *src++;
        case 3:
            *dest++ = *src++;
        case 2:
            *dest++ = *src++;
        case 1:
            *dest++ = *src++;
        case 0:
            if (size <= 3) break;
            size -= 4;
        }
    }
}

int main(int argc, char **argv) { exit(0); }
taiko:/depot/pkg/gcc-3.0/bin% gcc -O -Wall duff.c 
duff.c: In function `duffcpy':
duff.c:6: warning: unreachable code at beginning of switch statement
taiko:/depot/pkg/gcc-3.0/bin% 

>Fix:

Make the ``unreachable code'' warning conditional on -Wunreachable-code being
set. With the patch below gcc does the right thing:

taiko:/depot/pkg/gcc-3.0/bin% gcc -O -Wall duff.c
taiko:/depot/pkg/gcc-3.0/bin% gcc -O -Wall -Wunreachable-code duff.c
duff.c: In function `duffcpy':
duff.c:6: warning: unreachable code at beginning of switch statement
taiko:/depot/pkg/gcc-3.0/bin% 

--- stmt.c.orig	Fri Jul 27 10:40:12 2001
+++ stmt.c	Fri Jul 27 10:40:40 2001
@@ -4379,7 +4379,7 @@
 	      while (insn && (GET_CODE (insn) != NOTE || NOTE_LINE_NUMBER (insn) < 0));
 
 	      /* If insn is zero, then there must have been a syntax error.  */
-	      if (insn)
+	      if (insn && warn_notreached)
 		warning_with_file_and_line (NOTE_SOURCE_FILE (insn),
 					    NOTE_LINE_NUMBER (insn),
 					    "unreachable code at beginning of %s",
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]