This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c/8828: gcc reports some code is unreachable when it is not
- From: "Christian Ehrhardt" <ehrhardt at mathematik dot uni-ulm dot de>
- To: Rolf Campbell <rcampbell at tropicnetworks dot com>
- Cc: reichelt at igpm dot rwth-aachen dot de, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
- Date: Sat, 7 Dec 2002 01:58:19 +0100
- Subject: Re: c/8828: gcc reports some code is unreachable when it is not
- References: <83040F98B407E6428FEC18AC720F5D732DB774@exchange.tropicnetworks.com>
On Fri, Dec 06, 2002 at 11:22:32AM -0500, Rolf Campbell wrote:
> But, this was compiled WITHOUT optimizations (gcc -Wunreachable-code -c
> a.c), so there should be no removal of superfluous code, or folding of
> break statements.
Even without optimization it is possible that some code is unused
and removed. In this particular case the following case statement
switch (i) {
case 0:
for (; i<2; i++)
x++
break;
case 1:
x++;break;
}
Is rewritten to look like this (even without optimization this is allowed):
switch (i) {
case 0:
startfor:
if (i>=2)
goto caseend;
x++; i++;
goto startfor;
break;
case 1:
x++;break;
}
caseend:
which makes the first break statement unreachable. This is completly
legal and the compiler is even right in some sense that the break
statement is unreachable. Others should decide if this is actually a
bug but the warning is off by default for a reason.
regards Christian
--
THAT'S ALL FOLKS!