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