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