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