aboutsummaryrefslogtreecommitdiff
path: root/test/sanitizer_common/TestCases/Posix
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-04-16 16:02:53 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-04-16 16:02:53 +0000
commitab0bf875a5f328a6710f4e48258979ae1bc8da1c (patch)
tree66903cf9f73151825893dcc216b04c0930317a10 /test/sanitizer_common/TestCases/Posix
parentabacad30a54c59ad437ccf54ec5236a8dd7f3ba9 (diff)
downloadsrc-ab0bf875a5f328a6710f4e48258979ae1bc8da1c.tar.gz
src-ab0bf875a5f328a6710f4e48258979ae1bc8da1c.zip
Vendor import of compiler-rt trunk r300422:vendor/compiler-rt/compiler-rt-trunk-r300422
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=317021 svn path=/vendor/compiler-rt/compiler-rt-trunk-r300422/; revision=317022; tag=vendor/compiler-rt/compiler-rt-trunk-r300422
Diffstat (limited to 'test/sanitizer_common/TestCases/Posix')
-rw-r--r--test/sanitizer_common/TestCases/Posix/fpe.cc30
-rw-r--r--test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc7
-rw-r--r--test/sanitizer_common/TestCases/Posix/weak_hook_test.cc82
3 files changed, 119 insertions, 0 deletions
diff --git a/test/sanitizer_common/TestCases/Posix/fpe.cc b/test/sanitizer_common/TestCases/Posix/fpe.cc
new file mode 100644
index 000000000000..9a6f808a5cd7
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Posix/fpe.cc
@@ -0,0 +1,30 @@
+// Test the handle_sigfpe option.
+// RUN: %clang %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s
+// RUN: %env_tool_opts=handle_sigfpe=0 not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s
+// RUN: %env_tool_opts=handle_sigfpe=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s
+// FIXME: implement in other sanitizers, not just asan.
+// XFAIL: msan
+// XFAIL: lsan
+// XFAIL: tsan
+//
+// FIXME: seems to fail on ARM
+// REQUIRES: x86_64-target-arch
+#include <assert.h>
+#include <stdio.h>
+#include <sanitizer/asan_interface.h>
+
+void death() {
+ fprintf(stderr, "DEATH CALLBACK\n");
+}
+
+int main(int argc, char **argv) {
+ __sanitizer_set_death_callback(death);
+ volatile int one = 1;
+ volatile int zero = 0;
+ volatile int sink;
+ sink = one / zero;
+}
+// CHECK1: ERROR: {{.*}}Sanitizer:
+// CHECK1: DEATH CALLBACK
+// CHECK0-NOT: Sanitizer
diff --git a/test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc b/test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc
index fdb68c0cdea5..12a56c73e049 100644
--- a/test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc
+++ b/test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc
@@ -2,6 +2,13 @@
// REQUIRES: stable-runtime
+// For standalone LSan on x86 we have a problem: compiler spills the address
+// of allocated at line 42 memory thus memory block allocated in Leak() function
+// ends up to be classified as reachable despite the fact we zero out 'sink' at
+// the last line of main function. The problem doesn't reproduce with ASan because
+// quarantine prohibits memory block reuse for different allocations.
+// XFAIL: lsan-x86
+
#include <sanitizer/common_interface_defs.h>
#include <stdio.h>
diff --git a/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc b/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc
new file mode 100644
index 000000000000..d5667649bb9c
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc
@@ -0,0 +1,82 @@
+// Test the weak hooks.
+// RUN: %clangxx %s -o %t
+// RUN: %run %t
+
+// Hooks are not implemented for lsan.
+// XFAIL: lsan
+
+#include <string.h>
+#include <assert.h>
+
+bool seen_memcmp, seen_strncmp, seen_strncasecmp, seen_strcmp, seen_strcasecmp,
+ seen_strstr, seen_strcasestr, seen_memmem;
+
+extern "C" {
+void __sanitizer_weak_hook_memcmp(void *called_pc, const void *s1,
+ const void *s2, size_t n, int result) {
+ seen_memcmp = true;
+}
+void __sanitizer_weak_hook_strncmp(void *called_pc, const char *s1,
+ const char *s2, size_t n, int result) {
+ seen_strncmp = true;
+}
+void __sanitizer_weak_hook_strncasecmp(void *called_pc, const char *s1,
+ const char *s2, size_t n, int result){
+ seen_strncasecmp = true;
+}
+void __sanitizer_weak_hook_strcmp(void *called_pc, const char *s1,
+ const char *s2, int result){
+ seen_strcmp = true;
+}
+void __sanitizer_weak_hook_strcasecmp(void *called_pc, const char *s1,
+ const char *s2, int result){
+ seen_strcasecmp = true;
+}
+void __sanitizer_weak_hook_strstr(void *called_pc, const char *s1,
+ const char *s2, char *result){
+ seen_strstr = true;
+}
+void __sanitizer_weak_hook_strcasestr(void *called_pc, const char *s1,
+ const char *s2, char *result){
+ seen_strcasestr = true;
+}
+void __sanitizer_weak_hook_memmem(void *called_pc, const void *s1, size_t len1,
+ const void *s2, size_t len2, void *result){
+ seen_memmem = true;
+}
+} // extern "C"
+
+char s1[] = "ABCDEF";
+char s2[] = "CDE";
+
+static volatile int int_sink;
+static volatile void *ptr_sink;
+
+int main() {
+ assert(sizeof(s2) < sizeof(s1));
+
+ int_sink = memcmp(s1, s2, sizeof(s2));
+ assert(seen_memcmp);
+
+ int_sink = strncmp(s1, s2, sizeof(s2));
+ assert(seen_strncmp);
+
+ int_sink = strncasecmp(s1, s2, sizeof(s2));
+ assert(seen_strncasecmp);
+
+ int_sink = strcmp(s1, s2);
+ assert(seen_strcmp);
+
+ int_sink = strcasecmp(s1, s2);
+ assert(seen_strcasecmp);
+
+ ptr_sink = strstr(s1, s2);
+ assert(seen_strstr);
+
+ ptr_sink = strcasestr(s1, s2);
+ assert(seen_strcasestr);
+
+ ptr_sink = memmem(s1, sizeof(s1), s2, sizeof(s2));
+ assert(seen_memmem);
+ return 0;
+}