Options given when GCC was configured/built: I configured gcc 3.3.1 with no options; just invoked it as ./configure. Command line that triggers the bug: g++ -v --save-temps -Wunreachable-code -O3 preprocessModifiedFiles.C -o preprocessModifiedFiles Compiler output: g++ -v --save-temps -Wunreachable-code -O3 preprocessModifiedFiles.C -o preprocessModifiedFiles Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs Configured with: ./configure --cache-file=config.cache Thread model: posix gcc version 3.3.1 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/cc1plus -E -D__GNUG__=3 -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=1 -D_GNU_SOURCE preprocessModifiedFiles.C -Wunreachable-code -O3 preprocessModifiedFiles.ii ignoring nonexistent directory "NONE/include" ignoring nonexistent directory "/usr/local/i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include/c++/3.3.1 /usr/local/include/c++/3.3.1/i686-pc-linux-gnu /usr/local/include/c++/3.3.1/backward /usr/local/include /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/include /usr/include End of search list. /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/cc1plus -fpreprocessed preprocessModifiedFiles.ii -quiet -dumpbase preprocessModifiedFiles.C -auxbase preprocessModifiedFiles -O3 -Wunreachable-code -version -o preprocessModifiedFiles.s GNU C++ version 3.3.1 (i686-pc-linux-gnu) compiled by GNU C version 3.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 preprocessModifiedFiles.C: In function `int main(int, char**)': preprocessModifiedFiles.C:1147: warning: will never be executed preprocessModifiedFiles.C:1147: warning: will never be executed preprocessModifiedFiles.C:1147: warning: will never be executed preprocessModifiedFiles.C: In function `int preprocess(const char*, const char*)': preprocessModifiedFiles.C:773: warning: will never be executed preprocessModifiedFiles.C:753: warning: will never be executed preprocessModifiedFiles.C:732: warning: will never be executed preprocessModifiedFiles.C:747: warning: will never be executed preprocessModifiedFiles.C:631: warning: will never be executed preprocessModifiedFiles.C:631: warning: will never be executed preprocessModifiedFiles.C:629: warning: will never be executed /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/../../../../i686-pc-linux-gnu/bin/as -V -Qy -o preprocessModifiedFiles.o preprocessModifiedFiles.s GNU assembler version 2.14 (i686-pc-linux-gnu) using BFD version 2.14 20030612 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o preprocessModifiedFiles /usr/lib/crt1.o /usr/lib/crti.o /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/crtbegin.o -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1 -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/../../../../i686-pc-linux-gnu/lib -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/../../.. preprocessModifiedFiles.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/crtend.o /usr/lib/crtn.o I will attach the compressed preprocessed file preprocessModifiedFiles.ii after I've submitted this report to Bugzilla; don't see how to do so upon bug creation. Why I think this is a bug: I believe the "will never be executed" warnings are incorrect. Additional details: I am running on an IBM Netvista type 6792-MHU computer, under a Red Hat 7.3 GNU/Linux distribution. Linux kernel 2.40.20, 1536MB of RAM, 1GB of swap space. Pentium 4 (1.80 GHz processor). Please let me know if I can provide you with additional information. I compiled GCC myself from the 3.3.1 tarball, using gcc 2.96. The build and install completed normally. Before I compiled gcc, I compiled and installed binutils 2.14: Bash$ gcc --version gcc (GCC) 3.3.1 [...] Bash$ as --version GNU assembler 2.14 20030612 [...] I have tried to trim down the program text I'm appending, but the really short versions don't show the warning. Sincerely Yours, --Steven Augart Jikes RVM Open Source Java Compiler Project http://www.ibm.com/developerworks/oss/jikesrvm/
Created attachment 4666 [details] preprocessModifiedFiles.ii.bz2 This is the preprocessor output, compressed with "bzip2 -9"
I can confirm this, the warnings are clearly bogus. Slightly changing the code makes the locations of the problem go away or move randomly. It takes someone with some more time than me right now to reduce this, though. One of the things that startle me is that it reports warnings in functions with the wrong name (i.e. it says the problem is in function "main", but the given line number is in another function). Maybe this has something to do with inlining then. W.
I have found a smaller test case that shows the bug (down to 36 lines including 7 blank lines). I am attaching "bad1.i", a preprocessed C file that triggers the warning. Here is the output from compiling bad1.i with gcc 3.3.1: bilbo:~/JikesRVM/gccbug > cc --save-temps -v -Wunreachable-code -O3 -o bad1.S -S bad1.i Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs Configured with: ./configure --cache-file=config.cache Thread model: posix gcc version 3.3.1 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/cc1 -fpreprocessed bad1.i -quiet -dumpbase bad1.i -auxbase-strip bad1.S -O3 -Wunreachable-code -version -o bad1.S GNU C version 3.3.1 (i686-pc-linux-gnu) compiled by GNU C version 3.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 bad1.c: In function `main': bad1.c:13: warning: will never be executed bilbo:~/JikesRVM/gccbug > The bug does not appear when I compile the very similar source file good1.c: bilbo:~/JikesRVM/gccbug > cc --save-temps -v -Wunreachable-code -O3 -o good1.S -S good1.i Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs Configured with: ./configure --cache-file=config.cache Thread model: posix gcc version 3.3.1 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/cc1 -fpreprocessed good1.i -quiet -dumpbase good1.i -auxbase-strip good1.S -O3 -Wunreachable-code -version -o good1.S GNU C version 3.3.1 (i686-pc-linux-gnu) compiled by GNU C version 3.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 bilbo:~/JikesRVM/gccbug > Nor does it appear when I compile good2.i, which is bad1.i without the for loop: bilbo:~/JikesRVM/gccbug > cc --save-temps -v -Wunreachable-code -O3 -o good2.S -S good2.i Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs Configured with: ./configure --cache-file=config.cache Thread model: posix gcc version 3.3.1 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/cc1 -fpreprocessed good2.i -quiet -dumpbase good2.i -auxbase-strip good2.S -O3 -Wunreachable-code -version -o good2.S GNU C version 3.3.1 (i686-pc-linux-gnu) compiled by GNU C version 3.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 bilbo:~/JikesRVM/gccbug >
Created attachment 4673 [details] bad1.i: preprocessed C that triggers the problem. preprocessed C that triggers the problem. Here is the output from compiling bad1.i with gcc 3.3.1: bilbo:~/JikesRVM/gccbug > cc --save-temps -v -Wunreachable-code -O3 -o bad1.S -S bad1.i Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs Configured with: ./configure --cache-file=config.cache Thread model: posix gcc version 3.3.1 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/cc1 -fpreprocessed bad1.i -quiet -dumpbase bad1.i -auxbase-strip bad1.S -O3 -Wunreachable-code -version -o bad1.S GNU C version 3.3.1 (i686-pc-linux-gnu) compiled by GNU C version 3.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 bad1.c: In function `main': bad1.c:13: warning: will never be executed bilbo:~/JikesRVM/gccbug >
Created attachment 4674 [details] good1.i, one-line change that makes the problem go away good1.i, one-line change that makes the problem go away bilbo:~/JikesRVM/gccbug > cc --save-temps -v -Wunreachable-code -O3 -o good1.S -S good1.i Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs Configured with: ./configure --cache-file=config.cache Thread model: posix gcc version 3.3.1 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/cc1 -fpreprocessed good1.i -quiet -dumpbase good1.i -auxbase-strip good1.S -O3 -Wunreachable-code -version -o good1.S GNU C version 3.3.1 (i686-pc-linux-gnu) compiled by GNU C version 3.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 bilbo:~/JikesRVM/gccbug >
Created attachment 4675 [details] good2.i, preprocessed C source that doesn't show the problem. The bug doesn't appear when I compile good2.i, which is bad1.i without the for loop: bilbo:~/JikesRVM/gccbug > cc --save-temps -v -Wunreachable-code -O3 -o good2.S -S good2.i Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs Configured with: ./configure --cache-file=config.cache Thread model: posix gcc version 3.3.1 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/cc1 -fpreprocessed good2.i -quiet -dumpbase good2.i -auxbase-strip good2.S -O3 -Wunreachable-code -version -o good2.S GNU C version 3.3.1 (i686-pc-linux-gnu) compiled by GNU C version 3.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 bilbo:~/JikesRVM/gccbug > bilbo:~/JikesRVM/gccbug >
bad1.c is a nice example, but you didn't go all the way :-) Here's something even smaller: ------------------------------------------- int g(); void f (int i) { for (; g();) if (g()) { ++i; break; } } ------------------------------------ tmp/g> ~/bin/gcc-3.3/bin/gcc -Wunreachable-code -O3 -c x.c x.c: In function `f': x.c:5: warning: will never be executed That's clearly bogus. The same happens with present mainline, with an additional twist: there's an empty line sneaking into the message: tmp/g> ../build-gcc/gcc-install/bin/gcc -Wunreachable-code -O3 -c x.c x.c: In function `f': x.c:5: warning: will never be executed Thanks fro reducing your testcase! W.
Forgot to say this -- it's a regression in 3.3 and mailine w.r.t. 3.2. W.
Created attachment 4676 [details] testcase (11 lines) The warning appears with this testcase (11 lines of preprocessed C). bilbo:~/JikesRVM/gccbug > gcc -O3 -Wunreachable-code -v --save-temps bad2.i -S -o bad2.S Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs Configured with: ./configure --cache-file=config.cache Thread model: posix gcc version 3.3.1 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/cc1 -fpreprocessed bad2.i -quiet -dumpbase bad2.i -auxbase-strip bad2.S -O3 -Wunreachable-code -version -o bad2.S GNU C version 3.3.1 (i686-pc-linux-gnu) compiled by GNU C version 3.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 bad2.i: In function `main': bad2.i:6: warning: will never be executed bilbo:~/JikesRVM/gccbug >
Wolfgang Bangerth's test case in Comment #7 is superior to any of the attached ones that I wrote. (I added comment #9 unaware that Wolfgang had added #7 and #8).
The regression in PR 12082 was introduced or exposed by this patch: --- gcc/gcc/ChangeLog --- Don Feb 28 11:07:36 CET 2002 Jan Hubicka <jh@suse.cz> * basic-block.h (BB_REACHABLE): Renumber. (BB_DIRTY, BB_NEW): New flags. (clear_bb_flags): Declare. (update_life_info_in_dirty_blocks): Declare. * cfg.c (clear_bb_flags): New function. * cfgrtl.c (create_basic_block_structure): Set flags to BB_NEW. * emit-rtl.c (add_insn_after, add_insn_before, remove_insn, reorder_insns, emit_insn_after): Mark block as dirty. * flow.c (update_life_info): Fix clearing of PROP_LOG_LINKS. (update_life_info_in_dirty_blocks): New function. * recog.c (apply_change_group): Dirtify block. * cse.c (cse_insn): Reorder emitting of jump insn to keep cfg consistent. * gcse.c (delete_null_pointer_checks): Likewise. * toplev.c (dump_file_index): Move cse2 after bp, add DFI_null (dump_file_info): Similary. (rest_of_compilation): Avoid most of CFG rebuilds; do first if converision after null pointer checks, do cse2 after branch prediction; avoid full liveness rebuild after initializing subregs. * invoke.texi (-d options): Document -du, renumber. * cfgcleanup.c (bb_flags): Remove BB_UPDATE_LIFE. (notice_new_block): Do not set BB_UPDATE_LIFE. (try_forward_edges, merge_blocks_move_predecessor_nojumps, merge_blocks_move_successor_nojumps, merge_blocks, try_crossjump_to_edge): Likewise. (try_optimize_cfg): Likewise; use update_life_info_in_dirty_blocks. * cfgrtl.c (merge_blocks_nomove): Copy b's flags to a. * ifcvt.c (SET_UPDATE_LIFE, UPDATE_LIFE): Kill. (merge_of_block): Do not use life_data_ok. (find_if_case_1): Do not use SET_UPDATE_LIFE. (if_convert): Use BB_DIRTY mechanizm to update life. * lcm.c (optimize_mode_switching): Update update_life_info_in_dirty_blocks The regression hunt took place on i686-pc-linux-gnu using Wolfgang's small test case from comment #7 compiled with "-O3 -Wunreachable-code".
Subject: Bug 12082 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: hubicka@gcc.gnu.org 2003-09-06 21:26:52 Modified files: gcc : ChangeLog calls.c cfgcleanup.c Log message: PR target/12070 * calls.c (emit_library_call_value_1): Fix saving of BLKmode arguments. PR opt/12082 * cfgcleanup.c (try_simplify_condjump): Avoid unreachable code warning. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.724&r2=1.16114.2.725 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/calls.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.244.2.10&r2=1.244.2.11 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cfgcleanup.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.68.2.5&r2=1.68.2.6
Subject: Bug 12082 CVSROOT: /cvs/gcc Module name: gcc Changes by: hubicka@gcc.gnu.org 2003-09-06 21:50:22 Modified files: gcc : ChangeLog calls.c cfgcleanup.c Log message: PR target/12070 * calls.c (emit_library_call_value_1): Fix saving of BLKmode arguments. PR opt/12082 * cfgcleanup.c (try_simplify_condjump): Avoid unreachable code warning. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.988&r2=2.989 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/calls.c.diff?cvsroot=gcc&r1=1.297&r2=1.298 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cfgcleanup.c.diff?cvsroot=gcc&r1=1.91&r2=1.92
Fixed by the patch above for 3.3.2 and 3.4.