blob: 6171d0beebb3ee9ea1d6a41b20b72d1a2826eec1 [file] [log] [blame]
Marshall Clow5c520bd2014-05-08 14:14:06 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Clow5c520bd2014-05-08 14:14:06 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef ASAN_TESTING_H
10#define ASAN_TESTING_H
11
Eric Fiselierb530a252016-04-22 10:33:56 +000012#include "test_macros.h"
Marshall Clow5c520bd2014-05-08 14:14:06 +000013
Eric Fiselierb530a252016-04-22 10:33:56 +000014#if TEST_HAS_FEATURE(address_sanitizer)
Marshall Clow5c520bd2014-05-08 14:14:06 +000015extern "C" int __sanitizer_verify_contiguous_container
16 ( const void *beg, const void *mid, const void *end );
Eric Fiselier382e9172016-04-29 04:07:45 +000017
Marshall Clow5c520bd2014-05-08 14:14:06 +000018template <typename T, typename Alloc>
19bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &c )
20{
Kostya Serebryany3f0e8342014-09-02 23:43:38 +000021 if ( std::is_same<Alloc, std::allocator<T> >::value && c.data() != NULL)
Marshall Clow5c520bd2014-05-08 14:14:06 +000022 return __sanitizer_verify_contiguous_container (
23 c.data(), c.data() + c.size(), c.data() + c.capacity()) != 0;
24 return true;
25}
26
27#else
28template <typename T, typename Alloc>
Eric Fiselierb530a252016-04-22 10:33:56 +000029bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &)
Marshall Clow5c520bd2014-05-08 14:14:06 +000030{
31 return true;
32}
33#endif
Eric Fiselierd04c6852016-06-01 21:35:39 +000034
Marshall Clow5c520bd2014-05-08 14:14:06 +000035
Kostya Serebryany3f0e8342014-09-02 23:43:38 +000036#endif // ASAN_TESTING_H