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 GNU CC.
7 GNU CC is free software
; you can redistribute it and
/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation
; either version
2, or (at your option
)
12 GNU CC is distributed in the hope that it will be useful
,
13 but WITHOUT ANY WARRANTY
; without even the implied warranty of
14 MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC
; see the file COPYING. If not
, write to
19 the Free Software Foundation
, 59 Temple Place
- Suite
330,
20 Boston
, MA
02111-1307, USA.
*/
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 /* A library builtin (like __builtin_strchr) is a builtin equivalent
74 of an ANSI/ISO standard library function. In addition to the
75 `__builtin' version
, we will create a an ordinary
version (e.g
,
76 `strchr
') as well. If we cannot compute the answer using the
77 builtin function, we will fall back to the standard library
79 #undef DEF_LIB_BUILTIN
80 #define DEF_LIB_BUILTIN(ENUM, NAME, TYPE) \
81 DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
84 /* Like DEF_LIB_BUILTIN, except that a call to the builtin should
85 never fall back to the library version. */
86 #undef DEF_LIB_ALWAYS_BUILTIN
87 #define DEF_LIB_ALWAYS_BUILTIN(ENUM, NAME, TYPE) \
88 DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
91 /* Like DEF_LIB_BUILTIN, except that the function is not one that is
92 specified by ANSI/ISO C. So, when we're being fully conformant we
93 ignore the version of these builtins that does not begin with
95 #undef DEF_EXT_LIB_BUILTIN
96 #define
DEF_EXT_LIB_BUILTIN(ENUM
, NAME
, TYPE) \
97 DEF_BUILTIN (ENUM
, NAME
, BUILT_IN_NORMAL
, TYPE, TYPE, \
100 /* Like DEF_LIB_BUILTIN
, except that the function is only a part of
101 the standard in C99 or above.
*/
102 #undef DEF_C99_BUILTIN
103 #define
DEF_C99_BUILTIN(ENUM
, NAME
, TYPE) \
104 DEF_BUILTIN (ENUM
, NAME
, BUILT_IN_NORMAL
, TYPE, TYPE, \
105 true
, !flag_isoc99
, true
)
107 /* Like DEF_LIB_BUILTIN
, except that the function is expanded in the
109 #undef DEF_FRONT_END_LIB_BUILTIN
110 #define
DEF_FRONT_END_LIB_BUILTIN(ENUM
, NAME
, TYPE) \
111 DEF_BUILTIN (ENUM
, NAME
, BUILT_IN_FRONTEND
, TYPE, TYPE, \
114 /* A built
-in that is not currently used.
*/
115 #undef DEF_UNUSED_BUILTIN
116 #define
DEF_UNUSED_BUILTIN(X
) \
117 DEF_BUILTIN (X
, (const char *) NULL
, NOT_BUILT_IN
, BT_LAST
, \
118 BT_LAST
, false
, false
, false
)
120 /* If SMALL_STACK is defined
, then `alloca
' is only defined in its
123 DEF_FALLBACK_BUILTIN(BUILT_IN_ALLOCA
,
127 DEF_EXT_LIB_BUILTIN(BUILT_IN_ALLOCA
,
132 DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_ABS
,
135 DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_LABS
,
139 DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FABS
,
142 DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FABSF
,
145 DEF_LIB_ALWAYS_BUILTIN(BUILT_IN_FABSL
,
147 BT_FN_LONG_DOUBLE_LONG_DOUBLE
)
149 DEF_C99_BUILTIN(BUILT_IN_LLABS
,
151 BT_FN_LONGLONG_LONGLONG
)
152 DEF_C99_BUILTIN(BUILT_IN_IMAXABS
,
155 DEF_C99_BUILTIN(BUILT_IN_CONJ
,
157 BT_FN_COMPLEX_DOUBLE_COMPLEX_DOUBLE
)
158 DEF_C99_BUILTIN(BUILT_IN_CONJF
,
160 BT_FN_COMPLEX_FLOAT_COMPLEX_FLOAT
)
161 DEF_C99_BUILTIN(BUILT_IN_CONJL
,
163 BT_FN_COMPLEX_LONG_DOUBLE_COMPLEX_LONG_DOUBLE
)
164 DEF_C99_BUILTIN(BUILT_IN_CREAL
,
166 BT_FN_DOUBLE_COMPLEX_DOUBLE
)
167 DEF_C99_BUILTIN(BUILT_IN_CREALF
,
169 BT_FN_FLOAT_COMPLEX_FLOAT
)
170 DEF_C99_BUILTIN(BUILT_IN_CREALL
,
172 BT_FN_LONG_DOUBLE_COMPLEX_LONG_DOUBLE
)
173 DEF_C99_BUILTIN(BUILT_IN_CIMAG
,
175 BT_FN_DOUBLE_COMPLEX_DOUBLE
)
176 DEF_C99_BUILTIN(BUILT_IN_CIMAGF
,
178 BT_FN_FLOAT_COMPLEX_FLOAT
)
179 DEF_C99_BUILTIN(BUILT_IN_CIMAGL
,
181 BT_FN_LONG_DOUBLE_COMPLEX_LONG_DOUBLE
)
183 DEF_UNUSED_BUILTIN(BUILT_IN_DIV
)
184 DEF_UNUSED_BUILTIN(BUILT_IN_LDIV
)
185 DEF_UNUSED_BUILTIN(BUILT_IN_FFLOOR
)
186 DEF_UNUSED_BUILTIN(BUILT_IN_FCEIL
)
187 DEF_UNUSED_BUILTIN(BUILT_IN_FMOD
)
188 DEF_UNUSED_BUILTIN(BUILT_IN_FREM
)
190 /* The system prototypes for `bzero
' and `bcmp' functions have many
191 variations
, so don
't specify parameters to avoid conflicts. The
192 expand_* functions check the argument types anyway. */
193 DEF_BUILTIN (BUILT_IN_BZERO,
196 BT_FN_VOID_TRAD_PTR_LEN,
199 DEF_BUILTIN (BUILT_IN_BCMP,
202 BT_FN_INT_TRAD_CONST_PTR_TRAD_CONST_PTR_LEN,
206 DEF_EXT_LIB_BUILTIN(BUILT_IN_FFS,
209 DEF_EXT_LIB_BUILTIN(BUILT_IN_INDEX,
211 BT_FN_STRING_CONST_STRING_INT)
212 DEF_EXT_LIB_BUILTIN(BUILT_IN_RINDEX,
214 BT_FN_STRING_CONST_STRING_INT)
216 DEF_LIB_BUILTIN(BUILT_IN_MEMCPY,
218 BT_FN_TRAD_PTR_PTR_CONST_PTR_SIZE)
219 DEF_LIB_BUILTIN(BUILT_IN_MEMCMP,
221 BT_FN_INT_CONST_PTR_CONST_PTR_SIZE)
222 DEF_LIB_BUILTIN(BUILT_IN_MEMSET,
224 BT_FN_TRAD_PTR_PTR_INT_SIZE)
226 DEF_LIB_BUILTIN(BUILT_IN_STRCAT,
228 BT_FN_STRING_STRING_CONST_STRING)
229 DEF_LIB_BUILTIN(BUILT_IN_STRNCAT,
231 BT_FN_STRING_STRING_CONST_STRING_SIZE)
232 DEF_LIB_BUILTIN(BUILT_IN_STRCPY,
234 BT_FN_STRING_STRING_CONST_STRING)
235 DEF_LIB_BUILTIN(BUILT_IN_STRNCPY,
237 BT_FN_STRING_STRING_CONST_STRING_SIZE)
238 DEF_LIB_BUILTIN(BUILT_IN_STRCMP,
240 BT_FN_INT_CONST_STRING_CONST_STRING)
241 DEF_LIB_BUILTIN(BUILT_IN_STRNCMP,
243 BT_FN_INT_CONST_STRING_CONST_STRING_SIZE)
244 DEF_LIB_BUILTIN(BUILT_IN_STRLEN,
246 BT_FN_LEN_CONST_STRING)
247 DEF_LIB_BUILTIN(BUILT_IN_STRSTR,
249 BT_FN_STRING_CONST_STRING_CONST_STRING)
250 DEF_LIB_BUILTIN(BUILT_IN_STRPBRK,
252 BT_FN_STRING_CONST_STRING_CONST_STRING)
253 DEF_LIB_BUILTIN(BUILT_IN_STRSPN,
255 BT_FN_SIZE_CONST_STRING_CONST_STRING)
256 DEF_LIB_BUILTIN(BUILT_IN_STRCSPN,
258 BT_FN_SIZE_CONST_STRING_CONST_STRING)
259 DEF_LIB_BUILTIN(BUILT_IN_STRCHR,
261 BT_FN_STRING_CONST_STRING_INT)
262 DEF_LIB_BUILTIN(BUILT_IN_STRRCHR,
264 BT_FN_STRING_CONST_STRING_INT)
266 DEF_LIB_BUILTIN(BUILT_IN_FSQRT,
269 DEF_LIB_BUILTIN(BUILT_IN_SIN,
272 DEF_LIB_BUILTIN(BUILT_IN_COS,
275 DEF_LIB_BUILTIN(BUILT_IN_SQRTF,
278 DEF_LIB_BUILTIN(BUILT_IN_SINF,
281 DEF_LIB_BUILTIN(BUILT_IN_COSF,
283 BT_FN_LONG_DOUBLE_LONG_DOUBLE)
284 DEF_LIB_BUILTIN(BUILT_IN_SQRTL,
286 BT_FN_LONG_DOUBLE_LONG_DOUBLE)
287 DEF_LIB_BUILTIN(BUILT_IN_SINL,
289 BT_FN_LONG_DOUBLE_LONG_DOUBLE)
290 DEF_LIB_BUILTIN(BUILT_IN_COSL,
292 BT_FN_LONG_DOUBLE_LONG_DOUBLE)
294 DEF_UNUSED_BUILTIN(BUILT_IN_GETEXP)
295 DEF_UNUSED_BUILTIN(BUILT_IN_GETMAN)
297 DEF_GCC_BUILTIN(BUILT_IN_SAVEREGS,
298 "__builtin_saveregs",
300 DEF_GCC_BUILTIN(BUILT_IN_CLASSIFY_TYPE,
301 "__builtin_classify_type",
303 DEF_GCC_BUILTIN(BUILT_IN_NEXT_ARG,
304 "__builtin_next_arg",
306 DEF_GCC_BUILTIN(BUILT_IN_ARGS_INFO,
307 "__builtin_args_info",
309 DEF_GCC_BUILTIN(BUILT_IN_CONSTANT_P,
310 "__builtin_constant_p",
312 DEF_GCC_BUILTIN(BUILT_IN_FRAME_ADDRESS,
313 "__builtin_frame_address",
315 DEF_GCC_BUILTIN(BUILT_IN_RETURN_ADDRESS,
316 "__builtin_return_address",
318 DEF_GCC_BUILTIN(BUILT_IN_AGGREGATE_INCOMING_ADDRESS,
319 "__builtin_aggregate_incoming_address",
321 DEF_GCC_BUILTIN(BUILT_IN_APPLY_ARGS,
322 "__builtin_apply_args",
324 DEF_GCC_BUILTIN(BUILT_IN_APPLY,
326 BT_FN_PTR_PTR_FN_VOID_VAR_PTR_SIZE)
327 DEF_GCC_BUILTIN(BUILT_IN_RETURN,
330 DEF_GCC_BUILTIN(BUILT_IN_SETJMP,
333 DEF_GCC_BUILTIN(BUILT_IN_LONGJMP,
336 DEF_GCC_BUILTIN(BUILT_IN_TRAP,
340 /* Stdio builtins. */
341 DEF_FALLBACK_BUILTIN(BUILT_IN_PUTCHAR,
344 DEF_FALLBACK_BUILTIN(BUILT_IN_PUTS,
346 BT_FN_INT_CONST_STRING)
347 DEF_FRONT_END_LIB_BUILTIN(BUILT_IN_PRINTF,
349 BT_FN_INT_CONST_STRING_VAR)
350 DEF_FALLBACK_BUILTIN(BUILT_IN_FPUTC,
353 /* Declare the __builtin_ style with arguments and the regular style
354 without them. We rely on stdio.h to supply the arguments for the
355 regular style declaration since we had to use void* instead of
356 FILE* in the __builtin_ prototype supplied here. */
357 DEF_BUILTIN (BUILT_IN_FPUTS,
360 BT_FN_INT_CONST_STRING_PTR,
363 DEF_FALLBACK_BUILTIN(BUILT_IN_FWRITE,
365 BT_FN_SIZE_CONST_PTR_SIZE_SIZE_PTR)
366 DEF_FRONT_END_LIB_BUILTIN(BUILT_IN_FPRINTF,
368 BT_FN_INT_PTR_CONST_STRING_VAR)
370 /* ISO C99 floating point unordered comparisons. */
371 DEF_GCC_BUILTIN(BUILT_IN_ISGREATER,
372 "__builtin_isgreater",
374 DEF_GCC_BUILTIN(BUILT_IN_ISGREATEREQUAL,
375 "__builtin_isgreaterequal",
377 DEF_GCC_BUILTIN(BUILT_IN_ISLESS,
380 DEF_GCC_BUILTIN(BUILT_IN_ISLESSEQUAL,
381 "__builtin_islessequal",
383 DEF_GCC_BUILTIN(BUILT_IN_ISLESSGREATER,
384 "__builtin_islessgreater",
386 DEF_GCC_BUILTIN(BUILT_IN_ISUNORDERED,
387 "__builtin_isunordered",
390 /* Various hooks for the DWARF 2 __throw routine. */
391 DEF_GCC_BUILTIN(BUILT_IN_UNWIND_INIT,
392 "__builtin_unwind_init",
394 DEF_GCC_BUILTIN(BUILT_IN_DWARF_CFA,
395 "__builtin_dwarf_cfa",
397 DEF_GCC_BUILTIN(BUILT_IN_DWARF_FP_REGNUM,
398 "__builtin_dwarf_fp_regnum",
400 DEF_GCC_BUILTIN(BUILT_IN_INIT_DWARF_REG_SIZES,
401 "__builtin_init_dwarf_reg_size_table",
403 DEF_GCC_BUILTIN(BUILT_IN_FROB_RETURN_ADDR,
404 "__builtin_frob_return_addr",
406 DEF_GCC_BUILTIN(BUILT_IN_EXTRACT_RETURN_ADDR,
407 "__builtin_extract_return_addr",
409 DEF_GCC_BUILTIN(BUILT_IN_EH_RETURN,
410 "__builtin_eh_return",
411 BT_FN_VOID_PTRMODE_PTR)
412 DEF_GCC_BUILTIN(BUILT_IN_EH_RETURN_DATA_REGNO,
413 "__builtin_eh_return_data_regno",
416 DEF_GCC_BUILTIN(BUILT_IN_VARARGS_START,
417 "__builtin_varargs_start",
418 BT_FN_VOID_VALIST_REF)
419 DEF_GCC_BUILTIN(BUILT_IN_STDARG_START,
420 "__builtin_stdarg_start",
421 BT_FN_VOID_VALIST_REF_VAR)
422 DEF_GCC_BUILTIN(BUILT_IN_VA_END,
424 BT_FN_VOID_VALIST_REF)
425 DEF_GCC_BUILTIN(BUILT_IN_VA_COPY,
427 BT_FN_VOID_VALIST_REF_VALIST_ARG)
428 DEF_GCC_BUILTIN(BUILT_IN_EXPECT,
430 BT_FN_LONG_LONG_LONG)
433 DEF_UNUSED_BUILTIN(BUILT_IN_NEW)
434 DEF_UNUSED_BUILTIN(BUILT_IN_VEC_NEW)
435 DEF_UNUSED_BUILTIN(BUILT_IN_DELETE)
436 DEF_UNUSED_BUILTIN(BUILT_IN_VEC_DELETE)