This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c/8828: gcc reports some code is unreachable when it is not


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!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]