7189 – [3.2 regression] gcc -O2 -Wall does not print ``control reaches end of non-void function'' warning (original) (raw)
| [gcc -O -Wall] reasonably prints a warning message complaining ``control reaches end of non-void function''. [gcc -O2 -Wall] should also print the same warning message. However, [gcc -O2 -Wall] silently succeeds. cd /tmp tar xfz gcc-3.1.tar.gz mkdir /tmp/build mkdir /tmp/experiment cd /tmp/build ../gcc-3.1/configure \ --prefix=/tmp/experiment \ --enable-languages=c make bootstrap make install cd /tmp echo "extern void foo(void);" > chk.c echo "int bar(void) { foo(); }" >> chk.c /tmp/experiment/bin/gcc -S -O -Wall chk.c --> "warning: control reaches end of ..." (correct behavior) /tmp/experiment/bin/gcc -S -O2 -Wall chk.c --> compilation silently succeeds (wrong behavior) Release: gcc version 3.1 Environment: i686-pc-linux-gnu How-To-Repeat: extern void foo(void); int bar(void) { foo(); } Comment 1 s.bosscher 2003-02-13 16:33:14 UTC From: Steven Bosscher <s.bosscher@student.tudelft.nl> To: gcc-gnats@gcc.gnu.org, am99173@konami.com, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org Cc: Subject: Re: optimization/7189: gcc -O2 -Wall does not print ``control reaches end of non-void function'' warning Date: 13 Feb 2003 16:33:14 +0100 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7189 This is a sibling call optimization bug. Without any optimization (gcc -c -Wall), the warning is issued as it should be. When sibling calls are optimized (gcc -c -Wall -foptimize-sibling-calls), the warning disappears. # cat c7129.c extern void foo(void); int bar(void) { foo(); } # gcc-3.4 -v Reading specs from /opt/experimental/lib/gcc-lib/i586-pc-linux-gnu/3.4/specs Configured with: ../gcc-trunk/configure --disable-nls --with-gnu-as --with-gnu-ld --prefix=/opt/experimental --program-suffix=-3.5 --enable-languages=c,c++ Thread model: posix gcc version 3.4 20030213 (experimental) # gcc-3.4 -c -Wall c7189.c c7189.c: In function `bar': c7189.c:2: warning: control reaches end of non-void function # gcc-3.4 -c -Wall c7189.c -foptimize-sibling-calls # Greetz Steven Comment 2 s.bosscher 2003-02-13 22:04:14 UTC From: Steven Bosscher <s.bosscher@student.tudelft.nl> To: gcc-gnats@gcc.gnu.org, am-99173@konami.com, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-prs@gcc.gnu.org Cc: rth@redhat.com Subject: Re: optimization/7189: gcc -O2 -Wall does not print ``control reaches end of non-void function'' warning Date: 13 Feb 2003 22:04:14 +0100 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7189 This is a bug that happens when sibcall optimizations are performed. It does not matter what other optimizations are enabled. When you do gcc -O0 -Wall -foptimize-sibling-calls, the warning about the non-void function not returning anything doesn't show up. The test case in the PR is: extern void foo(void); int bar(void) { foo(); } Without sibcall optimization, the warning is issued. The warning always shows up with gcc 2.95.3, so technically one could argue it's a regression... The problem seems to be that after the sibcall optimizations, the cfg cleanup after jump optimizations also cleans up the clobber INSN for the function result (output for -c -Wall -foptimize-sibling-calls, todays mainline CVS): --- c7189.c.01.sibling Thu Feb 13 16:52:05 2003 +++ c7189.c.03.jump Thu Feb 13 16:52:05 2003 @@ -1,14 +1,29 @@ --- pass specific dump info cut out --- @@ -27,19 +42,4 @@ (barrier 11 10 14) -(note 14 11 23 NOTE_INSN_FUNCTION_END) - -(note 23 14 18 1 [bb 1] NOTE_INSN_BASIC_BLOCK) - -(insn 18 23 19 1 (nil) (clobber (reg/i:SI 0 eax)) -1 (nil) - (nil)) - -(insn 19 18 17 1 (nil) (clobber (reg:SI 58 [ ])) -1 (nil) - (nil)) - -(insn 17 19 20 1 (nil) (set (reg/i:SI 0 eax) - (reg:SI 58 [ ])) -1 (nil) - (nil)) - -(insn 20 17 0 1 (nil) (use (reg/i:SI 0 eax)) -1 (nil) - (nil)) +(note 14 11 0 NOTE_INSN_FUNCTION_END) One way to "fix" this bug is to move check_function_return_warnings() up to before sibling call optimization in toplev.c, but maybe there's a more correct fix? Greetz Steven Comment 3 Eric Botcazou 2003-02-19 09:31:36 UTC State-Changed-From-To: open->analyzed State-Changed-Why: Already analyzed by Steven. Comment 4 Richard Henderson 2003-02-28 16:29:13 UTC From: Richard Henderson <rth@redhat.com> To: Steven Bosscher <s.bosscher@student.tudelft.nl> Cc: gcc-gnats@gcc.gnu.org, am-99173@konami.com, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-prs@gcc.gnu.org Subject: Re: optimization/7189: gcc -O2 -Wall does not print ``control reaches end of non-void function'' warning Date: Fri, 28 Feb 2003 16:29:13 -0800 On Thu, Feb 13, 2003 at 10:04:14PM +0100, Steven Bosscher wrote: > One way to "fix" this bug is to move check_function_return_warnings() up > to before sibling call optimization in toplev.c, but maybe there's a > more correct fix? I don't really like doing this earlier. To get correct results we'd have to do an extra DCE pass, which seems wasteful wrt compile-time for a warning. We should be able to detect this by looking at (1) predecessors of the EXIT block, (2) noticing that they end in a call_insn with SIBLING_CALL_P set, and (3) noticing that the return value embedded in the call_insn is correct for the return value of the function. r~ Comment 6 s.bosscher 2003-03-01 23:55:33 UTC From: Steven Bosscher <s.bosscher@student.tudelft.nl> To: Richard Henderson <rth@redhat.com> Cc: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-patches@gcc.gnu.org, nobody@gcc.gnu.org Subject: Re: optimization/7189: gcc -O2 -Wall does not print ``control reaches end of non-void function'' warning Date: 01 Mar 2003 23:55:33 +0100 Op za 01-03-2003, om 01:30 schreef Richard Henderson: > On Thu, Feb 13, 2003 at 10:04:14PM +0100, Steven Bosscher wrote: > > One way to "fix" this bug is to move check_function_return_warnings() up > > to before sibling call optimization in toplev.c, but maybe there's a > > more correct fix? > > I take that back. Moving this to just after > delete_unreachable_blocks should be just fine. I just bootstrapped all except Ada and treelang with the attached patch, regtesting now. OK for mainline and 3.3 if it passes? Greetz Steven 2003-03-01 Steven Bosscher <s.bosscher@student.tudelft.nl> PR optimization/7189 * toplev.c (rest_of_compilation): Move check_function_return_warnings up to just after delete_unreachable_blocks. Index: toplev.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/toplev.c,v retrieving revision 1.725 diff -c -3 -p -r1.725 toplev.c *** toplev.c 1 Mar 2003 01:21:22 -0000 1.725 --- toplev.c 1 Mar 2003 22:43:44 -0000 *************** rest_of_compilation (decl) *** 2625,2630 **** --- 2625,2634 ---- delete_unreachable_blocks (); + /* We have to issue these warnings now already, because CFG cleanups + further down may destroy the required information. */ + check_function_return_warnings (); + /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */ if (flag_guess_branch_prob) { *************** rest_of_compilation (decl) *** 3179,3186 **** open_dump_file (DFI_life, decl); regclass_init (); - - check_function_return_warnings (); #ifdef ENABLE_CHECKING verify_flow_info (); --- 3183,3188 ---- Comment 10 Steven Bosscher 2003-03-11 20:09:11 UTC Responsible-Changed-From-To: unassigned->steven Responsible-Changed-Why: Already fixed on mainline with my patch. Waiting for approval for 3.3. Will have to backport to 3.2 too... Comment 12 Joe Buck 2003-04-25 21:16:58 UTC State-Changed-From-To: analyzed->closed State-Changed-Why: Fixed for 3.3. | | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |