]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fortran/f95-lang.c
trans-array.c (gfc_trans_array_constructor_value): Use build_constructor instead...
[thirdparty/gcc.git] / gcc / fortran / f95-lang.c
CommitLineData
f36327db 1/* gfortran backend interface
2b65cd83 2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010
6c7a4dfd 3 Free Software Foundation, Inc.
6de9cd9a
DN
4 Contributed by Paul Brook.
5
9fc4d79b 6This file is part of GCC.
6de9cd9a 7
9fc4d79b
TS
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
d234d788 10Software Foundation; either version 3, or (at your option) any later
9fc4d79b 11version.
6de9cd9a 12
9fc4d79b
TS
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
6de9cd9a
DN
17
18You should have received a copy of the GNU General Public License
d234d788
NC
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
6de9cd9a
DN
21
22/* f95-lang.c-- GCC backend interface stuff */
23
24/* declare required prototypes: */
25
26#include "config.h"
d22e4895 27#include "system.h"
6de9cd9a
DN
28#include "ansidecl.h"
29#include "system.h"
30#include "coretypes.h"
31#include "tree.h"
726a989a 32#include "gimple.h"
6de9cd9a
DN
33#include "flags.h"
34#include "langhooks.h"
35#include "langhooks-def.h"
36#include "timevar.h"
37#include "tm.h"
38#include "function.h"
39#include "ggc.h"
40#include "toplev.h"
41#include "target.h"
42#include "debug.h"
43#include "diagnostic.h"
44#include "tree-dump.h"
45#include "cgraph.h"
602b8523
TB
46/* For gfc_maybe_initialize_eh. */
47#include "libfuncs.h"
48#include "expr.h"
49#include "except.h"
6de9cd9a
DN
50
51#include "gfortran.h"
670637ee 52#include "cpp.h"
6de9cd9a
DN
53#include "trans.h"
54#include "trans-types.h"
55#include "trans-const.h"
56
6de9cd9a
DN
57/* Language-dependent contents of an identifier. */
58
d1b38208
TG
59struct GTY(())
60lang_identifier {
6de9cd9a
DN
61 struct tree_identifier common;
62};
63
64/* The resulting tree type. */
65
d1b38208 66union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
726a989a 67 chain_next ("(union lang_tree_node *)TREE_CHAIN (&%h.generic)")))
07beea0d 68
d1b38208 69lang_tree_node {
6de9cd9a
DN
70 union tree_node GTY((tag ("0"),
71 desc ("tree_node_structure (&%h)"))) generic;
72 struct lang_identifier GTY((tag ("1"))) identifier;
73};
74
75/* Save and restore the variables in this file and elsewhere
76 that keep track of the progress of compilation of the current function.
77 Used for nested functions. */
78
d1b38208
TG
79struct GTY(())
80language_function {
6de9cd9a 81 /* struct gfc_language_function base; */
6de9cd9a
DN
82 struct binding_level *binding_level;
83};
84
85/* We don't have a lex/yacc lexer/parser, but toplev expects these to
86 exist anyway. */
87void yyerror (const char *str);
88int yylex (void);
89
90static void gfc_init_decl_processing (void);
91static void gfc_init_builtin_functions (void);
92
93/* Each front end provides its own. */
94static bool gfc_init (void);
95static void gfc_finish (void);
96static void gfc_print_identifier (FILE *, tree, int);
6de9cd9a
DN
97void do_function_end (void);
98int global_bindings_p (void);
30e257e5 99static void clear_binding_stack (void);
6de9cd9a 100static void gfc_be_parse_file (int);
4862826d 101static alias_set_type gfc_get_alias_set (tree);
a64f5186 102static void gfc_init_ts (void);
6de9cd9a
DN
103
104#undef LANG_HOOKS_NAME
105#undef LANG_HOOKS_INIT
106#undef LANG_HOOKS_FINISH
107#undef LANG_HOOKS_INIT_OPTIONS
108#undef LANG_HOOKS_HANDLE_OPTION
109#undef LANG_HOOKS_POST_OPTIONS
110#undef LANG_HOOKS_PRINT_IDENTIFIER
111#undef LANG_HOOKS_PARSE_FILE
6de9cd9a
DN
112#undef LANG_HOOKS_MARK_ADDRESSABLE
113#undef LANG_HOOKS_TYPE_FOR_MODE
114#undef LANG_HOOKS_TYPE_FOR_SIZE
7b9c708f 115#undef LANG_HOOKS_GET_ALIAS_SET
a64f5186 116#undef LANG_HOOKS_INIT_TS
6c7a4dfd
JJ
117#undef LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE
118#undef LANG_HOOKS_OMP_PREDETERMINED_SHARING
cd75853e 119#undef LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR
a68ab351
JJ
120#undef LANG_HOOKS_OMP_CLAUSE_COPY_CTOR
121#undef LANG_HOOKS_OMP_CLAUSE_ASSIGN_OP
122#undef LANG_HOOKS_OMP_CLAUSE_DTOR
6c7a4dfd
JJ
123#undef LANG_HOOKS_OMP_DISREGARD_VALUE_EXPR
124#undef LANG_HOOKS_OMP_PRIVATE_DEBUG_CLAUSE
a68ab351 125#undef LANG_HOOKS_OMP_PRIVATE_OUTER_REF
6c7a4dfd 126#undef LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES
c79efc4d 127#undef LANG_HOOKS_BUILTIN_FUNCTION
fad0afd7 128#undef LANG_HOOKS_GET_ARRAY_DESCR_INFO
6de9cd9a
DN
129
130/* Define lang hooks. */
3135ce84 131#define LANG_HOOKS_NAME "GNU Fortran"
6de9cd9a
DN
132#define LANG_HOOKS_INIT gfc_init
133#define LANG_HOOKS_FINISH gfc_finish
134#define LANG_HOOKS_INIT_OPTIONS gfc_init_options
135#define LANG_HOOKS_HANDLE_OPTION gfc_handle_option
136#define LANG_HOOKS_POST_OPTIONS gfc_post_options
137#define LANG_HOOKS_PRINT_IDENTIFIER gfc_print_identifier
138#define LANG_HOOKS_PARSE_FILE gfc_be_parse_file
a64f5186
JJ
139#define LANG_HOOKS_TYPE_FOR_MODE gfc_type_for_mode
140#define LANG_HOOKS_TYPE_FOR_SIZE gfc_type_for_size
141#define LANG_HOOKS_GET_ALIAS_SET gfc_get_alias_set
142#define LANG_HOOKS_INIT_TS gfc_init_ts
6c7a4dfd
JJ
143#define LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE gfc_omp_privatize_by_reference
144#define LANG_HOOKS_OMP_PREDETERMINED_SHARING gfc_omp_predetermined_sharing
cd75853e 145#define LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR gfc_omp_clause_default_ctor
a68ab351
JJ
146#define LANG_HOOKS_OMP_CLAUSE_COPY_CTOR gfc_omp_clause_copy_ctor
147#define LANG_HOOKS_OMP_CLAUSE_ASSIGN_OP gfc_omp_clause_assign_op
148#define LANG_HOOKS_OMP_CLAUSE_DTOR gfc_omp_clause_dtor
6c7a4dfd
JJ
149#define LANG_HOOKS_OMP_DISREGARD_VALUE_EXPR gfc_omp_disregard_value_expr
150#define LANG_HOOKS_OMP_PRIVATE_DEBUG_CLAUSE gfc_omp_private_debug_clause
a68ab351 151#define LANG_HOOKS_OMP_PRIVATE_OUTER_REF gfc_omp_private_outer_ref
6c7a4dfd
JJ
152#define LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES \
153 gfc_omp_firstprivatize_type_sizes
c79efc4d 154#define LANG_HOOKS_BUILTIN_FUNCTION gfc_builtin_function
fad0afd7 155#define LANG_HOOKS_GET_ARRAY_DESCR_INFO gfc_get_array_descr_info
6de9cd9a 156
4537ec0c 157struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
6de9cd9a 158
6de9cd9a
DN
159#define NULL_BINDING_LEVEL (struct binding_level *) NULL
160
161/* A chain of binding_level structures awaiting reuse. */
162
163static GTY(()) struct binding_level *free_binding_level;
164
165/* The elements of `ridpointers' are identifier nodes
166 for the reserved type names and storage classes.
167 It is indexed by a RID_... value. */
168tree *ridpointers = NULL;
169
602b8523
TB
170/* True means we've initialized exception handling. */
171bool gfc_eh_initialized_p;
172
173
6de9cd9a
DN
174/* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
175 or validate its data type for an `if' or `while' statement or ?..: exp.
176
177 This preparation consists of taking the ordinary
178 representation of an expression expr and producing a valid tree
179 boolean expression describing whether expr is nonzero. We could
180 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
181 but we optimize comparisons, &&, ||, and !.
182
183 The resulting type should always be `boolean_type_node'.
184 This is much simpler than the corresponding C version because we have a
185 distinct boolean type. */
186
187tree
188gfc_truthvalue_conversion (tree expr)
189{
190 switch (TREE_CODE (TREE_TYPE (expr)))
191 {
192 case BOOLEAN_TYPE:
193 if (TREE_TYPE (expr) == boolean_type_node)
194 return expr;
6615c446 195 else if (COMPARISON_CLASS_P (expr))
6de9cd9a
DN
196 {
197 TREE_TYPE (expr) = boolean_type_node;
198 return expr;
199 }
200 else if (TREE_CODE (expr) == NOP_EXPR)
44855d8c
TS
201 return fold_build1 (NOP_EXPR,
202 boolean_type_node, TREE_OPERAND (expr, 0));
6de9cd9a 203 else
44855d8c 204 return fold_build1 (NOP_EXPR, boolean_type_node, expr);
6de9cd9a
DN
205
206 case INTEGER_TYPE:
207 if (TREE_CODE (expr) == INTEGER_CST)
208 return integer_zerop (expr) ? boolean_false_node : boolean_true_node;
209 else
44855d8c
TS
210 return fold_build2 (NE_EXPR, boolean_type_node, expr,
211 build_int_cst (TREE_TYPE (expr), 0));
6de9cd9a
DN
212
213 default:
214 internal_error ("Unexpected type in truthvalue_conversion");
215 }
216}
217
b251af97 218
6de9cd9a
DN
219static void
220gfc_create_decls (void)
221{
222 /* GCC builtins. */
223 gfc_init_builtin_functions ();
224
225 /* Runtime/IO library functions. */
226 gfc_build_builtin_function_decls ();
227
228 gfc_init_constants ();
229}
230
b251af97 231
6de9cd9a
DN
232static void
233gfc_be_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
234{
235 int errors;
236 int warnings;
237
238 gfc_create_decls ();
239 gfc_parse_file ();
240 gfc_generate_constructors ();
241
df2fba9e 242 /* Tell the frontend about any errors. */
6de9cd9a
DN
243 gfc_get_errors (&warnings, &errors);
244 errorcount += errors;
245 warningcount += warnings;
30e257e5
PB
246
247 clear_binding_stack ();
6de9cd9a 248}
b251af97
SK
249
250
6de9cd9a
DN
251/* Initialize everything. */
252
253static bool
254gfc_init (void)
255{
670637ee
DF
256 if (!gfc_cpp_enabled ())
257 {
258 linemap_add (line_table, LC_ENTER, false, gfc_source_file, 1);
259 linemap_add (line_table, LC_RENAME, false, "<built-in>", 0);
260 }
261 else
262 gfc_cpp_init_0 ();
c8cc8542 263
6de9cd9a
DN
264 gfc_init_decl_processing ();
265 gfc_static_ctors = NULL_TREE;
266
670637ee
DF
267 if (gfc_cpp_enabled ())
268 gfc_cpp_init ();
269
6de9cd9a
DN
270 gfc_init_1 ();
271
e0bcf78c
TS
272 if (gfc_new_file () != SUCCESS)
273 fatal_error ("can't open input file: %s", gfc_source_file);
670637ee 274
6de9cd9a
DN
275 return true;
276}
277
278
279static void
280gfc_finish (void)
281{
670637ee 282 gfc_cpp_done ();
6de9cd9a
DN
283 gfc_done_1 ();
284 gfc_release_include_path ();
285 return;
286}
287
288static void
289gfc_print_identifier (FILE * file ATTRIBUTE_UNUSED,
290 tree node ATTRIBUTE_UNUSED,
291 int indent ATTRIBUTE_UNUSED)
292{
293 return;
294}
b251af97 295
6de9cd9a
DN
296
297/* These functions and variables deal with binding contours. We only
298 need these functions for the list of PARM_DECLs, but we leave the
299 functions more general; these are a simplified version of the
300 functions from GNAT. */
301
b251af97
SK
302/* For each binding contour we allocate a binding_level structure which
303 records the entities defined or declared in that contour. Contours
304 include:
6de9cd9a
DN
305
306 the global one
307 one for each subprogram definition
308 one for each compound statement (declare block)
309
310 Binding contours are used to create GCC tree BLOCK nodes. */
311
d1b38208
TG
312struct GTY(())
313binding_level {
6de9cd9a
DN
314 /* A chain of ..._DECL nodes for all variables, constants, functions,
315 parameters and type declarations. These ..._DECL nodes are chained
316 through the TREE_CHAIN field. Note that these ..._DECL nodes are stored
317 in the reverse of the order supplied to be compatible with the
318 back-end. */
319 tree names;
320 /* For each level (except the global one), a chain of BLOCK nodes for all
321 the levels that were entered and exited one level down from this one. */
322 tree blocks;
f7b529fa 323 /* The binding level containing this one (the enclosing binding level). */
6de9cd9a
DN
324 struct binding_level *level_chain;
325};
326
327/* The binding level currently in effect. */
328static GTY(()) struct binding_level *current_binding_level = NULL;
329
330/* The outermost binding level. This binding level is created when the
331 compiler is started and it will exist through the entire compilation. */
332static GTY(()) struct binding_level *global_binding_level;
333
334/* Binding level structures are initialized by copying this one. */
9dcf6e73 335static struct binding_level clear_binding_level = { NULL, NULL, NULL };
b251af97
SK
336
337
13795658 338/* Return nonzero if we are currently in the global binding level. */
6de9cd9a
DN
339
340int
341global_bindings_p (void)
342{
343 return current_binding_level == global_binding_level ? -1 : 0;
344}
345
346tree
347getdecls (void)
348{
349 return current_binding_level->names;
350}
351
352/* Enter a new binding level. The input parameter is ignored, but has to be
353 specified for back-end compatibility. */
354
355void
356pushlevel (int ignore ATTRIBUTE_UNUSED)
357{
358 struct binding_level *newlevel
359 = (struct binding_level *) ggc_alloc (sizeof (struct binding_level));
360
361 *newlevel = clear_binding_level;
362
363 /* Add this level to the front of the chain (stack) of levels that are
364 active. */
365 newlevel->level_chain = current_binding_level;
366 current_binding_level = newlevel;
367}
368
369/* Exit a binding level.
370 Pop the level off, and restore the state of the identifier-decl mappings
371 that were in effect when this level was entered.
372
373 If KEEP is nonzero, this level had explicit declarations, so
374 and create a "block" (a BLOCK node) for the level
375 to record its declarations and subblocks for symbol table output.
376
377 If FUNCTIONBODY is nonzero, this level is the body of a function,
378 so create a block as if KEEP were set and also clear out all
379 label names.
380
381 If REVERSE is nonzero, reverse the order of decls before putting
382 them into the BLOCK. */
383
384tree
385poplevel (int keep, int reverse, int functionbody)
386{
1f2959f0 387 /* Points to a BLOCK tree node. This is the BLOCK node constructed for the
6de9cd9a
DN
388 binding level that we are about to exit and which is returned by this
389 routine. */
390 tree block_node = NULL_TREE;
391 tree decl_chain;
392 tree subblock_chain = current_binding_level->blocks;
393 tree subblock_node;
6de9cd9a
DN
394
395 /* Reverse the list of XXXX_DECL nodes if desired. Note that the ..._DECL
396 nodes chained through the `names' field of current_binding_level are in
1f2959f0 397 reverse order except for PARM_DECL node, which are explicitly stored in
6de9cd9a
DN
398 the right order. */
399 decl_chain = (reverse) ? nreverse (current_binding_level->names)
b251af97 400 : current_binding_level->names;
6de9cd9a 401
6de9cd9a
DN
402 /* If there were any declarations in the current binding level, or if this
403 binding level is a function body, or if there are any nested blocks then
404 create a BLOCK node to record them for the life of this function. */
9dcf6e73 405 if (keep || functionbody)
22e8617b 406 block_node = build_block (keep ? decl_chain : 0, subblock_chain, 0, 0);
6de9cd9a
DN
407
408 /* Record the BLOCK node just built as the subblock its enclosing scope. */
409 for (subblock_node = subblock_chain; subblock_node;
410 subblock_node = TREE_CHAIN (subblock_node))
411 BLOCK_SUPERCONTEXT (subblock_node) = block_node;
412
413 /* Clear out the meanings of the local variables of this level. */
414
415 for (subblock_node = decl_chain; subblock_node;
416 subblock_node = TREE_CHAIN (subblock_node))
417 if (DECL_NAME (subblock_node) != 0)
418 /* If the identifier was used or addressed via a local extern decl,
f7b529fa 419 don't forget that fact. */
6de9cd9a
DN
420 if (DECL_EXTERNAL (subblock_node))
421 {
422 if (TREE_USED (subblock_node))
423 TREE_USED (DECL_NAME (subblock_node)) = 1;
424 if (TREE_ADDRESSABLE (subblock_node))
425 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (subblock_node)) = 1;
426 }
427
428 /* Pop the current level. */
429 current_binding_level = current_binding_level->level_chain;
430
431 if (functionbody)
c7c79a09
JJ
432 /* This is the top level block of a function. */
433 DECL_INITIAL (current_function_decl) = block_node;
77092cda
JJ
434 else if (current_binding_level == global_binding_level)
435 /* When using gfc_start_block/gfc_finish_block from middle-end hooks,
df2fba9e 436 don't add newly created BLOCKs as subblocks of global_binding_level. */
77092cda 437 ;
6de9cd9a
DN
438 else if (block_node)
439 {
9dcf6e73
JM
440 current_binding_level->blocks
441 = chainon (current_binding_level->blocks, block_node);
6de9cd9a
DN
442 }
443
444 /* If we did not make a block for the level just exited, any blocks made for
445 inner levels (since they cannot be recorded as subblocks in that level)
446 must be carried forward so they will later become subblocks of something
447 else. */
448 else if (subblock_chain)
449 current_binding_level->blocks
450 = chainon (current_binding_level->blocks, subblock_chain);
451 if (block_node)
452 TREE_USED (block_node) = 1;
453
454 return block_node;
455}
b251af97
SK
456
457
6de9cd9a 458/* Records a ..._DECL node DECL as belonging to the current lexical scope.
f7b529fa 459 Returns the ..._DECL node. */
6de9cd9a
DN
460
461tree
462pushdecl (tree decl)
463{
464 /* External objects aren't nested, other objects may be. */
465 if ((DECL_EXTERNAL (decl)) || (decl == current_function_decl))
466 DECL_CONTEXT (decl) = 0;
467 else
468 DECL_CONTEXT (decl) = current_function_decl;
469
470 /* Put the declaration on the list. The list of declarations is in reverse
471 order. The list will be reversed later if necessary. This needs to be
472 this way for compatibility with the back-end. */
473
474 TREE_CHAIN (decl) = current_binding_level->names;
475 current_binding_level->names = decl;
476
69de3b83 477 /* For the declaration of a type, set its name if it is not already set. */
6de9cd9a
DN
478
479 if (TREE_CODE (decl) == TYPE_DECL && TYPE_NAME (TREE_TYPE (decl)) == 0)
480 {
481 if (DECL_SOURCE_LINE (decl) == 0)
482 TYPE_NAME (TREE_TYPE (decl)) = decl;
483 else
484 TYPE_NAME (TREE_TYPE (decl)) = DECL_NAME (decl);
485 }
486
487 return decl;
488}
489
490
491/* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL. */
492
493tree
494pushdecl_top_level (tree x)
495{
496 tree t;
497 struct binding_level *b = current_binding_level;
498
499 current_binding_level = global_binding_level;
500 t = pushdecl (x);
501 current_binding_level = b;
502 return t;
503}
504
505
9dcf6e73
JM
506/* Clear the binding stack. */
507static void
30e257e5 508clear_binding_stack (void)
9dcf6e73
JM
509{
510 while (!global_bindings_p ())
511 poplevel (0, 0, 0);
512}
513
514
6de9cd9a
DN
515#ifndef CHAR_TYPE_SIZE
516#define CHAR_TYPE_SIZE BITS_PER_UNIT
517#endif
518
519#ifndef INT_TYPE_SIZE
520#define INT_TYPE_SIZE BITS_PER_WORD
521#endif
522
523#undef SIZE_TYPE
524#define SIZE_TYPE "long unsigned int"
525
526/* Create tree nodes for the basic scalar types of Fortran 95,
527 and some nodes representing standard constants (0, 1, (void *) 0).
528 Initialize the global binding level.
529 Make definitions for built-in primitive functions. */
530static void
531gfc_init_decl_processing (void)
532{
533 current_function_decl = NULL;
6de9cd9a
DN
534 current_binding_level = NULL_BINDING_LEVEL;
535 free_binding_level = NULL_BINDING_LEVEL;
536
537 /* Make the binding_level structure for global names. We move all
538 variables that are in a COMMON block to this binding level. */
539 pushlevel (0);
540 global_binding_level = current_binding_level;
541
542 /* Build common tree nodes. char_type_node is unsigned because we
543 only use it for actual characters, not for INTEGER(1). Also, we
f7b529fa 544 want double_type_node to actually have double precision. */
3b9e5d95 545 build_common_tree_nodes (false);
df2fba9e 546 /* x86_64 mingw32 has a sizetype of "unsigned long long", most other hosts
fcdb5d68
KT
547 have a sizetype of "unsigned long". Therefore choose the correct size
548 in mostly target independent way. */
6384205f 549 if (TYPE_MODE (long_unsigned_type_node) == ptr_mode)
fcdb5d68 550 set_sizetype (long_unsigned_type_node);
6384205f 551 else if (TYPE_MODE (long_long_unsigned_type_node) == ptr_mode)
fcdb5d68
KT
552 set_sizetype (long_long_unsigned_type_node);
553 else
554 set_sizetype (long_unsigned_type_node);
6de9cd9a 555 build_common_tree_nodes_2 (0);
24cc1193 556 void_list_node = build_tree_list (NULL_TREE, void_type_node);
6de9cd9a
DN
557
558 /* Set up F95 type nodes. */
5e8e542f 559 gfc_init_kinds ();
6de9cd9a
DN
560 gfc_init_types ();
561}
562
b251af97 563
7b9c708f
JJ
564/* Return the typed-based alias set for T, which may be an expression
565 or a type. Return -1 if we don't do anything special. */
566
4862826d 567static alias_set_type
7b9c708f
JJ
568gfc_get_alias_set (tree t)
569{
570 tree u;
571
572 /* Permit type-punning when accessing an EQUIVALENCEd variable or
573 mixed type entry master's return value. */
574 for (u = t; handled_component_p (u); u = TREE_OPERAND (u, 0))
575 if (TREE_CODE (u) == COMPONENT_REF
576 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
577 return 0;
578
579 return -1;
580}
581
b251af97 582
6de9cd9a
DN
583/* press the big red button - garbage (ggc) collection is on */
584
585int ggc_p = 1;
586
1f2959f0 587/* Builtin function initialization. */
6de9cd9a 588
6de9cd9a 589tree
c79efc4d 590gfc_builtin_function (tree decl)
6de9cd9a 591{
0e6df31e 592 make_decl_rtl (decl);
6de9cd9a 593 pushdecl (decl);
6de9cd9a
DN
594 return decl;
595}
596
597
598static void
b251af97 599gfc_define_builtin (const char *name,
6de9cd9a
DN
600 tree type,
601 int code,
b251af97 602 const char *library_name,
6de9cd9a
DN
603 bool const_p)
604{
605 tree decl;
606
c79efc4d
RÁE
607 decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
608 library_name, NULL_TREE);
6de9cd9a
DN
609 if (const_p)
610 TREE_READONLY (decl) = 1;
2b65cd83 611 TREE_NOTHROW (decl) = 1;
6de9cd9a
DN
612
613 built_in_decls[code] = decl;
614 implicit_built_in_decls[code] = decl;
615}
616
617
e8525382 618#define DO_DEFINE_MATH_BUILTIN(code, name, argtype, tbase) \
644cb69f
FXC
619 gfc_define_builtin ("__builtin_" name "l", tbase##longdouble[argtype], \
620 BUILT_IN_ ## code ## L, name "l", true); \
e8525382 621 gfc_define_builtin ("__builtin_" name, tbase##double[argtype], \
6de9cd9a 622 BUILT_IN_ ## code, name, true); \
e8525382 623 gfc_define_builtin ("__builtin_" name "f", tbase##float[argtype], \
6de9cd9a
DN
624 BUILT_IN_ ## code ## F, name "f", true);
625
e8525382
SK
626#define DEFINE_MATH_BUILTIN(code, name, argtype) \
627 DO_DEFINE_MATH_BUILTIN (code, name, argtype, mfunc_)
628
e8525382 629#define DEFINE_MATH_BUILTIN_C(code, name, argtype) \
644cb69f
FXC
630 DO_DEFINE_MATH_BUILTIN (code, name, argtype, mfunc_) \
631 DO_DEFINE_MATH_BUILTIN (C##code, "c" name, argtype, mfunc_c)
e8525382
SK
632
633
634/* Create function types for builtin functions. */
635
636static void
b251af97 637build_builtin_fntypes (tree *fntype, tree type)
e8525382
SK
638{
639 tree tmp;
640
641 /* type (*) (type) */
fb2d50f5 642 tmp = tree_cons (NULL_TREE, type, void_list_node);
e8525382
SK
643 fntype[0] = build_function_type (type, tmp);
644 /* type (*) (type, type) */
fb2d50f5 645 tmp = tree_cons (NULL_TREE, type, tmp);
e8525382
SK
646 fntype[1] = build_function_type (type, tmp);
647 /* type (*) (int, type) */
648 tmp = tree_cons (NULL_TREE, integer_type_node, void_list_node);
649 tmp = tree_cons (NULL_TREE, type, tmp);
650 fntype[2] = build_function_type (type, tmp);
b5a4419c
FXC
651 /* type (*) (void) */
652 fntype[3] = build_function_type (type, void_list_node);
653 /* type (*) (type, &int) */
654 tmp = tree_cons (NULL_TREE, type, void_list_node);
655 tmp = tree_cons (NULL_TREE, build_pointer_type (integer_type_node), tmp);
656 fntype[4] = build_function_type (type, tmp);
657 /* type (*) (type, int) */
658 tmp = tree_cons (NULL_TREE, type, void_list_node);
659 tmp = tree_cons (NULL_TREE, integer_type_node, tmp);
660 fntype[5] = build_function_type (type, tmp);
e8525382
SK
661}
662
b251af97 663
6c7a4dfd
JJ
664static tree
665builtin_type_for_size (int size, bool unsignedp)
666{
667 tree type = lang_hooks.types.type_for_size (size, unsignedp);
668 return type ? type : error_mark_node;
669}
e8525382 670
1f2959f0 671/* Initialization of builtin function nodes. */
e8525382 672
6de9cd9a
DN
673static void
674gfc_init_builtin_functions (void)
675{
6c7a4dfd
JJ
676 enum builtin_type
677 {
678#define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
679#define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
680#define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
681#define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
682#define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
683#define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
684#define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
685#define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
686#define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
687#define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
688#define DEF_POINTER_TYPE(NAME, TYPE) NAME,
689#include "types.def"
690#undef DEF_PRIMITIVE_TYPE
691#undef DEF_FUNCTION_TYPE_0
692#undef DEF_FUNCTION_TYPE_1
693#undef DEF_FUNCTION_TYPE_2
694#undef DEF_FUNCTION_TYPE_3
695#undef DEF_FUNCTION_TYPE_4
696#undef DEF_FUNCTION_TYPE_5
697#undef DEF_FUNCTION_TYPE_6
698#undef DEF_FUNCTION_TYPE_7
699#undef DEF_FUNCTION_TYPE_VAR_0
700#undef DEF_POINTER_TYPE
701 BT_LAST
702 };
703 typedef enum builtin_type builtin_type;
704 enum
705 {
706 /* So far we need just these 2 attribute types. */
707 ATTR_NOTHROW_LIST,
708 ATTR_CONST_NOTHROW_LIST
709 };
710
b5a4419c
FXC
711 tree mfunc_float[6];
712 tree mfunc_double[6];
713 tree mfunc_longdouble[6];
714 tree mfunc_cfloat[6];
715 tree mfunc_cdouble[6];
716 tree mfunc_clongdouble[6];
3a53e165
RG
717 tree func_cfloat_float, func_float_cfloat;
718 tree func_cdouble_double, func_double_cdouble;
719 tree func_clongdouble_longdouble, func_longdouble_clongdouble;
720 tree func_float_floatp_floatp;
721 tree func_double_doublep_doublep;
722 tree func_longdouble_longdoublep_longdoublep;
723 tree ftype, ptype;
94f548c2 724 tree tmp, type;
6c7a4dfd 725 tree builtin_types[(int) BT_LAST + 1];
6de9cd9a 726
e8525382
SK
727 build_builtin_fntypes (mfunc_float, float_type_node);
728 build_builtin_fntypes (mfunc_double, double_type_node);
644cb69f 729 build_builtin_fntypes (mfunc_longdouble, long_double_type_node);
e8525382
SK
730 build_builtin_fntypes (mfunc_cfloat, complex_float_type_node);
731 build_builtin_fntypes (mfunc_cdouble, complex_double_type_node);
644cb69f 732 build_builtin_fntypes (mfunc_clongdouble, complex_long_double_type_node);
e8525382 733
ead6d15f
AP
734 tmp = tree_cons (NULL_TREE, complex_float_type_node, void_list_node);
735 func_cfloat_float = build_function_type (float_type_node, tmp);
6de9cd9a 736
3a53e165
RG
737 tmp = tree_cons (NULL_TREE, float_type_node, void_list_node);
738 func_float_cfloat = build_function_type (complex_float_type_node, tmp);
739
ead6d15f
AP
740 tmp = tree_cons (NULL_TREE, complex_double_type_node, void_list_node);
741 func_cdouble_double = build_function_type (double_type_node, tmp);
6de9cd9a 742
3a53e165
RG
743 tmp = tree_cons (NULL_TREE, double_type_node, void_list_node);
744 func_double_cdouble = build_function_type (complex_double_type_node, tmp);
745
644cb69f
FXC
746 tmp = tree_cons (NULL_TREE, complex_long_double_type_node, void_list_node);
747 func_clongdouble_longdouble =
748 build_function_type (long_double_type_node, tmp);
749
3a53e165
RG
750 tmp = tree_cons (NULL_TREE, long_double_type_node, void_list_node);
751 func_longdouble_clongdouble =
752 build_function_type (complex_long_double_type_node, tmp);
753
754 ptype = build_pointer_type (float_type_node);
755 tmp = tree_cons (NULL_TREE, float_type_node,
756 tree_cons (NULL_TREE, ptype,
fc207c37 757 tree_cons (NULL_TREE, ptype, void_list_node)));
3a53e165
RG
758 func_float_floatp_floatp =
759 build_function_type (void_type_node, tmp);
760
761 ptype = build_pointer_type (double_type_node);
762 tmp = tree_cons (NULL_TREE, double_type_node,
763 tree_cons (NULL_TREE, ptype,
fc207c37 764 tree_cons (NULL_TREE, ptype, void_list_node)));
3a53e165
RG
765 func_double_doublep_doublep =
766 build_function_type (void_type_node, tmp);
767
768 ptype = build_pointer_type (long_double_type_node);
769 tmp = tree_cons (NULL_TREE, long_double_type_node,
770 tree_cons (NULL_TREE, ptype,
fc207c37 771 tree_cons (NULL_TREE, ptype, void_list_node)));
3a53e165
RG
772 func_longdouble_longdoublep_longdoublep =
773 build_function_type (void_type_node, tmp);
774
6de9cd9a
DN
775#include "mathbuiltins.def"
776
e7dc5b4f 777 /* We define these separately as the fortran versions have different
6de9cd9a 778 semantics (they return an integer type) */
644cb69f
FXC
779 gfc_define_builtin ("__builtin_roundl", mfunc_longdouble[0],
780 BUILT_IN_ROUNDL, "roundl", true);
6de9cd9a
DN
781 gfc_define_builtin ("__builtin_round", mfunc_double[0],
782 BUILT_IN_ROUND, "round", true);
783 gfc_define_builtin ("__builtin_roundf", mfunc_float[0],
784 BUILT_IN_ROUNDF, "roundf", true);
644cb69f
FXC
785
786 gfc_define_builtin ("__builtin_truncl", mfunc_longdouble[0],
787 BUILT_IN_TRUNCL, "truncl", true);
e743d142
TS
788 gfc_define_builtin ("__builtin_trunc", mfunc_double[0],
789 BUILT_IN_TRUNC, "trunc", true);
790 gfc_define_builtin ("__builtin_truncf", mfunc_float[0],
791 BUILT_IN_TRUNCF, "truncf", true);
792
644cb69f
FXC
793 gfc_define_builtin ("__builtin_cabsl", func_clongdouble_longdouble,
794 BUILT_IN_CABSL, "cabsl", true);
ead6d15f
AP
795 gfc_define_builtin ("__builtin_cabs", func_cdouble_double,
796 BUILT_IN_CABS, "cabs", true);
797 gfc_define_builtin ("__builtin_cabsf", func_cfloat_float,
798 BUILT_IN_CABSF, "cabsf", true);
c6a912da 799
644cb69f
FXC
800 gfc_define_builtin ("__builtin_copysignl", mfunc_longdouble[1],
801 BUILT_IN_COPYSIGNL, "copysignl", true);
ead6d15f
AP
802 gfc_define_builtin ("__builtin_copysign", mfunc_double[1],
803 BUILT_IN_COPYSIGN, "copysign", true);
804 gfc_define_builtin ("__builtin_copysignf", mfunc_float[1],
805 BUILT_IN_COPYSIGNF, "copysignf", true);
58b6e047 806
b5a4419c
FXC
807 gfc_define_builtin ("__builtin_nextafterl", mfunc_longdouble[1],
808 BUILT_IN_NEXTAFTERL, "nextafterl", true);
809 gfc_define_builtin ("__builtin_nextafter", mfunc_double[1],
810 BUILT_IN_NEXTAFTER, "nextafter", true);
811 gfc_define_builtin ("__builtin_nextafterf", mfunc_float[1],
812 BUILT_IN_NEXTAFTERF, "nextafterf", true);
813
814 gfc_define_builtin ("__builtin_frexpl", mfunc_longdouble[4],
815 BUILT_IN_FREXPL, "frexpl", false);
816 gfc_define_builtin ("__builtin_frexp", mfunc_double[4],
817 BUILT_IN_FREXP, "frexp", false);
818 gfc_define_builtin ("__builtin_frexpf", mfunc_float[4],
819 BUILT_IN_FREXPF, "frexpf", false);
820
821 gfc_define_builtin ("__builtin_fabsl", mfunc_longdouble[0],
822 BUILT_IN_FABSL, "fabsl", true);
823 gfc_define_builtin ("__builtin_fabs", mfunc_double[0],
824 BUILT_IN_FABS, "fabs", true);
825 gfc_define_builtin ("__builtin_fabsf", mfunc_float[0],
826 BUILT_IN_FABSF, "fabsf", true);
827
828 gfc_define_builtin ("__builtin_scalbnl", mfunc_longdouble[5],
829 BUILT_IN_SCALBNL, "scalbnl", true);
830 gfc_define_builtin ("__builtin_scalbn", mfunc_double[5],
831 BUILT_IN_SCALBN, "scalbn", true);
832 gfc_define_builtin ("__builtin_scalbnf", mfunc_float[5],
833 BUILT_IN_SCALBNF, "scalbnf", true);
834
58b6e047
PT
835 gfc_define_builtin ("__builtin_fmodl", mfunc_longdouble[1],
836 BUILT_IN_FMODL, "fmodl", true);
837 gfc_define_builtin ("__builtin_fmod", mfunc_double[1],
838 BUILT_IN_FMOD, "fmod", true);
839 gfc_define_builtin ("__builtin_fmodf", mfunc_float[1],
840 BUILT_IN_FMODF, "fmodf", true);
6de9cd9a 841
f6d53468
UW
842 gfc_define_builtin ("__builtin_huge_vall", mfunc_longdouble[3],
843 BUILT_IN_HUGE_VALL, "__builtin_huge_vall", true);
844 gfc_define_builtin ("__builtin_huge_val", mfunc_double[3],
845 BUILT_IN_HUGE_VAL, "__builtin_huge_val", true);
846 gfc_define_builtin ("__builtin_huge_valf", mfunc_float[3],
847 BUILT_IN_HUGE_VALF, "__builtin_huge_valf", true);
b5a4419c 848
94f548c2
FXC
849 /* lround{f,,l} and llround{f,,l} */
850 type = tree_cons (NULL_TREE, float_type_node, void_list_node);
851 tmp = build_function_type (long_integer_type_node, type);
852 gfc_define_builtin ("__builtin_lroundf", tmp, BUILT_IN_LROUNDF,
853 "lroundf", true);
854 tmp = build_function_type (long_long_integer_type_node, type);
855 gfc_define_builtin ("__builtin_llroundf", tmp, BUILT_IN_LLROUNDF,
856 "llroundf", true);
857
858 type = tree_cons (NULL_TREE, double_type_node, void_list_node);
859 tmp = build_function_type (long_integer_type_node, type);
860 gfc_define_builtin ("__builtin_lround", tmp, BUILT_IN_LROUND,
861 "lround", true);
862 tmp = build_function_type (long_long_integer_type_node, type);
863 gfc_define_builtin ("__builtin_llround", tmp, BUILT_IN_LLROUND,
864 "llround", true);
865
866 type = tree_cons (NULL_TREE, long_double_type_node, void_list_node);
867 tmp = build_function_type (long_integer_type_node, type);
868 gfc_define_builtin ("__builtin_lroundl", tmp, BUILT_IN_LROUNDL,
869 "lroundl", true);
870 tmp = build_function_type (long_long_integer_type_node, type);
871 gfc_define_builtin ("__builtin_llroundl", tmp, BUILT_IN_LLROUNDL,
872 "llroundl", true);
873
5b200ac2 874 /* These are used to implement the ** operator. */
644cb69f
FXC
875 gfc_define_builtin ("__builtin_powl", mfunc_longdouble[1],
876 BUILT_IN_POWL, "powl", true);
c7d78bbe 877 gfc_define_builtin ("__builtin_pow", mfunc_double[1],
5b200ac2 878 BUILT_IN_POW, "pow", true);
c7d78bbe 879 gfc_define_builtin ("__builtin_powf", mfunc_float[1],
5b200ac2 880 BUILT_IN_POWF, "powf", true);
fb220235
FXC
881 gfc_define_builtin ("__builtin_cpowl", mfunc_clongdouble[1],
882 BUILT_IN_CPOWL, "cpowl", true);
883 gfc_define_builtin ("__builtin_cpow", mfunc_cdouble[1],
884 BUILT_IN_CPOW, "cpow", true);
885 gfc_define_builtin ("__builtin_cpowf", mfunc_cfloat[1],
886 BUILT_IN_CPOWF, "cpowf", true);
31c97dfe
JB
887 gfc_define_builtin ("__builtin_powil", mfunc_longdouble[2],
888 BUILT_IN_POWIL, "powil", true);
889 gfc_define_builtin ("__builtin_powi", mfunc_double[2],
890 BUILT_IN_POWI, "powi", true);
891 gfc_define_builtin ("__builtin_powif", mfunc_float[2],
892 BUILT_IN_POWIF, "powif", true);
893
5b200ac2 894
3a53e165
RG
895 if (TARGET_C99_FUNCTIONS)
896 {
897 gfc_define_builtin ("__builtin_cbrtl", mfunc_longdouble[0],
898 BUILT_IN_CBRTL, "cbrtl", true);
899 gfc_define_builtin ("__builtin_cbrt", mfunc_double[0],
900 BUILT_IN_CBRT, "cbrt", true);
901 gfc_define_builtin ("__builtin_cbrtf", mfunc_float[0],
902 BUILT_IN_CBRTF, "cbrtf", true);
903 gfc_define_builtin ("__builtin_cexpil", func_longdouble_clongdouble,
904 BUILT_IN_CEXPIL, "cexpil", true);
905 gfc_define_builtin ("__builtin_cexpi", func_double_cdouble,
906 BUILT_IN_CEXPI, "cexpi", true);
907 gfc_define_builtin ("__builtin_cexpif", func_float_cfloat,
908 BUILT_IN_CEXPIF, "cexpif", true);
909 }
910
911 if (TARGET_HAS_SINCOS)
912 {
913 gfc_define_builtin ("__builtin_sincosl",
914 func_longdouble_longdoublep_longdoublep,
915 BUILT_IN_SINCOSL, "sincosl", false);
916 gfc_define_builtin ("__builtin_sincos", func_double_doublep_doublep,
917 BUILT_IN_SINCOS, "sincos", false);
918 gfc_define_builtin ("__builtin_sincosf", func_float_floatp_floatp,
919 BUILT_IN_SINCOSF, "sincosf", false);
920 }
921
414f00e9
SB
922 /* For LEADZ / TRAILZ. */
923 tmp = tree_cons (NULL_TREE, unsigned_type_node, void_list_node);
924 ftype = build_function_type (integer_type_node, tmp);
925 gfc_define_builtin ("__builtin_clz", ftype, BUILT_IN_CLZ,
926 "__builtin_clz", true);
927
928 tmp = tree_cons (NULL_TREE, long_unsigned_type_node, void_list_node);
929 ftype = build_function_type (integer_type_node, tmp);
930 gfc_define_builtin ("__builtin_clzl", ftype, BUILT_IN_CLZL,
931 "__builtin_clzl", true);
932
933 tmp = tree_cons (NULL_TREE, long_long_unsigned_type_node, void_list_node);
934 ftype = build_function_type (integer_type_node, tmp);
935 gfc_define_builtin ("__builtin_clzll", ftype, BUILT_IN_CLZLL,
936 "__builtin_clzll", true);
937
938 tmp = tree_cons (NULL_TREE, unsigned_type_node, void_list_node);
939 ftype = build_function_type (integer_type_node, tmp);
940 gfc_define_builtin ("__builtin_ctz", ftype, BUILT_IN_CTZ,
941 "__builtin_ctz", true);
942
943 tmp = tree_cons (NULL_TREE, long_unsigned_type_node, void_list_node);
944 ftype = build_function_type (integer_type_node, tmp);
945 gfc_define_builtin ("__builtin_ctzl", ftype, BUILT_IN_CTZL,
946 "__builtin_ctzl", true);
947
948 tmp = tree_cons (NULL_TREE, long_long_unsigned_type_node, void_list_node);
949 ftype = build_function_type (integer_type_node, tmp);
950 gfc_define_builtin ("__builtin_ctzll", ftype, BUILT_IN_CTZLL,
951 "__builtin_ctzll", true);
952
6de9cd9a
DN
953 /* Other builtin functions we use. */
954
c6a912da
RH
955 tmp = tree_cons (NULL_TREE, long_integer_type_node, void_list_node);
956 tmp = tree_cons (NULL_TREE, long_integer_type_node, tmp);
957 ftype = build_function_type (long_integer_type_node, tmp);
958 gfc_define_builtin ("__builtin_expect", ftype, BUILT_IN_EXPECT,
959 "__builtin_expect", true);
ef9312c1 960
1529b8d9
FXC
961 tmp = tree_cons (NULL_TREE, pvoid_type_node, void_list_node);
962 ftype = build_function_type (void_type_node, tmp);
963 gfc_define_builtin ("__builtin_free", ftype, BUILT_IN_FREE,
964 "free", false);
965
966 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
967 ftype = build_function_type (pvoid_type_node, tmp);
968 gfc_define_builtin ("__builtin_malloc", ftype, BUILT_IN_MALLOC,
969 "malloc", false);
970 DECL_IS_MALLOC (built_in_decls[BUILT_IN_MALLOC]) = 1;
971
4376b7cf
FXC
972 tmp = tree_cons (NULL_TREE, pvoid_type_node, void_list_node);
973 tmp = tree_cons (NULL_TREE, size_type_node, tmp);
974 ftype = build_function_type (pvoid_type_node, tmp);
975 gfc_define_builtin ("__builtin_realloc", ftype, BUILT_IN_REALLOC,
976 "realloc", false);
977
5fcb93f1
FXC
978 tmp = tree_cons (NULL_TREE, void_type_node, void_list_node);
979 ftype = build_function_type (integer_type_node, tmp);
980 gfc_define_builtin ("__builtin_isnan", ftype, BUILT_IN_ISNAN,
981 "__builtin_isnan", true);
982
6c7a4dfd
JJ
983#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
984 builtin_types[(int) ENUM] = VALUE;
985#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
986 builtin_types[(int) ENUM] \
987 = build_function_type (builtin_types[(int) RETURN], \
988 void_list_node);
989#define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
990 builtin_types[(int) ENUM] \
991 = build_function_type (builtin_types[(int) RETURN], \
992 tree_cons (NULL_TREE, \
993 builtin_types[(int) ARG1], \
994 void_list_node));
995#define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
996 builtin_types[(int) ENUM] \
997 = build_function_type \
998 (builtin_types[(int) RETURN], \
999 tree_cons (NULL_TREE, \
1000 builtin_types[(int) ARG1], \
1001 tree_cons (NULL_TREE, \
1002 builtin_types[(int) ARG2], \
1003 void_list_node)));
1004#define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
1005 builtin_types[(int) ENUM] \
1006 = build_function_type \
1007 (builtin_types[(int) RETURN], \
1008 tree_cons (NULL_TREE, \
1009 builtin_types[(int) ARG1], \
1010 tree_cons (NULL_TREE, \
1011 builtin_types[(int) ARG2], \
1012 tree_cons (NULL_TREE, \
1013 builtin_types[(int) ARG3], \
1014 void_list_node))));
1015#define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
1016 builtin_types[(int) ENUM] \
1017 = build_function_type \
1018 (builtin_types[(int) RETURN], \
1019 tree_cons (NULL_TREE, \
1020 builtin_types[(int) ARG1], \
1021 tree_cons (NULL_TREE, \
1022 builtin_types[(int) ARG2], \
1023 tree_cons \
1024 (NULL_TREE, \
1025 builtin_types[(int) ARG3], \
1026 tree_cons (NULL_TREE, \
1027 builtin_types[(int) ARG4], \
1028 void_list_node)))));
1029#define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
1030 builtin_types[(int) ENUM] \
1031 = build_function_type \
1032 (builtin_types[(int) RETURN], \
1033 tree_cons (NULL_TREE, \
1034 builtin_types[(int) ARG1], \
1035 tree_cons (NULL_TREE, \
1036 builtin_types[(int) ARG2], \
1037 tree_cons \
1038 (NULL_TREE, \
1039 builtin_types[(int) ARG3], \
1040 tree_cons (NULL_TREE, \
1041 builtin_types[(int) ARG4], \
1042 tree_cons (NULL_TREE, \
1043 builtin_types[(int) ARG5],\
1044 void_list_node))))));
1045#define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1046 ARG6) \
1047 builtin_types[(int) ENUM] \
1048 = build_function_type \
1049 (builtin_types[(int) RETURN], \
1050 tree_cons (NULL_TREE, \
1051 builtin_types[(int) ARG1], \
1052 tree_cons (NULL_TREE, \
1053 builtin_types[(int) ARG2], \
1054 tree_cons \
1055 (NULL_TREE, \
1056 builtin_types[(int) ARG3], \
1057 tree_cons \
1058 (NULL_TREE, \
1059 builtin_types[(int) ARG4], \
1060 tree_cons (NULL_TREE, \
1061 builtin_types[(int) ARG5], \
1062 tree_cons (NULL_TREE, \
1063 builtin_types[(int) ARG6],\
1064 void_list_node)))))));
1065#define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1066 ARG6, ARG7) \
1067 builtin_types[(int) ENUM] \
1068 = build_function_type \
1069 (builtin_types[(int) RETURN], \
1070 tree_cons (NULL_TREE, \
1071 builtin_types[(int) ARG1], \
1072 tree_cons (NULL_TREE, \
1073 builtin_types[(int) ARG2], \
1074 tree_cons \
1075 (NULL_TREE, \
1076 builtin_types[(int) ARG3], \
1077 tree_cons \
1078 (NULL_TREE, \
1079 builtin_types[(int) ARG4], \
1080 tree_cons (NULL_TREE, \
1081 builtin_types[(int) ARG5], \
1082 tree_cons (NULL_TREE, \
1083 builtin_types[(int) ARG6],\
1084 tree_cons (NULL_TREE, \
1085 builtin_types[(int) ARG6], \
1086 void_list_node))))))));
1087#define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
1088 builtin_types[(int) ENUM] \
1089 = build_function_type (builtin_types[(int) RETURN], NULL_TREE);
1090#define DEF_POINTER_TYPE(ENUM, TYPE) \
1091 builtin_types[(int) ENUM] \
1092 = build_pointer_type (builtin_types[(int) TYPE]);
1093#include "types.def"
1094#undef DEF_PRIMITIVE_TYPE
1095#undef DEF_FUNCTION_TYPE_1
1096#undef DEF_FUNCTION_TYPE_2
1097#undef DEF_FUNCTION_TYPE_3
1098#undef DEF_FUNCTION_TYPE_4
1099#undef DEF_FUNCTION_TYPE_5
1100#undef DEF_FUNCTION_TYPE_6
1101#undef DEF_FUNCTION_TYPE_VAR_0
1102#undef DEF_POINTER_TYPE
1103 builtin_types[(int) BT_LAST] = NULL_TREE;
1104
1105 /* Initialize synchronization builtins. */
1106#undef DEF_SYNC_BUILTIN
1107#define DEF_SYNC_BUILTIN(code, name, type, attr) \
1108 gfc_define_builtin (name, builtin_types[type], code, name, \
1109 attr == ATTR_CONST_NOTHROW_LIST);
1110#include "../sync-builtins.def"
1111#undef DEF_SYNC_BUILTIN
1112
e0e8ce7a 1113 if (gfc_option.flag_openmp || flag_tree_parallelize_loops)
6c7a4dfd
JJ
1114 {
1115#undef DEF_GOMP_BUILTIN
1116#define DEF_GOMP_BUILTIN(code, name, type, attr) \
1117 gfc_define_builtin ("__builtin_" name, builtin_types[type], \
1118 code, name, attr == ATTR_CONST_NOTHROW_LIST);
1119#include "../omp-builtins.def"
1120#undef DEF_GOMP_BUILTIN
1121 }
1122
1123 gfc_define_builtin ("__builtin_trap", builtin_types[BT_FN_VOID],
1124 BUILT_IN_TRAP, NULL, false);
1125 TREE_THIS_VOLATILE (built_in_decls[BUILT_IN_TRAP]) = 1;
1126
8893239d
RH
1127 gfc_define_builtin ("__emutls_get_address",
1128 builtin_types[BT_FN_PTR_PTR], BUILT_IN_EMUTLS_GET_ADDRESS,
1129 "__emutls_get_address", true);
1130 gfc_define_builtin ("__emutls_register_common",
1131 builtin_types[BT_FN_VOID_PTR_WORD_WORD_PTR],
1132 BUILT_IN_EMUTLS_REGISTER_COMMON,
1133 "__emutls_register_common", false);
1134
384c400a 1135 build_common_builtin_nodes ();
ef9312c1 1136 targetm.init_builtins ();
6de9cd9a
DN
1137}
1138
e8525382 1139#undef DEFINE_MATH_BUILTIN_C
6de9cd9a
DN
1140#undef DEFINE_MATH_BUILTIN
1141
a64f5186
JJ
1142static void
1143gfc_init_ts (void)
1144{
1145 tree_contains_struct[NAMESPACE_DECL][TS_DECL_NON_COMMON] = 1;
1146 tree_contains_struct[NAMESPACE_DECL][TS_DECL_WITH_VIS] = 1;
1147 tree_contains_struct[NAMESPACE_DECL][TS_DECL_WRTL] = 1;
1148 tree_contains_struct[NAMESPACE_DECL][TS_DECL_COMMON] = 1;
1149 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1150}
1151
602b8523
TB
1152void
1153gfc_maybe_initialize_eh (void)
1154{
1155 if (!flag_exceptions || gfc_eh_initialized_p)
1156 return;
1157
1158 gfc_eh_initialized_p = true;
602b8523
TB
1159 using_eh_for_cleanups ();
1160}
1161
1162
6de9cd9a
DN
1163#include "gt-fortran-f95-lang.h"
1164#include "gtype-fortran.h"