summaryrefslogtreecommitdiff
path: root/test/asan/TestCases
diff options
context:
space:
mode:
Diffstat (limited to 'test/asan/TestCases')
-rw-r--r--test/asan/TestCases/Darwin/asan-symbolize-with-module-map.cc31
-rw-r--r--test/asan/TestCases/Linux/asan-asm-stacktrace-test.cc33
-rw-r--r--test/asan/TestCases/Linux/bzero.cc15
-rw-r--r--test/asan/TestCases/Linux/swapcontext_annotation.cc3
-rw-r--r--test/asan/TestCases/Linux/swapcontext_test.cc3
-rw-r--r--test/asan/TestCases/Linux/unpoison_tls.cc2
-rw-r--r--test/asan/TestCases/Linux/vfork.cc31
-rw-r--r--test/asan/TestCases/Posix/asan_symbolize_script/logging_options_in_help.cc5
-rw-r--r--test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op.py17
-rw-r--r--test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op_help_output.cc7
-rw-r--r--test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op_symbolicate.cc24
-rw-r--r--test/asan/TestCases/Posix/asan_symbolize_script/set_log_dest.cc3
-rw-r--r--test/asan/TestCases/Posix/asan_symbolize_script/set_log_level.cc8
-rw-r--r--test/asan/TestCases/Posix/bcmp_test.cc18
-rw-r--r--test/asan/TestCases/Posix/start-deactivated.cc1
-rw-r--r--test/asan/TestCases/Posix/wcrtomb.c16
-rw-r--r--test/asan/TestCases/Windows/dll_intercept_memcpy.cc4
-rw-r--r--test/asan/TestCases/Windows/dll_intercept_memset.cc4
-rw-r--r--test/asan/TestCases/Windows/heaprealloc_zero_size.cc21
-rw-r--r--test/asan/TestCases/Windows/recalloc_sanity.cc37
-rw-r--r--test/asan/TestCases/memcmp_test.cc4
21 files changed, 244 insertions, 43 deletions
diff --git a/test/asan/TestCases/Darwin/asan-symbolize-with-module-map.cc b/test/asan/TestCases/Darwin/asan-symbolize-with-module-map.cc
new file mode 100644
index 000000000..4557adeb0
--- /dev/null
+++ b/test/asan/TestCases/Darwin/asan-symbolize-with-module-map.cc
@@ -0,0 +1,31 @@
+// UNSUPPORTED: ios
+// RUN: %clangxx_asan -O0 -g %s -o %t.executable
+
+// Deliberately don't produce the module map and then check that offline symbolization fails
+// when we try to look for it.
+// RUN: %env_asan_opts="symbolize=0,print_module_map=0" not %run %t.executable > %t_no_module_map.log 2>&1
+// RUN: not %asan_symbolize --module-map %t_no_module_map.log --force-system-symbolizer < %t_no_module_map.log 2>&1 | FileCheck -check-prefix=CHECK-NO-MM %s
+// CHECK-NO-MM: ERROR:{{.*}} Failed to find module map
+
+// Now produce the module map and check we can symbolize.
+// RUN: %env_asan_opts="symbolize=0,print_module_map=2" not %run %t.executable > %t_with_module_map.log 2>&1
+// RUN: %asan_symbolize --module-map %t_with_module_map.log --force-system-symbolizer < %t_with_module_map.log 2>&1 | FileCheck -check-prefix=CHECK-MM %s
+
+#include <cstdlib>
+
+// CHECK-MM: WRITE of size 4
+
+extern "C" void foo(int* a) {
+ // CHECK-MM: #0 0x{{.+}} in foo {{.*}}asan-symbolize-with-module-map.cc:[[@LINE+1]]
+ *a = 5;
+}
+
+int main() {
+ int* a = (int*) malloc(sizeof(int));
+ if (!a)
+ return 0;
+ free(a);
+ // CHECK-MM: #1 0x{{.+}} in main {{.*}}asan-symbolize-with-module-map.cc:[[@LINE+1]]
+ foo(a);
+ return 0;
+}
diff --git a/test/asan/TestCases/Linux/asan-asm-stacktrace-test.cc b/test/asan/TestCases/Linux/asan-asm-stacktrace-test.cc
deleted file mode 100644
index acbe94726..000000000
--- a/test/asan/TestCases/Linux/asan-asm-stacktrace-test.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-// Check that a stack unwinding algorithm works corretly even with the assembly
-// instrumentation.
-
-// REQUIRES: x86_64-target-arch, shadow-scale-3
-// RUN: %clangxx_asan -g -O1 %s -fno-inline-functions -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -mllvm -asan-instrument-assembly -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -g -O1 %s -fno-inline-functions -fomit-frame-pointer -momit-leaf-frame-pointer -mllvm -asan-instrument-assembly -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -g0 -O1 %s -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-exceptions -fno-inline-functions -fomit-frame-pointer -momit-leaf-frame-pointer -mllvm -asan-instrument-assembly -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nounwind
-
-#include <cstddef>
-
-// CHECK: READ of size 4
-// CHECK-NEXT: {{#0 0x[0-9a-fA-F]+ in foo}}
-// CHECK-NEXT: {{#1 0x[0-9a-fA-F]+ in main}}
-
-// CHECK-nounwind: READ of size 4
-// CHECK-nounwind-NEXT: {{#0 0x[0-9a-fA-F]+ in foo}}
-
-__attribute__((noinline)) int foo(size_t n, int *buffer) {
- int r;
- __asm__("movl (%[buffer], %[n], 4), %[r] \n\t"
- : [r] "=r"(r)
- : [buffer] "r"(buffer), [n] "r"(n)
- : "memory");
- return r;
-}
-
-int main() {
- const size_t n = 16;
- int *buffer = new int[n];
- foo(n, buffer);
- delete[] buffer;
- return 0;
-}
diff --git a/test/asan/TestCases/Linux/bzero.cc b/test/asan/TestCases/Linux/bzero.cc
new file mode 100644
index 000000000..430edb744
--- /dev/null
+++ b/test/asan/TestCases/Linux/bzero.cc
@@ -0,0 +1,15 @@
+// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// REQUIRES: !android
+
+#include <assert.h>
+#include <strings.h>
+
+int main(int argc, char *argv[]) {
+ char buf[100];
+ // *& to suppress bzero-to-memset optimization.
+ (*&bzero)(buf, sizeof(buf) + 1);
+ // CHECK: AddressSanitizer: stack-buffer-overflow
+ // CHECK-NEXT: WRITE of size 101 at
+ return 0;
+}
diff --git a/test/asan/TestCases/Linux/swapcontext_annotation.cc b/test/asan/TestCases/Linux/swapcontext_annotation.cc
index 3bfda7353..5eae27a32 100644
--- a/test/asan/TestCases/Linux/swapcontext_annotation.cc
+++ b/test/asan/TestCases/Linux/swapcontext_annotation.cc
@@ -12,7 +12,8 @@
//
// This test is too subtle to try on non-x86 arch for now.
-// REQUIRES: x86-target-arch
+// Android does not support swapcontext.
+// REQUIRES: x86-target-arch && !android
#include <pthread.h>
#include <setjmp.h>
diff --git a/test/asan/TestCases/Linux/swapcontext_test.cc b/test/asan/TestCases/Linux/swapcontext_test.cc
index 210a667d0..2660ffe3b 100644
--- a/test/asan/TestCases/Linux/swapcontext_test.cc
+++ b/test/asan/TestCases/Linux/swapcontext_test.cc
@@ -6,7 +6,8 @@
// RUN: %clangxx_asan -O3 %s -o %t && %run %t 2>&1 | FileCheck %s
//
// This test is too sublte to try on non-x86 arch for now.
-// REQUIRES: x86-target-arch
+// Android does not support swapcontext.
+// REQUIRES: x86-target-arch && !android
#include <stdio.h>
#include <ucontext.h>
diff --git a/test/asan/TestCases/Linux/unpoison_tls.cc b/test/asan/TestCases/Linux/unpoison_tls.cc
index 19ebec467..e22345342 100644
--- a/test/asan/TestCases/Linux/unpoison_tls.cc
+++ b/test/asan/TestCases/Linux/unpoison_tls.cc
@@ -1,5 +1,5 @@
// Test that TLS is unpoisoned on thread death.
-// REQUIRES: x86-target-arch
+// REQUIRES: x86-target-arch && !android
// RUN: %clangxx_asan -O1 %s -pthread -o %t && %run %t 2>&1
diff --git a/test/asan/TestCases/Linux/vfork.cc b/test/asan/TestCases/Linux/vfork.cc
new file mode 100644
index 000000000..31a32dc56
--- /dev/null
+++ b/test/asan/TestCases/Linux/vfork.cc
@@ -0,0 +1,31 @@
+// https://github.com/google/sanitizers/issues/925
+// RUN: %clang_asan -O0 %s -o %t && %run %t 2>&1
+
+// REQUIRES: aarch64-target-arch || x86_64-target-arch || i386-target-arch || arm-target-arch
+
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sanitizer/asan_interface.h>
+
+__attribute__((noinline, no_sanitize("address"))) void child() {
+ alignas(8) char x[100000];
+ __asan_poison_memory_region(x, sizeof(x));
+ _exit(0);
+}
+
+__attribute__((noinline, no_sanitize("address"))) void parent() {
+ alignas(8) char x[100000];
+ assert(__asan_address_is_poisoned(x + 5000) == 0);
+}
+
+int main(int argc, char **argv) {
+ if (vfork())
+ parent();
+ else
+ child();
+
+ return 0;
+}
diff --git a/test/asan/TestCases/Posix/asan_symbolize_script/logging_options_in_help.cc b/test/asan/TestCases/Posix/asan_symbolize_script/logging_options_in_help.cc
new file mode 100644
index 000000000..b3df1cb35
--- /dev/null
+++ b/test/asan/TestCases/Posix/asan_symbolize_script/logging_options_in_help.cc
@@ -0,0 +1,5 @@
+// RUN: %asan_symbolize --help > %t_help_output.txt
+// RUN: FileCheck %s -input-file=%t_help_output.txt
+// CHECK: optional arguments:
+// CHECK: --log-dest
+// CHECK: --log-level
diff --git a/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op.py b/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op.py
new file mode 100644
index 000000000..c636bdfa2
--- /dev/null
+++ b/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op.py
@@ -0,0 +1,17 @@
+class NoOpPlugin(AsanSymbolizerPlugIn):
+ def register_cmdline_args(self, parser):
+ logging.info('Adding --unlikely-option-name-XXX option')
+ parser.add_argument('--unlikely-option-name-XXX', type=int, default=0)
+
+ def process_cmdline_args(self, pargs):
+ logging.info('GOT --unlikely-option-name-XXX=%d', pargs.unlikely_option_name_XXX)
+ return True
+
+ def destroy(self):
+ logging.info('destroy() called on NoOpPlugin')
+
+ def filter_binary_path(self, path):
+ logging.info('filter_binary_path called in NoOpPlugin')
+ return path
+
+register_plugin(NoOpPlugin())
diff --git a/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op_help_output.cc b/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op_help_output.cc
new file mode 100644
index 000000000..71f32e0d6
--- /dev/null
+++ b/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op_help_output.cc
@@ -0,0 +1,7 @@
+// Check help output.
+// RUN: %asan_symbolize --log-level info --plugins %S/plugin_no_op.py --help 2>&1 | FileCheck %s
+// CHECK: Registering plugin NoOpPlugin
+// CHECK: Adding --unlikely-option-name-XXX option
+// CHECK: optional arguments:
+// CHECK: --unlikely-option-name-XXX
+
diff --git a/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op_symbolicate.cc b/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op_symbolicate.cc
new file mode 100644
index 000000000..3f3ad9bfd
--- /dev/null
+++ b/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op_symbolicate.cc
@@ -0,0 +1,24 @@
+// UNSUPPORTED: ios, android
+// Check plugin command line args get parsed and that plugin functions get called as expected.
+
+// RUN: %clangxx_asan -O0 -g %s -o %t.executable
+// RUN: not %env_asan_opts=symbolize=0 %run %t.executable > %t.log 2>&1
+// RUN: %asan_symbolize --plugins %S/plugin_no_op.py --log-level info -l %t.log --unlikely-option-name-XXX=15 2>&1 | FileCheck %s
+
+// CHECK: GOT --unlikely-option-name-XXX=15
+// CHECK: filter_binary_path called in NoOpPlugin
+// CHECK: destroy() called on NoOpPlugin
+
+#include <cstdlib>
+extern "C" void foo(int* a) {
+ *a = 5;
+}
+
+int main() {
+ int* a = (int*) malloc(sizeof(int));
+ if (!a)
+ return 0;
+ free(a);
+ foo(a);
+ return 0;
+}
diff --git a/test/asan/TestCases/Posix/asan_symbolize_script/set_log_dest.cc b/test/asan/TestCases/Posix/asan_symbolize_script/set_log_dest.cc
new file mode 100644
index 000000000..f2c309808
--- /dev/null
+++ b/test/asan/TestCases/Posix/asan_symbolize_script/set_log_dest.cc
@@ -0,0 +1,3 @@
+// RUN: %asan_symbolize --log-level debug --log-dest %t_debug_log_output.txt --help
+// RUN: FileCheck %s -input-file=%t_debug_log_output.txt -check-prefix=DEBUG-CHECK
+// DEBUG-CHECK: DEBUG: [setup_logging() asan_symbolize.py:{{[0-9]+}}] Logging level set to "debug"
diff --git a/test/asan/TestCases/Posix/asan_symbolize_script/set_log_level.cc b/test/asan/TestCases/Posix/asan_symbolize_script/set_log_level.cc
new file mode 100644
index 000000000..b30fd6ec3
--- /dev/null
+++ b/test/asan/TestCases/Posix/asan_symbolize_script/set_log_level.cc
@@ -0,0 +1,8 @@
+// RUN: %asan_symbolize --log-level debug --help 2> %t_debug_log_output.txt
+// RUN: FileCheck %s -input-file=%t_debug_log_output.txt -check-prefix=DEBUG-CHECK
+// DEBUG-CHECK: DEBUG: [setup_logging() asan_symbolize.py:{{[0-9]+}}] Logging level set to "debug"
+//
+// FileCheck doesn't like empty files so add stdout too.
+// RUN: %asan_symbolize --log-level info --help > %t_info_log_output.txt 2>&1
+// RUN: FileCheck %s -input-file=%t_info_log_output.txt -check-prefix=INFO-CHECK
+// INFO-CHECK-NOT: DEBUG: [setup_logging() asan_symbolize.py:{{[0-9]+}}]
diff --git a/test/asan/TestCases/Posix/bcmp_test.cc b/test/asan/TestCases/Posix/bcmp_test.cc
new file mode 100644
index 000000000..44aa9cd24
--- /dev/null
+++ b/test/asan/TestCases/Posix/bcmp_test.cc
@@ -0,0 +1,18 @@
+// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// REQUIRES: compiler-rt-optimized, (linux && !android) || openbsd || freebsd || netbsd
+// XFAIL: darwin
+
+#include <string.h>
+int main(int argc, char **argv) {
+ char a1[] = {static_cast<char>(argc), 2, 3, 4};
+ char a2[] = {1, static_cast<char>(2 * argc), 3, 4};
+ int res = bcmp(a1, a2, 4 + argc); // BOOM
+ // CHECK: AddressSanitizer: stack-buffer-overflow
+ // CHECK: {{#1.*bcmp}}
+ // CHECK: {{#2.*main}}
+ return res;
+}
diff --git a/test/asan/TestCases/Posix/start-deactivated.cc b/test/asan/TestCases/Posix/start-deactivated.cc
index 736d7f698..9c674ac57 100644
--- a/test/asan/TestCases/Posix/start-deactivated.cc
+++ b/test/asan/TestCases/Posix/start-deactivated.cc
@@ -18,7 +18,6 @@
// RUN: %env_asan_opts=start_deactivated=1 \
// RUN: ASAN_ACTIVATION_OPTIONS=help=1,handle_segv=0,verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UNSUPPORTED
-// UNSUPPORTED: ios
// END.
diff --git a/test/asan/TestCases/Posix/wcrtomb.c b/test/asan/TestCases/Posix/wcrtomb.c
new file mode 100644
index 000000000..bd9a8bf3e
--- /dev/null
+++ b/test/asan/TestCases/Posix/wcrtomb.c
@@ -0,0 +1,16 @@
+// Function not intercepted on android.
+// UNSUPPORTED: android
+
+// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+#include <wchar.h>
+
+int main() {
+ char *buff = (char*) malloc(MB_CUR_MAX);
+ free(buff);
+ wcrtomb(buff, L'a', NULL);
+ // CHECK: use-after-free
+ // CHECK: SUMMARY
+ return 0;
+}
diff --git a/test/asan/TestCases/Windows/dll_intercept_memcpy.cc b/test/asan/TestCases/Windows/dll_intercept_memcpy.cc
index a5981fa5b..53cb7ef1c 100644
--- a/test/asan/TestCases/Windows/dll_intercept_memcpy.cc
+++ b/test/asan/TestCases/Windows/dll_intercept_memcpy.cc
@@ -1,9 +1,9 @@
// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -Wno-fortify-source -LD -O0 %s -Fe%t.dll
// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
// Test that it works correctly even with ICF enabled.
-// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll -link /OPT:REF /OPT:ICF
+// RUN: %clang_cl_asan -Wno-fortify-source -LD -O0 %s -Fe%t.dll -link /OPT:REF /OPT:ICF
// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
#include <stdio.h>
diff --git a/test/asan/TestCases/Windows/dll_intercept_memset.cc b/test/asan/TestCases/Windows/dll_intercept_memset.cc
index 4baa0a161..51096e4bb 100644
--- a/test/asan/TestCases/Windows/dll_intercept_memset.cc
+++ b/test/asan/TestCases/Windows/dll_intercept_memset.cc
@@ -1,9 +1,9 @@
// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -Wno-fortify-source -LD -O0 %s -Fe%t.dll
// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
// Test that it works correctly even with ICF enabled.
-// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll -link /OPT:REF /OPT:ICF
+// RUN: %clang_cl_asan -Wno-fortify-source -LD -O0 %s -Fe%t.dll -link /OPT:REF /OPT:ICF
// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
#include <stdio.h>
diff --git a/test/asan/TestCases/Windows/heaprealloc_zero_size.cc b/test/asan/TestCases/Windows/heaprealloc_zero_size.cc
new file mode 100644
index 000000000..3d60202ce
--- /dev/null
+++ b/test/asan/TestCases/Windows/heaprealloc_zero_size.cc
@@ -0,0 +1,21 @@
+// RUN: %clang_cl_asan /Od -o %t %s
+// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_cl /Od -o %t %s
+// RUN: %run %t 2>&1 | FileCheck %s
+#include <cassert>
+#include <stdio.h>
+#include<windows.h>
+
+int main() {
+ HANDLE heap = HeapCreate(0, 0, 0);
+ void *ptr = HeapAlloc(heap, 0, 4);
+ assert(ptr);
+ void *ptr2 = HeapReAlloc(heap, 0, ptr, 0);
+ assert(ptr2);
+ HeapFree(heap, 0, ptr2);
+ fprintf(stderr, "passed!\n");
+}
+
+// CHECK-NOT: double-free
+// CHECK-NOT: AddressSanitizer
+// CHECK: passed! \ No newline at end of file
diff --git a/test/asan/TestCases/Windows/recalloc_sanity.cc b/test/asan/TestCases/Windows/recalloc_sanity.cc
new file mode 100644
index 000000000..41df5d002
--- /dev/null
+++ b/test/asan/TestCases/Windows/recalloc_sanity.cc
@@ -0,0 +1,37 @@
+// RUN: %clang_cl_asan %s -o %t.exe
+// RUN: %run %t.exe 2>&1 | FileCheck %s
+// RUN: %clang_cl %s -o %t.exe
+// RUN: %run %t.exe 2>&1 | FileCheck %s
+
+#include <cassert>
+#include <stdio.h>
+#include <windows.h>
+
+int main() {
+ void *p = calloc(1, 100);
+ assert(p);
+ void *np = _recalloc(p, 2, 100);
+ assert(np);
+ for (int i = 0; i < 2 * 100; i++) {
+ assert(((BYTE *)np)[i] == 0);
+ }
+ void *nnp = _recalloc(np, 1, 100);
+ assert(nnp);
+ for (int i = 0; i < 100; i++) {
+ assert(((BYTE *)nnp)[i] == 0);
+ ((BYTE *)nnp)[i] = 0x0d;
+ }
+ void *nnnp = _recalloc(nnp, 2, 100);
+ assert(nnnp);
+ for (int i = 0; i < 100; i++) {
+ assert(((BYTE *)nnnp)[i] == 0x0d);
+ }
+ for (int i = 100; i < 200; i++) {
+ assert(((BYTE *)nnnp)[i] == 0);
+ }
+ fprintf(stderr, "passed\n");
+ return 0;
+}
+
+// CHECK-NOT: Assertion
+// CHECK: passed \ No newline at end of file
diff --git a/test/asan/TestCases/memcmp_test.cc b/test/asan/TestCases/memcmp_test.cc
index 0dd9820f5..e666b6d16 100644
--- a/test/asan/TestCases/memcmp_test.cc
+++ b/test/asan/TestCases/memcmp_test.cc
@@ -11,7 +11,7 @@ int main(int argc, char **argv) {
char a2[] = {1, static_cast<char>(2*argc), 3, 4};
int res = memcmp(a1, a2, 4 + argc); // BOOM
// CHECK: AddressSanitizer: stack-buffer-overflow
- // CHECK: {{#0.*memcmp}}
- // CHECK: {{#1.*main}}
+ // CHECK: {{#1.*memcmp}}
+ // CHECK: {{#2.*main}}
return res;
}