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
14extern "C" long __interceptor_strtol(const char *nptr, char **endptr, int base);
15extern "C" long strtol(const char *nptr, char **endptr, int base) {
16  fprintf(stderr, "my_strtol_interceptor\n");
17  return __interceptor_strtol(nptr, endptr, base);
18}
19
20int main() {
21  char *x = (char*)malloc(10 * sizeof(char));
22  free(x);
23  return (int)strtol(x, 0, 10);
24  // CHECK: my_strtol_interceptor
25  // CHECK: heap-use-after-free
26}
27