diff options
Diffstat (limited to 'test/asan/TestCases')
188 files changed, 1525 insertions, 519 deletions
diff --git a/test/asan/TestCases/Android/coverage-android.cc b/test/asan/TestCases/Android/coverage-android.cc index 5f2631605595..16a6e1f7e160 100644 --- a/test/asan/TestCases/Android/coverage-android.cc +++ b/test/asan/TestCases/Android/coverage-android.cc @@ -9,7 +9,7 @@ // RUN: adb shell mkdir -p %device/coverage-android/direct // RUN: mkdir -p %T/coverage-android/direct -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t +// RUN: %env_asan_opts=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 @@ -26,7 +26,7 @@ // RUN: adb shell mkdir -p %device/coverage-android-kill/direct // RUN: mkdir -p %T/coverage-android-kill/direct -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t +// RUN: %env_asan_opts=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 @@ -43,7 +43,7 @@ // RUN: adb shell mkdir -p %device/coverage-android/direct // RUN: mkdir -p %T/coverage-android/direct -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t +// RUN: %env_asan_opts=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 @@ -60,7 +60,7 @@ // RUN: adb shell mkdir -p %device/coverage-android-kill/direct // RUN: mkdir -p %T/coverage-android-kill/direct -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t +// RUN: %env_asan_opts=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 @@ -77,7 +77,7 @@ // RUN: adb shell mkdir -p %device/coverage-android/direct // RUN: mkdir -p %T/coverage-android/direct -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t +// RUN: %env_asan_opts=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 @@ -94,7 +94,7 @@ // RUN: adb shell mkdir -p %device/coverage-android-kill/direct // RUN: mkdir -p %T/coverage-android-kill/direct -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t +// RUN: %env_asan_opts=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/abort_on_error.cc b/test/asan/TestCases/Darwin/abort_on_error.cc new file mode 100644 index 000000000000..f09718bda06e --- /dev/null +++ b/test/asan/TestCases/Darwin/abort_on_error.cc @@ -0,0 +1,17 @@ +// Check that with empty ASAN_OPTIONS, ASan reports on OS X actually crash +// the process (abort_on_error=1). See also Linux/abort_on_error.cc. + +// RUN: %clangxx_asan %s -o %t + +// Intentionally don't inherit the default ASAN_OPTIONS. +// RUN: ASAN_OPTIONS="" not --crash %run %t 2>&1 | FileCheck %s +// When we use lit's default ASAN_OPTIONS, we shouldn't crash. +// RUN: not %run %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}} +} diff --git a/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cc b/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cc index f6070188d8e5..4595fb547f57 100644 --- a/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cc +++ b/test/asan/TestCases/Darwin/atos-symbolizer-dyld-root-path.cc @@ -1,9 +1,10 @@ // 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: %clangxx_asan -O0 %s -o %t +// RUN: %env_asan_opts=verbosity=2 DYLD_ROOT_PATH="/" 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 +// REQUIRES: asan-64-bits #include <stdlib.h> #include <string.h> @@ -16,11 +17,11 @@ int main(int argc, char **argv) { // 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: #1 0x{{.*}} in main {{.*}}atos-symbolizer-dyld-root-path.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: #1 0x{{.*}} in main {{.*}}atos-symbolizer-dyld-root-path.cc:[[@LINE-8]] // CHECK: allocated by thread T0 here: - // CHECK: atos-symbolizer.cc:[[@LINE-13]] + // CHECK: atos-symbolizer-dyld-root-path.cc:[[@LINE-13]] return res; } diff --git a/test/asan/TestCases/Darwin/atos-symbolizer.cc b/test/asan/TestCases/Darwin/atos-symbolizer.cc index 03cadf92d16a..2a9ffbc5b25c 100644 --- a/test/asan/TestCases/Darwin/atos-symbolizer.cc +++ b/test/asan/TestCases/Darwin/atos-symbolizer.cc @@ -1,7 +1,7 @@ // 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 +// RUN: %clangxx_asan -O0 %s -o %t +// RUN: %env_asan_opts=verbosity=2 ASAN_SYMBOLIZER_PATH=$(which atos) not %run %t 2>&1 | FileCheck %s #include <stdlib.h> #include <string.h> diff --git a/test/asan/TestCases/Darwin/crashlog-stacktraces.c b/test/asan/TestCases/Darwin/crashlog-stacktraces.c index e9af5396e1c3..915161481987 100644 --- a/test/asan/TestCases/Darwin/crashlog-stacktraces.c +++ b/test/asan/TestCases/Darwin/crashlog-stacktraces.c @@ -1,6 +1,11 @@ // RUN: %clang_asan -O0 %s -o %t // RUN: not %run %t 2>&1 | FileCheck %s +// Since ASan is built with -fomit-frame-pointer, backtrace is not able to +// symbolicate the trace past ASan runtime on i386. (This is fixed in +// latest OS X.) +// REQUIRES: asan-64-bits + #include <execinfo.h> #include <sanitizer/common_interface_defs.h> #include <stdio.h> diff --git a/test/asan/TestCases/Darwin/dladdr-demangling.cc b/test/asan/TestCases/Darwin/dladdr-demangling.cc index 3d36c4f96355..d773659b74f8 100644 --- a/test/asan/TestCases/Darwin/dladdr-demangling.cc +++ b/test/asan/TestCases/Darwin/dladdr-demangling.cc @@ -1,9 +1,9 @@ // 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: %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 +// RUN: %env_asan_opts=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> diff --git a/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc b/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc index 486223473d47..b22036a7efed 100644 --- a/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc +++ b/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc @@ -8,22 +8,23 @@ // 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: 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: %env_asan_opts=verbosity=1 \ +// RUN: DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib \ +// RUN: %run %T/dyld_insert_libraries_reexec/a.out 2>&1 \ // RUN: | FileCheck %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: %env_asan_opts=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: %env_asan_opts=verbosity=1 %run %T/dyld_insert_libraries_reexec/a.out 2>&1 \ // RUN: | FileCheck %s; \ // RUN: fi @@ -36,10 +37,10 @@ int main() { // CHECK-NOINSERT: exec()-ing the program with // CHECK-NOINSERT: DYLD_INSERT_LIBRARIES -// CHECK-NOINSERT: to enable ASan wrappers. +// CHECK-NOINSERT: to enable wrappers. // CHECK-NOINSERT: Passed // CHECK-NOT: exec()-ing the program with // CHECK-NOT: DYLD_INSERT_LIBRARIES -// CHECK-NOT: to enable ASan wrappers. +// CHECK-NOT: to enable wrappers. // CHECK: Passed diff --git a/test/asan/TestCases/Darwin/interface_symbols_darwin.c b/test/asan/TestCases/Darwin/interface_symbols_darwin.c index bd9bbee84a92..ed5779ebe220 100644 --- a/test/asan/TestCases/Darwin/interface_symbols_darwin.c +++ b/test/asan/TestCases/Darwin/interface_symbols_darwin.c @@ -8,7 +8,7 @@ // RUN: nm -g `%clang_asan %s -fsanitize=address -### 2>&1 | grep "libclang_rt.asan_osx_dynamic.dylib" | sed -e 's/.*"\(.*libclang_rt.asan_osx_dynamic.dylib\)".*/\1/'` \ // RUN: | grep " T " | sed "s/.* T //" \ // RUN: | grep "__asan_" | sed "s/___asan_/__asan_/" \ -// RUN: | sed -E "s/__asan_init_v[0-9]+/__asan_init/" \ +// RUN: | sed -E "s/__asan_version_mismatch_check_v[0-9]+/__asan_version_mismatch_check/" \ // RUN: | grep -v "__asan_default_options" \ // RUN: | grep -v "__asan_on_error" > %t.symbols @@ -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_load1_noabort >> %t.interface +// RUN: echo __asan_report_load2_noabort >> %t.interface +// RUN: echo __asan_report_load4_noabort >> %t.interface +// RUN: echo __asan_report_load8_noabort >> %t.interface +// RUN: echo __asan_report_load16_noabort >> %t.interface +// RUN: echo __asan_report_store1_noabort >> %t.interface +// RUN: echo __asan_report_store2_noabort >> %t.interface +// RUN: echo __asan_report_store4_noabort >> %t.interface +// RUN: echo __asan_report_store8_noabort >> %t.interface +// RUN: echo __asan_report_store16_noabort >> %t.interface +// RUN: echo __asan_report_load_n_noabort >> %t.interface +// RUN: echo __asan_report_store_n_noabort >> %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 @@ -43,14 +55,6 @@ // 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 -// RUN: echo __asan_mz_destroy >> %t.interface -// RUN: echo __asan_mz_free >> %t.interface -// RUN: echo __asan_mz_malloc >> %t.interface -// RUN: echo __asan_mz_memalign >> %t.interface -// RUN: echo __asan_mz_realloc >> %t.interface -// RUN: echo __asan_mz_size >> %t.interface -// RUN: echo __asan_mz_valloc >> %t.interface // RUN: for i in `jot - 0 10`; do echo __asan_stack_malloc_$i >> %t.interface; done // RUN: for i in `jot - 0 10`; do echo __asan_stack_free_$i >> %t.interface; done diff --git a/test/asan/TestCases/Darwin/suppressions-darwin.cc b/test/asan/TestCases/Darwin/suppressions-darwin.cc index 488bff140225..403d819706a9 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: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s +// RUN: %env_asan_opts=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: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp':symbolize=false" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s +// RUN: %env_asan_opts=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: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s +// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s // Check that suppressing library works even without the symbolizer. -// RUN: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp':symbolize=false" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s +// RUN: %env_asan_opts=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 index 47d80f80db2b..ddbad466f7bf 100644 --- a/test/asan/TestCases/Darwin/suppressions-sandbox.cc +++ b/test/asan/TestCases/Darwin/suppressions-sandbox.cc @@ -4,7 +4,7 @@ // 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: %env_asan_opts=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 diff --git a/test/asan/TestCases/Helpers/init-order-pthread-create-extra.cc b/test/asan/TestCases/Helpers/init-order-pthread-create-extra.cc deleted file mode 100644 index 54f26f16724c..000000000000 --- a/test/asan/TestCases/Helpers/init-order-pthread-create-extra.cc +++ /dev/null @@ -1,2 +0,0 @@ -void *bar(void *input, bool sleep_before_init); -void *glob2 = bar((void*)0x2345, true); diff --git a/test/asan/TestCases/Linux/abort_on_error.cc b/test/asan/TestCases/Linux/abort_on_error.cc new file mode 100644 index 000000000000..406d98b6764a --- /dev/null +++ b/test/asan/TestCases/Linux/abort_on_error.cc @@ -0,0 +1,18 @@ +// Check that with empty ASAN_OPTIONS, ASan reports on Linux don't crash +// the process (abort_on_error=0). See also Darwin/abort_on_error.cc. + +// RUN: %clangxx_asan %s -o %t + +// Intentionally don't inherit the default ASAN_OPTIONS. +// RUN: ASAN_OPTIONS="" not %run %t 2>&1 | FileCheck %s +// When we use lit's default ASAN_OPTIONS, we shouldn't crash either. On Linux +// lit doesn't set ASAN_OPTIONS anyway. +// RUN: not %run %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}} +} diff --git a/test/asan/TestCases/Linux/activation-options.cc b/test/asan/TestCases/Linux/activation-options.cc new file mode 100644 index 000000000000..1a1ad3f8c499 --- /dev/null +++ b/test/asan/TestCases/Linux/activation-options.cc @@ -0,0 +1,71 @@ +// Test for ASAN_OPTIONS=start_deactivated=1 mode. +// Main executable is uninstrumented, but linked to ASan runtime. The shared +// library is instrumented. + +// 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: rm -f %t.asan.options.activation-options.cc.tmp +// RUN: rm -f %t.asan.options.ABCDE +// RUN: echo "help=1" >%t.asan.options.activation-options.cc.tmp + +// RUN: %env_asan_opts=start_deactivated=1 \ +// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND + +// RUN: %env_asan_opts=start_deactivated=1 \ +// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options not %run %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING + +// RUN: %env_asan_opts=start_deactivated=1 \ +// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b not %run %t --fix-name 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING + +// RUN: echo "help=1" >%t.asan.options.ABCDE + +// RUN: %env_asan_opts=start_deactivated=1 \ +// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t --fix-name 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND + +// XFAIL: arm-linux-gnueabi +// XFAIL: android + +#if !defined(SHARED_LIB) +#include <assert.h> +#include <dlfcn.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <string> + +#include "sanitizer/asan_interface.h" + +typedef void (*Fn)(); + +int main(int argc, char *argv[]) { + std::string path = std::string(argv[0]) + "-so.so"; + + if (argc > 1 && strcmp(argv[1], "--fix-name") == 0) { + assert(strlen(argv[0]) > 5); + strcpy(argv[0], "ABCDE"); + } + + void *dso = dlopen(path.c_str(), RTLD_NOW); + if (!dso) { + fprintf(stderr, "dlopen failed: %s\n", dlerror()); + return 1; + } + + return 0; +} +#else // SHARED_LIB +// Empty: all we need is an ASan shared library constructor. +#endif // SHARED_LIB + +// CHECK-HELP: Available flags for {{.*}}Sanitizer: +// CHECK-NO-HELP-NOT: Available flags for {{.*}}Sanitizer: +// CHECK-FOUND-NOT: Failed to read options +// CHECK-MISSING: Failed to read options diff --git a/test/asan/TestCases/Linux/asan_prelink_test.cc b/test/asan/TestCases/Linux/asan_prelink_test.cc index 9e58f83d40c6..d67d945851f9 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: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1 %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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/calloc-preload.c b/test/asan/TestCases/Linux/calloc-preload.c new file mode 100644 index 000000000000..eb1c6738b6e9 --- /dev/null +++ b/test/asan/TestCases/Linux/calloc-preload.c @@ -0,0 +1,36 @@ +// Test that initially callocked memory is properly freed +// (see https://github.com/google/sanitizers/issues/626). +// +// RUN: %clang %s -o %t +// RUN: env LD_PRELOAD=%shared_libasan %run %t +// +// REQUIRES: asan-dynamic-runtime +// +// This way of setting LD_PRELOAD does not work with Android test runner. +// REQUIRES: not-android + +#include <stdio.h> +#include <stdlib.h> + +static void *ptr; + +// This constructor will run before __asan_init +// so calloc will allocate memory from special pool. +static void init() { + ptr = calloc(10, 1); +} + +__attribute__((section(".preinit_array"), used)) +void *dummy = init; + +void free_memory() { + // This used to abort because + // Asan's free didn't recognize ptr. + free(ptr); +} + +int main() { + free_memory(); + return 0; +} + diff --git a/test/asan/TestCases/Linux/coverage-missing.cc b/test/asan/TestCases/Linux/coverage-missing.cc index 36f33b505e27..6cd3201c48d1 100644 --- a/test/asan/TestCases/Linux/coverage-missing.cc +++ b/test/asan/TestCases/Linux/coverage-missing.cc @@ -1,21 +1,19 @@ // 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: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %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: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %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: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %t x x // RUN: %sancov print *.sancov > bar.txt // RUN: rm *.sancov // RUN: [ $(cat bar.txt | wc -l) == 4 ] @@ -34,11 +32,11 @@ // 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: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %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: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %t x x // RUN: %sancov print $LIBNAME.*.sancov > bar.txt // RUN: rm *.sancov // RUN: [ $(cat bar.txt | wc -l) == 3 ] diff --git a/test/asan/TestCases/Linux/init-order-dlopen.cc b/test/asan/TestCases/Linux/init-order-dlopen.cc index fcfb5d143df6..d469b98089fe 100644 --- a/test/asan/TestCases/Linux/init-order-dlopen.cc +++ b/test/asan/TestCases/Linux/init-order-dlopen.cc @@ -3,7 +3,7 @@ // 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 +// RUN: %env_asan_opts=strict_init_order=true %run %t 2>&1 // dlopen() can not be intercepted on Android, making strict_init_order nearly // useless there. diff --git a/test/asan/TestCases/Linux/init_fini_sections.cc b/test/asan/TestCases/Linux/init_fini_sections.cc new file mode 100644 index 000000000000..c7234eeeac2c --- /dev/null +++ b/test/asan/TestCases/Linux/init_fini_sections.cc @@ -0,0 +1,24 @@ +// RUN: %clangxx_asan %s -o %t && %run %t | FileCheck %s + +#include <stdio.h> + +static void foo() { + printf("foo\n"); +} + +int main() { + return 0; +} + +__attribute__((section(".preinit_array"))) +void (*call_foo)(void) = &foo; + +__attribute__((section(".init_array"))) +void (*call_foo_2)(void) = &foo; + +__attribute__((section(".fini_array"))) +void (*call_foo_3)(void) = &foo; + +// CHECK: foo +// CHECK: foo +// CHECK: foo diff --git a/test/asan/TestCases/Linux/initialization-bug-any-order.cc b/test/asan/TestCases/Linux/initialization-bug-any-order.cc index 0f2fccae79bb..85fefd40ee03 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: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 9e876799d384..971feb5dc09f 100644 --- a/test/asan/TestCases/Linux/interface_symbols_linux.c +++ b/test/asan/TestCases/Linux/interface_symbols_linux.c @@ -3,7 +3,7 @@ // RUN: %clang_asan -O2 %s -o %t.exe // RUN: nm -D %t.exe | grep " T " | sed "s/.* T //" \ // RUN: | grep "__asan_" | sed "s/___asan_/__asan_/" \ -// RUN: | sed -E "s/__asan_init_v[0-9]+/__asan_init/" \ +// RUN: | sed -E "s/__asan_version_mismatch_check_v[0-9]+/__asan_version_mismatch_check/" \ // RUN: | grep -v "__asan_default_options" \ // RUN: | grep -v "__asan_stack_" \ // RUN: | grep -v "__asan_on_error" > %t.symbols @@ -24,6 +24,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_load1_noabort >> %t.interface +// RUN: echo __asan_report_load2_noabort >> %t.interface +// RUN: echo __asan_report_load4_noabort >> %t.interface +// RUN: echo __asan_report_load8_noabort >> %t.interface +// RUN: echo __asan_report_load16_noabort >> %t.interface +// RUN: echo __asan_report_store1_noabort >> %t.interface +// RUN: echo __asan_report_store2_noabort >> %t.interface +// RUN: echo __asan_report_store4_noabort >> %t.interface +// RUN: echo __asan_report_store8_noabort >> %t.interface +// RUN: echo __asan_report_store16_noabort >> %t.interface +// RUN: echo __asan_report_load_n_noabort >> %t.interface +// RUN: echo __asan_report_store_n_noabort >> %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 diff --git a/test/asan/TestCases/Linux/kernel-area.cc b/test/asan/TestCases/Linux/kernel-area.cc index 8d3f7d6f8e88..c0f17272ad27 100644 --- a/test/asan/TestCases/Linux/kernel-area.cc +++ b/test/asan/TestCases/Linux/kernel-area.cc @@ -4,9 +4,9 @@ // Test that kernel area is not sanitized on 32-bit machines. // // RUN: %clangxx_asan %s -o %t -// 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 +// RUN: %env_asan_opts=verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits +// RUN: %env_asan_opts=verbosity=1:full_address_space=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits +// RUN: %env_asan_opts=verbosity=1:full_address_space=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-kernel-64-bits // // CHECK-kernel-32-bits: || `[0x38{{0+}}, 0xb{{f+}}]` || HighMem || // CHECK-kernel-32-bits: || `[0x27{{0+}}, 0x37{{f+}}]` || HighShadow || diff --git a/test/asan/TestCases/Linux/leak.cc b/test/asan/TestCases/Linux/leak.cc index 15c03b45e4c9..e22cd6eac16f 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: 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 +// RUN: %env_asan_opts=detect_leaks=1 not %run %t 2>&1 | FileCheck %s +// RUN: not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=detect_leaks=0 %run %t #include <stdio.h> int *t; diff --git a/test/asan/TestCases/Linux/malloc-in-qsort.cc b/test/asan/TestCases/Linux/malloc-in-qsort.cc index f7c7c5fe3df7..e8c9b7480b76 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: 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 +// RUN: %env_asan_opts=fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST +// RUN: %env_asan_opts=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 33d0ede15f3c..66eed33052c3 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: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALLOC-STACK +// RUN: %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALLOC-STACK // No error here. -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=0 %run %t +// RUN: %env_asan_opts=alloc_dealloc_mismatch=0 %run %t // Also works if no malloc context is available. -// 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 +// RUN: %env_asan_opts=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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/mincore.cc b/test/asan/TestCases/Linux/mincore.cc new file mode 100644 index 000000000000..30f450830fc2 --- /dev/null +++ b/test/asan/TestCases/Linux/mincore.cc @@ -0,0 +1,34 @@ +// RUN: %clangxx_asan -std=c++11 -O0 %s -o %t && %run %t + +#include <assert.h> +#include <unistd.h> +#include <sys/mman.h> + +int main(void) { + unsigned char vec[20]; + int res; + size_t PS = sysconf(_SC_PAGESIZE); + void *addr = mmap(nullptr, 20 * PS, PROT_READ | PROT_WRITE, + MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + + res = mincore(addr, 10 * PS, vec); + assert(res == 0); + for (int i = 0; i < 10; ++i) + assert((vec[i] & 1) == 0); + + for (int i = 0; i < 5; ++i) + ((char *)addr)[i * PS] = 1; + res = mincore(addr, 10 * PS, vec); + assert(res == 0); + for (int i = 0; i < 10; ++i) + assert((vec[i] & 1) == (i < 5)); + + for (int i = 5; i < 10; ++i) + ((char *)addr)[i * PS] = 1; + res = mincore(addr, 10 * PS, vec); + assert(res == 0); + for (int i = 0; i < 10; ++i) + assert((vec[i] & 1) == 1); + + return 0; +} diff --git a/test/asan/TestCases/Linux/nohugepage_test.cc b/test/asan/TestCases/Linux/nohugepage_test.cc index aeb70c94ec99..2758f0ad04f5 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: env ASAN_OPTIONS=$ASAN_OPTIONS:no_huge_pages_for_shadow=1 %run %t 2>&1 | FileCheck %s -// RUN: %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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... diff --git a/test/asan/TestCases/Linux/odr-violation.cc b/test/asan/TestCases/Linux/odr-violation.cc index e9311d16bd5f..bc76116632ec 100644 --- a/test/asan/TestCases/Linux/odr-violation.cc +++ b/test/asan/TestCases/Linux/odr-violation.cc @@ -7,20 +7,20 @@ // 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: 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 +// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s +// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s +// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED +// RUN: %env_asan_opts=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: 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: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED +// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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: %env_asan_opts=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: %env_asan_opts=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. diff --git a/test/asan/TestCases/Linux/overflow-in-qsort.cc b/test/asan/TestCases/Linux/overflow-in-qsort.cc index 26fe67d60729..dc3918e876a6 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: 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 +// RUN: %env_asan_opts=fast_unwind_on_fatal=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST +// RUN: %env_asan_opts=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/pthread_create_version.cc b/test/asan/TestCases/Linux/pthread_create_version.cc new file mode 100644 index 000000000000..efdb8ca97c4f --- /dev/null +++ b/test/asan/TestCases/Linux/pthread_create_version.cc @@ -0,0 +1,23 @@ +// RUN: %clangxx_asan -std=c++11 -pthread %s -o %t && %run %t 2>&1 +// Regression test for the versioned pthread_create interceptor on linux/i386. +// pthread_attr_init is not intercepted and binds to the new abi +// pthread_create is intercepted; dlsym always returns the oldest version. +// This results in a crash inside pthread_create in libc. + +#include <pthread.h> +#include <stdlib.h> + +void *ThreadFunc(void *) { return nullptr; } + +int main() { + pthread_t t; + const size_t sz = 1024 * 1024; + void *p = malloc(sz); + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstack(&attr, p, sz); + pthread_create(&t, &attr, ThreadFunc, nullptr); + pthread_join(t, nullptr); + free(p); + return 0; +} diff --git a/test/asan/TestCases/Linux/ptrace.cc b/test/asan/TestCases/Linux/ptrace.cc index 6840ebe28bfd..d87d90be4753 100644 --- a/test/asan/TestCases/Linux/ptrace.cc +++ b/test/asan/TestCases/Linux/ptrace.cc @@ -1,9 +1,9 @@ // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 // XFAIL: android +// XFAIL: mips // // RUN: %clangxx_asan -O0 %s -o %t && %run %t // RUN: %clangxx_asan -DPOSITIVE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s -// REQUIRES: x86_64-supported-target,i386-supported-target #include <assert.h> #include <stdio.h> @@ -12,6 +12,55 @@ #include <sys/user.h> #include <sys/wait.h> #include <unistd.h> +#include <sys/uio.h> // for iovec +#include <elf.h> // for NT_PRSTATUS +#ifdef __aarch64__ +# include <asm/ptrace.h> +#endif + +#if defined(__i386__) || defined(__x86_64__) +typedef user_regs_struct regs_struct; +typedef user_fpregs_struct fpregs_struct; +#if defined(__i386__) +#define REG_IP eip +#else +#define REG_IP rip +#endif +#define PRINT_REG_PC(__regs) printf ("%lx\n", (unsigned long) (__regs.REG_IP)) +#define PRINT_REG_FP(__fpregs) printf ("%lx\n", (unsigned long) (__fpregs.cwd)) +#define __PTRACE_FPREQUEST PTRACE_GETFPREGS + +#elif defined(__aarch64__) +typedef struct user_pt_regs regs_struct; +typedef struct user_fpsimd_state fpregs_struct; +#define PRINT_REG_PC(__regs) printf ("%x\n", (unsigned) (__regs.pc)) +#define PRINT_REG_FP(__fpregs) printf ("%x\n", (unsigned) (__fpregs.fpsr)) +#define ARCH_IOVEC_FOR_GETREGSET + +#elif defined(__powerpc64__) +typedef struct pt_regs regs_struct; +typedef elf_fpregset_t fpregs_struct; +#define PRINT_REG_PC(__regs) printf ("%lx\n", (unsigned long) (__regs.nip)) +#define PRINT_REG_FP(__fpregs) printf ("%lx\n", (elf_greg_t)fpregs[32]) +#define ARCH_IOVEC_FOR_GETREGSET + +#elif defined(__mips__) +typedef struct pt_regs regs_struct; +typedef elf_fpregset_t fpregs_struct; +#define PRINT_REG_PC(__regs) printf ("%lx\n", (unsigned long) (__regs.cp0_epc)) +#define PRINT_REG_FP(__fpregs) printf ("%lx\n", (elf_greg_t) (__fpregs[32])) +#define __PTRACE_FPREQUEST PTRACE_GETFPREGS + +#elif defined(__arm__) +# include <asm/ptrace.h> +# include <sys/procfs.h> +typedef struct pt_regs regs_struct; +typedef char fpregs_struct[ARM_VFPREGS_SIZE]; +#define PRINT_REG_PC(__regs) printf ("%x\n", (unsigned) (__regs.ARM_pc)) +#define PRINT_REG_FP(__fpregs) printf ("%x\n", (unsigned) (__fpregs + 32 * 8)) +#define __PTRACE_FPREQUEST PTRACE_GETVFPREGS +#endif + int main(void) { pid_t pid; @@ -21,28 +70,48 @@ int main(void) { execl("/bin/true", "true", NULL); } else { wait(NULL); - user_regs_struct regs; + regs_struct regs; + regs_struct* volatile pregs = ®s; +#ifdef ARCH_IOVEC_FOR_GETREGSET + struct iovec regset_io; +#endif int res; - user_regs_struct * volatile pregs = ®s; + #ifdef POSITIVE ++pregs; #endif - res = ptrace(PTRACE_GETREGS, pid, NULL, pregs); + +#ifdef ARCH_IOVEC_FOR_GETREGSET +# define __PTRACE_REQUEST PTRACE_GETREGSET +# define __PTRACE_ARGS (void*)NT_PRSTATUS, (void*)®set_io + regset_io.iov_base = pregs; + regset_io.iov_len = sizeof(regs_struct); +#else +# define __PTRACE_REQUEST PTRACE_GETREGS +# define __PTRACE_ARGS NULL, pregs +#endif + res = ptrace((enum __ptrace_request)__PTRACE_REQUEST, pid, __PTRACE_ARGS); // CHECK: AddressSanitizer: stack-buffer-overflow // CHECK: {{.*ptrace.cc:}}[[@LINE-2]] assert(!res); -#ifdef __x86_64__ - printf("%lx\n", (unsigned long)regs.rip); + PRINT_REG_PC(regs); + + fpregs_struct fpregs; +#ifdef ARCH_IOVEC_FOR_GETREGSET +# define __PTRACE_FPREQUEST PTRACE_GETREGSET +# define __PTRACE_FPARGS (void*)NT_PRSTATUS, (void*)®set_io + regset_io.iov_base = &fpregs; + regset_io.iov_len = sizeof(fpregs_struct); + res = ptrace((enum __ptrace_request)PTRACE_GETREGSET, pid, (void*)NT_FPREGSET, + (void*)®set_io); #else - printf("%lx\n", regs.eip); +# define __PTRACE_FPARGS NULL, &fpregs #endif - - user_fpregs_struct fpregs; - res = ptrace(PTRACE_GETFPREGS, pid, NULL, &fpregs); + res = ptrace((enum __ptrace_request)__PTRACE_FPREQUEST, pid, __PTRACE_FPARGS); assert(!res); - printf("%lx\n", (unsigned long)fpregs.cwd); + PRINT_REG_FP(fpregs); -#ifndef __x86_64__ +#ifdef __i386__ 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 1820cb90c4ef..cbacec22fa1e 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: 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 +// RUN: %env_asan_opts=quarantine_size=10485760:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10 +// RUN: %env_asan_opts=quarantine_size_mb=10:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10 +// RUN: %env_asan_opts=quarantine_size_mb=10:quarantine_size=20:verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=BOTH +// RUN: %env_asan_opts=quarantine_size_mb=1000:hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT +// RUN: %env_asan_opts=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 index 0e408d0e366d..b09096c89cb7 100644 --- a/test/asan/TestCases/Linux/read_binary_name_regtest.c +++ b/test/asan/TestCases/Linux/read_binary_name_regtest.c @@ -14,6 +14,10 @@ #include <linux/filter.h> #include <linux/seccomp.h> +#ifndef __NR_readlink +# define __NR_readlink __NR_readlinkat +#endif + #define syscall_nr (offsetof(struct seccomp_data, nr)) void corrupt() { diff --git a/test/asan/TestCases/Linux/sized_delete_test.cc b/test/asan/TestCases/Linux/sized_delete_test.cc index 1146b8239d8c..5d8c7010e31b 100644 --- a/test/asan/TestCases/Linux/sized_delete_test.cc +++ b/test/asan/TestCases/Linux/sized_delete_test.cc @@ -1,10 +1,10 @@ // 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: %env_asan_opts=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 +// RUN: %env_asan_opts=new_delete_type_mismatch=1 not %run %t array 2>&1 | FileCheck %s -check-prefix=ARRAY +// RUN: %env_asan_opts=new_delete_type_mismatch=0 %run %t scalar +// RUN: %env_asan_opts=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 23c4d23ce406..8c9599c9f611 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=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=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 f207a94ae65e..49c208978010 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: env ASAN_OPTIONS=$ASAN_OPTIONS:exitcode=0 %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=exitcode=0 %run %t 2>&1 | FileCheck %s // XFAIL: arm-linux-gnueabi // XFAIL: armv7l-unknown-linux-gnueabihf diff --git a/test/asan/TestCases/Linux/static_tls.cc b/test/asan/TestCases/Linux/static_tls.cc index 785228b29238..11bb1a4f849c 100644 --- a/test/asan/TestCases/Linux/static_tls.cc +++ b/test/asan/TestCases/Linux/static_tls.cc @@ -3,13 +3,13 @@ // // 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 +// RUN: %env_asan_opts=verbosity=2 %run %t 2>&1 | FileCheck %s // CHECK: before // CHECK: __tls_get_addr: static tls // CHECK: after -// XFAIL: powerpc64 +// XFAIL: aarch64 #ifndef SHARED #include <stdio.h> diff --git a/test/asan/TestCases/Linux/stress_dtls.c b/test/asan/TestCases/Linux/stress_dtls.c index 7af33b9457ea..fd1ce0cd472f 100644 --- a/test/asan/TestCases/Linux/stress_dtls.c +++ b/test/asan/TestCases/Linux/stress_dtls.c @@ -1,4 +1,5 @@ // REQUIRES: asan-64-bits +// UNSUPPORTED: android // Stress test dynamic TLS + dlopen + threads. // // Note that glibc 2.15 seems utterly broken on this test, @@ -12,9 +13,9 @@ // RUN: %clangxx_asan %s -ldl -pthread -o %t // RUN: %run %t 0 3 // RUN: %run %t 2 3 -// 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 +// RUN: %env_asan_opts=verbosity=2 %run %t 10 2 2>&1 | FileCheck %s +// RUN: %env_asan_opts=verbosity=2:intercept_tls_get_addr=1 %run %t 10 2 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 b299ae8cb21e..69c1df9a1d3f 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=$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 +// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=allow_user_segv_handler=true not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O2 %s -o %t && %env_asan_opts=allow_user_segv_handler=true not %run %t 2>&1 | FileCheck %s #include <signal.h> #include <stdio.h> @@ -55,5 +55,5 @@ int main() { // CHECK: User sigaction installed // CHECK-NEXT: User sigaction called -// CHECK-NEXT: ASAN:SIGSEGV +// CHECK-NEXT: ASAN:DEADLYSIGNAL // CHECK: AddressSanitizer: SEGV on unknown address diff --git a/test/asan/TestCases/Posix/asan-symbolize-bad-path.cc b/test/asan/TestCases/Posix/asan-symbolize-bad-path.cc new file mode 100644 index 000000000000..22c03e8ddced --- /dev/null +++ b/test/asan/TestCases/Posix/asan-symbolize-bad-path.cc @@ -0,0 +1,4 @@ +// Test that asan_symbolize does not hang when provided with an non-existing +// path. +// RUN: echo '#0 0xabcdabcd (%T/bad/path+0x1234)' | %asan_symbolize | FileCheck %s +// CHECK: #0 0xabcdabcd diff --git a/test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc b/test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc index 043130f9e549..dd59e4a60774 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=$ASAN_OPTIONS:symbolize=0 not %run %t 2>&1 | %asan_symbolize | FileCheck %s +// RUN: %env_asan_opts=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/Posix/assign_large_valloc_to_global.cc b/test/asan/TestCases/Posix/assign_large_valloc_to_global.cc index ad547ce0ce1b..8031d04aae48 100644 --- a/test/asan/TestCases/Posix/assign_large_valloc_to_global.cc +++ b/test/asan/TestCases/Posix/assign_large_valloc_to_global.cc @@ -2,8 +2,5 @@ // RUN: %clangxx_asan -O3 %s -o %t && %run %t #include <stdlib.h> #include <unistd.h> -#if !defined(__APPLE__) && !defined(__FreeBSD__) -# include <malloc.h> -#endif // !__APPLE__ && !__FreeBSD__ -int *p = (int*)valloc(1 << 20); -int main() { } +int *p; +int main() { posix_memalign((void **)&p, 4096, 1 << 20); } diff --git a/test/asan/TestCases/closed-fds.cc b/test/asan/TestCases/Posix/closed-fds.cc index af0ac26743ca..3bbe3d8e68e1 100644 --- a/test/asan/TestCases/closed-fds.cc +++ b/test/asan/TestCases/Posix/closed-fds.cc @@ -2,7 +2,7 @@ // 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: %clangxx_asan -O0 %s -o %t 2>&1 && %env_asan_opts=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. diff --git a/test/asan/TestCases/coverage-caller-callee.cc b/test/asan/TestCases/Posix/coverage-caller-callee.cc index 9c42817776f9..fb8b9bf92af2 100644 --- a/test/asan/TestCases/coverage-caller-callee.cc +++ b/test/asan/TestCases/Posix/coverage-caller-callee.cc @@ -2,15 +2,16 @@ // and various numbers of callers and callees. // 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: %env_asan_opts=coverage=1:verbosity=1 %run %t 10 1 2>&1 | FileCheck %s --check-prefix=CHECK-10-1 +// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 9 2 2>&1 | FileCheck %s --check-prefix=CHECK-9-2 +// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 7 3 2>&1 | FileCheck %s --check-prefix=CHECK-7-3 +// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 17 1 2>&1 | FileCheck %s --check-prefix=CHECK-17-1 +// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 15 2 2>&1 | FileCheck %s --check-prefix=CHECK-15-2 +// RUN: %env_asan_opts=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 +// UNSUPPORTED: android // // CHECK-10-1: CovDump: 10 caller-callee pairs written // CHECK-9-2: CovDump: 18 caller-callee pairs written diff --git a/test/asan/TestCases/Posix/coverage-direct-activation.cc b/test/asan/TestCases/Posix/coverage-direct-activation.cc index af73f5d2952d..0af3296f22d4 100644 --- a/test/asan/TestCases/Posix/coverage-direct-activation.cc +++ b/test/asan/TestCases/Posix/coverage-direct-activation.cc @@ -7,11 +7,11 @@ // RUN: rm -rf %T/coverage-direct-activation // RUN: mkdir -p %T/coverage-direct-activation/normal -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1,coverage_direct=0,coverage_dir=%T/coverage-direct-activation/normal:verbosity=1 %run %t %dynamiclib +// RUN: %env_asan_opts=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: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1,coverage_direct=1,verbosity=1 \ +// RUN: %env_asan_opts=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 @@ -23,7 +23,7 @@ // RUN: diff -u coverage-direct-activation/normal/out.txt coverage-direct-activation/direct/out.txt // RUN: mkdir -p %T/coverage-direct-activation/direct2 -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1,coverage=1,coverage_direct=1,verbosity=1 \ +// RUN: %env_asan_opts=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 diff --git a/test/asan/TestCases/Posix/coverage-direct-large.cc b/test/asan/TestCases/Posix/coverage-direct-large.cc index 2769172c39ab..367a5667a711 100644 --- a/test/asan/TestCases/Posix/coverage-direct-large.cc +++ b/test/asan/TestCases/Posix/coverage-direct-large.cc @@ -8,12 +8,12 @@ // RUN: rm -rf %T/coverage-direct-large // RUN: mkdir -p %T/coverage-direct-large/normal && cd %T/coverage-direct-large/normal -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:verbosity=1 %run %t %dynamiclib +// RUN: %env_asan_opts=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: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:verbosity=1 %run %t %dynamiclib +// RUN: %env_asan_opts=coverage=1:coverage_direct=1:verbosity=1 %run %t %dynamiclib // RUN: %sancov rawunpack *.sancov.raw // RUN: %sancov print *.sancov >out.txt // RUN: cd ../.. diff --git a/test/asan/TestCases/Posix/coverage-direct.cc b/test/asan/TestCases/Posix/coverage-direct.cc index 5371a859c24f..8caa9c553f2e 100644 --- a/test/asan/TestCases/Posix/coverage-direct.cc +++ b/test/asan/TestCases/Posix/coverage-direct.cc @@ -6,11 +6,11 @@ // RUN: rm -rf %T/coverage-direct // RUN: mkdir -p %T/coverage-direct/normal -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib +// RUN: %env_asan_opts=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: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib +// RUN: %env_asan_opts=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 @@ -25,11 +25,11 @@ // RUN: rm -rf %T/coverage-direct // RUN: mkdir -p %T/coverage-direct/normal -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib +// RUN: %env_asan_opts=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: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib +// RUN: %env_asan_opts=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 @@ -44,11 +44,11 @@ // RUN: rm -rf %T/coverage-direct // RUN: mkdir -p %T/coverage-direct/normal -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib +// RUN: %env_asan_opts=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: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib +// RUN: %env_asan_opts=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 diff --git a/test/asan/TestCases/Posix/coverage-fork-direct.cc b/test/asan/TestCases/Posix/coverage-fork-direct.cc index 39363911fec3..c19671953809 100644 --- a/test/asan/TestCases/Posix/coverage-fork-direct.cc +++ b/test/asan/TestCases/Posix/coverage-fork-direct.cc @@ -1,7 +1,7 @@ // 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=$ASAN_OPTIONS:coverage=1:coverage_direct=1:verbosity=1 %run %t; \ +// RUN: (%env_asan_opts=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/Posix/coverage-fork.cc b/test/asan/TestCases/Posix/coverage-fork.cc index c1f0fc3a84b8..799d71638a26 100644 --- a/test/asan/TestCases/Posix/coverage-fork.cc +++ b/test/asan/TestCases/Posix/coverage-fork.cc @@ -1,8 +1,7 @@ // 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 +// RUN: %env_asan_opts=coverage=1:coverage_direct=0:verbosity=1 %run %t 2>&1 | FileCheck %s // // XFAIL: android diff --git a/test/asan/TestCases/coverage-maybe-open-file.cc b/test/asan/TestCases/Posix/coverage-maybe-open-file.cc index b261fb0fc775..cab3d5770aa5 100644 --- a/test/asan/TestCases/coverage-maybe-open-file.cc +++ b/test/asan/TestCases/Posix/coverage-maybe-open-file.cc @@ -4,8 +4,8 @@ // 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: 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: %env_asan_opts=coverage=1 %run %t | FileCheck %s --check-prefix=CHECK-success +// RUN: %env_asan_opts=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 diff --git a/test/asan/TestCases/Posix/coverage-module-unloaded.cc b/test/asan/TestCases/Posix/coverage-module-unloaded.cc index fe08bdd792b1..d492af6662fa 100644 --- a/test/asan/TestCases/Posix/coverage-module-unloaded.cc +++ b/test/asan/TestCases/Posix/coverage-module-unloaded.cc @@ -3,10 +3,9 @@ // 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 %dynamiclib1 %dynamiclib2 2>&1 | FileCheck %s -// RUN: %run %t %dynamiclib1 %dynamiclib2 foo 2>&1 | FileCheck %s +// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t %dynamiclib1 %dynamiclib2 2>&1 | FileCheck %s +// RUN: %env_asan_opts=coverage=1:verbosity=1 %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 diff --git a/test/asan/TestCases/Posix/coverage-sandboxing.cc b/test/asan/TestCases/Posix/coverage-sandboxing.cc index dd2c1ec43be5..f6fc5266607c 100644 --- a/test/asan/TestCases/Posix/coverage-sandboxing.cc +++ b/test/asan/TestCases/Posix/coverage-sandboxing.cc @@ -1,16 +1,16 @@ // 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 -// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-vanilla +// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-vanilla // RUN: mkdir ../sandbox1 && cd ../sandbox1 -// RUN: %run %t a 2>&1 | FileCheck %s --check-prefix=CHECK-sandbox -// RUN: %sancov unpack coverage_sandboxing_test.sancov.packed +// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t a 2>&1 | FileCheck %s --check-prefix=CHECK-sandbox +// RUN: %sancov unpack coverage_sandboxing_test.sancov.packed // RUN: mkdir ../sandbox2 && cd ../sandbox2 -// RUN: %run %t a b 2>&1 | FileCheck %s --check-prefix=CHECK-sandbox -// RUN: %sancov unpack coverage_sandboxing_test.sancov.packed +// RUN: %env_asan_opts=coverage=1:verbosity=1 %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/`basename %dynamiclib`*.sancov > vanilla.txt // RUN: %sancov print sandbox1/`basename %dynamiclib`*.sancov > sandbox1.txt @@ -18,6 +18,7 @@ // RUN: diff vanilla.txt sandbox1.txt // RUN: diff vanilla.txt sandbox2.txt // RUN: rm -r %T/coverage_sandboxing_test + // https://code.google.com/p/address-sanitizer/issues/detail?id=263 // XFAIL: android diff --git a/test/asan/TestCases/Posix/coverage.cc b/test/asan/TestCases/Posix/coverage.cc index 99e348fdaf9d..7c1c4949f60c 100644 --- a/test/asan/TestCases/Posix/coverage.cc +++ b/test/asan/TestCases/Posix/coverage.cc @@ -1,20 +1,19 @@ // 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: %env_asan_opts=coverage=1:verbosity=1 %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: %env_asan_opts=coverage=1:verbosity=1 %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: %env_asan_opts=coverage=1:verbosity=1 %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: %env_asan_opts=coverage=1:verbosity=1 %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: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4 2>&1 | FileCheck %s --check-prefix=CHECK-report +// RUN: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4 5 2>&1 | FileCheck %s --check-prefix=CHECK-segv // RUN: rm -r %T/coverage // // https://code.google.com/p/address-sanitizer/issues/detail?id=263 diff --git a/test/asan/TestCases/current_allocated_bytes.cc b/test/asan/TestCases/Posix/current_allocated_bytes.cc index c49e433b1e8b..c49e433b1e8b 100644 --- a/test/asan/TestCases/current_allocated_bytes.cc +++ b/test/asan/TestCases/Posix/current_allocated_bytes.cc diff --git a/test/asan/TestCases/deep_call_stack.cc b/test/asan/TestCases/Posix/deep_call_stack.cc index 0a26a80758c6..18ba563dbd21 100644 --- a/test/asan/TestCases/deep_call_stack.cc +++ b/test/asan/TestCases/Posix/deep_call_stack.cc @@ -1,10 +1,9 @@ // Check that UAR mode can handle very deep recusrion. -// 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 +// RUN: (ulimit -s 4096; %env_asan_opts=detect_stack_use_after_return=1 %run %t) 2>&1 | FileCheck %s // Also check that use_sigaltstack+verbosity doesn't crash. -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1:use_sigaltstack=1 %run %t | FileCheck %s +// RUN: %env_asan_opts=verbosity=1:use_sigaltstack=1:detect_stack_use_after_return=1 %run %t | FileCheck %s #include <stdio.h> __attribute__((noinline)) diff --git a/test/asan/TestCases/deep_thread_stack.cc b/test/asan/TestCases/Posix/deep_thread_stack.cc index 535da79ff58d..535da79ff58d 100644 --- a/test/asan/TestCases/deep_thread_stack.cc +++ b/test/asan/TestCases/Posix/deep_thread_stack.cc diff --git a/test/asan/TestCases/dlclose-test.cc b/test/asan/TestCases/Posix/dlclose-test.cc index 369abd3127cc..369abd3127cc 100644 --- a/test/asan/TestCases/dlclose-test.cc +++ b/test/asan/TestCases/Posix/dlclose-test.cc diff --git a/test/asan/TestCases/free_hook_realloc.cc b/test/asan/TestCases/Posix/free_hook_realloc.cc index cbc5d6fed56e..cbc5d6fed56e 100644 --- a/test/asan/TestCases/free_hook_realloc.cc +++ b/test/asan/TestCases/Posix/free_hook_realloc.cc diff --git a/test/asan/TestCases/Posix/freopen.cc b/test/asan/TestCases/Posix/freopen.cc new file mode 100644 index 000000000000..c137abb8fcb8 --- /dev/null +++ b/test/asan/TestCases/Posix/freopen.cc @@ -0,0 +1,15 @@ +// RUN: %clangxx_asan -O0 %s -o %t && %run %t + +// This fails on i386 Linux due to a glibc versioned symbols mixup. +// REQUIRES: asan-64-bits + +#include <assert.h> +#include <stdio.h> + +int main() { + FILE *fp = fopen("/dev/null", "w"); + assert(fp); + freopen(NULL, "a", fp); + fclose(fp); + return 0; +} diff --git a/test/asan/TestCases/gc-test.cc b/test/asan/TestCases/Posix/gc-test.cc index 3fedd6a68d38..56d8c398fc75 100644 --- a/test/asan/TestCases/gc-test.cc +++ b/test/asan/TestCases/Posix/gc-test.cc @@ -1,9 +1,9 @@ // RUN: %clangxx_asan %s -pthread -o %t -// 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: %env_asan_opts=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 +// RUN: %env_asan_opts=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=$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: %env_asan_opts=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 +// RUN: %env_asan_opts=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/Posix/halt_on_error-signals.c b/test/asan/TestCases/Posix/halt_on_error-signals.c new file mode 100644 index 000000000000..60916f6570fc --- /dev/null +++ b/test/asan/TestCases/Posix/halt_on_error-signals.c @@ -0,0 +1,102 @@ +// Test interaction of Asan recovery mode with asynch signals. +// +// RUN: %clang_asan -fsanitize-recover=address -pthread %s -o %t +// +// RUN: rm -f %t.log +// RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=false %run %t 100 >%t.log 2>&1 || true +// Collision will almost always get triggered but we still need to check the unlikely case: +// RUN: FileCheck --check-prefix=CHECK-COLLISION %s < %t.log || FileCheck --check-prefix=CHECK-NO-COLLISION %s < %t.log + +#define _SVID_SOURCE 1 // SA_NODEFER + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <pthread.h> +#include <time.h> +#include <signal.h> + +#include <sanitizer/asan_interface.h> + +void random_delay(unsigned *seed) { + *seed = 1664525 * *seed + 1013904223; + struct timespec delay = { 0, (*seed % 1000) * 1000 }; + nanosleep(&delay, 0); +} + +volatile char bad[2] = {1, }; + +void error() { + // CHECK-COLLISION: AddressSanitizer: nested bug in the same thread, aborting + // CHECK-NO-COLLISION: AddressSanitizer: use-after-poison + volatile int idx = 0; + bad[idx] = 0; +} + +#define CHECK_CALL(e, msg) do { \ + if (0 != (e)) { \ + fprintf(stderr, "Failed to " msg "\n"); \ + exit(1); \ + } \ +} while (0) + +size_t niter = 10; +pthread_t sender_tid, receiver_tid; + +pthread_mutex_t keep_alive_mu = PTHREAD_MUTEX_INITIALIZER; + +void *sender(void *arg) { + unsigned seed = 0; + for (size_t i = 0; i < niter; ++i) { + random_delay(&seed); + CHECK_CALL(pthread_kill(receiver_tid, SIGUSR1), "send signal"); + } + return 0; +} + +void handler(int sig) { + // Expect error collisions here + error(); +} + +void *receiver(void *arg) { + unsigned seed = 1; + for (size_t i = 0; i < niter; ++i) { + random_delay(&seed); + // And here + error(); + } + // Parent will release this when it's ok to terminate + CHECK_CALL(pthread_mutex_lock(&keep_alive_mu), "unlock mutex"); + return 0; +} + +int main(int argc, char **argv) { + if (argc != 2) { + fprintf(stderr, "Syntax: %s niter\n", argv[0]); + exit(1); + } + + niter = (size_t)strtoul(argv[1], 0, 0); + + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = handler; + sa.sa_flags = SA_NODEFER; // Enable nested handlers to add more stress + CHECK_CALL(sigaction(SIGUSR1, &sa, 0), "set sighandler"); + + __asan_poison_memory_region(&bad, sizeof(bad)); + + CHECK_CALL(pthread_mutex_lock(&keep_alive_mu), "lock mutex"); + CHECK_CALL(pthread_create(&receiver_tid, 0, receiver, 0), "start thread"); + CHECK_CALL(pthread_create(&sender_tid, 0, sender, 0), "start thread"); + CHECK_CALL(pthread_join(sender_tid, 0), "join thread"); + // Now allow receiver to die + CHECK_CALL(pthread_mutex_unlock(&keep_alive_mu), "unlock mutex"); + CHECK_CALL(pthread_join(receiver_tid, 0), "join thread"); + + // CHECK-NO-COLLISION: All threads terminated + printf("All threads terminated\n"); + + return 0; +} diff --git a/test/asan/TestCases/Posix/halt_on_error-torture.cc b/test/asan/TestCases/Posix/halt_on_error-torture.cc new file mode 100644 index 000000000000..019f7d126a47 --- /dev/null +++ b/test/asan/TestCases/Posix/halt_on_error-torture.cc @@ -0,0 +1,87 @@ +// Stress test recovery mode with many threads. +// +// RUN: %clangxx_asan -fsanitize-recover=address -pthread %s -o %t +// +// RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=false %run %t 1 10 >1.txt 2>&1 +// RUN: FileCheck %s < 1.txt +// RUN: [ $(grep -c 'ERROR: AddressSanitizer: use-after-poison' 1.txt) -eq 10 ] +// RUN: FileCheck --check-prefix=CHECK-NO-COLLISION %s < 1.txt +// +// Collisions are unlikely but still possible so we need the ||. +// RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=false %run %t 10 20 >10.txt 2>&1 || true +// This one is racy although _very_ unlikely to fail: +// RUN: FileCheck %s < 10.txt +// RUN: FileCheck --check-prefix=CHECK-COLLISION %s < 1.txt || FileCheck --check-prefix=CHECK-NO-COLLISION %s < 1.txt +// +// Collisions are unlikely but still possible so we need the ||. +// RUN: %env_asan_opts=halt_on_error=false %run %t 10 20 >10.txt 2>&1 || true +// This one is racy although _very_ unlikely to fail: +// RUN: FileCheck %s < 10.txt +// RUN: FileCheck --check-prefix=CHECK-COLLISION %s < 1.txt || FileCheck --check-prefix=CHECK-NO-COLLISION %s < 1.txt + +#include <stdio.h> +#include <stdlib.h> +#include <pthread.h> +#include <time.h> + +#include <sanitizer/asan_interface.h> + +size_t nthreads = 10; +size_t niter = 10; + +void random_delay(unsigned *seed) { + *seed = 1664525 * *seed + 1013904223; + struct timespec delay = { 0, (*seed % 1000) * 1000 }; + nanosleep(&delay, 0); +} + +void *run(void *arg) { + unsigned seed = (unsigned)(size_t)arg; + + volatile char tmp[2]; + __asan_poison_memory_region(&tmp, sizeof(tmp)); + + for (size_t i = 0; i < niter; ++i) { + random_delay(&seed); + // Expect error collisions here + // CHECK: ERROR: AddressSanitizer: use-after-poison + volatile int idx = 0; + tmp[idx] = 0; + } + + return 0; +} + +int main(int argc, char **argv) { + if (argc != 3) { + fprintf(stderr, "Syntax: %s nthreads niter\n", argv[0]); + exit(1); + } + + nthreads = (size_t)strtoul(argv[1], 0, 0); + niter = (size_t)strtoul(argv[2], 0, 0); + + pthread_t *tids = new pthread_t[nthreads]; + + for (size_t i = 0; i < nthreads; ++i) { + if (0 != pthread_create(&tids[i], 0, run, (void *)i)) { + fprintf(stderr, "Failed to create thread\n"); + exit(1); + } + } + + for (size_t i = 0; i < nthreads; ++i) { + if (0 != pthread_join(tids[i], 0)) { + fprintf(stderr, "Failed to join thread\n"); + exit(1); + } + } + + // CHECK-COLLISION: AddressSanitizer: nested bug in the same thread, aborting + // CHECK-NO-COLLISION: All threads terminated + printf("All threads terminated\n"); + + delete [] tids; + + return 0; +} diff --git a/test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cc b/test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cc new file mode 100644 index 000000000000..98b034812ef6 --- /dev/null +++ b/test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cc @@ -0,0 +1,55 @@ +// Test reports dedupication for recovery mode. +// +// RUN: %clang_asan -fsanitize-recover=address %s -o %t +// +// Check for reports dedupication. +// RUN: %env_asan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s +// +// Check that we die after reaching different reports number threshold. +// RUN: %env_asan_opts=halt_on_error=false not %run %t 1 > %t1.log 2>&1 +// RUN: [ $(grep -c 'ERROR: AddressSanitizer: stack-buffer-overflow' %t1.log) -eq 25 ] +// +// Check suppress_equal_pcs=true behavior is equal to default one. +// RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=true %run %t 2>&1 | FileCheck %s +// +// Check suppress_equal_pcs=false behavior isn't equal to default one. +// RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=false %run %t > %t2.log 2>&1 +// RUN: [ $(grep -c 'ERROR: AddressSanitizer: stack-buffer-overflow' %t2.log) -eq 30 ] + +#define ACCESS_ARRAY_FIVE_ELEMENTS(array, i) \ + array[i] = i; \ + array[i + 1] = i + 1; \ + array[i + 2] = i + 2; \ + array[i + 3] = i + 3; \ + array[i + 4] = i + 4; \ + +volatile int ten = 10; +unsigned kNumIterations = 10; + +int main(int argc, char **argv) { + char a[10]; + char b[10]; + + if (argc == 1) { + for (int i = 0; i < kNumIterations; ++i) { + // CHECK: READ of size 1 + volatile int res = a[ten + i]; + // CHECK: WRITE of size 1 + a[i + ten] = res + 3; + // CHECK: READ of size 1 + res = a[ten + i]; + // CHECK-NOT: ERROR + } + } else { + for (int i = 0; i < kNumIterations; ++i) { + ACCESS_ARRAY_FIVE_ELEMENTS(a, ten); + ACCESS_ARRAY_FIVE_ELEMENTS(a, ten + 5); + ACCESS_ARRAY_FIVE_ELEMENTS(a, ten + 10); + ACCESS_ARRAY_FIVE_ELEMENTS(b, ten); + ACCESS_ARRAY_FIVE_ELEMENTS(b, ten + 5); + ACCESS_ARRAY_FIVE_ELEMENTS(b, ten + 10); + } + } + return 0; +} + diff --git a/test/asan/TestCases/init-order-pthread-create.cc b/test/asan/TestCases/Posix/init-order-pthread-create.cc index 12362fc440dc..19c000fec435 100644 --- a/test/asan/TestCases/init-order-pthread-create.cc +++ b/test/asan/TestCases/Posix/init-order-pthread-create.cc @@ -1,8 +1,12 @@ // Check that init-order checking is properly disabled if pthread_create is // called. -// RUN: %clangxx_asan %s %p/Helpers/init-order-pthread-create-extra.cc -pthread -o %t -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true %run %t +// RUN: %clangxx_asan -c -DCONFIG1 %s -o %t1.o +// RUN: %clangxx_asan -c %s -o %t2.o +// RUN: %clangxx_asan -pthread %t1.o %t2.o -o %t +// RUN: %env_asan_opts=strict_init_order=true %run %t + +#ifdef CONFIG1 #include <stdio.h> #include <pthread.h> @@ -41,3 +45,10 @@ int main() { printf("%p %p\n", glob, glob2); return 0; } + +#else // CONFIG1 + +void *bar(void *input, bool sleep_before_init); +void *glob2 = bar((void*)0x2345, true); + +#endif diff --git a/test/asan/TestCases/Posix/ioctl.cc b/test/asan/TestCases/Posix/ioctl.cc index d25f6ecbee1f..6cf9fa8e3cd3 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=$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 && %env_asan_opts=handle_ioctl=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O3 -g %s -o %t && %env_asan_opts=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 b1c99430c75d..b39fa74a3149 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: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size_mb=0 %run %t +// RUN: %env_asan_opts=quarantine_size_mb=0 %run %t #include <assert.h> #include <string.h> diff --git a/test/asan/TestCases/Posix/log_path_fork_test.cc.disabled b/test/asan/TestCases/Posix/log_path_fork_test.cc.disabled index 9f09b78f41c7..029bdd1e3372 100644 --- a/test/asan/TestCases/Posix/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="$ASAN_OPTIONS:log_path=%t.log verbosity=1" not %run %t 2> %t.out +// RUN: %env_asan_opts=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 bc681857ae67..dd50bf7fe6a8 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: 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 +// RUN: %env_asan_opts=poison_array_cookie=1 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 5998d06756d7..f36da2b5438d 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: 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 +// RUN: %env_asan_opts=poison_array_cookie=1 not %run %t 2>&1 | FileCheck %s --check-prefix=COOKIE +// RUN: %env_asan_opts=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/new_array_cookie_with_new_from_class.cc b/test/asan/TestCases/Posix/new_array_cookie_with_new_from_class.cc index 1cea6f68adb2..0683e391cf23 100644 --- a/test/asan/TestCases/Posix/new_array_cookie_with_new_from_class.cc +++ b/test/asan/TestCases/Posix/new_array_cookie_with_new_from_class.cc @@ -2,8 +2,7 @@ // inside the class. // RUN: %clangxx_asan %s -o %t && %run %t // -// XFAIL: android -// XFAIL: armv7l-unknown-linux-gnueabihf +// XFAIL: arm #include <new> #include <stdlib.h> #include <stdint.h> diff --git a/test/asan/TestCases/stack-overflow.cc b/test/asan/TestCases/Posix/stack-overflow.cc index d792c466f977..8ef161862499 100644 --- a/test/asan/TestCases/stack-overflow.cc +++ b/test/asan/TestCases/Posix/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=$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 -DSMALL_FRAME -pthread -o %t && %env_asan_opts=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O3 %s -DSMALL_FRAME -pthread -o %t && %env_asan_opts=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O0 %s -DSAVE_ALL_THE_REGISTERS -pthread -o %t && %env_asan_opts=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O3 %s -DSAVE_ALL_THE_REGISTERS -pthread -o %t && %env_asan_opts=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O0 %s -pthread -o %t && %env_asan_opts=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O3 %s -pthread -o %t && %env_asan_opts=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: %clangxx_asan -O0 %s -DTHREAD -DSMALL_FRAME -pthread -o %t && %env_asan_opts=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O3 %s -DTHREAD -DSMALL_FRAME -pthread -o %t && %env_asan_opts=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_opts=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_opts=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O0 %s -DTHREAD -pthread -o %t && %env_asan_opts=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O3 %s -DTHREAD -pthread -o %t && %env_asan_opts=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/Posix/stack-use-after-return.cc index 669e8703b82f..cf114be97d51 100644 --- a/test/asan/TestCases/stack-use-after-return.cc +++ b/test/asan/TestCases/Posix/stack-use-after-return.cc @@ -1,19 +1,18 @@ -// 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=$ASAN_OPTIONS:detect_stack_use_after_return=0 %run %t +// RUN: %clangxx_asan -O0 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O1 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O2 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O3 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 +// RUN: %clangxx_asan -O3 %s -pthread -o %t -DkSize=10000 -DUseThread -DkStackSize=65536 && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s // // Test that we can find UAR in a thread other than main: -// RUN: %clangxx_asan -DUseThread -O2 %s -pthread -o %t && not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s +// RUN: %clangxx_asan -DUseThread -O2 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s // // Test the max_uar_stack_size_log/min_uar_stack_size_log flag. // -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:max_uar_stack_size_log=20:verbosity=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-20 %s -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:min_uar_stack_size_log=24:max_uar_stack_size_log=24:verbosity=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-24 %s +// RUN: %env_asan_opts=detect_stack_use_after_return=1:max_uar_stack_size_log=20:verbosity=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-20 %s +// RUN: %env_asan_opts=detect_stack_use_after_return=1:min_uar_stack_size_log=24:max_uar_stack_size_log=24:verbosity=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-24 %s #include <stdio.h> #include <pthread.h> diff --git a/test/asan/TestCases/Posix/start-deactivated.cc b/test/asan/TestCases/Posix/start-deactivated.cc index 2ca8015fc742..b30141549014 100644 --- a/test/asan/TestCases/Posix/start-deactivated.cc +++ b/test/asan/TestCases/Posix/start-deactivated.cc @@ -5,17 +5,17 @@ // 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: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1,allocator_may_return_null=0 \ +// RUN: %env_asan_opts=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: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1 \ +// RUN: %env_asan_opts=start_deactivated=1 \ // RUN: ASAN_ACTIVATION_OPTIONS=help=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-HELP -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1,verbosity=1 \ +// RUN: %env_asan_opts=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: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1 \ +// RUN: %env_asan_opts=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: env ASAN_OPTIONS=$ASAN_OPTIONS:start_deactivated=1 \ +// RUN: %env_asan_opts=start_deactivated=1 \ // RUN: ASAN_ACTIVATION_OPTIONS=help=1,handle_segv=0,verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UNSUPPORTED // XFAIL: arm-linux-gnueabi diff --git a/test/asan/TestCases/Posix/tsd_dtor_leak.cc b/test/asan/TestCases/Posix/tsd_dtor_leak.cc index 69d28194fb9e..9e71ff61cf02 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: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size_mb=0 %run %t +// RUN: %env_asan_opts=quarantine_size_mb=0 %run %t #include <pthread.h> #include <stdio.h> #include <stdlib.h> diff --git a/test/asan/TestCases/Posix/wait.cc b/test/asan/TestCases/Posix/wait.cc index 99d0212acfab..ed6f326b57d6 100644 --- a/test/asan/TestCases/Posix/wait.cc +++ b/test/asan/TestCases/Posix/wait.cc @@ -4,12 +4,6 @@ // RUN: %clangxx_asan -DWAITPID -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s // RUN: %clangxx_asan -DWAITPID -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s -// RUN: %clangxx_asan -DWAIT3 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s -// RUN: %clangxx_asan -DWAIT3 -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s - -// RUN: %clangxx_asan -DWAIT3_RUSAGE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s -// RUN: %clangxx_asan -DWAIT3_RUSAGE -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s - #include <assert.h> #include <sys/wait.h> @@ -25,12 +19,6 @@ int main(int argc, char **argv) { res = wait(status); #elif defined(WAITPID) res = waitpid(pid, status, WNOHANG); -#elif defined(WAIT3) - res = wait3(status, WNOHANG, NULL); -#elif defined(WAIT3_RUSAGE) - struct rusage *ru = (struct rusage*)(x + argc * 3); - int good_status; - res = wait3(&good_status, WNOHANG, ru); #endif // CHECK: stack-buffer-overflow // CHECK: {{WRITE of size .* at 0x.* thread T0}} diff --git a/test/asan/TestCases/Posix/wait3.cc b/test/asan/TestCases/Posix/wait3.cc new file mode 100644 index 000000000000..2da816fed1aa --- /dev/null +++ b/test/asan/TestCases/Posix/wait3.cc @@ -0,0 +1,36 @@ +// RUN: %clangxx_asan -DWAIT3 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -DWAIT3 -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s + +// RUN: %clangxx_asan -DWAIT3_RUSAGE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -DWAIT3_RUSAGE -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s + +// UNSUPPORTED: android + +#include <assert.h> +#include <sys/wait.h> +#include <unistd.h> + +int main(int argc, char **argv) { + pid_t pid = fork(); + if (pid) { // parent + int x[3]; + int *status = x + argc * 3; + int res; +#if defined(WAIT3) + res = wait3(status, WNOHANG, NULL); +#elif defined(WAIT3_RUSAGE) + struct rusage *ru = (struct rusage*)(x + argc * 3); + int good_status; + res = wait3(&good_status, WNOHANG, ru); +#endif + // CHECK: stack-buffer-overflow + // CHECK: {{WRITE of size .* at 0x.* thread T0}} + // CHECK: {{in .*wait}} + // CHECK: {{in main .*wait3.cc:}} + // CHECK: is located in stack of thread T0 at offset + // CHECK: {{in main}} + return res == -1 ? 1 : 0; + } + // child + return 0; +} diff --git a/test/asan/TestCases/Windows/bitfield_uaf.cc b/test/asan/TestCases/Windows/bitfield_uaf.cc index f49d671e3eb3..a1a2657934a4 100644 --- a/test/asan/TestCases/Windows/bitfield_uaf.cc +++ b/test/asan/TestCases/Windows/bitfield_uaf.cc @@ -14,7 +14,7 @@ void make_access(S *s) { s->bf2 = 2; // CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]] // CHECK: READ of size {{[124]}} at [[ADDR]] -// CHECK: {{#0 .* make_access .*bitfield_uaf.cc}}:[[@LINE-3]] +// CHECK: {{#0 .* make_access.*bitfield_uaf.cc}}:[[@LINE-3]] // CHECK: {{#1 .* main}} } diff --git a/test/asan/TestCases/Windows/coverage-basic.cc b/test/asan/TestCases/Windows/coverage-basic.cc index 44b499fcb4cd..0ff105d1624e 100644 --- a/test/asan/TestCases/Windows/coverage-basic.cc +++ b/test/asan/TestCases/Windows/coverage-basic.cc @@ -1,7 +1,7 @@ // 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: %env_asan_opts=coverage=1 %run ./test.exe // // RUN: %sancov print *.sancov | FileCheck %s #include <stdio.h> diff --git a/test/asan/TestCases/Windows/demangled_names.cc b/test/asan/TestCases/Windows/demangled_names.cc index a528555b1e16..0e5939ee4155 100644 --- a/test/asan/TestCases/Windows/demangled_names.cc +++ b/test/asan/TestCases/Windows/demangled_names.cc @@ -43,8 +43,8 @@ int main() { free(buffer); A<char*> a(buffer); // CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]] -// CHECK: foo::bar<42> {{.*}}demangled_names.cc -// CHECK: foo::spam {{.*}}demangled_names.cc -// CHECK: baz<char *,1> {{.*}}demangled_names.cc -// CHECK: A<char *>::~A<char *> {{.*}}demangled_names.cc +// CHECK: foo::bar<42>{{.*}}demangled_names.cc +// CHECK: foo::spam{{.*}}demangled_names.cc +// CHECK: baz<char *,1>{{.*}}demangled_names.cc +// CHECK: A<char *>::~A<char *>{{.*}}demangled_names.cc } diff --git a/test/asan/TestCases/Windows/dll_control_c.cc b/test/asan/TestCases/Windows/dll_control_c.cc new file mode 100644 index 000000000000..b53cb3f62965 --- /dev/null +++ b/test/asan/TestCases/Windows/dll_control_c.cc @@ -0,0 +1,130 @@ +// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t +// RUN: %clang_cl_asan -LD -O2 %s -Fe%t.dll +// RUNX: %run %t %t.dll 2>&1 | FileCheck %s + +// Check that ASan does not CHECK fail when SEH is used around a crash from a +// thread injected by control C. + +#include <stdio.h> +#include <stdlib.h> +#include <windows.h> + +static void __declspec(noinline) CrashOnProcessDetach() { + printf("CrashOnProcessDetach\n"); + fflush(stdout); + *static_cast<volatile int *>(0) = 0x356; +} + +bool g_is_child = false; + +BOOL WINAPI DllMain(PVOID h, DWORD reason, PVOID reserved) { + if (reason == DLL_PROCESS_DETACH && g_is_child) { + printf("in DllMain DLL_PROCESS_DETACH\n"); + fflush(stdout); + __try { + CrashOnProcessDetach(); + } __except (1) { + printf("caught crash\n"); + fflush(stdout); + } + } + return true; +} + +static void run_child() { + // Send this process group Ctrl+C. That should only be this process. + printf("GenerateConsoleCtrlEvent\n"); + fflush(stdout); + GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0); + Sleep(10 * 1000); // Wait 10 seconds, and the process should die. + printf("unexpected execution after interrupt\n"); + fflush(stdout); + exit(0x42); +} + +static int WINAPI ignore_control_c(DWORD ctrl_type) { + // Don't interrupt the parent. + return ctrl_type == CTRL_C_EVENT; +} + +static int run_parent() { + // Set an environment variable to tell the child process to interrupt itself. + if (!SetEnvironmentVariableW(L"DO_CONTROL_C", L"1")) { + printf("SetEnvironmentVariableW failed (0x%8lx).\n", GetLastError()); + fflush(stdout); + return 2; + } + + // Launch a new process using the current executable with a new console. + // Ctrl-C events are console-wide, so we need a new console. + STARTUPINFOW si; + memset(&si, 0, sizeof(si)); + si.cb = sizeof(si); + // Hides the new console window that we are creating. + si.dwFlags |= STARTF_USESHOWWINDOW; + si.wShowWindow = SW_HIDE; + // Ensures that stdout still goes to the parent despite the new console. + si.dwFlags |= STARTF_USESTDHANDLES; + si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); + si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); + si.hStdError = GetStdHandle(STD_ERROR_HANDLE); + + PROCESS_INFORMATION pi; + memset(&pi, 0, sizeof(pi)); + int flags = CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE; + if (!CreateProcessW(nullptr, // No module name (use command line) + GetCommandLineW(), // Command line + nullptr, // Process handle not inheritable + nullptr, // Thread handle not inheritable + TRUE, // Set handle inheritance to TRUE + flags, // Flags to give the child a console + nullptr, // Use parent's environment block + nullptr, // Use parent's starting directory + &si, &pi)) { + printf("CreateProcess failed (0x%08lx).\n", GetLastError()); + fflush(stdout); + return 2; + } + + // Wait until child process exits. + if (WaitForSingleObject(pi.hProcess, INFINITE) == WAIT_FAILED) { + printf("WaitForSingleObject failed (0x%08lx).\n", GetLastError()); + fflush(stdout); + return 2; + } + + // Get the exit code. It should be the one for ctrl-c events. + DWORD rc; + if (!GetExitCodeProcess(pi.hProcess, &rc)) { + printf("GetExitCodeProcess failed (0x%08lx).\n", GetLastError()); + fflush(stdout); + return 2; + } + if (rc == STATUS_CONTROL_C_EXIT) + printf("child quit with STATUS_CONTROL_C_EXIT\n"); + else + printf("unexpected exit code: 0x%08lx\n", rc); + fflush(stdout); + + // Close process and thread handles. + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + return 0; +} + +// CHECK: in DllMain DLL_PROCESS_DETACH +// CHECK: CrashOnProcessDetach +// CHECK: caught crash +// CHECK: child quit with STATUS_CONTROL_C_EXIT + +extern "C" int __declspec(dllexport) test_function() { + wchar_t buf[260]; + int len = GetEnvironmentVariableW(L"DO_CONTROL_C", buf, 260); + if (len > 0) { + g_is_child = true; + run_child(); + } else { + exit(run_parent()); + } + return 0; +} diff --git a/test/asan/TestCases/Windows/dll_noreturn.cc b/test/asan/TestCases/Windows/dll_noreturn.cc index 79f923eccf84..8b5e3d005875 100644 --- a/test/asan/TestCases/Windows/dll_noreturn.cc +++ b/test/asan/TestCases/Windows/dll_noreturn.cc @@ -11,12 +11,12 @@ void noreturn_f() { _exit(1); // 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 -// CHECK-NEXT: main {{.*}}dll_host.cc +// CHECK-NEXT: noreturn_f{{.*}}dll_noreturn.cc:[[@LINE-4]] +// CHECK-NEXT: test_function{{.*}}dll_noreturn.cc +// CHECK-NEXT: main{{.*}}dll_host.cc // // CHECK: Address [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame -// CHECK-NEXT: noreturn_f {{.*}}dll_noreturn.cc +// CHECK-NEXT: noreturn_f{{.*}}dll_noreturn.cc // CHECK: 'buffer' <== Memory access at offset [[OFFSET]] underflows this variable // CHECK-LABEL: SUMMARY } diff --git a/test/asan/TestCases/Windows/dll_poison_unpoison.cc b/test/asan/TestCases/Windows/dll_poison_unpoison.cc index d486cb122251..9b25a126ef6b 100644 --- a/test/asan/TestCases/Windows/dll_poison_unpoison.cc +++ b/test/asan/TestCases/Windows/dll_poison_unpoison.cc @@ -24,12 +24,12 @@ int test_function() { should_crash(&buffer[96]); // CHECK: AddressSanitizer: use-after-poison on address [[ADDR:0x[0-9a-f]+]] // CHECK-NEXT: WRITE of size 1 at [[ADDR]] thread T0 -// CHECK-NEXT: should_crash {{.*}}\dll_poison_unpoison.cc -// CHECK-NEXT: test_function {{.*}}\dll_poison_unpoison.cc:[[@LINE-4]] +// CHECK-NEXT: should_crash{{.*}}\dll_poison_unpoison.cc +// CHECK-NEXT: test_function{{.*}}\dll_poison_unpoison.cc:[[@LINE-4]] // CHECK-NEXT: main // // CHECK: [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame -// CHECK-NEXT: test_function {{.*}}\dll_poison_unpoison.cc +// CHECK-NEXT: test_function{{.*}}\dll_poison_unpoison.cc // CHECK: 'buffer' <== Memory access at offset [[OFFSET]] is inside this variable return 0; } 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 index fbdb1c145bbe..e07f26f08349 100644 --- a/test/asan/TestCases/Windows/dll_report_globals_symbolization_at_startup.cc +++ b/test/asan/TestCases/Windows/dll_report_globals_symbolization_at_startup.cc @@ -1,6 +1,6 @@ // 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 +// RUN: %env_asan_opts=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. diff --git a/test/asan/TestCases/Windows/dll_stack_use_after_return.cc b/test/asan/TestCases/Windows/dll_stack_use_after_return.cc index 6cd74c265b8f..642871846926 100644 --- a/test/asan/TestCases/Windows/dll_stack_use_after_return.cc +++ b/test/asan/TestCases/Windows/dll_stack_use_after_return.cc @@ -1,6 +1,6 @@ // RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll -// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 not %run %t %t.dll 2>&1 | FileCheck %s +// RUN: %env_asan_opts=detect_stack_use_after_return=1 not %run %t %t.dll 2>&1 | FileCheck %s #include <malloc.h> @@ -17,11 +17,11 @@ int test_function() { *x = 42; // CHECK: AddressSanitizer: stack-use-after-return // CHECK: WRITE of size 1 at [[ADDR:.*]] thread T0 -// CHECK-NEXT: test_function {{.*}}dll_stack_use_after_return.cc:[[@LINE-3]] +// CHECK-NEXT: test_function{{.*}}dll_stack_use_after_return.cc:[[@LINE-3]] // CHECK-NEXT: main // // CHECK: Address [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame -// CHECK-NEXT: #0 {{.*}} foo {{.*}}dll_stack_use_after_return.cc +// CHECK-NEXT: #0 {{.*}} foo{{.*}}dll_stack_use_after_return.cc // CHECK: 'stack_buffer' <== Memory access at offset [[OFFSET]] is inside this variable return 0; } 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 04d3e2ec554b..dc7c7c6ad7e2 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 @@ -11,10 +11,10 @@ DWORD WINAPI thread_proc(void *context) { 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-NEXT: thread_proc {{.*}}dll_thread_stack_array_left_oob.cc:[[@LINE-3]] +// CHECK-NEXT: thread_proc{{.*}}dll_thread_stack_array_left_oob.cc:[[@LINE-3]] // // CHECK: Address [[ADDR]] is located in stack of thread T1 at offset [[OFFSET:.*]] in frame -// CHECK-NEXT: thread_proc {{.*}}dll_thread_stack_array_left_oob.cc +// CHECK-NEXT: thread_proc{{.*}}dll_thread_stack_array_left_oob.cc // // CHECK: 'stack_buffer' <== Memory access at offset [[OFFSET]] underflows this variable @@ -25,8 +25,8 @@ extern "C" __declspec(dllexport) int test_function() { HANDLE thr = CreateThread(NULL, 0, thread_proc, NULL, 0, NULL); // CHECK-LABEL: Thread T1 created by T0 here: -// CHECK: test_function {{.*}}dll_thread_stack_array_left_oob.cc:[[@LINE-2]] -// CHECK-NEXT: main {{.*}}dll_host.cc +// CHECK: test_function{{.*}}dll_thread_stack_array_left_oob.cc:[[@LINE-2]] +// CHECK-NEXT: main{{.*}}dll_host.cc // CHECK-LABEL: SUMMARY if (thr == 0) return 1; diff --git a/test/asan/TestCases/Windows/fuse-lld.cc b/test/asan/TestCases/Windows/fuse-lld.cc new file mode 100644 index 000000000000..76c36d828fb7 --- /dev/null +++ b/test/asan/TestCases/Windows/fuse-lld.cc @@ -0,0 +1,23 @@ +// If we have LLD, see that things more or less work. +// +// REQUIRES: lld +// +// FIXME: Use -fuse-ld=lld after the old COFF linker is removed. +// FIXME: Test will fail until we add flags for requesting dwarf or cv. +// RUNX: %clangxx_asan -O2 %s -o %t.exe -fuse-ld=lld -Wl,-debug +// RUN: %clangxx_asan -c -O2 %s -o %t.o -gdwarf +// RUN: lld-link %t.o -out:%t.exe -debug -defaultlib:libcmt %asan_lib %asan_cxx_lib +// RUN: not %run %t.exe 2>&1 | FileCheck %s + +#include <stdlib.h> + +int main() { + char *x = (char*)malloc(10 * sizeof(char)); + free(x); + return x[5]; + // CHECK: heap-use-after-free + // CHECK: free + // CHECK: main{{.*}}fuse-lld.cc:[[@LINE-4]]:3 + // CHECK: malloc + // CHECK: main{{.*}}fuse-lld.cc:[[@LINE-7]]:20 +} diff --git a/test/asan/TestCases/Windows/intercept_strdup.cc b/test/asan/TestCases/Windows/intercept_strdup.cc index edb1f2f99245..371053480d2c 100644 --- a/test/asan/TestCases/Windows/intercept_strdup.cc +++ b/test/asan/TestCases/Windows/intercept_strdup.cc @@ -21,7 +21,8 @@ int main() { // CHECK: [[ADDR]] is located 1 bytes to the left of 6-byte region // CHECK: allocated by thread T0 here: // CHECK: {{#0 .* malloc }} -// CHECK: {{#1 .*strdup}} -// CHECK: {{#2 .* main .*}}intercept_strdup.cc:[[@LINE-16]] +// FIXME: llvm-symbolizer can't find strdup in the CRT. +// CHECKX: {{#1 .*strdup}} +// CHECK: {{#2 .* main .*}}intercept_strdup.cc:[[@LINE-17]] free(ptr); } diff --git a/test/asan/TestCases/Windows/null_deref.cc b/test/asan/TestCases/Windows/null_deref.cc index 202000f59db7..9515602ce89c 100644 --- a/test/asan/TestCases/Windows/null_deref.cc +++ b/test/asan/TestCases/Windows/null_deref.cc @@ -10,6 +10,6 @@ static void NullDeref(int *ptr) { } int main() { NullDeref((int*)0); - // CHECK: {{ #1 0x.* in main.*null_deref.cc:}}[[@LINE-1]] + // CHECK: {{ #1 0x.* in main.*null_deref.cc:}}[[@LINE-1]]:3 // CHECK: AddressSanitizer can not provide additional info. } diff --git a/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc b/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc index c3e7daca55b0..46875920c4c1 100644 --- a/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc +++ b/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc @@ -7,6 +7,6 @@ int main() { int *x = new int[42]; delete (x + 1); // CHECK: AddressSanitizer: attempting free on address which was not malloc()-ed -// CHECK: {{#0 0x.* operator delete }} +// CHECK: {{#0 0x.* operator delete}} // CHECK: {{#1 .* main .*operator_delete_wrong_argument.cc}}:[[@LINE-3]] } diff --git a/test/asan/TestCases/Windows/operator_new_left_oob.cc b/test/asan/TestCases/Windows/operator_new_left_oob.cc index c077f11d68f9..a12db9b1e21e 100644 --- a/test/asan/TestCases/Windows/operator_new_left_oob.cc +++ b/test/asan/TestCases/Windows/operator_new_left_oob.cc @@ -11,7 +11,7 @@ int main() { // CHECK: {{#0 .* main .*operator_new_left_oob.cc}}:[[@LINE-3]] // CHECK: [[ADDR]] is located 1 bytes to the left of 1-byte region // CHECK: allocated by thread T0 here: -// CHECK: {{#0 .* operator new }} +// CHECK: {{#0 .* operator new}} // CHECK: {{#1 .* main .*operator_new_left_oob.cc}}:[[@LINE-8]] delete buffer; } diff --git a/test/asan/TestCases/Windows/operator_new_right_oob.cc b/test/asan/TestCases/Windows/operator_new_right_oob.cc index 7a66d1714b97..7edee5495549 100644 --- a/test/asan/TestCases/Windows/operator_new_right_oob.cc +++ b/test/asan/TestCases/Windows/operator_new_right_oob.cc @@ -11,7 +11,7 @@ int main() { // CHECK: {{#0 .* main .*operator_new_right_oob.cc}}:[[@LINE-3]] // CHECK: [[ADDR]] is located 0 bytes to the right of 1-byte region // CHECK: allocated by thread T0 here: -// CHECK: {{#0 .* operator new }} +// CHECK: {{#0 .* operator new}} // CHECK: {{#1 .* main .*operator_new_right_oob.cc}}:[[@LINE-8]] delete buffer; } diff --git a/test/asan/TestCases/Windows/operator_new_uaf.cc b/test/asan/TestCases/Windows/operator_new_uaf.cc index c435458f0c1c..9d5a4078d073 100644 --- a/test/asan/TestCases/Windows/operator_new_uaf.cc +++ b/test/asan/TestCases/Windows/operator_new_uaf.cc @@ -12,10 +12,10 @@ int main() { // CHECK: {{#0 .* main .*operator_new_uaf.cc}}:[[@LINE-3]] // CHECK: [[ADDR]] is located 0 bytes inside of 1-byte region // CHECK-LABEL: freed by thread T0 here: -// CHECK: {{#0 .* operator delete }} +// CHECK: {{#0 .* operator delete}} // CHECK: {{#1 .* main .*operator_new_uaf.cc}}:[[@LINE-8]] // CHECK-LABEL: previously allocated by thread T0 here: -// CHECK: {{#0 .* operator new }} +// CHECK: {{#0 .* operator new}} // CHECK: {{#1 .* main .*operator_new_uaf.cc}}:[[@LINE-12]] return 0; } diff --git a/test/asan/TestCases/Windows/queue_user_work_item_report.cc b/test/asan/TestCases/Windows/queue_user_work_item_report.cc index a57e1e767dc7..f0d3d3e7cbcc 100644 --- a/test/asan/TestCases/Windows/queue_user_work_item_report.cc +++ b/test/asan/TestCases/Windows/queue_user_work_item_report.cc @@ -11,7 +11,7 @@ DWORD CALLBACK work_item(LPVOID) { 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: {{#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); diff --git a/test/asan/TestCases/Windows/report_after_syminitialize.cc b/test/asan/TestCases/Windows/report_after_syminitialize.cc index faf5e35db5f5..d83d7dc264a7 100644 --- a/test/asan/TestCases/Windows/report_after_syminitialize.cc +++ b/test/asan/TestCases/Windows/report_after_syminitialize.cc @@ -1,4 +1,5 @@ -// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O0 %s -o %t +// RUN: %env_asan_opts=external_symbolizer_path=asdf not %run %t 2>&1 | FileCheck %s #include <windows.h> #include <dbghelp.h> @@ -13,7 +14,8 @@ int main() { *(volatile int*)0 = 42; // CHECK: ERROR: AddressSanitizer: access-violation on unknown address + // CHECK-NEXT: {{WARNING: Failed to use and restart external symbolizer}} // CHECK-NEXT: {{WARNING: .*DbgHelp}} - // CHECK: {{#0 0x.* in main.*report_after_syminitialize.cc:}}[[@LINE-3]] + // CHECK: {{#0 0x.* in main.*report_after_syminitialize.cc:}}[[@LINE-4]] // CHECK: AddressSanitizer can not provide additional info. } diff --git a/test/asan/TestCases/Windows/report_globals_reload_dll.cc b/test/asan/TestCases/Windows/report_globals_reload_dll.cc index 8b050975aac1..4adbcc3b5293 100644 --- a/test/asan/TestCases/Windows/report_globals_reload_dll.cc +++ b/test/asan/TestCases/Windows/report_globals_reload_dll.cc @@ -1,7 +1,7 @@ // 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 +// RUN: %env_asan_opts=report_globals=1 %run %te.exe %t.dll 2>&1 | FileCheck %s #include <windows.h> #include <stdio.h> diff --git a/test/asan/TestCases/Windows/report_globals_vs_freelibrary.cc b/test/asan/TestCases/Windows/report_globals_vs_freelibrary.cc index 72bf36ad0be7..94b97f58f286 100644 --- a/test/asan/TestCases/Windows/report_globals_vs_freelibrary.cc +++ b/test/asan/TestCases/Windows/report_globals_vs_freelibrary.cc @@ -1,6 +1,6 @@ // 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 +// RUN: %env_asan_opts=report_globals=2 %run %te.exe %t.dll 2>&1 | FileCheck %s #include <windows.h> #include <stdio.h> diff --git a/test/asan/TestCases/Windows/seh.cc b/test/asan/TestCases/Windows/seh.cc index 50cf6ddba8d6..4cb0c55bc773 100644 --- a/test/asan/TestCases/Windows/seh.cc +++ b/test/asan/TestCases/Windows/seh.cc @@ -1,16 +1,17 @@ -// Clang doesn't support SEH on Windows yet, so for the time being we -// build this program in two parts: the code with SEH 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". +// Make sure that ASan works with SEH in both Clang and MSVC. MSVC uses a +// different EH personality depending on the -GS setting, so test both -GS+ and +// -GS-. // -// Check both -GS and -GS- builds: -// RUN: cl -c %s -Fo%t.obj +// RUN: cl -c %s -Fo%t.obj -DCOMPILE_SEH // RUN: %clangxx_asan -o %t.exe %s %t.obj // RUN: %run %t.exe // -// RUN: cl -GS- -c %s -Fo%t.obj +// RUN: cl -GS- -c %s -Fo%t.obj -DCOMPILE_SEH // RUN: %clangxx_asan -o %t.exe %s %t.obj // RUN: %run %t.exe +// +// RUN: %clang_cl_asan %s -DCOMPILE_SEH -Fe%t.exe +// RUN: %run %t.exe #include <windows.h> #include <assert.h> @@ -22,7 +23,7 @@ extern "C" bool __asan_address_is_poisoned(void *p); void ThrowAndCatch(); -#if !defined(__clang__) +#if defined(COMPILE_SEH) __declspec(noinline) void Throw() { int local, zero = 0; @@ -39,8 +40,9 @@ void ThrowAndCatch() { fprintf(stderr, "__except: %p\n", &local); } } -#else +#endif +#if defined(__clang__) int main() { char x[32]; fprintf(stderr, "Before: %p poisoned: %d\n", &x, diff --git a/test/asan/TestCases/Windows/shadow_mapping_failure.cc b/test/asan/TestCases/Windows/shadow_mapping_failure.cc index 97cd3d60cdfa..9b83947442ed 100644 --- a/test/asan/TestCases/Windows/shadow_mapping_failure.cc +++ b/test/asan/TestCases/Windows/shadow_mapping_failure.cc @@ -13,6 +13,5 @@ int main() { // CHECK: ASan shadow was supposed to be located in the [0x2fff0000-0x{{.*}}ffff] range. // CHECK: Dumping process modules: // CHECK-DAG: 0x{{[0-9a-f]*}}-0x{{[0-9a-f]*}} {{.*}}shadow_mapping_failure -// CHECK-DAG: 0x{{[0-9a-f]*}}-0x{{[0-9a-f]*}} {{.*}}kernel32.dll // CHECK-DAG: 0x{{[0-9a-f]*}}-0x{{[0-9a-f]*}} {{.*}}ntdll.dll } diff --git a/test/asan/TestCases/Windows/stack_use_after_return.cc b/test/asan/TestCases/Windows/stack_use_after_return.cc index 7955f2685308..9c31922af1de 100644 --- a/test/asan/TestCases/Windows/stack_use_after_return.cc +++ b/test/asan/TestCases/Windows/stack_use_after_return.cc @@ -1,5 +1,5 @@ // RUN: %clang_cl_asan -O0 %s -Fe%t -// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s char *x; @@ -16,7 +16,7 @@ int main() { // CHECK-NEXT: {{#0 0x.* in main .*stack_use_after_return.cc}}:[[@LINE-3]] // // CHECK: is located in stack of thread T0 at offset [[OFFSET:.*]] in frame -// CHECK-NEXT: {{#0 0x.* in foo .*stack_use_after_return.cc}} +// CHECK-NEXT: {{#0 0x.* in foo.*stack_use_after_return.cc}} // // CHECK: 'stack_buffer' <== Memory access at offset [[OFFSET]] is inside this variable } diff --git a/test/asan/TestCases/Windows/symbols_path.cc b/test/asan/TestCases/Windows/symbols_path.cc index 3c69f8861d78..81ead05c5069 100644 --- a/test/asan/TestCases/Windows/symbols_path.cc +++ b/test/asan/TestCases/Windows/symbols_path.cc @@ -16,7 +16,7 @@ int main() { // CHECK-NEXT: {{#0 .* main .*symbols_path.cc}}:[[@LINE-3]] // CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region // CHECK: allocated by thread T0 here: -// CHECK-NEXT: {{#0 .* malloc }} +// CHECK-NEXT: {{#0 .* malloc}} // CHECK-NEXT: {{#1 .* main .*symbols_path.cc}}:[[@LINE-8]] free(buffer); } 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 63cb8ae1f43c..aac9ecf248d4 100644 --- a/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc +++ b/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc @@ -9,7 +9,7 @@ DWORD WINAPI thread_proc(void *) { 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 .* thread_proc .*thread_stack_array_left_oob.cc}}:[[@LINE-3]] +// 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 // CHECK: thread_proc return 0; diff --git a/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc b/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc index 601a1b8a8760..2982e48dc4f6 100644 --- a/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc +++ b/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc @@ -9,7 +9,7 @@ DWORD WINAPI thread_proc(void *) { stack_buffer[subscript] = 42; // CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] // CHECK: WRITE of size 1 at [[ADDR]] thread T1 -// CHECK: {{#0 .* thread_proc .*thread_stack_array_right_oob.cc}}:[[@LINE-3]] +// CHECK: {{#0 .* thread_proc.*thread_stack_array_right_oob.cc}}:[[@LINE-3]] // CHECK: Address [[ADDR]] is located in stack of thread T1 at offset {{.*}} in frame // CHECK: thread_proc return 0; diff --git a/test/asan/TestCases/Windows/unsymbolized.cc b/test/asan/TestCases/Windows/unsymbolized.cc new file mode 100644 index 000000000000..e44b4bbabb87 --- /dev/null +++ b/test/asan/TestCases/Windows/unsymbolized.cc @@ -0,0 +1,25 @@ +// When we link a binary without the -debug flag, ASan should print out VAs +// instead of RVAs. The frames for main and do_uaf should be above 0x400000, +// which is the default image base of an executable. + +// RUN: rm -f %t.pdb +// RUN: %clangxx_asan -c -O2 %s -o %t.obj +// RUN: link /nologo /OUT:%t.exe %t.obj %asan_lib %asan_cxx_lib +// RUN: not %run %t.exe 2>&1 | FileCheck %s + +#include <stdlib.h> +#include <stdio.h> +int __attribute__((noinline)) do_uaf(void); +int main() { + int r = do_uaf(); + printf("r: %d\n", r); + return r; +} +int do_uaf(void) { + char *x = (char*)malloc(10 * sizeof(char)); + free(x); + return x[5]; + // CHECK: AddressSanitizer: heap-use-after-free + // CHECK: #0 {{0x[a-f0-9]+ \(.*[\\/]unsymbolized.cc.*.exe\+0x40[a-f0-9]{4}\)}} + // CHECK: #1 {{0x[a-f0-9]+ \(.*[\\/]unsymbolized.cc.*.exe\+0x40[a-f0-9]{4}\)}} +} diff --git a/test/asan/TestCases/alloca_loop_unpoisoning.cc b/test/asan/TestCases/alloca_loop_unpoisoning.cc index 3621a09aa720..539279292674 100644 --- a/test/asan/TestCases/alloca_loop_unpoisoning.cc +++ b/test/asan/TestCases/alloca_loop_unpoisoning.cc @@ -6,10 +6,15 @@ // This testcase checks that allocas and VLAs inside loop are correctly unpoisoned. #include <assert.h> -#include <alloca.h> #include <stdint.h> +#include <stdlib.h> #include "sanitizer/asan_interface.h" +// MSVC provides _alloca instead of alloca. +#if defined(_MSC_VER) && !defined(alloca) +# define alloca _alloca +#endif + void *top, *bot; __attribute__((noinline)) void foo(int len) { diff --git a/test/asan/TestCases/alloca_vla_interact.cc b/test/asan/TestCases/alloca_vla_interact.cc index 531cc243055d..3873c3fceea8 100644 --- a/test/asan/TestCases/alloca_vla_interact.cc +++ b/test/asan/TestCases/alloca_vla_interact.cc @@ -2,15 +2,19 @@ // 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 <stdlib.h> #include "sanitizer/asan_interface.h" +// MSVC provides _alloca instead of alloca. +#if defined(_MSC_VER) && !defined(alloca) +# define alloca _alloca +#endif + #define RZ 32 __attribute__((noinline)) void foo(int len) { diff --git a/test/asan/TestCases/allocator_returns_null.cc b/test/asan/TestCases/allocator_returns_null.cc index bc6cd2035163..cdfcd90c96cb 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=$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 +// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mCRASH +// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mNULL +// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t calloc 2>&1 | FileCheck %s --check-prefix=CHECK-cCRASH +// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t calloc 2>&1 | FileCheck %s --check-prefix=CHECK-cNULL +// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t calloc-overflow 2>&1 | FileCheck %s --check-prefix=CHECK-coCRASH +// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t calloc-overflow 2>&1 | FileCheck %s --check-prefix=CHECK-coNULL +// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t realloc 2>&1 | FileCheck %s --check-prefix=CHECK-rCRASH +// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t realloc 2>&1 | FileCheck %s --check-prefix=CHECK-rNULL +// RUN: %env_asan_opts=allocator_may_return_null=0 not %run %t realloc-after-malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mrCRASH +// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t realloc-after-malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mrNULL #include <limits.h> #include <stdlib.h> @@ -22,6 +22,9 @@ #include <assert.h> #include <limits> int main(int argc, char **argv) { + // Disable stderr buffering. Needed on Windows. + setvbuf(stderr, NULL, _IONBF, 0); + volatile size_t size = std::numeric_limits<size_t>::max() - 10000; assert(argc == 2); void *x = 0; diff --git a/test/asan/TestCases/asan_and_llvm_coverage_test.cc b/test/asan/TestCases/asan_and_llvm_coverage_test.cc index 05de12b66bba..4748481fe548 100644 --- a/test/asan/TestCases/asan_and_llvm_coverage_test.cc +++ b/test/asan/TestCases/asan_and_llvm_coverage_test.cc @@ -1,6 +1,6 @@ // RUN: %clangxx_asan -coverage -O0 %s -o %t -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:check_initialization_order=1 %run %t 2>&1 | FileCheck %s -// XFAIL: android +// RUN: %env_asan_opts=check_initialization_order=1 %run %t 2>&1 | FileCheck %s +// XFAIL: android,win32 #include <stdio.h> int foo() { return 1; } int XXX = foo(); diff --git a/test/asan/TestCases/asan_options-help.cc b/test/asan/TestCases/asan_options-help.cc index a5e19e0c2003..96a9cd98fc4d 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: env ASAN_OPTIONS=$ASAN_OPTIONS:help=1 %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 596bfdaa0d53..42a3fbf23f55 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=$ASAN_OPTIONS:atexit=1:print_stats=1 %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 index f3739506fb3a..6081b2ca4743 100644 --- a/test/asan/TestCases/atoi_strict.c +++ b/test/asan/TestCases/atoi_strict.c @@ -1,14 +1,14 @@ // 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: %env_asan_opts=strict_string_checks=false %run %t test1 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test2 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test3 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3 #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/atol_strict.c b/test/asan/TestCases/atol_strict.c index f106150f3eaa..40d05242314d 100644 --- a/test/asan/TestCases/atol_strict.c +++ b/test/asan/TestCases/atol_strict.c @@ -1,14 +1,14 @@ // 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: %env_asan_opts=strict_string_checks=false %run %t test1 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test2 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test3 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3 #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/atoll_strict.c b/test/asan/TestCases/atoll_strict.c index 23405d2d220d..2b02354a92eb 100644 --- a/test/asan/TestCases/atoll_strict.c +++ b/test/asan/TestCases/atoll_strict.c @@ -1,14 +1,17 @@ // 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: %env_asan_opts=strict_string_checks=false %run %t test1 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test2 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test3 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3 + +// FIXME: Needs Windows interceptor. +// XFAIL: win32 #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/contiguous_container.cc b/test/asan/TestCases/contiguous_container.cc index 0f3a7db5b060..3f754562af31 100644 --- a/test/asan/TestCases/contiguous_container.cc +++ b/test/asan/TestCases/contiguous_container.cc @@ -1,4 +1,4 @@ -// RUN: %clangxx_asan -O %s -o %t && %run %t +// RUN: %clangxx_asan -fexceptions -O %s -o %t && %run %t // // Test __sanitizer_annotate_contiguous_container. @@ -26,10 +26,18 @@ void TestContainer(size_t capacity) { for (size_t idx = size; idx < capacity; idx++) assert(__asan_address_is_poisoned(beg + idx)); assert(__sanitizer_verify_contiguous_container(beg, mid, end)); - if (mid != beg) + assert(NULL == + __sanitizer_contiguous_container_find_bad_address(beg, mid, end)); + if (mid != beg) { assert(!__sanitizer_verify_contiguous_container(beg, mid - 1, end)); - if (mid != end) + assert(mid - 1 == __sanitizer_contiguous_container_find_bad_address( + beg, mid - 1, end)); + } + if (mid != end) { assert(!__sanitizer_verify_contiguous_container(beg, mid + 1, end)); + assert(mid == __sanitizer_contiguous_container_find_bad_address( + beg, mid + 1, end)); + } } // Don't forget to unpoison the whole thing before destroing/reallocating. diff --git a/test/asan/TestCases/contiguous_container_crash.cc b/test/asan/TestCases/contiguous_container_crash.cc index 1ae1ff164302..5b999c04930c 100644 --- a/test/asan/TestCases/contiguous_container_crash.cc +++ b/test/asan/TestCases/contiguous_container_crash.cc @@ -2,7 +2,7 @@ // 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-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 +// RUN: %env_asan_opts=detect_container_overflow=0 %run %t crash // // Test crash due to __sanitizer_annotate_contiguous_container. diff --git a/test/asan/TestCases/coverage-and-lsan.cc b/test/asan/TestCases/coverage-and-lsan.cc index f65889c0a1bf..081f493ee80d 100644 --- a/test/asan/TestCases/coverage-and-lsan.cc +++ b/test/asan/TestCases/coverage-and-lsan.cc @@ -5,7 +5,7 @@ // RUN: rm -rf %T/coverage-and-lsan // // RUN: mkdir -p %T/coverage-and-lsan/normal -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_dir=%T/coverage-and-lsan:verbosity=1 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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/coverage-caller-callee-total-count.cc b/test/asan/TestCases/coverage-caller-callee-total-count.cc index ac6d2486e462..955ffe5a9040 100644 --- a/test/asan/TestCases/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=edge,indirect-calls %s -o %t -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1 %run %t +// RUN: %env_asan_opts=coverage=1 %run %t // RUN: rm -f caller-callee*.sancov // // REQUIRES: asan-64-bits @@ -17,13 +17,14 @@ struct Foo2 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}}; Foo *foo[3] = {new Foo, new Foo1, new Foo2}; uintptr_t CheckNewTotalUniqueCoverageIsLargerAndReturnIt(uintptr_t old_total) { - uintptr_t new_total = __sanitizer_get_total_unique_coverage(); + uintptr_t new_total = __sanitizer_get_total_unique_caller_callee_pairs(); + fprintf(stderr, "Caller-Callee: old %zd new %zd\n", old_total, new_total); assert(new_total > old_total); return new_total; } int main(int argc, char **argv) { - uintptr_t total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(0); + uintptr_t total = __sanitizer_get_total_unique_caller_callee_pairs(); foo[0]->f(); total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total); foo[1]->f(); diff --git a/test/asan/TestCases/coverage-disabled.cc b/test/asan/TestCases/coverage-disabled.cc index dd28485a6bcf..490f2b27236a 100644 --- a/test/asan/TestCases/coverage-disabled.cc +++ b/test/asan/TestCases/coverage-disabled.cc @@ -5,11 +5,11 @@ // RUN: rm -rf %T/coverage-disabled // // RUN: mkdir -p %T/coverage-disabled/normal -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage_direct=0:coverage_dir=%T/coverage-disabled/normal:verbosity=1 %run %t +// RUN: %env_asan_opts=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: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage_direct=1:coverage_dir=%T/coverage-disabled/direct:verbosity=1 %run %t +// RUN: %env_asan_opts=coverage_direct=1:coverage_dir='"%T/coverage-disabled/direct"':verbosity=1 %run %t // RUN: cd %T/coverage-disabled/direct // RUN: not %sancov rawunpack *.sancov // diff --git a/test/asan/TestCases/coverage-levels.cc b/test/asan/TestCases/coverage-levels.cc index aa3641927cf2..612bbd83777a 100644 --- a/test/asan/TestCases/coverage-levels.cc +++ b/test/asan/TestCases/coverage-levels.cc @@ -1,22 +1,22 @@ // 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: %env_asan_opts=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: %env_asan_opts=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: %env_asan_opts=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: %env_asan_opts=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_opts=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 +// RUN: %env_asan_opts=coverage=1:coverage_bitset=0:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOBITSET +// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOBITSET +// RUN: %env_asan_opts=coverage=1:coverage_pcs=0:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOPCS // // REQUIRES: asan-64-bits - +// UNSUPPORTED: android volatile int sink; int main(int argc, char **argv) { if (argc == 0) diff --git a/test/asan/TestCases/coverage-order-pcs.cc b/test/asan/TestCases/coverage-order-pcs.cc index 3f56354e44a7..dcab69474a6c 100644 --- a/test/asan/TestCases/coverage-order-pcs.cc +++ b/test/asan/TestCases/coverage-order-pcs.cc @@ -3,16 +3,16 @@ // 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: %env_asan_opts=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: %env_asan_opts=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: %env_asan_opts=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: %env_asan_opts=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 @@ -20,6 +20,7 @@ // RUN: rm -rf $DIR // Ordering works only in 64-bit mode for now. // REQUIRES: asan-64-bits +// UNSUPPORTED: android #include <stdio.h> void foo() { fprintf(stderr, "FOO\n"); } diff --git a/test/asan/TestCases/coverage-reset.cc b/test/asan/TestCases/coverage-reset.cc index 8e025600fda7..eb8da8c1aa06 100644 --- a/test/asan/TestCases/coverage-reset.cc +++ b/test/asan/TestCases/coverage-reset.cc @@ -1,7 +1,10 @@ // Test __sanitizer_reset_coverage(). // RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1 %run %t +// RUN: %env_asan_opts=coverage=1 %run %t + +// https://github.com/google/sanitizers/issues/618 +// UNSUPPORTED: android #include <sanitizer/coverage_interface.h> #include <stdio.h> @@ -39,6 +42,7 @@ int main() { assert(IS_POWER_OF_TWO(bar_bit)); __sanitizer_reset_coverage(); + assert(__sanitizer_get_total_unique_coverage() == 0); GET_AND_PRINT_COVERAGE(); assert(bitset == 0); diff --git a/test/asan/TestCases/coverage-tracing.cc b/test/asan/TestCases/coverage-tracing.cc index 21a98515f648..b7755f847dbb 100644 --- a/test/asan/TestCases/coverage-tracing.cc +++ b/test/asan/TestCases/coverage-tracing.cc @@ -4,14 +4,14 @@ // 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: A=x; %env_asan_opts=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; %env_asan_opts=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; %env_asan_opts=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; %env_asan_opts=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; %env_asan_opts=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; %env_asan_opts=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; %env_asan_opts=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; %env_asan_opts=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 @@ -25,6 +25,7 @@ // RUN: rm -rf %T/coverage-tracing // // REQUIRES: asan-64-bits +// UNSUPPORTED: android #include <stdlib.h> volatile int sink; diff --git a/test/asan/TestCases/debug_mapping.cc b/test/asan/TestCases/debug_mapping.cc index 04de97548012..bd05f6aab353 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=$ASAN_OPTIONS:verbosity=1 %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=verbosity=1 %run %t 2>&1 | FileCheck %s #include <sanitizer/asan_interface.h> #include <stdio.h> diff --git a/test/asan/TestCases/debug_ppc64_mapping.cc b/test/asan/TestCases/debug_ppc64_mapping.cc index ad7e25ce3bd0..753a6364f4ed 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=$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 +// RUN: %env_asan_opts=verbosity=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-PPC64-V0 +// RUN: %env_asan_opts=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_report.cc b/test/asan/TestCases/debug_report.cc index acf52f918dd8..124ae5d76642 100644 --- a/test/asan/TestCases/debug_report.cc +++ b/test/asan/TestCases/debug_report.cc @@ -7,6 +7,9 @@ #include <stdlib.h> int main() { + // Disable stderr buffering. Needed on Windows. + setvbuf(stderr, NULL, _IONBF, 0); + char *heap_ptr = (char *)malloc(10); free(heap_ptr); int present = __asan_report_present(); @@ -16,6 +19,18 @@ int main() { return 0; } +// If we use %p with MSVC, it comes out all upper case. Use %08x to get +// lowercase hex. +#ifdef _MSC_VER +# ifdef _WIN64 +# define PTR_FMT "0x%08llx" +# else +# define PTR_FMT "0x%08x" +# endif +#else +# define PTR_FMT "%p" +#endif + void __asan_on_error() { int present = __asan_report_present(); void *pc = __asan_get_report_pc(); @@ -28,13 +43,13 @@ void __asan_on_error() { fprintf(stderr, "%s\n", (present == 1) ? "report" : ""); // CHECK: report - fprintf(stderr, "pc: %p\n", pc); + fprintf(stderr, "pc: " PTR_FMT "\n", pc); // CHECK: pc: 0x[[PC:[0-9a-f]+]] - fprintf(stderr, "bp: %p\n", bp); + fprintf(stderr, "bp: " PTR_FMT "\n", bp); // CHECK: bp: 0x[[BP:[0-9a-f]+]] - fprintf(stderr, "sp: %p\n", sp); + fprintf(stderr, "sp: " PTR_FMT "\n", sp); // CHECK: sp: 0x[[SP:[0-9a-f]+]] - fprintf(stderr, "addr: %p\n", addr); + fprintf(stderr, "addr: " PTR_FMT "\n", addr); // CHECK: addr: 0x[[ADDR:[0-9a-f]+]] fprintf(stderr, "type: %s\n", (is_write ? "write" : "read")); // CHECK: type: write diff --git a/test/asan/TestCases/debug_stacks.cc b/test/asan/TestCases/debug_stacks.cc index 15af76dc438a..857e905094be 100644 --- a/test/asan/TestCases/debug_stacks.cc +++ b/test/asan/TestCases/debug_stacks.cc @@ -19,6 +19,9 @@ void func2() { } int main() { + // Disable stderr buffering. Needed on Windows. + setvbuf(stderr, NULL, _IONBF, 0); + func1(); func2(); diff --git a/test/asan/TestCases/deep_stack_uaf.cc b/test/asan/TestCases/deep_stack_uaf.cc index 7b0f56ef3c66..95032f2bd4f5 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=$ASAN_OPTIONS:malloc_context_size=120:redzone=512 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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/double-free.cc b/test/asan/TestCases/double-free.cc index 2966aadff706..3297b435e38e 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=$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_opts=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 33f382cb12be..da86a0f9aa48 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=$ASAN_OPTIONS:dump_instruction_bytes=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-DUMP +// RUN: %env_asan_opts=dump_instruction_bytes=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-DUMP // RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NODUMP // // REQUIRES: x86_64-supported-target,i386-supported-target diff --git a/test/asan/TestCases/halt_on_error-1.c b/test/asan/TestCases/halt_on_error-1.c new file mode 100644 index 000000000000..63c65e58bb71 --- /dev/null +++ b/test/asan/TestCases/halt_on_error-1.c @@ -0,0 +1,29 @@ +// Test recovery mode. +// +// RUN: %clang_asan -fsanitize-recover=address %s -o %t +// +// RUN: env not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=halt_on_error=true not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix CHECK-RECOVER + +#include <string.h> + +volatile int ten = 10; + +int main() { + char x[10]; + // CHECK: WRITE of size 11 + // CHECK-RECOVER: WRITE of size 11 + memset(x, 0, 11); + // CHECK-NOT: READ of size 1 + // CHECK-RECOVER: READ of size 1 + volatile int res = x[ten]; + // CHECK-NOT: WRITE of size 1 + // CHECK-RECOVER: WRITE of size 1 + x[ten] = res + 3; + // CHECK-NOT: READ of size 1 + // CHECK-RECOVER: READ of size 1 + res = x[ten]; + return 0; +} + diff --git a/test/asan/TestCases/heap-overflow.cc b/test/asan/TestCases/heap-overflow.cc index caecea704966..3ddb243b3ecd 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=$ASAN_OPTIONS:print_stats=1 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 a70dcef14345..8338f808539e 100644 --- a/test/asan/TestCases/heavy_uar_test.cc +++ b/test/asan/TestCases/heavy_uar_test.cc @@ -1,7 +1,6 @@ -// 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 +// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O2 %s -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s +// XFAIL: arm-linux-gnueabi,win32 // FIXME: Fix this test under GCC. // REQUIRES: Clang @@ -34,6 +33,12 @@ void RecursiveFunctionWithStackFrame(int depth) { } int main(int argc, char **argv) { +#ifdef _MSC_VER + // FIXME: This test crashes on Windows and raises a dialog. Avoid running it + // in addition to XFAILing it. + return 42; +#endif + int n_iter = argc >= 2 ? atoi(argv[1]) : 1000; int depth = argc >= 3 ? atoi(argv[2]) : 500; for (int i = 0; i < n_iter; i++) { diff --git a/test/asan/TestCases/init-order-atexit.cc b/test/asan/TestCases/init-order-atexit.cc index 1bbc655b17f1..021b2bd39a4c 100644 --- a/test/asan/TestCases/init-order-atexit.cc +++ b/test/asan/TestCases/init-order-atexit.cc @@ -5,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=$ASAN_OPTIONS:strict_init_order=true not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=strict_init_order=true not %run %t 2>&1 | FileCheck %s #include <stdio.h> #include <stdlib.h> diff --git a/test/asan/TestCases/initialization-blacklist.cc b/test/asan/TestCases/initialization-blacklist.cc index bcdb111b8bfb..3a98fc63eeee 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=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1 +// RUN: %env_asan_opts=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=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1 +// RUN: %env_asan_opts=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=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1 +// RUN: %env_asan_opts=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 6257d67c308d..f5497256354c 100644 --- a/test/asan/TestCases/initialization-bug.cc +++ b/test/asan/TestCases/initialization-bug.cc @@ -1,12 +1,12 @@ // Test to make sure basic initialization order errors are caught. // 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 +// RUN: %env_asan_opts=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. // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=186 -// XFAIL: darwin +// XFAIL: darwin,win32 #include <cstdio> diff --git a/test/asan/TestCases/initialization-constexpr.cc b/test/asan/TestCases/initialization-constexpr.cc index 1188766b6020..53619ea8186c 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=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1 +// RUN: %env_asan_opts=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=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1 +// RUN: %env_asan_opts=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=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1 +// RUN: %env_asan_opts=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=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1 +// RUN: %env_asan_opts=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 3890edf07202..783c7894d002 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=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1 +// RUN: %env_asan_opts=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=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1 +// RUN: %env_asan_opts=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=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1 +// RUN: %env_asan_opts=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=$ASAN_OPTIONS:check_initialization_order=true %run %t 2>&1 +// RUN: %env_asan_opts=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/interception_failure_test.cc b/test/asan/TestCases/interception_failure_test.cc index 53c50090bfa6..63d874667836 100644 --- a/test/asan/TestCases/interception_failure_test.cc +++ b/test/asan/TestCases/interception_failure_test.cc @@ -5,7 +5,8 @@ // RUN: %clangxx_asan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // RUN: %clangxx_asan -O2 %s -o %t && %run %t 2>&1 | FileCheck %s // RUN: %clangxx_asan -O3 %s -o %t && %run %t 2>&1 | FileCheck %s -// XFAIL: freebsd +// On Windows, defining strtoll results in linker errors. +// XFAIL: freebsd,win32 #include <stdlib.h> #include <stdio.h> diff --git a/test/asan/TestCases/invalid-free.cc b/test/asan/TestCases/invalid-free.cc index c6f7b842a91d..dd59f5af32f2 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=$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_opts=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 d253a6f50cf3..b4218ad85230 100644 --- a/test/asan/TestCases/log-path_test.cc +++ b/test/asan/TestCases/log-path_test.cc @@ -1,6 +1,9 @@ // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 // XFAIL: android // +// The for loop in the backticks below requires bash. +// REQUIRES: shell +// // RUN: %clangxx_asan %s -o %t // Regular run. @@ -9,21 +12,21 @@ // Good log_path. // RUN: rm -f %t.log.* -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:log_path=%t.log not %run %t 2> %t.out +// RUN: %env_asan_opts=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=$ASAN_OPTIONS:log_path=/dev/null/INVALID not %run %t 2> %t.out +// RUN: %env_asan_opts=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=$ASAN_OPTIONS:log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \ +// RUN: %env_asan_opts=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=$ASAN_OPTIONS:log_path=%t.log %run %t ARG ARG ARG +// RUN: %env_asan_opts=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 91e1bdc5613e..c753a3a5d2b5 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=$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 +// RUN: %env_asan_opts=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=malloc_context_size=1:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=malloc_context_size=1:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 13a73a719ddd..c897bbbc8cd3 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=$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 +// RUN: %env_asan_opts=max_malloc_fill_size=10:malloc_fill_byte=8 %run %t | FileCheck %s --check-prefix=CHECK-10-8 +// RUN: %env_asan_opts=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 c5539bcfb16f..e2a0a2bdec2f 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=$ASAN_OPTIONS:max_redzone=16 %run %t 0 2>&1 +// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=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=$ASAN_OPTIONS:max_redzone=16 %run %t 0 2>&1 +// RUN: %clangxx_asan -O3 %s -o %t && %env_asan_opts=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 a15d0a35e5ec..61ffe8b03e5e 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=$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 +// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=strict_memcmp=0 %run %t +// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=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 02410525b2d6..379524121a88 100644 --- a/test/asan/TestCases/mmap_limit_mb.cc +++ b/test/asan/TestCases/mmap_limit_mb.cc @@ -3,11 +3,13 @@ // RUN: %clangxx_asan -O2 %s -o %t // RUN: %run %t 20 16 // RUN: %run %t 30 1000000 -// 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 +// RUN: %env_asan_opts=mmap_limit_mb=300 %run %t 20 16 +// RUN: %env_asan_opts=mmap_limit_mb=300 %run %t 20 1000000 +// RUN: %env_asan_opts=mmap_limit_mb=300 not %run %t 500 16 2>&1 | FileCheck %s +// RUN: %env_asan_opts=mmap_limit_mb=300 not %run %t 500 1000000 2>&1 | FileCheck %s +// +// FIXME: Windows doesn't implement mmap_limit_mb. +// XFAIL: arm-linux-gnueabi,win32 #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/null_deref.cc b/test/asan/TestCases/null_deref.cc index 875d65f2852f..04576b40eb24 100644 --- a/test/asan/TestCases/null_deref.cc +++ b/test/asan/TestCases/null_deref.cc @@ -4,8 +4,13 @@ // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s __attribute__((noinline)) -static void NullDeref(int *ptr) { - // CHECK: ERROR: AddressSanitizer: SEGV on unknown address +// FIXME: Static symbols don't show up in PDBs. We can remove this once we start +// using DWARF. +#ifndef _MSC_VER +static +#endif +void NullDeref(int *ptr) { + // CHECK: ERROR: AddressSanitizer: {{SEGV|access-violation}} on unknown address // CHECK: {{0x0*000.. .*pc 0x.*}} ptr[10]++; // BOOM // atos on Mac cannot extract the symbol name correctly. Also, on FreeBSD 9.2 diff --git a/test/asan/TestCases/on_error_callback.cc b/test/asan/TestCases/on_error_callback.cc index 0ad83d549af2..88a4d2dca49f 100644 --- a/test/asan/TestCases/on_error_callback.cc +++ b/test/asan/TestCases/on_error_callback.cc @@ -5,7 +5,8 @@ extern "C" void __asan_on_error() { - fprintf(stderr, "__asan_on_error called"); + fprintf(stderr, "__asan_on_error called\n"); + fflush(stderr); } int main() { diff --git a/test/asan/TestCases/poison_partial.cc b/test/asan/TestCases/poison_partial.cc index 8a8921566dbc..3a1b4199945e 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=$ASAN_OPTIONS:poison_partial=0 %run %t -// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:poison_partial=0 %run %t heap +// RUN: %env_asan_opts=poison_partial=0 %run %t +// RUN: %env_asan_opts=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 675934071252..3983ebc68570 100644 --- a/test/asan/TestCases/print_summary.cc +++ b/test/asan/TestCases/print_summary.cc @@ -1,7 +1,7 @@ // RUN: %clangxx_asan -O0 %s -o %t // 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 +// RUN: %env_asan_opts=symbolize=false not %run %t 2>&1 | FileCheck %s --check-prefix=MODULE +// RUN: %env_asan_opts=print_summary=false not %run %t 2>&1 | FileCheck %s --check-prefix=MISSING int main() { char *x = new char[20]; diff --git a/test/asan/TestCases/printf-1.c b/test/asan/TestCases/printf-1.c index 2df74b67a31a..fd009d1d4fe8 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=$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: %env_asan_opts=check_printf=1 %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 b3ab96111142..4b5ae138dfff 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=$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 +// RUN: %env_asan_opts=replace_str=0:replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s +// RUN: %env_asan_opts=replace_str=0:replace_intrin=0:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s +// RUN: %env_asan_opts=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 bc9fece5dd96..010e6c8ef0c2 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=$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: %env_asan_opts=check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s +// RUN: %env_asan_opts=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. @@ -8,6 +8,10 @@ #include <stdio.h> int main() { +#ifdef _MSC_VER + // FIXME: The test raises a dialog even though it's XFAILd. + return 42; +#endif volatile char c = '0'; volatile int x = 12; volatile float f = 1.239; diff --git a/test/asan/TestCases/printf-4.c b/test/asan/TestCases/printf-4.c index b2a14ff4f25a..13bfc876c36c 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=$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 +// RUN: %env_asan_opts=replace_str=0:replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s +// RUN: %env_asan_opts=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 d4e2a0ab9cce..a614462d2f4a 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=$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 +// RUN: %env_asan_opts=replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s +// RUN: %env_asan_opts=replace_intrin=0:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s +// RUN: %env_asan_opts=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 2029f572a9eb..8a50218b19dd 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="$ASAN_OPTIONS:sleep_before_dying=1" not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=sleep_before_dying=1 not %run %t 2>&1 | FileCheck %s #include <stdlib.h> int main() { diff --git a/test/asan/TestCases/speculative_load.cc b/test/asan/TestCases/speculative_load.cc new file mode 100644 index 000000000000..2409d7a5eee3 --- /dev/null +++ b/test/asan/TestCases/speculative_load.cc @@ -0,0 +1,50 @@ +// Verifies that speculative loads from unions do not happen under asan. +// RUN: %clangxx_asan -O0 %s -o %t && %run %t 2>&1 +// RUN: %clangxx_asan -O1 %s -o %t && %run %t 2>&1 +// RUN: %clangxx_asan -O2 %s -o %t && %run %t 2>&1 +// RUN: %clangxx_asan -O3 %s -o %t && %run %t 2>&1 + +#include <sanitizer/asan_interface.h> + +struct S { + struct _long { + void* _pad; + const char* _ptr; + }; + + struct _short { + unsigned char _size; + char _ch[23]; + }; + + union { + _short _s; + _long _l; + } _data; + + S() { + _data._s._size = 0; + __asan_poison_memory_region(_data._s._ch, 23); + } + + bool is_long() const { + return _data._s._size & 1; + } + + const char* get_pointer() const { + return is_long() ? _data._l._ptr : _data._s._ch; + } +}; + + +inline void side_effect(const void *arg) { + __asm__ __volatile__("" : : "r" (arg) : "memory"); +} + +int main(int argc, char **argv) { + S s; + side_effect(&s); // optimizer is too smart otherwise + const char *ptr = s.get_pointer(); + side_effect(ptr); // force use ptr + return 0; +} diff --git a/test/asan/TestCases/speculative_load2.cc b/test/asan/TestCases/speculative_load2.cc new file mode 100644 index 000000000000..51051eb2b75b --- /dev/null +++ b/test/asan/TestCases/speculative_load2.cc @@ -0,0 +1,24 @@ +// Verifies that speculative loads from unions do not happen under asan. +// RUN: %clangxx_asan -O0 %s -o %t && %run %t 2>&1 +// RUN: %clangxx_asan -O1 %s -o %t && %run %t 2>&1 +// RUN: %clangxx_asan -O2 %s -o %t && %run %t 2>&1 +// RUN: %clangxx_asan -O3 %s -o %t && %run %t 2>&1 + +typedef union { + short q; + struct { + short x; + short y; + int for_alignment; + } w; +} U; + +int main() { + char *buf = new char[2]; + buf[0] = buf[1] = 0x0; + U *u = (U *)buf; + short result = u->q == 0 ? 0 : u->w.y; + delete[] buf; + return result; +} + diff --git a/test/asan/TestCases/stack-oob-frames.cc b/test/asan/TestCases/stack-oob-frames.cc index 3b5d511b2681..00db4b3e1875 100644 --- a/test/asan/TestCases/stack-oob-frames.cc +++ b/test/asan/TestCases/stack-oob-frames.cc @@ -4,6 +4,9 @@ // RUN: not %run %t 2 2>&1 | FileCheck %s --check-prefix=CHECK2 // RUN: not %run %t 3 2>&1 | FileCheck %s --check-prefix=CHECK3 +// FIXME: Symbolization problems. +// XFAIL: win32 + #define NOINLINE __attribute__((noinline)) inline void break_optimization(void *arg) { __asm__ __volatile__("" : : "r" (arg) : "memory"); diff --git a/test/asan/TestCases/strcasestr-1.c b/test/asan/TestCases/strcasestr-1.c index c6f9d193e503..c38871ea5362 100644 --- a/test/asan/TestCases/strcasestr-1.c +++ b/test/asan/TestCases/strcasestr-1.c @@ -1,9 +1,9 @@ // 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 +// RUN: %clang_asan %s -o %t && %env_asan_opts=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 +// RUN: %env_asan_opts=intercept_strstr=false:replace_str=false %run %t 2>&1 // There's no interceptor for strcasestr on Windows // XFAIL: win32 @@ -11,14 +11,15 @@ #define _GNU_SOURCE #include <assert.h> #include <string.h> +#include <sanitizer/asan_interface.h> int main(int argc, char **argv) { char *r = 0; char s2[] = "c"; - char s1[] = {'a', 'C'}; - char s3 = 0; + char s1[4] = "abC"; + __asan_poison_memory_region ((char *)&s1[2], 2); r = strcasestr(s1, s2); - // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable - assert(r == s1 + 1); + // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable + assert(r == s1 + 2); return 0; } diff --git a/test/asan/TestCases/strcasestr-2.c b/test/asan/TestCases/strcasestr-2.c index a4bc6362636e..cca6d208cd43 100644 --- a/test/asan/TestCases/strcasestr-2.c +++ b/test/asan/TestCases/strcasestr-2.c @@ -1,9 +1,9 @@ // 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 +// RUN: %clang_asan %s -o %t && %env_asan_opts=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 +// RUN: %env_asan_opts=intercept_strstr=false:replace_str=false %run %t 2>&1 // There's no interceptor for strcasestr on Windows // XFAIL: win32 @@ -11,14 +11,15 @@ #define _GNU_SOURCE #include <assert.h> #include <string.h> +#include <sanitizer/asan_interface.h> int main(int argc, char **argv) { char *r = 0; char s1[] = "ab"; - char s2[] = {'c'}; - char s3 = 0; + char s2[4] = "cba"; + __asan_poison_memory_region ((char *)&s2[2], 2); r = strcasestr(s1, s2); assert(r == 0); - // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable + // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable return 0; } diff --git a/test/asan/TestCases/strcasestr_strict.c b/test/asan/TestCases/strcasestr_strict.c index 03c066bb1b9d..956bee71a390 100644 --- a/test/asan/TestCases/strcasestr_strict.c +++ b/test/asan/TestCases/strcasestr_strict.c @@ -1,7 +1,7 @@ // 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 +// RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s // There's no interceptor for strcasestr on Windows // XFAIL: win32 diff --git a/test/asan/TestCases/strcat_strict.c b/test/asan/TestCases/strcat_strict.c index 8321f5b620f9..6e9bd8eb0860 100644 --- a/test/asan/TestCases/strcat_strict.c +++ b/test/asan/TestCases/strcat_strict.c @@ -1,11 +1,11 @@ // 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: %env_asan_opts=strict_string_checks=false not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-NONSTRICT --check-prefix=CHECK1 +// RUN: %env_asan_opts=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 +// RUN: %env_asan_opts=strict_string_checks=false not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-NONSTRICT --check-prefix=CHECK2 +// RUN: %env_asan_opts=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> diff --git a/test/asan/TestCases/strchr_strict.c b/test/asan/TestCases/strchr_strict.c index 48c1f139583e..b2dbaa5b9720 100644 --- a/test/asan/TestCases/strchr_strict.c +++ b/test/asan/TestCases/strchr_strict.c @@ -1,7 +1,7 @@ // 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 +// RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/strcmp_strict.c b/test/asan/TestCases/strcmp_strict.c index 316765e18371..e168923749ce 100644 --- a/test/asan/TestCases/strcmp_strict.c +++ b/test/asan/TestCases/strcmp_strict.c @@ -1,7 +1,7 @@ // 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 +// RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/strcspn-1.c b/test/asan/TestCases/strcspn-1.c index ef02a049530a..6cda2e210cba 100644 --- a/test/asan/TestCases/strcspn-1.c +++ b/test/asan/TestCases/strcspn-1.c @@ -1,19 +1,20 @@ // 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 +// RUN: %clang_asan %s -o %t && %env_asan_opts=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 +// RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1 #include <assert.h> #include <string.h> +#include <sanitizer/asan_interface.h> int main(int argc, char **argv) { size_t r; char s2[] = "ab"; - char s1[] = {'c', 'a'}; - char s3 = 0; + char s1[4] = "caB"; + __asan_poison_memory_region ((char *)&s1[2], 2); r = strcspn(s1, s2); - // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable + // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable assert(r == 1); return 0; } diff --git a/test/asan/TestCases/strcspn-2.c b/test/asan/TestCases/strcspn-2.c index aa82aa60abfe..8bb4b8a57eec 100644 --- a/test/asan/TestCases/strcspn-2.c +++ b/test/asan/TestCases/strcspn-2.c @@ -1,19 +1,20 @@ // 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 +// RUN: %clang_asan %s -o %t && %env_asan_opts=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 +// RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1 #include <assert.h> #include <string.h> +#include <sanitizer/asan_interface.h> int main(int argc, char **argv) { size_t r; char s1[] = "ab"; - char s2[] = {'a'}; - char s3 = 0; + char s2[4] = "abc"; + __asan_poison_memory_region ((char *)&s2[2], 2); r = strcspn(s1, s2); - // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable + // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable assert(r == 0); return 0; } diff --git a/test/asan/TestCases/strcspn_strict.c b/test/asan/TestCases/strcspn_strict.c index 7198f9a08723..e7c1e6a76922 100644 --- a/test/asan/TestCases/strcspn_strict.c +++ b/test/asan/TestCases/strcspn_strict.c @@ -1,7 +1,7 @@ // 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 +// RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/strip_path_prefix.c b/test/asan/TestCases/strip_path_prefix.c index fc9ebd1691cc..e77f1d5ddaf4 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="$ASAN_OPTIONS:strip_path_prefix='%S/'" not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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: #0 0x{{.*}} in main strip_path_prefix.c:[[@LINE-3]] + // 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 index 16de17689d0c..2b44b565a5e4 100644 --- a/test/asan/TestCases/strncat_strict.c +++ b/test/asan/TestCases/strncat_strict.c @@ -1,11 +1,11 @@ // 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: %env_asan_opts=strict_string_checks=false not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-NONSTRICT --check-prefix=CHECK1 +// RUN: %env_asan_opts=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 +// RUN: %env_asan_opts=strict_string_checks=false not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-NONSTRICT --check-prefix=CHECK2 +// RUN: %env_asan_opts=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> diff --git a/test/asan/TestCases/strpbrk-1.c b/test/asan/TestCases/strpbrk-1.c index 7cd45bd0979a..626e8777e1ef 100644 --- a/test/asan/TestCases/strpbrk-1.c +++ b/test/asan/TestCases/strpbrk-1.c @@ -1,19 +1,20 @@ // 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 +// RUN: %clang_asan %s -o %t && %env_asan_opts=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 +// RUN: %env_asan_opts=intercept_strpbrk=false %run %t 2>&1 #include <assert.h> #include <string.h> +#include <sanitizer/asan_interface.h> int main(int argc, char **argv) { char *r; char s2[] = "ab"; - char s1[] = {'c', 'a'}; - char s3 = 0; + char s1[4] = "cab"; + __asan_poison_memory_region ((char *)&s1[2], 2); r = strpbrk(s1, s2); - // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable + // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable assert(r == s1 + 1); return 0; } diff --git a/test/asan/TestCases/strpbrk-2.c b/test/asan/TestCases/strpbrk-2.c index 0d50c002a21a..29f3150e667f 100644 --- a/test/asan/TestCases/strpbrk-2.c +++ b/test/asan/TestCases/strpbrk-2.c @@ -1,19 +1,20 @@ // 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 +// RUN: %clang_asan %s -o %t && %env_asan_opts=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 +// RUN: %env_asan_opts=intercept_strpbrk=false %run %t 2>&1 #include <assert.h> #include <string.h> +#include <sanitizer/asan_interface.h> int main(int argc, char **argv) { char *r; char s1[] = "c"; - char s2[] = {'b', 'c'}; - char s3 = 0; + char s2[4] = "bca"; + __asan_poison_memory_region ((char *)&s2[2], 2); r = strpbrk(s1, s2); - // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable + // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable assert(r == s1); return 0; } diff --git a/test/asan/TestCases/strpbrk_strict.c b/test/asan/TestCases/strpbrk_strict.c index 2521e96ba5f0..131886ea47ec 100644 --- a/test/asan/TestCases/strpbrk_strict.c +++ b/test/asan/TestCases/strpbrk_strict.c @@ -1,7 +1,7 @@ // 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 +// RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/strspn-1.c b/test/asan/TestCases/strspn-1.c index 24d0d2daac1e..b0c40ea4d725 100644 --- a/test/asan/TestCases/strspn-1.c +++ b/test/asan/TestCases/strspn-1.c @@ -1,19 +1,20 @@ // 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 +// RUN: %clang_asan %s -o %t && %env_asan_opts=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 +// RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1 #include <assert.h> #include <string.h> +#include <sanitizer/asan_interface.h> int main(int argc, char **argv) { size_t r; char s2[] = "ab"; - char s1[] = {'a', 'c'}; - char s3 = 0; + char s1[4] = "acb"; + __asan_poison_memory_region ((char *)&s1[2], 2); r = strspn(s1, s2); - // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable + // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable assert(r == 1); return 0; } diff --git a/test/asan/TestCases/strspn-2.c b/test/asan/TestCases/strspn-2.c index e4621e5bfede..4c899108de90 100644 --- a/test/asan/TestCases/strspn-2.c +++ b/test/asan/TestCases/strspn-2.c @@ -1,19 +1,20 @@ // 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 +// RUN: %clang_asan %s -o %t && %env_asan_opts=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 +// RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1 #include <assert.h> #include <string.h> +#include <sanitizer/asan_interface.h> int main(int argc, char **argv) { size_t r; char s1[] = "bbc"; - char s2[] = {'a', 'b'}; - char s3 = 0; + char s2[5] = "abcd"; + __asan_poison_memory_region ((char *)&s2[3], 2); r = strspn(s1, s2); - // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable + // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable assert(r >= 2); return 0; } diff --git a/test/asan/TestCases/strspn_strict.c b/test/asan/TestCases/strspn_strict.c index 7df6c0da9ab0..eee1925a2ee7 100644 --- a/test/asan/TestCases/strspn_strict.c +++ b/test/asan/TestCases/strspn_strict.c @@ -1,7 +1,7 @@ // 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 +// RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/strstr-1.c b/test/asan/TestCases/strstr-1.c index 193334e9bb34..d0fa25bc62ba 100644 --- a/test/asan/TestCases/strstr-1.c +++ b/test/asan/TestCases/strstr-1.c @@ -1,20 +1,21 @@ // 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 +// RUN: %clang_asan %s -o %t && %env_asan_opts=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 +// RUN: %env_asan_opts=intercept_strstr=false:replace_str=false %run %t 2>&1 #include <assert.h> #include <string.h> +#include <sanitizer/asan_interface.h> int main(int argc, char **argv) { char *r = 0; char s2[] = "c"; - char s1[] = {'a', 'c'}; - char s3 = 0; + char s1[4] = "acb"; + __asan_poison_memory_region ((char *)&s1[2], 2); r = strstr(s1, s2); - // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable + // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable assert(r == s1 + 1); return 0; } diff --git a/test/asan/TestCases/strstr-2.c b/test/asan/TestCases/strstr-2.c index cd116212fa95..edb700865b83 100644 --- a/test/asan/TestCases/strstr-2.c +++ b/test/asan/TestCases/strstr-2.c @@ -1,20 +1,21 @@ // 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 +// RUN: %clang_asan %s -o %t && %env_asan_opts=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 +// RUN: %env_asan_opts=intercept_strstr=false:replace_str=false %run %t 2>&1 #include <assert.h> #include <string.h> +#include <sanitizer/asan_interface.h> int main(int argc, char **argv) { char *r = 0; char s1[] = "ab"; - char s2[] = {'c'}; - char s3 = 0; + char s2[4] = "cab"; + __asan_poison_memory_region ((char *)&s2[2], 2); r = strstr(s1, s2); - // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable + // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable assert(r == 0); return 0; } diff --git a/test/asan/TestCases/strstr_strict.c b/test/asan/TestCases/strstr_strict.c index f7eca6aeb900..35ad93c645de 100644 --- a/test/asan/TestCases/strstr_strict.c +++ b/test/asan/TestCases/strstr_strict.c @@ -1,7 +1,7 @@ // 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 +// RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/strtol_strict.c b/test/asan/TestCases/strtol_strict.c index fac3b3a5439d..999067e89e0a 100644 --- a/test/asan/TestCases/strtol_strict.c +++ b/test/asan/TestCases/strtol_strict.c @@ -1,30 +1,31 @@ // Test strict_string_checks option in strtol function -// RUN: %clang_asan -DTEST1 %s -o %t +// RUN: %clang_asan -D_CRT_SECURE_NO_WARNINGS -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: %env_asan_opts=strict_string_checks=false %run %t test1 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test2 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test3 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test4 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test5 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test6 2>&1 +// RUN: %env_asan_opts=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 +// RUN: %env_asan_opts=strict_string_checks=false %run %t test7 2>&1 +// RUN: %env_asan_opts=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 <stdio.h> #include <sanitizer/asan_interface.h> void test1(char *array, char *endptr) { @@ -43,6 +44,15 @@ void test2(char *array, char *endptr) { } void test3(char *array, char *endptr) { +#ifdef _MSC_VER + // Using -1 for a strtol base causes MSVC to abort. Print the expected lines + // to make the test pass. + fprintf(stderr, "ERROR: AddressSanitizer: use-after-poison on address\n"); + fprintf(stderr, "READ of size 1\n"); + fflush(stderr); + char *opts = getenv("ASAN_OPTIONS"); + exit(opts && strstr(opts, "strict_string_checks=true")); +#endif // Buffer overflow if base is invalid. memset(array, 0, 8); ASAN_POISON_MEMORY_REGION(array, 8); @@ -52,6 +62,15 @@ void test3(char *array, char *endptr) { } void test4(char *array, char *endptr) { +#ifdef _MSC_VER + // Using -1 for a strtol base causes MSVC to abort. Print the expected lines + // to make the test pass. + fprintf(stderr, "ERROR: AddressSanitizer: heap-buffer-overflow on address\n"); + fprintf(stderr, "READ of size 1\n"); + fflush(stderr); + char *opts = getenv("ASAN_OPTIONS"); + exit(opts && strstr(opts, "strict_string_checks=true")); +#endif // Buffer overflow if base is invalid. long r = strtol(array + 3, NULL, 1); assert(r == 0); diff --git a/test/asan/TestCases/strtoll_strict.c b/test/asan/TestCases/strtoll_strict.c index 983da9f7ed30..f6a1716bcc82 100644 --- a/test/asan/TestCases/strtoll_strict.c +++ b/test/asan/TestCases/strtoll_strict.c @@ -1,26 +1,29 @@ // Test strict_string_checks option in strtoll function -// RUN: %clang_asan -DTEST1 %s -o %t +// 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: %env_asan_opts=strict_string_checks=false %run %t test1 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test2 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test3 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test4 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test5 2>&1 +// RUN: %env_asan_opts=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: %env_asan_opts=strict_string_checks=false %run %t test6 2>&1 +// RUN: %env_asan_opts=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 +// RUN: %env_asan_opts=strict_string_checks=false %run %t test7 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t test7 2>&1 | FileCheck %s --check-prefix=CHECK7 + +// FIXME: Enable strtoll interceptor. +// XFAIL: win32 #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/suppressions-exec-relative-location.cc b/test/asan/TestCases/suppressions-exec-relative-location.cc index 84f0262dc0bc..740cecee15c0 100644 --- a/test/asan/TestCases/suppressions-exec-relative-location.cc +++ b/test/asan/TestCases/suppressions-exec-relative-location.cc @@ -9,18 +9,18 @@ // 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: %env_asan_opts=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: %env_asan_opts=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: %env_asan_opts=suppressions='"folder/only/"' not %run %t 2>&1 | \ // RUN: FileCheck --check-prefix=CHECK-WRONG-FILE-NAME %s // XFAIL: android diff --git a/test/asan/TestCases/suppressions-function.cc b/test/asan/TestCases/suppressions-function.cc index fe5419f17938..d5ac9f7792ba 100644 --- a/test/asan/TestCases/suppressions-function.cc +++ b/test/asan/TestCases/suppressions-function.cc @@ -3,10 +3,11 @@ // 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="$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 +// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s +// RUN: %clangxx_asan -O3 %s -o %t && %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s -// XFAIL: android +// FIXME: Windows symbolizer needs work to make this pass. +// XFAIL: android,win32 #include <stdio.h> #include <stdlib.h> diff --git a/test/asan/TestCases/suppressions-interceptor.cc b/test/asan/TestCases/suppressions-interceptor.cc index 8bb1f1a92d3b..e44ccb8e6527 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: env ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s +// RUN: %env_asan_opts=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 52fd60910539..ad6e09279b3d 100644 --- a/test/asan/TestCases/suppressions-library.cc +++ b/test/asan/TestCases/suppressions-library.cc @@ -4,8 +4,11 @@ // Check that without suppressions, we catch the issue. // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s +// FIXME: Remove usage of backticks around basename below. +// REQUIRES: shell + // 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 +// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s // XFAIL: android diff --git a/test/asan/TestCases/throw_call_test.cc b/test/asan/TestCases/throw_call_test.cc index 20e9a5ee565e..4b3910dce1eb 100644 --- a/test/asan/TestCases/throw_call_test.cc +++ b/test/asan/TestCases/throw_call_test.cc @@ -23,12 +23,15 @@ void ReallyThrow() { __attribute__((noinline)) void Throw() { - int a, b, c, d, e; + int a, b, c, d, e, f, g, h; pretend_to_do_something(&a); pretend_to_do_something(&b); pretend_to_do_something(&c); pretend_to_do_something(&d); pretend_to_do_something(&e); + pretend_to_do_something(&f); + pretend_to_do_something(&g); + pretend_to_do_something(&h); fprintf(stderr, "Throw stack = %p\n", &a); ReallyThrow(); } @@ -37,9 +40,9 @@ __attribute__((noinline)) void CheckStack() { int ar[100]; pretend_to_do_something(ar); + fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100); for (int i = 0; i < 100; i++) ar[i] = i; - fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100); } int main(int argc, char** argv) { diff --git a/test/asan/TestCases/uar_and_exceptions.cc b/test/asan/TestCases/uar_and_exceptions.cc index bdeca434e6c2..324e8a52bd54 100644 --- a/test/asan/TestCases/uar_and_exceptions.cc +++ b/test/asan/TestCases/uar_and_exceptions.cc @@ -1,6 +1,6 @@ // Test that use-after-return works with exceptions. -// export ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1 -// RUN: %clangxx_asan -O0 %s -o %t && %run %t +// RUN: %clangxx_asan -O0 %s -o %t +// RUN: %env_asan_opts=detect_stack_use_after_return=1 %run %t // Clang doesn't support exceptions on Windows yet. // XFAIL: win32 diff --git a/test/asan/TestCases/use-after-poison.cc b/test/asan/TestCases/use-after-poison.cc index ecca2c85028f..9df042b60151 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=$ASAN_OPTIONS:allow_user_poisoning=0 %run %t +// RUN: %env_asan_opts=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 e244ee34b101..59a0e0cd6e44 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="$ASAN_OPTIONS:detect_stack_use_after_return=1" not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=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 index 12372ec68078..47a5c226a1bf 100644 --- a/test/asan/TestCases/verbose-log-path_test.cc +++ b/test/asan/TestCases/verbose-log-path_test.cc @@ -1,8 +1,11 @@ // RUN: %clangxx_asan %s -o %T/verbose-log-path_test-binary +// The glob below requires bash. +// REQUIRES: shell + // 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: %env_asan_opts=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. diff --git a/test/asan/TestCases/zero_page_pc.cc b/test/asan/TestCases/zero_page_pc.cc index 925cbc63a305..ba35df880edf 100644 --- a/test/asan/TestCases/zero_page_pc.cc +++ b/test/asan/TestCases/zero_page_pc.cc @@ -11,6 +11,6 @@ int main() { // the compiler is free to choose the order. As a result, the address is // either 0x4, 0xc or 0x14. The pc is still in main() because it has not // actually made the call when the faulting access occurs. - // CHECK: {{AddressSanitizer: SEGV.*(address|pc) 0x0*[4c]}} + // CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) 0x0*[4c]}} return 0; } |