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

            Bug ID: 83841
           Summary: missing -Wmemset-elt-size with array element plus
                    offset
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The -Wmemset-elt-size warning is issued inconsistently when memset is called
with an array plus offset as the first argument.

$ cat z.c && gcc -S -Wall z.c
int a[3];

void fcst (void)
{
  __builtin_memset (a + 1, 0, 2);   // missing -Wmemset-elt-size
}

void gcst (void)
{
  __builtin_memset (&a + 1, 0, 2);   // -Wmemset-elt-size (good)
}

void hcst (void)
{
  __builtin_memset (&a[1], 0, 2);   // missing -Wmemset-elt-size
}

void fvar (unsigned i)
{
  __builtin_memset (a + i, 0, 2);   // missing -Wmemset-elt-size
}

void gvar (unsigned i)
{
  __builtin_memset (&a + i, 0, 2);   // missing -Wmemset-elt-size
}

void hvar (unsigned i)
{
  __builtin_memset (&a[i], 0, 2);   // missing -Wmemset-elt-size
}

z.c: In function ‘gcst’:
z.c:10:3: warning: ‘__builtin_memset’ writing 2 bytes into a region of size 0
overflows the destination [-Wstringop-overflow=]
   __builtin_memset (&a + 1, 0, 2);   // -Wmemset-elt-size (good)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to