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