https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94053
Bug ID: 94053
Summary: Segmentation fault in default Optimization, but works
well in O1 ~ Os
Product: gcc
Version: 8.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: haoxintu at gmail dot com
Target Milestone: ---
Hi, The code test.c
#include <stdio.h>
#include <string.h>
void foo(int* a ) {
a[-1]=1;
}
int main (int argc, char* argv[]) {
int size= 10;
printf("%d\n", size);
int array[size];
memset(array,0,size*sizeof(int));
foo(array);
return 0;
}
is getting "Segmentation fault" when I use `gcc test.c` to compile and
`./a.out`
to execute it (in Ubuntu 16.04, gcc 8.1.0).
I know that the index of an array is -1 and not suitable, but when I add -O1,
-O2, -O3, or -Os to compile it, then the fault is gone.