diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:05:08 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:05:08 +0000 |
commit | 0646903fc1f75f6e605754621119473ee083f4a4 (patch) | |
tree | 57bce79a7423a054cccec23bdf6cd96e2d271b4a /test | |
parent | 005b7ed8f76756d94ef6266ded755ab7863cb936 (diff) | |
download | src-test2-f0e521381486bc5a6c3d35e6136690492889ae2f.tar.gz src-test2-f0e521381486bc5a6c3d35e6136690492889ae2f.zip |
Diffstat (limited to 'test')
417 files changed, 9475 insertions, 826 deletions
diff --git a/test/.clang-format b/test/.clang-format new file mode 100644 index 000000000000..4799b66f3e9a --- /dev/null +++ b/test/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: LLVM +ColumnLimit: 0 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 554ba5fa0f0e..2e239d54e29c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,8 +15,6 @@ if(COMPILER_RT_BUILD_PROFILE AND COMPILER_RT_HAS_PROFILE) endif() if(COMPILER_RT_STANDALONE_BUILD) - add_executable(FileCheck IMPORTED GLOBAL) - set_property(TARGET FileCheck PROPERTY IMPORTED_LOCATION ${LLVM_TOOLS_BINARY_DIR}/FileCheck) list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS FileCheck) endif() diff --git a/test/asan/CMakeLists.txt b/test/asan/CMakeLists.txt index e6d1df5e039a..6c22ef3b10ef 100644 --- a/test/asan/CMakeLists.txt +++ b/test/asan/CMakeLists.txt @@ -56,7 +56,7 @@ foreach(arch ${ASAN_TEST_ARCH}) string(TOLOWER "-${arch}-${OS_NAME}" ASAN_TEST_CONFIG_SUFFIX) get_bits_for_arch(${arch} ASAN_TEST_BITS) get_test_cc_for_arch(${arch} ASAN_TEST_TARGET_CC ASAN_TEST_TARGET_CFLAGS) - if(ANDROID) + if(ANDROID OR APPLE) set(ASAN_TEST_DYNAMIC True) else() set(ASAN_TEST_DYNAMIC False) diff --git a/test/asan/TestCases/Darwin/init_for_dlopen.cc b/test/asan/TestCases/Darwin/init_for_dlopen.cc new file mode 100644 index 000000000000..8a0fbf943b67 --- /dev/null +++ b/test/asan/TestCases/Darwin/init_for_dlopen.cc @@ -0,0 +1,46 @@ +// RUN: %clangxx -g -O0 %s -o %t + +// Check that trying to dlopen() the ASan dylib fails. +// We explictly set `abort_on_error=0` because +// - By default the lit config sets this but we don't want this +// test to implicitly depend on this. +// - It avoids requiring `--crash` to be passed to `not`. +// RUN: APPLE_ASAN_INIT_FOR_DLOPEN=0 %env_asan_opts=abort_on_error=0 not \ +// RUN: %run %t %shared_libasan 2>&1 | \ +// RUN: FileCheck -check-prefix=CHECK-DL-OPEN-FAIL %s +// RUN: env -u APPLE_ASAN_INIT_FOR_DLOPEN %env_asan_opts=abort_on_error=0 not \ +// RUN: %run %t %shared_libasan 2>&1 | \ +// RUN: FileCheck -check-prefix=CHECK-DL-OPEN-FAIL %s + +// Check that we can successfully dlopen the ASan dylib when we set the right +// environment variable. +// RUN: env APPLE_ASAN_INIT_FOR_DLOPEN=1 %run %t %shared_libasan 2>&1 | \ +// RUN: FileCheck -check-prefix=CHECK-DL-OPEN-SUCCESS %s + +#include <dlfcn.h> +#include <stdio.h> + +// CHECK-DL-OPEN-FAIL: ERROR: Interceptors are not working + +int main(int argc, char **argv) { + if (argc != 2) { + fprintf(stderr, "Usage: %s <dylib_path>\n", argv[0]); + return 1; + } + const char *dylib_path = argv[1]; + void *handle = dlopen(dylib_path, RTLD_LAZY); + if (!handle) { + fprintf(stderr, "Failed to dlopen: %s\n", dlerror()); + return 1; + } + // Make sure we can find a function we expect to be in the dylib. + void *fn = dlsym(handle, "__sanitizer_mz_size"); + if (!fn) { + fprintf(stderr, "Failed to get symbol: %s\n", dlerror()); + return 1; + } + // TODO(dliew): Actually call a function from the dylib that is safe to call. + // CHECK-DL-OPEN-SUCCESS: DONE + printf("DONE\n"); + return 0; +} diff --git a/test/asan/TestCases/Darwin/odr-lto.cc b/test/asan/TestCases/Darwin/odr-lto.cc index 56dd89b164c2..e1e454be077f 100644 --- a/test/asan/TestCases/Darwin/odr-lto.cc +++ b/test/asan/TestCases/Darwin/odr-lto.cc @@ -1,4 +1,4 @@ -// Check that -asan-use-private-alias and use_odr_indicator=1 silence the false +// Check that -asan-use-private-alias silence the false // positive ODR violation on Darwin with LTO. // REQUIRES: lto @@ -6,7 +6,7 @@ // RUN: %clangxx_asan -DPART=0 -c %s -o %t-1.o -flto -mllvm -asan-use-private-alias // RUN: %clangxx_asan -DPART=1 -c %s -o %t-2.o -flto -mllvm -asan-use-private-alias // RUN: %clangxx_asan %t-1.o %t-2.o -o %t -flto -// RUN: %env_asan_opts=use_odr_indicator=1 %run %t 2>&1 | FileCheck %s +// RUN: %run %t 2>&1 | FileCheck %s #include <stdio.h> #include <stdlib.h> diff --git a/test/asan/TestCases/Darwin/segv_read_write.c b/test/asan/TestCases/Darwin/segv_read_write.c index d8e2d215f832..127365d2f09c 100644 --- a/test/asan/TestCases/Darwin/segv_read_write.c +++ b/test/asan/TestCases/Darwin/segv_read_write.c @@ -9,11 +9,8 @@ static volatile int sink; __attribute__((noinline)) void Read(int *ptr) { sink = *ptr; } __attribute__((noinline)) void Write(int *ptr) { *ptr = 0; } int main(int argc, char **argv) { - // Writes to shadow are detected as reads from shadow gap (because of how the - // shadow mapping works). This is kinda hard to fix. Test a random address in - // the application part of the address space. void *volatile p = - mmap(nullptr, 4096, PROT_READ, MAP_PRIVATE | MAP_ANON, 0, 0); + mmap(nullptr, 4096, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0); munmap(p, 4096); if (argc == 1) Read((int *)p); diff --git a/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc b/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc index 4c935e2b0f3b..6328cbb2ce81 100644 --- a/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc +++ b/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc @@ -1,8 +1,8 @@ // Test that mixed static/dynamic sanitization of program objects // is prohibited. // -// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so -// RUN: %clangxx_asan_static %s %t.so -o %t +// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib +// RUN: %clangxx_asan_static %s %ld_flags_rpath_exe -o %t // RUN: not %run %t 2>&1 | FileCheck %s // REQUIRES: asan-dynamic-runtime diff --git a/test/asan/TestCases/Linux/coverage-missing.cc b/test/asan/TestCases/Linux/coverage-missing.cc index 32aada645deb..10acef9af4b0 100644 --- a/test/asan/TestCases/Linux/coverage-missing.cc +++ b/test/asan/TestCases/Linux/coverage-missing.cc @@ -45,7 +45,15 @@ // RUN: diff bar.txt foo-missing.txt > %t.log || true // RUN: not grep "^<" %t.log -// REQUIRES: x86-target-arch +// FIXME %sancov GetInstrumentedPCs relies on objdump -d to +// obtain the number of instrumented PCs. The i386 +// %dynamiclib has .plt entries that are not recognized by +// objdump, +// "sancov.py: found 0 instrumented PCs in *.so", +// causing AddressSanitizer-i386-linux to fail. +// Change it back to x86-target-arch after %sancov switches to a more robust approach. + +// REQUIRES: x86_64-target-arch // XFAIL: android #include <stdio.h> diff --git a/test/asan/TestCases/Linux/local_alias.cc b/test/asan/TestCases/Linux/local_alias.cc index 266d3fe6bc8f..a8b3d75e375b 100644 --- a/test/asan/TestCases/Linux/local_alias.cc +++ b/test/asan/TestCases/Linux/local_alias.cc @@ -4,14 +4,11 @@ // false positive global-buffer-overflow due to sanitized library poisons // globals from non-sanitized one. // -// FIXME: https://github.com/google/sanitizers/issues/316 -// XFAIL: android -// -// RUN: %clangxx_asan -DBUILD_INSTRUMENTED_DSO=1 -fPIC -shared -mllvm -asan-use-private-alias %s -o %t-INSTRUMENTED-SO.so -// RUN: %clangxx -DBUILD_UNINSTRUMENTED_DSO=1 -fPIC -shared %s -o %t-UNINSTRUMENTED-SO.so +// RUN: %clangxx_asan -DBUILD_INSTRUMENTED_DSO=1 -fPIC -shared -mllvm -asan-use-private-alias %s -o %dynamiclib1 +// RUN: %clangxx -DBUILD_UNINSTRUMENTED_DSO=1 -fPIC -shared %s -o %dynamiclib2 // RUN: %clangxx %s -c -mllvm -asan-use-private-alias -o %t.o -// RUN: %clangxx_asan %t.o %t-UNINSTRUMENTED-SO.so %t-INSTRUMENTED-SO.so -o %t-EXE -// RUN: %env_asan_opts=use_odr_indicator=true %run %t-EXE +// RUN: %clangxx_asan %t.o %ld_flags_rpath_exe2 %ld_flags_rpath_exe1 -o %t-EXE +// RUN: %run %t-EXE #if defined (BUILD_INSTRUMENTED_DSO) long h = 15; diff --git a/test/asan/TestCases/Linux/new_delete_mismatch.cc b/test/asan/TestCases/Linux/new_delete_mismatch.cc index 3a71862fb732..05f74bda7549 100644 --- a/test/asan/TestCases/Linux/new_delete_mismatch.cc +++ b/test/asan/TestCases/Linux/new_delete_mismatch.cc @@ -14,3 +14,4 @@ int main() { } // CHECK: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs operator delete) on 0x +// CHECK: is located 0 bytes inside of 10-byte region diff --git a/test/asan/TestCases/Linux/new_delete_mismatch_global.cc b/test/asan/TestCases/Linux/new_delete_mismatch_global.cc new file mode 100644 index 000000000000..3f1a78715caf --- /dev/null +++ b/test/asan/TestCases/Linux/new_delete_mismatch_global.cc @@ -0,0 +1,16 @@ +// Check that we report delete on a memory that belongs to a global variable. + +// RUN: %clangxx_asan -g %s -o %t && %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s + +#include <stdlib.h> + +static volatile char *x; +char a[10]; + +int main() { + x = &a[0]; + delete x; +} + +// CHECK: AddressSanitizer: attempting free on address which was not malloc()-ed +// CHECK: is located 0 bytes inside of global variable 'a' defined in diff --git a/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc b/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc new file mode 100644 index 000000000000..bbf07cc21380 --- /dev/null +++ b/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc @@ -0,0 +1,17 @@ +// Check that we report delete on a memory that belongs to a stack variable. + +// RUN: %clangxx_asan -g %s -o %t && %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s + +#include <stdlib.h> + +static volatile char *x; + +int main() { + char a[10]; + x = &a[0]; + delete x; +} + +// CHECK: AddressSanitizer: attempting free on address which was not malloc()-ed +// CHECK: is located in stack of thread T0 at offset +// CHECK: 'a'{{.*}} <== Memory access at offset {{16|32}} is inside this variable diff --git a/test/asan/TestCases/Linux/odr-violation.cc b/test/asan/TestCases/Linux/odr-violation.cc index 70437a8321b9..a1941fcc8d7a 100644 --- a/test/asan/TestCases/Linux/odr-violation.cc +++ b/test/asan/TestCases/Linux/odr-violation.cc @@ -5,15 +5,15 @@ // pointers. This setting is not on by default because it's too expensive. // // Different size: detect a bug if detect_odr_violation>=1 -// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so -// RUN: %clangxx_asan %s %t-ODR-SO.so -Wl,-R. -o %t-ODR-EXE +// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib +// RUN: %clangxx_asan %s %ld_flags_rpath_exe -o %t-ODR-EXE // 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: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %dynamiclib -DSZ=100 // 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 @@ -23,12 +23,20 @@ // 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 // +// Use private aliases for global variables without indicator symbol. +// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-private-alias %s -o %dynamiclib -DSZ=100 +// RUN: %clangxx_asan -mllvm -asan-use-private-alias %s %ld_flags_rpath_exe -o %t-ODR-EXE +// RUN: %env_asan_opts=fast_unwind_on_malloc=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED + // Use private aliases for global variables: use indicator symbol to detect ODR violation. -// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-private-alias %s -o %t-ODR-SO.so -DSZ=100 -// RUN: %clangxx_asan -mllvm -asan-use-private-alias %s %t-ODR-SO.so -Wl,-R. -o %t-ODR-EXE -// RUN: %env_asan_opts=fast_unwind_on_malloc=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED -// RUN: %env_asan_opts=fast_unwind_on_malloc=0:use_odr_indicator=false %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED -// RUN: %env_asan_opts=fast_unwind_on_malloc=0:use_odr_indicator=true not %run %t-ODR-EXE 2>&1 | FileCheck %s +// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared -mllvm -asan-use-private-alias -mllvm -asan-use-odr-indicator %s -o %dynamiclib -DSZ=100 +// RUN: %clangxx_asan -mllvm -asan-use-private-alias -mllvm -asan-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE +// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s + +// Same as above but with clang switches. +// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared -fsanitize-address-use-odr-indicator %s -o %dynamiclib -DSZ=100 +// RUN: %clangxx_asan -fsanitize-address-use-odr-indicator %s %ld_flags_rpath_exe -o %t-ODR-EXE +// RUN: %env_asan_opts=fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s // GNU driver doesn't handle .so files properly. // REQUIRES: Clang @@ -52,6 +60,6 @@ int main(int argc, char **argv) { // CHECK: These globals were registered at these points: // CHECK: ODR-EXE -// CHECK: ODR-SO +// CHECK: odr-violation.cc.dynamic // CHECK: SUMMARY: AddressSanitizer: odr-violation: global 'foo::G' at {{.*}}odr-violation.cc // DISABLED: PASS diff --git a/test/asan/TestCases/Linux/odr-vtable.cc b/test/asan/TestCases/Linux/odr-vtable.cc new file mode 100644 index 000000000000..fdbab4bb1fd8 --- /dev/null +++ b/test/asan/TestCases/Linux/odr-vtable.cc @@ -0,0 +1,26 @@ +// RUN: %clangxx_asan -fno-rtti -DBUILD_SO1 -fPIC -shared %s -o %dynamiclib1 +// RUN: %clangxx_asan -fno-rtti -DBUILD_SO2 -fPIC -shared %s -o %dynamiclib2 +// RUN: %clangxx_asan -fno-rtti %s %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t +// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t 2>&1 | FileCheck %s + +struct XYZ { + virtual void foo(); +}; + +#if defined(BUILD_SO1) + +void XYZ::foo() {} + +#elif defined(BUILD_SO2) + +void XYZ::foo() {} + +#else + +int main() {} + +#endif + +// CHECK: AddressSanitizer: odr-violation +// CHECK-NEXT: 'vtable for XYZ' +// CHECK-NEXT: 'vtable for XYZ' diff --git a/test/asan/TestCases/Linux/odr_c_test.c b/test/asan/TestCases/Linux/odr_c_test.c index b1d23493b570..c1423ed30b1b 100644 --- a/test/asan/TestCases/Linux/odr_c_test.c +++ b/test/asan/TestCases/Linux/odr_c_test.c @@ -1,13 +1,11 @@ // Test that we can properly report an ODR violation // between an instrumented global and a non-instrumented global. -// RUN: %clang_asan %s -fPIC -shared -o %t-1.so -DFILE1 -// RUN: %clang_asan %s -fPIC -shared -o %t-2.so -DFILE2 -// RUN: %clang_asan %s -fPIE %t-1.so %t-2.so -Wl,-R`pwd` -o %t +// RUN: %clang_asan %s -fPIC -shared -o %dynamiclib1 -DFILE1 +// RUN: %clang_asan %s -fPIC -shared -o %dynamiclib2 -DFILE2 +// RUN: %clang_asan %s -fPIE %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t // RUN: not %run %t 2>&1 | FileCheck %s // -// REQUIRES: x86_64-target-arch -// // CHECK: The following global variable is not properly aligned. // CHECK: ERROR: AddressSanitizer: odr-violation #if defined(FILE1) diff --git a/test/asan/TestCases/Linux/odr_indicators.cc b/test/asan/TestCases/Linux/odr_indicators.cc new file mode 100644 index 000000000000..36176b552906 --- /dev/null +++ b/test/asan/TestCases/Linux/odr_indicators.cc @@ -0,0 +1,26 @@ +// RUN: %clangxx_asan -fPIC %s -o %t +// RUN: %env_asan_opts=report_globals=2 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,INDICATOR0 + +// RUN: %clangxx_asan -fsanitize-address-use-odr-indicator -fPIC %s -o %t +// RUN: %env_asan_opts=report_globals=2 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,INDICATOR1 + +#include <stdio.h> + +int test_global_1; +// INDICATOR0-DAG: Added Global{{.*}} name=test_global_1{{.*}} odr_indicator={{0x0+$}} +// INDICATOR1-DAG: Added Global{{.*}} name=test_global_1{{.*}} odr_indicator={{0x0*[^0]+.*$}} + +static int test_global_2; +// CHECK-DAG: Added Global{{.*}} name=test_global_2{{.*}} odr_indicator={{0xf+$}} + +namespace { +static int test_global_3; +// CHECK-DAG: Added Global{{.*}} name={{.*}}::test_global_3{{.*}} odr_indicator={{0xf+$}} +} // namespace + +int main() { + const char f[] = "%d %d %d\n"; + // CHECK-DAG: Added Global{{.*}} name=__const.main.f{{.*}} odr_indicator={{0xf+$}} + printf(f, test_global_1, test_global_2, test_global_3); + return 0; +} diff --git a/test/asan/TestCases/Linux/preinit_test.cc b/test/asan/TestCases/Linux/preinit_test.cc index 10dde67d6a9b..f8c2b6bf52f1 100644 --- a/test/asan/TestCases/Linux/preinit_test.cc +++ b/test/asan/TestCases/Linux/preinit_test.cc @@ -1,8 +1,5 @@ -// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 -// XFAIL: android -// -// RUN: %clangxx -DFUNC=zzzz %s -shared -o %t.so -fPIC -// RUN: %clangxx_asan -DFUNC=main %s -o %t -Wl,-R. %t.so +// RUN: %clangxx -DFUNC=zzzz %s -shared -o %dynamiclib -fPIC +// RUN: %clangxx_asan -DFUNC=main %s -o %t %ld_flags_rpath_exe // RUN: %run %t // GNU driver doesn't handle .so files properly. diff --git a/test/asan/TestCases/Linux/preinstalled_signal.cc b/test/asan/TestCases/Linux/preinstalled_signal.cc index ac4ea93a5418..2b50944c6f2f 100644 --- a/test/asan/TestCases/Linux/preinstalled_signal.cc +++ b/test/asan/TestCases/Linux/preinstalled_signal.cc @@ -1,4 +1,3 @@ -// clang-format off // RUN: %clangxx -std=c++11 %s -o %t // RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck %s // RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s @@ -17,7 +16,6 @@ // This way of setting LD_PRELOAD does not work with Android test runner. // REQUIRES: !android -// clang-format on #include <assert.h> #include <signal.h> diff --git a/test/asan/TestCases/Posix/coverage-reset.cc b/test/asan/TestCases/Posix/coverage-reset.cc index 6d76a309b76f..152be2ab3a29 100644 --- a/test/asan/TestCases/Posix/coverage-reset.cc +++ b/test/asan/TestCases/Posix/coverage-reset.cc @@ -5,6 +5,8 @@ // // UNSUPPORTED: ios +// XFAIL: i386-netbsd + #include <stdio.h> #include <sanitizer/coverage_interface.h> diff --git a/test/asan/TestCases/Posix/coverage.cc b/test/asan/TestCases/Posix/coverage.cc index 12a88402eb5a..9dbd72eabd2c 100644 --- a/test/asan/TestCases/Posix/coverage.cc +++ b/test/asan/TestCases/Posix/coverage.cc @@ -18,6 +18,7 @@ // // https://code.google.com/p/address-sanitizer/issues/detail?id=263 // XFAIL: android +// XFAIL: i386-netbsd // UNSUPPORTED: ios #include <assert.h> diff --git a/test/asan/TestCases/Posix/dlclose-test.cc b/test/asan/TestCases/Posix/dlclose-test.cc index 0aafa3e79f6b..160c1c940e6f 100644 --- a/test/asan/TestCases/Posix/dlclose-test.cc +++ b/test/asan/TestCases/Posix/dlclose-test.cc @@ -23,6 +23,8 @@ // RUN: %clangxx_asan -O3 -DSHARED_LIB %s -fPIC -shared -o %t-so.so // RUN: %clangxx_asan -O3 %s %libdl -o %t && %run %t 2>&1 | FileCheck %s +// XFAIL: i386-netbsd + #if !defined(SHARED_LIB) #include <assert.h> #include <dlfcn.h> diff --git a/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc b/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc index a7d2bfb9b43c..b31b035f9e40 100644 --- a/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc +++ b/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc @@ -5,6 +5,8 @@ // RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe && \ // RUN: not %run %t 2>&1 | FileCheck %s +// XFAIL: i386-netbsd + #include <stdio.h> #include <string.h> diff --git a/test/asan/TestCases/Posix/mmap_limit_mb.cc b/test/asan/TestCases/Posix/mmap_limit_mb.cc index 508c03fbcb16..cb613f53577a 100644 --- a/test/asan/TestCases/Posix/mmap_limit_mb.cc +++ b/test/asan/TestCases/Posix/mmap_limit_mb.cc @@ -9,7 +9,7 @@ // 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: win32 +// XFAIL: windows-msvc #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/Posix/no-fd.cc b/test/asan/TestCases/Posix/no-fd.cc new file mode 100644 index 000000000000..086b01412ddb --- /dev/null +++ b/test/asan/TestCases/Posix/no-fd.cc @@ -0,0 +1,43 @@ +// RUN: %clangxx_asan -std=c++11 -O0 %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=debug=1,verbosity=2 %run %t 2>&1 | FileCheck %s + +// Test ASan initialization + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +extern "C" const char *__asan_default_options() { + return "test_only_emulate_no_memorymap=1"; +} + +void parent(int argc, char **argv) { + fprintf(stderr, "hello\n"); + // CHECK: hello + close(0); + close(1); + dup2(2, 3); + close(2); + char *const newargv[] = {argv[0], (char *)"x", nullptr}; + execv(argv[0], newargv); + perror("execve"); + exit(1); +} + +void child() { + assert(dup(3) == 0); + assert(dup(3) == 1); + assert(dup(3) == 2); + fprintf(stderr, "world\n"); + // CHECK: world +} + +int main(int argc, char **argv) { + if (argc == 1) { + parent(argc, argv); + } else { + child(); + } +} diff --git a/test/asan/TestCases/Posix/stack-use-after-return.cc b/test/asan/TestCases/Posix/stack-use-after-return.cc index 237c880f8e61..02588d708e22 100644 --- a/test/asan/TestCases/Posix/stack-use-after-return.cc +++ b/test/asan/TestCases/Posix/stack-use-after-return.cc @@ -17,7 +17,7 @@ // This test runs out of stack on AArch64. // UNSUPPORTED: aarch64 // stack size log lower than expected -// XFAIL: freebsd +// XFAIL: freebsd,netbsd // FIXME: Fix this test for dynamic runtime on arm linux. // UNSUPPORTED: (arm-linux || armhf-linux) && asan-dynamic-runtime @@ -78,9 +78,11 @@ int main(int argc, char **argv) { pthread_attr_init(&attr); if (kStackSize > 0) { size_t desired_stack_size = kStackSize; +#ifdef PTHREAD_STACK_MIN if (desired_stack_size < PTHREAD_STACK_MIN) { desired_stack_size = PTHREAD_STACK_MIN; } +#endif int ret = pthread_attr_setstacksize(&attr, desired_stack_size); if (ret != 0) { diff --git a/test/asan/TestCases/Posix/strndup_oob_test.cc b/test/asan/TestCases/Posix/strndup_oob_test.cc index 326ddcfd6b06..22bbf7c7ef1c 100644 --- a/test/asan/TestCases/Posix/strndup_oob_test.cc +++ b/test/asan/TestCases/Posix/strndup_oob_test.cc @@ -7,7 +7,7 @@ // RUN: %clangxx_asan -O3 -xc %s -o %t && not %run %t 2>&1 | FileCheck %s // Unwind problem on arm: "main" is missing from the allocation stack trace. -// UNSUPPORTED: win32,s390,arm && !fast-unwinder-works +// UNSUPPORTED: windows-msvc,s390,arm && !fast-unwinder-works #include <string.h> diff --git a/test/asan/TestCases/Posix/strndup_oob_test2.cc b/test/asan/TestCases/Posix/strndup_oob_test2.cc index 44df6bda9c83..8cc822d7cb3e 100644 --- a/test/asan/TestCases/Posix/strndup_oob_test2.cc +++ b/test/asan/TestCases/Posix/strndup_oob_test2.cc @@ -1,22 +1,22 @@ -// RUN: %clang_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s -// RUN: %clang_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s -// RUN: %clang_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s -// RUN: %clang_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s - -// When built as C on Linux, strndup is transformed to __strndup. -// RUN: %clang_asan -O3 -xc %s -o %t && not %run %t 2>&1 | FileCheck %s - -// Unwind problem on arm: "main" is missing from the allocation stack trace. -// UNSUPPORTED: win32,s390,arm && !fast-unwinder-works - -#include <string.h> - -char kChars[] = { 'f', 'o', 'o' }; - -int main(int argc, char **argv) { - char *copy = strndup(kChars, 3); - copy = strndup(kChars, 10); - // CHECK: AddressSanitizer: global-buffer-overflow - // CHECK: {{.*}}main {{.*}}.cc:[[@LINE-2]] - return *copy; -} +// RUN: %clang_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// When built as C on Linux, strndup is transformed to __strndup.
+// RUN: %clang_asan -O3 -xc %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// Unwind problem on arm: "main" is missing from the allocation stack trace.
+// UNSUPPORTED: windows-msvc,s390,arm && !fast-unwinder-works +
+#include <string.h>
+
+char kChars[] = { 'f', 'o', 'o' };
+
+int main(int argc, char **argv) {
+ char *copy = strndup(kChars, 3);
+ copy = strndup(kChars, 10);
+ // CHECK: AddressSanitizer: global-buffer-overflow
+ // CHECK: {{.*}}main {{.*}}.cc:[[@LINE-2]]
+ return *copy;
+}
diff --git a/test/asan/TestCases/Posix/tsd_dtor_leak.cc b/test/asan/TestCases/Posix/tsd_dtor_leak.cc index 9e71ff61cf02..26109fe1a5f4 100644 --- a/test/asan/TestCases/Posix/tsd_dtor_leak.cc +++ b/test/asan/TestCases/Posix/tsd_dtor_leak.cc @@ -2,6 +2,9 @@ // https://code.google.com/p/address-sanitizer/issues/detail?id=233 // RUN: %clangxx_asan -O1 %s -pthread -o %t // RUN: %env_asan_opts=quarantine_size_mb=0 %run %t +// XFAIL: x86_64-netbsd +// Assertion fails +// XFAIL: x86_64-freebsd #include <pthread.h> #include <stdio.h> #include <stdlib.h> diff --git a/test/asan/TestCases/asan_and_llvm_coverage_test.cc b/test/asan/TestCases/asan_and_llvm_coverage_test.cc index 1574a344399b..2ba5a42d1b7b 100644 --- a/test/asan/TestCases/asan_and_llvm_coverage_test.cc +++ b/test/asan/TestCases/asan_and_llvm_coverage_test.cc @@ -2,7 +2,8 @@ // RUN: %env_asan_opts=check_initialization_order=1 %run %t 2>&1 | FileCheck %s // We don't really support running tests using profile runtime on Windows. -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc + #include <stdio.h> int foo() { return 1; } int XXX = foo(); diff --git a/test/asan/TestCases/atoll_strict.c b/test/asan/TestCases/atoll_strict.c index 2b02354a92eb..0cb568969250 100644 --- a/test/asan/TestCases/atoll_strict.c +++ b/test/asan/TestCases/atoll_strict.c @@ -11,7 +11,7 @@ // 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 +// XFAIL: windows-msvc #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/heavy_uar_test.cc b/test/asan/TestCases/heavy_uar_test.cc index 94df0cefc73b..29a1d196567b 100644 --- a/test/asan/TestCases/heavy_uar_test.cc +++ b/test/asan/TestCases/heavy_uar_test.cc @@ -1,6 +1,6 @@ // 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: win32 +// XFAIL: windows-msvc // FIXME: Fix this test under GCC. // REQUIRES: Clang @@ -53,8 +53,8 @@ int main(int argc, char **argv) { RecursiveFunctionWithStackFrame<1024>(depth); RecursiveFunctionWithStackFrame<2000>(depth); // The stack size is tight for the main thread in multithread - // environment on FreeBSD. -#if !defined(__FreeBSD__) + // environment on FreeBSD and NetBSD. +#if !defined(__FreeBSD__) && !defined(__NetBSD__) RecursiveFunctionWithStackFrame<5000>(depth); RecursiveFunctionWithStackFrame<10000>(depth); #endif diff --git a/test/asan/TestCases/initialization-bug.cc b/test/asan/TestCases/initialization-bug.cc index 6ecc6c836c5c..20fdbfe5f59d 100644 --- a/test/asan/TestCases/initialization-bug.cc +++ b/test/asan/TestCases/initialization-bug.cc @@ -6,7 +6,7 @@ // Do not test with optimization -- the error may be optimized away. // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=186 -// XFAIL: win32 +// XFAIL: windows-msvc // The test is expected to fail on OS X Yosemite and older // UNSUPPORTED: osx-no-ld64-live_support diff --git a/test/asan/TestCases/intercept-rethrow-exception.cc b/test/asan/TestCases/intercept-rethrow-exception.cc index e81dc5398a98..019092a9e8b9 100644 --- a/test/asan/TestCases/intercept-rethrow-exception.cc +++ b/test/asan/TestCases/intercept-rethrow-exception.cc @@ -4,6 +4,10 @@ // RUN: %clangxx_asan -fexceptions -O0 %s -o %t // RUN: %run %t +// The current implementation of this functionality requires special +// combination of libraries that are not used by default on NetBSD +// XFAIL: netbsd + #include <assert.h> #include <exception> #include <sanitizer/asan_interface.h> diff --git a/test/asan/TestCases/interception_failure_test.cc b/test/asan/TestCases/interception_failure_test.cc index d85500b50486..4f6698e3a537 100644 --- a/test/asan/TestCases/interception_failure_test.cc +++ b/test/asan/TestCases/interception_failure_test.cc @@ -11,6 +11,10 @@ // it works with the dynamic runtime. // XFAIL: win32-static-asan +// On NetBSD, defining strtol in a static build results in linker errors, but +// it works with the dynamic runtime. +// XFAIL: netbsd && !asan-dynamic-runtime + #include <stdlib.h> #include <stdio.h> #include <string.h> diff --git a/test/asan/TestCases/intra-object-overflow.cc b/test/asan/TestCases/intra-object-overflow.cc index 56b5bb2b729f..b71e951bb0b7 100644 --- a/test/asan/TestCases/intra-object-overflow.cc +++ b/test/asan/TestCases/intra-object-overflow.cc @@ -5,7 +5,7 @@ // FIXME: fix 32-bits. // REQUIRES: asan-64-bits, shadow-scale-3 // FIXME: Implement ASan intra-object padding in Clang's MS record layout -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc #include <stdio.h> #include <stdlib.h> class Foo { diff --git a/test/asan/TestCases/log-path_test.cc b/test/asan/TestCases/log-path_test.cc index 710d22017700..fd33a31d6df9 100644 --- a/test/asan/TestCases/log-path_test.cc +++ b/test/asan/TestCases/log-path_test.cc @@ -31,7 +31,7 @@ // RUN: not cat %t.log.* // FIXME: log_path is not supported on Windows yet. -// XFAIL: win32 +// XFAIL: windows-msvc #include <stdlib.h> #include <string.h> diff --git a/test/asan/TestCases/pass-object-byval.cc b/test/asan/TestCases/pass-object-byval.cc index b99360fa7850..f9191c53d708 100644 --- a/test/asan/TestCases/pass-object-byval.cc +++ b/test/asan/TestCases/pass-object-byval.cc @@ -5,7 +5,7 @@ // RUN: Assertion{{.*}}failed // ASan instrumentation can't insert red-zones around inalloca parameters. -// XFAIL: win32 && asan-32-bits +// XFAIL: windows-msvc && asan-32-bits #include <cassert> diff --git a/test/asan/TestCases/printf-2.c b/test/asan/TestCases/printf-2.c index 0544847ff5bf..7127347f883b 100644 --- a/test/asan/TestCases/printf-2.c +++ b/test/asan/TestCases/printf-2.c @@ -6,7 +6,7 @@ // RUN: %env_asan_opts=replace_str=0:intercept_strlen=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 +// XFAIL: windows-msvc #include <stdio.h> #include <stdlib.h> diff --git a/test/asan/TestCases/printf-3.c b/test/asan/TestCases/printf-3.c index 010e6c8ef0c2..4f54ff956e3d 100644 --- a/test/asan/TestCases/printf-3.c +++ b/test/asan/TestCases/printf-3.c @@ -4,7 +4,11 @@ // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s // FIXME: printf is not intercepted on Windows yet. -// XFAIL: win32 +// XFAIL: windows-msvc + +// New Bionic rejects %n +// https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336 +// UNSUPPORTED: android #include <stdio.h> int main() { diff --git a/test/asan/TestCases/printf-4.c b/test/asan/TestCases/printf-4.c index 70f4073cc496..2af81b0efa15 100644 --- a/test/asan/TestCases/printf-4.c +++ b/test/asan/TestCases/printf-4.c @@ -4,7 +4,7 @@ // FIXME: sprintf is not intercepted on Windows yet. But this test can // pass if sprintf calls memmove, which is intercepted, so we can't XFAIL it. -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc #include <stdio.h> int main() { diff --git a/test/asan/TestCases/printf-5.c b/test/asan/TestCases/printf-5.c index a614462d2f4a..2257bb4e61aa 100644 --- a/test/asan/TestCases/printf-5.c +++ b/test/asan/TestCases/printf-5.c @@ -5,7 +5,7 @@ // 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 +// XFAIL: windows-msvc #include <stdio.h> #include <string.h> diff --git a/test/asan/TestCases/printf-m.c b/test/asan/TestCases/printf-m.c index 9cd5ae1c288e..3998a6956f74 100644 --- a/test/asan/TestCases/printf-m.c +++ b/test/asan/TestCases/printf-m.c @@ -1,7 +1,7 @@ // RUN: %clang_asan -O2 %s -o %t && %run %t // FIXME: printf is not intercepted on Windows yet. -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc #include <stdio.h> diff --git a/test/asan/TestCases/set_shadow_test.c b/test/asan/TestCases/set_shadow_test.c index daa79a66a389..95bbd829ba85 100644 --- a/test/asan/TestCases/set_shadow_test.c +++ b/test/asan/TestCases/set_shadow_test.c @@ -6,7 +6,7 @@ // RUN: not %run %t 0xf5 2>&1 | FileCheck %s -check-prefix=XF5 // RUN: not %run %t 0xf8 2>&1 | FileCheck %s -check-prefix=XF8 -// XFAIL: win32 +// XFAIL: windows-msvc #include <assert.h> #include <sanitizer/asan_interface.h> diff --git a/test/asan/TestCases/strcasestr-1.c b/test/asan/TestCases/strcasestr-1.c index dccfbcde7709..bb0863de77d2 100644 --- a/test/asan/TestCases/strcasestr-1.c +++ b/test/asan/TestCases/strcasestr-1.c @@ -6,7 +6,7 @@ // RUN: %env_asan_opts=intercept_strstr=false:replace_str=false %run %t 2>&1 // There's no interceptor for strcasestr on Windows -// XFAIL: win32 +// XFAIL: windows-msvc #define _GNU_SOURCE #include <assert.h> diff --git a/test/asan/TestCases/strcasestr-2.c b/test/asan/TestCases/strcasestr-2.c index 70de2dda437d..35d05c277eae 100644 --- a/test/asan/TestCases/strcasestr-2.c +++ b/test/asan/TestCases/strcasestr-2.c @@ -6,7 +6,7 @@ // RUN: %env_asan_opts=intercept_strstr=false:replace_str=false:intercept_strlen=false %run %t 2>&1 // There's no interceptor for strcasestr on Windows -// XFAIL: win32 +// XFAIL: windows-msvc #define _GNU_SOURCE #include <assert.h> diff --git a/test/asan/TestCases/strcasestr_strict.c b/test/asan/TestCases/strcasestr_strict.c index 956bee71a390..16adae184b53 100644 --- a/test/asan/TestCases/strcasestr_strict.c +++ b/test/asan/TestCases/strcasestr_strict.c @@ -4,7 +4,7 @@ // 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 +// XFAIL: windows-msvc #define _GNU_SOURCE #include <assert.h> diff --git a/test/asan/TestCases/strcat-overlap.cc b/test/asan/TestCases/strcat-overlap.cc index 89991fbd7881..5539b130f4e2 100644 --- a/test/asan/TestCases/strcat-overlap.cc +++ b/test/asan/TestCases/strcat-overlap.cc @@ -31,7 +31,7 @@ // depending on how strcat() is implemented. For now only run // on platforms where we know the test passes. // REQUIRES: x86_64h-darwin || x86_64-darwin || i386-darwin || x86_64-linux || i386-linux -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc // UNSUPPORTED: android #include <string.h> diff --git a/test/asan/TestCases/strncasecmp_strict.c b/test/asan/TestCases/strncasecmp_strict.c index aa658402b42b..bd937214092d 100644 --- a/test/asan/TestCases/strncasecmp_strict.c +++ b/test/asan/TestCases/strncasecmp_strict.c @@ -14,7 +14,7 @@ // RUN: %env_asan_opts=strict_string_checks=false %run %t i 2>&1 // RUN: %env_asan_opts=strict_string_checks=true not %run %t i 2>&1 | FileCheck %s -// XFAIL: win32 +// XFAIL: windows-msvc #include <assert.h> #include <stdlib.h> diff --git a/test/asan/TestCases/strtoll_strict.c b/test/asan/TestCases/strtoll_strict.c index 93cce30f8cb9..3fa800ca4136 100644 --- a/test/asan/TestCases/strtoll_strict.c +++ b/test/asan/TestCases/strtoll_strict.c @@ -24,7 +24,7 @@ // FIXME: Enable strtoll interceptor. // REQUIRES: shadow-scale-3 -// XFAIL: win32 +// XFAIL: windows-msvc #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 d7497566a8c3..3f6d239257d2 100644 --- a/test/asan/TestCases/suppressions-exec-relative-location.cc +++ b/test/asan/TestCases/suppressions-exec-relative-location.cc @@ -24,7 +24,7 @@ // RUN: FileCheck --check-prefix=CHECK-WRONG-FILE-NAME %s // XFAIL: android -// XFAIL: win32 +// XFAIL: windows-msvc // UNSUPPORTED: ios #include <stdio.h> diff --git a/test/asan/TestCases/suppressions-function.cc b/test/asan/TestCases/suppressions-function.cc index becefa2ee31c..510a9bc5bb56 100644 --- a/test/asan/TestCases/suppressions-function.cc +++ b/test/asan/TestCases/suppressions-function.cc @@ -7,7 +7,7 @@ // RUN: %clangxx_asan -O3 %s -o %t && %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s // FIXME: Windows symbolizer needs work to make this pass. -// XFAIL: android,win32 +// XFAIL: android,windows-msvc // UNSUPPORTED: ios // FIXME: atos does not work for inlined functions, yet llvm-symbolizer diff --git a/test/asan/TestCases/suppressions-library.cc b/test/asan/TestCases/suppressions-library.cc index 39ede0840105..181ed75826ce 100644 --- a/test/asan/TestCases/suppressions-library.cc +++ b/test/asan/TestCases/suppressions-library.cc @@ -11,6 +11,7 @@ // RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s // XFAIL: android +// XFAIL: i386-netbsd #include <stdio.h> #include <stdlib.h> diff --git a/test/asan/TestCases/throw_catch.cc b/test/asan/TestCases/throw_catch.cc index 01083510c32f..d7f00ea9e193 100644 --- a/test/asan/TestCases/throw_catch.cc +++ b/test/asan/TestCases/throw_catch.cc @@ -21,6 +21,7 @@ void ThrowAndCatch() { } } +__attribute__((noinline)) void TestThrow() { char x[32]; fprintf(stderr, "Before: %p poisoned: %d\n", &x, @@ -36,6 +37,7 @@ void TestThrow() { assert(!__asan_address_is_poisoned(x + 32)); } +__attribute__((noinline)) void TestThrowInline() { char x[32]; fprintf(stderr, "Before: %p poisoned: %d\n", &x, diff --git a/test/asan/TestCases/time_interceptor.cc b/test/asan/TestCases/time_interceptor.cc index 89b2183bcde2..f78af1056af6 100644 --- a/test/asan/TestCases/time_interceptor.cc +++ b/test/asan/TestCases/time_interceptor.cc @@ -3,7 +3,7 @@ // Test the time() interceptor. // There's no interceptor for time() on Windows yet. -// XFAIL: win32 +// XFAIL: windows-msvc #include <stdio.h> #include <stdlib.h> diff --git a/test/asan/TestCases/verbose-log-path_test.cc b/test/asan/TestCases/verbose-log-path_test.cc index 8088ff924761..5407d15d6f6e 100644 --- a/test/asan/TestCases/verbose-log-path_test.cc +++ b/test/asan/TestCases/verbose-log-path_test.cc @@ -10,7 +10,7 @@ // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t-dir/asan.log.verbose-log-path_test-binary.* // FIXME: only FreeBSD, NetBSD and Linux have verbose log paths now. -// XFAIL: win32,android +// XFAIL: windows-msvc,android // UNSUPPORTED: ios #include <stdlib.h> diff --git a/test/asan/lit.cfg b/test/asan/lit.cfg index f8994d069ad8..3deb4ccc5f91 100644 --- a/test/asan/lit.cfg +++ b/test/asan/lit.cfg @@ -101,8 +101,17 @@ config.substitutions.append( ("%clang ", build_invocation(target_cflags)) ) config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) ) config.substitutions.append( ("%clang_asan ", build_invocation(clang_asan_cflags)) ) config.substitutions.append( ("%clangxx_asan ", build_invocation(clang_asan_cxxflags)) ) -config.substitutions.append( ("%shared_libasan", "libclang_rt.asan%s.so" % config.target_suffix)) if config.asan_dynamic: + if config.host_os in ['Linux', 'NetBSD']: + shared_libasan_path = os.path.join(config.compiler_rt_libdir, "libclang_rt.asan{}.so".format(config.target_suffix)) + elif config.host_os == 'Darwin': + shared_libasan_path = os.path.join(config.compiler_rt_libdir, 'libclang_rt.asan_{}_dynamic.dylib'.format(config.apple_platform)) + else: + lit_config.warning('%shared_libasan substitution not set but dynamic ASan is available.') + shared_libasan_path = None + + if shared_libasan_path is not None: + config.substitutions.append( ("%shared_libasan", shared_libasan_path) ) config.substitutions.append( ("%clang_asan_static ", build_invocation(clang_asan_static_cflags)) ) config.substitutions.append( ("%clangxx_asan_static ", build_invocation(clang_asan_static_cxxflags)) ) diff --git a/test/builtins/CMakeLists.txt b/test/builtins/CMakeLists.txt index a9199ebf10df..eb4391fcab48 100644 --- a/test/builtins/CMakeLists.txt +++ b/test/builtins/CMakeLists.txt @@ -13,8 +13,18 @@ configure_lit_site_cfg( include(builtin-config-ix) +# Indicate if this is an MSVC environment. pythonize_bool(MSVC) +# Indicate if the compiler for the builtins library was MSVC. If the builtins +# compiler was clang-cl, we will enable some features that the host compiler +# will not, like C99 _Complex and int128. +set(BUILTINS_IS_MSVC OFF) +if (MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang") + set(BUILTINS_IS_MSVC ON) +endif() +pythonize_bool(BUILTINS_IS_MSVC) + #TODO: Add support for Apple. if (NOT APPLE) foreach(arch ${BUILTIN_SUPPORTED_ARCH}) diff --git a/test/builtins/Unit/absvti2_test.c b/test/builtins/Unit/absvti2_test.c index 0c0117dfeb45..3c2ded7b76ca 100644 --- a/test/builtins/Unit/absvti2_test.c +++ b/test/builtins/Unit/absvti2_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- absvti2_test.c - Test __absvti2 -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/addvti3_test.c b/test/builtins/Unit/addvti3_test.c index 3ffcf4b2d822..23e52d345ae2 100644 --- a/test/builtins/Unit/addvti3_test.c +++ b/test/builtins/Unit/addvti3_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- addvti3_test.c - Test __addvti3 -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/ashlti3_test.c b/test/builtins/Unit/ashlti3_test.c index 06186614ffc3..2dcd4494ffdf 100644 --- a/test/builtins/Unit/ashlti3_test.c +++ b/test/builtins/Unit/ashlti3_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- ashlti3_test.c - Test __ashlti3 -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/ashrti3_test.c b/test/builtins/Unit/ashrti3_test.c index 1f086535273f..69d0715b7406 100644 --- a/test/builtins/Unit/ashrti3_test.c +++ b/test/builtins/Unit/ashrti3_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- ashrti3_test.c - Test __ashrti3 -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/clzti2_test.c b/test/builtins/Unit/clzti2_test.c index 157838b6bddc..082583cb3f21 100644 --- a/test/builtins/Unit/clzti2_test.c +++ b/test/builtins/Unit/clzti2_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- clzti2_test.c - Test __clzti2 -------------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/cmpti2_test.c b/test/builtins/Unit/cmpti2_test.c index a2215f3c15cb..e74f379c8e7f 100644 --- a/test/builtins/Unit/cmpti2_test.c +++ b/test/builtins/Unit/cmpti2_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- cmpti2_test.c - Test __cmpti2 -------------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/compiler_rt_logb_test.c b/test/builtins/Unit/compiler_rt_logb_test.c new file mode 100644 index 000000000000..79676598089c --- /dev/null +++ b/test/builtins/Unit/compiler_rt_logb_test.c @@ -0,0 +1,63 @@ +// RUN: %clang_builtins %s %librt -o %t && %run %t +//===-- compiler_rt_logb_test.c - Test __compiler_rt_logb -----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file checks __compiler_rt_logb from the compiler_rt library for +// conformance against libm. +// +//===----------------------------------------------------------------------===// + +#define DOUBLE_PRECISION +#include <math.h> +#include <stdio.h> +#include "fp_lib.h" + +int test__compiler_rt_logb(fp_t x) { + fp_t crt_value = __compiler_rt_logb(x); + fp_t libm_value = logb(x); + // Compare actual rep, e.g. to avoid NaN != the same NaN + if (toRep(crt_value) != toRep(libm_value)) { + printf("error: in __compiler_rt_logb(%a [%lX]) = %a [%lX] != %a [%lX]\n", + x, toRep(x), crt_value, toRep(crt_value), libm_value, + toRep(libm_value)); + return 1; + } + return 0; +} + +double cases[] = { + 1.e-6, -1.e-6, NAN, -NAN, INFINITY, -INFINITY, -1, + -0.0, 0.0, 1, -2, 2, -0.5, 0.5, +}; + +int main() { + const unsigned N = sizeof(cases) / sizeof(cases[0]); + unsigned i; + for (i = 0; i < N; ++i) { + if (test__compiler_rt_logb(cases[i])) return 1; + } + + // Test a moving 1 bit, especially to handle denormal values. + // Test the negation as well. + rep_t x = signBit; + while (x) { + if (test__compiler_rt_logb(fromRep(x))) return 1; + if (test__compiler_rt_logb(fromRep(signBit ^ x))) return 1; + x >>= 1; + } + // Also try a couple moving ones + x = signBit | (signBit >> 1) | (signBit >> 2); + while (x) { + if (test__compiler_rt_logb(fromRep(x))) return 1; + if (test__compiler_rt_logb(fromRep(signBit ^ x))) return 1; + x >>= 1; + } + + return 0; +} diff --git a/test/builtins/Unit/compiler_rt_logbf_test.c b/test/builtins/Unit/compiler_rt_logbf_test.c new file mode 100644 index 000000000000..5a4979a4b4da --- /dev/null +++ b/test/builtins/Unit/compiler_rt_logbf_test.c @@ -0,0 +1,63 @@ +// RUN: %clang_builtins %s %librt -o %t && %run %t +//===-- compiler_rt_logbf_test.c - Test __compiler_rt_logbf ---------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file checks __compiler_rt_logbf from the compiler_rt library for +// conformance against libm. +// +//===----------------------------------------------------------------------===// + +#define SINGLE_PRECISION +#include <math.h> +#include <stdio.h> +#include "fp_lib.h" + +int test__compiler_rt_logbf(fp_t x) { + fp_t crt_value = __compiler_rt_logbf(x); + fp_t libm_value = logbf(x); + // Compare actual rep, e.g. to avoid NaN != the same NaN + if (toRep(crt_value) != toRep(libm_value)) { + printf("error: in __compiler_rt_logb(%a [%X]) = %a [%X] != %a [%X]\n", x, + toRep(x), crt_value, toRep(crt_value), libm_value, + toRep(libm_value)); + return 1; + } + return 0; +} + +double cases[] = { + 1.e-6, -1.e-6, NAN, -NAN, INFINITY, -INFINITY, -1, + -0.0, 0.0, 1, -2, 2, -0.5, 0.5, +}; + +int main() { + const unsigned N = sizeof(cases) / sizeof(cases[0]); + unsigned i; + for (i = 0; i < N; ++i) { + if (test__compiler_rt_logbf(cases[i])) return 1; + } + + // Test a moving 1 bit, especially to handle denormal values. + // Test the negation as well. + rep_t x = signBit; + while (x) { + if (test__compiler_rt_logbf(fromRep(x))) return 1; + if (test__compiler_rt_logbf(fromRep(signBit ^ x))) return 1; + x >>= 1; + } + // Also try a couple moving ones + x = signBit | (signBit >> 1) | (signBit >> 2); + while (x) { + if (test__compiler_rt_logbf(fromRep(x))) return 1; + if (test__compiler_rt_logbf(fromRep(signBit ^ x))) return 1; + x >>= 1; + } + + return 0; +} diff --git a/test/builtins/Unit/compiler_rt_logbl_test.c b/test/builtins/Unit/compiler_rt_logbl_test.c new file mode 100644 index 000000000000..2617748e9f14 --- /dev/null +++ b/test/builtins/Unit/compiler_rt_logbl_test.c @@ -0,0 +1,79 @@ +// RUN: %clang_builtins %s %librt -o %t && %run %t +//===-- compiler_rt_logbl_test.c - Test __compiler_rt_logbl ---------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file checks __compiler_rt_logbl from the compiler_rt library for +// conformance against libm. +// +//===----------------------------------------------------------------------===// + +#define QUAD_PRECISION +#include <math.h> +#include <stdio.h> +#include "fp_lib.h" +#include "int_lib.h" + +#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) + +int test__compiler_rt_logbl(fp_t x) { + fp_t crt_value = __compiler_rt_logbl(x); + fp_t libm_value = logbl(x); + // Compare actual rep, e.g. to avoid NaN != the same NaN + if (toRep(crt_value) != toRep(libm_value)) { + // Split expected values into two for printf + twords x_t, crt_value_t, libm_value_t; + x_t.all = toRep(x); + crt_value_t.all = toRep(crt_value); + libm_value_t.all = toRep(libm_value); + printf( + "error: in __compiler_rt_logb(%a [%llX %llX]) = %a [%llX %llX] != %a " + "[%llX %llX]\n", + x, x_t.s.high, x_t.s.low, crt_value, crt_value_t.s.high, + crt_value_t.s.low, libm_value, libm_value_t.s.high, libm_value_t.s.low); + return 1; + } + return 0; +} + +double cases[] = { + 1.e-6, -1.e-6, NAN, -NAN, INFINITY, -INFINITY, -1, + -0.0, 0.0, 1, -2, 2, -0.5, 0.5, +}; + +#endif + +int main() { +#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) + const unsigned N = sizeof(cases) / sizeof(cases[0]); + unsigned i; + for (i = 0; i < N; ++i) { + if (test__compiler_rt_logbl(cases[i])) return 1; + } + + // Test a moving 1 bit, especially to handle denormal values. + // Test the negation as well. + rep_t x = signBit; + while (x) { + if (test__compiler_rt_logbl(fromRep(x))) return 1; + if (test__compiler_rt_logbl(fromRep(signBit ^ x))) return 1; + x >>= 1; + } + // Also try a couple moving ones + x = signBit | (signBit >> 1) | (signBit >> 2); + while (x) { + if (test__compiler_rt_logbl(fromRep(x))) return 1; + if (test__compiler_rt_logbl(fromRep(signBit ^ x))) return 1; + x >>= 1; + } +#else + printf("skipped\n"); +#endif + + return 0; +} diff --git a/test/builtins/Unit/ctzti2_test.c b/test/builtins/Unit/ctzti2_test.c index bef79b6f8694..2ddcf0d0ac82 100644 --- a/test/builtins/Unit/ctzti2_test.c +++ b/test/builtins/Unit/ctzti2_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- ctzti2_test.c - Test __ctzti2 -------------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/divti3_test.c b/test/builtins/Unit/divti3_test.c index 9a6bf178b96c..77776e28ab77 100644 --- a/test/builtins/Unit/divti3_test.c +++ b/test/builtins/Unit/divti3_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- divti3_test.c - Test __divti3 -------------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/ffsti2_test.c b/test/builtins/Unit/ffsti2_test.c index 3b312c43099f..a7f0ca02ba04 100644 --- a/test/builtins/Unit/ffsti2_test.c +++ b/test/builtins/Unit/ffsti2_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- ffsti2_test.c - Test __ffsti2 -------------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/fixdfti_test.c b/test/builtins/Unit/fixdfti_test.c index 0abe187ae953..2b9db0f51396 100644 --- a/test/builtins/Unit/fixdfti_test.c +++ b/test/builtins/Unit/fixdfti_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- fixdfti_test.c - Test __fixdfti -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/fixsfti_test.c b/test/builtins/Unit/fixsfti_test.c index ec4e8ddb031a..25cf092c4562 100644 --- a/test/builtins/Unit/fixsfti_test.c +++ b/test/builtins/Unit/fixsfti_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- fixsfti_test.c - Test __fixsfti -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/fixunsdfti_test.c b/test/builtins/Unit/fixunsdfti_test.c index 249d8f886d0b..ca0bb76f1c41 100644 --- a/test/builtins/Unit/fixunsdfti_test.c +++ b/test/builtins/Unit/fixunsdfti_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- fixunsdfti_test.c - Test __fixunsdfti -----------------------------===// // // The LLVM Compiler Infrastructure @@ -99,25 +100,25 @@ int main() return 1; #endif - if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800LL)) + if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800ULL)) return 1; - if (test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000LL)) + if (test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000ULL)) return 1; - if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL)) + if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00ULL)) return 1; - if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL)) + if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800ULL)) return 1; - if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, make_ti(0xFFFFFFFFFFFFF800LL, 0))) + if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, make_ti(0xFFFFFFFFFFFFF800ULL, 0))) return 1; - if (test__fixunsdfti(0x1.0000000000000p+127, make_ti(0x8000000000000000LL, 0))) + if (test__fixunsdfti(0x1.0000000000000p+127, make_ti(0x8000000000000000ULL, 0))) return 1; - if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, make_ti(0x7FFFFFFFFFFFFC00LL, 0))) + if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, make_ti(0x7FFFFFFFFFFFFC00ULL, 0))) return 1; - if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, make_ti(0x7FFFFFFFFFFFF800LL, 0))) + if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, make_ti(0x7FFFFFFFFFFFF800ULL, 0))) return 1; - if (test__fixunsdfti(0x1.0000000000000p+128, make_ti(0xFFFFFFFFFFFFFFFFLL, - 0xFFFFFFFFFFFFFFFFLL))) + if (test__fixunsdfti(0x1.0000000000000p+128, make_ti(0xFFFFFFFFFFFFFFFFULL, + 0xFFFFFFFFFFFFFFFFULL))) return 1; #if !TARGET_LIBGCC diff --git a/test/builtins/Unit/fixunssfti_test.c b/test/builtins/Unit/fixunssfti_test.c index fd2d108f25b9..2306d283b854 100644 --- a/test/builtins/Unit/fixunssfti_test.c +++ b/test/builtins/Unit/fixunssfti_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- fixunssfti_test.c - Test __fixunssfti -----------------------------===// // // The LLVM Compiler Infrastructure @@ -87,18 +88,18 @@ int main() return 1; #endif - if (test__fixunssfti(0x1.FFFFFEp+63F, 0xFFFFFF0000000000LL)) + if (test__fixunssfti(0x1.FFFFFEp+63F, 0xFFFFFF0000000000ULL)) return 1; - if (test__fixunssfti(0x1.000000p+63F, 0x8000000000000000LL)) + if (test__fixunssfti(0x1.000000p+63F, 0x8000000000000000ULL)) return 1; if (test__fixunssfti(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL)) return 1; if (test__fixunssfti(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL)) return 1; - if (test__fixunssfti(0x1.FFFFFEp+127F, make_ti(0xFFFFFF0000000000LL, 0))) + if (test__fixunssfti(0x1.FFFFFEp+127F, make_ti(0xFFFFFF0000000000ULL, 0))) return 1; - if (test__fixunssfti(0x1.000000p+127F, make_ti(0x8000000000000000LL, 0))) + if (test__fixunssfti(0x1.000000p+127F, make_ti(0x8000000000000000ULL, 0))) return 1; if (test__fixunssfti(0x1.FFFFFEp+126F, make_ti(0x7FFFFF8000000000LL, 0))) return 1; diff --git a/test/builtins/Unit/fixunsxfti_test.c b/test/builtins/Unit/fixunsxfti_test.c index 256ba0cf452e..4e6fd39dca54 100644 --- a/test/builtins/Unit/fixunsxfti_test.c +++ b/test/builtins/Unit/fixunsxfti_test.c @@ -17,7 +17,7 @@ #include "int_lib.h" #include <stdio.h> -#ifdef CRT_HAS_128BIT +#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE // Returns: convert a to a unsigned long long, rounding toward zero. // Negative values all become zero. @@ -55,7 +55,7 @@ char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; int main() { -#ifdef CRT_HAS_128BIT +#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE if (test__fixunsxfti(0.0, 0)) return 1; diff --git a/test/builtins/Unit/fixxfdi_test.c b/test/builtins/Unit/fixxfdi_test.c index 40ad2b04f23b..dcfa75c4b453 100644 --- a/test/builtins/Unit/fixxfdi_test.c +++ b/test/builtins/Unit/fixxfdi_test.c @@ -26,7 +26,7 @@ // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee | // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm -COMPILER_RT_ABI di_int __sfixxfdi(long double a); +COMPILER_RT_ABI di_int __fixxfdi(long double a); int test__fixxfdi(long double a, di_int expected) { diff --git a/test/builtins/Unit/fixxfti_test.c b/test/builtins/Unit/fixxfti_test.c index 518ef44fbdb9..86f4c02da5c9 100644 --- a/test/builtins/Unit/fixxfti_test.c +++ b/test/builtins/Unit/fixxfti_test.c @@ -17,7 +17,7 @@ #include "int_lib.h" #include <stdio.h> -#ifdef CRT_HAS_128BIT +#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE // Returns: convert a to a signed long long, rounding toward zero. @@ -45,15 +45,15 @@ int test__fixxfti(long double a, ti_int expected) return x != expected; } -char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; -char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0}; -char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; +COMPILE_TIME_ASSERT(sizeof(ti_int) == 2*sizeof(di_int)); +COMPILE_TIME_ASSERT(sizeof(su_int)*CHAR_BIT == 32); +COMPILE_TIME_ASSERT(sizeof(long double)*CHAR_BIT == 128); #endif int main() { -#ifdef CRT_HAS_128BIT +#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE if (test__fixxfti(0.0, 0)) return 1; diff --git a/test/builtins/Unit/floattidf_test.c b/test/builtins/Unit/floattidf_test.c index 9da8c5dc68cb..51178f28e48a 100644 --- a/test/builtins/Unit/floattidf_test.c +++ b/test/builtins/Unit/floattidf_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- floattidf.c - Test __floattidf ------------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/floattisf_test.c b/test/builtins/Unit/floattisf_test.c index 9d7282cdea21..9162471a33c5 100644 --- a/test/builtins/Unit/floattisf_test.c +++ b/test/builtins/Unit/floattisf_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- floattisf_test.c - Test __floattisf -------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/floattixf_test.c b/test/builtins/Unit/floattixf_test.c index 77a6f7dbf0ce..501a8dc6cd34 100644 --- a/test/builtins/Unit/floattixf_test.c +++ b/test/builtins/Unit/floattixf_test.c @@ -18,7 +18,7 @@ #include <float.h> #include <stdio.h> -#ifdef CRT_HAS_128BIT +#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE // Returns: convert a to a long double, rounding toward even. @@ -43,15 +43,15 @@ int test__floattixf(ti_int a, long double expected) return x != expected; } -char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; -char assumption_2[sizeof(ti_int)*CHAR_BIT == 128] = {0}; -char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; +COMPILE_TIME_ASSERT(sizeof(ti_int) == 2*sizeof(di_int)); +COMPILE_TIME_ASSERT(sizeof(ti_int)*CHAR_BIT == 128); +COMPILE_TIME_ASSERT(sizeof(long double)*CHAR_BIT == 128); #endif int main() { -#ifdef CRT_HAS_128BIT +#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE if (test__floattixf(0, 0.0)) return 1; diff --git a/test/builtins/Unit/floatuntidf_test.c b/test/builtins/Unit/floatuntidf_test.c index 1bf19ba141b9..f91d0e1bd385 100644 --- a/test/builtins/Unit/floatuntidf_test.c +++ b/test/builtins/Unit/floatuntidf_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- floatuntidf.c - Test __floatuntidf --------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/floatuntisf_test.c b/test/builtins/Unit/floatuntisf_test.c index c7c11ba48c52..f460a059e6a1 100644 --- a/test/builtins/Unit/floatuntisf_test.c +++ b/test/builtins/Unit/floatuntisf_test.c @@ -16,7 +16,7 @@ #include <float.h> #include <stdio.h> -#ifdef CRT_HAS_128BIT +#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE // Returns: convert a to a float, rounding toward even. @@ -40,15 +40,15 @@ int test__floatuntisf(tu_int a, float expected) return x != expected; } -char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0}; -char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0}; -char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0}; +COMPILE_TIME_ASSERT(sizeof(tu_int) == 2*sizeof(du_int)); +COMPILE_TIME_ASSERT(sizeof(tu_int)*CHAR_BIT == 128); +COMPILE_TIME_ASSERT(sizeof(float)*CHAR_BIT == 32); #endif int main() { -#ifdef CRT_HAS_128BIT +#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE if (test__floatuntisf(0, 0.0F)) return 1; diff --git a/test/builtins/Unit/floatuntixf_test.c b/test/builtins/Unit/floatuntixf_test.c index 0f7ad463450d..a9a8441d0c32 100644 --- a/test/builtins/Unit/floatuntixf_test.c +++ b/test/builtins/Unit/floatuntixf_test.c @@ -18,7 +18,7 @@ #include <float.h> #include <stdio.h> -#ifdef CRT_HAS_128BIT +#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE // Returns: convert a to a long double, rounding toward even. @@ -43,15 +43,15 @@ int test__floatuntixf(tu_int a, long double expected) return x != expected; } -char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0}; -char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0}; -char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; +COMPILE_TIME_ASSERT(sizeof(tu_int) == 2*sizeof(du_int)); +COMPILE_TIME_ASSERT(sizeof(tu_int)*CHAR_BIT == 128); +COMPILE_TIME_ASSERT(sizeof(long double)*CHAR_BIT == 128); #endif int main() { -#ifdef CRT_HAS_128BIT +#if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE if (test__floatuntixf(0, 0.0)) return 1; diff --git a/test/builtins/Unit/lit.cfg b/test/builtins/Unit/lit.cfg index 4b63948b5ef6..d5fa73b0c64d 100644 --- a/test/builtins/Unit/lit.cfg +++ b/test/builtins/Unit/lit.cfg @@ -24,7 +24,7 @@ default_builtins_opts = '' config.test_source_root = os.path.dirname(__file__) # Path to the static library -is_msvc = get_required_attr(config, "builtins_is_msvc") +is_msvc = get_required_attr(config, "is_msvc") if is_msvc: base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.builtins%s.lib " % config.target_suffix) @@ -52,9 +52,15 @@ clang_builtins_static_cxxflags = config.cxx_mode_flags + \ clang_builtins_cflags = clang_builtins_static_cflags clang_builtins_cxxflags = clang_builtins_static_cxxflags +# FIXME: Right now we don't compile the C99 complex builtins when using +# clang-cl. Fix that. if not is_msvc: config.available_features.add('c99-complex') +builtins_is_msvc = get_required_attr(config, "builtins_is_msvc") +if not builtins_is_msvc: + config.available_features.add('int128') + clang_wrapper = "" def build_invocation(compile_flags): diff --git a/test/builtins/Unit/lit.site.cfg.in b/test/builtins/Unit/lit.site.cfg.in index 4241bdc9cebc..75d70f703238 100644 --- a/test/builtins/Unit/lit.site.cfg.in +++ b/test/builtins/Unit/lit.site.cfg.in @@ -4,7 +4,8 @@ config.name_suffix = "@BUILTINS_TEST_CONFIG_SUFFIX@" config.builtins_lit_source_dir = "@BUILTINS_LIT_SOURCE_DIR@/Unit" config.target_cflags = "@BUILTINS_TEST_TARGET_CFLAGS@" config.target_arch = "@BUILTINS_TEST_TARGET_ARCH@" -config.builtins_is_msvc = @MSVC_PYBOOL@ +config.is_msvc = @MSVC_PYBOOL@ +config.builtins_is_msvc = @BUILTINS_IS_MSVC_PYBOOL@ # Load common config for all compiler-rt lit tests. lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") diff --git a/test/builtins/Unit/lshrti3_test.c b/test/builtins/Unit/lshrti3_test.c index 91356c8bfe5b..51020edbf84a 100644 --- a/test/builtins/Unit/lshrti3_test.c +++ b/test/builtins/Unit/lshrti3_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- lshrti3_test.c - Test __lshrti3 -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/modti3_test.c b/test/builtins/Unit/modti3_test.c index 53fbf5bbad06..9faa0b5aff01 100644 --- a/test/builtins/Unit/modti3_test.c +++ b/test/builtins/Unit/modti3_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- modti3_test.c - Test __modti3 -------------------------------------===// // // The LLVM Compiler Infrastructure @@ -63,17 +64,17 @@ int main() if (test__modti3(-5, -3, -2)) return 1; - if (test__modti3(0x8000000000000000LL, 1, 0x0LL)) + if (test__modti3(0x8000000000000000ULL, 1, 0x0LL)) return 1; - if (test__modti3(0x8000000000000000LL, -1, 0x0LL)) + if (test__modti3(0x8000000000000000ULL, -1, 0x0LL)) return 1; - if (test__modti3(0x8000000000000000LL, 2, 0x0LL)) + if (test__modti3(0x8000000000000000ULL, 2, 0x0LL)) return 1; - if (test__modti3(0x8000000000000000LL, -2, 0x0LL)) + if (test__modti3(0x8000000000000000ULL, -2, 0x0LL)) return 1; - if (test__modti3(0x8000000000000000LL, 3, 2)) + if (test__modti3(0x8000000000000000ULL, 3, 2)) return 1; - if (test__modti3(0x8000000000000000LL, -3, 2)) + if (test__modti3(0x8000000000000000ULL, -3, 2)) return 1; if (test__modti3(make_ti(0x8000000000000000LL, 0), 1, 0x0LL)) diff --git a/test/builtins/Unit/muloti4_test.c b/test/builtins/Unit/muloti4_test.c index e7c78cf16853..9eb56f648a4a 100644 --- a/test/builtins/Unit/muloti4_test.c +++ b/test/builtins/Unit/muloti4_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- muloti4_test.c - Test __muloti4 -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/multi3_test.c b/test/builtins/Unit/multi3_test.c index 8227f2426860..d92bae68b0c6 100644 --- a/test/builtins/Unit/multi3_test.c +++ b/test/builtins/Unit/multi3_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- multi3_test.c - Test __multi3 -------------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/mulvti3_test.c b/test/builtins/Unit/mulvti3_test.c index 36e96ad60f11..f964ed699905 100644 --- a/test/builtins/Unit/mulvti3_test.c +++ b/test/builtins/Unit/mulvti3_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- mulvti3_test.c - Test __mulvti3 -----------------------------------===// // // The LLVM Compiler Infrastructure @@ -99,13 +100,13 @@ int main() if (test__mulvti3(-81985529216486895LL, 1, -81985529216486895LL)) return 1; - if (test__mulvti3(3037000499LL, 3037000499LL, 9223372030926249001LL)) + if (test__mulvti3(3037000499LL, 3037000499LL, 9223372030926249001ULL)) return 1; if (test__mulvti3(-3037000499LL, 3037000499LL, -9223372030926249001LL)) return 1; if (test__mulvti3(3037000499LL, -3037000499LL, -9223372030926249001LL)) return 1; - if (test__mulvti3(-3037000499LL, -3037000499LL, 9223372030926249001LL)) + if (test__mulvti3(-3037000499LL, -3037000499LL, 9223372030926249001ULL)) return 1; if (test__mulvti3(4398046511103LL, 2097152LL, 9223372036852678656LL)) @@ -117,7 +118,7 @@ int main() if (test__mulvti3(-4398046511103LL, -2097152LL, 9223372036852678656LL)) return 1; - if (test__mulvti3(2097152LL, 4398046511103LL, 9223372036852678656LL)) + if (test__mulvti3(2097152LL, 4398046511103LL, 9223372036852678656ULL)) return 1; if (test__mulvti3(-2097152LL, 4398046511103LL, -9223372036852678656LL)) return 1; diff --git a/test/builtins/Unit/negti2_test.c b/test/builtins/Unit/negti2_test.c index bb7379cae2b1..89eb0b04f99e 100644 --- a/test/builtins/Unit/negti2_test.c +++ b/test/builtins/Unit/negti2_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- negti2_test.c - Test __negti2 -------------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/negvti2_test.c b/test/builtins/Unit/negvti2_test.c index 980f44869327..9c2765ec6b07 100644 --- a/test/builtins/Unit/negvti2_test.c +++ b/test/builtins/Unit/negvti2_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- negvti2_test.c - Test __negvti2 -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/parityti2_test.c b/test/builtins/Unit/parityti2_test.c index bcd26d0af846..11d578be50e2 100644 --- a/test/builtins/Unit/parityti2_test.c +++ b/test/builtins/Unit/parityti2_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- parityti2_test.c - Test __parityti2 -------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/popcountti2_test.c b/test/builtins/Unit/popcountti2_test.c index ef8b2c3836bc..91c169fb550a 100644 --- a/test/builtins/Unit/popcountti2_test.c +++ b/test/builtins/Unit/popcountti2_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- popcountti2_test.c - Test __popcountti2 ----------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/ppc/fixtfdi_test.c b/test/builtins/Unit/ppc/fixtfdi_test.c index ea6c40563777..0dc6636552c4 100644 --- a/test/builtins/Unit/ppc/fixtfdi_test.c +++ b/test/builtins/Unit/ppc/fixtfdi_test.c @@ -1,5 +1,5 @@ -// REQUIRES: powerpc-registered-target -// RUN: %clang_builtins %s -o %t && %run %t +// REQUIRES: target-is-powerpc64le +// RUN: %clang_builtins %s %librt -o %t && %run %t #include <stdio.h> #include <limits.h> #include <stdint.h> @@ -476,4 +476,4 @@ int main(int argc, char *argv[]) { } return 0; -}
\ No newline at end of file +} diff --git a/test/builtins/Unit/ppc/fixunstfti_test.c b/test/builtins/Unit/ppc/fixunstfti_test.c new file mode 100644 index 000000000000..0eee31db1b5d --- /dev/null +++ b/test/builtins/Unit/ppc/fixunstfti_test.c @@ -0,0 +1,52 @@ +// REQUIRES: target-is-powerpc64le +// RUN: %clang_builtins %s %librt -o %t && %run %t + +#include <stdint.h> +#include <stdio.h> + +#include "fixunstfti_test.h" + +/* The long double representation, with the high and low portions of + * the long double, and the corresponding bit patterns of each double. */ +typedef union { + long double ld; + double d[2]; /* [0] is the high double, [1] is the low double. */ + unsigned long long ull[2]; /* High and low doubles as 64-bit integers. */ +} ldUnion; + +__uint128_t __fixunstfti(long double); + +int main(int argc, char *argv[]) { + /* Necessary long double and (unsigned) 128 bit integer + * declarations used to compare the computed and expected results + * from converting the IBM double-double to int128. */ + ldUnion ldInput; + __uint128_t expectedResult, computedResult; + + for (int i = 0; i < numTests; ++i) { + /* Set the expected 128 bit integer and the high and low + * values of the long double input. */ + ldInput.d[0] = testList[i].hiInput; + ldInput.d[1] = testList[i].loInput; + expectedResult = testList[i].result128; + + /* Get the computed 128 bit integer from the long double-> + * uint128 conversion, and check for errors between results. */ + computedResult = __fixunstfti(ldInput.ld); + + if (computedResult != expectedResult) { + printf("Error for __fixunstfti at input %La = ( %a , %a ):\n", ldInput.ld, + ldInput.d[0], ldInput.d[1]); + printf("\tExpected __uint128_t: 0x%016llx 0x%016llx\n", + (unsigned long long)(expectedResult >> 64), + (unsigned long long)expectedResult); + printf("\tComputed __uint128_t: 0x%016llx 0x%016llx\n\n", + (unsigned long long)(computedResult >> 64), + (unsigned long long)computedResult); + + return 1; + } + } + + return 0; +} diff --git a/test/builtins/Unit/ppc/fixunstfti_test.h b/test/builtins/Unit/ppc/fixunstfti_test.h new file mode 100644 index 000000000000..d7de0ce14303 --- /dev/null +++ b/test/builtins/Unit/ppc/fixunstfti_test.h @@ -0,0 +1,706 @@ +/* +* Test case inputs for: __uint128_t __fixunstfti (long double) +* Conversion from long double (IBM double-double) to 128 bit integer. +*/ + +#define INFINITY __builtin_inf() +#define QNAN __builtin_nan("") +#define INIT_U128(HI, LO) (((__uint128_t) (HI) << 64) | (LO)) + +struct testCase { + double hiInput; + double loInput; + __uint128_t result128; +}; + +struct testCase testList[] = { + { 0x0p+0, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { -0x0p+0, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { -0x0p+0, -0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x0p+0, -0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { -0x1p+0, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x1p+0, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000001 ) }, + { -INFINITY, 0x0p+0, ((__uint128_t)0x0000000000000000 << 64) | 0x0000000000000000 }, + { INFINITY, 0x0p+0, ((__uint128_t)0xffffffffffffffff << 64) | 0xffffffffffffffff }, + { QNAN, 0x0p+0, ((__uint128_t)0x7ff8000000000000 << 64) | 0x0000000000000000 }, + { -QNAN, 0x0p+0, ((__uint128_t)0x7ff8000000000000 << 64) | 0x0000000000000000 }, + { -0x1p+127, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x1p+127, -0x1p+0, INIT_U128( 0x7fffffffffffffff, 0xffffffffffffffff ) }, + { 0x1p+0, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000001 ) }, + { 0x1p+60, 0x0p+0, INIT_U128( 0x0000000000000000, 0x1000000000000000 ) }, + { 0x1p+64, -0x1p+0, INIT_U128( 0x0000000000000000, 0xffffffffffffffff ) }, + { 0x1p+63, -0x1p+0, INIT_U128( 0x0000000000000000, 0x7fffffffffffffff ) }, + { 0x1p+64, 0x0p+0, INIT_U128( 0x0000000000000001, 0x0000000000000000 ) }, + { 0x1p+64, 0x1p+0, INIT_U128( 0x0000000000000001, 0x0000000000000001 ) }, + { 0x1.8p+64, -0x1p+0, INIT_U128( 0x0000000000000001, 0x7fffffffffffffff ) }, + { 0x1.1p+64, 0x0p+0, INIT_U128( 0x0000000000000001, 0x1000000000000000 ) }, + { 0x1p+65, -0x1p+0, INIT_U128( 0x0000000000000001, 0xffffffffffffffff ) }, + { 0x1p+127, -0x1p+64, INIT_U128( 0x7fffffffffffffff, 0x0000000000000000 ) }, + { 0x1p+127, -0x1.ep+64, INIT_U128( 0x7ffffffffffffffe, 0x2000000000000000 ) }, + { 0x1p+127, -0x1p+63, INIT_U128( 0x7fffffffffffffff, 0x8000000000000000 ) }, + { 0x1p+124, 0x0p+0, INIT_U128( 0x1000000000000000, 0x0000000000000000 ) }, + { 0x1p+124, 0x1p+0, INIT_U128( 0x1000000000000000, 0x0000000000000001 ) }, + { 0x1p+124, 0x1p+63, INIT_U128( 0x1000000000000000, 0x8000000000000000 ) }, + { 0x1p+124, 0x1p+64, INIT_U128( 0x1000000000000001, 0x0000000000000000 ) }, + { -0x1p+64, 0x0p+0, INIT_U128( 0x00000000000000000, 0x0000000000000000 ) }, + { 0x1.84p+70, 0x1.84p+6, INIT_U128( 0x0000000000000061, 0x0000000000000061 ) }, + { 0x1.5cp+6, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000057 ) }, + { 0x1p+64, -0x1.88p+6, INIT_U128( 0x0000000000000000, 0xffffffffffffff9e ) }, + { 0x1.88p+6, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000062 ) }, + { 0x1.00cp+10, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000403 ) }, + { 0x1.fffffffffffffp+63, 0x1.fep+9, INIT_U128( 0x0000000000000000, 0xfffffffffffffbfc ) }, + { 0x1.028p+10, 0x0p+0, INIT_U128( 0x0000000000000000, 0x000000000000040a ) }, + { 0x1.44p+10, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000510 ) }, + { 0x1.fffffffffffffp+63, 0x1.738p+9, INIT_U128( 0x0000000000000000, 0xfffffffffffffae7 ) }, + { 0x1.808p+10, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000602 ) }, + { 0x1.fffffffffffffp+63, 0x1.fdp+8, INIT_U128( 0x0000000000000000, 0xfffffffffffff9fd ) }, + { 0x1.048p+13, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000002090 ) }, + { 0x1.ffffffffffffbp+63, 0x1.ed8p+9, INIT_U128( 0x0000000000000000, 0xffffffffffffdbdb ) }, + { 0x1.0101p+17, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000020202 ) }, + { 0x1.fffffffffffbep+63, -0x1.09p+8, INIT_U128( 0x0000000000000000, 0xfffffffffffdeef7 ) }, + { 0x1.9002p+17, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000032004 ) }, + { 0x1.fffffffffff9cp+63, -0x1.4p+2, INIT_U128( 0x0000000000000000, 0xfffffffffffcdffb ) }, + { 0x1.902p+17, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000032040 ) }, + { 0x1.ffffffffff7fcp+63, -0x1.14p+6, INIT_U128( 0x0000000000000000, 0xffffffffffbfdfbb ) }, + { 0x1.00822p+22, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000402088 ) }, + { 0x1.0010011p+31, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000080080088 ) }, + { 0x1.0a000001p+35, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000850000008 ) }, + { 0x1.000000224p+37, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000002000000448 ) }, + { 0x1.ffffffbffefb8p+63, -0x1p+0, INIT_U128( 0x0000000000000000, 0xffffffdfff7dbfff ) }, + { 0x1.00080044p+102, 0x1.00080044p+38, INIT_U128( 0x0000004002001100, 0x0000004002001100 ) }, + { 0x1.00400000018p+107, 0x1.00400000018p+43, INIT_U128( 0x000008020000000c, 0x000008020000000c ) }, + { 0x1.ffffeffcp+63, -0x1.ap+3, INIT_U128( 0x0000000000000000, 0xfffff7fdfffffff3 ) }, + { 0x1.000000001048p+47, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000800000000824 ) }, + { 0x1.fffbffffffp+63, -0x1.808p+9, INIT_U128( 0x0000000000000000, 0xfffdffffff7ffcff ) }, + { 0x1.000810004p+62, 0x0p+0, INIT_U128( 0x0000000000000000, 0x4002040010000000 ) }, + { 0x1.7ffbf7ffep+63, -0x1p+0, INIT_U128( 0x0000000000000000, 0xbffdfbffefffffff ) }, + { 0x1p+63, 0x0p+0, INIT_U128( 0x0000000000000000, 0x8000000000000000 ) }, + { 0x1.ffffffffe8319p+63, -0x1.1f8p+9, INIT_U128( 0x0000000000000000, 0xfffffffff418c5c1 ) }, + { 0x1p+68, -0x1p+0, INIT_U128( 0x000000000000000f, 0xffffffffffffffff ) }, + { 0x1p+72, -0x1p+0, INIT_U128( 0x00000000000000ff, 0xffffffffffffffff ) }, + { 0x1p+76, -0x1p+0, INIT_U128( 0x0000000000000fff, 0xffffffffffffffff ) }, + { 0x1p+80, -0x1p+0, INIT_U128( 0x000000000000ffff, 0xffffffffffffffff ) }, + { 0x1p+84, -0x1p+0, INIT_U128( 0x00000000000fffff, 0xffffffffffffffff ) }, + { 0x1p+88, -0x1p+0, INIT_U128( 0x0000000000ffffff, 0xffffffffffffffff ) }, + { 0x1p+92, -0x1p+0, INIT_U128( 0x000000000fffffff, 0xffffffffffffffff ) }, + { 0x1p+96, -0x1p+0, INIT_U128( 0x00000000ffffffff, 0xffffffffffffffff ) }, + { 0x1p+100, -0x1p+0, INIT_U128( 0x0000000fffffffff, 0xffffffffffffffff ) }, + { 0x1p+104, -0x1p+0, INIT_U128( 0x000000ffffffffff, 0xffffffffffffffff ) }, + { 0x1p+108, -0x1p+0, INIT_U128( 0x00000fffffffffff, 0xffffffffffffffff ) }, + { 0x1p+112, -0x1p+0, INIT_U128( 0x0000ffffffffffff, 0xffffffffffffffff ) }, + { 0x1p+116, -0x1p+0, INIT_U128( 0x000fffffffffffff, 0xffffffffffffffff ) }, + { 0x1p+120, -0x1p+0, INIT_U128( 0x00ffffffffffffff, 0xffffffffffffffff ) }, + { 0x1p+124, -0x1p+0, INIT_U128( 0x0fffffffffffffff, 0xffffffffffffffff ) }, + { 0x1p+124, 0x0p+0, INIT_U128( 0x1000000000000000, 0x0000000000000000 ) }, + { 0x1p+124, 0x1.1p+4, INIT_U128( 0x1000000000000000, 0x0000000000000011 ) }, + { 0x1p+124, 0x1.11p+8, INIT_U128( 0x1000000000000000, 0x0000000000000111 ) }, + { 0x1p+124, 0x1.111p+12, INIT_U128( 0x1000000000000000, 0x0000000000001111 ) }, + { 0x1p+124, 0x1.1111p+16, INIT_U128( 0x1000000000000000, 0x0000000000011111 ) }, + { 0x1p+124, 0x1.11111p+20, INIT_U128( 0x1000000000000000, 0x0000000000111111 ) }, + { 0x1p+124, 0x1.111111p+24, INIT_U128( 0x1000000000000000, 0x0000000001111111 ) }, + { 0x1p+124, 0x1.1111111p+28, INIT_U128( 0x1000000000000000, 0x0000000011111111 ) }, + { 0x1p+124, 0x1.11111111p+32, INIT_U128( 0x1000000000000000, 0x0000000111111111 ) }, + { 0x1p+124, 0x1.111111111p+36, INIT_U128( 0x1000000000000000, 0x0000001111111111 ) }, + { 0x1p+124, 0x1.1111111111p+40, INIT_U128( 0x1000000000000000, 0x0000011111111111 ) }, + { 0x1p+124, 0x1.11111111111p+44, INIT_U128( 0x1000000000000000, 0x0000111111111111 ) }, + { 0x1p+124, 0x1.111111111111p+48, INIT_U128( 0x1000000000000000, 0x0001111111111111 ) }, + { 0x1p+124, 0x1.1111111111111p+52, INIT_U128( 0x1000000000000000, 0x0011111111111111 ) }, + { 0x1p+124, 0x1.11111111111111p+56, INIT_U128( 0x1000000000000000, 0x0111111111111110 ) }, + { 0x1p+124, 0x1.111111111111111p+60, INIT_U128( 0x1000000000000000, 0x1111111111111100 ) }, + { 0x1.6ffffffefp+63, -0x1p+0, INIT_U128( 0x0000000000000000, 0xb7ffffff77ffffff ) }, + { 0x1p+106, 0x0p+0, INIT_U128( 0x0000040000000000, 0x0000000000000000 ) }, + { 0x1.ff8p+29, 0x0p+0, INIT_U128( 0x0000000000000000, 0x000000003ff00000 ) }, + { 0x1.6ff7ffffffffcp+63, -0x1p+0, INIT_U128( 0x0000000000000000, 0xb7fbffffffffdfff ) }, + { 0x1.2400000000004p+62, 0x0p+0, INIT_U128( 0x0000000000000000, 0x4900000000001000 ) }, + { 0x1.24000000001p+126, 0x1.24000000001p+62, INIT_U128( 0x4900000000040000, 0x4900000000040000 ) }, + { 0x1.2400001p+126, 0x1.2400001p+62, INIT_U128( 0x4900000400000000, 0x4900000400000000 ) }, + { 0x1.240001p+126, 0x1.240001p+62, INIT_U128( 0x4900004000000000, 0x4900004000000000 ) }, + { 0x1.24001p+126, 0x1.24001p+62, INIT_U128( 0x4900040000000000, 0x4900040000000000 ) }, + { 0x1.24008p+126, 0x1.24008p+62, INIT_U128( 0x4900200000000000, 0x4900200000000000 ) }, + { 0x1.2404p+126, 0x1.2404p+62, INIT_U128( 0x4901000000000000, 0x4901000000000000 ) }, + { 0x1.244p+126, 0x1.244p+62, INIT_U128( 0x4910000000000000, 0x4910000000000000 ) }, + { 0x1.26p+126, 0x1.26p+62, INIT_U128( 0x4980000000000000, 0x4980000000000000 ) }, + { 0x1.3p+126, 0x1.3p+62, INIT_U128( 0x4c00000000000000, 0x4c00000000000000 ) }, + { 0x1.800000000001p+126, 0x1.6000000000004p+64, INIT_U128( 0x6000000000004001, 0x6000000000004000 ) }, + { 0x1.cp+126, 0x1.00ep+71, INIT_U128( 0x7000000000000080, 0x7000000000000000 ) }, + { 0x1.c000000000008p+126, 0x1.c000000000008p+62, INIT_U128( 0x7000000000002000, 0x7000000000002000 ) }, + { 0x1.c00000000004p+126, 0x1.c00000000004p+62, INIT_U128( 0x7000000000010000, 0x7000000000010000 ) }, + { 0x1.c0000000002p+126, 0x1.c0000000002p+62, INIT_U128( 0x7000000000080000, 0x7000000000080000 ) }, + { 0x1.c000000002p+126, 0x1.c000000002p+62, INIT_U128( 0x7000000000800000, 0x7000000000800000 ) }, + { 0x1.c00000002p+126, 0x1.c00000002p+62, INIT_U128( 0x7000000008000000, 0x7000000008000000 ) }, + { 0x1.c0000008p+126, 0x1.c0000008p+62, INIT_U128( 0x7000000200000000, 0x7000000200000000 ) }, + { 0x1.c000002p+126, 0x1.c000002p+62, INIT_U128( 0x7000000800000000, 0x7000000800000000 ) }, + { 0x1.c00004p+126, 0x1.c00004p+62, INIT_U128( 0x7000010000000000, 0x7000010000000000 ) }, + { 0x1.c0002p+126, 0x1.c0002p+62, INIT_U128( 0x7000080000000000, 0x7000080000000000 ) }, + { 0x1.c008p+126, 0x1.c008p+62, INIT_U128( 0x7002000000000000, 0x7002000000000000 ) }, + { 0x1.c02p+126, 0x1.c02p+62, INIT_U128( 0x7008000000000000, 0x7008000000000000 ) }, + { 0x1.c2p+126, 0x1.c2p+62, INIT_U128( 0x7080000000000000, 0x7080000000000000 ) }, + { 0x1.dp+126, 0x1.dp+62, INIT_U128( 0x7400000000000000, 0x7400000000000000 ) }, + { 0x1.80be0cccccccdp+63, 0x1.80bc266666666p+63, INIT_U128( 0x0000000000000001, 0x80bd199999999800 ) }, + { 0x1.017c19999999ap+62, 0x1.01784cccccccdp+62, INIT_U128( 0x0000000000000000, 0x80bd199999999c00 ) }, + { 0x1.80be0cccccccdp+63, 0x1.01784cccccccdp+62, INIT_U128( 0x0000000000000001, 0x00bd199999999c00 ) }, + { 0x1.88a1831790ce8p+63, 0x1.1143062f219d8p+62, INIT_U128( 0x0000000000000001, 0x08a1831790cea000 ) }, + { 0x1.1143062f219dp+62, 0x1.88a1831790cecp+63, INIT_U128( 0x0000000000000001, 0x08a1831790cea000 ) }, + { 0x1.88a1831790ce8p+63, 0x1.88a1831790cecp+63, INIT_U128( 0x0000000000000001, 0x88a1831790cea000 ) }, + { 0x1.00014f3089001p+64, 0x1.e133333333333p+6, INIT_U128( 0x0000000000000001, 0x00014f3089001078 ) }, + { 0x1.fffffffffffffp+127, 0x1p+75, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x1.fffffffffffffp+127, 0x1.fffffffffffffp+74, INIT_U128( 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFC00000 ) }, + { 0x1.f066666666666p+6, -0x1.f066666666667p-768, INIT_U128( 0x0000000000000000, 0x000000000000007C ) }, + { 0x1.f066666666666p+6, 0x1.f066666666667p-768, INIT_U128( 0x0000000000000000, 0x000000000000007C ) }, + { 0x1.1111111111111p+124, 0x1.1p+68, INIT_U128( 0x1111111111111111, 0x0000000000000000 ) }, + { 0x0.0000000000001p-1022, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x0.0000001160e9fp-1022, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x0.0000001a26f3cp-1022, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { -0x0.0000001134f35p-1022, -0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x0.00003f9eec3ep-1022, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x0.0a40bec0e4818p-1022, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x0.0d4e1fcc5a9c4p-1022, 0x0p+0, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x1.acf5f5ef59ebfp-1007, 0x0.00000000000a8p-1022, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x1.1f45384e3e8a7p-1007, 0x0.00000000000b4p-1022, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x1.8474983f08e93p-1007, 0x0.00000000000d9p-1022, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x1.47ad6cf88f5aep-1007, 0x0.00000000000bcp-1022, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x1.2da4480a5b489p-1, 0x1.9e20ea6f3c41dp-618, INIT_U128( 0x0000000000000000, 0x0000000000000000 ) }, + { 0x1.438fba0a871f8p+0, 0x1.086e1f6e10dc4p-992, INIT_U128( 0x0000000000000000, 0x0000000000000001 ) }, + { 0x1.51c874cca390ep+0, 0x1.5dd30576bba6p-992, INIT_U128( 0x0000000000000000, 0x0000000000000001 ) }, + { 0x1.3691a8086d235p+1, 0x1.3670ebb66ce1ep-281, INIT_U128( 0x0000000000000000, 0x0000000000000002 ) }, + { 0x1.b800c73570019p+1, 0x1.1bf9094c37f21p-281, INIT_U128( 0x0000000000000000, 0x0000000000000003 ) }, + { 0x1.c1e89f3783d14p+1, 0x1.69999266d3332p-281, INIT_U128( 0x0000000000000000, 0x0000000000000003 ) }, + { 0x1.390b19fa72163p+1, 0x1.25bf7f6c4b7fp-281, INIT_U128( 0x0000000000000000, 0x0000000000000002 ) }, + { 0x1.4beee12897ddcp+2, 0x1.549d853aa93bp-815, INIT_U128( 0x0000000000000000, 0x0000000000000005 ) }, + { 0x1.e37742bfc6ee9p+2, 0x1.081a6dda1034ep-815, INIT_U128( 0x0000000000000000, 0x0000000000000007 ) }, + { 0x1.e6c0b50fcd816p+2, 0x1.c3d7967b87af3p-815, INIT_U128( 0x0000000000000000, 0x0000000000000007 ) }, + { 0x1.590290feb2052p+2, 0x1.07756f600eeaep-815, INIT_U128( 0x0000000000000000, 0x0000000000000005 ) }, + { 0x1.66154348cc2a8p+3, 0x1.bb93d1a97727ap-619, INIT_U128( 0x0000000000000000, 0x000000000000000b ) }, + { 0x1.69cf9e9ed39f4p+3, 0x1.ce842e739d086p-619, INIT_U128( 0x0000000000000000, 0x000000000000000b ) }, + { 0x1.e884574bd108bp+3, 0x1.9c6561f338cacp-619, INIT_U128( 0x0000000000000000, 0x000000000000000f ) }, + { 0x1.6263a430c4c74p+4, 0x1.6b327792d664fp-117, INIT_U128( 0x0000000000000000, 0x0000000000000016 ) }, + { 0x1.43637d1286c7p+4, 0x1.546df60aa8dbfp-117, INIT_U128( 0x0000000000000000, 0x0000000000000014 ) }, + { 0x1.faa21259f5443p+4, 0x1.b6708ecf6ce12p-117, INIT_U128( 0x0000000000000000, 0x000000000000001f ) }, + { 0x1.fd3105d1fa62p+4, 0x1.370912046e122p-117, INIT_U128( 0x0000000000000000, 0x000000000000001f ) }, + { 0x1.cf952d399f2a5p+5, 0x1.0d283ebe1a508p-735, INIT_U128( 0x0000000000000000, 0x0000000000000039 ) }, + { 0x1.6ac8f880d591fp+5, 0x1.ec284da5d8509p-735, INIT_U128( 0x0000000000000000, 0x000000000000002d ) }, + { 0x1.919c82bf2339p+5, 0x1.a58971fd4b12ep-735, INIT_U128( 0x0000000000000000, 0x0000000000000032 ) }, + { 0x1.789a89ccf1351p+5, 0x1.ebd48283d7a91p-735, INIT_U128( 0x0000000000000000, 0x000000000000002f ) }, + { 0x1.8db2068d1b641p+6, 0x1.056174ca0ac2ep-802, INIT_U128( 0x0000000000000000, 0x0000000000000063 ) }, + { 0x1.8d618e6f1ac32p+6, 0x1.0643da660c87cp-802, INIT_U128( 0x0000000000000000, 0x0000000000000063 ) }, + { 0x1.f10fc45fe21f8p+6, 0x1.d71f2d6bae3e5p-802, INIT_U128( 0x0000000000000000, 0x000000000000007c ) }, + { 0x1.1cafcb76395fap+8, 0x1.026dfe9a04dcp-78, INIT_U128( 0x0000000000000000, 0x000000000000011c ) }, + { 0x1.8b9a3b5917348p+8, 0x1.f64ef081ec9dep-78, INIT_U128( 0x0000000000000000, 0x000000000000018b ) }, + { 0x1.347ea22c68fd4p+8, 0x1.a86c77e750d8fp-78, INIT_U128( 0x0000000000000000, 0x0000000000000134 ) }, + { 0x1.c498c82389319p+8, 0x1.0d4d96061a9b3p-78, INIT_U128( 0x0000000000000000, 0x00000000000001c4 ) }, + { 0x1.3e4fa8b47c9f5p+9, 0x1.d0718139a0e3p-293, INIT_U128( 0x0000000000000000, 0x000000000000027c ) }, + { 0x1.5ffd3878bffa7p+9, 0x1.1828a29c30514p-293, INIT_U128( 0x0000000000000000, 0x00000000000002bf ) }, + { 0x1.bbbb3b8577768p+9, 0x1.ba79b21b74f36p-293, INIT_U128( 0x0000000000000000, 0x0000000000000377 ) }, + { 0x1.8777cb810eefap+9, 0x1.bb3afdc57676p-293, INIT_U128( 0x0000000000000000, 0x000000000000030e ) }, + { 0x1.8e7992a11cf32p+10, 0x1.a18e4033431c8p-789, INIT_U128( 0x0000000000000000, 0x0000000000000639 ) }, + { 0x1.7684faeced0ap+10, 0x1.5f11706abe22ep-789, INIT_U128( 0x0000000000000000, 0x00000000000005da ) }, + { 0x1.7d7ac11afaf58p+10, 0x1.64553beec8aa8p-789, INIT_U128( 0x0000000000000000, 0x00000000000005f5 ) }, + { 0x1.a540fa454a81fp+10, 0x1.329efbd6653ep-789, INIT_U128( 0x0000000000000000, 0x0000000000000695 ) }, + { 0x1.92ed812325dbp+11, 0x0.000012eafc716p-1022, INIT_U128( 0x0000000000000000, 0x0000000000000c97 ) }, + { 0x1.b10abb4562158p+11, 0x0.00001e4765564p-1022, INIT_U128( 0x0000000000000000, 0x0000000000000d88 ) }, + { 0x1.f6751879ecea3p+11, 0x0.000014435b4b9p-1022, INIT_U128( 0x0000000000000000, 0x0000000000000fb3 ) }, + { 0x1.32e6b0a465cd6p+11, 0x0.00001729d5c09p-1022, INIT_U128( 0x0000000000000000, 0x0000000000000997 ) }, + { 0x1.11f336c623e67p+12, 0x1.9d9af61f3b35fp-489, INIT_U128( 0x0000000000000000, 0x000000000000111f ) }, + { 0x1.18ebab5631d76p+12, 0x1.47d8de9e8fb1cp-489, INIT_U128( 0x0000000000000000, 0x000000000000118e ) }, + { 0x1.c25a29f984b45p+12, 0x1.c65b51e78cb6ap-489, INIT_U128( 0x0000000000000000, 0x0000000000001c25 ) }, + { 0x1.cf37f3299e6ffp+12, 0x1.38601ed270c04p-489, INIT_U128( 0x0000000000000000, 0x0000000000001cf3 ) }, + { 0x1.00db141c01b62p+13, 0x1.a4ea801149d5p-963, INIT_U128( 0x0000000000000000, 0x000000000000201b ) }, + { 0x1.b81f3643703e7p+13, 0x1.849a11a509342p-963, INIT_U128( 0x0000000000000000, 0x0000000000003703 ) }, + { 0x1.6dbbb6a4db777p+13, 0x1.362f46546c5e9p-963, INIT_U128( 0x0000000000000000, 0x0000000000002db7 ) }, + { 0x1.eeb645abdd6c8p+13, 0x1.1edee6683dbddp-963, INIT_U128( 0x0000000000000000, 0x0000000000003dd6 ) }, + { 0x1.dc7ac6d3b8f59p+14, 0x1.3a4d2846749a5p-96, INIT_U128( 0x0000000000000000, 0x000000000000771e ) }, + { 0x1.51b38df4a3672p+14, 0x1.ef5f5533debeap-96, INIT_U128( 0x0000000000000000, 0x000000000000546c ) }, + { 0x1.5cdcee10b9b9ep+14, 0x1.dd44c049ba898p-96, INIT_U128( 0x0000000000000000, 0x0000000000005737 ) }, + { 0x1.f5266d45ea4cdp+14, 0x1.3970615e72e0cp-96, INIT_U128( 0x0000000000000000, 0x0000000000007d49 ) }, + { 0x1.2ab9252a55724p+15, 0x1.a85ba3d950b74p-690, INIT_U128( 0x0000000000000000, 0x000000000000955c ) }, + { 0x1.707a4edee0f4ap+15, 0x1.00541f2800a84p-690, INIT_U128( 0x0000000000000000, 0x000000000000b83d ) }, + { 0x1.594c6252b298cp+15, 0x1.837b6c0706f6ep-690, INIT_U128( 0x0000000000000000, 0x000000000000aca6 ) }, + { 0x1.41fad8e683f5bp+15, 0x1.7cb3a2bef9674p-690, INIT_U128( 0x0000000000000000, 0x000000000000a0fd ) }, + { 0x1.f150e9b3e2a1dp+16, 0x1.155a86a62ab51p-762, INIT_U128( 0x0000000000000000, 0x000000000001f150 ) }, + { 0x1.0a3ca44214794p+16, 0x1.5c85e07eb90bcp-762, INIT_U128( 0x0000000000000000, 0x0000000000010a3c ) }, + { 0x1.0ef4814e1de9p+16, 0x1.2cd0510659a0ap-762, INIT_U128( 0x0000000000000000, 0x0000000000010ef4 ) }, + { 0x1.99373a97326e7p+16, 0x1.98d239d731a47p-762, INIT_U128( 0x0000000000000000, 0x0000000000019937 ) }, + { 0x1.0062da5400c5cp+17, 0x1.12b3124825662p-940, INIT_U128( 0x0000000000000000, 0x00000000000200c5 ) }, + { 0x1.8ac0f0251581ep+17, 0x1.60b254d0c164ap-940, INIT_U128( 0x0000000000000000, 0x0000000000031581 ) }, + { 0x1.51c0eb94a381ep+17, 0x1.ce1da4059c3b4p-940, INIT_U128( 0x0000000000000000, 0x000000000002a381 ) }, + { 0x1.5e83e6a4bd07dp+17, 0x1.adcff7815b9ffp-940, INIT_U128( 0x0000000000000000, 0x000000000002bd07 ) }, + { 0x1.242e55bc485cap+18, 0x0.000000000001fp-1022, INIT_U128( 0x0000000000000000, 0x00000000000490b9 ) }, + { 0x1.7d59ac2cfab36p+18, 0x0.000000000001p-1022, INIT_U128( 0x0000000000000000, 0x000000000005f566 ) }, + { 0x1.d19e6101a33ccp+18, 0x0.0000000000014p-1022, INIT_U128( 0x0000000000000000, 0x0000000000074679 ) }, + { 0x1.34c9981869933p+18, 0x0.0000000000011p-1022, INIT_U128( 0x0000000000000000, 0x000000000004d326 ) }, + { 0x1.c066e34f80cddp+19, 0x1.e3f363b5c7e6dp-881, INIT_U128( 0x0000000000000000, 0x00000000000e0337 ) }, + { 0x1.df32bc2fbe658p+19, 0x1.df947163bf28ep-881, INIT_U128( 0x0000000000000000, 0x00000000000ef995 ) }, + { 0x1.3bbc859e7779p+19, 0x1.0773506c0ee6ap-881, INIT_U128( 0x0000000000000000, 0x000000000009dde4 ) }, + { 0x1.3b65fdae76ccp+19, 0x1.36924fde6d24ap-881, INIT_U128( 0x0000000000000000, 0x000000000009db2f ) }, + { 0x1.52c7a810a58f5p+20, 0x1.a11a939f42352p-561, INIT_U128( 0x0000000000000000, 0x0000000000152c7a ) }, + { 0x1.9546ee252a8dep+20, 0x1.eeb4a28ddd695p-561, INIT_U128( 0x0000000000000000, 0x000000000019546e ) }, + { 0x1.f50465bdea08cp+20, 0x1.7288f4c2e511ep-561, INIT_U128( 0x0000000000000000, 0x00000000001f5046 ) }, + { 0x1.b8199d2770334p+20, 0x1.a2d4ddfb45a9cp-561, INIT_U128( 0x0000000000000000, 0x00000000001b8199 ) }, + { 0x1.efe67d0fdfccfp+21, 0x1.05ac37920b587p-121, INIT_U128( 0x0000000000000000, 0x00000000003dfccf ) }, + { 0x1.a1c8a86343915p+21, 0x1.ff7f144bfefe2p-121, INIT_U128( 0x0000000000000000, 0x0000000000343915 ) }, + { 0x1.0b3b76001676fp+21, 0x1.742fba58e85f8p-121, INIT_U128( 0x0000000000000000, 0x000000000021676e ) }, + { 0x1.cb12f6579625fp+21, 0x1.5e77e020bcefcp-121, INIT_U128( 0x0000000000000000, 0x000000000039625e ) }, + { 0x1.bd380f437a702p+22, 0x1.491fe5e8923fcp-995, INIT_U128( 0x0000000000000000, 0x00000000006f4e03 ) }, + { 0x1.46fbb89c8df77p+22, 0x1.a09fc8f7413f9p-995, INIT_U128( 0x0000000000000000, 0x000000000051beee ) }, + { 0x1.17e871f42fd0ep+22, 0x1.a11fc1a7423f8p-995, INIT_U128( 0x0000000000000000, 0x000000000045fa1c ) }, + { 0x1.277e999a4efd3p+22, 0x1.4bd3e11097a7cp-995, INIT_U128( 0x0000000000000000, 0x000000000049dfa6 ) }, + { 0x1.6e4d3250dc9a6p+23, 0x1.edf09145dbe12p-447, INIT_U128( 0x0000000000000000, 0x0000000000b72699 ) }, + { 0x1.eb0413bfd6083p+23, 0x1.29c840b053908p-447, INIT_U128( 0x0000000000000000, 0x0000000000f58209 ) }, + { 0x1.283f1d32507e4p+23, 0x1.06daa0fe0db54p-447, INIT_U128( 0x0000000000000000, 0x0000000000941f8e ) }, + { 0x1.cf7790bd9eef2p+23, 0x1.22ebe99845d7dp-447, INIT_U128( 0x0000000000000000, 0x0000000000e7bbc8 ) }, + { 0x1.39fb1e1473f64p+24, 0x1.baafa729755f5p-263, INIT_U128( 0x0000000000000000, 0x000000000139fb1e ) }, + { 0x1.553510f0aa6a2p+24, 0x1.806a3d5d00d48p-263, INIT_U128( 0x0000000000000000, 0x0000000001553510 ) }, + { 0x1.876715390ece3p+24, 0x1.cdf668119becdp-263, INIT_U128( 0x0000000000000000, 0x0000000001876715 ) }, + { 0x1.11816ac62302ep+24, 0x1.5e8451ecbd08ap-263, INIT_U128( 0x0000000000000000, 0x000000000111816a ) }, + { 0x1.3e7e811e7cfdp+25, 0x1.2dc6a5685b8d4p-155, INIT_U128( 0x0000000000000000, 0x00000000027cfd02 ) }, + { 0x1.6ebc2c8cdd786p+25, 0x1.22f38cd645e72p-155, INIT_U128( 0x0000000000000000, 0x0000000002dd7859 ) }, + { 0x1.421ccf068439ap+25, 0x1.bef8b6f57df17p-155, INIT_U128( 0x0000000000000000, 0x000000000284399e ) }, + { 0x1.e10ee555c21dcp+25, 0x1.033cdd7a0679cp-155, INIT_U128( 0x0000000000000000, 0x0000000003c21dca ) }, + { 0x1.f0b6e7ede16ddp+26, 0x1.bc0a81517815p-634, INIT_U128( 0x0000000000000000, 0x0000000007c2db9f ) }, + { 0x1.f7b66dc5ef6cdp+26, 0x1.2bd3184a57a63p-634, INIT_U128( 0x0000000000000000, 0x0000000007ded9b7 ) }, + { 0x1.259706244b2e1p+26, 0x1.8b7dd07716fbap-634, INIT_U128( 0x0000000000000000, 0x0000000004965c18 ) }, + { 0x1.fdf5519ffbeaap+26, 0x1.19d4925433a92p-634, INIT_U128( 0x0000000000000000, 0x0000000007f7d546 ) }, + { 0x1.bb13b1d776276p+27, 0x1.e509cb23ca13ap-395, INIT_U128( 0x0000000000000000, 0x000000000dd89d8e ) }, + { 0x1.20754b2a40eaap+27, 0x1.bcc8cd6b7991ap-395, INIT_U128( 0x0000000000000000, 0x000000000903aa59 ) }, + { 0x1.dc036999b806dp+27, 0x1.62b438eec5687p-395, INIT_U128( 0x0000000000000000, 0x000000000ee01b4c ) }, + { 0x1.92b76e3d256eep+27, 0x1.33f6413067ec8p-395, INIT_U128( 0x0000000000000000, 0x000000000c95bb71 ) }, + { 0x1.7a6c4408f4d88p+28, 0x1.0f6d05b41edap-716, INIT_U128( 0x0000000000000000, 0x0000000017a6c440 ) }, + { 0x1.25d2c9ae4ba59p+28, 0x1.005f5a6a00becp-716, INIT_U128( 0x0000000000000000, 0x00000000125d2c9a ) }, + { 0x1.c8949d0b91293p+28, 0x1.6e7ca504dcf94p-716, INIT_U128( 0x0000000000000000, 0x000000001c8949d0 ) }, + { 0x1.21af1f7a435e4p+28, 0x1.98e05ef731c0cp-716, INIT_U128( 0x0000000000000000, 0x00000000121af1f7 ) }, + { 0x1.307b63f060f6cp+29, 0x1.17d4949a2fa92p-112, INIT_U128( 0x0000000000000000, 0x00000000260f6c7e ) }, + { 0x1.053d62740a7acp+29, 0x1.a8881e6551104p-112, INIT_U128( 0x0000000000000000, 0x0000000020a7ac4e ) }, + { 0x1.9b60d35b36c1ap+29, 0x1.005bb09600b76p-112, INIT_U128( 0x0000000000000000, 0x00000000336c1a6b ) }, + { 0x1.3ba73afe774e8p+29, 0x1.0efca74e1df95p-112, INIT_U128( 0x0000000000000000, 0x000000002774e75f ) }, + { 0x1.dd796675baf2dp+30, 0x1.aaba00775574p-990, INIT_U128( 0x0000000000000000, 0x00000000775e599d ) }, + { 0x1.8b282c8d16506p+30, 0x1.4e04f8449c09fp-990, INIT_U128( 0x0000000000000000, 0x0000000062ca0b23 ) }, + { 0x1.7d6ab930fad57p+30, 0x1.764a6e3cec94ep-990, INIT_U128( 0x0000000000000000, 0x000000005f5aae4c ) }, + { 0x1.6906027cd20cp+30, 0x1.d5b4ef4dab69ep-990, INIT_U128( 0x0000000000000000, 0x000000005a41809f ) }, + { 0x1.04a9da360953cp+31, 0x1.6c11a2e4d8234p-857, INIT_U128( 0x0000000000000000, 0x000000008254ed1b ) }, + { 0x1.fbba6e93f774ep+31, 0x1.0e9a6e5c1d34ep-857, INIT_U128( 0x0000000000000000, 0x00000000fddd3749 ) }, + { 0x1.380b108470162p+31, 0x1.65c0e5f6cb81cp-857, INIT_U128( 0x0000000000000000, 0x000000009c058842 ) }, + { 0x1.050dfc000a1cp+31, 0x1.1df2fc803be6p-857, INIT_U128( 0x0000000000000000, 0x000000008286fe00 ) }, + { 0x1.88bf9e1d117f4p+32, 0x1.8dd4aa1b1ba95p-126, INIT_U128( 0x0000000000000000, 0x0000000188bf9e1d ) }, + { 0x1.8b35d7ff166bbp+32, 0x1.91ca210923944p-126, INIT_U128( 0x0000000000000000, 0x000000018b35d7ff ) }, + { 0x1.286a366250d47p+32, 0x1.012c86ac02591p-126, INIT_U128( 0x0000000000000000, 0x00000001286a3662 ) }, + { 0x1.ef233cd5de467p+32, 0x1.2292a62645255p-126, INIT_U128( 0x0000000000000000, 0x00000001ef233cd5 ) }, + { 0x1.917a959722f53p+33, 0x1.85a7d93f0b4fbp-478, INIT_U128( 0x0000000000000000, 0x0000000322f52b2e ) }, + { 0x1.f630053bec6p+33, 0x1.f79a5227ef34bp-478, INIT_U128( 0x0000000000000000, 0x00000003ec600a77 ) }, + { 0x1.1a062b14340c6p+33, 0x1.21179acc422f4p-478, INIT_U128( 0x0000000000000000, 0x00000002340c5628 ) }, + { 0x1.d62acf15ac55ap+33, 0x1.bf1cd2697e39ap-478, INIT_U128( 0x0000000000000000, 0x00000003ac559e2b ) }, + { 0x1.823ddfaf047bcp+34, 0x1.e2d35df1c5a6cp-649, INIT_U128( 0x0000000000000000, 0x0000000608f77ebc ) }, + { 0x1.996ef6e332ddfp+34, 0x1.7af28278f5e5p-649, INIT_U128( 0x0000000000000000, 0x0000000665bbdb8c ) }, + { 0x1.81a2bfc703458p+34, 0x1.acc15cd15982cp-649, INIT_U128( 0x0000000000000000, 0x00000006068aff1c ) }, + { 0x1.4517e98e8a2fdp+34, 0x1.a3233fc546468p-649, INIT_U128( 0x0000000000000000, 0x00000005145fa63a ) }, + { 0x1.09f551a013eaap+35, 0x0.0000000000006p-1022, INIT_U128( 0x0000000000000000, 0x000000084faa8d00 ) }, + { 0x1.a2911b3d45224p+35, 0x0.0000000000005p-1022, INIT_U128( 0x0000000000000000, 0x0000000d1488d9ea ) }, + { 0x1.77a301deef46p+35, 0x0.0000000000008p-1022, INIT_U128( 0x0000000000000000, 0x0000000bbd180ef7 ) }, + { 0x1.f60ea85fec1d5p+35, 0x0.0000000000006p-1022, INIT_U128( 0x0000000000000000, 0x0000000fb07542ff ) }, + { 0x1.75c28ed8eb852p+36, 0x1.64300234c86p-938, INIT_U128( 0x0000000000000000, 0x000000175c28ed8e ) }, + { 0x1.394f8bae729f2p+36, 0x1.2119204042324p-938, INIT_U128( 0x0000000000000000, 0x0000001394f8bae7 ) }, + { 0x1.94d6bc7929ad8p+36, 0x1.4a8aa2aa95154p-938, INIT_U128( 0x0000000000000000, 0x000000194d6bc792 ) }, + { 0x1.1f519dcc3ea34p+36, 0x1.b4fbc9c969f79p-938, INIT_U128( 0x0000000000000000, 0x00000011f519dcc3 ) }, + { 0x1.bb2fb46f765f6p+37, 0x1.cd4047139a809p-718, INIT_U128( 0x0000000000000000, 0x0000003765f68dee ) }, + { 0x1.f80989d1f0131p+37, 0x1.c0546f4180a8ep-718, INIT_U128( 0x0000000000000000, 0x0000003f01313a3e ) }, + { 0x1.90be9171217d2p+37, 0x1.bcc6089d798c1p-718, INIT_U128( 0x0000000000000000, 0x0000003217d22e24 ) }, + { 0x1.37469d226e8d4p+37, 0x1.06aff8000d5ffp-718, INIT_U128( 0x0000000000000000, 0x00000026e8d3a44d ) }, + { 0x1.2e0114905c022p+38, 0x1.298bde145317cp-115, INIT_U128( 0x0000000000000000, 0x0000004b80452417 ) }, + { 0x1.77354c42ee6aap+38, 0x1.d9a75513b34eap-115, INIT_U128( 0x0000000000000000, 0x0000005dcd5310bb ) }, + { 0x1.0881a80c11035p+38, 0x1.44e5e01889cbcp-115, INIT_U128( 0x0000000000000000, 0x00000042206a0304 ) }, + { 0x1.a32b590f4656bp+38, 0x1.760fbd2eec1f8p-115, INIT_U128( 0x0000000000000000, 0x00000068cad643d1 ) }, + { 0x1.e7bc6861cf78dp+39, 0x1.72addca8e55bcp-767, INIT_U128( 0x0000000000000000, 0x000000f3de3430e7 ) }, + { 0x1.e1e11b1bc3c24p+39, 0x1.713729dae26e5p-767, INIT_U128( 0x0000000000000000, 0x000000f0f08d8de1 ) }, + { 0x1.8bbb377f17767p+39, 0x1.c296d213852dap-767, INIT_U128( 0x0000000000000000, 0x000000c5dd9bbf8b ) }, + { 0x1.7cb13d18f9628p+39, 0x1.8dcf87351b9f1p-767, INIT_U128( 0x0000000000000000, 0x000000be589e8c7c ) }, + { 0x1.1ddbaf383bb76p+40, 0x1.20c8d9d04191bp-497, INIT_U128( 0x0000000000000000, 0x0000011ddbaf383b ) }, + { 0x1.fde474e3fbc8ep+40, 0x1.7e6de35afcdbcp-497, INIT_U128( 0x0000000000000000, 0x000001fde474e3fb ) }, + { 0x1.02a202b00544p+40, 0x1.311b40f462368p-497, INIT_U128( 0x0000000000000000, 0x00000102a202b005 ) }, + { 0x1.ec0b6577d816cp+40, 0x1.8e49e85d1c93dp-497, INIT_U128( 0x0000000000000000, 0x000001ec0b6577d8 ) }, + { 0x1.95fa4b912bf4ap+41, 0x1.295d953652bb2p-872, INIT_U128( 0x0000000000000000, 0x0000032bf4972257 ) }, + { 0x1.fd243093fa486p+41, 0x1.91e0a45723c14p-872, INIT_U128( 0x0000000000000000, 0x000003fa486127f4 ) }, + { 0x1.d0beeb21a17dep+41, 0x1.97f98e272ff32p-872, INIT_U128( 0x0000000000000000, 0x000003a17dd64342 ) }, + { 0x1.750735faea0e6p+41, 0x1.97a4c8c92f499p-872, INIT_U128( 0x0000000000000000, 0x000002ea0e6bf5d4 ) }, + { 0x1.ab409c8f56814p+42, 0x1.1e820fc23d042p-84, INIT_U128( 0x0000000000000000, 0x000006ad02723d5a ) }, + { 0x1.85e79a910bcf3p+42, 0x1.75d44930eba89p-84, INIT_U128( 0x0000000000000000, 0x000006179e6a442f ) }, + { 0x1.e2fa47dfc5f49p+42, 0x1.f91c1067f2382p-84, INIT_U128( 0x0000000000000000, 0x0000078be91f7f17 ) }, + { 0x1.ecaf7567d95eep+42, 0x1.dd787be3baf1p-84, INIT_U128( 0x0000000000000000, 0x000007b2bdd59f65 ) }, + { 0x1.4fd770a89faeep+43, 0x1.883956a11072bp-669, INIT_U128( 0x0000000000000000, 0x00000a7ebb8544fd ) }, + { 0x1.b2b2aa2d65655p+43, 0x1.0c2516f2184a3p-669, INIT_U128( 0x0000000000000000, 0x00000d9595516b2b ) }, + { 0x1.5848b5b4b0916p+43, 0x1.d9a0d8cfb341bp-669, INIT_U128( 0x0000000000000000, 0x00000ac245ada584 ) }, + { 0x1.be7daa1f7cfb5p+43, 0x1.f0c9d223e193bp-669, INIT_U128( 0x0000000000000000, 0x00000df3ed50fbe7 ) }, + { 0x1.3f6d46f07eda9p+44, 0x1.3d2fa1b27a5f4p-539, INIT_U128( 0x0000000000000000, 0x000013f6d46f07ed ) }, + { 0x1.5eb8dcaebd71cp+44, 0x1.8e170e7b1c2e2p-539, INIT_U128( 0x0000000000000000, 0x000015eb8dcaebd7 ) }, + { 0x1.893b63631276cp+44, 0x1.9447ca53288f9p-539, INIT_U128( 0x0000000000000000, 0x00001893b6363127 ) }, + { 0x1.4e089b389c114p+44, 0x1.d191b053a3236p-539, INIT_U128( 0x0000000000000000, 0x000014e089b389c1 ) }, + { 0x1.2e36d90e5c6dbp+45, 0x1.314d394c629a7p-889, INIT_U128( 0x0000000000000000, 0x000025c6db21cb8d ) }, + { 0x1.7f784de4fef0ap+45, 0x1.5413e986a827dp-889, INIT_U128( 0x0000000000000000, 0x00002fef09bc9fde ) }, + { 0x1.74448388e889p+45, 0x1.752c3c2cea588p-889, INIT_U128( 0x0000000000000000, 0x00002e8890711d11 ) }, + { 0x1.ebb20c51d7641p+45, 0x1.50a52f7ca14a6p-889, INIT_U128( 0x0000000000000000, 0x00003d76418a3aec ) }, + { 0x1.4b51066896a21p+46, 0x1.d43cc973a8799p-550, INIT_U128( 0x0000000000000000, 0x000052d4419a25a8 ) }, + { 0x1.070f0d280e1e2p+46, 0x1.c25aa6dd84b55p-550, INIT_U128( 0x0000000000000000, 0x000041c3c34a0387 ) }, + { 0x1.7f735ca4fee6cp+46, 0x1.a92889d752511p-550, INIT_U128( 0x0000000000000000, 0x00005fdcd7293fb9 ) }, + { 0x1.72ed987ae5db3p+46, 0x1.fae14a03f5c29p-550, INIT_U128( 0x0000000000000000, 0x00005cbb661eb976 ) }, + { 0x1.7352fdf0e6a6p+47, 0x1.1a64275034c85p-857, INIT_U128( 0x0000000000000000, 0x0000b9a97ef87353 ) }, + { 0x1.9f4b98f33e973p+47, 0x1.657b10c0caf62p-857, INIT_U128( 0x0000000000000000, 0x0000cfa5cc799f4b ) }, + { 0x1.b12eb79b625d7p+47, 0x1.4826ca96904dap-857, INIT_U128( 0x0000000000000000, 0x0000d8975bcdb12e ) }, + { 0x1.6148cbcac291ap+47, 0x1.8672a1ad0ce54p-857, INIT_U128( 0x0000000000000000, 0x0000b0a465e56148 ) }, + { 0x1.1df8159e3bf02p+48, 0x1.7c6dbd68f8db8p-407, INIT_U128( 0x0000000000000000, 0x00011df8159e3bf0 ) }, + { 0x1.d8e17545b1c2ep+48, 0x1.959fcc5f2b3fap-407, INIT_U128( 0x0000000000000000, 0x0001d8e17545b1c2 ) }, + { 0x1.ea57e075d4afcp+48, 0x1.56705400ace0ap-407, INIT_U128( 0x0000000000000000, 0x0001ea57e075d4af ) }, + { 0x1.d2aa9e99a5554p+48, 0x1.9ebcab993d796p-407, INIT_U128( 0x0000000000000000, 0x0001d2aa9e99a555 ) }, + { 0x1.4fe075a49fc0ep+49, 0x1.e950f533d2a1ep-694, INIT_U128( 0x0000000000000000, 0x00029fc0eb493f81 ) }, + { 0x1.a936db51526dcp+49, 0x1.8a1397df14273p-694, INIT_U128( 0x0000000000000000, 0x0003526db6a2a4db ) }, + { 0x1.138ce7682719dp+49, 0x1.7f879c76ff0f4p-694, INIT_U128( 0x0000000000000000, 0x00022719ced04e33 ) }, + { 0x1.21e981b043d3p+49, 0x1.eaefe1f3d5dfcp-694, INIT_U128( 0x0000000000000000, 0x000243d3036087a6 ) }, + { 0x1.793e9a3cf27d4p+50, 0x1.40169b90802d4p-934, INIT_U128( 0x0000000000000000, 0x0005e4fa68f3c9f5 ) }, + { 0x1.7e1caadcfc396p+50, 0x1.371020466e204p-934, INIT_U128( 0x0000000000000000, 0x0005f872ab73f0e5 ) }, + { 0x1.33a019d667403p+50, 0x1.9c77f7cb38effp-934, INIT_U128( 0x0000000000000000, 0x0004ce8067599d00 ) }, + { 0x1.b4966ecb692cep+50, 0x1.c4dd0f8989ba2p-934, INIT_U128( 0x0000000000000000, 0x0006d259bb2da4b3 ) }, + { 0x1.822ad9630455bp+51, 0x1.3fade6a07f5bdp-561, INIT_U128( 0x0000000000000000, 0x000c1156cb1822ad ) }, + { 0x1.3a77dd3c74efcp+51, 0x1.55dd3018abba6p-561, INIT_U128( 0x0000000000000000, 0x0009d3bee9e3a77e ) }, + { 0x1.d375773da6eafp+51, 0x1.ad40b9955a817p-561, INIT_U128( 0x0000000000000000, 0x000e9babb9ed3757 ) }, + { 0x1.16059bfe2c0b4p+51, 0x1.ff801c63ff003p-561, INIT_U128( 0x0000000000000000, 0x0008b02cdff1605a ) }, + { 0x1.af8f1e955f1e4p+52, 0x1.2c4cc4fa58998p-237, INIT_U128( 0x0000000000000000, 0x001af8f1e955f1e4 ) }, + { 0x1.579e5322af3cap+52, 0x1.e9974457d32e8p-237, INIT_U128( 0x0000000000000000, 0x001579e5322af3ca ) }, + { 0x1.2b9d921a573b2p+52, 0x1.d8798265b0f3p-237, INIT_U128( 0x0000000000000000, 0x0012b9d921a573b2 ) }, + { 0x1.b746d5596e8dbp+52, 0x1.a75bfc954eb8p-237, INIT_U128( 0x0000000000000000, 0x001b746d5596e8db ) }, + { 0x1.497ec4f092fd8p+53, 0x1.5c597ab2b8b3p-364, INIT_U128( 0x0000000000000000, 0x00292fd89e125fb0 ) }, + { 0x1.8a65536914caap+53, 0x1.958565492b0adp-364, INIT_U128( 0x0000000000000000, 0x00314caa6d229954 ) }, + { 0x1.11b7146c236e2p+53, 0x1.3154f5b662a9ep-364, INIT_U128( 0x0000000000000000, 0x002236e28d846dc4 ) }, + { 0x1.f71b5e7bee36cp+53, 0x1.efc7aa5ddf8f6p-364, INIT_U128( 0x0000000000000000, 0x003ee36bcf7dc6d8 ) }, + { 0x1.5a71157ab4e22p+54, 0x1.b4fd1c6b69fa4p-39, INIT_U128( 0x0000000000000000, 0x00569c455ead3888 ) }, + { 0x1.4ab52e26956a6p+54, 0x1.204833ee40906p-39, INIT_U128( 0x0000000000000000, 0x0052ad4b89a55a98 ) }, + { 0x1.7b9298b4f7253p+54, 0x1.084ca6f410995p-39, INIT_U128( 0x0000000000000000, 0x005ee4a62d3dc94c ) }, + { 0x1.8be06c0317c0ep+54, 0x1.9677f6df2ceffp-39, INIT_U128( 0x0000000000000000, 0x0062f81b00c5f038 ) }, + { 0x1.53534daca6a6ap+55, 0x1.af26be6f5e4d8p-905, INIT_U128( 0x0000000000000000, 0x00a9a9a6d6535350 ) }, + { 0x1.ee7424c1dce84p+55, 0x1.38a375387146ep-905, INIT_U128( 0x0000000000000000, 0x00f73a1260ee7420 ) }, + { 0x1.4275718484eaep+55, 0x1.693f342ed27e6p-905, INIT_U128( 0x0000000000000000, 0x00a13ab8c2427570 ) }, + { 0x1.4e48bc049c918p+55, 0x1.30d3b39661a76p-905, INIT_U128( 0x0000000000000000, 0x00a7245e024e48c0 ) }, + { 0x1.6fcb01f0df96p+56, 0x1.f3322f93e6646p-339, INIT_U128( 0x0000000000000000, 0x016fcb01f0df9600 ) }, + { 0x1.6f16f2e4de2dep+56, 0x1.b50cb2d16a196p-339, INIT_U128( 0x0000000000000000, 0x016f16f2e4de2de0 ) }, + { 0x1.6fcb3cb2df968p+56, 0x1.f7623e45eec48p-339, INIT_U128( 0x0000000000000000, 0x016fcb3cb2df9680 ) }, + { 0x1.a41a78314834fp+56, 0x1.ee812a93dd026p-339, INIT_U128( 0x0000000000000000, 0x01a41a78314834f0 ) }, + { 0x1.73544f7ce6a8ap+57, 0x1.fbf6a069f7ed4p-786, INIT_U128( 0x0000000000000000, 0x02e6a89ef9cd5140 ) }, + { 0x1.8d4beb3f1a97ep+57, 0x1.6f6e15a0dedc2p-786, INIT_U128( 0x0000000000000000, 0x031a97d67e352fc0 ) }, + { 0x1.70dfc328e1bf8p+57, 0x1.56963a34ad2c8p-786, INIT_U128( 0x0000000000000000, 0x02e1bf8651c37f00 ) }, + { 0x1.6e5e39acdcbc7p+57, 0x1.62dfb7d4c5bf7p-786, INIT_U128( 0x0000000000000000, 0x02dcbc7359b978e0 ) }, + { 0x1.10a375142146ep+58, 0x1.dde963f1bbd2cp-687, INIT_U128( 0x0000000000000000, 0x04428dd450851b80 ) }, + { 0x1.7eacb1acfd596p+58, 0x1.e59952a9cb32bp-687, INIT_U128( 0x0000000000000000, 0x05fab2c6b3f56580 ) }, + { 0x1.3f2bac4a7e576p+58, 0x1.d21ee367a43ddp-687, INIT_U128( 0x0000000000000000, 0x04fcaeb129f95d80 ) }, + { 0x1.be738acb7ce71p+58, 0x1.d4b6334fa96c7p-687, INIT_U128( 0x0000000000000000, 0x06f9ce2b2df39c40 ) }, + { 0x1.b322eff56645ep+59, 0x0.00000014b8158p-1022, INIT_U128( 0x0000000000000000, 0x0d99177fab322f00 ) }, + { 0x1.b8dfbdbd71bf8p+59, 0x0.00000010ac2d6p-1022, INIT_U128( 0x0000000000000000, 0x0dc6fdedeb8dfc00 ) }, + { 0x1.e45f6d33c8bedp+59, 0x0.0000001c79003p-1022, INIT_U128( 0x0000000000000000, 0x0f22fb699e45f680 ) }, + { 0x1.10c7106e218e2p+59, 0x0.0000001ea2457p-1022, INIT_U128( 0x0000000000000000, 0x08863883710c7100 ) }, + { 0x1.c48c230989185p+60, 0x1.a60d3fb34c1a8p-116, INIT_U128( 0x0000000000000000, 0x1c48c23098918500 ) }, + { 0x1.5e9345fabd268p+60, 0x1.4898e6d49131dp-116, INIT_U128( 0x0000000000000000, 0x15e9345fabd26800 ) }, + { 0x1.b56942576ad28p+60, 0x1.aff4a0655fe94p-116, INIT_U128( 0x0000000000000000, 0x1b56942576ad2800 ) }, + { 0x1.7f865930ff0cbp+60, 0x1.13a0876e27411p-116, INIT_U128( 0x0000000000000000, 0x17f865930ff0cb00 ) }, + { 0x1.ef482c31de906p+61, 0x1.43e655d887ccap-501, INIT_U128( 0x0000000000000000, 0x3de905863bd20c00 ) }, + { 0x1.9fa15a7d3f42bp+61, 0x1.b00fcc55601fap-501, INIT_U128( 0x0000000000000000, 0x33f42b4fa7e85600 ) }, + { 0x1.d2c465fda588dp+61, 0x1.98c2f6e73185fp-501, INIT_U128( 0x0000000000000000, 0x3a588cbfb4b11a00 ) }, + { 0x1.f038608de070cp+61, 0x1.7b4fa8a0f69f5p-501, INIT_U128( 0x0000000000000000, 0x3e070c11bc0e1800 ) }, + { 0x1.adfb2db35bf66p+62, 0x1.38efaf6271df6p+8, INIT_U128( 0x0000000000000000, 0x6b7ecb6cd6fd9938 ) }, + { 0x1.1679474c2cf29p+62, 0x1.ae04d7f95c09bp+8, INIT_U128( 0x0000000000000000, 0x459e51d30b3ca5ae ) }, + { 0x1.890c63b91218cp+62, 0x1.133030ac26606p+8, INIT_U128( 0x0000000000000000, 0x624318ee44863113 ) }, + { 0x1.08fc576811f8bp+62, 0x1.521d194ea43a3p+8, INIT_U128( 0x0000000000000000, 0x423f15da047e2d52 ) }, + { 0x1.5c2e1ea2b85c4p+63, 0x1.bbf1e79d77e3dp-836, INIT_U128( 0x0000000000000000, 0xae170f515c2e2000 ) }, + { 0x1.3a1d0742743a1p+63, 0x1.849ecbad093dap-836, INIT_U128( 0x0000000000000000, 0x9d0e83a13a1d0800 ) }, + { 0x1.ac698c2758d32p+63, 0x1.7a316edaf462ep-836, INIT_U128( 0x0000000000000000, 0xd634c613ac699000 ) }, + { 0x1.8542412f0a848p+63, 0x1.a53fa9cd4a7f5p-836, INIT_U128( 0x0000000000000000, 0xc2a1209785424000 ) }, + { 0x1.f526fb77ea4ep+64, 0x1.170327882e065p-848, INIT_U128( 0x0000000000000001, 0xf526fb77ea4e0000 ) }, + { 0x1.acca54155994ap+64, 0x1.4c44fdb4988ap-848, INIT_U128( 0x0000000000000001, 0xacca54155994a000 ) }, + { 0x1.b47ed77768fdbp+64, 0x1.e6883245cd107p-848, INIT_U128( 0x0000000000000001, 0xb47ed77768fdb000 ) }, + { 0x1.bf32165b7e643p+64, 0x1.7da93100fb526p-848, INIT_U128( 0x0000000000000001, 0xbf32165b7e643000 ) }, + { 0x1.c6aa72a58d54fp+65, 0x1.700d04ece01ap-810, INIT_U128( 0x0000000000000003, 0x8d54e54b1aa9e000 ) }, + { 0x1.651ffffcca4p+65, 0x1.b6e3b8e56dc77p-810, INIT_U128( 0x0000000000000002, 0xca3ffff994800000 ) }, + { 0x1.f59076c9eb20fp+65, 0x1.41622b1082c46p-810, INIT_U128( 0x0000000000000003, 0xeb20ed93d641e000 ) }, + { 0x1.2362224a46c44p+65, 0x1.0fe4f0321fc9ep-810, INIT_U128( 0x0000000000000002, 0x46c444948d888000 ) }, + { 0x1.96643d852cc88p+66, 0x1.5aadaff0b55b6p-820, INIT_U128( 0x0000000000000006, 0x5990f614b3220000 ) }, + { 0x1.38a95f0e7152cp+66, 0x1.8432d89b0865bp-820, INIT_U128( 0x0000000000000004, 0xe2a57c39c54b0000 ) }, + { 0x1.b674a85b6ce95p+66, 0x1.3adbee1a75b7ep-820, INIT_U128( 0x0000000000000006, 0xd9d2a16db3a54000 ) }, + { 0x1.81b2bc3303658p+66, 0x1.0e771c4e1cee4p-820, INIT_U128( 0x0000000000000006, 0x06caf0cc0d960000 ) }, + { 0x1.017e066002fc1p+67, 0x1.69eb9d80d3d74p-860, INIT_U128( 0x0000000000000008, 0x0bf0330017e08000 ) }, + { 0x1.b75b9b136eb74p+67, 0x1.ddf2ec69bbe5ep-860, INIT_U128( 0x000000000000000d, 0xbadcd89b75ba0000 ) }, + { 0x1.71432fe4e2866p+67, 0x1.cbea0a3797d41p-860, INIT_U128( 0x000000000000000b, 0x8a197f2714330000 ) }, + { 0x1.65e3ce88cbc7ap+67, 0x1.dd466e4dba8cep-860, INIT_U128( 0x000000000000000b, 0x2f1e74465e3d0000 ) }, + { 0x1.d76842dfaed09p+68, 0x1.d4739f6ba8e74p-740, INIT_U128( 0x000000000000001d, 0x76842dfaed090000 ) }, + { 0x1.9180cb312301ap+68, 0x1.5961b442b2c36p-740, INIT_U128( 0x0000000000000019, 0x180cb312301a0000 ) }, + { 0x1.5ea7abd8bd4f6p+68, 0x1.0afd825415fbp-740, INIT_U128( 0x0000000000000015, 0xea7abd8bd4f60000 ) }, + { 0x1.bcf6493f79ec9p+68, 0x1.39f6643a73eccp-740, INIT_U128( 0x000000000000001b, 0xcf6493f79ec90000 ) }, + { 0x1.6c264bbad84cap+69, 0x1.3d2b92de7a572p-358, INIT_U128( 0x000000000000002d, 0x84c9775b09940000 ) }, + { 0x1.13b3e09a2767cp+69, 0x1.a3ead92f47d5bp-358, INIT_U128( 0x0000000000000022, 0x767c1344ecf80000 ) }, + { 0x1.8518219d0a304p+69, 0x1.c9a99edf93534p-358, INIT_U128( 0x0000000000000030, 0xa30433a146080000 ) }, + { 0x1.afa032e75f406p+69, 0x1.76f3e70cede7dp-358, INIT_U128( 0x0000000000000035, 0xf4065cebe80c0000 ) }, + { 0x1.1aa2f5343545ep+70, 0x1.cd612ccd9ac25p-491, INIT_U128( 0x0000000000000046, 0xa8bd4d0d51780000 ) }, + { 0x1.2c8c2e1a59186p+70, 0x1.53ac1260a7582p-491, INIT_U128( 0x000000000000004b, 0x230b869646180000 ) }, + { 0x1.b92d16ef725a3p+70, 0x1.05faddde0bf5cp-491, INIT_U128( 0x000000000000006e, 0x4b45bbdc968c0000 ) }, + { 0x1.9fc802a33f9p+70, 0x1.203a627a4074cp-491, INIT_U128( 0x0000000000000067, 0xf200a8cfe4000000 ) }, + { 0x1.240746b6480e9p+71, 0x1.78c39518f1872p-676, INIT_U128( 0x0000000000000092, 0x03a35b2407480000 ) }, + { 0x1.863a24750c744p+71, 0x1.96d2b31d2da56p-676, INIT_U128( 0x00000000000000c3, 0x1d123a863a200000 ) }, + { 0x1.597fbe8ab2ff8p+71, 0x1.93afb023275f6p-676, INIT_U128( 0x00000000000000ac, 0xbfdf45597fc00000 ) }, + { 0x1.e1080a67c2102p+71, 0x1.b5c9f2a36b93ep-676, INIT_U128( 0x00000000000000f0, 0x840533e108100000 ) }, + { 0x1.5c1897a6b8313p+72, 0x1.e08b1a6fc1164p-272, INIT_U128( 0x000000000000015c, 0x1897a6b831300000 ) }, + { 0x1.9ba232cf37446p+72, 0x1.5f66bf90becd8p-272, INIT_U128( 0x000000000000019b, 0xa232cf3744600000 ) }, + { 0x1.595f744cb2beep+72, 0x1.f7a95a67ef52cp-272, INIT_U128( 0x0000000000000159, 0x5f744cb2bee00000 ) }, + { 0x1.a763ae594ec76p+72, 0x1.c295524f852aap-272, INIT_U128( 0x00000000000001a7, 0x63ae594ec7600000 ) }, + { 0x1.06eca6c40dd95p+73, 0x1.f918431ff2309p-572, INIT_U128( 0x000000000000020d, 0xd94d881bb2a00000 ) }, + { 0x1.4f9fc82a9f3f9p+73, 0x1.257089f24ae11p-572, INIT_U128( 0x000000000000029f, 0x3f90553e7f200000 ) }, + { 0x1.0fa3bdc41f478p+73, 0x1.1ca9162039523p-572, INIT_U128( 0x000000000000021f, 0x477b883e8f000000 ) }, + { 0x1.be3be7ef7c77dp+73, 0x1.ae73d50d5ce7bp-572, INIT_U128( 0x000000000000037c, 0x77cfdef8efa00000 ) }, + { 0x1.da6d4389b4da8p+74, 0x1.1806570a300cbp-230, INIT_U128( 0x0000000000000769, 0xb50e26d36a000000 ) }, + { 0x1.55276624aa4edp+74, 0x1.004fb390009f6p-230, INIT_U128( 0x0000000000000554, 0x9d9892a93b400000 ) }, + { 0x1.aeab3c995d568p+74, 0x1.08d9156011b22p-230, INIT_U128( 0x00000000000006ba, 0xacf265755a000000 ) }, + { 0x1.a281549f4502ap+74, 0x1.cb98cbdf9731ap-230, INIT_U128( 0x000000000000068a, 0x05527d140a800000 ) }, + { 0x1.35dae4746bb5cp+75, 0x1.492edd3c925dcp-684, INIT_U128( 0x00000000000009ae, 0xd723a35dae000000 ) }, + { 0x1.e6b8db83cd71cp+75, 0x1.e8282f8fd0506p-684, INIT_U128( 0x0000000000000f35, 0xc6dc1e6b8e000000 ) }, + { 0x1.17587f082eb1p+75, 0x1.45ebb9f28bd77p-684, INIT_U128( 0x00000000000008ba, 0xc3f8417588000000 ) }, + { 0x1.957ac7292af59p+75, 0x1.35b408566b681p-684, INIT_U128( 0x0000000000000cab, 0xd6394957ac800000 ) }, + { 0x1.6e0e0850dc1c1p+76, 0x1.9e623e393cc48p-1002, INIT_U128( 0x00000000000016e0, 0xe0850dc1c1000000 ) }, + { 0x1.90fee6ff21fddp+76, 0x1.7ceca2caf9d94p-1002, INIT_U128( 0x000000000000190f, 0xee6ff21fdd000000 ) }, + { 0x1.5798708eaf30ep+76, 0x1.d3322f4fa6646p-1002, INIT_U128( 0x0000000000001579, 0x8708eaf30e000000 ) }, + { 0x1.c2ef5f4185decp+76, 0x1.96ad4d692d5aap-1002, INIT_U128( 0x0000000000001c2e, 0xf5f4185dec000000 ) }, + { 0x1.ae14b81f5c297p+77, 0x1.062f208c0c5e4p-169, INIT_U128( 0x00000000000035c2, 0x9703eb852e000000 ) }, + { 0x1.1f2ef58a3e5dep+77, 0x1.97a029192f405p-169, INIT_U128( 0x00000000000023e5, 0xdeb147cbbc000000 ) }, + { 0x1.74861d64e90c4p+77, 0x1.fb289c69f6513p-169, INIT_U128( 0x0000000000002e90, 0xc3ac9d2188000000 ) }, + { 0x1.11782bc422f06p+77, 0x1.fe294db5fc529p-169, INIT_U128( 0x000000000000222f, 0x0578845e0c000000 ) }, + { 0x1.3af34bd275e6ap+78, 0x1.ba66054574cc1p-910, INIT_U128( 0x0000000000004ebc, 0xd2f49d79a8000000 ) }, + { 0x1.0708e3fc0e11cp+78, 0x1.09ae142c135c2p-910, INIT_U128( 0x00000000000041c2, 0x38ff038470000000 ) }, + { 0x1.c313a69786275p+78, 0x1.fc165a27f82ccp-910, INIT_U128( 0x00000000000070c4, 0xe9a5e189d4000000 ) }, + { 0x1.990c9ad532193p+78, 0x1.072499060e493p-910, INIT_U128( 0x0000000000006643, 0x26b54c864c000000 ) }, + { 0x1.dd2363c1ba46cp+79, 0x1.d163c99ba2c79p-815, INIT_U128( 0x000000000000ee91, 0xb1e0dd2360000000 ) }, + { 0x1.b0ae4ad1615c9p+79, 0x1.8f2f90f91e5f2p-815, INIT_U128( 0x000000000000d857, 0x2568b0ae48000000 ) }, + { 0x1.9a26bbb7344d8p+79, 0x1.ed90d6d9db21bp-815, INIT_U128( 0x000000000000cd13, 0x5ddb9a26c0000000 ) }, + { 0x1.71ec17ace3d83p+79, 0x1.ec2b79cfd856fp-815, INIT_U128( 0x000000000000b8f6, 0x0bd671ec18000000 ) }, + { 0x1.689f9cb2d13f4p+80, 0x1.adfbd9175bf7bp-935, INIT_U128( 0x000000000001689f, 0x9cb2d13f40000000 ) }, + { 0x1.cde2888d9bc51p+80, 0x1.0d3598f01a6b3p-935, INIT_U128( 0x000000000001cde2, 0x888d9bc510000000 ) }, + { 0x1.6866c948d0cd9p+80, 0x1.0d9da3cc1b3b4p-935, INIT_U128( 0x0000000000016866, 0xc948d0cd90000000 ) }, + { 0x1.eee79cbdddcf3p+80, 0x1.a60bf9374c17fp-935, INIT_U128( 0x000000000001eee7, 0x9cbdddcf30000000 ) }, + { 0x1.3a27b29c744f6p+81, 0x1.1270039224ep-231, INIT_U128( 0x000000000002744f, 0x6538e89ec0000000 ) }, + { 0x1.608a6c38c114ep+81, 0x1.a6ff1b154dfe4p-231, INIT_U128( 0x000000000002c114, 0xd8718229c0000000 ) }, + { 0x1.b8ddf2c971bbep+81, 0x1.7a6c452cf4d88p-231, INIT_U128( 0x00000000000371bb, 0xe592e377c0000000 ) }, + { 0x1.34056f04680aep+81, 0x1.3aa39ba075474p-231, INIT_U128( 0x000000000002680a, 0xde08d015c0000000 ) }, + { 0x1.df36567dbe6cbp+82, 0x1.948aa54b29155p-104, INIT_U128( 0x0000000000077cd9, 0x59f6f9b2c0000000 ) }, + { 0x1.00c5bf20018b8p+82, 0x1.0354f44e06a9ep-104, INIT_U128( 0x0000000000040316, 0xfc80062e00000000 ) }, + { 0x1.5a6d471ab4da9p+82, 0x1.ea755ca5d4eabp-104, INIT_U128( 0x00000000000569b5, 0x1c6ad36a40000000 ) }, + { 0x1.58acff6eb15ap+82, 0x1.f6c3b1b9ed876p-104, INIT_U128( 0x00000000000562b3, 0xfdbac56800000000 ) }, + { 0x1.9288c20b25118p+83, 0x1.477be5208ef7cp-445, INIT_U128( 0x00000000000c9446, 0x1059288c00000000 ) }, + { 0x1.3556fa5c6aaep+83, 0x1.f200a591e4014p-445, INIT_U128( 0x000000000009aab7, 0xd2e3557000000000 ) }, + { 0x1.88dec0dd11bd8p+83, 0x1.a1ceac19439d6p-445, INIT_U128( 0x00000000000c46f6, 0x06e88dec00000000 ) }, + { 0x1.603498e4c0693p+83, 0x1.94ccf0d52999ep-445, INIT_U128( 0x00000000000b01a4, 0xc726034980000000 ) }, + { 0x1.1dfbb7a43bf77p+84, 0x1.d7dd8bdbafbb2p-926, INIT_U128( 0x000000000011dfbb, 0x7a43bf7700000000 ) }, + { 0x1.5f5d18b8beba3p+84, 0x1.ac1b923558372p-926, INIT_U128( 0x000000000015f5d1, 0x8b8beba300000000 ) }, + { 0x1.8b32b85d16657p+84, 0x1.37ae11cc6f5c2p-926, INIT_U128( 0x000000000018b32b, 0x85d1665700000000 ) }, + { 0x1.506f56eca0debp+84, 0x1.185445da30a88p-926, INIT_U128( 0x00000000001506f5, 0x6eca0deb00000000 ) }, + { 0x1.506cf3dea0d9ep+85, 0x1.2e68e2945cd1cp-635, INIT_U128( 0x00000000002a0d9e, 0x7bd41b3c00000000 ) }, + { 0x1.99ef268733de5p+85, 0x1.2ce0960e59c13p-635, INIT_U128( 0x0000000000333de4, 0xd0e67bca00000000 ) }, + { 0x1.d46cd273a8d9ap+85, 0x1.fb0bae61f6176p-635, INIT_U128( 0x00000000003a8d9a, 0x4e751b3400000000 ) }, + { 0x1.31deaa8263bd6p+85, 0x1.8a752b4514ea6p-635, INIT_U128( 0x0000000000263bd5, 0x504c77ac00000000 ) }, + { 0x1.95956f032b2aep+86, 0x1.ddd18753bba31p-535, INIT_U128( 0x000000000065655b, 0xc0cacab800000000 ) }, + { 0x1.db4b6705b696dp+86, 0x1.fc438061f887p-535, INIT_U128( 0x000000000076d2d9, 0xc16da5b400000000 ) }, + { 0x1.42c9320885926p+86, 0x1.9258f3ab24b1ep-535, INIT_U128( 0x000000000050b24c, 0x8221649800000000 ) }, + { 0x1.08ca2a0e11946p+86, 0x1.1c860974390c1p-535, INIT_U128( 0x000000000042328a, 0x8384651800000000 ) }, + { 0x1.ddf27f51bbe5p+87, 0x1.a776e8c94eeddp-479, INIT_U128( 0x0000000000eef93f, 0xa8ddf28000000000 ) }, + { 0x1.3f5b6af47eb6ep+87, 0x1.cf47dd9d9e8fcp-479, INIT_U128( 0x00000000009fadb5, 0x7a3f5b7000000000 ) }, + { 0x1.4b9d6480973acp+87, 0x1.c249100d84922p-479, INIT_U128( 0x0000000000a5ceb2, 0x404b9d6000000000 ) }, + { 0x1.eea053a5dd40bp+87, 0x1.26e6f8d24dcdfp-479, INIT_U128( 0x0000000000f75029, 0xd2eea05800000000 ) }, + { 0x1.4e0a84329c15p+88, 0x1.b969043772d2p-931, INIT_U128( 0x00000000014e0a84, 0x329c150000000000 ) }, + { 0x1.20fcf75c41f9fp+88, 0x1.a487f5bf490ffp-931, INIT_U128( 0x000000000120fcf7, 0x5c41f9f000000000 ) }, + { 0x1.0937a468126f4p+88, 0x1.dd15685bba2adp-931, INIT_U128( 0x00000000010937a4, 0x68126f4000000000 ) }, + { 0x1.3a1b94d674372p+88, 0x1.0e98a7441d315p-931, INIT_U128( 0x00000000013a1b94, 0xd674372000000000 ) }, + { 0x1.b9b702f1736ep+89, 0x1.afdf8f8b5fbf2p-758, INIT_U128( 0x0000000003736e05, 0xe2e6dc0000000000 ) }, + { 0x1.f93973b7f272fp+89, 0x1.77696130eed2cp-758, INIT_U128( 0x0000000003f272e7, 0x6fe4e5e000000000 ) }, + { 0x1.85595b3b0ab2cp+89, 0x1.4c1c459298388p-758, INIT_U128( 0x00000000030ab2b6, 0x7615658000000000 ) }, + { 0x1.89e4ed0b13c9ep+89, 0x1.4c88ddd89911cp-758, INIT_U128( 0x000000000313c9da, 0x162793c000000000 ) }, + { 0x1.6d0dfe6ada1cp+90, 0x1.0873b16610e76p+20, INIT_U128( 0x0000000005b437f9, 0xab6870000010873b ) }, + { 0x1.403e37e4807c7p+90, 0x1.630feeecc61fep+20, INIT_U128( 0x000000000500f8df, 0x9201f1c0001630fe ) }, + { 0x1.1d3cdade3a79cp+90, 0x1.ecceb30bd99d7p+20, INIT_U128( 0x000000000474f36b, 0x78e9e700001ecceb ) }, + { 0x1.f50698adea0d3p+90, 0x1.4ed5f3749dabep+20, INIT_U128( 0x0000000007d41a62, 0xb7a834c00014ed5f ) }, + { 0x1.d869b87fb0d37p+91, 0x1.53d108a0a7a21p-525, INIT_U128( 0x000000000ec34dc3, 0xfd869b8000000000 ) }, + { 0x1.cd078fb39a0f2p+91, 0x1.228b56084516bp-525, INIT_U128( 0x000000000e683c7d, 0x9cd0790000000000 ) }, + { 0x1.c67dbd798cfb7p+91, 0x1.65e1ed28cbc3ep-525, INIT_U128( 0x000000000e33edeb, 0xcc67db8000000000 ) }, + { 0x1.c41a2ed388346p+91, 0x1.4799717a8f32ep-525, INIT_U128( 0x000000000e20d176, 0x9c41a30000000000 ) }, + { 0x1.db416739b682dp+92, 0x1.fea650affd4cap-706, INIT_U128( 0x000000001db41673, 0x9b682d0000000000 ) }, + { 0x1.872189f10e431p+92, 0x1.e1de445fc3bc8p-706, INIT_U128( 0x000000001872189f, 0x10e4310000000000 ) }, + { 0x1.d2ad0fd1a55a2p+92, 0x1.0a06ac7e140d6p-706, INIT_U128( 0x000000001d2ad0fd, 0x1a55a20000000000 ) }, + { 0x1.2535c3a84a6b8p+92, 0x1.65205312ca40ap-706, INIT_U128( 0x0000000012535c3a, 0x84a6b80000000000 ) }, + { 0x1.dd518ce9baa31p+93, 0x1.b123211362464p-663, INIT_U128( 0x000000003baa319d, 0x3754620000000000 ) }, + { 0x1.9a89da733513bp+93, 0x1.8c0a0b2b18142p-663, INIT_U128( 0x0000000033513b4e, 0x66a2760000000000 ) }, + { 0x1.01fc693203f8dp+93, 0x1.81040a6d02081p-663, INIT_U128( 0x00000000203f8d26, 0x407f1a0000000000 ) }, + { 0x1.1d9ae72e3b35dp+93, 0x1.fb816ce9f702dp-663, INIT_U128( 0x0000000023b35ce5, 0xc766ba0000000000 ) }, + { 0x1.1b8311c037062p+94, 0x1.3b413a6c76828p-946, INIT_U128( 0x0000000046e0c470, 0x0dc1880000000000 ) }, + { 0x1.e7c1239fcf825p+94, 0x1.e89cbe61d1398p-946, INIT_U128( 0x0000000079f048e7, 0xf3e0940000000000 ) }, + { 0x1.3ba2c92677459p+94, 0x1.4c19bb4098338p-946, INIT_U128( 0x000000004ee8b249, 0x9dd1640000000000 ) }, + { 0x1.e81787a3d02f1p+94, 0x1.21981a6a43304p-946, INIT_U128( 0x000000007a05e1e8, 0xf40bc40000000000 ) }, + { 0x1.e18ca9a3c3195p+95, 0x1.d2ce473ba59c9p-353, INIT_U128( 0x00000000f0c654d1, 0xe18ca80000000000 ) }, + { 0x1.ec1a5457d834ap+95, 0x1.673af5f4ce75ep-353, INIT_U128( 0x00000000f60d2a2b, 0xec1a500000000000 ) }, + { 0x1.3d4fcc727a9fap+95, 0x1.d577142daaee2p-353, INIT_U128( 0x000000009ea7e639, 0x3d4fd00000000000 ) }, + { 0x1.6b318358d663p+95, 0x1.d96b9445b2d72p-353, INIT_U128( 0x00000000b598c1ac, 0x6b31800000000000 ) }, + { 0x1.f8fedfa1f1fdcp+96, 0x1.6e54dd28dca9cp-828, INIT_U128( 0x00000001f8fedfa1, 0xf1fdc00000000000 ) }, + { 0x1.4b5ec85896bd9p+96, 0x1.e4251105c84a2p-828, INIT_U128( 0x000000014b5ec858, 0x96bd900000000000 ) }, + { 0x1.bc8f0397791ep+96, 0x1.b514998d6a293p-828, INIT_U128( 0x00000001bc8f0397, 0x791e000000000000 ) }, + { 0x1.056a2dfe0ad46p+96, 0x1.c98d1a15931a3p-828, INIT_U128( 0x00000001056a2dfe, 0x0ad4600000000000 ) }, + { 0x1.21192da842326p+97, 0x1.64dbdea4c9b7cp-314, INIT_U128( 0x0000000242325b50, 0x8464c00000000000 ) }, + { 0x1.95c269f12b84dp+97, 0x1.31bfb62e637f7p-314, INIT_U128( 0x000000032b84d3e2, 0x5709a00000000000 ) }, + { 0x1.f4a37e69e947p+97, 0x1.2c5cc8d658b99p-314, INIT_U128( 0x00000003e946fcd3, 0xd28e000000000000 ) }, + { 0x1.73c765e6e78ecp+97, 0x1.34b3a3f469674p-314, INIT_U128( 0x00000002e78ecbcd, 0xcf1d800000000000 ) }, + { 0x1.cafa773f95f4fp+98, 0x1.28d3338851a66p-207, INIT_U128( 0x000000072be9dcfe, 0x57d3c00000000000 ) }, + { 0x1.7b7b6aa4f6f6ep+98, 0x1.2c99252259324p-207, INIT_U128( 0x00000005ededaa93, 0xdbdb800000000000 ) }, + { 0x1.8c39a15918734p+98, 0x1.cdcd60b79b9acp-207, INIT_U128( 0x0000000630e68564, 0x61cd000000000000 ) }, + { 0x1.da220eb5b4442p+98, 0x1.cd0b52b19a16bp-207, INIT_U128( 0x0000000768883ad6, 0xd110800000000000 ) }, + { 0x1.0f34e6fa1e69dp+99, 0x1.596be5d4b2d7cp-575, INIT_U128( 0x0000000879a737d0, 0xf34e800000000000 ) }, + { 0x1.5318af1aa6316p+99, 0x1.b2d7a70f65af5p-575, INIT_U128( 0x0000000a98c578d5, 0x318b000000000000 ) }, + { 0x1.2f3f14005e7e2p+99, 0x1.bf1a11977e342p-575, INIT_U128( 0x0000000979f8a002, 0xf3f1000000000000 ) }, + { 0x1.c95da71792bb5p+99, 0x1.b673d5896ce7bp-575, INIT_U128( 0x0000000e4aed38bc, 0x95da800000000000 ) }, + { 0x1.fdead1dffbd5ap+100, 0x1.5a750c74b4ea2p-189, INIT_U128( 0x0000001fdead1dff, 0xbd5a000000000000 ) }, + { 0x1.fe8116bbfd023p+100, 0x1.c0314d4580629p-189, INIT_U128( 0x0000001fe8116bbf, 0xd023000000000000 ) }, + { 0x1.9177917922ef2p+100, 0x1.b5d94c0f6bb2ap-189, INIT_U128( 0x0000001917791792, 0x2ef2000000000000 ) }, + { 0x1.39ab1bf273564p+100, 0x1.4de96f889bd2ep-189, INIT_U128( 0x000000139ab1bf27, 0x3564000000000000 ) }, + { 0x1.52e21a8aa5c44p+101, 0x0.0000075bfbb25p-1022, INIT_U128( 0x0000002a5c435154, 0xb888000000000000 ) }, + { 0x1.c362c16186c58p+101, 0x0.00000417370ap-1022, INIT_U128( 0x000000386c582c30, 0xd8b0000000000000 ) }, + { 0x1.dcbb50a5b976ap+101, 0x0.000005dcb4b01p-1022, INIT_U128( 0x0000003b976a14b7, 0x2ed4000000000000 ) }, + { 0x1.fae77febf5cfp+101, 0x0.00000567e1492p-1022, INIT_U128( 0x0000003f5ceffd7e, 0xb9e0000000000000 ) }, + { 0x1.b94feaf3729fdp+102, 0x1.eb191b6bd6324p-32, INIT_U128( 0x0000006e53fabcdc, 0xa7f4000000000000 ) }, + { 0x1.ffcd483fff9a9p+102, 0x1.f6c951e5ed92ap-32, INIT_U128( 0x0000007ff3520fff, 0xe6a4000000000000 ) }, + { 0x1.f4a75991e94ebp+102, 0x1.5d81e52ebb03cp-32, INIT_U128( 0x0000007d29d6647a, 0x53ac000000000000 ) }, + { 0x1.d9014a81b202ap+102, 0x1.1d1a5c4c3a34cp-32, INIT_U128( 0x000000764052a06c, 0x80a8000000000000 ) }, + { 0x1.d33430cda6686p+103, 0x1.58855d10b10acp-383, INIT_U128( 0x000000e99a1866d3, 0x3430000000000000 ) }, + { 0x1.5e801048bd002p+103, 0x1.54a52a72a94a6p-383, INIT_U128( 0x000000af4008245e, 0x8010000000000000 ) }, + { 0x1.590a254ab2144p+103, 0x1.0307881c060f1p-383, INIT_U128( 0x000000ac8512a559, 0x0a20000000000000 ) }, + { 0x1.6dfaecf0dbf5ep+103, 0x1.54a4b130a9496p-383, INIT_U128( 0x000000b6fd76786d, 0xfaf0000000000000 ) }, + { 0x1.011eb1b0023d6p+104, 0x1.39df71da73beep-20, INIT_U128( 0x000001011eb1b002, 0x3d60000000000000 ) }, + { 0x1.5ee2142ebdc42p+104, 0x1.43553d9086aa8p-20, INIT_U128( 0x0000015ee2142ebd, 0xc420000000000000 ) }, + { 0x1.100502e4200ap+104, 0x1.534d9720a69b3p-20, INIT_U128( 0x000001100502e420, 0x0a00000000000000 ) }, + { 0x1.2aefc5ac55df8p+104, 0x1.f553d14beaa7ap-20, INIT_U128( 0x0000012aefc5ac55, 0xdf80000000000000 ) }, + { 0x1.d0559891a0ab3p+105, 0x1.87b2239d0f644p-316, INIT_U128( 0x000003a0ab312341, 0x5660000000000000 ) }, + { 0x1.0929084e12521p+105, 0x1.e345fe55c68cp-316, INIT_U128( 0x0000021252109c24, 0xa420000000000000 ) }, + { 0x1.70c26be4e184ep+105, 0x1.7a6011c6f4c02p-316, INIT_U128( 0x000002e184d7c9c3, 0x09c0000000000000 ) }, + { 0x1.8c345d471868cp+105, 0x1.b4a5d903694bbp-316, INIT_U128( 0x0000031868ba8e30, 0xd180000000000000 ) }, + { 0x1.66bf48cecd7e9p+106, 0x1.d926e3a9b24dcp-461, INIT_U128( 0x0000059afd233b35, 0xfa40000000000000 ) }, + { 0x1.caf9648595f2cp+106, 0x1.3edd8e587dbb2p-461, INIT_U128( 0x0000072be5921657, 0xcb00000000000000 ) }, + { 0x1.0ff9c5341ff38p+106, 0x1.5ecf4954bd9e9p-461, INIT_U128( 0x0000043fe714d07f, 0xce00000000000000 ) }, + { 0x1.010bbf3602178p+106, 0x1.90183dfb20308p-461, INIT_U128( 0x000004042efcd808, 0x5e00000000000000 ) }, + { 0x1.90f1198321e23p+107, 0x1.18ec849e31d9p-508, INIT_U128( 0x00000c8788cc190f, 0x1180000000000000 ) }, + { 0x1.88876447110ecp+107, 0x1.3dbc4a967b78ap-508, INIT_U128( 0x00000c443b223888, 0x7600000000000000 ) }, + { 0x1.e955d221d2abap+107, 0x1.1f1f0f983e3e2p-508, INIT_U128( 0x00000f4aae910e95, 0x5d00000000000000 ) }, + { 0x1.79931aacf3264p+107, 0x1.5c6d47c2b8da9p-508, INIT_U128( 0x00000bcc98d56799, 0x3200000000000000 ) }, + { 0x1.49a28e4c93452p+108, 0x1.0819b1c610336p-949, INIT_U128( 0x0000149a28e4c934, 0x5200000000000000 ) }, + { 0x1.b61387f56c271p+108, 0x1.fda021a7fb404p-949, INIT_U128( 0x00001b61387f56c2, 0x7100000000000000 ) }, + { 0x1.8364b71506c97p+108, 0x1.972f04852e5ep-949, INIT_U128( 0x000018364b71506c, 0x9700000000000000 ) }, + { 0x1.a902b10952056p+108, 0x1.aee9cfcf5dd3ap-949, INIT_U128( 0x00001a902b109520, 0x5600000000000000 ) }, + { 0x1.d96f1c29b2de4p+109, 0x1.8415bcdf082b8p-695, INIT_U128( 0x00003b2de385365b, 0xc800000000000000 ) }, + { 0x1.e8dfe3f9d1bfcp+109, 0x1.c31bb2ed86377p-695, INIT_U128( 0x00003d1bfc7f3a37, 0xf800000000000000 ) }, + { 0x1.3a0cc61474199p+109, 0x1.06f2795a0de4fp-695, INIT_U128( 0x0000274198c28e83, 0x3200000000000000 ) }, + { 0x1.1f3e5f4a3e7ccp+109, 0x1.d7cc8b85af992p-695, INIT_U128( 0x000023e7cbe947cf, 0x9800000000000000 ) }, + { 0x1.dc6af865b8d5fp+110, 0x1.b5d225136ba45p-22, INIT_U128( 0x0000771abe196e35, 0x7c00000000000000 ) }, + { 0x1.4ca9fcc69954p+110, 0x1.eaa024f7d5404p-22, INIT_U128( 0x0000532a7f31a655, 0x0000000000000000 ) }, + { 0x1.414c72988298ep+110, 0x1.a488753b4910fp-22, INIT_U128( 0x000050531ca620a6, 0x3800000000000000 ) }, + { 0x1.dc6b39dbb8d67p+110, 0x1.068d04580d1ap-22, INIT_U128( 0x0000771ace76ee35, 0x9c00000000000000 ) }, + { 0x1.74e50e90e9ca2p+111, 0x1.3f289f007e514p-487, INIT_U128( 0x0000ba72874874e5, 0x1000000000000000 ) }, + { 0x1.5f0a2632be145p+111, 0x1.f790c8d9ef219p-487, INIT_U128( 0x0000af8513195f0a, 0x2800000000000000 ) }, + { 0x1.d422bf03a8458p+111, 0x1.fbacd695f759bp-487, INIT_U128( 0x0000ea115f81d422, 0xc000000000000000 ) }, + { 0x1.d9b5cefdb36bap+111, 0x1.c968397b92d07p-487, INIT_U128( 0x0000ecdae77ed9b5, 0xd000000000000000 ) }, + { 0x1.f3e78001e7cfp+112, 0x1.4b4970649692ep-744, INIT_U128( 0x0001f3e78001e7cf, 0x0000000000000000 ) }, + { 0x1.17c200042f84p+112, 0x1.8d8e8a711b1d1p-744, INIT_U128( 0x000117c200042f84, 0x0000000000000000 ) }, + { 0x1.0fe4fde81fcap+112, 0x1.256616f84acc3p-744, INIT_U128( 0x00010fe4fde81fca, 0x0000000000000000 ) }, + { 0x1.f2773487e4ee6p+112, 0x1.075dd87a0ebbbp-744, INIT_U128( 0x0001f2773487e4ee, 0x6000000000000000 ) }, + { 0x1.7f2646f4fe4c9p+113, 0x1.bde0f7d57bc1fp-552, INIT_U128( 0x0002fe4c8de9fc99, 0x2000000000000000 ) }, + { 0x1.552a71c4aa54ep+113, 0x1.5f75cb84beebap-552, INIT_U128( 0x0002aa54e38954a9, 0xc000000000000000 ) }, + { 0x1.016211fe02c42p+113, 0x1.755a3ebeeab48p-552, INIT_U128( 0x000202c423fc0588, 0x4000000000000000 ) }, + { 0x1.2da4a1405b494p+113, 0x1.c7b5a5b78f6b5p-552, INIT_U128( 0x00025b494280b692, 0x8000000000000000 ) }, + { 0x1.454dcac88a9bap+114, 0x1.39e2f64073c5fp-541, INIT_U128( 0x000515372b222a6e, 0x8000000000000000 ) }, + { 0x1.f5769ad1eaed4p+114, 0x1.273e2b1a4e7c6p-541, INIT_U128( 0x0007d5da6b47abb5, 0x0000000000000000 ) }, + { 0x1.52bf04cca57ep+114, 0x1.2d92613e5b24cp-541, INIT_U128( 0x00054afc133295f8, 0x0000000000000000 ) }, + { 0x1.1b84a7fc37095p+114, 0x1.8b3360311666cp-541, INIT_U128( 0x00046e129ff0dc25, 0x4000000000000000 ) }, + { 0x1.82ef082b05de1p+115, 0x1.5205f44aa40bep-62, INIT_U128( 0x000c177841582ef0, 0x8000000000000000 ) }, + { 0x1.bafcbdf175f98p+115, 0x1.a9ea203153d44p-62, INIT_U128( 0x000dd7e5ef8bafcc, 0x0000000000000000 ) }, + { 0x1.64b56bd8c96aep+115, 0x1.42c3a3da85874p-62, INIT_U128( 0x000b25ab5ec64b57, 0x0000000000000000 ) }, + { 0x1.55c9b3b6ab936p+115, 0x1.48f9d11a91f3ap-62, INIT_U128( 0x000aae4d9db55c9b, 0x0000000000000000 ) }, + { 0x1.5321473ca6429p+116, 0x1.181db1c6303b6p-92, INIT_U128( 0x0015321473ca6429, 0x0000000000000000 ) }, + { 0x1.cdc20a3f9b841p+116, 0x1.50077ebca00fp-92, INIT_U128( 0x001cdc20a3f9b841, 0x0000000000000000 ) }, + { 0x1.92fee4f925fdcp+116, 0x1.028f8f16051f2p-92, INIT_U128( 0x00192fee4f925fdc, 0x0000000000000000 ) }, + { 0x1.1bab55e43756ap+116, 0x1.40855e9c810acp-92, INIT_U128( 0x0011bab55e43756a, 0x0000000000000000 ) }, + { 0x1.db43e365b687dp+117, 0x1.41baf8828375fp-732, INIT_U128( 0x003b687c6cb6d0fa, 0x0000000000000000 ) }, + { 0x1.a552a1674aa54p+117, 0x1.baa689f9754d1p-732, INIT_U128( 0x0034aa542ce954a8, 0x0000000000000000 ) }, + { 0x1.fe56ea4dfcadep+117, 0x1.5684197ead083p-732, INIT_U128( 0x003fcadd49bf95bc, 0x0000000000000000 ) }, + { 0x1.6c9b7a08d937p+117, 0x1.2337f65a466ffp-732, INIT_U128( 0x002d936f411b26e0, 0x0000000000000000 ) }, + { 0x1.076705de0ecep+118, 0x1.98bce7cb3179dp-844, INIT_U128( 0x0041d9c17783b380, 0x0000000000000000 ) }, + { 0x1.9b22f3533645ep+118, 0x1.74f31c32e9e64p-844, INIT_U128( 0x0066c8bcd4cd9178, 0x0000000000000000 ) }, + { 0x1.c1d136e583a27p+118, 0x1.767b76ceecf6fp-844, INIT_U128( 0x0070744db960e89c, 0x0000000000000000 ) }, + { 0x1.c885934b910b3p+118, 0x1.cd65a24d9acb4p-844, INIT_U128( 0x00722164d2e442cc, 0x0000000000000000 ) }, + { 0x1.fb2c8085f659p+119, 0x1.4485cbfc890bap-269, INIT_U128( 0x00fd964042fb2c80, 0x0000000000000000 ) }, + { 0x1.78eebbd0f1dd8p+119, 0x1.373c5ea66e78cp-269, INIT_U128( 0x00bc775de878eec0, 0x0000000000000000 ) }, + { 0x1.1cbf9dfc397f4p+119, 0x1.3a787bfa74f1p-269, INIT_U128( 0x008e5fcefe1cbfa0, 0x0000000000000000 ) }, + { 0x1.0b37d4fc166fap+119, 0x1.3ec2f1ca7d85ep-269, INIT_U128( 0x00859bea7e0b37d0, 0x0000000000000000 ) }, + { 0x1.f7d41d9befa83p+119, 0x1.737e360ee6fc7p+45, INIT_U128( 0x00fbea0ecdf7d418, 0x00002e6fc6c1dcdf ) }, + { 0x1.5f9adea4bf35cp+119, 0x1.f2a34d73e5469p+45, INIT_U128( 0x00afcd6f525f9ae0, 0x00003e5469ae7ca8 ) }, + { 0x1.1625a2842c4b4p+119, 0x1.dffa968fbff53p+45, INIT_U128( 0x008b12d1421625a0, 0x00003bff52d1f7fe ) }, + { 0x1.77b9ea5cef73ep+119, 0x1.03d8c57207b18p+45, INIT_U128( 0x00bbdcf52e77b9f0, 0x0000207b18ae40f6 ) }, + { 0x1.80c91d3d01924p+119, 0x1.dc2e84abb85dp+45, INIT_U128( 0x00c0648e9e80c920, 0x00003b85d095770b ) }, + { 0x1.a13e2abb427c5p+119, 0x1.be5baad37cb75p+45, INIT_U128( 0x00d09f155da13e28, 0x000037cb755a6f96 ) }, + { 0x1.3d0a39607a147p+119, 0x1.5d047beeba09p+45, INIT_U128( 0x009e851cb03d0a38, 0x00002ba08f7dd741 ) }, + { 0x1.e914f2edd229fp+119, 0x1.a87d6b5150faep+45, INIT_U128( 0x00f48a7976e914f8, 0x0000350fad6a2a1f ) }, + { 0x1.1bfba16037f74p+119, 0x1.f1667f23e2cdp+45, INIT_U128( 0x008dfdd0b01bfba0, 0x00003e2ccfe47c59 ) }, + { 0x1.e409cc97c8139p+119, 0x1.760ec180ec1d8p+45, INIT_U128( 0x00f204e64be409c8, 0x00002ec1d8301d83 ) }, + { 0x1.56095810ac12bp+119, 0x1.fd72c88bfae59p+45, INIT_U128( 0x00ab04ac08560958, 0x00003fae59117f5c ) }, + { 0x1.014b8dfe02972p+119, 0x1.5051ec7ca0a3ep+45, INIT_U128( 0x0080a5c6ff014b90, 0x00002a0a3d8f9414 ) }, + { 0x1.2c8071285900ep+119, 0x1.2df331a65be66p+45, INIT_U128( 0x00964038942c8070, 0x000025be6634cb7c ) }, + { 0x1.ec4edc7bd89dbp+119, 0x1.5689910cad132p+45, INIT_U128( 0x00f6276e3dec4ed8, 0x00002ad1322195a2 ) }, + { 0x1.acab22af59564p+120, 0x1.4302395486047p-789, INIT_U128( 0x01acab22af595640, 0x0000000000000000 ) }, + { 0x1.6d777264daeeep+120, 0x1.a94793a7528f2p-789, INIT_U128( 0x016d777264daeee0, 0x0000000000000000 ) }, + { 0x1.179807f22f301p+120, 0x1.f73f61cbee7ecp-789, INIT_U128( 0x01179807f22f3010, 0x0000000000000000 ) }, + { 0x1.2306ea1a460dep+120, 0x1.7f322c14fe646p-789, INIT_U128( 0x012306ea1a460de0, 0x0000000000000000 ) }, + { 0x1.4b89313897126p+121, 0x1.24f0cf5649e1ap-97, INIT_U128( 0x02971262712e24c0, 0x0000000000000000 ) }, + { 0x1.977d3ba32efa8p+121, 0x1.8d5ae3291ab5cp-97, INIT_U128( 0x032efa77465df500, 0x0000000000000000 ) }, + { 0x1.4951cf1a92a3ap+121, 0x1.ff3e4eaffe7cap-97, INIT_U128( 0x0292a39e35254740, 0x0000000000000000 ) }, + { 0x1.6487918ac90f2p+121, 0x1.8e5a3b671cb48p-97, INIT_U128( 0x02c90f2315921e40, 0x0000000000000000 ) }, + { 0x1.a71b395f4e367p+122, 0x1.4851ea7e90a3ep-824, INIT_U128( 0x069c6ce57d38d9c0, 0x0000000000000000 ) }, + { 0x1.58097738b012fp+122, 0x1.a4e92d4749d26p-824, INIT_U128( 0x056025dce2c04bc0, 0x0000000000000000 ) }, + { 0x1.431d2f4a863a6p+122, 0x1.ff84386fff087p-824, INIT_U128( 0x050c74bd2a18e980, 0x0000000000000000 ) }, + { 0x1.9f1393ad3e272p+122, 0x1.d7c0a6ddaf815p-824, INIT_U128( 0x067c4e4eb4f89c80, 0x0000000000000000 ) }, + { 0x1.8983ab7913076p+123, 0x1.fa01bdc9f4037p-825, INIT_U128( 0x0c4c1d5bc8983b00, 0x0000000000000000 ) }, + { 0x1.f3551e67e6aa4p+123, 0x1.029c51f00538ap-825, INIT_U128( 0x0f9aa8f33f355200, 0x0000000000000000 ) }, + { 0x1.a9da0d1d53b42p+123, 0x1.b5c718d36b8e3p-825, INIT_U128( 0x0d4ed068ea9da100, 0x0000000000000000 ) }, + { 0x1.95c79e2b2b8f4p+123, 0x1.384e4c32709cap-825, INIT_U128( 0x0cae3cf1595c7a00, 0x0000000000000000 ) }, + { 0x1.73af4650e75e9p+124, 0x1.ec4b7265d896fp-92, INIT_U128( 0x173af4650e75e900, 0x0000000000000000 ) }, + { 0x1.5e15a3a0bc2b4p+124, 0x1.2ff859825ff0bp-92, INIT_U128( 0x15e15a3a0bc2b400, 0x0000000000000000 ) }, + { 0x1.4dbe24a69b7c4p+124, 0x1.f5b685e5eb6d1p-92, INIT_U128( 0x14dbe24a69b7c400, 0x0000000000000000 ) }, + { 0x1.cd65ac439acb6p+124, 0x1.164d910a2c9b2p-92, INIT_U128( 0x1cd65ac439acb600, 0x0000000000000000 ) }, + { 0x1.f5bbadd5eb775p+125, 0x1.b16aeddb62d5ep-83, INIT_U128( 0x3eb775babd6eea00, 0x0000000000000000 ) }, + { 0x1.b66841396cd08p+125, 0x1.f9957d69f32afp-83, INIT_U128( 0x36cd08272d9a1000, 0x0000000000000000 ) }, + { 0x1.05be50760b7cap+125, 0x1.f9ebf8ddf3d7fp-83, INIT_U128( 0x20b7ca0ec16f9400, 0x0000000000000000 ) }, + { 0x1.51312262a2624p+125, 0x1.11c69084238d2p-83, INIT_U128( 0x2a26244c544c4800, 0x0000000000000000 ) }, + { 0x1.30eab12c61d56p+126, 0x1.f1e0e851e3c1dp-773, INIT_U128( 0x4c3aac4b18755800, 0x0000000000000000 ) }, + { 0x1.ac34bcf158698p+126, 0x1.a55b126f4ab62p-773, INIT_U128( 0x6b0d2f3c561a6000, 0x0000000000000000 ) }, + { 0x1.02246a040448ep+126, 0x1.61a83652c3507p-773, INIT_U128( 0x40891a8101123800, 0x0000000000000000 ) }, + { 0x1.ae881f955d104p+126, 0x1.c694aaa18d296p-773, INIT_U128( 0x6ba207e557441000, 0x0000000000000000 ) }, + { 0x1.08016b641002ep+127, 0x1.23a890d047512p-406, INIT_U128( 0x8400b5b208017000, 0x0000000000000000 ) }, + { 0x1.3d90e7327b21dp+127, 0x1.0aa664c0154ccp-406, INIT_U128( 0x9ec873993d90e800, 0x0000000000000000 ) }, + { 0x1.ff931617ff263p+127, 0x1.47d5e2a08fabcp-406, INIT_U128( 0xffc98b0bff931800, 0x0000000000000000 ) }, + { 0x1.f565d1dfeacbap+127, 0x1.827bc0c304f78p-406, INIT_U128( 0xfab2e8eff565d000, 0x0000000000000000 ) }, + { 0x1.fe1985fbfc33p+128, 0x1.a6e724cd4dce4p-1021, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.54709ed6a8e14p+128, 0x1.74a32d1ce9466p-1021, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.a8407dcf5081p+128, 0x1.ffb065f3ff60cp-1021, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.7a1cfcf2f43ap+130, 0x1.84bb5ea30976cp-548, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.6bddaae8d7bb6p+194, 0x1.de64c609bcc99p-754, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.5c6c29d4b8d85p+146, 0x1.0644f6d60c89fp-345, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.c6ce8bcf8d9d2p+158, 0x1.443b2e7088766p-26, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.747f6aa0e8feep+168, 0x1.fe663ae9fccc8p-143, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.26ee550a4ddcap+173, 0x1.951f708f2a3eep-45, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.3ecfe0ea7d9fcp+189, 0x1.9cb53593396a7p-619, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.9d394a313a729p+190, 0x1.9ecfff853dap-150, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.244a568a4894bp+241, 0x1.e23f42d7c47e9p-956, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.b564bb276ac98p+398, 0x1.7af8d1ccf5f1ap+215, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.ee06b389dc0d7p+468, 0x1.b54fa74f6a9f5p+322, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.ac0045bd58009p+588, 0x1.ba99775b7532fp-365, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.692078cad240fp+661, 0x1.bc4a88a978951p+356, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.be1e09dd7c3c1p+765, 0x1.428bc5dc85178p-848, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.5f5554c4beaaap+853, 0x1.a9e23bdd53c48p-807, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.748e96ace91d3p+993, 0x1.ab54ab4b56a96p-22, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { 0x1.0629e7380c53dp+1023, 0x1.c0b4b15581696p+323, INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ) }, + { INFINITY, 0x1.21bff4bc437fep-333, ((__uint128_t) 0xffffffffffffffff << 64) | 0xffffffffffffffff }, + { INFINITY, 0x1.47e9a0228fd34p-333, ((__uint128_t) 0xffffffffffffffff << 64) | 0xffffffffffffffff } +}; + +static const int numTests = sizeof(testList) / sizeof(struct testCase); + diff --git a/test/builtins/Unit/ppc/floatditf_test.c b/test/builtins/Unit/ppc/floatditf_test.c index 5c08ade4bdf8..e9b9458349ee 100644 --- a/test/builtins/Unit/ppc/floatditf_test.c +++ b/test/builtins/Unit/ppc/floatditf_test.c @@ -1,7 +1,8 @@ -// REQUIRES: powerpc-registered-target -// RUN: %clang_builtins %s -o %t && %run %t +// REQUIRES: target-is-powerpc64le +// RUN: %clang_builtins %s %librt -o %t && %run %t #include <stdint.h> #include <stdio.h> +#include "int_lib.h" COMPILER_RT_ABI long double __floatditf(int64_t); diff --git a/test/builtins/Unit/ppc/floattitf_test.c b/test/builtins/Unit/ppc/floattitf_test.c new file mode 100644 index 000000000000..e89e5d946ddb --- /dev/null +++ b/test/builtins/Unit/ppc/floattitf_test.c @@ -0,0 +1,59 @@ +// REQUIRES: target-is-powerpc64le +// RUN: %clang_builtins %s %librt -o %t && %run %t + +/* + * Test case execution for: long double __floattitf (__int128_t) + * Conversion from 128 bit integer to long double (IBM double-double). + */ + +#include <stdint.h> +#include <stdio.h> + +#include "floattitf_test.h" + +/* The long double representation, with the high and low portions of + * the long double, and the corresponding bit patterns of each double. */ +typedef union { + long double ld; + double d[2]; /* [0] is the high double, [1] is the low double. */ + unsigned long long ull[2]; /* High and low doubles as 64-bit integers. */ +} ldUnion; + +long double __floattitf(__int128_t); + +int main(int argc, char *argv[]) { + /* Necessary long double and 128 bit integer declarations used to + * compare computed and expected high and low portions of the + * IBM double-double. */ + ldUnion expectedLongDouble; + ldUnion computedLongDouble; + __int128_t result128; + + for (int i = 0; i < numTests; ++i) { + /* Set the expected high and low values of the long double, + * and the 128 bit integer input to be converted. */ + expectedLongDouble.d[0] = tests[i].hi; + expectedLongDouble.d[1] = tests[i].lo; + result128 = tests[i].input128; + + /* Get the computed long double from the int128->long double conversion + * and check for errors between high and low portions. */ + computedLongDouble.ld = __floattitf(result128); + + if ((computedLongDouble.d[0] != expectedLongDouble.d[0]) || + (computedLongDouble.d[1] != expectedLongDouble.d[1])) { + + printf("Error on __floattitf( 0x%016llx 0x%016llx ):\n", + (long long)(tests[i].input128 >> 64), + (long long)tests[i].input128); + printf("\tExpected value - %La = ( %a, %a )\n", expectedLongDouble.ld, + expectedLongDouble.d[0], expectedLongDouble.d[1]); + printf("\tComputed value - %La = ( %a, %a )\n\n", computedLongDouble.ld, + computedLongDouble.d[0], computedLongDouble.d[1]); + + return 1; + } + } + + return 0; +} diff --git a/test/builtins/Unit/ppc/floattitf_test.h b/test/builtins/Unit/ppc/floattitf_test.h new file mode 100644 index 000000000000..1da8a6b52065 --- /dev/null +++ b/test/builtins/Unit/ppc/floattitf_test.h @@ -0,0 +1,197 @@ +/* +* Test case inputs for: long double __floattitf (__int128_t) +* Conversion from 128 bit integer to long double (IBM double-double). +*/ + +#define INIT_U128(HI, LO) (((__uint128_t) (HI) << 64) | (LO)) + +struct testCase { + __int128_t input128; + double hi; + double lo; +}; + +struct testCase tests[] = { + { INIT_U128( 0x0000000000000000, 0x0000000000000000 ), 0x0p+0, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x0000000000000001 ), 0x1p+0, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x1000000000000000 ), 0x1p+60, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xffffffffffffffff ), 0x1p+64, -0x1p+0 }, + { INIT_U128( 0x0000000000000000, 0x7fffffffffffffff ), 0x1p+63, -0x1p+0 }, + { INIT_U128( 0x0000000000000001, 0x0000000000000000 ), 0x1p+64, 0x0p+0 }, + { INIT_U128( 0x0000000000000001, 0x0000000000000001 ), 0x1p+64, 0x1p+0 }, + { INIT_U128( 0x0000000000000001, 0x7fffffffffffffff ), 0x1.8p+64, -0x1p+0 }, + { INIT_U128( 0x0000000000000001, 0x1000000000000000 ), 0x1.1p+64, 0x0p+0 }, + { INIT_U128( 0x0000000000000001, 0xffffffffffffffff ), 0x1p+65, -0x1p+0 }, + { INIT_U128( 0x7fffffffffffffff, 0x0000000000000000 ), 0x1p+127, -0x1p+64 }, + { INIT_U128( 0x7fffffffffffffff, 0x0000000000000001 ), 0x1p+127, -0x1p+64 }, + { INIT_U128( 0x7fffffffffffffff, 0x7fffffffffffffff ), 0x1p+127, -0x1p+63 }, + { INIT_U128( 0x7fffffffffffffff, 0x1000000000000000 ), 0x1p+127, -0x1.ep+63 }, + { INIT_U128( 0x7fffffffffffffff, 0xffffffffffffffff ), 0x1p+127, -0x1p+0 }, + { INIT_U128( 0x1000000000000000, 0x0000000000000000 ), 0x1p+124, 0x0p+0 }, + { INIT_U128( 0x1000000000000000, 0x0000000000000001 ), 0x1p+124, 0x1p+0 }, + { INIT_U128( 0x1000000000000000, 0x7fffffffffffffff ), 0x1p+124, 0x1p+63 }, + { INIT_U128( 0x1000000000000000, 0x1000000000000000 ), 0x1p+124, 0x1p+60 }, + { INIT_U128( 0x1000000000000000, 0xffffffffffffffff ), 0x1p+124, 0x1p+64 }, + { INIT_U128( 0xffffffffffffffff, 0x0000000000000000 ), -0x1p+64, 0x0p+0 }, + { INIT_U128( 0xffffffffffffffff, 0x0000000000000001 ), -0x1p+64, 0x1p+0 }, + { INIT_U128( 0xffffffffffffffff, 0x7fffffffffffffff ), -0x1p+63, -0x1p+0 }, + { INIT_U128( 0xffffffffffffffff, 0x1000000000000000 ), -0x1.ep+63, 0x0p+0 }, + { INIT_U128( 0xffffffffffffffff, 0xffffffffffffffff ), -0x1p+0, 0x0p+0 }, + { INIT_U128( 0x0000000000000061, 0x0000000000000061 ), 0x1.84p+70, 0x1.84p+6 }, + { INIT_U128( 0x0000000000000000, 0x0000000000000057 ), 0x1.5cp+6, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xffffffffffffff9e ), 0x1p+64, -0x1.88p+6 }, + { INIT_U128( 0x0000000000000000, 0x0000000000000062 ), 0x1.88p+6, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x0000000000000403 ), 0x1.00cp+10, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xfffffffffffffbfc ), 0x1.fffffffffffffp+63, 0x1.fep+9 }, + { INIT_U128( 0x0000000000000000, 0x000000000000040a ), 0x1.028p+10, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x000000000000040c ), 0x1.03p+10, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x000000000000041a ), 0x1.068p+10, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x0000000000000510 ), 0x1.44p+10, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x0000000000000518 ), 0x1.46p+10, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xfffffffffffffae7 ), 0x1.fffffffffffffp+63, 0x1.738p+9 }, + { INIT_U128( 0x0000000000000000, 0x0000000000000602 ), 0x1.808p+10, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xfffffffffffff9fd ), 0x1.fffffffffffffp+63, 0x1.fdp+8 }, + { INIT_U128( 0x0000000000000000, 0x0000000000002090 ), 0x1.048p+13, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xffffffffffffdbdb ), 0x1.ffffffffffffbp+63, 0x1.ed8p+9 }, + { INIT_U128( 0x0000000000000000, 0x0000000000002430 ), 0x1.218p+13, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x0000000000020202 ), 0x1.0101p+17, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xfffffffffffdeef7 ), 0x1.fffffffffffbep+63, -0x1.09p+8 }, + { INIT_U128( 0x0000000000000000, 0x0000000000032004 ), 0x1.9002p+17, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xfffffffffffcdffb ), 0x1.fffffffffff9cp+63, -0x1.4p+2 }, + { INIT_U128( 0x0000000000000000, 0x0000000000032040 ), 0x1.902p+17, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xffffffffffbfdfbb ), 0x1.ffffffffff7fcp+63, -0x1.14p+6 }, + { INIT_U128( 0x0000000000000000, 0x0000000000402088 ), 0x1.00822p+22, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x0000000080080088 ), 0x1.0010011p+31, 0x0p+0 }, + { INIT_U128( 0xffffffff7ff7ff77, 0xffffffff7ff7ff77 ), -0x1.0010011p+95, -0x1.00100112p+31 }, + { INIT_U128( 0x0000000000000000, 0x0000000850000008 ), 0x1.0a000001p+35, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x0000002000000448 ), 0x1.000000224p+37, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xffffffdfff7dbfff ), 0x1.ffffffbffefb8p+63, -0x1p+0 }, + { INIT_U128( 0x0000004002001100, 0x0000004002001100 ), 0x1.00080044p+102, 0x1.00080044p+38 }, + { INIT_U128( 0x000008020000000c, 0x000008020000000c ), 0x1.00400000018p+107, 0x1.00400000018p+43 }, + { INIT_U128( 0x0000000000000000, 0xfffff7fdfffffff3 ), 0x1.ffffeffcp+63, -0x1.ap+3 }, + { INIT_U128( 0x0000000000000000, 0x0000800000000824 ), 0x1.000000001048p+47, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xfffdffffff7ffcff ), 0x1.fffbffffffp+63, -0x1.808p+9 }, + { INIT_U128( 0x0000000000000000, 0x4002040010000000 ), 0x1.000810004p+62, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xbffdfbffefffffff ), 0x1.7ffbf7ffep+63, -0x1p+0 }, + { INIT_U128( 0x0000000000000000, 0x8000000000000000 ), 0x1p+63, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xfffffffff418c5c1 ), 0x1.ffffffffe8319p+63, -0x1.1f8p+9 }, + { INIT_U128( 0x000000000000000f, 0xffffffffffffffff ), 0x1p+68, -0x1p+0 }, + { INIT_U128( 0x00000000000000ff, 0xffffffffffffffff ), 0x1p+72, -0x1p+0 }, + { INIT_U128( 0x0000000000000fff, 0xffffffffffffffff ), 0x1p+76, -0x1p+0 }, + { INIT_U128( 0x000000000000ffff, 0xffffffffffffffff ), 0x1p+80, -0x1p+0 }, + { INIT_U128( 0x00000000000fffff, 0xffffffffffffffff ), 0x1p+84, -0x1p+0 }, + { INIT_U128( 0x0000000000ffffff, 0xffffffffffffffff ), 0x1p+88, -0x1p+0 }, + { INIT_U128( 0x000000000fffffff, 0xffffffffffffffff ), 0x1p+92, -0x1p+0 }, + { INIT_U128( 0x00000000ffffffff, 0xffffffffffffffff ), 0x1p+96, -0x1p+0 }, + { INIT_U128( 0x0000000fffffffff, 0xffffffffffffffff ), 0x1p+100, -0x1p+0 }, + { INIT_U128( 0x000000ffffffffff, 0xffffffffffffffff ), 0x1p+104, -0x1p+0 }, + { INIT_U128( 0x00000fffffffffff, 0xffffffffffffffff ), 0x1p+108, -0x1p+0 }, + { INIT_U128( 0x0000ffffffffffff, 0xffffffffffffffff ), 0x1p+112, -0x1p+0 }, + { INIT_U128( 0x000fffffffffffff, 0xffffffffffffffff ), 0x1p+116, -0x1p+0 }, + { INIT_U128( 0x00ffffffffffffff, 0xffffffffffffffff ), 0x1p+120, -0x1p+0 }, + { INIT_U128( 0x0fffffffffffffff, 0xffffffffffffffff ), 0x1p+124, -0x1p+0 }, + { INIT_U128( 0x1000000000000000, 0x0000000000000000 ), 0x1p+124, 0x0p+0 }, + { INIT_U128( 0x1000000000000000, 0x0000000000000011 ), 0x1p+124, 0x1.1p+4 }, + { INIT_U128( 0x1000000000000000, 0x0000000000000111 ), 0x1p+124, 0x1.11p+8 }, + { INIT_U128( 0x1000000000000000, 0x0000000000001111 ), 0x1p+124, 0x1.111p+12 }, + { INIT_U128( 0x1000000000000000, 0x0000000000011111 ), 0x1p+124, 0x1.1111p+16 }, + { INIT_U128( 0x1000000000000000, 0x0000000000111111 ), 0x1p+124, 0x1.11111p+20 }, + { INIT_U128( 0x1000000000000000, 0x0000000001111111 ), 0x1p+124, 0x1.111111p+24 }, + { INIT_U128( 0x1000000000000000, 0x0000000011111111 ), 0x1p+124, 0x1.1111111p+28 }, + { INIT_U128( 0x1000000000000000, 0x0000000111111111 ), 0x1p+124, 0x1.11111111p+32 }, + { INIT_U128( 0x1000000000000000, 0x0000001111111111 ), 0x1p+124, 0x1.111111111p+36 }, + { INIT_U128( 0x1000000000000000, 0x0000011111111111 ), 0x1p+124, 0x1.1111111111p+40 }, + { INIT_U128( 0x1000000000000000, 0x0000111111111111 ), 0x1p+124, 0x1.11111111111p+44 }, + { INIT_U128( 0x1000000000000000, 0x0001111111111111 ), 0x1p+124, 0x1.111111111111p+48 }, + { INIT_U128( 0x1000000000000000, 0x0011111111111111 ), 0x1p+124, 0x1.1111111111111p+52 }, + { INIT_U128( 0x1000000000000000, 0x0111111111111111 ), 0x1p+124, 0x1.11111111111111p+56 }, + { INIT_U128( 0x1000000000000000, 0x1111111111111111 ), 0x1p+124, 0x1.111111111111111p+60 }, + { INIT_U128( 0xffffffffffffffff, 0xf000000000000000 ), -0x1p+60, 0x0p+0 }, + { INIT_U128( 0xffffffffffffffff, 0xff00000000000000 ), -0x1p+56, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xb7ffffff77ffffff ), 0x1.6ffffffefp+63, -0x1p+0 }, + { INIT_U128( 0xb7ffffff3fffffff, 0xb7ffffff3fffffff ), -0x1.20000003p+126, -0x1.20000003p+62 }, + { INIT_U128( 0xb7fffffefffffffe, 0xb7fffffefffffffe ), -0x1.20000004p+126, -0x1.48000001p+64 }, + { INIT_U128( 0xb7fffffeffffefff, 0xb7fffffeffffefff ), -0x1.2000000400004p+126, -0x1.2000000400004p+62 }, + { INIT_U128( 0x0000040000000000, 0x0000000000000000 ), 0x1p+106, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x000000003ff00000 ), 0x1.ff8p+29, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xb7fbffffffffdfff ), 0x1.6ff7ffffffffcp+63, -0x1p+0 }, + { INIT_U128( 0x0000000000000000, 0x4804000000010000 ), 0x1.201000000004p+62, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0x4900000000001000 ), 0x1.2400000000004p+62, 0x0p+0 }, + { INIT_U128( 0x0000000000000000, 0xb6ffffffffffefff ), 0x1.6dffffffffffep+63, -0x1p+0 }, + { INIT_U128( 0x0000000000000000, 0x4900000000008000 ), 0x1.240000000002p+62, 0x0p+0 }, + { INIT_U128( 0xb6ffffffffff7fff, 0xb6ffffffffff7fff ), -0x1.240000000002p+126, -0x1.240000000002p+62 }, + { INIT_U128( 0x4900000000040000, 0x4900000000040000 ), 0x1.24000000001p+126, 0x1.24000000001p+62 }, + { INIT_U128( 0xb6fffffffffbffff, 0xb6fffffffffbffff ), -0x1.24000000001p+126, -0x1.24000000001p+62 }, + { INIT_U128( 0x4900000000200000, 0x4900000000200000 ), 0x1.24000000008p+126, 0x1.24000000008p+62 }, + { INIT_U128( 0xb6ffffffffdfffff, 0xb6ffffffffdfffff ), -0x1.24000000008p+126, -0x1.24000000008p+62 }, + { INIT_U128( 0x4900000000800000, 0x4900000000800000 ), 0x1.2400000002p+126, 0x1.2400000002p+62 }, + { INIT_U128( 0xb6ffffffff7fffff, 0xb6ffffffff7fffff ), -0x1.2400000002p+126, -0x1.2400000002p+62 }, + { INIT_U128( 0x4900000008000000, 0x4900000008000000 ), 0x1.240000002p+126, 0x1.240000002p+62 }, + { INIT_U128( 0xb6fffffff7ffffff, 0xb6fffffff7ffffff ), -0x1.240000002p+126, -0x1.240000002p+62 }, + { INIT_U128( 0x4900000040000000, 0x4900000040000000 ), 0x1.24000001p+126, 0x1.24000001p+62 }, + { INIT_U128( 0xb6ffffffbfffffff, 0xb6ffffffbfffffff ), -0x1.24000001p+126, -0x1.24000001p+62 }, + { INIT_U128( 0x4900000080000000, 0x4900000080000000 ), 0x1.24000002p+126, 0x1.24000002p+62 }, + { INIT_U128( 0xb6ffffff7fffffff, 0xb6ffffff7fffffff ), -0x1.24000002p+126, -0x1.24000002p+62 }, + { INIT_U128( 0x4900000400000000, 0x4900000400000000 ), 0x1.2400001p+126, 0x1.2400001p+62 }, + { INIT_U128( 0xb6fffffbffffffff, 0xb6fffffbffffffff ), -0x1.2400001p+126, -0x1.2400001p+62 }, + { INIT_U128( 0x4900001000000000, 0x4900001000000000 ), 0x1.2400004p+126, 0x1.2400004p+62 }, + { INIT_U128( 0xb6ffffefffffffff, 0xb6ffffefffffffff ), -0x1.2400004p+126, -0x1.2400004p+62 }, + { INIT_U128( 0x4900004000000000, 0x4900004000000000 ), 0x1.240001p+126, 0x1.240001p+62 }, + { INIT_U128( 0xb6ffffbfffffffff, 0xb6ffffbfffffffff ), -0x1.240001p+126, -0x1.240001p+62 }, + { INIT_U128( 0x4900040000000000, 0x4900040000000000 ), 0x1.24001p+126, 0x1.24001p+62 }, + { INIT_U128( 0xb6fffbffffffffff, 0xb6fffbffffffffff ), -0x1.24001p+126, -0x1.24001p+62 }, + { INIT_U128( 0x4900200000000000, 0x4900200000000000 ), 0x1.24008p+126, 0x1.24008p+62 }, + { INIT_U128( 0xb6ffdfffffffffff, 0xb6ffdfffffffffff ), -0x1.24008p+126, -0x1.24008p+62 }, + { INIT_U128( 0x4901000000000000, 0x4901000000000000 ), 0x1.2404p+126, 0x1.2404p+62 }, + { INIT_U128( 0xb6feffffffffffff, 0xb6feffffffffffff ), -0x1.2404p+126, -0x1.2404p+62 }, + { INIT_U128( 0x4910000000000000, 0x4910000000000000 ), 0x1.244p+126, 0x1.244p+62 }, + { INIT_U128( 0xb6efffffffffffff, 0xb6efffffffffffff ), -0x1.244p+126, -0x1.244p+62 }, + { INIT_U128( 0x4980000000000000, 0x4980000000000000 ), 0x1.26p+126, 0x1.26p+62 }, + { INIT_U128( 0xb67fffffffffffff, 0xb67fffffffffffff ), -0x1.26p+126, -0x1.26p+62 }, + { INIT_U128( 0x4c00000000000000, 0x4c00000000000000 ), 0x1.3p+126, 0x1.3p+62 }, + { INIT_U128( 0xb3ffffffffffffff, 0xb3ffffffffffffff ), -0x1.3p+126, -0x1.3p+62 }, + { INIT_U128( 0x9fffffffffffbfff, 0x9fffffffffffbfff ), -0x1.800000000001p+126, -0x1.800000000001p+62 }, + { INIT_U128( 0x6000000000004001, 0x6000000000004001 ), 0x1.800000000001p+126, 0x1.6000000000004p+64 }, + { INIT_U128( 0x8fffffffffffffbf, 0x8fffffffffffffbf ), -0x1.cp+126, -0x1.01cp+70 }, + { INIT_U128( 0x7000000000000080, 0x7000000000000080 ), 0x1.cp+126, 0x1.00ep+71 }, + { INIT_U128( 0x8fffffffffffff7f, 0x8fffffffffffff7f ), -0x1.cp+126, -0x1.00ep+71 }, + { INIT_U128( 0x7000000000000800, 0x7000000000000800 ), 0x1.c000000000002p+126, 0x1.c000000000002p+62 }, + { INIT_U128( 0x8ffffffffffff7ff, 0x8ffffffffffff7ff ), -0x1.c000000000002p+126, -0x1.c000000000002p+62 }, + { INIT_U128( 0x7000000000002000, 0x7000000000002000 ), 0x1.c000000000008p+126, 0x1.c000000000008p+62 }, + { INIT_U128( 0x8fffffffffffdfff, 0x8fffffffffffdfff ), -0x1.c000000000008p+126, -0x1.c000000000008p+62 }, + { INIT_U128( 0x7000000000010000, 0x7000000000010000 ), 0x1.c00000000004p+126, 0x1.c00000000004p+62 }, + { INIT_U128( 0x8ffffffffffeffff, 0x8ffffffffffeffff ), -0x1.c00000000004p+126, -0x1.c00000000004p+62 }, + { INIT_U128( 0x7000000000040000, 0x7000000000040000 ), 0x1.c0000000001p+126, 0x1.c0000000001p+62 }, + { INIT_U128( 0x8ffffffffffbffff, 0x8ffffffffffbffff ), -0x1.c0000000001p+126, -0x1.c0000000001p+62 }, + { INIT_U128( 0x7000000000080000, 0x7000000000080000 ), 0x1.c0000000002p+126, 0x1.c0000000002p+62 }, + { INIT_U128( 0x8ffffffffff7ffff, 0x8ffffffffff7ffff ), -0x1.c0000000002p+126, -0x1.c0000000002p+62 }, + { INIT_U128( 0x7000000000800000, 0x7000000000800000 ), 0x1.c000000002p+126, 0x1.c000000002p+62 }, + { INIT_U128( 0x8fffffffff7fffff, 0x8fffffffff7fffff ), -0x1.c000000002p+126, -0x1.c000000002p+62 }, + { INIT_U128( 0x7000000008000000, 0x7000000008000000 ), 0x1.c00000002p+126, 0x1.c00000002p+62 }, + { INIT_U128( 0x8ffffffff7ffffff, 0x8ffffffff7ffffff ), -0x1.c00000002p+126, -0x1.c00000002p+62 }, + { INIT_U128( 0x7000000010000000, 0x7000000010000000 ), 0x1.c00000004p+126, 0x1.c00000004p+62 }, + { INIT_U128( 0x8fffffffefffffff, 0x8fffffffefffffff ), -0x1.c00000004p+126, -0x1.c00000004p+62 }, + { INIT_U128( 0x7000000100000000, 0x7000000100000000 ), 0x1.c0000004p+126, 0x1.c0000004p+62 }, + { INIT_U128( 0x8ffffffeffffffff, 0x8ffffffeffffffff ), -0x1.c0000004p+126, -0x1.c0000004p+62 }, + { INIT_U128( 0x7000000200000000, 0x7000000200000000 ), 0x1.c0000008p+126, 0x1.c0000008p+62 }, + { INIT_U128( 0x8ffffffdffffffff, 0x8ffffffdffffffff ), -0x1.c0000008p+126, -0x1.c0000008p+62 }, + { INIT_U128( 0x7000000800000000, 0x7000000800000000 ), 0x1.c000002p+126, 0x1.c000002p+62 }, + { INIT_U128( 0x8ffffff7ffffffff, 0x8ffffff7ffffffff ), -0x1.c000002p+126, -0x1.c000002p+62 }, + { INIT_U128( 0x7000008000000000, 0x7000008000000000 ), 0x1.c00002p+126, 0x1.c00002p+62 }, + { INIT_U128( 0x8fffff7fffffffff, 0x8fffff7fffffffff ), -0x1.c00002p+126, -0x1.c00002p+62 }, + { INIT_U128( 0x7000010000000000, 0x7000010000000000 ), 0x1.c00004p+126, 0x1.c00004p+62 }, + { INIT_U128( 0x8ffffeffffffffff, 0x8ffffeffffffffff ), -0x1.c00004p+126, -0x1.c00004p+62 }, + { INIT_U128( 0x7000080000000000, 0x7000080000000000 ), 0x1.c0002p+126, 0x1.c0002p+62 }, + { INIT_U128( 0x8ffff7ffffffffff, 0x8ffff7ffffffffff ), -0x1.c0002p+126, -0x1.c0002p+62 }, + { INIT_U128( 0x7000800000000000, 0x7000800000000000 ), 0x1.c002p+126, 0x1.c002p+62 }, + { INIT_U128( 0x8fff7fffffffffff, 0x8fff7fffffffffff ), -0x1.c002p+126, -0x1.c002p+62 }, + { INIT_U128( 0x7002000000000000, 0x7002000000000000 ), 0x1.c008p+126, 0x1.c008p+62 }, + { INIT_U128( 0x8ffdffffffffffff, 0x8ffdffffffffffff ), -0x1.c008p+126, -0x1.c008p+62 }, + { INIT_U128( 0x7008000000000000, 0x7008000000000000 ), 0x1.c02p+126, 0x1.c02p+62 }, + { INIT_U128( 0x8ff7ffffffffffff, 0x8ff7ffffffffffff ), -0x1.c02p+126, -0x1.c02p+62 }, + { INIT_U128( 0x7080000000000000, 0x7080000000000000 ), 0x1.c2p+126, 0x1.c2p+62 }, + { INIT_U128( 0x8f7fffffffffffff, 0x8f7fffffffffffff ), -0x1.c2p+126, -0x1.c2p+62 }, + { INIT_U128( 0x7400000000000000, 0x7400000000000000 ), 0x1.dp+126, 0x1.dp+62 } +}; + +static const int numTests = sizeof(tests) / sizeof(struct testCase); diff --git a/test/builtins/Unit/ppc/floatunditf_test.c b/test/builtins/Unit/ppc/floatunditf_test.c index 3e50128578e3..fc6090be1782 100644 --- a/test/builtins/Unit/ppc/floatunditf_test.c +++ b/test/builtins/Unit/ppc/floatunditf_test.c @@ -1,7 +1,8 @@ -// REQUIRES: powerpc-registered-target -// RUN: %clang_builtins %s -o %t && %run %t +// REQUIRES: target-is-powerpc64le +// RUN: %clang_builtins %s %librt -o %t && %run %t #include <stdint.h> #include <stdio.h> +#include "int_lib.h" COMPILER_RT_ABI long double __floatunditf(uint64_t); diff --git a/test/builtins/Unit/ppc/qadd_test.c b/test/builtins/Unit/ppc/qadd_test.c index 327fd21e8aa7..242850fff377 100644 --- a/test/builtins/Unit/ppc/qadd_test.c +++ b/test/builtins/Unit/ppc/qadd_test.c @@ -1,5 +1,5 @@ -// REQUIRES: powerpc-registered-target -// RUN: %clang_builtins %s -o %t && %run %t +// REQUIRES: target-is-powerpc64le +// RUN: %clang_builtins %s %librt -o %t && %run %t #include <stdio.h> #include "DD.h" diff --git a/test/builtins/Unit/ppc/qdiv_test.c b/test/builtins/Unit/ppc/qdiv_test.c index 7530e428fa72..15990f0c36fb 100644 --- a/test/builtins/Unit/ppc/qdiv_test.c +++ b/test/builtins/Unit/ppc/qdiv_test.c @@ -1,5 +1,5 @@ -// REQUIRES: powerpc-registered-target -// RUN: %clang_builtins %s -o %t && %run %t +// REQUIRES: target-is-powerpc64le +// RUN: %clang_builtins %s %librt -o %t && %run %t #include <stdio.h> #include "DD.h" diff --git a/test/builtins/Unit/ppc/qmul_test.c b/test/builtins/Unit/ppc/qmul_test.c index dbe3536f3098..c8e5bb096a25 100644 --- a/test/builtins/Unit/ppc/qmul_test.c +++ b/test/builtins/Unit/ppc/qmul_test.c @@ -1,5 +1,5 @@ -// REQUIRES: powerpc-registered-target -// RUN: %clang_builtins %s -o %t && %run %t +// REQUIRES: target-is-powerpc64le +// RUN: %clang_builtins %s %librt -o %t && %run %t #include <stdio.h> #include "DD.h" diff --git a/test/builtins/Unit/ppc/qsub_test.c b/test/builtins/Unit/ppc/qsub_test.c index e21224096f5c..1e456f83aea3 100644 --- a/test/builtins/Unit/ppc/qsub_test.c +++ b/test/builtins/Unit/ppc/qsub_test.c @@ -1,5 +1,5 @@ -// REQUIRES: powerpc-registered-target -// RUN: %clang_builtins %s -o %t && %run %t +// REQUIRES: target-is-powerpc64le +// RUN: %clang_builtins %s %librt -o %t && %run %t #include <stdio.h> #include "DD.h" diff --git a/test/builtins/Unit/subvti3_test.c b/test/builtins/Unit/subvti3_test.c index 66806ba0bb71..3add1ebc4bb6 100644 --- a/test/builtins/Unit/subvti3_test.c +++ b/test/builtins/Unit/subvti3_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- subvti3_test.c - Test __subvti3 -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/ucmpti2_test.c b/test/builtins/Unit/ucmpti2_test.c index 17a857fb59ea..39a6f5b95eb2 100644 --- a/test/builtins/Unit/ucmpti2_test.c +++ b/test/builtins/Unit/ucmpti2_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- ucmpti2_test.c - Test __ucmpti2 -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/udivmodti4_test.c b/test/builtins/Unit/udivmodti4_test.c index b07ce8c24200..38da855ae023 100644 --- a/test/builtins/Unit/udivmodti4_test.c +++ b/test/builtins/Unit/udivmodti4_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- udivmodti4_test.c - Test __udivmodti4 -----------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/udivti3_test.c b/test/builtins/Unit/udivti3_test.c index 81cedadff243..2db440d5b927 100644 --- a/test/builtins/Unit/udivti3_test.c +++ b/test/builtins/Unit/udivti3_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- udivti3_test.c - Test __udivti3 -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/builtins/Unit/umodti3_test.c b/test/builtins/Unit/umodti3_test.c index 5bce0258ae38..adfc8eba3402 100644 --- a/test/builtins/Unit/umodti3_test.c +++ b/test/builtins/Unit/umodti3_test.c @@ -1,4 +1,5 @@ // RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: int128 //===-- umodti3_test.c - Test __umodti3 -----------------------------------===// // // The LLVM Compiler Infrastructure diff --git a/test/cfi/bad-split.cpp b/test/cfi/bad-split.cpp index 37e635aef55b..dbbd7ecef0ce 100644 --- a/test/cfi/bad-split.cpp +++ b/test/cfi/bad-split.cpp @@ -1,7 +1,7 @@ // GlobalSplit used to lose type metadata for classes with virtual bases but no virtual methods. // RUN: %clangxx_cfi -o %t1 %s && %run %t1 -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc struct Z { }; diff --git a/test/cfi/cross-dso-diagnostic.cpp b/test/cfi/cross-dso-diagnostic.cpp index f3782dae0272..b8a88722768e 100644 --- a/test/cfi/cross-dso-diagnostic.cpp +++ b/test/cfi/cross-dso-diagnostic.cpp @@ -4,7 +4,7 @@ // RUN: %clangxx_cfi_diag -g -o %t_exe_suffix %s %ld_flags_rpath_exe // RUN: %t_exe_suffix 2>&1 | FileCheck -DDSONAME=%xdynamiclib_namespec %s -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc // REQUIRES: cxxabi #include <dlfcn.h> diff --git a/test/cfi/cross-dso/lit.local.cfg b/test/cfi/cross-dso/lit.local.cfg index afdac4246223..245d434faed9 100644 --- a/test/cfi/cross-dso/lit.local.cfg +++ b/test/cfi/cross-dso/lit.local.cfg @@ -5,7 +5,7 @@ def getRoot(config): root = getRoot(config) -if root.host_os not in ['Linux']: +if root.host_os not in ['Linux', 'FreeBSD', 'NetBSD']: config.unsupported = True # Android O (API level 26) has support for cross-dso cfi in libdl.so. diff --git a/test/cfi/mfcall.cpp b/test/cfi/mfcall.cpp index 6e22e3f3d711..4d561d943f41 100644 --- a/test/cfi/mfcall.cpp +++ b/test/cfi/mfcall.cpp @@ -1,4 +1,4 @@ -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc // RUN: %clangxx_cfi -o %t %s // RUN: %expect_crash %run %t a diff --git a/test/cfi/target_uninstrumented.cpp b/test/cfi/target_uninstrumented.cpp index 6379b7e12f44..c2db9d609f47 100644 --- a/test/cfi/target_uninstrumented.cpp +++ b/test/cfi/target_uninstrumented.cpp @@ -3,7 +3,7 @@ // RUN: %run %t 2>&1 | FileCheck %s // REQUIRES: cxxabi -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc #include <stdio.h> #include <string.h> diff --git a/test/cfi/two-vcalls.cpp b/test/cfi/two-vcalls.cpp index fbe4d971ace8..ff823c498027 100644 --- a/test/cfi/two-vcalls.cpp +++ b/test/cfi/two-vcalls.cpp @@ -4,7 +4,7 @@ // This test checks that we don't generate two type checks, // if two virtual calls are in the same function. -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc // REQUIRES: cxxabi // TODO(krasin): implement the optimization to not emit two type checks. diff --git a/test/esan/TestCases/large-stack-linux.c b/test/esan/TestCases/large-stack-linux.c index 1af32f8ba25e..17d88674ba1c 100644 --- a/test/esan/TestCases/large-stack-linux.c +++ b/test/esan/TestCases/large-stack-linux.c @@ -1,5 +1,7 @@ // RUN: %clang_esan_wset -O0 %s -o %t 2>&1 // RUN: %env_esan_opts="verbosity=1 record_snapshots=0" %run %t %t 2>&1 | FileCheck %s +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include <assert.h> #include <stdio.h> diff --git a/test/esan/TestCases/workingset-early-fault.c b/test/esan/TestCases/workingset-early-fault.c index 1c420c368ca9..971285b3f815 100644 --- a/test/esan/TestCases/workingset-early-fault.c +++ b/test/esan/TestCases/workingset-early-fault.c @@ -3,6 +3,8 @@ // // RUN: %clang_esan_wset %s -o %t // RUN: %run %t 2>&1 | FileCheck %s +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include <stdio.h> #include <stdlib.h> diff --git a/test/esan/TestCases/workingset-memset.cpp b/test/esan/TestCases/workingset-memset.cpp index 9c972ec7a738..56ed2f5b7c4f 100644 --- a/test/esan/TestCases/workingset-memset.cpp +++ b/test/esan/TestCases/workingset-memset.cpp @@ -1,5 +1,7 @@ // RUN: %clang_esan_wset -O0 %s -o %t 2>&1 // RUN: %run %t 2>&1 | FileCheck %s +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include <stdlib.h> #include <string.h> diff --git a/test/esan/TestCases/workingset-midreport.cpp b/test/esan/TestCases/workingset-midreport.cpp index 38c376554380..acd1eed1761d 100644 --- a/test/esan/TestCases/workingset-midreport.cpp +++ b/test/esan/TestCases/workingset-midreport.cpp @@ -6,6 +6,8 @@ // FIXME: Re-enable once PR33590 is fixed. // UNSUPPORTED: x86_64 +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include <sanitizer/esan_interface.h> #include <sched.h> diff --git a/test/esan/TestCases/workingset-samples.cpp b/test/esan/TestCases/workingset-samples.cpp index d97b62ba4e8a..1f8e97dadcc1 100644 --- a/test/esan/TestCases/workingset-samples.cpp +++ b/test/esan/TestCases/workingset-samples.cpp @@ -3,6 +3,8 @@ // FIXME: Re-enable once PR33590 is fixed. // UNSUPPORTED: x86_64 +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include <sanitizer/esan_interface.h> #include <sched.h> diff --git a/test/esan/TestCases/workingset-signal-posix.cpp b/test/esan/TestCases/workingset-signal-posix.cpp index ba776fc02ed8..6f9787bd73ef 100644 --- a/test/esan/TestCases/workingset-signal-posix.cpp +++ b/test/esan/TestCases/workingset-signal-posix.cpp @@ -1,5 +1,7 @@ // RUN: %clang_esan_wset -O0 %s -o %t 2>&1 // RUN: %run %t 2>&1 | FileCheck %s +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include <assert.h> #include <setjmp.h> diff --git a/test/esan/TestCases/workingset-simple.cpp b/test/esan/TestCases/workingset-simple.cpp index f1ac2ecfe132..dc17bcfd5401 100644 --- a/test/esan/TestCases/workingset-simple.cpp +++ b/test/esan/TestCases/workingset-simple.cpp @@ -3,6 +3,8 @@ // FIXME: Re-enable once PR33590 is fixed. // UNSUPPORTED: x86_64 +// Stucks at init and no clone feature equivalent. +// UNSUPPORTED: freebsd #include <stdlib.h> #include <string.h> diff --git a/test/esan/lit.cfg b/test/esan/lit.cfg index 8b8457d66e00..1bb34ee0865a 100644 --- a/test/esan/lit.cfg +++ b/test/esan/lit.cfg @@ -39,6 +39,5 @@ config.substitutions.append(('%env_esan_opts=', # Default test suffixes. config.suffixes = ['.c', '.cpp'] -# EfficiencySanitizer tests are currently supported on Linux x86-64 only. -if config.host_os not in ['Linux'] or config.target_arch not in ['x86_64', 'mips64'] : +if config.host_os not in ['Linux', 'FreeBSD'] or config.target_arch not in ['x86_64', 'mips64'] : config.unsupported = True diff --git a/test/fuzzer/AlignmentAssumptionTest.cpp b/test/fuzzer/AlignmentAssumptionTest.cpp new file mode 100644 index 000000000000..be51d37e8fe2 --- /dev/null +++ b/test/fuzzer/AlignmentAssumptionTest.cpp @@ -0,0 +1,27 @@ +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. + +// Test for alignment assumption failure. + +#include <assert.h> +#include <climits> +#include <cstddef> +#include <cstdint> +#include <cstdlib> +#include <iostream> + +static volatile int32_t Sink; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + assert(Data); + if (Size > 0 && Data[0] == 'H') { + Sink = 1; + if (Size > 1 && Data[1] == 'i') { + Sink = 2; + if (Size > 2 && Data[2] == '!') { + __builtin_assume_aligned(Data + 1, 0x8000); + } + } + } + return 0; +} diff --git a/test/fuzzer/ImplicitIntegerSignChangeTest.cpp b/test/fuzzer/ImplicitIntegerSignChangeTest.cpp new file mode 100644 index 000000000000..0fd7df0e2d2e --- /dev/null +++ b/test/fuzzer/ImplicitIntegerSignChangeTest.cpp @@ -0,0 +1,27 @@ +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. + +// Test for implicit-integer-sign-change. +#include <assert.h> +#include <climits> +#include <cstddef> +#include <cstdint> +#include <cstdlib> +#include <iostream> + +static volatile uint32_t Sink; +static volatile int32_t Storage = -1; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + assert(Data); + if (Size > 0 && Data[0] == 'H') { + Sink = 1; + if (Size > 1 && Data[1] == 'i') { + Sink = 2; + if (Size > 2 && Data[2] == '!') { + Sink = Storage; // 'sign change'. + } + } + } + return 0; +} diff --git a/test/fuzzer/ImplicitSignedIntegerTruncationOrSignChangeTest.cpp b/test/fuzzer/ImplicitSignedIntegerTruncationOrSignChangeTest.cpp new file mode 100644 index 000000000000..6e65f5442dcf --- /dev/null +++ b/test/fuzzer/ImplicitSignedIntegerTruncationOrSignChangeTest.cpp @@ -0,0 +1,27 @@ +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. + +// Test for implicit-signed-integer-truncation-or-sign-change. +#include <assert.h> +#include <climits> +#include <cstddef> +#include <cstdint> +#include <cstdlib> +#include <iostream> + +static volatile int8_t Sink; +static volatile uint32_t Storage = (uint32_t)-1; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + assert(Data); + if (Size > 0 && Data[0] == 'H') { + Sink = 1; + if (Size > 1 && Data[1] == 'i') { + Sink = 2; + if (Size > 2 && Data[2] == '!') { + Sink = Storage; // 'conversion'. + } + } + } + return 0; +} diff --git a/test/fuzzer/ImplicitIntegerTruncationTest.cpp b/test/fuzzer/ImplicitSignedIntegerTruncationTest.cpp index cb935da0c13e..9a17802e2a5f 100644 --- a/test/fuzzer/ImplicitIntegerTruncationTest.cpp +++ b/test/fuzzer/ImplicitSignedIntegerTruncationTest.cpp @@ -9,8 +9,8 @@ #include <cstdlib> #include <iostream> -static volatile int Sink; -static unsigned char Large = UINT8_MAX; +static volatile int32_t Sink; +static uint8_t Large = UINT8_MAX; extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { assert(Data); diff --git a/test/fuzzer/ImplicitUnsignedIntegerTruncationTest.cpp b/test/fuzzer/ImplicitUnsignedIntegerTruncationTest.cpp new file mode 100644 index 000000000000..c0bf40ab08f9 --- /dev/null +++ b/test/fuzzer/ImplicitUnsignedIntegerTruncationTest.cpp @@ -0,0 +1,27 @@ +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. + +// Test for unsigned-integer-overflow. +#include <assert.h> +#include <climits> +#include <cstddef> +#include <cstdint> +#include <cstdlib> +#include <iostream> + +static volatile int32_t Sink; +static uint8_t Large = UINT8_MAX; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + assert(Data); + if (Size > 0 && Data[0] == 'H') { + Sink = 1; + if (Size > 1 && Data[1] == 'i') { + Sink = 2; + if (Size > 2 && Data[2] == '!') { + Large = (unsigned int)Large + 1U; // 'char overflow'. + } + } + } + return 0; +} diff --git a/test/fuzzer/InitializeTest.cpp b/test/fuzzer/InitializeTest.cpp index a93c2a525088..5022c9efa640 100644 --- a/test/fuzzer/InitializeTest.cpp +++ b/test/fuzzer/InitializeTest.cpp @@ -9,7 +9,7 @@ #include <stdlib.h> #include <string.h> -static char *argv0; +static char *argv0 = NULL; extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { assert(*argc > 0); @@ -20,8 +20,7 @@ extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { assert(argv0); - if (Size == strlen(argv0) && - !memmem(Data, Size, argv0, Size)) { + if (argv0 && Size >= 4 && !memcmp(Data, "fuzz", 4)) { fprintf(stderr, "BINGO %s\n", argv0); exit(1); } diff --git a/test/fuzzer/PrintUnstableStatsTest.cpp b/test/fuzzer/PrintUnstableStatsTest.cpp deleted file mode 100644 index 078eb4c3d971..000000000000 --- a/test/fuzzer/PrintUnstableStatsTest.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include <assert.h> -#include <cstdint> -#include <cstdio> -#include <cstdlib> - -int x = 0; -bool skip0 = false; -bool skip1 = false; -bool skip2 = false; - -__attribute__((noinline)) void det0() { x++; } -__attribute__((noinline)) void det1() { x++; } -__attribute__((noinline)) void det2() { x++; } -__attribute__((noinline)) void det3() { x++; } -__attribute__((noinline)) void det4() { x++; } - -__attribute__((noinline)) void ini0() { x++; } -__attribute__((noinline)) void ini1() { x++; } -__attribute__((noinline)) void ini2() { x++; } - -__attribute__((noinline)) void t0() { x++; } -__attribute__((noinline)) void t1() { x++; } -__attribute__((noinline)) void t2() { x++; } -__attribute__((noinline)) void t3() { x++; } -__attribute__((noinline)) void t4() { x++; } - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { - if (Size == 1 && Data[0] == 'A' && !skip0) { - skip0 = true; - ini0(); - } - if (Size == 1 && Data[0] == 'B' && !skip1) { - skip1 = true; - ini1(); - } - if (Size == 1 && Data[0] == 'C' && !skip2) { - skip2 = true; - ini2(); - } - - det0(); - det1(); - int a = rand(); - det2(); - - switch (a % 5) { - case 0: - t0(); - break; - case 1: - t1(); - break; - case 2: - t2(); - break; - case 3: - t3(); - break; - case 4: - t4(); - break; - default: - assert(false); - } - - det3(); - det4(); - return 0; -} diff --git a/test/fuzzer/ReadBinaryTest.cpp b/test/fuzzer/ReadBinaryTest.cpp new file mode 100644 index 000000000000..de7a40036981 --- /dev/null +++ b/test/fuzzer/ReadBinaryTest.cpp @@ -0,0 +1,18 @@ +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. + +// Simple test for a fuzzer. Tests that fuzzer can read a file containing +// carriage returns. +#include <cstddef> +#include <cstdint> +#include <iostream> +#include <string> + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) { + std::string InputStr(reinterpret_cast<const char*>(Data), Size); + std::string MagicStr("Hello\r\nWorld\r\n"); + if (InputStr == MagicStr) { + std::cout << "BINGO!"; + } + return 0; +} diff --git a/test/fuzzer/SymbolizeDeadlock.cpp b/test/fuzzer/SymbolizeDeadlock.cpp index 5be1be804bce..b9ece38b2303 100644 --- a/test/fuzzer/SymbolizeDeadlock.cpp +++ b/test/fuzzer/SymbolizeDeadlock.cpp @@ -8,7 +8,6 @@ #include <cstdio> #include <cstdlib> #include <cstring> -#include <unistd.h> #include "Bingo.h" diff --git a/test/fuzzer/afl-driver-extra-stats.test b/test/fuzzer/afl-driver-extra-stats.test index cddb683e6dec..2f5641daf724 100644 --- a/test/fuzzer/afl-driver-extra-stats.test +++ b/test/fuzzer/afl-driver-extra-stats.test @@ -1,3 +1,5 @@ +# AFL doesn't work on Windows. No reason to test the driver. +UNSUPPORTED: windows XFAIL: ios RUN: %no_fuzzer_cpp_compiler %S/AFLDriverTest.cpp %libfuzzer_src/afl/afl_driver.cpp -o %t-AFLDriverTest diff --git a/test/fuzzer/afl-driver-stderr.test b/test/fuzzer/afl-driver-stderr.test index d3d739d3b977..5e3007e5427e 100644 --- a/test/fuzzer/afl-driver-stderr.test +++ b/test/fuzzer/afl-driver-stderr.test @@ -1,5 +1,6 @@ +# AFL doesn't work on Windows. No reason to test the driver. +UNSUPPORTED: freebsd, windows XFAIL: ios -UNSUPPORTED: freebsd RUN: %no_fuzzer_cpp_compiler %S/AFLDriverTest.cpp %libfuzzer_src/afl/afl_driver.cpp -o %t-AFLDriverTest ; Test that not specifying a stderr file isn't broken. diff --git a/test/fuzzer/counters.test b/test/fuzzer/counters.test index f75d3a03783f..8f461c6e1bb3 100644 --- a/test/fuzzer/counters.test +++ b/test/fuzzer/counters.test @@ -1,5 +1,4 @@ -XFAIL: ios -UNSUPPORTED: aarch64 +UNSUPPORTED: aarch64, ios RUN: %cpp_compiler %S/CounterTest.cpp -o %t-CounterTest RUN: not %run %t-CounterTest -max_len=6 -seed=1 -timeout=15 2>&1 | FileCheck %s --check-prefix=COUNTERS diff --git a/test/fuzzer/coverage.test b/test/fuzzer/coverage.test index 3b2341f21f69..ff7a436e3213 100644 --- a/test/fuzzer/coverage.test +++ b/test/fuzzer/coverage.test @@ -1,4 +1,5 @@ -UNSUPPORTED: aarch64 +# FIXME: Disabled on Windows because -fPIC cannot be used to compile for Windows. +UNSUPPORTED: windows RUN: %cpp_compiler -mllvm -use-unknown-locations=Disable %S/NullDerefTest.cpp -o %t-NullDerefTest RUN: %cpp_compiler -mllvm -use-unknown-locations=Disable %S/DSO1.cpp -fPIC %ld_flags_rpath_so1 -shared -o %dynamiclib1 RUN: %cpp_compiler -mllvm -use-unknown-locations=Disable %S/DSO2.cpp -fPIC %ld_flags_rpath_so2 -shared -o %dynamiclib2 diff --git a/test/fuzzer/dead-stripping.test b/test/fuzzer/dead-stripping.test new file mode 100644 index 000000000000..85445ea9f21b --- /dev/null +++ b/test/fuzzer/dead-stripping.test @@ -0,0 +1,23 @@ +REQUIRES: darwin + +No dead_strip. Unused code is not removed. +RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t +RUN: nm %t | grep UnusedFunctionShouldBeRemovedByLinker | count 1 +RUN: %run %t -runs=0 2>&1 | FileCheck %s + +With dead_strip. Unused code is not removed. +RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t -ffunction-sections -Wl,-dead_strip +RUN: nm %t | grep UnusedFunctionShouldBeRemovedByLinker | count 1 +RUN: %run %t -runs=0 2>&1 | FileCheck %s + +With dead_strip, with trace-pc. Unused code is removed. +RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t -ffunction-sections -fsanitize-coverage=0 -fsanitize-coverage=trace-pc -Wl,-dead_strip +RUN: nm %t | not grep UnusedFunctionShouldBeRemovedByLinker +RUN: %run %t -runs=0 2>&1 | FileCheck %s + +With dead_strip, with pc-table. Unused code is not removed. +RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t -ffunction-sections -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard,pc-table -Wl,-dead_strip +RUN: nm %t | grep UnusedFunctionShouldBeRemovedByLinker | count 1 +RUN: %run %t -runs=0 2>&1 | FileCheck %s + +CHECK-NOT: ERROR: The size of coverage PC tables does not match diff --git a/test/fuzzer/dso.test b/test/fuzzer/dso.test index fc1fe23818f0..60ef8a6ac832 100644 --- a/test/fuzzer/dso.test +++ b/test/fuzzer/dso.test @@ -1,3 +1,5 @@ +# FIXME: Disabled on Windows because -fPIC cannot be used to compile for Windows. +UNSUPPORTED: windows RUN: %cpp_compiler %S/DSO1.cpp -fPIC %ld_flags_rpath_so1 -shared -o %dynamiclib1 RUN: %cpp_compiler %S/DSO2.cpp -fPIC %ld_flags_rpath_so2 -shared -o %dynamiclib2 RUN: %cpp_compiler %S/DSOTestMain.cpp %S/DSOTestExtra.cpp %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t-DSOTest diff --git a/test/fuzzer/dump_coverage.test b/test/fuzzer/dump_coverage.test index 41e193824de6..803a4fbb8a05 100644 --- a/test/fuzzer/dump_coverage.test +++ b/test/fuzzer/dump_coverage.test @@ -1,4 +1,5 @@ -UNSUPPORTED: freebsd +# FIXME: Disabled on Windows because -fPIC cannot be used to compile for Windows. +UNSUPPORTED: freebsd, windows RUN: %cpp_compiler -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard %S/DSO1.cpp -fPIC -shared -o %dynamiclib1 %ld_flags_rpath_so1 RUN: %cpp_compiler -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard %S/DSO2.cpp -fPIC -shared -o %dynamiclib2 %ld_flags_rpath_so2 RUN: %cpp_compiler -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard %S/DSOTestMain.cpp %S/DSOTestExtra.cpp %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t-DSOTest @@ -7,7 +8,7 @@ RUN: %cpp_compiler -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard %S/N RUN: rm -rf %t_workdir && mkdir -p %t_workdir RUN: env ASAN_OPTIONS=coverage_dir='"%t_workdir"' not %run %t-NullDerefTest -dump_coverage=1 2>&1 | FileCheck %s -RUN: sancov -covered-functions %t-NullDerefTest* %t_workdir/*.sancov | FileCheck %s --check-prefix=SANCOV +RUN: sancov -covered-functions %t-NullDerefTest %t_workdir/*.sancov | FileCheck %s --check-prefix=SANCOV RUN: env ASAN_OPTIONS=coverage_dir='"%t_workdir"' %run %t-DSOTest -dump_coverage=1 -runs=0 2>&1 | FileCheck -allow-deprecated-dag-overlap %s --check-prefix=DSO RUN: env ASAN_OPTIONS=coverage_dir='"%t_workdir"' not %run %t-NullDerefTest -dump_coverage=0 2>&1 | FileCheck %s --check-prefix=NOCOV diff --git a/test/fuzzer/exit_on_src_pos.test b/test/fuzzer/exit_on_src_pos.test index ad0fa0a7ce4e..c08c01410e28 100644 --- a/test/fuzzer/exit_on_src_pos.test +++ b/test/fuzzer/exit_on_src_pos.test @@ -1,9 +1,11 @@ # Temporary use -mllvm -use-unknown-locations=Disable so that # all instructions have debug info (file line numbers) attached. # TODO: Find out why test fails on Darwin with -O2. -RUN: %cpp_compiler -O0 %S/SimpleTest.cpp -o %t-SimpleTest -mllvm -use-unknown-locations=Disable -RUN: %cpp_compiler -O0 %S/ShrinkControlFlowTest.cpp -o %t-ShrinkControlFlowTest +# Binaries must end in .exe or else symbolization will break on Windows because of how periods +# in expansion of %t cause the compiler to overwrite .lib and .exp files. +RUN: %cpp_compiler -O0 %S/SimpleTest.cpp -o %t-SimpleTest.exe -mllvm -use-unknown-locations=Disable +RUN: %cpp_compiler -O0 %S/ShrinkControlFlowTest.cpp -o %t-ShrinkControlFlowTest.exe -RUN: %run %t-SimpleTest -exit_on_src_pos=SimpleTest.cpp:18 2>&1 | FileCheck %s --check-prefix=EXIT_ON_SRC_POS -RUN: %run %t-ShrinkControlFlowTest -exit_on_src_pos=Foo 2>&1 | FileCheck %s --check-prefix=EXIT_ON_SRC_POS +RUN: %run %t-SimpleTest.exe -exit_on_src_pos=SimpleTest.cpp:18 2>&1 | FileCheck %s --check-prefix=EXIT_ON_SRC_POS +RUN: %run %t-ShrinkControlFlowTest.exe -exit_on_src_pos=Foo 2>&1 | FileCheck %s --check-prefix=EXIT_ON_SRC_POS EXIT_ON_SRC_POS: INFO: found line matching '{{.*}}', exiting. diff --git a/test/fuzzer/fuzzer-alignment-assumption.test b/test/fuzzer/fuzzer-alignment-assumption.test new file mode 100644 index 000000000000..6db77e19ccc8 --- /dev/null +++ b/test/fuzzer/fuzzer-alignment-assumption.test @@ -0,0 +1,7 @@ +RUN: rm -f %t-AlignmentAssumptionTest-Ubsan +RUN: %cpp_compiler -fsanitize=alignment -fno-sanitize-recover=all %S/AlignmentAssumptionTest.cpp -o %t-AlignmentAssumptionTest-Ubsan +RUN: not %run %t-AlignmentAssumptionTest-Ubsan 2>&1 | FileCheck %s +CHECK: AlignmentAssumptionTest.cpp:22:39: runtime error: assumption of 32768 byte alignment for pointer of type 'const {{.*}} *' (aka 'const unsigned char *') failed +CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte + +CHECK: Test unit written to ./crash- diff --git a/test/fuzzer/fuzzer-implicit-integer-sign-change.test b/test/fuzzer/fuzzer-implicit-integer-sign-change.test new file mode 100644 index 000000000000..7524f6cc4e5e --- /dev/null +++ b/test/fuzzer/fuzzer-implicit-integer-sign-change.test @@ -0,0 +1,5 @@ +RUN: rm -f %t-ImplicitIntegerSignChangeTest-Ubsan +RUN: %cpp_compiler -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=all %S/ImplicitIntegerSignChangeTest.cpp -o %t-ImplicitIntegerSignChangeTest-Ubsan +RUN: not %run %t-ImplicitIntegerSignChangeTest-Ubsan 2>&1 | FileCheck %s +CHECK: ImplicitIntegerSignChangeTest.cpp:22:16: runtime error: implicit conversion from type 'int32_t' (aka 'int') of value -1 (32-bit, signed) to type 'uint32_t' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) +CHECK: Test unit written to ./crash- diff --git a/test/fuzzer/fuzzer-implicit-integer-truncation.test b/test/fuzzer/fuzzer-implicit-integer-truncation.test deleted file mode 100644 index 212559bdca3c..000000000000 --- a/test/fuzzer/fuzzer-implicit-integer-truncation.test +++ /dev/null @@ -1,5 +0,0 @@ -RUN: rm -f %t-ImplicitIntegerTruncationTest-Ubsan -RUN: %cpp_compiler -fsanitize=implicit-integer-truncation -fno-sanitize-recover=all %S/ImplicitIntegerTruncationTest.cpp -o %t-ImplicitIntegerTruncationTest-Ubsan -RUN: not %run %t-ImplicitIntegerTruncationTest-Ubsan 2>&1 | FileCheck %s -CHECK: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'unsigned char' changed the value to 0 (8-bit, unsigned) -CHECK: Test unit written to ./crash- diff --git a/test/fuzzer/fuzzer-implicit-signed-integer-truncation-or-sign-change.test b/test/fuzzer/fuzzer-implicit-signed-integer-truncation-or-sign-change.test new file mode 100644 index 000000000000..532b36a03508 --- /dev/null +++ b/test/fuzzer/fuzzer-implicit-signed-integer-truncation-or-sign-change.test @@ -0,0 +1,5 @@ +RUN: rm -f %t-ImplicitSignedIntegerTruncationOrSignChangeTest-Ubsan +RUN: %cpp_compiler -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=all %S/ImplicitSignedIntegerTruncationOrSignChangeTest.cpp -o %t-ImplicitSignedIntegerTruncationOrSignChangeTest-Ubsan +RUN: not %run %t-ImplicitSignedIntegerTruncationOrSignChangeTest-Ubsan 2>&1 | FileCheck %s +CHECK: ImplicitSignedIntegerTruncationOrSignChangeTest.cpp:22:16: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'int8_t' (aka 'signed char') changed the value to -1 (8-bit, signed) +CHECK: Test unit written to ./crash- diff --git a/test/fuzzer/fuzzer-implicit-signed-integer-truncation.test b/test/fuzzer/fuzzer-implicit-signed-integer-truncation.test new file mode 100644 index 000000000000..d41625d3aede --- /dev/null +++ b/test/fuzzer/fuzzer-implicit-signed-integer-truncation.test @@ -0,0 +1,5 @@ +RUN: rm -f %t-ImplicitSignedIntegerTruncationTest-Ubsan +RUN: %cpp_compiler -fsanitize=implicit-signed-integer-truncation -fno-sanitize-recover=all %S/ImplicitSignedIntegerTruncationTest.cpp -o %t-ImplicitSignedIntegerTruncationTest-Ubsan +RUN: not %run %t-ImplicitSignedIntegerTruncationTest-Ubsan 2>&1 | FileCheck %s +CHECK: ImplicitSignedIntegerTruncationTest.cpp:22:17: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) +CHECK: Test unit written to ./crash- diff --git a/test/fuzzer/fuzzer-implicit-unsigned-integer-truncation.test b/test/fuzzer/fuzzer-implicit-unsigned-integer-truncation.test new file mode 100644 index 000000000000..e62a01e9eb24 --- /dev/null +++ b/test/fuzzer/fuzzer-implicit-unsigned-integer-truncation.test @@ -0,0 +1,5 @@ +RUN: rm -f %t-ImplicitUnsignedIntegerTruncationTest-Ubsan +RUN: %cpp_compiler -fsanitize=implicit-unsigned-integer-truncation -fno-sanitize-recover=all %S/ImplicitUnsignedIntegerTruncationTest.cpp -o %t-ImplicitUnsignedIntegerTruncationTest-Ubsan +RUN: not %run %t-ImplicitUnsignedIntegerTruncationTest-Ubsan 2>&1 | FileCheck %s +CHECK: ImplicitUnsignedIntegerTruncationTest.cpp:22:17: runtime error: implicit conversion from type 'unsigned int' of value 256 (32-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) +CHECK: Test unit written to ./crash- diff --git a/test/fuzzer/fuzzer-mutationstats.test b/test/fuzzer/fuzzer-mutationstats.test deleted file mode 100644 index 95743a818d1f..000000000000 --- a/test/fuzzer/fuzzer-mutationstats.test +++ /dev/null @@ -1,5 +0,0 @@ -RUN: %cpp_compiler %S/SimpleTest.cpp -o %t-MutationStatsTest -RUN: not %run %t-MutationStatsTest -print_mutation_stats=1 2>&1 | FileCheck %s - -# Ensures there are some non-zero values in the usefulness percentages printed. -CHECK: stat::mutation_usefulness: {{[0-9]+\.[0-9]+}} diff --git a/test/fuzzer/fuzzer-oom.test b/test/fuzzer/fuzzer-oom.test index e82fb47c5bed..9bc451c50ee9 100644 --- a/test/fuzzer/fuzzer-oom.test +++ b/test/fuzzer/fuzzer-oom.test @@ -1,17 +1,21 @@ -UNSUPPORTED: aarch64 -RUN: %cpp_compiler %S/OutOfMemoryTest.cpp -o %t-OutOfMemoryTest -RUN: %cpp_compiler %S/OutOfMemorySingleLargeMallocTest.cpp -o %t-OutOfMemorySingleLargeMallocTest -RUN: %cpp_compiler %S/AccumulateAllocationsTest.cpp -o %t-AccumulateAllocationsTest +UNSUPPORTED: aarch64, ios +# Tests break on windows unless exe extension is used (because there are periods +# in expansion of %t, the string after the period is interpreted as the file +# extension, so each compilation will clobber the previous one's lib and exp +# files causing symbolization to break). +RUN: %cpp_compiler %S/OutOfMemoryTest.cpp -o %t-OutOfMemoryTest.exe +RUN: %cpp_compiler %S/OutOfMemorySingleLargeMallocTest.cpp -o %t-OutOfMemorySingleLargeMallocTest.exe +RUN: %cpp_compiler %S/AccumulateAllocationsTest.cpp -o %t-AccumulateAllocationsTest.exe -RUN: not %run %t-OutOfMemoryTest -rss_limit_mb=300 2>&1 | FileCheck %s +RUN: not %run %t-OutOfMemoryTest.exe -rss_limit_mb=300 2>&1 | FileCheck %s CHECK: ERROR: libFuzzer: out-of-memory (used: {{.*}}; limit: 300Mb) CHECK: Test unit written to ./oom- SUMMARY: libFuzzer: out-of-memory -RUN: not %run %t-OutOfMemorySingleLargeMallocTest -rss_limit_mb=300 2>&1 | FileCheck %s --check-prefix=SINGLE_LARGE_MALLOC -RUN: not %run %t-OutOfMemorySingleLargeMallocTest -malloc_limit_mb=300 2>&1 | FileCheck %s --check-prefix=SINGLE_LARGE_MALLOC -RUN: not %run %t-OutOfMemorySingleLargeMallocTest -rss_limit_mb=1000 -malloc_limit_mb=300 2>&1 | FileCheck %s --check-prefix=SINGLE_LARGE_MALLOC +RUN: not %run %t-OutOfMemorySingleLargeMallocTest.exe -rss_limit_mb=300 2>&1 | FileCheck %s --check-prefix=SINGLE_LARGE_MALLOC +RUN: not %run %t-OutOfMemorySingleLargeMallocTest.exe -malloc_limit_mb=300 2>&1 | FileCheck %s --check-prefix=SINGLE_LARGE_MALLOC +RUN: not %run %t-OutOfMemorySingleLargeMallocTest.exe -rss_limit_mb=1000 -malloc_limit_mb=300 2>&1 | FileCheck %s --check-prefix=SINGLE_LARGE_MALLOC We used to check for "out-of-memory (malloc(53{{.*}}))", but that would fail sometimes, so now we accept any OOM message. @@ -20,4 +24,4 @@ SINGLE_LARGE_MALLOC: libFuzzer: out-of-memory SINGLE_LARGE_MALLOC: in LLVMFuzzerTestOneInput # Check that -rss_limit_mb=0 means no limit. -RUN: %run %t-AccumulateAllocationsTest -runs=1000 -rss_limit_mb=0 +RUN: %run %t-AccumulateAllocationsTest.exe -runs=1000 -rss_limit_mb=0 diff --git a/test/fuzzer/gc-sections.test b/test/fuzzer/gc-sections.test index b8abfbbdf17b..e915c4cc9eb0 100644 --- a/test/fuzzer/gc-sections.test +++ b/test/fuzzer/gc-sections.test @@ -8,8 +8,13 @@ With gc-sections. Currently, we can't remove unused code except with LLD. RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t -fuse-ld=lld -ffunction-sections -Wl,-gc-sections RUN: nm %t | not grep UnusedFunctionShouldBeRemovedByLinker RUN: %run %t -runs=0 2>&1 | FileCheck %s -CHECK-NOT: ERROR: The size of coverage PC tables does not match With gc sections, with trace-pc. Unused code is removed. RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t -fsanitize-coverage=0 -fsanitize-coverage=trace-pc -ffunction-sections -Wl,-gc-sections RUN: nm %t | not grep UnusedFunctionShouldBeRemovedByLinker + +RUN: %cpp_compiler %S/GcSectionsTest.cpp -o %t -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard,pc-table -fuse-ld=lld -ffunction-sections -Wl,-gc-sections +RUN: nm %t | not grep UnusedFunctionShouldBeRemovedByLinker +RUN: %run %t -runs=0 2>&1 | FileCheck %s + +CHECK-NOT: ERROR: The size of coverage PC tables does not match diff --git a/test/fuzzer/handle-unstable.test b/test/fuzzer/handle-unstable.test deleted file mode 100644 index 798ee2dc042f..000000000000 --- a/test/fuzzer/handle-unstable.test +++ /dev/null @@ -1,42 +0,0 @@ -# Tests -handle_unstable -UNSUPPORTED: aarch64 - -RUN: %cpp_compiler %S/PrintUnstableStatsTest.cpp -o %t-HandleUnstableTest - -; Normal -RUN: %run %t-HandleUnstableTest -print_coverage=1 -runs=100000 2>&1 | FileCheck %s --check-prefix=NORMAL -NORMAL-DAG: det0() -NORMAL-DAG: det1() -NORMAL-DAG: det2() -NORMAL-DAG: det3() -NORMAL-DAG: det4() -NORMAL-DAG: ini0() -NORMAL-DAG: ini1() -NORMAL-DAG: ini2() -NORMAL-DAG: t0() -NORMAL-DAG: t1() -NORMAL-DAG: t2() -NORMAL-DAG: t3() -NORMAL-DAG: t4() - -; MinUnstable -RUN: %run %t-HandleUnstableTest -print_coverage=1 -handle_unstable=1 -runs=100000 2>&1 | FileCheck %s --check-prefix=MIN -MIN-NOT: ini0() -MIN-NOT: ini1() -MIN-NOT: ini2() -MIN: det0() -MIN: det1() -MIN: det2() -MIN: det3() -MIN: det4() - -; ZeroUnstable -RUN: %run %t-HandleUnstableTest -print_coverage=1 -handle_unstable=2 -runs=1 2>&1 | FileCheck %s --check-prefix=ZERO -ZERO-NOT: ini0() -ZERO-NOT: ini1() -ZERO-NOT: ini2() -ZERO: det0() -ZERO: det1() -ZERO: det2() -ZERO: det3() -ZERO: det4() diff --git a/test/fuzzer/lit.cfg b/test/fuzzer/lit.cfg index 8a44860d4a5d..608991c0764f 100644 --- a/test/fuzzer/lit.cfg +++ b/test/fuzzer/lit.cfg @@ -24,15 +24,18 @@ else: # the test runner updated. config.test_format = lit.formats.ShTest(execute_external) -# LeakSanitizer is not supported on OSX right now. -if sys.platform.startswith('darwin') or sys.platform.startswith('freebsd'): +# LeakSanitizer is not supported on OSX or Windows right now. +if (sys.platform.startswith('darwin') or + sys.platform.startswith('freebsd') or + sys.platform.startswith('netbsd') or + sys.platform.startswith('win')): lit_config.note('lsan feature unavailable') else: lit_config.note('lsan feature available') config.available_features.add('lsan') -# MemorySanitizer is not supported on OSX right now -if sys.platform.startswith('darwin'): +# MemorySanitizer is not supported on OSX or Windows right now +if sys.platform.startswith('darwin') or sys.platform.startswith('win'): lit_config.note('msan feature unavailable') assert 'msan' not in config.available_features else: @@ -67,10 +70,18 @@ def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=False): config.runtime_library_dir) elif any(x in config.target_triple for x in ('darwin', 'freebsd')): link_cmd = '-lc++' + elif 'windows-msvc' in config.target_triple: + link_cmd = '' else: link_cmd = '-lstdc++' - std_cmd = '--driver-mode=g++ -std=c++11' if is_cpp else '' + if is_cpp and 'windows-msvc' in config.target_triple: + std_cmd = '--driver-mode=cl' + elif is_cpp: + std_cmd = '--driver-mode=g++ -std=c++11' + else: + std_cmd = '' + if msan_enabled: sanitizers = ['memory'] else: diff --git a/test/fuzzer/merge-control-file.test b/test/fuzzer/merge-control-file.test index 64b747116a9f..60b2a6a627ca 100644 --- a/test/fuzzer/merge-control-file.test +++ b/test/fuzzer/merge-control-file.test @@ -1,6 +1,8 @@ XFAIL: ios RUN: mkdir -p %t -RUN: %cpp_compiler %S/FullCoverageSetTest.cpp -o %t/T +# Use a ".exe" extension because it is needed on Windows to call system() +# to execute itself again. +RUN: %cpp_compiler %S/FullCoverageSetTest.cpp -o %t/T.exe RUN: rm -rf %t/T0 %t/T1 %t/T2 RUN: mkdir -p %t/T0 %t/T1 %t/T2 @@ -11,9 +13,9 @@ RUN: echo ..Z... > %t/T0/3 # Test what happens if the control file is junk. RUN: echo JUNK > %t/MCF -RUN: not %run %t/T -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF 2>&1 | FileCheck %s --check-prefix=JUNK +RUN: not %run %t/T.exe -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF 2>&1 | FileCheck %s --check-prefix=JUNK RUN: echo 3 > %t/MCF; echo 0 >> %t/MCF; echo %t/T1/1 >> %t/MCF -RUN: not %run %t/T -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF 2>&1 | FileCheck %s --check-prefix=JUNK +RUN: not %run %t/T.exe -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF 2>&1 | FileCheck %s --check-prefix=JUNK JUNK: MERGE-OUTER: non-empty control file provided: {{.*}}MCF JUNK: MERGE-OUTER: bad control file, will overwrite it @@ -22,18 +24,18 @@ JUNK: MERGE-OUTER: bad control file, will overwrite it RUN: rm -f %t/T1/*; cp %t/T0/* %t/T1 RUN: echo 3 > %t/MCF; echo 0 >> %t/MCF; echo %t/T1/1 >> %t/MCF; echo %t/T1/2 >> %t/MCF; echo %t/T1/3 >> %t/MCF -RUN: %run %t/T -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF 2>&1 | FileCheck %s --check-prefix=OK_0 +RUN: %run %t/T.exe -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF 2>&1 | FileCheck %s --check-prefix=OK_0 OK_0: MERGE-OUTER: control file ok, 3 files total, first not processed file 0 OK_0: MERGE-OUTER: 3 new files with {{.*}} new features added RUN: rm -f %t/T1/*; cp %t/T0/* %t/T1 RUN: echo 3 > %t/MCF; echo 0 >> %t/MCF; echo %t/T1/1 >> %t/MCF; echo %t/T1/2 >> %t/MCF; echo %t/T1/3 >> %t/MCF -RUN: %run %t/T -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF -save_coverage_summary=%t/SUMMARY 2>&1 | FileCheck %s --check-prefix=SAVE_SUMMARY +RUN: %run %t/T.exe -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF -save_coverage_summary=%t/SUMMARY 2>&1 | FileCheck %s --check-prefix=SAVE_SUMMARY SAVE_SUMMARY: MERGE-OUTER: writing coverage summary for 3 files to {{.*}}/SUMMARY RUN: rm -f %t/T1/*; cp %t/T0/* %t/T1 RUN: echo 3 > %t/MCF; echo 0 >> %t/MCF; echo %t/T1/1 >> %t/MCF; echo %t/T1/2 >> %t/MCF; echo %t/T1/3 >> %t/MCF -RUN: %run %t/T -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF -load_coverage_summary=%t/SUMMARY 2>&1 | FileCheck %s --check-prefix=LOAD_SUMMARY +RUN: %run %t/T.exe -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF -load_coverage_summary=%t/SUMMARY 2>&1 | FileCheck %s --check-prefix=LOAD_SUMMARY LOAD_SUMMARY: MERGE-OUTER: coverage summary loaded from RUN: rm -f %t/T1/*; cp %t/T0/* %t/T1 @@ -42,7 +44,7 @@ RUN: echo STARTED 0 1 >> %t/MCF RUN: echo DONE 0 11 >> %t/MCF RUN: echo STARTED 1 2 >> %t/MCF RUN: echo DONE 1 12 >> %t/MCF -RUN: %run %t/T -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF 2>&1 | FileCheck %s --check-prefix=OK_2 +RUN: %run %t/T.exe -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF 2>&1 | FileCheck %s --check-prefix=OK_2 OK_2: MERGE-OUTER: control file ok, 3 files total, first not processed file 2 OK_2: MERGE-OUTER: 3 new files with {{.*}} new features added @@ -54,5 +56,5 @@ RUN: echo STARTED 1 2 >> %t/MCF RUN: echo DONE 1 12 >> %t/MCF RUN: echo STARTED 2 2 >> %t/MCF RUN: echo DONE 2 13 >> %t/MCF -RUN: %run %t/T -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF 2>&1 | FileCheck %s --check-prefix=OK_3 +RUN: %run %t/T.exe -merge=1 %t/T1 %t/T2 -merge_control_file=%t/MCF 2>&1 | FileCheck %s --check-prefix=OK_3 OK_3: MERGE-OUTER: nothing to do, merge has been completed before diff --git a/test/fuzzer/merge-posix.test b/test/fuzzer/merge-posix.test index db0a48b5481e..883b7b6be97b 100644 --- a/test/fuzzer/merge-posix.test +++ b/test/fuzzer/merge-posix.test @@ -1,4 +1,5 @@ XFAIL: ios +UNSUPPORTED: windows RUN: %cpp_compiler %S/FullCoverageSetTest.cpp -o %t-FullCoverageSetTest RUN: rm -rf %tmp/T1 %tmp/T2 diff --git a/test/fuzzer/merge-sigusr.test b/test/fuzzer/merge-sigusr.test index a03e5440a8b8..44448ca29e63 100644 --- a/test/fuzzer/merge-sigusr.test +++ b/test/fuzzer/merge-sigusr.test @@ -1,5 +1,7 @@ # Check that libFuzzer honors SIGUSR1/SIGUSR2 -UNSUPPORTED: darwin +# FIXME: Disabled on Windows for now because of reliance on posix only features +# (eg: export, "&", pkill). +UNSUPPORTED: darwin, windows RUN: rm -rf %t RUN: mkdir -p %t RUN: %cpp_compiler %S/SleepOneSecondTest.cpp -o %t/LFSIGUSR diff --git a/test/fuzzer/minimize_crash.test b/test/fuzzer/minimize_crash.test index de44b8747e04..dcab67bfde32 100644 --- a/test/fuzzer/minimize_crash.test +++ b/test/fuzzer/minimize_crash.test @@ -1,3 +1,4 @@ +UNSUPPORTED: windows RUN: %cpp_compiler %S/NullDerefTest.cpp -o %t-NullDerefTest RUN: %cpp_compiler %S/SingleByteInputTest.cpp -o %t-SingleByteInputTest RUN: mkdir -p %t.dir diff --git a/test/fuzzer/minimize_two_crashes.test b/test/fuzzer/minimize_two_crashes.test index 3c528f707666..cba88eed12e4 100644 --- a/test/fuzzer/minimize_two_crashes.test +++ b/test/fuzzer/minimize_two_crashes.test @@ -1,5 +1,5 @@ -# Test that the minimizer stops when it sees a differe bug. -UNSUPPORTED: freebsd +# Test that the minimizer stops when it sees a different bug. +UNSUPPORTED: freebsd,windows # TODO: Find out why test fails on Darwin with -O2. RUN: %cpp_compiler -O0 %S/TwoDifferentBugsTest.cpp -o %t-TwoDifferentBugsTest diff --git a/test/fuzzer/null-deref-on-empty.test b/test/fuzzer/null-deref-on-empty.test index f159a79f4838..d576cc12b131 100644 --- a/test/fuzzer/null-deref-on-empty.test +++ b/test/fuzzer/null-deref-on-empty.test @@ -1,3 +1,4 @@ +UNSUPPORTED: windows RUN: %cpp_compiler %S/NullDerefOnEmptyTest.cpp -o %t-NullDerefOnEmptyTest RUN: not %run %t-NullDerefOnEmptyTest -print_final_stats=1 2>&1 | FileCheck %s --check-prefix=NULL_DEREF_ON_EMPTY diff --git a/test/fuzzer/null-deref.test b/test/fuzzer/null-deref.test index 31eb5990da33..e9926cab48e8 100644 --- a/test/fuzzer/null-deref.test +++ b/test/fuzzer/null-deref.test @@ -1,3 +1,4 @@ +UNSUPPORTED: windows RUN: %cpp_compiler %S/NullDerefTest.cpp -o %t-NullDerefTest RUN: not %run %t-NullDerefTest 2>&1 | FileCheck %s --check-prefix=NullDerefTest diff --git a/test/fuzzer/only-some-bytes.test b/test/fuzzer/only-some-bytes.test index fbfef14c7850..861718384080 100644 --- a/test/fuzzer/only-some-bytes.test +++ b/test/fuzzer/only-some-bytes.test @@ -34,5 +34,5 @@ HAVE_DFT: INFO: 1/{{.*}} inputs have the Data Flow Trace # Collect DFT, then use it. RUN: rm -rf %t/C && mkdir %t/C && cp %t/IN/* %t/C RUN: rm -rf %t/C_DFT && %libfuzzer_src/scripts/collect_data_flow.py %t-DFT %t/C %t/C_DFT > /dev/null 2>&1 -RUN: not %t-Fuzz -focus_function=f0 -data_flow_trace=%t/C_DFT -seed=1 -runs=1000000 -use_value_profile=3 %t/C 2> %t/log +RUN: not %t-Fuzz -focus_function=f0 -data_flow_trace=%t/C_DFT -seed=1 -runs=1000000 -use_value_profile=1 %t/C 2> %t/log RUN: grep BINGO %t/log diff --git a/test/fuzzer/print_unstable_stats.test b/test/fuzzer/print_unstable_stats.test deleted file mode 100644 index bba99aecc838..000000000000 --- a/test/fuzzer/print_unstable_stats.test +++ /dev/null @@ -1,3 +0,0 @@ -RUN: %cpp_compiler %S/PrintUnstableStatsTest.cpp -o %t-PrintUnstableStatsTest -RUN: %run %t-PrintUnstableStatsTest -print_unstable_stats=1 -runs=100000 2>&1 | FileCheck %s --check-prefix=LONG -LONG: stat::stability_rate: 27.59 diff --git a/test/fuzzer/read-binary.test b/test/fuzzer/read-binary.test new file mode 100644 index 000000000000..c80858e81134 --- /dev/null +++ b/test/fuzzer/read-binary.test @@ -0,0 +1,7 @@ +# Test that libFuzzer reads files properly. + +# Account for the fact that echo will add a trailing newline. +RUN: echo -e "Hello\r\nWorld\r" > %t-testcase +RUN: %cpp_compiler %S/ReadBinaryTest.cpp -o %t-fuzzer +RUN: %run %t-fuzzer %t-testcase | FileCheck %s +CHECK: BINGO! diff --git a/test/fuzzer/shrink.test b/test/fuzzer/shrink.test index 5abbcc90b8c0..78386ffaf092 100644 --- a/test/fuzzer/shrink.test +++ b/test/fuzzer/shrink.test @@ -1,6 +1,6 @@ RUN: %cpp_compiler %S/ShrinkControlFlowTest.cpp -o %t-ShrinkControlFlowTest RUN: %cpp_compiler %S/ShrinkValueProfileTest.cpp -o %t-ShrinkValueProfileTest -RUN: %run %t-ShrinkControlFlowTest -seed=1 -exit_on_item=0eb8e4ed029b774d80f2b66408203801cb982a60 -runs=1000000 -shrink=1 -reduce_inputs=0 2>&1 | FileCheck %s --check-prefix=SHRINK1 +RUN: %run %t-ShrinkControlFlowTest -seed=1 -exit_on_item=0eb8e4ed029b774d80f2b66408203801cb982a60 -runs=2000000 -shrink=1 -reduce_inputs=0 2>&1 | FileCheck %s --check-prefix=SHRINK1 # Limit max_len to run this negative test faster. RUN: %run %t-ShrinkControlFlowTest -seed=1 -exit_on_item=0eb8e4ed029b774d80f2b66408203801cb982a60 -runs=1000000 -shrink=0 -reduce_inputs=0 -max_len=64 2>&1 | FileCheck %s --check-prefix=SHRINK0 RUN: %run %t-ShrinkValueProfileTest -seed=1 -exit_on_item=aea2e3923af219a8956f626558ef32f30a914ebc -runs=100000 -shrink=1 -reduce_inputs=0 -use_value_profile=1 2>&1 | FileCheck %s --check-prefix=SHRINK1_VP diff --git a/test/fuzzer/sigusr.test b/test/fuzzer/sigusr.test index 0b3ddc72832d..fa477a76eea1 100644 --- a/test/fuzzer/sigusr.test +++ b/test/fuzzer/sigusr.test @@ -1,4 +1,6 @@ -UNSUPPORTED: darwin +# FIXME: Disabled on Windows for now because of reliance on posix only features +# (eg: export, "&", pkill). +UNSUPPORTED: darwin, windows # Check that libFuzzer honors SIGUSR1/SIGUSR2 RUN: rm -rf %t RUN: mkdir -p %t diff --git a/test/fuzzer/trace-malloc-threaded.test b/test/fuzzer/trace-malloc-threaded.test index 8f972d61f5c6..f38005c1d2f6 100644 --- a/test/fuzzer/trace-malloc-threaded.test +++ b/test/fuzzer/trace-malloc-threaded.test @@ -1,6 +1,7 @@ // FIXME: This test infinite loops on darwin because it crashes // printing a stack trace repeatedly -UNSUPPORTED: darwin, aarch64 +// FIXME: Disabled on Windows because of a crash (possibly related to above). +UNSUPPORTED: darwin, aarch64, windows RUN: %cpp_compiler %S/TraceMallocThreadedTest.cpp -o \ RUN: %t-TraceMallocThreadedTest diff --git a/test/fuzzer/trace-malloc-unbalanced.test b/test/fuzzer/trace-malloc-unbalanced.test index 193df01ddeff..c7b4632140cb 100644 --- a/test/fuzzer/trace-malloc-unbalanced.test +++ b/test/fuzzer/trace-malloc-unbalanced.test @@ -6,14 +6,17 @@ UNSUPPORTED: darwin RUN: %cpp_compiler %S/TraceMallocTest.cpp -o %t-TraceMallocTest +# Specify python because we can't use the shebang line on Windows. RUN: %run %t-TraceMallocTest -seed=1 -trace_malloc=1 -runs=200 2>&1 | \ -RUN: %libfuzzer_src/scripts/unbalanced_allocs.py --skip=5 | FileCheck %s +RUN: python %libfuzzer_src/scripts/unbalanced_allocs.py --skip=5 | FileCheck %s RUN: %run %t-TraceMallocTest -seed=1 -trace_malloc=2 -runs=200 2>&1 | \ -RUN: %libfuzzer_src/scripts/unbalanced_allocs.py --skip=5 | FileCheck %s --check-prefixes=CHECK,CHECK2 +RUN: python %libfuzzer_src/scripts/unbalanced_allocs.py --skip=5 | FileCheck %s --check-prefixes=CHECK,CHECK2 CHECK: MallocFreeTracer: START -CHECK: Unbalanced MALLOC[{{[0-9]+}}] [[PTR:0x[0-9a-f]+]] 4 +# Behavior of the format string "%p" is implementation defined. Account for the +# implementation on Windows and Linux. +CHECK: Unbalanced MALLOC[{{[0-9]+}}] [[PTR:(:?0x)?[0-9a-fA-F]+]] 4 CHECK2-NEXT: {{ #0 0x[0-9a-f]+ in }} CHECK2-NEXT: {{ #1 0x[0-9a-f]+ in }} CHECK2-NEXT: {{ #2 0x[0-9a-f]+ in }} diff --git a/test/fuzzer/ulimit.test b/test/fuzzer/ulimit.test index 076866c50940..7cf4c0a68866 100644 --- a/test/fuzzer/ulimit.test +++ b/test/fuzzer/ulimit.test @@ -1,3 +1,5 @@ +# FIXME: Disabled on Windows for now because Windows has no ulimit command. +UNSUPPORTED: windows RUN: %cpp_compiler %S/SimpleTest.cpp -o %t-SimpleTest RUN: ulimit -s 1000 RUN: not %run %t-SimpleTest diff --git a/test/fuzzer/value-profile-cmp.test b/test/fuzzer/value-profile-cmp.test index b927422d10ff..8f6ffe99cd65 100644 --- a/test/fuzzer/value-profile-cmp.test +++ b/test/fuzzer/value-profile-cmp.test @@ -1,3 +1,5 @@ +# FIXME: Disabled on Windows because of hangs. +UNSUPPORTED: windows, ios CHECK: BINGO RUN: %cpp_compiler %S/SimpleCmpTest.cpp -o %t-SimpleCmpTest RUN: not %run %t-SimpleCmpTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 2>&1 | FileCheck %s diff --git a/test/fuzzer/value-profile-cmp2.test b/test/fuzzer/value-profile-cmp2.test index 4bf119fcb3df..5935ed6d1325 100644 --- a/test/fuzzer/value-profile-cmp2.test +++ b/test/fuzzer/value-profile-cmp2.test @@ -1,3 +1,4 @@ +UNSUPPORTED: ios CHECK: BINGO RUN: %cpp_compiler -fno-sanitize=address %S/SimpleHashTest.cpp -o %t-SimpleHashTest RUN: not %run %t-SimpleHashTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 -max_len=64 2>&1 | FileCheck %s diff --git a/test/fuzzer/value-profile-cmp3.test b/test/fuzzer/value-profile-cmp3.test index 58ba18b9001e..fe715925f801 100644 --- a/test/fuzzer/value-profile-cmp3.test +++ b/test/fuzzer/value-profile-cmp3.test @@ -1,3 +1,4 @@ +UNSUPPORTED: ios CHECK: BINGO RUN: %cpp_compiler %S/AbsNegAndConstantTest.cpp -o %t-AbsNegAndConstantTest RUN: not %run %t-AbsNegAndConstantTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 2>&1 | FileCheck %s diff --git a/test/fuzzer/value-profile-cmp4.test b/test/fuzzer/value-profile-cmp4.test index 05bc3f435912..e5ac29f81c43 100644 --- a/test/fuzzer/value-profile-cmp4.test +++ b/test/fuzzer/value-profile-cmp4.test @@ -1,3 +1,5 @@ +# FIXME: Disabled on Windows because of hangs. +UNSUPPORTED: windows CHECK: BINGO RUN: %cpp_compiler %S/AbsNegAndConstant64Test.cpp -o %t-AbsNegAndConstant64Test RUN: not %run %t-AbsNegAndConstant64Test -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 2>&1 | FileCheck %s diff --git a/test/fuzzer/value-profile-div.test b/test/fuzzer/value-profile-div.test index 59cc7c2f9552..38f211241b0f 100644 --- a/test/fuzzer/value-profile-div.test +++ b/test/fuzzer/value-profile-div.test @@ -1,4 +1,4 @@ -XFAIL: ios +UNSUPPORTED: ios UNSUPPORTED: aarch64 CHECK: AddressSanitizer: {{FPE|int-divide-by-zero}} RUN: %cpp_compiler %S/DivTest.cpp -fsanitize-coverage=trace-div -o %t-DivTest diff --git a/test/fuzzer/value-profile-load.test b/test/fuzzer/value-profile-load.test index 607b81cd527f..b6baf13200d4 100644 --- a/test/fuzzer/value-profile-load.test +++ b/test/fuzzer/value-profile-load.test @@ -1,3 +1,5 @@ +# FIXME: Disabled on Windows because of hangs. +UNSUPPORTED: windows CHECK: AddressSanitizer: global-buffer-overflow RUN: %cpp_compiler %S/LoadTest.cpp -fsanitize-coverage=trace-gep -o %t-LoadTest RUN: not %run %t-LoadTest -seed=2 -use_cmp=0 -use_value_profile=1 -runs=20000000 2>&1 | FileCheck %s diff --git a/test/fuzzer/value-profile-mem.test b/test/fuzzer/value-profile-mem.test index 57c844e92261..7d68b8811cf0 100644 --- a/test/fuzzer/value-profile-mem.test +++ b/test/fuzzer/value-profile-mem.test @@ -1,3 +1,4 @@ +UNSUPPORTED: ios UNSUPPORTED: freebsd CHECK: BINGO RUN: %cpp_compiler %S/SingleMemcmpTest.cpp -o %t-SingleMemcmpTest diff --git a/test/fuzzer/value-profile-set.test b/test/fuzzer/value-profile-set.test index e55f1e4a853a..7515e3651f01 100644 --- a/test/fuzzer/value-profile-set.test +++ b/test/fuzzer/value-profile-set.test @@ -1,3 +1,4 @@ +UNSUPPORTED: ios CHECK: BINGO RUN: %cpp_compiler %S/FourIndependentBranchesTest.cpp -o %t-FourIndependentBranchesTest RUN: not %run %t-FourIndependentBranchesTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 2>&1 | FileCheck %s diff --git a/test/fuzzer/value-profile-strcmp.test b/test/fuzzer/value-profile-strcmp.test index 647121f22820..9b7a244d73c2 100644 --- a/test/fuzzer/value-profile-strcmp.test +++ b/test/fuzzer/value-profile-strcmp.test @@ -1,3 +1,4 @@ +UNSUPPORTED: ios UNSUPPORTED: freebsd CHECK: BINGO RUN: %cpp_compiler %S/SingleStrcmpTest.cpp -o %t-SingleStrcmpTest diff --git a/test/fuzzer/value-profile-strncmp.test b/test/fuzzer/value-profile-strncmp.test index b60b97f86f3e..98488df0a552 100644 --- a/test/fuzzer/value-profile-strncmp.test +++ b/test/fuzzer/value-profile-strncmp.test @@ -1,4 +1,4 @@ -UNSUPPORTED: freebsd +UNSUPPORTED: freebsd, aarch64 CHECK: BINGO RUN: %cpp_compiler %S/SingleStrncmpTest.cpp -o %t-SingleStrncmpTest RUN: not %run %t-SingleStrncmpTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 2>&1 | FileCheck %s diff --git a/test/fuzzer/value-profile-switch.test b/test/fuzzer/value-profile-switch.test index cc3d4944c0bf..a71682d79404 100644 --- a/test/fuzzer/value-profile-switch.test +++ b/test/fuzzer/value-profile-switch.test @@ -1,4 +1,4 @@ -XFAIL: ios +UNSUPPORTED: ios CHECK: BINGO RUN: %cpp_compiler %S/SwitchTest.cpp -o %t-SwitchTest RUN: %cpp_compiler %S/Switch2Test.cpp -o %t-Switch2Test diff --git a/test/fuzzer/windows-opt-ref.test b/test/fuzzer/windows-opt-ref.test new file mode 100644 index 000000000000..1f3386d13478 --- /dev/null +++ b/test/fuzzer/windows-opt-ref.test @@ -0,0 +1,9 @@ +REQUIRES: windows +// Verify that the linker eliminating unreferenced functions (/OPT:REF) does not +// strip sancov module constructor. +RUN: %cpp_compiler %S/SimpleCmpTest.cpp -o %t-SimpleCmpTest /link /OPT:REF + +RUN: not %run %t-SimpleCmpTest -seed=1 -runs=100000000 2>&1 | FileCheck %s + +CHECK-NOT: ERROR: no interesting inputs were found. Is the code instrumented for coverage? Exiting. +CHECK: BINGO diff --git a/test/hwasan/CMakeLists.txt b/test/hwasan/CMakeLists.txt index 972c73250cf3..3e397ac067f2 100644 --- a/test/hwasan/CMakeLists.txt +++ b/test/hwasan/CMakeLists.txt @@ -11,6 +11,9 @@ foreach(arch ${HWASAN_TEST_ARCH}) string(TOUPPER ${arch} ARCH_UPPER_CASE) set(CONFIG_NAME ${ARCH_UPPER_CASE}) + # FIXME: Set this. + set(HWASAN_ANDROID_FILES_TO_PUSH []) + configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg) diff --git a/test/hwasan/TestCases/Posix/system-allocator-fallback.cc b/test/hwasan/TestCases/Posix/system-allocator-fallback.cc new file mode 100644 index 000000000000..8678d906daec --- /dev/null +++ b/test/hwasan/TestCases/Posix/system-allocator-fallback.cc @@ -0,0 +1,54 @@ +// RUN: %clangxx %s -o %t -ldl +// RUN: %clangxx_hwasan -shared %s -o %t.so -DSHARED_LIB -shared-libsan -Wl,-rpath,%compiler_rt_libdir +// RUN: %env_hwasan_opts=disable_allocator_tagging=0 %run %t + +// The dynamic loader on Android O appears to have a bug where it crashes when +// dlopening DF_1_GLOBAL libraries. +// REQUIRES: android-28 + +#include <stddef.h> + +// Test that allocations made by the system allocator can be realloc'd and freed +// by the hwasan allocator. + +typedef void run_test_fn(void *(*system_malloc)(size_t size)); + +#ifdef SHARED_LIB + +// Call the __sanitizer_ versions of these functions so that the test +// doesn't require the Android dynamic loader. +extern "C" void *__sanitizer_realloc(void *ptr, size_t size); +extern "C" void __sanitizer_free(void *ptr); + +extern "C" run_test_fn run_test; +void run_test(void *(*system_malloc)(size_t size)) { + void *mem = system_malloc(64); + mem = __sanitizer_realloc(mem, 128); + __sanitizer_free(mem); +} + +#else + +#include <dlfcn.h> +#include <stdlib.h> +#include <string> + +int main(int argc, char **argv) { + std::string path = argv[0]; + path += ".so"; + void *lib = dlopen(path.c_str(), RTLD_NOW); + if (!lib) { + printf("error in dlopen(): %s\n", dlerror()); + return 1; + } + + auto run_test = reinterpret_cast<run_test_fn *>(dlsym(lib, "run_test")); + if (!run_test) { + printf("failed dlsym\n"); + return 1; + } + + run_test(malloc); +} + +#endif diff --git a/test/hwasan/TestCases/abort-message-android.cc b/test/hwasan/TestCases/abort-message-android.cc new file mode 100644 index 000000000000..f89b929d454d --- /dev/null +++ b/test/hwasan/TestCases/abort-message-android.cc @@ -0,0 +1,28 @@ +// RUN: %clangxx_hwasan -DERR=1 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clangxx_hwasan -DERR=2 %s -o %t && not %run %t 2>&1 | FileCheck %s +// REQUIRES: android + +#include <stdlib.h> +#include <stdio.h> + +#include <sanitizer/hwasan_interface.h> + +__attribute__((no_sanitize("hwaddress"))) +extern "C" void android_set_abort_message(const char *msg) { + fprintf(stderr, "== abort message start\n%s\n== abort message end\n", msg); +} + +int main() { + __hwasan_enable_allocator_tagging(); + char *volatile p = (char *)malloc(16); + if (ERR==1) { + p[16] = 1; + } else { + free(p); + free(p); + } + // CHECK: ERROR: HWAddressSanitizer: + // CHECK: == abort message start + // CHECK: ERROR: HWAddressSanitizer: + // CHECK: == abort message end +} diff --git a/test/hwasan/TestCases/cfi.cc b/test/hwasan/TestCases/cfi.cc new file mode 100644 index 000000000000..457e29659e77 --- /dev/null +++ b/test/hwasan/TestCases/cfi.cc @@ -0,0 +1,18 @@ +// RUN: %clang_hwasan -fsanitize=cfi -fno-sanitize-trap=cfi -flto -fvisibility=hidden -fuse-ld=lld %s -o %t +// RUN: not %run %t 2>&1 | FileCheck %s + +// REQUIRES: android + +// Smoke test for CFI + HWASAN. + +struct A { + virtual void f(); +}; + +void A::f() {} + +int main() { + // CHECK: control flow integrity check for type {{.*}} failed during cast to unrelated type + A *a = reinterpret_cast<A *>(reinterpret_cast<void *>(&main)); + (void)a; +} diff --git a/test/hwasan/TestCases/deep-recursion.c b/test/hwasan/TestCases/deep-recursion.c new file mode 100644 index 000000000000..2fe77a7bdaaf --- /dev/null +++ b/test/hwasan/TestCases/deep-recursion.c @@ -0,0 +1,73 @@ +// RUN: %clang_hwasan -O1 %s -o %t +// RUN: %env_hwasan_opts=stack_history_size=1 not %run %t 2>&1 | FileCheck %s --check-prefix=D1 +// RUN: %env_hwasan_opts=stack_history_size=2 not %run %t 2>&1 | FileCheck %s --check-prefix=D2 +// RUN: %env_hwasan_opts=stack_history_size=3 not %run %t 2>&1 | FileCheck %s --check-prefix=D3 +// RUN: %env_hwasan_opts=stack_history_size=5 not %run %t 2>&1 | FileCheck %s --check-prefix=D5 +// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=DEFAULT + +// REQUIRES: stable-runtime + +#include <stdlib.h> +// At least -O1 is needed for this function to not have a stack frame on +// AArch64. +void USE(void *x) { // pretend_to_do_something(void *x) + __asm__ __volatile__("" : : "r" (x) : "memory"); +} + +volatile int four = 4; + +__attribute__((noinline)) void OOB() { int x[4]; x[four] = 0; USE(&x[0]); } +__attribute__((noinline)) void FUNC1() { int x; USE(&x); OOB(); } +__attribute__((noinline)) void FUNC2() { int x; USE(&x); FUNC1(); } +__attribute__((noinline)) void FUNC3() { int x; USE(&x); FUNC2(); } +__attribute__((noinline)) void FUNC4() { int x; USE(&x); FUNC3(); } +__attribute__((noinline)) void FUNC5() { int x; USE(&x); FUNC4(); } +__attribute__((noinline)) void FUNC6() { int x; USE(&x); FUNC5(); } +__attribute__((noinline)) void FUNC7() { int x; USE(&x); FUNC6(); } +__attribute__((noinline)) void FUNC8() { int x; USE(&x); FUNC7(); } +__attribute__((noinline)) void FUNC9() { int x; USE(&x); FUNC8(); } +__attribute__((noinline)) void FUNC10() { int x; USE(&x); FUNC9(); } + +int main() { FUNC10(); } + +// D1: Previously allocated frames +// D1: in OOB +// D1-NOT: in FUNC +// D1: Memory tags around the buggy address + +// D2: Previously allocated frames +// D2: in OOB +// D2: in FUNC1 +// D2-NOT: in FUNC +// D2: Memory tags around the buggy address + +// D3: Previously allocated frames +// D3: in OOB +// D3: in FUNC1 +// D3: in FUNC2 +// D3-NOT: in FUNC +// D3: Memory tags around the buggy address + +// D5: Previously allocated frames +// D5: in OOB +// D5: in FUNC1 +// D5: in FUNC2 +// D5: in FUNC3 +// D5: in FUNC4 +// D5-NOT: in FUNC +// D5: Memory tags around the buggy address + +// DEFAULT: Previously allocated frames +// DEFAULT: in OOB +// DEFAULT: in FUNC1 +// DEFAULT: in FUNC2 +// DEFAULT: in FUNC3 +// DEFAULT: in FUNC4 +// DEFAULT: in FUNC5 +// DEFAULT: in FUNC6 +// DEFAULT: in FUNC7 +// DEFAULT: in FUNC8 +// DEFAULT: in FUNC9 +// DEFAULT: in FUNC10 +// DEFAULT-NOT: in FUNC +// DEFAULT: Memory tags around the buggy address diff --git a/test/hwasan/TestCases/double-free.c b/test/hwasan/TestCases/double-free.c new file mode 100644 index 000000000000..e97aae6edb4c --- /dev/null +++ b/test/hwasan/TestCases/double-free.c @@ -0,0 +1,23 @@ +// RUN: %clang_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s + +// REQUIRES: stable-runtime + +#include <stdlib.h> +#include <stdio.h> +#include <sanitizer/hwasan_interface.h> + +int main() { + __hwasan_enable_allocator_tagging(); + char * volatile x = (char*)malloc(40); + free(x); + free(x); +// CHECK: ERROR: HWAddressSanitizer: invalid-free on address +// CHECK: tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem) +// CHECK: freed by thread {{.*}} here: +// CHECK: previously allocated here: +// CHECK: Memory tags around the buggy address (one tag corresponds to 16 bytes): +// CHECK: =>{{.*}}[[MEM_TAG]] + fprintf(stderr, "DONE\n"); + __hwasan_disable_allocator_tagging(); +// CHECK-NOT: DONE +} diff --git a/test/hwasan/TestCases/heap-buffer-overflow.c b/test/hwasan/TestCases/heap-buffer-overflow.c new file mode 100644 index 000000000000..9f605b3208d6 --- /dev/null +++ b/test/hwasan/TestCases/heap-buffer-overflow.c @@ -0,0 +1,60 @@ +// RUN: %clang_hwasan %s -o %t +// RUN: not %run %t 40 2>&1 | FileCheck %s --check-prefix=CHECK40-LEFT +// RUN: %env_hwasan_opts=malloc_align_right=2 not %run %t 40 2>&1 | FileCheck %s --check-prefix=CHECK40-RIGHT +// RUN: not %run %t 80 2>&1 | FileCheck %s --check-prefix=CHECK80-LEFT +// RUN: %env_hwasan_opts=malloc_align_right=2 not %run %t 80 2>&1 | FileCheck %s --check-prefix=CHECK80-RIGHT +// RUN: not %run %t -30 2>&1 | FileCheck %s --check-prefix=CHECKm30 +// RUN: not %run %t -30 1000000 2>&1 | FileCheck %s --check-prefix=CHECKMm30 +// RUN: not %run %t 1000000 1000000 2>&1 | FileCheck %s --check-prefix=CHECKM + +// Test OOB within the granule. +// Misses the bug when malloc is left-aligned, catches it otherwise. +// RUN: %run %t 31 +// RUN: %env_hwasan_opts=malloc_align_right=2 not %run %t 31 2>&1 | FileCheck %s --check-prefix=CHECK31 + +// RUN: %run %t 30 20 +// RUN: %env_hwasan_opts=malloc_align_right=9 not %run %t 30 20 2>&1 | FileCheck %s --check-prefix=CHECK20-RIGHT8 + +// RUN: %env_hwasan_opts=malloc_align_right=42 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WRONG-FLAG + +// REQUIRES: stable-runtime + +#include <stdlib.h> +#include <stdio.h> +#include <sanitizer/hwasan_interface.h> + +static volatile char sink; + +int main(int argc, char **argv) { + __hwasan_enable_allocator_tagging(); + int offset = argc < 2 ? 40 : atoi(argv[1]); + int size = argc < 3 ? 30 : atoi(argv[2]); + char * volatile x = (char*)malloc(size); + fprintf(stderr, "base: %p access: %p\n", x, &x[offset]); + sink = x[offset]; + +// CHECK40-LEFT: allocated heap chunk; size: 32 offset: 8 +// CHECK40-LEFT: is located 10 bytes to the right of 30-byte region +// CHECK40-RIGHT: allocated heap chunk; size: 32 offset: +// CHECK40-RIGHT: is located 10 bytes to the right of 30-byte region +// +// CHECK80-LEFT: allocated heap chunk; size: 32 offset: 16 +// CHECK80-LEFT: is located 50 bytes to the right of 30-byte region +// CHECK80-RIGHT: allocated heap chunk; size: 32 offset: +// CHECK80-RIGHT: is located 50 bytes to the right of 30-byte region +// +// CHECKm30: is located 30 bytes to the left of 30-byte region +// +// CHECKMm30: is a large allocated heap chunk; size: 1003520 offset: -30 +// CHECKMm30: is located 30 bytes to the left of 1000000-byte region +// +// CHECKM: is a large allocated heap chunk; size: 1003520 offset: 1000000 +// CHECKM: is located 0 bytes to the right of 1000000-byte region +// +// CHECK31: is located 1 bytes to the right of 30-byte region +// +// CHECK20-RIGHT8: is located 10 bytes to the right of 20-byte region [0x{{.*}}8,0x{{.*}}c) +// +// CHECK-WRONG-FLAG: ERROR: unsupported value of malloc_align_right flag: 42 + free(x); +} diff --git a/test/hwasan/TestCases/hwasan-print-shadow.cc b/test/hwasan/TestCases/hwasan-print-shadow.cc new file mode 100644 index 000000000000..fa6330bbcccd --- /dev/null +++ b/test/hwasan/TestCases/hwasan-print-shadow.cc @@ -0,0 +1,29 @@ +// RUN: %clangxx_hwasan -DSIZE=16 -O0 %s -o %t && %run %t 2>&1 | FileCheck %s + +// REQUIRES: stable-runtime + +#include <assert.h> +#include <stdlib.h> +#include <sys/mman.h> +#include <sanitizer/hwasan_interface.h> + +int main() { + char *p = (char *)mmap(nullptr, 4096, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + assert(p); + + __hwasan_tag_memory(p, 1, 32); + __hwasan_tag_memory(p + 32, 3, 16); + __hwasan_tag_memory(p + 48, 0, 32); + __hwasan_tag_memory(p + 80, 4, 16); + + char *q = (char *)__hwasan_tag_pointer(p, 7); + __hwasan_print_shadow(q + 5, 89 - 5); + // CHECK: HWASan shadow map for {{.*}}5 .. {{.*}}9 (pointer tag 7) + // CHECK-NEXT: {{.*}}0: 1 + // CHECK-NEXT: {{.*}}0: 1 + // CHECK-NEXT: {{.*}}0: 3 + // CHECK-NEXT: {{.*}}0: 0 + // CHECK-NEXT: {{.*}}0: 0 + // CHECK-NEXT: {{.*}}0: 4 +} diff --git a/test/hwasan/TestCases/longjmp.c b/test/hwasan/TestCases/longjmp.c new file mode 100644 index 000000000000..8d847b54b275 --- /dev/null +++ b/test/hwasan/TestCases/longjmp.c @@ -0,0 +1,26 @@ +// RUN: %clang_hwasan -O0 -DNEGATIVE %s -o %t && %run %t 2>&1 +// RUN: %clang_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s + +// REQUIRES: stable-runtime + +#include <stdlib.h> +#include <assert.h> +#include <sanitizer/hwasan_interface.h> + +__attribute__((noinline)) +int f(void *caller_frame) { + int z = 0; + int *volatile p = &z; + // Tag of local is never zero. + assert(__hwasan_tag_pointer(p, 0) != p); +#ifndef NEGATIVE + // This will destroy shadow of "z", and the following load will crash. + __hwasan_handle_longjmp(caller_frame); +#endif + return p[0]; +} + +int main() { + return f(__builtin_frame_address(0)); + // CHECK: READ of size 8 at {{.*}} tags: {{.*}}/00 (ptr/mem) +} diff --git a/test/hwasan/TestCases/malloc-test.c b/test/hwasan/TestCases/malloc-test.c new file mode 100644 index 000000000000..199464b9c300 --- /dev/null +++ b/test/hwasan/TestCases/malloc-test.c @@ -0,0 +1,16 @@ +// Test basic malloc functionality. +// RUN: %clang_hwasan %s -o %t +// RUN: %run %t + +#include <stdlib.h> +#include <assert.h> +#include <sanitizer/hwasan_interface.h> +#include <sanitizer/allocator_interface.h> + +int main() { + __hwasan_enable_allocator_tagging(); + char *a1 = (char*)malloc(0); + assert(a1 != 0); + assert(__sanitizer_get_allocated_size(a1) == 0); + free(a1); +} diff --git a/test/hwasan/TestCases/malloc_fill.cc b/test/hwasan/TestCases/malloc_fill.cc new file mode 100644 index 000000000000..b8513b7e2b73 --- /dev/null +++ b/test/hwasan/TestCases/malloc_fill.cc @@ -0,0 +1,22 @@ +// Check that we fill malloc-ed memory correctly. +// RUN: %clangxx_hwasan %s -o %t +// RUN: %run %t | FileCheck %s +// RUN: %env_hwasan_opts=max_malloc_fill_size=10:malloc_fill_byte=8 %run %t | FileCheck %s --check-prefix=CHECK-10-8 +// RUN: %env_hwasan_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) { + // With asan allocator this makes sure we get memory from mmap. + static const int kSize = 1 << 25; + unsigned char *x = new unsigned char[kSize]; + printf("-"); + for (int i = 0; i <= 32; i++) { + printf("%02x", x[i]); + } + printf("-\n"); + delete [] x; +} + +// CHECK: -bebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebe- +// CHECK-10-8: -080808080808080808080000000000000000000000000000000000000000000000- +// CHECK-20-ab: -abababababababababababababababababababab00000000000000000000000000- diff --git a/test/hwasan/TestCases/many-threads-uaf.c b/test/hwasan/TestCases/many-threads-uaf.c new file mode 100644 index 000000000000..3a79cb37b608 --- /dev/null +++ b/test/hwasan/TestCases/many-threads-uaf.c @@ -0,0 +1,45 @@ +// RUN: %clang_hwasan %s -o %t && not %env_hwasan_opts=verbose_threads=1 %run %t 2>&1 | FileCheck %s +// REQUIRES: stable-runtime + +#include <pthread.h> +#include <stdlib.h> +#include <stdio.h> + +#include <sanitizer/hwasan_interface.h> + +void *BoringThread(void *arg) { + char * volatile x = (char*)malloc(10); + x[5] = 0; + free(x); + return NULL; +} + +// CHECK: Creating : T0 +// CHECK: Creating : T1 +// CHECK: Destroying: T1 +// CHECK: Creating : T1100 +// CHECK: Destroying: T1100 +// CHECK: Creating : T1101 + +void *UAFThread(void *arg) { + char * volatile x = (char*)malloc(10); + fprintf(stderr, "ZZZ %p\n", x); + free(x); + x[5] = 42; + // CHECK: ERROR: HWAddressSanitizer: tag-mismatch on address + // CHECK: WRITE of size 1 + // CHECK: many-threads-uaf.c:[[@LINE-3]] + // CHECK: Thread: T1101 + return NULL; +} + +int main() { + __hwasan_enable_allocator_tagging(); + pthread_t t; + for (int i = 0; i < 1100; i++) { + pthread_create(&t, NULL, BoringThread, NULL); + pthread_join(t, NULL); + } + pthread_create(&t, NULL, UAFThread, NULL); + pthread_join(t, NULL); +} diff --git a/test/hwasan/TestCases/mem-intrinsics-zero-size.c b/test/hwasan/TestCases/mem-intrinsics-zero-size.c new file mode 100644 index 000000000000..bcb8e0771f1e --- /dev/null +++ b/test/hwasan/TestCases/mem-intrinsics-zero-size.c @@ -0,0 +1,10 @@ +// RUN: %clang_hwasan %s -o %t && %run %t + +#include <string.h> + +int main() { + char a[1]; + memset(a, 0, 0); + memmove(a, a, 0); + memcpy(a, a, 0); +} diff --git a/test/hwasan/TestCases/mem-intrinsics.c b/test/hwasan/TestCases/mem-intrinsics.c new file mode 100644 index 000000000000..164bc6d93335 --- /dev/null +++ b/test/hwasan/TestCases/mem-intrinsics.c @@ -0,0 +1,37 @@ +// RUN: %clang_hwasan %s -DTEST_NO=1 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=WRITE +// RUN: %clang_hwasan %s -DTEST_NO=2 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=READ +// RUN: %clang_hwasan %s -DTEST_NO=3 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=WRITE +// RUN: %clang_hwasan %s -DTEST_NO=2 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER + +// REQUIRES: stable-runtime + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +int main() { + char Q[16]; + char P[16]; +#if TEST_NO == 1 + memset(Q, 0, 32); +#elif TEST_NO == 2 + memmove(Q, Q + 16, 16); +#elif TEST_NO == 3 + memcpy(Q, P, 32); +#endif + write(STDOUT_FILENO, "recovered\n", 10); + // WRITE: ERROR: HWAddressSanitizer: tag-mismatch on address + // WRITE: WRITE {{.*}} tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem) + // WRITE: Memory tags around the buggy address (one tag corresponds to 16 bytes): + // WRITE: =>{{.*}}[[MEM_TAG]] + // WRITE-NOT: recovered + + // READ: ERROR: HWAddressSanitizer: tag-mismatch on address + // READ: READ {{.*}} tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem) + // READ: Memory tags around the buggy address (one tag corresponds to 16 bytes): + // READ: =>{{.*}}[[MEM_TAG]] + // READ-NOT: recovered + + // RECOVER: recovered + return 0; +} diff --git a/test/hwasan/TestCases/new-test.cc b/test/hwasan/TestCases/new-test.cc new file mode 100644 index 000000000000..3b1991e4deaa --- /dev/null +++ b/test/hwasan/TestCases/new-test.cc @@ -0,0 +1,18 @@ +// Test basic new functionality. +// RUN: %clangxx_hwasan %s -o %t +// RUN: %run %t + +#include <stdlib.h> +#include <assert.h> +#include <sanitizer/hwasan_interface.h> +#include <sanitizer/allocator_interface.h> + +int main() { + __hwasan_enable_allocator_tagging(); + + size_t volatile n = 0; + char *a1 = new char[n]; + assert(a1 != nullptr); + assert(__sanitizer_get_allocated_size(a1) == 0); + delete[] a1; +} diff --git a/test/hwasan/TestCases/print-memory-usage-android.c b/test/hwasan/TestCases/print-memory-usage-android.c new file mode 100644 index 000000000000..5a057928ba75 --- /dev/null +++ b/test/hwasan/TestCases/print-memory-usage-android.c @@ -0,0 +1,21 @@ +// Tests __hwasan_print_memory_usage through /proc/$PID/maps. +// RUN: %clang_hwasan %s -o %t && %env_hwasan_opts=export_memory_stats=1 %run %t 2>&1 | FileCheck %s +// REQUIRES: android + +#include <sys/types.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +// The function needs to be unsanitized in order for &cmd to be untagged. This +// address is passed to system() and then to execve() syscall. The tests need to +// run on unpatched linux kernel, which at this time does not accept tagged +// pointers in system call arguments (but there is hope: see +// https://lore.kernel.org/patchwork/cover/979328). +__attribute__((no_sanitize("hwaddress"))) +int main() { + char cmd[1024]; + snprintf(cmd, sizeof(cmd), "cat /proc/%d/maps", getpid()); + system(cmd); + // CHECK: HWASAN pid: [[PID:[0-9]*]] rss: {{.*}} threads: 1 stacks: [[STACKS:[0-9]*]] thr_aux: {{.*}} stack_depot: {{.*}} uniq_stacks: [[UNIQ_STACKS:[0-9]*]] heap: [[HEAP:[0-9]*]] +} diff --git a/test/hwasan/TestCases/print-memory-usage.c b/test/hwasan/TestCases/print-memory-usage.c new file mode 100644 index 000000000000..df9d534f32d4 --- /dev/null +++ b/test/hwasan/TestCases/print-memory-usage.c @@ -0,0 +1,72 @@ +// Tests __hwasan_print_memory_usage. +// RUN: %clang_hwasan %s -o %t +// RUN: ulimit -s 1000 +// RUN: %run %t 2>&1 | FileCheck %s +// REQUIRES: stable-runtime + +#include <pthread.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include <sanitizer/hwasan_interface.h> + +int state; +__thread volatile char *sink; + +__attribute__((noinline)) +void *malloc_and_use(int size) { + char *x = (char*)malloc(size); + for (int i = 0; i < size; i++) + x[i] = 42; // make this memory used. + return x; +} + +void *T1(void *arg) { + + for (int i = 1; i <= (1 << 20); i *= 2) + sink = malloc_and_use(i); + + __sync_fetch_and_add(&state, 1); + while (__sync_fetch_and_add(&state, 0) != 4) {} + return NULL; +} + +void *T4(void *arg) { return NULL; } + +int main() { + __hwasan_enable_allocator_tagging(); + sink = malloc_and_use(10); + + __hwasan_print_memory_usage(); + // CHECK: HWASAN pid: [[PID:[0-9]*]] rss: {{.*}} threads: 1 stacks: [[STACKS:[0-9]*]] thr_aux: {{.*}} stack_depot: {{.*}} uniq_stacks: [[UNIQ_STACKS:[0-9]*]] heap: [[HEAP:[0-9]*]] + + void *one_meg = malloc_and_use(1 << 20); + + __hwasan_print_memory_usage(); + // CHECK: HWASAN pid: [[PID]] rss: {{.*}} threads: 1 stacks: [[STACKS]] thr_aux: {{.*}} stack_depot: {{.*}} + + free(one_meg); + + __hwasan_print_memory_usage(); + // CHECK: HWASAN pid: [[PID]] rss: {{.*}} threads: 1 stacks: [[STACKS]] thr_aux: {{.*}} stack_depot: {{.*}} uniq_stacks: {{.*}} heap: [[HEAP]] + + pthread_t t1, t2, t3, t4; + + pthread_create(&t1, NULL, T1, NULL); + pthread_create(&t2, NULL, T1, NULL); + pthread_create(&t3, NULL, T1, NULL); + pthread_create(&t4, NULL, T4, NULL); + while (__sync_fetch_and_add(&state, 0) != 3) {} + pthread_join(t4, NULL); + + __hwasan_print_memory_usage(); + // CHECK: HWASAN pid: [[PID]] rss: {{.*}} threads: 4 stacks: + + __sync_fetch_and_add(&state, 1); + pthread_join(t1, NULL); + pthread_join(t2, NULL); + pthread_join(t3, NULL); + __hwasan_print_memory_usage(); + // CHECK: HWASAN pid: [[PID]] rss: {{.*}} threads: 1 stacks: [[STACKS]] +} diff --git a/test/hwasan/TestCases/pthread_exit.c b/test/hwasan/TestCases/pthread_exit.c new file mode 100644 index 000000000000..937e20c6ad19 --- /dev/null +++ b/test/hwasan/TestCases/pthread_exit.c @@ -0,0 +1,5 @@ +// Tests pthread_exit. +// RUN: %clang_hwasan %s -o %t && %run %t +// REQUIRES: stable-runtime +#include <pthread.h> +int main() { pthread_exit(NULL); } diff --git a/test/hwasan/TestCases/random-align-right.c b/test/hwasan/TestCases/random-align-right.c new file mode 100644 index 000000000000..8c524ef4784d --- /dev/null +++ b/test/hwasan/TestCases/random-align-right.c @@ -0,0 +1,35 @@ +// Tests malloc_align_right=1 and 8 (randomly aligning right). +// RUN: %clang_hwasan %s -o %t +// +// RUN: %run %t +// RUN: %env_hwasan_opts=malloc_align_right=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 +// RUN: %env_hwasan_opts=malloc_align_right=8 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK8 + +// REQUIRES: stable-runtime + +#include <stdlib.h> +#include <stdio.h> +#include <sanitizer/hwasan_interface.h> + +static volatile void *sink; + +int main(int argc, char **argv) { + __hwasan_enable_allocator_tagging(); + + // Perform 1000 buffer overflows within the 16-byte granule, + // so that random right-alignment has a very high chance of + // catching at least one of them. + for (int i = 0; i < 1000; i++) { + char *p = (char*)malloc(20); + sink = p; + fprintf(stderr, "[%d] p: %p; accessing p[20]:\n", i, p); + p[20 * argc] = 0; // requires malloc_align_right=1 to catch + fprintf(stderr, "[%d] p: %p; accessing p[30]:\n", i, p); + p[30 * argc] = 0; // requires malloc_align_right={1,8} to catch +// CHECK1: accessing p[20] +// CHECK1-NEXT: HWAddressSanitizer: tag-mismatch +// CHECK8: accessing p[30]: +// CHECK8-NEXT: HWAddressSanitizer: tag-mismatch + } +} + diff --git a/test/hwasan/TestCases/realloc-after-free.c b/test/hwasan/TestCases/realloc-after-free.c new file mode 100644 index 000000000000..c4bc48c9ccda --- /dev/null +++ b/test/hwasan/TestCases/realloc-after-free.c @@ -0,0 +1,28 @@ +// RUN: %clang_hwasan %s -o %t +// RUN: not %run %t 50 2>&1 | FileCheck %s +// RUN: not %run %t 40 2>&1 | FileCheck %s +// RUN: not %run %t 30 2>&1 | FileCheck %s + +// REQUIRES: stable-runtime + +#include <stdlib.h> +#include <stdio.h> +#include <sanitizer/hwasan_interface.h> + +int main(int argc, char **argv) { + __hwasan_enable_allocator_tagging(); + if (argc != 2) return 0; + int realloc_size = atoi(argv[1]); + char * volatile x = (char*)malloc(40); + free(x); + x = realloc(x, realloc_size); +// CHECK: ERROR: HWAddressSanitizer: invalid-free on address +// CHECK: tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem) +// CHECK: freed by thread {{.*}} here: +// CHECK: previously allocated here: +// CHECK: Memory tags around the buggy address (one tag corresponds to 16 bytes): +// CHECK: =>{{.*}}[[MEM_TAG]] + fprintf(stderr, "DONE\n"); + __hwasan_disable_allocator_tagging(); +// CHECK-NOT: DONE +} diff --git a/test/hwasan/TestCases/realloc-test.cc b/test/hwasan/TestCases/realloc-test.cc new file mode 100644 index 000000000000..838790242426 --- /dev/null +++ b/test/hwasan/TestCases/realloc-test.cc @@ -0,0 +1,37 @@ +// Test basic realloc functionality. +// RUN: %clang_hwasan %s -o %t +// RUN: %run %t + +#include <stdlib.h> +#include <assert.h> +#include <sanitizer/hwasan_interface.h> + +int main() { + __hwasan_enable_allocator_tagging(); + char *x = (char*)realloc(nullptr, 4); + x[0] = 10; + x[1] = 20; + x[2] = 30; + x[3] = 40; + char *x1 = (char*)realloc(x, 5); + assert(x1 != x); // not necessary true for C, + // but true today for hwasan. + assert(x1[0] == 10 && x1[1] == 20 && x1[2] == 30 && x1[3] == 40); + x1[4] = 50; + + char *x2 = (char*)realloc(x1, 6); + x2[5] = 60; + assert(x2 != x1); + assert(x2[0] == 10 && x2[1] == 20 && x2[2] == 30 && x2[3] == 40 && + x2[4] == 50 && x2[5] == 60); + + char *x3 = (char*)realloc(x2, 6); + assert(x3 != x2); + assert(x3[0] == 10 && x3[1] == 20 && x3[2] == 30 && x3[3] == 40 && + x3[4] == 50 && x3[5] == 60); + + char *x4 = (char*)realloc(x3, 5); + assert(x4 != x3); + assert(x4[0] == 10 && x4[1] == 20 && x4[2] == 30 && x4[3] == 40 && + x4[4] == 50); +} diff --git a/test/hwasan/TestCases/rich-stack.c b/test/hwasan/TestCases/rich-stack.c new file mode 100644 index 000000000000..6787d57769f4 --- /dev/null +++ b/test/hwasan/TestCases/rich-stack.c @@ -0,0 +1,66 @@ +// Test how stack frames are reported (not fully implemented yet). +// RUN: %clang_hwasan %s -o %t +// RUN: not %run %t 3 2 -1 2>&1 | FileCheck %s --check-prefix=R321 +// REQUIRES: stable-runtime +#include <stdint.h> +#include <stdlib.h> +void USE(void *x) { // pretend_to_do_something(void *x) + __asm__ __volatile__("" : : "r" (x) : "memory"); +} +void USE2(void *a, void *b) { USE(a); USE(b); } +void USE4(void *a, void *b, void *c, void *d) { USE2(a, b); USE2(c, d); } + +void BAR(int depth, int err_depth, int offset); + +uint64_t *leaked_ptr; + +void FOO(int depth, int err_depth, int offset) { + uint8_t v1; + uint16_t v2; + uint32_t v4; + uint64_t v8; + uint64_t v16[2]; + uint64_t v32[4]; + uint64_t v48[3]; + USE4(&v1, &v2, &v4, &v8); USE4(&v16, &v32, &v48, 0); + leaked_ptr = &v16[0]; + if (depth) + BAR(depth - 1, err_depth, offset); + + if (err_depth == depth) + v16[offset] = 0; // maybe OOB. + if (err_depth == -depth) + leaked_ptr[offset] = 0; // maybe UAR. + USE(&v16); +} + +void BAR(int depth, int err_depth, int offset) { + uint64_t x16[2]; + uint64_t x32[4]; + USE2(&x16, &x32); + leaked_ptr = &x16[0]; + if (depth) + FOO(depth - 1, err_depth, offset); + if (err_depth == depth) + x16[offset] = 0; // maybe OOB + if (err_depth == -depth) + leaked_ptr[offset] = 0; // maybe UAR + USE(&x16); +} + + +int main(int argc, char **argv) { + if (argc != 4) return -1; + int depth = atoi(argv[1]); + int err_depth = atoi(argv[2]); + int offset = atoi(argv[3]); + FOO(depth, err_depth, offset); + return 0; +} + +// R321: HWAddressSanitizer: tag-mismatch +// R321-NEXT: WRITE of size 8 +// R321-NEXT: in BAR +// R321-NEXT: in FOO +// R321-NEXT: in main +// R321: is located in stack of thread T0 diff --git a/test/hwasan/TestCases/sanitizer_malloc.cc b/test/hwasan/TestCases/sanitizer_malloc.cc new file mode 100644 index 000000000000..66ac9641e109 --- /dev/null +++ b/test/hwasan/TestCases/sanitizer_malloc.cc @@ -0,0 +1,29 @@ +// Test allocator aliases. +// +// RUN: %clangxx_hwasan -O0 %s -o %t && %run %t + +#include <sanitizer/hwasan_interface.h> + +int main() { + void *volatile sink; + sink = (void *)&__sanitizer_posix_memalign; + sink = (void *)&__sanitizer_memalign; + sink = (void *)&__sanitizer_aligned_alloc; + sink = (void *)&__sanitizer___libc_memalign; + sink = (void *)&__sanitizer_valloc; + sink = (void *)&__sanitizer_pvalloc; + sink = (void *)&__sanitizer_free; + sink = (void *)&__sanitizer_cfree; + sink = (void *)&__sanitizer_malloc_usable_size; + sink = (void *)&__sanitizer_mallinfo; + sink = (void *)&__sanitizer_mallopt; + sink = (void *)&__sanitizer_malloc_stats; + sink = (void *)&__sanitizer_calloc; + sink = (void *)&__sanitizer_realloc; + sink = (void *)&__sanitizer_malloc; + + // sanity check + void *p = __sanitizer_malloc(100); + p = __sanitizer_realloc(p, 200); + __sanitizer_free(p); +} diff --git a/test/hwasan/TestCases/sizes.cpp b/test/hwasan/TestCases/sizes.cpp new file mode 100644 index 000000000000..52217de746e3 --- /dev/null +++ b/test/hwasan/TestCases/sizes.cpp @@ -0,0 +1,80 @@ +// RUN: %clangxx_hwasan %s -lstdc++ -o %t +// RUN: %env_hwasan_opts=allocator_may_return_null=0 not %run %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-max +// RUN: %env_hwasan_opts=allocator_may_return_null=1 %run %t malloc 2>&1 +// RUN: %env_hwasan_opts=allocator_may_return_null=0 not %run %t malloc max 2>&1 | FileCheck %s --check-prefix=CHECK-max +// RUN: %env_hwasan_opts=allocator_may_return_null=1 %run %t malloc max 2>&1 +// RUN: %env_hwasan_opts=allocator_may_return_null=0 not %run %t calloc 2>&1 | FileCheck %s --check-prefix=CHECK-calloc +// RUN: %env_hwasan_opts=allocator_may_return_null=1 %run %t calloc 2>&1 +// RUN: %env_hwasan_opts=allocator_may_return_null=0 not %run %t new 2>&1 | FileCheck %s --check-prefix=CHECK-max +// RUN: %env_hwasan_opts=allocator_may_return_null=1 not %run %t new 2>&1 | FileCheck %s --check-prefix=CHECK-oom +// RUN: %env_hwasan_opts=allocator_may_return_null=0 not %run %t new max 2>&1 | FileCheck %s --check-prefix=CHECK-max +// RUN: %env_hwasan_opts=allocator_may_return_null=1 not %run %t new max 2>&1 | FileCheck %s --check-prefix=CHECK-oom +// RUN: %env_hwasan_opts=allocator_may_return_null=0 not %run %t new-nothrow 2>&1 | FileCheck %s --check-prefix=CHECK-max +// RUN: %env_hwasan_opts=allocator_may_return_null=1 %run %t new-nothrow 2>&1 +// RUN: %env_hwasan_opts=allocator_may_return_null=0 not %run %t new-nothrow max 2>&1 | FileCheck %s --check-prefix=CHECK-max +// RUN: %env_hwasan_opts=allocator_may_return_null=1 %run %t new-nothrow max 2>&1 +// RUN: %run %t usable 2>&1 + +// Tests for various edge cases related to sizes, notably the maximum size the +// allocator can allocate. Tests that an integer overflow in the parameters of +// calloc is caught. + +#include <assert.h> +#include <malloc.h> +#include <stdlib.h> +#include <string.h> + +#include <limits> +#include <new> + +#include <sanitizer/allocator_interface.h> + +int main(int argc, char **argv) { + assert(argc <= 3); + bool test_size_max = argc == 3 && !strcmp(argv[2], "max"); + + static const size_t kMaxAllowedMallocSize = 1ULL << 40; + static const size_t kChunkHeaderSize = 16; + + size_t MallocSize = test_size_max ? std::numeric_limits<size_t>::max() + : kMaxAllowedMallocSize; + + if (!strcmp(argv[1], "malloc")) { + void *p = malloc(MallocSize); + assert(!p); + p = malloc(kMaxAllowedMallocSize - kChunkHeaderSize); + assert(!p); + } else if (!strcmp(argv[1], "calloc")) { + // Trigger an overflow in calloc. + size_t size = std::numeric_limits<size_t>::max(); + void *p = calloc((size / 0x1000) + 1, 0x1000); + assert(!p); + } else if (!strcmp(argv[1], "new")) { + void *p = operator new(MallocSize); + assert(!p); + } else if (!strcmp(argv[1], "new-nothrow")) { + void *p = operator new(MallocSize, std::nothrow); + assert(!p); + } else if (!strcmp(argv[1], "usable")) { + // Playing with the actual usable size of a chunk. + void *p = malloc(1007); + assert(p); + size_t size = __sanitizer_get_allocated_size(p); + assert(size >= 1007); + memset(p, 'A', size); + p = realloc(p, 2014); + assert(p); + size = __sanitizer_get_allocated_size(p); + assert(size >= 2014); + memset(p, 'B', size); + free(p); + } else { + assert(0); + } + + return 0; +} + +// CHECK-max: {{ERROR: HWAddressSanitizer: requested allocation size .* exceeds maximum supported size}} +// CHECK-oom: ERROR: HWAddressSanitizer: allocator is out of memory +// CHECK-calloc: ERROR: HWAddressSanitizer: calloc parameters overflow diff --git a/test/hwasan/TestCases/stack-history-length.c b/test/hwasan/TestCases/stack-history-length.c new file mode 100644 index 000000000000..0aefd40bebb1 --- /dev/null +++ b/test/hwasan/TestCases/stack-history-length.c @@ -0,0 +1,36 @@ +// RUN: %clang_hwasan -O1 %s -o %t +// RUN: %env_hwasan_opts=stack_history_size=2048 not %run %t 2046 2>&1 | FileCheck %s --check-prefix=YES +// RUN: %env_hwasan_opts=stack_history_size=2048 not %run %t 2047 2>&1 | FileCheck %s --check-prefix=NO + +// REQUIRES: stable-runtime + +#include <stdlib.h> + +void USE(void *x) { // pretend_to_do_something(void *x) + __asm__ __volatile__("" : : "r" (x) : "memory"); +} + +volatile int four = 4; +__attribute__((noinline)) void FUNC0() { int x[4]; USE(&x[0]); } +__attribute__((noinline)) void FUNC() { int x[4]; USE(&x[0]); } +__attribute__((noinline)) void OOB() { int x[4]; x[four] = 0; USE(&x[0]); } + +int main(int argc, char **argv) { + int X = argc == 2 ? atoi(argv[1]) : 10; + // FUNC0 is X+2's element of the ring buffer. + // If runtime buffer size is less than it, FUNC0 record will be lost. + FUNC0(); + for (int i = 0; i < X; ++i) + FUNC(); + OOB(); +} + +// YES: Previously allocated frames +// YES: OOB +// YES: FUNC +// YES: FUNC0 + +// NO: Previously allocated frames +// NO: OOB +// NO: FUNC +// NO-NOT: FUNC0 diff --git a/test/hwasan/TestCases/stack-oob.c b/test/hwasan/TestCases/stack-oob.c new file mode 100644 index 000000000000..567af334e4bc --- /dev/null +++ b/test/hwasan/TestCases/stack-oob.c @@ -0,0 +1,25 @@ +// RUN: %clang_hwasan -DSIZE=16 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang_hwasan -DSIZE=64 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang_hwasan -DSIZE=0x1000 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s + +// REQUIRES: stable-runtime + +#include <stdlib.h> +#include <sanitizer/hwasan_interface.h> + +__attribute__((noinline)) +int f() { + char z[SIZE]; + char *volatile p = z; + return p[SIZE]; +} + +int main() { + return f(); + // CHECK: READ of size 1 at + // CHECK: #0 {{.*}} in f{{.*}}stack-oob.c:14 + + // CHECK: is located in stack of threa + + // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in f +} diff --git a/test/hwasan/TestCases/stack-oob.cc b/test/hwasan/TestCases/stack-oob.cc deleted file mode 100644 index 60b9a6295005..000000000000 --- a/test/hwasan/TestCases/stack-oob.cc +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: %clangxx_hwasan -DSIZE=16 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s -// RUN: %clangxx_hwasan -DSIZE=64 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s -// RUN: %clangxx_hwasan -DSIZE=0x1000 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s - -// REQUIRES: stable-runtime - -#include <stdlib.h> -#include <sanitizer/hwasan_interface.h> - -__attribute__((noinline)) -int f() { - char z[SIZE]; - char *volatile p = z; - return p[SIZE]; -} - -int main() { - return f(); - // CHECK: READ of size 1 at - // CHECK: #0 {{.*}} in f{{.*}}stack-oob.cc:14 - - // CHECK: HWAddressSanitizer can not describe address in more detail. - - // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in f -} diff --git a/test/hwasan/TestCases/stack-uar.c b/test/hwasan/TestCases/stack-uar.c new file mode 100644 index 000000000000..863a84017ee9 --- /dev/null +++ b/test/hwasan/TestCases/stack-uar.c @@ -0,0 +1,41 @@ +// Tests use-after-return detection and reporting. +// RUN: %clang_hwasan -O0 -fno-discard-value-names %s -o %t && not %run %t 2>&1 | FileCheck %s + +// REQUIRES: stable-runtime + +void USE(void *x) { // pretend_to_do_something(void *x) + __asm__ __volatile__("" : : "r" (x) : "memory"); +} + +__attribute__((noinline)) +char *buggy() { + char zzz[0x1000]; + char *volatile p = zzz; + return p; +} + +__attribute__((noinline)) void Unrelated1() { int A[2]; USE(&A[0]); } +__attribute__((noinline)) void Unrelated2() { int BB[3]; USE(&BB[0]); } +__attribute__((noinline)) void Unrelated3() { int CCC[4]; USE(&CCC[0]); } + +int main() { + char *p = buggy(); + Unrelated1(); + Unrelated2(); + Unrelated3(); + return *p; + // CHECK: READ of size 1 at + // CHECK: #0 {{.*}} in main{{.*}}stack-uar.c:[[@LINE-2]] + // CHECK: is located in stack of thread + // CHECK: Previously allocated frames: + // CHECK: Unrelated3 + // CHECK: 16 CCC + // CHECK: Unrelated2 + // CHECK: 12 BB + // CHECK: Unrelated1 + // CHECK: 8 A + // CHECK: buggy + // CHECK: 4096 zzz + + // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main +} diff --git a/test/hwasan/TestCases/stack-uar.cc b/test/hwasan/TestCases/stack-uar.cc deleted file mode 100644 index e99dcceed533..000000000000 --- a/test/hwasan/TestCases/stack-uar.cc +++ /dev/null @@ -1,23 +0,0 @@ -// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s - -// REQUIRES: stable-runtime - -#include <stdlib.h> -#include <sanitizer/hwasan_interface.h> - -__attribute__((noinline)) -char *f() { - char z[0x1000]; - char *volatile p = z; - return p; -} - -int main() { - return *f(); - // CHECK: READ of size 1 at - // CHECK: #0 {{.*}} in main{{.*}}stack-uar.cc:16 - - // CHECK: HWAddressSanitizer can not describe address in more detail. - - // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main -} diff --git a/test/hwasan/TestCases/tail-magic.c b/test/hwasan/TestCases/tail-magic.c new file mode 100644 index 000000000000..95c5ada08a36 --- /dev/null +++ b/test/hwasan/TestCases/tail-magic.c @@ -0,0 +1,28 @@ +// Tests free_checks_tail_magic=1. +// RUN: %clang_hwasan %s -o %t +// RUN: %env_hwasan_opts=free_checks_tail_magic=0 %run %t +// RUN: %env_hwasan_opts=free_checks_tail_magic=1 not %run %t 2>&1 | FileCheck %s +// RUN: not %run %t 2>&1 | FileCheck %s + +// REQUIRES: stable-runtime + +#include <stdlib.h> +#include <stdio.h> +#include <sanitizer/hwasan_interface.h> + +static volatile void *sink; + +int main(int argc, char **argv) { + __hwasan_enable_allocator_tagging(); + + char *p = (char*)malloc(20); + sink = p; + p[20] = 0x42; + p[24] = 0x66; + free(p); +// CHECK: ERROR: HWAddressSanitizer: alocation-tail-overwritten; heap object [{{.*}}) of size 20 +// CHECK: in main {{.*}}tail-magic.c:[[@LINE-2]] +// CHECK: allocated here: +// CHECK: in main {{.*}}tail-magic.c:[[@LINE-8]] +// CHECK: Tail contains: .. .. .. .. 42 {{.. .. ..}} 66 +} diff --git a/test/hwasan/TestCases/thread-uaf.c b/test/hwasan/TestCases/thread-uaf.c new file mode 100644 index 000000000000..f091167e3ced --- /dev/null +++ b/test/hwasan/TestCases/thread-uaf.c @@ -0,0 +1,58 @@ +// Tests UAF detection where Allocate/Deallocate/Use +// happen in separate threads. +// RUN: %clang_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s +// REQUIRES: stable-runtime + +#include <pthread.h> +#include <stdlib.h> +#include <stdio.h> + +#include <sanitizer/hwasan_interface.h> + +char *volatile x; +int state; + +void *Allocate(void *arg) { + x = (char*)malloc(10); + __sync_fetch_and_add(&state, 1); + while (__sync_fetch_and_add(&state, 0) != 3) {} + return NULL; +} +void *Deallocate(void *arg) { + free(x); + __sync_fetch_and_add(&state, 1); + while (__sync_fetch_and_add(&state, 0) != 3) {} + return NULL; +} + +void *Use(void *arg) { + x[5] = 42; + // CHECK: ERROR: HWAddressSanitizer: tag-mismatch on address + // CHECK: WRITE of size 1 {{.*}} in thread T3 + // CHECK: thread-uaf.c:[[@LINE-3]] + // CHECK: freed by thread T2 here + // CHECK: in Deallocate + // CHECK: previously allocated here: + // CHECK: in Allocate + // CHECK: Thread: T2 0x + // CHECK: Thread: T3 0x + // CHECK-DAG: Thread: T0 0x + // CHECK-DAG: Thread: T1 0x + __sync_fetch_and_add(&state, 1); + return NULL; +} + +int main() { + __hwasan_enable_allocator_tagging(); + pthread_t t1, t2, t3; + + pthread_create(&t1, NULL, Allocate, NULL); + while (__sync_fetch_and_add(&state, 0) != 1) {} + pthread_create(&t2, NULL, Deallocate, NULL); + while (__sync_fetch_and_add(&state, 0) != 2) {} + pthread_create(&t3, NULL, Use, NULL); + + pthread_join(t1, NULL); + pthread_join(t2, NULL); + pthread_join(t3, NULL); +} diff --git a/test/hwasan/TestCases/uaf_with_rb_distance.c b/test/hwasan/TestCases/uaf_with_rb_distance.c new file mode 100644 index 000000000000..25aae5256c41 --- /dev/null +++ b/test/hwasan/TestCases/uaf_with_rb_distance.c @@ -0,0 +1,27 @@ +// Checks how we print the developer note "hwasan_dev_note_heap_rb_distance". +// RUN: %clang_hwasan %s -o %t +// RUN: not %run %t 10 2>&1 | FileCheck %s --check-prefix=D10 +// RUN: not %run %t 42 2>&1 | FileCheck %s --check-prefix=D42 + +// REQUIRES: stable-runtime + +#include <stdlib.h> +#include <stdio.h> +#include <sanitizer/hwasan_interface.h> + + +void *p[100]; + +int main(int argc, char **argv) { + __hwasan_enable_allocator_tagging(); + int distance = argc >= 2 ? atoi(argv[1]) : 1; + for (int i = 0; i < 100; i++) + p[i] = malloc(i); + for (int i = 0; i < 100; i++) + free(p[i]); + + *(int*)p[distance] = 0; +} + +// D10: hwasan_dev_note_heap_rb_distance: 90 1023 +// D42: hwasan_dev_note_heap_rb_distance: 58 1023 diff --git a/test/hwasan/TestCases/use-after-free.c b/test/hwasan/TestCases/use-after-free.c index b9f6060112c1..03a1771c1b8f 100644 --- a/test/hwasan/TestCases/use-after-free.c +++ b/test/hwasan/TestCases/use-after-free.c @@ -1,13 +1,14 @@ -// RUN: %clang_hwasan -O0 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD -// RUN: %clang_hwasan -O1 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD -// RUN: %clang_hwasan -O2 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD -// RUN: %clang_hwasan -O3 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD +// RUN: %clang_hwasan -O0 -DISREAD=1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK +// RUN: %clang_hwasan -O1 -DISREAD=1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK +// RUN: %clang_hwasan -O2 -DISREAD=1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK +// RUN: %clang_hwasan -O3 -DISREAD=1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK -// RUN: %clang_hwasan -O0 -DSTORE %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,STORE +// RUN: %clang_hwasan -O0 -DISREAD=0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK // REQUIRES: stable-runtime #include <stdlib.h> +#include <stdio.h> #include <sanitizer/hwasan_interface.h> int main() { @@ -15,25 +16,25 @@ int main() { char * volatile x = (char*)malloc(10); free(x); __hwasan_disable_allocator_tagging(); -#ifdef STORE - x[5] = 42; -#endif -#ifdef LOAD - return x[5]; -#endif - // LOAD: READ of size 1 at - // LOAD: #0 {{.*}} in main {{.*}}use-after-free.c:22 - - // STORE: WRITE of size 1 at - // STORE: #0 {{.*}} in main {{.*}}use-after-free.c:19 - - // CHECK: freed here: + fprintf(stderr, "Going to do a %s\n", ISREAD ? "READ" : "WRITE"); + // CHECK: Going to do a [[TYPE:[A-Z]*]] + int r = 0; + if (ISREAD) r = x[5]; else x[5] = 42; // should be on the same line. + // CHECK: [[TYPE]] of size 1 at {{.*}} tags: [[PTR_TAG:[0-9a-f][0-9a-f]]]/[[MEM_TAG:[0-9a-f][0-9a-f]]] (ptr/mem) + // CHECK: #0 {{.*}} in main {{.*}}use-after-free.c:[[@LINE-2]] + // Offset is 5 or 11 depending on left/right alignment. + // CHECK: is a small unallocated heap chunk; size: 32 offset: {{5|11}} + // CHECK: is located 5 bytes inside of 10-byte region + // + // CHECK: freed by thread {{.*}} here: // CHECK: #0 {{.*}} in {{.*}}free{{.*}} {{.*}}hwasan_interceptors.cc - // CHECK: #1 {{.*}} in main {{.*}}use-after-free.c:16 + // CHECK: #1 {{.*}} in main {{.*}}use-after-free.c:[[@LINE-14]] // CHECK: previously allocated here: // CHECK: #0 {{.*}} in {{.*}}malloc{{.*}} {{.*}}hwasan_interceptors.cc - // CHECK: #1 {{.*}} in main {{.*}}use-after-free.c:15 - + // CHECK: #1 {{.*}} in main {{.*}}use-after-free.c:[[@LINE-19]] + // CHECK: Memory tags around the buggy address (one tag corresponds to 16 bytes): + // CHECK: =>{{.*}}[[MEM_TAG]] // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main + return r; } diff --git a/test/hwasan/lit.cfg b/test/hwasan/lit.cfg index 3ebba51d05e4..66008a632bcf 100644 --- a/test/hwasan/lit.cfg +++ b/test/hwasan/lit.cfg @@ -9,14 +9,18 @@ config.name = 'HWAddressSanitizer' + getattr(config, 'name_suffix', 'default') config.test_source_root = os.path.dirname(__file__) # Setup default compiler flags used with -fsanitize=memory option. -clang_hwasan_cflags = ["-fsanitize=hwaddress", "-mllvm", "-hwasan-generate-tags-with-calls", config.target_cflags] + config.debug_info_flags +clang_cflags = [config.target_cflags] + config.debug_info_flags +clang_cxxflags = config.cxx_mode_flags + clang_cflags +clang_hwasan_cflags = ["-fsanitize=hwaddress", "-mllvm", "-hwasan-generate-tags-with-calls"] + clang_cflags clang_hwasan_cxxflags = config.cxx_mode_flags + clang_hwasan_cflags def build_invocation(compile_flags): return " " + " ".join([config.clang] + compile_flags) + " " +config.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) ) config.substitutions.append( ("%clang_hwasan ", build_invocation(clang_hwasan_cflags)) ) config.substitutions.append( ("%clangxx_hwasan ", build_invocation(clang_hwasan_cxxflags)) ) +config.substitutions.append( ("%compiler_rt_libdir", config.compiler_rt_libdir) ) default_hwasan_opts_str = ':'.join(['disable_allocator_tagging=1', 'random_tags=0'] + config.default_sanitizer_opts) if default_hwasan_opts_str: diff --git a/test/hwasan/lit.site.cfg.in b/test/hwasan/lit.site.cfg.in index 7453d1b74dc0..e95ea92cd2d9 100644 --- a/test/hwasan/lit.site.cfg.in +++ b/test/hwasan/lit.site.cfg.in @@ -4,6 +4,7 @@ config.name_suffix = "@HWASAN_TEST_CONFIG_SUFFIX@" config.target_cflags = "@HWASAN_TEST_TARGET_CFLAGS@" config.target_arch = "@HWASAN_TEST_TARGET_ARCH@" +config.android_files_to_push = @HWASAN_ANDROID_FILES_TO_PUSH@ # Load common config for all compiler-rt lit tests. lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") diff --git a/test/lit.common.cfg b/test/lit.common.cfg index 5274b49c654f..f06658ff2d27 100644 --- a/test/lit.common.cfg +++ b/test/lit.common.cfg @@ -55,10 +55,12 @@ config.available_features.add(compiler_id) if config.asan_shadow_scale != '': config.target_cflags += " -mllvm -asan-mapping-scale=" + config.asan_shadow_scale -# BFD linker in 64-bit android toolchains fails to find libm.so, which is a -# transitive shared library dependency (via asan runtime). +# BFD linker in 64-bit android toolchains fails to find libc++_shared.so, which +# is a transitive shared library dependency (via asan runtime). if config.android: - config.target_cflags += " -pie -fuse-ld=gold -Wl,--enable-new-dtags" + # Prepend the flag so that it can be overridden. + config.target_cflags = "-pie -fuse-ld=gold " + config.target_cflags + config.cxx_mode_flags.append('-stdlib=libstdc++') # Clear some environment variables that might affect Clang. possibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS', @@ -106,6 +108,10 @@ config.substitutions.append( if config.emulator: config.substitutions.append( ('%run', config.emulator) ) config.substitutions.append( ('%env ', "env ") ) + # TODO: Implement `%device_rm` to perform removal of files in the emulator. + # For now just make it a no-op. + lit_config.warning('%device_rm is not implemented') + config.substitutions.append( ('%device_rm', 'echo ') ) config.compile_wrapper = "" elif config.host_os == 'Darwin' and config.apple_platform != "osx": # Darwin tests can be targetting macOS, a device or a simulator. All devices @@ -127,14 +133,18 @@ elif config.host_os == 'Darwin' and config.apple_platform != "osx": ios_or_iossim = "iossim" if config.apple_platform.endswith("sim") else "ios" config.available_features.add('ios') + device_id_env = "SANITIZER_" + ios_or_iossim.upper() + "_TEST_DEVICE_IDENTIFIER" if ios_or_iossim == "iossim": config.available_features.add('iossim') + if device_id_env not in os.environ: + lit_config.fatal( + '{} must be set in the environment when running iossim tests'.format( + device_id_env)) if config.apple_platform != "ios" and config.apple_platform != "iossim": config.available_features.add(config.apple_platform) ios_commands_dir = os.path.join(config.compiler_rt_src_root, "test", "sanitizer_common", "ios_commands") - device_id_env = "SANITIZER_" + ios_or_iossim.upper() + "_TEST_DEVICE_IDENTIFIER" run_wrapper = os.path.join(ios_commands_dir, ios_or_iossim + "_run.py") env_wrapper = os.path.join(ios_commands_dir, ios_or_iossim + "_env.py") compile_wrapper = os.path.join(ios_commands_dir, ios_or_iossim + "_compile.py") @@ -144,9 +154,17 @@ elif config.host_os == 'Darwin' and config.apple_platform != "osx": config.environment[device_id_env] = os.environ[device_id_env] config.substitutions.append(('%run', run_wrapper)) config.substitutions.append(('%env ', env_wrapper + " ")) + # Current implementation of %device_rm uses the run_wrapper to do + # the work. + config.substitutions.append(('%device_rm', '{} rm '.format(run_wrapper))) config.compile_wrapper = compile_wrapper - prepare_output = subprocess.check_output([prepare_script, config.apple_platform, config.clang]).strip() + try: + prepare_output = subprocess.check_output([prepare_script, config.apple_platform, config.clang]).strip() + except subprocess.CalledProcessError as e: + print("Command failed:") + print(e.output) + raise e if len(prepare_output) > 0: print(prepare_output) prepare_output_json = prepare_output.split("\n")[-1] prepare_output = json.loads(prepare_output_json) @@ -157,9 +175,15 @@ elif config.android: config.compile_wrapper = compile_wrapper config.substitutions.append( ('%run', "") ) config.substitutions.append( ('%env ', "env ") ) + # TODO: Implement `%device_rm` to perform removal of files on a device. For + # now just make it a no-op. + lit_config.warning('%device_rm is not implemented') + config.substitutions.append( ('%device_rm', 'echo ') ) else: config.substitutions.append( ('%run', "") ) config.substitutions.append( ('%env ', "env ") ) + # When running locally %device_rm is a no-op. + config.substitutions.append( ('%device_rm', 'echo ') ) config.compile_wrapper = "" # Define CHECK-%os to check for OS-dependent output. @@ -252,9 +276,14 @@ else: config.substitutions.append( ("%darwin_min_target_with_full_runtime_arc_support", "") ) if config.android: + env = os.environ.copy() + if config.android_serial: + env['ANDROID_SERIAL'] = config.android_serial + config.environment['ANDROID_SERIAL'] = config.android_serial + adb = os.environ.get('ADB', 'adb') try: - android_api_level_str = subprocess.check_output([adb, "shell", "getprop", "ro.build.version.sdk"]).rstrip() + android_api_level_str = subprocess.check_output([adb, "shell", "getprop", "ro.build.version.sdk"], env=env).rstrip() except (subprocess.CalledProcessError, OSError): lit_config.fatal("Failed to read ro.build.version.sdk (using '%s' as adb)" % adb) try: @@ -263,6 +292,29 @@ if config.android: lit_config.fatal("Failed to read ro.build.version.sdk (using '%s' as adb): got '%s'" % (adb, android_api_level_str)) if android_api_level >= 26: config.available_features.add('android-26') + if android_api_level >= 28: + config.available_features.add('android-28') + + # Prepare the device. + android_tmpdir = '/data/local/tmp/Output' + subprocess.check_call([adb, "shell", "mkdir", "-p", android_tmpdir], env=env) + for file in config.android_files_to_push: + subprocess.check_call([adb, "push", file, android_tmpdir], env=env) + +if config.host_os == 'Linux': + # detect whether we are using glibc, and which version + # NB: 'ldd' is just one of the tools commonly installed as part of glibc + ldd_ver_cmd = subprocess.Popen(['ldd', '--version'], + stdout=subprocess.PIPE, + env={'LANG': 'C'}) + sout, _ = ldd_ver_cmd.communicate() + ver_line = sout.splitlines()[0] + if ver_line.startswith(b"ldd "): + from distutils.version import LooseVersion + ver = LooseVersion(ver_line.split()[-1].decode()) + # 2.27 introduced some incompatibilities + if ver >= LooseVersion("2.27"): + config.available_features.add("glibc-2.27") sancovcc_path = os.path.join(config.llvm_tools_dir, "sancov") if os.path.exists(sancovcc_path): @@ -295,7 +347,7 @@ if config.host_os == 'Darwin' and is_darwin_lto_supported(): config.lto_supported = True config.lto_launch = ["env", "DYLD_LIBRARY_PATH=" + config.llvm_shlib_dir] config.lto_flags = [] -elif config.host_os == 'Linux' and is_linux_lto_supported(): +elif config.host_os in ['Linux', 'FreeBSD', 'NetBSD'] and is_linux_lto_supported(): config.lto_supported = True config.lto_launch = [] if config.use_lld: @@ -319,6 +371,9 @@ if config.lto_supported: if config.use_newpm: config.lto_flags += ["-fexperimental-new-pass-manager"] +if config.have_rpc_xdr_h: + config.available_features.add('sunrpc') + # Ask llvm-config about assertion mode. try: llvm_config_cmd = subprocess.Popen( diff --git a/test/lit.common.configured.in b/test/lit.common.configured.in index 63d55bfdea81..4994ca69b18e 100644 --- a/test/lit.common.configured.in +++ b/test/lit.common.configured.in @@ -36,6 +36,9 @@ set_default("use_thinlto", False) set_default("use_lto", config.use_thinlto) set_default("use_newpm", False) set_default("android", @ANDROID_PYBOOL@) +set_default("android_serial", "@ANDROID_SERIAL_FOR_TESTING@") +set_default("android_files_to_push", []) +set_default("have_rpc_xdr_h", @HAVE_RPC_XDR_H@) config.available_features.add('target-is-%s' % config.target_arch) if config.enable_per_target_runtime_dir: diff --git a/test/lsan/TestCases/Linux/fork_and_leak.cc b/test/lsan/TestCases/Linux/fork_and_leak.cc new file mode 100644 index 000000000000..d7427ce3ed04 --- /dev/null +++ b/test/lsan/TestCases/Linux/fork_and_leak.cc @@ -0,0 +1,23 @@ +// Test that leaks detected after forking without exec(). +// RUN: %clangxx_lsan %s -o %t && not %run %t 2>&1 | FileCheck %s + +#include <assert.h> +#include <stdlib.h> +#include <sys/wait.h> +#include <unistd.h> + +int main() { + pid_t pid = fork(); + assert(pid >= 0); + if (pid > 0) { + int status = 0; + waitpid(pid, &status, 0); + assert(WIFEXITED(status)); + return WEXITSTATUS(status); + } else { + malloc(1337); + // CHECK: LeakSanitizer: detected memory leaks + } + return 0; +} + diff --git a/test/lsan/TestCases/Linux/fork_with_threads.cc b/test/lsan/TestCases/Linux/fork_with_threads.cc deleted file mode 100644 index 221c5d249d77..000000000000 --- a/test/lsan/TestCases/Linux/fork_with_threads.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Test forked process does not run lsan. -// RUN: %clangxx_lsan %s -o %t && %run %t 2>&1 | FileCheck %s - -#include <pthread.h> -#include <stdlib.h> -#include <sys/wait.h> -#include <unistd.h> - -static pthread_barrier_t barrier; - -// CHECK-NOT: SUMMARY: {{(Leak|Address)}}Sanitizer: -static void *thread_func(void *arg) { - void *buffer = malloc(1337); - pthread_barrier_wait(&barrier); - for (;;) - pthread_yield(); - return 0; -} - -int main() { - pthread_barrier_init(&barrier, 0, 2); - pthread_t tid; - int res = pthread_create(&tid, 0, thread_func, 0); - pthread_barrier_wait(&barrier); - pthread_barrier_destroy(&barrier); - - pid_t pid = fork(); - if (pid > 0) { - int status = 0; - waitpid(pid, &status, 0); - } - return 0; -} - -// CHECK: WARNING: LeakSanitizer is disabled in forked process diff --git a/test/lsan/TestCases/Linux/use_tls_dynamic.cc b/test/lsan/TestCases/Linux/use_tls_dynamic.cc index 4d70a46f8183..8093d6f0e68f 100644 --- a/test/lsan/TestCases/Linux/use_tls_dynamic.cc +++ b/test/lsan/TestCases/Linux/use_tls_dynamic.cc @@ -1,4 +1,9 @@ // Test that dynamically allocated TLS space is included in the root set. + +// This is known to be broken with glibc-2.27+ +// https://bugs.llvm.org/show_bug.cgi?id=37804 +// XFAIL: glibc-2.27 + // RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0:use_ld_allocations=0" // RUN: %clangxx %s -DBUILD_DSO -fPIC -shared -o %t-so.so // RUN: %clangxx_lsan %s -o %t diff --git a/test/msan/Linux/reexec_unlimited_stack.cc b/test/msan/Linux/reexec_unlimited_stack.cc new file mode 100644 index 000000000000..61492ec34533 --- /dev/null +++ b/test/msan/Linux/reexec_unlimited_stack.cc @@ -0,0 +1,23 @@ +// MSAN re-execs on unlimited stacks. We use that to verify ReExec() uses the +// right path. +// RUN: %clangxx_msan -O0 %s -o %t && ulimit -s unlimited && %run %t | FileCheck %s + +#include <stdio.h> + +#if !defined(__GLIBC_PREREQ) +#define __GLIBC_PREREQ(a, b) 0 +#endif + +#if __GLIBC_PREREQ(2, 16) +#include <sys/auxv.h> +#endif + +int main() { +#if __GLIBC_PREREQ(2, 16) + // Make sure AT_EXECFN didn't get overwritten by re-exec. + puts(reinterpret_cast<const char *>(getauxval(AT_EXECFN))); +#else + puts("No getauxval"); +#endif + // CHECK-NOT: /proc/self/exe +} diff --git a/test/msan/Linux/sunrpc.cc b/test/msan/Linux/sunrpc.cc index c92ad632c095..edf49c2a5cee 100644 --- a/test/msan/Linux/sunrpc.cc +++ b/test/msan/Linux/sunrpc.cc @@ -1,3 +1,5 @@ +// REQUIRES: sunrpc + // RUN: %clangxx_msan -g -O0 -DTYPE=int -DFN=xdr_int %s -o %t && \ // RUN: %run %t 2>&1 // RUN: %clangxx_msan -g -O0 -DTYPE=int -DFN=xdr_int -DUNINIT=1 %s -o %t && \ diff --git a/test/msan/Linux/sunrpc_bytes.cc b/test/msan/Linux/sunrpc_bytes.cc index 477637af2b63..7eb47e178492 100644 --- a/test/msan/Linux/sunrpc_bytes.cc +++ b/test/msan/Linux/sunrpc_bytes.cc @@ -1,3 +1,5 @@ +// REQUIRES: sunrpc + // RUN: %clangxx_msan -g -O0 %s -o %t && \ // RUN: %run %t 2>&1 // RUN: %clangxx_msan -g -O0 -DUNINIT=1 %s -o %t && \ diff --git a/test/msan/Linux/sunrpc_string.cc b/test/msan/Linux/sunrpc_string.cc index 350222f5cc1e..723b85592261 100644 --- a/test/msan/Linux/sunrpc_string.cc +++ b/test/msan/Linux/sunrpc_string.cc @@ -1,3 +1,5 @@ +// REQUIRES: sunrpc + // RUN: %clangxx_msan -g -O0 %s -o %t && \ // RUN: %run %t 2>&1 // RUN: %clangxx_msan -g -O0 -DUNINIT=1 %s -o %t && \ diff --git a/test/msan/chained_origin_with_signals.cc b/test/msan/chained_origin_with_signals.cc index 43dbdcca76a9..9c071569a2ba 100644 --- a/test/msan/chained_origin_with_signals.cc +++ b/test/msan/chained_origin_with_signals.cc @@ -10,6 +10,9 @@ // RUN: not %run %t >%t.out 2>&1 // RUN: FileCheck %s < %t.out +// Reported deadly signal due to stack-overflow +// XFAIL: netbsd + #include <signal.h> #include <stdio.h> #include <sys/types.h> diff --git a/test/msan/dtls_test.c b/test/msan/dtls_test.c index b9021e0da1af..bc1fe609a850 100644 --- a/test/msan/dtls_test.c +++ b/test/msan/dtls_test.c @@ -8,6 +8,14 @@ XFAIL: FreeBSD UNSUPPORTED: powerpc + + // Reports use-of-uninitialized-value, not analyzed + XFAIL: netbsd + + // This is known to be broken with glibc-2.27+ + // https://bugs.llvm.org/show_bug.cgi?id=37804 + XFAIL: glibc-2.27 + */ #ifndef BUILD_SO diff --git a/test/msan/fork.cc b/test/msan/fork.cc index e4dc5490887c..87d71f87efe6 100644 --- a/test/msan/fork.cc +++ b/test/msan/fork.cc @@ -14,6 +14,9 @@ // UNSUPPORTED: powerpc64-target-arch // UNSUPPORTED: powerpc64le-target-arch +// Sometimes hangs +// UNSUPPORTED: netbsd + #include <pthread.h> #include <unistd.h> #include <stdio.h> diff --git a/test/msan/ioctl_custom.cc b/test/msan/ioctl_custom.cc index eaab63384582..794f34535358 100644 --- a/test/msan/ioctl_custom.cc +++ b/test/msan/ioctl_custom.cc @@ -4,6 +4,9 @@ // RUN: %clangxx_msan -DPOSITIVE -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s // RUN: %clangxx_msan -DPOSITIVE -O3 -g %s -o %t && not %run %t 2>&1 | FileCheck %s +// Reports different report (not analyzed) +// XFAIL: netbsd + #include <assert.h> #include <stdlib.h> #include <net/if.h> diff --git a/test/msan/lit.cfg b/test/msan/lit.cfg index 550d04d0812b..e08673d5cfea 100644 --- a/test/msan/lit.cfg +++ b/test/msan/lit.cfg @@ -17,14 +17,20 @@ clang_msan_cflags = (["-fsanitize=memory", config.debug_info_flags) # Some Msan tests leverage backtrace() which requires libexecinfo on FreeBSD. if config.host_os == 'FreeBSD': - clang_msan_cflags += ["-lexecinfo"] + clang_msan_cflags += ["-lexecinfo", "-fPIC"] clang_msan_cxxflags = config.cxx_mode_flags + clang_msan_cflags +# Flags for KMSAN invocation. This is C-only, we're not interested in C++. +clang_kmsan_cflags = (["-fsanitize=kernel-memory"] + + [config.target_cflags] + + config.debug_info_flags) + def build_invocation(compile_flags): return " " + " ".join([config.clang] + compile_flags) + " " config.substitutions.append( ("%clang_msan ", build_invocation(clang_msan_cflags)) ) config.substitutions.append( ("%clangxx_msan ", build_invocation(clang_msan_cxxflags)) ) +config.substitutions.append( ("%clang_kmsan ", build_invocation(clang_kmsan_cflags)) ) # Default test suffixes. config.suffixes = ['.c', '.cc', '.cpp'] diff --git a/test/msan/pthread_getname_np.cc b/test/msan/pthread_getname_np.cc index e19b652a73c9..4827b3a00643 100644 --- a/test/msan/pthread_getname_np.cc +++ b/test/msan/pthread_getname_np.cc @@ -1,7 +1,7 @@ // RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t // The main goal is getting the pthread name back and // FreeBSD based do not support this feature -// UNSUPPORTED: android, netbsd, freebsd +// UNSUPPORTED: android, freebsd // Regression test for a deadlock in pthread_getattr_np @@ -32,7 +32,11 @@ int main(void) { assert(!res); const char *kMyThreadName = "my-thread-name"; +#if defined(__NetBSD__) + res = pthread_setname_np(t, "%s", (void *)kMyThreadName); +#else res = pthread_setname_np(t, kMyThreadName); +#endif assert(!res); char buf[100]; diff --git a/test/msan/signal_stress_test.cc b/test/msan/signal_stress_test.cc index 5bc6f59213b1..dfbc580faf2c 100644 --- a/test/msan/signal_stress_test.cc +++ b/test/msan/signal_stress_test.cc @@ -2,6 +2,9 @@ // // Test that va_arg shadow from a signal handler does not leak outside. +// Reported deadly signal due to stack-overflow +// XFAIL: netbsd + #include <signal.h> #include <stdarg.h> #include <sanitizer/msan_interface.h> diff --git a/test/msan/strndup.cc b/test/msan/strndup.cc index d4b9af1a9a6e..07bdd9f8f5fb 100644 --- a/test/msan/strndup.cc +++ b/test/msan/strndup.cc @@ -4,7 +4,7 @@ // When built as C on Linux, strndup is transformed to __strndup. // RUN: %clangxx_msan -O3 -xc %s -o %t && not %run %t 2>&1 | FileCheck --check-prefix=ON %s -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc #include <assert.h> #include <stdlib.h> diff --git a/test/msan/tls_reuse.cc b/test/msan/tls_reuse.cc index 9c2ee975cb57..78a328fa3ce0 100644 --- a/test/msan/tls_reuse.cc +++ b/test/msan/tls_reuse.cc @@ -1,7 +1,6 @@ // RUN: %clangxx_msan -O0 %s -o %t && %run %t // Check that when TLS block is reused between threads, its shadow is cleaned. -// XFAIL: freebsd #include <pthread.h> #include <stdio.h> diff --git a/test/msan/vararg.cc b/test/msan/vararg.cc new file mode 100644 index 000000000000..e1a7b1266165 --- /dev/null +++ b/test/msan/vararg.cc @@ -0,0 +1,60 @@ +// RUN: %clangxx_msan -fsanitize-memory-track-origins=0 -O3 %s -o %t && \ +// RUN: not %run %t va_arg_tls >%t.out 2>&1 +// RUN: FileCheck %s --check-prefix=CHECK < %t.out + +// RUN: %clangxx_msan -fsanitize-memory-track-origins=0 -O3 %s -o %t && \ +// RUN: not %run %t overflow >%t.out 2>&1 +// RUN: FileCheck %s --check-prefix=CHECK < %t.out + +// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O3 %s -o %t && \ +// RUN: not %run %t va_arg_tls >%t.out 2>&1 +// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN < %t.out + +// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O3 %s -o %t && \ +// RUN: not %run %t overflow >%t.out 2>&1 +// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN < %t.out + +// Check that shadow and origin are passed through va_args. + +// Copying origins on AArch64, MIPS and PowerPC isn't supported yet. +// XFAIL: aarch64 +// XFAIL: mips +// XFAIL: powerpc64 + +#include <stdarg.h> +#include <string.h> + +__attribute__((noinline)) +int sum(int n, ...) { + va_list args; + int i, sum = 0, arg; + volatile int temp; + va_start(args, n); + for (i = 0; i < n; i++) { + arg = va_arg(args, int); + sum += arg; + } + va_end(args); + return sum; +} + +int main(int argc, char *argv[]) { + volatile int uninit; + volatile int a = 1, b = 2; + if (argc == 2) { + // Shadow/origin will be passed via va_arg_tls/va_arg_origin_tls. + if (strcmp(argv[1], "va_arg_tls") == 0) { + return sum(3, uninit, a, b); + } + // Shadow/origin of |uninit| will be passed via overflow area. + if (strcmp(argv[1], "overflow") == 0) { + return sum(7, + a, a, a, a, a, a, uninit + ); + } + } + return 0; +} + +// CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value +// CHECK-ORIGIN: Uninitialized value was created by an allocation of 'uninit' in the stack frame of function 'main' diff --git a/test/profile/Inputs/instrprof-dlopen-dlclose-main.c.gcov b/test/profile/Inputs/instrprof-dlopen-dlclose-main.c.gcov index acb2076fd763..2d538f63eb46 100644 --- a/test/profile/Inputs/instrprof-dlopen-dlclose-main.c.gcov +++ b/test/profile/Inputs/instrprof-dlopen-dlclose-main.c.gcov @@ -7,7 +7,7 @@ // CHECK-NEXT: -: 2:#include <stdio.h> // CHECK-NEXT: -: 3:#include <stdlib.h> // CHECK-NEXT: -: 4: -// CHECK-NEXT: -: 5:int main(int argc, char *argv[]) { +// CHECK-NEXT: 1: 5:int main(int argc, char *argv[]) { // CHECK-NEXT: 1: 6: dlerror(); // CHECK-NEXT: 1: 7: void *f1_handle = dlopen("func.shared", RTLD_LAZY | RTLD_GLOBAL); // CHECK-NEXT: 1: 8: if (f1_handle == NULL) { diff --git a/test/profile/Inputs/instrprof-dlopen-dlclose-main_three-libs.c.gcov b/test/profile/Inputs/instrprof-dlopen-dlclose-main_three-libs.c.gcov index 97eef4c3b905..f1dd1757144f 100644 --- a/test/profile/Inputs/instrprof-dlopen-dlclose-main_three-libs.c.gcov +++ b/test/profile/Inputs/instrprof-dlopen-dlclose-main_three-libs.c.gcov @@ -7,7 +7,7 @@ // CHECK-NEXT: -: 2:#include <stdio.h> // CHECK-NEXT: -: 3:#include <stdlib.h> // CHECK-NEXT: -: 4: -// CHECK-NEXT: -: 5:int main(int argc, char *argv[]) { +// CHECK-NEXT: 1: 5:int main(int argc, char *argv[]) { // CHECK-NEXT: 1: 6: dlerror(); // CHECK-NEXT: 1: 7: void *f1_handle = dlopen("func.shared", RTLD_LAZY | RTLD_GLOBAL); // CHECK-NEXT: 1: 8: if (f1_handle == NULL) { diff --git a/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c b/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c new file mode 100644 index 000000000000..dadd8959991a --- /dev/null +++ b/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c @@ -0,0 +1,16 @@ +int main(void) { + __gcov_flush(); + + if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) { + return 1; + } + + __gcov_flush(); + __gcov_flush(); + + if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) { + return 1; + } + + return 0; +} diff --git a/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c.gcov b/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c.gcov new file mode 100644 index 000000000000..f2141229bd4f --- /dev/null +++ b/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c.gcov @@ -0,0 +1,21 @@ +// CHECK: -: 0:Source:{{.*}}Inputs/instrprof-gcov-__gcov_flush-multiple.c +// CHECK-NEXT: -: 0:Graph:instrprof-gcov-__gcov_flush-multiple.gcno +// CHECK-NEXT: -: 0:Data:instrprof-gcov-__gcov_flush-multiple.gcda +// CHECK-NEXT: -: 0:Runs:1 +// CHECK-NEXT: -: 0:Programs:1 +// CHECK-NEXT: #####: 1:int main(void) { +// CHECK-NEXT: #####: 2: __gcov_flush(); +// CHECK-NEXT: -: 3: +// CHECK-NEXT: #####: 4: if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) { +// CHECK-NEXT: #####: 5: return 1; +// CHECK-NEXT: -: 6: } +// CHECK-NEXT: -: 7: +// CHECK-NEXT: #####: 8: __gcov_flush(); +// CHECK-NEXT: #####: 9: __gcov_flush(); +// CHECK-NEXT: -: 10: +// CHECK-NEXT: #####: 11: if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) { +// CHECK-NEXT: #####: 12: return 1; +// CHECK-NEXT: -: 13: } +// CHECK-NEXT: -: 14: +// CHECK-NEXT: 1: 15: return 0; +// CHECK-NEXT: 1: 16:} diff --git a/test/profile/Inputs/instrprof-gcov-exceptions.cpp.gcov b/test/profile/Inputs/instrprof-gcov-exceptions.cpp.gcov index 7caf50806020..f8e38297475d 100644 --- a/test/profile/Inputs/instrprof-gcov-exceptions.cpp.gcov +++ b/test/profile/Inputs/instrprof-gcov-exceptions.cpp.gcov @@ -5,10 +5,10 @@ // CHECK-NEXT: -: 0:Programs:1 // CHECK-NEXT: -: 1:#include <string> // CHECK-NEXT: -: 2: -// CHECK-NEXT: -: 3:void asd(std::string i) { -// CHECK-NEXT: 2: 4:} +// CHECK-NEXT: 1: 3:void asd(std::string i) { +// CHECK-NEXT: 1: 4:} // CHECK-NEXT: -: 5: -// CHECK-NEXT: -: 6:int main(void) +// CHECK-NEXT: 1: 6:int main(void) // CHECK-NEXT: -: 7:{ // CHECK-NEXT: 1: 8: asd("22"); // CHECK-NEXT: -: 9: diff --git a/test/profile/Inputs/instrprof-gcov-execlp.c b/test/profile/Inputs/instrprof-gcov-execlp.c new file mode 100644 index 000000000000..5213a5b80360 --- /dev/null +++ b/test/profile/Inputs/instrprof-gcov-execlp.c @@ -0,0 +1,15 @@ +#include <unistd.h> + +void func1() {} +void func2() {} + +int main(void) +{ + func1(); + + execlp("ls", "-l", "-h", (char*)0); + + func2(); + + return 0; +} diff --git a/test/profile/Inputs/instrprof-gcov-execlp.c.gcov b/test/profile/Inputs/instrprof-gcov-execlp.c.gcov new file mode 100644 index 000000000000..7542f6ff73b2 --- /dev/null +++ b/test/profile/Inputs/instrprof-gcov-execlp.c.gcov @@ -0,0 +1,23 @@ +//CHECK: -: 0:Source:{{.*}}Inputs/instrprof-gcov-execlp.c +//CHECK-NEXT: -: 0:Graph:instrprof-gcov-execlp.gcno +//CHECK-NEXT: -: 0:Data:instrprof-gcov-execlp.gcda +//CHECK-NEXT: -: 0:Runs:1 +//CHECK-NEXT: -: 0:Programs:1 +//CHECK-NEXT: -: 1:#include <unistd.h> +//CHECK-NEXT: -: 2: +//CHECK-NEXT:function func1 called 1 returned 100% blocks executed 100% +//CHECK-NEXT: 1: 3:void func1() {} +//CHECK-NEXT:function func2 called 0 returned 0% blocks executed 0% +//CHECK-NEXT: #####: 4:void func2() {} +//CHECK-NEXT: -: 5: +//CHECK-NEXT:function main called 1 returned 0% blocks executed 33% +//CHECK-NEXT: 1: 6:int main(void) +//CHECK-NEXT: -: 7:{ +//CHECK-NEXT: 1: 8: func1(); +//CHECK-NEXT: -: 9: +//CHECK-NEXT: 1: 10: execlp("ls", "-l", "-h", (char*)0); +//CHECK-NEXT: -: 11: +//CHECK-NEXT: #####: 12: func2(); +//CHECK-NEXT: -: 13: +//CHECK-NEXT: #####: 14: return 0; +//CHECK-NEXT: -: 15:} diff --git a/test/profile/Inputs/instrprof-gcov-execvp.c b/test/profile/Inputs/instrprof-gcov-execvp.c new file mode 100644 index 000000000000..f2e411c2a42e --- /dev/null +++ b/test/profile/Inputs/instrprof-gcov-execvp.c @@ -0,0 +1,17 @@ +#include <unistd.h> + +void func1() {} +void func2() {} + +int main(void) +{ + char *const args[] = {"-l", "-h", (char*)0}; + + func1(); + + execvp("ls", args); + + func2(); + + return 0; +} diff --git a/test/profile/Inputs/instrprof-gcov-execvp.c.gcov b/test/profile/Inputs/instrprof-gcov-execvp.c.gcov new file mode 100644 index 000000000000..37cd1e59ab38 --- /dev/null +++ b/test/profile/Inputs/instrprof-gcov-execvp.c.gcov @@ -0,0 +1,25 @@ +//CHECK: -: 0:Source:{{.*}}Inputs/instrprof-gcov-execvp.c +//CHECK-NEXT: -: 0:Graph:instrprof-gcov-execvp.gcno +//CHECK-NEXT: -: 0:Data:instrprof-gcov-execvp.gcda +//CHECK-NEXT: -: 0:Runs:1 +//CHECK-NEXT: -: 0:Programs:1 +//CHECK-NEXT: -: 1:#include <unistd.h> +//CHECK-NEXT: -: 2: +//CHECK-NEXT:function func1 called 1 returned 100% blocks executed 100% +//CHECK-NEXT: 1: 3:void func1() {} +//CHECK-NEXT:function func2 called 0 returned 0% blocks executed 0% +//CHECK-NEXT: #####: 4:void func2() {} +//CHECK-NEXT: -: 5: +//CHECK-NEXT:function main called 1 returned 0% blocks executed 33% +//CHECK-NEXT: 1: 6:int main(void) +//CHECK-NEXT: -: 7:{ +//CHECK-NEXT: 1: 8: char *const args[] = {"-l", "-h", (char*)0}; +//CHECK-NEXT: -: 9: +//CHECK-NEXT: 1: 10: func1(); +//CHECK-NEXT: -: 11: +//CHECK-NEXT: 1: 12: execvp("ls", args); +//CHECK-NEXT: -: 13: +//CHECK-NEXT: #####: 14: func2(); +//CHECK-NEXT: -: 15: +//CHECK-NEXT: #####: 16: return 0; +//CHECK-NEXT: -: 17:} diff --git a/test/profile/Inputs/instrprof-gcov-fork.c.gcov b/test/profile/Inputs/instrprof-gcov-fork.c.gcov index 9591f62ed602..c667c7b9e97e 100644 --- a/test/profile/Inputs/instrprof-gcov-fork.c.gcov +++ b/test/profile/Inputs/instrprof-gcov-fork.c.gcov @@ -10,8 +10,8 @@ // CHECK-NEXT:function func2 called 2 returned 100% blocks executed 100% // CHECK-NEXT: 2: 4:void func2() {} // CHECK-NEXT: -: 5: -// CHECK-NEXT:function main called 1 returned 100% blocks executed 100% -// CHECK-NEXT: -: 6:int main(void) +// CHECK-NEXT:function main called 1 returned 200% blocks executed 100% +// CHECK-NEXT: 1: 6:int main(void) // CHECK-NEXT: -: 7:{ // CHECK-NEXT: 1: 8: func1(); // CHECK-NEXT: -: 9: diff --git a/test/profile/Inputs/instrprof-gcov-multiple-bbs-single-line.c.gcov b/test/profile/Inputs/instrprof-gcov-multiple-bbs-single-line.c.gcov index 92532af30674..4bc1c1cd50f7 100644 --- a/test/profile/Inputs/instrprof-gcov-multiple-bbs-single-line.c.gcov +++ b/test/profile/Inputs/instrprof-gcov-multiple-bbs-single-line.c.gcov @@ -4,7 +4,7 @@ // CHECK-NEXT: -: 0:Runs:1 // CHECK-NEXT: -: 0:Programs:1 // CHECK-NEXT:function main called 1 returned 100% blocks executed 80% -// CHECK-NEXT: -: 1:int main(void) +// CHECK-NEXT: 1: 1:int main(void) // CHECK-NEXT: -: 2:{ // CHECK-NEXT: -: 3: int var; // CHECK-NEXT: -: 4: diff --git a/test/profile/Inputs/instrprof-gcov-one-line-function.c b/test/profile/Inputs/instrprof-gcov-one-line-function.c new file mode 100644 index 000000000000..ee1582351969 --- /dev/null +++ b/test/profile/Inputs/instrprof-gcov-one-line-function.c @@ -0,0 +1,11 @@ +void foo() { } + +void bar() { } + +int main(void) { + foo(); + + bar(); + + return 0; +} diff --git a/test/profile/Inputs/instrprof-gcov-one-line-function.c.gcov b/test/profile/Inputs/instrprof-gcov-one-line-function.c.gcov new file mode 100644 index 000000000000..a91b20fdc9a3 --- /dev/null +++ b/test/profile/Inputs/instrprof-gcov-one-line-function.c.gcov @@ -0,0 +1,16 @@ +// CHECK: -: 0:Source:{{.*}}Inputs/instrprof-gcov-one-line-function.c +// CHECK-NEXT: -: 0:Graph:instrprof-gcov-one-line-function.gcno +// CHECK-NEXT: -: 0:Data:instrprof-gcov-one-line-function.gcda +// CHECK-NEXT: -: 0:Runs:1 +// CHECK-NEXT: -: 0:Programs:1 +// CHECK-NEXT: 1: 1:void foo() { } +// CHECK-NEXT: -: 2: +// CHECK-NEXT: 1: 3:void bar() { } +// CHECK-NEXT: -: 4: +// CHECK-NEXT: 1: 5:int main(void) { +// CHECK-NEXT: 1: 6: foo(); +// CHECK-NEXT: -: 7: +// CHECK-NEXT: 1: 8: bar(); +// CHECK-NEXT: -: 9: +// CHECK-NEXT: 1: 10: return 0; +// CHECK-NEXT: -: 11:} diff --git a/test/profile/Inputs/instrprof-gcov-switch1.c.gcov b/test/profile/Inputs/instrprof-gcov-switch1.c.gcov index 7d136dc98ec3..6e9c5228b938 100644 --- a/test/profile/Inputs/instrprof-gcov-switch1.c.gcov +++ b/test/profile/Inputs/instrprof-gcov-switch1.c.gcov @@ -3,11 +3,11 @@ // CHECK-NEXT: -: 0:Data:instrprof-gcov-switch1.gcda // CHECK-NEXT: -: 0:Runs:1 // CHECK-NEXT: -: 0:Programs:1 -// CHECK-NEXT: -: 1:int main(void) +// CHECK-NEXT: 1: 1:int main(void) // CHECK-NEXT: -: 2:{ -// CHECK-NEXT: 2: 3: int i = 22; +// CHECK-NEXT: 1: 3: int i = 22; // CHECK-NEXT: -: 4: -// CHECK-NEXT: 2: 5: switch (i) { +// CHECK-NEXT: 1: 5: switch (i) { // CHECK-NEXT: -: 6: case 7: // CHECK-NEXT: #####: 7: break; // CHECK-NEXT: -: 8: diff --git a/test/profile/Inputs/instrprof-gcov-switch2.c.gcov b/test/profile/Inputs/instrprof-gcov-switch2.c.gcov index 67f408606a39..47d7f1d7cb41 100644 --- a/test/profile/Inputs/instrprof-gcov-switch2.c.gcov +++ b/test/profile/Inputs/instrprof-gcov-switch2.c.gcov @@ -3,11 +3,11 @@ // CHECK-NEXT: -: 0:Data:instrprof-gcov-switch2.gcda // CHECK-NEXT: -: 0:Runs:1 // CHECK-NEXT: -: 0:Programs:1 -// CHECK-NEXT: -: 1:int main(void) +// CHECK-NEXT: 1: 1:int main(void) // CHECK-NEXT: -: 2:{ -// CHECK-NEXT: 3: 3: int i = 22; +// CHECK-NEXT: 1: 3: int i = 22; // CHECK-NEXT: -: 4: -// CHECK-NEXT: 3: 5: switch (i) { +// CHECK-NEXT: 1: 5: switch (i) { // CHECK-NEXT: -: 6: case 7: // CHECK-NEXT: #####: 7: break; // CHECK-NEXT: -: 8: diff --git a/test/profile/Inputs/instrprof-shared-lib.c.gcov b/test/profile/Inputs/instrprof-shared-lib.c.gcov index fbc43d5f7d50..620a85257577 100644 --- a/test/profile/Inputs/instrprof-shared-lib.c.gcov +++ b/test/profile/Inputs/instrprof-shared-lib.c.gcov @@ -6,7 +6,7 @@ // CHECK-NEXT: -: 1:int g1 = 0; // CHECK-NEXT: -: 2:int g2 = 1; // CHECK-NEXT: -: 3: -// CHECK-NEXT: -: 4:void foo(int n) { +// CHECK-NEXT: 1: 4:void foo(int n) { // CHECK-NEXT: 1: 5: if (n % 5 == 0) // CHECK-NEXT: #####: 6: g1++; // CHECK-NEXT: -: 7: else diff --git a/test/profile/Inputs/instrprof-shared-lib_called-twice.c.gcov b/test/profile/Inputs/instrprof-shared-lib_called-twice.c.gcov index 779c885d862d..39b32b8c097a 100644 --- a/test/profile/Inputs/instrprof-shared-lib_called-twice.c.gcov +++ b/test/profile/Inputs/instrprof-shared-lib_called-twice.c.gcov @@ -6,7 +6,7 @@ // CHECK-NEXT: -: 1:int g1 = 0; // CHECK-NEXT: -: 2:int g2 = 1; // CHECK-NEXT: -: 3: -// CHECK-NEXT: -: 4:void foo(int n) { +// CHECK-NEXT: 2: 4:void foo(int n) { // CHECK-NEXT: 2: 5: if (n % 5 == 0) // CHECK-NEXT: #####: 6: g1++; // CHECK-NEXT: -: 7: else diff --git a/test/profile/Inputs/instrprof-shared-lib_in-loop.c.gcov b/test/profile/Inputs/instrprof-shared-lib_in-loop.c.gcov index 76503d91426e..0fc7ccbabab2 100644 --- a/test/profile/Inputs/instrprof-shared-lib_in-loop.c.gcov +++ b/test/profile/Inputs/instrprof-shared-lib_in-loop.c.gcov @@ -6,7 +6,7 @@ // CHECK-NEXT: -: 1:int g1 = 0; // CHECK-NEXT: -: 2:int g2 = 1; // CHECK-NEXT: -: 3: -// CHECK-NEXT: -: 4:void foo(int n) { +// CHECK-NEXT: 1000000: 4:void foo(int n) { // CHECK-NEXT: 1000000: 5: if (n % 5 == 0) // CHECK-NEXT: 360000: 6: g1++; // CHECK-NEXT: -: 7: else diff --git a/test/profile/Inputs/instrprof-shared-main-gcov-flush_no-writeout.c.gcov b/test/profile/Inputs/instrprof-shared-main-gcov-flush_no-writeout.c.gcov index b2dfe2acde67..6027c64af61b 100644 --- a/test/profile/Inputs/instrprof-shared-main-gcov-flush_no-writeout.c.gcov +++ b/test/profile/Inputs/instrprof-shared-main-gcov-flush_no-writeout.c.gcov @@ -9,14 +9,14 @@ // CHECK-NEXT: -: 4:int bar1 = 0; // CHECK-NEXT: -: 5:int bar2 = 1; // CHECK-NEXT: -: 6: -// CHECK-NEXT: -: 7:void bar(int n) { +// CHECK-NEXT: 1: 7:void bar(int n) { // CHECK-NEXT: 1: 8: if (n % 5 == 0) // CHECK-NEXT: 1: 9: bar1++; // CHECK-NEXT: -: 10: else // CHECK-NEXT: #####: 11: bar2++; // CHECK-NEXT: 1: 12:} // CHECK-NEXT: -: 13: -// CHECK-NEXT: -: 14:int main(int argc, char *argv[]) { +// CHECK-NEXT: 1: 14:int main(int argc, char *argv[]) { // CHECK-NEXT: -: 15:#ifdef SHARED_CALL_BEFORE_GCOV_FLUSH // CHECK-NEXT: 1: 16: foo(1); // CHECK-NEXT: -: 17:#endif diff --git a/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-after.c.gcov b/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-after.c.gcov index f70e34e52894..fba3f3fe2812 100644 --- a/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-after.c.gcov +++ b/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-after.c.gcov @@ -9,14 +9,14 @@ // CHECK-NEXT: -: 4:int bar1 = 0; // CHECK-NEXT: -: 5:int bar2 = 1; // CHECK-NEXT: -: 6: -// CHECK-NEXT: -: 7:void bar(int n) { +// CHECK-NEXT: 3: 7:void bar(int n) { // CHECK-NEXT: 3: 8: if (n % 5 == 0) // CHECK-NEXT: 3: 9: bar1++; // CHECK-NEXT: -: 10: else // CHECK-NEXT: #####: 11: bar2++; // CHECK-NEXT: 3: 12:} // CHECK-NEXT: -: 13: -// CHECK-NEXT: -: 14:int main(int argc, char *argv[]) { +// CHECK-NEXT: 1: 14:int main(int argc, char *argv[]) { // CHECK-NEXT: -: 15:#ifdef SHARED_CALL_BEFORE_GCOV_FLUSH // CHECK-NEXT: -: 16: foo(1); // CHECK-NEXT: -: 17:#endif diff --git a/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-before-after.c.gcov b/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-before-after.c.gcov index b9ecff698722..86beda22a1ad 100644 --- a/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-before-after.c.gcov +++ b/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-before-after.c.gcov @@ -9,14 +9,14 @@ // CHECK-NEXT: -: 4:int bar1 = 0; // CHECK-NEXT: -: 5:int bar2 = 1; // CHECK-NEXT: -: 6: -// CHECK-NEXT: -: 7:void bar(int n) { +// CHECK-NEXT: 3: 7:void bar(int n) { // CHECK-NEXT: 3: 8: if (n % 5 == 0) // CHECK-NEXT: 3: 9: bar1++; // CHECK-NEXT: -: 10: else // CHECK-NEXT: #####: 11: bar2++; // CHECK-NEXT: 3: 12:} // CHECK-NEXT: -: 13: -// CHECK-NEXT: -: 14:int main(int argc, char *argv[]) { +// CHECK-NEXT: 1: 14:int main(int argc, char *argv[]) { // CHECK-NEXT: -: 15:#ifdef SHARED_CALL_BEFORE_GCOV_FLUSH // CHECK-NEXT: 1: 16: foo(1); // CHECK-NEXT: -: 17:#endif diff --git a/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-before.c.gcov b/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-before.c.gcov index 7c9e0afa11b2..2e55741cc536 100644 --- a/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-before.c.gcov +++ b/test/profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-before.c.gcov @@ -9,14 +9,14 @@ // CHECK-NEXT: -: 4:int bar1 = 0; // CHECK-NEXT: -: 5:int bar2 = 1; // CHECK-NEXT: -: 6: -// CHECK-NEXT: -: 7:void bar(int n) { +// CHECK-NEXT: 3: 7:void bar(int n) { // CHECK-NEXT: 3: 8: if (n % 5 == 0) // CHECK-NEXT: 3: 9: bar1++; // CHECK-NEXT: -: 10: else // CHECK-NEXT: #####: 11: bar2++; // CHECK-NEXT: 3: 12:} // CHECK-NEXT: -: 13: -// CHECK-NEXT: -: 14:int main(int argc, char *argv[]) { +// CHECK-NEXT: 1: 14:int main(int argc, char *argv[]) { // CHECK-NEXT: -: 15:#ifdef SHARED_CALL_BEFORE_GCOV_FLUSH // CHECK-NEXT: 1: 16: foo(1); // CHECK-NEXT: -: 17:#endif diff --git a/test/profile/Inputs/instrprof-shared-main.c.gcov b/test/profile/Inputs/instrprof-shared-main.c.gcov index 70be367507ff..05cd4e31d6eb 100644 --- a/test/profile/Inputs/instrprof-shared-main.c.gcov +++ b/test/profile/Inputs/instrprof-shared-main.c.gcov @@ -6,10 +6,10 @@ // CHECK-NEXT: -: 1:extern int g1, g2; // CHECK-NEXT: -: 2:extern void foo(int n); // CHECK-NEXT: -: 3: -// CHECK-NEXT: -: 4:int main() { +// CHECK-NEXT: 1: 4:int main() { // CHECK-NEXT: -: 5: int i, j; -// CHECK-NEXT: 2002: 6: for (i = 0; i < 1000; i++) -// CHECK-NEXT: 2002000: 7: for (j = 0; j < 1000; j++) +// CHECK-NEXT: 1001: 6: for (i = 0; i < 1000; i++) +// CHECK-NEXT: 1001000: 7: for (j = 0; j < 1000; j++) // CHECK-NEXT: 1001000: 8: foo(i * j); // CHECK-NEXT: -: 9: // CHECK-NEXT: 1: 10: if (g2 - g1 == 280001) diff --git a/test/profile/Posix/instrprof-gcov-execlp.test b/test/profile/Posix/instrprof-gcov-execlp.test new file mode 100644 index 000000000000..1d136ce97907 --- /dev/null +++ b/test/profile/Posix/instrprof-gcov-execlp.test @@ -0,0 +1,10 @@ +RUN: mkdir -p %t.d +RUN: cd %t.d + +RUN: %clang --coverage -o %t %S/../Inputs/instrprof-gcov-execlp.c +RUN: test -f instrprof-gcov-execlp.gcno + +RUN: rm -f instrprof-gcov-execlp.gcda +RUN: %run %t +RUN: llvm-cov gcov -b -c instrprof-gcov-execlp.gcda +RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-gcov-execlp.c.gcov %S/../Inputs/instrprof-gcov-execlp.c.gcov diff --git a/test/profile/Posix/instrprof-gcov-execvp.test b/test/profile/Posix/instrprof-gcov-execvp.test new file mode 100644 index 000000000000..8e5cbc609509 --- /dev/null +++ b/test/profile/Posix/instrprof-gcov-execvp.test @@ -0,0 +1,10 @@ +RUN: mkdir -p %t.d +RUN: cd %t.d + +RUN: %clang --coverage -o %t %S/../Inputs/instrprof-gcov-execvp.c +RUN: test -f instrprof-gcov-execvp.gcno + +RUN: rm -f instrprof-gcov-execvp.gcda +RUN: %run %t +RUN: llvm-cov gcov -b -c instrprof-gcov-execvp.gcda +RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-gcov-execvp.c.gcov %S/../Inputs/instrprof-gcov-execvp.c.gcov diff --git a/test/profile/Posix/instrprof-gcov-fork.test b/test/profile/Posix/instrprof-gcov-fork.test index 436d7e663faa..5a406fda4b67 100644 --- a/test/profile/Posix/instrprof-gcov-fork.test +++ b/test/profile/Posix/instrprof-gcov-fork.test @@ -1,4 +1,4 @@ -XFAIL: * +UNSUPPORTED: linux RUN: mkdir -p %t.d RUN: cd %t.d diff --git a/test/profile/instrprof-darwin-exports.c b/test/profile/instrprof-darwin-exports.c index 6667cabdb2df..1ef36ae8b553 100644 --- a/test/profile/instrprof-darwin-exports.c +++ b/test/profile/instrprof-darwin-exports.c @@ -8,4 +8,20 @@ // RUN: %clang_profgen -Werror -fcoverage-mapping -Wl,-exported_symbols_list,%t.exports -o %t %s 2>&1 | tee -a %t.log // RUN: cat %t.log | count 0 +// RUN: %clang -Werror -Wl,-exported_symbols_list,%t.exports --coverage -o %t.gcov %s | tee -a %t.gcov.log +// RUN: cat %t.gcov.log | count 0 + +// The default set of weak external symbols should match the set of symbols +// exported by clang. See Darwin::addProfileRTLibs. + +// RUN: %clang_pgogen -Werror -o %t.default %s +// RUN: nm -jUg %t.default | grep -v __mh_execute_header > %t.default.exports +// RUN: nm -jUg %t > %t.clang.exports +// RUN: diff %t.default.exports %t.clang.exports + +// RUN: %clang -Werror --coverage -o %t.gcov.default %s +// RUN: nm -jUg %t.gcov | grep -v __mh_execute_header > %t.gcov.exports +// RUN: nm -jUg %t.gcov.default | grep -v __mh_execute_header > %t.gcov.default.exports +// RUN: diff %t.gcov.default.exports %t.gcov.exports + int main() {} diff --git a/test/profile/instrprof-dlopen-dlclose-gcov.test b/test/profile/instrprof-dlopen-dlclose-gcov.test index 0444fca2692c..36b5dbd262df 100644 --- a/test/profile/instrprof-dlopen-dlclose-gcov.test +++ b/test/profile/instrprof-dlopen-dlclose-gcov.test @@ -1,3 +1,6 @@ +# atexit(3) not supported in dlopen(3)ed+dlclose(3)d DSO +XFAIL: netbsd + RUN: mkdir -p %t.d RUN: cd %t.d @@ -7,6 +10,7 @@ RUN: %clang --coverage -o func3.shared -fPIC -shared %S/Inputs/instrprof-dlopen- RUN: %clang --coverage -o %t -fPIC -rpath %t.d %S/Inputs/instrprof-dlopen-dlclose-main.c # Test with two dlopened libraries. +RUN: rm -f instrprof-dlopen-dlclose-main.gcda instrprof-dlopen-func.gcda instrprof-dlopen-func2.gcda RUN: %run %t RUN: llvm-cov gcov instrprof-dlopen-dlclose-main.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-dlclose-main.c.gcov %S/Inputs/instrprof-dlopen-dlclose-main.c.gcov @@ -14,10 +18,10 @@ RUN: llvm-cov gcov instrprof-dlopen-func.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-func.c.gcov %S/Inputs/instrprof-dlopen-func.c.gcov RUN: llvm-cov gcov instrprof-dlopen-func2.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-func2.c.gcov %S/Inputs/instrprof-dlopen-func2.c.gcov -RUN: rm instrprof-dlopen-dlclose-main.gcda instrprof-dlopen-func.gcda instrprof-dlopen-func2.gcda # Test with three dlopened libraries. RUN: %clang -DUSE_LIB3 --coverage -o %t -fPIC -rpath %t.d %S/Inputs/instrprof-dlopen-dlclose-main.c +RUN: rm -f instrprof-dlopen-dlclose-main.gcda instrprof-dlopen-func.gcda instrprof-dlopen-func2.gcda instrprof-dlopen-func3.gcda RUN: %run %t RUN: llvm-cov gcov instrprof-dlopen-dlclose-main.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-dlclose-main.c.gcov %S/Inputs/instrprof-dlopen-dlclose-main_three-libs.c.gcov @@ -27,4 +31,3 @@ RUN: llvm-cov gcov instrprof-dlopen-func2.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-func2.c.gcov %S/Inputs/instrprof-dlopen-func2.c.gcov RUN: llvm-cov gcov instrprof-dlopen-func3.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-func2.c.gcov %S/Inputs/instrprof-dlopen-func3.c.gcov -RUN: rm instrprof-dlopen-dlclose-main.gcda instrprof-dlopen-func.gcda instrprof-dlopen-func2.gcda instrprof-dlopen-func3.gcda diff --git a/test/profile/instrprof-gcov-__gcov_flush-multiple.test b/test/profile/instrprof-gcov-__gcov_flush-multiple.test new file mode 100644 index 000000000000..fdc93c93e0b0 --- /dev/null +++ b/test/profile/instrprof-gcov-__gcov_flush-multiple.test @@ -0,0 +1,10 @@ +RUN: mkdir -p %t.d +RUN: cd %t.d + +RUN: %clang --coverage -o %t %S/Inputs/instrprof-gcov-__gcov_flush-multiple.c +RUN: test -f instrprof-gcov-__gcov_flush-multiple.gcno + +RUN: rm -f instrprof-gcov-__gcov_flush-multiple.gcda +RUN: %run %t +RUN: llvm-cov gcov instrprof-gcov-__gcov_flush-multiple.gcda +RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-gcov-__gcov_flush-multiple.c.gcov %S/Inputs/instrprof-gcov-__gcov_flush-multiple.c.gcov diff --git a/test/profile/instrprof-gcov-multiple-bbs-single-line.test b/test/profile/instrprof-gcov-multiple-bbs-single-line.test index 8839455189ee..66b6429208a0 100644 --- a/test/profile/instrprof-gcov-multiple-bbs-single-line.test +++ b/test/profile/instrprof-gcov-multiple-bbs-single-line.test @@ -1,5 +1,3 @@ -XFAIL: * - RUN: mkdir -p %t.d RUN: cd %t.d diff --git a/test/profile/instrprof-gcov-one-line-function.test b/test/profile/instrprof-gcov-one-line-function.test new file mode 100644 index 000000000000..d67c21a863bf --- /dev/null +++ b/test/profile/instrprof-gcov-one-line-function.test @@ -0,0 +1,9 @@ +RUN: mkdir -p %t.d +RUN: cd %t.d + +RUN: %clang --coverage -o %t %S/Inputs/instrprof-gcov-one-line-function.c +RUN: test -f instrprof-gcov-one-line-function.gcno +RUN: rm -f instrprof-gcov-one-line-function.gcda +RUN: %run %t +RUN: llvm-cov gcov instrprof-gcov-one-line-function.gcda +RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-gcov-one-line-function.c.gcov %S/Inputs/instrprof-gcov-one-line-function.c.gcov diff --git a/test/profile/instrprof-gcov-two-objects.test b/test/profile/instrprof-gcov-two-objects.test index a53d51dce8ed..4080caa7fdd9 100644 --- a/test/profile/instrprof-gcov-two-objects.test +++ b/test/profile/instrprof-gcov-two-objects.test @@ -10,9 +10,9 @@ RUN: test -f instrprof-shared-main.gcno RUN: %clang --coverage -o %t instrprof-shared-main.o instrprof-shared-lib.o RUN: test -f %t +RUN: rm -f instrprof-shared-main.gcda instrprof-shared-lib.gcda RUN: %run %t RUN: llvm-cov gcov instrprof-shared-main.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-main.c.gcov %S/Inputs/instrprof-shared-main.c.gcov RUN: llvm-cov gcov instrprof-shared-lib.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-lib.c.gcov %S/Inputs/instrprof-shared-lib_in-loop.c.gcov -RUN: rm instrprof-shared-main.gcda instrprof-shared-lib.gcda diff --git a/test/profile/instrprof-merging.cpp b/test/profile/instrprof-merging.cpp new file mode 100644 index 000000000000..06f05ce612aa --- /dev/null +++ b/test/profile/instrprof-merging.cpp @@ -0,0 +1,53 @@ +// 1) Compile shared code into different object files and into an executable. + +// RUN: %clangxx_profgen -fcoverage-mapping %s -c -o %t.v1.o -D_VERSION_1 +// RUN: %clangxx_profgen -fcoverage-mapping %s -c -o %t.v2.o -D_VERSION_2 +// RUN: %clangxx_profgen -fcoverage-mapping %t.v1.o %t.v2.o -o %t.exe + +// 2) Collect profile data. + +// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.exe +// RUN: llvm-profdata merge %t.profraw -o %t.profdata + +// 3) Generate coverage reports from the different object files and the exe. + +// RUN: llvm-cov show %t.v1.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V1-ONLY +// RUN: llvm-cov show %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V2,V2-ONLY +// RUN: llvm-cov show %t.v1.o -object %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2 +// RUN: llvm-cov show %t.exe -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2 + +// 4) Verify that coverage reporting on the aggregate coverage mapping shows +// hits for all code. (We used to arbitrarily pick a mapping from one binary +// and prefer it over others.) When only limited coverage information is +// available (just from one binary), don't try to guess any region counts. + +struct A { + A() {} // V1: [[@LINE]]{{ *}}|{{ *}}1 + // V1-ONLY: [[@LINE+1]]{{ *}}|{{ *}}| + A(int) {} // V2-ONLY: [[@LINE-2]]{{ *}}|{{ *}}| + // V2: [[@LINE-1]]{{ *}}|{{ *}}1 +}; + +#ifdef _VERSION_1 + +void foo(); + +void bar() { + A x; // V1: [[@LINE]]{{ *}}|{{ *}}1 +} + +int main() { + foo(); // V1: [[@LINE]]{{ *}}|{{ *}}1 + bar(); + return 0; +} + +#endif // _VERSION_1 + +#ifdef _VERSION_2 + +void foo() { + A x{0}; // V2: [[@LINE]]{{ *}}|{{ *}}1 +} + +#endif // _VERSION_2 diff --git a/test/profile/instrprof-shared-gcov-flush.test b/test/profile/instrprof-shared-gcov-flush.test index 50292b6336c4..542db0412437 100644 --- a/test/profile/instrprof-shared-gcov-flush.test +++ b/test/profile/instrprof-shared-gcov-flush.test @@ -11,42 +11,42 @@ RUN: test -f instrprof-shared-lib.gcno RUN: %clang -DEXIT_ABRUPTLY -DSHARED_CALL_BEFORE_GCOV_FLUSH -DSHARED_CALL_AFTER_GCOV_FLUSH --coverage -o %t -L%t.d -rpath %t.d -lfunc %S/Inputs/instrprof-shared-main-gcov-flush.c RUN: test -f instrprof-shared-main-gcov-flush.gcno +RUN: rm -f instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda RUN: %run %t RUN: llvm-cov gcov instrprof-shared-main-gcov-flush.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-main-gcov-flush.c.gcov %S/Inputs/instrprof-shared-main-gcov-flush_no-writeout.c.gcov RUN: llvm-cov gcov instrprof-shared-lib.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-lib.c.gcov %S/Inputs/instrprof-shared-lib.c.gcov -RUN: rm instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda # Test the case where we exit normally and we have a call to the shared library function before __gcov_flush. RUN: %clang -DSHARED_CALL_BEFORE_GCOV_FLUSH --coverage -o %t -L%t.d -rpath %t.d -lfunc %S/Inputs/instrprof-shared-main-gcov-flush.c RUN: test -f instrprof-shared-main-gcov-flush.gcno +RUN: rm -f instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda RUN: %run %t RUN: llvm-cov gcov instrprof-shared-main-gcov-flush.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-main-gcov-flush.c.gcov %S/Inputs/instrprof-shared-main-gcov-flush_shared-call-before.c.gcov RUN: llvm-cov gcov instrprof-shared-lib.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-lib.c.gcov %S/Inputs/instrprof-shared-lib.c.gcov -RUN: rm instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda # Test the case where we exit normally and we have a call to the shared library function after __gcov_flush. RUN: %clang -DSHARED_CALL_AFTER_GCOV_FLUSH --coverage -o %t -L%t.d -rpath %t.d -lfunc %S/Inputs/instrprof-shared-main-gcov-flush.c RUN: test -f instrprof-shared-main-gcov-flush.gcno +RUN: rm -f instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda RUN: %run %t RUN: llvm-cov gcov instrprof-shared-main-gcov-flush.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-main-gcov-flush.c.gcov %S/Inputs/instrprof-shared-main-gcov-flush_shared-call-after.c.gcov RUN: llvm-cov gcov instrprof-shared-lib.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-lib.c.gcov %S/Inputs/instrprof-shared-lib.c.gcov -RUN: rm instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda # Test the case where we exit normally and we have calls to the shared library function before and after __gcov_flush. RUN: %clang -DSHARED_CALL_BEFORE_GCOV_FLUSH -DSHARED_CALL_AFTER_GCOV_FLUSH --coverage -o %t -L%t.d -rpath %t.d -lfunc %S/Inputs/instrprof-shared-main-gcov-flush.c RUN: test -f instrprof-shared-main-gcov-flush.gcno +RUN: rm -f instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda RUN: %run %t RUN: llvm-cov gcov instrprof-shared-main-gcov-flush.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-main-gcov-flush.c.gcov %S/Inputs/instrprof-shared-main-gcov-flush_shared-call-before-after.c.gcov RUN: llvm-cov gcov instrprof-shared-lib.gcda RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-lib.c.gcov %S/Inputs/instrprof-shared-lib_called-twice.c.gcov -RUN: rm instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda diff --git a/test/profile/lit.cfg b/test/profile/lit.cfg index 1cd2509672fd..7449650a623c 100644 --- a/test/profile/lit.cfg +++ b/test/profile/lit.cfg @@ -67,7 +67,7 @@ config.substitutions.append( ("%clangxx_profuse=", build_invocation(clang_cxxfla config.substitutions.append( ("%clang_lto_profgen=", build_invocation(clang_cflags, True) + " -fprofile-instr-generate=") ) -if config.host_os not in ['Darwin', 'FreeBSD', 'Linux', 'SunOS']: +if config.host_os not in ['Darwin', 'FreeBSD', 'Linux', 'NetBSD', 'SunOS']: config.unsupported = True if config.target_arch in ['armv7l']: diff --git a/test/safestack/lit.cfg b/test/safestack/lit.cfg index 10cd8a5a5135..f58ec45533d7 100644 --- a/test/safestack/lit.cfg +++ b/test/safestack/lit.cfg @@ -18,5 +18,5 @@ config.substitutions.append( ("%clang_safestack ", config.clang + " -O0 -fsaniti if config.lto_supported: config.substitutions.append((r"%clang_lto_safestack ", ' '.join(config.lto_launch + [config.clang] + config.lto_flags + ['-fsanitize=safe-stack ']))) -if config.host_os not in ['Linux', 'FreeBSD', 'Darwin', 'NetBSD']: +if config.host_os not in ['Linux', 'FreeBSD', 'NetBSD']: config.unsupported = True diff --git a/test/safestack/pthread-cleanup.c b/test/safestack/pthread-cleanup.c index 805366c9f1eb..55c5b42dcbb2 100644 --- a/test/safestack/pthread-cleanup.c +++ b/test/safestack/pthread-cleanup.c @@ -1,7 +1,9 @@ // RUN: %clang_safestack %s -pthread -o %t -// RUN: not --crash %run %t +// RUN: %run %t 0 +// RUN: not --crash %run %t 1 -// Test that unsafe stacks are deallocated correctly on thread exit. +// Test unsafe stack deallocation. Unsafe stacks are not deallocated immediately +// at thread exit. They are deallocated by following exiting threads. #include <stdlib.h> #include <string.h> @@ -9,7 +11,7 @@ enum { kBufferSize = (1 << 15) }; -void *t1_start(void *ptr) +void *start(void *ptr) { char buffer[kBufferSize]; return buffer; @@ -17,15 +19,36 @@ void *t1_start(void *ptr) int main(int argc, char **argv) { - pthread_t t1; - char *buffer = NULL; + int arg = atoi(argv[1]); - if (pthread_create(&t1, NULL, t1_start, NULL)) + pthread_t t1, t2; + char *t1_buffer = NULL; + + if (pthread_create(&t1, NULL, start, NULL)) abort(); - if (pthread_join(t1, &buffer)) + if (pthread_join(t1, &t1_buffer)) abort(); - // should segfault here - memset(buffer, 0, kBufferSize); + // Stack has not yet been deallocated + memset(t1_buffer, 0, kBufferSize); + + if (arg == 0) + return 0; + + for (int i = 0; i < 3; i++) { + if (pthread_create(&t2, NULL, start, NULL)) + abort(); + // Second thread destructor cleans up the first thread's stack. + if (pthread_join(t2, NULL)) + abort(); + + // Should segfault here + memset(t1_buffer, 0, kBufferSize); + + // PR39001: Re-try in the rare case that pthread_join() returns before the + // thread finishes exiting in the kernel--hence the tgkill() check for t1 + // returns that it's alive despite pthread_join() returning. + sleep(1); + } return 0; } diff --git a/test/safestack/pthread-stack-size.c b/test/safestack/pthread-stack-size.c new file mode 100644 index 000000000000..2fe7c680ef6f --- /dev/null +++ b/test/safestack/pthread-stack-size.c @@ -0,0 +1,53 @@ +// RUN: %clang_safestack %s -pthread -o %t +// RUN: %run %t + +// Test unsafe stack deallocation with custom stack sizes, in particular ensure +// that we correctly deallocate small stacks and don't accidentally deallocate +// adjacent memory. + +#include <pthread.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +volatile int step = 0; + +void *wait_until(void *ptr) { + while ((int)ptr != step) + usleep(1000); + + volatile char buf[64]; + buf[0] = 0; + + return NULL; +} + +int main(int argc, char **argv) { + pthread_t t1, t2, t3; + + pthread_attr_t small_stack_attr; + pthread_attr_init(&small_stack_attr); + pthread_attr_setstacksize(&small_stack_attr, 65536); + + if (pthread_create(&t3, NULL, wait_until, (void *)3)) + abort(); + if (pthread_create(&t1, &small_stack_attr, wait_until, (void *)1)) + abort(); + if (pthread_create(&t2, NULL, wait_until, (void *)2)) + abort(); + + step = 1; + if (pthread_join(t1, NULL)) + abort(); + + step = 2; + if (pthread_join(t2, NULL)) + abort(); + + step = 3; + if (pthread_join(t3, NULL)) + abort(); + + pthread_attr_destroy(&small_stack_attr); + return 0; +} diff --git a/test/safestack/pthread.c b/test/safestack/pthread.c index 416586ee13e7..1687c10a6ef2 100644 --- a/test/safestack/pthread.c +++ b/test/safestack/pthread.c @@ -1,8 +1,6 @@ // RUN: %clang_safestack %s -pthread -o %t // RUN: %run %t -// XFAIL: darwin - // Test that pthreads receive their own unsafe stack. #include <stdlib.h> diff --git a/test/sanitizer_common/CMakeLists.txt b/test/sanitizer_common/CMakeLists.txt index 4e2c80390f71..23292e548207 100644 --- a/test/sanitizer_common/CMakeLists.txt +++ b/test/sanitizer_common/CMakeLists.txt @@ -16,6 +16,13 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT ANDROID) list(APPEND SUPPORTED_TOOLS lsan) endif() +# FIXME(dliew): Remove this. +# Temporary helper for https://reviews.llvm.org/D55740 +message( + STATUS + "sanitizer_common tests on \"${CMAKE_SYSTEM_NAME}\" will run against " + "\"${SUPPORTED_TOOLS}\"") + # Create a separate config for each tool we support. foreach(tool ${SUPPORTED_TOOLS}) string(TOUPPER ${tool} tool_toupper) diff --git a/test/sanitizer_common/TestCases/FreeBSD/capsicum.cc b/test/sanitizer_common/TestCases/FreeBSD/capsicum.cc new file mode 100644 index 000000000000..1bfb6f8d945c --- /dev/null +++ b/test/sanitizer_common/TestCases/FreeBSD/capsicum.cc @@ -0,0 +1,68 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <sys/capsicum.h> +#include <sys/ioctl.h> + +#include <assert.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <termios.h> +#include <unistd.h> + +void test_cap_ioctls() { + cap_rights_t rights; + unsigned long ncmds[] = {TIOCGETA, TIOCGWINSZ, FIODTYPE}; + unsigned long rcmds = 0; + cap_rights_t *rptr = cap_rights_init(&rights, CAP_IOCTL, CAP_READ); + assert(rptr); + + int rv = cap_rights_limit(STDIN_FILENO, &rights); + assert(rv == 0); + rv = cap_ioctls_limit(STDIN_FILENO, ncmds, 3); + assert(rv == 0); + ssize_t rz = cap_ioctls_get(STDIN_FILENO, &rcmds, 3); + assert(rz == 3); + printf("ioctls test: %ld commands authorized\n", rz); +} + +void test_cap_rights() { + cap_rights_t rights, little, remove, grights; + cap_rights_t *rptr = cap_rights_init(&rights, CAP_IOCTL, CAP_READ); + assert(rptr); + cap_rights_t *gptr = cap_rights_init(&remove, CAP_IOCTL); + assert(gptr); + cap_rights_t *sptr = cap_rights_init(&little, CAP_READ); + assert(sptr); + bool hasit = cap_rights_contains(rptr, sptr); + assert(hasit == true); + cap_rights_t *pptr = cap_rights_remove(&rights, gptr); + hasit = cap_rights_contains(pptr, sptr); + assert(hasit == true); + cap_rights_t *aptr = cap_rights_merge(&rights, gptr); + assert(aptr); + bool correct = cap_rights_is_valid(&rights); + assert(correct == true); + + int rv = cap_rights_limit(STDIN_FILENO, &rights); + assert(rv == 0); + rv = cap_rights_get(STDIN_FILENO, &grights); + assert(rv == 0); + assert(memcmp(&grights, &rights, sizeof(grights)) == 0); + cap_rights_t *iptr = cap_rights_set(&rights, CAP_IOCTL); + assert(iptr); + cap_rights_t *eptr = cap_rights_clear(&rights, CAP_READ); + assert(eptr); + hasit = cap_rights_is_set(&rights, CAP_IOCTL); + assert(hasit == true); + printf("rights test: %d\n", rv); +} + +int main(void) { + test_cap_ioctls(); + + test_cap_rights(); + + // CHECK: ioctls test: {{.*}} commands authorized + // CHECK: rights test: {{.*}} +} diff --git a/test/sanitizer_common/TestCases/FreeBSD/fdevname.cc b/test/sanitizer_common/TestCases/FreeBSD/fdevname.cc new file mode 100644 index 000000000000..252335e9afb4 --- /dev/null +++ b/test/sanitizer_common/TestCases/FreeBSD/fdevname.cc @@ -0,0 +1,44 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <assert.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/stat.h> + +void test_fdevname() { + int fd = open("/dev/null", O_RDONLY); + char *name; + + printf("test_fdevname\n"); + assert(fd != -1); + assert((name = fdevname(fd))); + close(fd); + + printf("%s\n", name); +} + +void test_fdevname_r() { + int fd = open("/dev/null", O_RDONLY); + char *name; + char buf[5]; + + printf("test_fdevname_r\n"); + assert(fd != -1); + assert((name = fdevname_r(fd, buf, sizeof(buf)))); + close(fd); + + printf("%s\n", name); +} + +int main(void) { + test_fdevname(); + test_fdevname_r(); + // CHECK: test_fdevname + // CHECK: null + // CHECK: test_fdevname_r + // CHECK: null + + return 0; +} diff --git a/test/sanitizer_common/TestCases/FreeBSD/lit.local.cfg b/test/sanitizer_common/TestCases/FreeBSD/lit.local.cfg new file mode 100644 index 000000000000..6f2f4280f978 --- /dev/null +++ b/test/sanitizer_common/TestCases/FreeBSD/lit.local.cfg @@ -0,0 +1,9 @@ +def getRoot(config): + if not config.parent: + return config + return getRoot(config.parent) + +root = getRoot(config) + +if root.host_os not in ['FreeBSD']: + config.unsupported = True diff --git a/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc b/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc index e17de1853eb3..bd58f4bd9265 100644 --- a/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc +++ b/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc @@ -1,7 +1,6 @@ // Regression test for // https://code.google.com/p/address-sanitizer/issues/detail?id=180 -// clang-format off // RUN: %clangxx -O0 %s -o %t // RUN: %env_tool_opts=handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0 @@ -15,7 +14,6 @@ // RUN: %env_tool_opts=handle_segv=0:allow_user_segv_handler=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0 // RUN: %env_tool_opts=handle_segv=1:allow_user_segv_handler=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 // RUN: %env_tool_opts=handle_segv=2:allow_user_segv_handler=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 -// clang-format on // Flaky errors in debuggerd with "waitpid returned unexpected pid (0)" in logcat. // UNSUPPORTED: android && i386-target-arch diff --git a/test/sanitizer_common/TestCases/Linux/assert.cc b/test/sanitizer_common/TestCases/Linux/assert.cc index 9c5263f8e776..2a73c508844b 100644 --- a/test/sanitizer_common/TestCases/Linux/assert.cc +++ b/test/sanitizer_common/TestCases/Linux/assert.cc @@ -1,11 +1,9 @@ // Test the handle_abort option. -// clang-format off // RUN: %clangxx %s -o %t // RUN: not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s // RUN: %env_tool_opts=handle_abort=0 not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s // RUN: %env_tool_opts=handle_abort=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s -// clang-format on #include <assert.h> #include <stdio.h> diff --git a/test/sanitizer_common/TestCases/Linux/ill.cc b/test/sanitizer_common/TestCases/Linux/ill.cc index 43f7a7830495..bbde13b5675b 100644 --- a/test/sanitizer_common/TestCases/Linux/ill.cc +++ b/test/sanitizer_common/TestCases/Linux/ill.cc @@ -1,11 +1,9 @@ // Test the handle_sigill option. -// clang-format off // RUN: %clangxx %s -o %t -O1 // RUN: not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s // RUN: %env_tool_opts=handle_sigill=0 not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s // RUN: %env_tool_opts=handle_sigill=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s -// clang-format on // FIXME: seems to fail on ARM // REQUIRES: x86_64-target-arch diff --git a/test/sanitizer_common/TestCases/Linux/mallopt.cc b/test/sanitizer_common/TestCases/Linux/mallopt.cc new file mode 100644 index 000000000000..9ac3c5dc5978 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/mallopt.cc @@ -0,0 +1,10 @@ +// Check that mallopt does not return invalid values (ex. -1). +// RUN: %clangxx -O2 %s -o %t && %run %t +#include <assert.h> +#include <malloc.h> + +int main() { + // Try a random mallopt option, possibly invalid. + int res = mallopt(-42, 0); + assert(res == 0 || res == 1); +} diff --git a/test/sanitizer_common/TestCases/Linux/signal_segv_handler.cc b/test/sanitizer_common/TestCases/Linux/signal_segv_handler.cc index d6c3ecbff475..9802617c2d05 100644 --- a/test/sanitizer_common/TestCases/Linux/signal_segv_handler.cc +++ b/test/sanitizer_common/TestCases/Linux/signal_segv_handler.cc @@ -1,6 +1,4 @@ -// clang-format off // RUN: %clangxx -O1 %s -o %t && TSAN_OPTIONS="flush_memory_ms=1 memory_limit_mb=1" %run %t 2>&1 | FileCheck %s -// clang-format on // JVM uses SEGV to preempt threads. All threads do a load from a known address // periodically. When runtime needs to preempt threads, it unmaps the page. diff --git a/test/sanitizer_common/TestCases/NetBSD/asysctl.cc b/test/sanitizer_common/TestCases/NetBSD/asysctl.cc new file mode 100644 index 000000000000..acdfb17f28b5 --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/asysctl.cc @@ -0,0 +1,44 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <sys/param.h> +#include <sys/types.h> + +#include <sys/sysctl.h> + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +void test_asysctl() { + int mib[] = {CTL_KERN, KERN_OSTYPE}; + size_t len; + char *buf = (char *)asysctl(mib, __arraycount(mib), &len); + assert(buf); + + printf("asysctl: '%s' size: '%zu'\n", buf, len); + + free(buf); +} + +void test_asysctlbyname() { + size_t len; + char *buf = (char *)asysctlbyname("kern.ostype", &len); + assert(buf); + + printf("asysctlbyname: '%s' size: '%zu'\n", buf, len); + + free(buf); +} + +int main(void) { + printf("asysctl\n"); + + test_asysctl(); + test_asysctlbyname(); + + return 0; + + // CHECK: asysctl + // CHECK: asysctl: '{{.*}}' size: '{{.*}}' + // CHECK: asysctlbyname: '{{.*}}' size: '{{.*}}' +} diff --git a/test/sanitizer_common/TestCases/NetBSD/cdb.cc b/test/sanitizer_common/TestCases/NetBSD/cdb.cc new file mode 100644 index 000000000000..065623b7d7d0 --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/cdb.cc @@ -0,0 +1,134 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <sys/param.h> + +#include <sys/types.h> + +#include <sys/mman.h> +#include <sys/stat.h> + +#include <assert.h> +#include <cdbr.h> +#include <cdbw.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +static char *name; + +const char data1[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; +const char data2[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17}; +const char key1[] = {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27}; +const char key2[] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37}; + +void test_cdbw() { + uint32_t idx; + + struct cdbw *cdbw = cdbw_open(); + assert(cdbw); + + int rv = cdbw_put_data(cdbw, data1, __arraycount(data1), &idx); + assert(!rv); + + rv = cdbw_put_key(cdbw, key1, __arraycount(key1), idx); + assert(!rv); + + rv = cdbw_put(cdbw, key2, __arraycount(key2), data2, __arraycount(data2)); + assert(!rv); + + name = strdup("/tmp/temp.XXXXXX"); + assert(name); + + name = mktemp(name); + assert(name); + + int fd = open(name, O_RDWR | O_CREAT, 0644); + assert(fd != -1); + + cdbw_output(cdbw, fd, "TEST1", cdbw_stable_seeder); + + cdbw_close(cdbw); + + rv = close(fd); + assert(rv != -1); +} + +void test_cdbr1() { + struct cdbr *cdbr = cdbr_open(name, CDBR_DEFAULT); + assert(cdbr); + + uint32_t idx = cdbr_entries(cdbr); + assert(idx > 0); + printf("entries: %" PRIu32 "\n", idx); + + const void *data; + size_t data_len; + int rv = cdbr_get(cdbr, idx - 1, &data, &data_len); + assert(rv == 0); + + printf("data: "); + for (size_t i = 0; i < data_len; i++) + printf("%02" PRIx8, ((uint8_t *)data)[i]); + printf("\n"); + + rv = cdbr_find(cdbr, key1, __arraycount(key1), &data, &data_len); + + printf("data: "); + for (size_t i = 0; i < data_len; i++) + printf("%02" PRIx8, ((uint8_t *)data)[i]); + printf("\n"); + + cdbr_close(cdbr); +} + +#define COOKIE ((void *)1) + +static void cdbr_unmap(void *cookie, void *base, size_t sz) { + assert(cookie == COOKIE); + int rv = munmap(base, sz); + assert(rv != -1); +} + +void test_cdbr2() { + struct stat sb; + + int fd = open(name, O_RDONLY); + assert(fd != -1); + + int rv = fstat(fd, &sb); + assert(rv != -1); + + size_t sz = sb.st_size; + assert(sz < SSIZE_MAX); + + void *base = mmap(NULL, sz, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0); + assert(base != MAP_FAILED); + + rv = close(fd); + assert(rv != -1); + + struct cdbr *cdbr = cdbr_open_mem(base, sz, CDBR_DEFAULT, cdbr_unmap, COOKIE); + assert(cdbr); + + printf("entries: %" PRIu32 "\n", cdbr_entries(cdbr)); + + cdbr_close(cdbr); +} + +int main(void) { + printf("cdb\n"); + + test_cdbw(); + test_cdbr1(); + test_cdbr2(); + + // CHECK: cdb + // CHECK: entries: 2 + // CHECK: data: 1011121314151617 + // CHECK: data: 0001020304050607 + // CHECK: entries: 2 + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/fparseln.cc b/test/sanitizer_common/TestCases/NetBSD/fparseln.cc new file mode 100644 index 000000000000..8a71d5fcdadc --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/fparseln.cc @@ -0,0 +1,25 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +int main(void) { + printf("fparseln\n"); + + FILE *fp = fopen("/etc/fstab", "r"); + assert(fp); + + int flags = FPARSELN_UNESCALL; + const char *delim = "\\\\#"; + size_t lineno = 0, len; + char *line; + while ((line = fparseln(fp, &len, &lineno, delim, flags))) { + printf("lineno: %zu, length: %zu, line: %s\n", lineno, len, line); + free(line); + } + + // CHECK: fparseln + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/funopen2.cc b/test/sanitizer_common/TestCases/NetBSD/funopen2.cc new file mode 100644 index 000000000000..181ad03c991f --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/funopen2.cc @@ -0,0 +1,110 @@ +// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s + +// CHECK: READ CALLED; len={{[0-9]*}} +// CHECK-NEXT: READ: test +// CHECK-NEXT: WRITE CALLED: test +// CHECK-NEXT: READ CALLED; len={{[0-9]*}} +// CHECK-NEXT: READ: test +// CHECK-NEXT: WRITE CALLED: test +// CHECK-NEXT: CLOSE CALLED +// CHECK-NEXT: SEEK CALLED; off=100, whence=0 +// CHECK-NEXT: READ CALLED; len={{[0-9]*}} +// CHECK-NEXT: READ: test +// CHECK-NEXT: WRITE CALLED: test +// CHECK-NEXT: FLUSH CALLED +// CHECK-NEXT: WRITE CALLED: test +// CHECK-NEXT: FLUSH CALLED + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int cookie_var; + +ssize_t f_read(void *cookie, void *buf, size_t len) { + assert(cookie == &cookie_var); + assert(len >= 6); + printf("READ CALLED; len=%zd\n", len); + return strlcpy((char*)buf, "test\n", len); +} + +ssize_t f_write(void *cookie, const void *buf, size_t len) { + assert(cookie == &cookie_var); + char *data = strndup((char*)buf, len); + assert(data); + printf("WRITE CALLED: %s\n", data); + free(data); + return len; +} + +off_t f_seek(void *cookie, off_t off, int whence) { + assert(cookie == &cookie_var); + assert(whence == SEEK_SET); + printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence); + return off; +} + +int f_flush(void *cookie) { + assert(cookie == &cookie_var); + printf("FLUSH CALLED\n"); + return 0; +} + +int f_close(void *cookie) { + assert(cookie == &cookie_var); + printf("CLOSE CALLED\n"); + return 0; +} + +int main(void) { + FILE *fp; + char buf[10]; + + // 1. read-only variant + fp = fropen2(&cookie_var, f_read); + assert(fp); + // verify that fileno() does not crash or report nonsense + assert(fileno(fp) == -1); + assert(fgets(buf, sizeof(buf), fp)); + printf("READ: %s", buf); + assert(!fclose(fp)); + + // 2. write-only variant + fp = fwopen2(&cookie_var, f_write); + assert(fp); + assert(fileno(fp) == -1); + assert(fputs("test", fp) >= 0); + assert(!fclose(fp)); + + // 3. read+write+close + fp = funopen2(&cookie_var, f_read, f_write, NULL, NULL, f_close); + assert(fp); + assert(fileno(fp) == -1); + assert(fgets(buf, sizeof(buf), fp)); + printf("READ: %s", buf); + assert(fputs("test", fp) >= 0); + assert(!fflush(fp)); + assert(!fclose(fp)); + + // 4. read+seek + fp = funopen2(&cookie_var, f_read, NULL, f_seek, NULL, NULL); + assert(fp); + assert(fileno(fp) == -1); + assert(fseek(fp, 100, SEEK_SET) == 0); + assert(fgets(buf, sizeof(buf), fp)); + printf("READ: %s", buf); + assert(!fclose(fp)); + + // 5. write+flush + fp = funopen2(&cookie_var, NULL, f_write, NULL, f_flush, NULL); + assert(fp); + assert(fileno(fp) == -1); + assert(fputs("test", fp) >= 0); + assert(!fflush(fp)); + assert(fputs("test", fp) >= 0); + // NB: fclose() also implicitly calls flush + assert(!fclose(fp)); + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/getgroupmembership.cc b/test/sanitizer_common/TestCases/NetBSD/getgroupmembership.cc index ee27ad6cf365..025ca9052e6f 100644 --- a/test/sanitizer_common/TestCases/NetBSD/getgroupmembership.cc +++ b/test/sanitizer_common/TestCases/NetBSD/getgroupmembership.cc @@ -1,5 +1,7 @@ // RUN: %clangxx -O0 -g %s -o %t && %run %t +// XFAIL: netbsd && msan + #include <stdlib.h> #include <unistd.h> #include <grp.h> diff --git a/test/sanitizer_common/TestCases/NetBSD/getvfsstat.cc b/test/sanitizer_common/TestCases/NetBSD/getvfsstat.cc new file mode 100644 index 000000000000..ea72e41ede0f --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/getvfsstat.cc @@ -0,0 +1,36 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <sys/types.h> + +#include <sys/statvfs.h> + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +int main(void) { + printf("getvfsstat\n"); + + int rv = getvfsstat(NULL, 0, ST_WAIT); + assert(rv != -1); + + size_t sz = rv * sizeof(struct statvfs); + struct statvfs *buf = (struct statvfs *)malloc(sz); + assert(buf); + + rv = getvfsstat(buf, sz, ST_WAIT); + assert(rv != -1); + + for (int i = 0; i < rv; i++) { + printf("Filesystem %d\n", i); + printf("\tfstypename=%s\n", buf[i].f_fstypename); + printf("\tmntonname=%s\n", buf[i].f_mntonname); + printf("\tmntfromname=%s\n", buf[i].f_mntfromname); + } + + free(buf); + + // CHECK: getvfsstat + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/md2.cc b/test/sanitizer_common/TestCases/NetBSD/md2.cc new file mode 100644 index 000000000000..7738aecdf822 --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/md2.cc @@ -0,0 +1,114 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <sys/param.h> + +#include <assert.h> +#include <endian.h> +#include <md2.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void test1() { + MD2_CTX ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + uint8_t digest[MD2_DIGEST_LENGTH]; + + MD2Init(&ctx); + MD2Update(&ctx, entropy, __arraycount(entropy)); + MD2Final(digest, &ctx); + + printf("test1: '"); + for (size_t i = 0; i < __arraycount(digest); i++) + printf("%02x", digest[i]); + printf("'\n"); +} + +void test2() { + MD2_CTX ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + char digest[MD2_DIGEST_STRING_LENGTH]; + + MD2Init(&ctx); + MD2Update(&ctx, entropy, __arraycount(entropy)); + char *p = MD2End(&ctx, digest); + assert(p == digest); + + printf("test2: '%s'\n", digest); +} + +void test3() { + MD2_CTX ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + + MD2Init(&ctx); + MD2Update(&ctx, entropy, __arraycount(entropy)); + char *p = MD2End(&ctx, NULL); + assert(strlen(p) == MD2_DIGEST_STRING_LENGTH - 1); + + printf("test3: '%s'\n", p); + + free(p); +} + +void test4() { + char digest[MD2_DIGEST_STRING_LENGTH]; + + char *p = MD2File("/etc/fstab", digest); + assert(p == digest); + + printf("test4: '%s'\n", p); +} + +void test5() { + char *p = MD2File("/etc/fstab", NULL); + assert(strlen(p) == MD2_DIGEST_STRING_LENGTH - 1); + + printf("test5: '%s'\n", p); + + free(p); +} + +void test6() { + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + char digest[MD2_DIGEST_STRING_LENGTH]; + + char *p = MD2Data(entropy, __arraycount(entropy), digest); + assert(p == digest); + + printf("test6: '%s'\n", p); +} + +void test7() { + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + + char *p = MD2Data(entropy, __arraycount(entropy), NULL); + assert(strlen(p) == MD2_DIGEST_STRING_LENGTH - 1); + + printf("test7: '%s'\n", p); + + free(p); +} + +int main(void) { + printf("MD2\n"); + + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); + test7(); + + // CHECK: MD2 + // CHECK: test1: 'e303e49b34f981c2740cdf809200d51b' + // CHECK: test2: 'e303e49b34f981c2740cdf809200d51b' + // CHECK: test3: 'e303e49b34f981c2740cdf809200d51b' + // CHECK: test4: '{{.*}}' + // CHECK: test5: '{{.*}}' + // CHECK: test6: 'e303e49b34f981c2740cdf809200d51b' + // CHECK: test7: 'e303e49b34f981c2740cdf809200d51b' + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/md4.cc b/test/sanitizer_common/TestCases/NetBSD/md4.cc new file mode 100644 index 000000000000..a319e89a3519 --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/md4.cc @@ -0,0 +1,114 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <sys/param.h> + +#include <assert.h> +#include <endian.h> +#include <md4.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void test1() { + MD4_CTX ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + uint8_t digest[MD4_DIGEST_LENGTH]; + + MD4Init(&ctx); + MD4Update(&ctx, entropy, __arraycount(entropy)); + MD4Final(digest, &ctx); + + printf("test1: '"); + for (size_t i = 0; i < __arraycount(digest); i++) + printf("%02x", digest[i]); + printf("'\n"); +} + +void test2() { + MD4_CTX ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + char digest[MD4_DIGEST_STRING_LENGTH]; + + MD4Init(&ctx); + MD4Update(&ctx, entropy, __arraycount(entropy)); + char *p = MD4End(&ctx, digest); + assert(p == digest); + + printf("test2: '%s'\n", digest); +} + +void test3() { + MD4_CTX ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + + MD4Init(&ctx); + MD4Update(&ctx, entropy, __arraycount(entropy)); + char *p = MD4End(&ctx, NULL); + assert(strlen(p) == MD4_DIGEST_STRING_LENGTH - 1); + + printf("test3: '%s'\n", p); + + free(p); +} + +void test4() { + char digest[MD4_DIGEST_STRING_LENGTH]; + + char *p = MD4File("/etc/fstab", digest); + assert(p == digest); + + printf("test4: '%s'\n", p); +} + +void test5() { + char *p = MD4File("/etc/fstab", NULL); + assert(strlen(p) == MD4_DIGEST_STRING_LENGTH - 1); + + printf("test5: '%s'\n", p); + + free(p); +} + +void test6() { + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + char digest[MD4_DIGEST_STRING_LENGTH]; + + char *p = MD4Data(entropy, __arraycount(entropy), digest); + assert(p == digest); + + printf("test6: '%s'\n", p); +} + +void test7() { + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + + char *p = MD4Data(entropy, __arraycount(entropy), NULL); + assert(strlen(p) == MD4_DIGEST_STRING_LENGTH - 1); + + printf("test7: '%s'\n", p); + + free(p); +} + +int main(void) { + printf("MD4\n"); + + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); + test7(); + + // CHECK: MD4 + // CHECK: test1: 'bf78fda2ca35eb7a026bfcdd3d17283d' + // CHECK: test2: 'bf78fda2ca35eb7a026bfcdd3d17283d' + // CHECK: test3: 'bf78fda2ca35eb7a026bfcdd3d17283d' + // CHECK: test4: '{{.*}}' + // CHECK: test5: '{{.*}}' + // CHECK: test6: 'bf78fda2ca35eb7a026bfcdd3d17283d' + // CHECK: test7: 'bf78fda2ca35eb7a026bfcdd3d17283d' + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/md5.cc b/test/sanitizer_common/TestCases/NetBSD/md5.cc new file mode 100644 index 000000000000..aee21681800d --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/md5.cc @@ -0,0 +1,114 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <sys/param.h> + +#include <assert.h> +#include <endian.h> +#include <md5.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void test1() { + MD5_CTX ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + uint8_t digest[MD5_DIGEST_LENGTH]; + + MD5Init(&ctx); + MD5Update(&ctx, entropy, __arraycount(entropy)); + MD5Final(digest, &ctx); + + printf("test1: '"); + for (size_t i = 0; i < __arraycount(digest); i++) + printf("%02x", digest[i]); + printf("'\n"); +} + +void test2() { + MD5_CTX ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + char digest[MD5_DIGEST_STRING_LENGTH]; + + MD5Init(&ctx); + MD5Update(&ctx, entropy, __arraycount(entropy)); + char *p = MD5End(&ctx, digest); + assert(p); + + printf("test2: '%s'\n", digest); +} + +void test3() { + MD5_CTX ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + + MD5Init(&ctx); + MD5Update(&ctx, entropy, __arraycount(entropy)); + char *p = MD5End(&ctx, NULL); + assert(strlen(p) == MD5_DIGEST_STRING_LENGTH - 1); + + printf("test3: '%s'\n", p); + + free(p); +} + +void test4() { + char digest[MD5_DIGEST_STRING_LENGTH]; + + char *p = MD5File("/etc/fstab", digest); + assert(p == digest); + + printf("test4: '%s'\n", p); +} + +void test5() { + char *p = MD5File("/etc/fstab", NULL); + assert(strlen(p) == MD5_DIGEST_STRING_LENGTH - 1); + + printf("test5: '%s'\n", p); + + free(p); +} + +void test6() { + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + char digest[MD5_DIGEST_STRING_LENGTH]; + + char *p = MD5Data(entropy, __arraycount(entropy), digest); + assert(p == digest); + + printf("test6: '%s'\n", p); +} + +void test7() { + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + + char *p = MD5Data(entropy, __arraycount(entropy), NULL); + assert(strlen(p) == MD5_DIGEST_STRING_LENGTH - 1); + + printf("test7: '%s'\n", p); + + free(p); +} + +int main(void) { + printf("MD5\n"); + + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); + test7(); + + // CHECK: MD5 + // CHECK: test1: '86e65b1ef4a830af347ac05ab4f0e999' + // CHECK: test2: '86e65b1ef4a830af347ac05ab4f0e999' + // CHECK: test3: '86e65b1ef4a830af347ac05ab4f0e999' + // CHECK: test4: '{{.*}}' + // CHECK: test5: '{{.*}}' + // CHECK: test6: '86e65b1ef4a830af347ac05ab4f0e999' + // CHECK: test7: '86e65b1ef4a830af347ac05ab4f0e999' + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/mi_vector_hash.cc b/test/sanitizer_common/TestCases/NetBSD/mi_vector_hash.cc new file mode 100644 index 000000000000..1f6c14848884 --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/mi_vector_hash.cc @@ -0,0 +1,19 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> + +int main(void) { + unsigned char key[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99}; + uint32_t hashes[3]; + mi_vector_hash(key, __arraycount(key), 0, hashes); + for (size_t i = 0; i < __arraycount(hashes); i++) + printf("hashes[%zu]='%" PRIx32 "'\n", i, hashes[i]); + + // CHECK: hashes[0]='{{.*}}' + // CHECK: hashes[1]='{{.*}}' + // CHECK: hashes[2]='{{.*}}' + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/rmd160.cc b/test/sanitizer_common/TestCases/NetBSD/rmd160.cc new file mode 100644 index 000000000000..5b9ff0cb2e11 --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/rmd160.cc @@ -0,0 +1,133 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <assert.h> +#include <rmd160.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void test1() { + RMD160_CTX ctx; + uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + uint8_t digest[RMD160_DIGEST_LENGTH]; + + RMD160Init(&ctx); + RMD160Update(&ctx, entropy, __arraycount(entropy)); + RMD160Final(digest, &ctx); + + printf("test1: '"); + for (size_t i = 0; i < __arraycount(digest); i++) + printf("%02x", digest[i]); + printf("'\n"); +} + +void test2() { + RMD160_CTX ctx; + uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + char digest[RMD160_DIGEST_STRING_LENGTH]; + + RMD160Init(&ctx); + RMD160Update(&ctx, entropy, __arraycount(entropy)); + char *p = RMD160End(&ctx, digest); + assert(p == digest); + + printf("test2: '%s'\n", digest); +} + +void test3() { + RMD160_CTX ctx; + uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + + RMD160Init(&ctx); + RMD160Update(&ctx, entropy, __arraycount(entropy)); + char *p = RMD160End(&ctx, NULL); + assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1); + + printf("test3: '%s'\n", p); + + free(p); +} + +void test4() { + char digest[RMD160_DIGEST_STRING_LENGTH]; + + char *p = RMD160File("/etc/fstab", digest); + assert(p == digest); + + printf("test4: '%s'\n", p); +} + +void test5() { + char *p = RMD160File("/etc/fstab", NULL); + assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1); + + printf("test5: '%s'\n", p); + + free(p); +} + +void test6() { + char digest[RMD160_DIGEST_STRING_LENGTH]; + + char *p = RMD160FileChunk("/etc/fstab", digest, 10, 20); + assert(p == digest); + + printf("test6: '%s'\n", p); +} + +void test7() { + char *p = RMD160FileChunk("/etc/fstab", NULL, 10, 20); + assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1); + + printf("test7: '%s'\n", p); + + free(p); +} + +void test8() { + uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + char digest[RMD160_DIGEST_STRING_LENGTH]; + + char *p = RMD160Data(entropy, __arraycount(entropy), digest); + assert(p == digest); + + printf("test8: '%s'\n", p); +} + +void test9() { + uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + + char *p = RMD160Data(entropy, __arraycount(entropy), NULL); + assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1); + + printf("test9: '%s'\n", p); + + free(p); +} + +int main(void) { + printf("RMD160\n"); + + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); + test7(); + test8(); + test9(); + + // CHECK: RMD160 + // CHECK: test1: '2787e5a006365df6e8e799315b669dc34866783c' + // CHECK: test2: '2787e5a006365df6e8e799315b669dc34866783c' + // CHECK: test3: '2787e5a006365df6e8e799315b669dc34866783c' + // CHECK: test4: '{{.*}}' + // CHECK: test5: '{{.*}}' + // CHECK: test6: '{{.*}}' + // CHECK: test7: '{{.*}}' + // CHECK: test8: '2787e5a006365df6e8e799315b669dc34866783c' + // CHECK: test9: '2787e5a006365df6e8e799315b669dc34866783c' + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/sha1.cc b/test/sanitizer_common/TestCases/NetBSD/sha1.cc new file mode 100644 index 000000000000..ee5060a6601d --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/sha1.cc @@ -0,0 +1,171 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <assert.h> +#include <sha1.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void test1() { + SHA1_CTX ctx; + uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + uint8_t digest[SHA1_DIGEST_LENGTH]; + + SHA1Init(&ctx); + SHA1Update(&ctx, entropy, __arraycount(entropy)); + SHA1Final(digest, &ctx); + + printf("test1: '"); + for (size_t i = 0; i < __arraycount(digest); i++) + printf("%02x", digest[i]); + printf("'\n"); +} + +void local_SHA1Update(SHA1_CTX *context, const uint8_t *data, unsigned int len) +{ + unsigned int a, b; + + b = context->count[0]; + context->count[0] += len << 3; + if (context->count[0] < b) + context->count[1] += (len >> 29) + 1; + b = (b >> 3) & 63; + if ((b + len) > 63) { + memcpy(&context->buffer[b], data, (a = 64 - b)); + SHA1Transform(context->state, context->buffer); + for ( ; a + 63 < len; a += 64) + SHA1Transform(context->state, &data[a]); + b = 0; + } else { + a = 0; + } + memcpy(&context->buffer[b], &data[a], len - a); +} + +void test2() { + SHA1_CTX ctx; + uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + uint8_t digest[SHA1_DIGEST_LENGTH]; + + SHA1Init(&ctx); + local_SHA1Update(&ctx, entropy, __arraycount(entropy)); + SHA1Final(digest, &ctx); + + printf("test2: '"); + for (size_t i = 0; i < __arraycount(digest); i++) + printf("%02x", digest[i]); + printf("'\n"); +} + +void test3() { + SHA1_CTX ctx; + uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + char digest[SHA1_DIGEST_STRING_LENGTH]; + + SHA1Init(&ctx); + SHA1Update(&ctx, entropy, __arraycount(entropy)); + char *p = SHA1End(&ctx, digest); + assert(p == digest); + + printf("test3: '%s'\n", digest); +} + +void test4() { + SHA1_CTX ctx; + uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + + SHA1Init(&ctx); + SHA1Update(&ctx, entropy, __arraycount(entropy)); + char *p = SHA1End(&ctx, NULL); + assert(strlen(p) == SHA1_DIGEST_STRING_LENGTH - 1); + + printf("test4: '%s'\n", p); + + free(p); +} + +void test5() { + char digest[SHA1_DIGEST_STRING_LENGTH]; + + char *p = SHA1File("/etc/fstab", digest); + assert(p == digest); + + printf("test5: '%s'\n", p); +} + +void test6() { + char *p = SHA1File("/etc/fstab", NULL); + assert(strlen(p) == SHA1_DIGEST_STRING_LENGTH - 1); + + printf("test6: '%s'\n", p); + + free(p); +} + +void test7() { + char digest[SHA1_DIGEST_STRING_LENGTH]; + + char *p = SHA1FileChunk("/etc/fstab", digest, 10, 20); + assert(p == digest); + + printf("test7: '%s'\n", p); +} + +void test8() { + char *p = SHA1FileChunk("/etc/fstab", NULL, 10, 20); + assert(strlen(p) == SHA1_DIGEST_STRING_LENGTH - 1); + + printf("test8: '%s'\n", p); + + free(p); +} + +void test9() { + uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + char digest[SHA1_DIGEST_STRING_LENGTH]; + + char *p = SHA1Data(entropy, __arraycount(entropy), digest); + assert(p == digest); + + printf("test9: '%s'\n", p); +} + +void test10() { + uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + + char *p = SHA1Data(entropy, __arraycount(entropy), NULL); + assert(strlen(p) == SHA1_DIGEST_STRING_LENGTH - 1); + + printf("test10: '%s'\n", p); + + free(p); +} + +int main(void) { + printf("SHA1\n"); + + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); + test7(); + test8(); + test9(); + test10(); + + // CHECK: SHA1 + // CHECK: test1: '57d1b759bf3d1811135748cb0328c73b51fa6f57' + // CHECK: test2: '57d1b759bf3d1811135748cb0328c73b51fa6f57' + // CHECK: test3: '57d1b759bf3d1811135748cb0328c73b51fa6f57' + // CHECK: test4: '57d1b759bf3d1811135748cb0328c73b51fa6f57' + // CHECK: test5: '{{.*}}' + // CHECK: test6: '{{.*}}' + // CHECK: test7: '{{.*}}' + // CHECK: test8: '{{.*}}' + // CHECK: test9: '57d1b759bf3d1811135748cb0328c73b51fa6f57' + // CHECK: test10: '57d1b759bf3d1811135748cb0328c73b51fa6f57' + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/sha2.cc b/test/sanitizer_common/TestCases/NetBSD/sha2.cc new file mode 100644 index 000000000000..e905e3b610fd --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/sha2.cc @@ -0,0 +1,206 @@ +// RUN: %clangxx -O0 -g %s -DSHASIZE=224 -o %t && %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-224 +// RUN: %clangxx -O0 -g %s -DSHASIZE=256 -o %t && %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-256 +// RUN: %clangxx -O0 -g %s -DSHASIZE=384 -o %t && %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-384 +// RUN: %clangxx -O0 -g %s -DSHASIZE=512 -o %t && %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-512 + +#include <sys/param.h> + +#include <assert.h> +#include <endian.h> +#include <sha2.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#ifndef SHASIZE +#error SHASIZE must be defined +#endif + +#define _SHA_CTX(x) SHA##x##_CTX +#define SHA_CTX(x) _SHA_CTX(x) + +#define _SHA_DIGEST_LENGTH(x) SHA##x##_DIGEST_LENGTH +#define SHA_DIGEST_LENGTH(x) _SHA_DIGEST_LENGTH(x) + +#define _SHA_DIGEST_STRING_LENGTH(x) SHA##x##_DIGEST_STRING_LENGTH +#define SHA_DIGEST_STRING_LENGTH(x) _SHA_DIGEST_STRING_LENGTH(x) + +#define _SHA_Init(x) SHA##x##_Init +#define SHA_Init(x) _SHA_Init(x) + +#define _SHA_Update(x) SHA##x##_Update +#define SHA_Update(x) _SHA_Update(x) + +#define _SHA_Final(x) SHA##x##_Final +#define SHA_Final(x) _SHA_Final(x) + +#define _SHA_End(x) SHA##x##_End +#define SHA_End(x) _SHA_End(x) + +#define _SHA_File(x) SHA##x##_File +#define SHA_File(x) _SHA_File(x) + +#define _SHA_FileChunk(x) SHA##x##_FileChunk +#define SHA_FileChunk(x) _SHA_FileChunk(x) + +#define _SHA_Data(x) SHA##x##_Data +#define SHA_Data(x) _SHA_Data(x) + +void test1() { + SHA_CTX(SHASIZE) ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + uint8_t digest[SHA_DIGEST_LENGTH(SHASIZE)]; + + SHA_Init(SHASIZE)(&ctx); + SHA_Update(SHASIZE)(&ctx, entropy, __arraycount(entropy)); + SHA_Final(SHASIZE)(digest, &ctx); + + printf("test1: '"); + for (size_t i = 0; i < __arraycount(digest); i++) + printf("%02x", digest[i]); + printf("'\n"); +} + +void test2() { + SHA_CTX(SHASIZE) ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + char digest[SHA_DIGEST_STRING_LENGTH(SHASIZE)]; + + SHA_Init(SHASIZE)(&ctx); + SHA_Update(SHASIZE)(&ctx, entropy, __arraycount(entropy)); + char *p = SHA_End(SHASIZE)(&ctx, digest); + assert(p == digest); + + printf("test2: '%s'\n", digest); +} + +void test3() { + SHA_CTX(SHASIZE) ctx; + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + + SHA_Init(SHASIZE)(&ctx); + SHA_Update(SHASIZE)(&ctx, entropy, __arraycount(entropy)); + char *p = SHA_End(SHASIZE)(&ctx, NULL); + assert(strlen(p) == SHA_DIGEST_STRING_LENGTH(SHASIZE) - 1); + + printf("test3: '%s'\n", p); + + free(p); +} + +void test4() { + char digest[SHA_DIGEST_STRING_LENGTH(SHASIZE)]; + + char *p = SHA_File(SHASIZE)("/etc/fstab", digest); + assert(p == digest); + + printf("test4: '%s'\n", p); +} + +void test5() { + char *p = SHA_File(SHASIZE)("/etc/fstab", NULL); + assert(strlen(p) == SHA_DIGEST_STRING_LENGTH(SHASIZE) - 1); + + printf("test5: '%s'\n", p); + + free(p); +} + +void test6() { + char digest[SHA_DIGEST_STRING_LENGTH(SHASIZE)]; + + char *p = SHA_FileChunk(SHASIZE)("/etc/fstab", digest, 10, 20); + assert(p == digest); + + printf("test6: '%s'\n", p); +} + +void test7() { + char *p = SHA_FileChunk(SHASIZE)("/etc/fstab", NULL, 10, 20); + assert(strlen(p) == SHA_DIGEST_STRING_LENGTH(SHASIZE) - 1); + + printf("test7: '%s'\n", p); + + free(p); +} + +void test8() { + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + char digest[SHA_DIGEST_STRING_LENGTH(SHASIZE)]; + + char *p = SHA_Data(SHASIZE)(entropy, __arraycount(entropy), digest); + assert(p == digest); + + printf("test8: '%s'\n", p); +} + +void test9() { + uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + + char *p = SHA_Data(SHASIZE)(entropy, __arraycount(entropy), NULL); + assert(strlen(p) == SHA_DIGEST_STRING_LENGTH(SHASIZE) - 1); + + printf("test9: '%s'\n", p); + + free(p); +} + +int main(void) { + printf("SHA" ___STRING(SHASIZE) "\n"); + + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); + test7(); + test8(); + test9(); + + // CHECK-224: SHA224 + // CHECK-224: test1: '760dfb93100a6bf5996c90f678e529dc945bb2f74a211eedcf0f3a48' + // CHECK-224: test2: '760dfb93100a6bf5996c90f678e529dc945bb2f74a211eedcf0f3a48' + // CHECK-224: test3: '760dfb93100a6bf5996c90f678e529dc945bb2f74a211eedcf0f3a48' + // CHECK-224: test4: '{{.*}}' + // CHECK-224: test5: '{{.*}}' + // CHECK-224: test6: '{{.*}}' + // CHECK-224: test7: '{{.*}}' + // CHECK-224: test8: '760dfb93100a6bf5996c90f678e529dc945bb2f74a211eedcf0f3a48' + // CHECK-224: test9: '760dfb93100a6bf5996c90f678e529dc945bb2f74a211eedcf0f3a48' + + // CHECK-256: SHA256 + // CHECK-256: test1: 'bb000ddd92a0a2a346f0b531f278af06e370f86932ccafccc892d68d350f80f8' + // CHECK-256: test2: 'bb000ddd92a0a2a346f0b531f278af06e370f86932ccafccc892d68d350f80f8' + // CHECK-256: test3: 'bb000ddd92a0a2a346f0b531f278af06e370f86932ccafccc892d68d350f80f8' + // CHECK-256: test4: '{{.*}}' + // CHECK-256: test5: '{{.*}}' + // CHECK-256: test6: '{{.*}}' + // CHECK-256: test7: '{{.*}}' + // CHECK-256: test8: 'bb000ddd92a0a2a346f0b531f278af06e370f86932ccafccc892d68d350f80f8' + // CHECK-256: test9: 'bb000ddd92a0a2a346f0b531f278af06e370f86932ccafccc892d68d350f80f8' + + // CHECK-384: SHA384 + // CHECK-384: test1: 'f450c023b168ebd56ff916ca9b1f1f0010b8c592d28205cc91fa3056f629eed108e8bac864f01ca37a3edee596739e12' + // CHECK-384: test2: 'f450c023b168ebd56ff916ca9b1f1f0010b8c592d28205cc91fa3056f629eed108e8bac864f01ca37a3edee596739e12' + // CHECK-384: test3: 'f450c023b168ebd56ff916ca9b1f1f0010b8c592d28205cc91fa3056f629eed108e8bac864f01ca37a3edee596739e12' + // CHECK-384: test4: '{{.*}}' + // CHECK-384: test5: '{{.*}}' + // CHECK-384: test6: '{{.*}}' + // CHECK-384: test7: '{{.*}}' + // CHECK-384: test8: 'f450c023b168ebd56ff916ca9b1f1f0010b8c592d28205cc91fa3056f629eed108e8bac864f01ca37a3edee596739e12' + // CHECK-384: test9: 'f450c023b168ebd56ff916ca9b1f1f0010b8c592d28205cc91fa3056f629eed108e8bac864f01ca37a3edee596739e12' + + // CHECK-512: SHA512 + // CHECK-512: test1: '0e3f68731c0e2a6a4eab5d713c9a80dc78086b5fa7d2b5ab127277958e68d1b1dee1882b083b0106cd4319de42c0c8f452871364f5baa8a6379690612c6b844e' + // CHECK-512: test2: '0e3f68731c0e2a6a4eab5d713c9a80dc78086b5fa7d2b5ab127277958e68d1b1dee1882b083b0106cd4319de42c0c8f452871364f5baa8a6379690612c6b844e' + // CHECK-512: test3: '0e3f68731c0e2a6a4eab5d713c9a80dc78086b5fa7d2b5ab127277958e68d1b1dee1882b083b0106cd4319de42c0c8f452871364f5baa8a6379690612c6b844e' + // CHECK-512: test4: '{{.*}}' + // CHECK-512: test5: '{{.*}}' + // CHECK-512: test6: '{{.*}}' + // CHECK-512: test7: '{{.*}}' + // CHECK-512: test8: '0e3f68731c0e2a6a4eab5d713c9a80dc78086b5fa7d2b5ab127277958e68d1b1dee1882b083b0106cd4319de42c0c8f452871364f5baa8a6379690612c6b844e' + // CHECK-512: test9: '0e3f68731c0e2a6a4eab5d713c9a80dc78086b5fa7d2b5ab127277958e68d1b1dee1882b083b0106cd4319de42c0c8f452871364f5baa8a6379690612c6b844e' + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/statvfs1.cc b/test/sanitizer_common/TestCases/NetBSD/statvfs1.cc new file mode 100644 index 000000000000..40dfca37bb58 --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/statvfs1.cc @@ -0,0 +1,58 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <sys/param.h> +#include <sys/types.h> + +#include <sys/statvfs.h> + +#include <assert.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +void test_statvfs1() { + printf("statvfs1\n"); + + struct statvfs buf; + int rv = statvfs1("/etc/fstab", &buf, ST_WAIT); + assert(rv != -1); + + printf("fstypename='%s'\n", buf.f_fstypename); + printf("mntonname='%s'\n", buf.f_mntonname); + printf("mntfromname='%s'\n", buf.f_mntfromname); +} + +void test_fstatvfs1() { + printf("fstatvfs1\n"); + + int fd = open("/etc/fstab", O_RDONLY); + assert(fd > 0); + + struct statvfs buf; + int rv = fstatvfs1(fd, &buf, ST_WAIT); + assert(rv != -1); + + printf("fstypename='%s'\n", buf.f_fstypename); + printf("mntonname='%s'\n", buf.f_mntonname); + printf("mntfromname='%s'\n", buf.f_mntfromname); + + rv = close(fd); + assert(rv != -1); +} + +int main(void) { + test_statvfs1(); + test_fstatvfs1(); + + // CHECK: statvfs1 + // CHECK: fstypename='{{.*}}' + // CHECK: mntonname='{{.*}}' + // CHECK: mntfromname='{{.*}}' + // CHECK: fstatvfs1 + // CHECK: fstypename='{{.*}}' + // CHECK: mntonname='{{.*}}' + // CHECK: mntfromname='{{.*}}' + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/strtoi.cc b/test/sanitizer_common/TestCases/NetBSD/strtoi.cc new file mode 100644 index 000000000000..4d0d8b3aebf0 --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/strtoi.cc @@ -0,0 +1,43 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <inttypes.h> +#include <stdio.h> + +void test_strtoi(const char *nptr, int base, intmax_t lo, intmax_t hi) { + char *p; + int status; + intmax_t i = strtoi(nptr, &p, base, lo, hi, &status); + printf("strtoi: conversion of '%s' to a number %s, using %jd, p=%#" PRIx8 + "\n", + nptr, status ? "failed" : "successful", i, *p); +} + +void test_strtou(const char *nptr, int base, intmax_t lo, intmax_t hi) { + char *p; + int status; + uintmax_t i = strtou(nptr, &p, base, lo, hi, &status); + printf("strtou: conversion of '%s' to a number %s, using %ju, p=%#" PRIx8 + "\n", + nptr, status ? "failed" : "successful", i, *p); +} + +int main(void) { + printf("strtoi\n"); + + test_strtoi("100", 0, 1, 100); + test_strtoi("100", 0, 1, 10); + test_strtoi("100xyz", 0, 1, 100); + test_strtou("100", 0, 1, 100); + test_strtou("100", 0, 1, 10); + test_strtou("100xyz", 0, 1, 100); + + // CHECK: strtoi + // CHECK: strtoi: conversion of '100' to a number successful, using 100, p=0 + // CHECK: strtoi: conversion of '100' to a number failed, using 10, p=0 + // CHECK: strtoi: conversion of '100xyz' to a number failed, using 100, p=0x78 + // CHECK: strtou: conversion of '100' to a number successful, using 100, p=0 + // CHECK: strtou: conversion of '100' to a number failed, using 10, p=0 + // CHECK: strtou: conversion of '100xyz' to a number failed, using 100, p=0x78 + + return 0; +} diff --git a/test/sanitizer_common/TestCases/NetBSD/sysctlgetmibinfo.cc b/test/sanitizer_common/TestCases/NetBSD/sysctlgetmibinfo.cc new file mode 100644 index 000000000000..d81c1567fc44 --- /dev/null +++ b/test/sanitizer_common/TestCases/NetBSD/sysctlgetmibinfo.cc @@ -0,0 +1,36 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <sys/param.h> +#include <sys/types.h> + +#include <sys/sysctl.h> + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +void test_sysctlgetmibinfo() { + int mib[CTL_MAXNAME]; + unsigned int mib_len = __arraycount(mib); + int rv = sysctlgetmibinfo("kern.ostype", &mib[0], &mib_len, NULL, NULL, NULL, + SYSCTL_VERSION); + assert(!rv); + + char buf[100]; + size_t len = sizeof(buf); + rv = sysctl(mib, mib_len, buf, &len, NULL, 0); + assert(!rv); + + printf("sysctlgetmibinfo: '%s' size: '%zu'\n", buf, len); +} + +int main(void) { + printf("sysctlgetmibinfo\n"); + + test_sysctlgetmibinfo(); + + return 0; + + // CHECK: sysctlgetmibinfo + // CHECK: sysctlgetmibinfo: '{{.*}}' size: '{{.*}}' +} diff --git a/test/sanitizer_common/TestCases/Posix/arc4random.cc b/test/sanitizer_common/TestCases/Posix/arc4random.cc new file mode 100644 index 000000000000..0a983b58f59f --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/arc4random.cc @@ -0,0 +1,71 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, darwin, solaris + +#include <cstdlib> +#include <ctime> +#include <cstdio> +#include <inttypes.h> + +void print_buf(unsigned char *buf, size_t buflen) { + printf("buf '"); + for (auto i = 0; i < buflen; i ++) + printf("%" PRIx8, buf[i]); + printf("'\n"); +} + +void test_seed() { +#ifdef __NetBSD__ + time_t now = ::time(nullptr); + arc4random_addrandom((unsigned char *)&now, sizeof(now)); +#endif +} + +void test_arc4random() { + printf("test_arc4random\n"); + auto i = arc4random(); + print_buf((unsigned char *)&i, sizeof(i)); +} + +void test_arc4random_uniform() { + printf("test_arc4random_uniform\n"); + auto i = arc4random_uniform(1024); + print_buf((unsigned char *)&i, sizeof(i)); +} + +void test_arc4random_buf10() { + printf("test_arc4random_buf10\n"); + char buf[10]; +#ifdef __NetBSD__ + arc4random_stir(); +#endif + arc4random_buf(buf, sizeof(buf)); + print_buf((unsigned char *)buf, sizeof(buf)); +} + +void test_arc4random_buf256() { + printf("test_arc4random_buf256\n"); + char buf[256]; +#ifdef __NetBSD__ + arc4random_stir(); +#endif + arc4random_buf(buf, sizeof(buf)); + print_buf((unsigned char *)buf, sizeof(buf)); +} + +int main(void) { + test_seed(); + test_arc4random(); + test_arc4random_uniform(); + test_arc4random_buf10(); + test_arc4random_buf256(); + return 0; + // CHECK: test_arc4random + // CHECK: buf '{{.*}}' + // CHECK: test_arc4random_uniform + // CHECK: buf '{{.*}}' + // CHECK: test_arc4random_buf10 + // CHECK: buf '{{.*}}' + // CHECK: test_arc4random_buf256 + // CHECK: buf '{{.*}}' +} diff --git a/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc b/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc index d9a1bc66082c..94c50be169b4 100644 --- a/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc +++ b/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc @@ -8,6 +8,8 @@ // REQUIRES: stable-runtime +// XFAIL: netbsd && !asan + volatile int *null = 0; namespace Xyz { diff --git a/test/sanitizer_common/TestCases/Posix/devname.cc b/test/sanitizer_common/TestCases/Posix/devname.cc index da4bb8853a12..1495f7d9d518 100644 --- a/test/sanitizer_common/TestCases/Posix/devname.cc +++ b/test/sanitizer_common/TestCases/Posix/devname.cc @@ -1,6 +1,7 @@ // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s // UNSUPPORTED: linux, solaris +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> @@ -9,11 +10,8 @@ int main(void) { struct stat st; char *name; - if (stat("/dev/null", &st)) - exit(1); - - if (!(name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK))) - exit(1); + assert(!stat("/dev/null", &st)); + assert((name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK))); printf("%s\n", name); diff --git a/test/sanitizer_common/TestCases/Posix/devname_r.cc b/test/sanitizer_common/TestCases/Posix/devname_r.cc index 826b7c92ef2f..ae10a766271e 100644 --- a/test/sanitizer_common/TestCases/Posix/devname_r.cc +++ b/test/sanitizer_common/TestCases/Posix/devname_r.cc @@ -4,6 +4,7 @@ #include <sys/cdefs.h> #include <sys/stat.h> +#include <assert.h> #include <stdio.h> #include <stdlib.h> @@ -12,13 +13,15 @@ int main(void) { char name[100]; mode_t type; - if (stat("/dev/null", &st)) - exit(1); + assert(!stat("/dev/null", &st)); type = S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK; - if (!devname_r(st.st_rdev, type, name, sizeof(name))) - exit(1); +#if defined(__NetBSD__) + assert(!devname_r(st.st_rdev, type, name, sizeof(name))); +#else + assert(devname_r(st.st_rdev, type, name, sizeof(name))); +#endif printf("%s\n", name); diff --git a/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc b/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc index 87e797a00ae1..f42802a34582 100644 --- a/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc +++ b/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc @@ -1,11 +1,9 @@ // Check that sanitizer prints the faulting instruction bytes on // dump_instruction_bytes=1 -// clang-format off // RUN: %clangxx %s -o %t // RUN: %env_tool_opts=dump_instruction_bytes=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-DUMP // RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NODUMP -// clang-format on // REQUIRES: x86-target-arch diff --git a/test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc b/test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc new file mode 100644 index 000000000000..cfcf0e3970a4 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc @@ -0,0 +1,41 @@ +// RUN: %clangxx -g %s -o %t && %run %t + +#include <assert.h> +#include <stdio.h> +#include <unistd.h> + +int main(int argc, char **argv) { + FILE *fp = fopen(argv[0], "r"); + assert(fp); + + // file should be good upon opening + assert(!feof(fp) && !ferror(fp)); + + // read until EOF + char buf[BUFSIZ]; + while (fread(buf, 1, sizeof buf, fp) != 0) {} + assert(feof(fp)); + + // clear EOF + clearerr(fp); + assert(!feof(fp) && !ferror(fp)); + + // get file descriptor + int fd = fileno(fp); + assert(fd != -1); + + // break the file by closing underlying descriptor + assert(close(fd) != -1); + + // verify that an error is signalled + assert(fread(buf, 1, sizeof buf, fp) == 0); + assert(ferror(fp)); + + // clear error + clearerr(fp); + assert(!feof(fp) && !ferror(fp)); + + // fclose() will return EBADF because of closed fd + assert(fclose(fp) == -1); + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc b/test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc new file mode 100644 index 000000000000..f895cf194ce7 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc @@ -0,0 +1,19 @@ +// RUN: %clangxx -g %s -o %t && %run %t + +#include <assert.h> +#include <stdio.h> + +int main(int argc, char **argv) { + FILE *fp = fopen(argv[0], "r"); + assert(fp); + + // the file should be at least one character long, always + assert(fgetc(fp) != EOF); + // POSIX guarantees being able to ungetc() at least one character + assert(ungetc('X', fp) != EOF); + // check whether ungetc() worked + assert(getc(fp) == 'X'); + + assert(!fclose(fp)); + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/fgetln.cc b/test/sanitizer_common/TestCases/Posix/fgetln.cc index e98cf449a272..b1b4665389a3 100644 --- a/test/sanitizer_common/TestCases/Posix/fgetln.cc +++ b/test/sanitizer_common/TestCases/Posix/fgetln.cc @@ -1,24 +1,20 @@ // RUN: %clangxx -O0 -g %s -o %t && %run %t // UNSUPPORTED: linux +#include <assert.h> #include <stdio.h> #include <stdlib.h> int main(void) { - FILE *fp; - size_t len; - char *s; - - fp = fopen("/etc/hosts", "r"); - if (!fp) - exit(1); + FILE *fp = fopen("/etc/hosts", "r"); + assert(fp); - s = fgetln(fp, &len); + size_t len; + char *s = fgetln(fp, &len); printf("%.*s\n", (int)len, s); - if (fclose(fp) == EOF) - exit(1); + assert(!fclose(fp)); return 0; } diff --git a/test/sanitizer_common/TestCases/Posix/fgets.cc b/test/sanitizer_common/TestCases/Posix/fgets.cc index 8dde5cd1a84f..6a639f8047db 100644 --- a/test/sanitizer_common/TestCases/Posix/fgets.cc +++ b/test/sanitizer_common/TestCases/Posix/fgets.cc @@ -1,20 +1,16 @@ // RUN: %clangxx -g %s -o %t && %run %t +#include <assert.h> #include <stdio.h> int main(int argc, char **argv) { - FILE *fp; - char buf[2]; - char *s; - - fp = fopen(argv[0], "r"); - if (!fp) - return 1; + FILE *fp = fopen(argv[0], "r"); + assert(fp); - s = fgets(buf, sizeof(buf), fp); - if (!s) - return 2; + char buf[2]; + char *s = fgets(buf, sizeof(buf), fp); + assert(s); - fclose(fp); + assert(!fclose(fp)); return 0; } diff --git a/test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc b/test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc new file mode 100644 index 000000000000..7e786cd9ef37 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/fputc_putc_putchar.cc @@ -0,0 +1,13 @@ +// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s +// CHECK: abc + +#include <assert.h> +#include <stdio.h> + +int main(void) { + assert(fputc('a', stdout) != EOF); + assert(putc('b', stdout) != EOF); + assert(putchar('c') != EOF); + + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/fputs_puts.cc b/test/sanitizer_common/TestCases/Posix/fputs_puts.cc index 8e8f7d384e8c..21bb93aa4310 100644 --- a/test/sanitizer_common/TestCases/Posix/fputs_puts.cc +++ b/test/sanitizer_common/TestCases/Posix/fputs_puts.cc @@ -1,18 +1,12 @@ // RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s // CHECK: {{^foobar$}} +#include <assert.h> #include <stdio.h> int main(void) { - int r; - - r = fputs("foo", stdout); - if (r < 0) - return 1; - - r = puts("bar"); - if (r < 0) - return 1; + assert(fputs("foo", stdout) >= 0); + assert(puts("bar") >= 0); return 0; } diff --git a/test/sanitizer_common/TestCases/Posix/fseek.cc b/test/sanitizer_common/TestCases/Posix/fseek.cc new file mode 100644 index 000000000000..26f3b849f4c4 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/fseek.cc @@ -0,0 +1,53 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, darwin, solaris + +#include <assert.h> +#include <inttypes.h> +#include <stdio.h> + +int main(void) { + printf("fseek\n"); + + FILE *fp = fopen("/etc/fstab", "r"); + assert(fp); + + int rv = fseek(fp, 10, SEEK_SET); + assert(!rv); + + printf("position: %ld\n", ftell(fp)); + + rewind(fp); + + printf("position: %ld\n", ftell(fp)); + + rv = fseeko(fp, 15, SEEK_SET); + assert(!rv); + + printf("position: %" PRIuMAX "\n", (uintmax_t)ftello(fp)); + + fpos_t pos; + rv = fgetpos(fp, &pos); + assert(!rv); + + rewind(fp); + + printf("position: %" PRIuMAX "\n", (uintmax_t)ftello(fp)); + + rv = fsetpos(fp, &pos); + assert(!rv); + + printf("position: %" PRIuMAX "\n", (uintmax_t)ftello(fp)); + + rv = fclose(fp); + assert(!rv); + + // CHECK: fseek + // CHECK: position: 10 + // CHECK: position: 0 + // CHECK: position: 15 + // CHECK: position: 0 + // CHECK: position: 15 + + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/fts.cc b/test/sanitizer_common/TestCases/Posix/fts.cc new file mode 100644 index 000000000000..79c41f7de674 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/fts.cc @@ -0,0 +1,42 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, darwin, solaris + +#include <sys/param.h> +#include <sys/types.h> + +#include <sys/stat.h> + +#include <assert.h> +#include <fts.h> +#include <stdio.h> +#include <stdlib.h> + +int main() { + char *const paths[] = {(char *)"/etc", 0}; + FTS *ftsp = fts_open(paths, FTS_LOGICAL, NULL); + assert(ftsp); + + FTSENT *chp = fts_children(ftsp, 0); + assert(chp); + + size_t n = 0; + for (FTSENT *p = fts_read(ftsp); p; p = fts_read(ftsp)) { + /* Skip recursively subdirectories */ + if (p->fts_info == FTS_D && p->fts_level != FTS_ROOTLEVEL) /* pre-order */ + fts_set(ftsp, p, FTS_SKIP); + else if (p->fts_info == FTS_DP) /* post-order */ + continue; + else if (p->fts_info == FTS_F) /* regular file */ + n++; + } + + int rv = fts_close(ftsp); + assert(!rv); + + printf("Number of files in /etc: '%zu'\n", n); + + return EXIT_SUCCESS; + + // CHECK: Number of files in /etc: '{{.*}}' +} diff --git a/test/sanitizer_common/TestCases/Posix/funopen.cc b/test/sanitizer_common/TestCases/Posix/funopen.cc new file mode 100644 index 000000000000..7d3192488ec5 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/funopen.cc @@ -0,0 +1,91 @@ +// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s + +// CHECK: READ CALLED; len={{[0-9]*}} +// CHECK-NEXT: READ: test +// CHECK-NEXT: WRITE CALLED: test +// CHECK-NEXT: READ CALLED; len={{[0-9]*}} +// CHECK-NEXT: READ: test +// CHECK-NEXT: WRITE CALLED: test +// CHECK-NEXT: CLOSE CALLED +// CHECK-NEXT: SEEK CALLED; off=100, whence=0 +// CHECK-NEXT: READ CALLED; len={{[0-9]*}} +// CHECK-NEXT: READ: test +// +// UNSUPPORTED: linux, darwin, solaris + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int cookie_var; + +int f_read(void *cookie, char *buf, int len) { + assert(cookie == &cookie_var); + assert(len >= 6); + printf("READ CALLED; len=%d\n", len); + return strlcpy(buf, "test\n", len); +} + +int f_write(void *cookie, const char *buf, int len) { + assert(cookie == &cookie_var); + char *data = strndup(buf, len); + assert(data); + printf("WRITE CALLED: %s\n", data); + free(data); + return len; +} + +off_t f_seek(void *cookie, off_t off, int whence) { + assert(cookie == &cookie_var); + assert(whence == SEEK_SET); + printf("SEEK CALLED; off=%d, whence=%d\n", (int)off, whence); + return off; +} + +int f_close(void *cookie) { + assert(cookie == &cookie_var); + printf("CLOSE CALLED\n"); + return 0; +} + +int main(void) { + FILE *fp; + char buf[10]; + + // 1. read-only variant + fp = fropen(&cookie_var, f_read); + assert(fp); + // verify that fileno() does not crash or report nonsense + assert(fileno(fp) == -1); + assert(fgets(buf, sizeof(buf), fp)); + printf("READ: %s", buf); + assert(!fclose(fp)); + + // 2. write-only variant + fp = fwopen(&cookie_var, f_write); + assert(fp); + assert(fileno(fp) == -1); + assert(fputs("test", fp) >= 0); + assert(!fclose(fp)); + + // 3. read+write+close + fp = funopen(&cookie_var, f_read, f_write, NULL, f_close); + assert(fp); + assert(fileno(fp) == -1); + assert(fgets(buf, sizeof(buf), fp)); + printf("READ: %s", buf); + assert(fputs("test", fp) >= 0); + assert(!fclose(fp)); + + // 4. read+seek + fp = funopen(&cookie_var, f_read, NULL, f_seek, NULL); + assert(fp); + assert(fileno(fp) == -1); + assert(fseek(fp, 100, SEEK_SET) == 0); + assert(fgets(buf, sizeof(buf), fp)); + printf("READ: %s", buf); + assert(!fclose(fp)); + + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/getc_unlocked.cc b/test/sanitizer_common/TestCases/Posix/getc_unlocked.cc new file mode 100644 index 000000000000..c4257d130428 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/getc_unlocked.cc @@ -0,0 +1,20 @@ +// RUN: %clangxx -g %s -o %t && %run %t + +#include <assert.h> +#include <stdio.h> + +int main(int argc, char **argv) { + FILE *fp = fopen(argv[0], "r"); + assert(fp); + + // the file should be at least one character long, always + assert(getc_unlocked(fp) != EOF); + // POSIX guarantees being able to ungetc() at least one character + // NB: ungetc_unlocked is apparently not present + assert(ungetc('X', fp) != EOF); + // check whether ungetc() works with getc_unlocked() + assert(getc_unlocked(fp) == 'X'); + + assert(!fclose(fp)); + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/getfsent.cc b/test/sanitizer_common/TestCases/Posix/getfsent.cc new file mode 100644 index 000000000000..687a7a7d4879 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/getfsent.cc @@ -0,0 +1,36 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, darwin, solaris + +#include <assert.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <fstab.h> + +int main(void) { + printf("getfsent\n"); + + setfsent(); + struct fstab *fentry = getfsent(); + + assert(fentry); + + setfsent(); + struct fstab *pentry = getfsspec(fentry->fs_spec); + assert(pentry); + setfsent(); + struct fstab *wentry = getfsfile(fentry->fs_file); + assert(wentry); + assert(!memcmp(fentry, wentry, sizeof(*wentry))); + assert(!memcmp(pentry, wentry, sizeof(*pentry))); + + printf("First entry: device block '%s', mounted with '%s'\n", + fentry->fs_spec, fentry->fs_mntops); + + endfsent(); + + return 0; + // CHECK: getfsent + // CHECK: First entry: device block '{{.*}}', mounted with '{{.*}}' +} diff --git a/test/sanitizer_common/TestCases/Posix/getmntinfo.cc b/test/sanitizer_common/TestCases/Posix/getmntinfo.cc new file mode 100644 index 000000000000..26c065d4dd1f --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/getmntinfo.cc @@ -0,0 +1,35 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, solaris + +#include <sys/types.h> + +#if defined(__NetBSD__) +#include <sys/statvfs.h> +#else +#include <sys/mount.h> +#endif + +#include <err.h> +#include <stdio.h> +#include <stdlib.h> + +int main(void) { + printf("getmntinfo\n"); + +#if defined(__NetBSD__) + struct statvfs *fss; +#else + struct statfs *fss; +#endif + int nfss = getmntinfo(&fss, MNT_NOWAIT); + if (nfss <= 0) + errx(1, "getmntinfo"); + + for (int i = 0; i < nfss; i++) + printf("%d: %s\n", i, fss[i].f_fstypename); + + // CHECK: getmntinfo + + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/getusershell.cc b/test/sanitizer_common/TestCases/Posix/getusershell.cc new file mode 100644 index 000000000000..c00d75f11211 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/getusershell.cc @@ -0,0 +1,23 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +// UNSUPPORTED: android + +#include <assert.h> +#include <errno.h> +#include <stdio.h> +#include <unistd.h> + +int main(void) { + printf("getusershell\n"); + + setusershell(); + char *fentry = getusershell(); + + printf("First entry: '%s'\n", fentry); + + endusershell(); + + return 0; + // CHECK: getusershell + // CHECK: First entry: '{{.*}}' +} diff --git a/test/sanitizer_common/TestCases/Posix/lstat.cc b/test/sanitizer_common/TestCases/Posix/lstat.cc index 37237d82102c..01c2ea83d9c1 100644 --- a/test/sanitizer_common/TestCases/Posix/lstat.cc +++ b/test/sanitizer_common/TestCases/Posix/lstat.cc @@ -1,16 +1,14 @@ // RUN: %clangxx -O0 -g %s -o %t && %run %t +#include <assert.h> #include <stdlib.h> #include <sys/stat.h> int main(void) { struct stat st; - if (lstat("/dev/null", &st)) - exit(1); - - if (!S_ISCHR(st.st_mode)) - exit(1); + assert(!lstat("/dev/null", &st)); + assert(S_ISCHR(st.st_mode)); return 0; } diff --git a/test/sanitizer_common/TestCases/Posix/nl_langinfo.cc b/test/sanitizer_common/TestCases/Posix/nl_langinfo.cc new file mode 100644 index 000000000000..b8123542fb8f --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/nl_langinfo.cc @@ -0,0 +1,20 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, darwin, solaris + +#include <langinfo.h> + +#include <stdio.h> + +int main(void) { + printf("nl_langinfo\n"); + + char *info = nl_langinfo(DAY_1); + + printf("DAY_1='%s'\n", info); + + // CHECK: nl_langinfo + // CHECK: DAY_1='{{.*}}' + + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/popen.cc b/test/sanitizer_common/TestCases/Posix/popen.cc new file mode 100644 index 000000000000..6bf6255a697a --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/popen.cc @@ -0,0 +1,23 @@ +// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s +// CHECK: 1 +// CHECK-NEXT: 2 + +#include <assert.h> +#include <stdio.h> + +int main(void) { + // use a tool that produces different output than input to verify + // that everything worked correctly + FILE *fp = popen("sort", "w"); + assert(fp); + + // verify that fileno() returns a meaningful descriptor (needed + // for the implementation of TSan) + assert(fileno(fp) != -1); + + assert(fputs("2\n", fp) >= 0); + assert(fputs("1\n", fp) >= 0); + assert(pclose(fp) == 0); + + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc b/test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc new file mode 100644 index 000000000000..12c35c220d97 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/putc_putchar_unlocked.cc @@ -0,0 +1,12 @@ +// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s +// CHECK: bc + +#include <assert.h> +#include <stdio.h> + +int main(void) { + assert(putc_unlocked('b', stdout) != EOF); + assert(putchar_unlocked('c') != EOF); + + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/readlinkat.c b/test/sanitizer_common/TestCases/Posix/readlinkat.c index 0afb5efe6b5f..227c6da54afb 100644 --- a/test/sanitizer_common/TestCases/Posix/readlinkat.c +++ b/test/sanitizer_common/TestCases/Posix/readlinkat.c @@ -1,5 +1,7 @@ // RUN: %clang -O0 %s -o %t && %run %t +// XFAIL: i386-netbsd && asan + #include <assert.h> #include <fcntl.h> #include <limits.h> diff --git a/test/sanitizer_common/TestCases/Posix/regex.cc b/test/sanitizer_common/TestCases/Posix/regex.cc new file mode 100644 index 000000000000..3727f01325f8 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/regex.cc @@ -0,0 +1,71 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: darwin, solaris + +#include <assert.h> +#include <regex.h> +#include <stdio.h> +#include <stdlib.h> + +#ifndef __arraycount +#define __arraycount(a) ((sizeof(a) / sizeof(a[0]))) +#endif + +void test_matched(const regex_t *preg, const char *string) { + int rv = regexec(preg, string, 0, NULL, 0); + if (!rv) + printf("%s: matched\n", string); + else if (rv == REG_NOMATCH) + printf("%s: not-matched\n", string); + else + abort(); +} + +void test_print_matches(const regex_t *preg, const char *string) { + regmatch_t rm[10]; + int rv = regexec(preg, string, __arraycount(rm), rm, 0); + if (!rv) { + for (size_t i = 0; i < __arraycount(rm); i++) { + // This condition shall be simplified, but verify that the data fields + // are accessible. + if (rm[i].rm_so == -1 && rm[i].rm_eo == -1) + continue; + printf("matched[%zu]='%.*s'\n", i, (int)(rm[i].rm_eo - rm[i].rm_so), + string + rm[i].rm_so); + } + } else if (rv == REG_NOMATCH) + printf("%s: not-matched\n", string); + else + abort(); +} + +int main(void) { + printf("regex\n"); + + regex_t regex; + int rv = regcomp(®ex, "[[:upper:]]\\([[:upper:]]\\)", 0); + assert(!rv); + + test_matched(®ex, "abc"); + test_matched(®ex, "ABC"); + + test_print_matches(®ex, "ABC"); + + regfree(®ex); + + rv = regcomp(®ex, "[[:upp:]]", 0); + assert(rv); + + char errbuf[1024]; + regerror(rv, ®ex, errbuf, sizeof errbuf); + printf("error: %s\n", errbuf); + + // CHECK: regex + // CHECK: abc: not-matched + // CHECK: ABC: matched + // CHECK: matched[0]='AB' + // CHECK: matched[1]='B' + // CHECK: error:{{.*}} + + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/setvbuf.cc b/test/sanitizer_common/TestCases/Posix/setvbuf.cc new file mode 100644 index 000000000000..bc29ba45d89a --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/setvbuf.cc @@ -0,0 +1,81 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +// UNSUPPORTED: solaris + +#include <stdio.h> + +void print_something() { + for (size_t i = 0; i < 10 * BUFSIZ; i++) + printf("Hello world %zu\n", i); +} + +void print_one_byte(char *buf) { + printf("First byte is %c\n", buf[0]); +} + +void test_setbuf() { + char buf[BUFSIZ]; + + setbuf(stdout, NULL); + + print_something(); + + setbuf(stdout, buf); + + print_something(); + + print_one_byte(buf); +} + +void test_setbuffer() { + char buf[BUFSIZ]; + + setbuffer(stdout, NULL, 0); + + print_something(); + + setbuffer(stdout, buf, BUFSIZ); + + print_something(); + + print_one_byte(buf); +} + +void test_setlinebuf() { + setlinebuf(stdout); + + print_something(); +} + +void test_setvbuf() { + char buf[BUFSIZ]; + + setvbuf(stdout, NULL, _IONBF, 0); + + print_something(); + + setvbuf(stdout, buf, _IOLBF, BUFSIZ); + + print_something(); + + print_one_byte(buf); + + setvbuf(stdout, buf, _IOFBF, BUFSIZ); + + print_something(); + + print_one_byte(buf); +} + +int main(void) { + printf("setvbuf\n"); + + test_setbuf(); + test_setbuffer(); + test_setlinebuf(); + test_setvbuf(); + + // CHECK: setvbuf + + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/sl_add.cc b/test/sanitizer_common/TestCases/Posix/sl_add.cc new file mode 100644 index 000000000000..4da70c7888f6 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/sl_add.cc @@ -0,0 +1,26 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, darwin, solaris + +#include <assert.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <stringlist.h> + +int main(void) { + printf("sl_add\n"); + + StringList *sl = sl_init(); + assert(sl); + char *p = strdup("entry"); + assert(!sl_add(sl, p)); + char *entry = sl_find(sl, "entry"); + assert(!strcmp(entry, p)); + printf("Found '%s'\n", entry); + sl_free(sl, 1); + + return 0; + // CHECK: sl_add + // CHECK: Found '{{.*}}' +} diff --git a/test/sanitizer_common/TestCases/Posix/strtonum.cc b/test/sanitizer_common/TestCases/Posix/strtonum.cc new file mode 100644 index 000000000000..22346b2e111c --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/strtonum.cc @@ -0,0 +1,54 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, darwin, solaris + +#define _OPENBSD_SOURCE + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +int main(void) { + const char *errstr; + + printf("strtonum\n"); + + long long l = strtonum("100", 1, 100, &errstr); + assert(!errstr); + printf("%lld\n", l); + + l = strtonum("200", 1, 100, &errstr); + assert(errstr); + printf("%s\n", errstr); + + l = strtonum("300", 1000, 1001, &errstr); + assert(errstr); + printf("%s\n", errstr); + + l = strtonum("abc", 1000, 1001, &errstr); + assert(errstr); + printf("%s\n", errstr); + + l = strtonum("1000", 1001, 1000, &errstr); + assert(errstr); + printf("%s\n", errstr); + + l = strtonum("1000abc", 1000, 1001, &errstr); + assert(errstr); + printf("%s\n", errstr); + + l = strtonum("1000.0", 1000, 1001, &errstr); + assert(errstr); + printf("%s\n", errstr); + + // CHECK: strtonum + // CHECK: 100 + // CHECK: too large + // CHECK: too small + // CHECK: invalid + // CHECK: invalid + // CHECK: invalid + // CHECK: invalid + + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/sysctl.cc b/test/sanitizer_common/TestCases/Posix/sysctl.cc new file mode 100644 index 000000000000..2cb8764f34b0 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/sysctl.cc @@ -0,0 +1,64 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, solaris + +#include <sys/param.h> +#include <sys/types.h> + +#include <sys/sysctl.h> + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +#ifndef __arraycount +#define __arraycount(a) (sizeof(a) / sizeof(a[0])) +#endif + +void test_sysctl() { + char buf[100]; + size_t len = sizeof(buf); + int mib[] = {CTL_KERN, KERN_OSTYPE}; + int rv = sysctl(mib, __arraycount(mib), buf, &len, NULL, 0); + assert(!rv); + + printf("sysctl: '%s' size: '%zu'\n", buf, len); +} + +void test_sysctlbyname() { + char buf[100]; + size_t len = sizeof(buf); + int rv = sysctlbyname("kern.ostype", buf, &len, NULL, 0); + assert(!rv); + + printf("sysctlbyname: '%s' size: '%zu'\n", buf, len); +} + +void test_sysctlnametomib() { + int mib[CTL_MAXNAME]; + size_t mib_len = __arraycount(mib); + int rv = sysctlnametomib("kern.ostype", &mib[0], &mib_len); + assert(!rv); + + char buf[100]; + size_t len = sizeof(buf); + rv = sysctl(mib, mib_len, buf, &len, NULL, 0); + assert(!rv); + + printf("sysctlnametomib: '%s' size: '%zu'\n", buf, len); +} + +int main(void) { + printf("sysctl\n"); + + test_sysctl(); + test_sysctlbyname(); + test_sysctlnametomib(); + + // CHECK: sysctl + // CHECK: sysctl: '{{.*}}' size: '{{.*}}' + // CHECK: sysctlbyname: '{{.*}}' size: '{{.*}}' + // CHECK: sysctlnametomib: '{{.*}}' size: '{{.*}}' + + return 0; +} diff --git a/test/sanitizer_common/TestCases/Posix/vis.cc b/test/sanitizer_common/TestCases/Posix/vis.cc new file mode 100644 index 000000000000..15f1bc949023 --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/vis.cc @@ -0,0 +1,247 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, solaris, darwin + +#include <ctype.h> +#include <err.h> +#include <inttypes.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <vis.h> + +void test_vis() { + char visout[5]; + int ch = toascii(0x1); + vis(visout, ch, VIS_SAFE | VIS_NOSLASH, 0); + printf("vis: %s\n", visout); +} + +void test_nvis() { + char visout[5]; + int ch = toascii(0x2); + nvis(visout, sizeof visout, ch, VIS_SAFE | VIS_NOSLASH, 0); + printf("nvis: %s\n", visout); +} + +void test_strvis() { + char visout[5]; + strvis(visout, "\3", VIS_SAFE | VIS_NOSLASH); + printf("strvis: %s\n", visout); +} + +void test_stravis() { + char *visout; + stravis(&visout, "\4", VIS_SAFE | VIS_NOSLASH); + printf("stravis: %s\n", visout); + free(visout); +} + +void test_strnvis() { + char visout[5]; + strnvis(visout, sizeof visout, "\5", VIS_SAFE | VIS_NOSLASH); + printf("strnvis: %s\n", visout); +} + +void test_strvisx() { + char visout[5]; + char src[] = "\6"; + strvisx(visout, src, sizeof src - 1 /* skip final \0 */, + VIS_SAFE | VIS_NOSLASH); + printf("strvisx: %s\n", visout); +} + +void test_strnvisx() { + char visout[5]; + char src[] = "\1"; + strnvisx(visout, sizeof visout, src, sizeof src - 1 /* skip final \0 */, + VIS_SAFE | VIS_NOSLASH); + printf("strnvisx: %s\n", visout); +} + +void test_strenvisx() { + char visout[5]; + char src[] = "\2"; + strenvisx(visout, sizeof visout, src, sizeof src - 1 /* skip final \0 */, + VIS_SAFE | VIS_NOSLASH, NULL); + printf("strenvisx: %s\n", visout); +} + +void test_svis() { + char visout[5]; + int ch = toascii(0x3); + svis(visout, ch, VIS_SAFE | VIS_NOSLASH, 0, "x"); + printf("svis: %s\n", visout); +} + +void test_snvis() { + char visout[5]; + int ch = toascii(0x2); + snvis(visout, sizeof visout, ch, VIS_SAFE | VIS_NOSLASH, 0, "x"); + printf("snvis: %s\n", visout); +} + +void test_strsvis() { + char visout[5]; + strsvis(visout, "\4", VIS_SAFE | VIS_NOSLASH, "x"); + printf("strsvis: %s\n", visout); +} + +void test_strsnvis() { + char visout[5]; + strsnvis(visout, sizeof visout, "\5", VIS_SAFE | VIS_NOSLASH, "x"); + printf("strsnvis: %s\n", visout); +} + +void test_strsvisx() { + char visout[5]; + char src[] = "\5"; + strsvisx(visout, src, sizeof src - 1 /* skip final \0 */, + VIS_SAFE | VIS_NOSLASH, "x"); + printf("strsvisx: %s\n", visout); +} + +void test_strsnvisx() { + char visout[5]; + char src[] = "\6"; + strsnvisx(visout, sizeof visout, src, sizeof src - 1 /* skip final \0 */, + VIS_SAFE | VIS_NOSLASH, "x"); + printf("strsnvisx: %s\n", visout); +} + +void test_strsenvisx() { + char visout[5]; + char src[] = "\1"; + strsenvisx(visout, sizeof visout, src, sizeof src - 1 /* skip final \0 */, + VIS_SAFE | VIS_NOSLASH, "x", NULL); + printf("strsenvisx: %s\n", visout); +} + +void test_unvis() { + char visout[5]; + int ch = toascii(0x1); + vis(visout, ch, VIS_SAFE, 0); + + int state = 0; + char out; + char *p = visout; + while ((ch = *(p++)) != '\0') { + again: + switch (unvis(&out, ch, &state, 0)) { + case 0: + case UNVIS_NOCHAR: + break; + case UNVIS_VALID: + printf("unvis: %" PRIx8 "\n", (unsigned char)out); + break; + case UNVIS_VALIDPUSH: + printf("unvis: %" PRIx8 "\n", (unsigned char)out); + goto again; + case UNVIS_SYNBAD: + errx(1, "Bad character sequence!"); + } + } + if (unvis(&out, '\0', &state, UNVIS_END) == UNVIS_VALID) + printf("unvis: %" PRIx8 "\n", (unsigned char)out); +} + +void test_strunvis() { + char visout[5]; + int ch = toascii(0x2); + vis(visout, ch, VIS_SAFE, 0); + + char p[5]; + strunvis(p, visout); + + char *pp = p; + while ((ch = *(pp++)) != '\0') + printf("strunvis: %" PRIx8 "\n", (unsigned char)ch); +} + +void test_strnunvis() { + char visout[5]; + int ch = toascii(0x3); + vis(visout, ch, VIS_SAFE, 0); + + char p[5]; + strnunvis(p, sizeof p, visout); + + char *pp = p; + while ((ch = *(pp++)) != '\0') + printf("strnunvis: %" PRIx8 "\n", (unsigned char)ch); +} + +void test_strunvisx() { + char visout[5]; + int ch = toascii(0x4); + vis(visout, ch, VIS_SAFE, 0); + + char p[5]; + strunvisx(p, visout, VIS_SAFE); + + char *pp = p; + while ((ch = *(pp++)) != '\0') + printf("strunvisx: %" PRIx8 "\n", (unsigned char)ch); +} + +void test_strnunvisx() { + char visout[5]; + int ch = toascii(0x5); + vis(visout, ch, VIS_SAFE, 0); + + char p[5]; + strnunvisx(p, sizeof p, visout, VIS_SAFE); + + char *pp = p; + while ((ch = *(pp++)) != '\0') + printf("strnunvisx: %" PRIx8 "\n", (unsigned char)ch); +} + +int main(void) { + printf("vis\n"); + + test_vis(); + test_nvis(); + test_strvis(); + test_stravis(); + test_strnvis(); + test_strvisx(); + test_strnvisx(); + test_strenvisx(); + test_svis(); + test_snvis(); + test_strsvis(); + test_strsnvis(); + test_strsvisx(); + test_strsnvisx(); + test_strsenvisx(); + test_unvis(); + test_strunvis(); + test_strnunvis(); + test_strunvisx(); + test_strnunvisx(); + + // CHECK: vis + // CHECK: vis: ^A + // CHECK: nvis: ^B + // CHECK: strvis: ^C + // CHECK: stravis: ^D + // CHECK: strnvis: ^E + // CHECK: strvisx: ^F + // CHECK: strnvisx: ^A + // CHECK: strenvisx: ^B + // CHECK: svis: ^C + // CHECK: snvis: ^B + // CHECK: strsvis: ^D + // CHECK: strsnvis: ^E + // CHECK: strsvisx: ^E + // CHECK: strsnvisx: ^F + // CHECK: strsenvisx: ^A + // CHECK: unvis: 1 + // CHECK: strunvis: 2 + // CHECK: strnunvis: 3 + // CHECK: strunvisx: 4 + // CHECK: strnunvisx: 5 + + return 0; +} diff --git a/test/sanitizer_common/TestCases/allocator_returns_null.cc b/test/sanitizer_common/TestCases/allocator_returns_null.cc index 9ecdfef9ffcd..f5d99174910f 100644 --- a/test/sanitizer_common/TestCases/allocator_returns_null.cc +++ b/test/sanitizer_common/TestCases/allocator_returns_null.cc @@ -36,7 +36,7 @@ // RUN: | FileCheck %s --check-prefix=CHECK-NULL // TODO(alekseyshl): win32 is disabled due to failing errno tests, fix it there. -// UNSUPPORTED: ubsan, win32 +// UNSUPPORTED: ubsan, windows-msvc #include <assert.h> #include <errno.h> diff --git a/test/sanitizer_common/TestCases/corelimit.cc b/test/sanitizer_common/TestCases/corelimit.cc index eb02afc01a1b..2378a4cfdced 100644 --- a/test/sanitizer_common/TestCases/corelimit.cc +++ b/test/sanitizer_common/TestCases/corelimit.cc @@ -10,7 +10,7 @@ int main() { getrlimit(RLIMIT_CORE, &lim_core); void *p; if (sizeof(p) == 8) { - assert(0 == lim_core.rlim_max); + assert(0 == lim_core.rlim_cur); } return 0; } diff --git a/test/sanitizer_common/TestCases/get_module_and_offset_for_pc.cc b/test/sanitizer_common/TestCases/get_module_and_offset_for_pc.cc index 0591d356f136..b313df87ce1d 100644 --- a/test/sanitizer_common/TestCases/get_module_and_offset_for_pc.cc +++ b/test/sanitizer_common/TestCases/get_module_and_offset_for_pc.cc @@ -1,6 +1,6 @@ // RUN: mkdir -p %t-dir // RUN: %clangxx -DSHARED %s -shared -o %t-dir/get_module_and_offset_for_pc.so -fPIC -// RUN: %clangxx -DSO_DIR=\"%t-dir\" -O0 %s -ldl -o %t +// RUN: %clangxx -DSO_DIR=\"%t-dir\" -O0 %s -o %t // RUN: %run %t 2>&1 | FileCheck %s // UNSUPPORTED: i386-darwin diff --git a/test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc b/test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cc index 3013a3c3fd7d..e01d416cb80f 100644 --- a/test/sanitizer_common/TestCases/Linux/hard_rss_limit_mb_test.cc +++ b/test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cc @@ -16,8 +16,7 @@ // XFAIL: msan // XFAIL: ubsan -// https://github.com/google/sanitizers/issues/981 -// UNSUPPORTED: android-26 +// UNSUPPORTED: freebsd, solaris, darwin #include <string.h> #include <stdio.h> diff --git a/test/sanitizer_common/TestCases/malloc_hook.cc b/test/sanitizer_common/TestCases/malloc_hook.cc index 853bb66ac5c4..7579ca2c3f98 100644 --- a/test/sanitizer_common/TestCases/malloc_hook.cc +++ b/test/sanitizer_common/TestCases/malloc_hook.cc @@ -1,7 +1,7 @@ // RUN: %clangxx -O2 %s -o %t && %run %t 2>&1 | FileCheck %s // Malloc/free hooks are not supported on Windows. -// XFAIL: win32 +// XFAIL: windows-msvc // XFAIL: ubsan #include <stdlib.h> diff --git a/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc b/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc index 26060f395c11..742ae72c41b4 100644 --- a/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc +++ b/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc @@ -1,5 +1,8 @@ // RUN: %clangxx -O0 %s -o %t && %run %t +// pthread_mutexattr_setpshared and pthread_mutexattr_getpshared unavailable +// UNSUPPORTED: netbsd + #include <assert.h> #include <pthread.h> diff --git a/test/sanitizer_common/TestCases/sanitizer_coverage_symbolize.cc b/test/sanitizer_common/TestCases/sanitizer_coverage_symbolize.cc index 28e237802b21..daa994c81162 100644 --- a/test/sanitizer_common/TestCases/sanitizer_coverage_symbolize.cc +++ b/test/sanitizer_common/TestCases/sanitizer_coverage_symbolize.cc @@ -7,7 +7,7 @@ // RUN: rm -rf $DIR // RUN: mkdir -p $DIR // RUN: cd $DIR -// RUN: %clangxx -O0 -fsanitize-coverage=trace-pc-guard %s -ldl -o %t +// RUN: %clangxx -O0 -fsanitize-coverage=trace-pc-guard %s -o %t // RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s // RUN: rm -rf $DIR diff --git a/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc index 1adbf653bb76..5e01a803bff0 100644 --- a/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc +++ b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc @@ -9,7 +9,7 @@ // RUN: rm -rf $DIR // RUN: mkdir -p $DIR // RUN: cd $DIR -// RUN: %clangxx -O0 -fsanitize-coverage=trace-pc-guard %s -ldl -o %t +// RUN: %clangxx -O0 -fsanitize-coverage=trace-pc-guard %s -o %t // RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s // RUN: %sancovcc -covered-functions -strip_path_prefix=TestCases/ *.sancov %t 2>&1 | \ // RUN: FileCheck --check-prefix=CHECK-SANCOV %s diff --git a/test/sanitizer_common/TestCases/strcasestr.c b/test/sanitizer_common/TestCases/strcasestr.c index 4de3cac7e253..04f8d744b7ab 100644 --- a/test/sanitizer_common/TestCases/strcasestr.c +++ b/test/sanitizer_common/TestCases/strcasestr.c @@ -1,7 +1,7 @@ // RUN: %clang %s -o %t && %run %t 2>&1 // There's no interceptor for strcasestr on Windows -// XFAIL: win32 +// XFAIL: windows-msvc #define _GNU_SOURCE #include <assert.h> diff --git a/test/sanitizer_common/TestCases/symbolize_pc.cc b/test/sanitizer_common/TestCases/symbolize_pc.cc index 68a6733f4464..16a81f1bbd43 100644 --- a/test/sanitizer_common/TestCases/symbolize_pc.cc +++ b/test/sanitizer_common/TestCases/symbolize_pc.cc @@ -7,6 +7,17 @@ int GLOBAL_VAR_ABC; +void SymbolizeSmallBuffer() { + char data[] = "abcdef"; + __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", data, 0); + printf("UNCHANGED '%s'\n", data); + __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", data, 1); + printf("EMPTY '%s'\n", data); + __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", data, + sizeof(data)); + printf("PARTIAL '%s'\n", data); +} + void SymbolizeCaller() { char data[100]; __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", data, @@ -31,10 +42,16 @@ void SymbolizeData() { printf("GLOBAL: %s\n", data); } -// CHECK: FIRST_FORMAT 0x{{.*}} in main symbolize_pc.cc:[[@LINE+3]] -// CHECK: SECOND_FORMAT FUNC:main LINE:[[@LINE+2]] FILE:symbolize_pc.cc int main() { + // CHECK: UNCHANGED 'abcdef' + // CHECK: EMPTY '' + // CHECK: PARTIAL '0x{{.*}}' + SymbolizeSmallBuffer(); + + // CHECK: FIRST_FORMAT 0x{{.*}} in main symbolize_pc.cc:[[@LINE+2]] + // CHECK: SECOND_FORMAT FUNC:main LINE:[[@LINE+1]] FILE:symbolize_pc.cc SymbolizeCaller(); + + // CHECK: GLOBAL: GLOBAL_VAR_ABC SymbolizeData(); } -// CHECK: GLOBAL: GLOBAL_VAR_ABC diff --git a/test/sanitizer_common/TestCases/symbolize_pc_inline.cc b/test/sanitizer_common/TestCases/symbolize_pc_inline.cc new file mode 100644 index 000000000000..9589a3af0765 --- /dev/null +++ b/test/sanitizer_common/TestCases/symbolize_pc_inline.cc @@ -0,0 +1,32 @@ +// RUN: %clangxx -O3 %s -o %t +// RUN: %env_tool_opts=strip_path_prefix=/TestCases/ %run %t 2>&1 | FileCheck %s +// RUN: %env_tool_opts=strip_path_prefix=/TestCases/:symbolize_inline_frames=0 \ +// RUN: %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-NOINLINE + +// XFAIL: darwin + +#include <sanitizer/common_interface_defs.h> +#include <stdio.h> +#include <string.h> + +char buffer[10000]; + +__attribute__((noinline)) static void Symbolize() { + __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", buffer, + sizeof(buffer)); + for (char *p = buffer; strlen(p); p += strlen(p) + 1) + printf("%s\n", p); +} + +// CHECK-NOINLINE: {{0x[0-9a-f]+}} in main symbolize_pc_inline.cc:[[@LINE+2]] +// CHECK: [[ADDR:0x[0-9a-f]+]] in C2 symbolize_pc_inline.cc:[[@LINE+1]] +static inline void C2() { Symbolize(); } + +// CHECK: [[ADDR]] in C3 symbolize_pc_inline.cc:[[@LINE+1]] +static inline void C3() { C2(); } + +// CHECK: [[ADDR]] in C4 symbolize_pc_inline.cc:[[@LINE+1]] +static inline void C4() { C3(); } + +// CHECK: [[ADDR]] in main symbolize_pc_inline.cc:[[@LINE+1]] +int main() { C4(); } diff --git a/test/sanitizer_common/ios_commands/iossim_run.py b/test/sanitizer_common/ios_commands/iossim_run.py index 47b847f5329c..e1f633e87463 100755 --- a/test/sanitizer_common/ios_commands/iossim_run.py +++ b/test/sanitizer_common/ios_commands/iossim_run.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import os, sys, subprocess +import glob, os, pipes, sys, subprocess if not "SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER" in os.environ: @@ -8,11 +8,29 @@ if not "SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER" in os.environ: device_id = os.environ["SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER"] -for e in ["ASAN_OPTIONS", "TSAN_OPTIONS"]: +for e in ["ASAN_OPTIONS", "TSAN_OPTIONS", "UBSAN_OPTIONS", "APPLE_ASAN_INIT_FOR_DLOPEN"]: if e in os.environ: os.environ["SIMCTL_CHILD_" + e] = os.environ[e] -exitcode = subprocess.call(["xcrun", "simctl", "spawn", device_id] + sys.argv[1:]) +prog = sys.argv[1] +exit_code = None +if prog == 'rm': + # The simulator and host actually share the same file system so we can just + # execute directly on the host. + rm_args = [] + for arg in sys.argv[2:]: + if '*' in arg or '?' in arg: + # Don't quote glob pattern + rm_args.append(arg) + else: + # FIXME(dliew): pipes.quote() is deprecated + rm_args.append(pipes.quote(arg)) + rm_cmd_line = ["/bin/rm"] + rm_args + rm_cmd_line_str = ' '.join(rm_cmd_line) + # We use `shell=True` so that any wildcard globs get expanded by the shell. + exitcode = subprocess.call(rm_cmd_line_str, shell=True) +else: + exitcode = subprocess.call(["xcrun", "simctl", "spawn", device_id] + sys.argv[1:]) if exitcode > 125: exitcode = 126 sys.exit(exitcode) diff --git a/test/sanitizer_common/lit.common.cfg b/test/sanitizer_common/lit.common.cfg index 1b347bf2bbac..75cc7b77e70e 100644 --- a/test/sanitizer_common/lit.common.cfg +++ b/test/sanitizer_common/lit.common.cfg @@ -46,7 +46,13 @@ if default_tool_options_str: config.environment[tool_options] = default_tool_options_str default_tool_options_str += ':' +if config.host_os in ['Linux']: + extra_link_flags = ["-ldl"] +else: + extra_link_flags = [] + clang_cflags = config.debug_info_flags + tool_cflags + [config.target_cflags] +clang_cflags += extra_link_flags clang_cxxflags = config.cxx_mode_flags + clang_cflags def build_invocation(compile_flags): diff --git a/test/scudo/dealloc-race.c b/test/scudo/dealloc-race.c new file mode 100644 index 000000000000..326e22f27373 --- /dev/null +++ b/test/scudo/dealloc-race.c @@ -0,0 +1,69 @@ +// RUN: %clang_scudo %s -O2 -o %t +// RUN: %env_scudo_opts="QuarantineChunksUpToSize=0" %run %t 2>&1 + +// This test attempts to reproduce a race condition in the deallocation path +// when bypassing the Quarantine. The old behavior was to zero-out the chunk +// header after checking its checksum, state & various other things, but that +// left a window during which 2 (or more) threads could deallocate the same +// chunk, with a net result of having said chunk present in those distinct +// thread caches. + +// A passing test means all the children died with an error. The failing +// scenario involves winning a race, so repro can be scarce. + +#include <pthread.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/wait.h> + +const int kNumThreads = 2; +pthread_t tid[kNumThreads]; + +pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +char go = 0; + +// Frees the pointer passed when signaled to. +void *thread_free(void *p) { + pthread_mutex_lock(&mutex); + while (!go) + pthread_cond_wait(&cond, &mutex); + pthread_mutex_unlock(&mutex); + free(p); + return 0; +} + +// Allocates a chunk, and attempts to free it "simultaneously" by 2 threads. +void child(void) { + void *p = malloc(16); + for (int i = 0; i < kNumThreads; i++) + pthread_create(&tid[i], 0, thread_free, p); + pthread_mutex_lock(&mutex); + go = 1; + pthread_cond_broadcast(&cond); + pthread_mutex_unlock(&mutex); + for (int i = 0; i < kNumThreads; i++) + pthread_join(tid[i], 0); +} + +int main(int argc, char** argv) { + const int kChildren = 40; + pid_t pid; + for (int i = 0; i < kChildren; ++i) { + pid = fork(); + if (pid < 0) { + exit(1); + } else if (pid == 0) { + child(); + exit(0); + } else { + int status; + wait(&status); + // A 0 status means the child didn't die with an error. The race was won. + if (status == 0) + exit(1); + } + } + return 0; +} diff --git a/test/tsan/Darwin/gcd-sync-block-copy.mm b/test/tsan/Darwin/gcd-sync-block-copy.mm new file mode 100644 index 000000000000..87658d7f3e3a --- /dev/null +++ b/test/tsan/Darwin/gcd-sync-block-copy.mm @@ -0,0 +1,34 @@ +// This test verifies that dispatch_sync() doesn't actually copy the block under TSan (without TSan, it doesn't). + +// RUN: %clang_tsan -fno-sanitize=thread %s -o %t_no_tsan -framework Foundation +// RUN: %run %t_no_tsan 2>&1 | FileCheck %s + +// RUN: %clang_tsan %s -o %t_with_tsan -framework Foundation +// RUN: %run %t_with_tsan 2>&1 | FileCheck %s + +#import <Foundation/Foundation.h> + +@interface MyClass : NSObject +@end + +@implementation MyClass +- (instancetype)retain { + // Copying the dispatch_sync'd block below will increment the retain count of + // this object. Abort if that happens. + abort(); +} +@end + +int main(int argc, const char* argv[]) { + dispatch_queue_t q = dispatch_queue_create("my.queue", NULL); + id object = [[MyClass alloc] init]; + dispatch_sync(q, ^{ + NSLog(@"%@", object); + }); + [object release]; + NSLog(@"Done."); + return 0; +} + +// CHECK: Done. +// CHECK-NOT: WARNING: ThreadSanitizer diff --git a/test/tsan/Darwin/ignore-noninstrumented.mm b/test/tsan/Darwin/ignore-noninstrumented.mm index 668a76a462ce..88d39268f1b8 100644 --- a/test/tsan/Darwin/ignore-noninstrumented.mm +++ b/test/tsan/Darwin/ignore-noninstrumented.mm @@ -1,4 +1,7 @@ -// Check that ignore_noninstrumented_modules=1 suppresses races from system libraries on OS X. +// Check that ignore_noninstrumented_modules=1 suppresses reporting races from +// system libraries on OS X. There are currently false positives coming from +// libxpc, libdispatch, CoreFoundation and others, because these libraries use +// TSan-invisible atomics as synchronization. // RUN: %clang_tsan %s -o %t -framework Foundation diff --git a/test/tsan/Darwin/ignored-interceptors.mm b/test/tsan/Darwin/ignored-interceptors.mm deleted file mode 100644 index b2e40f07d574..000000000000 --- a/test/tsan/Darwin/ignored-interceptors.mm +++ /dev/null @@ -1,55 +0,0 @@ -// Check that ignore_interceptors_accesses=1 suppresses reporting races from -// system libraries on OS X. There are currently false positives coming from -// libxpc, libdispatch, CoreFoundation and others, because these libraries use -// TSan-invisible atomics as synchronization. - -// RUN: %clang_tsan %s -o %t -framework Foundation - -// Check that without the flag, there are false positives. -// RUN: %env_tsan_opts=ignore_noninstrumented_modules=0 %deflake %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-RACE - -// With ignore_interceptors_accesses=1, no races are reported. -// RUN: %env_tsan_opts=ignore_noninstrumented_modules=0:ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s - -// With ignore_interceptors_accesses=1, races in user's code are still reported. -// RUN: %env_tsan_opts=ignore_noninstrumented_modules=0:ignore_interceptors_accesses=1 %deflake %run %t race 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RACE - -#import <Foundation/Foundation.h> - -#import "../test.h" - -long global; - -void *Thread1(void *x) { - barrier_wait(&barrier); - global = 42; - return NULL; -} - -void *Thread2(void *x) { - global = 43; - barrier_wait(&barrier); - return NULL; -} - -int main(int argc, char *argv[]) { - fprintf(stderr, "Hello world.\n"); - - // NSUserDefaults uses XPC which triggers the false positive. - NSDictionary *d = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]; - - if (argc > 1 && strcmp(argv[1], "race") == 0) { - barrier_init(&barrier, 2); - pthread_t t[2]; - pthread_create(&t[0], NULL, Thread1, NULL); - pthread_create(&t[1], NULL, Thread2, NULL); - pthread_join(t[0], NULL); - pthread_join(t[1], NULL); - } - - fprintf(stderr, "Done.\n"); -} - -// CHECK: Hello world. -// CHECK-RACE: SUMMARY: ThreadSanitizer: data race -// CHECK: Done. diff --git a/test/tsan/Darwin/objc-synchronize-cycle-tagged.mm b/test/tsan/Darwin/objc-synchronize-cycle-tagged.mm new file mode 100644 index 000000000000..5806e8af925e --- /dev/null +++ b/test/tsan/Darwin/objc-synchronize-cycle-tagged.mm @@ -0,0 +1,42 @@ +// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc %darwin_min_target_with_full_runtime_arc_support +// RUN: %run %t 6 2>&1 | FileCheck %s --check-prefix=SIX +// RUN: not %run %t 7 2>&1 | FileCheck %s --check-prefix=SEVEN + +#import <Foundation/Foundation.h> + +static bool isTaggedPtr(id obj) { + uintptr_t ptr = (uintptr_t) obj; + return (ptr & 0x8000000000000001ull) != 0; +} + +int main(int argc, char* argv[]) { + assert(argc == 2); + int arg = atoi(argv[1]); + + @autoreleasepool { + NSObject* obj = [NSObject new]; + NSObject* num1 = @7; + NSObject* num2 = [NSNumber numberWithInt:arg]; + + assert(!isTaggedPtr(obj)); + assert(isTaggedPtr(num1) && isTaggedPtr(num2)); + + // obj -> num1 (includes num2) + @synchronized(obj) { + @synchronized(num1) { + } + } + + // num2 -> obj1 + @synchronized(num2) { + @synchronized(obj) { +// SEVEN: ThreadSanitizer: lock-order-inversion (potential deadlock) + } + } + } + + NSLog(@"PASS"); +// SIX-NOT: ThreadSanitizer +// SIX: PASS + return 0; +} diff --git a/test/tsan/Darwin/objc-synchronize-cycle.mm b/test/tsan/Darwin/objc-synchronize-cycle.mm new file mode 100644 index 000000000000..fb816311580b --- /dev/null +++ b/test/tsan/Darwin/objc-synchronize-cycle.mm @@ -0,0 +1,31 @@ +// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc %darwin_min_target_with_full_runtime_arc_support +// RUN: not %run %t 2>&1 | FileCheck %s +// RUN: %env_tsan_opts=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s +// RUN: %env_tsan_opts=detect_deadlocks=0 %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED + +#import <Foundation/Foundation.h> + +int main() { + @autoreleasepool { + NSObject* obj1 = [NSObject new]; + NSObject* obj2 = [NSObject new]; + + // obj1 -> obj2 + @synchronized(obj1) { + @synchronized(obj2) { + } + } + + // obj1 -> obj1 + @synchronized(obj2) { + @synchronized(obj1) { +// CHECK: ThreadSanitizer: lock-order-inversion (potential deadlock) + } + } + } + + NSLog(@"PASS"); +// DISABLED-NOT: ThreadSanitizer +// DISABLED: PASS + return 0; +} diff --git a/test/tsan/Darwin/objc-synchronize-nested-recursive.mm b/test/tsan/Darwin/objc-synchronize-nested-recursive.mm new file mode 100644 index 000000000000..ab6643e5c54e --- /dev/null +++ b/test/tsan/Darwin/objc-synchronize-nested-recursive.mm @@ -0,0 +1,35 @@ +// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc %darwin_min_target_with_full_runtime_arc_support +// RUN: %run %t 2>&1 | FileCheck %s + +#import <Foundation/Foundation.h> + +int main() { + @autoreleasepool { + NSObject* obj1 = [NSObject new]; + NSObject* obj2 = [NSObject new]; + + @synchronized(obj1) { + @synchronized(obj1) { + NSLog(@"nested 1-1"); +// CHECK: nested 1-1 + } + } + + @synchronized(obj1) { + @synchronized(obj2) { + @synchronized(obj1) { + @synchronized(obj2) { + NSLog(@"nested 1-2-1-2"); +// CHECK: nested 1-2-1-2 + } + } + } + } + + } + + NSLog(@"PASS"); +// CHECK-NOT: ThreadSanitizer +// CHECK: PASS + return 0; +} diff --git a/test/tsan/Linux/thread_timedjoin.c b/test/tsan/Linux/thread_timedjoin.c new file mode 100644 index 000000000000..1d3f1098ece7 --- /dev/null +++ b/test/tsan/Linux/thread_timedjoin.c @@ -0,0 +1,39 @@ +// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s +#define _GNU_SOURCE +#include "../test.h" +#include <errno.h> + +int var; + +void *Thread(void *x) { + barrier_wait(&barrier); + var = 1; + return 0; +} + +static void check(int res, int expect) { + if (res != expect) { + fprintf(stderr, "Unexpected result of pthread_timedjoin_np: %d\n", res); + exit(1); + } +} + +int main() { + barrier_init(&barrier, 2); + pthread_t t; + pthread_create(&t, 0, Thread, 0); + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + check(pthread_timedjoin_np(t, 0, &ts), ETIMEDOUT); + barrier_wait(&barrier); + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec += 10000; + check(pthread_timedjoin_np(t, 0, &ts), 0); + var = 2; + fprintf(stderr, "PASS\n"); + return 0; +} + +// CHECK-NOT: WARNING: ThreadSanitizer: data race +// CHECK-NOT: WARNING: ThreadSanitizer: thread leak +// CHECK: PASS diff --git a/test/tsan/Linux/thread_tryjoin.c b/test/tsan/Linux/thread_tryjoin.c new file mode 100644 index 000000000000..675e1595528a --- /dev/null +++ b/test/tsan/Linux/thread_tryjoin.c @@ -0,0 +1,41 @@ +// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s +#define _GNU_SOURCE +#include "../test.h" +#include <errno.h> + +int var; + +void *Thread(void *x) { + barrier_wait(&barrier); + var = 1; + return 0; +} + +static void check(int res) { + if (res != EBUSY) { + fprintf(stderr, "Unexpected result of pthread_tryjoin_np: %d\n", res); + exit(1); + } +} + +int main() { + barrier_init(&barrier, 2); + pthread_t t; + pthread_create(&t, 0, Thread, 0); + check(pthread_tryjoin_np(t, 0)); + barrier_wait(&barrier); + for (;;) { + int res = pthread_tryjoin_np(t, 0); + if (!res) + break; + check(res); + pthread_yield(); + } + var = 2; + fprintf(stderr, "PASS\n"); + return 0; +} + +// CHECK-NOT: WARNING: ThreadSanitizer: data race +// CHECK-NOT: WARNING: ThreadSanitizer: thread leak +// CHECK: PASS diff --git a/test/tsan/cxa_guard_acquire.cc b/test/tsan/cxa_guard_acquire.cc new file mode 100644 index 000000000000..cdbe609003d4 --- /dev/null +++ b/test/tsan/cxa_guard_acquire.cc @@ -0,0 +1,25 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <stdio.h> + +namespace __tsan { + +void OnPotentiallyBlockingRegionBegin() { + printf("Enter __cxa_guard_acquire\n"); +} + +void OnPotentiallyBlockingRegionEnd() { printf("Exit __cxa_guard_acquire\n"); } + +} // namespace __tsan + +int main(int argc, char **argv) { + // CHECK: Enter main + printf("Enter main\n"); + // CHECK-NEXT: Enter __cxa_guard_acquire + // CHECK-NEXT: Exit __cxa_guard_acquire + static int s = argc; + (void)s; + // CHECK-NEXT: Exit main + printf("Exit main\n"); + return 0; +} diff --git a/test/tsan/deadlock_detector_stress_test.cc b/test/tsan/deadlock_detector_stress_test.cc index bbaaabbb3c14..f3d2fc71249d 100644 --- a/test/tsan/deadlock_detector_stress_test.cc +++ b/test/tsan/deadlock_detector_stress_test.cc @@ -1,12 +1,12 @@ // RUN: %clangxx_tsan %s -o %t -DLockType=PthreadMutex -// RUN: %env_tsan_opts=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOT-SECOND -// RUN: %env_tsan_opts=detect_deadlocks=1:second_deadlock_stack=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SECOND +// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOT-SECOND +// RUN: %env_tsan_opts=second_deadlock_stack=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SECOND // RUN: %clangxx_tsan %s -o %t -DLockType=PthreadSpinLock -// RUN: %env_tsan_opts=detect_deadlocks=1 %deflake %run %t | FileCheck %s +// RUN: %deflake %run %t | FileCheck %s // RUN: %clangxx_tsan %s -o %t -DLockType=PthreadRWLock -// RUN: %env_tsan_opts=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RD +// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RD // RUN: %clangxx_tsan %s -o %t -DLockType=PthreadRecursiveMutex -// RUN: %env_tsan_opts=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-REC +// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-REC #include "test.h" #undef NDEBUG #include <assert.h> diff --git a/test/tsan/dtls.c b/test/tsan/dtls.c index 51697565f1f1..b00ca7691354 100644 --- a/test/tsan/dtls.c +++ b/test/tsan/dtls.c @@ -1,6 +1,7 @@ // RUN: %clang_tsan %s -o %t // RUN: %clang_tsan %s -DBUILD_SO -fPIC -o %t-so.so -shared // RUN: %run %t 2>&1 | FileCheck %s +// XFAIL: netbsd // Test that tsan cleans up dynamic TLS memory between reuse. diff --git a/test/tsan/getline_nohang.cc b/test/tsan/getline_nohang.cc index d103839b8bd0..027ba7bac26a 100644 --- a/test/tsan/getline_nohang.cc +++ b/test/tsan/getline_nohang.cc @@ -1,5 +1,8 @@ // RUN: %clangxx_tsan -O1 %s -o %t && %run %t +// Data race randomly triggered. +// UNSUPPORTED: netbsd + // Make sure TSan doesn't deadlock on a file stream lock at program shutdown. // See https://github.com/google/sanitizers/issues/454 #ifdef __FreeBSD__ diff --git a/test/tsan/ignore_lib5.cc b/test/tsan/ignore_lib5.cc index d6c3f870e49b..43780daf7b68 100644 --- a/test/tsan/ignore_lib5.cc +++ b/test/tsan/ignore_lib5.cc @@ -18,6 +18,9 @@ // matched against 2 libraries: '/libignore_lib1.so' and '/libignore_lib1.so' // This was caused by non-atomicity of reading of /proc/self/maps. +// ReadProcMaps() on NetBSD does not handle >=1MB of memory layout information +// UNSUPPORTED: netbsd + #ifndef LIB #include <dlfcn.h> @@ -78,4 +81,3 @@ int main(int argc, char **argv) { // CHECK-WITHSUPP-NOT: WARNING: ThreadSanitizer: data race // CHECK-WITHSUPP: OK - diff --git a/test/tsan/ignored-interceptors-mmap.cc b/test/tsan/ignored-interceptors-mmap.cc index 796ea9323345..bb43250a659d 100644 --- a/test/tsan/ignored-interceptors-mmap.cc +++ b/test/tsan/ignored-interceptors-mmap.cc @@ -1,10 +1,12 @@ // RUN: %clangxx_tsan -O0 %s -o %t -// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NORMAL -// RUN: %env_tsan_opts=ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-IGNORE -// XFAIL: freebsd +// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-RACE +// RUN: %run %t ignore 2>&1 | FileCheck %s --check-prefix=CHECK-IGNORE +// XFAIL: freebsd,netbsd -#include <errno.h> #include <sys/mman.h> +#include <string.h> +#include <assert.h> +#include <atomic> #include "test.h" @@ -15,48 +17,45 @@ void AnnotateIgnoreWritesBegin(const char *f, int l); void AnnotateIgnoreWritesEnd(const char *f, int l); } -void *global_p; +// Use atomic to ensure we do not have a race for the pointer value itself. We +// only want to check races in the mmap'd memory to isolate the test that mmap +// respects ignore annotations. +std::atomic<int*> global_p; -int mmap_and_ignore_reads_and_writes() { +void mmap_ignored(bool ignore) { const size_t kSize = sysconf(_SC_PAGESIZE); - void *p = mmap(0, kSize, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANON, -1, 0); - if (p == MAP_FAILED) - return printf("mmap failed with %d\n", errno); - munmap(p, kSize); - - void *new_p = mmap(p, kSize, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANON, -1, 0); - if (p == MAP_FAILED || p != new_p) - return printf("second mmap failed with %d\n", errno); - - AnnotateIgnoreWritesBegin(__FILE__, __LINE__); - global_p = p; - AnnotateIgnoreWritesEnd(__FILE__, __LINE__); + + if (ignore) AnnotateIgnoreWritesBegin(__FILE__, __LINE__); + void *p = mmap(0, kSize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); + if (ignore) AnnotateIgnoreWritesEnd(__FILE__, __LINE__); + + // Use relaxed to retain the race between the mmap call and the memory write + global_p.store((int *)p, std::memory_order_relaxed); barrier_wait(&barrier); - return 0; } -void *Thread(void *a) { +void *WriteToMemory(void *unused) { barrier_wait(&barrier); - - ((int*)global_p)[1] = 10; - printf("Read the zero value from mmapped memory %d\n", ((int*)global_p)[1]); + global_p[0] = 7; return 0; } -int main() { +// Create race between allocating (mmap) and writing memory +int main(int argc, const char *argv[]) { + bool ignore = (argc > 1) && (strcmp(argv[1], "ignore") == 0); + barrier_init(&barrier, 2); pthread_t t; - pthread_create(&t, 0, Thread, 0); - if (mmap_and_ignore_reads_and_writes()) - return 1; + pthread_create(&t, 0, WriteToMemory, 0); + mmap_ignored(ignore); pthread_join(t, 0); + + assert(global_p[0] == 7); printf("OK\n"); return 0; } -// CHECK-NORMAL: WARNING: ThreadSanitizer: data race -// CHECK-NORMAL: OK -// CHECK-IGNORE_NOT: WARNING: ThreadSanitizer: data race +// CHECK-RACE: WARNING: ThreadSanitizer: data race +// CHECK-RACE: OK +// CHECK-IGNORE-NOT: WARNING: ThreadSanitizer: data race // CHECK-IGNORE: OK diff --git a/test/tsan/large_malloc_meta.cc b/test/tsan/large_malloc_meta.cc index e83004824a3a..0d0eec34b38d 100644 --- a/test/tsan/large_malloc_meta.cc +++ b/test/tsan/large_malloc_meta.cc @@ -1,4 +1,7 @@ // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s + +// UNSUPPORTED: ios + #include "test.h" #include <sys/mman.h> diff --git a/test/tsan/mmap_large.cc b/test/tsan/mmap_large.cc index 764e954f2b8e..c8d258e804d7 100644 --- a/test/tsan/mmap_large.cc +++ b/test/tsan/mmap_large.cc @@ -1,4 +1,7 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s + +// UNSUPPORTED: ios + #include <stdint.h> #include <stdio.h> #include <errno.h> diff --git a/test/tsan/mutex_cycle2.c b/test/tsan/mutex_cycle2.c index 32659d4eec0d..0dc96d07cb96 100644 --- a/test/tsan/mutex_cycle2.c +++ b/test/tsan/mutex_cycle2.c @@ -1,5 +1,5 @@ // RUN: %clangxx_tsan %s -o %t -// RUN: not %run %t 2>&1 | FileCheck %s +// RUN: not %run %t 2>&1 | FileCheck %s // RUN: %env_tsan_opts=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s // RUN: %env_tsan_opts=detect_deadlocks=0 %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED // RUN: echo "deadlock:main" > %t.supp diff --git a/test/tsan/mutex_lock_destroyed.cc b/test/tsan/mutex_lock_destroyed.cc index 52d6be6210a6..581d8cce296e 100644 --- a/test/tsan/mutex_lock_destroyed.cc +++ b/test/tsan/mutex_lock_destroyed.cc @@ -2,6 +2,9 @@ // RUN: %deflake %run %t | FileCheck %s // RUN: %deflake %run %t 1 | FileCheck %s +// The pthread_mutex_lock interceptor assumes incompatible internals w/ NetBSD +// XFAIL: netbsd + #include <pthread.h> #include <stdio.h> #include <stdlib.h> diff --git a/test/tsan/strerror_r.cc b/test/tsan/strerror_r.cc index cfe8a18c1736..438f54914d6c 100644 --- a/test/tsan/strerror_r.cc +++ b/test/tsan/strerror_r.cc @@ -1,8 +1,7 @@ // RUN: %clangxx_tsan -O1 -DTEST_ERROR=ERANGE %s -o %t && %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-SYS %s // RUN: %clangxx_tsan -O1 -DTEST_ERROR=-1 %s -o %t && not %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-USER %s -// UNSUPPORTED: darwin -// This test provokes a data race under FreeBSD -// XFAIL: freebsd +// This test is for GNU specific version of strerror_r() +// UNSUPPORTED: darwin, netbsd, freebsd #include "test.h" @@ -14,8 +13,7 @@ char buffer[1000]; void *Thread(void *p) { barrier_wait(&barrier); - strerror_r(TEST_ERROR, buffer, sizeof(buffer)); - return buffer; + return strerror_r(TEST_ERROR, buffer, sizeof(buffer)); } int main() { diff --git a/test/tsan/sunrpc.cc b/test/tsan/sunrpc.cc index 5cfb5344ec10..8e32d6d30436 100644 --- a/test/tsan/sunrpc.cc +++ b/test/tsan/sunrpc.cc @@ -1,3 +1,5 @@ +// REQUIRES: sunrpc + // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include <pthread.h> diff --git a/test/ubsan/CMakeLists.txt b/test/ubsan/CMakeLists.txt index fa8b16b8093e..351bf3b829da 100644 --- a/test/ubsan/CMakeLists.txt +++ b/test/ubsan/CMakeLists.txt @@ -62,6 +62,31 @@ foreach(arch ${UBSAN_TEST_ARCH}) endif() endforeach() +macro(add_ubsan_device_testsuite test_mode sanitizer platform arch) + # Note we expect the caller to have already set UBSAN_TEST_TARGET_CFLAGS + set(UBSAN_LIT_TEST_MODE "${test_mode}") + set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${platform}-${arch}) + set(UBSAN_TEST_TARGET_ARCH ${arch}) + set(UBSAN_TEST_USE_LLD "False") + set(UBSAN_TEST_USE_THINLTO "False") + if (APPLE) + set(UBSAN_TEST_APPLE_PLATFORM "${platform}") + else() + unset(UBSAN_TEST_APPLE_PLATFORM) + endif() + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg) + #list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) + if(NOT COMPILER_RT_STANDALONE_BUILD) + list(APPEND UBSAN_TEST_DEPS ${sanitizer}) + endif() + add_lit_testsuite(check-ubsan-${test_mode}-${platform}-${arch} + "UBSan ${CONFIG_NAME} tests" + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/ + DEPENDS ${UBSAN_TEST_DEPS}) +endmacro() + if(APPLE) foreach(arch ${UBSAN_TEST_ARCH}) set(UBSAN_TEST_TARGET_ARCH ${arch}) @@ -69,9 +94,47 @@ if(APPLE) set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi") add_ubsan_testsuites("StandaloneStatic" ubsan ${arch}) endforeach() + + # Device and simulator test suites. + # These are not added into "check-all", in order to run these tests, use + # "check-asan-iossim-x86_64" and similar. They also require that an extra env + # variable to select which iOS device or simulator to use, e.g.: + # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6" + set(EXCLUDE_FROM_ALL ON) + set(UBSAN_APPLE_PLATFORMS "") + if (COMPILER_RT_ENABLE_IOS) + list(APPEND UBSAN_APPLE_PLATFORMS ios iossim) + endif() + if (COMPILER_RT_ENABLE_WATCHOS) + list(APPEND UBSAN_APPLE_PLATFORMS watchos watchossim) + endif() + if (COMPILER_RT_ENABLE_TVOS) + list(APPEND UBSAN_APPLE_PLATFORMS tvos tvossim) + endif() + foreach(platform ${UBSAN_APPLE_PLATFORMS}) + foreach(arch ${DARWIN_${platform}_ARCHS}) + get_target_flags_for_arch(${arch} UBSAN_TEST_TARGET_ARCH_FLAGS_AS_LIST) + string(REPLACE ";" " " UBSAN_TEST_TARGET_ARCH_FLAGS "${UBSAN_TEST_TARGET_ARCH_FLAGS_AS_LIST}") + set(UBSAN_TEST_TARGET_CFLAGS + "${UBSAN_TEST_TARGET_ARCH_FLAGS} -isysroot ${DARWIN_${platform}_SYSROOT}") + if (";${UBSAN_SUPPORTED_ARCH};" MATCHES ";${arch};") + add_ubsan_device_testsuite("Standalone" ubsan ${platform} ${arch}) + endif() + + if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};") + add_ubsan_device_testsuite("AddressSanitizer" asan ${platform} ${arch}) + endif() + + if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};") + add_ubsan_device_testsuite("ThreadSanitizer" tsan ${platform} ${arch}) + endif() + endforeach() + endforeach() + set(EXCLUDE_FROM_ALL OFF) endif() add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests" ${UBSAN_TESTSUITES} DEPENDS ${UBSAN_TEST_DEPS}) set_target_properties(check-ubsan PROPERTIES FOLDER "Compiler-RT Misc") + diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-arithmetic-value-change.c b/test/ubsan/TestCases/ImplicitConversion/integer-arithmetic-value-change.c new file mode 100644 index 000000000000..ef06fbf8398d --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/integer-arithmetic-value-change.c @@ -0,0 +1,345 @@ +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c -fsanitize=implicit-integer-arithmetic-value-change %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c++ -fsanitize=implicit-integer-arithmetic-value-change %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +#include <stdint.h> + +// Test plan: +// * Two types - int and char +// * Two signs - signed and unsigned +// * Square that - we have input and output types. +// Thus, there are total of (2*2)^2 == 16 tests. +// These are all the possible variations/combinations of casts. +// However, not all of them should result in the check. +// So here, we *only* check which should and which should not result in checks. + +uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) { +#line 100 + return x; +} + +uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) { +#line 200 + return x; +} + +int32_t convert_signed_int_to_signed_int(int32_t x) { +#line 300 + return x; +} + +int8_t convert_signed_char_to_signed_char(int8_t x) { +#line 400 + return x; +} + +uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) { +#line 500 + return x; +} + +uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) { +#line 600 + return x; +} + +int32_t convert_unsigned_char_to_signed_int(uint8_t x) { +#line 700 + return x; +} + +int32_t convert_signed_char_to_signed_int(int8_t x) { +#line 800 + return x; +} + +int32_t convert_unsigned_int_to_signed_int(uint32_t x) { +#line 900 + return x; +} + +uint32_t convert_signed_int_to_unsigned_int(int32_t x) { +#line 1000 + return x; +} + +uint8_t convert_signed_int_to_unsigned_char(int32_t x) { +#line 1100 + return x; +} + +uint8_t convert_signed_char_to_unsigned_char(int8_t x) { +#line 1200 + return x; +} + +int8_t convert_unsigned_char_to_signed_char(uint8_t x) { +#line 1300 + return x; +} + +uint32_t convert_signed_char_to_unsigned_int(int8_t x) { +#line 1400 + return x; +} + +int8_t convert_unsigned_int_to_signed_char(uint32_t x) { +#line 1500 + return x; +} + +int8_t convert_signed_int_to_signed_char(int32_t x) { +#line 1600 + return x; +} + +#line 10111 // !!! + +int main() { + // No bits set. + convert_unsigned_int_to_unsigned_int(0); + convert_unsigned_char_to_unsigned_char(0); + convert_signed_int_to_signed_int(0); + convert_signed_char_to_signed_char(0); + convert_unsigned_int_to_unsigned_char(0); + convert_unsigned_char_to_unsigned_int(0); + convert_unsigned_char_to_signed_int(0); + convert_signed_char_to_signed_int(0); + convert_unsigned_int_to_signed_int(0); + convert_signed_int_to_unsigned_int(0); + convert_signed_int_to_unsigned_char(0); + convert_signed_char_to_unsigned_char(0); + convert_unsigned_char_to_signed_char(0); + convert_signed_char_to_unsigned_int(0); + convert_unsigned_int_to_signed_char(0); + convert_signed_int_to_signed_char(0); + + // One lowest bit set. + convert_unsigned_int_to_unsigned_int(1); + convert_unsigned_char_to_unsigned_char(1); + convert_signed_int_to_signed_int(1); + convert_signed_char_to_signed_char(1); + convert_unsigned_int_to_unsigned_char(1); + convert_unsigned_char_to_unsigned_int(1); + convert_unsigned_char_to_signed_int(1); + convert_signed_char_to_signed_int(1); + convert_unsigned_int_to_signed_int(1); + convert_signed_int_to_unsigned_int(1); + convert_signed_int_to_unsigned_char(1); + convert_signed_char_to_unsigned_char(1); + convert_unsigned_char_to_signed_char(1); + convert_signed_char_to_unsigned_int(1); + convert_unsigned_int_to_signed_char(1); + convert_signed_int_to_signed_char(1); + +#if defined(V0) + // All source bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -1 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX); +#elif defined(V1) + // Source 'Sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) +#elif defined(V2) + // All bits except the source 'Sign' bit are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V3) + // All destination bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 255 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V4) + // Destination 'sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 128 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 128 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V5) + // All bits except the destination 'sign' bit are set. + convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -129 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967167 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#elif defined(V6) + // Only the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V7) + // All bits except the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)))); +// CHECK-V7: {{.*}}integer-arithmetic-value-change.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}integer-arithmetic-value-change.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}integer-arithmetic-value-change.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#else +#error Some V* needs to be defined! +#endif + + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c b/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c new file mode 100644 index 000000000000..5c1530a63786 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c @@ -0,0 +1,351 @@ +// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c -fsanitize=implicit-conversion %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +// RUN: %clang -x c++ -fsanitize=implicit-conversion %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c++ -fsanitize=implicit-conversion %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c++ -fsanitize=implicit-conversion %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c++ -fsanitize=implicit-conversion %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c++ -fsanitize=implicit-conversion %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c++ -fsanitize=implicit-conversion %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c++ -fsanitize=implicit-conversion %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c++ -fsanitize=implicit-conversion %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +#include <stdint.h> + +// Test plan: +// * Two types - int and char +// * Two signs - signed and unsigned +// * Square that - we have input and output types. +// Thus, there are total of (2*2)^2 == 16 tests. +// These are all the possible variations/combinations of casts. +// However, not all of them should result in the check. +// So here, we *only* check which should and which should not result in checks. + +uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) { +#line 100 + return x; +} + +uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) { +#line 200 + return x; +} + +int32_t convert_signed_int_to_signed_int(int32_t x) { +#line 300 + return x; +} + +int8_t convert_signed_char_to_signed_char(int8_t x) { +#line 400 + return x; +} + +uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) { +#line 500 + return x; +} + +uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) { +#line 600 + return x; +} + +int32_t convert_unsigned_char_to_signed_int(uint8_t x) { +#line 700 + return x; +} + +int32_t convert_signed_char_to_signed_int(int8_t x) { +#line 800 + return x; +} + +int32_t convert_unsigned_int_to_signed_int(uint32_t x) { +#line 900 + return x; +} + +uint32_t convert_signed_int_to_unsigned_int(int32_t x) { +#line 1000 + return x; +} + +uint8_t convert_signed_int_to_unsigned_char(int32_t x) { +#line 1100 + return x; +} + +uint8_t convert_signed_char_to_unsigned_char(int8_t x) { +#line 1200 + return x; +} + +int8_t convert_unsigned_char_to_signed_char(uint8_t x) { +#line 1300 + return x; +} + +uint32_t convert_signed_char_to_unsigned_int(int8_t x) { +#line 1400 + return x; +} + +int8_t convert_unsigned_int_to_signed_char(uint32_t x) { +#line 1500 + return x; +} + +int8_t convert_signed_int_to_signed_char(int32_t x) { +#line 1600 + return x; +} + +#line 10111 // !!! + +int main() { + // No bits set. + convert_unsigned_int_to_unsigned_int(0); + convert_unsigned_char_to_unsigned_char(0); + convert_signed_int_to_signed_int(0); + convert_signed_char_to_signed_char(0); + convert_unsigned_int_to_unsigned_char(0); + convert_unsigned_char_to_unsigned_int(0); + convert_unsigned_char_to_signed_int(0); + convert_signed_char_to_signed_int(0); + convert_unsigned_int_to_signed_int(0); + convert_signed_int_to_unsigned_int(0); + convert_signed_int_to_unsigned_char(0); + convert_signed_char_to_unsigned_char(0); + convert_unsigned_char_to_signed_char(0); + convert_signed_char_to_unsigned_int(0); + convert_unsigned_int_to_signed_char(0); + convert_signed_int_to_signed_char(0); + + // One lowest bit set. + convert_unsigned_int_to_unsigned_int(1); + convert_unsigned_char_to_unsigned_char(1); + convert_signed_int_to_signed_int(1); + convert_signed_char_to_signed_char(1); + convert_unsigned_int_to_unsigned_char(1); + convert_unsigned_char_to_unsigned_int(1); + convert_unsigned_char_to_signed_int(1); + convert_signed_char_to_signed_int(1); + convert_unsigned_int_to_signed_int(1); + convert_signed_int_to_unsigned_int(1); + convert_signed_int_to_unsigned_char(1); + convert_signed_char_to_unsigned_char(1); + convert_unsigned_char_to_signed_char(1); + convert_signed_char_to_unsigned_int(1); + convert_unsigned_int_to_signed_char(1); + convert_signed_int_to_signed_char(1); + +#if defined(V0) + // All source bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -1 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX); +#elif defined(V1) + // Source 'Sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) +#elif defined(V2) + // All bits except the source 'Sign' bit are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V3) + // All destination bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 255 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V4) + // Destination 'sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 128 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 128 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V5) + // All bits except the destination 'sign' bit are set. + convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -129 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967167 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); +// CHECK-V5: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#elif defined(V6) + // Only the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)); +// CHECK-V6: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-conversion.c:900:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-conversion.c:1000:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-conversion.c:1200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-conversion.c:1300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-conversion.c:1400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V7) + // All bits except the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}integer-conversion.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)))); +// CHECK-V7: {{.*}}integer-conversion.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}integer-conversion.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}integer-conversion.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#else +#error Some V* needs to be defined! +#endif + + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-sign-change-blacklist.c b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change-blacklist.c new file mode 100644 index 000000000000..a3a745e5fbf6 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change-blacklist.c @@ -0,0 +1,28 @@ +// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 +// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases. +// XFAIL: android +// UNSUPPORTED: ios + +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + +// RUN: rm -f %tmp +// RUN: echo "[implicit-integer-sign-change]" >> %tmp +// RUN: echo "fun:implicitSignChange" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +#include <stdint.h> + +int32_t implicitSignChange(uint32_t argc) { + return argc; // BOOM +// CHECK: {{.*}}integer-sign-change-blacklist.c:[[@LINE-1]]:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -1 (32-bit, signed) +} + +int main(int argc, char **argv) { + return implicitSignChange(~0U); +} diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change-summary.cpp index a92e01fb4ab6..7cdc4c5a1b97 100644 --- a/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp +++ b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change-summary.cpp @@ -1,4 +1,4 @@ -// RUN: %clangxx -fsanitize=implicit-integer-truncation %s -o %t +// RUN: %clangxx -fsanitize=implicit-integer-sign-change %s -o %t // RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE // RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE // REQUIRES: !ubsan-standalone && !ubsan-standalone-static @@ -6,8 +6,8 @@ #include <stdint.h> int main() { - uint8_t t0 = (~(uint32_t(0))); + int32_t t0 = (~(uint32_t(0))); // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:16 - // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-integer-truncation {{.*}}summary.cpp:[[@LINE-2]]:16 + // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-integer-sign-change {{.*}}summary.cpp:[[@LINE-2]]:16 return 0; } diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-sign-change.c b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change.c new file mode 100644 index 000000000000..192c69ade1d5 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/integer-sign-change.c @@ -0,0 +1,297 @@ +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c -fsanitize=implicit-integer-sign-change %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 + +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c++ -fsanitize=implicit-integer-sign-change %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 + +#include <stdint.h> + +// Test plan: +// * Two types - int and char +// * Two signs - signed and unsigned +// * Square that - we have input and output types. +// Thus, there are total of (2*2)^2 == 16 tests. +// These are all the possible variations/combinations of casts. +// However, not all of them should result in the check. +// So here, we *only* check which should and which should not result in checks. + +//============================================================================// +// Half of the cases do not need the check. // +//============================================================================// + +uint32_t negative0_convert_unsigned_int_to_unsigned_int(uint32_t x) { + return x; +} + +uint8_t negative1_convert_unsigned_char_to_unsigned_char(uint8_t x) { + return x; +} + +int32_t negative2_convert_signed_int_to_signed_int(int32_t x) { + return x; +} + +int8_t negative3_convert_signed_char_to_signed_char(int8_t x) { + return x; +} + +uint8_t negative4_convert_unsigned_int_to_unsigned_char(uint32_t x) { + return x; +} + +uint32_t negative5_convert_unsigned_char_to_unsigned_int(uint8_t x) { + return x; +} + +int32_t negative6_convert_unsigned_char_to_signed_int(uint8_t x) { + return x; +} + +int32_t negative7_convert_signed_char_to_signed_int(int8_t x) { + return x; +} + +void test_negatives() { + // No bits set. + negative0_convert_unsigned_int_to_unsigned_int(0); + negative1_convert_unsigned_char_to_unsigned_char(0); + negative2_convert_signed_int_to_signed_int(0); + negative3_convert_signed_char_to_signed_char(0); + negative4_convert_unsigned_int_to_unsigned_char(0); + negative5_convert_unsigned_char_to_unsigned_int(0); + negative6_convert_unsigned_char_to_signed_int(0); + negative7_convert_signed_char_to_signed_int(0); + + // One lowest bit set. + negative0_convert_unsigned_int_to_unsigned_int(1); + negative1_convert_unsigned_char_to_unsigned_char(1); + negative2_convert_signed_int_to_signed_int(1); + negative3_convert_signed_char_to_signed_char(1); + negative4_convert_unsigned_int_to_unsigned_char(1); + negative5_convert_unsigned_char_to_unsigned_int(1); + negative6_convert_unsigned_char_to_signed_int(1); + negative7_convert_signed_char_to_signed_int(1); + + // All source bits set. + negative0_convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX); + negative1_convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + negative2_convert_signed_int_to_signed_int((int32_t)INT32_MAX); + negative3_convert_signed_char_to_signed_char((int8_t)INT8_MAX); + negative4_convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); + negative5_convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + negative6_convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + negative7_convert_signed_char_to_signed_int((int8_t)INT8_MAX); + + // Source 'sign' bit set. + negative0_convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + negative1_convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + negative2_convert_signed_int_to_signed_int((int32_t)INT32_MIN); + negative3_convert_signed_char_to_signed_char((int8_t)INT8_MIN); + negative4_convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); + negative5_convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + negative6_convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + negative7_convert_signed_char_to_signed_int((int8_t)INT8_MIN); +} + +//============================================================================// +// The remaining 8 cases *do* need the check. // +//============================================================================// + +int32_t positive0_convert_unsigned_int_to_signed_int(uint32_t x) { +#line 100 + return x; +} + +uint32_t positive1_convert_signed_int_to_unsigned_int(int32_t x) { +#line 200 + return x; +} + +uint8_t positive2_convert_signed_int_to_unsigned_char(int32_t x) { +#line 300 + return x; +} + +uint8_t positive3_convert_signed_char_to_unsigned_char(int8_t x) { +#line 400 + return x; +} + +int8_t positive4_convert_unsigned_char_to_signed_char(uint8_t x) { +#line 500 + return x; +} + +uint32_t positive5_convert_signed_char_to_unsigned_int(int8_t x) { +#line 600 + return x; +} + +int8_t positive6_convert_unsigned_int_to_signed_char(uint32_t x) { +#line 700 + return x; +} + +int8_t positive7_convert_signed_int_to_signed_char(int32_t x) { +#line 800 + return x; +} + +#line 1120 // !!! + +void test_positives() { + // No bits set. + positive0_convert_unsigned_int_to_signed_int(0); + positive1_convert_signed_int_to_unsigned_int(0); + positive2_convert_signed_int_to_unsigned_char(0); + positive3_convert_signed_char_to_unsigned_char(0); + positive4_convert_unsigned_char_to_signed_char(0); + positive5_convert_signed_char_to_unsigned_int(0); + positive6_convert_unsigned_int_to_signed_char(0); + positive7_convert_signed_int_to_signed_char(0); + + // One lowest bit set. + positive0_convert_unsigned_int_to_signed_int(1); + positive1_convert_signed_int_to_unsigned_int(1); + positive2_convert_signed_int_to_unsigned_char(1); + positive3_convert_signed_char_to_unsigned_char(1); + positive4_convert_unsigned_char_to_signed_char(1); + positive5_convert_signed_char_to_unsigned_int(1); + positive6_convert_unsigned_int_to_signed_char(1); + positive7_convert_signed_int_to_signed_char(1); + +#if defined(V0) + // All source bits set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -1 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + positive3_convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + positive6_convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-sign-change.c:700:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + positive7_convert_signed_int_to_signed_char((int32_t)UINT32_MAX); +#elif defined(V1) + // Source 'Sign' bit set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + positive3_convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + positive6_convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); + positive7_convert_signed_int_to_signed_char((int32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-sign-change.c:800:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) +#elif defined(V2) + // All bits except the source 'Sign' bit are set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + positive1_convert_signed_int_to_unsigned_int((int32_t)INT32_MAX); + positive2_convert_signed_int_to_unsigned_char((int32_t)INT32_MAX); + positive3_convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + positive4_convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + positive5_convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + positive6_convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-sign-change.c:700:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + positive7_convert_signed_int_to_signed_char((int32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-sign-change.c:800:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V3) + // All destination bits set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -1 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)UINT32_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)UINT8_MAX); + positive3_convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 255 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)UINT32_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -1 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) + positive6_convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:700:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + positive7_convert_signed_int_to_signed_char((int32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-sign-change.c:800:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 255 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V4) + // Destination 'sign' bit set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -128 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive3_convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)INT32_MIN); + positive6_convert_unsigned_int_to_signed_char((uint32_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-sign-change.c:700:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967168 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive7_convert_signed_int_to_signed_char((int32_t)INT8_MIN); +#elif defined(V5) + // All bits except the destination 'sign' bit are set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V5: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V5: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-sign-change.c:300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + positive3_convert_signed_char_to_unsigned_char((int8_t)(INT8_MIN)); +// CHECK-V5: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)(INT8_MIN)); +// CHECK-V5: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)(INT32_MIN)); + positive6_convert_unsigned_int_to_signed_char(~((uint32_t)(uint8_t)INT8_MIN)); + positive7_convert_signed_int_to_signed_char((int32_t)(~((uint32_t)((uint8_t)INT8_MIN)))); +// CHECK-V5: {{.*}}integer-sign-change.c:800:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#elif defined(V6) + // Only the source and destination sign bits are set. + positive0_convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-sign-change.c:100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'int') changed the value to -2147483648 (32-bit, signed) + positive1_convert_signed_int_to_unsigned_int((int32_t)INT32_MIN); +// CHECK-V6: {{.*}}integer-sign-change.c:200:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 2147483648 (32-bit, unsigned) + positive2_convert_signed_int_to_unsigned_char((int32_t)((uint32_t)INT32_MIN | (uint32_t)((uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-sign-change.c:300:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive3_convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-sign-change.c:400:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + positive4_convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-sign-change.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned char') of value 128 (8-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive5_convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); +// CHECK-V6: {{.*}}integer-sign-change.c:600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'signed char') of value -128 (8-bit, signed) to type '{{.*}}' (aka 'unsigned int') changed the value to 4294967168 (32-bit, unsigned) + positive6_convert_unsigned_int_to_signed_char((uint32_t)((uint32_t)INT32_MIN | (uint32_t)((uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-sign-change.c:700:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + positive7_convert_signed_int_to_signed_char((int32_t)((uint32_t)INT32_MIN | (uint32_t)((uint8_t)INT8_MIN))); +#else +#error Some V* needs to be defined! +#endif +} + +// CHECK-NOT: implicit conversion + +int main() { + test_negatives(); + test_positives(); + + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c b/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c deleted file mode 100644 index 13d4dca4ff14..000000000000 --- a/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c +++ /dev/null @@ -1,20 +0,0 @@ -// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 -// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases. -// XFAIL: android -// UNSUPPORTED: ios - -// RUN: rm -f %tmp -// RUN: echo "[implicit-integer-truncation]" >> %tmp -// RUN: echo "fun:*implicitTruncation*" >> %tmp -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 -// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 - -unsigned char implicitTruncation(unsigned int argc) { - return argc; // BOOM -} - -int main(int argc, char **argv) { - return implicitTruncation(~0U); -} diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-truncation.c b/test/ubsan/TestCases/ImplicitConversion/integer-truncation.c index 995eb7d0faf4..157564871e45 100644 --- a/test/ubsan/TestCases/ImplicitConversion/integer-truncation.c +++ b/test/ubsan/TestCases/ImplicitConversion/integer-truncation.c @@ -1,63 +1,324 @@ -// RUN: %clang -x c -fsanitize=implicit-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK -// RUN: %clangxx -x c++ -fsanitize=implicit-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK +// RUN: %clang -x c -fsanitize=implicit-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c -fsanitize=implicit-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c -fsanitize=implicit-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c -fsanitize=implicit-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c -fsanitize=implicit-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c -fsanitize=implicit-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c -fsanitize=implicit-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c -fsanitize=implicit-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +// RUN: %clang -x c++ -fsanitize=implicit-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c++ -fsanitize=implicit-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c++ -fsanitize=implicit-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c++ -fsanitize=implicit-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c++ -fsanitize=implicit-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c++ -fsanitize=implicit-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c++ -fsanitize=implicit-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c++ -fsanitize=implicit-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 #include <stdint.h> -#if !defined(__cplusplus) -#define bool _Bool -#endif +// Test plan: +// * Two types - int and char +// * Two signs - signed and unsigned +// * Square that - we have input and output types. +// Thus, there are total of (2*2)^2 == 16 tests. +// These are all the possible variations/combinations of casts. +// However, not all of them should result in the check. +// So here, we *only* check which should and which should not result in checks. -int main() { -// CHECK-NOT: integer-truncation.c +uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) { +#line 100 + return x; +} - // Negative tests. Even if they produce unexpected results, this sanitizer does not care. - int8_t n0 = (~((uint32_t)0)); // ~0 -> -1, but do not warn. - uint8_t n2 = 128; - uint8_t n3 = 255; - // Bools do not count - bool b0 = (~((uint32_t)0)); - bool b1 = 255; +uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) { +#line 200 + return x; +} - // Explicit and-ing of bits will silence it. - uint8_t nc0 = (~((uint32_t)0)) & 255; +int32_t convert_signed_int_to_signed_int(int32_t x) { +#line 300 + return x; +} - // Explicit casts - uint8_t i0 = (uint8_t)(~((uint32_t)0)); +int8_t convert_signed_char_to_signed_char(int8_t x) { +#line 400 + return x; +} -#if defined(__cplusplus) - uint8_t i1 = uint8_t(~(uint32_t(0))); - uint8_t i2 = static_cast<uint8_t>(~(uint32_t(0))); -#endif +uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) { +#line 500 + return x; +} + +uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) { +#line 600 + return x; +} + +int32_t convert_unsigned_char_to_signed_int(uint8_t x) { +#line 700 + return x; +} + +int32_t convert_signed_char_to_signed_int(int8_t x) { +#line 800 + return x; +} + +int32_t convert_unsigned_int_to_signed_int(uint32_t x) { +#line 900 + return x; +} + +uint32_t convert_signed_int_to_unsigned_int(int32_t x) { +#line 1000 + return x; +} + +uint8_t convert_signed_int_to_unsigned_char(int32_t x) { +#line 1100 + return x; +} + +uint8_t convert_signed_char_to_unsigned_char(int8_t x) { +#line 1200 + return x; +} + +int8_t convert_unsigned_char_to_signed_char(uint8_t x) { +#line 1300 + return x; +} + +uint32_t convert_signed_char_to_unsigned_int(int8_t x) { +#line 1400 + return x; +} - // Positive tests. - - uint8_t t_b0 = (~((uint16_t)(0))); -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:18: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) - - uint8_t t_b1 = (~((uint32_t)0)); -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:18: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) - uint16_t t_b2 = (~((uint32_t)0)); -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:19: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'uint16_t' (aka 'unsigned short') changed the value to 65535 (16-bit, unsigned) - - uint8_t t_b3 = ~((uint64_t)0); -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:18: runtime error: implicit conversion from type 'uint64_t' (aka 'unsigned long{{[^']*}}') of value 18446744073709551615 (64-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) - uint16_t t_b4 = ~((uint64_t)0); -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:19: runtime error: implicit conversion from type 'uint64_t' (aka 'unsigned long{{[^']*}}') of value 18446744073709551615 (64-bit, unsigned) to type 'uint16_t' (aka 'unsigned short') changed the value to 65535 (16-bit, unsigned) - uint32_t t_b5 = ~((uint64_t)0); -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:19: runtime error: implicit conversion from type 'uint64_t' (aka 'unsigned long{{[^']*}}') of value 18446744073709551615 (64-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned) - - int8_t t1 = 255; -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:15: runtime error: implicit conversion from type 'int' of value 255 (32-bit, signed) to type 'int8_t' (aka 'signed char') changed the value to -1 (8-bit, signed) - uint8_t t2 = 256; -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:16: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) - int8_t t3 = 256; -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:15: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'int8_t' (aka 'signed char') changed the value to 0 (8-bit, signed) - uint8_t t4 = 257; -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:16: runtime error: implicit conversion from type 'int' of value 257 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 1 (8-bit, unsigned) - int8_t t5 = 257; -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:15: runtime error: implicit conversion from type 'int' of value 257 (32-bit, signed) to type 'int8_t' (aka 'signed char') changed the value to 1 (8-bit, signed) - int8_t t6 = 128; -// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:15: runtime error: implicit conversion from type 'int' of value 128 (32-bit, signed) to type 'int8_t' (aka 'signed char') changed the value to -128 (8-bit, signed) +int8_t convert_unsigned_int_to_signed_char(uint32_t x) { +#line 1500 + return x; +} + +int8_t convert_signed_int_to_signed_char(int32_t x) { +#line 1600 + return x; +} + +#line 1111 // !!! + +int main() { + // No bits set. + convert_unsigned_int_to_unsigned_int(0); + convert_unsigned_char_to_unsigned_char(0); + convert_signed_int_to_signed_int(0); + convert_signed_char_to_signed_char(0); + convert_unsigned_int_to_unsigned_char(0); + convert_unsigned_char_to_unsigned_int(0); + convert_unsigned_char_to_signed_int(0); + convert_signed_char_to_signed_int(0); + convert_unsigned_int_to_signed_int(0); + convert_signed_int_to_unsigned_int(0); + convert_signed_int_to_unsigned_char(0); + convert_signed_char_to_unsigned_char(0); + convert_unsigned_char_to_signed_char(0); + convert_signed_char_to_unsigned_int(0); + convert_unsigned_int_to_signed_char(0); + convert_signed_int_to_signed_char(0); + + // One lowest bit set. + convert_unsigned_int_to_unsigned_int(1); + convert_unsigned_char_to_unsigned_char(1); + convert_signed_int_to_signed_int(1); + convert_signed_char_to_signed_char(1); + convert_unsigned_int_to_unsigned_char(1); + convert_unsigned_char_to_unsigned_int(1); + convert_unsigned_char_to_signed_int(1); + convert_signed_char_to_signed_int(1); + convert_unsigned_int_to_signed_int(1); + convert_signed_int_to_unsigned_int(1); + convert_signed_int_to_unsigned_char(1); + convert_signed_char_to_unsigned_char(1); + convert_unsigned_char_to_signed_char(1); + convert_signed_char_to_unsigned_int(1); + convert_unsigned_int_to_signed_char(1); + convert_signed_int_to_signed_char(1); + +#if defined(V0) + // All source bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX); +#elif defined(V1) + // Source 'Sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) +#elif defined(V2) + // All bits except the source 'Sign' bit are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V3) + // All destination bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 255 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V4) + // Destination 'sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 128 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 128 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V5) + // All bits except the destination 'sign' bit are set. + convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#elif defined(V6) + // Only the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)); +// CHECK-V6: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V7) + // All bits except the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)))); +// CHECK-V7: {{.*}}integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#else +#error Some V* needs to be defined! +#endif return 0; } diff --git a/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-blacklist.c b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-blacklist.c new file mode 100644 index 000000000000..229f8326077a --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-blacklist.c @@ -0,0 +1,60 @@ +// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 +// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases. +// XFAIL: android +// UNSUPPORTED: ios + +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + +// RUN: rm -f %tmp +// RUN: echo "[integer]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-conversion]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-signed-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-unsigned-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s + +#include <stdint.h> + +uint8_t implicitUnsignedTruncation(int32_t argc) { + return argc; // BOOM +// CHECK: {{.*}}signed-integer-truncation-blacklist.c:[[@LINE-1]]:10: runtime error: implicit conversion from type '{{.*}} (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) +} + +int main(int argc, char **argv) { + return implicitUnsignedTruncation(-1); +} diff --git a/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-blacklist.c b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-blacklist.c new file mode 100644 index 000000000000..0e79df0b512c --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-blacklist.c @@ -0,0 +1,58 @@ +// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 +// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases. +// XFAIL: android +// UNSUPPORTED: ios + +// All of these don't actually silence it: + +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + +// RUN: rm -f %tmp +// RUN: echo "[implicit-signed-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitConversion" >> %tmp +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + +// RUN: rm -f %tmp +// RUN: echo "[implicit-signed-integer-truncation,implicit-integer-sign-change]" >> %tmp +// RUN: echo "fun:implicitConversion" >> %tmp +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + + +// The only two way it works: + +// RUN: rm -f %tmp +// RUN: echo "[implicit-integer-sign-change]" >> %tmp +// RUN: echo "fun:implicitConversion" >> %tmp +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-signed-integer-truncation]" >> %tmp +// RUN: echo "[implicit-integer-sign-change]" >> %tmp +// RUN: echo "fun:implicitConversion" >> %tmp +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fno-sanitize-recover=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +#include <stdint.h> + +int8_t implicitConversion(uint32_t argc) { + return argc; // BOOM +// CHECK: {{.*}}signed-integer-truncation-or-sign-change-blacklist.c:[[@LINE-1]]:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +} + +int main(int argc, char **argv) { + return implicitConversion(~0U); +} diff --git a/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-summary.cpp b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-summary.cpp new file mode 100644 index 000000000000..13eaef274157 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-or-sign-change-summary.cpp @@ -0,0 +1,13 @@ +// RUN: %clangxx -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE +// RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE +// REQUIRES: !ubsan-standalone && !ubsan-standalone-static + +#include <stdint.h> + +int main() { + int8_t t0 = (~(uint32_t(0))); + // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:15 + // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-signed-integer-truncation-or-sign-change {{.*}}summary.cpp:[[@LINE-2]]:15 + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-summary.cpp b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-summary.cpp new file mode 100644 index 000000000000..1da9e3b41e36 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-summary.cpp @@ -0,0 +1,13 @@ +// RUN: %clangxx -fsanitize=implicit-signed-integer-truncation %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE +// RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE +// REQUIRES: !ubsan-standalone && !ubsan-standalone-static + +#include <stdint.h> + +int main() { + uint8_t t0 = int32_t(-1); + // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:16 + // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-signed-integer-truncation {{.*}}summary.cpp:[[@LINE-2]]:16 + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation.c b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation.c new file mode 100644 index 000000000000..1ff67eb0579b --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation.c @@ -0,0 +1,318 @@ +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +#include <stdint.h> + +// Test plan: +// * Two types - int and char +// * Two signs - signed and unsigned +// * Square that - we have input and output types. +// Thus, there are total of (2*2)^2 == 16 tests. +// These are all the possible variations/combinations of casts. +// However, not all of them should result in the check. +// So here, we *only* check which should and which should not result in checks. + +uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) { +#line 100 + return x; +} + +uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) { +#line 200 + return x; +} + +int32_t convert_signed_int_to_signed_int(int32_t x) { +#line 300 + return x; +} + +int8_t convert_signed_char_to_signed_char(int8_t x) { +#line 400 + return x; +} + +uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) { +#line 500 + return x; +} + +uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) { +#line 600 + return x; +} + +int32_t convert_unsigned_char_to_signed_int(uint8_t x) { +#line 700 + return x; +} + +int32_t convert_signed_char_to_signed_int(int8_t x) { +#line 800 + return x; +} + +int32_t convert_unsigned_int_to_signed_int(uint32_t x) { +#line 900 + return x; +} + +uint32_t convert_signed_int_to_unsigned_int(int32_t x) { +#line 1000 + return x; +} + +uint8_t convert_signed_int_to_unsigned_char(int32_t x) { +#line 1100 + return x; +} + +uint8_t convert_signed_char_to_unsigned_char(int8_t x) { +#line 1200 + return x; +} + +int8_t convert_unsigned_char_to_signed_char(uint8_t x) { +#line 1300 + return x; +} + +uint32_t convert_signed_char_to_unsigned_int(int8_t x) { +#line 1400 + return x; +} + +int8_t convert_unsigned_int_to_signed_char(uint32_t x) { +#line 1500 + return x; +} + +int8_t convert_signed_int_to_signed_char(int32_t x) { +#line 1600 + return x; +} + +#line 1111 // !!! + +int main() { + // No bits set. + convert_unsigned_int_to_unsigned_int(0); + convert_unsigned_char_to_unsigned_char(0); + convert_signed_int_to_signed_int(0); + convert_signed_char_to_signed_char(0); + convert_unsigned_int_to_unsigned_char(0); + convert_unsigned_char_to_unsigned_int(0); + convert_unsigned_char_to_signed_int(0); + convert_signed_char_to_signed_int(0); + convert_unsigned_int_to_signed_int(0); + convert_signed_int_to_unsigned_int(0); + convert_signed_int_to_unsigned_char(0); + convert_signed_char_to_unsigned_char(0); + convert_unsigned_char_to_signed_char(0); + convert_signed_char_to_unsigned_int(0); + convert_unsigned_int_to_signed_char(0); + convert_signed_int_to_signed_char(0); + + // One lowest bit set. + convert_unsigned_int_to_unsigned_int(1); + convert_unsigned_char_to_unsigned_char(1); + convert_signed_int_to_signed_int(1); + convert_signed_char_to_signed_char(1); + convert_unsigned_int_to_unsigned_char(1); + convert_unsigned_char_to_unsigned_int(1); + convert_unsigned_char_to_signed_int(1); + convert_signed_char_to_signed_int(1); + convert_unsigned_int_to_signed_int(1); + convert_signed_int_to_unsigned_int(1); + convert_signed_int_to_unsigned_char(1); + convert_signed_char_to_unsigned_char(1); + convert_unsigned_char_to_signed_char(1); + convert_signed_char_to_unsigned_int(1); + convert_unsigned_int_to_signed_char(1); + convert_signed_int_to_signed_char(1); + +#if defined(V0) + // All source bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -1 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX); +#elif defined(V1) + // Source 'Sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483648 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 0 (8-bit, signed) +#elif defined(V2) + // All bits except the source 'Sign' bit are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483647 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V3) + // All destination bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX); +// CHECK-V3: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 255 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -1 (8-bit, signed) +#elif defined(V4) + // Destination 'sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 128 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); +// CHECK-V4: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 128 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V5) + // All bits except the destination 'sign' bit are set. + convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -129 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#elif defined(V6) + // Only the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V6: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value -2147483520 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to -128 (8-bit, signed) +#elif defined(V7) + // All bits except the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)))); +// CHECK-V7: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) + convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type '{{.*}}' (aka 'int') of value 2147483519 (32-bit, signed) to type '{{.*}}' (aka 'signed char') changed the value to 127 (8-bit, signed) +#else +#error Some V* needs to be defined! +#endif + + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-blacklist.c b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-blacklist.c new file mode 100644 index 000000000000..938b7a8c102c --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-blacklist.c @@ -0,0 +1,60 @@ +// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 +// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases. +// XFAIL: android +// UNSUPPORTED: ios + +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" + +// RUN: rm -f %tmp +// RUN: echo "[integer]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-conversion]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-unsigned-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s + +// RUN: rm -f %tmp +// RUN: echo "[implicit-signed-integer-truncation]" >> %tmp +// RUN: echo "fun:implicitUnsignedTruncation" >> %tmp +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s + +#include <stdint.h> + +uint8_t implicitUnsignedTruncation(uint32_t argc) { + return argc; // BOOM +// CHECK: {{.*}}unsigned-integer-truncation-blacklist.c:[[@LINE-1]]:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) +} + +int main(int argc, char **argv) { + return implicitUnsignedTruncation(~0U); +} diff --git a/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-summary.cpp b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-summary.cpp new file mode 100644 index 000000000000..5117dc2a34f3 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-summary.cpp @@ -0,0 +1,13 @@ +// RUN: %clangxx -fsanitize=implicit-unsigned-integer-truncation %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE +// RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE +// REQUIRES: !ubsan-standalone && !ubsan-standalone-static + +#include <stdint.h> + +int main() { + uint8_t t0 = (~(uint32_t(0))); + // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:16 + // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-unsigned-integer-truncation {{.*}}summary.cpp:[[@LINE-2]]:16 + return 0; +} diff --git a/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation.c b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation.c new file mode 100644 index 000000000000..49d223ccda39 --- /dev/null +++ b/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation.c @@ -0,0 +1,304 @@ +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6 +// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7 + +#include <stdint.h> + +// Test plan: +// * Two types - int and char +// * Two signs - signed and unsigned +// * Square that - we have input and output types. +// Thus, there are total of (2*2)^2 == 16 tests. +// These are all the possible variations/combinations of casts. +// However, not all of them should result in the check. +// So here, we *only* check which should and which should not result in checks. + +uint32_t convert_unsigned_int_to_unsigned_int(uint32_t x) { +#line 100 + return x; +} + +uint8_t convert_unsigned_char_to_unsigned_char(uint8_t x) { +#line 200 + return x; +} + +int32_t convert_signed_int_to_signed_int(int32_t x) { +#line 300 + return x; +} + +int8_t convert_signed_char_to_signed_char(int8_t x) { +#line 400 + return x; +} + +uint8_t convert_unsigned_int_to_unsigned_char(uint32_t x) { +#line 500 + return x; +} + +uint32_t convert_unsigned_char_to_unsigned_int(uint8_t x) { +#line 600 + return x; +} + +int32_t convert_unsigned_char_to_signed_int(uint8_t x) { +#line 700 + return x; +} + +int32_t convert_signed_char_to_signed_int(int8_t x) { +#line 800 + return x; +} + +int32_t convert_unsigned_int_to_signed_int(uint32_t x) { +#line 900 + return x; +} + +uint32_t convert_signed_int_to_unsigned_int(int32_t x) { +#line 1000 + return x; +} + +uint8_t convert_signed_int_to_unsigned_char(int32_t x) { +#line 1100 + return x; +} + +uint8_t convert_signed_char_to_unsigned_char(int8_t x) { +#line 1200 + return x; +} + +int8_t convert_unsigned_char_to_signed_char(uint8_t x) { +#line 1300 + return x; +} + +uint32_t convert_signed_char_to_unsigned_int(int8_t x) { +#line 1400 + return x; +} + +int8_t convert_unsigned_int_to_signed_char(uint32_t x) { +#line 1500 + return x; +} + +int8_t convert_signed_int_to_signed_char(int32_t x) { +#line 1600 + return x; +} + +#line 1111 // !!! + +int main() { + // No bits set. + convert_unsigned_int_to_unsigned_int(0); + convert_unsigned_char_to_unsigned_char(0); + convert_signed_int_to_signed_int(0); + convert_signed_char_to_signed_char(0); + convert_unsigned_int_to_unsigned_char(0); + convert_unsigned_char_to_unsigned_int(0); + convert_unsigned_char_to_signed_int(0); + convert_signed_char_to_signed_int(0); + convert_unsigned_int_to_signed_int(0); + convert_signed_int_to_unsigned_int(0); + convert_signed_int_to_unsigned_char(0); + convert_signed_char_to_unsigned_char(0); + convert_unsigned_char_to_signed_char(0); + convert_signed_char_to_unsigned_int(0); + convert_unsigned_int_to_signed_char(0); + convert_signed_int_to_signed_char(0); + + // One lowest bit set. + convert_unsigned_int_to_unsigned_int(1); + convert_unsigned_char_to_unsigned_char(1); + convert_signed_int_to_signed_int(1); + convert_signed_char_to_signed_char(1); + convert_unsigned_int_to_unsigned_char(1); + convert_unsigned_char_to_unsigned_int(1); + convert_unsigned_char_to_signed_int(1); + convert_signed_char_to_signed_int(1); + convert_unsigned_int_to_signed_int(1); + convert_signed_int_to_unsigned_int(1); + convert_signed_int_to_unsigned_char(1); + convert_signed_char_to_unsigned_char(1); + convert_unsigned_char_to_signed_char(1); + convert_signed_char_to_unsigned_int(1); + convert_unsigned_int_to_signed_char(1); + convert_signed_int_to_signed_char(1); + +#if defined(V0) + // All source bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX); +// CHECK-V0: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX); + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX); + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX); +#elif defined(V1) + // Source 'Sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN); +// CHECK-V1: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN); + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN); + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN); +#elif defined(V2) + // All bits except the source 'Sign' bit are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX); +// CHECK-V2: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX); + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX); + convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX); +#elif defined(V3) + // All destination bits set. + convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX); + convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_signed_char((int8_t)UINT8_MAX); + convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX); + convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX); + convert_signed_char_to_signed_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX); + convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX); + convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX); + convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX); +#elif defined(V4) + // Destination 'sign' bit set. + convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN); +#elif defined(V5) + // All bits except the destination 'sign' bit are set. + convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V5: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN))); +#elif defined(V6) + // Only the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN); + convert_signed_int_to_signed_int((int32_t)INT32_MIN); + convert_signed_char_to_signed_char((int8_t)INT8_MIN); + convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)); +// CHECK-V6: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 128 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN); + convert_signed_char_to_signed_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_int((uint32_t)INT32_MIN); + convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_char_to_unsigned_char((int8_t)INT8_MIN); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN); + convert_signed_char_to_unsigned_int((int8_t)INT8_MIN); + convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +#elif defined(V7) + // All bits except the source and destination sign bits are set. + convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX); + convert_signed_int_to_signed_int((int32_t)INT32_MAX); + convert_signed_char_to_signed_char((int8_t)INT8_MAX); + convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +// CHECK-V7: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type '{{.*}}' (aka 'unsigned int') of value 2147483519 (32-bit, unsigned) to type '{{.*}}' (aka 'unsigned char') changed the value to 127 (8-bit, unsigned) + convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX); + convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX); + convert_signed_char_to_signed_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_int((uint32_t)INT32_MAX); + convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)))); + convert_signed_char_to_unsigned_char((int8_t)INT8_MAX); + convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX); + convert_signed_char_to_unsigned_int((int8_t)INT8_MAX); + convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); + convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))); +#else +#error Some V* needs to be defined! +#endif + + return 0; +} diff --git a/test/ubsan/TestCases/Integer/no-recover.cpp b/test/ubsan/TestCases/Integer/no-recover.cpp index 515ebbd0702e..45aeb9e75241 100644 --- a/test/ubsan/TestCases/Integer/no-recover.cpp +++ b/test/ubsan/TestCases/Integer/no-recover.cpp @@ -1,7 +1,9 @@ // RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER // RUN: %clangxx -fsanitize=unsigned-integer-overflow -fno-sanitize-recover=all -fsanitize-recover=unsigned-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER // RUN: %env_ubsan_opts=silence_unsigned_overflow=1 %run %t 2>&1 | FileCheck %s --check-prefix=SILENT-RECOVER --allow-empty -// RUN: %clangxx -fsanitize=unsigned-integer-overflow -fno-sanitize-recover=unsigned-integer-overflow %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=ABORT +// RUN: %clangxx -fsanitize=unsigned-integer-overflow -fno-sanitize-recover=unsigned-integer-overflow %s -o %t +// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=ABORT +// RUN: %env_ubsan_opts=silence_unsigned_overflow=1 not %run %t 2>&1 | FileCheck %s --check-prefix=ABORT #include <stdint.h> diff --git a/test/ubsan/TestCases/Misc/enum.cpp b/test/ubsan/TestCases/Misc/enum.cpp index 5dbecf161262..8e95f8b403a9 100644 --- a/test/ubsan/TestCases/Misc/enum.cpp +++ b/test/ubsan/TestCases/Misc/enum.cpp @@ -4,7 +4,7 @@ // FIXME: UBSan fails to add the correct instrumentation code for some reason on // Windows. -// XFAIL: win32 +// XFAIL: windows-msvc enum E { a = 1 } e; #undef E diff --git a/test/ubsan/TestCases/Misc/log-path_test.cc b/test/ubsan/TestCases/Misc/log-path_test.cc index 40bb35a06aaf..23ad7e27d21f 100644 --- a/test/ubsan/TestCases/Misc/log-path_test.cc +++ b/test/ubsan/TestCases/Misc/log-path_test.cc @@ -12,16 +12,18 @@ // Good log_path. // RUN: rm -f %t.log.* +// RUN: %device_rm -f '%t.log.*' // RUN: %env_ubsan_opts=log_path='"%t.log"' %run %t -4 2> %t.out // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.* // Run w/o errors should not produce any log. // RUN: rm -f %t.log.* +// RUN: %device_rm -f '%t.log.*' // RUN: %env_ubsan_opts=log_path='"%t.log"' %run %t 4 // RUN: not cat %t.log.* // FIXME: log_path is not supported on Windows yet. -// XFAIL: win32 +// XFAIL: windows-msvc #include <stdio.h> #include <stdlib.h> diff --git a/test/ubsan/TestCases/Misc/monitor.cpp b/test/ubsan/TestCases/Misc/monitor.cpp index 6c5cacfed8be..c02702847afb 100644 --- a/test/ubsan/TestCases/Misc/monitor.cpp +++ b/test/ubsan/TestCases/Misc/monitor.cpp @@ -4,7 +4,7 @@ // __ubsan_on_report is not defined as weak. Redefining it here isn't supported // on Windows. // -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc // Linkage issue // XFAIL: openbsd diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-align_value-on-lvalue.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-align_value-on-lvalue.cpp new file mode 100644 index 000000000000..97d4b4623c2d --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-align_value-on-lvalue.cpp @@ -0,0 +1,36 @@ +// RUN: %clang -x c -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +// RUN: %clang -x c++ -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +#include <stdlib.h> + +typedef char *__attribute__((align_value(0x8000))) aligned_char; + +struct ac_struct { + aligned_char a; +}; + +char *load_from_ac_struct(struct ac_struct *x) { + return x->a; +} + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(2); + + struct ac_struct x; + x.a = ptr + 1; // FIXME: it is weird that this does not also have an assumption. + load_from_ac_struct(&x); + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-9]]:13: runtime error: assumption of 32768 byte alignment for pointer of type 'aligned_char' (aka 'char *') failed + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-17]]:30: note: alignment assumption was specified here + // CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte + + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-align_value-on-paramvar.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-align_value-on-paramvar.cpp new file mode 100644 index 000000000000..774ba90fbe92 --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-align_value-on-paramvar.cpp @@ -0,0 +1,30 @@ +// RUN: %clang -x c -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +// RUN: %clang -x c++ -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +#include <stdlib.h> + +char *passthrough(__attribute__((align_value(0x8000))) char *x) { + return x; +} + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(2); + + passthrough(ptr + 1); + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-7]]:10: runtime error: assumption of 32768 byte alignment for pointer of type 'char *' failed + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-9]]:34: note: alignment assumption was specified here + // CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte + + // FIXME: shouldn't there be an assumption on the caller's side too? + + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-alloc_align-on-function-variable.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-alloc_align-on-function-variable.cpp new file mode 100644 index 000000000000..c71cb1e1bc7b --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-alloc_align-on-function-variable.cpp @@ -0,0 +1,33 @@ +// RUN: %clang -x c -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +// RUN: %clang -x c++ -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +#include <stdlib.h> + +char *__attribute__((alloc_align(2))) +passthrough(char *x, unsigned long alignment) { + return x; +} + +unsigned long alignment; + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(2); + + alignment = 0x8000; + + passthrough(ptr + 1, alignment); + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-1]]:3: runtime error: assumption of 32768 byte alignment for pointer of type 'char *' failed + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-14]]:22: note: alignment assumption was specified here + // CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte + + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-alloc_align-on-function.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-alloc_align-on-function.cpp new file mode 100644 index 000000000000..db22e3a8fcff --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-alloc_align-on-function.cpp @@ -0,0 +1,29 @@ +// RUN: %clang -x c -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +// RUN: %clang -x c++ -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +#include <stdlib.h> + +char *__attribute__((alloc_align(2))) +passthrough(char *x, unsigned long alignment) { + return x; +} + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(2); + + passthrough(ptr + 1, 0x8000); + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-1]]:3: runtime error: assumption of 32768 byte alignment for pointer of type 'char *' failed + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-10]]:22: note: alignment assumption was specified here + // CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte + + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-assume_aligned-on-function-two-params.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-assume_aligned-on-function-two-params.cpp new file mode 100644 index 000000000000..33aa132f601b --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-assume_aligned-on-function-two-params.cpp @@ -0,0 +1,28 @@ +// RUN: %clang -x c -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +// RUN: %clang -x c++ -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +#include <stdlib.h> + +char *__attribute__((assume_aligned(0x8000, 1))) passthrough(char *x) { + return x; +} + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(3); + + passthrough(ptr + 2); + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-1]]:3: runtime error: assumption of 32768 byte alignment (with offset of 1 byte) for pointer of type 'char *' failed + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-9]]:22: note: alignment assumption was specified here + // CHECK: 0x{{.*}}: note: offset address is {{.*}} aligned, misalignment offset is {{.*}} byte + + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-assume_aligned-on-function.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-assume_aligned-on-function.cpp new file mode 100644 index 000000000000..202c0ce00639 --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-attribute-assume_aligned-on-function.cpp @@ -0,0 +1,28 @@ +// RUN: %clang -x c -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +// RUN: %clang -x c++ -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +#include <stdlib.h> + +char *__attribute__((assume_aligned(0x8000))) passthrough(char *x) { + return x; +} + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(2); + + passthrough(ptr + 1); + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-1]]:3: runtime error: assumption of 32768 byte alignment for pointer of type 'char *' failed + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-9]]:22: note: alignment assumption was specified here + // CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte + + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-blacklist.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-blacklist.cpp new file mode 100644 index 000000000000..c0c7b373f623 --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-blacklist.cpp @@ -0,0 +1,20 @@ +// RUN: %clang -fsanitize=alignment -fno-sanitize-recover=alignment -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " + +// RUN: rm -f %tmp +// RUN: echo "[alignment]" >> %tmp +// RUN: echo "fun:main" >> %tmp +// RUN: %clang -fsanitize=alignment -fno-sanitize-recover=alignment -fsanitize-blacklist=%tmp -O0 %s -o %t && %run %t 2>&1 + +#include <stdlib.h> + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(2); + + __builtin_assume_aligned(ptr + 1, 0x8000); + // CHECK: {{.*}}alignment-assumption-blacklist.cpp:[[@LINE-1]]:32: runtime error: assumption of 32768 byte alignment for pointer of type 'char *' failed + // CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte + + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-builtin_assume_aligned-three-params-variable.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-builtin_assume_aligned-three-params-variable.cpp new file mode 100644 index 000000000000..cc4e1f2184da --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-builtin_assume_aligned-three-params-variable.cpp @@ -0,0 +1,27 @@ +// RUN: %clang -x c -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +// RUN: %clang -x c++ -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +#include <stdlib.h> + +volatile long offset; + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(3); + + offset = 1; + + __builtin_assume_aligned(ptr + 2, 0x8000, offset); + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-1]]:32: runtime error: assumption of 32768 byte alignment (with offset of 1 byte) for pointer of type 'char *' failed + // CHECK: 0x{{.*}}: note: offset address is {{.*}} aligned, misalignment offset is {{.*}} byte + + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-builtin_assume_aligned-three-params.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-builtin_assume_aligned-three-params.cpp new file mode 100644 index 000000000000..724abd540e78 --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-builtin_assume_aligned-three-params.cpp @@ -0,0 +1,23 @@ +// RUN: %clang -x c -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +// RUN: %clang -x c++ -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +#include <stdlib.h> + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(3); + + __builtin_assume_aligned(ptr + 2, 0x8000, 1); + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-1]]:32: runtime error: assumption of 32768 byte alignment (with offset of 1 byte) for pointer of type 'char *' failed + // CHECK: 0x{{.*}}: note: offset address is {{.*}} aligned, misalignment offset is {{.*}} byte + + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-builtin_assume_aligned-two-params.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-builtin_assume_aligned-two-params.cpp new file mode 100644 index 000000000000..2737f3d08b44 --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-builtin_assume_aligned-two-params.cpp @@ -0,0 +1,23 @@ +// RUN: %clang -x c -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +// RUN: %clang -x c++ -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +#include <stdlib.h> + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(2); + + __builtin_assume_aligned(ptr + 1, 0x8000); + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-1]]:32: runtime error: assumption of 32768 byte alignment for pointer of type 'char *' failed + // CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte + + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-openmp.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-openmp.cpp new file mode 100644 index 000000000000..482316ee254f --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-openmp.cpp @@ -0,0 +1,28 @@ +// RUN: %clang -x c -fsanitize=alignment -fopenmp-simd -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -fopenmp-simd -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -fopenmp-simd -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c -fsanitize=alignment -fopenmp-simd -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +// RUN: %clang -x c++ -fsanitize=alignment -fopenmp-simd -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -fopenmp-simd -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -fopenmp-simd -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" +// RUN: %clang -x c++ -fsanitize=alignment -fopenmp-simd -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="error:" + +#include <stdlib.h> + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(2); + char *data = ptr + 1; + + data[0] = 0; + +#pragma omp for simd aligned(data : 0x8000) + for(int x = 0; x < 1; x++) + data[x] = data[x]; + // CHECK: {{.*}}alignment-assumption-{{.*}}.cpp:[[@LINE-3]]:30: runtime error: assumption of 32768 byte alignment for pointer of type 'char *' failed + // CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte + + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/alignment-assumption-summary.cpp b/test/ubsan/TestCases/Pointer/alignment-assumption-summary.cpp new file mode 100644 index 000000000000..cc7769a06fe5 --- /dev/null +++ b/test/ubsan/TestCases/Pointer/alignment-assumption-summary.cpp @@ -0,0 +1,17 @@ +// RUN: %clangxx -fsanitize=alignment %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE +// RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE +// REQUIRES: !ubsan-standalone && !ubsan-standalone-static + +#include <stdlib.h> + +int main(int argc, char* argv[]) { + char *ptr = (char *)malloc(2); + + __builtin_assume_aligned(ptr + 1, 0x8000); + // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:32 + // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: alignment-assumption {{.*}}summary.cpp:[[@LINE-2]]:32 + free(ptr); + + return 0; +} diff --git a/test/ubsan/TestCases/Pointer/index-overflow.cpp b/test/ubsan/TestCases/Pointer/index-overflow.cpp index eb7f95e85c2c..f9b1fea08c94 100644 --- a/test/ubsan/TestCases/Pointer/index-overflow.cpp +++ b/test/ubsan/TestCases/Pointer/index-overflow.cpp @@ -1,7 +1,7 @@ // RUN: %clangxx -fsanitize=pointer-overflow %s -o %t -// RUN: %t 1 2>&1 | FileCheck %s --check-prefix=ERR -// RUN: %t 0 2>&1 | FileCheck %s --check-prefix=SAFE -// RUN: %t -1 2>&1 | FileCheck %s --check-prefix=SAFE +// RUN: %run %t 1 2>&1 | FileCheck %s --check-prefix=ERR +// RUN: %run %t 0 2>&1 | FileCheck %s --check-prefix=SAFE +// RUN: %run %t -1 2>&1 | FileCheck %s --check-prefix=SAFE #include <stdio.h> #include <stdint.h> diff --git a/test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp b/test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp index 0002c713f866..5a1432625a54 100644 --- a/test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp +++ b/test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp @@ -1,5 +1,5 @@ // RUN: %clangxx -std=c++11 -fsanitize=pointer-overflow %s -o %t -// RUN: %t 2>&1 | FileCheck %s +// RUN: %run %t 2>&1 | FileCheck %s int main(int argc, char *argv[]) { char c; diff --git a/test/ubsan/TestCases/TypeCheck/Function/function.cpp b/test/ubsan/TestCases/TypeCheck/Function/function.cpp index 7b9f0982639a..31baa2af8ca9 100644 --- a/test/ubsan/TestCases/TypeCheck/Function/function.cpp +++ b/test/ubsan/TestCases/TypeCheck/Function/function.cpp @@ -2,7 +2,7 @@ // RUN: %run %t 2>&1 | FileCheck %s // Verify that we can disable symbolization if needed: // RUN: %env_ubsan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM -// XFAIL: win32,win64 +// XFAIL: windows-msvc // Unsupported function flag // UNSUPPORTED: openbsd diff --git a/test/ubsan/TestCases/TypeCheck/PR33221.cpp b/test/ubsan/TestCases/TypeCheck/PR33221.cpp index 65cbf5d000d9..6088338a3dee 100644 --- a/test/ubsan/TestCases/TypeCheck/PR33221.cpp +++ b/test/ubsan/TestCases/TypeCheck/PR33221.cpp @@ -2,7 +2,7 @@ // RUN: %run %t 2>&1 | FileCheck %s // REQUIRES: cxxabi -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc #include <string.h> diff --git a/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp b/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp index f0659f439438..fd1e7ed779a6 100644 --- a/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp +++ b/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp @@ -1,7 +1,7 @@ // RUN: %clangxx -frtti -fsanitize=vptr -fno-sanitize-recover=vptr,null -g %s -O3 -o %t // RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-CORRUPTED-VTABLE --strict-whitespace -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc // REQUIRES: stable-runtime, cxxabi #include <cstddef> diff --git a/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp b/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp index 7bc19bdae8fa..13b05238610e 100644 --- a/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp +++ b/test/ubsan/TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp @@ -3,7 +3,8 @@ // RUN: %run %t // // REQUIRES: cxxabi -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc +// XFAIL: i386-netbsd struct X { virtual ~X() {} diff --git a/test/ubsan/TestCases/TypeCheck/vptr-virtual-base-construction.cpp b/test/ubsan/TestCases/TypeCheck/vptr-virtual-base-construction.cpp index a86960d12ad7..75a5d7670fb9 100644 --- a/test/ubsan/TestCases/TypeCheck/vptr-virtual-base-construction.cpp +++ b/test/ubsan/TestCases/TypeCheck/vptr-virtual-base-construction.cpp @@ -2,7 +2,7 @@ // RUN: %run %t // REQUIRES: cxxabi -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc int volatile n; diff --git a/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp b/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp index aa0123c46e9c..925373bdee1f 100644 --- a/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp +++ b/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp @@ -2,7 +2,9 @@ // RUN: not %run %t 2>&1 | FileCheck %s // REQUIRES: cxxabi -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc +// Nested crash reported +// UNSUPPORTED: freebsd struct S { virtual int f() { return 0; } }; struct T : virtual S {}; diff --git a/test/ubsan/TestCases/TypeCheck/vptr.cpp b/test/ubsan/TestCases/TypeCheck/vptr.cpp index 9b53e8095777..67239e82d340 100644 --- a/test/ubsan/TestCases/TypeCheck/vptr.cpp +++ b/test/ubsan/TestCases/TypeCheck/vptr.cpp @@ -37,11 +37,13 @@ // RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.loc-supp"' not %run %t x- 2>&1 | FileCheck %s --check-prefix=CHECK-LOC-SUPPRESS // REQUIRES: stable-runtime, cxxabi -// UNSUPPORTED: win32 +// UNSUPPORTED: windows-msvc // Suppressions file not pushed to the device. // UNSUPPORTED: android // Compilation error // UNSUPPORTED: openbsd +// Compilation error +// UNSUPPORTED: freebsd #include <new> #include <typeinfo> #include <assert.h> diff --git a/test/ubsan/lit.common.cfg b/test/ubsan/lit.common.cfg index e20832bd655f..9a7a8900e342 100644 --- a/test/ubsan/lit.common.cfg +++ b/test/ubsan/lit.common.cfg @@ -74,3 +74,8 @@ if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows', 'NetBSD', 'Su config.available_features.add('arch=' + config.target_arch) config.excludes = ['Inputs'] + +# Limit parallelism if necessary +if config.host_os == 'Darwin': + if config.apple_platform != "osx" and not config.apple_platform.endswith("sim"): + config.parallelism_group = "darwin-ios-device-sanitizer" diff --git a/test/ubsan/lit.site.cfg.in b/test/ubsan/lit.site.cfg.in index a4d7b50edafc..60c9c84e3c10 100644 --- a/test/ubsan/lit.site.cfg.in +++ b/test/ubsan/lit.site.cfg.in @@ -7,6 +7,7 @@ config.target_cflags = "@UBSAN_TEST_TARGET_CFLAGS@" config.target_arch = "@UBSAN_TEST_TARGET_ARCH@" config.use_lld = @UBSAN_TEST_USE_LLD@ config.use_thinlto = @UBSAN_TEST_USE_THINLTO@ +config.apple_platform = "@UBSAN_TEST_APPLE_PLATFORM@" # Load common config for all compiler-rt lit tests. lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") diff --git a/test/ubsan_minimal/TestCases/alignment-assumption.c b/test/ubsan_minimal/TestCases/alignment-assumption.c new file mode 100644 index 000000000000..ed6fff359296 --- /dev/null +++ b/test/ubsan_minimal/TestCases/alignment-assumption.c @@ -0,0 +1,17 @@ +// RUN: %clang -fsanitize=alignment %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK + +#include <stdlib.h> + +int main(int argc, char* argv[]) { +// CHECK-NOT: alignment-assumption + +char *ptr = (char *)malloc(2); + +__builtin_assume_aligned(ptr + 1, 0x8000); +// CHECK: alignment-assumption +// CHECK-NOT: alignment-assumption + +free(ptr); + +return 0; +} diff --git a/test/ubsan_minimal/TestCases/implicit-integer-sign-change.c b/test/ubsan_minimal/TestCases/implicit-integer-sign-change.c new file mode 100644 index 000000000000..1e208921922e --- /dev/null +++ b/test/ubsan_minimal/TestCases/implicit-integer-sign-change.c @@ -0,0 +1,17 @@ +// RUN: %clang -fsanitize=implicit-integer-sign-change %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK + +#include <stdint.h> + +int main() { +// CHECK-NOT: implicit-conversion + + // Explicitly casting hides it, + int32_t n0 = (int32_t)(~((uint32_t)0)); + + // Positive tests. + int32_t t0 = (~((uint32_t)0)); +// CHECK: implicit-conversion +// CHECK-NOT: implicit-conversion + + return 0; +} diff --git a/test/ubsan_minimal/TestCases/implicit-signed-integer-truncation-or-sign-change.c b/test/ubsan_minimal/TestCases/implicit-signed-integer-truncation-or-sign-change.c new file mode 100644 index 000000000000..3a72a406a8b0 --- /dev/null +++ b/test/ubsan_minimal/TestCases/implicit-signed-integer-truncation-or-sign-change.c @@ -0,0 +1,17 @@ +// RUN: %clang -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK + +#include <stdint.h> + +int main() { +// CHECK-NOT: implicit-conversion + + // Explicitly casting hides it, + int8_t n0 = (int8_t)((uint32_t)-1); + + // Positive tests. + int8_t t0 = (uint32_t)-1; +// CHECK: implicit-conversion +// CHECK-NOT: implicit-conversion + + return 0; +} diff --git a/test/ubsan_minimal/TestCases/implicit-signed-integer-truncation.c b/test/ubsan_minimal/TestCases/implicit-signed-integer-truncation.c new file mode 100644 index 000000000000..9677407e0ce0 --- /dev/null +++ b/test/ubsan_minimal/TestCases/implicit-signed-integer-truncation.c @@ -0,0 +1,25 @@ +// RUN: %clang -fsanitize=implicit-signed-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK + +#include <stdint.h> + +int main() { +// CHECK-NOT: implicit-conversion + + // Negative tests. Even if they produce unexpected results, this sanitizer does not care. + int8_t n0 = (~((uint32_t)(0))); // ~0 -> -1, but do not warn. + uint8_t n2 = 128; + uint8_t n3 = 255; + // Bools do not count + _Bool b0 = (~((uint32_t)(0))); + _Bool b1 = 255; + + // Explicit and-ing of bits will silence it. + uint8_t nc0 = ((int32_t)(-1)) & 255; + + // Positive tests. + uint8_t t0 = (int32_t)(-1); +// CHECK: implicit-conversion +// CHECK-NOT: implicit-conversion + + return 0; +} diff --git a/test/ubsan_minimal/TestCases/implicit-integer-truncation.c b/test/ubsan_minimal/TestCases/implicit-unsigned-integer-truncation.c index 1db6e6976815..8b9e166af812 100644 --- a/test/ubsan_minimal/TestCases/implicit-integer-truncation.c +++ b/test/ubsan_minimal/TestCases/implicit-unsigned-integer-truncation.c @@ -1,9 +1,9 @@ -// RUN: %clang -fsanitize=implicit-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK +// RUN: %clang -fsanitize=implicit-unsigned-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK #include <stdint.h> int main() { -// CHECK-NOT: integer-truncation.c +// CHECK-NOT: implicit-conversion // Negative tests. Even if they produce unexpected results, this sanitizer does not care. int8_t n0 = (~((uint32_t)(0))); // ~0 -> -1, but do not warn. @@ -19,6 +19,7 @@ int main() { // Positive tests. uint8_t t0 = (~((uint32_t)(0))); // CHECK: implicit-conversion +// CHECK-NOT: implicit-conversion return 0; } diff --git a/test/xray/TestCases/Posix/argv0-log-file-name.cc b/test/xray/TestCases/Posix/argv0-log-file-name.cc index 2f9a234f8064..a2cb11b4d0d9 100644 --- a/test/xray/TestCases/Posix/argv0-log-file-name.cc +++ b/test/xray/TestCases/Posix/argv0-log-file-name.cc @@ -4,7 +4,7 @@ // RUN: %clangxx_xray -std=c++11 %s -o %t // RUN: XRAY_OPTIONS="patch_premain=true xray_naive_log=true" %run %t > xray.log.file.name 2>&1 // RUN: ls | FileCheck xray.log.file.name -// RUN: rm xray-log.* xray.log.file.name +// RUN: rm xray-log.argv0-log-file-name.* xray.log.file.name // UNSUPPORTED: target-is-mips64,target-is-mips64el diff --git a/test/xray/TestCases/Posix/basic-filtering.cc b/test/xray/TestCases/Posix/basic-filtering.cc index db07ef510c5c..3d4f4dda2d72 100644 --- a/test/xray/TestCases/Posix/basic-filtering.cc +++ b/test/xray/TestCases/Posix/basic-filtering.cc @@ -57,5 +57,5 @@ always_shows() { // TRACE-NOT: - { type: 0, func-id: {{.*}}, function: {{.*filtered.*}}, {{.*}} } // TRACE-NOT: - { type: 0, func-id: {{.*}}, function: {{.*beyond_stack.*}}, {{.*}} } -// TRACE-DAG: - { type: 0, func-id: [[FID:[0-9]+]], function: {{.*always_shows.*}}, cpu: {{.*}}, thread: {{.*}}, kind: function-enter, tsc: {{[0-9]+}} } -// TRACE-DAG: - { type: 0, func-id: [[FID]], function: {{.*always_shows.*}}, cpu: {{.*}}, thread: {{.*}}, kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[FID:[0-9]+]], function: {{.*always_shows.*}}, cpu: {{.*}}, thread: {{.*}}, kind: function-enter, tsc: {{[0-9]+}}, data: '' } +// TRACE-DAG: - { type: 0, func-id: [[FID]], function: {{.*always_shows.*}}, cpu: {{.*}}, thread: {{.*}}, kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}}, data: '' } diff --git a/test/xray/TestCases/Posix/clang-no-xray-instrument.cc b/test/xray/TestCases/Posix/clang-no-xray-instrument.cc new file mode 100644 index 000000000000..c2444b18ab6e --- /dev/null +++ b/test/xray/TestCases/Posix/clang-no-xray-instrument.cc @@ -0,0 +1,11 @@ +// Test that we cannot actually find XRay instrumentation when we build with +// -fno-xray-instrument but have code that's marked as 'xray_always_instrument'. +// +// RUN: %clangxx -fno-xray-instrument -c %s -o %t.o +// RUN: not %llvm_xray extract -symbolize %t.o 2>&1 | FileCheck %s +// REQUIRES: x86_64-target-arch +// REQUIRES: built-in-llvm-tree + +// CHECK: llvm-xray: Cannot extract instrumentation map +// CHECK-NOT: {{.*always_instrumented.*}} +[[clang::xray_always_instrument]] int always_instrumented() { return 42; } diff --git a/test/xray/TestCases/Posix/fdr-mode.cc b/test/xray/TestCases/Posix/fdr-mode.cc index b12d97c0005a..8b9cb2bbfd53 100644 --- a/test/xray/TestCases/Posix/fdr-mode.cc +++ b/test/xray/TestCases/Posix/fdr-mode.cc @@ -42,7 +42,6 @@ thread_local uint64_t var = 0; void __attribute__((noinline)) fArg(int) { } int main(int argc, char *argv[]) { - using namespace __xray; std::cout << "Logging before init." << std::endl; // CHECK: Logging before init. assert(__xray_log_select_mode("xray-fdr") == @@ -81,32 +80,32 @@ int main(int argc, char *argv[]) { } // Check that we're able to see two threads, each entering and exiting fA(). -// TRACE-DAG: - { type: 0, func-id: [[FIDA:[0-9]+]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} } -// TRACE: - { type: 0, func-id: [[FIDA]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}} } -// TRACE-DAG: - { type: 0, func-id: [[FIDA]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}} } -// TRACE: - { type: 0, func-id: [[FIDA]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[FIDA:[0-9]+]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } +// TRACE: - { type: 0, func-id: [[FIDA]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}}, data: '' } +// TRACE-DAG: - { type: 0, func-id: [[FIDA]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } +// TRACE: - { type: 0, func-id: [[FIDA]], function: {{.*fA.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}}, data: '' } // // Do the same as above for fC() -// TRACE-DAG: - { type: 0, func-id: [[FIDC:[0-9]+]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}} } -// TRACE: - { type: 0, func-id: [[FIDC]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}} } -// TRACE-DAG: - { type: 0, func-id: [[FIDC]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}} } -// TRACE: - { type: 0, func-id: [[FIDC]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[FIDC:[0-9]+]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } +// TRACE: - { type: 0, func-id: [[FIDC]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}}, data: '' } +// TRACE-DAG: - { type: 0, func-id: [[FIDC]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } +// TRACE: - { type: 0, func-id: [[FIDC]], function: {{.*fC.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}}, data: '' } // Do the same as above for fB() -// TRACE-DAG: - { type: 0, func-id: [[FIDB:[0-9]+]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}} } -// TRACE: - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}} } -// TRACE-DAG: - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}} } -// TRACE: - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[FIDB:[0-9]+]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } +// TRACE: - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}}, data: '' } +// TRACE-DAG: - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } +// TRACE: - { type: 0, func-id: [[FIDB]], function: {{.*fB.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}}, data: '' } -// TRACE-DAG: - { type: 0, func-id: [[FIDARG:[0-9]+]], function: 'fArg(int)', args: [ 1 ], cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-enter-arg, tsc: {{[0-9]+}} } -// TRACE-DAG: - { type: 0, func-id: [[FIDARG]], function: 'fArg(int)', cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-exit, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[FIDARG:[0-9]+]], function: 'fArg(int)', args: [ 1 ], cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-enter-arg, tsc: {{[0-9]+}}, data: '' } +// TRACE-DAG: - { type: 0, func-id: [[FIDARG]], function: 'fArg(int)', cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-exit, tsc: {{[0-9]+}}, data: '' } // Assert that when unwriting is enabled with a high threshold time, all the function records are erased. A CPU switch could erroneously fail this test, but // is unlikely given the test program. // Even with a high threshold, arg1 logging is never unwritten. // UNWRITE: header: // UNWRITE: records: -// UNWRITE-NEXT: - { type: 0, func-id: [[FIDARG:[0-9]+]], function: 'fArg(int)', args: [ 1 ], cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS:[0-9]+]], kind: function-enter-arg, tsc: {{[0-9]+}} } -// UNWRITE-NEXT: - { type: 0, func-id: [[FIDARG]], function: 'fArg(int)', cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-exit, tsc: {{[0-9]+}} } +// UNWRITE-NEXT: - { type: 0, func-id: [[FIDARG:[0-9]+]], function: 'fArg(int)', args: [ 1 ], cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS:[0-9]+]], kind: function-enter-arg, tsc: {{[0-9]+}}, data: '' } +// UNWRITE-NEXT: - { type: 0, func-id: [[FIDARG]], function: 'fArg(int)', cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: function-exit, tsc: {{[0-9]+}}, data: '' } // UNWRITE-NOT: function-enter // UNWRITE-NOT: function-{{exit|tail-exit}} diff --git a/test/xray/TestCases/Posix/fdr-reinit.cc b/test/xray/TestCases/Posix/fdr-reinit.cc new file mode 100644 index 000000000000..dc9888d6e48a --- /dev/null +++ b/test/xray/TestCases/Posix/fdr-reinit.cc @@ -0,0 +1,73 @@ +// RUN: %clangxx_xray -g -std=c++11 %s -o %t +// RUN: rm xray-log.fdr-reinit* || true +// RUN: XRAY_OPTIONS="verbosity=1" %run %t +// RUN: rm xray-log.fdr-reinit* || true +#include "xray/xray_log_interface.h" +#include <atomic> +#include <cassert> +#include <cstddef> +#include <thread> + +volatile uint64_t var = 0; + +std::atomic_flag keep_going = ATOMIC_FLAG_INIT; + +[[clang::xray_always_instrument]] void __attribute__((noinline)) func() { + ++var; +} + +int main(int argc, char *argv[]) { + // Start a thread that will just keep calling the function, to spam calls to + // the function call handler. + keep_going.test_and_set(std::memory_order_acquire); + std::thread t([] { + while (keep_going.test_and_set(std::memory_order_acquire)) + func(); + }); + + static constexpr char kConfig[] = + "buffer_size=1024:buffer_max=10:no_file_flush=true"; + + // Then we initialize the FDR mode implementation. + assert(__xray_log_select_mode("xray-fdr") == + XRayLogRegisterStatus::XRAY_REGISTRATION_OK); + auto init_status = __xray_log_init_mode("xray-fdr", kConfig); + assert(init_status == XRayLogInitStatus::XRAY_LOG_INITIALIZED); + + // Now we patch the instrumentation points. + __xray_patch(); + + // Spin for a bit, calling func() enough times. + for (auto i = 0; i < 1 << 20; ++i) + func(); + + // Then immediately finalize the implementation. + auto finalize_status = __xray_log_finalize(); + assert(finalize_status == XRayLogInitStatus::XRAY_LOG_FINALIZED); + + // Once we're here, we should then flush. + auto flush_status = __xray_log_flushLog(); + assert(flush_status == XRayLogFlushStatus::XRAY_LOG_FLUSHED); + + // Without doing anything else, we should re-initialize. + init_status = __xray_log_init_mode("xray-fdr", kConfig); + assert(init_status == XRayLogInitStatus::XRAY_LOG_INITIALIZED); + + // Then we spin for a bit again calling func() enough times. + for (auto i = 0; i < 1 << 20; ++i) + func(); + + // Then immediately finalize the implementation. + finalize_status = __xray_log_finalize(); + assert(finalize_status == XRayLogInitStatus::XRAY_LOG_FINALIZED); + + // Once we're here, we should then flush. + flush_status = __xray_log_flushLog(); + assert(flush_status == XRayLogFlushStatus::XRAY_LOG_FLUSHED); + + // Finally, we should signal the sibling thread to stop. + keep_going.clear(std::memory_order_release); + + // Then join. + t.join(); +} diff --git a/test/xray/TestCases/Posix/fdr-single-thread.cc b/test/xray/TestCases/Posix/fdr-single-thread.cc index 480502b0a60f..accc5925c682 100644 --- a/test/xray/TestCases/Posix/fdr-single-thread.cc +++ b/test/xray/TestCases/Posix/fdr-single-thread.cc @@ -13,16 +13,10 @@ #include "xray/xray_log_interface.h" #include <cassert> -constexpr auto kBufferSize = 16384; -constexpr auto kBufferMax = 10; - [[clang::xray_always_instrument]] void __attribute__((noinline)) fn() { } int main(int argc, char *argv[]) { - using namespace __xray; - FDRLoggingOptions Opts; - - auto status = __xray_log_init(kBufferSize, kBufferMax, &Opts, sizeof(Opts)); + auto status = __xray_log_init_mode("xray-fdr", ""); assert(status == XRayLogInitStatus::XRAY_LOG_INITIALIZED); __xray_patch(); @@ -34,5 +28,5 @@ int main(int argc, char *argv[]) { } // CHECK: records: -// CHECK-NEXT: - { type: 0, func-id: [[FID1:[0-9]+]], function: {{.*fn.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} } -// CHECK-NEXT: - { type: 0, func-id: [[FID1:[0-9]+]], function: {{.*fn.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS:[0-9]+]], kind: function-exit, tsc: {{[0-9]+}} } +// CHECK-NEXT: - { type: 0, func-id: [[FID1:[0-9]+]], function: {{.*fn.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } +// CHECK-NEXT: - { type: 0, func-id: [[FID1:[0-9]+]], function: {{.*fn.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS:[0-9]+]], kind: function-exit, tsc: {{[0-9]+}}, data: '' } diff --git a/test/xray/TestCases/Posix/fdr-thread-order.cc b/test/xray/TestCases/Posix/fdr-thread-order.cc index 1d6b01759f14..eb405967a0d8 100644 --- a/test/xray/TestCases/Posix/fdr-thread-order.cc +++ b/test/xray/TestCases/Posix/fdr-thread-order.cc @@ -1,15 +1,12 @@ -// RUN: %clangxx_xray -g -std=c++11 %s -o %t -// RUN: rm fdr-thread-order.* || true -// RUN: XRAY_OPTIONS="patch_premain=false xray_naive_log=false \ -// RUN: xray_logfile_base=fdr-thread-order. xray_fdr_log=true verbosity=1 \ -// RUN: xray_fdr_log_func_duration_threshold_us=0" %run %t 2>&1 | \ +// RUN: rm -rf %t && mkdir %t +// RUN: %clangxx_xray -g -std=c++11 %s -o %t.exe +// RUN: XRAY_OPTIONS="patch_premain=false \ +// RUN: xray_logfile_base=%t/ xray_mode=xray-fdr verbosity=1" \ +// RUN: XRAY_FDR_OPTIONS=func_duration_threshold_us=0 %run %t.exe 2>&1 | \ // RUN: FileCheck %s -// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t \ -// RUN: "`ls fdr-thread-order.* | head -1`" -// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t \ -// RUN: "`ls fdr-thread-order.* | head -1`" | \ -// RUN: FileCheck %s --check-prefix TRACE -// RUN: rm fdr-thread-order.* +// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t.exe %t/* +// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t.exe %t/* | \ +// RUN: FileCheck %s --check-prefix TRACE // FIXME: Make llvm-xray work on non-x86_64 as well. // REQUIRES: x86_64-target-arch // REQUIRES: built-in-llvm-tree @@ -19,9 +16,6 @@ #include <cassert> #include <thread> -constexpr auto kBufferSize = 16384; -constexpr auto kBufferMax = 10; - std::atomic<uint64_t> var{0}; [[clang::xray_always_instrument]] void __attribute__((noinline)) f1() { @@ -35,11 +29,8 @@ std::atomic<uint64_t> var{0}; } int main(int argc, char *argv[]) { - using namespace __xray; - FDRLoggingOptions Options; __xray_patch(); - assert(__xray_log_init(kBufferSize, kBufferMax, &Options, - sizeof(FDRLoggingOptions)) == + assert(__xray_log_init_mode("xray-fdr", "") == XRayLogInitStatus::XRAY_LOG_INITIALIZED); std::atomic_thread_fence(std::memory_order_acq_rel); @@ -61,7 +52,7 @@ int main(int argc, char *argv[]) { } // We want to make sure that the order of the function log doesn't matter. -// TRACE-DAG: - { type: 0, func-id: [[FID1:[0-9]+]], function: {{.*f1.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} } -// TRACE-DAG: - { type: 0, func-id: [[FID2:[0-9]+]], function: {{.*f2.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}} } -// TRACE-DAG: - { type: 0, func-id: [[FID1]], function: {{.*f1.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS]], kind: {{function-exit|function-tail-exit}}, tsc: {{[0-9]+}} } -// TRACE-DAG: - { type: 0, func-id: [[FID2]], function: {{.*f2.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: {{function-exit|function-tail-exit}}, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[FID1:[0-9]+]], function: {{.*f1.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } +// TRACE-DAG: - { type: 0, func-id: [[FID2:[0-9]+]], function: {{.*f2.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } +// TRACE-DAG: - { type: 0, func-id: [[FID1]], function: {{.*f1.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS]], kind: {{function-exit|function-tail-exit}}, tsc: {{[0-9]+}}, data: '' } +// TRACE-DAG: - { type: 0, func-id: [[FID2]], function: {{.*f2.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: {{function-exit|function-tail-exit}}, tsc: {{[0-9]+}}, data: '' } diff --git a/test/xray/TestCases/Posix/fork_basic_logging.cc b/test/xray/TestCases/Posix/fork_basic_logging.cc index 5aefdec08016..3873325ef746 100644 --- a/test/xray/TestCases/Posix/fork_basic_logging.cc +++ b/test/xray/TestCases/Posix/fork_basic_logging.cc @@ -11,6 +11,9 @@ // REQUIRES: x86_64-target-arch // REQUIRES: built-in-llvm-tree +// Not ported. +// UNSUPPORTED: netbsd + #include "xray/xray_log_interface.h" #include <stdio.h> #include <unistd.h> @@ -81,20 +84,20 @@ int main() } // Make sure we know which thread is the parent process -// TRACE-DAG: - { type: 0, func-id: [[LSGT:[0-9]+]], function: {{.*log_syscall_gettid.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS1:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[LSGT:[0-9]+]], function: {{.*log_syscall_gettid.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS1:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } -// TRACE-DAG: - { type: 0, func-id: [[PPOC:[0-9]+]], function: {{.*print_parent_or_child.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS1]], kind: function-enter, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[PPOC:[0-9]+]], function: {{.*print_parent_or_child.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS1]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } // // The parent will print its pid -// TRACE-DAG: - { type: 0, func-id: [[PPTARG:[0-9]+]], function: {{.*print_parent_tid.*}}, args: [ [[THREAD1]] ], cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS1]], kind: function-enter-arg, tsc: {{[0-9]+}} } -// TRACE-DAG: - { type: 0, func-id: [[PPTARG]], function: {{.*print_parent_tid.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS1]], kind: function-exit, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[PPTARG:[0-9]+]], function: {{.*print_parent_tid.*}}, args: [ [[THREAD1]] ], cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS1]], kind: function-enter-arg, tsc: {{[0-9]+}}, data: '' } +// TRACE-DAG: - { type: 0, func-id: [[PPTARG]], function: {{.*print_parent_tid.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS1]], kind: function-exit, tsc: {{[0-9]+}}, data: '' } // -// TRACE-DAG - { type: 0, func-id: [[PPOC]], function: {{.*print_parent_or_child.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS1]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}} } +// TRACE-DAG - { type: 0, func-id: [[PPOC]], function: {{.*print_parent_or_child.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS1]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}}, data: '' } -// TRACE-DAG: - { type: 0, func-id: [[PPOC]], function: {{.*print_parent_or_child.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS2:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[PPOC]], function: {{.*print_parent_or_child.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS2:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}}, data: '' } // // The child will print its pid -// TRACE-DAG: - { type: 0, func-id: [[PCTARG:[0-9]+]], function: {{.*print_child_tid.*}}, args: [ [[THREAD2]] ], cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS2]], kind: function-enter-arg, tsc: {{[0-9]+}} } -// TRACE-DAG: - { type: 0, func-id: [[PCTARG]], function: {{.*print_child_tid.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS2]], kind: function-exit, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[PCTARG:[0-9]+]], function: {{.*print_child_tid.*}}, args: [ [[THREAD2]] ], cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS2]], kind: function-enter-arg, tsc: {{[0-9]+}}, data: '' } +// TRACE-DAG: - { type: 0, func-id: [[PCTARG]], function: {{.*print_child_tid.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS2]], kind: function-exit, tsc: {{[0-9]+}}, data: '' } // -// TRACE-DAG: - { type: 0, func-id: [[PPOC]], function: {{.*print_parent_or_child.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS2]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}} } +// TRACE-DAG: - { type: 0, func-id: [[PPOC]], function: {{.*print_parent_or_child.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS2]], kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}}, data: '' } diff --git a/test/xray/TestCases/Posix/profiling-multi-threaded.cc b/test/xray/TestCases/Posix/profiling-multi-threaded.cc index 45e5e70226da..8bd15b7d312d 100644 --- a/test/xray/TestCases/Posix/profiling-multi-threaded.cc +++ b/test/xray/TestCases/Posix/profiling-multi-threaded.cc @@ -41,7 +41,7 @@ volatile int buffer_counter = 0; std::string current_mode = __xray_log_get_current_mode(); assert(current_mode == "xray-profiling"); assert(__xray_patch() == XRayPatchingStatus::SUCCESS); - assert(__xray_log_init(0, 0, nullptr, 0) == + assert(__xray_log_init_mode("xray-profiling", "") == XRayLogInitStatus::XRAY_LOG_INITIALIZED); std::thread t0([] { f0(); }); std::thread t1([] { f0(); }); diff --git a/test/xray/Unit/lit.site.cfg.in b/test/xray/Unit/lit.site.cfg.in index be860deafd08..54fcc1cbd23c 100644 --- a/test/xray/Unit/lit.site.cfg.in +++ b/test/xray/Unit/lit.site.cfg.in @@ -14,3 +14,11 @@ config.test_source_root = config.test_exec_root # Do not patch the XRay unit tests pre-main, and also make the error logging # verbose to get a more accurate error logging mechanism. config.environment['XRAY_OPTIONS'] = 'patch_premain=false' + +# Add the LLVM Library directory to the LD_LIBRARY_PATH to allow tests to look +# up the shared libraries. +if 'LD_LIBRARY_PATH' in os.environ: + libdirs = os.path.pathsep.join((config.llvm_lib_dir, os.environ['LD_LIBRARY_PATH'])) + config.environment['LD_LIBRARY_PATH'] = libdirs +else: + config.environment['LD_LIBRARY_PATH'] = config.llvm_lib_dir |