[PATCH] [asan and libcxx] Add missing instrumentation in vector::insert
Anna Zaks
zaks.anna at gmail.com
Tue Jun 30 19:58:08 PDT 2015
Hi mclow.lists, samsonov,
Ensures that the vector::insert's specialization for non-forward_iterators is instrumented with ASan.
http://reviews.llvm.org/D10859
Files:
include/vector
test/std/containers/sequences/vector/asan.pass.cpp
Index: include/vector
===================================================================
--- include/vector
+++ include/vector
@@ -1905,9 +1905,11 @@
pointer __old_last = this->__end_;
for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
{
+ __RAII_IncreaseAnnotator __annotator(*this);
__alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
*__first);
++this->__end_;
+ __annotator.__done();
}
__split_buffer<value_type, allocator_type&> __v(__a);
if (__first != __last)
Index: test/std/containers/sequences/vector/asan.pass.cpp
===================================================================
--- test/std/containers/sequences/vector/asan.pass.cpp
+++ test/std/containers/sequences/vector/asan.pass.cpp
@@ -21,6 +21,20 @@
#ifndef _LIBCPP_HAS_NO_ASAN
extern "C" void __asan_set_error_exit_code(int);
+// This is a Toy iterator that ensures that the vector::insert
+// specialization for non-forward_iterators is taken.
+class MyInputIter : public std::iterator<std::input_iterator_tag, int> {
+public:
+ MyInputIter(int* ptr) : ptr_(ptr) {}
+ friend bool operator!=(const MyInputIter& i1, const MyInputIter& i2) {
+ return i1.ptr_ != i2.ptr_;
+ }
+ MyInputIter& operator++() { ++ptr_; return *this; }
+ int operator*() const { return *ptr_; }
+private:
+ int* ptr_;
+};
+
int main()
{
#if __cplusplus >= 201103L
@@ -33,7 +47,17 @@
T foo = c[c.size()]; // bad, but not caught by ASAN
}
#endif
-
+
+ {
+ // Sould not trigger ASan.
+ std::vector<int> v;
+ v.reserve(1);
+ int i = 42;
+ v.insert(v.begin(), MyInputIter(&i), MyInputIter(&i + 1));
+ assert(v[0] == 42);
+ assert(is_contiguous_container_asan_correct(v));
+ }
+
__asan_set_error_exit_code(0);
{
typedef int T;
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10859.28839.patch
Type: text/x-patch
Size: 1935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150701/332ace0f/attachment.bin>
More information about the llvm-commits
mailing list