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

            Bug ID: 102555
           Summary: missing -Waddress comparing &p[0] to zero
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Event with the patch for pr102103 applied, only the first of the two equality
expressions gets a warning, even though ideally both should.  This is tracked
(and xfailed) in gcc/testsuite/c-c++-common/Waddress-4.c.

$ cat z.c && gcc -S -Wall -fdump-tree-original=/dev/stdout z.c
int f (int *p, int i)
{
  return &p[i] == 0;
}      

int g (int *p)
{
  return &p[0] == 0;
}
z.c: In function ‘f’:
z.c:3:16: warning: the comparison will always evaluate as ‘false’ for the
pointer operand in ‘p + (sizetype)((long unsigned int)i * 4)’ must not be NULL
[-Waddress]
    3 |   return &p[i] == 0;
      |                ^~

;; Function f (null)
;; enabled by -tree-original


{
  return p + (sizetype) ((long unsigned int) i * 4) == 0B;
}


;; Function g (null)
;; enabled by -tree-original


{
  return p == 0B;
}

Reply via email to