| 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 | // REQUIRES: stable-runtime |
| 6 | |
| 7 | #include <stdlib.h> |
| 8 | int main() { |
| 9 | char *x = (char*)malloc(size: 10 * sizeof(char)); |
| 10 | free(ptr: x); |
| 11 | return x[5]; |
| 12 | // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}} |
| 13 | // CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}} |
| 14 | // CHECK: {{READ of size 1 at 0x.* thread T0}} |
| 15 | // CHECK: {{ #0 0x.* in main .*use-after-free.cpp:}}[[@LINE-4]] |
| 16 | // CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}} |
| 17 | // CHECK: {{freed by thread T0 here:}} |
| 18 | // CHECK: {{ #0 0x.* in .*free}} |
| 19 | // CHECK: {{ #[1-3] 0x.* in main .*use-after-free.cpp:}}[[@LINE-9]] |
| 20 | |
| 21 | // CHECK: {{previously allocated by thread T0 here:}} |
| 22 | // CHECK: {{ #0 0x.* in .*malloc}} |
| 23 | // CHECK: {{ #[1-3] 0x.* in main .*use-after-free.cpp:}}[[@LINE-14]] |
| 24 | // CHECK: Shadow byte legend (one shadow byte represents {{[0-9]+}} application bytes): |
| 25 | // CHECK: Global redzone: |
| 26 | // CHECK: ASan internal: |
| 27 | } |
| 28 | |