Bug 9862 - [3.3/3.4 regression] spurious warnings with -W -finline-functions
Summary: [3.3/3.4 regression] spurious warnings with -W -finline-functions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3
: P1 minor
Target Milestone: 3.3.2
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2003-02-26 13:56 UTC by danielv
Modified: 2004-01-17 04:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-05-28 23:37:44


Attachments
Patch for Bug 9862 (1.02 KB, patch)
2003-07-27 10:33 UTC, Steven Bosscher
Details | Diff
test cases (399 bytes, application/gzip)
2003-07-27 10:34 UTC, Steven Bosscher
Details

Note You need to log in before you can comment on or make changes to this bug.
Description danielv 2003-02-26 13:56:00 UTC
  In the file <file.c> given below, the <trigger> function might return
  with or without a value.

  If compiling with -ansi -Wall -W -O3, the compiler warns about this,
  but also warns about the function <f> having the same problem,
  which is not the case.

<file.c>
extern int i;
extern int f(void);
extern int trigger(void);

int f(void)
{
  if( i ) return 0;
  else    return 1;
}

int trigger(void)
{
  if( i ) return;
  else    return 1;
}
</file.c>

Release:
3.2.2

Environment:
System: SunOS neuchatel 5.8 Generic_108528-17 sun4u sparc SUNW,Sun-Blade-100
Architecture: sun4

	
host: sparc-sun-solaris2.7
build: sparc-sun-solaris2.7
target: sparc-sun-solaris2.7
configured with: ./configure --prefix=/misc/ultra-sun-solaris2/gcc-3.2.2 --enable-threads=posix --disable-shared --disable-multilib

How-To-Repeat:
     gcc -ansi -Wall -W -O3 -c file.c
Comment 1 danielv 2003-02-26 13:56:00 UTC
Fix:

NOTE: This e-mail and any file attached therewith is intended only for the named recipient(s) above and contains information that is  confidential and may be legally privileged and/or exempt from disclosure under applicable law.  If you have received this message in error, or are not the named recipient(s), please immediately notify the sender and delete this e-mail message.
 
NOTE: Ce courriel ainsi que tout fichier d'accompagnement est destiné à l'usage exclusif du destinataire(s) mentionné(s) ci-dessus et peut contenir de l'information confidentielle, privilegiée et/ou dispensée de divulgation aux termes des lois applicables.  Si vous avez reçu ce message par erreur, ou s'il ne vous est pas destiné, veuillez le mentionner immédiatement à l'expéditeur et effacer ce courriel.
Comment 2 Wolfgang Bangerth 2003-02-26 17:31:46 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed. -O3 is actually needed.
Comment 3 Wolfgang Bangerth 2003-05-28 23:37:44 UTC
It's actually a regression:

g/x> gcc -c test.c -O3 -ansi -Wall -W
test.c: In function `trigger':
test.c:13: warning: `return' with no value, in function returning non-void
test.c:15: warning: this function may return with or without a value


g/x> /home/bangerth/bin/gcc-3.4-pre/bin/gcc -c test.c -O3 -ansi -Wall -W
test.c: In function `trigger':
test.c:13: warning: `return' with no value, in function returning non-void
test.c: In function `f':
test.c:9: warning: this function may return with or without a value
test.c: In function `trigger':
test.c:15: warning: this function may return with or without a value
Comment 4 Steven Bosscher 2003-07-11 23:44:55 UTC
Wolfgang, is this one really target-specific?  I'd be surprised...
Comment 5 Dara Hazeghi 2003-07-11 23:57:27 UTC
Nope. Confirmed as not target-specific (20030710). Happily reproduced on i686-linux.
Comment 6 Wolfgang Bangerth 2003-07-12 22:50:31 UTC
Steven:
I only have x86 to check, so can't say whether something is target-specific :-)
Why do you think I suggested it was?

W.
Comment 7 s.bosscher 2003-07-12 23:02:34 UTC
Subject: RE:  [3.3/3.4 regression] spurious warnings with -W -	O3

> Why do you think I suggested it was?

I did not :-)

Can you assign it to me, I'll see if i can find out what is going on here (I
suspect I know what is causing this).


Comment 8 Steven Bosscher 2003-07-13 00:00:56 UTC
This PR is a result of defering functions.  The problem is that in c-decl we
assume that two global variables, current_function_retunrs_value and
current_function_returns_null, are reset for the current function, which is not
true if the function we're expanding is not the function we just parsed.  So for
this test case:

extern int i;
 
static int f(void) {
  if( i ) return 0; else return 1;
}
 
static int trigger(void) {
  if( i ) return; else return 1;
}

the current_function_returns_{value, null} variables have the values they should
have for "trigger" when we expand "f", and we get the warning:

if (extra_warnings
      && current_function_returns_value
      && current_function_returns_null)
    warning ("this function may return with or without a value");

If the two functions in the test case are switched (trigger before f) we get no
warnings at all.

With the rtl inliner we always expanded and then deferred.  With the tree
inliner this is not the case.

To check, I tried GCC 3.2 and indeed it shows the same bug.  Contrary to the
comments in the audit trail, -O3 is not necessary.  Just -O -finline-functions
will trigger the same problem.

I'll work on a fix for this.
Comment 9 Steven Bosscher 2003-07-13 11:53:57 UTC
Patch pending in "http://gcc.gnu.org/ml/gcc-patches/2003-07/msg01286.html"
Comment 10 Andrew Pinski 2003-07-13 20:01:31 UTC
Moving target to 3.3.2 based on email from Mark which states he is accepting only fixes 
for ice-on-valid-code and wrong-code patches for 3.3.1 now <http://gcc.gnu.org/ml/gcc-
patches/2003-07/msg01319.html>.
Comment 11 Steven Bosscher 2003-07-27 10:33:14 UTC
Created attachment 4489 [details]
Patch for Bug 9862
Comment 12 Steven Bosscher 2003-07-27 10:34:53 UTC
Created attachment 4490 [details]
test cases
Comment 13 CVS Commits 2003-09-06 13:34:03 UTC
Subject: Bug 9862

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	steven@gcc.gnu.org	2003-09-06 13:34:00

Modified files:
	gcc            : ChangeLog c-decl.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: 20030906-1.c 20030906-2.c 

Log message:
	PR c/9862
	* c-decl.c (c_expand_body_1): Move return warning from here...
	(finish_function): ...to here.
	
	* gcc.dg/20030906-1.c: New test.
	* gcc.dg/20030906-2.c: Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.984&r2=2.985
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.442&r2=1.443
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3028&r2=1.3029
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20030906-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20030906-2.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 14 CVS Commits 2003-09-06 14:44:37 UTC
Subject: Bug 9862

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	steven@gcc.gnu.org	2003-09-06 14:44:34

Modified files:
	gcc            : c-decl.c ChangeLog 

Log message:
	PR c/9862
	* c-decl.c (c_expand_body): Move return warning from here...
	(finish_function): ...to here

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.356.2.13&r2=1.356.2.14
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.723&r2=1.16114.2.724

Comment 15 Steven Bosscher 2003-09-06 14:45:06 UTC
Fixed