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
27 #include "expression.h"
31 #include "compat/bswap.h"
34 static int evaluate_to_int_const_expr(struct expression
*expr
)
36 expr
->ctype
= &int_ctype
;
37 expr
->flags
|= CEF_SET_ICE
;
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;
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
;
66 FOR_EACH_PTR(expr
->args
, arg
) {
68 msg
= "too many arguments";
71 if (!evaluate_expression(arg
))
73 } END_FOR_EACH_PTR(arg
);
75 msg
= "not enough arguments";
81 sym
= expr
->fn
->ctype
;
82 expression_error(expr
, "%s for %s", msg
, show_ident(sym
->ident
));
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];
97 /* there will be exactly 3; we'd already verified that */
98 FOR_EACH_PTR(list
, arg
) {
100 } END_FOR_EACH_PTR(arg
);
102 *expr
= get_expression_value(args
[0]) ? *args
[1] : *args
[2];
107 static int expand_expect(struct expression
*expr
, int cost
)
109 struct expression
*arg
= first_ptr_list((struct ptr_list
*) expr
->args
);
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
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
);
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
)
153 } END_FOR_EACH_PTR(arg
);
155 expr
->type
= EXPR_VALUE
;
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
;
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
);
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
;
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 */
223 expr
->type
= EXPR_VALUE
;
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; \
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; \
255 expr->type = EXPR_VALUE; \
260 static struct symbol_op name##_op = { \
261 .evaluate = evaluate_pure_unop, \
262 .expand = expand_##name, \
267 EXPAND_FINDBIT(clrsb
);
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))
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
));
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
;
298 /* there will be exactly 3; we'd already verified that */
299 FOR_EACH_PTR(expr
->args
, arg
) {
303 if (!arg
|| !(type
= arg
->ctype
))
305 // 1st & 2nd args must be a basic integer type
306 // 3rd arg must be a pointer to such a type.
308 if (type
->type
== SYM_NODE
)
309 type
= type
->ctype
.base_type
;
312 if (type
->type
!= SYM_PTR
)
314 type
= type
->ctype
.base_type
;
318 if (type
->type
== SYM_NODE
)
319 type
= type
->ctype
.base_type
;
322 if (type
->ctype
.base_type
!= &int_type
|| type
== &bool_ctype
)
324 } END_FOR_EACH_PTR(arg
);
326 // the builtin returns a bool
327 expr
->ctype
= &bool_ctype
;
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
;
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
,
361 static struct symbol size_t_alias
;
363 static struct symbol
*get_ctype(struct symbol
*sym
)
365 if (sym
== &size_t_alias
)
370 static void declare_builtin(int stream
, const struct builtin_fn
*entry
)
372 struct symbol
*sym
= create_symbol(stream
, entry
->name
, SYM_NODE
, NS_SYMBOL
);
373 struct symbol
*fun
= alloc_symbol(sym
->pos
, SYM_FN
);
377 sym
->ctype
.base_type
= fun
;
378 sym
->ctype
.modifiers
= MOD_TOPLEVEL
;
382 fun
->ctype
.base_type
= get_ctype(entry
->ret_type
);
383 fun
->variadic
= entry
->variadic
;
385 for (i
= 0; (arg
= entry
->args
[i
]); i
++) {
386 struct symbol
*anode
= alloc_symbol(sym
->pos
, SYM_NODE
);
387 anode
->ctype
.base_type
= get_ctype(arg
);
388 add_symbol(&fun
->arguments
, anode
);
392 static void declare_builtins(int stream
, const struct builtin_fn tbl
[])
398 declare_builtin(stream
, tbl
++);
401 static const struct builtin_fn builtins_common
[] = {
402 #define size_t_ctype &size_t_alias
403 #define va_list_ctype &ptr_ctype
404 { "__builtin_choose_expr", NULL
, 1, .op
= &choose_op
},
405 { "__builtin_constant_p", NULL
, 1, .op
= &constant_p_op
},
406 { "__builtin_expect", &long_ctype
, 0, { &long_ctype
,&long_ctype
}, .op
= &expect_op
},
407 { "__builtin_safe_p", NULL
, 1, .op
= &safe_p_op
},
408 { "__builtin_warning", NULL
, 1, .op
= &warning_op
},
410 { "__builtin_abort", &void_ctype
, 0 },
411 { "__builtin_abs", &int_ctype
, 0, { &int_ctype
}},
412 { "__builtin_add_overflow", &bool_ctype
, 1, .op
= &overflow_op
},
413 { "__builtin_add_overflow_p", &bool_ctype
, 1, .op
= &overflow_p_op
},
414 { "__builtin_alloca", &ptr_ctype
, 0, { size_t_ctype
}},
415 { "__builtin_bcmp", &int_ctype
, 0, { &const_ptr_ctype
, &const_ptr_ctype
, size_t_ctype
}},
416 { "__builtin_bcopy", &void_ctype
, 0, { &const_ptr_ctype
, &ptr_ctype
, size_t_ctype
}},
417 { "__builtin_bswap16", &ushort_ctype
, 0, { &ushort_ctype
}, .op
= &bswap_op
},
418 { "__builtin_bswap32", &uint_ctype
, 0, { &uint_ctype
}, .op
= &bswap_op
},
419 { "__builtin_bswap64", &ullong_ctype
, 0, { &ullong_ctype
}, .op
= &bswap_op
},
420 { "__builtin_bzero", &void_ctype
, 0, { &ptr_ctype
, size_t_ctype
}},
421 { "__builtin_calloc", &ptr_ctype
, 0, { size_t_ctype
, size_t_ctype
}},
422 { "__builtin_clrsb", &int_ctype
, 0, { &int_ctype
}, .op
= &clrsb_op
},
423 { "__builtin_clrsbl", &int_ctype
, 0, { &long_ctype
}, .op
= &clrsb_op
},
424 { "__builtin_clrsbll", &int_ctype
, 0, { &llong_ctype
}, .op
= &clrsb_op
},
425 { "__builtin_clz", &int_ctype
, 0, { &int_ctype
}, .op
= &clz_op
},
426 { "__builtin_clzl", &int_ctype
, 0, { &long_ctype
}, .op
= &clz_op
},
427 { "__builtin_clzll", &int_ctype
, 0, { &llong_ctype
}, .op
= &clz_op
},
428 { "__builtin_ctz", &int_ctype
, 0, { &int_ctype
}, .op
= &ctz_op
},
429 { "__builtin_ctzl", &int_ctype
, 0, { &long_ctype
}, .op
= &ctz_op
},
430 { "__builtin_ctzll", &int_ctype
, 0, { &llong_ctype
}, .op
= &ctz_op
},
431 { "__builtin_exit", &void_ctype
, 0, { &int_ctype
}},
432 { "__builtin_extract_return_addr", &ptr_ctype
, 0, { &ptr_ctype
}},
433 { "__builtin_fabs", &double_ctype
, 0, { &double_ctype
}},
434 { "__builtin_ffs", &int_ctype
, 0, { &int_ctype
}, .op
= &ffs_op
},
435 { "__builtin_ffsl", &int_ctype
, 0, { &long_ctype
}, .op
= &ffs_op
},
436 { "__builtin_ffsll", &int_ctype
, 0, { &llong_ctype
}, .op
= &ffs_op
},
437 { "__builtin_frame_address", &ptr_ctype
, 0, { &uint_ctype
}},
438 { "__builtin_free", &void_ctype
, 0, { &ptr_ctype
}},
439 { "__builtin_huge_val", &double_ctype
, 0 },
440 { "__builtin_huge_valf", &float_ctype
, 0 },
441 { "__builtin_huge_vall", &ldouble_ctype
, 0 },
442 { "__builtin_index", &string_ctype
, 0, { &const_string_ctype
, &int_ctype
}},
443 { "__builtin_inf", &double_ctype
, 0 },
444 { "__builtin_inff", &float_ctype
, 0 },
445 { "__builtin_infl", &ldouble_ctype
, 0 },
446 { "__builtin_isfinite", &int_ctype
, 1, .op
= &fp_unop_op
},
447 { "__builtin_isgreater", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
448 { "__builtin_isgreaterequal", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
449 { "__builtin_isinf", &int_ctype
, 1, .op
= &fp_unop_op
},
450 { "__builtin_isinf_sign", &int_ctype
, 1, .op
= &fp_unop_op
},
451 { "__builtin_isless", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
452 { "__builtin_islessequal", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
453 { "__builtin_islessgreater", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
454 { "__builtin_isnan", &int_ctype
, 1, .op
= &fp_unop_op
},
455 { "__builtin_isnormal", &int_ctype
, 1, .op
= &fp_unop_op
},
456 { "__builtin_isunordered", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
457 { "__builtin_labs", &long_ctype
, 0, { &long_ctype
}},
458 { "__builtin_llabs", &llong_ctype
, 0, { &llong_ctype
}},
459 { "__builtin_malloc", &ptr_ctype
, 0, { size_t_ctype
}},
460 { "__builtin_memchr", &ptr_ctype
, 0, { &const_ptr_ctype
, &int_ctype
, size_t_ctype
}},
461 { "__builtin_memcmp", &int_ctype
, 0, { &const_ptr_ctype
, &const_ptr_ctype
, size_t_ctype
}},
462 { "__builtin_memcpy", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
}},
463 { "__builtin_memmove", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
}},
464 { "__builtin_mempcpy", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
}},
465 { "__builtin_memset", &ptr_ctype
, 0, { &ptr_ctype
, &int_ctype
, size_t_ctype
}},
466 { "__builtin_mul_overflow", &bool_ctype
, 1, .op
= &overflow_op
},
467 { "__builtin_mul_overflow_p", &bool_ctype
, 1, .op
= &overflow_p_op
},
468 { "__builtin_nan", &double_ctype
, 0, { &const_string_ctype
}},
469 { "__builtin_nanf", &float_ctype
, 0, { &const_string_ctype
}},
470 { "__builtin_nanl", &ldouble_ctype
, 0, { &const_string_ctype
}},
471 { "__builtin_object_size", size_t_ctype
, 0, { &const_ptr_ctype
, &int_ctype
}},
472 { "__builtin_parity", &int_ctype
, 0, { &uint_ctype
}, .op
= &parity_op
},
473 { "__builtin_parityl", &int_ctype
, 0, { &ulong_ctype
}, .op
= &parity_op
},
474 { "__builtin_parityll", &int_ctype
, 0, { &ullong_ctype
}, .op
= &parity_op
},
475 { "__builtin_popcount", &int_ctype
, 0, { &uint_ctype
}, .op
= &popcount_op
},
476 { "__builtin_popcountl", &int_ctype
, 0, { &ulong_ctype
}, .op
= &popcount_op
},
477 { "__builtin_popcountll", &int_ctype
, 0, { &ullong_ctype
}, .op
= &popcount_op
},
478 { "__builtin_prefetch", &void_ctype
, 1, { &const_ptr_ctype
}},
479 { "__builtin_printf", &int_ctype
, 1, { &const_string_ctype
}},
480 { "__builtin_puts", &int_ctype
, 0, { &const_string_ctype
}},
481 { "__builtin_realloc", &ptr_ctype
, 0, { &ptr_ctype
, size_t_ctype
}},
482 { "__builtin_return_address", &ptr_ctype
, 0, { &uint_ctype
}},
483 { "__builtin_rindex", &string_ctype
, 0, { &const_string_ctype
, &int_ctype
}},
484 { "__builtin_sadd_overflow", &bool_ctype
, 0, { &int_ctype
, &int_ctype
, &int_ptr_ctype
}},
485 { "__builtin_saddl_overflow", &bool_ctype
, 0, { &long_ctype
, &long_ctype
, &long_ptr_ctype
}},
486 { "__builtin_saddll_overflow", &bool_ctype
, 0, { &llong_ctype
, &llong_ctype
, &llong_ptr_ctype
}},
487 { "__builtin_signbit", &int_ctype
, 1 , .op
= &fp_unop_op
},
488 { "__builtin_smul_overflow", &bool_ctype
, 0, { &int_ctype
, &int_ctype
, &int_ptr_ctype
}},
489 { "__builtin_smull_overflow", &bool_ctype
, 0, { &long_ctype
, &long_ctype
, &long_ptr_ctype
}},
490 { "__builtin_smulll_overflow", &bool_ctype
, 0, { &llong_ctype
, &llong_ctype
, &llong_ptr_ctype
}},
491 { "__builtin_snprintf", &int_ctype
, 1, { &string_ctype
, size_t_ctype
, &const_string_ctype
}},
492 { "__builtin_sprintf", &int_ctype
, 1, { &string_ctype
, &const_string_ctype
}},
493 { "__builtin_ssub_overflow", &bool_ctype
, 0, { &int_ctype
, &int_ctype
, &int_ptr_ctype
}},
494 { "__builtin_ssubl_overflow", &bool_ctype
, 0, { &long_ctype
, &long_ctype
, &long_ptr_ctype
}},
495 { "__builtin_ssubll_overflow", &bool_ctype
, 0, { &llong_ctype
, &llong_ctype
, &llong_ptr_ctype
}},
496 { "__builtin_stpcpy", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
497 { "__builtin_stpncpy", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
, size_t_ctype
}},
498 { "__builtin_strcasecmp", &int_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
499 { "__builtin_strcasestr", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
500 { "__builtin_strcat", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
}},
501 { "__builtin_strchr", &string_ctype
, 0, { &const_string_ctype
, &int_ctype
}},
502 { "__builtin_strcmp", &int_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
503 { "__builtin_strcpy", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
}},
504 { "__builtin_strcspn", size_t_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
505 { "__builtin_strdup", &string_ctype
, 0, { &const_string_ctype
}},
506 { "__builtin_strlen", size_t_ctype
, 0, { &const_string_ctype
}},
507 { "__builtin_strncasecmp", &int_ctype
, 0, { &const_string_ctype
, &const_string_ctype
, size_t_ctype
}},
508 { "__builtin_strncat", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
}},
509 { "__builtin_strncmp", &int_ctype
, 0, { &const_string_ctype
, &const_string_ctype
, size_t_ctype
}},
510 { "__builtin_strncpy", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
}},
511 { "__builtin_strndup", &string_ctype
, 0, { &const_string_ctype
, size_t_ctype
}},
512 { "__builtin_strnstr", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
, size_t_ctype
}},
513 { "__builtin_strpbrk", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
514 { "__builtin_strrchr", &string_ctype
, 0, { &const_string_ctype
, &int_ctype
}},
515 { "__builtin_strspn", size_t_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
516 { "__builtin_strstr", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
517 { "__builtin_sub_overflow", &bool_ctype
, 1, .op
= &overflow_op
},
518 { "__builtin_sub_overflow_p", &bool_ctype
, 1, .op
= &overflow_p_op
},
519 { "__builtin_trap", &void_ctype
, 0 },
520 { "__builtin_uadd_overflow", &bool_ctype
, 0, { &uint_ctype
, &uint_ctype
, &uint_ptr_ctype
}},
521 { "__builtin_uaddl_overflow", &bool_ctype
, 0, { &ulong_ctype
, &ulong_ctype
, &ulong_ptr_ctype
}},
522 { "__builtin_uaddll_overflow", &bool_ctype
, 0, { &ullong_ctype
, &ullong_ctype
, &ullong_ptr_ctype
}},
523 { "__builtin_umul_overflow", &bool_ctype
, 0, { &uint_ctype
, &uint_ctype
, &uint_ptr_ctype
}},
524 { "__builtin_umull_overflow", &bool_ctype
, 0, { &ulong_ctype
, &ulong_ctype
, &ulong_ptr_ctype
}},
525 { "__builtin_umulll_overflow", &bool_ctype
, 0, { &ullong_ctype
, &ullong_ctype
, &ullong_ptr_ctype
}},
526 { "__builtin_unreachable", &void_ctype
, 0 },
527 { "__builtin_usub_overflow", &bool_ctype
, 0, { &uint_ctype
, &uint_ctype
, &uint_ptr_ctype
}},
528 { "__builtin_usubl_overflow", &bool_ctype
, 0, { &ulong_ctype
, &ulong_ctype
, &ulong_ptr_ctype
}},
529 { "__builtin_usubll_overflow", &bool_ctype
, 0, { &ullong_ctype
, &ullong_ctype
, &ullong_ptr_ctype
}},
530 { "__builtin_va_arg_pack_len", size_t_ctype
, 0 },
531 { "__builtin_vprintf", &int_ctype
, 0, { &const_string_ctype
, va_list_ctype
}},
532 { "__builtin_vsnprintf", &int_ctype
, 0, { &string_ctype
, size_t_ctype
, &const_string_ctype
, va_list_ctype
}},
533 { "__builtin_vsprintf", &int_ctype
, 0, { &string_ctype
, &const_string_ctype
, va_list_ctype
}},
535 { "__builtin___memcpy_chk", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
, size_t_ctype
}},
536 { "__builtin___memmove_chk", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
, size_t_ctype
}},
537 { "__builtin___mempcpy_chk", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
, size_t_ctype
}},
538 { "__builtin___memset_chk", &ptr_ctype
, 0, { &ptr_ctype
, &int_ctype
, size_t_ctype
, size_t_ctype
}},
539 { "__builtin___snprintf_chk", &int_ctype
, 1, { &string_ctype
, size_t_ctype
, &int_ctype
, size_t_ctype
, &const_string_ctype
}},
540 { "__builtin___sprintf_chk", &int_ctype
, 1, { &string_ctype
, &int_ctype
, size_t_ctype
, &const_string_ctype
}},
541 { "__builtin___stpcpy_chk", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
}},
542 { "__builtin___strcat_chk", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
}},
543 { "__builtin___strcpy_chk", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
}},
544 { "__builtin___strncat_chk", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
, size_t_ctype
}},
545 { "__builtin___strncpy_chk", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
, size_t_ctype
}},
546 { "__builtin___vsnprintf_chk", &int_ctype
, 0, { &string_ctype
, size_t_ctype
, &int_ctype
, size_t_ctype
, &const_string_ctype
, va_list_ctype
}},
547 { "__builtin___vsprintf_chk", &int_ctype
, 0, { &string_ctype
, &int_ctype
, size_t_ctype
, &const_string_ctype
, va_list_ctype
}},
549 { "__sync_add_and_fetch", &int_ctype
, 1, { &ptr_ctype
}},
550 { "__sync_and_and_fetch", &int_ctype
, 1, { &ptr_ctype
}},
551 { "__sync_bool_compare_and_swap", &int_ctype
, 1, { &ptr_ctype
}},
552 { "__sync_fetch_and_add", &int_ctype
, 1, { &ptr_ctype
}},
553 { "__sync_fetch_and_and", &int_ctype
, 1, { &ptr_ctype
}},
554 { "__sync_fetch_and_nand", &int_ctype
, 1, { &ptr_ctype
}},
555 { "__sync_fetch_and_or", &int_ctype
, 1, { &ptr_ctype
}},
556 { "__sync_fetch_and_sub", &int_ctype
, 1, { &ptr_ctype
}},
557 { "__sync_fetch_and_xor", &int_ctype
, 1, { &ptr_ctype
}},
558 { "__sync_lock_release", &void_ctype
, 1, { &ptr_ctype
}},
559 { "__sync_lock_test_and_set", &int_ctype
, 1, { &ptr_ctype
}},
560 { "__sync_nand_and_fetch", &int_ctype
, 1, { &ptr_ctype
}},
561 { "__sync_or_and_fetch", &int_ctype
, 1, { &ptr_ctype
}},
562 { "__sync_sub_and_fetch", &int_ctype
, 1, { &ptr_ctype
}},
563 { "__sync_synchronize", &void_ctype
, 0 },
564 { "__sync_val_compare_and_swap", &int_ctype
, 1, { &ptr_ctype
}},
565 { "__sync_xor_and_fetch", &int_ctype
, 1, { &ptr_ctype
}},
570 void init_builtins(int stream
)
572 declare_builtins(stream
, builtins_common
);
573 declare_builtins(stream
, arch_target
->builtins
);
574 init_linearized_builtins(stream
);