https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113588
Bug ID: 113588 Summary: The vectorizer is introducing out-of-bounds memory access Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: kristerw at gcc dot gnu.org Target Milestone: --- The following function is miscompiled for x86_64 when compiled with -O3 -march=x86-64-v2 unsigned long foo (const char *s, unsigned long n) { unsigned long len = 0; while (*s++ && n--) ++len; return len; } The original function reads two bytes from 's' when called as: char a[4]; a[0] = 1; a[1] = 0; foo(a, 1000); However, the vectorized function reads 16 bytes (thereby accessing the buffer out of bounds) as it reads one vector at a time when s[0] != 0 and n >= 16.