1 /* Perform type resolution on the various structures.
2 Copyright (C) 2001-2021 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
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/>. */
23 #include "coretypes.h"
27 #include "arith.h" /* For gfc_compare_expr(). */
28 #include "dependency.h"
30 #include "target-memory.h" /* for gfc_simplify_transfer */
31 #include "constructor.h"
33 /* Types used in equivalence statements. */
37 SEQ_NONDEFAULT
, SEQ_NUMERIC
, SEQ_CHARACTER
, SEQ_MIXED
40 /* Stack to keep track of the nesting of blocks as we move through the
41 code. See resolve_branch() and gfc_resolve_code(). */
43 typedef struct code_stack
45 struct gfc_code
*head
, *current
;
46 struct code_stack
*prev
;
48 /* This bitmap keeps track of the targets valid for a branch from
49 inside this block except for END {IF|SELECT}s of enclosing
51 bitmap reachable_labels
;
55 static code_stack
*cs_base
= NULL
;
58 /* Nonzero if we're inside a FORALL or DO CONCURRENT block. */
60 static int forall_flag
;
61 int gfc_do_concurrent_flag
;
63 /* True when we are resolving an expression that is an actual argument to
65 static bool actual_arg
= false;
66 /* True when we are resolving an expression that is the first actual argument
68 static bool first_actual_arg
= false;
71 /* Nonzero if we're inside a OpenMP WORKSHARE or PARALLEL WORKSHARE block. */
73 static int omp_workshare_flag
;
75 /* True if we are processing a formal arglist. The corresponding function
76 resets the flag each time that it is read. */
77 static bool formal_arg_flag
= false;
79 /* True if we are resolving a specification expression. */
80 static bool specification_expr
= false;
82 /* The id of the last entry seen. */
83 static int current_entry_id
;
85 /* We use bitmaps to determine if a branch target is valid. */
86 static bitmap_obstack labels_obstack
;
88 /* True when simplifying a EXPR_VARIABLE argument to an inquiry function. */
89 static bool inquiry_argument
= false;
93 gfc_is_formal_arg (void)
95 return formal_arg_flag
;
98 /* Is the symbol host associated? */
100 is_sym_host_assoc (gfc_symbol
*sym
, gfc_namespace
*ns
)
102 for (ns
= ns
->parent
; ns
; ns
= ns
->parent
)
111 /* Ensure a typespec used is valid; for instance, TYPE(t) is invalid if t is
112 an ABSTRACT derived-type. If where is not NULL, an error message with that
113 locus is printed, optionally using name. */
116 resolve_typespec_used (gfc_typespec
* ts
, locus
* where
, const char* name
)
118 if (ts
->type
== BT_DERIVED
&& ts
->u
.derived
->attr
.abstract
)
123 gfc_error ("%qs at %L is of the ABSTRACT type %qs",
124 name
, where
, ts
->u
.derived
->name
);
126 gfc_error ("ABSTRACT type %qs used at %L",
127 ts
->u
.derived
->name
, where
);
138 check_proc_interface (gfc_symbol
*ifc
, locus
*where
)
140 /* Several checks for F08:C1216. */
141 if (ifc
->attr
.procedure
)
143 gfc_error ("Interface %qs at %L is declared "
144 "in a later PROCEDURE statement", ifc
->name
, where
);
149 /* For generic interfaces, check if there is
150 a specific procedure with the same name. */
151 gfc_interface
*gen
= ifc
->generic
;
152 while (gen
&& strcmp (gen
->sym
->name
, ifc
->name
) != 0)
156 gfc_error ("Interface %qs at %L may not be generic",
161 if (ifc
->attr
.proc
== PROC_ST_FUNCTION
)
163 gfc_error ("Interface %qs at %L may not be a statement function",
167 if (gfc_is_intrinsic (ifc
, 0, ifc
->declared_at
)
168 || gfc_is_intrinsic (ifc
, 1, ifc
->declared_at
))
169 ifc
->attr
.intrinsic
= 1;
170 if (ifc
->attr
.intrinsic
&& !gfc_intrinsic_actual_ok (ifc
->name
, 0))
172 gfc_error ("Intrinsic procedure %qs not allowed in "
173 "PROCEDURE statement at %L", ifc
->name
, where
);
176 if (!ifc
->attr
.if_source
&& !ifc
->attr
.intrinsic
&& ifc
->name
[0] != '\0')
178 gfc_error ("Interface %qs at %L must be explicit", ifc
->name
, where
);
185 static void resolve_symbol (gfc_symbol
*sym
);
188 /* Resolve the interface for a PROCEDURE declaration or procedure pointer. */
191 resolve_procedure_interface (gfc_symbol
*sym
)
193 gfc_symbol
*ifc
= sym
->ts
.interface
;
200 gfc_error ("PROCEDURE %qs at %L may not be used as its own interface",
201 sym
->name
, &sym
->declared_at
);
204 if (!check_proc_interface (ifc
, &sym
->declared_at
))
207 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
209 /* Resolve interface and copy attributes. */
210 resolve_symbol (ifc
);
211 if (ifc
->attr
.intrinsic
)
212 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
216 sym
->ts
= ifc
->result
->ts
;
217 sym
->attr
.allocatable
= ifc
->result
->attr
.allocatable
;
218 sym
->attr
.pointer
= ifc
->result
->attr
.pointer
;
219 sym
->attr
.dimension
= ifc
->result
->attr
.dimension
;
220 sym
->attr
.class_ok
= ifc
->result
->attr
.class_ok
;
221 sym
->as
= gfc_copy_array_spec (ifc
->result
->as
);
227 sym
->attr
.allocatable
= ifc
->attr
.allocatable
;
228 sym
->attr
.pointer
= ifc
->attr
.pointer
;
229 sym
->attr
.dimension
= ifc
->attr
.dimension
;
230 sym
->attr
.class_ok
= ifc
->attr
.class_ok
;
231 sym
->as
= gfc_copy_array_spec (ifc
->as
);
233 sym
->ts
.interface
= ifc
;
234 sym
->attr
.function
= ifc
->attr
.function
;
235 sym
->attr
.subroutine
= ifc
->attr
.subroutine
;
237 sym
->attr
.pure
= ifc
->attr
.pure
;
238 sym
->attr
.elemental
= ifc
->attr
.elemental
;
239 sym
->attr
.contiguous
= ifc
->attr
.contiguous
;
240 sym
->attr
.recursive
= ifc
->attr
.recursive
;
241 sym
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
242 sym
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
243 sym
->attr
.is_bind_c
= ifc
->attr
.is_bind_c
;
244 /* Copy char length. */
245 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
247 sym
->ts
.u
.cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
248 if (sym
->ts
.u
.cl
->length
&& !sym
->ts
.u
.cl
->resolved
249 && !gfc_resolve_expr (sym
->ts
.u
.cl
->length
))
258 /* Resolve types of formal argument lists. These have to be done early so that
259 the formal argument lists of module procedures can be copied to the
260 containing module before the individual procedures are resolved
261 individually. We also resolve argument lists of procedures in interface
262 blocks because they are self-contained scoping units.
264 Since a dummy argument cannot be a non-dummy procedure, the only
265 resort left for untyped names are the IMPLICIT types. */
268 gfc_resolve_formal_arglist (gfc_symbol
*proc
)
270 gfc_formal_arglist
*f
;
272 bool saved_specification_expr
;
275 if (proc
->result
!= NULL
)
280 if (gfc_elemental (proc
)
281 || sym
->attr
.pointer
|| sym
->attr
.allocatable
282 || (sym
->as
&& sym
->as
->rank
!= 0))
284 proc
->attr
.always_explicit
= 1;
285 sym
->attr
.always_explicit
= 1;
288 formal_arg_flag
= true;
290 for (f
= proc
->formal
; f
; f
= f
->next
)
298 /* Alternate return placeholder. */
299 if (gfc_elemental (proc
))
300 gfc_error ("Alternate return specifier in elemental subroutine "
301 "%qs at %L is not allowed", proc
->name
,
303 if (proc
->attr
.function
)
304 gfc_error ("Alternate return specifier in function "
305 "%qs at %L is not allowed", proc
->name
,
309 else if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
310 && !resolve_procedure_interface (sym
))
313 if (strcmp (proc
->name
, sym
->name
) == 0)
315 gfc_error ("Self-referential argument "
316 "%qs at %L is not allowed", sym
->name
,
321 if (sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
322 gfc_resolve_formal_arglist (sym
);
324 if (sym
->attr
.subroutine
|| sym
->attr
.external
)
326 if (sym
->attr
.flavor
== FL_UNKNOWN
)
327 gfc_add_flavor (&sym
->attr
, FL_PROCEDURE
, sym
->name
, &sym
->declared_at
);
331 if (sym
->ts
.type
== BT_UNKNOWN
&& !proc
->attr
.intrinsic
332 && (!sym
->attr
.function
|| sym
->result
== sym
))
333 gfc_set_default_type (sym
, 1, sym
->ns
);
336 as
= sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
337 ? CLASS_DATA (sym
)->as
: sym
->as
;
339 saved_specification_expr
= specification_expr
;
340 specification_expr
= true;
341 gfc_resolve_array_spec (as
, 0);
342 specification_expr
= saved_specification_expr
;
344 /* We can't tell if an array with dimension (:) is assumed or deferred
345 shape until we know if it has the pointer or allocatable attributes.
347 if (as
&& as
->rank
> 0 && as
->type
== AS_DEFERRED
348 && ((sym
->ts
.type
!= BT_CLASS
349 && !(sym
->attr
.pointer
|| sym
->attr
.allocatable
))
350 || (sym
->ts
.type
== BT_CLASS
351 && !(CLASS_DATA (sym
)->attr
.class_pointer
352 || CLASS_DATA (sym
)->attr
.allocatable
)))
353 && sym
->attr
.flavor
!= FL_PROCEDURE
)
355 as
->type
= AS_ASSUMED_SHAPE
;
356 for (i
= 0; i
< as
->rank
; i
++)
357 as
->lower
[i
] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
360 if ((as
&& as
->rank
> 0 && as
->type
== AS_ASSUMED_SHAPE
)
361 || (as
&& as
->type
== AS_ASSUMED_RANK
)
362 || sym
->attr
.pointer
|| sym
->attr
.allocatable
|| sym
->attr
.target
363 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
364 && (CLASS_DATA (sym
)->attr
.class_pointer
365 || CLASS_DATA (sym
)->attr
.allocatable
366 || CLASS_DATA (sym
)->attr
.target
))
367 || sym
->attr
.optional
)
369 proc
->attr
.always_explicit
= 1;
371 proc
->result
->attr
.always_explicit
= 1;
374 /* If the flavor is unknown at this point, it has to be a variable.
375 A procedure specification would have already set the type. */
377 if (sym
->attr
.flavor
== FL_UNKNOWN
)
378 gfc_add_flavor (&sym
->attr
, FL_VARIABLE
, sym
->name
, &sym
->declared_at
);
382 if (sym
->attr
.flavor
== FL_PROCEDURE
)
387 gfc_error ("Dummy procedure %qs of PURE procedure at %L must "
388 "also be PURE", sym
->name
, &sym
->declared_at
);
392 else if (!sym
->attr
.pointer
)
394 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
)
397 gfc_notify_std (GFC_STD_F2008
, "Argument %qs"
398 " of pure function %qs at %L with VALUE "
399 "attribute but without INTENT(IN)",
400 sym
->name
, proc
->name
, &sym
->declared_at
);
402 gfc_error ("Argument %qs of pure function %qs at %L must "
403 "be INTENT(IN) or VALUE", sym
->name
, proc
->name
,
407 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
)
410 gfc_notify_std (GFC_STD_F2008
, "Argument %qs"
411 " of pure subroutine %qs at %L with VALUE "
412 "attribute but without INTENT", sym
->name
,
413 proc
->name
, &sym
->declared_at
);
415 gfc_error ("Argument %qs of pure subroutine %qs at %L "
416 "must have its INTENT specified or have the "
417 "VALUE attribute", sym
->name
, proc
->name
,
423 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.intent
== INTENT_OUT
)
425 gfc_error ("INTENT(OUT) argument %qs of pure procedure %qs at %L"
426 " may not be polymorphic", sym
->name
, proc
->name
,
432 if (proc
->attr
.implicit_pure
)
434 if (sym
->attr
.flavor
== FL_PROCEDURE
)
437 proc
->attr
.implicit_pure
= 0;
439 else if (!sym
->attr
.pointer
)
441 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
443 proc
->attr
.implicit_pure
= 0;
445 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
447 proc
->attr
.implicit_pure
= 0;
451 if (gfc_elemental (proc
))
454 if (sym
->attr
.codimension
455 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
456 && CLASS_DATA (sym
)->attr
.codimension
))
458 gfc_error ("Coarray dummy argument %qs at %L to elemental "
459 "procedure", sym
->name
, &sym
->declared_at
);
463 if (sym
->as
|| (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
464 && CLASS_DATA (sym
)->as
))
466 gfc_error ("Argument %qs of elemental procedure at %L must "
467 "be scalar", sym
->name
, &sym
->declared_at
);
471 if (sym
->attr
.allocatable
472 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
473 && CLASS_DATA (sym
)->attr
.allocatable
))
475 gfc_error ("Argument %qs of elemental procedure at %L cannot "
476 "have the ALLOCATABLE attribute", sym
->name
,
481 if (sym
->attr
.pointer
482 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
483 && CLASS_DATA (sym
)->attr
.class_pointer
))
485 gfc_error ("Argument %qs of elemental procedure at %L cannot "
486 "have the POINTER attribute", sym
->name
,
491 if (sym
->attr
.flavor
== FL_PROCEDURE
)
493 gfc_error ("Dummy procedure %qs not allowed in elemental "
494 "procedure %qs at %L", sym
->name
, proc
->name
,
499 /* Fortran 2008 Corrigendum 1, C1290a. */
500 if (sym
->attr
.intent
== INTENT_UNKNOWN
&& !sym
->attr
.value
)
502 gfc_error ("Argument %qs of elemental procedure %qs at %L must "
503 "have its INTENT specified or have the VALUE "
504 "attribute", sym
->name
, proc
->name
,
510 /* Each dummy shall be specified to be scalar. */
511 if (proc
->attr
.proc
== PROC_ST_FUNCTION
)
515 /* F03:C1263 (R1238) The function-name and each dummy-arg-name
516 shall be specified, explicitly or implicitly, to be scalar. */
517 gfc_error ("Argument '%s' of statement function '%s' at %L "
518 "must be scalar", sym
->name
, proc
->name
,
523 if (sym
->ts
.type
== BT_CHARACTER
)
525 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
526 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
528 gfc_error ("Character-valued argument %qs of statement "
529 "function at %L must have constant length",
530 sym
->name
, &sym
->declared_at
);
536 formal_arg_flag
= false;
540 /* Work function called when searching for symbols that have argument lists
541 associated with them. */
544 find_arglists (gfc_symbol
*sym
)
546 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
|| sym
->ns
!= gfc_current_ns
547 || gfc_fl_struct (sym
->attr
.flavor
) || sym
->attr
.intrinsic
)
550 gfc_resolve_formal_arglist (sym
);
554 /* Given a namespace, resolve all formal argument lists within the namespace.
558 resolve_formal_arglists (gfc_namespace
*ns
)
563 gfc_traverse_ns (ns
, find_arglists
);
568 resolve_contained_fntype (gfc_symbol
*sym
, gfc_namespace
*ns
)
572 if (sym
&& sym
->attr
.flavor
== FL_PROCEDURE
574 && sym
->ns
->parent
->proc_name
575 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_PROCEDURE
576 && !strcmp (sym
->name
, sym
->ns
->parent
->proc_name
->name
))
577 gfc_error ("Contained procedure %qs at %L has the same name as its "
578 "encompassing procedure", sym
->name
, &sym
->declared_at
);
580 /* If this namespace is not a function or an entry master function,
582 if (! sym
|| !(sym
->attr
.function
|| sym
->attr
.flavor
== FL_VARIABLE
)
583 || sym
->attr
.entry_master
)
589 /* Try to find out of what the return type is. */
590 if (sym
->result
->ts
.type
== BT_UNKNOWN
&& sym
->result
->ts
.interface
== NULL
)
592 t
= gfc_set_default_type (sym
->result
, 0, ns
);
594 if (!t
&& !sym
->result
->attr
.untyped
)
596 if (sym
->result
== sym
)
597 gfc_error ("Contained function %qs at %L has no IMPLICIT type",
598 sym
->name
, &sym
->declared_at
);
599 else if (!sym
->result
->attr
.proc_pointer
)
600 gfc_error ("Result %qs of contained function %qs at %L has "
601 "no IMPLICIT type", sym
->result
->name
, sym
->name
,
602 &sym
->result
->declared_at
);
603 sym
->result
->attr
.untyped
= 1;
607 /* Fortran 2008 Draft Standard, page 535, C418, on type-param-value
608 type, lists the only ways a character length value of * can be used:
609 dummy arguments of procedures, named constants, function results and
610 in allocate statements if the allocate_object is an assumed length dummy
611 in external functions. Internal function results and results of module
612 procedures are not on this list, ergo, not permitted. */
614 if (sym
->result
->ts
.type
== BT_CHARACTER
)
616 gfc_charlen
*cl
= sym
->result
->ts
.u
.cl
;
617 if ((!cl
|| !cl
->length
) && !sym
->result
->ts
.deferred
)
619 /* See if this is a module-procedure and adapt error message
622 gcc_assert (ns
->parent
&& ns
->parent
->proc_name
);
623 module_proc
= (ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
);
625 gfc_error (module_proc
626 ? G_("Character-valued module procedure %qs at %L"
627 " must not be assumed length")
628 : G_("Character-valued internal function %qs at %L"
629 " must not be assumed length"),
630 sym
->name
, &sym
->declared_at
);
636 /* Add NEW_ARGS to the formal argument list of PROC, taking care not to
637 introduce duplicates. */
640 merge_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
642 gfc_formal_arglist
*f
, *new_arglist
;
645 for (; new_args
!= NULL
; new_args
= new_args
->next
)
647 new_sym
= new_args
->sym
;
648 /* See if this arg is already in the formal argument list. */
649 for (f
= proc
->formal
; f
; f
= f
->next
)
651 if (new_sym
== f
->sym
)
658 /* Add a new argument. Argument order is not important. */
659 new_arglist
= gfc_get_formal_arglist ();
660 new_arglist
->sym
= new_sym
;
661 new_arglist
->next
= proc
->formal
;
662 proc
->formal
= new_arglist
;
667 /* Flag the arguments that are not present in all entries. */
670 check_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
672 gfc_formal_arglist
*f
, *head
;
675 for (f
= proc
->formal
; f
; f
= f
->next
)
680 for (new_args
= head
; new_args
; new_args
= new_args
->next
)
682 if (new_args
->sym
== f
->sym
)
689 f
->sym
->attr
.not_always_present
= 1;
694 /* Resolve alternate entry points. If a symbol has multiple entry points we
695 create a new master symbol for the main routine, and turn the existing
696 symbol into an entry point. */
699 resolve_entries (gfc_namespace
*ns
)
701 gfc_namespace
*old_ns
;
705 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
706 static int master_count
= 0;
708 if (ns
->proc_name
== NULL
)
711 /* No need to do anything if this procedure doesn't have alternate entry
716 /* We may already have resolved alternate entry points. */
717 if (ns
->proc_name
->attr
.entry_master
)
720 /* If this isn't a procedure something has gone horribly wrong. */
721 gcc_assert (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
);
723 /* Remember the current namespace. */
724 old_ns
= gfc_current_ns
;
728 /* Add the main entry point to the list of entry points. */
729 el
= gfc_get_entry_list ();
730 el
->sym
= ns
->proc_name
;
732 el
->next
= ns
->entries
;
734 ns
->proc_name
->attr
.entry
= 1;
736 /* If it is a module function, it needs to be in the right namespace
737 so that gfc_get_fake_result_decl can gather up the results. The
738 need for this arose in get_proc_name, where these beasts were
739 left in their own namespace, to keep prior references linked to
740 the entry declaration.*/
741 if (ns
->proc_name
->attr
.function
742 && ns
->parent
&& ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
745 /* Do the same for entries where the master is not a module
746 procedure. These are retained in the module namespace because
747 of the module procedure declaration. */
748 for (el
= el
->next
; el
; el
= el
->next
)
749 if (el
->sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
750 && el
->sym
->attr
.mod_proc
)
754 /* Add an entry statement for it. */
755 c
= gfc_get_code (EXEC_ENTRY
);
760 /* Create a new symbol for the master function. */
761 /* Give the internal function a unique name (within this file).
762 Also include the function name so the user has some hope of figuring
763 out what is going on. */
764 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "master.%d.%s",
765 master_count
++, ns
->proc_name
->name
);
766 gfc_get_ha_symbol (name
, &proc
);
767 gcc_assert (proc
!= NULL
);
769 gfc_add_procedure (&proc
->attr
, PROC_INTERNAL
, proc
->name
, NULL
);
770 if (ns
->proc_name
->attr
.subroutine
)
771 gfc_add_subroutine (&proc
->attr
, proc
->name
, NULL
);
775 gfc_typespec
*ts
, *fts
;
776 gfc_array_spec
*as
, *fas
;
777 gfc_add_function (&proc
->attr
, proc
->name
, NULL
);
779 fas
= ns
->entries
->sym
->as
;
780 fas
= fas
? fas
: ns
->entries
->sym
->result
->as
;
781 fts
= &ns
->entries
->sym
->result
->ts
;
782 if (fts
->type
== BT_UNKNOWN
)
783 fts
= gfc_get_default_type (ns
->entries
->sym
->result
->name
, NULL
);
784 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
786 ts
= &el
->sym
->result
->ts
;
788 as
= as
? as
: el
->sym
->result
->as
;
789 if (ts
->type
== BT_UNKNOWN
)
790 ts
= gfc_get_default_type (el
->sym
->result
->name
, NULL
);
792 if (! gfc_compare_types (ts
, fts
)
793 || (el
->sym
->result
->attr
.dimension
794 != ns
->entries
->sym
->result
->attr
.dimension
)
795 || (el
->sym
->result
->attr
.pointer
796 != ns
->entries
->sym
->result
->attr
.pointer
))
798 else if (as
&& fas
&& ns
->entries
->sym
->result
!= el
->sym
->result
799 && gfc_compare_array_spec (as
, fas
) == 0)
800 gfc_error ("Function %s at %L has entries with mismatched "
801 "array specifications", ns
->entries
->sym
->name
,
802 &ns
->entries
->sym
->declared_at
);
803 /* The characteristics need to match and thus both need to have
804 the same string length, i.e. both len=*, or both len=4.
805 Having both len=<variable> is also possible, but difficult to
806 check at compile time. */
807 else if (ts
->type
== BT_CHARACTER
&& ts
->u
.cl
&& fts
->u
.cl
808 && (((ts
->u
.cl
->length
&& !fts
->u
.cl
->length
)
809 ||(!ts
->u
.cl
->length
&& fts
->u
.cl
->length
))
811 && ts
->u
.cl
->length
->expr_type
812 != fts
->u
.cl
->length
->expr_type
)
814 && ts
->u
.cl
->length
->expr_type
== EXPR_CONSTANT
815 && mpz_cmp (ts
->u
.cl
->length
->value
.integer
,
816 fts
->u
.cl
->length
->value
.integer
) != 0)))
817 gfc_notify_std (GFC_STD_GNU
, "Function %s at %L with "
818 "entries returning variables of different "
819 "string lengths", ns
->entries
->sym
->name
,
820 &ns
->entries
->sym
->declared_at
);
825 sym
= ns
->entries
->sym
->result
;
826 /* All result types the same. */
828 if (sym
->attr
.dimension
)
829 gfc_set_array_spec (proc
, gfc_copy_array_spec (sym
->as
), NULL
);
830 if (sym
->attr
.pointer
)
831 gfc_add_pointer (&proc
->attr
, NULL
);
835 /* Otherwise the result will be passed through a union by
837 proc
->attr
.mixed_entry_master
= 1;
838 for (el
= ns
->entries
; el
; el
= el
->next
)
840 sym
= el
->sym
->result
;
841 if (sym
->attr
.dimension
)
843 if (el
== ns
->entries
)
844 gfc_error ("FUNCTION result %s cannot be an array in "
845 "FUNCTION %s at %L", sym
->name
,
846 ns
->entries
->sym
->name
, &sym
->declared_at
);
848 gfc_error ("ENTRY result %s cannot be an array in "
849 "FUNCTION %s at %L", sym
->name
,
850 ns
->entries
->sym
->name
, &sym
->declared_at
);
852 else if (sym
->attr
.pointer
)
854 if (el
== ns
->entries
)
855 gfc_error ("FUNCTION result %s cannot be a POINTER in "
856 "FUNCTION %s at %L", sym
->name
,
857 ns
->entries
->sym
->name
, &sym
->declared_at
);
859 gfc_error ("ENTRY result %s cannot be a POINTER in "
860 "FUNCTION %s at %L", sym
->name
,
861 ns
->entries
->sym
->name
, &sym
->declared_at
);
866 if (ts
->type
== BT_UNKNOWN
)
867 ts
= gfc_get_default_type (sym
->name
, NULL
);
871 if (ts
->kind
== gfc_default_integer_kind
)
875 if (ts
->kind
== gfc_default_real_kind
876 || ts
->kind
== gfc_default_double_kind
)
880 if (ts
->kind
== gfc_default_complex_kind
)
884 if (ts
->kind
== gfc_default_logical_kind
)
888 /* We will issue error elsewhere. */
896 if (el
== ns
->entries
)
897 gfc_error ("FUNCTION result %s cannot be of type %s "
898 "in FUNCTION %s at %L", sym
->name
,
899 gfc_typename (ts
), ns
->entries
->sym
->name
,
902 gfc_error ("ENTRY result %s cannot be of type %s "
903 "in FUNCTION %s at %L", sym
->name
,
904 gfc_typename (ts
), ns
->entries
->sym
->name
,
911 proc
->attr
.access
= ACCESS_PRIVATE
;
912 proc
->attr
.entry_master
= 1;
914 /* Merge all the entry point arguments. */
915 for (el
= ns
->entries
; el
; el
= el
->next
)
916 merge_argument_lists (proc
, el
->sym
->formal
);
918 /* Check the master formal arguments for any that are not
919 present in all entry points. */
920 for (el
= ns
->entries
; el
; el
= el
->next
)
921 check_argument_lists (proc
, el
->sym
->formal
);
923 /* Use the master function for the function body. */
924 ns
->proc_name
= proc
;
926 /* Finalize the new symbols. */
927 gfc_commit_symbols ();
929 /* Restore the original namespace. */
930 gfc_current_ns
= old_ns
;
934 /* Resolve common variables. */
936 resolve_common_vars (gfc_common_head
*common_block
, bool named_common
)
938 gfc_symbol
*csym
= common_block
->head
;
941 for (; csym
; csym
= csym
->common_next
)
943 gsym
= gfc_find_gsymbol (gfc_gsym_root
, csym
->name
);
944 if (gsym
&& (gsym
->type
== GSYM_MODULE
|| gsym
->type
== GSYM_PROGRAM
))
945 gfc_error_now ("Global entity %qs at %L cannot appear in a "
946 "COMMON block at %L", gsym
->name
,
947 &gsym
->where
, &csym
->common_block
->where
);
949 /* gfc_add_in_common may have been called before, but the reported errors
950 have been ignored to continue parsing.
951 We do the checks again here. */
952 if (!csym
->attr
.use_assoc
)
954 gfc_add_in_common (&csym
->attr
, csym
->name
, &common_block
->where
);
955 gfc_notify_std (GFC_STD_F2018_OBS
, "COMMON block at %L",
956 &common_block
->where
);
959 if (csym
->value
|| csym
->attr
.data
)
961 if (!csym
->ns
->is_block_data
)
962 gfc_notify_std (GFC_STD_GNU
, "Variable %qs at %L is in COMMON "
963 "but only in BLOCK DATA initialization is "
964 "allowed", csym
->name
, &csym
->declared_at
);
965 else if (!named_common
)
966 gfc_notify_std (GFC_STD_GNU
, "Initialized variable %qs at %L is "
967 "in a blank COMMON but initialization is only "
968 "allowed in named common blocks", csym
->name
,
972 if (UNLIMITED_POLY (csym
))
973 gfc_error_now ("%qs in cannot appear in COMMON at %L "
974 "[F2008:C5100]", csym
->name
, &csym
->declared_at
);
976 if (csym
->ts
.type
!= BT_DERIVED
)
979 if (!(csym
->ts
.u
.derived
->attr
.sequence
980 || csym
->ts
.u
.derived
->attr
.is_bind_c
))
981 gfc_error_now ("Derived type variable %qs in COMMON at %L "
982 "has neither the SEQUENCE nor the BIND(C) "
983 "attribute", csym
->name
, &csym
->declared_at
);
984 if (csym
->ts
.u
.derived
->attr
.alloc_comp
)
985 gfc_error_now ("Derived type variable %qs in COMMON at %L "
986 "has an ultimate component that is "
987 "allocatable", csym
->name
, &csym
->declared_at
);
988 if (gfc_has_default_initializer (csym
->ts
.u
.derived
))
989 gfc_error_now ("Derived type variable %qs in COMMON at %L "
990 "may not have default initializer", csym
->name
,
993 if (csym
->attr
.flavor
== FL_UNKNOWN
&& !csym
->attr
.proc_pointer
)
994 gfc_add_flavor (&csym
->attr
, FL_VARIABLE
, csym
->name
, &csym
->declared_at
);
998 /* Resolve common blocks. */
1000 resolve_common_blocks (gfc_symtree
*common_root
)
1005 if (common_root
== NULL
)
1008 if (common_root
->left
)
1009 resolve_common_blocks (common_root
->left
);
1010 if (common_root
->right
)
1011 resolve_common_blocks (common_root
->right
);
1013 resolve_common_vars (common_root
->n
.common
, true);
1015 /* The common name is a global name - in Fortran 2003 also if it has a
1016 C binding name, since Fortran 2008 only the C binding name is a global
1018 if (!common_root
->n
.common
->binding_label
1019 || gfc_notification_std (GFC_STD_F2008
))
1021 gsym
= gfc_find_gsymbol (gfc_gsym_root
,
1022 common_root
->n
.common
->name
);
1024 if (gsym
&& gfc_notification_std (GFC_STD_F2008
)
1025 && gsym
->type
== GSYM_COMMON
1026 && ((common_root
->n
.common
->binding_label
1027 && (!gsym
->binding_label
1028 || strcmp (common_root
->n
.common
->binding_label
,
1029 gsym
->binding_label
) != 0))
1030 || (!common_root
->n
.common
->binding_label
1031 && gsym
->binding_label
)))
1033 gfc_error ("In Fortran 2003 COMMON %qs block at %L is a global "
1034 "identifier and must thus have the same binding name "
1035 "as the same-named COMMON block at %L: %s vs %s",
1036 common_root
->n
.common
->name
, &common_root
->n
.common
->where
,
1038 common_root
->n
.common
->binding_label
1039 ? common_root
->n
.common
->binding_label
: "(blank)",
1040 gsym
->binding_label
? gsym
->binding_label
: "(blank)");
1044 if (gsym
&& gsym
->type
!= GSYM_COMMON
1045 && !common_root
->n
.common
->binding_label
)
1047 gfc_error ("COMMON block %qs at %L uses the same global identifier "
1049 common_root
->n
.common
->name
, &common_root
->n
.common
->where
,
1053 if (gsym
&& gsym
->type
!= GSYM_COMMON
)
1055 gfc_error ("Fortran 2008: COMMON block %qs with binding label at "
1056 "%L sharing the identifier with global non-COMMON-block "
1057 "entity at %L", common_root
->n
.common
->name
,
1058 &common_root
->n
.common
->where
, &gsym
->where
);
1063 gsym
= gfc_get_gsymbol (common_root
->n
.common
->name
, false);
1064 gsym
->type
= GSYM_COMMON
;
1065 gsym
->where
= common_root
->n
.common
->where
;
1071 if (common_root
->n
.common
->binding_label
)
1073 gsym
= gfc_find_gsymbol (gfc_gsym_root
,
1074 common_root
->n
.common
->binding_label
);
1075 if (gsym
&& gsym
->type
!= GSYM_COMMON
)
1077 gfc_error ("COMMON block at %L with binding label %qs uses the same "
1078 "global identifier as entity at %L",
1079 &common_root
->n
.common
->where
,
1080 common_root
->n
.common
->binding_label
, &gsym
->where
);
1085 gsym
= gfc_get_gsymbol (common_root
->n
.common
->binding_label
, true);
1086 gsym
->type
= GSYM_COMMON
;
1087 gsym
->where
= common_root
->n
.common
->where
;
1093 gfc_find_symbol (common_root
->name
, gfc_current_ns
, 0, &sym
);
1097 if (sym
->attr
.flavor
== FL_PARAMETER
)
1098 gfc_error ("COMMON block %qs at %L is used as PARAMETER at %L",
1099 sym
->name
, &common_root
->n
.common
->where
, &sym
->declared_at
);
1101 if (sym
->attr
.external
)
1102 gfc_error ("COMMON block %qs at %L cannot have the EXTERNAL attribute",
1103 sym
->name
, &common_root
->n
.common
->where
);
1105 if (sym
->attr
.intrinsic
)
1106 gfc_error ("COMMON block %qs at %L is also an intrinsic procedure",
1107 sym
->name
, &common_root
->n
.common
->where
);
1108 else if (sym
->attr
.result
1109 || gfc_is_function_return_value (sym
, gfc_current_ns
))
1110 gfc_notify_std (GFC_STD_F2003
, "COMMON block %qs at %L "
1111 "that is also a function result", sym
->name
,
1112 &common_root
->n
.common
->where
);
1113 else if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.proc
!= PROC_INTERNAL
1114 && sym
->attr
.proc
!= PROC_ST_FUNCTION
)
1115 gfc_notify_std (GFC_STD_F2003
, "COMMON block %qs at %L "
1116 "that is also a global procedure", sym
->name
,
1117 &common_root
->n
.common
->where
);
1121 /* Resolve contained function types. Because contained functions can call one
1122 another, they have to be worked out before any of the contained procedures
1125 The good news is that if a function doesn't already have a type, the only
1126 way it can get one is through an IMPLICIT type or a RESULT variable, because
1127 by definition contained functions are contained namespace they're contained
1128 in, not in a sibling or parent namespace. */
1131 resolve_contained_functions (gfc_namespace
*ns
)
1133 gfc_namespace
*child
;
1136 resolve_formal_arglists (ns
);
1138 for (child
= ns
->contained
; child
; child
= child
->sibling
)
1140 /* Resolve alternate entry points first. */
1141 resolve_entries (child
);
1143 /* Then check function return types. */
1144 resolve_contained_fntype (child
->proc_name
, child
);
1145 for (el
= child
->entries
; el
; el
= el
->next
)
1146 resolve_contained_fntype (el
->sym
, child
);
1152 /* A Parameterized Derived Type constructor must contain values for
1153 the PDT KIND parameters or they must have a default initializer.
1154 Go through the constructor picking out the KIND expressions,
1155 storing them in 'param_list' and then call gfc_get_pdt_instance
1156 to obtain the PDT instance. */
1158 static gfc_actual_arglist
*param_list
, *param_tail
, *param
;
1161 get_pdt_spec_expr (gfc_component
*c
, gfc_expr
*expr
)
1163 param
= gfc_get_actual_arglist ();
1165 param_list
= param_tail
= param
;
1168 param_tail
->next
= param
;
1169 param_tail
= param_tail
->next
;
1172 param_tail
->name
= c
->name
;
1174 param_tail
->expr
= gfc_copy_expr (expr
);
1175 else if (c
->initializer
)
1176 param_tail
->expr
= gfc_copy_expr (c
->initializer
);
1179 param_tail
->spec_type
= SPEC_ASSUMED
;
1180 if (c
->attr
.pdt_kind
)
1182 gfc_error ("The KIND parameter %qs in the PDT constructor "
1183 "at %C has no value", param
->name
);
1192 get_pdt_constructor (gfc_expr
*expr
, gfc_constructor
**constr
,
1193 gfc_symbol
*derived
)
1195 gfc_constructor
*cons
= NULL
;
1196 gfc_component
*comp
;
1199 if (expr
&& expr
->expr_type
== EXPR_STRUCTURE
)
1200 cons
= gfc_constructor_first (expr
->value
.constructor
);
1205 comp
= derived
->components
;
1207 for (; comp
&& cons
; comp
= comp
->next
, cons
= gfc_constructor_next (cons
))
1210 && cons
->expr
->expr_type
== EXPR_STRUCTURE
1211 && comp
->ts
.type
== BT_DERIVED
)
1213 t
= get_pdt_constructor (cons
->expr
, NULL
, comp
->ts
.u
.derived
);
1217 else if (comp
->ts
.type
== BT_DERIVED
)
1219 t
= get_pdt_constructor (NULL
, &cons
, comp
->ts
.u
.derived
);
1223 else if ((comp
->attr
.pdt_kind
|| comp
->attr
.pdt_len
)
1224 && derived
->attr
.pdt_template
)
1226 t
= get_pdt_spec_expr (comp
, cons
->expr
);
1235 static bool resolve_fl_derived0 (gfc_symbol
*sym
);
1236 static bool resolve_fl_struct (gfc_symbol
*sym
);
1239 /* Resolve all of the elements of a structure constructor and make sure that
1240 the types are correct. The 'init' flag indicates that the given
1241 constructor is an initializer. */
1244 resolve_structure_cons (gfc_expr
*expr
, int init
)
1246 gfc_constructor
*cons
;
1247 gfc_component
*comp
;
1253 if (expr
->ts
.type
== BT_DERIVED
|| expr
->ts
.type
== BT_UNION
)
1255 if (expr
->ts
.u
.derived
->attr
.flavor
== FL_DERIVED
)
1256 resolve_fl_derived0 (expr
->ts
.u
.derived
);
1258 resolve_fl_struct (expr
->ts
.u
.derived
);
1260 /* If this is a Parameterized Derived Type template, find the
1261 instance corresponding to the PDT kind parameters. */
1262 if (expr
->ts
.u
.derived
->attr
.pdt_template
)
1265 t
= get_pdt_constructor (expr
, NULL
, expr
->ts
.u
.derived
);
1268 gfc_get_pdt_instance (param_list
, &expr
->ts
.u
.derived
, NULL
);
1270 expr
->param_list
= gfc_copy_actual_arglist (param_list
);
1273 gfc_free_actual_arglist (param_list
);
1275 if (!expr
->ts
.u
.derived
->attr
.pdt_type
)
1280 cons
= gfc_constructor_first (expr
->value
.constructor
);
1282 /* A constructor may have references if it is the result of substituting a
1283 parameter variable. In this case we just pull out the component we
1286 comp
= expr
->ref
->u
.c
.sym
->components
;
1288 comp
= expr
->ts
.u
.derived
->components
;
1290 for (; comp
&& cons
; comp
= comp
->next
, cons
= gfc_constructor_next (cons
))
1297 /* Unions use an EXPR_NULL contrived expression to tell the translation
1298 phase to generate an initializer of the appropriate length.
1300 if (cons
->expr
->ts
.type
== BT_UNION
&& cons
->expr
->expr_type
== EXPR_NULL
)
1303 if (!gfc_resolve_expr (cons
->expr
))
1309 rank
= comp
->as
? comp
->as
->rank
: 0;
1310 if (comp
->ts
.type
== BT_CLASS
1311 && !comp
->ts
.u
.derived
->attr
.unlimited_polymorphic
1312 && CLASS_DATA (comp
)->as
)
1313 rank
= CLASS_DATA (comp
)->as
->rank
;
1315 if (cons
->expr
->expr_type
!= EXPR_NULL
&& rank
!= cons
->expr
->rank
1316 && (comp
->attr
.allocatable
|| cons
->expr
->rank
))
1318 gfc_error ("The rank of the element in the structure "
1319 "constructor at %L does not match that of the "
1320 "component (%d/%d)", &cons
->expr
->where
,
1321 cons
->expr
->rank
, rank
);
1325 /* If we don't have the right type, try to convert it. */
1327 if (!comp
->attr
.proc_pointer
&&
1328 !gfc_compare_types (&cons
->expr
->ts
, &comp
->ts
))
1330 if (strcmp (comp
->name
, "_extends") == 0)
1332 /* Can afford to be brutal with the _extends initializer.
1333 The derived type can get lost because it is PRIVATE
1334 but it is not usage constrained by the standard. */
1335 cons
->expr
->ts
= comp
->ts
;
1337 else if (comp
->attr
.pointer
&& cons
->expr
->ts
.type
!= BT_UNKNOWN
)
1339 gfc_error ("The element in the structure constructor at %L, "
1340 "for pointer component %qs, is %s but should be %s",
1341 &cons
->expr
->where
, comp
->name
,
1342 gfc_basic_typename (cons
->expr
->ts
.type
),
1343 gfc_basic_typename (comp
->ts
.type
));
1348 bool t2
= gfc_convert_type (cons
->expr
, &comp
->ts
, 1);
1354 /* For strings, the length of the constructor should be the same as
1355 the one of the structure, ensure this if the lengths are known at
1356 compile time and when we are dealing with PARAMETER or structure
1358 if (cons
->expr
->ts
.type
== BT_CHARACTER
&& comp
->ts
.u
.cl
1359 && comp
->ts
.u
.cl
->length
1360 && comp
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1361 && cons
->expr
->ts
.u
.cl
&& cons
->expr
->ts
.u
.cl
->length
1362 && cons
->expr
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1363 && cons
->expr
->rank
!= 0
1364 && mpz_cmp (cons
->expr
->ts
.u
.cl
->length
->value
.integer
,
1365 comp
->ts
.u
.cl
->length
->value
.integer
) != 0)
1367 if (cons
->expr
->expr_type
== EXPR_VARIABLE
1368 && cons
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
)
1370 /* Wrap the parameter in an array constructor (EXPR_ARRAY)
1371 to make use of the gfc_resolve_character_array_constructor
1372 machinery. The expression is later simplified away to
1373 an array of string literals. */
1374 gfc_expr
*para
= cons
->expr
;
1375 cons
->expr
= gfc_get_expr ();
1376 cons
->expr
->ts
= para
->ts
;
1377 cons
->expr
->where
= para
->where
;
1378 cons
->expr
->expr_type
= EXPR_ARRAY
;
1379 cons
->expr
->rank
= para
->rank
;
1380 cons
->expr
->shape
= gfc_copy_shape (para
->shape
, para
->rank
);
1381 gfc_constructor_append_expr (&cons
->expr
->value
.constructor
,
1382 para
, &cons
->expr
->where
);
1385 if (cons
->expr
->expr_type
== EXPR_ARRAY
)
1387 /* Rely on the cleanup of the namespace to deal correctly with
1388 the old charlen. (There was a block here that attempted to
1389 remove the charlen but broke the chain in so doing.) */
1390 cons
->expr
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
1391 cons
->expr
->ts
.u
.cl
->length_from_typespec
= true;
1392 cons
->expr
->ts
.u
.cl
->length
= gfc_copy_expr (comp
->ts
.u
.cl
->length
);
1393 gfc_resolve_character_array_constructor (cons
->expr
);
1397 if (cons
->expr
->expr_type
== EXPR_NULL
1398 && !(comp
->attr
.pointer
|| comp
->attr
.allocatable
1399 || comp
->attr
.proc_pointer
|| comp
->ts
.f90_type
== BT_VOID
1400 || (comp
->ts
.type
== BT_CLASS
1401 && (CLASS_DATA (comp
)->attr
.class_pointer
1402 || CLASS_DATA (comp
)->attr
.allocatable
))))
1405 gfc_error ("The NULL in the structure constructor at %L is "
1406 "being applied to component %qs, which is neither "
1407 "a POINTER nor ALLOCATABLE", &cons
->expr
->where
,
1411 if (comp
->attr
.proc_pointer
&& comp
->ts
.interface
)
1413 /* Check procedure pointer interface. */
1414 gfc_symbol
*s2
= NULL
;
1419 c2
= gfc_get_proc_ptr_comp (cons
->expr
);
1422 s2
= c2
->ts
.interface
;
1425 else if (cons
->expr
->expr_type
== EXPR_FUNCTION
)
1427 s2
= cons
->expr
->symtree
->n
.sym
->result
;
1428 name
= cons
->expr
->symtree
->n
.sym
->result
->name
;
1430 else if (cons
->expr
->expr_type
!= EXPR_NULL
)
1432 s2
= cons
->expr
->symtree
->n
.sym
;
1433 name
= cons
->expr
->symtree
->n
.sym
->name
;
1436 if (s2
&& !gfc_compare_interfaces (comp
->ts
.interface
, s2
, name
, 0, 1,
1437 err
, sizeof (err
), NULL
, NULL
))
1439 gfc_error_opt (0, "Interface mismatch for procedure-pointer "
1440 "component %qs in structure constructor at %L:"
1441 " %s", comp
->name
, &cons
->expr
->where
, err
);
1446 if (!comp
->attr
.pointer
|| comp
->attr
.proc_pointer
1447 || cons
->expr
->expr_type
== EXPR_NULL
)
1450 a
= gfc_expr_attr (cons
->expr
);
1452 if (!a
.pointer
&& !a
.target
)
1455 gfc_error ("The element in the structure constructor at %L, "
1456 "for pointer component %qs should be a POINTER or "
1457 "a TARGET", &cons
->expr
->where
, comp
->name
);
1462 /* F08:C461. Additional checks for pointer initialization. */
1466 gfc_error ("Pointer initialization target at %L "
1467 "must not be ALLOCATABLE", &cons
->expr
->where
);
1472 gfc_error ("Pointer initialization target at %L "
1473 "must have the SAVE attribute", &cons
->expr
->where
);
1477 /* F2003, C1272 (3). */
1478 bool impure
= cons
->expr
->expr_type
== EXPR_VARIABLE
1479 && (gfc_impure_variable (cons
->expr
->symtree
->n
.sym
)
1480 || gfc_is_coindexed (cons
->expr
));
1481 if (impure
&& gfc_pure (NULL
))
1484 gfc_error ("Invalid expression in the structure constructor for "
1485 "pointer component %qs at %L in PURE procedure",
1486 comp
->name
, &cons
->expr
->where
);
1490 gfc_unset_implicit_pure (NULL
);
1497 /****************** Expression name resolution ******************/
1499 /* Returns 0 if a symbol was not declared with a type or
1500 attribute declaration statement, nonzero otherwise. */
1503 was_declared (gfc_symbol
*sym
)
1509 if (!a
.implicit_type
&& sym
->ts
.type
!= BT_UNKNOWN
)
1512 if (a
.allocatable
|| a
.dimension
|| a
.dummy
|| a
.external
|| a
.intrinsic
1513 || a
.optional
|| a
.pointer
|| a
.save
|| a
.target
|| a
.volatile_
1514 || a
.value
|| a
.access
!= ACCESS_UNKNOWN
|| a
.intent
!= INTENT_UNKNOWN
1515 || a
.asynchronous
|| a
.codimension
)
1522 /* Determine if a symbol is generic or not. */
1525 generic_sym (gfc_symbol
*sym
)
1529 if (sym
->attr
.generic
||
1530 (sym
->attr
.intrinsic
&& gfc_generic_intrinsic (sym
->name
)))
1533 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1536 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1543 return generic_sym (s
);
1550 /* Determine if a symbol is specific or not. */
1553 specific_sym (gfc_symbol
*sym
)
1557 if (sym
->attr
.if_source
== IFSRC_IFBODY
1558 || sym
->attr
.proc
== PROC_MODULE
1559 || sym
->attr
.proc
== PROC_INTERNAL
1560 || sym
->attr
.proc
== PROC_ST_FUNCTION
1561 || (sym
->attr
.intrinsic
&& gfc_specific_intrinsic (sym
->name
))
1562 || sym
->attr
.external
)
1565 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1568 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1570 return (s
== NULL
) ? 0 : specific_sym (s
);
1574 /* Figure out if the procedure is specific, generic or unknown. */
1577 { PTYPE_GENERIC
= 1, PTYPE_SPECIFIC
, PTYPE_UNKNOWN
};
1580 procedure_kind (gfc_symbol
*sym
)
1582 if (generic_sym (sym
))
1583 return PTYPE_GENERIC
;
1585 if (specific_sym (sym
))
1586 return PTYPE_SPECIFIC
;
1588 return PTYPE_UNKNOWN
;
1591 /* Check references to assumed size arrays. The flag need_full_assumed_size
1592 is nonzero when matching actual arguments. */
1594 static int need_full_assumed_size
= 0;
1597 check_assumed_size_reference (gfc_symbol
*sym
, gfc_expr
*e
)
1599 if (need_full_assumed_size
|| !(sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
))
1602 /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong.
1603 What should it be? */
1604 if (e
->ref
&& (e
->ref
->u
.ar
.end
[e
->ref
->u
.ar
.as
->rank
- 1] == NULL
)
1605 && (e
->ref
->u
.ar
.as
->type
== AS_ASSUMED_SIZE
)
1606 && (e
->ref
->u
.ar
.type
== AR_FULL
))
1608 gfc_error ("The upper bound in the last dimension must "
1609 "appear in the reference to the assumed size "
1610 "array %qs at %L", sym
->name
, &e
->where
);
1617 /* Look for bad assumed size array references in argument expressions
1618 of elemental and array valued intrinsic procedures. Since this is
1619 called from procedure resolution functions, it only recurses at
1623 resolve_assumed_size_actual (gfc_expr
*e
)
1628 switch (e
->expr_type
)
1631 if (e
->symtree
&& check_assumed_size_reference (e
->symtree
->n
.sym
, e
))
1636 if (resolve_assumed_size_actual (e
->value
.op
.op1
)
1637 || resolve_assumed_size_actual (e
->value
.op
.op2
))
1648 /* Check a generic procedure, passed as an actual argument, to see if
1649 there is a matching specific name. If none, it is an error, and if
1650 more than one, the reference is ambiguous. */
1652 count_specific_procs (gfc_expr
*e
)
1659 sym
= e
->symtree
->n
.sym
;
1661 for (p
= sym
->generic
; p
; p
= p
->next
)
1662 if (strcmp (sym
->name
, p
->sym
->name
) == 0)
1664 e
->symtree
= gfc_find_symtree (p
->sym
->ns
->sym_root
,
1670 gfc_error ("%qs at %L is ambiguous", e
->symtree
->n
.sym
->name
,
1674 gfc_error ("GENERIC procedure %qs is not allowed as an actual "
1675 "argument at %L", sym
->name
, &e
->where
);
1681 /* See if a call to sym could possibly be a not allowed RECURSION because of
1682 a missing RECURSIVE declaration. This means that either sym is the current
1683 context itself, or sym is the parent of a contained procedure calling its
1684 non-RECURSIVE containing procedure.
1685 This also works if sym is an ENTRY. */
1688 is_illegal_recursion (gfc_symbol
* sym
, gfc_namespace
* context
)
1690 gfc_symbol
* proc_sym
;
1691 gfc_symbol
* context_proc
;
1692 gfc_namespace
* real_context
;
1694 if (sym
->attr
.flavor
== FL_PROGRAM
1695 || gfc_fl_struct (sym
->attr
.flavor
))
1698 /* If we've got an ENTRY, find real procedure. */
1699 if (sym
->attr
.entry
&& sym
->ns
->entries
)
1700 proc_sym
= sym
->ns
->entries
->sym
;
1704 /* If sym is RECURSIVE, all is well of course. */
1705 if (proc_sym
->attr
.recursive
|| flag_recursive
)
1708 /* Find the context procedure's "real" symbol if it has entries.
1709 We look for a procedure symbol, so recurse on the parents if we don't
1710 find one (like in case of a BLOCK construct). */
1711 for (real_context
= context
; ; real_context
= real_context
->parent
)
1713 /* We should find something, eventually! */
1714 gcc_assert (real_context
);
1716 context_proc
= (real_context
->entries
? real_context
->entries
->sym
1717 : real_context
->proc_name
);
1719 /* In some special cases, there may not be a proc_name, like for this
1721 real(bad_kind()) function foo () ...
1722 when checking the call to bad_kind ().
1723 In these cases, we simply return here and assume that the
1728 if (context_proc
->attr
.flavor
!= FL_LABEL
)
1732 /* A call from sym's body to itself is recursion, of course. */
1733 if (context_proc
== proc_sym
)
1736 /* The same is true if context is a contained procedure and sym the
1738 if (context_proc
->attr
.contained
)
1740 gfc_symbol
* parent_proc
;
1742 gcc_assert (context
->parent
);
1743 parent_proc
= (context
->parent
->entries
? context
->parent
->entries
->sym
1744 : context
->parent
->proc_name
);
1746 if (parent_proc
== proc_sym
)
1754 /* Resolve an intrinsic procedure: Set its function/subroutine attribute,
1755 its typespec and formal argument list. */
1758 gfc_resolve_intrinsic (gfc_symbol
*sym
, locus
*loc
)
1760 gfc_intrinsic_sym
* isym
= NULL
;
1763 if (sym
->resolve_symbol_called
>= 2)
1766 sym
->resolve_symbol_called
= 2;
1768 /* Already resolved. */
1769 if (sym
->from_intmod
&& sym
->ts
.type
!= BT_UNKNOWN
)
1772 /* We already know this one is an intrinsic, so we don't call
1773 gfc_is_intrinsic for full checking but rather use gfc_find_function and
1774 gfc_find_subroutine directly to check whether it is a function or
1777 if (sym
->intmod_sym_id
&& sym
->attr
.subroutine
)
1779 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1780 isym
= gfc_intrinsic_subroutine_by_id (id
);
1782 else if (sym
->intmod_sym_id
)
1784 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1785 isym
= gfc_intrinsic_function_by_id (id
);
1787 else if (!sym
->attr
.subroutine
)
1788 isym
= gfc_find_function (sym
->name
);
1790 if (isym
&& !sym
->attr
.subroutine
)
1792 if (sym
->ts
.type
!= BT_UNKNOWN
&& warn_surprising
1793 && !sym
->attr
.implicit_type
)
1794 gfc_warning (OPT_Wsurprising
,
1795 "Type specified for intrinsic function %qs at %L is"
1796 " ignored", sym
->name
, &sym
->declared_at
);
1798 if (!sym
->attr
.function
&&
1799 !gfc_add_function(&sym
->attr
, sym
->name
, loc
))
1804 else if (isym
|| (isym
= gfc_find_subroutine (sym
->name
)))
1806 if (sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.implicit_type
)
1808 gfc_error ("Intrinsic subroutine %qs at %L shall not have a type"
1809 " specifier", sym
->name
, &sym
->declared_at
);
1813 if (!sym
->attr
.subroutine
&&
1814 !gfc_add_subroutine(&sym
->attr
, sym
->name
, loc
))
1819 gfc_error ("%qs declared INTRINSIC at %L does not exist", sym
->name
,
1824 gfc_copy_formal_args_intr (sym
, isym
, NULL
);
1826 sym
->attr
.pure
= isym
->pure
;
1827 sym
->attr
.elemental
= isym
->elemental
;
1829 /* Check it is actually available in the standard settings. */
1830 if (!gfc_check_intrinsic_standard (isym
, &symstd
, false, sym
->declared_at
))
1832 gfc_error ("The intrinsic %qs declared INTRINSIC at %L is not "
1833 "available in the current standard settings but %s. Use "
1834 "an appropriate %<-std=*%> option or enable "
1835 "%<-fall-intrinsics%> in order to use it.",
1836 sym
->name
, &sym
->declared_at
, symstd
);
1844 /* Resolve a procedure expression, like passing it to a called procedure or as
1845 RHS for a procedure pointer assignment. */
1848 resolve_procedure_expression (gfc_expr
* expr
)
1852 if (expr
->expr_type
!= EXPR_VARIABLE
)
1854 gcc_assert (expr
->symtree
);
1856 sym
= expr
->symtree
->n
.sym
;
1858 if (sym
->attr
.intrinsic
)
1859 gfc_resolve_intrinsic (sym
, &expr
->where
);
1861 if (sym
->attr
.flavor
!= FL_PROCEDURE
1862 || (sym
->attr
.function
&& sym
->result
== sym
))
1865 /* A non-RECURSIVE procedure that is used as procedure expression within its
1866 own body is in danger of being called recursively. */
1867 if (is_illegal_recursion (sym
, gfc_current_ns
))
1868 gfc_warning (0, "Non-RECURSIVE procedure %qs at %L is possibly calling"
1869 " itself recursively. Declare it RECURSIVE or use"
1870 " %<-frecursive%>", sym
->name
, &expr
->where
);
1876 /* Check that name is not a derived type. */
1879 is_dt_name (const char *name
)
1881 gfc_symbol
*dt_list
, *dt_first
;
1883 dt_list
= dt_first
= gfc_derived_types
;
1884 for (; dt_list
; dt_list
= dt_list
->dt_next
)
1886 if (strcmp(dt_list
->name
, name
) == 0)
1888 if (dt_first
== dt_list
->dt_next
)
1895 /* Resolve an actual argument list. Most of the time, this is just
1896 resolving the expressions in the list.
1897 The exception is that we sometimes have to decide whether arguments
1898 that look like procedure arguments are really simple variable
1902 resolve_actual_arglist (gfc_actual_arglist
*arg
, procedure_type ptype
,
1903 bool no_formal_args
)
1906 gfc_symtree
*parent_st
;
1908 gfc_component
*comp
;
1909 int save_need_full_assumed_size
;
1910 bool return_value
= false;
1911 bool actual_arg_sav
= actual_arg
, first_actual_arg_sav
= first_actual_arg
;
1914 first_actual_arg
= true;
1916 for (; arg
; arg
= arg
->next
)
1921 /* Check the label is a valid branching target. */
1924 if (arg
->label
->defined
== ST_LABEL_UNKNOWN
)
1926 gfc_error ("Label %d referenced at %L is never defined",
1927 arg
->label
->value
, &arg
->label
->where
);
1931 first_actual_arg
= false;
1935 if (e
->expr_type
== EXPR_VARIABLE
1936 && e
->symtree
->n
.sym
->attr
.generic
1938 && count_specific_procs (e
) != 1)
1941 if (e
->ts
.type
!= BT_PROCEDURE
)
1943 save_need_full_assumed_size
= need_full_assumed_size
;
1944 if (e
->expr_type
!= EXPR_VARIABLE
)
1945 need_full_assumed_size
= 0;
1946 if (!gfc_resolve_expr (e
))
1948 need_full_assumed_size
= save_need_full_assumed_size
;
1952 /* See if the expression node should really be a variable reference. */
1954 sym
= e
->symtree
->n
.sym
;
1956 if (sym
->attr
.flavor
== FL_PROCEDURE
&& is_dt_name (sym
->name
))
1958 gfc_error ("Derived type %qs is used as an actual "
1959 "argument at %L", sym
->name
, &e
->where
);
1963 if (sym
->attr
.flavor
== FL_PROCEDURE
1964 || sym
->attr
.intrinsic
1965 || sym
->attr
.external
)
1969 /* If a procedure is not already determined to be something else
1970 check if it is intrinsic. */
1971 if (gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, e
->where
))
1972 sym
->attr
.intrinsic
= 1;
1974 if (sym
->attr
.proc
== PROC_ST_FUNCTION
)
1976 gfc_error ("Statement function %qs at %L is not allowed as an "
1977 "actual argument", sym
->name
, &e
->where
);
1980 actual_ok
= gfc_intrinsic_actual_ok (sym
->name
,
1981 sym
->attr
.subroutine
);
1982 if (sym
->attr
.intrinsic
&& actual_ok
== 0)
1984 gfc_error ("Intrinsic %qs at %L is not allowed as an "
1985 "actual argument", sym
->name
, &e
->where
);
1988 if (sym
->attr
.contained
&& !sym
->attr
.use_assoc
1989 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
1991 if (!gfc_notify_std (GFC_STD_F2008
, "Internal procedure %qs is"
1992 " used as actual argument at %L",
1993 sym
->name
, &e
->where
))
1997 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
)
1999 gfc_error ("ELEMENTAL non-INTRINSIC procedure %qs is not "
2000 "allowed as an actual argument at %L", sym
->name
,
2004 /* Check if a generic interface has a specific procedure
2005 with the same name before emitting an error. */
2006 if (sym
->attr
.generic
&& count_specific_procs (e
) != 1)
2009 /* Just in case a specific was found for the expression. */
2010 sym
= e
->symtree
->n
.sym
;
2012 /* If the symbol is the function that names the current (or
2013 parent) scope, then we really have a variable reference. */
2015 if (gfc_is_function_return_value (sym
, sym
->ns
))
2018 /* If all else fails, see if we have a specific intrinsic. */
2019 if (sym
->ts
.type
== BT_UNKNOWN
&& sym
->attr
.intrinsic
)
2021 gfc_intrinsic_sym
*isym
;
2023 isym
= gfc_find_function (sym
->name
);
2024 if (isym
== NULL
|| !isym
->specific
)
2026 gfc_error ("Unable to find a specific INTRINSIC procedure "
2027 "for the reference %qs at %L", sym
->name
,
2032 sym
->attr
.intrinsic
= 1;
2033 sym
->attr
.function
= 1;
2036 if (!gfc_resolve_expr (e
))
2041 /* See if the name is a module procedure in a parent unit. */
2043 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
2046 if (gfc_find_sym_tree (sym
->name
, sym
->ns
->parent
, 1, &parent_st
))
2048 gfc_error ("Symbol %qs at %L is ambiguous", sym
->name
, &e
->where
);
2052 if (parent_st
== NULL
)
2055 sym
= parent_st
->n
.sym
;
2056 e
->symtree
= parent_st
; /* Point to the right thing. */
2058 if (sym
->attr
.flavor
== FL_PROCEDURE
2059 || sym
->attr
.intrinsic
2060 || sym
->attr
.external
)
2062 if (!gfc_resolve_expr (e
))
2068 e
->expr_type
= EXPR_VARIABLE
;
2070 if ((sym
->as
!= NULL
&& sym
->ts
.type
!= BT_CLASS
)
2071 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
2072 && CLASS_DATA (sym
)->as
))
2074 e
->rank
= sym
->ts
.type
== BT_CLASS
2075 ? CLASS_DATA (sym
)->as
->rank
: sym
->as
->rank
;
2076 e
->ref
= gfc_get_ref ();
2077 e
->ref
->type
= REF_ARRAY
;
2078 e
->ref
->u
.ar
.type
= AR_FULL
;
2079 e
->ref
->u
.ar
.as
= sym
->ts
.type
== BT_CLASS
2080 ? CLASS_DATA (sym
)->as
: sym
->as
;
2083 /* Expressions are assigned a default ts.type of BT_PROCEDURE in
2084 primary.c (match_actual_arg). If above code determines that it
2085 is a variable instead, it needs to be resolved as it was not
2086 done at the beginning of this function. */
2087 save_need_full_assumed_size
= need_full_assumed_size
;
2088 if (e
->expr_type
!= EXPR_VARIABLE
)
2089 need_full_assumed_size
= 0;
2090 if (!gfc_resolve_expr (e
))
2092 need_full_assumed_size
= save_need_full_assumed_size
;
2095 /* Check argument list functions %VAL, %LOC and %REF. There is
2096 nothing to do for %REF. */
2097 if (arg
->name
&& arg
->name
[0] == '%')
2099 if (strcmp ("%VAL", arg
->name
) == 0)
2101 if (e
->ts
.type
== BT_CHARACTER
|| e
->ts
.type
== BT_DERIVED
)
2103 gfc_error ("By-value argument at %L is not of numeric "
2110 gfc_error ("By-value argument at %L cannot be an array or "
2111 "an array section", &e
->where
);
2115 /* Intrinsics are still PROC_UNKNOWN here. However,
2116 since same file external procedures are not resolvable
2117 in gfortran, it is a good deal easier to leave them to
2119 if (ptype
!= PROC_UNKNOWN
2120 && ptype
!= PROC_DUMMY
2121 && ptype
!= PROC_EXTERNAL
2122 && ptype
!= PROC_MODULE
)
2124 gfc_error ("By-value argument at %L is not allowed "
2125 "in this context", &e
->where
);
2130 /* Statement functions have already been excluded above. */
2131 else if (strcmp ("%LOC", arg
->name
) == 0
2132 && e
->ts
.type
== BT_PROCEDURE
)
2134 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_INTERNAL
)
2136 gfc_error ("Passing internal procedure at %L by location "
2137 "not allowed", &e
->where
);
2143 comp
= gfc_get_proc_ptr_comp(e
);
2144 if (e
->expr_type
== EXPR_VARIABLE
2145 && comp
&& comp
->attr
.elemental
)
2147 gfc_error ("ELEMENTAL procedure pointer component %qs is not "
2148 "allowed as an actual argument at %L", comp
->name
,
2152 /* Fortran 2008, C1237. */
2153 if (e
->expr_type
== EXPR_VARIABLE
&& gfc_is_coindexed (e
)
2154 && gfc_has_ultimate_pointer (e
))
2156 gfc_error ("Coindexed actual argument at %L with ultimate pointer "
2157 "component", &e
->where
);
2161 first_actual_arg
= false;
2164 return_value
= true;
2167 actual_arg
= actual_arg_sav
;
2168 first_actual_arg
= first_actual_arg_sav
;
2170 return return_value
;
2174 /* Do the checks of the actual argument list that are specific to elemental
2175 procedures. If called with c == NULL, we have a function, otherwise if
2176 expr == NULL, we have a subroutine. */
2179 resolve_elemental_actual (gfc_expr
*expr
, gfc_code
*c
)
2181 gfc_actual_arglist
*arg0
;
2182 gfc_actual_arglist
*arg
;
2183 gfc_symbol
*esym
= NULL
;
2184 gfc_intrinsic_sym
*isym
= NULL
;
2186 gfc_intrinsic_arg
*iformal
= NULL
;
2187 gfc_formal_arglist
*eformal
= NULL
;
2188 bool formal_optional
= false;
2189 bool set_by_optional
= false;
2193 /* Is this an elemental procedure? */
2194 if (expr
&& expr
->value
.function
.actual
!= NULL
)
2196 if (expr
->value
.function
.esym
!= NULL
2197 && expr
->value
.function
.esym
->attr
.elemental
)
2199 arg0
= expr
->value
.function
.actual
;
2200 esym
= expr
->value
.function
.esym
;
2202 else if (expr
->value
.function
.isym
!= NULL
2203 && expr
->value
.function
.isym
->elemental
)
2205 arg0
= expr
->value
.function
.actual
;
2206 isym
= expr
->value
.function
.isym
;
2211 else if (c
&& c
->ext
.actual
!= NULL
)
2213 arg0
= c
->ext
.actual
;
2215 if (c
->resolved_sym
)
2216 esym
= c
->resolved_sym
;
2218 esym
= c
->symtree
->n
.sym
;
2221 if (!esym
->attr
.elemental
)
2227 /* The rank of an elemental is the rank of its array argument(s). */
2228 for (arg
= arg0
; arg
; arg
= arg
->next
)
2230 if (arg
->expr
!= NULL
&& arg
->expr
->rank
!= 0)
2232 rank
= arg
->expr
->rank
;
2233 if (arg
->expr
->expr_type
== EXPR_VARIABLE
2234 && arg
->expr
->symtree
->n
.sym
->attr
.optional
)
2235 set_by_optional
= true;
2237 /* Function specific; set the result rank and shape. */
2241 if (!expr
->shape
&& arg
->expr
->shape
)
2243 expr
->shape
= gfc_get_shape (rank
);
2244 for (i
= 0; i
< rank
; i
++)
2245 mpz_init_set (expr
->shape
[i
], arg
->expr
->shape
[i
]);
2252 /* If it is an array, it shall not be supplied as an actual argument
2253 to an elemental procedure unless an array of the same rank is supplied
2254 as an actual argument corresponding to a nonoptional dummy argument of
2255 that elemental procedure(12.4.1.5). */
2256 formal_optional
= false;
2258 iformal
= isym
->formal
;
2260 eformal
= esym
->formal
;
2262 for (arg
= arg0
; arg
; arg
= arg
->next
)
2266 if (eformal
->sym
&& eformal
->sym
->attr
.optional
)
2267 formal_optional
= true;
2268 eformal
= eformal
->next
;
2270 else if (isym
&& iformal
)
2272 if (iformal
->optional
)
2273 formal_optional
= true;
2274 iformal
= iformal
->next
;
2277 formal_optional
= true;
2279 if (pedantic
&& arg
->expr
!= NULL
2280 && arg
->expr
->expr_type
== EXPR_VARIABLE
2281 && arg
->expr
->symtree
->n
.sym
->attr
.optional
2284 && (set_by_optional
|| arg
->expr
->rank
!= rank
)
2285 && !(isym
&& isym
->id
== GFC_ISYM_CONVERSION
))
2288 gfc_actual_arglist
*a
;
2290 /* Scan the argument list for a non-optional argument with the
2291 same rank as arg. */
2292 for (a
= arg0
; a
; a
= a
->next
)
2294 && a
->expr
->rank
== arg
->expr
->rank
2295 && !a
->expr
->symtree
->n
.sym
->attr
.optional
)
2302 gfc_warning (OPT_Wpedantic
,
2303 "%qs at %L is an array and OPTIONAL; If it is not "
2304 "present, then it cannot be the actual argument of "
2305 "an ELEMENTAL procedure unless there is a non-optional"
2306 " argument with the same rank "
2307 "(Fortran 2018, 15.5.2.12)",
2308 arg
->expr
->symtree
->n
.sym
->name
, &arg
->expr
->where
);
2312 for (arg
= arg0
; arg
; arg
= arg
->next
)
2314 if (arg
->expr
== NULL
|| arg
->expr
->rank
== 0)
2317 /* Being elemental, the last upper bound of an assumed size array
2318 argument must be present. */
2319 if (resolve_assumed_size_actual (arg
->expr
))
2322 /* Elemental procedure's array actual arguments must conform. */
2325 if (!gfc_check_conformance (arg
->expr
, e
, _("elemental procedure")))
2332 /* INTENT(OUT) is only allowed for subroutines; if any actual argument
2333 is an array, the intent inout/out variable needs to be also an array. */
2334 if (rank
> 0 && esym
&& expr
== NULL
)
2335 for (eformal
= esym
->formal
, arg
= arg0
; arg
&& eformal
;
2336 arg
= arg
->next
, eformal
= eformal
->next
)
2337 if ((eformal
->sym
->attr
.intent
== INTENT_OUT
2338 || eformal
->sym
->attr
.intent
== INTENT_INOUT
)
2339 && arg
->expr
&& arg
->expr
->rank
== 0)
2341 gfc_error ("Actual argument at %L for INTENT(%s) dummy %qs of "
2342 "ELEMENTAL subroutine %qs is a scalar, but another "
2343 "actual argument is an array", &arg
->expr
->where
,
2344 (eformal
->sym
->attr
.intent
== INTENT_OUT
) ? "OUT"
2345 : "INOUT", eformal
->sym
->name
, esym
->name
);
2352 /* This function does the checking of references to global procedures
2353 as defined in sections 18.1 and 14.1, respectively, of the Fortran
2354 77 and 95 standards. It checks for a gsymbol for the name, making
2355 one if it does not already exist. If it already exists, then the
2356 reference being resolved must correspond to the type of gsymbol.
2357 Otherwise, the new symbol is equipped with the attributes of the
2358 reference. The corresponding code that is called in creating
2359 global entities is parse.c.
2361 In addition, for all but -std=legacy, the gsymbols are used to
2362 check the interfaces of external procedures from the same file.
2363 The namespace of the gsymbol is resolved and then, once this is
2364 done the interface is checked. */
2368 not_in_recursive (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2370 if (!gsym_ns
->proc_name
->attr
.recursive
)
2373 if (sym
->ns
== gsym_ns
)
2376 if (sym
->ns
->parent
&& sym
->ns
->parent
== gsym_ns
)
2383 not_entry_self_reference (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2385 if (gsym_ns
->entries
)
2387 gfc_entry_list
*entry
= gsym_ns
->entries
;
2389 for (; entry
; entry
= entry
->next
)
2391 if (strcmp (sym
->name
, entry
->sym
->name
) == 0)
2393 if (strcmp (gsym_ns
->proc_name
->name
,
2394 sym
->ns
->proc_name
->name
) == 0)
2398 && strcmp (gsym_ns
->proc_name
->name
,
2399 sym
->ns
->parent
->proc_name
->name
) == 0)
2408 /* Check for the requirement of an explicit interface. F08:12.4.2.2. */
2411 gfc_explicit_interface_required (gfc_symbol
*sym
, char *errmsg
, int err_len
)
2413 gfc_formal_arglist
*arg
= gfc_sym_get_dummy_args (sym
);
2415 for ( ; arg
; arg
= arg
->next
)
2420 if (arg
->sym
->attr
.allocatable
) /* (2a) */
2422 strncpy (errmsg
, _("allocatable argument"), err_len
);
2425 else if (arg
->sym
->attr
.asynchronous
)
2427 strncpy (errmsg
, _("asynchronous argument"), err_len
);
2430 else if (arg
->sym
->attr
.optional
)
2432 strncpy (errmsg
, _("optional argument"), err_len
);
2435 else if (arg
->sym
->attr
.pointer
)
2437 strncpy (errmsg
, _("pointer argument"), err_len
);
2440 else if (arg
->sym
->attr
.target
)
2442 strncpy (errmsg
, _("target argument"), err_len
);
2445 else if (arg
->sym
->attr
.value
)
2447 strncpy (errmsg
, _("value argument"), err_len
);
2450 else if (arg
->sym
->attr
.volatile_
)
2452 strncpy (errmsg
, _("volatile argument"), err_len
);
2455 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_SHAPE
) /* (2b) */
2457 strncpy (errmsg
, _("assumed-shape argument"), err_len
);
2460 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_RANK
) /* TS 29113, 6.2. */
2462 strncpy (errmsg
, _("assumed-rank argument"), err_len
);
2465 else if (arg
->sym
->attr
.codimension
) /* (2c) */
2467 strncpy (errmsg
, _("coarray argument"), err_len
);
2470 else if (false) /* (2d) TODO: parametrized derived type */
2472 strncpy (errmsg
, _("parametrized derived type argument"), err_len
);
2475 else if (arg
->sym
->ts
.type
== BT_CLASS
) /* (2e) */
2477 strncpy (errmsg
, _("polymorphic argument"), err_len
);
2480 else if (arg
->sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
2482 strncpy (errmsg
, _("NO_ARG_CHECK attribute"), err_len
);
2485 else if (arg
->sym
->ts
.type
== BT_ASSUMED
)
2487 /* As assumed-type is unlimited polymorphic (cf. above).
2488 See also TS 29113, Note 6.1. */
2489 strncpy (errmsg
, _("assumed-type argument"), err_len
);
2494 if (sym
->attr
.function
)
2496 gfc_symbol
*res
= sym
->result
? sym
->result
: sym
;
2498 if (res
->attr
.dimension
) /* (3a) */
2500 strncpy (errmsg
, _("array result"), err_len
);
2503 else if (res
->attr
.pointer
|| res
->attr
.allocatable
) /* (3b) */
2505 strncpy (errmsg
, _("pointer or allocatable result"), err_len
);
2508 else if (res
->ts
.type
== BT_CHARACTER
&& res
->ts
.u
.cl
2509 && res
->ts
.u
.cl
->length
2510 && res
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
) /* (3c) */
2512 strncpy (errmsg
, _("result with non-constant character length"), err_len
);
2517 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
) /* (4) */
2519 strncpy (errmsg
, _("elemental procedure"), err_len
);
2522 else if (sym
->attr
.is_bind_c
) /* (5) */
2524 strncpy (errmsg
, _("bind(c) procedure"), err_len
);
2533 resolve_global_procedure (gfc_symbol
*sym
, locus
*where
, int sub
)
2537 enum gfc_symbol_type type
;
2540 type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
2542 gsym
= gfc_get_gsymbol (sym
->binding_label
? sym
->binding_label
: sym
->name
,
2543 sym
->binding_label
!= NULL
);
2545 if ((gsym
->type
!= GSYM_UNKNOWN
&& gsym
->type
!= type
))
2546 gfc_global_used (gsym
, where
);
2548 if ((sym
->attr
.if_source
== IFSRC_UNKNOWN
2549 || sym
->attr
.if_source
== IFSRC_IFBODY
)
2550 && gsym
->type
!= GSYM_UNKNOWN
2551 && !gsym
->binding_label
2553 && gsym
->ns
->proc_name
2554 && not_in_recursive (sym
, gsym
->ns
)
2555 && not_entry_self_reference (sym
, gsym
->ns
))
2557 gfc_symbol
*def_sym
;
2558 def_sym
= gsym
->ns
->proc_name
;
2560 if (gsym
->ns
->resolved
!= -1)
2563 /* Resolve the gsymbol namespace if needed. */
2564 if (!gsym
->ns
->resolved
)
2566 gfc_symbol
*old_dt_list
;
2568 /* Stash away derived types so that the backend_decls
2569 do not get mixed up. */
2570 old_dt_list
= gfc_derived_types
;
2571 gfc_derived_types
= NULL
;
2573 gfc_resolve (gsym
->ns
);
2575 /* Store the new derived types with the global namespace. */
2576 if (gfc_derived_types
)
2577 gsym
->ns
->derived_types
= gfc_derived_types
;
2579 /* Restore the derived types of this namespace. */
2580 gfc_derived_types
= old_dt_list
;
2583 /* Make sure that translation for the gsymbol occurs before
2584 the procedure currently being resolved. */
2585 ns
= gfc_global_ns_list
;
2586 for (; ns
&& ns
!= gsym
->ns
; ns
= ns
->sibling
)
2588 if (ns
->sibling
== gsym
->ns
)
2590 ns
->sibling
= gsym
->ns
->sibling
;
2591 gsym
->ns
->sibling
= gfc_global_ns_list
;
2592 gfc_global_ns_list
= gsym
->ns
;
2597 /* This can happen if a binding name has been specified. */
2598 if (gsym
->binding_label
&& gsym
->sym_name
!= def_sym
->name
)
2599 gfc_find_symbol (gsym
->sym_name
, gsym
->ns
, 0, &def_sym
);
2601 if (def_sym
->attr
.entry_master
|| def_sym
->attr
.entry
)
2603 gfc_entry_list
*entry
;
2604 for (entry
= gsym
->ns
->entries
; entry
; entry
= entry
->next
)
2605 if (strcmp (entry
->sym
->name
, sym
->name
) == 0)
2607 def_sym
= entry
->sym
;
2613 if (sym
->attr
.function
&& !gfc_compare_types (&sym
->ts
, &def_sym
->ts
))
2615 gfc_error ("Return type mismatch of function %qs at %L (%s/%s)",
2616 sym
->name
, &sym
->declared_at
, gfc_typename (&sym
->ts
),
2617 gfc_typename (&def_sym
->ts
));
2621 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
2622 && gfc_explicit_interface_required (def_sym
, reason
, sizeof(reason
)))
2624 gfc_error ("Explicit interface required for %qs at %L: %s",
2625 sym
->name
, &sym
->declared_at
, reason
);
2629 bool bad_result_characteristics
;
2630 if (!gfc_compare_interfaces (sym
, def_sym
, sym
->name
, 0, 1,
2631 reason
, sizeof(reason
), NULL
, NULL
,
2632 &bad_result_characteristics
))
2634 /* Turn erros into warnings with -std=gnu and -std=legacy,
2635 unless a function returns a wrong type, which can lead
2636 to all kinds of ICEs and wrong code. */
2638 if (!pedantic
&& (gfc_option
.allow_std
& GFC_STD_GNU
)
2639 && !bad_result_characteristics
)
2640 gfc_errors_to_warnings (true);
2642 gfc_error ("Interface mismatch in global procedure %qs at %L: %s",
2643 sym
->name
, &sym
->declared_at
, reason
);
2645 gfc_errors_to_warnings (false);
2652 if (gsym
->type
== GSYM_UNKNOWN
)
2655 gsym
->where
= *where
;
2662 /************* Function resolution *************/
2664 /* Resolve a function call known to be generic.
2665 Section 14.1.2.4.1. */
2668 resolve_generic_f0 (gfc_expr
*expr
, gfc_symbol
*sym
)
2672 if (sym
->attr
.generic
)
2674 s
= gfc_search_interface (sym
->generic
, 0, &expr
->value
.function
.actual
);
2677 expr
->value
.function
.name
= s
->name
;
2678 expr
->value
.function
.esym
= s
;
2680 if (s
->ts
.type
!= BT_UNKNOWN
)
2682 else if (s
->result
!= NULL
&& s
->result
->ts
.type
!= BT_UNKNOWN
)
2683 expr
->ts
= s
->result
->ts
;
2686 expr
->rank
= s
->as
->rank
;
2687 else if (s
->result
!= NULL
&& s
->result
->as
!= NULL
)
2688 expr
->rank
= s
->result
->as
->rank
;
2690 gfc_set_sym_referenced (expr
->value
.function
.esym
);
2695 /* TODO: Need to search for elemental references in generic
2699 if (sym
->attr
.intrinsic
)
2700 return gfc_intrinsic_func_interface (expr
, 0);
2707 resolve_generic_f (gfc_expr
*expr
)
2711 gfc_interface
*intr
= NULL
;
2713 sym
= expr
->symtree
->n
.sym
;
2717 m
= resolve_generic_f0 (expr
, sym
);
2720 else if (m
== MATCH_ERROR
)
2725 for (intr
= sym
->generic
; intr
; intr
= intr
->next
)
2726 if (gfc_fl_struct (intr
->sym
->attr
.flavor
))
2729 if (sym
->ns
->parent
== NULL
)
2731 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2735 if (!generic_sym (sym
))
2739 /* Last ditch attempt. See if the reference is to an intrinsic
2740 that possesses a matching interface. 14.1.2.4 */
2741 if (sym
&& !intr
&& !gfc_is_intrinsic (sym
, 0, expr
->where
))
2743 if (gfc_init_expr_flag
)
2744 gfc_error ("Function %qs in initialization expression at %L "
2745 "must be an intrinsic function",
2746 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2748 gfc_error ("There is no specific function for the generic %qs "
2749 "at %L", expr
->symtree
->n
.sym
->name
, &expr
->where
);
2755 if (!gfc_convert_to_structure_constructor (expr
, intr
->sym
, NULL
,
2758 if (!gfc_use_derived (expr
->ts
.u
.derived
))
2760 return resolve_structure_cons (expr
, 0);
2763 m
= gfc_intrinsic_func_interface (expr
, 0);
2768 gfc_error ("Generic function %qs at %L is not consistent with a "
2769 "specific intrinsic interface", expr
->symtree
->n
.sym
->name
,
2776 /* Resolve a function call known to be specific. */
2779 resolve_specific_f0 (gfc_symbol
*sym
, gfc_expr
*expr
)
2783 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
2785 if (sym
->attr
.dummy
)
2787 sym
->attr
.proc
= PROC_DUMMY
;
2791 sym
->attr
.proc
= PROC_EXTERNAL
;
2795 if (sym
->attr
.proc
== PROC_MODULE
2796 || sym
->attr
.proc
== PROC_ST_FUNCTION
2797 || sym
->attr
.proc
== PROC_INTERNAL
)
2800 if (sym
->attr
.intrinsic
)
2802 m
= gfc_intrinsic_func_interface (expr
, 1);
2806 gfc_error ("Function %qs at %L is INTRINSIC but is not compatible "
2807 "with an intrinsic", sym
->name
, &expr
->where
);
2815 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2818 expr
->ts
= sym
->result
->ts
;
2821 expr
->value
.function
.name
= sym
->name
;
2822 expr
->value
.function
.esym
= sym
;
2823 /* Prevent crash when sym->ts.u.derived->components is not set due to previous
2825 if (sym
->ts
.type
== BT_CLASS
&& !CLASS_DATA (sym
))
2827 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->as
)
2828 expr
->rank
= CLASS_DATA (sym
)->as
->rank
;
2829 else if (sym
->as
!= NULL
)
2830 expr
->rank
= sym
->as
->rank
;
2837 resolve_specific_f (gfc_expr
*expr
)
2842 sym
= expr
->symtree
->n
.sym
;
2846 m
= resolve_specific_f0 (sym
, expr
);
2849 if (m
== MATCH_ERROR
)
2852 if (sym
->ns
->parent
== NULL
)
2855 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2861 gfc_error ("Unable to resolve the specific function %qs at %L",
2862 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2867 /* Recursively append candidate SYM to CANDIDATES. Store the number of
2868 candidates in CANDIDATES_LEN. */
2871 lookup_function_fuzzy_find_candidates (gfc_symtree
*sym
,
2873 size_t &candidates_len
)
2879 if ((sym
->n
.sym
->ts
.type
!= BT_UNKNOWN
|| sym
->n
.sym
->attr
.external
)
2880 && sym
->n
.sym
->attr
.flavor
== FL_PROCEDURE
)
2881 vec_push (candidates
, candidates_len
, sym
->name
);
2885 lookup_function_fuzzy_find_candidates (p
, candidates
, candidates_len
);
2889 lookup_function_fuzzy_find_candidates (p
, candidates
, candidates_len
);
2893 /* Lookup function FN fuzzily, taking names in SYMROOT into account. */
2896 gfc_lookup_function_fuzzy (const char *fn
, gfc_symtree
*symroot
)
2898 char **candidates
= NULL
;
2899 size_t candidates_len
= 0;
2900 lookup_function_fuzzy_find_candidates (symroot
, candidates
, candidates_len
);
2901 return gfc_closest_fuzzy_match (fn
, candidates
);
2905 /* Resolve a procedure call not known to be generic nor specific. */
2908 resolve_unknown_f (gfc_expr
*expr
)
2913 sym
= expr
->symtree
->n
.sym
;
2915 if (sym
->attr
.dummy
)
2917 sym
->attr
.proc
= PROC_DUMMY
;
2918 expr
->value
.function
.name
= sym
->name
;
2922 /* See if we have an intrinsic function reference. */
2924 if (gfc_is_intrinsic (sym
, 0, expr
->where
))
2926 if (gfc_intrinsic_func_interface (expr
, 1) == MATCH_YES
)
2931 /* The reference is to an external name. */
2933 sym
->attr
.proc
= PROC_EXTERNAL
;
2934 expr
->value
.function
.name
= sym
->name
;
2935 expr
->value
.function
.esym
= expr
->symtree
->n
.sym
;
2937 if (sym
->as
!= NULL
)
2938 expr
->rank
= sym
->as
->rank
;
2940 /* Type of the expression is either the type of the symbol or the
2941 default type of the symbol. */
2944 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2946 if (sym
->ts
.type
!= BT_UNKNOWN
)
2950 ts
= gfc_get_default_type (sym
->name
, sym
->ns
);
2952 if (ts
->type
== BT_UNKNOWN
)
2955 = gfc_lookup_function_fuzzy (sym
->name
, sym
->ns
->sym_root
);
2957 gfc_error ("Function %qs at %L has no IMPLICIT type"
2958 "; did you mean %qs?",
2959 sym
->name
, &expr
->where
, guessed
);
2961 gfc_error ("Function %qs at %L has no IMPLICIT type",
2962 sym
->name
, &expr
->where
);
2973 /* Return true, if the symbol is an external procedure. */
2975 is_external_proc (gfc_symbol
*sym
)
2977 if (!sym
->attr
.dummy
&& !sym
->attr
.contained
2978 && !gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, sym
->declared_at
)
2979 && sym
->attr
.proc
!= PROC_ST_FUNCTION
2980 && !sym
->attr
.proc_pointer
2981 && !sym
->attr
.use_assoc
2989 /* Figure out if a function reference is pure or not. Also set the name
2990 of the function for a potential error message. Return nonzero if the
2991 function is PURE, zero if not. */
2993 pure_stmt_function (gfc_expr
*, gfc_symbol
*);
2996 gfc_pure_function (gfc_expr
*e
, const char **name
)
2999 gfc_component
*comp
;
3003 if (e
->symtree
!= NULL
3004 && e
->symtree
->n
.sym
!= NULL
3005 && e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
3006 return pure_stmt_function (e
, e
->symtree
->n
.sym
);
3008 comp
= gfc_get_proc_ptr_comp (e
);
3011 pure
= gfc_pure (comp
->ts
.interface
);
3014 else if (e
->value
.function
.esym
)
3016 pure
= gfc_pure (e
->value
.function
.esym
);
3017 *name
= e
->value
.function
.esym
->name
;
3019 else if (e
->value
.function
.isym
)
3021 pure
= e
->value
.function
.isym
->pure
3022 || e
->value
.function
.isym
->elemental
;
3023 *name
= e
->value
.function
.isym
->name
;
3027 /* Implicit functions are not pure. */
3029 *name
= e
->value
.function
.name
;
3036 /* Check if the expression is a reference to an implicitly pure function. */
3039 gfc_implicit_pure_function (gfc_expr
*e
)
3041 gfc_component
*comp
= gfc_get_proc_ptr_comp (e
);
3043 return gfc_implicit_pure (comp
->ts
.interface
);
3044 else if (e
->value
.function
.esym
)
3045 return gfc_implicit_pure (e
->value
.function
.esym
);
3052 impure_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
,
3053 int *f ATTRIBUTE_UNUSED
)
3057 /* Don't bother recursing into other statement functions
3058 since they will be checked individually for purity. */
3059 if (e
->expr_type
!= EXPR_FUNCTION
3061 || e
->symtree
->n
.sym
== sym
3062 || e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
3065 return gfc_pure_function (e
, &name
) ? false : true;
3070 pure_stmt_function (gfc_expr
*e
, gfc_symbol
*sym
)
3072 return gfc_traverse_expr (e
, sym
, impure_stmt_fcn
, 0) ? 0 : 1;
3076 /* Check if an impure function is allowed in the current context. */
3078 static bool check_pure_function (gfc_expr
*e
)
3080 const char *name
= NULL
;
3081 if (!gfc_pure_function (e
, &name
) && name
)
3085 gfc_error ("Reference to impure function %qs at %L inside a "
3086 "FORALL %s", name
, &e
->where
,
3087 forall_flag
== 2 ? "mask" : "block");
3090 else if (gfc_do_concurrent_flag
)
3092 gfc_error ("Reference to impure function %qs at %L inside a "
3093 "DO CONCURRENT %s", name
, &e
->where
,
3094 gfc_do_concurrent_flag
== 2 ? "mask" : "block");
3097 else if (gfc_pure (NULL
))
3099 gfc_error ("Reference to impure function %qs at %L "
3100 "within a PURE procedure", name
, &e
->where
);
3103 if (!gfc_implicit_pure_function (e
))
3104 gfc_unset_implicit_pure (NULL
);
3110 /* Update current procedure's array_outer_dependency flag, considering
3111 a call to procedure SYM. */
3114 update_current_proc_array_outer_dependency (gfc_symbol
*sym
)
3116 /* Check to see if this is a sibling function that has not yet
3118 gfc_namespace
*sibling
= gfc_current_ns
->sibling
;
3119 for (; sibling
; sibling
= sibling
->sibling
)
3121 if (sibling
->proc_name
== sym
)
3123 gfc_resolve (sibling
);
3128 /* If SYM has references to outer arrays, so has the procedure calling
3129 SYM. If SYM is a procedure pointer, we can assume the worst. */
3130 if ((sym
->attr
.array_outer_dependency
|| sym
->attr
.proc_pointer
)
3131 && gfc_current_ns
->proc_name
)
3132 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
3136 /* Resolve a function call, which means resolving the arguments, then figuring
3137 out which entity the name refers to. */
3140 resolve_function (gfc_expr
*expr
)
3142 gfc_actual_arglist
*arg
;
3146 procedure_type p
= PROC_INTRINSIC
;
3147 bool no_formal_args
;
3151 sym
= expr
->symtree
->n
.sym
;
3153 /* If this is a procedure pointer component, it has already been resolved. */
3154 if (gfc_is_proc_ptr_comp (expr
))
3157 /* Avoid re-resolving the arguments of caf_get, which can lead to inserting
3159 if (sym
&& sym
->attr
.intrinsic
3160 && (sym
->intmod_sym_id
== GFC_ISYM_CAF_GET
3161 || sym
->intmod_sym_id
== GFC_ISYM_CAF_SEND
))
3166 gfc_error ("Unexpected junk after %qs at %L", expr
->symtree
->n
.sym
->name
,
3171 if (sym
&& sym
->attr
.intrinsic
3172 && !gfc_resolve_intrinsic (sym
, &expr
->where
))
3175 if (sym
&& (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.subroutine
))
3177 gfc_error ("%qs at %L is not a function", sym
->name
, &expr
->where
);
3181 /* If this is a deferred TBP with an abstract interface (which may
3182 of course be referenced), expr->value.function.esym will be set. */
3183 if (sym
&& sym
->attr
.abstract
&& !expr
->value
.function
.esym
)
3185 gfc_error ("ABSTRACT INTERFACE %qs must not be referenced at %L",
3186 sym
->name
, &expr
->where
);
3190 /* If this is a deferred TBP with an abstract interface, its result
3191 cannot be an assumed length character (F2003: C418). */
3192 if (sym
&& sym
->attr
.abstract
&& sym
->attr
.function
3193 && sym
->result
->ts
.u
.cl
3194 && sym
->result
->ts
.u
.cl
->length
== NULL
3195 && !sym
->result
->ts
.deferred
)
3197 gfc_error ("ABSTRACT INTERFACE %qs at %L must not have an assumed "
3198 "character length result (F2008: C418)", sym
->name
,
3203 /* Switch off assumed size checking and do this again for certain kinds
3204 of procedure, once the procedure itself is resolved. */
3205 need_full_assumed_size
++;
3207 if (expr
->symtree
&& expr
->symtree
->n
.sym
)
3208 p
= expr
->symtree
->n
.sym
->attr
.proc
;
3210 if (expr
->value
.function
.isym
&& expr
->value
.function
.isym
->inquiry
)
3211 inquiry_argument
= true;
3212 no_formal_args
= sym
&& is_external_proc (sym
)
3213 && gfc_sym_get_dummy_args (sym
) == NULL
;
3215 if (!resolve_actual_arglist (expr
->value
.function
.actual
,
3218 inquiry_argument
= false;
3222 inquiry_argument
= false;
3224 /* Resume assumed_size checking. */
3225 need_full_assumed_size
--;
3227 /* If the procedure is external, check for usage. */
3228 if (sym
&& is_external_proc (sym
))
3229 resolve_global_procedure (sym
, &expr
->where
, 0);
3231 if (sym
&& sym
->ts
.type
== BT_CHARACTER
3233 && sym
->ts
.u
.cl
->length
== NULL
3235 && !sym
->ts
.deferred
3236 && expr
->value
.function
.esym
== NULL
3237 && !sym
->attr
.contained
)
3239 /* Internal procedures are taken care of in resolve_contained_fntype. */
3240 gfc_error ("Function %qs is declared CHARACTER(*) and cannot "
3241 "be used at %L since it is not a dummy argument",
3242 sym
->name
, &expr
->where
);
3246 /* See if function is already resolved. */
3248 if (expr
->value
.function
.name
!= NULL
3249 || expr
->value
.function
.isym
!= NULL
)
3251 if (expr
->ts
.type
== BT_UNKNOWN
)
3257 /* Apply the rules of section 14.1.2. */
3259 switch (procedure_kind (sym
))
3262 t
= resolve_generic_f (expr
);
3265 case PTYPE_SPECIFIC
:
3266 t
= resolve_specific_f (expr
);
3270 t
= resolve_unknown_f (expr
);
3274 gfc_internal_error ("resolve_function(): bad function type");
3278 /* If the expression is still a function (it might have simplified),
3279 then we check to see if we are calling an elemental function. */
3281 if (expr
->expr_type
!= EXPR_FUNCTION
)
3284 /* Walk the argument list looking for invalid BOZ. */
3285 for (arg
= expr
->value
.function
.actual
; arg
; arg
= arg
->next
)
3286 if (arg
->expr
&& arg
->expr
->ts
.type
== BT_BOZ
)
3288 gfc_error ("A BOZ literal constant at %L cannot appear as an "
3289 "actual argument in a function reference",
3294 temp
= need_full_assumed_size
;
3295 need_full_assumed_size
= 0;
3297 if (!resolve_elemental_actual (expr
, NULL
))
3300 if (omp_workshare_flag
3301 && expr
->value
.function
.esym
3302 && ! gfc_elemental (expr
->value
.function
.esym
))
3304 gfc_error ("User defined non-ELEMENTAL function %qs at %L not allowed "
3305 "in WORKSHARE construct", expr
->value
.function
.esym
->name
,
3310 #define GENERIC_ID expr->value.function.isym->id
3311 else if (expr
->value
.function
.actual
!= NULL
3312 && expr
->value
.function
.isym
!= NULL
3313 && GENERIC_ID
!= GFC_ISYM_LBOUND
3314 && GENERIC_ID
!= GFC_ISYM_LCOBOUND
3315 && GENERIC_ID
!= GFC_ISYM_UCOBOUND
3316 && GENERIC_ID
!= GFC_ISYM_LEN
3317 && GENERIC_ID
!= GFC_ISYM_LOC
3318 && GENERIC_ID
!= GFC_ISYM_C_LOC
3319 && GENERIC_ID
!= GFC_ISYM_PRESENT
)
3321 /* Array intrinsics must also have the last upper bound of an
3322 assumed size array argument. UBOUND and SIZE have to be
3323 excluded from the check if the second argument is anything
3326 for (arg
= expr
->value
.function
.actual
; arg
; arg
= arg
->next
)
3328 if ((GENERIC_ID
== GFC_ISYM_UBOUND
|| GENERIC_ID
== GFC_ISYM_SIZE
)
3329 && arg
== expr
->value
.function
.actual
3330 && arg
->next
!= NULL
&& arg
->next
->expr
)
3332 if (arg
->next
->expr
->expr_type
!= EXPR_CONSTANT
)
3335 if (arg
->next
->name
&& strcmp (arg
->next
->name
, "kind") == 0)
3338 if ((int)mpz_get_si (arg
->next
->expr
->value
.integer
)
3343 if (arg
->expr
!= NULL
3344 && arg
->expr
->rank
> 0
3345 && resolve_assumed_size_actual (arg
->expr
))
3351 need_full_assumed_size
= temp
;
3353 if (!check_pure_function(expr
))
3356 /* Functions without the RECURSIVE attribution are not allowed to
3357 * call themselves. */
3358 if (expr
->value
.function
.esym
&& !expr
->value
.function
.esym
->attr
.recursive
)
3361 esym
= expr
->value
.function
.esym
;
3363 if (is_illegal_recursion (esym
, gfc_current_ns
))
3365 if (esym
->attr
.entry
&& esym
->ns
->entries
)
3366 gfc_error ("ENTRY %qs at %L cannot be called recursively, as"
3367 " function %qs is not RECURSIVE",
3368 esym
->name
, &expr
->where
, esym
->ns
->entries
->sym
->name
);
3370 gfc_error ("Function %qs at %L cannot be called recursively, as it"
3371 " is not RECURSIVE", esym
->name
, &expr
->where
);
3377 /* Character lengths of use associated functions may contains references to
3378 symbols not referenced from the current program unit otherwise. Make sure
3379 those symbols are marked as referenced. */
3381 if (expr
->ts
.type
== BT_CHARACTER
&& expr
->value
.function
.esym
3382 && expr
->value
.function
.esym
->attr
.use_assoc
)
3384 gfc_expr_set_symbols_referenced (expr
->ts
.u
.cl
->length
);
3387 /* Make sure that the expression has a typespec that works. */
3388 if (expr
->ts
.type
== BT_UNKNOWN
)
3390 if (expr
->symtree
->n
.sym
->result
3391 && expr
->symtree
->n
.sym
->result
->ts
.type
!= BT_UNKNOWN
3392 && !expr
->symtree
->n
.sym
->result
->attr
.proc_pointer
)
3393 expr
->ts
= expr
->symtree
->n
.sym
->result
->ts
;
3396 if (!expr
->ref
&& !expr
->value
.function
.isym
)
3398 if (expr
->value
.function
.esym
)
3399 update_current_proc_array_outer_dependency (expr
->value
.function
.esym
);
3401 update_current_proc_array_outer_dependency (sym
);
3404 /* typebound procedure: Assume the worst. */
3405 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
3407 if (expr
->value
.function
.esym
3408 && expr
->value
.function
.esym
->attr
.ext_attr
& (1 << EXT_ATTR_DEPRECATED
))
3409 gfc_warning (OPT_Wdeprecated_declarations
,
3410 "Using function %qs at %L is deprecated",
3411 sym
->name
, &expr
->where
);
3416 /************* Subroutine resolution *************/
3419 pure_subroutine (gfc_symbol
*sym
, const char *name
, locus
*loc
)
3426 gfc_error ("Subroutine call to %qs in FORALL block at %L is not PURE",
3430 else if (gfc_do_concurrent_flag
)
3432 gfc_error ("Subroutine call to %qs in DO CONCURRENT block at %L is not "
3436 else if (gfc_pure (NULL
))
3438 gfc_error ("Subroutine call to %qs at %L is not PURE", name
, loc
);
3442 gfc_unset_implicit_pure (NULL
);
3448 resolve_generic_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3452 if (sym
->attr
.generic
)
3454 s
= gfc_search_interface (sym
->generic
, 1, &c
->ext
.actual
);
3457 c
->resolved_sym
= s
;
3458 if (!pure_subroutine (s
, s
->name
, &c
->loc
))
3463 /* TODO: Need to search for elemental references in generic interface. */
3466 if (sym
->attr
.intrinsic
)
3467 return gfc_intrinsic_sub_interface (c
, 0);
3474 resolve_generic_s (gfc_code
*c
)
3479 sym
= c
->symtree
->n
.sym
;
3483 m
= resolve_generic_s0 (c
, sym
);
3486 else if (m
== MATCH_ERROR
)
3490 if (sym
->ns
->parent
== NULL
)
3492 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3496 if (!generic_sym (sym
))
3500 /* Last ditch attempt. See if the reference is to an intrinsic
3501 that possesses a matching interface. 14.1.2.4 */
3502 sym
= c
->symtree
->n
.sym
;
3504 if (!gfc_is_intrinsic (sym
, 1, c
->loc
))
3506 gfc_error ("There is no specific subroutine for the generic %qs at %L",
3507 sym
->name
, &c
->loc
);
3511 m
= gfc_intrinsic_sub_interface (c
, 0);
3515 gfc_error ("Generic subroutine %qs at %L is not consistent with an "
3516 "intrinsic subroutine interface", sym
->name
, &c
->loc
);
3522 /* Resolve a subroutine call known to be specific. */
3525 resolve_specific_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3529 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
3531 if (sym
->attr
.dummy
)
3533 sym
->attr
.proc
= PROC_DUMMY
;
3537 sym
->attr
.proc
= PROC_EXTERNAL
;
3541 if (sym
->attr
.proc
== PROC_MODULE
|| sym
->attr
.proc
== PROC_INTERNAL
)
3544 if (sym
->attr
.intrinsic
)
3546 m
= gfc_intrinsic_sub_interface (c
, 1);
3550 gfc_error ("Subroutine %qs at %L is INTRINSIC but is not compatible "
3551 "with an intrinsic", sym
->name
, &c
->loc
);
3559 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3561 c
->resolved_sym
= sym
;
3562 if (!pure_subroutine (sym
, sym
->name
, &c
->loc
))
3570 resolve_specific_s (gfc_code
*c
)
3575 sym
= c
->symtree
->n
.sym
;
3579 m
= resolve_specific_s0 (c
, sym
);
3582 if (m
== MATCH_ERROR
)
3585 if (sym
->ns
->parent
== NULL
)
3588 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3594 sym
= c
->symtree
->n
.sym
;
3595 gfc_error ("Unable to resolve the specific subroutine %qs at %L",
3596 sym
->name
, &c
->loc
);
3602 /* Resolve a subroutine call not known to be generic nor specific. */
3605 resolve_unknown_s (gfc_code
*c
)
3609 sym
= c
->symtree
->n
.sym
;
3611 if (sym
->attr
.dummy
)
3613 sym
->attr
.proc
= PROC_DUMMY
;
3617 /* See if we have an intrinsic function reference. */
3619 if (gfc_is_intrinsic (sym
, 1, c
->loc
))
3621 if (gfc_intrinsic_sub_interface (c
, 1) == MATCH_YES
)
3626 /* The reference is to an external name. */
3629 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3631 c
->resolved_sym
= sym
;
3633 return pure_subroutine (sym
, sym
->name
, &c
->loc
);
3637 /* Resolve a subroutine call. Although it was tempting to use the same code
3638 for functions, subroutines and functions are stored differently and this
3639 makes things awkward. */
3642 resolve_call (gfc_code
*c
)
3645 procedure_type ptype
= PROC_INTRINSIC
;
3646 gfc_symbol
*csym
, *sym
;
3647 bool no_formal_args
;
3649 csym
= c
->symtree
? c
->symtree
->n
.sym
: NULL
;
3651 if (csym
&& csym
->ts
.type
!= BT_UNKNOWN
)
3653 gfc_error ("%qs at %L has a type, which is not consistent with "
3654 "the CALL at %L", csym
->name
, &csym
->declared_at
, &c
->loc
);
3658 if (csym
&& gfc_current_ns
->parent
&& csym
->ns
!= gfc_current_ns
)
3661 gfc_find_sym_tree (c
->symtree
->name
, gfc_current_ns
, 1, &st
);
3662 sym
= st
? st
->n
.sym
: NULL
;
3663 if (sym
&& csym
!= sym
3664 && sym
->ns
== gfc_current_ns
3665 && sym
->attr
.flavor
== FL_PROCEDURE
3666 && sym
->attr
.contained
)
3669 if (csym
->attr
.generic
)
3670 c
->symtree
->n
.sym
= sym
;
3673 csym
= c
->symtree
->n
.sym
;
3677 /* If this ia a deferred TBP, c->expr1 will be set. */
3678 if (!c
->expr1
&& csym
)
3680 if (csym
->attr
.abstract
)
3682 gfc_error ("ABSTRACT INTERFACE %qs must not be referenced at %L",
3683 csym
->name
, &c
->loc
);
3687 /* Subroutines without the RECURSIVE attribution are not allowed to
3689 if (is_illegal_recursion (csym
, gfc_current_ns
))
3691 if (csym
->attr
.entry
&& csym
->ns
->entries
)
3692 gfc_error ("ENTRY %qs at %L cannot be called recursively, "
3693 "as subroutine %qs is not RECURSIVE",
3694 csym
->name
, &c
->loc
, csym
->ns
->entries
->sym
->name
);
3696 gfc_error ("SUBROUTINE %qs at %L cannot be called recursively, "
3697 "as it is not RECURSIVE", csym
->name
, &c
->loc
);
3703 /* Switch off assumed size checking and do this again for certain kinds
3704 of procedure, once the procedure itself is resolved. */
3705 need_full_assumed_size
++;
3708 ptype
= csym
->attr
.proc
;
3710 no_formal_args
= csym
&& is_external_proc (csym
)
3711 && gfc_sym_get_dummy_args (csym
) == NULL
;
3712 if (!resolve_actual_arglist (c
->ext
.actual
, ptype
, no_formal_args
))
3715 /* Resume assumed_size checking. */
3716 need_full_assumed_size
--;
3718 /* If external, check for usage. */
3719 if (csym
&& is_external_proc (csym
))
3720 resolve_global_procedure (csym
, &c
->loc
, 1);
3723 if (c
->resolved_sym
== NULL
)
3725 c
->resolved_isym
= NULL
;
3726 switch (procedure_kind (csym
))
3729 t
= resolve_generic_s (c
);
3732 case PTYPE_SPECIFIC
:
3733 t
= resolve_specific_s (c
);
3737 t
= resolve_unknown_s (c
);
3741 gfc_internal_error ("resolve_subroutine(): bad function type");
3745 /* Some checks of elemental subroutine actual arguments. */
3746 if (!resolve_elemental_actual (NULL
, c
))
3750 update_current_proc_array_outer_dependency (csym
);
3752 /* Typebound procedure: Assume the worst. */
3753 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
3756 && c
->resolved_sym
->attr
.ext_attr
& (1 << EXT_ATTR_DEPRECATED
))
3757 gfc_warning (OPT_Wdeprecated_declarations
,
3758 "Using subroutine %qs at %L is deprecated",
3759 c
->resolved_sym
->name
, &c
->loc
);
3765 /* Compare the shapes of two arrays that have non-NULL shapes. If both
3766 op1->shape and op2->shape are non-NULL return true if their shapes
3767 match. If both op1->shape and op2->shape are non-NULL return false
3768 if their shapes do not match. If either op1->shape or op2->shape is
3769 NULL, return true. */
3772 compare_shapes (gfc_expr
*op1
, gfc_expr
*op2
)
3779 if (op1
->shape
!= NULL
&& op2
->shape
!= NULL
)
3781 for (i
= 0; i
< op1
->rank
; i
++)
3783 if (mpz_cmp (op1
->shape
[i
], op2
->shape
[i
]) != 0)
3785 gfc_error ("Shapes for operands at %L and %L are not conformable",
3786 &op1
->where
, &op2
->where
);
3796 /* Convert a logical operator to the corresponding bitwise intrinsic call.
3797 For example A .AND. B becomes IAND(A, B). */
3799 logical_to_bitwise (gfc_expr
*e
)
3801 gfc_expr
*tmp
, *op1
, *op2
;
3803 gfc_actual_arglist
*args
= NULL
;
3805 gcc_assert (e
->expr_type
== EXPR_OP
);
3807 isym
= GFC_ISYM_NONE
;
3808 op1
= e
->value
.op
.op1
;
3809 op2
= e
->value
.op
.op2
;
3811 switch (e
->value
.op
.op
)
3814 isym
= GFC_ISYM_NOT
;
3817 isym
= GFC_ISYM_IAND
;
3820 isym
= GFC_ISYM_IOR
;
3822 case INTRINSIC_NEQV
:
3823 isym
= GFC_ISYM_IEOR
;
3826 /* "Bitwise eqv" is just the complement of NEQV === IEOR.
3827 Change the old expression to NEQV, which will get replaced by IEOR,
3828 and wrap it in NOT. */
3829 tmp
= gfc_copy_expr (e
);
3830 tmp
->value
.op
.op
= INTRINSIC_NEQV
;
3831 tmp
= logical_to_bitwise (tmp
);
3832 isym
= GFC_ISYM_NOT
;
3837 gfc_internal_error ("logical_to_bitwise(): Bad intrinsic");
3840 /* Inherit the original operation's operands as arguments. */
3841 args
= gfc_get_actual_arglist ();
3845 args
->next
= gfc_get_actual_arglist ();
3846 args
->next
->expr
= op2
;
3849 /* Convert the expression to a function call. */
3850 e
->expr_type
= EXPR_FUNCTION
;
3851 e
->value
.function
.actual
= args
;
3852 e
->value
.function
.isym
= gfc_intrinsic_function_by_id (isym
);
3853 e
->value
.function
.name
= e
->value
.function
.isym
->name
;
3854 e
->value
.function
.esym
= NULL
;
3856 /* Make up a pre-resolved function call symtree if we need to. */
3857 if (!e
->symtree
|| !e
->symtree
->n
.sym
)
3860 gfc_get_ha_sym_tree (e
->value
.function
.isym
->name
, &e
->symtree
);
3861 sym
= e
->symtree
->n
.sym
;
3863 sym
->attr
.flavor
= FL_PROCEDURE
;
3864 sym
->attr
.function
= 1;
3865 sym
->attr
.elemental
= 1;
3867 sym
->attr
.referenced
= 1;
3868 gfc_intrinsic_symbol (sym
);
3869 gfc_commit_symbol (sym
);
3872 args
->name
= e
->value
.function
.isym
->formal
->name
;
3873 if (e
->value
.function
.isym
->formal
->next
)
3874 args
->next
->name
= e
->value
.function
.isym
->formal
->next
->name
;
3879 /* Recursively append candidate UOP to CANDIDATES. Store the number of
3880 candidates in CANDIDATES_LEN. */
3882 lookup_uop_fuzzy_find_candidates (gfc_symtree
*uop
,
3884 size_t &candidates_len
)
3891 /* Not sure how to properly filter here. Use all for a start.
3892 n.uop.op is NULL for empty interface operators (is that legal?) disregard
3893 these as i suppose they don't make terribly sense. */
3895 if (uop
->n
.uop
->op
!= NULL
)
3896 vec_push (candidates
, candidates_len
, uop
->name
);
3900 lookup_uop_fuzzy_find_candidates (p
, candidates
, candidates_len
);
3904 lookup_uop_fuzzy_find_candidates (p
, candidates
, candidates_len
);
3907 /* Lookup user-operator OP fuzzily, taking names in UOP into account. */
3910 lookup_uop_fuzzy (const char *op
, gfc_symtree
*uop
)
3912 char **candidates
= NULL
;
3913 size_t candidates_len
= 0;
3914 lookup_uop_fuzzy_find_candidates (uop
, candidates
, candidates_len
);
3915 return gfc_closest_fuzzy_match (op
, candidates
);
3919 /* Callback finding an impure function as an operand to an .and. or
3920 .or. expression. Remember the last function warned about to
3921 avoid double warnings when recursing. */
3924 impure_function_callback (gfc_expr
**e
, int *walk_subtrees ATTRIBUTE_UNUSED
,
3929 static gfc_expr
*last
= NULL
;
3930 bool *found
= (bool *) data
;
3932 if (f
->expr_type
== EXPR_FUNCTION
)
3935 if (f
!= last
&& !gfc_pure_function (f
, &name
)
3936 && !gfc_implicit_pure_function (f
))
3939 gfc_warning (OPT_Wfunction_elimination
,
3940 "Impure function %qs at %L might not be evaluated",
3943 gfc_warning (OPT_Wfunction_elimination
,
3944 "Impure function at %L might not be evaluated",
3953 /* Return true if TYPE is character based, false otherwise. */
3956 is_character_based (bt type
)
3958 return type
== BT_CHARACTER
|| type
== BT_HOLLERITH
;
3962 /* If expression is a hollerith, convert it to character and issue a warning
3963 for the conversion. */
3966 convert_hollerith_to_character (gfc_expr
*e
)
3968 if (e
->ts
.type
== BT_HOLLERITH
)
3972 t
.type
= BT_CHARACTER
;
3973 t
.kind
= e
->ts
.kind
;
3974 gfc_convert_type_warn (e
, &t
, 2, 1);
3978 /* Convert to numeric and issue a warning for the conversion. */
3981 convert_to_numeric (gfc_expr
*a
, gfc_expr
*b
)
3985 t
.type
= b
->ts
.type
;
3986 t
.kind
= b
->ts
.kind
;
3987 gfc_convert_type_warn (a
, &t
, 2, 1);
3990 /* Resolve an operator expression node. This can involve replacing the
3991 operation with a user defined function call. */
3994 resolve_operator (gfc_expr
*e
)
3996 gfc_expr
*op1
, *op2
;
3997 /* One error uses 3 names; additional space for wording (also via gettext). */
3998 char msg
[3*GFC_MAX_SYMBOL_LEN
+ 1 + 50];
3999 bool dual_locus_error
;
4002 /* Resolve all subnodes-- give them types. */
4004 switch (e
->value
.op
.op
)
4007 if (!gfc_resolve_expr (e
->value
.op
.op2
))
4013 case INTRINSIC_UPLUS
:
4014 case INTRINSIC_UMINUS
:
4015 case INTRINSIC_PARENTHESES
:
4016 if (!gfc_resolve_expr (e
->value
.op
.op1
))
4019 && e
->value
.op
.op1
->ts
.type
== BT_BOZ
&& !e
->value
.op
.op2
)
4021 gfc_error ("BOZ literal constant at %L cannot be an operand of "
4022 "unary operator %qs", &e
->value
.op
.op1
->where
,
4023 gfc_op2string (e
->value
.op
.op
));
4029 /* Typecheck the new node. */
4031 op1
= e
->value
.op
.op1
;
4032 op2
= e
->value
.op
.op2
;
4033 if (op1
== NULL
&& op2
== NULL
)
4036 dual_locus_error
= false;
4038 /* op1 and op2 cannot both be BOZ. */
4039 if (op1
&& op1
->ts
.type
== BT_BOZ
4040 && op2
&& op2
->ts
.type
== BT_BOZ
)
4042 gfc_error ("Operands at %L and %L cannot appear as operands of "
4043 "binary operator %qs", &op1
->where
, &op2
->where
,
4044 gfc_op2string (e
->value
.op
.op
));
4048 if ((op1
&& op1
->expr_type
== EXPR_NULL
)
4049 || (op2
&& op2
->expr_type
== EXPR_NULL
))
4051 snprintf (msg
, sizeof (msg
),
4052 _("Invalid context for NULL() pointer at %%L"));
4056 switch (e
->value
.op
.op
)
4058 case INTRINSIC_UPLUS
:
4059 case INTRINSIC_UMINUS
:
4060 if (op1
->ts
.type
== BT_INTEGER
4061 || op1
->ts
.type
== BT_REAL
4062 || op1
->ts
.type
== BT_COMPLEX
)
4068 snprintf (msg
, sizeof (msg
),
4069 _("Operand of unary numeric operator %%<%s%%> at %%L is %s"),
4070 gfc_op2string (e
->value
.op
.op
), gfc_typename (e
));
4073 case INTRINSIC_PLUS
:
4074 case INTRINSIC_MINUS
:
4075 case INTRINSIC_TIMES
:
4076 case INTRINSIC_DIVIDE
:
4077 case INTRINSIC_POWER
:
4078 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
4080 gfc_type_convert_binary (e
, 1);
4084 if (op1
->ts
.type
== BT_DERIVED
|| op2
->ts
.type
== BT_DERIVED
)
4085 snprintf (msg
, sizeof (msg
),
4086 _("Unexpected derived-type entities in binary intrinsic "
4087 "numeric operator %%<%s%%> at %%L"),
4088 gfc_op2string (e
->value
.op
.op
));
4090 snprintf (msg
, sizeof(msg
),
4091 _("Operands of binary numeric operator %%<%s%%> at %%L are %s/%s"),
4092 gfc_op2string (e
->value
.op
.op
), gfc_typename (op1
),
4093 gfc_typename (op2
));
4096 case INTRINSIC_CONCAT
:
4097 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
4098 && op1
->ts
.kind
== op2
->ts
.kind
)
4100 e
->ts
.type
= BT_CHARACTER
;
4101 e
->ts
.kind
= op1
->ts
.kind
;
4105 snprintf (msg
, sizeof (msg
),
4106 _("Operands of string concatenation operator at %%L are %s/%s"),
4107 gfc_typename (op1
), gfc_typename (op2
));
4113 case INTRINSIC_NEQV
:
4114 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
4116 e
->ts
.type
= BT_LOGICAL
;
4117 e
->ts
.kind
= gfc_kind_max (op1
, op2
);
4118 if (op1
->ts
.kind
< e
->ts
.kind
)
4119 gfc_convert_type (op1
, &e
->ts
, 2);
4120 else if (op2
->ts
.kind
< e
->ts
.kind
)
4121 gfc_convert_type (op2
, &e
->ts
, 2);
4123 if (flag_frontend_optimize
&&
4124 (e
->value
.op
.op
== INTRINSIC_AND
|| e
->value
.op
.op
== INTRINSIC_OR
))
4126 /* Warn about short-circuiting
4127 with impure function as second operand. */
4129 gfc_expr_walker (&op2
, impure_function_callback
, &op2_f
);
4134 /* Logical ops on integers become bitwise ops with -fdec. */
4136 && (op1
->ts
.type
== BT_INTEGER
|| op2
->ts
.type
== BT_INTEGER
))
4138 e
->ts
.type
= BT_INTEGER
;
4139 e
->ts
.kind
= gfc_kind_max (op1
, op2
);
4140 if (op1
->ts
.type
!= e
->ts
.type
|| op1
->ts
.kind
!= e
->ts
.kind
)
4141 gfc_convert_type (op1
, &e
->ts
, 1);
4142 if (op2
->ts
.type
!= e
->ts
.type
|| op2
->ts
.kind
!= e
->ts
.kind
)
4143 gfc_convert_type (op2
, &e
->ts
, 1);
4144 e
= logical_to_bitwise (e
);
4148 snprintf (msg
, sizeof (msg
),
4149 _("Operands of logical operator %%<%s%%> at %%L are %s/%s"),
4150 gfc_op2string (e
->value
.op
.op
), gfc_typename (op1
),
4151 gfc_typename (op2
));
4156 /* Logical ops on integers become bitwise ops with -fdec. */
4157 if (flag_dec
&& op1
->ts
.type
== BT_INTEGER
)
4159 e
->ts
.type
= BT_INTEGER
;
4160 e
->ts
.kind
= op1
->ts
.kind
;
4161 e
= logical_to_bitwise (e
);
4165 if (op1
->ts
.type
== BT_LOGICAL
)
4167 e
->ts
.type
= BT_LOGICAL
;
4168 e
->ts
.kind
= op1
->ts
.kind
;
4172 snprintf (msg
, sizeof (msg
), _("Operand of .not. operator at %%L is %s"),
4173 gfc_typename (op1
));
4177 case INTRINSIC_GT_OS
:
4179 case INTRINSIC_GE_OS
:
4181 case INTRINSIC_LT_OS
:
4183 case INTRINSIC_LE_OS
:
4184 if (op1
->ts
.type
== BT_COMPLEX
|| op2
->ts
.type
== BT_COMPLEX
)
4186 strcpy (msg
, _("COMPLEX quantities cannot be compared at %L"));
4193 case INTRINSIC_EQ_OS
:
4195 case INTRINSIC_NE_OS
:
4198 && is_character_based (op1
->ts
.type
)
4199 && is_character_based (op2
->ts
.type
))
4201 convert_hollerith_to_character (op1
);
4202 convert_hollerith_to_character (op2
);
4205 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
4206 && op1
->ts
.kind
== op2
->ts
.kind
)
4208 e
->ts
.type
= BT_LOGICAL
;
4209 e
->ts
.kind
= gfc_default_logical_kind
;
4213 /* If op1 is BOZ, then op2 is not!. Try to convert to type of op2. */
4214 if (op1
->ts
.type
== BT_BOZ
)
4216 if (gfc_invalid_boz (G_("BOZ literal constant near %L cannot appear "
4217 "as an operand of a relational operator"),
4221 if (op2
->ts
.type
== BT_INTEGER
&& !gfc_boz2int (op1
, op2
->ts
.kind
))
4224 if (op2
->ts
.type
== BT_REAL
&& !gfc_boz2real (op1
, op2
->ts
.kind
))
4228 /* If op2 is BOZ, then op1 is not!. Try to convert to type of op2. */
4229 if (op2
->ts
.type
== BT_BOZ
)
4231 if (gfc_invalid_boz (G_("BOZ literal constant near %L cannot appear"
4232 " as an operand of a relational operator"),
4236 if (op1
->ts
.type
== BT_INTEGER
&& !gfc_boz2int (op2
, op1
->ts
.kind
))
4239 if (op1
->ts
.type
== BT_REAL
&& !gfc_boz2real (op2
, op1
->ts
.kind
))
4243 && op1
->ts
.type
== BT_HOLLERITH
&& gfc_numeric_ts (&op2
->ts
))
4244 convert_to_numeric (op1
, op2
);
4247 && gfc_numeric_ts (&op1
->ts
) && op2
->ts
.type
== BT_HOLLERITH
)
4248 convert_to_numeric (op2
, op1
);
4250 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
4252 gfc_type_convert_binary (e
, 1);
4254 e
->ts
.type
= BT_LOGICAL
;
4255 e
->ts
.kind
= gfc_default_logical_kind
;
4257 if (warn_compare_reals
)
4259 gfc_intrinsic_op op
= e
->value
.op
.op
;
4261 /* Type conversion has made sure that the types of op1 and op2
4262 agree, so it is only necessary to check the first one. */
4263 if ((op1
->ts
.type
== BT_REAL
|| op1
->ts
.type
== BT_COMPLEX
)
4264 && (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
4265 || op
== INTRINSIC_NE
|| op
== INTRINSIC_NE_OS
))
4269 if (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
)
4270 msg
= G_("Equality comparison for %s at %L");
4272 msg
= G_("Inequality comparison for %s at %L");
4274 gfc_warning (OPT_Wcompare_reals
, msg
,
4275 gfc_typename (op1
), &op1
->where
);
4282 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
4283 snprintf (msg
, sizeof (msg
),
4284 _("Logicals at %%L must be compared with %s instead of %s"),
4285 (e
->value
.op
.op
== INTRINSIC_EQ
4286 || e
->value
.op
.op
== INTRINSIC_EQ_OS
)
4287 ? ".eqv." : ".neqv.", gfc_op2string (e
->value
.op
.op
));
4289 snprintf (msg
, sizeof (msg
),
4290 _("Operands of comparison operator %%<%s%%> at %%L are %s/%s"),
4291 gfc_op2string (e
->value
.op
.op
), gfc_typename (op1
),
4292 gfc_typename (op2
));
4296 case INTRINSIC_USER
:
4297 if (e
->value
.op
.uop
->op
== NULL
)
4299 const char *name
= e
->value
.op
.uop
->name
;
4300 const char *guessed
;
4301 guessed
= lookup_uop_fuzzy (name
, e
->value
.op
.uop
->ns
->uop_root
);
4303 snprintf (msg
, sizeof (msg
),
4304 _("Unknown operator %%<%s%%> at %%L; did you mean '%s'?"),
4307 snprintf (msg
, sizeof (msg
), _("Unknown operator %%<%s%%> at %%L"),
4310 else if (op2
== NULL
)
4311 snprintf (msg
, sizeof (msg
),
4312 _("Operand of user operator %%<%s%%> at %%L is %s"),
4313 e
->value
.op
.uop
->name
, gfc_typename (op1
));
4316 snprintf (msg
, sizeof (msg
),
4317 _("Operands of user operator %%<%s%%> at %%L are %s/%s"),
4318 e
->value
.op
.uop
->name
, gfc_typename (op1
),
4319 gfc_typename (op2
));
4320 e
->value
.op
.uop
->op
->sym
->attr
.referenced
= 1;
4325 case INTRINSIC_PARENTHESES
:
4327 if (e
->ts
.type
== BT_CHARACTER
)
4328 e
->ts
.u
.cl
= op1
->ts
.u
.cl
;
4332 gfc_internal_error ("resolve_operator(): Bad intrinsic");
4335 /* Deal with arrayness of an operand through an operator. */
4337 switch (e
->value
.op
.op
)
4339 case INTRINSIC_PLUS
:
4340 case INTRINSIC_MINUS
:
4341 case INTRINSIC_TIMES
:
4342 case INTRINSIC_DIVIDE
:
4343 case INTRINSIC_POWER
:
4344 case INTRINSIC_CONCAT
:
4348 case INTRINSIC_NEQV
:
4350 case INTRINSIC_EQ_OS
:
4352 case INTRINSIC_NE_OS
:
4354 case INTRINSIC_GT_OS
:
4356 case INTRINSIC_GE_OS
:
4358 case INTRINSIC_LT_OS
:
4360 case INTRINSIC_LE_OS
:
4362 if (op1
->rank
== 0 && op2
->rank
== 0)
4365 if (op1
->rank
== 0 && op2
->rank
!= 0)
4367 e
->rank
= op2
->rank
;
4369 if (e
->shape
== NULL
)
4370 e
->shape
= gfc_copy_shape (op2
->shape
, op2
->rank
);
4373 if (op1
->rank
!= 0 && op2
->rank
== 0)
4375 e
->rank
= op1
->rank
;
4377 if (e
->shape
== NULL
)
4378 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
4381 if (op1
->rank
!= 0 && op2
->rank
!= 0)
4383 if (op1
->rank
== op2
->rank
)
4385 e
->rank
= op1
->rank
;
4386 if (e
->shape
== NULL
)
4388 t
= compare_shapes (op1
, op2
);
4392 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
4397 /* Allow higher level expressions to work. */
4400 /* Try user-defined operators, and otherwise throw an error. */
4401 dual_locus_error
= true;
4402 snprintf (msg
, sizeof (msg
),
4403 _("Inconsistent ranks for operator at %%L and %%L"));
4410 case INTRINSIC_PARENTHESES
:
4412 case INTRINSIC_UPLUS
:
4413 case INTRINSIC_UMINUS
:
4414 /* Simply copy arrayness attribute */
4415 e
->rank
= op1
->rank
;
4417 if (e
->shape
== NULL
)
4418 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
4428 /* Attempt to simplify the expression. */
4431 t
= gfc_simplify_expr (e
, 0);
4432 /* Some calls do not succeed in simplification and return false
4433 even though there is no error; e.g. variable references to
4434 PARAMETER arrays. */
4435 if (!gfc_is_constant_expr (e
))
4443 match m
= gfc_extend_expr (e
);
4446 if (m
== MATCH_ERROR
)
4450 if (dual_locus_error
)
4451 gfc_error (msg
, &op1
->where
, &op2
->where
);
4453 gfc_error (msg
, &e
->where
);
4459 /************** Array resolution subroutines **************/
4462 { CMP_LT
, CMP_EQ
, CMP_GT
, CMP_UNKNOWN
};
4464 /* Compare two integer expressions. */
4466 static compare_result
4467 compare_bound (gfc_expr
*a
, gfc_expr
*b
)
4471 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
4472 || b
== NULL
|| b
->expr_type
!= EXPR_CONSTANT
)
4475 /* If either of the types isn't INTEGER, we must have
4476 raised an error earlier. */
4478 if (a
->ts
.type
!= BT_INTEGER
|| b
->ts
.type
!= BT_INTEGER
)
4481 i
= mpz_cmp (a
->value
.integer
, b
->value
.integer
);
4491 /* Compare an integer expression with an integer. */
4493 static compare_result
4494 compare_bound_int (gfc_expr
*a
, int b
)
4498 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
4501 if (a
->ts
.type
!= BT_INTEGER
)
4502 gfc_internal_error ("compare_bound_int(): Bad expression");
4504 i
= mpz_cmp_si (a
->value
.integer
, b
);
4514 /* Compare an integer expression with a mpz_t. */
4516 static compare_result
4517 compare_bound_mpz_t (gfc_expr
*a
, mpz_t b
)
4521 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
4524 if (a
->ts
.type
!= BT_INTEGER
)
4525 gfc_internal_error ("compare_bound_int(): Bad expression");
4527 i
= mpz_cmp (a
->value
.integer
, b
);
4537 /* Compute the last value of a sequence given by a triplet.
4538 Return 0 if it wasn't able to compute the last value, or if the
4539 sequence if empty, and 1 otherwise. */
4542 compute_last_value_for_triplet (gfc_expr
*start
, gfc_expr
*end
,
4543 gfc_expr
*stride
, mpz_t last
)
4547 if (start
== NULL
|| start
->expr_type
!= EXPR_CONSTANT
4548 || end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
4549 || (stride
!= NULL
&& stride
->expr_type
!= EXPR_CONSTANT
))
4552 if (start
->ts
.type
!= BT_INTEGER
|| end
->ts
.type
!= BT_INTEGER
4553 || (stride
!= NULL
&& stride
->ts
.type
!= BT_INTEGER
))
4556 if (stride
== NULL
|| compare_bound_int (stride
, 1) == CMP_EQ
)
4558 if (compare_bound (start
, end
) == CMP_GT
)
4560 mpz_set (last
, end
->value
.integer
);
4564 if (compare_bound_int (stride
, 0) == CMP_GT
)
4566 /* Stride is positive */
4567 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) > 0)
4572 /* Stride is negative */
4573 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) < 0)
4578 mpz_sub (rem
, end
->value
.integer
, start
->value
.integer
);
4579 mpz_tdiv_r (rem
, rem
, stride
->value
.integer
);
4580 mpz_sub (last
, end
->value
.integer
, rem
);
4587 /* Compare a single dimension of an array reference to the array
4591 check_dimension (int i
, gfc_array_ref
*ar
, gfc_array_spec
*as
)
4595 if (ar
->dimen_type
[i
] == DIMEN_STAR
)
4597 gcc_assert (ar
->stride
[i
] == NULL
);
4598 /* This implies [*] as [*:] and [*:3] are not possible. */
4599 if (ar
->start
[i
] == NULL
)
4601 gcc_assert (ar
->end
[i
] == NULL
);
4606 /* Given start, end and stride values, calculate the minimum and
4607 maximum referenced indexes. */
4609 switch (ar
->dimen_type
[i
])
4612 case DIMEN_THIS_IMAGE
:
4617 if (compare_bound (ar
->start
[i
], as
->lower
[i
]) == CMP_LT
)
4620 gfc_warning (0, "Array reference at %L is out of bounds "
4621 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4622 mpz_get_si (ar
->start
[i
]->value
.integer
),
4623 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4625 gfc_warning (0, "Array reference at %L is out of bounds "
4626 "(%ld < %ld) in codimension %d", &ar
->c_where
[i
],
4627 mpz_get_si (ar
->start
[i
]->value
.integer
),
4628 mpz_get_si (as
->lower
[i
]->value
.integer
),
4632 if (compare_bound (ar
->start
[i
], as
->upper
[i
]) == CMP_GT
)
4635 gfc_warning (0, "Array reference at %L is out of bounds "
4636 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4637 mpz_get_si (ar
->start
[i
]->value
.integer
),
4638 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4640 gfc_warning (0, "Array reference at %L is out of bounds "
4641 "(%ld > %ld) in codimension %d", &ar
->c_where
[i
],
4642 mpz_get_si (ar
->start
[i
]->value
.integer
),
4643 mpz_get_si (as
->upper
[i
]->value
.integer
),
4652 #define AR_START (ar->start[i] ? ar->start[i] : as->lower[i])
4653 #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i])
4655 compare_result comp_start_end
= compare_bound (AR_START
, AR_END
);
4657 /* Check for zero stride, which is not allowed. */
4658 if (compare_bound_int (ar
->stride
[i
], 0) == CMP_EQ
)
4660 gfc_error ("Illegal stride of zero at %L", &ar
->c_where
[i
]);
4664 /* if start == len || (stride > 0 && start < len)
4665 || (stride < 0 && start > len),
4666 then the array section contains at least one element. In this
4667 case, there is an out-of-bounds access if
4668 (start < lower || start > upper). */
4669 if (compare_bound (AR_START
, AR_END
) == CMP_EQ
4670 || ((compare_bound_int (ar
->stride
[i
], 0) == CMP_GT
4671 || ar
->stride
[i
] == NULL
) && comp_start_end
== CMP_LT
)
4672 || (compare_bound_int (ar
->stride
[i
], 0) == CMP_LT
4673 && comp_start_end
== CMP_GT
))
4675 if (compare_bound (AR_START
, as
->lower
[i
]) == CMP_LT
)
4677 gfc_warning (0, "Lower array reference at %L is out of bounds "
4678 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4679 mpz_get_si (AR_START
->value
.integer
),
4680 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4683 if (compare_bound (AR_START
, as
->upper
[i
]) == CMP_GT
)
4685 gfc_warning (0, "Lower array reference at %L is out of bounds "
4686 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4687 mpz_get_si (AR_START
->value
.integer
),
4688 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4693 /* If we can compute the highest index of the array section,
4694 then it also has to be between lower and upper. */
4695 mpz_init (last_value
);
4696 if (compute_last_value_for_triplet (AR_START
, AR_END
, ar
->stride
[i
],
4699 if (compare_bound_mpz_t (as
->lower
[i
], last_value
) == CMP_GT
)
4701 gfc_warning (0, "Upper array reference at %L is out of bounds "
4702 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4703 mpz_get_si (last_value
),
4704 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4705 mpz_clear (last_value
);
4708 if (compare_bound_mpz_t (as
->upper
[i
], last_value
) == CMP_LT
)
4710 gfc_warning (0, "Upper array reference at %L is out of bounds "
4711 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4712 mpz_get_si (last_value
),
4713 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4714 mpz_clear (last_value
);
4718 mpz_clear (last_value
);
4726 gfc_internal_error ("check_dimension(): Bad array reference");
4733 /* Compare an array reference with an array specification. */
4736 compare_spec_to_ref (gfc_array_ref
*ar
)
4743 /* TODO: Full array sections are only allowed as actual parameters. */
4744 if (as
->type
== AS_ASSUMED_SIZE
4745 && (/*ar->type == AR_FULL
4746 ||*/ (ar
->type
== AR_SECTION
4747 && ar
->dimen_type
[i
] == DIMEN_RANGE
&& ar
->end
[i
] == NULL
)))
4749 gfc_error ("Rightmost upper bound of assumed size array section "
4750 "not specified at %L", &ar
->where
);
4754 if (ar
->type
== AR_FULL
)
4757 if (as
->rank
!= ar
->dimen
)
4759 gfc_error ("Rank mismatch in array reference at %L (%d/%d)",
4760 &ar
->where
, ar
->dimen
, as
->rank
);
4764 /* ar->codimen == 0 is a local array. */
4765 if (as
->corank
!= ar
->codimen
&& ar
->codimen
!= 0)
4767 gfc_error ("Coindex rank mismatch in array reference at %L (%d/%d)",
4768 &ar
->where
, ar
->codimen
, as
->corank
);
4772 for (i
= 0; i
< as
->rank
; i
++)
4773 if (!check_dimension (i
, ar
, as
))
4776 /* Local access has no coarray spec. */
4777 if (ar
->codimen
!= 0)
4778 for (i
= as
->rank
; i
< as
->rank
+ as
->corank
; i
++)
4780 if (ar
->dimen_type
[i
] != DIMEN_ELEMENT
&& !ar
->in_allocate
4781 && ar
->dimen_type
[i
] != DIMEN_THIS_IMAGE
)
4783 gfc_error ("Coindex of codimension %d must be a scalar at %L",
4784 i
+ 1 - as
->rank
, &ar
->where
);
4787 if (!check_dimension (i
, ar
, as
))
4795 /* Resolve one part of an array index. */
4798 gfc_resolve_index_1 (gfc_expr
*index
, int check_scalar
,
4799 int force_index_integer_kind
)
4806 if (!gfc_resolve_expr (index
))
4809 if (check_scalar
&& index
->rank
!= 0)
4811 gfc_error ("Array index at %L must be scalar", &index
->where
);
4815 if (index
->ts
.type
!= BT_INTEGER
&& index
->ts
.type
!= BT_REAL
)
4817 gfc_error ("Array index at %L must be of INTEGER type, found %s",
4818 &index
->where
, gfc_basic_typename (index
->ts
.type
));
4822 if (index
->ts
.type
== BT_REAL
)
4823 if (!gfc_notify_std (GFC_STD_LEGACY
, "REAL array index at %L",
4827 if ((index
->ts
.kind
!= gfc_index_integer_kind
4828 && force_index_integer_kind
)
4829 || index
->ts
.type
!= BT_INTEGER
)
4832 ts
.type
= BT_INTEGER
;
4833 ts
.kind
= gfc_index_integer_kind
;
4835 gfc_convert_type_warn (index
, &ts
, 2, 0);
4841 /* Resolve one part of an array index. */
4844 gfc_resolve_index (gfc_expr
*index
, int check_scalar
)
4846 return gfc_resolve_index_1 (index
, check_scalar
, 1);
4849 /* Resolve a dim argument to an intrinsic function. */
4852 gfc_resolve_dim_arg (gfc_expr
*dim
)
4857 if (!gfc_resolve_expr (dim
))
4862 gfc_error ("Argument dim at %L must be scalar", &dim
->where
);
4867 if (dim
->ts
.type
!= BT_INTEGER
)
4869 gfc_error ("Argument dim at %L must be of INTEGER type", &dim
->where
);
4873 if (dim
->ts
.kind
!= gfc_index_integer_kind
)
4878 ts
.type
= BT_INTEGER
;
4879 ts
.kind
= gfc_index_integer_kind
;
4881 gfc_convert_type_warn (dim
, &ts
, 2, 0);
4887 /* Given an expression that contains array references, update those array
4888 references to point to the right array specifications. While this is
4889 filled in during matching, this information is difficult to save and load
4890 in a module, so we take care of it here.
4892 The idea here is that the original array reference comes from the
4893 base symbol. We traverse the list of reference structures, setting
4894 the stored reference to references. Component references can
4895 provide an additional array specification. */
4897 resolve_assoc_var (gfc_symbol
* sym
, bool resolve_target
);
4900 find_array_spec (gfc_expr
*e
)
4905 bool class_as
= false;
4907 if (e
->symtree
->n
.sym
->assoc
)
4909 if (e
->symtree
->n
.sym
->assoc
->target
)
4910 gfc_resolve_expr (e
->symtree
->n
.sym
->assoc
->target
);
4911 resolve_assoc_var (e
->symtree
->n
.sym
, false);
4914 if (e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
)
4916 as
= CLASS_DATA (e
->symtree
->n
.sym
)->as
;
4920 as
= e
->symtree
->n
.sym
->as
;
4922 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4927 gfc_internal_error ("find_array_spec(): Missing spec");
4934 c
= ref
->u
.c
.component
;
4935 if (c
->attr
.dimension
)
4937 if (as
!= NULL
&& !(class_as
&& as
== c
->as
))
4938 gfc_internal_error ("find_array_spec(): unused as(1)");
4950 gfc_internal_error ("find_array_spec(): unused as(2)");
4954 /* Resolve an array reference. */
4957 resolve_array_ref (gfc_array_ref
*ar
)
4959 int i
, check_scalar
;
4962 for (i
= 0; i
< ar
->dimen
+ ar
->codimen
; i
++)
4964 check_scalar
= ar
->dimen_type
[i
] == DIMEN_RANGE
;
4966 /* Do not force gfc_index_integer_kind for the start. We can
4967 do fine with any integer kind. This avoids temporary arrays
4968 created for indexing with a vector. */
4969 if (!gfc_resolve_index_1 (ar
->start
[i
], check_scalar
, 0))
4971 if (!gfc_resolve_index (ar
->end
[i
], check_scalar
))
4973 if (!gfc_resolve_index (ar
->stride
[i
], check_scalar
))
4978 if (ar
->dimen_type
[i
] == DIMEN_UNKNOWN
)
4982 ar
->dimen_type
[i
] = DIMEN_ELEMENT
;
4986 ar
->dimen_type
[i
] = DIMEN_VECTOR
;
4987 if (e
->expr_type
== EXPR_VARIABLE
4988 && e
->symtree
->n
.sym
->ts
.type
== BT_DERIVED
)
4989 ar
->start
[i
] = gfc_get_parentheses (e
);
4993 gfc_error ("Array index at %L is an array of rank %d",
4994 &ar
->c_where
[i
], e
->rank
);
4998 /* Fill in the upper bound, which may be lower than the
4999 specified one for something like a(2:10:5), which is
5000 identical to a(2:7:5). Only relevant for strides not equal
5001 to one. Don't try a division by zero. */
5002 if (ar
->dimen_type
[i
] == DIMEN_RANGE
5003 && ar
->stride
[i
] != NULL
&& ar
->stride
[i
]->expr_type
== EXPR_CONSTANT
5004 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 1L) != 0
5005 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 0L) != 0)
5009 if (gfc_ref_dimen_size (ar
, i
, &size
, &end
))
5011 if (ar
->end
[i
] == NULL
)
5014 gfc_get_constant_expr (BT_INTEGER
, gfc_index_integer_kind
,
5016 mpz_set (ar
->end
[i
]->value
.integer
, end
);
5018 else if (ar
->end
[i
]->ts
.type
== BT_INTEGER
5019 && ar
->end
[i
]->expr_type
== EXPR_CONSTANT
)
5021 mpz_set (ar
->end
[i
]->value
.integer
, end
);
5032 if (ar
->type
== AR_FULL
)
5034 if (ar
->as
->rank
== 0)
5035 ar
->type
= AR_ELEMENT
;
5037 /* Make sure array is the same as array(:,:), this way
5038 we don't need to special case all the time. */
5039 ar
->dimen
= ar
->as
->rank
;
5040 for (i
= 0; i
< ar
->dimen
; i
++)
5042 ar
->dimen_type
[i
] = DIMEN_RANGE
;
5044 gcc_assert (ar
->start
[i
] == NULL
);
5045 gcc_assert (ar
->end
[i
] == NULL
);
5046 gcc_assert (ar
->stride
[i
] == NULL
);
5050 /* If the reference type is unknown, figure out what kind it is. */
5052 if (ar
->type
== AR_UNKNOWN
)
5054 ar
->type
= AR_ELEMENT
;
5055 for (i
= 0; i
< ar
->dimen
; i
++)
5056 if (ar
->dimen_type
[i
] == DIMEN_RANGE
5057 || ar
->dimen_type
[i
] == DIMEN_VECTOR
)
5059 ar
->type
= AR_SECTION
;
5064 if (!ar
->as
->cray_pointee
&& !compare_spec_to_ref (ar
))
5067 if (ar
->as
->corank
&& ar
->codimen
== 0)
5070 ar
->codimen
= ar
->as
->corank
;
5071 for (n
= ar
->dimen
; n
< ar
->dimen
+ ar
->codimen
; n
++)
5072 ar
->dimen_type
[n
] = DIMEN_THIS_IMAGE
;
5080 gfc_resolve_substring (gfc_ref
*ref
, bool *equal_length
)
5082 int k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
5084 if (ref
->u
.ss
.start
!= NULL
)
5086 if (!gfc_resolve_expr (ref
->u
.ss
.start
))
5089 if (ref
->u
.ss
.start
->ts
.type
!= BT_INTEGER
)
5091 gfc_error ("Substring start index at %L must be of type INTEGER",
5092 &ref
->u
.ss
.start
->where
);
5096 if (ref
->u
.ss
.start
->rank
!= 0)
5098 gfc_error ("Substring start index at %L must be scalar",
5099 &ref
->u
.ss
.start
->where
);
5103 if (compare_bound_int (ref
->u
.ss
.start
, 1) == CMP_LT
5104 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
5105 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
5107 gfc_error ("Substring start index at %L is less than one",
5108 &ref
->u
.ss
.start
->where
);
5113 if (ref
->u
.ss
.end
!= NULL
)
5115 if (!gfc_resolve_expr (ref
->u
.ss
.end
))
5118 if (ref
->u
.ss
.end
->ts
.type
!= BT_INTEGER
)
5120 gfc_error ("Substring end index at %L must be of type INTEGER",
5121 &ref
->u
.ss
.end
->where
);
5125 if (ref
->u
.ss
.end
->rank
!= 0)
5127 gfc_error ("Substring end index at %L must be scalar",
5128 &ref
->u
.ss
.end
->where
);
5132 if (ref
->u
.ss
.length
!= NULL
5133 && compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.length
->length
) == CMP_GT
5134 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
5135 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
5137 gfc_error ("Substring end index at %L exceeds the string length",
5138 &ref
->u
.ss
.start
->where
);
5142 if (compare_bound_mpz_t (ref
->u
.ss
.end
,
5143 gfc_integer_kinds
[k
].huge
) == CMP_GT
5144 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
5145 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
5147 gfc_error ("Substring end index at %L is too large",
5148 &ref
->u
.ss
.end
->where
);
5151 /* If the substring has the same length as the original
5152 variable, the reference itself can be deleted. */
5154 if (ref
->u
.ss
.length
!= NULL
5155 && compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.length
->length
) == CMP_EQ
5156 && compare_bound_int (ref
->u
.ss
.start
, 1) == CMP_EQ
)
5157 *equal_length
= true;
5164 /* This function supplies missing substring charlens. */
5167 gfc_resolve_substring_charlen (gfc_expr
*e
)
5170 gfc_expr
*start
, *end
;
5171 gfc_typespec
*ts
= NULL
;
5174 for (char_ref
= e
->ref
; char_ref
; char_ref
= char_ref
->next
)
5176 if (char_ref
->type
== REF_SUBSTRING
|| char_ref
->type
== REF_INQUIRY
)
5178 if (char_ref
->type
== REF_COMPONENT
)
5179 ts
= &char_ref
->u
.c
.component
->ts
;
5182 if (!char_ref
|| char_ref
->type
== REF_INQUIRY
)
5185 gcc_assert (char_ref
->next
== NULL
);
5189 if (e
->ts
.u
.cl
->length
)
5190 gfc_free_expr (e
->ts
.u
.cl
->length
);
5191 else if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.dummy
)
5196 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5198 if (char_ref
->u
.ss
.start
)
5199 start
= gfc_copy_expr (char_ref
->u
.ss
.start
);
5201 start
= gfc_get_int_expr (gfc_charlen_int_kind
, NULL
, 1);
5203 if (char_ref
->u
.ss
.end
)
5204 end
= gfc_copy_expr (char_ref
->u
.ss
.end
);
5205 else if (e
->expr_type
== EXPR_VARIABLE
)
5208 ts
= &e
->symtree
->n
.sym
->ts
;
5209 end
= gfc_copy_expr (ts
->u
.cl
->length
);
5216 gfc_free_expr (start
);
5217 gfc_free_expr (end
);
5221 /* Length = (end - start + 1).
5222 Check first whether it has a constant length. */
5223 if (gfc_dep_difference (end
, start
, &diff
))
5225 gfc_expr
*len
= gfc_get_constant_expr (BT_INTEGER
, gfc_charlen_int_kind
,
5228 mpz_add_ui (len
->value
.integer
, diff
, 1);
5230 e
->ts
.u
.cl
->length
= len
;
5231 /* The check for length < 0 is handled below */
5235 e
->ts
.u
.cl
->length
= gfc_subtract (end
, start
);
5236 e
->ts
.u
.cl
->length
= gfc_add (e
->ts
.u
.cl
->length
,
5237 gfc_get_int_expr (gfc_charlen_int_kind
,
5241 /* F2008, 6.4.1: Both the starting point and the ending point shall
5242 be within the range 1, 2, ..., n unless the starting point exceeds
5243 the ending point, in which case the substring has length zero. */
5245 if (mpz_cmp_si (e
->ts
.u
.cl
->length
->value
.integer
, 0) < 0)
5246 mpz_set_si (e
->ts
.u
.cl
->length
->value
.integer
, 0);
5248 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
5249 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
5251 /* Make sure that the length is simplified. */
5252 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 1);
5253 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
5257 /* Resolve subtype references. */
5260 gfc_resolve_ref (gfc_expr
*expr
)
5262 int current_part_dimension
, n_components
, seen_part_dimension
, dim
;
5263 gfc_ref
*ref
, **prev
, *array_ref
;
5266 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
5267 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.as
== NULL
)
5269 find_array_spec (expr
);
5273 for (prev
= &expr
->ref
; *prev
!= NULL
;
5274 prev
= *prev
== NULL
? prev
: &(*prev
)->next
)
5275 switch ((*prev
)->type
)
5278 if (!resolve_array_ref (&(*prev
)->u
.ar
))
5287 equal_length
= false;
5288 if (!gfc_resolve_substring (*prev
, &equal_length
))
5291 if (expr
->expr_type
!= EXPR_SUBSTRING
&& equal_length
)
5293 /* Remove the reference and move the charlen, if any. */
5297 expr
->ts
.u
.cl
= ref
->u
.ss
.length
;
5298 ref
->u
.ss
.length
= NULL
;
5299 gfc_free_ref_list (ref
);
5304 /* Check constraints on part references. */
5306 current_part_dimension
= 0;
5307 seen_part_dimension
= 0;
5311 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
5317 switch (ref
->u
.ar
.type
)
5320 /* Coarray scalar. */
5321 if (ref
->u
.ar
.as
->rank
== 0)
5323 current_part_dimension
= 0;
5328 current_part_dimension
= 1;
5333 current_part_dimension
= 0;
5337 gfc_internal_error ("resolve_ref(): Bad array reference");
5343 if (current_part_dimension
|| seen_part_dimension
)
5346 if (ref
->u
.c
.component
->attr
.pointer
5347 || ref
->u
.c
.component
->attr
.proc_pointer
5348 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
5349 && CLASS_DATA (ref
->u
.c
.component
)->attr
.pointer
))
5351 gfc_error ("Component to the right of a part reference "
5352 "with nonzero rank must not have the POINTER "
5353 "attribute at %L", &expr
->where
);
5356 else if (ref
->u
.c
.component
->attr
.allocatable
5357 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
5358 && CLASS_DATA (ref
->u
.c
.component
)->attr
.allocatable
))
5361 gfc_error ("Component to the right of a part reference "
5362 "with nonzero rank must not have the ALLOCATABLE "
5363 "attribute at %L", &expr
->where
);
5375 /* Implement requirement in note 9.7 of F2018 that the result of the
5376 LEN inquiry be a scalar. */
5377 if (ref
->u
.i
== INQUIRY_LEN
&& array_ref
&& expr
->ts
.deferred
)
5379 array_ref
->u
.ar
.type
= AR_ELEMENT
;
5381 /* INQUIRY_LEN is not evaluated from the rest of the expr
5382 but directly from the string length. This means that setting
5383 the array indices to one does not matter but might trigger
5384 a runtime bounds error. Suppress the check. */
5385 expr
->no_bounds_check
= 1;
5386 for (dim
= 0; dim
< array_ref
->u
.ar
.dimen
; dim
++)
5388 array_ref
->u
.ar
.dimen_type
[dim
] = DIMEN_ELEMENT
;
5389 if (array_ref
->u
.ar
.start
[dim
])
5390 gfc_free_expr (array_ref
->u
.ar
.start
[dim
]);
5391 array_ref
->u
.ar
.start
[dim
]
5392 = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
5393 if (array_ref
->u
.ar
.end
[dim
])
5394 gfc_free_expr (array_ref
->u
.ar
.end
[dim
]);
5395 if (array_ref
->u
.ar
.stride
[dim
])
5396 gfc_free_expr (array_ref
->u
.ar
.stride
[dim
]);
5402 if (((ref
->type
== REF_COMPONENT
&& n_components
> 1)
5403 || ref
->next
== NULL
)
5404 && current_part_dimension
5405 && seen_part_dimension
)
5407 gfc_error ("Two or more part references with nonzero rank must "
5408 "not be specified at %L", &expr
->where
);
5412 if (ref
->type
== REF_COMPONENT
)
5414 if (current_part_dimension
)
5415 seen_part_dimension
= 1;
5417 /* reset to make sure */
5418 current_part_dimension
= 0;
5426 /* Given an expression, determine its shape. This is easier than it sounds.
5427 Leaves the shape array NULL if it is not possible to determine the shape. */
5430 expression_shape (gfc_expr
*e
)
5432 mpz_t array
[GFC_MAX_DIMENSIONS
];
5435 if (e
->rank
<= 0 || e
->shape
!= NULL
)
5438 for (i
= 0; i
< e
->rank
; i
++)
5439 if (!gfc_array_dimen_size (e
, i
, &array
[i
]))
5442 e
->shape
= gfc_get_shape (e
->rank
);
5444 memcpy (e
->shape
, array
, e
->rank
* sizeof (mpz_t
));
5449 for (i
--; i
>= 0; i
--)
5450 mpz_clear (array
[i
]);
5454 /* Given a variable expression node, compute the rank of the expression by
5455 examining the base symbol and any reference structures it may have. */
5458 gfc_expression_rank (gfc_expr
*e
)
5463 /* Just to make sure, because EXPR_COMPCALL's also have an e->ref and that
5464 could lead to serious confusion... */
5465 gcc_assert (e
->expr_type
!= EXPR_COMPCALL
);
5469 if (e
->expr_type
== EXPR_ARRAY
)
5471 /* Constructors can have a rank different from one via RESHAPE(). */
5473 e
->rank
= ((e
->symtree
== NULL
|| e
->symtree
->n
.sym
->as
== NULL
)
5474 ? 0 : e
->symtree
->n
.sym
->as
->rank
);
5480 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5482 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.proc_pointer
5483 && ref
->u
.c
.component
->attr
.function
&& !ref
->next
)
5484 rank
= ref
->u
.c
.component
->as
? ref
->u
.c
.component
->as
->rank
: 0;
5486 if (ref
->type
!= REF_ARRAY
)
5489 if (ref
->u
.ar
.type
== AR_FULL
)
5491 rank
= ref
->u
.ar
.as
->rank
;
5495 if (ref
->u
.ar
.type
== AR_SECTION
)
5497 /* Figure out the rank of the section. */
5499 gfc_internal_error ("gfc_expression_rank(): Two array specs");
5501 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
5502 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_RANGE
5503 || ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
5513 expression_shape (e
);
5518 add_caf_get_intrinsic (gfc_expr
*e
)
5520 gfc_expr
*wrapper
, *tmp_expr
;
5524 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5525 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
5530 for (n
= ref
->u
.ar
.dimen
; n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
5531 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_ELEMENT
)
5534 tmp_expr
= XCNEW (gfc_expr
);
5536 wrapper
= gfc_build_intrinsic_call (gfc_current_ns
, GFC_ISYM_CAF_GET
,
5537 "caf_get", tmp_expr
->where
, 1, tmp_expr
);
5538 wrapper
->ts
= e
->ts
;
5539 wrapper
->rank
= e
->rank
;
5541 wrapper
->shape
= gfc_copy_shape (e
->shape
, e
->rank
);
5548 remove_caf_get_intrinsic (gfc_expr
*e
)
5550 gcc_assert (e
->expr_type
== EXPR_FUNCTION
&& e
->value
.function
.isym
5551 && e
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
);
5552 gfc_expr
*e2
= e
->value
.function
.actual
->expr
;
5553 e
->value
.function
.actual
->expr
= NULL
;
5554 gfc_free_actual_arglist (e
->value
.function
.actual
);
5555 gfc_free_shape (&e
->shape
, e
->rank
);
5561 /* Resolve a variable expression. */
5564 resolve_variable (gfc_expr
*e
)
5571 if (e
->symtree
== NULL
)
5573 sym
= e
->symtree
->n
.sym
;
5575 /* Use same check as for TYPE(*) below; this check has to be before TYPE(*)
5576 as ts.type is set to BT_ASSUMED in resolve_symbol. */
5577 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
5579 if (!actual_arg
|| inquiry_argument
)
5581 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may only "
5582 "be used as actual argument", sym
->name
, &e
->where
);
5586 /* TS 29113, 407b. */
5587 else if (e
->ts
.type
== BT_ASSUMED
)
5591 gfc_error ("Assumed-type variable %s at %L may only be used "
5592 "as actual argument", sym
->name
, &e
->where
);
5595 else if (inquiry_argument
&& !first_actual_arg
)
5597 /* FIXME: It doesn't work reliably as inquiry_argument is not set
5598 for all inquiry functions in resolve_function; the reason is
5599 that the function-name resolution happens too late in that
5601 gfc_error ("Assumed-type variable %s at %L as actual argument to "
5602 "an inquiry function shall be the first argument",
5603 sym
->name
, &e
->where
);
5607 /* TS 29113, C535b. */
5608 else if (((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
5609 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
5610 && CLASS_DATA (sym
)->as
5611 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
5612 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
5613 && sym
->as
->type
== AS_ASSUMED_RANK
))
5614 && !sym
->attr
.select_rank_temporary
)
5617 && !(cs_base
&& cs_base
->current
5618 && cs_base
->current
->op
== EXEC_SELECT_RANK
))
5620 gfc_error ("Assumed-rank variable %s at %L may only be used as "
5621 "actual argument", sym
->name
, &e
->where
);
5624 else if (inquiry_argument
&& !first_actual_arg
)
5626 /* FIXME: It doesn't work reliably as inquiry_argument is not set
5627 for all inquiry functions in resolve_function; the reason is
5628 that the function-name resolution happens too late in that
5630 gfc_error ("Assumed-rank variable %s at %L as actual argument "
5631 "to an inquiry function shall be the first argument",
5632 sym
->name
, &e
->where
);
5637 if ((sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
)) && e
->ref
5638 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
5639 && e
->ref
->next
== NULL
))
5641 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall not have "
5642 "a subobject reference", sym
->name
, &e
->ref
->u
.ar
.where
);
5645 /* TS 29113, 407b. */
5646 else if (e
->ts
.type
== BT_ASSUMED
&& e
->ref
5647 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
5648 && e
->ref
->next
== NULL
))
5650 gfc_error ("Assumed-type variable %s at %L shall not have a subobject "
5651 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
5655 /* TS 29113, C535b. */
5656 if (((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
5657 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
5658 && CLASS_DATA (sym
)->as
5659 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
5660 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
5661 && sym
->as
->type
== AS_ASSUMED_RANK
))
5663 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
5664 && e
->ref
->next
== NULL
))
5666 gfc_error ("Assumed-rank variable %s at %L shall not have a subobject "
5667 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
5671 /* For variables that are used in an associate (target => object) where
5672 the object's basetype is array valued while the target is scalar,
5673 the ts' type of the component refs is still array valued, which
5674 can't be translated that way. */
5675 if (sym
->assoc
&& e
->rank
== 0 && e
->ref
&& sym
->ts
.type
== BT_CLASS
5676 && sym
->assoc
->target
&& sym
->assoc
->target
->ts
.type
== BT_CLASS
5677 && CLASS_DATA (sym
->assoc
->target
)->as
)
5679 gfc_ref
*ref
= e
->ref
;
5685 ref
->u
.c
.sym
= sym
->ts
.u
.derived
;
5686 /* Stop the loop. */
5696 /* If this is an associate-name, it may be parsed with an array reference
5697 in error even though the target is scalar. Fail directly in this case.
5698 TODO Understand why class scalar expressions must be excluded. */
5699 if (sym
->assoc
&& !(sym
->ts
.type
== BT_CLASS
&& e
->rank
== 0))
5701 if (sym
->ts
.type
== BT_CLASS
)
5702 gfc_fix_class_refs (e
);
5703 if (!sym
->attr
.dimension
&& e
->ref
&& e
->ref
->type
== REF_ARRAY
)
5705 else if (sym
->attr
.dimension
&& (!e
->ref
|| e
->ref
->type
!= REF_ARRAY
))
5707 /* This can happen because the parser did not detect that the
5708 associate name is an array and the expression had no array
5710 gfc_ref
*ref
= gfc_get_ref ();
5711 ref
->type
= REF_ARRAY
;
5712 ref
->u
.ar
= *gfc_get_array_ref();
5713 ref
->u
.ar
.type
= AR_FULL
;
5716 ref
->u
.ar
.as
= sym
->as
;
5717 ref
->u
.ar
.dimen
= sym
->as
->rank
;
5725 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.generic
)
5726 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
5728 /* On the other hand, the parser may not have known this is an array;
5729 in this case, we have to add a FULL reference. */
5730 if (sym
->assoc
&& sym
->attr
.dimension
&& !e
->ref
)
5732 e
->ref
= gfc_get_ref ();
5733 e
->ref
->type
= REF_ARRAY
;
5734 e
->ref
->u
.ar
.type
= AR_FULL
;
5735 e
->ref
->u
.ar
.dimen
= 0;
5738 /* Like above, but for class types, where the checking whether an array
5739 ref is present is more complicated. Furthermore make sure not to add
5740 the full array ref to _vptr or _len refs. */
5741 if (sym
->assoc
&& sym
->ts
.type
== BT_CLASS
5742 && CLASS_DATA (sym
)->attr
.dimension
5743 && (e
->ts
.type
!= BT_DERIVED
|| !e
->ts
.u
.derived
->attr
.vtype
))
5745 gfc_ref
*ref
, *newref
;
5747 newref
= gfc_get_ref ();
5748 newref
->type
= REF_ARRAY
;
5749 newref
->u
.ar
.type
= AR_FULL
;
5750 newref
->u
.ar
.dimen
= 0;
5751 /* Because this is an associate var and the first ref either is a ref to
5752 the _data component or not, no traversal of the ref chain is
5753 needed. The array ref needs to be inserted after the _data ref,
5754 or when that is not present, which may happend for polymorphic
5755 types, then at the first position. */
5759 else if (ref
->type
== REF_COMPONENT
5760 && strcmp ("_data", ref
->u
.c
.component
->name
) == 0)
5762 if (!ref
->next
|| ref
->next
->type
!= REF_ARRAY
)
5764 newref
->next
= ref
->next
;
5768 /* Array ref present already. */
5769 gfc_free_ref_list (newref
);
5771 else if (ref
->type
== REF_ARRAY
)
5772 /* Array ref present already. */
5773 gfc_free_ref_list (newref
);
5781 if (e
->ref
&& !gfc_resolve_ref (e
))
5784 if (sym
->attr
.flavor
== FL_PROCEDURE
5785 && (!sym
->attr
.function
5786 || (sym
->attr
.function
&& sym
->result
5787 && sym
->result
->attr
.proc_pointer
5788 && !sym
->result
->attr
.function
)))
5790 e
->ts
.type
= BT_PROCEDURE
;
5791 goto resolve_procedure
;
5794 if (sym
->ts
.type
!= BT_UNKNOWN
)
5795 gfc_variable_attr (e
, &e
->ts
);
5796 else if (sym
->attr
.flavor
== FL_PROCEDURE
5797 && sym
->attr
.function
&& sym
->result
5798 && sym
->result
->ts
.type
!= BT_UNKNOWN
5799 && sym
->result
->attr
.proc_pointer
)
5800 e
->ts
= sym
->result
->ts
;
5803 /* Must be a simple variable reference. */
5804 if (!gfc_set_default_type (sym
, 1, sym
->ns
))
5809 if (check_assumed_size_reference (sym
, e
))
5812 /* Deal with forward references to entries during gfc_resolve_code, to
5813 satisfy, at least partially, 12.5.2.5. */
5814 if (gfc_current_ns
->entries
5815 && current_entry_id
== sym
->entry_id
5818 && cs_base
->current
->op
!= EXEC_ENTRY
)
5820 gfc_entry_list
*entry
;
5821 gfc_formal_arglist
*formal
;
5823 bool seen
, saved_specification_expr
;
5825 /* If the symbol is a dummy... */
5826 if (sym
->attr
.dummy
&& sym
->ns
== gfc_current_ns
)
5828 entry
= gfc_current_ns
->entries
;
5831 /* ...test if the symbol is a parameter of previous entries. */
5832 for (; entry
&& entry
->id
<= current_entry_id
; entry
= entry
->next
)
5833 for (formal
= entry
->sym
->formal
; formal
; formal
= formal
->next
)
5835 if (formal
->sym
&& sym
->name
== formal
->sym
->name
)
5842 /* If it has not been seen as a dummy, this is an error. */
5845 if (specification_expr
)
5846 gfc_error ("Variable %qs, used in a specification expression"
5847 ", is referenced at %L before the ENTRY statement "
5848 "in which it is a parameter",
5849 sym
->name
, &cs_base
->current
->loc
);
5851 gfc_error ("Variable %qs is used at %L before the ENTRY "
5852 "statement in which it is a parameter",
5853 sym
->name
, &cs_base
->current
->loc
);
5858 /* Now do the same check on the specification expressions. */
5859 saved_specification_expr
= specification_expr
;
5860 specification_expr
= true;
5861 if (sym
->ts
.type
== BT_CHARACTER
5862 && !gfc_resolve_expr (sym
->ts
.u
.cl
->length
))
5866 for (n
= 0; n
< sym
->as
->rank
; n
++)
5868 if (!gfc_resolve_expr (sym
->as
->lower
[n
]))
5870 if (!gfc_resolve_expr (sym
->as
->upper
[n
]))
5873 specification_expr
= saved_specification_expr
;
5876 /* Update the symbol's entry level. */
5877 sym
->entry_id
= current_entry_id
+ 1;
5880 /* If a symbol has been host_associated mark it. This is used latter,
5881 to identify if aliasing is possible via host association. */
5882 if (sym
->attr
.flavor
== FL_VARIABLE
5883 && gfc_current_ns
->parent
5884 && (gfc_current_ns
->parent
== sym
->ns
5885 || (gfc_current_ns
->parent
->parent
5886 && gfc_current_ns
->parent
->parent
== sym
->ns
)))
5887 sym
->attr
.host_assoc
= 1;
5889 if (gfc_current_ns
->proc_name
5890 && sym
->attr
.dimension
5891 && (sym
->ns
!= gfc_current_ns
5892 || sym
->attr
.use_assoc
5893 || sym
->attr
.in_common
))
5894 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
5897 if (t
&& !resolve_procedure_expression (e
))
5900 /* F2008, C617 and C1229. */
5901 if (!inquiry_argument
&& (e
->ts
.type
== BT_CLASS
|| e
->ts
.type
== BT_DERIVED
)
5902 && gfc_is_coindexed (e
))
5904 gfc_ref
*ref
, *ref2
= NULL
;
5906 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5908 if (ref
->type
== REF_COMPONENT
)
5910 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
5914 for ( ; ref
; ref
= ref
->next
)
5915 if (ref
->type
== REF_COMPONENT
)
5918 /* Expression itself is not coindexed object. */
5919 if (ref
&& e
->ts
.type
== BT_CLASS
)
5921 gfc_error ("Polymorphic subobject of coindexed object at %L",
5926 /* Expression itself is coindexed object. */
5930 c
= ref2
? ref2
->u
.c
.component
: e
->symtree
->n
.sym
->components
;
5931 for ( ; c
; c
= c
->next
)
5932 if (c
->attr
.allocatable
&& c
->ts
.type
== BT_CLASS
)
5934 gfc_error ("Coindexed object with polymorphic allocatable "
5935 "subcomponent at %L", &e
->where
);
5943 gfc_expression_rank (e
);
5945 if (t
&& flag_coarray
== GFC_FCOARRAY_LIB
&& gfc_is_coindexed (e
))
5946 add_caf_get_intrinsic (e
);
5948 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_DEPRECATED
) && sym
!= sym
->result
)
5949 gfc_warning (OPT_Wdeprecated_declarations
,
5950 "Using variable %qs at %L is deprecated",
5951 sym
->name
, &e
->where
);
5952 /* Simplify cases where access to a parameter array results in a
5953 single constant. Suppress errors since those will have been
5954 issued before, as warnings. */
5955 if (e
->rank
== 0 && sym
->as
&& sym
->attr
.flavor
== FL_PARAMETER
)
5957 gfc_push_suppress_errors ();
5958 gfc_simplify_expr (e
, 1);
5959 gfc_pop_suppress_errors ();
5966 /* Checks to see that the correct symbol has been host associated.
5967 The only situation where this arises is that in which a twice
5968 contained function is parsed after the host association is made.
5969 Therefore, on detecting this, change the symbol in the expression
5970 and convert the array reference into an actual arglist if the old
5971 symbol is a variable. */
5973 check_host_association (gfc_expr
*e
)
5975 gfc_symbol
*sym
, *old_sym
;
5979 gfc_actual_arglist
*arg
, *tail
= NULL
;
5980 bool retval
= e
->expr_type
== EXPR_FUNCTION
;
5982 /* If the expression is the result of substitution in
5983 interface.c(gfc_extend_expr) because there is no way in
5984 which the host association can be wrong. */
5985 if (e
->symtree
== NULL
5986 || e
->symtree
->n
.sym
== NULL
5987 || e
->user_operator
)
5990 old_sym
= e
->symtree
->n
.sym
;
5992 if (gfc_current_ns
->parent
5993 && old_sym
->ns
!= gfc_current_ns
)
5995 /* Use the 'USE' name so that renamed module symbols are
5996 correctly handled. */
5997 gfc_find_symbol (e
->symtree
->name
, gfc_current_ns
, 1, &sym
);
5999 if (sym
&& old_sym
!= sym
6000 && sym
->ts
.type
== old_sym
->ts
.type
6001 && sym
->attr
.flavor
== FL_PROCEDURE
6002 && sym
->attr
.contained
)
6004 /* Clear the shape, since it might not be valid. */
6005 gfc_free_shape (&e
->shape
, e
->rank
);
6007 /* Give the expression the right symtree! */
6008 gfc_find_sym_tree (e
->symtree
->name
, NULL
, 1, &st
);
6009 gcc_assert (st
!= NULL
);
6011 if (old_sym
->attr
.flavor
== FL_PROCEDURE
6012 || e
->expr_type
== EXPR_FUNCTION
)
6014 /* Original was function so point to the new symbol, since
6015 the actual argument list is already attached to the
6017 e
->value
.function
.esym
= NULL
;
6022 /* Original was variable so convert array references into
6023 an actual arglist. This does not need any checking now
6024 since resolve_function will take care of it. */
6025 e
->value
.function
.actual
= NULL
;
6026 e
->expr_type
= EXPR_FUNCTION
;
6029 /* Ambiguity will not arise if the array reference is not
6030 the last reference. */
6031 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6032 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
6035 if ((ref
== NULL
|| ref
->type
!= REF_ARRAY
)
6036 && sym
->attr
.proc
== PROC_INTERNAL
)
6038 gfc_error ("%qs at %L is host associated at %L into "
6039 "a contained procedure with an internal "
6040 "procedure of the same name", sym
->name
,
6041 &old_sym
->declared_at
, &e
->where
);
6045 gcc_assert (ref
->type
== REF_ARRAY
);
6047 /* Grab the start expressions from the array ref and
6048 copy them into actual arguments. */
6049 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
6051 arg
= gfc_get_actual_arglist ();
6052 arg
->expr
= gfc_copy_expr (ref
->u
.ar
.start
[n
]);
6053 if (e
->value
.function
.actual
== NULL
)
6054 tail
= e
->value
.function
.actual
= arg
;
6062 /* Dump the reference list and set the rank. */
6063 gfc_free_ref_list (e
->ref
);
6065 e
->rank
= sym
->as
? sym
->as
->rank
: 0;
6068 gfc_resolve_expr (e
);
6072 /* This might have changed! */
6073 return e
->expr_type
== EXPR_FUNCTION
;
6078 gfc_resolve_character_operator (gfc_expr
*e
)
6080 gfc_expr
*op1
= e
->value
.op
.op1
;
6081 gfc_expr
*op2
= e
->value
.op
.op2
;
6082 gfc_expr
*e1
= NULL
;
6083 gfc_expr
*e2
= NULL
;
6085 gcc_assert (e
->value
.op
.op
== INTRINSIC_CONCAT
);
6087 if (op1
->ts
.u
.cl
&& op1
->ts
.u
.cl
->length
)
6088 e1
= gfc_copy_expr (op1
->ts
.u
.cl
->length
);
6089 else if (op1
->expr_type
== EXPR_CONSTANT
)
6090 e1
= gfc_get_int_expr (gfc_charlen_int_kind
, NULL
,
6091 op1
->value
.character
.length
);
6093 if (op2
->ts
.u
.cl
&& op2
->ts
.u
.cl
->length
)
6094 e2
= gfc_copy_expr (op2
->ts
.u
.cl
->length
);
6095 else if (op2
->expr_type
== EXPR_CONSTANT
)
6096 e2
= gfc_get_int_expr (gfc_charlen_int_kind
, NULL
,
6097 op2
->value
.character
.length
);
6099 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
6109 e
->ts
.u
.cl
->length
= gfc_add (e1
, e2
);
6110 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
6111 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
6112 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 0);
6113 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
6119 /* Ensure that an character expression has a charlen and, if possible, a
6120 length expression. */
6123 fixup_charlen (gfc_expr
*e
)
6125 /* The cases fall through so that changes in expression type and the need
6126 for multiple fixes are picked up. In all circumstances, a charlen should
6127 be available for the middle end to hang a backend_decl on. */
6128 switch (e
->expr_type
)
6131 gfc_resolve_character_operator (e
);
6135 if (e
->expr_type
== EXPR_ARRAY
)
6136 gfc_resolve_character_array_constructor (e
);
6139 case EXPR_SUBSTRING
:
6140 if (!e
->ts
.u
.cl
&& e
->ref
)
6141 gfc_resolve_substring_charlen (e
);
6146 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
6153 /* Update an actual argument to include the passed-object for type-bound
6154 procedures at the right position. */
6156 static gfc_actual_arglist
*
6157 update_arglist_pass (gfc_actual_arglist
* lst
, gfc_expr
* po
, unsigned argpos
,
6160 gcc_assert (argpos
> 0);
6164 gfc_actual_arglist
* result
;
6166 result
= gfc_get_actual_arglist ();
6170 result
->name
= name
;
6176 lst
->next
= update_arglist_pass (lst
->next
, po
, argpos
- 1, name
);
6178 lst
= update_arglist_pass (NULL
, po
, argpos
- 1, name
);
6183 /* Extract the passed-object from an EXPR_COMPCALL (a copy of it). */
6186 extract_compcall_passed_object (gfc_expr
* e
)
6190 if (e
->expr_type
== EXPR_UNKNOWN
)
6192 gfc_error ("Error in typebound call at %L",
6197 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
6199 if (e
->value
.compcall
.base_object
)
6200 po
= gfc_copy_expr (e
->value
.compcall
.base_object
);
6203 po
= gfc_get_expr ();
6204 po
->expr_type
= EXPR_VARIABLE
;
6205 po
->symtree
= e
->symtree
;
6206 po
->ref
= gfc_copy_ref (e
->ref
);
6207 po
->where
= e
->where
;
6210 if (!gfc_resolve_expr (po
))
6217 /* Update the arglist of an EXPR_COMPCALL expression to include the
6221 update_compcall_arglist (gfc_expr
* e
)
6224 gfc_typebound_proc
* tbp
;
6226 tbp
= e
->value
.compcall
.tbp
;
6231 po
= extract_compcall_passed_object (e
);
6235 if (tbp
->nopass
|| e
->value
.compcall
.ignore_pass
)
6241 if (tbp
->pass_arg_num
<= 0)
6244 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
6252 /* Extract the passed object from a PPC call (a copy of it). */
6255 extract_ppc_passed_object (gfc_expr
*e
)
6260 po
= gfc_get_expr ();
6261 po
->expr_type
= EXPR_VARIABLE
;
6262 po
->symtree
= e
->symtree
;
6263 po
->ref
= gfc_copy_ref (e
->ref
);
6264 po
->where
= e
->where
;
6266 /* Remove PPC reference. */
6268 while ((*ref
)->next
)
6269 ref
= &(*ref
)->next
;
6270 gfc_free_ref_list (*ref
);
6273 if (!gfc_resolve_expr (po
))
6280 /* Update the actual arglist of a procedure pointer component to include the
6284 update_ppc_arglist (gfc_expr
* e
)
6288 gfc_typebound_proc
* tb
;
6290 ppc
= gfc_get_proc_ptr_comp (e
);
6298 else if (tb
->nopass
)
6301 po
= extract_ppc_passed_object (e
);
6308 gfc_error ("Passed-object at %L must be scalar", &e
->where
);
6313 if (po
->ts
.type
== BT_DERIVED
&& po
->ts
.u
.derived
->attr
.abstract
)
6315 gfc_error ("Base object for procedure-pointer component call at %L is of"
6316 " ABSTRACT type %qs", &e
->where
, po
->ts
.u
.derived
->name
);
6320 gcc_assert (tb
->pass_arg_num
> 0);
6321 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
6329 /* Check that the object a TBP is called on is valid, i.e. it must not be
6330 of ABSTRACT type (as in subobject%abstract_parent%tbp()). */
6333 check_typebound_baseobject (gfc_expr
* e
)
6336 bool return_value
= false;
6338 base
= extract_compcall_passed_object (e
);
6342 if (base
->ts
.type
!= BT_DERIVED
&& base
->ts
.type
!= BT_CLASS
)
6344 gfc_error ("Error in typebound call at %L", &e
->where
);
6348 if (base
->ts
.type
== BT_CLASS
&& !gfc_expr_attr (base
).class_ok
)
6352 if (base
->ts
.type
== BT_DERIVED
&& base
->ts
.u
.derived
->attr
.abstract
)
6354 gfc_error ("Base object for type-bound procedure call at %L is of"
6355 " ABSTRACT type %qs", &e
->where
, base
->ts
.u
.derived
->name
);
6359 /* F08:C1230. If the procedure called is NOPASS,
6360 the base object must be scalar. */
6361 if (e
->value
.compcall
.tbp
->nopass
&& base
->rank
!= 0)
6363 gfc_error ("Base object for NOPASS type-bound procedure call at %L must"
6364 " be scalar", &e
->where
);
6368 return_value
= true;
6371 gfc_free_expr (base
);
6372 return return_value
;
6376 /* Resolve a call to a type-bound procedure, either function or subroutine,
6377 statically from the data in an EXPR_COMPCALL expression. The adapted
6378 arglist and the target-procedure symtree are returned. */
6381 resolve_typebound_static (gfc_expr
* e
, gfc_symtree
** target
,
6382 gfc_actual_arglist
** actual
)
6384 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
6385 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
6387 /* Update the actual arglist for PASS. */
6388 if (!update_compcall_arglist (e
))
6391 *actual
= e
->value
.compcall
.actual
;
6392 *target
= e
->value
.compcall
.tbp
->u
.specific
;
6394 gfc_free_ref_list (e
->ref
);
6396 e
->value
.compcall
.actual
= NULL
;
6398 /* If we find a deferred typebound procedure, check for derived types
6399 that an overriding typebound procedure has not been missed. */
6400 if (e
->value
.compcall
.name
6401 && !e
->value
.compcall
.tbp
->non_overridable
6402 && e
->value
.compcall
.base_object
6403 && e
->value
.compcall
.base_object
->ts
.type
== BT_DERIVED
)
6406 gfc_symbol
*derived
;
6408 /* Use the derived type of the base_object. */
6409 derived
= e
->value
.compcall
.base_object
->ts
.u
.derived
;
6412 /* If necessary, go through the inheritance chain. */
6413 while (!st
&& derived
)
6415 /* Look for the typebound procedure 'name'. */
6416 if (derived
->f2k_derived
&& derived
->f2k_derived
->tb_sym_root
)
6417 st
= gfc_find_symtree (derived
->f2k_derived
->tb_sym_root
,
6418 e
->value
.compcall
.name
);
6420 derived
= gfc_get_derived_super_type (derived
);
6423 /* Now find the specific name in the derived type namespace. */
6424 if (st
&& st
->n
.tb
&& st
->n
.tb
->u
.specific
)
6425 gfc_find_sym_tree (st
->n
.tb
->u
.specific
->name
,
6426 derived
->ns
, 1, &st
);
6434 /* Get the ultimate declared type from an expression. In addition,
6435 return the last class/derived type reference and the copy of the
6436 reference list. If check_types is set true, derived types are
6437 identified as well as class references. */
6439 get_declared_from_expr (gfc_ref
**class_ref
, gfc_ref
**new_ref
,
6440 gfc_expr
*e
, bool check_types
)
6442 gfc_symbol
*declared
;
6449 *new_ref
= gfc_copy_ref (e
->ref
);
6451 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6453 if (ref
->type
!= REF_COMPONENT
)
6456 if ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
6457 || (check_types
&& gfc_bt_struct (ref
->u
.c
.component
->ts
.type
)))
6458 && ref
->u
.c
.component
->attr
.flavor
!= FL_PROCEDURE
)
6460 declared
= ref
->u
.c
.component
->ts
.u
.derived
;
6466 if (declared
== NULL
)
6467 declared
= e
->symtree
->n
.sym
->ts
.u
.derived
;
6473 /* Given an EXPR_COMPCALL calling a GENERIC typebound procedure, figure out
6474 which of the specific bindings (if any) matches the arglist and transform
6475 the expression into a call of that binding. */
6478 resolve_typebound_generic_call (gfc_expr
* e
, const char **name
)
6480 gfc_typebound_proc
* genproc
;
6481 const char* genname
;
6483 gfc_symbol
*derived
;
6485 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
6486 genname
= e
->value
.compcall
.name
;
6487 genproc
= e
->value
.compcall
.tbp
;
6489 if (!genproc
->is_generic
)
6492 /* Try the bindings on this type and in the inheritance hierarchy. */
6493 for (; genproc
; genproc
= genproc
->overridden
)
6497 gcc_assert (genproc
->is_generic
);
6498 for (g
= genproc
->u
.generic
; g
; g
= g
->next
)
6501 gfc_actual_arglist
* args
;
6504 gcc_assert (g
->specific
);
6506 if (g
->specific
->error
)
6509 target
= g
->specific
->u
.specific
->n
.sym
;
6511 /* Get the right arglist by handling PASS/NOPASS. */
6512 args
= gfc_copy_actual_arglist (e
->value
.compcall
.actual
);
6513 if (!g
->specific
->nopass
)
6516 po
= extract_compcall_passed_object (e
);
6519 gfc_free_actual_arglist (args
);
6523 gcc_assert (g
->specific
->pass_arg_num
> 0);
6524 gcc_assert (!g
->specific
->error
);
6525 args
= update_arglist_pass (args
, po
, g
->specific
->pass_arg_num
,
6526 g
->specific
->pass_arg
);
6528 resolve_actual_arglist (args
, target
->attr
.proc
,
6529 is_external_proc (target
)
6530 && gfc_sym_get_dummy_args (target
) == NULL
);
6532 /* Check if this arglist matches the formal. */
6533 matches
= gfc_arglist_matches_symbol (&args
, target
);
6535 /* Clean up and break out of the loop if we've found it. */
6536 gfc_free_actual_arglist (args
);
6539 e
->value
.compcall
.tbp
= g
->specific
;
6540 genname
= g
->specific_st
->name
;
6541 /* Pass along the name for CLASS methods, where the vtab
6542 procedure pointer component has to be referenced. */
6550 /* Nothing matching found! */
6551 gfc_error ("Found no matching specific binding for the call to the GENERIC"
6552 " %qs at %L", genname
, &e
->where
);
6556 /* Make sure that we have the right specific instance for the name. */
6557 derived
= get_declared_from_expr (NULL
, NULL
, e
, true);
6559 st
= gfc_find_typebound_proc (derived
, NULL
, genname
, true, &e
->where
);
6561 e
->value
.compcall
.tbp
= st
->n
.tb
;
6567 /* Resolve a call to a type-bound subroutine. */
6570 resolve_typebound_call (gfc_code
* c
, const char **name
, bool *overridable
)
6572 gfc_actual_arglist
* newactual
;
6573 gfc_symtree
* target
;
6575 /* Check that's really a SUBROUTINE. */
6576 if (!c
->expr1
->value
.compcall
.tbp
->subroutine
)
6578 if (!c
->expr1
->value
.compcall
.tbp
->is_generic
6579 && c
->expr1
->value
.compcall
.tbp
->u
.specific
6580 && c
->expr1
->value
.compcall
.tbp
->u
.specific
->n
.sym
6581 && c
->expr1
->value
.compcall
.tbp
->u
.specific
->n
.sym
->attr
.subroutine
)
6582 c
->expr1
->value
.compcall
.tbp
->subroutine
= 1;
6585 gfc_error ("%qs at %L should be a SUBROUTINE",
6586 c
->expr1
->value
.compcall
.name
, &c
->loc
);
6591 if (!check_typebound_baseobject (c
->expr1
))
6594 /* Pass along the name for CLASS methods, where the vtab
6595 procedure pointer component has to be referenced. */
6597 *name
= c
->expr1
->value
.compcall
.name
;
6599 if (!resolve_typebound_generic_call (c
->expr1
, name
))
6602 /* Pass along the NON_OVERRIDABLE attribute of the specific TBP. */
6604 *overridable
= !c
->expr1
->value
.compcall
.tbp
->non_overridable
;
6606 /* Transform into an ordinary EXEC_CALL for now. */
6608 if (!resolve_typebound_static (c
->expr1
, &target
, &newactual
))
6611 c
->ext
.actual
= newactual
;
6612 c
->symtree
= target
;
6613 c
->op
= (c
->expr1
->value
.compcall
.assign
? EXEC_ASSIGN_CALL
: EXEC_CALL
);
6615 gcc_assert (!c
->expr1
->ref
&& !c
->expr1
->value
.compcall
.actual
);
6617 gfc_free_expr (c
->expr1
);
6618 c
->expr1
= gfc_get_expr ();
6619 c
->expr1
->expr_type
= EXPR_FUNCTION
;
6620 c
->expr1
->symtree
= target
;
6621 c
->expr1
->where
= c
->loc
;
6623 return resolve_call (c
);
6627 /* Resolve a component-call expression. */
6629 resolve_compcall (gfc_expr
* e
, const char **name
)
6631 gfc_actual_arglist
* newactual
;
6632 gfc_symtree
* target
;
6634 /* Check that's really a FUNCTION. */
6635 if (!e
->value
.compcall
.tbp
->function
)
6637 gfc_error ("%qs at %L should be a FUNCTION",
6638 e
->value
.compcall
.name
, &e
->where
);
6643 /* These must not be assign-calls! */
6644 gcc_assert (!e
->value
.compcall
.assign
);
6646 if (!check_typebound_baseobject (e
))
6649 /* Pass along the name for CLASS methods, where the vtab
6650 procedure pointer component has to be referenced. */
6652 *name
= e
->value
.compcall
.name
;
6654 if (!resolve_typebound_generic_call (e
, name
))
6656 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
6658 /* Take the rank from the function's symbol. */
6659 if (e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
)
6660 e
->rank
= e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
->rank
;
6662 /* For now, we simply transform it into an EXPR_FUNCTION call with the same
6663 arglist to the TBP's binding target. */
6665 if (!resolve_typebound_static (e
, &target
, &newactual
))
6668 e
->value
.function
.actual
= newactual
;
6669 e
->value
.function
.name
= NULL
;
6670 e
->value
.function
.esym
= target
->n
.sym
;
6671 e
->value
.function
.isym
= NULL
;
6672 e
->symtree
= target
;
6673 e
->ts
= target
->n
.sym
->ts
;
6674 e
->expr_type
= EXPR_FUNCTION
;
6676 /* Resolution is not necessary if this is a class subroutine; this
6677 function only has to identify the specific proc. Resolution of
6678 the call will be done next in resolve_typebound_call. */
6679 return gfc_resolve_expr (e
);
6683 static bool resolve_fl_derived (gfc_symbol
*sym
);
6686 /* Resolve a typebound function, or 'method'. First separate all
6687 the non-CLASS references by calling resolve_compcall directly. */
6690 resolve_typebound_function (gfc_expr
* e
)
6692 gfc_symbol
*declared
;
6704 /* Deal with typebound operators for CLASS objects. */
6705 expr
= e
->value
.compcall
.base_object
;
6706 overridable
= !e
->value
.compcall
.tbp
->non_overridable
;
6707 if (expr
&& expr
->ts
.type
== BT_CLASS
&& e
->value
.compcall
.name
)
6709 /* Since the typebound operators are generic, we have to ensure
6710 that any delays in resolution are corrected and that the vtab
6713 declared
= ts
.u
.derived
;
6714 c
= gfc_find_component (declared
, "_vptr", true, true, NULL
);
6715 if (c
->ts
.u
.derived
== NULL
)
6716 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
6718 if (!resolve_compcall (e
, &name
))
6721 /* Use the generic name if it is there. */
6722 name
= name
? name
: e
->value
.function
.esym
->name
;
6723 e
->symtree
= expr
->symtree
;
6724 e
->ref
= gfc_copy_ref (expr
->ref
);
6725 get_declared_from_expr (&class_ref
, NULL
, e
, false);
6727 /* Trim away the extraneous references that emerge from nested
6728 use of interface.c (extend_expr). */
6729 if (class_ref
&& class_ref
->next
)
6731 gfc_free_ref_list (class_ref
->next
);
6732 class_ref
->next
= NULL
;
6734 else if (e
->ref
&& !class_ref
&& expr
->ts
.type
!= BT_CLASS
)
6736 gfc_free_ref_list (e
->ref
);
6740 gfc_add_vptr_component (e
);
6741 gfc_add_component_ref (e
, name
);
6742 e
->value
.function
.esym
= NULL
;
6743 if (expr
->expr_type
!= EXPR_VARIABLE
)
6744 e
->base_expr
= expr
;
6749 return resolve_compcall (e
, NULL
);
6751 if (!gfc_resolve_ref (e
))
6754 /* Get the CLASS declared type. */
6755 declared
= get_declared_from_expr (&class_ref
, &new_ref
, e
, true);
6757 if (!resolve_fl_derived (declared
))
6760 /* Weed out cases of the ultimate component being a derived type. */
6761 if ((class_ref
&& gfc_bt_struct (class_ref
->u
.c
.component
->ts
.type
))
6762 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
6764 gfc_free_ref_list (new_ref
);
6765 return resolve_compcall (e
, NULL
);
6768 c
= gfc_find_component (declared
, "_data", true, true, NULL
);
6770 /* Treat the call as if it is a typebound procedure, in order to roll
6771 out the correct name for the specific function. */
6772 if (!resolve_compcall (e
, &name
))
6774 gfc_free_ref_list (new_ref
);
6781 /* Convert the expression to a procedure pointer component call. */
6782 e
->value
.function
.esym
= NULL
;
6788 /* '_vptr' points to the vtab, which contains the procedure pointers. */
6789 gfc_add_vptr_component (e
);
6790 gfc_add_component_ref (e
, name
);
6792 /* Recover the typespec for the expression. This is really only
6793 necessary for generic procedures, where the additional call
6794 to gfc_add_component_ref seems to throw the collection of the
6795 correct typespec. */
6799 gfc_free_ref_list (new_ref
);
6804 /* Resolve a typebound subroutine, or 'method'. First separate all
6805 the non-CLASS references by calling resolve_typebound_call
6809 resolve_typebound_subroutine (gfc_code
*code
)
6811 gfc_symbol
*declared
;
6821 st
= code
->expr1
->symtree
;
6823 /* Deal with typebound operators for CLASS objects. */
6824 expr
= code
->expr1
->value
.compcall
.base_object
;
6825 overridable
= !code
->expr1
->value
.compcall
.tbp
->non_overridable
;
6826 if (expr
&& expr
->ts
.type
== BT_CLASS
&& code
->expr1
->value
.compcall
.name
)
6828 /* If the base_object is not a variable, the corresponding actual
6829 argument expression must be stored in e->base_expression so
6830 that the corresponding tree temporary can be used as the base
6831 object in gfc_conv_procedure_call. */
6832 if (expr
->expr_type
!= EXPR_VARIABLE
)
6834 gfc_actual_arglist
*args
;
6836 args
= code
->expr1
->value
.function
.actual
;
6837 for (; args
; args
= args
->next
)
6838 if (expr
== args
->expr
)
6842 /* Since the typebound operators are generic, we have to ensure
6843 that any delays in resolution are corrected and that the vtab
6845 declared
= expr
->ts
.u
.derived
;
6846 c
= gfc_find_component (declared
, "_vptr", true, true, NULL
);
6847 if (c
->ts
.u
.derived
== NULL
)
6848 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
6850 if (!resolve_typebound_call (code
, &name
, NULL
))
6853 /* Use the generic name if it is there. */
6854 name
= name
? name
: code
->expr1
->value
.function
.esym
->name
;
6855 code
->expr1
->symtree
= expr
->symtree
;
6856 code
->expr1
->ref
= gfc_copy_ref (expr
->ref
);
6858 /* Trim away the extraneous references that emerge from nested
6859 use of interface.c (extend_expr). */
6860 get_declared_from_expr (&class_ref
, NULL
, code
->expr1
, false);
6861 if (class_ref
&& class_ref
->next
)
6863 gfc_free_ref_list (class_ref
->next
);
6864 class_ref
->next
= NULL
;
6866 else if (code
->expr1
->ref
&& !class_ref
)
6868 gfc_free_ref_list (code
->expr1
->ref
);
6869 code
->expr1
->ref
= NULL
;
6872 /* Now use the procedure in the vtable. */
6873 gfc_add_vptr_component (code
->expr1
);
6874 gfc_add_component_ref (code
->expr1
, name
);
6875 code
->expr1
->value
.function
.esym
= NULL
;
6876 if (expr
->expr_type
!= EXPR_VARIABLE
)
6877 code
->expr1
->base_expr
= expr
;
6882 return resolve_typebound_call (code
, NULL
, NULL
);
6884 if (!gfc_resolve_ref (code
->expr1
))
6887 /* Get the CLASS declared type. */
6888 get_declared_from_expr (&class_ref
, &new_ref
, code
->expr1
, true);
6890 /* Weed out cases of the ultimate component being a derived type. */
6891 if ((class_ref
&& gfc_bt_struct (class_ref
->u
.c
.component
->ts
.type
))
6892 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
6894 gfc_free_ref_list (new_ref
);
6895 return resolve_typebound_call (code
, NULL
, NULL
);
6898 if (!resolve_typebound_call (code
, &name
, &overridable
))
6900 gfc_free_ref_list (new_ref
);
6903 ts
= code
->expr1
->ts
;
6907 /* Convert the expression to a procedure pointer component call. */
6908 code
->expr1
->value
.function
.esym
= NULL
;
6909 code
->expr1
->symtree
= st
;
6912 code
->expr1
->ref
= new_ref
;
6914 /* '_vptr' points to the vtab, which contains the procedure pointers. */
6915 gfc_add_vptr_component (code
->expr1
);
6916 gfc_add_component_ref (code
->expr1
, name
);
6918 /* Recover the typespec for the expression. This is really only
6919 necessary for generic procedures, where the additional call
6920 to gfc_add_component_ref seems to throw the collection of the
6921 correct typespec. */
6922 code
->expr1
->ts
= ts
;
6925 gfc_free_ref_list (new_ref
);
6931 /* Resolve a CALL to a Procedure Pointer Component (Subroutine). */
6934 resolve_ppc_call (gfc_code
* c
)
6936 gfc_component
*comp
;
6938 comp
= gfc_get_proc_ptr_comp (c
->expr1
);
6939 gcc_assert (comp
!= NULL
);
6941 c
->resolved_sym
= c
->expr1
->symtree
->n
.sym
;
6942 c
->expr1
->expr_type
= EXPR_VARIABLE
;
6944 if (!comp
->attr
.subroutine
)
6945 gfc_add_subroutine (&comp
->attr
, comp
->name
, &c
->expr1
->where
);
6947 if (!gfc_resolve_ref (c
->expr1
))
6950 if (!update_ppc_arglist (c
->expr1
))
6953 c
->ext
.actual
= c
->expr1
->value
.compcall
.actual
;
6955 if (!resolve_actual_arglist (c
->ext
.actual
, comp
->attr
.proc
,
6956 !(comp
->ts
.interface
6957 && comp
->ts
.interface
->formal
)))
6960 if (!pure_subroutine (comp
->ts
.interface
, comp
->name
, &c
->expr1
->where
))
6963 gfc_ppc_use (comp
, &c
->expr1
->value
.compcall
.actual
, &c
->expr1
->where
);
6969 /* Resolve a Function Call to a Procedure Pointer Component (Function). */
6972 resolve_expr_ppc (gfc_expr
* e
)
6974 gfc_component
*comp
;
6976 comp
= gfc_get_proc_ptr_comp (e
);
6977 gcc_assert (comp
!= NULL
);
6979 /* Convert to EXPR_FUNCTION. */
6980 e
->expr_type
= EXPR_FUNCTION
;
6981 e
->value
.function
.isym
= NULL
;
6982 e
->value
.function
.actual
= e
->value
.compcall
.actual
;
6984 if (comp
->as
!= NULL
)
6985 e
->rank
= comp
->as
->rank
;
6987 if (!comp
->attr
.function
)
6988 gfc_add_function (&comp
->attr
, comp
->name
, &e
->where
);
6990 if (!gfc_resolve_ref (e
))
6993 if (!resolve_actual_arglist (e
->value
.function
.actual
, comp
->attr
.proc
,
6994 !(comp
->ts
.interface
6995 && comp
->ts
.interface
->formal
)))
6998 if (!update_ppc_arglist (e
))
7001 if (!check_pure_function(e
))
7004 gfc_ppc_use (comp
, &e
->value
.compcall
.actual
, &e
->where
);
7011 gfc_is_expandable_expr (gfc_expr
*e
)
7013 gfc_constructor
*con
;
7015 if (e
->expr_type
== EXPR_ARRAY
)
7017 /* Traverse the constructor looking for variables that are flavor
7018 parameter. Parameters must be expanded since they are fully used at
7020 con
= gfc_constructor_first (e
->value
.constructor
);
7021 for (; con
; con
= gfc_constructor_next (con
))
7023 if (con
->expr
->expr_type
== EXPR_VARIABLE
7024 && con
->expr
->symtree
7025 && (con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
7026 || con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_VARIABLE
))
7028 if (con
->expr
->expr_type
== EXPR_ARRAY
7029 && gfc_is_expandable_expr (con
->expr
))
7038 /* Sometimes variables in specification expressions of the result
7039 of module procedures in submodules wind up not being the 'real'
7040 dummy. Find this, if possible, in the namespace of the first
7044 fixup_unique_dummy (gfc_expr
*e
)
7046 gfc_symtree
*st
= NULL
;
7047 gfc_symbol
*s
= NULL
;
7049 if (e
->symtree
->n
.sym
->ns
->proc_name
7050 && e
->symtree
->n
.sym
->ns
->proc_name
->formal
)
7051 s
= e
->symtree
->n
.sym
->ns
->proc_name
->formal
->sym
;
7054 st
= gfc_find_symtree (s
->ns
->sym_root
, e
->symtree
->n
.sym
->name
);
7057 && st
->n
.sym
!= NULL
7058 && st
->n
.sym
->attr
.dummy
)
7062 /* Resolve an expression. That is, make sure that types of operands agree
7063 with their operators, intrinsic operators are converted to function calls
7064 for overloaded types and unresolved function references are resolved. */
7067 gfc_resolve_expr (gfc_expr
*e
)
7070 bool inquiry_save
, actual_arg_save
, first_actual_arg_save
;
7072 if (e
== NULL
|| e
->do_not_resolve_again
)
7075 /* inquiry_argument only applies to variables. */
7076 inquiry_save
= inquiry_argument
;
7077 actual_arg_save
= actual_arg
;
7078 first_actual_arg_save
= first_actual_arg
;
7080 if (e
->expr_type
!= EXPR_VARIABLE
)
7082 inquiry_argument
= false;
7084 first_actual_arg
= false;
7086 else if (e
->symtree
!= NULL
7087 && *e
->symtree
->name
== '@'
7088 && e
->symtree
->n
.sym
->attr
.dummy
)
7090 /* Deal with submodule specification expressions that are not
7091 found to be referenced in module.c(read_cleanup). */
7092 fixup_unique_dummy (e
);
7095 switch (e
->expr_type
)
7098 t
= resolve_operator (e
);
7104 if (check_host_association (e
))
7105 t
= resolve_function (e
);
7107 t
= resolve_variable (e
);
7109 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.u
.cl
== NULL
&& e
->ref
7110 && e
->ref
->type
!= REF_SUBSTRING
)
7111 gfc_resolve_substring_charlen (e
);
7116 t
= resolve_typebound_function (e
);
7119 case EXPR_SUBSTRING
:
7120 t
= gfc_resolve_ref (e
);
7129 t
= resolve_expr_ppc (e
);
7134 if (!gfc_resolve_ref (e
))
7137 t
= gfc_resolve_array_constructor (e
);
7138 /* Also try to expand a constructor. */
7141 gfc_expression_rank (e
);
7142 if (gfc_is_constant_expr (e
) || gfc_is_expandable_expr (e
))
7143 gfc_expand_constructor (e
, false);
7146 /* This provides the opportunity for the length of constructors with
7147 character valued function elements to propagate the string length
7148 to the expression. */
7149 if (t
&& e
->ts
.type
== BT_CHARACTER
)
7151 /* For efficiency, we call gfc_expand_constructor for BT_CHARACTER
7152 here rather then add a duplicate test for it above. */
7153 gfc_expand_constructor (e
, false);
7154 t
= gfc_resolve_character_array_constructor (e
);
7159 case EXPR_STRUCTURE
:
7160 t
= gfc_resolve_ref (e
);
7164 t
= resolve_structure_cons (e
, 0);
7168 t
= gfc_simplify_expr (e
, 0);
7172 gfc_internal_error ("gfc_resolve_expr(): Bad expression type");
7175 if (e
->ts
.type
== BT_CHARACTER
&& t
&& !e
->ts
.u
.cl
)
7178 inquiry_argument
= inquiry_save
;
7179 actual_arg
= actual_arg_save
;
7180 first_actual_arg
= first_actual_arg_save
;
7182 /* For some reason, resolving these expressions a second time mangles
7183 the typespec of the expression itself. */
7184 if (t
&& e
->expr_type
== EXPR_VARIABLE
7185 && e
->symtree
->n
.sym
->attr
.select_rank_temporary
7186 && UNLIMITED_POLY (e
->symtree
->n
.sym
))
7187 e
->do_not_resolve_again
= 1;
7193 /* Resolve an expression from an iterator. They must be scalar and have
7194 INTEGER or (optionally) REAL type. */
7197 gfc_resolve_iterator_expr (gfc_expr
*expr
, bool real_ok
,
7198 const char *name_msgid
)
7200 if (!gfc_resolve_expr (expr
))
7203 if (expr
->rank
!= 0)
7205 gfc_error ("%s at %L must be a scalar", _(name_msgid
), &expr
->where
);
7209 if (expr
->ts
.type
!= BT_INTEGER
)
7211 if (expr
->ts
.type
== BT_REAL
)
7214 return gfc_notify_std (GFC_STD_F95_DEL
,
7215 "%s at %L must be integer",
7216 _(name_msgid
), &expr
->where
);
7219 gfc_error ("%s at %L must be INTEGER", _(name_msgid
),
7226 gfc_error ("%s at %L must be INTEGER", _(name_msgid
), &expr
->where
);
7234 /* Resolve the expressions in an iterator structure. If REAL_OK is
7235 false allow only INTEGER type iterators, otherwise allow REAL types.
7236 Set own_scope to true for ac-implied-do and data-implied-do as those
7237 have a separate scope such that, e.g., a INTENT(IN) doesn't apply. */
7240 gfc_resolve_iterator (gfc_iterator
*iter
, bool real_ok
, bool own_scope
)
7242 if (!gfc_resolve_iterator_expr (iter
->var
, real_ok
, "Loop variable"))
7245 if (!gfc_check_vardef_context (iter
->var
, false, false, own_scope
,
7246 _("iterator variable")))
7249 if (!gfc_resolve_iterator_expr (iter
->start
, real_ok
,
7250 "Start expression in DO loop"))
7253 if (!gfc_resolve_iterator_expr (iter
->end
, real_ok
,
7254 "End expression in DO loop"))
7257 if (!gfc_resolve_iterator_expr (iter
->step
, real_ok
,
7258 "Step expression in DO loop"))
7261 /* Convert start, end, and step to the same type as var. */
7262 if (iter
->start
->ts
.kind
!= iter
->var
->ts
.kind
7263 || iter
->start
->ts
.type
!= iter
->var
->ts
.type
)
7264 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 1);
7266 if (iter
->end
->ts
.kind
!= iter
->var
->ts
.kind
7267 || iter
->end
->ts
.type
!= iter
->var
->ts
.type
)
7268 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 1);
7270 if (iter
->step
->ts
.kind
!= iter
->var
->ts
.kind
7271 || iter
->step
->ts
.type
!= iter
->var
->ts
.type
)
7272 gfc_convert_type (iter
->step
, &iter
->var
->ts
, 1);
7274 if (iter
->step
->expr_type
== EXPR_CONSTANT
)
7276 if ((iter
->step
->ts
.type
== BT_INTEGER
7277 && mpz_cmp_ui (iter
->step
->value
.integer
, 0) == 0)
7278 || (iter
->step
->ts
.type
== BT_REAL
7279 && mpfr_sgn (iter
->step
->value
.real
) == 0))
7281 gfc_error ("Step expression in DO loop at %L cannot be zero",
7282 &iter
->step
->where
);
7287 if (iter
->start
->expr_type
== EXPR_CONSTANT
7288 && iter
->end
->expr_type
== EXPR_CONSTANT
7289 && iter
->step
->expr_type
== EXPR_CONSTANT
)
7292 if (iter
->start
->ts
.type
== BT_INTEGER
)
7294 sgn
= mpz_cmp_ui (iter
->step
->value
.integer
, 0);
7295 cmp
= mpz_cmp (iter
->end
->value
.integer
, iter
->start
->value
.integer
);
7299 sgn
= mpfr_sgn (iter
->step
->value
.real
);
7300 cmp
= mpfr_cmp (iter
->end
->value
.real
, iter
->start
->value
.real
);
7302 if (warn_zerotrip
&& ((sgn
> 0 && cmp
< 0) || (sgn
< 0 && cmp
> 0)))
7303 gfc_warning (OPT_Wzerotrip
,
7304 "DO loop at %L will be executed zero times",
7305 &iter
->step
->where
);
7308 if (iter
->end
->expr_type
== EXPR_CONSTANT
7309 && iter
->end
->ts
.type
== BT_INTEGER
7310 && iter
->step
->expr_type
== EXPR_CONSTANT
7311 && iter
->step
->ts
.type
== BT_INTEGER
7312 && (mpz_cmp_si (iter
->step
->value
.integer
, -1L) == 0
7313 || mpz_cmp_si (iter
->step
->value
.integer
, 1L) == 0))
7315 bool is_step_positive
= mpz_cmp_ui (iter
->step
->value
.integer
, 1) == 0;
7316 int k
= gfc_validate_kind (BT_INTEGER
, iter
->end
->ts
.kind
, false);
7318 if (is_step_positive
7319 && mpz_cmp (iter
->end
->value
.integer
, gfc_integer_kinds
[k
].huge
) == 0)
7320 gfc_warning (OPT_Wundefined_do_loop
,
7321 "DO loop at %L is undefined as it overflows",
7322 &iter
->step
->where
);
7323 else if (!is_step_positive
7324 && mpz_cmp (iter
->end
->value
.integer
,
7325 gfc_integer_kinds
[k
].min_int
) == 0)
7326 gfc_warning (OPT_Wundefined_do_loop
,
7327 "DO loop at %L is undefined as it underflows",
7328 &iter
->step
->where
);
7335 /* Traversal function for find_forall_index. f == 2 signals that
7336 that variable itself is not to be checked - only the references. */
7339 forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int *f
)
7341 if (expr
->expr_type
!= EXPR_VARIABLE
)
7344 /* A scalar assignment */
7345 if (!expr
->ref
|| *f
== 1)
7347 if (expr
->symtree
->n
.sym
== sym
)
7359 /* Check whether the FORALL index appears in the expression or not.
7360 Returns true if SYM is found in EXPR. */
7363 find_forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int f
)
7365 if (gfc_traverse_expr (expr
, sym
, forall_index
, f
))
7372 /* Resolve a list of FORALL iterators. The FORALL index-name is constrained
7373 to be a scalar INTEGER variable. The subscripts and stride are scalar
7374 INTEGERs, and if stride is a constant it must be nonzero.
7375 Furthermore "A subscript or stride in a forall-triplet-spec shall
7376 not contain a reference to any index-name in the
7377 forall-triplet-spec-list in which it appears." (7.5.4.1) */
7380 resolve_forall_iterators (gfc_forall_iterator
*it
)
7382 gfc_forall_iterator
*iter
, *iter2
;
7384 for (iter
= it
; iter
; iter
= iter
->next
)
7386 if (gfc_resolve_expr (iter
->var
)
7387 && (iter
->var
->ts
.type
!= BT_INTEGER
|| iter
->var
->rank
!= 0))
7388 gfc_error ("FORALL index-name at %L must be a scalar INTEGER",
7391 if (gfc_resolve_expr (iter
->start
)
7392 && (iter
->start
->ts
.type
!= BT_INTEGER
|| iter
->start
->rank
!= 0))
7393 gfc_error ("FORALL start expression at %L must be a scalar INTEGER",
7394 &iter
->start
->where
);
7395 if (iter
->var
->ts
.kind
!= iter
->start
->ts
.kind
)
7396 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 1);
7398 if (gfc_resolve_expr (iter
->end
)
7399 && (iter
->end
->ts
.type
!= BT_INTEGER
|| iter
->end
->rank
!= 0))
7400 gfc_error ("FORALL end expression at %L must be a scalar INTEGER",
7402 if (iter
->var
->ts
.kind
!= iter
->end
->ts
.kind
)
7403 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 1);
7405 if (gfc_resolve_expr (iter
->stride
))
7407 if (iter
->stride
->ts
.type
!= BT_INTEGER
|| iter
->stride
->rank
!= 0)
7408 gfc_error ("FORALL stride expression at %L must be a scalar %s",
7409 &iter
->stride
->where
, "INTEGER");
7411 if (iter
->stride
->expr_type
== EXPR_CONSTANT
7412 && mpz_cmp_ui (iter
->stride
->value
.integer
, 0) == 0)
7413 gfc_error ("FORALL stride expression at %L cannot be zero",
7414 &iter
->stride
->where
);
7416 if (iter
->var
->ts
.kind
!= iter
->stride
->ts
.kind
)
7417 gfc_convert_type (iter
->stride
, &iter
->var
->ts
, 1);
7420 for (iter
= it
; iter
; iter
= iter
->next
)
7421 for (iter2
= iter
; iter2
; iter2
= iter2
->next
)
7423 if (find_forall_index (iter2
->start
, iter
->var
->symtree
->n
.sym
, 0)
7424 || find_forall_index (iter2
->end
, iter
->var
->symtree
->n
.sym
, 0)
7425 || find_forall_index (iter2
->stride
, iter
->var
->symtree
->n
.sym
, 0))
7426 gfc_error ("FORALL index %qs may not appear in triplet "
7427 "specification at %L", iter
->var
->symtree
->name
,
7428 &iter2
->start
->where
);
7433 /* Given a pointer to a symbol that is a derived type, see if it's
7434 inaccessible, i.e. if it's defined in another module and the components are
7435 PRIVATE. The search is recursive if necessary. Returns zero if no
7436 inaccessible components are found, nonzero otherwise. */
7439 derived_inaccessible (gfc_symbol
*sym
)
7443 if (sym
->attr
.use_assoc
&& sym
->attr
.private_comp
)
7446 for (c
= sym
->components
; c
; c
= c
->next
)
7448 /* Prevent an infinite loop through this function. */
7449 if (c
->ts
.type
== BT_DERIVED
&& c
->attr
.pointer
7450 && sym
== c
->ts
.u
.derived
)
7453 if (c
->ts
.type
== BT_DERIVED
&& derived_inaccessible (c
->ts
.u
.derived
))
7461 /* Resolve the argument of a deallocate expression. The expression must be
7462 a pointer or a full array. */
7465 resolve_deallocate_expr (gfc_expr
*e
)
7467 symbol_attribute attr
;
7468 int allocatable
, pointer
;
7474 if (!gfc_resolve_expr (e
))
7477 if (e
->expr_type
!= EXPR_VARIABLE
)
7480 sym
= e
->symtree
->n
.sym
;
7481 unlimited
= UNLIMITED_POLY(sym
);
7483 if (sym
->ts
.type
== BT_CLASS
)
7485 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
7486 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
7490 allocatable
= sym
->attr
.allocatable
;
7491 pointer
= sym
->attr
.pointer
;
7493 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
7498 if (ref
->u
.ar
.type
!= AR_FULL
7499 && !(ref
->u
.ar
.type
== AR_ELEMENT
&& ref
->u
.ar
.as
->rank
== 0
7500 && ref
->u
.ar
.codimen
&& gfc_ref_this_image (ref
)))
7505 c
= ref
->u
.c
.component
;
7506 if (c
->ts
.type
== BT_CLASS
)
7508 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
7509 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
7513 allocatable
= c
->attr
.allocatable
;
7514 pointer
= c
->attr
.pointer
;
7525 attr
= gfc_expr_attr (e
);
7527 if (allocatable
== 0 && attr
.pointer
== 0 && !unlimited
)
7530 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
7536 if (gfc_is_coindexed (e
))
7538 gfc_error ("Coindexed allocatable object at %L", &e
->where
);
7543 && !gfc_check_vardef_context (e
, true, true, false,
7544 _("DEALLOCATE object")))
7546 if (!gfc_check_vardef_context (e
, false, true, false,
7547 _("DEALLOCATE object")))
7554 /* Returns true if the expression e contains a reference to the symbol sym. */
7556 sym_in_expr (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
7558 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
== sym
)
7565 gfc_find_sym_in_expr (gfc_symbol
*sym
, gfc_expr
*e
)
7567 return gfc_traverse_expr (e
, sym
, sym_in_expr
, 0);
7571 /* Given the expression node e for an allocatable/pointer of derived type to be
7572 allocated, get the expression node to be initialized afterwards (needed for
7573 derived types with default initializers, and derived types with allocatable
7574 components that need nullification.) */
7577 gfc_expr_to_initialize (gfc_expr
*e
)
7583 result
= gfc_copy_expr (e
);
7585 /* Change the last array reference from AR_ELEMENT to AR_FULL. */
7586 for (ref
= result
->ref
; ref
; ref
= ref
->next
)
7587 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
7589 if (ref
->u
.ar
.dimen
== 0
7590 && ref
->u
.ar
.as
&& ref
->u
.ar
.as
->corank
)
7593 ref
->u
.ar
.type
= AR_FULL
;
7595 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
7596 ref
->u
.ar
.start
[i
] = ref
->u
.ar
.end
[i
] = ref
->u
.ar
.stride
[i
] = NULL
;
7601 gfc_free_shape (&result
->shape
, result
->rank
);
7603 /* Recalculate rank, shape, etc. */
7604 gfc_resolve_expr (result
);
7609 /* If the last ref of an expression is an array ref, return a copy of the
7610 expression with that one removed. Otherwise, a copy of the original
7611 expression. This is used for allocate-expressions and pointer assignment
7612 LHS, where there may be an array specification that needs to be stripped
7613 off when using gfc_check_vardef_context. */
7616 remove_last_array_ref (gfc_expr
* e
)
7621 e2
= gfc_copy_expr (e
);
7622 for (r
= &e2
->ref
; *r
; r
= &(*r
)->next
)
7623 if ((*r
)->type
== REF_ARRAY
&& !(*r
)->next
)
7625 gfc_free_ref_list (*r
);
7634 /* Used in resolve_allocate_expr to check that a allocation-object and
7635 a source-expr are conformable. This does not catch all possible
7636 cases; in particular a runtime checking is needed. */
7639 conformable_arrays (gfc_expr
*e1
, gfc_expr
*e2
)
7642 for (tail
= e2
->ref
; tail
&& tail
->next
; tail
= tail
->next
);
7644 /* First compare rank. */
7645 if ((tail
&& (!tail
->u
.ar
.as
|| e1
->rank
!= tail
->u
.ar
.as
->rank
))
7646 || (!tail
&& e1
->rank
!= e2
->rank
))
7648 gfc_error ("Source-expr at %L must be scalar or have the "
7649 "same rank as the allocate-object at %L",
7650 &e1
->where
, &e2
->where
);
7661 for (i
= 0; i
< e1
->rank
; i
++)
7663 if (tail
->u
.ar
.start
[i
] == NULL
)
7666 if (tail
->u
.ar
.end
[i
])
7668 mpz_set (s
, tail
->u
.ar
.end
[i
]->value
.integer
);
7669 mpz_sub (s
, s
, tail
->u
.ar
.start
[i
]->value
.integer
);
7670 mpz_add_ui (s
, s
, 1);
7674 mpz_set (s
, tail
->u
.ar
.start
[i
]->value
.integer
);
7677 if (mpz_cmp (e1
->shape
[i
], s
) != 0)
7679 gfc_error ("Source-expr at %L and allocate-object at %L must "
7680 "have the same shape", &e1
->where
, &e2
->where
);
7693 /* Resolve the expression in an ALLOCATE statement, doing the additional
7694 checks to see whether the expression is OK or not. The expression must
7695 have a trailing array reference that gives the size of the array. */
7698 resolve_allocate_expr (gfc_expr
*e
, gfc_code
*code
, bool *array_alloc_wo_spec
)
7700 int i
, pointer
, allocatable
, dimension
, is_abstract
;
7704 symbol_attribute attr
;
7705 gfc_ref
*ref
, *ref2
;
7708 gfc_symbol
*sym
= NULL
;
7713 /* Mark the utmost array component as being in allocate to allow DIMEN_STAR
7714 checking of coarrays. */
7715 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
7716 if (ref
->next
== NULL
)
7719 if (ref
&& ref
->type
== REF_ARRAY
)
7720 ref
->u
.ar
.in_allocate
= true;
7722 if (!gfc_resolve_expr (e
))
7725 /* Make sure the expression is allocatable or a pointer. If it is
7726 pointer, the next-to-last reference must be a pointer. */
7730 sym
= e
->symtree
->n
.sym
;
7732 /* Check whether ultimate component is abstract and CLASS. */
7735 /* Is the allocate-object unlimited polymorphic? */
7736 unlimited
= UNLIMITED_POLY(e
);
7738 if (e
->expr_type
!= EXPR_VARIABLE
)
7741 attr
= gfc_expr_attr (e
);
7742 pointer
= attr
.pointer
;
7743 dimension
= attr
.dimension
;
7744 codimension
= attr
.codimension
;
7748 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
7750 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
7751 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
7752 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
7753 codimension
= CLASS_DATA (sym
)->attr
.codimension
;
7754 is_abstract
= CLASS_DATA (sym
)->attr
.abstract
;
7758 allocatable
= sym
->attr
.allocatable
;
7759 pointer
= sym
->attr
.pointer
;
7760 dimension
= sym
->attr
.dimension
;
7761 codimension
= sym
->attr
.codimension
;
7766 for (ref
= e
->ref
; ref
; ref2
= ref
, ref
= ref
->next
)
7771 if (ref
->u
.ar
.codimen
> 0)
7774 for (n
= ref
->u
.ar
.dimen
;
7775 n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
7776 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_THIS_IMAGE
)
7783 if (ref
->next
!= NULL
)
7791 gfc_error ("Coindexed allocatable object at %L",
7796 c
= ref
->u
.c
.component
;
7797 if (c
->ts
.type
== BT_CLASS
)
7799 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
7800 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
7801 dimension
= CLASS_DATA (c
)->attr
.dimension
;
7802 codimension
= CLASS_DATA (c
)->attr
.codimension
;
7803 is_abstract
= CLASS_DATA (c
)->attr
.abstract
;
7807 allocatable
= c
->attr
.allocatable
;
7808 pointer
= c
->attr
.pointer
;
7809 dimension
= c
->attr
.dimension
;
7810 codimension
= c
->attr
.codimension
;
7811 is_abstract
= c
->attr
.abstract
;
7824 /* Check for F08:C628. */
7825 if (allocatable
== 0 && pointer
== 0 && !unlimited
)
7827 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
7832 /* Some checks for the SOURCE tag. */
7835 /* Check F03:C631. */
7836 if (!gfc_type_compatible (&e
->ts
, &code
->expr3
->ts
))
7838 gfc_error ("Type of entity at %L is type incompatible with "
7839 "source-expr at %L", &e
->where
, &code
->expr3
->where
);
7843 /* Check F03:C632 and restriction following Note 6.18. */
7844 if (code
->expr3
->rank
> 0 && !conformable_arrays (code
->expr3
, e
))
7847 /* Check F03:C633. */
7848 if (code
->expr3
->ts
.kind
!= e
->ts
.kind
&& !unlimited
)
7850 gfc_error ("The allocate-object at %L and the source-expr at %L "
7851 "shall have the same kind type parameter",
7852 &e
->where
, &code
->expr3
->where
);
7856 /* Check F2008, C642. */
7857 if (code
->expr3
->ts
.type
== BT_DERIVED
7858 && ((codimension
&& gfc_expr_attr (code
->expr3
).lock_comp
)
7859 || (code
->expr3
->ts
.u
.derived
->from_intmod
7860 == INTMOD_ISO_FORTRAN_ENV
7861 && code
->expr3
->ts
.u
.derived
->intmod_sym_id
7862 == ISOFORTRAN_LOCK_TYPE
)))
7864 gfc_error ("The source-expr at %L shall neither be of type "
7865 "LOCK_TYPE nor have a LOCK_TYPE component if "
7866 "allocate-object at %L is a coarray",
7867 &code
->expr3
->where
, &e
->where
);
7871 /* Check TS18508, C702/C703. */
7872 if (code
->expr3
->ts
.type
== BT_DERIVED
7873 && ((codimension
&& gfc_expr_attr (code
->expr3
).event_comp
)
7874 || (code
->expr3
->ts
.u
.derived
->from_intmod
7875 == INTMOD_ISO_FORTRAN_ENV
7876 && code
->expr3
->ts
.u
.derived
->intmod_sym_id
7877 == ISOFORTRAN_EVENT_TYPE
)))
7879 gfc_error ("The source-expr at %L shall neither be of type "
7880 "EVENT_TYPE nor have a EVENT_TYPE component if "
7881 "allocate-object at %L is a coarray",
7882 &code
->expr3
->where
, &e
->where
);
7887 /* Check F08:C629. */
7888 if (is_abstract
&& code
->ext
.alloc
.ts
.type
== BT_UNKNOWN
7891 gcc_assert (e
->ts
.type
== BT_CLASS
);
7892 gfc_error ("Allocating %s of ABSTRACT base type at %L requires a "
7893 "type-spec or source-expr", sym
->name
, &e
->where
);
7897 /* Check F08:C632. */
7898 if (code
->ext
.alloc
.ts
.type
== BT_CHARACTER
&& !e
->ts
.deferred
7899 && !UNLIMITED_POLY (e
))
7903 if (!e
->ts
.u
.cl
->length
)
7906 cmp
= gfc_dep_compare_expr (e
->ts
.u
.cl
->length
,
7907 code
->ext
.alloc
.ts
.u
.cl
->length
);
7908 if (cmp
== 1 || cmp
== -1 || cmp
== -3)
7910 gfc_error ("Allocating %s at %L with type-spec requires the same "
7911 "character-length parameter as in the declaration",
7912 sym
->name
, &e
->where
);
7917 /* In the variable definition context checks, gfc_expr_attr is used
7918 on the expression. This is fooled by the array specification
7919 present in e, thus we have to eliminate that one temporarily. */
7920 e2
= remove_last_array_ref (e
);
7923 t
= gfc_check_vardef_context (e2
, true, true, false,
7924 _("ALLOCATE object"));
7926 t
= gfc_check_vardef_context (e2
, false, true, false,
7927 _("ALLOCATE object"));
7932 if (e
->ts
.type
== BT_CLASS
&& CLASS_DATA (e
)->attr
.dimension
7933 && !code
->expr3
&& code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
7935 /* For class arrays, the initialization with SOURCE is done
7936 using _copy and trans_call. It is convenient to exploit that
7937 when the allocated type is different from the declared type but
7938 no SOURCE exists by setting expr3. */
7939 code
->expr3
= gfc_default_initializer (&code
->ext
.alloc
.ts
);
7941 else if (flag_coarray
!= GFC_FCOARRAY_LIB
&& e
->ts
.type
== BT_DERIVED
7942 && e
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
7943 && e
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
7945 /* We have to zero initialize the integer variable. */
7946 code
->expr3
= gfc_get_int_expr (gfc_default_integer_kind
, &e
->where
, 0);
7949 if (e
->ts
.type
== BT_CLASS
&& !unlimited
&& !UNLIMITED_POLY (code
->expr3
))
7951 /* Make sure the vtab symbol is present when
7952 the module variables are generated. */
7953 gfc_typespec ts
= e
->ts
;
7955 ts
= code
->expr3
->ts
;
7956 else if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
7957 ts
= code
->ext
.alloc
.ts
;
7959 /* Finding the vtab also publishes the type's symbol. Therefore this
7960 statement is necessary. */
7961 gfc_find_derived_vtab (ts
.u
.derived
);
7963 else if (unlimited
&& !UNLIMITED_POLY (code
->expr3
))
7965 /* Again, make sure the vtab symbol is present when
7966 the module variables are generated. */
7967 gfc_typespec
*ts
= NULL
;
7969 ts
= &code
->expr3
->ts
;
7971 ts
= &code
->ext
.alloc
.ts
;
7975 /* Finding the vtab also publishes the type's symbol. Therefore this
7976 statement is necessary. */
7980 if (dimension
== 0 && codimension
== 0)
7983 /* Make sure the last reference node is an array specification. */
7985 if (!ref2
|| ref2
->type
!= REF_ARRAY
|| ref2
->u
.ar
.type
== AR_FULL
7986 || (dimension
&& ref2
->u
.ar
.dimen
== 0))
7991 if (!gfc_notify_std (GFC_STD_F2008
, "Array specification required "
7992 "in ALLOCATE statement at %L", &e
->where
))
7994 if (code
->expr3
->rank
!= 0)
7995 *array_alloc_wo_spec
= true;
7998 gfc_error ("Array specification or array-valued SOURCE= "
7999 "expression required in ALLOCATE statement at %L",
8006 gfc_error ("Array specification required in ALLOCATE statement "
8007 "at %L", &e
->where
);
8012 /* Make sure that the array section reference makes sense in the
8013 context of an ALLOCATE specification. */
8018 for (i
= ar
->dimen
; i
< ar
->dimen
+ ar
->codimen
; i
++)
8020 switch (ar
->dimen_type
[i
])
8022 case DIMEN_THIS_IMAGE
:
8023 gfc_error ("Coarray specification required in ALLOCATE statement "
8024 "at %L", &e
->where
);
8028 if (ar
->start
[i
] == 0 || ar
->end
[i
] == 0)
8030 /* If ar->stride[i] is NULL, we issued a previous error. */
8031 if (ar
->stride
[i
] == NULL
)
8032 gfc_error ("Bad array specification in ALLOCATE statement "
8033 "at %L", &e
->where
);
8036 else if (gfc_dep_compare_expr (ar
->start
[i
], ar
->end
[i
]) == 1)
8038 gfc_error ("Upper cobound is less than lower cobound at %L",
8039 &ar
->start
[i
]->where
);
8045 if (ar
->start
[i
]->expr_type
== EXPR_CONSTANT
)
8047 gcc_assert (ar
->start
[i
]->ts
.type
== BT_INTEGER
);
8048 if (mpz_cmp_si (ar
->start
[i
]->value
.integer
, 1) < 0)
8050 gfc_error ("Upper cobound is less than lower cobound "
8051 "of 1 at %L", &ar
->start
[i
]->where
);
8061 gfc_error ("Bad array specification in ALLOCATE statement at %L",
8067 for (i
= 0; i
< ar
->dimen
; i
++)
8069 if (ar
->type
== AR_ELEMENT
|| ar
->type
== AR_FULL
)
8072 switch (ar
->dimen_type
[i
])
8078 if (ar
->start
[i
] != NULL
8079 && ar
->end
[i
] != NULL
8080 && ar
->stride
[i
] == NULL
)
8088 case DIMEN_THIS_IMAGE
:
8089 gfc_error ("Bad array specification in ALLOCATE statement at %L",
8095 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
8097 sym
= a
->expr
->symtree
->n
.sym
;
8099 /* TODO - check derived type components. */
8100 if (gfc_bt_struct (sym
->ts
.type
) || sym
->ts
.type
== BT_CLASS
)
8103 if ((ar
->start
[i
] != NULL
8104 && gfc_find_sym_in_expr (sym
, ar
->start
[i
]))
8105 || (ar
->end
[i
] != NULL
8106 && gfc_find_sym_in_expr (sym
, ar
->end
[i
])))
8108 gfc_error ("%qs must not appear in the array specification at "
8109 "%L in the same ALLOCATE statement where it is "
8110 "itself allocated", sym
->name
, &ar
->where
);
8116 for (i
= ar
->dimen
; i
< ar
->codimen
+ ar
->dimen
; i
++)
8118 if (ar
->dimen_type
[i
] == DIMEN_ELEMENT
8119 || ar
->dimen_type
[i
] == DIMEN_RANGE
)
8121 if (i
== (ar
->dimen
+ ar
->codimen
- 1))
8123 gfc_error ("Expected '*' in coindex specification in ALLOCATE "
8124 "statement at %L", &e
->where
);
8130 if (ar
->dimen_type
[i
] == DIMEN_STAR
&& i
== (ar
->dimen
+ ar
->codimen
- 1)
8131 && ar
->stride
[i
] == NULL
)
8134 gfc_error ("Bad coarray specification in ALLOCATE statement at %L",
8148 resolve_allocate_deallocate (gfc_code
*code
, const char *fcn
)
8150 gfc_expr
*stat
, *errmsg
, *pe
, *qe
;
8151 gfc_alloc
*a
, *p
, *q
;
8154 errmsg
= code
->expr2
;
8156 /* Check the stat variable. */
8159 if (!gfc_check_vardef_context (stat
, false, false, false,
8160 _("STAT variable")))
8163 if (stat
->ts
.type
!= BT_INTEGER
8165 gfc_error ("Stat-variable at %L must be a scalar INTEGER "
8166 "variable", &stat
->where
);
8168 if (stat
->expr_type
== EXPR_CONSTANT
|| stat
->symtree
== NULL
)
8171 /* F2018:9.7.4: The stat-variable shall not be allocated or deallocated
8172 * within the ALLOCATE or DEALLOCATE statement in which it appears ...
8174 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
8175 if (p
->expr
->symtree
->n
.sym
->name
== stat
->symtree
->n
.sym
->name
)
8177 gfc_ref
*ref1
, *ref2
;
8180 for (ref1
= p
->expr
->ref
, ref2
= stat
->ref
; ref1
&& ref2
;
8181 ref1
= ref1
->next
, ref2
= ref2
->next
)
8183 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
8185 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
8194 gfc_error ("Stat-variable at %L shall not be %sd within "
8195 "the same %s statement", &stat
->where
, fcn
, fcn
);
8203 /* Check the errmsg variable. */
8207 gfc_warning (0, "ERRMSG at %L is useless without a STAT tag",
8210 if (!gfc_check_vardef_context (errmsg
, false, false, false,
8211 _("ERRMSG variable")))
8214 /* F18:R928 alloc-opt is ERRMSG = errmsg-variable
8215 F18:R930 errmsg-variable is scalar-default-char-variable
8216 F18:R906 default-char-variable is variable
8217 F18:C906 default-char-variable shall be default character. */
8218 if (errmsg
->ts
.type
!= BT_CHARACTER
8220 || errmsg
->ts
.kind
!= gfc_default_character_kind
)
8221 gfc_error ("ERRMSG variable at %L shall be a scalar default CHARACTER "
8222 "variable", &errmsg
->where
);
8224 if (errmsg
->expr_type
== EXPR_CONSTANT
|| errmsg
->symtree
== NULL
)
8227 /* F2018:9.7.5: The errmsg-variable shall not be allocated or deallocated
8228 * within the ALLOCATE or DEALLOCATE statement in which it appears ...
8230 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
8231 if (p
->expr
->symtree
->n
.sym
->name
== errmsg
->symtree
->n
.sym
->name
)
8233 gfc_ref
*ref1
, *ref2
;
8236 for (ref1
= p
->expr
->ref
, ref2
= errmsg
->ref
; ref1
&& ref2
;
8237 ref1
= ref1
->next
, ref2
= ref2
->next
)
8239 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
8241 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
8250 gfc_error ("Errmsg-variable at %L shall not be %sd within "
8251 "the same %s statement", &errmsg
->where
, fcn
, fcn
);
8259 /* Check that an allocate-object appears only once in the statement. */
8261 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
8264 for (q
= p
->next
; q
; q
= q
->next
)
8267 if (pe
->symtree
->n
.sym
->name
== qe
->symtree
->n
.sym
->name
)
8269 /* This is a potential collision. */
8270 gfc_ref
*pr
= pe
->ref
;
8271 gfc_ref
*qr
= qe
->ref
;
8273 /* Follow the references until
8274 a) They start to differ, in which case there is no error;
8275 you can deallocate a%b and a%c in a single statement
8276 b) Both of them stop, which is an error
8277 c) One of them stops, which is also an error. */
8280 if (pr
== NULL
&& qr
== NULL
)
8282 gfc_error ("Allocate-object at %L also appears at %L",
8283 &pe
->where
, &qe
->where
);
8286 else if (pr
!= NULL
&& qr
== NULL
)
8288 gfc_error ("Allocate-object at %L is subobject of"
8289 " object at %L", &pe
->where
, &qe
->where
);
8292 else if (pr
== NULL
&& qr
!= NULL
)
8294 gfc_error ("Allocate-object at %L is subobject of"
8295 " object at %L", &qe
->where
, &pe
->where
);
8298 /* Here, pr != NULL && qr != NULL */
8299 gcc_assert(pr
->type
== qr
->type
);
8300 if (pr
->type
== REF_ARRAY
)
8302 /* Handle cases like allocate(v(3)%x(3), v(2)%x(3)),
8304 gcc_assert (qr
->type
== REF_ARRAY
);
8306 if (pr
->next
&& qr
->next
)
8309 gfc_array_ref
*par
= &(pr
->u
.ar
);
8310 gfc_array_ref
*qar
= &(qr
->u
.ar
);
8312 for (i
=0; i
<par
->dimen
; i
++)
8314 if ((par
->start
[i
] != NULL
8315 || qar
->start
[i
] != NULL
)
8316 && gfc_dep_compare_expr (par
->start
[i
],
8317 qar
->start
[i
]) != 0)
8324 if (pr
->u
.c
.component
->name
!= qr
->u
.c
.component
->name
)
8337 if (strcmp (fcn
, "ALLOCATE") == 0)
8339 bool arr_alloc_wo_spec
= false;
8341 /* Resolving the expr3 in the loop over all objects to allocate would
8342 execute loop invariant code for each loop item. Therefore do it just
8344 if (code
->expr3
&& code
->expr3
->mold
8345 && code
->expr3
->ts
.type
== BT_DERIVED
)
8347 /* Default initialization via MOLD (non-polymorphic). */
8348 gfc_expr
*rhs
= gfc_default_initializer (&code
->expr3
->ts
);
8351 gfc_resolve_expr (rhs
);
8352 gfc_free_expr (code
->expr3
);
8356 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
8357 resolve_allocate_expr (a
->expr
, code
, &arr_alloc_wo_spec
);
8359 if (arr_alloc_wo_spec
&& code
->expr3
)
8361 /* Mark the allocate to have to take the array specification
8363 code
->ext
.alloc
.arr_spec_from_expr3
= 1;
8368 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
8369 resolve_deallocate_expr (a
->expr
);
8374 /************ SELECT CASE resolution subroutines ************/
8376 /* Callback function for our mergesort variant. Determines interval
8377 overlaps for CASEs. Return <0 if op1 < op2, 0 for overlap, >0 for
8378 op1 > op2. Assumes we're not dealing with the default case.
8379 We have op1 = (:L), (K:L) or (K:) and op2 = (:N), (M:N) or (M:).
8380 There are nine situations to check. */
8383 compare_cases (const gfc_case
*op1
, const gfc_case
*op2
)
8387 if (op1
->low
== NULL
) /* op1 = (:L) */
8389 /* op2 = (:N), so overlap. */
8391 /* op2 = (M:) or (M:N), L < M */
8392 if (op2
->low
!= NULL
8393 && gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
8396 else if (op1
->high
== NULL
) /* op1 = (K:) */
8398 /* op2 = (M:), so overlap. */
8400 /* op2 = (:N) or (M:N), K > N */
8401 if (op2
->high
!= NULL
8402 && gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
8405 else /* op1 = (K:L) */
8407 if (op2
->low
== NULL
) /* op2 = (:N), K > N */
8408 retval
= (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
8410 else if (op2
->high
== NULL
) /* op2 = (M:), L < M */
8411 retval
= (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
8413 else /* op2 = (M:N) */
8417 if (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
8420 else if (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
8429 /* Merge-sort a double linked case list, detecting overlap in the
8430 process. LIST is the head of the double linked case list before it
8431 is sorted. Returns the head of the sorted list if we don't see any
8432 overlap, or NULL otherwise. */
8435 check_case_overlap (gfc_case
*list
)
8437 gfc_case
*p
, *q
, *e
, *tail
;
8438 int insize
, nmerges
, psize
, qsize
, cmp
, overlap_seen
;
8440 /* If the passed list was empty, return immediately. */
8447 /* Loop unconditionally. The only exit from this loop is a return
8448 statement, when we've finished sorting the case list. */
8455 /* Count the number of merges we do in this pass. */
8458 /* Loop while there exists a merge to be done. */
8463 /* Count this merge. */
8466 /* Cut the list in two pieces by stepping INSIZE places
8467 forward in the list, starting from P. */
8470 for (i
= 0; i
< insize
; i
++)
8479 /* Now we have two lists. Merge them! */
8480 while (psize
> 0 || (qsize
> 0 && q
!= NULL
))
8482 /* See from which the next case to merge comes from. */
8485 /* P is empty so the next case must come from Q. */
8490 else if (qsize
== 0 || q
== NULL
)
8499 cmp
= compare_cases (p
, q
);
8502 /* The whole case range for P is less than the
8510 /* The whole case range for Q is greater than
8511 the case range for P. */
8518 /* The cases overlap, or they are the same
8519 element in the list. Either way, we must
8520 issue an error and get the next case from P. */
8521 /* FIXME: Sort P and Q by line number. */
8522 gfc_error ("CASE label at %L overlaps with CASE "
8523 "label at %L", &p
->where
, &q
->where
);
8531 /* Add the next element to the merged list. */
8540 /* P has now stepped INSIZE places along, and so has Q. So
8541 they're the same. */
8546 /* If we have done only one merge or none at all, we've
8547 finished sorting the cases. */
8556 /* Otherwise repeat, merging lists twice the size. */
8562 /* Check to see if an expression is suitable for use in a CASE statement.
8563 Makes sure that all case expressions are scalar constants of the same
8564 type. Return false if anything is wrong. */
8567 validate_case_label_expr (gfc_expr
*e
, gfc_expr
*case_expr
)
8569 if (e
== NULL
) return true;
8571 if (e
->ts
.type
!= case_expr
->ts
.type
)
8573 gfc_error ("Expression in CASE statement at %L must be of type %s",
8574 &e
->where
, gfc_basic_typename (case_expr
->ts
.type
));
8578 /* C805 (R808) For a given case-construct, each case-value shall be of
8579 the same type as case-expr. For character type, length differences
8580 are allowed, but the kind type parameters shall be the same. */
8582 if (case_expr
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= case_expr
->ts
.kind
)
8584 gfc_error ("Expression in CASE statement at %L must be of kind %d",
8585 &e
->where
, case_expr
->ts
.kind
);
8589 /* Convert the case value kind to that of case expression kind,
8592 if (e
->ts
.kind
!= case_expr
->ts
.kind
)
8593 gfc_convert_type_warn (e
, &case_expr
->ts
, 2, 0);
8597 gfc_error ("Expression in CASE statement at %L must be scalar",
8606 /* Given a completely parsed select statement, we:
8608 - Validate all expressions and code within the SELECT.
8609 - Make sure that the selection expression is not of the wrong type.
8610 - Make sure that no case ranges overlap.
8611 - Eliminate unreachable cases and unreachable code resulting from
8612 removing case labels.
8614 The standard does allow unreachable cases, e.g. CASE (5:3). But
8615 they are a hassle for code generation, and to prevent that, we just
8616 cut them out here. This is not necessary for overlapping cases
8617 because they are illegal and we never even try to generate code.
8619 We have the additional caveat that a SELECT construct could have
8620 been a computed GOTO in the source code. Fortunately we can fairly
8621 easily work around that here: The case_expr for a "real" SELECT CASE
8622 is in code->expr1, but for a computed GOTO it is in code->expr2. All
8623 we have to do is make sure that the case_expr is a scalar integer
8627 resolve_select (gfc_code
*code
, bool select_type
)
8630 gfc_expr
*case_expr
;
8631 gfc_case
*cp
, *default_case
, *tail
, *head
;
8632 int seen_unreachable
;
8638 if (code
->expr1
== NULL
)
8640 /* This was actually a computed GOTO statement. */
8641 case_expr
= code
->expr2
;
8642 if (case_expr
->ts
.type
!= BT_INTEGER
|| case_expr
->rank
!= 0)
8643 gfc_error ("Selection expression in computed GOTO statement "
8644 "at %L must be a scalar integer expression",
8647 /* Further checking is not necessary because this SELECT was built
8648 by the compiler, so it should always be OK. Just move the
8649 case_expr from expr2 to expr so that we can handle computed
8650 GOTOs as normal SELECTs from here on. */
8651 code
->expr1
= code
->expr2
;
8656 case_expr
= code
->expr1
;
8657 type
= case_expr
->ts
.type
;
8660 if (type
!= BT_LOGICAL
&& type
!= BT_INTEGER
&& type
!= BT_CHARACTER
)
8662 gfc_error ("Argument of SELECT statement at %L cannot be %s",
8663 &case_expr
->where
, gfc_typename (case_expr
));
8665 /* Punt. Going on here just produce more garbage error messages. */
8670 if (!select_type
&& case_expr
->rank
!= 0)
8672 gfc_error ("Argument of SELECT statement at %L must be a scalar "
8673 "expression", &case_expr
->where
);
8679 /* Raise a warning if an INTEGER case value exceeds the range of
8680 the case-expr. Later, all expressions will be promoted to the
8681 largest kind of all case-labels. */
8683 if (type
== BT_INTEGER
)
8684 for (body
= code
->block
; body
; body
= body
->block
)
8685 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
8688 && gfc_check_integer_range (cp
->low
->value
.integer
,
8689 case_expr
->ts
.kind
) != ARITH_OK
)
8690 gfc_warning (0, "Expression in CASE statement at %L is "
8691 "not in the range of %s", &cp
->low
->where
,
8692 gfc_typename (case_expr
));
8695 && cp
->low
!= cp
->high
8696 && gfc_check_integer_range (cp
->high
->value
.integer
,
8697 case_expr
->ts
.kind
) != ARITH_OK
)
8698 gfc_warning (0, "Expression in CASE statement at %L is "
8699 "not in the range of %s", &cp
->high
->where
,
8700 gfc_typename (case_expr
));
8703 /* PR 19168 has a long discussion concerning a mismatch of the kinds
8704 of the SELECT CASE expression and its CASE values. Walk the lists
8705 of case values, and if we find a mismatch, promote case_expr to
8706 the appropriate kind. */
8708 if (type
== BT_LOGICAL
|| type
== BT_INTEGER
)
8710 for (body
= code
->block
; body
; body
= body
->block
)
8712 /* Walk the case label list. */
8713 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
8715 /* Intercept the DEFAULT case. It does not have a kind. */
8716 if (cp
->low
== NULL
&& cp
->high
== NULL
)
8719 /* Unreachable case ranges are discarded, so ignore. */
8720 if (cp
->low
!= NULL
&& cp
->high
!= NULL
8721 && cp
->low
!= cp
->high
8722 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
8726 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->low
))
8727 gfc_convert_type_warn (case_expr
, &cp
->low
->ts
, 2, 0);
8729 if (cp
->high
!= NULL
8730 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->high
))
8731 gfc_convert_type_warn (case_expr
, &cp
->high
->ts
, 2, 0);
8736 /* Assume there is no DEFAULT case. */
8737 default_case
= NULL
;
8742 for (body
= code
->block
; body
; body
= body
->block
)
8744 /* Assume the CASE list is OK, and all CASE labels can be matched. */
8746 seen_unreachable
= 0;
8748 /* Walk the case label list, making sure that all case labels
8750 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
8752 /* Count the number of cases in the whole construct. */
8755 /* Intercept the DEFAULT case. */
8756 if (cp
->low
== NULL
&& cp
->high
== NULL
)
8758 if (default_case
!= NULL
)
8760 gfc_error ("The DEFAULT CASE at %L cannot be followed "
8761 "by a second DEFAULT CASE at %L",
8762 &default_case
->where
, &cp
->where
);
8773 /* Deal with single value cases and case ranges. Errors are
8774 issued from the validation function. */
8775 if (!validate_case_label_expr (cp
->low
, case_expr
)
8776 || !validate_case_label_expr (cp
->high
, case_expr
))
8782 if (type
== BT_LOGICAL
8783 && ((cp
->low
== NULL
|| cp
->high
== NULL
)
8784 || cp
->low
!= cp
->high
))
8786 gfc_error ("Logical range in CASE statement at %L is not "
8787 "allowed", &cp
->low
->where
);
8792 if (type
== BT_LOGICAL
&& cp
->low
->expr_type
== EXPR_CONSTANT
)
8795 value
= cp
->low
->value
.logical
== 0 ? 2 : 1;
8796 if (value
& seen_logical
)
8798 gfc_error ("Constant logical value in CASE statement "
8799 "is repeated at %L",
8804 seen_logical
|= value
;
8807 if (cp
->low
!= NULL
&& cp
->high
!= NULL
8808 && cp
->low
!= cp
->high
8809 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
8811 if (warn_surprising
)
8812 gfc_warning (OPT_Wsurprising
,
8813 "Range specification at %L can never be matched",
8816 cp
->unreachable
= 1;
8817 seen_unreachable
= 1;
8821 /* If the case range can be matched, it can also overlap with
8822 other cases. To make sure it does not, we put it in a
8823 double linked list here. We sort that with a merge sort
8824 later on to detect any overlapping cases. */
8828 head
->right
= head
->left
= NULL
;
8833 tail
->right
->left
= tail
;
8840 /* It there was a failure in the previous case label, give up
8841 for this case label list. Continue with the next block. */
8845 /* See if any case labels that are unreachable have been seen.
8846 If so, we eliminate them. This is a bit of a kludge because
8847 the case lists for a single case statement (label) is a
8848 single forward linked lists. */
8849 if (seen_unreachable
)
8851 /* Advance until the first case in the list is reachable. */
8852 while (body
->ext
.block
.case_list
!= NULL
8853 && body
->ext
.block
.case_list
->unreachable
)
8855 gfc_case
*n
= body
->ext
.block
.case_list
;
8856 body
->ext
.block
.case_list
= body
->ext
.block
.case_list
->next
;
8858 gfc_free_case_list (n
);
8861 /* Strip all other unreachable cases. */
8862 if (body
->ext
.block
.case_list
)
8864 for (cp
= body
->ext
.block
.case_list
; cp
&& cp
->next
; cp
= cp
->next
)
8866 if (cp
->next
->unreachable
)
8868 gfc_case
*n
= cp
->next
;
8869 cp
->next
= cp
->next
->next
;
8871 gfc_free_case_list (n
);
8878 /* See if there were overlapping cases. If the check returns NULL,
8879 there was overlap. In that case we don't do anything. If head
8880 is non-NULL, we prepend the DEFAULT case. The sorted list can
8881 then used during code generation for SELECT CASE constructs with
8882 a case expression of a CHARACTER type. */
8885 head
= check_case_overlap (head
);
8887 /* Prepend the default_case if it is there. */
8888 if (head
!= NULL
&& default_case
)
8890 default_case
->left
= NULL
;
8891 default_case
->right
= head
;
8892 head
->left
= default_case
;
8896 /* Eliminate dead blocks that may be the result if we've seen
8897 unreachable case labels for a block. */
8898 for (body
= code
; body
&& body
->block
; body
= body
->block
)
8900 if (body
->block
->ext
.block
.case_list
== NULL
)
8902 /* Cut the unreachable block from the code chain. */
8903 gfc_code
*c
= body
->block
;
8904 body
->block
= c
->block
;
8906 /* Kill the dead block, but not the blocks below it. */
8908 gfc_free_statements (c
);
8912 /* More than two cases is legal but insane for logical selects.
8913 Issue a warning for it. */
8914 if (warn_surprising
&& type
== BT_LOGICAL
&& ncases
> 2)
8915 gfc_warning (OPT_Wsurprising
,
8916 "Logical SELECT CASE block at %L has more that two cases",
8921 /* Check if a derived type is extensible. */
8924 gfc_type_is_extensible (gfc_symbol
*sym
)
8926 return !(sym
->attr
.is_bind_c
|| sym
->attr
.sequence
8927 || (sym
->attr
.is_class
8928 && sym
->components
->ts
.u
.derived
->attr
.unlimited_polymorphic
));
8933 resolve_types (gfc_namespace
*ns
);
8935 /* Resolve an associate-name: Resolve target and ensure the type-spec is
8936 correct as well as possibly the array-spec. */
8939 resolve_assoc_var (gfc_symbol
* sym
, bool resolve_target
)
8943 gcc_assert (sym
->assoc
);
8944 gcc_assert (sym
->attr
.flavor
== FL_VARIABLE
);
8946 /* If this is for SELECT TYPE, the target may not yet be set. In that
8947 case, return. Resolution will be called later manually again when
8949 target
= sym
->assoc
->target
;
8952 gcc_assert (!sym
->assoc
->dangling
);
8954 if (resolve_target
&& !gfc_resolve_expr (target
))
8957 /* For variable targets, we get some attributes from the target. */
8958 if (target
->expr_type
== EXPR_VARIABLE
)
8960 gfc_symbol
*tsym
, *dsym
;
8962 gcc_assert (target
->symtree
);
8963 tsym
= target
->symtree
->n
.sym
;
8965 if (gfc_expr_attr (target
).proc_pointer
)
8967 gfc_error ("Associating entity %qs at %L is a procedure pointer",
8968 tsym
->name
, &target
->where
);
8972 if (tsym
->attr
.flavor
== FL_PROCEDURE
&& tsym
->generic
8973 && (dsym
= gfc_find_dt_in_generic (tsym
)) != NULL
8974 && dsym
->attr
.flavor
== FL_DERIVED
)
8976 gfc_error ("Derived type %qs cannot be used as a variable at %L",
8977 tsym
->name
, &target
->where
);
8981 if (tsym
->attr
.flavor
== FL_PROCEDURE
)
8983 bool is_error
= true;
8984 if (tsym
->attr
.function
&& tsym
->result
== tsym
)
8985 for (gfc_namespace
*ns
= sym
->ns
; ns
; ns
= ns
->parent
)
8986 if (tsym
== ns
->proc_name
)
8993 gfc_error ("Associating entity %qs at %L is a procedure name",
8994 tsym
->name
, &target
->where
);
8999 sym
->attr
.asynchronous
= tsym
->attr
.asynchronous
;
9000 sym
->attr
.volatile_
= tsym
->attr
.volatile_
;
9002 sym
->attr
.target
= tsym
->attr
.target
9003 || gfc_expr_attr (target
).pointer
;
9004 if (is_subref_array (target
))
9005 sym
->attr
.subref_array_pointer
= 1;
9007 else if (target
->ts
.type
== BT_PROCEDURE
)
9009 gfc_error ("Associating selector-expression at %L yields a procedure",
9014 if (target
->expr_type
== EXPR_NULL
)
9016 gfc_error ("Selector at %L cannot be NULL()", &target
->where
);
9019 else if (target
->ts
.type
== BT_UNKNOWN
)
9021 gfc_error ("Selector at %L has no type", &target
->where
);
9025 /* Get type if this was not already set. Note that it can be
9026 some other type than the target in case this is a SELECT TYPE
9027 selector! So we must not update when the type is already there. */
9028 if (sym
->ts
.type
== BT_UNKNOWN
)
9029 sym
->ts
= target
->ts
;
9031 gcc_assert (sym
->ts
.type
!= BT_UNKNOWN
);
9033 /* See if this is a valid association-to-variable. */
9034 sym
->assoc
->variable
= (target
->expr_type
== EXPR_VARIABLE
9035 && !gfc_has_vector_subscript (target
));
9037 /* Finally resolve if this is an array or not. */
9038 if (sym
->attr
.dimension
&& target
->rank
== 0)
9040 /* primary.c makes the assumption that a reference to an associate
9041 name followed by a left parenthesis is an array reference. */
9042 if (sym
->ts
.type
!= BT_CHARACTER
)
9043 gfc_error ("Associate-name %qs at %L is used as array",
9044 sym
->name
, &sym
->declared_at
);
9045 sym
->attr
.dimension
= 0;
9050 /* We cannot deal with class selectors that need temporaries. */
9051 if (target
->ts
.type
== BT_CLASS
9052 && gfc_ref_needs_temporary_p (target
->ref
))
9054 gfc_error ("CLASS selector at %L needs a temporary which is not "
9055 "yet implemented", &target
->where
);
9059 if (target
->ts
.type
== BT_CLASS
)
9060 gfc_fix_class_refs (target
);
9062 if (target
->rank
!= 0 && !sym
->attr
.select_rank_temporary
)
9065 /* The rank may be incorrectly guessed at parsing, therefore make sure
9066 it is corrected now. */
9067 if (sym
->ts
.type
!= BT_CLASS
&& (!sym
->as
|| sym
->assoc
->rankguessed
))
9070 sym
->as
= gfc_get_array_spec ();
9072 as
->rank
= target
->rank
;
9073 as
->type
= AS_DEFERRED
;
9074 as
->corank
= gfc_get_corank (target
);
9075 sym
->attr
.dimension
= 1;
9076 if (as
->corank
!= 0)
9077 sym
->attr
.codimension
= 1;
9079 else if (sym
->ts
.type
== BT_CLASS
9081 && (!CLASS_DATA (sym
)->as
|| sym
->assoc
->rankguessed
))
9083 if (!CLASS_DATA (sym
)->as
)
9084 CLASS_DATA (sym
)->as
= gfc_get_array_spec ();
9085 as
= CLASS_DATA (sym
)->as
;
9086 as
->rank
= target
->rank
;
9087 as
->type
= AS_DEFERRED
;
9088 as
->corank
= gfc_get_corank (target
);
9089 CLASS_DATA (sym
)->attr
.dimension
= 1;
9090 if (as
->corank
!= 0)
9091 CLASS_DATA (sym
)->attr
.codimension
= 1;
9094 else if (!sym
->attr
.select_rank_temporary
)
9096 /* target's rank is 0, but the type of the sym is still array valued,
9097 which has to be corrected. */
9098 if (sym
->ts
.type
== BT_CLASS
&& sym
->ts
.u
.derived
9099 && CLASS_DATA (sym
) && CLASS_DATA (sym
)->as
)
9102 symbol_attribute attr
;
9103 /* The associated variable's type is still the array type
9104 correct this now. */
9105 gfc_typespec
*ts
= &target
->ts
;
9108 for (ref
= target
->ref
; ref
!= NULL
; ref
= ref
->next
)
9113 ts
= &ref
->u
.c
.component
->ts
;
9116 if (ts
->type
== BT_CLASS
)
9117 ts
= &ts
->u
.derived
->components
->ts
;
9123 /* Create a scalar instance of the current class type. Because the
9124 rank of a class array goes into its name, the type has to be
9125 rebuild. The alternative of (re-)setting just the attributes
9126 and as in the current type, destroys the type also in other
9130 sym
->ts
.type
= BT_CLASS
;
9131 attr
= CLASS_DATA (sym
) ? CLASS_DATA (sym
)->attr
: sym
->attr
;
9133 attr
.associate_var
= 1;
9134 attr
.dimension
= attr
.codimension
= 0;
9135 attr
.class_pointer
= 1;
9136 if (!gfc_build_class_symbol (&sym
->ts
, &attr
, &as
))
9138 /* Make sure the _vptr is set. */
9139 c
= gfc_find_component (sym
->ts
.u
.derived
, "_vptr", true, true, NULL
);
9140 if (c
->ts
.u
.derived
== NULL
)
9141 c
->ts
.u
.derived
= gfc_find_derived_vtab (sym
->ts
.u
.derived
);
9142 CLASS_DATA (sym
)->attr
.pointer
= 1;
9143 CLASS_DATA (sym
)->attr
.class_pointer
= 1;
9144 gfc_set_sym_referenced (sym
->ts
.u
.derived
);
9145 gfc_commit_symbol (sym
->ts
.u
.derived
);
9146 /* _vptr now has the _vtab in it, change it to the _vtype. */
9147 if (c
->ts
.u
.derived
->attr
.vtab
)
9148 c
->ts
.u
.derived
= c
->ts
.u
.derived
->ts
.u
.derived
;
9149 c
->ts
.u
.derived
->ns
->types_resolved
= 0;
9150 resolve_types (c
->ts
.u
.derived
->ns
);
9154 /* Mark this as an associate variable. */
9155 sym
->attr
.associate_var
= 1;
9157 /* Fix up the type-spec for CHARACTER types. */
9158 if (sym
->ts
.type
== BT_CHARACTER
&& !sym
->attr
.select_type_temporary
)
9161 sym
->ts
.u
.cl
= target
->ts
.u
.cl
;
9163 if (sym
->ts
.deferred
&& target
->expr_type
== EXPR_VARIABLE
9164 && target
->symtree
->n
.sym
->attr
.dummy
9165 && sym
->ts
.u
.cl
== target
->ts
.u
.cl
)
9167 sym
->ts
.u
.cl
= gfc_new_charlen (sym
->ns
, NULL
);
9168 sym
->ts
.deferred
= 1;
9171 if (!sym
->ts
.u
.cl
->length
9172 && !sym
->ts
.deferred
9173 && target
->expr_type
== EXPR_CONSTANT
)
9175 sym
->ts
.u
.cl
->length
=
9176 gfc_get_int_expr (gfc_charlen_int_kind
, NULL
,
9177 target
->value
.character
.length
);
9179 else if ((!sym
->ts
.u
.cl
->length
9180 || sym
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
9181 && target
->expr_type
!= EXPR_VARIABLE
)
9183 sym
->ts
.u
.cl
= gfc_new_charlen (sym
->ns
, NULL
);
9184 sym
->ts
.deferred
= 1;
9186 /* This is reset in trans-stmt.c after the assignment
9187 of the target expression to the associate name. */
9188 sym
->attr
.allocatable
= 1;
9192 /* If the target is a good class object, so is the associate variable. */
9193 if (sym
->ts
.type
== BT_CLASS
&& gfc_expr_attr (target
).class_ok
)
9194 sym
->attr
.class_ok
= 1;
9198 /* Ensure that SELECT TYPE expressions have the correct rank and a full
9199 array reference, where necessary. The symbols are artificial and so
9200 the dimension attribute and arrayspec can also be set. In addition,
9201 sometimes the expr1 arrives as BT_DERIVED, when the symbol is BT_CLASS.
9202 This is corrected here as well.*/
9205 fixup_array_ref (gfc_expr
**expr1
, gfc_expr
*expr2
,
9206 int rank
, gfc_ref
*ref
)
9208 gfc_ref
*nref
= (*expr1
)->ref
;
9209 gfc_symbol
*sym1
= (*expr1
)->symtree
->n
.sym
;
9210 gfc_symbol
*sym2
= expr2
? expr2
->symtree
->n
.sym
: NULL
;
9211 (*expr1
)->rank
= rank
;
9212 if (sym1
->ts
.type
== BT_CLASS
)
9214 if ((*expr1
)->ts
.type
!= BT_CLASS
)
9215 (*expr1
)->ts
= sym1
->ts
;
9217 CLASS_DATA (sym1
)->attr
.dimension
= 1;
9218 if (CLASS_DATA (sym1
)->as
== NULL
&& sym2
)
9219 CLASS_DATA (sym1
)->as
9220 = gfc_copy_array_spec (CLASS_DATA (sym2
)->as
);
9224 sym1
->attr
.dimension
= 1;
9225 if (sym1
->as
== NULL
&& sym2
)
9226 sym1
->as
= gfc_copy_array_spec (sym2
->as
);
9229 for (; nref
; nref
= nref
->next
)
9230 if (nref
->next
== NULL
)
9233 if (ref
&& nref
&& nref
->type
!= REF_ARRAY
)
9234 nref
->next
= gfc_copy_ref (ref
);
9235 else if (ref
&& !nref
)
9236 (*expr1
)->ref
= gfc_copy_ref (ref
);
9241 build_loc_call (gfc_expr
*sym_expr
)
9244 loc_call
= gfc_get_expr ();
9245 loc_call
->expr_type
= EXPR_FUNCTION
;
9246 gfc_get_sym_tree ("_loc", gfc_current_ns
, &loc_call
->symtree
, false);
9247 loc_call
->symtree
->n
.sym
->attr
.flavor
= FL_PROCEDURE
;
9248 loc_call
->symtree
->n
.sym
->attr
.intrinsic
= 1;
9249 loc_call
->symtree
->n
.sym
->result
= loc_call
->symtree
->n
.sym
;
9250 gfc_commit_symbol (loc_call
->symtree
->n
.sym
);
9251 loc_call
->ts
.type
= BT_INTEGER
;
9252 loc_call
->ts
.kind
= gfc_index_integer_kind
;
9253 loc_call
->value
.function
.isym
= gfc_intrinsic_function_by_id (GFC_ISYM_LOC
);
9254 loc_call
->value
.function
.actual
= gfc_get_actual_arglist ();
9255 loc_call
->value
.function
.actual
->expr
= sym_expr
;
9256 loc_call
->where
= sym_expr
->where
;
9260 /* Resolve a SELECT TYPE statement. */
9263 resolve_select_type (gfc_code
*code
, gfc_namespace
*old_ns
)
9265 gfc_symbol
*selector_type
;
9266 gfc_code
*body
, *new_st
, *if_st
, *tail
;
9267 gfc_code
*class_is
= NULL
, *default_case
= NULL
;
9270 char name
[GFC_MAX_SYMBOL_LEN
+ 12 + 1];
9274 gfc_ref
* ref
= NULL
;
9275 gfc_expr
*selector_expr
= NULL
;
9277 ns
= code
->ext
.block
.ns
;
9280 /* Check for F03:C813. */
9281 if (code
->expr1
->ts
.type
!= BT_CLASS
9282 && !(code
->expr2
&& code
->expr2
->ts
.type
== BT_CLASS
))
9284 gfc_error ("Selector shall be polymorphic in SELECT TYPE statement "
9285 "at %L", &code
->loc
);
9289 if (!code
->expr1
->symtree
->n
.sym
->attr
.class_ok
)
9294 gfc_ref
*ref2
= NULL
;
9295 for (ref
= code
->expr2
->ref
; ref
!= NULL
; ref
= ref
->next
)
9296 if (ref
->type
== REF_COMPONENT
9297 && ref
->u
.c
.component
->ts
.type
== BT_CLASS
)
9302 if (code
->expr1
->symtree
->n
.sym
->attr
.untyped
)
9303 code
->expr1
->symtree
->n
.sym
->ts
= ref2
->u
.c
.component
->ts
;
9304 selector_type
= CLASS_DATA (ref2
->u
.c
.component
)->ts
.u
.derived
;
9308 if (code
->expr1
->symtree
->n
.sym
->attr
.untyped
)
9309 code
->expr1
->symtree
->n
.sym
->ts
= code
->expr2
->ts
;
9310 selector_type
= CLASS_DATA (code
->expr2
)
9311 ? CLASS_DATA (code
->expr2
)->ts
.u
.derived
: code
->expr2
->ts
.u
.derived
;
9314 if (code
->expr2
->rank
9315 && code
->expr1
->ts
.type
== BT_CLASS
9316 && CLASS_DATA (code
->expr1
)->as
)
9317 CLASS_DATA (code
->expr1
)->as
->rank
= code
->expr2
->rank
;
9319 /* F2008: C803 The selector expression must not be coindexed. */
9320 if (gfc_is_coindexed (code
->expr2
))
9322 gfc_error ("Selector at %L must not be coindexed",
9323 &code
->expr2
->where
);
9330 selector_type
= CLASS_DATA (code
->expr1
)->ts
.u
.derived
;
9332 if (gfc_is_coindexed (code
->expr1
))
9334 gfc_error ("Selector at %L must not be coindexed",
9335 &code
->expr1
->where
);
9340 /* Loop over TYPE IS / CLASS IS cases. */
9341 for (body
= code
->block
; body
; body
= body
->block
)
9343 c
= body
->ext
.block
.case_list
;
9347 /* Check for repeated cases. */
9348 for (tail
= code
->block
; tail
; tail
= tail
->block
)
9350 gfc_case
*d
= tail
->ext
.block
.case_list
;
9354 if (c
->ts
.type
== d
->ts
.type
9355 && ((c
->ts
.type
== BT_DERIVED
9356 && c
->ts
.u
.derived
&& d
->ts
.u
.derived
9357 && !strcmp (c
->ts
.u
.derived
->name
,
9358 d
->ts
.u
.derived
->name
))
9359 || c
->ts
.type
== BT_UNKNOWN
9360 || (!(c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
9361 && c
->ts
.kind
== d
->ts
.kind
)))
9363 gfc_error ("TYPE IS at %L overlaps with TYPE IS at %L",
9364 &c
->where
, &d
->where
);
9370 /* Check F03:C815. */
9371 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
9372 && !selector_type
->attr
.unlimited_polymorphic
9373 && !gfc_type_is_extensible (c
->ts
.u
.derived
))
9375 gfc_error ("Derived type %qs at %L must be extensible",
9376 c
->ts
.u
.derived
->name
, &c
->where
);
9381 /* Check F03:C816. */
9382 if (c
->ts
.type
!= BT_UNKNOWN
&& !selector_type
->attr
.unlimited_polymorphic
9383 && ((c
->ts
.type
!= BT_DERIVED
&& c
->ts
.type
!= BT_CLASS
)
9384 || !gfc_type_is_extension_of (selector_type
, c
->ts
.u
.derived
)))
9386 if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
9387 gfc_error ("Derived type %qs at %L must be an extension of %qs",
9388 c
->ts
.u
.derived
->name
, &c
->where
, selector_type
->name
);
9390 gfc_error ("Unexpected intrinsic type %qs at %L",
9391 gfc_basic_typename (c
->ts
.type
), &c
->where
);
9396 /* Check F03:C814. */
9397 if (c
->ts
.type
== BT_CHARACTER
9398 && (c
->ts
.u
.cl
->length
!= NULL
|| c
->ts
.deferred
))
9400 gfc_error ("The type-spec at %L shall specify that each length "
9401 "type parameter is assumed", &c
->where
);
9406 /* Intercept the DEFAULT case. */
9407 if (c
->ts
.type
== BT_UNKNOWN
)
9409 /* Check F03:C818. */
9412 gfc_error ("The DEFAULT CASE at %L cannot be followed "
9413 "by a second DEFAULT CASE at %L",
9414 &default_case
->ext
.block
.case_list
->where
, &c
->where
);
9419 default_case
= body
;
9426 /* Transform SELECT TYPE statement to BLOCK and associate selector to
9427 target if present. If there are any EXIT statements referring to the
9428 SELECT TYPE construct, this is no problem because the gfc_code
9429 reference stays the same and EXIT is equally possible from the BLOCK
9430 it is changed to. */
9431 code
->op
= EXEC_BLOCK
;
9434 gfc_association_list
* assoc
;
9436 assoc
= gfc_get_association_list ();
9437 assoc
->st
= code
->expr1
->symtree
;
9438 assoc
->target
= gfc_copy_expr (code
->expr2
);
9439 assoc
->target
->where
= code
->expr2
->where
;
9440 /* assoc->variable will be set by resolve_assoc_var. */
9442 code
->ext
.block
.assoc
= assoc
;
9443 code
->expr1
->symtree
->n
.sym
->assoc
= assoc
;
9445 resolve_assoc_var (code
->expr1
->symtree
->n
.sym
, false);
9448 code
->ext
.block
.assoc
= NULL
;
9450 /* Ensure that the selector rank and arrayspec are available to
9451 correct expressions in which they might be missing. */
9452 if (code
->expr2
&& code
->expr2
->rank
)
9454 rank
= code
->expr2
->rank
;
9455 for (ref
= code
->expr2
->ref
; ref
; ref
= ref
->next
)
9456 if (ref
->next
== NULL
)
9458 if (ref
&& ref
->type
== REF_ARRAY
)
9459 ref
= gfc_copy_ref (ref
);
9461 /* Fixup expr1 if necessary. */
9463 fixup_array_ref (&code
->expr1
, code
->expr2
, rank
, ref
);
9465 else if (code
->expr1
->rank
)
9467 rank
= code
->expr1
->rank
;
9468 for (ref
= code
->expr1
->ref
; ref
; ref
= ref
->next
)
9469 if (ref
->next
== NULL
)
9471 if (ref
&& ref
->type
== REF_ARRAY
)
9472 ref
= gfc_copy_ref (ref
);
9475 /* Add EXEC_SELECT to switch on type. */
9476 new_st
= gfc_get_code (code
->op
);
9477 new_st
->expr1
= code
->expr1
;
9478 new_st
->expr2
= code
->expr2
;
9479 new_st
->block
= code
->block
;
9480 code
->expr1
= code
->expr2
= NULL
;
9485 ns
->code
->next
= new_st
;
9487 code
->op
= EXEC_SELECT_TYPE
;
9489 /* Use the intrinsic LOC function to generate an integer expression
9490 for the vtable of the selector. Note that the rank of the selector
9491 expression has to be set to zero. */
9492 gfc_add_vptr_component (code
->expr1
);
9493 code
->expr1
->rank
= 0;
9494 code
->expr1
= build_loc_call (code
->expr1
);
9495 selector_expr
= code
->expr1
->value
.function
.actual
->expr
;
9497 /* Loop over TYPE IS / CLASS IS cases. */
9498 for (body
= code
->block
; body
; body
= body
->block
)
9502 c
= body
->ext
.block
.case_list
;
9504 /* Generate an index integer expression for address of the
9505 TYPE/CLASS vtable and store it in c->low. The hash expression
9506 is stored in c->high and is used to resolve intrinsic cases. */
9507 if (c
->ts
.type
!= BT_UNKNOWN
)
9509 if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
9511 vtab
= gfc_find_derived_vtab (c
->ts
.u
.derived
);
9513 c
->high
= gfc_get_int_expr (gfc_integer_4_kind
, NULL
,
9514 c
->ts
.u
.derived
->hash_value
);
9518 vtab
= gfc_find_vtab (&c
->ts
);
9519 gcc_assert (vtab
&& CLASS_DATA (vtab
)->initializer
);
9520 e
= CLASS_DATA (vtab
)->initializer
;
9521 c
->high
= gfc_copy_expr (e
);
9522 if (c
->high
->ts
.kind
!= gfc_integer_4_kind
)
9525 ts
.kind
= gfc_integer_4_kind
;
9526 ts
.type
= BT_INTEGER
;
9527 gfc_convert_type_warn (c
->high
, &ts
, 2, 0);
9531 e
= gfc_lval_expr_from_sym (vtab
);
9532 c
->low
= build_loc_call (e
);
9537 /* Associate temporary to selector. This should only be done
9538 when this case is actually true, so build a new ASSOCIATE
9539 that does precisely this here (instead of using the
9542 if (c
->ts
.type
== BT_CLASS
)
9543 sprintf (name
, "__tmp_class_%s", c
->ts
.u
.derived
->name
);
9544 else if (c
->ts
.type
== BT_DERIVED
)
9545 sprintf (name
, "__tmp_type_%s", c
->ts
.u
.derived
->name
);
9546 else if (c
->ts
.type
== BT_CHARACTER
)
9548 HOST_WIDE_INT charlen
= 0;
9549 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
9550 && c
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9551 charlen
= gfc_mpz_get_hwi (c
->ts
.u
.cl
->length
->value
.integer
);
9552 snprintf (name
, sizeof (name
),
9553 "__tmp_%s_" HOST_WIDE_INT_PRINT_DEC
"_%d",
9554 gfc_basic_typename (c
->ts
.type
), charlen
, c
->ts
.kind
);
9557 sprintf (name
, "__tmp_%s_%d", gfc_basic_typename (c
->ts
.type
),
9560 st
= gfc_find_symtree (ns
->sym_root
, name
);
9561 gcc_assert (st
->n
.sym
->assoc
);
9562 st
->n
.sym
->assoc
->target
= gfc_get_variable_expr (selector_expr
->symtree
);
9563 st
->n
.sym
->assoc
->target
->where
= selector_expr
->where
;
9564 if (c
->ts
.type
!= BT_CLASS
&& c
->ts
.type
!= BT_UNKNOWN
)
9566 gfc_add_data_component (st
->n
.sym
->assoc
->target
);
9567 /* Fixup the target expression if necessary. */
9569 fixup_array_ref (&st
->n
.sym
->assoc
->target
, NULL
, rank
, ref
);
9572 new_st
= gfc_get_code (EXEC_BLOCK
);
9573 new_st
->ext
.block
.ns
= gfc_build_block_ns (ns
);
9574 new_st
->ext
.block
.ns
->code
= body
->next
;
9575 body
->next
= new_st
;
9577 /* Chain in the new list only if it is marked as dangling. Otherwise
9578 there is a CASE label overlap and this is already used. Just ignore,
9579 the error is diagnosed elsewhere. */
9580 if (st
->n
.sym
->assoc
->dangling
)
9582 new_st
->ext
.block
.assoc
= st
->n
.sym
->assoc
;
9583 st
->n
.sym
->assoc
->dangling
= 0;
9586 resolve_assoc_var (st
->n
.sym
, false);
9589 /* Take out CLASS IS cases for separate treatment. */
9591 while (body
&& body
->block
)
9593 if (body
->block
->ext
.block
.case_list
->ts
.type
== BT_CLASS
)
9595 /* Add to class_is list. */
9596 if (class_is
== NULL
)
9598 class_is
= body
->block
;
9603 for (tail
= class_is
; tail
->block
; tail
= tail
->block
) ;
9604 tail
->block
= body
->block
;
9607 /* Remove from EXEC_SELECT list. */
9608 body
->block
= body
->block
->block
;
9621 /* Add a default case to hold the CLASS IS cases. */
9622 for (tail
= code
; tail
->block
; tail
= tail
->block
) ;
9623 tail
->block
= gfc_get_code (EXEC_SELECT_TYPE
);
9625 tail
->ext
.block
.case_list
= gfc_get_case ();
9626 tail
->ext
.block
.case_list
->ts
.type
= BT_UNKNOWN
;
9628 default_case
= tail
;
9631 /* More than one CLASS IS block? */
9632 if (class_is
->block
)
9636 /* Sort CLASS IS blocks by extension level. */
9640 for (c1
= &class_is
; (*c1
) && (*c1
)->block
; c1
= &((*c1
)->block
))
9643 /* F03:C817 (check for doubles). */
9644 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->hash_value
9645 == c2
->ext
.block
.case_list
->ts
.u
.derived
->hash_value
)
9647 gfc_error ("Double CLASS IS block in SELECT TYPE "
9649 &c2
->ext
.block
.case_list
->where
);
9652 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
9653 < c2
->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
)
9656 (*c1
)->block
= c2
->block
;
9666 /* Generate IF chain. */
9667 if_st
= gfc_get_code (EXEC_IF
);
9669 for (body
= class_is
; body
; body
= body
->block
)
9671 new_st
->block
= gfc_get_code (EXEC_IF
);
9672 new_st
= new_st
->block
;
9673 /* Set up IF condition: Call _gfortran_is_extension_of. */
9674 new_st
->expr1
= gfc_get_expr ();
9675 new_st
->expr1
->expr_type
= EXPR_FUNCTION
;
9676 new_st
->expr1
->ts
.type
= BT_LOGICAL
;
9677 new_st
->expr1
->ts
.kind
= 4;
9678 new_st
->expr1
->value
.function
.name
= gfc_get_string (PREFIX ("is_extension_of"));
9679 new_st
->expr1
->value
.function
.isym
= XCNEW (gfc_intrinsic_sym
);
9680 new_st
->expr1
->value
.function
.isym
->id
= GFC_ISYM_EXTENDS_TYPE_OF
;
9681 /* Set up arguments. */
9682 new_st
->expr1
->value
.function
.actual
= gfc_get_actual_arglist ();
9683 new_st
->expr1
->value
.function
.actual
->expr
= gfc_get_variable_expr (selector_expr
->symtree
);
9684 new_st
->expr1
->value
.function
.actual
->expr
->where
= code
->loc
;
9685 new_st
->expr1
->where
= code
->loc
;
9686 gfc_add_vptr_component (new_st
->expr1
->value
.function
.actual
->expr
);
9687 vtab
= gfc_find_derived_vtab (body
->ext
.block
.case_list
->ts
.u
.derived
);
9688 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
9689 new_st
->expr1
->value
.function
.actual
->next
= gfc_get_actual_arglist ();
9690 new_st
->expr1
->value
.function
.actual
->next
->expr
= gfc_get_variable_expr (st
);
9691 new_st
->expr1
->value
.function
.actual
->next
->expr
->where
= code
->loc
;
9692 /* Set up types in formal arg list. */
9693 new_st
->expr1
->value
.function
.isym
->formal
= XCNEW (gfc_intrinsic_arg
);
9694 new_st
->expr1
->value
.function
.isym
->formal
->ts
= new_st
->expr1
->value
.function
.actual
->expr
->ts
;
9695 new_st
->expr1
->value
.function
.isym
->formal
->next
= XCNEW (gfc_intrinsic_arg
);
9696 new_st
->expr1
->value
.function
.isym
->formal
->next
->ts
= new_st
->expr1
->value
.function
.actual
->next
->expr
->ts
;
9698 new_st
->next
= body
->next
;
9700 if (default_case
->next
)
9702 new_st
->block
= gfc_get_code (EXEC_IF
);
9703 new_st
= new_st
->block
;
9704 new_st
->next
= default_case
->next
;
9707 /* Replace CLASS DEFAULT code by the IF chain. */
9708 default_case
->next
= if_st
;
9711 /* Resolve the internal code. This cannot be done earlier because
9712 it requires that the sym->assoc of selectors is set already. */
9713 gfc_current_ns
= ns
;
9714 gfc_resolve_blocks (code
->block
, gfc_current_ns
);
9715 gfc_current_ns
= old_ns
;
9722 /* Resolve a SELECT RANK statement. */
9725 resolve_select_rank (gfc_code
*code
, gfc_namespace
*old_ns
)
9728 gfc_code
*body
, *new_st
, *tail
;
9730 char tname
[GFC_MAX_SYMBOL_LEN
+ 7];
9731 char name
[2 * GFC_MAX_SYMBOL_LEN
];
9733 gfc_expr
*selector_expr
= NULL
;
9735 HOST_WIDE_INT charlen
= 0;
9737 ns
= code
->ext
.block
.ns
;
9740 code
->op
= EXEC_BLOCK
;
9743 gfc_association_list
* assoc
;
9745 assoc
= gfc_get_association_list ();
9746 assoc
->st
= code
->expr1
->symtree
;
9747 assoc
->target
= gfc_copy_expr (code
->expr2
);
9748 assoc
->target
->where
= code
->expr2
->where
;
9749 /* assoc->variable will be set by resolve_assoc_var. */
9751 code
->ext
.block
.assoc
= assoc
;
9752 code
->expr1
->symtree
->n
.sym
->assoc
= assoc
;
9754 resolve_assoc_var (code
->expr1
->symtree
->n
.sym
, false);
9757 code
->ext
.block
.assoc
= NULL
;
9759 /* Loop over RANK cases. Note that returning on the errors causes a
9760 cascade of further errors because the case blocks do not compile
9762 for (body
= code
->block
; body
; body
= body
->block
)
9764 c
= body
->ext
.block
.case_list
;
9766 case_value
= (int) mpz_get_si (c
->low
->value
.integer
);
9770 /* Check for repeated cases. */
9771 for (tail
= code
->block
; tail
; tail
= tail
->block
)
9773 gfc_case
*d
= tail
->ext
.block
.case_list
;
9779 /* Check F2018: C1153. */
9780 if (!c
->low
&& !d
->low
)
9781 gfc_error ("RANK DEFAULT at %L is repeated at %L",
9782 &c
->where
, &d
->where
);
9784 if (!c
->low
|| !d
->low
)
9787 /* Check F2018: C1153. */
9788 case_value2
= (int) mpz_get_si (d
->low
->value
.integer
);
9789 if ((case_value
== case_value2
) && case_value
== -1)
9790 gfc_error ("RANK (*) at %L is repeated at %L",
9791 &c
->where
, &d
->where
);
9792 else if (case_value
== case_value2
)
9793 gfc_error ("RANK (%i) at %L is repeated at %L",
9794 case_value
, &c
->where
, &d
->where
);
9800 /* Check F2018: C1155. */
9801 if (case_value
== -1 && (gfc_expr_attr (code
->expr1
).allocatable
9802 || gfc_expr_attr (code
->expr1
).pointer
))
9803 gfc_error ("RANK (*) at %L cannot be used with the pointer or "
9804 "allocatable selector at %L", &c
->where
, &code
->expr1
->where
);
9806 if (case_value
== -1 && (gfc_expr_attr (code
->expr1
).allocatable
9807 || gfc_expr_attr (code
->expr1
).pointer
))
9808 gfc_error ("RANK (*) at %L cannot be used with the pointer or "
9809 "allocatable selector at %L", &c
->where
, &code
->expr1
->where
);
9812 /* Add EXEC_SELECT to switch on rank. */
9813 new_st
= gfc_get_code (code
->op
);
9814 new_st
->expr1
= code
->expr1
;
9815 new_st
->expr2
= code
->expr2
;
9816 new_st
->block
= code
->block
;
9817 code
->expr1
= code
->expr2
= NULL
;
9822 ns
->code
->next
= new_st
;
9824 code
->op
= EXEC_SELECT_RANK
;
9826 selector_expr
= code
->expr1
;
9828 /* Loop over SELECT RANK cases. */
9829 for (body
= code
->block
; body
; body
= body
->block
)
9831 c
= body
->ext
.block
.case_list
;
9834 /* Pass on the default case. */
9838 /* Associate temporary to selector. This should only be done
9839 when this case is actually true, so build a new ASSOCIATE
9840 that does precisely this here (instead of using the
9842 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
9843 && c
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9844 charlen
= gfc_mpz_get_hwi (c
->ts
.u
.cl
->length
->value
.integer
);
9846 if (c
->ts
.type
== BT_CLASS
)
9847 sprintf (tname
, "class_%s", c
->ts
.u
.derived
->name
);
9848 else if (c
->ts
.type
== BT_DERIVED
)
9849 sprintf (tname
, "type_%s", c
->ts
.u
.derived
->name
);
9850 else if (c
->ts
.type
!= BT_CHARACTER
)
9851 sprintf (tname
, "%s_%d", gfc_basic_typename (c
->ts
.type
), c
->ts
.kind
);
9853 sprintf (tname
, "%s_" HOST_WIDE_INT_PRINT_DEC
"_%d",
9854 gfc_basic_typename (c
->ts
.type
), charlen
, c
->ts
.kind
);
9856 case_value
= (int) mpz_get_si (c
->low
->value
.integer
);
9857 if (case_value
>= 0)
9858 sprintf (name
, "__tmp_%s_rank_%d", tname
, case_value
);
9860 sprintf (name
, "__tmp_%s_rank_m%d", tname
, -case_value
);
9862 st
= gfc_find_symtree (ns
->sym_root
, name
);
9863 gcc_assert (st
->n
.sym
->assoc
);
9865 st
->n
.sym
->assoc
->target
= gfc_get_variable_expr (selector_expr
->symtree
);
9866 st
->n
.sym
->assoc
->target
->where
= selector_expr
->where
;
9868 new_st
= gfc_get_code (EXEC_BLOCK
);
9869 new_st
->ext
.block
.ns
= gfc_build_block_ns (ns
);
9870 new_st
->ext
.block
.ns
->code
= body
->next
;
9871 body
->next
= new_st
;
9873 /* Chain in the new list only if it is marked as dangling. Otherwise
9874 there is a CASE label overlap and this is already used. Just ignore,
9875 the error is diagnosed elsewhere. */
9876 if (st
->n
.sym
->assoc
->dangling
)
9878 new_st
->ext
.block
.assoc
= st
->n
.sym
->assoc
;
9879 st
->n
.sym
->assoc
->dangling
= 0;
9882 resolve_assoc_var (st
->n
.sym
, false);
9885 gfc_current_ns
= ns
;
9886 gfc_resolve_blocks (code
->block
, gfc_current_ns
);
9887 gfc_current_ns
= old_ns
;
9891 /* Resolve a transfer statement. This is making sure that:
9892 -- a derived type being transferred has only non-pointer components
9893 -- a derived type being transferred doesn't have private components, unless
9894 it's being transferred from the module where the type was defined
9895 -- we're not trying to transfer a whole assumed size array. */
9898 resolve_transfer (gfc_code
*code
)
9900 gfc_symbol
*sym
, *derived
;
9904 bool formatted
= false;
9905 gfc_dt
*dt
= code
->ext
.dt
;
9906 gfc_symbol
*dtio_sub
= NULL
;
9910 while (exp
!= NULL
&& exp
->expr_type
== EXPR_OP
9911 && exp
->value
.op
.op
== INTRINSIC_PARENTHESES
)
9912 exp
= exp
->value
.op
.op1
;
9914 if (exp
&& exp
->expr_type
== EXPR_NULL
9917 gfc_error ("Invalid context for NULL () intrinsic at %L",
9922 if (exp
== NULL
|| (exp
->expr_type
!= EXPR_VARIABLE
9923 && exp
->expr_type
!= EXPR_FUNCTION
9924 && exp
->expr_type
!= EXPR_STRUCTURE
))
9927 /* If we are reading, the variable will be changed. Note that
9928 code->ext.dt may be NULL if the TRANSFER is related to
9929 an INQUIRE statement -- but in this case, we are not reading, either. */
9930 if (dt
&& dt
->dt_io_kind
->value
.iokind
== M_READ
9931 && !gfc_check_vardef_context (exp
, false, false, false,
9935 const gfc_typespec
*ts
= exp
->expr_type
== EXPR_STRUCTURE
9936 || exp
->expr_type
== EXPR_FUNCTION
9937 ? &exp
->ts
: &exp
->symtree
->n
.sym
->ts
;
9939 /* Go to actual component transferred. */
9940 for (ref
= exp
->ref
; ref
; ref
= ref
->next
)
9941 if (ref
->type
== REF_COMPONENT
)
9942 ts
= &ref
->u
.c
.component
->ts
;
9944 if (dt
&& dt
->dt_io_kind
->value
.iokind
!= M_INQUIRE
9945 && (ts
->type
== BT_DERIVED
|| ts
->type
== BT_CLASS
))
9947 derived
= ts
->u
.derived
;
9949 /* Determine when to use the formatted DTIO procedure. */
9950 if (dt
&& (dt
->format_expr
|| dt
->format_label
))
9953 write
= dt
->dt_io_kind
->value
.iokind
== M_WRITE
9954 || dt
->dt_io_kind
->value
.iokind
== M_PRINT
;
9955 dtio_sub
= gfc_find_specific_dtio_proc (derived
, write
, formatted
);
9957 if (dtio_sub
!= NULL
&& exp
->expr_type
== EXPR_VARIABLE
)
9960 sym
= exp
->symtree
->n
.sym
->ns
->proc_name
;
9961 /* Check to see if this is a nested DTIO call, with the
9962 dummy as the io-list object. */
9963 if (sym
&& sym
== dtio_sub
&& sym
->formal
9964 && sym
->formal
->sym
== exp
->symtree
->n
.sym
9965 && exp
->ref
== NULL
)
9967 if (!sym
->attr
.recursive
)
9969 gfc_error ("DTIO %s procedure at %L must be recursive",
9970 sym
->name
, &sym
->declared_at
);
9977 if (ts
->type
== BT_CLASS
&& dtio_sub
== NULL
)
9979 gfc_error ("Data transfer element at %L cannot be polymorphic unless "
9980 "it is processed by a defined input/output procedure",
9985 if (ts
->type
== BT_DERIVED
)
9987 /* Check that transferred derived type doesn't contain POINTER
9988 components unless it is processed by a defined input/output
9990 if (ts
->u
.derived
->attr
.pointer_comp
&& dtio_sub
== NULL
)
9992 gfc_error ("Data transfer element at %L cannot have POINTER "
9993 "components unless it is processed by a defined "
9994 "input/output procedure", &code
->loc
);
9999 if (ts
->u
.derived
->attr
.proc_pointer_comp
)
10001 gfc_error ("Data transfer element at %L cannot have "
10002 "procedure pointer components", &code
->loc
);
10006 if (ts
->u
.derived
->attr
.alloc_comp
&& dtio_sub
== NULL
)
10008 gfc_error ("Data transfer element at %L cannot have ALLOCATABLE "
10009 "components unless it is processed by a defined "
10010 "input/output procedure", &code
->loc
);
10014 /* C_PTR and C_FUNPTR have private components which means they cannot
10015 be printed. However, if -std=gnu and not -pedantic, allow
10016 the component to be printed to help debugging. */
10017 if (ts
->u
.derived
->ts
.f90_type
== BT_VOID
)
10019 if (!gfc_notify_std (GFC_STD_GNU
, "Data transfer element at %L "
10020 "cannot have PRIVATE components", &code
->loc
))
10023 else if (derived_inaccessible (ts
->u
.derived
) && dtio_sub
== NULL
)
10025 gfc_error ("Data transfer element at %L cannot have "
10026 "PRIVATE components unless it is processed by "
10027 "a defined input/output procedure", &code
->loc
);
10032 if (exp
->expr_type
== EXPR_STRUCTURE
)
10035 sym
= exp
->symtree
->n
.sym
;
10037 if (sym
->as
!= NULL
&& sym
->as
->type
== AS_ASSUMED_SIZE
&& exp
->ref
10038 && exp
->ref
->type
== REF_ARRAY
&& exp
->ref
->u
.ar
.type
== AR_FULL
)
10040 gfc_error ("Data transfer element at %L cannot be a full reference to "
10041 "an assumed-size array", &code
->loc
);
10047 /*********** Toplevel code resolution subroutines ***********/
10049 /* Find the set of labels that are reachable from this block. We also
10050 record the last statement in each block. */
10053 find_reachable_labels (gfc_code
*block
)
10060 cs_base
->reachable_labels
= bitmap_alloc (&labels_obstack
);
10062 /* Collect labels in this block. We don't keep those corresponding
10063 to END {IF|SELECT}, these are checked in resolve_branch by going
10064 up through the code_stack. */
10065 for (c
= block
; c
; c
= c
->next
)
10067 if (c
->here
&& c
->op
!= EXEC_END_NESTED_BLOCK
)
10068 bitmap_set_bit (cs_base
->reachable_labels
, c
->here
->value
);
10071 /* Merge with labels from parent block. */
10074 gcc_assert (cs_base
->prev
->reachable_labels
);
10075 bitmap_ior_into (cs_base
->reachable_labels
,
10076 cs_base
->prev
->reachable_labels
);
10082 resolve_lock_unlock_event (gfc_code
*code
)
10084 if (code
->expr1
->expr_type
== EXPR_FUNCTION
10085 && code
->expr1
->value
.function
.isym
10086 && code
->expr1
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
10087 remove_caf_get_intrinsic (code
->expr1
);
10089 if ((code
->op
== EXEC_LOCK
|| code
->op
== EXEC_UNLOCK
)
10090 && (code
->expr1
->ts
.type
!= BT_DERIVED
10091 || code
->expr1
->expr_type
!= EXPR_VARIABLE
10092 || code
->expr1
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
10093 || code
->expr1
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_LOCK_TYPE
10094 || code
->expr1
->rank
!= 0
10095 || (!gfc_is_coarray (code
->expr1
) &&
10096 !gfc_is_coindexed (code
->expr1
))))
10097 gfc_error ("Lock variable at %L must be a scalar of type LOCK_TYPE",
10098 &code
->expr1
->where
);
10099 else if ((code
->op
== EXEC_EVENT_POST
|| code
->op
== EXEC_EVENT_WAIT
)
10100 && (code
->expr1
->ts
.type
!= BT_DERIVED
10101 || code
->expr1
->expr_type
!= EXPR_VARIABLE
10102 || code
->expr1
->ts
.u
.derived
->from_intmod
10103 != INTMOD_ISO_FORTRAN_ENV
10104 || code
->expr1
->ts
.u
.derived
->intmod_sym_id
10105 != ISOFORTRAN_EVENT_TYPE
10106 || code
->expr1
->rank
!= 0))
10107 gfc_error ("Event variable at %L must be a scalar of type EVENT_TYPE",
10108 &code
->expr1
->where
);
10109 else if (code
->op
== EXEC_EVENT_POST
&& !gfc_is_coarray (code
->expr1
)
10110 && !gfc_is_coindexed (code
->expr1
))
10111 gfc_error ("Event variable argument at %L must be a coarray or coindexed",
10112 &code
->expr1
->where
);
10113 else if (code
->op
== EXEC_EVENT_WAIT
&& !gfc_is_coarray (code
->expr1
))
10114 gfc_error ("Event variable argument at %L must be a coarray but not "
10115 "coindexed", &code
->expr1
->where
);
10119 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
10120 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
10121 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
10122 &code
->expr2
->where
);
10125 && !gfc_check_vardef_context (code
->expr2
, false, false, false,
10126 _("STAT variable")))
10129 /* Check ERRMSG. */
10131 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
10132 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
10133 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
10134 &code
->expr3
->where
);
10137 && !gfc_check_vardef_context (code
->expr3
, false, false, false,
10138 _("ERRMSG variable")))
10141 /* Check for LOCK the ACQUIRED_LOCK. */
10142 if (code
->op
!= EXEC_EVENT_WAIT
&& code
->expr4
10143 && (code
->expr4
->ts
.type
!= BT_LOGICAL
|| code
->expr4
->rank
!= 0
10144 || code
->expr4
->expr_type
!= EXPR_VARIABLE
))
10145 gfc_error ("ACQUIRED_LOCK= argument at %L must be a scalar LOGICAL "
10146 "variable", &code
->expr4
->where
);
10148 if (code
->op
!= EXEC_EVENT_WAIT
&& code
->expr4
10149 && !gfc_check_vardef_context (code
->expr4
, false, false, false,
10150 _("ACQUIRED_LOCK variable")))
10153 /* Check for EVENT WAIT the UNTIL_COUNT. */
10154 if (code
->op
== EXEC_EVENT_WAIT
&& code
->expr4
)
10156 if (!gfc_resolve_expr (code
->expr4
) || code
->expr4
->ts
.type
!= BT_INTEGER
10157 || code
->expr4
->rank
!= 0)
10158 gfc_error ("UNTIL_COUNT= argument at %L must be a scalar INTEGER "
10159 "expression", &code
->expr4
->where
);
10165 resolve_critical (gfc_code
*code
)
10167 gfc_symtree
*symtree
;
10168 gfc_symbol
*lock_type
;
10169 char name
[GFC_MAX_SYMBOL_LEN
];
10170 static int serial
= 0;
10172 if (flag_coarray
!= GFC_FCOARRAY_LIB
)
10175 symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
10176 GFC_PREFIX ("lock_type"));
10178 lock_type
= symtree
->n
.sym
;
10181 if (gfc_get_sym_tree (GFC_PREFIX ("lock_type"), gfc_current_ns
, &symtree
,
10183 gcc_unreachable ();
10184 lock_type
= symtree
->n
.sym
;
10185 lock_type
->attr
.flavor
= FL_DERIVED
;
10186 lock_type
->attr
.zero_comp
= 1;
10187 lock_type
->from_intmod
= INTMOD_ISO_FORTRAN_ENV
;
10188 lock_type
->intmod_sym_id
= ISOFORTRAN_LOCK_TYPE
;
10191 sprintf(name
, GFC_PREFIX ("lock_var") "%d",serial
++);
10192 if (gfc_get_sym_tree (name
, gfc_current_ns
, &symtree
, false) != 0)
10193 gcc_unreachable ();
10195 code
->resolved_sym
= symtree
->n
.sym
;
10196 symtree
->n
.sym
->attr
.flavor
= FL_VARIABLE
;
10197 symtree
->n
.sym
->attr
.referenced
= 1;
10198 symtree
->n
.sym
->attr
.artificial
= 1;
10199 symtree
->n
.sym
->attr
.codimension
= 1;
10200 symtree
->n
.sym
->ts
.type
= BT_DERIVED
;
10201 symtree
->n
.sym
->ts
.u
.derived
= lock_type
;
10202 symtree
->n
.sym
->as
= gfc_get_array_spec ();
10203 symtree
->n
.sym
->as
->corank
= 1;
10204 symtree
->n
.sym
->as
->type
= AS_EXPLICIT
;
10205 symtree
->n
.sym
->as
->cotype
= AS_EXPLICIT
;
10206 symtree
->n
.sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
,
10208 gfc_commit_symbols();
10213 resolve_sync (gfc_code
*code
)
10215 /* Check imageset. The * case matches expr1 == NULL. */
10218 if (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
> 1)
10219 gfc_error ("Imageset argument at %L must be a scalar or rank-1 "
10220 "INTEGER expression", &code
->expr1
->where
);
10221 if (code
->expr1
->expr_type
== EXPR_CONSTANT
&& code
->expr1
->rank
== 0
10222 && mpz_cmp_si (code
->expr1
->value
.integer
, 1) < 0)
10223 gfc_error ("Imageset argument at %L must between 1 and num_images()",
10224 &code
->expr1
->where
);
10225 else if (code
->expr1
->expr_type
== EXPR_ARRAY
10226 && gfc_simplify_expr (code
->expr1
, 0))
10228 gfc_constructor
*cons
;
10229 cons
= gfc_constructor_first (code
->expr1
->value
.constructor
);
10230 for (; cons
; cons
= gfc_constructor_next (cons
))
10231 if (cons
->expr
->expr_type
== EXPR_CONSTANT
10232 && mpz_cmp_si (cons
->expr
->value
.integer
, 1) < 0)
10233 gfc_error ("Imageset argument at %L must between 1 and "
10234 "num_images()", &cons
->expr
->where
);
10239 gfc_resolve_expr (code
->expr2
);
10241 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
10242 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
10243 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
10244 &code
->expr2
->where
);
10246 /* Check ERRMSG. */
10247 gfc_resolve_expr (code
->expr3
);
10249 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
10250 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
10251 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
10252 &code
->expr3
->where
);
10256 /* Given a branch to a label, see if the branch is conforming.
10257 The code node describes where the branch is located. */
10260 resolve_branch (gfc_st_label
*label
, gfc_code
*code
)
10267 /* Step one: is this a valid branching target? */
10269 if (label
->defined
== ST_LABEL_UNKNOWN
)
10271 gfc_error ("Label %d referenced at %L is never defined", label
->value
,
10276 if (label
->defined
!= ST_LABEL_TARGET
&& label
->defined
!= ST_LABEL_DO_TARGET
)
10278 gfc_error ("Statement at %L is not a valid branch target statement "
10279 "for the branch statement at %L", &label
->where
, &code
->loc
);
10283 /* Step two: make sure this branch is not a branch to itself ;-) */
10285 if (code
->here
== label
)
10288 "Branch at %L may result in an infinite loop", &code
->loc
);
10292 /* Step three: See if the label is in the same block as the
10293 branching statement. The hard work has been done by setting up
10294 the bitmap reachable_labels. */
10296 if (bitmap_bit_p (cs_base
->reachable_labels
, label
->value
))
10298 /* Check now whether there is a CRITICAL construct; if so, check
10299 whether the label is still visible outside of the CRITICAL block,
10300 which is invalid. */
10301 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
10303 if (stack
->current
->op
== EXEC_CRITICAL
10304 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
10305 gfc_error ("GOTO statement at %L leaves CRITICAL construct for "
10306 "label at %L", &code
->loc
, &label
->where
);
10307 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
10308 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
10309 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct "
10310 "for label at %L", &code
->loc
, &label
->where
);
10316 /* Step four: If we haven't found the label in the bitmap, it may
10317 still be the label of the END of the enclosing block, in which
10318 case we find it by going up the code_stack. */
10320 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
10322 if (stack
->current
->next
&& stack
->current
->next
->here
== label
)
10324 if (stack
->current
->op
== EXEC_CRITICAL
)
10326 /* Note: A label at END CRITICAL does not leave the CRITICAL
10327 construct as END CRITICAL is still part of it. */
10328 gfc_error ("GOTO statement at %L leaves CRITICAL construct for label"
10329 " at %L", &code
->loc
, &label
->where
);
10332 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
)
10334 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct for "
10335 "label at %L", &code
->loc
, &label
->where
);
10342 gcc_assert (stack
->current
->next
->op
== EXEC_END_NESTED_BLOCK
);
10346 /* The label is not in an enclosing block, so illegal. This was
10347 allowed in Fortran 66, so we allow it as extension. No
10348 further checks are necessary in this case. */
10349 gfc_notify_std (GFC_STD_LEGACY
, "Label at %L is not in the same block "
10350 "as the GOTO statement at %L", &label
->where
,
10356 /* Check whether EXPR1 has the same shape as EXPR2. */
10359 resolve_where_shape (gfc_expr
*expr1
, gfc_expr
*expr2
)
10361 mpz_t shape
[GFC_MAX_DIMENSIONS
];
10362 mpz_t shape2
[GFC_MAX_DIMENSIONS
];
10363 bool result
= false;
10366 /* Compare the rank. */
10367 if (expr1
->rank
!= expr2
->rank
)
10370 /* Compare the size of each dimension. */
10371 for (i
=0; i
<expr1
->rank
; i
++)
10373 if (!gfc_array_dimen_size (expr1
, i
, &shape
[i
]))
10376 if (!gfc_array_dimen_size (expr2
, i
, &shape2
[i
]))
10379 if (mpz_cmp (shape
[i
], shape2
[i
]))
10383 /* When either of the two expression is an assumed size array, we
10384 ignore the comparison of dimension sizes. */
10389 gfc_clear_shape (shape
, i
);
10390 gfc_clear_shape (shape2
, i
);
10395 /* Check whether a WHERE assignment target or a WHERE mask expression
10396 has the same shape as the outmost WHERE mask expression. */
10399 resolve_where (gfc_code
*code
, gfc_expr
*mask
)
10403 gfc_expr
*e
= NULL
;
10405 cblock
= code
->block
;
10407 /* Store the first WHERE mask-expr of the WHERE statement or construct.
10408 In case of nested WHERE, only the outmost one is stored. */
10409 if (mask
== NULL
) /* outmost WHERE */
10411 else /* inner WHERE */
10418 /* Check if the mask-expr has a consistent shape with the
10419 outmost WHERE mask-expr. */
10420 if (!resolve_where_shape (cblock
->expr1
, e
))
10421 gfc_error ("WHERE mask at %L has inconsistent shape",
10422 &cblock
->expr1
->where
);
10425 /* the assignment statement of a WHERE statement, or the first
10426 statement in where-body-construct of a WHERE construct */
10427 cnext
= cblock
->next
;
10432 /* WHERE assignment statement */
10435 /* Check shape consistent for WHERE assignment target. */
10436 if (e
&& !resolve_where_shape (cnext
->expr1
, e
))
10437 gfc_error ("WHERE assignment target at %L has "
10438 "inconsistent shape", &cnext
->expr1
->where
);
10442 case EXEC_ASSIGN_CALL
:
10443 resolve_call (cnext
);
10444 if (!cnext
->resolved_sym
->attr
.elemental
)
10445 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
10446 &cnext
->ext
.actual
->expr
->where
);
10449 /* WHERE or WHERE construct is part of a where-body-construct */
10451 resolve_where (cnext
, e
);
10455 gfc_error ("Unsupported statement inside WHERE at %L",
10458 /* the next statement within the same where-body-construct */
10459 cnext
= cnext
->next
;
10461 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
10462 cblock
= cblock
->block
;
10467 /* Resolve assignment in FORALL construct.
10468 NVAR is the number of FORALL index variables, and VAR_EXPR records the
10469 FORALL index variables. */
10472 gfc_resolve_assign_in_forall (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
10476 for (n
= 0; n
< nvar
; n
++)
10478 gfc_symbol
*forall_index
;
10480 forall_index
= var_expr
[n
]->symtree
->n
.sym
;
10482 /* Check whether the assignment target is one of the FORALL index
10484 if ((code
->expr1
->expr_type
== EXPR_VARIABLE
)
10485 && (code
->expr1
->symtree
->n
.sym
== forall_index
))
10486 gfc_error ("Assignment to a FORALL index variable at %L",
10487 &code
->expr1
->where
);
10490 /* If one of the FORALL index variables doesn't appear in the
10491 assignment variable, then there could be a many-to-one
10492 assignment. Emit a warning rather than an error because the
10493 mask could be resolving this problem. */
10494 if (!find_forall_index (code
->expr1
, forall_index
, 0))
10495 gfc_warning (0, "The FORALL with index %qs is not used on the "
10496 "left side of the assignment at %L and so might "
10497 "cause multiple assignment to this object",
10498 var_expr
[n
]->symtree
->name
, &code
->expr1
->where
);
10504 /* Resolve WHERE statement in FORALL construct. */
10507 gfc_resolve_where_code_in_forall (gfc_code
*code
, int nvar
,
10508 gfc_expr
**var_expr
)
10513 cblock
= code
->block
;
10516 /* the assignment statement of a WHERE statement, or the first
10517 statement in where-body-construct of a WHERE construct */
10518 cnext
= cblock
->next
;
10523 /* WHERE assignment statement */
10525 gfc_resolve_assign_in_forall (cnext
, nvar
, var_expr
);
10528 /* WHERE operator assignment statement */
10529 case EXEC_ASSIGN_CALL
:
10530 resolve_call (cnext
);
10531 if (!cnext
->resolved_sym
->attr
.elemental
)
10532 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
10533 &cnext
->ext
.actual
->expr
->where
);
10536 /* WHERE or WHERE construct is part of a where-body-construct */
10538 gfc_resolve_where_code_in_forall (cnext
, nvar
, var_expr
);
10542 gfc_error ("Unsupported statement inside WHERE at %L",
10545 /* the next statement within the same where-body-construct */
10546 cnext
= cnext
->next
;
10548 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
10549 cblock
= cblock
->block
;
10554 /* Traverse the FORALL body to check whether the following errors exist:
10555 1. For assignment, check if a many-to-one assignment happens.
10556 2. For WHERE statement, check the WHERE body to see if there is any
10557 many-to-one assignment. */
10560 gfc_resolve_forall_body (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
10564 c
= code
->block
->next
;
10570 case EXEC_POINTER_ASSIGN
:
10571 gfc_resolve_assign_in_forall (c
, nvar
, var_expr
);
10574 case EXEC_ASSIGN_CALL
:
10578 /* Because the gfc_resolve_blocks() will handle the nested FORALL,
10579 there is no need to handle it here. */
10583 gfc_resolve_where_code_in_forall(c
, nvar
, var_expr
);
10588 /* The next statement in the FORALL body. */
10594 /* Counts the number of iterators needed inside a forall construct, including
10595 nested forall constructs. This is used to allocate the needed memory
10596 in gfc_resolve_forall. */
10599 gfc_count_forall_iterators (gfc_code
*code
)
10601 int max_iters
, sub_iters
, current_iters
;
10602 gfc_forall_iterator
*fa
;
10604 gcc_assert(code
->op
== EXEC_FORALL
);
10608 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
10611 code
= code
->block
->next
;
10615 if (code
->op
== EXEC_FORALL
)
10617 sub_iters
= gfc_count_forall_iterators (code
);
10618 if (sub_iters
> max_iters
)
10619 max_iters
= sub_iters
;
10624 return current_iters
+ max_iters
;
10628 /* Given a FORALL construct, first resolve the FORALL iterator, then call
10629 gfc_resolve_forall_body to resolve the FORALL body. */
10632 gfc_resolve_forall (gfc_code
*code
, gfc_namespace
*ns
, int forall_save
)
10634 static gfc_expr
**var_expr
;
10635 static int total_var
= 0;
10636 static int nvar
= 0;
10637 int i
, old_nvar
, tmp
;
10638 gfc_forall_iterator
*fa
;
10642 if (!gfc_notify_std (GFC_STD_F2018_OBS
, "FORALL construct at %L", &code
->loc
))
10645 /* Start to resolve a FORALL construct */
10646 if (forall_save
== 0)
10648 /* Count the total number of FORALL indices in the nested FORALL
10649 construct in order to allocate the VAR_EXPR with proper size. */
10650 total_var
= gfc_count_forall_iterators (code
);
10652 /* Allocate VAR_EXPR with NUMBER_OF_FORALL_INDEX elements. */
10653 var_expr
= XCNEWVEC (gfc_expr
*, total_var
);
10656 /* The information about FORALL iterator, including FORALL indices start, end
10657 and stride. An outer FORALL indice cannot appear in start, end or stride. */
10658 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
10660 /* Fortran 20008: C738 (R753). */
10661 if (fa
->var
->ref
&& fa
->var
->ref
->type
== REF_ARRAY
)
10663 gfc_error ("FORALL index-name at %L must be a scalar variable "
10664 "of type integer", &fa
->var
->where
);
10668 /* Check if any outer FORALL index name is the same as the current
10670 for (i
= 0; i
< nvar
; i
++)
10672 if (fa
->var
->symtree
->n
.sym
== var_expr
[i
]->symtree
->n
.sym
)
10673 gfc_error ("An outer FORALL construct already has an index "
10674 "with this name %L", &fa
->var
->where
);
10677 /* Record the current FORALL index. */
10678 var_expr
[nvar
] = gfc_copy_expr (fa
->var
);
10682 /* No memory leak. */
10683 gcc_assert (nvar
<= total_var
);
10686 /* Resolve the FORALL body. */
10687 gfc_resolve_forall_body (code
, nvar
, var_expr
);
10689 /* May call gfc_resolve_forall to resolve the inner FORALL loop. */
10690 gfc_resolve_blocks (code
->block
, ns
);
10694 /* Free only the VAR_EXPRs allocated in this frame. */
10695 for (i
= nvar
; i
< tmp
; i
++)
10696 gfc_free_expr (var_expr
[i
]);
10700 /* We are in the outermost FORALL construct. */
10701 gcc_assert (forall_save
== 0);
10703 /* VAR_EXPR is not needed any more. */
10710 /* Resolve a BLOCK construct statement. */
10713 resolve_block_construct (gfc_code
* code
)
10715 /* Resolve the BLOCK's namespace. */
10716 gfc_resolve (code
->ext
.block
.ns
);
10718 /* For an ASSOCIATE block, the associations (and their targets) are already
10719 resolved during resolve_symbol. */
10723 /* Resolve lists of blocks found in IF, SELECT CASE, WHERE, FORALL, GOTO and
10727 gfc_resolve_blocks (gfc_code
*b
, gfc_namespace
*ns
)
10731 for (; b
; b
= b
->block
)
10733 t
= gfc_resolve_expr (b
->expr1
);
10734 if (!gfc_resolve_expr (b
->expr2
))
10740 if (t
&& b
->expr1
!= NULL
10741 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
!= 0))
10742 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
10748 && b
->expr1
!= NULL
10749 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
== 0))
10750 gfc_error ("WHERE/ELSEWHERE clause at %L requires a LOGICAL array",
10755 resolve_branch (b
->label1
, b
);
10759 resolve_block_construct (b
);
10763 case EXEC_SELECT_TYPE
:
10764 case EXEC_SELECT_RANK
:
10767 case EXEC_DO_WHILE
:
10768 case EXEC_DO_CONCURRENT
:
10769 case EXEC_CRITICAL
:
10772 case EXEC_IOLENGTH
:
10776 case EXEC_OMP_ATOMIC
:
10777 case EXEC_OACC_ATOMIC
:
10779 /* Verify this before calling gfc_resolve_code, which might
10781 gcc_assert (b
->next
&& b
->next
->op
== EXEC_ASSIGN
);
10782 gcc_assert ((!b
->ext
.omp_clauses
->capture
10783 && b
->next
->next
== NULL
)
10784 || (b
->ext
.omp_clauses
->capture
10785 && b
->next
->next
!= NULL
10786 && b
->next
->next
->op
== EXEC_ASSIGN
10787 && b
->next
->next
->next
== NULL
));
10791 case EXEC_OACC_PARALLEL_LOOP
:
10792 case EXEC_OACC_PARALLEL
:
10793 case EXEC_OACC_KERNELS_LOOP
:
10794 case EXEC_OACC_KERNELS
:
10795 case EXEC_OACC_SERIAL_LOOP
:
10796 case EXEC_OACC_SERIAL
:
10797 case EXEC_OACC_DATA
:
10798 case EXEC_OACC_HOST_DATA
:
10799 case EXEC_OACC_LOOP
:
10800 case EXEC_OACC_UPDATE
:
10801 case EXEC_OACC_WAIT
:
10802 case EXEC_OACC_CACHE
:
10803 case EXEC_OACC_ENTER_DATA
:
10804 case EXEC_OACC_EXIT_DATA
:
10805 case EXEC_OACC_ROUTINE
:
10806 case EXEC_OMP_CRITICAL
:
10807 case EXEC_OMP_DISTRIBUTE
:
10808 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
10809 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
10810 case EXEC_OMP_DISTRIBUTE_SIMD
:
10812 case EXEC_OMP_DO_SIMD
:
10813 case EXEC_OMP_LOOP
:
10814 case EXEC_OMP_MASTER
:
10815 case EXEC_OMP_MASTER_TASKLOOP
:
10816 case EXEC_OMP_MASTER_TASKLOOP_SIMD
:
10817 case EXEC_OMP_ORDERED
:
10818 case EXEC_OMP_PARALLEL
:
10819 case EXEC_OMP_PARALLEL_DO
:
10820 case EXEC_OMP_PARALLEL_DO_SIMD
:
10821 case EXEC_OMP_PARALLEL_LOOP
:
10822 case EXEC_OMP_PARALLEL_MASTER
:
10823 case EXEC_OMP_PARALLEL_MASTER_TASKLOOP
:
10824 case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
10825 case EXEC_OMP_PARALLEL_SECTIONS
:
10826 case EXEC_OMP_PARALLEL_WORKSHARE
:
10827 case EXEC_OMP_SECTIONS
:
10828 case EXEC_OMP_SIMD
:
10829 case EXEC_OMP_SINGLE
:
10830 case EXEC_OMP_TARGET
:
10831 case EXEC_OMP_TARGET_DATA
:
10832 case EXEC_OMP_TARGET_ENTER_DATA
:
10833 case EXEC_OMP_TARGET_EXIT_DATA
:
10834 case EXEC_OMP_TARGET_PARALLEL
:
10835 case EXEC_OMP_TARGET_PARALLEL_DO
:
10836 case EXEC_OMP_TARGET_PARALLEL_DO_SIMD
:
10837 case EXEC_OMP_TARGET_PARALLEL_LOOP
:
10838 case EXEC_OMP_TARGET_SIMD
:
10839 case EXEC_OMP_TARGET_TEAMS
:
10840 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
10841 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10842 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10843 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
10844 case EXEC_OMP_TARGET_TEAMS_LOOP
:
10845 case EXEC_OMP_TARGET_UPDATE
:
10846 case EXEC_OMP_TASK
:
10847 case EXEC_OMP_TASKGROUP
:
10848 case EXEC_OMP_TASKLOOP
:
10849 case EXEC_OMP_TASKLOOP_SIMD
:
10850 case EXEC_OMP_TASKWAIT
:
10851 case EXEC_OMP_TASKYIELD
:
10852 case EXEC_OMP_TEAMS
:
10853 case EXEC_OMP_TEAMS_DISTRIBUTE
:
10854 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10855 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10856 case EXEC_OMP_TEAMS_LOOP
:
10857 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
10858 case EXEC_OMP_WORKSHARE
:
10862 gfc_internal_error ("gfc_resolve_blocks(): Bad block type");
10865 gfc_resolve_code (b
->next
, ns
);
10870 /* Does everything to resolve an ordinary assignment. Returns true
10871 if this is an interface assignment. */
10873 resolve_ordinary_assign (gfc_code
*code
, gfc_namespace
*ns
)
10880 symbol_attribute attr
;
10882 if (gfc_extend_assign (code
, ns
))
10886 if (code
->op
== EXEC_ASSIGN_CALL
)
10888 lhs
= code
->ext
.actual
->expr
;
10889 rhsptr
= &code
->ext
.actual
->next
->expr
;
10893 gfc_actual_arglist
* args
;
10894 gfc_typebound_proc
* tbp
;
10896 gcc_assert (code
->op
== EXEC_COMPCALL
);
10898 args
= code
->expr1
->value
.compcall
.actual
;
10900 rhsptr
= &args
->next
->expr
;
10902 tbp
= code
->expr1
->value
.compcall
.tbp
;
10903 gcc_assert (!tbp
->is_generic
);
10906 /* Make a temporary rhs when there is a default initializer
10907 and rhs is the same symbol as the lhs. */
10908 if ((*rhsptr
)->expr_type
== EXPR_VARIABLE
10909 && (*rhsptr
)->symtree
->n
.sym
->ts
.type
== BT_DERIVED
10910 && gfc_has_default_initializer ((*rhsptr
)->symtree
->n
.sym
->ts
.u
.derived
)
10911 && (lhs
->symtree
->n
.sym
== (*rhsptr
)->symtree
->n
.sym
))
10912 *rhsptr
= gfc_get_parentheses (*rhsptr
);
10920 if ((gfc_numeric_ts (&lhs
->ts
) || lhs
->ts
.type
== BT_LOGICAL
)
10921 && rhs
->ts
.type
== BT_CHARACTER
10922 && (rhs
->expr_type
!= EXPR_CONSTANT
|| !flag_dec_char_conversions
))
10924 /* Use of -fdec-char-conversions allows assignment of character data
10925 to non-character variables. This not permited for nonconstant
10927 gfc_error ("Cannot convert %s to %s at %L", gfc_typename (rhs
),
10928 gfc_typename (lhs
), &rhs
->where
);
10932 /* Handle the case of a BOZ literal on the RHS. */
10933 if (rhs
->ts
.type
== BT_BOZ
)
10935 if (gfc_invalid_boz ("BOZ literal constant at %L is neither a DATA "
10936 "statement value nor an actual argument of "
10937 "INT/REAL/DBLE/CMPLX intrinsic subprogram",
10941 switch (lhs
->ts
.type
)
10944 if (!gfc_boz2int (rhs
, lhs
->ts
.kind
))
10948 if (!gfc_boz2real (rhs
, lhs
->ts
.kind
))
10952 gfc_error ("Invalid use of BOZ literal constant at %L", &rhs
->where
);
10957 if (lhs
->ts
.type
== BT_CHARACTER
&& warn_character_truncation
)
10959 HOST_WIDE_INT llen
= 0, rlen
= 0;
10960 if (lhs
->ts
.u
.cl
!= NULL
10961 && lhs
->ts
.u
.cl
->length
!= NULL
10962 && lhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
10963 llen
= gfc_mpz_get_hwi (lhs
->ts
.u
.cl
->length
->value
.integer
);
10965 if (rhs
->expr_type
== EXPR_CONSTANT
)
10966 rlen
= rhs
->value
.character
.length
;
10968 else if (rhs
->ts
.u
.cl
!= NULL
10969 && rhs
->ts
.u
.cl
->length
!= NULL
10970 && rhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
10971 rlen
= gfc_mpz_get_hwi (rhs
->ts
.u
.cl
->length
->value
.integer
);
10973 if (rlen
&& llen
&& rlen
> llen
)
10974 gfc_warning_now (OPT_Wcharacter_truncation
,
10975 "CHARACTER expression will be truncated "
10976 "in assignment (%ld/%ld) at %L",
10977 (long) llen
, (long) rlen
, &code
->loc
);
10980 /* Ensure that a vector index expression for the lvalue is evaluated
10981 to a temporary if the lvalue symbol is referenced in it. */
10984 for (ref
= lhs
->ref
; ref
; ref
= ref
->next
)
10985 if (ref
->type
== REF_ARRAY
)
10987 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
10988 if (ref
->u
.ar
.dimen_type
[n
] == DIMEN_VECTOR
10989 && gfc_find_sym_in_expr (lhs
->symtree
->n
.sym
,
10990 ref
->u
.ar
.start
[n
]))
10992 = gfc_get_parentheses (ref
->u
.ar
.start
[n
]);
10996 if (gfc_pure (NULL
))
10998 if (lhs
->ts
.type
== BT_DERIVED
10999 && lhs
->expr_type
== EXPR_VARIABLE
11000 && lhs
->ts
.u
.derived
->attr
.pointer_comp
11001 && rhs
->expr_type
== EXPR_VARIABLE
11002 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
11003 || gfc_is_coindexed (rhs
)))
11005 /* F2008, C1283. */
11006 if (gfc_is_coindexed (rhs
))
11007 gfc_error ("Coindexed expression at %L is assigned to "
11008 "a derived type variable with a POINTER "
11009 "component in a PURE procedure",
11012 /* F2008, C1283 (4). */
11013 gfc_error ("In a pure subprogram an INTENT(IN) dummy argument "
11014 "shall not be used as the expr at %L of an intrinsic "
11015 "assignment statement in which the variable is of a "
11016 "derived type if the derived type has a pointer "
11017 "component at any level of component selection.",
11022 /* Fortran 2008, C1283. */
11023 if (gfc_is_coindexed (lhs
))
11025 gfc_error ("Assignment to coindexed variable at %L in a PURE "
11026 "procedure", &rhs
->where
);
11031 if (gfc_implicit_pure (NULL
))
11033 if (lhs
->expr_type
== EXPR_VARIABLE
11034 && lhs
->symtree
->n
.sym
!= gfc_current_ns
->proc_name
11035 && lhs
->symtree
->n
.sym
->ns
!= gfc_current_ns
)
11036 gfc_unset_implicit_pure (NULL
);
11038 if (lhs
->ts
.type
== BT_DERIVED
11039 && lhs
->expr_type
== EXPR_VARIABLE
11040 && lhs
->ts
.u
.derived
->attr
.pointer_comp
11041 && rhs
->expr_type
== EXPR_VARIABLE
11042 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
11043 || gfc_is_coindexed (rhs
)))
11044 gfc_unset_implicit_pure (NULL
);
11046 /* Fortran 2008, C1283. */
11047 if (gfc_is_coindexed (lhs
))
11048 gfc_unset_implicit_pure (NULL
);
11051 /* F2008, 7.2.1.2. */
11052 attr
= gfc_expr_attr (lhs
);
11053 if (lhs
->ts
.type
== BT_CLASS
&& attr
.allocatable
)
11055 if (attr
.codimension
)
11057 gfc_error ("Assignment to polymorphic coarray at %L is not "
11058 "permitted", &lhs
->where
);
11061 if (!gfc_notify_std (GFC_STD_F2008
, "Assignment to an allocatable "
11062 "polymorphic variable at %L", &lhs
->where
))
11064 if (!flag_realloc_lhs
)
11066 gfc_error ("Assignment to an allocatable polymorphic variable at %L "
11067 "requires %<-frealloc-lhs%>", &lhs
->where
);
11071 else if (lhs
->ts
.type
== BT_CLASS
)
11073 gfc_error ("Nonallocatable variable must not be polymorphic in intrinsic "
11074 "assignment at %L - check that there is a matching specific "
11075 "subroutine for '=' operator", &lhs
->where
);
11079 bool lhs_coindexed
= gfc_is_coindexed (lhs
);
11081 /* F2008, Section 7.2.1.2. */
11082 if (lhs_coindexed
&& gfc_has_ultimate_allocatable (lhs
))
11084 gfc_error ("Coindexed variable must not have an allocatable ultimate "
11085 "component in assignment at %L", &lhs
->where
);
11089 /* Assign the 'data' of a class object to a derived type. */
11090 if (lhs
->ts
.type
== BT_DERIVED
11091 && rhs
->ts
.type
== BT_CLASS
11092 && rhs
->expr_type
!= EXPR_ARRAY
)
11093 gfc_add_data_component (rhs
);
11095 /* Make sure there is a vtable and, in particular, a _copy for the
11097 if (lhs
->ts
.type
== BT_CLASS
&& rhs
->ts
.type
!= BT_CLASS
)
11098 gfc_find_vtab (&rhs
->ts
);
11100 bool caf_convert_to_send
= flag_coarray
== GFC_FCOARRAY_LIB
11102 || (code
->expr2
->expr_type
== EXPR_FUNCTION
11103 && code
->expr2
->value
.function
.isym
11104 && code
->expr2
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
11105 && (code
->expr1
->rank
== 0 || code
->expr2
->rank
!= 0)
11106 && !gfc_expr_attr (rhs
).allocatable
11107 && !gfc_has_vector_subscript (rhs
)));
11109 gfc_check_assign (lhs
, rhs
, 1, !caf_convert_to_send
);
11111 /* Insert a GFC_ISYM_CAF_SEND intrinsic, when the LHS is a coindexed variable.
11112 Additionally, insert this code when the RHS is a CAF as we then use the
11113 GFC_ISYM_CAF_SEND intrinsic just to avoid a temporary; but do not do so if
11114 the LHS is (re)allocatable or has a vector subscript. If the LHS is a
11115 noncoindexed array and the RHS is a coindexed scalar, use the normal code
11117 if (caf_convert_to_send
)
11119 if (code
->expr2
->expr_type
== EXPR_FUNCTION
11120 && code
->expr2
->value
.function
.isym
11121 && code
->expr2
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
11122 remove_caf_get_intrinsic (code
->expr2
);
11123 code
->op
= EXEC_CALL
;
11124 gfc_get_sym_tree (GFC_PREFIX ("caf_send"), ns
, &code
->symtree
, true);
11125 code
->resolved_sym
= code
->symtree
->n
.sym
;
11126 code
->resolved_sym
->attr
.flavor
= FL_PROCEDURE
;
11127 code
->resolved_sym
->attr
.intrinsic
= 1;
11128 code
->resolved_sym
->attr
.subroutine
= 1;
11129 code
->resolved_isym
= gfc_intrinsic_subroutine_by_id (GFC_ISYM_CAF_SEND
);
11130 gfc_commit_symbol (code
->resolved_sym
);
11131 code
->ext
.actual
= gfc_get_actual_arglist ();
11132 code
->ext
.actual
->expr
= lhs
;
11133 code
->ext
.actual
->next
= gfc_get_actual_arglist ();
11134 code
->ext
.actual
->next
->expr
= rhs
;
11135 code
->expr1
= NULL
;
11136 code
->expr2
= NULL
;
11143 /* Add a component reference onto an expression. */
11146 add_comp_ref (gfc_expr
*e
, gfc_component
*c
)
11151 ref
= &((*ref
)->next
);
11152 *ref
= gfc_get_ref ();
11153 (*ref
)->type
= REF_COMPONENT
;
11154 (*ref
)->u
.c
.sym
= e
->ts
.u
.derived
;
11155 (*ref
)->u
.c
.component
= c
;
11158 /* Add a full array ref, as necessary. */
11161 gfc_add_full_array_ref (e
, c
->as
);
11162 e
->rank
= c
->as
->rank
;
11167 /* Build an assignment. Keep the argument 'op' for future use, so that
11168 pointer assignments can be made. */
11171 build_assignment (gfc_exec_op op
, gfc_expr
*expr1
, gfc_expr
*expr2
,
11172 gfc_component
*comp1
, gfc_component
*comp2
, locus loc
)
11174 gfc_code
*this_code
;
11176 this_code
= gfc_get_code (op
);
11177 this_code
->next
= NULL
;
11178 this_code
->expr1
= gfc_copy_expr (expr1
);
11179 this_code
->expr2
= gfc_copy_expr (expr2
);
11180 this_code
->loc
= loc
;
11181 if (comp1
&& comp2
)
11183 add_comp_ref (this_code
->expr1
, comp1
);
11184 add_comp_ref (this_code
->expr2
, comp2
);
11191 /* Makes a temporary variable expression based on the characteristics of
11192 a given variable expression. */
11195 get_temp_from_expr (gfc_expr
*e
, gfc_namespace
*ns
)
11197 static int serial
= 0;
11198 char name
[GFC_MAX_SYMBOL_LEN
];
11200 gfc_array_spec
*as
;
11201 gfc_array_ref
*aref
;
11204 sprintf (name
, GFC_PREFIX("DA%d"), serial
++);
11205 gfc_get_sym_tree (name
, ns
, &tmp
, false);
11206 gfc_add_type (tmp
->n
.sym
, &e
->ts
, NULL
);
11208 if (e
->expr_type
== EXPR_CONSTANT
&& e
->ts
.type
== BT_CHARACTER
)
11209 tmp
->n
.sym
->ts
.u
.cl
->length
= gfc_get_int_expr (gfc_charlen_int_kind
,
11211 e
->value
.character
.length
);
11217 /* Obtain the arrayspec for the temporary. */
11218 if (e
->rank
&& e
->expr_type
!= EXPR_ARRAY
11219 && e
->expr_type
!= EXPR_FUNCTION
11220 && e
->expr_type
!= EXPR_OP
)
11222 aref
= gfc_find_array_ref (e
);
11223 if (e
->expr_type
== EXPR_VARIABLE
11224 && e
->symtree
->n
.sym
->as
== aref
->as
)
11228 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
11229 if (ref
->type
== REF_COMPONENT
11230 && ref
->u
.c
.component
->as
== aref
->as
)
11238 /* Add the attributes and the arrayspec to the temporary. */
11239 tmp
->n
.sym
->attr
= gfc_expr_attr (e
);
11240 tmp
->n
.sym
->attr
.function
= 0;
11241 tmp
->n
.sym
->attr
.proc_pointer
= 0;
11242 tmp
->n
.sym
->attr
.result
= 0;
11243 tmp
->n
.sym
->attr
.flavor
= FL_VARIABLE
;
11244 tmp
->n
.sym
->attr
.dummy
= 0;
11245 tmp
->n
.sym
->attr
.use_assoc
= 0;
11246 tmp
->n
.sym
->attr
.intent
= INTENT_UNKNOWN
;
11250 tmp
->n
.sym
->as
= gfc_copy_array_spec (as
);
11253 if (as
->type
== AS_DEFERRED
)
11254 tmp
->n
.sym
->attr
.allocatable
= 1;
11256 else if (e
->rank
&& (e
->expr_type
== EXPR_ARRAY
11257 || e
->expr_type
== EXPR_FUNCTION
11258 || e
->expr_type
== EXPR_OP
))
11260 tmp
->n
.sym
->as
= gfc_get_array_spec ();
11261 tmp
->n
.sym
->as
->type
= AS_DEFERRED
;
11262 tmp
->n
.sym
->as
->rank
= e
->rank
;
11263 tmp
->n
.sym
->attr
.allocatable
= 1;
11264 tmp
->n
.sym
->attr
.dimension
= 1;
11267 tmp
->n
.sym
->attr
.dimension
= 0;
11269 gfc_set_sym_referenced (tmp
->n
.sym
);
11270 gfc_commit_symbol (tmp
->n
.sym
);
11271 e
= gfc_lval_expr_from_sym (tmp
->n
.sym
);
11273 /* Should the lhs be a section, use its array ref for the
11274 temporary expression. */
11275 if (aref
&& aref
->type
!= AR_FULL
)
11277 gfc_free_ref_list (e
->ref
);
11278 e
->ref
= gfc_copy_ref (ref
);
11284 /* Add one line of code to the code chain, making sure that 'head' and
11285 'tail' are appropriately updated. */
11288 add_code_to_chain (gfc_code
**this_code
, gfc_code
**head
, gfc_code
**tail
)
11290 gcc_assert (this_code
);
11292 *head
= *tail
= *this_code
;
11294 *tail
= gfc_append_code (*tail
, *this_code
);
11299 /* Counts the potential number of part array references that would
11300 result from resolution of typebound defined assignments. */
11303 nonscalar_typebound_assign (gfc_symbol
*derived
, int depth
)
11306 int c_depth
= 0, t_depth
;
11308 for (c
= derived
->components
; c
; c
= c
->next
)
11310 if ((!gfc_bt_struct (c
->ts
.type
)
11312 || c
->attr
.allocatable
11313 || c
->attr
.proc_pointer_comp
11314 || c
->attr
.class_pointer
11315 || c
->attr
.proc_pointer
)
11316 && !c
->attr
.defined_assign_comp
)
11319 if (c
->as
&& c_depth
== 0)
11322 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
11323 t_depth
= nonscalar_typebound_assign (c
->ts
.u
.derived
,
11328 c_depth
= t_depth
> c_depth
? t_depth
: c_depth
;
11330 return depth
+ c_depth
;
11334 /* Implement 7.2.1.3 of the F08 standard:
11335 "An intrinsic assignment where the variable is of derived type is
11336 performed as if each component of the variable were assigned from the
11337 corresponding component of expr using pointer assignment (7.2.2) for
11338 each pointer component, defined assignment for each nonpointer
11339 nonallocatable component of a type that has a type-bound defined
11340 assignment consistent with the component, intrinsic assignment for
11341 each other nonpointer nonallocatable component, ..."
11343 The pointer assignments are taken care of by the intrinsic
11344 assignment of the structure itself. This function recursively adds
11345 defined assignments where required. The recursion is accomplished
11346 by calling gfc_resolve_code.
11348 When the lhs in a defined assignment has intent INOUT, we need a
11349 temporary for the lhs. In pseudo-code:
11351 ! Only call function lhs once.
11352 if (lhs is not a constant or an variable)
11355 ! Do the intrinsic assignment
11357 ! Now do the defined assignments
11358 do over components with typebound defined assignment [%cmp]
11359 #if one component's assignment procedure is INOUT
11361 #if expr2 non-variable
11367 t1%cmp {defined=} expr2%cmp
11373 expr1%cmp {defined=} expr2%cmp
11377 /* The temporary assignments have to be put on top of the additional
11378 code to avoid the result being changed by the intrinsic assignment.
11380 static int component_assignment_level
= 0;
11381 static gfc_code
*tmp_head
= NULL
, *tmp_tail
= NULL
;
11384 generate_component_assignments (gfc_code
**code
, gfc_namespace
*ns
)
11386 gfc_component
*comp1
, *comp2
;
11387 gfc_code
*this_code
= NULL
, *head
= NULL
, *tail
= NULL
;
11389 int error_count
, depth
;
11391 gfc_get_errors (NULL
, &error_count
);
11393 /* Filter out continuing processing after an error. */
11395 || (*code
)->expr1
->ts
.type
!= BT_DERIVED
11396 || (*code
)->expr2
->ts
.type
!= BT_DERIVED
)
11399 /* TODO: Handle more than one part array reference in assignments. */
11400 depth
= nonscalar_typebound_assign ((*code
)->expr1
->ts
.u
.derived
,
11401 (*code
)->expr1
->rank
? 1 : 0);
11404 gfc_warning (0, "TODO: type-bound defined assignment(s) at %L not "
11405 "done because multiple part array references would "
11406 "occur in intermediate expressions.", &(*code
)->loc
);
11410 component_assignment_level
++;
11412 /* Create a temporary so that functions get called only once. */
11413 if ((*code
)->expr2
->expr_type
!= EXPR_VARIABLE
11414 && (*code
)->expr2
->expr_type
!= EXPR_CONSTANT
)
11416 gfc_expr
*tmp_expr
;
11418 /* Assign the rhs to the temporary. */
11419 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
11420 this_code
= build_assignment (EXEC_ASSIGN
,
11421 tmp_expr
, (*code
)->expr2
,
11422 NULL
, NULL
, (*code
)->loc
);
11423 /* Add the code and substitute the rhs expression. */
11424 add_code_to_chain (&this_code
, &tmp_head
, &tmp_tail
);
11425 gfc_free_expr ((*code
)->expr2
);
11426 (*code
)->expr2
= tmp_expr
;
11429 /* Do the intrinsic assignment. This is not needed if the lhs is one
11430 of the temporaries generated here, since the intrinsic assignment
11431 to the final result already does this. */
11432 if ((*code
)->expr1
->symtree
->n
.sym
->name
[2] != '@')
11434 this_code
= build_assignment (EXEC_ASSIGN
,
11435 (*code
)->expr1
, (*code
)->expr2
,
11436 NULL
, NULL
, (*code
)->loc
);
11437 add_code_to_chain (&this_code
, &head
, &tail
);
11440 comp1
= (*code
)->expr1
->ts
.u
.derived
->components
;
11441 comp2
= (*code
)->expr2
->ts
.u
.derived
->components
;
11444 for (; comp1
; comp1
= comp1
->next
, comp2
= comp2
->next
)
11446 bool inout
= false;
11448 /* The intrinsic assignment does the right thing for pointers
11449 of all kinds and allocatable components. */
11450 if (!gfc_bt_struct (comp1
->ts
.type
)
11451 || comp1
->attr
.pointer
11452 || comp1
->attr
.allocatable
11453 || comp1
->attr
.proc_pointer_comp
11454 || comp1
->attr
.class_pointer
11455 || comp1
->attr
.proc_pointer
)
11458 /* Make an assigment for this component. */
11459 this_code
= build_assignment (EXEC_ASSIGN
,
11460 (*code
)->expr1
, (*code
)->expr2
,
11461 comp1
, comp2
, (*code
)->loc
);
11463 /* Convert the assignment if there is a defined assignment for
11464 this type. Otherwise, using the call from gfc_resolve_code,
11465 recurse into its components. */
11466 gfc_resolve_code (this_code
, ns
);
11468 if (this_code
->op
== EXEC_ASSIGN_CALL
)
11470 gfc_formal_arglist
*dummy_args
;
11472 /* Check that there is a typebound defined assignment. If not,
11473 then this must be a module defined assignment. We cannot
11474 use the defined_assign_comp attribute here because it must
11475 be this derived type that has the defined assignment and not
11477 if (!(comp1
->ts
.u
.derived
->f2k_derived
11478 && comp1
->ts
.u
.derived
->f2k_derived
11479 ->tb_op
[INTRINSIC_ASSIGN
]))
11481 gfc_free_statements (this_code
);
11486 /* If the first argument of the subroutine has intent INOUT
11487 a temporary must be generated and used instead. */
11488 rsym
= this_code
->resolved_sym
;
11489 dummy_args
= gfc_sym_get_dummy_args (rsym
);
11491 && dummy_args
->sym
->attr
.intent
== INTENT_INOUT
)
11493 gfc_code
*temp_code
;
11496 /* Build the temporary required for the assignment and put
11497 it at the head of the generated code. */
11500 t1
= get_temp_from_expr ((*code
)->expr1
, ns
);
11501 temp_code
= build_assignment (EXEC_ASSIGN
,
11502 t1
, (*code
)->expr1
,
11503 NULL
, NULL
, (*code
)->loc
);
11505 /* For allocatable LHS, check whether it is allocated. Note
11506 that allocatable components with defined assignment are
11507 not yet support. See PR 57696. */
11508 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
)
11512 gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
11513 block
= gfc_get_code (EXEC_IF
);
11514 block
->block
= gfc_get_code (EXEC_IF
);
11515 block
->block
->expr1
11516 = gfc_build_intrinsic_call (ns
,
11517 GFC_ISYM_ALLOCATED
, "allocated",
11518 (*code
)->loc
, 1, e
);
11519 block
->block
->next
= temp_code
;
11522 add_code_to_chain (&temp_code
, &tmp_head
, &tmp_tail
);
11525 /* Replace the first actual arg with the component of the
11527 gfc_free_expr (this_code
->ext
.actual
->expr
);
11528 this_code
->ext
.actual
->expr
= gfc_copy_expr (t1
);
11529 add_comp_ref (this_code
->ext
.actual
->expr
, comp1
);
11531 /* If the LHS variable is allocatable and wasn't allocated and
11532 the temporary is allocatable, pointer assign the address of
11533 the freshly allocated LHS to the temporary. */
11534 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
11535 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
11540 cond
= gfc_get_expr ();
11541 cond
->ts
.type
= BT_LOGICAL
;
11542 cond
->ts
.kind
= gfc_default_logical_kind
;
11543 cond
->expr_type
= EXPR_OP
;
11544 cond
->where
= (*code
)->loc
;
11545 cond
->value
.op
.op
= INTRINSIC_NOT
;
11546 cond
->value
.op
.op1
= gfc_build_intrinsic_call (ns
,
11547 GFC_ISYM_ALLOCATED
, "allocated",
11548 (*code
)->loc
, 1, gfc_copy_expr (t1
));
11549 block
= gfc_get_code (EXEC_IF
);
11550 block
->block
= gfc_get_code (EXEC_IF
);
11551 block
->block
->expr1
= cond
;
11552 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
11553 t1
, (*code
)->expr1
,
11554 NULL
, NULL
, (*code
)->loc
);
11555 add_code_to_chain (&block
, &head
, &tail
);
11559 else if (this_code
->op
== EXEC_ASSIGN
&& !this_code
->next
)
11561 /* Don't add intrinsic assignments since they are already
11562 effected by the intrinsic assignment of the structure. */
11563 gfc_free_statements (this_code
);
11568 add_code_to_chain (&this_code
, &head
, &tail
);
11572 /* Transfer the value to the final result. */
11573 this_code
= build_assignment (EXEC_ASSIGN
,
11574 (*code
)->expr1
, t1
,
11575 comp1
, comp2
, (*code
)->loc
);
11576 add_code_to_chain (&this_code
, &head
, &tail
);
11580 /* Put the temporary assignments at the top of the generated code. */
11581 if (tmp_head
&& component_assignment_level
== 1)
11583 gfc_append_code (tmp_head
, head
);
11585 tmp_head
= tmp_tail
= NULL
;
11588 // If we did a pointer assignment - thus, we need to ensure that the LHS is
11589 // not accidentally deallocated. Hence, nullify t1.
11590 if (t1
&& (*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
11591 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
11597 e
= gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
11598 cond
= gfc_build_intrinsic_call (ns
, GFC_ISYM_ASSOCIATED
, "associated",
11599 (*code
)->loc
, 2, gfc_copy_expr (t1
), e
);
11600 block
= gfc_get_code (EXEC_IF
);
11601 block
->block
= gfc_get_code (EXEC_IF
);
11602 block
->block
->expr1
= cond
;
11603 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
11604 t1
, gfc_get_null_expr (&(*code
)->loc
),
11605 NULL
, NULL
, (*code
)->loc
);
11606 gfc_append_code (tail
, block
);
11610 /* Now attach the remaining code chain to the input code. Step on
11611 to the end of the new code since resolution is complete. */
11612 gcc_assert ((*code
)->op
== EXEC_ASSIGN
);
11613 tail
->next
= (*code
)->next
;
11614 /* Overwrite 'code' because this would place the intrinsic assignment
11615 before the temporary for the lhs is created. */
11616 gfc_free_expr ((*code
)->expr1
);
11617 gfc_free_expr ((*code
)->expr2
);
11623 component_assignment_level
--;
11627 /* F2008: Pointer function assignments are of the form:
11628 ptr_fcn (args) = expr
11629 This function breaks these assignments into two statements:
11630 temporary_pointer => ptr_fcn(args)
11631 temporary_pointer = expr */
11634 resolve_ptr_fcn_assign (gfc_code
**code
, gfc_namespace
*ns
)
11636 gfc_expr
*tmp_ptr_expr
;
11637 gfc_code
*this_code
;
11638 gfc_component
*comp
;
11641 if ((*code
)->expr1
->expr_type
!= EXPR_FUNCTION
)
11644 /* Even if standard does not support this feature, continue to build
11645 the two statements to avoid upsetting frontend_passes.c. */
11646 gfc_notify_std (GFC_STD_F2008
, "Pointer procedure assignment at "
11647 "%L", &(*code
)->loc
);
11649 comp
= gfc_get_proc_ptr_comp ((*code
)->expr1
);
11652 s
= comp
->ts
.interface
;
11654 s
= (*code
)->expr1
->symtree
->n
.sym
;
11656 if (s
== NULL
|| !s
->result
->attr
.pointer
)
11658 gfc_error ("The function result on the lhs of the assignment at "
11659 "%L must have the pointer attribute.",
11660 &(*code
)->expr1
->where
);
11661 (*code
)->op
= EXEC_NOP
;
11665 tmp_ptr_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
11667 /* get_temp_from_expression is set up for ordinary assignments. To that
11668 end, where array bounds are not known, arrays are made allocatable.
11669 Change the temporary to a pointer here. */
11670 tmp_ptr_expr
->symtree
->n
.sym
->attr
.pointer
= 1;
11671 tmp_ptr_expr
->symtree
->n
.sym
->attr
.allocatable
= 0;
11672 tmp_ptr_expr
->where
= (*code
)->loc
;
11674 this_code
= build_assignment (EXEC_ASSIGN
,
11675 tmp_ptr_expr
, (*code
)->expr2
,
11676 NULL
, NULL
, (*code
)->loc
);
11677 this_code
->next
= (*code
)->next
;
11678 (*code
)->next
= this_code
;
11679 (*code
)->op
= EXEC_POINTER_ASSIGN
;
11680 (*code
)->expr2
= (*code
)->expr1
;
11681 (*code
)->expr1
= tmp_ptr_expr
;
11687 /* Deferred character length assignments from an operator expression
11688 require a temporary because the character length of the lhs can
11689 change in the course of the assignment. */
11692 deferred_op_assign (gfc_code
**code
, gfc_namespace
*ns
)
11694 gfc_expr
*tmp_expr
;
11695 gfc_code
*this_code
;
11697 if (!((*code
)->expr1
->ts
.type
== BT_CHARACTER
11698 && (*code
)->expr1
->ts
.deferred
&& (*code
)->expr1
->rank
11699 && (*code
)->expr2
->expr_type
== EXPR_OP
))
11702 if (!gfc_check_dependency ((*code
)->expr1
, (*code
)->expr2
, 1))
11705 if (gfc_expr_attr ((*code
)->expr1
).pointer
)
11708 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
11709 tmp_expr
->where
= (*code
)->loc
;
11711 /* A new charlen is required to ensure that the variable string
11712 length is different to that of the original lhs. */
11713 tmp_expr
->ts
.u
.cl
= gfc_get_charlen();
11714 tmp_expr
->symtree
->n
.sym
->ts
.u
.cl
= tmp_expr
->ts
.u
.cl
;
11715 tmp_expr
->ts
.u
.cl
->next
= (*code
)->expr2
->ts
.u
.cl
->next
;
11716 (*code
)->expr2
->ts
.u
.cl
->next
= tmp_expr
->ts
.u
.cl
;
11718 tmp_expr
->symtree
->n
.sym
->ts
.deferred
= 1;
11720 this_code
= build_assignment (EXEC_ASSIGN
,
11722 gfc_copy_expr (tmp_expr
),
11723 NULL
, NULL
, (*code
)->loc
);
11725 (*code
)->expr1
= tmp_expr
;
11727 this_code
->next
= (*code
)->next
;
11728 (*code
)->next
= this_code
;
11734 /* Given a block of code, recursively resolve everything pointed to by this
11738 gfc_resolve_code (gfc_code
*code
, gfc_namespace
*ns
)
11740 int omp_workshare_save
;
11741 int forall_save
, do_concurrent_save
;
11745 frame
.prev
= cs_base
;
11749 find_reachable_labels (code
);
11751 for (; code
; code
= code
->next
)
11753 frame
.current
= code
;
11754 forall_save
= forall_flag
;
11755 do_concurrent_save
= gfc_do_concurrent_flag
;
11757 if (code
->op
== EXEC_FORALL
)
11760 gfc_resolve_forall (code
, ns
, forall_save
);
11763 else if (code
->block
)
11765 omp_workshare_save
= -1;
11768 case EXEC_OACC_PARALLEL_LOOP
:
11769 case EXEC_OACC_PARALLEL
:
11770 case EXEC_OACC_KERNELS_LOOP
:
11771 case EXEC_OACC_KERNELS
:
11772 case EXEC_OACC_SERIAL_LOOP
:
11773 case EXEC_OACC_SERIAL
:
11774 case EXEC_OACC_DATA
:
11775 case EXEC_OACC_HOST_DATA
:
11776 case EXEC_OACC_LOOP
:
11777 gfc_resolve_oacc_blocks (code
, ns
);
11779 case EXEC_OMP_PARALLEL_WORKSHARE
:
11780 omp_workshare_save
= omp_workshare_flag
;
11781 omp_workshare_flag
= 1;
11782 gfc_resolve_omp_parallel_blocks (code
, ns
);
11784 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
11785 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
11786 case EXEC_OMP_PARALLEL
:
11787 case EXEC_OMP_PARALLEL_DO
:
11788 case EXEC_OMP_PARALLEL_DO_SIMD
:
11789 case EXEC_OMP_PARALLEL_MASTER
:
11790 case EXEC_OMP_PARALLEL_MASTER_TASKLOOP
:
11791 case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
11792 case EXEC_OMP_PARALLEL_SECTIONS
:
11793 case EXEC_OMP_TARGET_PARALLEL
:
11794 case EXEC_OMP_TARGET_PARALLEL_DO
:
11795 case EXEC_OMP_TARGET_PARALLEL_DO_SIMD
:
11796 case EXEC_OMP_TARGET_TEAMS
:
11797 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
11798 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
11799 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
11800 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
11801 case EXEC_OMP_TASK
:
11802 case EXEC_OMP_TASKLOOP
:
11803 case EXEC_OMP_TASKLOOP_SIMD
:
11804 case EXEC_OMP_TEAMS
:
11805 case EXEC_OMP_TEAMS_DISTRIBUTE
:
11806 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
11807 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
11808 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
11809 omp_workshare_save
= omp_workshare_flag
;
11810 omp_workshare_flag
= 0;
11811 gfc_resolve_omp_parallel_blocks (code
, ns
);
11813 case EXEC_OMP_DISTRIBUTE
:
11814 case EXEC_OMP_DISTRIBUTE_SIMD
:
11816 case EXEC_OMP_DO_SIMD
:
11817 case EXEC_OMP_SIMD
:
11818 case EXEC_OMP_TARGET_SIMD
:
11819 gfc_resolve_omp_do_blocks (code
, ns
);
11821 case EXEC_SELECT_TYPE
:
11822 case EXEC_SELECT_RANK
:
11823 /* Blocks are handled in resolve_select_type/rank because we
11824 have to transform the SELECT TYPE into ASSOCIATE first. */
11826 case EXEC_DO_CONCURRENT
:
11827 gfc_do_concurrent_flag
= 1;
11828 gfc_resolve_blocks (code
->block
, ns
);
11829 gfc_do_concurrent_flag
= 2;
11831 case EXEC_OMP_WORKSHARE
:
11832 omp_workshare_save
= omp_workshare_flag
;
11833 omp_workshare_flag
= 1;
11836 gfc_resolve_blocks (code
->block
, ns
);
11840 if (omp_workshare_save
!= -1)
11841 omp_workshare_flag
= omp_workshare_save
;
11845 if (code
->op
!= EXEC_COMPCALL
&& code
->op
!= EXEC_CALL_PPC
)
11846 t
= gfc_resolve_expr (code
->expr1
);
11847 forall_flag
= forall_save
;
11848 gfc_do_concurrent_flag
= do_concurrent_save
;
11850 if (!gfc_resolve_expr (code
->expr2
))
11853 if (code
->op
== EXEC_ALLOCATE
11854 && !gfc_resolve_expr (code
->expr3
))
11860 case EXEC_END_BLOCK
:
11861 case EXEC_END_NESTED_BLOCK
:
11865 case EXEC_ERROR_STOP
:
11867 case EXEC_CONTINUE
:
11869 case EXEC_ASSIGN_CALL
:
11872 case EXEC_CRITICAL
:
11873 resolve_critical (code
);
11876 case EXEC_SYNC_ALL
:
11877 case EXEC_SYNC_IMAGES
:
11878 case EXEC_SYNC_MEMORY
:
11879 resolve_sync (code
);
11884 case EXEC_EVENT_POST
:
11885 case EXEC_EVENT_WAIT
:
11886 resolve_lock_unlock_event (code
);
11889 case EXEC_FAIL_IMAGE
:
11890 case EXEC_FORM_TEAM
:
11891 case EXEC_CHANGE_TEAM
:
11892 case EXEC_END_TEAM
:
11893 case EXEC_SYNC_TEAM
:
11897 /* Keep track of which entry we are up to. */
11898 current_entry_id
= code
->ext
.entry
->id
;
11902 resolve_where (code
, NULL
);
11906 if (code
->expr1
!= NULL
)
11908 if (code
->expr1
->expr_type
!= EXPR_VARIABLE
11909 || code
->expr1
->ts
.type
!= BT_INTEGER
11910 || (code
->expr1
->ref
11911 && code
->expr1
->ref
->type
== REF_ARRAY
)
11912 || code
->expr1
->symtree
== NULL
11913 || (code
->expr1
->symtree
->n
.sym
11914 && (code
->expr1
->symtree
->n
.sym
->attr
.flavor
11916 gfc_error ("ASSIGNED GOTO statement at %L requires a "
11917 "scalar INTEGER variable", &code
->expr1
->where
);
11918 else if (code
->expr1
->symtree
->n
.sym
11919 && code
->expr1
->symtree
->n
.sym
->attr
.assign
!= 1)
11920 gfc_error ("Variable %qs has not been assigned a target "
11921 "label at %L", code
->expr1
->symtree
->n
.sym
->name
,
11922 &code
->expr1
->where
);
11925 resolve_branch (code
->label1
, code
);
11929 if (code
->expr1
!= NULL
11930 && (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
))
11931 gfc_error ("Alternate RETURN statement at %L requires a SCALAR-"
11932 "INTEGER return specifier", &code
->expr1
->where
);
11935 case EXEC_INIT_ASSIGN
:
11936 case EXEC_END_PROCEDURE
:
11943 if (code
->expr1
->ts
.type
== BT_CLASS
)
11944 gfc_find_vtab (&code
->expr2
->ts
);
11946 /* Remove a GFC_ISYM_CAF_GET inserted for a coindexed variable on
11948 if (code
->expr1
->expr_type
== EXPR_FUNCTION
11949 && code
->expr1
->value
.function
.isym
11950 && code
->expr1
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
11951 remove_caf_get_intrinsic (code
->expr1
);
11953 /* If this is a pointer function in an lvalue variable context,
11954 the new code will have to be resolved afresh. This is also the
11955 case with an error, where the code is transformed into NOP to
11956 prevent ICEs downstream. */
11957 if (resolve_ptr_fcn_assign (&code
, ns
)
11958 || code
->op
== EXEC_NOP
)
11961 if (!gfc_check_vardef_context (code
->expr1
, false, false, false,
11965 if (resolve_ordinary_assign (code
, ns
))
11967 if (omp_workshare_flag
)
11969 gfc_error ("Expected intrinsic assignment in OMP WORKSHARE "
11970 "at %L", &code
->loc
);
11973 if (code
->op
== EXEC_COMPCALL
)
11979 /* Check for dependencies in deferred character length array
11980 assignments and generate a temporary, if necessary. */
11981 if (code
->op
== EXEC_ASSIGN
&& deferred_op_assign (&code
, ns
))
11984 /* F03 7.4.1.3 for non-allocatable, non-pointer components. */
11985 if (code
->op
!= EXEC_CALL
&& code
->expr1
->ts
.type
== BT_DERIVED
11986 && code
->expr1
->ts
.u
.derived
11987 && code
->expr1
->ts
.u
.derived
->attr
.defined_assign_comp
)
11988 generate_component_assignments (&code
, ns
);
11992 case EXEC_LABEL_ASSIGN
:
11993 if (code
->label1
->defined
== ST_LABEL_UNKNOWN
)
11994 gfc_error ("Label %d referenced at %L is never defined",
11995 code
->label1
->value
, &code
->label1
->where
);
11997 && (code
->expr1
->expr_type
!= EXPR_VARIABLE
11998 || code
->expr1
->symtree
->n
.sym
->ts
.type
!= BT_INTEGER
11999 || code
->expr1
->symtree
->n
.sym
->ts
.kind
12000 != gfc_default_integer_kind
12001 || code
->expr1
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
12002 || code
->expr1
->symtree
->n
.sym
->as
!= NULL
))
12003 gfc_error ("ASSIGN statement at %L requires a scalar "
12004 "default INTEGER variable", &code
->expr1
->where
);
12007 case EXEC_POINTER_ASSIGN
:
12014 /* This is both a variable definition and pointer assignment
12015 context, so check both of them. For rank remapping, a final
12016 array ref may be present on the LHS and fool gfc_expr_attr
12017 used in gfc_check_vardef_context. Remove it. */
12018 e
= remove_last_array_ref (code
->expr1
);
12019 t
= gfc_check_vardef_context (e
, true, false, false,
12020 _("pointer assignment"));
12022 t
= gfc_check_vardef_context (e
, false, false, false,
12023 _("pointer assignment"));
12026 t
= gfc_check_pointer_assign (code
->expr1
, code
->expr2
, !t
) && t
;
12031 /* Assigning a class object always is a regular assign. */
12032 if (code
->expr2
->ts
.type
== BT_CLASS
12033 && code
->expr1
->ts
.type
== BT_CLASS
12034 && CLASS_DATA (code
->expr2
)
12035 && !CLASS_DATA (code
->expr2
)->attr
.dimension
12036 && !(gfc_expr_attr (code
->expr1
).proc_pointer
12037 && code
->expr2
->expr_type
== EXPR_VARIABLE
12038 && code
->expr2
->symtree
->n
.sym
->attr
.flavor
12040 code
->op
= EXEC_ASSIGN
;
12044 case EXEC_ARITHMETIC_IF
:
12046 gfc_expr
*e
= code
->expr1
;
12048 gfc_resolve_expr (e
);
12049 if (e
->expr_type
== EXPR_NULL
)
12050 gfc_error ("Invalid NULL at %L", &e
->where
);
12052 if (t
&& (e
->rank
> 0
12053 || !(e
->ts
.type
== BT_REAL
|| e
->ts
.type
== BT_INTEGER
)))
12054 gfc_error ("Arithmetic IF statement at %L requires a scalar "
12055 "REAL or INTEGER expression", &e
->where
);
12057 resolve_branch (code
->label1
, code
);
12058 resolve_branch (code
->label2
, code
);
12059 resolve_branch (code
->label3
, code
);
12064 if (t
&& code
->expr1
!= NULL
12065 && (code
->expr1
->ts
.type
!= BT_LOGICAL
12066 || code
->expr1
->rank
!= 0))
12067 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
12068 &code
->expr1
->where
);
12073 resolve_call (code
);
12076 case EXEC_COMPCALL
:
12078 resolve_typebound_subroutine (code
);
12081 case EXEC_CALL_PPC
:
12082 resolve_ppc_call (code
);
12086 /* Select is complicated. Also, a SELECT construct could be
12087 a transformed computed GOTO. */
12088 resolve_select (code
, false);
12091 case EXEC_SELECT_TYPE
:
12092 resolve_select_type (code
, ns
);
12095 case EXEC_SELECT_RANK
:
12096 resolve_select_rank (code
, ns
);
12100 resolve_block_construct (code
);
12104 if (code
->ext
.iterator
!= NULL
)
12106 gfc_iterator
*iter
= code
->ext
.iterator
;
12107 if (gfc_resolve_iterator (iter
, true, false))
12108 gfc_resolve_do_iterator (code
, iter
->var
->symtree
->n
.sym
,
12113 case EXEC_DO_WHILE
:
12114 if (code
->expr1
== NULL
)
12115 gfc_internal_error ("gfc_resolve_code(): No expression on "
12118 && (code
->expr1
->rank
!= 0
12119 || code
->expr1
->ts
.type
!= BT_LOGICAL
))
12120 gfc_error ("Exit condition of DO WHILE loop at %L must be "
12121 "a scalar LOGICAL expression", &code
->expr1
->where
);
12124 case EXEC_ALLOCATE
:
12126 resolve_allocate_deallocate (code
, "ALLOCATE");
12130 case EXEC_DEALLOCATE
:
12132 resolve_allocate_deallocate (code
, "DEALLOCATE");
12137 if (!gfc_resolve_open (code
->ext
.open
, &code
->loc
))
12140 resolve_branch (code
->ext
.open
->err
, code
);
12144 if (!gfc_resolve_close (code
->ext
.close
, &code
->loc
))
12147 resolve_branch (code
->ext
.close
->err
, code
);
12150 case EXEC_BACKSPACE
:
12154 if (!gfc_resolve_filepos (code
->ext
.filepos
, &code
->loc
))
12157 resolve_branch (code
->ext
.filepos
->err
, code
);
12161 if (!gfc_resolve_inquire (code
->ext
.inquire
))
12164 resolve_branch (code
->ext
.inquire
->err
, code
);
12167 case EXEC_IOLENGTH
:
12168 gcc_assert (code
->ext
.inquire
!= NULL
);
12169 if (!gfc_resolve_inquire (code
->ext
.inquire
))
12172 resolve_branch (code
->ext
.inquire
->err
, code
);
12176 if (!gfc_resolve_wait (code
->ext
.wait
))
12179 resolve_branch (code
->ext
.wait
->err
, code
);
12180 resolve_branch (code
->ext
.wait
->end
, code
);
12181 resolve_branch (code
->ext
.wait
->eor
, code
);
12186 if (!gfc_resolve_dt (code
, code
->ext
.dt
, &code
->loc
))
12189 resolve_branch (code
->ext
.dt
->err
, code
);
12190 resolve_branch (code
->ext
.dt
->end
, code
);
12191 resolve_branch (code
->ext
.dt
->eor
, code
);
12194 case EXEC_TRANSFER
:
12195 resolve_transfer (code
);
12198 case EXEC_DO_CONCURRENT
:
12200 resolve_forall_iterators (code
->ext
.forall_iterator
);
12202 if (code
->expr1
!= NULL
12203 && (code
->expr1
->ts
.type
!= BT_LOGICAL
|| code
->expr1
->rank
))
12204 gfc_error ("FORALL mask clause at %L requires a scalar LOGICAL "
12205 "expression", &code
->expr1
->where
);
12208 case EXEC_OACC_PARALLEL_LOOP
:
12209 case EXEC_OACC_PARALLEL
:
12210 case EXEC_OACC_KERNELS_LOOP
:
12211 case EXEC_OACC_KERNELS
:
12212 case EXEC_OACC_SERIAL_LOOP
:
12213 case EXEC_OACC_SERIAL
:
12214 case EXEC_OACC_DATA
:
12215 case EXEC_OACC_HOST_DATA
:
12216 case EXEC_OACC_LOOP
:
12217 case EXEC_OACC_UPDATE
:
12218 case EXEC_OACC_WAIT
:
12219 case EXEC_OACC_CACHE
:
12220 case EXEC_OACC_ENTER_DATA
:
12221 case EXEC_OACC_EXIT_DATA
:
12222 case EXEC_OACC_ATOMIC
:
12223 case EXEC_OACC_DECLARE
:
12224 gfc_resolve_oacc_directive (code
, ns
);
12227 case EXEC_OMP_ATOMIC
:
12228 case EXEC_OMP_BARRIER
:
12229 case EXEC_OMP_CANCEL
:
12230 case EXEC_OMP_CANCELLATION_POINT
:
12231 case EXEC_OMP_CRITICAL
:
12232 case EXEC_OMP_FLUSH
:
12233 case EXEC_OMP_DEPOBJ
:
12234 case EXEC_OMP_DISTRIBUTE
:
12235 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
12236 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
12237 case EXEC_OMP_DISTRIBUTE_SIMD
:
12239 case EXEC_OMP_DO_SIMD
:
12240 case EXEC_OMP_LOOP
:
12241 case EXEC_OMP_MASTER
:
12242 case EXEC_OMP_MASTER_TASKLOOP
:
12243 case EXEC_OMP_MASTER_TASKLOOP_SIMD
:
12244 case EXEC_OMP_ORDERED
:
12245 case EXEC_OMP_SCAN
:
12246 case EXEC_OMP_SECTIONS
:
12247 case EXEC_OMP_SIMD
:
12248 case EXEC_OMP_SINGLE
:
12249 case EXEC_OMP_TARGET
:
12250 case EXEC_OMP_TARGET_DATA
:
12251 case EXEC_OMP_TARGET_ENTER_DATA
:
12252 case EXEC_OMP_TARGET_EXIT_DATA
:
12253 case EXEC_OMP_TARGET_PARALLEL
:
12254 case EXEC_OMP_TARGET_PARALLEL_DO
:
12255 case EXEC_OMP_TARGET_PARALLEL_DO_SIMD
:
12256 case EXEC_OMP_TARGET_PARALLEL_LOOP
:
12257 case EXEC_OMP_TARGET_SIMD
:
12258 case EXEC_OMP_TARGET_TEAMS
:
12259 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
12260 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
12261 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
12262 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
12263 case EXEC_OMP_TARGET_TEAMS_LOOP
:
12264 case EXEC_OMP_TARGET_UPDATE
:
12265 case EXEC_OMP_TASK
:
12266 case EXEC_OMP_TASKGROUP
:
12267 case EXEC_OMP_TASKLOOP
:
12268 case EXEC_OMP_TASKLOOP_SIMD
:
12269 case EXEC_OMP_TASKWAIT
:
12270 case EXEC_OMP_TASKYIELD
:
12271 case EXEC_OMP_TEAMS
:
12272 case EXEC_OMP_TEAMS_DISTRIBUTE
:
12273 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
12274 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
12275 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
12276 case EXEC_OMP_TEAMS_LOOP
:
12277 case EXEC_OMP_WORKSHARE
:
12278 gfc_resolve_omp_directive (code
, ns
);
12281 case EXEC_OMP_PARALLEL
:
12282 case EXEC_OMP_PARALLEL_DO
:
12283 case EXEC_OMP_PARALLEL_DO_SIMD
:
12284 case EXEC_OMP_PARALLEL_LOOP
:
12285 case EXEC_OMP_PARALLEL_MASTER
:
12286 case EXEC_OMP_PARALLEL_MASTER_TASKLOOP
:
12287 case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
12288 case EXEC_OMP_PARALLEL_SECTIONS
:
12289 case EXEC_OMP_PARALLEL_WORKSHARE
:
12290 omp_workshare_save
= omp_workshare_flag
;
12291 omp_workshare_flag
= 0;
12292 gfc_resolve_omp_directive (code
, ns
);
12293 omp_workshare_flag
= omp_workshare_save
;
12297 gfc_internal_error ("gfc_resolve_code(): Bad statement code");
12301 cs_base
= frame
.prev
;
12305 /* Resolve initial values and make sure they are compatible with
12309 resolve_values (gfc_symbol
*sym
)
12313 if (sym
->value
== NULL
)
12316 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_DEPRECATED
))
12317 gfc_warning (OPT_Wdeprecated_declarations
,
12318 "Using parameter %qs declared at %L is deprecated",
12319 sym
->name
, &sym
->declared_at
);
12321 if (sym
->value
->expr_type
== EXPR_STRUCTURE
)
12322 t
= resolve_structure_cons (sym
->value
, 1);
12324 t
= gfc_resolve_expr (sym
->value
);
12329 gfc_check_assign_symbol (sym
, NULL
, sym
->value
);
12333 /* Verify any BIND(C) derived types in the namespace so we can report errors
12334 for them once, rather than for each variable declared of that type. */
12337 resolve_bind_c_derived_types (gfc_symbol
*derived_sym
)
12339 if (derived_sym
!= NULL
&& derived_sym
->attr
.flavor
== FL_DERIVED
12340 && derived_sym
->attr
.is_bind_c
== 1)
12341 verify_bind_c_derived_type (derived_sym
);
12347 /* Check the interfaces of DTIO procedures associated with derived
12348 type 'sym'. These procedures can either have typebound bindings or
12349 can appear in DTIO generic interfaces. */
12352 gfc_verify_DTIO_procedures (gfc_symbol
*sym
)
12354 if (!sym
|| sym
->attr
.flavor
!= FL_DERIVED
)
12357 gfc_check_dtio_interfaces (sym
);
12362 /* Verify that any binding labels used in a given namespace do not collide
12363 with the names or binding labels of any global symbols. Multiple INTERFACE
12364 for the same procedure are permitted. */
12367 gfc_verify_binding_labels (gfc_symbol
*sym
)
12370 const char *module
;
12372 if (!sym
|| !sym
->attr
.is_bind_c
|| sym
->attr
.is_iso_c
12373 || sym
->attr
.flavor
== FL_DERIVED
|| !sym
->binding_label
)
12376 gsym
= gfc_find_case_gsymbol (gfc_gsym_root
, sym
->binding_label
);
12379 module
= sym
->module
;
12380 else if (sym
->ns
&& sym
->ns
->proc_name
12381 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
12382 module
= sym
->ns
->proc_name
->name
;
12383 else if (sym
->ns
&& sym
->ns
->parent
12384 && sym
->ns
&& sym
->ns
->parent
->proc_name
12385 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
12386 module
= sym
->ns
->parent
->proc_name
->name
;
12392 && (gsym
->type
== GSYM_FUNCTION
|| gsym
->type
== GSYM_SUBROUTINE
)))
12395 gsym
= gfc_get_gsymbol (sym
->binding_label
, true);
12396 gsym
->where
= sym
->declared_at
;
12397 gsym
->sym_name
= sym
->name
;
12398 gsym
->binding_label
= sym
->binding_label
;
12399 gsym
->ns
= sym
->ns
;
12400 gsym
->mod_name
= module
;
12401 if (sym
->attr
.function
)
12402 gsym
->type
= GSYM_FUNCTION
;
12403 else if (sym
->attr
.subroutine
)
12404 gsym
->type
= GSYM_SUBROUTINE
;
12405 /* Mark as variable/procedure as defined, unless its an INTERFACE. */
12406 gsym
->defined
= sym
->attr
.if_source
!= IFSRC_IFBODY
;
12410 if (sym
->attr
.flavor
== FL_VARIABLE
&& gsym
->type
!= GSYM_UNKNOWN
)
12412 gfc_error ("Variable %qs with binding label %qs at %L uses the same global "
12413 "identifier as entity at %L", sym
->name
,
12414 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
12415 /* Clear the binding label to prevent checking multiple times. */
12416 sym
->binding_label
= NULL
;
12420 if (sym
->attr
.flavor
== FL_VARIABLE
&& module
12421 && (strcmp (module
, gsym
->mod_name
) != 0
12422 || strcmp (sym
->name
, gsym
->sym_name
) != 0))
12424 /* This can only happen if the variable is defined in a module - if it
12425 isn't the same module, reject it. */
12426 gfc_error ("Variable %qs from module %qs with binding label %qs at %L "
12427 "uses the same global identifier as entity at %L from module %qs",
12428 sym
->name
, module
, sym
->binding_label
,
12429 &sym
->declared_at
, &gsym
->where
, gsym
->mod_name
);
12430 sym
->binding_label
= NULL
;
12434 if ((sym
->attr
.function
|| sym
->attr
.subroutine
)
12435 && ((gsym
->type
!= GSYM_SUBROUTINE
&& gsym
->type
!= GSYM_FUNCTION
)
12436 || (gsym
->defined
&& sym
->attr
.if_source
!= IFSRC_IFBODY
))
12437 && (sym
!= gsym
->ns
->proc_name
&& sym
->attr
.entry
== 0)
12438 && (module
!= gsym
->mod_name
12439 || strcmp (gsym
->sym_name
, sym
->name
) != 0
12440 || (module
&& strcmp (module
, gsym
->mod_name
) != 0)))
12442 /* Print an error if the procedure is defined multiple times; we have to
12443 exclude references to the same procedure via module association or
12444 multiple checks for the same procedure. */
12445 gfc_error ("Procedure %qs with binding label %qs at %L uses the same "
12446 "global identifier as entity at %L", sym
->name
,
12447 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
12448 sym
->binding_label
= NULL
;
12453 /* Resolve an index expression. */
12456 resolve_index_expr (gfc_expr
*e
)
12458 if (!gfc_resolve_expr (e
))
12461 if (!gfc_simplify_expr (e
, 0))
12464 if (!gfc_specification_expr (e
))
12471 /* Resolve a charlen structure. */
12474 resolve_charlen (gfc_charlen
*cl
)
12477 bool saved_specification_expr
;
12483 saved_specification_expr
= specification_expr
;
12484 specification_expr
= true;
12486 if (cl
->length_from_typespec
)
12488 if (!gfc_resolve_expr (cl
->length
))
12490 specification_expr
= saved_specification_expr
;
12494 if (!gfc_simplify_expr (cl
->length
, 0))
12496 specification_expr
= saved_specification_expr
;
12500 /* cl->length has been resolved. It should have an integer type. */
12502 && (cl
->length
->ts
.type
!= BT_INTEGER
|| cl
->length
->rank
!= 0))
12504 gfc_error ("Scalar INTEGER expression expected at %L",
12505 &cl
->length
->where
);
12511 if (!resolve_index_expr (cl
->length
))
12513 specification_expr
= saved_specification_expr
;
12518 /* F2008, 4.4.3.2: If the character length parameter value evaluates to
12519 a negative value, the length of character entities declared is zero. */
12520 if (cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
12521 && mpz_sgn (cl
->length
->value
.integer
) < 0)
12522 gfc_replace_expr (cl
->length
,
12523 gfc_get_int_expr (gfc_charlen_int_kind
, NULL
, 0));
12525 /* Check that the character length is not too large. */
12526 k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
12527 if (cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
12528 && cl
->length
->ts
.type
== BT_INTEGER
12529 && mpz_cmp (cl
->length
->value
.integer
, gfc_integer_kinds
[k
].huge
) > 0)
12531 gfc_error ("String length at %L is too large", &cl
->length
->where
);
12532 specification_expr
= saved_specification_expr
;
12536 specification_expr
= saved_specification_expr
;
12541 /* Test for non-constant shape arrays. */
12544 is_non_constant_shape_array (gfc_symbol
*sym
)
12550 not_constant
= false;
12551 if (sym
->as
!= NULL
)
12553 /* Unfortunately, !gfc_is_compile_time_shape hits a legal case that
12554 has not been simplified; parameter array references. Do the
12555 simplification now. */
12556 for (i
= 0; i
< sym
->as
->rank
+ sym
->as
->corank
; i
++)
12558 if (i
== GFC_MAX_DIMENSIONS
)
12561 e
= sym
->as
->lower
[i
];
12562 if (e
&& (!resolve_index_expr(e
)
12563 || !gfc_is_constant_expr (e
)))
12564 not_constant
= true;
12565 e
= sym
->as
->upper
[i
];
12566 if (e
&& (!resolve_index_expr(e
)
12567 || !gfc_is_constant_expr (e
)))
12568 not_constant
= true;
12571 return not_constant
;
12574 /* Given a symbol and an initialization expression, add code to initialize
12575 the symbol to the function entry. */
12577 build_init_assign (gfc_symbol
*sym
, gfc_expr
*init
)
12581 gfc_namespace
*ns
= sym
->ns
;
12583 /* Search for the function namespace if this is a contained
12584 function without an explicit result. */
12585 if (sym
->attr
.function
&& sym
== sym
->result
12586 && sym
->name
!= sym
->ns
->proc_name
->name
)
12588 ns
= ns
->contained
;
12589 for (;ns
; ns
= ns
->sibling
)
12590 if (strcmp (ns
->proc_name
->name
, sym
->name
) == 0)
12596 gfc_free_expr (init
);
12600 /* Build an l-value expression for the result. */
12601 lval
= gfc_lval_expr_from_sym (sym
);
12603 /* Add the code at scope entry. */
12604 init_st
= gfc_get_code (EXEC_INIT_ASSIGN
);
12605 init_st
->next
= ns
->code
;
12606 ns
->code
= init_st
;
12608 /* Assign the default initializer to the l-value. */
12609 init_st
->loc
= sym
->declared_at
;
12610 init_st
->expr1
= lval
;
12611 init_st
->expr2
= init
;
12615 /* Whether or not we can generate a default initializer for a symbol. */
12618 can_generate_init (gfc_symbol
*sym
)
12620 symbol_attribute
*a
;
12625 /* These symbols should never have a default initialization. */
12630 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
12631 && (CLASS_DATA (sym
)->attr
.class_pointer
12632 || CLASS_DATA (sym
)->attr
.proc_pointer
))
12633 || a
->in_equivalence
12640 || (!a
->referenced
&& !a
->result
)
12641 || (a
->dummy
&& a
->intent
!= INTENT_OUT
)
12642 || (a
->function
&& sym
!= sym
->result
)
12647 /* Assign the default initializer to a derived type variable or result. */
12650 apply_default_init (gfc_symbol
*sym
)
12652 gfc_expr
*init
= NULL
;
12654 if (sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
12657 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
)
12658 init
= gfc_generate_initializer (&sym
->ts
, can_generate_init (sym
));
12660 if (init
== NULL
&& sym
->ts
.type
!= BT_CLASS
)
12663 build_init_assign (sym
, init
);
12664 sym
->attr
.referenced
= 1;
12668 /* Build an initializer for a local. Returns null if the symbol should not have
12669 a default initialization. */
12672 build_default_init_expr (gfc_symbol
*sym
)
12674 /* These symbols should never have a default initialization. */
12675 if (sym
->attr
.allocatable
12676 || sym
->attr
.external
12678 || sym
->attr
.pointer
12679 || sym
->attr
.in_equivalence
12680 || sym
->attr
.in_common
12683 || sym
->attr
.cray_pointee
12684 || sym
->attr
.cray_pointer
12688 /* Get the appropriate init expression. */
12689 return gfc_build_default_init_expr (&sym
->ts
, &sym
->declared_at
);
12692 /* Add an initialization expression to a local variable. */
12694 apply_default_init_local (gfc_symbol
*sym
)
12696 gfc_expr
*init
= NULL
;
12698 /* The symbol should be a variable or a function return value. */
12699 if ((sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
12700 || (sym
->attr
.function
&& sym
->result
!= sym
))
12703 /* Try to build the initializer expression. If we can't initialize
12704 this symbol, then init will be NULL. */
12705 init
= build_default_init_expr (sym
);
12709 /* For saved variables, we don't want to add an initializer at function
12710 entry, so we just add a static initializer. Note that automatic variables
12711 are stack allocated even with -fno-automatic; we have also to exclude
12712 result variable, which are also nonstatic. */
12713 if (!sym
->attr
.automatic
12714 && (sym
->attr
.save
|| sym
->ns
->save_all
12715 || (flag_max_stack_var_size
== 0 && !sym
->attr
.result
12716 && (sym
->ns
->proc_name
&& !sym
->ns
->proc_name
->attr
.recursive
)
12717 && (!sym
->attr
.dimension
|| !is_non_constant_shape_array (sym
)))))
12719 /* Don't clobber an existing initializer! */
12720 gcc_assert (sym
->value
== NULL
);
12725 build_init_assign (sym
, init
);
12729 /* Resolution of common features of flavors variable and procedure. */
12732 resolve_fl_var_and_proc (gfc_symbol
*sym
, int mp_flag
)
12734 gfc_array_spec
*as
;
12736 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
12737 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
))
12738 as
= CLASS_DATA (sym
)->as
;
12742 /* Constraints on deferred shape variable. */
12743 if (as
== NULL
|| as
->type
!= AS_DEFERRED
)
12745 bool pointer
, allocatable
, dimension
;
12747 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
12748 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
))
12750 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
12751 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
12752 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
12756 pointer
= sym
->attr
.pointer
&& !sym
->attr
.select_type_temporary
;
12757 allocatable
= sym
->attr
.allocatable
;
12758 dimension
= sym
->attr
.dimension
;
12763 if (dimension
&& as
->type
!= AS_ASSUMED_RANK
)
12765 gfc_error ("Allocatable array %qs at %L must have a deferred "
12766 "shape or assumed rank", sym
->name
, &sym
->declared_at
);
12769 else if (!gfc_notify_std (GFC_STD_F2003
, "Scalar object "
12770 "%qs at %L may not be ALLOCATABLE",
12771 sym
->name
, &sym
->declared_at
))
12775 if (pointer
&& dimension
&& as
->type
!= AS_ASSUMED_RANK
)
12777 gfc_error ("Array pointer %qs at %L must have a deferred shape or "
12778 "assumed rank", sym
->name
, &sym
->declared_at
);
12785 if (!mp_flag
&& !sym
->attr
.allocatable
&& !sym
->attr
.pointer
12786 && sym
->ts
.type
!= BT_CLASS
&& !sym
->assoc
)
12788 gfc_error ("Array %qs at %L cannot have a deferred shape",
12789 sym
->name
, &sym
->declared_at
);
12794 /* Constraints on polymorphic variables. */
12795 if (sym
->ts
.type
== BT_CLASS
&& !(sym
->result
&& sym
->result
!= sym
))
12798 if (sym
->attr
.class_ok
12799 && sym
->ts
.u
.derived
12800 && !sym
->attr
.select_type_temporary
12801 && !UNLIMITED_POLY (sym
)
12802 && !gfc_type_is_extensible (CLASS_DATA (sym
)->ts
.u
.derived
))
12804 gfc_error ("Type %qs of CLASS variable %qs at %L is not extensible",
12805 CLASS_DATA (sym
)->ts
.u
.derived
->name
, sym
->name
,
12806 &sym
->declared_at
);
12811 /* Assume that use associated symbols were checked in the module ns.
12812 Class-variables that are associate-names are also something special
12813 and excepted from the test. */
12814 if (!sym
->attr
.class_ok
&& !sym
->attr
.use_assoc
&& !sym
->assoc
)
12816 gfc_error ("CLASS variable %qs at %L must be dummy, allocatable "
12817 "or pointer", sym
->name
, &sym
->declared_at
);
12826 /* Additional checks for symbols with flavor variable and derived
12827 type. To be called from resolve_fl_variable. */
12830 resolve_fl_variable_derived (gfc_symbol
*sym
, int no_init_flag
)
12832 gcc_assert (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
);
12834 /* Check to see if a derived type is blocked from being host
12835 associated by the presence of another class I symbol in the same
12836 namespace. 14.6.1.3 of the standard and the discussion on
12837 comp.lang.fortran. */
12838 if (sym
->ts
.u
.derived
12839 && sym
->ns
!= sym
->ts
.u
.derived
->ns
12840 && !sym
->ts
.u
.derived
->attr
.use_assoc
12841 && sym
->ns
->proc_name
->attr
.if_source
!= IFSRC_IFBODY
)
12844 gfc_find_symbol (sym
->ts
.u
.derived
->name
, sym
->ns
, 0, &s
);
12845 if (s
&& s
->attr
.generic
)
12846 s
= gfc_find_dt_in_generic (s
);
12847 if (s
&& !gfc_fl_struct (s
->attr
.flavor
))
12849 gfc_error ("The type %qs cannot be host associated at %L "
12850 "because it is blocked by an incompatible object "
12851 "of the same name declared at %L",
12852 sym
->ts
.u
.derived
->name
, &sym
->declared_at
,
12858 /* 4th constraint in section 11.3: "If an object of a type for which
12859 component-initialization is specified (R429) appears in the
12860 specification-part of a module and does not have the ALLOCATABLE
12861 or POINTER attribute, the object shall have the SAVE attribute."
12863 The check for initializers is performed with
12864 gfc_has_default_initializer because gfc_default_initializer generates
12865 a hidden default for allocatable components. */
12866 if (!(sym
->value
|| no_init_flag
) && sym
->ns
->proc_name
12867 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
12868 && !(sym
->ns
->save_all
&& !sym
->attr
.automatic
) && !sym
->attr
.save
12869 && !sym
->attr
.pointer
&& !sym
->attr
.allocatable
12870 && gfc_has_default_initializer (sym
->ts
.u
.derived
)
12871 && !gfc_notify_std (GFC_STD_F2008
, "Implied SAVE for module variable "
12872 "%qs at %L, needed due to the default "
12873 "initialization", sym
->name
, &sym
->declared_at
))
12876 /* Assign default initializer. */
12877 if (!(sym
->value
|| sym
->attr
.pointer
|| sym
->attr
.allocatable
)
12878 && (!no_init_flag
|| sym
->attr
.intent
== INTENT_OUT
))
12879 sym
->value
= gfc_generate_initializer (&sym
->ts
, can_generate_init (sym
));
12885 /* F2008, C402 (R401): A colon shall not be used as a type-param-value
12886 except in the declaration of an entity or component that has the POINTER
12887 or ALLOCATABLE attribute. */
12890 deferred_requirements (gfc_symbol
*sym
)
12892 if (sym
->ts
.deferred
12893 && !(sym
->attr
.pointer
12894 || sym
->attr
.allocatable
12895 || sym
->attr
.associate_var
12896 || sym
->attr
.omp_udr_artificial_var
))
12898 /* If a function has a result variable, only check the variable. */
12899 if (sym
->result
&& sym
->name
!= sym
->result
->name
)
12902 gfc_error ("Entity %qs at %L has a deferred type parameter and "
12903 "requires either the POINTER or ALLOCATABLE attribute",
12904 sym
->name
, &sym
->declared_at
);
12911 /* Resolve symbols with flavor variable. */
12914 resolve_fl_variable (gfc_symbol
*sym
, int mp_flag
)
12916 const char *auto_save_msg
= "Automatic object %qs at %L cannot have the "
12919 if (!resolve_fl_var_and_proc (sym
, mp_flag
))
12922 /* Set this flag to check that variables are parameters of all entries.
12923 This check is effected by the call to gfc_resolve_expr through
12924 is_non_constant_shape_array. */
12925 bool saved_specification_expr
= specification_expr
;
12926 specification_expr
= true;
12928 if (sym
->ns
->proc_name
12929 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
12930 || sym
->ns
->proc_name
->attr
.is_main_program
)
12931 && !sym
->attr
.use_assoc
12932 && !sym
->attr
.allocatable
12933 && !sym
->attr
.pointer
12934 && is_non_constant_shape_array (sym
))
12936 /* F08:C541. The shape of an array defined in a main program or module
12937 * needs to be constant. */
12938 gfc_error ("The module or main program array %qs at %L must "
12939 "have constant shape", sym
->name
, &sym
->declared_at
);
12940 specification_expr
= saved_specification_expr
;
12944 /* Constraints on deferred type parameter. */
12945 if (!deferred_requirements (sym
))
12948 if (sym
->ts
.type
== BT_CHARACTER
&& !sym
->attr
.associate_var
)
12950 /* Make sure that character string variables with assumed length are
12951 dummy arguments. */
12952 gfc_expr
*e
= NULL
;
12955 e
= sym
->ts
.u
.cl
->length
;
12959 if (e
== NULL
&& !sym
->attr
.dummy
&& !sym
->attr
.result
12960 && !sym
->ts
.deferred
&& !sym
->attr
.select_type_temporary
12961 && !sym
->attr
.omp_udr_artificial_var
)
12963 gfc_error ("Entity with assumed character length at %L must be a "
12964 "dummy argument or a PARAMETER", &sym
->declared_at
);
12965 specification_expr
= saved_specification_expr
;
12969 if (e
&& sym
->attr
.save
== SAVE_EXPLICIT
&& !gfc_is_constant_expr (e
))
12971 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
12972 specification_expr
= saved_specification_expr
;
12976 if (!gfc_is_constant_expr (e
)
12977 && !(e
->expr_type
== EXPR_VARIABLE
12978 && e
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
))
12980 if (!sym
->attr
.use_assoc
&& sym
->ns
->proc_name
12981 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
12982 || sym
->ns
->proc_name
->attr
.is_main_program
))
12984 gfc_error ("%qs at %L must have constant character length "
12985 "in this context", sym
->name
, &sym
->declared_at
);
12986 specification_expr
= saved_specification_expr
;
12989 if (sym
->attr
.in_common
)
12991 gfc_error ("COMMON variable %qs at %L must have constant "
12992 "character length", sym
->name
, &sym
->declared_at
);
12993 specification_expr
= saved_specification_expr
;
12999 if (sym
->value
== NULL
&& sym
->attr
.referenced
)
13000 apply_default_init_local (sym
); /* Try to apply a default initialization. */
13002 /* Determine if the symbol may not have an initializer. */
13003 int no_init_flag
= 0, automatic_flag
= 0;
13004 if (sym
->attr
.allocatable
|| sym
->attr
.external
|| sym
->attr
.dummy
13005 || sym
->attr
.intrinsic
|| sym
->attr
.result
)
13007 else if ((sym
->attr
.dimension
|| sym
->attr
.codimension
) && !sym
->attr
.pointer
13008 && is_non_constant_shape_array (sym
))
13010 no_init_flag
= automatic_flag
= 1;
13012 /* Also, they must not have the SAVE attribute.
13013 SAVE_IMPLICIT is checked below. */
13014 if (sym
->as
&& sym
->attr
.codimension
)
13016 int corank
= sym
->as
->corank
;
13017 sym
->as
->corank
= 0;
13018 no_init_flag
= automatic_flag
= is_non_constant_shape_array (sym
);
13019 sym
->as
->corank
= corank
;
13021 if (automatic_flag
&& sym
->attr
.save
== SAVE_EXPLICIT
)
13023 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
13024 specification_expr
= saved_specification_expr
;
13029 /* Ensure that any initializer is simplified. */
13031 gfc_simplify_expr (sym
->value
, 1);
13033 /* Reject illegal initializers. */
13034 if (!sym
->mark
&& sym
->value
)
13036 if (sym
->attr
.allocatable
|| (sym
->ts
.type
== BT_CLASS
13037 && CLASS_DATA (sym
)->attr
.allocatable
))
13038 gfc_error ("Allocatable %qs at %L cannot have an initializer",
13039 sym
->name
, &sym
->declared_at
);
13040 else if (sym
->attr
.external
)
13041 gfc_error ("External %qs at %L cannot have an initializer",
13042 sym
->name
, &sym
->declared_at
);
13043 else if (sym
->attr
.dummy
)
13044 gfc_error ("Dummy %qs at %L cannot have an initializer",
13045 sym
->name
, &sym
->declared_at
);
13046 else if (sym
->attr
.intrinsic
)
13047 gfc_error ("Intrinsic %qs at %L cannot have an initializer",
13048 sym
->name
, &sym
->declared_at
);
13049 else if (sym
->attr
.result
)
13050 gfc_error ("Function result %qs at %L cannot have an initializer",
13051 sym
->name
, &sym
->declared_at
);
13052 else if (automatic_flag
)
13053 gfc_error ("Automatic array %qs at %L cannot have an initializer",
13054 sym
->name
, &sym
->declared_at
);
13056 goto no_init_error
;
13057 specification_expr
= saved_specification_expr
;
13062 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
13064 bool res
= resolve_fl_variable_derived (sym
, no_init_flag
);
13065 specification_expr
= saved_specification_expr
;
13069 specification_expr
= saved_specification_expr
;
13074 /* Compare the dummy characteristics of a module procedure interface
13075 declaration with the corresponding declaration in a submodule. */
13076 static gfc_formal_arglist
*new_formal
;
13077 static char errmsg
[200];
13080 compare_fsyms (gfc_symbol
*sym
)
13084 if (sym
== NULL
|| new_formal
== NULL
)
13087 fsym
= new_formal
->sym
;
13092 if (strcmp (sym
->name
, fsym
->name
) == 0)
13094 if (!gfc_check_dummy_characteristics (fsym
, sym
, true, errmsg
, 200))
13095 gfc_error ("%s at %L", errmsg
, &fsym
->declared_at
);
13100 /* Resolve a procedure. */
13103 resolve_fl_procedure (gfc_symbol
*sym
, int mp_flag
)
13105 gfc_formal_arglist
*arg
;
13106 bool allocatable_or_pointer
;
13108 if (sym
->attr
.function
13109 && !resolve_fl_var_and_proc (sym
, mp_flag
))
13112 /* Constraints on deferred type parameter. */
13113 if (!deferred_requirements (sym
))
13116 if (sym
->ts
.type
== BT_CHARACTER
)
13118 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
13120 if (cl
&& cl
->length
&& gfc_is_constant_expr (cl
->length
)
13121 && !resolve_charlen (cl
))
13124 if ((!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
13125 && sym
->attr
.proc
== PROC_ST_FUNCTION
)
13127 gfc_error ("Character-valued statement function %qs at %L must "
13128 "have constant length", sym
->name
, &sym
->declared_at
);
13133 /* Ensure that derived type for are not of a private type. Internal
13134 module procedures are excluded by 2.2.3.3 - i.e., they are not
13135 externally accessible and can access all the objects accessible in
13137 if (!(sym
->ns
->parent
&& sym
->ns
->parent
->proc_name
13138 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
13139 && gfc_check_symbol_access (sym
))
13141 gfc_interface
*iface
;
13143 for (arg
= gfc_sym_get_dummy_args (sym
); arg
; arg
= arg
->next
)
13146 && arg
->sym
->ts
.type
== BT_DERIVED
13147 && arg
->sym
->ts
.u
.derived
13148 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
13149 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
13150 && !gfc_notify_std (GFC_STD_F2003
, "%qs is of a PRIVATE type "
13151 "and cannot be a dummy argument"
13152 " of %qs, which is PUBLIC at %L",
13153 arg
->sym
->name
, sym
->name
,
13154 &sym
->declared_at
))
13156 /* Stop this message from recurring. */
13157 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
13162 /* PUBLIC interfaces may expose PRIVATE procedures that take types
13163 PRIVATE to the containing module. */
13164 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
13166 for (arg
= gfc_sym_get_dummy_args (iface
->sym
); arg
; arg
= arg
->next
)
13169 && arg
->sym
->ts
.type
== BT_DERIVED
13170 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
13171 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
13172 && !gfc_notify_std (GFC_STD_F2003
, "Procedure %qs in "
13173 "PUBLIC interface %qs at %L "
13174 "takes dummy arguments of %qs which "
13175 "is PRIVATE", iface
->sym
->name
,
13176 sym
->name
, &iface
->sym
->declared_at
,
13177 gfc_typename(&arg
->sym
->ts
)))
13179 /* Stop this message from recurring. */
13180 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
13187 if (sym
->attr
.function
&& sym
->value
&& sym
->attr
.proc
!= PROC_ST_FUNCTION
13188 && !sym
->attr
.proc_pointer
)
13190 gfc_error ("Function %qs at %L cannot have an initializer",
13191 sym
->name
, &sym
->declared_at
);
13193 /* Make sure no second error is issued for this. */
13194 sym
->value
->error
= 1;
13198 /* An external symbol may not have an initializer because it is taken to be
13199 a procedure. Exception: Procedure Pointers. */
13200 if (sym
->attr
.external
&& sym
->value
&& !sym
->attr
.proc_pointer
)
13202 gfc_error ("External object %qs at %L may not have an initializer",
13203 sym
->name
, &sym
->declared_at
);
13207 /* An elemental function is required to return a scalar 12.7.1 */
13208 if (sym
->attr
.elemental
&& sym
->attr
.function
13209 && (sym
->as
|| (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->as
)))
13211 gfc_error ("ELEMENTAL function %qs at %L must have a scalar "
13212 "result", sym
->name
, &sym
->declared_at
);
13213 /* Reset so that the error only occurs once. */
13214 sym
->attr
.elemental
= 0;
13218 if (sym
->attr
.proc
== PROC_ST_FUNCTION
13219 && (sym
->attr
.allocatable
|| sym
->attr
.pointer
))
13221 gfc_error ("Statement function %qs at %L may not have pointer or "
13222 "allocatable attribute", sym
->name
, &sym
->declared_at
);
13226 /* 5.1.1.5 of the Standard: A function name declared with an asterisk
13227 char-len-param shall not be array-valued, pointer-valued, recursive
13228 or pure. ....snip... A character value of * may only be used in the
13229 following ways: (i) Dummy arg of procedure - dummy associates with
13230 actual length; (ii) To declare a named constant; or (iii) External
13231 function - but length must be declared in calling scoping unit. */
13232 if (sym
->attr
.function
13233 && sym
->ts
.type
== BT_CHARACTER
&& !sym
->ts
.deferred
13234 && sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
== NULL
)
13236 if ((sym
->as
&& sym
->as
->rank
) || (sym
->attr
.pointer
)
13237 || (sym
->attr
.recursive
) || (sym
->attr
.pure
))
13239 if (sym
->as
&& sym
->as
->rank
)
13240 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
13241 "array-valued", sym
->name
, &sym
->declared_at
);
13243 if (sym
->attr
.pointer
)
13244 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
13245 "pointer-valued", sym
->name
, &sym
->declared_at
);
13247 if (sym
->attr
.pure
)
13248 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
13249 "pure", sym
->name
, &sym
->declared_at
);
13251 if (sym
->attr
.recursive
)
13252 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
13253 "recursive", sym
->name
, &sym
->declared_at
);
13258 /* Appendix B.2 of the standard. Contained functions give an
13259 error anyway. Deferred character length is an F2003 feature.
13260 Don't warn on intrinsic conversion functions, which start
13261 with two underscores. */
13262 if (!sym
->attr
.contained
&& !sym
->ts
.deferred
13263 && (sym
->name
[0] != '_' || sym
->name
[1] != '_'))
13264 gfc_notify_std (GFC_STD_F95_OBS
,
13265 "CHARACTER(*) function %qs at %L",
13266 sym
->name
, &sym
->declared_at
);
13269 /* F2008, C1218. */
13270 if (sym
->attr
.elemental
)
13272 if (sym
->attr
.proc_pointer
)
13274 const char* name
= (sym
->attr
.result
? sym
->ns
->proc_name
->name
13276 gfc_error ("Procedure pointer %qs at %L shall not be elemental",
13277 name
, &sym
->declared_at
);
13280 if (sym
->attr
.dummy
)
13282 gfc_error ("Dummy procedure %qs at %L shall not be elemental",
13283 sym
->name
, &sym
->declared_at
);
13288 /* F2018, C15100: "The result of an elemental function shall be scalar,
13289 and shall not have the POINTER or ALLOCATABLE attribute." The scalar
13290 pointer is tested and caught elsewhere. */
13292 allocatable_or_pointer
= sym
->result
->ts
.type
== BT_CLASS
13293 && CLASS_DATA (sym
->result
) ?
13294 (CLASS_DATA (sym
->result
)->attr
.allocatable
13295 || CLASS_DATA (sym
->result
)->attr
.pointer
) :
13296 (sym
->result
->attr
.allocatable
13297 || sym
->result
->attr
.pointer
);
13299 if (sym
->attr
.elemental
&& sym
->result
13300 && allocatable_or_pointer
)
13302 gfc_error ("Function result variable %qs at %L of elemental "
13303 "function %qs shall not have an ALLOCATABLE or POINTER "
13304 "attribute", sym
->result
->name
,
13305 &sym
->result
->declared_at
, sym
->name
);
13309 if (sym
->attr
.is_bind_c
&& sym
->attr
.is_c_interop
!= 1)
13311 gfc_formal_arglist
*curr_arg
;
13312 int has_non_interop_arg
= 0;
13314 if (!verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
13315 sym
->common_block
))
13317 /* Clear these to prevent looking at them again if there was an
13319 sym
->attr
.is_bind_c
= 0;
13320 sym
->attr
.is_c_interop
= 0;
13321 sym
->ts
.is_c_interop
= 0;
13325 /* So far, no errors have been found. */
13326 sym
->attr
.is_c_interop
= 1;
13327 sym
->ts
.is_c_interop
= 1;
13330 curr_arg
= gfc_sym_get_dummy_args (sym
);
13331 while (curr_arg
!= NULL
)
13333 /* Skip implicitly typed dummy args here. */
13334 if (curr_arg
->sym
&& curr_arg
->sym
->attr
.implicit_type
== 0)
13335 if (!gfc_verify_c_interop_param (curr_arg
->sym
))
13336 /* If something is found to fail, record the fact so we
13337 can mark the symbol for the procedure as not being
13338 BIND(C) to try and prevent multiple errors being
13340 has_non_interop_arg
= 1;
13342 curr_arg
= curr_arg
->next
;
13345 /* See if any of the arguments were not interoperable and if so, clear
13346 the procedure symbol to prevent duplicate error messages. */
13347 if (has_non_interop_arg
!= 0)
13349 sym
->attr
.is_c_interop
= 0;
13350 sym
->ts
.is_c_interop
= 0;
13351 sym
->attr
.is_bind_c
= 0;
13355 if (!sym
->attr
.proc_pointer
)
13357 if (sym
->attr
.save
== SAVE_EXPLICIT
)
13359 gfc_error ("PROCEDURE attribute conflicts with SAVE attribute "
13360 "in %qs at %L", sym
->name
, &sym
->declared_at
);
13363 if (sym
->attr
.intent
)
13365 gfc_error ("PROCEDURE attribute conflicts with INTENT attribute "
13366 "in %qs at %L", sym
->name
, &sym
->declared_at
);
13369 if (sym
->attr
.subroutine
&& sym
->attr
.result
)
13371 gfc_error ("PROCEDURE attribute conflicts with RESULT attribute "
13372 "in %qs at %L", sym
->ns
->proc_name
->name
, &sym
->declared_at
);
13375 if (sym
->attr
.external
&& sym
->attr
.function
&& !sym
->attr
.module_procedure
13376 && ((sym
->attr
.if_source
== IFSRC_DECL
&& !sym
->attr
.procedure
)
13377 || sym
->attr
.contained
))
13379 gfc_error ("EXTERNAL attribute conflicts with FUNCTION attribute "
13380 "in %qs at %L", sym
->name
, &sym
->declared_at
);
13383 if (strcmp ("ppr@", sym
->name
) == 0)
13385 gfc_error ("Procedure pointer result %qs at %L "
13386 "is missing the pointer attribute",
13387 sym
->ns
->proc_name
->name
, &sym
->declared_at
);
13392 /* Assume that a procedure whose body is not known has references
13393 to external arrays. */
13394 if (sym
->attr
.if_source
!= IFSRC_DECL
)
13395 sym
->attr
.array_outer_dependency
= 1;
13397 /* Compare the characteristics of a module procedure with the
13398 interface declaration. Ideally this would be done with
13399 gfc_compare_interfaces but, at present, the formal interface
13400 cannot be copied to the ts.interface. */
13401 if (sym
->attr
.module_procedure
13402 && sym
->attr
.if_source
== IFSRC_DECL
)
13405 char name
[2*GFC_MAX_SYMBOL_LEN
+ 1];
13407 char *submodule_name
;
13408 strcpy (name
, sym
->ns
->proc_name
->name
);
13409 module_name
= strtok (name
, ".");
13410 submodule_name
= strtok (NULL
, ".");
13412 iface
= sym
->tlink
;
13415 /* Make sure that the result uses the correct charlen for deferred
13417 if (iface
&& sym
->result
13418 && iface
->ts
.type
== BT_CHARACTER
13419 && iface
->ts
.deferred
)
13420 sym
->result
->ts
.u
.cl
= iface
->ts
.u
.cl
;
13425 /* Check the procedure characteristics. */
13426 if (sym
->attr
.elemental
!= iface
->attr
.elemental
)
13428 gfc_error ("Mismatch in ELEMENTAL attribute between MODULE "
13429 "PROCEDURE at %L and its interface in %s",
13430 &sym
->declared_at
, module_name
);
13434 if (sym
->attr
.pure
!= iface
->attr
.pure
)
13436 gfc_error ("Mismatch in PURE attribute between MODULE "
13437 "PROCEDURE at %L and its interface in %s",
13438 &sym
->declared_at
, module_name
);
13442 if (sym
->attr
.recursive
!= iface
->attr
.recursive
)
13444 gfc_error ("Mismatch in RECURSIVE attribute between MODULE "
13445 "PROCEDURE at %L and its interface in %s",
13446 &sym
->declared_at
, module_name
);
13450 /* Check the result characteristics. */
13451 if (!gfc_check_result_characteristics (sym
, iface
, errmsg
, 200))
13453 gfc_error ("%s between the MODULE PROCEDURE declaration "
13454 "in MODULE %qs and the declaration at %L in "
13456 errmsg
, module_name
, &sym
->declared_at
,
13457 submodule_name
? submodule_name
: module_name
);
13462 /* Check the characteristics of the formal arguments. */
13463 if (sym
->formal
&& sym
->formal_ns
)
13465 for (arg
= sym
->formal
; arg
&& arg
->sym
; arg
= arg
->next
)
13468 gfc_traverse_ns (sym
->formal_ns
, compare_fsyms
);
13476 /* Resolve a list of finalizer procedures. That is, after they have hopefully
13477 been defined and we now know their defined arguments, check that they fulfill
13478 the requirements of the standard for procedures used as finalizers. */
13481 gfc_resolve_finalizers (gfc_symbol
* derived
, bool *finalizable
)
13483 gfc_finalizer
* list
;
13484 gfc_finalizer
** prev_link
; /* For removing wrong entries from the list. */
13485 bool result
= true;
13486 bool seen_scalar
= false;
13489 gfc_symbol
*parent
= gfc_get_derived_super_type (derived
);
13492 gfc_resolve_finalizers (parent
, finalizable
);
13494 /* Ensure that derived-type components have a their finalizers resolved. */
13495 bool has_final
= derived
->f2k_derived
&& derived
->f2k_derived
->finalizers
;
13496 for (c
= derived
->components
; c
; c
= c
->next
)
13497 if (c
->ts
.type
== BT_DERIVED
13498 && !c
->attr
.pointer
&& !c
->attr
.proc_pointer
&& !c
->attr
.allocatable
)
13500 bool has_final2
= false;
13501 if (!gfc_resolve_finalizers (c
->ts
.u
.derived
, &has_final2
))
13502 return false; /* Error. */
13503 has_final
= has_final
|| has_final2
;
13505 /* Return early if not finalizable. */
13509 *finalizable
= false;
13513 /* Walk over the list of finalizer-procedures, check them, and if any one
13514 does not fit in with the standard's definition, print an error and remove
13515 it from the list. */
13516 prev_link
= &derived
->f2k_derived
->finalizers
;
13517 for (list
= derived
->f2k_derived
->finalizers
; list
; list
= *prev_link
)
13519 gfc_formal_arglist
*dummy_args
;
13524 /* Skip this finalizer if we already resolved it. */
13525 if (list
->proc_tree
)
13527 if (list
->proc_tree
->n
.sym
->formal
->sym
->as
== NULL
13528 || list
->proc_tree
->n
.sym
->formal
->sym
->as
->rank
== 0)
13529 seen_scalar
= true;
13530 prev_link
= &(list
->next
);
13534 /* Check this exists and is a SUBROUTINE. */
13535 if (!list
->proc_sym
->attr
.subroutine
)
13537 gfc_error ("FINAL procedure %qs at %L is not a SUBROUTINE",
13538 list
->proc_sym
->name
, &list
->where
);
13542 /* We should have exactly one argument. */
13543 dummy_args
= gfc_sym_get_dummy_args (list
->proc_sym
);
13544 if (!dummy_args
|| dummy_args
->next
)
13546 gfc_error ("FINAL procedure at %L must have exactly one argument",
13550 arg
= dummy_args
->sym
;
13552 /* This argument must be of our type. */
13553 if (arg
->ts
.type
!= BT_DERIVED
|| arg
->ts
.u
.derived
!= derived
)
13555 gfc_error ("Argument of FINAL procedure at %L must be of type %qs",
13556 &arg
->declared_at
, derived
->name
);
13560 /* It must neither be a pointer nor allocatable nor optional. */
13561 if (arg
->attr
.pointer
)
13563 gfc_error ("Argument of FINAL procedure at %L must not be a POINTER",
13564 &arg
->declared_at
);
13567 if (arg
->attr
.allocatable
)
13569 gfc_error ("Argument of FINAL procedure at %L must not be"
13570 " ALLOCATABLE", &arg
->declared_at
);
13573 if (arg
->attr
.optional
)
13575 gfc_error ("Argument of FINAL procedure at %L must not be OPTIONAL",
13576 &arg
->declared_at
);
13580 /* It must not be INTENT(OUT). */
13581 if (arg
->attr
.intent
== INTENT_OUT
)
13583 gfc_error ("Argument of FINAL procedure at %L must not be"
13584 " INTENT(OUT)", &arg
->declared_at
);
13588 /* Warn if the procedure is non-scalar and not assumed shape. */
13589 if (warn_surprising
&& arg
->as
&& arg
->as
->rank
!= 0
13590 && arg
->as
->type
!= AS_ASSUMED_SHAPE
)
13591 gfc_warning (OPT_Wsurprising
,
13592 "Non-scalar FINAL procedure at %L should have assumed"
13593 " shape argument", &arg
->declared_at
);
13595 /* Check that it does not match in kind and rank with a FINAL procedure
13596 defined earlier. To really loop over the *earlier* declarations,
13597 we need to walk the tail of the list as new ones were pushed at the
13599 /* TODO: Handle kind parameters once they are implemented. */
13600 my_rank
= (arg
->as
? arg
->as
->rank
: 0);
13601 for (i
= list
->next
; i
; i
= i
->next
)
13603 gfc_formal_arglist
*dummy_args
;
13605 /* Argument list might be empty; that is an error signalled earlier,
13606 but we nevertheless continued resolving. */
13607 dummy_args
= gfc_sym_get_dummy_args (i
->proc_sym
);
13610 gfc_symbol
* i_arg
= dummy_args
->sym
;
13611 const int i_rank
= (i_arg
->as
? i_arg
->as
->rank
: 0);
13612 if (i_rank
== my_rank
)
13614 gfc_error ("FINAL procedure %qs declared at %L has the same"
13615 " rank (%d) as %qs",
13616 list
->proc_sym
->name
, &list
->where
, my_rank
,
13617 i
->proc_sym
->name
);
13623 /* Is this the/a scalar finalizer procedure? */
13625 seen_scalar
= true;
13627 /* Find the symtree for this procedure. */
13628 gcc_assert (!list
->proc_tree
);
13629 list
->proc_tree
= gfc_find_sym_in_symtree (list
->proc_sym
);
13631 prev_link
= &list
->next
;
13634 /* Remove wrong nodes immediately from the list so we don't risk any
13635 troubles in the future when they might fail later expectations. */
13638 *prev_link
= list
->next
;
13639 gfc_free_finalizer (i
);
13643 if (result
== false)
13646 /* Warn if we haven't seen a scalar finalizer procedure (but we know there
13647 were nodes in the list, must have been for arrays. It is surely a good
13648 idea to have a scalar version there if there's something to finalize. */
13649 if (warn_surprising
&& derived
->f2k_derived
->finalizers
&& !seen_scalar
)
13650 gfc_warning (OPT_Wsurprising
,
13651 "Only array FINAL procedures declared for derived type %qs"
13652 " defined at %L, suggest also scalar one",
13653 derived
->name
, &derived
->declared_at
);
13655 vtab
= gfc_find_derived_vtab (derived
);
13656 c
= vtab
->ts
.u
.derived
->components
->next
->next
->next
->next
->next
;
13657 gfc_set_sym_referenced (c
->initializer
->symtree
->n
.sym
);
13660 *finalizable
= true;
13666 /* Check if two GENERIC targets are ambiguous and emit an error is they are. */
13669 check_generic_tbp_ambiguity (gfc_tbp_generic
* t1
, gfc_tbp_generic
* t2
,
13670 const char* generic_name
, locus where
)
13672 gfc_symbol
*sym1
, *sym2
;
13673 const char *pass1
, *pass2
;
13674 gfc_formal_arglist
*dummy_args
;
13676 gcc_assert (t1
->specific
&& t2
->specific
);
13677 gcc_assert (!t1
->specific
->is_generic
);
13678 gcc_assert (!t2
->specific
->is_generic
);
13679 gcc_assert (t1
->is_operator
== t2
->is_operator
);
13681 sym1
= t1
->specific
->u
.specific
->n
.sym
;
13682 sym2
= t2
->specific
->u
.specific
->n
.sym
;
13687 /* Both must be SUBROUTINEs or both must be FUNCTIONs. */
13688 if (sym1
->attr
.subroutine
!= sym2
->attr
.subroutine
13689 || sym1
->attr
.function
!= sym2
->attr
.function
)
13691 gfc_error ("%qs and %qs cannot be mixed FUNCTION/SUBROUTINE for"
13692 " GENERIC %qs at %L",
13693 sym1
->name
, sym2
->name
, generic_name
, &where
);
13697 /* Determine PASS arguments. */
13698 if (t1
->specific
->nopass
)
13700 else if (t1
->specific
->pass_arg
)
13701 pass1
= t1
->specific
->pass_arg
;
13704 dummy_args
= gfc_sym_get_dummy_args (t1
->specific
->u
.specific
->n
.sym
);
13706 pass1
= dummy_args
->sym
->name
;
13710 if (t2
->specific
->nopass
)
13712 else if (t2
->specific
->pass_arg
)
13713 pass2
= t2
->specific
->pass_arg
;
13716 dummy_args
= gfc_sym_get_dummy_args (t2
->specific
->u
.specific
->n
.sym
);
13718 pass2
= dummy_args
->sym
->name
;
13723 /* Compare the interfaces. */
13724 if (gfc_compare_interfaces (sym1
, sym2
, sym2
->name
, !t1
->is_operator
, 0,
13725 NULL
, 0, pass1
, pass2
))
13727 gfc_error ("%qs and %qs for GENERIC %qs at %L are ambiguous",
13728 sym1
->name
, sym2
->name
, generic_name
, &where
);
13736 /* Worker function for resolving a generic procedure binding; this is used to
13737 resolve GENERIC as well as user and intrinsic OPERATOR typebound procedures.
13739 The difference between those cases is finding possible inherited bindings
13740 that are overridden, as one has to look for them in tb_sym_root,
13741 tb_uop_root or tb_op, respectively. Thus the caller must already find
13742 the super-type and set p->overridden correctly. */
13745 resolve_tb_generic_targets (gfc_symbol
* super_type
,
13746 gfc_typebound_proc
* p
, const char* name
)
13748 gfc_tbp_generic
* target
;
13749 gfc_symtree
* first_target
;
13750 gfc_symtree
* inherited
;
13752 gcc_assert (p
&& p
->is_generic
);
13754 /* Try to find the specific bindings for the symtrees in our target-list. */
13755 gcc_assert (p
->u
.generic
);
13756 for (target
= p
->u
.generic
; target
; target
= target
->next
)
13757 if (!target
->specific
)
13759 gfc_typebound_proc
* overridden_tbp
;
13760 gfc_tbp_generic
* g
;
13761 const char* target_name
;
13763 target_name
= target
->specific_st
->name
;
13765 /* Defined for this type directly. */
13766 if (target
->specific_st
->n
.tb
&& !target
->specific_st
->n
.tb
->error
)
13768 target
->specific
= target
->specific_st
->n
.tb
;
13769 goto specific_found
;
13772 /* Look for an inherited specific binding. */
13775 inherited
= gfc_find_typebound_proc (super_type
, NULL
, target_name
,
13780 gcc_assert (inherited
->n
.tb
);
13781 target
->specific
= inherited
->n
.tb
;
13782 goto specific_found
;
13786 gfc_error ("Undefined specific binding %qs as target of GENERIC %qs"
13787 " at %L", target_name
, name
, &p
->where
);
13790 /* Once we've found the specific binding, check it is not ambiguous with
13791 other specifics already found or inherited for the same GENERIC. */
13793 gcc_assert (target
->specific
);
13795 /* This must really be a specific binding! */
13796 if (target
->specific
->is_generic
)
13798 gfc_error ("GENERIC %qs at %L must target a specific binding,"
13799 " %qs is GENERIC, too", name
, &p
->where
, target_name
);
13803 /* Check those already resolved on this type directly. */
13804 for (g
= p
->u
.generic
; g
; g
= g
->next
)
13805 if (g
!= target
&& g
->specific
13806 && !check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
13809 /* Check for ambiguity with inherited specific targets. */
13810 for (overridden_tbp
= p
->overridden
; overridden_tbp
;
13811 overridden_tbp
= overridden_tbp
->overridden
)
13812 if (overridden_tbp
->is_generic
)
13814 for (g
= overridden_tbp
->u
.generic
; g
; g
= g
->next
)
13816 gcc_assert (g
->specific
);
13817 if (!check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
13823 /* If we attempt to "overwrite" a specific binding, this is an error. */
13824 if (p
->overridden
&& !p
->overridden
->is_generic
)
13826 gfc_error ("GENERIC %qs at %L cannot overwrite specific binding with"
13827 " the same name", name
, &p
->where
);
13831 /* Take the SUBROUTINE/FUNCTION attributes of the first specific target, as
13832 all must have the same attributes here. */
13833 first_target
= p
->u
.generic
->specific
->u
.specific
;
13834 gcc_assert (first_target
);
13835 p
->subroutine
= first_target
->n
.sym
->attr
.subroutine
;
13836 p
->function
= first_target
->n
.sym
->attr
.function
;
13842 /* Resolve a GENERIC procedure binding for a derived type. */
13845 resolve_typebound_generic (gfc_symbol
* derived
, gfc_symtree
* st
)
13847 gfc_symbol
* super_type
;
13849 /* Find the overridden binding if any. */
13850 st
->n
.tb
->overridden
= NULL
;
13851 super_type
= gfc_get_derived_super_type (derived
);
13854 gfc_symtree
* overridden
;
13855 overridden
= gfc_find_typebound_proc (super_type
, NULL
, st
->name
,
13858 if (overridden
&& overridden
->n
.tb
)
13859 st
->n
.tb
->overridden
= overridden
->n
.tb
;
13862 /* Resolve using worker function. */
13863 return resolve_tb_generic_targets (super_type
, st
->n
.tb
, st
->name
);
13867 /* Retrieve the target-procedure of an operator binding and do some checks in
13868 common for intrinsic and user-defined type-bound operators. */
13871 get_checked_tb_operator_target (gfc_tbp_generic
* target
, locus where
)
13873 gfc_symbol
* target_proc
;
13875 gcc_assert (target
->specific
&& !target
->specific
->is_generic
);
13876 target_proc
= target
->specific
->u
.specific
->n
.sym
;
13877 gcc_assert (target_proc
);
13879 /* F08:C468. All operator bindings must have a passed-object dummy argument. */
13880 if (target
->specific
->nopass
)
13882 gfc_error ("Type-bound operator at %L cannot be NOPASS", &where
);
13886 return target_proc
;
13890 /* Resolve a type-bound intrinsic operator. */
13893 resolve_typebound_intrinsic_op (gfc_symbol
* derived
, gfc_intrinsic_op op
,
13894 gfc_typebound_proc
* p
)
13896 gfc_symbol
* super_type
;
13897 gfc_tbp_generic
* target
;
13899 /* If there's already an error here, do nothing (but don't fail again). */
13903 /* Operators should always be GENERIC bindings. */
13904 gcc_assert (p
->is_generic
);
13906 /* Look for an overridden binding. */
13907 super_type
= gfc_get_derived_super_type (derived
);
13908 if (super_type
&& super_type
->f2k_derived
)
13909 p
->overridden
= gfc_find_typebound_intrinsic_op (super_type
, NULL
,
13912 p
->overridden
= NULL
;
13914 /* Resolve general GENERIC properties using worker function. */
13915 if (!resolve_tb_generic_targets (super_type
, p
, gfc_op2string(op
)))
13918 /* Check the targets to be procedures of correct interface. */
13919 for (target
= p
->u
.generic
; target
; target
= target
->next
)
13921 gfc_symbol
* target_proc
;
13923 target_proc
= get_checked_tb_operator_target (target
, p
->where
);
13927 if (!gfc_check_operator_interface (target_proc
, op
, p
->where
))
13930 /* Add target to non-typebound operator list. */
13931 if (!target
->specific
->deferred
&& !derived
->attr
.use_assoc
13932 && p
->access
!= ACCESS_PRIVATE
&& derived
->ns
== gfc_current_ns
)
13934 gfc_interface
*head
, *intr
;
13936 /* Preempt 'gfc_check_new_interface' for submodules, where the
13937 mechanism for handling module procedures winds up resolving
13938 operator interfaces twice and would otherwise cause an error. */
13939 for (intr
= derived
->ns
->op
[op
]; intr
; intr
= intr
->next
)
13940 if (intr
->sym
== target_proc
13941 && target_proc
->attr
.used_in_submodule
)
13944 if (!gfc_check_new_interface (derived
->ns
->op
[op
],
13945 target_proc
, p
->where
))
13947 head
= derived
->ns
->op
[op
];
13948 intr
= gfc_get_interface ();
13949 intr
->sym
= target_proc
;
13950 intr
->where
= p
->where
;
13952 derived
->ns
->op
[op
] = intr
;
13964 /* Resolve a type-bound user operator (tree-walker callback). */
13966 static gfc_symbol
* resolve_bindings_derived
;
13967 static bool resolve_bindings_result
;
13969 static bool check_uop_procedure (gfc_symbol
* sym
, locus where
);
13972 resolve_typebound_user_op (gfc_symtree
* stree
)
13974 gfc_symbol
* super_type
;
13975 gfc_tbp_generic
* target
;
13977 gcc_assert (stree
&& stree
->n
.tb
);
13979 if (stree
->n
.tb
->error
)
13982 /* Operators should always be GENERIC bindings. */
13983 gcc_assert (stree
->n
.tb
->is_generic
);
13985 /* Find overridden procedure, if any. */
13986 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
13987 if (super_type
&& super_type
->f2k_derived
)
13989 gfc_symtree
* overridden
;
13990 overridden
= gfc_find_typebound_user_op (super_type
, NULL
,
13991 stree
->name
, true, NULL
);
13993 if (overridden
&& overridden
->n
.tb
)
13994 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
13997 stree
->n
.tb
->overridden
= NULL
;
13999 /* Resolve basically using worker function. */
14000 if (!resolve_tb_generic_targets (super_type
, stree
->n
.tb
, stree
->name
))
14003 /* Check the targets to be functions of correct interface. */
14004 for (target
= stree
->n
.tb
->u
.generic
; target
; target
= target
->next
)
14006 gfc_symbol
* target_proc
;
14008 target_proc
= get_checked_tb_operator_target (target
, stree
->n
.tb
->where
);
14012 if (!check_uop_procedure (target_proc
, stree
->n
.tb
->where
))
14019 resolve_bindings_result
= false;
14020 stree
->n
.tb
->error
= 1;
14024 /* Resolve the type-bound procedures for a derived type. */
14027 resolve_typebound_procedure (gfc_symtree
* stree
)
14031 gfc_symbol
* me_arg
;
14032 gfc_symbol
* super_type
;
14033 gfc_component
* comp
;
14035 gcc_assert (stree
);
14037 /* Undefined specific symbol from GENERIC target definition. */
14041 if (stree
->n
.tb
->error
)
14044 /* If this is a GENERIC binding, use that routine. */
14045 if (stree
->n
.tb
->is_generic
)
14047 if (!resolve_typebound_generic (resolve_bindings_derived
, stree
))
14052 /* Get the target-procedure to check it. */
14053 gcc_assert (!stree
->n
.tb
->is_generic
);
14054 gcc_assert (stree
->n
.tb
->u
.specific
);
14055 proc
= stree
->n
.tb
->u
.specific
->n
.sym
;
14056 where
= stree
->n
.tb
->where
;
14058 /* Default access should already be resolved from the parser. */
14059 gcc_assert (stree
->n
.tb
->access
!= ACCESS_UNKNOWN
);
14061 if (stree
->n
.tb
->deferred
)
14063 if (!check_proc_interface (proc
, &where
))
14068 /* If proc has not been resolved at this point, proc->name may
14069 actually be a USE associated entity. See PR fortran/89647. */
14070 if (!proc
->resolve_symbol_called
14071 && proc
->attr
.function
== 0 && proc
->attr
.subroutine
== 0)
14074 gfc_find_symbol (proc
->name
, gfc_current_ns
->parent
, 1, &tmp
);
14075 if (tmp
&& tmp
->attr
.use_assoc
)
14077 proc
->module
= tmp
->module
;
14078 proc
->attr
.proc
= tmp
->attr
.proc
;
14079 proc
->attr
.function
= tmp
->attr
.function
;
14080 proc
->attr
.subroutine
= tmp
->attr
.subroutine
;
14081 proc
->attr
.use_assoc
= tmp
->attr
.use_assoc
;
14082 proc
->ts
= tmp
->ts
;
14083 proc
->result
= tmp
->result
;
14087 /* Check for F08:C465. */
14088 if ((!proc
->attr
.subroutine
&& !proc
->attr
.function
)
14089 || (proc
->attr
.proc
!= PROC_MODULE
14090 && proc
->attr
.if_source
!= IFSRC_IFBODY
14091 && !proc
->attr
.module_procedure
)
14092 || proc
->attr
.abstract
)
14094 gfc_error ("%qs must be a module procedure or an external "
14095 "procedure with an explicit interface at %L",
14096 proc
->name
, &where
);
14101 stree
->n
.tb
->subroutine
= proc
->attr
.subroutine
;
14102 stree
->n
.tb
->function
= proc
->attr
.function
;
14104 /* Find the super-type of the current derived type. We could do this once and
14105 store in a global if speed is needed, but as long as not I believe this is
14106 more readable and clearer. */
14107 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
14109 /* If PASS, resolve and check arguments if not already resolved / loaded
14110 from a .mod file. */
14111 if (!stree
->n
.tb
->nopass
&& stree
->n
.tb
->pass_arg_num
== 0)
14113 gfc_formal_arglist
*dummy_args
;
14115 dummy_args
= gfc_sym_get_dummy_args (proc
);
14116 if (stree
->n
.tb
->pass_arg
)
14118 gfc_formal_arglist
*i
;
14120 /* If an explicit passing argument name is given, walk the arg-list
14121 and look for it. */
14124 stree
->n
.tb
->pass_arg_num
= 1;
14125 for (i
= dummy_args
; i
; i
= i
->next
)
14127 if (!strcmp (i
->sym
->name
, stree
->n
.tb
->pass_arg
))
14132 ++stree
->n
.tb
->pass_arg_num
;
14137 gfc_error ("Procedure %qs with PASS(%s) at %L has no"
14139 proc
->name
, stree
->n
.tb
->pass_arg
, &where
,
14140 stree
->n
.tb
->pass_arg
);
14146 /* Otherwise, take the first one; there should in fact be at least
14148 stree
->n
.tb
->pass_arg_num
= 1;
14151 gfc_error ("Procedure %qs with PASS at %L must have at"
14152 " least one argument", proc
->name
, &where
);
14155 me_arg
= dummy_args
->sym
;
14158 /* Now check that the argument-type matches and the passed-object
14159 dummy argument is generally fine. */
14161 gcc_assert (me_arg
);
14163 if (me_arg
->ts
.type
!= BT_CLASS
)
14165 gfc_error ("Non-polymorphic passed-object dummy argument of %qs"
14166 " at %L", proc
->name
, &where
);
14170 if (CLASS_DATA (me_arg
)->ts
.u
.derived
14171 != resolve_bindings_derived
)
14173 gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of"
14174 " the derived-type %qs", me_arg
->name
, proc
->name
,
14175 me_arg
->name
, &where
, resolve_bindings_derived
->name
);
14179 gcc_assert (me_arg
->ts
.type
== BT_CLASS
);
14180 if (CLASS_DATA (me_arg
)->as
&& CLASS_DATA (me_arg
)->as
->rank
!= 0)
14182 gfc_error ("Passed-object dummy argument of %qs at %L must be"
14183 " scalar", proc
->name
, &where
);
14186 if (CLASS_DATA (me_arg
)->attr
.allocatable
)
14188 gfc_error ("Passed-object dummy argument of %qs at %L must not"
14189 " be ALLOCATABLE", proc
->name
, &where
);
14192 if (CLASS_DATA (me_arg
)->attr
.class_pointer
)
14194 gfc_error ("Passed-object dummy argument of %qs at %L must not"
14195 " be POINTER", proc
->name
, &where
);
14200 /* If we are extending some type, check that we don't override a procedure
14201 flagged NON_OVERRIDABLE. */
14202 stree
->n
.tb
->overridden
= NULL
;
14205 gfc_symtree
* overridden
;
14206 overridden
= gfc_find_typebound_proc (super_type
, NULL
,
14207 stree
->name
, true, NULL
);
14211 if (overridden
->n
.tb
)
14212 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
14214 if (!gfc_check_typebound_override (stree
, overridden
))
14219 /* See if there's a name collision with a component directly in this type. */
14220 for (comp
= resolve_bindings_derived
->components
; comp
; comp
= comp
->next
)
14221 if (!strcmp (comp
->name
, stree
->name
))
14223 gfc_error ("Procedure %qs at %L has the same name as a component of"
14225 stree
->name
, &where
, resolve_bindings_derived
->name
);
14229 /* Try to find a name collision with an inherited component. */
14230 if (super_type
&& gfc_find_component (super_type
, stree
->name
, true, true,
14233 gfc_error ("Procedure %qs at %L has the same name as an inherited"
14234 " component of %qs",
14235 stree
->name
, &where
, resolve_bindings_derived
->name
);
14239 stree
->n
.tb
->error
= 0;
14243 resolve_bindings_result
= false;
14244 stree
->n
.tb
->error
= 1;
14249 resolve_typebound_procedures (gfc_symbol
* derived
)
14252 gfc_symbol
* super_type
;
14254 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->tb_sym_root
)
14257 super_type
= gfc_get_derived_super_type (derived
);
14259 resolve_symbol (super_type
);
14261 resolve_bindings_derived
= derived
;
14262 resolve_bindings_result
= true;
14264 if (derived
->f2k_derived
->tb_sym_root
)
14265 gfc_traverse_symtree (derived
->f2k_derived
->tb_sym_root
,
14266 &resolve_typebound_procedure
);
14268 if (derived
->f2k_derived
->tb_uop_root
)
14269 gfc_traverse_symtree (derived
->f2k_derived
->tb_uop_root
,
14270 &resolve_typebound_user_op
);
14272 for (op
= 0; op
!= GFC_INTRINSIC_OPS
; ++op
)
14274 gfc_typebound_proc
* p
= derived
->f2k_derived
->tb_op
[op
];
14275 if (p
&& !resolve_typebound_intrinsic_op (derived
,
14276 (gfc_intrinsic_op
)op
, p
))
14277 resolve_bindings_result
= false;
14280 return resolve_bindings_result
;
14284 /* Add a derived type to the dt_list. The dt_list is used in trans-types.c
14285 to give all identical derived types the same backend_decl. */
14287 add_dt_to_dt_list (gfc_symbol
*derived
)
14289 if (!derived
->dt_next
)
14291 if (gfc_derived_types
)
14293 derived
->dt_next
= gfc_derived_types
->dt_next
;
14294 gfc_derived_types
->dt_next
= derived
;
14298 derived
->dt_next
= derived
;
14300 gfc_derived_types
= derived
;
14305 /* Ensure that a derived-type is really not abstract, meaning that every
14306 inherited DEFERRED binding is overridden by a non-DEFERRED one. */
14309 ensure_not_abstract_walker (gfc_symbol
* sub
, gfc_symtree
* st
)
14314 if (!ensure_not_abstract_walker (sub
, st
->left
))
14316 if (!ensure_not_abstract_walker (sub
, st
->right
))
14319 if (st
->n
.tb
&& st
->n
.tb
->deferred
)
14321 gfc_symtree
* overriding
;
14322 overriding
= gfc_find_typebound_proc (sub
, NULL
, st
->name
, true, NULL
);
14325 gcc_assert (overriding
->n
.tb
);
14326 if (overriding
->n
.tb
->deferred
)
14328 gfc_error ("Derived-type %qs declared at %L must be ABSTRACT because"
14329 " %qs is DEFERRED and not overridden",
14330 sub
->name
, &sub
->declared_at
, st
->name
);
14339 ensure_not_abstract (gfc_symbol
* sub
, gfc_symbol
* ancestor
)
14341 /* The algorithm used here is to recursively travel up the ancestry of sub
14342 and for each ancestor-type, check all bindings. If any of them is
14343 DEFERRED, look it up starting from sub and see if the found (overriding)
14344 binding is not DEFERRED.
14345 This is not the most efficient way to do this, but it should be ok and is
14346 clearer than something sophisticated. */
14348 gcc_assert (ancestor
&& !sub
->attr
.abstract
);
14350 if (!ancestor
->attr
.abstract
)
14353 /* Walk bindings of this ancestor. */
14354 if (ancestor
->f2k_derived
)
14357 t
= ensure_not_abstract_walker (sub
, ancestor
->f2k_derived
->tb_sym_root
);
14362 /* Find next ancestor type and recurse on it. */
14363 ancestor
= gfc_get_derived_super_type (ancestor
);
14365 return ensure_not_abstract (sub
, ancestor
);
14371 /* This check for typebound defined assignments is done recursively
14372 since the order in which derived types are resolved is not always in
14373 order of the declarations. */
14376 check_defined_assignments (gfc_symbol
*derived
)
14380 for (c
= derived
->components
; c
; c
= c
->next
)
14382 if (!gfc_bt_struct (c
->ts
.type
)
14384 || c
->attr
.allocatable
14385 || c
->attr
.proc_pointer_comp
14386 || c
->attr
.class_pointer
14387 || c
->attr
.proc_pointer
)
14390 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
14391 || (c
->ts
.u
.derived
->f2k_derived
14392 && c
->ts
.u
.derived
->f2k_derived
->tb_op
[INTRINSIC_ASSIGN
]))
14394 derived
->attr
.defined_assign_comp
= 1;
14398 check_defined_assignments (c
->ts
.u
.derived
);
14399 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
14401 derived
->attr
.defined_assign_comp
= 1;
14408 /* Resolve a single component of a derived type or structure. */
14411 resolve_component (gfc_component
*c
, gfc_symbol
*sym
)
14413 gfc_symbol
*super_type
;
14414 symbol_attribute
*attr
;
14416 if (c
->attr
.artificial
)
14419 /* Do not allow vtype components to be resolved in nameless namespaces
14420 such as block data because the procedure pointers will cause ICEs
14421 and vtables are not needed in these contexts. */
14422 if (sym
->attr
.vtype
&& sym
->attr
.use_assoc
14423 && sym
->ns
->proc_name
== NULL
)
14427 if ((!sym
->attr
.is_class
|| c
!= sym
->components
)
14428 && c
->attr
.codimension
14429 && (!c
->attr
.allocatable
|| (c
->as
&& c
->as
->type
!= AS_DEFERRED
)))
14431 gfc_error ("Coarray component %qs at %L must be allocatable with "
14432 "deferred shape", c
->name
, &c
->loc
);
14437 if (c
->attr
.codimension
&& c
->ts
.type
== BT_DERIVED
14438 && c
->ts
.u
.derived
->ts
.is_iso_c
)
14440 gfc_error ("Component %qs at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
14441 "shall not be a coarray", c
->name
, &c
->loc
);
14446 if (gfc_bt_struct (c
->ts
.type
) && c
->ts
.u
.derived
->attr
.coarray_comp
14447 && (c
->attr
.codimension
|| c
->attr
.pointer
|| c
->attr
.dimension
14448 || c
->attr
.allocatable
))
14450 gfc_error ("Component %qs at %L with coarray component "
14451 "shall be a nonpointer, nonallocatable scalar",
14457 if (c
->ts
.type
== BT_CLASS
)
14459 if (c
->attr
.class_ok
&& CLASS_DATA (c
))
14461 attr
= &(CLASS_DATA (c
)->attr
);
14463 /* Fix up contiguous attribute. */
14464 if (c
->attr
.contiguous
)
14465 attr
->contiguous
= 1;
14473 if (attr
&& attr
->contiguous
&& (!attr
->dimension
|| !attr
->pointer
))
14475 gfc_error ("Component %qs at %L has the CONTIGUOUS attribute but "
14476 "is not an array pointer", c
->name
, &c
->loc
);
14480 /* F2003, 15.2.1 - length has to be one. */
14481 if (sym
->attr
.is_bind_c
&& c
->ts
.type
== BT_CHARACTER
14482 && (c
->ts
.u
.cl
== NULL
|| c
->ts
.u
.cl
->length
== NULL
14483 || !gfc_is_constant_expr (c
->ts
.u
.cl
->length
)
14484 || mpz_cmp_si (c
->ts
.u
.cl
->length
->value
.integer
, 1) != 0))
14486 gfc_error ("Component %qs of BIND(C) type at %L must have length one",
14491 if (c
->attr
.proc_pointer
&& c
->ts
.interface
)
14493 gfc_symbol
*ifc
= c
->ts
.interface
;
14495 if (!sym
->attr
.vtype
&& !check_proc_interface (ifc
, &c
->loc
))
14501 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
14503 /* Resolve interface and copy attributes. */
14504 if (ifc
->formal
&& !ifc
->formal_ns
)
14505 resolve_symbol (ifc
);
14506 if (ifc
->attr
.intrinsic
)
14507 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
14511 c
->ts
= ifc
->result
->ts
;
14512 c
->attr
.allocatable
= ifc
->result
->attr
.allocatable
;
14513 c
->attr
.pointer
= ifc
->result
->attr
.pointer
;
14514 c
->attr
.dimension
= ifc
->result
->attr
.dimension
;
14515 c
->as
= gfc_copy_array_spec (ifc
->result
->as
);
14516 c
->attr
.class_ok
= ifc
->result
->attr
.class_ok
;
14521 c
->attr
.allocatable
= ifc
->attr
.allocatable
;
14522 c
->attr
.pointer
= ifc
->attr
.pointer
;
14523 c
->attr
.dimension
= ifc
->attr
.dimension
;
14524 c
->as
= gfc_copy_array_spec (ifc
->as
);
14525 c
->attr
.class_ok
= ifc
->attr
.class_ok
;
14527 c
->ts
.interface
= ifc
;
14528 c
->attr
.function
= ifc
->attr
.function
;
14529 c
->attr
.subroutine
= ifc
->attr
.subroutine
;
14531 c
->attr
.pure
= ifc
->attr
.pure
;
14532 c
->attr
.elemental
= ifc
->attr
.elemental
;
14533 c
->attr
.recursive
= ifc
->attr
.recursive
;
14534 c
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
14535 c
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
14536 /* Copy char length. */
14537 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
14539 gfc_charlen
*cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
14540 if (cl
->length
&& !cl
->resolved
14541 && !gfc_resolve_expr (cl
->length
))
14550 else if (c
->attr
.proc_pointer
&& c
->ts
.type
== BT_UNKNOWN
)
14552 /* Since PPCs are not implicitly typed, a PPC without an explicit
14553 interface must be a subroutine. */
14554 gfc_add_subroutine (&c
->attr
, c
->name
, &c
->loc
);
14557 /* Procedure pointer components: Check PASS arg. */
14558 if (c
->attr
.proc_pointer
&& !c
->tb
->nopass
&& c
->tb
->pass_arg_num
== 0
14559 && !sym
->attr
.vtype
)
14561 gfc_symbol
* me_arg
;
14563 if (c
->tb
->pass_arg
)
14565 gfc_formal_arglist
* i
;
14567 /* If an explicit passing argument name is given, walk the arg-list
14568 and look for it. */
14571 c
->tb
->pass_arg_num
= 1;
14572 for (i
= c
->ts
.interface
->formal
; i
; i
= i
->next
)
14574 if (!strcmp (i
->sym
->name
, c
->tb
->pass_arg
))
14579 c
->tb
->pass_arg_num
++;
14584 gfc_error ("Procedure pointer component %qs with PASS(%s) "
14585 "at %L has no argument %qs", c
->name
,
14586 c
->tb
->pass_arg
, &c
->loc
, c
->tb
->pass_arg
);
14593 /* Otherwise, take the first one; there should in fact be at least
14595 c
->tb
->pass_arg_num
= 1;
14596 if (!c
->ts
.interface
->formal
)
14598 gfc_error ("Procedure pointer component %qs with PASS at %L "
14599 "must have at least one argument",
14604 me_arg
= c
->ts
.interface
->formal
->sym
;
14607 /* Now check that the argument-type matches. */
14608 gcc_assert (me_arg
);
14609 if ((me_arg
->ts
.type
!= BT_DERIVED
&& me_arg
->ts
.type
!= BT_CLASS
)
14610 || (me_arg
->ts
.type
== BT_DERIVED
&& me_arg
->ts
.u
.derived
!= sym
)
14611 || (me_arg
->ts
.type
== BT_CLASS
14612 && CLASS_DATA (me_arg
)->ts
.u
.derived
!= sym
))
14614 gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of"
14615 " the derived type %qs", me_arg
->name
, c
->name
,
14616 me_arg
->name
, &c
->loc
, sym
->name
);
14621 /* Check for F03:C453. */
14622 if (CLASS_DATA (me_arg
)->attr
.dimension
)
14624 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
14625 "must be scalar", me_arg
->name
, c
->name
, me_arg
->name
,
14631 if (CLASS_DATA (me_arg
)->attr
.class_pointer
)
14633 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
14634 "may not have the POINTER attribute", me_arg
->name
,
14635 c
->name
, me_arg
->name
, &c
->loc
);
14640 if (CLASS_DATA (me_arg
)->attr
.allocatable
)
14642 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
14643 "may not be ALLOCATABLE", me_arg
->name
, c
->name
,
14644 me_arg
->name
, &c
->loc
);
14649 if (gfc_type_is_extensible (sym
) && me_arg
->ts
.type
!= BT_CLASS
)
14651 gfc_error ("Non-polymorphic passed-object dummy argument of %qs"
14652 " at %L", c
->name
, &c
->loc
);
14658 /* Check type-spec if this is not the parent-type component. */
14659 if (((sym
->attr
.is_class
14660 && (!sym
->components
->ts
.u
.derived
->attr
.extension
14661 || c
!= sym
->components
->ts
.u
.derived
->components
))
14662 || (!sym
->attr
.is_class
14663 && (!sym
->attr
.extension
|| c
!= sym
->components
)))
14664 && !sym
->attr
.vtype
14665 && !resolve_typespec_used (&c
->ts
, &c
->loc
, c
->name
))
14668 super_type
= gfc_get_derived_super_type (sym
);
14670 /* If this type is an extension, set the accessibility of the parent
14673 && ((sym
->attr
.is_class
14674 && c
== sym
->components
->ts
.u
.derived
->components
)
14675 || (!sym
->attr
.is_class
&& c
== sym
->components
))
14676 && strcmp (super_type
->name
, c
->name
) == 0)
14677 c
->attr
.access
= super_type
->attr
.access
;
14679 /* If this type is an extension, see if this component has the same name
14680 as an inherited type-bound procedure. */
14681 if (super_type
&& !sym
->attr
.is_class
14682 && gfc_find_typebound_proc (super_type
, NULL
, c
->name
, true, NULL
))
14684 gfc_error ("Component %qs of %qs at %L has the same name as an"
14685 " inherited type-bound procedure",
14686 c
->name
, sym
->name
, &c
->loc
);
14690 if (c
->ts
.type
== BT_CHARACTER
&& !c
->attr
.proc_pointer
14691 && !c
->ts
.deferred
)
14693 if (c
->ts
.u
.cl
->length
== NULL
14694 || (!resolve_charlen(c
->ts
.u
.cl
))
14695 || !gfc_is_constant_expr (c
->ts
.u
.cl
->length
))
14697 gfc_error ("Character length of component %qs needs to "
14698 "be a constant specification expression at %L",
14700 c
->ts
.u
.cl
->length
? &c
->ts
.u
.cl
->length
->where
: &c
->loc
);
14705 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
14706 && !c
->attr
.pointer
&& !c
->attr
.allocatable
)
14708 gfc_error ("Character component %qs of %qs at %L with deferred "
14709 "length must be a POINTER or ALLOCATABLE",
14710 c
->name
, sym
->name
, &c
->loc
);
14714 /* Add the hidden deferred length field. */
14715 if (c
->ts
.type
== BT_CHARACTER
14716 && (c
->ts
.deferred
|| c
->attr
.pdt_string
)
14717 && !c
->attr
.function
14718 && !sym
->attr
.is_class
)
14720 char name
[GFC_MAX_SYMBOL_LEN
+9];
14721 gfc_component
*strlen
;
14722 sprintf (name
, "_%s_length", c
->name
);
14723 strlen
= gfc_find_component (sym
, name
, true, true, NULL
);
14724 if (strlen
== NULL
)
14726 if (!gfc_add_component (sym
, name
, &strlen
))
14728 strlen
->ts
.type
= BT_INTEGER
;
14729 strlen
->ts
.kind
= gfc_charlen_int_kind
;
14730 strlen
->attr
.access
= ACCESS_PRIVATE
;
14731 strlen
->attr
.artificial
= 1;
14735 if (c
->ts
.type
== BT_DERIVED
14736 && sym
->component_access
!= ACCESS_PRIVATE
14737 && gfc_check_symbol_access (sym
)
14738 && !is_sym_host_assoc (c
->ts
.u
.derived
, sym
->ns
)
14739 && !c
->ts
.u
.derived
->attr
.use_assoc
14740 && !gfc_check_symbol_access (c
->ts
.u
.derived
)
14741 && !gfc_notify_std (GFC_STD_F2003
, "the component %qs is a "
14742 "PRIVATE type and cannot be a component of "
14743 "%qs, which is PUBLIC at %L", c
->name
,
14744 sym
->name
, &sym
->declared_at
))
14747 if ((sym
->attr
.sequence
|| sym
->attr
.is_bind_c
) && c
->ts
.type
== BT_CLASS
)
14749 gfc_error ("Polymorphic component %s at %L in SEQUENCE or BIND(C) "
14750 "type %s", c
->name
, &c
->loc
, sym
->name
);
14754 if (sym
->attr
.sequence
)
14756 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.sequence
== 0)
14758 gfc_error ("Component %s of SEQUENCE type declared at %L does "
14759 "not have the SEQUENCE attribute",
14760 c
->ts
.u
.derived
->name
, &sym
->declared_at
);
14765 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.generic
)
14766 c
->ts
.u
.derived
= gfc_find_dt_in_generic (c
->ts
.u
.derived
);
14767 else if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
14768 && CLASS_DATA (c
)->ts
.u
.derived
->attr
.generic
)
14769 CLASS_DATA (c
)->ts
.u
.derived
14770 = gfc_find_dt_in_generic (CLASS_DATA (c
)->ts
.u
.derived
);
14772 /* If an allocatable component derived type is of the same type as
14773 the enclosing derived type, we need a vtable generating so that
14774 the __deallocate procedure is created. */
14775 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
14776 && c
->ts
.u
.derived
== sym
&& c
->attr
.allocatable
== 1)
14777 gfc_find_vtab (&c
->ts
);
14779 /* Ensure that all the derived type components are put on the
14780 derived type list; even in formal namespaces, where derived type
14781 pointer components might not have been declared. */
14782 if (c
->ts
.type
== BT_DERIVED
14784 && c
->ts
.u
.derived
->components
14786 && sym
!= c
->ts
.u
.derived
)
14787 add_dt_to_dt_list (c
->ts
.u
.derived
);
14789 if (c
->as
&& c
->as
->type
!= AS_DEFERRED
14790 && (c
->attr
.pointer
|| c
->attr
.allocatable
))
14793 if (!gfc_resolve_array_spec (c
->as
,
14794 !(c
->attr
.pointer
|| c
->attr
.proc_pointer
14795 || c
->attr
.allocatable
)))
14798 if (c
->initializer
&& !sym
->attr
.vtype
14799 && !c
->attr
.pdt_kind
&& !c
->attr
.pdt_len
14800 && !gfc_check_assign_symbol (sym
, c
, c
->initializer
))
14807 /* Be nice about the locus for a structure expression - show the locus of the
14808 first non-null sub-expression if we can. */
14811 cons_where (gfc_expr
*struct_expr
)
14813 gfc_constructor
*cons
;
14815 gcc_assert (struct_expr
&& struct_expr
->expr_type
== EXPR_STRUCTURE
);
14817 cons
= gfc_constructor_first (struct_expr
->value
.constructor
);
14818 for (; cons
; cons
= gfc_constructor_next (cons
))
14820 if (cons
->expr
&& cons
->expr
->expr_type
!= EXPR_NULL
)
14821 return &cons
->expr
->where
;
14824 return &struct_expr
->where
;
14827 /* Resolve the components of a structure type. Much less work than derived
14831 resolve_fl_struct (gfc_symbol
*sym
)
14834 gfc_expr
*init
= NULL
;
14837 /* Make sure UNIONs do not have overlapping initializers. */
14838 if (sym
->attr
.flavor
== FL_UNION
)
14840 for (c
= sym
->components
; c
; c
= c
->next
)
14842 if (init
&& c
->initializer
)
14844 gfc_error ("Conflicting initializers in union at %L and %L",
14845 cons_where (init
), cons_where (c
->initializer
));
14846 gfc_free_expr (c
->initializer
);
14847 c
->initializer
= NULL
;
14850 init
= c
->initializer
;
14855 for (c
= sym
->components
; c
; c
= c
->next
)
14856 if (!resolve_component (c
, sym
))
14862 if (sym
->components
)
14863 add_dt_to_dt_list (sym
);
14869 /* Resolve the components of a derived type. This does not have to wait until
14870 resolution stage, but can be done as soon as the dt declaration has been
14874 resolve_fl_derived0 (gfc_symbol
*sym
)
14876 gfc_symbol
* super_type
;
14878 gfc_formal_arglist
*f
;
14881 if (sym
->attr
.unlimited_polymorphic
)
14884 super_type
= gfc_get_derived_super_type (sym
);
14887 if (super_type
&& sym
->attr
.coarray_comp
&& !super_type
->attr
.coarray_comp
)
14889 gfc_error ("As extending type %qs at %L has a coarray component, "
14890 "parent type %qs shall also have one", sym
->name
,
14891 &sym
->declared_at
, super_type
->name
);
14895 /* Ensure the extended type gets resolved before we do. */
14896 if (super_type
&& !resolve_fl_derived0 (super_type
))
14899 /* An ABSTRACT type must be extensible. */
14900 if (sym
->attr
.abstract
&& !gfc_type_is_extensible (sym
))
14902 gfc_error ("Non-extensible derived-type %qs at %L must not be ABSTRACT",
14903 sym
->name
, &sym
->declared_at
);
14907 c
= (sym
->attr
.is_class
) ? sym
->components
->ts
.u
.derived
->components
14911 for ( ; c
!= NULL
; c
= c
->next
)
14912 if (!resolve_component (c
, sym
))
14918 /* Now add the caf token field, where needed. */
14919 if (flag_coarray
!= GFC_FCOARRAY_NONE
14920 && !sym
->attr
.is_class
&& !sym
->attr
.vtype
)
14922 for (c
= sym
->components
; c
; c
= c
->next
)
14923 if (!c
->attr
.dimension
&& !c
->attr
.codimension
14924 && (c
->attr
.allocatable
|| c
->attr
.pointer
))
14926 char name
[GFC_MAX_SYMBOL_LEN
+9];
14927 gfc_component
*token
;
14928 sprintf (name
, "_caf_%s", c
->name
);
14929 token
= gfc_find_component (sym
, name
, true, true, NULL
);
14932 if (!gfc_add_component (sym
, name
, &token
))
14934 token
->ts
.type
= BT_VOID
;
14935 token
->ts
.kind
= gfc_default_integer_kind
;
14936 token
->attr
.access
= ACCESS_PRIVATE
;
14937 token
->attr
.artificial
= 1;
14938 token
->attr
.caf_token
= 1;
14943 check_defined_assignments (sym
);
14945 if (!sym
->attr
.defined_assign_comp
&& super_type
)
14946 sym
->attr
.defined_assign_comp
14947 = super_type
->attr
.defined_assign_comp
;
14949 /* If this is a non-ABSTRACT type extending an ABSTRACT one, ensure that
14950 all DEFERRED bindings are overridden. */
14951 if (super_type
&& super_type
->attr
.abstract
&& !sym
->attr
.abstract
14952 && !sym
->attr
.is_class
14953 && !ensure_not_abstract (sym
, super_type
))
14956 /* Check that there is a component for every PDT parameter. */
14957 if (sym
->attr
.pdt_template
)
14959 for (f
= sym
->formal
; f
; f
= f
->next
)
14963 c
= gfc_find_component (sym
, f
->sym
->name
, true, true, NULL
);
14966 gfc_error ("Parameterized type %qs does not have a component "
14967 "corresponding to parameter %qs at %L", sym
->name
,
14968 f
->sym
->name
, &sym
->declared_at
);
14974 /* Add derived type to the derived type list. */
14975 add_dt_to_dt_list (sym
);
14981 /* The following procedure does the full resolution of a derived type,
14982 including resolution of all type-bound procedures (if present). In contrast
14983 to 'resolve_fl_derived0' this can only be done after the module has been
14984 parsed completely. */
14987 resolve_fl_derived (gfc_symbol
*sym
)
14989 gfc_symbol
*gen_dt
= NULL
;
14991 if (sym
->attr
.unlimited_polymorphic
)
14994 if (!sym
->attr
.is_class
)
14995 gfc_find_symbol (sym
->name
, sym
->ns
, 0, &gen_dt
);
14996 if (gen_dt
&& gen_dt
->generic
&& gen_dt
->generic
->next
14997 && (!gen_dt
->generic
->sym
->attr
.use_assoc
14998 || gen_dt
->generic
->sym
->module
!= gen_dt
->generic
->next
->sym
->module
)
14999 && !gfc_notify_std (GFC_STD_F2003
, "Generic name %qs of function "
15000 "%qs at %L being the same name as derived "
15001 "type at %L", sym
->name
,
15002 gen_dt
->generic
->sym
== sym
15003 ? gen_dt
->generic
->next
->sym
->name
15004 : gen_dt
->generic
->sym
->name
,
15005 gen_dt
->generic
->sym
== sym
15006 ? &gen_dt
->generic
->next
->sym
->declared_at
15007 : &gen_dt
->generic
->sym
->declared_at
,
15008 &sym
->declared_at
))
15011 if (sym
->components
== NULL
&& !sym
->attr
.zero_comp
&& !sym
->attr
.use_assoc
)
15013 gfc_error ("Derived type %qs at %L has not been declared",
15014 sym
->name
, &sym
->declared_at
);
15018 /* Resolve the finalizer procedures. */
15019 if (!gfc_resolve_finalizers (sym
, NULL
))
15022 if (sym
->attr
.is_class
&& sym
->ts
.u
.derived
== NULL
)
15024 /* Fix up incomplete CLASS symbols. */
15025 gfc_component
*data
= gfc_find_component (sym
, "_data", true, true, NULL
);
15026 gfc_component
*vptr
= gfc_find_component (sym
, "_vptr", true, true, NULL
);
15028 /* Nothing more to do for unlimited polymorphic entities. */
15029 if (data
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
15031 else if (vptr
->ts
.u
.derived
== NULL
)
15033 gfc_symbol
*vtab
= gfc_find_derived_vtab (data
->ts
.u
.derived
);
15035 vptr
->ts
.u
.derived
= vtab
->ts
.u
.derived
;
15036 if (!resolve_fl_derived0 (vptr
->ts
.u
.derived
))
15041 if (!resolve_fl_derived0 (sym
))
15044 /* Resolve the type-bound procedures. */
15045 if (!resolve_typebound_procedures (sym
))
15048 /* Generate module vtables subject to their accessibility and their not
15049 being vtables or pdt templates. If this is not done class declarations
15050 in external procedures wind up with their own version and so SELECT TYPE
15051 fails because the vptrs do not have the same address. */
15052 if (gfc_option
.allow_std
& GFC_STD_F2003
15053 && sym
->ns
->proc_name
15054 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
15055 && sym
->attr
.access
!= ACCESS_PRIVATE
15056 && !(sym
->attr
.use_assoc
|| sym
->attr
.vtype
|| sym
->attr
.pdt_template
))
15058 gfc_symbol
*vtab
= gfc_find_derived_vtab (sym
);
15059 gfc_set_sym_referenced (vtab
);
15067 resolve_fl_namelist (gfc_symbol
*sym
)
15072 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
15074 /* Check again, the check in match only works if NAMELIST comes
15076 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SIZE
)
15078 gfc_error ("Assumed size array %qs in namelist %qs at %L is not "
15079 "allowed", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
15083 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SHAPE
15084 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object %qs "
15085 "with assumed shape in namelist %qs at %L",
15086 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
15089 if (is_non_constant_shape_array (nl
->sym
)
15090 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object %qs "
15091 "with nonconstant shape in namelist %qs at %L",
15092 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
15095 if (nl
->sym
->ts
.type
== BT_CHARACTER
15096 && (nl
->sym
->ts
.u
.cl
->length
== NULL
15097 || !gfc_is_constant_expr (nl
->sym
->ts
.u
.cl
->length
))
15098 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST object %qs with "
15099 "nonconstant character length in "
15100 "namelist %qs at %L", nl
->sym
->name
,
15101 sym
->name
, &sym
->declared_at
))
15106 /* Reject PRIVATE objects in a PUBLIC namelist. */
15107 if (gfc_check_symbol_access (sym
))
15109 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
15111 if (!nl
->sym
->attr
.use_assoc
15112 && !is_sym_host_assoc (nl
->sym
, sym
->ns
)
15113 && !gfc_check_symbol_access (nl
->sym
))
15115 gfc_error ("NAMELIST object %qs was declared PRIVATE and "
15116 "cannot be member of PUBLIC namelist %qs at %L",
15117 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
15121 if (nl
->sym
->ts
.type
== BT_DERIVED
15122 && (nl
->sym
->ts
.u
.derived
->attr
.alloc_comp
15123 || nl
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
15125 if (!gfc_notify_std (GFC_STD_F2003
, "NAMELIST object %qs in "
15126 "namelist %qs at %L with ALLOCATABLE "
15127 "or POINTER components", nl
->sym
->name
,
15128 sym
->name
, &sym
->declared_at
))
15133 /* Types with private components that came here by USE-association. */
15134 if (nl
->sym
->ts
.type
== BT_DERIVED
15135 && derived_inaccessible (nl
->sym
->ts
.u
.derived
))
15137 gfc_error ("NAMELIST object %qs has use-associated PRIVATE "
15138 "components and cannot be member of namelist %qs at %L",
15139 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
15143 /* Types with private components that are defined in the same module. */
15144 if (nl
->sym
->ts
.type
== BT_DERIVED
15145 && !is_sym_host_assoc (nl
->sym
->ts
.u
.derived
, sym
->ns
)
15146 && nl
->sym
->ts
.u
.derived
->attr
.private_comp
)
15148 gfc_error ("NAMELIST object %qs has PRIVATE components and "
15149 "cannot be a member of PUBLIC namelist %qs at %L",
15150 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
15157 /* 14.1.2 A module or internal procedure represent local entities
15158 of the same type as a namelist member and so are not allowed. */
15159 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
15161 if (nl
->sym
->ts
.kind
!= 0 && nl
->sym
->attr
.flavor
== FL_VARIABLE
)
15164 if (nl
->sym
->attr
.function
&& nl
->sym
== nl
->sym
->result
)
15165 if ((nl
->sym
== sym
->ns
->proc_name
)
15167 (sym
->ns
->parent
&& nl
->sym
== sym
->ns
->parent
->proc_name
))
15172 gfc_find_symbol (nl
->sym
->name
, sym
->ns
, 1, &nlsym
);
15173 if (nlsym
&& nlsym
->attr
.flavor
== FL_PROCEDURE
)
15175 gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
15176 "attribute in %qs at %L", nlsym
->name
,
15177 &sym
->declared_at
);
15187 resolve_fl_parameter (gfc_symbol
*sym
)
15189 /* A parameter array's shape needs to be constant. */
15190 if (sym
->as
!= NULL
15191 && (sym
->as
->type
== AS_DEFERRED
15192 || is_non_constant_shape_array (sym
)))
15194 gfc_error ("Parameter array %qs at %L cannot be automatic "
15195 "or of deferred shape", sym
->name
, &sym
->declared_at
);
15199 /* Constraints on deferred type parameter. */
15200 if (!deferred_requirements (sym
))
15203 /* Make sure a parameter that has been implicitly typed still
15204 matches the implicit type, since PARAMETER statements can precede
15205 IMPLICIT statements. */
15206 if (sym
->attr
.implicit_type
15207 && !gfc_compare_types (&sym
->ts
, gfc_get_default_type (sym
->name
,
15210 gfc_error ("Implicitly typed PARAMETER %qs at %L doesn't match a "
15211 "later IMPLICIT type", sym
->name
, &sym
->declared_at
);
15215 /* Make sure the types of derived parameters are consistent. This
15216 type checking is deferred until resolution because the type may
15217 refer to a derived type from the host. */
15218 if (sym
->ts
.type
== BT_DERIVED
15219 && !gfc_compare_types (&sym
->ts
, &sym
->value
->ts
))
15221 gfc_error ("Incompatible derived type in PARAMETER at %L",
15222 &sym
->value
->where
);
15226 /* F03:C509,C514. */
15227 if (sym
->ts
.type
== BT_CLASS
)
15229 gfc_error ("CLASS variable %qs at %L cannot have the PARAMETER attribute",
15230 sym
->name
, &sym
->declared_at
);
15238 /* Called by resolve_symbol to check PDTs. */
15241 resolve_pdt (gfc_symbol
* sym
)
15243 gfc_symbol
*derived
= NULL
;
15244 gfc_actual_arglist
*param
;
15246 bool const_len_exprs
= true;
15247 bool assumed_len_exprs
= false;
15248 symbol_attribute
*attr
;
15250 if (sym
->ts
.type
== BT_DERIVED
)
15252 derived
= sym
->ts
.u
.derived
;
15253 attr
= &(sym
->attr
);
15255 else if (sym
->ts
.type
== BT_CLASS
)
15257 derived
= CLASS_DATA (sym
)->ts
.u
.derived
;
15258 attr
= &(CLASS_DATA (sym
)->attr
);
15261 gcc_unreachable ();
15263 gcc_assert (derived
->attr
.pdt_type
);
15265 for (param
= sym
->param_list
; param
; param
= param
->next
)
15267 c
= gfc_find_component (derived
, param
->name
, false, true, NULL
);
15269 if (c
->attr
.pdt_kind
)
15272 if (param
->expr
&& !gfc_is_constant_expr (param
->expr
)
15273 && c
->attr
.pdt_len
)
15274 const_len_exprs
= false;
15275 else if (param
->spec_type
== SPEC_ASSUMED
)
15276 assumed_len_exprs
= true;
15278 if (param
->spec_type
== SPEC_DEFERRED
15279 && !attr
->allocatable
&& !attr
->pointer
)
15280 gfc_error ("The object %qs at %L has a deferred LEN "
15281 "parameter %qs and is neither allocatable "
15282 "nor a pointer", sym
->name
, &sym
->declared_at
,
15287 if (!const_len_exprs
15288 && (sym
->ns
->proc_name
->attr
.is_main_program
15289 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
15290 || sym
->attr
.save
!= SAVE_NONE
))
15291 gfc_error ("The AUTOMATIC object %qs at %L must not have the "
15292 "SAVE attribute or be a variable declared in the "
15293 "main program, a module or a submodule(F08/C513)",
15294 sym
->name
, &sym
->declared_at
);
15296 if (assumed_len_exprs
&& !(sym
->attr
.dummy
15297 || sym
->attr
.select_type_temporary
|| sym
->attr
.associate_var
))
15298 gfc_error ("The object %qs at %L with ASSUMED type parameters "
15299 "must be a dummy or a SELECT TYPE selector(F08/4.2)",
15300 sym
->name
, &sym
->declared_at
);
15304 /* Do anything necessary to resolve a symbol. Right now, we just
15305 assume that an otherwise unknown symbol is a variable. This sort
15306 of thing commonly happens for symbols in module. */
15309 resolve_symbol (gfc_symbol
*sym
)
15311 int check_constant
, mp_flag
;
15312 gfc_symtree
*symtree
;
15313 gfc_symtree
*this_symtree
;
15316 symbol_attribute class_attr
;
15317 gfc_array_spec
*as
;
15318 bool saved_specification_expr
;
15320 if (sym
->resolve_symbol_called
>= 1)
15322 sym
->resolve_symbol_called
= 1;
15324 /* No symbol will ever have union type; only components can be unions.
15325 Union type declaration symbols have type BT_UNKNOWN but flavor FL_UNION
15326 (just like derived type declaration symbols have flavor FL_DERIVED). */
15327 gcc_assert (sym
->ts
.type
!= BT_UNION
);
15329 /* Coarrayed polymorphic objects with allocatable or pointer components are
15330 yet unsupported for -fcoarray=lib. */
15331 if (flag_coarray
== GFC_FCOARRAY_LIB
&& sym
->ts
.type
== BT_CLASS
15332 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
15333 && CLASS_DATA (sym
)->attr
.codimension
15334 && CLASS_DATA (sym
)->ts
.u
.derived
15335 && (CLASS_DATA (sym
)->ts
.u
.derived
->attr
.alloc_comp
15336 || CLASS_DATA (sym
)->ts
.u
.derived
->attr
.pointer_comp
))
15338 gfc_error ("Sorry, allocatable/pointer components in polymorphic (CLASS) "
15339 "type coarrays at %L are unsupported", &sym
->declared_at
);
15343 if (sym
->attr
.artificial
)
15346 if (sym
->attr
.unlimited_polymorphic
)
15349 if (sym
->attr
.flavor
== FL_UNKNOWN
15350 || (sym
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.intrinsic
15351 && !sym
->attr
.generic
&& !sym
->attr
.external
15352 && sym
->attr
.if_source
== IFSRC_UNKNOWN
15353 && sym
->ts
.type
== BT_UNKNOWN
))
15356 /* If we find that a flavorless symbol is an interface in one of the
15357 parent namespaces, find its symtree in this namespace, free the
15358 symbol and set the symtree to point to the interface symbol. */
15359 for (ns
= gfc_current_ns
->parent
; ns
; ns
= ns
->parent
)
15361 symtree
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
15362 if (symtree
&& (symtree
->n
.sym
->generic
||
15363 (symtree
->n
.sym
->attr
.flavor
== FL_PROCEDURE
15364 && sym
->ns
->construct_entities
)))
15366 this_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
15368 if (this_symtree
->n
.sym
== sym
)
15370 symtree
->n
.sym
->refs
++;
15371 gfc_release_symbol (sym
);
15372 this_symtree
->n
.sym
= symtree
->n
.sym
;
15378 /* Otherwise give it a flavor according to such attributes as
15380 if (sym
->attr
.flavor
== FL_UNKNOWN
&& sym
->attr
.external
== 0
15381 && sym
->attr
.intrinsic
== 0)
15382 sym
->attr
.flavor
= FL_VARIABLE
;
15383 else if (sym
->attr
.flavor
== FL_UNKNOWN
)
15385 sym
->attr
.flavor
= FL_PROCEDURE
;
15386 if (sym
->attr
.dimension
)
15387 sym
->attr
.function
= 1;
15391 if (sym
->attr
.external
&& sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.function
)
15392 gfc_add_function (&sym
->attr
, sym
->name
, &sym
->declared_at
);
15394 if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
15395 && !resolve_procedure_interface (sym
))
15398 if (sym
->attr
.is_protected
&& !sym
->attr
.proc_pointer
15399 && (sym
->attr
.procedure
|| sym
->attr
.external
))
15401 if (sym
->attr
.external
)
15402 gfc_error ("PROTECTED attribute conflicts with EXTERNAL attribute "
15403 "at %L", &sym
->declared_at
);
15405 gfc_error ("PROCEDURE attribute conflicts with PROTECTED attribute "
15406 "at %L", &sym
->declared_at
);
15411 if (sym
->attr
.flavor
== FL_DERIVED
&& !resolve_fl_derived (sym
))
15414 else if ((sym
->attr
.flavor
== FL_STRUCT
|| sym
->attr
.flavor
== FL_UNION
)
15415 && !resolve_fl_struct (sym
))
15418 /* Symbols that are module procedures with results (functions) have
15419 the types and array specification copied for type checking in
15420 procedures that call them, as well as for saving to a module
15421 file. These symbols can't stand the scrutiny that their results
15423 mp_flag
= (sym
->result
!= NULL
&& sym
->result
!= sym
);
15425 /* Make sure that the intrinsic is consistent with its internal
15426 representation. This needs to be done before assigning a default
15427 type to avoid spurious warnings. */
15428 if (sym
->attr
.flavor
!= FL_MODULE
&& sym
->attr
.intrinsic
15429 && !gfc_resolve_intrinsic (sym
, &sym
->declared_at
))
15432 /* Resolve associate names. */
15434 resolve_assoc_var (sym
, true);
15436 /* Assign default type to symbols that need one and don't have one. */
15437 if (sym
->ts
.type
== BT_UNKNOWN
)
15439 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
)
15441 gfc_set_default_type (sym
, 1, NULL
);
15444 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.external
15445 && !sym
->attr
.function
&& !sym
->attr
.subroutine
15446 && gfc_get_default_type (sym
->name
, sym
->ns
)->type
== BT_UNKNOWN
)
15447 gfc_add_subroutine (&sym
->attr
, sym
->name
, &sym
->declared_at
);
15449 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
15451 /* The specific case of an external procedure should emit an error
15452 in the case that there is no implicit type. */
15455 if (!sym
->attr
.mixed_entry_master
)
15456 gfc_set_default_type (sym
, sym
->attr
.external
, NULL
);
15460 /* Result may be in another namespace. */
15461 resolve_symbol (sym
->result
);
15463 if (!sym
->result
->attr
.proc_pointer
)
15465 sym
->ts
= sym
->result
->ts
;
15466 sym
->as
= gfc_copy_array_spec (sym
->result
->as
);
15467 sym
->attr
.dimension
= sym
->result
->attr
.dimension
;
15468 sym
->attr
.pointer
= sym
->result
->attr
.pointer
;
15469 sym
->attr
.allocatable
= sym
->result
->attr
.allocatable
;
15470 sym
->attr
.contiguous
= sym
->result
->attr
.contiguous
;
15475 else if (mp_flag
&& sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
15477 bool saved_specification_expr
= specification_expr
;
15478 bool saved_formal_arg_flag
= formal_arg_flag
;
15480 specification_expr
= true;
15481 formal_arg_flag
= true;
15482 gfc_resolve_array_spec (sym
->result
->as
, false);
15483 formal_arg_flag
= saved_formal_arg_flag
;
15484 specification_expr
= saved_specification_expr
;
15487 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
&& sym
->ts
.u
.derived
)
15489 as
= CLASS_DATA (sym
)->as
;
15490 class_attr
= CLASS_DATA (sym
)->attr
;
15491 class_attr
.pointer
= class_attr
.class_pointer
;
15495 class_attr
= sym
->attr
;
15500 if (sym
->attr
.contiguous
15501 && (!class_attr
.dimension
15502 || (as
->type
!= AS_ASSUMED_SHAPE
&& as
->type
!= AS_ASSUMED_RANK
15503 && !class_attr
.pointer
)))
15505 gfc_error ("%qs at %L has the CONTIGUOUS attribute but is not an "
15506 "array pointer or an assumed-shape or assumed-rank array",
15507 sym
->name
, &sym
->declared_at
);
15511 /* Assumed size arrays and assumed shape arrays must be dummy
15512 arguments. Array-spec's of implied-shape should have been resolved to
15513 AS_EXPLICIT already. */
15517 /* If AS_IMPLIED_SHAPE makes it to here, it must be a bad
15518 specification expression. */
15519 if (as
->type
== AS_IMPLIED_SHAPE
)
15522 for (i
=0; i
<as
->rank
; i
++)
15524 if (as
->lower
[i
] != NULL
&& as
->upper
[i
] == NULL
)
15526 gfc_error ("Bad specification for assumed size array at %L",
15527 &as
->lower
[i
]->where
);
15534 if (((as
->type
== AS_ASSUMED_SIZE
&& !as
->cp_was_assumed
)
15535 || as
->type
== AS_ASSUMED_SHAPE
)
15536 && !sym
->attr
.dummy
&& !sym
->attr
.select_type_temporary
)
15538 if (as
->type
== AS_ASSUMED_SIZE
)
15539 gfc_error ("Assumed size array at %L must be a dummy argument",
15540 &sym
->declared_at
);
15542 gfc_error ("Assumed shape array at %L must be a dummy argument",
15543 &sym
->declared_at
);
15546 /* TS 29113, C535a. */
15547 if (as
->type
== AS_ASSUMED_RANK
&& !sym
->attr
.dummy
15548 && !sym
->attr
.select_type_temporary
15549 && !(cs_base
&& cs_base
->current
15550 && cs_base
->current
->op
== EXEC_SELECT_RANK
))
15552 gfc_error ("Assumed-rank array at %L must be a dummy argument",
15553 &sym
->declared_at
);
15556 if (as
->type
== AS_ASSUMED_RANK
15557 && (sym
->attr
.codimension
|| sym
->attr
.value
))
15559 gfc_error ("Assumed-rank array at %L may not have the VALUE or "
15560 "CODIMENSION attribute", &sym
->declared_at
);
15565 /* Make sure symbols with known intent or optional are really dummy
15566 variable. Because of ENTRY statement, this has to be deferred
15567 until resolution time. */
15569 if (!sym
->attr
.dummy
15570 && (sym
->attr
.optional
|| sym
->attr
.intent
!= INTENT_UNKNOWN
))
15572 gfc_error ("Symbol at %L is not a DUMMY variable", &sym
->declared_at
);
15576 if (sym
->attr
.value
&& !sym
->attr
.dummy
)
15578 gfc_error ("%qs at %L cannot have the VALUE attribute because "
15579 "it is not a dummy argument", sym
->name
, &sym
->declared_at
);
15583 if (sym
->attr
.value
&& sym
->ts
.type
== BT_CHARACTER
)
15585 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
15586 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
15588 gfc_error ("Character dummy variable %qs at %L with VALUE "
15589 "attribute must have constant length",
15590 sym
->name
, &sym
->declared_at
);
15594 if (sym
->ts
.is_c_interop
15595 && mpz_cmp_si (cl
->length
->value
.integer
, 1) != 0)
15597 gfc_error ("C interoperable character dummy variable %qs at %L "
15598 "with VALUE attribute must have length one",
15599 sym
->name
, &sym
->declared_at
);
15604 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
15605 && sym
->ts
.u
.derived
->attr
.generic
)
15607 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
15608 if (!sym
->ts
.u
.derived
)
15610 gfc_error ("The derived type %qs at %L is of type %qs, "
15611 "which has not been defined", sym
->name
,
15612 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
15613 sym
->ts
.type
= BT_UNKNOWN
;
15618 /* Use the same constraints as TYPE(*), except for the type check
15619 and that only scalars and assumed-size arrays are permitted. */
15620 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
15622 if (!sym
->attr
.dummy
)
15624 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
15625 "a dummy argument", sym
->name
, &sym
->declared_at
);
15629 if (sym
->ts
.type
!= BT_ASSUMED
&& sym
->ts
.type
!= BT_INTEGER
15630 && sym
->ts
.type
!= BT_REAL
&& sym
->ts
.type
!= BT_LOGICAL
15631 && sym
->ts
.type
!= BT_COMPLEX
)
15633 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
15634 "of type TYPE(*) or of an numeric intrinsic type",
15635 sym
->name
, &sym
->declared_at
);
15639 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
15640 || sym
->attr
.pointer
|| sym
->attr
.value
)
15642 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
15643 "have the ALLOCATABLE, CODIMENSION, POINTER or VALUE "
15644 "attribute", sym
->name
, &sym
->declared_at
);
15648 if (sym
->attr
.intent
== INTENT_OUT
)
15650 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
15651 "have the INTENT(OUT) attribute",
15652 sym
->name
, &sym
->declared_at
);
15655 if (sym
->attr
.dimension
&& sym
->as
->type
!= AS_ASSUMED_SIZE
)
15657 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall "
15658 "either be a scalar or an assumed-size array",
15659 sym
->name
, &sym
->declared_at
);
15663 /* Set the type to TYPE(*) and add a dimension(*) to ensure
15664 NO_ARG_CHECK is correctly handled in trans*.c, e.g. with
15666 sym
->ts
.type
= BT_ASSUMED
;
15667 sym
->as
= gfc_get_array_spec ();
15668 sym
->as
->type
= AS_ASSUMED_SIZE
;
15670 sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
15672 else if (sym
->ts
.type
== BT_ASSUMED
)
15674 /* TS 29113, C407a. */
15675 if (!sym
->attr
.dummy
)
15677 gfc_error ("Assumed type of variable %s at %L is only permitted "
15678 "for dummy variables", sym
->name
, &sym
->declared_at
);
15681 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
15682 || sym
->attr
.pointer
|| sym
->attr
.value
)
15684 gfc_error ("Assumed-type variable %s at %L may not have the "
15685 "ALLOCATABLE, CODIMENSION, POINTER or VALUE attribute",
15686 sym
->name
, &sym
->declared_at
);
15689 if (sym
->attr
.intent
== INTENT_OUT
)
15691 gfc_error ("Assumed-type variable %s at %L may not have the "
15692 "INTENT(OUT) attribute",
15693 sym
->name
, &sym
->declared_at
);
15696 if (sym
->attr
.dimension
&& sym
->as
->type
== AS_EXPLICIT
)
15698 gfc_error ("Assumed-type variable %s at %L shall not be an "
15699 "explicit-shape array", sym
->name
, &sym
->declared_at
);
15704 /* If the symbol is marked as bind(c), that it is declared at module level
15705 scope and verify its type and kind. Do not do the latter for symbols
15706 that are implicitly typed because that is handled in
15707 gfc_set_default_type. Handle dummy arguments and procedure definitions
15708 separately. Also, anything that is use associated is not handled here
15709 but instead is handled in the module it is declared in. Finally, derived
15710 type definitions are allowed to be BIND(C) since that only implies that
15711 they're interoperable, and they are checked fully for interoperability
15712 when a variable is declared of that type. */
15713 if (sym
->attr
.is_bind_c
&& sym
->attr
.use_assoc
== 0
15714 && sym
->attr
.dummy
== 0 && sym
->attr
.flavor
!= FL_PROCEDURE
15715 && sym
->attr
.flavor
!= FL_DERIVED
)
15719 /* First, make sure the variable is declared at the
15720 module-level scope (J3/04-007, Section 15.3). */
15721 if (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
&&
15722 sym
->attr
.in_common
== 0)
15724 gfc_error ("Variable %qs at %L cannot be BIND(C) because it "
15725 "is neither a COMMON block nor declared at the "
15726 "module level scope", sym
->name
, &(sym
->declared_at
));
15729 else if (sym
->ts
.type
== BT_CHARACTER
15730 && (sym
->ts
.u
.cl
== NULL
|| sym
->ts
.u
.cl
->length
== NULL
15731 || !gfc_is_constant_expr (sym
->ts
.u
.cl
->length
)
15732 || mpz_cmp_si (sym
->ts
.u
.cl
->length
->value
.integer
, 1) != 0))
15734 gfc_error ("BIND(C) Variable %qs at %L must have length one",
15735 sym
->name
, &sym
->declared_at
);
15738 else if (sym
->common_head
!= NULL
&& sym
->attr
.implicit_type
== 0)
15740 t
= verify_com_block_vars_c_interop (sym
->common_head
);
15742 else if (sym
->attr
.implicit_type
== 0)
15744 /* If type() declaration, we need to verify that the components
15745 of the given type are all C interoperable, etc. */
15746 if (sym
->ts
.type
== BT_DERIVED
&&
15747 sym
->ts
.u
.derived
->attr
.is_c_interop
!= 1)
15749 /* Make sure the user marked the derived type as BIND(C). If
15750 not, call the verify routine. This could print an error
15751 for the derived type more than once if multiple variables
15752 of that type are declared. */
15753 if (sym
->ts
.u
.derived
->attr
.is_bind_c
!= 1)
15754 verify_bind_c_derived_type (sym
->ts
.u
.derived
);
15758 /* Verify the variable itself as C interoperable if it
15759 is BIND(C). It is not possible for this to succeed if
15760 the verify_bind_c_derived_type failed, so don't have to handle
15761 any error returned by verify_bind_c_derived_type. */
15762 t
= verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
15763 sym
->common_block
);
15768 /* clear the is_bind_c flag to prevent reporting errors more than
15769 once if something failed. */
15770 sym
->attr
.is_bind_c
= 0;
15775 /* If a derived type symbol has reached this point, without its
15776 type being declared, we have an error. Notice that most
15777 conditions that produce undefined derived types have already
15778 been dealt with. However, the likes of:
15779 implicit type(t) (t) ..... call foo (t) will get us here if
15780 the type is not declared in the scope of the implicit
15781 statement. Change the type to BT_UNKNOWN, both because it is so
15782 and to prevent an ICE. */
15783 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
15784 && sym
->ts
.u
.derived
->components
== NULL
15785 && !sym
->ts
.u
.derived
->attr
.zero_comp
)
15787 gfc_error ("The derived type %qs at %L is of type %qs, "
15788 "which has not been defined", sym
->name
,
15789 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
15790 sym
->ts
.type
= BT_UNKNOWN
;
15794 /* Make sure that the derived type has been resolved and that the
15795 derived type is visible in the symbol's namespace, if it is a
15796 module function and is not PRIVATE. */
15797 if (sym
->ts
.type
== BT_DERIVED
15798 && sym
->ts
.u
.derived
->attr
.use_assoc
15799 && sym
->ns
->proc_name
15800 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
15801 && !resolve_fl_derived (sym
->ts
.u
.derived
))
15804 /* Unless the derived-type declaration is use associated, Fortran 95
15805 does not allow public entries of private derived types.
15806 See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
15807 161 in 95-006r3. */
15808 if (sym
->ts
.type
== BT_DERIVED
15809 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
15810 && !sym
->ts
.u
.derived
->attr
.use_assoc
15811 && gfc_check_symbol_access (sym
)
15812 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
15813 && !gfc_notify_std (GFC_STD_F2003
, "PUBLIC %s %qs at %L of PRIVATE "
15814 "derived type %qs",
15815 (sym
->attr
.flavor
== FL_PARAMETER
)
15816 ? "parameter" : "variable",
15817 sym
->name
, &sym
->declared_at
,
15818 sym
->ts
.u
.derived
->name
))
15821 /* F2008, C1302. */
15822 if (sym
->ts
.type
== BT_DERIVED
15823 && ((sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
15824 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
15825 || sym
->ts
.u
.derived
->attr
.lock_comp
)
15826 && !sym
->attr
.codimension
&& !sym
->ts
.u
.derived
->attr
.coarray_comp
)
15828 gfc_error ("Variable %s at %L of type LOCK_TYPE or with subcomponent of "
15829 "type LOCK_TYPE must be a coarray", sym
->name
,
15830 &sym
->declared_at
);
15834 /* TS18508, C702/C703. */
15835 if (sym
->ts
.type
== BT_DERIVED
15836 && ((sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
15837 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
15838 || sym
->ts
.u
.derived
->attr
.event_comp
)
15839 && !sym
->attr
.codimension
&& !sym
->ts
.u
.derived
->attr
.coarray_comp
)
15841 gfc_error ("Variable %s at %L of type EVENT_TYPE or with subcomponent of "
15842 "type EVENT_TYPE must be a coarray", sym
->name
,
15843 &sym
->declared_at
);
15847 /* An assumed-size array with INTENT(OUT) shall not be of a type for which
15848 default initialization is defined (5.1.2.4.4). */
15849 if (sym
->ts
.type
== BT_DERIVED
15851 && sym
->attr
.intent
== INTENT_OUT
15853 && sym
->as
->type
== AS_ASSUMED_SIZE
)
15855 for (c
= sym
->ts
.u
.derived
->components
; c
; c
= c
->next
)
15857 if (c
->initializer
)
15859 gfc_error ("The INTENT(OUT) dummy argument %qs at %L is "
15860 "ASSUMED SIZE and so cannot have a default initializer",
15861 sym
->name
, &sym
->declared_at
);
15868 if (sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.dummy
15869 && sym
->attr
.intent
== INTENT_OUT
&& sym
->attr
.lock_comp
)
15871 gfc_error ("Dummy argument %qs at %L of LOCK_TYPE shall not be "
15872 "INTENT(OUT)", sym
->name
, &sym
->declared_at
);
15877 if (sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.dummy
15878 && sym
->attr
.intent
== INTENT_OUT
&& sym
->attr
.event_comp
)
15880 gfc_error ("Dummy argument %qs at %L of EVENT_TYPE shall not be "
15881 "INTENT(OUT)", sym
->name
, &sym
->declared_at
);
15886 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
15887 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
15888 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
15889 && CLASS_DATA (sym
)->attr
.coarray_comp
))
15890 || class_attr
.codimension
)
15891 && (sym
->attr
.result
|| sym
->result
== sym
))
15893 gfc_error ("Function result %qs at %L shall not be a coarray or have "
15894 "a coarray component", sym
->name
, &sym
->declared_at
);
15899 if (sym
->attr
.codimension
&& sym
->ts
.type
== BT_DERIVED
15900 && sym
->ts
.u
.derived
->ts
.is_iso_c
)
15902 gfc_error ("Variable %qs at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
15903 "shall not be a coarray", sym
->name
, &sym
->declared_at
);
15908 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
15909 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
15910 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
15911 && CLASS_DATA (sym
)->attr
.coarray_comp
))
15912 && (class_attr
.codimension
|| class_attr
.pointer
|| class_attr
.dimension
15913 || class_attr
.allocatable
))
15915 gfc_error ("Variable %qs at %L with coarray component shall be a "
15916 "nonpointer, nonallocatable scalar, which is not a coarray",
15917 sym
->name
, &sym
->declared_at
);
15921 /* F2008, C526. The function-result case was handled above. */
15922 if (class_attr
.codimension
15923 && !(class_attr
.allocatable
|| sym
->attr
.dummy
|| sym
->attr
.save
15924 || sym
->attr
.select_type_temporary
15925 || sym
->attr
.associate_var
15926 || (sym
->ns
->save_all
&& !sym
->attr
.automatic
)
15927 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
15928 || sym
->ns
->proc_name
->attr
.is_main_program
15929 || sym
->attr
.function
|| sym
->attr
.result
|| sym
->attr
.use_assoc
))
15931 gfc_error ("Variable %qs at %L is a coarray and is not ALLOCATABLE, SAVE "
15932 "nor a dummy argument", sym
->name
, &sym
->declared_at
);
15936 else if (class_attr
.codimension
&& !sym
->attr
.select_type_temporary
15937 && !class_attr
.allocatable
&& as
&& as
->cotype
== AS_DEFERRED
)
15939 gfc_error ("Coarray variable %qs at %L shall not have codimensions with "
15940 "deferred shape", sym
->name
, &sym
->declared_at
);
15943 else if (class_attr
.codimension
&& class_attr
.allocatable
&& as
15944 && (as
->cotype
!= AS_DEFERRED
|| as
->type
!= AS_DEFERRED
))
15946 gfc_error ("Allocatable coarray variable %qs at %L must have "
15947 "deferred shape", sym
->name
, &sym
->declared_at
);
15952 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
15953 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
15954 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
15955 && CLASS_DATA (sym
)->attr
.coarray_comp
))
15956 || (class_attr
.codimension
&& class_attr
.allocatable
))
15957 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
)
15959 gfc_error ("Variable %qs at %L is INTENT(OUT) and can thus not be an "
15960 "allocatable coarray or have coarray components",
15961 sym
->name
, &sym
->declared_at
);
15965 if (class_attr
.codimension
&& sym
->attr
.dummy
15966 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.is_bind_c
)
15968 gfc_error ("Coarray dummy variable %qs at %L not allowed in BIND(C) "
15969 "procedure %qs", sym
->name
, &sym
->declared_at
,
15970 sym
->ns
->proc_name
->name
);
15974 if (sym
->ts
.type
== BT_LOGICAL
15975 && ((sym
->attr
.function
&& sym
->attr
.is_bind_c
&& sym
->result
== sym
)
15976 || ((sym
->attr
.dummy
|| sym
->attr
.result
) && sym
->ns
->proc_name
15977 && sym
->ns
->proc_name
->attr
.is_bind_c
)))
15980 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
15981 if (gfc_logical_kinds
[i
].kind
== sym
->ts
.kind
)
15983 if (!gfc_logical_kinds
[i
].c_bool
&& sym
->attr
.dummy
15984 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL dummy argument %qs at "
15985 "%L with non-C_Bool kind in BIND(C) procedure "
15986 "%qs", sym
->name
, &sym
->declared_at
,
15987 sym
->ns
->proc_name
->name
))
15989 else if (!gfc_logical_kinds
[i
].c_bool
15990 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL result variable "
15991 "%qs at %L with non-C_Bool kind in "
15992 "BIND(C) procedure %qs", sym
->name
,
15994 sym
->attr
.function
? sym
->name
15995 : sym
->ns
->proc_name
->name
))
15999 switch (sym
->attr
.flavor
)
16002 if (!resolve_fl_variable (sym
, mp_flag
))
16007 if (sym
->formal
&& !sym
->formal_ns
)
16009 /* Check that none of the arguments are a namelist. */
16010 gfc_formal_arglist
*formal
= sym
->formal
;
16012 for (; formal
; formal
= formal
->next
)
16013 if (formal
->sym
&& formal
->sym
->attr
.flavor
== FL_NAMELIST
)
16015 gfc_error ("Namelist %qs cannot be an argument to "
16016 "subroutine or function at %L",
16017 formal
->sym
->name
, &sym
->declared_at
);
16022 if (!resolve_fl_procedure (sym
, mp_flag
))
16027 if (!resolve_fl_namelist (sym
))
16032 if (!resolve_fl_parameter (sym
))
16040 /* Resolve array specifier. Check as well some constraints
16041 on COMMON blocks. */
16043 check_constant
= sym
->attr
.in_common
&& !sym
->attr
.pointer
;
16045 /* Set the formal_arg_flag so that check_conflict will not throw
16046 an error for host associated variables in the specification
16047 expression for an array_valued function. */
16048 if ((sym
->attr
.function
|| sym
->attr
.result
) && sym
->as
)
16049 formal_arg_flag
= true;
16051 saved_specification_expr
= specification_expr
;
16052 specification_expr
= true;
16053 gfc_resolve_array_spec (sym
->as
, check_constant
);
16054 specification_expr
= saved_specification_expr
;
16056 formal_arg_flag
= false;
16058 /* Resolve formal namespaces. */
16059 if (sym
->formal_ns
&& sym
->formal_ns
!= gfc_current_ns
16060 && !sym
->attr
.contained
&& !sym
->attr
.intrinsic
)
16061 gfc_resolve (sym
->formal_ns
);
16063 /* Make sure the formal namespace is present. */
16064 if (sym
->formal
&& !sym
->formal_ns
)
16066 gfc_formal_arglist
*formal
= sym
->formal
;
16067 while (formal
&& !formal
->sym
)
16068 formal
= formal
->next
;
16072 sym
->formal_ns
= formal
->sym
->ns
;
16073 if (sym
->formal_ns
&& sym
->ns
!= formal
->sym
->ns
)
16074 sym
->formal_ns
->refs
++;
16078 /* Check threadprivate restrictions. */
16079 if (sym
->attr
.threadprivate
16080 && !(sym
->attr
.save
|| sym
->attr
.data
|| sym
->attr
.in_common
)
16081 && !(sym
->ns
->save_all
&& !sym
->attr
.automatic
)
16082 && sym
->module
== NULL
16083 && (sym
->ns
->proc_name
== NULL
16084 || (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
16085 && !sym
->ns
->proc_name
->attr
.is_main_program
)))
16086 gfc_error ("Threadprivate at %L isn't SAVEd", &sym
->declared_at
);
16088 /* Check omp declare target restrictions. */
16089 if (sym
->attr
.omp_declare_target
16090 && sym
->attr
.flavor
== FL_VARIABLE
16092 && !(sym
->ns
->save_all
&& !sym
->attr
.automatic
)
16093 && (!sym
->attr
.in_common
16094 && sym
->module
== NULL
16095 && (sym
->ns
->proc_name
== NULL
16096 || (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
16097 && !sym
->ns
->proc_name
->attr
.is_main_program
))))
16098 gfc_error ("!$OMP DECLARE TARGET variable %qs at %L isn't SAVEd",
16099 sym
->name
, &sym
->declared_at
);
16101 /* If we have come this far we can apply default-initializers, as
16102 described in 14.7.5, to those variables that have not already
16103 been assigned one. */
16104 if (sym
->ts
.type
== BT_DERIVED
16106 && !sym
->attr
.allocatable
16107 && !sym
->attr
.alloc_comp
)
16109 symbol_attribute
*a
= &sym
->attr
;
16111 if ((!a
->save
&& !a
->dummy
&& !a
->pointer
16112 && !a
->in_common
&& !a
->use_assoc
16114 && !((a
->function
|| a
->result
)
16116 || sym
->ts
.u
.derived
->attr
.alloc_comp
16117 || sym
->ts
.u
.derived
->attr
.pointer_comp
))
16118 && !(a
->function
&& sym
!= sym
->result
))
16119 || (a
->dummy
&& a
->intent
== INTENT_OUT
&& !a
->pointer
))
16120 apply_default_init (sym
);
16121 else if (a
->function
&& sym
->result
&& a
->access
!= ACCESS_PRIVATE
16122 && (sym
->ts
.u
.derived
->attr
.alloc_comp
16123 || sym
->ts
.u
.derived
->attr
.pointer_comp
))
16124 /* Mark the result symbol to be referenced, when it has allocatable
16126 sym
->result
->attr
.referenced
= 1;
16129 if (sym
->ts
.type
== BT_CLASS
&& sym
->ns
== gfc_current_ns
16130 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
16131 && !CLASS_DATA (sym
)->attr
.class_pointer
16132 && !CLASS_DATA (sym
)->attr
.allocatable
)
16133 apply_default_init (sym
);
16135 /* If this symbol has a type-spec, check it. */
16136 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
16137 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
))
16138 if (!resolve_typespec_used (&sym
->ts
, &sym
->declared_at
, sym
->name
))
16141 if (sym
->param_list
)
16146 /************* Resolve DATA statements *************/
16150 gfc_data_value
*vnode
;
16156 /* Advance the values structure to point to the next value in the data list. */
16159 next_data_value (void)
16161 while (mpz_cmp_ui (values
.left
, 0) == 0)
16164 if (values
.vnode
->next
== NULL
)
16167 values
.vnode
= values
.vnode
->next
;
16168 mpz_set (values
.left
, values
.vnode
->repeat
);
16176 check_data_variable (gfc_data_variable
*var
, locus
*where
)
16182 ar_type mark
= AR_UNKNOWN
;
16184 mpz_t section_index
[GFC_MAX_DIMENSIONS
];
16190 if (!gfc_resolve_expr (var
->expr
))
16194 mpz_init_set_si (offset
, 0);
16197 if (e
->expr_type
== EXPR_FUNCTION
&& e
->value
.function
.isym
16198 && e
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
16199 e
= e
->value
.function
.actual
->expr
;
16201 if (e
->expr_type
!= EXPR_VARIABLE
)
16203 gfc_error ("Expecting definable entity near %L", where
);
16207 sym
= e
->symtree
->n
.sym
;
16209 if (sym
->ns
->is_block_data
&& !sym
->attr
.in_common
)
16211 gfc_error ("BLOCK DATA element %qs at %L must be in COMMON",
16212 sym
->name
, &sym
->declared_at
);
16216 if (e
->ref
== NULL
&& sym
->as
)
16218 gfc_error ("DATA array %qs at %L must be specified in a previous"
16219 " declaration", sym
->name
, where
);
16223 if (gfc_is_coindexed (e
))
16225 gfc_error ("DATA element %qs at %L cannot have a coindex", sym
->name
,
16230 has_pointer
= sym
->attr
.pointer
;
16232 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
16234 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.pointer
)
16239 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.type
!= AR_FULL
)
16241 gfc_error ("DATA element %qs at %L is a pointer and so must "
16242 "be a full array", sym
->name
, where
);
16246 if (values
.vnode
->expr
->expr_type
== EXPR_CONSTANT
)
16248 gfc_error ("DATA object near %L has the pointer attribute "
16249 "and the corresponding DATA value is not a valid "
16250 "initial-data-target", where
);
16255 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.allocatable
)
16257 gfc_error ("DATA element %qs at %L cannot have the ALLOCATABLE "
16258 "attribute", ref
->u
.c
.component
->name
, &e
->where
);
16263 if (e
->rank
== 0 || has_pointer
)
16265 mpz_init_set_ui (size
, 1);
16272 /* Find the array section reference. */
16273 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
16275 if (ref
->type
!= REF_ARRAY
)
16277 if (ref
->u
.ar
.type
== AR_ELEMENT
)
16283 /* Set marks according to the reference pattern. */
16284 switch (ref
->u
.ar
.type
)
16292 /* Get the start position of array section. */
16293 gfc_get_section_index (ar
, section_index
, &offset
);
16298 gcc_unreachable ();
16301 if (!gfc_array_size (e
, &size
))
16303 gfc_error ("Nonconstant array section at %L in DATA statement",
16305 mpz_clear (offset
);
16312 while (mpz_cmp_ui (size
, 0) > 0)
16314 if (!next_data_value ())
16316 gfc_error ("DATA statement at %L has more variables than values",
16322 t
= gfc_check_assign (var
->expr
, values
.vnode
->expr
, 0);
16326 /* If we have more than one element left in the repeat count,
16327 and we have more than one element left in the target variable,
16328 then create a range assignment. */
16329 /* FIXME: Only done for full arrays for now, since array sections
16331 if (mark
== AR_FULL
&& ref
&& ref
->next
== NULL
16332 && mpz_cmp_ui (values
.left
, 1) > 0 && mpz_cmp_ui (size
, 1) > 0)
16336 if (mpz_cmp (size
, values
.left
) >= 0)
16338 mpz_init_set (range
, values
.left
);
16339 mpz_sub (size
, size
, values
.left
);
16340 mpz_set_ui (values
.left
, 0);
16344 mpz_init_set (range
, size
);
16345 mpz_sub (values
.left
, values
.left
, size
);
16346 mpz_set_ui (size
, 0);
16349 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
16352 mpz_add (offset
, offset
, range
);
16359 /* Assign initial value to symbol. */
16362 mpz_sub_ui (values
.left
, values
.left
, 1);
16363 mpz_sub_ui (size
, size
, 1);
16365 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
16370 if (mark
== AR_FULL
)
16371 mpz_add_ui (offset
, offset
, 1);
16373 /* Modify the array section indexes and recalculate the offset
16374 for next element. */
16375 else if (mark
== AR_SECTION
)
16376 gfc_advance_section (section_index
, ar
, &offset
);
16380 if (mark
== AR_SECTION
)
16382 for (i
= 0; i
< ar
->dimen
; i
++)
16383 mpz_clear (section_index
[i
]);
16387 mpz_clear (offset
);
16393 static bool traverse_data_var (gfc_data_variable
*, locus
*);
16395 /* Iterate over a list of elements in a DATA statement. */
16398 traverse_data_list (gfc_data_variable
*var
, locus
*where
)
16401 iterator_stack frame
;
16402 gfc_expr
*e
, *start
, *end
, *step
;
16403 bool retval
= true;
16405 mpz_init (frame
.value
);
16408 start
= gfc_copy_expr (var
->iter
.start
);
16409 end
= gfc_copy_expr (var
->iter
.end
);
16410 step
= gfc_copy_expr (var
->iter
.step
);
16412 if (!gfc_simplify_expr (start
, 1)
16413 || start
->expr_type
!= EXPR_CONSTANT
)
16415 gfc_error ("start of implied-do loop at %L could not be "
16416 "simplified to a constant value", &start
->where
);
16420 if (!gfc_simplify_expr (end
, 1)
16421 || end
->expr_type
!= EXPR_CONSTANT
)
16423 gfc_error ("end of implied-do loop at %L could not be "
16424 "simplified to a constant value", &end
->where
);
16428 if (!gfc_simplify_expr (step
, 1)
16429 || step
->expr_type
!= EXPR_CONSTANT
)
16431 gfc_error ("step of implied-do loop at %L could not be "
16432 "simplified to a constant value", &step
->where
);
16436 if (mpz_cmp_si (step
->value
.integer
, 0) == 0)
16438 gfc_error ("step of implied-do loop at %L shall not be zero",
16444 mpz_set (trip
, end
->value
.integer
);
16445 mpz_sub (trip
, trip
, start
->value
.integer
);
16446 mpz_add (trip
, trip
, step
->value
.integer
);
16448 mpz_div (trip
, trip
, step
->value
.integer
);
16450 mpz_set (frame
.value
, start
->value
.integer
);
16452 frame
.prev
= iter_stack
;
16453 frame
.variable
= var
->iter
.var
->symtree
;
16454 iter_stack
= &frame
;
16456 while (mpz_cmp_ui (trip
, 0) > 0)
16458 if (!traverse_data_var (var
->list
, where
))
16464 e
= gfc_copy_expr (var
->expr
);
16465 if (!gfc_simplify_expr (e
, 1))
16472 mpz_add (frame
.value
, frame
.value
, step
->value
.integer
);
16474 mpz_sub_ui (trip
, trip
, 1);
16478 mpz_clear (frame
.value
);
16481 gfc_free_expr (start
);
16482 gfc_free_expr (end
);
16483 gfc_free_expr (step
);
16485 iter_stack
= frame
.prev
;
16490 /* Type resolve variables in the variable list of a DATA statement. */
16493 traverse_data_var (gfc_data_variable
*var
, locus
*where
)
16497 for (; var
; var
= var
->next
)
16499 if (var
->expr
== NULL
)
16500 t
= traverse_data_list (var
, where
);
16502 t
= check_data_variable (var
, where
);
16512 /* Resolve the expressions and iterators associated with a data statement.
16513 This is separate from the assignment checking because data lists should
16514 only be resolved once. */
16517 resolve_data_variables (gfc_data_variable
*d
)
16519 for (; d
; d
= d
->next
)
16521 if (d
->list
== NULL
)
16523 if (!gfc_resolve_expr (d
->expr
))
16528 if (!gfc_resolve_iterator (&d
->iter
, false, true))
16531 if (!resolve_data_variables (d
->list
))
16540 /* Resolve a single DATA statement. We implement this by storing a pointer to
16541 the value list into static variables, and then recursively traversing the
16542 variables list, expanding iterators and such. */
16545 resolve_data (gfc_data
*d
)
16548 if (!resolve_data_variables (d
->var
))
16551 values
.vnode
= d
->value
;
16552 if (d
->value
== NULL
)
16553 mpz_set_ui (values
.left
, 0);
16555 mpz_set (values
.left
, d
->value
->repeat
);
16557 if (!traverse_data_var (d
->var
, &d
->where
))
16560 /* At this point, we better not have any values left. */
16562 if (next_data_value ())
16563 gfc_error ("DATA statement at %L has more values than variables",
16568 /* 12.6 Constraint: In a pure subprogram any variable which is in common or
16569 accessed by host or use association, is a dummy argument to a pure function,
16570 is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
16571 is storage associated with any such variable, shall not be used in the
16572 following contexts: (clients of this function). */
16574 /* Determines if a variable is not 'pure', i.e., not assignable within a pure
16575 procedure. Returns zero if assignment is OK, nonzero if there is a
16578 gfc_impure_variable (gfc_symbol
*sym
)
16583 if (sym
->attr
.use_assoc
|| sym
->attr
.in_common
)
16586 /* Check if the symbol's ns is inside the pure procedure. */
16587 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
16591 if (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
16595 proc
= sym
->ns
->proc_name
;
16596 if (sym
->attr
.dummy
16597 && !sym
->attr
.value
16598 && ((proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_IN
)
16599 || proc
->attr
.function
))
16602 /* TODO: Sort out what can be storage associated, if anything, and include
16603 it here. In principle equivalences should be scanned but it does not
16604 seem to be possible to storage associate an impure variable this way. */
16609 /* Test whether a symbol is pure or not. For a NULL pointer, checks if the
16610 current namespace is inside a pure procedure. */
16613 gfc_pure (gfc_symbol
*sym
)
16615 symbol_attribute attr
;
16620 /* Check if the current namespace or one of its parents
16621 belongs to a pure procedure. */
16622 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
16624 sym
= ns
->proc_name
;
16628 if (attr
.flavor
== FL_PROCEDURE
&& attr
.pure
)
16636 return attr
.flavor
== FL_PROCEDURE
&& attr
.pure
;
16640 /* Test whether a symbol is implicitly pure or not. For a NULL pointer,
16641 checks if the current namespace is implicitly pure. Note that this
16642 function returns false for a PURE procedure. */
16645 gfc_implicit_pure (gfc_symbol
*sym
)
16651 /* Check if the current procedure is implicit_pure. Walk up
16652 the procedure list until we find a procedure. */
16653 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
16655 sym
= ns
->proc_name
;
16659 if (sym
->attr
.flavor
== FL_PROCEDURE
)
16664 return sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.implicit_pure
16665 && !sym
->attr
.pure
;
16670 gfc_unset_implicit_pure (gfc_symbol
*sym
)
16676 /* Check if the current procedure is implicit_pure. Walk up
16677 the procedure list until we find a procedure. */
16678 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
16680 sym
= ns
->proc_name
;
16684 if (sym
->attr
.flavor
== FL_PROCEDURE
)
16689 if (sym
->attr
.flavor
== FL_PROCEDURE
)
16690 sym
->attr
.implicit_pure
= 0;
16692 sym
->attr
.pure
= 0;
16696 /* Test whether the current procedure is elemental or not. */
16699 gfc_elemental (gfc_symbol
*sym
)
16701 symbol_attribute attr
;
16704 sym
= gfc_current_ns
->proc_name
;
16709 return attr
.flavor
== FL_PROCEDURE
&& attr
.elemental
;
16713 /* Warn about unused labels. */
16716 warn_unused_fortran_label (gfc_st_label
*label
)
16721 warn_unused_fortran_label (label
->left
);
16723 if (label
->defined
== ST_LABEL_UNKNOWN
)
16726 switch (label
->referenced
)
16728 case ST_LABEL_UNKNOWN
:
16729 gfc_warning (OPT_Wunused_label
, "Label %d at %L defined but not used",
16730 label
->value
, &label
->where
);
16733 case ST_LABEL_BAD_TARGET
:
16734 gfc_warning (OPT_Wunused_label
,
16735 "Label %d at %L defined but cannot be used",
16736 label
->value
, &label
->where
);
16743 warn_unused_fortran_label (label
->right
);
16747 /* Returns the sequence type of a symbol or sequence. */
16750 sequence_type (gfc_typespec ts
)
16759 if (ts
.u
.derived
->components
== NULL
)
16760 return SEQ_NONDEFAULT
;
16762 result
= sequence_type (ts
.u
.derived
->components
->ts
);
16763 for (c
= ts
.u
.derived
->components
->next
; c
; c
= c
->next
)
16764 if (sequence_type (c
->ts
) != result
)
16770 if (ts
.kind
!= gfc_default_character_kind
)
16771 return SEQ_NONDEFAULT
;
16773 return SEQ_CHARACTER
;
16776 if (ts
.kind
!= gfc_default_integer_kind
)
16777 return SEQ_NONDEFAULT
;
16779 return SEQ_NUMERIC
;
16782 if (!(ts
.kind
== gfc_default_real_kind
16783 || ts
.kind
== gfc_default_double_kind
))
16784 return SEQ_NONDEFAULT
;
16786 return SEQ_NUMERIC
;
16789 if (ts
.kind
!= gfc_default_complex_kind
)
16790 return SEQ_NONDEFAULT
;
16792 return SEQ_NUMERIC
;
16795 if (ts
.kind
!= gfc_default_logical_kind
)
16796 return SEQ_NONDEFAULT
;
16798 return SEQ_NUMERIC
;
16801 return SEQ_NONDEFAULT
;
16806 /* Resolve derived type EQUIVALENCE object. */
16809 resolve_equivalence_derived (gfc_symbol
*derived
, gfc_symbol
*sym
, gfc_expr
*e
)
16811 gfc_component
*c
= derived
->components
;
16816 /* Shall not be an object of nonsequence derived type. */
16817 if (!derived
->attr
.sequence
)
16819 gfc_error ("Derived type variable %qs at %L must have SEQUENCE "
16820 "attribute to be an EQUIVALENCE object", sym
->name
,
16825 /* Shall not have allocatable components. */
16826 if (derived
->attr
.alloc_comp
)
16828 gfc_error ("Derived type variable %qs at %L cannot have ALLOCATABLE "
16829 "components to be an EQUIVALENCE object",sym
->name
,
16834 if (sym
->attr
.in_common
&& gfc_has_default_initializer (sym
->ts
.u
.derived
))
16836 gfc_error ("Derived type variable %qs at %L with default "
16837 "initialization cannot be in EQUIVALENCE with a variable "
16838 "in COMMON", sym
->name
, &e
->where
);
16842 for (; c
; c
= c
->next
)
16844 if (gfc_bt_struct (c
->ts
.type
)
16845 && (!resolve_equivalence_derived(c
->ts
.u
.derived
, sym
, e
)))
16848 /* Shall not be an object of sequence derived type containing a pointer
16849 in the structure. */
16850 if (c
->attr
.pointer
)
16852 gfc_error ("Derived type variable %qs at %L with pointer "
16853 "component(s) cannot be an EQUIVALENCE object",
16854 sym
->name
, &e
->where
);
16862 /* Resolve equivalence object.
16863 An EQUIVALENCE object shall not be a dummy argument, a pointer, a target,
16864 an allocatable array, an object of nonsequence derived type, an object of
16865 sequence derived type containing a pointer at any level of component
16866 selection, an automatic object, a function name, an entry name, a result
16867 name, a named constant, a structure component, or a subobject of any of
16868 the preceding objects. A substring shall not have length zero. A
16869 derived type shall not have components with default initialization nor
16870 shall two objects of an equivalence group be initialized.
16871 Either all or none of the objects shall have an protected attribute.
16872 The simple constraints are done in symbol.c(check_conflict) and the rest
16873 are implemented here. */
16876 resolve_equivalence (gfc_equiv
*eq
)
16879 gfc_symbol
*first_sym
;
16882 locus
*last_where
= NULL
;
16883 seq_type eq_type
, last_eq_type
;
16884 gfc_typespec
*last_ts
;
16885 int object
, cnt_protected
;
16888 last_ts
= &eq
->expr
->symtree
->n
.sym
->ts
;
16890 first_sym
= eq
->expr
->symtree
->n
.sym
;
16894 for (object
= 1; eq
; eq
= eq
->eq
, object
++)
16898 e
->ts
= e
->symtree
->n
.sym
->ts
;
16899 /* match_varspec might not know yet if it is seeing
16900 array reference or substring reference, as it doesn't
16902 if (e
->ref
&& e
->ref
->type
== REF_ARRAY
)
16904 gfc_ref
*ref
= e
->ref
;
16905 sym
= e
->symtree
->n
.sym
;
16907 if (sym
->attr
.dimension
)
16909 ref
->u
.ar
.as
= sym
->as
;
16913 /* For substrings, convert REF_ARRAY into REF_SUBSTRING. */
16914 if (e
->ts
.type
== BT_CHARACTER
16916 && ref
->type
== REF_ARRAY
16917 && ref
->u
.ar
.dimen
== 1
16918 && ref
->u
.ar
.dimen_type
[0] == DIMEN_RANGE
16919 && ref
->u
.ar
.stride
[0] == NULL
)
16921 gfc_expr
*start
= ref
->u
.ar
.start
[0];
16922 gfc_expr
*end
= ref
->u
.ar
.end
[0];
16925 /* Optimize away the (:) reference. */
16926 if (start
== NULL
&& end
== NULL
)
16929 e
->ref
= ref
->next
;
16931 e
->ref
->next
= ref
->next
;
16936 ref
->type
= REF_SUBSTRING
;
16938 start
= gfc_get_int_expr (gfc_charlen_int_kind
,
16940 ref
->u
.ss
.start
= start
;
16941 if (end
== NULL
&& e
->ts
.u
.cl
)
16942 end
= gfc_copy_expr (e
->ts
.u
.cl
->length
);
16943 ref
->u
.ss
.end
= end
;
16944 ref
->u
.ss
.length
= e
->ts
.u
.cl
;
16951 /* Any further ref is an error. */
16954 gcc_assert (ref
->type
== REF_ARRAY
);
16955 gfc_error ("Syntax error in EQUIVALENCE statement at %L",
16961 if (!gfc_resolve_expr (e
))
16964 sym
= e
->symtree
->n
.sym
;
16966 if (sym
->attr
.is_protected
)
16968 if (cnt_protected
> 0 && cnt_protected
!= object
)
16970 gfc_error ("Either all or none of the objects in the "
16971 "EQUIVALENCE set at %L shall have the "
16972 "PROTECTED attribute",
16977 /* Shall not equivalence common block variables in a PURE procedure. */
16978 if (sym
->ns
->proc_name
16979 && sym
->ns
->proc_name
->attr
.pure
16980 && sym
->attr
.in_common
)
16982 /* Need to check for symbols that may have entered the pure
16983 procedure via a USE statement. */
16984 bool saw_sym
= false;
16985 if (sym
->ns
->use_stmts
)
16988 for (r
= sym
->ns
->use_stmts
->rename
; r
; r
= r
->next
)
16989 if (strcmp(r
->use_name
, sym
->name
) == 0) saw_sym
= true;
16995 gfc_error ("COMMON block member %qs at %L cannot be an "
16996 "EQUIVALENCE object in the pure procedure %qs",
16997 sym
->name
, &e
->where
, sym
->ns
->proc_name
->name
);
17001 /* Shall not be a named constant. */
17002 if (e
->expr_type
== EXPR_CONSTANT
)
17004 gfc_error ("Named constant %qs at %L cannot be an EQUIVALENCE "
17005 "object", sym
->name
, &e
->where
);
17009 if (e
->ts
.type
== BT_DERIVED
17010 && !resolve_equivalence_derived (e
->ts
.u
.derived
, sym
, e
))
17013 /* Check that the types correspond correctly:
17015 A numeric sequence structure may be equivalenced to another sequence
17016 structure, an object of default integer type, default real type, double
17017 precision real type, default logical type such that components of the
17018 structure ultimately only become associated to objects of the same
17019 kind. A character sequence structure may be equivalenced to an object
17020 of default character kind or another character sequence structure.
17021 Other objects may be equivalenced only to objects of the same type and
17022 kind parameters. */
17024 /* Identical types are unconditionally OK. */
17025 if (object
== 1 || gfc_compare_types (last_ts
, &sym
->ts
))
17026 goto identical_types
;
17028 last_eq_type
= sequence_type (*last_ts
);
17029 eq_type
= sequence_type (sym
->ts
);
17031 /* Since the pair of objects is not of the same type, mixed or
17032 non-default sequences can be rejected. */
17034 msg
= "Sequence %s with mixed components in EQUIVALENCE "
17035 "statement at %L with different type objects";
17037 && last_eq_type
== SEQ_MIXED
17038 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
17039 || (eq_type
== SEQ_MIXED
17040 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
17043 msg
= "Non-default type object or sequence %s in EQUIVALENCE "
17044 "statement at %L with objects of different type";
17046 && last_eq_type
== SEQ_NONDEFAULT
17047 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
17048 || (eq_type
== SEQ_NONDEFAULT
17049 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
17052 msg
="Non-CHARACTER object %qs in default CHARACTER "
17053 "EQUIVALENCE statement at %L";
17054 if (last_eq_type
== SEQ_CHARACTER
17055 && eq_type
!= SEQ_CHARACTER
17056 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
17059 msg
="Non-NUMERIC object %qs in default NUMERIC "
17060 "EQUIVALENCE statement at %L";
17061 if (last_eq_type
== SEQ_NUMERIC
17062 && eq_type
!= SEQ_NUMERIC
17063 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
17069 last_where
= &e
->where
;
17074 /* Shall not be an automatic array. */
17075 if (e
->ref
->type
== REF_ARRAY
&& is_non_constant_shape_array (sym
))
17077 gfc_error ("Array %qs at %L with non-constant bounds cannot be "
17078 "an EQUIVALENCE object", sym
->name
, &e
->where
);
17085 /* Shall not be a structure component. */
17086 if (r
->type
== REF_COMPONENT
)
17088 gfc_error ("Structure component %qs at %L cannot be an "
17089 "EQUIVALENCE object",
17090 r
->u
.c
.component
->name
, &e
->where
);
17094 /* A substring shall not have length zero. */
17095 if (r
->type
== REF_SUBSTRING
)
17097 if (compare_bound (r
->u
.ss
.start
, r
->u
.ss
.end
) == CMP_GT
)
17099 gfc_error ("Substring at %L has length zero",
17100 &r
->u
.ss
.start
->where
);
17110 /* Function called by resolve_fntype to flag other symbols used in the
17111 length type parameter specification of function results. */
17114 flag_fn_result_spec (gfc_expr
*expr
,
17116 int *f ATTRIBUTE_UNUSED
)
17121 if (expr
->expr_type
== EXPR_VARIABLE
)
17123 s
= expr
->symtree
->n
.sym
;
17124 for (ns
= s
->ns
; ns
; ns
= ns
->parent
)
17130 gfc_error ("Self reference in character length expression "
17131 "for %qs at %L", sym
->name
, &expr
->where
);
17135 if (!s
->fn_result_spec
17136 && s
->attr
.flavor
== FL_PARAMETER
)
17138 /* Function contained in a module.... */
17139 if (ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_MODULE
)
17142 s
->fn_result_spec
= 1;
17143 /* Make sure that this symbol is translated as a module
17145 st
= gfc_get_unique_symtree (ns
);
17149 /* ... which is use associated and called. */
17150 else if (s
->attr
.use_assoc
|| s
->attr
.used_in_submodule
17152 /* External function matched with an interface. */
17155 && s
->ns
->proc_name
->attr
.if_source
== IFSRC_DECL
)
17156 || s
->ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
17157 && s
->ns
->proc_name
->attr
.function
))
17158 s
->fn_result_spec
= 1;
17165 /* Resolve function and ENTRY types, issue diagnostics if needed. */
17168 resolve_fntype (gfc_namespace
*ns
)
17170 gfc_entry_list
*el
;
17173 if (ns
->proc_name
== NULL
|| !ns
->proc_name
->attr
.function
)
17176 /* If there are any entries, ns->proc_name is the entry master
17177 synthetic symbol and ns->entries->sym actual FUNCTION symbol. */
17179 sym
= ns
->entries
->sym
;
17181 sym
= ns
->proc_name
;
17182 if (sym
->result
== sym
17183 && sym
->ts
.type
== BT_UNKNOWN
17184 && !gfc_set_default_type (sym
, 0, NULL
)
17185 && !sym
->attr
.untyped
)
17187 gfc_error ("Function %qs at %L has no IMPLICIT type",
17188 sym
->name
, &sym
->declared_at
);
17189 sym
->attr
.untyped
= 1;
17192 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->ts
.u
.derived
->attr
.use_assoc
17193 && !sym
->attr
.contained
17194 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
17195 && gfc_check_symbol_access (sym
))
17197 gfc_notify_std (GFC_STD_F2003
, "PUBLIC function %qs at "
17198 "%L of PRIVATE type %qs", sym
->name
,
17199 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
17203 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
17205 if (el
->sym
->result
== el
->sym
17206 && el
->sym
->ts
.type
== BT_UNKNOWN
17207 && !gfc_set_default_type (el
->sym
, 0, NULL
)
17208 && !el
->sym
->attr
.untyped
)
17210 gfc_error ("ENTRY %qs at %L has no IMPLICIT type",
17211 el
->sym
->name
, &el
->sym
->declared_at
);
17212 el
->sym
->attr
.untyped
= 1;
17216 if (sym
->ts
.type
== BT_CHARACTER
)
17217 gfc_traverse_expr (sym
->ts
.u
.cl
->length
, sym
, flag_fn_result_spec
, 0);
17221 /* 12.3.2.1.1 Defined operators. */
17224 check_uop_procedure (gfc_symbol
*sym
, locus where
)
17226 gfc_formal_arglist
*formal
;
17228 if (!sym
->attr
.function
)
17230 gfc_error ("User operator procedure %qs at %L must be a FUNCTION",
17231 sym
->name
, &where
);
17235 if (sym
->ts
.type
== BT_CHARACTER
17236 && !((sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
) || sym
->ts
.deferred
)
17237 && !(sym
->result
&& ((sym
->result
->ts
.u
.cl
17238 && sym
->result
->ts
.u
.cl
->length
) || sym
->result
->ts
.deferred
)))
17240 gfc_error ("User operator procedure %qs at %L cannot be assumed "
17241 "character length", sym
->name
, &where
);
17245 formal
= gfc_sym_get_dummy_args (sym
);
17246 if (!formal
|| !formal
->sym
)
17248 gfc_error ("User operator procedure %qs at %L must have at least "
17249 "one argument", sym
->name
, &where
);
17253 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
17255 gfc_error ("First argument of operator interface at %L must be "
17256 "INTENT(IN)", &where
);
17260 if (formal
->sym
->attr
.optional
)
17262 gfc_error ("First argument of operator interface at %L cannot be "
17263 "optional", &where
);
17267 formal
= formal
->next
;
17268 if (!formal
|| !formal
->sym
)
17271 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
17273 gfc_error ("Second argument of operator interface at %L must be "
17274 "INTENT(IN)", &where
);
17278 if (formal
->sym
->attr
.optional
)
17280 gfc_error ("Second argument of operator interface at %L cannot be "
17281 "optional", &where
);
17287 gfc_error ("Operator interface at %L must have, at most, two "
17288 "arguments", &where
);
17296 gfc_resolve_uops (gfc_symtree
*symtree
)
17298 gfc_interface
*itr
;
17300 if (symtree
== NULL
)
17303 gfc_resolve_uops (symtree
->left
);
17304 gfc_resolve_uops (symtree
->right
);
17306 for (itr
= symtree
->n
.uop
->op
; itr
; itr
= itr
->next
)
17307 check_uop_procedure (itr
->sym
, itr
->sym
->declared_at
);
17311 /* Examine all of the expressions associated with a program unit,
17312 assign types to all intermediate expressions, make sure that all
17313 assignments are to compatible types and figure out which names
17314 refer to which functions or subroutines. It doesn't check code
17315 block, which is handled by gfc_resolve_code. */
17318 resolve_types (gfc_namespace
*ns
)
17324 gfc_namespace
* old_ns
= gfc_current_ns
;
17325 bool recursive
= ns
->proc_name
&& ns
->proc_name
->attr
.recursive
;
17327 if (ns
->types_resolved
)
17330 /* Check that all IMPLICIT types are ok. */
17331 if (!ns
->seen_implicit_none
)
17334 for (letter
= 0; letter
!= GFC_LETTERS
; ++letter
)
17335 if (ns
->set_flag
[letter
]
17336 && !resolve_typespec_used (&ns
->default_type
[letter
],
17337 &ns
->implicit_loc
[letter
], NULL
))
17341 gfc_current_ns
= ns
;
17343 resolve_entries (ns
);
17345 resolve_common_vars (&ns
->blank_common
, false);
17346 resolve_common_blocks (ns
->common_root
);
17348 resolve_contained_functions (ns
);
17350 if (ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
17351 && ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
17352 gfc_resolve_formal_arglist (ns
->proc_name
);
17354 gfc_traverse_ns (ns
, resolve_bind_c_derived_types
);
17356 for (cl
= ns
->cl_list
; cl
; cl
= cl
->next
)
17357 resolve_charlen (cl
);
17359 gfc_traverse_ns (ns
, resolve_symbol
);
17361 resolve_fntype (ns
);
17363 for (n
= ns
->contained
; n
; n
= n
->sibling
)
17365 if (gfc_pure (ns
->proc_name
) && !gfc_pure (n
->proc_name
))
17366 gfc_error ("Contained procedure %qs at %L of a PURE procedure must "
17367 "also be PURE", n
->proc_name
->name
,
17368 &n
->proc_name
->declared_at
);
17374 gfc_do_concurrent_flag
= 0;
17375 gfc_check_interfaces (ns
);
17377 gfc_traverse_ns (ns
, resolve_values
);
17379 if (ns
->save_all
|| (!flag_automatic
&& !recursive
))
17383 for (d
= ns
->data
; d
; d
= d
->next
)
17387 gfc_traverse_ns (ns
, gfc_formalize_init_value
);
17389 gfc_traverse_ns (ns
, gfc_verify_binding_labels
);
17391 for (eq
= ns
->equiv
; eq
; eq
= eq
->next
)
17392 resolve_equivalence (eq
);
17394 /* Warn about unused labels. */
17395 if (warn_unused_label
)
17396 warn_unused_fortran_label (ns
->st_labels
);
17398 gfc_resolve_uops (ns
->uop_root
);
17400 gfc_traverse_ns (ns
, gfc_verify_DTIO_procedures
);
17402 gfc_resolve_omp_declare_simd (ns
);
17404 gfc_resolve_omp_udrs (ns
->omp_udr_root
);
17406 ns
->types_resolved
= 1;
17408 gfc_current_ns
= old_ns
;
17412 /* Call gfc_resolve_code recursively. */
17415 resolve_codes (gfc_namespace
*ns
)
17418 bitmap_obstack old_obstack
;
17420 if (ns
->resolved
== 1)
17423 for (n
= ns
->contained
; n
; n
= n
->sibling
)
17426 gfc_current_ns
= ns
;
17428 /* Don't clear 'cs_base' if this is the namespace of a BLOCK construct. */
17429 if (!(ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_LABEL
))
17432 /* Set to an out of range value. */
17433 current_entry_id
= -1;
17435 old_obstack
= labels_obstack
;
17436 bitmap_obstack_initialize (&labels_obstack
);
17438 gfc_resolve_oacc_declare (ns
);
17439 gfc_resolve_oacc_routines (ns
);
17440 gfc_resolve_omp_local_vars (ns
);
17441 gfc_resolve_code (ns
->code
, ns
);
17443 bitmap_obstack_release (&labels_obstack
);
17444 labels_obstack
= old_obstack
;
17448 /* This function is called after a complete program unit has been compiled.
17449 Its purpose is to examine all of the expressions associated with a program
17450 unit, assign types to all intermediate expressions, make sure that all
17451 assignments are to compatible types and figure out which names refer to
17452 which functions or subroutines. */
17455 gfc_resolve (gfc_namespace
*ns
)
17457 gfc_namespace
*old_ns
;
17458 code_stack
*old_cs_base
;
17459 struct gfc_omp_saved_state old_omp_state
;
17465 old_ns
= gfc_current_ns
;
17466 old_cs_base
= cs_base
;
17468 /* As gfc_resolve can be called during resolution of an OpenMP construct
17469 body, we should clear any state associated to it, so that say NS's
17470 DO loops are not interpreted as OpenMP loops. */
17471 if (!ns
->construct_entities
)
17472 gfc_omp_save_and_clear_state (&old_omp_state
);
17474 resolve_types (ns
);
17475 component_assignment_level
= 0;
17476 resolve_codes (ns
);
17478 gfc_current_ns
= old_ns
;
17479 cs_base
= old_cs_base
;
17482 gfc_run_passes (ns
);
17484 if (!ns
->construct_entities
)
17485 gfc_omp_restore_state (&old_omp_state
);