18c888b10fdd2846885e8582b131fa076ce1b77b1Jordan Rose// Like the compiler, the static analyzer treats some functions differently if
28c888b10fdd2846885e8582b131fa076ce1b77b1Jordan Rose// they come from a system header -- for example, it is assumed that system
38c888b10fdd2846885e8582b131fa076ce1b77b1Jordan Rose// functions do not arbitrarily free() their parameters, and that some bugs
48c888b10fdd2846885e8582b131fa076ce1b77b1Jordan Rose// found in system headers cannot be fixed by the user and should be
58c888b10fdd2846885e8582b131fa076ce1b77b1Jordan Rose// suppressed.
681fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose#pragma clang system_header
781fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
8bdc0bf3f84b8771572d8401c66903c56a2e1318eAnna Zakstypedef unsigned char uint8_t;
9bdc0bf3f84b8771572d8401c66903c56a2e1318eAnna Zaks
1081fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rosenamespace std {
1181fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose  template <class T1, class T2>
1281fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose  struct pair {
1381fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    T1 first;
1481fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    T2 second;
1581fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
1681fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    pair() : first(), second() {}
1781fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    pair(const T1 &a, const T2 &b) : first(a), second(b) {}
1881fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
1981fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    template<class U1, class U2>
2081fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    pair(const pair<U1, U2> &other) : first(other.first), second(other.second) {}
2181fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose  };
2281fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
2381fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose  typedef __typeof__(sizeof(int)) size_t;
2481fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
2581fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose  template<typename T>
2681fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose  class vector {
2781fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    T *_start;
2881fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    T *_finish;
2981fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    T *_end_of_storage;
3081fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose  public:
3181fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    vector() : _start(0), _finish(0), _end_of_storage(0) {}
3281fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    ~vector();
3381fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
3481fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    size_t size() const {
3581fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose      return size_t(_finish - _start);
3681fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    }
3781fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
3881fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    void push_back();
3981fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    T pop_back();
4081fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
4181fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    T &operator[](size_t n) {
4281fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose      return _start[n];
4381fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    }
4481fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
4581fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    const T &operator[](size_t n) const {
4681fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose      return _start[n];
4781fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    }
4881fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
4981fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    T *begin() { return _start; }
5081fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    const T *begin() const { return _start; }
5181fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
5281fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    T *end() { return _finish; }
5381fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    const T *end() const { return _finish; }
5481fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose  };
5581fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose
5681fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose  class exception {
5781fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose  public:
5881fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    exception() throw();
5981fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    virtual ~exception() throw();
6081fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    virtual const char *what() const throw() {
6181fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose      return 0;
6281fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose    }
6381fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose  };
642de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev
652de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev  class bad_alloc : public exception {
662de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev    public:
672de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev    bad_alloc() throw();
682de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev    bad_alloc(const bad_alloc&) throw();
692de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev    bad_alloc& operator=(const bad_alloc&) throw();
702de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev    virtual const char* what() const throw() {
712de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev      return 0;
722de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev    }
732de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev  };
742de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev
752de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev  struct nothrow_t {};
762de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev
772de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev  extern const nothrow_t nothrow;
78a12643622ad3b85972dfdd80fe9006a3e8d8fb80Jordan Rose
79be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose  // libc++'s implementation
80be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose  template <class _E>
81be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose  class initializer_list
82be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose  {
83be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    const _E* __begin_;
84be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    size_t    __size_;
85be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose
86be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    initializer_list(const _E* __b, size_t __s)
87be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose      : __begin_(__b),
88be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose        __size_(__s)
89be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    {}
90be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose
91be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose  public:
92be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    typedef _E        value_type;
93be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    typedef const _E& reference;
94be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    typedef const _E& const_reference;
95be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    typedef size_t    size_type;
96be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose
97be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    typedef const _E* iterator;
98be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    typedef const _E* const_iterator;
99be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose
100be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    initializer_list() : __begin_(0), __size_(0) {}
101be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose
102be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    size_t    size()  const {return __size_;}
103be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    const _E* begin() const {return __begin_;}
104be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose    const _E* end()   const {return __begin_ + __size_;}
105be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose  };
106be2e1b11e3350e3a6e632c71beaab83aae3824d2Jordan Rose
107a12643622ad3b85972dfdd80fe9006a3e8d8fb80Jordan Rose  template<class InputIter, class OutputIter>
108a12643622ad3b85972dfdd80fe9006a3e8d8fb80Jordan Rose  OutputIter copy(InputIter II, InputIter IE, OutputIter OI) {
109a12643622ad3b85972dfdd80fe9006a3e8d8fb80Jordan Rose    while (II != IE)
110a12643622ad3b85972dfdd80fe9006a3e8d8fb80Jordan Rose      *OI++ = *II++;
111a12643622ad3b85972dfdd80fe9006a3e8d8fb80Jordan Rose    return OI;
112a12643622ad3b85972dfdd80fe9006a3e8d8fb80Jordan Rose  }
113776d3bb65c90278b9c65544b235d2ac40aea1d6eJordan Rose
114776d3bb65c90278b9c65544b235d2ac40aea1d6eJordan Rose  struct input_iterator_tag { };
115776d3bb65c90278b9c65544b235d2ac40aea1d6eJordan Rose  struct output_iterator_tag { };
116776d3bb65c90278b9c65544b235d2ac40aea1d6eJordan Rose  struct forward_iterator_tag : public input_iterator_tag { };
117776d3bb65c90278b9c65544b235d2ac40aea1d6eJordan Rose  struct bidirectional_iterator_tag : public forward_iterator_tag { };
118776d3bb65c90278b9c65544b235d2ac40aea1d6eJordan Rose  struct random_access_iterator_tag : public bidirectional_iterator_tag { };
1198b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks
1208b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks  template <class _Tp>
121fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose  class allocator {
122fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose  public:
123fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose    void deallocate(void *p) {
124fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose      ::delete p;
125fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose    }
126fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose  };
127fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose
128fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose  template <class _Alloc>
129fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose  class allocator_traits {
130fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose  public:
131fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose    static void deallocate(void *p) {
132fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose      _Alloc().deallocate(p);
133fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose    }
134fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose  };
1358b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks
1368b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks  template <class _Tp, class _Alloc>
1378b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks  class __list_imp
1388b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks  {};
1398b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks
1408b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks  template <class _Tp, class _Alloc = allocator<_Tp> >
1418b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks  class list
1428b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks  : private __list_imp<_Tp, _Alloc>
1438b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks  {
1448b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks  public:
145e600d4be7d01661ab7601f9ef9c4d3236c377385Anna Zaks    void pop_front() {
146e600d4be7d01661ab7601f9ef9c4d3236c377385Anna Zaks      // Fake use-after-free.
147651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      // No warning is expected as we are suppressing warning coming
148e600d4be7d01661ab7601f9ef9c4d3236c377385Anna Zaks      // out of std::list.
149e600d4be7d01661ab7601f9ef9c4d3236c377385Anna Zaks      int z = 0;
150e600d4be7d01661ab7601f9ef9c4d3236c377385Anna Zaks      z = 5/z;
151e600d4be7d01661ab7601f9ef9c4d3236c377385Anna Zaks    }
1528b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks    bool empty() const;
1538b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks  };
1548b625a3f7764959d0a2ac3cd860ce1e168e0fc9bAnna Zaks
155bdc0bf3f84b8771572d8401c66903c56a2e1318eAnna Zaks  // basic_string
156fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose  template<class _CharT, class _Alloc = allocator<_CharT> >
157bdc0bf3f84b8771572d8401c66903c56a2e1318eAnna Zaks  class __attribute__ ((__type_visibility__("default"))) basic_string {
158651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    bool isLong;
159651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    union {
160651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      _CharT localStorage[4];
161651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      _CharT *externalStorage;
162651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
163651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      void assignExternal(_CharT *newExternal) {
164651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines        externalStorage = newExternal;
165651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      }
166651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    } storage;
167fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose
168fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose    typedef allocator_traits<_Alloc> __alloc_traits;
169fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose
170bdc0bf3f84b8771572d8401c66903c56a2e1318eAnna Zaks  public:
171651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    basic_string();
172651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
173fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose    void push_back(int c) {
174fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose      // Fake error trigger.
175651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      // No warning is expected as we are suppressing warning coming
176fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose      // out of std::basic_string.
177fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose      int z = 0;
178fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose      z = 5/z;
179fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose    }
180fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose
181651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    _CharT *getBuffer() {
182651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      return isLong ? storage.externalStorage : storage.localStorage;
183651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    }
184651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
185fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose    basic_string &operator +=(int c) {
186fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose      // Fake deallocate stack-based storage.
187fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose      // No warning is expected as we are suppressing warnings within
188651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      // std::basic_string.
189651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      __alloc_traits::deallocate(getBuffer());
190651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    }
191651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
192651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    basic_string &operator =(const basic_string &other) {
193651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      // Fake deallocate stack-based storage, then use the variable in the
194651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      // same union.
195651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      // No warning is expected as we are suppressing warnings within
196651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      // std::basic_string.
197651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      __alloc_traits::deallocate(getBuffer());
198651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      storage.assignExternal(new _CharT[4]);
199fda9dbf1f4d15baaedffdd4b4bb529e06172f73dJordan Rose    }
200bdc0bf3f84b8771572d8401c66903c56a2e1318eAnna Zaks  };
20181fb50e8b120fc95dc0245b4112972d4d7cca3b5Jordan Rose}
2022de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev
2032de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsevvoid* operator new(std::size_t, const std::nothrow_t&) throw();
2042de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsevvoid* operator new[](std::size_t, const std::nothrow_t&) throw();
2052de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsevvoid operator delete(void*, const std::nothrow_t&) throw();
2062de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsevvoid operator delete[](void*, const std::nothrow_t&) throw();
2072de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsev
2082de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsevvoid* operator new (std::size_t size, void* ptr) throw() { return ptr; };
2092de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsevvoid* operator new[] (std::size_t size, void* ptr) throw() { return ptr; };
2102de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsevvoid operator delete (void* ptr, void*) throw() {};
2112de19edab6001d2c17720d02fe0760b9b452192aAnton Yartsevvoid operator delete[] (void* ptr, void*) throw() {};
212