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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot 
gnu.org

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed with the following test case.

  extern char arr[] __attribute__ ((nonstring));
  extern char str[];

  int f (void)
  {
    return __builtin_strcmp (arr, str);
  }

The expected output is:

  $ gcc -O2 -S -Wall -Wextra -Wpedantic a.c
  a.c: In function ‘f’:
  a.c:6:10: warning: ‘__builtin_strcmp’ argument 1 declared attribute
‘nonstring’ [-Wstringop-overflow=]
     return __builtin_strcmp (arr, str);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  a.c:1:13: note: argument ‘arr’ declared here
   extern char arr[] __attribute__ ((nonstring));
               ^~~

With a powerpc64le-linux GCC, there is no warning.

The strcmp call is expanded in builtins.c and never reaches expand_call in
calls.c where the checking is done.  Something similar can happen for strlen on
x86_64 and there it's being handled by also checking in builtins.c (in
expand_builtin_strlen).  So strcmp and other string functions will need the
same treatment.

Reply via email to