On 12/14/2017 05:35 PM, Marcel Keller wrote:
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?
What should certainly be considered a bug is that the warning doesn't point to the source code line where it says the overflow happens. The warning isn't caused by the explicit memset but rather by GCC introducing one within the loop. I'm not sure that the warning itself should be considered a bug. If the function is called with length greater than or equal to 32 it will overflow. So I'd say the warning is helpful in pointing it out. What's not helpful is the missing location information, compounded by the fact that the only memset call in the source code isn't what causes it. To avoid the warning make sure foo() calls avx_memzero with a length of at most the size of bar. Martin