On Mon, Oct 24, 2016 at 08:18:25AM -0600, Martin Sebor wrote:
> > The case above is just a case where with -O GCC can figure out what the 
> > value
> > of a const-qualified variable is, see decl_constant_value_for_optimization.
> > Since the warning is implemented even before gimplifying, optimizations like
> > CP don't come into play yet.
> 
> Ah, okay.  That should limit the number of these false positives.
> (I saw -O2 in dg-options and assumed it was important.  It sounds
> like the test case should pass even with -O1).
 
Yep--even -O is enough.

> But even without constant propagation there will be similar cases
> (though probably less pervasive).  For instance, if j were defined
> to something like this:
> 
>   const int j = 4 == sizeof (size_t);

Well, I think the warning would still be desirable:

  const int j = 4 == sizeof (long);
  if (j == 0)
    {   
      if (i > 10) /* { dg-warning "this condition has identical branches" } */
        *p = j * 2 + 1;
      else
        *p = 1;
    }

Given the j == 0 check, the branches really are duplicated.  This is actually
a distilled version of what I found in gcov-io.c.

        Marek

Reply via email to