<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5"><br>
> Do you like the idea?<br>
<br>
</div></div>Yes - very much so.<br>
<div class="im"><br>
> Any comments about the prototype patch?<br>
<br>
</div>Yes.<br>
<br>
1) I would implement it with inline functions other than macros.<br>
<br>
Like this:<br>
<br>
<br>
extern "C" void __sanitizer_annotate_contiguous_container(void *, void *, void *, void *);<br>
void inline __annotate_contiguous container<br>
        ( const void *__beg, const void *__end, const void *__old_mid, const void *new_mid )<br>
#if __has_feature(address_sanitizer)<br>
        {  __sanitizer_annotate_contiguous_container(beg, end, old_mid, new_mid); }<br>
#else<br>
        {}<br>
#endif<br></blockquote><div><br></div><div>Makes sense, see below. </div><div>We''l probably want to move __annotate_contiguous container into a separate file so that both string and vector use it.</div><div>But let's do the whole thing with vector before moving to string. </div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
2) I'd like more information about what __sanitizer_annotate_contiguous_container does ;-)<br></blockquote><div><br></div><div>In short, it [un]poisons the parts of shadow memory that correspond to the container's memory. </div>
<div>More details in compiler-rt files:  include/sanitizer/common_interface_defs.h and lib/asan/asan_poisoning.cc</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class="im"><br>
> Any suggestion how to test these annotations in libc++ (we need some kind of DEATH tests)?<br>
<br>
</div>We already have failing tests in libc++.<br>
they are named XXXX.fail.cpp.<br></blockquote><div><br></div><div>These are tests that fail to compile. </div><div>for asan annotations we need tests that build and run, and then either fail at run-time or check the state of shadow. </div>
<div>Like these:</div><div><div>compiler-rt/lib/asan/lit_tests/TestCases/contiguous_container.cc</div><div>compiler-rt/lib/asan/lit_tests/TestCases/contiguous_container_crash.cc</div></div><div><br></div><div>Suggestions?</div>
<div><br></div><div>--kcc  </div><div><br></div><div><div>--- include/vector      (revision 195116)</div><div>+++ include/vector      (working copy)</div><div>@@ -288,6 +288,16 @@</div><div> </div><div> _LIBCPP_BEGIN_NAMESPACE_STD</div>
<div> </div><div>+extern "C" void __sanitizer_annotate_contiguous_container(</div><div>+  const void *, const void *, const void *, const void *);</div><div>+void inline __annotate_contiguous_container</div><div>
+    (const void *__beg, const void *__end, const void *__old_mid, const void *__new_mid)</div><div>+#if __has_feature(address_sanitizer)</div><div>+    {  __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); }</div>
<div>+#else</div><div>+    {}</div><div>+#endif</div><div>+</div><div> template <bool></div><div> class __vector_base_common</div><div> {</div><div>@@ -1525,7 +1535,12 @@</div><div>     // __v.push_back(_VSTD::forward<_Up>(__x));</div>
<div>     __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));</div><div>     __v.__end_++;</div><div>+    if (data())</div><div>+      __annotate_contiguous_container(</div>
<div>+          data(), data() + capacity(), data() + size(), data() + capacity());</div><div>     __swap_out_circular_buffer(__v);</div><div>+    __annotate_contiguous_container(data(), data() + capacity(),</div><div>+                                          data() + capacity(), data() + size());</div>
<div> }</div><div> </div></div><div><br></div><div><br></div></div></div></div>