1 /* Backend function setup
2 Copyright (C) 2002-2016 Free Software Foundation, Inc.
3 Contributed by Paul Brook
5 This file is part of GCC.
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
9 Software Foundation; either version 3, or (at your option) any later
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
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* trans-decl.c -- Handling of backend function and variable decls, etc */
25 #include "coretypes.h"
30 #include "gimple-expr.h" /* For create_tmp_var_raw. */
32 #include "stringpool.h"
34 #include "fold-const.h"
35 #include "stor-layout.h"
38 #include "tree-dump.h"
39 #include "toplev.h" /* For announce_function. */
41 #include "constructor.h"
42 #include "trans-types.h"
43 #include "trans-array.h"
44 #include "trans-const.h"
45 /* Only for gfc_trans_code. Shouldn't need to include this. */
46 #include "trans-stmt.h"
47 #include "gomp-constants.h"
49 #define MAX_LABEL_VALUE 99999
52 /* Holds the result of the function if no result variable specified. */
54 static GTY(()) tree current_fake_result_decl
;
55 static GTY(()) tree parent_fake_result_decl
;
58 /* Holds the variable DECLs for the current function. */
60 static GTY(()) tree saved_function_decls
;
61 static GTY(()) tree saved_parent_function_decls
;
63 static hash_set
<tree
> *nonlocal_dummy_decl_pset
;
64 static GTY(()) tree nonlocal_dummy_decls
;
66 /* Holds the variable DECLs that are locals. */
68 static GTY(()) tree saved_local_decls
;
70 /* The namespace of the module we're currently generating. Only used while
71 outputting decls for module variables. Do not rely on this being set. */
73 static gfc_namespace
*module_namespace
;
75 /* The currently processed procedure symbol. */
76 static gfc_symbol
* current_procedure_symbol
= NULL
;
78 /* The currently processed module. */
79 static struct module_htab_entry
*cur_module
;
81 /* With -fcoarray=lib: For generating the registering call
82 of static coarrays. */
83 static bool has_coarray_vars
;
84 static stmtblock_t caf_init_block
;
87 /* List of static constructor functions. */
89 tree gfc_static_ctors
;
92 /* Whether we've seen a symbol from an IEEE module in the namespace. */
93 static int seen_ieee_symbol
;
95 /* Function declarations for builtin library functions. */
97 tree gfor_fndecl_pause_numeric
;
98 tree gfor_fndecl_pause_string
;
99 tree gfor_fndecl_stop_numeric
;
100 tree gfor_fndecl_stop_numeric_f08
;
101 tree gfor_fndecl_stop_string
;
102 tree gfor_fndecl_error_stop_numeric
;
103 tree gfor_fndecl_error_stop_string
;
104 tree gfor_fndecl_runtime_error
;
105 tree gfor_fndecl_runtime_error_at
;
106 tree gfor_fndecl_runtime_warning_at
;
107 tree gfor_fndecl_os_error
;
108 tree gfor_fndecl_generate_error
;
109 tree gfor_fndecl_set_args
;
110 tree gfor_fndecl_set_fpe
;
111 tree gfor_fndecl_set_options
;
112 tree gfor_fndecl_set_convert
;
113 tree gfor_fndecl_set_record_marker
;
114 tree gfor_fndecl_set_max_subrecord_length
;
115 tree gfor_fndecl_ctime
;
116 tree gfor_fndecl_fdate
;
117 tree gfor_fndecl_ttynam
;
118 tree gfor_fndecl_in_pack
;
119 tree gfor_fndecl_in_unpack
;
120 tree gfor_fndecl_associated
;
121 tree gfor_fndecl_system_clock4
;
122 tree gfor_fndecl_system_clock8
;
123 tree gfor_fndecl_ieee_procedure_entry
;
124 tree gfor_fndecl_ieee_procedure_exit
;
127 /* Coarray run-time library function decls. */
128 tree gfor_fndecl_caf_init
;
129 tree gfor_fndecl_caf_finalize
;
130 tree gfor_fndecl_caf_this_image
;
131 tree gfor_fndecl_caf_num_images
;
132 tree gfor_fndecl_caf_register
;
133 tree gfor_fndecl_caf_deregister
;
134 tree gfor_fndecl_caf_get
;
135 tree gfor_fndecl_caf_send
;
136 tree gfor_fndecl_caf_sendget
;
137 tree gfor_fndecl_caf_sync_all
;
138 tree gfor_fndecl_caf_sync_memory
;
139 tree gfor_fndecl_caf_sync_images
;
140 tree gfor_fndecl_caf_error_stop
;
141 tree gfor_fndecl_caf_error_stop_str
;
142 tree gfor_fndecl_caf_atomic_def
;
143 tree gfor_fndecl_caf_atomic_ref
;
144 tree gfor_fndecl_caf_atomic_cas
;
145 tree gfor_fndecl_caf_atomic_op
;
146 tree gfor_fndecl_caf_lock
;
147 tree gfor_fndecl_caf_unlock
;
148 tree gfor_fndecl_caf_event_post
;
149 tree gfor_fndecl_caf_event_wait
;
150 tree gfor_fndecl_caf_event_query
;
151 tree gfor_fndecl_co_broadcast
;
152 tree gfor_fndecl_co_max
;
153 tree gfor_fndecl_co_min
;
154 tree gfor_fndecl_co_reduce
;
155 tree gfor_fndecl_co_sum
;
158 /* Math functions. Many other math functions are handled in
159 trans-intrinsic.c. */
161 gfc_powdecl_list gfor_fndecl_math_powi
[4][3];
162 tree gfor_fndecl_math_ishftc4
;
163 tree gfor_fndecl_math_ishftc8
;
164 tree gfor_fndecl_math_ishftc16
;
167 /* String functions. */
169 tree gfor_fndecl_compare_string
;
170 tree gfor_fndecl_concat_string
;
171 tree gfor_fndecl_string_len_trim
;
172 tree gfor_fndecl_string_index
;
173 tree gfor_fndecl_string_scan
;
174 tree gfor_fndecl_string_verify
;
175 tree gfor_fndecl_string_trim
;
176 tree gfor_fndecl_string_minmax
;
177 tree gfor_fndecl_adjustl
;
178 tree gfor_fndecl_adjustr
;
179 tree gfor_fndecl_select_string
;
180 tree gfor_fndecl_compare_string_char4
;
181 tree gfor_fndecl_concat_string_char4
;
182 tree gfor_fndecl_string_len_trim_char4
;
183 tree gfor_fndecl_string_index_char4
;
184 tree gfor_fndecl_string_scan_char4
;
185 tree gfor_fndecl_string_verify_char4
;
186 tree gfor_fndecl_string_trim_char4
;
187 tree gfor_fndecl_string_minmax_char4
;
188 tree gfor_fndecl_adjustl_char4
;
189 tree gfor_fndecl_adjustr_char4
;
190 tree gfor_fndecl_select_string_char4
;
193 /* Conversion between character kinds. */
194 tree gfor_fndecl_convert_char1_to_char4
;
195 tree gfor_fndecl_convert_char4_to_char1
;
198 /* Other misc. runtime library functions. */
199 tree gfor_fndecl_size0
;
200 tree gfor_fndecl_size1
;
201 tree gfor_fndecl_iargc
;
203 /* Intrinsic functions implemented in Fortran. */
204 tree gfor_fndecl_sc_kind
;
205 tree gfor_fndecl_si_kind
;
206 tree gfor_fndecl_sr_kind
;
208 /* BLAS gemm functions. */
209 tree gfor_fndecl_sgemm
;
210 tree gfor_fndecl_dgemm
;
211 tree gfor_fndecl_cgemm
;
212 tree gfor_fndecl_zgemm
;
216 gfc_add_decl_to_parent_function (tree decl
)
219 DECL_CONTEXT (decl
) = DECL_CONTEXT (current_function_decl
);
220 DECL_NONLOCAL (decl
) = 1;
221 DECL_CHAIN (decl
) = saved_parent_function_decls
;
222 saved_parent_function_decls
= decl
;
226 gfc_add_decl_to_function (tree decl
)
229 TREE_USED (decl
) = 1;
230 DECL_CONTEXT (decl
) = current_function_decl
;
231 DECL_CHAIN (decl
) = saved_function_decls
;
232 saved_function_decls
= decl
;
236 add_decl_as_local (tree decl
)
239 TREE_USED (decl
) = 1;
240 DECL_CONTEXT (decl
) = current_function_decl
;
241 DECL_CHAIN (decl
) = saved_local_decls
;
242 saved_local_decls
= decl
;
246 /* Build a backend label declaration. Set TREE_USED for named labels.
247 The context of the label is always the current_function_decl. All
248 labels are marked artificial. */
251 gfc_build_label_decl (tree label_id
)
253 /* 2^32 temporaries should be enough. */
254 static unsigned int tmp_num
= 1;
258 if (label_id
== NULL_TREE
)
260 /* Build an internal label name. */
261 ASM_FORMAT_PRIVATE_NAME (label_name
, "L", tmp_num
++);
262 label_id
= get_identifier (label_name
);
267 /* Build the LABEL_DECL node. Labels have no type. */
268 label_decl
= build_decl (input_location
,
269 LABEL_DECL
, label_id
, void_type_node
);
270 DECL_CONTEXT (label_decl
) = current_function_decl
;
271 DECL_MODE (label_decl
) = VOIDmode
;
273 /* We always define the label as used, even if the original source
274 file never references the label. We don't want all kinds of
275 spurious warnings for old-style Fortran code with too many
277 TREE_USED (label_decl
) = 1;
279 DECL_ARTIFICIAL (label_decl
) = 1;
284 /* Set the backend source location of a decl. */
287 gfc_set_decl_location (tree decl
, locus
* loc
)
289 DECL_SOURCE_LOCATION (decl
) = loc
->lb
->location
;
293 /* Return the backend label declaration for a given label structure,
294 or create it if it doesn't exist yet. */
297 gfc_get_label_decl (gfc_st_label
* lp
)
299 if (lp
->backend_decl
)
300 return lp
->backend_decl
;
303 char label_name
[GFC_MAX_SYMBOL_LEN
+ 1];
306 /* Validate the label declaration from the front end. */
307 gcc_assert (lp
!= NULL
&& lp
->value
<= MAX_LABEL_VALUE
);
309 /* Build a mangled name for the label. */
310 sprintf (label_name
, "__label_%.6d", lp
->value
);
312 /* Build the LABEL_DECL node. */
313 label_decl
= gfc_build_label_decl (get_identifier (label_name
));
315 /* Tell the debugger where the label came from. */
316 if (lp
->value
<= MAX_LABEL_VALUE
) /* An internal label. */
317 gfc_set_decl_location (label_decl
, &lp
->where
);
319 DECL_ARTIFICIAL (label_decl
) = 1;
321 /* Store the label in the label list and return the LABEL_DECL. */
322 lp
->backend_decl
= label_decl
;
328 /* Convert a gfc_symbol to an identifier of the same name. */
331 gfc_sym_identifier (gfc_symbol
* sym
)
333 if (sym
->attr
.is_main_program
&& strcmp (sym
->name
, "main") == 0)
334 return (get_identifier ("MAIN__"));
336 return (get_identifier (sym
->name
));
340 /* Construct mangled name from symbol name. */
343 gfc_sym_mangled_identifier (gfc_symbol
* sym
)
345 char name
[GFC_MAX_MANGLED_SYMBOL_LEN
+ 1];
347 /* Prevent the mangling of identifiers that have an assigned
348 binding label (mainly those that are bind(c)). */
349 if (sym
->attr
.is_bind_c
== 1 && sym
->binding_label
)
350 return get_identifier (sym
->binding_label
);
352 if (sym
->module
== NULL
)
353 return gfc_sym_identifier (sym
);
356 snprintf (name
, sizeof name
, "__%s_MOD_%s", sym
->module
, sym
->name
);
357 return get_identifier (name
);
362 /* Construct mangled function name from symbol name. */
365 gfc_sym_mangled_function_id (gfc_symbol
* sym
)
368 char name
[GFC_MAX_MANGLED_SYMBOL_LEN
+ 1];
370 /* It may be possible to simply use the binding label if it's
371 provided, and remove the other checks. Then we could use it
372 for other things if we wished. */
373 if ((sym
->attr
.is_bind_c
== 1 || sym
->attr
.is_iso_c
== 1) &&
375 /* use the binding label rather than the mangled name */
376 return get_identifier (sym
->binding_label
);
378 if ((sym
->module
== NULL
|| sym
->attr
.proc
== PROC_EXTERNAL
379 || (sym
->module
!= NULL
&& (sym
->attr
.external
380 || sym
->attr
.if_source
== IFSRC_IFBODY
)))
381 && !sym
->attr
.module_procedure
)
383 /* Main program is mangled into MAIN__. */
384 if (sym
->attr
.is_main_program
)
385 return get_identifier ("MAIN__");
387 /* Intrinsic procedures are never mangled. */
388 if (sym
->attr
.proc
== PROC_INTRINSIC
)
389 return get_identifier (sym
->name
);
391 if (flag_underscoring
)
393 has_underscore
= strchr (sym
->name
, '_') != 0;
394 if (flag_second_underscore
&& has_underscore
)
395 snprintf (name
, sizeof name
, "%s__", sym
->name
);
397 snprintf (name
, sizeof name
, "%s_", sym
->name
);
398 return get_identifier (name
);
401 return get_identifier (sym
->name
);
405 snprintf (name
, sizeof name
, "__%s_MOD_%s", sym
->module
, sym
->name
);
406 return get_identifier (name
);
412 gfc_set_decl_assembler_name (tree decl
, tree name
)
414 tree target_mangled
= targetm
.mangle_decl_assembler_name (decl
, name
);
415 SET_DECL_ASSEMBLER_NAME (decl
, target_mangled
);
419 /* Returns true if a variable of specified size should go on the stack. */
422 gfc_can_put_var_on_stack (tree size
)
424 unsigned HOST_WIDE_INT low
;
426 if (!INTEGER_CST_P (size
))
429 if (flag_max_stack_var_size
< 0)
432 if (!tree_fits_uhwi_p (size
))
435 low
= TREE_INT_CST_LOW (size
);
436 if (low
> (unsigned HOST_WIDE_INT
) flag_max_stack_var_size
)
439 /* TODO: Set a per-function stack size limit. */
445 /* gfc_finish_cray_pointee sets DECL_VALUE_EXPR for a Cray pointee to
446 an expression involving its corresponding pointer. There are
447 2 cases; one for variable size arrays, and one for everything else,
448 because variable-sized arrays require one fewer level of
452 gfc_finish_cray_pointee (tree decl
, gfc_symbol
*sym
)
454 tree ptr_decl
= gfc_get_symbol_decl (sym
->cp_pointer
);
457 /* Parameters need to be dereferenced. */
458 if (sym
->cp_pointer
->attr
.dummy
)
459 ptr_decl
= build_fold_indirect_ref_loc (input_location
,
462 /* Check to see if we're dealing with a variable-sized array. */
463 if (sym
->attr
.dimension
464 && TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
466 /* These decls will be dereferenced later, so we don't dereference
468 value
= convert (TREE_TYPE (decl
), ptr_decl
);
472 ptr_decl
= convert (build_pointer_type (TREE_TYPE (decl
)),
474 value
= build_fold_indirect_ref_loc (input_location
,
478 SET_DECL_VALUE_EXPR (decl
, value
);
479 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
480 GFC_DECL_CRAY_POINTEE (decl
) = 1;
484 /* Finish processing of a declaration without an initial value. */
487 gfc_finish_decl (tree decl
)
489 gcc_assert (TREE_CODE (decl
) == PARM_DECL
490 || DECL_INITIAL (decl
) == NULL_TREE
);
492 if (TREE_CODE (decl
) != VAR_DECL
)
495 if (DECL_SIZE (decl
) == NULL_TREE
496 && TYPE_SIZE (TREE_TYPE (decl
)) != NULL_TREE
)
497 layout_decl (decl
, 0);
499 /* A few consistency checks. */
500 /* A static variable with an incomplete type is an error if it is
501 initialized. Also if it is not file scope. Otherwise, let it
502 through, but if it is not `extern' then it may cause an error
504 /* An automatic variable with an incomplete type is an error. */
506 /* We should know the storage size. */
507 gcc_assert (DECL_SIZE (decl
) != NULL_TREE
508 || (TREE_STATIC (decl
)
509 ? (!DECL_INITIAL (decl
) || !DECL_CONTEXT (decl
))
510 : DECL_EXTERNAL (decl
)));
512 /* The storage size should be constant. */
513 gcc_assert ((!DECL_EXTERNAL (decl
) && !TREE_STATIC (decl
))
515 || TREE_CODE (DECL_SIZE (decl
)) == INTEGER_CST
);
519 /* Handle setting of GFC_DECL_SCALAR* on DECL. */
522 gfc_finish_decl_attrs (tree decl
, symbol_attribute
*attr
)
524 if (!attr
->dimension
&& !attr
->codimension
)
526 /* Handle scalar allocatable variables. */
527 if (attr
->allocatable
)
529 gfc_allocate_lang_decl (decl
);
530 GFC_DECL_SCALAR_ALLOCATABLE (decl
) = 1;
532 /* Handle scalar pointer variables. */
535 gfc_allocate_lang_decl (decl
);
536 GFC_DECL_SCALAR_POINTER (decl
) = 1;
542 /* Apply symbol attributes to a variable, and add it to the function scope. */
545 gfc_finish_var_decl (tree decl
, gfc_symbol
* sym
)
549 /* Set DECL_VALUE_EXPR for Cray Pointees. */
550 if (sym
->attr
.cray_pointee
)
551 gfc_finish_cray_pointee (decl
, sym
);
553 /* TREE_ADDRESSABLE means the address of this variable is actually needed.
554 This is the equivalent of the TARGET variables.
555 We also need to set this if the variable is passed by reference in a
557 if (sym
->attr
.target
)
558 TREE_ADDRESSABLE (decl
) = 1;
560 /* If it wasn't used we wouldn't be getting it. */
561 TREE_USED (decl
) = 1;
563 if (sym
->attr
.flavor
== FL_PARAMETER
564 && (sym
->attr
.dimension
|| sym
->ts
.type
== BT_DERIVED
))
565 TREE_READONLY (decl
) = 1;
567 /* Chain this decl to the pending declarations. Don't do pushdecl()
568 because this would add them to the current scope rather than the
570 if (current_function_decl
!= NULL_TREE
)
572 if (sym
->ns
->proc_name
->backend_decl
== current_function_decl
573 || sym
->result
== sym
)
574 gfc_add_decl_to_function (decl
);
575 else if (sym
->ns
->proc_name
->attr
.flavor
== FL_LABEL
)
576 /* This is a BLOCK construct. */
577 add_decl_as_local (decl
);
579 gfc_add_decl_to_parent_function (decl
);
582 if (sym
->attr
.cray_pointee
)
585 if(sym
->attr
.is_bind_c
== 1 && sym
->binding_label
)
587 /* We need to put variables that are bind(c) into the common
588 segment of the object file, because this is what C would do.
589 gfortran would typically put them in either the BSS or
590 initialized data segments, and only mark them as common if
591 they were part of common blocks. However, if they are not put
592 into common space, then C cannot initialize global Fortran
593 variables that it interoperates with and the draft says that
594 either Fortran or C should be able to initialize it (but not
595 both, of course.) (J3/04-007, section 15.3). */
596 TREE_PUBLIC(decl
) = 1;
597 DECL_COMMON(decl
) = 1;
598 if (sym
->attr
.access
== ACCESS_PRIVATE
&& !sym
->attr
.public_used
)
600 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
601 DECL_VISIBILITY_SPECIFIED (decl
) = true;
605 /* If a variable is USE associated, it's always external. */
606 if (sym
->attr
.use_assoc
|| sym
->attr
.used_in_submodule
)
608 DECL_EXTERNAL (decl
) = 1;
609 TREE_PUBLIC (decl
) = 1;
611 else if (sym
->module
&& !sym
->attr
.result
&& !sym
->attr
.dummy
)
613 /* TODO: Don't set sym->module for result or dummy variables. */
614 gcc_assert (current_function_decl
== NULL_TREE
|| sym
->result
== sym
);
616 TREE_PUBLIC (decl
) = 1;
617 TREE_STATIC (decl
) = 1;
618 if (sym
->attr
.access
== ACCESS_PRIVATE
&& !sym
->attr
.public_used
)
620 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
621 DECL_VISIBILITY_SPECIFIED (decl
) = true;
625 /* Derived types are a bit peculiar because of the possibility of
626 a default initializer; this must be applied each time the variable
627 comes into scope it therefore need not be static. These variables
628 are SAVE_NONE but have an initializer. Otherwise explicitly
629 initialized variables are SAVE_IMPLICIT and explicitly saved are
631 if (!sym
->attr
.use_assoc
632 && (sym
->attr
.save
!= SAVE_NONE
|| sym
->attr
.data
633 || (sym
->value
&& sym
->ns
->proc_name
->attr
.is_main_program
)
634 || (flag_coarray
== GFC_FCOARRAY_LIB
635 && sym
->attr
.codimension
&& !sym
->attr
.allocatable
)))
636 TREE_STATIC (decl
) = 1;
638 if (sym
->attr
.volatile_
)
640 TREE_THIS_VOLATILE (decl
) = 1;
641 TREE_SIDE_EFFECTS (decl
) = 1;
642 new_type
= build_qualified_type (TREE_TYPE (decl
), TYPE_QUAL_VOLATILE
);
643 TREE_TYPE (decl
) = new_type
;
646 /* Keep variables larger than max-stack-var-size off stack. */
647 if (!sym
->ns
->proc_name
->attr
.recursive
648 && INTEGER_CST_P (DECL_SIZE_UNIT (decl
))
649 && !gfc_can_put_var_on_stack (DECL_SIZE_UNIT (decl
))
650 /* Put variable length auto array pointers always into stack. */
651 && (TREE_CODE (TREE_TYPE (decl
)) != POINTER_TYPE
652 || sym
->attr
.dimension
== 0
653 || sym
->as
->type
!= AS_EXPLICIT
655 || sym
->attr
.allocatable
)
656 && !DECL_ARTIFICIAL (decl
))
657 TREE_STATIC (decl
) = 1;
659 /* Handle threadprivate variables. */
660 if (sym
->attr
.threadprivate
661 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
662 set_decl_tls_model (decl
, decl_default_tls_model (decl
));
664 gfc_finish_decl_attrs (decl
, &sym
->attr
);
668 /* Allocate the lang-specific part of a decl. */
671 gfc_allocate_lang_decl (tree decl
)
673 if (DECL_LANG_SPECIFIC (decl
) == NULL
)
674 DECL_LANG_SPECIFIC (decl
) = ggc_cleared_alloc
<struct lang_decl
> ();
677 /* Remember a symbol to generate initialization/cleanup code at function
681 gfc_defer_symbol_init (gfc_symbol
* sym
)
687 /* Don't add a symbol twice. */
691 last
= head
= sym
->ns
->proc_name
;
694 /* Make sure that setup code for dummy variables which are used in the
695 setup of other variables is generated first. */
698 /* Find the first dummy arg seen after us, or the first non-dummy arg.
699 This is a circular list, so don't go past the head. */
701 && (!p
->attr
.dummy
|| p
->dummy_order
> sym
->dummy_order
))
707 /* Insert in between last and p. */
713 /* Used in gfc_get_symbol_decl and gfc_get_derived_type to obtain the
714 backend_decl for a module symbol, if it all ready exists. If the
715 module gsymbol does not exist, it is created. If the symbol does
716 not exist, it is added to the gsymbol namespace. Returns true if
717 an existing backend_decl is found. */
720 gfc_get_module_backend_decl (gfc_symbol
*sym
)
726 gsym
= gfc_find_gsymbol (gfc_gsym_root
, sym
->module
);
728 if (!gsym
|| (gsym
->ns
&& gsym
->type
== GSYM_MODULE
))
734 gfc_find_symbol (sym
->name
, gsym
->ns
, 0, &s
);
740 gsym
= gfc_get_gsymbol (sym
->module
);
741 gsym
->type
= GSYM_MODULE
;
742 gsym
->ns
= gfc_get_namespace (NULL
, 0);
745 st
= gfc_new_symtree (&gsym
->ns
->sym_root
, sym
->name
);
749 else if (sym
->attr
.flavor
== FL_DERIVED
)
751 if (s
&& s
->attr
.flavor
== FL_PROCEDURE
)
754 gcc_assert (s
->attr
.generic
);
755 for (intr
= s
->generic
; intr
; intr
= intr
->next
)
756 if (intr
->sym
->attr
.flavor
== FL_DERIVED
)
763 if (!s
->backend_decl
)
764 s
->backend_decl
= gfc_get_derived_type (s
);
765 gfc_copy_dt_decls_ifequal (s
, sym
, true);
768 else if (s
->backend_decl
)
770 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
771 gfc_copy_dt_decls_ifequal (s
->ts
.u
.derived
, sym
->ts
.u
.derived
,
773 else if (sym
->ts
.type
== BT_CHARACTER
)
774 sym
->ts
.u
.cl
->backend_decl
= s
->ts
.u
.cl
->backend_decl
;
775 sym
->backend_decl
= s
->backend_decl
;
783 /* Create an array index type variable with function scope. */
786 create_index_var (const char * pfx
, int nest
)
790 decl
= gfc_create_var_np (gfc_array_index_type
, pfx
);
792 gfc_add_decl_to_parent_function (decl
);
794 gfc_add_decl_to_function (decl
);
799 /* Create variables to hold all the non-constant bits of info for a
800 descriptorless array. Remember these in the lang-specific part of the
804 gfc_build_qualified_array (tree decl
, gfc_symbol
* sym
)
809 gfc_namespace
* procns
;
810 symbol_attribute
*array_attr
;
812 bool is_classarray
= IS_CLASS_ARRAY (sym
);
814 type
= TREE_TYPE (decl
);
815 array_attr
= is_classarray
? &CLASS_DATA (sym
)->attr
: &sym
->attr
;
816 as
= is_classarray
? CLASS_DATA (sym
)->as
: sym
->as
;
818 /* We just use the descriptor, if there is one. */
819 if (GFC_DESCRIPTOR_TYPE_P (type
))
822 gcc_assert (GFC_ARRAY_TYPE_P (type
));
823 procns
= gfc_find_proc_namespace (sym
->ns
);
824 nest
= (procns
->proc_name
->backend_decl
!= current_function_decl
)
825 && !sym
->attr
.contained
;
827 if (array_attr
->codimension
&& flag_coarray
== GFC_FCOARRAY_LIB
828 && as
->type
!= AS_ASSUMED_SHAPE
829 && GFC_TYPE_ARRAY_CAF_TOKEN (type
) == NULL_TREE
)
832 tree token_type
= build_qualified_type (pvoid_type_node
,
835 if (sym
->module
&& (sym
->attr
.use_assoc
836 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
))
839 = get_identifier (gfc_get_string (GFC_PREFIX ("caf_token%s"),
840 IDENTIFIER_POINTER (gfc_sym_mangled_identifier (sym
))));
841 token
= build_decl (DECL_SOURCE_LOCATION (decl
), VAR_DECL
, token_name
,
843 if (sym
->attr
.use_assoc
)
844 DECL_EXTERNAL (token
) = 1;
846 TREE_STATIC (token
) = 1;
848 TREE_PUBLIC (token
) = 1;
850 if (sym
->attr
.access
== ACCESS_PRIVATE
&& !sym
->attr
.public_used
)
852 DECL_VISIBILITY (token
) = VISIBILITY_HIDDEN
;
853 DECL_VISIBILITY_SPECIFIED (token
) = true;
858 token
= gfc_create_var_np (token_type
, "caf_token");
859 TREE_STATIC (token
) = 1;
862 GFC_TYPE_ARRAY_CAF_TOKEN (type
) = token
;
863 DECL_ARTIFICIAL (token
) = 1;
864 DECL_NONALIASED (token
) = 1;
866 if (sym
->module
&& !sym
->attr
.use_assoc
)
869 DECL_CONTEXT (token
) = sym
->ns
->proc_name
->backend_decl
;
870 gfc_module_add_decl (cur_module
, token
);
873 gfc_add_decl_to_function (token
);
876 for (dim
= 0; dim
< GFC_TYPE_ARRAY_RANK (type
); dim
++)
878 if (GFC_TYPE_ARRAY_LBOUND (type
, dim
) == NULL_TREE
)
880 GFC_TYPE_ARRAY_LBOUND (type
, dim
) = create_index_var ("lbound", nest
);
881 TREE_NO_WARNING (GFC_TYPE_ARRAY_LBOUND (type
, dim
)) = 1;
883 /* Don't try to use the unknown bound for assumed shape arrays. */
884 if (GFC_TYPE_ARRAY_UBOUND (type
, dim
) == NULL_TREE
885 && (as
->type
!= AS_ASSUMED_SIZE
886 || dim
< GFC_TYPE_ARRAY_RANK (type
) - 1))
888 GFC_TYPE_ARRAY_UBOUND (type
, dim
) = create_index_var ("ubound", nest
);
889 TREE_NO_WARNING (GFC_TYPE_ARRAY_UBOUND (type
, dim
)) = 1;
892 if (GFC_TYPE_ARRAY_STRIDE (type
, dim
) == NULL_TREE
)
894 GFC_TYPE_ARRAY_STRIDE (type
, dim
) = create_index_var ("stride", nest
);
895 TREE_NO_WARNING (GFC_TYPE_ARRAY_STRIDE (type
, dim
)) = 1;
898 for (dim
= GFC_TYPE_ARRAY_RANK (type
);
899 dim
< GFC_TYPE_ARRAY_RANK (type
) + GFC_TYPE_ARRAY_CORANK (type
); dim
++)
901 if (GFC_TYPE_ARRAY_LBOUND (type
, dim
) == NULL_TREE
)
903 GFC_TYPE_ARRAY_LBOUND (type
, dim
) = create_index_var ("lbound", nest
);
904 TREE_NO_WARNING (GFC_TYPE_ARRAY_LBOUND (type
, dim
)) = 1;
906 /* Don't try to use the unknown ubound for the last coarray dimension. */
907 if (GFC_TYPE_ARRAY_UBOUND (type
, dim
) == NULL_TREE
908 && dim
< GFC_TYPE_ARRAY_RANK (type
) + GFC_TYPE_ARRAY_CORANK (type
) - 1)
910 GFC_TYPE_ARRAY_UBOUND (type
, dim
) = create_index_var ("ubound", nest
);
911 TREE_NO_WARNING (GFC_TYPE_ARRAY_UBOUND (type
, dim
)) = 1;
914 if (GFC_TYPE_ARRAY_OFFSET (type
) == NULL_TREE
)
916 GFC_TYPE_ARRAY_OFFSET (type
) = gfc_create_var_np (gfc_array_index_type
,
918 TREE_NO_WARNING (GFC_TYPE_ARRAY_OFFSET (type
)) = 1;
921 gfc_add_decl_to_parent_function (GFC_TYPE_ARRAY_OFFSET (type
));
923 gfc_add_decl_to_function (GFC_TYPE_ARRAY_OFFSET (type
));
926 if (GFC_TYPE_ARRAY_SIZE (type
) == NULL_TREE
927 && as
->type
!= AS_ASSUMED_SIZE
)
929 GFC_TYPE_ARRAY_SIZE (type
) = create_index_var ("size", nest
);
930 TREE_NO_WARNING (GFC_TYPE_ARRAY_SIZE (type
)) = 1;
933 if (POINTER_TYPE_P (type
))
935 gcc_assert (GFC_ARRAY_TYPE_P (TREE_TYPE (type
)));
936 gcc_assert (TYPE_LANG_SPECIFIC (type
)
937 == TYPE_LANG_SPECIFIC (TREE_TYPE (type
)));
938 type
= TREE_TYPE (type
);
941 if (! COMPLETE_TYPE_P (type
) && GFC_TYPE_ARRAY_SIZE (type
))
945 size
= fold_build2_loc (input_location
, MINUS_EXPR
, gfc_array_index_type
,
946 GFC_TYPE_ARRAY_SIZE (type
), gfc_index_one_node
);
947 range
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
949 TYPE_DOMAIN (type
) = range
;
953 if (TYPE_NAME (type
) != NULL_TREE
954 && GFC_TYPE_ARRAY_UBOUND (type
, as
->rank
- 1) != NULL_TREE
955 && TREE_CODE (GFC_TYPE_ARRAY_UBOUND (type
, as
->rank
- 1)) == VAR_DECL
)
957 tree gtype
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
959 for (dim
= 0; dim
< as
->rank
- 1; dim
++)
961 gcc_assert (TREE_CODE (gtype
) == ARRAY_TYPE
);
962 gtype
= TREE_TYPE (gtype
);
964 gcc_assert (TREE_CODE (gtype
) == ARRAY_TYPE
);
965 if (TYPE_MAX_VALUE (TYPE_DOMAIN (gtype
)) == NULL
)
966 TYPE_NAME (type
) = NULL_TREE
;
969 if (TYPE_NAME (type
) == NULL_TREE
)
971 tree gtype
= TREE_TYPE (type
), rtype
, type_decl
;
973 for (dim
= as
->rank
- 1; dim
>= 0; dim
--)
976 lbound
= GFC_TYPE_ARRAY_LBOUND (type
, dim
);
977 ubound
= GFC_TYPE_ARRAY_UBOUND (type
, dim
);
978 rtype
= build_range_type (gfc_array_index_type
, lbound
, ubound
);
979 gtype
= build_array_type (gtype
, rtype
);
980 /* Ensure the bound variables aren't optimized out at -O0.
981 For -O1 and above they often will be optimized out, but
982 can be tracked by VTA. Also set DECL_NAMELESS, so that
983 the artificial lbound.N or ubound.N DECL_NAME doesn't
984 end up in debug info. */
985 if (lbound
&& TREE_CODE (lbound
) == VAR_DECL
986 && DECL_ARTIFICIAL (lbound
) && DECL_IGNORED_P (lbound
))
988 if (DECL_NAME (lbound
)
989 && strstr (IDENTIFIER_POINTER (DECL_NAME (lbound
)),
991 DECL_NAMELESS (lbound
) = 1;
992 DECL_IGNORED_P (lbound
) = 0;
994 if (ubound
&& TREE_CODE (ubound
) == VAR_DECL
995 && DECL_ARTIFICIAL (ubound
) && DECL_IGNORED_P (ubound
))
997 if (DECL_NAME (ubound
)
998 && strstr (IDENTIFIER_POINTER (DECL_NAME (ubound
)),
1000 DECL_NAMELESS (ubound
) = 1;
1001 DECL_IGNORED_P (ubound
) = 0;
1004 TYPE_NAME (type
) = type_decl
= build_decl (input_location
,
1005 TYPE_DECL
, NULL
, gtype
);
1006 DECL_ORIGINAL_TYPE (type_decl
) = gtype
;
1011 /* For some dummy arguments we don't use the actual argument directly.
1012 Instead we create a local decl and use that. This allows us to perform
1013 initialization, and construct full type information. */
1016 gfc_build_dummy_array_decl (gfc_symbol
* sym
, tree dummy
)
1021 symbol_attribute
*array_attr
;
1026 bool is_classarray
= IS_CLASS_ARRAY (sym
);
1028 /* Use the array as and attr. */
1029 as
= is_classarray
? CLASS_DATA (sym
)->as
: sym
->as
;
1030 array_attr
= is_classarray
? &CLASS_DATA (sym
)->attr
: &sym
->attr
;
1032 /* The dummy is returned for pointer, allocatable or assumed rank arrays.
1033 For class arrays the information if sym is an allocatable or pointer
1034 object needs to be checked explicitly (IS_CLASS_ARRAY can be false for
1035 too many reasons to be of use here). */
1036 if ((sym
->ts
.type
!= BT_CLASS
&& sym
->attr
.pointer
)
1037 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->attr
.class_pointer
)
1038 || array_attr
->allocatable
1039 || (as
&& as
->type
== AS_ASSUMED_RANK
))
1042 /* Add to list of variables if not a fake result variable.
1043 These symbols are set on the symbol only, not on the class component. */
1044 if (sym
->attr
.result
|| sym
->attr
.dummy
)
1045 gfc_defer_symbol_init (sym
);
1047 /* For a class array the array descriptor is in the _data component, while
1048 for a regular array the TREE_TYPE of the dummy is a pointer to the
1050 type
= TREE_TYPE (is_classarray
? gfc_class_data_get (dummy
)
1051 : TREE_TYPE (dummy
));
1052 /* type now is the array descriptor w/o any indirection. */
1053 gcc_assert (TREE_CODE (dummy
) == PARM_DECL
1054 && POINTER_TYPE_P (TREE_TYPE (dummy
)));
1056 /* Do we know the element size? */
1057 known_size
= sym
->ts
.type
!= BT_CHARACTER
1058 || INTEGER_CST_P (sym
->ts
.u
.cl
->backend_decl
);
1060 if (known_size
&& !GFC_DESCRIPTOR_TYPE_P (type
))
1062 /* For descriptorless arrays with known element size the actual
1063 argument is sufficient. */
1064 gfc_build_qualified_array (dummy
, sym
);
1068 if (GFC_DESCRIPTOR_TYPE_P (type
))
1070 /* Create a descriptorless array pointer. */
1073 /* Even when -frepack-arrays is used, symbols with TARGET attribute
1074 are not repacked. */
1075 if (!flag_repack_arrays
|| sym
->attr
.target
)
1077 if (as
->type
== AS_ASSUMED_SIZE
)
1078 packed
= PACKED_FULL
;
1082 if (as
->type
== AS_EXPLICIT
)
1084 packed
= PACKED_FULL
;
1085 for (n
= 0; n
< as
->rank
; n
++)
1089 && as
->upper
[n
]->expr_type
== EXPR_CONSTANT
1090 && as
->lower
[n
]->expr_type
== EXPR_CONSTANT
))
1092 packed
= PACKED_PARTIAL
;
1098 packed
= PACKED_PARTIAL
;
1101 /* For classarrays the element type is required, but
1102 gfc_typenode_for_spec () returns the array descriptor. */
1103 type
= is_classarray
? gfc_get_element_type (type
)
1104 : gfc_typenode_for_spec (&sym
->ts
);
1105 type
= gfc_get_nodesc_array_type (type
, as
, packed
,
1110 /* We now have an expression for the element size, so create a fully
1111 qualified type. Reset sym->backend decl or this will just return the
1113 DECL_ARTIFICIAL (sym
->backend_decl
) = 1;
1114 sym
->backend_decl
= NULL_TREE
;
1115 type
= gfc_sym_type (sym
);
1116 packed
= PACKED_FULL
;
1119 ASM_FORMAT_PRIVATE_NAME (name
, IDENTIFIER_POINTER (DECL_NAME (dummy
)), 0);
1120 decl
= build_decl (input_location
,
1121 VAR_DECL
, get_identifier (name
), type
);
1123 DECL_ARTIFICIAL (decl
) = 1;
1124 DECL_NAMELESS (decl
) = 1;
1125 TREE_PUBLIC (decl
) = 0;
1126 TREE_STATIC (decl
) = 0;
1127 DECL_EXTERNAL (decl
) = 0;
1129 /* Avoid uninitialized warnings for optional dummy arguments. */
1130 if (sym
->attr
.optional
)
1131 TREE_NO_WARNING (decl
) = 1;
1133 /* We should never get deferred shape arrays here. We used to because of
1135 gcc_assert (as
->type
!= AS_DEFERRED
);
1137 if (packed
== PACKED_PARTIAL
)
1138 GFC_DECL_PARTIAL_PACKED_ARRAY (decl
) = 1;
1139 else if (packed
== PACKED_FULL
)
1140 GFC_DECL_PACKED_ARRAY (decl
) = 1;
1142 gfc_build_qualified_array (decl
, sym
);
1144 if (DECL_LANG_SPECIFIC (dummy
))
1145 DECL_LANG_SPECIFIC (decl
) = DECL_LANG_SPECIFIC (dummy
);
1147 gfc_allocate_lang_decl (decl
);
1149 GFC_DECL_SAVED_DESCRIPTOR (decl
) = dummy
;
1151 if (sym
->ns
->proc_name
->backend_decl
== current_function_decl
1152 || sym
->attr
.contained
)
1153 gfc_add_decl_to_function (decl
);
1155 gfc_add_decl_to_parent_function (decl
);
1160 /* For symbol SYM with GFC_DECL_SAVED_DESCRIPTOR used in contained
1161 function add a VAR_DECL to the current function with DECL_VALUE_EXPR
1162 pointing to the artificial variable for debug info purposes. */
1165 gfc_nonlocal_dummy_array_decl (gfc_symbol
*sym
)
1169 if (! nonlocal_dummy_decl_pset
)
1170 nonlocal_dummy_decl_pset
= new hash_set
<tree
>;
1172 if (nonlocal_dummy_decl_pset
->add (sym
->backend_decl
))
1175 dummy
= GFC_DECL_SAVED_DESCRIPTOR (sym
->backend_decl
);
1176 decl
= build_decl (input_location
, VAR_DECL
, DECL_NAME (dummy
),
1177 TREE_TYPE (sym
->backend_decl
));
1178 DECL_ARTIFICIAL (decl
) = 0;
1179 TREE_USED (decl
) = 1;
1180 TREE_PUBLIC (decl
) = 0;
1181 TREE_STATIC (decl
) = 0;
1182 DECL_EXTERNAL (decl
) = 0;
1183 if (DECL_BY_REFERENCE (dummy
))
1184 DECL_BY_REFERENCE (decl
) = 1;
1185 DECL_LANG_SPECIFIC (decl
) = DECL_LANG_SPECIFIC (sym
->backend_decl
);
1186 SET_DECL_VALUE_EXPR (decl
, sym
->backend_decl
);
1187 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
1188 DECL_CONTEXT (decl
) = DECL_CONTEXT (sym
->backend_decl
);
1189 DECL_CHAIN (decl
) = nonlocal_dummy_decls
;
1190 nonlocal_dummy_decls
= decl
;
1193 /* Return a constant or a variable to use as a string length. Does not
1194 add the decl to the current scope. */
1197 gfc_create_string_length (gfc_symbol
* sym
)
1199 gcc_assert (sym
->ts
.u
.cl
);
1200 gfc_conv_const_charlen (sym
->ts
.u
.cl
);
1202 if (sym
->ts
.u
.cl
->backend_decl
== NULL_TREE
)
1207 /* The string length variable shall be in static memory if it is either
1208 explicitly SAVED, a module variable or with -fno-automatic. Only
1209 relevant is "len=:" - otherwise, it is either a constant length or
1210 it is an automatic variable. */
1211 bool static_length
= sym
->attr
.save
1212 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
1213 || (flag_max_stack_var_size
== 0
1214 && sym
->ts
.deferred
&& !sym
->attr
.dummy
1215 && !sym
->attr
.result
&& !sym
->attr
.function
);
1217 /* Also prefix the mangled name. We need to call GFC_PREFIX for static
1218 variables as some systems do not support the "." in the assembler name.
1219 For nonstatic variables, the "." does not appear in assembler. */
1223 name
= gfc_get_string (GFC_PREFIX ("%s_MOD_%s"), sym
->module
,
1226 name
= gfc_get_string (GFC_PREFIX ("%s"), sym
->name
);
1228 else if (sym
->module
)
1229 name
= gfc_get_string (".__%s_MOD_%s", sym
->module
, sym
->name
);
1231 name
= gfc_get_string (".%s", sym
->name
);
1233 length
= build_decl (input_location
,
1234 VAR_DECL
, get_identifier (name
),
1235 gfc_charlen_type_node
);
1236 DECL_ARTIFICIAL (length
) = 1;
1237 TREE_USED (length
) = 1;
1238 if (sym
->ns
->proc_name
->tlink
!= NULL
)
1239 gfc_defer_symbol_init (sym
);
1241 sym
->ts
.u
.cl
->backend_decl
= length
;
1244 TREE_STATIC (length
) = 1;
1246 if (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
1247 && (sym
->attr
.access
!= ACCESS_PRIVATE
|| sym
->attr
.public_used
))
1248 TREE_PUBLIC (length
) = 1;
1251 gcc_assert (sym
->ts
.u
.cl
->backend_decl
!= NULL_TREE
);
1252 return sym
->ts
.u
.cl
->backend_decl
;
1255 /* If a variable is assigned a label, we add another two auxiliary
1259 gfc_add_assign_aux_vars (gfc_symbol
* sym
)
1265 gcc_assert (sym
->backend_decl
);
1267 decl
= sym
->backend_decl
;
1268 gfc_allocate_lang_decl (decl
);
1269 GFC_DECL_ASSIGN (decl
) = 1;
1270 length
= build_decl (input_location
,
1271 VAR_DECL
, create_tmp_var_name (sym
->name
),
1272 gfc_charlen_type_node
);
1273 addr
= build_decl (input_location
,
1274 VAR_DECL
, create_tmp_var_name (sym
->name
),
1276 gfc_finish_var_decl (length
, sym
);
1277 gfc_finish_var_decl (addr
, sym
);
1278 /* STRING_LENGTH is also used as flag. Less than -1 means that
1279 ASSIGN_ADDR can not be used. Equal -1 means that ASSIGN_ADDR is the
1280 target label's address. Otherwise, value is the length of a format string
1281 and ASSIGN_ADDR is its address. */
1282 if (TREE_STATIC (length
))
1283 DECL_INITIAL (length
) = build_int_cst (gfc_charlen_type_node
, -2);
1285 gfc_defer_symbol_init (sym
);
1287 GFC_DECL_STRING_LEN (decl
) = length
;
1288 GFC_DECL_ASSIGN_ADDR (decl
) = addr
;
1293 add_attributes_to_decl (symbol_attribute sym_attr
, tree list
)
1298 for (id
= 0; id
< EXT_ATTR_NUM
; id
++)
1299 if (sym_attr
.ext_attr
& (1 << id
))
1301 attr
= build_tree_list (
1302 get_identifier (ext_attr_list
[id
].middle_end_name
),
1304 list
= chainon (list
, attr
);
1307 if (sym_attr
.omp_declare_target
)
1308 list
= tree_cons (get_identifier ("omp declare target"),
1311 if (sym_attr
.oacc_function
)
1313 tree dims
= NULL_TREE
;
1315 int level
= sym_attr
.oacc_function
- 1;
1317 for (ix
= GOMP_DIM_MAX
; ix
--;)
1318 dims
= tree_cons (build_int_cst (boolean_type_node
, ix
>= level
),
1319 integer_zero_node
, dims
);
1321 list
= tree_cons (get_identifier ("oacc function"),
1329 static void build_function_decl (gfc_symbol
* sym
, bool global
);
1332 /* Return the decl for a gfc_symbol, create it if it doesn't already
1336 gfc_get_symbol_decl (gfc_symbol
* sym
)
1339 tree length
= NULL_TREE
;
1342 bool intrinsic_array_parameter
= false;
1345 gcc_assert (sym
->attr
.referenced
1346 || sym
->attr
.flavor
== FL_PROCEDURE
1347 || sym
->attr
.use_assoc
1348 || sym
->attr
.used_in_submodule
1349 || sym
->ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
1350 || (sym
->module
&& sym
->attr
.if_source
!= IFSRC_DECL
1351 && sym
->backend_decl
));
1353 if (sym
->ns
&& sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.function
)
1354 byref
= gfc_return_by_reference (sym
->ns
->proc_name
);
1358 /* Make sure that the vtab for the declared type is completed. */
1359 if (sym
->ts
.type
== BT_CLASS
)
1361 gfc_component
*c
= CLASS_DATA (sym
);
1362 if (!c
->ts
.u
.derived
->backend_decl
)
1364 gfc_find_derived_vtab (c
->ts
.u
.derived
);
1365 gfc_get_derived_type (sym
->ts
.u
.derived
);
1369 /* All deferred character length procedures need to retain the backend
1370 decl, which is a pointer to the character length in the caller's
1371 namespace and to declare a local character length. */
1372 if (!byref
&& sym
->attr
.function
1373 && sym
->ts
.type
== BT_CHARACTER
1375 && sym
->ts
.u
.cl
->passed_length
== NULL
1376 && sym
->ts
.u
.cl
->backend_decl
1377 && TREE_CODE (sym
->ts
.u
.cl
->backend_decl
) == PARM_DECL
)
1379 sym
->ts
.u
.cl
->passed_length
= sym
->ts
.u
.cl
->backend_decl
;
1380 sym
->ts
.u
.cl
->backend_decl
= NULL_TREE
;
1381 length
= gfc_create_string_length (sym
);
1384 fun_or_res
= byref
&& (sym
->attr
.result
1385 || (sym
->attr
.function
&& sym
->ts
.deferred
));
1386 if ((sym
->attr
.dummy
&& ! sym
->attr
.function
) || fun_or_res
)
1388 /* Return via extra parameter. */
1389 if (sym
->attr
.result
&& byref
1390 && !sym
->backend_decl
)
1393 DECL_ARGUMENTS (sym
->ns
->proc_name
->backend_decl
);
1394 /* For entry master function skip over the __entry
1396 if (sym
->ns
->proc_name
->attr
.entry_master
)
1397 sym
->backend_decl
= DECL_CHAIN (sym
->backend_decl
);
1400 /* Dummy variables should already have been created. */
1401 gcc_assert (sym
->backend_decl
);
1403 /* Create a character length variable. */
1404 if (sym
->ts
.type
== BT_CHARACTER
)
1406 /* For a deferred dummy, make a new string length variable. */
1407 if (sym
->ts
.deferred
1409 (sym
->ts
.u
.cl
->passed_length
== sym
->ts
.u
.cl
->backend_decl
))
1410 sym
->ts
.u
.cl
->backend_decl
= NULL_TREE
;
1412 if (sym
->ts
.deferred
&& byref
)
1414 /* The string length of a deferred char array is stored in the
1415 parameter at sym->ts.u.cl->backend_decl as a reference and
1416 marked as a result. Exempt this variable from generating a
1417 temporary for it. */
1418 if (sym
->attr
.result
)
1420 /* We need to insert a indirect ref for param decls. */
1421 if (sym
->ts
.u
.cl
->backend_decl
1422 && TREE_CODE (sym
->ts
.u
.cl
->backend_decl
) == PARM_DECL
)
1423 sym
->ts
.u
.cl
->backend_decl
=
1424 build_fold_indirect_ref (sym
->ts
.u
.cl
->backend_decl
);
1426 /* For all other parameters make sure, that they are copied so
1427 that the value and any modifications are local to the routine
1428 by generating a temporary variable. */
1429 else if (sym
->attr
.function
1430 && sym
->ts
.u
.cl
->passed_length
== NULL
1431 && sym
->ts
.u
.cl
->backend_decl
)
1433 sym
->ts
.u
.cl
->passed_length
= sym
->ts
.u
.cl
->backend_decl
;
1434 sym
->ts
.u
.cl
->backend_decl
= NULL_TREE
;
1438 if (sym
->ts
.u
.cl
->backend_decl
== NULL_TREE
)
1439 length
= gfc_create_string_length (sym
);
1441 length
= sym
->ts
.u
.cl
->backend_decl
;
1442 if (TREE_CODE (length
) == VAR_DECL
1443 && DECL_FILE_SCOPE_P (length
))
1445 /* Add the string length to the same context as the symbol. */
1446 if (DECL_CONTEXT (sym
->backend_decl
) == current_function_decl
)
1447 gfc_add_decl_to_function (length
);
1449 gfc_add_decl_to_parent_function (length
);
1451 gcc_assert (DECL_CONTEXT (sym
->backend_decl
) ==
1452 DECL_CONTEXT (length
));
1454 gfc_defer_symbol_init (sym
);
1458 /* Use a copy of the descriptor for dummy arrays. */
1459 if ((sym
->attr
.dimension
|| sym
->attr
.codimension
)
1460 && !TREE_USED (sym
->backend_decl
))
1462 decl
= gfc_build_dummy_array_decl (sym
, sym
->backend_decl
);
1463 /* Prevent the dummy from being detected as unused if it is copied. */
1464 if (sym
->backend_decl
!= NULL
&& decl
!= sym
->backend_decl
)
1465 DECL_ARTIFICIAL (sym
->backend_decl
) = 1;
1466 sym
->backend_decl
= decl
;
1469 /* Returning the descriptor for dummy class arrays is hazardous, because
1470 some caller is expecting an expression to apply the component refs to.
1471 Therefore the descriptor is only created and stored in
1472 sym->backend_decl's GFC_DECL_SAVED_DESCRIPTOR. The caller is then
1473 responsible to extract it from there, when the descriptor is
1475 if (IS_CLASS_ARRAY (sym
)
1476 && (!DECL_LANG_SPECIFIC (sym
->backend_decl
)
1477 || !GFC_DECL_SAVED_DESCRIPTOR (sym
->backend_decl
)))
1479 decl
= gfc_build_dummy_array_decl (sym
, sym
->backend_decl
);
1480 /* Prevent the dummy from being detected as unused if it is copied. */
1481 if (sym
->backend_decl
!= NULL
&& decl
!= sym
->backend_decl
)
1482 DECL_ARTIFICIAL (sym
->backend_decl
) = 1;
1483 sym
->backend_decl
= decl
;
1486 TREE_USED (sym
->backend_decl
) = 1;
1487 if (sym
->attr
.assign
&& GFC_DECL_ASSIGN (sym
->backend_decl
) == 0)
1489 gfc_add_assign_aux_vars (sym
);
1492 if ((sym
->attr
.dimension
|| IS_CLASS_ARRAY (sym
))
1493 && DECL_LANG_SPECIFIC (sym
->backend_decl
)
1494 && GFC_DECL_SAVED_DESCRIPTOR (sym
->backend_decl
)
1495 && DECL_CONTEXT (sym
->backend_decl
) != current_function_decl
)
1496 gfc_nonlocal_dummy_array_decl (sym
);
1498 if (sym
->ts
.type
== BT_CLASS
&& sym
->backend_decl
)
1499 GFC_DECL_CLASS(sym
->backend_decl
) = 1;
1501 return sym
->backend_decl
;
1504 if (sym
->backend_decl
)
1505 return sym
->backend_decl
;
1507 /* Special case for array-valued named constants from intrinsic
1508 procedures; those are inlined. */
1509 if (sym
->attr
.use_assoc
&& sym
->attr
.flavor
== FL_PARAMETER
1510 && (sym
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
1511 || sym
->from_intmod
== INTMOD_ISO_C_BINDING
))
1512 intrinsic_array_parameter
= true;
1514 /* If use associated compilation, use the module
1516 if ((sym
->attr
.flavor
== FL_VARIABLE
1517 || sym
->attr
.flavor
== FL_PARAMETER
)
1518 && (sym
->attr
.use_assoc
|| sym
->attr
.used_in_submodule
)
1519 && !intrinsic_array_parameter
1521 && gfc_get_module_backend_decl (sym
))
1523 if (sym
->ts
.type
== BT_CLASS
&& sym
->backend_decl
)
1524 GFC_DECL_CLASS(sym
->backend_decl
) = 1;
1525 return sym
->backend_decl
;
1528 if (sym
->attr
.flavor
== FL_PROCEDURE
)
1530 /* Catch functions. Only used for actual parameters,
1531 procedure pointers and procptr initialization targets. */
1532 if (sym
->attr
.use_assoc
|| sym
->attr
.intrinsic
1533 || sym
->attr
.if_source
!= IFSRC_DECL
)
1535 decl
= gfc_get_extern_function_decl (sym
);
1536 gfc_set_decl_location (decl
, &sym
->declared_at
);
1540 if (!sym
->backend_decl
)
1541 build_function_decl (sym
, false);
1542 decl
= sym
->backend_decl
;
1547 if (sym
->attr
.intrinsic
)
1548 gfc_internal_error ("intrinsic variable which isn't a procedure");
1550 /* Create string length decl first so that they can be used in the
1551 type declaration. For associate names, the target character
1552 length is used. Set 'length' to a constant so that if the
1553 string lenght is a variable, it is not finished a second time. */
1554 if (sym
->ts
.type
== BT_CHARACTER
)
1556 if (sym
->attr
.associate_var
1557 && sym
->ts
.u
.cl
->backend_decl
1558 && TREE_CODE (sym
->ts
.u
.cl
->backend_decl
) == VAR_DECL
)
1559 length
= gfc_index_zero_node
;
1561 length
= gfc_create_string_length (sym
);
1564 /* Create the decl for the variable. */
1565 decl
= build_decl (sym
->declared_at
.lb
->location
,
1566 VAR_DECL
, gfc_sym_identifier (sym
), gfc_sym_type (sym
));
1568 /* Add attributes to variables. Functions are handled elsewhere. */
1569 attributes
= add_attributes_to_decl (sym
->attr
, NULL_TREE
);
1570 decl_attributes (&decl
, attributes
, 0);
1572 /* Symbols from modules should have their assembler names mangled.
1573 This is done here rather than in gfc_finish_var_decl because it
1574 is different for string length variables. */
1577 gfc_set_decl_assembler_name (decl
, gfc_sym_mangled_identifier (sym
));
1578 if (sym
->attr
.use_assoc
&& !intrinsic_array_parameter
)
1579 DECL_IGNORED_P (decl
) = 1;
1582 if (sym
->attr
.select_type_temporary
)
1584 DECL_ARTIFICIAL (decl
) = 1;
1585 DECL_IGNORED_P (decl
) = 1;
1588 if (sym
->attr
.dimension
|| sym
->attr
.codimension
)
1590 /* Create variables to hold the non-constant bits of array info. */
1591 gfc_build_qualified_array (decl
, sym
);
1593 if (sym
->attr
.contiguous
1594 || ((sym
->attr
.allocatable
|| !sym
->attr
.dummy
) && !sym
->attr
.pointer
))
1595 GFC_DECL_PACKED_ARRAY (decl
) = 1;
1598 /* Remember this variable for allocation/cleanup. */
1599 if (sym
->attr
.dimension
|| sym
->attr
.allocatable
|| sym
->attr
.codimension
1600 || (sym
->ts
.type
== BT_CLASS
&&
1601 (CLASS_DATA (sym
)->attr
.dimension
1602 || CLASS_DATA (sym
)->attr
.allocatable
))
1603 || (sym
->ts
.type
== BT_DERIVED
1604 && (sym
->ts
.u
.derived
->attr
.alloc_comp
1605 || (!sym
->attr
.pointer
&& !sym
->attr
.artificial
&& !sym
->attr
.save
1606 && !sym
->ns
->proc_name
->attr
.is_main_program
1607 && gfc_is_finalizable (sym
->ts
.u
.derived
, NULL
))))
1608 /* This applies a derived type default initializer. */
1609 || (sym
->ts
.type
== BT_DERIVED
1610 && sym
->attr
.save
== SAVE_NONE
1612 && !sym
->attr
.allocatable
1613 && (sym
->value
&& !sym
->ns
->proc_name
->attr
.is_main_program
)
1614 && !(sym
->attr
.use_assoc
&& !intrinsic_array_parameter
)))
1615 gfc_defer_symbol_init (sym
);
1617 gfc_finish_var_decl (decl
, sym
);
1619 if (sym
->ts
.type
== BT_CHARACTER
)
1621 /* Character variables need special handling. */
1622 gfc_allocate_lang_decl (decl
);
1624 /* Associate names can use the hidden string length variable
1625 of their associated target. */
1626 if (TREE_CODE (length
) != INTEGER_CST
)
1628 gfc_finish_var_decl (length
, sym
);
1629 gcc_assert (!sym
->value
);
1632 else if (sym
->attr
.subref_array_pointer
)
1634 /* We need the span for these beasts. */
1635 gfc_allocate_lang_decl (decl
);
1638 if (sym
->attr
.subref_array_pointer
)
1641 GFC_DECL_SUBREF_ARRAY_P (decl
) = 1;
1642 span
= build_decl (input_location
,
1643 VAR_DECL
, create_tmp_var_name ("span"),
1644 gfc_array_index_type
);
1645 gfc_finish_var_decl (span
, sym
);
1646 TREE_STATIC (span
) = TREE_STATIC (decl
);
1647 DECL_ARTIFICIAL (span
) = 1;
1649 GFC_DECL_SPAN (decl
) = span
;
1650 GFC_TYPE_ARRAY_SPAN (TREE_TYPE (decl
)) = span
;
1653 if (sym
->ts
.type
== BT_CLASS
)
1654 GFC_DECL_CLASS(decl
) = 1;
1656 sym
->backend_decl
= decl
;
1658 if (sym
->attr
.assign
)
1659 gfc_add_assign_aux_vars (sym
);
1661 if (intrinsic_array_parameter
)
1663 TREE_STATIC (decl
) = 1;
1664 DECL_EXTERNAL (decl
) = 0;
1667 if (TREE_STATIC (decl
)
1668 && !(sym
->attr
.use_assoc
&& !intrinsic_array_parameter
)
1669 && (sym
->attr
.save
|| sym
->ns
->proc_name
->attr
.is_main_program
1670 || flag_max_stack_var_size
== 0
1671 || sym
->attr
.data
|| sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
1672 && (flag_coarray
!= GFC_FCOARRAY_LIB
1673 || !sym
->attr
.codimension
|| sym
->attr
.allocatable
))
1675 /* Add static initializer. For procedures, it is only needed if
1676 SAVE is specified otherwise they need to be reinitialized
1677 every time the procedure is entered. The TREE_STATIC is
1678 in this case due to -fmax-stack-var-size=. */
1680 DECL_INITIAL (decl
) = gfc_conv_initializer (sym
->value
, &sym
->ts
,
1681 TREE_TYPE (decl
), sym
->attr
.dimension
1682 || (sym
->attr
.codimension
1683 && sym
->attr
.allocatable
),
1684 sym
->attr
.pointer
|| sym
->attr
.allocatable
1685 || sym
->ts
.type
== BT_CLASS
,
1686 sym
->attr
.proc_pointer
);
1689 if (!TREE_STATIC (decl
)
1690 && POINTER_TYPE_P (TREE_TYPE (decl
))
1691 && !sym
->attr
.pointer
1692 && !sym
->attr
.allocatable
1693 && !sym
->attr
.proc_pointer
1694 && !sym
->attr
.select_type_temporary
)
1695 DECL_BY_REFERENCE (decl
) = 1;
1697 if (sym
->attr
.associate_var
)
1698 GFC_DECL_ASSOCIATE_VAR_P (decl
) = 1;
1701 || (sym
->name
[0] == '_' && strncmp ("__def_init", sym
->name
, 10) == 0))
1702 TREE_READONLY (decl
) = 1;
1708 /* Substitute a temporary variable in place of the real one. */
1711 gfc_shadow_sym (gfc_symbol
* sym
, tree decl
, gfc_saved_var
* save
)
1713 save
->attr
= sym
->attr
;
1714 save
->decl
= sym
->backend_decl
;
1716 gfc_clear_attr (&sym
->attr
);
1717 sym
->attr
.referenced
= 1;
1718 sym
->attr
.flavor
= FL_VARIABLE
;
1720 sym
->backend_decl
= decl
;
1724 /* Restore the original variable. */
1727 gfc_restore_sym (gfc_symbol
* sym
, gfc_saved_var
* save
)
1729 sym
->attr
= save
->attr
;
1730 sym
->backend_decl
= save
->decl
;
1734 /* Declare a procedure pointer. */
1737 get_proc_pointer_decl (gfc_symbol
*sym
)
1742 decl
= sym
->backend_decl
;
1746 decl
= build_decl (input_location
,
1747 VAR_DECL
, get_identifier (sym
->name
),
1748 build_pointer_type (gfc_get_function_type (sym
)));
1752 /* Apply name mangling. */
1753 gfc_set_decl_assembler_name (decl
, gfc_sym_mangled_identifier (sym
));
1754 if (sym
->attr
.use_assoc
)
1755 DECL_IGNORED_P (decl
) = 1;
1758 if ((sym
->ns
->proc_name
1759 && sym
->ns
->proc_name
->backend_decl
== current_function_decl
)
1760 || sym
->attr
.contained
)
1761 gfc_add_decl_to_function (decl
);
1762 else if (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
1763 gfc_add_decl_to_parent_function (decl
);
1765 sym
->backend_decl
= decl
;
1767 /* If a variable is USE associated, it's always external. */
1768 if (sym
->attr
.use_assoc
)
1770 DECL_EXTERNAL (decl
) = 1;
1771 TREE_PUBLIC (decl
) = 1;
1773 else if (sym
->module
&& sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
1775 /* This is the declaration of a module variable. */
1776 TREE_PUBLIC (decl
) = 1;
1777 if (sym
->attr
.access
== ACCESS_PRIVATE
&& !sym
->attr
.public_used
)
1779 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
1780 DECL_VISIBILITY_SPECIFIED (decl
) = true;
1782 TREE_STATIC (decl
) = 1;
1785 if (!sym
->attr
.use_assoc
1786 && (sym
->attr
.save
!= SAVE_NONE
|| sym
->attr
.data
1787 || (sym
->value
&& sym
->ns
->proc_name
->attr
.is_main_program
)))
1788 TREE_STATIC (decl
) = 1;
1790 if (TREE_STATIC (decl
) && sym
->value
)
1792 /* Add static initializer. */
1793 DECL_INITIAL (decl
) = gfc_conv_initializer (sym
->value
, &sym
->ts
,
1795 sym
->attr
.dimension
,
1799 /* Handle threadprivate procedure pointers. */
1800 if (sym
->attr
.threadprivate
1801 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
1802 set_decl_tls_model (decl
, decl_default_tls_model (decl
));
1804 attributes
= add_attributes_to_decl (sym
->attr
, NULL_TREE
);
1805 decl_attributes (&decl
, attributes
, 0);
1811 /* Get a basic decl for an external function. */
1814 gfc_get_extern_function_decl (gfc_symbol
* sym
)
1820 gfc_intrinsic_sym
*isym
;
1822 char s
[GFC_MAX_SYMBOL_LEN
+ 23]; /* "_gfortran_f2c_specific" and '\0'. */
1827 if (sym
->backend_decl
)
1828 return sym
->backend_decl
;
1830 /* We should never be creating external decls for alternate entry points.
1831 The procedure may be an alternate entry point, but we don't want/need
1833 gcc_assert (!(sym
->attr
.entry
|| sym
->attr
.entry_master
));
1835 if (sym
->attr
.proc_pointer
)
1836 return get_proc_pointer_decl (sym
);
1838 /* See if this is an external procedure from the same file. If so,
1839 return the backend_decl. */
1840 gsym
= gfc_find_gsymbol (gfc_gsym_root
, sym
->binding_label
1841 ? sym
->binding_label
: sym
->name
);
1843 if (gsym
&& !gsym
->defined
)
1846 /* This can happen because of C binding. */
1847 if (gsym
&& gsym
->ns
&& gsym
->ns
->proc_name
1848 && gsym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
1851 if ((!sym
->attr
.use_assoc
|| sym
->attr
.if_source
!= IFSRC_DECL
)
1852 && !sym
->backend_decl
1854 && ((gsym
->type
== GSYM_SUBROUTINE
) || (gsym
->type
== GSYM_FUNCTION
))
1855 && (gsym
->ns
->proc_name
->backend_decl
|| !sym
->attr
.intrinsic
))
1857 if (!gsym
->ns
->proc_name
->backend_decl
)
1859 /* By construction, the external function cannot be
1860 a contained procedure. */
1863 gfc_save_backend_locus (&old_loc
);
1866 gfc_create_function_decl (gsym
->ns
, true);
1869 gfc_restore_backend_locus (&old_loc
);
1872 /* If the namespace has entries, the proc_name is the
1873 entry master. Find the entry and use its backend_decl.
1874 otherwise, use the proc_name backend_decl. */
1875 if (gsym
->ns
->entries
)
1877 gfc_entry_list
*entry
= gsym
->ns
->entries
;
1879 for (; entry
; entry
= entry
->next
)
1881 if (strcmp (gsym
->name
, entry
->sym
->name
) == 0)
1883 sym
->backend_decl
= entry
->sym
->backend_decl
;
1889 sym
->backend_decl
= gsym
->ns
->proc_name
->backend_decl
;
1891 if (sym
->backend_decl
)
1893 /* Avoid problems of double deallocation of the backend declaration
1894 later in gfc_trans_use_stmts; cf. PR 45087. */
1895 if (sym
->attr
.if_source
!= IFSRC_DECL
&& sym
->attr
.use_assoc
)
1896 sym
->attr
.use_assoc
= 0;
1898 return sym
->backend_decl
;
1902 /* See if this is a module procedure from the same file. If so,
1903 return the backend_decl. */
1905 gsym
= gfc_find_gsymbol (gfc_gsym_root
, sym
->module
);
1908 if (gsym
&& gsym
->ns
1909 && (gsym
->type
== GSYM_MODULE
1910 || (gsym
->ns
->proc_name
&& gsym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)))
1915 if (gsym
->type
== GSYM_MODULE
)
1916 gfc_find_symbol (sym
->name
, gsym
->ns
, 0, &s
);
1918 gfc_find_symbol (gsym
->sym_name
, gsym
->ns
, 0, &s
);
1920 if (s
&& s
->backend_decl
)
1922 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
1923 gfc_copy_dt_decls_ifequal (s
->ts
.u
.derived
, sym
->ts
.u
.derived
,
1925 else if (sym
->ts
.type
== BT_CHARACTER
)
1926 sym
->ts
.u
.cl
->backend_decl
= s
->ts
.u
.cl
->backend_decl
;
1927 sym
->backend_decl
= s
->backend_decl
;
1928 return sym
->backend_decl
;
1932 if (sym
->attr
.intrinsic
)
1934 /* Call the resolution function to get the actual name. This is
1935 a nasty hack which relies on the resolution functions only looking
1936 at the first argument. We pass NULL for the second argument
1937 otherwise things like AINT get confused. */
1938 isym
= gfc_find_function (sym
->name
);
1939 gcc_assert (isym
->resolve
.f0
!= NULL
);
1941 memset (&e
, 0, sizeof (e
));
1942 e
.expr_type
= EXPR_FUNCTION
;
1944 memset (&argexpr
, 0, sizeof (argexpr
));
1945 gcc_assert (isym
->formal
);
1946 argexpr
.ts
= isym
->formal
->ts
;
1948 if (isym
->formal
->next
== NULL
)
1949 isym
->resolve
.f1 (&e
, &argexpr
);
1952 if (isym
->formal
->next
->next
== NULL
)
1953 isym
->resolve
.f2 (&e
, &argexpr
, NULL
);
1956 if (isym
->formal
->next
->next
->next
== NULL
)
1957 isym
->resolve
.f3 (&e
, &argexpr
, NULL
, NULL
);
1960 /* All specific intrinsics take less than 5 arguments. */
1961 gcc_assert (isym
->formal
->next
->next
->next
->next
== NULL
);
1962 isym
->resolve
.f4 (&e
, &argexpr
, NULL
, NULL
, NULL
);
1968 && ((e
.ts
.type
== BT_REAL
&& e
.ts
.kind
== gfc_default_real_kind
)
1969 || e
.ts
.type
== BT_COMPLEX
))
1971 /* Specific which needs a different implementation if f2c
1972 calling conventions are used. */
1973 sprintf (s
, "_gfortran_f2c_specific%s", e
.value
.function
.name
);
1976 sprintf (s
, "_gfortran_specific%s", e
.value
.function
.name
);
1978 name
= get_identifier (s
);
1979 mangled_name
= name
;
1983 name
= gfc_sym_identifier (sym
);
1984 mangled_name
= gfc_sym_mangled_function_id (sym
);
1987 type
= gfc_get_function_type (sym
);
1988 fndecl
= build_decl (input_location
,
1989 FUNCTION_DECL
, name
, type
);
1991 /* Initialize DECL_EXTERNAL and TREE_PUBLIC before calling decl_attributes;
1992 TREE_PUBLIC specifies whether a function is globally addressable (i.e.
1993 the opposite of declaring a function as static in C). */
1994 DECL_EXTERNAL (fndecl
) = 1;
1995 TREE_PUBLIC (fndecl
) = 1;
1997 attributes
= add_attributes_to_decl (sym
->attr
, NULL_TREE
);
1998 decl_attributes (&fndecl
, attributes
, 0);
2000 gfc_set_decl_assembler_name (fndecl
, mangled_name
);
2002 /* Set the context of this decl. */
2003 if (0 && sym
->ns
&& sym
->ns
->proc_name
)
2005 /* TODO: Add external decls to the appropriate scope. */
2006 DECL_CONTEXT (fndecl
) = sym
->ns
->proc_name
->backend_decl
;
2010 /* Global declaration, e.g. intrinsic subroutine. */
2011 DECL_CONTEXT (fndecl
) = NULL_TREE
;
2014 /* Set attributes for PURE functions. A call to PURE function in the
2015 Fortran 95 sense is both pure and without side effects in the C
2017 if (sym
->attr
.pure
|| sym
->attr
.implicit_pure
)
2019 if (sym
->attr
.function
&& !gfc_return_by_reference (sym
))
2020 DECL_PURE_P (fndecl
) = 1;
2021 /* TODO: check if pure SUBROUTINEs don't have INTENT(OUT)
2022 parameters and don't use alternate returns (is this
2023 allowed?). In that case, calls to them are meaningless, and
2024 can be optimized away. See also in build_function_decl(). */
2025 TREE_SIDE_EFFECTS (fndecl
) = 0;
2028 /* Mark non-returning functions. */
2029 if (sym
->attr
.noreturn
)
2030 TREE_THIS_VOLATILE(fndecl
) = 1;
2032 sym
->backend_decl
= fndecl
;
2034 if (DECL_CONTEXT (fndecl
) == NULL_TREE
)
2035 pushdecl_top_level (fndecl
);
2038 && sym
->formal_ns
->proc_name
== sym
2039 && sym
->formal_ns
->omp_declare_simd
)
2040 gfc_trans_omp_declare_simd (sym
->formal_ns
);
2046 /* Create a declaration for a procedure. For external functions (in the C
2047 sense) use gfc_get_extern_function_decl. HAS_ENTRIES is true if this is
2048 a master function with alternate entry points. */
2051 build_function_decl (gfc_symbol
* sym
, bool global
)
2053 tree fndecl
, type
, attributes
;
2054 symbol_attribute attr
;
2056 gfc_formal_arglist
*f
;
2058 gcc_assert (!sym
->attr
.external
);
2060 if (sym
->backend_decl
)
2063 /* Set the line and filename. sym->declared_at seems to point to the
2064 last statement for subroutines, but it'll do for now. */
2065 gfc_set_backend_locus (&sym
->declared_at
);
2067 /* Allow only one nesting level. Allow public declarations. */
2068 gcc_assert (current_function_decl
== NULL_TREE
2069 || DECL_FILE_SCOPE_P (current_function_decl
)
2070 || (TREE_CODE (DECL_CONTEXT (current_function_decl
))
2071 == NAMESPACE_DECL
));
2073 type
= gfc_get_function_type (sym
);
2074 fndecl
= build_decl (input_location
,
2075 FUNCTION_DECL
, gfc_sym_identifier (sym
), type
);
2079 /* Initialize DECL_EXTERNAL and TREE_PUBLIC before calling decl_attributes;
2080 TREE_PUBLIC specifies whether a function is globally addressable (i.e.
2081 the opposite of declaring a function as static in C). */
2082 DECL_EXTERNAL (fndecl
) = 0;
2084 if (sym
->attr
.access
== ACCESS_UNKNOWN
&& sym
->module
2085 && (sym
->ns
->default_access
== ACCESS_PRIVATE
2086 || (sym
->ns
->default_access
== ACCESS_UNKNOWN
2087 && flag_module_private
)))
2088 sym
->attr
.access
= ACCESS_PRIVATE
;
2090 if (!current_function_decl
2091 && !sym
->attr
.entry_master
&& !sym
->attr
.is_main_program
2092 && (sym
->attr
.access
!= ACCESS_PRIVATE
|| sym
->binding_label
2093 || sym
->attr
.public_used
))
2094 TREE_PUBLIC (fndecl
) = 1;
2096 if (sym
->attr
.referenced
|| sym
->attr
.entry_master
)
2097 TREE_USED (fndecl
) = 1;
2099 attributes
= add_attributes_to_decl (attr
, NULL_TREE
);
2100 decl_attributes (&fndecl
, attributes
, 0);
2102 /* Figure out the return type of the declared function, and build a
2103 RESULT_DECL for it. If this is a subroutine with alternate
2104 returns, build a RESULT_DECL for it. */
2105 result_decl
= NULL_TREE
;
2106 /* TODO: Shouldn't this just be TREE_TYPE (TREE_TYPE (fndecl)). */
2109 if (gfc_return_by_reference (sym
))
2110 type
= void_type_node
;
2113 if (sym
->result
!= sym
)
2114 result_decl
= gfc_sym_identifier (sym
->result
);
2116 type
= TREE_TYPE (TREE_TYPE (fndecl
));
2121 /* Look for alternate return placeholders. */
2122 int has_alternate_returns
= 0;
2123 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
2127 has_alternate_returns
= 1;
2132 if (has_alternate_returns
)
2133 type
= integer_type_node
;
2135 type
= void_type_node
;
2138 result_decl
= build_decl (input_location
,
2139 RESULT_DECL
, result_decl
, type
);
2140 DECL_ARTIFICIAL (result_decl
) = 1;
2141 DECL_IGNORED_P (result_decl
) = 1;
2142 DECL_CONTEXT (result_decl
) = fndecl
;
2143 DECL_RESULT (fndecl
) = result_decl
;
2145 /* Don't call layout_decl for a RESULT_DECL.
2146 layout_decl (result_decl, 0); */
2148 /* TREE_STATIC means the function body is defined here. */
2149 TREE_STATIC (fndecl
) = 1;
2151 /* Set attributes for PURE functions. A call to a PURE function in the
2152 Fortran 95 sense is both pure and without side effects in the C
2154 if (attr
.pure
|| attr
.implicit_pure
)
2156 /* TODO: check if a pure SUBROUTINE has no INTENT(OUT) arguments
2157 including an alternate return. In that case it can also be
2158 marked as PURE. See also in gfc_get_extern_function_decl(). */
2159 if (attr
.function
&& !gfc_return_by_reference (sym
))
2160 DECL_PURE_P (fndecl
) = 1;
2161 TREE_SIDE_EFFECTS (fndecl
) = 0;
2165 /* Layout the function declaration and put it in the binding level
2166 of the current function. */
2169 pushdecl_top_level (fndecl
);
2173 /* Perform name mangling if this is a top level or module procedure. */
2174 if (current_function_decl
== NULL_TREE
)
2175 gfc_set_decl_assembler_name (fndecl
, gfc_sym_mangled_function_id (sym
));
2177 sym
->backend_decl
= fndecl
;
2181 /* Create the DECL_ARGUMENTS for a procedure. */
2184 create_function_arglist (gfc_symbol
* sym
)
2187 gfc_formal_arglist
*f
;
2188 tree typelist
, hidden_typelist
;
2189 tree arglist
, hidden_arglist
;
2193 fndecl
= sym
->backend_decl
;
2195 /* Build formal argument list. Make sure that their TREE_CONTEXT is
2196 the new FUNCTION_DECL node. */
2197 arglist
= NULL_TREE
;
2198 hidden_arglist
= NULL_TREE
;
2199 typelist
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
2201 if (sym
->attr
.entry_master
)
2203 type
= TREE_VALUE (typelist
);
2204 parm
= build_decl (input_location
,
2205 PARM_DECL
, get_identifier ("__entry"), type
);
2207 DECL_CONTEXT (parm
) = fndecl
;
2208 DECL_ARG_TYPE (parm
) = type
;
2209 TREE_READONLY (parm
) = 1;
2210 gfc_finish_decl (parm
);
2211 DECL_ARTIFICIAL (parm
) = 1;
2213 arglist
= chainon (arglist
, parm
);
2214 typelist
= TREE_CHAIN (typelist
);
2217 if (gfc_return_by_reference (sym
))
2219 tree type
= TREE_VALUE (typelist
), length
= NULL
;
2221 if (sym
->ts
.type
== BT_CHARACTER
)
2223 /* Length of character result. */
2224 tree len_type
= TREE_VALUE (TREE_CHAIN (typelist
));
2226 length
= build_decl (input_location
,
2228 get_identifier (".__result"),
2230 if (!sym
->ts
.u
.cl
->length
)
2232 sym
->ts
.u
.cl
->backend_decl
= length
;
2233 TREE_USED (length
) = 1;
2235 gcc_assert (TREE_CODE (length
) == PARM_DECL
);
2236 DECL_CONTEXT (length
) = fndecl
;
2237 DECL_ARG_TYPE (length
) = len_type
;
2238 TREE_READONLY (length
) = 1;
2239 DECL_ARTIFICIAL (length
) = 1;
2240 gfc_finish_decl (length
);
2241 if (sym
->ts
.u
.cl
->backend_decl
== NULL
2242 || sym
->ts
.u
.cl
->backend_decl
== length
)
2247 if (sym
->ts
.u
.cl
->backend_decl
== NULL
)
2249 tree len
= build_decl (input_location
,
2251 get_identifier ("..__result"),
2252 gfc_charlen_type_node
);
2253 DECL_ARTIFICIAL (len
) = 1;
2254 TREE_USED (len
) = 1;
2255 sym
->ts
.u
.cl
->backend_decl
= len
;
2258 /* Make sure PARM_DECL type doesn't point to incomplete type. */
2259 arg
= sym
->result
? sym
->result
: sym
;
2260 backend_decl
= arg
->backend_decl
;
2261 /* Temporary clear it, so that gfc_sym_type creates complete
2263 arg
->backend_decl
= NULL
;
2264 type
= gfc_sym_type (arg
);
2265 arg
->backend_decl
= backend_decl
;
2266 type
= build_reference_type (type
);
2270 parm
= build_decl (input_location
,
2271 PARM_DECL
, get_identifier ("__result"), type
);
2273 DECL_CONTEXT (parm
) = fndecl
;
2274 DECL_ARG_TYPE (parm
) = TREE_VALUE (typelist
);
2275 TREE_READONLY (parm
) = 1;
2276 DECL_ARTIFICIAL (parm
) = 1;
2277 gfc_finish_decl (parm
);
2279 arglist
= chainon (arglist
, parm
);
2280 typelist
= TREE_CHAIN (typelist
);
2282 if (sym
->ts
.type
== BT_CHARACTER
)
2284 gfc_allocate_lang_decl (parm
);
2285 arglist
= chainon (arglist
, length
);
2286 typelist
= TREE_CHAIN (typelist
);
2290 hidden_typelist
= typelist
;
2291 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
2292 if (f
->sym
!= NULL
) /* Ignore alternate returns. */
2293 hidden_typelist
= TREE_CHAIN (hidden_typelist
);
2295 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
2297 char name
[GFC_MAX_SYMBOL_LEN
+ 2];
2299 /* Ignore alternate returns. */
2303 type
= TREE_VALUE (typelist
);
2305 if (f
->sym
->ts
.type
== BT_CHARACTER
2306 && (!sym
->attr
.is_bind_c
|| sym
->attr
.entry_master
))
2308 tree len_type
= TREE_VALUE (hidden_typelist
);
2309 tree length
= NULL_TREE
;
2310 if (!f
->sym
->ts
.deferred
)
2311 gcc_assert (len_type
== gfc_charlen_type_node
);
2313 gcc_assert (POINTER_TYPE_P (len_type
));
2315 strcpy (&name
[1], f
->sym
->name
);
2317 length
= build_decl (input_location
,
2318 PARM_DECL
, get_identifier (name
), len_type
);
2320 hidden_arglist
= chainon (hidden_arglist
, length
);
2321 DECL_CONTEXT (length
) = fndecl
;
2322 DECL_ARTIFICIAL (length
) = 1;
2323 DECL_ARG_TYPE (length
) = len_type
;
2324 TREE_READONLY (length
) = 1;
2325 gfc_finish_decl (length
);
2327 /* Remember the passed value. */
2328 if (!f
->sym
->ts
.u
.cl
|| f
->sym
->ts
.u
.cl
->passed_length
)
2330 /* This can happen if the same type is used for multiple
2331 arguments. We need to copy cl as otherwise
2332 cl->passed_length gets overwritten. */
2333 f
->sym
->ts
.u
.cl
= gfc_new_charlen (f
->sym
->ns
, f
->sym
->ts
.u
.cl
);
2335 f
->sym
->ts
.u
.cl
->passed_length
= length
;
2337 /* Use the passed value for assumed length variables. */
2338 if (!f
->sym
->ts
.u
.cl
->length
)
2340 TREE_USED (length
) = 1;
2341 gcc_assert (!f
->sym
->ts
.u
.cl
->backend_decl
);
2342 f
->sym
->ts
.u
.cl
->backend_decl
= length
;
2345 hidden_typelist
= TREE_CHAIN (hidden_typelist
);
2347 if (f
->sym
->ts
.u
.cl
->backend_decl
== NULL
2348 || f
->sym
->ts
.u
.cl
->backend_decl
== length
)
2350 if (f
->sym
->ts
.u
.cl
->backend_decl
== NULL
)
2351 gfc_create_string_length (f
->sym
);
2353 /* Make sure PARM_DECL type doesn't point to incomplete type. */
2354 if (f
->sym
->attr
.flavor
== FL_PROCEDURE
)
2355 type
= build_pointer_type (gfc_get_function_type (f
->sym
));
2357 type
= gfc_sym_type (f
->sym
);
2360 /* For noncharacter scalar intrinsic types, VALUE passes the value,
2361 hence, the optional status cannot be transferred via a NULL pointer.
2362 Thus, we will use a hidden argument in that case. */
2363 else if (f
->sym
->attr
.optional
&& f
->sym
->attr
.value
2364 && !f
->sym
->attr
.dimension
&& f
->sym
->ts
.type
!= BT_CLASS
2365 && f
->sym
->ts
.type
!= BT_DERIVED
)
2368 strcpy (&name
[1], f
->sym
->name
);
2370 tmp
= build_decl (input_location
,
2371 PARM_DECL
, get_identifier (name
),
2374 hidden_arglist
= chainon (hidden_arglist
, tmp
);
2375 DECL_CONTEXT (tmp
) = fndecl
;
2376 DECL_ARTIFICIAL (tmp
) = 1;
2377 DECL_ARG_TYPE (tmp
) = boolean_type_node
;
2378 TREE_READONLY (tmp
) = 1;
2379 gfc_finish_decl (tmp
);
2382 /* For non-constant length array arguments, make sure they use
2383 a different type node from TYPE_ARG_TYPES type. */
2384 if (f
->sym
->attr
.dimension
2385 && type
== TREE_VALUE (typelist
)
2386 && TREE_CODE (type
) == POINTER_TYPE
2387 && GFC_ARRAY_TYPE_P (type
)
2388 && f
->sym
->as
->type
!= AS_ASSUMED_SIZE
2389 && ! COMPLETE_TYPE_P (TREE_TYPE (type
)))
2391 if (f
->sym
->attr
.flavor
== FL_PROCEDURE
)
2392 type
= build_pointer_type (gfc_get_function_type (f
->sym
));
2394 type
= gfc_sym_type (f
->sym
);
2397 if (f
->sym
->attr
.proc_pointer
)
2398 type
= build_pointer_type (type
);
2400 if (f
->sym
->attr
.volatile_
)
2401 type
= build_qualified_type (type
, TYPE_QUAL_VOLATILE
);
2403 /* Build the argument declaration. */
2404 parm
= build_decl (input_location
,
2405 PARM_DECL
, gfc_sym_identifier (f
->sym
), type
);
2407 if (f
->sym
->attr
.volatile_
)
2409 TREE_THIS_VOLATILE (parm
) = 1;
2410 TREE_SIDE_EFFECTS (parm
) = 1;
2413 /* Fill in arg stuff. */
2414 DECL_CONTEXT (parm
) = fndecl
;
2415 DECL_ARG_TYPE (parm
) = TREE_VALUE (typelist
);
2416 /* All implementation args except for VALUE are read-only. */
2417 if (!f
->sym
->attr
.value
)
2418 TREE_READONLY (parm
) = 1;
2419 if (POINTER_TYPE_P (type
)
2420 && (!f
->sym
->attr
.proc_pointer
2421 && f
->sym
->attr
.flavor
!= FL_PROCEDURE
))
2422 DECL_BY_REFERENCE (parm
) = 1;
2424 gfc_finish_decl (parm
);
2425 gfc_finish_decl_attrs (parm
, &f
->sym
->attr
);
2427 f
->sym
->backend_decl
= parm
;
2429 /* Coarrays which are descriptorless or assumed-shape pass with
2430 -fcoarray=lib the token and the offset as hidden arguments. */
2431 if (flag_coarray
== GFC_FCOARRAY_LIB
2432 && ((f
->sym
->ts
.type
!= BT_CLASS
&& f
->sym
->attr
.codimension
2433 && !f
->sym
->attr
.allocatable
)
2434 || (f
->sym
->ts
.type
== BT_CLASS
2435 && CLASS_DATA (f
->sym
)->attr
.codimension
2436 && !CLASS_DATA (f
->sym
)->attr
.allocatable
)))
2442 gcc_assert (f
->sym
->backend_decl
!= NULL_TREE
2443 && !sym
->attr
.is_bind_c
);
2444 caf_type
= f
->sym
->ts
.type
== BT_CLASS
2445 ? TREE_TYPE (CLASS_DATA (f
->sym
)->backend_decl
)
2446 : TREE_TYPE (f
->sym
->backend_decl
);
2448 token
= build_decl (input_location
, PARM_DECL
,
2449 create_tmp_var_name ("caf_token"),
2450 build_qualified_type (pvoid_type_node
,
2451 TYPE_QUAL_RESTRICT
));
2452 if ((f
->sym
->ts
.type
!= BT_CLASS
2453 && f
->sym
->as
->type
!= AS_DEFERRED
)
2454 || (f
->sym
->ts
.type
== BT_CLASS
2455 && CLASS_DATA (f
->sym
)->as
->type
!= AS_DEFERRED
))
2457 gcc_assert (DECL_LANG_SPECIFIC (f
->sym
->backend_decl
) == NULL
2458 || GFC_DECL_TOKEN (f
->sym
->backend_decl
) == NULL_TREE
);
2459 if (DECL_LANG_SPECIFIC (f
->sym
->backend_decl
) == NULL
)
2460 gfc_allocate_lang_decl (f
->sym
->backend_decl
);
2461 GFC_DECL_TOKEN (f
->sym
->backend_decl
) = token
;
2465 gcc_assert (GFC_TYPE_ARRAY_CAF_TOKEN (caf_type
) == NULL_TREE
);
2466 GFC_TYPE_ARRAY_CAF_TOKEN (caf_type
) = token
;
2469 DECL_CONTEXT (token
) = fndecl
;
2470 DECL_ARTIFICIAL (token
) = 1;
2471 DECL_ARG_TYPE (token
) = TREE_VALUE (typelist
);
2472 TREE_READONLY (token
) = 1;
2473 hidden_arglist
= chainon (hidden_arglist
, token
);
2474 gfc_finish_decl (token
);
2476 offset
= build_decl (input_location
, PARM_DECL
,
2477 create_tmp_var_name ("caf_offset"),
2478 gfc_array_index_type
);
2480 if ((f
->sym
->ts
.type
!= BT_CLASS
2481 && f
->sym
->as
->type
!= AS_DEFERRED
)
2482 || (f
->sym
->ts
.type
== BT_CLASS
2483 && CLASS_DATA (f
->sym
)->as
->type
!= AS_DEFERRED
))
2485 gcc_assert (GFC_DECL_CAF_OFFSET (f
->sym
->backend_decl
)
2487 GFC_DECL_CAF_OFFSET (f
->sym
->backend_decl
) = offset
;
2491 gcc_assert (GFC_TYPE_ARRAY_CAF_OFFSET (caf_type
) == NULL_TREE
);
2492 GFC_TYPE_ARRAY_CAF_OFFSET (caf_type
) = offset
;
2494 DECL_CONTEXT (offset
) = fndecl
;
2495 DECL_ARTIFICIAL (offset
) = 1;
2496 DECL_ARG_TYPE (offset
) = TREE_VALUE (typelist
);
2497 TREE_READONLY (offset
) = 1;
2498 hidden_arglist
= chainon (hidden_arglist
, offset
);
2499 gfc_finish_decl (offset
);
2502 arglist
= chainon (arglist
, parm
);
2503 typelist
= TREE_CHAIN (typelist
);
2506 /* Add the hidden string length parameters, unless the procedure
2508 if (!sym
->attr
.is_bind_c
)
2509 arglist
= chainon (arglist
, hidden_arglist
);
2511 gcc_assert (hidden_typelist
== NULL_TREE
2512 || TREE_VALUE (hidden_typelist
) == void_type_node
);
2513 DECL_ARGUMENTS (fndecl
) = arglist
;
2516 /* Do the setup necessary before generating the body of a function. */
2519 trans_function_start (gfc_symbol
* sym
)
2523 fndecl
= sym
->backend_decl
;
2525 /* Let GCC know the current scope is this function. */
2526 current_function_decl
= fndecl
;
2528 /* Let the world know what we're about to do. */
2529 announce_function (fndecl
);
2531 if (DECL_FILE_SCOPE_P (fndecl
))
2533 /* Create RTL for function declaration. */
2534 rest_of_decl_compilation (fndecl
, 1, 0);
2537 /* Create RTL for function definition. */
2538 make_decl_rtl (fndecl
);
2540 allocate_struct_function (fndecl
, false);
2542 /* function.c requires a push at the start of the function. */
2546 /* Create thunks for alternate entry points. */
2549 build_entry_thunks (gfc_namespace
* ns
, bool global
)
2551 gfc_formal_arglist
*formal
;
2552 gfc_formal_arglist
*thunk_formal
;
2554 gfc_symbol
*thunk_sym
;
2560 /* This should always be a toplevel function. */
2561 gcc_assert (current_function_decl
== NULL_TREE
);
2563 gfc_save_backend_locus (&old_loc
);
2564 for (el
= ns
->entries
; el
; el
= el
->next
)
2566 vec
<tree
, va_gc
> *args
= NULL
;
2567 vec
<tree
, va_gc
> *string_args
= NULL
;
2569 thunk_sym
= el
->sym
;
2571 build_function_decl (thunk_sym
, global
);
2572 create_function_arglist (thunk_sym
);
2574 trans_function_start (thunk_sym
);
2576 thunk_fndecl
= thunk_sym
->backend_decl
;
2578 gfc_init_block (&body
);
2580 /* Pass extra parameter identifying this entry point. */
2581 tmp
= build_int_cst (gfc_array_index_type
, el
->id
);
2582 vec_safe_push (args
, tmp
);
2584 if (thunk_sym
->attr
.function
)
2586 if (gfc_return_by_reference (ns
->proc_name
))
2588 tree ref
= DECL_ARGUMENTS (current_function_decl
);
2589 vec_safe_push (args
, ref
);
2590 if (ns
->proc_name
->ts
.type
== BT_CHARACTER
)
2591 vec_safe_push (args
, DECL_CHAIN (ref
));
2595 for (formal
= gfc_sym_get_dummy_args (ns
->proc_name
); formal
;
2596 formal
= formal
->next
)
2598 /* Ignore alternate returns. */
2599 if (formal
->sym
== NULL
)
2602 /* We don't have a clever way of identifying arguments, so resort to
2603 a brute-force search. */
2604 for (thunk_formal
= gfc_sym_get_dummy_args (thunk_sym
);
2606 thunk_formal
= thunk_formal
->next
)
2608 if (thunk_formal
->sym
== formal
->sym
)
2614 /* Pass the argument. */
2615 DECL_ARTIFICIAL (thunk_formal
->sym
->backend_decl
) = 1;
2616 vec_safe_push (args
, thunk_formal
->sym
->backend_decl
);
2617 if (formal
->sym
->ts
.type
== BT_CHARACTER
)
2619 tmp
= thunk_formal
->sym
->ts
.u
.cl
->backend_decl
;
2620 vec_safe_push (string_args
, tmp
);
2625 /* Pass NULL for a missing argument. */
2626 vec_safe_push (args
, null_pointer_node
);
2627 if (formal
->sym
->ts
.type
== BT_CHARACTER
)
2629 tmp
= build_int_cst (gfc_charlen_type_node
, 0);
2630 vec_safe_push (string_args
, tmp
);
2635 /* Call the master function. */
2636 vec_safe_splice (args
, string_args
);
2637 tmp
= ns
->proc_name
->backend_decl
;
2638 tmp
= build_call_expr_loc_vec (input_location
, tmp
, args
);
2639 if (ns
->proc_name
->attr
.mixed_entry_master
)
2641 tree union_decl
, field
;
2642 tree master_type
= TREE_TYPE (ns
->proc_name
->backend_decl
);
2644 union_decl
= build_decl (input_location
,
2645 VAR_DECL
, get_identifier ("__result"),
2646 TREE_TYPE (master_type
));
2647 DECL_ARTIFICIAL (union_decl
) = 1;
2648 DECL_EXTERNAL (union_decl
) = 0;
2649 TREE_PUBLIC (union_decl
) = 0;
2650 TREE_USED (union_decl
) = 1;
2651 layout_decl (union_decl
, 0);
2652 pushdecl (union_decl
);
2654 DECL_CONTEXT (union_decl
) = current_function_decl
;
2655 tmp
= fold_build2_loc (input_location
, MODIFY_EXPR
,
2656 TREE_TYPE (union_decl
), union_decl
, tmp
);
2657 gfc_add_expr_to_block (&body
, tmp
);
2659 for (field
= TYPE_FIELDS (TREE_TYPE (union_decl
));
2660 field
; field
= DECL_CHAIN (field
))
2661 if (strcmp (IDENTIFIER_POINTER (DECL_NAME (field
)),
2662 thunk_sym
->result
->name
) == 0)
2664 gcc_assert (field
!= NULL_TREE
);
2665 tmp
= fold_build3_loc (input_location
, COMPONENT_REF
,
2666 TREE_TYPE (field
), union_decl
, field
,
2668 tmp
= fold_build2_loc (input_location
, MODIFY_EXPR
,
2669 TREE_TYPE (DECL_RESULT (current_function_decl
)),
2670 DECL_RESULT (current_function_decl
), tmp
);
2671 tmp
= build1_v (RETURN_EXPR
, tmp
);
2673 else if (TREE_TYPE (DECL_RESULT (current_function_decl
))
2676 tmp
= fold_build2_loc (input_location
, MODIFY_EXPR
,
2677 TREE_TYPE (DECL_RESULT (current_function_decl
)),
2678 DECL_RESULT (current_function_decl
), tmp
);
2679 tmp
= build1_v (RETURN_EXPR
, tmp
);
2681 gfc_add_expr_to_block (&body
, tmp
);
2683 /* Finish off this function and send it for code generation. */
2684 DECL_SAVED_TREE (thunk_fndecl
) = gfc_finish_block (&body
);
2687 BLOCK_SUPERCONTEXT (DECL_INITIAL (thunk_fndecl
)) = thunk_fndecl
;
2688 DECL_SAVED_TREE (thunk_fndecl
)
2689 = build3_v (BIND_EXPR
, tmp
, DECL_SAVED_TREE (thunk_fndecl
),
2690 DECL_INITIAL (thunk_fndecl
));
2692 /* Output the GENERIC tree. */
2693 dump_function (TDI_original
, thunk_fndecl
);
2695 /* Store the end of the function, so that we get good line number
2696 info for the epilogue. */
2697 cfun
->function_end_locus
= input_location
;
2699 /* We're leaving the context of this function, so zap cfun.
2700 It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
2701 tree_rest_of_compilation. */
2704 current_function_decl
= NULL_TREE
;
2706 cgraph_node::finalize_function (thunk_fndecl
, true);
2708 /* We share the symbols in the formal argument list with other entry
2709 points and the master function. Clear them so that they are
2710 recreated for each function. */
2711 for (formal
= gfc_sym_get_dummy_args (thunk_sym
); formal
;
2712 formal
= formal
->next
)
2713 if (formal
->sym
!= NULL
) /* Ignore alternate returns. */
2715 formal
->sym
->backend_decl
= NULL_TREE
;
2716 if (formal
->sym
->ts
.type
== BT_CHARACTER
)
2717 formal
->sym
->ts
.u
.cl
->backend_decl
= NULL_TREE
;
2720 if (thunk_sym
->attr
.function
)
2722 if (thunk_sym
->ts
.type
== BT_CHARACTER
)
2723 thunk_sym
->ts
.u
.cl
->backend_decl
= NULL_TREE
;
2724 if (thunk_sym
->result
->ts
.type
== BT_CHARACTER
)
2725 thunk_sym
->result
->ts
.u
.cl
->backend_decl
= NULL_TREE
;
2729 gfc_restore_backend_locus (&old_loc
);
2733 /* Create a decl for a function, and create any thunks for alternate entry
2734 points. If global is true, generate the function in the global binding
2735 level, otherwise in the current binding level (which can be global). */
2738 gfc_create_function_decl (gfc_namespace
* ns
, bool global
)
2740 /* Create a declaration for the master function. */
2741 build_function_decl (ns
->proc_name
, global
);
2743 /* Compile the entry thunks. */
2745 build_entry_thunks (ns
, global
);
2747 /* Now create the read argument list. */
2748 create_function_arglist (ns
->proc_name
);
2750 if (ns
->omp_declare_simd
)
2751 gfc_trans_omp_declare_simd (ns
);
2754 /* Return the decl used to hold the function return value. If
2755 parent_flag is set, the context is the parent_scope. */
2758 gfc_get_fake_result_decl (gfc_symbol
* sym
, int parent_flag
)
2762 tree this_fake_result_decl
;
2763 tree this_function_decl
;
2765 char name
[GFC_MAX_SYMBOL_LEN
+ 10];
2769 this_fake_result_decl
= parent_fake_result_decl
;
2770 this_function_decl
= DECL_CONTEXT (current_function_decl
);
2774 this_fake_result_decl
= current_fake_result_decl
;
2775 this_function_decl
= current_function_decl
;
2779 && sym
->ns
->proc_name
->backend_decl
== this_function_decl
2780 && sym
->ns
->proc_name
->attr
.entry_master
2781 && sym
!= sym
->ns
->proc_name
)
2784 if (this_fake_result_decl
!= NULL
)
2785 for (t
= TREE_CHAIN (this_fake_result_decl
); t
; t
= TREE_CHAIN (t
))
2786 if (strcmp (IDENTIFIER_POINTER (TREE_PURPOSE (t
)), sym
->name
) == 0)
2789 return TREE_VALUE (t
);
2790 decl
= gfc_get_fake_result_decl (sym
->ns
->proc_name
, parent_flag
);
2793 this_fake_result_decl
= parent_fake_result_decl
;
2795 this_fake_result_decl
= current_fake_result_decl
;
2797 if (decl
&& sym
->ns
->proc_name
->attr
.mixed_entry_master
)
2801 for (field
= TYPE_FIELDS (TREE_TYPE (decl
));
2802 field
; field
= DECL_CHAIN (field
))
2803 if (strcmp (IDENTIFIER_POINTER (DECL_NAME (field
)),
2807 gcc_assert (field
!= NULL_TREE
);
2808 decl
= fold_build3_loc (input_location
, COMPONENT_REF
,
2809 TREE_TYPE (field
), decl
, field
, NULL_TREE
);
2812 var
= create_tmp_var_raw (TREE_TYPE (decl
), sym
->name
);
2814 gfc_add_decl_to_parent_function (var
);
2816 gfc_add_decl_to_function (var
);
2818 SET_DECL_VALUE_EXPR (var
, decl
);
2819 DECL_HAS_VALUE_EXPR_P (var
) = 1;
2820 GFC_DECL_RESULT (var
) = 1;
2822 TREE_CHAIN (this_fake_result_decl
)
2823 = tree_cons (get_identifier (sym
->name
), var
,
2824 TREE_CHAIN (this_fake_result_decl
));
2828 if (this_fake_result_decl
!= NULL_TREE
)
2829 return TREE_VALUE (this_fake_result_decl
);
2831 /* Only when gfc_get_fake_result_decl is called by gfc_trans_return,
2836 if (sym
->ts
.type
== BT_CHARACTER
)
2838 if (sym
->ts
.u
.cl
->backend_decl
== NULL_TREE
)
2839 length
= gfc_create_string_length (sym
);
2841 length
= sym
->ts
.u
.cl
->backend_decl
;
2842 if (TREE_CODE (length
) == VAR_DECL
2843 && DECL_CONTEXT (length
) == NULL_TREE
)
2844 gfc_add_decl_to_function (length
);
2847 if (gfc_return_by_reference (sym
))
2849 decl
= DECL_ARGUMENTS (this_function_decl
);
2851 if (sym
->ns
->proc_name
->backend_decl
== this_function_decl
2852 && sym
->ns
->proc_name
->attr
.entry_master
)
2853 decl
= DECL_CHAIN (decl
);
2855 TREE_USED (decl
) = 1;
2857 decl
= gfc_build_dummy_array_decl (sym
, decl
);
2861 sprintf (name
, "__result_%.20s",
2862 IDENTIFIER_POINTER (DECL_NAME (this_function_decl
)));
2864 if (!sym
->attr
.mixed_entry_master
&& sym
->attr
.function
)
2865 decl
= build_decl (DECL_SOURCE_LOCATION (this_function_decl
),
2866 VAR_DECL
, get_identifier (name
),
2867 gfc_sym_type (sym
));
2869 decl
= build_decl (DECL_SOURCE_LOCATION (this_function_decl
),
2870 VAR_DECL
, get_identifier (name
),
2871 TREE_TYPE (TREE_TYPE (this_function_decl
)));
2872 DECL_ARTIFICIAL (decl
) = 1;
2873 DECL_EXTERNAL (decl
) = 0;
2874 TREE_PUBLIC (decl
) = 0;
2875 TREE_USED (decl
) = 1;
2876 GFC_DECL_RESULT (decl
) = 1;
2877 TREE_ADDRESSABLE (decl
) = 1;
2879 layout_decl (decl
, 0);
2880 gfc_finish_decl_attrs (decl
, &sym
->attr
);
2883 gfc_add_decl_to_parent_function (decl
);
2885 gfc_add_decl_to_function (decl
);
2889 parent_fake_result_decl
= build_tree_list (NULL
, decl
);
2891 current_fake_result_decl
= build_tree_list (NULL
, decl
);
2897 /* Builds a function decl. The remaining parameters are the types of the
2898 function arguments. Negative nargs indicates a varargs function. */
2901 build_library_function_decl_1 (tree name
, const char *spec
,
2902 tree rettype
, int nargs
, va_list p
)
2904 vec
<tree
, va_gc
> *arglist
;
2909 /* Library functions must be declared with global scope. */
2910 gcc_assert (current_function_decl
== NULL_TREE
);
2912 /* Create a list of the argument types. */
2913 vec_alloc (arglist
, abs (nargs
));
2914 for (n
= abs (nargs
); n
> 0; n
--)
2916 tree argtype
= va_arg (p
, tree
);
2917 arglist
->quick_push (argtype
);
2920 /* Build the function type and decl. */
2922 fntype
= build_function_type_vec (rettype
, arglist
);
2924 fntype
= build_varargs_function_type_vec (rettype
, arglist
);
2927 tree attr_args
= build_tree_list (NULL_TREE
,
2928 build_string (strlen (spec
), spec
));
2929 tree attrs
= tree_cons (get_identifier ("fn spec"),
2930 attr_args
, TYPE_ATTRIBUTES (fntype
));
2931 fntype
= build_type_attribute_variant (fntype
, attrs
);
2933 fndecl
= build_decl (input_location
,
2934 FUNCTION_DECL
, name
, fntype
);
2936 /* Mark this decl as external. */
2937 DECL_EXTERNAL (fndecl
) = 1;
2938 TREE_PUBLIC (fndecl
) = 1;
2942 rest_of_decl_compilation (fndecl
, 1, 0);
2947 /* Builds a function decl. The remaining parameters are the types of the
2948 function arguments. Negative nargs indicates a varargs function. */
2951 gfc_build_library_function_decl (tree name
, tree rettype
, int nargs
, ...)
2955 va_start (args
, nargs
);
2956 ret
= build_library_function_decl_1 (name
, NULL
, rettype
, nargs
, args
);
2961 /* Builds a function decl. The remaining parameters are the types of the
2962 function arguments. Negative nargs indicates a varargs function.
2963 The SPEC parameter specifies the function argument and return type
2964 specification according to the fnspec function type attribute. */
2967 gfc_build_library_function_decl_with_spec (tree name
, const char *spec
,
2968 tree rettype
, int nargs
, ...)
2972 va_start (args
, nargs
);
2973 ret
= build_library_function_decl_1 (name
, spec
, rettype
, nargs
, args
);
2979 gfc_build_intrinsic_function_decls (void)
2981 tree gfc_int4_type_node
= gfc_get_int_type (4);
2982 tree gfc_pint4_type_node
= build_pointer_type (gfc_int4_type_node
);
2983 tree gfc_int8_type_node
= gfc_get_int_type (8);
2984 tree gfc_pint8_type_node
= build_pointer_type (gfc_int8_type_node
);
2985 tree gfc_int16_type_node
= gfc_get_int_type (16);
2986 tree gfc_logical4_type_node
= gfc_get_logical_type (4);
2987 tree pchar1_type_node
= gfc_get_pchar_type (1);
2988 tree pchar4_type_node
= gfc_get_pchar_type (4);
2990 /* String functions. */
2991 gfor_fndecl_compare_string
= gfc_build_library_function_decl_with_spec (
2992 get_identifier (PREFIX("compare_string")), "..R.R",
2993 integer_type_node
, 4, gfc_charlen_type_node
, pchar1_type_node
,
2994 gfc_charlen_type_node
, pchar1_type_node
);
2995 DECL_PURE_P (gfor_fndecl_compare_string
) = 1;
2996 TREE_NOTHROW (gfor_fndecl_compare_string
) = 1;
2998 gfor_fndecl_concat_string
= gfc_build_library_function_decl_with_spec (
2999 get_identifier (PREFIX("concat_string")), "..W.R.R",
3000 void_type_node
, 6, gfc_charlen_type_node
, pchar1_type_node
,
3001 gfc_charlen_type_node
, pchar1_type_node
,
3002 gfc_charlen_type_node
, pchar1_type_node
);
3003 TREE_NOTHROW (gfor_fndecl_concat_string
) = 1;
3005 gfor_fndecl_string_len_trim
= gfc_build_library_function_decl_with_spec (
3006 get_identifier (PREFIX("string_len_trim")), "..R",
3007 gfc_charlen_type_node
, 2, gfc_charlen_type_node
, pchar1_type_node
);
3008 DECL_PURE_P (gfor_fndecl_string_len_trim
) = 1;
3009 TREE_NOTHROW (gfor_fndecl_string_len_trim
) = 1;
3011 gfor_fndecl_string_index
= gfc_build_library_function_decl_with_spec (
3012 get_identifier (PREFIX("string_index")), "..R.R.",
3013 gfc_charlen_type_node
, 5, gfc_charlen_type_node
, pchar1_type_node
,
3014 gfc_charlen_type_node
, pchar1_type_node
, gfc_logical4_type_node
);
3015 DECL_PURE_P (gfor_fndecl_string_index
) = 1;
3016 TREE_NOTHROW (gfor_fndecl_string_index
) = 1;
3018 gfor_fndecl_string_scan
= gfc_build_library_function_decl_with_spec (
3019 get_identifier (PREFIX("string_scan")), "..R.R.",
3020 gfc_charlen_type_node
, 5, gfc_charlen_type_node
, pchar1_type_node
,
3021 gfc_charlen_type_node
, pchar1_type_node
, gfc_logical4_type_node
);
3022 DECL_PURE_P (gfor_fndecl_string_scan
) = 1;
3023 TREE_NOTHROW (gfor_fndecl_string_scan
) = 1;
3025 gfor_fndecl_string_verify
= gfc_build_library_function_decl_with_spec (
3026 get_identifier (PREFIX("string_verify")), "..R.R.",
3027 gfc_charlen_type_node
, 5, gfc_charlen_type_node
, pchar1_type_node
,
3028 gfc_charlen_type_node
, pchar1_type_node
, gfc_logical4_type_node
);
3029 DECL_PURE_P (gfor_fndecl_string_verify
) = 1;
3030 TREE_NOTHROW (gfor_fndecl_string_verify
) = 1;
3032 gfor_fndecl_string_trim
= gfc_build_library_function_decl_with_spec (
3033 get_identifier (PREFIX("string_trim")), ".Ww.R",
3034 void_type_node
, 4, build_pointer_type (gfc_charlen_type_node
),
3035 build_pointer_type (pchar1_type_node
), gfc_charlen_type_node
,
3038 gfor_fndecl_string_minmax
= gfc_build_library_function_decl_with_spec (
3039 get_identifier (PREFIX("string_minmax")), ".Ww.R",
3040 void_type_node
, -4, build_pointer_type (gfc_charlen_type_node
),
3041 build_pointer_type (pchar1_type_node
), integer_type_node
,
3044 gfor_fndecl_adjustl
= gfc_build_library_function_decl_with_spec (
3045 get_identifier (PREFIX("adjustl")), ".W.R",
3046 void_type_node
, 3, pchar1_type_node
, gfc_charlen_type_node
,
3048 TREE_NOTHROW (gfor_fndecl_adjustl
) = 1;
3050 gfor_fndecl_adjustr
= gfc_build_library_function_decl_with_spec (
3051 get_identifier (PREFIX("adjustr")), ".W.R",
3052 void_type_node
, 3, pchar1_type_node
, gfc_charlen_type_node
,
3054 TREE_NOTHROW (gfor_fndecl_adjustr
) = 1;
3056 gfor_fndecl_select_string
= gfc_build_library_function_decl_with_spec (
3057 get_identifier (PREFIX("select_string")), ".R.R.",
3058 integer_type_node
, 4, pvoid_type_node
, integer_type_node
,
3059 pchar1_type_node
, gfc_charlen_type_node
);
3060 DECL_PURE_P (gfor_fndecl_select_string
) = 1;
3061 TREE_NOTHROW (gfor_fndecl_select_string
) = 1;
3063 gfor_fndecl_compare_string_char4
= gfc_build_library_function_decl_with_spec (
3064 get_identifier (PREFIX("compare_string_char4")), "..R.R",
3065 integer_type_node
, 4, gfc_charlen_type_node
, pchar4_type_node
,
3066 gfc_charlen_type_node
, pchar4_type_node
);
3067 DECL_PURE_P (gfor_fndecl_compare_string_char4
) = 1;
3068 TREE_NOTHROW (gfor_fndecl_compare_string_char4
) = 1;
3070 gfor_fndecl_concat_string_char4
= gfc_build_library_function_decl_with_spec (
3071 get_identifier (PREFIX("concat_string_char4")), "..W.R.R",
3072 void_type_node
, 6, gfc_charlen_type_node
, pchar4_type_node
,
3073 gfc_charlen_type_node
, pchar4_type_node
, gfc_charlen_type_node
,
3075 TREE_NOTHROW (gfor_fndecl_concat_string_char4
) = 1;
3077 gfor_fndecl_string_len_trim_char4
= gfc_build_library_function_decl_with_spec (
3078 get_identifier (PREFIX("string_len_trim_char4")), "..R",
3079 gfc_charlen_type_node
, 2, gfc_charlen_type_node
, pchar4_type_node
);
3080 DECL_PURE_P (gfor_fndecl_string_len_trim_char4
) = 1;
3081 TREE_NOTHROW (gfor_fndecl_string_len_trim_char4
) = 1;
3083 gfor_fndecl_string_index_char4
= gfc_build_library_function_decl_with_spec (
3084 get_identifier (PREFIX("string_index_char4")), "..R.R.",
3085 gfc_charlen_type_node
, 5, gfc_charlen_type_node
, pchar4_type_node
,
3086 gfc_charlen_type_node
, pchar4_type_node
, gfc_logical4_type_node
);
3087 DECL_PURE_P (gfor_fndecl_string_index_char4
) = 1;
3088 TREE_NOTHROW (gfor_fndecl_string_index_char4
) = 1;
3090 gfor_fndecl_string_scan_char4
= gfc_build_library_function_decl_with_spec (
3091 get_identifier (PREFIX("string_scan_char4")), "..R.R.",
3092 gfc_charlen_type_node
, 5, gfc_charlen_type_node
, pchar4_type_node
,
3093 gfc_charlen_type_node
, pchar4_type_node
, gfc_logical4_type_node
);
3094 DECL_PURE_P (gfor_fndecl_string_scan_char4
) = 1;
3095 TREE_NOTHROW (gfor_fndecl_string_scan_char4
) = 1;
3097 gfor_fndecl_string_verify_char4
= gfc_build_library_function_decl_with_spec (
3098 get_identifier (PREFIX("string_verify_char4")), "..R.R.",
3099 gfc_charlen_type_node
, 5, gfc_charlen_type_node
, pchar4_type_node
,
3100 gfc_charlen_type_node
, pchar4_type_node
, gfc_logical4_type_node
);
3101 DECL_PURE_P (gfor_fndecl_string_verify_char4
) = 1;
3102 TREE_NOTHROW (gfor_fndecl_string_verify_char4
) = 1;
3104 gfor_fndecl_string_trim_char4
= gfc_build_library_function_decl_with_spec (
3105 get_identifier (PREFIX("string_trim_char4")), ".Ww.R",
3106 void_type_node
, 4, build_pointer_type (gfc_charlen_type_node
),
3107 build_pointer_type (pchar4_type_node
), gfc_charlen_type_node
,
3110 gfor_fndecl_string_minmax_char4
= gfc_build_library_function_decl_with_spec (
3111 get_identifier (PREFIX("string_minmax_char4")), ".Ww.R",
3112 void_type_node
, -4, build_pointer_type (gfc_charlen_type_node
),
3113 build_pointer_type (pchar4_type_node
), integer_type_node
,
3116 gfor_fndecl_adjustl_char4
= gfc_build_library_function_decl_with_spec (
3117 get_identifier (PREFIX("adjustl_char4")), ".W.R",
3118 void_type_node
, 3, pchar4_type_node
, gfc_charlen_type_node
,
3120 TREE_NOTHROW (gfor_fndecl_adjustl_char4
) = 1;
3122 gfor_fndecl_adjustr_char4
= gfc_build_library_function_decl_with_spec (
3123 get_identifier (PREFIX("adjustr_char4")), ".W.R",
3124 void_type_node
, 3, pchar4_type_node
, gfc_charlen_type_node
,
3126 TREE_NOTHROW (gfor_fndecl_adjustr_char4
) = 1;
3128 gfor_fndecl_select_string_char4
= gfc_build_library_function_decl_with_spec (
3129 get_identifier (PREFIX("select_string_char4")), ".R.R.",
3130 integer_type_node
, 4, pvoid_type_node
, integer_type_node
,
3131 pvoid_type_node
, gfc_charlen_type_node
);
3132 DECL_PURE_P (gfor_fndecl_select_string_char4
) = 1;
3133 TREE_NOTHROW (gfor_fndecl_select_string_char4
) = 1;
3136 /* Conversion between character kinds. */
3138 gfor_fndecl_convert_char1_to_char4
= gfc_build_library_function_decl_with_spec (
3139 get_identifier (PREFIX("convert_char1_to_char4")), ".w.R",
3140 void_type_node
, 3, build_pointer_type (pchar4_type_node
),
3141 gfc_charlen_type_node
, pchar1_type_node
);
3143 gfor_fndecl_convert_char4_to_char1
= gfc_build_library_function_decl_with_spec (
3144 get_identifier (PREFIX("convert_char4_to_char1")), ".w.R",
3145 void_type_node
, 3, build_pointer_type (pchar1_type_node
),
3146 gfc_charlen_type_node
, pchar4_type_node
);
3148 /* Misc. functions. */
3150 gfor_fndecl_ttynam
= gfc_build_library_function_decl_with_spec (
3151 get_identifier (PREFIX("ttynam")), ".W",
3152 void_type_node
, 3, pchar_type_node
, gfc_charlen_type_node
,
3155 gfor_fndecl_fdate
= gfc_build_library_function_decl_with_spec (
3156 get_identifier (PREFIX("fdate")), ".W",
3157 void_type_node
, 2, pchar_type_node
, gfc_charlen_type_node
);
3159 gfor_fndecl_ctime
= gfc_build_library_function_decl_with_spec (
3160 get_identifier (PREFIX("ctime")), ".W",
3161 void_type_node
, 3, pchar_type_node
, gfc_charlen_type_node
,
3162 gfc_int8_type_node
);
3164 gfor_fndecl_sc_kind
= gfc_build_library_function_decl_with_spec (
3165 get_identifier (PREFIX("selected_char_kind")), "..R",
3166 gfc_int4_type_node
, 2, gfc_charlen_type_node
, pchar_type_node
);
3167 DECL_PURE_P (gfor_fndecl_sc_kind
) = 1;
3168 TREE_NOTHROW (gfor_fndecl_sc_kind
) = 1;
3170 gfor_fndecl_si_kind
= gfc_build_library_function_decl_with_spec (
3171 get_identifier (PREFIX("selected_int_kind")), ".R",
3172 gfc_int4_type_node
, 1, pvoid_type_node
);
3173 DECL_PURE_P (gfor_fndecl_si_kind
) = 1;
3174 TREE_NOTHROW (gfor_fndecl_si_kind
) = 1;
3176 gfor_fndecl_sr_kind
= gfc_build_library_function_decl_with_spec (
3177 get_identifier (PREFIX("selected_real_kind2008")), ".RR",
3178 gfc_int4_type_node
, 3, pvoid_type_node
, pvoid_type_node
,
3180 DECL_PURE_P (gfor_fndecl_sr_kind
) = 1;
3181 TREE_NOTHROW (gfor_fndecl_sr_kind
) = 1;
3183 gfor_fndecl_system_clock4
= gfc_build_library_function_decl (
3184 get_identifier (PREFIX("system_clock_4")),
3185 void_type_node
, 3, gfc_pint4_type_node
, gfc_pint4_type_node
,
3186 gfc_pint4_type_node
);
3188 gfor_fndecl_system_clock8
= gfc_build_library_function_decl (
3189 get_identifier (PREFIX("system_clock_8")),
3190 void_type_node
, 3, gfc_pint8_type_node
, gfc_pint8_type_node
,
3191 gfc_pint8_type_node
);
3193 /* Power functions. */
3195 tree ctype
, rtype
, itype
, jtype
;
3196 int rkind
, ikind
, jkind
;
3199 static int ikinds
[NIKINDS
] = {4, 8, 16};
3200 static int rkinds
[NRKINDS
] = {4, 8, 10, 16};
3201 char name
[PREFIX_LEN
+ 12]; /* _gfortran_pow_?n_?n */
3203 for (ikind
=0; ikind
< NIKINDS
; ikind
++)
3205 itype
= gfc_get_int_type (ikinds
[ikind
]);
3207 for (jkind
=0; jkind
< NIKINDS
; jkind
++)
3209 jtype
= gfc_get_int_type (ikinds
[jkind
]);
3212 sprintf(name
, PREFIX("pow_i%d_i%d"), ikinds
[ikind
],
3214 gfor_fndecl_math_powi
[jkind
][ikind
].integer
=
3215 gfc_build_library_function_decl (get_identifier (name
),
3216 jtype
, 2, jtype
, itype
);
3217 TREE_READONLY (gfor_fndecl_math_powi
[jkind
][ikind
].integer
) = 1;
3218 TREE_NOTHROW (gfor_fndecl_math_powi
[jkind
][ikind
].integer
) = 1;
3222 for (rkind
= 0; rkind
< NRKINDS
; rkind
++)
3224 rtype
= gfc_get_real_type (rkinds
[rkind
]);
3227 sprintf(name
, PREFIX("pow_r%d_i%d"), rkinds
[rkind
],
3229 gfor_fndecl_math_powi
[rkind
][ikind
].real
=
3230 gfc_build_library_function_decl (get_identifier (name
),
3231 rtype
, 2, rtype
, itype
);
3232 TREE_READONLY (gfor_fndecl_math_powi
[rkind
][ikind
].real
) = 1;
3233 TREE_NOTHROW (gfor_fndecl_math_powi
[rkind
][ikind
].real
) = 1;
3236 ctype
= gfc_get_complex_type (rkinds
[rkind
]);
3239 sprintf(name
, PREFIX("pow_c%d_i%d"), rkinds
[rkind
],
3241 gfor_fndecl_math_powi
[rkind
][ikind
].cmplx
=
3242 gfc_build_library_function_decl (get_identifier (name
),
3243 ctype
, 2,ctype
, itype
);
3244 TREE_READONLY (gfor_fndecl_math_powi
[rkind
][ikind
].cmplx
) = 1;
3245 TREE_NOTHROW (gfor_fndecl_math_powi
[rkind
][ikind
].cmplx
) = 1;
3253 gfor_fndecl_math_ishftc4
= gfc_build_library_function_decl (
3254 get_identifier (PREFIX("ishftc4")),
3255 gfc_int4_type_node
, 3, gfc_int4_type_node
, gfc_int4_type_node
,
3256 gfc_int4_type_node
);
3257 TREE_READONLY (gfor_fndecl_math_ishftc4
) = 1;
3258 TREE_NOTHROW (gfor_fndecl_math_ishftc4
) = 1;
3260 gfor_fndecl_math_ishftc8
= gfc_build_library_function_decl (
3261 get_identifier (PREFIX("ishftc8")),
3262 gfc_int8_type_node
, 3, gfc_int8_type_node
, gfc_int4_type_node
,
3263 gfc_int4_type_node
);
3264 TREE_READONLY (gfor_fndecl_math_ishftc8
) = 1;
3265 TREE_NOTHROW (gfor_fndecl_math_ishftc8
) = 1;
3267 if (gfc_int16_type_node
)
3269 gfor_fndecl_math_ishftc16
= gfc_build_library_function_decl (
3270 get_identifier (PREFIX("ishftc16")),
3271 gfc_int16_type_node
, 3, gfc_int16_type_node
, gfc_int4_type_node
,
3272 gfc_int4_type_node
);
3273 TREE_READONLY (gfor_fndecl_math_ishftc16
) = 1;
3274 TREE_NOTHROW (gfor_fndecl_math_ishftc16
) = 1;
3277 /* BLAS functions. */
3279 tree pint
= build_pointer_type (integer_type_node
);
3280 tree ps
= build_pointer_type (gfc_get_real_type (gfc_default_real_kind
));
3281 tree pd
= build_pointer_type (gfc_get_real_type (gfc_default_double_kind
));
3282 tree pc
= build_pointer_type (gfc_get_complex_type (gfc_default_real_kind
));
3283 tree pz
= build_pointer_type
3284 (gfc_get_complex_type (gfc_default_double_kind
));
3286 gfor_fndecl_sgemm
= gfc_build_library_function_decl
3288 (flag_underscoring
? "sgemm_" : "sgemm"),
3289 void_type_node
, 15, pchar_type_node
,
3290 pchar_type_node
, pint
, pint
, pint
, ps
, ps
, pint
,
3291 ps
, pint
, ps
, ps
, pint
, integer_type_node
,
3293 gfor_fndecl_dgemm
= gfc_build_library_function_decl
3295 (flag_underscoring
? "dgemm_" : "dgemm"),
3296 void_type_node
, 15, pchar_type_node
,
3297 pchar_type_node
, pint
, pint
, pint
, pd
, pd
, pint
,
3298 pd
, pint
, pd
, pd
, pint
, integer_type_node
,
3300 gfor_fndecl_cgemm
= gfc_build_library_function_decl
3302 (flag_underscoring
? "cgemm_" : "cgemm"),
3303 void_type_node
, 15, pchar_type_node
,
3304 pchar_type_node
, pint
, pint
, pint
, pc
, pc
, pint
,
3305 pc
, pint
, pc
, pc
, pint
, integer_type_node
,
3307 gfor_fndecl_zgemm
= gfc_build_library_function_decl
3309 (flag_underscoring
? "zgemm_" : "zgemm"),
3310 void_type_node
, 15, pchar_type_node
,
3311 pchar_type_node
, pint
, pint
, pint
, pz
, pz
, pint
,
3312 pz
, pint
, pz
, pz
, pint
, integer_type_node
,
3316 /* Other functions. */
3317 gfor_fndecl_size0
= gfc_build_library_function_decl_with_spec (
3318 get_identifier (PREFIX("size0")), ".R",
3319 gfc_array_index_type
, 1, pvoid_type_node
);
3320 DECL_PURE_P (gfor_fndecl_size0
) = 1;
3321 TREE_NOTHROW (gfor_fndecl_size0
) = 1;
3323 gfor_fndecl_size1
= gfc_build_library_function_decl_with_spec (
3324 get_identifier (PREFIX("size1")), ".R",
3325 gfc_array_index_type
, 2, pvoid_type_node
, gfc_array_index_type
);
3326 DECL_PURE_P (gfor_fndecl_size1
) = 1;
3327 TREE_NOTHROW (gfor_fndecl_size1
) = 1;
3329 gfor_fndecl_iargc
= gfc_build_library_function_decl (
3330 get_identifier (PREFIX ("iargc")), gfc_int4_type_node
, 0);
3331 TREE_NOTHROW (gfor_fndecl_iargc
) = 1;
3335 /* Make prototypes for runtime library functions. */
3338 gfc_build_builtin_function_decls (void)
3340 tree gfc_int4_type_node
= gfc_get_int_type (4);
3342 gfor_fndecl_stop_numeric
= gfc_build_library_function_decl (
3343 get_identifier (PREFIX("stop_numeric")),
3344 void_type_node
, 1, gfc_int4_type_node
);
3345 /* STOP doesn't return. */
3346 TREE_THIS_VOLATILE (gfor_fndecl_stop_numeric
) = 1;
3348 gfor_fndecl_stop_numeric_f08
= gfc_build_library_function_decl (
3349 get_identifier (PREFIX("stop_numeric_f08")),
3350 void_type_node
, 1, gfc_int4_type_node
);
3351 /* STOP doesn't return. */
3352 TREE_THIS_VOLATILE (gfor_fndecl_stop_numeric_f08
) = 1;
3354 gfor_fndecl_stop_string
= gfc_build_library_function_decl_with_spec (
3355 get_identifier (PREFIX("stop_string")), ".R.",
3356 void_type_node
, 2, pchar_type_node
, gfc_int4_type_node
);
3357 /* STOP doesn't return. */
3358 TREE_THIS_VOLATILE (gfor_fndecl_stop_string
) = 1;
3360 gfor_fndecl_error_stop_numeric
= gfc_build_library_function_decl (
3361 get_identifier (PREFIX("error_stop_numeric")),
3362 void_type_node
, 1, gfc_int4_type_node
);
3363 /* ERROR STOP doesn't return. */
3364 TREE_THIS_VOLATILE (gfor_fndecl_error_stop_numeric
) = 1;
3366 gfor_fndecl_error_stop_string
= gfc_build_library_function_decl_with_spec (
3367 get_identifier (PREFIX("error_stop_string")), ".R.",
3368 void_type_node
, 2, pchar_type_node
, gfc_int4_type_node
);
3369 /* ERROR STOP doesn't return. */
3370 TREE_THIS_VOLATILE (gfor_fndecl_error_stop_string
) = 1;
3372 gfor_fndecl_pause_numeric
= gfc_build_library_function_decl (
3373 get_identifier (PREFIX("pause_numeric")),
3374 void_type_node
, 1, gfc_int4_type_node
);
3376 gfor_fndecl_pause_string
= gfc_build_library_function_decl_with_spec (
3377 get_identifier (PREFIX("pause_string")), ".R.",
3378 void_type_node
, 2, pchar_type_node
, gfc_int4_type_node
);
3380 gfor_fndecl_runtime_error
= gfc_build_library_function_decl_with_spec (
3381 get_identifier (PREFIX("runtime_error")), ".R",
3382 void_type_node
, -1, pchar_type_node
);
3383 /* The runtime_error function does not return. */
3384 TREE_THIS_VOLATILE (gfor_fndecl_runtime_error
) = 1;
3386 gfor_fndecl_runtime_error_at
= gfc_build_library_function_decl_with_spec (
3387 get_identifier (PREFIX("runtime_error_at")), ".RR",
3388 void_type_node
, -2, pchar_type_node
, pchar_type_node
);
3389 /* The runtime_error_at function does not return. */
3390 TREE_THIS_VOLATILE (gfor_fndecl_runtime_error_at
) = 1;
3392 gfor_fndecl_runtime_warning_at
= gfc_build_library_function_decl_with_spec (
3393 get_identifier (PREFIX("runtime_warning_at")), ".RR",
3394 void_type_node
, -2, pchar_type_node
, pchar_type_node
);
3396 gfor_fndecl_generate_error
= gfc_build_library_function_decl_with_spec (
3397 get_identifier (PREFIX("generate_error")), ".R.R",
3398 void_type_node
, 3, pvoid_type_node
, integer_type_node
,
3401 gfor_fndecl_os_error
= gfc_build_library_function_decl_with_spec (
3402 get_identifier (PREFIX("os_error")), ".R",
3403 void_type_node
, 1, pchar_type_node
);
3404 /* The runtime_error function does not return. */
3405 TREE_THIS_VOLATILE (gfor_fndecl_os_error
) = 1;
3407 gfor_fndecl_set_args
= gfc_build_library_function_decl (
3408 get_identifier (PREFIX("set_args")),
3409 void_type_node
, 2, integer_type_node
,
3410 build_pointer_type (pchar_type_node
));
3412 gfor_fndecl_set_fpe
= gfc_build_library_function_decl (
3413 get_identifier (PREFIX("set_fpe")),
3414 void_type_node
, 1, integer_type_node
);
3416 gfor_fndecl_ieee_procedure_entry
= gfc_build_library_function_decl (
3417 get_identifier (PREFIX("ieee_procedure_entry")),
3418 void_type_node
, 1, pvoid_type_node
);
3420 gfor_fndecl_ieee_procedure_exit
= gfc_build_library_function_decl (
3421 get_identifier (PREFIX("ieee_procedure_exit")),
3422 void_type_node
, 1, pvoid_type_node
);
3424 /* Keep the array dimension in sync with the call, later in this file. */
3425 gfor_fndecl_set_options
= gfc_build_library_function_decl_with_spec (
3426 get_identifier (PREFIX("set_options")), "..R",
3427 void_type_node
, 2, integer_type_node
,
3428 build_pointer_type (integer_type_node
));
3430 gfor_fndecl_set_convert
= gfc_build_library_function_decl (
3431 get_identifier (PREFIX("set_convert")),
3432 void_type_node
, 1, integer_type_node
);
3434 gfor_fndecl_set_record_marker
= gfc_build_library_function_decl (
3435 get_identifier (PREFIX("set_record_marker")),
3436 void_type_node
, 1, integer_type_node
);
3438 gfor_fndecl_set_max_subrecord_length
= gfc_build_library_function_decl (
3439 get_identifier (PREFIX("set_max_subrecord_length")),
3440 void_type_node
, 1, integer_type_node
);
3442 gfor_fndecl_in_pack
= gfc_build_library_function_decl_with_spec (
3443 get_identifier (PREFIX("internal_pack")), ".r",
3444 pvoid_type_node
, 1, pvoid_type_node
);
3446 gfor_fndecl_in_unpack
= gfc_build_library_function_decl_with_spec (
3447 get_identifier (PREFIX("internal_unpack")), ".wR",
3448 void_type_node
, 2, pvoid_type_node
, pvoid_type_node
);
3450 gfor_fndecl_associated
= gfc_build_library_function_decl_with_spec (
3451 get_identifier (PREFIX("associated")), ".RR",
3452 integer_type_node
, 2, ppvoid_type_node
, ppvoid_type_node
);
3453 DECL_PURE_P (gfor_fndecl_associated
) = 1;
3454 TREE_NOTHROW (gfor_fndecl_associated
) = 1;
3456 /* Coarray library calls. */
3457 if (flag_coarray
== GFC_FCOARRAY_LIB
)
3459 tree pint_type
, pppchar_type
;
3461 pint_type
= build_pointer_type (integer_type_node
);
3463 = build_pointer_type (build_pointer_type (pchar_type_node
));
3465 gfor_fndecl_caf_init
= gfc_build_library_function_decl (
3466 get_identifier (PREFIX("caf_init")), void_type_node
,
3467 2, pint_type
, pppchar_type
);
3469 gfor_fndecl_caf_finalize
= gfc_build_library_function_decl (
3470 get_identifier (PREFIX("caf_finalize")), void_type_node
, 0);
3472 gfor_fndecl_caf_this_image
= gfc_build_library_function_decl (
3473 get_identifier (PREFIX("caf_this_image")), integer_type_node
,
3474 1, integer_type_node
);
3476 gfor_fndecl_caf_num_images
= gfc_build_library_function_decl (
3477 get_identifier (PREFIX("caf_num_images")), integer_type_node
,
3478 2, integer_type_node
, integer_type_node
);
3480 gfor_fndecl_caf_register
= gfc_build_library_function_decl_with_spec (
3481 get_identifier (PREFIX("caf_register")), "...WWW", pvoid_type_node
, 6,
3482 size_type_node
, integer_type_node
, ppvoid_type_node
, pint_type
,
3483 pchar_type_node
, integer_type_node
);
3485 gfor_fndecl_caf_deregister
= gfc_build_library_function_decl_with_spec (
3486 get_identifier (PREFIX("caf_deregister")), ".WWW", void_type_node
, 4,
3487 ppvoid_type_node
, pint_type
, pchar_type_node
, integer_type_node
);
3489 gfor_fndecl_caf_get
= gfc_build_library_function_decl_with_spec (
3490 get_identifier (PREFIX("caf_get")), ".R.RRRW", void_type_node
, 9,
3491 pvoid_type_node
, size_type_node
, integer_type_node
, pvoid_type_node
,
3492 pvoid_type_node
, pvoid_type_node
, integer_type_node
, integer_type_node
,
3495 gfor_fndecl_caf_send
= gfc_build_library_function_decl_with_spec (
3496 get_identifier (PREFIX("caf_send")), ".R.RRRR", void_type_node
, 9,
3497 pvoid_type_node
, size_type_node
, integer_type_node
, pvoid_type_node
,
3498 pvoid_type_node
, pvoid_type_node
, integer_type_node
, integer_type_node
,
3501 gfor_fndecl_caf_sendget
= gfc_build_library_function_decl_with_spec (
3502 get_identifier (PREFIX("caf_sendget")), ".R.RRRR.RRR", void_type_node
,
3503 13, pvoid_type_node
, size_type_node
, integer_type_node
, pvoid_type_node
,
3504 pvoid_type_node
, pvoid_type_node
, size_type_node
, integer_type_node
,
3505 pvoid_type_node
, pvoid_type_node
, integer_type_node
, integer_type_node
,
3508 gfor_fndecl_caf_sync_all
= gfc_build_library_function_decl_with_spec (
3509 get_identifier (PREFIX("caf_sync_all")), ".WW", void_type_node
,
3510 3, pint_type
, pchar_type_node
, integer_type_node
);
3512 gfor_fndecl_caf_sync_memory
= gfc_build_library_function_decl_with_spec (
3513 get_identifier (PREFIX("caf_sync_memory")), ".WW", void_type_node
,
3514 3, pint_type
, pchar_type_node
, integer_type_node
);
3516 gfor_fndecl_caf_sync_images
= gfc_build_library_function_decl_with_spec (
3517 get_identifier (PREFIX("caf_sync_images")), ".RRWW", void_type_node
,
3518 5, integer_type_node
, pint_type
, pint_type
,
3519 pchar_type_node
, integer_type_node
);
3521 gfor_fndecl_caf_error_stop
= gfc_build_library_function_decl (
3522 get_identifier (PREFIX("caf_error_stop")),
3523 void_type_node
, 1, gfc_int4_type_node
);
3524 /* CAF's ERROR STOP doesn't return. */
3525 TREE_THIS_VOLATILE (gfor_fndecl_caf_error_stop
) = 1;
3527 gfor_fndecl_caf_error_stop_str
= gfc_build_library_function_decl_with_spec (
3528 get_identifier (PREFIX("caf_error_stop_str")), ".R.",
3529 void_type_node
, 2, pchar_type_node
, gfc_int4_type_node
);
3530 /* CAF's ERROR STOP doesn't return. */
3531 TREE_THIS_VOLATILE (gfor_fndecl_caf_error_stop_str
) = 1;
3533 gfor_fndecl_caf_atomic_def
= gfc_build_library_function_decl_with_spec (
3534 get_identifier (PREFIX("caf_atomic_define")), "R..RW",
3535 void_type_node
, 7, pvoid_type_node
, size_type_node
, integer_type_node
,
3536 pvoid_type_node
, pint_type
, integer_type_node
, integer_type_node
);
3538 gfor_fndecl_caf_atomic_ref
= gfc_build_library_function_decl_with_spec (
3539 get_identifier (PREFIX("caf_atomic_ref")), "R..WW",
3540 void_type_node
, 7, pvoid_type_node
, size_type_node
, integer_type_node
,
3541 pvoid_type_node
, pint_type
, integer_type_node
, integer_type_node
);
3543 gfor_fndecl_caf_atomic_cas
= gfc_build_library_function_decl_with_spec (
3544 get_identifier (PREFIX("caf_atomic_cas")), "R..WRRW",
3545 void_type_node
, 9, pvoid_type_node
, size_type_node
, integer_type_node
,
3546 pvoid_type_node
, pvoid_type_node
, pvoid_type_node
, pint_type
,
3547 integer_type_node
, integer_type_node
);
3549 gfor_fndecl_caf_atomic_op
= gfc_build_library_function_decl_with_spec (
3550 get_identifier (PREFIX("caf_atomic_op")), ".R..RWW",
3551 void_type_node
, 9, integer_type_node
, pvoid_type_node
, size_type_node
,
3552 integer_type_node
, pvoid_type_node
, pvoid_type_node
, pint_type
,
3553 integer_type_node
, integer_type_node
);
3555 gfor_fndecl_caf_lock
= gfc_build_library_function_decl_with_spec (
3556 get_identifier (PREFIX("caf_lock")), "R..WWW",
3557 void_type_node
, 7, pvoid_type_node
, size_type_node
, integer_type_node
,
3558 pint_type
, pint_type
, pchar_type_node
, integer_type_node
);
3560 gfor_fndecl_caf_unlock
= gfc_build_library_function_decl_with_spec (
3561 get_identifier (PREFIX("caf_unlock")), "R..WW",
3562 void_type_node
, 6, pvoid_type_node
, size_type_node
, integer_type_node
,
3563 pint_type
, pchar_type_node
, integer_type_node
);
3565 gfor_fndecl_caf_event_post
= gfc_build_library_function_decl_with_spec (
3566 get_identifier (PREFIX("caf_event_post")), "R..WW",
3567 void_type_node
, 6, pvoid_type_node
, size_type_node
, integer_type_node
,
3568 pint_type
, pchar_type_node
, integer_type_node
);
3570 gfor_fndecl_caf_event_wait
= gfc_build_library_function_decl_with_spec (
3571 get_identifier (PREFIX("caf_event_wait")), "R..WW",
3572 void_type_node
, 6, pvoid_type_node
, size_type_node
, integer_type_node
,
3573 pint_type
, pchar_type_node
, integer_type_node
);
3575 gfor_fndecl_caf_event_query
= gfc_build_library_function_decl_with_spec (
3576 get_identifier (PREFIX("caf_event_query")), "R..WW",
3577 void_type_node
, 5, pvoid_type_node
, size_type_node
, integer_type_node
,
3578 pint_type
, pint_type
);
3580 gfor_fndecl_co_broadcast
= gfc_build_library_function_decl_with_spec (
3581 get_identifier (PREFIX("caf_co_broadcast")), "W.WW",
3582 void_type_node
, 5, pvoid_type_node
, integer_type_node
,
3583 pint_type
, pchar_type_node
, integer_type_node
);
3585 gfor_fndecl_co_max
= gfc_build_library_function_decl_with_spec (
3586 get_identifier (PREFIX("caf_co_max")), "W.WW",
3587 void_type_node
, 6, pvoid_type_node
, integer_type_node
,
3588 pint_type
, pchar_type_node
, integer_type_node
, integer_type_node
);
3590 gfor_fndecl_co_min
= gfc_build_library_function_decl_with_spec (
3591 get_identifier (PREFIX("caf_co_min")), "W.WW",
3592 void_type_node
, 6, pvoid_type_node
, integer_type_node
,
3593 pint_type
, pchar_type_node
, integer_type_node
, integer_type_node
);
3595 gfor_fndecl_co_reduce
= gfc_build_library_function_decl_with_spec (
3596 get_identifier (PREFIX("caf_co_reduce")), "W.R.WW",
3597 void_type_node
, 8, pvoid_type_node
,
3598 build_pointer_type (build_varargs_function_type_list (void_type_node
,
3600 integer_type_node
, integer_type_node
, pint_type
, pchar_type_node
,
3601 integer_type_node
, integer_type_node
);
3603 gfor_fndecl_co_sum
= gfc_build_library_function_decl_with_spec (
3604 get_identifier (PREFIX("caf_co_sum")), "W.WW",
3605 void_type_node
, 5, pvoid_type_node
, integer_type_node
,
3606 pint_type
, pchar_type_node
, integer_type_node
);
3609 gfc_build_intrinsic_function_decls ();
3610 gfc_build_intrinsic_lib_fndecls ();
3611 gfc_build_io_library_fndecls ();
3615 /* Evaluate the length of dummy character variables. */
3618 gfc_trans_dummy_character (gfc_symbol
*sym
, gfc_charlen
*cl
,
3619 gfc_wrapped_block
*block
)
3623 gfc_finish_decl (cl
->backend_decl
);
3625 gfc_start_block (&init
);
3627 /* Evaluate the string length expression. */
3628 gfc_conv_string_length (cl
, NULL
, &init
);
3630 gfc_trans_vla_type_sizes (sym
, &init
);
3632 gfc_add_init_cleanup (block
, gfc_finish_block (&init
), NULL_TREE
);
3636 /* Allocate and cleanup an automatic character variable. */
3639 gfc_trans_auto_character_variable (gfc_symbol
* sym
, gfc_wrapped_block
* block
)
3645 gcc_assert (sym
->backend_decl
);
3646 gcc_assert (sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
);
3648 gfc_init_block (&init
);
3650 /* Evaluate the string length expression. */
3651 gfc_conv_string_length (sym
->ts
.u
.cl
, NULL
, &init
);
3653 gfc_trans_vla_type_sizes (sym
, &init
);
3655 decl
= sym
->backend_decl
;
3657 /* Emit a DECL_EXPR for this variable, which will cause the
3658 gimplifier to allocate storage, and all that good stuff. */
3659 tmp
= fold_build1_loc (input_location
, DECL_EXPR
, TREE_TYPE (decl
), decl
);
3660 gfc_add_expr_to_block (&init
, tmp
);
3662 gfc_add_init_cleanup (block
, gfc_finish_block (&init
), NULL_TREE
);
3665 /* Set the initial value of ASSIGN statement auxiliary variable explicitly. */
3668 gfc_trans_assign_aux_var (gfc_symbol
* sym
, gfc_wrapped_block
* block
)
3672 gcc_assert (sym
->backend_decl
);
3673 gfc_start_block (&init
);
3675 /* Set the initial value to length. See the comments in
3676 function gfc_add_assign_aux_vars in this file. */
3677 gfc_add_modify (&init
, GFC_DECL_STRING_LEN (sym
->backend_decl
),
3678 build_int_cst (gfc_charlen_type_node
, -2));
3680 gfc_add_init_cleanup (block
, gfc_finish_block (&init
), NULL_TREE
);
3684 gfc_trans_vla_one_sizepos (tree
*tp
, stmtblock_t
*body
)
3686 tree t
= *tp
, var
, val
;
3688 if (t
== NULL
|| t
== error_mark_node
)
3690 if (TREE_CONSTANT (t
) || DECL_P (t
))
3693 if (TREE_CODE (t
) == SAVE_EXPR
)
3695 if (SAVE_EXPR_RESOLVED_P (t
))
3697 *tp
= TREE_OPERAND (t
, 0);
3700 val
= TREE_OPERAND (t
, 0);
3705 var
= gfc_create_var_np (TREE_TYPE (t
), NULL
);
3706 gfc_add_decl_to_function (var
);
3707 gfc_add_modify (body
, var
, val
);
3708 if (TREE_CODE (t
) == SAVE_EXPR
)
3709 TREE_OPERAND (t
, 0) = var
;
3714 gfc_trans_vla_type_sizes_1 (tree type
, stmtblock_t
*body
)
3718 if (type
== NULL
|| type
== error_mark_node
)
3721 type
= TYPE_MAIN_VARIANT (type
);
3723 if (TREE_CODE (type
) == INTEGER_TYPE
)
3725 gfc_trans_vla_one_sizepos (&TYPE_MIN_VALUE (type
), body
);
3726 gfc_trans_vla_one_sizepos (&TYPE_MAX_VALUE (type
), body
);
3728 for (t
= TYPE_NEXT_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
3730 TYPE_MIN_VALUE (t
) = TYPE_MIN_VALUE (type
);
3731 TYPE_MAX_VALUE (t
) = TYPE_MAX_VALUE (type
);
3734 else if (TREE_CODE (type
) == ARRAY_TYPE
)
3736 gfc_trans_vla_type_sizes_1 (TREE_TYPE (type
), body
);
3737 gfc_trans_vla_type_sizes_1 (TYPE_DOMAIN (type
), body
);
3738 gfc_trans_vla_one_sizepos (&TYPE_SIZE (type
), body
);
3739 gfc_trans_vla_one_sizepos (&TYPE_SIZE_UNIT (type
), body
);
3741 for (t
= TYPE_NEXT_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
3743 TYPE_SIZE (t
) = TYPE_SIZE (type
);
3744 TYPE_SIZE_UNIT (t
) = TYPE_SIZE_UNIT (type
);
3749 /* Make sure all type sizes and array domains are either constant,
3750 or variable or parameter decls. This is a simplified variant
3751 of gimplify_type_sizes, but we can't use it here, as none of the
3752 variables in the expressions have been gimplified yet.
3753 As type sizes and domains for various variable length arrays
3754 contain VAR_DECLs that are only initialized at gfc_trans_deferred_vars
3755 time, without this routine gimplify_type_sizes in the middle-end
3756 could result in the type sizes being gimplified earlier than where
3757 those variables are initialized. */
3760 gfc_trans_vla_type_sizes (gfc_symbol
*sym
, stmtblock_t
*body
)
3762 tree type
= TREE_TYPE (sym
->backend_decl
);
3764 if (TREE_CODE (type
) == FUNCTION_TYPE
3765 && (sym
->attr
.function
|| sym
->attr
.result
|| sym
->attr
.entry
))
3767 if (! current_fake_result_decl
)
3770 type
= TREE_TYPE (TREE_VALUE (current_fake_result_decl
));
3773 while (POINTER_TYPE_P (type
))
3774 type
= TREE_TYPE (type
);
3776 if (GFC_DESCRIPTOR_TYPE_P (type
))
3778 tree etype
= GFC_TYPE_ARRAY_DATAPTR_TYPE (type
);
3780 while (POINTER_TYPE_P (etype
))
3781 etype
= TREE_TYPE (etype
);
3783 gfc_trans_vla_type_sizes_1 (etype
, body
);
3786 gfc_trans_vla_type_sizes_1 (type
, body
);
3790 /* Initialize a derived type by building an lvalue from the symbol
3791 and using trans_assignment to do the work. Set dealloc to false
3792 if no deallocation prior the assignment is needed. */
3794 gfc_init_default_dt (gfc_symbol
* sym
, stmtblock_t
* block
, bool dealloc
)
3802 gcc_assert (!sym
->attr
.allocatable
);
3803 gfc_set_sym_referenced (sym
);
3804 e
= gfc_lval_expr_from_sym (sym
);
3805 tmp
= gfc_trans_assignment (e
, sym
->value
, false, dealloc
);
3806 if (sym
->attr
.dummy
&& (sym
->attr
.optional
3807 || sym
->ns
->proc_name
->attr
.entry_master
))
3809 present
= gfc_conv_expr_present (sym
);
3810 tmp
= build3_loc (input_location
, COND_EXPR
, TREE_TYPE (tmp
), present
,
3811 tmp
, build_empty_stmt (input_location
));
3813 gfc_add_expr_to_block (block
, tmp
);
3818 /* Initialize INTENT(OUT) derived type dummies. As well as giving
3819 them their default initializer, if they do not have allocatable
3820 components, they have their allocatable components deallocated. */
3823 init_intent_out_dt (gfc_symbol
* proc_sym
, gfc_wrapped_block
* block
)
3826 gfc_formal_arglist
*f
;
3830 gfc_init_block (&init
);
3831 for (f
= gfc_sym_get_dummy_args (proc_sym
); f
; f
= f
->next
)
3832 if (f
->sym
&& f
->sym
->attr
.intent
== INTENT_OUT
3833 && !f
->sym
->attr
.pointer
3834 && f
->sym
->ts
.type
== BT_DERIVED
)
3838 /* Note: Allocatables are excluded as they are already handled
3840 if (!f
->sym
->attr
.allocatable
3841 && gfc_is_finalizable (f
->sym
->ts
.u
.derived
, NULL
))
3846 gfc_init_block (&block
);
3847 f
->sym
->attr
.referenced
= 1;
3848 e
= gfc_lval_expr_from_sym (f
->sym
);
3849 gfc_add_finalizer_call (&block
, e
);
3851 tmp
= gfc_finish_block (&block
);
3854 if (tmp
== NULL_TREE
&& !f
->sym
->attr
.allocatable
3855 && f
->sym
->ts
.u
.derived
->attr
.alloc_comp
&& !f
->sym
->value
)
3856 tmp
= gfc_deallocate_alloc_comp (f
->sym
->ts
.u
.derived
,
3857 f
->sym
->backend_decl
,
3858 f
->sym
->as
? f
->sym
->as
->rank
: 0);
3860 if (tmp
!= NULL_TREE
&& (f
->sym
->attr
.optional
3861 || f
->sym
->ns
->proc_name
->attr
.entry_master
))
3863 present
= gfc_conv_expr_present (f
->sym
);
3864 tmp
= build3_loc (input_location
, COND_EXPR
, TREE_TYPE (tmp
),
3865 present
, tmp
, build_empty_stmt (input_location
));
3868 if (tmp
!= NULL_TREE
)
3869 gfc_add_expr_to_block (&init
, tmp
);
3870 else if (f
->sym
->value
&& !f
->sym
->attr
.allocatable
)
3871 gfc_init_default_dt (f
->sym
, &init
, true);
3873 else if (f
->sym
&& f
->sym
->attr
.intent
== INTENT_OUT
3874 && f
->sym
->ts
.type
== BT_CLASS
3875 && !CLASS_DATA (f
->sym
)->attr
.class_pointer
3876 && !CLASS_DATA (f
->sym
)->attr
.allocatable
)
3881 gfc_init_block (&block
);
3882 f
->sym
->attr
.referenced
= 1;
3883 e
= gfc_lval_expr_from_sym (f
->sym
);
3884 gfc_add_finalizer_call (&block
, e
);
3886 tmp
= gfc_finish_block (&block
);
3888 if (f
->sym
->attr
.optional
|| f
->sym
->ns
->proc_name
->attr
.entry_master
)
3890 present
= gfc_conv_expr_present (f
->sym
);
3891 tmp
= build3_loc (input_location
, COND_EXPR
, TREE_TYPE (tmp
),
3893 build_empty_stmt (input_location
));
3896 gfc_add_expr_to_block (&init
, tmp
);
3899 gfc_add_init_cleanup (block
, gfc_finish_block (&init
), NULL_TREE
);
3903 /* Generate function entry and exit code, and add it to the function body.
3905 Allocation and initialization of array variables.
3906 Allocation of character string variables.
3907 Initialization and possibly repacking of dummy arrays.
3908 Initialization of ASSIGN statement auxiliary variable.
3909 Initialization of ASSOCIATE names.
3910 Automatic deallocation. */
3913 gfc_trans_deferred_vars (gfc_symbol
* proc_sym
, gfc_wrapped_block
* block
)
3917 gfc_formal_arglist
*f
;
3918 stmtblock_t tmpblock
;
3919 bool seen_trans_deferred_array
= false;
3925 /* Deal with implicit return variables. Explicit return variables will
3926 already have been added. */
3927 if (gfc_return_by_reference (proc_sym
) && proc_sym
->result
== proc_sym
)
3929 if (!current_fake_result_decl
)
3931 gfc_entry_list
*el
= NULL
;
3932 if (proc_sym
->attr
.entry_master
)
3934 for (el
= proc_sym
->ns
->entries
; el
; el
= el
->next
)
3935 if (el
->sym
!= el
->sym
->result
)
3938 /* TODO: move to the appropriate place in resolve.c. */
3939 if (warn_return_type
&& el
== NULL
)
3940 gfc_warning (OPT_Wreturn_type
,
3941 "Return value of function %qs at %L not set",
3942 proc_sym
->name
, &proc_sym
->declared_at
);
3944 else if (proc_sym
->as
)
3946 tree result
= TREE_VALUE (current_fake_result_decl
);
3947 gfc_trans_dummy_array_bias (proc_sym
, result
, block
);
3949 /* An automatic character length, pointer array result. */
3950 if (proc_sym
->ts
.type
== BT_CHARACTER
3951 && TREE_CODE (proc_sym
->ts
.u
.cl
->backend_decl
) == VAR_DECL
)
3952 gfc_trans_dummy_character (proc_sym
, proc_sym
->ts
.u
.cl
, block
);
3954 else if (proc_sym
->ts
.type
== BT_CHARACTER
)
3956 if (proc_sym
->ts
.deferred
)
3959 gfc_save_backend_locus (&loc
);
3960 gfc_set_backend_locus (&proc_sym
->declared_at
);
3961 gfc_start_block (&init
);
3962 /* Zero the string length on entry. */
3963 gfc_add_modify (&init
, proc_sym
->ts
.u
.cl
->backend_decl
,
3964 build_int_cst (gfc_charlen_type_node
, 0));
3965 /* Null the pointer. */
3966 e
= gfc_lval_expr_from_sym (proc_sym
);
3967 gfc_init_se (&se
, NULL
);
3968 se
.want_pointer
= 1;
3969 gfc_conv_expr (&se
, e
);
3972 gfc_add_modify (&init
, tmp
,
3973 fold_convert (TREE_TYPE (se
.expr
),
3974 null_pointer_node
));
3975 gfc_restore_backend_locus (&loc
);
3977 /* Pass back the string length on exit. */
3978 tmp
= proc_sym
->ts
.u
.cl
->passed_length
;
3979 tmp
= build_fold_indirect_ref_loc (input_location
, tmp
);
3980 tmp
= fold_convert (gfc_charlen_type_node
, tmp
);
3981 tmp
= fold_build2_loc (input_location
, MODIFY_EXPR
,
3982 gfc_charlen_type_node
, tmp
,
3983 proc_sym
->ts
.u
.cl
->backend_decl
);
3984 gfc_add_init_cleanup (block
, gfc_finish_block (&init
), tmp
);
3986 else if (TREE_CODE (proc_sym
->ts
.u
.cl
->backend_decl
) == VAR_DECL
)
3987 gfc_trans_dummy_character (proc_sym
, proc_sym
->ts
.u
.cl
, block
);
3990 gcc_assert (flag_f2c
&& proc_sym
->ts
.type
== BT_COMPLEX
);
3993 /* Initialize the INTENT(OUT) derived type dummy arguments. This
3994 should be done here so that the offsets and lbounds of arrays
3996 gfc_save_backend_locus (&loc
);
3997 gfc_set_backend_locus (&proc_sym
->declared_at
);
3998 init_intent_out_dt (proc_sym
, block
);
3999 gfc_restore_backend_locus (&loc
);
4001 for (sym
= proc_sym
->tlink
; sym
!= proc_sym
; sym
= sym
->tlink
)
4003 bool alloc_comp_or_fini
= (sym
->ts
.type
== BT_DERIVED
)
4004 && (sym
->ts
.u
.derived
->attr
.alloc_comp
4005 || gfc_is_finalizable (sym
->ts
.u
.derived
,
4010 if (sym
->attr
.subref_array_pointer
4011 && GFC_DECL_SPAN (sym
->backend_decl
)
4012 && !TREE_STATIC (GFC_DECL_SPAN (sym
->backend_decl
)))
4014 gfc_init_block (&tmpblock
);
4015 gfc_add_modify (&tmpblock
, GFC_DECL_SPAN (sym
->backend_decl
),
4016 build_int_cst (gfc_array_index_type
, 0));
4017 gfc_add_init_cleanup (block
, gfc_finish_block (&tmpblock
),
4021 if (sym
->ts
.type
== BT_CLASS
4022 && (sym
->attr
.save
|| flag_max_stack_var_size
== 0)
4023 && CLASS_DATA (sym
)->attr
.allocatable
)
4027 if (UNLIMITED_POLY (sym
))
4028 vptr
= null_pointer_node
;
4032 vsym
= gfc_find_derived_vtab (sym
->ts
.u
.derived
);
4033 vptr
= gfc_get_symbol_decl (vsym
);
4034 vptr
= gfc_build_addr_expr (NULL
, vptr
);
4037 if (CLASS_DATA (sym
)->attr
.dimension
4038 || (CLASS_DATA (sym
)->attr
.codimension
4039 && flag_coarray
!= GFC_FCOARRAY_LIB
))
4041 tmp
= gfc_class_data_get (sym
->backend_decl
);
4042 tmp
= gfc_build_null_descriptor (TREE_TYPE (tmp
));
4045 tmp
= null_pointer_node
;
4047 DECL_INITIAL (sym
->backend_decl
)
4048 = gfc_class_set_static_fields (sym
->backend_decl
, vptr
, tmp
);
4049 TREE_CONSTANT (DECL_INITIAL (sym
->backend_decl
)) = 1;
4051 else if (sym
->attr
.dimension
|| sym
->attr
.codimension
4052 || (IS_CLASS_ARRAY (sym
) && !CLASS_DATA (sym
)->attr
.allocatable
))
4054 bool is_classarray
= IS_CLASS_ARRAY (sym
);
4055 symbol_attribute
*array_attr
;
4059 array_attr
= is_classarray
? &CLASS_DATA (sym
)->attr
: &sym
->attr
;
4060 as
= is_classarray
? CLASS_DATA (sym
)->as
: sym
->as
;
4061 /* Assumed-size Cray pointees need to be treated as AS_EXPLICIT. */
4063 if (tmp
== AS_ASSUMED_SIZE
&& as
->cp_was_assumed
)
4068 if (sym
->attr
.dummy
|| sym
->attr
.result
)
4069 gfc_trans_dummy_array_bias (sym
, sym
->backend_decl
, block
);
4070 /* Allocatable and pointer arrays need to processed
4072 else if ((sym
->ts
.type
!= BT_CLASS
&& sym
->attr
.pointer
)
4073 || (sym
->ts
.type
== BT_CLASS
4074 && CLASS_DATA (sym
)->attr
.class_pointer
)
4075 || array_attr
->allocatable
)
4077 if (TREE_STATIC (sym
->backend_decl
))
4079 gfc_save_backend_locus (&loc
);
4080 gfc_set_backend_locus (&sym
->declared_at
);
4081 gfc_trans_static_array_pointer (sym
);
4082 gfc_restore_backend_locus (&loc
);
4086 seen_trans_deferred_array
= true;
4087 gfc_trans_deferred_array (sym
, block
);
4090 else if (sym
->attr
.codimension
4091 && TREE_STATIC (sym
->backend_decl
))
4093 gfc_init_block (&tmpblock
);
4094 gfc_trans_array_cobounds (TREE_TYPE (sym
->backend_decl
),
4096 gfc_add_init_cleanup (block
, gfc_finish_block (&tmpblock
),
4102 gfc_save_backend_locus (&loc
);
4103 gfc_set_backend_locus (&sym
->declared_at
);
4105 if (alloc_comp_or_fini
)
4107 seen_trans_deferred_array
= true;
4108 gfc_trans_deferred_array (sym
, block
);
4110 else if (sym
->ts
.type
== BT_DERIVED
4113 && sym
->attr
.save
== SAVE_NONE
)
4115 gfc_start_block (&tmpblock
);
4116 gfc_init_default_dt (sym
, &tmpblock
, false);
4117 gfc_add_init_cleanup (block
,
4118 gfc_finish_block (&tmpblock
),
4122 gfc_trans_auto_array_allocation (sym
->backend_decl
,
4124 gfc_restore_backend_locus (&loc
);
4128 case AS_ASSUMED_SIZE
:
4129 /* Must be a dummy parameter. */
4130 gcc_assert (sym
->attr
.dummy
|| as
->cp_was_assumed
);
4132 /* We should always pass assumed size arrays the g77 way. */
4133 if (sym
->attr
.dummy
)
4134 gfc_trans_g77_array (sym
, block
);
4137 case AS_ASSUMED_SHAPE
:
4138 /* Must be a dummy parameter. */
4139 gcc_assert (sym
->attr
.dummy
);
4141 gfc_trans_dummy_array_bias (sym
, sym
->backend_decl
, block
);
4144 case AS_ASSUMED_RANK
:
4146 seen_trans_deferred_array
= true;
4147 gfc_trans_deferred_array (sym
, block
);
4153 if (alloc_comp_or_fini
&& !seen_trans_deferred_array
)
4154 gfc_trans_deferred_array (sym
, block
);
4156 else if ((!sym
->attr
.dummy
|| sym
->ts
.deferred
)
4157 && (sym
->ts
.type
== BT_CLASS
4158 && CLASS_DATA (sym
)->attr
.class_pointer
))
4160 else if ((!sym
->attr
.dummy
|| sym
->ts
.deferred
)
4161 && (sym
->attr
.allocatable
4162 || (sym
->ts
.type
== BT_CLASS
4163 && CLASS_DATA (sym
)->attr
.allocatable
)))
4165 if (!sym
->attr
.save
&& flag_max_stack_var_size
!= 0)
4167 tree descriptor
= NULL_TREE
;
4169 /* Nullify and automatic deallocation of allocatable
4171 e
= gfc_lval_expr_from_sym (sym
);
4172 if (sym
->ts
.type
== BT_CLASS
)
4173 gfc_add_data_component (e
);
4175 gfc_init_se (&se
, NULL
);
4176 if (sym
->ts
.type
!= BT_CLASS
4177 || sym
->ts
.u
.derived
->attr
.dimension
4178 || sym
->ts
.u
.derived
->attr
.codimension
)
4180 se
.want_pointer
= 1;
4181 gfc_conv_expr (&se
, e
);
4183 else if (sym
->ts
.type
== BT_CLASS
4184 && !CLASS_DATA (sym
)->attr
.dimension
4185 && !CLASS_DATA (sym
)->attr
.codimension
)
4187 se
.want_pointer
= 1;
4188 gfc_conv_expr (&se
, e
);
4192 se
.descriptor_only
= 1;
4193 gfc_conv_expr (&se
, e
);
4194 descriptor
= se
.expr
;
4195 se
.expr
= gfc_conv_descriptor_data_addr (se
.expr
);
4196 se
.expr
= build_fold_indirect_ref_loc (input_location
, se
.expr
);
4200 gfc_save_backend_locus (&loc
);
4201 gfc_set_backend_locus (&sym
->declared_at
);
4202 gfc_start_block (&init
);
4204 if (!sym
->attr
.dummy
|| sym
->attr
.intent
== INTENT_OUT
)
4206 /* Nullify when entering the scope. */
4207 tmp
= fold_build2_loc (input_location
, MODIFY_EXPR
,
4208 TREE_TYPE (se
.expr
), se
.expr
,
4209 fold_convert (TREE_TYPE (se
.expr
),
4210 null_pointer_node
));
4211 if (sym
->attr
.optional
)
4213 tree present
= gfc_conv_expr_present (sym
);
4214 tmp
= build3_loc (input_location
, COND_EXPR
,
4215 void_type_node
, present
, tmp
,
4216 build_empty_stmt (input_location
));
4218 gfc_add_expr_to_block (&init
, tmp
);
4221 if ((sym
->attr
.dummy
|| sym
->attr
.result
)
4222 && sym
->ts
.type
== BT_CHARACTER
4223 && sym
->ts
.deferred
)
4225 /* Character length passed by reference. */
4226 tmp
= sym
->ts
.u
.cl
->passed_length
;
4227 tmp
= build_fold_indirect_ref_loc (input_location
, tmp
);
4228 tmp
= fold_convert (gfc_charlen_type_node
, tmp
);
4230 if (!sym
->attr
.dummy
|| sym
->attr
.intent
== INTENT_OUT
)
4231 /* Zero the string length when entering the scope. */
4232 gfc_add_modify (&init
, sym
->ts
.u
.cl
->backend_decl
,
4233 build_int_cst (gfc_charlen_type_node
, 0));
4238 tmp2
= fold_build2_loc (input_location
, MODIFY_EXPR
,
4239 gfc_charlen_type_node
,
4240 sym
->ts
.u
.cl
->backend_decl
, tmp
);
4241 if (sym
->attr
.optional
)
4243 tree present
= gfc_conv_expr_present (sym
);
4244 tmp2
= build3_loc (input_location
, COND_EXPR
,
4245 void_type_node
, present
, tmp2
,
4246 build_empty_stmt (input_location
));
4248 gfc_add_expr_to_block (&init
, tmp2
);
4251 gfc_restore_backend_locus (&loc
);
4253 /* Pass the final character length back. */
4254 if (sym
->attr
.intent
!= INTENT_IN
)
4256 tmp
= fold_build2_loc (input_location
, MODIFY_EXPR
,
4257 gfc_charlen_type_node
, tmp
,
4258 sym
->ts
.u
.cl
->backend_decl
);
4259 if (sym
->attr
.optional
)
4261 tree present
= gfc_conv_expr_present (sym
);
4262 tmp
= build3_loc (input_location
, COND_EXPR
,
4263 void_type_node
, present
, tmp
,
4264 build_empty_stmt (input_location
));
4271 gfc_restore_backend_locus (&loc
);
4273 /* Deallocate when leaving the scope. Nullifying is not
4275 if (!sym
->attr
.result
&& !sym
->attr
.dummy
4276 && !sym
->ns
->proc_name
->attr
.is_main_program
)
4278 if (sym
->ts
.type
== BT_CLASS
4279 && CLASS_DATA (sym
)->attr
.codimension
)
4280 tmp
= gfc_deallocate_with_status (descriptor
, NULL_TREE
,
4281 NULL_TREE
, NULL_TREE
,
4282 NULL_TREE
, true, NULL
,
4286 gfc_expr
*expr
= gfc_lval_expr_from_sym (sym
);
4287 tmp
= gfc_deallocate_scalar_with_status (se
.expr
, NULL_TREE
,
4288 true, expr
, sym
->ts
);
4289 gfc_free_expr (expr
);
4292 if (sym
->ts
.type
== BT_CLASS
)
4294 /* Initialize _vptr to declared type. */
4298 gfc_save_backend_locus (&loc
);
4299 gfc_set_backend_locus (&sym
->declared_at
);
4300 e
= gfc_lval_expr_from_sym (sym
);
4301 gfc_add_vptr_component (e
);
4302 gfc_init_se (&se
, NULL
);
4303 se
.want_pointer
= 1;
4304 gfc_conv_expr (&se
, e
);
4306 if (UNLIMITED_POLY (sym
))
4307 rhs
= build_int_cst (TREE_TYPE (se
.expr
), 0);
4310 vtab
= gfc_find_derived_vtab (sym
->ts
.u
.derived
);
4311 rhs
= gfc_build_addr_expr (TREE_TYPE (se
.expr
),
4312 gfc_get_symbol_decl (vtab
));
4314 gfc_add_modify (&init
, se
.expr
, rhs
);
4315 gfc_restore_backend_locus (&loc
);
4318 gfc_add_init_cleanup (block
, gfc_finish_block (&init
), tmp
);
4321 else if (sym
->ts
.type
== BT_CHARACTER
&& sym
->ts
.deferred
)
4326 /* If we get to here, all that should be left are pointers. */
4327 gcc_assert (sym
->attr
.pointer
);
4329 if (sym
->attr
.dummy
)
4331 gfc_start_block (&init
);
4333 /* Character length passed by reference. */
4334 tmp
= sym
->ts
.u
.cl
->passed_length
;
4335 tmp
= build_fold_indirect_ref_loc (input_location
, tmp
);
4336 tmp
= fold_convert (gfc_charlen_type_node
, tmp
);
4337 gfc_add_modify (&init
, sym
->ts
.u
.cl
->backend_decl
, tmp
);
4338 /* Pass the final character length back. */
4339 if (sym
->attr
.intent
!= INTENT_IN
)
4340 tmp
= fold_build2_loc (input_location
, MODIFY_EXPR
,
4341 gfc_charlen_type_node
, tmp
,
4342 sym
->ts
.u
.cl
->backend_decl
);
4345 gfc_add_init_cleanup (block
, gfc_finish_block (&init
), tmp
);
4348 else if (sym
->ts
.deferred
)
4349 gfc_fatal_error ("Deferred type parameter not yet supported");
4350 else if (alloc_comp_or_fini
)
4351 gfc_trans_deferred_array (sym
, block
);
4352 else if (sym
->ts
.type
== BT_CHARACTER
)
4354 gfc_save_backend_locus (&loc
);
4355 gfc_set_backend_locus (&sym
->declared_at
);
4356 if (sym
->attr
.dummy
|| sym
->attr
.result
)
4357 gfc_trans_dummy_character (sym
, sym
->ts
.u
.cl
, block
);
4359 gfc_trans_auto_character_variable (sym
, block
);
4360 gfc_restore_backend_locus (&loc
);
4362 else if (sym
->attr
.assign
)
4364 gfc_save_backend_locus (&loc
);
4365 gfc_set_backend_locus (&sym
->declared_at
);
4366 gfc_trans_assign_aux_var (sym
, block
);
4367 gfc_restore_backend_locus (&loc
);
4369 else if (sym
->ts
.type
== BT_DERIVED
4372 && sym
->attr
.save
== SAVE_NONE
)
4374 gfc_start_block (&tmpblock
);
4375 gfc_init_default_dt (sym
, &tmpblock
, false);
4376 gfc_add_init_cleanup (block
, gfc_finish_block (&tmpblock
),
4379 else if (!(UNLIMITED_POLY(sym
)))
4383 gfc_init_block (&tmpblock
);
4385 for (f
= gfc_sym_get_dummy_args (proc_sym
); f
; f
= f
->next
)
4387 if (f
->sym
&& f
->sym
->tlink
== NULL
&& f
->sym
->ts
.type
== BT_CHARACTER
)
4389 gcc_assert (f
->sym
->ts
.u
.cl
->backend_decl
!= NULL
);
4390 if (TREE_CODE (f
->sym
->ts
.u
.cl
->backend_decl
) == PARM_DECL
)
4391 gfc_trans_vla_type_sizes (f
->sym
, &tmpblock
);
4395 if (gfc_return_by_reference (proc_sym
) && proc_sym
->ts
.type
== BT_CHARACTER
4396 && current_fake_result_decl
!= NULL
)
4398 gcc_assert (proc_sym
->ts
.u
.cl
->backend_decl
!= NULL
);
4399 if (TREE_CODE (proc_sym
->ts
.u
.cl
->backend_decl
) == PARM_DECL
)
4400 gfc_trans_vla_type_sizes (proc_sym
, &tmpblock
);
4403 gfc_add_init_cleanup (block
, gfc_finish_block (&tmpblock
), NULL_TREE
);
4406 struct module_hasher
: ggc_ptr_hash
<module_htab_entry
>
4408 typedef const char *compare_type
;
4410 static hashval_t
hash (module_htab_entry
*s
) { return htab_hash_string (s
); }
4412 equal (module_htab_entry
*a
, const char *b
)
4414 return !strcmp (a
->name
, b
);
4418 static GTY (()) hash_table
<module_hasher
> *module_htab
;
4420 /* Hash and equality functions for module_htab's decls. */
4423 module_decl_hasher::hash (tree t
)
4425 const_tree n
= DECL_NAME (t
);
4427 n
= TYPE_NAME (TREE_TYPE (t
));
4428 return htab_hash_string (IDENTIFIER_POINTER (n
));
4432 module_decl_hasher::equal (tree t1
, const char *x2
)
4434 const_tree n1
= DECL_NAME (t1
);
4435 if (n1
== NULL_TREE
)
4436 n1
= TYPE_NAME (TREE_TYPE (t1
));
4437 return strcmp (IDENTIFIER_POINTER (n1
), x2
) == 0;
4440 struct module_htab_entry
*
4441 gfc_find_module (const char *name
)
4444 module_htab
= hash_table
<module_hasher
>::create_ggc (10);
4446 module_htab_entry
**slot
4447 = module_htab
->find_slot_with_hash (name
, htab_hash_string (name
), INSERT
);
4450 module_htab_entry
*entry
= ggc_cleared_alloc
<module_htab_entry
> ();
4452 entry
->name
= gfc_get_string (name
);
4453 entry
->decls
= hash_table
<module_decl_hasher
>::create_ggc (10);
4460 gfc_module_add_decl (struct module_htab_entry
*entry
, tree decl
)
4464 if (DECL_NAME (decl
))
4465 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
4468 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
4469 name
= IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl
)));
4472 = entry
->decls
->find_slot_with_hash (name
, htab_hash_string (name
),
4479 /* Generate debugging symbols for namelists. This function must come after
4480 generate_local_decl to ensure that the variables in the namelist are
4481 already declared. */
4484 generate_namelist_decl (gfc_symbol
* sym
)
4488 vec
<constructor_elt
, va_gc
> *nml_decls
= NULL
;
4490 gcc_assert (sym
->attr
.flavor
== FL_NAMELIST
);
4491 for (nml
= sym
->namelist
; nml
; nml
= nml
->next
)
4493 if (nml
->sym
->backend_decl
== NULL_TREE
)
4495 nml
->sym
->attr
.referenced
= 1;
4496 nml
->sym
->backend_decl
= gfc_get_symbol_decl (nml
->sym
);
4498 DECL_IGNORED_P (nml
->sym
->backend_decl
) = 0;
4499 CONSTRUCTOR_APPEND_ELT (nml_decls
, NULL_TREE
, nml
->sym
->backend_decl
);
4502 decl
= make_node (NAMELIST_DECL
);
4503 TREE_TYPE (decl
) = void_type_node
;
4504 NAMELIST_DECL_ASSOCIATED_DECL (decl
) = build_constructor (NULL_TREE
, nml_decls
);
4505 DECL_NAME (decl
) = get_identifier (sym
->name
);
4510 /* Output an initialized decl for a module variable. */
4513 gfc_create_module_variable (gfc_symbol
* sym
)
4517 /* Module functions with alternate entries are dealt with later and
4518 would get caught by the next condition. */
4519 if (sym
->attr
.entry
)
4522 /* Make sure we convert the types of the derived types from iso_c_binding
4524 if (sym
->attr
.flavor
!= FL_PROCEDURE
&& sym
->attr
.is_iso_c
4525 && sym
->ts
.type
== BT_DERIVED
)
4526 sym
->backend_decl
= gfc_typenode_for_spec (&(sym
->ts
));
4528 if (sym
->attr
.flavor
== FL_DERIVED
4529 && sym
->backend_decl
4530 && TREE_CODE (sym
->backend_decl
) == RECORD_TYPE
)
4532 decl
= sym
->backend_decl
;
4533 gcc_assert (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
);
4535 if (!sym
->attr
.use_assoc
&& !sym
->attr
.used_in_submodule
)
4537 gcc_assert (TYPE_CONTEXT (decl
) == NULL_TREE
4538 || TYPE_CONTEXT (decl
) == sym
->ns
->proc_name
->backend_decl
);
4539 gcc_assert (DECL_CONTEXT (TYPE_STUB_DECL (decl
)) == NULL_TREE
4540 || DECL_CONTEXT (TYPE_STUB_DECL (decl
))
4541 == sym
->ns
->proc_name
->backend_decl
);
4543 TYPE_CONTEXT (decl
) = sym
->ns
->proc_name
->backend_decl
;
4544 DECL_CONTEXT (TYPE_STUB_DECL (decl
)) = sym
->ns
->proc_name
->backend_decl
;
4545 gfc_module_add_decl (cur_module
, TYPE_STUB_DECL (decl
));
4548 /* Only output variables, procedure pointers and array valued,
4549 or derived type, parameters. */
4550 if (sym
->attr
.flavor
!= FL_VARIABLE
4551 && !(sym
->attr
.flavor
== FL_PARAMETER
4552 && (sym
->attr
.dimension
|| sym
->ts
.type
== BT_DERIVED
))
4553 && !(sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.proc_pointer
))
4556 if ((sym
->attr
.in_common
|| sym
->attr
.in_equivalence
) && sym
->backend_decl
)
4558 decl
= sym
->backend_decl
;
4559 gcc_assert (DECL_FILE_SCOPE_P (decl
));
4560 gcc_assert (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
);
4561 DECL_CONTEXT (decl
) = sym
->ns
->proc_name
->backend_decl
;
4562 gfc_module_add_decl (cur_module
, decl
);
4565 /* Don't generate variables from other modules. Variables from
4566 COMMONs and Cray pointees will already have been generated. */
4567 if (sym
->attr
.use_assoc
|| sym
->attr
.used_in_submodule
4568 || sym
->attr
.in_common
|| sym
->attr
.cray_pointee
)
4571 /* Equivalenced variables arrive here after creation. */
4572 if (sym
->backend_decl
4573 && (sym
->equiv_built
|| sym
->attr
.in_equivalence
))
4576 if (sym
->backend_decl
&& !sym
->attr
.vtab
&& !sym
->attr
.target
)
4577 gfc_internal_error ("backend decl for module variable %qs already exists",
4580 if (sym
->module
&& !sym
->attr
.result
&& !sym
->attr
.dummy
4581 && (sym
->attr
.access
== ACCESS_UNKNOWN
4582 && (sym
->ns
->default_access
== ACCESS_PRIVATE
4583 || (sym
->ns
->default_access
== ACCESS_UNKNOWN
4584 && flag_module_private
))))
4585 sym
->attr
.access
= ACCESS_PRIVATE
;
4587 if (warn_unused_variable
&& !sym
->attr
.referenced
4588 && sym
->attr
.access
== ACCESS_PRIVATE
)
4589 gfc_warning (OPT_Wunused_value
,
4590 "Unused PRIVATE module variable %qs declared at %L",
4591 sym
->name
, &sym
->declared_at
);
4593 /* We always want module variables to be created. */
4594 sym
->attr
.referenced
= 1;
4595 /* Create the decl. */
4596 decl
= gfc_get_symbol_decl (sym
);
4598 /* Create the variable. */
4600 gcc_assert (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
);
4601 DECL_CONTEXT (decl
) = sym
->ns
->proc_name
->backend_decl
;
4602 rest_of_decl_compilation (decl
, 1, 0);
4603 gfc_module_add_decl (cur_module
, decl
);
4605 /* Also add length of strings. */
4606 if (sym
->ts
.type
== BT_CHARACTER
)
4610 length
= sym
->ts
.u
.cl
->backend_decl
;
4611 gcc_assert (length
|| sym
->attr
.proc_pointer
);
4612 if (length
&& !INTEGER_CST_P (length
))
4615 rest_of_decl_compilation (length
, 1, 0);
4619 if (sym
->attr
.codimension
&& !sym
->attr
.dummy
&& !sym
->attr
.allocatable
4620 && sym
->attr
.referenced
&& !sym
->attr
.use_assoc
)
4621 has_coarray_vars
= true;
4624 /* Emit debug information for USE statements. */
4627 gfc_trans_use_stmts (gfc_namespace
* ns
)
4629 gfc_use_list
*use_stmt
;
4630 for (use_stmt
= ns
->use_stmts
; use_stmt
; use_stmt
= use_stmt
->next
)
4632 struct module_htab_entry
*entry
4633 = gfc_find_module (use_stmt
->module_name
);
4634 gfc_use_rename
*rent
;
4636 if (entry
->namespace_decl
== NULL
)
4638 entry
->namespace_decl
4639 = build_decl (input_location
,
4641 get_identifier (use_stmt
->module_name
),
4643 DECL_EXTERNAL (entry
->namespace_decl
) = 1;
4645 gfc_set_backend_locus (&use_stmt
->where
);
4646 if (!use_stmt
->only_flag
)
4647 (*debug_hooks
->imported_module_or_decl
) (entry
->namespace_decl
,
4649 ns
->proc_name
->backend_decl
,
4651 for (rent
= use_stmt
->rename
; rent
; rent
= rent
->next
)
4653 tree decl
, local_name
;
4655 if (rent
->op
!= INTRINSIC_NONE
)
4658 hashval_t hash
= htab_hash_string (rent
->use_name
);
4659 tree
*slot
= entry
->decls
->find_slot_with_hash (rent
->use_name
, hash
,
4665 st
= gfc_find_symtree (ns
->sym_root
,
4667 ? rent
->local_name
: rent
->use_name
);
4669 /* The following can happen if a derived type is renamed. */
4673 name
= xstrdup (rent
->local_name
[0]
4674 ? rent
->local_name
: rent
->use_name
);
4675 name
[0] = (char) TOUPPER ((unsigned char) name
[0]);
4676 st
= gfc_find_symtree (ns
->sym_root
, name
);
4681 /* Sometimes, generic interfaces wind up being over-ruled by a
4682 local symbol (see PR41062). */
4683 if (!st
->n
.sym
->attr
.use_assoc
)
4686 if (st
->n
.sym
->backend_decl
4687 && DECL_P (st
->n
.sym
->backend_decl
)
4688 && st
->n
.sym
->module
4689 && strcmp (st
->n
.sym
->module
, use_stmt
->module_name
) == 0)
4691 gcc_assert (DECL_EXTERNAL (entry
->namespace_decl
)
4692 || (TREE_CODE (st
->n
.sym
->backend_decl
)
4694 decl
= copy_node (st
->n
.sym
->backend_decl
);
4695 DECL_CONTEXT (decl
) = entry
->namespace_decl
;
4696 DECL_EXTERNAL (decl
) = 1;
4697 DECL_IGNORED_P (decl
) = 0;
4698 DECL_INITIAL (decl
) = NULL_TREE
;
4700 else if (st
->n
.sym
->attr
.flavor
== FL_NAMELIST
4701 && st
->n
.sym
->attr
.use_only
4702 && st
->n
.sym
->module
4703 && strcmp (st
->n
.sym
->module
, use_stmt
->module_name
)
4706 decl
= generate_namelist_decl (st
->n
.sym
);
4707 DECL_CONTEXT (decl
) = entry
->namespace_decl
;
4708 DECL_EXTERNAL (decl
) = 1;
4709 DECL_IGNORED_P (decl
) = 0;
4710 DECL_INITIAL (decl
) = NULL_TREE
;
4714 *slot
= error_mark_node
;
4715 entry
->decls
->clear_slot (slot
);
4720 decl
= (tree
) *slot
;
4721 if (rent
->local_name
[0])
4722 local_name
= get_identifier (rent
->local_name
);
4724 local_name
= NULL_TREE
;
4725 gfc_set_backend_locus (&rent
->where
);
4726 (*debug_hooks
->imported_module_or_decl
) (decl
, local_name
,
4727 ns
->proc_name
->backend_decl
,
4728 !use_stmt
->only_flag
);
4734 /* Return true if expr is a constant initializer that gfc_conv_initializer
4738 check_constant_initializer (gfc_expr
*expr
, gfc_typespec
*ts
, bool array
,
4748 if (expr
->expr_type
== EXPR_CONSTANT
|| expr
->expr_type
== EXPR_NULL
)
4750 else if (expr
->expr_type
== EXPR_STRUCTURE
)
4751 return check_constant_initializer (expr
, ts
, false, false);
4752 else if (expr
->expr_type
!= EXPR_ARRAY
)
4754 for (c
= gfc_constructor_first (expr
->value
.constructor
);
4755 c
; c
= gfc_constructor_next (c
))
4759 if (c
->expr
->expr_type
== EXPR_STRUCTURE
)
4761 if (!check_constant_initializer (c
->expr
, ts
, false, false))
4764 else if (c
->expr
->expr_type
!= EXPR_CONSTANT
)
4769 else switch (ts
->type
)
4772 if (expr
->expr_type
!= EXPR_STRUCTURE
)
4774 cm
= expr
->ts
.u
.derived
->components
;
4775 for (c
= gfc_constructor_first (expr
->value
.constructor
);
4776 c
; c
= gfc_constructor_next (c
), cm
= cm
->next
)
4778 if (!c
->expr
|| cm
->attr
.allocatable
)
4780 if (!check_constant_initializer (c
->expr
, &cm
->ts
,
4787 return expr
->expr_type
== EXPR_CONSTANT
;
4791 /* Emit debug info for parameters and unreferenced variables with
4795 gfc_emit_parameter_debug_info (gfc_symbol
*sym
)
4799 if (sym
->attr
.flavor
!= FL_PARAMETER
4800 && (sym
->attr
.flavor
!= FL_VARIABLE
|| sym
->attr
.referenced
))
4803 if (sym
->backend_decl
!= NULL
4804 || sym
->value
== NULL
4805 || sym
->attr
.use_assoc
4808 || sym
->attr
.function
4809 || sym
->attr
.intrinsic
4810 || sym
->attr
.pointer
4811 || sym
->attr
.allocatable
4812 || sym
->attr
.cray_pointee
4813 || sym
->attr
.threadprivate
4814 || sym
->attr
.is_bind_c
4815 || sym
->attr
.subref_array_pointer
4816 || sym
->attr
.assign
)
4819 if (sym
->ts
.type
== BT_CHARACTER
)
4821 gfc_conv_const_charlen (sym
->ts
.u
.cl
);
4822 if (sym
->ts
.u
.cl
->backend_decl
== NULL
4823 || TREE_CODE (sym
->ts
.u
.cl
->backend_decl
) != INTEGER_CST
)
4826 else if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.alloc_comp
)
4833 if (sym
->as
->type
!= AS_EXPLICIT
)
4835 for (n
= 0; n
< sym
->as
->rank
; n
++)
4836 if (sym
->as
->lower
[n
]->expr_type
!= EXPR_CONSTANT
4837 || sym
->as
->upper
[n
] == NULL
4838 || sym
->as
->upper
[n
]->expr_type
!= EXPR_CONSTANT
)
4842 if (!check_constant_initializer (sym
->value
, &sym
->ts
,
4843 sym
->attr
.dimension
, false))
4846 if (flag_coarray
== GFC_FCOARRAY_LIB
&& sym
->attr
.codimension
)
4849 /* Create the decl for the variable or constant. */
4850 decl
= build_decl (input_location
,
4851 sym
->attr
.flavor
== FL_PARAMETER
? CONST_DECL
: VAR_DECL
,
4852 gfc_sym_identifier (sym
), gfc_sym_type (sym
));
4853 if (sym
->attr
.flavor
== FL_PARAMETER
)
4854 TREE_READONLY (decl
) = 1;
4855 gfc_set_decl_location (decl
, &sym
->declared_at
);
4856 if (sym
->attr
.dimension
)
4857 GFC_DECL_PACKED_ARRAY (decl
) = 1;
4858 DECL_CONTEXT (decl
) = sym
->ns
->proc_name
->backend_decl
;
4859 TREE_STATIC (decl
) = 1;
4860 TREE_USED (decl
) = 1;
4861 if (DECL_CONTEXT (decl
) && TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
4862 TREE_PUBLIC (decl
) = 1;
4863 DECL_INITIAL (decl
) = gfc_conv_initializer (sym
->value
, &sym
->ts
,
4865 sym
->attr
.dimension
,
4867 debug_hooks
->early_global_decl (decl
);
4872 generate_coarray_sym_init (gfc_symbol
*sym
)
4874 tree tmp
, size
, decl
, token
;
4875 bool is_lock_type
, is_event_type
;
4878 if (sym
->attr
.dummy
|| sym
->attr
.allocatable
|| !sym
->attr
.codimension
4879 || sym
->attr
.use_assoc
|| !sym
->attr
.referenced
4880 || sym
->attr
.select_type_temporary
)
4883 decl
= sym
->backend_decl
;
4884 TREE_USED(decl
) = 1;
4885 gcc_assert (GFC_ARRAY_TYPE_P (TREE_TYPE (decl
)));
4887 is_lock_type
= sym
->ts
.type
== BT_DERIVED
4888 && sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
4889 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
;
4891 is_event_type
= sym
->ts
.type
== BT_DERIVED
4892 && sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
4893 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
;
4895 /* FIXME: Workaround for PR middle-end/49106, cf. also PR middle-end/49108
4896 to make sure the variable is not optimized away. */
4897 DECL_PRESERVE_P (DECL_CONTEXT (decl
)) = 1;
4899 /* For lock types, we pass the array size as only the library knows the
4900 size of the variable. */
4901 if (is_lock_type
|| is_event_type
)
4902 size
= gfc_index_one_node
;
4904 size
= TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (decl
)));
4906 /* Ensure that we do not have size=0 for zero-sized arrays. */
4907 size
= fold_build2_loc (input_location
, MAX_EXPR
, size_type_node
,
4908 fold_convert (size_type_node
, size
),
4909 build_int_cst (size_type_node
, 1));
4911 if (GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl
)))
4913 tmp
= GFC_TYPE_ARRAY_SIZE (TREE_TYPE (decl
));
4914 size
= fold_build2_loc (input_location
, MULT_EXPR
, size_type_node
,
4915 fold_convert (size_type_node
, tmp
), size
);
4918 gcc_assert (GFC_TYPE_ARRAY_CAF_TOKEN (TREE_TYPE (decl
)) != NULL_TREE
);
4919 token
= gfc_build_addr_expr (ppvoid_type_node
,
4920 GFC_TYPE_ARRAY_CAF_TOKEN (TREE_TYPE(decl
)));
4922 reg_type
= sym
->attr
.artificial
? GFC_CAF_CRITICAL
: GFC_CAF_LOCK_STATIC
;
4923 else if (is_event_type
)
4924 reg_type
= GFC_CAF_EVENT_STATIC
;
4926 reg_type
= GFC_CAF_COARRAY_STATIC
;
4927 tmp
= build_call_expr_loc (input_location
, gfor_fndecl_caf_register
, 6, size
,
4928 build_int_cst (integer_type_node
, reg_type
),
4929 token
, null_pointer_node
, /* token, stat. */
4930 null_pointer_node
, /* errgmsg, errmsg_len. */
4931 build_int_cst (integer_type_node
, 0));
4932 gfc_add_modify (&caf_init_block
, decl
, fold_convert (TREE_TYPE (decl
), tmp
));
4934 /* Handle "static" initializer. */
4937 sym
->attr
.pointer
= 1;
4938 tmp
= gfc_trans_assignment (gfc_lval_expr_from_sym (sym
), sym
->value
,
4940 sym
->attr
.pointer
= 0;
4941 gfc_add_expr_to_block (&caf_init_block
, tmp
);
4946 /* Generate constructor function to initialize static, nonallocatable
4950 generate_coarray_init (gfc_namespace
* ns
__attribute((unused
)))
4952 tree fndecl
, tmp
, decl
, save_fn_decl
;
4954 save_fn_decl
= current_function_decl
;
4955 push_function_context ();
4957 tmp
= build_function_type_list (void_type_node
, NULL_TREE
);
4958 fndecl
= build_decl (input_location
, FUNCTION_DECL
,
4959 create_tmp_var_name ("_caf_init"), tmp
);
4961 DECL_STATIC_CONSTRUCTOR (fndecl
) = 1;
4962 SET_DECL_INIT_PRIORITY (fndecl
, DEFAULT_INIT_PRIORITY
);
4964 decl
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
, void_type_node
);
4965 DECL_ARTIFICIAL (decl
) = 1;
4966 DECL_IGNORED_P (decl
) = 1;
4967 DECL_CONTEXT (decl
) = fndecl
;
4968 DECL_RESULT (fndecl
) = decl
;
4971 current_function_decl
= fndecl
;
4972 announce_function (fndecl
);
4974 rest_of_decl_compilation (fndecl
, 0, 0);
4975 make_decl_rtl (fndecl
);
4976 allocate_struct_function (fndecl
, false);
4979 gfc_init_block (&caf_init_block
);
4981 gfc_traverse_ns (ns
, generate_coarray_sym_init
);
4983 DECL_SAVED_TREE (fndecl
) = gfc_finish_block (&caf_init_block
);
4987 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
4989 DECL_SAVED_TREE (fndecl
)
4990 = build3_v (BIND_EXPR
, decl
, DECL_SAVED_TREE (fndecl
),
4991 DECL_INITIAL (fndecl
));
4992 dump_function (TDI_original
, fndecl
);
4994 cfun
->function_end_locus
= input_location
;
4997 if (decl_function_context (fndecl
))
4998 (void) cgraph_node::create (fndecl
);
5000 cgraph_node::finalize_function (fndecl
, true);
5002 pop_function_context ();
5003 current_function_decl
= save_fn_decl
;
5008 create_module_nml_decl (gfc_symbol
*sym
)
5010 if (sym
->attr
.flavor
== FL_NAMELIST
)
5012 tree decl
= generate_namelist_decl (sym
);
5014 gcc_assert (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
);
5015 DECL_CONTEXT (decl
) = sym
->ns
->proc_name
->backend_decl
;
5016 rest_of_decl_compilation (decl
, 1, 0);
5017 gfc_module_add_decl (cur_module
, decl
);
5022 /* Generate all the required code for module variables. */
5025 gfc_generate_module_vars (gfc_namespace
* ns
)
5027 module_namespace
= ns
;
5028 cur_module
= gfc_find_module (ns
->proc_name
->name
);
5030 /* Check if the frontend left the namespace in a reasonable state. */
5031 gcc_assert (ns
->proc_name
&& !ns
->proc_name
->tlink
);
5033 /* Generate COMMON blocks. */
5034 gfc_trans_common (ns
);
5036 has_coarray_vars
= false;
5038 /* Create decls for all the module variables. */
5039 gfc_traverse_ns (ns
, gfc_create_module_variable
);
5040 gfc_traverse_ns (ns
, create_module_nml_decl
);
5042 if (flag_coarray
== GFC_FCOARRAY_LIB
&& has_coarray_vars
)
5043 generate_coarray_init (ns
);
5047 gfc_trans_use_stmts (ns
);
5048 gfc_traverse_ns (ns
, gfc_emit_parameter_debug_info
);
5053 gfc_generate_contained_functions (gfc_namespace
* parent
)
5057 /* We create all the prototypes before generating any code. */
5058 for (ns
= parent
->contained
; ns
; ns
= ns
->sibling
)
5060 /* Skip namespaces from used modules. */
5061 if (ns
->parent
!= parent
)
5064 gfc_create_function_decl (ns
, false);
5067 for (ns
= parent
->contained
; ns
; ns
= ns
->sibling
)
5069 /* Skip namespaces from used modules. */
5070 if (ns
->parent
!= parent
)
5073 gfc_generate_function_code (ns
);
5078 /* Drill down through expressions for the array specification bounds and
5079 character length calling generate_local_decl for all those variables
5080 that have not already been declared. */
5083 generate_local_decl (gfc_symbol
*);
5085 /* Traverse expr, marking all EXPR_VARIABLE symbols referenced. */
5088 expr_decls (gfc_expr
*e
, gfc_symbol
*sym
,
5089 int *f ATTRIBUTE_UNUSED
)
5091 if (e
->expr_type
!= EXPR_VARIABLE
5092 || sym
== e
->symtree
->n
.sym
5093 || e
->symtree
->n
.sym
->mark
5094 || e
->symtree
->n
.sym
->ns
!= sym
->ns
)
5097 generate_local_decl (e
->symtree
->n
.sym
);
5102 generate_expr_decls (gfc_symbol
*sym
, gfc_expr
*e
)
5104 gfc_traverse_expr (e
, sym
, expr_decls
, 0);
5108 /* Check for dependencies in the character length and array spec. */
5111 generate_dependency_declarations (gfc_symbol
*sym
)
5115 if (sym
->ts
.type
== BT_CHARACTER
5117 && sym
->ts
.u
.cl
->length
5118 && sym
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
5119 generate_expr_decls (sym
, sym
->ts
.u
.cl
->length
);
5121 if (sym
->as
&& sym
->as
->rank
)
5123 for (i
= 0; i
< sym
->as
->rank
; i
++)
5125 generate_expr_decls (sym
, sym
->as
->lower
[i
]);
5126 generate_expr_decls (sym
, sym
->as
->upper
[i
]);
5132 /* Generate decls for all local variables. We do this to ensure correct
5133 handling of expressions which only appear in the specification of
5137 generate_local_decl (gfc_symbol
* sym
)
5139 if (sym
->attr
.flavor
== FL_VARIABLE
)
5141 if (sym
->attr
.codimension
&& !sym
->attr
.dummy
&& !sym
->attr
.allocatable
5142 && sym
->attr
.referenced
&& !sym
->attr
.use_assoc
)
5143 has_coarray_vars
= true;
5145 if (!sym
->attr
.dummy
&& !sym
->ns
->proc_name
->attr
.entry_master
)
5146 generate_dependency_declarations (sym
);
5148 if (sym
->attr
.referenced
)
5149 gfc_get_symbol_decl (sym
);
5151 /* Warnings for unused dummy arguments. */
5152 else if (sym
->attr
.dummy
&& !sym
->attr
.in_namelist
)
5154 /* INTENT(out) dummy arguments are likely meant to be set. */
5155 if (warn_unused_dummy_argument
&& sym
->attr
.intent
== INTENT_OUT
)
5157 if (sym
->ts
.type
!= BT_DERIVED
)
5158 gfc_warning (OPT_Wunused_dummy_argument
,
5159 "Dummy argument %qs at %L was declared "
5160 "INTENT(OUT) but was not set", sym
->name
,
5162 else if (!gfc_has_default_initializer (sym
->ts
.u
.derived
)
5163 && !sym
->ts
.u
.derived
->attr
.zero_comp
)
5164 gfc_warning (OPT_Wunused_dummy_argument
,
5165 "Derived-type dummy argument %qs at %L was "
5166 "declared INTENT(OUT) but was not set and "
5167 "does not have a default initializer",
5168 sym
->name
, &sym
->declared_at
);
5169 if (sym
->backend_decl
!= NULL_TREE
)
5170 TREE_NO_WARNING(sym
->backend_decl
) = 1;
5172 else if (warn_unused_dummy_argument
)
5174 gfc_warning (OPT_Wunused_dummy_argument
,
5175 "Unused dummy argument %qs at %L", sym
->name
,
5177 if (sym
->backend_decl
!= NULL_TREE
)
5178 TREE_NO_WARNING(sym
->backend_decl
) = 1;
5182 /* Warn for unused variables, but not if they're inside a common
5183 block or a namelist. */
5184 else if (warn_unused_variable
5185 && !(sym
->attr
.in_common
|| sym
->mark
|| sym
->attr
.in_namelist
))
5187 if (sym
->attr
.use_only
)
5189 gfc_warning (OPT_Wunused_variable
,
5190 "Unused module variable %qs which has been "
5191 "explicitly imported at %L", sym
->name
,
5193 if (sym
->backend_decl
!= NULL_TREE
)
5194 TREE_NO_WARNING(sym
->backend_decl
) = 1;
5196 else if (!sym
->attr
.use_assoc
)
5198 gfc_warning (OPT_Wunused_variable
,
5199 "Unused variable %qs declared at %L",
5200 sym
->name
, &sym
->declared_at
);
5201 if (sym
->backend_decl
!= NULL_TREE
)
5202 TREE_NO_WARNING(sym
->backend_decl
) = 1;
5206 /* For variable length CHARACTER parameters, the PARM_DECL already
5207 references the length variable, so force gfc_get_symbol_decl
5208 even when not referenced. If optimize > 0, it will be optimized
5209 away anyway. But do this only after emitting -Wunused-parameter
5210 warning if requested. */
5211 if (sym
->attr
.dummy
&& !sym
->attr
.referenced
5212 && sym
->ts
.type
== BT_CHARACTER
5213 && sym
->ts
.u
.cl
->backend_decl
!= NULL
5214 && TREE_CODE (sym
->ts
.u
.cl
->backend_decl
) == VAR_DECL
)
5216 sym
->attr
.referenced
= 1;
5217 gfc_get_symbol_decl (sym
);
5220 /* INTENT(out) dummy arguments and result variables with allocatable
5221 components are reset by default and need to be set referenced to
5222 generate the code for nullification and automatic lengths. */
5223 if (!sym
->attr
.referenced
5224 && sym
->ts
.type
== BT_DERIVED
5225 && sym
->ts
.u
.derived
->attr
.alloc_comp
5226 && !sym
->attr
.pointer
5227 && ((sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
)
5229 (sym
->attr
.result
&& sym
!= sym
->result
)))
5231 sym
->attr
.referenced
= 1;
5232 gfc_get_symbol_decl (sym
);
5235 /* Check for dependencies in the array specification and string
5236 length, adding the necessary declarations to the function. We
5237 mark the symbol now, as well as in traverse_ns, to prevent
5238 getting stuck in a circular dependency. */
5241 else if (sym
->attr
.flavor
== FL_PARAMETER
)
5243 if (warn_unused_parameter
5244 && !sym
->attr
.referenced
)
5246 if (!sym
->attr
.use_assoc
)
5247 gfc_warning (OPT_Wunused_parameter
,
5248 "Unused parameter %qs declared at %L", sym
->name
,
5250 else if (sym
->attr
.use_only
)
5251 gfc_warning (OPT_Wunused_parameter
,
5252 "Unused parameter %qs which has been explicitly "
5253 "imported at %L", sym
->name
, &sym
->declared_at
);
5258 && sym
->ns
->parent
->code
5259 && sym
->ns
->parent
->code
->op
== EXEC_BLOCK
)
5261 if (sym
->attr
.referenced
)
5262 gfc_get_symbol_decl (sym
);
5266 else if (sym
->attr
.flavor
== FL_PROCEDURE
)
5268 /* TODO: move to the appropriate place in resolve.c. */
5269 if (warn_return_type
5270 && sym
->attr
.function
5272 && sym
!= sym
->result
5273 && !sym
->result
->attr
.referenced
5274 && !sym
->attr
.use_assoc
5275 && sym
->attr
.if_source
!= IFSRC_IFBODY
)
5277 gfc_warning (OPT_Wreturn_type
,
5278 "Return value %qs of function %qs declared at "
5279 "%L not set", sym
->result
->name
, sym
->name
,
5280 &sym
->result
->declared_at
);
5282 /* Prevents "Unused variable" warning for RESULT variables. */
5283 sym
->result
->mark
= 1;
5287 if (sym
->attr
.dummy
== 1)
5289 /* Modify the tree type for scalar character dummy arguments of bind(c)
5290 procedures if they are passed by value. The tree type for them will
5291 be promoted to INTEGER_TYPE for the middle end, which appears to be
5292 what C would do with characters passed by-value. The value attribute
5293 implies the dummy is a scalar. */
5294 if (sym
->attr
.value
== 1 && sym
->backend_decl
!= NULL
5295 && sym
->ts
.type
== BT_CHARACTER
&& sym
->ts
.is_c_interop
5296 && sym
->ns
->proc_name
!= NULL
&& sym
->ns
->proc_name
->attr
.is_bind_c
)
5297 gfc_conv_scalar_char_value (sym
, NULL
, NULL
);
5299 /* Unused procedure passed as dummy argument. */
5300 if (sym
->attr
.flavor
== FL_PROCEDURE
)
5302 if (!sym
->attr
.referenced
)
5304 if (warn_unused_dummy_argument
)
5305 gfc_warning (OPT_Wunused_dummy_argument
,
5306 "Unused dummy argument %qs at %L", sym
->name
,
5310 /* Silence bogus "unused parameter" warnings from the
5312 if (sym
->backend_decl
!= NULL_TREE
)
5313 TREE_NO_WARNING (sym
->backend_decl
) = 1;
5317 /* Make sure we convert the types of the derived types from iso_c_binding
5319 if (sym
->attr
.flavor
!= FL_PROCEDURE
&& sym
->attr
.is_iso_c
5320 && sym
->ts
.type
== BT_DERIVED
)
5321 sym
->backend_decl
= gfc_typenode_for_spec (&(sym
->ts
));
5326 generate_local_nml_decl (gfc_symbol
* sym
)
5328 if (sym
->attr
.flavor
== FL_NAMELIST
&& !sym
->attr
.use_assoc
)
5330 tree decl
= generate_namelist_decl (sym
);
5337 generate_local_vars (gfc_namespace
* ns
)
5339 gfc_traverse_ns (ns
, generate_local_decl
);
5340 gfc_traverse_ns (ns
, generate_local_nml_decl
);
5344 /* Generate a switch statement to jump to the correct entry point. Also
5345 creates the label decls for the entry points. */
5348 gfc_trans_entry_master_switch (gfc_entry_list
* el
)
5355 gfc_init_block (&block
);
5356 for (; el
; el
= el
->next
)
5358 /* Add the case label. */
5359 label
= gfc_build_label_decl (NULL_TREE
);
5360 val
= build_int_cst (gfc_array_index_type
, el
->id
);
5361 tmp
= build_case_label (val
, NULL_TREE
, label
);
5362 gfc_add_expr_to_block (&block
, tmp
);
5364 /* And jump to the actual entry point. */
5365 label
= gfc_build_label_decl (NULL_TREE
);
5366 tmp
= build1_v (GOTO_EXPR
, label
);
5367 gfc_add_expr_to_block (&block
, tmp
);
5369 /* Save the label decl. */
5372 tmp
= gfc_finish_block (&block
);
5373 /* The first argument selects the entry point. */
5374 val
= DECL_ARGUMENTS (current_function_decl
);
5375 tmp
= fold_build3_loc (input_location
, SWITCH_EXPR
, NULL_TREE
,
5376 val
, tmp
, NULL_TREE
);
5381 /* Add code to string lengths of actual arguments passed to a function against
5382 the expected lengths of the dummy arguments. */
5385 add_argument_checking (stmtblock_t
*block
, gfc_symbol
*sym
)
5387 gfc_formal_arglist
*formal
;
5389 for (formal
= gfc_sym_get_dummy_args (sym
); formal
; formal
= formal
->next
)
5390 if (formal
->sym
&& formal
->sym
->ts
.type
== BT_CHARACTER
5391 && !formal
->sym
->ts
.deferred
)
5393 enum tree_code comparison
;
5398 const char *message
;
5404 gcc_assert (cl
->passed_length
!= NULL_TREE
);
5405 gcc_assert (cl
->backend_decl
!= NULL_TREE
);
5407 /* For POINTER, ALLOCATABLE and assumed-shape dummy arguments, the
5408 string lengths must match exactly. Otherwise, it is only required
5409 that the actual string length is *at least* the expected one.
5410 Sequence association allows for a mismatch of the string length
5411 if the actual argument is (part of) an array, but only if the
5412 dummy argument is an array. (See "Sequence association" in
5413 Section 12.4.1.4 for F95 and 12.4.1.5 for F2003.) */
5414 if (fsym
->attr
.pointer
|| fsym
->attr
.allocatable
5415 || (fsym
->as
&& (fsym
->as
->type
== AS_ASSUMED_SHAPE
5416 || fsym
->as
->type
== AS_ASSUMED_RANK
)))
5418 comparison
= NE_EXPR
;
5419 message
= _("Actual string length does not match the declared one"
5420 " for dummy argument '%s' (%ld/%ld)");
5422 else if (fsym
->as
&& fsym
->as
->rank
!= 0)
5426 comparison
= LT_EXPR
;
5427 message
= _("Actual string length is shorter than the declared one"
5428 " for dummy argument '%s' (%ld/%ld)");
5431 /* Build the condition. For optional arguments, an actual length
5432 of 0 is also acceptable if the associated string is NULL, which
5433 means the argument was not passed. */
5434 cond
= fold_build2_loc (input_location
, comparison
, boolean_type_node
,
5435 cl
->passed_length
, cl
->backend_decl
);
5436 if (fsym
->attr
.optional
)
5442 not_0length
= fold_build2_loc (input_location
, NE_EXPR
,
5445 build_zero_cst (gfc_charlen_type_node
));
5446 /* The symbol needs to be referenced for gfc_get_symbol_decl. */
5447 fsym
->attr
.referenced
= 1;
5448 not_absent
= gfc_conv_expr_present (fsym
);
5450 absent_failed
= fold_build2_loc (input_location
, TRUTH_OR_EXPR
,
5451 boolean_type_node
, not_0length
,
5454 cond
= fold_build2_loc (input_location
, TRUTH_AND_EXPR
,
5455 boolean_type_node
, cond
, absent_failed
);
5458 /* Build the runtime check. */
5459 argname
= gfc_build_cstring_const (fsym
->name
);
5460 argname
= gfc_build_addr_expr (pchar_type_node
, argname
);
5461 gfc_trans_runtime_check (true, false, cond
, block
, &fsym
->declared_at
,
5463 fold_convert (long_integer_type_node
,
5465 fold_convert (long_integer_type_node
,
5472 create_main_function (tree fndecl
)
5476 tree tmp
, decl
, result_decl
, argc
, argv
, typelist
, arglist
;
5479 old_context
= current_function_decl
;
5483 push_function_context ();
5484 saved_parent_function_decls
= saved_function_decls
;
5485 saved_function_decls
= NULL_TREE
;
5488 /* main() function must be declared with global scope. */
5489 gcc_assert (current_function_decl
== NULL_TREE
);
5491 /* Declare the function. */
5492 tmp
= build_function_type_list (integer_type_node
, integer_type_node
,
5493 build_pointer_type (pchar_type_node
),
5495 main_identifier_node
= get_identifier ("main");
5496 ftn_main
= build_decl (input_location
, FUNCTION_DECL
,
5497 main_identifier_node
, tmp
);
5498 DECL_EXTERNAL (ftn_main
) = 0;
5499 TREE_PUBLIC (ftn_main
) = 1;
5500 TREE_STATIC (ftn_main
) = 1;
5501 DECL_ATTRIBUTES (ftn_main
)
5502 = tree_cons (get_identifier("externally_visible"), NULL_TREE
, NULL_TREE
);
5504 /* Setup the result declaration (for "return 0"). */
5505 result_decl
= build_decl (input_location
,
5506 RESULT_DECL
, NULL_TREE
, integer_type_node
);
5507 DECL_ARTIFICIAL (result_decl
) = 1;
5508 DECL_IGNORED_P (result_decl
) = 1;
5509 DECL_CONTEXT (result_decl
) = ftn_main
;
5510 DECL_RESULT (ftn_main
) = result_decl
;
5512 pushdecl (ftn_main
);
5514 /* Get the arguments. */
5516 arglist
= NULL_TREE
;
5517 typelist
= TYPE_ARG_TYPES (TREE_TYPE (ftn_main
));
5519 tmp
= TREE_VALUE (typelist
);
5520 argc
= build_decl (input_location
, PARM_DECL
, get_identifier ("argc"), tmp
);
5521 DECL_CONTEXT (argc
) = ftn_main
;
5522 DECL_ARG_TYPE (argc
) = TREE_VALUE (typelist
);
5523 TREE_READONLY (argc
) = 1;
5524 gfc_finish_decl (argc
);
5525 arglist
= chainon (arglist
, argc
);
5527 typelist
= TREE_CHAIN (typelist
);
5528 tmp
= TREE_VALUE (typelist
);
5529 argv
= build_decl (input_location
, PARM_DECL
, get_identifier ("argv"), tmp
);
5530 DECL_CONTEXT (argv
) = ftn_main
;
5531 DECL_ARG_TYPE (argv
) = TREE_VALUE (typelist
);
5532 TREE_READONLY (argv
) = 1;
5533 DECL_BY_REFERENCE (argv
) = 1;
5534 gfc_finish_decl (argv
);
5535 arglist
= chainon (arglist
, argv
);
5537 DECL_ARGUMENTS (ftn_main
) = arglist
;
5538 current_function_decl
= ftn_main
;
5539 announce_function (ftn_main
);
5541 rest_of_decl_compilation (ftn_main
, 1, 0);
5542 make_decl_rtl (ftn_main
);
5543 allocate_struct_function (ftn_main
, false);
5546 gfc_init_block (&body
);
5548 /* Call some libgfortran initialization routines, call then MAIN__(). */
5550 /* Call _gfortran_caf_init (*argc, ***argv). */
5551 if (flag_coarray
== GFC_FCOARRAY_LIB
)
5553 tree pint_type
, pppchar_type
;
5554 pint_type
= build_pointer_type (integer_type_node
);
5556 = build_pointer_type (build_pointer_type (pchar_type_node
));
5558 tmp
= build_call_expr_loc (input_location
, gfor_fndecl_caf_init
, 2,
5559 gfc_build_addr_expr (pint_type
, argc
),
5560 gfc_build_addr_expr (pppchar_type
, argv
));
5561 gfc_add_expr_to_block (&body
, tmp
);
5564 /* Call _gfortran_set_args (argc, argv). */
5565 TREE_USED (argc
) = 1;
5566 TREE_USED (argv
) = 1;
5567 tmp
= build_call_expr_loc (input_location
,
5568 gfor_fndecl_set_args
, 2, argc
, argv
);
5569 gfc_add_expr_to_block (&body
, tmp
);
5571 /* Add a call to set_options to set up the runtime library Fortran
5572 language standard parameters. */
5574 tree array_type
, array
, var
;
5575 vec
<constructor_elt
, va_gc
> *v
= NULL
;
5577 /* Passing a new option to the library requires four modifications:
5578 + add it to the tree_cons list below
5579 + change the array size in the call to build_array_type
5580 + change the first argument to the library call
5581 gfor_fndecl_set_options
5582 + modify the library (runtime/compile_options.c)! */
5584 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
,
5585 build_int_cst (integer_type_node
,
5586 gfc_option
.warn_std
));
5587 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
,
5588 build_int_cst (integer_type_node
,
5589 gfc_option
.allow_std
));
5590 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
,
5591 build_int_cst (integer_type_node
, pedantic
));
5592 /* TODO: This is the old -fdump-core option, which is unused but
5593 passed due to ABI compatibility; remove when bumping the
5595 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
,
5596 build_int_cst (integer_type_node
,
5598 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
,
5599 build_int_cst (integer_type_node
, flag_backtrace
));
5600 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
,
5601 build_int_cst (integer_type_node
, flag_sign_zero
));
5602 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
,
5603 build_int_cst (integer_type_node
,
5605 & GFC_RTCHECK_BOUNDS
)));
5606 /* TODO: This is the -frange-check option, which no longer affects
5607 library behavior; when bumping the library ABI this slot can be
5608 reused for something else. As it is the last element in the
5609 array, we can instead leave it out altogether. */
5610 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
,
5611 build_int_cst (integer_type_node
, 0));
5612 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
,
5613 build_int_cst (integer_type_node
,
5614 gfc_option
.fpe_summary
));
5616 array_type
= build_array_type (integer_type_node
,
5617 build_index_type (size_int (8)));
5618 array
= build_constructor (array_type
, v
);
5619 TREE_CONSTANT (array
) = 1;
5620 TREE_STATIC (array
) = 1;
5622 /* Create a static variable to hold the jump table. */
5623 var
= build_decl (input_location
, VAR_DECL
,
5624 create_tmp_var_name ("options"),
5626 DECL_ARTIFICIAL (var
) = 1;
5627 DECL_IGNORED_P (var
) = 1;
5628 TREE_CONSTANT (var
) = 1;
5629 TREE_STATIC (var
) = 1;
5630 TREE_READONLY (var
) = 1;
5631 DECL_INITIAL (var
) = array
;
5633 var
= gfc_build_addr_expr (build_pointer_type (integer_type_node
), var
);
5635 tmp
= build_call_expr_loc (input_location
,
5636 gfor_fndecl_set_options
, 2,
5637 build_int_cst (integer_type_node
, 9), var
);
5638 gfc_add_expr_to_block (&body
, tmp
);
5641 /* If -ffpe-trap option was provided, add a call to set_fpe so that
5642 the library will raise a FPE when needed. */
5643 if (gfc_option
.fpe
!= 0)
5645 tmp
= build_call_expr_loc (input_location
,
5646 gfor_fndecl_set_fpe
, 1,
5647 build_int_cst (integer_type_node
,
5649 gfc_add_expr_to_block (&body
, tmp
);
5652 /* If this is the main program and an -fconvert option was provided,
5653 add a call to set_convert. */
5655 if (flag_convert
!= GFC_FLAG_CONVERT_NATIVE
)
5657 tmp
= build_call_expr_loc (input_location
,
5658 gfor_fndecl_set_convert
, 1,
5659 build_int_cst (integer_type_node
, flag_convert
));
5660 gfc_add_expr_to_block (&body
, tmp
);
5663 /* If this is the main program and an -frecord-marker option was provided,
5664 add a call to set_record_marker. */
5666 if (flag_record_marker
!= 0)
5668 tmp
= build_call_expr_loc (input_location
,
5669 gfor_fndecl_set_record_marker
, 1,
5670 build_int_cst (integer_type_node
,
5671 flag_record_marker
));
5672 gfc_add_expr_to_block (&body
, tmp
);
5675 if (flag_max_subrecord_length
!= 0)
5677 tmp
= build_call_expr_loc (input_location
,
5678 gfor_fndecl_set_max_subrecord_length
, 1,
5679 build_int_cst (integer_type_node
,
5680 flag_max_subrecord_length
));
5681 gfc_add_expr_to_block (&body
, tmp
);
5684 /* Call MAIN__(). */
5685 tmp
= build_call_expr_loc (input_location
,
5687 gfc_add_expr_to_block (&body
, tmp
);
5689 /* Mark MAIN__ as used. */
5690 TREE_USED (fndecl
) = 1;
5692 /* Coarray: Call _gfortran_caf_finalize(void). */
5693 if (flag_coarray
== GFC_FCOARRAY_LIB
)
5695 tmp
= build_call_expr_loc (input_location
, gfor_fndecl_caf_finalize
, 0);
5696 gfc_add_expr_to_block (&body
, tmp
);
5700 tmp
= fold_build2_loc (input_location
, MODIFY_EXPR
, integer_type_node
,
5701 DECL_RESULT (ftn_main
),
5702 build_int_cst (integer_type_node
, 0));
5703 tmp
= build1_v (RETURN_EXPR
, tmp
);
5704 gfc_add_expr_to_block (&body
, tmp
);
5707 DECL_SAVED_TREE (ftn_main
) = gfc_finish_block (&body
);
5710 /* Finish off this function and send it for code generation. */
5712 BLOCK_SUPERCONTEXT (DECL_INITIAL (ftn_main
)) = ftn_main
;
5714 DECL_SAVED_TREE (ftn_main
)
5715 = build3_v (BIND_EXPR
, decl
, DECL_SAVED_TREE (ftn_main
),
5716 DECL_INITIAL (ftn_main
));
5718 /* Output the GENERIC tree. */
5719 dump_function (TDI_original
, ftn_main
);
5721 cgraph_node::finalize_function (ftn_main
, true);
5725 pop_function_context ();
5726 saved_function_decls
= saved_parent_function_decls
;
5728 current_function_decl
= old_context
;
5732 /* Get the result expression for a procedure. */
5735 get_proc_result (gfc_symbol
* sym
)
5737 if (sym
->attr
.subroutine
|| sym
== sym
->result
)
5739 if (current_fake_result_decl
!= NULL
)
5740 return TREE_VALUE (current_fake_result_decl
);
5745 return sym
->result
->backend_decl
;
5749 /* Generate an appropriate return-statement for a procedure. */
5752 gfc_generate_return (void)
5758 sym
= current_procedure_symbol
;
5759 fndecl
= sym
->backend_decl
;
5761 if (TREE_TYPE (DECL_RESULT (fndecl
)) == void_type_node
)
5765 result
= get_proc_result (sym
);
5767 /* Set the return value to the dummy result variable. The
5768 types may be different for scalar default REAL functions
5769 with -ff2c, therefore we have to convert. */
5770 if (result
!= NULL_TREE
)
5772 result
= convert (TREE_TYPE (DECL_RESULT (fndecl
)), result
);
5773 result
= fold_build2_loc (input_location
, MODIFY_EXPR
,
5774 TREE_TYPE (result
), DECL_RESULT (fndecl
),
5779 return build1_v (RETURN_EXPR
, result
);
5784 is_from_ieee_module (gfc_symbol
*sym
)
5786 if (sym
->from_intmod
== INTMOD_IEEE_FEATURES
5787 || sym
->from_intmod
== INTMOD_IEEE_EXCEPTIONS
5788 || sym
->from_intmod
== INTMOD_IEEE_ARITHMETIC
)
5789 seen_ieee_symbol
= 1;
5794 is_ieee_module_used (gfc_namespace
*ns
)
5796 seen_ieee_symbol
= 0;
5797 gfc_traverse_ns (ns
, is_from_ieee_module
);
5798 return seen_ieee_symbol
;
5802 static gfc_omp_clauses
*module_oacc_clauses
;
5806 add_clause (gfc_symbol
*sym
, gfc_omp_map_op map_op
)
5808 gfc_omp_namelist
*n
;
5810 n
= gfc_get_omp_namelist ();
5812 n
->u
.map_op
= map_op
;
5814 if (!module_oacc_clauses
)
5815 module_oacc_clauses
= gfc_get_omp_clauses ();
5817 if (module_oacc_clauses
->lists
[OMP_LIST_MAP
])
5818 n
->next
= module_oacc_clauses
->lists
[OMP_LIST_MAP
];
5820 module_oacc_clauses
->lists
[OMP_LIST_MAP
] = n
;
5825 find_module_oacc_declare_clauses (gfc_symbol
*sym
)
5827 if (sym
->attr
.use_assoc
)
5829 gfc_omp_map_op map_op
;
5831 if (sym
->attr
.oacc_declare_create
)
5832 map_op
= OMP_MAP_FORCE_ALLOC
;
5834 if (sym
->attr
.oacc_declare_copyin
)
5835 map_op
= OMP_MAP_FORCE_TO
;
5837 if (sym
->attr
.oacc_declare_deviceptr
)
5838 map_op
= OMP_MAP_FORCE_DEVICEPTR
;
5840 if (sym
->attr
.oacc_declare_device_resident
)
5841 map_op
= OMP_MAP_DEVICE_RESIDENT
;
5843 if (sym
->attr
.oacc_declare_create
5844 || sym
->attr
.oacc_declare_copyin
5845 || sym
->attr
.oacc_declare_deviceptr
5846 || sym
->attr
.oacc_declare_device_resident
)
5848 sym
->attr
.referenced
= 1;
5849 add_clause (sym
, map_op
);
5856 finish_oacc_declare (gfc_namespace
*ns
, gfc_symbol
*sym
, bool block
)
5859 gfc_oacc_declare
*oc
;
5860 locus where
= gfc_current_locus
;
5861 gfc_omp_clauses
*omp_clauses
= NULL
;
5862 gfc_omp_namelist
*n
, *p
;
5864 gfc_traverse_ns (ns
, find_module_oacc_declare_clauses
);
5866 if (module_oacc_clauses
&& sym
->attr
.flavor
== FL_PROGRAM
)
5868 gfc_oacc_declare
*new_oc
;
5870 new_oc
= gfc_get_oacc_declare ();
5871 new_oc
->next
= ns
->oacc_declare
;
5872 new_oc
->clauses
= module_oacc_clauses
;
5874 ns
->oacc_declare
= new_oc
;
5875 module_oacc_clauses
= NULL
;
5878 if (!ns
->oacc_declare
)
5881 for (oc
= ns
->oacc_declare
; oc
; oc
= oc
->next
)
5887 gfc_error ("Sorry, $!ACC DECLARE at %L is not allowed "
5888 "in BLOCK construct", &oc
->loc
);
5891 if (oc
->clauses
&& oc
->clauses
->lists
[OMP_LIST_MAP
])
5893 if (omp_clauses
== NULL
)
5895 omp_clauses
= oc
->clauses
;
5899 for (n
= oc
->clauses
->lists
[OMP_LIST_MAP
]; n
; p
= n
, n
= n
->next
)
5902 gcc_assert (p
->next
== NULL
);
5904 p
->next
= omp_clauses
->lists
[OMP_LIST_MAP
];
5905 omp_clauses
= oc
->clauses
;
5912 for (n
= omp_clauses
->lists
[OMP_LIST_MAP
]; n
; n
= n
->next
)
5914 switch (n
->u
.map_op
)
5916 case OMP_MAP_DEVICE_RESIDENT
:
5917 n
->u
.map_op
= OMP_MAP_FORCE_ALLOC
;
5925 code
= XCNEW (gfc_code
);
5926 code
->op
= EXEC_OACC_DECLARE
;
5929 code
->ext
.oacc_declare
= gfc_get_oacc_declare ();
5930 code
->ext
.oacc_declare
->clauses
= omp_clauses
;
5932 code
->block
= XCNEW (gfc_code
);
5933 code
->block
->op
= EXEC_OACC_DECLARE
;
5934 code
->block
->loc
= where
;
5937 code
->block
->next
= ns
->code
;
5945 /* Generate code for a function. */
5948 gfc_generate_function_code (gfc_namespace
* ns
)
5954 tree fpstate
= NULL_TREE
;
5955 stmtblock_t init
, cleanup
;
5957 gfc_wrapped_block try_block
;
5958 tree recurcheckvar
= NULL_TREE
;
5960 gfc_symbol
*previous_procedure_symbol
;
5964 sym
= ns
->proc_name
;
5965 previous_procedure_symbol
= current_procedure_symbol
;
5966 current_procedure_symbol
= sym
;
5968 /* Check that the frontend isn't still using this. */
5969 gcc_assert (sym
->tlink
== NULL
);
5972 /* Create the declaration for functions with global scope. */
5973 if (!sym
->backend_decl
)
5974 gfc_create_function_decl (ns
, false);
5976 fndecl
= sym
->backend_decl
;
5977 old_context
= current_function_decl
;
5981 push_function_context ();
5982 saved_parent_function_decls
= saved_function_decls
;
5983 saved_function_decls
= NULL_TREE
;
5986 trans_function_start (sym
);
5988 gfc_init_block (&init
);
5990 if (ns
->entries
&& ns
->proc_name
->ts
.type
== BT_CHARACTER
)
5992 /* Copy length backend_decls to all entry point result
5997 gfc_conv_const_charlen (ns
->proc_name
->ts
.u
.cl
);
5998 backend_decl
= ns
->proc_name
->result
->ts
.u
.cl
->backend_decl
;
5999 for (el
= ns
->entries
; el
; el
= el
->next
)
6000 el
->sym
->result
->ts
.u
.cl
->backend_decl
= backend_decl
;
6003 /* Translate COMMON blocks. */
6004 gfc_trans_common (ns
);
6006 /* Null the parent fake result declaration if this namespace is
6007 a module function or an external procedures. */
6008 if ((ns
->parent
&& ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
6009 || ns
->parent
== NULL
)
6010 parent_fake_result_decl
= NULL_TREE
;
6012 gfc_generate_contained_functions (ns
);
6014 nonlocal_dummy_decls
= NULL
;
6015 nonlocal_dummy_decl_pset
= NULL
;
6017 has_coarray_vars
= false;
6018 generate_local_vars (ns
);
6020 if (flag_coarray
== GFC_FCOARRAY_LIB
&& has_coarray_vars
)
6021 generate_coarray_init (ns
);
6023 /* Keep the parent fake result declaration in module functions
6024 or external procedures. */
6025 if ((ns
->parent
&& ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
6026 || ns
->parent
== NULL
)
6027 current_fake_result_decl
= parent_fake_result_decl
;
6029 current_fake_result_decl
= NULL_TREE
;
6031 is_recursive
= sym
->attr
.recursive
6032 || (sym
->attr
.entry_master
6033 && sym
->ns
->entries
->sym
->attr
.recursive
);
6034 if ((gfc_option
.rtcheck
& GFC_RTCHECK_RECURSION
)
6035 && !is_recursive
&& !flag_recursive
)
6039 msg
= xasprintf ("Recursive call to nonrecursive procedure '%s'",
6041 recurcheckvar
= gfc_create_var (boolean_type_node
, "is_recursive");
6042 TREE_STATIC (recurcheckvar
) = 1;
6043 DECL_INITIAL (recurcheckvar
) = boolean_false_node
;
6044 gfc_add_expr_to_block (&init
, recurcheckvar
);
6045 gfc_trans_runtime_check (true, false, recurcheckvar
, &init
,
6046 &sym
->declared_at
, msg
);
6047 gfc_add_modify (&init
, recurcheckvar
, boolean_true_node
);
6051 /* Check if an IEEE module is used in the procedure. If so, save
6052 the floating point state. */
6053 ieee
= is_ieee_module_used (ns
);
6055 fpstate
= gfc_save_fp_state (&init
);
6057 /* Now generate the code for the body of this function. */
6058 gfc_init_block (&body
);
6060 if (TREE_TYPE (DECL_RESULT (fndecl
)) != void_type_node
6061 && sym
->attr
.subroutine
)
6063 tree alternate_return
;
6064 alternate_return
= gfc_get_fake_result_decl (sym
, 0);
6065 gfc_add_modify (&body
, alternate_return
, integer_zero_node
);
6070 /* Jump to the correct entry point. */
6071 tmp
= gfc_trans_entry_master_switch (ns
->entries
);
6072 gfc_add_expr_to_block (&body
, tmp
);
6075 /* If bounds-checking is enabled, generate code to check passed in actual
6076 arguments against the expected dummy argument attributes (e.g. string
6078 if ((gfc_option
.rtcheck
& GFC_RTCHECK_BOUNDS
) && !sym
->attr
.is_bind_c
)
6079 add_argument_checking (&body
, sym
);
6081 finish_oacc_declare (ns
, sym
, false);
6083 tmp
= gfc_trans_code (ns
->code
);
6084 gfc_add_expr_to_block (&body
, tmp
);
6086 if (TREE_TYPE (DECL_RESULT (fndecl
)) != void_type_node
6087 || (sym
->result
&& sym
->result
!= sym
6088 && sym
->result
->ts
.type
== BT_DERIVED
6089 && sym
->result
->ts
.u
.derived
->attr
.alloc_comp
))
6091 bool artificial_result_decl
= false;
6092 tree result
= get_proc_result (sym
);
6093 gfc_symbol
*rsym
= sym
== sym
->result
? sym
: sym
->result
;
6095 /* Make sure that a function returning an object with
6096 alloc/pointer_components always has a result, where at least
6097 the allocatable/pointer components are set to zero. */
6098 if (result
== NULL_TREE
&& sym
->attr
.function
6099 && ((sym
->result
->ts
.type
== BT_DERIVED
6100 && (sym
->attr
.allocatable
6101 || sym
->attr
.pointer
6102 || sym
->result
->ts
.u
.derived
->attr
.alloc_comp
6103 || sym
->result
->ts
.u
.derived
->attr
.pointer_comp
))
6104 || (sym
->result
->ts
.type
== BT_CLASS
6105 && (CLASS_DATA (sym
)->attr
.allocatable
6106 || CLASS_DATA (sym
)->attr
.class_pointer
6107 || CLASS_DATA (sym
->result
)->attr
.alloc_comp
6108 || CLASS_DATA (sym
->result
)->attr
.pointer_comp
))))
6110 artificial_result_decl
= true;
6111 result
= gfc_get_fake_result_decl (sym
, 0);
6114 if (result
!= NULL_TREE
&& sym
->attr
.function
&& !sym
->attr
.pointer
)
6116 if (sym
->attr
.allocatable
&& sym
->attr
.dimension
== 0
6117 && sym
->result
== sym
)
6118 gfc_add_modify (&init
, result
, fold_convert (TREE_TYPE (result
),
6119 null_pointer_node
));
6120 else if (sym
->ts
.type
== BT_CLASS
6121 && CLASS_DATA (sym
)->attr
.allocatable
6122 && CLASS_DATA (sym
)->attr
.dimension
== 0
6123 && sym
->result
== sym
)
6125 tmp
= CLASS_DATA (sym
)->backend_decl
;
6126 tmp
= fold_build3_loc (input_location
, COMPONENT_REF
,
6127 TREE_TYPE (tmp
), result
, tmp
, NULL_TREE
);
6128 gfc_add_modify (&init
, tmp
, fold_convert (TREE_TYPE (tmp
),
6129 null_pointer_node
));
6131 else if (sym
->ts
.type
== BT_DERIVED
6132 && !sym
->attr
.allocatable
)
6135 /* Arrays are not initialized using the default initializer of
6136 their elements. Therefore only check if a default
6137 initializer is available when the result is scalar. */
6138 init_exp
= rsym
->as
? NULL
: gfc_default_initializer (&rsym
->ts
);
6141 tmp
= gfc_trans_structure_assign (result
, init_exp
, 0);
6142 gfc_free_expr (init_exp
);
6143 gfc_add_expr_to_block (&init
, tmp
);
6145 else if (rsym
->ts
.u
.derived
->attr
.alloc_comp
)
6147 rank
= rsym
->as
? rsym
->as
->rank
: 0;
6148 tmp
= gfc_nullify_alloc_comp (rsym
->ts
.u
.derived
, result
,
6150 gfc_prepend_expr_to_block (&body
, tmp
);
6155 if (result
== NULL_TREE
|| artificial_result_decl
)
6157 /* TODO: move to the appropriate place in resolve.c. */
6158 if (warn_return_type
&& sym
== sym
->result
)
6159 gfc_warning (OPT_Wreturn_type
,
6160 "Return value of function %qs at %L not set",
6161 sym
->name
, &sym
->declared_at
);
6162 if (warn_return_type
)
6163 TREE_NO_WARNING(sym
->backend_decl
) = 1;
6165 if (result
!= NULL_TREE
)
6166 gfc_add_expr_to_block (&body
, gfc_generate_return ());
6169 gfc_init_block (&cleanup
);
6171 /* Reset recursion-check variable. */
6172 if ((gfc_option
.rtcheck
& GFC_RTCHECK_RECURSION
)
6173 && !is_recursive
&& !flag_openmp
&& recurcheckvar
!= NULL_TREE
)
6175 gfc_add_modify (&cleanup
, recurcheckvar
, boolean_false_node
);
6176 recurcheckvar
= NULL
;
6179 /* If IEEE modules are loaded, restore the floating-point state. */
6181 gfc_restore_fp_state (&cleanup
, fpstate
);
6183 /* Finish the function body and add init and cleanup code. */
6184 tmp
= gfc_finish_block (&body
);
6185 gfc_start_wrapped_block (&try_block
, tmp
);
6186 /* Add code to create and cleanup arrays. */
6187 gfc_trans_deferred_vars (sym
, &try_block
);
6188 gfc_add_init_cleanup (&try_block
, gfc_finish_block (&init
),
6189 gfc_finish_block (&cleanup
));
6191 /* Add all the decls we created during processing. */
6192 decl
= saved_function_decls
;
6197 next
= DECL_CHAIN (decl
);
6198 DECL_CHAIN (decl
) = NULL_TREE
;
6202 saved_function_decls
= NULL_TREE
;
6204 DECL_SAVED_TREE (fndecl
) = gfc_finish_wrapped_block (&try_block
);
6207 /* Finish off this function and send it for code generation. */
6209 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
6211 DECL_SAVED_TREE (fndecl
)
6212 = build3_v (BIND_EXPR
, decl
, DECL_SAVED_TREE (fndecl
),
6213 DECL_INITIAL (fndecl
));
6215 if (nonlocal_dummy_decls
)
6217 BLOCK_VARS (DECL_INITIAL (fndecl
))
6218 = chainon (BLOCK_VARS (DECL_INITIAL (fndecl
)), nonlocal_dummy_decls
);
6219 delete nonlocal_dummy_decl_pset
;
6220 nonlocal_dummy_decls
= NULL
;
6221 nonlocal_dummy_decl_pset
= NULL
;
6224 /* Output the GENERIC tree. */
6225 dump_function (TDI_original
, fndecl
);
6227 /* Store the end of the function, so that we get good line number
6228 info for the epilogue. */
6229 cfun
->function_end_locus
= input_location
;
6231 /* We're leaving the context of this function, so zap cfun.
6232 It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
6233 tree_rest_of_compilation. */
6238 pop_function_context ();
6239 saved_function_decls
= saved_parent_function_decls
;
6241 current_function_decl
= old_context
;
6243 if (decl_function_context (fndecl
))
6245 /* Register this function with cgraph just far enough to get it
6246 added to our parent's nested function list.
6247 If there are static coarrays in this function, the nested _caf_init
6248 function has already called cgraph_create_node, which also created
6249 the cgraph node for this function. */
6250 if (!has_coarray_vars
|| flag_coarray
!= GFC_FCOARRAY_LIB
)
6251 (void) cgraph_node::create (fndecl
);
6254 cgraph_node::finalize_function (fndecl
, true);
6256 gfc_trans_use_stmts (ns
);
6257 gfc_traverse_ns (ns
, gfc_emit_parameter_debug_info
);
6259 if (sym
->attr
.is_main_program
)
6260 create_main_function (fndecl
);
6262 current_procedure_symbol
= previous_procedure_symbol
;
6267 gfc_generate_constructors (void)
6269 gcc_assert (gfc_static_ctors
== NULL_TREE
);
6277 if (gfc_static_ctors
== NULL_TREE
)
6280 fnname
= get_file_function_name ("I");
6281 type
= build_function_type_list (void_type_node
, NULL_TREE
);
6283 fndecl
= build_decl (input_location
,
6284 FUNCTION_DECL
, fnname
, type
);
6285 TREE_PUBLIC (fndecl
) = 1;
6287 decl
= build_decl (input_location
,
6288 RESULT_DECL
, NULL_TREE
, void_type_node
);
6289 DECL_ARTIFICIAL (decl
) = 1;
6290 DECL_IGNORED_P (decl
) = 1;
6291 DECL_CONTEXT (decl
) = fndecl
;
6292 DECL_RESULT (fndecl
) = decl
;
6296 current_function_decl
= fndecl
;
6298 rest_of_decl_compilation (fndecl
, 1, 0);
6300 make_decl_rtl (fndecl
);
6302 allocate_struct_function (fndecl
, false);
6306 for (; gfc_static_ctors
; gfc_static_ctors
= TREE_CHAIN (gfc_static_ctors
))
6308 tmp
= build_call_expr_loc (input_location
,
6309 TREE_VALUE (gfc_static_ctors
), 0);
6310 DECL_SAVED_TREE (fndecl
) = build_stmt (input_location
, EXPR_STMT
, tmp
);
6316 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
6317 DECL_SAVED_TREE (fndecl
)
6318 = build3_v (BIND_EXPR
, decl
, DECL_SAVED_TREE (fndecl
),
6319 DECL_INITIAL (fndecl
));
6321 free_after_parsing (cfun
);
6322 free_after_compilation (cfun
);
6324 tree_rest_of_compilation (fndecl
);
6326 current_function_decl
= NULL_TREE
;
6330 /* Translates a BLOCK DATA program unit. This means emitting the
6331 commons contained therein plus their initializations. We also emit
6332 a globally visible symbol to make sure that each BLOCK DATA program
6333 unit remains unique. */
6336 gfc_generate_block_data (gfc_namespace
* ns
)
6341 /* Tell the backend the source location of the block data. */
6343 gfc_set_backend_locus (&ns
->proc_name
->declared_at
);
6345 gfc_set_backend_locus (&gfc_current_locus
);
6347 /* Process the DATA statements. */
6348 gfc_trans_common (ns
);
6350 /* Create a global symbol with the mane of the block data. This is to
6351 generate linker errors if the same name is used twice. It is never
6354 id
= gfc_sym_mangled_function_id (ns
->proc_name
);
6356 id
= get_identifier ("__BLOCK_DATA__");
6358 decl
= build_decl (input_location
,
6359 VAR_DECL
, id
, gfc_array_index_type
);
6360 TREE_PUBLIC (decl
) = 1;
6361 TREE_STATIC (decl
) = 1;
6362 DECL_IGNORED_P (decl
) = 1;
6365 rest_of_decl_compilation (decl
, 1, 0);
6369 /* Process the local variables of a BLOCK construct. */
6372 gfc_process_block_locals (gfc_namespace
* ns
)
6376 gcc_assert (saved_local_decls
== NULL_TREE
);
6377 has_coarray_vars
= false;
6379 generate_local_vars (ns
);
6381 if (flag_coarray
== GFC_FCOARRAY_LIB
&& has_coarray_vars
)
6382 generate_coarray_init (ns
);
6384 decl
= saved_local_decls
;
6389 next
= DECL_CHAIN (decl
);
6390 DECL_CHAIN (decl
) = NULL_TREE
;
6394 saved_local_decls
= NULL_TREE
;
6398 #include "gt-fortran-trans-decl.h"