Bug 13000 - [3.4 Regression] [unit-at-a-time] Using -O2 cannot detect missing return statement in a function
[3.4 Regression] [unit-at-a-time] Using -O2 cannot detect missing return stat...
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: tree-optimization
3.4.0
: P2 minor
: 4.0.0
Assigned To: Not yet assigned to anyone
: diagnostic
: 18588 (view as bug list)
Depends on:
Blocks: 13127
  Show dependency treegraph
 
Reported: 2003-11-10 23:07 UTC by cheng
Modified: 2006-02-28 08:49 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3 4.0.0
Known to fail: 3.4.0
Last reconfirmed: 2006-01-06 15:23:21


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cheng 2003-11-10 23:07:05 UTC
In the following contrived code snippet, gcc 2.953 will not complain about the 
function not returning a value despite its function signature says so when 
compiling with optimizations enabled (e.g. -O1 or -O2).  Disabling 
optimizations with -O0 will enable the compiler to display an appropriate error 
message.  This problem appears in both C and C++ test code.


typedef int ui32;

static ui32 AddPrimitiveDvrResource(ui32 hSession, ui32 *pSessNode,
									
	void *pvResourceDescriptor, ui32 dwSize);

static ui32 AddPrimitiveDvrResource(ui32 hSession, ui32 *pSessNode,
									
	void *pvResourceDescriptor, ui32 dwSize)
{
	ui32 rc;

	if (dwSize != 32)
	{
		rc = 0;
	}
	else
	{
		// set the DVR ID in the session node even if subsequent steps 
fail
		
		if (dwSize) 
		{
			rc = dwSize;
		}
		else
		{
			if (!pSessNode)
			{
				rc = 2;
			}
			else
			{
				ui32 dwTranscryptorAvrID = 0;
	
				if (rc = dwTranscryptorAvrID)
				{
					dwTranscryptorAvrID;
				}
				else
				{
					ui32 dk;

					if (rc = 16)
					{
						dk = rc;
					}
					else
					{
						if (dk) 
						{
							rc = 1;
						}
						else
						{
							rc = 0;
						}
					}
				}
			}
		}
	}
}

int main(int argc, char **argv)
{
	int result = AddPrimitiveDvrResource(0,0,0,0);

	return 0;
}
Comment 1 Andrew Pinski 2003-11-10 23:13:50 UTC
Been fixed since at least 3.1.
Comment 2 falk.hueffner 2003-11-10 23:29:17 UTC
Subject: Re:  Using -Ox cannot detect missing return statement in a function

"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

> ------- Additional Comments From pinskia at gcc dot gnu dot org  2003-11-10 23:13 -------
> Been fixed since at least 3.1.

Seems to be back in tree-ssa though (warning at -O0, -O1 and -O3, but
not at -O2, weird).  Unfortunately, I don't have a mainline compiler
to check right now.

Comment 3 Andrew Pinski 2003-11-10 23:36:04 UTC
Reopening based on Falk's tree-ssa problem.
Comment 4 Andrew Pinski 2003-12-01 04:34:28 UTC
I can also reproduce this on the mainline (20031119).
Comment 5 Andrew Pinski 2003-12-25 00:10:10 UTC
From Phil's regression hunter:
: Search converges between 2003-09-04-trunk (#391) and 2003-09-05-trunk (#392).
Before that GCC gave at -O2:
input.c: In function `AddPrimitiveDvrResource':
input.c:41: warning: statement with no effect
input.c:10: warning: unused parameter 'hSession'
input.c:12: warning: unused parameter 'pvResourceDescriptor'
Comment 6 Andrew Pinski 2003-12-25 00:22:05 UTC
It also works with -fno-unit-at-a-time or with -O3.
Jan could look into what causes this?
Comment 7 Jan Hubicka 2003-12-25 16:05:07 UTC
Subject: Re:  [3.4 Regression] [unit-at-a-time] Using -O2 cannot detect missing return statement in a function

> 
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-25 00:22 -------
> It also works with -fno-unit-at-a-time or with -O3.
> Jan could look into what causes this?

This is caused by a fact that we either fully inline or decide to not
compile function at all.  Because the warning come from the brackend, we
never notice it.  This is kind of problem we had all the time, just it
is more common now.  I hope to do something about it in a tree-ssa
branch.

Honza
> 
> -- 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>          AssignedTo|unassigned at gcc dot gnu   |hubicka at gcc dot gnu dot
>                    |dot org                     |org
>              Status|NEW                         |ASSIGNED
>             Summary|[3.4 Regression] Using -O2  |[3.4 Regression] [unit-at-a-
>                    |cannot detect missing return|time] Using -O2 cannot
>                    |statement in a function     |detect missing return
>                    |                            |statement in a function
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13000
> 
> ------- You are receiving this mail because: -------
> You are the assignee for the bug, or are watching the assignee.
Comment 8 Jan Hubicka 2004-01-03 21:21:09 UTC
Needs the analysis done before inlining
Comment 9 Richard Henderson 2004-08-18 07:35:49 UTC
Looking at it.
Comment 10 Andrew Pinski 2004-11-21 14:10:27 UTC
*** Bug 18588 has been marked as a duplicate of this bug. ***
Comment 11 Andrew Pinski 2005-01-18 00:39:55 UTC
Hmm, This seems like a place where the tree-profiling branch can come in handing as we always 
produce the CFG for all functions even the ones which we inline and don't emit.
Comment 12 Ian Lance Taylor 2005-01-19 15:51:30 UTC
Proposed patch: http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01223.html
Comment 13 Ian Lance Taylor 2005-01-21 02:52:28 UTC
Updated patch: http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01443.html
Comment 14 CVS Commits 2005-01-21 19:05:44 UTC
Subject: Bug 13000

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ian@gcc.gnu.org	2005-01-21 19:05:25

Modified files:
	gcc            : ChangeLog tree-inline.c tree-cfg.c gimple-low.c 
	                 gimplify.c c-typeck.c 

Log message:
	PR tree-optimization/13000
	* tree-inline.c: Include "tree-flow.h".
	(expand_call_inline): If warn_return_type, warn if non-void inline
	function falls through.
	* tree-cfg.c (execute_warn_function_return): Don't warn about
	control reaching end if TREE_NO_WARNING is set.  Set
	TREE_NO_WARNING.
	* gimple-low.c (block_may_fallthru): Don't assume that SWITCH_EXPR
	has been lowered.
	* gimplify.c (shortcut_cond_expr): Don't emit a jump over the else
	branch if we don't need one.
	* c-typeck.c: Include "tree-flow.h"
	(c_finish_bc_stmt): Don't add a goto if the current statement
	list doesn't fall through to the current point.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7221&r2=2.7222
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-inline.c.diff?cvsroot=gcc&r1=1.166&r2=1.167
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-cfg.c.diff?cvsroot=gcc&r1=2.144&r2=2.145
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimple-low.c.diff?cvsroot=gcc&r1=2.17&r2=2.18
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimplify.c.diff?cvsroot=gcc&r1=2.104&r2=2.105
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.411&r2=1.412

Comment 15 CVS Commits 2005-01-21 19:06:07 UTC
Subject: Bug 13000

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ian@gcc.gnu.org	2005-01-21 19:05:54

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg: 20040206-1.c 

Log message:
	PR tree-optimization/13000
	* gcc.dg/20040206-1.c: Change warning to point where function is
	being inlined.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4917&r2=1.4918
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20040206-1.c.diff?cvsroot=gcc&r1=1.4&r2=1.5

Comment 16 Ian Lance Taylor 2005-01-21 19:07:18 UTC
Fixed on mainline.
Comment 17 Ian Lance Taylor 2005-01-21 19:14:23 UTC
Note that if we do move to a better solution, i.e., building a CFG for inline
functions, we should remove the patch to c_finish_bc_stmt in c-typeck.c.  It
prevents -Wunreachable from ever warning about an unreachable break or continue
statement (we currently do not issue a warning about those statements anyhow).

We may want to consider removing the patch to shortcut_cond_expr in gimplify.c,
although that one is relatively harmless.

And of course if we build a CFG, we should adjust the patch to
expand_call_inline, although that will probably be pretty obvious.

See the e-mail thread starting here:
    http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01223.html
Comment 18 Richard Henderson 2005-01-27 01:58:37 UTC
I am uninterested in fixing this for 3.4.
Comment 19 Giovanni Bajo 2005-04-12 17:35:22 UTC
Since this bug was fixed in 4.1, I'm removing the dependencies with the 4.1 
metabug.
Comment 20 Ian Lance Taylor 2005-04-12 18:49:17 UTC
The dependency on 17652 is there because of comment #17, q.v.  We want to make
sure that we back out the patch to c_finish_bc_stmt when it is no longer needed,
which should happen after the tree-profiling branch is merged to mainline.  So
I'm re-adding the dependency.  If you still think this is wrong, go ahead and
take it out.
Comment 21 Andrew Pinski 2005-09-05 15:48:38 UTC
(In reply to comment #20)
> The dependency on 17652 is there because of comment #17, q.v.  We want to make
> sure that we back out the patch to c_finish_bc_stmt when it is no longer needed,
> which should happen after the tree-profiling branch is merged to mainline.  So
> I'm re-adding the dependency.  If you still think this is wrong, go ahead and
> take it out.

Removing dependent on 13127 because the patch to c_finish_bc_stmt still speeds up the compiling as 
we don't need to generate as many BBs with it as we would without it.
Comment 22 Gabriel Dos Reis 2006-02-28 08:49:46 UTC
No interest in fixing for 3.4.6.