https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115965
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Nathan Teodosio from comment #5) > In none of them. Or am I overlooking a buffer overrun here? You definitely are overlooking one. for (size_t i = 0; i < size; i += hn::Lanes(d)) { hn::Store(x, d, x_array + i); hn::Lanes(d) is 4. so you are storing 0,1,2,3 and then 4,5,6,7 . Except there are only 5 elements of x_array so 5,6,7 stores is broken. >In any case I fail to see why that would be dependent on which of the array >definitions in main come first. Because -fstack-protector-all only checks one place in the stack rather than after each array. So the order of the arrays on the stack for a tie breaker is the order of how the user order was. So it just happens to be at the end you get the stack smasher error. With -fsanitize=address all arrays have a redzone and you get the following eror message and that is indepdent of the order of arrays since all load/stores are checked. ================================================================= ==1==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x782bede00030 at pc 0x000000401b3e bp 0x7ffeb05deab0 sp 0x7ffeb05deaa8 READ of size 16 at 0x782bede00030 thread T0 #0 0x401b3d in _mm_load_si128(long long __vector(2) const*) /opt/compiler-explorer/gcc-trunk-20240717/lib/gcc/x86_64-linux-gnu/15.0.0/include/emmintrin.h:701 #1 0x401b3d in Load<hwy::N_SSE2::Simd<int, 4, 0> > /opt/compiler-explorer/libs/highway/trunk/hwy/ops/x86_128-inl.h:2069 #2 0x401311 in MulAddLoop(int const*, int const*, unsigned long, int*) /app/example.cpp:11 #3 0x401954 in main /app/example.cpp:22 #4 0x782befa29d8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 490fef8403240c91833978d494d39e537409b92e) #5 0x782befa29e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 490fef8403240c91833978d494d39e537409b92e) #6 0x401104 in _start (/app/output.s+0x401104) (BuildId: 4af5893bdf93a048dba77151f2e0b5e5a0ee46bd) Address 0x782bede00030 is located in stack of thread T0 at offset 48 in frame #0 0x4014cf in main /app/example.cpp:18 This frame has 3 object(s): [32, 52) 'a' (line 19) <== Memory access at offset 48 partially overflows this variable [96, 116) 'b' (line 19) [160, 180) 'c' (line 20) HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork (longjmp and C++ exceptions *are* supported) SUMMARY: AddressSanitizer: stack-buffer-overflow /opt/compiler-explorer/gcc-trunk-20240717/lib/gcc/x86_64-linux-gnu/15.0.0/include/emmintrin.h:701 in _mm_load_si128(long long __vector(2) const*) Shadow bytes around the buggy address: 0x782beddffd80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x782beddffe00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x782beddffe80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x782beddfff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x782beddfff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x782bede00000: f1 f1 f1 f1 00 00[04]f2 f2 f2 f2 f2 00 00 04 f2 0x782bede00080: f2 f2 f2 f2 00 00 04 f3 f3 f3 f3 f3 00 00 00 00 0x782bede00100: f1 f1 f1 f1 f1 f1 01 f2 00 00 f2 f2 f8 f8 f2 f2 0x782bede00180: f8 f8 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00 0x782bede00200: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 0x782bede00280: f5 f5 f5 f5 00 00 00 00 00 00 00 00 00 00 00 00 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==1==ABORTING