This revision was automatically updated to reflect the committed changes.
Closed by commit rL298601: [libcxx] Improve code generation for 
vector::clear(). (authored by brucem).

Changed prior to commit:
  https://reviews.llvm.org/D25241?vs=73790&id=92796#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25241

Files:
  libcxx/trunk/include/vector
  
libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp


Index: libcxx/trunk/include/vector
===================================================================
--- libcxx/trunk/include/vector
+++ libcxx/trunk/include/vector
@@ -413,8 +413,10 @@
 void
 __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
 {
-    while (__new_last != __end_)
-        __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
+    pointer __soon_to_be_end = __end_;
+    while (__new_last != __soon_to_be_end)
+        __alloc_traits::destroy(__alloc(), 
_VSTD::__to_raw_pointer(--__soon_to_be_end));
+    __end_ = __new_last;
 }
 
 template <class _Tp, class _Allocator>
Index: 
libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp
===================================================================
--- 
libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp
+++ 
libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// void clear();
+
+#include <vector>
+#include <cassert>
+
+#include "min_allocator.h"
+#include "asan_testing.h"
+
+int main()
+{
+    {
+    int a[] = {1, 2, 3};
+    std::vector<int> c(a, a+3);
+    c.clear();
+    assert(c.empty());
+    LIBCPP_ASSERT(c.__invariants());
+    LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
+    }
+#if TEST_STD_VER >= 11
+    {
+    int a[] = {1, 2, 3};
+    std::vector<int, min_allocator<int>> c(a, a+3);
+    c.clear();
+    assert(c.empty());
+    LIBCPP_ASSERT(c.__invariants());
+    LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
+    }
+#endif
+}


Index: libcxx/trunk/include/vector
===================================================================
--- libcxx/trunk/include/vector
+++ libcxx/trunk/include/vector
@@ -413,8 +413,10 @@
 void
 __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
 {
-    while (__new_last != __end_)
-        __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
+    pointer __soon_to_be_end = __end_;
+    while (__new_last != __soon_to_be_end)
+        __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__soon_to_be_end));
+    __end_ = __new_last;
 }
 
 template <class _Tp, class _Allocator>
Index: libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp
===================================================================
--- libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp
+++ libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// void clear();
+
+#include <vector>
+#include <cassert>
+
+#include "min_allocator.h"
+#include "asan_testing.h"
+
+int main()
+{
+    {
+    int a[] = {1, 2, 3};
+    std::vector<int> c(a, a+3);
+    c.clear();
+    assert(c.empty());
+    LIBCPP_ASSERT(c.__invariants());
+    LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
+    }
+#if TEST_STD_VER >= 11
+    {
+    int a[] = {1, 2, 3};
+    std::vector<int, min_allocator<int>> c(a, a+3);
+    c.clear();
+    assert(c.empty());
+    LIBCPP_ASSERT(c.__invariants());
+    LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
+    }
+#endif
+}
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to