1 // ASan interceptor can be accessed with __interceptor_ prefix.
2 
3 // { dg-do run }
4 // { dg-options "-fno-builtin-malloc -fno-builtin-free" }
5 // { dg-additional-options "-D__NO_INLINE__" { target { *-*-linux-gnu } } }
6 // { dg-shouldfail "asan" }
7 // { dg-skip-if "Darwin uses mac function interposition" { *-*-darwin* } }
8 
9 #include <stdlib.h>
10 #include <stdio.h>
11 
12 extern "C" long __interceptor_strtol(const char *nptr, char **endptr, int base);
strtol(const char * nptr,char ** endptr,int base)13 extern "C" long strtol(const char *nptr, char **endptr, int base) {
14   fprintf(stderr, "my_strtol_interceptor\n");
15   return __interceptor_strtol(nptr, endptr, base);
16 }
17 
main()18 int main() {
19   char *x = (char*)malloc(10);
20   free(x);
21   return (int)strtol(x, 0, 10);
22 }
23 
24 // { dg-output "my_strtol_interceptor.*(\n|\r\n|\r)" }
25 // { dg-output "\[^\n\r]*heap-use-after-free" }
26