https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80479
Alan Modra <amodra at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amodra at gmail dot com --- Comment #9 from Alan Modra <amodra at gmail dot com> --- The following doesn't fail, but the strcmp optimization doesn't trigger either.. #include <stdio.h> #include <string.h> #include <sys/mman.h> int main () { #if 0 char str1[15]; char str2[15]; #else const size_t len = 65536; char *buf1, *buf2, *str1, *str2; buf1 = mmap (NULL, 2 * len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (buf1 == MAP_FAILED) { perror ("mmap failed"); return 0; } if (munmap (buf1 + len, len) < 0) { perror ("munmap failed"); return 0; } buf2 = mmap (NULL, 2 * len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (buf2 == MAP_FAILED) { perror ("mmap failed"); return 0; } if (munmap (buf2 + len, len) < 0) { perror ("munmap failed"); return 0; } str1 = buf1 + len - 7; str2 = buf2 + len - 7; #endif strcpy (str1, "abcdef"); strcpy (str2, "ABCDEF"); return strcmp (str1, str2); } For the #if 1 case, valgrind is complaining about the compare of two eight byte words read from the stack, which indeed do have one uninitialized byte past the string terminating zero. I don't believe it matters. (The generated asm looks OK to me, but that might be because my brain has shut down for the night.)