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

            Bug ID: 95278
           Summary: attribute nonstring effect on arguments in function
                    declaration that's not a definition
           Product: gcc
           Version: 10.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: ---

strlen calls in both functions below should be diagnosed because the
declaration with the attribute is likely to be in a header and thus come first,
and it's what determines what calls can be diagnosed.  Unfortunately, the more
likely case is not diagnosed.

$ cat z.c && gcc -S -Wall -Wextra z.c
int f (const char *);

int f (const char __attribute__ ((nonstring)) *p)
{
  return __builtin_strlen (p);     // warning (good)
}


int g (const char __attribute__ ((nonstring))*);

int g (const char *p)
{
  return __builtin_strlen (p);     // missing warning
}
z.c: In function ‘f’:
z.c:5:10: warning: ‘__builtin_strlen’ argument 1 declared attribute ‘nonstring’
[-Wstringop-overflow=]
    5 |   return __builtin_strlen (p);     // warning (good)
      |          ^~~~~~~~~~~~~~~~~~~~
z.c:3:48: note: argument ‘p’ declared here
    3 | int f (const char __attribute__ ((nonstring)) *p)
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Reply via email to