1// ASan interceptor can be accessed with __interceptor_ prefix.
2
3// RUN: %clangxx_asan -m64 -O0 %s -o %t && %t 2>&1 | FileCheck %s
4// RUN: %clangxx_asan -m64 -O1 %s -o %t && %t 2>&1 | FileCheck %s
5// RUN: %clangxx_asan -m64 -O2 %s -o %t && %t 2>&1 | FileCheck %s
6// RUN: %clangxx_asan -m64 -O3 %s -o %t && %t 2>&1 | FileCheck %s
7// RUN: %clangxx_asan -m32 -O0 %s -o %t && %t 2>&1 | FileCheck %s
8// RUN: %clangxx_asan -m32 -O1 %s -o %t && %t 2>&1 | FileCheck %s
9// RUN: %clangxx_asan -m32 -O2 %s -o %t && %t 2>&1 | FileCheck %s
10// RUN: %clangxx_asan -m32 -O3 %s -o %t && %t 2>&1 | FileCheck %s
11#include <stdlib.h>
12#include <stdio.h>
13#include <unistd.h>
14
15extern "C" void *__interceptor_malloc(size_t size);
16extern "C" void *malloc(size_t size) {
17  write(2, "malloc call\n", sizeof("malloc call\n") - 1);
18  return __interceptor_malloc(size);
19}
20
21int main() {
22  char *x = (char*)malloc(10 * sizeof(char));
23  free(x);
24  return (int)strtol(x, 0, 10);
25  // CHECK: malloc call
26  // CHECK: heap-use-after-free
27}
28