[Bug c/80525] New: -Wlogical-op confused by undefined integer overflow

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Apr 26 11:09:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80525

            Bug ID: 80525
           Summary: -Wlogical-op confused by undefined integer overflow
           Product: gcc
           Version: 7.0.1
            Status: UNCONFIRMED
          Keywords: diagnostic, xfail
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

A subset of c-c++-common/Wlogical-op-1.c doesn't work with -fstrict-overflow:

  if ((a + 1) && (a + 1)) {}

and

  if ((a + 1) || (a + 1)) {}

do not warn because op_left is a <maybe_const_expr a + 1> != 0 and
op_right a + 1.  Fr the first make_range simply returns
<maybe_const_expr a + 1> while for the second it returns a.

it looks like maybe_const_expr handling is bogus here.

With removing -fstrict-overflow I need to XFAIL the subtests (or add -fwrapv
give the test only runs at -O0 at the moment and thus with signed overflow
not undefined).

Testcase:

void andfn (int a, int b)
{
  if ((a + 1) && (a + 1)) {}
}

> gcc-7 -S t.c -Wlogical-op 
t.c: In function ‘andfn’:
t.c:3:15: warning: logical ‘and’ of equal expressions [-Wlogical-op]
   if ((a + 1) && (a + 1)) {}
               ^~
> gcc-7 -S t.c -Wlogical-op -fstrict-overflow
<nothing>


More information about the Gcc-bugs mailing list