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.
6 #pragma clang system_header
7
8 typedef unsigned char uint8_t;
9
10 namespace std {
11 template <class T1, class T2>
12 struct pair {
13 T1 first;
14 T2 second;
15
pairpair16 pair() : first(), second() {}
pairpair17 pair(const T1 &a, const T2 &b) : first(a), second(b) {}
18
19 template<class U1, class U2>
pairpair20 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:
vector()31 vector() : _start(0), _finish(0), _end_of_storage(0) {}
32 ~vector();
33
size()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
begin()49 T *begin() { return _start; }
begin()50 const T *begin() const { return _start; }
51
end()52 T *end() { return _finish; }
end()53 const T *end() const { return _finish; }
54 };
55
56 class exception {
57 public:
58 exception() throw();
59 virtual ~exception() throw();
what()60 virtual const char *what() const throw() {
61 return 0;
62 }
63 };
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();
what()70 virtual const char* what() const throw() {
71 return 0;
72 }
73 };
74
75 struct nothrow_t {};
76
77 extern const nothrow_t nothrow;
78
79 // libc++'s implementation
80 template <class _E>
81 class initializer_list
82 {
83 const _E* __begin_;
84 size_t __size_;
85
initializer_list(const _E * __b,size_t __s)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
initializer_list()100 initializer_list() : __begin_(0), __size_(0) {}
101
size()102 size_t size() const {return __size_;}
begin()103 const _E* begin() const {return __begin_;}
end()104 const _E* end() const {return __begin_ + __size_;}
105 };
106
107 template<class InputIter, class OutputIter>
copy(InputIter II,InputIter IE,OutputIter OI)108 OutputIter copy(InputIter II, InputIter IE, OutputIter OI) {
109 while (II != IE)
110 *OI++ = *II++;
111 return OI;
112 }
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 { };
119
120 template <class _Tp>
121 class allocator {
122 public:
deallocate(void * p)123 void deallocate(void *p) {
124 ::delete p;
125 }
126 };
127
128 template <class _Alloc>
129 class allocator_traits {
130 public:
deallocate(void * p)131 static void deallocate(void *p) {
132 _Alloc().deallocate(p);
133 }
134 };
135
136 template <class _Tp, class _Alloc>
137 class __list_imp
138 {};
139
140 template <class _Tp, class _Alloc = allocator<_Tp> >
141 class list
142 : private __list_imp<_Tp, _Alloc>
143 {
144 public:
pop_front()145 void pop_front() {
146 // Fake use-after-free.
147 // No warning is expected as we are suppressing warning coming
148 // out of std::list.
149 int z = 0;
150 z = 5/z;
151 }
152 bool empty() const;
153 };
154
155 // basic_string
156 template<class _CharT, class _Alloc = allocator<_CharT> >
157 class __attribute__ ((__type_visibility__("default"))) basic_string {
158 bool isLong;
159 union {
160 _CharT localStorage[4];
161 _CharT *externalStorage;
162
assignExternal(_CharT * newExternal)163 void assignExternal(_CharT *newExternal) {
164 externalStorage = newExternal;
165 }
166 } storage;
167
168 typedef allocator_traits<_Alloc> __alloc_traits;
169
170 public:
171 basic_string();
172
push_back(int c)173 void push_back(int c) {
174 // Fake error trigger.
175 // No warning is expected as we are suppressing warning coming
176 // out of std::basic_string.
177 int z = 0;
178 z = 5/z;
179 }
180
getBuffer()181 _CharT *getBuffer() {
182 return isLong ? storage.externalStorage : storage.localStorage;
183 }
184
185 basic_string &operator +=(int c) {
186 // Fake deallocate stack-based storage.
187 // No warning is expected as we are suppressing warnings within
188 // std::basic_string.
189 __alloc_traits::deallocate(getBuffer());
190 }
191
192 basic_string &operator =(const basic_string &other) {
193 // Fake deallocate stack-based storage, then use the variable in the
194 // same union.
195 // No warning is expected as we are suppressing warnings within
196 // std::basic_string.
197 __alloc_traits::deallocate(getBuffer());
198 storage.assignExternal(new _CharT[4]);
199 }
200 };
201 }
202
203 void* operator new(std::size_t, const std::nothrow_t&) throw();
204 void* operator new[](std::size_t, const std::nothrow_t&) throw();
205 void operator delete(void*, const std::nothrow_t&) throw();
206 void operator delete[](void*, const std::nothrow_t&) throw();
207
new(std::size_t size,void * ptr)208 void* operator new (std::size_t size, void* ptr) throw() { return ptr; };
throw()209 void* operator new[] (std::size_t size, void* ptr) throw() { return ptr; };
delete(void * ptr,void *)210 void operator delete (void* ptr, void*) throw() {};
throw()211 void operator delete[] (void* ptr, void*) throw() {};
212