commit d0478d9fbd17b9e9d165b4893f784ae897531713
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Jun 27 13:31:12 2017 +0100
Add AddressSanitizer annotations to std::make_shared
* include/bits/shared_ptr_base.h [_GLIBCXX_SANITIZE_STD_ALLOCATOR]
(__asan_annotate): Add.
(_Sp_counted_ptr_inplace::_M_dispose): Call __asan_annotate.
@@ -57,6 +57,12 @@
#include <bits/stl_function.h>
#include <ext/aligned_buffer.h>
+#if _GLIBCXX_SANITIZE_STD_ALLOCATOR
+extern "C" void
+__sanitizer_annotate_contiguous_container(const void*, const void*,
+ const void*, const void*);
+#endif
+
namespace std _GLIBCXX_VISIBILITY(default)
{
#if !__cpp_rtti
@@ -522,6 +528,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
};
+#if _GLIBCXX_SANITIZE_STD_ALLOCATOR
+ template<typename _Tp>
+ inline void
+ __asan_annotate(const void* __beg, const void* __mid, const void* __end,
+ const allocator<_Tp>&)
+ { __sanitizer_annotate_contiguous_container(__beg, __end, __end, __mid); }
+
+ template<typename _Alloc>
+ inline void
+ __asan_annotate(const void*, const void*, const void*, const _Alloc&)
+ { }
+#endif
+
template<typename _Tp, typename _Alloc, _Lock_policy _Lp>
class _Sp_counted_ptr_inplace final : public _Sp_counted_base<_Lp>
{
@@ -556,6 +575,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_dispose() noexcept
{
allocator_traits<_Alloc>::destroy(_M_impl._M_alloc(), _M_ptr());
+#if _GLIBCXX_SANITIZE_STD_ALLOCATOR
+ __asan_annotate(this, &_M_impl._M_storage, this + 1, _M_impl._M_alloc());
+#endif
}
// Override because the allocator needs to know the dynamic type