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]

Unreachable code warning conflicts with optomisation


I like to use a lot of warning flags in my C programming, including many of
the optional ones - generally I find that they indicate possible bugs or
typos in my code, or things that may be correct but should be more verbose
in the code (such as adding extra casts).  However, one warning that is
potentially useful, -Wunreachable-code, seems to conflict with optomisation
(in the sense that it gives incorrect warnings, not that it generates bad
code).  I find the flag useful for spotting errors in code such as:

    unsigned int u;     if (u >= 0) {... } else { ...}

The "else" part will be flagged as unreachable - the condition should have
(u > 0), not (u >= 0).  However, when compiling with optomisation, the
compiler does a fair amount of common expression elimination, and erronously
flags code as "unreachable" when it is eliminated, even if it is logically
still used.  For example:
    switch (i) {
        case 0 : sendString("Zero"); sendNewline(); break;
        case 1 : sendString("One"); sendNewline(); break;
        case 2 : sendString("Two"); sendNewline(); break;
    }

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 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)?  Or is this just something I have to get used to (and use "lint" if
I want better static code analysis)?

Thanks,


David Brown
Norway

"Utvikling er kunsten av å vikle seg ut av det man har viklet seg inn i"




------
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]