33 lines · cpp
1// RUN: %clangxx_asan -O0 %s --std=c++14 -o %t2 3// RUN: not %run %t 10 0 2>&1 | FileCheck %s --check-prefixes=CHECK,T04// RUN: not %run %t 10000000 0 2>&1 | FileCheck %s --check-prefixes=CHECK,T05 6// RUN: not %run %t 10 1 2>&1 | FileCheck %s --check-prefixes=CHECK,T17// RUN: not %run %t 10000000 1 2>&1 | FileCheck %s --check-prefixes=CHECK,T18 9// REQUIRES: stable-runtime10 11#include <sanitizer/asan_interface.h>12#include <stdlib.h>13#include <thread>14 15void UPDATE(void *p) {16 __asan_update_allocation_context(p);17}18 19int main(int argc, char *argv[]) {20 char *x = (char *)malloc(atoi(argv[1]) * sizeof(char));21 if (atoi(argv[2]))22 std::thread([&]() { UPDATE(x); }).join();23 else24 UPDATE(x);25 free(x);26 return x[5];27 // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}28 // CHECK: READ of size 1 at {{.*}} thread T029 // T0: allocated by thread T0 here30 // T1: allocated by thread T1 here31 // CHECK: UPDATE32}33