This is the mail archive of the gcc@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]

proposal: suppress warnings in unexecutable code


Consider the warning message for this code:

    int main() { return 0 && main; }

    foo.c:1: warning: the address of 'main', will always evaluate as 'true'

While the warning is technically true, it doesn't matter
since it happens in code that can never be executed.
(Such code typically happens as a result of macro expansions.)

A "grep skip_evaluation" on gcc source shows a number of warnings
that are explicitly suppressed for unexecutable code.
Let's do this systematically by putting this into the warning function:

    if (skip_evaluation)
      return;

===========

But this might suppress desirable warnings.

1. For a year I ran a gcc which put the string UNREACHABLE in warnings
when skip_evaluation was true.  All such warnings were just noise,
so after the year I suppressed them entirely.

2. Here is a potentially useful warning message for unexecutable code:

    int subr(void)
    {
      char x[10];
      return sizeof((char *)x);
    }
    foo.c:4: warning: sizeof used on array that has been converted to pointer

The hazard is that perhaps this was supposed to return 10, not sizeof(char *).
(Again, such code would most likely arise from macro expansions.)
Vanilla gcc does not issue such a warning, but it it did
the proposed change might suppress it, so perhaps the test should instead be:

   if (skip_evaluation && !in_sizeof && !in_alignof && !in_typeof)

3. That fact that code is unexecutable can itself be worth a warning,
which is what -Wunreachable-code does.  The proposed change
does not suppresses those, but conceptually this is an issue as well.

===========

gcc can continue to use (abuse?) skip_evaluation
to suppress selected warnings as people complain about the noise,
so this isn't that big a deal.  But it seemed worth bringing up.

Tom Truscott


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