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 //===----------------------------------------------------------------------===//
8
9 #ifndef ASAN_TESTING_H
10 #define ASAN_TESTING_H
11
12 #include "test_macros.h"
13 #include <vector>
14
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 );
18
19 template <typename T, typename Alloc>
is_contiguous_container_asan_correct(const std::vector<T,Alloc> & c)20 TEST_CONSTEXPR bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &c )
21 {
22 if (TEST_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;
28 }
29 #else
30 template <typename T, typename Alloc>
is_contiguous_container_asan_correct(const std::vector<T,Alloc> &)31 TEST_CONSTEXPR bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &)
32 {
33 return true;
34 }
35 #endif // TEST_HAS_FEATURE(address_sanitizer)
36
37 #if TEST_HAS_FEATURE(address_sanitizer)
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>
42
43 template <class T, class Alloc>
is_double_ended_contiguous_container_asan_correct(const std::deque<T,Alloc> & c)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;
50 }
51 #else
52 # include <deque>
53 template <class T, class Alloc>
is_double_ended_contiguous_container_asan_correct(const std::deque<T,Alloc> &)54 TEST_CONSTEXPR bool is_double_ended_contiguous_container_asan_correct(const std::deque<T, Alloc>&) {
55 return true;
56 }
57 #endif
58
59 #endif // ASAN_TESTING_H
60