1// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
4// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
5
6#include <string.h>
7int main(int argc, char **argv) {
8 char x[10];
9 memset(s: x, c: 0, n: 10);
10 int res = x[argc * 10]; // BOOOM
11 // CHECK: {{READ of size 1 at 0x.* thread T0}}
12 // CHECK: {{ #0 0x.* in main .*stack-buffer-overflow.cpp:}}[[@LINE-2]]
13 // CHECK: {{Address 0x.* is located in stack of thread T0 at offset}}
14 // CHECK-NEXT: in{{.*}}main{{.*}}stack-buffer-overflow.cpp
15 return res;
16}
17

source code of compiler-rt/test/asan/TestCases/stack-buffer-overflow.cpp