1*67e74705SXin Li // This is a fake system header with divide-by-zero bugs introduced in
2*67e74705SXin Li // c++ std library functions. We use these bugs to test hard-coded
3*67e74705SXin Li // suppression of diagnostics within standard library functions that are known
4*67e74705SXin Li // to produce false positives.
5*67e74705SXin Li
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
15*67e74705SXin Li template <class _Tp>
16*67e74705SXin Li class allocator {
17*67e74705SXin Li public:
deallocate(void * p)18*67e74705SXin Li void deallocate(void *p) {
19*67e74705SXin Li ::delete p;
20*67e74705SXin Li }
21*67e74705SXin Li };
22*67e74705SXin Li
23*67e74705SXin Li template <class _Alloc>
24*67e74705SXin Li class allocator_traits {
25*67e74705SXin Li public:
deallocate(void * p)26*67e74705SXin Li static void deallocate(void *p) {
27*67e74705SXin Li _Alloc().deallocate(p);
28*67e74705SXin Li }
29*67e74705SXin Li };
30*67e74705SXin Li
31*67e74705SXin Li template <class _Tp, class _Alloc>
32*67e74705SXin Li class __list_imp
33*67e74705SXin Li {};
34*67e74705SXin Li
35*67e74705SXin Li template <class _Tp, class _Alloc = allocator<_Tp> >
36*67e74705SXin Li class list
37*67e74705SXin Li : private __list_imp<_Tp, _Alloc>
38*67e74705SXin Li {
39*67e74705SXin Li public:
pop_front()40*67e74705SXin Li void pop_front() {
41*67e74705SXin Li // Fake use-after-free.
42*67e74705SXin Li // No warning is expected as we are suppressing warning coming
43*67e74705SXin Li // out of std::list.
44*67e74705SXin Li int z = 0;
45*67e74705SXin Li z = 5/z;
46*67e74705SXin Li }
47*67e74705SXin Li bool empty() const;
48*67e74705SXin Li };
49*67e74705SXin Li
50*67e74705SXin Li // basic_string
51*67e74705SXin Li template<class _CharT, class _Alloc = allocator<_CharT> >
52*67e74705SXin Li class __attribute__ ((__type_visibility__("default"))) basic_string {
53*67e74705SXin Li bool isLong;
54*67e74705SXin Li union {
55*67e74705SXin Li _CharT localStorage[4];
56*67e74705SXin Li _CharT *externalStorage;
57*67e74705SXin Li
assignExternal(_CharT * newExternal)58*67e74705SXin Li void assignExternal(_CharT *newExternal) {
59*67e74705SXin Li externalStorage = newExternal;
60*67e74705SXin Li }
61*67e74705SXin Li } storage;
62*67e74705SXin Li
63*67e74705SXin Li typedef allocator_traits<_Alloc> __alloc_traits;
64*67e74705SXin Li
65*67e74705SXin Li public:
66*67e74705SXin Li basic_string();
67*67e74705SXin Li
push_back(int c)68*67e74705SXin Li void push_back(int c) {
69*67e74705SXin Li // Fake error trigger.
70*67e74705SXin Li // No warning is expected as we are suppressing warning coming
71*67e74705SXin Li // out of std::basic_string.
72*67e74705SXin Li int z = 0;
73*67e74705SXin Li z = 5/z;
74*67e74705SXin Li }
75*67e74705SXin Li
getBuffer()76*67e74705SXin Li _CharT *getBuffer() {
77*67e74705SXin Li return isLong ? storage.externalStorage : storage.localStorage;
78*67e74705SXin Li }
79*67e74705SXin Li
80*67e74705SXin Li basic_string &operator +=(int c) {
81*67e74705SXin Li // Fake deallocate stack-based storage.
82*67e74705SXin Li // No warning is expected as we are suppressing warnings within
83*67e74705SXin Li // std::basic_string.
84*67e74705SXin Li __alloc_traits::deallocate(getBuffer());
85*67e74705SXin Li }
86*67e74705SXin Li
87*67e74705SXin Li basic_string &operator =(const basic_string &other) {
88*67e74705SXin Li // Fake deallocate stack-based storage, then use the variable in the
89*67e74705SXin Li // same union.
90*67e74705SXin Li // No warning is expected as we are suppressing warnings within
91*67e74705SXin Li // std::basic_string.
92*67e74705SXin Li __alloc_traits::deallocate(getBuffer());
93*67e74705SXin Li storage.assignExternal(new _CharT[4]);
94*67e74705SXin Li }
95*67e74705SXin Li };
96*67e74705SXin Li
97*67e74705SXin Li template<class _Engine, class _UIntType>
98*67e74705SXin Li class __independent_bits_engine {
99*67e74705SXin Li public:
100*67e74705SXin Li // constructors and seeding functions
101*67e74705SXin Li __independent_bits_engine(_Engine& __e, size_t __w);
102*67e74705SXin Li };
103*67e74705SXin Li
104*67e74705SXin Li template<class _Engine, class _UIntType>
105*67e74705SXin Li __independent_bits_engine<_Engine, _UIntType>
__independent_bits_engine(_Engine & __e,size_t __w)106*67e74705SXin Li ::__independent_bits_engine(_Engine& __e, size_t __w)
107*67e74705SXin Li {
108*67e74705SXin Li // Fake error trigger.
109*67e74705SXin Li // No warning is expected as we are suppressing warning coming
110*67e74705SXin Li // out of std::__independent_bits_engine.
111*67e74705SXin Li int z = 0;
112*67e74705SXin Li z = 5/z;
113*67e74705SXin Li }
114*67e74705SXin Li
115*67e74705SXin Li #if __has_feature(cxx_decltype)
116*67e74705SXin Li typedef decltype(nullptr) nullptr_t;
117*67e74705SXin Li
118*67e74705SXin Li template<class _Tp>
119*67e74705SXin Li class shared_ptr
120*67e74705SXin Li {
121*67e74705SXin Li public:
122*67e74705SXin Li constexpr shared_ptr(nullptr_t);
123*67e74705SXin Li explicit shared_ptr(_Tp* __p);
124*67e74705SXin Li
shared_ptr(shared_ptr && __r)125*67e74705SXin Li shared_ptr(shared_ptr&& __r) { }
126*67e74705SXin Li
127*67e74705SXin Li ~shared_ptr();
128*67e74705SXin Li
129*67e74705SXin Li shared_ptr& operator=(shared_ptr&& __r) {
130*67e74705SXin Li // Fake error trigger.
131*67e74705SXin Li // No warning is expected as we are suppressing warning coming
132*67e74705SXin Li // out of std::shared_ptr.
133*67e74705SXin Li int z = 0;
134*67e74705SXin Li z = 5/z;
135*67e74705SXin Li }
136*67e74705SXin Li };
137*67e74705SXin Li
138*67e74705SXin Li template<class _Tp>
139*67e74705SXin Li inline
140*67e74705SXin Li constexpr
shared_ptr(nullptr_t)141*67e74705SXin Li shared_ptr<_Tp>::shared_ptr(nullptr_t) {
142*67e74705SXin Li }
143*67e74705SXin Li
144*67e74705SXin Li #endif // __has_feature(cxx_decltype)
145*67e74705SXin Li }
146*67e74705SXin Li
147