1 /* This file contains the definitions and documentation for the
2 builtins used in the GNU compiler.
3 Copyright (C
) 2000, 2001 Free Software Foundation
, Inc.
5 This file is part of GCC.
7 GCC is free software
; you can redistribute it and
/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation
; either version
2, or (at your option
) any later
12 GCC is distributed in the hope that it will be useful
, but WITHOUT ANY
13 WARRANTY
; without even the implied warranty of MERCHANTABILITY or
14 FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC
; see the file COPYING. If not
, write to the Free
19 Software Foundation
, 59 Temple Place
- Suite
330, Boston
, MA
22 /* Before including this file
, you should define a macro
:
24 DEF_BUILTIN (ENUM
, NAME
, CLASS
, TYPE, LIBTYPE
, BOTH_P
,
25 FALLBACK_P
, NONANSI_P
)
27 This macro will be called once for each builtin function. The
28 ENUM will be of type `enum built_in_function
', and will indicate
29 which builtin function is being processed. The NAME of the builtin
30 function (which will always start with `__builtin_') is a string
31 literal. The CLASS is of type `enum built_in_class
' and indicates
32 what kind of builtin is being processed.
34 Some builtins are actually two separate functions. For example,
35 for `strcmp' there are two builtin functions
; `__builtin_strcmp
'
36 and `strcmp' itself. Both behave identically. Other builtins
37 define only the `__builtin
' variant. If BOTH_P is TRUE, then this
38 builtin has both variants; otherwise, it is has only the first
41 TYPE indicates the type of the function. The symbols correspond to
42 enumerals from builtin-types.def. If BOTH_P is true, then LIBTYPE
43 is the type of the non-`__builtin_' variant. Otherwise
, LIBTYPE
46 If FALLBACK_P is true then
, if for some reason
, the compiler cannot
47 expand the builtin function directly
, it will call the
48 corresponding library
function (which does not have the
51 If NONANSI_P is true, then the non-`__builtin_' variant is not an
52 ANSI
/ISO library function
, and so we should pretend it does not
53 exist when compiling in ANSI conformant mode.
*/
55 /* A GCC
builtin (like __builtin_saveregs
) is provided by the
56 compiler
, but does not correspond to a function in the standard
58 #undef DEF_GCC_BUILTIN
59 #define
DEF_GCC_BUILTIN(ENUM
, NAME
, TYPE) \
60 DEF_BUILTIN (ENUM
, NAME
, BUILT_IN_NORMAL
, TYPE, BT_LAST
, \
64 /* A fallback builtin is a
builtin (like __builtin_puts
) that falls
65 back to the corresopnding library function if necessary
-- but
66 for which we should not introduce the non
-`__builtin
' variant of
68 #undef DEF_FALLBACK_BUILTIN
69 #define DEF_FALLBACK_BUILTIN(ENUM, NAME, TYPE) \
70 DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
73 /* Like DEF_FALLBACK_BUILTIN, except that the function is not one that
74 is specified by ANSI/ISO C. So, when we're being fully conformant
75 we ignore the version of these builtins that does not begin with
77 #undef DEF_EXT_FALLBACK_BUILTIN
78 #define
DEF_EXT_FALLBACK_BUILTIN(ENUM
, NAME
, TYPE) \
79 DEF_BUILTIN (ENUM
, NAME
, BUILT_IN_NORMAL
, TYPE, TYPE, \
82 /* A library
builtin (like __builtin_strchr
) is a builtin equivalent
83 of an ANSI
/ISO standard library function. In addition to the
84 `__builtin
' version, we will create an ordinary version (e.g,
85 `strchr') as well. If we cannot compute the answer using the
86 builtin function
, we will fall back to the standard library
88 #undef DEF_LIB_BUILTIN
89 #define
DEF_LIB_BUILTIN(ENUM
, NAME
, TYPE) \
90 DEF_BUILTIN (ENUM
, NAME
, BUILT_IN_NORMAL
, TYPE, TYPE, \
93 /* Like DEF_LIB_BUILTIN
, except that a call to the builtin should
94 never fall back to the library version.
*/
95 #undef DEF_LIB_ALWAYS_BUILTIN
96 #define
DEF_LIB_ALWAYS_BUILTIN(ENUM
, NAME
, TYPE) \
97 DEF_BUILTIN (ENUM
, NAME
, BUILT_IN_NORMAL
, TYPE, TYPE, \
100 /* Like DEF_LIB_BUILTIN
, except that the function is not one that is
101 specified by ANSI
/ISO C. So
, when we
're being fully conformant we
102 ignore the version of these builtins that does not begin with
104 #undef DEF_EXT_LIB_BUILTIN
105 #define DEF_EXT_LIB_BUILTIN(ENUM, NAME, TYPE) \
106 DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
109 /* Like DEF_LIB_BUILTIN, except that the function is only a part of
110 the standard in C99 or above. */
111 #undef DEF_C99_BUILTIN
112 #define DEF_C99_BUILTIN(ENUM, NAME, TYPE) \
113 DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
114 true, !flag_isoc99, true)
116 /* Like DEF_LIB_BUILTIN, except that the function is expanded in the
118 #undef DEF_FRONT_END_LIB_BUILTIN
119 #define DEF_FRONT_END_LIB_BUILTIN(ENUM, NAME, TYPE) \
120 DEF_BUILTIN (ENUM, NAME, BUILT_IN_FRONTEND, TYPE, TYPE, \
123 /* Like DEF_FRONT_END_LIB_BUILTIN, except that the function is not one
124 that is specified by ANSI/ISO C. So, when we're being fully
125 conformant we ignore the version of these builtins that does not
126 begin with __builtin.
*/
127 #undef DEF_EXT_FRONT_END_LIB_BUILTIN
128 #define
DEF_EXT_FRONT_END_LIB_BUILTIN(ENUM
, NAME
, TYPE) \
129 DEF_BUILTIN (ENUM
, NAME
, BUILT_IN_FRONTEND
, TYPE, TYPE, \
132 /* A built
-in that is not currently used.
*/
133 #undef DEF_UNUSED_BUILTIN
134 #define
DEF_UNUSED_BUILTIN(X
) \
135 DEF_BUILTIN (X
, (const char *) NULL
, NOT_BUILT_IN
, BT_LAST
, \
136 BT_LAST
, false
, false
, false
)
138 /* If SMALL_STACK is defined
, then `alloca
' is only defined in its
141 DEF_FALLBACK_BUILTIN(BUILT_IN_ALLOCA
,
145 DEF_EXT_LIB_BUILTIN(BUILT_IN_ALLOCA
,
150 DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_ABS
,
153 DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_LABS
,
157 DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FABS
,
160 DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FABSF
,
163 DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FABSL
,
165 BT_FN_LONG_DOUBLE_LONG_DOUBLE
)
167 DEF_C99_BUILTIN(BUILT_IN_LLABS
,
169 BT_FN_LONGLONG_LONGLONG
)
170 DEF_C99_BUILTIN(BUILT_IN_IMAXABS
,
173 DEF_C99_BUILTIN(BUILT_IN_CONJ
,
175 BT_FN_COMPLEX_DOUBLE_COMPLEX_DOUBLE
)
176 DEF_C99_BUILTIN(BUILT_IN_CONJF
,
178 BT_FN_COMPLEX_FLOAT_COMPLEX_FLOAT
)
179 DEF_C99_BUILTIN(BUILT_IN_CONJL
,
181 BT_FN_COMPLEX_LONG_DOUBLE_COMPLEX_LONG_DOUBLE
)
182 DEF_C99_BUILTIN(BUILT_IN_CREAL
,
184 BT_FN_DOUBLE_COMPLEX_DOUBLE
)
185 DEF_C99_BUILTIN(BUILT_IN_CREALF
,
187 BT_FN_FLOAT_COMPLEX_FLOAT
)
188 DEF_C99_BUILTIN(BUILT_IN_CREALL
,
190 BT_FN_LONG_DOUBLE_COMPLEX_LONG_DOUBLE
)
191 DEF_C99_BUILTIN(BUILT_IN_CIMAG
,
193 BT_FN_DOUBLE_COMPLEX_DOUBLE
)
194 DEF_C99_BUILTIN(BUILT_IN_CIMAGF
,
196 BT_FN_FLOAT_COMPLEX_FLOAT
)
197 DEF_C99_BUILTIN(BUILT_IN_CIMAGL
,
199 BT_FN_LONG_DOUBLE_COMPLEX_LONG_DOUBLE
)
201 DEF_UNUSED_BUILTIN(BUILT_IN_DIV
)
202 DEF_UNUSED_BUILTIN(BUILT_IN_LDIV
)
203 DEF_UNUSED_BUILTIN(BUILT_IN_FFLOOR
)
204 DEF_UNUSED_BUILTIN(BUILT_IN_FCEIL
)
205 DEF_UNUSED_BUILTIN(BUILT_IN_FMOD
)
206 DEF_UNUSED_BUILTIN(BUILT_IN_FREM
)
208 /* The system prototypes for `bzero
' and `bcmp' functions have many
209 variations
, so don
't specify parameters to avoid conflicts. The
210 expand_* functions check the argument types anyway. */
211 DEF_BUILTIN (BUILT_IN_BZERO,
217 DEF_BUILTIN (BUILT_IN_BCMP,
220 BT_FN_INT_CONST_PTR_CONST_PTR_SIZE,
224 DEF_EXT_LIB_BUILTIN(BUILT_IN_FFS,
227 DEF_EXT_LIB_BUILTIN(BUILT_IN_INDEX,
229 BT_FN_STRING_CONST_STRING_INT)
230 DEF_EXT_LIB_BUILTIN(BUILT_IN_RINDEX,
232 BT_FN_STRING_CONST_STRING_INT)
234 DEF_LIB_BUILTIN(BUILT_IN_MEMCPY,
236 BT_FN_PTR_PTR_CONST_PTR_SIZE)
237 DEF_LIB_BUILTIN(BUILT_IN_MEMCMP,
239 BT_FN_INT_CONST_PTR_CONST_PTR_SIZE)
240 DEF_LIB_BUILTIN(BUILT_IN_MEMSET,
242 BT_FN_PTR_PTR_INT_SIZE)
244 DEF_LIB_BUILTIN(BUILT_IN_STRCAT,
246 BT_FN_STRING_STRING_CONST_STRING)
247 DEF_LIB_BUILTIN(BUILT_IN_STRNCAT,
249 BT_FN_STRING_STRING_CONST_STRING_SIZE)
250 DEF_LIB_BUILTIN(BUILT_IN_STRCPY,
252 BT_FN_STRING_STRING_CONST_STRING)
253 DEF_LIB_BUILTIN(BUILT_IN_STRNCPY,
255 BT_FN_STRING_STRING_CONST_STRING_SIZE)
256 DEF_LIB_BUILTIN(BUILT_IN_STRCMP,
258 BT_FN_INT_CONST_STRING_CONST_STRING)
259 DEF_LIB_BUILTIN(BUILT_IN_STRNCMP,
261 BT_FN_INT_CONST_STRING_CONST_STRING_SIZE)
262 DEF_LIB_BUILTIN(BUILT_IN_STRLEN,
264 BT_FN_SIZE_CONST_STRING)
265 DEF_LIB_BUILTIN(BUILT_IN_STRSTR,
267 BT_FN_STRING_CONST_STRING_CONST_STRING)
268 DEF_LIB_BUILTIN(BUILT_IN_STRPBRK,
270 BT_FN_STRING_CONST_STRING_CONST_STRING)
271 DEF_LIB_BUILTIN(BUILT_IN_STRSPN,
273 BT_FN_SIZE_CONST_STRING_CONST_STRING)
274 DEF_LIB_BUILTIN(BUILT_IN_STRCSPN,
276 BT_FN_SIZE_CONST_STRING_CONST_STRING)
277 DEF_LIB_BUILTIN(BUILT_IN_STRCHR,
279 BT_FN_STRING_CONST_STRING_INT)
280 DEF_LIB_BUILTIN(BUILT_IN_STRRCHR,
282 BT_FN_STRING_CONST_STRING_INT)
284 DEF_LIB_BUILTIN(BUILT_IN_SQRT,
287 DEF_LIB_BUILTIN(BUILT_IN_SIN,
290 DEF_LIB_BUILTIN(BUILT_IN_COS,
293 DEF_LIB_BUILTIN(BUILT_IN_SQRTF,
296 DEF_LIB_BUILTIN(BUILT_IN_SINF,
299 DEF_LIB_BUILTIN(BUILT_IN_COSF,
302 DEF_LIB_BUILTIN(BUILT_IN_SQRTL,
304 BT_FN_LONG_DOUBLE_LONG_DOUBLE)
305 DEF_LIB_BUILTIN(BUILT_IN_SINL,
307 BT_FN_LONG_DOUBLE_LONG_DOUBLE)
308 DEF_LIB_BUILTIN(BUILT_IN_COSL,
310 BT_FN_LONG_DOUBLE_LONG_DOUBLE)
312 DEF_UNUSED_BUILTIN(BUILT_IN_GETEXP)
313 DEF_UNUSED_BUILTIN(BUILT_IN_GETMAN)
315 DEF_GCC_BUILTIN(BUILT_IN_SAVEREGS,
316 "__builtin_saveregs",
318 DEF_GCC_BUILTIN(BUILT_IN_CLASSIFY_TYPE,
319 "__builtin_classify_type",
321 DEF_GCC_BUILTIN(BUILT_IN_NEXT_ARG,
322 "__builtin_next_arg",
324 DEF_GCC_BUILTIN(BUILT_IN_ARGS_INFO,
325 "__builtin_args_info",
327 DEF_GCC_BUILTIN(BUILT_IN_CONSTANT_P,
328 "__builtin_constant_p",
330 DEF_GCC_BUILTIN(BUILT_IN_FRAME_ADDRESS,
331 "__builtin_frame_address",
333 DEF_GCC_BUILTIN(BUILT_IN_RETURN_ADDRESS,
334 "__builtin_return_address",
336 DEF_GCC_BUILTIN(BUILT_IN_AGGREGATE_INCOMING_ADDRESS,
337 "__builtin_aggregate_incoming_address",
339 DEF_GCC_BUILTIN(BUILT_IN_APPLY_ARGS,
340 "__builtin_apply_args",
342 DEF_GCC_BUILTIN(BUILT_IN_APPLY,
344 BT_FN_PTR_PTR_FN_VOID_VAR_PTR_SIZE)
345 DEF_GCC_BUILTIN(BUILT_IN_RETURN,
348 DEF_GCC_BUILTIN(BUILT_IN_SETJMP,
351 DEF_GCC_BUILTIN(BUILT_IN_LONGJMP,
354 DEF_GCC_BUILTIN(BUILT_IN_TRAP,
357 DEF_GCC_BUILTIN(BUILT_IN_PREFETCH,
358 "__builtin_prefetch",
359 BT_FN_VOID_CONST_PTR_VAR)
361 /* Stdio builtins. */
362 DEF_FALLBACK_BUILTIN(BUILT_IN_PUTCHAR,
365 DEF_FALLBACK_BUILTIN(BUILT_IN_PUTS,
367 BT_FN_INT_CONST_STRING)
368 DEF_FRONT_END_LIB_BUILTIN(BUILT_IN_PRINTF,
370 BT_FN_INT_CONST_STRING_VAR)
371 DEF_FALLBACK_BUILTIN(BUILT_IN_FPUTC,
374 /* Declare the __builtin_ style with arguments and the regular style
375 without them. We rely on stdio.h to supply the arguments for the
376 regular style declaration since we had to use void* instead of
377 FILE* in the __builtin_ prototype supplied here. */
378 DEF_BUILTIN (BUILT_IN_FPUTS,
381 BT_FN_INT_CONST_STRING_PTR,
384 DEF_FALLBACK_BUILTIN(BUILT_IN_FWRITE,
386 BT_FN_SIZE_CONST_PTR_SIZE_SIZE_PTR)
387 DEF_FRONT_END_LIB_BUILTIN(BUILT_IN_FPRINTF,
389 BT_FN_INT_PTR_CONST_STRING_VAR)
391 /* Stdio unlocked builtins. */
393 DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_PUTCHAR_UNLOCKED,
394 "__builtin_putchar_unlocked",
396 DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_PUTS_UNLOCKED,
397 "__builtin_puts_unlocked",
398 BT_FN_INT_CONST_STRING)
399 DEF_EXT_FRONT_END_LIB_BUILTIN(BUILT_IN_PRINTF_UNLOCKED,
400 "__builtin_printf_unlocked",
401 BT_FN_INT_CONST_STRING_VAR)
402 DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_FPUTC_UNLOCKED,
403 "__builtin_fputc_unlocked",
405 /* Declare the __builtin_ style with arguments and the regular style
406 without them. We rely on stdio.h to supply the arguments for the
407 regular style declaration since we had to use void* instead of
408 FILE* in the __builtin_ prototype supplied here. */
409 DEF_BUILTIN (BUILT_IN_FPUTS_UNLOCKED,
410 "__builtin_fputs_unlocked",
412 BT_FN_INT_CONST_STRING_PTR,
415 DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_FWRITE_UNLOCKED,
416 "__builtin_fwrite_unlocked",
417 BT_FN_SIZE_CONST_PTR_SIZE_SIZE_PTR)
418 DEF_EXT_FRONT_END_LIB_BUILTIN(BUILT_IN_FPRINTF_UNLOCKED,
419 "__builtin_fprintf_unlocked",
420 BT_FN_INT_PTR_CONST_STRING_VAR)
422 /* ISO C99 floating point unordered comparisons. */
423 DEF_GCC_BUILTIN(BUILT_IN_ISGREATER,
424 "__builtin_isgreater",
426 DEF_GCC_BUILTIN(BUILT_IN_ISGREATEREQUAL,
427 "__builtin_isgreaterequal",
429 DEF_GCC_BUILTIN(BUILT_IN_ISLESS,
432 DEF_GCC_BUILTIN(BUILT_IN_ISLESSEQUAL,
433 "__builtin_islessequal",
435 DEF_GCC_BUILTIN(BUILT_IN_ISLESSGREATER,
436 "__builtin_islessgreater",
438 DEF_GCC_BUILTIN(BUILT_IN_ISUNORDERED,
439 "__builtin_isunordered",
442 /* Various hooks for the DWARF 2 __throw routine. */
443 DEF_GCC_BUILTIN(BUILT_IN_UNWIND_INIT,
444 "__builtin_unwind_init",
446 DEF_GCC_BUILTIN(BUILT_IN_DWARF_CFA,
447 "__builtin_dwarf_cfa",
449 DEF_GCC_BUILTIN(BUILT_IN_DWARF_FP_REGNUM,
450 "__builtin_dwarf_fp_regnum",
452 DEF_GCC_BUILTIN(BUILT_IN_INIT_DWARF_REG_SIZES,
453 "__builtin_init_dwarf_reg_size_table",
455 DEF_GCC_BUILTIN(BUILT_IN_FROB_RETURN_ADDR,
456 "__builtin_frob_return_addr",
458 DEF_GCC_BUILTIN(BUILT_IN_EXTRACT_RETURN_ADDR,
459 "__builtin_extract_return_addr",
461 DEF_GCC_BUILTIN(BUILT_IN_EH_RETURN,
462 "__builtin_eh_return",
463 BT_FN_VOID_PTRMODE_PTR)
464 DEF_GCC_BUILTIN(BUILT_IN_EH_RETURN_DATA_REGNO,
465 "__builtin_eh_return_data_regno",
468 DEF_GCC_BUILTIN(BUILT_IN_VARARGS_START,
469 "__builtin_varargs_start",
470 BT_FN_VOID_VALIST_REF)
471 DEF_GCC_BUILTIN(BUILT_IN_STDARG_START,
472 "__builtin_stdarg_start",
473 BT_FN_VOID_VALIST_REF_VAR)
474 DEF_GCC_BUILTIN(BUILT_IN_VA_END,
476 BT_FN_VOID_VALIST_REF)
477 DEF_GCC_BUILTIN(BUILT_IN_VA_COPY,
479 BT_FN_VOID_VALIST_REF_VALIST_ARG)
480 DEF_GCC_BUILTIN(BUILT_IN_EXPECT,
482 BT_FN_LONG_LONG_LONG)
485 DEF_UNUSED_BUILTIN(BUILT_IN_NEW)
486 DEF_UNUSED_BUILTIN(BUILT_IN_VEC_NEW)
487 DEF_UNUSED_BUILTIN(BUILT_IN_DELETE)
488 DEF_UNUSED_BUILTIN(BUILT_IN_VEC_DELETE)