aboutsummaryrefslogtreecommitdiff
path: root/test/asan
diff options
context:
space:
mode:
Diffstat (limited to 'test/asan')
-rw-r--r--test/asan/CMakeLists.txt5
-rw-r--r--test/asan/TestCases/Android/coverage-android.cc36
-rw-r--r--test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cc26
-rw-r--r--test/asan/TestCases/Darwin/atos-symbolizer.cc24
-rw-r--r--test/asan/TestCases/Darwin/dladdr-demangling.cc33
-rw-r--r--test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc22
-rw-r--r--test/asan/TestCases/Darwin/empty-section.cc12
-rw-r--r--test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc32
-rw-r--r--test/asan/TestCases/Darwin/interface_symbols_darwin.c12
-rw-r--r--test/asan/TestCases/Darwin/reexec-insert-libraries-env.cc2
-rw-r--r--test/asan/TestCases/Darwin/sandbox-symbolizer.cc29
-rw-r--r--test/asan/TestCases/Darwin/suppressions-darwin.cc8
-rw-r--r--test/asan/TestCases/Darwin/suppressions-sandbox.cc26
-rw-r--r--test/asan/TestCases/Darwin/unset-insert-libraries-on-exec.cc2
-rw-r--r--test/asan/TestCases/Helpers/init-order-pthread-create-extra.cc4
-rw-r--r--test/asan/TestCases/Linux/asan_default_suppressions.cc7
-rw-r--r--test/asan/TestCases/Linux/asan_prelink_test.cc2
-rw-r--r--test/asan/TestCases/Linux/asan_preload_test-1.cc2
-rw-r--r--test/asan/TestCases/Linux/asan_preload_test-2.cc2
-rw-r--r--test/asan/TestCases/Linux/asan_rt_confict_test-1.cc2
-rw-r--r--test/asan/TestCases/Linux/clang_gcc_abi.cc3
-rw-r--r--test/asan/TestCases/Linux/coverage-levels.cc29
-rw-r--r--test/asan/TestCases/Linux/coverage-missing.cc84
-rw-r--r--test/asan/TestCases/Linux/coverage-tracing.cc50
-rw-r--r--test/asan/TestCases/Linux/init-order-dlopen.cc47
-rw-r--r--test/asan/TestCases/Linux/initialization-bug-any-order.cc4
-rw-r--r--test/asan/TestCases/Linux/interface_symbols_linux.c14
-rw-r--r--test/asan/TestCases/Linux/kernel-area.cc20
-rw-r--r--test/asan/TestCases/Linux/leak.cc6
-rw-r--r--test/asan/TestCases/Linux/leak_check_segv.cc23
-rw-r--r--test/asan/TestCases/Linux/malloc-in-qsort.cc4
-rw-r--r--test/asan/TestCases/Linux/malloc_delete_mismatch.cc8
-rw-r--r--test/asan/TestCases/Linux/nohugepage_test.cc24
-rw-r--r--test/asan/TestCases/Linux/odr-violation.cc22
-rw-r--r--test/asan/TestCases/Linux/overflow-in-qsort.cc4
-rw-r--r--test/asan/TestCases/Linux/ptrace.cc6
-rw-r--r--test/asan/TestCases/Linux/quarantine_size_mb.cc10
-rw-r--r--test/asan/TestCases/Linux/read_binary_name_regtest.c50
-rw-r--r--test/asan/TestCases/Linux/signal_during_stop_the_world.cc60
-rw-r--r--test/asan/TestCases/Linux/sized_delete_test.cc18
-rw-r--r--test/asan/TestCases/Linux/stack-overflow-sigbus.cc2
-rw-r--r--test/asan/TestCases/Linux/stack-trace-dlclose.cc4
-rw-r--r--test/asan/TestCases/Linux/static_tls.cc29
-rw-r--r--test/asan/TestCases/Linux/stress_dtls.c6
-rw-r--r--test/asan/TestCases/Posix/allow_user_segv.cc4
-rw-r--r--test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc2
-rw-r--r--test/asan/TestCases/Posix/coverage-direct-activation.cc (renamed from test/asan/TestCases/Linux/coverage-direct-activation.cc)18
-rw-r--r--test/asan/TestCases/Posix/coverage-direct-large.cc (renamed from test/asan/TestCases/Linux/coverage-direct-large.cc)16
-rw-r--r--test/asan/TestCases/Posix/coverage-direct.cc (renamed from test/asan/TestCases/Linux/coverage-direct.cc)28
-rw-r--r--test/asan/TestCases/Posix/coverage-fork-direct.cc (renamed from test/asan/TestCases/Linux/coverage-fork-direct.cc)4
-rw-r--r--test/asan/TestCases/Posix/coverage-fork.cc (renamed from test/asan/TestCases/Linux/coverage-fork.cc)4
-rw-r--r--test/asan/TestCases/Posix/coverage-module-unloaded.cc (renamed from test/asan/TestCases/Linux/coverage-module-unloaded.cc)29
-rw-r--r--test/asan/TestCases/Posix/coverage-sandboxing.cc (renamed from test/asan/TestCases/Linux/coverage-sandboxing.cc)16
-rw-r--r--test/asan/TestCases/Posix/coverage.cc (renamed from test/asan/TestCases/Linux/coverage.cc)24
-rw-r--r--test/asan/TestCases/Posix/init-order-dlopen.cc72
-rw-r--r--test/asan/TestCases/Posix/interception-in-shared-lib-test.cc (renamed from test/asan/TestCases/Linux/interception-in-shared-lib-test.cc)11
-rw-r--r--test/asan/TestCases/Posix/ioctl.cc4
-rw-r--r--test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc2
-rw-r--r--test/asan/TestCases/Posix/log_path_fork_test.cc.disabled (renamed from test/asan/TestCases/log_path_fork_test.cc.disabled)2
-rw-r--r--test/asan/TestCases/Posix/new_array_cookie_test.cc4
-rw-r--r--test/asan/TestCases/Posix/new_array_cookie_uaf_test.cc4
-rw-r--r--test/asan/TestCases/Posix/start-deactivated.cc11
-rw-r--r--test/asan/TestCases/Posix/tsd_dtor_leak.cc2
-rw-r--r--test/asan/TestCases/Windows/bind_io_completion_callback.cc70
-rw-r--r--test/asan/TestCases/Windows/coverage-basic.cc25
-rw-r--r--test/asan/TestCases/Windows/default_options.cc18
-rw-r--r--test/asan/TestCases/Windows/dll_noreturn.cc2
-rw-r--r--test/asan/TestCases/Windows/dll_report_globals_symbolization_at_startup.cc40
-rw-r--r--test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc2
-rw-r--r--test/asan/TestCases/Windows/free_hook_realloc.cc37
-rw-r--r--test/asan/TestCases/Windows/on_error_callback.cc20
-rw-r--r--test/asan/TestCases/Windows/queue_user_work_item.cc55
-rw-r--r--test/asan/TestCases/Windows/queue_user_work_item_report.cc29
-rw-r--r--test/asan/TestCases/Windows/report_globals_reload_dll.cc51
-rw-r--r--test/asan/TestCases/Windows/report_globals_vs_freelibrary.cc (renamed from test/asan/TestCases/Windows/globals_multiple_dlls.cc)4
-rw-r--r--test/asan/TestCases/Windows/stack_array_left_oob.cc2
-rw-r--r--test/asan/TestCases/Windows/thread_stack_array_left_oob.cc2
-rw-r--r--test/asan/TestCases/alloca_instruments_all_paddings.cc1
-rw-r--r--test/asan/TestCases/alloca_loop_unpoisoning.cc33
-rw-r--r--test/asan/TestCases/alloca_vla_interact.cc41
-rw-r--r--test/asan/TestCases/allocator_returns_null.cc20
-rw-r--r--test/asan/TestCases/asan_and_llvm_coverage_test.cc2
-rw-r--r--test/asan/TestCases/asan_options-help.cc2
-rw-r--r--test/asan/TestCases/atexit_stats.cc2
-rw-r--r--test/asan/TestCases/atoi_strict.c55
-rw-r--r--test/asan/TestCases/atol_strict.c55
-rw-r--r--test/asan/TestCases/atoll_strict.c55
-rw-r--r--test/asan/TestCases/closed-fds.cc33
-rw-r--r--test/asan/TestCases/contiguous_container_crash.cc19
-rw-r--r--test/asan/TestCases/coverage-and-lsan.cc (renamed from test/asan/TestCases/Linux/coverage-and-lsan.cc)4
-rw-r--r--test/asan/TestCases/coverage-caller-callee-total-count.cc (renamed from test/asan/TestCases/Linux/coverage-caller-callee-total-count.cc)4
-rw-r--r--test/asan/TestCases/coverage-caller-callee.cc (renamed from test/asan/TestCases/Linux/coverage-caller-callee.cc)14
-rw-r--r--test/asan/TestCases/coverage-disabled.cc (renamed from test/asan/TestCases/Linux/coverage-disabled.cc)8
-rw-r--r--test/asan/TestCases/coverage-levels.cc34
-rw-r--r--test/asan/TestCases/coverage-maybe-open-file.cc (renamed from test/asan/TestCases/Linux/coverage-maybe-open-file.cc)7
-rw-r--r--test/asan/TestCases/coverage-order-pcs.cc56
-rw-r--r--test/asan/TestCases/coverage-reset.cc (renamed from test/asan/TestCases/Linux/coverage-reset.cc)4
-rw-r--r--test/asan/TestCases/coverage-tracing.cc50
-rw-r--r--test/asan/TestCases/debug_mapping.cc8
-rw-r--r--test/asan/TestCases/debug_ppc64_mapping.cc4
-rw-r--r--test/asan/TestCases/debug_stacks.cc3
-rw-r--r--test/asan/TestCases/deep_call_stack.cc4
-rw-r--r--test/asan/TestCases/deep_stack_uaf.cc2
-rw-r--r--test/asan/TestCases/default_options.cc3
-rw-r--r--test/asan/TestCases/double-free.cc4
-rw-r--r--test/asan/TestCases/dump_instruction_bytes.cc2
-rw-r--r--test/asan/TestCases/free_hook_realloc.cc3
-rw-r--r--test/asan/TestCases/gc-test.cc8
-rw-r--r--test/asan/TestCases/heap-overflow-large.cc4
-rw-r--r--test/asan/TestCases/heap-overflow.cc2
-rw-r--r--test/asan/TestCases/heavy_uar_test.cc2
-rw-r--r--test/asan/TestCases/init-order-atexit.cc5
-rw-r--r--test/asan/TestCases/init-order-pthread-create.cc39
-rw-r--r--test/asan/TestCases/initialization-blacklist.cc6
-rw-r--r--test/asan/TestCases/initialization-bug.cc6
-rw-r--r--test/asan/TestCases/initialization-constexpr.cc8
-rw-r--r--test/asan/TestCases/initialization-nobug.cc8
-rw-r--r--test/asan/TestCases/interface_test.cc4
-rw-r--r--test/asan/TestCases/invalid-free.cc4
-rw-r--r--test/asan/TestCases/log-path_test.cc8
-rw-r--r--test/asan/TestCases/malloc_context_size.cc10
-rw-r--r--test/asan/TestCases/malloc_fill.cc4
-rw-r--r--test/asan/TestCases/max_redzone.cc4
-rw-r--r--test/asan/TestCases/memcmp_strict_test.cc4
-rw-r--r--test/asan/TestCases/mmap_limit_mb.cc8
-rw-r--r--test/asan/TestCases/no_asan_gen_globals.c2
-rw-r--r--test/asan/TestCases/on_error_callback.cc3
-rw-r--r--test/asan/TestCases/poison_partial.cc4
-rw-r--r--test/asan/TestCases/print_summary.cc16
-rw-r--r--test/asan/TestCases/printf-1.c4
-rw-r--r--test/asan/TestCases/printf-2.c6
-rw-r--r--test/asan/TestCases/printf-3.c4
-rw-r--r--test/asan/TestCases/printf-4.c4
-rw-r--r--test/asan/TestCases/printf-5.c6
-rw-r--r--test/asan/TestCases/sleep_before_dying.c2
-rw-r--r--test/asan/TestCases/stack-overflow.cc24
-rw-r--r--test/asan/TestCases/stack-use-after-return.cc4
-rw-r--r--test/asan/TestCases/strcasestr-1.c24
-rw-r--r--test/asan/TestCases/strcasestr-2.c24
-rw-r--r--test/asan/TestCases/strcasestr_strict.c28
-rw-r--r--test/asan/TestCases/strcat_strict.c44
-rw-r--r--test/asan/TestCases/strchr_strict.c22
-rw-r--r--test/asan/TestCases/strcmp_strict.c26
-rw-r--r--test/asan/TestCases/strcspn-1.c19
-rw-r--r--test/asan/TestCases/strcspn-2.c19
-rw-r--r--test/asan/TestCases/strcspn_strict.c26
-rw-r--r--test/asan/TestCases/strip_path_prefix.c4
-rw-r--r--test/asan/TestCases/strncat_strict.c44
-rw-r--r--test/asan/TestCases/strpbrk-1.c19
-rw-r--r--test/asan/TestCases/strpbrk-2.c19
-rw-r--r--test/asan/TestCases/strpbrk_strict.c25
-rw-r--r--test/asan/TestCases/strspn-1.c19
-rw-r--r--test/asan/TestCases/strspn-2.c19
-rw-r--r--test/asan/TestCases/strspn_strict.c25
-rw-r--r--test/asan/TestCases/strstr-1.c20
-rw-r--r--test/asan/TestCases/strstr-2.c20
-rw-r--r--test/asan/TestCases/strstr_strict.c25
-rw-r--r--test/asan/TestCases/strtol_strict.c116
-rw-r--r--test/asan/TestCases/strtoll_strict.c116
-rw-r--r--test/asan/TestCases/suppressions-exec-relative-location.cc47
-rw-r--r--test/asan/TestCases/suppressions-function.cc4
-rw-r--r--test/asan/TestCases/suppressions-interceptor.cc2
-rw-r--r--test/asan/TestCases/suppressions-library.cc8
-rw-r--r--test/asan/TestCases/uar_and_exceptions.cc2
-rw-r--r--test/asan/TestCases/use-after-poison.cc2
-rw-r--r--test/asan/TestCases/use-after-scope.cc2
-rw-r--r--test/asan/TestCases/verbose-log-path_test.cc21
-rw-r--r--test/asan/TestCases/vla_chrome_testcase.cc30
-rw-r--r--test/asan/TestCases/vla_condition_overflow.cc22
-rw-r--r--test/asan/TestCases/vla_loop_overfow.cc22
-rw-r--r--test/asan/lit.cfg17
171 files changed, 2510 insertions, 546 deletions
diff --git a/test/asan/CMakeLists.txt b/test/asan/CMakeLists.txt
index e1b81264604d..aff54db1e77a 100644
--- a/test/asan/CMakeLists.txt
+++ b/test/asan/CMakeLists.txt
@@ -5,9 +5,9 @@ set(ASAN_DYNAMIC_TESTSUITES)
macro(get_bits_for_arch arch bits)
if (${arch} MATCHES "i386|i686|arm|mips|mipsel")
- set(bits 32)
+ set(${bits} 32)
elseif (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|mips64|mips64el")
- set(bits 64)
+ set(${bits} 64)
else()
message(FATAL_ERROR "Unknown target architecture: ${arch}")
endif()
@@ -28,6 +28,7 @@ foreach(arch ${ASAN_SUPPORTED_ARCH})
set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
else()
get_target_flags_for_arch(${arch} ASAN_TEST_TARGET_CFLAGS)
+ string(REPLACE ";" " " ASAN_TEST_TARGET_CFLAGS "${ASAN_TEST_TARGET_CFLAGS}")
endif()
if(ANDROID)
set(ASAN_TEST_DYNAMIC True)
diff --git a/test/asan/TestCases/Android/coverage-android.cc b/test/asan/TestCases/Android/coverage-android.cc
index e243059fbbec..5f2631605595 100644
--- a/test/asan/TestCases/Android/coverage-android.cc
+++ b/test/asan/TestCases/Android/coverage-android.cc
@@ -1,15 +1,15 @@
// Test for direct coverage writing with dlopen.
// Test normal exit, coverage level 1.
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_android_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSO_DIR=\"%device\" %s -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %T/libcoverage_android_test_1.so -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=func -DSO_DIR=\"%device\" %s -o %t
// RUN: adb shell rm -rf %device/coverage-android
// RUN: rm -rf %T/coverage-android
// RUN: adb shell mkdir -p %device/coverage-android/direct
// RUN: mkdir -p %T/coverage-android/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
// RUN: adb pull %device/coverage-android/direct %T/coverage-android/direct
// RUN: ls; pwd
// RUN: cd %T/coverage-android/direct
@@ -18,15 +18,15 @@
// Test sudden death, coverage level 1.
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED -DKILL %s -shared -o %T/libcoverage_android_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSO_DIR=\"%device\" %s -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED -DKILL %s -shared -o %T/libcoverage_android_test_1.so -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=func -DSO_DIR=\"%device\" %s -o %t
// RUN: adb shell rm -rf %device/coverage-android-kill
// RUN: rm -rf %T/coverage-android-kill
// RUN: adb shell mkdir -p %device/coverage-android-kill/direct
// RUN: mkdir -p %T/coverage-android-kill/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
// RUN: adb pull %device/coverage-android-kill/direct %T/coverage-android-kill/direct
// RUN: ls; pwd
// RUN: cd %T/coverage-android-kill/direct
@@ -35,15 +35,15 @@
// Test normal exit, coverage level 2.
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %T/libcoverage_android_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSO_DIR=\"%device\" %s -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=bb -DSHARED %s -shared -o %T/libcoverage_android_test_1.so -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=bb -DSO_DIR=\"%device\" %s -o %t
// RUN: adb shell rm -rf %device/coverage-android
// RUN: rm -rf %T/coverage-android
// RUN: adb shell mkdir -p %device/coverage-android/direct
// RUN: mkdir -p %T/coverage-android/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
// RUN: adb pull %device/coverage-android/direct %T/coverage-android/direct
// RUN: ls; pwd
// RUN: cd %T/coverage-android/direct
@@ -52,15 +52,15 @@
// Test sudden death, coverage level 2.
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED -DKILL %s -shared -o %T/libcoverage_android_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSO_DIR=\"%device\" %s -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=bb -DSHARED -DKILL %s -shared -o %T/libcoverage_android_test_1.so -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=bb -DSO_DIR=\"%device\" %s -o %t
// RUN: adb shell rm -rf %device/coverage-android-kill
// RUN: rm -rf %T/coverage-android-kill
// RUN: adb shell mkdir -p %device/coverage-android-kill/direct
// RUN: mkdir -p %T/coverage-android-kill/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
// RUN: adb pull %device/coverage-android-kill/direct %T/coverage-android-kill/direct
// RUN: ls; pwd
// RUN: cd %T/coverage-android-kill/direct
@@ -69,15 +69,15 @@
// Test normal exit, coverage level 3.
-// RUN: %clangxx_asan -fsanitize-coverage=3 -DSHARED %s -shared -o %T/libcoverage_android_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=3 -DSO_DIR=\"%device\" %s -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=edge -DSHARED %s -shared -o %T/libcoverage_android_test_1.so -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=edge -DSO_DIR=\"%device\" %s -o %t
// RUN: adb shell rm -rf %device/coverage-android
// RUN: rm -rf %T/coverage-android
// RUN: adb shell mkdir -p %device/coverage-android/direct
// RUN: mkdir -p %T/coverage-android/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
// RUN: adb pull %device/coverage-android/direct %T/coverage-android/direct
// RUN: ls; pwd
// RUN: cd %T/coverage-android/direct
@@ -86,15 +86,15 @@
// Test sudden death, coverage level 3.
-// RUN: %clangxx_asan -fsanitize-coverage=3 -DSHARED -DKILL %s -shared -o %T/libcoverage_android_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=3 -DSO_DIR=\"%device\" %s -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=edge -DSHARED -DKILL %s -shared -o %T/libcoverage_android_test_1.so -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=edge -DSO_DIR=\"%device\" %s -o %t
// RUN: adb shell rm -rf %device/coverage-android-kill
// RUN: rm -rf %T/coverage-android-kill
// RUN: adb shell mkdir -p %device/coverage-android-kill/direct
// RUN: mkdir -p %T/coverage-android-kill/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
// RUN: adb pull %device/coverage-android-kill/direct %T/coverage-android-kill/direct
// RUN: ls; pwd
// RUN: cd %T/coverage-android-kill/direct
diff --git a/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cc b/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cc
new file mode 100644
index 000000000000..f6070188d8e5
--- /dev/null
+++ b/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cc
@@ -0,0 +1,26 @@
+// Check that when having a DYLD_ROOT_PATH set, the symbolizer still works.
+// RUN: env DYLD_ROOT_PATH="/" ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2 ASAN_SYMBOLIZER_PATH=$(which atos) \
+// RUN: not %run %t 2>&1 | FileCheck %s
+//
+// Due to a bug in atos, this only works on x86_64.
+// REQUIRES: x86_64
+
+#include <stdlib.h>
+#include <string.h>
+int main(int argc, char **argv) {
+ char *x = (char*)malloc(10 * sizeof(char));
+ memset(x, 0, 10);
+ int res = x[argc];
+ free(x);
+ free(x + argc - 1); // BOOM
+ // CHECK: AddressSanitizer: attempting double-free{{.*}}in thread T0
+ // CHECK: Using atos at user-specified path:
+ // CHECK: #0 0x{{.*}} in {{.*}}free
+ // CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer.cc:[[@LINE-4]]
+ // CHECK: freed by thread T0 here:
+ // CHECK: #0 0x{{.*}} in {{.*}}free
+ // CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer.cc:[[@LINE-8]]
+ // CHECK: allocated by thread T0 here:
+ // CHECK: atos-symbolizer.cc:[[@LINE-13]]
+ return res;
+}
diff --git a/test/asan/TestCases/Darwin/atos-symbolizer.cc b/test/asan/TestCases/Darwin/atos-symbolizer.cc
new file mode 100644
index 000000000000..03cadf92d16a
--- /dev/null
+++ b/test/asan/TestCases/Darwin/atos-symbolizer.cc
@@ -0,0 +1,24 @@
+// Check that the `atos` symbolizer works.
+
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2 ASAN_SYMBOLIZER_PATH=$(which atos) not %run %t 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+#include <string.h>
+int main(int argc, char **argv) {
+ char *x = (char*)malloc(10 * sizeof(char));
+ memset(x, 0, 10);
+ int res = x[argc];
+ free(x);
+ free(x + argc - 1); // BOOM
+ // CHECK: AddressSanitizer: attempting double-free{{.*}}in thread T0
+ // CHECK: Using atos at user-specified path:
+ // CHECK: #0 0x{{.*}} in {{.*}}free
+ // CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer.cc:[[@LINE-4]]
+ // CHECK: freed by thread T0 here:
+ // CHECK: #0 0x{{.*}} in {{.*}}free
+ // CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer.cc:[[@LINE-8]]
+ // CHECK: allocated by thread T0 here:
+ // CHECK: atos-symbolizer.cc:[[@LINE-13]]
+ return res;
+}
diff --git a/test/asan/TestCases/Darwin/dladdr-demangling.cc b/test/asan/TestCases/Darwin/dladdr-demangling.cc
new file mode 100644
index 000000000000..3d36c4f96355
--- /dev/null
+++ b/test/asan/TestCases/Darwin/dladdr-demangling.cc
@@ -0,0 +1,33 @@
+// In a non-forking sandbox, we fallback to dladdr(). Test that we provide
+// properly demangled C++ names in that case.
+
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2 not %run sandbox-exec -p '(version 1)(allow default)(deny process-fork)' %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-DLADDR
+
+#include <stdlib.h>
+
+class MyClass {
+ public:
+ int my_function(int n) {
+ char *x = (char*)malloc(n * sizeof(char));
+ free(x);
+ return x[5];
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+ // CHECK: {{READ of size 1 at 0x.* thread T0}}
+ // CHECK-DLADDR: Using dladdr symbolizer
+ // CHECK-DLADDR: failed to fork external symbolizer
+ // CHECK: {{ #0 0x.* in MyClass::my_function\(int\)}}
+ // CHECK: {{freed by thread T0 here:}}
+ // CHECK: {{ #0 0x.* in wrap_free}}
+ // CHECK: {{ #1 0x.* in MyClass::my_function\(int\)}}
+ // CHECK: {{previously allocated by thread T0 here:}}
+ // CHECK: {{ #0 0x.* in wrap_malloc}}
+ // CHECK: {{ #1 0x.* in MyClass::my_function\(int\)}}
+ }
+};
+
+int main() {
+ MyClass o;
+ return o.my_function(10);
+}
diff --git a/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc b/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc
index 0bd4170a353c..486223473d47 100644
--- a/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc
+++ b/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc
@@ -7,11 +7,25 @@
// RUN: | sed -e 's/.*"\(.*libclang_rt.asan_osx_dynamic.dylib\)".*/\1/'` \
// RUN: %T/dyld_insert_libraries_reexec/libclang_rt.asan_osx_dynamic.dylib
// RUN: %clangxx_asan %s -o %T/dyld_insert_libraries_reexec/a.out
-// RUN: DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib \
-// RUN: ASAN_OPTIONS=verbosity=1 %run %T/dyld_insert_libraries_reexec/a.out 2>&1 \
+
+// RUN: env DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib \
+// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1 %run %T/dyld_insert_libraries_reexec/a.out 2>&1 \
// RUN: | FileCheck %s
-// RUN: ASAN_OPTIONS=verbosity=1 %run %T/dyld_insert_libraries_reexec/a.out 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-NOINSERT %s
+
+// RUN: IS_OSX_10_11_OR_HIGHER=$([ `sw_vers -productVersion | cut -d'.' -f2` -lt 11 ]; echo $?)
+
+// On OS X 10.10 and lower, if the dylib is not DYLD-inserted, ASan will re-exec.
+// RUN: if [ $IS_OSX_10_11_OR_HIGHER == 0 ]; then \
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1 %run %T/dyld_insert_libraries_reexec/a.out 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-NOINSERT %s; \
+// RUN: fi
+
+// On OS X 10.11 and higher, we don't need to DYLD-insert anymore, and the interceptors
+// still installed correctly. Let's just check that things work and we don't try to re-exec.
+// RUN: if [ $IS_OSX_10_11_OR_HIGHER == 1 ]; then \
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1 %run %T/dyld_insert_libraries_reexec/a.out 2>&1 \
+// RUN: | FileCheck %s; \
+// RUN: fi
#include <stdio.h>
diff --git a/test/asan/TestCases/Darwin/empty-section.cc b/test/asan/TestCases/Darwin/empty-section.cc
new file mode 100644
index 000000000000..5b006b545488
--- /dev/null
+++ b/test/asan/TestCases/Darwin/empty-section.cc
@@ -0,0 +1,12 @@
+// Regression test with an empty (length = 0) custom section.
+
+// RUN: %clangxx_asan -g -O0 %s -c -o %t.o
+// RUN: %clangxx_asan -g -O0 %t.o -o %t -sectcreate mysegment mysection /dev/null
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+
+int main() {
+ printf("Hello, world!\n");
+ // CHECK: Hello, world!
+}
diff --git a/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc b/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc
deleted file mode 100644
index 028683d2fc41..000000000000
--- a/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-// Check that memset() call from a shared library gets intercepted.
-// Please always keep this file in sync with
-// ../Linux/interception-in-shared-lib-test.cc.
-
-// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
-// RUN: -shared -o %t-so.so \
-// RUN: -fPIC -install_name @rpath/interception-in-shared-lib-test.cc.tmp-so.so
-// TODO(glider): figure out how to set rpath in a more portable way and unite
-// this test with ../Linux/interception-in-shared-lib-test.cc.
-// RUN: %clangxx_asan -O0 %s -o %t -Wl,-rpath,@executable_path %t-so.so && \
-// RUN: not %run %t 2>&1 | FileCheck %s
-
-#include <stdio.h>
-#include <string.h>
-
-#if defined(SHARED_LIB)
-extern "C"
-void my_memset(void *p, size_t sz) {
- memset(p, 0, sz);
-}
-#else
-extern "C" void my_memset(void *p, size_t sz);
-
-int main(int argc, char *argv[]) {
- char buf[10];
- my_memset(buf, 11);
- // CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
- // CHECK: {{WRITE of size 11 at 0x.* thread T0}}
- // CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:19}}
- return 0;
-}
-#endif
diff --git a/test/asan/TestCases/Darwin/interface_symbols_darwin.c b/test/asan/TestCases/Darwin/interface_symbols_darwin.c
index a75044d491fb..bd9bbee84a92 100644
--- a/test/asan/TestCases/Darwin/interface_symbols_darwin.c
+++ b/test/asan/TestCases/Darwin/interface_symbols_darwin.c
@@ -29,6 +29,18 @@
// RUN: echo __asan_report_store16 >> %t.interface
// RUN: echo __asan_report_load_n >> %t.interface
// RUN: echo __asan_report_store_n >> %t.interface
+// RUN: echo __asan_report_exp_load1 >> %t.interface
+// RUN: echo __asan_report_exp_load2 >> %t.interface
+// RUN: echo __asan_report_exp_load4 >> %t.interface
+// RUN: echo __asan_report_exp_load8 >> %t.interface
+// RUN: echo __asan_report_exp_load16 >> %t.interface
+// RUN: echo __asan_report_exp_store1 >> %t.interface
+// RUN: echo __asan_report_exp_store2 >> %t.interface
+// RUN: echo __asan_report_exp_store4 >> %t.interface
+// RUN: echo __asan_report_exp_store8 >> %t.interface
+// RUN: echo __asan_report_exp_store16 >> %t.interface
+// RUN: echo __asan_report_exp_load_n >> %t.interface
+// RUN: echo __asan_report_exp_store_n >> %t.interface
// RUN: echo __asan_get_current_fake_stack >> %t.interface
// RUN: echo __asan_addr_is_in_fake_stack >> %t.interface
// RUN: echo __asan_mz_calloc >> %t.interface
diff --git a/test/asan/TestCases/Darwin/reexec-insert-libraries-env.cc b/test/asan/TestCases/Darwin/reexec-insert-libraries-env.cc
index 59ddd634b400..aa4d92b00a01 100644
--- a/test/asan/TestCases/Darwin/reexec-insert-libraries-env.cc
+++ b/test/asan/TestCases/Darwin/reexec-insert-libraries-env.cc
@@ -7,7 +7,7 @@
// RUN: -dynamiclib -o darwin-dummy-shared-lib-so.dylib
// FIXME: the following command line may hang in the case of a regression.
-// RUN: DYLD_INSERT_LIBRARIES=darwin-dummy-shared-lib-so.dylib \
+// RUN: env DYLD_INSERT_LIBRARIES=darwin-dummy-shared-lib-so.dylib \
// RUN: %run %t 2>&1 | FileCheck %s || exit 1
#if !defined(SHARED_LIB)
diff --git a/test/asan/TestCases/Darwin/sandbox-symbolizer.cc b/test/asan/TestCases/Darwin/sandbox-symbolizer.cc
new file mode 100644
index 000000000000..4310f9c599e3
--- /dev/null
+++ b/test/asan/TestCases/Darwin/sandbox-symbolizer.cc
@@ -0,0 +1,29 @@
+// In a non-forking sandbox, we can't spawn an external symbolizer, but dladdr()
+// should still work and provide function names. No line numbers though.
+// Second, `atos` symbolizer can't inspect a process that has an inaccessible
+// task port, in which case we should again fallback to dladdr gracefully.
+
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny process-fork)' %t 2>&1 | FileCheck %s
+// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s
+// RUN: env ASAN_SYMBOLIZER_PATH="" not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -o %t
+// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny process-fork)' %t 2>&1 | FileCheck %s
+// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s
+// RUN: env ASAN_SYMBOLIZER_PATH="" not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+int main() {
+ char *x = (char*)malloc(10 * sizeof(char));
+ free(x);
+ return x[5];
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+ // CHECK: {{READ of size 1 at 0x.* thread T0}}
+ // CHECK: {{ #0 0x.* in main}}
+ // CHECK: {{freed by thread T0 here:}}
+ // CHECK: {{ #0 0x.* in wrap_free}}
+ // CHECK: {{ #1 0x.* in main}}
+ // CHECK: {{previously allocated by thread T0 here:}}
+ // CHECK: {{ #0 0x.* in wrap_malloc}}
+ // CHECK: {{ #1 0x.* in main}}
+}
diff --git a/test/asan/TestCases/Darwin/suppressions-darwin.cc b/test/asan/TestCases/Darwin/suppressions-darwin.cc
index fb37296d404f..488bff140225 100644
--- a/test/asan/TestCases/Darwin/suppressions-darwin.cc
+++ b/test/asan/TestCases/Darwin/suppressions-darwin.cc
@@ -4,17 +4,17 @@
// Check that suppressing the interceptor by name works.
// RUN: echo "interceptor_name:memmove" > %t.supp
-// RUN: ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
// Check that suppressing by interceptor name works even without the symbolizer
-// RUN: ASAN_OPTIONS="suppressions='%t.supp':symbolize=false" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp':symbolize=false" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
// Check that suppressing all reports from a library works.
// RUN: echo "interceptor_via_lib:CoreFoundation" > %t.supp
-// RUN: ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
// Check that suppressing library works even without the symbolizer.
-// RUN: ASAN_OPTIONS="suppressions='%t.supp':symbolize=false" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp':symbolize=false" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
#include <CoreFoundation/CoreFoundation.h>
diff --git a/test/asan/TestCases/Darwin/suppressions-sandbox.cc b/test/asan/TestCases/Darwin/suppressions-sandbox.cc
new file mode 100644
index 000000000000..47d80f80db2b
--- /dev/null
+++ b/test/asan/TestCases/Darwin/suppressions-sandbox.cc
@@ -0,0 +1,26 @@
+// Check that without suppressions, we catch the issue.
+// RUN: %clangxx_asan -O0 %s -o %t -framework Foundation
+// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
+
+// Check that suppressing a function name works within a no-fork sandbox
+// RUN: echo "interceptor_via_fun:CFStringCreateWithBytes" > %t.supp
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:suppressions=%t.supp \
+// RUN: sandbox-exec -p '(version 1)(allow default)(deny process-fork)' \
+// RUN: %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+
+#include <CoreFoundation/CoreFoundation.h>
+
+int main() {
+ char *a = (char *)malloc(6);
+ strcpy(a, "hello");
+ CFStringRef str =
+ CFStringCreateWithBytes(kCFAllocatorDefault, (unsigned char *)a, 10,
+ kCFStringEncodingUTF8, FALSE); // BOOM
+ fprintf(stderr, "Ignored.\n");
+ free(a);
+}
+
+// CHECK-CRASH: AddressSanitizer: heap-buffer-overflow
+// CHECK-CRASH-NOT: Ignored.
+// CHECK-IGNORE-NOT: AddressSanitizer: heap-buffer-overflow
+// CHECK-IGNORE: Ignored.
diff --git a/test/asan/TestCases/Darwin/unset-insert-libraries-on-exec.cc b/test/asan/TestCases/Darwin/unset-insert-libraries-on-exec.cc
index ed476b223af3..f8a330ad5fe0 100644
--- a/test/asan/TestCases/Darwin/unset-insert-libraries-on-exec.cc
+++ b/test/asan/TestCases/Darwin/unset-insert-libraries-on-exec.cc
@@ -10,7 +10,7 @@
// execl().
// RUN: %run %t %T/echo-env >/dev/null 2>&1
-// RUN: DYLD_INSERT_LIBRARIES=%t-darwin-dummy-shared-lib-so.dylib \
+// RUN: env DYLD_INSERT_LIBRARIES=%t-darwin-dummy-shared-lib-so.dylib \
// RUN: %run %t %T/echo-env 2>&1 | FileCheck %s || exit 1
#if !defined(SHARED_LIB)
diff --git a/test/asan/TestCases/Helpers/init-order-pthread-create-extra.cc b/test/asan/TestCases/Helpers/init-order-pthread-create-extra.cc
index d4606f0afb52..54f26f16724c 100644
--- a/test/asan/TestCases/Helpers/init-order-pthread-create-extra.cc
+++ b/test/asan/TestCases/Helpers/init-order-pthread-create-extra.cc
@@ -1,2 +1,2 @@
-void *bar(void *input);
-void *glob2 = bar((void*)0x2345);
+void *bar(void *input, bool sleep_before_init);
+void *glob2 = bar((void*)0x2345, true);
diff --git a/test/asan/TestCases/Linux/asan_default_suppressions.cc b/test/asan/TestCases/Linux/asan_default_suppressions.cc
new file mode 100644
index 000000000000..5ff59c1dfe7f
--- /dev/null
+++ b/test/asan/TestCases/Linux/asan_default_suppressions.cc
@@ -0,0 +1,7 @@
+// Test that we use the suppressions from __asan_default_suppressions.
+// RUN: %clangxx_asan %s -o %t && not %run %t 2>&1 | FileCheck %s
+extern "C" {
+ const char *__asan_default_suppressions() { return "FooBar"; }
+}
+// CHECK: AddressSanitizer: failed to parse suppressions
+int main() {}
diff --git a/test/asan/TestCases/Linux/asan_prelink_test.cc b/test/asan/TestCases/Linux/asan_prelink_test.cc
index 6145c01f7342..9e58f83d40c6 100644
--- a/test/asan/TestCases/Linux/asan_prelink_test.cc
+++ b/test/asan/TestCases/Linux/asan_prelink_test.cc
@@ -7,7 +7,7 @@
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so -Wl,-Ttext-segment=0x3600000000 ||\
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so -Wl,-Ttext=0x3600000000
// RUN: %clangxx_asan %t.o %t.so -Wl,-R. -o %t
-// RUN: ASAN_OPTIONS=verbosity=1 %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1 %run %t 2>&1 | FileCheck %s
// GNU driver doesn't handle .so files properly.
// REQUIRES: x86_64-supported-target, asan-64-bits, Clang
diff --git a/test/asan/TestCases/Linux/asan_preload_test-1.cc b/test/asan/TestCases/Linux/asan_preload_test-1.cc
index e5eab5545b83..4e365b5633f3 100644
--- a/test/asan/TestCases/Linux/asan_preload_test-1.cc
+++ b/test/asan/TestCases/Linux/asan_preload_test-1.cc
@@ -5,7 +5,7 @@
// RUN: %clangxx %s %t.so -o %t
//
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so
-// RUN: LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
+// RUN: env LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
// REQUIRES: asan-dynamic-runtime
diff --git a/test/asan/TestCases/Linux/asan_preload_test-2.cc b/test/asan/TestCases/Linux/asan_preload_test-2.cc
index 0f22264cf1fb..488fd52e682a 100644
--- a/test/asan/TestCases/Linux/asan_preload_test-2.cc
+++ b/test/asan/TestCases/Linux/asan_preload_test-2.cc
@@ -1,7 +1,7 @@
// Test that preloaded runtime works with unsanitized executables.
//
// RUN: %clangxx %s -o %t
-// RUN: LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
+// RUN: env LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
// REQUIRES: asan-dynamic-runtime
diff --git a/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc b/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc
index 30f1c17700c8..8cf761c905f8 100644
--- a/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc
+++ b/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc
@@ -2,7 +2,7 @@
// executable is prohibited.
//
// RUN: %clangxx_asan_static %s -o %t
-// RUN: LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
+// RUN: env LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
// REQUIRES: asan-dynamic-runtime
// XFAIL: android
diff --git a/test/asan/TestCases/Linux/clang_gcc_abi.cc b/test/asan/TestCases/Linux/clang_gcc_abi.cc
index e833881661d2..669d1524077c 100644
--- a/test/asan/TestCases/Linux/clang_gcc_abi.cc
+++ b/test/asan/TestCases/Linux/clang_gcc_abi.cc
@@ -8,9 +8,10 @@
#include <stdlib.h>
+__attribute__((noinline))
int boom() {
volatile int three = 3;
- char *s = (char *)malloc(three);
+ char * volatile s = (char *)malloc(three);
// CHECK: #1 0x{{.*}} in boom {{.*}}clang_gcc_abi.cc:[[@LINE-1]]
return s[three]; //BOOM
}
diff --git a/test/asan/TestCases/Linux/coverage-levels.cc b/test/asan/TestCases/Linux/coverage-levels.cc
deleted file mode 100644
index cc196c5a9e18..000000000000
--- a/test/asan/TestCases/Linux/coverage-levels.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-// Test various levels of coverage
-//
-// RUN: %clangxx_asan -O1 -fsanitize-coverage=1 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1:coverage_bitset=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
-// RUN: %clangxx_asan -O1 -fsanitize-coverage=2 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1:coverage_bitset=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2
-// RUN: %clangxx_asan -O1 -fsanitize-coverage=3 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1:coverage_bitset=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3
-
-// RUN: ASAN_OPTIONS=coverage=1:coverage_bitset=0:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOBITSET
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOBITSET
-// RUN: ASAN_OPTIONS=coverage=1:coverage_pcs=0:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOPCS
-//
-// REQUIRES: asan-64-bits
-
-volatile int sink;
-int main(int argc, char **argv) {
- if (argc == 0)
- sink = 0;
-}
-
-// CHECK1: CovDump: bitset of 1 bits written, 1 bits are set
-// CHECK1: 1 PCs written
-// CHECK2: CovDump: bitset of 3 bits written, 2 bits are set
-// CHECK2: 2 PCs written
-// CHECK3: CovDump: bitset of 4 bits written, 3 bits are set
-// CHECK3: 3 PCs written
-// CHECK3_NOBITSET-NOT: bitset of
-// CHECK3_NOPCS-NOT: PCs written
diff --git a/test/asan/TestCases/Linux/coverage-missing.cc b/test/asan/TestCases/Linux/coverage-missing.cc
new file mode 100644
index 000000000000..36f33b505e27
--- /dev/null
+++ b/test/asan/TestCases/Linux/coverage-missing.cc
@@ -0,0 +1,84 @@
+// Test for "sancov.py missing ...".
+
+// RUN: export ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_dir=%T/coverage-missing
+
+// First case: coverage from executable. main() is called on every code path.
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t -DFOOBAR -DMAIN
+// RUN: rm -rf %T/coverage-missing
+// RUN: mkdir -p %T/coverage-missing
+// RUN: cd %T/coverage-missing
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t
+// RUN: %sancov print *.sancov > main.txt
+// RUN: rm *.sancov
+// RUN: [ $(cat main.txt | wc -l) == 1 ]
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x
+// RUN: %sancov print *.sancov > foo.txt
+// RUN: rm *.sancov
+// RUN: [ $(cat foo.txt | wc -l) == 3 ]
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x x
+// RUN: %sancov print *.sancov > bar.txt
+// RUN: rm *.sancov
+// RUN: [ $(cat bar.txt | wc -l) == 4 ]
+// RUN: %sancov missing %t < foo.txt > foo-missing.txt
+// RUN: sort main.txt foo-missing.txt -o foo-missing-with-main.txt
+// The "missing from foo" set may contain a few bogus PCs from the sanitizer
+// runtime, but it must include the entire "bar" code path as a subset. Sorted
+// lists can be tested for set inclusion with diff + grep.
+// RUN: ( diff bar.txt foo-missing-with-main.txt || true ) | not grep "^<"
+
+// Second case: coverage from DSO.
+// cd %T
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %dynamiclib -DFOOBAR -shared -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=func %s %dynamiclib -o %t -DMAIN
+// RUN: export LIBNAME=`basename %dynamiclib`
+// RUN: rm -rf %T/coverage-missing
+// RUN: mkdir -p %T/coverage-missing
+// RUN: cd %T/coverage-missing
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x
+// RUN: %sancov print $LIBNAME.*.sancov > foo.txt
+// RUN: rm *.sancov
+// RUN: [ $(cat foo.txt | wc -l) == 2 ]
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x x
+// RUN: %sancov print $LIBNAME.*.sancov > bar.txt
+// RUN: rm *.sancov
+// RUN: [ $(cat bar.txt | wc -l) == 3 ]
+// RUN: %sancov missing %dynamiclib < foo.txt > foo-missing.txt
+// RUN: ( diff bar.txt foo-missing.txt || true ) | not grep "^<"
+
+// REQUIRES: x86_64-supported-target, i386-supported-target
+// XFAIL: android
+
+#include <stdio.h>
+
+void foo1();
+void foo2();
+void bar1();
+void bar2();
+void bar3();
+
+#if defined(FOOBAR)
+void foo1() { fprintf(stderr, "foo1\n"); }
+void foo2() { fprintf(stderr, "foo2\n"); }
+
+void bar1() { fprintf(stderr, "bar1\n"); }
+void bar2() { fprintf(stderr, "bar2\n"); }
+void bar3() { fprintf(stderr, "bar3\n"); }
+#endif
+
+#if defined(MAIN)
+int main(int argc, char **argv) {
+ switch (argc) {
+ case 1:
+ break;
+ case 2:
+ foo1();
+ foo2();
+ break;
+ case 3:
+ bar1();
+ bar2();
+ bar3();
+ break;
+ }
+}
+#endif
diff --git a/test/asan/TestCases/Linux/coverage-tracing.cc b/test/asan/TestCases/Linux/coverage-tracing.cc
deleted file mode 100644
index 49dbb5e9528b..000000000000
--- a/test/asan/TestCases/Linux/coverage-tracing.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-// Test -mllvm -sanitizer-coverage-experimental-tracing
-//
-// RUN: %clangxx_asan -O1 -fsanitize-coverage=1 -mllvm -sanitizer-coverage-experimental-tracing %s -o %t
-// RUN: rm -rf %T/coverage-tracing
-// RUN: mkdir %T/coverage-tracing
-// RUN: cd %T/coverage-tracing
-// RUN: A=x; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK1; mv trace-points.*.sancov $A.points
-// RUN: A=f; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK2; mv trace-points.*.sancov $A.points
-// RUN: A=b; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK2; mv trace-points.*.sancov $A.points
-// RUN: A=bf; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK3; mv trace-points.*.sancov $A.points
-// RUN: A=fb; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK3; mv trace-points.*.sancov $A.points
-// RUN: A=ffb; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK4; mv trace-points.*.sancov $A.points
-// RUN: A=fff; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK4; mv trace-points.*.sancov $A.points
-// RUN: A=bbf; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 100 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK301; mv trace-points.*.sancov $A.points
-// RUN: diff f.points fff.points
-// RUN: diff bf.points fb.points
-// RUN: diff bf.points ffb.points
-// RUN: diff bf.points bbf.points
-// RUN: not diff x.points f.points
-// RUN: not diff x.points b.points
-// RUN: not diff x.points bf.points
-// RUN: not diff f.points b.points
-// RUN: not diff f.points bf.points
-// RUN: not diff b.points bf.points
-// RUN: rm -rf %T/coverage-tracing
-//
-// REQUIRES: asan-64-bits
-
-#include <stdlib.h>
-volatile int sink;
-__attribute__((noinline)) void foo() { sink++; }
-__attribute__((noinline)) void bar() { sink++; }
-
-int main(int argc, char **argv) {
- if (argc != 3) return 0;
- int n = strtol(argv[2], 0, 10);
- while (n-- > 0) {
- for (int i = 0; argv[1][i]; i++) {
- if (argv[1][i] == 'f') foo();
- else if (argv[1][i] == 'b') bar();
- }
- }
-}
-
-// CHECK: CovDump: Trace: 3 PCs written
-// CHECK1: CovDump: Trace: 1 Events written
-// CHECK2: CovDump: Trace: 2 Events written
-// CHECK3: CovDump: Trace: 3 Events written
-// CHECK4: CovDump: Trace: 4 Events written
-// CHECK301: CovDump: Trace: 301 Events written
diff --git a/test/asan/TestCases/Linux/init-order-dlopen.cc b/test/asan/TestCases/Linux/init-order-dlopen.cc
new file mode 100644
index 000000000000..fcfb5d143df6
--- /dev/null
+++ b/test/asan/TestCases/Linux/init-order-dlopen.cc
@@ -0,0 +1,47 @@
+// Regression test for
+// https://code.google.com/p/address-sanitizer/issues/detail?id=178
+
+// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so
+// RUN: %clangxx_asan -O0 %s %libdl -Wl,--export-dynamic -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true %run %t 2>&1
+
+// dlopen() can not be intercepted on Android, making strict_init_order nearly
+// useless there.
+// UNSUPPORTED: android
+
+#if defined(SHARED_LIB)
+#include <stdio.h>
+
+struct Bar {
+ Bar(int val) : val(val) { printf("Bar::Bar(%d)\n", val); }
+ int val;
+};
+
+int get_foo_val();
+Bar global_bar(get_foo_val());
+#else // SHARED LIB
+#include <dlfcn.h>
+#include <stdio.h>
+#include <string>
+struct Foo {
+ Foo() : val(42) { printf("Foo::Foo()\n"); }
+ int val;
+};
+
+Foo global_foo;
+
+int get_foo_val() {
+ return global_foo.val;
+}
+
+int main(int argc, char *argv[]) {
+ std::string path = std::string(argv[0]) + "-so.so";
+ void *handle = dlopen(path.c_str(), RTLD_NOW);
+ if (!handle) {
+ printf("error in dlopen(): %s\n", dlerror());
+ return 1;
+ }
+ printf("%d\n", get_foo_val());
+ return 0;
+}
+#endif // SHARED_LIB
diff --git a/test/asan/TestCases/Linux/initialization-bug-any-order.cc b/test/asan/TestCases/Linux/initialization-bug-any-order.cc
index a462f4a163f1..0f2fccae79bb 100644
--- a/test/asan/TestCases/Linux/initialization-bug-any-order.cc
+++ b/test/asan/TestCases/Linux/initialization-bug-any-order.cc
@@ -4,9 +4,9 @@
// strict init-order checking).
// RUN: %clangxx_asan -O0 %s %p/../Helpers/initialization-bug-extra.cc -o %t
-// RUN: ASAN_OPTIONS=strict_init_order=true not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O0 %p/../Helpers/initialization-bug-extra.cc %s -o %t
-// RUN: ASAN_OPTIONS=strict_init_order=true not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true not %run %t 2>&1 | FileCheck %s
// Do not test with optimization -- the error may be optimized away.
diff --git a/test/asan/TestCases/Linux/interface_symbols_linux.c b/test/asan/TestCases/Linux/interface_symbols_linux.c
index a616732ff9f8..9e876799d384 100644
--- a/test/asan/TestCases/Linux/interface_symbols_linux.c
+++ b/test/asan/TestCases/Linux/interface_symbols_linux.c
@@ -24,8 +24,22 @@
// RUN: echo __asan_report_store16 >> %t.interface
// RUN: echo __asan_report_load_n >> %t.interface
// RUN: echo __asan_report_store_n >> %t.interface
+// RUN: echo __asan_report_exp_load1 >> %t.interface
+// RUN: echo __asan_report_exp_load2 >> %t.interface
+// RUN: echo __asan_report_exp_load4 >> %t.interface
+// RUN: echo __asan_report_exp_load8 >> %t.interface
+// RUN: echo __asan_report_exp_load16 >> %t.interface
+// RUN: echo __asan_report_exp_store1 >> %t.interface
+// RUN: echo __asan_report_exp_store2 >> %t.interface
+// RUN: echo __asan_report_exp_store4 >> %t.interface
+// RUN: echo __asan_report_exp_store8 >> %t.interface
+// RUN: echo __asan_report_exp_store16 >> %t.interface
+// RUN: echo __asan_report_exp_load_n >> %t.interface
+// RUN: echo __asan_report_exp_store_n >> %t.interface
// RUN: echo __asan_get_current_fake_stack >> %t.interface
// RUN: echo __asan_addr_is_in_fake_stack >> %t.interface
+// RUN: echo __asan_alloca_poison >> %t.interface
+// RUN: echo __asan_allocas_unpoison >> %t.interface
// RUN: cat %t.interface | sort -u | diff %t.symbols -
// FIXME: nm -D on powerpc somewhy shows ASan interface symbols residing
diff --git a/test/asan/TestCases/Linux/kernel-area.cc b/test/asan/TestCases/Linux/kernel-area.cc
index 8dd509f84975..8d3f7d6f8e88 100644
--- a/test/asan/TestCases/Linux/kernel-area.cc
+++ b/test/asan/TestCases/Linux/kernel-area.cc
@@ -4,19 +4,19 @@
// Test that kernel area is not sanitized on 32-bit machines.
//
// RUN: %clangxx_asan %s -o %t
-// RUN: ASAN_OPTIONS=verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits
-// RUN: ASAN_OPTIONS=verbosity=1:full_address_space=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits
-// RUN: ASAN_OPTIONS=verbosity=1:full_address_space=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-kernel-64-bits
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1:full_address_space=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1:full_address_space=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-kernel-64-bits
//
-// CHECK-kernel-32-bits: || `[0x38000000, 0xbfffffff]` || HighMem ||
-// CHECK-kernel-32-bits: || `[0x27000000, 0x37ffffff]` || HighShadow ||
-// CHECK-kernel-32-bits: || `[0x24000000, 0x26ffffff]` || ShadowGap ||
+// CHECK-kernel-32-bits: || `[0x38{{0+}}, 0xb{{f+}}]` || HighMem ||
+// CHECK-kernel-32-bits: || `[0x27{{0+}}, 0x37{{f+}}]` || HighShadow ||
+// CHECK-kernel-32-bits: || `[0x24{{0+}}, 0x26{{f+}}]` || ShadowGap ||
//
-// CHECK-kernel-64-bits: || `[0x40000000, 0xffffffff]` || HighMem ||
-// CHECK-kernel-64-bits: || `[0x28000000, 0x3fffffff]` || HighShadow ||
-// CHECK-kernel-64-bits: || `[0x24000000, 0x27ffffff]` || ShadowGap ||
+// CHECK-kernel-64-bits: || `[0x4{{0+}}, 0x{{f+}}]` || HighMem ||
+// CHECK-kernel-64-bits: || `[0x28{{0+}}, 0x3{{f+}}]` || HighShadow ||
+// CHECK-kernel-64-bits: || `[0x24{{0+}}, 0x27{{f+}}]` || ShadowGap ||
//
-// REQUIRES: asan-32-bits
+// REQUIRES: asan-32-bits,i386-supported-target
int main() {
return 0;
diff --git a/test/asan/TestCases/Linux/leak.cc b/test/asan/TestCases/Linux/leak.cc
index 36dc6ddb8adf..15c03b45e4c9 100644
--- a/test/asan/TestCases/Linux/leak.cc
+++ b/test/asan/TestCases/Linux/leak.cc
@@ -2,9 +2,9 @@
// REQUIRES: leak-detection
//
// RUN: %clangxx_asan %s -o %t
-// RUN: ASAN_OPTIONS=detect_leaks=1 not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS="" not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=detect_leaks=0 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:detect_leaks=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:detect_leaks=0 %run %t
#include <stdio.h>
int *t;
diff --git a/test/asan/TestCases/Linux/leak_check_segv.cc b/test/asan/TestCases/Linux/leak_check_segv.cc
new file mode 100644
index 000000000000..8160d5fe56bb
--- /dev/null
+++ b/test/asan/TestCases/Linux/leak_check_segv.cc
@@ -0,0 +1,23 @@
+// Test that SIGSEGV during leak checking does not crash the process.
+// RUN: %clangxx_asan -O1 %s -o %t && LSAN_OPTIONS="verbosity=1" not %run %t 2>&1
+// REQUIRES: leak-detection
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <sanitizer/lsan_interface.h>
+
+char data[10 * 1024 * 1024];
+
+int main() {
+ void *p = malloc(10 * 1024 * 1024);
+ // surprise-surprise!
+ mprotect((void*)(((unsigned long)p + 4095) & ~4095), 16 * 1024, PROT_NONE);
+ mprotect((void*)(((unsigned long)data + 4095) & ~4095), 16 * 1024, PROT_NONE);
+ __lsan_do_leak_check();
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: Tracer caught signal 11
+// CHECK: LeakSanitizer has encountered a fatal error
+// CHECK-NOT: DONE
+
diff --git a/test/asan/TestCases/Linux/malloc-in-qsort.cc b/test/asan/TestCases/Linux/malloc-in-qsort.cc
index 80af409d66a9..f7c7c5fe3df7 100644
--- a/test/asan/TestCases/Linux/malloc-in-qsort.cc
+++ b/test/asan/TestCases/Linux/malloc-in-qsort.cc
@@ -1,6 +1,6 @@
// RUN: %clangxx_asan -O2 %s -o %t
-// RUN: ASAN_OPTIONS=fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST
-// RUN: ASAN_OPTIONS=fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SLOW
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SLOW
// Test how well we unwind in presence of qsort in the stack
// (i.e. if we can unwind through a function compiled w/o frame pointers).
diff --git a/test/asan/TestCases/Linux/malloc_delete_mismatch.cc b/test/asan/TestCases/Linux/malloc_delete_mismatch.cc
index 18d65ce0008f..33d0ede15f3c 100644
--- a/test/asan/TestCases/Linux/malloc_delete_mismatch.cc
+++ b/test/asan/TestCases/Linux/malloc_delete_mismatch.cc
@@ -4,14 +4,14 @@
// RUN: %clangxx_asan -g %s -o %t 2>&1
// Find error and provide malloc context.
-// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALLOC-STACK
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALLOC-STACK
// No error here.
-// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=0 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=0 %run %t
// Also works if no malloc context is available.
-// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
// XFAIL: arm-linux-gnueabi
// XFAIL: armv7l-unknown-linux-gnueabihf
#include <stdlib.h>
diff --git a/test/asan/TestCases/Linux/nohugepage_test.cc b/test/asan/TestCases/Linux/nohugepage_test.cc
index b549f3bc2119..aeb70c94ec99 100644
--- a/test/asan/TestCases/Linux/nohugepage_test.cc
+++ b/test/asan/TestCases/Linux/nohugepage_test.cc
@@ -3,8 +3,8 @@
// where asan consumed too much RAM due to transparent hugetables.
//
// RUN: %clangxx_asan -g %s -o %t
-// RUN: ASAN_OPTIONS=no_huge_pages_for_shadow=1 %run %t 2>&1 | FileCheck %s
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:no_huge_pages_for_shadow=1 %run %t 2>&1 | FileCheck %s
+// RUN: %run %t 2>&1 | FileCheck %s
//
// Would be great to run the test with no_huge_pages_for_shadow=0, but
// the result will depend on the OS version and settings...
@@ -22,15 +22,31 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include <errno.h>
#include <sanitizer/asan_interface.h>
-char FileContents[1 << 14];
+char FileContents[1 << 16];
void FileToString(const char *path) {
FileContents[0] = 0;
int fd = open(path, 0);
if (fd < 0) return;
- ssize_t res = read(fd, FileContents, sizeof(FileContents) - 1);
+ char *p = FileContents;
+ ssize_t size = sizeof(FileContents) - 1;
+ ssize_t res = 0;
+ do {
+ ssize_t got = read (fd, p, size);
+ if (got == 0)
+ break;
+ else if (got > 0)
+ {
+ p += got;
+ res += got;
+ size -= got;
+ }
+ else if (errno != EINTR)
+ break;
+ } while (size > 0 && res < sizeof(FileContents));
if (res >= 0)
FileContents[res] = 0;
}
diff --git a/test/asan/TestCases/Linux/odr-violation.cc b/test/asan/TestCases/Linux/odr-violation.cc
index ddc68a2db0f1..e9311d16bd5f 100644
--- a/test/asan/TestCases/Linux/odr-violation.cc
+++ b/test/asan/TestCases/Linux/odr-violation.cc
@@ -1,19 +1,27 @@
// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
// XFAIL: android
//
+// We use fast_unwind_on_malloc=0 to have full unwinding even w/o frame
+// pointers. This setting is not on by default because it's too expensive.
+//
// Different size: detect a bug if detect_odr_violation>=1
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so
// RUN: %clangxx_asan %s %t-ODR-SO.so -Wl,-R. -o %t-ODR-EXE
-// RUN: ASAN_OPTIONS=detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
-// RUN: not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
//
// Same size: report a bug only if detect_odr_violation>=2.
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so -DSZ=100
-// RUN: ASAN_OPTIONS=detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
-// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
-// RUN: not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: echo "odr_violation:foo::ZZZ" > %t.supp
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: echo "odr_violation:foo::G" > %t.supp
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: rm -f %t.supp
// GNU driver doesn't handle .so files properly.
// REQUIRES: Clang
diff --git a/test/asan/TestCases/Linux/overflow-in-qsort.cc b/test/asan/TestCases/Linux/overflow-in-qsort.cc
index 21bdff60cd30..26fe67d60729 100644
--- a/test/asan/TestCases/Linux/overflow-in-qsort.cc
+++ b/test/asan/TestCases/Linux/overflow-in-qsort.cc
@@ -1,6 +1,6 @@
// RUN: %clangxx_asan -O2 %s -o %t
-// RUN: ASAN_OPTIONS=fast_unwind_on_fatal=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST
-// RUN: ASAN_OPTIONS=fast_unwind_on_fatal=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SLOW
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_fatal=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_fatal=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SLOW
// Test how well we unwind in presence of qsort in the stack
// (i.e. if we can unwind through a function compiled w/o frame pointers).
diff --git a/test/asan/TestCases/Linux/ptrace.cc b/test/asan/TestCases/Linux/ptrace.cc
index 7e5acb64c7a1..6840ebe28bfd 100644
--- a/test/asan/TestCases/Linux/ptrace.cc
+++ b/test/asan/TestCases/Linux/ptrace.cc
@@ -31,8 +31,8 @@ int main(void) {
// CHECK: AddressSanitizer: stack-buffer-overflow
// CHECK: {{.*ptrace.cc:}}[[@LINE-2]]
assert(!res);
-#if __WORDSIZE == 64
- printf("%zx\n", regs.rip);
+#ifdef __x86_64__
+ printf("%lx\n", (unsigned long)regs.rip);
#else
printf("%lx\n", regs.eip);
#endif
@@ -42,7 +42,7 @@ int main(void) {
assert(!res);
printf("%lx\n", (unsigned long)fpregs.cwd);
-#if __WORDSIZE == 32
+#ifndef __x86_64__
user_fpxregs_struct fpxregs;
res = ptrace(PTRACE_GETFPXREGS, pid, NULL, &fpxregs);
assert(!res);
diff --git a/test/asan/TestCases/Linux/quarantine_size_mb.cc b/test/asan/TestCases/Linux/quarantine_size_mb.cc
index 4499992444f9..1820cb90c4ef 100644
--- a/test/asan/TestCases/Linux/quarantine_size_mb.cc
+++ b/test/asan/TestCases/Linux/quarantine_size_mb.cc
@@ -1,10 +1,10 @@
// Test quarantine_size_mb (and the deprecated quarantine_size)
// RUN: %clangxx_asan %s -o %t
-// RUN: ASAN_OPTIONS=quarantine_size=10485760:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
-// RUN: ASAN_OPTIONS=quarantine_size_mb=10:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
-// RUN: ASAN_OPTIONS=quarantine_size_mb=10:quarantine_size=20:verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=BOTH
-// RUN: ASAN_OPTIONS=quarantine_size_mb=1000:hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
-// RUN: ASAN_OPTIONS=hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size=10485760:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size_mb=10:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size_mb=10:quarantine_size=20:verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=BOTH
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size_mb=1000:hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
#include <string.h>
char *g;
diff --git a/test/asan/TestCases/Linux/read_binary_name_regtest.c b/test/asan/TestCases/Linux/read_binary_name_regtest.c
new file mode 100644
index 000000000000..0e408d0e366d
--- /dev/null
+++ b/test/asan/TestCases/Linux/read_binary_name_regtest.c
@@ -0,0 +1,50 @@
+// Regression test for https://crbug.com/502974, where ASan was unable to read
+// the binary name because of sandbox restrictions.
+// This test uses seccomp-BPF to restrict the readlink() system call and makes
+// sure ASan is still able to
+// RUN: not ls /usr/include/linux/seccomp.h || ( %clang_asan %s -o %t && not %run %t 2>&1 | FileCheck %s )
+// UNSUPPORTED: android
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/prctl.h>
+#include <sys/syscall.h>
+#include <linux/filter.h>
+#include <linux/seccomp.h>
+
+#define syscall_nr (offsetof(struct seccomp_data, nr))
+
+void corrupt() {
+ void *p = malloc(10);
+ free(p);
+ free(p);
+}
+
+int main() {
+ prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
+
+ struct sock_filter filter[] = {
+ /* Grab the system call number */
+ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, syscall_nr),
+ // If this is __NR_readlink,
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __NR_readlink, 0, 1),
+ // return with EPERM,
+ BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ERRNO | EPERM),
+ // otherwise allow the syscall.
+ BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW)
+ };
+ struct sock_fprog prog;
+ prog.len = (unsigned short)(sizeof(filter)/sizeof(filter[0]));
+ prog.filter = filter;
+
+ int res = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog, 0, 0);
+ if (res != 0) {
+ fprintf(stderr, "PR_SET_SECCOMP unsupported!\n");
+ }
+ corrupt();
+ // CHECK: AddressSanitizer
+ // CHECK-NOT: reading executable name failed
+ return 0;
+}
diff --git a/test/asan/TestCases/Linux/signal_during_stop_the_world.cc b/test/asan/TestCases/Linux/signal_during_stop_the_world.cc
new file mode 100644
index 000000000000..b1a41fe20c05
--- /dev/null
+++ b/test/asan/TestCases/Linux/signal_during_stop_the_world.cc
@@ -0,0 +1,60 @@
+// Test StopTheWorld behavior during signal storm.
+// Historically StopTheWorld crashed because did not handle EINTR properly.
+// The test is somewhat convoluted, but that's what caused crashes previously.
+
+// RUN: %clangxx_asan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/prctl.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <pthread.h>
+#include <sanitizer/lsan_interface.h>
+
+static void handler(int signo);
+static void *thr(void *arg);
+
+int main() {
+ struct sigaction act = {};
+ act.sa_handler = handler;
+ sigaction(SIGPROF, &act, 0);
+
+ pid_t pid = fork();
+ if (pid < 0) {
+ fprintf(stderr, "failed to fork\n");
+ exit(1);
+ }
+ if (pid == 0) {
+ // Child constantly sends signals to parent to cause spurious return from
+ // waitpid in StopTheWorld.
+ prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0);
+ pid_t parent = getppid();
+ for (;;) {
+ // There is no strong reason for these two particular signals,
+ // but at least one of them ought to unblock waitpid.
+ kill(parent, SIGCHLD);
+ kill(parent, SIGPROF);
+ }
+ }
+ usleep(10000); // Let the child start.
+ __lsan_do_leak_check();
+ // Kill and join the child.
+ kill(pid, SIGTERM);
+ waitpid(pid, 0, 0);
+ sleep(1); // If the tracer thread still runs, give it time to crash.
+ fprintf(stderr, "DONE\n");
+// CHECK: DONE
+}
+
+static void handler(int signo) {
+}
+
+static void *thr(void *arg) {
+ for (;;)
+ sleep(1);
+ return 0;
+}
diff --git a/test/asan/TestCases/Linux/sized_delete_test.cc b/test/asan/TestCases/Linux/sized_delete_test.cc
index 343cb0a86fed..1146b8239d8c 100644
--- a/test/asan/TestCases/Linux/sized_delete_test.cc
+++ b/test/asan/TestCases/Linux/sized_delete_test.cc
@@ -1,14 +1,10 @@
-// RUN: %clangxx_asan -Xclang -fsized-deallocation -O0 %s -o %t
-// RUN: not %run %t scalar 2>&1 | FileCheck %s -check-prefix=SCALAR
-// RUN: ASAN_OPTIONS=new_delete_type_mismatch=1 not %run %t scalar 2>&1 | FileCheck %s -check-prefix=SCALAR
-// RUN: not %run %t array 2>&1 | FileCheck %s -check-prefix=ARRAY
-// RUN: ASAN_OPTIONS=new_delete_type_mismatch=1 not %run %t array 2>&1 | FileCheck %s -check-prefix=ARRAY
-// RUN: ASAN_OPTIONS=new_delete_type_mismatch=0 %run %t scalar
-// RUN: ASAN_OPTIONS=new_delete_type_mismatch=0 %run %t array
-
-// Sized-delete is implemented with a weak delete() definition.
-// Weak symbols are kind of broken on Android.
-// XFAIL: android, asan-dynamic-runtime
+// RUN: %clangxx_asan -fsized-deallocation -O0 %s -o %t
+// RUN: not %run %t scalar 2>&1 | FileCheck %s -check-prefix=SCALAR
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:new_delete_type_mismatch=1 not %run %t scalar 2>&1 | FileCheck %s -check-prefix=SCALAR
+// RUN: not %run %t array 2>&1 | FileCheck %s -check-prefix=ARRAY
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:new_delete_type_mismatch=1 not %run %t array 2>&1 | FileCheck %s -check-prefix=ARRAY
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:new_delete_type_mismatch=0 %run %t scalar
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:new_delete_type_mismatch=0 %run %t array
#include <new>
#include <stdio.h>
diff --git a/test/asan/TestCases/Linux/stack-overflow-sigbus.cc b/test/asan/TestCases/Linux/stack-overflow-sigbus.cc
index 5f597e9c51f0..23c4d23ce406 100644
--- a/test/asan/TestCases/Linux/stack-overflow-sigbus.cc
+++ b/test/asan/TestCases/Linux/stack-overflow-sigbus.cc
@@ -1,6 +1,6 @@
// Test ASan detection of stack-overflow condition when Linux sends SIGBUS.
-// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
#include <assert.h>
#include <stdio.h>
diff --git a/test/asan/TestCases/Linux/stack-trace-dlclose.cc b/test/asan/TestCases/Linux/stack-trace-dlclose.cc
index b3bd9f7780f5..f207a94ae65e 100644
--- a/test/asan/TestCases/Linux/stack-trace-dlclose.cc
+++ b/test/asan/TestCases/Linux/stack-trace-dlclose.cc
@@ -3,7 +3,7 @@
//
// RUN: %clangxx_asan -DSHARED %s -shared -o %T/stack_trace_dlclose.so -fPIC
// RUN: %clangxx_asan -DSO_DIR=\"%T\" %s %libdl -o %t
-// RUN: ASAN_OPTIONS=exitcode=0 %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:exitcode=0 %run %t 2>&1 | FileCheck %s
// XFAIL: arm-linux-gnueabi
// XFAIL: armv7l-unknown-linux-gnueabihf
@@ -40,6 +40,6 @@ int main(int argc, char **argv) {
}
#endif
-// CHECK: {{ #0 0x.* in malloc}}
+// CHECK: {{ #0 0x.* in (__interceptor_)?malloc}}
// CHECK: {{ #1 0x.* \(<unknown module>\)}}
// CHECK: {{ #2 0x.* in main}}
diff --git a/test/asan/TestCases/Linux/static_tls.cc b/test/asan/TestCases/Linux/static_tls.cc
new file mode 100644
index 000000000000..785228b29238
--- /dev/null
+++ b/test/asan/TestCases/Linux/static_tls.cc
@@ -0,0 +1,29 @@
+// REQUIRES: asan-64-bits
+// Regression test: __tls_get_addr interceptor must recognize static TLS.
+//
+// RUN: %clangxx_asan -DSHARED %s -shared -o %t-so.so -fPIC
+// RUN: %clangxx_asan %s -ldl -pthread -o %t %t-so.so
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2 %run %t 2>&1 | FileCheck %s
+
+// CHECK: before
+// CHECK: __tls_get_addr: static tls
+// CHECK: after
+
+// XFAIL: powerpc64
+
+#ifndef SHARED
+#include <stdio.h>
+
+unsigned *f();
+int main(int argc, char *argv[]) {
+ fprintf(stderr, "before\n");
+ f();
+ fprintf(stderr, "after\n");
+ return 0;
+}
+#else // SHARED
+static __thread unsigned ThreadLocal;
+unsigned *f() {
+ return &ThreadLocal;
+}
+#endif
diff --git a/test/asan/TestCases/Linux/stress_dtls.c b/test/asan/TestCases/Linux/stress_dtls.c
index cb901ee59953..7af33b9457ea 100644
--- a/test/asan/TestCases/Linux/stress_dtls.c
+++ b/test/asan/TestCases/Linux/stress_dtls.c
@@ -12,9 +12,9 @@
// RUN: %clangxx_asan %s -ldl -pthread -o %t
// RUN: %run %t 0 3
// RUN: %run %t 2 3
-// RUN: ASAN_OPTIONS=verbosity=2 %run %t 10 2 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=verbosity=2:intercept_tls_get_addr=1 %run %t 10 2 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=verbosity=2:intercept_tls_get_addr=0 %run %t 10 2 2>&1 | FileCheck %s --check-prefix=CHECK0
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2 %run %t 10 2 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2:intercept_tls_get_addr=1 %run %t 10 2 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2:intercept_tls_get_addr=0 %run %t 10 2 2>&1 | FileCheck %s --check-prefix=CHECK0
// CHECK: __tls_get_addr
// CHECK: Creating thread 0
// CHECK: __tls_get_addr
diff --git a/test/asan/TestCases/Posix/allow_user_segv.cc b/test/asan/TestCases/Posix/allow_user_segv.cc
index b6443fab85df..b299ae8cb21e 100644
--- a/test/asan/TestCases/Posix/allow_user_segv.cc
+++ b/test/asan/TestCases/Posix/allow_user_segv.cc
@@ -1,8 +1,8 @@
// Regression test for
// https://code.google.com/p/address-sanitizer/issues/detail?id=180
-// RUN: %clangxx_asan -O0 %s -o %t && ASAN_OPTIONS=allow_user_segv_handler=true not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O2 %s -o %t && ASAN_OPTIONS=allow_user_segv_handler=true not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -o %t && ASAN_OPTIONS=$ASAN_OPTIONS:allow_user_segv_handler=true not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O2 %s -o %t && ASAN_OPTIONS=$ASAN_OPTIONS:allow_user_segv_handler=true not %run %t 2>&1 | FileCheck %s
#include <signal.h>
#include <stdio.h>
diff --git a/test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc b/test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc
index 3ce6446eca22..043130f9e549 100644
--- a/test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc
+++ b/test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc
@@ -6,7 +6,7 @@
// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so
// RUN: %clangxx_asan -O0 %s %libdl -o %t
-// RUN: env ASAN_OPTIONS=symbolize=0 not %run %t 2>&1 | %asan_symbolize | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:symbolize=0 not %run %t 2>&1 | %asan_symbolize | FileCheck %s
// XFAIL: arm-linux-gnueabi
// XFAIL: armv7l-unknown-linux-gnueabihf
diff --git a/test/asan/TestCases/Linux/coverage-direct-activation.cc b/test/asan/TestCases/Posix/coverage-direct-activation.cc
index 9b2a0d8897c8..af73f5d2952d 100644
--- a/test/asan/TestCases/Linux/coverage-direct-activation.cc
+++ b/test/asan/TestCases/Posix/coverage-direct-activation.cc
@@ -1,18 +1,18 @@
// Test for direct coverage writing enabled at activation time.
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_direct_activation_test_1.so -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %dynamiclib -fPIC
// RUN: %clangxx -c -DSO_DIR=\"%T\" %s -o %t.o
-// RUN: %clangxx_asan -fsanitize-coverage=1 %t.o %libdl -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=func %t.o %libdl -o %t
// RUN: rm -rf %T/coverage-direct-activation
// RUN: mkdir -p %T/coverage-direct-activation/normal
-// RUN: ASAN_OPTIONS=coverage=1,coverage_direct=0,coverage_dir=%T/coverage-direct-activation/normal:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1,coverage_direct=0,coverage_dir=%T/coverage-direct-activation/normal:verbosity=1 %run %t %dynamiclib
// RUN: %sancov print %T/coverage-direct-activation/normal/*.sancov >%T/coverage-direct-activation/normal/out.txt
// RUN: mkdir -p %T/coverage-direct-activation/direct
-// RUN: ASAN_OPTIONS=start_deactivated=1,coverage_direct=1,verbosity=1 \
-// RUN: ASAN_ACTIVATION_OPTIONS=coverage=1,coverage_dir=%T/coverage-direct-activation/direct %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1,coverage_direct=1,verbosity=1 \
+// RUN: ASAN_ACTIVATION_OPTIONS=coverage=1,coverage_dir=%T/coverage-direct-activation/direct %run %t %dynamiclib
// RUN: cd %T/coverage-direct-activation/direct
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
@@ -23,8 +23,8 @@
// RUN: diff -u coverage-direct-activation/normal/out.txt coverage-direct-activation/direct/out.txt
// RUN: mkdir -p %T/coverage-direct-activation/direct2
-// RUN: ASAN_OPTIONS=start_deactivated=1,coverage=1,coverage_direct=1,verbosity=1 \
-// RUN: ASAN_ACTIVATION_OPTIONS=coverage_dir=%T/coverage-direct-activation/direct2 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1,coverage=1,coverage_direct=1,verbosity=1 \
+// RUN: ASAN_ACTIVATION_OPTIONS=coverage_dir=%T/coverage-direct-activation/direct2 %run %t %dynamiclib
// RUN: cd %T/coverage-direct-activation/direct2
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
@@ -47,8 +47,8 @@ void bar() { printf("bar\n"); }
int main(int argc, char **argv) {
fprintf(stderr, "PID: %d\n", getpid());
- void *handle1 =
- dlopen(SO_DIR "/libcoverage_direct_activation_test_1.so", RTLD_LAZY);
+ assert(argc > 1);
+ void *handle1 = dlopen(argv[1], RTLD_LAZY); // %dynamiclib
assert(handle1);
void (*bar1)() = (void (*)())dlsym(handle1, "bar");
assert(bar1);
diff --git a/test/asan/TestCases/Linux/coverage-direct-large.cc b/test/asan/TestCases/Posix/coverage-direct-large.cc
index 25c950e0bb30..2769172c39ab 100644
--- a/test/asan/TestCases/Linux/coverage-direct-large.cc
+++ b/test/asan/TestCases/Posix/coverage-direct-large.cc
@@ -2,18 +2,18 @@
// Current implementation maps output file in chunks of 64K. This test overflows
// 1 chunk.
-// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 -DSHARED %s -shared -o %T/libcoverage_direct_large_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 -DSO_DIR=\"%T\" %s %libdl -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=func -O0 -DSHARED %s -shared -o %dynamiclib -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=func -O0 %s %libdl -o %t
// RUN: rm -rf %T/coverage-direct-large
// RUN: mkdir -p %T/coverage-direct-large/normal && cd %T/coverage-direct-large/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:verbosity=1 %run %t %dynamiclib
// RUN: %sancov print *.sancov >out.txt
// RUN: cd ../..
// RUN: mkdir -p %T/coverage-direct-large/direct && cd %T/coverage-direct-large/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:verbosity=1 %run %t %dynamiclib
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
// RUN: cd ../..
@@ -49,11 +49,11 @@ extern "C" void so_entry() {
#include <assert.h>
#include <dlfcn.h>
-int main(void) {
+#include <stdio.h>
+int main(int argc, char **argv) {
F4(CALL, f)
-
- void *handle1 =
- dlopen(SO_DIR "/libcoverage_direct_large_test_1.so", RTLD_LAZY);
+ assert(argc > 1);
+ void *handle1 = dlopen(argv[1], RTLD_LAZY); // %dynamiclib
assert(handle1);
void (*so_entry)() = (void (*)())dlsym(handle1, "so_entry");
assert(so_entry);
diff --git a/test/asan/TestCases/Linux/coverage-direct.cc b/test/asan/TestCases/Posix/coverage-direct.cc
index 45222fa1a03e..5371a859c24f 100644
--- a/test/asan/TestCases/Linux/coverage-direct.cc
+++ b/test/asan/TestCases/Posix/coverage-direct.cc
@@ -1,16 +1,16 @@
// Test for direct coverage writing with dlopen at coverage level 1 to 3.
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSO_DIR=\"%T\" %s %libdl -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %dynamiclib -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=func %s %libdl -o %t
// RUN: rm -rf %T/coverage-direct
// RUN: mkdir -p %T/coverage-direct/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib
// RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
// RUN: mkdir -p %T/coverage-direct/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib
// RUN: cd %T/coverage-direct/direct
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
@@ -19,17 +19,17 @@
// RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSO_DIR=\"%T\" %s %libdl -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=bb -DSHARED %s -shared -o %dynamiclib -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=bb -DSO_DIR=\"%T\" %s %libdl -o %t
// RUN: rm -rf %T/coverage-direct
// RUN: mkdir -p %T/coverage-direct/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib
// RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
// RUN: mkdir -p %T/coverage-direct/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib
// RUN: cd %T/coverage-direct/direct
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
@@ -38,17 +38,17 @@
// RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt
-// RUN: %clangxx_asan -fsanitize-coverage=3 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=3 -DSO_DIR=\"%T\" %s %libdl -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=edge -DSHARED %s -shared -o %dynamiclib -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=edge -DSO_DIR=\"%T\" %s %libdl -o %t
// RUN: rm -rf %T/coverage-direct
// RUN: mkdir -p %T/coverage-direct/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib
// RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
// RUN: mkdir -p %T/coverage-direct/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib
// RUN: cd %T/coverage-direct/direct
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
@@ -71,8 +71,8 @@ void bar() { printf("bar\n"); }
int main(int argc, char **argv) {
fprintf(stderr, "PID: %d\n", getpid());
- void *handle1 =
- dlopen(SO_DIR "/libcoverage_direct_test_1.so", RTLD_LAZY);
+ assert(argc > 1);
+ void *handle1 = dlopen(argv[1], RTLD_LAZY);
assert(handle1);
void (*bar1)() = (void (*)())dlsym(handle1, "bar");
assert(bar1);
diff --git a/test/asan/TestCases/Linux/coverage-fork-direct.cc b/test/asan/TestCases/Posix/coverage-fork-direct.cc
index 51cbbd821b8e..39363911fec3 100644
--- a/test/asan/TestCases/Linux/coverage-fork-direct.cc
+++ b/test/asan/TestCases/Posix/coverage-fork-direct.cc
@@ -1,7 +1,7 @@
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
// RUN: rm -rf %T/coverage-fork-direct
// RUN: mkdir -p %T/coverage-fork-direct && cd %T/coverage-fork-direct
-// RUN: (ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t; \
+// RUN: (ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:verbosity=1 %run %t; \
// RUN: %sancov rawunpack *.sancov.raw; %sancov print *.sancov) 2>&1
//
// XFAIL: android
diff --git a/test/asan/TestCases/Linux/coverage-fork.cc b/test/asan/TestCases/Posix/coverage-fork.cc
index 38c200942609..c1f0fc3a84b8 100644
--- a/test/asan/TestCases/Linux/coverage-fork.cc
+++ b/test/asan/TestCases/Posix/coverage-fork.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
-// RUN: export ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
+// RUN: export ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:verbosity=1
// RUN: rm -rf %T/coverage-fork
// RUN: mkdir -p %T/coverage-fork && cd %T/coverage-fork
// RUN: %run %t 2>&1 | FileCheck %s
diff --git a/test/asan/TestCases/Linux/coverage-module-unloaded.cc b/test/asan/TestCases/Posix/coverage-module-unloaded.cc
index f8d9c57f81be..fe08bdd792b1 100644
--- a/test/asan/TestCases/Linux/coverage-module-unloaded.cc
+++ b/test/asan/TestCases/Posix/coverage-module-unloaded.cc
@@ -1,13 +1,13 @@
// Check that unloading a module doesn't break coverage dumping for remaining
// modules.
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_module_unloaded_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_module_unloaded_test_2.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSO_DIR=\"%T\" %s %libdl -o %t
-// RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
+// RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %dynamiclib1 -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %dynamiclib2 -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=func %s %libdl -o %t
+// RUN: export ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1
// RUN: mkdir -p %T/coverage-module-unloaded && cd %T/coverage-module-unloaded
-// RUN: %run %t 2>&1 | FileCheck %s
-// RUN: %run %t foo 2>&1 | FileCheck %s
-// RUN: cd .. && rm coverage-module-unloaded -r
+// RUN: %run %t %dynamiclib1 %dynamiclib2 2>&1 | FileCheck %s
+// RUN: %run %t %dynamiclib1 %dynamiclib2 foo 2>&1 | FileCheck %s
+// RUN: rm -r %T/coverage-module-unloaded
//
// https://code.google.com/p/address-sanitizer/issues/detail?id=263
// XFAIL: android
@@ -25,14 +25,13 @@ void bar() { printf("bar\n"); }
int main(int argc, char **argv) {
fprintf(stderr, "PID: %d\n", getpid());
- void *handle1 =
- dlopen(SO_DIR "/libcoverage_module_unloaded_test_1.so", RTLD_LAZY);
+ assert(argc > 2);
+ void *handle1 = dlopen(argv[1], RTLD_LAZY); // %dynamiclib1
assert(handle1);
void (*bar1)() = (void (*)())dlsym(handle1, "bar");
assert(bar1);
bar1();
- void *handle2 =
- dlopen(SO_DIR "/libcoverage_module_unloaded_test_2.so", RTLD_LAZY);
+ void *handle2 = dlopen(argv[2], RTLD_LAZY); // %dynamiclib2
assert(handle2);
void (*bar2)() = (void (*)())dlsym(handle2, "bar");
assert(bar2);
@@ -50,7 +49,7 @@ int main(int argc, char **argv) {
// CHECK: PID: [[PID:[0-9]+]]
// CHECK: [[PID]].sancov: 1 PCs written
-// CHECK: .so.[[PID]]
-// If we get coverage for both DSOs, it means the module wasn't unloaded and
-// this test is useless.
-// CHECK-NOT: .so.[[PID]]
+// CHECK: coverage-module-unloaded{{.*}}1.[[PID]]
+// CHECK: coverage-module-unloaded{{.*}}2.[[PID]]
+// Even though we've unloaded one of the libs we still dump the coverage file
+// for that lib (although the data will be inaccurate, if at all useful)
diff --git a/test/asan/TestCases/Linux/coverage-sandboxing.cc b/test/asan/TestCases/Posix/coverage-sandboxing.cc
index 1a72c6bb9a6e..dd2c1ec43be5 100644
--- a/test/asan/TestCases/Linux/coverage-sandboxing.cc
+++ b/test/asan/TestCases/Posix/coverage-sandboxing.cc
@@ -1,6 +1,6 @@
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %T/libcoverage_sandboxing_test.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t -Wl,-R,\$ORIGIN -L%T -lcoverage_sandboxing_test
-// RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
+// RUN: %clangxx_asan -fsanitize-coverage=bb -DSHARED %s -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t %ld_flags_rpath_exe
+// RUN: export ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1
// RUN: rm -rf %T/coverage_sandboxing_test
// RUN: mkdir %T/coverage_sandboxing_test && cd %T/coverage_sandboxing_test
// RUN: mkdir vanilla && cd vanilla
@@ -12,12 +12,12 @@
// RUN: %run %t a b 2>&1 | FileCheck %s --check-prefix=CHECK-sandbox
// RUN: %sancov unpack coverage_sandboxing_test.sancov.packed
// RUN: cd ..
-// RUN: %sancov print vanilla/libcoverage_sandboxing_test.so.*.sancov > vanilla.txt
-// RUN: %sancov print sandbox1/libcoverage_sandboxing_test.so.*.sancov > sandbox1.txt
-// RUN: %sancov print sandbox2/libcoverage_sandboxing_test.so.*.sancov > sandbox2.txt
+// RUN: %sancov print vanilla/`basename %dynamiclib`*.sancov > vanilla.txt
+// RUN: %sancov print sandbox1/`basename %dynamiclib`*.sancov > sandbox1.txt
+// RUN: %sancov print sandbox2/`basename %dynamiclib`*.sancov > sandbox2.txt
// RUN: diff vanilla.txt sandbox1.txt
// RUN: diff vanilla.txt sandbox2.txt
-// RUN: cd ../ && rm coverage_sandboxing_test -r
+// RUN: rm -r %T/coverage_sandboxing_test
// https://code.google.com/p/address-sanitizer/issues/detail?id=263
// XFAIL: android
@@ -78,8 +78,8 @@ int main(int argc, char **argv) {
#endif
// CHECK-vanilla: PID: [[PID:[0-9]+]]
-// CHECK-vanilla: [[PID]].sancov: 1 PCs written
// CHECK-vanilla: .so.[[PID]].sancov: 258 PCs written
+// CHECK-vanilla: [[PID]].sancov: 1 PCs written
// CHECK-sandbox: PID: [[PID:[0-9]+]]
// CHECK-sandbox: 258 PCs written to packed file
diff --git a/test/asan/TestCases/Linux/coverage.cc b/test/asan/TestCases/Posix/coverage.cc
index 06fe1a295eaf..99e348fdaf9d 100644
--- a/test/asan/TestCases/Linux/coverage.cc
+++ b/test/asan/TestCases/Posix/coverage.cc
@@ -1,14 +1,21 @@
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_test.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t -Wl,-R,\$ORIGIN -L%T -lcoverage_test
-// RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
-// RUN: mkdir -p %T/coverage && cd %T/coverage
+// RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
+// RUN: %clangxx_asan -fsanitize-coverage=func %s %ld_flags_rpath_exe -o %t
+// RUN: export ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1
+// RUN: rm -rf %T/coverage && mkdir -p %T/coverage && cd %T/coverage
// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-main
+// RUN: %sancov print `ls coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
// RUN: %run %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-foo
+// RUN: %sancov print `ls coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
// RUN: %run %t bar 2>&1 | FileCheck %s --check-prefix=CHECK-bar
+// RUN: %sancov print `ls *coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
// RUN: %run %t foo bar 2>&1 | FileCheck %s --check-prefix=CHECK-foo-bar
+// RUN: %sancov print `ls *coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
+// RUN: %sancov print `ls *coverage.*sancov | grep '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
+// RUN: %sancov merge `ls *coverage.*sancov | grep -v '.so'` > merged-cov
+// RUN: %sancov print merged-cov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
// RUN: not %run %t foo bar 4 2>&1 | FileCheck %s --check-prefix=CHECK-report
// RUN: not %run %t foo bar 4 5 2>&1 | FileCheck %s --check-prefix=CHECK-segv
-// RUN: cd .. && rm coverage -r
+// RUN: rm -r %T/coverage
//
// https://code.google.com/p/address-sanitizer/issues/detail?id=263
// XFAIL: android
@@ -57,15 +64,18 @@ int main(int argc, char **argv) {
// CHECK-foo-NOT: .so.[[PID]]
//
// CHECK-bar: PID: [[PID:[0-9]+]]
-// CHECK-bar: [[PID]].sancov: 1 PCs written
// CHECK-bar: .so.[[PID]].sancov: 1 PCs written
+// CHECK-bar: [[PID]].sancov: 1 PCs written
//
// CHECK-foo-bar: PID: [[PID:[0-9]+]]
-// CHECK-foo-bar: [[PID]].sancov: 2 PCs written
// CHECK-foo-bar: so.[[PID]].sancov: 1 PCs written
+// CHECK-foo-bar: [[PID]].sancov: 2 PCs written
//
// CHECK-report: AddressSanitizer: global-buffer-overflow
// CHECK-report: PCs written
//
// CHECK-segv: AddressSanitizer: SEGV
// CHECK-segv: PCs written
+//
+// CHECK-SANCOV1: 1 PCs total
+// CHECK-SANCOV2: 2 PCs total
diff --git a/test/asan/TestCases/Posix/init-order-dlopen.cc b/test/asan/TestCases/Posix/init-order-dlopen.cc
deleted file mode 100644
index 3c6f093b03d1..000000000000
--- a/test/asan/TestCases/Posix/init-order-dlopen.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-// Regression test for
-// https://code.google.com/p/address-sanitizer/issues/detail?id=178
-
-// Assume we're on Darwin and try to pass -U to the linker. If this flag is
-// unsupported, don't use it.
-// RUN: %clangxx_asan -O0 -DSHARED_LIB %s \
-// RUN: -fPIC -shared -o %t-so.so -Wl,-U,_inc_global || \
-// RUN: %clangxx_asan -O0 -DSHARED_LIB %s \
-// RUN: -fPIC -shared -o %t-so.so
-// If the linker doesn't support --export-dynamic (which is ELF-specific),
-// try to link without that option.
-// FIXME: find a better solution.
-// RUN: %clangxx_asan -O0 %s -pthread %libdl -o %t -Wl,--export-dynamic || \
-// RUN: %clangxx_asan -O0 %s -pthread %libdl -o %t
-// RUN: ASAN_OPTIONS=strict_init_order=true %run %t 2>&1 | FileCheck %s
-#if !defined(SHARED_LIB)
-#include <dlfcn.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#include <string>
-
-using std::string;
-
-int foo() {
- return 42;
-}
-int global = foo();
-
-__attribute__((visibility("default")))
-extern "C"
-void inc_global() {
- global++;
-}
-
-void *global_poller(void *arg) {
- while (true) {
- if (global != 42)
- break;
- usleep(100);
- }
- return 0;
-}
-
-int main(int argc, char *argv[]) {
- pthread_t p;
- pthread_create(&p, 0, global_poller, 0);
- string path = string(argv[0]) + "-so.so";
- if (0 == dlopen(path.c_str(), RTLD_NOW)) {
- fprintf(stderr, "dlerror: %s\n", dlerror());
- return 1;
- }
- pthread_join(p, 0);
- printf("PASSED\n");
- // CHECK: PASSED
- return 0;
-}
-#else // SHARED_LIB
-#include <stdio.h>
-#include <unistd.h>
-
-extern "C" void inc_global();
-
-int slow_init() {
- sleep(1);
- inc_global();
- return 42;
-}
-
-int slowly_init_glob = slow_init();
-#endif // SHARED_LIB
diff --git a/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc b/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc
index b828d5524ee0..a7d2bfb9b43c 100644
--- a/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc
+++ b/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc
@@ -1,13 +1,8 @@
// Check that memset() call from a shared library gets intercepted.
-// Please always keep this file in sync with
-// ../Darwin/interception-in-shared-lib-test.cc.
// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
-// RUN: -shared -o %T/libinterception-in-shared-lib-test.so \
-// RUN: -fPIC
-// TODO(glider): figure out how to set rpath in a more portable way and unite
-// this test with ../Darwin/interception-in-shared-lib-test.cc.
-// RUN: %clangxx_asan -O0 %s -o %t -Wl,-R,\$ORIGIN -L%T -linterception-in-shared-lib-test && \
+// RUN: -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
+// RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe && \
// RUN: not %run %t 2>&1 | FileCheck %s
#include <stdio.h>
@@ -26,7 +21,7 @@ int main(int argc, char *argv[]) {
my_memset(buf, 11);
// CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
// CHECK: {{WRITE of size 11 at 0x.* thread T0}}
- // CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:19}}
+ // CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:}}[[@LINE-10]]
return 0;
}
#endif
diff --git a/test/asan/TestCases/Posix/ioctl.cc b/test/asan/TestCases/Posix/ioctl.cc
index 78f152fe93fe..d25f6ecbee1f 100644
--- a/test/asan/TestCases/Posix/ioctl.cc
+++ b/test/asan/TestCases/Posix/ioctl.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 -g %s -o %t && ASAN_OPTIONS=handle_ioctl=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 -g %s -o %t && ASAN_OPTIONS=handle_ioctl=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 -g %s -o %t && ASAN_OPTIONS=$ASAN_OPTIONS:handle_ioctl=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 -g %s -o %t && ASAN_OPTIONS=$ASAN_OPTIONS:handle_ioctl=1 not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O0 -g %s -o %t && %run %t
// RUN: %clangxx_asan -O3 -g %s -o %t && %run %t
diff --git a/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc b/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc
index f852a62ea9a3..b1c99430c75d 100644
--- a/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc
+++ b/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc
@@ -2,7 +2,7 @@
// RUN: %clangxx_asan %s -o %t
// The memory is released only when the deallocated chunk leaves the quarantine,
// otherwise the mmap(p, ...) call overwrites the malloc header.
-// RUN: ASAN_OPTIONS=quarantine_size_mb=0 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size_mb=0 %run %t
#include <assert.h>
#include <string.h>
diff --git a/test/asan/TestCases/log_path_fork_test.cc.disabled b/test/asan/TestCases/Posix/log_path_fork_test.cc.disabled
index cfe90dfb54d3..9f09b78f41c7 100644
--- a/test/asan/TestCases/log_path_fork_test.cc.disabled
+++ b/test/asan/TestCases/Posix/log_path_fork_test.cc.disabled
@@ -1,7 +1,7 @@
// RUN: %clangxx_asan %s -o %t
// RUN: rm -f %t.log.*
// Set verbosity to 1 so that the log files are opened prior to fork().
-// RUN: env ASAN_OPTIONS="log_path=%t.log verbosity=1" not %run %t 2> %t.out
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:log_path=%t.log verbosity=1" not %run %t 2> %t.out
// RUN: for f in %t.log.* ; do FileCheck %s < $f; done
// RUN: [ `ls %t.log.* | wc -l` == 2 ]
diff --git a/test/asan/TestCases/Posix/new_array_cookie_test.cc b/test/asan/TestCases/Posix/new_array_cookie_test.cc
index 85d51f361835..bc681857ae67 100644
--- a/test/asan/TestCases/Posix/new_array_cookie_test.cc
+++ b/test/asan/TestCases/Posix/new_array_cookie_test.cc
@@ -1,8 +1,8 @@
// REQUIRES: asan-64-bits
// RUN: %clangxx_asan -O3 %s -o %t
// RUN: not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=poison_array_cookie=1 not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=poison_array_cookie=0 not %run %t 2>&1 | FileCheck %s --check-prefix=NO_COOKIE
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:poison_array_cookie=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:poison_array_cookie=0 not %run %t 2>&1 | FileCheck %s --check-prefix=NO_COOKIE
#include <stdio.h>
#include <stdlib.h>
struct C {
diff --git a/test/asan/TestCases/Posix/new_array_cookie_uaf_test.cc b/test/asan/TestCases/Posix/new_array_cookie_uaf_test.cc
index c35ccebb8c79..5998d06756d7 100644
--- a/test/asan/TestCases/Posix/new_array_cookie_uaf_test.cc
+++ b/test/asan/TestCases/Posix/new_array_cookie_uaf_test.cc
@@ -1,7 +1,7 @@
// REQUIRES: asan-64-bits
// RUN: %clangxx_asan -O3 %s -o %t
-// RUN: ASAN_OPTIONS=poison_array_cookie=1 not %run %t 2>&1 | FileCheck %s --check-prefix=COOKIE
-// RUN: ASAN_OPTIONS=poison_array_cookie=0 not %run %t 2>&1 | FileCheck %s --check-prefix=NO_COOKIE
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:poison_array_cookie=1 not %run %t 2>&1 | FileCheck %s --check-prefix=COOKIE
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:poison_array_cookie=0 not %run %t 2>&1 | FileCheck %s --check-prefix=NO_COOKIE
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
diff --git a/test/asan/TestCases/Posix/start-deactivated.cc b/test/asan/TestCases/Posix/start-deactivated.cc
index d7e0dfc98e6d..2ca8015fc742 100644
--- a/test/asan/TestCases/Posix/start-deactivated.cc
+++ b/test/asan/TestCases/Posix/start-deactivated.cc
@@ -5,21 +5,20 @@
// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so
// RUN: %clangxx -O0 %s -c -o %t.o
// RUN: %clangxx_asan -O0 %t.o %libdl -o %t
-// RUN: ASAN_OPTIONS=start_deactivated=1,allocator_may_return_null=0 \
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1,allocator_may_return_null=0 \
// RUN: ASAN_ACTIVATION_OPTIONS=allocator_may_return_null=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
-// RUN: ASAN_OPTIONS=start_deactivated=1 \
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1 \
// RUN: ASAN_ACTIVATION_OPTIONS=help=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-HELP
-// RUN: ASAN_OPTIONS=start_deactivated=1,verbosity=1 \
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1,verbosity=1 \
// RUN: ASAN_ACTIVATION_OPTIONS=help=1,handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UNSUPPORTED
-// RUN: ASAN_OPTIONS=start_deactivated=1 \
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1 \
// RUN: ASAN_ACTIVATION_OPTIONS=help=1,handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UNSUPPORTED-V0
// Check that verbosity=1 in activation flags affects reporting of unrecognized activation flags.
-// RUN: ASAN_OPTIONS=start_deactivated=1 \
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS: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
// XFAIL: arm-linux-gnueabi
-// XFAIL: armv7l-unknown-linux-gnueabihf
#if !defined(SHARED_LIB)
#include <assert.h>
diff --git a/test/asan/TestCases/Posix/tsd_dtor_leak.cc b/test/asan/TestCases/Posix/tsd_dtor_leak.cc
index 6952245227b4..69d28194fb9e 100644
--- a/test/asan/TestCases/Posix/tsd_dtor_leak.cc
+++ b/test/asan/TestCases/Posix/tsd_dtor_leak.cc
@@ -1,7 +1,7 @@
// Regression test for a leak in tsd:
// https://code.google.com/p/address-sanitizer/issues/detail?id=233
// RUN: %clangxx_asan -O1 %s -pthread -o %t
-// RUN: ASAN_OPTIONS=quarantine_size_mb=0 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size_mb=0 %run %t
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/test/asan/TestCases/Windows/bind_io_completion_callback.cc b/test/asan/TestCases/Windows/bind_io_completion_callback.cc
new file mode 100644
index 000000000000..c062a799fdcc
--- /dev/null
+++ b/test/asan/TestCases/Windows/bind_io_completion_callback.cc
@@ -0,0 +1,70 @@
+// Make sure we can throw exceptions from work items executed via
+// BindIoCompletionCallback.
+//
+// Clang doesn't support exceptions on Windows yet, so for the time being we
+// build this program in two parts: the code with exceptions is built with CL,
+// the rest is built with Clang. This represents the typical scenario when we
+// build a large project using "clang-cl -fallback -fsanitize=address".
+//
+// RUN: cl -c %s -Fo%t.obj
+// RUN: %clangxx_asan -o %t.exe %s %t.obj
+// RUN: %run %t.exe 2>&1 | FileCheck %s
+
+#include <windows.h>
+#include <stdio.h>
+
+void ThrowAndCatch();
+
+#if !defined(__clang__)
+__declspec(noinline)
+void Throw() {
+ fprintf(stderr, "Throw\n");
+// CHECK: Throw
+ throw 1;
+}
+
+void ThrowAndCatch() {
+ int local;
+ try {
+ Throw();
+ } catch(...) {
+ fprintf(stderr, "Catch\n");
+// CHECK: Catch
+ }
+}
+#else
+
+char buffer[65536];
+HANDLE done;
+OVERLAPPED ov;
+
+void CALLBACK completion_callback(DWORD error, DWORD bytesRead,
+ LPOVERLAPPED pov) {
+ ThrowAndCatch();
+ SetEvent(done);
+}
+
+int main(int argc, char **argv) {
+ done = CreateEvent(0, false, false, "job is done");
+ if (!done)
+ return 1;
+ HANDLE file = CreateFile(
+ argv[0], GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED,
+ NULL);
+ if (!file)
+ return 2;
+ if (!BindIoCompletionCallback(file, completion_callback, 0))
+ return 3;
+
+ if (!ReadFile(file, buffer, sizeof(buffer), NULL, &ov) &&
+ GetLastError() != ERROR_IO_PENDING)
+ return 4;
+
+ if (WAIT_OBJECT_0 != WaitForSingleObject(done, INFINITE))
+ return 5;
+ fprintf(stderr, "Done!\n");
+// CHECK: Done!
+}
+#endif
diff --git a/test/asan/TestCases/Windows/coverage-basic.cc b/test/asan/TestCases/Windows/coverage-basic.cc
new file mode 100644
index 000000000000..44b499fcb4cd
--- /dev/null
+++ b/test/asan/TestCases/Windows/coverage-basic.cc
@@ -0,0 +1,25 @@
+// RUN: rm -rf %T/coverage-basic
+// RUN: mkdir %T/coverage-basic && cd %T/coverage-basic
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o test.exe
+// RUN: env ASAN_OPTIONS=coverage=1 %run ./test.exe
+//
+// RUN: %sancov print *.sancov | FileCheck %s
+#include <stdio.h>
+
+void foo() { fprintf(stderr, "FOO\n"); }
+void bar() { fprintf(stderr, "BAR\n"); }
+
+int main(int argc, char **argv) {
+ if (argc == 2) {
+ foo();
+ bar();
+ } else {
+ bar();
+ foo();
+ }
+}
+
+// CHECK: 0x{{[0-9a-f]*}}
+// CHECK: 0x{{[0-9a-f]*}}
+// CHECK: 0x{{[0-9a-f]*}}
+// CHECK-NOT: 0x{{[0-9a-f]*}}
diff --git a/test/asan/TestCases/Windows/default_options.cc b/test/asan/TestCases/Windows/default_options.cc
new file mode 100644
index 000000000000..6e0a28f33692
--- /dev/null
+++ b/test/asan/TestCases/Windows/default_options.cc
@@ -0,0 +1,18 @@
+// RUN: %clangxx_asan -O2 %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+// FIXME: merge this with the common default_options test when we can run common
+// tests on Windows.
+
+const char *kAsanDefaultOptions="verbosity=1 help=1";
+
+extern "C"
+__attribute__((no_sanitize_address))
+const char *__asan_default_options() {
+ // CHECK: Available flags for AddressSanitizer:
+ return kAsanDefaultOptions;
+}
+
+int main() {
+ return 0;
+}
diff --git a/test/asan/TestCases/Windows/dll_noreturn.cc b/test/asan/TestCases/Windows/dll_noreturn.cc
index 6ec90725145f..79f923eccf84 100644
--- a/test/asan/TestCases/Windows/dll_noreturn.cc
+++ b/test/asan/TestCases/Windows/dll_noreturn.cc
@@ -9,7 +9,7 @@ void noreturn_f() {
char buffer[42];
buffer[subscript] = 42;
_exit(1);
-// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: AddressSanitizer: stack-buffer-underflow on address [[ADDR:0x[0-9a-f]+]]
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
// CHECK-NEXT: noreturn_f {{.*}}dll_noreturn.cc:[[@LINE-4]]
// CHECK-NEXT: test_function {{.*}}dll_noreturn.cc
diff --git a/test/asan/TestCases/Windows/dll_report_globals_symbolization_at_startup.cc b/test/asan/TestCases/Windows/dll_report_globals_symbolization_at_startup.cc
new file mode 100644
index 000000000000..fbdb1c145bbe
--- /dev/null
+++ b/test/asan/TestCases/Windows/dll_report_globals_symbolization_at_startup.cc
@@ -0,0 +1,40 @@
+// RUN: %clang_cl_asan -LD -O0 -DDLL %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 -DEXE %s %t.lib -Fe%te.exe
+// RUN: env ASAN_OPTIONS=report_globals=2 %run %te.exe 2>&1 | FileCheck %s
+
+// FIXME: Currently, the MT runtime build crashes on startup due to dbghelp.dll
+// initialization failure.
+// REQUIRES: asan-dynamic-runtime
+
+#include <windows.h>
+#include <stdio.h>
+
+extern "C" {
+#if defined(EXE)
+__declspec(dllimport) int foo_from_dll();
+
+// CHECK: in DLL(reason=1)
+int main(int argc, char **argv) {
+ foo_from_dll();
+// CHECK: hello!
+ printf("hello!\n");
+ fflush(0);
+// CHECK: in DLL(reason=0)
+}
+#elif defined(DLL)
+// This global is registered at startup.
+int x[42];
+
+__declspec(dllexport) int foo_from_dll() {
+ return x[2];
+}
+
+BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) {
+ printf("in DLL(reason=%d)\n", (int)reason);
+ fflush(0);
+ return TRUE;
+}
+#else
+# error oops!
+#endif
+}
diff --git a/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc b/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc
index 8f53623419ce..04d3e2ec554b 100644
--- a/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc
+++ b/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc
@@ -9,7 +9,7 @@ DWORD WINAPI thread_proc(void *context) {
int subscript = -1;
char stack_buffer[42];
stack_buffer[subscript] = 42;
-// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: AddressSanitizer: stack-buffer-underflow on address [[ADDR:0x[0-9a-f]+]]
// CHECK: WRITE of size 1 at [[ADDR]] thread T1
// CHECK-NEXT: thread_proc {{.*}}dll_thread_stack_array_left_oob.cc:[[@LINE-3]]
//
diff --git a/test/asan/TestCases/Windows/free_hook_realloc.cc b/test/asan/TestCases/Windows/free_hook_realloc.cc
new file mode 100644
index 000000000000..297218bf8e99
--- /dev/null
+++ b/test/asan/TestCases/Windows/free_hook_realloc.cc
@@ -0,0 +1,37 @@
+// Check that free hook doesn't conflict with Realloc.
+// RUN: %clangxx_asan -O2 %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+// FIXME: merge this with the common free_hook_realloc test when we can run
+// common tests on Windows.
+
+#include <stdlib.h>
+#include <io.h>
+#include <sanitizer/allocator_interface.h>
+
+static void *glob_ptr;
+
+extern "C" {
+void __sanitizer_free_hook(const volatile void *ptr) {
+ if (ptr == glob_ptr) {
+ *(int*)ptr = 0;
+ write(1, "FreeHook\n", sizeof("FreeHook\n"));
+ }
+}
+}
+
+int main() {
+ int *x = (int*)malloc(100);
+ x[0] = 42;
+ glob_ptr = x;
+ int *y = (int*)realloc(x, 200);
+ // Verify that free hook was called and didn't spoil the memory.
+ if (y[0] != 42) {
+ _exit(1);
+ }
+ write(1, "Passed\n", sizeof("Passed\n"));
+ free(y);
+ // CHECK: FreeHook
+ // CHECK: Passed
+ return 0;
+}
diff --git a/test/asan/TestCases/Windows/on_error_callback.cc b/test/asan/TestCases/Windows/on_error_callback.cc
new file mode 100644
index 000000000000..9e690a342b56
--- /dev/null
+++ b/test/asan/TestCases/Windows/on_error_callback.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// FIXME: merge this with the common on_error_callback test when we can run
+// common tests on Windows.
+
+#include <stdio.h>
+#include <stdlib.h>
+
+extern "C"
+void __asan_on_error() {
+ fprintf(stderr, "__asan_on_error called");
+ fflush(0);
+}
+
+int main() {
+ char *x = (char*)malloc(10 * sizeof(char));
+ free(x);
+ return x[5];
+ // CHECK: __asan_on_error called
+}
diff --git a/test/asan/TestCases/Windows/queue_user_work_item.cc b/test/asan/TestCases/Windows/queue_user_work_item.cc
new file mode 100644
index 000000000000..d99ea6fc2e45
--- /dev/null
+++ b/test/asan/TestCases/Windows/queue_user_work_item.cc
@@ -0,0 +1,55 @@
+// Make sure we can throw exceptions from work items executed via
+// QueueUserWorkItem.
+//
+// Clang doesn't support exceptions on Windows yet, so for the time being we
+// build this program in two parts: the code with exceptions is built with CL,
+// the rest is built with Clang. This represents the typical scenario when we
+// build a large project using "clang-cl -fallback -fsanitize=address".
+//
+// RUN: cl -c %s -Fo%t.obj
+// RUN: %clangxx_asan -o %t.exe %s %t.obj
+// RUN: %run %t.exe 2>&1 | FileCheck %s
+
+#include <windows.h>
+#include <stdio.h>
+
+void ThrowAndCatch();
+
+#if !defined(__clang__)
+__declspec(noinline)
+void Throw() {
+ fprintf(stderr, "Throw\n");
+// CHECK: Throw
+ throw 1;
+}
+
+void ThrowAndCatch() {
+ int local;
+ try {
+ Throw();
+ } catch(...) {
+ fprintf(stderr, "Catch\n");
+// CHECK: Catch
+ }
+}
+#else
+
+HANDLE done;
+
+DWORD CALLBACK work_item(LPVOID) {
+ ThrowAndCatch();
+ SetEvent(done);
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ done = CreateEvent(0, false, false, "job is done");
+ if (!done)
+ return 1;
+ QueueUserWorkItem(&work_item, nullptr, 0);
+ if (WAIT_OBJECT_0 != WaitForSingleObject(done, INFINITE))
+ return 2;
+ fprintf(stderr, "Done!\n");
+// CHECK: Done!
+}
+#endif
diff --git a/test/asan/TestCases/Windows/queue_user_work_item_report.cc b/test/asan/TestCases/Windows/queue_user_work_item_report.cc
new file mode 100644
index 000000000000..a57e1e767dc7
--- /dev/null
+++ b/test/asan/TestCases/Windows/queue_user_work_item_report.cc
@@ -0,0 +1,29 @@
+// RUN: %clang_cl_asan -O0 %s -Fe%t
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include <windows.h>
+
+HANDLE done;
+
+DWORD CALLBACK work_item(LPVOID) {
+ int subscript = -1;
+ volatile char stack_buffer[42];
+ stack_buffer[subscript] = 42;
+// CHECK: AddressSanitizer: stack-buffer-underflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T1
+// CHECK: {{#0 .* work_item .*queue_user_work_item_report.cc}}:[[@LINE-3]]
+// CHECK: Address [[ADDR]] is located in stack of thread T1 at offset {{.*}} in frame
+// CHECK: work_item
+ SetEvent(done);
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ done = CreateEvent(0, false, false, "job is done");
+ if (!done)
+ return 1;
+// CHECK-NOT: Thread T1 created
+ QueueUserWorkItem(&work_item, nullptr, 0);
+ if (WAIT_OBJECT_0 != WaitForSingleObject(done, INFINITE))
+ return 2;
+}
diff --git a/test/asan/TestCases/Windows/report_globals_reload_dll.cc b/test/asan/TestCases/Windows/report_globals_reload_dll.cc
new file mode 100644
index 000000000000..8b050975aac1
--- /dev/null
+++ b/test/asan/TestCases/Windows/report_globals_reload_dll.cc
@@ -0,0 +1,51 @@
+// Make sure we can handle reloading the same DLL multiple times.
+// RUN: %clang_cl_asan -LD -O0 -DDLL %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 -DEXE %s -Fe%te.exe
+// RUN: env ASAN_OPTIONS=report_globals=1 %run %te.exe %t.dll 2>&1 | FileCheck %s
+
+#include <windows.h>
+#include <stdio.h>
+#include <string.h>
+
+extern "C" {
+#if defined(EXE)
+int main(int argc, char **argv) {
+ if (argc != 2) {
+ printf("Usage: %s [client].dll\n", argv[0]);
+ return 101;
+ }
+ const char *dll_name = argv[1];
+
+// CHECK: time to load DLL
+ printf("time to load DLL\n");
+ fflush(0);
+
+// CHECK: in DLL(reason=1)
+// CHECK: in DLL(reason=0)
+// CHECK: in DLL(reason=1)
+// CHECK: in DLL(reason=0)
+// CHECK: in DLL(reason=1)
+// CHECK: in DLL(reason=0)
+ for (int i = 0; i < 30; ++i) {
+ HMODULE dll = LoadLibrary(dll_name);
+ if (dll == NULL)
+ return 3;
+
+ if (!FreeLibrary(dll))
+ return 4;
+ }
+
+// CHECK: All OK!
+ printf("All OK!\n");
+ fflush(0);
+}
+#elif defined(DLL)
+BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) {
+ printf("in DLL(reason=%d)\n", (int)reason);
+ fflush(0);
+ return TRUE;
+}
+#else
+# error oops!
+#endif
+}
diff --git a/test/asan/TestCases/Windows/globals_multiple_dlls.cc b/test/asan/TestCases/Windows/report_globals_vs_freelibrary.cc
index 634e5782796c..72bf36ad0be7 100644
--- a/test/asan/TestCases/Windows/globals_multiple_dlls.cc
+++ b/test/asan/TestCases/Windows/report_globals_vs_freelibrary.cc
@@ -1,7 +1,3 @@
-// Make sure everything works even if the main module doesn't have any stack
-// variables, thus doesn't explicitly reference any symbol exported by the
-// runtime thunk.
-//
// RUN: %clang_cl_asan -LD -O0 -DDLL %s -Fe%t.dll
// RUN: %clang_cl_asan -O0 -DEXE %s -Fe%te.exe
// RUN: env ASAN_OPTIONS=report_globals=2 %run %te.exe %t.dll 2>&1 | FileCheck %s
diff --git a/test/asan/TestCases/Windows/stack_array_left_oob.cc b/test/asan/TestCases/Windows/stack_array_left_oob.cc
index 040d855b48e2..845a1f33261f 100644
--- a/test/asan/TestCases/Windows/stack_array_left_oob.cc
+++ b/test/asan/TestCases/Windows/stack_array_left_oob.cc
@@ -7,7 +7,7 @@ int main() {
int subscript = -1;
char buffer[42];
buffer[subscript] = 42;
-// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: AddressSanitizer: stack-buffer-underflow on address [[ADDR:0x[0-9a-f]+]]
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
// CHECK-NEXT: {{#0 .* main .*stack_array_left_oob.cc}}:[[@LINE-3]]
// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame
diff --git a/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc b/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
index 17b9b1bf8ecb..63cb8ae1f43c 100644
--- a/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
+++ b/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
@@ -7,7 +7,7 @@ DWORD WINAPI thread_proc(void *) {
int subscript = -1;
volatile char stack_buffer[42];
stack_buffer[subscript] = 42;
-// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: AddressSanitizer: stack-buffer-underflow on address [[ADDR:0x[0-9a-f]+]]
// CHECK: WRITE of size 1 at [[ADDR]] thread T1
// CHECK: {{#0 .* thread_proc .*thread_stack_array_left_oob.cc}}:[[@LINE-3]]
// CHECK: Address [[ADDR]] is located in stack of thread T1 at offset {{.*}} in frame
diff --git a/test/asan/TestCases/alloca_instruments_all_paddings.cc b/test/asan/TestCases/alloca_instruments_all_paddings.cc
index d60a3b22dcb9..e2c7fafb193e 100644
--- a/test/asan/TestCases/alloca_instruments_all_paddings.cc
+++ b/test/asan/TestCases/alloca_instruments_all_paddings.cc
@@ -1,4 +1,5 @@
// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t
+// RUN: %clangxx_asan -O3 -mllvm -asan-instrument-allocas %s -o %t
// RUN: %run %t 2>&1
//
diff --git a/test/asan/TestCases/alloca_loop_unpoisoning.cc b/test/asan/TestCases/alloca_loop_unpoisoning.cc
new file mode 100644
index 000000000000..3621a09aa720
--- /dev/null
+++ b/test/asan/TestCases/alloca_loop_unpoisoning.cc
@@ -0,0 +1,33 @@
+// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t
+// RUN: %run %t 2>&1
+//
+// REQUIRES: stable-runtime
+
+// This testcase checks that allocas and VLAs inside loop are correctly unpoisoned.
+
+#include <assert.h>
+#include <alloca.h>
+#include <stdint.h>
+#include "sanitizer/asan_interface.h"
+
+void *top, *bot;
+
+__attribute__((noinline)) void foo(int len) {
+ char x;
+ top = &x;
+ char array[len]; // NOLINT
+ assert(!(reinterpret_cast<uintptr_t>(array) & 31L));
+ alloca(len);
+ for (int i = 0; i < 32; ++i) {
+ char array[i]; // NOLINT
+ bot = alloca(i);
+ assert(!(reinterpret_cast<uintptr_t>(bot) & 31L));
+ }
+}
+
+int main(int argc, char **argv) {
+ foo(32);
+ void *q = __asan_region_is_poisoned(bot, (char *)top - (char *)bot);
+ assert(!q);
+ return 0;
+}
diff --git a/test/asan/TestCases/alloca_vla_interact.cc b/test/asan/TestCases/alloca_vla_interact.cc
new file mode 100644
index 000000000000..531cc243055d
--- /dev/null
+++ b/test/asan/TestCases/alloca_vla_interact.cc
@@ -0,0 +1,41 @@
+// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t
+// RUN: %run %t 2>&1
+//
+// REQUIRES: stable-runtime
+// XFAIL: powerpc64
+
+// This testcase checks correct interaction between VLAs and allocas.
+
+#include <assert.h>
+#include <alloca.h>
+#include <stdint.h>
+#include "sanitizer/asan_interface.h"
+
+#define RZ 32
+
+__attribute__((noinline)) void foo(int len) {
+ char *top, *bot;
+ // This alloca call should live until the end of foo.
+ char *alloca1 = (char *)alloca(len);
+ assert(!(reinterpret_cast<uintptr_t>(alloca1) & 31L));
+ // This should be first poisoned address after loop.
+ top = alloca1 - RZ;
+ for (int i = 0; i < 32; ++i) {
+ // Check that previous alloca was unpoisoned at the end of iteration.
+ if (i) assert(!__asan_region_is_poisoned(bot, 96));
+ // VLA is unpoisoned at the end of iteration.
+ volatile char array[i];
+ assert(!(reinterpret_cast<uintptr_t>(array) & 31L));
+ // Alloca is unpoisoned at the end of iteration,
+ // because dominated by VLA.
+ bot = (char *)alloca(i) - RZ;
+ }
+ // Check that all allocas from loop were unpoisoned correctly.
+ void *q = __asan_region_is_poisoned(bot, (char *)top - (char *)bot + 1);
+ assert(q == top);
+}
+
+int main(int argc, char **argv) {
+ foo(32);
+ return 0;
+}
diff --git a/test/asan/TestCases/allocator_returns_null.cc b/test/asan/TestCases/allocator_returns_null.cc
index da6fbd43099e..bc6cd2035163 100644
--- a/test/asan/TestCases/allocator_returns_null.cc
+++ b/test/asan/TestCases/allocator_returns_null.cc
@@ -4,16 +4,16 @@
//
// RUN: %clangxx_asan -O0 %s -o %t
// RUN: not %run %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mCRASH
-// RUN: env ASAN_OPTIONS=allocator_may_return_null=0 not %run %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mCRASH
-// RUN: env ASAN_OPTIONS=allocator_may_return_null=1 %run %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mNULL
-// RUN: env ASAN_OPTIONS=allocator_may_return_null=0 not %run %t calloc 2>&1 | FileCheck %s --check-prefix=CHECK-cCRASH
-// RUN: env ASAN_OPTIONS=allocator_may_return_null=1 %run %t calloc 2>&1 | FileCheck %s --check-prefix=CHECK-cNULL
-// RUN: env ASAN_OPTIONS=allocator_may_return_null=0 not %run %t calloc-overflow 2>&1 | FileCheck %s --check-prefix=CHECK-coCRASH
-// RUN: env ASAN_OPTIONS=allocator_may_return_null=1 %run %t calloc-overflow 2>&1 | FileCheck %s --check-prefix=CHECK-coNULL
-// RUN: env ASAN_OPTIONS=allocator_may_return_null=0 not %run %t realloc 2>&1 | FileCheck %s --check-prefix=CHECK-rCRASH
-// RUN: env ASAN_OPTIONS=allocator_may_return_null=1 %run %t realloc 2>&1 | FileCheck %s --check-prefix=CHECK-rNULL
-// RUN: env ASAN_OPTIONS=allocator_may_return_null=0 not %run %t realloc-after-malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mrCRASH
-// RUN: env ASAN_OPTIONS=allocator_may_return_null=1 %run %t realloc-after-malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mrNULL
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:allocator_may_return_null=0 not %run %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mCRASH
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:allocator_may_return_null=1 %run %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mNULL
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:allocator_may_return_null=0 not %run %t calloc 2>&1 | FileCheck %s --check-prefix=CHECK-cCRASH
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:allocator_may_return_null=1 %run %t calloc 2>&1 | FileCheck %s --check-prefix=CHECK-cNULL
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:allocator_may_return_null=0 not %run %t calloc-overflow 2>&1 | FileCheck %s --check-prefix=CHECK-coCRASH
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:allocator_may_return_null=1 %run %t calloc-overflow 2>&1 | FileCheck %s --check-prefix=CHECK-coNULL
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:allocator_may_return_null=0 not %run %t realloc 2>&1 | FileCheck %s --check-prefix=CHECK-rCRASH
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:allocator_may_return_null=1 %run %t realloc 2>&1 | FileCheck %s --check-prefix=CHECK-rNULL
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:allocator_may_return_null=0 not %run %t realloc-after-malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mrCRASH
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:allocator_may_return_null=1 %run %t realloc-after-malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mrNULL
#include <limits.h>
#include <stdlib.h>
diff --git a/test/asan/TestCases/asan_and_llvm_coverage_test.cc b/test/asan/TestCases/asan_and_llvm_coverage_test.cc
index 35bdfcb353c2..05de12b66bba 100644
--- a/test/asan/TestCases/asan_and_llvm_coverage_test.cc
+++ b/test/asan/TestCases/asan_and_llvm_coverage_test.cc
@@ -1,5 +1,5 @@
// RUN: %clangxx_asan -coverage -O0 %s -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=1 %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=1 %run %t 2>&1 | FileCheck %s
// XFAIL: android
#include <stdio.h>
int foo() { return 1; }
diff --git a/test/asan/TestCases/asan_options-help.cc b/test/asan/TestCases/asan_options-help.cc
index f10830f16085..a5e19e0c2003 100644
--- a/test/asan/TestCases/asan_options-help.cc
+++ b/test/asan/TestCases/asan_options-help.cc
@@ -1,5 +1,5 @@
// RUN: %clangxx_asan -O0 %s -o %t
-// RUN: ASAN_OPTIONS=help=1 %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:help=1 %run %t 2>&1 | FileCheck %s
int main() {
}
diff --git a/test/asan/TestCases/atexit_stats.cc b/test/asan/TestCases/atexit_stats.cc
index be6534475245..596bfdaa0d53 100644
--- a/test/asan/TestCases/atexit_stats.cc
+++ b/test/asan/TestCases/atexit_stats.cc
@@ -1,6 +1,6 @@
// Make sure we report atexit stats.
// RUN: %clangxx_asan -O3 %s -o %t
-// RUN: env ASAN_OPTIONS=atexit=1:print_stats=1 %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:atexit=1:print_stats=1 %run %t 2>&1 | FileCheck %s
//
// No atexit output on Android due to
// https://code.google.com/p/address-sanitizer/issues/detail?id=263
diff --git a/test/asan/TestCases/atoi_strict.c b/test/asan/TestCases/atoi_strict.c
new file mode 100644
index 000000000000..f3739506fb3a
--- /dev/null
+++ b/test/asan/TestCases/atoi_strict.c
@@ -0,0 +1,55 @@
+// Test strict_string_checks option in atoi function
+// RUN: %clang_asan %s -o %t
+// RUN: %run %t test1 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test1 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %run %t test2 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test2 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %run %t test3 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test3 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *array) {
+ // Last symbol is non-digit
+ memset(array, '1', 10);
+ array[9] = 'a';
+ int r = atoi(array);
+ assert(r == 111111111);
+}
+
+void test2(char *array) {
+ // Single non-digit symbol
+ array[9] = 'a';
+ int r = atoi(array + 9);
+ assert(r == 0);
+}
+
+void test3(char *array) {
+ // Incorrect number format
+ memset(array, ' ', 10);
+ array[9] = '-';
+ array[8] = '-';
+ int r = atoi(array);
+ assert(r == 0);
+}
+
+int main(int argc, char **argv) {
+ char *array = (char*)malloc(10);
+ if (argc != 2) return 1;
+ if (!strcmp(argv[1], "test1")) test1(array);
+ // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK1: READ of size 11
+ if (!strcmp(argv[1], "test2")) test2(array);
+ // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK2: READ of size 2
+ if (!strcmp(argv[1], "test3")) test3(array);
+ // CHECK3: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK3: READ of size 11
+ free(array);
+ return 0;
+}
diff --git a/test/asan/TestCases/atol_strict.c b/test/asan/TestCases/atol_strict.c
new file mode 100644
index 000000000000..f106150f3eaa
--- /dev/null
+++ b/test/asan/TestCases/atol_strict.c
@@ -0,0 +1,55 @@
+// Test strict_string_checks option in atol function
+// RUN: %clang_asan %s -o %t
+// RUN: %run %t test1 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test1 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %run %t test2 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test2 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %run %t test3 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test3 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *array) {
+ // Last symbol is non-digit
+ memset(array, '1', 10);
+ array[9] = 'a';
+ long r = atol(array);
+ assert(r == 111111111);
+}
+
+void test2(char *array) {
+ // Single non-digit symbol
+ array[9] = 'a';
+ long r = atol(array + 9);
+ assert(r == 0);
+}
+
+void test3(char *array) {
+ // Incorrect number format
+ memset(array, ' ', 10);
+ array[9] = '-';
+ array[8] = '-';
+ long r = atol(array);
+ assert(r == 0);
+}
+
+int main(int argc, char **argv) {
+ char *array = (char*)malloc(10);
+ if (argc != 2) return 1;
+ if (!strcmp(argv[1], "test1")) test1(array);
+ // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK1: READ of size 11
+ if (!strcmp(argv[1], "test2")) test2(array);
+ // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK2: READ of size 2
+ if (!strcmp(argv[1], "test3")) test3(array);
+ // CHECK3: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK3: READ of size 11
+ free(array);
+ return 0;
+}
diff --git a/test/asan/TestCases/atoll_strict.c b/test/asan/TestCases/atoll_strict.c
new file mode 100644
index 000000000000..23405d2d220d
--- /dev/null
+++ b/test/asan/TestCases/atoll_strict.c
@@ -0,0 +1,55 @@
+// Test strict_string_checks option in atoll function
+// RUN: %clang_asan %s -o %t
+// RUN: %run %t test1 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test1 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %run %t test2 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test2 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %run %t test3 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test3 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *array) {
+ // Last symbol is non-digit
+ memset(array, '1', 10);
+ array[9] = 'a';
+ long long r = atoll(array);
+ assert(r == 111111111);
+}
+
+void test2(char *array) {
+ // Single non-digit symbol
+ array[9] = 'a';
+ long long r = atoll(array + 9);
+ assert(r == 0);
+}
+
+void test3(char *array) {
+ // Incorrect number format
+ memset(array, ' ', 10);
+ array[9] = '-';
+ array[8] = '-';
+ long long r = atoll(array);
+ assert(r == 0);
+}
+
+int main(int argc, char **argv) {
+ char *array = (char*)malloc(10);
+ if (argc != 2) return 1;
+ if (!strcmp(argv[1], "test1")) test1(array);
+ // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK1: READ of size 11
+ if (!strcmp(argv[1], "test2")) test2(array);
+ // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK2: READ of size 2
+ if (!strcmp(argv[1], "test3")) test3(array);
+ // CHECK3: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK3: READ of size 11
+ free(array);
+ return 0;
+}
diff --git a/test/asan/TestCases/closed-fds.cc b/test/asan/TestCases/closed-fds.cc
new file mode 100644
index 000000000000..af0ac26743ca
--- /dev/null
+++ b/test/asan/TestCases/closed-fds.cc
@@ -0,0 +1,33 @@
+// Check that when the program closed its std(in|out|err), running the external
+// symbolizer still works.
+
+// RUN: rm -f %t.log.*
+// RUN: %clangxx_asan -O0 %s -o %t 2>&1 && ASAN_OPTIONS=$ASAN_OPTIONS:log_path=%t.log:verbosity=2 not %run %t 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK-FILE < %t.log.*
+
+// FIXME: copy %t.log back from the device and re-enable on Android.
+// UNSUPPORTED: android
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ int result = fprintf(stderr, "Closing streams.\n");
+ assert(result > 0);
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
+ result = fprintf(stderr, "Can you hear me now?\n");
+ assert(result < 0);
+ char *x = (char *)malloc(10 * sizeof(char));
+ free(x);
+ x[argc] = 'X'; // BOOM
+ // CHECK-FILE: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+ // CHECK-FILE: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
+ // CHECK-FILE: {{WRITE of size 1 at 0x.* thread T0}}
+ // CHECK-FILE: {{ #0 0x.* in main .*closed-fds.cc:}}[[@LINE-4]]
+ return 0;
+}
diff --git a/test/asan/TestCases/contiguous_container_crash.cc b/test/asan/TestCases/contiguous_container_crash.cc
index 143ae9d8edee..1ae1ff164302 100644
--- a/test/asan/TestCases/contiguous_container_crash.cc
+++ b/test/asan/TestCases/contiguous_container_crash.cc
@@ -1,7 +1,8 @@
// RUN: %clangxx_asan -O %s -o %t
// RUN: not %run %t crash 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
-// RUN: not %run %t bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-BAD %s
-// RUN: env ASAN_OPTIONS=detect_container_overflow=0 %run %t crash
+// RUN: not %run %t bad-bounds 2>&1 | FileCheck --check-prefix=CHECK-BAD-BOUNDS %s
+// RUN: not %run %t bad-alignment 2>&1 | FileCheck --check-prefix=CHECK-BAD-ALIGNMENT %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:detect_container_overflow=0 %run %t crash
//
// Test crash due to __sanitizer_annotate_contiguous_container.
@@ -21,21 +22,31 @@ int TestCrash() {
t[60] = 0;
__sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100,
&t[0] + 50);
+// CHECK-CRASH: AddressSanitizer: container-overflow
return (int)t[60 * one]; // Touches the poisoned memory.
}
void BadBounds() {
long t[100];
+// CHECK-BAD-BOUNDS: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
__sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 101,
&t[0] + 50);
}
+void BadAlignment() {
+ int t[100];
+// CHECK-BAD-ALIGNMENT: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
+// CHECK-BAD-ALIGNMENT: ERROR: beg is not aligned by 8
+ __sanitizer_annotate_contiguous_container(&t[1], &t[0] + 100, &t[1] + 10,
+ &t[0] + 50);
+}
+
int main(int argc, char **argv) {
assert(argc == 2);
if (!strcmp(argv[1], "crash"))
return TestCrash();
else if (!strcmp(argv[1], "bad-bounds"))
BadBounds();
+ else if (!strcmp(argv[1], "bad-alignment"))
+ BadAlignment();
}
-// CHECK-CRASH: AddressSanitizer: container-overflow
-// CHECK-BAD: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container
diff --git a/test/asan/TestCases/Linux/coverage-and-lsan.cc b/test/asan/TestCases/coverage-and-lsan.cc
index 4cb8e2af3084..f65889c0a1bf 100644
--- a/test/asan/TestCases/Linux/coverage-and-lsan.cc
+++ b/test/asan/TestCases/coverage-and-lsan.cc
@@ -1,11 +1,11 @@
// Make sure coverage is dumped even if there are reported leaks.
//
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
//
// RUN: rm -rf %T/coverage-and-lsan
//
// RUN: mkdir -p %T/coverage-and-lsan/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_dir=%T/coverage-and-lsan:verbosity=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_dir=%T/coverage-and-lsan:verbosity=1 not %run %t 2>&1 | FileCheck %s
// RUN: %sancov print %T/coverage-and-lsan/*.sancov 2>&1
//
// REQUIRES: leak-detection
diff --git a/test/asan/TestCases/Linux/coverage-caller-callee-total-count.cc b/test/asan/TestCases/coverage-caller-callee-total-count.cc
index 7598f6bc7bc5..ac6d2486e462 100644
--- a/test/asan/TestCases/Linux/coverage-caller-callee-total-count.cc
+++ b/test/asan/TestCases/coverage-caller-callee-total-count.cc
@@ -1,7 +1,7 @@
// Test __sanitizer_get_total_unique_coverage for caller-callee coverage
-// RUN: %clangxx_asan -fsanitize-coverage=4 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1 %run %t
+// RUN: %clangxx_asan -fsanitize-coverage=edge,indirect-calls %s -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1 %run %t
// RUN: rm -f caller-callee*.sancov
//
// REQUIRES: asan-64-bits
diff --git a/test/asan/TestCases/Linux/coverage-caller-callee.cc b/test/asan/TestCases/coverage-caller-callee.cc
index cd318962b8e0..9c42817776f9 100644
--- a/test/asan/TestCases/Linux/coverage-caller-callee.cc
+++ b/test/asan/TestCases/coverage-caller-callee.cc
@@ -1,13 +1,13 @@
// Test caller-callee coverage with large number of threads
// and various numbers of callers and callees.
-// RUN: %clangxx_asan -fsanitize-coverage=4 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 10 1 2>&1 | FileCheck %s --check-prefix=CHECK-10-1
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 9 2 2>&1 | FileCheck %s --check-prefix=CHECK-9-2
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 7 3 2>&1 | FileCheck %s --check-prefix=CHECK-7-3
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 17 1 2>&1 | FileCheck %s --check-prefix=CHECK-17-1
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 15 2 2>&1 | FileCheck %s --check-prefix=CHECK-15-2
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 18 3 2>&1 | FileCheck %s --check-prefix=CHECK-18-3
+// RUN: %clangxx_asan -fsanitize-coverage=edge,indirect-calls %s -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t 10 1 2>&1 | FileCheck %s --check-prefix=CHECK-10-1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t 9 2 2>&1 | FileCheck %s --check-prefix=CHECK-9-2
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t 7 3 2>&1 | FileCheck %s --check-prefix=CHECK-7-3
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t 17 1 2>&1 | FileCheck %s --check-prefix=CHECK-17-1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t 15 2 2>&1 | FileCheck %s --check-prefix=CHECK-15-2
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t 18 3 2>&1 | FileCheck %s --check-prefix=CHECK-18-3
// RUN: rm -f caller-callee*.sancov
//
// REQUIRES: asan-64-bits
diff --git a/test/asan/TestCases/Linux/coverage-disabled.cc b/test/asan/TestCases/coverage-disabled.cc
index cb33542a5701..dd28485a6bcf 100644
--- a/test/asan/TestCases/Linux/coverage-disabled.cc
+++ b/test/asan/TestCases/coverage-disabled.cc
@@ -1,19 +1,19 @@
// Test that no data is collected without a runtime flag.
//
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
//
// RUN: rm -rf %T/coverage-disabled
//
// RUN: mkdir -p %T/coverage-disabled/normal
-// RUN: ASAN_OPTIONS=coverage_direct=0:coverage_dir=%T/coverage-disabled/normal:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage_direct=0:coverage_dir=%T/coverage-disabled/normal:verbosity=1 %run %t
// RUN: not %sancov print %T/coverage-disabled/normal/*.sancov 2>&1
//
// RUN: mkdir -p %T/coverage-disabled/direct
-// RUN: ASAN_OPTIONS=coverage_direct=1:coverage_dir=%T/coverage-disabled/direct:verbosity=1 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage_direct=1:coverage_dir=%T/coverage-disabled/direct:verbosity=1 %run %t
// RUN: cd %T/coverage-disabled/direct
// RUN: not %sancov rawunpack *.sancov
//
-// XFAIL: android
+// UNSUPPORTED: android
int main(int argc, char **argv) {
return 0;
diff --git a/test/asan/TestCases/coverage-levels.cc b/test/asan/TestCases/coverage-levels.cc
new file mode 100644
index 000000000000..aa3641927cf2
--- /dev/null
+++ b/test/asan/TestCases/coverage-levels.cc
@@ -0,0 +1,34 @@
+// Test various levels of coverage
+//
+// RUN: %clangxx_asan -O1 -fsanitize-coverage=func %s -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_bitset=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %clangxx_asan -O1 -fsanitize-coverage=bb %s -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_bitset=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %clangxx_asan -O1 -fsanitize-coverage=edge %s -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_bitset=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3
+// RUN: %clangxx_asan -O1 -fsanitize-coverage=edge -mllvm -sanitizer-coverage-block-threshold=0 %s -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_bitset=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3
+// RUN: %clangxx_asan -O1 -fsanitize-coverage=edge,8bit-counters %s -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_counters=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK_COUNTERS
+
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_bitset=0:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOBITSET
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOBITSET
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_pcs=0:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOPCS
+//
+// REQUIRES: asan-64-bits
+
+volatile int sink;
+int main(int argc, char **argv) {
+ if (argc == 0)
+ sink = 0;
+}
+
+// CHECK1: CovDump: bitset of 1 bits written for '{{.*}}', 1 bits are set
+// CHECK1: 1 PCs written
+// CHECK2: CovDump: bitset of 3 bits written for '{{.*}}', 2 bits are set
+// CHECK2: 2 PCs written
+// CHECK3: CovDump: bitset of 4 bits written for '{{.*}}', 3 bits are set
+// CHECK3: 3 PCs written
+// CHECK3_NOBITSET-NOT: bitset of
+// CHECK3_NOPCS-NOT: PCs written
+// CHECK_COUNTERS: CovDump: 4 counters written for
diff --git a/test/asan/TestCases/Linux/coverage-maybe-open-file.cc b/test/asan/TestCases/coverage-maybe-open-file.cc
index 4580de411799..b261fb0fc775 100644
--- a/test/asan/TestCases/Linux/coverage-maybe-open-file.cc
+++ b/test/asan/TestCases/coverage-maybe-open-file.cc
@@ -1,11 +1,11 @@
// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
// XFAIL: android
//
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
// RUN: rm -rf %T/coverage-maybe-open-file
// RUN: mkdir -p %T/coverage-maybe-open-file && cd %T/coverage-maybe-open-file
-// RUN: ASAN_OPTIONS=coverage=1 %run %t | FileCheck %s --check-prefix=CHECK-success
-// RUN: ASAN_OPTIONS=coverage=0 %run %t | FileCheck %s --check-prefix=CHECK-fail
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1 %run %t | FileCheck %s --check-prefix=CHECK-success
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=0 %run %t | FileCheck %s --check-prefix=CHECK-fail
// RUN: [ "$(cat test.sancov.packed)" == "test" ]
// RUN: cd .. && rm -rf %T/coverage-maybe-open-file
@@ -15,6 +15,7 @@
#include <sanitizer/coverage_interface.h>
+// FIXME: the code below might not work on Windows.
int main(int argc, char **argv) {
int fd = __sanitizer_maybe_open_cov_file("test");
if (fd > 0) {
diff --git a/test/asan/TestCases/coverage-order-pcs.cc b/test/asan/TestCases/coverage-order-pcs.cc
new file mode 100644
index 000000000000..3f56354e44a7
--- /dev/null
+++ b/test/asan/TestCases/coverage-order-pcs.cc
@@ -0,0 +1,56 @@
+// Test coverage_order_pcs=1 flag which orders the PCs by their appearance.
+// RUN: DIR=%T/coverage-order-pcs
+// RUN: rm -rf $DIR
+// RUN: mkdir $DIR
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage_dir=$DIR:coverage=1:coverage_order_pcs=0 %run %t
+// RUN: mv $DIR/*sancov $DIR/A
+
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage_dir=$DIR:coverage=1:coverage_order_pcs=0 %run %t 1
+// RUN: mv $DIR/*sancov $DIR/B
+
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage_dir=$DIR:coverage=1:coverage_order_pcs=1 %run %t
+// RUN: mv $DIR/*sancov $DIR/C
+
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage_dir=$DIR:coverage=1:coverage_order_pcs=1 %run %t 1
+// RUN: mv $DIR/*sancov $DIR/D
+//
+// RUN: (%sancov print $DIR/A; %sancov print $DIR/B; %sancov print $DIR/C; %sancov print $DIR/D) | FileCheck %s
+//
+// RUN: rm -rf $DIR
+// Ordering works only in 64-bit mode for now.
+// REQUIRES: asan-64-bits
+#include <stdio.h>
+
+void foo() { fprintf(stderr, "FOO\n"); }
+void bar() { fprintf(stderr, "BAR\n"); }
+
+int main(int argc, char **argv) {
+ if (argc == 2) {
+ foo();
+ bar();
+ } else {
+ bar();
+ foo();
+ }
+}
+
+// Run A: no ordering
+// CHECK: [[FOO:0x[0-9a-f]*]]
+// CHECK-NEXT: [[BAR:0x[0-9a-f]*]]
+// CHECK-NEXT: [[MAIN:0x[0-9a-f]*]]
+//
+// Run B: still no ordering
+// CHECK-NEXT: [[FOO]]
+// CHECK-NEXT: [[BAR]]
+// CHECK-NEXT: [[MAIN]]
+//
+// Run C: MAIN, BAR, FOO
+// CHECK-NEXT: [[MAIN]]
+// CHECK-NEXT: [[BAR]]
+// CHECK-NEXT: [[FOO]]
+//
+// Run D: MAIN, FOO, BAR
+// CHECK-NEXT: [[MAIN]]
+// CHECK-NEXT: [[FOO]]
+// CHECK-NEXT: [[BAR]]
diff --git a/test/asan/TestCases/Linux/coverage-reset.cc b/test/asan/TestCases/coverage-reset.cc
index d3d35e21b5a7..8e025600fda7 100644
--- a/test/asan/TestCases/Linux/coverage-reset.cc
+++ b/test/asan/TestCases/coverage-reset.cc
@@ -1,7 +1,7 @@
// Test __sanitizer_reset_coverage().
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1 %run %t
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1 %run %t
#include <sanitizer/coverage_interface.h>
#include <stdio.h>
diff --git a/test/asan/TestCases/coverage-tracing.cc b/test/asan/TestCases/coverage-tracing.cc
new file mode 100644
index 000000000000..21a98515f648
--- /dev/null
+++ b/test/asan/TestCases/coverage-tracing.cc
@@ -0,0 +1,50 @@
+// Test -fsanitize-coverage=trace-bb
+//
+// RUN: %clangxx_asan -O1 -fsanitize-coverage=func,trace-bb %s -o %t
+// RUN: rm -rf %T/coverage-tracing
+// RUN: mkdir %T/coverage-tracing
+// RUN: cd %T/coverage-tracing
+// RUN: A=x; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK1; mv trace-points.*.sancov $A.points
+// RUN: A=f; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK2; mv trace-points.*.sancov $A.points
+// RUN: A=b; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK2; mv trace-points.*.sancov $A.points
+// RUN: A=bf; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK3; mv trace-points.*.sancov $A.points
+// RUN: A=fb; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK3; mv trace-points.*.sancov $A.points
+// RUN: A=ffb; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK4; mv trace-points.*.sancov $A.points
+// RUN: A=fff; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK4; mv trace-points.*.sancov $A.points
+// RUN: A=bbf; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 100 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK301; mv trace-points.*.sancov $A.points
+// RUN: diff f.points fff.points
+// RUN: diff bf.points fb.points
+// RUN: diff bf.points ffb.points
+// RUN: diff bf.points bbf.points
+// RUN: not diff x.points f.points
+// RUN: not diff x.points b.points
+// RUN: not diff x.points bf.points
+// RUN: not diff f.points b.points
+// RUN: not diff f.points bf.points
+// RUN: not diff b.points bf.points
+// RUN: rm -rf %T/coverage-tracing
+//
+// REQUIRES: asan-64-bits
+
+#include <stdlib.h>
+volatile int sink;
+__attribute__((noinline)) void foo() { sink++; }
+__attribute__((noinline)) void bar() { sink++; }
+
+int main(int argc, char **argv) {
+ if (argc != 3) return 0;
+ int n = strtol(argv[2], 0, 10);
+ while (n-- > 0) {
+ for (int i = 0; argv[1][i]; i++) {
+ if (argv[1][i] == 'f') foo();
+ else if (argv[1][i] == 'b') bar();
+ }
+ }
+}
+
+// CHECK: CovDump: Trace: 3 PCs written
+// CHECK1: CovDump: Trace: 1 Events written
+// CHECK2: CovDump: Trace: 2 Events written
+// CHECK3: CovDump: Trace: 3 Events written
+// CHECK4: CovDump: Trace: 4 Events written
+// CHECK301: CovDump: Trace: 301 Events written
diff --git a/test/asan/TestCases/debug_mapping.cc b/test/asan/TestCases/debug_mapping.cc
index f96abf6d11cf..04de97548012 100644
--- a/test/asan/TestCases/debug_mapping.cc
+++ b/test/asan/TestCases/debug_mapping.cc
@@ -1,6 +1,6 @@
// Checks that the debugging API returns correct shadow scale and offset.
// RUN: %clangxx_asan -O %s -o %t
-// RUN: env ASAN_OPTIONS=verbosity=1 %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1 %run %t 2>&1 | FileCheck %s
#include <sanitizer/asan_interface.h>
#include <stdio.h>
@@ -8,14 +8,14 @@
// printed because of verbosity=1
// CHECK: SHADOW_SCALE: [[SCALE:[0-9]+]]
-// CHECK: SHADOW_OFFSET: [[OFFSET:[0-9]+]]
+// CHECK: SHADOW_OFFSET: [[OFFSET:0x[0-9a-f]+]]
int main() {
size_t scale, offset;
__asan_get_shadow_mapping(&scale, &offset);
- fprintf(stderr, "scale: %lx\n", scale);
- fprintf(stderr, "offset: %lx\n", offset);
+ fprintf(stderr, "scale: %d\n", (int)scale);
+ fprintf(stderr, "offset: 0x%lx\n", offset);
// CHECK: scale: [[SCALE]]
// CHECK: offset: [[OFFSET]]
diff --git a/test/asan/TestCases/debug_ppc64_mapping.cc b/test/asan/TestCases/debug_ppc64_mapping.cc
index 3ddd3e1404ce..ad7e25ce3bd0 100644
--- a/test/asan/TestCases/debug_ppc64_mapping.cc
+++ b/test/asan/TestCases/debug_ppc64_mapping.cc
@@ -1,6 +1,6 @@
// RUN: %clang_asan -O0 %s -o %t
-// RUN: env ASAN_OPTIONS=verbosity=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-PPC64-V0
-// RUN: env ASAN_OPTIONS=verbosity=2 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-PPC64
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-PPC64-V0
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-PPC64
// REQUIRES: powerpc64-supported-target
#include <stdio.h>
diff --git a/test/asan/TestCases/debug_stacks.cc b/test/asan/TestCases/debug_stacks.cc
index 57bb5465035a..15af76dc438a 100644
--- a/test/asan/TestCases/debug_stacks.cc
+++ b/test/asan/TestCases/debug_stacks.cc
@@ -2,6 +2,9 @@
// malloc and free stacks.
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// FIXME: Figure out why allocation/free stack traces may be too short on ARM.
+// REQUIRES: stable-runtime
+
#include <sanitizer/asan_interface.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/test/asan/TestCases/deep_call_stack.cc b/test/asan/TestCases/deep_call_stack.cc
index a5b846e3eb75..0a26a80758c6 100644
--- a/test/asan/TestCases/deep_call_stack.cc
+++ b/test/asan/TestCases/deep_call_stack.cc
@@ -1,10 +1,10 @@
// Check that UAR mode can handle very deep recusrion.
-// RUN: export ASAN_OPTIONS=detect_stack_use_after_return=1
+// RUN: export ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1
// RUN: %clangxx_asan -O2 %s -o %t && \
// RUN: (ulimit -s 4096; %run %t) 2>&1 | FileCheck %s
// Also check that use_sigaltstack+verbosity doesn't crash.
-// RUN: env ASAN_OPTIONS=verbosity=1:use_sigaltstack=1 %run %t | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1:use_sigaltstack=1 %run %t | FileCheck %s
#include <stdio.h>
__attribute__((noinline))
diff --git a/test/asan/TestCases/deep_stack_uaf.cc b/test/asan/TestCases/deep_stack_uaf.cc
index 3e88d697fcef..7b0f56ef3c66 100644
--- a/test/asan/TestCases/deep_stack_uaf.cc
+++ b/test/asan/TestCases/deep_stack_uaf.cc
@@ -1,7 +1,7 @@
// Check that we can store lots of stack frames if asked to.
// RUN: %clangxx_asan -O0 %s -o %t 2>&1
-// RUN: env ASAN_OPTIONS=malloc_context_size=120:redzone=512 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=120:redzone=512 not %run %t 2>&1 | FileCheck %s
// XFAIL: arm-linux-gnueabi
// XFAIL: armv7l-unknown-linux-gnueabihf
#include <stdlib.h>
diff --git a/test/asan/TestCases/default_options.cc b/test/asan/TestCases/default_options.cc
index 1614fbe71b4b..a3aa6637e8ac 100644
--- a/test/asan/TestCases/default_options.cc
+++ b/test/asan/TestCases/default_options.cc
@@ -1,9 +1,6 @@
// RUN: %clangxx_asan -O2 %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s
-// __asan_default_options() are not supported on Windows.
-// XFAIL: win32
-
const char *kAsanDefaultOptions="verbosity=1 help=1";
extern "C"
diff --git a/test/asan/TestCases/double-free.cc b/test/asan/TestCases/double-free.cc
index f0dd29174849..2966aadff706 100644
--- a/test/asan/TestCases/double-free.cc
+++ b/test/asan/TestCases/double-free.cc
@@ -2,8 +2,8 @@
// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=MALLOC-CTX
// Also works if no malloc context is available.
-// RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
-// RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
// XFAIL: arm-linux-gnueabi
// XFAIL: armv7l-unknown-linux-gnueabihf
diff --git a/test/asan/TestCases/dump_instruction_bytes.cc b/test/asan/TestCases/dump_instruction_bytes.cc
index 981e3c31327f..33f382cb12be 100644
--- a/test/asan/TestCases/dump_instruction_bytes.cc
+++ b/test/asan/TestCases/dump_instruction_bytes.cc
@@ -1,7 +1,7 @@
// Check that ASan prints the faulting instruction bytes on
// dump_instruction_bytes=1
// RUN: %clangxx_asan %s -o %t
-// RUN: env ASAN_OPTIONS=dump_instruction_bytes=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-DUMP
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS: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
//
// REQUIRES: x86_64-supported-target,i386-supported-target
diff --git a/test/asan/TestCases/free_hook_realloc.cc b/test/asan/TestCases/free_hook_realloc.cc
index 4b2753252a8d..cbc5d6fed56e 100644
--- a/test/asan/TestCases/free_hook_realloc.cc
+++ b/test/asan/TestCases/free_hook_realloc.cc
@@ -2,9 +2,6 @@
// RUN: %clangxx_asan -O2 %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s
-// Malloc/free hooks are not supported on Windows.
-// XFAIL: win32
-
#include <stdlib.h>
#include <unistd.h>
#include <sanitizer/allocator_interface.h>
diff --git a/test/asan/TestCases/gc-test.cc b/test/asan/TestCases/gc-test.cc
index 4ffa51dd22d3..3fedd6a68d38 100644
--- a/test/asan/TestCases/gc-test.cc
+++ b/test/asan/TestCases/gc-test.cc
@@ -1,9 +1,9 @@
// RUN: %clangxx_asan %s -pthread -o %t
-// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
-// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
// RUN: %clangxx_asan -O3 %s -pthread -o %t
-// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
-// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
// REQUIRES: stable-runtime
#include <assert.h>
diff --git a/test/asan/TestCases/heap-overflow-large.cc b/test/asan/TestCases/heap-overflow-large.cc
index eb2fcc3220e7..566b1158a5da 100644
--- a/test/asan/TestCases/heap-overflow-large.cc
+++ b/test/asan/TestCases/heap-overflow-large.cc
@@ -15,9 +15,9 @@ int main(int argc, char *argv[]) {
int *x = new int[5];
memset(x, 0, sizeof(x[0]) * 5);
int index = atoi(argv[1]);
- int res = x[index];
+ unsigned res = x[index];
// CHECK: main
// CHECK-NOT: CHECK failed
delete[] x;
- return res ? res : 1;
+ return (res % 10) + 1;
}
diff --git a/test/asan/TestCases/heap-overflow.cc b/test/asan/TestCases/heap-overflow.cc
index 70a1203562be..caecea704966 100644
--- a/test/asan/TestCases/heap-overflow.cc
+++ b/test/asan/TestCases/heap-overflow.cc
@@ -2,7 +2,7 @@
// 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
-// RUN: env ASAN_OPTIONS=print_stats=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:print_stats=1 not %run %t 2>&1 | FileCheck %s
// FIXME: Fix this test under GCC.
// REQUIRES: Clang
diff --git a/test/asan/TestCases/heavy_uar_test.cc b/test/asan/TestCases/heavy_uar_test.cc
index 1f8caea21690..a70dcef14345 100644
--- a/test/asan/TestCases/heavy_uar_test.cc
+++ b/test/asan/TestCases/heavy_uar_test.cc
@@ -1,4 +1,4 @@
-// RUN: export ASAN_OPTIONS=detect_stack_use_after_return=1
+// RUN: export ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
// XFAIL: arm-linux-gnueabi
diff --git a/test/asan/TestCases/init-order-atexit.cc b/test/asan/TestCases/init-order-atexit.cc
index e0dac325ce58..1bbc655b17f1 100644
--- a/test/asan/TestCases/init-order-atexit.cc
+++ b/test/asan/TestCases/init-order-atexit.cc
@@ -1,6 +1,3 @@
-// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
-// XFAIL: android
-//
// Test for the following situation:
// (1) global A is constructed.
// (2) exit() is called during construction of global B.
@@ -8,7 +5,7 @@
// We do *not* want to report init-order bug in this case.
// RUN: %clangxx_asan -O0 %s %p/Helpers/init-order-atexit-extra.cc -o %t
-// RUN: env ASAN_OPTIONS=strict_init_order=true not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true not %run %t 2>&1 | FileCheck %s
#include <stdio.h>
#include <stdlib.h>
diff --git a/test/asan/TestCases/init-order-pthread-create.cc b/test/asan/TestCases/init-order-pthread-create.cc
index eeff308a4cd5..12362fc440dc 100644
--- a/test/asan/TestCases/init-order-pthread-create.cc
+++ b/test/asan/TestCases/init-order-pthread-create.cc
@@ -2,29 +2,40 @@
// called.
// RUN: %clangxx_asan %s %p/Helpers/init-order-pthread-create-extra.cc -pthread -o %t
-// RUN: env ASAN_OPTIONS=strict_init_order=true %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true %run %t
#include <stdio.h>
#include <pthread.h>
+#include <unistd.h>
-void *run(void *arg) {
- return arg;
+void *bar(void *input, bool sleep_before_init) {
+ if (sleep_before_init)
+ usleep(500000);
+ return input;
}
-void *foo(void *input) {
- pthread_t t;
- pthread_create(&t, 0, run, input);
- void *res;
- pthread_join(t, &res);
- return res;
-}
+void *glob = bar((void*)0x1234, false);
+extern void *glob2;
-void *bar(void *input) {
- return input;
+void *poll(void *arg) {
+ void **glob = (void**)arg;
+ while (true) {
+ usleep(100000);
+ printf("glob is now: %p\n", *glob);
+ }
}
-void *glob = foo((void*)0x1234);
-extern void *glob2;
+struct GlobalPollerStarter {
+ GlobalPollerStarter() {
+ pthread_t p;
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ pthread_create(&p, 0, poll, &glob);
+ pthread_attr_destroy(&attr);
+ printf("glob poller is started");
+ }
+} global_poller;
int main() {
printf("%p %p\n", glob, glob2);
diff --git a/test/asan/TestCases/initialization-blacklist.cc b/test/asan/TestCases/initialization-blacklist.cc
index 8ea6b46c1833..bcdb111b8bfb 100644
--- a/test/asan/TestCases/initialization-blacklist.cc
+++ b/test/asan/TestCases/initialization-blacklist.cc
@@ -3,15 +3,15 @@
// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-blacklist-extra.cc\
// RUN: %p/Helpers/initialization-blacklist-extra2.cc \
// RUN: -fsanitize-blacklist=%p/Helpers/initialization-blacklist.txt -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1
// RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-blacklist-extra.cc\
// RUN: %p/Helpers/initialization-blacklist-extra2.cc \
// RUN: -fsanitize-blacklist=%p/Helpers/initialization-blacklist.txt -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1
// RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-blacklist-extra.cc\
// RUN: %p/Helpers/initialization-blacklist-extra2.cc \
// RUN: -fsanitize-blacklist=%p/Helpers/initialization-blacklist.txt -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1
// Function is defined in another TU.
int readBadGlobal();
diff --git a/test/asan/TestCases/initialization-bug.cc b/test/asan/TestCases/initialization-bug.cc
index badc6d1d1165..6257d67c308d 100644
--- a/test/asan/TestCases/initialization-bug.cc
+++ b/test/asan/TestCases/initialization-bug.cc
@@ -1,7 +1,7 @@
// Test to make sure basic initialization order errors are caught.
-// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-bug-extra2.cc -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-bug-extra2.cc -o %t-INIT-ORDER-EXE
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true not %run %t-INIT-ORDER-EXE 2>&1 | FileCheck %s
// Do not test with optimization -- the error may be optimized away.
@@ -32,6 +32,8 @@ int __attribute__((noinline)) initX() {
// CHECK: {{AddressSanitizer: initialization-order-fiasco}}
// CHECK: {{READ of size .* at 0x.* thread T0}}
// CHECK: {{0x.* is located 0 bytes inside of global variable .*(y|z).*}}
+ // CHECK: registered at:
+ // CHECK: 0x{{.*}} in __asan_register_globals
}
// This initializer begins our initialization order problems.
diff --git a/test/asan/TestCases/initialization-constexpr.cc b/test/asan/TestCases/initialization-constexpr.cc
index 644246186e02..1188766b6020 100644
--- a/test/asan/TestCases/initialization-constexpr.cc
+++ b/test/asan/TestCases/initialization-constexpr.cc
@@ -5,13 +5,13 @@
// not dynamic initialization).
// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1
// RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1
// RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1
// RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1
class Integer {
private:
diff --git a/test/asan/TestCases/initialization-nobug.cc b/test/asan/TestCases/initialization-nobug.cc
index 1249deb425aa..3890edf07202 100644
--- a/test/asan/TestCases/initialization-nobug.cc
+++ b/test/asan/TestCases/initialization-nobug.cc
@@ -2,13 +2,13 @@
// order checking. If successful, this will just return 0.
// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-nobug-extra.cc -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1
// RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-nobug-extra.cc -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1
// RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-nobug-extra.cc -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1
// RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-nobug-extra.cc -o %t
-// RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1
// Simple access:
// Make sure that accessing a global in the same TU is safe
diff --git a/test/asan/TestCases/interface_test.cc b/test/asan/TestCases/interface_test.cc
index dc9d0652c8c3..9419f07e91ea 100644
--- a/test/asan/TestCases/interface_test.cc
+++ b/test/asan/TestCases/interface_test.cc
@@ -1,8 +1,8 @@
// Check that user may include ASan interface header.
// RUN: %clang_asan %s -o %t && %run %t
// RUN: %clang_asan -x c %s -o %t && %run %t
-// RUN: %clang %s -o %t && %run %t
-// RUN: %clang -x c %s -o %t && %run %t
+// RUN: %clang %s -pie -o %t && %run %t
+// RUN: %clang -x c %s -pie -o %t && %run %t
#include <sanitizer/asan_interface.h>
int main() {
diff --git a/test/asan/TestCases/invalid-free.cc b/test/asan/TestCases/invalid-free.cc
index cb545ccc215e..c6f7b842a91d 100644
--- a/test/asan/TestCases/invalid-free.cc
+++ b/test/asan/TestCases/invalid-free.cc
@@ -2,8 +2,8 @@
// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=MALLOC-CTX
// Also works if no malloc context is available.
-// RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
-// RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
// XFAIL: arm-linux-gnueabi
// XFAIL: armv7l-unknown-linux-gnueabihf
diff --git a/test/asan/TestCases/log-path_test.cc b/test/asan/TestCases/log-path_test.cc
index 7dd1fadda86d..d253a6f50cf3 100644
--- a/test/asan/TestCases/log-path_test.cc
+++ b/test/asan/TestCases/log-path_test.cc
@@ -9,21 +9,21 @@
// Good log_path.
// RUN: rm -f %t.log.*
-// RUN: env ASAN_OPTIONS=log_path=%t.log not %run %t 2> %t.out
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:log_path=%t.log not %run %t 2> %t.out
// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.*
// Invalid log_path.
-// RUN: env ASAN_OPTIONS=log_path=/dev/null/INVALID not %run %t 2> %t.out
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:log_path=/dev/null/INVALID not %run %t 2> %t.out
// RUN: FileCheck %s --check-prefix=CHECK-INVALID < %t.out
// Too long log_path.
-// RUN: env ASAN_OPTIONS=log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \
// RUN: not %run %t 2> %t.out
// RUN: FileCheck %s --check-prefix=CHECK-LONG < %t.out
// Run w/o errors should not produce any log.
// RUN: rm -f %t.log.*
-// RUN: env ASAN_OPTIONS=log_path=%t.log %run %t ARG ARG ARG
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:log_path=%t.log %run %t ARG ARG ARG
// RUN: not cat %t.log.*
// FIXME: log_path is not supported on Windows yet.
diff --git a/test/asan/TestCases/malloc_context_size.cc b/test/asan/TestCases/malloc_context_size.cc
index 0d9f31598545..91e1bdc5613e 100644
--- a/test/asan/TestCases/malloc_context_size.cc
+++ b/test/asan/TestCases/malloc_context_size.cc
@@ -1,9 +1,9 @@
// RUN: %clangxx_asan -O0 %s -o %t
-// RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
-// RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
-// RUN: env ASAN_OPTIONS=malloc_context_size=1:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
-// RUN: env ASAN_OPTIONS=malloc_context_size=1:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
-// RUN: env ASAN_OPTIONS=malloc_context_size=2 not %run %t 2>&1 | FileCheck %s --check-prefix=TWO
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=1:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=1:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:malloc_context_size=2 not %run %t 2>&1 | FileCheck %s --check-prefix=TWO
int main() {
char *x = new char[20];
diff --git a/test/asan/TestCases/malloc_fill.cc b/test/asan/TestCases/malloc_fill.cc
index 5c926803708d..13a73a719ddd 100644
--- a/test/asan/TestCases/malloc_fill.cc
+++ b/test/asan/TestCases/malloc_fill.cc
@@ -1,8 +1,8 @@
// Check that we fill malloc-ed memory correctly.
// RUN: %clangxx_asan %s -o %t
// RUN: %run %t | FileCheck %s
-// RUN: env ASAN_OPTIONS=max_malloc_fill_size=10:malloc_fill_byte=8 %run %t | FileCheck %s --check-prefix=CHECK-10-8
-// RUN: env ASAN_OPTIONS=max_malloc_fill_size=20:malloc_fill_byte=171 %run %t | FileCheck %s --check-prefix=CHECK-20-ab
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:max_malloc_fill_size=10:malloc_fill_byte=8 %run %t | FileCheck %s --check-prefix=CHECK-10-8
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:max_malloc_fill_size=20:malloc_fill_byte=171 %run %t | FileCheck %s --check-prefix=CHECK-20-ab
#include <stdio.h>
int main(int argc, char **argv) {
diff --git a/test/asan/TestCases/max_redzone.cc b/test/asan/TestCases/max_redzone.cc
index 01c25a9f3efc..c5539bcfb16f 100644
--- a/test/asan/TestCases/max_redzone.cc
+++ b/test/asan/TestCases/max_redzone.cc
@@ -1,8 +1,8 @@
// Test max_redzone runtime option.
-// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=max_redzone=16 %run %t 0 2>&1
+// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:max_redzone=16 %run %t 0 2>&1
// RUN: %clangxx_asan -O0 %s -o %t && %run %t 1 2>&1
-// RUN: %clangxx_asan -O3 %s -o %t && env ASAN_OPTIONS=max_redzone=16 %run %t 0 2>&1
+// RUN: %clangxx_asan -O3 %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:max_redzone=16 %run %t 0 2>&1
// RUN: %clangxx_asan -O3 %s -o %t && %run %t 1 2>&1
#include <stdio.h>
diff --git a/test/asan/TestCases/memcmp_strict_test.cc b/test/asan/TestCases/memcmp_strict_test.cc
index 16b7673dd547..a15d0a35e5ec 100644
--- a/test/asan/TestCases/memcmp_strict_test.cc
+++ b/test/asan/TestCases/memcmp_strict_test.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=strict_memcmp=0 %run %t
-// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=strict_memcmp=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:strict_memcmp=0 %run %t
+// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:strict_memcmp=1 not %run %t 2>&1 | FileCheck %s
// Default to strict_memcmp=1.
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
diff --git a/test/asan/TestCases/mmap_limit_mb.cc b/test/asan/TestCases/mmap_limit_mb.cc
index d4ffb2eac246..02410525b2d6 100644
--- a/test/asan/TestCases/mmap_limit_mb.cc
+++ b/test/asan/TestCases/mmap_limit_mb.cc
@@ -3,10 +3,10 @@
// RUN: %clangxx_asan -O2 %s -o %t
// RUN: %run %t 20 16
// RUN: %run %t 30 1000000
-// RUN: env ASAN_OPTIONS=mmap_limit_mb=300 %run %t 20 16
-// RUN: env ASAN_OPTIONS=mmap_limit_mb=300 %run %t 20 1000000
-// RUN: env ASAN_OPTIONS=mmap_limit_mb=300 not %run %t 500 16 2>&1 | FileCheck %s
-// RUN: env ASAN_OPTIONS=mmap_limit_mb=300 not %run %t 500 1000000 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:mmap_limit_mb=300 %run %t 20 16
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:mmap_limit_mb=300 %run %t 20 1000000
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:mmap_limit_mb=300 not %run %t 500 16 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:mmap_limit_mb=300 not %run %t 500 1000000 2>&1 | FileCheck %s
// XFAIL: arm-linux-gnueabi
#include <assert.h>
diff --git a/test/asan/TestCases/no_asan_gen_globals.c b/test/asan/TestCases/no_asan_gen_globals.c
index 0a383da1384d..2b13deace4b5 100644
--- a/test/asan/TestCases/no_asan_gen_globals.c
+++ b/test/asan/TestCases/no_asan_gen_globals.c
@@ -1,5 +1,7 @@
// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
// XFAIL: android
+// FIXME: http://llvm.org/bugs/show_bug.cgi?id=22682
+// REQUIRES: asan-64-bits
//
// Make sure __asan_gen_* strings do not end up in the symbol table.
diff --git a/test/asan/TestCases/on_error_callback.cc b/test/asan/TestCases/on_error_callback.cc
index c378c8b2de1b..0ad83d549af2 100644
--- a/test/asan/TestCases/on_error_callback.cc
+++ b/test/asan/TestCases/on_error_callback.cc
@@ -1,8 +1,5 @@
// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
-// FIXME: __asan_on_error() is not supported on Windows yet.
-// XFAIL: win32
-
#include <stdio.h>
#include <stdlib.h>
diff --git a/test/asan/TestCases/poison_partial.cc b/test/asan/TestCases/poison_partial.cc
index ce9c98b7859a..8a8921566dbc 100644
--- a/test/asan/TestCases/poison_partial.cc
+++ b/test/asan/TestCases/poison_partial.cc
@@ -1,8 +1,8 @@
// RUN: %clangxx_asan -O0 %s -o %t
// RUN: not %run %t 2>&1 | FileCheck %s
// RUN: not %run %t heap 2>&1 | FileCheck %s
-// RUN: env ASAN_OPTIONS=poison_partial=0 %run %t
-// RUN: env ASAN_OPTIONS=poison_partial=0 %run %t heap
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:poison_partial=0 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:poison_partial=0 %run %t heap
#include <string.h>
char g[21];
char *x;
diff --git a/test/asan/TestCases/print_summary.cc b/test/asan/TestCases/print_summary.cc
index 79411c529469..675934071252 100644
--- a/test/asan/TestCases/print_summary.cc
+++ b/test/asan/TestCases/print_summary.cc
@@ -1,14 +1,16 @@
// RUN: %clangxx_asan -O0 %s -o %t
-// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=YES
-// RUN: env ASAN_OPTIONS=print_summary=false not %run %t 2>&1 | FileCheck %s --check-prefix=NO
+// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=SOURCE
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:symbolize=false not %run %t 2>&1 | FileCheck %s --check-prefix=MODULE
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:print_summary=false not %run %t 2>&1 | FileCheck %s --check-prefix=MISSING
int main() {
char *x = new char[20];
delete[] x;
return x[0];
- // YES: ERROR: AddressSanitizer: heap-use-after-free
- // YES: SUMMARY: AddressSanitizer: heap-use-after-free
- // NO: ERROR: AddressSanitizer: heap-use-after-free
- // NO-NOT: SUMMARY: AddressSanitizer: heap-use-after-free
+ // SOURCE: ERROR: AddressSanitizer: heap-use-after-free
+ // SOURCE: SUMMARY: AddressSanitizer: heap-use-after-free {{.*}}print_summary.cc:[[@LINE-2]]{{.*}} main
+ // MODULE: ERROR: AddressSanitizer: heap-use-after-free
+ // MODULE: SUMMARY: AddressSanitizer: heap-use-after-free ({{.*}}+0x{{.*}})
+ // MISSING: ERROR: AddressSanitizer: heap-use-after-free
+ // MISSING-NOT: SUMMARY
}
-
diff --git a/test/asan/TestCases/printf-1.c b/test/asan/TestCases/printf-1.c
index 5657083c5865..2df74b67a31a 100644
--- a/test/asan/TestCases/printf-1.c
+++ b/test/asan/TestCases/printf-1.c
@@ -1,6 +1,6 @@
// RUN: %clang_asan -O2 %s -o %t
-// RUN: env ASAN_OPTIONS=check_printf=1 %run %t 2>&1 | FileCheck %s
-// RUN: env ASAN_OPTIONS=check_printf=0 %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_printf=1 %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_printf=0 %run %t 2>&1 | FileCheck %s
// RUN: %run %t 2>&1 | FileCheck %s
#include <stdio.h>
diff --git a/test/asan/TestCases/printf-2.c b/test/asan/TestCases/printf-2.c
index e9cb47e24c15..b3ab96111142 100644
--- a/test/asan/TestCases/printf-2.c
+++ b/test/asan/TestCases/printf-2.c
@@ -1,9 +1,9 @@
// RUN: %clang_asan -O2 %s -o %t
// We need replace_str=0 and replace_intrin=0 to avoid reporting errors in
// strlen() and memcpy() called by printf().
-// RUN: env ASAN_OPTIONS=replace_str=0:replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
-// RUN: env ASAN_OPTIONS=replace_str=0:replace_intrin=0:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
-// RUN: env ASAN_OPTIONS=replace_str=0:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:replace_str=0:replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:replace_str=0:replace_intrin=0:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:replace_str=0:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
// FIXME: printf is not intercepted on Windows yet.
// XFAIL: win32
diff --git a/test/asan/TestCases/printf-3.c b/test/asan/TestCases/printf-3.c
index d16833d83c6e..bc9fece5dd96 100644
--- a/test/asan/TestCases/printf-3.c
+++ b/test/asan/TestCases/printf-3.c
@@ -1,6 +1,6 @@
// RUN: %clang_asan -O2 %s -o %t
-// RUN: env ASAN_OPTIONS=check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
-// RUN: env ASAN_OPTIONS=check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
// FIXME: printf is not intercepted on Windows yet.
diff --git a/test/asan/TestCases/printf-4.c b/test/asan/TestCases/printf-4.c
index e269211d4871..b2a14ff4f25a 100644
--- a/test/asan/TestCases/printf-4.c
+++ b/test/asan/TestCases/printf-4.c
@@ -1,8 +1,8 @@
// RUN: %clang_asan -O2 %s -o %t
// We need replace_str=0 and replace_intrin=0 to avoid reporting errors in
// strlen() and memcpy() called by puts().
-// RUN: env ASAN_OPTIONS=replace_str=0:replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
-// RUN: env ASAN_OPTIONS=replace_str=0:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:replace_str=0:replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:replace_str=0:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
// FIXME: printf is not intercepted on Windows yet.
// XFAIL: win32
diff --git a/test/asan/TestCases/printf-5.c b/test/asan/TestCases/printf-5.c
index ac2c1c4b2997..d4e2a0ab9cce 100644
--- a/test/asan/TestCases/printf-5.c
+++ b/test/asan/TestCases/printf-5.c
@@ -1,8 +1,8 @@
// RUN: %clang_asan -O2 %s -o %t
// We need replace_intrin=0 to avoid reporting errors in memcpy.
-// RUN: env ASAN_OPTIONS=replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
-// RUN: env ASAN_OPTIONS=replace_intrin=0:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
-// RUN: env ASAN_OPTIONS=replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:replace_intrin=0:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
// FIXME: printf is not intercepted on Windows yet.
// XFAIL: win32
diff --git a/test/asan/TestCases/sleep_before_dying.c b/test/asan/TestCases/sleep_before_dying.c
index 28ae0bf66d47..2029f572a9eb 100644
--- a/test/asan/TestCases/sleep_before_dying.c
+++ b/test/asan/TestCases/sleep_before_dying.c
@@ -1,5 +1,5 @@
// RUN: %clang_asan -O2 %s -o %t
-// RUN: env ASAN_OPTIONS="sleep_before_dying=1" not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:sleep_before_dying=1" not %run %t 2>&1 | FileCheck %s
#include <stdlib.h>
int main() {
diff --git a/test/asan/TestCases/stack-overflow.cc b/test/asan/TestCases/stack-overflow.cc
index d4bb74730f12..d792c466f977 100644
--- a/test/asan/TestCases/stack-overflow.cc
+++ b/test/asan/TestCases/stack-overflow.cc
@@ -1,18 +1,18 @@
// Test ASan detection of stack-overflow condition.
-// RUN: %clangxx_asan -O0 %s -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O0 %s -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O0 %s -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O0 %s -DTHREAD -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -DTHREAD -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O0 %s -DTHREAD -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -DTHREAD -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O0 %s -DTHREAD -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -DTHREAD -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -DTHREAD -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -DTHREAD -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -DTHREAD -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -DTHREAD -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -DTHREAD -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -DTHREAD -pthread -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
// RUN: not %run %t 2>&1 | FileCheck %s
// REQUIRES: stable-runtime
diff --git a/test/asan/TestCases/stack-use-after-return.cc b/test/asan/TestCases/stack-use-after-return.cc
index 437c457748c4..669e8703b82f 100644
--- a/test/asan/TestCases/stack-use-after-return.cc
+++ b/test/asan/TestCases/stack-use-after-return.cc
@@ -1,9 +1,9 @@
-// RUN: export ASAN_OPTIONS=detect_stack_use_after_return=1
+// RUN: export ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1
// RUN: %clangxx_asan -O0 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O1 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O2 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O3 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=0 %run %t
// Regression test for a CHECK failure with small stack size and large frame.
// RUN: %clangxx_asan -O3 %s -pthread -o %t -DkSize=10000 -DUseThread -DkStackSize=65536 && not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s
//
diff --git a/test/asan/TestCases/strcasestr-1.c b/test/asan/TestCases/strcasestr-1.c
new file mode 100644
index 000000000000..c6f9d193e503
--- /dev/null
+++ b/test/asan/TestCases/strcasestr-1.c
@@ -0,0 +1,24 @@
+// Test haystack overflow in strcasestr function
+// RUN: %clang_asan %s -o %t && ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+// Test intercept_strstr asan option
+// Disable other interceptors because strlen may be called inside strcasestr
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strstr=false:replace_str=false %run %t 2>&1
+
+// There's no interceptor for strcasestr on Windows
+// XFAIL: win32
+
+#define _GNU_SOURCE
+#include <assert.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ char *r = 0;
+ char s2[] = "c";
+ char s1[] = {'a', 'C'};
+ char s3 = 0;
+ r = strcasestr(s1, s2);
+ // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ assert(r == s1 + 1);
+ return 0;
+}
diff --git a/test/asan/TestCases/strcasestr-2.c b/test/asan/TestCases/strcasestr-2.c
new file mode 100644
index 000000000000..a4bc6362636e
--- /dev/null
+++ b/test/asan/TestCases/strcasestr-2.c
@@ -0,0 +1,24 @@
+// Test needle overflow in strcasestr function
+// RUN: %clang_asan %s -o %t && ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+// Test intercept_strstr asan option
+// Disable other interceptors because strlen may be called inside strcasestr
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strstr=false:replace_str=false %run %t 2>&1
+
+// There's no interceptor for strcasestr on Windows
+// XFAIL: win32
+
+#define _GNU_SOURCE
+#include <assert.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ char *r = 0;
+ char s1[] = "ab";
+ char s2[] = {'c'};
+ char s3 = 0;
+ r = strcasestr(s1, s2);
+ assert(r == 0);
+ // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ return 0;
+}
diff --git a/test/asan/TestCases/strcasestr_strict.c b/test/asan/TestCases/strcasestr_strict.c
new file mode 100644
index 000000000000..03c066bb1b9d
--- /dev/null
+++ b/test/asan/TestCases/strcasestr_strict.c
@@ -0,0 +1,28 @@
+// Test strict_string_checks option in strcasestr function
+// RUN: %clang_asan %s -o %t && %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+// There's no interceptor for strcasestr on Windows
+// XFAIL: win32
+
+#define _GNU_SOURCE
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ size_t size = 100;
+ char *s1 = (char*)malloc(size);
+ char *s2 = (char*)malloc(size);
+ memset(s1, 'o', size);
+ memset(s2, 'O', size);
+ s2[size - 1]='\0';
+ char* r = strcasestr(s1, s2);
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK: READ of size 101
+ assert(r == s1);
+ free(s1);
+ free(s2);
+ return 0;
+}
diff --git a/test/asan/TestCases/strcat_strict.c b/test/asan/TestCases/strcat_strict.c
new file mode 100644
index 000000000000..8321f5b620f9
--- /dev/null
+++ b/test/asan/TestCases/strcat_strict.c
@@ -0,0 +1,44 @@
+// Test strict_string_checks option in strcat function
+// RUN: %clang_asan %s -o %t
+// RUN: not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-NONSTRICT --check-prefix=CHECK1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-NONSTRICT --check-prefix=CHECK1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-STRICT --check-prefix=CHECK1
+// RUN: not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-NONSTRICT --check-prefix=CHECK2
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-NONSTRICT --check-prefix=CHECK2
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-STRICT --check-prefix=CHECK2
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *to, int to_size, char *from) {
+ // One of arguments points to not allocated memory.
+ char* r = strcat(to + to_size, from);
+}
+
+void test2(char *to, int to_size, char *from) {
+ // "to" is not zero-terminated.
+ memset(to, 'z', to_size);
+ char* r = strcat(to, from);
+}
+
+int main(int argc, char **argv) {
+ size_t to_size = 100;
+ char *to = (char*)malloc(to_size);
+ size_t from_size = 20;
+ char *from = (char*)malloc(from_size);
+ memset(from, 'z', from_size);
+ from[from_size - 1] = '\0';
+ if (argc != 2) return 1;
+ if (!strcmp(argv[1], "test1")) test1(to, to_size, from);
+ // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK1-STRICT: READ of size 1
+ // CHECK1-NONSTRICT: WRITE of size 20
+ if (!strcmp(argv[1], "test2")) test2(to, to_size, from);
+ // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK2-STRICT: READ of size 101
+ // CHECK2-NONSTRICT: WRITE of size 20
+ free(to);
+ free(from);
+ return 0;
+}
diff --git a/test/asan/TestCases/strchr_strict.c b/test/asan/TestCases/strchr_strict.c
new file mode 100644
index 000000000000..48c1f139583e
--- /dev/null
+++ b/test/asan/TestCases/strchr_strict.c
@@ -0,0 +1,22 @@
+// Test strict_string_checks option in strchr function
+// RUN: %clang_asan %s -o %t && %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ size_t size = 100;
+ char fill = 'o';
+ char *s = (char*)malloc(size);
+ memset(s, fill, size);
+ char c = 'o';
+ char* r = strchr(s, c);
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK: READ of size 101
+ assert(r == s);
+ free(s);
+ return 0;
+}
diff --git a/test/asan/TestCases/strcmp_strict.c b/test/asan/TestCases/strcmp_strict.c
new file mode 100644
index 000000000000..316765e18371
--- /dev/null
+++ b/test/asan/TestCases/strcmp_strict.c
@@ -0,0 +1,26 @@
+// Test strict_string_checks option in strcmp function
+// RUN: %clang_asan %s -o %t && %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ size_t size = 100;
+ char fill = 'o';
+ char *s1 = (char*)malloc(size);
+ memset(s1, fill, size);
+ char *s2 = (char*)malloc(size);
+ memset(s2, fill, size);
+ s1[size - 1] = 'z';
+ s2[size - 1] = 'x';
+ int r = strcmp(s1, s2);
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK: READ of size 101
+ assert(r == 1);
+ free(s1);
+ free(s2);
+ return 0;
+}
diff --git a/test/asan/TestCases/strcspn-1.c b/test/asan/TestCases/strcspn-1.c
new file mode 100644
index 000000000000..ef02a049530a
--- /dev/null
+++ b/test/asan/TestCases/strcspn-1.c
@@ -0,0 +1,19 @@
+// Test string s1 overflow in strcspn function
+// RUN: %clang_asan %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+// Test intercept_strspn asan option
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strspn=false %run %t 2>&1
+
+#include <assert.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ size_t r;
+ char s2[] = "ab";
+ char s1[] = {'c', 'a'};
+ char s3 = 0;
+ r = strcspn(s1, s2);
+ // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ assert(r == 1);
+ return 0;
+}
diff --git a/test/asan/TestCases/strcspn-2.c b/test/asan/TestCases/strcspn-2.c
new file mode 100644
index 000000000000..aa82aa60abfe
--- /dev/null
+++ b/test/asan/TestCases/strcspn-2.c
@@ -0,0 +1,19 @@
+// Test stopset overflow in strcspn function
+// RUN: %clang_asan %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+// Test intercept_strcspn asan option
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strspn=false %run %t 2>&1
+
+#include <assert.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ size_t r;
+ char s1[] = "ab";
+ char s2[] = {'a'};
+ char s3 = 0;
+ r = strcspn(s1, s2);
+ // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ assert(r == 0);
+ return 0;
+}
diff --git a/test/asan/TestCases/strcspn_strict.c b/test/asan/TestCases/strcspn_strict.c
new file mode 100644
index 000000000000..7198f9a08723
--- /dev/null
+++ b/test/asan/TestCases/strcspn_strict.c
@@ -0,0 +1,26 @@
+// Test strict_string_checks option in strcspn function
+// RUN: %clang_asan %s -o %t && %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ size_t size = 100;
+ char fill = 'o';
+ char *s1 = (char*)malloc(size);
+ char *s2 = (char*)malloc(size);
+ memset(s1, fill, size);
+ s1[0] = 'z';
+ memset(s2, fill, size);
+ s2[size-1] = '\0';
+ size_t r = strcspn(s1, s2);
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK: READ of size 101
+ assert(r == 1);
+ free(s1);
+ free(s2);
+ return 0;
+}
diff --git a/test/asan/TestCases/strip_path_prefix.c b/test/asan/TestCases/strip_path_prefix.c
index 4556e9031e2d..fc9ebd1691cc 100644
--- a/test/asan/TestCases/strip_path_prefix.c
+++ b/test/asan/TestCases/strip_path_prefix.c
@@ -1,5 +1,5 @@
// RUN: %clang_asan -O2 %s -o %t
-// RUN: env ASAN_OPTIONS="strip_path_prefix='/'" not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:strip_path_prefix='%S/'" not %run %t 2>&1 | FileCheck %s
#include <stdlib.h>
int main() {
@@ -8,5 +8,5 @@ int main() {
return x[5];
// Check that paths in error report don't start with slash.
// CHECK: heap-use-after-free
- // CHECK-NOT: #0 0x{{.*}} ({{[/].*}})
+ // CHECK: #0 0x{{.*}} in main strip_path_prefix.c:[[@LINE-3]]
}
diff --git a/test/asan/TestCases/strncat_strict.c b/test/asan/TestCases/strncat_strict.c
new file mode 100644
index 000000000000..16de17689d0c
--- /dev/null
+++ b/test/asan/TestCases/strncat_strict.c
@@ -0,0 +1,44 @@
+// Test strict_string_checks option in strncat function
+// RUN: %clang_asan %s -o %t
+// RUN: not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-NONSTRICT --check-prefix=CHECK1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-NONSTRICT --check-prefix=CHECK1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-STRICT --check-prefix=CHECK1
+// RUN: not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-NONSTRICT --check-prefix=CHECK2
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-NONSTRICT --check-prefix=CHECK2
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-STRICT --check-prefix=CHECK2
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *to, int to_size, char *from) {
+ // One of arguments points to not allocated memory.
+ char* r = strncat(to + to_size, from, 2);
+}
+
+void test2(char *to, int to_size, char *from) {
+ // "to" is not zero-terminated.
+ memset(to, 'z', to_size);
+ char* r = strncat(to, from, 1);
+}
+
+int main(int argc, char **argv) {
+ size_t to_size = 100;
+ char *to = (char*)malloc(to_size);
+ size_t from_size = 20;
+ char *from = (char*)malloc(from_size);
+ memset(from, 'z', from_size);
+ from[from_size - 1] = '\0';
+ if (argc != 2) return 1;
+ if (!strcmp(argv[1], "test1")) test1(to, to_size, from);
+ // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK1-STRICT: READ of size 1
+ // CHECK1-NONSTRICT: WRITE of size 3
+ if (!strcmp(argv[1], "test2")) test2(to, to_size, from);
+ // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK2-STRICT: READ of size 101
+ // CHECK2-NONSTRICT: WRITE of size 2
+ free(to);
+ free(from);
+ return 0;
+}
diff --git a/test/asan/TestCases/strpbrk-1.c b/test/asan/TestCases/strpbrk-1.c
new file mode 100644
index 000000000000..7cd45bd0979a
--- /dev/null
+++ b/test/asan/TestCases/strpbrk-1.c
@@ -0,0 +1,19 @@
+// Test string s1 overflow in strpbrk function
+// RUN: %clang_asan %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+// Test intercept_strpbrk asan option
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strpbrk=false %run %t 2>&1
+
+#include <assert.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ char *r;
+ char s2[] = "ab";
+ char s1[] = {'c', 'a'};
+ char s3 = 0;
+ r = strpbrk(s1, s2);
+ // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ assert(r == s1 + 1);
+ return 0;
+}
diff --git a/test/asan/TestCases/strpbrk-2.c b/test/asan/TestCases/strpbrk-2.c
new file mode 100644
index 000000000000..0d50c002a21a
--- /dev/null
+++ b/test/asan/TestCases/strpbrk-2.c
@@ -0,0 +1,19 @@
+// Test stopset overflow in strpbrk function
+// RUN: %clang_asan %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+// Test intercept_strpbrk asan option
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strpbrk=false %run %t 2>&1
+
+#include <assert.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ char *r;
+ char s1[] = "c";
+ char s2[] = {'b', 'c'};
+ char s3 = 0;
+ r = strpbrk(s1, s2);
+ // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ assert(r == s1);
+ return 0;
+}
diff --git a/test/asan/TestCases/strpbrk_strict.c b/test/asan/TestCases/strpbrk_strict.c
new file mode 100644
index 000000000000..2521e96ba5f0
--- /dev/null
+++ b/test/asan/TestCases/strpbrk_strict.c
@@ -0,0 +1,25 @@
+// Test strict_string_checks option in strpbrk function
+// RUN: %clang_asan %s -o %t && %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ size_t size = 100;
+ char fill = 'o';
+ char *s1 = (char*)malloc(size);
+ char *s2 = (char*)malloc(2);
+ memset(s1, fill, size);
+ s2[0] = fill;
+ s2[1]='\0';
+ char* r = strpbrk(s1, s2);
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK: READ of size 101
+ assert(r == s1);
+ free(s1);
+ free(s2);
+ return 0;
+}
diff --git a/test/asan/TestCases/strspn-1.c b/test/asan/TestCases/strspn-1.c
new file mode 100644
index 000000000000..24d0d2daac1e
--- /dev/null
+++ b/test/asan/TestCases/strspn-1.c
@@ -0,0 +1,19 @@
+// Test string s1 overflow in strspn function
+// RUN: %clang_asan %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+// Test intercept_strspn asan option
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strspn=false %run %t 2>&1
+
+#include <assert.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ size_t r;
+ char s2[] = "ab";
+ char s1[] = {'a', 'c'};
+ char s3 = 0;
+ r = strspn(s1, s2);
+ // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ assert(r == 1);
+ return 0;
+}
diff --git a/test/asan/TestCases/strspn-2.c b/test/asan/TestCases/strspn-2.c
new file mode 100644
index 000000000000..e4621e5bfede
--- /dev/null
+++ b/test/asan/TestCases/strspn-2.c
@@ -0,0 +1,19 @@
+// Test stopset overflow in strspn function
+// RUN: %clang_asan %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+// Test intercept_strspn asan option
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strspn=false %run %t 2>&1
+
+#include <assert.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ size_t r;
+ char s1[] = "bbc";
+ char s2[] = {'a', 'b'};
+ char s3 = 0;
+ r = strspn(s1, s2);
+ // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ assert(r >= 2);
+ return 0;
+}
diff --git a/test/asan/TestCases/strspn_strict.c b/test/asan/TestCases/strspn_strict.c
new file mode 100644
index 000000000000..7df6c0da9ab0
--- /dev/null
+++ b/test/asan/TestCases/strspn_strict.c
@@ -0,0 +1,25 @@
+// Test strict_str`ing_checks option in strspn function
+// RUN: %clang_asan %s -o %t && %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ size_t size = 100;
+ char fill = 'o';
+ char *s1 = (char*)malloc(size);
+ char *s2 = (char*)malloc(2);
+ memset(s1, fill, size);
+ s1[0] = s2[0] = 'z';
+ s2[1] = '\0';
+ size_t r = strspn(s1, s2);
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK: READ of size 101
+ assert(r == 1);
+ free(s1);
+ free(s2);
+ return 0;
+}
diff --git a/test/asan/TestCases/strstr-1.c b/test/asan/TestCases/strstr-1.c
new file mode 100644
index 000000000000..193334e9bb34
--- /dev/null
+++ b/test/asan/TestCases/strstr-1.c
@@ -0,0 +1,20 @@
+// Test haystack overflow in strstr function
+// RUN: %clang_asan %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+// Test intercept_strstr asan option
+// Disable other interceptors because strlen may be called inside strstr
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strstr=false:replace_str=false %run %t 2>&1
+
+#include <assert.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ char *r = 0;
+ char s2[] = "c";
+ char s1[] = {'a', 'c'};
+ char s3 = 0;
+ r = strstr(s1, s2);
+ // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ assert(r == s1 + 1);
+ return 0;
+}
diff --git a/test/asan/TestCases/strstr-2.c b/test/asan/TestCases/strstr-2.c
new file mode 100644
index 000000000000..cd116212fa95
--- /dev/null
+++ b/test/asan/TestCases/strstr-2.c
@@ -0,0 +1,20 @@
+// Test needle overflow in strstr function
+// RUN: %clang_asan %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+// Test intercept_strstr asan option
+// Disable other interceptors because strlen may be called inside strstr
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strstr=false:replace_str=false %run %t 2>&1
+
+#include <assert.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ char *r = 0;
+ char s1[] = "ab";
+ char s2[] = {'c'};
+ char s3 = 0;
+ r = strstr(s1, s2);
+ // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
+ assert(r == 0);
+ return 0;
+}
diff --git a/test/asan/TestCases/strstr_strict.c b/test/asan/TestCases/strstr_strict.c
new file mode 100644
index 000000000000..f7eca6aeb900
--- /dev/null
+++ b/test/asan/TestCases/strstr_strict.c
@@ -0,0 +1,25 @@
+// Test strict_string_checks option in strstr function
+// RUN: %clang_asan %s -o %t && %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ size_t size = 100;
+ char fill = 'o';
+ char *s1 = (char*)malloc(size);
+ char *s2 = (char*)malloc(size);
+ memset(s1, fill, size);
+ memset(s2, fill, size);
+ s2[size - 1]='\0';
+ char* r = strstr(s1, s2);
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK: READ of size 101
+ assert(r == s1);
+ free(s1);
+ free(s2);
+ return 0;
+}
diff --git a/test/asan/TestCases/strtol_strict.c b/test/asan/TestCases/strtol_strict.c
new file mode 100644
index 000000000000..fac3b3a5439d
--- /dev/null
+++ b/test/asan/TestCases/strtol_strict.c
@@ -0,0 +1,116 @@
+// Test strict_string_checks option in strtol function
+// RUN: %clang_asan -DTEST1 %s -o %t
+// RUN: %run %t test1 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test1 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %run %t test2 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test2 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %run %t test3 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test3 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
+// RUN: %run %t test4 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test4 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test4 2>&1 | FileCheck %s --check-prefix=CHECK4
+// RUN: %run %t test5 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test5 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test5 2>&1 | FileCheck %s --check-prefix=CHECK5
+// RUN: %run %t test6 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test6 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test6 2>&1 | FileCheck %s --check-prefix=CHECK6
+// RUN: %run %t test7 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test7 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test7 2>&1 | FileCheck %s --check-prefix=CHECK7
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sanitizer/asan_interface.h>
+
+void test1(char *array, char *endptr) {
+ // Buffer overflow if there is no terminating null (depends on base)
+ long r = strtol(array, &endptr, 3);
+ assert(array + 2 == endptr);
+ assert(r == 5);
+}
+
+void test2(char *array, char *endptr) {
+ // Buffer overflow if there is no terminating null (depends on base)
+ array[2] = 'z';
+ long r = strtol(array, &endptr, 35);
+ assert(array + 2 == endptr);
+ assert(r == 37);
+}
+
+void test3(char *array, char *endptr) {
+ // Buffer overflow if base is invalid.
+ memset(array, 0, 8);
+ ASAN_POISON_MEMORY_REGION(array, 8);
+ long r = strtol(array + 1, NULL, -1);
+ assert(r == 0);
+ ASAN_UNPOISON_MEMORY_REGION(array, 8);
+}
+
+void test4(char *array, char *endptr) {
+ // Buffer overflow if base is invalid.
+ long r = strtol(array + 3, NULL, 1);
+ assert(r == 0);
+}
+
+void test5(char *array, char *endptr) {
+ // Overflow if no digits are found.
+ array[0] = ' ';
+ array[1] = '+';
+ array[2] = '-';
+ long r = strtol(array, NULL, 0);
+ assert(r == 0);
+}
+
+void test6(char *array, char *endptr) {
+ // Overflow if no digits are found.
+ array[0] = ' ';
+ array[1] = array[2] = 'z';
+ long r = strtol(array, &endptr, 0);
+ assert(array == endptr);
+ assert(r == 0);
+}
+
+void test7(char *array, char *endptr) {
+ // Overflow if no digits are found.
+ array[2] = 'z';
+ long r = strtol(array + 2, NULL, 0);
+ assert(r == 0);
+}
+
+int main(int argc, char **argv) {
+ char *array0 = (char*)malloc(11);
+ char* array = array0 + 8;
+ char *endptr = NULL;
+ array[0] = '1';
+ array[1] = '2';
+ array[2] = '3';
+ if (argc != 2) return 1;
+ if (!strcmp(argv[1], "test1")) test1(array, endptr);
+ // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK1: READ of size 4
+ if (!strcmp(argv[1], "test2")) test2(array, endptr);
+ // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK2: READ of size 4
+ if (!strcmp(argv[1], "test3")) test3(array0, endptr);
+ // CHECK3: {{.*ERROR: AddressSanitizer: use-after-poison on address}}
+ // CHECK3: READ of size 1
+ if (!strcmp(argv[1], "test4")) test4(array, endptr);
+ // CHECK4: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK4: READ of size 1
+ if (!strcmp(argv[1], "test5")) test5(array, endptr);
+ // CHECK5: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK5: READ of size 4
+ if (!strcmp(argv[1], "test6")) test6(array, endptr);
+ // CHECK6: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK6: READ of size 4
+ if (!strcmp(argv[1], "test7")) test7(array, endptr);
+ // CHECK7: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK7: READ of size 2
+ free(array0);
+ return 0;
+}
diff --git a/test/asan/TestCases/strtoll_strict.c b/test/asan/TestCases/strtoll_strict.c
new file mode 100644
index 000000000000..983da9f7ed30
--- /dev/null
+++ b/test/asan/TestCases/strtoll_strict.c
@@ -0,0 +1,116 @@
+// Test strict_string_checks option in strtoll function
+// RUN: %clang_asan -DTEST1 %s -o %t
+// RUN: %run %t test1 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test1 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %run %t test2 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test2 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %run %t test3 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test3 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
+// RUN: %run %t test4 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test4 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test4 2>&1 | FileCheck %s --check-prefix=CHECK4
+// RUN: %run %t test5 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test5 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test5 2>&1 | FileCheck %s --check-prefix=CHECK5
+// RUN: %run %t test6 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test6 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test6 2>&1 | FileCheck %s --check-prefix=CHECK6
+// RUN: %run %t test7 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test7 2>&1
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test7 2>&1 | FileCheck %s --check-prefix=CHECK7
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sanitizer/asan_interface.h>
+
+void test1(char *array, char *endptr) {
+ // Buffer overflow if there is no terminating null (depends on base)
+ long long r = strtoll(array, &endptr, 3);
+ assert(array + 2 == endptr);
+ assert(r == 5);
+}
+
+void test2(char *array, char *endptr) {
+ // Buffer overflow if there is no terminating null (depends on base)
+ array[2] = 'z';
+ long long r = strtoll(array, &endptr, 35);
+ assert(array + 2 == endptr);
+ assert(r == 37);
+}
+
+void test3(char *array, char *endptr) {
+ // Buffer overflow if base is invalid.
+ memset(array, 0, 8);
+ ASAN_POISON_MEMORY_REGION(array, 8);
+ long long r = strtoll(array + 1, NULL, -1);
+ assert(r == 0);
+ ASAN_UNPOISON_MEMORY_REGION(array, 8);
+}
+
+void test4(char *array, char *endptr) {
+ // Buffer overflow if base is invalid.
+ long long r = strtoll(array + 3, NULL, 1);
+ assert(r == 0);
+}
+
+void test5(char *array, char *endptr) {
+ // Overflow if no digits are found.
+ array[0] = ' ';
+ array[1] = '+';
+ array[2] = '-';
+ long long r = strtoll(array, NULL, 0);
+ assert(r == 0);
+}
+
+void test6(char *array, char *endptr) {
+ // Overflow if no digits are found.
+ array[0] = ' ';
+ array[1] = array[2] = 'z';
+ long long r = strtoll(array, &endptr, 0);
+ assert(array == endptr);
+ assert(r == 0);
+}
+
+void test7(char *array, char *endptr) {
+ // Overflow if no digits are found.
+ array[2] = 'z';
+ long long r = strtoll(array + 2, NULL, 0);
+ assert(r == 0);
+}
+
+int main(int argc, char **argv) {
+ char *array0 = (char*)malloc(11);
+ char* array = array0 + 8;
+ char *endptr = NULL;
+ array[0] = '1';
+ array[1] = '2';
+ array[2] = '3';
+ if (argc != 2) return 1;
+ if (!strcmp(argv[1], "test1")) test1(array, endptr);
+ // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK1: READ of size 4
+ if (!strcmp(argv[1], "test2")) test2(array, endptr);
+ // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK2: READ of size 4
+ if (!strcmp(argv[1], "test3")) test3(array0, endptr);
+ // CHECK3: {{.*ERROR: AddressSanitizer: use-after-poison on address}}
+ // CHECK3: READ of size 1
+ if (!strcmp(argv[1], "test4")) test4(array, endptr);
+ // CHECK4: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK4: READ of size 1
+ if (!strcmp(argv[1], "test5")) test5(array, endptr);
+ // CHECK5: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK5: READ of size 4
+ if (!strcmp(argv[1], "test6")) test6(array, endptr);
+ // CHECK6: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK6: READ of size 4
+ if (!strcmp(argv[1], "test7")) test7(array, endptr);
+ // CHECK7: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+ // CHECK7: READ of size 2
+ free(array0);
+ return 0;
+}
diff --git a/test/asan/TestCases/suppressions-exec-relative-location.cc b/test/asan/TestCases/suppressions-exec-relative-location.cc
new file mode 100644
index 000000000000..84f0262dc0bc
--- /dev/null
+++ b/test/asan/TestCases/suppressions-exec-relative-location.cc
@@ -0,0 +1,47 @@
+// Check that without suppressions, we catch the issue.
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
+
+// If the executable is started from a different location, we should still
+// find the suppression file located relative to the location of the executable.
+// RUN: rm -rf %T/suppressions-exec-relative-location
+// RUN: mkdir -p %T/suppressions-exec-relative-location
+// RUN: %clangxx_asan -O0 %s -o %T/suppressions-exec-relative-location/exec
+// RUN: echo "interceptor_via_fun:crash_function" > \
+// RUN: %T/suppressions-exec-relative-location/supp.txt
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions=supp.txt" \
+// RUN: %run %T/suppressions-exec-relative-location/exec 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: rm -rf %T/suppressions-exec-relative-location
+
+// If the wrong absolute path is given, we don't try to construct
+// a relative path with it.
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='/absolute/path'" not %run %t 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-WRONG-FILE-NAME %s
+
+// Test that we reject directory as filename.
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='folder/only/'" not %run %t 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-WRONG-FILE-NAME %s
+
+// XFAIL: android
+// XFAIL: win32
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void crash_function() {
+ char *a = (char *)malloc(6);
+ free(a);
+ size_t len = strlen(a); // BOOM
+ fprintf(stderr, "strlen ignored, len = %zu\n", len);
+}
+
+int main() {
+ crash_function();
+}
+
+// CHECK-CRASH: AddressSanitizer: heap-use-after-free
+// CHECK-IGNORE-NOT: AddressSanitizer: heap-buffer-overflow
+// CHECK-IGNORE: ignored
+// CHECK-WRONG-FILE-NAME: failed to read suppressions file
diff --git a/test/asan/TestCases/suppressions-function.cc b/test/asan/TestCases/suppressions-function.cc
index 0a6c9995827e..fe5419f17938 100644
--- a/test/asan/TestCases/suppressions-function.cc
+++ b/test/asan/TestCases/suppressions-function.cc
@@ -3,8 +3,8 @@
// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
// RUN: echo "interceptor_via_fun:crash_function" > %t.supp
-// RUN: %clangxx_asan -O0 %s -o %t && ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
-// RUN: %clangxx_asan -O3 %s -o %t && ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: %clangxx_asan -O0 %s -o %t && ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: %clangxx_asan -O3 %s -o %t && ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
// XFAIL: android
diff --git a/test/asan/TestCases/suppressions-interceptor.cc b/test/asan/TestCases/suppressions-interceptor.cc
index 45a14d1a422a..8bb1f1a92d3b 100644
--- a/test/asan/TestCases/suppressions-interceptor.cc
+++ b/test/asan/TestCases/suppressions-interceptor.cc
@@ -3,7 +3,7 @@
// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
// RUN: echo "interceptor_name:strlen" > %t.supp
-// RUN: ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
// XFAIL: android
diff --git a/test/asan/TestCases/suppressions-library.cc b/test/asan/TestCases/suppressions-library.cc
index 28f19f54efc1..52fd60910539 100644
--- a/test/asan/TestCases/suppressions-library.cc
+++ b/test/asan/TestCases/suppressions-library.cc
@@ -1,11 +1,11 @@
-// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so -install_name @rpath/suppressions-library.cc.tmp-so.so
-// RUN: %clangxx_asan -O0 %s %t-so.so -o %t -rpath @executable_path
+// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
+// RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe
// Check that without suppressions, we catch the issue.
// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
-// RUN: echo "interceptor_via_lib:suppressions-library.cc.tmp-so.so" > %t.supp
-// RUN: ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: echo "interceptor_via_lib:"`basename %dynamiclib` > %t.supp
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
// XFAIL: android
diff --git a/test/asan/TestCases/uar_and_exceptions.cc b/test/asan/TestCases/uar_and_exceptions.cc
index 0bfe29729555..bdeca434e6c2 100644
--- a/test/asan/TestCases/uar_and_exceptions.cc
+++ b/test/asan/TestCases/uar_and_exceptions.cc
@@ -1,5 +1,5 @@
// Test that use-after-return works with exceptions.
-// export ASAN_OPTIONS=detect_stack_use_after_return=1
+// export ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1
// RUN: %clangxx_asan -O0 %s -o %t && %run %t
// Clang doesn't support exceptions on Windows yet.
diff --git a/test/asan/TestCases/use-after-poison.cc b/test/asan/TestCases/use-after-poison.cc
index 3b247ff531b9..ecca2c85028f 100644
--- a/test/asan/TestCases/use-after-poison.cc
+++ b/test/asan/TestCases/use-after-poison.cc
@@ -2,7 +2,7 @@
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
//
// Check that we can disable it
-// RUN: env ASAN_OPTIONS=allow_user_poisoning=0 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:allow_user_poisoning=0 %run %t
#include <stdlib.h>
diff --git a/test/asan/TestCases/use-after-scope.cc b/test/asan/TestCases/use-after-scope.cc
index f98a8e6b62e1..e244ee34b101 100644
--- a/test/asan/TestCases/use-after-scope.cc
+++ b/test/asan/TestCases/use-after-scope.cc
@@ -1,6 +1,6 @@
// RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \
// RUN: not %run %t 2>&1 | FileCheck %s
-// RUN: env ASAN_OPTIONS="detect_stack_use_after_return=1" not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:detect_stack_use_after_return=1" not %run %t 2>&1 | FileCheck %s
// XFAIL: *
int main() {
diff --git a/test/asan/TestCases/verbose-log-path_test.cc b/test/asan/TestCases/verbose-log-path_test.cc
new file mode 100644
index 000000000000..12372ec68078
--- /dev/null
+++ b/test/asan/TestCases/verbose-log-path_test.cc
@@ -0,0 +1,21 @@
+// RUN: %clangxx_asan %s -o %T/verbose-log-path_test-binary
+
+// Good log_path.
+// RUN: rm -f %T/asan.log.*
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:log_path=%T/asan.log:log_exe_name=1 not %run %T/verbose-log-path_test-binary 2> %t.out
+// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %T/asan.log.verbose-log-path_test-binary.*
+
+// FIXME: only FreeBSD and Linux have verbose log paths now.
+// XFAIL: win32,android
+
+#include <stdlib.h>
+#include <string.h>
+int main(int argc, char **argv) {
+ if (argc > 2) return 0;
+ char *x = (char*)malloc(10);
+ memset(x, 0, 10);
+ int res = x[argc * 10]; // BOOOM
+ free(x);
+ return res;
+}
+// CHECK-ERROR: ERROR: AddressSanitizer
diff --git a/test/asan/TestCases/vla_chrome_testcase.cc b/test/asan/TestCases/vla_chrome_testcase.cc
new file mode 100644
index 000000000000..8ee040120c48
--- /dev/null
+++ b/test/asan/TestCases/vla_chrome_testcase.cc
@@ -0,0 +1,30 @@
+// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+//
+
+// This is reduced testcase based on Chromium code.
+// See http://reviews.llvm.org/D6055?vs=on&id=15616&whitespace=ignore-all#toc.
+
+#include <stdint.h>
+#include <assert.h>
+
+int a = 7;
+int b;
+int c;
+int *p;
+
+__attribute__((noinline)) void fn3(int *first, int second) {
+}
+
+int main() {
+ int d = b && c;
+ int e[a]; // NOLINT
+ assert(!(reinterpret_cast<uintptr_t>(e) & 31L));
+ int f;
+ if (d)
+ fn3(&f, sizeof 0 * (&c - e));
+ e[a] = 0;
+// CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 4 at [[ADDR]] thread T0
+ return 0;
+}
diff --git a/test/asan/TestCases/vla_condition_overflow.cc b/test/asan/TestCases/vla_condition_overflow.cc
new file mode 100644
index 000000000000..17f28d823252
--- /dev/null
+++ b/test/asan/TestCases/vla_condition_overflow.cc
@@ -0,0 +1,22 @@
+// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+//
+// REQUIRES: stable-runtime
+
+#include <assert.h>
+#include <stdint.h>
+
+__attribute__((noinline)) void foo(int index, int len) {
+ if (index > len) {
+ char str[len]; //NOLINT
+ assert(!(reinterpret_cast<uintptr_t>(str) & 31L));
+ str[index] = '1'; // BOOM
+// CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T0
+ }
+}
+
+int main(int argc, char **argv) {
+ foo(33, 10);
+ return 0;
+}
diff --git a/test/asan/TestCases/vla_loop_overfow.cc b/test/asan/TestCases/vla_loop_overfow.cc
new file mode 100644
index 000000000000..4f20c8d19d14
--- /dev/null
+++ b/test/asan/TestCases/vla_loop_overfow.cc
@@ -0,0 +1,22 @@
+// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+//
+// REQUIRES: stable-runtime
+
+#include <assert.h>
+#include <stdint.h>
+
+void foo(int index, int len) {
+ for (int i = 1; i < len; ++i) {
+ char array[len]; // NOLINT
+ assert(!(reinterpret_cast<uintptr_t>(array) & 31L));
+ array[index + i] = 0;
+// CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T0
+ }
+}
+
+int main(int argc, char **argv) {
+ foo(9, 21);
+ return 0;
+}
diff --git a/test/asan/lit.cfg b/test/asan/lit.cfg
index a6f443cfb6a5..c5164713dbe4 100644
--- a/test/asan/lit.cfg
+++ b/test/asan/lit.cfg
@@ -29,6 +29,9 @@ def push_dynamic_library_lookup_path(config, new_path):
# Setup config name.
config.name = 'AddressSanitizer' + config.name_suffix
+# Setup default ASAN_OPTIONS
+config.environment['ASAN_OPTIONS'] = 'symbolize_vs_style=false'
+
# testFormat: The test format to use to interpret tests.
external_bash = (not sys.platform in ['win32'])
config.test_format = lit.formats.ShTest(external_bash)
@@ -135,6 +138,20 @@ config.substitutions.append( ("%libdl", libdl_flag) )
config.available_features.add("asan-" + config.bits + "-bits")
+if config.host_os == 'Darwin':
+ config.substitutions.append( ("%ld_flags_rpath_exe", '-Wl,-rpath,@executable_path/ %dynamiclib') )
+ config.substitutions.append( ("%ld_flags_rpath_so", '-install_name @rpath/`basename %dynamiclib`') )
+elif config.host_os == 'FreeBSD':
+ config.substitutions.append( ("%ld_flags_rpath_exe", "-Wl,-z,origin -Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec") )
+ config.substitutions.append( ("%ld_flags_rpath_so", '') )
+elif config.host_os == 'Linux':
+ config.substitutions.append( ("%ld_flags_rpath_exe", "-Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec") )
+ config.substitutions.append( ("%ld_flags_rpath_so", '') )
+
+# Must be defined after the substitutions that use %dynamiclib.
+config.substitutions.append( ("%dynamiclib", '%T/lib%xdynamiclib_namespec.so') )
+config.substitutions.append( ("%xdynamiclib_namespec", '$(basename %t).dynamic') )
+
# Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL
# because the test hangs.
if config.target_arch != 'arm':