2016-07-28 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / gcc / fortran / f95-lang.c
blob2b58173450a7f7407da6c6a584da651380133105
1 /* gfortran backend interface
2 Copyright (C) 2000-2016 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 "coretypes.h"
28 #include "target.h"
29 #include "function.h"
30 #include "tree.h"
31 #include "gfortran.h"
32 #include "trans.h"
33 #include "diagnostic.h" /* For errorcount/warningcount */
34 #include "langhooks.h"
35 #include "langhooks-def.h"
36 #include "toplev.h"
37 #include "debug.h"
38 #include "cpp.h"
39 #include "trans-types.h"
40 #include "trans-const.h"
42 /* Language-dependent contents of an identifier. */
44 struct GTY(())
45 lang_identifier {
46 struct tree_identifier common;
49 /* The resulting tree type. */
51 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
52 chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
53 lang_tree_node {
54 union tree_node GTY((tag ("0"),
55 desc ("tree_node_structure (&%h)"))) generic;
56 struct lang_identifier GTY((tag ("1"))) identifier;
59 /* Save and restore the variables in this file and elsewhere
60 that keep track of the progress of compilation of the current function.
61 Used for nested functions. */
63 struct GTY(())
64 language_function {
65 /* struct gfc_language_function base; */
66 struct binding_level *binding_level;
69 static void gfc_init_decl_processing (void);
70 static void gfc_init_builtin_functions (void);
71 static bool global_bindings_p (void);
73 /* Each front end provides its own. */
74 static bool gfc_init (void);
75 static void gfc_finish (void);
76 static void gfc_be_parse_file (void);
77 static void gfc_init_ts (void);
78 static tree gfc_builtin_function (tree);
80 /* Handle an "omp declare target" attribute; arguments as in
81 struct attribute_spec.handler. */
82 static tree
83 gfc_handle_omp_declare_target_attribute (tree *, tree, tree, int, bool *)
85 return NULL_TREE;
88 /* Table of valid Fortran attributes. */
89 static const struct attribute_spec gfc_attribute_table[] =
91 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
92 affects_type_identity } */
93 { "omp declare target", 0, 0, true, false, false,
94 gfc_handle_omp_declare_target_attribute, false },
95 { "oacc function", 0, -1, true, false, false,
96 gfc_handle_omp_declare_target_attribute, false },
97 { NULL, 0, 0, false, false, false, NULL, false }
100 #undef LANG_HOOKS_NAME
101 #undef LANG_HOOKS_INIT
102 #undef LANG_HOOKS_FINISH
103 #undef LANG_HOOKS_OPTION_LANG_MASK
104 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
105 #undef LANG_HOOKS_INIT_OPTIONS
106 #undef LANG_HOOKS_HANDLE_OPTION
107 #undef LANG_HOOKS_POST_OPTIONS
108 #undef LANG_HOOKS_PARSE_FILE
109 #undef LANG_HOOKS_MARK_ADDRESSABLE
110 #undef LANG_HOOKS_TYPE_FOR_MODE
111 #undef LANG_HOOKS_TYPE_FOR_SIZE
112 #undef LANG_HOOKS_INIT_TS
113 #undef LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE
114 #undef LANG_HOOKS_OMP_PREDETERMINED_SHARING
115 #undef LANG_HOOKS_OMP_REPORT_DECL
116 #undef LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR
117 #undef LANG_HOOKS_OMP_CLAUSE_COPY_CTOR
118 #undef LANG_HOOKS_OMP_CLAUSE_ASSIGN_OP
119 #undef LANG_HOOKS_OMP_CLAUSE_LINEAR_CTOR
120 #undef LANG_HOOKS_OMP_CLAUSE_DTOR
121 #undef LANG_HOOKS_OMP_FINISH_CLAUSE
122 #undef LANG_HOOKS_OMP_DISREGARD_VALUE_EXPR
123 #undef LANG_HOOKS_OMP_PRIVATE_DEBUG_CLAUSE
124 #undef LANG_HOOKS_OMP_PRIVATE_OUTER_REF
125 #undef LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES
126 #undef LANG_HOOKS_BUILTIN_FUNCTION
127 #undef LANG_HOOKS_BUILTIN_FUNCTION
128 #undef LANG_HOOKS_GET_ARRAY_DESCR_INFO
129 #undef LANG_HOOKS_ATTRIBUTE_TABLE
131 /* Define lang hooks. */
132 #define LANG_HOOKS_NAME "GNU Fortran"
133 #define LANG_HOOKS_INIT gfc_init
134 #define LANG_HOOKS_FINISH gfc_finish
135 #define LANG_HOOKS_OPTION_LANG_MASK gfc_option_lang_mask
136 #define LANG_HOOKS_INIT_OPTIONS_STRUCT gfc_init_options_struct
137 #define LANG_HOOKS_INIT_OPTIONS gfc_init_options
138 #define LANG_HOOKS_HANDLE_OPTION gfc_handle_option
139 #define LANG_HOOKS_POST_OPTIONS gfc_post_options
140 #define LANG_HOOKS_PARSE_FILE gfc_be_parse_file
141 #define LANG_HOOKS_TYPE_FOR_MODE gfc_type_for_mode
142 #define LANG_HOOKS_TYPE_FOR_SIZE gfc_type_for_size
143 #define LANG_HOOKS_INIT_TS gfc_init_ts
144 #define LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE gfc_omp_privatize_by_reference
145 #define LANG_HOOKS_OMP_PREDETERMINED_SHARING gfc_omp_predetermined_sharing
146 #define LANG_HOOKS_OMP_REPORT_DECL gfc_omp_report_decl
147 #define LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR gfc_omp_clause_default_ctor
148 #define LANG_HOOKS_OMP_CLAUSE_COPY_CTOR gfc_omp_clause_copy_ctor
149 #define LANG_HOOKS_OMP_CLAUSE_ASSIGN_OP gfc_omp_clause_assign_op
150 #define LANG_HOOKS_OMP_CLAUSE_LINEAR_CTOR gfc_omp_clause_linear_ctor
151 #define LANG_HOOKS_OMP_CLAUSE_DTOR gfc_omp_clause_dtor
152 #define LANG_HOOKS_OMP_FINISH_CLAUSE gfc_omp_finish_clause
153 #define LANG_HOOKS_OMP_DISREGARD_VALUE_EXPR gfc_omp_disregard_value_expr
154 #define LANG_HOOKS_OMP_PRIVATE_DEBUG_CLAUSE gfc_omp_private_debug_clause
155 #define LANG_HOOKS_OMP_PRIVATE_OUTER_REF gfc_omp_private_outer_ref
156 #define LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES \
157 gfc_omp_firstprivatize_type_sizes
158 #define LANG_HOOKS_BUILTIN_FUNCTION gfc_builtin_function
159 #define LANG_HOOKS_GET_ARRAY_DESCR_INFO gfc_get_array_descr_info
160 #define LANG_HOOKS_ATTRIBUTE_TABLE gfc_attribute_table
162 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
164 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
166 /* A chain of binding_level structures awaiting reuse. */
168 static GTY(()) struct binding_level *free_binding_level;
170 /* True means we've initialized exception handling. */
171 static bool gfc_eh_initialized_p;
173 /* The current translation unit. */
174 static GTY(()) tree current_translation_unit;
177 static void
178 gfc_create_decls (void)
180 /* GCC builtins. */
181 gfc_init_builtin_functions ();
183 /* Runtime/IO library functions. */
184 gfc_build_builtin_function_decls ();
186 gfc_init_constants ();
188 /* Build our translation-unit decl. */
189 current_translation_unit = build_translation_unit_decl (NULL_TREE);
190 debug_hooks->register_main_translation_unit (current_translation_unit);
194 static void
195 gfc_be_parse_file (void)
197 gfc_create_decls ();
198 gfc_parse_file ();
199 gfc_generate_constructors ();
201 /* Clear the binding level stack. */
202 while (!global_bindings_p ())
203 poplevel (0, 0);
205 /* Finalize all of the globals.
207 Emulated tls lowering needs to see all TLS variables before we
208 call finalize_compilation_unit. The C/C++ front ends manage this
209 by calling decl_rest_of_compilation on each global and static
210 variable as they are seen. The Fortran front end waits until
211 here. */
212 for (tree decl = getdecls (); decl ; decl = DECL_CHAIN (decl))
213 rest_of_decl_compilation (decl, true, true);
215 /* Switch to the default tree diagnostics here, because there may be
216 diagnostics before gfc_finish(). */
217 gfc_diagnostics_finish ();
219 global_decl_processing ();
223 /* Initialize everything. */
225 static bool
226 gfc_init (void)
228 if (!gfc_cpp_enabled ())
230 linemap_add (line_table, LC_ENTER, false, gfc_source_file, 1);
231 linemap_add (line_table, LC_RENAME, false, "<built-in>", 0);
233 else
234 gfc_cpp_init_0 ();
236 gfc_init_decl_processing ();
237 gfc_static_ctors = NULL_TREE;
239 if (gfc_cpp_enabled ())
240 gfc_cpp_init ();
242 gfc_init_1 ();
244 if (!gfc_new_file ())
245 fatal_error (input_location, "can't open input file: %s", gfc_source_file);
247 if (flag_preprocess_only)
248 return false;
250 return true;
254 static void
255 gfc_finish (void)
257 gfc_cpp_done ();
258 gfc_done_1 ();
259 gfc_release_include_path ();
260 return;
263 /* These functions and variables deal with binding contours. We only
264 need these functions for the list of PARM_DECLs, but we leave the
265 functions more general; these are a simplified version of the
266 functions from GNAT. */
268 /* For each binding contour we allocate a binding_level structure which
269 records the entities defined or declared in that contour. Contours
270 include:
272 the global one
273 one for each subprogram definition
274 one for each compound statement (declare block)
276 Binding contours are used to create GCC tree BLOCK nodes. */
278 struct GTY(())
279 binding_level {
280 /* A chain of ..._DECL nodes for all variables, constants, functions,
281 parameters and type declarations. These ..._DECL nodes are chained
282 through the DECL_CHAIN field. */
283 tree names;
284 /* For each level (except the global one), a chain of BLOCK nodes for all
285 the levels that were entered and exited one level down from this one. */
286 tree blocks;
287 /* The binding level containing this one (the enclosing binding level). */
288 struct binding_level *level_chain;
289 /* True if nreverse has been already called on names; if false, names
290 are ordered from newest declaration to oldest one. */
291 bool reversed;
294 /* The binding level currently in effect. */
295 static GTY(()) struct binding_level *current_binding_level = NULL;
297 /* The outermost binding level. This binding level is created when the
298 compiler is started and it will exist through the entire compilation. */
299 static GTY(()) struct binding_level *global_binding_level;
301 /* Binding level structures are initialized by copying this one. */
302 static struct binding_level clear_binding_level = { NULL, NULL, NULL, false };
305 /* Return true if we are in the global binding level. */
307 bool
308 global_bindings_p (void)
310 return current_binding_level == global_binding_level;
313 tree
314 getdecls (void)
316 if (!current_binding_level->reversed)
318 current_binding_level->reversed = true;
319 current_binding_level->names = nreverse (current_binding_level->names);
321 return current_binding_level->names;
324 /* Enter a new binding level. */
326 void
327 pushlevel (void)
329 struct binding_level *newlevel = ggc_alloc<binding_level> ();
331 *newlevel = clear_binding_level;
333 /* Add this level to the front of the chain (stack) of levels that are
334 active. */
335 newlevel->level_chain = current_binding_level;
336 current_binding_level = newlevel;
339 /* Exit a binding level.
340 Pop the level off, and restore the state of the identifier-decl mappings
341 that were in effect when this level was entered.
343 If KEEP is nonzero, this level had explicit declarations, so
344 and create a "block" (a BLOCK node) for the level
345 to record its declarations and subblocks for symbol table output.
347 If FUNCTIONBODY is nonzero, this level is the body of a function,
348 so create a block as if KEEP were set and also clear out all
349 label names. */
351 tree
352 poplevel (int keep, int functionbody)
354 /* Points to a BLOCK tree node. This is the BLOCK node constructed for the
355 binding level that we are about to exit and which is returned by this
356 routine. */
357 tree block_node = NULL_TREE;
358 tree decl_chain = getdecls ();
359 tree subblock_chain = current_binding_level->blocks;
360 tree subblock_node;
362 /* If there were any declarations in the current binding level, or if this
363 binding level is a function body, or if there are any nested blocks then
364 create a BLOCK node to record them for the life of this function. */
365 if (keep || functionbody)
366 block_node = build_block (keep ? decl_chain : 0, subblock_chain, 0, 0);
368 /* Record the BLOCK node just built as the subblock its enclosing scope. */
369 for (subblock_node = subblock_chain; subblock_node;
370 subblock_node = BLOCK_CHAIN (subblock_node))
371 BLOCK_SUPERCONTEXT (subblock_node) = block_node;
373 /* Clear out the meanings of the local variables of this level. */
375 for (subblock_node = decl_chain; subblock_node;
376 subblock_node = DECL_CHAIN (subblock_node))
377 if (DECL_NAME (subblock_node) != 0)
378 /* If the identifier was used or addressed via a local extern decl,
379 don't forget that fact. */
380 if (DECL_EXTERNAL (subblock_node))
382 if (TREE_USED (subblock_node))
383 TREE_USED (DECL_NAME (subblock_node)) = 1;
384 if (TREE_ADDRESSABLE (subblock_node))
385 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (subblock_node)) = 1;
388 /* Pop the current level. */
389 current_binding_level = current_binding_level->level_chain;
391 if (functionbody)
392 /* This is the top level block of a function. */
393 DECL_INITIAL (current_function_decl) = block_node;
394 else if (current_binding_level == global_binding_level)
395 /* When using gfc_start_block/gfc_finish_block from middle-end hooks,
396 don't add newly created BLOCKs as subblocks of global_binding_level. */
398 else if (block_node)
400 current_binding_level->blocks
401 = block_chainon (current_binding_level->blocks, block_node);
404 /* If we did not make a block for the level just exited, any blocks made for
405 inner levels (since they cannot be recorded as subblocks in that level)
406 must be carried forward so they will later become subblocks of something
407 else. */
408 else if (subblock_chain)
409 current_binding_level->blocks
410 = block_chainon (current_binding_level->blocks, subblock_chain);
411 if (block_node)
412 TREE_USED (block_node) = 1;
414 return block_node;
418 /* Records a ..._DECL node DECL as belonging to the current lexical scope.
419 Returns the ..._DECL node. */
421 tree
422 pushdecl (tree decl)
424 if (global_bindings_p ())
425 DECL_CONTEXT (decl) = current_translation_unit;
426 else
428 /* External objects aren't nested. For debug info insert a copy
429 of the decl into the binding level. */
430 if (DECL_EXTERNAL (decl))
432 tree orig = decl;
433 decl = copy_node (decl);
434 DECL_CONTEXT (orig) = NULL_TREE;
436 DECL_CONTEXT (decl) = current_function_decl;
439 /* Put the declaration on the list. */
440 DECL_CHAIN (decl) = current_binding_level->names;
441 current_binding_level->names = decl;
443 /* For the declaration of a type, set its name if it is not already set. */
445 if (TREE_CODE (decl) == TYPE_DECL && TYPE_NAME (TREE_TYPE (decl)) == 0)
447 if (DECL_SOURCE_LINE (decl) == 0)
448 TYPE_NAME (TREE_TYPE (decl)) = decl;
449 else
450 TYPE_NAME (TREE_TYPE (decl)) = DECL_NAME (decl);
453 return decl;
457 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL. */
459 tree
460 pushdecl_top_level (tree x)
462 tree t;
463 struct binding_level *b = current_binding_level;
465 current_binding_level = global_binding_level;
466 t = pushdecl (x);
467 current_binding_level = b;
468 return t;
471 #ifndef CHAR_TYPE_SIZE
472 #define CHAR_TYPE_SIZE BITS_PER_UNIT
473 #endif
475 #ifndef INT_TYPE_SIZE
476 #define INT_TYPE_SIZE BITS_PER_WORD
477 #endif
479 #undef SIZE_TYPE
480 #define SIZE_TYPE "long unsigned int"
482 /* Create tree nodes for the basic scalar types of Fortran 95,
483 and some nodes representing standard constants (0, 1, (void *) 0).
484 Initialize the global binding level.
485 Make definitions for built-in primitive functions. */
486 static void
487 gfc_init_decl_processing (void)
489 current_function_decl = NULL;
490 current_binding_level = NULL_BINDING_LEVEL;
491 free_binding_level = NULL_BINDING_LEVEL;
493 /* Make the binding_level structure for global names. We move all
494 variables that are in a COMMON block to this binding level. */
495 pushlevel ();
496 global_binding_level = current_binding_level;
498 /* Build common tree nodes. char_type_node is unsigned because we
499 only use it for actual characters, not for INTEGER(1). */
500 build_common_tree_nodes (false);
502 void_list_node = build_tree_list (NULL_TREE, void_type_node);
504 /* Set up F95 type nodes. */
505 gfc_init_kinds ();
506 gfc_init_types ();
507 gfc_init_c_interop_kinds ();
511 /* Builtin function initialization. */
513 static tree
514 gfc_builtin_function (tree decl)
516 pushdecl (decl);
517 return decl;
520 /* So far we need just these 7 attribute types. */
521 #define ATTR_NULL 0
522 #define ATTR_LEAF_LIST (ECF_LEAF)
523 #define ATTR_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF)
524 #define ATTR_NOTHROW_LEAF_MALLOC_LIST (ECF_NOTHROW | ECF_LEAF | ECF_MALLOC)
525 #define ATTR_CONST_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF | ECF_CONST)
526 #define ATTR_PURE_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF | ECF_PURE)
527 #define ATTR_NOTHROW_LIST (ECF_NOTHROW)
528 #define ATTR_CONST_NOTHROW_LIST (ECF_NOTHROW | ECF_CONST)
530 static void
531 gfc_define_builtin (const char *name, tree type, enum built_in_function code,
532 const char *library_name, int attr)
534 tree decl;
536 decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
537 library_name, NULL_TREE);
538 set_call_expr_flags (decl, attr);
540 set_builtin_decl (code, decl, true);
544 #define DO_DEFINE_MATH_BUILTIN(code, name, argtype, tbase) \
545 gfc_define_builtin ("__builtin_" name "l", tbase##longdouble[argtype], \
546 BUILT_IN_ ## code ## L, name "l", \
547 ATTR_CONST_NOTHROW_LEAF_LIST); \
548 gfc_define_builtin ("__builtin_" name, tbase##double[argtype], \
549 BUILT_IN_ ## code, name, \
550 ATTR_CONST_NOTHROW_LEAF_LIST); \
551 gfc_define_builtin ("__builtin_" name "f", tbase##float[argtype], \
552 BUILT_IN_ ## code ## F, name "f", \
553 ATTR_CONST_NOTHROW_LEAF_LIST);
555 #define DEFINE_MATH_BUILTIN(code, name, argtype) \
556 DO_DEFINE_MATH_BUILTIN (code, name, argtype, mfunc_)
558 #define DEFINE_MATH_BUILTIN_C(code, name, argtype) \
559 DO_DEFINE_MATH_BUILTIN (code, name, argtype, mfunc_) \
560 DO_DEFINE_MATH_BUILTIN (C##code, "c" name, argtype, mfunc_c)
563 /* Create function types for builtin functions. */
565 static void
566 build_builtin_fntypes (tree *fntype, tree type)
568 /* type (*) (type) */
569 fntype[0] = build_function_type_list (type, type, NULL_TREE);
570 /* type (*) (type, type) */
571 fntype[1] = build_function_type_list (type, type, type, NULL_TREE);
572 /* type (*) (type, int) */
573 fntype[2] = build_function_type_list (type,
574 type, integer_type_node, NULL_TREE);
575 /* type (*) (void) */
576 fntype[3] = build_function_type_list (type, NULL_TREE);
577 /* type (*) (type, &int) */
578 fntype[4] = build_function_type_list (type, type,
579 build_pointer_type (integer_type_node),
580 NULL_TREE);
581 /* type (*) (int, type) */
582 fntype[5] = build_function_type_list (type,
583 integer_type_node, type, NULL_TREE);
587 static tree
588 builtin_type_for_size (int size, bool unsignedp)
590 tree type = gfc_type_for_size (size, unsignedp);
591 return type ? type : error_mark_node;
594 /* Initialization of builtin function nodes. */
596 static void
597 gfc_init_builtin_functions (void)
599 enum builtin_type
601 #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
602 #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
603 #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
604 #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
605 #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
606 #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
607 #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
608 #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
609 ARG6) NAME,
610 #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
611 ARG6, ARG7) NAME,
612 #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
613 ARG6, ARG7, ARG8) NAME,
614 #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
615 ARG6, ARG7, ARG8, ARG9) NAME,
616 #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
617 ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
618 #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
619 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
620 #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
621 #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
622 #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
623 #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
624 ARG6) NAME,
625 #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
626 ARG6, ARG7) NAME,
627 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
628 #include "types.def"
629 #undef DEF_PRIMITIVE_TYPE
630 #undef DEF_FUNCTION_TYPE_0
631 #undef DEF_FUNCTION_TYPE_1
632 #undef DEF_FUNCTION_TYPE_2
633 #undef DEF_FUNCTION_TYPE_3
634 #undef DEF_FUNCTION_TYPE_4
635 #undef DEF_FUNCTION_TYPE_5
636 #undef DEF_FUNCTION_TYPE_6
637 #undef DEF_FUNCTION_TYPE_7
638 #undef DEF_FUNCTION_TYPE_8
639 #undef DEF_FUNCTION_TYPE_9
640 #undef DEF_FUNCTION_TYPE_10
641 #undef DEF_FUNCTION_TYPE_11
642 #undef DEF_FUNCTION_TYPE_VAR_0
643 #undef DEF_FUNCTION_TYPE_VAR_1
644 #undef DEF_FUNCTION_TYPE_VAR_2
645 #undef DEF_FUNCTION_TYPE_VAR_6
646 #undef DEF_FUNCTION_TYPE_VAR_7
647 #undef DEF_POINTER_TYPE
648 BT_LAST
651 tree mfunc_float[6];
652 tree mfunc_double[6];
653 tree mfunc_longdouble[6];
654 tree mfunc_cfloat[6];
655 tree mfunc_cdouble[6];
656 tree mfunc_clongdouble[6];
657 tree func_cfloat_float, func_float_cfloat;
658 tree func_cdouble_double, func_double_cdouble;
659 tree func_clongdouble_longdouble, func_longdouble_clongdouble;
660 tree func_float_floatp_floatp;
661 tree func_double_doublep_doublep;
662 tree func_longdouble_longdoublep_longdoublep;
663 tree ftype, ptype;
664 tree builtin_types[(int) BT_LAST + 1];
666 int attr;
668 build_builtin_fntypes (mfunc_float, float_type_node);
669 build_builtin_fntypes (mfunc_double, double_type_node);
670 build_builtin_fntypes (mfunc_longdouble, long_double_type_node);
671 build_builtin_fntypes (mfunc_cfloat, complex_float_type_node);
672 build_builtin_fntypes (mfunc_cdouble, complex_double_type_node);
673 build_builtin_fntypes (mfunc_clongdouble, complex_long_double_type_node);
675 func_cfloat_float = build_function_type_list (float_type_node,
676 complex_float_type_node,
677 NULL_TREE);
679 func_float_cfloat = build_function_type_list (complex_float_type_node,
680 float_type_node, NULL_TREE);
682 func_cdouble_double = build_function_type_list (double_type_node,
683 complex_double_type_node,
684 NULL_TREE);
686 func_double_cdouble = build_function_type_list (complex_double_type_node,
687 double_type_node, NULL_TREE);
689 func_clongdouble_longdouble =
690 build_function_type_list (long_double_type_node,
691 complex_long_double_type_node, NULL_TREE);
693 func_longdouble_clongdouble =
694 build_function_type_list (complex_long_double_type_node,
695 long_double_type_node, NULL_TREE);
697 ptype = build_pointer_type (float_type_node);
698 func_float_floatp_floatp =
699 build_function_type_list (void_type_node, ptype, ptype, NULL_TREE);
701 ptype = build_pointer_type (double_type_node);
702 func_double_doublep_doublep =
703 build_function_type_list (void_type_node, ptype, ptype, NULL_TREE);
705 ptype = build_pointer_type (long_double_type_node);
706 func_longdouble_longdoublep_longdoublep =
707 build_function_type_list (void_type_node, ptype, ptype, NULL_TREE);
709 /* Non-math builtins are defined manually, so they're not included here. */
710 #define OTHER_BUILTIN(ID,NAME,TYPE,CONST)
712 #include "mathbuiltins.def"
714 gfc_define_builtin ("__builtin_roundl", mfunc_longdouble[0],
715 BUILT_IN_ROUNDL, "roundl", ATTR_CONST_NOTHROW_LEAF_LIST);
716 gfc_define_builtin ("__builtin_round", mfunc_double[0],
717 BUILT_IN_ROUND, "round", ATTR_CONST_NOTHROW_LEAF_LIST);
718 gfc_define_builtin ("__builtin_roundf", mfunc_float[0],
719 BUILT_IN_ROUNDF, "roundf", ATTR_CONST_NOTHROW_LEAF_LIST);
721 gfc_define_builtin ("__builtin_truncl", mfunc_longdouble[0],
722 BUILT_IN_TRUNCL, "truncl", ATTR_CONST_NOTHROW_LEAF_LIST);
723 gfc_define_builtin ("__builtin_trunc", mfunc_double[0],
724 BUILT_IN_TRUNC, "trunc", ATTR_CONST_NOTHROW_LEAF_LIST);
725 gfc_define_builtin ("__builtin_truncf", mfunc_float[0],
726 BUILT_IN_TRUNCF, "truncf", ATTR_CONST_NOTHROW_LEAF_LIST);
728 gfc_define_builtin ("__builtin_cabsl", func_clongdouble_longdouble,
729 BUILT_IN_CABSL, "cabsl", ATTR_CONST_NOTHROW_LEAF_LIST);
730 gfc_define_builtin ("__builtin_cabs", func_cdouble_double,
731 BUILT_IN_CABS, "cabs", ATTR_CONST_NOTHROW_LEAF_LIST);
732 gfc_define_builtin ("__builtin_cabsf", func_cfloat_float,
733 BUILT_IN_CABSF, "cabsf", ATTR_CONST_NOTHROW_LEAF_LIST);
735 gfc_define_builtin ("__builtin_copysignl", mfunc_longdouble[1],
736 BUILT_IN_COPYSIGNL, "copysignl",
737 ATTR_CONST_NOTHROW_LEAF_LIST);
738 gfc_define_builtin ("__builtin_copysign", mfunc_double[1],
739 BUILT_IN_COPYSIGN, "copysign",
740 ATTR_CONST_NOTHROW_LEAF_LIST);
741 gfc_define_builtin ("__builtin_copysignf", mfunc_float[1],
742 BUILT_IN_COPYSIGNF, "copysignf",
743 ATTR_CONST_NOTHROW_LEAF_LIST);
745 gfc_define_builtin ("__builtin_nextafterl", mfunc_longdouble[1],
746 BUILT_IN_NEXTAFTERL, "nextafterl",
747 ATTR_CONST_NOTHROW_LEAF_LIST);
748 gfc_define_builtin ("__builtin_nextafter", mfunc_double[1],
749 BUILT_IN_NEXTAFTER, "nextafter",
750 ATTR_CONST_NOTHROW_LEAF_LIST);
751 gfc_define_builtin ("__builtin_nextafterf", mfunc_float[1],
752 BUILT_IN_NEXTAFTERF, "nextafterf",
753 ATTR_CONST_NOTHROW_LEAF_LIST);
755 /* Some built-ins depend on rounding mode. Depending on compilation options, they
756 will be "pure" or "const". */
757 attr = flag_rounding_math ? ATTR_PURE_NOTHROW_LEAF_LIST : ATTR_CONST_NOTHROW_LEAF_LIST;
759 gfc_define_builtin ("__builtin_rintl", mfunc_longdouble[0],
760 BUILT_IN_RINTL, "rintl", attr);
761 gfc_define_builtin ("__builtin_rint", mfunc_double[0],
762 BUILT_IN_RINT, "rint", attr);
763 gfc_define_builtin ("__builtin_rintf", mfunc_float[0],
764 BUILT_IN_RINTF, "rintf", attr);
766 gfc_define_builtin ("__builtin_remainderl", mfunc_longdouble[1],
767 BUILT_IN_REMAINDERL, "remainderl", attr);
768 gfc_define_builtin ("__builtin_remainder", mfunc_double[1],
769 BUILT_IN_REMAINDER, "remainder", attr);
770 gfc_define_builtin ("__builtin_remainderf", mfunc_float[1],
771 BUILT_IN_REMAINDERF, "remainderf", attr);
773 gfc_define_builtin ("__builtin_logbl", mfunc_longdouble[0],
774 BUILT_IN_LOGBL, "logbl", ATTR_CONST_NOTHROW_LEAF_LIST);
775 gfc_define_builtin ("__builtin_logb", mfunc_double[0],
776 BUILT_IN_LOGB, "logb", ATTR_CONST_NOTHROW_LEAF_LIST);
777 gfc_define_builtin ("__builtin_logbf", mfunc_float[0],
778 BUILT_IN_LOGBF, "logbf", ATTR_CONST_NOTHROW_LEAF_LIST);
781 gfc_define_builtin ("__builtin_frexpl", mfunc_longdouble[4],
782 BUILT_IN_FREXPL, "frexpl", ATTR_NOTHROW_LEAF_LIST);
783 gfc_define_builtin ("__builtin_frexp", mfunc_double[4],
784 BUILT_IN_FREXP, "frexp", ATTR_NOTHROW_LEAF_LIST);
785 gfc_define_builtin ("__builtin_frexpf", mfunc_float[4],
786 BUILT_IN_FREXPF, "frexpf", ATTR_NOTHROW_LEAF_LIST);
788 gfc_define_builtin ("__builtin_fabsl", mfunc_longdouble[0],
789 BUILT_IN_FABSL, "fabsl", ATTR_CONST_NOTHROW_LEAF_LIST);
790 gfc_define_builtin ("__builtin_fabs", mfunc_double[0],
791 BUILT_IN_FABS, "fabs", ATTR_CONST_NOTHROW_LEAF_LIST);
792 gfc_define_builtin ("__builtin_fabsf", mfunc_float[0],
793 BUILT_IN_FABSF, "fabsf", ATTR_CONST_NOTHROW_LEAF_LIST);
795 gfc_define_builtin ("__builtin_scalbnl", mfunc_longdouble[2],
796 BUILT_IN_SCALBNL, "scalbnl", ATTR_CONST_NOTHROW_LEAF_LIST);
797 gfc_define_builtin ("__builtin_scalbn", mfunc_double[2],
798 BUILT_IN_SCALBN, "scalbn", ATTR_CONST_NOTHROW_LEAF_LIST);
799 gfc_define_builtin ("__builtin_scalbnf", mfunc_float[2],
800 BUILT_IN_SCALBNF, "scalbnf", ATTR_CONST_NOTHROW_LEAF_LIST);
802 gfc_define_builtin ("__builtin_fmodl", mfunc_longdouble[1],
803 BUILT_IN_FMODL, "fmodl", ATTR_CONST_NOTHROW_LEAF_LIST);
804 gfc_define_builtin ("__builtin_fmod", mfunc_double[1],
805 BUILT_IN_FMOD, "fmod", ATTR_CONST_NOTHROW_LEAF_LIST);
806 gfc_define_builtin ("__builtin_fmodf", mfunc_float[1],
807 BUILT_IN_FMODF, "fmodf", ATTR_CONST_NOTHROW_LEAF_LIST);
809 /* iround{f,,l}, lround{f,,l} and llround{f,,l} */
810 ftype = build_function_type_list (integer_type_node,
811 float_type_node, NULL_TREE);
812 gfc_define_builtin("__builtin_iroundf", ftype, BUILT_IN_IROUNDF,
813 "iroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
814 ftype = build_function_type_list (long_integer_type_node,
815 float_type_node, NULL_TREE);
816 gfc_define_builtin ("__builtin_lroundf", ftype, BUILT_IN_LROUNDF,
817 "lroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
818 ftype = build_function_type_list (long_long_integer_type_node,
819 float_type_node, NULL_TREE);
820 gfc_define_builtin ("__builtin_llroundf", ftype, BUILT_IN_LLROUNDF,
821 "llroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
823 ftype = build_function_type_list (integer_type_node,
824 double_type_node, NULL_TREE);
825 gfc_define_builtin("__builtin_iround", ftype, BUILT_IN_IROUND,
826 "iround", ATTR_CONST_NOTHROW_LEAF_LIST);
827 ftype = build_function_type_list (long_integer_type_node,
828 double_type_node, NULL_TREE);
829 gfc_define_builtin ("__builtin_lround", ftype, BUILT_IN_LROUND,
830 "lround", ATTR_CONST_NOTHROW_LEAF_LIST);
831 ftype = build_function_type_list (long_long_integer_type_node,
832 double_type_node, NULL_TREE);
833 gfc_define_builtin ("__builtin_llround", ftype, BUILT_IN_LLROUND,
834 "llround", ATTR_CONST_NOTHROW_LEAF_LIST);
836 ftype = build_function_type_list (integer_type_node,
837 long_double_type_node, NULL_TREE);
838 gfc_define_builtin("__builtin_iroundl", ftype, BUILT_IN_IROUNDL,
839 "iroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
840 ftype = build_function_type_list (long_integer_type_node,
841 long_double_type_node, NULL_TREE);
842 gfc_define_builtin ("__builtin_lroundl", ftype, BUILT_IN_LROUNDL,
843 "lroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
844 ftype = build_function_type_list (long_long_integer_type_node,
845 long_double_type_node, NULL_TREE);
846 gfc_define_builtin ("__builtin_llroundl", ftype, BUILT_IN_LLROUNDL,
847 "llroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
849 /* These are used to implement the ** operator. */
850 gfc_define_builtin ("__builtin_powl", mfunc_longdouble[1],
851 BUILT_IN_POWL, "powl", ATTR_CONST_NOTHROW_LEAF_LIST);
852 gfc_define_builtin ("__builtin_pow", mfunc_double[1],
853 BUILT_IN_POW, "pow", ATTR_CONST_NOTHROW_LEAF_LIST);
854 gfc_define_builtin ("__builtin_powf", mfunc_float[1],
855 BUILT_IN_POWF, "powf", ATTR_CONST_NOTHROW_LEAF_LIST);
856 gfc_define_builtin ("__builtin_cpowl", mfunc_clongdouble[1],
857 BUILT_IN_CPOWL, "cpowl", ATTR_CONST_NOTHROW_LEAF_LIST);
858 gfc_define_builtin ("__builtin_cpow", mfunc_cdouble[1],
859 BUILT_IN_CPOW, "cpow", ATTR_CONST_NOTHROW_LEAF_LIST);
860 gfc_define_builtin ("__builtin_cpowf", mfunc_cfloat[1],
861 BUILT_IN_CPOWF, "cpowf", ATTR_CONST_NOTHROW_LEAF_LIST);
862 gfc_define_builtin ("__builtin_powil", mfunc_longdouble[2],
863 BUILT_IN_POWIL, "powil", ATTR_CONST_NOTHROW_LEAF_LIST);
864 gfc_define_builtin ("__builtin_powi", mfunc_double[2],
865 BUILT_IN_POWI, "powi", ATTR_CONST_NOTHROW_LEAF_LIST);
866 gfc_define_builtin ("__builtin_powif", mfunc_float[2],
867 BUILT_IN_POWIF, "powif", ATTR_CONST_NOTHROW_LEAF_LIST);
870 if (targetm.libc_has_function (function_c99_math_complex))
872 gfc_define_builtin ("__builtin_cbrtl", mfunc_longdouble[0],
873 BUILT_IN_CBRTL, "cbrtl",
874 ATTR_CONST_NOTHROW_LEAF_LIST);
875 gfc_define_builtin ("__builtin_cbrt", mfunc_double[0],
876 BUILT_IN_CBRT, "cbrt",
877 ATTR_CONST_NOTHROW_LEAF_LIST);
878 gfc_define_builtin ("__builtin_cbrtf", mfunc_float[0],
879 BUILT_IN_CBRTF, "cbrtf",
880 ATTR_CONST_NOTHROW_LEAF_LIST);
881 gfc_define_builtin ("__builtin_cexpil", func_longdouble_clongdouble,
882 BUILT_IN_CEXPIL, "cexpil",
883 ATTR_CONST_NOTHROW_LEAF_LIST);
884 gfc_define_builtin ("__builtin_cexpi", func_double_cdouble,
885 BUILT_IN_CEXPI, "cexpi",
886 ATTR_CONST_NOTHROW_LEAF_LIST);
887 gfc_define_builtin ("__builtin_cexpif", func_float_cfloat,
888 BUILT_IN_CEXPIF, "cexpif",
889 ATTR_CONST_NOTHROW_LEAF_LIST);
892 if (targetm.libc_has_function (function_sincos))
894 gfc_define_builtin ("__builtin_sincosl",
895 func_longdouble_longdoublep_longdoublep,
896 BUILT_IN_SINCOSL, "sincosl", ATTR_NOTHROW_LEAF_LIST);
897 gfc_define_builtin ("__builtin_sincos", func_double_doublep_doublep,
898 BUILT_IN_SINCOS, "sincos", ATTR_NOTHROW_LEAF_LIST);
899 gfc_define_builtin ("__builtin_sincosf", func_float_floatp_floatp,
900 BUILT_IN_SINCOSF, "sincosf", ATTR_NOTHROW_LEAF_LIST);
903 /* For LEADZ, TRAILZ, POPCNT and POPPAR. */
904 ftype = build_function_type_list (integer_type_node,
905 unsigned_type_node, NULL_TREE);
906 gfc_define_builtin ("__builtin_clz", ftype, BUILT_IN_CLZ,
907 "__builtin_clz", ATTR_CONST_NOTHROW_LEAF_LIST);
908 gfc_define_builtin ("__builtin_ctz", ftype, BUILT_IN_CTZ,
909 "__builtin_ctz", ATTR_CONST_NOTHROW_LEAF_LIST);
910 gfc_define_builtin ("__builtin_parity", ftype, BUILT_IN_PARITY,
911 "__builtin_parity", ATTR_CONST_NOTHROW_LEAF_LIST);
912 gfc_define_builtin ("__builtin_popcount", ftype, BUILT_IN_POPCOUNT,
913 "__builtin_popcount", ATTR_CONST_NOTHROW_LEAF_LIST);
915 ftype = build_function_type_list (integer_type_node,
916 long_unsigned_type_node, NULL_TREE);
917 gfc_define_builtin ("__builtin_clzl", ftype, BUILT_IN_CLZL,
918 "__builtin_clzl", ATTR_CONST_NOTHROW_LEAF_LIST);
919 gfc_define_builtin ("__builtin_ctzl", ftype, BUILT_IN_CTZL,
920 "__builtin_ctzl", ATTR_CONST_NOTHROW_LEAF_LIST);
921 gfc_define_builtin ("__builtin_parityl", ftype, BUILT_IN_PARITYL,
922 "__builtin_parityl", ATTR_CONST_NOTHROW_LEAF_LIST);
923 gfc_define_builtin ("__builtin_popcountl", ftype, BUILT_IN_POPCOUNTL,
924 "__builtin_popcountl", ATTR_CONST_NOTHROW_LEAF_LIST);
926 ftype = build_function_type_list (integer_type_node,
927 long_long_unsigned_type_node, NULL_TREE);
928 gfc_define_builtin ("__builtin_clzll", ftype, BUILT_IN_CLZLL,
929 "__builtin_clzll", ATTR_CONST_NOTHROW_LEAF_LIST);
930 gfc_define_builtin ("__builtin_ctzll", ftype, BUILT_IN_CTZLL,
931 "__builtin_ctzll", ATTR_CONST_NOTHROW_LEAF_LIST);
932 gfc_define_builtin ("__builtin_parityll", ftype, BUILT_IN_PARITYLL,
933 "__builtin_parityll", ATTR_CONST_NOTHROW_LEAF_LIST);
934 gfc_define_builtin ("__builtin_popcountll", ftype, BUILT_IN_POPCOUNTLL,
935 "__builtin_popcountll", ATTR_CONST_NOTHROW_LEAF_LIST);
937 /* Other builtin functions we use. */
939 ftype = build_function_type_list (long_integer_type_node,
940 long_integer_type_node,
941 long_integer_type_node, NULL_TREE);
942 gfc_define_builtin ("__builtin_expect", ftype, BUILT_IN_EXPECT,
943 "__builtin_expect", ATTR_CONST_NOTHROW_LEAF_LIST);
945 ftype = build_function_type_list (void_type_node,
946 pvoid_type_node, NULL_TREE);
947 gfc_define_builtin ("__builtin_free", ftype, BUILT_IN_FREE,
948 "free", ATTR_NOTHROW_LEAF_LIST);
950 ftype = build_function_type_list (pvoid_type_node,
951 size_type_node, NULL_TREE);
952 gfc_define_builtin ("__builtin_malloc", ftype, BUILT_IN_MALLOC,
953 "malloc", ATTR_NOTHROW_LEAF_MALLOC_LIST);
955 ftype = build_function_type_list (pvoid_type_node, size_type_node,
956 size_type_node, NULL_TREE);
957 gfc_define_builtin ("__builtin_calloc", ftype, BUILT_IN_CALLOC,
958 "calloc", ATTR_NOTHROW_LEAF_MALLOC_LIST);
959 DECL_IS_MALLOC (builtin_decl_explicit (BUILT_IN_CALLOC)) = 1;
961 ftype = build_function_type_list (pvoid_type_node,
962 size_type_node, pvoid_type_node,
963 NULL_TREE);
964 gfc_define_builtin ("__builtin_realloc", ftype, BUILT_IN_REALLOC,
965 "realloc", ATTR_NOTHROW_LEAF_LIST);
967 /* Type-generic floating-point classification built-ins. */
969 ftype = build_function_type (integer_type_node, NULL_TREE);
970 gfc_define_builtin ("__builtin_isfinite", ftype, BUILT_IN_ISFINITE,
971 "__builtin_isfinite", ATTR_CONST_NOTHROW_LEAF_LIST);
972 gfc_define_builtin ("__builtin_isinf", ftype, BUILT_IN_ISINF,
973 "__builtin_isinf", ATTR_CONST_NOTHROW_LEAF_LIST);
974 gfc_define_builtin ("__builtin_isinf_sign", ftype, BUILT_IN_ISINF_SIGN,
975 "__builtin_isinf_sign", ATTR_CONST_NOTHROW_LEAF_LIST);
976 gfc_define_builtin ("__builtin_isnan", ftype, BUILT_IN_ISNAN,
977 "__builtin_isnan", ATTR_CONST_NOTHROW_LEAF_LIST);
978 gfc_define_builtin ("__builtin_isnormal", ftype, BUILT_IN_ISNORMAL,
979 "__builtin_isnormal", ATTR_CONST_NOTHROW_LEAF_LIST);
980 gfc_define_builtin ("__builtin_signbit", ftype, BUILT_IN_SIGNBIT,
981 "__builtin_signbit", ATTR_CONST_NOTHROW_LEAF_LIST);
983 ftype = build_function_type (integer_type_node, NULL_TREE);
984 gfc_define_builtin ("__builtin_isless", ftype, BUILT_IN_ISLESS,
985 "__builtin_isless", ATTR_CONST_NOTHROW_LEAF_LIST);
986 gfc_define_builtin ("__builtin_islessequal", ftype, BUILT_IN_ISLESSEQUAL,
987 "__builtin_islessequal", ATTR_CONST_NOTHROW_LEAF_LIST);
988 gfc_define_builtin ("__builtin_islessgreater", ftype, BUILT_IN_ISLESSGREATER,
989 "__builtin_islessgreater", ATTR_CONST_NOTHROW_LEAF_LIST);
990 gfc_define_builtin ("__builtin_isgreater", ftype, BUILT_IN_ISGREATER,
991 "__builtin_isgreater", ATTR_CONST_NOTHROW_LEAF_LIST);
992 gfc_define_builtin ("__builtin_isgreaterequal", ftype,
993 BUILT_IN_ISGREATEREQUAL, "__builtin_isgreaterequal",
994 ATTR_CONST_NOTHROW_LEAF_LIST);
995 gfc_define_builtin ("__builtin_isunordered", ftype, BUILT_IN_ISUNORDERED,
996 "__builtin_isunordered", ATTR_CONST_NOTHROW_LEAF_LIST);
999 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
1000 builtin_types[(int) ENUM] = VALUE;
1001 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
1002 builtin_types[(int) ENUM] \
1003 = build_function_type_list (builtin_types[(int) RETURN], \
1004 NULL_TREE);
1005 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
1006 builtin_types[(int) ENUM] \
1007 = build_function_type_list (builtin_types[(int) RETURN], \
1008 builtin_types[(int) ARG1], \
1009 NULL_TREE);
1010 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
1011 builtin_types[(int) ENUM] \
1012 = build_function_type_list (builtin_types[(int) RETURN], \
1013 builtin_types[(int) ARG1], \
1014 builtin_types[(int) ARG2], \
1015 NULL_TREE);
1016 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
1017 builtin_types[(int) ENUM] \
1018 = build_function_type_list (builtin_types[(int) RETURN], \
1019 builtin_types[(int) ARG1], \
1020 builtin_types[(int) ARG2], \
1021 builtin_types[(int) ARG3], \
1022 NULL_TREE);
1023 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
1024 builtin_types[(int) ENUM] \
1025 = build_function_type_list (builtin_types[(int) RETURN], \
1026 builtin_types[(int) ARG1], \
1027 builtin_types[(int) ARG2], \
1028 builtin_types[(int) ARG3], \
1029 builtin_types[(int) ARG4], \
1030 NULL_TREE);
1031 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
1032 builtin_types[(int) ENUM] \
1033 = build_function_type_list (builtin_types[(int) RETURN], \
1034 builtin_types[(int) ARG1], \
1035 builtin_types[(int) ARG2], \
1036 builtin_types[(int) ARG3], \
1037 builtin_types[(int) ARG4], \
1038 builtin_types[(int) ARG5], \
1039 NULL_TREE);
1040 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1041 ARG6) \
1042 builtin_types[(int) ENUM] \
1043 = build_function_type_list (builtin_types[(int) RETURN], \
1044 builtin_types[(int) ARG1], \
1045 builtin_types[(int) ARG2], \
1046 builtin_types[(int) ARG3], \
1047 builtin_types[(int) ARG4], \
1048 builtin_types[(int) ARG5], \
1049 builtin_types[(int) ARG6], \
1050 NULL_TREE);
1051 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1052 ARG6, ARG7) \
1053 builtin_types[(int) ENUM] \
1054 = build_function_type_list (builtin_types[(int) RETURN], \
1055 builtin_types[(int) ARG1], \
1056 builtin_types[(int) ARG2], \
1057 builtin_types[(int) ARG3], \
1058 builtin_types[(int) ARG4], \
1059 builtin_types[(int) ARG5], \
1060 builtin_types[(int) ARG6], \
1061 builtin_types[(int) ARG7], \
1062 NULL_TREE);
1063 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1064 ARG6, ARG7, ARG8) \
1065 builtin_types[(int) ENUM] \
1066 = build_function_type_list (builtin_types[(int) RETURN], \
1067 builtin_types[(int) ARG1], \
1068 builtin_types[(int) ARG2], \
1069 builtin_types[(int) ARG3], \
1070 builtin_types[(int) ARG4], \
1071 builtin_types[(int) ARG5], \
1072 builtin_types[(int) ARG6], \
1073 builtin_types[(int) ARG7], \
1074 builtin_types[(int) ARG8], \
1075 NULL_TREE);
1076 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1077 ARG6, ARG7, ARG8, ARG9) \
1078 builtin_types[(int) ENUM] \
1079 = build_function_type_list (builtin_types[(int) RETURN], \
1080 builtin_types[(int) ARG1], \
1081 builtin_types[(int) ARG2], \
1082 builtin_types[(int) ARG3], \
1083 builtin_types[(int) ARG4], \
1084 builtin_types[(int) ARG5], \
1085 builtin_types[(int) ARG6], \
1086 builtin_types[(int) ARG7], \
1087 builtin_types[(int) ARG8], \
1088 builtin_types[(int) ARG9], \
1089 NULL_TREE);
1090 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, \
1091 ARG5, ARG6, ARG7, ARG8, ARG9, ARG10) \
1092 builtin_types[(int) ENUM] \
1093 = build_function_type_list (builtin_types[(int) RETURN], \
1094 builtin_types[(int) ARG1], \
1095 builtin_types[(int) ARG2], \
1096 builtin_types[(int) ARG3], \
1097 builtin_types[(int) ARG4], \
1098 builtin_types[(int) ARG5], \
1099 builtin_types[(int) ARG6], \
1100 builtin_types[(int) ARG7], \
1101 builtin_types[(int) ARG8], \
1102 builtin_types[(int) ARG9], \
1103 builtin_types[(int) ARG10], \
1104 NULL_TREE);
1105 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, \
1106 ARG5, ARG6, ARG7, ARG8, ARG9, ARG10, ARG11)\
1107 builtin_types[(int) ENUM] \
1108 = build_function_type_list (builtin_types[(int) RETURN], \
1109 builtin_types[(int) ARG1], \
1110 builtin_types[(int) ARG2], \
1111 builtin_types[(int) ARG3], \
1112 builtin_types[(int) ARG4], \
1113 builtin_types[(int) ARG5], \
1114 builtin_types[(int) ARG6], \
1115 builtin_types[(int) ARG7], \
1116 builtin_types[(int) ARG8], \
1117 builtin_types[(int) ARG9], \
1118 builtin_types[(int) ARG10], \
1119 builtin_types[(int) ARG11], \
1120 NULL_TREE);
1121 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
1122 builtin_types[(int) ENUM] \
1123 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1124 NULL_TREE);
1125 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
1126 builtin_types[(int) ENUM] \
1127 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1128 builtin_types[(int) ARG1], \
1129 NULL_TREE);
1130 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
1131 builtin_types[(int) ENUM] \
1132 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1133 builtin_types[(int) ARG1], \
1134 builtin_types[(int) ARG2], \
1135 NULL_TREE);
1136 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1137 ARG6) \
1138 builtin_types[(int) ENUM] \
1139 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1140 builtin_types[(int) ARG1], \
1141 builtin_types[(int) ARG2], \
1142 builtin_types[(int) ARG3], \
1143 builtin_types[(int) ARG4], \
1144 builtin_types[(int) ARG5], \
1145 builtin_types[(int) ARG6], \
1146 NULL_TREE);
1147 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1148 ARG6, ARG7) \
1149 builtin_types[(int) ENUM] \
1150 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1151 builtin_types[(int) ARG1], \
1152 builtin_types[(int) ARG2], \
1153 builtin_types[(int) ARG3], \
1154 builtin_types[(int) ARG4], \
1155 builtin_types[(int) ARG5], \
1156 builtin_types[(int) ARG6], \
1157 builtin_types[(int) ARG7], \
1158 NULL_TREE);
1159 #define DEF_POINTER_TYPE(ENUM, TYPE) \
1160 builtin_types[(int) ENUM] \
1161 = build_pointer_type (builtin_types[(int) TYPE]);
1162 #include "types.def"
1163 #undef DEF_PRIMITIVE_TYPE
1164 #undef DEF_FUNCTION_TYPE_0
1165 #undef DEF_FUNCTION_TYPE_1
1166 #undef DEF_FUNCTION_TYPE_2
1167 #undef DEF_FUNCTION_TYPE_3
1168 #undef DEF_FUNCTION_TYPE_4
1169 #undef DEF_FUNCTION_TYPE_5
1170 #undef DEF_FUNCTION_TYPE_6
1171 #undef DEF_FUNCTION_TYPE_7
1172 #undef DEF_FUNCTION_TYPE_8
1173 #undef DEF_FUNCTION_TYPE_10
1174 #undef DEF_FUNCTION_TYPE_VAR_0
1175 #undef DEF_FUNCTION_TYPE_VAR_1
1176 #undef DEF_FUNCTION_TYPE_VAR_2
1177 #undef DEF_FUNCTION_TYPE_VAR_6
1178 #undef DEF_FUNCTION_TYPE_VAR_7
1179 #undef DEF_POINTER_TYPE
1180 builtin_types[(int) BT_LAST] = NULL_TREE;
1182 /* Initialize synchronization builtins. */
1183 #undef DEF_SYNC_BUILTIN
1184 #define DEF_SYNC_BUILTIN(code, name, type, attr) \
1185 gfc_define_builtin (name, builtin_types[type], code, name, \
1186 attr);
1187 #include "../sync-builtins.def"
1188 #undef DEF_SYNC_BUILTIN
1190 if (flag_openacc)
1192 #undef DEF_GOACC_BUILTIN
1193 #define DEF_GOACC_BUILTIN(code, name, type, attr) \
1194 gfc_define_builtin ("__builtin_" name, builtin_types[type], \
1195 code, name, attr);
1196 #undef DEF_GOACC_BUILTIN_COMPILER
1197 #define DEF_GOACC_BUILTIN_COMPILER(code, name, type, attr) \
1198 gfc_define_builtin (name, builtin_types[type], code, name, attr);
1199 #undef DEF_GOMP_BUILTIN
1200 #define DEF_GOMP_BUILTIN(code, name, type, attr) /* ignore */
1201 #include "../omp-builtins.def"
1202 #undef DEF_GOACC_BUILTIN
1203 #undef DEF_GOACC_BUILTIN_COMPILER
1204 #undef DEF_GOMP_BUILTIN
1207 if (flag_openmp || flag_openmp_simd || flag_tree_parallelize_loops)
1209 #undef DEF_GOACC_BUILTIN
1210 #define DEF_GOACC_BUILTIN(code, name, type, attr) /* ignore */
1211 #undef DEF_GOACC_BUILTIN_COMPILER
1212 #define DEF_GOACC_BUILTIN_COMPILER(code, name, type, attr) /* ignore */
1213 #undef DEF_GOMP_BUILTIN
1214 #define DEF_GOMP_BUILTIN(code, name, type, attr) \
1215 gfc_define_builtin ("__builtin_" name, builtin_types[type], \
1216 code, name, attr);
1217 #include "../omp-builtins.def"
1218 #undef DEF_GOACC_BUILTIN
1219 #undef DEF_GOACC_BUILTIN_COMPILER
1220 #undef DEF_GOMP_BUILTIN
1223 gfc_define_builtin ("__builtin_trap", builtin_types[BT_FN_VOID],
1224 BUILT_IN_TRAP, NULL, ATTR_NOTHROW_LEAF_LIST);
1225 TREE_THIS_VOLATILE (builtin_decl_explicit (BUILT_IN_TRAP)) = 1;
1227 ftype = build_varargs_function_type_list (ptr_type_node, const_ptr_type_node,
1228 size_type_node, NULL_TREE);
1229 gfc_define_builtin ("__builtin_assume_aligned", ftype,
1230 BUILT_IN_ASSUME_ALIGNED,
1231 "__builtin_assume_aligned",
1232 ATTR_CONST_NOTHROW_LEAF_LIST);
1234 gfc_define_builtin ("__emutls_get_address",
1235 builtin_types[BT_FN_PTR_PTR],
1236 BUILT_IN_EMUTLS_GET_ADDRESS,
1237 "__emutls_get_address", ATTR_CONST_NOTHROW_LEAF_LIST);
1238 gfc_define_builtin ("__emutls_register_common",
1239 builtin_types[BT_FN_VOID_PTR_WORD_WORD_PTR],
1240 BUILT_IN_EMUTLS_REGISTER_COMMON,
1241 "__emutls_register_common", ATTR_NOTHROW_LEAF_LIST);
1243 build_common_builtin_nodes ();
1244 targetm.init_builtins ();
1247 #undef DEFINE_MATH_BUILTIN_C
1248 #undef DEFINE_MATH_BUILTIN
1250 static void
1251 gfc_init_ts (void)
1253 tree_contains_struct[NAMESPACE_DECL][TS_DECL_NON_COMMON] = 1;
1254 tree_contains_struct[NAMESPACE_DECL][TS_DECL_WITH_VIS] = 1;
1255 tree_contains_struct[NAMESPACE_DECL][TS_DECL_WRTL] = 1;
1256 tree_contains_struct[NAMESPACE_DECL][TS_DECL_COMMON] = 1;
1257 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1260 void
1261 gfc_maybe_initialize_eh (void)
1263 if (!flag_exceptions || gfc_eh_initialized_p)
1264 return;
1266 gfc_eh_initialized_p = true;
1267 using_eh_for_cleanups ();
1271 #include "gt-fortran-f95-lang.h"
1272 #include "gtype-fortran.h"