1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <vector> 11 12 // reference operator[](size_type n); 13 14 #include <vector> 15 #include <cassert> 16 #include <cstdlib> 17 18 #include "min_allocator.h" 19 #include "asan_testing.h" 20 21 #ifndef _LIBCPP_HAS_NO_ASAN 22 extern "C" void __asan_set_error_exit_code(int); 23 24 int main() 25 { 26 #if __cplusplus >= 201103L 27 { 28 typedef int T; 29 typedef std::vector<T, min_allocator<T>> C; 30 const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 31 C c(std::begin(t), std::end(t)); 32 c.reserve(2*c.size()); 33 T foo = c[c.size()]; // bad, but not caught by ASAN 34 } 35 #endif 36 37 __asan_set_error_exit_code(0); 38 { 39 typedef int T; 40 typedef std::vector<T> C; 41 const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 42 C c(std::begin(t), std::end(t)); 43 c.reserve(2*c.size()); 44 assert(is_contiguous_container_asan_correct(c)); 45 assert(!__sanitizer_verify_contiguous_container ( c.data(), c.data() + 1, c.data() + c.capacity())); 46 T foo = c[c.size()]; // should trigger ASAN 47 assert(false); // if we got here, ASAN didn't trigger 48 } 49 } 50 #else 51 int main () { return 0; } 52 #endif 53