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

            Bug ID: 83840
           Summary: missing -Wmemset-elt-size with address of array
                    element
           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: ---

When passing the address of an array to a function that takes a pointer it's
common (if unnecessarily verbose) practice  to take the address of the first
element of the array and pass it instead.  The test program below shows that
the -Wmemset-elt-size warning doesn't work for this case.

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

void f (void)
{
  __builtin_memset (a, 0, 2);   // -Wmemset-elt-size (good)
}

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

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

z.c: In function ‘void f()’:
z.c:5:28: warning: ‘memset’ used with length equal to number of elements
without multiplication by element size [-Wmemset-elt-size]
   __builtin_memset (a, 0, 2);   // -Wmemset-elt-size (good)
                            ^
z.c: In function ‘void g()’:
z.c:10:29: warning: ‘memset’ used with length equal to number of elements
without multiplication by element size [-Wmemset-elt-size]
   __builtin_memset (&a, 0, 2);   // -Wmemset-elt-size (good)
                             ^

Reply via email to