diff options
Diffstat (limited to 'test/sanitizer_common/TestCases')
36 files changed, 303 insertions, 61 deletions
diff --git a/test/sanitizer_common/TestCases/Darwin/print-stack-trace.cc b/test/sanitizer_common/TestCases/Darwin/print-stack-trace.cc new file mode 100644 index 0000000000000..715282fd76674 --- /dev/null +++ b/test/sanitizer_common/TestCases/Darwin/print-stack-trace.cc @@ -0,0 +1,19 @@ +// RUN: %clangxx -O0 %s -o %t && %env_tool_opts=stack_trace_format=DEFAULT %run %t 2>&1 | FileCheck %s +// RUN: %env_tool_opts=stack_trace_format='"frame:%n lineno:%l"' %run %t 2>&1 | FileCheck %s --check-prefix=CUSTOM + +#include <sanitizer/common_interface_defs.h> + +static inline void FooBarBaz() { + __sanitizer_print_stack_trace(); +} + +int main() { + FooBarBaz(); + return 0; +} +// CHECK: {{ #0 0x.* in __sanitizer_print_stack_trace}} +// CHECK: {{ #1 0x.* in FooBarBaz(\(\))? .*}}print-stack-trace.cc:[[@LINE-8]] +// CHECK: {{ #2 0x.* in main.*}}print-stack-trace.cc:[[@LINE-5]] + +// CUSTOM: frame:1 lineno:[[@LINE-11]] +// CUSTOM: frame:2 lineno:[[@LINE-8]] diff --git a/test/sanitizer_common/TestCases/Linux/abort_on_error.cc b/test/sanitizer_common/TestCases/Linux/abort_on_error.cc index a5ef665364788..e4b246e35f6a3 100644 --- a/test/sanitizer_common/TestCases/Linux/abort_on_error.cc +++ b/test/sanitizer_common/TestCases/Linux/abort_on_error.cc @@ -10,6 +10,9 @@ // lit doesn't set options anyway. // RUN: not %run %t 2>&1 +// Android needs abort_on_error=0 +// UNSUPPORTED: android + namespace __sanitizer { void Die(); } diff --git a/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc b/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc new file mode 100644 index 0000000000000..e17de1853eb36 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc @@ -0,0 +1,90 @@ +// Regression test for +// https://code.google.com/p/address-sanitizer/issues/detail?id=180 + +// clang-format off +// RUN: %clangxx -O0 %s -o %t + +// RUN: %env_tool_opts=handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0 +// RUN: %env_tool_opts=handle_segv=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 +// RUN: %env_tool_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 + +// RUN: %env_tool_opts=handle_segv=0:allow_user_segv_handler=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0 +// RUN: %env_tool_opts=handle_segv=1:allow_user_segv_handler=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 +// RUN: %env_tool_opts=handle_segv=2:allow_user_segv_handler=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 + +// RUN: %env_tool_opts=handle_segv=0:allow_user_segv_handler=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0 +// RUN: %env_tool_opts=handle_segv=1:allow_user_segv_handler=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 +// RUN: %env_tool_opts=handle_segv=2:allow_user_segv_handler=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 +// clang-format on + +// Flaky errors in debuggerd with "waitpid returned unexpected pid (0)" in logcat. +// UNSUPPORTED: android && i386-target-arch + +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> + +struct sigaction original_sigaction_sigbus; +struct sigaction original_sigaction_sigsegv; + +void User_OnSIGSEGV(int signum, siginfo_t *siginfo, void *context) { + fprintf(stderr, "User sigaction called\n"); + struct sigaction original_sigaction = {}; + if (signum == SIGBUS) + original_sigaction = original_sigaction_sigbus; + else if (signum == SIGSEGV) + original_sigaction = original_sigaction_sigsegv; + else { + printf("Invalid signum"); + exit(1); + } + if (original_sigaction.sa_flags | SA_SIGINFO) { + if (original_sigaction.sa_sigaction) + original_sigaction.sa_sigaction(signum, siginfo, context); + } else { + if (original_sigaction.sa_handler) + original_sigaction.sa_handler(signum); + } + exit(1); +} + +int DoSEGV() { + volatile int *x = 0; + return *x; +} + +bool InstallHandler(int signum, struct sigaction *original_sigaction) { + struct sigaction user_sigaction = {}; + user_sigaction.sa_sigaction = User_OnSIGSEGV; + user_sigaction.sa_flags = SA_SIGINFO; + if (sigaction(signum, &user_sigaction, original_sigaction)) { + perror("sigaction"); + return false; + } + return true; +} + +int main() { + // Let's install handlers for both SIGSEGV and SIGBUS, since pre-Yosemite + // 32-bit Darwin triggers SIGBUS instead. + if (InstallHandler(SIGSEGV, &original_sigaction_sigsegv) && + InstallHandler(SIGBUS, &original_sigaction_sigbus)) { + fprintf(stderr, "User sigaction installed\n"); + } + return DoSEGV(); +} + +// CHECK0-NOT: Sanitizer:DEADLYSIGNAL +// CHECK0-NOT: Sanitizer: SEGV on unknown address +// CHECK0: User sigaction installed +// CHECK0-NEXT: User sigaction called + +// CHECK1: User sigaction installed +// CHECK1-NEXT: User sigaction called +// CHECK1-NEXT: Sanitizer:DEADLYSIGNAL +// CHECK1: Sanitizer: SEGV on unknown address + +// CHECK2-NOT: User sigaction called +// CHECK2: User sigaction installed +// CHECK2-NEXT: Sanitizer:DEADLYSIGNAL +// CHECK2: Sanitizer: SEGV on unknown address diff --git a/test/sanitizer_common/TestCases/Linux/assert.cc b/test/sanitizer_common/TestCases/Linux/assert.cc index 5d58ea4f7e818..9c5263f8e776a 100644 --- a/test/sanitizer_common/TestCases/Linux/assert.cc +++ b/test/sanitizer_common/TestCases/Linux/assert.cc @@ -1,12 +1,12 @@ // Test the handle_abort option. -// RUN: %clang %s -o %t + +// clang-format off +// RUN: %clangxx %s -o %t // RUN: not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s // RUN: %env_tool_opts=handle_abort=0 not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s // RUN: %env_tool_opts=handle_abort=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 +// clang-format on + #include <assert.h> #include <stdio.h> #include <sanitizer/asan_interface.h> @@ -19,6 +19,9 @@ int main(int argc, char **argv) { __sanitizer_set_death_callback(death); assert(argc == 100); } -// CHECK1: ERROR: {{.*}}Sanitizer: + +// CHECK0-NOT: Sanitizer:DEADLYSIGNAL +// CHECK1: ERROR: {{.*}}Sanitizer: ABRT +// CHECK1: {{ #0 }} // CHECK1: DEATH CALLBACK // CHECK0-NOT: Sanitizer diff --git a/test/sanitizer_common/TestCases/Linux/decorate_proc_maps.cc b/test/sanitizer_common/TestCases/Linux/decorate_proc_maps.cc index 36d4df567ee7c..8a05f4b66868e 100644 --- a/test/sanitizer_common/TestCases/Linux/decorate_proc_maps.cc +++ b/test/sanitizer_common/TestCases/Linux/decorate_proc_maps.cc @@ -1,6 +1,9 @@ // RUN: %clangxx -g %s -o %t // RUN: %env_tool_opts=decorate_proc_maps=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%tool_name + // REQUIRES: stable-runtime +// XFAIL: android && asan + #include <errno.h> #include <fcntl.h> #include <pthread.h> @@ -57,5 +60,6 @@ int main(void) { // CHECK-tsan: rw-p {{.*}} [trace 1] // CHECK-tsan: rw-p {{.*}} [trace header 1] -// Nothing interesting with standalone LSan. +// Nothing interesting with standalone LSan and UBSan. // CHECK-lsan: decorate_proc_maps +// CHECK-ubsan: decorate_proc_maps diff --git a/test/sanitizer_common/TestCases/Linux/deepbind.cc b/test/sanitizer_common/TestCases/Linux/deepbind.cc index fc810ad039f47..81150fae977e0 100644 --- a/test/sanitizer_common/TestCases/Linux/deepbind.cc +++ b/test/sanitizer_common/TestCases/Linux/deepbind.cc @@ -1,5 +1,5 @@ // RUN: %clangxx %s -o %t && %run not %t 1 2>&1 | FileCheck %s -// UNSUPPORTED: lsan, android +// UNSUPPORTED: lsan,ubsan,android #include <dlfcn.h> #include <stdio.h> diff --git a/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc b/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc index 5bee1fb4bc93e..c0d6cfea1fbef 100644 --- a/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc +++ b/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc @@ -1,8 +1,6 @@ // Regression test for a crash in getpwnam_r and similar interceptors. // RUN: %clangxx -O0 -g %s -o %t && %run %t -// XFAIL: mips - #include <assert.h> #include <errno.h> #include <pwd.h> diff --git a/test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc b/test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc index d4a60a0d37315..3c875c1793dff 100644 --- a/test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc +++ b/test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc @@ -14,6 +14,7 @@ // XFAIL: lsan // XFAIL: tsan // XFAIL: msan +// XFAIL: ubsan #include <string.h> #include <stdio.h> @@ -26,7 +27,10 @@ volatile char *sink[kNumAllocs]; int main(int argc, char **argv) { for (int i = 0; i < kNumAllocs; i++) { if ((i % 1000) == 0) { - fprintf(stderr, "[%d]\n", i); + // Don't write to stderr! Doing that triggers a kernel race condition + // between this thread and the rss-limit thread, and may lose part of the + // output. See https://lkml.org/lkml/2014/2/17/324. + printf("[%d]\n", i); } char *x = new char[kAllocSize]; memset(x, 0, kAllocSize); diff --git a/test/sanitizer_common/TestCases/Linux/iconv_test.c b/test/sanitizer_common/TestCases/Linux/iconv_test.c index 08da34d89a3c4..eb995d21c3434 100644 --- a/test/sanitizer_common/TestCases/Linux/iconv_test.c +++ b/test/sanitizer_common/TestCases/Linux/iconv_test.c @@ -1,6 +1,9 @@ // RUN: %clang %s -o %t && %run %t // Verify that even if iconv returned -1 // we still treat the initialized part of outbuf as properly initialized. + +// UNSUPPORTED: android + #include <iconv.h> #include <assert.h> #include <stdio.h> diff --git a/test/sanitizer_common/TestCases/Linux/ill.cc b/test/sanitizer_common/TestCases/Linux/ill.cc index 2c69618ad7cbd..43f7a7830495f 100644 --- a/test/sanitizer_common/TestCases/Linux/ill.cc +++ b/test/sanitizer_common/TestCases/Linux/ill.cc @@ -1,13 +1,12 @@ // Test the handle_sigill option. -// RUN: %clang %s -o %t -O1 + +// clang-format off +// RUN: %clangxx %s -o %t -O1 // RUN: not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s // RUN: %env_tool_opts=handle_sigill=0 not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s // RUN: %env_tool_opts=handle_sigill=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 -// +// clang-format on + // FIXME: seems to fail on ARM // REQUIRES: x86_64-target-arch #include <assert.h> @@ -22,6 +21,9 @@ int main(int argc, char **argv) { __sanitizer_set_death_callback(death); __builtin_trap(); } -// CHECK1: ERROR: {{.*}}Sanitizer: + +// CHECK0-NOT: Sanitizer:DEADLYSIGNAL +// CHECK1: ERROR: {{.*}}Sanitizer: ILL +// CHECK1: {{#[0-9]+.* main .*ill\.cc:[0-9]+}} // CHECK1: DEATH CALLBACK // CHECK0-NOT: Sanitizer diff --git a/test/sanitizer_common/TestCases/Linux/mlock_test.cc b/test/sanitizer_common/TestCases/Linux/mlock_test.cc index 69ea7cb91c4fc..a952922aaabc8 100644 --- a/test/sanitizer_common/TestCases/Linux/mlock_test.cc +++ b/test/sanitizer_common/TestCases/Linux/mlock_test.cc @@ -1,5 +1,5 @@ // RUN: %clang %s -o %t && %run %t -// XFAIL: lsan +// XFAIL: ubsan,lsan #include <assert.h> #include <sys/mman.h> diff --git a/test/sanitizer_common/TestCases/Linux/mprobe.cc b/test/sanitizer_common/TestCases/Linux/mprobe.cc index 57e5ba5a6c747..82c0faf0e2add 100644 --- a/test/sanitizer_common/TestCases/Linux/mprobe.cc +++ b/test/sanitizer_common/TestCases/Linux/mprobe.cc @@ -1,5 +1,5 @@ // RUN: %clangxx %s -o %t && %run %t 2>&1 | FileCheck %s -// UNSUPPORTED: android +// UNSUPPORTED: android, ubsan #include <stdio.h> #include <stdlib.h> diff --git a/test/sanitizer_common/TestCases/Linux/ptrace.cc b/test/sanitizer_common/TestCases/Linux/ptrace.cc index b10aecd3579d6..82532c35fab5e 100644 --- a/test/sanitizer_common/TestCases/Linux/ptrace.cc +++ b/test/sanitizer_common/TestCases/Linux/ptrace.cc @@ -1,5 +1,7 @@ // RUN: %clangxx -O0 %s -o %t && %run %t +// UNSUPPORTED: android + #include <assert.h> #include <signal.h> #include <stdio.h> diff --git a/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cc b/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cc index b7e8721a1b9e3..d623ccabb5b55 100644 --- a/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cc +++ b/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cc @@ -1,7 +1,7 @@ // RUN: %clangxx -O0 -g %s -lutil -o %t && %run %t // This test depends on the glibc layout of struct sem_t and checks that we // don't leave sem_t::private uninitialized. -// UNSUPPORTED: android, lsan-x86 +// UNSUPPORTED: android, lsan-x86, ubsan, target-is-mips64, target-is-mips64el #include <features.h> #include <assert.h> #include <semaphore.h> diff --git a/test/sanitizer_common/TestCases/Linux/signal_segv_handler.cc b/test/sanitizer_common/TestCases/Linux/signal_segv_handler.cc index 51e8bdb6e95db..d6c3ecbff4756 100644 --- a/test/sanitizer_common/TestCases/Linux/signal_segv_handler.cc +++ b/test/sanitizer_common/TestCases/Linux/signal_segv_handler.cc @@ -1,4 +1,6 @@ -// RUN: %clangxx -O1 %s -o %t && TSAN_OPTIONS="flush_memory_ms=1 memory_limit_mb=1" ASAN_OPTIONS="handle_segv=0" %run %t 2>&1 | FileCheck %s +// clang-format off +// RUN: %clangxx -O1 %s -o %t && TSAN_OPTIONS="flush_memory_ms=1 memory_limit_mb=1" %run %t 2>&1 | FileCheck %s +// clang-format on // JVM uses SEGV to preempt threads. All threads do a load from a known address // periodically. When runtime needs to preempt threads, it unmaps the page. @@ -13,11 +15,12 @@ // "benign" SEGVs that are handled by signal handler, and ensures that // the process survive. +#include <assert.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> -#include <signal.h> -#include <sys/mman.h> #include <string.h> +#include <sys/mman.h> #include <unistd.h> unsigned long page_size; @@ -35,6 +38,12 @@ int main() { a.sa_sigaction = handler; a.sa_flags = SA_SIGINFO; sigaction(SIGSEGV, &a, &old); + + memset(&a, 0, sizeof(a)); + sigaction(SIGSEGV, 0, &a); + assert(a.sa_sigaction == handler); + assert(a.sa_flags & SA_SIGINFO); + guard = mmap(0, 3 * page_size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); guard = (char*)guard + page_size; // work around a kernel bug for (int i = 0; i < 1000000; i++) { diff --git a/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc b/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc index 83570a9f13a44..2ee809547530f 100644 --- a/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc +++ b/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc @@ -14,6 +14,7 @@ // XFAIL: lsan // XFAIL: tsan // XFAIL: msan +// XFAIL: ubsan #include <stdlib.h> #include <stdio.h> #include <string.h> diff --git a/test/sanitizer_common/TestCases/Linux/sysconf_interceptor_bypass_test.cc b/test/sanitizer_common/TestCases/Linux/sysconf_interceptor_bypass_test.cc index eb4deace060ce..c3a6560228972 100644 --- a/test/sanitizer_common/TestCases/Linux/sysconf_interceptor_bypass_test.cc +++ b/test/sanitizer_common/TestCases/Linux/sysconf_interceptor_bypass_test.cc @@ -1,5 +1,7 @@ // RUN: %clangxx -O2 %s -o %t && %run %t 2>&1 | FileCheck %s +// XFAIL: android + #include <stdio.h> // getauxval() used instead of sysconf() in GetPageSize() is defined starting diff --git a/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc b/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc index f48cce8ea22b0..641495508ba10 100644 --- a/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc +++ b/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc @@ -1,6 +1,7 @@ // RUN: %clang -w -O0 %s -o %t && %run %t 2>&1 | FileCheck %s // UNSUPPORTED: lsan // UNSUPPORTED: msan +// UNSUPPORTED: ubsan #include <stdio.h> int main() { int a; diff --git a/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc b/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc index 261295790836f..d9a1bc66082c3 100644 --- a/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc +++ b/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc @@ -7,10 +7,6 @@ // RUN: env %tool_options='abort_on_error=0, dedup_token_length=3' not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3 --match-full-lines // REQUIRES: stable-runtime -// FIXME: implement SEGV handler in other sanitizers, not just asan. -// XFAIL: msan -// XFAIL: lsan -// XFAIL: tsan volatile int *null = 0; diff --git a/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc b/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc new file mode 100644 index 0000000000000..87e797a00ae13 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc @@ -0,0 +1,23 @@ +// Check that sanitizer prints the faulting instruction bytes on +// dump_instruction_bytes=1 + +// clang-format off +// RUN: %clangxx %s -o %t +// RUN: %env_tool_opts=dump_instruction_bytes=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-DUMP +// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NODUMP +// clang-format on + +// REQUIRES: x86-target-arch + +int main() { +#if defined(__x86_64__) + asm("movq $0, %rax"); + asm("movl $0xcafebabe, 0x0(%rax)"); +#elif defined(i386) + asm("movl $0, %eax"); + asm("movl $0xcafebabe, 0x0(%eax)"); +#endif + // CHECK-DUMP: First 16 instruction bytes at pc: c7 00 be ba fe ca + // CHECK-NODUMP-NOT: First 16 instruction bytes + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/dump_registers.cc b/test/sanitizer_common/TestCases/Posix/dump_registers.cc new file mode 100644 index 0000000000000..07e87bedc131c --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/dump_registers.cc @@ -0,0 +1,20 @@ +// Check that sanitizer prints registers dump_registers on dump_registers=1 +// RUN: %clangxx %s -o %t +// RUN: %env_tool_opts=dump_registers=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NODUMP +// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-DUMP +// +// FIXME: Implement. +// UNSUPPORTED: asan +// UNSUPPORTED: lsan +// UNSUPPORTED: msan +// UNSUPPORTED: tsan +// UNSUPPORTED: ubsan + +#include <signal.h> + +int main() { + raise(SIGSEGV); + // CHECK-DUMP: Register values + // CHECK-NODUMP-NOT: Register values + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/fpe.cc b/test/sanitizer_common/TestCases/Posix/fpe.cc index 9a6f808a5cd79..c1e785a7ae828 100644 --- a/test/sanitizer_common/TestCases/Posix/fpe.cc +++ b/test/sanitizer_common/TestCases/Posix/fpe.cc @@ -1,13 +1,9 @@ // Test the handle_sigfpe option. -// RUN: %clang %s -o %t +// RUN: %clangxx %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> @@ -25,6 +21,9 @@ int main(int argc, char **argv) { volatile int sink; sink = one / zero; } -// CHECK1: ERROR: {{.*}}Sanitizer: + +// CHECK0-NOT: Sanitizer:DEADLYSIGNAL +// CHECK1: ERROR: {{.*}}Sanitizer: FPE +// CHECK1: {{#[0-9]+.* main .*fpe\.cc}}:[[@LINE-5]] // CHECK1: DEATH CALLBACK // CHECK0-NOT: Sanitizer diff --git a/test/sanitizer_common/TestCases/Posix/getpass.cc b/test/sanitizer_common/TestCases/Posix/getpass.cc index 251f9119d6828..b91a3d7d5264f 100644 --- a/test/sanitizer_common/TestCases/Posix/getpass.cc +++ b/test/sanitizer_common/TestCases/Posix/getpass.cc @@ -1,5 +1,8 @@ // RUN: %clangxx -O0 -g %s -lutil -o %t && %run %t | FileCheck %s + // REQUIRES: stable-runtime +// XFAIL: android && asan + #include <assert.h> #include <stdio.h> #include <unistd.h> 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 12a56c73e0498..8d2db364114ac 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 @@ -8,6 +8,7 @@ // 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 +// XFAIL: ubsan #include <sanitizer/common_interface_defs.h> #include <stdio.h> diff --git a/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc b/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc index af7eea1d7de2d..cc7de193f0a41 100644 --- a/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc +++ b/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc @@ -5,10 +5,7 @@ // RUN: not %run %t %t-out && FileCheck < %t-out %s // REQUIRES: stable-runtime -// FIXME: implement SEGV handler in other sanitizers, not just asan. -// XFAIL: msan -// XFAIL: lsan -// XFAIL: tsan +// XFAIL: android && asan #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 index d5667649bb9c4..9176a524dbe89 100644 --- a/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc +++ b/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc @@ -4,6 +4,7 @@ // Hooks are not implemented for lsan. // XFAIL: lsan +// XFAIL: ubsan #include <string.h> #include <assert.h> diff --git a/test/sanitizer_common/TestCases/corelimit.cc b/test/sanitizer_common/TestCases/corelimit.cc index 0a86e5b7b7fe5..eb02afc01a1ba 100644 --- a/test/sanitizer_common/TestCases/corelimit.cc +++ b/test/sanitizer_common/TestCases/corelimit.cc @@ -1,5 +1,5 @@ // RUN: %clangxx -O0 %s -o %t && %run %t -// UNSUPPORTED: lsan +// UNSUPPORTED: lsan,ubsan #include <assert.h> #include <sys/time.h> diff --git a/test/sanitizer_common/TestCases/get_module_and_offset_for_pc.cc b/test/sanitizer_common/TestCases/get_module_and_offset_for_pc.cc index f5a18e6721cf5..69ccb7234fabc 100644 --- a/test/sanitizer_common/TestCases/get_module_and_offset_for_pc.cc +++ b/test/sanitizer_common/TestCases/get_module_and_offset_for_pc.cc @@ -1,8 +1,10 @@ // RUN: %clangxx -DSHARED %s -shared -o %T/get_module_and_offset_for_pc.so -fPIC // RUN: %clangxx -DSO_DIR=\"%T\" -O0 %s -ldl -o %t // RUN: %run %t 2>&1 | FileCheck %s + // UNSUPPORTED: i386-darwin -// +// XFAIL: android + // Tests __sanitizer_get_module_and_offset_for_pc. #include <assert.h> diff --git a/test/sanitizer_common/TestCases/malloc_hook.cc b/test/sanitizer_common/TestCases/malloc_hook.cc index 59cd620b3f634..853bb66ac5c4d 100644 --- a/test/sanitizer_common/TestCases/malloc_hook.cc +++ b/test/sanitizer_common/TestCases/malloc_hook.cc @@ -2,6 +2,7 @@ // Malloc/free hooks are not supported on Windows. // XFAIL: win32 +// XFAIL: ubsan #include <stdlib.h> #include <unistd.h> diff --git a/test/sanitizer_common/TestCases/options-include.cc b/test/sanitizer_common/TestCases/options-include.cc index 5b0b6d52585ac..3d9127b7f23dc 100644 --- a/test/sanitizer_common/TestCases/options-include.cc +++ b/test/sanitizer_common/TestCases/options-include.cc @@ -34,6 +34,8 @@ // RUN: %env_tool_opts=include_if_exists='"%t.options-not-found.%b"' %run %t 2>&1 | tee %t.out // RUN: FileCheck %s --check-prefix=CHECK-WITHOUT-HELP --check-prefix=CHECK-FOUND < %t.out +// Android tests run on remote device so includes will not work. +// UNSUPPORTED: android #include <stdio.h> diff --git a/test/sanitizer_common/TestCases/print-stack-trace.cc b/test/sanitizer_common/TestCases/print-stack-trace.cc index 0055b279666e5..fce8503663af8 100644 --- a/test/sanitizer_common/TestCases/print-stack-trace.cc +++ b/test/sanitizer_common/TestCases/print-stack-trace.cc @@ -1,8 +1,10 @@ // RUN: %clangxx -O0 %s -o %t && %env_tool_opts=stack_trace_format=DEFAULT %run %t 2>&1 | FileCheck %s // RUN: %clangxx -O3 %s -o %t && %env_tool_opts=stack_trace_format=DEFAULT %run %t 2>&1 | FileCheck %s -// RUN: %env_tool_opts=stack_trace_format='"frame:%n lineno:%l"' %run %t 2>&1 | FileCheck %s --check-prefix=CUSTOM +// RUN: %env_tool_opts=stack_trace_format=frame%n_lineno%l %run %t 2>&1 | FileCheck %s --check-prefix=CUSTOM // RUN: %env_tool_opts=symbolize_inline_frames=false:stack_trace_format=DEFAULT %run %t 2>&1 | FileCheck %s --check-prefix=NOINLINE +// UNSUPPORTED: darwin + #include <sanitizer/common_interface_defs.h> static inline void FooBarBaz() { @@ -17,8 +19,8 @@ int main() { // CHECK: {{ #1 0x.* in FooBarBaz(\(\))? .*}}print-stack-trace.cc:[[@LINE-8]] // CHECK: {{ #2 0x.* in main.*}}print-stack-trace.cc:[[@LINE-5]] -// CUSTOM: frame:1 lineno:[[@LINE-11]] -// CUSTOM: frame:2 lineno:[[@LINE-8]] +// CUSTOM: frame1_lineno[[@LINE-11]] +// CUSTOM: frame2_lineno[[@LINE-8]] // NOINLINE: #0 0x{{.*}} in __sanitizer_print_stack_trace // NOINLINE: #1 0x{{.*}} in main{{.*}}print-stack-trace.cc:[[@LINE-15]] diff --git a/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter.cc b/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter.cc index b7246ebf27510..58a64d1a92dc8 100644 --- a/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter.cc +++ b/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter.cc @@ -1,11 +1,14 @@ -// Tests -fsanitize-coverage=inline-8bit-counters +// Tests -fsanitize-coverage=inline-8bit-counters,pc-table // // REQUIRES: has_sancovcc,stable-runtime // UNSUPPORTED: i386-darwin // -// RUN: %clangxx -O0 %s -fsanitize-coverage=inline-8bit-counters 2>&1 +// RUN: %clangxx -O0 %s -fsanitize-coverage=inline-8bit-counters,pc-table -o %t +// RUN: %run %t 2>&1 | FileCheck %s +// XFAIL: tsan #include <stdio.h> +#include <stdint.h> #include <assert.h> const char *first_counter; @@ -17,7 +20,24 @@ void __sanitizer_cov_8bit_counters_init(const char *start, const char *end) { first_counter = start; } +uintptr_t FirstPC; +uintptr_t FirstPCFlag; + +extern "C" void __sanitizer_cov_pcs_init(const uintptr_t *pcs_beg, + const uintptr_t *pcs_end) { + const uintptr_t *B = (const uintptr_t *)pcs_beg; + const uintptr_t *E = (const uintptr_t *)pcs_end; + assert(B + 1 < E); + FirstPC = B[0]; + FirstPCFlag = B[1]; +} + + int main() { assert(first_counter); assert(*first_counter == 1); + assert(FirstPC == (uintptr_t)&main); + assert(FirstPCFlag == 1); + fprintf(stderr, "PASS\n"); + // CHECK: PASS } diff --git a/test/sanitizer_common/TestCases/sanitizer_coverage_no_prune.cc b/test/sanitizer_common/TestCases/sanitizer_coverage_no_prune.cc index 8751930345e55..9604da222f8e9 100644 --- a/test/sanitizer_common/TestCases/sanitizer_coverage_no_prune.cc +++ b/test/sanitizer_common/TestCases/sanitizer_coverage_no_prune.cc @@ -1,9 +1,10 @@ // Tests -fsanitize-coverage=no-prune -// + // REQUIRES: has_sancovcc,stable-runtime // UNSUPPORTED: i386-darwin -// XFAIL: tsan -// +// XFAIL: ubsan,tsan +// XFAIL: android && asan + // RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=trace-pc,bb,no-prune 2>&1 | grep "call void @__sanitizer_cov_trace_pc" | count 3 // RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=trace-pc,bb 2>&1 | grep "call void @__sanitizer_cov_trace_pc" | count 2 // RUN: %clangxx -O0 %s -S -o - -emit-llvm -fsanitize-coverage=trace-pc,no-prune 2>&1 | grep "call void @__sanitizer_cov_trace_pc" | count 4 diff --git a/test/sanitizer_common/TestCases/sanitizer_coverage_stack_depth.cc b/test/sanitizer_common/TestCases/sanitizer_coverage_stack_depth.cc new file mode 100644 index 0000000000000..90959ef5b0287 --- /dev/null +++ b/test/sanitizer_common/TestCases/sanitizer_coverage_stack_depth.cc @@ -0,0 +1,32 @@ +// Tests -fsanitize-coverage=stack-depth +// +// XFAIL: tsan +// +// RUN: %clangxx -O0 -std=c++11 -fsanitize-coverage=stack-depth %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not Assertion{{.*}}failed +// RUN: %clangxx -O0 -std=c++11 -fsanitize-coverage=trace-pc-guard,stack-depth \ +// RUN: %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not Assertion{{.*}}failed + +#include <cstdint> +#include <cstdio> +#include <cassert> + +thread_local uintptr_t __sancov_lowest_stack; +uintptr_t last_stack; + +void foo(int recurse) { + assert(__sancov_lowest_stack < last_stack); + last_stack = __sancov_lowest_stack; + if (recurse <= 0) return; + foo(recurse - 1); +} + +int main() { + last_stack = __sancov_lowest_stack; + foo(100); + printf("Success!\n"); + return 0; +} + +// CHECK: Success! diff --git a/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-dso.cc b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-dso.cc index 6185177a169a4..7a2eca8bcd90a 100644 --- a/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-dso.cc +++ b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-dso.cc @@ -1,8 +1,10 @@ // Tests trace pc guard coverage collection. -// + // REQUIRES: has_sancovcc,stable-runtime +// UNSUPPORTED: ubsan // XFAIL: tsan,darwin,powerpc64,s390x,mips -// +// XFAIL: android && asan + // RUN: DIR=%t_workdir // RUN: CLANG_ARGS="-O0 -fsanitize-coverage=trace-pc-guard" // RUN: rm -rf $DIR @@ -68,5 +70,5 @@ int baz() { // // CHECK-SANCOV: Ignoring {{.*}}_1.so and its coverage because __sanitizer_cov* functions were not found. // CHECK-SANCOV: Ignoring {{.*}}_2.so and its coverage because __sanitizer_cov* functions were not found. -// CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard-dso.cc:29 foo -// CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard-dso.cc:34 main +// CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard-dso.cc:[[@LINE-42]] foo +// CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard-dso.cc:[[@LINE-38]] main diff --git a/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc index 2d6d00b6a0cdb..1adbf653bb76c 100644 --- a/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc +++ b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc @@ -1,9 +1,10 @@ // Tests trace pc guard coverage collection. -// + // REQUIRES: has_sancovcc,stable-runtime -// UNSUPPORTED: i386-darwin +// UNSUPPORTED: ubsan,i386-darwin // XFAIL: tsan,powerpc64,s390x,mips -// +// XFAIL: android && asan + // RUN: DIR=%t_workdir // RUN: rm -rf $DIR // RUN: mkdir -p $DIR @@ -15,9 +16,7 @@ // RUN: %env_tool_opts=coverage=0 %t 2>&1 | FileCheck --check-prefix=CHECK-NOCOV %s // RUN: rm -rf $DIR // Make some room to stabilize line numbers -// -// -// + #include <stdio.h> int foo() { @@ -36,7 +35,7 @@ int main() { // CHECK-NEXT: foo // CHECK-NEXT: SanitizerCoverage: ./sanitizer_coverage_trace_pc_guard.{{.*}}.sancov: 2 PCs written // -// CHECK-SANCOV: sanitizer_coverage_trace_pc_guard.cc:23 foo -// CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard.cc:28 main +// CHECK-SANCOV: sanitizer_coverage_trace_pc_guard.cc:[[@LINE-16]] foo +// CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard.cc:[[@LINE-12]] main // // CHECK-NOCOV-NOT: SanitizerCoverage |