Bug 11370

Summary: [3.3 Regression] -Wunreachable-code gives false complaints
Product: gcc Reporter: Debian GCC Maintainers <debian-gcc>
Component: otherAssignee: roger
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, sayle
Priority: P2 Keywords: diagnostic
Version: 3.3   
Target Milestone: 3.3.2   
Host: i386-linux Target: i386-linux
Build: i386-linux Known to work:
Known to fail: Last reconfirmed: 2003-06-29 13:39:29

Description Debian GCC Maintainers 2003-06-29 10:57:51 UTC
[forwarded from http://bugs.debian.org/196600]

rechecked with HEAD.

  Gcc complains that a declaration "will never be executed" for a
code path that executes, as shown below.
If I:
 . remove the exit line
 . change "int ix;" to "int ix = 0;"
or
 . move the declaration to line 2 or after line 3
the complaint go away.

$ cat -n test.c
#include <stdio.h>

int main(int argc, char *argv[]) { /* line 3 */
  if (argc != 1) exit(1);

  {
    int ix;                     /* line 7 */
    ix = printf("hello\n");
    printf("%d\n", ix);
  }

  return 0;
}

$ gcc-3.3 -Wunreachable-code test.c; ./a.out 
test.c: In function `main':
test.c:7: warning: will never be executed
hello
6
Comment 1 Andrew Pinski 2003-06-29 13:39:29 UTC
I can confirm this bug on the mainline (20030629) and in 3.3.1 (20030616).  I also 
happens in 3.2.2 and 3.2.3 but does not in 3.0.4 (2.95.3 does not have the option), so this 
is a regression.
Note this only happens with -march=i386 (with -march=i686 the warning does not 
happen).
Comment 2 Andrew Pinski 2003-07-06 14:32:16 UTC
*** Bug 11445 has been marked as a duplicate of this bug. ***
Comment 3 GCC Commits 2003-07-09 01:17:34 UTC
Subject: Bug 11370

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sayle@gcc.gnu.org	2003-07-09 01:17:28

Modified files:
	gcc            : ChangeLog calls.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: Wunreachable-6.c Wunreachable-7.c 

Log message:
	PR c/11370
	* calls.c (emit_call_1): Don't bother popping the arguments off of
	the stack after a noreturn function call;  The adjustment is dead.
	(expand_call): Likewise.
	
	* gcc.dg/Wunreachable-6.c: New testcase.
	* gcc.dg/Wunreachable-7.c: New testcase.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.412&r2=2.413
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/calls.c.diff?cvsroot=gcc&r1=1.284&r2=1.285
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2852&r2=1.2853
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/Wunreachable-6.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/Wunreachable-7.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 Steven Bosscher 2003-07-10 20:58:23 UTC
Roger, does this bug still need fixing somewhere or should it be closed?
Comment 5 Andrew Pinski 2003-07-11 14:59:54 UTC
This is a 3.3 regression only now. It has been fixed on the mainline.
Comment 6 Mark Mitchell 2003-07-11 22:50:26 UTC
Postponed until GCC 3.3.2.
Comment 7 GCC Commits 2003-08-09 03:50:08 UTC
Subject: Bug 11370

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	sayle@gcc.gnu.org	2003-08-09 03:50:05

Modified files:
	gcc            : ChangeLog calls.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: Wunreachable-6.c Wunreachable-7.c 

Log message:
	PR c/11370
	* calls.c (emit_call_1): Don't bother popping the arguments off of
	the stack after a noreturn function call;  The adjustment is dead.
	(expand_call): Likewise.
	
	* gcc.dg/Wunreachable-6.c: New testcase.
	* gcc.dg/Wunreachable-7.c: New testcase.

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.699&r2=1.16114.2.700
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.9&r2=1.244.2.10
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.249&r2=1.2261.2.250
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/Wunreachable-6.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.10.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/Wunreachable-7.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.10.1

Comment 8 Andrew Pinski 2003-08-09 03:57:43 UTC
Fixed for 3.3.2.