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 | |
Jordan Rose | 1e0e400 | 2012-09-10 21:27:35 +0000 | [diff] [blame] | 10 | namespace std { |
| 11 | template <class T1, class T2> |
| 12 | struct pair { |
| 13 | T1 first; |
| 14 | T2 second; |
| 15 | |
| 16 | pair() : first(), second() {} |
| 17 | pair(const T1 &a, const T2 &b) : first(a), second(b) {} |
| 18 | |
| 19 | template<class U1, class U2> |
| 20 | pair(const pair<U1, U2> &other) : first(other.first), second(other.second) {} |
| 21 | }; |
| 22 | |
| 23 | typedef __typeof__(sizeof(int)) size_t; |
| 24 | |
| 25 | template<typename T> |
| 26 | class vector { |
| 27 | T *_start; |
| 28 | T *_finish; |
| 29 | T *_end_of_storage; |
| 30 | public: |
| 31 | vector() : _start(0), _finish(0), _end_of_storage(0) {} |
| 32 | ~vector(); |
| 33 | |
| 34 | size_t size() const { |
| 35 | return size_t(_finish - _start); |
| 36 | } |
| 37 | |
| 38 | void push_back(); |
| 39 | T pop_back(); |
| 40 | |
| 41 | T &operator[](size_t n) { |
| 42 | return _start[n]; |
| 43 | } |
| 44 | |
| 45 | const T &operator[](size_t n) const { |
| 46 | return _start[n]; |
| 47 | } |
| 48 | |
| 49 | T *begin() { return _start; } |
| 50 | const T *begin() const { return _start; } |
| 51 | |
| 52 | T *end() { return _finish; } |
| 53 | const T *end() const { return _finish; } |
| 54 | }; |
| 55 | |
| 56 | class exception { |
| 57 | public: |
| 58 | exception() throw(); |
| 59 | virtual ~exception() throw(); |
| 60 | virtual const char *what() const throw() { |
| 61 | return 0; |
| 62 | } |
| 63 | }; |
Anton Yartsev | 13df036 | 2013-03-25 01:35:45 +0000 | [diff] [blame] | 64 | |
| 65 | class bad_alloc : public exception { |
| 66 | public: |
| 67 | bad_alloc() throw(); |
| 68 | bad_alloc(const bad_alloc&) throw(); |
| 69 | bad_alloc& operator=(const bad_alloc&) throw(); |
| 70 | virtual const char* what() const throw() { |
| 71 | return 0; |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | struct nothrow_t {}; |
| 76 | |
| 77 | extern const nothrow_t nothrow; |
Jordan Rose | d11ef1a | 2013-04-02 00:26:15 +0000 | [diff] [blame] | 78 | |
Jordan Rose | 05b2f98 | 2013-07-17 17:16:33 +0000 | [diff] [blame] | 79 | // libc++'s implementation |
| 80 | template <class _E> |
| 81 | class initializer_list |
| 82 | { |
| 83 | const _E* __begin_; |
| 84 | size_t __size_; |
| 85 | |
| 86 | initializer_list(const _E* __b, size_t __s) |
| 87 | : __begin_(__b), |
| 88 | __size_(__s) |
| 89 | {} |
| 90 | |
| 91 | public: |
| 92 | typedef _E value_type; |
| 93 | typedef const _E& reference; |
| 94 | typedef const _E& const_reference; |
| 95 | typedef size_t size_type; |
| 96 | |
| 97 | typedef const _E* iterator; |
| 98 | typedef const _E* const_iterator; |
| 99 | |
| 100 | initializer_list() : __begin_(0), __size_(0) {} |
| 101 | |
| 102 | size_t size() const {return __size_;} |
| 103 | const _E* begin() const {return __begin_;} |
| 104 | const _E* end() const {return __begin_ + __size_;} |
| 105 | }; |
| 106 | |
Jordan Rose | d11ef1a | 2013-04-02 00:26:15 +0000 | [diff] [blame] | 107 | template<class InputIter, class OutputIter> |
| 108 | OutputIter copy(InputIter II, InputIter IE, OutputIter OI) { |
| 109 | while (II != IE) |
| 110 | *OI++ = *II++; |
| 111 | return OI; |
| 112 | } |
Jordan Rose | 7023a90 | 2013-05-01 22:39:31 +0000 | [diff] [blame] | 113 | |
| 114 | struct input_iterator_tag { }; |
| 115 | struct output_iterator_tag { }; |
| 116 | struct forward_iterator_tag : public input_iterator_tag { }; |
| 117 | struct bidirectional_iterator_tag : public forward_iterator_tag { }; |
| 118 | struct random_access_iterator_tag : public bidirectional_iterator_tag { }; |
Anna Zaks | a42fb52 | 2013-07-04 02:38:10 +0000 | [diff] [blame] | 119 | |
| 120 | template <class _Tp> |
| 121 | class allocator {}; |
| 122 | |
| 123 | template <class _Tp, class _Alloc> |
| 124 | class __list_imp |
| 125 | {}; |
| 126 | |
| 127 | template <class _Tp, class _Alloc = allocator<_Tp> > |
| 128 | class list |
| 129 | : private __list_imp<_Tp, _Alloc> |
| 130 | { |
| 131 | public: |
Anna Zaks | e0ad104 | 2013-07-09 01:55:00 +0000 | [diff] [blame] | 132 | void pop_front() { |
| 133 | // Fake use-after-free. |
| 134 | // No warning is expected as we are suppressing warning comming |
| 135 | // out of std::list. |
| 136 | int z = 0; |
| 137 | z = 5/z; |
| 138 | } |
Anna Zaks | a42fb52 | 2013-07-04 02:38:10 +0000 | [diff] [blame] | 139 | bool empty() const; |
| 140 | }; |
| 141 | |
Anna Zaks | 830d2f7 | 2013-11-04 19:13:03 +0000 | [diff] [blame^] | 142 | // basic_string |
| 143 | template<class _CharT> |
| 144 | class __attribute__ ((__type_visibility__("default"))) basic_string { |
| 145 | public: |
| 146 | void push_back(int c); |
| 147 | }; |
| 148 | template <class _CharT> |
| 149 | void basic_string<_CharT>::push_back(int __c) { |
| 150 | // Fake error trigger. |
| 151 | // No warning is expected as we are suppressing warning comming |
| 152 | // out of std::basic_string. |
| 153 | int z = 0; |
| 154 | z = 5/z; |
| 155 | } |
Jordan Rose | 1e0e400 | 2012-09-10 21:27:35 +0000 | [diff] [blame] | 156 | } |
Anton Yartsev | 13df036 | 2013-03-25 01:35:45 +0000 | [diff] [blame] | 157 | |
| 158 | void* operator new(std::size_t, const std::nothrow_t&) throw(); |
| 159 | void* operator new[](std::size_t, const std::nothrow_t&) throw(); |
| 160 | void operator delete(void*, const std::nothrow_t&) throw(); |
| 161 | void operator delete[](void*, const std::nothrow_t&) throw(); |
| 162 | |
| 163 | void* operator new (std::size_t size, void* ptr) throw() { return ptr; }; |
| 164 | void* operator new[] (std::size_t size, void* ptr) throw() { return ptr; }; |
| 165 | void operator delete (void* ptr, void*) throw() {}; |
| 166 | void operator delete[] (void* ptr, void*) throw() {}; |