blob: 678f12a91b65a5b955e0763b339d6bf0d807de01 [file] [log] [blame]
Marshall Clow5c520bd2014-05-08 14:14:06 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef ASAN_TESTING_H
11#define ASAN_TESTING_H
12
Eric Fiselierb530a252016-04-22 10:33:56 +000013#include "test_macros.h"
Marshall Clow5c520bd2014-05-08 14:14:06 +000014
Eric Fiselierb530a252016-04-22 10:33:56 +000015#if TEST_HAS_FEATURE(address_sanitizer)
Marshall Clow5c520bd2014-05-08 14:14:06 +000016extern "C" int __sanitizer_verify_contiguous_container
17 ( const void *beg, const void *mid, const void *end );
Eric Fiselier382e9172016-04-29 04:07:45 +000018
Marshall Clow5c520bd2014-05-08 14:14:06 +000019template <typename T, typename Alloc>
20bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &c )
21{
Kostya Serebryany3f0e8342014-09-02 23:43:38 +000022 if ( std::is_same<Alloc, std::allocator<T> >::value && c.data() != NULL)
Marshall Clow5c520bd2014-05-08 14:14:06 +000023 return __sanitizer_verify_contiguous_container (
24 c.data(), c.data() + c.size(), c.data() + c.capacity()) != 0;
25 return true;
26}
27
28#else
29template <typename T, typename Alloc>
Eric Fiselierb530a252016-04-22 10:33:56 +000030bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &)
Marshall Clow5c520bd2014-05-08 14:14:06 +000031{
32 return true;
33}
34#endif
Eric Fiselierd04c6852016-06-01 21:35:39 +000035
Marshall Clow5c520bd2014-05-08 14:14:06 +000036
Kostya Serebryany3f0e8342014-09-02 23:43:38 +000037#endif // ASAN_TESTING_H