asan_testing.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. #ifndef ASAN_TESTING_H
  9. #define ASAN_TESTING_H
  10. #include "test_macros.h"
  11. #if TEST_HAS_FEATURE(address_sanitizer)
  12. extern "C" int __sanitizer_verify_contiguous_container
  13. ( const void *beg, const void *mid, const void *end );
  14. template <typename T, typename Alloc>
  15. bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &c )
  16. {
  17. if ( std::is_same<Alloc, std::allocator<T> >::value && c.data() != NULL)
  18. return __sanitizer_verify_contiguous_container (
  19. c.data(), c.data() + c.size(), c.data() + c.capacity()) != 0;
  20. return true;
  21. }
  22. #else
  23. template <typename T, typename Alloc>
  24. bool is_contiguous_container_asan_correct ( const std::vector<T, Alloc> &)
  25. {
  26. return true;
  27. }
  28. #endif
  29. #endif // ASAN_TESTING_H