From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9860 invoked by alias); 15 Feb 2003 20:06:00 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 9846 invoked by uid 71); 15 Feb 2003 20:06:00 -0000 Date: Sat, 15 Feb 2003 20:06:00 -0000 Message-ID: <20030215200600.9845.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Steven Bosscher Subject: Re: c/8828: [3.2/3.3/3.4 regression] gcc reports some code is unreachable when it is not Reply-To: Steven Bosscher X-SW-Source: 2003-02/txt/msg00667.txt.bz2 List-Id: The following reply was made to PR c/8828; it has been noted by GNATS. From: Steven Bosscher To: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org, rcampbell@tropicnetworks.com, nobody@gcc.gnu.org, gcc-prs@gcc.gnu.org Cc: Subject: Re: c/8828: [3.2/3.3/3.4 regression] gcc reports some code is unreachable when it is not Date: 15 Feb 2003 20:56:34 +0100 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8828 We would incorrectly flag the case blocks as unreachable code (with -Wunreachable-code, or course) for this testcase: void foo (int i) { switch (i) { case 0: break; case 1: break; }; }; The problem seems to be that in the loop in jump.c:never_reached_warning() ignores barriers, so it happily falls through to the next basic block and thinks that the jump_insn for break is an unreachable insn. With the attached patch, we terminate the loop when we hit a barrier. I hardly tested this patch, but I've made sure that it bootstraps, fixes the testcase and does not break any of the test cases in the test suite that have the option "-Wunreachable-code". I can't do a full regression test (just a bootstrap takes about half a day on my computer :-/), and it wouldn't even matter for the bootstrap because -Wunreachable-code is not set for "-Wall". There's also another change in behavior; for this test case: int x; void foo (int i) { switch (i) { case 0: startfor: goto caseend; x = 1; case 1: x = 1; break; } caseend: return; } We used to flag that the "goto caseend;" was unreachable code, instead of "x=1". I think this is actually an example of this PR (8828), not warning about "x = 1" is probably the same bug as reported in PR c/5897. With this patch we don't have a warning for this code at all. I think this still is better than having false positives. Can somebody with a better machine give this patch some propper testing? Greetz Steven Index: gcc/jump.c =================================================================== RCS file: /cvsroot/gcc/gcc/gcc/jump.c,v retrieving revision 1.216 diff -c -3 -p -r1.216 jump.c *** gcc/jump.c 10 Jan 2003 13:44:28 -0000 1.216 --- gcc/jump.c 15 Feb 2003 19:16:48 -0000 *************** never_reached_warning (avoided_insn, fin *** 1918,1924 **** for (insn = avoided_insn; insn != NULL; insn = NEXT_INSN (insn)) { ! if (finish == NULL && GET_CODE (insn) == CODE_LABEL) break; if (GET_CODE (insn) == NOTE /* A line number note? */ --- 1918,1925 ---- for (insn = avoided_insn; insn != NULL; insn = NEXT_INSN (insn)) { ! if ((finish == NULL && GET_CODE (insn) == CODE_LABEL) ! || GET_CODE (insn) == BARRIER) break; if (GET_CODE (insn) == NOTE /* A line number note? */