1*67e74705SXin Li // Like the compiler, the static analyzer treats some functions differently if 2*67e74705SXin Li // they come from a system header -- for example, it is assumed that system 3*67e74705SXin Li // functions do not arbitrarily free() their parameters, and that some bugs 4*67e74705SXin Li // found in system headers cannot be fixed by the user and should be 5*67e74705SXin Li // suppressed. 6*67e74705SXin Li #pragma clang system_header 7*67e74705SXin Li 8*67e74705SXin Li typedef unsigned char uint8_t; 9*67e74705SXin Li 10*67e74705SXin Li typedef __typeof__(sizeof(int)) size_t; 11*67e74705SXin Li void *memmove(void *s1, const void *s2, size_t n); 12*67e74705SXin Li 13*67e74705SXin Li namespace std { 14*67e74705SXin Li template <class T1, class T2> 15*67e74705SXin Li struct pair { 16*67e74705SXin Li T1 first; 17*67e74705SXin Li T2 second; 18*67e74705SXin Li pairpair19*67e74705SXin Li pair() : first(), second() {} pairpair20*67e74705SXin Li pair(const T1 &a, const T2 &b) : first(a), second(b) {} 21*67e74705SXin Li 22*67e74705SXin Li template<class U1, class U2> pairpair23*67e74705SXin Li pair(const pair<U1, U2> &other) : first(other.first), second(other.second) {} 24*67e74705SXin Li }; 25*67e74705SXin Li 26*67e74705SXin Li typedef __typeof__(sizeof(int)) size_t; 27*67e74705SXin Li 28*67e74705SXin Li template<typename T> 29*67e74705SXin Li class vector { 30*67e74705SXin Li T *_start; 31*67e74705SXin Li T *_finish; 32*67e74705SXin Li T *_end_of_storage; 33*67e74705SXin Li public: vector()34*67e74705SXin Li vector() : _start(0), _finish(0), _end_of_storage(0) {} 35*67e74705SXin Li ~vector(); 36*67e74705SXin Li size()37*67e74705SXin Li size_t size() const { 38*67e74705SXin Li return size_t(_finish - _start); 39*67e74705SXin Li } 40*67e74705SXin Li 41*67e74705SXin Li void push_back(); 42*67e74705SXin Li T pop_back(); 43*67e74705SXin Li 44*67e74705SXin Li T &operator[](size_t n) { 45*67e74705SXin Li return _start[n]; 46*67e74705SXin Li } 47*67e74705SXin Li 48*67e74705SXin Li const T &operator[](size_t n) const { 49*67e74705SXin Li return _start[n]; 50*67e74705SXin Li } 51*67e74705SXin Li begin()52*67e74705SXin Li T *begin() { return _start; } begin()53*67e74705SXin Li const T *begin() const { return _start; } 54*67e74705SXin Li end()55*67e74705SXin Li T *end() { return _finish; } end()56*67e74705SXin Li const T *end() const { return _finish; } 57*67e74705SXin Li }; 58*67e74705SXin Li 59*67e74705SXin Li class exception { 60*67e74705SXin Li public: 61*67e74705SXin Li exception() throw(); 62*67e74705SXin Li virtual ~exception() throw(); what()63*67e74705SXin Li virtual const char *what() const throw() { 64*67e74705SXin Li return 0; 65*67e74705SXin Li } 66*67e74705SXin Li }; 67*67e74705SXin Li 68*67e74705SXin Li class bad_alloc : public exception { 69*67e74705SXin Li public: 70*67e74705SXin Li bad_alloc() throw(); 71*67e74705SXin Li bad_alloc(const bad_alloc&) throw(); 72*67e74705SXin Li bad_alloc& operator=(const bad_alloc&) throw(); what()73*67e74705SXin Li virtual const char* what() const throw() { 74*67e74705SXin Li return 0; 75*67e74705SXin Li } 76*67e74705SXin Li }; 77*67e74705SXin Li 78*67e74705SXin Li struct nothrow_t {}; 79*67e74705SXin Li 80*67e74705SXin Li extern const nothrow_t nothrow; 81*67e74705SXin Li 82*67e74705SXin Li // libc++'s implementation 83*67e74705SXin Li template <class _E> 84*67e74705SXin Li class initializer_list 85*67e74705SXin Li { 86*67e74705SXin Li const _E* __begin_; 87*67e74705SXin Li size_t __size_; 88*67e74705SXin Li initializer_list(const _E * __b,size_t __s)89*67e74705SXin Li initializer_list(const _E* __b, size_t __s) 90*67e74705SXin Li : __begin_(__b), 91*67e74705SXin Li __size_(__s) 92*67e74705SXin Li {} 93*67e74705SXin Li 94*67e74705SXin Li public: 95*67e74705SXin Li typedef _E value_type; 96*67e74705SXin Li typedef const _E& reference; 97*67e74705SXin Li typedef const _E& const_reference; 98*67e74705SXin Li typedef size_t size_type; 99*67e74705SXin Li 100*67e74705SXin Li typedef const _E* iterator; 101*67e74705SXin Li typedef const _E* const_iterator; 102*67e74705SXin Li initializer_list()103*67e74705SXin Li initializer_list() : __begin_(0), __size_(0) {} 104*67e74705SXin Li size()105*67e74705SXin Li size_t size() const {return __size_;} begin()106*67e74705SXin Li const _E* begin() const {return __begin_;} end()107*67e74705SXin Li const _E* end() const {return __begin_ + __size_;} 108*67e74705SXin Li }; 109*67e74705SXin Li 110*67e74705SXin Li template <bool, class _Tp = void> struct enable_if {}; 111*67e74705SXin Li template <class _Tp> struct enable_if<true, _Tp> {typedef _Tp type;}; 112*67e74705SXin Li 113*67e74705SXin Li template <class _Tp, _Tp __v> 114*67e74705SXin Li struct integral_constant 115*67e74705SXin Li { 116*67e74705SXin Li static const _Tp value = __v; 117*67e74705SXin Li typedef _Tp value_type; 118*67e74705SXin Li typedef integral_constant type; 119*67e74705SXin Li 120*67e74705SXin Li operator value_type() const {return value;} 121*67e74705SXin Li 122*67e74705SXin Li value_type operator ()() const {return value;} 123*67e74705SXin Li }; 124*67e74705SXin Li 125*67e74705SXin Li template <class _Tp, _Tp __v> 126*67e74705SXin Li const _Tp integral_constant<_Tp, __v>::value; 127*67e74705SXin Li 128*67e74705SXin Li template <class _Tp, class _Arg> 129*67e74705SXin Li struct is_trivially_assignable 130*67e74705SXin Li : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)> 131*67e74705SXin Li { 132*67e74705SXin Li }; 133*67e74705SXin Li 134*67e74705SXin Li typedef integral_constant<bool,true> true_type; 135*67e74705SXin Li typedef integral_constant<bool,false> false_type; 136*67e74705SXin Li 137*67e74705SXin Li template <class _Tp> struct is_const : public false_type {}; 138*67e74705SXin Li template <class _Tp> struct is_const<_Tp const> : public true_type {}; 139*67e74705SXin Li 140*67e74705SXin Li template <class _Tp> struct is_reference : public false_type {}; 141*67e74705SXin Li template <class _Tp> struct is_reference<_Tp&> : public true_type {}; 142*67e74705SXin Li 143*67e74705SXin Li template <class _Tp, class _Up> struct is_same : public false_type {}; 144*67e74705SXin Li template <class _Tp> struct is_same<_Tp, _Tp> : public true_type {}; 145*67e74705SXin Li 146*67e74705SXin Li template <class _Tp, bool = is_const<_Tp>::value || is_reference<_Tp>::value > 147*67e74705SXin Li struct __add_const {typedef _Tp type;}; 148*67e74705SXin Li 149*67e74705SXin Li template <class _Tp> 150*67e74705SXin Li struct __add_const<_Tp, false> {typedef const _Tp type;}; 151*67e74705SXin Li 152*67e74705SXin Li template <class _Tp> struct add_const {typedef typename __add_const<_Tp>::type type;}; 153*67e74705SXin Li 154*67e74705SXin Li template <class _Tp> struct remove_const {typedef _Tp type;}; 155*67e74705SXin Li template <class _Tp> struct remove_const<const _Tp> {typedef _Tp type;}; 156*67e74705SXin Li 157*67e74705SXin Li template <class _Tp> struct add_lvalue_reference {typedef _Tp& type;}; 158*67e74705SXin Li 159*67e74705SXin Li template <class _Tp> struct is_trivially_copy_assignable 160*67e74705SXin Li : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type, 161*67e74705SXin Li typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; 162*67e74705SXin Li 163*67e74705SXin Li template<class InputIter, class OutputIter> 164*67e74705SXin Li OutputIter __copy(InputIter II, InputIter IE, OutputIter OI) { 165*67e74705SXin Li while (II != IE) 166*67e74705SXin Li *OI++ = *II++; 167*67e74705SXin Li 168*67e74705SXin Li return OI; 169*67e74705SXin Li } 170*67e74705SXin Li 171*67e74705SXin Li template <class _Tp, class _Up> 172*67e74705SXin Li inline 173*67e74705SXin Li typename enable_if 174*67e74705SXin Li < 175*67e74705SXin Li is_same<typename remove_const<_Tp>::type, _Up>::value && 176*67e74705SXin Li is_trivially_copy_assignable<_Up>::value, 177*67e74705SXin Li _Up* 178*67e74705SXin Li >::type __copy(_Tp* __first, _Tp* __last, _Up* __result) { 179*67e74705SXin Li size_t __n = __last - __first; 180*67e74705SXin Li 181*67e74705SXin Li if (__n > 0) 182*67e74705SXin Li memmove(__result, __first, __n * sizeof(_Up)); 183*67e74705SXin Li 184*67e74705SXin Li return __result + __n; 185*67e74705SXin Li } 186*67e74705SXin Li 187*67e74705SXin Li template<class InputIter, class OutputIter> 188*67e74705SXin Li OutputIter copy(InputIter II, InputIter IE, OutputIter OI) { 189*67e74705SXin Li return __copy(II, IE, OI); 190*67e74705SXin Li } 191*67e74705SXin Li 192*67e74705SXin Li template <class _BidirectionalIterator, class _OutputIterator> 193*67e74705SXin Li inline 194*67e74705SXin Li _OutputIterator 195*67e74705SXin Li __copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, 196*67e74705SXin Li _OutputIterator __result) 197*67e74705SXin Li { 198*67e74705SXin Li while (__first != __last) 199*67e74705SXin Li *--__result = *--__last; 200*67e74705SXin Li return __result; 201*67e74705SXin Li } 202*67e74705SXin Li 203*67e74705SXin Li template <class _Tp, class _Up> 204*67e74705SXin Li inline 205*67e74705SXin Li typename enable_if 206*67e74705SXin Li < 207*67e74705SXin Li is_same<typename remove_const<_Tp>::type, _Up>::value && 208*67e74705SXin Li is_trivially_copy_assignable<_Up>::value, 209*67e74705SXin Li _Up* 210*67e74705SXin Li >::type __copy_backward(_Tp* __first, _Tp* __last, _Up* __result) { 211*67e74705SXin Li size_t __n = __last - __first; 212*67e74705SXin Li 213*67e74705SXin Li if (__n > 0) 214*67e74705SXin Li { 215*67e74705SXin Li __result -= __n; 216*67e74705SXin Li memmove(__result, __first, __n * sizeof(_Up)); 217*67e74705SXin Li } 218*67e74705SXin Li return __result; 219*67e74705SXin Li } 220*67e74705SXin Li 221*67e74705SXin Li template<class InputIter, class OutputIter> 222*67e74705SXin Li OutputIter copy_backward(InputIter II, InputIter IE, OutputIter OI) { 223*67e74705SXin Li return __copy_backward(II, IE, OI); 224*67e74705SXin Li } 225*67e74705SXin Li 226*67e74705SXin Li struct input_iterator_tag { }; 227*67e74705SXin Li struct output_iterator_tag { }; 228*67e74705SXin Li struct forward_iterator_tag : public input_iterator_tag { }; 229*67e74705SXin Li struct bidirectional_iterator_tag : public forward_iterator_tag { }; 230*67e74705SXin Li struct random_access_iterator_tag : public bidirectional_iterator_tag { }; 231*67e74705SXin Li 232*67e74705SXin Li } 233*67e74705SXin Li 234*67e74705SXin Li void* operator new(std::size_t, const std::nothrow_t&) throw(); 235*67e74705SXin Li void* operator new[](std::size_t, const std::nothrow_t&) throw(); 236*67e74705SXin Li void operator delete(void*, const std::nothrow_t&) throw(); 237*67e74705SXin Li void operator delete[](void*, const std::nothrow_t&) throw(); 238*67e74705SXin Li 239*67e74705SXin Li void* operator new (std::size_t size, void* ptr) throw() { return ptr; }; 240*67e74705SXin Li void* operator new[] (std::size_t size, void* ptr) throw() { return ptr; }; 241*67e74705SXin Li void operator delete (void* ptr, void*) throw() {}; 242*67e74705SXin Li void operator delete[] (void* ptr, void*) throw() {}; 243