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 #define dyntype incomplete_ctype
35 static bool is_dynamic_type(struct symbol
*t
)
37 if (t
->type
== SYM_NODE
)
38 t
= t
->ctype
.base_type
;
42 static int evaluate_to_int_const_expr(struct expression
*expr
)
44 expr
->ctype
= &int_ctype
;
45 expr
->flags
|= CEF_SET_ICE
;
49 static int evaluate_pure_unop(struct expression
*expr
)
51 struct expression
*arg
= first_expression(expr
->args
);
52 int flags
= arg
->flags
;
55 * Allow such functions with a constant integer expression
56 * argument to be treated as a *constant* integer.
57 * This allow us to use them in switch() { case ...:
59 flags
|= (flags
& CEF_ICE
) ? CEF_SET_INT
: 0;
65 * eval_args - check the number of arguments and evaluate them.
67 static int eval_args(struct expression
*expr
, int n
)
69 struct expression
*arg
;
74 FOR_EACH_PTR(expr
->args
, arg
) {
76 msg
= "too many arguments";
79 if (!evaluate_expression(arg
))
81 } END_FOR_EACH_PTR(arg
);
83 msg
= "not enough arguments";
89 sym
= expr
->fn
->ctype
;
90 expression_error(expr
, "%s for %s", msg
, show_ident(sym
->ident
));
94 static int args_prototype(struct expression
*expr
)
96 struct symbol
*fntype
= expr
->fn
->ctype
->ctype
.base_type
;
97 int n
= symbol_list_size(fntype
->arguments
);
98 return eval_args(expr
, n
);
101 static int args_triadic(struct expression
*expr
)
103 return eval_args(expr
, 3);
106 static int evaluate_choose(struct expression
*expr
)
108 struct expression_list
*list
= expr
->args
;
109 struct expression
*arg
, *args
[3];
112 /* there will be exactly 3; we'd already verified that */
113 FOR_EACH_PTR(list
, arg
) {
115 } END_FOR_EACH_PTR(arg
);
117 *expr
= get_expression_value(args
[0]) ? *args
[1] : *args
[2];
122 static int expand_expect(struct expression
*expr
, int cost
)
124 struct expression
*arg
= first_ptr_list((struct ptr_list
*) expr
->args
);
132 * __builtin_warning() has type "int" and always returns 1,
133 * so that you can use it in conditionals or whatever
135 static int expand_warning(struct expression
*expr
, int cost
)
137 struct expression
*arg
;
138 struct expression_list
*arglist
= expr
->args
;
140 FOR_EACH_PTR (arglist
, arg
) {
142 * Constant strings get printed out as a warning. By the
143 * time we get here, the EXPR_STRING has been fully
144 * evaluated, so by now it's an anonymous symbol with a
145 * string initializer.
147 * Just for the heck of it, allow any constant string
150 if (arg
->type
== EXPR_SYMBOL
) {
151 struct symbol
*sym
= arg
->symbol
;
152 if (sym
->initializer
&& sym
->initializer
->type
== EXPR_STRING
) {
153 struct string
*string
= sym
->initializer
->string
;
154 warning(expr
->pos
, "%*s", string
->length
-1, string
->data
);
160 * Any other argument is a conditional. If it's
161 * non-constant, or it is false, we exit and do
162 * not print any warning.
164 if (arg
->type
!= EXPR_VALUE
)
168 } END_FOR_EACH_PTR(arg
);
170 expr
->type
= EXPR_VALUE
;
176 /* The arguments are constant if the cost of all of them is zero */
177 static int expand_constant_p(struct expression
*expr
, int cost
)
179 expr
->type
= EXPR_VALUE
;
185 /* The arguments are safe, if their cost is less than SIDE_EFFECTS */
186 static int expand_safe_p(struct expression
*expr
, int cost
)
188 expr
->type
= EXPR_VALUE
;
189 expr
->value
= (cost
< SIDE_EFFECTS
);
194 static struct symbol_op constant_p_op
= {
195 .evaluate
= evaluate_to_int_const_expr
,
196 .expand
= expand_constant_p
199 static struct symbol_op safe_p_op
= {
200 .evaluate
= evaluate_to_int_const_expr
,
201 .expand
= expand_safe_p
204 static struct symbol_op warning_op
= {
205 .evaluate
= evaluate_to_int_const_expr
,
206 .expand
= expand_warning
209 static struct symbol_op expect_op
= {
210 .expand
= expand_expect
213 static struct symbol_op choose_op
= {
214 .args
= args_triadic
,
215 .evaluate
= evaluate_choose
,
218 /* The argument is constant and valid if the cost is zero */
219 static int expand_bswap(struct expression
*expr
, int cost
)
221 struct expression
*arg
;
227 /* the arguments number & type have already been checked */
228 arg
= first_expression(expr
->args
);
229 val
= get_expression_value_silent(arg
);
230 switch (expr
->ctype
->bit_size
) {
231 case 16: expr
->value
= bswap16(val
); break;
232 case 32: expr
->value
= bswap32(val
); break;
233 case 64: expr
->value
= bswap64(val
); break;
234 default: /* impossible error */
238 expr
->type
= EXPR_VALUE
;
243 static struct symbol_op bswap_op
= {
244 .evaluate
= evaluate_pure_unop
,
245 .expand
= expand_bswap
,
249 #define EXPAND_FINDBIT(name) \
250 static int expand_##name(struct expression *expr, int cost) \
252 struct expression *arg; \
258 arg = first_expression(expr->args); \
259 val = get_expression_value_silent(arg); \
260 switch (arg->ctype->bit_size) { \
261 case sizeof(int) * 8: \
262 val = __builtin_##name(val); break; \
263 case sizeof(long long) * 8: \
264 val = __builtin_##name##ll(val); break; \
265 default: /* impossible error */ \
266 return SIDE_EFFECTS; \
270 expr->type = EXPR_VALUE; \
275 static struct symbol_op name##_op = { \
276 .evaluate = evaluate_pure_unop, \
277 .expand = expand_##name, \
282 EXPAND_FINDBIT(clrsb
);
284 EXPAND_FINDBIT(parity
);
285 EXPAND_FINDBIT(popcount
);
287 static int evaluate_fp_unop(struct expression
*expr
)
289 struct expression
*arg
;
291 if (!eval_args(expr
, 1))
294 arg
= first_expression(expr
->args
);
295 if (!is_float_type(arg
->ctype
)) {
296 expression_error(expr
, "non-floating-point argument in call to %s()",
297 show_ident(expr
->fn
->ctype
->ident
));
303 static struct symbol_op fp_unop_op
= {
304 .evaluate
= evaluate_fp_unop
,
308 static int expand_isdigit(struct expression
*expr
, int cost
)
310 struct expression
*arg
= first_expression(expr
->args
);
311 long long val
= get_expression_value_silent(arg
);
316 expr
->value
= (val
>= '0') && (val
<= '9');
317 expr
->type
= EXPR_VALUE
;
322 static struct symbol_op isdigit_op
= {
323 .evaluate
= evaluate_pure_unop
,
324 .expand
= expand_isdigit
,
328 static int evaluate_overflow_gen(struct expression
*expr
, int ptr
)
330 struct expression
*arg
;
333 /* there will be exactly 3; we'd already verified that */
334 FOR_EACH_PTR(expr
->args
, arg
) {
338 if (!arg
|| !(type
= arg
->ctype
))
340 // 1st & 2nd args must be a basic integer type
341 // 3rd arg must be a pointer to such a type.
343 if (type
->type
== SYM_NODE
)
344 type
= type
->ctype
.base_type
;
347 if (type
->type
!= SYM_PTR
)
349 type
= type
->ctype
.base_type
;
353 if (type
->type
== SYM_NODE
)
354 type
= type
->ctype
.base_type
;
357 if (type
->ctype
.base_type
!= &int_type
|| type
== &bool_ctype
)
359 } END_FOR_EACH_PTR(arg
);
361 // the builtin returns a bool
362 expr
->ctype
= &bool_ctype
;
366 sparse_error(arg
->pos
, "invalid type for argument %d:", n
);
367 info(arg
->pos
, " %s", show_typename(arg
->ctype
));
368 expr
->ctype
= &bad_ctype
;
372 static int evaluate_overflow(struct expression
*expr
)
374 return evaluate_overflow_gen(expr
, 1);
377 static struct symbol_op overflow_op
= {
378 .args
= args_triadic
,
379 .evaluate
= evaluate_overflow
,
382 static int evaluate_overflow_p(struct expression
*expr
)
384 return evaluate_overflow_gen(expr
, 0);
387 static struct symbol_op overflow_p_op
= {
388 .args
= args_triadic
,
389 .evaluate
= evaluate_overflow_p
,
393 static int eval_atomic_common(struct expression
*expr
)
395 struct symbol
*fntype
= expr
->fn
->ctype
->ctype
.base_type
;
396 struct symbol_list
*types
= NULL
;
397 struct symbol
*ctype
= NULL
;
399 struct expression
*arg
;
402 // The number of arguments has already be verified.
403 // The first arg must be a pointer to an integral type.
404 PREPARE_PTR_LIST(fntype
->arguments
, t
);
405 FOR_EACH_PTR(expr
->args
, arg
) {
406 struct symbol
*ptrtype
= NULL
;
412 if (t
->type
== SYM_NODE
)
413 t
= t
->ctype
.base_type
;
416 if (t
->type
!= SYM_PTR
)
419 t
= t
->ctype
.base_type
;
422 if (t
->type
== SYM_NODE
)
423 t
= t
->ctype
.base_type
;
426 if (t
->type
!= SYM_PTR
&& t
->ctype
.base_type
!= &int_type
)
430 } else if (is_dynamic_type(t
)) {
432 } else if (t
== &ptr_ctype
) {
435 add_ptr_list(&types
, t
);
437 } END_FOR_EACH_PTR(arg
);
440 if (!expr
->ctype
) // set the return type, if needed
442 return evaluate_arguments(types
, expr
->args
);
445 sparse_error(arg
->pos
, "invalid type for argument %d:", n
);
446 info(arg
->pos
, " %s", show_typename(arg
->ctype
));
447 expr
->ctype
= &bad_ctype
;
451 static struct symbol_op atomic_op
= {
452 .args
= args_prototype
,
453 .evaluate
= eval_atomic_common
,
460 static struct symbol size_t_alias
;
462 static struct symbol
*get_ctype(struct symbol
*sym
)
464 if (sym
== &size_t_alias
)
469 static void declare_builtin(int stream
, const struct builtin_fn
*entry
)
471 struct symbol
*sym
= create_symbol(stream
, entry
->name
, SYM_NODE
, NS_SYMBOL
);
472 struct symbol
*fun
= alloc_symbol(sym
->pos
, SYM_FN
);
476 sym
->ctype
.base_type
= fun
;
477 sym
->ctype
.modifiers
= MOD_TOPLEVEL
;
481 fun
->ctype
.base_type
= get_ctype(entry
->ret_type
);
482 fun
->variadic
= entry
->variadic
;
484 for (i
= 0; (arg
= entry
->args
[i
]); i
++) {
485 struct symbol
*anode
= alloc_symbol(sym
->pos
, SYM_NODE
);
486 anode
->ctype
.base_type
= get_ctype(arg
);
487 add_symbol(&fun
->arguments
, anode
);
491 static void declare_builtins(int stream
, const struct builtin_fn tbl
[])
497 declare_builtin(stream
, tbl
++);
500 static const struct builtin_fn builtins_common
[] = {
501 #define size_t_ctype &size_t_alias
502 #define va_list_ctype &ptr_ctype
503 #define vol_ptr &volatile_ptr_ctype
504 { "__atomic_add_fetch", NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
505 { "__atomic_always_lock_free", &bool_ctype
, 0, { size_t_ctype
, vol_ptr
}},
506 { "__atomic_and_fetch", NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
507 { "__atomic_clear", &void_ctype
, 0, { &volatile_bool_ptr_ctype
, &int_ctype
}},
508 { "__atomic_compare_exchange", &bool_ctype
, 0, { vol_ptr
, &ptr_ctype
, &ptr_ctype
, &bool_ctype
, &int_ctype
, &int_ctype
}, .op
= &atomic_op
},
509 { "__atomic_compare_exchange_n", &bool_ctype
, 0, { vol_ptr
, &ptr_ctype
, &dyntype
, &bool_ctype
, &int_ctype
, &int_ctype
}, .op
= &atomic_op
},
510 { "__atomic_exchange", &void_ctype
, 0, { vol_ptr
, &ptr_ctype
, &ptr_ctype
, &int_ctype
}, .op
= &atomic_op
},
511 { "__atomic_exchange_n", NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
512 { "__atomic_fetch_add", NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
513 { "__atomic_fetch_and", NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
514 { "__atomic_fetch_nand",NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
515 { "__atomic_fetch_or", NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
516 { "__atomic_fetch_sub", NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
517 { "__atomic_fetch_xor", NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
518 { "__atomic_is_lock_free", &bool_ctype
, 0, { size_t_ctype
, vol_ptr
}},
519 { "__atomic_load", &void_ctype
, 0, { vol_ptr
, &ptr_ctype
, &int_ctype
}, .op
= &atomic_op
},
520 { "__atomic_load_n", NULL
, 0, { vol_ptr
, &int_ctype
}, .op
= &atomic_op
},
521 { "__atomic_nand_fetch",NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
522 { "__atomic_or_fetch", NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
523 { "__atomic_signal_fence", &void_ctype
, 0, { &int_ctype
}},
524 { "__atomic_store", &void_ctype
, 0, { vol_ptr
, &ptr_ctype
, &int_ctype
}, .op
= &atomic_op
},
525 { "__atomic_store_n", &void_ctype
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
526 { "__atomic_sub_fetch", NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
527 { "__atomic_test_and_set", &bool_ctype
, 0, { vol_ptr
, &int_ctype
}},
528 { "__atomic_thread_fence", &void_ctype
, 0, { &int_ctype
}},
529 { "__atomic_xor_fetch", NULL
, 0, { vol_ptr
, &dyntype
, &int_ctype
}, .op
= &atomic_op
},
530 { "__builtin_choose_expr", NULL
, 1, .op
= &choose_op
},
531 { "__builtin_constant_p", NULL
, 1, .op
= &constant_p_op
},
532 { "__builtin_expect", &long_ctype
, 0, { &long_ctype
,&long_ctype
}, .op
= &expect_op
},
533 { "__builtin_safe_p", NULL
, 1, .op
= &safe_p_op
},
534 { "__builtin_warning", NULL
, 1, .op
= &warning_op
},
536 { "__builtin_abort", &void_ctype
, 0 },
537 { "__builtin_abs", &int_ctype
, 0, { &int_ctype
}},
538 { "__builtin_add_overflow", &bool_ctype
, 1, .op
= &overflow_op
},
539 { "__builtin_add_overflow_p", &bool_ctype
, 1, .op
= &overflow_p_op
},
540 { "__builtin_alloca", &ptr_ctype
, 0, { size_t_ctype
}},
541 { "__builtin_bcmp", &int_ctype
, 0, { &const_ptr_ctype
, &const_ptr_ctype
, size_t_ctype
}},
542 { "__builtin_bcopy", &void_ctype
, 0, { &const_ptr_ctype
, &ptr_ctype
, size_t_ctype
}},
543 { "__builtin_bswap16", &ushort_ctype
, 0, { &ushort_ctype
}, .op
= &bswap_op
},
544 { "__builtin_bswap32", &uint_ctype
, 0, { &uint_ctype
}, .op
= &bswap_op
},
545 { "__builtin_bswap64", &ullong_ctype
, 0, { &ullong_ctype
}, .op
= &bswap_op
},
546 { "__builtin_bzero", &void_ctype
, 0, { &ptr_ctype
, size_t_ctype
}},
547 { "__builtin_calloc", &ptr_ctype
, 0, { size_t_ctype
, size_t_ctype
}},
548 { "__builtin_clrsb", &int_ctype
, 0, { &int_ctype
}, .op
= &clrsb_op
},
549 { "__builtin_clrsbl", &int_ctype
, 0, { &long_ctype
}, .op
= &clrsb_op
},
550 { "__builtin_clrsbll", &int_ctype
, 0, { &llong_ctype
}, .op
= &clrsb_op
},
551 { "__builtin_clz", &int_ctype
, 0, { &int_ctype
}, .op
= &clz_op
},
552 { "__builtin_clzl", &int_ctype
, 0, { &long_ctype
}, .op
= &clz_op
},
553 { "__builtin_clzll", &int_ctype
, 0, { &llong_ctype
}, .op
= &clz_op
},
554 { "__builtin_ctz", &int_ctype
, 0, { &int_ctype
}, .op
= &ctz_op
},
555 { "__builtin_ctzl", &int_ctype
, 0, { &long_ctype
}, .op
= &ctz_op
},
556 { "__builtin_ctzll", &int_ctype
, 0, { &llong_ctype
}, .op
= &ctz_op
},
557 { "__builtin_exit", &void_ctype
, 0, { &int_ctype
}},
558 { "__builtin_extract_return_addr", &ptr_ctype
, 0, { &ptr_ctype
}},
559 { "__builtin_fabs", &double_ctype
, 0, { &double_ctype
}},
560 { "__builtin_ffs", &int_ctype
, 0, { &int_ctype
}, .op
= &ffs_op
},
561 { "__builtin_ffsl", &int_ctype
, 0, { &long_ctype
}, .op
= &ffs_op
},
562 { "__builtin_ffsll", &int_ctype
, 0, { &llong_ctype
}, .op
= &ffs_op
},
563 { "__builtin_fma", &double_ctype
, 0, { &double_ctype
, &double_ctype
, &double_ctype
}},
564 { "__builtin_fmaf", &float_ctype
, 0, { &float_ctype
, &float_ctype
, &float_ctype
}},
565 { "__builtin_fmal", &ldouble_ctype
, 0, { &ldouble_ctype
, &ldouble_ctype
, &ldouble_ctype
}},
566 { "__builtin_frame_address", &ptr_ctype
, 0, { &uint_ctype
}},
567 { "__builtin_free", &void_ctype
, 0, { &ptr_ctype
}},
568 { "__builtin_huge_val", &double_ctype
, 0 },
569 { "__builtin_huge_valf", &float_ctype
, 0 },
570 { "__builtin_huge_vall", &ldouble_ctype
, 0 },
571 { "__builtin_index", &string_ctype
, 0, { &const_string_ctype
, &int_ctype
}},
572 { "__builtin_inf", &double_ctype
, 0 },
573 { "__builtin_inff", &float_ctype
, 0 },
574 { "__builtin_infl", &ldouble_ctype
, 0 },
575 { "__builtin_isdigit", &int_ctype
, 0, { &int_ctype
}, .op
= &isdigit_op
},
576 { "__builtin_isfinite", &int_ctype
, 1, .op
= &fp_unop_op
},
577 { "__builtin_isgreater", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
578 { "__builtin_isgreaterequal", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
579 { "__builtin_isinf", &int_ctype
, 1, .op
= &fp_unop_op
},
580 { "__builtin_isinf_sign", &int_ctype
, 1, .op
= &fp_unop_op
},
581 { "__builtin_isless", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
582 { "__builtin_islessequal", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
583 { "__builtin_islessgreater", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
584 { "__builtin_isnan", &int_ctype
, 1, .op
= &fp_unop_op
},
585 { "__builtin_isnormal", &int_ctype
, 1, .op
= &fp_unop_op
},
586 { "__builtin_isunordered", &int_ctype
, 0, { &float_ctype
, &float_ctype
}},
587 { "__builtin_labs", &long_ctype
, 0, { &long_ctype
}},
588 { "__builtin_llabs", &llong_ctype
, 0, { &llong_ctype
}},
589 { "__builtin_malloc", &ptr_ctype
, 0, { size_t_ctype
}},
590 { "__builtin_memchr", &ptr_ctype
, 0, { &const_ptr_ctype
, &int_ctype
, size_t_ctype
}},
591 { "__builtin_memcmp", &int_ctype
, 0, { &const_ptr_ctype
, &const_ptr_ctype
, size_t_ctype
}},
592 { "__builtin_memcpy", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
}},
593 { "__builtin_memmove", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
}},
594 { "__builtin_mempcpy", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
}},
595 { "__builtin_memset", &ptr_ctype
, 0, { &ptr_ctype
, &int_ctype
, size_t_ctype
}},
596 { "__builtin_mul_overflow", &bool_ctype
, 1, .op
= &overflow_op
},
597 { "__builtin_mul_overflow_p", &bool_ctype
, 1, .op
= &overflow_p_op
},
598 { "__builtin_nan", &double_ctype
, 0, { &const_string_ctype
}},
599 { "__builtin_nanf", &float_ctype
, 0, { &const_string_ctype
}},
600 { "__builtin_nanl", &ldouble_ctype
, 0, { &const_string_ctype
}},
601 { "__builtin_object_size", size_t_ctype
, 0, { &const_ptr_ctype
, &int_ctype
}},
602 { "__builtin_parity", &int_ctype
, 0, { &uint_ctype
}, .op
= &parity_op
},
603 { "__builtin_parityl", &int_ctype
, 0, { &ulong_ctype
}, .op
= &parity_op
},
604 { "__builtin_parityll", &int_ctype
, 0, { &ullong_ctype
}, .op
= &parity_op
},
605 { "__builtin_popcount", &int_ctype
, 0, { &uint_ctype
}, .op
= &popcount_op
},
606 { "__builtin_popcountl", &int_ctype
, 0, { &ulong_ctype
}, .op
= &popcount_op
},
607 { "__builtin_popcountll", &int_ctype
, 0, { &ullong_ctype
}, .op
= &popcount_op
},
608 { "__builtin_prefetch", &void_ctype
, 1, { &const_ptr_ctype
}},
609 { "__builtin_printf", &int_ctype
, 1, { &const_string_ctype
}},
610 { "__builtin_puts", &int_ctype
, 0, { &const_string_ctype
}},
611 { "__builtin_realloc", &ptr_ctype
, 0, { &ptr_ctype
, size_t_ctype
}},
612 { "__builtin_return_address", &ptr_ctype
, 0, { &uint_ctype
}},
613 { "__builtin_rindex", &string_ctype
, 0, { &const_string_ctype
, &int_ctype
}},
614 { "__builtin_sadd_overflow", &bool_ctype
, 0, { &int_ctype
, &int_ctype
, &int_ptr_ctype
}},
615 { "__builtin_saddl_overflow", &bool_ctype
, 0, { &long_ctype
, &long_ctype
, &long_ptr_ctype
}},
616 { "__builtin_saddll_overflow", &bool_ctype
, 0, { &llong_ctype
, &llong_ctype
, &llong_ptr_ctype
}},
617 { "__builtin_signbit", &int_ctype
, 1 , .op
= &fp_unop_op
},
618 { "__builtin_smul_overflow", &bool_ctype
, 0, { &int_ctype
, &int_ctype
, &int_ptr_ctype
}},
619 { "__builtin_smull_overflow", &bool_ctype
, 0, { &long_ctype
, &long_ctype
, &long_ptr_ctype
}},
620 { "__builtin_smulll_overflow", &bool_ctype
, 0, { &llong_ctype
, &llong_ctype
, &llong_ptr_ctype
}},
621 { "__builtin_snprintf", &int_ctype
, 1, { &string_ctype
, size_t_ctype
, &const_string_ctype
}},
622 { "__builtin_sprintf", &int_ctype
, 1, { &string_ctype
, &const_string_ctype
}},
623 { "__builtin_ssub_overflow", &bool_ctype
, 0, { &int_ctype
, &int_ctype
, &int_ptr_ctype
}},
624 { "__builtin_ssubl_overflow", &bool_ctype
, 0, { &long_ctype
, &long_ctype
, &long_ptr_ctype
}},
625 { "__builtin_ssubll_overflow", &bool_ctype
, 0, { &llong_ctype
, &llong_ctype
, &llong_ptr_ctype
}},
626 { "__builtin_stpcpy", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
627 { "__builtin_stpncpy", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
, size_t_ctype
}},
628 { "__builtin_strcasecmp", &int_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
629 { "__builtin_strcasestr", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
630 { "__builtin_strcat", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
}},
631 { "__builtin_strchr", &string_ctype
, 0, { &const_string_ctype
, &int_ctype
}},
632 { "__builtin_strcmp", &int_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
633 { "__builtin_strcpy", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
}},
634 { "__builtin_strcspn", size_t_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
635 { "__builtin_strdup", &string_ctype
, 0, { &const_string_ctype
}},
636 { "__builtin_strlen", size_t_ctype
, 0, { &const_string_ctype
}},
637 { "__builtin_strncasecmp", &int_ctype
, 0, { &const_string_ctype
, &const_string_ctype
, size_t_ctype
}},
638 { "__builtin_strncat", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
}},
639 { "__builtin_strncmp", &int_ctype
, 0, { &const_string_ctype
, &const_string_ctype
, size_t_ctype
}},
640 { "__builtin_strncpy", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
}},
641 { "__builtin_strndup", &string_ctype
, 0, { &const_string_ctype
, size_t_ctype
}},
642 { "__builtin_strnstr", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
, size_t_ctype
}},
643 { "__builtin_strpbrk", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
644 { "__builtin_strrchr", &string_ctype
, 0, { &const_string_ctype
, &int_ctype
}},
645 { "__builtin_strspn", size_t_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
646 { "__builtin_strstr", &string_ctype
, 0, { &const_string_ctype
, &const_string_ctype
}},
647 { "__builtin_sub_overflow", &bool_ctype
, 1, .op
= &overflow_op
},
648 { "__builtin_sub_overflow_p", &bool_ctype
, 1, .op
= &overflow_p_op
},
649 { "__builtin_trap", &void_ctype
, 0 },
650 { "__builtin_uadd_overflow", &bool_ctype
, 0, { &uint_ctype
, &uint_ctype
, &uint_ptr_ctype
}},
651 { "__builtin_uaddl_overflow", &bool_ctype
, 0, { &ulong_ctype
, &ulong_ctype
, &ulong_ptr_ctype
}},
652 { "__builtin_uaddll_overflow", &bool_ctype
, 0, { &ullong_ctype
, &ullong_ctype
, &ullong_ptr_ctype
}},
653 { "__builtin_umul_overflow", &bool_ctype
, 0, { &uint_ctype
, &uint_ctype
, &uint_ptr_ctype
}},
654 { "__builtin_umull_overflow", &bool_ctype
, 0, { &ulong_ctype
, &ulong_ctype
, &ulong_ptr_ctype
}},
655 { "__builtin_umulll_overflow", &bool_ctype
, 0, { &ullong_ctype
, &ullong_ctype
, &ullong_ptr_ctype
}},
656 { "__builtin_unreachable", &void_ctype
, 0 },
657 { "__builtin_usub_overflow", &bool_ctype
, 0, { &uint_ctype
, &uint_ctype
, &uint_ptr_ctype
}},
658 { "__builtin_usubl_overflow", &bool_ctype
, 0, { &ulong_ctype
, &ulong_ctype
, &ulong_ptr_ctype
}},
659 { "__builtin_usubll_overflow", &bool_ctype
, 0, { &ullong_ctype
, &ullong_ctype
, &ullong_ptr_ctype
}},
660 { "__builtin_va_arg_pack_len", size_t_ctype
, 0 },
661 { "__builtin_vprintf", &int_ctype
, 0, { &const_string_ctype
, va_list_ctype
}},
662 { "__builtin_vsnprintf", &int_ctype
, 0, { &string_ctype
, size_t_ctype
, &const_string_ctype
, va_list_ctype
}},
663 { "__builtin_vsprintf", &int_ctype
, 0, { &string_ctype
, &const_string_ctype
, va_list_ctype
}},
665 { "__builtin___memcpy_chk", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
, size_t_ctype
}},
666 { "__builtin___memmove_chk", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
, size_t_ctype
}},
667 { "__builtin___mempcpy_chk", &ptr_ctype
, 0, { &ptr_ctype
, &const_ptr_ctype
, size_t_ctype
, size_t_ctype
}},
668 { "__builtin___memset_chk", &ptr_ctype
, 0, { &ptr_ctype
, &int_ctype
, size_t_ctype
, size_t_ctype
}},
669 { "__builtin___snprintf_chk", &int_ctype
, 1, { &string_ctype
, size_t_ctype
, &int_ctype
, size_t_ctype
, &const_string_ctype
}},
670 { "__builtin___sprintf_chk", &int_ctype
, 1, { &string_ctype
, &int_ctype
, size_t_ctype
, &const_string_ctype
}},
671 { "__builtin___stpcpy_chk", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
}},
672 { "__builtin___strcat_chk", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
}},
673 { "__builtin___strcpy_chk", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
}},
674 { "__builtin___strncat_chk", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
, size_t_ctype
}},
675 { "__builtin___strncpy_chk", &string_ctype
, 0, { &string_ctype
, &const_string_ctype
, size_t_ctype
, size_t_ctype
}},
676 { "__builtin___vsnprintf_chk", &int_ctype
, 0, { &string_ctype
, size_t_ctype
, &int_ctype
, size_t_ctype
, &const_string_ctype
, va_list_ctype
}},
677 { "__builtin___vsprintf_chk", &int_ctype
, 0, { &string_ctype
, &int_ctype
, size_t_ctype
, &const_string_ctype
, va_list_ctype
}},
679 { "__sync_add_and_fetch", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
680 { "__sync_and_and_fetch", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
681 { "__sync_bool_compare_and_swap", &bool_ctype
, 1, { vol_ptr
, &dyntype
, &dyntype
}, .op
= &atomic_op
},
682 { "__sync_fetch_and_add", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
683 { "__sync_fetch_and_and", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
684 { "__sync_fetch_and_nand", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
685 { "__sync_fetch_and_or", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
686 { "__sync_fetch_and_sub", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
687 { "__sync_fetch_and_xor", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
688 { "__sync_lock_release", &void_ctype
, 1, { vol_ptr
}, .op
= &atomic_op
},
689 { "__sync_lock_test_and_set", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
690 { "__sync_nand_and_fetch", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
691 { "__sync_or_and_fetch", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
692 { "__sync_sub_and_fetch", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
693 { "__sync_synchronize", &void_ctype
, 1 },
694 { "__sync_val_compare_and_swap", NULL
, 1, { vol_ptr
, &dyntype
, &dyntype
}, .op
= &atomic_op
},
695 { "__sync_xor_and_fetch", NULL
, 1, { vol_ptr
, &dyntype
}, .op
= &atomic_op
},
700 void init_builtins(int stream
)
702 declare_builtins(stream
, builtins_common
);
703 declare_builtins(stream
, arch_target
->builtins
);
704 init_linearized_builtins(stream
);