math: store all constant EXPR_BINOP results
[smatch.git] / builtin.c
blob2e9be8be8adb58d687ee80c15a8608883625645e
1 /*
2 * builtin evaluation & expansion.
4 * Copyright (C) 2003 Transmeta Corp.
5 * 2003-2004 Linus Torvalds
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
26 #include "builtin.h"
27 #include "expression.h"
28 #include "evaluate.h"
29 #include "expand.h"
30 #include "symbol.h"
31 #include "compat/bswap.h"
32 #include <stdarg.h>
34 static int evaluate_to_int_const_expr(struct expression *expr)
36 expr->ctype = &int_ctype;
37 expr->flags |= CEF_SET_ICE;
38 return 1;
41 static int evaluate_pure_unop(struct expression *expr)
43 struct expression *arg = first_expression(expr->args);
44 int flags = arg->flags;
47 * Allow such functions with a constant integer expression
48 * argument to be treated as a *constant* integer.
49 * This allow us to use them in switch() { case ...:
51 flags |= (flags & CEF_ICE) ? CEF_SET_INT : 0;
52 expr->flags = flags;
53 return 1;
57 * eval_args - check the number of arguments and evaluate them.
59 static int eval_args(struct expression *expr, int n)
61 struct expression *arg;
62 struct symbol *sym;
63 const char *msg;
64 int rc = 1;
66 FOR_EACH_PTR(expr->args, arg) {
67 if (n-- == 0) {
68 msg = "too many arguments";
69 goto error;
71 if (!evaluate_expression(arg))
72 rc = 0;
73 } END_FOR_EACH_PTR(arg);
74 if (n > 0) {
75 msg = "not enough arguments";
76 goto error;
78 return rc;
80 error:
81 sym = expr->fn->ctype;
82 expression_error(expr, "%s for %s", msg, show_ident(sym->ident));
83 return 0;
86 static int args_triadic(struct expression *expr)
88 return eval_args(expr, 3);
91 static int evaluate_choose(struct expression *expr)
93 struct expression_list *list = expr->args;
94 struct expression *arg, *args[3];
95 int n = 0;
97 /* there will be exactly 3; we'd already verified that */
98 FOR_EACH_PTR(list, arg) {
99 args[n++] = arg;
100 } END_FOR_EACH_PTR(arg);
102 *expr = get_expression_value(args[0]) ? *args[1] : *args[2];
104 return 1;
107 static int expand_expect(struct expression *expr, int cost)
109 struct expression *arg = first_ptr_list((struct ptr_list *) expr->args);
111 if (arg)
112 *expr = *arg;
113 return 0;
117 * __builtin_warning() has type "int" and always returns 1,
118 * so that you can use it in conditionals or whatever
120 static int expand_warning(struct expression *expr, int cost)
122 struct expression *arg;
123 struct expression_list *arglist = expr->args;
125 FOR_EACH_PTR (arglist, arg) {
127 * Constant strings get printed out as a warning. By the
128 * time we get here, the EXPR_STRING has been fully
129 * evaluated, so by now it's an anonymous symbol with a
130 * string initializer.
132 * Just for the heck of it, allow any constant string
133 * symbol.
135 if (arg->type == EXPR_SYMBOL) {
136 struct symbol *sym = arg->symbol;
137 if (sym->initializer && sym->initializer->type == EXPR_STRING) {
138 struct string *string = sym->initializer->string;
139 warning(expr->pos, "%*s", string->length-1, string->data);
141 continue;
145 * Any other argument is a conditional. If it's
146 * non-constant, or it is false, we exit and do
147 * not print any warning.
149 if (arg->type != EXPR_VALUE)
150 goto out;
151 if (!arg->value)
152 goto out;
153 } END_FOR_EACH_PTR(arg);
154 out:
155 expr->type = EXPR_VALUE;
156 expr->value = 1;
157 expr->taint = 0;
158 return 0;
161 /* The arguments are constant if the cost of all of them is zero */
162 static int expand_constant_p(struct expression *expr, int cost)
164 expr->type = EXPR_VALUE;
165 expr->value = !cost;
166 expr->taint = 0;
167 return 0;
170 /* The arguments are safe, if their cost is less than SIDE_EFFECTS */
171 static int expand_safe_p(struct expression *expr, int cost)
173 expr->type = EXPR_VALUE;
174 expr->value = (cost < SIDE_EFFECTS);
175 expr->taint = 0;
176 return 0;
179 static struct symbol_op constant_p_op = {
180 .evaluate = evaluate_to_int_const_expr,
181 .expand = expand_constant_p
184 static struct symbol_op safe_p_op = {
185 .evaluate = evaluate_to_int_const_expr,
186 .expand = expand_safe_p
189 static struct symbol_op warning_op = {
190 .evaluate = evaluate_to_int_const_expr,
191 .expand = expand_warning
194 static struct symbol_op expect_op = {
195 .expand = expand_expect
198 static struct symbol_op choose_op = {
199 .args = args_triadic,
200 .evaluate = evaluate_choose,
203 /* The argument is constant and valid if the cost is zero */
204 static int expand_bswap(struct expression *expr, int cost)
206 struct expression *arg;
207 long long val;
209 if (cost)
210 return cost;
212 /* the arguments number & type have already been checked */
213 arg = first_expression(expr->args);
214 val = get_expression_value_silent(arg);
215 switch (expr->ctype->bit_size) {
216 case 16: expr->value = bswap16(val); break;
217 case 32: expr->value = bswap32(val); break;
218 case 64: expr->value = bswap64(val); break;
219 default: /* impossible error */
220 return SIDE_EFFECTS;
223 expr->type = EXPR_VALUE;
224 expr->taint = 0;
225 return 0;
228 static struct symbol_op bswap_op = {
229 .evaluate = evaluate_pure_unop,
230 .expand = expand_bswap,
234 #define EXPAND_FINDBIT(name) \
235 static int expand_##name(struct expression *expr, int cost) \
237 struct expression *arg; \
238 long long val; \
240 if (cost) \
241 return cost; \
243 arg = first_expression(expr->args); \
244 val = get_expression_value_silent(arg); \
245 switch (arg->ctype->bit_size) { \
246 case sizeof(int) * 8: \
247 val = __builtin_##name(val); break; \
248 case sizeof(long long) * 8: \
249 val = __builtin_##name##ll(val); break; \
250 default: /* impossible error */ \
251 return SIDE_EFFECTS; \
254 expr->value = val; \
255 expr->type = EXPR_VALUE; \
256 expr->taint = 0; \
257 return 0; \
260 static struct symbol_op name##_op = { \
261 .evaluate = evaluate_pure_unop, \
262 .expand = expand_##name, \
265 EXPAND_FINDBIT(clz);
266 EXPAND_FINDBIT(ctz);
267 EXPAND_FINDBIT(clrsb);
268 EXPAND_FINDBIT(ffs);
269 EXPAND_FINDBIT(parity);
270 EXPAND_FINDBIT(popcount);
272 static int evaluate_fp_unop(struct expression *expr)
274 struct expression *arg;
276 if (!eval_args(expr, 1))
277 return 0;
279 arg = first_expression(expr->args);
280 if (!is_float_type(arg->ctype)) {
281 expression_error(expr, "non-floating-point argument in call to %s()",
282 show_ident(expr->fn->ctype->ident));
283 return 0;
285 return 1;
288 static struct symbol_op fp_unop_op = {
289 .evaluate = evaluate_fp_unop,
293 static int evaluate_overflow_gen(struct expression *expr, int ptr)
295 struct expression *arg;
296 int n = 0;
298 /* there will be exactly 3; we'd already verified that */
299 FOR_EACH_PTR(expr->args, arg) {
300 struct symbol *type;
302 n++;
303 if (!arg || !(type = arg->ctype))
304 return 0;
305 // 1st & 2nd args must be a basic integer type
306 // 3rd arg must be a pointer to such a type.
307 if (n == 3 && ptr) {
308 if (type->type == SYM_NODE)
309 type = type->ctype.base_type;
310 if (!type)
311 return 0;
312 if (type->type != SYM_PTR)
313 goto err;
314 type = type->ctype.base_type;
315 if (!type)
316 return 0;
318 if (type->type == SYM_NODE)
319 type = type->ctype.base_type;
320 if (!type)
321 return 0;
322 if (type->ctype.base_type != &int_type || type == &bool_ctype)
323 goto err;
324 } END_FOR_EACH_PTR(arg);
326 // the builtin returns a bool
327 expr->ctype = &bool_ctype;
328 return 1;
330 err:
331 sparse_error(arg->pos, "invalid type for argument %d:", n);
332 info(arg->pos, " %s", show_typename(arg->ctype));
333 expr->ctype = &bad_ctype;
334 return 0;
337 static int evaluate_overflow(struct expression *expr)
339 return evaluate_overflow_gen(expr, 1);
342 static struct symbol_op overflow_op = {
343 .args = args_triadic,
344 .evaluate = evaluate_overflow,
347 static int evaluate_overflow_p(struct expression *expr)
349 return evaluate_overflow_gen(expr, 0);
352 static struct symbol_op overflow_p_op = {
353 .args = args_triadic,
354 .evaluate = evaluate_overflow_p,
358 static int eval_sync_compare_and_swap(struct expression *expr)
360 struct symbol_list *types = NULL;
361 struct symbol *ctype = NULL;
362 struct expression *arg;
363 int n = 0;
365 /* the first arg is a pointer type; we'd already verified that */
366 FOR_EACH_PTR(expr->args, arg) {
367 struct symbol *t = arg->ctype;
369 if (!t)
370 return 0;
372 // 2nd & 3rd args must be a basic integer type or a pointer
373 // 1st arg must be a pointer to such a type.
374 if (++n == 1) {
375 if (t->type == SYM_NODE)
376 t = t->ctype.base_type;
377 if (!t)
378 return 0;
379 if (t->type != SYM_PTR)
380 goto err;
381 t = t->ctype.base_type;
382 if (!t)
383 return 0;
384 if (t->type == SYM_NODE)
385 t = t->ctype.base_type;
386 if (!t)
387 return 0;
388 if (t->type != SYM_PTR && t->ctype.base_type != &int_type)
389 goto err;
390 ctype = t;
391 add_ptr_list(&types, arg->ctype);
392 } else {
393 add_ptr_list(&types, ctype);
395 } END_FOR_EACH_PTR(arg);
397 if (!expr->ctype) // __sync_val_compare_and_swap()
398 expr->ctype = ctype;
399 return evaluate_arguments(types, expr->args);
401 err:
402 sparse_error(arg->pos, "invalid type for argument %d:", n);
403 info(arg->pos, " %s", show_typename(arg->ctype));
404 expr->ctype = &bad_ctype;
405 return 0;
408 static struct symbol_op sync_compare_and_swap_op = {
409 .args = args_triadic,
410 .evaluate = eval_sync_compare_and_swap,
415 * Builtin functions
417 static struct symbol size_t_alias;
419 static struct symbol *get_ctype(struct symbol *sym)
421 if (sym == &size_t_alias)
422 return size_t_ctype;
423 return sym;
426 static void declare_builtin(int stream, const struct builtin_fn *entry)
428 struct symbol *sym = create_symbol(stream, entry->name, SYM_NODE, NS_SYMBOL);
429 struct symbol *fun = alloc_symbol(sym->pos, SYM_FN);
430 struct symbol *arg;
431 int i;
433 sym->ctype.base_type = fun;
434 sym->ctype.modifiers = MOD_TOPLEVEL;
435 sym->builtin = 1;
436 sym->op = entry->op;
438 fun->ctype.base_type = get_ctype(entry->ret_type);
439 fun->variadic = entry->variadic;
441 for (i = 0; (arg = entry->args[i]); i++) {
442 struct symbol *anode = alloc_symbol(sym->pos, SYM_NODE);
443 anode->ctype.base_type = get_ctype(arg);
444 add_symbol(&fun->arguments, anode);
448 static void declare_builtins(int stream, const struct builtin_fn tbl[])
450 if (!tbl)
451 return;
453 while (tbl->name)
454 declare_builtin(stream, tbl++);
457 static const struct builtin_fn builtins_common[] = {
458 #define size_t_ctype &size_t_alias
459 #define va_list_ctype &ptr_ctype
460 { "__builtin_choose_expr", NULL, 1, .op = &choose_op },
461 { "__builtin_constant_p", NULL, 1, .op = &constant_p_op },
462 { "__builtin_expect", &long_ctype, 0, { &long_ctype ,&long_ctype }, .op = &expect_op },
463 { "__builtin_safe_p", NULL, 1, .op = &safe_p_op },
464 { "__builtin_warning", NULL, 1, .op = &warning_op },
466 { "__builtin_abort", &void_ctype, 0 },
467 { "__builtin_abs", &int_ctype , 0, { &int_ctype }},
468 { "__builtin_add_overflow", &bool_ctype, 1, .op = &overflow_op },
469 { "__builtin_add_overflow_p", &bool_ctype, 1, .op = &overflow_p_op },
470 { "__builtin_alloca", &ptr_ctype, 0, { size_t_ctype }},
471 { "__builtin_bcmp", &int_ctype , 0, { &const_ptr_ctype, &const_ptr_ctype, size_t_ctype }},
472 { "__builtin_bcopy", &void_ctype, 0, { &const_ptr_ctype, &ptr_ctype, size_t_ctype }},
473 { "__builtin_bswap16", &ushort_ctype, 0, { &ushort_ctype }, .op = &bswap_op },
474 { "__builtin_bswap32", &uint_ctype, 0, { &uint_ctype }, .op = &bswap_op },
475 { "__builtin_bswap64", &ullong_ctype, 0, { &ullong_ctype }, .op = &bswap_op },
476 { "__builtin_bzero", &void_ctype, 0, { &ptr_ctype, size_t_ctype }},
477 { "__builtin_calloc", &ptr_ctype, 0, { size_t_ctype, size_t_ctype }},
478 { "__builtin_clrsb", &int_ctype, 0, { &int_ctype }, .op = &clrsb_op },
479 { "__builtin_clrsbl", &int_ctype, 0, { &long_ctype }, .op = &clrsb_op },
480 { "__builtin_clrsbll", &int_ctype, 0, { &llong_ctype }, .op = &clrsb_op },
481 { "__builtin_clz", &int_ctype, 0, { &int_ctype }, .op = &clz_op },
482 { "__builtin_clzl", &int_ctype, 0, { &long_ctype }, .op = &clz_op },
483 { "__builtin_clzll", &int_ctype, 0, { &llong_ctype }, .op = &clz_op },
484 { "__builtin_ctz", &int_ctype, 0, { &int_ctype }, .op = &ctz_op },
485 { "__builtin_ctzl", &int_ctype, 0, { &long_ctype }, .op = &ctz_op },
486 { "__builtin_ctzll", &int_ctype, 0, { &llong_ctype }, .op = &ctz_op },
487 { "__builtin_exit", &void_ctype, 0, { &int_ctype }},
488 { "__builtin_extract_return_addr", &ptr_ctype, 0, { &ptr_ctype }},
489 { "__builtin_fabs", &double_ctype, 0, { &double_ctype }},
490 { "__builtin_ffs", &int_ctype, 0, { &int_ctype }, .op = &ffs_op },
491 { "__builtin_ffsl", &int_ctype, 0, { &long_ctype }, .op = &ffs_op },
492 { "__builtin_ffsll", &int_ctype, 0, { &llong_ctype }, .op = &ffs_op },
493 { "__builtin_frame_address", &ptr_ctype, 0, { &uint_ctype }},
494 { "__builtin_free", &void_ctype, 0, { &ptr_ctype }},
495 { "__builtin_huge_val", &double_ctype, 0 },
496 { "__builtin_huge_valf", &float_ctype, 0 },
497 { "__builtin_huge_vall", &ldouble_ctype, 0 },
498 { "__builtin_index", &string_ctype, 0, { &const_string_ctype, &int_ctype }},
499 { "__builtin_inf", &double_ctype, 0 },
500 { "__builtin_inff", &float_ctype, 0 },
501 { "__builtin_infl", &ldouble_ctype, 0 },
502 { "__builtin_isfinite", &int_ctype, 1, .op = &fp_unop_op },
503 { "__builtin_isgreater", &int_ctype, 0, { &float_ctype, &float_ctype }},
504 { "__builtin_isgreaterequal", &int_ctype, 0, { &float_ctype, &float_ctype }},
505 { "__builtin_isinf", &int_ctype, 1, .op = &fp_unop_op },
506 { "__builtin_isinf_sign", &int_ctype, 1, .op = &fp_unop_op },
507 { "__builtin_isless", &int_ctype, 0, { &float_ctype, &float_ctype }},
508 { "__builtin_islessequal", &int_ctype, 0, { &float_ctype, &float_ctype }},
509 { "__builtin_islessgreater", &int_ctype, 0, { &float_ctype, &float_ctype }},
510 { "__builtin_isnan", &int_ctype, 1, .op = &fp_unop_op },
511 { "__builtin_isnormal", &int_ctype, 1, .op = &fp_unop_op },
512 { "__builtin_isunordered", &int_ctype, 0, { &float_ctype, &float_ctype }},
513 { "__builtin_labs", &long_ctype, 0, { &long_ctype }},
514 { "__builtin_llabs", &llong_ctype, 0, { &llong_ctype }},
515 { "__builtin_malloc", &ptr_ctype, 0, { size_t_ctype }},
516 { "__builtin_memchr", &ptr_ctype, 0, { &const_ptr_ctype, &int_ctype, size_t_ctype }},
517 { "__builtin_memcmp", &int_ctype, 0, { &const_ptr_ctype, &const_ptr_ctype, size_t_ctype }},
518 { "__builtin_memcpy", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }},
519 { "__builtin_memmove", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }},
520 { "__builtin_mempcpy", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype }},
521 { "__builtin_memset", &ptr_ctype, 0, { &ptr_ctype, &int_ctype, size_t_ctype }},
522 { "__builtin_mul_overflow", &bool_ctype, 1, .op = &overflow_op },
523 { "__builtin_mul_overflow_p", &bool_ctype, 1, .op = &overflow_p_op },
524 { "__builtin_nan", &double_ctype, 0, { &const_string_ctype }},
525 { "__builtin_nanf", &float_ctype, 0, { &const_string_ctype }},
526 { "__builtin_nanl", &ldouble_ctype, 0, { &const_string_ctype }},
527 { "__builtin_object_size", size_t_ctype, 0, { &const_ptr_ctype, &int_ctype }},
528 { "__builtin_parity", &int_ctype, 0, { &uint_ctype }, .op = &parity_op },
529 { "__builtin_parityl", &int_ctype, 0, { &ulong_ctype }, .op = &parity_op },
530 { "__builtin_parityll", &int_ctype, 0, { &ullong_ctype }, .op = &parity_op },
531 { "__builtin_popcount", &int_ctype, 0, { &uint_ctype }, .op = &popcount_op },
532 { "__builtin_popcountl", &int_ctype, 0, { &ulong_ctype }, .op = &popcount_op },
533 { "__builtin_popcountll", &int_ctype, 0, { &ullong_ctype }, .op = &popcount_op },
534 { "__builtin_prefetch", &void_ctype, 1, { &const_ptr_ctype }},
535 { "__builtin_printf", &int_ctype, 1, { &const_string_ctype }},
536 { "__builtin_puts", &int_ctype, 0, { &const_string_ctype }},
537 { "__builtin_realloc", &ptr_ctype, 0, { &ptr_ctype, size_t_ctype }},
538 { "__builtin_return_address", &ptr_ctype, 0, { &uint_ctype }},
539 { "__builtin_rindex", &string_ctype, 0, { &const_string_ctype, &int_ctype }},
540 { "__builtin_sadd_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }},
541 { "__builtin_saddl_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }},
542 { "__builtin_saddll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }},
543 { "__builtin_signbit", &int_ctype, 1 , .op = &fp_unop_op },
544 { "__builtin_smul_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }},
545 { "__builtin_smull_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }},
546 { "__builtin_smulll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }},
547 { "__builtin_snprintf", &int_ctype, 1, { &string_ctype, size_t_ctype, &const_string_ctype }},
548 { "__builtin_sprintf", &int_ctype, 1, { &string_ctype, &const_string_ctype }},
549 { "__builtin_ssub_overflow", &bool_ctype, 0, { &int_ctype, &int_ctype, &int_ptr_ctype }},
550 { "__builtin_ssubl_overflow", &bool_ctype, 0, { &long_ctype, &long_ctype, &long_ptr_ctype }},
551 { "__builtin_ssubll_overflow", &bool_ctype, 0, { &llong_ctype, &llong_ctype, &llong_ptr_ctype }},
552 { "__builtin_stpcpy", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }},
553 { "__builtin_stpncpy", &string_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }},
554 { "__builtin_strcasecmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype }},
555 { "__builtin_strcasestr", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }},
556 { "__builtin_strcat", &string_ctype, 0, { &string_ctype, &const_string_ctype }},
557 { "__builtin_strchr", &string_ctype, 0, { &const_string_ctype, &int_ctype }},
558 { "__builtin_strcmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype }},
559 { "__builtin_strcpy", &string_ctype, 0, { &string_ctype, &const_string_ctype }},
560 { "__builtin_strcspn", size_t_ctype, 0, { &const_string_ctype, &const_string_ctype }},
561 { "__builtin_strdup", &string_ctype, 0, { &const_string_ctype }},
562 { "__builtin_strlen", size_t_ctype, 0, { &const_string_ctype }},
563 { "__builtin_strncasecmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }},
564 { "__builtin_strncat", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }},
565 { "__builtin_strncmp", &int_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }},
566 { "__builtin_strncpy", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }},
567 { "__builtin_strndup", &string_ctype, 0, { &const_string_ctype, size_t_ctype }},
568 { "__builtin_strnstr", &string_ctype, 0, { &const_string_ctype, &const_string_ctype, size_t_ctype }},
569 { "__builtin_strpbrk", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }},
570 { "__builtin_strrchr", &string_ctype, 0, { &const_string_ctype, &int_ctype }},
571 { "__builtin_strspn", size_t_ctype, 0, { &const_string_ctype, &const_string_ctype }},
572 { "__builtin_strstr", &string_ctype, 0, { &const_string_ctype, &const_string_ctype }},
573 { "__builtin_sub_overflow", &bool_ctype, 1, .op = &overflow_op },
574 { "__builtin_sub_overflow_p", &bool_ctype, 1, .op = &overflow_p_op },
575 { "__builtin_trap", &void_ctype, 0 },
576 { "__builtin_uadd_overflow", &bool_ctype, 0, { &uint_ctype, &uint_ctype, &uint_ptr_ctype }},
577 { "__builtin_uaddl_overflow", &bool_ctype, 0, { &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype }},
578 { "__builtin_uaddll_overflow", &bool_ctype, 0, { &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype }},
579 { "__builtin_umul_overflow", &bool_ctype, 0, { &uint_ctype, &uint_ctype, &uint_ptr_ctype }},
580 { "__builtin_umull_overflow", &bool_ctype, 0, { &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype }},
581 { "__builtin_umulll_overflow", &bool_ctype, 0, { &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype }},
582 { "__builtin_unreachable", &void_ctype, 0 },
583 { "__builtin_usub_overflow", &bool_ctype, 0, { &uint_ctype, &uint_ctype, &uint_ptr_ctype }},
584 { "__builtin_usubl_overflow", &bool_ctype, 0, { &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype }},
585 { "__builtin_usubll_overflow", &bool_ctype, 0, { &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype }},
586 { "__builtin_va_arg_pack_len", size_t_ctype, 0 },
587 { "__builtin_vprintf", &int_ctype, 0, { &const_string_ctype, va_list_ctype }},
588 { "__builtin_vsnprintf", &int_ctype, 0, { &string_ctype, size_t_ctype, &const_string_ctype, va_list_ctype }},
589 { "__builtin_vsprintf", &int_ctype, 0, { &string_ctype, &const_string_ctype, va_list_ctype }},
591 { "__builtin___memcpy_chk", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype }},
592 { "__builtin___memmove_chk", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype }},
593 { "__builtin___mempcpy_chk", &ptr_ctype, 0, { &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype }},
594 { "__builtin___memset_chk", &ptr_ctype, 0, { &ptr_ctype, &int_ctype, size_t_ctype, size_t_ctype }},
595 { "__builtin___snprintf_chk", &int_ctype, 1, { &string_ctype, size_t_ctype, &int_ctype , size_t_ctype, &const_string_ctype }},
596 { "__builtin___sprintf_chk", &int_ctype, 1, { &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype }},
597 { "__builtin___stpcpy_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }},
598 { "__builtin___strcat_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }},
599 { "__builtin___strcpy_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype }},
600 { "__builtin___strncat_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype }},
601 { "__builtin___strncpy_chk", &string_ctype, 0, { &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype }},
602 { "__builtin___vsnprintf_chk", &int_ctype, 0, { &string_ctype, size_t_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype }},
603 { "__builtin___vsprintf_chk", &int_ctype, 0, { &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype }},
605 { "__sync_add_and_fetch", &int_ctype, 1, { &ptr_ctype }},
606 { "__sync_and_and_fetch", &int_ctype, 1, { &ptr_ctype }},
607 { "__sync_bool_compare_and_swap", &bool_ctype, 1, { &ptr_ctype }, .op = &sync_compare_and_swap_op},
608 { "__sync_fetch_and_add", &int_ctype, 1, { &ptr_ctype }},
609 { "__sync_fetch_and_and", &int_ctype, 1, { &ptr_ctype }},
610 { "__sync_fetch_and_nand", &int_ctype, 1, { &ptr_ctype }},
611 { "__sync_fetch_and_or", &int_ctype, 1, { &ptr_ctype }},
612 { "__sync_fetch_and_sub", &int_ctype, 1, { &ptr_ctype }},
613 { "__sync_fetch_and_xor", &int_ctype, 1, { &ptr_ctype }},
614 { "__sync_lock_release", &void_ctype, 1, { &ptr_ctype }},
615 { "__sync_lock_test_and_set", &int_ctype, 1, { &ptr_ctype }},
616 { "__sync_nand_and_fetch", &int_ctype, 1, { &ptr_ctype }},
617 { "__sync_or_and_fetch", &int_ctype, 1, { &ptr_ctype }},
618 { "__sync_sub_and_fetch", &int_ctype, 1, { &ptr_ctype }},
619 { "__sync_synchronize", &void_ctype, 0 },
620 { "__sync_val_compare_and_swap", NULL, 1, { &ptr_ctype }, .op = &sync_compare_and_swap_op },
621 { "__sync_xor_and_fetch", &int_ctype, 1, { &ptr_ctype }},
626 void init_builtins(int stream)
628 declare_builtins(stream, builtins_common);
629 declare_builtins(stream, arch_target->builtins);
630 init_linearized_builtins(stream);