[libcxx-commits] [PATCH] D145628: A way to turn off annotations for containers with a specific allocator

Tacet via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 8 16:19:33 PST 2023


AdvenamTacet created this revision.
AdvenamTacet added reviewers: ldionne, philnik.
Herald added a project: All.
AdvenamTacet requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

This patch is part of our efforts to support container annotations with (almost) every allocator.
Annotations with different allocators work (check D136765 <https://reviews.llvm.org/D136765>), but after merge a suggestion for easier way to turn off annotations with a specific allocator was posted.

This is answer to that request, this patch adds a new template stuct to support turning off container annotations with a specific allocator.
It will be used also in other containers (like std::basic_string, check D132769 <https://reviews.llvm.org/D132769>), therefore it should be available in different source files.

To turn off annotations, it's enough to create template specialization with value `false`.

This patch should be merged with D136765 <https://reviews.llvm.org/D136765> as it's used there.

Possibility to do it was added to ASan here: rGdd1b7b797a116eed588fd752fbe61d34deeb24e4 <https://reviews.llvm.org/rGdd1b7b797a116eed588fd752fbe61d34deeb24e4>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145628

Files:
  libcxx/docs/UsingLibcxx.rst
  libcxx/include/__memory/allocator_traits.h


Index: libcxx/include/__memory/allocator_traits.h
===================================================================
--- libcxx/include/__memory/allocator_traits.h
+++ libcxx/include/__memory/allocator_traits.h
@@ -401,6 +401,12 @@
     : __is_cpp17_move_insertable<_Alloc>
 { };
 
+// ASan choices
+template <class _Alloc>
+struct __asan_annotate_container_with_allocator {
+    static bool const value = true;
+};
+
 #undef _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX
 
 _LIBCPP_END_NAMESPACE_STD
Index: libcxx/docs/UsingLibcxx.rst
===================================================================
--- libcxx/docs/UsingLibcxx.rst
+++ libcxx/docs/UsingLibcxx.rst
@@ -517,3 +517,14 @@
 ``format-string`` and ``wformat-string`` became ``basic_format_string``,
 ``format_string``, and ``wformat_string`` in C++23. Libc++ makes these types
 available in C++20 as an extension.
+
+Turning off ASan annotation in containers
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Struct template ``__asan_annotate_container_with_allocator`` may be used to turn off ASan annotations for containers
+with a specific allocator.
+If ``__asan_annotate_container_with_allocator<_Alloc>::value == false``, container won't be poisoned at all.
+Value may be changed by template specialization. Variable ``value`` is of type ``bool``.
+
+If you are creating allocator not working correctly with container annotations from libc++,
+a better choice may be unpoisoning memory, if possible. This way, ASan benefits are present in the program.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145628.503555.patch
Type: text/x-patch
Size: 1506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230309/2ca09783/attachment.bin>


More information about the libcxx-commits mailing list