[llvm-bugs] [Bug 45122] New: Segmentation fault in memet function

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 5 08:00:10 PST 2020


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: unassignedclangbugs at nondot.org
          Reporter: haoxintu at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200305/0bad3e4a/attachment.html>


More information about the llvm-bugs mailing list