]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fortran/f95-lang.cc
Update copyright years.
[thirdparty/gcc.git] / gcc / fortran / f95-lang.cc
CommitLineData
f36327db 1/* gfortran backend interface
a945c346 2 Copyright (C) 2000-2024 Free Software Foundation, Inc.
6de9cd9a
DN
3 Contributed by Paul Brook.
4
9fc4d79b 5This file is part of GCC.
6de9cd9a 6
9fc4d79b
TS
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
d234d788 9Software Foundation; either version 3, or (at your option) any later
9fc4d79b 10version.
6de9cd9a 11
9fc4d79b
TS
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
6de9cd9a
DN
16
17You should have received a copy of the GNU General Public License
d234d788
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
6de9cd9a 20
e53b6e56 21/* f95-lang.cc-- GCC backend interface stuff */
6de9cd9a
DN
22
23/* declare required prototypes: */
24
25#include "config.h"
d22e4895 26#include "system.h"
6de9cd9a 27#include "coretypes.h"
2adfab87
AM
28#include "target.h"
29#include "function.h"
30#include "tree.h"
8e54f6d3 31#include "gfortran.h"
2adfab87 32#include "trans.h"
e5e391d6 33#include "stringpool.h"
2adfab87 34#include "diagnostic.h" /* For errorcount/warningcount */
6de9cd9a
DN
35#include "langhooks.h"
36#include "langhooks-def.h"
6de9cd9a 37#include "toplev.h"
6de9cd9a 38#include "debug.h"
670637ee 39#include "cpp.h"
6de9cd9a
DN
40#include "trans-types.h"
41#include "trans-const.h"
7fa24687 42#include "attribs.h"
6de9cd9a 43
6de9cd9a
DN
44/* Language-dependent contents of an identifier. */
45
d1b38208
TG
46struct GTY(())
47lang_identifier {
6de9cd9a
DN
48 struct tree_identifier common;
49};
50
51/* The resulting tree type. */
52
d1b38208 53union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
81f653d6 54 chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
d1b38208 55lang_tree_node {
6de9cd9a
DN
56 union tree_node GTY((tag ("0"),
57 desc ("tree_node_structure (&%h)"))) generic;
58 struct lang_identifier GTY((tag ("1"))) identifier;
59};
60
61/* Save and restore the variables in this file and elsewhere
62 that keep track of the progress of compilation of the current function.
63 Used for nested functions. */
64
d1b38208
TG
65struct GTY(())
66language_function {
6de9cd9a 67 /* struct gfc_language_function base; */
6de9cd9a
DN
68 struct binding_level *binding_level;
69};
70
6de9cd9a
DN
71static void gfc_init_decl_processing (void);
72static void gfc_init_builtin_functions (void);
87a60f68 73static bool global_bindings_p (void);
6de9cd9a
DN
74
75/* Each front end provides its own. */
76static bool gfc_init (void);
77static void gfc_finish (void);
b37421c6 78static void gfc_be_parse_file (void);
a64f5186 79static void gfc_init_ts (void);
87a60f68 80static tree gfc_builtin_function (tree);
6de9cd9a 81
f014c653
JJ
82/* Handle an "omp declare target" attribute; arguments as in
83 struct attribute_spec.handler. */
84static tree
85gfc_handle_omp_declare_target_attribute (tree *, tree, tree, int, bool *)
86{
87 return NULL_TREE;
88}
89
90/* Table of valid Fortran attributes. */
7fa24687 91static const attribute_spec gfc_gnu_attributes[] =
f014c653 92{
4849deb1
JJ
93 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
94 affects_type_identity, handler, exclude } */
e03436e7 95 { "omp declare target", 0, -1, true, false, false, false,
4849deb1
JJ
96 gfc_handle_omp_declare_target_attribute, NULL },
97 { "omp declare target link", 0, 0, true, false, false, false,
98 gfc_handle_omp_declare_target_attribute, NULL },
99 { "oacc function", 0, -1, true, false, false, false,
100 gfc_handle_omp_declare_target_attribute, NULL },
7fa24687
RS
101};
102
103static const scoped_attribute_specs gfc_gnu_attribute_table =
104{
1dad3df1 105 "gnu", { gfc_gnu_attributes }
7fa24687
RS
106};
107
108static const scoped_attribute_specs *const gfc_attribute_table[] =
109{
110 &gfc_gnu_attribute_table
f014c653
JJ
111};
112
6cf276dd
DM
113/* Get a value for the SARIF v2.1.0 "artifact.sourceLanguage" property,
114 based on the list in SARIF v2.1.0 Appendix J. */
115
116static const char *
117gfc_get_sarif_source_language (const char *)
118{
119 return "fortran";
120}
121
6de9cd9a
DN
122#undef LANG_HOOKS_NAME
123#undef LANG_HOOKS_INIT
124#undef LANG_HOOKS_FINISH
7a9bf9a4 125#undef LANG_HOOKS_OPTION_LANG_MASK
a75bfaa6 126#undef LANG_HOOKS_INIT_OPTIONS_STRUCT
6de9cd9a
DN
127#undef LANG_HOOKS_INIT_OPTIONS
128#undef LANG_HOOKS_HANDLE_OPTION
129#undef LANG_HOOKS_POST_OPTIONS
6de9cd9a 130#undef LANG_HOOKS_PARSE_FILE
6de9cd9a
DN
131#undef LANG_HOOKS_MARK_ADDRESSABLE
132#undef LANG_HOOKS_TYPE_FOR_MODE
133#undef LANG_HOOKS_TYPE_FOR_SIZE
a64f5186 134#undef LANG_HOOKS_INIT_TS
92e63bd2 135#undef LANG_HOOKS_OMP_ARRAY_DATA
49d1a2f9 136#undef LANG_HOOKS_OMP_ARRAY_SIZE
08c14aaa 137#undef LANG_HOOKS_OMP_IS_ALLOCATABLE_OR_PTR
a2c26c50 138#undef LANG_HOOKS_OMP_CHECK_OPTIONAL_ARGUMENT
6c7a4dfd
JJ
139#undef LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE
140#undef LANG_HOOKS_OMP_PREDETERMINED_SHARING
93535a2b 141#undef LANG_HOOKS_OMP_PREDETERMINED_MAPPING
79943d19 142#undef LANG_HOOKS_OMP_REPORT_DECL
cd75853e 143#undef LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR
a68ab351
JJ
144#undef LANG_HOOKS_OMP_CLAUSE_COPY_CTOR
145#undef LANG_HOOKS_OMP_CLAUSE_ASSIGN_OP
da6f124d 146#undef LANG_HOOKS_OMP_CLAUSE_LINEAR_CTOR
a68ab351 147#undef LANG_HOOKS_OMP_CLAUSE_DTOR
f014c653 148#undef LANG_HOOKS_OMP_FINISH_CLAUSE
1de31913
TB
149#undef LANG_HOOKS_OMP_ALLOCATABLE_P
150#undef LANG_HOOKS_OMP_SCALAR_TARGET_P
b4c3a85b 151#undef LANG_HOOKS_OMP_SCALAR_P
6c7a4dfd
JJ
152#undef LANG_HOOKS_OMP_DISREGARD_VALUE_EXPR
153#undef LANG_HOOKS_OMP_PRIVATE_DEBUG_CLAUSE
a68ab351 154#undef LANG_HOOKS_OMP_PRIVATE_OUTER_REF
6c7a4dfd 155#undef LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES
c79efc4d 156#undef LANG_HOOKS_BUILTIN_FUNCTION
87a60f68 157#undef LANG_HOOKS_BUILTIN_FUNCTION
fad0afd7 158#undef LANG_HOOKS_GET_ARRAY_DESCR_INFO
f014c653 159#undef LANG_HOOKS_ATTRIBUTE_TABLE
6cf276dd 160#undef LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE
6de9cd9a
DN
161
162/* Define lang hooks. */
3135ce84 163#define LANG_HOOKS_NAME "GNU Fortran"
6de9cd9a
DN
164#define LANG_HOOKS_INIT gfc_init
165#define LANG_HOOKS_FINISH gfc_finish
7a9bf9a4 166#define LANG_HOOKS_OPTION_LANG_MASK gfc_option_lang_mask
a75bfaa6 167#define LANG_HOOKS_INIT_OPTIONS_STRUCT gfc_init_options_struct
6de9cd9a
DN
168#define LANG_HOOKS_INIT_OPTIONS gfc_init_options
169#define LANG_HOOKS_HANDLE_OPTION gfc_handle_option
170#define LANG_HOOKS_POST_OPTIONS gfc_post_options
6de9cd9a 171#define LANG_HOOKS_PARSE_FILE gfc_be_parse_file
a64f5186
JJ
172#define LANG_HOOKS_TYPE_FOR_MODE gfc_type_for_mode
173#define LANG_HOOKS_TYPE_FOR_SIZE gfc_type_for_size
a64f5186 174#define LANG_HOOKS_INIT_TS gfc_init_ts
92e63bd2 175#define LANG_HOOKS_OMP_ARRAY_DATA gfc_omp_array_data
49d1a2f9 176#define LANG_HOOKS_OMP_ARRAY_SIZE gfc_omp_array_size
08c14aaa 177#define LANG_HOOKS_OMP_IS_ALLOCATABLE_OR_PTR gfc_omp_is_allocatable_or_ptr
a2c26c50 178#define LANG_HOOKS_OMP_CHECK_OPTIONAL_ARGUMENT gfc_omp_check_optional_argument
6c7a4dfd
JJ
179#define LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE gfc_omp_privatize_by_reference
180#define LANG_HOOKS_OMP_PREDETERMINED_SHARING gfc_omp_predetermined_sharing
93535a2b 181#define LANG_HOOKS_OMP_PREDETERMINED_MAPPING gfc_omp_predetermined_mapping
79943d19 182#define LANG_HOOKS_OMP_REPORT_DECL gfc_omp_report_decl
cd75853e 183#define LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR gfc_omp_clause_default_ctor
a68ab351
JJ
184#define LANG_HOOKS_OMP_CLAUSE_COPY_CTOR gfc_omp_clause_copy_ctor
185#define LANG_HOOKS_OMP_CLAUSE_ASSIGN_OP gfc_omp_clause_assign_op
da6f124d 186#define LANG_HOOKS_OMP_CLAUSE_LINEAR_CTOR gfc_omp_clause_linear_ctor
a68ab351 187#define LANG_HOOKS_OMP_CLAUSE_DTOR gfc_omp_clause_dtor
f014c653 188#define LANG_HOOKS_OMP_FINISH_CLAUSE gfc_omp_finish_clause
1de31913 189#define LANG_HOOKS_OMP_ALLOCATABLE_P gfc_omp_allocatable_p
b4c3a85b 190#define LANG_HOOKS_OMP_SCALAR_P gfc_omp_scalar_p
1de31913 191#define LANG_HOOKS_OMP_SCALAR_TARGET_P gfc_omp_scalar_target_p
6c7a4dfd
JJ
192#define LANG_HOOKS_OMP_DISREGARD_VALUE_EXPR gfc_omp_disregard_value_expr
193#define LANG_HOOKS_OMP_PRIVATE_DEBUG_CLAUSE gfc_omp_private_debug_clause
a68ab351 194#define LANG_HOOKS_OMP_PRIVATE_OUTER_REF gfc_omp_private_outer_ref
6c7a4dfd
JJ
195#define LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES \
196 gfc_omp_firstprivatize_type_sizes
f014c653
JJ
197#define LANG_HOOKS_BUILTIN_FUNCTION gfc_builtin_function
198#define LANG_HOOKS_GET_ARRAY_DESCR_INFO gfc_get_array_descr_info
199#define LANG_HOOKS_ATTRIBUTE_TABLE gfc_attribute_table
6cf276dd 200#define LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE gfc_get_sarif_source_language
6de9cd9a 201
4537ec0c 202struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
6de9cd9a 203
6de9cd9a
DN
204#define NULL_BINDING_LEVEL (struct binding_level *) NULL
205
206/* A chain of binding_level structures awaiting reuse. */
207
208static GTY(()) struct binding_level *free_binding_level;
209
602b8523 210/* True means we've initialized exception handling. */
87a60f68 211static bool gfc_eh_initialized_p;
602b8523 212
e5b16755
RG
213/* The current translation unit. */
214static GTY(()) tree current_translation_unit;
215
602b8523 216
6de9cd9a
DN
217static void
218gfc_create_decls (void)
219{
220 /* GCC builtins. */
221 gfc_init_builtin_functions ();
222
223 /* Runtime/IO library functions. */
224 gfc_build_builtin_function_decls ();
225
226 gfc_init_constants ();
e5b16755
RG
227
228 /* Build our translation-unit decl. */
e5e391d6
MO
229 current_translation_unit
230 = build_translation_unit_decl (get_identifier (main_input_filename));
881a5e60 231 debug_hooks->register_main_translation_unit (current_translation_unit);
6de9cd9a
DN
232}
233
b251af97 234
6de9cd9a 235static void
b37421c6 236gfc_be_parse_file (void)
6de9cd9a 237{
6de9cd9a
DN
238 gfc_create_decls ();
239 gfc_parse_file ();
240 gfc_generate_constructors ();
241
87a60f68
SB
242 /* Clear the binding level stack. */
243 while (!global_bindings_p ())
244 poplevel (0, 0);
3aa34c1d 245
d7438551
AH
246 /* Finalize all of the globals.
247
248 Emulated tls lowering needs to see all TLS variables before we
249 call finalize_compilation_unit. The C/C++ front ends manage this
250 by calling decl_rest_of_compilation on each global and static
251 variable as they are seen. The Fortran front end waits until
252 here. */
253 for (tree decl = getdecls (); decl ; decl = DECL_CHAIN (decl))
254 rest_of_decl_compilation (decl, true, true);
255
3aa34c1d
MLI
256 /* Switch to the default tree diagnostics here, because there may be
257 diagnostics before gfc_finish(). */
258 gfc_diagnostics_finish ();
d7438551
AH
259
260 global_decl_processing ();
6de9cd9a 261}
b251af97
SK
262
263
6de9cd9a
DN
264/* Initialize everything. */
265
266static bool
267gfc_init (void)
268{
670637ee
DF
269 if (!gfc_cpp_enabled ())
270 {
271 linemap_add (line_table, LC_ENTER, false, gfc_source_file, 1);
15d31555 272 linemap_add (line_table, LC_RENAME, false, special_fname_builtin (), 0);
670637ee
DF
273 }
274 else
275 gfc_cpp_init_0 ();
c8cc8542 276
6de9cd9a
DN
277 gfc_init_decl_processing ();
278 gfc_static_ctors = NULL_TREE;
279
670637ee
DF
280 if (gfc_cpp_enabled ())
281 gfc_cpp_init ();
282
6de9cd9a
DN
283 gfc_init_1 ();
284
83aac698
TB
285 /* Calls exit in case of a fail. */
286 gfc_new_file ();
670637ee 287
566916e6
TB
288 if (flag_preprocess_only)
289 return false;
290
6de9cd9a
DN
291 return true;
292}
293
294
295static void
296gfc_finish (void)
297{
670637ee 298 gfc_cpp_done ();
6de9cd9a
DN
299 gfc_done_1 ();
300 gfc_release_include_path ();
301 return;
302}
303
6de9cd9a
DN
304/* These functions and variables deal with binding contours. We only
305 need these functions for the list of PARM_DECLs, but we leave the
306 functions more general; these are a simplified version of the
307 functions from GNAT. */
308
b251af97
SK
309/* For each binding contour we allocate a binding_level structure which
310 records the entities defined or declared in that contour. Contours
311 include:
6de9cd9a
DN
312
313 the global one
314 one for each subprogram definition
315 one for each compound statement (declare block)
316
317 Binding contours are used to create GCC tree BLOCK nodes. */
318
d1b38208
TG
319struct GTY(())
320binding_level {
6de9cd9a
DN
321 /* A chain of ..._DECL nodes for all variables, constants, functions,
322 parameters and type declarations. These ..._DECL nodes are chained
87a60f68 323 through the DECL_CHAIN field. */
6de9cd9a
DN
324 tree names;
325 /* For each level (except the global one), a chain of BLOCK nodes for all
326 the levels that were entered and exited one level down from this one. */
327 tree blocks;
f7b529fa 328 /* The binding level containing this one (the enclosing binding level). */
6de9cd9a 329 struct binding_level *level_chain;
79a592e3
JJ
330 /* True if nreverse has been already called on names; if false, names
331 are ordered from newest declaration to oldest one. */
332 bool reversed;
6de9cd9a
DN
333};
334
335/* The binding level currently in effect. */
336static GTY(()) struct binding_level *current_binding_level = NULL;
337
338/* The outermost binding level. This binding level is created when the
339 compiler is started and it will exist through the entire compilation. */
340static GTY(()) struct binding_level *global_binding_level;
341
342/* Binding level structures are initialized by copying this one. */
79a592e3 343static struct binding_level clear_binding_level = { NULL, NULL, NULL, false };
b251af97
SK
344
345
c99c0026 346/* Return true if we are in the global binding level. */
6de9cd9a 347
c99c0026 348bool
6de9cd9a
DN
349global_bindings_p (void)
350{
c99c0026 351 return current_binding_level == global_binding_level;
6de9cd9a
DN
352}
353
354tree
355getdecls (void)
356{
79a592e3
JJ
357 if (!current_binding_level->reversed)
358 {
359 current_binding_level->reversed = true;
360 current_binding_level->names = nreverse (current_binding_level->names);
361 }
6de9cd9a
DN
362 return current_binding_level->names;
363}
364
1cc0e193 365/* Enter a new binding level. */
6de9cd9a
DN
366
367void
87a60f68 368pushlevel (void)
6de9cd9a 369{
766090c2 370 struct binding_level *newlevel = ggc_alloc<binding_level> ();
6de9cd9a
DN
371
372 *newlevel = clear_binding_level;
373
374 /* Add this level to the front of the chain (stack) of levels that are
375 active. */
376 newlevel->level_chain = current_binding_level;
377 current_binding_level = newlevel;
378}
379
380/* Exit a binding level.
381 Pop the level off, and restore the state of the identifier-decl mappings
382 that were in effect when this level was entered.
383
384 If KEEP is nonzero, this level had explicit declarations, so
385 and create a "block" (a BLOCK node) for the level
386 to record its declarations and subblocks for symbol table output.
387
388 If FUNCTIONBODY is nonzero, this level is the body of a function,
389 so create a block as if KEEP were set and also clear out all
87a60f68 390 label names. */
6de9cd9a
DN
391
392tree
87a60f68 393poplevel (int keep, int functionbody)
6de9cd9a 394{
1f2959f0 395 /* Points to a BLOCK tree node. This is the BLOCK node constructed for the
6de9cd9a
DN
396 binding level that we are about to exit and which is returned by this
397 routine. */
398 tree block_node = NULL_TREE;
79a592e3 399 tree decl_chain = getdecls ();
6de9cd9a
DN
400 tree subblock_chain = current_binding_level->blocks;
401 tree subblock_node;
6de9cd9a 402
6de9cd9a
DN
403 /* If there were any declarations in the current binding level, or if this
404 binding level is a function body, or if there are any nested blocks then
405 create a BLOCK node to record them for the life of this function. */
9dcf6e73 406 if (keep || functionbody)
22e8617b 407 block_node = build_block (keep ? decl_chain : 0, subblock_chain, 0, 0);
6de9cd9a
DN
408
409 /* Record the BLOCK node just built as the subblock its enclosing scope. */
410 for (subblock_node = subblock_chain; subblock_node;
61e46a7d 411 subblock_node = BLOCK_CHAIN (subblock_node))
6de9cd9a
DN
412 BLOCK_SUPERCONTEXT (subblock_node) = block_node;
413
414 /* Clear out the meanings of the local variables of this level. */
415
416 for (subblock_node = decl_chain; subblock_node;
910ad8de 417 subblock_node = DECL_CHAIN (subblock_node))
6de9cd9a
DN
418 if (DECL_NAME (subblock_node) != 0)
419 /* If the identifier was used or addressed via a local extern decl,
f7b529fa 420 don't forget that fact. */
6de9cd9a
DN
421 if (DECL_EXTERNAL (subblock_node))
422 {
423 if (TREE_USED (subblock_node))
424 TREE_USED (DECL_NAME (subblock_node)) = 1;
425 if (TREE_ADDRESSABLE (subblock_node))
426 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (subblock_node)) = 1;
427 }
428
429 /* Pop the current level. */
430 current_binding_level = current_binding_level->level_chain;
431
432 if (functionbody)
1cc0e193 433 /* This is the top level block of a function. */
c7c79a09 434 DECL_INITIAL (current_function_decl) = block_node;
77092cda
JJ
435 else if (current_binding_level == global_binding_level)
436 /* When using gfc_start_block/gfc_finish_block from middle-end hooks,
df2fba9e 437 don't add newly created BLOCKs as subblocks of global_binding_level. */
77092cda 438 ;
6de9cd9a
DN
439 else if (block_node)
440 {
9dcf6e73 441 current_binding_level->blocks
61e46a7d 442 = block_chainon (current_binding_level->blocks, block_node);
6de9cd9a
DN
443 }
444
445 /* If we did not make a block for the level just exited, any blocks made for
446 inner levels (since they cannot be recorded as subblocks in that level)
447 must be carried forward so they will later become subblocks of something
448 else. */
449 else if (subblock_chain)
450 current_binding_level->blocks
61e46a7d 451 = block_chainon (current_binding_level->blocks, subblock_chain);
6de9cd9a
DN
452 if (block_node)
453 TREE_USED (block_node) = 1;
454
455 return block_node;
456}
b251af97
SK
457
458
6de9cd9a 459/* Records a ..._DECL node DECL as belonging to the current lexical scope.
f7b529fa 460 Returns the ..._DECL node. */
6de9cd9a
DN
461
462tree
463pushdecl (tree decl)
464{
5b1cce91 465 if (global_bindings_p ())
e5b16755 466 DECL_CONTEXT (decl) = current_translation_unit;
6de9cd9a 467 else
5b1cce91
RG
468 {
469 /* External objects aren't nested. For debug info insert a copy
470 of the decl into the binding level. */
471 if (DECL_EXTERNAL (decl))
472 {
473 tree orig = decl;
474 decl = copy_node (decl);
475 DECL_CONTEXT (orig) = NULL_TREE;
476 }
477 DECL_CONTEXT (decl) = current_function_decl;
478 }
6de9cd9a 479
87a60f68 480 /* Put the declaration on the list. */
910ad8de 481 DECL_CHAIN (decl) = current_binding_level->names;
6de9cd9a
DN
482 current_binding_level->names = decl;
483
69de3b83 484 /* For the declaration of a type, set its name if it is not already set. */
6de9cd9a
DN
485
486 if (TREE_CODE (decl) == TYPE_DECL && TYPE_NAME (TREE_TYPE (decl)) == 0)
487 {
488 if (DECL_SOURCE_LINE (decl) == 0)
489 TYPE_NAME (TREE_TYPE (decl)) = decl;
490 else
491 TYPE_NAME (TREE_TYPE (decl)) = DECL_NAME (decl);
492 }
493
494 return decl;
495}
496
497
498/* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL. */
499
500tree
501pushdecl_top_level (tree x)
502{
503 tree t;
504 struct binding_level *b = current_binding_level;
505
506 current_binding_level = global_binding_level;
507 t = pushdecl (x);
508 current_binding_level = b;
509 return t;
510}
511
6de9cd9a
DN
512#ifndef CHAR_TYPE_SIZE
513#define CHAR_TYPE_SIZE BITS_PER_UNIT
514#endif
515
516#ifndef INT_TYPE_SIZE
517#define INT_TYPE_SIZE BITS_PER_WORD
518#endif
519
520#undef SIZE_TYPE
521#define SIZE_TYPE "long unsigned int"
522
523/* Create tree nodes for the basic scalar types of Fortran 95,
524 and some nodes representing standard constants (0, 1, (void *) 0).
525 Initialize the global binding level.
526 Make definitions for built-in primitive functions. */
527static void
528gfc_init_decl_processing (void)
529{
530 current_function_decl = NULL;
6de9cd9a
DN
531 current_binding_level = NULL_BINDING_LEVEL;
532 free_binding_level = NULL_BINDING_LEVEL;
533
534 /* Make the binding_level structure for global names. We move all
535 variables that are in a COMMON block to this binding level. */
87a60f68 536 pushlevel ();
6de9cd9a
DN
537 global_binding_level = current_binding_level;
538
539 /* Build common tree nodes. char_type_node is unsigned because we
a011cd92
BS
540 only use it for actual characters, not for INTEGER(1). */
541 build_common_tree_nodes (false);
c1775967 542
6de9cd9a 543 /* Set up F95 type nodes. */
5e8e542f 544 gfc_init_kinds ();
6de9cd9a 545 gfc_init_types ();
28d0b595 546 gfc_init_c_interop_kinds ();
6de9cd9a
DN
547}
548
b251af97 549
1f2959f0 550/* Builtin function initialization. */
6de9cd9a 551
87a60f68 552static tree
c79efc4d 553gfc_builtin_function (tree decl)
6de9cd9a 554{
6de9cd9a 555 pushdecl (decl);
6de9cd9a
DN
556 return decl;
557}
558
0d973c0a 559/* So far we need just these 10 attribute types. */
acf0174b 560#define ATTR_NULL 0
5325296e 561#define ATTR_LEAF_LIST (ECF_LEAF)
d724c876 562#define ATTR_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF)
46de9f5e 563#define ATTR_NOTHROW_LEAF_MALLOC_LIST (ECF_NOTHROW | ECF_LEAF | ECF_MALLOC)
d724c876 564#define ATTR_CONST_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF | ECF_CONST)
3b7ea188 565#define ATTR_PURE_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF | ECF_PURE)
d724c876
JJ
566#define ATTR_NOTHROW_LIST (ECF_NOTHROW)
567#define ATTR_CONST_NOTHROW_LIST (ECF_NOTHROW | ECF_CONST)
6fcc3cac 568#define ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LIST \
d4b6d147
TB
569 (ECF_NOTHROW | ECF_LEAF | ECF_MALLOC)
570#define ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LEAF_LIST \
571 (ECF_NOTHROW | ECF_LEAF)
0d973c0a
JJ
572#define ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST \
573 (ECF_COLD | ECF_NORETURN | \
574 ECF_NOTHROW | ECF_LEAF)
6de9cd9a
DN
575
576static void
e79983f4 577gfc_define_builtin (const char *name, tree type, enum built_in_function code,
d724c876 578 const char *library_name, int attr)
6de9cd9a
DN
579{
580 tree decl;
581
c79efc4d
RÁE
582 decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
583 library_name, NULL_TREE);
46de9f5e 584 set_call_expr_flags (decl, attr);
6de9cd9a 585
e79983f4 586 set_builtin_decl (code, decl, true);
6de9cd9a
DN
587}
588
589
e8525382 590#define DO_DEFINE_MATH_BUILTIN(code, name, argtype, tbase) \
644cb69f 591 gfc_define_builtin ("__builtin_" name "l", tbase##longdouble[argtype], \
d724c876
JJ
592 BUILT_IN_ ## code ## L, name "l", \
593 ATTR_CONST_NOTHROW_LEAF_LIST); \
e8525382 594 gfc_define_builtin ("__builtin_" name, tbase##double[argtype], \
d724c876
JJ
595 BUILT_IN_ ## code, name, \
596 ATTR_CONST_NOTHROW_LEAF_LIST); \
e8525382 597 gfc_define_builtin ("__builtin_" name "f", tbase##float[argtype], \
d724c876
JJ
598 BUILT_IN_ ## code ## F, name "f", \
599 ATTR_CONST_NOTHROW_LEAF_LIST);
6de9cd9a 600
e8525382
SK
601#define DEFINE_MATH_BUILTIN(code, name, argtype) \
602 DO_DEFINE_MATH_BUILTIN (code, name, argtype, mfunc_)
603
e8525382 604#define DEFINE_MATH_BUILTIN_C(code, name, argtype) \
644cb69f
FXC
605 DO_DEFINE_MATH_BUILTIN (code, name, argtype, mfunc_) \
606 DO_DEFINE_MATH_BUILTIN (C##code, "c" name, argtype, mfunc_c)
e8525382
SK
607
608
609/* Create function types for builtin functions. */
610
611static void
b251af97 612build_builtin_fntypes (tree *fntype, tree type)
e8525382 613{
e8525382 614 /* type (*) (type) */
b64fca63 615 fntype[0] = build_function_type_list (type, type, NULL_TREE);
e8525382 616 /* type (*) (type, type) */
b64fca63 617 fntype[1] = build_function_type_list (type, type, type, NULL_TREE);
b5a4419c 618 /* type (*) (type, int) */
b64fca63
NF
619 fntype[2] = build_function_type_list (type,
620 type, integer_type_node, NULL_TREE);
621 /* type (*) (void) */
622 fntype[3] = build_function_type_list (type, NULL_TREE);
db7f455b
DS
623 /* type (*) (type, &int) */
624 fntype[4] = build_function_type_list (type, type,
b64fca63 625 build_pointer_type (integer_type_node),
b64fca63
NF
626 NULL_TREE);
627 /* type (*) (int, type) */
628 fntype[5] = build_function_type_list (type,
629 integer_type_node, type, NULL_TREE);
e8525382
SK
630}
631
b251af97 632
6c7a4dfd
JJ
633static tree
634builtin_type_for_size (int size, bool unsignedp)
635{
21fa2faf 636 tree type = gfc_type_for_size (size, unsignedp);
6c7a4dfd
JJ
637 return type ? type : error_mark_node;
638}
e8525382 639
1f2959f0 640/* Initialization of builtin function nodes. */
e8525382 641
6de9cd9a
DN
642static void
643gfc_init_builtin_functions (void)
644{
6c7a4dfd
JJ
645 enum builtin_type
646 {
647#define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
648#define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
649#define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
650#define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
651#define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
652#define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
653#define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
f6a7cffc
TS
654#define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
655 ARG6) NAME,
656#define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
657 ARG6, ARG7) NAME,
658#define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
659 ARG6, ARG7, ARG8) NAME,
d9a6bd32
JJ
660#define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
661 ARG6, ARG7, ARG8, ARG9) NAME,
662#define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
663 ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
664#define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
665 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
6c7a4dfd 666#define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
d9a6bd32 667#define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
41dbbb37 668#define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
3e32ee19
NS
669#define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
670 ARG6) NAME,
56a9f6bc
TS
671#define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
672 ARG6, ARG7) NAME,
6c7a4dfd
JJ
673#define DEF_POINTER_TYPE(NAME, TYPE) NAME,
674#include "types.def"
675#undef DEF_PRIMITIVE_TYPE
676#undef DEF_FUNCTION_TYPE_0
677#undef DEF_FUNCTION_TYPE_1
678#undef DEF_FUNCTION_TYPE_2
679#undef DEF_FUNCTION_TYPE_3
680#undef DEF_FUNCTION_TYPE_4
681#undef DEF_FUNCTION_TYPE_5
682#undef DEF_FUNCTION_TYPE_6
683#undef DEF_FUNCTION_TYPE_7
acf0174b 684#undef DEF_FUNCTION_TYPE_8
d9a6bd32
JJ
685#undef DEF_FUNCTION_TYPE_9
686#undef DEF_FUNCTION_TYPE_10
687#undef DEF_FUNCTION_TYPE_11
6c7a4dfd 688#undef DEF_FUNCTION_TYPE_VAR_0
d9a6bd32 689#undef DEF_FUNCTION_TYPE_VAR_1
41dbbb37 690#undef DEF_FUNCTION_TYPE_VAR_2
3e32ee19 691#undef DEF_FUNCTION_TYPE_VAR_6
56a9f6bc 692#undef DEF_FUNCTION_TYPE_VAR_7
6c7a4dfd
JJ
693#undef DEF_POINTER_TYPE
694 BT_LAST
695 };
6c7a4dfd 696
b5a4419c
FXC
697 tree mfunc_float[6];
698 tree mfunc_double[6];
699 tree mfunc_longdouble[6];
700 tree mfunc_cfloat[6];
701 tree mfunc_cdouble[6];
702 tree mfunc_clongdouble[6];
3a53e165
RG
703 tree func_cfloat_float, func_float_cfloat;
704 tree func_cdouble_double, func_double_cdouble;
705 tree func_clongdouble_longdouble, func_longdouble_clongdouble;
706 tree func_float_floatp_floatp;
707 tree func_double_doublep_doublep;
708 tree func_longdouble_longdoublep_longdoublep;
709 tree ftype, ptype;
6c7a4dfd 710 tree builtin_types[(int) BT_LAST + 1];
6de9cd9a 711
3b7ea188
FXC
712 int attr;
713
e8525382
SK
714 build_builtin_fntypes (mfunc_float, float_type_node);
715 build_builtin_fntypes (mfunc_double, double_type_node);
644cb69f 716 build_builtin_fntypes (mfunc_longdouble, long_double_type_node);
e8525382
SK
717 build_builtin_fntypes (mfunc_cfloat, complex_float_type_node);
718 build_builtin_fntypes (mfunc_cdouble, complex_double_type_node);
644cb69f 719 build_builtin_fntypes (mfunc_clongdouble, complex_long_double_type_node);
e8525382 720
b64fca63
NF
721 func_cfloat_float = build_function_type_list (float_type_node,
722 complex_float_type_node,
723 NULL_TREE);
6de9cd9a 724
b64fca63
NF
725 func_float_cfloat = build_function_type_list (complex_float_type_node,
726 float_type_node, NULL_TREE);
3a53e165 727
b64fca63 728 func_cdouble_double = build_function_type_list (double_type_node,
0986c351
JJ
729 complex_double_type_node,
730 NULL_TREE);
6de9cd9a 731
b64fca63 732 func_double_cdouble = build_function_type_list (complex_double_type_node,
0986c351 733 double_type_node, NULL_TREE);
3a53e165 734
0986c351
JJ
735 func_clongdouble_longdouble
736 = build_function_type_list (long_double_type_node,
737 complex_long_double_type_node, NULL_TREE);
644cb69f 738
0986c351
JJ
739 func_longdouble_clongdouble
740 = build_function_type_list (complex_long_double_type_node,
741 long_double_type_node, NULL_TREE);
3a53e165
RG
742
743 ptype = build_pointer_type (float_type_node);
0986c351
JJ
744 func_float_floatp_floatp
745 = build_function_type_list (void_type_node, float_type_node, ptype, ptype,
746 NULL_TREE);
3a53e165
RG
747
748 ptype = build_pointer_type (double_type_node);
0986c351
JJ
749 func_double_doublep_doublep
750 = build_function_type_list (void_type_node, double_type_node, ptype,
751 ptype, NULL_TREE);
3a53e165
RG
752
753 ptype = build_pointer_type (long_double_type_node);
0986c351
JJ
754 func_longdouble_longdoublep_longdoublep
755 = build_function_type_list (void_type_node, long_double_type_node, ptype,
756 ptype, NULL_TREE);
3a53e165 757
2921157d 758/* Non-math builtins are defined manually, so they're not included here. */
a3c85b74 759#define OTHER_BUILTIN(ID,NAME,TYPE,CONST)
2921157d 760
6de9cd9a
DN
761#include "mathbuiltins.def"
762
644cb69f 763 gfc_define_builtin ("__builtin_roundl", mfunc_longdouble[0],
d724c876 764 BUILT_IN_ROUNDL, "roundl", ATTR_CONST_NOTHROW_LEAF_LIST);
6de9cd9a 765 gfc_define_builtin ("__builtin_round", mfunc_double[0],
d724c876 766 BUILT_IN_ROUND, "round", ATTR_CONST_NOTHROW_LEAF_LIST);
6de9cd9a 767 gfc_define_builtin ("__builtin_roundf", mfunc_float[0],
d724c876 768 BUILT_IN_ROUNDF, "roundf", ATTR_CONST_NOTHROW_LEAF_LIST);
644cb69f
FXC
769
770 gfc_define_builtin ("__builtin_truncl", mfunc_longdouble[0],
d724c876 771 BUILT_IN_TRUNCL, "truncl", ATTR_CONST_NOTHROW_LEAF_LIST);
e743d142 772 gfc_define_builtin ("__builtin_trunc", mfunc_double[0],
d724c876 773 BUILT_IN_TRUNC, "trunc", ATTR_CONST_NOTHROW_LEAF_LIST);
e743d142 774 gfc_define_builtin ("__builtin_truncf", mfunc_float[0],
d724c876 775 BUILT_IN_TRUNCF, "truncf", ATTR_CONST_NOTHROW_LEAF_LIST);
e743d142 776
644cb69f 777 gfc_define_builtin ("__builtin_cabsl", func_clongdouble_longdouble,
d724c876 778 BUILT_IN_CABSL, "cabsl", ATTR_CONST_NOTHROW_LEAF_LIST);
ead6d15f 779 gfc_define_builtin ("__builtin_cabs", func_cdouble_double,
d724c876 780 BUILT_IN_CABS, "cabs", ATTR_CONST_NOTHROW_LEAF_LIST);
ead6d15f 781 gfc_define_builtin ("__builtin_cabsf", func_cfloat_float,
d724c876 782 BUILT_IN_CABSF, "cabsf", ATTR_CONST_NOTHROW_LEAF_LIST);
c6a912da 783
644cb69f 784 gfc_define_builtin ("__builtin_copysignl", mfunc_longdouble[1],
d724c876
JJ
785 BUILT_IN_COPYSIGNL, "copysignl",
786 ATTR_CONST_NOTHROW_LEAF_LIST);
ead6d15f 787 gfc_define_builtin ("__builtin_copysign", mfunc_double[1],
d724c876
JJ
788 BUILT_IN_COPYSIGN, "copysign",
789 ATTR_CONST_NOTHROW_LEAF_LIST);
ead6d15f 790 gfc_define_builtin ("__builtin_copysignf", mfunc_float[1],
d724c876
JJ
791 BUILT_IN_COPYSIGNF, "copysignf",
792 ATTR_CONST_NOTHROW_LEAF_LIST);
58b6e047 793
b5a4419c 794 gfc_define_builtin ("__builtin_nextafterl", mfunc_longdouble[1],
d724c876
JJ
795 BUILT_IN_NEXTAFTERL, "nextafterl",
796 ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 797 gfc_define_builtin ("__builtin_nextafter", mfunc_double[1],
d724c876
JJ
798 BUILT_IN_NEXTAFTER, "nextafter",
799 ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 800 gfc_define_builtin ("__builtin_nextafterf", mfunc_float[1],
d724c876
JJ
801 BUILT_IN_NEXTAFTERF, "nextafterf",
802 ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 803
3b7ea188
FXC
804 /* Some built-ins depend on rounding mode. Depending on compilation options, they
805 will be "pure" or "const". */
806 attr = flag_rounding_math ? ATTR_PURE_NOTHROW_LEAF_LIST : ATTR_CONST_NOTHROW_LEAF_LIST;
807
808 gfc_define_builtin ("__builtin_rintl", mfunc_longdouble[0],
809 BUILT_IN_RINTL, "rintl", attr);
810 gfc_define_builtin ("__builtin_rint", mfunc_double[0],
811 BUILT_IN_RINT, "rint", attr);
812 gfc_define_builtin ("__builtin_rintf", mfunc_float[0],
813 BUILT_IN_RINTF, "rintf", attr);
814
815 gfc_define_builtin ("__builtin_remainderl", mfunc_longdouble[1],
816 BUILT_IN_REMAINDERL, "remainderl", attr);
817 gfc_define_builtin ("__builtin_remainder", mfunc_double[1],
818 BUILT_IN_REMAINDER, "remainder", attr);
819 gfc_define_builtin ("__builtin_remainderf", mfunc_float[1],
820 BUILT_IN_REMAINDERF, "remainderf", attr);
821
822 gfc_define_builtin ("__builtin_logbl", mfunc_longdouble[0],
823 BUILT_IN_LOGBL, "logbl", ATTR_CONST_NOTHROW_LEAF_LIST);
824 gfc_define_builtin ("__builtin_logb", mfunc_double[0],
825 BUILT_IN_LOGB, "logb", ATTR_CONST_NOTHROW_LEAF_LIST);
826 gfc_define_builtin ("__builtin_logbf", mfunc_float[0],
827 BUILT_IN_LOGBF, "logbf", ATTR_CONST_NOTHROW_LEAF_LIST);
828
829
b5a4419c 830 gfc_define_builtin ("__builtin_frexpl", mfunc_longdouble[4],
d724c876 831 BUILT_IN_FREXPL, "frexpl", ATTR_NOTHROW_LEAF_LIST);
b5a4419c 832 gfc_define_builtin ("__builtin_frexp", mfunc_double[4],
d724c876 833 BUILT_IN_FREXP, "frexp", ATTR_NOTHROW_LEAF_LIST);
b5a4419c 834 gfc_define_builtin ("__builtin_frexpf", mfunc_float[4],
d724c876 835 BUILT_IN_FREXPF, "frexpf", ATTR_NOTHROW_LEAF_LIST);
b5a4419c
FXC
836
837 gfc_define_builtin ("__builtin_fabsl", mfunc_longdouble[0],
d724c876 838 BUILT_IN_FABSL, "fabsl", ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 839 gfc_define_builtin ("__builtin_fabs", mfunc_double[0],
d724c876 840 BUILT_IN_FABS, "fabs", ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 841 gfc_define_builtin ("__builtin_fabsf", mfunc_float[0],
d724c876 842 BUILT_IN_FABSF, "fabsf", ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 843
5cfd56a7 844 gfc_define_builtin ("__builtin_scalbnl", mfunc_longdouble[2],
d724c876 845 BUILT_IN_SCALBNL, "scalbnl", ATTR_CONST_NOTHROW_LEAF_LIST);
5cfd56a7 846 gfc_define_builtin ("__builtin_scalbn", mfunc_double[2],
d724c876 847 BUILT_IN_SCALBN, "scalbn", ATTR_CONST_NOTHROW_LEAF_LIST);
5cfd56a7 848 gfc_define_builtin ("__builtin_scalbnf", mfunc_float[2],
d724c876 849 BUILT_IN_SCALBNF, "scalbnf", ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 850
17bccd1d
FXC
851 gfc_define_builtin ("__builtin_fmaxl", mfunc_longdouble[1],
852 BUILT_IN_FMAXL, "fmaxl", ATTR_CONST_NOTHROW_LEAF_LIST);
853 gfc_define_builtin ("__builtin_fmax", mfunc_double[1],
854 BUILT_IN_FMAX, "fmax", ATTR_CONST_NOTHROW_LEAF_LIST);
855 gfc_define_builtin ("__builtin_fmaxf", mfunc_float[1],
856 BUILT_IN_FMAXF, "fmaxf", ATTR_CONST_NOTHROW_LEAF_LIST);
857
858 gfc_define_builtin ("__builtin_fminl", mfunc_longdouble[1],
859 BUILT_IN_FMINL, "fminl", ATTR_CONST_NOTHROW_LEAF_LIST);
860 gfc_define_builtin ("__builtin_fmin", mfunc_double[1],
861 BUILT_IN_FMIN, "fmin", ATTR_CONST_NOTHROW_LEAF_LIST);
862 gfc_define_builtin ("__builtin_fminf", mfunc_float[1],
863 BUILT_IN_FMINF, "fminf", ATTR_CONST_NOTHROW_LEAF_LIST);
864
58b6e047 865 gfc_define_builtin ("__builtin_fmodl", mfunc_longdouble[1],
d724c876 866 BUILT_IN_FMODL, "fmodl", ATTR_CONST_NOTHROW_LEAF_LIST);
58b6e047 867 gfc_define_builtin ("__builtin_fmod", mfunc_double[1],
d724c876 868 BUILT_IN_FMOD, "fmod", ATTR_CONST_NOTHROW_LEAF_LIST);
58b6e047 869 gfc_define_builtin ("__builtin_fmodf", mfunc_float[1],
d724c876 870 BUILT_IN_FMODF, "fmodf", ATTR_CONST_NOTHROW_LEAF_LIST);
6de9cd9a 871
6715d47b
JB
872 /* iround{f,,l}, lround{f,,l} and llround{f,,l} */
873 ftype = build_function_type_list (integer_type_node,
874 float_type_node, NULL_TREE);
875 gfc_define_builtin("__builtin_iroundf", ftype, BUILT_IN_IROUNDF,
876 "iroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
877 ftype = build_function_type_list (long_integer_type_node,
878 float_type_node, NULL_TREE);
879 gfc_define_builtin ("__builtin_lroundf", ftype, BUILT_IN_LROUNDF,
d724c876 880 "lroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
881 ftype = build_function_type_list (long_long_integer_type_node,
882 float_type_node, NULL_TREE);
883 gfc_define_builtin ("__builtin_llroundf", ftype, BUILT_IN_LLROUNDF,
d724c876 884 "llroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
94f548c2 885
6715d47b
JB
886 ftype = build_function_type_list (integer_type_node,
887 double_type_node, NULL_TREE);
888 gfc_define_builtin("__builtin_iround", ftype, BUILT_IN_IROUND,
889 "iround", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
890 ftype = build_function_type_list (long_integer_type_node,
891 double_type_node, NULL_TREE);
892 gfc_define_builtin ("__builtin_lround", ftype, BUILT_IN_LROUND,
d724c876 893 "lround", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
894 ftype = build_function_type_list (long_long_integer_type_node,
895 double_type_node, NULL_TREE);
896 gfc_define_builtin ("__builtin_llround", ftype, BUILT_IN_LLROUND,
d724c876 897 "llround", ATTR_CONST_NOTHROW_LEAF_LIST);
94f548c2 898
6715d47b
JB
899 ftype = build_function_type_list (integer_type_node,
900 long_double_type_node, NULL_TREE);
901 gfc_define_builtin("__builtin_iroundl", ftype, BUILT_IN_IROUNDL,
902 "iroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
903 ftype = build_function_type_list (long_integer_type_node,
904 long_double_type_node, NULL_TREE);
905 gfc_define_builtin ("__builtin_lroundl", ftype, BUILT_IN_LROUNDL,
d724c876 906 "lroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
907 ftype = build_function_type_list (long_long_integer_type_node,
908 long_double_type_node, NULL_TREE);
909 gfc_define_builtin ("__builtin_llroundl", ftype, BUILT_IN_LLROUNDL,
d724c876 910 "llroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
94f548c2 911
5b200ac2 912 /* These are used to implement the ** operator. */
644cb69f 913 gfc_define_builtin ("__builtin_powl", mfunc_longdouble[1],
d724c876 914 BUILT_IN_POWL, "powl", ATTR_CONST_NOTHROW_LEAF_LIST);
c7d78bbe 915 gfc_define_builtin ("__builtin_pow", mfunc_double[1],
d724c876 916 BUILT_IN_POW, "pow", ATTR_CONST_NOTHROW_LEAF_LIST);
c7d78bbe 917 gfc_define_builtin ("__builtin_powf", mfunc_float[1],
d724c876 918 BUILT_IN_POWF, "powf", ATTR_CONST_NOTHROW_LEAF_LIST);
fb220235 919 gfc_define_builtin ("__builtin_cpowl", mfunc_clongdouble[1],
d724c876 920 BUILT_IN_CPOWL, "cpowl", ATTR_CONST_NOTHROW_LEAF_LIST);
fb220235 921 gfc_define_builtin ("__builtin_cpow", mfunc_cdouble[1],
d724c876 922 BUILT_IN_CPOW, "cpow", ATTR_CONST_NOTHROW_LEAF_LIST);
fb220235 923 gfc_define_builtin ("__builtin_cpowf", mfunc_cfloat[1],
d724c876 924 BUILT_IN_CPOWF, "cpowf", ATTR_CONST_NOTHROW_LEAF_LIST);
5cfd56a7 925 gfc_define_builtin ("__builtin_powil", mfunc_longdouble[2],
d724c876 926 BUILT_IN_POWIL, "powil", ATTR_CONST_NOTHROW_LEAF_LIST);
5cfd56a7 927 gfc_define_builtin ("__builtin_powi", mfunc_double[2],
d724c876 928 BUILT_IN_POWI, "powi", ATTR_CONST_NOTHROW_LEAF_LIST);
5cfd56a7 929 gfc_define_builtin ("__builtin_powif", mfunc_float[2],
d724c876 930 BUILT_IN_POWIF, "powif", ATTR_CONST_NOTHROW_LEAF_LIST);
31c97dfe 931
5b200ac2 932
bae974e6 933 if (targetm.libc_has_function (function_c99_math_complex, NULL_TREE))
3a53e165
RG
934 {
935 gfc_define_builtin ("__builtin_cbrtl", mfunc_longdouble[0],
d724c876
JJ
936 BUILT_IN_CBRTL, "cbrtl",
937 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165 938 gfc_define_builtin ("__builtin_cbrt", mfunc_double[0],
d724c876
JJ
939 BUILT_IN_CBRT, "cbrt",
940 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165 941 gfc_define_builtin ("__builtin_cbrtf", mfunc_float[0],
d724c876
JJ
942 BUILT_IN_CBRTF, "cbrtf",
943 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165 944 gfc_define_builtin ("__builtin_cexpil", func_longdouble_clongdouble,
d724c876
JJ
945 BUILT_IN_CEXPIL, "cexpil",
946 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165 947 gfc_define_builtin ("__builtin_cexpi", func_double_cdouble,
d724c876
JJ
948 BUILT_IN_CEXPI, "cexpi",
949 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165 950 gfc_define_builtin ("__builtin_cexpif", func_float_cfloat,
d724c876
JJ
951 BUILT_IN_CEXPIF, "cexpif",
952 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165
RG
953 }
954
bae974e6 955 if (targetm.libc_has_function (function_sincos, NULL_TREE))
3a53e165
RG
956 {
957 gfc_define_builtin ("__builtin_sincosl",
958 func_longdouble_longdoublep_longdoublep,
d724c876 959 BUILT_IN_SINCOSL, "sincosl", ATTR_NOTHROW_LEAF_LIST);
3a53e165 960 gfc_define_builtin ("__builtin_sincos", func_double_doublep_doublep,
d724c876 961 BUILT_IN_SINCOS, "sincos", ATTR_NOTHROW_LEAF_LIST);
3a53e165 962 gfc_define_builtin ("__builtin_sincosf", func_float_floatp_floatp,
d724c876 963 BUILT_IN_SINCOSF, "sincosf", ATTR_NOTHROW_LEAF_LIST);
3a53e165
RG
964 }
965
451238b7 966 /* For LEADZ, TRAILZ, POPCNT and POPPAR. */
b64fca63
NF
967 ftype = build_function_type_list (integer_type_node,
968 unsigned_type_node, NULL_TREE);
414f00e9 969 gfc_define_builtin ("__builtin_clz", ftype, BUILT_IN_CLZ,
d724c876 970 "__builtin_clz", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 971 gfc_define_builtin ("__builtin_ctz", ftype, BUILT_IN_CTZ,
d724c876 972 "__builtin_ctz", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 973 gfc_define_builtin ("__builtin_parity", ftype, BUILT_IN_PARITY,
d724c876 974 "__builtin_parity", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 975 gfc_define_builtin ("__builtin_popcount", ftype, BUILT_IN_POPCOUNT,
d724c876 976 "__builtin_popcount", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 977
b64fca63
NF
978 ftype = build_function_type_list (integer_type_node,
979 long_unsigned_type_node, NULL_TREE);
980 gfc_define_builtin ("__builtin_clzl", ftype, BUILT_IN_CLZL,
d724c876 981 "__builtin_clzl", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 982 gfc_define_builtin ("__builtin_ctzl", ftype, BUILT_IN_CTZL,
d724c876 983 "__builtin_ctzl", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 984 gfc_define_builtin ("__builtin_parityl", ftype, BUILT_IN_PARITYL,
d724c876 985 "__builtin_parityl", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 986 gfc_define_builtin ("__builtin_popcountl", ftype, BUILT_IN_POPCOUNTL,
d724c876 987 "__builtin_popcountl", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 988
b64fca63
NF
989 ftype = build_function_type_list (integer_type_node,
990 long_long_unsigned_type_node, NULL_TREE);
991 gfc_define_builtin ("__builtin_clzll", ftype, BUILT_IN_CLZLL,
d724c876 992 "__builtin_clzll", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 993 gfc_define_builtin ("__builtin_ctzll", ftype, BUILT_IN_CTZLL,
d724c876 994 "__builtin_ctzll", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 995 gfc_define_builtin ("__builtin_parityll", ftype, BUILT_IN_PARITYLL,
d724c876 996 "__builtin_parityll", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 997 gfc_define_builtin ("__builtin_popcountll", ftype, BUILT_IN_POPCOUNTLL,
d724c876 998 "__builtin_popcountll", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 999
6de9cd9a
DN
1000 /* Other builtin functions we use. */
1001
b64fca63
NF
1002 ftype = build_function_type_list (long_integer_type_node,
1003 long_integer_type_node,
1004 long_integer_type_node, NULL_TREE);
c6a912da 1005 gfc_define_builtin ("__builtin_expect", ftype, BUILT_IN_EXPECT,
d724c876 1006 "__builtin_expect", ATTR_CONST_NOTHROW_LEAF_LIST);
ef9312c1 1007
b64fca63
NF
1008 ftype = build_function_type_list (void_type_node,
1009 pvoid_type_node, NULL_TREE);
1529b8d9 1010 gfc_define_builtin ("__builtin_free", ftype, BUILT_IN_FREE,
d724c876 1011 "free", ATTR_NOTHROW_LEAF_LIST);
1529b8d9 1012
b64fca63
NF
1013 ftype = build_function_type_list (pvoid_type_node,
1014 size_type_node, NULL_TREE);
1529b8d9 1015 gfc_define_builtin ("__builtin_malloc", ftype, BUILT_IN_MALLOC,
46de9f5e 1016 "malloc", ATTR_NOTHROW_LEAF_MALLOC_LIST);
1529b8d9 1017
4df0f7da
TB
1018 ftype = build_function_type_list (pvoid_type_node, size_type_node,
1019 size_type_node, NULL_TREE);
1020 gfc_define_builtin ("__builtin_calloc", ftype, BUILT_IN_CALLOC,
46de9f5e 1021 "calloc", ATTR_NOTHROW_LEAF_MALLOC_LIST);
4df0f7da
TB
1022 DECL_IS_MALLOC (builtin_decl_explicit (BUILT_IN_CALLOC)) = 1;
1023
0986c351
JJ
1024 ftype = build_function_type_list (pvoid_type_node, pvoid_type_node,
1025 size_type_node, NULL_TREE);
4376b7cf 1026 gfc_define_builtin ("__builtin_realloc", ftype, BUILT_IN_REALLOC,
d724c876 1027 "realloc", ATTR_NOTHROW_LEAF_LIST);
4376b7cf 1028
c541d521
FXC
1029 /* Type-generic floating-point classification built-ins. */
1030
384aedfc 1031 ftype = build_function_type (integer_type_node, NULL_TREE);
3b7ea188
FXC
1032 gfc_define_builtin ("__builtin_isfinite", ftype, BUILT_IN_ISFINITE,
1033 "__builtin_isfinite", ATTR_CONST_NOTHROW_LEAF_LIST);
c541d521
FXC
1034 gfc_define_builtin ("__builtin_isinf", ftype, BUILT_IN_ISINF,
1035 "__builtin_isinf", ATTR_CONST_NOTHROW_LEAF_LIST);
1036 gfc_define_builtin ("__builtin_isinf_sign", ftype, BUILT_IN_ISINF_SIGN,
1037 "__builtin_isinf_sign", ATTR_CONST_NOTHROW_LEAF_LIST);
1038 gfc_define_builtin ("__builtin_isnan", ftype, BUILT_IN_ISNAN,
1039 "__builtin_isnan", ATTR_CONST_NOTHROW_LEAF_LIST);
3b7ea188
FXC
1040 gfc_define_builtin ("__builtin_isnormal", ftype, BUILT_IN_ISNORMAL,
1041 "__builtin_isnormal", ATTR_CONST_NOTHROW_LEAF_LIST);
0982edd3
JJ
1042 gfc_define_builtin ("__builtin_issignaling", ftype, BUILT_IN_ISSIGNALING,
1043 "__builtin_issignaling", ATTR_CONST_NOTHROW_LEAF_LIST);
c541d521
FXC
1044 gfc_define_builtin ("__builtin_signbit", ftype, BUILT_IN_SIGNBIT,
1045 "__builtin_signbit", ATTR_CONST_NOTHROW_LEAF_LIST);
db630423
JJ
1046 gfc_define_builtin ("__builtin_fpclassify", ftype, BUILT_IN_FPCLASSIFY,
1047 "__builtin_fpclassify", ATTR_CONST_NOTHROW_LEAF_LIST);
3b7ea188 1048
c541d521
FXC
1049 gfc_define_builtin ("__builtin_isless", ftype, BUILT_IN_ISLESS,
1050 "__builtin_isless", ATTR_CONST_NOTHROW_LEAF_LIST);
3b7ea188
FXC
1051 gfc_define_builtin ("__builtin_islessequal", ftype, BUILT_IN_ISLESSEQUAL,
1052 "__builtin_islessequal", ATTR_CONST_NOTHROW_LEAF_LIST);
c541d521
FXC
1053 gfc_define_builtin ("__builtin_islessgreater", ftype, BUILT_IN_ISLESSGREATER,
1054 "__builtin_islessgreater", ATTR_CONST_NOTHROW_LEAF_LIST);
1055 gfc_define_builtin ("__builtin_isgreater", ftype, BUILT_IN_ISGREATER,
1056 "__builtin_isgreater", ATTR_CONST_NOTHROW_LEAF_LIST);
3b7ea188
FXC
1057 gfc_define_builtin ("__builtin_isgreaterequal", ftype,
1058 BUILT_IN_ISGREATEREQUAL, "__builtin_isgreaterequal",
1059 ATTR_CONST_NOTHROW_LEAF_LIST);
c541d521
FXC
1060 gfc_define_builtin ("__builtin_isunordered", ftype, BUILT_IN_ISUNORDERED,
1061 "__builtin_isunordered", ATTR_CONST_NOTHROW_LEAF_LIST);
dca28748
FXC
1062 gfc_define_builtin ("__builtin_iseqsig", ftype, BUILT_IN_ISEQSIG,
1063 "__builtin_iseqsig", ATTR_CONST_NOTHROW_LEAF_LIST);
3b7ea188 1064
5fcb93f1 1065
6c7a4dfd
JJ
1066#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
1067 builtin_types[(int) ENUM] = VALUE;
b64fca63
NF
1068#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
1069 builtin_types[(int) ENUM] \
1070 = build_function_type_list (builtin_types[(int) RETURN], \
1071 NULL_TREE);
6c7a4dfd
JJ
1072#define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
1073 builtin_types[(int) ENUM] \
b64fca63
NF
1074 = build_function_type_list (builtin_types[(int) RETURN], \
1075 builtin_types[(int) ARG1], \
1076 NULL_TREE);
1077#define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
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 NULL_TREE);
1083#define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
1084 builtin_types[(int) ENUM] \
1085 = build_function_type_list (builtin_types[(int) RETURN], \
1086 builtin_types[(int) ARG1], \
1087 builtin_types[(int) ARG2], \
1088 builtin_types[(int) ARG3], \
1089 NULL_TREE);
6c7a4dfd
JJ
1090#define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
1091 builtin_types[(int) ENUM] \
b64fca63
NF
1092 = build_function_type_list (builtin_types[(int) RETURN], \
1093 builtin_types[(int) ARG1], \
1094 builtin_types[(int) ARG2], \
1095 builtin_types[(int) ARG3], \
1096 builtin_types[(int) ARG4], \
1097 NULL_TREE);
6c7a4dfd
JJ
1098#define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
1099 builtin_types[(int) ENUM] \
b64fca63
NF
1100 = build_function_type_list (builtin_types[(int) RETURN], \
1101 builtin_types[(int) ARG1], \
1102 builtin_types[(int) ARG2], \
1103 builtin_types[(int) ARG3], \
1104 builtin_types[(int) ARG4], \
1105 builtin_types[(int) ARG5], \
1106 NULL_TREE);
6c7a4dfd
JJ
1107#define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1108 ARG6) \
1109 builtin_types[(int) ENUM] \
b64fca63
NF
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 NULL_TREE);
6c7a4dfd
JJ
1118#define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1119 ARG6, ARG7) \
1120 builtin_types[(int) ENUM] \
b64fca63
NF
1121 = build_function_type_list (builtin_types[(int) RETURN], \
1122 builtin_types[(int) ARG1], \
1123 builtin_types[(int) ARG2], \
1124 builtin_types[(int) ARG3], \
1125 builtin_types[(int) ARG4], \
1126 builtin_types[(int) ARG5], \
1127 builtin_types[(int) ARG6], \
1128 builtin_types[(int) ARG7], \
1129 NULL_TREE);
acf0174b
JJ
1130#define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1131 ARG6, ARG7, ARG8) \
1132 builtin_types[(int) ENUM] \
1133 = build_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);
d9a6bd32
JJ
1143#define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1144 ARG6, ARG7, ARG8, ARG9) \
1145 builtin_types[(int) ENUM] \
1146 = build_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 NULL_TREE);
1157#define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, \
1158 ARG5, ARG6, ARG7, ARG8, ARG9, ARG10) \
1159 builtin_types[(int) ENUM] \
1160 = build_function_type_list (builtin_types[(int) RETURN], \
1161 builtin_types[(int) ARG1], \
1162 builtin_types[(int) ARG2], \
1163 builtin_types[(int) ARG3], \
1164 builtin_types[(int) ARG4], \
1165 builtin_types[(int) ARG5], \
1166 builtin_types[(int) ARG6], \
1167 builtin_types[(int) ARG7], \
1168 builtin_types[(int) ARG8], \
1169 builtin_types[(int) ARG9], \
1170 builtin_types[(int) ARG10], \
1171 NULL_TREE);
1172#define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, \
1173 ARG5, ARG6, ARG7, ARG8, ARG9, ARG10, ARG11)\
1174 builtin_types[(int) ENUM] \
1175 = build_function_type_list (builtin_types[(int) RETURN], \
1176 builtin_types[(int) ARG1], \
1177 builtin_types[(int) ARG2], \
1178 builtin_types[(int) ARG3], \
1179 builtin_types[(int) ARG4], \
1180 builtin_types[(int) ARG5], \
1181 builtin_types[(int) ARG6], \
1182 builtin_types[(int) ARG7], \
1183 builtin_types[(int) ARG8], \
1184 builtin_types[(int) ARG9], \
1185 builtin_types[(int) ARG10], \
1186 builtin_types[(int) ARG11], \
1187 NULL_TREE);
6c7a4dfd
JJ
1188#define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
1189 builtin_types[(int) ENUM] \
b64fca63
NF
1190 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1191 NULL_TREE);
d9a6bd32
JJ
1192#define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
1193 builtin_types[(int) ENUM] \
1194 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1195 builtin_types[(int) ARG1], \
1196 NULL_TREE);
41dbbb37
TS
1197#define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
1198 builtin_types[(int) ENUM] \
1199 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1200 builtin_types[(int) ARG1], \
1201 builtin_types[(int) ARG2], \
1202 NULL_TREE);
3e32ee19
NS
1203#define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1204 ARG6) \
41dbbb37
TS
1205 builtin_types[(int) ENUM] \
1206 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1207 builtin_types[(int) ARG1], \
1208 builtin_types[(int) ARG2], \
1209 builtin_types[(int) ARG3], \
1210 builtin_types[(int) ARG4], \
1211 builtin_types[(int) ARG5], \
1212 builtin_types[(int) ARG6], \
41dbbb37 1213 NULL_TREE);
3e32ee19
NS
1214#define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1215 ARG6, ARG7) \
41dbbb37
TS
1216 builtin_types[(int) ENUM] \
1217 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1218 builtin_types[(int) ARG1], \
1219 builtin_types[(int) ARG2], \
1220 builtin_types[(int) ARG3], \
1221 builtin_types[(int) ARG4], \
1222 builtin_types[(int) ARG5], \
1223 builtin_types[(int) ARG6], \
1224 builtin_types[(int) ARG7], \
41dbbb37 1225 NULL_TREE);
6c7a4dfd
JJ
1226#define DEF_POINTER_TYPE(ENUM, TYPE) \
1227 builtin_types[(int) ENUM] \
1228 = build_pointer_type (builtin_types[(int) TYPE]);
1229#include "types.def"
1230#undef DEF_PRIMITIVE_TYPE
f6a7cffc 1231#undef DEF_FUNCTION_TYPE_0
6c7a4dfd
JJ
1232#undef DEF_FUNCTION_TYPE_1
1233#undef DEF_FUNCTION_TYPE_2
1234#undef DEF_FUNCTION_TYPE_3
1235#undef DEF_FUNCTION_TYPE_4
1236#undef DEF_FUNCTION_TYPE_5
1237#undef DEF_FUNCTION_TYPE_6
f6a7cffc
TS
1238#undef DEF_FUNCTION_TYPE_7
1239#undef DEF_FUNCTION_TYPE_8
d9a6bd32 1240#undef DEF_FUNCTION_TYPE_10
6c7a4dfd 1241#undef DEF_FUNCTION_TYPE_VAR_0
d9a6bd32 1242#undef DEF_FUNCTION_TYPE_VAR_1
41dbbb37 1243#undef DEF_FUNCTION_TYPE_VAR_2
3e32ee19 1244#undef DEF_FUNCTION_TYPE_VAR_6
56a9f6bc 1245#undef DEF_FUNCTION_TYPE_VAR_7
6c7a4dfd
JJ
1246#undef DEF_POINTER_TYPE
1247 builtin_types[(int) BT_LAST] = NULL_TREE;
1248
1249 /* Initialize synchronization builtins. */
1250#undef DEF_SYNC_BUILTIN
1251#define DEF_SYNC_BUILTIN(code, name, type, attr) \
1252 gfc_define_builtin (name, builtin_types[type], code, name, \
d724c876 1253 attr);
6c7a4dfd
JJ
1254#include "../sync-builtins.def"
1255#undef DEF_SYNC_BUILTIN
1256
41dbbb37
TS
1257 if (flag_openacc)
1258 {
1259#undef DEF_GOACC_BUILTIN
1260#define DEF_GOACC_BUILTIN(code, name, type, attr) \
1261 gfc_define_builtin ("__builtin_" name, builtin_types[type], \
1262 code, name, attr);
1263#undef DEF_GOACC_BUILTIN_COMPILER
1264#define DEF_GOACC_BUILTIN_COMPILER(code, name, type, attr) \
1265 gfc_define_builtin (name, builtin_types[type], code, name, attr);
1f62d637
TV
1266#undef DEF_GOACC_BUILTIN_ONLY
1267#define DEF_GOACC_BUILTIN_ONLY(code, name, type, attr) \
1268 gfc_define_builtin ("__builtin_" name, builtin_types[type], code, NULL, \
1269 attr);
41dbbb37
TS
1270#undef DEF_GOMP_BUILTIN
1271#define DEF_GOMP_BUILTIN(code, name, type, attr) /* ignore */
1272#include "../omp-builtins.def"
1273#undef DEF_GOACC_BUILTIN
1274#undef DEF_GOACC_BUILTIN_COMPILER
1275#undef DEF_GOMP_BUILTIN
1276 }
1277
c61819ff 1278 if (flag_openmp || flag_openmp_simd || flag_tree_parallelize_loops)
6c7a4dfd 1279 {
41dbbb37
TS
1280#undef DEF_GOACC_BUILTIN
1281#define DEF_GOACC_BUILTIN(code, name, type, attr) /* ignore */
1282#undef DEF_GOACC_BUILTIN_COMPILER
1283#define DEF_GOACC_BUILTIN_COMPILER(code, name, type, attr) /* ignore */
6c7a4dfd
JJ
1284#undef DEF_GOMP_BUILTIN
1285#define DEF_GOMP_BUILTIN(code, name, type, attr) \
1286 gfc_define_builtin ("__builtin_" name, builtin_types[type], \
d724c876 1287 code, name, attr);
6c7a4dfd 1288#include "../omp-builtins.def"
41dbbb37
TS
1289#undef DEF_GOACC_BUILTIN
1290#undef DEF_GOACC_BUILTIN_COMPILER
6c7a4dfd 1291#undef DEF_GOMP_BUILTIN
6fcc3cac
JJ
1292 tree gomp_alloc = builtin_decl_explicit (BUILT_IN_GOMP_ALLOC);
1293 tree two = build_int_cst (integer_type_node, 2);
1294 DECL_ATTRIBUTES (gomp_alloc)
1295 = tree_cons (get_identifier ("warn_unused_result"), NULL_TREE,
1296 tree_cons (get_identifier ("alloc_size"),
1297 build_tree_list (NULL_TREE, two),
1298 DECL_ATTRIBUTES (gomp_alloc)));
6c7a4dfd
JJ
1299 }
1300
1301 gfc_define_builtin ("__builtin_trap", builtin_types[BT_FN_VOID],
d724c876 1302 BUILT_IN_TRAP, NULL, ATTR_NOTHROW_LEAF_LIST);
e79983f4 1303 TREE_THIS_VOLATILE (builtin_decl_explicit (BUILT_IN_TRAP)) = 1;
6c7a4dfd 1304
b46ebd6c
JJ
1305 ftype = build_varargs_function_type_list (ptr_type_node, const_ptr_type_node,
1306 size_type_node, NULL_TREE);
1307 gfc_define_builtin ("__builtin_assume_aligned", ftype,
1308 BUILT_IN_ASSUME_ALIGNED,
1309 "__builtin_assume_aligned",
1310 ATTR_CONST_NOTHROW_LEAF_LIST);
1311
7c4c65d1
FXC
1312 ftype = build_function_type_list (long_double_type_node, long_double_type_node,
1313 long_double_type_node, long_double_type_node,
1314 NULL_TREE);
1315 gfc_define_builtin ("__builtin_fmal", ftype, BUILT_IN_FMAL,
1316 "fmal", ATTR_CONST_NOTHROW_LEAF_LIST);
1317 ftype = build_function_type_list (double_type_node, double_type_node,
1318 double_type_node, double_type_node,
1319 NULL_TREE);
1320 gfc_define_builtin ("__builtin_fma", ftype, BUILT_IN_FMA,
1321 "fma", ATTR_CONST_NOTHROW_LEAF_LIST);
1322 ftype = build_function_type_list (float_type_node, float_type_node,
1323 float_type_node, float_type_node,
1324 NULL_TREE);
1325 gfc_define_builtin ("__builtin_fmaf", ftype, BUILT_IN_FMAF,
1326 "fmaf", ATTR_CONST_NOTHROW_LEAF_LIST);
1327
8893239d 1328 gfc_define_builtin ("__emutls_get_address",
d724c876
JJ
1329 builtin_types[BT_FN_PTR_PTR],
1330 BUILT_IN_EMUTLS_GET_ADDRESS,
1331 "__emutls_get_address", ATTR_CONST_NOTHROW_LEAF_LIST);
8893239d
RH
1332 gfc_define_builtin ("__emutls_register_common",
1333 builtin_types[BT_FN_VOID_PTR_WORD_WORD_PTR],
1334 BUILT_IN_EMUTLS_REGISTER_COMMON,
d724c876 1335 "__emutls_register_common", ATTR_NOTHROW_LEAF_LIST);
8893239d 1336
384c400a 1337 build_common_builtin_nodes ();
ef9312c1 1338 targetm.init_builtins ();
6de9cd9a
DN
1339}
1340
e8525382 1341#undef DEFINE_MATH_BUILTIN_C
6de9cd9a
DN
1342#undef DEFINE_MATH_BUILTIN
1343
a64f5186
JJ
1344static void
1345gfc_init_ts (void)
1346{
1347 tree_contains_struct[NAMESPACE_DECL][TS_DECL_NON_COMMON] = 1;
1348 tree_contains_struct[NAMESPACE_DECL][TS_DECL_WITH_VIS] = 1;
1349 tree_contains_struct[NAMESPACE_DECL][TS_DECL_WRTL] = 1;
1350 tree_contains_struct[NAMESPACE_DECL][TS_DECL_COMMON] = 1;
1351 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1352}
1353
602b8523
TB
1354void
1355gfc_maybe_initialize_eh (void)
1356{
1357 if (!flag_exceptions || gfc_eh_initialized_p)
1358 return;
1359
1360 gfc_eh_initialized_p = true;
602b8523
TB
1361 using_eh_for_cleanups ();
1362}
1363
1364
6de9cd9a
DN
1365#include "gt-fortran-f95-lang.h"
1366#include "gtype-fortran.h"