| 1 | // RUN: %clangxx_asan -O0 %s --std=c++14 -o %t |
| 2 | |
| 3 | // RUN: not %run %t 10 0 2>&1 | FileCheck %s --check-prefixes=CHECK,T0 |
| 4 | // RUN: not %run %t 10000000 0 2>&1 | FileCheck %s --check-prefixes=CHECK,T0 |
| 5 | |
| 6 | // RUN: not %run %t 10 1 2>&1 | FileCheck %s --check-prefixes=CHECK,T1 |
| 7 | // RUN: not %run %t 10000000 1 2>&1 | FileCheck %s --check-prefixes=CHECK,T1 |
| 8 | |
| 9 | // REQUIRES: stable-runtime |
| 10 | |
| 11 | #include <sanitizer/asan_interface.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <thread> |
| 14 | |
| 15 | void UPDATE(void *p) { |
| 16 | __asan_update_allocation_context(addr: p); |
| 17 | } |
| 18 | |
| 19 | int main(int argc, char *argv[]) { |
| 20 | char *x = (char *)malloc(size: atoi(nptr: argv[1]) * sizeof(char)); |
| 21 | if (atoi(nptr: argv[2])) |
| 22 | std::thread([&]() { UPDATE(x); }).join(); |
| 23 | else |
| 24 | UPDATE(p: x); |
| 25 | free(ptr: x); |
| 26 | return x[5]; |
| 27 | // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}} |
| 28 | // CHECK: READ of size 1 at {{.*}} thread T0 |
| 29 | // T0: allocated by thread T0 here |
| 30 | // T1: allocated by thread T1 here |
| 31 | // CHECK: UPDATE |
| 32 | } |
| 33 | |