diff options
author | Alex Shlyapnikov <alekseys@google.com> | 2017-12-22 17:02:17 +0000 |
---|---|---|
committer | Alex Shlyapnikov <alekseys@google.com> | 2017-12-22 17:02:17 +0000 |
commit | 4a21f6f81e93ebc443e5f63f6e70528b65e1b3b1 (patch) | |
tree | 8588041a65dff6fecfc0bcbabe04fc871c5149ca /test | |
parent | 73b3adc3842f4e748b6b5f19743a95b246db2699 (diff) |
[MSan,TSan] Add aligned new/delete interceptors.
Summary:
Providing aligned new/delete implementations to match ASan.
Unlike ASan, MSan and TSan do not perform any additional checks
on overaligned memory, hence no sanitizer specific tests.
Reviewers: eugenis
Subscribers: kubamracek, #sanitizers, llvm-commits
Differential Revision: https://reviews.llvm.org/D41532
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@321365 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/sanitizer_common/TestCases/Linux/new_delete_test.cc | 80 |
1 files changed, 80 insertions, 0 deletions
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 000000000..5532da399 --- /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 +// plaform. 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))); +} |