svn merge -r 216846:217483 svn+ssh://gcc.gnu.org/svn/gcc/trunk
[official-gcc.git] / gcc / fortran / f95-lang.c
blob20ba36478a47ce52281a4ebec62c9897a62508b4
1 /* gfortran backend interface
2 Copyright (C) 2000-2014 Free Software Foundation, Inc.
3 Contributed by Paul Brook.
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 3, or (at your option) any later
10 version.
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
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* f95-lang.c-- GCC backend interface stuff */
23 /* declare required prototypes: */
25 #include "config.h"
26 #include "system.h"
27 #include "ansidecl.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "gfortran.h"
31 #include "tree.h"
32 #include "flags.h"
33 #include "langhooks.h"
34 #include "langhooks-def.h"
35 #include "timevar.h"
36 #include "tm.h"
37 #include "hashtab.h"
38 #include "hash-set.h"
39 #include "vec.h"
40 #include "machmode.h"
41 #include "hard-reg-set.h"
42 #include "input.h"
43 #include "function.h"
44 #include "ggc.h"
45 #include "toplev.h"
46 #include "target.h"
47 #include "debug.h"
48 #include "diagnostic.h" /* For errorcount/warningcount */
49 #include "dumpfile.h"
50 #include "hash-map.h"
51 #include "is-a.h"
52 #include "plugin-api.h"
53 #include "ipa-ref.h"
54 #include "cgraph.h"
55 #include "cpp.h"
56 #include "trans.h"
57 #include "trans-types.h"
58 #include "trans-const.h"
60 /* Language-dependent contents of an identifier. */
62 struct GTY(())
63 lang_identifier {
64 struct tree_identifier common;
67 /* The resulting tree type. */
69 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
70 chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
71 lang_tree_node {
72 union tree_node GTY((tag ("0"),
73 desc ("tree_node_structure (&%h)"))) generic;
74 struct lang_identifier GTY((tag ("1"))) identifier;
77 /* Save and restore the variables in this file and elsewhere
78 that keep track of the progress of compilation of the current function.
79 Used for nested functions. */
81 struct GTY(())
82 language_function {
83 /* struct gfc_language_function base; */
84 struct binding_level *binding_level;
87 static void gfc_init_decl_processing (void);
88 static void gfc_init_builtin_functions (void);
89 static bool global_bindings_p (void);
91 /* Each front end provides its own. */
92 static bool gfc_init (void);
93 static void gfc_finish (void);
94 static void gfc_write_global_declarations (void);
95 static void gfc_be_parse_file (void);
96 static alias_set_type gfc_get_alias_set (tree);
97 static void gfc_init_ts (void);
98 static tree gfc_builtin_function (tree);
100 /* Handle an "omp declare target" attribute; arguments as in
101 struct attribute_spec.handler. */
102 static tree
103 gfc_handle_omp_declare_target_attribute (tree *, tree, tree, int, bool *)
105 return NULL_TREE;
108 /* Table of valid Fortran attributes. */
109 static const struct attribute_spec gfc_attribute_table[] =
111 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
112 affects_type_identity } */
113 { "omp declare target", 0, 0, true, false, false,
114 gfc_handle_omp_declare_target_attribute, false },
115 { NULL, 0, 0, false, false, false, NULL, false }
118 #undef LANG_HOOKS_NAME
119 #undef LANG_HOOKS_INIT
120 #undef LANG_HOOKS_FINISH
121 #undef LANG_HOOKS_WRITE_GLOBALS
122 #undef LANG_HOOKS_OPTION_LANG_MASK
123 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
124 #undef LANG_HOOKS_INIT_OPTIONS
125 #undef LANG_HOOKS_HANDLE_OPTION
126 #undef LANG_HOOKS_POST_OPTIONS
127 #undef LANG_HOOKS_PARSE_FILE
128 #undef LANG_HOOKS_MARK_ADDRESSABLE
129 #undef LANG_HOOKS_TYPE_FOR_MODE
130 #undef LANG_HOOKS_TYPE_FOR_SIZE
131 #undef LANG_HOOKS_GET_ALIAS_SET
132 #undef LANG_HOOKS_INIT_TS
133 #undef LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE
134 #undef LANG_HOOKS_OMP_PREDETERMINED_SHARING
135 #undef LANG_HOOKS_OMP_REPORT_DECL
136 #undef LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR
137 #undef LANG_HOOKS_OMP_CLAUSE_COPY_CTOR
138 #undef LANG_HOOKS_OMP_CLAUSE_ASSIGN_OP
139 #undef LANG_HOOKS_OMP_CLAUSE_LINEAR_CTOR
140 #undef LANG_HOOKS_OMP_CLAUSE_DTOR
141 #undef LANG_HOOKS_OMP_FINISH_CLAUSE
142 #undef LANG_HOOKS_OMP_DISREGARD_VALUE_EXPR
143 #undef LANG_HOOKS_OMP_PRIVATE_DEBUG_CLAUSE
144 #undef LANG_HOOKS_OMP_PRIVATE_OUTER_REF
145 #undef LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES
146 #undef LANG_HOOKS_BUILTIN_FUNCTION
147 #undef LANG_HOOKS_BUILTIN_FUNCTION
148 #undef LANG_HOOKS_GET_ARRAY_DESCR_INFO
149 #undef LANG_HOOKS_ATTRIBUTE_TABLE
151 /* Define lang hooks. */
152 #define LANG_HOOKS_NAME "GNU Fortran"
153 #define LANG_HOOKS_INIT gfc_init
154 #define LANG_HOOKS_FINISH gfc_finish
155 #define LANG_HOOKS_WRITE_GLOBALS gfc_write_global_declarations
156 #define LANG_HOOKS_OPTION_LANG_MASK gfc_option_lang_mask
157 #define LANG_HOOKS_INIT_OPTIONS_STRUCT gfc_init_options_struct
158 #define LANG_HOOKS_INIT_OPTIONS gfc_init_options
159 #define LANG_HOOKS_HANDLE_OPTION gfc_handle_option
160 #define LANG_HOOKS_POST_OPTIONS gfc_post_options
161 #define LANG_HOOKS_PARSE_FILE gfc_be_parse_file
162 #define LANG_HOOKS_TYPE_FOR_MODE gfc_type_for_mode
163 #define LANG_HOOKS_TYPE_FOR_SIZE gfc_type_for_size
164 #define LANG_HOOKS_GET_ALIAS_SET gfc_get_alias_set
165 #define LANG_HOOKS_INIT_TS gfc_init_ts
166 #define LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE gfc_omp_privatize_by_reference
167 #define LANG_HOOKS_OMP_PREDETERMINED_SHARING gfc_omp_predetermined_sharing
168 #define LANG_HOOKS_OMP_REPORT_DECL gfc_omp_report_decl
169 #define LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR gfc_omp_clause_default_ctor
170 #define LANG_HOOKS_OMP_CLAUSE_COPY_CTOR gfc_omp_clause_copy_ctor
171 #define LANG_HOOKS_OMP_CLAUSE_ASSIGN_OP gfc_omp_clause_assign_op
172 #define LANG_HOOKS_OMP_CLAUSE_LINEAR_CTOR gfc_omp_clause_linear_ctor
173 #define LANG_HOOKS_OMP_CLAUSE_DTOR gfc_omp_clause_dtor
174 #define LANG_HOOKS_OMP_FINISH_CLAUSE gfc_omp_finish_clause
175 #define LANG_HOOKS_OMP_DISREGARD_VALUE_EXPR gfc_omp_disregard_value_expr
176 #define LANG_HOOKS_OMP_PRIVATE_DEBUG_CLAUSE gfc_omp_private_debug_clause
177 #define LANG_HOOKS_OMP_PRIVATE_OUTER_REF gfc_omp_private_outer_ref
178 #define LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES \
179 gfc_omp_firstprivatize_type_sizes
180 #define LANG_HOOKS_BUILTIN_FUNCTION gfc_builtin_function
181 #define LANG_HOOKS_GET_ARRAY_DESCR_INFO gfc_get_array_descr_info
182 #define LANG_HOOKS_ATTRIBUTE_TABLE gfc_attribute_table
184 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
186 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
188 /* A chain of binding_level structures awaiting reuse. */
190 static GTY(()) struct binding_level *free_binding_level;
192 /* True means we've initialized exception handling. */
193 static bool gfc_eh_initialized_p;
195 /* The current translation unit. */
196 static GTY(()) tree current_translation_unit;
199 static void
200 gfc_create_decls (void)
202 /* GCC builtins. */
203 gfc_init_builtin_functions ();
205 /* Runtime/IO library functions. */
206 gfc_build_builtin_function_decls ();
208 gfc_init_constants ();
210 /* Build our translation-unit decl. */
211 current_translation_unit = build_translation_unit_decl (NULL_TREE);
215 static void
216 gfc_be_parse_file (void)
218 int errors;
219 int warnings;
221 gfc_create_decls ();
222 gfc_parse_file ();
223 gfc_generate_constructors ();
225 /* Tell the frontend about any errors. */
226 gfc_get_errors (&warnings, &errors);
227 errorcount += errors;
228 warningcount += warnings;
230 /* Clear the binding level stack. */
231 while (!global_bindings_p ())
232 poplevel (0, 0);
234 /* Switch to the default tree diagnostics here, because there may be
235 diagnostics before gfc_finish(). */
236 gfc_diagnostics_finish ();
240 /* Initialize everything. */
242 static bool
243 gfc_init (void)
245 if (!gfc_cpp_enabled ())
247 linemap_add (line_table, LC_ENTER, false, gfc_source_file, 1);
248 linemap_add (line_table, LC_RENAME, false, "<built-in>", 0);
250 else
251 gfc_cpp_init_0 ();
253 gfc_init_decl_processing ();
254 gfc_static_ctors = NULL_TREE;
256 if (gfc_cpp_enabled ())
257 gfc_cpp_init ();
259 gfc_init_1 ();
261 if (!gfc_new_file ())
262 fatal_error ("can't open input file: %s", gfc_source_file);
264 if (flag_preprocess_only)
265 return false;
267 return true;
271 static void
272 gfc_finish (void)
274 gfc_cpp_done ();
275 gfc_done_1 ();
276 gfc_release_include_path ();
277 return;
280 /* ??? This is something of a hack.
282 Emulated tls lowering needs to see all TLS variables before we call
283 finalize_compilation_unit. The C/C++ front ends manage this
284 by calling decl_rest_of_compilation on each global and static variable
285 as they are seen. The Fortran front end waits until this hook.
287 A Correct solution is for finalize_compilation_unit not to be
288 called during the WRITE_GLOBALS langhook, and have that hook only do what
289 its name suggests and write out globals. But the C++ and Java front ends
290 have (unspecified) problems with aliases that gets in the way. It has
291 been suggested that these problems would be solved by completing the
292 conversion to cgraph-based aliases. */
294 static void
295 gfc_write_global_declarations (void)
297 tree decl;
299 /* Finalize all of the globals. */
300 for (decl = getdecls(); decl ; decl = DECL_CHAIN (decl))
301 rest_of_decl_compilation (decl, true, true);
303 write_global_declarations ();
306 /* These functions and variables deal with binding contours. We only
307 need these functions for the list of PARM_DECLs, but we leave the
308 functions more general; these are a simplified version of the
309 functions from GNAT. */
311 /* For each binding contour we allocate a binding_level structure which
312 records the entities defined or declared in that contour. Contours
313 include:
315 the global one
316 one for each subprogram definition
317 one for each compound statement (declare block)
319 Binding contours are used to create GCC tree BLOCK nodes. */
321 struct GTY(())
322 binding_level {
323 /* A chain of ..._DECL nodes for all variables, constants, functions,
324 parameters and type declarations. These ..._DECL nodes are chained
325 through the DECL_CHAIN field. */
326 tree names;
327 /* For each level (except the global one), a chain of BLOCK nodes for all
328 the levels that were entered and exited one level down from this one. */
329 tree blocks;
330 /* The binding level containing this one (the enclosing binding level). */
331 struct binding_level *level_chain;
334 /* The binding level currently in effect. */
335 static GTY(()) struct binding_level *current_binding_level = NULL;
337 /* The outermost binding level. This binding level is created when the
338 compiler is started and it will exist through the entire compilation. */
339 static GTY(()) struct binding_level *global_binding_level;
341 /* Binding level structures are initialized by copying this one. */
342 static struct binding_level clear_binding_level = { NULL, NULL, NULL };
345 /* Return true if we are in the global binding level. */
347 bool
348 global_bindings_p (void)
350 return current_binding_level == global_binding_level;
353 tree
354 getdecls (void)
356 return current_binding_level->names;
359 /* Enter a new binding level. */
361 void
362 pushlevel (void)
364 struct binding_level *newlevel = ggc_alloc<binding_level> ();
366 *newlevel = clear_binding_level;
368 /* Add this level to the front of the chain (stack) of levels that are
369 active. */
370 newlevel->level_chain = current_binding_level;
371 current_binding_level = newlevel;
374 /* Exit a binding level.
375 Pop the level off, and restore the state of the identifier-decl mappings
376 that were in effect when this level was entered.
378 If KEEP is nonzero, this level had explicit declarations, so
379 and create a "block" (a BLOCK node) for the level
380 to record its declarations and subblocks for symbol table output.
382 If FUNCTIONBODY is nonzero, this level is the body of a function,
383 so create a block as if KEEP were set and also clear out all
384 label names. */
386 tree
387 poplevel (int keep, int functionbody)
389 /* Points to a BLOCK tree node. This is the BLOCK node constructed for the
390 binding level that we are about to exit and which is returned by this
391 routine. */
392 tree block_node = NULL_TREE;
393 tree decl_chain = current_binding_level->names;
394 tree subblock_chain = current_binding_level->blocks;
395 tree subblock_node;
397 /* If there were any declarations in the current binding level, or if this
398 binding level is a function body, or if there are any nested blocks then
399 create a BLOCK node to record them for the life of this function. */
400 if (keep || functionbody)
401 block_node = build_block (keep ? decl_chain : 0, subblock_chain, 0, 0);
403 /* Record the BLOCK node just built as the subblock its enclosing scope. */
404 for (subblock_node = subblock_chain; subblock_node;
405 subblock_node = BLOCK_CHAIN (subblock_node))
406 BLOCK_SUPERCONTEXT (subblock_node) = block_node;
408 /* Clear out the meanings of the local variables of this level. */
410 for (subblock_node = decl_chain; subblock_node;
411 subblock_node = DECL_CHAIN (subblock_node))
412 if (DECL_NAME (subblock_node) != 0)
413 /* If the identifier was used or addressed via a local extern decl,
414 don't forget that fact. */
415 if (DECL_EXTERNAL (subblock_node))
417 if (TREE_USED (subblock_node))
418 TREE_USED (DECL_NAME (subblock_node)) = 1;
419 if (TREE_ADDRESSABLE (subblock_node))
420 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (subblock_node)) = 1;
423 /* Pop the current level. */
424 current_binding_level = current_binding_level->level_chain;
426 if (functionbody)
427 /* This is the top level block of a function. */
428 DECL_INITIAL (current_function_decl) = block_node;
429 else if (current_binding_level == global_binding_level)
430 /* When using gfc_start_block/gfc_finish_block from middle-end hooks,
431 don't add newly created BLOCKs as subblocks of global_binding_level. */
433 else if (block_node)
435 current_binding_level->blocks
436 = block_chainon (current_binding_level->blocks, block_node);
439 /* If we did not make a block for the level just exited, any blocks made for
440 inner levels (since they cannot be recorded as subblocks in that level)
441 must be carried forward so they will later become subblocks of something
442 else. */
443 else if (subblock_chain)
444 current_binding_level->blocks
445 = block_chainon (current_binding_level->blocks, subblock_chain);
446 if (block_node)
447 TREE_USED (block_node) = 1;
449 return block_node;
453 /* Records a ..._DECL node DECL as belonging to the current lexical scope.
454 Returns the ..._DECL node. */
456 tree
457 pushdecl (tree decl)
459 if (global_bindings_p ())
460 DECL_CONTEXT (decl) = current_translation_unit;
461 else
463 /* External objects aren't nested. For debug info insert a copy
464 of the decl into the binding level. */
465 if (DECL_EXTERNAL (decl))
467 tree orig = decl;
468 decl = copy_node (decl);
469 DECL_CONTEXT (orig) = NULL_TREE;
471 DECL_CONTEXT (decl) = current_function_decl;
474 /* Put the declaration on the list. */
475 DECL_CHAIN (decl) = current_binding_level->names;
476 current_binding_level->names = decl;
478 /* For the declaration of a type, set its name if it is not already set. */
480 if (TREE_CODE (decl) == TYPE_DECL && TYPE_NAME (TREE_TYPE (decl)) == 0)
482 if (DECL_SOURCE_LINE (decl) == 0)
483 TYPE_NAME (TREE_TYPE (decl)) = decl;
484 else
485 TYPE_NAME (TREE_TYPE (decl)) = DECL_NAME (decl);
488 return decl;
492 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL. */
494 tree
495 pushdecl_top_level (tree x)
497 tree t;
498 struct binding_level *b = current_binding_level;
500 current_binding_level = global_binding_level;
501 t = pushdecl (x);
502 current_binding_level = b;
503 return t;
506 #ifndef CHAR_TYPE_SIZE
507 #define CHAR_TYPE_SIZE BITS_PER_UNIT
508 #endif
510 #ifndef INT_TYPE_SIZE
511 #define INT_TYPE_SIZE BITS_PER_WORD
512 #endif
514 #undef SIZE_TYPE
515 #define SIZE_TYPE "long unsigned int"
517 /* Create tree nodes for the basic scalar types of Fortran 95,
518 and some nodes representing standard constants (0, 1, (void *) 0).
519 Initialize the global binding level.
520 Make definitions for built-in primitive functions. */
521 static void
522 gfc_init_decl_processing (void)
524 current_function_decl = NULL;
525 current_binding_level = NULL_BINDING_LEVEL;
526 free_binding_level = NULL_BINDING_LEVEL;
528 /* Make the binding_level structure for global names. We move all
529 variables that are in a COMMON block to this binding level. */
530 pushlevel ();
531 global_binding_level = current_binding_level;
533 /* Build common tree nodes. char_type_node is unsigned because we
534 only use it for actual characters, not for INTEGER(1). Also, we
535 want double_type_node to actually have double precision. */
536 build_common_tree_nodes (false, false);
538 void_list_node = build_tree_list (NULL_TREE, void_type_node);
540 /* Set up F95 type nodes. */
541 gfc_init_kinds ();
542 gfc_init_types ();
543 gfc_init_c_interop_kinds ();
547 /* Return the typed-based alias set for T, which may be an expression
548 or a type. Return -1 if we don't do anything special. */
550 static alias_set_type
551 gfc_get_alias_set (tree t)
553 tree u;
555 /* Permit type-punning when accessing an EQUIVALENCEd variable or
556 mixed type entry master's return value. */
557 for (u = t; handled_component_p (u); u = TREE_OPERAND (u, 0))
558 if (TREE_CODE (u) == COMPONENT_REF
559 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
560 return 0;
562 return -1;
565 /* Builtin function initialization. */
567 static tree
568 gfc_builtin_function (tree decl)
570 pushdecl (decl);
571 return decl;
574 /* So far we need just these 7 attribute types. */
575 #define ATTR_NULL 0
576 #define ATTR_LEAF_LIST (ECF_LEAF)
577 #define ATTR_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF)
578 #define ATTR_NOTHROW_LEAF_MALLOC_LIST (ECF_NOTHROW | ECF_LEAF | ECF_MALLOC)
579 #define ATTR_CONST_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF | ECF_CONST)
580 #define ATTR_PURE_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF | ECF_PURE)
581 #define ATTR_NOTHROW_LIST (ECF_NOTHROW)
582 #define ATTR_CONST_NOTHROW_LIST (ECF_NOTHROW | ECF_CONST)
584 static void
585 gfc_define_builtin (const char *name, tree type, enum built_in_function code,
586 const char *library_name, int attr)
588 tree decl;
590 decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
591 library_name, NULL_TREE);
592 set_call_expr_flags (decl, attr);
594 set_builtin_decl (code, decl, true);
598 #define DO_DEFINE_MATH_BUILTIN(code, name, argtype, tbase) \
599 gfc_define_builtin ("__builtin_" name "l", tbase##longdouble[argtype], \
600 BUILT_IN_ ## code ## L, name "l", \
601 ATTR_CONST_NOTHROW_LEAF_LIST); \
602 gfc_define_builtin ("__builtin_" name, tbase##double[argtype], \
603 BUILT_IN_ ## code, name, \
604 ATTR_CONST_NOTHROW_LEAF_LIST); \
605 gfc_define_builtin ("__builtin_" name "f", tbase##float[argtype], \
606 BUILT_IN_ ## code ## F, name "f", \
607 ATTR_CONST_NOTHROW_LEAF_LIST);
609 #define DEFINE_MATH_BUILTIN(code, name, argtype) \
610 DO_DEFINE_MATH_BUILTIN (code, name, argtype, mfunc_)
612 #define DEFINE_MATH_BUILTIN_C(code, name, argtype) \
613 DO_DEFINE_MATH_BUILTIN (code, name, argtype, mfunc_) \
614 DO_DEFINE_MATH_BUILTIN (C##code, "c" name, argtype, mfunc_c)
617 /* Create function types for builtin functions. */
619 static void
620 build_builtin_fntypes (tree *fntype, tree type)
622 /* type (*) (type) */
623 fntype[0] = build_function_type_list (type, type, NULL_TREE);
624 /* type (*) (type, type) */
625 fntype[1] = build_function_type_list (type, type, type, NULL_TREE);
626 /* type (*) (type, int) */
627 fntype[2] = build_function_type_list (type,
628 type, integer_type_node, NULL_TREE);
629 /* type (*) (void) */
630 fntype[3] = build_function_type_list (type, NULL_TREE);
631 /* type (*) (type, &int) */
632 fntype[4] = build_function_type_list (type, type,
633 build_pointer_type (integer_type_node),
634 NULL_TREE);
635 /* type (*) (int, type) */
636 fntype[5] = build_function_type_list (type,
637 integer_type_node, type, NULL_TREE);
641 static tree
642 builtin_type_for_size (int size, bool unsignedp)
644 tree type = gfc_type_for_size (size, unsignedp);
645 return type ? type : error_mark_node;
648 /* Initialization of builtin function nodes. */
650 static void
651 gfc_init_builtin_functions (void)
653 enum builtin_type
655 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
656 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
657 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
658 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
659 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
660 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
661 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
662 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
663 ARG6) NAME,
664 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
665 ARG6, ARG7) NAME,
666 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
667 ARG6, ARG7, ARG8) NAME,
668 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
669 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
670 #define DEF_FUNCTION_TYPE_VAR_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
671 ARG6, ARG7, ARG8) NAME,
672 #define DEF_FUNCTION_TYPE_VAR_12(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
673 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11, ARG12) NAME,
674 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
675 #include "types.def"
676 #undef DEF_PRIMITIVE_TYPE
677 #undef DEF_FUNCTION_TYPE_0
678 #undef DEF_FUNCTION_TYPE_1
679 #undef DEF_FUNCTION_TYPE_2
680 #undef DEF_FUNCTION_TYPE_3
681 #undef DEF_FUNCTION_TYPE_4
682 #undef DEF_FUNCTION_TYPE_5
683 #undef DEF_FUNCTION_TYPE_6
684 #undef DEF_FUNCTION_TYPE_7
685 #undef DEF_FUNCTION_TYPE_8
686 #undef DEF_FUNCTION_TYPE_VAR_0
687 #undef DEF_FUNCTION_TYPE_VAR_2
688 #undef DEF_FUNCTION_TYPE_VAR_8
689 #undef DEF_FUNCTION_TYPE_VAR_12
690 #undef DEF_POINTER_TYPE
691 BT_LAST
694 tree mfunc_float[6];
695 tree mfunc_double[6];
696 tree mfunc_longdouble[6];
697 tree mfunc_cfloat[6];
698 tree mfunc_cdouble[6];
699 tree mfunc_clongdouble[6];
700 tree func_cfloat_float, func_float_cfloat;
701 tree func_cdouble_double, func_double_cdouble;
702 tree func_clongdouble_longdouble, func_longdouble_clongdouble;
703 tree func_float_floatp_floatp;
704 tree func_double_doublep_doublep;
705 tree func_longdouble_longdoublep_longdoublep;
706 tree ftype, ptype;
707 tree builtin_types[(int) BT_LAST + 1];
709 int attr;
711 build_builtin_fntypes (mfunc_float, float_type_node);
712 build_builtin_fntypes (mfunc_double, double_type_node);
713 build_builtin_fntypes (mfunc_longdouble, long_double_type_node);
714 build_builtin_fntypes (mfunc_cfloat, complex_float_type_node);
715 build_builtin_fntypes (mfunc_cdouble, complex_double_type_node);
716 build_builtin_fntypes (mfunc_clongdouble, complex_long_double_type_node);
718 func_cfloat_float = build_function_type_list (float_type_node,
719 complex_float_type_node,
720 NULL_TREE);
722 func_float_cfloat = build_function_type_list (complex_float_type_node,
723 float_type_node, NULL_TREE);
725 func_cdouble_double = build_function_type_list (double_type_node,
726 complex_double_type_node,
727 NULL_TREE);
729 func_double_cdouble = build_function_type_list (complex_double_type_node,
730 double_type_node, NULL_TREE);
732 func_clongdouble_longdouble =
733 build_function_type_list (long_double_type_node,
734 complex_long_double_type_node, NULL_TREE);
736 func_longdouble_clongdouble =
737 build_function_type_list (complex_long_double_type_node,
738 long_double_type_node, NULL_TREE);
740 ptype = build_pointer_type (float_type_node);
741 func_float_floatp_floatp =
742 build_function_type_list (void_type_node, ptype, ptype, NULL_TREE);
744 ptype = build_pointer_type (double_type_node);
745 func_double_doublep_doublep =
746 build_function_type_list (void_type_node, ptype, ptype, NULL_TREE);
748 ptype = build_pointer_type (long_double_type_node);
749 func_longdouble_longdoublep_longdoublep =
750 build_function_type_list (void_type_node, ptype, ptype, NULL_TREE);
752 /* Non-math builtins are defined manually, so they're not included here. */
753 #define OTHER_BUILTIN(ID,NAME,TYPE,CONST)
755 #include "mathbuiltins.def"
757 gfc_define_builtin ("__builtin_roundl", mfunc_longdouble[0],
758 BUILT_IN_ROUNDL, "roundl", ATTR_CONST_NOTHROW_LEAF_LIST);
759 gfc_define_builtin ("__builtin_round", mfunc_double[0],
760 BUILT_IN_ROUND, "round", ATTR_CONST_NOTHROW_LEAF_LIST);
761 gfc_define_builtin ("__builtin_roundf", mfunc_float[0],
762 BUILT_IN_ROUNDF, "roundf", ATTR_CONST_NOTHROW_LEAF_LIST);
764 gfc_define_builtin ("__builtin_truncl", mfunc_longdouble[0],
765 BUILT_IN_TRUNCL, "truncl", ATTR_CONST_NOTHROW_LEAF_LIST);
766 gfc_define_builtin ("__builtin_trunc", mfunc_double[0],
767 BUILT_IN_TRUNC, "trunc", ATTR_CONST_NOTHROW_LEAF_LIST);
768 gfc_define_builtin ("__builtin_truncf", mfunc_float[0],
769 BUILT_IN_TRUNCF, "truncf", ATTR_CONST_NOTHROW_LEAF_LIST);
771 gfc_define_builtin ("__builtin_cabsl", func_clongdouble_longdouble,
772 BUILT_IN_CABSL, "cabsl", ATTR_CONST_NOTHROW_LEAF_LIST);
773 gfc_define_builtin ("__builtin_cabs", func_cdouble_double,
774 BUILT_IN_CABS, "cabs", ATTR_CONST_NOTHROW_LEAF_LIST);
775 gfc_define_builtin ("__builtin_cabsf", func_cfloat_float,
776 BUILT_IN_CABSF, "cabsf", ATTR_CONST_NOTHROW_LEAF_LIST);
778 gfc_define_builtin ("__builtin_copysignl", mfunc_longdouble[1],
779 BUILT_IN_COPYSIGNL, "copysignl",
780 ATTR_CONST_NOTHROW_LEAF_LIST);
781 gfc_define_builtin ("__builtin_copysign", mfunc_double[1],
782 BUILT_IN_COPYSIGN, "copysign",
783 ATTR_CONST_NOTHROW_LEAF_LIST);
784 gfc_define_builtin ("__builtin_copysignf", mfunc_float[1],
785 BUILT_IN_COPYSIGNF, "copysignf",
786 ATTR_CONST_NOTHROW_LEAF_LIST);
788 gfc_define_builtin ("__builtin_nextafterl", mfunc_longdouble[1],
789 BUILT_IN_NEXTAFTERL, "nextafterl",
790 ATTR_CONST_NOTHROW_LEAF_LIST);
791 gfc_define_builtin ("__builtin_nextafter", mfunc_double[1],
792 BUILT_IN_NEXTAFTER, "nextafter",
793 ATTR_CONST_NOTHROW_LEAF_LIST);
794 gfc_define_builtin ("__builtin_nextafterf", mfunc_float[1],
795 BUILT_IN_NEXTAFTERF, "nextafterf",
796 ATTR_CONST_NOTHROW_LEAF_LIST);
798 /* Some built-ins depend on rounding mode. Depending on compilation options, they
799 will be "pure" or "const". */
800 attr = flag_rounding_math ? ATTR_PURE_NOTHROW_LEAF_LIST : ATTR_CONST_NOTHROW_LEAF_LIST;
802 gfc_define_builtin ("__builtin_rintl", mfunc_longdouble[0],
803 BUILT_IN_RINTL, "rintl", attr);
804 gfc_define_builtin ("__builtin_rint", mfunc_double[0],
805 BUILT_IN_RINT, "rint", attr);
806 gfc_define_builtin ("__builtin_rintf", mfunc_float[0],
807 BUILT_IN_RINTF, "rintf", attr);
809 gfc_define_builtin ("__builtin_remainderl", mfunc_longdouble[1],
810 BUILT_IN_REMAINDERL, "remainderl", attr);
811 gfc_define_builtin ("__builtin_remainder", mfunc_double[1],
812 BUILT_IN_REMAINDER, "remainder", attr);
813 gfc_define_builtin ("__builtin_remainderf", mfunc_float[1],
814 BUILT_IN_REMAINDERF, "remainderf", attr);
816 gfc_define_builtin ("__builtin_logbl", mfunc_longdouble[0],
817 BUILT_IN_LOGBL, "logbl", ATTR_CONST_NOTHROW_LEAF_LIST);
818 gfc_define_builtin ("__builtin_logb", mfunc_double[0],
819 BUILT_IN_LOGB, "logb", ATTR_CONST_NOTHROW_LEAF_LIST);
820 gfc_define_builtin ("__builtin_logbf", mfunc_float[0],
821 BUILT_IN_LOGBF, "logbf", ATTR_CONST_NOTHROW_LEAF_LIST);
824 gfc_define_builtin ("__builtin_frexpl", mfunc_longdouble[4],
825 BUILT_IN_FREXPL, "frexpl", ATTR_NOTHROW_LEAF_LIST);
826 gfc_define_builtin ("__builtin_frexp", mfunc_double[4],
827 BUILT_IN_FREXP, "frexp", ATTR_NOTHROW_LEAF_LIST);
828 gfc_define_builtin ("__builtin_frexpf", mfunc_float[4],
829 BUILT_IN_FREXPF, "frexpf", ATTR_NOTHROW_LEAF_LIST);
831 gfc_define_builtin ("__builtin_fabsl", mfunc_longdouble[0],
832 BUILT_IN_FABSL, "fabsl", ATTR_CONST_NOTHROW_LEAF_LIST);
833 gfc_define_builtin ("__builtin_fabs", mfunc_double[0],
834 BUILT_IN_FABS, "fabs", ATTR_CONST_NOTHROW_LEAF_LIST);
835 gfc_define_builtin ("__builtin_fabsf", mfunc_float[0],
836 BUILT_IN_FABSF, "fabsf", ATTR_CONST_NOTHROW_LEAF_LIST);
838 gfc_define_builtin ("__builtin_scalbnl", mfunc_longdouble[2],
839 BUILT_IN_SCALBNL, "scalbnl", ATTR_CONST_NOTHROW_LEAF_LIST);
840 gfc_define_builtin ("__builtin_scalbn", mfunc_double[2],
841 BUILT_IN_SCALBN, "scalbn", ATTR_CONST_NOTHROW_LEAF_LIST);
842 gfc_define_builtin ("__builtin_scalbnf", mfunc_float[2],
843 BUILT_IN_SCALBNF, "scalbnf", ATTR_CONST_NOTHROW_LEAF_LIST);
845 gfc_define_builtin ("__builtin_fmodl", mfunc_longdouble[1],
846 BUILT_IN_FMODL, "fmodl", ATTR_CONST_NOTHROW_LEAF_LIST);
847 gfc_define_builtin ("__builtin_fmod", mfunc_double[1],
848 BUILT_IN_FMOD, "fmod", ATTR_CONST_NOTHROW_LEAF_LIST);
849 gfc_define_builtin ("__builtin_fmodf", mfunc_float[1],
850 BUILT_IN_FMODF, "fmodf", ATTR_CONST_NOTHROW_LEAF_LIST);
852 /* iround{f,,l}, lround{f,,l} and llround{f,,l} */
853 ftype = build_function_type_list (integer_type_node,
854 float_type_node, NULL_TREE);
855 gfc_define_builtin("__builtin_iroundf", ftype, BUILT_IN_IROUNDF,
856 "iroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
857 ftype = build_function_type_list (long_integer_type_node,
858 float_type_node, NULL_TREE);
859 gfc_define_builtin ("__builtin_lroundf", ftype, BUILT_IN_LROUNDF,
860 "lroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
861 ftype = build_function_type_list (long_long_integer_type_node,
862 float_type_node, NULL_TREE);
863 gfc_define_builtin ("__builtin_llroundf", ftype, BUILT_IN_LLROUNDF,
864 "llroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
866 ftype = build_function_type_list (integer_type_node,
867 double_type_node, NULL_TREE);
868 gfc_define_builtin("__builtin_iround", ftype, BUILT_IN_IROUND,
869 "iround", ATTR_CONST_NOTHROW_LEAF_LIST);
870 ftype = build_function_type_list (long_integer_type_node,
871 double_type_node, NULL_TREE);
872 gfc_define_builtin ("__builtin_lround", ftype, BUILT_IN_LROUND,
873 "lround", ATTR_CONST_NOTHROW_LEAF_LIST);
874 ftype = build_function_type_list (long_long_integer_type_node,
875 double_type_node, NULL_TREE);
876 gfc_define_builtin ("__builtin_llround", ftype, BUILT_IN_LLROUND,
877 "llround", ATTR_CONST_NOTHROW_LEAF_LIST);
879 ftype = build_function_type_list (integer_type_node,
880 long_double_type_node, NULL_TREE);
881 gfc_define_builtin("__builtin_iroundl", ftype, BUILT_IN_IROUNDL,
882 "iroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
883 ftype = build_function_type_list (long_integer_type_node,
884 long_double_type_node, NULL_TREE);
885 gfc_define_builtin ("__builtin_lroundl", ftype, BUILT_IN_LROUNDL,
886 "lroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
887 ftype = build_function_type_list (long_long_integer_type_node,
888 long_double_type_node, NULL_TREE);
889 gfc_define_builtin ("__builtin_llroundl", ftype, BUILT_IN_LLROUNDL,
890 "llroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
892 /* These are used to implement the ** operator. */
893 gfc_define_builtin ("__builtin_powl", mfunc_longdouble[1],
894 BUILT_IN_POWL, "powl", ATTR_CONST_NOTHROW_LEAF_LIST);
895 gfc_define_builtin ("__builtin_pow", mfunc_double[1],
896 BUILT_IN_POW, "pow", ATTR_CONST_NOTHROW_LEAF_LIST);
897 gfc_define_builtin ("__builtin_powf", mfunc_float[1],
898 BUILT_IN_POWF, "powf", ATTR_CONST_NOTHROW_LEAF_LIST);
899 gfc_define_builtin ("__builtin_cpowl", mfunc_clongdouble[1],
900 BUILT_IN_CPOWL, "cpowl", ATTR_CONST_NOTHROW_LEAF_LIST);
901 gfc_define_builtin ("__builtin_cpow", mfunc_cdouble[1],
902 BUILT_IN_CPOW, "cpow", ATTR_CONST_NOTHROW_LEAF_LIST);
903 gfc_define_builtin ("__builtin_cpowf", mfunc_cfloat[1],
904 BUILT_IN_CPOWF, "cpowf", ATTR_CONST_NOTHROW_LEAF_LIST);
905 gfc_define_builtin ("__builtin_powil", mfunc_longdouble[2],
906 BUILT_IN_POWIL, "powil", ATTR_CONST_NOTHROW_LEAF_LIST);
907 gfc_define_builtin ("__builtin_powi", mfunc_double[2],
908 BUILT_IN_POWI, "powi", ATTR_CONST_NOTHROW_LEAF_LIST);
909 gfc_define_builtin ("__builtin_powif", mfunc_float[2],
910 BUILT_IN_POWIF, "powif", ATTR_CONST_NOTHROW_LEAF_LIST);
913 if (targetm.libc_has_function (function_c99_math_complex))
915 gfc_define_builtin ("__builtin_cbrtl", mfunc_longdouble[0],
916 BUILT_IN_CBRTL, "cbrtl",
917 ATTR_CONST_NOTHROW_LEAF_LIST);
918 gfc_define_builtin ("__builtin_cbrt", mfunc_double[0],
919 BUILT_IN_CBRT, "cbrt",
920 ATTR_CONST_NOTHROW_LEAF_LIST);
921 gfc_define_builtin ("__builtin_cbrtf", mfunc_float[0],
922 BUILT_IN_CBRTF, "cbrtf",
923 ATTR_CONST_NOTHROW_LEAF_LIST);
924 gfc_define_builtin ("__builtin_cexpil", func_longdouble_clongdouble,
925 BUILT_IN_CEXPIL, "cexpil",
926 ATTR_CONST_NOTHROW_LEAF_LIST);
927 gfc_define_builtin ("__builtin_cexpi", func_double_cdouble,
928 BUILT_IN_CEXPI, "cexpi",
929 ATTR_CONST_NOTHROW_LEAF_LIST);
930 gfc_define_builtin ("__builtin_cexpif", func_float_cfloat,
931 BUILT_IN_CEXPIF, "cexpif",
932 ATTR_CONST_NOTHROW_LEAF_LIST);
935 if (targetm.libc_has_function (function_sincos))
937 gfc_define_builtin ("__builtin_sincosl",
938 func_longdouble_longdoublep_longdoublep,
939 BUILT_IN_SINCOSL, "sincosl", ATTR_NOTHROW_LEAF_LIST);
940 gfc_define_builtin ("__builtin_sincos", func_double_doublep_doublep,
941 BUILT_IN_SINCOS, "sincos", ATTR_NOTHROW_LEAF_LIST);
942 gfc_define_builtin ("__builtin_sincosf", func_float_floatp_floatp,
943 BUILT_IN_SINCOSF, "sincosf", ATTR_NOTHROW_LEAF_LIST);
946 /* For LEADZ, TRAILZ, POPCNT and POPPAR. */
947 ftype = build_function_type_list (integer_type_node,
948 unsigned_type_node, NULL_TREE);
949 gfc_define_builtin ("__builtin_clz", ftype, BUILT_IN_CLZ,
950 "__builtin_clz", ATTR_CONST_NOTHROW_LEAF_LIST);
951 gfc_define_builtin ("__builtin_ctz", ftype, BUILT_IN_CTZ,
952 "__builtin_ctz", ATTR_CONST_NOTHROW_LEAF_LIST);
953 gfc_define_builtin ("__builtin_parity", ftype, BUILT_IN_PARITY,
954 "__builtin_parity", ATTR_CONST_NOTHROW_LEAF_LIST);
955 gfc_define_builtin ("__builtin_popcount", ftype, BUILT_IN_POPCOUNT,
956 "__builtin_popcount", ATTR_CONST_NOTHROW_LEAF_LIST);
958 ftype = build_function_type_list (integer_type_node,
959 long_unsigned_type_node, NULL_TREE);
960 gfc_define_builtin ("__builtin_clzl", ftype, BUILT_IN_CLZL,
961 "__builtin_clzl", ATTR_CONST_NOTHROW_LEAF_LIST);
962 gfc_define_builtin ("__builtin_ctzl", ftype, BUILT_IN_CTZL,
963 "__builtin_ctzl", ATTR_CONST_NOTHROW_LEAF_LIST);
964 gfc_define_builtin ("__builtin_parityl", ftype, BUILT_IN_PARITYL,
965 "__builtin_parityl", ATTR_CONST_NOTHROW_LEAF_LIST);
966 gfc_define_builtin ("__builtin_popcountl", ftype, BUILT_IN_POPCOUNTL,
967 "__builtin_popcountl", ATTR_CONST_NOTHROW_LEAF_LIST);
969 ftype = build_function_type_list (integer_type_node,
970 long_long_unsigned_type_node, NULL_TREE);
971 gfc_define_builtin ("__builtin_clzll", ftype, BUILT_IN_CLZLL,
972 "__builtin_clzll", ATTR_CONST_NOTHROW_LEAF_LIST);
973 gfc_define_builtin ("__builtin_ctzll", ftype, BUILT_IN_CTZLL,
974 "__builtin_ctzll", ATTR_CONST_NOTHROW_LEAF_LIST);
975 gfc_define_builtin ("__builtin_parityll", ftype, BUILT_IN_PARITYLL,
976 "__builtin_parityll", ATTR_CONST_NOTHROW_LEAF_LIST);
977 gfc_define_builtin ("__builtin_popcountll", ftype, BUILT_IN_POPCOUNTLL,
978 "__builtin_popcountll", ATTR_CONST_NOTHROW_LEAF_LIST);
980 /* Other builtin functions we use. */
982 ftype = build_function_type_list (long_integer_type_node,
983 long_integer_type_node,
984 long_integer_type_node, NULL_TREE);
985 gfc_define_builtin ("__builtin_expect", ftype, BUILT_IN_EXPECT,
986 "__builtin_expect", ATTR_CONST_NOTHROW_LEAF_LIST);
988 ftype = build_function_type_list (void_type_node,
989 pvoid_type_node, NULL_TREE);
990 gfc_define_builtin ("__builtin_free", ftype, BUILT_IN_FREE,
991 "free", ATTR_NOTHROW_LEAF_LIST);
993 ftype = build_function_type_list (pvoid_type_node,
994 size_type_node, NULL_TREE);
995 gfc_define_builtin ("__builtin_malloc", ftype, BUILT_IN_MALLOC,
996 "malloc", ATTR_NOTHROW_LEAF_MALLOC_LIST);
998 ftype = build_function_type_list (pvoid_type_node, size_type_node,
999 size_type_node, NULL_TREE);
1000 gfc_define_builtin ("__builtin_calloc", ftype, BUILT_IN_CALLOC,
1001 "calloc", ATTR_NOTHROW_LEAF_MALLOC_LIST);
1002 DECL_IS_MALLOC (builtin_decl_explicit (BUILT_IN_CALLOC)) = 1;
1004 ftype = build_function_type_list (pvoid_type_node,
1005 size_type_node, pvoid_type_node,
1006 NULL_TREE);
1007 gfc_define_builtin ("__builtin_realloc", ftype, BUILT_IN_REALLOC,
1008 "realloc", ATTR_NOTHROW_LEAF_LIST);
1010 ftype = build_function_type_list (integer_type_node,
1011 void_type_node, NULL_TREE);
1012 gfc_define_builtin ("__builtin_isnan", ftype, BUILT_IN_ISNAN,
1013 "__builtin_isnan", ATTR_CONST_NOTHROW_LEAF_LIST);
1014 gfc_define_builtin ("__builtin_isfinite", ftype, BUILT_IN_ISFINITE,
1015 "__builtin_isfinite", ATTR_CONST_NOTHROW_LEAF_LIST);
1016 gfc_define_builtin ("__builtin_isnormal", ftype, BUILT_IN_ISNORMAL,
1017 "__builtin_isnormal", ATTR_CONST_NOTHROW_LEAF_LIST);
1019 ftype = build_function_type_list (integer_type_node, void_type_node,
1020 void_type_node, NULL_TREE);
1021 gfc_define_builtin ("__builtin_isunordered", ftype, BUILT_IN_ISUNORDERED,
1022 "__builtin_isunordered", ATTR_CONST_NOTHROW_LEAF_LIST);
1023 gfc_define_builtin ("__builtin_islessequal", ftype, BUILT_IN_ISLESSEQUAL,
1024 "__builtin_islessequal", ATTR_CONST_NOTHROW_LEAF_LIST);
1025 gfc_define_builtin ("__builtin_isgreaterequal", ftype,
1026 BUILT_IN_ISGREATEREQUAL, "__builtin_isgreaterequal",
1027 ATTR_CONST_NOTHROW_LEAF_LIST);
1029 ftype = build_function_type_list (integer_type_node,
1030 float_type_node, NULL_TREE);
1031 gfc_define_builtin("__builtin_signbitf", ftype, BUILT_IN_SIGNBITF,
1032 "signbitf", ATTR_CONST_NOTHROW_LEAF_LIST);
1033 ftype = build_function_type_list (integer_type_node,
1034 double_type_node, NULL_TREE);
1035 gfc_define_builtin("__builtin_signbit", ftype, BUILT_IN_SIGNBIT,
1036 "signbit", ATTR_CONST_NOTHROW_LEAF_LIST);
1037 ftype = build_function_type_list (integer_type_node,
1038 long_double_type_node, NULL_TREE);
1039 gfc_define_builtin("__builtin_signbitl", ftype, BUILT_IN_SIGNBITL,
1040 "signbitl", ATTR_CONST_NOTHROW_LEAF_LIST);
1043 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
1044 builtin_types[(int) ENUM] = VALUE;
1045 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
1046 builtin_types[(int) ENUM] \
1047 = build_function_type_list (builtin_types[(int) RETURN], \
1048 NULL_TREE);
1049 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
1050 builtin_types[(int) ENUM] \
1051 = build_function_type_list (builtin_types[(int) RETURN], \
1052 builtin_types[(int) ARG1], \
1053 NULL_TREE);
1054 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
1055 builtin_types[(int) ENUM] \
1056 = build_function_type_list (builtin_types[(int) RETURN], \
1057 builtin_types[(int) ARG1], \
1058 builtin_types[(int) ARG2], \
1059 NULL_TREE);
1060 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
1061 builtin_types[(int) ENUM] \
1062 = build_function_type_list (builtin_types[(int) RETURN], \
1063 builtin_types[(int) ARG1], \
1064 builtin_types[(int) ARG2], \
1065 builtin_types[(int) ARG3], \
1066 NULL_TREE);
1067 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
1068 builtin_types[(int) ENUM] \
1069 = build_function_type_list (builtin_types[(int) RETURN], \
1070 builtin_types[(int) ARG1], \
1071 builtin_types[(int) ARG2], \
1072 builtin_types[(int) ARG3], \
1073 builtin_types[(int) ARG4], \
1074 NULL_TREE);
1075 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
1076 builtin_types[(int) ENUM] \
1077 = build_function_type_list (builtin_types[(int) RETURN], \
1078 builtin_types[(int) ARG1], \
1079 builtin_types[(int) ARG2], \
1080 builtin_types[(int) ARG3], \
1081 builtin_types[(int) ARG4], \
1082 builtin_types[(int) ARG5], \
1083 NULL_TREE);
1084 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1085 ARG6) \
1086 builtin_types[(int) ENUM] \
1087 = build_function_type_list (builtin_types[(int) RETURN], \
1088 builtin_types[(int) ARG1], \
1089 builtin_types[(int) ARG2], \
1090 builtin_types[(int) ARG3], \
1091 builtin_types[(int) ARG4], \
1092 builtin_types[(int) ARG5], \
1093 builtin_types[(int) ARG6], \
1094 NULL_TREE);
1095 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1096 ARG6, ARG7) \
1097 builtin_types[(int) ENUM] \
1098 = build_function_type_list (builtin_types[(int) RETURN], \
1099 builtin_types[(int) ARG1], \
1100 builtin_types[(int) ARG2], \
1101 builtin_types[(int) ARG3], \
1102 builtin_types[(int) ARG4], \
1103 builtin_types[(int) ARG5], \
1104 builtin_types[(int) ARG6], \
1105 builtin_types[(int) ARG7], \
1106 NULL_TREE);
1107 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1108 ARG6, ARG7, ARG8) \
1109 builtin_types[(int) ENUM] \
1110 = build_function_type_list (builtin_types[(int) RETURN], \
1111 builtin_types[(int) ARG1], \
1112 builtin_types[(int) ARG2], \
1113 builtin_types[(int) ARG3], \
1114 builtin_types[(int) ARG4], \
1115 builtin_types[(int) ARG5], \
1116 builtin_types[(int) ARG6], \
1117 builtin_types[(int) ARG7], \
1118 builtin_types[(int) ARG8], \
1119 NULL_TREE);
1120 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
1121 builtin_types[(int) ENUM] \
1122 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1123 NULL_TREE);
1124 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
1125 builtin_types[(int) ENUM] \
1126 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1127 builtin_types[(int) ARG1], \
1128 builtin_types[(int) ARG2], \
1129 NULL_TREE);
1130 #define DEF_FUNCTION_TYPE_VAR_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1131 ARG6, ARG7, ARG8) \
1132 builtin_types[(int) ENUM] \
1133 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1134 builtin_types[(int) ARG1], \
1135 builtin_types[(int) ARG2], \
1136 builtin_types[(int) ARG3], \
1137 builtin_types[(int) ARG4], \
1138 builtin_types[(int) ARG5], \
1139 builtin_types[(int) ARG6], \
1140 builtin_types[(int) ARG7], \
1141 builtin_types[(int) ARG8], \
1142 NULL_TREE);
1143 #define DEF_FUNCTION_TYPE_VAR_12(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1144 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11, ARG12) \
1145 builtin_types[(int) ENUM] \
1146 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1147 builtin_types[(int) ARG1], \
1148 builtin_types[(int) ARG2], \
1149 builtin_types[(int) ARG3], \
1150 builtin_types[(int) ARG4], \
1151 builtin_types[(int) ARG5], \
1152 builtin_types[(int) ARG6], \
1153 builtin_types[(int) ARG7], \
1154 builtin_types[(int) ARG8], \
1155 builtin_types[(int) ARG9], \
1156 builtin_types[(int) ARG10], \
1157 builtin_types[(int) ARG11], \
1158 builtin_types[(int) ARG12], \
1159 NULL_TREE);
1160 #define DEF_POINTER_TYPE(ENUM, TYPE) \
1161 builtin_types[(int) ENUM] \
1162 = build_pointer_type (builtin_types[(int) TYPE]);
1163 #include "types.def"
1164 #undef DEF_PRIMITIVE_TYPE
1165 #undef DEF_FUNCTION_TYPE_0
1166 #undef DEF_FUNCTION_TYPE_1
1167 #undef DEF_FUNCTION_TYPE_2
1168 #undef DEF_FUNCTION_TYPE_3
1169 #undef DEF_FUNCTION_TYPE_4
1170 #undef DEF_FUNCTION_TYPE_5
1171 #undef DEF_FUNCTION_TYPE_6
1172 #undef DEF_FUNCTION_TYPE_7
1173 #undef DEF_FUNCTION_TYPE_8
1174 #undef DEF_FUNCTION_TYPE_VAR_0
1175 #undef DEF_FUNCTION_TYPE_VAR_2
1176 #undef DEF_FUNCTION_TYPE_VAR_8
1177 #undef DEF_FUNCTION_TYPE_VAR_12
1178 #undef DEF_POINTER_TYPE
1179 builtin_types[(int) BT_LAST] = NULL_TREE;
1181 /* Initialize synchronization builtins. */
1182 #undef DEF_SYNC_BUILTIN
1183 #define DEF_SYNC_BUILTIN(code, name, type, attr) \
1184 gfc_define_builtin (name, builtin_types[type], code, name, \
1185 attr);
1186 #include "../sync-builtins.def"
1187 #undef DEF_SYNC_BUILTIN
1189 if (gfc_option.gfc_flag_openacc)
1191 #undef DEF_GOACC_BUILTIN
1192 #define DEF_GOACC_BUILTIN(code, name, type, attr) \
1193 gfc_define_builtin ("__builtin_" name, builtin_types[type], \
1194 code, name, attr);
1195 #undef DEF_GOACC_BUILTIN_COMPILER
1196 #define DEF_GOACC_BUILTIN_COMPILER(code, name, type, attr) \
1197 gfc_define_builtin (name, builtin_types[type], code, name, attr);
1198 #include "../oacc-builtins.def"
1199 #undef DEF_GOACC_BUILTIN_COMPILER
1200 #undef DEF_GOACC_BUILTIN
1203 if (gfc_option.gfc_flag_openmp
1204 || gfc_option.gfc_flag_openmp_simd
1205 || flag_tree_parallelize_loops)
1207 #undef DEF_GOMP_BUILTIN
1208 #define DEF_GOMP_BUILTIN(code, name, type, attr) \
1209 gfc_define_builtin ("__builtin_" name, builtin_types[type], \
1210 code, name, attr);
1211 #include "../omp-builtins.def"
1212 #undef DEF_GOMP_BUILTIN
1215 gfc_define_builtin ("__builtin_trap", builtin_types[BT_FN_VOID],
1216 BUILT_IN_TRAP, NULL, ATTR_NOTHROW_LEAF_LIST);
1217 TREE_THIS_VOLATILE (builtin_decl_explicit (BUILT_IN_TRAP)) = 1;
1219 ftype = build_varargs_function_type_list (ptr_type_node, const_ptr_type_node,
1220 size_type_node, NULL_TREE);
1221 gfc_define_builtin ("__builtin_assume_aligned", ftype,
1222 BUILT_IN_ASSUME_ALIGNED,
1223 "__builtin_assume_aligned",
1224 ATTR_CONST_NOTHROW_LEAF_LIST);
1226 gfc_define_builtin ("__emutls_get_address",
1227 builtin_types[BT_FN_PTR_PTR],
1228 BUILT_IN_EMUTLS_GET_ADDRESS,
1229 "__emutls_get_address", ATTR_CONST_NOTHROW_LEAF_LIST);
1230 gfc_define_builtin ("__emutls_register_common",
1231 builtin_types[BT_FN_VOID_PTR_WORD_WORD_PTR],
1232 BUILT_IN_EMUTLS_REGISTER_COMMON,
1233 "__emutls_register_common", ATTR_NOTHROW_LEAF_LIST);
1235 build_common_builtin_nodes ();
1236 targetm.init_builtins ();
1239 #undef DEFINE_MATH_BUILTIN_C
1240 #undef DEFINE_MATH_BUILTIN
1242 static void
1243 gfc_init_ts (void)
1245 tree_contains_struct[NAMESPACE_DECL][TS_DECL_NON_COMMON] = 1;
1246 tree_contains_struct[NAMESPACE_DECL][TS_DECL_WITH_VIS] = 1;
1247 tree_contains_struct[NAMESPACE_DECL][TS_DECL_WRTL] = 1;
1248 tree_contains_struct[NAMESPACE_DECL][TS_DECL_COMMON] = 1;
1249 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1252 void
1253 gfc_maybe_initialize_eh (void)
1255 if (!flag_exceptions || gfc_eh_initialized_p)
1256 return;
1258 gfc_eh_initialized_p = true;
1259 using_eh_for_cleanups ();
1263 #include "gt-fortran-f95-lang.h"
1264 #include "gtype-fortran.h"