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

            Bug ID: 98548
           Summary: missing warning on strcmp with a nonstring member
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

-Wstringop-overread detects the misuse of the nonstring array as a strcmp
argument in f() but not in g().  Both calls should trigger a warning.

$ cat b.c && gcc -O2 -S -Wall -Wextra b.c
struct A
{
  char a[4] __attribute__ ((nonstring));
  char b[8];
};

int f (void)
{
  extern struct A a;
  return 0 == __builtin_strcmp (a.a, a.b);   // warning (good)
}

int g (struct A *p)
{
  return 0 == __builtin_strcmp (p->a, p->b);   // missing warning
}
b.c: In function ‘f’:
b.c:10:15: warning: ‘__builtin_strcmp’ argument 1 declared attribute
‘nonstring’ is smaller than the specified bound 8 [-Wstringop-overread]
   10 |   return 0 == __builtin_strcmp (a.a, a.b);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
b.c:3:8: note: argument ‘a’ declared here
    3 |   char a[4] __attribute__ ((nonstring));
      |        ^

Reply via email to