Bug 12603 - No return statement warning on function that never returns with -O3
Summary: No return statement warning on function that never returns with -O3
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3.1
: P3 minor
Target Milestone: ---
Assignee: Manuel López-Ibáñez
Keywords: diagnostic
: 30794 (view as bug list)
Depends on:
Reported: 2003-10-13 22:19 UTC by Jerry James
Modified: 2008-10-20 20:42 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail: 4.4.0
Last reconfirmed: 2008-08-29 13:28:06


Note You need to log in before you can comment on or make changes to this bug.
Description Jerry James 2003-10-13 22:19:16 UTC
The following function compiles without warning at optimization level -O2 or
below.  With -Wall -O3, gcc says:

noreturn.c: In function `this_function_never_returns':
noreturn.c:5: warning: no return statement in function returning non-void

This happens with gcc 3.2.2 - 3.3.1, at least.

this_function_never_returns ()
  for (;;);

This is an extremely stripped down version of a problem with XEmacs and
Fcommand_loop_1, which must be declared to return a Lisp_Object (since it is a
Lisp-visible function), but which contains an infinite loop.  The obvious
solution of putting a return statement at the end causes some compilers to
complain about unreachable code.  Adding __attribute__ ((noreturn)) did not make
the warning go away.
Comment 1 Andrew Pinski 2003-10-18 17:44:11 UTC
This should not warn at -O3, I think this is related to the control flow graph some how.
Comment 2 Kazu Hirata 2003-11-24 20:54:28 UTC
This problem does not seem to occur with gcc-3.4 20031124.
Comment 3 Andrew Pinski 2003-11-24 22:51:09 UTC
I can still reproduce it with the mainline (20031124).
Comment 4 Andrew Pinski 2004-03-06 05:48:57 UTC
The problem is that -O3, DECL_INLINE for the function decl becomes true because -O3 
enables -finline-functions.  So it looks like a different check is needed for the C front-end.
Comment 5 Zbynek Winkler 2004-05-02 15:36:59 UTC
I am also getting this warning about no return statement for methods in C++.
While a global function int noret() { for (;;); } does not fire the warning, the
same in a method does (3.2.3).
Comment 6 Andrew Pinski 2007-02-15 19:30:39 UTC
*** Bug 30794 has been marked as a duplicate of this bug. ***
Comment 7 Manuel López-Ibáñez 2008-08-29 13:28:06 UTC
No warning in GCC 4.4 with any of those:

-O0 -Wall -Wextra -Wreturn-type -Wunreachable-code
-O1 -Wall -Wextra -Wreturn-type -Wunreachable-code
-O2 -Wall -Wextra -Wreturn-type -Wunreachable-code
-O3 -Wall -Wextra -Wreturn-type -Wunreachable-code
-O3 -finline -Wall -Wextra -Wreturn-type -Wunreachable-code

If you can reproduce the problem in a recent GCC, let us know. I will add the testcase to the testsuite before closing this.
Comment 8 Manuel López-Ibáñez 2008-10-20 18:27:44 UTC
Subject: Bug 12603

Author: manu
Date: Mon Oct 20 18:26:21 2008
New Revision: 141244

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141244
2008-10-20  Manuel López-Ibáñez  <manu@gcc.gnu.org>
	PR 12603
	* gcc.dg/pr12603.c: New testcase.


Comment 9 Manuel López-Ibáñez 2008-10-20 18:28:40 UTC
This got fixed somehow. There is a testcase in the testsuite to make sure we do not regress.
Comment 10 Andrew Pinski 2008-10-20 20:42:43 UTC
(In reply to comment #9)
> This got fixed somehow. There is a testcase in the testsuite to make sure we do
> not regress.

This was most likely fixed by:
2008-09-17  Jan Hubicka  <jh@suse.cz>

        PR c++/18071
        * tree.h (DECL_INLINE): remove.
        (DECL_DECLARED_INLINE_P): Update docs.
        (DECL_NO_INLINE_WARNING_P): new.
        (tree_function_decl): Replace inline_flag by no_inline_warning_flag.
        * tree-inline.c (inlinable_function_p): Set DECL_NO_INLINE_WARNING_P.

Which removed DECL_INLINE.  As I mentioned in comment #4 DECL_INLINE was the issue.