This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


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: Unreachable code warning conflicts with optomisation


> On Fri, Sep 26, 2003 at 11:51:30AM +0200, David Brown wrote:
> > The optomiser will combine the "sendNewline()" calls, which is good.
> > However, two of the three calls are now flagged as "unreachable", which
is
> > not the case.
>
> I can't reproduce this at all, using your code and -Wall on
> gcc 2.95.4. What version do you use and how do you compile
> it?
>
> > I suppose this problem is a general gcc one rather than a crossgcc
issue,
> > but maybe someone here has come across this and has some ideas?  Or
should I
> > ask on a gcc list (I don't know if it really counts as a "bug" for a bug
> > report)?
>
> IMO it's definitely a gcc bug: it warns you of something
> that really isn't there.
>

I've filled out a complete example below.  The "-Wunreachable-code" is not
included in the -Wall flags, so it has to be specified seperately.  The
warnings depend on the optomisation level used:

>m68k-elf-gcc -W -c test.c -o test.o -Wunreachable-code

>m68k-elf-gcc -W -O1 -c test.c -o test.o -Wunreachable-code
test.c: In function `test2':
test.c:27: warning: will never be executed
test.c:23: warning: will never be executed

>m68k-elf-gcc -W -O2 -c test.c -o test.o -Wunreachable-code
test.c: In function `test1':
test.c:13: warning: will never be executed
test.c: In function `test2':
test.c:27: warning: will never be executed
test.c:23: warning: will never be executed


// *******************************
extern void sendString(char *p);
extern void sendNewline(void);


void test1(unsigned int u)
{
 if (u > 0) {
  sendString("Greater than 0");
 } else if (u == 0) {
  sendString("Equal to 0");
 } else {
  sendString("Less than 0");
 };
}


void test2(int i)
{
 switch (i) {
 case 0 :
  sendString("Zero");
  sendNewline();
  break;
 case 1 :
  sendString("One");
  sendNewline();
  break;
 case 2 :
  sendString("Two");
  sendNewline();
  break;
    }
}
// *******************************



mvh.

David




------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


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