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

            Bug ID: 93977
           Summary: missing -Wrestrict with sprintf with same format as
                    destination
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

-Wrestrict correctly detects the overlap in g() below but misses the trivial
overlap in h():

$ cat t.c && gcc -O2 -S -Wall t.c
void f (void*);

void g (void)
{
  char a[] = "%s abc";
  __builtin_sprintf (a, "%s abc", a);    // -Wrestrict (good)
  f (a);
}

void h (void)
{ 
  char a[] = "%s abc";
  __builtin_sprintf (a, a, a);           // missing warning
  f (a);
}
t.c: In function ‘g’:
t.c:6:29: warning: ‘ abc’ directive writing 4 bytes into a region of size 1
[-Wformat-overflow=]
    6 |   __builtin_sprintf (a, "%s abc", a);    // -Wrestrict (good)
      |                            ~^~~
t.c:6:3: note: ‘__builtin_sprintf’ output 11 bytes into a destination of size 7
    6 |   __builtin_sprintf (a, "%s abc", a);    // -Wrestrict (good)
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t.c:6:3: warning: ‘__builtin_sprintf’ argument 3 overlaps destination object
‘a’ [-Wrestrict]
t.c:5:8: note: destination object referenced by ‘restrict’-qualified argument 1
was declared here
    5 |   char a[] = "%s abc";
      |        ^

Reply via email to