[NFC][Py Reformat] Reformat python files in libcxx/libcxxabi
[llvm-project.git] / libcxx / test / support / asan_testing.h
blobd8e97af421139f2e8b65474e8c91c331f565a86b
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef ASAN_TESTING_H
10 #define ASAN_TESTING_H
12 #include "test_macros.h"
13 #include <vector>
15 #if TEST_HAS_FEATURE(address_sanitizer)
16 extern "C" int __sanitizer_verify_contiguous_container
17 ( const void *beg, const void *mid, const void *end );
19 template <typename T, typename Alloc>
20 TEST_CONSTEXPR bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &c )
22 if (std::__libcpp_is_constant_evaluated())
23 return true;
24 if (std::is_same<Alloc, std::allocator<T> >::value && c.data() != NULL)
25 return __sanitizer_verify_contiguous_container(
26 c.data(), c.data() + c.size(), c.data() + c.capacity()) != 0;
27 return true;
29 #else
30 template <typename T, typename Alloc>
31 TEST_CONSTEXPR bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &)
33 return true;
35 #endif // TEST_HAS_FEATURE(address_sanitizer)
37 #if TEST_HAS_FEATURE(address_sanitizer) && _LIBCPP_CLANG_VER >= 1600
38 extern "C" int __sanitizer_verify_double_ended_contiguous_container(
39 const void* beg, const void* con_beg, const void* con_end, const void* end);
40 extern "C" bool __sanitizer_is_annotable(const void* address, const unsigned long size);
41 #include <deque>
43 template <class T, class Alloc>
44 TEST_CONSTEXPR bool is_double_ended_contiguous_container_asan_correct(const std::deque<T, Alloc>& c) {
45 if (TEST_IS_CONSTANT_EVALUATED)
46 return true;
47 if (std::is_same<Alloc, std::allocator<T> >::value)
48 return c.__verify_asan_annotations();
49 return true;
51 #else
52 # include <deque>
53 template <class T, class Alloc>
54 TEST_CONSTEXPR bool is_double_ended_contiguous_container_asan_correct(const std::deque<T, Alloc>&) {
55 return true;
57 #endif
59 #endif // ASAN_TESTING_H