Marshall Clow | 5c520bd | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Marshall Clow | 5c520bd | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef ASAN_TESTING_H |
| 10 | #define ASAN_TESTING_H |
| 11 | |
Eric Fiselier | b530a25 | 2016-04-22 10:33:56 +0000 | [diff] [blame] | 12 | #include "test_macros.h" |
Marshall Clow | 5c520bd | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 13 | |
Eric Fiselier | b530a25 | 2016-04-22 10:33:56 +0000 | [diff] [blame] | 14 | #if TEST_HAS_FEATURE(address_sanitizer) |
Marshall Clow | 5c520bd | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 15 | extern "C" int __sanitizer_verify_contiguous_container |
| 16 | ( const void *beg, const void *mid, const void *end ); |
Eric Fiselier | 382e917 | 2016-04-29 04:07:45 +0000 | [diff] [blame] | 17 | |
Marshall Clow | 5c520bd | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 18 | template <typename T, typename Alloc> |
| 19 | bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &c ) |
| 20 | { |
Kostya Serebryany | 3f0e834 | 2014-09-02 23:43:38 +0000 | [diff] [blame] | 21 | if ( std::is_same<Alloc, std::allocator<T> >::value && c.data() != NULL) |
Marshall Clow | 5c520bd | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 22 | return __sanitizer_verify_contiguous_container ( |
| 23 | c.data(), c.data() + c.size(), c.data() + c.capacity()) != 0; |
| 24 | return true; |
| 25 | } |
| 26 | |
| 27 | #else |
| 28 | template <typename T, typename Alloc> |
Eric Fiselier | b530a25 | 2016-04-22 10:33:56 +0000 | [diff] [blame] | 29 | bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &) |
Marshall Clow | 5c520bd | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 30 | { |
| 31 | return true; |
| 32 | } |
| 33 | #endif |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 34 | |
Marshall Clow | 5c520bd | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 35 | |
Kostya Serebryany | 3f0e834 | 2014-09-02 23:43:38 +0000 | [diff] [blame] | 36 | #endif // ASAN_TESTING_H |