aboutsummaryrefslogtreecommitdiff
path: root/lib/asan/lit_tests/malloc_hook.cc
diff options
context:
space:
mode:
authorAndrew Turner <andrew@FreeBSD.org>2013-01-18 20:06:45 +0000
committerAndrew Turner <andrew@FreeBSD.org>2013-01-18 20:06:45 +0000
commit58aabf08b77d221489f10e274812ec60917c21a8 (patch)
treeb946f82269be87d83f086167c762c362e734c5bb /lib/asan/lit_tests/malloc_hook.cc
parent37dfff057418e02f8e5322da12684dd927e3d881 (diff)
downloadsrc-vendor/compiler-rt/compiler-rt-r172839.tar.gz
src-vendor/compiler-rt/compiler-rt-r172839.zip
Import compiler-rt r172839.vendor/compiler-rt/compiler-rt-r172839
Diffstat (limited to 'lib/asan/lit_tests/malloc_hook.cc')
-rw-r--r--lib/asan/lit_tests/malloc_hook.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/asan/lit_tests/malloc_hook.cc b/lib/asan/lit_tests/malloc_hook.cc
new file mode 100644
index 000000000000..6435d105ee26
--- /dev/null
+++ b/lib/asan/lit_tests/malloc_hook.cc
@@ -0,0 +1,24 @@
+// RUN: %clangxx_asan -O2 %s -o %t
+// RUN: %t 2>&1 | FileCheck %s
+#include <stdlib.h>
+#include <unistd.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) {
+ write(1, "MallocHook\n", sizeof("MallocHook\n"));
+}
+void __asan_free_hook(void *ptr) {
+ write(1, "FreeHook\n", sizeof("FreeHook\n"));
+}
+} // extern "C"
+
+int main() {
+ volatile int *x = new int;
+ // CHECK: MallocHook
+ *x = 0;
+ delete x;
+ // CHECK: FreeHook
+ return 0;
+}