Bug 10175 - -Wunreachable-code doesn't work for single lines
Summary: -Wunreachable-code doesn't work for single lines
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-21 00:36 UTC by bobsummerwill
Modified: 2003-07-25 17:33 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Unreachable.ii (143 bytes, text/x-c++)
2003-05-21 15:17 UTC, bobsummerwill
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bobsummerwill 2003-03-21 00:36:00 UTC
The -Wunreachable-code warning doesn't appear to work correctly for single-statement blocks.  I've replicate this behaviour on MinGW, Cygwin, and a colleague has verified it against the CVS head revision on Linux.

Release:
gcc version 3.2 (mingw special 20020817-1)

Environment:
MinGW

How-To-Repeat:
Just compile the attached .ii file using MinGW-2.0.0.3, like so:

D:\>gcc -v
Reading specs from D:/FIFA/packages/MinGW/2.0.0.3/bin/../lib/gcc-lib/mingw32/3.2
/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=
mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable
-languages=f77,c++,objc,ada --disable-win32-registry --disable-shared
Thread model: win32
gcc version 3.2 (mingw special 20020817-1)

D:\>gcc -Wunreachable-code Unreachable.ii
Unreachable.cpp: In function `int main()':
Unreachable.cpp:12: warning: will never be executed

A warning is only issued for one the three unreachable statements.
Comment 1 Wolfgang Bangerth 2003-03-21 01:35:59 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed, the warning is only displayed for the
    multi-statement block.
    
    However, what is worse: for 3.3 and present mainline, the
    warning isn't generated _at all_, so this is a regression.
    All this is the same for the C and C++ front ends, by the
    way, so I put it into the more generic "C" category.
    
    W.
Comment 2 Jason Merrill 2003-04-03 22:06:59 UTC
Responsible-Changed-From-To: unassigned->jason
Responsible-Changed-Why: got it
Comment 3 Jason Merrill 2003-04-04 01:21:46 UTC
From: jason@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/10175
Date: 4 Apr 2003 01:21:46 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_3-branch
 Changes by:	jason@gcc.gnu.org	2003-04-04 01:21:46
 
 Modified files:
 	gcc            : ChangeLog jump.c 
 
 Log message:
 	PR c/10175
 	* jump.c (never_reached_warning): Revert patch of 2002-11-02.
 	Look backwards for a line note.
 
 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.401&r2=1.16114.2.402
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/jump.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.214.2.3&r2=1.214.2.4
 

Comment 4 Jason Merrill 2003-04-04 01:21:57 UTC
From: jason@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/10175
Date: 4 Apr 2003 01:21:57 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	jason@gcc.gnu.org	2003-04-04 01:21:57
 
 Modified files:
 	gcc            : ChangeLog jump.c 
 
 Log message:
 	PR c/10175
 	* jump.c (never_reached_warning): Revert patch of 2002-11-02.
 	Look backwards for a line note.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.17319&r2=1.17320
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/jump.c.diff?cvsroot=gcc&r1=1.220&r2=1.221
 

Comment 5 Jason Merrill 2003-04-04 01:22:48 UTC
From: jason@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/10175
Date: 4 Apr 2003 01:22:48 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	jason@gcc.gnu.org	2003-04-04 01:22:48
 
 Modified files:
 	gcc            : ChangeLog jump.c 
 
 Log message:
 	PR c/10175
 	* jump.c (never_reached_warning): Look backwards for a line note.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.297&r2=1.13152.2.657.2.298
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/jump.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.205.2.1.4.4&r2=1.205.2.1.4.5
 

Comment 6 Jason Merrill 2003-04-04 01:25:40 UTC
From: jason@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/10175
Date: 4 Apr 2003 01:25:40 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	jason@gcc.gnu.org	2003-04-04 01:25:40
 
 Added files:
 	gcc/testsuite/gcc.dg: Wunreachable-3.c 
 
 Log message:
 	PR c/10175
 	* jump.c (never_reached_warning): Revert patch of 2002-11-02.
 	Look backwards for a line note.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/Wunreachable-3.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
 
Comment 7 Jason Merrill 2003-04-04 05:09:41 UTC
State-Changed-From-To: analyzed->open
State-Changed-Why: I've fixed the regression which broke the warning for 
    multiple-line blocks in 3.3 and on the trunk, but the 
    original limitation of not working with single lines 
    remains.  This seems to have been a deliberate choice when 
    the code was first written, presumably to reduce the number
    of false positives.
Comment 8 Jason Merrill 2003-04-04 05:14:30 UTC
Responsible-Changed-From-To: jason->unassigned
Responsible-Changed-Why: i now disclaim responsibility.
Comment 9 Roger Sayle 2003-04-17 01:22:51 UTC
From: sayle@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/10175
Date: 17 Apr 2003 01:22:51 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	sayle@gcc.gnu.org	2003-04-17 01:22:51
 
 Modified files:
 	gcc            : ChangeLog c-semantics.c Makefile.in 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/gcc.dg: Wunreachable-5.c 
 	gcc/testsuite/gcc.c-torture/execute: medce-1.c medce-2.c 
 
 Log message:
 	2003-04-16  Roger Sayle  <roger@eyesopen.com>
 	
 	* c-semantics.c (find_reachable_label): New function to find a
 	potentially reachable label in an expression.
 	(expand_unreachable_if_stmt): Similar to expand_if_stmt but
 	assumes the start of the IF_STMT is unreachable (dead) code.
 	(expand_unreachable_stmt): Similar to expand_stmt but assumes
 	the start of the statement list is unreachable (dead) code.
 	(genrtl_if_stmt):  If the controlling expression of the IF
 	is constant, use expand_unreachable_stmt for the THEN or ELSE
 	clause as appropriate.
 	(genrtl_switch_stmt):  Use expand_unreachable_stmt to expand
 	the body of a SWITCH statement.
 	(expand_stmt): The code immediately following a "return",
 	"break", "continue" or "goto" is unreachable.
 	* Makefile.in (c-semantics.o): Depend upon tree-inline.h.
 	
 	* gcc.dg/Wunreachable-5.c: New test case for PR c/10175.
 	* gcc.c-torture/execute/medce-1.c: New test case.
 	* gcc.c-torture/execute/medce-2.c: New test case.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.17475&r2=1.17476
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-semantics.c.diff?cvsroot=gcc&r1=1.53&r2=1.54
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/Makefile.in.diff?cvsroot=gcc&r1=1.1034&r2=1.1035
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2598&r2=1.2599
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/Wunreachable-5.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/medce-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/medce-2.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
 
Comment 10 Roger Sayle 2003-05-18 02:23:44 UTC
State-Changed-From-To: open->closed
State-Changed-Why: This should now be fixed on mainline with my 2003-04-16
    patch (as listed in the audit trail).  Many thanks to
    Giovanni Bajo for reminding me to close the PR.