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

            Bug ID: 93519
           Summary: bogus -Wrestrict for strcpy(d, s) call guarded by d !=
                    s
           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: ---

This was reported in RHBZ #1796688 (and previously for memcpy in bug 83456). 
The warning is obviously incorrect here:

#include <string.h>

static char *
str_numth(char *dest, char *num, int type)
{
        if (dest != num)
                strcpy(dest, num);
        strcat(dest, "foo");
        return dest;
}

void
DCH_to_char(char *in, char *out, int collid)
{
        char       *s  = out;

        str_numth(s, s, 42);
}

$ gcc -Wall -c -O2 wtest.c
wtest.c: In function 'DCH_to_char':
wtest.c:7:3: warning: 'strcpy' source argument is the same as destination
[-Wrestrict]
    7 |   strcpy(dest, num);
      |   ^~~~~~~~~~~~~~~~~

Reply via email to