11f5207b7SJohn Levon /*
21f5207b7SJohn Levon * builtin evaluation & expansion.
31f5207b7SJohn Levon *
41f5207b7SJohn Levon * Copyright (C) 2003 Transmeta Corp.
51f5207b7SJohn Levon * 2003-2004 Linus Torvalds
61f5207b7SJohn Levon *
71f5207b7SJohn Levon * Permission is hereby granted, free of charge, to any person obtaining a copy
81f5207b7SJohn Levon * of this software and associated documentation files (the "Software"), to deal
91f5207b7SJohn Levon * in the Software without restriction, including without limitation the rights
101f5207b7SJohn Levon * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
111f5207b7SJohn Levon * copies of the Software, and to permit persons to whom the Software is
121f5207b7SJohn Levon * furnished to do so, subject to the following conditions:
131f5207b7SJohn Levon *
141f5207b7SJohn Levon * The above copyright notice and this permission notice shall be included in
151f5207b7SJohn Levon * all copies or substantial portions of the Software.
161f5207b7SJohn Levon *
171f5207b7SJohn Levon * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
181f5207b7SJohn Levon * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
191f5207b7SJohn Levon * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
201f5207b7SJohn Levon * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
211f5207b7SJohn Levon * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
221f5207b7SJohn Levon * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
231f5207b7SJohn Levon * THE SOFTWARE.
241f5207b7SJohn Levon */
251f5207b7SJohn Levon
261f5207b7SJohn Levon #include "expression.h"
27*c85f09ccSJohn Levon #include "evaluate.h"
281f5207b7SJohn Levon #include "expand.h"
291f5207b7SJohn Levon #include "symbol.h"
301f5207b7SJohn Levon #include "compat/bswap.h"
31*c85f09ccSJohn Levon #include <stdarg.h>
321f5207b7SJohn Levon
evaluate_to_int_const_expr(struct expression * expr)331f5207b7SJohn Levon static int evaluate_to_int_const_expr(struct expression *expr)
341f5207b7SJohn Levon {
351f5207b7SJohn Levon expr->ctype = &int_ctype;
361f5207b7SJohn Levon expr->flags |= CEF_SET_ICE;
371f5207b7SJohn Levon return 1;
381f5207b7SJohn Levon }
391f5207b7SJohn Levon
evaluate_pure_unop(struct expression * expr)401f5207b7SJohn Levon static int evaluate_pure_unop(struct expression *expr)
411f5207b7SJohn Levon {
421f5207b7SJohn Levon struct expression *arg = first_expression(expr->args);
431f5207b7SJohn Levon int flags = arg->flags;
441f5207b7SJohn Levon
451f5207b7SJohn Levon /*
461f5207b7SJohn Levon * Allow such functions with a constant integer expression
471f5207b7SJohn Levon * argument to be treated as a *constant* integer.
481f5207b7SJohn Levon * This allow us to use them in switch() { case ...:
491f5207b7SJohn Levon */
501f5207b7SJohn Levon flags |= (flags & CEF_ICE) ? CEF_SET_INT : 0;
511f5207b7SJohn Levon expr->flags = flags;
521f5207b7SJohn Levon return 1;
531f5207b7SJohn Levon }
541f5207b7SJohn Levon
55*c85f09ccSJohn Levon /*
56*c85f09ccSJohn Levon * eval_args - check the number of arguments and evaluate them.
57*c85f09ccSJohn Levon */
eval_args(struct expression * expr,int n)58*c85f09ccSJohn Levon static int eval_args(struct expression *expr, int n)
591f5207b7SJohn Levon {
601f5207b7SJohn Levon struct expression *arg;
61*c85f09ccSJohn Levon struct symbol *sym;
62*c85f09ccSJohn Levon const char *msg;
63*c85f09ccSJohn Levon int rc = 1;
641f5207b7SJohn Levon
65*c85f09ccSJohn Levon FOR_EACH_PTR(expr->args, arg) {
66*c85f09ccSJohn Levon if (n-- == 0) {
67*c85f09ccSJohn Levon msg = "too many arguments";
68*c85f09ccSJohn Levon goto error;
69*c85f09ccSJohn Levon }
701f5207b7SJohn Levon if (!evaluate_expression(arg))
71*c85f09ccSJohn Levon rc = 0;
721f5207b7SJohn Levon } END_FOR_EACH_PTR(arg);
73*c85f09ccSJohn Levon if (n > 0) {
74*c85f09ccSJohn Levon msg = "not enough arguments";
75*c85f09ccSJohn Levon goto error;
76*c85f09ccSJohn Levon }
77*c85f09ccSJohn Levon return rc;
78*c85f09ccSJohn Levon
79*c85f09ccSJohn Levon error:
80*c85f09ccSJohn Levon sym = expr->fn->ctype;
81*c85f09ccSJohn Levon expression_error(expr, "%s for %s", msg, show_ident(sym->ident));
821f5207b7SJohn Levon return 0;
831f5207b7SJohn Levon }
84*c85f09ccSJohn Levon
args_triadic(struct expression * expr)85*c85f09ccSJohn Levon static int args_triadic(struct expression *expr)
86*c85f09ccSJohn Levon {
87*c85f09ccSJohn Levon return eval_args(expr, 3);
881f5207b7SJohn Levon }
891f5207b7SJohn Levon
evaluate_choose(struct expression * expr)901f5207b7SJohn Levon static int evaluate_choose(struct expression *expr)
911f5207b7SJohn Levon {
921f5207b7SJohn Levon struct expression_list *list = expr->args;
931f5207b7SJohn Levon struct expression *arg, *args[3];
941f5207b7SJohn Levon int n = 0;
951f5207b7SJohn Levon
961f5207b7SJohn Levon /* there will be exactly 3; we'd already verified that */
971f5207b7SJohn Levon FOR_EACH_PTR(list, arg) {
981f5207b7SJohn Levon args[n++] = arg;
991f5207b7SJohn Levon } END_FOR_EACH_PTR(arg);
1001f5207b7SJohn Levon
1011f5207b7SJohn Levon *expr = get_expression_value(args[0]) ? *args[1] : *args[2];
1021f5207b7SJohn Levon
1031f5207b7SJohn Levon return 1;
1041f5207b7SJohn Levon }
1051f5207b7SJohn Levon
expand_expect(struct expression * expr,int cost)1061f5207b7SJohn Levon static int expand_expect(struct expression *expr, int cost)
1071f5207b7SJohn Levon {
1081f5207b7SJohn Levon struct expression *arg = first_ptr_list((struct ptr_list *) expr->args);
1091f5207b7SJohn Levon
1101f5207b7SJohn Levon if (arg)
1111f5207b7SJohn Levon *expr = *arg;
1121f5207b7SJohn Levon return 0;
1131f5207b7SJohn Levon }
1141f5207b7SJohn Levon
1151f5207b7SJohn Levon /*
1161f5207b7SJohn Levon * __builtin_warning() has type "int" and always returns 1,
1171f5207b7SJohn Levon * so that you can use it in conditionals or whatever
1181f5207b7SJohn Levon */
expand_warning(struct expression * expr,int cost)1191f5207b7SJohn Levon static int expand_warning(struct expression *expr, int cost)
1201f5207b7SJohn Levon {
1211f5207b7SJohn Levon struct expression *arg;
1221f5207b7SJohn Levon struct expression_list *arglist = expr->args;
1231f5207b7SJohn Levon
1241f5207b7SJohn Levon FOR_EACH_PTR (arglist, arg) {
1251f5207b7SJohn Levon /*
1261f5207b7SJohn Levon * Constant strings get printed out as a warning. By the
1271f5207b7SJohn Levon * time we get here, the EXPR_STRING has been fully
1281f5207b7SJohn Levon * evaluated, so by now it's an anonymous symbol with a
1291f5207b7SJohn Levon * string initializer.
1301f5207b7SJohn Levon *
1311f5207b7SJohn Levon * Just for the heck of it, allow any constant string
1321f5207b7SJohn Levon * symbol.
1331f5207b7SJohn Levon */
1341f5207b7SJohn Levon if (arg->type == EXPR_SYMBOL) {
1351f5207b7SJohn Levon struct symbol *sym = arg->symbol;
1361f5207b7SJohn Levon if (sym->initializer && sym->initializer->type == EXPR_STRING) {
1371f5207b7SJohn Levon struct string *string = sym->initializer->string;
1381f5207b7SJohn Levon warning(expr->pos, "%*s", string->length-1, string->data);
1391f5207b7SJohn Levon }
1401f5207b7SJohn Levon continue;
1411f5207b7SJohn Levon }
1421f5207b7SJohn Levon
1431f5207b7SJohn Levon /*
1441f5207b7SJohn Levon * Any other argument is a conditional. If it's
1451f5207b7SJohn Levon * non-constant, or it is false, we exit and do
1461f5207b7SJohn Levon * not print any warning.
1471f5207b7SJohn Levon */
1481f5207b7SJohn Levon if (arg->type != EXPR_VALUE)
1491f5207b7SJohn Levon goto out;
1501f5207b7SJohn Levon if (!arg->value)
1511f5207b7SJohn Levon goto out;
1521f5207b7SJohn Levon } END_FOR_EACH_PTR(arg);
1531f5207b7SJohn Levon out:
1541f5207b7SJohn Levon expr->type = EXPR_VALUE;
1551f5207b7SJohn Levon expr->value = 1;
1561f5207b7SJohn Levon expr->taint = 0;
1571f5207b7SJohn Levon return 0;
1581f5207b7SJohn Levon }
1591f5207b7SJohn Levon
1601f5207b7SJohn Levon /* The arguments are constant if the cost of all of them is zero */
expand_constant_p(struct expression * expr,int cost)1611f5207b7SJohn Levon static int expand_constant_p(struct expression *expr, int cost)
1621f5207b7SJohn Levon {
1631f5207b7SJohn Levon expr->type = EXPR_VALUE;
1641f5207b7SJohn Levon expr->value = !cost;
1651f5207b7SJohn Levon expr->taint = 0;
1661f5207b7SJohn Levon return 0;
1671f5207b7SJohn Levon }
1681f5207b7SJohn Levon
1691f5207b7SJohn Levon /* The arguments are safe, if their cost is less than SIDE_EFFECTS */
expand_safe_p(struct expression * expr,int cost)1701f5207b7SJohn Levon static int expand_safe_p(struct expression *expr, int cost)
1711f5207b7SJohn Levon {
1721f5207b7SJohn Levon expr->type = EXPR_VALUE;
1731f5207b7SJohn Levon expr->value = (cost < SIDE_EFFECTS);
1741f5207b7SJohn Levon expr->taint = 0;
1751f5207b7SJohn Levon return 0;
1761f5207b7SJohn Levon }
1771f5207b7SJohn Levon
1781f5207b7SJohn Levon static struct symbol_op constant_p_op = {
1791f5207b7SJohn Levon .evaluate = evaluate_to_int_const_expr,
1801f5207b7SJohn Levon .expand = expand_constant_p
1811f5207b7SJohn Levon };
1821f5207b7SJohn Levon
1831f5207b7SJohn Levon static struct symbol_op safe_p_op = {
1841f5207b7SJohn Levon .evaluate = evaluate_to_int_const_expr,
1851f5207b7SJohn Levon .expand = expand_safe_p
1861f5207b7SJohn Levon };
1871f5207b7SJohn Levon
1881f5207b7SJohn Levon static struct symbol_op warning_op = {
1891f5207b7SJohn Levon .evaluate = evaluate_to_int_const_expr,
1901f5207b7SJohn Levon .expand = expand_warning
1911f5207b7SJohn Levon };
1921f5207b7SJohn Levon
1931f5207b7SJohn Levon static struct symbol_op expect_op = {
1941f5207b7SJohn Levon .expand = expand_expect
1951f5207b7SJohn Levon };
1961f5207b7SJohn Levon
1971f5207b7SJohn Levon static struct symbol_op choose_op = {
198*c85f09ccSJohn Levon .args = args_triadic,
1991f5207b7SJohn Levon .evaluate = evaluate_choose,
2001f5207b7SJohn Levon };
2011f5207b7SJohn Levon
2021f5207b7SJohn Levon /* The argument is constant and valid if the cost is zero */
expand_bswap(struct expression * expr,int cost)2031f5207b7SJohn Levon static int expand_bswap(struct expression *expr, int cost)
2041f5207b7SJohn Levon {
2051f5207b7SJohn Levon struct expression *arg;
2061f5207b7SJohn Levon long long val;
2071f5207b7SJohn Levon
2081f5207b7SJohn Levon if (cost)
2091f5207b7SJohn Levon return cost;
2101f5207b7SJohn Levon
2111f5207b7SJohn Levon /* the arguments number & type have already been checked */
2121f5207b7SJohn Levon arg = first_expression(expr->args);
2131f5207b7SJohn Levon val = get_expression_value_silent(arg);
2141f5207b7SJohn Levon switch (expr->ctype->bit_size) {
2151f5207b7SJohn Levon case 16: expr->value = bswap16(val); break;
2161f5207b7SJohn Levon case 32: expr->value = bswap32(val); break;
2171f5207b7SJohn Levon case 64: expr->value = bswap64(val); break;
2181f5207b7SJohn Levon default: /* impossible error */
2191f5207b7SJohn Levon return SIDE_EFFECTS;
2201f5207b7SJohn Levon }
2211f5207b7SJohn Levon
2221f5207b7SJohn Levon expr->type = EXPR_VALUE;
2231f5207b7SJohn Levon expr->taint = 0;
2241f5207b7SJohn Levon return 0;
2251f5207b7SJohn Levon }
2261f5207b7SJohn Levon
2271f5207b7SJohn Levon static struct symbol_op bswap_op = {
2281f5207b7SJohn Levon .evaluate = evaluate_pure_unop,
2291f5207b7SJohn Levon .expand = expand_bswap,
2301f5207b7SJohn Levon };
2311f5207b7SJohn Levon
2321f5207b7SJohn Levon
evaluate_fp_unop(struct expression * expr)233*c85f09ccSJohn Levon static int evaluate_fp_unop(struct expression *expr)
234*c85f09ccSJohn Levon {
235*c85f09ccSJohn Levon struct expression *arg;
236*c85f09ccSJohn Levon
237*c85f09ccSJohn Levon if (!eval_args(expr, 1))
238*c85f09ccSJohn Levon return 0;
239*c85f09ccSJohn Levon
240*c85f09ccSJohn Levon arg = first_expression(expr->args);
241*c85f09ccSJohn Levon if (!is_float_type(arg->ctype)) {
242*c85f09ccSJohn Levon expression_error(expr, "non-floating-point argument in call to %s()",
243*c85f09ccSJohn Levon show_ident(expr->fn->ctype->ident));
244*c85f09ccSJohn Levon return 0;
245*c85f09ccSJohn Levon }
246*c85f09ccSJohn Levon return 1;
247*c85f09ccSJohn Levon }
248*c85f09ccSJohn Levon
249*c85f09ccSJohn Levon static struct symbol_op fp_unop_op = {
250*c85f09ccSJohn Levon .evaluate = evaluate_fp_unop,
251*c85f09ccSJohn Levon };
252*c85f09ccSJohn Levon
253*c85f09ccSJohn Levon
evaluate_overflow_gen(struct expression * expr,int ptr)254*c85f09ccSJohn Levon static int evaluate_overflow_gen(struct expression *expr, int ptr)
255*c85f09ccSJohn Levon {
256*c85f09ccSJohn Levon struct expression *arg;
257*c85f09ccSJohn Levon int n = 0;
258*c85f09ccSJohn Levon
259*c85f09ccSJohn Levon /* there will be exactly 3; we'd already verified that */
260*c85f09ccSJohn Levon FOR_EACH_PTR(expr->args, arg) {
261*c85f09ccSJohn Levon struct symbol *type;
262*c85f09ccSJohn Levon
263*c85f09ccSJohn Levon n++;
264*c85f09ccSJohn Levon if (!arg || !(type = arg->ctype))
265*c85f09ccSJohn Levon return 0;
266*c85f09ccSJohn Levon // 1st & 2nd args must be a basic integer type
267*c85f09ccSJohn Levon // 3rd arg must be a pointer to such a type.
268*c85f09ccSJohn Levon if (n == 3 && ptr) {
269*c85f09ccSJohn Levon if (type->type == SYM_NODE)
270*c85f09ccSJohn Levon type = type->ctype.base_type;
271*c85f09ccSJohn Levon if (!type)
272*c85f09ccSJohn Levon return 0;
273*c85f09ccSJohn Levon if (type->type != SYM_PTR)
274*c85f09ccSJohn Levon goto err;
275*c85f09ccSJohn Levon type = type->ctype.base_type;
276*c85f09ccSJohn Levon if (!type)
277*c85f09ccSJohn Levon return 0;
278*c85f09ccSJohn Levon }
279*c85f09ccSJohn Levon if (type->type == SYM_NODE)
280*c85f09ccSJohn Levon type = type->ctype.base_type;
281*c85f09ccSJohn Levon if (!type)
282*c85f09ccSJohn Levon return 0;
283*c85f09ccSJohn Levon if (type->ctype.base_type != &int_type || type == &bool_ctype)
284*c85f09ccSJohn Levon goto err;
285*c85f09ccSJohn Levon } END_FOR_EACH_PTR(arg);
286*c85f09ccSJohn Levon
287*c85f09ccSJohn Levon // the builtin returns a bool
288*c85f09ccSJohn Levon expr->ctype = &bool_ctype;
289*c85f09ccSJohn Levon return 1;
290*c85f09ccSJohn Levon
291*c85f09ccSJohn Levon err:
292*c85f09ccSJohn Levon sparse_error(arg->pos, "invalid type for argument %d:", n);
293*c85f09ccSJohn Levon info(arg->pos, " %s", show_typename(arg->ctype));
294*c85f09ccSJohn Levon expr->ctype = &bad_ctype;
295*c85f09ccSJohn Levon return 0;
296*c85f09ccSJohn Levon }
297*c85f09ccSJohn Levon
evaluate_overflow(struct expression * expr)298*c85f09ccSJohn Levon static int evaluate_overflow(struct expression *expr)
299*c85f09ccSJohn Levon {
300*c85f09ccSJohn Levon return evaluate_overflow_gen(expr, 1);
301*c85f09ccSJohn Levon }
302*c85f09ccSJohn Levon
303*c85f09ccSJohn Levon static struct symbol_op overflow_op = {
304*c85f09ccSJohn Levon .args = args_triadic,
305*c85f09ccSJohn Levon .evaluate = evaluate_overflow,
306*c85f09ccSJohn Levon };
307*c85f09ccSJohn Levon
evaluate_overflow_p(struct expression * expr)308*c85f09ccSJohn Levon static int evaluate_overflow_p(struct expression *expr)
309*c85f09ccSJohn Levon {
310*c85f09ccSJohn Levon return evaluate_overflow_gen(expr, 0);
311*c85f09ccSJohn Levon }
312*c85f09ccSJohn Levon
313*c85f09ccSJohn Levon static struct symbol_op overflow_p_op = {
314*c85f09ccSJohn Levon .args = args_triadic,
315*c85f09ccSJohn Levon .evaluate = evaluate_overflow_p,
316*c85f09ccSJohn Levon };
317*c85f09ccSJohn Levon
318*c85f09ccSJohn Levon
3191f5207b7SJohn Levon /*
3201f5207b7SJohn Levon * Builtin functions
3211f5207b7SJohn Levon */
3221f5207b7SJohn Levon static struct symbol builtin_fn_type = { .type = SYM_FN /* , .variadic =1 */ };
3231f5207b7SJohn Levon static struct sym_init {
3241f5207b7SJohn Levon const char *name;
3251f5207b7SJohn Levon struct symbol *base_type;
3261f5207b7SJohn Levon unsigned int modifiers;
3271f5207b7SJohn Levon struct symbol_op *op;
3281f5207b7SJohn Levon } builtins_table[] = {
3291f5207b7SJohn Levon { "__builtin_constant_p", &builtin_fn_type, MOD_TOPLEVEL, &constant_p_op },
3301f5207b7SJohn Levon { "__builtin_safe_p", &builtin_fn_type, MOD_TOPLEVEL, &safe_p_op },
3311f5207b7SJohn Levon { "__builtin_warning", &builtin_fn_type, MOD_TOPLEVEL, &warning_op },
3321f5207b7SJohn Levon { "__builtin_expect", &builtin_fn_type, MOD_TOPLEVEL, &expect_op },
3331f5207b7SJohn Levon { "__builtin_choose_expr", &builtin_fn_type, MOD_TOPLEVEL, &choose_op },
334*c85f09ccSJohn Levon { "__builtin_bswap16", &builtin_fn_type, MOD_TOPLEVEL, &bswap_op },
335*c85f09ccSJohn Levon { "__builtin_bswap32", &builtin_fn_type, MOD_TOPLEVEL, &bswap_op },
336*c85f09ccSJohn Levon { "__builtin_bswap64", &builtin_fn_type, MOD_TOPLEVEL, &bswap_op },
337*c85f09ccSJohn Levon { "__builtin_isfinite", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op },
338*c85f09ccSJohn Levon { "__builtin_isinf", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op },
339*c85f09ccSJohn Levon { "__builtin_isinf_sign", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op },
340*c85f09ccSJohn Levon { "__builtin_isnan", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op },
341*c85f09ccSJohn Levon { "__builtin_isnormal", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op },
342*c85f09ccSJohn Levon { "__builtin_signbit", &builtin_fn_type, MOD_TOPLEVEL, &fp_unop_op },
343*c85f09ccSJohn Levon { "__builtin_add_overflow", &builtin_fn_type, MOD_TOPLEVEL, &overflow_op },
344*c85f09ccSJohn Levon { "__builtin_sub_overflow", &builtin_fn_type, MOD_TOPLEVEL, &overflow_op },
345*c85f09ccSJohn Levon { "__builtin_mul_overflow", &builtin_fn_type, MOD_TOPLEVEL, &overflow_op },
346*c85f09ccSJohn Levon { "__builtin_add_overflow_p", &builtin_fn_type, MOD_TOPLEVEL, &overflow_p_op },
347*c85f09ccSJohn Levon { "__builtin_sub_overflow_p", &builtin_fn_type, MOD_TOPLEVEL, &overflow_p_op },
348*c85f09ccSJohn Levon { "__builtin_mul_overflow_p", &builtin_fn_type, MOD_TOPLEVEL, &overflow_p_op },
3491f5207b7SJohn Levon { NULL, NULL, 0 }
3501f5207b7SJohn Levon };
3511f5207b7SJohn Levon
init_builtins(int stream)3521f5207b7SJohn Levon void init_builtins(int stream)
3531f5207b7SJohn Levon {
3541f5207b7SJohn Levon struct sym_init *ptr;
3551f5207b7SJohn Levon
3561f5207b7SJohn Levon builtin_fn_type.variadic = 1;
3571f5207b7SJohn Levon for (ptr = builtins_table; ptr->name; ptr++) {
3581f5207b7SJohn Levon struct symbol *sym;
3591f5207b7SJohn Levon sym = create_symbol(stream, ptr->name, SYM_NODE, NS_SYMBOL);
3601f5207b7SJohn Levon sym->ctype.base_type = ptr->base_type;
3611f5207b7SJohn Levon sym->ctype.modifiers = ptr->modifiers;
3621f5207b7SJohn Levon sym->op = ptr->op;
363*c85f09ccSJohn Levon sym->builtin = 1;
3641f5207b7SJohn Levon }
3651f5207b7SJohn Levon }
366*c85f09ccSJohn Levon
declare_builtin(const char * name,struct symbol * rtype,int variadic,...)367*c85f09ccSJohn Levon static void declare_builtin(const char *name, struct symbol *rtype, int variadic, ...)
368*c85f09ccSJohn Levon {
369*c85f09ccSJohn Levon int stream = 0; // FIXME
370*c85f09ccSJohn Levon struct symbol *sym = create_symbol(stream, name, SYM_NODE, NS_SYMBOL);
371*c85f09ccSJohn Levon struct symbol *fun = alloc_symbol(sym->pos, SYM_FN);
372*c85f09ccSJohn Levon struct symbol *arg;
373*c85f09ccSJohn Levon va_list args;
374*c85f09ccSJohn Levon
375*c85f09ccSJohn Levon sym->ctype.base_type = fun;
376*c85f09ccSJohn Levon sym->ctype.modifiers = MOD_TOPLEVEL;
377*c85f09ccSJohn Levon sym->builtin = 1;
378*c85f09ccSJohn Levon
379*c85f09ccSJohn Levon fun->ctype.base_type = rtype;
380*c85f09ccSJohn Levon fun->variadic = variadic;
381*c85f09ccSJohn Levon
382*c85f09ccSJohn Levon va_start(args, variadic);
383*c85f09ccSJohn Levon while ((arg = va_arg(args, struct symbol *))) {
384*c85f09ccSJohn Levon struct symbol *anode = alloc_symbol(sym->pos, SYM_NODE);
385*c85f09ccSJohn Levon anode->ctype.base_type = arg;
386*c85f09ccSJohn Levon add_symbol(&fun->arguments, anode);
387*c85f09ccSJohn Levon }
388*c85f09ccSJohn Levon va_end(args);
389*c85f09ccSJohn Levon }
390*c85f09ccSJohn Levon
declare_builtins(void)391*c85f09ccSJohn Levon void declare_builtins(void)
392*c85f09ccSJohn Levon {
393*c85f09ccSJohn Levon struct symbol *va_list_ctype = &ptr_ctype;
394*c85f09ccSJohn Levon
395*c85f09ccSJohn Levon declare_builtin("__builtin_abort", &void_ctype, 0, NULL);
396*c85f09ccSJohn Levon declare_builtin("__builtin_abs", &int_ctype , 0, &int_ctype, NULL);
397*c85f09ccSJohn Levon declare_builtin("__builtin_alloca", &ptr_ctype, 0, size_t_ctype, NULL);
398*c85f09ccSJohn Levon declare_builtin("__builtin_alpha_cmpbge", &long_ctype, 0, &long_ctype, &long_ctype, NULL);
399*c85f09ccSJohn Levon declare_builtin("__builtin_alpha_extbl", &long_ctype, 0, &long_ctype, &long_ctype, NULL);
400*c85f09ccSJohn Levon declare_builtin("__builtin_alpha_extwl", &long_ctype, 0, &long_ctype, &long_ctype, NULL);
401*c85f09ccSJohn Levon declare_builtin("__builtin_alpha_insbl", &long_ctype, 0, &long_ctype, &long_ctype, NULL);
402*c85f09ccSJohn Levon declare_builtin("__builtin_alpha_inslh", &long_ctype, 0, &long_ctype, &long_ctype, NULL);
403*c85f09ccSJohn Levon declare_builtin("__builtin_alpha_insql", &long_ctype, 0, &long_ctype, &long_ctype, NULL);
404*c85f09ccSJohn Levon declare_builtin("__builtin_alpha_inswl", &long_ctype, 0, &long_ctype, &long_ctype, NULL);
405*c85f09ccSJohn Levon declare_builtin("__builtin_bcmp", &int_ctype , 0, &const_ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL);
406*c85f09ccSJohn Levon declare_builtin("__builtin_bcopy", &void_ctype, 0, &const_ptr_ctype, &ptr_ctype, size_t_ctype, NULL);
407*c85f09ccSJohn Levon declare_builtin("__builtin_bswap16", &ushort_ctype, 0, &ushort_ctype, NULL);
408*c85f09ccSJohn Levon declare_builtin("__builtin_bswap32", &uint_ctype, 0, &uint_ctype, NULL);
409*c85f09ccSJohn Levon declare_builtin("__builtin_bswap64", &ullong_ctype, 0, &ullong_ctype, NULL);
410*c85f09ccSJohn Levon declare_builtin("__builtin_bzero", &void_ctype, 0, &ptr_ctype, size_t_ctype, NULL);
411*c85f09ccSJohn Levon declare_builtin("__builtin_calloc", &ptr_ctype, 0, size_t_ctype, size_t_ctype, NULL);
412*c85f09ccSJohn Levon declare_builtin("__builtin_clrsb", &int_ctype, 0, &int_ctype, NULL);
413*c85f09ccSJohn Levon declare_builtin("__builtin_clrsbl", &int_ctype, 0, &long_ctype, NULL);
414*c85f09ccSJohn Levon declare_builtin("__builtin_clrsbll", &int_ctype, 0, &llong_ctype, NULL);
415*c85f09ccSJohn Levon declare_builtin("__builtin_clz", &int_ctype, 0, &int_ctype, NULL);
416*c85f09ccSJohn Levon declare_builtin("__builtin_clzl", &int_ctype, 0, &long_ctype, NULL);
417*c85f09ccSJohn Levon declare_builtin("__builtin_clzll", &int_ctype, 0, &llong_ctype, NULL);
418*c85f09ccSJohn Levon declare_builtin("__builtin_ctz", &int_ctype, 0, &int_ctype, NULL);
419*c85f09ccSJohn Levon declare_builtin("__builtin_ctzl", &int_ctype, 0, &long_ctype, NULL);
420*c85f09ccSJohn Levon declare_builtin("__builtin_ctzll", &int_ctype, 0, &llong_ctype, NULL);
421*c85f09ccSJohn Levon declare_builtin("__builtin_exit", &void_ctype, 0, &int_ctype, NULL);
422*c85f09ccSJohn Levon declare_builtin("__builtin_expect", &long_ctype, 0, &long_ctype ,&long_ctype, NULL);
423*c85f09ccSJohn Levon declare_builtin("__builtin_extract_return_addr", &ptr_ctype, 0, &ptr_ctype, NULL);
424*c85f09ccSJohn Levon declare_builtin("__builtin_fabs", &double_ctype, 0, &double_ctype, NULL);
425*c85f09ccSJohn Levon declare_builtin("__builtin_ffs", &int_ctype, 0, &int_ctype, NULL);
426*c85f09ccSJohn Levon declare_builtin("__builtin_ffsl", &int_ctype, 0, &long_ctype, NULL);
427*c85f09ccSJohn Levon declare_builtin("__builtin_ffsll", &int_ctype, 0, &llong_ctype, NULL);
428*c85f09ccSJohn Levon declare_builtin("__builtin_frame_address", &ptr_ctype, 0, &uint_ctype, NULL);
429*c85f09ccSJohn Levon declare_builtin("__builtin_free", &void_ctype, 0, &ptr_ctype, NULL);
430*c85f09ccSJohn Levon declare_builtin("__builtin_huge_val", &double_ctype, 0, NULL);
431*c85f09ccSJohn Levon declare_builtin("__builtin_huge_valf", &float_ctype, 0, NULL);
432*c85f09ccSJohn Levon declare_builtin("__builtin_huge_vall", &ldouble_ctype, 0, NULL);
433*c85f09ccSJohn Levon declare_builtin("__builtin_index", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL);
434*c85f09ccSJohn Levon declare_builtin("__builtin_inf", &double_ctype, 0, NULL);
435*c85f09ccSJohn Levon declare_builtin("__builtin_inff", &float_ctype, 0, NULL);
436*c85f09ccSJohn Levon declare_builtin("__builtin_infl", &ldouble_ctype, 0, NULL);
437*c85f09ccSJohn Levon declare_builtin("__builtin_isfinite", &int_ctype, 1, NULL);
438*c85f09ccSJohn Levon declare_builtin("__builtin_isgreater", &int_ctype, 0, &float_ctype, &float_ctype, NULL);
439*c85f09ccSJohn Levon declare_builtin("__builtin_isgreaterequal", &int_ctype, 0, &float_ctype, &float_ctype, NULL);
440*c85f09ccSJohn Levon declare_builtin("__builtin_isinf", &int_ctype, 1, NULL);
441*c85f09ccSJohn Levon declare_builtin("__builtin_isinf_sign", &int_ctype, 1, NULL);
442*c85f09ccSJohn Levon declare_builtin("__builtin_isless", &int_ctype, 0, &float_ctype, &float_ctype, NULL);
443*c85f09ccSJohn Levon declare_builtin("__builtin_islessequal", &int_ctype, 0, &float_ctype, &float_ctype, NULL);
444*c85f09ccSJohn Levon declare_builtin("__builtin_islessgreater", &int_ctype, 0, &float_ctype, &float_ctype, NULL);
445*c85f09ccSJohn Levon declare_builtin("__builtin_isnan", &int_ctype, 1, NULL);
446*c85f09ccSJohn Levon declare_builtin("__builtin_isnormal", &int_ctype, 1, NULL);
447*c85f09ccSJohn Levon declare_builtin("__builtin_isunordered", &int_ctype, 0, &float_ctype, &float_ctype, NULL);
448*c85f09ccSJohn Levon declare_builtin("__builtin_labs", &long_ctype, 0, &long_ctype, NULL);
449*c85f09ccSJohn Levon declare_builtin("__builtin_llabs", &llong_ctype, 0, &llong_ctype, NULL);
450*c85f09ccSJohn Levon declare_builtin("__builtin_malloc", &ptr_ctype, 0, size_t_ctype, NULL);
451*c85f09ccSJohn Levon declare_builtin("__builtin_memchr", &ptr_ctype, 0, &const_ptr_ctype, &int_ctype, size_t_ctype, NULL);
452*c85f09ccSJohn Levon declare_builtin("__builtin_memcmp", &int_ctype, 0, &const_ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL);
453*c85f09ccSJohn Levon declare_builtin("__builtin_memcpy", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL);
454*c85f09ccSJohn Levon declare_builtin("__builtin_memmove", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL);
455*c85f09ccSJohn Levon declare_builtin("__builtin_mempcpy", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, NULL);
456*c85f09ccSJohn Levon declare_builtin("__builtin_memset", &ptr_ctype, 0, &ptr_ctype, &int_ctype, size_t_ctype, NULL);
457*c85f09ccSJohn Levon declare_builtin("__builtin_nan", &double_ctype, 0, &const_string_ctype, NULL);
458*c85f09ccSJohn Levon declare_builtin("__builtin_nanf", &float_ctype, 0, &const_string_ctype, NULL);
459*c85f09ccSJohn Levon declare_builtin("__builtin_nanl", &ldouble_ctype, 0, &const_string_ctype, NULL);
460*c85f09ccSJohn Levon declare_builtin("__builtin_object_size", size_t_ctype, 0, &const_ptr_ctype, &int_ctype, NULL);
461*c85f09ccSJohn Levon declare_builtin("__builtin_parity", &int_ctype, 0, &uint_ctype, NULL);
462*c85f09ccSJohn Levon declare_builtin("__builtin_parityl", &int_ctype, 0, &ulong_ctype, NULL);
463*c85f09ccSJohn Levon declare_builtin("__builtin_parityll", &int_ctype, 0, &ullong_ctype, NULL);
464*c85f09ccSJohn Levon declare_builtin("__builtin_popcount", &int_ctype, 0, &uint_ctype, NULL);
465*c85f09ccSJohn Levon declare_builtin("__builtin_popcountl", &int_ctype, 0, &ulong_ctype, NULL);
466*c85f09ccSJohn Levon declare_builtin("__builtin_popcountll", &int_ctype, 0, &ullong_ctype, NULL);
467*c85f09ccSJohn Levon declare_builtin("__builtin_prefetch", &void_ctype, 1, &const_ptr_ctype, NULL);
468*c85f09ccSJohn Levon declare_builtin("__builtin_printf", &int_ctype, 1, &const_string_ctype, NULL);
469*c85f09ccSJohn Levon declare_builtin("__builtin_puts", &int_ctype, 0, &const_string_ctype, NULL);
470*c85f09ccSJohn Levon declare_builtin("__builtin_realloc", &ptr_ctype, 0, &ptr_ctype, size_t_ctype, NULL);
471*c85f09ccSJohn Levon declare_builtin("__builtin_return_address", &ptr_ctype, 0, &uint_ctype, NULL);
472*c85f09ccSJohn Levon declare_builtin("__builtin_rindex", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL);
473*c85f09ccSJohn Levon declare_builtin("__builtin_sadd_overflow", &bool_ctype, 0, &int_ctype, &int_ctype, &int_ptr_ctype, NULL);
474*c85f09ccSJohn Levon declare_builtin("__builtin_saddl_overflow", &bool_ctype, 0, &long_ctype, &long_ctype, &long_ptr_ctype, NULL);
475*c85f09ccSJohn Levon declare_builtin("__builtin_saddll_overflow", &bool_ctype, 0, &llong_ctype, &llong_ctype, &llong_ptr_ctype, NULL);
476*c85f09ccSJohn Levon declare_builtin("__builtin_signbit", &int_ctype, 1, NULL);
477*c85f09ccSJohn Levon declare_builtin("__builtin_smul_overflow", &bool_ctype, 0, &int_ctype, &int_ctype, &int_ptr_ctype, NULL);
478*c85f09ccSJohn Levon declare_builtin("__builtin_smull_overflow", &bool_ctype, 0, &long_ctype, &long_ctype, &long_ptr_ctype, NULL);
479*c85f09ccSJohn Levon declare_builtin("__builtin_smulll_overflow", &bool_ctype, 0, &llong_ctype, &llong_ctype, &llong_ptr_ctype, NULL);
480*c85f09ccSJohn Levon declare_builtin("__builtin_snprintf", &int_ctype, 1, &string_ctype, size_t_ctype, &const_string_ctype, NULL);
481*c85f09ccSJohn Levon declare_builtin("__builtin_sprintf", &int_ctype, 1, &string_ctype, &const_string_ctype, NULL);
482*c85f09ccSJohn Levon declare_builtin("__builtin_ssub_overflow", &bool_ctype, 0, &int_ctype, &int_ctype, &int_ptr_ctype, NULL);
483*c85f09ccSJohn Levon declare_builtin("__builtin_ssubl_overflow", &bool_ctype, 0, &long_ctype, &long_ctype, &long_ptr_ctype, NULL);
484*c85f09ccSJohn Levon declare_builtin("__builtin_ssubll_overflow", &bool_ctype, 0, &llong_ctype, &llong_ctype, &llong_ptr_ctype, NULL);
485*c85f09ccSJohn Levon declare_builtin("__builtin_stpcpy", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL);
486*c85f09ccSJohn Levon declare_builtin("__builtin_stpncpy", &string_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL);
487*c85f09ccSJohn Levon declare_builtin("__builtin_strcasecmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, NULL);
488*c85f09ccSJohn Levon declare_builtin("__builtin_strcasestr", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL);
489*c85f09ccSJohn Levon declare_builtin("__builtin_strcat", &string_ctype, 0, &string_ctype, &const_string_ctype, NULL);
490*c85f09ccSJohn Levon declare_builtin("__builtin_strchr", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL);
491*c85f09ccSJohn Levon declare_builtin("__builtin_strcmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, NULL);
492*c85f09ccSJohn Levon declare_builtin("__builtin_strcpy", &string_ctype, 0, &string_ctype, &const_string_ctype, NULL);
493*c85f09ccSJohn Levon declare_builtin("__builtin_strcspn", size_t_ctype, 0, &const_string_ctype, &const_string_ctype, NULL);
494*c85f09ccSJohn Levon declare_builtin("__builtin_strdup", &string_ctype, 0, &const_string_ctype, NULL);
495*c85f09ccSJohn Levon declare_builtin("__builtin_strlen", size_t_ctype, 0, &const_string_ctype, NULL);
496*c85f09ccSJohn Levon declare_builtin("__builtin_strncasecmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL);
497*c85f09ccSJohn Levon declare_builtin("__builtin_strncat", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL);
498*c85f09ccSJohn Levon declare_builtin("__builtin_strncmp", &int_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL);
499*c85f09ccSJohn Levon declare_builtin("__builtin_strncpy", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL);
500*c85f09ccSJohn Levon declare_builtin("__builtin_strndup", &string_ctype, 0, &const_string_ctype, size_t_ctype, NULL);
501*c85f09ccSJohn Levon declare_builtin("__builtin_strnstr", &string_ctype, 0, &const_string_ctype, &const_string_ctype, size_t_ctype, NULL);
502*c85f09ccSJohn Levon declare_builtin("__builtin_strpbrk", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL);
503*c85f09ccSJohn Levon declare_builtin("__builtin_strrchr", &string_ctype, 0, &const_string_ctype, &int_ctype, NULL);
504*c85f09ccSJohn Levon declare_builtin("__builtin_strspn", size_t_ctype, 0, &const_string_ctype, &const_string_ctype, NULL);
505*c85f09ccSJohn Levon declare_builtin("__builtin_strstr", &string_ctype, 0, &const_string_ctype, &const_string_ctype, NULL);
506*c85f09ccSJohn Levon declare_builtin("__builtin_trap", &void_ctype, 0, NULL);
507*c85f09ccSJohn Levon declare_builtin("__builtin_uadd_overflow", &bool_ctype, 0, &uint_ctype, &uint_ctype, &uint_ptr_ctype, NULL);
508*c85f09ccSJohn Levon declare_builtin("__builtin_uaddl_overflow", &bool_ctype, 0, &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype, NULL);
509*c85f09ccSJohn Levon declare_builtin("__builtin_uaddll_overflow", &bool_ctype, 0, &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype, NULL);
510*c85f09ccSJohn Levon declare_builtin("__builtin_umul_overflow", &bool_ctype, 0, &uint_ctype, &uint_ctype, &uint_ptr_ctype, NULL);
511*c85f09ccSJohn Levon declare_builtin("__builtin_umull_overflow", &bool_ctype, 0, &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype, NULL);
512*c85f09ccSJohn Levon declare_builtin("__builtin_umulll_overflow", &bool_ctype, 0, &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype, NULL);
513*c85f09ccSJohn Levon declare_builtin("__builtin_unreachable", &void_ctype, 0, NULL);
514*c85f09ccSJohn Levon declare_builtin("__builtin_usub_overflow", &bool_ctype, 0, &uint_ctype, &uint_ctype, &uint_ptr_ctype, NULL);
515*c85f09ccSJohn Levon declare_builtin("__builtin_usubl_overflow", &bool_ctype, 0, &ulong_ctype, &ulong_ctype, &ulong_ptr_ctype, NULL);
516*c85f09ccSJohn Levon declare_builtin("__builtin_usubll_overflow", &bool_ctype, 0, &ullong_ctype, &ullong_ctype, &ullong_ptr_ctype, NULL);
517*c85f09ccSJohn Levon declare_builtin("__builtin_va_arg_pack_len", size_t_ctype, 0, NULL);
518*c85f09ccSJohn Levon declare_builtin("__builtin_vprintf", &int_ctype, 0, &const_string_ctype, va_list_ctype, NULL);
519*c85f09ccSJohn Levon declare_builtin("__builtin_vsnprintf", &int_ctype, 0, &string_ctype, size_t_ctype, &const_string_ctype, va_list_ctype, NULL);
520*c85f09ccSJohn Levon declare_builtin("__builtin_vsprintf", &int_ctype, 0, &string_ctype, &const_string_ctype, va_list_ctype, NULL);
521*c85f09ccSJohn Levon
522*c85f09ccSJohn Levon declare_builtin("__builtin___memcpy_chk", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype, NULL);
523*c85f09ccSJohn Levon declare_builtin("__builtin___memmove_chk", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype, NULL);
524*c85f09ccSJohn Levon declare_builtin("__builtin___mempcpy_chk", &ptr_ctype, 0, &ptr_ctype, &const_ptr_ctype, size_t_ctype, size_t_ctype, NULL);
525*c85f09ccSJohn Levon declare_builtin("__builtin___memset_chk", &ptr_ctype, 0, &ptr_ctype, &int_ctype, size_t_ctype, size_t_ctype, NULL);
526*c85f09ccSJohn Levon declare_builtin("__builtin___snprintf_chk", &int_ctype, 1, &string_ctype, size_t_ctype, &int_ctype , size_t_ctype, &const_string_ctype, NULL);
527*c85f09ccSJohn Levon declare_builtin("__builtin___sprintf_chk", &int_ctype, 1, &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype, NULL);
528*c85f09ccSJohn Levon declare_builtin("__builtin___stpcpy_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL);
529*c85f09ccSJohn Levon declare_builtin("__builtin___strcat_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL);
530*c85f09ccSJohn Levon declare_builtin("__builtin___strcpy_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, NULL);
531*c85f09ccSJohn Levon declare_builtin("__builtin___strncat_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype, NULL);
532*c85f09ccSJohn Levon declare_builtin("__builtin___strncpy_chk", &string_ctype, 0, &string_ctype, &const_string_ctype, size_t_ctype, size_t_ctype, NULL);
533*c85f09ccSJohn Levon declare_builtin("__builtin___vsnprintf_chk", &int_ctype, 0, &string_ctype, size_t_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype, NULL);
534*c85f09ccSJohn Levon declare_builtin("__builtin___vsprintf_chk", &int_ctype, 0, &string_ctype, &int_ctype, size_t_ctype, &const_string_ctype, va_list_ctype, NULL);
535*c85f09ccSJohn Levon
536*c85f09ccSJohn Levon declare_builtin("__sync_add_and_fetch", &int_ctype, 1, &ptr_ctype, NULL);
537*c85f09ccSJohn Levon declare_builtin("__sync_and_and_fetch", &int_ctype, 1, &ptr_ctype, NULL);
538*c85f09ccSJohn Levon declare_builtin("__sync_bool_compare_and_swap", &int_ctype, 1, &ptr_ctype, NULL);
539*c85f09ccSJohn Levon declare_builtin("__sync_fetch_and_add", &int_ctype, 1, &ptr_ctype, NULL);
540*c85f09ccSJohn Levon declare_builtin("__sync_fetch_and_and", &int_ctype, 1, &ptr_ctype, NULL);
541*c85f09ccSJohn Levon declare_builtin("__sync_fetch_and_nand", &int_ctype, 1, &ptr_ctype, NULL);
542*c85f09ccSJohn Levon declare_builtin("__sync_fetch_and_or", &int_ctype, 1, &ptr_ctype, NULL);
543*c85f09ccSJohn Levon declare_builtin("__sync_fetch_and_sub", &int_ctype, 1, &ptr_ctype, NULL);
544*c85f09ccSJohn Levon declare_builtin("__sync_fetch_and_xor", &int_ctype, 1, &ptr_ctype, NULL);
545*c85f09ccSJohn Levon declare_builtin("__sync_lock_release", &void_ctype, 1, &ptr_ctype, NULL);
546*c85f09ccSJohn Levon declare_builtin("__sync_lock_test_and_set", &int_ctype, 1, &ptr_ctype, NULL);
547*c85f09ccSJohn Levon declare_builtin("__sync_nand_and_fetch", &int_ctype, 1, &ptr_ctype, NULL);
548*c85f09ccSJohn Levon declare_builtin("__sync_or_and_fetch", &int_ctype, 1, &ptr_ctype, NULL);
549*c85f09ccSJohn Levon declare_builtin("__sync_sub_and_fetch", &int_ctype, 1, &ptr_ctype, NULL);
550*c85f09ccSJohn Levon declare_builtin("__sync_synchronize", &void_ctype, 0, NULL);
551*c85f09ccSJohn Levon declare_builtin("__sync_val_compare_and_swap", &int_ctype, 1, &ptr_ctype, NULL);
552*c85f09ccSJohn Levon declare_builtin("__sync_xor_and_fetch", &int_ctype, 1, &ptr_ctype, NULL);
553*c85f09ccSJohn Levon
554*c85f09ccSJohn Levon // Blackfin-specific stuff
555*c85f09ccSJohn Levon declare_builtin("__builtin_bfin_csync", &void_ctype, 0, NULL);
556*c85f09ccSJohn Levon declare_builtin("__builtin_bfin_ssync", &void_ctype, 0, NULL);
557*c85f09ccSJohn Levon declare_builtin("__builtin_bfin_norm_fr1x32", &int_ctype, 0, &int_ctype, NULL);
558*c85f09ccSJohn Levon }
559