Hi,
Compiling the attached code with GCC 7.2 (Ubuntu 17.10) gives the
following warning:
$ g++ -mavx -O3 foo.cpp -c
In function ‘void foo(size_t)’:
cc1plus: warning: ‘void* __builtin_memset(void*, int, long unsigned
int)’: writing between 32 and 18446744073709551584 bytes into a region
of size 16 overflows the destination [-Wstringop-overflow=]
However, the length in the memset call would be between 1 and 31, and
the range 1 to 16 should be fine, as far as I can tell. Should that be
considered a bug?
Best regards,
Marcel
#include <immintrin.h>
#include <string.h>
long long bar[2];
void avx_memzero(void* dest, size_t length)
{
__m256i* d = (__m256i*)dest;
__m256i s = _mm256_setzero_si256();
while (length >= 32)
{
_mm256_storeu_si256(d++, s);
length -= 32;
}
if (length)
memset((void*)d, 0, length);
}
void foo(size_t t)
{
avx_memzero(bar, t);
}