https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94055
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- With optimization GCC removes the memset statement because the array isn't used after that, so that's probably why the program doesn't crash. As Andrew pointed out, very large variable length arrays can exhaust the stack and cause crashes. When using them it's best to make sure they don't exceed some small number of elements. The -Wvla-larger-than=<byte-size> option helps enforce that policy. With that: $ cat pr94055.c && gcc -O2 -Wall -Wvla-larger-than=1000 pr94055.c && ./a.out #include <stdio.h> #include <string.h> #include <stdlib.h> int i = 0; int main (int argc, char* argv[]) { int size = 10000000; printf("%d \n", size); int array[size]; memset(array,0,size*sizeof(int)); return array[i]; } pr94055.c: In function ‘main’: pr94055.c:10:9: warning: argument to variable-length array is too large [-Wvla-larger-than=] 10 | int array[size]; | ^~~~~ pr94055.c:10:9: note: limit is 1000 bytes, but argument is 40000000 10000000 Segmentation fault (core dumped)