Jordan Rose | b54cfa3 | 2013-02-01 19:50:01 +0000 | [diff] [blame] | 1 | // Like the compiler, the static analyzer treats some functions differently if |
| 2 | // they come from a system header -- for example, it is assumed that system |
| 3 | // functions do not arbitrarily free() their parameters, and that some bugs |
| 4 | // found in system headers cannot be fixed by the user and should be |
| 5 | // suppressed. |
Jordan Rose | 1e0e400 | 2012-09-10 21:27:35 +0000 | [diff] [blame] | 6 | #pragma clang system_header |
| 7 | |
Anna Zaks | 830d2f7 | 2013-11-04 19:13:03 +0000 | [diff] [blame] | 8 | typedef unsigned char uint8_t; |
| 9 | |
Devin Coughlin | 9165df1 | 2016-02-07 16:55:44 +0000 | [diff] [blame] | 10 | typedef __typeof__(sizeof(int)) size_t; |
| 11 | void *memmove(void *s1, const void *s2, size_t n); |
| 12 | |
Jordan Rose | 1e0e400 | 2012-09-10 21:27:35 +0000 | [diff] [blame] | 13 | namespace std { |
| 14 | template <class T1, class T2> |
| 15 | struct pair { |
| 16 | T1 first; |
| 17 | T2 second; |
| 18 | |
| 19 | pair() : first(), second() {} |
| 20 | pair(const T1 &a, const T2 &b) : first(a), second(b) {} |
| 21 | |
| 22 | template<class U1, class U2> |
| 23 | pair(const pair<U1, U2> &other) : first(other.first), second(other.second) {} |
| 24 | }; |
| 25 | |
| 26 | typedef __typeof__(sizeof(int)) size_t; |
| 27 | |
| 28 | template<typename T> |
| 29 | class vector { |
| 30 | T *_start; |
| 31 | T *_finish; |
| 32 | T *_end_of_storage; |
| 33 | public: |
| 34 | vector() : _start(0), _finish(0), _end_of_storage(0) {} |
| 35 | ~vector(); |
| 36 | |
| 37 | size_t size() const { |
| 38 | return size_t(_finish - _start); |
| 39 | } |
| 40 | |
| 41 | void push_back(); |
| 42 | T pop_back(); |
| 43 | |
| 44 | T &operator[](size_t n) { |
| 45 | return _start[n]; |
| 46 | } |
| 47 | |
| 48 | const T &operator[](size_t n) const { |
| 49 | return _start[n]; |
| 50 | } |
| 51 | |
| 52 | T *begin() { return _start; } |
| 53 | const T *begin() const { return _start; } |
| 54 | |
| 55 | T *end() { return _finish; } |
| 56 | const T *end() const { return _finish; } |
| 57 | }; |
| 58 | |
| 59 | class exception { |
| 60 | public: |
| 61 | exception() throw(); |
| 62 | virtual ~exception() throw(); |
| 63 | virtual const char *what() const throw() { |
| 64 | return 0; |
| 65 | } |
| 66 | }; |
Anton Yartsev | 13df036 | 2013-03-25 01:35:45 +0000 | [diff] [blame] | 67 | |
| 68 | class bad_alloc : public exception { |
| 69 | public: |
| 70 | bad_alloc() throw(); |
| 71 | bad_alloc(const bad_alloc&) throw(); |
| 72 | bad_alloc& operator=(const bad_alloc&) throw(); |
| 73 | virtual const char* what() const throw() { |
| 74 | return 0; |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | struct nothrow_t {}; |
| 79 | |
| 80 | extern const nothrow_t nothrow; |
Jordan Rose | d11ef1a | 2013-04-02 00:26:15 +0000 | [diff] [blame] | 81 | |
Jordan Rose | 05b2f98 | 2013-07-17 17:16:33 +0000 | [diff] [blame] | 82 | // libc++'s implementation |
| 83 | template <class _E> |
| 84 | class initializer_list |
| 85 | { |
| 86 | const _E* __begin_; |
| 87 | size_t __size_; |
| 88 | |
| 89 | initializer_list(const _E* __b, size_t __s) |
| 90 | : __begin_(__b), |
| 91 | __size_(__s) |
| 92 | {} |
| 93 | |
| 94 | public: |
| 95 | typedef _E value_type; |
| 96 | typedef const _E& reference; |
| 97 | typedef const _E& const_reference; |
| 98 | typedef size_t size_type; |
| 99 | |
| 100 | typedef const _E* iterator; |
| 101 | typedef const _E* const_iterator; |
| 102 | |
| 103 | initializer_list() : __begin_(0), __size_(0) {} |
| 104 | |
| 105 | size_t size() const {return __size_;} |
| 106 | const _E* begin() const {return __begin_;} |
| 107 | const _E* end() const {return __begin_ + __size_;} |
| 108 | }; |
| 109 | |
Devin Coughlin | 9165df1 | 2016-02-07 16:55:44 +0000 | [diff] [blame] | 110 | template <bool, class _Tp = void> struct enable_if {}; |
| 111 | template <class _Tp> struct enable_if<true, _Tp> {typedef _Tp type;}; |
| 112 | |
| 113 | template <class _Tp, _Tp __v> |
| 114 | struct integral_constant |
| 115 | { |
| 116 | static const _Tp value = __v; |
| 117 | typedef _Tp value_type; |
| 118 | typedef integral_constant type; |
| 119 | |
| 120 | operator value_type() const {return value;} |
| 121 | |
| 122 | value_type operator ()() const {return value;} |
| 123 | }; |
| 124 | |
| 125 | template <class _Tp, _Tp __v> |
| 126 | const _Tp integral_constant<_Tp, __v>::value; |
| 127 | |
| 128 | template <class _Tp, class _Arg> |
| 129 | struct is_trivially_assignable |
| 130 | : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)> |
| 131 | { |
| 132 | }; |
| 133 | |
| 134 | typedef integral_constant<bool,true> true_type; |
| 135 | typedef integral_constant<bool,false> false_type; |
| 136 | |
| 137 | template <class _Tp> struct is_const : public false_type {}; |
| 138 | template <class _Tp> struct is_const<_Tp const> : public true_type {}; |
| 139 | |
| 140 | template <class _Tp> struct is_reference : public false_type {}; |
| 141 | template <class _Tp> struct is_reference<_Tp&> : public true_type {}; |
| 142 | |
| 143 | template <class _Tp, class _Up> struct is_same : public false_type {}; |
| 144 | template <class _Tp> struct is_same<_Tp, _Tp> : public true_type {}; |
| 145 | |
| 146 | template <class _Tp, bool = is_const<_Tp>::value || is_reference<_Tp>::value > |
| 147 | struct __add_const {typedef _Tp type;}; |
| 148 | |
| 149 | template <class _Tp> |
| 150 | struct __add_const<_Tp, false> {typedef const _Tp type;}; |
| 151 | |
| 152 | template <class _Tp> struct add_const {typedef typename __add_const<_Tp>::type type;}; |
| 153 | |
| 154 | template <class _Tp> struct remove_const {typedef _Tp type;}; |
| 155 | template <class _Tp> struct remove_const<const _Tp> {typedef _Tp type;}; |
| 156 | |
| 157 | template <class _Tp> struct add_lvalue_reference {typedef _Tp& type;}; |
| 158 | |
| 159 | template <class _Tp> struct is_trivially_copy_assignable |
| 160 | : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type, |
| 161 | typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; |
| 162 | |
| 163 | template<class InputIter, class OutputIter> |
| 164 | OutputIter __copy(InputIter II, InputIter IE, OutputIter OI) { |
| 165 | while (II != IE) |
| 166 | *OI++ = *II++; |
| 167 | |
| 168 | return OI; |
| 169 | } |
| 170 | |
| 171 | template <class _Tp, class _Up> |
| 172 | inline |
| 173 | typename enable_if |
| 174 | < |
| 175 | is_same<typename remove_const<_Tp>::type, _Up>::value && |
| 176 | is_trivially_copy_assignable<_Up>::value, |
| 177 | _Up* |
| 178 | >::type __copy(_Tp* __first, _Tp* __last, _Up* __result) { |
| 179 | size_t __n = __last - __first; |
| 180 | |
| 181 | if (__n > 0) |
| 182 | memmove(__result, __first, __n * sizeof(_Up)); |
| 183 | |
| 184 | return __result + __n; |
| 185 | } |
| 186 | |
Jordan Rose | d11ef1a | 2013-04-02 00:26:15 +0000 | [diff] [blame] | 187 | template<class InputIter, class OutputIter> |
| 188 | OutputIter copy(InputIter II, InputIter IE, OutputIter OI) { |
Devin Coughlin | 9165df1 | 2016-02-07 16:55:44 +0000 | [diff] [blame] | 189 | return __copy(II, IE, OI); |
| 190 | } |
| 191 | |
| 192 | template <class _BidirectionalIterator, class _OutputIterator> |
| 193 | inline |
| 194 | _OutputIterator |
| 195 | __copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 196 | _OutputIterator __result) |
| 197 | { |
| 198 | while (__first != __last) |
| 199 | *--__result = *--__last; |
| 200 | return __result; |
| 201 | } |
| 202 | |
| 203 | template <class _Tp, class _Up> |
| 204 | inline |
| 205 | typename enable_if |
| 206 | < |
| 207 | is_same<typename remove_const<_Tp>::type, _Up>::value && |
| 208 | is_trivially_copy_assignable<_Up>::value, |
| 209 | _Up* |
| 210 | >::type __copy_backward(_Tp* __first, _Tp* __last, _Up* __result) { |
| 211 | size_t __n = __last - __first; |
| 212 | |
| 213 | if (__n > 0) |
| 214 | { |
| 215 | __result -= __n; |
| 216 | memmove(__result, __first, __n * sizeof(_Up)); |
| 217 | } |
| 218 | return __result; |
| 219 | } |
| 220 | |
| 221 | template<class InputIter, class OutputIter> |
| 222 | OutputIter copy_backward(InputIter II, InputIter IE, OutputIter OI) { |
| 223 | return __copy_backward(II, IE, OI); |
Jordan Rose | d11ef1a | 2013-04-02 00:26:15 +0000 | [diff] [blame] | 224 | } |
Jordan Rose | 7023a90 | 2013-05-01 22:39:31 +0000 | [diff] [blame] | 225 | |
| 226 | struct input_iterator_tag { }; |
| 227 | struct output_iterator_tag { }; |
| 228 | struct forward_iterator_tag : public input_iterator_tag { }; |
| 229 | struct bidirectional_iterator_tag : public forward_iterator_tag { }; |
| 230 | struct random_access_iterator_tag : public bidirectional_iterator_tag { }; |
Anna Zaks | a42fb52 | 2013-07-04 02:38:10 +0000 | [diff] [blame] | 231 | |
| 232 | template <class _Tp> |
Jordan Rose | 4c56c22 | 2013-11-15 02:11:19 +0000 | [diff] [blame] | 233 | class allocator { |
| 234 | public: |
| 235 | void deallocate(void *p) { |
| 236 | ::delete p; |
| 237 | } |
| 238 | }; |
| 239 | |
| 240 | template <class _Alloc> |
| 241 | class allocator_traits { |
| 242 | public: |
| 243 | static void deallocate(void *p) { |
| 244 | _Alloc().deallocate(p); |
| 245 | } |
| 246 | }; |
Anna Zaks | a42fb52 | 2013-07-04 02:38:10 +0000 | [diff] [blame] | 247 | |
| 248 | template <class _Tp, class _Alloc> |
| 249 | class __list_imp |
| 250 | {}; |
| 251 | |
| 252 | template <class _Tp, class _Alloc = allocator<_Tp> > |
| 253 | class list |
| 254 | : private __list_imp<_Tp, _Alloc> |
| 255 | { |
| 256 | public: |
Anna Zaks | e0ad104 | 2013-07-09 01:55:00 +0000 | [diff] [blame] | 257 | void pop_front() { |
| 258 | // Fake use-after-free. |
Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 259 | // No warning is expected as we are suppressing warning coming |
Anna Zaks | e0ad104 | 2013-07-09 01:55:00 +0000 | [diff] [blame] | 260 | // out of std::list. |
| 261 | int z = 0; |
| 262 | z = 5/z; |
| 263 | } |
Anna Zaks | a42fb52 | 2013-07-04 02:38:10 +0000 | [diff] [blame] | 264 | bool empty() const; |
| 265 | }; |
| 266 | |
Anna Zaks | 830d2f7 | 2013-11-04 19:13:03 +0000 | [diff] [blame] | 267 | // basic_string |
Jordan Rose | 4c56c22 | 2013-11-15 02:11:19 +0000 | [diff] [blame] | 268 | template<class _CharT, class _Alloc = allocator<_CharT> > |
Anna Zaks | 830d2f7 | 2013-11-04 19:13:03 +0000 | [diff] [blame] | 269 | class __attribute__ ((__type_visibility__("default"))) basic_string { |
Jordan Rose | c7d0aca | 2014-02-07 17:35:04 +0000 | [diff] [blame] | 270 | bool isLong; |
| 271 | union { |
| 272 | _CharT localStorage[4]; |
| 273 | _CharT *externalStorage; |
| 274 | |
| 275 | void assignExternal(_CharT *newExternal) { |
| 276 | externalStorage = newExternal; |
| 277 | } |
| 278 | } storage; |
Jordan Rose | 4c56c22 | 2013-11-15 02:11:19 +0000 | [diff] [blame] | 279 | |
| 280 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 281 | |
Anna Zaks | 830d2f7 | 2013-11-04 19:13:03 +0000 | [diff] [blame] | 282 | public: |
Jordan Rose | c7d0aca | 2014-02-07 17:35:04 +0000 | [diff] [blame] | 283 | basic_string(); |
| 284 | |
Jordan Rose | 4c56c22 | 2013-11-15 02:11:19 +0000 | [diff] [blame] | 285 | void push_back(int c) { |
| 286 | // Fake error trigger. |
Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 287 | // No warning is expected as we are suppressing warning coming |
Jordan Rose | 4c56c22 | 2013-11-15 02:11:19 +0000 | [diff] [blame] | 288 | // out of std::basic_string. |
| 289 | int z = 0; |
| 290 | z = 5/z; |
| 291 | } |
| 292 | |
Jordan Rose | c7d0aca | 2014-02-07 17:35:04 +0000 | [diff] [blame] | 293 | _CharT *getBuffer() { |
| 294 | return isLong ? storage.externalStorage : storage.localStorage; |
| 295 | } |
| 296 | |
Jordan Rose | 4c56c22 | 2013-11-15 02:11:19 +0000 | [diff] [blame] | 297 | basic_string &operator +=(int c) { |
| 298 | // Fake deallocate stack-based storage. |
| 299 | // No warning is expected as we are suppressing warnings within |
Jordan Rose | c7d0aca | 2014-02-07 17:35:04 +0000 | [diff] [blame] | 300 | // std::basic_string. |
| 301 | __alloc_traits::deallocate(getBuffer()); |
| 302 | } |
| 303 | |
| 304 | basic_string &operator =(const basic_string &other) { |
| 305 | // Fake deallocate stack-based storage, then use the variable in the |
| 306 | // same union. |
| 307 | // No warning is expected as we are suppressing warnings within |
| 308 | // std::basic_string. |
| 309 | __alloc_traits::deallocate(getBuffer()); |
| 310 | storage.assignExternal(new _CharT[4]); |
Jordan Rose | 4c56c22 | 2013-11-15 02:11:19 +0000 | [diff] [blame] | 311 | } |
Anna Zaks | 830d2f7 | 2013-11-04 19:13:03 +0000 | [diff] [blame] | 312 | }; |
Anna Zaks | ac4c8a6 | 2016-01-06 00:32:52 +0000 | [diff] [blame] | 313 | |
| 314 | template<class _Engine, class _UIntType> |
| 315 | class __independent_bits_engine { |
| 316 | public: |
| 317 | // constructors and seeding functions |
| 318 | __independent_bits_engine(_Engine& __e, size_t __w); |
| 319 | }; |
| 320 | |
| 321 | template<class _Engine, class _UIntType> |
| 322 | __independent_bits_engine<_Engine, _UIntType> |
| 323 | ::__independent_bits_engine(_Engine& __e, size_t __w) |
| 324 | { |
| 325 | // Fake error trigger. |
| 326 | // No warning is expected as we are suppressing warning coming |
| 327 | // out of std::basic_string. |
| 328 | int z = 0; |
| 329 | z = 5/z; |
| 330 | } |
| 331 | |
Jordan Rose | 1e0e400 | 2012-09-10 21:27:35 +0000 | [diff] [blame] | 332 | } |
Anton Yartsev | 13df036 | 2013-03-25 01:35:45 +0000 | [diff] [blame] | 333 | |
| 334 | void* operator new(std::size_t, const std::nothrow_t&) throw(); |
| 335 | void* operator new[](std::size_t, const std::nothrow_t&) throw(); |
| 336 | void operator delete(void*, const std::nothrow_t&) throw(); |
| 337 | void operator delete[](void*, const std::nothrow_t&) throw(); |
| 338 | |
| 339 | void* operator new (std::size_t size, void* ptr) throw() { return ptr; }; |
| 340 | void* operator new[] (std::size_t size, void* ptr) throw() { return ptr; }; |
| 341 | void operator delete (void* ptr, void*) throw() {}; |
| 342 | void operator delete[] (void* ptr, void*) throw() {}; |