[libcxx-commits] [PATCH] D151777: [libc++][ASan] Annotating const types in deque old errors

Tacet via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 30 22:07:37 PDT 2023


AdvenamTacet created this revision.
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 adds `const` to a few places, to make `std::deque<const T>` work as before D132092 <https://reviews.llvm.org/D132092>.
That change shouldn't brake anything and makes compilation backward compatible.

Deque does not support const objects (objects have to be movable), so correct C++ code works with and without this patch, but there is no point in changing the behavior for incorrect code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151777

Files:
  libcxx/include/deque


Index: libcxx/include/deque
===================================================================
--- libcxx/include/deque
+++ libcxx/include/deque
@@ -1129,7 +1129,7 @@
     }
 
     _LIBCPP_HIDE_FROM_ABI
-    void __annotate_poison_block(void *__beginning, void *__end) {
+    void __annotate_poison_block(const void *__beginning, const void *__end) {
         __annotate_double_ended_contiguous_container(__beginning, __end, __beginning, __end, __end, __end);
     }
 
@@ -1158,8 +1158,8 @@
 
         // Pointers to first and after last elements
         // Those can be in different deque blocks
-        void* __p_beg = std::__to_address(*__first_mp + (__start_ % __block_size));
-        void* __p_end =
+        const void* __p_beg = std::__to_address(*__first_mp + (__start_ % __block_size));
+        const void* __p_end =
             std::__to_address(*__last_mp + ((__end % __block_size == 0) ? __block_size : __end % __block_size));
 
         for (__map_const_iterator __it = __map_.begin(); __it != __map_.end(); ++__it) {
@@ -1180,9 +1180,9 @@
                         std::__to_address(*__it + __block_size)))
                   return false;
             } else {
-                void* __containers_buffer_beg = (__it == __first_mp) ? __p_beg : (void*)std::__to_address(*__it);
-                void* __containers_buffer_end =
-                    (__it == __last_mp) ? __p_end : (void*)std::__to_address(*__it + __block_size);
+                const void* __containers_buffer_beg = (__it == __first_mp) ? __p_beg : (const void*)std::__to_address(*__it);
+                const void* __containers_buffer_end =
+                    (__it == __last_mp) ? __p_end : (const void*)std::__to_address(*__it + __block_size);
                 if (!__sanitizer_verify_double_ended_contiguous_container(
                         std::__to_address(*__it),
                         __containers_buffer_beg,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151777.526900.patch
Type: text/x-patch
Size: 1912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230531/841d2d66/attachment.bin>


More information about the libcxx-commits mailing list