xref: /aosp_15_r20/external/libcxx/test/support/asan_testing.h (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
2*58b9f456SAndroid Build Coastguard Worker //
3*58b9f456SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*58b9f456SAndroid Build Coastguard Worker //
5*58b9f456SAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
6*58b9f456SAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
7*58b9f456SAndroid Build Coastguard Worker //
8*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*58b9f456SAndroid Build Coastguard Worker 
10*58b9f456SAndroid Build Coastguard Worker #ifndef ASAN_TESTING_H
11*58b9f456SAndroid Build Coastguard Worker #define ASAN_TESTING_H
12*58b9f456SAndroid Build Coastguard Worker 
13*58b9f456SAndroid Build Coastguard Worker #include "test_macros.h"
14*58b9f456SAndroid Build Coastguard Worker 
15*58b9f456SAndroid Build Coastguard Worker #if TEST_HAS_FEATURE(address_sanitizer)
16*58b9f456SAndroid Build Coastguard Worker extern "C" int __sanitizer_verify_contiguous_container
17*58b9f456SAndroid Build Coastguard Worker      ( const void *beg, const void *mid, const void *end );
18*58b9f456SAndroid Build Coastguard Worker 
19*58b9f456SAndroid Build Coastguard Worker template <typename T, typename Alloc>
is_contiguous_container_asan_correct(const std::vector<T,Alloc> & c)20*58b9f456SAndroid Build Coastguard Worker bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &c )
21*58b9f456SAndroid Build Coastguard Worker {
22*58b9f456SAndroid Build Coastguard Worker     if ( std::is_same<Alloc, std::allocator<T> >::value && c.data() != NULL)
23*58b9f456SAndroid Build Coastguard Worker         return __sanitizer_verify_contiguous_container (
24*58b9f456SAndroid Build Coastguard Worker             c.data(), c.data() + c.size(), c.data() + c.capacity()) != 0;
25*58b9f456SAndroid Build Coastguard Worker     return true;
26*58b9f456SAndroid Build Coastguard Worker }
27*58b9f456SAndroid Build Coastguard Worker 
28*58b9f456SAndroid Build Coastguard Worker #else
29*58b9f456SAndroid Build Coastguard Worker template <typename T, typename Alloc>
is_contiguous_container_asan_correct(const std::vector<T,Alloc> &)30*58b9f456SAndroid Build Coastguard Worker bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &)
31*58b9f456SAndroid Build Coastguard Worker {
32*58b9f456SAndroid Build Coastguard Worker     return true;
33*58b9f456SAndroid Build Coastguard Worker }
34*58b9f456SAndroid Build Coastguard Worker #endif
35*58b9f456SAndroid Build Coastguard Worker 
36*58b9f456SAndroid Build Coastguard Worker 
37*58b9f456SAndroid Build Coastguard Worker #endif  // ASAN_TESTING_H
38