This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug c/16881] New: -O1 -Wunreachable-code incorrect warning


int main(void)
{
        int c = 42;
        int d = 1;

        if(c == 42)
                d=0;
        else
                return d;

        return d;
}

When compiled with -O1 (or higher) and -Wunreachable-code, gcc produces a
warning about the d=0 line being unreachable. Possibly this is just a line
number confusion when optimizing as the first return is never executed. The
warning only occurs when the else is a return.

With -O0 or no -O flags, this returns no warings at all which also is incorrect
as the first return is never executed.

The compiled version does function correctly.

The incorrect warning is produced on the above code in 2.95, 3.2, 3.3 and 3.4.
Oddly enough, 3.0 does not produce the warning. All versiosn are from debian
unstable updated as of this morning.

gcc-3.4 -v -save-temps -O1 -Wunreachable-code -o unreachable-code1
unreachable-code1.c
Reading specs from /usr/lib/gcc/i486-linux/3.4.1/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.4
--enable-shared --with-system-zlib --enable-nls --without-included-gettext
--program-suffix=-3.4 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt
--enable-clocale=gnu --enable-libstdcxx-debug --disable-werror i486-linux
Thread model: posix
gcc version 3.4.1 (Debian 3.4.1-5)
 /usr/lib/gcc/i486-linux/3.4.1/cc1 -E -quiet -v unreachable-code1.c -mtune=i486
-Wunreachable-code -O1 -o unreachable-code1.i
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux/3.4.1/../../../../i486-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc/i486-linux/3.4.1/include
 /usr/include
End of search list.
 /usr/lib/gcc/i486-linux/3.4.1/cc1 -fpreprocessed unreachable-code1.i -quiet
-dumpbase unreachable-code1.c -mtune=i486 -auxbase unreachable-code1 -O1
-Wunreachable-code -version -o unreachable-code1.s
GNU C version 3.4.1 (Debian 3.4.1-5) (i486-linux)
        compiled by GNU C version 3.4.1 (Debian 3.4.1-5).
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129583
unreachable-code1.c: In function `main':
unreachable-code1.c:7: warning: will never be executed
 as -V -Qy -o unreachable-code1.o unreachable-code1.s
GNU assembler version 2.15 (i386-linux) using BFD version 2.15
 /usr/lib/gcc/i486-linux/3.4.1/collect2 --eh-frame-hdr -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o unreachable-code1
/usr/lib/gcc/i486-linux/3.4.1/../../../crt1.o
/usr/lib/gcc/i486-linux/3.4.1/../../../crti.o
/usr/lib/gcc/i486-linux/3.4.1/crtbegin.o -L/usr/lib/gcc/i486-linux/3.4.1
-L/usr/lib/gcc/i486-linux/3.4.1 -L/usr/lib/gcc/i486-linux/3.4.1/../../..
unreachable-code1.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc
--as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i486-linux/3.4.1/crtend.o
/usr/lib/gcc/i486-linux/3.4.1/../../../crtn.o

-- 
           Summary: -O1 -Wunreachable-code incorrect warning
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: schallee at darkmist dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: 3.4.1
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16881


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