https://bugs.llvm.org/show_bug.cgi?id=45122

            Bug ID: 45122
           Summary: Segmentation fault in memet function
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

Hi, this 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;
}

get "Segmentation fault" when I use `clang-6.0 test.c ` to compiler and then
`./a.out` to execute (-O1 is also fault, in ubuntu 16.04). 

I know that the index of an array is -1 and not suitable, but when I add -O2,
-O3, or -Os to compile it, then the fault is gone. I also test clang-3.8, and
it has the same results.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to