]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fortran/f95-lang.c
g++-dg.exp (g++-dg-runtest): Change -std=c++1y to -std=c++14.
[thirdparty/gcc.git] / gcc / fortran / f95-lang.c
CommitLineData
f36327db 1/* gfortran backend interface
23a5b65a 2 Copyright (C) 2000-2014 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
DN
20
21/* f95-lang.c-- GCC backend interface stuff */
22
23/* declare required prototypes: */
24
25#include "config.h"
d22e4895 26#include "system.h"
6de9cd9a
DN
27#include "ansidecl.h"
28#include "system.h"
29#include "coretypes.h"
8e54f6d3 30#include "gfortran.h"
6de9cd9a 31#include "tree.h"
6de9cd9a
DN
32#include "flags.h"
33#include "langhooks.h"
34#include "langhooks-def.h"
35#include "timevar.h"
36#include "tm.h"
83685514
AM
37#include "hashtab.h"
38#include "hash-set.h"
39#include "vec.h"
40#include "machmode.h"
41#include "hard-reg-set.h"
42#include "input.h"
6de9cd9a
DN
43#include "function.h"
44#include "ggc.h"
45#include "toplev.h"
46#include "target.h"
47#include "debug.h"
8e54f6d3 48#include "diagnostic.h" /* For errorcount/warningcount */
7ee2468b 49#include "dumpfile.h"
c582198b
AM
50#include "hash-map.h"
51#include "is-a.h"
52#include "plugin-api.h"
53#include "ipa-ref.h"
6de9cd9a 54#include "cgraph.h"
670637ee 55#include "cpp.h"
6de9cd9a
DN
56#include "trans.h"
57#include "trans-types.h"
58#include "trans-const.h"
59
6de9cd9a
DN
60/* Language-dependent contents of an identifier. */
61
d1b38208
TG
62struct GTY(())
63lang_identifier {
6de9cd9a
DN
64 struct tree_identifier common;
65};
66
67/* The resulting tree type. */
68
d1b38208 69union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
81f653d6 70 chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
d1b38208 71lang_tree_node {
6de9cd9a
DN
72 union tree_node GTY((tag ("0"),
73 desc ("tree_node_structure (&%h)"))) generic;
74 struct lang_identifier GTY((tag ("1"))) identifier;
75};
76
77/* Save and restore the variables in this file and elsewhere
78 that keep track of the progress of compilation of the current function.
79 Used for nested functions. */
80
d1b38208
TG
81struct GTY(())
82language_function {
6de9cd9a 83 /* struct gfc_language_function base; */
6de9cd9a
DN
84 struct binding_level *binding_level;
85};
86
6de9cd9a
DN
87static void gfc_init_decl_processing (void);
88static void gfc_init_builtin_functions (void);
87a60f68 89static bool global_bindings_p (void);
6de9cd9a
DN
90
91/* Each front end provides its own. */
92static bool gfc_init (void);
93static void gfc_finish (void);
8b84c596 94static void gfc_write_global_declarations (void);
b37421c6 95static void gfc_be_parse_file (void);
4862826d 96static alias_set_type gfc_get_alias_set (tree);
a64f5186 97static void gfc_init_ts (void);
87a60f68 98static tree gfc_builtin_function (tree);
6de9cd9a 99
f014c653
JJ
100/* Handle an "omp declare target" attribute; arguments as in
101 struct attribute_spec.handler. */
102static tree
103gfc_handle_omp_declare_target_attribute (tree *, tree, tree, int, bool *)
104{
105 return NULL_TREE;
106}
107
108/* Table of valid Fortran attributes. */
109static const struct attribute_spec gfc_attribute_table[] =
110{
111 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
112 affects_type_identity } */
113 { "omp declare target", 0, 0, true, false, false,
114 gfc_handle_omp_declare_target_attribute, false },
115 { NULL, 0, 0, false, false, false, NULL, false }
116};
117
6de9cd9a
DN
118#undef LANG_HOOKS_NAME
119#undef LANG_HOOKS_INIT
120#undef LANG_HOOKS_FINISH
8b84c596 121#undef LANG_HOOKS_WRITE_GLOBALS
7a9bf9a4 122#undef LANG_HOOKS_OPTION_LANG_MASK
a75bfaa6 123#undef LANG_HOOKS_INIT_OPTIONS_STRUCT
6de9cd9a
DN
124#undef LANG_HOOKS_INIT_OPTIONS
125#undef LANG_HOOKS_HANDLE_OPTION
126#undef LANG_HOOKS_POST_OPTIONS
6de9cd9a 127#undef LANG_HOOKS_PARSE_FILE
6de9cd9a
DN
128#undef LANG_HOOKS_MARK_ADDRESSABLE
129#undef LANG_HOOKS_TYPE_FOR_MODE
130#undef LANG_HOOKS_TYPE_FOR_SIZE
7b9c708f 131#undef LANG_HOOKS_GET_ALIAS_SET
a64f5186 132#undef LANG_HOOKS_INIT_TS
6c7a4dfd
JJ
133#undef LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE
134#undef LANG_HOOKS_OMP_PREDETERMINED_SHARING
79943d19 135#undef LANG_HOOKS_OMP_REPORT_DECL
cd75853e 136#undef LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR
a68ab351
JJ
137#undef LANG_HOOKS_OMP_CLAUSE_COPY_CTOR
138#undef LANG_HOOKS_OMP_CLAUSE_ASSIGN_OP
da6f124d 139#undef LANG_HOOKS_OMP_CLAUSE_LINEAR_CTOR
a68ab351 140#undef LANG_HOOKS_OMP_CLAUSE_DTOR
f014c653 141#undef LANG_HOOKS_OMP_FINISH_CLAUSE
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
6de9cd9a
DN
150
151/* Define lang hooks. */
3135ce84 152#define LANG_HOOKS_NAME "GNU Fortran"
6de9cd9a
DN
153#define LANG_HOOKS_INIT gfc_init
154#define LANG_HOOKS_FINISH gfc_finish
8b84c596 155#define LANG_HOOKS_WRITE_GLOBALS gfc_write_global_declarations
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
164#define LANG_HOOKS_GET_ALIAS_SET gfc_get_alias_set
165#define LANG_HOOKS_INIT_TS gfc_init_ts
6c7a4dfd
JJ
166#define LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE gfc_omp_privatize_by_reference
167#define LANG_HOOKS_OMP_PREDETERMINED_SHARING gfc_omp_predetermined_sharing
79943d19 168#define LANG_HOOKS_OMP_REPORT_DECL gfc_omp_report_decl
cd75853e 169#define LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR gfc_omp_clause_default_ctor
a68ab351
JJ
170#define LANG_HOOKS_OMP_CLAUSE_COPY_CTOR gfc_omp_clause_copy_ctor
171#define LANG_HOOKS_OMP_CLAUSE_ASSIGN_OP gfc_omp_clause_assign_op
da6f124d 172#define LANG_HOOKS_OMP_CLAUSE_LINEAR_CTOR gfc_omp_clause_linear_ctor
a68ab351 173#define LANG_HOOKS_OMP_CLAUSE_DTOR gfc_omp_clause_dtor
f014c653 174#define LANG_HOOKS_OMP_FINISH_CLAUSE gfc_omp_finish_clause
6c7a4dfd
JJ
175#define LANG_HOOKS_OMP_DISREGARD_VALUE_EXPR gfc_omp_disregard_value_expr
176#define LANG_HOOKS_OMP_PRIVATE_DEBUG_CLAUSE gfc_omp_private_debug_clause
a68ab351 177#define LANG_HOOKS_OMP_PRIVATE_OUTER_REF gfc_omp_private_outer_ref
6c7a4dfd
JJ
178#define LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES \
179 gfc_omp_firstprivatize_type_sizes
f014c653
JJ
180#define LANG_HOOKS_BUILTIN_FUNCTION gfc_builtin_function
181#define LANG_HOOKS_GET_ARRAY_DESCR_INFO gfc_get_array_descr_info
182#define LANG_HOOKS_ATTRIBUTE_TABLE gfc_attribute_table
6de9cd9a 183
4537ec0c 184struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
6de9cd9a 185
6de9cd9a
DN
186#define NULL_BINDING_LEVEL (struct binding_level *) NULL
187
188/* A chain of binding_level structures awaiting reuse. */
189
190static GTY(()) struct binding_level *free_binding_level;
191
602b8523 192/* True means we've initialized exception handling. */
87a60f68 193static bool gfc_eh_initialized_p;
602b8523 194
e5b16755
RG
195/* The current translation unit. */
196static GTY(()) tree current_translation_unit;
197
602b8523 198
6de9cd9a
DN
199static void
200gfc_create_decls (void)
201{
202 /* GCC builtins. */
203 gfc_init_builtin_functions ();
204
205 /* Runtime/IO library functions. */
206 gfc_build_builtin_function_decls ();
207
208 gfc_init_constants ();
e5b16755
RG
209
210 /* Build our translation-unit decl. */
211 current_translation_unit = build_translation_unit_decl (NULL_TREE);
6de9cd9a
DN
212}
213
b251af97 214
6de9cd9a 215static void
b37421c6 216gfc_be_parse_file (void)
6de9cd9a
DN
217{
218 int errors;
219 int warnings;
220
221 gfc_create_decls ();
222 gfc_parse_file ();
223 gfc_generate_constructors ();
224
df2fba9e 225 /* Tell the frontend about any errors. */
6de9cd9a
DN
226 gfc_get_errors (&warnings, &errors);
227 errorcount += errors;
228 warningcount += warnings;
30e257e5 229
87a60f68
SB
230 /* Clear the binding level stack. */
231 while (!global_bindings_p ())
232 poplevel (0, 0);
6de9cd9a 233}
b251af97
SK
234
235
6de9cd9a
DN
236/* Initialize everything. */
237
238static bool
239gfc_init (void)
240{
670637ee
DF
241 if (!gfc_cpp_enabled ())
242 {
243 linemap_add (line_table, LC_ENTER, false, gfc_source_file, 1);
244 linemap_add (line_table, LC_RENAME, false, "<built-in>", 0);
245 }
246 else
247 gfc_cpp_init_0 ();
c8cc8542 248
6de9cd9a
DN
249 gfc_init_decl_processing ();
250 gfc_static_ctors = NULL_TREE;
251
670637ee
DF
252 if (gfc_cpp_enabled ())
253 gfc_cpp_init ();
254
6de9cd9a
DN
255 gfc_init_1 ();
256
524af0d6 257 if (!gfc_new_file ())
e0bcf78c 258 fatal_error ("can't open input file: %s", gfc_source_file);
670637ee 259
566916e6
TB
260 if (flag_preprocess_only)
261 return false;
262
6de9cd9a
DN
263 return true;
264}
265
266
267static void
268gfc_finish (void)
269{
670637ee 270 gfc_cpp_done ();
6de9cd9a
DN
271 gfc_done_1 ();
272 gfc_release_include_path ();
273 return;
274}
275
8b84c596
RH
276/* ??? This is something of a hack.
277
278 Emulated tls lowering needs to see all TLS variables before we call
65d630d4 279 finalize_compilation_unit. The C/C++ front ends manage this
8b84c596
RH
280 by calling decl_rest_of_compilation on each global and static variable
281 as they are seen. The Fortran front end waits until this hook.
282
65d630d4 283 A Correct solution is for finalize_compilation_unit not to be
8b84c596
RH
284 called during the WRITE_GLOBALS langhook, and have that hook only do what
285 its name suggests and write out globals. But the C++ and Java front ends
286 have (unspecified) problems with aliases that gets in the way. It has
287 been suggested that these problems would be solved by completing the
288 conversion to cgraph-based aliases. */
289
290static void
291gfc_write_global_declarations (void)
292{
293 tree decl;
294
295 /* Finalize all of the globals. */
296 for (decl = getdecls(); decl ; decl = DECL_CHAIN (decl))
297 rest_of_decl_compilation (decl, true, true);
298
299 write_global_declarations ();
300}
301
6de9cd9a
DN
302/* These functions and variables deal with binding contours. We only
303 need these functions for the list of PARM_DECLs, but we leave the
304 functions more general; these are a simplified version of the
305 functions from GNAT. */
306
b251af97
SK
307/* For each binding contour we allocate a binding_level structure which
308 records the entities defined or declared in that contour. Contours
309 include:
6de9cd9a
DN
310
311 the global one
312 one for each subprogram definition
313 one for each compound statement (declare block)
314
315 Binding contours are used to create GCC tree BLOCK nodes. */
316
d1b38208
TG
317struct GTY(())
318binding_level {
6de9cd9a
DN
319 /* A chain of ..._DECL nodes for all variables, constants, functions,
320 parameters and type declarations. These ..._DECL nodes are chained
87a60f68 321 through the DECL_CHAIN field. */
6de9cd9a
DN
322 tree names;
323 /* For each level (except the global one), a chain of BLOCK nodes for all
324 the levels that were entered and exited one level down from this one. */
325 tree blocks;
f7b529fa 326 /* The binding level containing this one (the enclosing binding level). */
6de9cd9a
DN
327 struct binding_level *level_chain;
328};
329
330/* The binding level currently in effect. */
331static GTY(()) struct binding_level *current_binding_level = NULL;
332
333/* The outermost binding level. This binding level is created when the
334 compiler is started and it will exist through the entire compilation. */
335static GTY(()) struct binding_level *global_binding_level;
336
337/* Binding level structures are initialized by copying this one. */
9dcf6e73 338static struct binding_level clear_binding_level = { NULL, NULL, NULL };
b251af97
SK
339
340
c99c0026 341/* Return true if we are in the global binding level. */
6de9cd9a 342
c99c0026 343bool
6de9cd9a
DN
344global_bindings_p (void)
345{
c99c0026 346 return current_binding_level == global_binding_level;
6de9cd9a
DN
347}
348
349tree
350getdecls (void)
351{
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;
87a60f68 389 tree decl_chain = current_binding_level->names;
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
530 only use it for actual characters, not for INTEGER(1). Also, we
f7b529fa 531 want double_type_node to actually have double precision. */
1a072294 532 build_common_tree_nodes (false, false);
c1775967 533
24cc1193 534 void_list_node = build_tree_list (NULL_TREE, void_type_node);
6de9cd9a
DN
535
536 /* Set up F95 type nodes. */
5e8e542f 537 gfc_init_kinds ();
6de9cd9a 538 gfc_init_types ();
28d0b595 539 gfc_init_c_interop_kinds ();
6de9cd9a
DN
540}
541
b251af97 542
7b9c708f
JJ
543/* Return the typed-based alias set for T, which may be an expression
544 or a type. Return -1 if we don't do anything special. */
545
4862826d 546static alias_set_type
7b9c708f
JJ
547gfc_get_alias_set (tree t)
548{
549 tree u;
550
551 /* Permit type-punning when accessing an EQUIVALENCEd variable or
552 mixed type entry master's return value. */
553 for (u = t; handled_component_p (u); u = TREE_OPERAND (u, 0))
554 if (TREE_CODE (u) == COMPONENT_REF
555 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
556 return 0;
557
558 return -1;
559}
560
1f2959f0 561/* Builtin function initialization. */
6de9cd9a 562
87a60f68 563static tree
c79efc4d 564gfc_builtin_function (tree decl)
6de9cd9a 565{
6de9cd9a 566 pushdecl (decl);
6de9cd9a
DN
567 return decl;
568}
569
5325296e 570/* So far we need just these 7 attribute types. */
acf0174b 571#define ATTR_NULL 0
5325296e 572#define ATTR_LEAF_LIST (ECF_LEAF)
d724c876 573#define ATTR_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF)
46de9f5e 574#define ATTR_NOTHROW_LEAF_MALLOC_LIST (ECF_NOTHROW | ECF_LEAF | ECF_MALLOC)
d724c876 575#define ATTR_CONST_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF | ECF_CONST)
3b7ea188 576#define ATTR_PURE_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF | ECF_PURE)
d724c876
JJ
577#define ATTR_NOTHROW_LIST (ECF_NOTHROW)
578#define ATTR_CONST_NOTHROW_LIST (ECF_NOTHROW | ECF_CONST)
6de9cd9a
DN
579
580static void
e79983f4 581gfc_define_builtin (const char *name, tree type, enum built_in_function code,
d724c876 582 const char *library_name, int attr)
6de9cd9a
DN
583{
584 tree decl;
585
c79efc4d
RÁE
586 decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
587 library_name, NULL_TREE);
46de9f5e 588 set_call_expr_flags (decl, attr);
6de9cd9a 589
e79983f4 590 set_builtin_decl (code, decl, true);
6de9cd9a
DN
591}
592
593
e8525382 594#define DO_DEFINE_MATH_BUILTIN(code, name, argtype, tbase) \
644cb69f 595 gfc_define_builtin ("__builtin_" name "l", tbase##longdouble[argtype], \
d724c876
JJ
596 BUILT_IN_ ## code ## L, name "l", \
597 ATTR_CONST_NOTHROW_LEAF_LIST); \
e8525382 598 gfc_define_builtin ("__builtin_" name, tbase##double[argtype], \
d724c876
JJ
599 BUILT_IN_ ## code, name, \
600 ATTR_CONST_NOTHROW_LEAF_LIST); \
e8525382 601 gfc_define_builtin ("__builtin_" name "f", tbase##float[argtype], \
d724c876
JJ
602 BUILT_IN_ ## code ## F, name "f", \
603 ATTR_CONST_NOTHROW_LEAF_LIST);
6de9cd9a 604
e8525382
SK
605#define DEFINE_MATH_BUILTIN(code, name, argtype) \
606 DO_DEFINE_MATH_BUILTIN (code, name, argtype, mfunc_)
607
e8525382 608#define DEFINE_MATH_BUILTIN_C(code, name, argtype) \
644cb69f
FXC
609 DO_DEFINE_MATH_BUILTIN (code, name, argtype, mfunc_) \
610 DO_DEFINE_MATH_BUILTIN (C##code, "c" name, argtype, mfunc_c)
e8525382
SK
611
612
613/* Create function types for builtin functions. */
614
615static void
b251af97 616build_builtin_fntypes (tree *fntype, tree type)
e8525382 617{
e8525382 618 /* type (*) (type) */
b64fca63 619 fntype[0] = build_function_type_list (type, type, NULL_TREE);
e8525382 620 /* type (*) (type, type) */
b64fca63 621 fntype[1] = build_function_type_list (type, type, type, NULL_TREE);
b5a4419c 622 /* type (*) (type, int) */
b64fca63
NF
623 fntype[2] = build_function_type_list (type,
624 type, integer_type_node, NULL_TREE);
625 /* type (*) (void) */
626 fntype[3] = build_function_type_list (type, NULL_TREE);
db7f455b
DS
627 /* type (*) (type, &int) */
628 fntype[4] = build_function_type_list (type, type,
b64fca63 629 build_pointer_type (integer_type_node),
b64fca63
NF
630 NULL_TREE);
631 /* type (*) (int, type) */
632 fntype[5] = build_function_type_list (type,
633 integer_type_node, type, NULL_TREE);
e8525382
SK
634}
635
b251af97 636
6c7a4dfd
JJ
637static tree
638builtin_type_for_size (int size, bool unsignedp)
639{
21fa2faf 640 tree type = gfc_type_for_size (size, unsignedp);
6c7a4dfd
JJ
641 return type ? type : error_mark_node;
642}
e8525382 643
1f2959f0 644/* Initialization of builtin function nodes. */
e8525382 645
6de9cd9a
DN
646static void
647gfc_init_builtin_functions (void)
648{
6c7a4dfd
JJ
649 enum builtin_type
650 {
651#define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
652#define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
653#define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
654#define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
655#define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
656#define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
657#define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
f6a7cffc
TS
658#define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
659 ARG6) NAME,
660#define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
661 ARG6, ARG7) NAME,
662#define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
663 ARG6, ARG7, ARG8) NAME,
6c7a4dfd
JJ
664#define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
665#define DEF_POINTER_TYPE(NAME, TYPE) NAME,
666#include "types.def"
667#undef DEF_PRIMITIVE_TYPE
668#undef DEF_FUNCTION_TYPE_0
669#undef DEF_FUNCTION_TYPE_1
670#undef DEF_FUNCTION_TYPE_2
671#undef DEF_FUNCTION_TYPE_3
672#undef DEF_FUNCTION_TYPE_4
673#undef DEF_FUNCTION_TYPE_5
674#undef DEF_FUNCTION_TYPE_6
675#undef DEF_FUNCTION_TYPE_7
acf0174b 676#undef DEF_FUNCTION_TYPE_8
6c7a4dfd
JJ
677#undef DEF_FUNCTION_TYPE_VAR_0
678#undef DEF_POINTER_TYPE
679 BT_LAST
680 };
6c7a4dfd 681
b5a4419c
FXC
682 tree mfunc_float[6];
683 tree mfunc_double[6];
684 tree mfunc_longdouble[6];
685 tree mfunc_cfloat[6];
686 tree mfunc_cdouble[6];
687 tree mfunc_clongdouble[6];
3a53e165
RG
688 tree func_cfloat_float, func_float_cfloat;
689 tree func_cdouble_double, func_double_cdouble;
690 tree func_clongdouble_longdouble, func_longdouble_clongdouble;
691 tree func_float_floatp_floatp;
692 tree func_double_doublep_doublep;
693 tree func_longdouble_longdoublep_longdoublep;
694 tree ftype, ptype;
6c7a4dfd 695 tree builtin_types[(int) BT_LAST + 1];
6de9cd9a 696
3b7ea188
FXC
697 int attr;
698
e8525382
SK
699 build_builtin_fntypes (mfunc_float, float_type_node);
700 build_builtin_fntypes (mfunc_double, double_type_node);
644cb69f 701 build_builtin_fntypes (mfunc_longdouble, long_double_type_node);
e8525382
SK
702 build_builtin_fntypes (mfunc_cfloat, complex_float_type_node);
703 build_builtin_fntypes (mfunc_cdouble, complex_double_type_node);
644cb69f 704 build_builtin_fntypes (mfunc_clongdouble, complex_long_double_type_node);
e8525382 705
b64fca63
NF
706 func_cfloat_float = build_function_type_list (float_type_node,
707 complex_float_type_node,
708 NULL_TREE);
6de9cd9a 709
b64fca63
NF
710 func_float_cfloat = build_function_type_list (complex_float_type_node,
711 float_type_node, NULL_TREE);
3a53e165 712
b64fca63
NF
713 func_cdouble_double = build_function_type_list (double_type_node,
714 complex_double_type_node,
715 NULL_TREE);
6de9cd9a 716
b64fca63
NF
717 func_double_cdouble = build_function_type_list (complex_double_type_node,
718 double_type_node, NULL_TREE);
3a53e165 719
644cb69f 720 func_clongdouble_longdouble =
b64fca63
NF
721 build_function_type_list (long_double_type_node,
722 complex_long_double_type_node, NULL_TREE);
644cb69f 723
3a53e165 724 func_longdouble_clongdouble =
b64fca63
NF
725 build_function_type_list (complex_long_double_type_node,
726 long_double_type_node, NULL_TREE);
3a53e165
RG
727
728 ptype = build_pointer_type (float_type_node);
3a53e165 729 func_float_floatp_floatp =
b64fca63 730 build_function_type_list (void_type_node, ptype, ptype, NULL_TREE);
3a53e165
RG
731
732 ptype = build_pointer_type (double_type_node);
3a53e165 733 func_double_doublep_doublep =
b64fca63 734 build_function_type_list (void_type_node, ptype, ptype, NULL_TREE);
3a53e165
RG
735
736 ptype = build_pointer_type (long_double_type_node);
3a53e165 737 func_longdouble_longdoublep_longdoublep =
b64fca63 738 build_function_type_list (void_type_node, ptype, ptype, NULL_TREE);
3a53e165 739
2921157d 740/* Non-math builtins are defined manually, so they're not included here. */
a3c85b74 741#define OTHER_BUILTIN(ID,NAME,TYPE,CONST)
2921157d 742
6de9cd9a
DN
743#include "mathbuiltins.def"
744
644cb69f 745 gfc_define_builtin ("__builtin_roundl", mfunc_longdouble[0],
d724c876 746 BUILT_IN_ROUNDL, "roundl", ATTR_CONST_NOTHROW_LEAF_LIST);
6de9cd9a 747 gfc_define_builtin ("__builtin_round", mfunc_double[0],
d724c876 748 BUILT_IN_ROUND, "round", ATTR_CONST_NOTHROW_LEAF_LIST);
6de9cd9a 749 gfc_define_builtin ("__builtin_roundf", mfunc_float[0],
d724c876 750 BUILT_IN_ROUNDF, "roundf", ATTR_CONST_NOTHROW_LEAF_LIST);
644cb69f
FXC
751
752 gfc_define_builtin ("__builtin_truncl", mfunc_longdouble[0],
d724c876 753 BUILT_IN_TRUNCL, "truncl", ATTR_CONST_NOTHROW_LEAF_LIST);
e743d142 754 gfc_define_builtin ("__builtin_trunc", mfunc_double[0],
d724c876 755 BUILT_IN_TRUNC, "trunc", ATTR_CONST_NOTHROW_LEAF_LIST);
e743d142 756 gfc_define_builtin ("__builtin_truncf", mfunc_float[0],
d724c876 757 BUILT_IN_TRUNCF, "truncf", ATTR_CONST_NOTHROW_LEAF_LIST);
e743d142 758
644cb69f 759 gfc_define_builtin ("__builtin_cabsl", func_clongdouble_longdouble,
d724c876 760 BUILT_IN_CABSL, "cabsl", ATTR_CONST_NOTHROW_LEAF_LIST);
ead6d15f 761 gfc_define_builtin ("__builtin_cabs", func_cdouble_double,
d724c876 762 BUILT_IN_CABS, "cabs", ATTR_CONST_NOTHROW_LEAF_LIST);
ead6d15f 763 gfc_define_builtin ("__builtin_cabsf", func_cfloat_float,
d724c876 764 BUILT_IN_CABSF, "cabsf", ATTR_CONST_NOTHROW_LEAF_LIST);
c6a912da 765
644cb69f 766 gfc_define_builtin ("__builtin_copysignl", mfunc_longdouble[1],
d724c876
JJ
767 BUILT_IN_COPYSIGNL, "copysignl",
768 ATTR_CONST_NOTHROW_LEAF_LIST);
ead6d15f 769 gfc_define_builtin ("__builtin_copysign", mfunc_double[1],
d724c876
JJ
770 BUILT_IN_COPYSIGN, "copysign",
771 ATTR_CONST_NOTHROW_LEAF_LIST);
ead6d15f 772 gfc_define_builtin ("__builtin_copysignf", mfunc_float[1],
d724c876
JJ
773 BUILT_IN_COPYSIGNF, "copysignf",
774 ATTR_CONST_NOTHROW_LEAF_LIST);
58b6e047 775
b5a4419c 776 gfc_define_builtin ("__builtin_nextafterl", mfunc_longdouble[1],
d724c876
JJ
777 BUILT_IN_NEXTAFTERL, "nextafterl",
778 ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 779 gfc_define_builtin ("__builtin_nextafter", mfunc_double[1],
d724c876
JJ
780 BUILT_IN_NEXTAFTER, "nextafter",
781 ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 782 gfc_define_builtin ("__builtin_nextafterf", mfunc_float[1],
d724c876
JJ
783 BUILT_IN_NEXTAFTERF, "nextafterf",
784 ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 785
3b7ea188
FXC
786 /* Some built-ins depend on rounding mode. Depending on compilation options, they
787 will be "pure" or "const". */
788 attr = flag_rounding_math ? ATTR_PURE_NOTHROW_LEAF_LIST : ATTR_CONST_NOTHROW_LEAF_LIST;
789
790 gfc_define_builtin ("__builtin_rintl", mfunc_longdouble[0],
791 BUILT_IN_RINTL, "rintl", attr);
792 gfc_define_builtin ("__builtin_rint", mfunc_double[0],
793 BUILT_IN_RINT, "rint", attr);
794 gfc_define_builtin ("__builtin_rintf", mfunc_float[0],
795 BUILT_IN_RINTF, "rintf", attr);
796
797 gfc_define_builtin ("__builtin_remainderl", mfunc_longdouble[1],
798 BUILT_IN_REMAINDERL, "remainderl", attr);
799 gfc_define_builtin ("__builtin_remainder", mfunc_double[1],
800 BUILT_IN_REMAINDER, "remainder", attr);
801 gfc_define_builtin ("__builtin_remainderf", mfunc_float[1],
802 BUILT_IN_REMAINDERF, "remainderf", attr);
803
804 gfc_define_builtin ("__builtin_logbl", mfunc_longdouble[0],
805 BUILT_IN_LOGBL, "logbl", ATTR_CONST_NOTHROW_LEAF_LIST);
806 gfc_define_builtin ("__builtin_logb", mfunc_double[0],
807 BUILT_IN_LOGB, "logb", ATTR_CONST_NOTHROW_LEAF_LIST);
808 gfc_define_builtin ("__builtin_logbf", mfunc_float[0],
809 BUILT_IN_LOGBF, "logbf", ATTR_CONST_NOTHROW_LEAF_LIST);
810
811
b5a4419c 812 gfc_define_builtin ("__builtin_frexpl", mfunc_longdouble[4],
d724c876 813 BUILT_IN_FREXPL, "frexpl", ATTR_NOTHROW_LEAF_LIST);
b5a4419c 814 gfc_define_builtin ("__builtin_frexp", mfunc_double[4],
d724c876 815 BUILT_IN_FREXP, "frexp", ATTR_NOTHROW_LEAF_LIST);
b5a4419c 816 gfc_define_builtin ("__builtin_frexpf", mfunc_float[4],
d724c876 817 BUILT_IN_FREXPF, "frexpf", ATTR_NOTHROW_LEAF_LIST);
b5a4419c
FXC
818
819 gfc_define_builtin ("__builtin_fabsl", mfunc_longdouble[0],
d724c876 820 BUILT_IN_FABSL, "fabsl", ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 821 gfc_define_builtin ("__builtin_fabs", mfunc_double[0],
d724c876 822 BUILT_IN_FABS, "fabs", ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 823 gfc_define_builtin ("__builtin_fabsf", mfunc_float[0],
d724c876 824 BUILT_IN_FABSF, "fabsf", ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c
FXC
825
826 gfc_define_builtin ("__builtin_scalbnl", mfunc_longdouble[5],
d724c876 827 BUILT_IN_SCALBNL, "scalbnl", ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 828 gfc_define_builtin ("__builtin_scalbn", mfunc_double[5],
d724c876 829 BUILT_IN_SCALBN, "scalbn", ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 830 gfc_define_builtin ("__builtin_scalbnf", mfunc_float[5],
d724c876 831 BUILT_IN_SCALBNF, "scalbnf", ATTR_CONST_NOTHROW_LEAF_LIST);
b5a4419c 832
58b6e047 833 gfc_define_builtin ("__builtin_fmodl", mfunc_longdouble[1],
d724c876 834 BUILT_IN_FMODL, "fmodl", ATTR_CONST_NOTHROW_LEAF_LIST);
58b6e047 835 gfc_define_builtin ("__builtin_fmod", mfunc_double[1],
d724c876 836 BUILT_IN_FMOD, "fmod", ATTR_CONST_NOTHROW_LEAF_LIST);
58b6e047 837 gfc_define_builtin ("__builtin_fmodf", mfunc_float[1],
d724c876 838 BUILT_IN_FMODF, "fmodf", ATTR_CONST_NOTHROW_LEAF_LIST);
6de9cd9a 839
6715d47b
JB
840 /* iround{f,,l}, lround{f,,l} and llround{f,,l} */
841 ftype = build_function_type_list (integer_type_node,
842 float_type_node, NULL_TREE);
843 gfc_define_builtin("__builtin_iroundf", ftype, BUILT_IN_IROUNDF,
844 "iroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
845 ftype = build_function_type_list (long_integer_type_node,
846 float_type_node, NULL_TREE);
847 gfc_define_builtin ("__builtin_lroundf", ftype, BUILT_IN_LROUNDF,
d724c876 848 "lroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
849 ftype = build_function_type_list (long_long_integer_type_node,
850 float_type_node, NULL_TREE);
851 gfc_define_builtin ("__builtin_llroundf", ftype, BUILT_IN_LLROUNDF,
d724c876 852 "llroundf", ATTR_CONST_NOTHROW_LEAF_LIST);
94f548c2 853
6715d47b
JB
854 ftype = build_function_type_list (integer_type_node,
855 double_type_node, NULL_TREE);
856 gfc_define_builtin("__builtin_iround", ftype, BUILT_IN_IROUND,
857 "iround", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
858 ftype = build_function_type_list (long_integer_type_node,
859 double_type_node, NULL_TREE);
860 gfc_define_builtin ("__builtin_lround", ftype, BUILT_IN_LROUND,
d724c876 861 "lround", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
862 ftype = build_function_type_list (long_long_integer_type_node,
863 double_type_node, NULL_TREE);
864 gfc_define_builtin ("__builtin_llround", ftype, BUILT_IN_LLROUND,
d724c876 865 "llround", ATTR_CONST_NOTHROW_LEAF_LIST);
94f548c2 866
6715d47b
JB
867 ftype = build_function_type_list (integer_type_node,
868 long_double_type_node, NULL_TREE);
869 gfc_define_builtin("__builtin_iroundl", ftype, BUILT_IN_IROUNDL,
870 "iroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
871 ftype = build_function_type_list (long_integer_type_node,
872 long_double_type_node, NULL_TREE);
873 gfc_define_builtin ("__builtin_lroundl", ftype, BUILT_IN_LROUNDL,
d724c876 874 "lroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
b64fca63
NF
875 ftype = build_function_type_list (long_long_integer_type_node,
876 long_double_type_node, NULL_TREE);
877 gfc_define_builtin ("__builtin_llroundl", ftype, BUILT_IN_LLROUNDL,
d724c876 878 "llroundl", ATTR_CONST_NOTHROW_LEAF_LIST);
94f548c2 879
5b200ac2 880 /* These are used to implement the ** operator. */
644cb69f 881 gfc_define_builtin ("__builtin_powl", mfunc_longdouble[1],
d724c876 882 BUILT_IN_POWL, "powl", ATTR_CONST_NOTHROW_LEAF_LIST);
c7d78bbe 883 gfc_define_builtin ("__builtin_pow", mfunc_double[1],
d724c876 884 BUILT_IN_POW, "pow", ATTR_CONST_NOTHROW_LEAF_LIST);
c7d78bbe 885 gfc_define_builtin ("__builtin_powf", mfunc_float[1],
d724c876 886 BUILT_IN_POWF, "powf", ATTR_CONST_NOTHROW_LEAF_LIST);
fb220235 887 gfc_define_builtin ("__builtin_cpowl", mfunc_clongdouble[1],
d724c876 888 BUILT_IN_CPOWL, "cpowl", ATTR_CONST_NOTHROW_LEAF_LIST);
fb220235 889 gfc_define_builtin ("__builtin_cpow", mfunc_cdouble[1],
d724c876 890 BUILT_IN_CPOW, "cpow", ATTR_CONST_NOTHROW_LEAF_LIST);
fb220235 891 gfc_define_builtin ("__builtin_cpowf", mfunc_cfloat[1],
d724c876 892 BUILT_IN_CPOWF, "cpowf", ATTR_CONST_NOTHROW_LEAF_LIST);
31c97dfe 893 gfc_define_builtin ("__builtin_powil", mfunc_longdouble[2],
d724c876 894 BUILT_IN_POWIL, "powil", ATTR_CONST_NOTHROW_LEAF_LIST);
31c97dfe 895 gfc_define_builtin ("__builtin_powi", mfunc_double[2],
d724c876 896 BUILT_IN_POWI, "powi", ATTR_CONST_NOTHROW_LEAF_LIST);
31c97dfe 897 gfc_define_builtin ("__builtin_powif", mfunc_float[2],
d724c876 898 BUILT_IN_POWIF, "powif", ATTR_CONST_NOTHROW_LEAF_LIST);
31c97dfe 899
5b200ac2 900
d33d9e47 901 if (targetm.libc_has_function (function_c99_math_complex))
3a53e165
RG
902 {
903 gfc_define_builtin ("__builtin_cbrtl", mfunc_longdouble[0],
d724c876
JJ
904 BUILT_IN_CBRTL, "cbrtl",
905 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165 906 gfc_define_builtin ("__builtin_cbrt", mfunc_double[0],
d724c876
JJ
907 BUILT_IN_CBRT, "cbrt",
908 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165 909 gfc_define_builtin ("__builtin_cbrtf", mfunc_float[0],
d724c876
JJ
910 BUILT_IN_CBRTF, "cbrtf",
911 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165 912 gfc_define_builtin ("__builtin_cexpil", func_longdouble_clongdouble,
d724c876
JJ
913 BUILT_IN_CEXPIL, "cexpil",
914 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165 915 gfc_define_builtin ("__builtin_cexpi", func_double_cdouble,
d724c876
JJ
916 BUILT_IN_CEXPI, "cexpi",
917 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165 918 gfc_define_builtin ("__builtin_cexpif", func_float_cfloat,
d724c876
JJ
919 BUILT_IN_CEXPIF, "cexpif",
920 ATTR_CONST_NOTHROW_LEAF_LIST);
3a53e165
RG
921 }
922
d33d9e47 923 if (targetm.libc_has_function (function_sincos))
3a53e165
RG
924 {
925 gfc_define_builtin ("__builtin_sincosl",
926 func_longdouble_longdoublep_longdoublep,
d724c876 927 BUILT_IN_SINCOSL, "sincosl", ATTR_NOTHROW_LEAF_LIST);
3a53e165 928 gfc_define_builtin ("__builtin_sincos", func_double_doublep_doublep,
d724c876 929 BUILT_IN_SINCOS, "sincos", ATTR_NOTHROW_LEAF_LIST);
3a53e165 930 gfc_define_builtin ("__builtin_sincosf", func_float_floatp_floatp,
d724c876 931 BUILT_IN_SINCOSF, "sincosf", ATTR_NOTHROW_LEAF_LIST);
3a53e165
RG
932 }
933
451238b7 934 /* For LEADZ, TRAILZ, POPCNT and POPPAR. */
b64fca63
NF
935 ftype = build_function_type_list (integer_type_node,
936 unsigned_type_node, NULL_TREE);
414f00e9 937 gfc_define_builtin ("__builtin_clz", ftype, BUILT_IN_CLZ,
d724c876 938 "__builtin_clz", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 939 gfc_define_builtin ("__builtin_ctz", ftype, BUILT_IN_CTZ,
d724c876 940 "__builtin_ctz", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 941 gfc_define_builtin ("__builtin_parity", ftype, BUILT_IN_PARITY,
d724c876 942 "__builtin_parity", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 943 gfc_define_builtin ("__builtin_popcount", ftype, BUILT_IN_POPCOUNT,
d724c876 944 "__builtin_popcount", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 945
b64fca63
NF
946 ftype = build_function_type_list (integer_type_node,
947 long_unsigned_type_node, NULL_TREE);
948 gfc_define_builtin ("__builtin_clzl", ftype, BUILT_IN_CLZL,
d724c876 949 "__builtin_clzl", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 950 gfc_define_builtin ("__builtin_ctzl", ftype, BUILT_IN_CTZL,
d724c876 951 "__builtin_ctzl", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 952 gfc_define_builtin ("__builtin_parityl", ftype, BUILT_IN_PARITYL,
d724c876 953 "__builtin_parityl", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 954 gfc_define_builtin ("__builtin_popcountl", ftype, BUILT_IN_POPCOUNTL,
d724c876 955 "__builtin_popcountl", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 956
b64fca63
NF
957 ftype = build_function_type_list (integer_type_node,
958 long_long_unsigned_type_node, NULL_TREE);
959 gfc_define_builtin ("__builtin_clzll", ftype, BUILT_IN_CLZLL,
d724c876 960 "__builtin_clzll", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 961 gfc_define_builtin ("__builtin_ctzll", ftype, BUILT_IN_CTZLL,
d724c876 962 "__builtin_ctzll", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 963 gfc_define_builtin ("__builtin_parityll", ftype, BUILT_IN_PARITYLL,
d724c876 964 "__builtin_parityll", ATTR_CONST_NOTHROW_LEAF_LIST);
ad5f4de2 965 gfc_define_builtin ("__builtin_popcountll", ftype, BUILT_IN_POPCOUNTLL,
d724c876 966 "__builtin_popcountll", ATTR_CONST_NOTHROW_LEAF_LIST);
414f00e9 967
6de9cd9a
DN
968 /* Other builtin functions we use. */
969
b64fca63
NF
970 ftype = build_function_type_list (long_integer_type_node,
971 long_integer_type_node,
972 long_integer_type_node, NULL_TREE);
c6a912da 973 gfc_define_builtin ("__builtin_expect", ftype, BUILT_IN_EXPECT,
d724c876 974 "__builtin_expect", ATTR_CONST_NOTHROW_LEAF_LIST);
ef9312c1 975
b64fca63
NF
976 ftype = build_function_type_list (void_type_node,
977 pvoid_type_node, NULL_TREE);
1529b8d9 978 gfc_define_builtin ("__builtin_free", ftype, BUILT_IN_FREE,
d724c876 979 "free", ATTR_NOTHROW_LEAF_LIST);
1529b8d9 980
b64fca63
NF
981 ftype = build_function_type_list (pvoid_type_node,
982 size_type_node, NULL_TREE);
1529b8d9 983 gfc_define_builtin ("__builtin_malloc", ftype, BUILT_IN_MALLOC,
46de9f5e 984 "malloc", ATTR_NOTHROW_LEAF_MALLOC_LIST);
1529b8d9 985
4df0f7da
TB
986 ftype = build_function_type_list (pvoid_type_node, size_type_node,
987 size_type_node, NULL_TREE);
988 gfc_define_builtin ("__builtin_calloc", ftype, BUILT_IN_CALLOC,
46de9f5e 989 "calloc", ATTR_NOTHROW_LEAF_MALLOC_LIST);
4df0f7da
TB
990 DECL_IS_MALLOC (builtin_decl_explicit (BUILT_IN_CALLOC)) = 1;
991
b64fca63
NF
992 ftype = build_function_type_list (pvoid_type_node,
993 size_type_node, pvoid_type_node,
994 NULL_TREE);
4376b7cf 995 gfc_define_builtin ("__builtin_realloc", ftype, BUILT_IN_REALLOC,
d724c876 996 "realloc", ATTR_NOTHROW_LEAF_LIST);
4376b7cf 997
b64fca63
NF
998 ftype = build_function_type_list (integer_type_node,
999 void_type_node, NULL_TREE);
5fcb93f1 1000 gfc_define_builtin ("__builtin_isnan", ftype, BUILT_IN_ISNAN,
d724c876 1001 "__builtin_isnan", ATTR_CONST_NOTHROW_LEAF_LIST);
3b7ea188
FXC
1002 gfc_define_builtin ("__builtin_isfinite", ftype, BUILT_IN_ISFINITE,
1003 "__builtin_isfinite", ATTR_CONST_NOTHROW_LEAF_LIST);
1004 gfc_define_builtin ("__builtin_isnormal", ftype, BUILT_IN_ISNORMAL,
1005 "__builtin_isnormal", ATTR_CONST_NOTHROW_LEAF_LIST);
1006
1007 ftype = build_function_type_list (integer_type_node, void_type_node,
1008 void_type_node, NULL_TREE);
1009 gfc_define_builtin ("__builtin_isunordered", ftype, BUILT_IN_ISUNORDERED,
1010 "__builtin_isunordered", ATTR_CONST_NOTHROW_LEAF_LIST);
1011 gfc_define_builtin ("__builtin_islessequal", ftype, BUILT_IN_ISLESSEQUAL,
1012 "__builtin_islessequal", ATTR_CONST_NOTHROW_LEAF_LIST);
1013 gfc_define_builtin ("__builtin_isgreaterequal", ftype,
1014 BUILT_IN_ISGREATEREQUAL, "__builtin_isgreaterequal",
1015 ATTR_CONST_NOTHROW_LEAF_LIST);
1016
1017 ftype = build_function_type_list (integer_type_node,
1018 float_type_node, NULL_TREE);
1019 gfc_define_builtin("__builtin_signbitf", ftype, BUILT_IN_SIGNBITF,
1020 "signbitf", ATTR_CONST_NOTHROW_LEAF_LIST);
1021 ftype = build_function_type_list (integer_type_node,
1022 double_type_node, NULL_TREE);
1023 gfc_define_builtin("__builtin_signbit", ftype, BUILT_IN_SIGNBIT,
1024 "signbit", ATTR_CONST_NOTHROW_LEAF_LIST);
1025 ftype = build_function_type_list (integer_type_node,
1026 long_double_type_node, NULL_TREE);
1027 gfc_define_builtin("__builtin_signbitl", ftype, BUILT_IN_SIGNBITL,
1028 "signbitl", ATTR_CONST_NOTHROW_LEAF_LIST);
1029
5fcb93f1 1030
6c7a4dfd
JJ
1031#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
1032 builtin_types[(int) ENUM] = VALUE;
b64fca63
NF
1033#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
1034 builtin_types[(int) ENUM] \
1035 = build_function_type_list (builtin_types[(int) RETURN], \
1036 NULL_TREE);
6c7a4dfd
JJ
1037#define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
1038 builtin_types[(int) ENUM] \
b64fca63
NF
1039 = build_function_type_list (builtin_types[(int) RETURN], \
1040 builtin_types[(int) ARG1], \
1041 NULL_TREE);
1042#define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
1043 builtin_types[(int) ENUM] \
1044 = build_function_type_list (builtin_types[(int) RETURN], \
1045 builtin_types[(int) ARG1], \
1046 builtin_types[(int) ARG2], \
1047 NULL_TREE);
1048#define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
1049 builtin_types[(int) ENUM] \
1050 = build_function_type_list (builtin_types[(int) RETURN], \
1051 builtin_types[(int) ARG1], \
1052 builtin_types[(int) ARG2], \
1053 builtin_types[(int) ARG3], \
1054 NULL_TREE);
6c7a4dfd
JJ
1055#define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
1056 builtin_types[(int) ENUM] \
b64fca63
NF
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 builtin_types[(int) ARG4], \
1062 NULL_TREE);
6c7a4dfd
JJ
1063#define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
1064 builtin_types[(int) ENUM] \
b64fca63
NF
1065 = build_function_type_list (builtin_types[(int) RETURN], \
1066 builtin_types[(int) ARG1], \
1067 builtin_types[(int) ARG2], \
1068 builtin_types[(int) ARG3], \
1069 builtin_types[(int) ARG4], \
1070 builtin_types[(int) ARG5], \
1071 NULL_TREE);
6c7a4dfd
JJ
1072#define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1073 ARG6) \
1074 builtin_types[(int) ENUM] \
b64fca63
NF
1075 = build_function_type_list (builtin_types[(int) RETURN], \
1076 builtin_types[(int) ARG1], \
1077 builtin_types[(int) ARG2], \
1078 builtin_types[(int) ARG3], \
1079 builtin_types[(int) ARG4], \
1080 builtin_types[(int) ARG5], \
1081 builtin_types[(int) ARG6], \
1082 NULL_TREE);
6c7a4dfd
JJ
1083#define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1084 ARG6, ARG7) \
1085 builtin_types[(int) ENUM] \
b64fca63
NF
1086 = build_function_type_list (builtin_types[(int) RETURN], \
1087 builtin_types[(int) ARG1], \
1088 builtin_types[(int) ARG2], \
1089 builtin_types[(int) ARG3], \
1090 builtin_types[(int) ARG4], \
1091 builtin_types[(int) ARG5], \
1092 builtin_types[(int) ARG6], \
1093 builtin_types[(int) ARG7], \
1094 NULL_TREE);
acf0174b
JJ
1095#define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
1096 ARG6, ARG7, ARG8) \
1097 builtin_types[(int) ENUM] \
1098 = build_function_type_list (builtin_types[(int) RETURN], \
1099 builtin_types[(int) ARG1], \
1100 builtin_types[(int) ARG2], \
1101 builtin_types[(int) ARG3], \
1102 builtin_types[(int) ARG4], \
1103 builtin_types[(int) ARG5], \
1104 builtin_types[(int) ARG6], \
1105 builtin_types[(int) ARG7], \
1106 builtin_types[(int) ARG8], \
1107 NULL_TREE);
6c7a4dfd
JJ
1108#define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
1109 builtin_types[(int) ENUM] \
b64fca63
NF
1110 = build_varargs_function_type_list (builtin_types[(int) RETURN], \
1111 NULL_TREE);
6c7a4dfd
JJ
1112#define DEF_POINTER_TYPE(ENUM, TYPE) \
1113 builtin_types[(int) ENUM] \
1114 = build_pointer_type (builtin_types[(int) TYPE]);
1115#include "types.def"
1116#undef DEF_PRIMITIVE_TYPE
f6a7cffc 1117#undef DEF_FUNCTION_TYPE_0
6c7a4dfd
JJ
1118#undef DEF_FUNCTION_TYPE_1
1119#undef DEF_FUNCTION_TYPE_2
1120#undef DEF_FUNCTION_TYPE_3
1121#undef DEF_FUNCTION_TYPE_4
1122#undef DEF_FUNCTION_TYPE_5
1123#undef DEF_FUNCTION_TYPE_6
f6a7cffc
TS
1124#undef DEF_FUNCTION_TYPE_7
1125#undef DEF_FUNCTION_TYPE_8
6c7a4dfd
JJ
1126#undef DEF_FUNCTION_TYPE_VAR_0
1127#undef DEF_POINTER_TYPE
1128 builtin_types[(int) BT_LAST] = NULL_TREE;
1129
1130 /* Initialize synchronization builtins. */
1131#undef DEF_SYNC_BUILTIN
1132#define DEF_SYNC_BUILTIN(code, name, type, attr) \
1133 gfc_define_builtin (name, builtin_types[type], code, name, \
d724c876 1134 attr);
6c7a4dfd
JJ
1135#include "../sync-builtins.def"
1136#undef DEF_SYNC_BUILTIN
1137
92d28cbb
JJ
1138 if (gfc_option.gfc_flag_openmp
1139 || gfc_option.gfc_flag_openmp_simd
1140 || flag_tree_parallelize_loops)
6c7a4dfd
JJ
1141 {
1142#undef DEF_GOMP_BUILTIN
1143#define DEF_GOMP_BUILTIN(code, name, type, attr) \
1144 gfc_define_builtin ("__builtin_" name, builtin_types[type], \
d724c876 1145 code, name, attr);
6c7a4dfd
JJ
1146#include "../omp-builtins.def"
1147#undef DEF_GOMP_BUILTIN
1148 }
1149
1150 gfc_define_builtin ("__builtin_trap", builtin_types[BT_FN_VOID],
d724c876 1151 BUILT_IN_TRAP, NULL, ATTR_NOTHROW_LEAF_LIST);
e79983f4 1152 TREE_THIS_VOLATILE (builtin_decl_explicit (BUILT_IN_TRAP)) = 1;
6c7a4dfd 1153
b46ebd6c
JJ
1154 ftype = build_varargs_function_type_list (ptr_type_node, const_ptr_type_node,
1155 size_type_node, NULL_TREE);
1156 gfc_define_builtin ("__builtin_assume_aligned", ftype,
1157 BUILT_IN_ASSUME_ALIGNED,
1158 "__builtin_assume_aligned",
1159 ATTR_CONST_NOTHROW_LEAF_LIST);
1160
8893239d 1161 gfc_define_builtin ("__emutls_get_address",
d724c876
JJ
1162 builtin_types[BT_FN_PTR_PTR],
1163 BUILT_IN_EMUTLS_GET_ADDRESS,
1164 "__emutls_get_address", ATTR_CONST_NOTHROW_LEAF_LIST);
8893239d
RH
1165 gfc_define_builtin ("__emutls_register_common",
1166 builtin_types[BT_FN_VOID_PTR_WORD_WORD_PTR],
1167 BUILT_IN_EMUTLS_REGISTER_COMMON,
d724c876 1168 "__emutls_register_common", ATTR_NOTHROW_LEAF_LIST);
8893239d 1169
384c400a 1170 build_common_builtin_nodes ();
ef9312c1 1171 targetm.init_builtins ();
6de9cd9a
DN
1172}
1173
e8525382 1174#undef DEFINE_MATH_BUILTIN_C
6de9cd9a
DN
1175#undef DEFINE_MATH_BUILTIN
1176
a64f5186
JJ
1177static void
1178gfc_init_ts (void)
1179{
1180 tree_contains_struct[NAMESPACE_DECL][TS_DECL_NON_COMMON] = 1;
1181 tree_contains_struct[NAMESPACE_DECL][TS_DECL_WITH_VIS] = 1;
1182 tree_contains_struct[NAMESPACE_DECL][TS_DECL_WRTL] = 1;
1183 tree_contains_struct[NAMESPACE_DECL][TS_DECL_COMMON] = 1;
1184 tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1185}
1186
602b8523
TB
1187void
1188gfc_maybe_initialize_eh (void)
1189{
1190 if (!flag_exceptions || gfc_eh_initialized_p)
1191 return;
1192
1193 gfc_eh_initialized_p = true;
602b8523
TB
1194 using_eh_for_cleanups ();
1195}
1196
1197
6de9cd9a
DN
1198#include "gt-fortran-f95-lang.h"
1199#include "gtype-fortran.h"