summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/asan/lit_tests/malloc_hook.cc
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/lib/asan/lit_tests/malloc_hook.cc')
-rw-r--r--compiler-rt/lib/asan/lit_tests/malloc_hook.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/compiler-rt/lib/asan/lit_tests/malloc_hook.cc b/compiler-rt/lib/asan/lit_tests/malloc_hook.cc
new file mode 100644
index 00000000000..885fc6693fd
--- /dev/null
+++ b/compiler-rt/lib/asan/lit_tests/malloc_hook.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx_asan -O2 %s -o %t
+// RUN: %t 2>&1 | FileCheck %s
+#include <stdio.h>
+#include <stdlib.h>
+
+extern "C" {
+// Note: avoid calling functions that allocate memory in malloc/free
+// to avoid infinite recursion.
+void __asan_malloc_hook(void *ptr, size_t sz) { puts("MallocHook"); }
+void __asan_free_hook(void *ptr) { puts("FreeHook"); }
+} // extern "C"
+
+int main() {
+ volatile int *x = new int;
+ // CHECK: MallocHook
+ *x = 0;
+ delete x;
+ // CHECK: FreeHook
+ return 0;
+}
OpenPOWER on IntegriCloud