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

Vincent Riviere <vincent.riviere at freesbee dot fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|WONTFIX                     |---
             Status|RESOLVED                    |REOPENED

--- Comment #4 from Vincent Riviere <vincent.riviere at freesbee dot fr> ---
Thanks for your explanations.
But apologies, I oversimplified my real-world testcase. The one below is more
realistic, and still triggers the warning with -O2

$ cat foo.c && m68k-elf-gcc -c foo.c -Wall -O2
char *strcpy(char *, const char *);
int sprintf(char *, const char *, ...);

char* myalloc(int n) __attribute__((alloc_size(1)));

void f(void)
{
    char* buf = myalloc(30);
    char* str1 = buf;
    char* str2 = buf + 10;
    char* str3 = buf + 20;

    strcpy(str3, "123");
    sprintf(str2, "ABC%s", str3);
    sprintf(str1, "DEF%s", str2);
}
foo.c: In function 'f':
foo.c:15:5: warning: 'sprintf' argument 3 may overlap destination object 'buf'
[-Wrestrict]
   15 |     sprintf(str1, "DEF%s", str2);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to