Bug 5897 - [3.3 regression] No warning for statement after return
Summary: [3.3 regression] No warning for statement after return
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 2.95.3
: P3 enhancement
Target Milestone: 3.3.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-03-09 04:16 UTC by yooden
Modified: 2003-06-12 00:03 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-05-24 22:36:31


Attachments
broken.i (90 bytes, text/x-c)
2003-05-21 15:16 UTC, yooden
Details

Note You need to log in before you can comment on or make changes to this bug.
Description yooden 2002-03-09 04:16:02 UTC
In an if-else combo, statements after the returns are not reported when running:
	gcc -O3 -Wall -pedantic
- - -
static int broken()
{
    int i;
    
    if (0)
    {
        return(1);
        i = 0;
    } else
    {
        return(1);
        i = 0;
    }
}

Release:
2.95.3, provided by SuSE 7.2

Environment:
Linux eumel 2.4.4-4GB #1 Wed May 16 00:37:55 GMT 2001 i686 unknown

How-To-Repeat:
gcc -O3 -Wall -pedantic -c broken.c -o broken.o
Comment 1 Wolfgang Bangerth 2002-12-11 14:01:53 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed with present 3.3CVS. You must add -Wunreachable-code,
    but it doesn't detect the problem here either.
Comment 2 Andrew Pinski 2003-05-24 22:36:31 UTC
It has been fixed on the mainline (20030524).
Should this go into 3.3.1?
Fixed by:
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.
Comment 3 Andrew Pinski 2003-05-29 17:28:37 UTC
Since this is fixed in 3.3.1 (20030526) and on the mainline (20030529), I am closing this 
as being fixed, you still have to use -Wunreachable-code.