[cfe-dev] [cfe-commits] False positive for -Wunreachable-code

Ted Kremenek kremenek at apple.com
Tue Oct 30 14:26:53 PDT 2012


On Oct 30, 2012, at 2:19 PM, Richard Smith <richard at metafoo.co.uk> wrote:

> On Tue, Oct 30, 2012 at 1:51 PM, Ted Kremenek <kremenek at apple.com> wrote:
>> On Oct 30, 2012, at 1:24 PM, Richard Smith <richard at metafoo.co.uk> wrote:
>> 
>> 3) If there is no code after an enum-covered switch with no default,
>> or the next statement can be reached by a different path, we should
>> make a conservative assumption (that it cannot happen for cases where
>> it happening would trigger a warning, and that it can happen in cases
>> where it not happening would trigger a warning).
>> 
>> 
>> I think I understand what you mean, but that's a bit of a run on sentence.
>> The multiple "it happening" and "it not happening" is confusing.  Can you be
>> a bit more clear?  Since this may not be fixed immediately it would be good
>> to establish some clarity here.
> 
> Sorry for my terrible sentence construction! I have in mind examples like this:
> 
> enum E { a, b, c };
> int f(bool b, E e) {
>  int n;
>  if (b) {
>    switch (e) { // #1
>    case a: case b: case c:
>      return 0;
>    }
>  } else {
>    n = 0;
>  }
>  return n; // #2
> }
> 
> I'm suggesting that in this case, we should be conservative when
> adding a CFG edge from #1 to #2, because:
>  * #2 has predecessors other than #1, and
>  * #1 has no explicit indication that the default case is reachable
> 
> By "be conservative", I mean:
>  * If the presence of a CFG edge would make a particular checker
> think there was a bug, we assume the edge from #1 to #2 cannot happen
> for the purpose of that check
>  * If the absence of a CFG edge would make a particular checker think
> there was a bug, we assume the edge from #1 to #2 can happen for the
> purpose of that check
> 
> So, -Wuninitialized and -Wreturn-type would assume that the edge from
> #1 to #2 cannot happen (and -Wuninitialized would not warn here). But
> -Wunreachable-code would assume that the edge from #1 to #2 can
> happen, and again would not warn (as it happens, -Wunreachable-code
> can actually assume that the edge cannot happen too, since we only
> make this assumption in the cases where we already know #2 is
> reachable by some other path).

Ok, that makes perfect sense.  Thanks for taking the time to explain this!




More information about the cfe-dev mailing list