1enum e { OK, KO = -1 };
2typedef _Bool bool;
3
4static int test(int i, long l, long long ll, enum e e, bool b, void *p)
5{
6	int rc = 0;
7
8	// should be OK
9	rc += __builtin_add_overflow(i, i, &i);
10	rc += __builtin_add_overflow(l, i, &i);
11	rc += __builtin_add_overflow(i, l, &i);
12	rc += __builtin_add_overflow(i, i, &l);
13	rc += __builtin_add_overflow(ll, i, &i);
14	rc += __builtin_add_overflow(i, ll, &i);
15	rc += __builtin_add_overflow(i, i, &ll);
16
17	rc += __builtin_add_overflow_p(i, i, i);
18	rc += __builtin_add_overflow_p(l, i, i);
19	rc += __builtin_add_overflow_p(i, l, i);
20	rc += __builtin_add_overflow_p(i, i, l);
21	rc += __builtin_add_overflow_p(ll, i, i);
22	rc += __builtin_add_overflow_p(i, ll, i);
23	rc += __builtin_add_overflow_p(i, i, ll);
24
25	rc += __builtin_sub_overflow(i, i, &i);
26	rc += __builtin_sub_overflow(l, i, &i);
27	rc += __builtin_sub_overflow(i, l, &i);
28	rc += __builtin_sub_overflow(i, i, &l);
29	rc += __builtin_sub_overflow(ll, i, &i);
30	rc += __builtin_sub_overflow(i, ll, &i);
31	rc += __builtin_sub_overflow(i, i, &ll);
32
33	rc += __builtin_sub_overflow_p(i, i, i);
34	rc += __builtin_sub_overflow_p(l, i, i);
35	rc += __builtin_sub_overflow_p(i, l, i);
36	rc += __builtin_sub_overflow_p(i, i, l);
37	rc += __builtin_sub_overflow_p(ll, i, i);
38	rc += __builtin_sub_overflow_p(i, ll, i);
39	rc += __builtin_sub_overflow_p(i, i, ll);
40
41	rc += __builtin_mul_overflow(i, i, &i);
42	rc += __builtin_mul_overflow(l, i, &i);
43	rc += __builtin_mul_overflow(i, l, &i);
44	rc += __builtin_mul_overflow(i, i, &l);
45	rc += __builtin_mul_overflow(ll, i, &i);
46	rc += __builtin_mul_overflow(i, ll, &i);
47	rc += __builtin_mul_overflow(i, i, &ll);
48
49	rc += __builtin_mul_overflow_p(i, i, i);
50	rc += __builtin_mul_overflow_p(l, i, i);
51	rc += __builtin_mul_overflow_p(i, l, i);
52	rc += __builtin_mul_overflow_p(i, i, l);
53	rc += __builtin_mul_overflow_p(ll, i, i);
54	rc += __builtin_mul_overflow_p(i, ll, i);
55	rc += __builtin_mul_overflow_p(i, i, ll);
56
57	// should be KO
58	rc += __builtin_add_overflow();
59	rc += __builtin_add_overflow(i);
60	rc += __builtin_add_overflow(i, i);
61	rc += __builtin_add_overflow(i, i, &i, i);
62	rc += __builtin_add_overflow(e, i, &i);
63	rc += __builtin_add_overflow(i, e, &i);
64	rc += __builtin_add_overflow(i, i, &e);
65	rc += __builtin_add_overflow(b, i, &i);
66	rc += __builtin_add_overflow(i, b, &i);
67	rc += __builtin_add_overflow(i, i, &b);
68	rc += __builtin_add_overflow(i, i, p);
69
70	rc += __builtin_add_overflow_p();
71	rc += __builtin_add_overflow_p(i);
72	rc += __builtin_add_overflow_p(i, i);
73	rc += __builtin_add_overflow_p(i, i, i, i);
74	rc += __builtin_add_overflow_p(e, i, i);
75	rc += __builtin_add_overflow_p(i, e, i);
76	rc += __builtin_add_overflow_p(i, i, e);
77	rc += __builtin_add_overflow_p(b, i, i);
78	rc += __builtin_add_overflow_p(i, b, i);
79	rc += __builtin_add_overflow_p(i, i, b);
80	rc += __builtin_add_overflow_p(i, i, p);
81
82	rc += __builtin_sub_overflow();
83	rc += __builtin_sub_overflow(i);
84	rc += __builtin_sub_overflow(i, i);
85	rc += __builtin_sub_overflow(i, i, &i, i);
86	rc += __builtin_sub_overflow(e, i, &i);
87	rc += __builtin_sub_overflow(i, e, &i);
88	rc += __builtin_sub_overflow(i, i, &e);
89	rc += __builtin_sub_overflow(b, i, &i);
90	rc += __builtin_sub_overflow(i, b, &i);
91	rc += __builtin_sub_overflow(i, i, &b);
92	rc += __builtin_sub_overflow(i, i, p);
93
94	rc += __builtin_sub_overflow_p();
95	rc += __builtin_sub_overflow_p(i);
96	rc += __builtin_sub_overflow_p(i, i);
97	rc += __builtin_sub_overflow_p(i, i, i, i);
98	rc += __builtin_sub_overflow_p(e, i, i);
99	rc += __builtin_sub_overflow_p(i, e, i);
100	rc += __builtin_sub_overflow_p(i, i, e);
101	rc += __builtin_sub_overflow_p(b, i, i);
102	rc += __builtin_sub_overflow_p(i, b, i);
103	rc += __builtin_sub_overflow_p(i, i, b);
104	rc += __builtin_sub_overflow_p(i, i, p);
105
106	rc += __builtin_mul_overflow();
107	rc += __builtin_mul_overflow(i);
108	rc += __builtin_mul_overflow(i, i);
109	rc += __builtin_mul_overflow(i, i, &i, i);
110	rc += __builtin_mul_overflow(e, i, &i);
111	rc += __builtin_mul_overflow(i, e, &i);
112	rc += __builtin_mul_overflow(i, i, &e);
113	rc += __builtin_mul_overflow(b, i, &i);
114	rc += __builtin_mul_overflow(i, b, &i);
115	rc += __builtin_mul_overflow(i, i, &b);
116	rc += __builtin_mul_overflow(i, i, p);
117
118	rc += __builtin_mul_overflow_p();
119	rc += __builtin_mul_overflow_p(i);
120	rc += __builtin_mul_overflow_p(i, i);
121	rc += __builtin_mul_overflow_p(i, i, i, i);
122	rc += __builtin_mul_overflow_p(e, i, i);
123	rc += __builtin_mul_overflow_p(i, e, i);
124	rc += __builtin_mul_overflow_p(i, i, e);
125	rc += __builtin_mul_overflow_p(b, i, i);
126	rc += __builtin_mul_overflow_p(i, b, i);
127	rc += __builtin_mul_overflow_p(i, i, b);
128	rc += __builtin_mul_overflow_p(i, i, p);
129
130	return rc;
131}
132
133/*
134 * check-name: builtin-overflow
135 *
136 * check-error-start
137builtin-overflow.c:58:37: error: not enough arguments for __builtin_add_overflow
138builtin-overflow.c:59:37: error: not enough arguments for __builtin_add_overflow
139builtin-overflow.c:60:37: error: not enough arguments for __builtin_add_overflow
140builtin-overflow.c:61:37: error: too many arguments for __builtin_add_overflow
141builtin-overflow.c:62:38: error: invalid type for argument 1:
142builtin-overflow.c:62:38:         int enum e e
143builtin-overflow.c:63:41: error: invalid type for argument 2:
144builtin-overflow.c:63:41:         int enum e e
145builtin-overflow.c:64:45: error: invalid type for argument 3:
146builtin-overflow.c:64:45:         int enum e *
147builtin-overflow.c:65:38: error: invalid type for argument 1:
148builtin-overflow.c:65:38:         bool [usertype] b
149builtin-overflow.c:66:41: error: invalid type for argument 2:
150builtin-overflow.c:66:41:         bool [usertype] b
151builtin-overflow.c:67:45: error: invalid type for argument 3:
152builtin-overflow.c:67:45:         bool *
153builtin-overflow.c:68:44: error: invalid type for argument 3:
154builtin-overflow.c:68:44:         void *p
155builtin-overflow.c:70:39: error: not enough arguments for __builtin_add_overflow_p
156builtin-overflow.c:71:39: error: not enough arguments for __builtin_add_overflow_p
157builtin-overflow.c:72:39: error: not enough arguments for __builtin_add_overflow_p
158builtin-overflow.c:73:39: error: too many arguments for __builtin_add_overflow_p
159builtin-overflow.c:74:40: error: invalid type for argument 1:
160builtin-overflow.c:74:40:         int enum e [addressable] e
161builtin-overflow.c:75:43: error: invalid type for argument 2:
162builtin-overflow.c:75:43:         int enum e [addressable] e
163builtin-overflow.c:76:46: error: invalid type for argument 3:
164builtin-overflow.c:76:46:         int enum e [addressable] e
165builtin-overflow.c:77:40: error: invalid type for argument 1:
166builtin-overflow.c:77:40:         bool [addressable] [usertype] b
167builtin-overflow.c:78:43: error: invalid type for argument 2:
168builtin-overflow.c:78:43:         bool [addressable] [usertype] b
169builtin-overflow.c:79:46: error: invalid type for argument 3:
170builtin-overflow.c:79:46:         bool [addressable] [usertype] b
171builtin-overflow.c:80:46: error: invalid type for argument 3:
172builtin-overflow.c:80:46:         void *p
173builtin-overflow.c:82:37: error: not enough arguments for __builtin_sub_overflow
174builtin-overflow.c:83:37: error: not enough arguments for __builtin_sub_overflow
175builtin-overflow.c:84:37: error: not enough arguments for __builtin_sub_overflow
176builtin-overflow.c:85:37: error: too many arguments for __builtin_sub_overflow
177builtin-overflow.c:86:38: error: invalid type for argument 1:
178builtin-overflow.c:86:38:         int enum e [addressable] e
179builtin-overflow.c:87:41: error: invalid type for argument 2:
180builtin-overflow.c:87:41:         int enum e [addressable] e
181builtin-overflow.c:88:45: error: invalid type for argument 3:
182builtin-overflow.c:88:45:         int enum e *
183builtin-overflow.c:89:38: error: invalid type for argument 1:
184builtin-overflow.c:89:38:         bool [addressable] [usertype] b
185builtin-overflow.c:90:41: error: invalid type for argument 2:
186builtin-overflow.c:90:41:         bool [addressable] [usertype] b
187builtin-overflow.c:91:45: error: invalid type for argument 3:
188builtin-overflow.c:91:45:         bool *
189builtin-overflow.c:92:44: error: invalid type for argument 3:
190builtin-overflow.c:92:44:         void *p
191builtin-overflow.c:94:39: error: not enough arguments for __builtin_sub_overflow_p
192builtin-overflow.c:95:39: error: not enough arguments for __builtin_sub_overflow_p
193builtin-overflow.c:96:39: error: not enough arguments for __builtin_sub_overflow_p
194builtin-overflow.c:97:39: error: too many arguments for __builtin_sub_overflow_p
195builtin-overflow.c:98:40: error: invalid type for argument 1:
196builtin-overflow.c:98:40:         int enum e [addressable] e
197builtin-overflow.c:99:43: error: invalid type for argument 2:
198builtin-overflow.c:99:43:         int enum e [addressable] e
199builtin-overflow.c:100:46: error: invalid type for argument 3:
200builtin-overflow.c:100:46:         int enum e [addressable] e
201builtin-overflow.c:101:40: error: invalid type for argument 1:
202builtin-overflow.c:101:40:         bool [addressable] [usertype] b
203builtin-overflow.c:102:43: error: invalid type for argument 2:
204builtin-overflow.c:102:43:         bool [addressable] [usertype] b
205builtin-overflow.c:103:46: error: invalid type for argument 3:
206builtin-overflow.c:103:46:         bool [addressable] [usertype] b
207builtin-overflow.c:104:46: error: invalid type for argument 3:
208builtin-overflow.c:104:46:         void *p
209builtin-overflow.c:106:37: error: not enough arguments for __builtin_mul_overflow
210builtin-overflow.c:107:37: error: not enough arguments for __builtin_mul_overflow
211builtin-overflow.c:108:37: error: not enough arguments for __builtin_mul_overflow
212builtin-overflow.c:109:37: error: too many arguments for __builtin_mul_overflow
213builtin-overflow.c:110:38: error: invalid type for argument 1:
214builtin-overflow.c:110:38:         int enum e [addressable] e
215builtin-overflow.c:111:41: error: invalid type for argument 2:
216builtin-overflow.c:111:41:         int enum e [addressable] e
217builtin-overflow.c:112:45: error: invalid type for argument 3:
218builtin-overflow.c:112:45:         int enum e *
219builtin-overflow.c:113:38: error: invalid type for argument 1:
220builtin-overflow.c:113:38:         bool [addressable] [usertype] b
221builtin-overflow.c:114:41: error: invalid type for argument 2:
222builtin-overflow.c:114:41:         bool [addressable] [usertype] b
223builtin-overflow.c:115:45: error: invalid type for argument 3:
224builtin-overflow.c:115:45:         bool *
225builtin-overflow.c:116:44: error: invalid type for argument 3:
226builtin-overflow.c:116:44:         void *p
227builtin-overflow.c:118:39: error: not enough arguments for __builtin_mul_overflow_p
228builtin-overflow.c:119:39: error: not enough arguments for __builtin_mul_overflow_p
229builtin-overflow.c:120:39: error: not enough arguments for __builtin_mul_overflow_p
230builtin-overflow.c:121:39: error: too many arguments for __builtin_mul_overflow_p
231builtin-overflow.c:122:40: error: invalid type for argument 1:
232builtin-overflow.c:122:40:         int enum e [addressable] e
233builtin-overflow.c:123:43: error: invalid type for argument 2:
234builtin-overflow.c:123:43:         int enum e [addressable] e
235builtin-overflow.c:124:46: error: invalid type for argument 3:
236builtin-overflow.c:124:46:         int enum e [addressable] e
237builtin-overflow.c:125:40: error: invalid type for argument 1:
238builtin-overflow.c:125:40:         bool [addressable] [usertype] b
239builtin-overflow.c:126:43: error: invalid type for argument 2:
240builtin-overflow.c:126:43:         bool [addressable] [usertype] b
241builtin-overflow.c:127:46: error: invalid type for argument 3:
242builtin-overflow.c:127:46:         bool [addressable] [usertype] b
243builtin-overflow.c:128:46: error: invalid type for argument 3:
244builtin-overflow.c:128:46:         void *p
245 * check-error-end
246 */
247