diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-24 01:00:33 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-24 01:00:33 +0000 |
| commit | 46d7550315cd1db7e0cdf313e2702222751d8a24 (patch) | |
| tree | 7c8ad1d503cf19120d55ce098d2f8bd1534fa721 /test | |
| parent | cdf4f3055e964bb585f294cf77cb549ead82783f (diff) | |
Notes
Diffstat (limited to 'test')
| -rw-r--r-- | test/asan/TestCases/Linux/aligned_delete_test.cc | 34 | ||||
| -rw-r--r-- | test/hwasan/TestCases/halt-on-error.cc | 38 | ||||
| -rw-r--r-- | test/hwasan/TestCases/use-after-free.cc | 29 | ||||
| -rw-r--r-- | test/sanitizer_common/TestCases/Linux/new_delete_test.cc | 80 | ||||
| -rw-r--r-- | test/ubsan/TestCases/Misc/Inputs/returns-unexpectedly.c | 1 | ||||
| -rw-r--r-- | test/ubsan/TestCases/Misc/unreachable.cpp | 25 |
6 files changed, 153 insertions, 54 deletions
diff --git a/test/asan/TestCases/Linux/aligned_delete_test.cc b/test/asan/TestCases/Linux/aligned_delete_test.cc index 5b9455e56553d..9117198f91daf 100644 --- a/test/asan/TestCases/Linux/aligned_delete_test.cc +++ b/test/asan/TestCases/Linux/aligned_delete_test.cc @@ -6,12 +6,10 @@ // RUN: %env_asan_opts=new_delete_type_mismatch=1:halt_on_error=false:detect_leaks=false %run %t 2>&1 | FileCheck %s // RUN: %env_asan_opts=new_delete_type_mismatch=0 %run %t -// REQUIRES: asan-static-runtime - #include <stdio.h> // Define all new/delete to do not depend on the version provided by the -// plaform. The implementation is provided by ASan anyway. +// platform. The implementation is provided by ASan anyway. namespace std { struct nothrow_t {}; @@ -57,34 +55,8 @@ struct alignas(1024) S1024_1024 { char a[1024]; }; int main(int argc, char **argv) { - fprintf(stderr, "Testing valid cases\n"); - - delete break_optimization(new S12); - operator delete(break_optimization(new S12), std::nothrow); - delete [] break_optimization(new S12[100]); - operator delete[](break_optimization(new S12[100]), std::nothrow); - - delete break_optimization(new S12_128); - operator delete(break_optimization(new S12_128), - std::align_val_t(alignof(S12_128))); - operator delete(break_optimization(new S12_128), - std::align_val_t(alignof(S12_128)), std::nothrow); - operator delete(break_optimization(new S12_128), sizeof(S12_128), - std::align_val_t(alignof(S12_128))); - - delete [] break_optimization(new S12_128[100]); - operator delete[](break_optimization(new S12_128[100]), - std::align_val_t(alignof(S12_128))); - operator delete[](break_optimization(new S12_128[100]), - std::align_val_t(alignof(S12_128)), std::nothrow); - operator delete[](break_optimization(new S12_128[100]), sizeof(S12_128[100]), - std::align_val_t(alignof(S12_128))); - - fprintf(stderr, "Done\n"); - // CHECK: Testing valid cases - // CHECK-NEXT: Done - - // Explicit mismatched calls. + // Check the mismatched calls only, all the valid cases are verified in + // test/sanitizer_common/TestCases/Linux/new_delete_test.cc. operator delete(break_optimization(new S12_128), std::nothrow); // CHECK: AddressSanitizer: new-delete-type-mismatch diff --git a/test/hwasan/TestCases/halt-on-error.cc b/test/hwasan/TestCases/halt-on-error.cc index 97693d5bceba8..fdf6d27d7939b 100644 --- a/test/hwasan/TestCases/halt-on-error.cc +++ b/test/hwasan/TestCases/halt-on-error.cc @@ -1,4 +1,19 @@ -// RUN: %clangxx_hwasan -O0 %s -o %t && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK +// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=COMMON +// RUN: %clangxx_hwasan -O0 %s -o %t && not %env_hwasan_opts=halt_on_error=1 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON +// RUN: %clangxx_hwasan -O0 %s -o %t && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON + +// RUN: %clangxx_hwasan -O0 %s -o %t -fsanitize-recover=hwaddress && not %run %t 2>&1 | FileCheck %s --check-prefix=COMMON +// RUN: %clangxx_hwasan -O0 %s -o %t -fsanitize-recover=hwaddress && not %env_hwasan_opts=halt_on_error=1 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON +// RUN: %clangxx_hwasan -O0 %s -o %t -fsanitize-recover=hwaddress && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefixes=COMMON,RECOVER + +// RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=COMMON +// RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t && not %env_hwasan_opts=halt_on_error=1 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON +// RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON + +// RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t -fsanitize-recover=hwaddress && not %run %t 2>&1 | FileCheck %s --check-prefix=COMMON +// RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t -fsanitize-recover=hwaddress && not %env_hwasan_opts=halt_on_error=1 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON +// RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t -fsanitize-recover=hwaddress && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefixes=COMMON,RECOVER + // REQUIRES: stable-runtime #include <stdlib.h> @@ -10,17 +25,18 @@ int main() { free(x); __hwasan_disable_allocator_tagging(); return x[2] + ((char *)x)[6] + ((char *)x)[9]; - // CHECK: READ of size 4 at - // CHECK: #0 {{.*}} in main {{.*}}halt-on-error.cc:12 - // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main + // COMMON: READ of size 4 at + // When instrumenting with callbacks, main is actually #1, and #0 is __hwasan_load4. + // COMMON: #{{.*}} in main {{.*}}halt-on-error.cc:27 + // COMMON: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in - // CHECK: READ of size 1 at - // CHECK: #0 {{.*}} in main {{.*}}halt-on-error.cc:12 - // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main + // RECOVER: READ of size 1 at + // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cc:27 + // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in - // CHECK: READ of size 1 at - // CHECK: #0 {{.*}} in main {{.*}}halt-on-error.cc:12 - // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main + // RECOVER: READ of size 1 at + // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cc:27 + // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in - // CHECK-NOT: tag-mismatch + // COMMON-NOT: tag-mismatch } diff --git a/test/hwasan/TestCases/use-after-free.cc b/test/hwasan/TestCases/use-after-free.cc index a4d3ee89509fd..37637898d7a1a 100644 --- a/test/hwasan/TestCases/use-after-free.cc +++ b/test/hwasan/TestCases/use-after-free.cc @@ -1,7 +1,10 @@ -// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK -// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK -// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK -// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK +// RUN: %clangxx_hwasan -O0 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD +// RUN: %clangxx_hwasan -O1 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD +// RUN: %clangxx_hwasan -O2 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD +// RUN: %clangxx_hwasan -O3 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD + +// RUN: %clangxx_hwasan -O0 -DSTORE %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,STORE + // REQUIRES: stable-runtime #include <stdlib.h> @@ -9,20 +12,28 @@ int main() { __hwasan_enable_allocator_tagging(); - char *x = (char*)malloc(10); + char * volatile x = (char*)malloc(10); free(x); __hwasan_disable_allocator_tagging(); +#ifdef STORE + x[5] = 42; +#endif +#ifdef LOAD return x[5]; - // CHECK: READ of size 1 at - // CHECK: #0 {{.*}} in main {{.*}}use-after-free.cc:15 +#endif + // LOAD: READ of size 1 at + // LOAD: #0 {{.*}} in main {{.*}}use-after-free.cc:22 + + // STORE: WRITE of size 1 at + // STORE: #0 {{.*}} in main {{.*}}use-after-free.cc:19 // CHECK: freed here: // CHECK: #0 {{.*}} in free {{.*}}hwasan_interceptors.cc - // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:13 + // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:16 // CHECK: previously allocated here: // CHECK: #0 {{.*}} in __interceptor_malloc {{.*}}hwasan_interceptors.cc - // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:12 + // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:15 // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main } diff --git a/test/sanitizer_common/TestCases/Linux/new_delete_test.cc b/test/sanitizer_common/TestCases/Linux/new_delete_test.cc new file mode 100644 index 0000000000000..5e5346a08df49 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/new_delete_test.cc @@ -0,0 +1,80 @@ +// RUN: %clangxx -std=c++1z -faligned-allocation -O0 %s -o %t && %run %t +// RUN: %clangxx -std=c++1z -faligned-allocation -fsized-deallocation -O0 %s -o %t && %run %t + +// ubsan does not intercept new/delete. +// UNSUPPORTED: ubsan + +// Check that all new/delete variants are defined and work with supported +// sanitizers. Sanitizer-specific failure modes tests are supposed to go to +// the particular sanitizier's test suites. + +#include <cstddef> + +// Define all new/delete to do not depend on the version provided by the +// platform. The implementation is provided by the sanitizer anyway. + +namespace std { +struct nothrow_t {}; +static const nothrow_t nothrow; +enum class align_val_t : size_t {}; +} // namespace std + +void *operator new(size_t); +void *operator new[](size_t); +void *operator new(size_t, std::nothrow_t const&); +void *operator new[](size_t, std::nothrow_t const&); +void *operator new(size_t, std::align_val_t); +void *operator new[](size_t, std::align_val_t); +void *operator new(size_t, std::align_val_t, std::nothrow_t const&); +void *operator new[](size_t, std::align_val_t, std::nothrow_t const&); + +void operator delete(void*) throw(); +void operator delete[](void*) throw(); +void operator delete(void*, std::nothrow_t const&); +void operator delete[](void*, std::nothrow_t const&); +void operator delete(void*, size_t) throw(); +void operator delete[](void*, size_t) throw(); +void operator delete(void*, std::align_val_t) throw(); +void operator delete[](void*, std::align_val_t) throw(); +void operator delete(void*, std::align_val_t, std::nothrow_t const&); +void operator delete[](void*, std::align_val_t, std::nothrow_t const&); +void operator delete(void*, size_t, std::align_val_t) throw(); +void operator delete[](void*, size_t, std::align_val_t) throw(); + + +template<typename T> +inline T* break_optimization(T *arg) { + __asm__ __volatile__("" : : "r" (arg) : "memory"); + return arg; +} + + +struct S12 { int a, b, c; }; +struct alignas(128) S12_128 { int a, b, c; }; +struct alignas(256) S12_256 { int a, b, c; }; +struct alignas(512) S1024_512 { char a[1024]; }; +struct alignas(1024) S1024_1024 { char a[1024]; }; + + +int main(int argc, char **argv) { + delete break_optimization(new S12); + operator delete(break_optimization(new S12), std::nothrow); + delete [] break_optimization(new S12[100]); + operator delete[](break_optimization(new S12[100]), std::nothrow); + + delete break_optimization(new S12_128); + operator delete(break_optimization(new S12_128), + std::align_val_t(alignof(S12_128))); + operator delete(break_optimization(new S12_128), + std::align_val_t(alignof(S12_128)), std::nothrow); + operator delete(break_optimization(new S12_128), sizeof(S12_128), + std::align_val_t(alignof(S12_128))); + + delete [] break_optimization(new S12_128[100]); + operator delete[](break_optimization(new S12_128[100]), + std::align_val_t(alignof(S12_128))); + operator delete[](break_optimization(new S12_128[100]), + std::align_val_t(alignof(S12_128)), std::nothrow); + operator delete[](break_optimization(new S12_128[100]), sizeof(S12_128[100]), + std::align_val_t(alignof(S12_128))); +} diff --git a/test/ubsan/TestCases/Misc/Inputs/returns-unexpectedly.c b/test/ubsan/TestCases/Misc/Inputs/returns-unexpectedly.c new file mode 100644 index 0000000000000..826ea0ca496a2 --- /dev/null +++ b/test/ubsan/TestCases/Misc/Inputs/returns-unexpectedly.c @@ -0,0 +1 @@ +void returns_unexpectedly() {} diff --git a/test/ubsan/TestCases/Misc/unreachable.cpp b/test/ubsan/TestCases/Misc/unreachable.cpp index e1206edb30d54..1b096721ce9ca 100644 --- a/test/ubsan/TestCases/Misc/unreachable.cpp +++ b/test/ubsan/TestCases/Misc/unreachable.cpp @@ -1,6 +1,25 @@ -// RUN: %clangxx -fsanitize=unreachable %s -O3 -o %t && not %run %t 2>&1 | FileCheck %s +// RUN: %clang %S/Inputs/returns-unexpectedly.c -O3 -c -o %t.ru.o +// RUN: %clangxx -fsanitize=unreachable -O3 -o %t %s %t.ru.o +// RUN: not %run %t builtin 2>&1 | FileCheck %s -check-prefix=BUILTIN +// RUN: not %run %t noreturn-callee-marked 2>&1 | FileCheck %s -check-prefix=NORETURN1 +// RUN: not %run %t noreturn-caller-marked 2>&1 | FileCheck %s -check-prefix=NORETURN2 + +#include <string.h> + +void __attribute__((noreturn)) callee_marked_noreturn() { + // NORETURN1: unreachable.cpp:[[@LINE+1]]:1: runtime error: execution reached an unreachable program point +} + +extern "C" void __attribute__((noreturn)) returns_unexpectedly(); int main(int, char **argv) { - // CHECK: unreachable.cpp:5:3: runtime error: execution reached a __builtin_unreachable() call - __builtin_unreachable(); + if (strcmp(argv[1], "builtin") == 0) + // BUILTIN: unreachable.cpp:[[@LINE+1]]:5: runtime error: execution reached an unreachable program point + __builtin_unreachable(); + else if (strcmp(argv[1], "noreturn-callee-marked") == 0) + callee_marked_noreturn(); + else if (strcmp(argv[1], "noreturn-caller-marked") == 0) + // NORETURN2: unreachable.cpp:[[@LINE+1]]:5: runtime error: execution reached an unreachable program point + returns_unexpectedly(); + return 0; } |
