On Tue, 2015-06-09 at 13:31 -0400, Patrick Palka wrote:
> This patch improves the heuristics of the warning in a number of ways.
> The improvements are hopefully adequately documented in the code
> comments.
> 
> The additions to the test case also highlight the improvements.
> 
> I tested an earlier version of this patch on more than a dozen C code
> bases.  I only found one class of bogus warnings yet emitted, in the
> libpng and bdwgc projects.  These projects have a coding style which
> indents code inside #ifdefs as if this code was guarded by an if(), e.g.
> 
>   if (foo != 0)
>     x = 10;
>   else       // GUARD
>     y = 100; // BODY
> 
>   #ifdef BAR
>     blah ();  // NEXT
>   #endif

We have detect_preprocessor_logic which suppresses warnings when there's
preprocessor logic between BODY_EXPLOC and NEXT_STMT_EXPLOC, for cases
like this:

        if (flagA)
          foo ();
          ^ BODY_EXPLOC
      #if SOME_CONDITION_THAT_DOES_NOT_HOLD
        if (flagB)
      #endif
          bar ();
          ^ NEXT_STMT_EXPLOC

This currently requires that it be multiline preprocessor logic: there
must be 3 or more lines between BODY_EXPLOC and NEXT_STMT_EXPLOC for
this rejection heuristic to fire.

Perhaps we could tweak or reuse that heuristic, perhaps if there's an
entirely blank (or all whitespace) line separating them (given that this
warning is all about the "look" of the code).

> These bogus warnings are pre-existing, however (i.e. not caused by this
> patch).

(nods)   Fixing the false positives from libpng/bdwgc sounds like a
separate issue and thus a separate patch then.

[...snip...]


Reply via email to