1 /* Perform type resolution on the various structures.
2 Copyright (C) 2001-2013 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"
28 #include "arith.h" /* For gfc_compare_expr(). */
29 #include "dependency.h"
31 #include "target-memory.h" /* for gfc_simplify_transfer */
32 #include "constructor.h"
34 /* Types used in equivalence statements. */
38 SEQ_NONDEFAULT
, SEQ_NUMERIC
, SEQ_CHARACTER
, SEQ_MIXED
42 /* Stack to keep track of the nesting of blocks as we move through the
43 code. See resolve_branch() and resolve_code(). */
45 typedef struct code_stack
47 struct gfc_code
*head
, *current
;
48 struct code_stack
*prev
;
50 /* This bitmap keeps track of the targets valid for a branch from
51 inside this block except for END {IF|SELECT}s of enclosing
53 bitmap reachable_labels
;
57 static code_stack
*cs_base
= NULL
;
60 /* Nonzero if we're inside a FORALL or DO CONCURRENT block. */
62 static int forall_flag
;
63 static int do_concurrent_flag
;
65 /* True when we are resolving an expression that is an actual argument to
67 static bool actual_arg
= false;
68 /* True when we are resolving an expression that is the first actual argument
70 static bool first_actual_arg
= false;
73 /* Nonzero if we're inside a OpenMP WORKSHARE or PARALLEL WORKSHARE block. */
75 static int omp_workshare_flag
;
77 /* Nonzero if we are processing a formal arglist. The corresponding function
78 resets the flag each time that it is read. */
79 static int formal_arg_flag
= 0;
81 /* True if we are resolving a specification expression. */
82 static bool specification_expr
= false;
84 /* The id of the last entry seen. */
85 static int current_entry_id
;
87 /* We use bitmaps to determine if a branch target is valid. */
88 static bitmap_obstack labels_obstack
;
90 /* True when simplifying a EXPR_VARIABLE argument to an inquiry function. */
91 static bool inquiry_argument
= false;
95 gfc_is_formal_arg (void)
97 return formal_arg_flag
;
100 /* Is the symbol host associated? */
102 is_sym_host_assoc (gfc_symbol
*sym
, gfc_namespace
*ns
)
104 for (ns
= ns
->parent
; ns
; ns
= ns
->parent
)
113 /* Ensure a typespec used is valid; for instance, TYPE(t) is invalid if t is
114 an ABSTRACT derived-type. If where is not NULL, an error message with that
115 locus is printed, optionally using name. */
118 resolve_typespec_used (gfc_typespec
* ts
, locus
* where
, const char* name
)
120 if (ts
->type
== BT_DERIVED
&& ts
->u
.derived
->attr
.abstract
)
125 gfc_error ("'%s' at %L is of the ABSTRACT type '%s'",
126 name
, where
, ts
->u
.derived
->name
);
128 gfc_error ("ABSTRACT type '%s' used at %L",
129 ts
->u
.derived
->name
, where
);
140 check_proc_interface (gfc_symbol
*ifc
, locus
*where
)
142 /* Several checks for F08:C1216. */
143 if (ifc
->attr
.procedure
)
145 gfc_error ("Interface '%s' at %L is declared "
146 "in a later PROCEDURE statement", ifc
->name
, where
);
151 /* For generic interfaces, check if there is
152 a specific procedure with the same name. */
153 gfc_interface
*gen
= ifc
->generic
;
154 while (gen
&& strcmp (gen
->sym
->name
, ifc
->name
) != 0)
158 gfc_error ("Interface '%s' at %L may not be generic",
163 if (ifc
->attr
.proc
== PROC_ST_FUNCTION
)
165 gfc_error ("Interface '%s' at %L may not be a statement function",
169 if (gfc_is_intrinsic (ifc
, 0, ifc
->declared_at
)
170 || gfc_is_intrinsic (ifc
, 1, ifc
->declared_at
))
171 ifc
->attr
.intrinsic
= 1;
172 if (ifc
->attr
.intrinsic
&& !gfc_intrinsic_actual_ok (ifc
->name
, 0))
174 gfc_error ("Intrinsic procedure '%s' not allowed in "
175 "PROCEDURE statement at %L", ifc
->name
, where
);
178 if (!ifc
->attr
.if_source
&& !ifc
->attr
.intrinsic
&& ifc
->name
[0] != '\0')
180 gfc_error ("Interface '%s' at %L must be explicit", ifc
->name
, where
);
187 static void resolve_symbol (gfc_symbol
*sym
);
190 /* Resolve the interface for a PROCEDURE declaration or procedure pointer. */
193 resolve_procedure_interface (gfc_symbol
*sym
)
195 gfc_symbol
*ifc
= sym
->ts
.interface
;
202 gfc_error ("PROCEDURE '%s' at %L may not be used as its own interface",
203 sym
->name
, &sym
->declared_at
);
206 if (!check_proc_interface (ifc
, &sym
->declared_at
))
209 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
211 /* Resolve interface and copy attributes. */
212 resolve_symbol (ifc
);
213 if (ifc
->attr
.intrinsic
)
214 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
218 sym
->ts
= ifc
->result
->ts
;
223 sym
->ts
.interface
= ifc
;
224 sym
->attr
.function
= ifc
->attr
.function
;
225 sym
->attr
.subroutine
= ifc
->attr
.subroutine
;
227 sym
->attr
.allocatable
= ifc
->attr
.allocatable
;
228 sym
->attr
.pointer
= ifc
->attr
.pointer
;
229 sym
->attr
.pure
= ifc
->attr
.pure
;
230 sym
->attr
.elemental
= ifc
->attr
.elemental
;
231 sym
->attr
.dimension
= ifc
->attr
.dimension
;
232 sym
->attr
.contiguous
= ifc
->attr
.contiguous
;
233 sym
->attr
.recursive
= ifc
->attr
.recursive
;
234 sym
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
235 sym
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
236 sym
->attr
.is_bind_c
= ifc
->attr
.is_bind_c
;
237 sym
->attr
.class_ok
= ifc
->attr
.class_ok
;
238 /* Copy array spec. */
239 sym
->as
= gfc_copy_array_spec (ifc
->as
);
240 /* Copy char length. */
241 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
243 sym
->ts
.u
.cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
244 if (sym
->ts
.u
.cl
->length
&& !sym
->ts
.u
.cl
->resolved
245 && !gfc_resolve_expr (sym
->ts
.u
.cl
->length
))
254 /* Resolve types of formal argument lists. These have to be done early so that
255 the formal argument lists of module procedures can be copied to the
256 containing module before the individual procedures are resolved
257 individually. We also resolve argument lists of procedures in interface
258 blocks because they are self-contained scoping units.
260 Since a dummy argument cannot be a non-dummy procedure, the only
261 resort left for untyped names are the IMPLICIT types. */
264 resolve_formal_arglist (gfc_symbol
*proc
)
266 gfc_formal_arglist
*f
;
268 bool saved_specification_expr
;
271 if (proc
->result
!= NULL
)
276 if (gfc_elemental (proc
)
277 || sym
->attr
.pointer
|| sym
->attr
.allocatable
278 || (sym
->as
&& sym
->as
->rank
!= 0))
280 proc
->attr
.always_explicit
= 1;
281 sym
->attr
.always_explicit
= 1;
286 for (f
= proc
->formal
; f
; f
= f
->next
)
294 /* Alternate return placeholder. */
295 if (gfc_elemental (proc
))
296 gfc_error ("Alternate return specifier in elemental subroutine "
297 "'%s' at %L is not allowed", proc
->name
,
299 if (proc
->attr
.function
)
300 gfc_error ("Alternate return specifier in function "
301 "'%s' at %L is not allowed", proc
->name
,
305 else if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
306 && !resolve_procedure_interface (sym
))
309 if (strcmp (proc
->name
, sym
->name
) == 0)
311 gfc_error ("Self-referential argument "
312 "'%s' at %L is not allowed", sym
->name
,
317 if (sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
318 resolve_formal_arglist (sym
);
320 if (sym
->attr
.subroutine
|| sym
->attr
.external
)
322 if (sym
->attr
.flavor
== FL_UNKNOWN
)
323 gfc_add_flavor (&sym
->attr
, FL_PROCEDURE
, sym
->name
, &sym
->declared_at
);
327 if (sym
->ts
.type
== BT_UNKNOWN
&& !proc
->attr
.intrinsic
328 && (!sym
->attr
.function
|| sym
->result
== sym
))
329 gfc_set_default_type (sym
, 1, sym
->ns
);
332 as
= sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
333 ? CLASS_DATA (sym
)->as
: sym
->as
;
335 saved_specification_expr
= specification_expr
;
336 specification_expr
= true;
337 gfc_resolve_array_spec (as
, 0);
338 specification_expr
= saved_specification_expr
;
340 /* We can't tell if an array with dimension (:) is assumed or deferred
341 shape until we know if it has the pointer or allocatable attributes.
343 if (as
&& as
->rank
> 0 && as
->type
== AS_DEFERRED
344 && ((sym
->ts
.type
!= BT_CLASS
345 && !(sym
->attr
.pointer
|| sym
->attr
.allocatable
))
346 || (sym
->ts
.type
== BT_CLASS
347 && !(CLASS_DATA (sym
)->attr
.class_pointer
348 || CLASS_DATA (sym
)->attr
.allocatable
)))
349 && sym
->attr
.flavor
!= FL_PROCEDURE
)
351 as
->type
= AS_ASSUMED_SHAPE
;
352 for (i
= 0; i
< as
->rank
; i
++)
353 as
->lower
[i
] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
356 if ((as
&& as
->rank
> 0 && as
->type
== AS_ASSUMED_SHAPE
)
357 || (as
&& as
->type
== AS_ASSUMED_RANK
)
358 || sym
->attr
.pointer
|| sym
->attr
.allocatable
|| sym
->attr
.target
359 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
360 && (CLASS_DATA (sym
)->attr
.class_pointer
361 || CLASS_DATA (sym
)->attr
.allocatable
362 || CLASS_DATA (sym
)->attr
.target
))
363 || sym
->attr
.optional
)
365 proc
->attr
.always_explicit
= 1;
367 proc
->result
->attr
.always_explicit
= 1;
370 /* If the flavor is unknown at this point, it has to be a variable.
371 A procedure specification would have already set the type. */
373 if (sym
->attr
.flavor
== FL_UNKNOWN
)
374 gfc_add_flavor (&sym
->attr
, FL_VARIABLE
, sym
->name
, &sym
->declared_at
);
378 if (sym
->attr
.flavor
== FL_PROCEDURE
)
383 gfc_error ("Dummy procedure '%s' of PURE procedure at %L must "
384 "also be PURE", sym
->name
, &sym
->declared_at
);
388 else if (!sym
->attr
.pointer
)
390 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
)
393 gfc_notify_std (GFC_STD_F2008
, "Argument '%s'"
394 " of pure function '%s' at %L with VALUE "
395 "attribute but without INTENT(IN)",
396 sym
->name
, proc
->name
, &sym
->declared_at
);
398 gfc_error ("Argument '%s' of pure function '%s' at %L must "
399 "be INTENT(IN) or VALUE", sym
->name
, proc
->name
,
403 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
)
406 gfc_notify_std (GFC_STD_F2008
, "Argument '%s'"
407 " of pure subroutine '%s' at %L with VALUE "
408 "attribute but without INTENT", sym
->name
,
409 proc
->name
, &sym
->declared_at
);
411 gfc_error ("Argument '%s' of pure subroutine '%s' at %L "
412 "must have its INTENT specified or have the "
413 "VALUE attribute", sym
->name
, proc
->name
,
419 if (proc
->attr
.implicit_pure
)
421 if (sym
->attr
.flavor
== FL_PROCEDURE
)
424 proc
->attr
.implicit_pure
= 0;
426 else if (!sym
->attr
.pointer
)
428 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
430 proc
->attr
.implicit_pure
= 0;
432 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
434 proc
->attr
.implicit_pure
= 0;
438 if (gfc_elemental (proc
))
441 if (sym
->attr
.codimension
442 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
443 && CLASS_DATA (sym
)->attr
.codimension
))
445 gfc_error ("Coarray dummy argument '%s' at %L to elemental "
446 "procedure", sym
->name
, &sym
->declared_at
);
450 if (sym
->as
|| (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
451 && CLASS_DATA (sym
)->as
))
453 gfc_error ("Argument '%s' of elemental procedure at %L must "
454 "be scalar", sym
->name
, &sym
->declared_at
);
458 if (sym
->attr
.allocatable
459 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
460 && CLASS_DATA (sym
)->attr
.allocatable
))
462 gfc_error ("Argument '%s' of elemental procedure at %L cannot "
463 "have the ALLOCATABLE attribute", sym
->name
,
468 if (sym
->attr
.pointer
469 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
470 && CLASS_DATA (sym
)->attr
.class_pointer
))
472 gfc_error ("Argument '%s' of elemental procedure at %L cannot "
473 "have the POINTER attribute", sym
->name
,
478 if (sym
->attr
.flavor
== FL_PROCEDURE
)
480 gfc_error ("Dummy procedure '%s' not allowed in elemental "
481 "procedure '%s' at %L", sym
->name
, proc
->name
,
486 /* Fortran 2008 Corrigendum 1, C1290a. */
487 if (sym
->attr
.intent
== INTENT_UNKNOWN
&& !sym
->attr
.value
)
489 gfc_error ("Argument '%s' of elemental procedure '%s' at %L must "
490 "have its INTENT specified or have the VALUE "
491 "attribute", sym
->name
, proc
->name
,
497 /* Each dummy shall be specified to be scalar. */
498 if (proc
->attr
.proc
== PROC_ST_FUNCTION
)
502 gfc_error ("Argument '%s' of statement function at %L must "
503 "be scalar", sym
->name
, &sym
->declared_at
);
507 if (sym
->ts
.type
== BT_CHARACTER
)
509 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
510 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
512 gfc_error ("Character-valued argument '%s' of statement "
513 "function at %L must have constant length",
514 sym
->name
, &sym
->declared_at
);
524 /* Work function called when searching for symbols that have argument lists
525 associated with them. */
528 find_arglists (gfc_symbol
*sym
)
530 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
|| sym
->ns
!= gfc_current_ns
531 || sym
->attr
.flavor
== FL_DERIVED
|| sym
->attr
.intrinsic
)
534 resolve_formal_arglist (sym
);
538 /* Given a namespace, resolve all formal argument lists within the namespace.
542 resolve_formal_arglists (gfc_namespace
*ns
)
547 gfc_traverse_ns (ns
, find_arglists
);
552 resolve_contained_fntype (gfc_symbol
*sym
, gfc_namespace
*ns
)
556 /* If this namespace is not a function or an entry master function,
558 if (! sym
|| !(sym
->attr
.function
|| sym
->attr
.flavor
== FL_VARIABLE
)
559 || sym
->attr
.entry_master
)
562 /* Try to find out of what the return type is. */
563 if (sym
->result
->ts
.type
== BT_UNKNOWN
&& sym
->result
->ts
.interface
== NULL
)
565 t
= gfc_set_default_type (sym
->result
, 0, ns
);
567 if (!t
&& !sym
->result
->attr
.untyped
)
569 if (sym
->result
== sym
)
570 gfc_error ("Contained function '%s' at %L has no IMPLICIT type",
571 sym
->name
, &sym
->declared_at
);
572 else if (!sym
->result
->attr
.proc_pointer
)
573 gfc_error ("Result '%s' of contained function '%s' at %L has "
574 "no IMPLICIT type", sym
->result
->name
, sym
->name
,
575 &sym
->result
->declared_at
);
576 sym
->result
->attr
.untyped
= 1;
580 /* Fortran 95 Draft Standard, page 51, Section 5.1.1.5, on the Character
581 type, lists the only ways a character length value of * can be used:
582 dummy arguments of procedures, named constants, and function results
583 in external functions. Internal function results and results of module
584 procedures are not on this list, ergo, not permitted. */
586 if (sym
->result
->ts
.type
== BT_CHARACTER
)
588 gfc_charlen
*cl
= sym
->result
->ts
.u
.cl
;
589 if ((!cl
|| !cl
->length
) && !sym
->result
->ts
.deferred
)
591 /* See if this is a module-procedure and adapt error message
594 gcc_assert (ns
->parent
&& ns
->parent
->proc_name
);
595 module_proc
= (ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
);
597 gfc_error ("Character-valued %s '%s' at %L must not be"
599 module_proc
? _("module procedure")
600 : _("internal function"),
601 sym
->name
, &sym
->declared_at
);
607 /* Add NEW_ARGS to the formal argument list of PROC, taking care not to
608 introduce duplicates. */
611 merge_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
613 gfc_formal_arglist
*f
, *new_arglist
;
616 for (; new_args
!= NULL
; new_args
= new_args
->next
)
618 new_sym
= new_args
->sym
;
619 /* See if this arg is already in the formal argument list. */
620 for (f
= proc
->formal
; f
; f
= f
->next
)
622 if (new_sym
== f
->sym
)
629 /* Add a new argument. Argument order is not important. */
630 new_arglist
= gfc_get_formal_arglist ();
631 new_arglist
->sym
= new_sym
;
632 new_arglist
->next
= proc
->formal
;
633 proc
->formal
= new_arglist
;
638 /* Flag the arguments that are not present in all entries. */
641 check_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
643 gfc_formal_arglist
*f
, *head
;
646 for (f
= proc
->formal
; f
; f
= f
->next
)
651 for (new_args
= head
; new_args
; new_args
= new_args
->next
)
653 if (new_args
->sym
== f
->sym
)
660 f
->sym
->attr
.not_always_present
= 1;
665 /* Resolve alternate entry points. If a symbol has multiple entry points we
666 create a new master symbol for the main routine, and turn the existing
667 symbol into an entry point. */
670 resolve_entries (gfc_namespace
*ns
)
672 gfc_namespace
*old_ns
;
676 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
677 static int master_count
= 0;
679 if (ns
->proc_name
== NULL
)
682 /* No need to do anything if this procedure doesn't have alternate entry
687 /* We may already have resolved alternate entry points. */
688 if (ns
->proc_name
->attr
.entry_master
)
691 /* If this isn't a procedure something has gone horribly wrong. */
692 gcc_assert (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
);
694 /* Remember the current namespace. */
695 old_ns
= gfc_current_ns
;
699 /* Add the main entry point to the list of entry points. */
700 el
= gfc_get_entry_list ();
701 el
->sym
= ns
->proc_name
;
703 el
->next
= ns
->entries
;
705 ns
->proc_name
->attr
.entry
= 1;
707 /* If it is a module function, it needs to be in the right namespace
708 so that gfc_get_fake_result_decl can gather up the results. The
709 need for this arose in get_proc_name, where these beasts were
710 left in their own namespace, to keep prior references linked to
711 the entry declaration.*/
712 if (ns
->proc_name
->attr
.function
713 && ns
->parent
&& ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
716 /* Do the same for entries where the master is not a module
717 procedure. These are retained in the module namespace because
718 of the module procedure declaration. */
719 for (el
= el
->next
; el
; el
= el
->next
)
720 if (el
->sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
721 && el
->sym
->attr
.mod_proc
)
725 /* Add an entry statement for it. */
732 /* Create a new symbol for the master function. */
733 /* Give the internal function a unique name (within this file).
734 Also include the function name so the user has some hope of figuring
735 out what is going on. */
736 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "master.%d.%s",
737 master_count
++, ns
->proc_name
->name
);
738 gfc_get_ha_symbol (name
, &proc
);
739 gcc_assert (proc
!= NULL
);
741 gfc_add_procedure (&proc
->attr
, PROC_INTERNAL
, proc
->name
, NULL
);
742 if (ns
->proc_name
->attr
.subroutine
)
743 gfc_add_subroutine (&proc
->attr
, proc
->name
, NULL
);
747 gfc_typespec
*ts
, *fts
;
748 gfc_array_spec
*as
, *fas
;
749 gfc_add_function (&proc
->attr
, proc
->name
, NULL
);
751 fas
= ns
->entries
->sym
->as
;
752 fas
= fas
? fas
: ns
->entries
->sym
->result
->as
;
753 fts
= &ns
->entries
->sym
->result
->ts
;
754 if (fts
->type
== BT_UNKNOWN
)
755 fts
= gfc_get_default_type (ns
->entries
->sym
->result
->name
, NULL
);
756 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
758 ts
= &el
->sym
->result
->ts
;
760 as
= as
? as
: el
->sym
->result
->as
;
761 if (ts
->type
== BT_UNKNOWN
)
762 ts
= gfc_get_default_type (el
->sym
->result
->name
, NULL
);
764 if (! gfc_compare_types (ts
, fts
)
765 || (el
->sym
->result
->attr
.dimension
766 != ns
->entries
->sym
->result
->attr
.dimension
)
767 || (el
->sym
->result
->attr
.pointer
768 != ns
->entries
->sym
->result
->attr
.pointer
))
770 else if (as
&& fas
&& ns
->entries
->sym
->result
!= el
->sym
->result
771 && gfc_compare_array_spec (as
, fas
) == 0)
772 gfc_error ("Function %s at %L has entries with mismatched "
773 "array specifications", ns
->entries
->sym
->name
,
774 &ns
->entries
->sym
->declared_at
);
775 /* The characteristics need to match and thus both need to have
776 the same string length, i.e. both len=*, or both len=4.
777 Having both len=<variable> is also possible, but difficult to
778 check at compile time. */
779 else if (ts
->type
== BT_CHARACTER
&& ts
->u
.cl
&& fts
->u
.cl
780 && (((ts
->u
.cl
->length
&& !fts
->u
.cl
->length
)
781 ||(!ts
->u
.cl
->length
&& fts
->u
.cl
->length
))
783 && ts
->u
.cl
->length
->expr_type
784 != fts
->u
.cl
->length
->expr_type
)
786 && ts
->u
.cl
->length
->expr_type
== EXPR_CONSTANT
787 && mpz_cmp (ts
->u
.cl
->length
->value
.integer
,
788 fts
->u
.cl
->length
->value
.integer
) != 0)))
789 gfc_notify_std (GFC_STD_GNU
, "Function %s at %L with "
790 "entries returning variables of different "
791 "string lengths", ns
->entries
->sym
->name
,
792 &ns
->entries
->sym
->declared_at
);
797 sym
= ns
->entries
->sym
->result
;
798 /* All result types the same. */
800 if (sym
->attr
.dimension
)
801 gfc_set_array_spec (proc
, gfc_copy_array_spec (sym
->as
), NULL
);
802 if (sym
->attr
.pointer
)
803 gfc_add_pointer (&proc
->attr
, NULL
);
807 /* Otherwise the result will be passed through a union by
809 proc
->attr
.mixed_entry_master
= 1;
810 for (el
= ns
->entries
; el
; el
= el
->next
)
812 sym
= el
->sym
->result
;
813 if (sym
->attr
.dimension
)
815 if (el
== ns
->entries
)
816 gfc_error ("FUNCTION result %s can't be an array in "
817 "FUNCTION %s at %L", sym
->name
,
818 ns
->entries
->sym
->name
, &sym
->declared_at
);
820 gfc_error ("ENTRY result %s can't be an array in "
821 "FUNCTION %s at %L", sym
->name
,
822 ns
->entries
->sym
->name
, &sym
->declared_at
);
824 else if (sym
->attr
.pointer
)
826 if (el
== ns
->entries
)
827 gfc_error ("FUNCTION result %s can't be a POINTER in "
828 "FUNCTION %s at %L", sym
->name
,
829 ns
->entries
->sym
->name
, &sym
->declared_at
);
831 gfc_error ("ENTRY result %s can't be a POINTER in "
832 "FUNCTION %s at %L", sym
->name
,
833 ns
->entries
->sym
->name
, &sym
->declared_at
);
838 if (ts
->type
== BT_UNKNOWN
)
839 ts
= gfc_get_default_type (sym
->name
, NULL
);
843 if (ts
->kind
== gfc_default_integer_kind
)
847 if (ts
->kind
== gfc_default_real_kind
848 || ts
->kind
== gfc_default_double_kind
)
852 if (ts
->kind
== gfc_default_complex_kind
)
856 if (ts
->kind
== gfc_default_logical_kind
)
860 /* We will issue error elsewhere. */
868 if (el
== ns
->entries
)
869 gfc_error ("FUNCTION result %s can't be of type %s "
870 "in FUNCTION %s at %L", sym
->name
,
871 gfc_typename (ts
), ns
->entries
->sym
->name
,
874 gfc_error ("ENTRY result %s can't be of type %s "
875 "in FUNCTION %s at %L", sym
->name
,
876 gfc_typename (ts
), ns
->entries
->sym
->name
,
883 proc
->attr
.access
= ACCESS_PRIVATE
;
884 proc
->attr
.entry_master
= 1;
886 /* Merge all the entry point arguments. */
887 for (el
= ns
->entries
; el
; el
= el
->next
)
888 merge_argument_lists (proc
, el
->sym
->formal
);
890 /* Check the master formal arguments for any that are not
891 present in all entry points. */
892 for (el
= ns
->entries
; el
; el
= el
->next
)
893 check_argument_lists (proc
, el
->sym
->formal
);
895 /* Use the master function for the function body. */
896 ns
->proc_name
= proc
;
898 /* Finalize the new symbols. */
899 gfc_commit_symbols ();
901 /* Restore the original namespace. */
902 gfc_current_ns
= old_ns
;
906 /* Resolve common variables. */
908 resolve_common_vars (gfc_symbol
*sym
, bool named_common
)
910 gfc_symbol
*csym
= sym
;
912 for (; csym
; csym
= csym
->common_next
)
914 if (csym
->value
|| csym
->attr
.data
)
916 if (!csym
->ns
->is_block_data
)
917 gfc_notify_std (GFC_STD_GNU
, "Variable '%s' at %L is in COMMON "
918 "but only in BLOCK DATA initialization is "
919 "allowed", csym
->name
, &csym
->declared_at
);
920 else if (!named_common
)
921 gfc_notify_std (GFC_STD_GNU
, "Initialized variable '%s' at %L is "
922 "in a blank COMMON but initialization is only "
923 "allowed in named common blocks", csym
->name
,
927 if (UNLIMITED_POLY (csym
))
928 gfc_error_now ("'%s' in cannot appear in COMMON at %L "
929 "[F2008:C5100]", csym
->name
, &csym
->declared_at
);
931 if (csym
->ts
.type
!= BT_DERIVED
)
934 if (!(csym
->ts
.u
.derived
->attr
.sequence
935 || csym
->ts
.u
.derived
->attr
.is_bind_c
))
936 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
937 "has neither the SEQUENCE nor the BIND(C) "
938 "attribute", csym
->name
, &csym
->declared_at
);
939 if (csym
->ts
.u
.derived
->attr
.alloc_comp
)
940 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
941 "has an ultimate component that is "
942 "allocatable", csym
->name
, &csym
->declared_at
);
943 if (gfc_has_default_initializer (csym
->ts
.u
.derived
))
944 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
945 "may not have default initializer", csym
->name
,
948 if (csym
->attr
.flavor
== FL_UNKNOWN
&& !csym
->attr
.proc_pointer
)
949 gfc_add_flavor (&csym
->attr
, FL_VARIABLE
, csym
->name
, &csym
->declared_at
);
953 /* Resolve common blocks. */
955 resolve_common_blocks (gfc_symtree
*common_root
)
960 if (common_root
== NULL
)
963 if (common_root
->left
)
964 resolve_common_blocks (common_root
->left
);
965 if (common_root
->right
)
966 resolve_common_blocks (common_root
->right
);
968 resolve_common_vars (common_root
->n
.common
->head
, true);
970 /* The common name is a global name - in Fortran 2003 also if it has a
971 C binding name, since Fortran 2008 only the C binding name is a global
973 if (!common_root
->n
.common
->binding_label
974 || gfc_notification_std (GFC_STD_F2008
))
976 gsym
= gfc_find_gsymbol (gfc_gsym_root
,
977 common_root
->n
.common
->name
);
979 if (gsym
&& gfc_notification_std (GFC_STD_F2008
)
980 && gsym
->type
== GSYM_COMMON
981 && ((common_root
->n
.common
->binding_label
982 && (!gsym
->binding_label
983 || strcmp (common_root
->n
.common
->binding_label
,
984 gsym
->binding_label
) != 0))
985 || (!common_root
->n
.common
->binding_label
986 && gsym
->binding_label
)))
988 gfc_error ("In Fortran 2003 COMMON '%s' block at %L is a global "
989 "identifier and must thus have the same binding name "
990 "as the same-named COMMON block at %L: %s vs %s",
991 common_root
->n
.common
->name
, &common_root
->n
.common
->where
,
993 common_root
->n
.common
->binding_label
994 ? common_root
->n
.common
->binding_label
: "(blank)",
995 gsym
->binding_label
? gsym
->binding_label
: "(blank)");
999 if (gsym
&& gsym
->type
!= GSYM_COMMON
1000 && !common_root
->n
.common
->binding_label
)
1002 gfc_error ("COMMON block '%s' at %L uses the same global identifier "
1004 common_root
->n
.common
->name
, &common_root
->n
.common
->where
,
1008 if (gsym
&& gsym
->type
!= GSYM_COMMON
)
1010 gfc_error ("Fortran 2008: COMMON block '%s' with binding label at "
1011 "%L sharing the identifier with global non-COMMON-block "
1012 "entity at %L", common_root
->n
.common
->name
,
1013 &common_root
->n
.common
->where
, &gsym
->where
);
1018 gsym
= gfc_get_gsymbol (common_root
->n
.common
->name
);
1019 gsym
->type
= GSYM_COMMON
;
1020 gsym
->where
= common_root
->n
.common
->where
;
1026 if (common_root
->n
.common
->binding_label
)
1028 gsym
= gfc_find_gsymbol (gfc_gsym_root
,
1029 common_root
->n
.common
->binding_label
);
1030 if (gsym
&& gsym
->type
!= GSYM_COMMON
)
1032 gfc_error ("COMMON block at %L with binding label %s uses the same "
1033 "global identifier as entity at %L",
1034 &common_root
->n
.common
->where
,
1035 common_root
->n
.common
->binding_label
, &gsym
->where
);
1040 gsym
= gfc_get_gsymbol (common_root
->n
.common
->binding_label
);
1041 gsym
->type
= GSYM_COMMON
;
1042 gsym
->where
= common_root
->n
.common
->where
;
1048 gfc_find_symbol (common_root
->name
, gfc_current_ns
, 0, &sym
);
1052 if (sym
->attr
.flavor
== FL_PARAMETER
)
1053 gfc_error ("COMMON block '%s' at %L is used as PARAMETER at %L",
1054 sym
->name
, &common_root
->n
.common
->where
, &sym
->declared_at
);
1056 if (sym
->attr
.external
)
1057 gfc_error ("COMMON block '%s' at %L can not have the EXTERNAL attribute",
1058 sym
->name
, &common_root
->n
.common
->where
);
1060 if (sym
->attr
.intrinsic
)
1061 gfc_error ("COMMON block '%s' at %L is also an intrinsic procedure",
1062 sym
->name
, &common_root
->n
.common
->where
);
1063 else if (sym
->attr
.result
1064 || gfc_is_function_return_value (sym
, gfc_current_ns
))
1065 gfc_notify_std (GFC_STD_F2003
, "COMMON block '%s' at %L "
1066 "that is also a function result", sym
->name
,
1067 &common_root
->n
.common
->where
);
1068 else if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.proc
!= PROC_INTERNAL
1069 && sym
->attr
.proc
!= PROC_ST_FUNCTION
)
1070 gfc_notify_std (GFC_STD_F2003
, "COMMON block '%s' at %L "
1071 "that is also a global procedure", sym
->name
,
1072 &common_root
->n
.common
->where
);
1076 /* Resolve contained function types. Because contained functions can call one
1077 another, they have to be worked out before any of the contained procedures
1080 The good news is that if a function doesn't already have a type, the only
1081 way it can get one is through an IMPLICIT type or a RESULT variable, because
1082 by definition contained functions are contained namespace they're contained
1083 in, not in a sibling or parent namespace. */
1086 resolve_contained_functions (gfc_namespace
*ns
)
1088 gfc_namespace
*child
;
1091 resolve_formal_arglists (ns
);
1093 for (child
= ns
->contained
; child
; child
= child
->sibling
)
1095 /* Resolve alternate entry points first. */
1096 resolve_entries (child
);
1098 /* Then check function return types. */
1099 resolve_contained_fntype (child
->proc_name
, child
);
1100 for (el
= child
->entries
; el
; el
= el
->next
)
1101 resolve_contained_fntype (el
->sym
, child
);
1106 static bool resolve_fl_derived0 (gfc_symbol
*sym
);
1109 /* Resolve all of the elements of a structure constructor and make sure that
1110 the types are correct. The 'init' flag indicates that the given
1111 constructor is an initializer. */
1114 resolve_structure_cons (gfc_expr
*expr
, int init
)
1116 gfc_constructor
*cons
;
1117 gfc_component
*comp
;
1123 if (expr
->ts
.type
== BT_DERIVED
)
1124 resolve_fl_derived0 (expr
->ts
.u
.derived
);
1126 cons
= gfc_constructor_first (expr
->value
.constructor
);
1128 /* A constructor may have references if it is the result of substituting a
1129 parameter variable. In this case we just pull out the component we
1132 comp
= expr
->ref
->u
.c
.sym
->components
;
1134 comp
= expr
->ts
.u
.derived
->components
;
1136 for (; comp
&& cons
; comp
= comp
->next
, cons
= gfc_constructor_next (cons
))
1143 if (!gfc_resolve_expr (cons
->expr
))
1149 rank
= comp
->as
? comp
->as
->rank
: 0;
1150 if (cons
->expr
->expr_type
!= EXPR_NULL
&& rank
!= cons
->expr
->rank
1151 && (comp
->attr
.allocatable
|| cons
->expr
->rank
))
1153 gfc_error ("The rank of the element in the structure "
1154 "constructor at %L does not match that of the "
1155 "component (%d/%d)", &cons
->expr
->where
,
1156 cons
->expr
->rank
, rank
);
1160 /* If we don't have the right type, try to convert it. */
1162 if (!comp
->attr
.proc_pointer
&&
1163 !gfc_compare_types (&cons
->expr
->ts
, &comp
->ts
))
1165 if (strcmp (comp
->name
, "_extends") == 0)
1167 /* Can afford to be brutal with the _extends initializer.
1168 The derived type can get lost because it is PRIVATE
1169 but it is not usage constrained by the standard. */
1170 cons
->expr
->ts
= comp
->ts
;
1172 else if (comp
->attr
.pointer
&& cons
->expr
->ts
.type
!= BT_UNKNOWN
)
1174 gfc_error ("The element in the structure constructor at %L, "
1175 "for pointer component '%s', is %s but should be %s",
1176 &cons
->expr
->where
, comp
->name
,
1177 gfc_basic_typename (cons
->expr
->ts
.type
),
1178 gfc_basic_typename (comp
->ts
.type
));
1183 bool t2
= gfc_convert_type (cons
->expr
, &comp
->ts
, 1);
1189 /* For strings, the length of the constructor should be the same as
1190 the one of the structure, ensure this if the lengths are known at
1191 compile time and when we are dealing with PARAMETER or structure
1193 if (cons
->expr
->ts
.type
== BT_CHARACTER
&& comp
->ts
.u
.cl
1194 && comp
->ts
.u
.cl
->length
1195 && comp
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1196 && cons
->expr
->ts
.u
.cl
&& cons
->expr
->ts
.u
.cl
->length
1197 && cons
->expr
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1198 && cons
->expr
->rank
!= 0
1199 && mpz_cmp (cons
->expr
->ts
.u
.cl
->length
->value
.integer
,
1200 comp
->ts
.u
.cl
->length
->value
.integer
) != 0)
1202 if (cons
->expr
->expr_type
== EXPR_VARIABLE
1203 && cons
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
)
1205 /* Wrap the parameter in an array constructor (EXPR_ARRAY)
1206 to make use of the gfc_resolve_character_array_constructor
1207 machinery. The expression is later simplified away to
1208 an array of string literals. */
1209 gfc_expr
*para
= cons
->expr
;
1210 cons
->expr
= gfc_get_expr ();
1211 cons
->expr
->ts
= para
->ts
;
1212 cons
->expr
->where
= para
->where
;
1213 cons
->expr
->expr_type
= EXPR_ARRAY
;
1214 cons
->expr
->rank
= para
->rank
;
1215 cons
->expr
->shape
= gfc_copy_shape (para
->shape
, para
->rank
);
1216 gfc_constructor_append_expr (&cons
->expr
->value
.constructor
,
1217 para
, &cons
->expr
->where
);
1219 if (cons
->expr
->expr_type
== EXPR_ARRAY
)
1222 p
= gfc_constructor_first (cons
->expr
->value
.constructor
);
1223 if (cons
->expr
->ts
.u
.cl
!= p
->expr
->ts
.u
.cl
)
1225 gfc_charlen
*cl
, *cl2
;
1228 for (cl
= gfc_current_ns
->cl_list
; cl
; cl
= cl
->next
)
1230 if (cl
== cons
->expr
->ts
.u
.cl
)
1238 cl2
->next
= cl
->next
;
1240 gfc_free_expr (cl
->length
);
1244 cons
->expr
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
1245 cons
->expr
->ts
.u
.cl
->length_from_typespec
= true;
1246 cons
->expr
->ts
.u
.cl
->length
= gfc_copy_expr (comp
->ts
.u
.cl
->length
);
1247 gfc_resolve_character_array_constructor (cons
->expr
);
1251 if (cons
->expr
->expr_type
== EXPR_NULL
1252 && !(comp
->attr
.pointer
|| comp
->attr
.allocatable
1253 || comp
->attr
.proc_pointer
|| comp
->ts
.f90_type
== BT_VOID
1254 || (comp
->ts
.type
== BT_CLASS
1255 && (CLASS_DATA (comp
)->attr
.class_pointer
1256 || CLASS_DATA (comp
)->attr
.allocatable
))))
1259 gfc_error ("The NULL in the structure constructor at %L is "
1260 "being applied to component '%s', which is neither "
1261 "a POINTER nor ALLOCATABLE", &cons
->expr
->where
,
1265 if (comp
->attr
.proc_pointer
&& comp
->ts
.interface
)
1267 /* Check procedure pointer interface. */
1268 gfc_symbol
*s2
= NULL
;
1273 c2
= gfc_get_proc_ptr_comp (cons
->expr
);
1276 s2
= c2
->ts
.interface
;
1279 else if (cons
->expr
->expr_type
== EXPR_FUNCTION
)
1281 s2
= cons
->expr
->symtree
->n
.sym
->result
;
1282 name
= cons
->expr
->symtree
->n
.sym
->result
->name
;
1284 else if (cons
->expr
->expr_type
!= EXPR_NULL
)
1286 s2
= cons
->expr
->symtree
->n
.sym
;
1287 name
= cons
->expr
->symtree
->n
.sym
->name
;
1290 if (s2
&& !gfc_compare_interfaces (comp
->ts
.interface
, s2
, name
, 0, 1,
1291 err
, sizeof (err
), NULL
, NULL
))
1293 gfc_error ("Interface mismatch for procedure-pointer component "
1294 "'%s' in structure constructor at %L: %s",
1295 comp
->name
, &cons
->expr
->where
, err
);
1300 if (!comp
->attr
.pointer
|| comp
->attr
.proc_pointer
1301 || cons
->expr
->expr_type
== EXPR_NULL
)
1304 a
= gfc_expr_attr (cons
->expr
);
1306 if (!a
.pointer
&& !a
.target
)
1309 gfc_error ("The element in the structure constructor at %L, "
1310 "for pointer component '%s' should be a POINTER or "
1311 "a TARGET", &cons
->expr
->where
, comp
->name
);
1316 /* F08:C461. Additional checks for pointer initialization. */
1320 gfc_error ("Pointer initialization target at %L "
1321 "must not be ALLOCATABLE ", &cons
->expr
->where
);
1326 gfc_error ("Pointer initialization target at %L "
1327 "must have the SAVE attribute", &cons
->expr
->where
);
1331 /* F2003, C1272 (3). */
1332 if (gfc_pure (NULL
) && cons
->expr
->expr_type
== EXPR_VARIABLE
1333 && (gfc_impure_variable (cons
->expr
->symtree
->n
.sym
)
1334 || gfc_is_coindexed (cons
->expr
)))
1337 gfc_error ("Invalid expression in the structure constructor for "
1338 "pointer component '%s' at %L in PURE procedure",
1339 comp
->name
, &cons
->expr
->where
);
1342 if (gfc_implicit_pure (NULL
)
1343 && cons
->expr
->expr_type
== EXPR_VARIABLE
1344 && (gfc_impure_variable (cons
->expr
->symtree
->n
.sym
)
1345 || gfc_is_coindexed (cons
->expr
)))
1346 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
1354 /****************** Expression name resolution ******************/
1356 /* Returns 0 if a symbol was not declared with a type or
1357 attribute declaration statement, nonzero otherwise. */
1360 was_declared (gfc_symbol
*sym
)
1366 if (!a
.implicit_type
&& sym
->ts
.type
!= BT_UNKNOWN
)
1369 if (a
.allocatable
|| a
.dimension
|| a
.dummy
|| a
.external
|| a
.intrinsic
1370 || a
.optional
|| a
.pointer
|| a
.save
|| a
.target
|| a
.volatile_
1371 || a
.value
|| a
.access
!= ACCESS_UNKNOWN
|| a
.intent
!= INTENT_UNKNOWN
1372 || a
.asynchronous
|| a
.codimension
)
1379 /* Determine if a symbol is generic or not. */
1382 generic_sym (gfc_symbol
*sym
)
1386 if (sym
->attr
.generic
||
1387 (sym
->attr
.intrinsic
&& gfc_generic_intrinsic (sym
->name
)))
1390 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1393 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1400 return generic_sym (s
);
1407 /* Determine if a symbol is specific or not. */
1410 specific_sym (gfc_symbol
*sym
)
1414 if (sym
->attr
.if_source
== IFSRC_IFBODY
1415 || sym
->attr
.proc
== PROC_MODULE
1416 || sym
->attr
.proc
== PROC_INTERNAL
1417 || sym
->attr
.proc
== PROC_ST_FUNCTION
1418 || (sym
->attr
.intrinsic
&& gfc_specific_intrinsic (sym
->name
))
1419 || sym
->attr
.external
)
1422 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1425 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1427 return (s
== NULL
) ? 0 : specific_sym (s
);
1431 /* Figure out if the procedure is specific, generic or unknown. */
1434 { PTYPE_GENERIC
= 1, PTYPE_SPECIFIC
, PTYPE_UNKNOWN
}
1438 procedure_kind (gfc_symbol
*sym
)
1440 if (generic_sym (sym
))
1441 return PTYPE_GENERIC
;
1443 if (specific_sym (sym
))
1444 return PTYPE_SPECIFIC
;
1446 return PTYPE_UNKNOWN
;
1449 /* Check references to assumed size arrays. The flag need_full_assumed_size
1450 is nonzero when matching actual arguments. */
1452 static int need_full_assumed_size
= 0;
1455 check_assumed_size_reference (gfc_symbol
*sym
, gfc_expr
*e
)
1457 if (need_full_assumed_size
|| !(sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
))
1460 /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong.
1461 What should it be? */
1462 if (e
->ref
&& (e
->ref
->u
.ar
.end
[e
->ref
->u
.ar
.as
->rank
- 1] == NULL
)
1463 && (e
->ref
->u
.ar
.as
->type
== AS_ASSUMED_SIZE
)
1464 && (e
->ref
->u
.ar
.type
== AR_FULL
))
1466 gfc_error ("The upper bound in the last dimension must "
1467 "appear in the reference to the assumed size "
1468 "array '%s' at %L", sym
->name
, &e
->where
);
1475 /* Look for bad assumed size array references in argument expressions
1476 of elemental and array valued intrinsic procedures. Since this is
1477 called from procedure resolution functions, it only recurses at
1481 resolve_assumed_size_actual (gfc_expr
*e
)
1486 switch (e
->expr_type
)
1489 if (e
->symtree
&& check_assumed_size_reference (e
->symtree
->n
.sym
, e
))
1494 if (resolve_assumed_size_actual (e
->value
.op
.op1
)
1495 || resolve_assumed_size_actual (e
->value
.op
.op2
))
1506 /* Check a generic procedure, passed as an actual argument, to see if
1507 there is a matching specific name. If none, it is an error, and if
1508 more than one, the reference is ambiguous. */
1510 count_specific_procs (gfc_expr
*e
)
1517 sym
= e
->symtree
->n
.sym
;
1519 for (p
= sym
->generic
; p
; p
= p
->next
)
1520 if (strcmp (sym
->name
, p
->sym
->name
) == 0)
1522 e
->symtree
= gfc_find_symtree (p
->sym
->ns
->sym_root
,
1528 gfc_error ("'%s' at %L is ambiguous", e
->symtree
->n
.sym
->name
,
1532 gfc_error ("GENERIC procedure '%s' is not allowed as an actual "
1533 "argument at %L", sym
->name
, &e
->where
);
1539 /* See if a call to sym could possibly be a not allowed RECURSION because of
1540 a missing RECURSIVE declaration. This means that either sym is the current
1541 context itself, or sym is the parent of a contained procedure calling its
1542 non-RECURSIVE containing procedure.
1543 This also works if sym is an ENTRY. */
1546 is_illegal_recursion (gfc_symbol
* sym
, gfc_namespace
* context
)
1548 gfc_symbol
* proc_sym
;
1549 gfc_symbol
* context_proc
;
1550 gfc_namespace
* real_context
;
1552 if (sym
->attr
.flavor
== FL_PROGRAM
1553 || sym
->attr
.flavor
== FL_DERIVED
)
1556 gcc_assert (sym
->attr
.flavor
== FL_PROCEDURE
);
1558 /* If we've got an ENTRY, find real procedure. */
1559 if (sym
->attr
.entry
&& sym
->ns
->entries
)
1560 proc_sym
= sym
->ns
->entries
->sym
;
1564 /* If sym is RECURSIVE, all is well of course. */
1565 if (proc_sym
->attr
.recursive
|| gfc_option
.flag_recursive
)
1568 /* Find the context procedure's "real" symbol if it has entries.
1569 We look for a procedure symbol, so recurse on the parents if we don't
1570 find one (like in case of a BLOCK construct). */
1571 for (real_context
= context
; ; real_context
= real_context
->parent
)
1573 /* We should find something, eventually! */
1574 gcc_assert (real_context
);
1576 context_proc
= (real_context
->entries
? real_context
->entries
->sym
1577 : real_context
->proc_name
);
1579 /* In some special cases, there may not be a proc_name, like for this
1581 real(bad_kind()) function foo () ...
1582 when checking the call to bad_kind ().
1583 In these cases, we simply return here and assume that the
1588 if (context_proc
->attr
.flavor
!= FL_LABEL
)
1592 /* A call from sym's body to itself is recursion, of course. */
1593 if (context_proc
== proc_sym
)
1596 /* The same is true if context is a contained procedure and sym the
1598 if (context_proc
->attr
.contained
)
1600 gfc_symbol
* parent_proc
;
1602 gcc_assert (context
->parent
);
1603 parent_proc
= (context
->parent
->entries
? context
->parent
->entries
->sym
1604 : context
->parent
->proc_name
);
1606 if (parent_proc
== proc_sym
)
1614 /* Resolve an intrinsic procedure: Set its function/subroutine attribute,
1615 its typespec and formal argument list. */
1618 gfc_resolve_intrinsic (gfc_symbol
*sym
, locus
*loc
)
1620 gfc_intrinsic_sym
* isym
= NULL
;
1626 /* Already resolved. */
1627 if (sym
->from_intmod
&& sym
->ts
.type
!= BT_UNKNOWN
)
1630 /* We already know this one is an intrinsic, so we don't call
1631 gfc_is_intrinsic for full checking but rather use gfc_find_function and
1632 gfc_find_subroutine directly to check whether it is a function or
1635 if (sym
->intmod_sym_id
&& sym
->attr
.subroutine
)
1637 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1638 isym
= gfc_intrinsic_subroutine_by_id (id
);
1640 else if (sym
->intmod_sym_id
)
1642 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1643 isym
= gfc_intrinsic_function_by_id (id
);
1645 else if (!sym
->attr
.subroutine
)
1646 isym
= gfc_find_function (sym
->name
);
1648 if (isym
&& !sym
->attr
.subroutine
)
1650 if (sym
->ts
.type
!= BT_UNKNOWN
&& gfc_option
.warn_surprising
1651 && !sym
->attr
.implicit_type
)
1652 gfc_warning ("Type specified for intrinsic function '%s' at %L is"
1653 " ignored", sym
->name
, &sym
->declared_at
);
1655 if (!sym
->attr
.function
&&
1656 !gfc_add_function(&sym
->attr
, sym
->name
, loc
))
1661 else if (isym
|| (isym
= gfc_find_subroutine (sym
->name
)))
1663 if (sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.implicit_type
)
1665 gfc_error ("Intrinsic subroutine '%s' at %L shall not have a type"
1666 " specifier", sym
->name
, &sym
->declared_at
);
1670 if (!sym
->attr
.subroutine
&&
1671 !gfc_add_subroutine(&sym
->attr
, sym
->name
, loc
))
1676 gfc_error ("'%s' declared INTRINSIC at %L does not exist", sym
->name
,
1681 gfc_copy_formal_args_intr (sym
, isym
);
1683 /* Check it is actually available in the standard settings. */
1684 if (!gfc_check_intrinsic_standard (isym
, &symstd
, false, sym
->declared_at
))
1686 gfc_error ("The intrinsic '%s' declared INTRINSIC at %L is not"
1687 " available in the current standard settings but %s. Use"
1688 " an appropriate -std=* option or enable -fall-intrinsics"
1689 " in order to use it.",
1690 sym
->name
, &sym
->declared_at
, symstd
);
1698 /* Resolve a procedure expression, like passing it to a called procedure or as
1699 RHS for a procedure pointer assignment. */
1702 resolve_procedure_expression (gfc_expr
* expr
)
1706 if (expr
->expr_type
!= EXPR_VARIABLE
)
1708 gcc_assert (expr
->symtree
);
1710 sym
= expr
->symtree
->n
.sym
;
1712 if (sym
->attr
.intrinsic
)
1713 gfc_resolve_intrinsic (sym
, &expr
->where
);
1715 if (sym
->attr
.flavor
!= FL_PROCEDURE
1716 || (sym
->attr
.function
&& sym
->result
== sym
))
1719 /* A non-RECURSIVE procedure that is used as procedure expression within its
1720 own body is in danger of being called recursively. */
1721 if (is_illegal_recursion (sym
, gfc_current_ns
))
1722 gfc_warning ("Non-RECURSIVE procedure '%s' at %L is possibly calling"
1723 " itself recursively. Declare it RECURSIVE or use"
1724 " -frecursive", sym
->name
, &expr
->where
);
1730 /* Resolve an actual argument list. Most of the time, this is just
1731 resolving the expressions in the list.
1732 The exception is that we sometimes have to decide whether arguments
1733 that look like procedure arguments are really simple variable
1737 resolve_actual_arglist (gfc_actual_arglist
*arg
, procedure_type ptype
,
1738 bool no_formal_args
)
1741 gfc_symtree
*parent_st
;
1743 int save_need_full_assumed_size
;
1744 bool return_value
= false;
1745 bool actual_arg_sav
= actual_arg
, first_actual_arg_sav
= first_actual_arg
;
1748 first_actual_arg
= true;
1750 for (; arg
; arg
= arg
->next
)
1755 /* Check the label is a valid branching target. */
1758 if (arg
->label
->defined
== ST_LABEL_UNKNOWN
)
1760 gfc_error ("Label %d referenced at %L is never defined",
1761 arg
->label
->value
, &arg
->label
->where
);
1765 first_actual_arg
= false;
1769 if (e
->expr_type
== EXPR_VARIABLE
1770 && e
->symtree
->n
.sym
->attr
.generic
1772 && count_specific_procs (e
) != 1)
1775 if (e
->ts
.type
!= BT_PROCEDURE
)
1777 save_need_full_assumed_size
= need_full_assumed_size
;
1778 if (e
->expr_type
!= EXPR_VARIABLE
)
1779 need_full_assumed_size
= 0;
1780 if (!gfc_resolve_expr (e
))
1782 need_full_assumed_size
= save_need_full_assumed_size
;
1786 /* See if the expression node should really be a variable reference. */
1788 sym
= e
->symtree
->n
.sym
;
1790 if (sym
->attr
.flavor
== FL_PROCEDURE
1791 || sym
->attr
.intrinsic
1792 || sym
->attr
.external
)
1796 /* If a procedure is not already determined to be something else
1797 check if it is intrinsic. */
1798 if (gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, e
->where
))
1799 sym
->attr
.intrinsic
= 1;
1801 if (sym
->attr
.proc
== PROC_ST_FUNCTION
)
1803 gfc_error ("Statement function '%s' at %L is not allowed as an "
1804 "actual argument", sym
->name
, &e
->where
);
1807 actual_ok
= gfc_intrinsic_actual_ok (sym
->name
,
1808 sym
->attr
.subroutine
);
1809 if (sym
->attr
.intrinsic
&& actual_ok
== 0)
1811 gfc_error ("Intrinsic '%s' at %L is not allowed as an "
1812 "actual argument", sym
->name
, &e
->where
);
1815 if (sym
->attr
.contained
&& !sym
->attr
.use_assoc
1816 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
1818 if (!gfc_notify_std (GFC_STD_F2008
, "Internal procedure '%s' is"
1819 " used as actual argument at %L",
1820 sym
->name
, &e
->where
))
1824 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
)
1826 gfc_error ("ELEMENTAL non-INTRINSIC procedure '%s' is not "
1827 "allowed as an actual argument at %L", sym
->name
,
1831 /* Check if a generic interface has a specific procedure
1832 with the same name before emitting an error. */
1833 if (sym
->attr
.generic
&& count_specific_procs (e
) != 1)
1836 /* Just in case a specific was found for the expression. */
1837 sym
= e
->symtree
->n
.sym
;
1839 /* If the symbol is the function that names the current (or
1840 parent) scope, then we really have a variable reference. */
1842 if (gfc_is_function_return_value (sym
, sym
->ns
))
1845 /* If all else fails, see if we have a specific intrinsic. */
1846 if (sym
->ts
.type
== BT_UNKNOWN
&& sym
->attr
.intrinsic
)
1848 gfc_intrinsic_sym
*isym
;
1850 isym
= gfc_find_function (sym
->name
);
1851 if (isym
== NULL
|| !isym
->specific
)
1853 gfc_error ("Unable to find a specific INTRINSIC procedure "
1854 "for the reference '%s' at %L", sym
->name
,
1859 sym
->attr
.intrinsic
= 1;
1860 sym
->attr
.function
= 1;
1863 if (!gfc_resolve_expr (e
))
1868 /* See if the name is a module procedure in a parent unit. */
1870 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1873 if (gfc_find_sym_tree (sym
->name
, sym
->ns
->parent
, 1, &parent_st
))
1875 gfc_error ("Symbol '%s' at %L is ambiguous", sym
->name
, &e
->where
);
1879 if (parent_st
== NULL
)
1882 sym
= parent_st
->n
.sym
;
1883 e
->symtree
= parent_st
; /* Point to the right thing. */
1885 if (sym
->attr
.flavor
== FL_PROCEDURE
1886 || sym
->attr
.intrinsic
1887 || sym
->attr
.external
)
1889 if (!gfc_resolve_expr (e
))
1895 e
->expr_type
= EXPR_VARIABLE
;
1897 if ((sym
->as
!= NULL
&& sym
->ts
.type
!= BT_CLASS
)
1898 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
1899 && CLASS_DATA (sym
)->as
))
1901 e
->rank
= sym
->ts
.type
== BT_CLASS
1902 ? CLASS_DATA (sym
)->as
->rank
: sym
->as
->rank
;
1903 e
->ref
= gfc_get_ref ();
1904 e
->ref
->type
= REF_ARRAY
;
1905 e
->ref
->u
.ar
.type
= AR_FULL
;
1906 e
->ref
->u
.ar
.as
= sym
->ts
.type
== BT_CLASS
1907 ? CLASS_DATA (sym
)->as
: sym
->as
;
1910 /* Expressions are assigned a default ts.type of BT_PROCEDURE in
1911 primary.c (match_actual_arg). If above code determines that it
1912 is a variable instead, it needs to be resolved as it was not
1913 done at the beginning of this function. */
1914 save_need_full_assumed_size
= need_full_assumed_size
;
1915 if (e
->expr_type
!= EXPR_VARIABLE
)
1916 need_full_assumed_size
= 0;
1917 if (!gfc_resolve_expr (e
))
1919 need_full_assumed_size
= save_need_full_assumed_size
;
1922 /* Check argument list functions %VAL, %LOC and %REF. There is
1923 nothing to do for %REF. */
1924 if (arg
->name
&& arg
->name
[0] == '%')
1926 if (strncmp ("%VAL", arg
->name
, 4) == 0)
1928 if (e
->ts
.type
== BT_CHARACTER
|| e
->ts
.type
== BT_DERIVED
)
1930 gfc_error ("By-value argument at %L is not of numeric "
1937 gfc_error ("By-value argument at %L cannot be an array or "
1938 "an array section", &e
->where
);
1942 /* Intrinsics are still PROC_UNKNOWN here. However,
1943 since same file external procedures are not resolvable
1944 in gfortran, it is a good deal easier to leave them to
1946 if (ptype
!= PROC_UNKNOWN
1947 && ptype
!= PROC_DUMMY
1948 && ptype
!= PROC_EXTERNAL
1949 && ptype
!= PROC_MODULE
)
1951 gfc_error ("By-value argument at %L is not allowed "
1952 "in this context", &e
->where
);
1957 /* Statement functions have already been excluded above. */
1958 else if (strncmp ("%LOC", arg
->name
, 4) == 0
1959 && e
->ts
.type
== BT_PROCEDURE
)
1961 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_INTERNAL
)
1963 gfc_error ("Passing internal procedure at %L by location "
1964 "not allowed", &e
->where
);
1970 /* Fortran 2008, C1237. */
1971 if (e
->expr_type
== EXPR_VARIABLE
&& gfc_is_coindexed (e
)
1972 && gfc_has_ultimate_pointer (e
))
1974 gfc_error ("Coindexed actual argument at %L with ultimate pointer "
1975 "component", &e
->where
);
1979 first_actual_arg
= false;
1982 return_value
= true;
1985 actual_arg
= actual_arg_sav
;
1986 first_actual_arg
= first_actual_arg_sav
;
1988 return return_value
;
1992 /* Do the checks of the actual argument list that are specific to elemental
1993 procedures. If called with c == NULL, we have a function, otherwise if
1994 expr == NULL, we have a subroutine. */
1997 resolve_elemental_actual (gfc_expr
*expr
, gfc_code
*c
)
1999 gfc_actual_arglist
*arg0
;
2000 gfc_actual_arglist
*arg
;
2001 gfc_symbol
*esym
= NULL
;
2002 gfc_intrinsic_sym
*isym
= NULL
;
2004 gfc_intrinsic_arg
*iformal
= NULL
;
2005 gfc_formal_arglist
*eformal
= NULL
;
2006 bool formal_optional
= false;
2007 bool set_by_optional
= false;
2011 /* Is this an elemental procedure? */
2012 if (expr
&& expr
->value
.function
.actual
!= NULL
)
2014 if (expr
->value
.function
.esym
!= NULL
2015 && expr
->value
.function
.esym
->attr
.elemental
)
2017 arg0
= expr
->value
.function
.actual
;
2018 esym
= expr
->value
.function
.esym
;
2020 else if (expr
->value
.function
.isym
!= NULL
2021 && expr
->value
.function
.isym
->elemental
)
2023 arg0
= expr
->value
.function
.actual
;
2024 isym
= expr
->value
.function
.isym
;
2029 else if (c
&& c
->ext
.actual
!= NULL
)
2031 arg0
= c
->ext
.actual
;
2033 if (c
->resolved_sym
)
2034 esym
= c
->resolved_sym
;
2036 esym
= c
->symtree
->n
.sym
;
2039 if (!esym
->attr
.elemental
)
2045 /* The rank of an elemental is the rank of its array argument(s). */
2046 for (arg
= arg0
; arg
; arg
= arg
->next
)
2048 if (arg
->expr
!= NULL
&& arg
->expr
->rank
!= 0)
2050 rank
= arg
->expr
->rank
;
2051 if (arg
->expr
->expr_type
== EXPR_VARIABLE
2052 && arg
->expr
->symtree
->n
.sym
->attr
.optional
)
2053 set_by_optional
= true;
2055 /* Function specific; set the result rank and shape. */
2059 if (!expr
->shape
&& arg
->expr
->shape
)
2061 expr
->shape
= gfc_get_shape (rank
);
2062 for (i
= 0; i
< rank
; i
++)
2063 mpz_init_set (expr
->shape
[i
], arg
->expr
->shape
[i
]);
2070 /* If it is an array, it shall not be supplied as an actual argument
2071 to an elemental procedure unless an array of the same rank is supplied
2072 as an actual argument corresponding to a nonoptional dummy argument of
2073 that elemental procedure(12.4.1.5). */
2074 formal_optional
= false;
2076 iformal
= isym
->formal
;
2078 eformal
= esym
->formal
;
2080 for (arg
= arg0
; arg
; arg
= arg
->next
)
2084 if (eformal
->sym
&& eformal
->sym
->attr
.optional
)
2085 formal_optional
= true;
2086 eformal
= eformal
->next
;
2088 else if (isym
&& iformal
)
2090 if (iformal
->optional
)
2091 formal_optional
= true;
2092 iformal
= iformal
->next
;
2095 formal_optional
= true;
2097 if (pedantic
&& arg
->expr
!= NULL
2098 && arg
->expr
->expr_type
== EXPR_VARIABLE
2099 && arg
->expr
->symtree
->n
.sym
->attr
.optional
2102 && (set_by_optional
|| arg
->expr
->rank
!= rank
)
2103 && !(isym
&& isym
->id
== GFC_ISYM_CONVERSION
))
2105 gfc_warning ("'%s' at %L is an array and OPTIONAL; IF IT IS "
2106 "MISSING, it cannot be the actual argument of an "
2107 "ELEMENTAL procedure unless there is a non-optional "
2108 "argument with the same rank (12.4.1.5)",
2109 arg
->expr
->symtree
->n
.sym
->name
, &arg
->expr
->where
);
2113 for (arg
= arg0
; arg
; arg
= arg
->next
)
2115 if (arg
->expr
== NULL
|| arg
->expr
->rank
== 0)
2118 /* Being elemental, the last upper bound of an assumed size array
2119 argument must be present. */
2120 if (resolve_assumed_size_actual (arg
->expr
))
2123 /* Elemental procedure's array actual arguments must conform. */
2126 if (!gfc_check_conformance (arg
->expr
, e
, "elemental procedure"))
2133 /* INTENT(OUT) is only allowed for subroutines; if any actual argument
2134 is an array, the intent inout/out variable needs to be also an array. */
2135 if (rank
> 0 && esym
&& expr
== NULL
)
2136 for (eformal
= esym
->formal
, arg
= arg0
; arg
&& eformal
;
2137 arg
= arg
->next
, eformal
= eformal
->next
)
2138 if ((eformal
->sym
->attr
.intent
== INTENT_OUT
2139 || eformal
->sym
->attr
.intent
== INTENT_INOUT
)
2140 && arg
->expr
&& arg
->expr
->rank
== 0)
2142 gfc_error ("Actual argument at %L for INTENT(%s) dummy '%s' of "
2143 "ELEMENTAL subroutine '%s' is a scalar, but another "
2144 "actual argument is an array", &arg
->expr
->where
,
2145 (eformal
->sym
->attr
.intent
== INTENT_OUT
) ? "OUT"
2146 : "INOUT", eformal
->sym
->name
, esym
->name
);
2153 /* This function does the checking of references to global procedures
2154 as defined in sections 18.1 and 14.1, respectively, of the Fortran
2155 77 and 95 standards. It checks for a gsymbol for the name, making
2156 one if it does not already exist. If it already exists, then the
2157 reference being resolved must correspond to the type of gsymbol.
2158 Otherwise, the new symbol is equipped with the attributes of the
2159 reference. The corresponding code that is called in creating
2160 global entities is parse.c.
2162 In addition, for all but -std=legacy, the gsymbols are used to
2163 check the interfaces of external procedures from the same file.
2164 The namespace of the gsymbol is resolved and then, once this is
2165 done the interface is checked. */
2169 not_in_recursive (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2171 if (!gsym_ns
->proc_name
->attr
.recursive
)
2174 if (sym
->ns
== gsym_ns
)
2177 if (sym
->ns
->parent
&& sym
->ns
->parent
== gsym_ns
)
2184 not_entry_self_reference (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2186 if (gsym_ns
->entries
)
2188 gfc_entry_list
*entry
= gsym_ns
->entries
;
2190 for (; entry
; entry
= entry
->next
)
2192 if (strcmp (sym
->name
, entry
->sym
->name
) == 0)
2194 if (strcmp (gsym_ns
->proc_name
->name
,
2195 sym
->ns
->proc_name
->name
) == 0)
2199 && strcmp (gsym_ns
->proc_name
->name
,
2200 sym
->ns
->parent
->proc_name
->name
) == 0)
2209 /* Check for the requirement of an explicit interface. F08:12.4.2.2. */
2212 gfc_explicit_interface_required (gfc_symbol
*sym
, char *errmsg
, int err_len
)
2214 gfc_formal_arglist
*arg
= gfc_sym_get_dummy_args (sym
);
2216 for ( ; arg
; arg
= arg
->next
)
2221 if (arg
->sym
->attr
.allocatable
) /* (2a) */
2223 strncpy (errmsg
, _("allocatable argument"), err_len
);
2226 else if (arg
->sym
->attr
.asynchronous
)
2228 strncpy (errmsg
, _("asynchronous argument"), err_len
);
2231 else if (arg
->sym
->attr
.optional
)
2233 strncpy (errmsg
, _("optional argument"), err_len
);
2236 else if (arg
->sym
->attr
.pointer
)
2238 strncpy (errmsg
, _("pointer argument"), err_len
);
2241 else if (arg
->sym
->attr
.target
)
2243 strncpy (errmsg
, _("target argument"), err_len
);
2246 else if (arg
->sym
->attr
.value
)
2248 strncpy (errmsg
, _("value argument"), err_len
);
2251 else if (arg
->sym
->attr
.volatile_
)
2253 strncpy (errmsg
, _("volatile argument"), err_len
);
2256 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_SHAPE
) /* (2b) */
2258 strncpy (errmsg
, _("assumed-shape argument"), err_len
);
2261 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_RANK
) /* TS 29113, 6.2. */
2263 strncpy (errmsg
, _("assumed-rank argument"), err_len
);
2266 else if (arg
->sym
->attr
.codimension
) /* (2c) */
2268 strncpy (errmsg
, _("coarray argument"), err_len
);
2271 else if (false) /* (2d) TODO: parametrized derived type */
2273 strncpy (errmsg
, _("parametrized derived type argument"), err_len
);
2276 else if (arg
->sym
->ts
.type
== BT_CLASS
) /* (2e) */
2278 strncpy (errmsg
, _("polymorphic argument"), err_len
);
2281 else if (arg
->sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
2283 strncpy (errmsg
, _("NO_ARG_CHECK attribute"), err_len
);
2286 else if (arg
->sym
->ts
.type
== BT_ASSUMED
)
2288 /* As assumed-type is unlimited polymorphic (cf. above).
2289 See also TS 29113, Note 6.1. */
2290 strncpy (errmsg
, _("assumed-type argument"), err_len
);
2295 if (sym
->attr
.function
)
2297 gfc_symbol
*res
= sym
->result
? sym
->result
: sym
;
2299 if (res
->attr
.dimension
) /* (3a) */
2301 strncpy (errmsg
, _("array result"), err_len
);
2304 else if (res
->attr
.pointer
|| res
->attr
.allocatable
) /* (3b) */
2306 strncpy (errmsg
, _("pointer or allocatable result"), err_len
);
2309 else if (res
->ts
.type
== BT_CHARACTER
&& res
->ts
.u
.cl
2310 && res
->ts
.u
.cl
->length
2311 && res
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
) /* (3c) */
2313 strncpy (errmsg
, _("result with non-constant character length"), err_len
);
2318 if (sym
->attr
.elemental
) /* (4) */
2320 strncpy (errmsg
, _("elemental procedure"), err_len
);
2323 else if (sym
->attr
.is_bind_c
) /* (5) */
2325 strncpy (errmsg
, _("bind(c) procedure"), err_len
);
2334 resolve_global_procedure (gfc_symbol
*sym
, locus
*where
,
2335 gfc_actual_arglist
**actual
, int sub
)
2339 enum gfc_symbol_type type
;
2342 type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
2344 gsym
= gfc_get_gsymbol (sym
->binding_label
? sym
->binding_label
: sym
->name
);
2346 if ((gsym
->type
!= GSYM_UNKNOWN
&& gsym
->type
!= type
))
2347 gfc_global_used (gsym
, where
);
2349 if ((sym
->attr
.if_source
== IFSRC_UNKNOWN
2350 || sym
->attr
.if_source
== IFSRC_IFBODY
)
2351 && gsym
->type
!= GSYM_UNKNOWN
2353 && gsym
->ns
->resolved
!= -1
2354 && gsym
->ns
->proc_name
2355 && not_in_recursive (sym
, gsym
->ns
)
2356 && not_entry_self_reference (sym
, gsym
->ns
))
2358 gfc_symbol
*def_sym
;
2360 /* Resolve the gsymbol namespace if needed. */
2361 if (!gsym
->ns
->resolved
)
2363 gfc_dt_list
*old_dt_list
;
2364 struct gfc_omp_saved_state old_omp_state
;
2366 /* Stash away derived types so that the backend_decls do not
2368 old_dt_list
= gfc_derived_types
;
2369 gfc_derived_types
= NULL
;
2370 /* And stash away openmp state. */
2371 gfc_omp_save_and_clear_state (&old_omp_state
);
2373 gfc_resolve (gsym
->ns
);
2375 /* Store the new derived types with the global namespace. */
2376 if (gfc_derived_types
)
2377 gsym
->ns
->derived_types
= gfc_derived_types
;
2379 /* Restore the derived types of this namespace. */
2380 gfc_derived_types
= old_dt_list
;
2381 /* And openmp state. */
2382 gfc_omp_restore_state (&old_omp_state
);
2385 /* Make sure that translation for the gsymbol occurs before
2386 the procedure currently being resolved. */
2387 ns
= gfc_global_ns_list
;
2388 for (; ns
&& ns
!= gsym
->ns
; ns
= ns
->sibling
)
2390 if (ns
->sibling
== gsym
->ns
)
2392 ns
->sibling
= gsym
->ns
->sibling
;
2393 gsym
->ns
->sibling
= gfc_global_ns_list
;
2394 gfc_global_ns_list
= gsym
->ns
;
2399 def_sym
= gsym
->ns
->proc_name
;
2401 /* This can happen if a binding name has been specified. */
2402 if (gsym
->binding_label
&& gsym
->sym_name
!= def_sym
->name
)
2403 gfc_find_symbol (gsym
->sym_name
, gsym
->ns
, 0, &def_sym
);
2405 if (def_sym
->attr
.entry_master
)
2407 gfc_entry_list
*entry
;
2408 for (entry
= gsym
->ns
->entries
; entry
; entry
= entry
->next
)
2409 if (strcmp (entry
->sym
->name
, sym
->name
) == 0)
2411 def_sym
= entry
->sym
;
2416 if (sym
->attr
.function
&& !gfc_compare_types (&sym
->ts
, &def_sym
->ts
))
2418 gfc_error ("Return type mismatch of function '%s' at %L (%s/%s)",
2419 sym
->name
, &sym
->declared_at
, gfc_typename (&sym
->ts
),
2420 gfc_typename (&def_sym
->ts
));
2424 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
2425 && gfc_explicit_interface_required (def_sym
, reason
, sizeof(reason
)))
2427 gfc_error ("Explicit interface required for '%s' at %L: %s",
2428 sym
->name
, &sym
->declared_at
, reason
);
2432 if (!pedantic
&& (gfc_option
.allow_std
& GFC_STD_GNU
))
2433 /* Turn erros into warnings with -std=gnu and -std=legacy. */
2434 gfc_errors_to_warnings (1);
2436 if (!gfc_compare_interfaces (sym
, def_sym
, sym
->name
, 0, 1,
2437 reason
, sizeof(reason
), NULL
, NULL
))
2439 gfc_error ("Interface mismatch in global procedure '%s' at %L: %s ",
2440 sym
->name
, &sym
->declared_at
, reason
);
2445 || ((gfc_option
.warn_std
& GFC_STD_LEGACY
)
2446 && !(gfc_option
.warn_std
& GFC_STD_GNU
)))
2447 gfc_errors_to_warnings (1);
2449 if (sym
->attr
.if_source
!= IFSRC_IFBODY
)
2450 gfc_procedure_use (def_sym
, actual
, where
);
2454 gfc_errors_to_warnings (0);
2456 if (gsym
->type
== GSYM_UNKNOWN
)
2459 gsym
->where
= *where
;
2466 /************* Function resolution *************/
2468 /* Resolve a function call known to be generic.
2469 Section 14.1.2.4.1. */
2472 resolve_generic_f0 (gfc_expr
*expr
, gfc_symbol
*sym
)
2476 if (sym
->attr
.generic
)
2478 s
= gfc_search_interface (sym
->generic
, 0, &expr
->value
.function
.actual
);
2481 expr
->value
.function
.name
= s
->name
;
2482 expr
->value
.function
.esym
= s
;
2484 if (s
->ts
.type
!= BT_UNKNOWN
)
2486 else if (s
->result
!= NULL
&& s
->result
->ts
.type
!= BT_UNKNOWN
)
2487 expr
->ts
= s
->result
->ts
;
2490 expr
->rank
= s
->as
->rank
;
2491 else if (s
->result
!= NULL
&& s
->result
->as
!= NULL
)
2492 expr
->rank
= s
->result
->as
->rank
;
2494 gfc_set_sym_referenced (expr
->value
.function
.esym
);
2499 /* TODO: Need to search for elemental references in generic
2503 if (sym
->attr
.intrinsic
)
2504 return gfc_intrinsic_func_interface (expr
, 0);
2511 resolve_generic_f (gfc_expr
*expr
)
2515 gfc_interface
*intr
= NULL
;
2517 sym
= expr
->symtree
->n
.sym
;
2521 m
= resolve_generic_f0 (expr
, sym
);
2524 else if (m
== MATCH_ERROR
)
2529 for (intr
= sym
->generic
; intr
; intr
= intr
->next
)
2530 if (intr
->sym
->attr
.flavor
== FL_DERIVED
)
2533 if (sym
->ns
->parent
== NULL
)
2535 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2539 if (!generic_sym (sym
))
2543 /* Last ditch attempt. See if the reference is to an intrinsic
2544 that possesses a matching interface. 14.1.2.4 */
2545 if (sym
&& !intr
&& !gfc_is_intrinsic (sym
, 0, expr
->where
))
2547 gfc_error ("There is no specific function for the generic '%s' "
2548 "at %L", expr
->symtree
->n
.sym
->name
, &expr
->where
);
2554 if (!gfc_convert_to_structure_constructor (expr
, intr
->sym
, NULL
,
2557 return resolve_structure_cons (expr
, 0);
2560 m
= gfc_intrinsic_func_interface (expr
, 0);
2565 gfc_error ("Generic function '%s' at %L is not consistent with a "
2566 "specific intrinsic interface", expr
->symtree
->n
.sym
->name
,
2573 /* Resolve a function call known to be specific. */
2576 resolve_specific_f0 (gfc_symbol
*sym
, gfc_expr
*expr
)
2580 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
2582 if (sym
->attr
.dummy
)
2584 sym
->attr
.proc
= PROC_DUMMY
;
2588 sym
->attr
.proc
= PROC_EXTERNAL
;
2592 if (sym
->attr
.proc
== PROC_MODULE
2593 || sym
->attr
.proc
== PROC_ST_FUNCTION
2594 || sym
->attr
.proc
== PROC_INTERNAL
)
2597 if (sym
->attr
.intrinsic
)
2599 m
= gfc_intrinsic_func_interface (expr
, 1);
2603 gfc_error ("Function '%s' at %L is INTRINSIC but is not compatible "
2604 "with an intrinsic", sym
->name
, &expr
->where
);
2612 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2615 expr
->ts
= sym
->result
->ts
;
2618 expr
->value
.function
.name
= sym
->name
;
2619 expr
->value
.function
.esym
= sym
;
2620 if (sym
->as
!= NULL
)
2621 expr
->rank
= sym
->as
->rank
;
2628 resolve_specific_f (gfc_expr
*expr
)
2633 sym
= expr
->symtree
->n
.sym
;
2637 m
= resolve_specific_f0 (sym
, expr
);
2640 if (m
== MATCH_ERROR
)
2643 if (sym
->ns
->parent
== NULL
)
2646 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2652 gfc_error ("Unable to resolve the specific function '%s' at %L",
2653 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2659 /* Resolve a procedure call not known to be generic nor specific. */
2662 resolve_unknown_f (gfc_expr
*expr
)
2667 sym
= expr
->symtree
->n
.sym
;
2669 if (sym
->attr
.dummy
)
2671 sym
->attr
.proc
= PROC_DUMMY
;
2672 expr
->value
.function
.name
= sym
->name
;
2676 /* See if we have an intrinsic function reference. */
2678 if (gfc_is_intrinsic (sym
, 0, expr
->where
))
2680 if (gfc_intrinsic_func_interface (expr
, 1) == MATCH_YES
)
2685 /* The reference is to an external name. */
2687 sym
->attr
.proc
= PROC_EXTERNAL
;
2688 expr
->value
.function
.name
= sym
->name
;
2689 expr
->value
.function
.esym
= expr
->symtree
->n
.sym
;
2691 if (sym
->as
!= NULL
)
2692 expr
->rank
= sym
->as
->rank
;
2694 /* Type of the expression is either the type of the symbol or the
2695 default type of the symbol. */
2698 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2700 if (sym
->ts
.type
!= BT_UNKNOWN
)
2704 ts
= gfc_get_default_type (sym
->name
, sym
->ns
);
2706 if (ts
->type
== BT_UNKNOWN
)
2708 gfc_error ("Function '%s' at %L has no IMPLICIT type",
2709 sym
->name
, &expr
->where
);
2720 /* Return true, if the symbol is an external procedure. */
2722 is_external_proc (gfc_symbol
*sym
)
2724 if (!sym
->attr
.dummy
&& !sym
->attr
.contained
2725 && !gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, sym
->declared_at
)
2726 && sym
->attr
.proc
!= PROC_ST_FUNCTION
2727 && !sym
->attr
.proc_pointer
2728 && !sym
->attr
.use_assoc
2736 /* Figure out if a function reference is pure or not. Also set the name
2737 of the function for a potential error message. Return nonzero if the
2738 function is PURE, zero if not. */
2740 pure_stmt_function (gfc_expr
*, gfc_symbol
*);
2743 pure_function (gfc_expr
*e
, const char **name
)
2749 if (e
->symtree
!= NULL
2750 && e
->symtree
->n
.sym
!= NULL
2751 && e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2752 return pure_stmt_function (e
, e
->symtree
->n
.sym
);
2754 if (e
->value
.function
.esym
)
2756 pure
= gfc_pure (e
->value
.function
.esym
);
2757 *name
= e
->value
.function
.esym
->name
;
2759 else if (e
->value
.function
.isym
)
2761 pure
= e
->value
.function
.isym
->pure
2762 || e
->value
.function
.isym
->elemental
;
2763 *name
= e
->value
.function
.isym
->name
;
2767 /* Implicit functions are not pure. */
2769 *name
= e
->value
.function
.name
;
2777 impure_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
,
2778 int *f ATTRIBUTE_UNUSED
)
2782 /* Don't bother recursing into other statement functions
2783 since they will be checked individually for purity. */
2784 if (e
->expr_type
!= EXPR_FUNCTION
2786 || e
->symtree
->n
.sym
== sym
2787 || e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2790 return pure_function (e
, &name
) ? false : true;
2795 pure_stmt_function (gfc_expr
*e
, gfc_symbol
*sym
)
2797 return gfc_traverse_expr (e
, sym
, impure_stmt_fcn
, 0) ? 0 : 1;
2801 /* Resolve a function call, which means resolving the arguments, then figuring
2802 out which entity the name refers to. */
2805 resolve_function (gfc_expr
*expr
)
2807 gfc_actual_arglist
*arg
;
2812 procedure_type p
= PROC_INTRINSIC
;
2813 bool no_formal_args
;
2817 sym
= expr
->symtree
->n
.sym
;
2819 /* If this is a procedure pointer component, it has already been resolved. */
2820 if (gfc_is_proc_ptr_comp (expr
))
2823 if (sym
&& sym
->attr
.intrinsic
2824 && !gfc_resolve_intrinsic (sym
, &expr
->where
))
2827 if (sym
&& (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.subroutine
))
2829 gfc_error ("'%s' at %L is not a function", sym
->name
, &expr
->where
);
2833 /* If this ia a deferred TBP with an abstract interface (which may
2834 of course be referenced), expr->value.function.esym will be set. */
2835 if (sym
&& sym
->attr
.abstract
&& !expr
->value
.function
.esym
)
2837 gfc_error ("ABSTRACT INTERFACE '%s' must not be referenced at %L",
2838 sym
->name
, &expr
->where
);
2842 /* Switch off assumed size checking and do this again for certain kinds
2843 of procedure, once the procedure itself is resolved. */
2844 need_full_assumed_size
++;
2846 if (expr
->symtree
&& expr
->symtree
->n
.sym
)
2847 p
= expr
->symtree
->n
.sym
->attr
.proc
;
2849 if (expr
->value
.function
.isym
&& expr
->value
.function
.isym
->inquiry
)
2850 inquiry_argument
= true;
2851 no_formal_args
= sym
&& is_external_proc (sym
)
2852 && gfc_sym_get_dummy_args (sym
) == NULL
;
2854 if (!resolve_actual_arglist (expr
->value
.function
.actual
,
2857 inquiry_argument
= false;
2861 inquiry_argument
= false;
2863 /* Resume assumed_size checking. */
2864 need_full_assumed_size
--;
2866 /* If the procedure is external, check for usage. */
2867 if (sym
&& is_external_proc (sym
))
2868 resolve_global_procedure (sym
, &expr
->where
,
2869 &expr
->value
.function
.actual
, 0);
2871 if (sym
&& sym
->ts
.type
== BT_CHARACTER
2873 && sym
->ts
.u
.cl
->length
== NULL
2875 && !sym
->ts
.deferred
2876 && expr
->value
.function
.esym
== NULL
2877 && !sym
->attr
.contained
)
2879 /* Internal procedures are taken care of in resolve_contained_fntype. */
2880 gfc_error ("Function '%s' is declared CHARACTER(*) and cannot "
2881 "be used at %L since it is not a dummy argument",
2882 sym
->name
, &expr
->where
);
2886 /* See if function is already resolved. */
2888 if (expr
->value
.function
.name
!= NULL
)
2890 if (expr
->ts
.type
== BT_UNKNOWN
)
2896 /* Apply the rules of section 14.1.2. */
2898 switch (procedure_kind (sym
))
2901 t
= resolve_generic_f (expr
);
2904 case PTYPE_SPECIFIC
:
2905 t
= resolve_specific_f (expr
);
2909 t
= resolve_unknown_f (expr
);
2913 gfc_internal_error ("resolve_function(): bad function type");
2917 /* If the expression is still a function (it might have simplified),
2918 then we check to see if we are calling an elemental function. */
2920 if (expr
->expr_type
!= EXPR_FUNCTION
)
2923 temp
= need_full_assumed_size
;
2924 need_full_assumed_size
= 0;
2926 if (!resolve_elemental_actual (expr
, NULL
))
2929 if (omp_workshare_flag
2930 && expr
->value
.function
.esym
2931 && ! gfc_elemental (expr
->value
.function
.esym
))
2933 gfc_error ("User defined non-ELEMENTAL function '%s' at %L not allowed "
2934 "in WORKSHARE construct", expr
->value
.function
.esym
->name
,
2939 #define GENERIC_ID expr->value.function.isym->id
2940 else if (expr
->value
.function
.actual
!= NULL
2941 && expr
->value
.function
.isym
!= NULL
2942 && GENERIC_ID
!= GFC_ISYM_LBOUND
2943 && GENERIC_ID
!= GFC_ISYM_LEN
2944 && GENERIC_ID
!= GFC_ISYM_LOC
2945 && GENERIC_ID
!= GFC_ISYM_C_LOC
2946 && GENERIC_ID
!= GFC_ISYM_PRESENT
)
2948 /* Array intrinsics must also have the last upper bound of an
2949 assumed size array argument. UBOUND and SIZE have to be
2950 excluded from the check if the second argument is anything
2953 for (arg
= expr
->value
.function
.actual
; arg
; arg
= arg
->next
)
2955 if ((GENERIC_ID
== GFC_ISYM_UBOUND
|| GENERIC_ID
== GFC_ISYM_SIZE
)
2956 && arg
== expr
->value
.function
.actual
2957 && arg
->next
!= NULL
&& arg
->next
->expr
)
2959 if (arg
->next
->expr
->expr_type
!= EXPR_CONSTANT
)
2962 if (arg
->next
->name
&& strncmp (arg
->next
->name
, "kind", 4) == 0)
2965 if ((int)mpz_get_si (arg
->next
->expr
->value
.integer
)
2970 if (arg
->expr
!= NULL
2971 && arg
->expr
->rank
> 0
2972 && resolve_assumed_size_actual (arg
->expr
))
2978 need_full_assumed_size
= temp
;
2981 if (!pure_function (expr
, &name
) && name
)
2985 gfc_error ("Reference to non-PURE function '%s' at %L inside a "
2986 "FORALL %s", name
, &expr
->where
,
2987 forall_flag
== 2 ? "mask" : "block");
2990 else if (do_concurrent_flag
)
2992 gfc_error ("Reference to non-PURE function '%s' at %L inside a "
2993 "DO CONCURRENT %s", name
, &expr
->where
,
2994 do_concurrent_flag
== 2 ? "mask" : "block");
2997 else if (gfc_pure (NULL
))
2999 gfc_error ("Function reference to '%s' at %L is to a non-PURE "
3000 "procedure within a PURE procedure", name
, &expr
->where
);
3004 if (gfc_implicit_pure (NULL
))
3005 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
3008 /* Functions without the RECURSIVE attribution are not allowed to
3009 * call themselves. */
3010 if (expr
->value
.function
.esym
&& !expr
->value
.function
.esym
->attr
.recursive
)
3013 esym
= expr
->value
.function
.esym
;
3015 if (is_illegal_recursion (esym
, gfc_current_ns
))
3017 if (esym
->attr
.entry
&& esym
->ns
->entries
)
3018 gfc_error ("ENTRY '%s' at %L cannot be called recursively, as"
3019 " function '%s' is not RECURSIVE",
3020 esym
->name
, &expr
->where
, esym
->ns
->entries
->sym
->name
);
3022 gfc_error ("Function '%s' at %L cannot be called recursively, as it"
3023 " is not RECURSIVE", esym
->name
, &expr
->where
);
3029 /* Character lengths of use associated functions may contains references to
3030 symbols not referenced from the current program unit otherwise. Make sure
3031 those symbols are marked as referenced. */
3033 if (expr
->ts
.type
== BT_CHARACTER
&& expr
->value
.function
.esym
3034 && expr
->value
.function
.esym
->attr
.use_assoc
)
3036 gfc_expr_set_symbols_referenced (expr
->ts
.u
.cl
->length
);
3039 /* Make sure that the expression has a typespec that works. */
3040 if (expr
->ts
.type
== BT_UNKNOWN
)
3042 if (expr
->symtree
->n
.sym
->result
3043 && expr
->symtree
->n
.sym
->result
->ts
.type
!= BT_UNKNOWN
3044 && !expr
->symtree
->n
.sym
->result
->attr
.proc_pointer
)
3045 expr
->ts
= expr
->symtree
->n
.sym
->result
->ts
;
3052 /************* Subroutine resolution *************/
3055 pure_subroutine (gfc_code
*c
, gfc_symbol
*sym
)
3061 gfc_error ("Subroutine call to '%s' in FORALL block at %L is not PURE",
3062 sym
->name
, &c
->loc
);
3063 else if (do_concurrent_flag
)
3064 gfc_error ("Subroutine call to '%s' in DO CONCURRENT block at %L is not "
3065 "PURE", sym
->name
, &c
->loc
);
3066 else if (gfc_pure (NULL
))
3067 gfc_error ("Subroutine call to '%s' at %L is not PURE", sym
->name
,
3070 if (gfc_implicit_pure (NULL
))
3071 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
3076 resolve_generic_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3080 if (sym
->attr
.generic
)
3082 s
= gfc_search_interface (sym
->generic
, 1, &c
->ext
.actual
);
3085 c
->resolved_sym
= s
;
3086 pure_subroutine (c
, s
);
3090 /* TODO: Need to search for elemental references in generic interface. */
3093 if (sym
->attr
.intrinsic
)
3094 return gfc_intrinsic_sub_interface (c
, 0);
3101 resolve_generic_s (gfc_code
*c
)
3106 sym
= c
->symtree
->n
.sym
;
3110 m
= resolve_generic_s0 (c
, sym
);
3113 else if (m
== MATCH_ERROR
)
3117 if (sym
->ns
->parent
== NULL
)
3119 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3123 if (!generic_sym (sym
))
3127 /* Last ditch attempt. See if the reference is to an intrinsic
3128 that possesses a matching interface. 14.1.2.4 */
3129 sym
= c
->symtree
->n
.sym
;
3131 if (!gfc_is_intrinsic (sym
, 1, c
->loc
))
3133 gfc_error ("There is no specific subroutine for the generic '%s' at %L",
3134 sym
->name
, &c
->loc
);
3138 m
= gfc_intrinsic_sub_interface (c
, 0);
3142 gfc_error ("Generic subroutine '%s' at %L is not consistent with an "
3143 "intrinsic subroutine interface", sym
->name
, &c
->loc
);
3149 /* Resolve a subroutine call known to be specific. */
3152 resolve_specific_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3156 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
3158 if (sym
->attr
.dummy
)
3160 sym
->attr
.proc
= PROC_DUMMY
;
3164 sym
->attr
.proc
= PROC_EXTERNAL
;
3168 if (sym
->attr
.proc
== PROC_MODULE
|| sym
->attr
.proc
== PROC_INTERNAL
)
3171 if (sym
->attr
.intrinsic
)
3173 m
= gfc_intrinsic_sub_interface (c
, 1);
3177 gfc_error ("Subroutine '%s' at %L is INTRINSIC but is not compatible "
3178 "with an intrinsic", sym
->name
, &c
->loc
);
3186 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3188 c
->resolved_sym
= sym
;
3189 pure_subroutine (c
, sym
);
3196 resolve_specific_s (gfc_code
*c
)
3201 sym
= c
->symtree
->n
.sym
;
3205 m
= resolve_specific_s0 (c
, sym
);
3208 if (m
== MATCH_ERROR
)
3211 if (sym
->ns
->parent
== NULL
)
3214 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3220 sym
= c
->symtree
->n
.sym
;
3221 gfc_error ("Unable to resolve the specific subroutine '%s' at %L",
3222 sym
->name
, &c
->loc
);
3228 /* Resolve a subroutine call not known to be generic nor specific. */
3231 resolve_unknown_s (gfc_code
*c
)
3235 sym
= c
->symtree
->n
.sym
;
3237 if (sym
->attr
.dummy
)
3239 sym
->attr
.proc
= PROC_DUMMY
;
3243 /* See if we have an intrinsic function reference. */
3245 if (gfc_is_intrinsic (sym
, 1, c
->loc
))
3247 if (gfc_intrinsic_sub_interface (c
, 1) == MATCH_YES
)
3252 /* The reference is to an external name. */
3255 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3257 c
->resolved_sym
= sym
;
3259 pure_subroutine (c
, sym
);
3265 /* Resolve a subroutine call. Although it was tempting to use the same code
3266 for functions, subroutines and functions are stored differently and this
3267 makes things awkward. */
3270 resolve_call (gfc_code
*c
)
3273 procedure_type ptype
= PROC_INTRINSIC
;
3274 gfc_symbol
*csym
, *sym
;
3275 bool no_formal_args
;
3277 csym
= c
->symtree
? c
->symtree
->n
.sym
: NULL
;
3279 if (csym
&& csym
->ts
.type
!= BT_UNKNOWN
)
3281 gfc_error ("'%s' at %L has a type, which is not consistent with "
3282 "the CALL at %L", csym
->name
, &csym
->declared_at
, &c
->loc
);
3286 if (csym
&& gfc_current_ns
->parent
&& csym
->ns
!= gfc_current_ns
)
3289 gfc_find_sym_tree (c
->symtree
->name
, gfc_current_ns
, 1, &st
);
3290 sym
= st
? st
->n
.sym
: NULL
;
3291 if (sym
&& csym
!= sym
3292 && sym
->ns
== gfc_current_ns
3293 && sym
->attr
.flavor
== FL_PROCEDURE
3294 && sym
->attr
.contained
)
3297 if (csym
->attr
.generic
)
3298 c
->symtree
->n
.sym
= sym
;
3301 csym
= c
->symtree
->n
.sym
;
3305 /* If this ia a deferred TBP, c->expr1 will be set. */
3306 if (!c
->expr1
&& csym
)
3308 if (csym
->attr
.abstract
)
3310 gfc_error ("ABSTRACT INTERFACE '%s' must not be referenced at %L",
3311 csym
->name
, &c
->loc
);
3315 /* Subroutines without the RECURSIVE attribution are not allowed to
3317 if (is_illegal_recursion (csym
, gfc_current_ns
))
3319 if (csym
->attr
.entry
&& csym
->ns
->entries
)
3320 gfc_error ("ENTRY '%s' at %L cannot be called recursively, "
3321 "as subroutine '%s' is not RECURSIVE",
3322 csym
->name
, &c
->loc
, csym
->ns
->entries
->sym
->name
);
3324 gfc_error ("SUBROUTINE '%s' at %L cannot be called recursively, "
3325 "as it is not RECURSIVE", csym
->name
, &c
->loc
);
3331 /* Switch off assumed size checking and do this again for certain kinds
3332 of procedure, once the procedure itself is resolved. */
3333 need_full_assumed_size
++;
3336 ptype
= csym
->attr
.proc
;
3338 no_formal_args
= csym
&& is_external_proc (csym
)
3339 && gfc_sym_get_dummy_args (csym
) == NULL
;
3340 if (!resolve_actual_arglist (c
->ext
.actual
, ptype
, no_formal_args
))
3343 /* Resume assumed_size checking. */
3344 need_full_assumed_size
--;
3346 /* If external, check for usage. */
3347 if (csym
&& is_external_proc (csym
))
3348 resolve_global_procedure (csym
, &c
->loc
, &c
->ext
.actual
, 1);
3351 if (c
->resolved_sym
== NULL
)
3353 c
->resolved_isym
= NULL
;
3354 switch (procedure_kind (csym
))
3357 t
= resolve_generic_s (c
);
3360 case PTYPE_SPECIFIC
:
3361 t
= resolve_specific_s (c
);
3365 t
= resolve_unknown_s (c
);
3369 gfc_internal_error ("resolve_subroutine(): bad function type");
3373 /* Some checks of elemental subroutine actual arguments. */
3374 if (!resolve_elemental_actual (NULL
, c
))
3381 /* Compare the shapes of two arrays that have non-NULL shapes. If both
3382 op1->shape and op2->shape are non-NULL return true if their shapes
3383 match. If both op1->shape and op2->shape are non-NULL return false
3384 if their shapes do not match. If either op1->shape or op2->shape is
3385 NULL, return true. */
3388 compare_shapes (gfc_expr
*op1
, gfc_expr
*op2
)
3395 if (op1
->shape
!= NULL
&& op2
->shape
!= NULL
)
3397 for (i
= 0; i
< op1
->rank
; i
++)
3399 if (mpz_cmp (op1
->shape
[i
], op2
->shape
[i
]) != 0)
3401 gfc_error ("Shapes for operands at %L and %L are not conformable",
3402 &op1
->where
, &op2
->where
);
3413 /* Resolve an operator expression node. This can involve replacing the
3414 operation with a user defined function call. */
3417 resolve_operator (gfc_expr
*e
)
3419 gfc_expr
*op1
, *op2
;
3421 bool dual_locus_error
;
3424 /* Resolve all subnodes-- give them types. */
3426 switch (e
->value
.op
.op
)
3429 if (!gfc_resolve_expr (e
->value
.op
.op2
))
3432 /* Fall through... */
3435 case INTRINSIC_UPLUS
:
3436 case INTRINSIC_UMINUS
:
3437 case INTRINSIC_PARENTHESES
:
3438 if (!gfc_resolve_expr (e
->value
.op
.op1
))
3443 /* Typecheck the new node. */
3445 op1
= e
->value
.op
.op1
;
3446 op2
= e
->value
.op
.op2
;
3447 dual_locus_error
= false;
3449 if ((op1
&& op1
->expr_type
== EXPR_NULL
)
3450 || (op2
&& op2
->expr_type
== EXPR_NULL
))
3452 sprintf (msg
, _("Invalid context for NULL() pointer at %%L"));
3456 switch (e
->value
.op
.op
)
3458 case INTRINSIC_UPLUS
:
3459 case INTRINSIC_UMINUS
:
3460 if (op1
->ts
.type
== BT_INTEGER
3461 || op1
->ts
.type
== BT_REAL
3462 || op1
->ts
.type
== BT_COMPLEX
)
3468 sprintf (msg
, _("Operand of unary numeric operator '%s' at %%L is %s"),
3469 gfc_op2string (e
->value
.op
.op
), gfc_typename (&e
->ts
));
3472 case INTRINSIC_PLUS
:
3473 case INTRINSIC_MINUS
:
3474 case INTRINSIC_TIMES
:
3475 case INTRINSIC_DIVIDE
:
3476 case INTRINSIC_POWER
:
3477 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3479 gfc_type_convert_binary (e
, 1);
3484 _("Operands of binary numeric operator '%s' at %%L are %s/%s"),
3485 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3486 gfc_typename (&op2
->ts
));
3489 case INTRINSIC_CONCAT
:
3490 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3491 && op1
->ts
.kind
== op2
->ts
.kind
)
3493 e
->ts
.type
= BT_CHARACTER
;
3494 e
->ts
.kind
= op1
->ts
.kind
;
3499 _("Operands of string concatenation operator at %%L are %s/%s"),
3500 gfc_typename (&op1
->ts
), gfc_typename (&op2
->ts
));
3506 case INTRINSIC_NEQV
:
3507 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3509 e
->ts
.type
= BT_LOGICAL
;
3510 e
->ts
.kind
= gfc_kind_max (op1
, op2
);
3511 if (op1
->ts
.kind
< e
->ts
.kind
)
3512 gfc_convert_type (op1
, &e
->ts
, 2);
3513 else if (op2
->ts
.kind
< e
->ts
.kind
)
3514 gfc_convert_type (op2
, &e
->ts
, 2);
3518 sprintf (msg
, _("Operands of logical operator '%s' at %%L are %s/%s"),
3519 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3520 gfc_typename (&op2
->ts
));
3525 if (op1
->ts
.type
== BT_LOGICAL
)
3527 e
->ts
.type
= BT_LOGICAL
;
3528 e
->ts
.kind
= op1
->ts
.kind
;
3532 sprintf (msg
, _("Operand of .not. operator at %%L is %s"),
3533 gfc_typename (&op1
->ts
));
3537 case INTRINSIC_GT_OS
:
3539 case INTRINSIC_GE_OS
:
3541 case INTRINSIC_LT_OS
:
3543 case INTRINSIC_LE_OS
:
3544 if (op1
->ts
.type
== BT_COMPLEX
|| op2
->ts
.type
== BT_COMPLEX
)
3546 strcpy (msg
, _("COMPLEX quantities cannot be compared at %L"));
3550 /* Fall through... */
3553 case INTRINSIC_EQ_OS
:
3555 case INTRINSIC_NE_OS
:
3556 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3557 && op1
->ts
.kind
== op2
->ts
.kind
)
3559 e
->ts
.type
= BT_LOGICAL
;
3560 e
->ts
.kind
= gfc_default_logical_kind
;
3564 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3566 gfc_type_convert_binary (e
, 1);
3568 e
->ts
.type
= BT_LOGICAL
;
3569 e
->ts
.kind
= gfc_default_logical_kind
;
3571 if (gfc_option
.warn_compare_reals
)
3573 gfc_intrinsic_op op
= e
->value
.op
.op
;
3575 /* Type conversion has made sure that the types of op1 and op2
3576 agree, so it is only necessary to check the first one. */
3577 if ((op1
->ts
.type
== BT_REAL
|| op1
->ts
.type
== BT_COMPLEX
)
3578 && (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
3579 || op
== INTRINSIC_NE
|| op
== INTRINSIC_NE_OS
))
3583 if (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
)
3584 msg
= "Equality comparison for %s at %L";
3586 msg
= "Inequality comparison for %s at %L";
3588 gfc_warning (msg
, gfc_typename (&op1
->ts
), &op1
->where
);
3595 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3597 _("Logicals at %%L must be compared with %s instead of %s"),
3598 (e
->value
.op
.op
== INTRINSIC_EQ
3599 || e
->value
.op
.op
== INTRINSIC_EQ_OS
)
3600 ? ".eqv." : ".neqv.", gfc_op2string (e
->value
.op
.op
));
3603 _("Operands of comparison operator '%s' at %%L are %s/%s"),
3604 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3605 gfc_typename (&op2
->ts
));
3609 case INTRINSIC_USER
:
3610 if (e
->value
.op
.uop
->op
== NULL
)
3611 sprintf (msg
, _("Unknown operator '%s' at %%L"), e
->value
.op
.uop
->name
);
3612 else if (op2
== NULL
)
3613 sprintf (msg
, _("Operand of user operator '%s' at %%L is %s"),
3614 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
));
3617 sprintf (msg
, _("Operands of user operator '%s' at %%L are %s/%s"),
3618 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
),
3619 gfc_typename (&op2
->ts
));
3620 e
->value
.op
.uop
->op
->sym
->attr
.referenced
= 1;
3625 case INTRINSIC_PARENTHESES
:
3627 if (e
->ts
.type
== BT_CHARACTER
)
3628 e
->ts
.u
.cl
= op1
->ts
.u
.cl
;
3632 gfc_internal_error ("resolve_operator(): Bad intrinsic");
3635 /* Deal with arrayness of an operand through an operator. */
3639 switch (e
->value
.op
.op
)
3641 case INTRINSIC_PLUS
:
3642 case INTRINSIC_MINUS
:
3643 case INTRINSIC_TIMES
:
3644 case INTRINSIC_DIVIDE
:
3645 case INTRINSIC_POWER
:
3646 case INTRINSIC_CONCAT
:
3650 case INTRINSIC_NEQV
:
3652 case INTRINSIC_EQ_OS
:
3654 case INTRINSIC_NE_OS
:
3656 case INTRINSIC_GT_OS
:
3658 case INTRINSIC_GE_OS
:
3660 case INTRINSIC_LT_OS
:
3662 case INTRINSIC_LE_OS
:
3664 if (op1
->rank
== 0 && op2
->rank
== 0)
3667 if (op1
->rank
== 0 && op2
->rank
!= 0)
3669 e
->rank
= op2
->rank
;
3671 if (e
->shape
== NULL
)
3672 e
->shape
= gfc_copy_shape (op2
->shape
, op2
->rank
);
3675 if (op1
->rank
!= 0 && op2
->rank
== 0)
3677 e
->rank
= op1
->rank
;
3679 if (e
->shape
== NULL
)
3680 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3683 if (op1
->rank
!= 0 && op2
->rank
!= 0)
3685 if (op1
->rank
== op2
->rank
)
3687 e
->rank
= op1
->rank
;
3688 if (e
->shape
== NULL
)
3690 t
= compare_shapes (op1
, op2
);
3694 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3699 /* Allow higher level expressions to work. */
3702 /* Try user-defined operators, and otherwise throw an error. */
3703 dual_locus_error
= true;
3705 _("Inconsistent ranks for operator at %%L and %%L"));
3712 case INTRINSIC_PARENTHESES
:
3714 case INTRINSIC_UPLUS
:
3715 case INTRINSIC_UMINUS
:
3716 /* Simply copy arrayness attribute */
3717 e
->rank
= op1
->rank
;
3719 if (e
->shape
== NULL
)
3720 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3728 /* Attempt to simplify the expression. */
3731 t
= gfc_simplify_expr (e
, 0);
3732 /* Some calls do not succeed in simplification and return false
3733 even though there is no error; e.g. variable references to
3734 PARAMETER arrays. */
3735 if (!gfc_is_constant_expr (e
))
3743 match m
= gfc_extend_expr (e
);
3746 if (m
== MATCH_ERROR
)
3750 if (dual_locus_error
)
3751 gfc_error (msg
, &op1
->where
, &op2
->where
);
3753 gfc_error (msg
, &e
->where
);
3759 /************** Array resolution subroutines **************/
3762 { CMP_LT
, CMP_EQ
, CMP_GT
, CMP_UNKNOWN
}
3765 /* Compare two integer expressions. */
3768 compare_bound (gfc_expr
*a
, gfc_expr
*b
)
3772 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
3773 || b
== NULL
|| b
->expr_type
!= EXPR_CONSTANT
)
3776 /* If either of the types isn't INTEGER, we must have
3777 raised an error earlier. */
3779 if (a
->ts
.type
!= BT_INTEGER
|| b
->ts
.type
!= BT_INTEGER
)
3782 i
= mpz_cmp (a
->value
.integer
, b
->value
.integer
);
3792 /* Compare an integer expression with an integer. */
3795 compare_bound_int (gfc_expr
*a
, int b
)
3799 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3802 if (a
->ts
.type
!= BT_INTEGER
)
3803 gfc_internal_error ("compare_bound_int(): Bad expression");
3805 i
= mpz_cmp_si (a
->value
.integer
, b
);
3815 /* Compare an integer expression with a mpz_t. */
3818 compare_bound_mpz_t (gfc_expr
*a
, mpz_t b
)
3822 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3825 if (a
->ts
.type
!= BT_INTEGER
)
3826 gfc_internal_error ("compare_bound_int(): Bad expression");
3828 i
= mpz_cmp (a
->value
.integer
, b
);
3838 /* Compute the last value of a sequence given by a triplet.
3839 Return 0 if it wasn't able to compute the last value, or if the
3840 sequence if empty, and 1 otherwise. */
3843 compute_last_value_for_triplet (gfc_expr
*start
, gfc_expr
*end
,
3844 gfc_expr
*stride
, mpz_t last
)
3848 if (start
== NULL
|| start
->expr_type
!= EXPR_CONSTANT
3849 || end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
3850 || (stride
!= NULL
&& stride
->expr_type
!= EXPR_CONSTANT
))
3853 if (start
->ts
.type
!= BT_INTEGER
|| end
->ts
.type
!= BT_INTEGER
3854 || (stride
!= NULL
&& stride
->ts
.type
!= BT_INTEGER
))
3857 if (stride
== NULL
|| compare_bound_int (stride
, 1) == CMP_EQ
)
3859 if (compare_bound (start
, end
) == CMP_GT
)
3861 mpz_set (last
, end
->value
.integer
);
3865 if (compare_bound_int (stride
, 0) == CMP_GT
)
3867 /* Stride is positive */
3868 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) > 0)
3873 /* Stride is negative */
3874 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) < 0)
3879 mpz_sub (rem
, end
->value
.integer
, start
->value
.integer
);
3880 mpz_tdiv_r (rem
, rem
, stride
->value
.integer
);
3881 mpz_sub (last
, end
->value
.integer
, rem
);
3888 /* Compare a single dimension of an array reference to the array
3892 check_dimension (int i
, gfc_array_ref
*ar
, gfc_array_spec
*as
)
3896 if (ar
->dimen_type
[i
] == DIMEN_STAR
)
3898 gcc_assert (ar
->stride
[i
] == NULL
);
3899 /* This implies [*] as [*:] and [*:3] are not possible. */
3900 if (ar
->start
[i
] == NULL
)
3902 gcc_assert (ar
->end
[i
] == NULL
);
3907 /* Given start, end and stride values, calculate the minimum and
3908 maximum referenced indexes. */
3910 switch (ar
->dimen_type
[i
])
3913 case DIMEN_THIS_IMAGE
:
3918 if (compare_bound (ar
->start
[i
], as
->lower
[i
]) == CMP_LT
)
3921 gfc_warning ("Array reference at %L is out of bounds "
3922 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
3923 mpz_get_si (ar
->start
[i
]->value
.integer
),
3924 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
3926 gfc_warning ("Array reference at %L is out of bounds "
3927 "(%ld < %ld) in codimension %d", &ar
->c_where
[i
],
3928 mpz_get_si (ar
->start
[i
]->value
.integer
),
3929 mpz_get_si (as
->lower
[i
]->value
.integer
),
3933 if (compare_bound (ar
->start
[i
], as
->upper
[i
]) == CMP_GT
)
3936 gfc_warning ("Array reference at %L is out of bounds "
3937 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
3938 mpz_get_si (ar
->start
[i
]->value
.integer
),
3939 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
3941 gfc_warning ("Array reference at %L is out of bounds "
3942 "(%ld > %ld) in codimension %d", &ar
->c_where
[i
],
3943 mpz_get_si (ar
->start
[i
]->value
.integer
),
3944 mpz_get_si (as
->upper
[i
]->value
.integer
),
3953 #define AR_START (ar->start[i] ? ar->start[i] : as->lower[i])
3954 #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i])
3956 comparison comp_start_end
= compare_bound (AR_START
, AR_END
);
3958 /* Check for zero stride, which is not allowed. */
3959 if (compare_bound_int (ar
->stride
[i
], 0) == CMP_EQ
)
3961 gfc_error ("Illegal stride of zero at %L", &ar
->c_where
[i
]);
3965 /* if start == len || (stride > 0 && start < len)
3966 || (stride < 0 && start > len),
3967 then the array section contains at least one element. In this
3968 case, there is an out-of-bounds access if
3969 (start < lower || start > upper). */
3970 if (compare_bound (AR_START
, AR_END
) == CMP_EQ
3971 || ((compare_bound_int (ar
->stride
[i
], 0) == CMP_GT
3972 || ar
->stride
[i
] == NULL
) && comp_start_end
== CMP_LT
)
3973 || (compare_bound_int (ar
->stride
[i
], 0) == CMP_LT
3974 && comp_start_end
== CMP_GT
))
3976 if (compare_bound (AR_START
, as
->lower
[i
]) == CMP_LT
)
3978 gfc_warning ("Lower array reference at %L is out of bounds "
3979 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
3980 mpz_get_si (AR_START
->value
.integer
),
3981 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
3984 if (compare_bound (AR_START
, as
->upper
[i
]) == CMP_GT
)
3986 gfc_warning ("Lower array reference at %L is out of bounds "
3987 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
3988 mpz_get_si (AR_START
->value
.integer
),
3989 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
3994 /* If we can compute the highest index of the array section,
3995 then it also has to be between lower and upper. */
3996 mpz_init (last_value
);
3997 if (compute_last_value_for_triplet (AR_START
, AR_END
, ar
->stride
[i
],
4000 if (compare_bound_mpz_t (as
->lower
[i
], last_value
) == CMP_GT
)
4002 gfc_warning ("Upper array reference at %L is out of bounds "
4003 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4004 mpz_get_si (last_value
),
4005 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4006 mpz_clear (last_value
);
4009 if (compare_bound_mpz_t (as
->upper
[i
], last_value
) == CMP_LT
)
4011 gfc_warning ("Upper array reference at %L is out of bounds "
4012 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4013 mpz_get_si (last_value
),
4014 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4015 mpz_clear (last_value
);
4019 mpz_clear (last_value
);
4027 gfc_internal_error ("check_dimension(): Bad array reference");
4034 /* Compare an array reference with an array specification. */
4037 compare_spec_to_ref (gfc_array_ref
*ar
)
4044 /* TODO: Full array sections are only allowed as actual parameters. */
4045 if (as
->type
== AS_ASSUMED_SIZE
4046 && (/*ar->type == AR_FULL
4047 ||*/ (ar
->type
== AR_SECTION
4048 && ar
->dimen_type
[i
] == DIMEN_RANGE
&& ar
->end
[i
] == NULL
)))
4050 gfc_error ("Rightmost upper bound of assumed size array section "
4051 "not specified at %L", &ar
->where
);
4055 if (ar
->type
== AR_FULL
)
4058 if (as
->rank
!= ar
->dimen
)
4060 gfc_error ("Rank mismatch in array reference at %L (%d/%d)",
4061 &ar
->where
, ar
->dimen
, as
->rank
);
4065 /* ar->codimen == 0 is a local array. */
4066 if (as
->corank
!= ar
->codimen
&& ar
->codimen
!= 0)
4068 gfc_error ("Coindex rank mismatch in array reference at %L (%d/%d)",
4069 &ar
->where
, ar
->codimen
, as
->corank
);
4073 for (i
= 0; i
< as
->rank
; i
++)
4074 if (!check_dimension (i
, ar
, as
))
4077 /* Local access has no coarray spec. */
4078 if (ar
->codimen
!= 0)
4079 for (i
= as
->rank
; i
< as
->rank
+ as
->corank
; i
++)
4081 if (ar
->dimen_type
[i
] != DIMEN_ELEMENT
&& !ar
->in_allocate
4082 && ar
->dimen_type
[i
] != DIMEN_THIS_IMAGE
)
4084 gfc_error ("Coindex of codimension %d must be a scalar at %L",
4085 i
+ 1 - as
->rank
, &ar
->where
);
4088 if (!check_dimension (i
, ar
, as
))
4096 /* Resolve one part of an array index. */
4099 gfc_resolve_index_1 (gfc_expr
*index
, int check_scalar
,
4100 int force_index_integer_kind
)
4107 if (!gfc_resolve_expr (index
))
4110 if (check_scalar
&& index
->rank
!= 0)
4112 gfc_error ("Array index at %L must be scalar", &index
->where
);
4116 if (index
->ts
.type
!= BT_INTEGER
&& index
->ts
.type
!= BT_REAL
)
4118 gfc_error ("Array index at %L must be of INTEGER type, found %s",
4119 &index
->where
, gfc_basic_typename (index
->ts
.type
));
4123 if (index
->ts
.type
== BT_REAL
)
4124 if (!gfc_notify_std (GFC_STD_LEGACY
, "REAL array index at %L",
4128 if ((index
->ts
.kind
!= gfc_index_integer_kind
4129 && force_index_integer_kind
)
4130 || index
->ts
.type
!= BT_INTEGER
)
4133 ts
.type
= BT_INTEGER
;
4134 ts
.kind
= gfc_index_integer_kind
;
4136 gfc_convert_type_warn (index
, &ts
, 2, 0);
4142 /* Resolve one part of an array index. */
4145 gfc_resolve_index (gfc_expr
*index
, int check_scalar
)
4147 return gfc_resolve_index_1 (index
, check_scalar
, 1);
4150 /* Resolve a dim argument to an intrinsic function. */
4153 gfc_resolve_dim_arg (gfc_expr
*dim
)
4158 if (!gfc_resolve_expr (dim
))
4163 gfc_error ("Argument dim at %L must be scalar", &dim
->where
);
4168 if (dim
->ts
.type
!= BT_INTEGER
)
4170 gfc_error ("Argument dim at %L must be of INTEGER type", &dim
->where
);
4174 if (dim
->ts
.kind
!= gfc_index_integer_kind
)
4179 ts
.type
= BT_INTEGER
;
4180 ts
.kind
= gfc_index_integer_kind
;
4182 gfc_convert_type_warn (dim
, &ts
, 2, 0);
4188 /* Given an expression that contains array references, update those array
4189 references to point to the right array specifications. While this is
4190 filled in during matching, this information is difficult to save and load
4191 in a module, so we take care of it here.
4193 The idea here is that the original array reference comes from the
4194 base symbol. We traverse the list of reference structures, setting
4195 the stored reference to references. Component references can
4196 provide an additional array specification. */
4199 find_array_spec (gfc_expr
*e
)
4205 if (e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
)
4206 as
= CLASS_DATA (e
->symtree
->n
.sym
)->as
;
4208 as
= e
->symtree
->n
.sym
->as
;
4210 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4215 gfc_internal_error ("find_array_spec(): Missing spec");
4222 c
= ref
->u
.c
.component
;
4223 if (c
->attr
.dimension
)
4226 gfc_internal_error ("find_array_spec(): unused as(1)");
4237 gfc_internal_error ("find_array_spec(): unused as(2)");
4241 /* Resolve an array reference. */
4244 resolve_array_ref (gfc_array_ref
*ar
)
4246 int i
, check_scalar
;
4249 for (i
= 0; i
< ar
->dimen
+ ar
->codimen
; i
++)
4251 check_scalar
= ar
->dimen_type
[i
] == DIMEN_RANGE
;
4253 /* Do not force gfc_index_integer_kind for the start. We can
4254 do fine with any integer kind. This avoids temporary arrays
4255 created for indexing with a vector. */
4256 if (!gfc_resolve_index_1 (ar
->start
[i
], check_scalar
, 0))
4258 if (!gfc_resolve_index (ar
->end
[i
], check_scalar
))
4260 if (!gfc_resolve_index (ar
->stride
[i
], check_scalar
))
4265 if (ar
->dimen_type
[i
] == DIMEN_UNKNOWN
)
4269 ar
->dimen_type
[i
] = DIMEN_ELEMENT
;
4273 ar
->dimen_type
[i
] = DIMEN_VECTOR
;
4274 if (e
->expr_type
== EXPR_VARIABLE
4275 && e
->symtree
->n
.sym
->ts
.type
== BT_DERIVED
)
4276 ar
->start
[i
] = gfc_get_parentheses (e
);
4280 gfc_error ("Array index at %L is an array of rank %d",
4281 &ar
->c_where
[i
], e
->rank
);
4285 /* Fill in the upper bound, which may be lower than the
4286 specified one for something like a(2:10:5), which is
4287 identical to a(2:7:5). Only relevant for strides not equal
4288 to one. Don't try a division by zero. */
4289 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4290 && ar
->stride
[i
] != NULL
&& ar
->stride
[i
]->expr_type
== EXPR_CONSTANT
4291 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 1L) != 0
4292 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 0L) != 0)
4296 if (gfc_ref_dimen_size (ar
, i
, &size
, &end
))
4298 if (ar
->end
[i
] == NULL
)
4301 gfc_get_constant_expr (BT_INTEGER
, gfc_index_integer_kind
,
4303 mpz_set (ar
->end
[i
]->value
.integer
, end
);
4305 else if (ar
->end
[i
]->ts
.type
== BT_INTEGER
4306 && ar
->end
[i
]->expr_type
== EXPR_CONSTANT
)
4308 mpz_set (ar
->end
[i
]->value
.integer
, end
);
4319 if (ar
->type
== AR_FULL
)
4321 if (ar
->as
->rank
== 0)
4322 ar
->type
= AR_ELEMENT
;
4324 /* Make sure array is the same as array(:,:), this way
4325 we don't need to special case all the time. */
4326 ar
->dimen
= ar
->as
->rank
;
4327 for (i
= 0; i
< ar
->dimen
; i
++)
4329 ar
->dimen_type
[i
] = DIMEN_RANGE
;
4331 gcc_assert (ar
->start
[i
] == NULL
);
4332 gcc_assert (ar
->end
[i
] == NULL
);
4333 gcc_assert (ar
->stride
[i
] == NULL
);
4337 /* If the reference type is unknown, figure out what kind it is. */
4339 if (ar
->type
== AR_UNKNOWN
)
4341 ar
->type
= AR_ELEMENT
;
4342 for (i
= 0; i
< ar
->dimen
; i
++)
4343 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4344 || ar
->dimen_type
[i
] == DIMEN_VECTOR
)
4346 ar
->type
= AR_SECTION
;
4351 if (!ar
->as
->cray_pointee
&& !compare_spec_to_ref (ar
))
4354 if (ar
->as
->corank
&& ar
->codimen
== 0)
4357 ar
->codimen
= ar
->as
->corank
;
4358 for (n
= ar
->dimen
; n
< ar
->dimen
+ ar
->codimen
; n
++)
4359 ar
->dimen_type
[n
] = DIMEN_THIS_IMAGE
;
4367 resolve_substring (gfc_ref
*ref
)
4369 int k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
4371 if (ref
->u
.ss
.start
!= NULL
)
4373 if (!gfc_resolve_expr (ref
->u
.ss
.start
))
4376 if (ref
->u
.ss
.start
->ts
.type
!= BT_INTEGER
)
4378 gfc_error ("Substring start index at %L must be of type INTEGER",
4379 &ref
->u
.ss
.start
->where
);
4383 if (ref
->u
.ss
.start
->rank
!= 0)
4385 gfc_error ("Substring start index at %L must be scalar",
4386 &ref
->u
.ss
.start
->where
);
4390 if (compare_bound_int (ref
->u
.ss
.start
, 1) == CMP_LT
4391 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4392 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4394 gfc_error ("Substring start index at %L is less than one",
4395 &ref
->u
.ss
.start
->where
);
4400 if (ref
->u
.ss
.end
!= NULL
)
4402 if (!gfc_resolve_expr (ref
->u
.ss
.end
))
4405 if (ref
->u
.ss
.end
->ts
.type
!= BT_INTEGER
)
4407 gfc_error ("Substring end index at %L must be of type INTEGER",
4408 &ref
->u
.ss
.end
->where
);
4412 if (ref
->u
.ss
.end
->rank
!= 0)
4414 gfc_error ("Substring end index at %L must be scalar",
4415 &ref
->u
.ss
.end
->where
);
4419 if (ref
->u
.ss
.length
!= NULL
4420 && compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.length
->length
) == CMP_GT
4421 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4422 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4424 gfc_error ("Substring end index at %L exceeds the string length",
4425 &ref
->u
.ss
.start
->where
);
4429 if (compare_bound_mpz_t (ref
->u
.ss
.end
,
4430 gfc_integer_kinds
[k
].huge
) == CMP_GT
4431 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4432 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4434 gfc_error ("Substring end index at %L is too large",
4435 &ref
->u
.ss
.end
->where
);
4444 /* This function supplies missing substring charlens. */
4447 gfc_resolve_substring_charlen (gfc_expr
*e
)
4450 gfc_expr
*start
, *end
;
4452 for (char_ref
= e
->ref
; char_ref
; char_ref
= char_ref
->next
)
4453 if (char_ref
->type
== REF_SUBSTRING
)
4459 gcc_assert (char_ref
->next
== NULL
);
4463 if (e
->ts
.u
.cl
->length
)
4464 gfc_free_expr (e
->ts
.u
.cl
->length
);
4465 else if (e
->expr_type
== EXPR_VARIABLE
4466 && e
->symtree
->n
.sym
->attr
.dummy
)
4470 e
->ts
.type
= BT_CHARACTER
;
4471 e
->ts
.kind
= gfc_default_character_kind
;
4474 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
4476 if (char_ref
->u
.ss
.start
)
4477 start
= gfc_copy_expr (char_ref
->u
.ss
.start
);
4479 start
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
4481 if (char_ref
->u
.ss
.end
)
4482 end
= gfc_copy_expr (char_ref
->u
.ss
.end
);
4483 else if (e
->expr_type
== EXPR_VARIABLE
)
4484 end
= gfc_copy_expr (e
->symtree
->n
.sym
->ts
.u
.cl
->length
);
4490 gfc_free_expr (start
);
4491 gfc_free_expr (end
);
4495 /* Length = (end - start +1). */
4496 e
->ts
.u
.cl
->length
= gfc_subtract (end
, start
);
4497 e
->ts
.u
.cl
->length
= gfc_add (e
->ts
.u
.cl
->length
,
4498 gfc_get_int_expr (gfc_default_integer_kind
,
4501 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
4502 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
4504 /* Make sure that the length is simplified. */
4505 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 1);
4506 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
4510 /* Resolve subtype references. */
4513 resolve_ref (gfc_expr
*expr
)
4515 int current_part_dimension
, n_components
, seen_part_dimension
;
4518 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4519 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.as
== NULL
)
4521 find_array_spec (expr
);
4525 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4529 if (!resolve_array_ref (&ref
->u
.ar
))
4537 if (!resolve_substring (ref
))
4542 /* Check constraints on part references. */
4544 current_part_dimension
= 0;
4545 seen_part_dimension
= 0;
4548 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4553 switch (ref
->u
.ar
.type
)
4556 /* Coarray scalar. */
4557 if (ref
->u
.ar
.as
->rank
== 0)
4559 current_part_dimension
= 0;
4564 current_part_dimension
= 1;
4568 current_part_dimension
= 0;
4572 gfc_internal_error ("resolve_ref(): Bad array reference");
4578 if (current_part_dimension
|| seen_part_dimension
)
4581 if (ref
->u
.c
.component
->attr
.pointer
4582 || ref
->u
.c
.component
->attr
.proc_pointer
4583 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
4584 && CLASS_DATA (ref
->u
.c
.component
)->attr
.pointer
))
4586 gfc_error ("Component to the right of a part reference "
4587 "with nonzero rank must not have the POINTER "
4588 "attribute at %L", &expr
->where
);
4591 else if (ref
->u
.c
.component
->attr
.allocatable
4592 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
4593 && CLASS_DATA (ref
->u
.c
.component
)->attr
.allocatable
))
4596 gfc_error ("Component to the right of a part reference "
4597 "with nonzero rank must not have the ALLOCATABLE "
4598 "attribute at %L", &expr
->where
);
4610 if (((ref
->type
== REF_COMPONENT
&& n_components
> 1)
4611 || ref
->next
== NULL
)
4612 && current_part_dimension
4613 && seen_part_dimension
)
4615 gfc_error ("Two or more part references with nonzero rank must "
4616 "not be specified at %L", &expr
->where
);
4620 if (ref
->type
== REF_COMPONENT
)
4622 if (current_part_dimension
)
4623 seen_part_dimension
= 1;
4625 /* reset to make sure */
4626 current_part_dimension
= 0;
4634 /* Given an expression, determine its shape. This is easier than it sounds.
4635 Leaves the shape array NULL if it is not possible to determine the shape. */
4638 expression_shape (gfc_expr
*e
)
4640 mpz_t array
[GFC_MAX_DIMENSIONS
];
4643 if (e
->rank
<= 0 || e
->shape
!= NULL
)
4646 for (i
= 0; i
< e
->rank
; i
++)
4647 if (!gfc_array_dimen_size (e
, i
, &array
[i
]))
4650 e
->shape
= gfc_get_shape (e
->rank
);
4652 memcpy (e
->shape
, array
, e
->rank
* sizeof (mpz_t
));
4657 for (i
--; i
>= 0; i
--)
4658 mpz_clear (array
[i
]);
4662 /* Given a variable expression node, compute the rank of the expression by
4663 examining the base symbol and any reference structures it may have. */
4666 expression_rank (gfc_expr
*e
)
4671 /* Just to make sure, because EXPR_COMPCALL's also have an e->ref and that
4672 could lead to serious confusion... */
4673 gcc_assert (e
->expr_type
!= EXPR_COMPCALL
);
4677 if (e
->expr_type
== EXPR_ARRAY
)
4679 /* Constructors can have a rank different from one via RESHAPE(). */
4681 if (e
->symtree
== NULL
)
4687 e
->rank
= (e
->symtree
->n
.sym
->as
== NULL
)
4688 ? 0 : e
->symtree
->n
.sym
->as
->rank
;
4694 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4696 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.proc_pointer
4697 && ref
->u
.c
.component
->attr
.function
&& !ref
->next
)
4698 rank
= ref
->u
.c
.component
->as
? ref
->u
.c
.component
->as
->rank
: 0;
4700 if (ref
->type
!= REF_ARRAY
)
4703 if (ref
->u
.ar
.type
== AR_FULL
)
4705 rank
= ref
->u
.ar
.as
->rank
;
4709 if (ref
->u
.ar
.type
== AR_SECTION
)
4711 /* Figure out the rank of the section. */
4713 gfc_internal_error ("expression_rank(): Two array specs");
4715 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
4716 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_RANGE
4717 || ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
4727 expression_shape (e
);
4731 /* Resolve a variable expression. */
4734 resolve_variable (gfc_expr
*e
)
4741 if (e
->symtree
== NULL
)
4743 sym
= e
->symtree
->n
.sym
;
4745 /* Use same check as for TYPE(*) below; this check has to be before TYPE(*)
4746 as ts.type is set to BT_ASSUMED in resolve_symbol. */
4747 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
4749 if (!actual_arg
|| inquiry_argument
)
4751 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may only "
4752 "be used as actual argument", sym
->name
, &e
->where
);
4756 /* TS 29113, 407b. */
4757 else if (e
->ts
.type
== BT_ASSUMED
)
4761 gfc_error ("Assumed-type variable %s at %L may only be used "
4762 "as actual argument", sym
->name
, &e
->where
);
4765 else if (inquiry_argument
&& !first_actual_arg
)
4767 /* FIXME: It doesn't work reliably as inquiry_argument is not set
4768 for all inquiry functions in resolve_function; the reason is
4769 that the function-name resolution happens too late in that
4771 gfc_error ("Assumed-type variable %s at %L as actual argument to "
4772 "an inquiry function shall be the first argument",
4773 sym
->name
, &e
->where
);
4777 /* TS 29113, C535b. */
4778 else if ((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
4779 && CLASS_DATA (sym
)->as
4780 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
4781 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
4782 && sym
->as
->type
== AS_ASSUMED_RANK
))
4786 gfc_error ("Assumed-rank variable %s at %L may only be used as "
4787 "actual argument", sym
->name
, &e
->where
);
4790 else if (inquiry_argument
&& !first_actual_arg
)
4792 /* FIXME: It doesn't work reliably as inquiry_argument is not set
4793 for all inquiry functions in resolve_function; the reason is
4794 that the function-name resolution happens too late in that
4796 gfc_error ("Assumed-rank variable %s at %L as actual argument "
4797 "to an inquiry function shall be the first argument",
4798 sym
->name
, &e
->where
);
4803 if ((sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
)) && e
->ref
4804 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
4805 && e
->ref
->next
== NULL
))
4807 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall not have "
4808 "a subobject reference", sym
->name
, &e
->ref
->u
.ar
.where
);
4811 /* TS 29113, 407b. */
4812 else if (e
->ts
.type
== BT_ASSUMED
&& e
->ref
4813 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
4814 && e
->ref
->next
== NULL
))
4816 gfc_error ("Assumed-type variable %s at %L shall not have a subobject "
4817 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
4821 /* TS 29113, C535b. */
4822 if (((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
4823 && CLASS_DATA (sym
)->as
4824 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
4825 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
4826 && sym
->as
->type
== AS_ASSUMED_RANK
))
4828 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
4829 && e
->ref
->next
== NULL
))
4831 gfc_error ("Assumed-rank variable %s at %L shall not have a subobject "
4832 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
4837 /* If this is an associate-name, it may be parsed with an array reference
4838 in error even though the target is scalar. Fail directly in this case.
4839 TODO Understand why class scalar expressions must be excluded. */
4840 if (sym
->assoc
&& !(sym
->ts
.type
== BT_CLASS
&& e
->rank
== 0))
4842 if (sym
->ts
.type
== BT_CLASS
)
4843 gfc_fix_class_refs (e
);
4844 if (!sym
->attr
.dimension
&& e
->ref
&& e
->ref
->type
== REF_ARRAY
)
4848 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.generic
)
4849 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
4851 /* On the other hand, the parser may not have known this is an array;
4852 in this case, we have to add a FULL reference. */
4853 if (sym
->assoc
&& sym
->attr
.dimension
&& !e
->ref
)
4855 e
->ref
= gfc_get_ref ();
4856 e
->ref
->type
= REF_ARRAY
;
4857 e
->ref
->u
.ar
.type
= AR_FULL
;
4858 e
->ref
->u
.ar
.dimen
= 0;
4861 if (e
->ref
&& !resolve_ref (e
))
4864 if (sym
->attr
.flavor
== FL_PROCEDURE
4865 && (!sym
->attr
.function
4866 || (sym
->attr
.function
&& sym
->result
4867 && sym
->result
->attr
.proc_pointer
4868 && !sym
->result
->attr
.function
)))
4870 e
->ts
.type
= BT_PROCEDURE
;
4871 goto resolve_procedure
;
4874 if (sym
->ts
.type
!= BT_UNKNOWN
)
4875 gfc_variable_attr (e
, &e
->ts
);
4878 /* Must be a simple variable reference. */
4879 if (!gfc_set_default_type (sym
, 1, sym
->ns
))
4884 if (check_assumed_size_reference (sym
, e
))
4887 /* Deal with forward references to entries during resolve_code, to
4888 satisfy, at least partially, 12.5.2.5. */
4889 if (gfc_current_ns
->entries
4890 && current_entry_id
== sym
->entry_id
4893 && cs_base
->current
->op
!= EXEC_ENTRY
)
4895 gfc_entry_list
*entry
;
4896 gfc_formal_arglist
*formal
;
4898 bool seen
, saved_specification_expr
;
4900 /* If the symbol is a dummy... */
4901 if (sym
->attr
.dummy
&& sym
->ns
== gfc_current_ns
)
4903 entry
= gfc_current_ns
->entries
;
4906 /* ...test if the symbol is a parameter of previous entries. */
4907 for (; entry
&& entry
->id
<= current_entry_id
; entry
= entry
->next
)
4908 for (formal
= entry
->sym
->formal
; formal
; formal
= formal
->next
)
4910 if (formal
->sym
&& sym
->name
== formal
->sym
->name
)
4914 /* If it has not been seen as a dummy, this is an error. */
4917 if (specification_expr
)
4918 gfc_error ("Variable '%s', used in a specification expression"
4919 ", is referenced at %L before the ENTRY statement "
4920 "in which it is a parameter",
4921 sym
->name
, &cs_base
->current
->loc
);
4923 gfc_error ("Variable '%s' is used at %L before the ENTRY "
4924 "statement in which it is a parameter",
4925 sym
->name
, &cs_base
->current
->loc
);
4930 /* Now do the same check on the specification expressions. */
4931 saved_specification_expr
= specification_expr
;
4932 specification_expr
= true;
4933 if (sym
->ts
.type
== BT_CHARACTER
4934 && !gfc_resolve_expr (sym
->ts
.u
.cl
->length
))
4938 for (n
= 0; n
< sym
->as
->rank
; n
++)
4940 if (!gfc_resolve_expr (sym
->as
->lower
[n
]))
4942 if (!gfc_resolve_expr (sym
->as
->upper
[n
]))
4945 specification_expr
= saved_specification_expr
;
4948 /* Update the symbol's entry level. */
4949 sym
->entry_id
= current_entry_id
+ 1;
4952 /* If a symbol has been host_associated mark it. This is used latter,
4953 to identify if aliasing is possible via host association. */
4954 if (sym
->attr
.flavor
== FL_VARIABLE
4955 && gfc_current_ns
->parent
4956 && (gfc_current_ns
->parent
== sym
->ns
4957 || (gfc_current_ns
->parent
->parent
4958 && gfc_current_ns
->parent
->parent
== sym
->ns
)))
4959 sym
->attr
.host_assoc
= 1;
4962 if (t
&& !resolve_procedure_expression (e
))
4965 /* F2008, C617 and C1229. */
4966 if (!inquiry_argument
&& (e
->ts
.type
== BT_CLASS
|| e
->ts
.type
== BT_DERIVED
)
4967 && gfc_is_coindexed (e
))
4969 gfc_ref
*ref
, *ref2
= NULL
;
4971 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4973 if (ref
->type
== REF_COMPONENT
)
4975 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
4979 for ( ; ref
; ref
= ref
->next
)
4980 if (ref
->type
== REF_COMPONENT
)
4983 /* Expression itself is not coindexed object. */
4984 if (ref
&& e
->ts
.type
== BT_CLASS
)
4986 gfc_error ("Polymorphic subobject of coindexed object at %L",
4991 /* Expression itself is coindexed object. */
4995 c
= ref2
? ref2
->u
.c
.component
: e
->symtree
->n
.sym
->components
;
4996 for ( ; c
; c
= c
->next
)
4997 if (c
->attr
.allocatable
&& c
->ts
.type
== BT_CLASS
)
4999 gfc_error ("Coindexed object with polymorphic allocatable "
5000 "subcomponent at %L", &e
->where
);
5011 /* Checks to see that the correct symbol has been host associated.
5012 The only situation where this arises is that in which a twice
5013 contained function is parsed after the host association is made.
5014 Therefore, on detecting this, change the symbol in the expression
5015 and convert the array reference into an actual arglist if the old
5016 symbol is a variable. */
5018 check_host_association (gfc_expr
*e
)
5020 gfc_symbol
*sym
, *old_sym
;
5024 gfc_actual_arglist
*arg
, *tail
= NULL
;
5025 bool retval
= e
->expr_type
== EXPR_FUNCTION
;
5027 /* If the expression is the result of substitution in
5028 interface.c(gfc_extend_expr) because there is no way in
5029 which the host association can be wrong. */
5030 if (e
->symtree
== NULL
5031 || e
->symtree
->n
.sym
== NULL
5032 || e
->user_operator
)
5035 old_sym
= e
->symtree
->n
.sym
;
5037 if (gfc_current_ns
->parent
5038 && old_sym
->ns
!= gfc_current_ns
)
5040 /* Use the 'USE' name so that renamed module symbols are
5041 correctly handled. */
5042 gfc_find_symbol (e
->symtree
->name
, gfc_current_ns
, 1, &sym
);
5044 if (sym
&& old_sym
!= sym
5045 && sym
->ts
.type
== old_sym
->ts
.type
5046 && sym
->attr
.flavor
== FL_PROCEDURE
5047 && sym
->attr
.contained
)
5049 /* Clear the shape, since it might not be valid. */
5050 gfc_free_shape (&e
->shape
, e
->rank
);
5052 /* Give the expression the right symtree! */
5053 gfc_find_sym_tree (e
->symtree
->name
, NULL
, 1, &st
);
5054 gcc_assert (st
!= NULL
);
5056 if (old_sym
->attr
.flavor
== FL_PROCEDURE
5057 || e
->expr_type
== EXPR_FUNCTION
)
5059 /* Original was function so point to the new symbol, since
5060 the actual argument list is already attached to the
5062 e
->value
.function
.esym
= NULL
;
5067 /* Original was variable so convert array references into
5068 an actual arglist. This does not need any checking now
5069 since resolve_function will take care of it. */
5070 e
->value
.function
.actual
= NULL
;
5071 e
->expr_type
= EXPR_FUNCTION
;
5074 /* Ambiguity will not arise if the array reference is not
5075 the last reference. */
5076 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5077 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
5080 gcc_assert (ref
->type
== REF_ARRAY
);
5082 /* Grab the start expressions from the array ref and
5083 copy them into actual arguments. */
5084 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
5086 arg
= gfc_get_actual_arglist ();
5087 arg
->expr
= gfc_copy_expr (ref
->u
.ar
.start
[n
]);
5088 if (e
->value
.function
.actual
== NULL
)
5089 tail
= e
->value
.function
.actual
= arg
;
5097 /* Dump the reference list and set the rank. */
5098 gfc_free_ref_list (e
->ref
);
5100 e
->rank
= sym
->as
? sym
->as
->rank
: 0;
5103 gfc_resolve_expr (e
);
5107 /* This might have changed! */
5108 return e
->expr_type
== EXPR_FUNCTION
;
5113 gfc_resolve_character_operator (gfc_expr
*e
)
5115 gfc_expr
*op1
= e
->value
.op
.op1
;
5116 gfc_expr
*op2
= e
->value
.op
.op2
;
5117 gfc_expr
*e1
= NULL
;
5118 gfc_expr
*e2
= NULL
;
5120 gcc_assert (e
->value
.op
.op
== INTRINSIC_CONCAT
);
5122 if (op1
->ts
.u
.cl
&& op1
->ts
.u
.cl
->length
)
5123 e1
= gfc_copy_expr (op1
->ts
.u
.cl
->length
);
5124 else if (op1
->expr_type
== EXPR_CONSTANT
)
5125 e1
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
5126 op1
->value
.character
.length
);
5128 if (op2
->ts
.u
.cl
&& op2
->ts
.u
.cl
->length
)
5129 e2
= gfc_copy_expr (op2
->ts
.u
.cl
->length
);
5130 else if (op2
->expr_type
== EXPR_CONSTANT
)
5131 e2
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
5132 op2
->value
.character
.length
);
5134 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5144 e
->ts
.u
.cl
->length
= gfc_add (e1
, e2
);
5145 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
5146 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
5147 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 0);
5148 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
5154 /* Ensure that an character expression has a charlen and, if possible, a
5155 length expression. */
5158 fixup_charlen (gfc_expr
*e
)
5160 /* The cases fall through so that changes in expression type and the need
5161 for multiple fixes are picked up. In all circumstances, a charlen should
5162 be available for the middle end to hang a backend_decl on. */
5163 switch (e
->expr_type
)
5166 gfc_resolve_character_operator (e
);
5169 if (e
->expr_type
== EXPR_ARRAY
)
5170 gfc_resolve_character_array_constructor (e
);
5172 case EXPR_SUBSTRING
:
5173 if (!e
->ts
.u
.cl
&& e
->ref
)
5174 gfc_resolve_substring_charlen (e
);
5178 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5185 /* Update an actual argument to include the passed-object for type-bound
5186 procedures at the right position. */
5188 static gfc_actual_arglist
*
5189 update_arglist_pass (gfc_actual_arglist
* lst
, gfc_expr
* po
, unsigned argpos
,
5192 gcc_assert (argpos
> 0);
5196 gfc_actual_arglist
* result
;
5198 result
= gfc_get_actual_arglist ();
5202 result
->name
= name
;
5208 lst
->next
= update_arglist_pass (lst
->next
, po
, argpos
- 1, name
);
5210 lst
= update_arglist_pass (NULL
, po
, argpos
- 1, name
);
5215 /* Extract the passed-object from an EXPR_COMPCALL (a copy of it). */
5218 extract_compcall_passed_object (gfc_expr
* e
)
5222 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5224 if (e
->value
.compcall
.base_object
)
5225 po
= gfc_copy_expr (e
->value
.compcall
.base_object
);
5228 po
= gfc_get_expr ();
5229 po
->expr_type
= EXPR_VARIABLE
;
5230 po
->symtree
= e
->symtree
;
5231 po
->ref
= gfc_copy_ref (e
->ref
);
5232 po
->where
= e
->where
;
5235 if (!gfc_resolve_expr (po
))
5242 /* Update the arglist of an EXPR_COMPCALL expression to include the
5246 update_compcall_arglist (gfc_expr
* e
)
5249 gfc_typebound_proc
* tbp
;
5251 tbp
= e
->value
.compcall
.tbp
;
5256 po
= extract_compcall_passed_object (e
);
5260 if (tbp
->nopass
|| e
->value
.compcall
.ignore_pass
)
5266 gcc_assert (tbp
->pass_arg_num
> 0);
5267 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5275 /* Extract the passed object from a PPC call (a copy of it). */
5278 extract_ppc_passed_object (gfc_expr
*e
)
5283 po
= gfc_get_expr ();
5284 po
->expr_type
= EXPR_VARIABLE
;
5285 po
->symtree
= e
->symtree
;
5286 po
->ref
= gfc_copy_ref (e
->ref
);
5287 po
->where
= e
->where
;
5289 /* Remove PPC reference. */
5291 while ((*ref
)->next
)
5292 ref
= &(*ref
)->next
;
5293 gfc_free_ref_list (*ref
);
5296 if (!gfc_resolve_expr (po
))
5303 /* Update the actual arglist of a procedure pointer component to include the
5307 update_ppc_arglist (gfc_expr
* e
)
5311 gfc_typebound_proc
* tb
;
5313 ppc
= gfc_get_proc_ptr_comp (e
);
5321 else if (tb
->nopass
)
5324 po
= extract_ppc_passed_object (e
);
5331 gfc_error ("Passed-object at %L must be scalar", &e
->where
);
5336 if (po
->ts
.type
== BT_DERIVED
&& po
->ts
.u
.derived
->attr
.abstract
)
5338 gfc_error ("Base object for procedure-pointer component call at %L is of"
5339 " ABSTRACT type '%s'", &e
->where
, po
->ts
.u
.derived
->name
);
5343 gcc_assert (tb
->pass_arg_num
> 0);
5344 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5352 /* Check that the object a TBP is called on is valid, i.e. it must not be
5353 of ABSTRACT type (as in subobject%abstract_parent%tbp()). */
5356 check_typebound_baseobject (gfc_expr
* e
)
5359 bool return_value
= false;
5361 base
= extract_compcall_passed_object (e
);
5365 gcc_assert (base
->ts
.type
== BT_DERIVED
|| base
->ts
.type
== BT_CLASS
);
5367 if (base
->ts
.type
== BT_CLASS
&& !gfc_expr_attr (base
).class_ok
)
5371 if (base
->ts
.type
== BT_DERIVED
&& base
->ts
.u
.derived
->attr
.abstract
)
5373 gfc_error ("Base object for type-bound procedure call at %L is of"
5374 " ABSTRACT type '%s'", &e
->where
, base
->ts
.u
.derived
->name
);
5378 /* F08:C1230. If the procedure called is NOPASS,
5379 the base object must be scalar. */
5380 if (e
->value
.compcall
.tbp
->nopass
&& base
->rank
!= 0)
5382 gfc_error ("Base object for NOPASS type-bound procedure call at %L must"
5383 " be scalar", &e
->where
);
5387 return_value
= true;
5390 gfc_free_expr (base
);
5391 return return_value
;
5395 /* Resolve a call to a type-bound procedure, either function or subroutine,
5396 statically from the data in an EXPR_COMPCALL expression. The adapted
5397 arglist and the target-procedure symtree are returned. */
5400 resolve_typebound_static (gfc_expr
* e
, gfc_symtree
** target
,
5401 gfc_actual_arglist
** actual
)
5403 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5404 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5406 /* Update the actual arglist for PASS. */
5407 if (!update_compcall_arglist (e
))
5410 *actual
= e
->value
.compcall
.actual
;
5411 *target
= e
->value
.compcall
.tbp
->u
.specific
;
5413 gfc_free_ref_list (e
->ref
);
5415 e
->value
.compcall
.actual
= NULL
;
5417 /* If we find a deferred typebound procedure, check for derived types
5418 that an overriding typebound procedure has not been missed. */
5419 if (e
->value
.compcall
.name
5420 && !e
->value
.compcall
.tbp
->non_overridable
5421 && e
->value
.compcall
.base_object
5422 && e
->value
.compcall
.base_object
->ts
.type
== BT_DERIVED
)
5425 gfc_symbol
*derived
;
5427 /* Use the derived type of the base_object. */
5428 derived
= e
->value
.compcall
.base_object
->ts
.u
.derived
;
5431 /* If necessary, go through the inheritance chain. */
5432 while (!st
&& derived
)
5434 /* Look for the typebound procedure 'name'. */
5435 if (derived
->f2k_derived
&& derived
->f2k_derived
->tb_sym_root
)
5436 st
= gfc_find_symtree (derived
->f2k_derived
->tb_sym_root
,
5437 e
->value
.compcall
.name
);
5439 derived
= gfc_get_derived_super_type (derived
);
5442 /* Now find the specific name in the derived type namespace. */
5443 if (st
&& st
->n
.tb
&& st
->n
.tb
->u
.specific
)
5444 gfc_find_sym_tree (st
->n
.tb
->u
.specific
->name
,
5445 derived
->ns
, 1, &st
);
5453 /* Get the ultimate declared type from an expression. In addition,
5454 return the last class/derived type reference and the copy of the
5455 reference list. If check_types is set true, derived types are
5456 identified as well as class references. */
5458 get_declared_from_expr (gfc_ref
**class_ref
, gfc_ref
**new_ref
,
5459 gfc_expr
*e
, bool check_types
)
5461 gfc_symbol
*declared
;
5468 *new_ref
= gfc_copy_ref (e
->ref
);
5470 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5472 if (ref
->type
!= REF_COMPONENT
)
5475 if ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
5476 || (check_types
&& ref
->u
.c
.component
->ts
.type
== BT_DERIVED
))
5477 && ref
->u
.c
.component
->attr
.flavor
!= FL_PROCEDURE
)
5479 declared
= ref
->u
.c
.component
->ts
.u
.derived
;
5485 if (declared
== NULL
)
5486 declared
= e
->symtree
->n
.sym
->ts
.u
.derived
;
5492 /* Given an EXPR_COMPCALL calling a GENERIC typebound procedure, figure out
5493 which of the specific bindings (if any) matches the arglist and transform
5494 the expression into a call of that binding. */
5497 resolve_typebound_generic_call (gfc_expr
* e
, const char **name
)
5499 gfc_typebound_proc
* genproc
;
5500 const char* genname
;
5502 gfc_symbol
*derived
;
5504 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5505 genname
= e
->value
.compcall
.name
;
5506 genproc
= e
->value
.compcall
.tbp
;
5508 if (!genproc
->is_generic
)
5511 /* Try the bindings on this type and in the inheritance hierarchy. */
5512 for (; genproc
; genproc
= genproc
->overridden
)
5516 gcc_assert (genproc
->is_generic
);
5517 for (g
= genproc
->u
.generic
; g
; g
= g
->next
)
5520 gfc_actual_arglist
* args
;
5523 gcc_assert (g
->specific
);
5525 if (g
->specific
->error
)
5528 target
= g
->specific
->u
.specific
->n
.sym
;
5530 /* Get the right arglist by handling PASS/NOPASS. */
5531 args
= gfc_copy_actual_arglist (e
->value
.compcall
.actual
);
5532 if (!g
->specific
->nopass
)
5535 po
= extract_compcall_passed_object (e
);
5538 gfc_free_actual_arglist (args
);
5542 gcc_assert (g
->specific
->pass_arg_num
> 0);
5543 gcc_assert (!g
->specific
->error
);
5544 args
= update_arglist_pass (args
, po
, g
->specific
->pass_arg_num
,
5545 g
->specific
->pass_arg
);
5547 resolve_actual_arglist (args
, target
->attr
.proc
,
5548 is_external_proc (target
)
5549 && gfc_sym_get_dummy_args (target
) == NULL
);
5551 /* Check if this arglist matches the formal. */
5552 matches
= gfc_arglist_matches_symbol (&args
, target
);
5554 /* Clean up and break out of the loop if we've found it. */
5555 gfc_free_actual_arglist (args
);
5558 e
->value
.compcall
.tbp
= g
->specific
;
5559 genname
= g
->specific_st
->name
;
5560 /* Pass along the name for CLASS methods, where the vtab
5561 procedure pointer component has to be referenced. */
5569 /* Nothing matching found! */
5570 gfc_error ("Found no matching specific binding for the call to the GENERIC"
5571 " '%s' at %L", genname
, &e
->where
);
5575 /* Make sure that we have the right specific instance for the name. */
5576 derived
= get_declared_from_expr (NULL
, NULL
, e
, true);
5578 st
= gfc_find_typebound_proc (derived
, NULL
, genname
, true, &e
->where
);
5580 e
->value
.compcall
.tbp
= st
->n
.tb
;
5586 /* Resolve a call to a type-bound subroutine. */
5589 resolve_typebound_call (gfc_code
* c
, const char **name
)
5591 gfc_actual_arglist
* newactual
;
5592 gfc_symtree
* target
;
5594 /* Check that's really a SUBROUTINE. */
5595 if (!c
->expr1
->value
.compcall
.tbp
->subroutine
)
5597 gfc_error ("'%s' at %L should be a SUBROUTINE",
5598 c
->expr1
->value
.compcall
.name
, &c
->loc
);
5602 if (!check_typebound_baseobject (c
->expr1
))
5605 /* Pass along the name for CLASS methods, where the vtab
5606 procedure pointer component has to be referenced. */
5608 *name
= c
->expr1
->value
.compcall
.name
;
5610 if (!resolve_typebound_generic_call (c
->expr1
, name
))
5613 /* Transform into an ordinary EXEC_CALL for now. */
5615 if (!resolve_typebound_static (c
->expr1
, &target
, &newactual
))
5618 c
->ext
.actual
= newactual
;
5619 c
->symtree
= target
;
5620 c
->op
= (c
->expr1
->value
.compcall
.assign
? EXEC_ASSIGN_CALL
: EXEC_CALL
);
5622 gcc_assert (!c
->expr1
->ref
&& !c
->expr1
->value
.compcall
.actual
);
5624 gfc_free_expr (c
->expr1
);
5625 c
->expr1
= gfc_get_expr ();
5626 c
->expr1
->expr_type
= EXPR_FUNCTION
;
5627 c
->expr1
->symtree
= target
;
5628 c
->expr1
->where
= c
->loc
;
5630 return resolve_call (c
);
5634 /* Resolve a component-call expression. */
5636 resolve_compcall (gfc_expr
* e
, const char **name
)
5638 gfc_actual_arglist
* newactual
;
5639 gfc_symtree
* target
;
5641 /* Check that's really a FUNCTION. */
5642 if (!e
->value
.compcall
.tbp
->function
)
5644 gfc_error ("'%s' at %L should be a FUNCTION",
5645 e
->value
.compcall
.name
, &e
->where
);
5649 /* These must not be assign-calls! */
5650 gcc_assert (!e
->value
.compcall
.assign
);
5652 if (!check_typebound_baseobject (e
))
5655 /* Pass along the name for CLASS methods, where the vtab
5656 procedure pointer component has to be referenced. */
5658 *name
= e
->value
.compcall
.name
;
5660 if (!resolve_typebound_generic_call (e
, name
))
5662 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5664 /* Take the rank from the function's symbol. */
5665 if (e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
)
5666 e
->rank
= e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
->rank
;
5668 /* For now, we simply transform it into an EXPR_FUNCTION call with the same
5669 arglist to the TBP's binding target. */
5671 if (!resolve_typebound_static (e
, &target
, &newactual
))
5674 e
->value
.function
.actual
= newactual
;
5675 e
->value
.function
.name
= NULL
;
5676 e
->value
.function
.esym
= target
->n
.sym
;
5677 e
->value
.function
.isym
= NULL
;
5678 e
->symtree
= target
;
5679 e
->ts
= target
->n
.sym
->ts
;
5680 e
->expr_type
= EXPR_FUNCTION
;
5682 /* Resolution is not necessary if this is a class subroutine; this
5683 function only has to identify the specific proc. Resolution of
5684 the call will be done next in resolve_typebound_call. */
5685 return gfc_resolve_expr (e
);
5690 /* Resolve a typebound function, or 'method'. First separate all
5691 the non-CLASS references by calling resolve_compcall directly. */
5694 resolve_typebound_function (gfc_expr
* e
)
5696 gfc_symbol
*declared
;
5708 /* Deal with typebound operators for CLASS objects. */
5709 expr
= e
->value
.compcall
.base_object
;
5710 overridable
= !e
->value
.compcall
.tbp
->non_overridable
;
5711 if (expr
&& expr
->ts
.type
== BT_CLASS
&& e
->value
.compcall
.name
)
5713 /* If the base_object is not a variable, the corresponding actual
5714 argument expression must be stored in e->base_expression so
5715 that the corresponding tree temporary can be used as the base
5716 object in gfc_conv_procedure_call. */
5717 if (expr
->expr_type
!= EXPR_VARIABLE
)
5719 gfc_actual_arglist
*args
;
5721 for (args
= e
->value
.function
.actual
; args
; args
= args
->next
)
5723 if (expr
== args
->expr
)
5728 /* Since the typebound operators are generic, we have to ensure
5729 that any delays in resolution are corrected and that the vtab
5732 declared
= ts
.u
.derived
;
5733 c
= gfc_find_component (declared
, "_vptr", true, true);
5734 if (c
->ts
.u
.derived
== NULL
)
5735 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
5737 if (!resolve_compcall (e
, &name
))
5740 /* Use the generic name if it is there. */
5741 name
= name
? name
: e
->value
.function
.esym
->name
;
5742 e
->symtree
= expr
->symtree
;
5743 e
->ref
= gfc_copy_ref (expr
->ref
);
5744 get_declared_from_expr (&class_ref
, NULL
, e
, false);
5746 /* Trim away the extraneous references that emerge from nested
5747 use of interface.c (extend_expr). */
5748 if (class_ref
&& class_ref
->next
)
5750 gfc_free_ref_list (class_ref
->next
);
5751 class_ref
->next
= NULL
;
5753 else if (e
->ref
&& !class_ref
)
5755 gfc_free_ref_list (e
->ref
);
5759 gfc_add_vptr_component (e
);
5760 gfc_add_component_ref (e
, name
);
5761 e
->value
.function
.esym
= NULL
;
5762 if (expr
->expr_type
!= EXPR_VARIABLE
)
5763 e
->base_expr
= expr
;
5768 return resolve_compcall (e
, NULL
);
5770 if (!resolve_ref (e
))
5773 /* Get the CLASS declared type. */
5774 declared
= get_declared_from_expr (&class_ref
, &new_ref
, e
, true);
5776 /* Weed out cases of the ultimate component being a derived type. */
5777 if ((class_ref
&& class_ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
5778 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
5780 gfc_free_ref_list (new_ref
);
5781 return resolve_compcall (e
, NULL
);
5784 c
= gfc_find_component (declared
, "_data", true, true);
5785 declared
= c
->ts
.u
.derived
;
5787 /* Treat the call as if it is a typebound procedure, in order to roll
5788 out the correct name for the specific function. */
5789 if (!resolve_compcall (e
, &name
))
5791 gfc_free_ref_list (new_ref
);
5798 /* Convert the expression to a procedure pointer component call. */
5799 e
->value
.function
.esym
= NULL
;
5805 /* '_vptr' points to the vtab, which contains the procedure pointers. */
5806 gfc_add_vptr_component (e
);
5807 gfc_add_component_ref (e
, name
);
5809 /* Recover the typespec for the expression. This is really only
5810 necessary for generic procedures, where the additional call
5811 to gfc_add_component_ref seems to throw the collection of the
5812 correct typespec. */
5816 gfc_free_ref_list (new_ref
);
5821 /* Resolve a typebound subroutine, or 'method'. First separate all
5822 the non-CLASS references by calling resolve_typebound_call
5826 resolve_typebound_subroutine (gfc_code
*code
)
5828 gfc_symbol
*declared
;
5838 st
= code
->expr1
->symtree
;
5840 /* Deal with typebound operators for CLASS objects. */
5841 expr
= code
->expr1
->value
.compcall
.base_object
;
5842 overridable
= !code
->expr1
->value
.compcall
.tbp
->non_overridable
;
5843 if (expr
&& expr
->ts
.type
== BT_CLASS
&& code
->expr1
->value
.compcall
.name
)
5845 /* If the base_object is not a variable, the corresponding actual
5846 argument expression must be stored in e->base_expression so
5847 that the corresponding tree temporary can be used as the base
5848 object in gfc_conv_procedure_call. */
5849 if (expr
->expr_type
!= EXPR_VARIABLE
)
5851 gfc_actual_arglist
*args
;
5853 args
= code
->expr1
->value
.function
.actual
;
5854 for (; args
; args
= args
->next
)
5855 if (expr
== args
->expr
)
5859 /* Since the typebound operators are generic, we have to ensure
5860 that any delays in resolution are corrected and that the vtab
5862 declared
= expr
->ts
.u
.derived
;
5863 c
= gfc_find_component (declared
, "_vptr", true, true);
5864 if (c
->ts
.u
.derived
== NULL
)
5865 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
5867 if (!resolve_typebound_call (code
, &name
))
5870 /* Use the generic name if it is there. */
5871 name
= name
? name
: code
->expr1
->value
.function
.esym
->name
;
5872 code
->expr1
->symtree
= expr
->symtree
;
5873 code
->expr1
->ref
= gfc_copy_ref (expr
->ref
);
5875 /* Trim away the extraneous references that emerge from nested
5876 use of interface.c (extend_expr). */
5877 get_declared_from_expr (&class_ref
, NULL
, code
->expr1
, false);
5878 if (class_ref
&& class_ref
->next
)
5880 gfc_free_ref_list (class_ref
->next
);
5881 class_ref
->next
= NULL
;
5883 else if (code
->expr1
->ref
&& !class_ref
)
5885 gfc_free_ref_list (code
->expr1
->ref
);
5886 code
->expr1
->ref
= NULL
;
5889 /* Now use the procedure in the vtable. */
5890 gfc_add_vptr_component (code
->expr1
);
5891 gfc_add_component_ref (code
->expr1
, name
);
5892 code
->expr1
->value
.function
.esym
= NULL
;
5893 if (expr
->expr_type
!= EXPR_VARIABLE
)
5894 code
->expr1
->base_expr
= expr
;
5899 return resolve_typebound_call (code
, NULL
);
5901 if (!resolve_ref (code
->expr1
))
5904 /* Get the CLASS declared type. */
5905 get_declared_from_expr (&class_ref
, &new_ref
, code
->expr1
, true);
5907 /* Weed out cases of the ultimate component being a derived type. */
5908 if ((class_ref
&& class_ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
5909 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
5911 gfc_free_ref_list (new_ref
);
5912 return resolve_typebound_call (code
, NULL
);
5915 if (!resolve_typebound_call (code
, &name
))
5917 gfc_free_ref_list (new_ref
);
5920 ts
= code
->expr1
->ts
;
5924 /* Convert the expression to a procedure pointer component call. */
5925 code
->expr1
->value
.function
.esym
= NULL
;
5926 code
->expr1
->symtree
= st
;
5929 code
->expr1
->ref
= new_ref
;
5931 /* '_vptr' points to the vtab, which contains the procedure pointers. */
5932 gfc_add_vptr_component (code
->expr1
);
5933 gfc_add_component_ref (code
->expr1
, name
);
5935 /* Recover the typespec for the expression. This is really only
5936 necessary for generic procedures, where the additional call
5937 to gfc_add_component_ref seems to throw the collection of the
5938 correct typespec. */
5939 code
->expr1
->ts
= ts
;
5942 gfc_free_ref_list (new_ref
);
5948 /* Resolve a CALL to a Procedure Pointer Component (Subroutine). */
5951 resolve_ppc_call (gfc_code
* c
)
5953 gfc_component
*comp
;
5955 comp
= gfc_get_proc_ptr_comp (c
->expr1
);
5956 gcc_assert (comp
!= NULL
);
5958 c
->resolved_sym
= c
->expr1
->symtree
->n
.sym
;
5959 c
->expr1
->expr_type
= EXPR_VARIABLE
;
5961 if (!comp
->attr
.subroutine
)
5962 gfc_add_subroutine (&comp
->attr
, comp
->name
, &c
->expr1
->where
);
5964 if (!resolve_ref (c
->expr1
))
5967 if (!update_ppc_arglist (c
->expr1
))
5970 c
->ext
.actual
= c
->expr1
->value
.compcall
.actual
;
5972 if (!resolve_actual_arglist (c
->ext
.actual
, comp
->attr
.proc
,
5973 !(comp
->ts
.interface
5974 && comp
->ts
.interface
->formal
)))
5977 gfc_ppc_use (comp
, &c
->expr1
->value
.compcall
.actual
, &c
->expr1
->where
);
5983 /* Resolve a Function Call to a Procedure Pointer Component (Function). */
5986 resolve_expr_ppc (gfc_expr
* e
)
5988 gfc_component
*comp
;
5990 comp
= gfc_get_proc_ptr_comp (e
);
5991 gcc_assert (comp
!= NULL
);
5993 /* Convert to EXPR_FUNCTION. */
5994 e
->expr_type
= EXPR_FUNCTION
;
5995 e
->value
.function
.isym
= NULL
;
5996 e
->value
.function
.actual
= e
->value
.compcall
.actual
;
5998 if (comp
->as
!= NULL
)
5999 e
->rank
= comp
->as
->rank
;
6001 if (!comp
->attr
.function
)
6002 gfc_add_function (&comp
->attr
, comp
->name
, &e
->where
);
6004 if (!resolve_ref (e
))
6007 if (!resolve_actual_arglist (e
->value
.function
.actual
, comp
->attr
.proc
,
6008 !(comp
->ts
.interface
6009 && comp
->ts
.interface
->formal
)))
6012 if (!update_ppc_arglist (e
))
6015 gfc_ppc_use (comp
, &e
->value
.compcall
.actual
, &e
->where
);
6022 gfc_is_expandable_expr (gfc_expr
*e
)
6024 gfc_constructor
*con
;
6026 if (e
->expr_type
== EXPR_ARRAY
)
6028 /* Traverse the constructor looking for variables that are flavor
6029 parameter. Parameters must be expanded since they are fully used at
6031 con
= gfc_constructor_first (e
->value
.constructor
);
6032 for (; con
; con
= gfc_constructor_next (con
))
6034 if (con
->expr
->expr_type
== EXPR_VARIABLE
6035 && con
->expr
->symtree
6036 && (con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
6037 || con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_VARIABLE
))
6039 if (con
->expr
->expr_type
== EXPR_ARRAY
6040 && gfc_is_expandable_expr (con
->expr
))
6048 /* Resolve an expression. That is, make sure that types of operands agree
6049 with their operators, intrinsic operators are converted to function calls
6050 for overloaded types and unresolved function references are resolved. */
6053 gfc_resolve_expr (gfc_expr
*e
)
6056 bool inquiry_save
, actual_arg_save
, first_actual_arg_save
;
6061 /* inquiry_argument only applies to variables. */
6062 inquiry_save
= inquiry_argument
;
6063 actual_arg_save
= actual_arg
;
6064 first_actual_arg_save
= first_actual_arg
;
6066 if (e
->expr_type
!= EXPR_VARIABLE
)
6068 inquiry_argument
= false;
6070 first_actual_arg
= false;
6073 switch (e
->expr_type
)
6076 t
= resolve_operator (e
);
6082 if (check_host_association (e
))
6083 t
= resolve_function (e
);
6086 t
= resolve_variable (e
);
6088 expression_rank (e
);
6091 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.u
.cl
== NULL
&& e
->ref
6092 && e
->ref
->type
!= REF_SUBSTRING
)
6093 gfc_resolve_substring_charlen (e
);
6098 t
= resolve_typebound_function (e
);
6101 case EXPR_SUBSTRING
:
6102 t
= resolve_ref (e
);
6111 t
= resolve_expr_ppc (e
);
6116 if (!resolve_ref (e
))
6119 t
= gfc_resolve_array_constructor (e
);
6120 /* Also try to expand a constructor. */
6123 expression_rank (e
);
6124 if (gfc_is_constant_expr (e
) || gfc_is_expandable_expr (e
))
6125 gfc_expand_constructor (e
, false);
6128 /* This provides the opportunity for the length of constructors with
6129 character valued function elements to propagate the string length
6130 to the expression. */
6131 if (t
&& e
->ts
.type
== BT_CHARACTER
)
6133 /* For efficiency, we call gfc_expand_constructor for BT_CHARACTER
6134 here rather then add a duplicate test for it above. */
6135 gfc_expand_constructor (e
, false);
6136 t
= gfc_resolve_character_array_constructor (e
);
6141 case EXPR_STRUCTURE
:
6142 t
= resolve_ref (e
);
6146 t
= resolve_structure_cons (e
, 0);
6150 t
= gfc_simplify_expr (e
, 0);
6154 gfc_internal_error ("gfc_resolve_expr(): Bad expression type");
6157 if (e
->ts
.type
== BT_CHARACTER
&& t
&& !e
->ts
.u
.cl
)
6160 inquiry_argument
= inquiry_save
;
6161 actual_arg
= actual_arg_save
;
6162 first_actual_arg
= first_actual_arg_save
;
6168 /* Resolve an expression from an iterator. They must be scalar and have
6169 INTEGER or (optionally) REAL type. */
6172 gfc_resolve_iterator_expr (gfc_expr
*expr
, bool real_ok
,
6173 const char *name_msgid
)
6175 if (!gfc_resolve_expr (expr
))
6178 if (expr
->rank
!= 0)
6180 gfc_error ("%s at %L must be a scalar", _(name_msgid
), &expr
->where
);
6184 if (expr
->ts
.type
!= BT_INTEGER
)
6186 if (expr
->ts
.type
== BT_REAL
)
6189 return gfc_notify_std (GFC_STD_F95_DEL
,
6190 "%s at %L must be integer",
6191 _(name_msgid
), &expr
->where
);
6194 gfc_error ("%s at %L must be INTEGER", _(name_msgid
),
6201 gfc_error ("%s at %L must be INTEGER", _(name_msgid
), &expr
->where
);
6209 /* Resolve the expressions in an iterator structure. If REAL_OK is
6210 false allow only INTEGER type iterators, otherwise allow REAL types.
6211 Set own_scope to true for ac-implied-do and data-implied-do as those
6212 have a separate scope such that, e.g., a INTENT(IN) doesn't apply. */
6215 gfc_resolve_iterator (gfc_iterator
*iter
, bool real_ok
, bool own_scope
)
6217 if (!gfc_resolve_iterator_expr (iter
->var
, real_ok
, "Loop variable"))
6220 if (!gfc_check_vardef_context (iter
->var
, false, false, own_scope
,
6221 _("iterator variable")))
6224 if (!gfc_resolve_iterator_expr (iter
->start
, real_ok
,
6225 "Start expression in DO loop"))
6228 if (!gfc_resolve_iterator_expr (iter
->end
, real_ok
,
6229 "End expression in DO loop"))
6232 if (!gfc_resolve_iterator_expr (iter
->step
, real_ok
,
6233 "Step expression in DO loop"))
6236 if (iter
->step
->expr_type
== EXPR_CONSTANT
)
6238 if ((iter
->step
->ts
.type
== BT_INTEGER
6239 && mpz_cmp_ui (iter
->step
->value
.integer
, 0) == 0)
6240 || (iter
->step
->ts
.type
== BT_REAL
6241 && mpfr_sgn (iter
->step
->value
.real
) == 0))
6243 gfc_error ("Step expression in DO loop at %L cannot be zero",
6244 &iter
->step
->where
);
6249 /* Convert start, end, and step to the same type as var. */
6250 if (iter
->start
->ts
.kind
!= iter
->var
->ts
.kind
6251 || iter
->start
->ts
.type
!= iter
->var
->ts
.type
)
6252 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 2);
6254 if (iter
->end
->ts
.kind
!= iter
->var
->ts
.kind
6255 || iter
->end
->ts
.type
!= iter
->var
->ts
.type
)
6256 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 2);
6258 if (iter
->step
->ts
.kind
!= iter
->var
->ts
.kind
6259 || iter
->step
->ts
.type
!= iter
->var
->ts
.type
)
6260 gfc_convert_type (iter
->step
, &iter
->var
->ts
, 2);
6262 if (iter
->start
->expr_type
== EXPR_CONSTANT
6263 && iter
->end
->expr_type
== EXPR_CONSTANT
6264 && iter
->step
->expr_type
== EXPR_CONSTANT
)
6267 if (iter
->start
->ts
.type
== BT_INTEGER
)
6269 sgn
= mpz_cmp_ui (iter
->step
->value
.integer
, 0);
6270 cmp
= mpz_cmp (iter
->end
->value
.integer
, iter
->start
->value
.integer
);
6274 sgn
= mpfr_sgn (iter
->step
->value
.real
);
6275 cmp
= mpfr_cmp (iter
->end
->value
.real
, iter
->start
->value
.real
);
6277 if ((sgn
> 0 && cmp
< 0) || (sgn
< 0 && cmp
> 0))
6278 gfc_warning ("DO loop at %L will be executed zero times",
6279 &iter
->step
->where
);
6286 /* Traversal function for find_forall_index. f == 2 signals that
6287 that variable itself is not to be checked - only the references. */
6290 forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int *f
)
6292 if (expr
->expr_type
!= EXPR_VARIABLE
)
6295 /* A scalar assignment */
6296 if (!expr
->ref
|| *f
== 1)
6298 if (expr
->symtree
->n
.sym
== sym
)
6310 /* Check whether the FORALL index appears in the expression or not.
6311 Returns true if SYM is found in EXPR. */
6314 find_forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int f
)
6316 if (gfc_traverse_expr (expr
, sym
, forall_index
, f
))
6323 /* Resolve a list of FORALL iterators. The FORALL index-name is constrained
6324 to be a scalar INTEGER variable. The subscripts and stride are scalar
6325 INTEGERs, and if stride is a constant it must be nonzero.
6326 Furthermore "A subscript or stride in a forall-triplet-spec shall
6327 not contain a reference to any index-name in the
6328 forall-triplet-spec-list in which it appears." (7.5.4.1) */
6331 resolve_forall_iterators (gfc_forall_iterator
*it
)
6333 gfc_forall_iterator
*iter
, *iter2
;
6335 for (iter
= it
; iter
; iter
= iter
->next
)
6337 if (gfc_resolve_expr (iter
->var
)
6338 && (iter
->var
->ts
.type
!= BT_INTEGER
|| iter
->var
->rank
!= 0))
6339 gfc_error ("FORALL index-name at %L must be a scalar INTEGER",
6342 if (gfc_resolve_expr (iter
->start
)
6343 && (iter
->start
->ts
.type
!= BT_INTEGER
|| iter
->start
->rank
!= 0))
6344 gfc_error ("FORALL start expression at %L must be a scalar INTEGER",
6345 &iter
->start
->where
);
6346 if (iter
->var
->ts
.kind
!= iter
->start
->ts
.kind
)
6347 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 1);
6349 if (gfc_resolve_expr (iter
->end
)
6350 && (iter
->end
->ts
.type
!= BT_INTEGER
|| iter
->end
->rank
!= 0))
6351 gfc_error ("FORALL end expression at %L must be a scalar INTEGER",
6353 if (iter
->var
->ts
.kind
!= iter
->end
->ts
.kind
)
6354 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 1);
6356 if (gfc_resolve_expr (iter
->stride
))
6358 if (iter
->stride
->ts
.type
!= BT_INTEGER
|| iter
->stride
->rank
!= 0)
6359 gfc_error ("FORALL stride expression at %L must be a scalar %s",
6360 &iter
->stride
->where
, "INTEGER");
6362 if (iter
->stride
->expr_type
== EXPR_CONSTANT
6363 && mpz_cmp_ui (iter
->stride
->value
.integer
, 0) == 0)
6364 gfc_error ("FORALL stride expression at %L cannot be zero",
6365 &iter
->stride
->where
);
6367 if (iter
->var
->ts
.kind
!= iter
->stride
->ts
.kind
)
6368 gfc_convert_type (iter
->stride
, &iter
->var
->ts
, 1);
6371 for (iter
= it
; iter
; iter
= iter
->next
)
6372 for (iter2
= iter
; iter2
; iter2
= iter2
->next
)
6374 if (find_forall_index (iter2
->start
, iter
->var
->symtree
->n
.sym
, 0)
6375 || find_forall_index (iter2
->end
, iter
->var
->symtree
->n
.sym
, 0)
6376 || find_forall_index (iter2
->stride
, iter
->var
->symtree
->n
.sym
, 0))
6377 gfc_error ("FORALL index '%s' may not appear in triplet "
6378 "specification at %L", iter
->var
->symtree
->name
,
6379 &iter2
->start
->where
);
6384 /* Given a pointer to a symbol that is a derived type, see if it's
6385 inaccessible, i.e. if it's defined in another module and the components are
6386 PRIVATE. The search is recursive if necessary. Returns zero if no
6387 inaccessible components are found, nonzero otherwise. */
6390 derived_inaccessible (gfc_symbol
*sym
)
6394 if (sym
->attr
.use_assoc
&& sym
->attr
.private_comp
)
6397 for (c
= sym
->components
; c
; c
= c
->next
)
6399 if (c
->ts
.type
== BT_DERIVED
&& derived_inaccessible (c
->ts
.u
.derived
))
6407 /* Resolve the argument of a deallocate expression. The expression must be
6408 a pointer or a full array. */
6411 resolve_deallocate_expr (gfc_expr
*e
)
6413 symbol_attribute attr
;
6414 int allocatable
, pointer
;
6420 if (!gfc_resolve_expr (e
))
6423 if (e
->expr_type
!= EXPR_VARIABLE
)
6426 sym
= e
->symtree
->n
.sym
;
6427 unlimited
= UNLIMITED_POLY(sym
);
6429 if (sym
->ts
.type
== BT_CLASS
)
6431 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6432 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6436 allocatable
= sym
->attr
.allocatable
;
6437 pointer
= sym
->attr
.pointer
;
6439 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6444 if (ref
->u
.ar
.type
!= AR_FULL
6445 && !(ref
->u
.ar
.type
== AR_ELEMENT
&& ref
->u
.ar
.as
->rank
== 0
6446 && ref
->u
.ar
.codimen
&& gfc_ref_this_image (ref
)))
6451 c
= ref
->u
.c
.component
;
6452 if (c
->ts
.type
== BT_CLASS
)
6454 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
6455 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
6459 allocatable
= c
->attr
.allocatable
;
6460 pointer
= c
->attr
.pointer
;
6470 attr
= gfc_expr_attr (e
);
6472 if (allocatable
== 0 && attr
.pointer
== 0 && !unlimited
)
6475 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
6481 if (gfc_is_coindexed (e
))
6483 gfc_error ("Coindexed allocatable object at %L", &e
->where
);
6488 && !gfc_check_vardef_context (e
, true, true, false,
6489 _("DEALLOCATE object")))
6491 if (!gfc_check_vardef_context (e
, false, true, false,
6492 _("DEALLOCATE object")))
6499 /* Returns true if the expression e contains a reference to the symbol sym. */
6501 sym_in_expr (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
6503 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
== sym
)
6510 gfc_find_sym_in_expr (gfc_symbol
*sym
, gfc_expr
*e
)
6512 return gfc_traverse_expr (e
, sym
, sym_in_expr
, 0);
6516 /* Given the expression node e for an allocatable/pointer of derived type to be
6517 allocated, get the expression node to be initialized afterwards (needed for
6518 derived types with default initializers, and derived types with allocatable
6519 components that need nullification.) */
6522 gfc_expr_to_initialize (gfc_expr
*e
)
6528 result
= gfc_copy_expr (e
);
6530 /* Change the last array reference from AR_ELEMENT to AR_FULL. */
6531 for (ref
= result
->ref
; ref
; ref
= ref
->next
)
6532 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
6534 ref
->u
.ar
.type
= AR_FULL
;
6536 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
6537 ref
->u
.ar
.start
[i
] = ref
->u
.ar
.end
[i
] = ref
->u
.ar
.stride
[i
] = NULL
;
6542 gfc_free_shape (&result
->shape
, result
->rank
);
6544 /* Recalculate rank, shape, etc. */
6545 gfc_resolve_expr (result
);
6550 /* If the last ref of an expression is an array ref, return a copy of the
6551 expression with that one removed. Otherwise, a copy of the original
6552 expression. This is used for allocate-expressions and pointer assignment
6553 LHS, where there may be an array specification that needs to be stripped
6554 off when using gfc_check_vardef_context. */
6557 remove_last_array_ref (gfc_expr
* e
)
6562 e2
= gfc_copy_expr (e
);
6563 for (r
= &e2
->ref
; *r
; r
= &(*r
)->next
)
6564 if ((*r
)->type
== REF_ARRAY
&& !(*r
)->next
)
6566 gfc_free_ref_list (*r
);
6575 /* Used in resolve_allocate_expr to check that a allocation-object and
6576 a source-expr are conformable. This does not catch all possible
6577 cases; in particular a runtime checking is needed. */
6580 conformable_arrays (gfc_expr
*e1
, gfc_expr
*e2
)
6583 for (tail
= e2
->ref
; tail
&& tail
->next
; tail
= tail
->next
);
6585 /* First compare rank. */
6586 if (tail
&& e1
->rank
!= tail
->u
.ar
.as
->rank
)
6588 gfc_error ("Source-expr at %L must be scalar or have the "
6589 "same rank as the allocate-object at %L",
6590 &e1
->where
, &e2
->where
);
6601 for (i
= 0; i
< e1
->rank
; i
++)
6603 if (tail
->u
.ar
.start
[i
] == NULL
)
6606 if (tail
->u
.ar
.end
[i
])
6608 mpz_set (s
, tail
->u
.ar
.end
[i
]->value
.integer
);
6609 mpz_sub (s
, s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6610 mpz_add_ui (s
, s
, 1);
6614 mpz_set (s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6617 if (mpz_cmp (e1
->shape
[i
], s
) != 0)
6619 gfc_error ("Source-expr at %L and allocate-object at %L must "
6620 "have the same shape", &e1
->where
, &e2
->where
);
6633 /* Resolve the expression in an ALLOCATE statement, doing the additional
6634 checks to see whether the expression is OK or not. The expression must
6635 have a trailing array reference that gives the size of the array. */
6638 resolve_allocate_expr (gfc_expr
*e
, gfc_code
*code
)
6640 int i
, pointer
, allocatable
, dimension
, is_abstract
;
6644 symbol_attribute attr
;
6645 gfc_ref
*ref
, *ref2
;
6648 gfc_symbol
*sym
= NULL
;
6653 /* Mark the utmost array component as being in allocate to allow DIMEN_STAR
6654 checking of coarrays. */
6655 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6656 if (ref
->next
== NULL
)
6659 if (ref
&& ref
->type
== REF_ARRAY
)
6660 ref
->u
.ar
.in_allocate
= true;
6662 if (!gfc_resolve_expr (e
))
6665 /* Make sure the expression is allocatable or a pointer. If it is
6666 pointer, the next-to-last reference must be a pointer. */
6670 sym
= e
->symtree
->n
.sym
;
6672 /* Check whether ultimate component is abstract and CLASS. */
6675 /* Is the allocate-object unlimited polymorphic? */
6676 unlimited
= UNLIMITED_POLY(e
);
6678 if (e
->expr_type
!= EXPR_VARIABLE
)
6681 attr
= gfc_expr_attr (e
);
6682 pointer
= attr
.pointer
;
6683 dimension
= attr
.dimension
;
6684 codimension
= attr
.codimension
;
6688 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
6690 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6691 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6692 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
6693 codimension
= CLASS_DATA (sym
)->attr
.codimension
;
6694 is_abstract
= CLASS_DATA (sym
)->attr
.abstract
;
6698 allocatable
= sym
->attr
.allocatable
;
6699 pointer
= sym
->attr
.pointer
;
6700 dimension
= sym
->attr
.dimension
;
6701 codimension
= sym
->attr
.codimension
;
6706 for (ref
= e
->ref
; ref
; ref2
= ref
, ref
= ref
->next
)
6711 if (ref
->u
.ar
.codimen
> 0)
6714 for (n
= ref
->u
.ar
.dimen
;
6715 n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
6716 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_THIS_IMAGE
)
6723 if (ref
->next
!= NULL
)
6731 gfc_error ("Coindexed allocatable object at %L",
6736 c
= ref
->u
.c
.component
;
6737 if (c
->ts
.type
== BT_CLASS
)
6739 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
6740 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
6741 dimension
= CLASS_DATA (c
)->attr
.dimension
;
6742 codimension
= CLASS_DATA (c
)->attr
.codimension
;
6743 is_abstract
= CLASS_DATA (c
)->attr
.abstract
;
6747 allocatable
= c
->attr
.allocatable
;
6748 pointer
= c
->attr
.pointer
;
6749 dimension
= c
->attr
.dimension
;
6750 codimension
= c
->attr
.codimension
;
6751 is_abstract
= c
->attr
.abstract
;
6763 /* Check for F08:C628. */
6764 if (allocatable
== 0 && pointer
== 0 && !unlimited
)
6766 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
6771 /* Some checks for the SOURCE tag. */
6774 /* Check F03:C631. */
6775 if (!gfc_type_compatible (&e
->ts
, &code
->expr3
->ts
))
6777 gfc_error ("Type of entity at %L is type incompatible with "
6778 "source-expr at %L", &e
->where
, &code
->expr3
->where
);
6782 /* Check F03:C632 and restriction following Note 6.18. */
6783 if (code
->expr3
->rank
> 0 && !unlimited
6784 && !conformable_arrays (code
->expr3
, e
))
6787 /* Check F03:C633. */
6788 if (code
->expr3
->ts
.kind
!= e
->ts
.kind
&& !unlimited
)
6790 gfc_error ("The allocate-object at %L and the source-expr at %L "
6791 "shall have the same kind type parameter",
6792 &e
->where
, &code
->expr3
->where
);
6796 /* Check F2008, C642. */
6797 if (code
->expr3
->ts
.type
== BT_DERIVED
6798 && ((codimension
&& gfc_expr_attr (code
->expr3
).lock_comp
)
6799 || (code
->expr3
->ts
.u
.derived
->from_intmod
6800 == INTMOD_ISO_FORTRAN_ENV
6801 && code
->expr3
->ts
.u
.derived
->intmod_sym_id
6802 == ISOFORTRAN_LOCK_TYPE
)))
6804 gfc_error ("The source-expr at %L shall neither be of type "
6805 "LOCK_TYPE nor have a LOCK_TYPE component if "
6806 "allocate-object at %L is a coarray",
6807 &code
->expr3
->where
, &e
->where
);
6812 /* Check F08:C629. */
6813 if (is_abstract
&& code
->ext
.alloc
.ts
.type
== BT_UNKNOWN
6816 gcc_assert (e
->ts
.type
== BT_CLASS
);
6817 gfc_error ("Allocating %s of ABSTRACT base type at %L requires a "
6818 "type-spec or source-expr", sym
->name
, &e
->where
);
6822 if (code
->ext
.alloc
.ts
.type
== BT_CHARACTER
&& !e
->ts
.deferred
)
6824 int cmp
= gfc_dep_compare_expr (e
->ts
.u
.cl
->length
,
6825 code
->ext
.alloc
.ts
.u
.cl
->length
);
6826 if (cmp
== 1 || cmp
== -1 || cmp
== -3)
6828 gfc_error ("Allocating %s at %L with type-spec requires the same "
6829 "character-length parameter as in the declaration",
6830 sym
->name
, &e
->where
);
6835 /* In the variable definition context checks, gfc_expr_attr is used
6836 on the expression. This is fooled by the array specification
6837 present in e, thus we have to eliminate that one temporarily. */
6838 e2
= remove_last_array_ref (e
);
6841 t
= gfc_check_vardef_context (e2
, true, true, false,
6842 _("ALLOCATE object"));
6844 t
= gfc_check_vardef_context (e2
, false, true, false,
6845 _("ALLOCATE object"));
6850 if (e
->ts
.type
== BT_CLASS
&& CLASS_DATA (e
)->attr
.dimension
6851 && !code
->expr3
&& code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
6853 /* For class arrays, the initialization with SOURCE is done
6854 using _copy and trans_call. It is convenient to exploit that
6855 when the allocated type is different from the declared type but
6856 no SOURCE exists by setting expr3. */
6857 code
->expr3
= gfc_default_initializer (&code
->ext
.alloc
.ts
);
6859 else if (!code
->expr3
)
6861 /* Set up default initializer if needed. */
6865 if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
6866 ts
= code
->ext
.alloc
.ts
;
6870 if (ts
.type
== BT_CLASS
)
6871 ts
= ts
.u
.derived
->components
->ts
;
6873 if (ts
.type
== BT_DERIVED
&& (init_e
= gfc_default_initializer (&ts
)))
6875 gfc_code
*init_st
= gfc_get_code ();
6876 init_st
->loc
= code
->loc
;
6877 init_st
->op
= EXEC_INIT_ASSIGN
;
6878 init_st
->expr1
= gfc_expr_to_initialize (e
);
6879 init_st
->expr2
= init_e
;
6880 init_st
->next
= code
->next
;
6881 code
->next
= init_st
;
6884 else if (code
->expr3
->mold
&& code
->expr3
->ts
.type
== BT_DERIVED
)
6886 /* Default initialization via MOLD (non-polymorphic). */
6887 gfc_expr
*rhs
= gfc_default_initializer (&code
->expr3
->ts
);
6888 gfc_resolve_expr (rhs
);
6889 gfc_free_expr (code
->expr3
);
6893 if (e
->ts
.type
== BT_CLASS
&& !unlimited
&& !UNLIMITED_POLY (code
->expr3
))
6895 /* Make sure the vtab symbol is present when
6896 the module variables are generated. */
6897 gfc_typespec ts
= e
->ts
;
6899 ts
= code
->expr3
->ts
;
6900 else if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
6901 ts
= code
->ext
.alloc
.ts
;
6903 gfc_find_derived_vtab (ts
.u
.derived
);
6906 e
= gfc_expr_to_initialize (e
);
6908 else if (unlimited
&& !UNLIMITED_POLY (code
->expr3
))
6910 /* Again, make sure the vtab symbol is present when
6911 the module variables are generated. */
6912 gfc_typespec
*ts
= NULL
;
6914 ts
= &code
->expr3
->ts
;
6916 ts
= &code
->ext
.alloc
.ts
;
6920 if (ts
->type
== BT_CLASS
|| ts
->type
== BT_DERIVED
)
6921 gfc_find_derived_vtab (ts
->u
.derived
);
6923 gfc_find_intrinsic_vtab (ts
);
6926 e
= gfc_expr_to_initialize (e
);
6929 if (dimension
== 0 && codimension
== 0)
6932 /* Make sure the last reference node is an array specification. */
6934 if (!ref2
|| ref2
->type
!= REF_ARRAY
|| ref2
->u
.ar
.type
== AR_FULL
6935 || (dimension
&& ref2
->u
.ar
.dimen
== 0))
6937 gfc_error ("Array specification required in ALLOCATE statement "
6938 "at %L", &e
->where
);
6942 /* Make sure that the array section reference makes sense in the
6943 context of an ALLOCATE specification. */
6948 for (i
= ar
->dimen
; i
< ar
->dimen
+ ar
->codimen
; i
++)
6949 if (ar
->dimen_type
[i
] == DIMEN_THIS_IMAGE
)
6951 gfc_error ("Coarray specification required in ALLOCATE statement "
6952 "at %L", &e
->where
);
6956 for (i
= 0; i
< ar
->dimen
; i
++)
6958 if (ref2
->u
.ar
.type
== AR_ELEMENT
)
6961 switch (ar
->dimen_type
[i
])
6967 if (ar
->start
[i
] != NULL
6968 && ar
->end
[i
] != NULL
6969 && ar
->stride
[i
] == NULL
)
6972 /* Fall Through... */
6977 case DIMEN_THIS_IMAGE
:
6978 gfc_error ("Bad array specification in ALLOCATE statement at %L",
6984 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
6986 sym
= a
->expr
->symtree
->n
.sym
;
6988 /* TODO - check derived type components. */
6989 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
6992 if ((ar
->start
[i
] != NULL
6993 && gfc_find_sym_in_expr (sym
, ar
->start
[i
]))
6994 || (ar
->end
[i
] != NULL
6995 && gfc_find_sym_in_expr (sym
, ar
->end
[i
])))
6997 gfc_error ("'%s' must not appear in the array specification at "
6998 "%L in the same ALLOCATE statement where it is "
6999 "itself allocated", sym
->name
, &ar
->where
);
7005 for (i
= ar
->dimen
; i
< ar
->codimen
+ ar
->dimen
; i
++)
7007 if (ar
->dimen_type
[i
] == DIMEN_ELEMENT
7008 || ar
->dimen_type
[i
] == DIMEN_RANGE
)
7010 if (i
== (ar
->dimen
+ ar
->codimen
- 1))
7012 gfc_error ("Expected '*' in coindex specification in ALLOCATE "
7013 "statement at %L", &e
->where
);
7019 if (ar
->dimen_type
[i
] == DIMEN_STAR
&& i
== (ar
->dimen
+ ar
->codimen
- 1)
7020 && ar
->stride
[i
] == NULL
)
7023 gfc_error ("Bad coarray specification in ALLOCATE statement at %L",
7036 resolve_allocate_deallocate (gfc_code
*code
, const char *fcn
)
7038 gfc_expr
*stat
, *errmsg
, *pe
, *qe
;
7039 gfc_alloc
*a
, *p
, *q
;
7042 errmsg
= code
->expr2
;
7044 /* Check the stat variable. */
7047 gfc_check_vardef_context (stat
, false, false, false,
7048 _("STAT variable"));
7050 if ((stat
->ts
.type
!= BT_INTEGER
7051 && !(stat
->ref
&& (stat
->ref
->type
== REF_ARRAY
7052 || stat
->ref
->type
== REF_COMPONENT
)))
7054 gfc_error ("Stat-variable at %L must be a scalar INTEGER "
7055 "variable", &stat
->where
);
7057 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7058 if (p
->expr
->symtree
->n
.sym
->name
== stat
->symtree
->n
.sym
->name
)
7060 gfc_ref
*ref1
, *ref2
;
7063 for (ref1
= p
->expr
->ref
, ref2
= stat
->ref
; ref1
&& ref2
;
7064 ref1
= ref1
->next
, ref2
= ref2
->next
)
7066 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
7068 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
7077 gfc_error ("Stat-variable at %L shall not be %sd within "
7078 "the same %s statement", &stat
->where
, fcn
, fcn
);
7084 /* Check the errmsg variable. */
7088 gfc_warning ("ERRMSG at %L is useless without a STAT tag",
7091 gfc_check_vardef_context (errmsg
, false, false, false,
7092 _("ERRMSG variable"));
7094 if ((errmsg
->ts
.type
!= BT_CHARACTER
7096 && (errmsg
->ref
->type
== REF_ARRAY
7097 || errmsg
->ref
->type
== REF_COMPONENT
)))
7098 || errmsg
->rank
> 0 )
7099 gfc_error ("Errmsg-variable at %L must be a scalar CHARACTER "
7100 "variable", &errmsg
->where
);
7102 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7103 if (p
->expr
->symtree
->n
.sym
->name
== errmsg
->symtree
->n
.sym
->name
)
7105 gfc_ref
*ref1
, *ref2
;
7108 for (ref1
= p
->expr
->ref
, ref2
= errmsg
->ref
; ref1
&& ref2
;
7109 ref1
= ref1
->next
, ref2
= ref2
->next
)
7111 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
7113 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
7122 gfc_error ("Errmsg-variable at %L shall not be %sd within "
7123 "the same %s statement", &errmsg
->where
, fcn
, fcn
);
7129 /* Check that an allocate-object appears only once in the statement. */
7131 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7134 for (q
= p
->next
; q
; q
= q
->next
)
7137 if (pe
->symtree
->n
.sym
->name
== qe
->symtree
->n
.sym
->name
)
7139 /* This is a potential collision. */
7140 gfc_ref
*pr
= pe
->ref
;
7141 gfc_ref
*qr
= qe
->ref
;
7143 /* Follow the references until
7144 a) They start to differ, in which case there is no error;
7145 you can deallocate a%b and a%c in a single statement
7146 b) Both of them stop, which is an error
7147 c) One of them stops, which is also an error. */
7150 if (pr
== NULL
&& qr
== NULL
)
7152 gfc_error ("Allocate-object at %L also appears at %L",
7153 &pe
->where
, &qe
->where
);
7156 else if (pr
!= NULL
&& qr
== NULL
)
7158 gfc_error ("Allocate-object at %L is subobject of"
7159 " object at %L", &pe
->where
, &qe
->where
);
7162 else if (pr
== NULL
&& qr
!= NULL
)
7164 gfc_error ("Allocate-object at %L is subobject of"
7165 " object at %L", &qe
->where
, &pe
->where
);
7168 /* Here, pr != NULL && qr != NULL */
7169 gcc_assert(pr
->type
== qr
->type
);
7170 if (pr
->type
== REF_ARRAY
)
7172 /* Handle cases like allocate(v(3)%x(3), v(2)%x(3)),
7174 gcc_assert (qr
->type
== REF_ARRAY
);
7176 if (pr
->next
&& qr
->next
)
7179 gfc_array_ref
*par
= &(pr
->u
.ar
);
7180 gfc_array_ref
*qar
= &(qr
->u
.ar
);
7182 for (i
=0; i
<par
->dimen
; i
++)
7184 if ((par
->start
[i
] != NULL
7185 || qar
->start
[i
] != NULL
)
7186 && gfc_dep_compare_expr (par
->start
[i
],
7187 qar
->start
[i
]) != 0)
7194 if (pr
->u
.c
.component
->name
!= qr
->u
.c
.component
->name
)
7207 if (strcmp (fcn
, "ALLOCATE") == 0)
7209 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7210 resolve_allocate_expr (a
->expr
, code
);
7214 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7215 resolve_deallocate_expr (a
->expr
);
7220 /************ SELECT CASE resolution subroutines ************/
7222 /* Callback function for our mergesort variant. Determines interval
7223 overlaps for CASEs. Return <0 if op1 < op2, 0 for overlap, >0 for
7224 op1 > op2. Assumes we're not dealing with the default case.
7225 We have op1 = (:L), (K:L) or (K:) and op2 = (:N), (M:N) or (M:).
7226 There are nine situations to check. */
7229 compare_cases (const gfc_case
*op1
, const gfc_case
*op2
)
7233 if (op1
->low
== NULL
) /* op1 = (:L) */
7235 /* op2 = (:N), so overlap. */
7237 /* op2 = (M:) or (M:N), L < M */
7238 if (op2
->low
!= NULL
7239 && gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7242 else if (op1
->high
== NULL
) /* op1 = (K:) */
7244 /* op2 = (M:), so overlap. */
7246 /* op2 = (:N) or (M:N), K > N */
7247 if (op2
->high
!= NULL
7248 && gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7251 else /* op1 = (K:L) */
7253 if (op2
->low
== NULL
) /* op2 = (:N), K > N */
7254 retval
= (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7256 else if (op2
->high
== NULL
) /* op2 = (M:), L < M */
7257 retval
= (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7259 else /* op2 = (M:N) */
7263 if (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7266 else if (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7275 /* Merge-sort a double linked case list, detecting overlap in the
7276 process. LIST is the head of the double linked case list before it
7277 is sorted. Returns the head of the sorted list if we don't see any
7278 overlap, or NULL otherwise. */
7281 check_case_overlap (gfc_case
*list
)
7283 gfc_case
*p
, *q
, *e
, *tail
;
7284 int insize
, nmerges
, psize
, qsize
, cmp
, overlap_seen
;
7286 /* If the passed list was empty, return immediately. */
7293 /* Loop unconditionally. The only exit from this loop is a return
7294 statement, when we've finished sorting the case list. */
7301 /* Count the number of merges we do in this pass. */
7304 /* Loop while there exists a merge to be done. */
7309 /* Count this merge. */
7312 /* Cut the list in two pieces by stepping INSIZE places
7313 forward in the list, starting from P. */
7316 for (i
= 0; i
< insize
; i
++)
7325 /* Now we have two lists. Merge them! */
7326 while (psize
> 0 || (qsize
> 0 && q
!= NULL
))
7328 /* See from which the next case to merge comes from. */
7331 /* P is empty so the next case must come from Q. */
7336 else if (qsize
== 0 || q
== NULL
)
7345 cmp
= compare_cases (p
, q
);
7348 /* The whole case range for P is less than the
7356 /* The whole case range for Q is greater than
7357 the case range for P. */
7364 /* The cases overlap, or they are the same
7365 element in the list. Either way, we must
7366 issue an error and get the next case from P. */
7367 /* FIXME: Sort P and Q by line number. */
7368 gfc_error ("CASE label at %L overlaps with CASE "
7369 "label at %L", &p
->where
, &q
->where
);
7377 /* Add the next element to the merged list. */
7386 /* P has now stepped INSIZE places along, and so has Q. So
7387 they're the same. */
7392 /* If we have done only one merge or none at all, we've
7393 finished sorting the cases. */
7402 /* Otherwise repeat, merging lists twice the size. */
7408 /* Check to see if an expression is suitable for use in a CASE statement.
7409 Makes sure that all case expressions are scalar constants of the same
7410 type. Return false if anything is wrong. */
7413 validate_case_label_expr (gfc_expr
*e
, gfc_expr
*case_expr
)
7415 if (e
== NULL
) return true;
7417 if (e
->ts
.type
!= case_expr
->ts
.type
)
7419 gfc_error ("Expression in CASE statement at %L must be of type %s",
7420 &e
->where
, gfc_basic_typename (case_expr
->ts
.type
));
7424 /* C805 (R808) For a given case-construct, each case-value shall be of
7425 the same type as case-expr. For character type, length differences
7426 are allowed, but the kind type parameters shall be the same. */
7428 if (case_expr
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= case_expr
->ts
.kind
)
7430 gfc_error ("Expression in CASE statement at %L must be of kind %d",
7431 &e
->where
, case_expr
->ts
.kind
);
7435 /* Convert the case value kind to that of case expression kind,
7438 if (e
->ts
.kind
!= case_expr
->ts
.kind
)
7439 gfc_convert_type_warn (e
, &case_expr
->ts
, 2, 0);
7443 gfc_error ("Expression in CASE statement at %L must be scalar",
7452 /* Given a completely parsed select statement, we:
7454 - Validate all expressions and code within the SELECT.
7455 - Make sure that the selection expression is not of the wrong type.
7456 - Make sure that no case ranges overlap.
7457 - Eliminate unreachable cases and unreachable code resulting from
7458 removing case labels.
7460 The standard does allow unreachable cases, e.g. CASE (5:3). But
7461 they are a hassle for code generation, and to prevent that, we just
7462 cut them out here. This is not necessary for overlapping cases
7463 because they are illegal and we never even try to generate code.
7465 We have the additional caveat that a SELECT construct could have
7466 been a computed GOTO in the source code. Fortunately we can fairly
7467 easily work around that here: The case_expr for a "real" SELECT CASE
7468 is in code->expr1, but for a computed GOTO it is in code->expr2. All
7469 we have to do is make sure that the case_expr is a scalar integer
7473 resolve_select (gfc_code
*code
, bool select_type
)
7476 gfc_expr
*case_expr
;
7477 gfc_case
*cp
, *default_case
, *tail
, *head
;
7478 int seen_unreachable
;
7484 if (code
->expr1
== NULL
)
7486 /* This was actually a computed GOTO statement. */
7487 case_expr
= code
->expr2
;
7488 if (case_expr
->ts
.type
!= BT_INTEGER
|| case_expr
->rank
!= 0)
7489 gfc_error ("Selection expression in computed GOTO statement "
7490 "at %L must be a scalar integer expression",
7493 /* Further checking is not necessary because this SELECT was built
7494 by the compiler, so it should always be OK. Just move the
7495 case_expr from expr2 to expr so that we can handle computed
7496 GOTOs as normal SELECTs from here on. */
7497 code
->expr1
= code
->expr2
;
7502 case_expr
= code
->expr1
;
7503 type
= case_expr
->ts
.type
;
7506 if (type
!= BT_LOGICAL
&& type
!= BT_INTEGER
&& type
!= BT_CHARACTER
)
7508 gfc_error ("Argument of SELECT statement at %L cannot be %s",
7509 &case_expr
->where
, gfc_typename (&case_expr
->ts
));
7511 /* Punt. Going on here just produce more garbage error messages. */
7516 if (!select_type
&& case_expr
->rank
!= 0)
7518 gfc_error ("Argument of SELECT statement at %L must be a scalar "
7519 "expression", &case_expr
->where
);
7525 /* Raise a warning if an INTEGER case value exceeds the range of
7526 the case-expr. Later, all expressions will be promoted to the
7527 largest kind of all case-labels. */
7529 if (type
== BT_INTEGER
)
7530 for (body
= code
->block
; body
; body
= body
->block
)
7531 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7534 && gfc_check_integer_range (cp
->low
->value
.integer
,
7535 case_expr
->ts
.kind
) != ARITH_OK
)
7536 gfc_warning ("Expression in CASE statement at %L is "
7537 "not in the range of %s", &cp
->low
->where
,
7538 gfc_typename (&case_expr
->ts
));
7541 && cp
->low
!= cp
->high
7542 && gfc_check_integer_range (cp
->high
->value
.integer
,
7543 case_expr
->ts
.kind
) != ARITH_OK
)
7544 gfc_warning ("Expression in CASE statement at %L is "
7545 "not in the range of %s", &cp
->high
->where
,
7546 gfc_typename (&case_expr
->ts
));
7549 /* PR 19168 has a long discussion concerning a mismatch of the kinds
7550 of the SELECT CASE expression and its CASE values. Walk the lists
7551 of case values, and if we find a mismatch, promote case_expr to
7552 the appropriate kind. */
7554 if (type
== BT_LOGICAL
|| type
== BT_INTEGER
)
7556 for (body
= code
->block
; body
; body
= body
->block
)
7558 /* Walk the case label list. */
7559 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7561 /* Intercept the DEFAULT case. It does not have a kind. */
7562 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7565 /* Unreachable case ranges are discarded, so ignore. */
7566 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7567 && cp
->low
!= cp
->high
7568 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7572 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->low
))
7573 gfc_convert_type_warn (case_expr
, &cp
->low
->ts
, 2, 0);
7575 if (cp
->high
!= NULL
7576 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->high
))
7577 gfc_convert_type_warn (case_expr
, &cp
->high
->ts
, 2, 0);
7582 /* Assume there is no DEFAULT case. */
7583 default_case
= NULL
;
7588 for (body
= code
->block
; body
; body
= body
->block
)
7590 /* Assume the CASE list is OK, and all CASE labels can be matched. */
7592 seen_unreachable
= 0;
7594 /* Walk the case label list, making sure that all case labels
7596 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7598 /* Count the number of cases in the whole construct. */
7601 /* Intercept the DEFAULT case. */
7602 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7604 if (default_case
!= NULL
)
7606 gfc_error ("The DEFAULT CASE at %L cannot be followed "
7607 "by a second DEFAULT CASE at %L",
7608 &default_case
->where
, &cp
->where
);
7619 /* Deal with single value cases and case ranges. Errors are
7620 issued from the validation function. */
7621 if (!validate_case_label_expr (cp
->low
, case_expr
)
7622 || !validate_case_label_expr (cp
->high
, case_expr
))
7628 if (type
== BT_LOGICAL
7629 && ((cp
->low
== NULL
|| cp
->high
== NULL
)
7630 || cp
->low
!= cp
->high
))
7632 gfc_error ("Logical range in CASE statement at %L is not "
7633 "allowed", &cp
->low
->where
);
7638 if (type
== BT_LOGICAL
&& cp
->low
->expr_type
== EXPR_CONSTANT
)
7641 value
= cp
->low
->value
.logical
== 0 ? 2 : 1;
7642 if (value
& seen_logical
)
7644 gfc_error ("Constant logical value in CASE statement "
7645 "is repeated at %L",
7650 seen_logical
|= value
;
7653 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7654 && cp
->low
!= cp
->high
7655 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7657 if (gfc_option
.warn_surprising
)
7658 gfc_warning ("Range specification at %L can never "
7659 "be matched", &cp
->where
);
7661 cp
->unreachable
= 1;
7662 seen_unreachable
= 1;
7666 /* If the case range can be matched, it can also overlap with
7667 other cases. To make sure it does not, we put it in a
7668 double linked list here. We sort that with a merge sort
7669 later on to detect any overlapping cases. */
7673 head
->right
= head
->left
= NULL
;
7678 tail
->right
->left
= tail
;
7685 /* It there was a failure in the previous case label, give up
7686 for this case label list. Continue with the next block. */
7690 /* See if any case labels that are unreachable have been seen.
7691 If so, we eliminate them. This is a bit of a kludge because
7692 the case lists for a single case statement (label) is a
7693 single forward linked lists. */
7694 if (seen_unreachable
)
7696 /* Advance until the first case in the list is reachable. */
7697 while (body
->ext
.block
.case_list
!= NULL
7698 && body
->ext
.block
.case_list
->unreachable
)
7700 gfc_case
*n
= body
->ext
.block
.case_list
;
7701 body
->ext
.block
.case_list
= body
->ext
.block
.case_list
->next
;
7703 gfc_free_case_list (n
);
7706 /* Strip all other unreachable cases. */
7707 if (body
->ext
.block
.case_list
)
7709 for (cp
= body
->ext
.block
.case_list
; cp
->next
; cp
= cp
->next
)
7711 if (cp
->next
->unreachable
)
7713 gfc_case
*n
= cp
->next
;
7714 cp
->next
= cp
->next
->next
;
7716 gfc_free_case_list (n
);
7723 /* See if there were overlapping cases. If the check returns NULL,
7724 there was overlap. In that case we don't do anything. If head
7725 is non-NULL, we prepend the DEFAULT case. The sorted list can
7726 then used during code generation for SELECT CASE constructs with
7727 a case expression of a CHARACTER type. */
7730 head
= check_case_overlap (head
);
7732 /* Prepend the default_case if it is there. */
7733 if (head
!= NULL
&& default_case
)
7735 default_case
->left
= NULL
;
7736 default_case
->right
= head
;
7737 head
->left
= default_case
;
7741 /* Eliminate dead blocks that may be the result if we've seen
7742 unreachable case labels for a block. */
7743 for (body
= code
; body
&& body
->block
; body
= body
->block
)
7745 if (body
->block
->ext
.block
.case_list
== NULL
)
7747 /* Cut the unreachable block from the code chain. */
7748 gfc_code
*c
= body
->block
;
7749 body
->block
= c
->block
;
7751 /* Kill the dead block, but not the blocks below it. */
7753 gfc_free_statements (c
);
7757 /* More than two cases is legal but insane for logical selects.
7758 Issue a warning for it. */
7759 if (gfc_option
.warn_surprising
&& type
== BT_LOGICAL
7761 gfc_warning ("Logical SELECT CASE block at %L has more that two cases",
7766 /* Check if a derived type is extensible. */
7769 gfc_type_is_extensible (gfc_symbol
*sym
)
7771 return !(sym
->attr
.is_bind_c
|| sym
->attr
.sequence
7772 || (sym
->attr
.is_class
7773 && sym
->components
->ts
.u
.derived
->attr
.unlimited_polymorphic
));
7777 /* Resolve an associate-name: Resolve target and ensure the type-spec is
7778 correct as well as possibly the array-spec. */
7781 resolve_assoc_var (gfc_symbol
* sym
, bool resolve_target
)
7785 gcc_assert (sym
->assoc
);
7786 gcc_assert (sym
->attr
.flavor
== FL_VARIABLE
);
7788 /* If this is for SELECT TYPE, the target may not yet be set. In that
7789 case, return. Resolution will be called later manually again when
7791 target
= sym
->assoc
->target
;
7794 gcc_assert (!sym
->assoc
->dangling
);
7796 if (resolve_target
&& !gfc_resolve_expr (target
))
7799 /* For variable targets, we get some attributes from the target. */
7800 if (target
->expr_type
== EXPR_VARIABLE
)
7804 gcc_assert (target
->symtree
);
7805 tsym
= target
->symtree
->n
.sym
;
7807 sym
->attr
.asynchronous
= tsym
->attr
.asynchronous
;
7808 sym
->attr
.volatile_
= tsym
->attr
.volatile_
;
7810 sym
->attr
.target
= tsym
->attr
.target
7811 || gfc_expr_attr (target
).pointer
;
7814 /* Get type if this was not already set. Note that it can be
7815 some other type than the target in case this is a SELECT TYPE
7816 selector! So we must not update when the type is already there. */
7817 if (sym
->ts
.type
== BT_UNKNOWN
)
7818 sym
->ts
= target
->ts
;
7819 gcc_assert (sym
->ts
.type
!= BT_UNKNOWN
);
7821 /* See if this is a valid association-to-variable. */
7822 sym
->assoc
->variable
= (target
->expr_type
== EXPR_VARIABLE
7823 && !gfc_has_vector_subscript (target
));
7825 /* Finally resolve if this is an array or not. */
7826 if (sym
->attr
.dimension
&& target
->rank
== 0)
7828 gfc_error ("Associate-name '%s' at %L is used as array",
7829 sym
->name
, &sym
->declared_at
);
7830 sym
->attr
.dimension
= 0;
7834 /* We cannot deal with class selectors that need temporaries. */
7835 if (target
->ts
.type
== BT_CLASS
7836 && gfc_ref_needs_temporary_p (target
->ref
))
7838 gfc_error ("CLASS selector at %L needs a temporary which is not "
7839 "yet implemented", &target
->where
);
7843 if (target
->ts
.type
!= BT_CLASS
&& target
->rank
> 0)
7844 sym
->attr
.dimension
= 1;
7845 else if (target
->ts
.type
== BT_CLASS
)
7846 gfc_fix_class_refs (target
);
7848 /* The associate-name will have a correct type by now. Make absolutely
7849 sure that it has not picked up a dimension attribute. */
7850 if (sym
->ts
.type
== BT_CLASS
)
7851 sym
->attr
.dimension
= 0;
7853 if (sym
->attr
.dimension
)
7855 sym
->as
= gfc_get_array_spec ();
7856 sym
->as
->rank
= target
->rank
;
7857 sym
->as
->type
= AS_DEFERRED
;
7859 /* Target must not be coindexed, thus the associate-variable
7861 sym
->as
->corank
= 0;
7864 /* Mark this as an associate variable. */
7865 sym
->attr
.associate_var
= 1;
7867 /* If the target is a good class object, so is the associate variable. */
7868 if (sym
->ts
.type
== BT_CLASS
&& gfc_expr_attr (target
).class_ok
)
7869 sym
->attr
.class_ok
= 1;
7873 /* Resolve a SELECT TYPE statement. */
7876 resolve_select_type (gfc_code
*code
, gfc_namespace
*old_ns
)
7878 gfc_symbol
*selector_type
;
7879 gfc_code
*body
, *new_st
, *if_st
, *tail
;
7880 gfc_code
*class_is
= NULL
, *default_case
= NULL
;
7883 char name
[GFC_MAX_SYMBOL_LEN
];
7888 ns
= code
->ext
.block
.ns
;
7891 /* Check for F03:C813. */
7892 if (code
->expr1
->ts
.type
!= BT_CLASS
7893 && !(code
->expr2
&& code
->expr2
->ts
.type
== BT_CLASS
))
7895 gfc_error ("Selector shall be polymorphic in SELECT TYPE statement "
7896 "at %L", &code
->loc
);
7900 if (!code
->expr1
->symtree
->n
.sym
->attr
.class_ok
)
7905 if (code
->expr1
->symtree
->n
.sym
->attr
.untyped
)
7906 code
->expr1
->symtree
->n
.sym
->ts
= code
->expr2
->ts
;
7907 selector_type
= CLASS_DATA (code
->expr2
)->ts
.u
.derived
;
7909 /* F2008: C803 The selector expression must not be coindexed. */
7910 if (gfc_is_coindexed (code
->expr2
))
7912 gfc_error ("Selector at %L must not be coindexed",
7913 &code
->expr2
->where
);
7920 selector_type
= CLASS_DATA (code
->expr1
)->ts
.u
.derived
;
7922 if (gfc_is_coindexed (code
->expr1
))
7924 gfc_error ("Selector at %L must not be coindexed",
7925 &code
->expr1
->where
);
7930 /* Loop over TYPE IS / CLASS IS cases. */
7931 for (body
= code
->block
; body
; body
= body
->block
)
7933 c
= body
->ext
.block
.case_list
;
7935 /* Check F03:C815. */
7936 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
7937 && !selector_type
->attr
.unlimited_polymorphic
7938 && !gfc_type_is_extensible (c
->ts
.u
.derived
))
7940 gfc_error ("Derived type '%s' at %L must be extensible",
7941 c
->ts
.u
.derived
->name
, &c
->where
);
7946 /* Check F03:C816. */
7947 if (c
->ts
.type
!= BT_UNKNOWN
&& !selector_type
->attr
.unlimited_polymorphic
7948 && ((c
->ts
.type
!= BT_DERIVED
&& c
->ts
.type
!= BT_CLASS
)
7949 || !gfc_type_is_extension_of (selector_type
, c
->ts
.u
.derived
)))
7951 if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
7952 gfc_error ("Derived type '%s' at %L must be an extension of '%s'",
7953 c
->ts
.u
.derived
->name
, &c
->where
, selector_type
->name
);
7955 gfc_error ("Unexpected intrinsic type '%s' at %L",
7956 gfc_basic_typename (c
->ts
.type
), &c
->where
);
7961 /* Check F03:C814. */
7962 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.u
.cl
->length
!= NULL
)
7964 gfc_error ("The type-spec at %L shall specify that each length "
7965 "type parameter is assumed", &c
->where
);
7970 /* Intercept the DEFAULT case. */
7971 if (c
->ts
.type
== BT_UNKNOWN
)
7973 /* Check F03:C818. */
7976 gfc_error ("The DEFAULT CASE at %L cannot be followed "
7977 "by a second DEFAULT CASE at %L",
7978 &default_case
->ext
.block
.case_list
->where
, &c
->where
);
7983 default_case
= body
;
7990 /* Transform SELECT TYPE statement to BLOCK and associate selector to
7991 target if present. If there are any EXIT statements referring to the
7992 SELECT TYPE construct, this is no problem because the gfc_code
7993 reference stays the same and EXIT is equally possible from the BLOCK
7994 it is changed to. */
7995 code
->op
= EXEC_BLOCK
;
7998 gfc_association_list
* assoc
;
8000 assoc
= gfc_get_association_list ();
8001 assoc
->st
= code
->expr1
->symtree
;
8002 assoc
->target
= gfc_copy_expr (code
->expr2
);
8003 assoc
->target
->where
= code
->expr2
->where
;
8004 /* assoc->variable will be set by resolve_assoc_var. */
8006 code
->ext
.block
.assoc
= assoc
;
8007 code
->expr1
->symtree
->n
.sym
->assoc
= assoc
;
8009 resolve_assoc_var (code
->expr1
->symtree
->n
.sym
, false);
8012 code
->ext
.block
.assoc
= NULL
;
8014 /* Add EXEC_SELECT to switch on type. */
8015 new_st
= gfc_get_code ();
8016 new_st
->op
= code
->op
;
8017 new_st
->expr1
= code
->expr1
;
8018 new_st
->expr2
= code
->expr2
;
8019 new_st
->block
= code
->block
;
8020 code
->expr1
= code
->expr2
= NULL
;
8025 ns
->code
->next
= new_st
;
8027 code
->op
= EXEC_SELECT
;
8029 gfc_add_vptr_component (code
->expr1
);
8030 gfc_add_hash_component (code
->expr1
);
8032 /* Loop over TYPE IS / CLASS IS cases. */
8033 for (body
= code
->block
; body
; body
= body
->block
)
8035 c
= body
->ext
.block
.case_list
;
8037 if (c
->ts
.type
== BT_DERIVED
)
8038 c
->low
= c
->high
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
8039 c
->ts
.u
.derived
->hash_value
);
8040 else if (c
->ts
.type
!= BT_CLASS
&& c
->ts
.type
!= BT_UNKNOWN
)
8045 ivtab
= gfc_find_intrinsic_vtab (&c
->ts
);
8046 gcc_assert (ivtab
&& CLASS_DATA (ivtab
)->initializer
);
8047 e
= CLASS_DATA (ivtab
)->initializer
;
8048 c
->low
= c
->high
= gfc_copy_expr (e
);
8051 else if (c
->ts
.type
== BT_UNKNOWN
)
8054 /* Associate temporary to selector. This should only be done
8055 when this case is actually true, so build a new ASSOCIATE
8056 that does precisely this here (instead of using the
8059 if (c
->ts
.type
== BT_CLASS
)
8060 sprintf (name
, "__tmp_class_%s", c
->ts
.u
.derived
->name
);
8061 else if (c
->ts
.type
== BT_DERIVED
)
8062 sprintf (name
, "__tmp_type_%s", c
->ts
.u
.derived
->name
);
8063 else if (c
->ts
.type
== BT_CHARACTER
)
8065 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
8066 && c
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
8067 charlen
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
8068 sprintf (name
, "__tmp_%s_%d_%d", gfc_basic_typename (c
->ts
.type
),
8069 charlen
, c
->ts
.kind
);
8072 sprintf (name
, "__tmp_%s_%d", gfc_basic_typename (c
->ts
.type
),
8075 st
= gfc_find_symtree (ns
->sym_root
, name
);
8076 gcc_assert (st
->n
.sym
->assoc
);
8077 st
->n
.sym
->assoc
->target
= gfc_get_variable_expr (code
->expr1
->symtree
);
8078 st
->n
.sym
->assoc
->target
->where
= code
->expr1
->where
;
8079 if (c
->ts
.type
!= BT_CLASS
&& c
->ts
.type
!= BT_UNKNOWN
)
8080 gfc_add_data_component (st
->n
.sym
->assoc
->target
);
8082 new_st
= gfc_get_code ();
8083 new_st
->op
= EXEC_BLOCK
;
8084 new_st
->ext
.block
.ns
= gfc_build_block_ns (ns
);
8085 new_st
->ext
.block
.ns
->code
= body
->next
;
8086 body
->next
= new_st
;
8088 /* Chain in the new list only if it is marked as dangling. Otherwise
8089 there is a CASE label overlap and this is already used. Just ignore,
8090 the error is diagnosed elsewhere. */
8091 if (st
->n
.sym
->assoc
->dangling
)
8093 new_st
->ext
.block
.assoc
= st
->n
.sym
->assoc
;
8094 st
->n
.sym
->assoc
->dangling
= 0;
8097 resolve_assoc_var (st
->n
.sym
, false);
8100 /* Take out CLASS IS cases for separate treatment. */
8102 while (body
&& body
->block
)
8104 if (body
->block
->ext
.block
.case_list
->ts
.type
== BT_CLASS
)
8106 /* Add to class_is list. */
8107 if (class_is
== NULL
)
8109 class_is
= body
->block
;
8114 for (tail
= class_is
; tail
->block
; tail
= tail
->block
) ;
8115 tail
->block
= body
->block
;
8118 /* Remove from EXEC_SELECT list. */
8119 body
->block
= body
->block
->block
;
8132 /* Add a default case to hold the CLASS IS cases. */
8133 for (tail
= code
; tail
->block
; tail
= tail
->block
) ;
8134 tail
->block
= gfc_get_code ();
8136 tail
->op
= EXEC_SELECT_TYPE
;
8137 tail
->ext
.block
.case_list
= gfc_get_case ();
8138 tail
->ext
.block
.case_list
->ts
.type
= BT_UNKNOWN
;
8140 default_case
= tail
;
8143 /* More than one CLASS IS block? */
8144 if (class_is
->block
)
8148 /* Sort CLASS IS blocks by extension level. */
8152 for (c1
= &class_is
; (*c1
) && (*c1
)->block
; c1
= &((*c1
)->block
))
8155 /* F03:C817 (check for doubles). */
8156 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->hash_value
8157 == c2
->ext
.block
.case_list
->ts
.u
.derived
->hash_value
)
8159 gfc_error ("Double CLASS IS block in SELECT TYPE "
8161 &c2
->ext
.block
.case_list
->where
);
8164 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
8165 < c2
->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
)
8168 (*c1
)->block
= c2
->block
;
8178 /* Generate IF chain. */
8179 if_st
= gfc_get_code ();
8180 if_st
->op
= EXEC_IF
;
8182 for (body
= class_is
; body
; body
= body
->block
)
8184 new_st
->block
= gfc_get_code ();
8185 new_st
= new_st
->block
;
8186 new_st
->op
= EXEC_IF
;
8187 /* Set up IF condition: Call _gfortran_is_extension_of. */
8188 new_st
->expr1
= gfc_get_expr ();
8189 new_st
->expr1
->expr_type
= EXPR_FUNCTION
;
8190 new_st
->expr1
->ts
.type
= BT_LOGICAL
;
8191 new_st
->expr1
->ts
.kind
= 4;
8192 new_st
->expr1
->value
.function
.name
= gfc_get_string (PREFIX ("is_extension_of"));
8193 new_st
->expr1
->value
.function
.isym
= XCNEW (gfc_intrinsic_sym
);
8194 new_st
->expr1
->value
.function
.isym
->id
= GFC_ISYM_EXTENDS_TYPE_OF
;
8195 /* Set up arguments. */
8196 new_st
->expr1
->value
.function
.actual
= gfc_get_actual_arglist ();
8197 new_st
->expr1
->value
.function
.actual
->expr
= gfc_get_variable_expr (code
->expr1
->symtree
);
8198 new_st
->expr1
->value
.function
.actual
->expr
->where
= code
->loc
;
8199 gfc_add_vptr_component (new_st
->expr1
->value
.function
.actual
->expr
);
8200 vtab
= gfc_find_derived_vtab (body
->ext
.block
.case_list
->ts
.u
.derived
);
8201 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
8202 new_st
->expr1
->value
.function
.actual
->next
= gfc_get_actual_arglist ();
8203 new_st
->expr1
->value
.function
.actual
->next
->expr
= gfc_get_variable_expr (st
);
8204 new_st
->next
= body
->next
;
8206 if (default_case
->next
)
8208 new_st
->block
= gfc_get_code ();
8209 new_st
= new_st
->block
;
8210 new_st
->op
= EXEC_IF
;
8211 new_st
->next
= default_case
->next
;
8214 /* Replace CLASS DEFAULT code by the IF chain. */
8215 default_case
->next
= if_st
;
8218 /* Resolve the internal code. This can not be done earlier because
8219 it requires that the sym->assoc of selectors is set already. */
8220 gfc_current_ns
= ns
;
8221 gfc_resolve_blocks (code
->block
, gfc_current_ns
);
8222 gfc_current_ns
= old_ns
;
8224 resolve_select (code
, true);
8228 /* Resolve a transfer statement. This is making sure that:
8229 -- a derived type being transferred has only non-pointer components
8230 -- a derived type being transferred doesn't have private components, unless
8231 it's being transferred from the module where the type was defined
8232 -- we're not trying to transfer a whole assumed size array. */
8235 resolve_transfer (gfc_code
*code
)
8244 while (exp
!= NULL
&& exp
->expr_type
== EXPR_OP
8245 && exp
->value
.op
.op
== INTRINSIC_PARENTHESES
)
8246 exp
= exp
->value
.op
.op1
;
8248 if (exp
&& exp
->expr_type
== EXPR_NULL
&& exp
->ts
.type
== BT_UNKNOWN
)
8250 gfc_error ("NULL intrinsic at %L in data transfer statement requires "
8251 "MOLD=", &exp
->where
);
8255 if (exp
== NULL
|| (exp
->expr_type
!= EXPR_VARIABLE
8256 && exp
->expr_type
!= EXPR_FUNCTION
))
8259 /* If we are reading, the variable will be changed. Note that
8260 code->ext.dt may be NULL if the TRANSFER is related to
8261 an INQUIRE statement -- but in this case, we are not reading, either. */
8262 if (code
->ext
.dt
&& code
->ext
.dt
->dt_io_kind
->value
.iokind
== M_READ
8263 && !gfc_check_vardef_context (exp
, false, false, false,
8267 sym
= exp
->symtree
->n
.sym
;
8270 /* Go to actual component transferred. */
8271 for (ref
= exp
->ref
; ref
; ref
= ref
->next
)
8272 if (ref
->type
== REF_COMPONENT
)
8273 ts
= &ref
->u
.c
.component
->ts
;
8275 if (ts
->type
== BT_CLASS
)
8277 /* FIXME: Test for defined input/output. */
8278 gfc_error ("Data transfer element at %L cannot be polymorphic unless "
8279 "it is processed by a defined input/output procedure",
8284 if (ts
->type
== BT_DERIVED
)
8286 /* Check that transferred derived type doesn't contain POINTER
8288 if (ts
->u
.derived
->attr
.pointer_comp
)
8290 gfc_error ("Data transfer element at %L cannot have POINTER "
8291 "components unless it is processed by a defined "
8292 "input/output procedure", &code
->loc
);
8297 if (ts
->u
.derived
->attr
.proc_pointer_comp
)
8299 gfc_error ("Data transfer element at %L cannot have "
8300 "procedure pointer components", &code
->loc
);
8304 if (ts
->u
.derived
->attr
.alloc_comp
)
8306 gfc_error ("Data transfer element at %L cannot have ALLOCATABLE "
8307 "components unless it is processed by a defined "
8308 "input/output procedure", &code
->loc
);
8312 /* C_PTR and C_FUNPTR have private components which means they can not
8313 be printed. However, if -std=gnu and not -pedantic, allow
8314 the component to be printed to help debugging. */
8315 if (ts
->u
.derived
->ts
.f90_type
== BT_VOID
)
8317 if (!gfc_notify_std (GFC_STD_GNU
, "Data transfer element at %L "
8318 "cannot have PRIVATE components", &code
->loc
))
8321 else if (derived_inaccessible (ts
->u
.derived
))
8323 gfc_error ("Data transfer element at %L cannot have "
8324 "PRIVATE components",&code
->loc
);
8329 if (sym
->as
!= NULL
&& sym
->as
->type
== AS_ASSUMED_SIZE
&& exp
->ref
8330 && exp
->ref
->type
== REF_ARRAY
&& exp
->ref
->u
.ar
.type
== AR_FULL
)
8332 gfc_error ("Data transfer element at %L cannot be a full reference to "
8333 "an assumed-size array", &code
->loc
);
8339 /*********** Toplevel code resolution subroutines ***********/
8341 /* Find the set of labels that are reachable from this block. We also
8342 record the last statement in each block. */
8345 find_reachable_labels (gfc_code
*block
)
8352 cs_base
->reachable_labels
= bitmap_obstack_alloc (&labels_obstack
);
8354 /* Collect labels in this block. We don't keep those corresponding
8355 to END {IF|SELECT}, these are checked in resolve_branch by going
8356 up through the code_stack. */
8357 for (c
= block
; c
; c
= c
->next
)
8359 if (c
->here
&& c
->op
!= EXEC_END_NESTED_BLOCK
)
8360 bitmap_set_bit (cs_base
->reachable_labels
, c
->here
->value
);
8363 /* Merge with labels from parent block. */
8366 gcc_assert (cs_base
->prev
->reachable_labels
);
8367 bitmap_ior_into (cs_base
->reachable_labels
,
8368 cs_base
->prev
->reachable_labels
);
8374 resolve_lock_unlock (gfc_code
*code
)
8376 if (code
->expr1
->ts
.type
!= BT_DERIVED
8377 || code
->expr1
->expr_type
!= EXPR_VARIABLE
8378 || code
->expr1
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
8379 || code
->expr1
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_LOCK_TYPE
8380 || code
->expr1
->rank
!= 0
8381 || (!gfc_is_coarray (code
->expr1
) && !gfc_is_coindexed (code
->expr1
)))
8382 gfc_error ("Lock variable at %L must be a scalar of type LOCK_TYPE",
8383 &code
->expr1
->where
);
8387 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
8388 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
8389 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
8390 &code
->expr2
->where
);
8393 && !gfc_check_vardef_context (code
->expr2
, false, false, false,
8394 _("STAT variable")))
8399 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
8400 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
8401 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
8402 &code
->expr3
->where
);
8405 && !gfc_check_vardef_context (code
->expr3
, false, false, false,
8406 _("ERRMSG variable")))
8409 /* Check ACQUIRED_LOCK. */
8411 && (code
->expr4
->ts
.type
!= BT_LOGICAL
|| code
->expr4
->rank
!= 0
8412 || code
->expr4
->expr_type
!= EXPR_VARIABLE
))
8413 gfc_error ("ACQUIRED_LOCK= argument at %L must be a scalar LOGICAL "
8414 "variable", &code
->expr4
->where
);
8417 && !gfc_check_vardef_context (code
->expr4
, false, false, false,
8418 _("ACQUIRED_LOCK variable")))
8424 resolve_sync (gfc_code
*code
)
8426 /* Check imageset. The * case matches expr1 == NULL. */
8429 if (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
> 1)
8430 gfc_error ("Imageset argument at %L must be a scalar or rank-1 "
8431 "INTEGER expression", &code
->expr1
->where
);
8432 if (code
->expr1
->expr_type
== EXPR_CONSTANT
&& code
->expr1
->rank
== 0
8433 && mpz_cmp_si (code
->expr1
->value
.integer
, 1) < 0)
8434 gfc_error ("Imageset argument at %L must between 1 and num_images()",
8435 &code
->expr1
->where
);
8436 else if (code
->expr1
->expr_type
== EXPR_ARRAY
8437 && gfc_simplify_expr (code
->expr1
, 0))
8439 gfc_constructor
*cons
;
8440 cons
= gfc_constructor_first (code
->expr1
->value
.constructor
);
8441 for (; cons
; cons
= gfc_constructor_next (cons
))
8442 if (cons
->expr
->expr_type
== EXPR_CONSTANT
8443 && mpz_cmp_si (cons
->expr
->value
.integer
, 1) < 0)
8444 gfc_error ("Imageset argument at %L must between 1 and "
8445 "num_images()", &cons
->expr
->where
);
8451 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
8452 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
8453 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
8454 &code
->expr2
->where
);
8458 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
8459 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
8460 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
8461 &code
->expr3
->where
);
8465 /* Given a branch to a label, see if the branch is conforming.
8466 The code node describes where the branch is located. */
8469 resolve_branch (gfc_st_label
*label
, gfc_code
*code
)
8476 /* Step one: is this a valid branching target? */
8478 if (label
->defined
== ST_LABEL_UNKNOWN
)
8480 gfc_error ("Label %d referenced at %L is never defined", label
->value
,
8485 if (label
->defined
!= ST_LABEL_TARGET
&& label
->defined
!= ST_LABEL_DO_TARGET
)
8487 gfc_error ("Statement at %L is not a valid branch target statement "
8488 "for the branch statement at %L", &label
->where
, &code
->loc
);
8492 /* Step two: make sure this branch is not a branch to itself ;-) */
8494 if (code
->here
== label
)
8496 gfc_warning ("Branch at %L may result in an infinite loop", &code
->loc
);
8500 /* Step three: See if the label is in the same block as the
8501 branching statement. The hard work has been done by setting up
8502 the bitmap reachable_labels. */
8504 if (bitmap_bit_p (cs_base
->reachable_labels
, label
->value
))
8506 /* Check now whether there is a CRITICAL construct; if so, check
8507 whether the label is still visible outside of the CRITICAL block,
8508 which is invalid. */
8509 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
8511 if (stack
->current
->op
== EXEC_CRITICAL
8512 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
8513 gfc_error ("GOTO statement at %L leaves CRITICAL construct for "
8514 "label at %L", &code
->loc
, &label
->where
);
8515 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
8516 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
8517 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct "
8518 "for label at %L", &code
->loc
, &label
->where
);
8524 /* Step four: If we haven't found the label in the bitmap, it may
8525 still be the label of the END of the enclosing block, in which
8526 case we find it by going up the code_stack. */
8528 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
8530 if (stack
->current
->next
&& stack
->current
->next
->here
== label
)
8532 if (stack
->current
->op
== EXEC_CRITICAL
)
8534 /* Note: A label at END CRITICAL does not leave the CRITICAL
8535 construct as END CRITICAL is still part of it. */
8536 gfc_error ("GOTO statement at %L leaves CRITICAL construct for label"
8537 " at %L", &code
->loc
, &label
->where
);
8540 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
)
8542 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct for "
8543 "label at %L", &code
->loc
, &label
->where
);
8550 gcc_assert (stack
->current
->next
->op
== EXEC_END_NESTED_BLOCK
);
8554 /* The label is not in an enclosing block, so illegal. This was
8555 allowed in Fortran 66, so we allow it as extension. No
8556 further checks are necessary in this case. */
8557 gfc_notify_std (GFC_STD_LEGACY
, "Label at %L is not in the same block "
8558 "as the GOTO statement at %L", &label
->where
,
8564 /* Check whether EXPR1 has the same shape as EXPR2. */
8567 resolve_where_shape (gfc_expr
*expr1
, gfc_expr
*expr2
)
8569 mpz_t shape
[GFC_MAX_DIMENSIONS
];
8570 mpz_t shape2
[GFC_MAX_DIMENSIONS
];
8571 bool result
= false;
8574 /* Compare the rank. */
8575 if (expr1
->rank
!= expr2
->rank
)
8578 /* Compare the size of each dimension. */
8579 for (i
=0; i
<expr1
->rank
; i
++)
8581 if (!gfc_array_dimen_size (expr1
, i
, &shape
[i
]))
8584 if (!gfc_array_dimen_size (expr2
, i
, &shape2
[i
]))
8587 if (mpz_cmp (shape
[i
], shape2
[i
]))
8591 /* When either of the two expression is an assumed size array, we
8592 ignore the comparison of dimension sizes. */
8597 gfc_clear_shape (shape
, i
);
8598 gfc_clear_shape (shape2
, i
);
8603 /* Check whether a WHERE assignment target or a WHERE mask expression
8604 has the same shape as the outmost WHERE mask expression. */
8607 resolve_where (gfc_code
*code
, gfc_expr
*mask
)
8613 cblock
= code
->block
;
8615 /* Store the first WHERE mask-expr of the WHERE statement or construct.
8616 In case of nested WHERE, only the outmost one is stored. */
8617 if (mask
== NULL
) /* outmost WHERE */
8619 else /* inner WHERE */
8626 /* Check if the mask-expr has a consistent shape with the
8627 outmost WHERE mask-expr. */
8628 if (!resolve_where_shape (cblock
->expr1
, e
))
8629 gfc_error ("WHERE mask at %L has inconsistent shape",
8630 &cblock
->expr1
->where
);
8633 /* the assignment statement of a WHERE statement, or the first
8634 statement in where-body-construct of a WHERE construct */
8635 cnext
= cblock
->next
;
8640 /* WHERE assignment statement */
8643 /* Check shape consistent for WHERE assignment target. */
8644 if (e
&& !resolve_where_shape (cnext
->expr1
, e
))
8645 gfc_error ("WHERE assignment target at %L has "
8646 "inconsistent shape", &cnext
->expr1
->where
);
8650 case EXEC_ASSIGN_CALL
:
8651 resolve_call (cnext
);
8652 if (!cnext
->resolved_sym
->attr
.elemental
)
8653 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
8654 &cnext
->ext
.actual
->expr
->where
);
8657 /* WHERE or WHERE construct is part of a where-body-construct */
8659 resolve_where (cnext
, e
);
8663 gfc_error ("Unsupported statement inside WHERE at %L",
8666 /* the next statement within the same where-body-construct */
8667 cnext
= cnext
->next
;
8669 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
8670 cblock
= cblock
->block
;
8675 /* Resolve assignment in FORALL construct.
8676 NVAR is the number of FORALL index variables, and VAR_EXPR records the
8677 FORALL index variables. */
8680 gfc_resolve_assign_in_forall (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
8684 for (n
= 0; n
< nvar
; n
++)
8686 gfc_symbol
*forall_index
;
8688 forall_index
= var_expr
[n
]->symtree
->n
.sym
;
8690 /* Check whether the assignment target is one of the FORALL index
8692 if ((code
->expr1
->expr_type
== EXPR_VARIABLE
)
8693 && (code
->expr1
->symtree
->n
.sym
== forall_index
))
8694 gfc_error ("Assignment to a FORALL index variable at %L",
8695 &code
->expr1
->where
);
8698 /* If one of the FORALL index variables doesn't appear in the
8699 assignment variable, then there could be a many-to-one
8700 assignment. Emit a warning rather than an error because the
8701 mask could be resolving this problem. */
8702 if (!find_forall_index (code
->expr1
, forall_index
, 0))
8703 gfc_warning ("The FORALL with index '%s' is not used on the "
8704 "left side of the assignment at %L and so might "
8705 "cause multiple assignment to this object",
8706 var_expr
[n
]->symtree
->name
, &code
->expr1
->where
);
8712 /* Resolve WHERE statement in FORALL construct. */
8715 gfc_resolve_where_code_in_forall (gfc_code
*code
, int nvar
,
8716 gfc_expr
**var_expr
)
8721 cblock
= code
->block
;
8724 /* the assignment statement of a WHERE statement, or the first
8725 statement in where-body-construct of a WHERE construct */
8726 cnext
= cblock
->next
;
8731 /* WHERE assignment statement */
8733 gfc_resolve_assign_in_forall (cnext
, nvar
, var_expr
);
8736 /* WHERE operator assignment statement */
8737 case EXEC_ASSIGN_CALL
:
8738 resolve_call (cnext
);
8739 if (!cnext
->resolved_sym
->attr
.elemental
)
8740 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
8741 &cnext
->ext
.actual
->expr
->where
);
8744 /* WHERE or WHERE construct is part of a where-body-construct */
8746 gfc_resolve_where_code_in_forall (cnext
, nvar
, var_expr
);
8750 gfc_error ("Unsupported statement inside WHERE at %L",
8753 /* the next statement within the same where-body-construct */
8754 cnext
= cnext
->next
;
8756 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
8757 cblock
= cblock
->block
;
8762 /* Traverse the FORALL body to check whether the following errors exist:
8763 1. For assignment, check if a many-to-one assignment happens.
8764 2. For WHERE statement, check the WHERE body to see if there is any
8765 many-to-one assignment. */
8768 gfc_resolve_forall_body (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
8772 c
= code
->block
->next
;
8778 case EXEC_POINTER_ASSIGN
:
8779 gfc_resolve_assign_in_forall (c
, nvar
, var_expr
);
8782 case EXEC_ASSIGN_CALL
:
8786 /* Because the gfc_resolve_blocks() will handle the nested FORALL,
8787 there is no need to handle it here. */
8791 gfc_resolve_where_code_in_forall(c
, nvar
, var_expr
);
8796 /* The next statement in the FORALL body. */
8802 /* Counts the number of iterators needed inside a forall construct, including
8803 nested forall constructs. This is used to allocate the needed memory
8804 in gfc_resolve_forall. */
8807 gfc_count_forall_iterators (gfc_code
*code
)
8809 int max_iters
, sub_iters
, current_iters
;
8810 gfc_forall_iterator
*fa
;
8812 gcc_assert(code
->op
== EXEC_FORALL
);
8816 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
8819 code
= code
->block
->next
;
8823 if (code
->op
== EXEC_FORALL
)
8825 sub_iters
= gfc_count_forall_iterators (code
);
8826 if (sub_iters
> max_iters
)
8827 max_iters
= sub_iters
;
8832 return current_iters
+ max_iters
;
8836 /* Given a FORALL construct, first resolve the FORALL iterator, then call
8837 gfc_resolve_forall_body to resolve the FORALL body. */
8840 gfc_resolve_forall (gfc_code
*code
, gfc_namespace
*ns
, int forall_save
)
8842 static gfc_expr
**var_expr
;
8843 static int total_var
= 0;
8844 static int nvar
= 0;
8846 gfc_forall_iterator
*fa
;
8851 /* Start to resolve a FORALL construct */
8852 if (forall_save
== 0)
8854 /* Count the total number of FORALL index in the nested FORALL
8855 construct in order to allocate the VAR_EXPR with proper size. */
8856 total_var
= gfc_count_forall_iterators (code
);
8858 /* Allocate VAR_EXPR with NUMBER_OF_FORALL_INDEX elements. */
8859 var_expr
= XCNEWVEC (gfc_expr
*, total_var
);
8862 /* The information about FORALL iterator, including FORALL index start, end
8863 and stride. The FORALL index can not appear in start, end or stride. */
8864 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
8866 /* Check if any outer FORALL index name is the same as the current
8868 for (i
= 0; i
< nvar
; i
++)
8870 if (fa
->var
->symtree
->n
.sym
== var_expr
[i
]->symtree
->n
.sym
)
8872 gfc_error ("An outer FORALL construct already has an index "
8873 "with this name %L", &fa
->var
->where
);
8877 /* Record the current FORALL index. */
8878 var_expr
[nvar
] = gfc_copy_expr (fa
->var
);
8882 /* No memory leak. */
8883 gcc_assert (nvar
<= total_var
);
8886 /* Resolve the FORALL body. */
8887 gfc_resolve_forall_body (code
, nvar
, var_expr
);
8889 /* May call gfc_resolve_forall to resolve the inner FORALL loop. */
8890 gfc_resolve_blocks (code
->block
, ns
);
8894 /* Free only the VAR_EXPRs allocated in this frame. */
8895 for (i
= nvar
; i
< tmp
; i
++)
8896 gfc_free_expr (var_expr
[i
]);
8900 /* We are in the outermost FORALL construct. */
8901 gcc_assert (forall_save
== 0);
8903 /* VAR_EXPR is not needed any more. */
8910 /* Resolve a BLOCK construct statement. */
8913 resolve_block_construct (gfc_code
* code
)
8915 /* Resolve the BLOCK's namespace. */
8916 gfc_resolve (code
->ext
.block
.ns
);
8918 /* For an ASSOCIATE block, the associations (and their targets) are already
8919 resolved during resolve_symbol. */
8923 /* Resolve lists of blocks found in IF, SELECT CASE, WHERE, FORALL, GOTO and
8926 static void resolve_code (gfc_code
*, gfc_namespace
*);
8929 gfc_resolve_blocks (gfc_code
*b
, gfc_namespace
*ns
)
8933 for (; b
; b
= b
->block
)
8935 t
= gfc_resolve_expr (b
->expr1
);
8936 if (!gfc_resolve_expr (b
->expr2
))
8942 if (t
&& b
->expr1
!= NULL
8943 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
!= 0))
8944 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
8951 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
== 0))
8952 gfc_error ("WHERE/ELSEWHERE clause at %L requires a LOGICAL array",
8957 resolve_branch (b
->label1
, b
);
8961 resolve_block_construct (b
);
8965 case EXEC_SELECT_TYPE
:
8969 case EXEC_DO_CONCURRENT
:
8977 case EXEC_OMP_ATOMIC
:
8978 case EXEC_OMP_CRITICAL
:
8980 case EXEC_OMP_MASTER
:
8981 case EXEC_OMP_ORDERED
:
8982 case EXEC_OMP_PARALLEL
:
8983 case EXEC_OMP_PARALLEL_DO
:
8984 case EXEC_OMP_PARALLEL_SECTIONS
:
8985 case EXEC_OMP_PARALLEL_WORKSHARE
:
8986 case EXEC_OMP_SECTIONS
:
8987 case EXEC_OMP_SINGLE
:
8989 case EXEC_OMP_TASKWAIT
:
8990 case EXEC_OMP_TASKYIELD
:
8991 case EXEC_OMP_WORKSHARE
:
8995 gfc_internal_error ("gfc_resolve_blocks(): Bad block type");
8998 resolve_code (b
->next
, ns
);
9003 /* Does everything to resolve an ordinary assignment. Returns true
9004 if this is an interface assignment. */
9006 resolve_ordinary_assign (gfc_code
*code
, gfc_namespace
*ns
)
9016 if (gfc_extend_assign (code
, ns
))
9020 if (code
->op
== EXEC_ASSIGN_CALL
)
9022 lhs
= code
->ext
.actual
->expr
;
9023 rhsptr
= &code
->ext
.actual
->next
->expr
;
9027 gfc_actual_arglist
* args
;
9028 gfc_typebound_proc
* tbp
;
9030 gcc_assert (code
->op
== EXEC_COMPCALL
);
9032 args
= code
->expr1
->value
.compcall
.actual
;
9034 rhsptr
= &args
->next
->expr
;
9036 tbp
= code
->expr1
->value
.compcall
.tbp
;
9037 gcc_assert (!tbp
->is_generic
);
9040 /* Make a temporary rhs when there is a default initializer
9041 and rhs is the same symbol as the lhs. */
9042 if ((*rhsptr
)->expr_type
== EXPR_VARIABLE
9043 && (*rhsptr
)->symtree
->n
.sym
->ts
.type
== BT_DERIVED
9044 && gfc_has_default_initializer ((*rhsptr
)->symtree
->n
.sym
->ts
.u
.derived
)
9045 && (lhs
->symtree
->n
.sym
== (*rhsptr
)->symtree
->n
.sym
))
9046 *rhsptr
= gfc_get_parentheses (*rhsptr
);
9055 && !gfc_notify_std (GFC_STD_GNU
, "BOZ literal at %L outside "
9056 "a DATA statement and outside INT/REAL/DBLE/CMPLX",
9060 /* Handle the case of a BOZ literal on the RHS. */
9061 if (rhs
->is_boz
&& lhs
->ts
.type
!= BT_INTEGER
)
9064 if (gfc_option
.warn_surprising
)
9065 gfc_warning ("BOZ literal at %L is bitwise transferred "
9066 "non-integer symbol '%s'", &code
->loc
,
9067 lhs
->symtree
->n
.sym
->name
);
9069 if (!gfc_convert_boz (rhs
, &lhs
->ts
))
9071 if ((rc
= gfc_range_check (rhs
)) != ARITH_OK
)
9073 if (rc
== ARITH_UNDERFLOW
)
9074 gfc_error ("Arithmetic underflow of bit-wise transferred BOZ at %L"
9075 ". This check can be disabled with the option "
9076 "-fno-range-check", &rhs
->where
);
9077 else if (rc
== ARITH_OVERFLOW
)
9078 gfc_error ("Arithmetic overflow of bit-wise transferred BOZ at %L"
9079 ". This check can be disabled with the option "
9080 "-fno-range-check", &rhs
->where
);
9081 else if (rc
== ARITH_NAN
)
9082 gfc_error ("Arithmetic NaN of bit-wise transferred BOZ at %L"
9083 ". This check can be disabled with the option "
9084 "-fno-range-check", &rhs
->where
);
9089 if (lhs
->ts
.type
== BT_CHARACTER
9090 && gfc_option
.warn_character_truncation
)
9092 if (lhs
->ts
.u
.cl
!= NULL
9093 && lhs
->ts
.u
.cl
->length
!= NULL
9094 && lhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9095 llen
= mpz_get_si (lhs
->ts
.u
.cl
->length
->value
.integer
);
9097 if (rhs
->expr_type
== EXPR_CONSTANT
)
9098 rlen
= rhs
->value
.character
.length
;
9100 else if (rhs
->ts
.u
.cl
!= NULL
9101 && rhs
->ts
.u
.cl
->length
!= NULL
9102 && rhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9103 rlen
= mpz_get_si (rhs
->ts
.u
.cl
->length
->value
.integer
);
9105 if (rlen
&& llen
&& rlen
> llen
)
9106 gfc_warning_now ("CHARACTER expression will be truncated "
9107 "in assignment (%d/%d) at %L",
9108 llen
, rlen
, &code
->loc
);
9111 /* Ensure that a vector index expression for the lvalue is evaluated
9112 to a temporary if the lvalue symbol is referenced in it. */
9115 for (ref
= lhs
->ref
; ref
; ref
= ref
->next
)
9116 if (ref
->type
== REF_ARRAY
)
9118 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
9119 if (ref
->u
.ar
.dimen_type
[n
] == DIMEN_VECTOR
9120 && gfc_find_sym_in_expr (lhs
->symtree
->n
.sym
,
9121 ref
->u
.ar
.start
[n
]))
9123 = gfc_get_parentheses (ref
->u
.ar
.start
[n
]);
9127 if (gfc_pure (NULL
))
9129 if (lhs
->ts
.type
== BT_DERIVED
9130 && lhs
->expr_type
== EXPR_VARIABLE
9131 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9132 && rhs
->expr_type
== EXPR_VARIABLE
9133 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9134 || gfc_is_coindexed (rhs
)))
9137 if (gfc_is_coindexed (rhs
))
9138 gfc_error ("Coindexed expression at %L is assigned to "
9139 "a derived type variable with a POINTER "
9140 "component in a PURE procedure",
9143 gfc_error ("The impure variable at %L is assigned to "
9144 "a derived type variable with a POINTER "
9145 "component in a PURE procedure (12.6)",
9150 /* Fortran 2008, C1283. */
9151 if (gfc_is_coindexed (lhs
))
9153 gfc_error ("Assignment to coindexed variable at %L in a PURE "
9154 "procedure", &rhs
->where
);
9159 if (gfc_implicit_pure (NULL
))
9161 if (lhs
->expr_type
== EXPR_VARIABLE
9162 && lhs
->symtree
->n
.sym
!= gfc_current_ns
->proc_name
9163 && lhs
->symtree
->n
.sym
->ns
!= gfc_current_ns
)
9164 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
9166 if (lhs
->ts
.type
== BT_DERIVED
9167 && lhs
->expr_type
== EXPR_VARIABLE
9168 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9169 && rhs
->expr_type
== EXPR_VARIABLE
9170 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9171 || gfc_is_coindexed (rhs
)))
9172 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
9174 /* Fortran 2008, C1283. */
9175 if (gfc_is_coindexed (lhs
))
9176 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
9180 /* FIXME: Valid in Fortran 2008, unless the LHS is both polymorphic
9181 and coindexed; cf. F2008, 7.2.1.2 and PR 43366. */
9182 if (lhs
->ts
.type
== BT_CLASS
)
9184 gfc_error ("Variable must not be polymorphic in intrinsic assignment at "
9185 "%L - check that there is a matching specific subroutine "
9186 "for '=' operator", &lhs
->where
);
9190 /* F2008, Section 7.2.1.2. */
9191 if (gfc_is_coindexed (lhs
) && gfc_has_ultimate_allocatable (lhs
))
9193 gfc_error ("Coindexed variable must not be have an allocatable ultimate "
9194 "component in assignment at %L", &lhs
->where
);
9198 gfc_check_assign (lhs
, rhs
, 1);
9203 /* Add a component reference onto an expression. */
9206 add_comp_ref (gfc_expr
*e
, gfc_component
*c
)
9211 ref
= &((*ref
)->next
);
9212 *ref
= gfc_get_ref ();
9213 (*ref
)->type
= REF_COMPONENT
;
9214 (*ref
)->u
.c
.sym
= e
->ts
.u
.derived
;
9215 (*ref
)->u
.c
.component
= c
;
9218 /* Add a full array ref, as necessary. */
9221 gfc_add_full_array_ref (e
, c
->as
);
9222 e
->rank
= c
->as
->rank
;
9227 /* Build an assignment. Keep the argument 'op' for future use, so that
9228 pointer assignments can be made. */
9231 build_assignment (gfc_exec_op op
, gfc_expr
*expr1
, gfc_expr
*expr2
,
9232 gfc_component
*comp1
, gfc_component
*comp2
, locus loc
)
9234 gfc_code
*this_code
;
9236 this_code
= gfc_get_code ();
9238 this_code
->next
= NULL
;
9239 this_code
->expr1
= gfc_copy_expr (expr1
);
9240 this_code
->expr2
= gfc_copy_expr (expr2
);
9241 this_code
->loc
= loc
;
9244 add_comp_ref (this_code
->expr1
, comp1
);
9245 add_comp_ref (this_code
->expr2
, comp2
);
9252 /* Makes a temporary variable expression based on the characteristics of
9253 a given variable expression. */
9256 get_temp_from_expr (gfc_expr
*e
, gfc_namespace
*ns
)
9258 static int serial
= 0;
9259 char name
[GFC_MAX_SYMBOL_LEN
];
9262 gfc_array_ref
*aref
;
9265 sprintf (name
, GFC_PREFIX("DA%d"), serial
++);
9266 gfc_get_sym_tree (name
, ns
, &tmp
, false);
9267 gfc_add_type (tmp
->n
.sym
, &e
->ts
, NULL
);
9273 /* This function could be expanded to support other expression type
9274 but this is not needed here. */
9275 gcc_assert (e
->expr_type
== EXPR_VARIABLE
);
9277 /* Obtain the arrayspec for the temporary. */
9280 aref
= gfc_find_array_ref (e
);
9281 if (e
->expr_type
== EXPR_VARIABLE
9282 && e
->symtree
->n
.sym
->as
== aref
->as
)
9286 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
9287 if (ref
->type
== REF_COMPONENT
9288 && ref
->u
.c
.component
->as
== aref
->as
)
9296 /* Add the attributes and the arrayspec to the temporary. */
9297 tmp
->n
.sym
->attr
= gfc_expr_attr (e
);
9298 tmp
->n
.sym
->attr
.function
= 0;
9299 tmp
->n
.sym
->attr
.result
= 0;
9300 tmp
->n
.sym
->attr
.flavor
= FL_VARIABLE
;
9304 tmp
->n
.sym
->as
= gfc_copy_array_spec (as
);
9307 if (as
->type
== AS_DEFERRED
)
9308 tmp
->n
.sym
->attr
.allocatable
= 1;
9311 tmp
->n
.sym
->attr
.dimension
= 0;
9313 gfc_set_sym_referenced (tmp
->n
.sym
);
9314 gfc_commit_symbol (tmp
->n
.sym
);
9315 e
= gfc_lval_expr_from_sym (tmp
->n
.sym
);
9317 /* Should the lhs be a section, use its array ref for the
9318 temporary expression. */
9319 if (aref
&& aref
->type
!= AR_FULL
)
9321 gfc_free_ref_list (e
->ref
);
9322 e
->ref
= gfc_copy_ref (ref
);
9328 /* Add one line of code to the code chain, making sure that 'head' and
9329 'tail' are appropriately updated. */
9332 add_code_to_chain (gfc_code
**this_code
, gfc_code
**head
, gfc_code
**tail
)
9334 gcc_assert (this_code
);
9336 *head
= *tail
= *this_code
;
9338 *tail
= gfc_append_code (*tail
, *this_code
);
9343 /* Counts the potential number of part array references that would
9344 result from resolution of typebound defined assignments. */
9347 nonscalar_typebound_assign (gfc_symbol
*derived
, int depth
)
9350 int c_depth
= 0, t_depth
;
9352 for (c
= derived
->components
; c
; c
= c
->next
)
9354 if ((c
->ts
.type
!= BT_DERIVED
9356 || c
->attr
.allocatable
9357 || c
->attr
.proc_pointer_comp
9358 || c
->attr
.class_pointer
9359 || c
->attr
.proc_pointer
)
9360 && !c
->attr
.defined_assign_comp
)
9363 if (c
->as
&& c_depth
== 0)
9366 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
9367 t_depth
= nonscalar_typebound_assign (c
->ts
.u
.derived
,
9372 c_depth
= t_depth
> c_depth
? t_depth
: c_depth
;
9374 return depth
+ c_depth
;
9378 /* Implement 7.2.1.3 of the F08 standard:
9379 "An intrinsic assignment where the variable is of derived type is
9380 performed as if each component of the variable were assigned from the
9381 corresponding component of expr using pointer assignment (7.2.2) for
9382 each pointer component, defined assignment for each nonpointer
9383 nonallocatable component of a type that has a type-bound defined
9384 assignment consistent with the component, intrinsic assignment for
9385 each other nonpointer nonallocatable component, ..."
9387 The pointer assignments are taken care of by the intrinsic
9388 assignment of the structure itself. This function recursively adds
9389 defined assignments where required. The recursion is accomplished
9390 by calling resolve_code.
9392 When the lhs in a defined assignment has intent INOUT, we need a
9393 temporary for the lhs. In pseudo-code:
9395 ! Only call function lhs once.
9396 if (lhs is not a constant or an variable)
9399 ! Do the intrinsic assignment
9401 ! Now do the defined assignments
9402 do over components with typebound defined assignment [%cmp]
9403 #if one component's assignment procedure is INOUT
9405 #if expr2 non-variable
9411 t1%cmp {defined=} expr2%cmp
9417 expr1%cmp {defined=} expr2%cmp
9421 /* The temporary assignments have to be put on top of the additional
9422 code to avoid the result being changed by the intrinsic assignment.
9424 static int component_assignment_level
= 0;
9425 static gfc_code
*tmp_head
= NULL
, *tmp_tail
= NULL
;
9428 generate_component_assignments (gfc_code
**code
, gfc_namespace
*ns
)
9430 gfc_component
*comp1
, *comp2
;
9431 gfc_code
*this_code
= NULL
, *head
= NULL
, *tail
= NULL
;
9433 int error_count
, depth
;
9435 gfc_get_errors (NULL
, &error_count
);
9437 /* Filter out continuing processing after an error. */
9439 || (*code
)->expr1
->ts
.type
!= BT_DERIVED
9440 || (*code
)->expr2
->ts
.type
!= BT_DERIVED
)
9443 /* TODO: Handle more than one part array reference in assignments. */
9444 depth
= nonscalar_typebound_assign ((*code
)->expr1
->ts
.u
.derived
,
9445 (*code
)->expr1
->rank
? 1 : 0);
9448 gfc_warning ("TODO: type-bound defined assignment(s) at %L not "
9449 "done because multiple part array references would "
9450 "occur in intermediate expressions.", &(*code
)->loc
);
9454 component_assignment_level
++;
9456 /* Create a temporary so that functions get called only once. */
9457 if ((*code
)->expr2
->expr_type
!= EXPR_VARIABLE
9458 && (*code
)->expr2
->expr_type
!= EXPR_CONSTANT
)
9462 /* Assign the rhs to the temporary. */
9463 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
9464 this_code
= build_assignment (EXEC_ASSIGN
,
9465 tmp_expr
, (*code
)->expr2
,
9466 NULL
, NULL
, (*code
)->loc
);
9467 /* Add the code and substitute the rhs expression. */
9468 add_code_to_chain (&this_code
, &tmp_head
, &tmp_tail
);
9469 gfc_free_expr ((*code
)->expr2
);
9470 (*code
)->expr2
= tmp_expr
;
9473 /* Do the intrinsic assignment. This is not needed if the lhs is one
9474 of the temporaries generated here, since the intrinsic assignment
9475 to the final result already does this. */
9476 if ((*code
)->expr1
->symtree
->n
.sym
->name
[2] != '@')
9478 this_code
= build_assignment (EXEC_ASSIGN
,
9479 (*code
)->expr1
, (*code
)->expr2
,
9480 NULL
, NULL
, (*code
)->loc
);
9481 add_code_to_chain (&this_code
, &head
, &tail
);
9484 comp1
= (*code
)->expr1
->ts
.u
.derived
->components
;
9485 comp2
= (*code
)->expr2
->ts
.u
.derived
->components
;
9488 for (; comp1
; comp1
= comp1
->next
, comp2
= comp2
->next
)
9492 /* The intrinsic assignment does the right thing for pointers
9493 of all kinds and allocatable components. */
9494 if (comp1
->ts
.type
!= BT_DERIVED
9495 || comp1
->attr
.pointer
9496 || comp1
->attr
.allocatable
9497 || comp1
->attr
.proc_pointer_comp
9498 || comp1
->attr
.class_pointer
9499 || comp1
->attr
.proc_pointer
)
9502 /* Make an assigment for this component. */
9503 this_code
= build_assignment (EXEC_ASSIGN
,
9504 (*code
)->expr1
, (*code
)->expr2
,
9505 comp1
, comp2
, (*code
)->loc
);
9507 /* Convert the assignment if there is a defined assignment for
9508 this type. Otherwise, using the call from resolve_code,
9509 recurse into its components. */
9510 resolve_code (this_code
, ns
);
9512 if (this_code
->op
== EXEC_ASSIGN_CALL
)
9514 gfc_formal_arglist
*dummy_args
;
9516 /* Check that there is a typebound defined assignment. If not,
9517 then this must be a module defined assignment. We cannot
9518 use the defined_assign_comp attribute here because it must
9519 be this derived type that has the defined assignment and not
9521 if (!(comp1
->ts
.u
.derived
->f2k_derived
9522 && comp1
->ts
.u
.derived
->f2k_derived
9523 ->tb_op
[INTRINSIC_ASSIGN
]))
9525 gfc_free_statements (this_code
);
9530 /* If the first argument of the subroutine has intent INOUT
9531 a temporary must be generated and used instead. */
9532 rsym
= this_code
->resolved_sym
;
9533 dummy_args
= gfc_sym_get_dummy_args (rsym
);
9535 && dummy_args
->sym
->attr
.intent
== INTENT_INOUT
)
9537 gfc_code
*temp_code
;
9540 /* Build the temporary required for the assignment and put
9541 it at the head of the generated code. */
9544 t1
= get_temp_from_expr ((*code
)->expr1
, ns
);
9545 temp_code
= build_assignment (EXEC_ASSIGN
,
9547 NULL
, NULL
, (*code
)->loc
);
9548 add_code_to_chain (&temp_code
, &tmp_head
, &tmp_tail
);
9551 /* Replace the first actual arg with the component of the
9553 gfc_free_expr (this_code
->ext
.actual
->expr
);
9554 this_code
->ext
.actual
->expr
= gfc_copy_expr (t1
);
9555 add_comp_ref (this_code
->ext
.actual
->expr
, comp1
);
9558 else if (this_code
->op
== EXEC_ASSIGN
&& !this_code
->next
)
9560 /* Don't add intrinsic assignments since they are already
9561 effected by the intrinsic assignment of the structure. */
9562 gfc_free_statements (this_code
);
9567 add_code_to_chain (&this_code
, &head
, &tail
);
9571 /* Transfer the value to the final result. */
9572 this_code
= build_assignment (EXEC_ASSIGN
,
9574 comp1
, comp2
, (*code
)->loc
);
9575 add_code_to_chain (&this_code
, &head
, &tail
);
9579 /* This is probably not necessary. */
9582 gfc_free_statements (this_code
);
9586 /* Put the temporary assignments at the top of the generated code. */
9587 if (tmp_head
&& component_assignment_level
== 1)
9589 gfc_append_code (tmp_head
, head
);
9591 tmp_head
= tmp_tail
= NULL
;
9594 /* Now attach the remaining code chain to the input code. Step on
9595 to the end of the new code since resolution is complete. */
9596 gcc_assert ((*code
)->op
== EXEC_ASSIGN
);
9597 tail
->next
= (*code
)->next
;
9598 /* Overwrite 'code' because this would place the intrinsic assignment
9599 before the temporary for the lhs is created. */
9600 gfc_free_expr ((*code
)->expr1
);
9601 gfc_free_expr ((*code
)->expr2
);
9606 component_assignment_level
--;
9610 /* Given a block of code, recursively resolve everything pointed to by this
9614 resolve_code (gfc_code
*code
, gfc_namespace
*ns
)
9616 int omp_workshare_save
;
9617 int forall_save
, do_concurrent_save
;
9621 frame
.prev
= cs_base
;
9625 find_reachable_labels (code
);
9627 for (; code
; code
= code
->next
)
9629 frame
.current
= code
;
9630 forall_save
= forall_flag
;
9631 do_concurrent_save
= do_concurrent_flag
;
9633 if (code
->op
== EXEC_FORALL
)
9636 gfc_resolve_forall (code
, ns
, forall_save
);
9639 else if (code
->block
)
9641 omp_workshare_save
= -1;
9644 case EXEC_OMP_PARALLEL_WORKSHARE
:
9645 omp_workshare_save
= omp_workshare_flag
;
9646 omp_workshare_flag
= 1;
9647 gfc_resolve_omp_parallel_blocks (code
, ns
);
9649 case EXEC_OMP_PARALLEL
:
9650 case EXEC_OMP_PARALLEL_DO
:
9651 case EXEC_OMP_PARALLEL_SECTIONS
:
9653 omp_workshare_save
= omp_workshare_flag
;
9654 omp_workshare_flag
= 0;
9655 gfc_resolve_omp_parallel_blocks (code
, ns
);
9658 gfc_resolve_omp_do_blocks (code
, ns
);
9660 case EXEC_SELECT_TYPE
:
9661 /* Blocks are handled in resolve_select_type because we have
9662 to transform the SELECT TYPE into ASSOCIATE first. */
9664 case EXEC_DO_CONCURRENT
:
9665 do_concurrent_flag
= 1;
9666 gfc_resolve_blocks (code
->block
, ns
);
9667 do_concurrent_flag
= 2;
9669 case EXEC_OMP_WORKSHARE
:
9670 omp_workshare_save
= omp_workshare_flag
;
9671 omp_workshare_flag
= 1;
9674 gfc_resolve_blocks (code
->block
, ns
);
9678 if (omp_workshare_save
!= -1)
9679 omp_workshare_flag
= omp_workshare_save
;
9683 if (code
->op
!= EXEC_COMPCALL
&& code
->op
!= EXEC_CALL_PPC
)
9684 t
= gfc_resolve_expr (code
->expr1
);
9685 forall_flag
= forall_save
;
9686 do_concurrent_flag
= do_concurrent_save
;
9688 if (!gfc_resolve_expr (code
->expr2
))
9691 if (code
->op
== EXEC_ALLOCATE
9692 && !gfc_resolve_expr (code
->expr3
))
9698 case EXEC_END_BLOCK
:
9699 case EXEC_END_NESTED_BLOCK
:
9703 case EXEC_ERROR_STOP
:
9707 case EXEC_ASSIGN_CALL
:
9712 case EXEC_SYNC_IMAGES
:
9713 case EXEC_SYNC_MEMORY
:
9714 resolve_sync (code
);
9719 resolve_lock_unlock (code
);
9723 /* Keep track of which entry we are up to. */
9724 current_entry_id
= code
->ext
.entry
->id
;
9728 resolve_where (code
, NULL
);
9732 if (code
->expr1
!= NULL
)
9734 if (code
->expr1
->ts
.type
!= BT_INTEGER
)
9735 gfc_error ("ASSIGNED GOTO statement at %L requires an "
9736 "INTEGER variable", &code
->expr1
->where
);
9737 else if (code
->expr1
->symtree
->n
.sym
->attr
.assign
!= 1)
9738 gfc_error ("Variable '%s' has not been assigned a target "
9739 "label at %L", code
->expr1
->symtree
->n
.sym
->name
,
9740 &code
->expr1
->where
);
9743 resolve_branch (code
->label1
, code
);
9747 if (code
->expr1
!= NULL
9748 && (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
))
9749 gfc_error ("Alternate RETURN statement at %L requires a SCALAR-"
9750 "INTEGER return specifier", &code
->expr1
->where
);
9753 case EXEC_INIT_ASSIGN
:
9754 case EXEC_END_PROCEDURE
:
9761 if (!gfc_check_vardef_context (code
->expr1
, false, false, false,
9765 if (resolve_ordinary_assign (code
, ns
))
9767 if (code
->op
== EXEC_COMPCALL
)
9773 /* F03 7.4.1.3 for non-allocatable, non-pointer components. */
9774 if (code
->expr1
->ts
.type
== BT_DERIVED
9775 && code
->expr1
->ts
.u
.derived
->attr
.defined_assign_comp
)
9776 generate_component_assignments (&code
, ns
);
9780 case EXEC_LABEL_ASSIGN
:
9781 if (code
->label1
->defined
== ST_LABEL_UNKNOWN
)
9782 gfc_error ("Label %d referenced at %L is never defined",
9783 code
->label1
->value
, &code
->label1
->where
);
9785 && (code
->expr1
->expr_type
!= EXPR_VARIABLE
9786 || code
->expr1
->symtree
->n
.sym
->ts
.type
!= BT_INTEGER
9787 || code
->expr1
->symtree
->n
.sym
->ts
.kind
9788 != gfc_default_integer_kind
9789 || code
->expr1
->symtree
->n
.sym
->as
!= NULL
))
9790 gfc_error ("ASSIGN statement at %L requires a scalar "
9791 "default INTEGER variable", &code
->expr1
->where
);
9794 case EXEC_POINTER_ASSIGN
:
9801 /* This is both a variable definition and pointer assignment
9802 context, so check both of them. For rank remapping, a final
9803 array ref may be present on the LHS and fool gfc_expr_attr
9804 used in gfc_check_vardef_context. Remove it. */
9805 e
= remove_last_array_ref (code
->expr1
);
9806 t
= gfc_check_vardef_context (e
, true, false, false,
9807 _("pointer assignment"));
9809 t
= gfc_check_vardef_context (e
, false, false, false,
9810 _("pointer assignment"));
9815 gfc_check_pointer_assign (code
->expr1
, code
->expr2
);
9819 case EXEC_ARITHMETIC_IF
:
9821 && code
->expr1
->ts
.type
!= BT_INTEGER
9822 && code
->expr1
->ts
.type
!= BT_REAL
)
9823 gfc_error ("Arithmetic IF statement at %L requires a numeric "
9824 "expression", &code
->expr1
->where
);
9826 resolve_branch (code
->label1
, code
);
9827 resolve_branch (code
->label2
, code
);
9828 resolve_branch (code
->label3
, code
);
9832 if (t
&& code
->expr1
!= NULL
9833 && (code
->expr1
->ts
.type
!= BT_LOGICAL
9834 || code
->expr1
->rank
!= 0))
9835 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
9836 &code
->expr1
->where
);
9841 resolve_call (code
);
9846 resolve_typebound_subroutine (code
);
9850 resolve_ppc_call (code
);
9854 /* Select is complicated. Also, a SELECT construct could be
9855 a transformed computed GOTO. */
9856 resolve_select (code
, false);
9859 case EXEC_SELECT_TYPE
:
9860 resolve_select_type (code
, ns
);
9864 resolve_block_construct (code
);
9868 if (code
->ext
.iterator
!= NULL
)
9870 gfc_iterator
*iter
= code
->ext
.iterator
;
9871 if (gfc_resolve_iterator (iter
, true, false))
9872 gfc_resolve_do_iterator (code
, iter
->var
->symtree
->n
.sym
);
9877 if (code
->expr1
== NULL
)
9878 gfc_internal_error ("resolve_code(): No expression on DO WHILE");
9880 && (code
->expr1
->rank
!= 0
9881 || code
->expr1
->ts
.type
!= BT_LOGICAL
))
9882 gfc_error ("Exit condition of DO WHILE loop at %L must be "
9883 "a scalar LOGICAL expression", &code
->expr1
->where
);
9888 resolve_allocate_deallocate (code
, "ALLOCATE");
9892 case EXEC_DEALLOCATE
:
9894 resolve_allocate_deallocate (code
, "DEALLOCATE");
9899 if (!gfc_resolve_open (code
->ext
.open
))
9902 resolve_branch (code
->ext
.open
->err
, code
);
9906 if (!gfc_resolve_close (code
->ext
.close
))
9909 resolve_branch (code
->ext
.close
->err
, code
);
9912 case EXEC_BACKSPACE
:
9916 if (!gfc_resolve_filepos (code
->ext
.filepos
))
9919 resolve_branch (code
->ext
.filepos
->err
, code
);
9923 if (!gfc_resolve_inquire (code
->ext
.inquire
))
9926 resolve_branch (code
->ext
.inquire
->err
, code
);
9930 gcc_assert (code
->ext
.inquire
!= NULL
);
9931 if (!gfc_resolve_inquire (code
->ext
.inquire
))
9934 resolve_branch (code
->ext
.inquire
->err
, code
);
9938 if (!gfc_resolve_wait (code
->ext
.wait
))
9941 resolve_branch (code
->ext
.wait
->err
, code
);
9942 resolve_branch (code
->ext
.wait
->end
, code
);
9943 resolve_branch (code
->ext
.wait
->eor
, code
);
9948 if (!gfc_resolve_dt (code
->ext
.dt
, &code
->loc
))
9951 resolve_branch (code
->ext
.dt
->err
, code
);
9952 resolve_branch (code
->ext
.dt
->end
, code
);
9953 resolve_branch (code
->ext
.dt
->eor
, code
);
9957 resolve_transfer (code
);
9960 case EXEC_DO_CONCURRENT
:
9962 resolve_forall_iterators (code
->ext
.forall_iterator
);
9964 if (code
->expr1
!= NULL
9965 && (code
->expr1
->ts
.type
!= BT_LOGICAL
|| code
->expr1
->rank
))
9966 gfc_error ("FORALL mask clause at %L requires a scalar LOGICAL "
9967 "expression", &code
->expr1
->where
);
9970 case EXEC_OMP_ATOMIC
:
9971 case EXEC_OMP_BARRIER
:
9972 case EXEC_OMP_CRITICAL
:
9973 case EXEC_OMP_FLUSH
:
9975 case EXEC_OMP_MASTER
:
9976 case EXEC_OMP_ORDERED
:
9977 case EXEC_OMP_SECTIONS
:
9978 case EXEC_OMP_SINGLE
:
9979 case EXEC_OMP_TASKWAIT
:
9980 case EXEC_OMP_TASKYIELD
:
9981 case EXEC_OMP_WORKSHARE
:
9982 gfc_resolve_omp_directive (code
, ns
);
9985 case EXEC_OMP_PARALLEL
:
9986 case EXEC_OMP_PARALLEL_DO
:
9987 case EXEC_OMP_PARALLEL_SECTIONS
:
9988 case EXEC_OMP_PARALLEL_WORKSHARE
:
9990 omp_workshare_save
= omp_workshare_flag
;
9991 omp_workshare_flag
= 0;
9992 gfc_resolve_omp_directive (code
, ns
);
9993 omp_workshare_flag
= omp_workshare_save
;
9997 gfc_internal_error ("resolve_code(): Bad statement code");
10001 cs_base
= frame
.prev
;
10005 /* Resolve initial values and make sure they are compatible with
10009 resolve_values (gfc_symbol
*sym
)
10013 if (sym
->value
== NULL
)
10016 if (sym
->value
->expr_type
== EXPR_STRUCTURE
)
10017 t
= resolve_structure_cons (sym
->value
, 1);
10019 t
= gfc_resolve_expr (sym
->value
);
10024 gfc_check_assign_symbol (sym
, NULL
, sym
->value
);
10028 /* Verify any BIND(C) derived types in the namespace so we can report errors
10029 for them once, rather than for each variable declared of that type. */
10032 resolve_bind_c_derived_types (gfc_symbol
*derived_sym
)
10034 if (derived_sym
!= NULL
&& derived_sym
->attr
.flavor
== FL_DERIVED
10035 && derived_sym
->attr
.is_bind_c
== 1)
10036 verify_bind_c_derived_type (derived_sym
);
10042 /* Verify that any binding labels used in a given namespace do not collide
10043 with the names or binding labels of any global symbols. Multiple INTERFACE
10044 for the same procedure are permitted. */
10047 gfc_verify_binding_labels (gfc_symbol
*sym
)
10050 const char *module
;
10052 if (!sym
|| !sym
->attr
.is_bind_c
|| sym
->attr
.is_iso_c
10053 || sym
->attr
.flavor
== FL_DERIVED
|| !sym
->binding_label
)
10056 gsym
= gfc_find_gsymbol (gfc_gsym_root
, sym
->binding_label
);
10059 module
= sym
->module
;
10060 else if (sym
->ns
&& sym
->ns
->proc_name
10061 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
10062 module
= sym
->ns
->proc_name
->name
;
10063 else if (sym
->ns
&& sym
->ns
->parent
10064 && sym
->ns
&& sym
->ns
->parent
->proc_name
10065 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
10066 module
= sym
->ns
->parent
->proc_name
->name
;
10072 && (gsym
->type
== GSYM_FUNCTION
|| gsym
->type
== GSYM_SUBROUTINE
)))
10075 gsym
= gfc_get_gsymbol (sym
->binding_label
);
10076 gsym
->where
= sym
->declared_at
;
10077 gsym
->sym_name
= sym
->name
;
10078 gsym
->binding_label
= sym
->binding_label
;
10079 gsym
->binding_label
= sym
->binding_label
;
10080 gsym
->ns
= sym
->ns
;
10081 gsym
->mod_name
= module
;
10082 if (sym
->attr
.function
)
10083 gsym
->type
= GSYM_FUNCTION
;
10084 else if (sym
->attr
.subroutine
)
10085 gsym
->type
= GSYM_SUBROUTINE
;
10086 /* Mark as variable/procedure as defined, unless its an INTERFACE. */
10087 gsym
->defined
= sym
->attr
.if_source
!= IFSRC_IFBODY
;
10091 if (sym
->attr
.flavor
== FL_VARIABLE
&& gsym
->type
!= GSYM_UNKNOWN
)
10093 gfc_error ("Variable %s with binding label %s at %L uses the same global "
10094 "identifier as entity at %L", sym
->name
,
10095 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
10096 /* Clear the binding label to prevent checking multiple times. */
10097 sym
->binding_label
= NULL
;
10100 else if (sym
->attr
.flavor
== FL_VARIABLE
10101 && (strcmp (module
, gsym
->mod_name
) != 0
10102 || strcmp (sym
->name
, gsym
->sym_name
) != 0))
10104 /* This can only happen if the variable is defined in a module - if it
10105 isn't the same module, reject it. */
10106 gfc_error ("Variable %s from module %s with binding label %s at %L uses "
10107 "the same global identifier as entity at %L from module %s",
10108 sym
->name
, module
, sym
->binding_label
,
10109 &sym
->declared_at
, &gsym
->where
, gsym
->mod_name
);
10110 sym
->binding_label
= NULL
;
10112 else if ((sym
->attr
.function
|| sym
->attr
.subroutine
)
10113 && ((gsym
->type
!= GSYM_SUBROUTINE
&& gsym
->type
!= GSYM_FUNCTION
)
10114 || (gsym
->defined
&& sym
->attr
.if_source
!= IFSRC_IFBODY
))
10115 && sym
!= gsym
->ns
->proc_name
10116 && (strcmp (gsym
->sym_name
, sym
->name
) != 0
10117 || module
!= gsym
->mod_name
10118 || (module
&& strcmp (module
, gsym
->mod_name
) != 0)))
10120 /* Print an error if the procdure is defined multiple times; we have to
10121 exclude references to the same procedure via module association or
10122 multiple checks for the same procedure. */
10123 gfc_error ("Procedure %s with binding label %s at %L uses the same "
10124 "global identifier as entity at %L", sym
->name
,
10125 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
10126 sym
->binding_label
= NULL
;
10131 /* Resolve an index expression. */
10134 resolve_index_expr (gfc_expr
*e
)
10136 if (!gfc_resolve_expr (e
))
10139 if (!gfc_simplify_expr (e
, 0))
10142 if (!gfc_specification_expr (e
))
10149 /* Resolve a charlen structure. */
10152 resolve_charlen (gfc_charlen
*cl
)
10155 bool saved_specification_expr
;
10161 saved_specification_expr
= specification_expr
;
10162 specification_expr
= true;
10164 if (cl
->length_from_typespec
)
10166 if (!gfc_resolve_expr (cl
->length
))
10168 specification_expr
= saved_specification_expr
;
10172 if (!gfc_simplify_expr (cl
->length
, 0))
10174 specification_expr
= saved_specification_expr
;
10181 if (!resolve_index_expr (cl
->length
))
10183 specification_expr
= saved_specification_expr
;
10188 /* "If the character length parameter value evaluates to a negative
10189 value, the length of character entities declared is zero." */
10190 if (cl
->length
&& !gfc_extract_int (cl
->length
, &i
) && i
< 0)
10192 if (gfc_option
.warn_surprising
)
10193 gfc_warning_now ("CHARACTER variable at %L has negative length %d,"
10194 " the length has been set to zero",
10195 &cl
->length
->where
, i
);
10196 gfc_replace_expr (cl
->length
,
10197 gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 0));
10200 /* Check that the character length is not too large. */
10201 k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
10202 if (cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
10203 && cl
->length
->ts
.type
== BT_INTEGER
10204 && mpz_cmp (cl
->length
->value
.integer
, gfc_integer_kinds
[k
].huge
) > 0)
10206 gfc_error ("String length at %L is too large", &cl
->length
->where
);
10207 specification_expr
= saved_specification_expr
;
10211 specification_expr
= saved_specification_expr
;
10216 /* Test for non-constant shape arrays. */
10219 is_non_constant_shape_array (gfc_symbol
*sym
)
10225 not_constant
= false;
10226 if (sym
->as
!= NULL
)
10228 /* Unfortunately, !gfc_is_compile_time_shape hits a legal case that
10229 has not been simplified; parameter array references. Do the
10230 simplification now. */
10231 for (i
= 0; i
< sym
->as
->rank
+ sym
->as
->corank
; i
++)
10233 e
= sym
->as
->lower
[i
];
10234 if (e
&& (!resolve_index_expr(e
)
10235 || !gfc_is_constant_expr (e
)))
10236 not_constant
= true;
10237 e
= sym
->as
->upper
[i
];
10238 if (e
&& (!resolve_index_expr(e
)
10239 || !gfc_is_constant_expr (e
)))
10240 not_constant
= true;
10243 return not_constant
;
10246 /* Given a symbol and an initialization expression, add code to initialize
10247 the symbol to the function entry. */
10249 build_init_assign (gfc_symbol
*sym
, gfc_expr
*init
)
10253 gfc_namespace
*ns
= sym
->ns
;
10255 /* Search for the function namespace if this is a contained
10256 function without an explicit result. */
10257 if (sym
->attr
.function
&& sym
== sym
->result
10258 && sym
->name
!= sym
->ns
->proc_name
->name
)
10260 ns
= ns
->contained
;
10261 for (;ns
; ns
= ns
->sibling
)
10262 if (strcmp (ns
->proc_name
->name
, sym
->name
) == 0)
10268 gfc_free_expr (init
);
10272 /* Build an l-value expression for the result. */
10273 lval
= gfc_lval_expr_from_sym (sym
);
10275 /* Add the code at scope entry. */
10276 init_st
= gfc_get_code ();
10277 init_st
->next
= ns
->code
;
10278 ns
->code
= init_st
;
10280 /* Assign the default initializer to the l-value. */
10281 init_st
->loc
= sym
->declared_at
;
10282 init_st
->op
= EXEC_INIT_ASSIGN
;
10283 init_st
->expr1
= lval
;
10284 init_st
->expr2
= init
;
10287 /* Assign the default initializer to a derived type variable or result. */
10290 apply_default_init (gfc_symbol
*sym
)
10292 gfc_expr
*init
= NULL
;
10294 if (sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
10297 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
)
10298 init
= gfc_default_initializer (&sym
->ts
);
10300 if (init
== NULL
&& sym
->ts
.type
!= BT_CLASS
)
10303 build_init_assign (sym
, init
);
10304 sym
->attr
.referenced
= 1;
10307 /* Build an initializer for a local integer, real, complex, logical, or
10308 character variable, based on the command line flags finit-local-zero,
10309 finit-integer=, finit-real=, finit-logical=, and finit-runtime. Returns
10310 null if the symbol should not have a default initialization. */
10312 build_default_init_expr (gfc_symbol
*sym
)
10315 gfc_expr
*init_expr
;
10318 /* These symbols should never have a default initialization. */
10319 if (sym
->attr
.allocatable
10320 || sym
->attr
.external
10322 || sym
->attr
.pointer
10323 || sym
->attr
.in_equivalence
10324 || sym
->attr
.in_common
10327 || sym
->attr
.cray_pointee
10328 || sym
->attr
.cray_pointer
10332 /* Now we'll try to build an initializer expression. */
10333 init_expr
= gfc_get_constant_expr (sym
->ts
.type
, sym
->ts
.kind
,
10334 &sym
->declared_at
);
10336 /* We will only initialize integers, reals, complex, logicals, and
10337 characters, and only if the corresponding command-line flags
10338 were set. Otherwise, we free init_expr and return null. */
10339 switch (sym
->ts
.type
)
10342 if (gfc_option
.flag_init_integer
!= GFC_INIT_INTEGER_OFF
)
10343 mpz_set_si (init_expr
->value
.integer
,
10344 gfc_option
.flag_init_integer_value
);
10347 gfc_free_expr (init_expr
);
10353 switch (gfc_option
.flag_init_real
)
10355 case GFC_INIT_REAL_SNAN
:
10356 init_expr
->is_snan
= 1;
10357 /* Fall through. */
10358 case GFC_INIT_REAL_NAN
:
10359 mpfr_set_nan (init_expr
->value
.real
);
10362 case GFC_INIT_REAL_INF
:
10363 mpfr_set_inf (init_expr
->value
.real
, 1);
10366 case GFC_INIT_REAL_NEG_INF
:
10367 mpfr_set_inf (init_expr
->value
.real
, -1);
10370 case GFC_INIT_REAL_ZERO
:
10371 mpfr_set_ui (init_expr
->value
.real
, 0.0, GFC_RND_MODE
);
10375 gfc_free_expr (init_expr
);
10382 switch (gfc_option
.flag_init_real
)
10384 case GFC_INIT_REAL_SNAN
:
10385 init_expr
->is_snan
= 1;
10386 /* Fall through. */
10387 case GFC_INIT_REAL_NAN
:
10388 mpfr_set_nan (mpc_realref (init_expr
->value
.complex));
10389 mpfr_set_nan (mpc_imagref (init_expr
->value
.complex));
10392 case GFC_INIT_REAL_INF
:
10393 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), 1);
10394 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), 1);
10397 case GFC_INIT_REAL_NEG_INF
:
10398 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), -1);
10399 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), -1);
10402 case GFC_INIT_REAL_ZERO
:
10403 mpc_set_ui (init_expr
->value
.complex, 0, GFC_MPC_RND_MODE
);
10407 gfc_free_expr (init_expr
);
10414 if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_FALSE
)
10415 init_expr
->value
.logical
= 0;
10416 else if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_TRUE
)
10417 init_expr
->value
.logical
= 1;
10420 gfc_free_expr (init_expr
);
10426 /* For characters, the length must be constant in order to
10427 create a default initializer. */
10428 if (gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
10429 && sym
->ts
.u
.cl
->length
10430 && sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
10432 char_len
= mpz_get_si (sym
->ts
.u
.cl
->length
->value
.integer
);
10433 init_expr
->value
.character
.length
= char_len
;
10434 init_expr
->value
.character
.string
= gfc_get_wide_string (char_len
+1);
10435 for (i
= 0; i
< char_len
; i
++)
10436 init_expr
->value
.character
.string
[i
]
10437 = (unsigned char) gfc_option
.flag_init_character_value
;
10441 gfc_free_expr (init_expr
);
10444 if (!init_expr
&& gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
10445 && sym
->ts
.u
.cl
->length
)
10447 gfc_actual_arglist
*arg
;
10448 init_expr
= gfc_get_expr ();
10449 init_expr
->where
= sym
->declared_at
;
10450 init_expr
->ts
= sym
->ts
;
10451 init_expr
->expr_type
= EXPR_FUNCTION
;
10452 init_expr
->value
.function
.isym
=
10453 gfc_intrinsic_function_by_id (GFC_ISYM_REPEAT
);
10454 init_expr
->value
.function
.name
= "repeat";
10455 arg
= gfc_get_actual_arglist ();
10456 arg
->expr
= gfc_get_character_expr (sym
->ts
.kind
, &sym
->declared_at
,
10458 arg
->expr
->value
.character
.string
[0]
10459 = gfc_option
.flag_init_character_value
;
10460 arg
->next
= gfc_get_actual_arglist ();
10461 arg
->next
->expr
= gfc_copy_expr (sym
->ts
.u
.cl
->length
);
10462 init_expr
->value
.function
.actual
= arg
;
10467 gfc_free_expr (init_expr
);
10473 /* Add an initialization expression to a local variable. */
10475 apply_default_init_local (gfc_symbol
*sym
)
10477 gfc_expr
*init
= NULL
;
10479 /* The symbol should be a variable or a function return value. */
10480 if ((sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
10481 || (sym
->attr
.function
&& sym
->result
!= sym
))
10484 /* Try to build the initializer expression. If we can't initialize
10485 this symbol, then init will be NULL. */
10486 init
= build_default_init_expr (sym
);
10490 /* For saved variables, we don't want to add an initializer at function
10491 entry, so we just add a static initializer. Note that automatic variables
10492 are stack allocated even with -fno-automatic; we have also to exclude
10493 result variable, which are also nonstatic. */
10494 if (sym
->attr
.save
|| sym
->ns
->save_all
10495 || (gfc_option
.flag_max_stack_var_size
== 0 && !sym
->attr
.result
10496 && (!sym
->attr
.dimension
|| !is_non_constant_shape_array (sym
))))
10498 /* Don't clobber an existing initializer! */
10499 gcc_assert (sym
->value
== NULL
);
10504 build_init_assign (sym
, init
);
10508 /* Resolution of common features of flavors variable and procedure. */
10511 resolve_fl_var_and_proc (gfc_symbol
*sym
, int mp_flag
)
10513 gfc_array_spec
*as
;
10515 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
10516 as
= CLASS_DATA (sym
)->as
;
10520 /* Constraints on deferred shape variable. */
10521 if (as
== NULL
|| as
->type
!= AS_DEFERRED
)
10523 bool pointer
, allocatable
, dimension
;
10525 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
10527 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
10528 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
10529 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
10533 pointer
= sym
->attr
.pointer
&& !sym
->attr
.select_type_temporary
;
10534 allocatable
= sym
->attr
.allocatable
;
10535 dimension
= sym
->attr
.dimension
;
10540 if (dimension
&& as
->type
!= AS_ASSUMED_RANK
)
10542 gfc_error ("Allocatable array '%s' at %L must have a deferred "
10543 "shape or assumed rank", sym
->name
, &sym
->declared_at
);
10546 else if (!gfc_notify_std (GFC_STD_F2003
, "Scalar object "
10547 "'%s' at %L may not be ALLOCATABLE",
10548 sym
->name
, &sym
->declared_at
))
10552 if (pointer
&& dimension
&& as
->type
!= AS_ASSUMED_RANK
)
10554 gfc_error ("Array pointer '%s' at %L must have a deferred shape or "
10555 "assumed rank", sym
->name
, &sym
->declared_at
);
10561 if (!mp_flag
&& !sym
->attr
.allocatable
&& !sym
->attr
.pointer
10562 && sym
->ts
.type
!= BT_CLASS
&& !sym
->assoc
)
10564 gfc_error ("Array '%s' at %L cannot have a deferred shape",
10565 sym
->name
, &sym
->declared_at
);
10570 /* Constraints on polymorphic variables. */
10571 if (sym
->ts
.type
== BT_CLASS
&& !(sym
->result
&& sym
->result
!= sym
))
10574 if (sym
->attr
.class_ok
10575 && !sym
->attr
.select_type_temporary
10576 && !UNLIMITED_POLY (sym
)
10577 && !gfc_type_is_extensible (CLASS_DATA (sym
)->ts
.u
.derived
))
10579 gfc_error ("Type '%s' of CLASS variable '%s' at %L is not extensible",
10580 CLASS_DATA (sym
)->ts
.u
.derived
->name
, sym
->name
,
10581 &sym
->declared_at
);
10586 /* Assume that use associated symbols were checked in the module ns.
10587 Class-variables that are associate-names are also something special
10588 and excepted from the test. */
10589 if (!sym
->attr
.class_ok
&& !sym
->attr
.use_assoc
&& !sym
->assoc
)
10591 gfc_error ("CLASS variable '%s' at %L must be dummy, allocatable "
10592 "or pointer", sym
->name
, &sym
->declared_at
);
10601 /* Additional checks for symbols with flavor variable and derived
10602 type. To be called from resolve_fl_variable. */
10605 resolve_fl_variable_derived (gfc_symbol
*sym
, int no_init_flag
)
10607 gcc_assert (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
);
10609 /* Check to see if a derived type is blocked from being host
10610 associated by the presence of another class I symbol in the same
10611 namespace. 14.6.1.3 of the standard and the discussion on
10612 comp.lang.fortran. */
10613 if (sym
->ns
!= sym
->ts
.u
.derived
->ns
10614 && sym
->ns
->proc_name
->attr
.if_source
!= IFSRC_IFBODY
)
10617 gfc_find_symbol (sym
->ts
.u
.derived
->name
, sym
->ns
, 0, &s
);
10618 if (s
&& s
->attr
.generic
)
10619 s
= gfc_find_dt_in_generic (s
);
10620 if (s
&& s
->attr
.flavor
!= FL_DERIVED
)
10622 gfc_error ("The type '%s' cannot be host associated at %L "
10623 "because it is blocked by an incompatible object "
10624 "of the same name declared at %L",
10625 sym
->ts
.u
.derived
->name
, &sym
->declared_at
,
10631 /* 4th constraint in section 11.3: "If an object of a type for which
10632 component-initialization is specified (R429) appears in the
10633 specification-part of a module and does not have the ALLOCATABLE
10634 or POINTER attribute, the object shall have the SAVE attribute."
10636 The check for initializers is performed with
10637 gfc_has_default_initializer because gfc_default_initializer generates
10638 a hidden default for allocatable components. */
10639 if (!(sym
->value
|| no_init_flag
) && sym
->ns
->proc_name
10640 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
10641 && !sym
->ns
->save_all
&& !sym
->attr
.save
10642 && !sym
->attr
.pointer
&& !sym
->attr
.allocatable
10643 && gfc_has_default_initializer (sym
->ts
.u
.derived
)
10644 && !gfc_notify_std (GFC_STD_F2008
, "Implied SAVE for module variable "
10645 "'%s' at %L, needed due to the default "
10646 "initialization", sym
->name
, &sym
->declared_at
))
10649 /* Assign default initializer. */
10650 if (!(sym
->value
|| sym
->attr
.pointer
|| sym
->attr
.allocatable
)
10651 && (!no_init_flag
|| sym
->attr
.intent
== INTENT_OUT
))
10653 sym
->value
= gfc_default_initializer (&sym
->ts
);
10660 /* Resolve symbols with flavor variable. */
10663 resolve_fl_variable (gfc_symbol
*sym
, int mp_flag
)
10665 int no_init_flag
, automatic_flag
;
10667 const char *auto_save_msg
;
10668 bool saved_specification_expr
;
10670 auto_save_msg
= "Automatic object '%s' at %L cannot have the "
10673 if (!resolve_fl_var_and_proc (sym
, mp_flag
))
10676 /* Set this flag to check that variables are parameters of all entries.
10677 This check is effected by the call to gfc_resolve_expr through
10678 is_non_constant_shape_array. */
10679 saved_specification_expr
= specification_expr
;
10680 specification_expr
= true;
10682 if (sym
->ns
->proc_name
10683 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
10684 || sym
->ns
->proc_name
->attr
.is_main_program
)
10685 && !sym
->attr
.use_assoc
10686 && !sym
->attr
.allocatable
10687 && !sym
->attr
.pointer
10688 && is_non_constant_shape_array (sym
))
10690 /* The shape of a main program or module array needs to be
10692 gfc_error ("The module or main program array '%s' at %L must "
10693 "have constant shape", sym
->name
, &sym
->declared_at
);
10694 specification_expr
= saved_specification_expr
;
10698 /* Constraints on deferred type parameter. */
10699 if (sym
->ts
.deferred
&& !(sym
->attr
.pointer
|| sym
->attr
.allocatable
))
10701 gfc_error ("Entity '%s' at %L has a deferred type parameter and "
10702 "requires either the pointer or allocatable attribute",
10703 sym
->name
, &sym
->declared_at
);
10704 specification_expr
= saved_specification_expr
;
10708 if (sym
->ts
.type
== BT_CHARACTER
)
10710 /* Make sure that character string variables with assumed length are
10711 dummy arguments. */
10712 e
= sym
->ts
.u
.cl
->length
;
10713 if (e
== NULL
&& !sym
->attr
.dummy
&& !sym
->attr
.result
10714 && !sym
->ts
.deferred
&& !sym
->attr
.select_type_temporary
)
10716 gfc_error ("Entity with assumed character length at %L must be a "
10717 "dummy argument or a PARAMETER", &sym
->declared_at
);
10718 specification_expr
= saved_specification_expr
;
10722 if (e
&& sym
->attr
.save
== SAVE_EXPLICIT
&& !gfc_is_constant_expr (e
))
10724 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
10725 specification_expr
= saved_specification_expr
;
10729 if (!gfc_is_constant_expr (e
)
10730 && !(e
->expr_type
== EXPR_VARIABLE
10731 && e
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
))
10733 if (!sym
->attr
.use_assoc
&& sym
->ns
->proc_name
10734 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
10735 || sym
->ns
->proc_name
->attr
.is_main_program
))
10737 gfc_error ("'%s' at %L must have constant character length "
10738 "in this context", sym
->name
, &sym
->declared_at
);
10739 specification_expr
= saved_specification_expr
;
10742 if (sym
->attr
.in_common
)
10744 gfc_error ("COMMON variable '%s' at %L must have constant "
10745 "character length", sym
->name
, &sym
->declared_at
);
10746 specification_expr
= saved_specification_expr
;
10752 if (sym
->value
== NULL
&& sym
->attr
.referenced
)
10753 apply_default_init_local (sym
); /* Try to apply a default initialization. */
10755 /* Determine if the symbol may not have an initializer. */
10756 no_init_flag
= automatic_flag
= 0;
10757 if (sym
->attr
.allocatable
|| sym
->attr
.external
|| sym
->attr
.dummy
10758 || sym
->attr
.intrinsic
|| sym
->attr
.result
)
10760 else if ((sym
->attr
.dimension
|| sym
->attr
.codimension
) && !sym
->attr
.pointer
10761 && is_non_constant_shape_array (sym
))
10763 no_init_flag
= automatic_flag
= 1;
10765 /* Also, they must not have the SAVE attribute.
10766 SAVE_IMPLICIT is checked below. */
10767 if (sym
->as
&& sym
->attr
.codimension
)
10769 int corank
= sym
->as
->corank
;
10770 sym
->as
->corank
= 0;
10771 no_init_flag
= automatic_flag
= is_non_constant_shape_array (sym
);
10772 sym
->as
->corank
= corank
;
10774 if (automatic_flag
&& sym
->attr
.save
== SAVE_EXPLICIT
)
10776 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
10777 specification_expr
= saved_specification_expr
;
10782 /* Ensure that any initializer is simplified. */
10784 gfc_simplify_expr (sym
->value
, 1);
10786 /* Reject illegal initializers. */
10787 if (!sym
->mark
&& sym
->value
)
10789 if (sym
->attr
.allocatable
|| (sym
->ts
.type
== BT_CLASS
10790 && CLASS_DATA (sym
)->attr
.allocatable
))
10791 gfc_error ("Allocatable '%s' at %L cannot have an initializer",
10792 sym
->name
, &sym
->declared_at
);
10793 else if (sym
->attr
.external
)
10794 gfc_error ("External '%s' at %L cannot have an initializer",
10795 sym
->name
, &sym
->declared_at
);
10796 else if (sym
->attr
.dummy
10797 && !(sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.intent
== INTENT_OUT
))
10798 gfc_error ("Dummy '%s' at %L cannot have an initializer",
10799 sym
->name
, &sym
->declared_at
);
10800 else if (sym
->attr
.intrinsic
)
10801 gfc_error ("Intrinsic '%s' at %L cannot have an initializer",
10802 sym
->name
, &sym
->declared_at
);
10803 else if (sym
->attr
.result
)
10804 gfc_error ("Function result '%s' at %L cannot have an initializer",
10805 sym
->name
, &sym
->declared_at
);
10806 else if (automatic_flag
)
10807 gfc_error ("Automatic array '%s' at %L cannot have an initializer",
10808 sym
->name
, &sym
->declared_at
);
10810 goto no_init_error
;
10811 specification_expr
= saved_specification_expr
;
10816 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
10818 bool res
= resolve_fl_variable_derived (sym
, no_init_flag
);
10819 specification_expr
= saved_specification_expr
;
10823 specification_expr
= saved_specification_expr
;
10828 /* Resolve a procedure. */
10831 resolve_fl_procedure (gfc_symbol
*sym
, int mp_flag
)
10833 gfc_formal_arglist
*arg
;
10835 if (sym
->attr
.function
10836 && !resolve_fl_var_and_proc (sym
, mp_flag
))
10839 if (sym
->ts
.type
== BT_CHARACTER
)
10841 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
10843 if (cl
&& cl
->length
&& gfc_is_constant_expr (cl
->length
)
10844 && !resolve_charlen (cl
))
10847 if ((!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
10848 && sym
->attr
.proc
== PROC_ST_FUNCTION
)
10850 gfc_error ("Character-valued statement function '%s' at %L must "
10851 "have constant length", sym
->name
, &sym
->declared_at
);
10856 /* Ensure that derived type for are not of a private type. Internal
10857 module procedures are excluded by 2.2.3.3 - i.e., they are not
10858 externally accessible and can access all the objects accessible in
10860 if (!(sym
->ns
->parent
10861 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
10862 && gfc_check_symbol_access (sym
))
10864 gfc_interface
*iface
;
10866 for (arg
= gfc_sym_get_dummy_args (sym
); arg
; arg
= arg
->next
)
10869 && arg
->sym
->ts
.type
== BT_DERIVED
10870 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
10871 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
10872 && !gfc_notify_std (GFC_STD_F2003
, "'%s' is of a PRIVATE type "
10873 "and cannot be a dummy argument"
10874 " of '%s', which is PUBLIC at %L",
10875 arg
->sym
->name
, sym
->name
,
10876 &sym
->declared_at
))
10878 /* Stop this message from recurring. */
10879 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
10884 /* PUBLIC interfaces may expose PRIVATE procedures that take types
10885 PRIVATE to the containing module. */
10886 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
10888 for (arg
= gfc_sym_get_dummy_args (iface
->sym
); arg
; arg
= arg
->next
)
10891 && arg
->sym
->ts
.type
== BT_DERIVED
10892 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
10893 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
10894 && !gfc_notify_std (GFC_STD_F2003
, "Procedure '%s' in "
10895 "PUBLIC interface '%s' at %L "
10896 "takes dummy arguments of '%s' which "
10897 "is PRIVATE", iface
->sym
->name
,
10898 sym
->name
, &iface
->sym
->declared_at
,
10899 gfc_typename(&arg
->sym
->ts
)))
10901 /* Stop this message from recurring. */
10902 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
10908 /* PUBLIC interfaces may expose PRIVATE procedures that take types
10909 PRIVATE to the containing module. */
10910 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
10912 for (arg
= gfc_sym_get_dummy_args (iface
->sym
); arg
; arg
= arg
->next
)
10915 && arg
->sym
->ts
.type
== BT_DERIVED
10916 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
10917 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
10918 && !gfc_notify_std (GFC_STD_F2003
, "Procedure '%s' in "
10919 "PUBLIC interface '%s' at %L takes "
10920 "dummy arguments of '%s' which is "
10921 "PRIVATE", iface
->sym
->name
,
10922 sym
->name
, &iface
->sym
->declared_at
,
10923 gfc_typename(&arg
->sym
->ts
)))
10925 /* Stop this message from recurring. */
10926 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
10933 if (sym
->attr
.function
&& sym
->value
&& sym
->attr
.proc
!= PROC_ST_FUNCTION
10934 && !sym
->attr
.proc_pointer
)
10936 gfc_error ("Function '%s' at %L cannot have an initializer",
10937 sym
->name
, &sym
->declared_at
);
10941 /* An external symbol may not have an initializer because it is taken to be
10942 a procedure. Exception: Procedure Pointers. */
10943 if (sym
->attr
.external
&& sym
->value
&& !sym
->attr
.proc_pointer
)
10945 gfc_error ("External object '%s' at %L may not have an initializer",
10946 sym
->name
, &sym
->declared_at
);
10950 /* An elemental function is required to return a scalar 12.7.1 */
10951 if (sym
->attr
.elemental
&& sym
->attr
.function
&& sym
->as
)
10953 gfc_error ("ELEMENTAL function '%s' at %L must have a scalar "
10954 "result", sym
->name
, &sym
->declared_at
);
10955 /* Reset so that the error only occurs once. */
10956 sym
->attr
.elemental
= 0;
10960 if (sym
->attr
.proc
== PROC_ST_FUNCTION
10961 && (sym
->attr
.allocatable
|| sym
->attr
.pointer
))
10963 gfc_error ("Statement function '%s' at %L may not have pointer or "
10964 "allocatable attribute", sym
->name
, &sym
->declared_at
);
10968 /* 5.1.1.5 of the Standard: A function name declared with an asterisk
10969 char-len-param shall not be array-valued, pointer-valued, recursive
10970 or pure. ....snip... A character value of * may only be used in the
10971 following ways: (i) Dummy arg of procedure - dummy associates with
10972 actual length; (ii) To declare a named constant; or (iii) External
10973 function - but length must be declared in calling scoping unit. */
10974 if (sym
->attr
.function
10975 && sym
->ts
.type
== BT_CHARACTER
&& !sym
->ts
.deferred
10976 && sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
== NULL
)
10978 if ((sym
->as
&& sym
->as
->rank
) || (sym
->attr
.pointer
)
10979 || (sym
->attr
.recursive
) || (sym
->attr
.pure
))
10981 if (sym
->as
&& sym
->as
->rank
)
10982 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
10983 "array-valued", sym
->name
, &sym
->declared_at
);
10985 if (sym
->attr
.pointer
)
10986 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
10987 "pointer-valued", sym
->name
, &sym
->declared_at
);
10989 if (sym
->attr
.pure
)
10990 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
10991 "pure", sym
->name
, &sym
->declared_at
);
10993 if (sym
->attr
.recursive
)
10994 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
10995 "recursive", sym
->name
, &sym
->declared_at
);
11000 /* Appendix B.2 of the standard. Contained functions give an
11001 error anyway. Fixed-form is likely to be F77/legacy. Deferred
11002 character length is an F2003 feature. */
11003 if (!sym
->attr
.contained
11004 && gfc_current_form
!= FORM_FIXED
11005 && !sym
->ts
.deferred
)
11006 gfc_notify_std (GFC_STD_F95_OBS
,
11007 "CHARACTER(*) function '%s' at %L",
11008 sym
->name
, &sym
->declared_at
);
11011 if (sym
->attr
.is_bind_c
&& sym
->attr
.is_c_interop
!= 1)
11013 gfc_formal_arglist
*curr_arg
;
11014 int has_non_interop_arg
= 0;
11016 if (!verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
11017 sym
->common_block
))
11019 /* Clear these to prevent looking at them again if there was an
11021 sym
->attr
.is_bind_c
= 0;
11022 sym
->attr
.is_c_interop
= 0;
11023 sym
->ts
.is_c_interop
= 0;
11027 /* So far, no errors have been found. */
11028 sym
->attr
.is_c_interop
= 1;
11029 sym
->ts
.is_c_interop
= 1;
11032 curr_arg
= gfc_sym_get_dummy_args (sym
);
11033 while (curr_arg
!= NULL
)
11035 /* Skip implicitly typed dummy args here. */
11036 if (curr_arg
->sym
->attr
.implicit_type
== 0)
11037 if (!gfc_verify_c_interop_param (curr_arg
->sym
))
11038 /* If something is found to fail, record the fact so we
11039 can mark the symbol for the procedure as not being
11040 BIND(C) to try and prevent multiple errors being
11042 has_non_interop_arg
= 1;
11044 curr_arg
= curr_arg
->next
;
11047 /* See if any of the arguments were not interoperable and if so, clear
11048 the procedure symbol to prevent duplicate error messages. */
11049 if (has_non_interop_arg
!= 0)
11051 sym
->attr
.is_c_interop
= 0;
11052 sym
->ts
.is_c_interop
= 0;
11053 sym
->attr
.is_bind_c
= 0;
11057 if (!sym
->attr
.proc_pointer
)
11059 if (sym
->attr
.save
== SAVE_EXPLICIT
)
11061 gfc_error ("PROCEDURE attribute conflicts with SAVE attribute "
11062 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
11065 if (sym
->attr
.intent
)
11067 gfc_error ("PROCEDURE attribute conflicts with INTENT attribute "
11068 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
11071 if (sym
->attr
.subroutine
&& sym
->attr
.result
)
11073 gfc_error ("PROCEDURE attribute conflicts with RESULT attribute "
11074 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
11077 if (sym
->attr
.external
&& sym
->attr
.function
11078 && ((sym
->attr
.if_source
== IFSRC_DECL
&& !sym
->attr
.procedure
)
11079 || sym
->attr
.contained
))
11081 gfc_error ("EXTERNAL attribute conflicts with FUNCTION attribute "
11082 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
11085 if (strcmp ("ppr@", sym
->name
) == 0)
11087 gfc_error ("Procedure pointer result '%s' at %L "
11088 "is missing the pointer attribute",
11089 sym
->ns
->proc_name
->name
, &sym
->declared_at
);
11098 /* Resolve a list of finalizer procedures. That is, after they have hopefully
11099 been defined and we now know their defined arguments, check that they fulfill
11100 the requirements of the standard for procedures used as finalizers. */
11103 gfc_resolve_finalizers (gfc_symbol
* derived
)
11105 gfc_finalizer
* list
;
11106 gfc_finalizer
** prev_link
; /* For removing wrong entries from the list. */
11107 bool result
= true;
11108 bool seen_scalar
= false;
11110 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->finalizers
)
11113 /* Walk over the list of finalizer-procedures, check them, and if any one
11114 does not fit in with the standard's definition, print an error and remove
11115 it from the list. */
11116 prev_link
= &derived
->f2k_derived
->finalizers
;
11117 for (list
= derived
->f2k_derived
->finalizers
; list
; list
= *prev_link
)
11119 gfc_formal_arglist
*dummy_args
;
11124 /* Skip this finalizer if we already resolved it. */
11125 if (list
->proc_tree
)
11127 prev_link
= &(list
->next
);
11131 /* Check this exists and is a SUBROUTINE. */
11132 if (!list
->proc_sym
->attr
.subroutine
)
11134 gfc_error ("FINAL procedure '%s' at %L is not a SUBROUTINE",
11135 list
->proc_sym
->name
, &list
->where
);
11139 /* We should have exactly one argument. */
11140 dummy_args
= gfc_sym_get_dummy_args (list
->proc_sym
);
11141 if (!dummy_args
|| dummy_args
->next
)
11143 gfc_error ("FINAL procedure at %L must have exactly one argument",
11147 arg
= dummy_args
->sym
;
11149 /* This argument must be of our type. */
11150 if (arg
->ts
.type
!= BT_DERIVED
|| arg
->ts
.u
.derived
!= derived
)
11152 gfc_error ("Argument of FINAL procedure at %L must be of type '%s'",
11153 &arg
->declared_at
, derived
->name
);
11157 /* It must neither be a pointer nor allocatable nor optional. */
11158 if (arg
->attr
.pointer
)
11160 gfc_error ("Argument of FINAL procedure at %L must not be a POINTER",
11161 &arg
->declared_at
);
11164 if (arg
->attr
.allocatable
)
11166 gfc_error ("Argument of FINAL procedure at %L must not be"
11167 " ALLOCATABLE", &arg
->declared_at
);
11170 if (arg
->attr
.optional
)
11172 gfc_error ("Argument of FINAL procedure at %L must not be OPTIONAL",
11173 &arg
->declared_at
);
11177 /* It must not be INTENT(OUT). */
11178 if (arg
->attr
.intent
== INTENT_OUT
)
11180 gfc_error ("Argument of FINAL procedure at %L must not be"
11181 " INTENT(OUT)", &arg
->declared_at
);
11185 /* Warn if the procedure is non-scalar and not assumed shape. */
11186 if (gfc_option
.warn_surprising
&& arg
->as
&& arg
->as
->rank
!= 0
11187 && arg
->as
->type
!= AS_ASSUMED_SHAPE
)
11188 gfc_warning ("Non-scalar FINAL procedure at %L should have assumed"
11189 " shape argument", &arg
->declared_at
);
11191 /* Check that it does not match in kind and rank with a FINAL procedure
11192 defined earlier. To really loop over the *earlier* declarations,
11193 we need to walk the tail of the list as new ones were pushed at the
11195 /* TODO: Handle kind parameters once they are implemented. */
11196 my_rank
= (arg
->as
? arg
->as
->rank
: 0);
11197 for (i
= list
->next
; i
; i
= i
->next
)
11199 gfc_formal_arglist
*dummy_args
;
11201 /* Argument list might be empty; that is an error signalled earlier,
11202 but we nevertheless continued resolving. */
11203 dummy_args
= gfc_sym_get_dummy_args (i
->proc_sym
);
11206 gfc_symbol
* i_arg
= dummy_args
->sym
;
11207 const int i_rank
= (i_arg
->as
? i_arg
->as
->rank
: 0);
11208 if (i_rank
== my_rank
)
11210 gfc_error ("FINAL procedure '%s' declared at %L has the same"
11211 " rank (%d) as '%s'",
11212 list
->proc_sym
->name
, &list
->where
, my_rank
,
11213 i
->proc_sym
->name
);
11219 /* Is this the/a scalar finalizer procedure? */
11220 if (!arg
->as
|| arg
->as
->rank
== 0)
11221 seen_scalar
= true;
11223 /* Find the symtree for this procedure. */
11224 gcc_assert (!list
->proc_tree
);
11225 list
->proc_tree
= gfc_find_sym_in_symtree (list
->proc_sym
);
11227 prev_link
= &list
->next
;
11230 /* Remove wrong nodes immediately from the list so we don't risk any
11231 troubles in the future when they might fail later expectations. */
11235 *prev_link
= list
->next
;
11236 gfc_free_finalizer (i
);
11239 /* Warn if we haven't seen a scalar finalizer procedure (but we know there
11240 were nodes in the list, must have been for arrays. It is surely a good
11241 idea to have a scalar version there if there's something to finalize. */
11242 if (gfc_option
.warn_surprising
&& result
&& !seen_scalar
)
11243 gfc_warning ("Only array FINAL procedures declared for derived type '%s'"
11244 " defined at %L, suggest also scalar one",
11245 derived
->name
, &derived
->declared_at
);
11247 gfc_find_derived_vtab (derived
);
11252 /* Check if two GENERIC targets are ambiguous and emit an error is they are. */
11255 check_generic_tbp_ambiguity (gfc_tbp_generic
* t1
, gfc_tbp_generic
* t2
,
11256 const char* generic_name
, locus where
)
11258 gfc_symbol
*sym1
, *sym2
;
11259 const char *pass1
, *pass2
;
11261 gcc_assert (t1
->specific
&& t2
->specific
);
11262 gcc_assert (!t1
->specific
->is_generic
);
11263 gcc_assert (!t2
->specific
->is_generic
);
11264 gcc_assert (t1
->is_operator
== t2
->is_operator
);
11266 sym1
= t1
->specific
->u
.specific
->n
.sym
;
11267 sym2
= t2
->specific
->u
.specific
->n
.sym
;
11272 /* Both must be SUBROUTINEs or both must be FUNCTIONs. */
11273 if (sym1
->attr
.subroutine
!= sym2
->attr
.subroutine
11274 || sym1
->attr
.function
!= sym2
->attr
.function
)
11276 gfc_error ("'%s' and '%s' can't be mixed FUNCTION/SUBROUTINE for"
11277 " GENERIC '%s' at %L",
11278 sym1
->name
, sym2
->name
, generic_name
, &where
);
11282 /* Compare the interfaces. */
11283 if (t1
->specific
->nopass
)
11285 else if (t1
->specific
->pass_arg
)
11286 pass1
= t1
->specific
->pass_arg
;
11288 pass1
= gfc_sym_get_dummy_args (t1
->specific
->u
.specific
->n
.sym
)->sym
->name
;
11289 if (t2
->specific
->nopass
)
11291 else if (t2
->specific
->pass_arg
)
11292 pass2
= t2
->specific
->pass_arg
;
11294 pass2
= gfc_sym_get_dummy_args (t2
->specific
->u
.specific
->n
.sym
)->sym
->name
;
11295 if (gfc_compare_interfaces (sym1
, sym2
, sym2
->name
, !t1
->is_operator
, 0,
11296 NULL
, 0, pass1
, pass2
))
11298 gfc_error ("'%s' and '%s' for GENERIC '%s' at %L are ambiguous",
11299 sym1
->name
, sym2
->name
, generic_name
, &where
);
11307 /* Worker function for resolving a generic procedure binding; this is used to
11308 resolve GENERIC as well as user and intrinsic OPERATOR typebound procedures.
11310 The difference between those cases is finding possible inherited bindings
11311 that are overridden, as one has to look for them in tb_sym_root,
11312 tb_uop_root or tb_op, respectively. Thus the caller must already find
11313 the super-type and set p->overridden correctly. */
11316 resolve_tb_generic_targets (gfc_symbol
* super_type
,
11317 gfc_typebound_proc
* p
, const char* name
)
11319 gfc_tbp_generic
* target
;
11320 gfc_symtree
* first_target
;
11321 gfc_symtree
* inherited
;
11323 gcc_assert (p
&& p
->is_generic
);
11325 /* Try to find the specific bindings for the symtrees in our target-list. */
11326 gcc_assert (p
->u
.generic
);
11327 for (target
= p
->u
.generic
; target
; target
= target
->next
)
11328 if (!target
->specific
)
11330 gfc_typebound_proc
* overridden_tbp
;
11331 gfc_tbp_generic
* g
;
11332 const char* target_name
;
11334 target_name
= target
->specific_st
->name
;
11336 /* Defined for this type directly. */
11337 if (target
->specific_st
->n
.tb
&& !target
->specific_st
->n
.tb
->error
)
11339 target
->specific
= target
->specific_st
->n
.tb
;
11340 goto specific_found
;
11343 /* Look for an inherited specific binding. */
11346 inherited
= gfc_find_typebound_proc (super_type
, NULL
, target_name
,
11351 gcc_assert (inherited
->n
.tb
);
11352 target
->specific
= inherited
->n
.tb
;
11353 goto specific_found
;
11357 gfc_error ("Undefined specific binding '%s' as target of GENERIC '%s'"
11358 " at %L", target_name
, name
, &p
->where
);
11361 /* Once we've found the specific binding, check it is not ambiguous with
11362 other specifics already found or inherited for the same GENERIC. */
11364 gcc_assert (target
->specific
);
11366 /* This must really be a specific binding! */
11367 if (target
->specific
->is_generic
)
11369 gfc_error ("GENERIC '%s' at %L must target a specific binding,"
11370 " '%s' is GENERIC, too", name
, &p
->where
, target_name
);
11374 /* Check those already resolved on this type directly. */
11375 for (g
= p
->u
.generic
; g
; g
= g
->next
)
11376 if (g
!= target
&& g
->specific
11377 && !check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
11380 /* Check for ambiguity with inherited specific targets. */
11381 for (overridden_tbp
= p
->overridden
; overridden_tbp
;
11382 overridden_tbp
= overridden_tbp
->overridden
)
11383 if (overridden_tbp
->is_generic
)
11385 for (g
= overridden_tbp
->u
.generic
; g
; g
= g
->next
)
11387 gcc_assert (g
->specific
);
11388 if (!check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
11394 /* If we attempt to "overwrite" a specific binding, this is an error. */
11395 if (p
->overridden
&& !p
->overridden
->is_generic
)
11397 gfc_error ("GENERIC '%s' at %L can't overwrite specific binding with"
11398 " the same name", name
, &p
->where
);
11402 /* Take the SUBROUTINE/FUNCTION attributes of the first specific target, as
11403 all must have the same attributes here. */
11404 first_target
= p
->u
.generic
->specific
->u
.specific
;
11405 gcc_assert (first_target
);
11406 p
->subroutine
= first_target
->n
.sym
->attr
.subroutine
;
11407 p
->function
= first_target
->n
.sym
->attr
.function
;
11413 /* Resolve a GENERIC procedure binding for a derived type. */
11416 resolve_typebound_generic (gfc_symbol
* derived
, gfc_symtree
* st
)
11418 gfc_symbol
* super_type
;
11420 /* Find the overridden binding if any. */
11421 st
->n
.tb
->overridden
= NULL
;
11422 super_type
= gfc_get_derived_super_type (derived
);
11425 gfc_symtree
* overridden
;
11426 overridden
= gfc_find_typebound_proc (super_type
, NULL
, st
->name
,
11429 if (overridden
&& overridden
->n
.tb
)
11430 st
->n
.tb
->overridden
= overridden
->n
.tb
;
11433 /* Resolve using worker function. */
11434 return resolve_tb_generic_targets (super_type
, st
->n
.tb
, st
->name
);
11438 /* Retrieve the target-procedure of an operator binding and do some checks in
11439 common for intrinsic and user-defined type-bound operators. */
11442 get_checked_tb_operator_target (gfc_tbp_generic
* target
, locus where
)
11444 gfc_symbol
* target_proc
;
11446 gcc_assert (target
->specific
&& !target
->specific
->is_generic
);
11447 target_proc
= target
->specific
->u
.specific
->n
.sym
;
11448 gcc_assert (target_proc
);
11450 /* F08:C468. All operator bindings must have a passed-object dummy argument. */
11451 if (target
->specific
->nopass
)
11453 gfc_error ("Type-bound operator at %L can't be NOPASS", &where
);
11457 return target_proc
;
11461 /* Resolve a type-bound intrinsic operator. */
11464 resolve_typebound_intrinsic_op (gfc_symbol
* derived
, gfc_intrinsic_op op
,
11465 gfc_typebound_proc
* p
)
11467 gfc_symbol
* super_type
;
11468 gfc_tbp_generic
* target
;
11470 /* If there's already an error here, do nothing (but don't fail again). */
11474 /* Operators should always be GENERIC bindings. */
11475 gcc_assert (p
->is_generic
);
11477 /* Look for an overridden binding. */
11478 super_type
= gfc_get_derived_super_type (derived
);
11479 if (super_type
&& super_type
->f2k_derived
)
11480 p
->overridden
= gfc_find_typebound_intrinsic_op (super_type
, NULL
,
11483 p
->overridden
= NULL
;
11485 /* Resolve general GENERIC properties using worker function. */
11486 if (!resolve_tb_generic_targets (super_type
, p
, gfc_op2string(op
)))
11489 /* Check the targets to be procedures of correct interface. */
11490 for (target
= p
->u
.generic
; target
; target
= target
->next
)
11492 gfc_symbol
* target_proc
;
11494 target_proc
= get_checked_tb_operator_target (target
, p
->where
);
11498 if (!gfc_check_operator_interface (target_proc
, op
, p
->where
))
11501 /* Add target to non-typebound operator list. */
11502 if (!target
->specific
->deferred
&& !derived
->attr
.use_assoc
11503 && p
->access
!= ACCESS_PRIVATE
&& derived
->ns
== gfc_current_ns
)
11505 gfc_interface
*head
, *intr
;
11506 if (!gfc_check_new_interface (derived
->ns
->op
[op
], target_proc
, p
->where
))
11508 head
= derived
->ns
->op
[op
];
11509 intr
= gfc_get_interface ();
11510 intr
->sym
= target_proc
;
11511 intr
->where
= p
->where
;
11513 derived
->ns
->op
[op
] = intr
;
11525 /* Resolve a type-bound user operator (tree-walker callback). */
11527 static gfc_symbol
* resolve_bindings_derived
;
11528 static bool resolve_bindings_result
;
11530 static bool check_uop_procedure (gfc_symbol
* sym
, locus where
);
11533 resolve_typebound_user_op (gfc_symtree
* stree
)
11535 gfc_symbol
* super_type
;
11536 gfc_tbp_generic
* target
;
11538 gcc_assert (stree
&& stree
->n
.tb
);
11540 if (stree
->n
.tb
->error
)
11543 /* Operators should always be GENERIC bindings. */
11544 gcc_assert (stree
->n
.tb
->is_generic
);
11546 /* Find overridden procedure, if any. */
11547 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
11548 if (super_type
&& super_type
->f2k_derived
)
11550 gfc_symtree
* overridden
;
11551 overridden
= gfc_find_typebound_user_op (super_type
, NULL
,
11552 stree
->name
, true, NULL
);
11554 if (overridden
&& overridden
->n
.tb
)
11555 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
11558 stree
->n
.tb
->overridden
= NULL
;
11560 /* Resolve basically using worker function. */
11561 if (!resolve_tb_generic_targets (super_type
, stree
->n
.tb
, stree
->name
))
11564 /* Check the targets to be functions of correct interface. */
11565 for (target
= stree
->n
.tb
->u
.generic
; target
; target
= target
->next
)
11567 gfc_symbol
* target_proc
;
11569 target_proc
= get_checked_tb_operator_target (target
, stree
->n
.tb
->where
);
11573 if (!check_uop_procedure (target_proc
, stree
->n
.tb
->where
))
11580 resolve_bindings_result
= false;
11581 stree
->n
.tb
->error
= 1;
11585 /* Resolve the type-bound procedures for a derived type. */
11588 resolve_typebound_procedure (gfc_symtree
* stree
)
11592 gfc_symbol
* me_arg
;
11593 gfc_symbol
* super_type
;
11594 gfc_component
* comp
;
11596 gcc_assert (stree
);
11598 /* Undefined specific symbol from GENERIC target definition. */
11602 if (stree
->n
.tb
->error
)
11605 /* If this is a GENERIC binding, use that routine. */
11606 if (stree
->n
.tb
->is_generic
)
11608 if (!resolve_typebound_generic (resolve_bindings_derived
, stree
))
11613 /* Get the target-procedure to check it. */
11614 gcc_assert (!stree
->n
.tb
->is_generic
);
11615 gcc_assert (stree
->n
.tb
->u
.specific
);
11616 proc
= stree
->n
.tb
->u
.specific
->n
.sym
;
11617 where
= stree
->n
.tb
->where
;
11619 /* Default access should already be resolved from the parser. */
11620 gcc_assert (stree
->n
.tb
->access
!= ACCESS_UNKNOWN
);
11622 if (stree
->n
.tb
->deferred
)
11624 if (!check_proc_interface (proc
, &where
))
11629 /* Check for F08:C465. */
11630 if ((!proc
->attr
.subroutine
&& !proc
->attr
.function
)
11631 || (proc
->attr
.proc
!= PROC_MODULE
11632 && proc
->attr
.if_source
!= IFSRC_IFBODY
)
11633 || proc
->attr
.abstract
)
11635 gfc_error ("'%s' must be a module procedure or an external procedure with"
11636 " an explicit interface at %L", proc
->name
, &where
);
11641 stree
->n
.tb
->subroutine
= proc
->attr
.subroutine
;
11642 stree
->n
.tb
->function
= proc
->attr
.function
;
11644 /* Find the super-type of the current derived type. We could do this once and
11645 store in a global if speed is needed, but as long as not I believe this is
11646 more readable and clearer. */
11647 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
11649 /* If PASS, resolve and check arguments if not already resolved / loaded
11650 from a .mod file. */
11651 if (!stree
->n
.tb
->nopass
&& stree
->n
.tb
->pass_arg_num
== 0)
11653 gfc_formal_arglist
*dummy_args
;
11655 dummy_args
= gfc_sym_get_dummy_args (proc
);
11656 if (stree
->n
.tb
->pass_arg
)
11658 gfc_formal_arglist
*i
;
11660 /* If an explicit passing argument name is given, walk the arg-list
11661 and look for it. */
11664 stree
->n
.tb
->pass_arg_num
= 1;
11665 for (i
= dummy_args
; i
; i
= i
->next
)
11667 if (!strcmp (i
->sym
->name
, stree
->n
.tb
->pass_arg
))
11672 ++stree
->n
.tb
->pass_arg_num
;
11677 gfc_error ("Procedure '%s' with PASS(%s) at %L has no"
11679 proc
->name
, stree
->n
.tb
->pass_arg
, &where
,
11680 stree
->n
.tb
->pass_arg
);
11686 /* Otherwise, take the first one; there should in fact be at least
11688 stree
->n
.tb
->pass_arg_num
= 1;
11691 gfc_error ("Procedure '%s' with PASS at %L must have at"
11692 " least one argument", proc
->name
, &where
);
11695 me_arg
= dummy_args
->sym
;
11698 /* Now check that the argument-type matches and the passed-object
11699 dummy argument is generally fine. */
11701 gcc_assert (me_arg
);
11703 if (me_arg
->ts
.type
!= BT_CLASS
)
11705 gfc_error ("Non-polymorphic passed-object dummy argument of '%s'"
11706 " at %L", proc
->name
, &where
);
11710 if (CLASS_DATA (me_arg
)->ts
.u
.derived
11711 != resolve_bindings_derived
)
11713 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L must be of"
11714 " the derived-type '%s'", me_arg
->name
, proc
->name
,
11715 me_arg
->name
, &where
, resolve_bindings_derived
->name
);
11719 gcc_assert (me_arg
->ts
.type
== BT_CLASS
);
11720 if (CLASS_DATA (me_arg
)->as
&& CLASS_DATA (me_arg
)->as
->rank
!= 0)
11722 gfc_error ("Passed-object dummy argument of '%s' at %L must be"
11723 " scalar", proc
->name
, &where
);
11726 if (CLASS_DATA (me_arg
)->attr
.allocatable
)
11728 gfc_error ("Passed-object dummy argument of '%s' at %L must not"
11729 " be ALLOCATABLE", proc
->name
, &where
);
11732 if (CLASS_DATA (me_arg
)->attr
.class_pointer
)
11734 gfc_error ("Passed-object dummy argument of '%s' at %L must not"
11735 " be POINTER", proc
->name
, &where
);
11740 /* If we are extending some type, check that we don't override a procedure
11741 flagged NON_OVERRIDABLE. */
11742 stree
->n
.tb
->overridden
= NULL
;
11745 gfc_symtree
* overridden
;
11746 overridden
= gfc_find_typebound_proc (super_type
, NULL
,
11747 stree
->name
, true, NULL
);
11751 if (overridden
->n
.tb
)
11752 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
11754 if (!gfc_check_typebound_override (stree
, overridden
))
11759 /* See if there's a name collision with a component directly in this type. */
11760 for (comp
= resolve_bindings_derived
->components
; comp
; comp
= comp
->next
)
11761 if (!strcmp (comp
->name
, stree
->name
))
11763 gfc_error ("Procedure '%s' at %L has the same name as a component of"
11765 stree
->name
, &where
, resolve_bindings_derived
->name
);
11769 /* Try to find a name collision with an inherited component. */
11770 if (super_type
&& gfc_find_component (super_type
, stree
->name
, true, true))
11772 gfc_error ("Procedure '%s' at %L has the same name as an inherited"
11773 " component of '%s'",
11774 stree
->name
, &where
, resolve_bindings_derived
->name
);
11778 stree
->n
.tb
->error
= 0;
11782 resolve_bindings_result
= false;
11783 stree
->n
.tb
->error
= 1;
11788 resolve_typebound_procedures (gfc_symbol
* derived
)
11791 gfc_symbol
* super_type
;
11793 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->tb_sym_root
)
11796 super_type
= gfc_get_derived_super_type (derived
);
11798 resolve_symbol (super_type
);
11800 resolve_bindings_derived
= derived
;
11801 resolve_bindings_result
= true;
11803 /* Make sure the vtab has been generated. */
11804 gfc_find_derived_vtab (derived
);
11806 if (derived
->f2k_derived
->tb_sym_root
)
11807 gfc_traverse_symtree (derived
->f2k_derived
->tb_sym_root
,
11808 &resolve_typebound_procedure
);
11810 if (derived
->f2k_derived
->tb_uop_root
)
11811 gfc_traverse_symtree (derived
->f2k_derived
->tb_uop_root
,
11812 &resolve_typebound_user_op
);
11814 for (op
= 0; op
!= GFC_INTRINSIC_OPS
; ++op
)
11816 gfc_typebound_proc
* p
= derived
->f2k_derived
->tb_op
[op
];
11817 if (p
&& !resolve_typebound_intrinsic_op (derived
,
11818 (gfc_intrinsic_op
)op
, p
))
11819 resolve_bindings_result
= false;
11822 return resolve_bindings_result
;
11826 /* Add a derived type to the dt_list. The dt_list is used in trans-types.c
11827 to give all identical derived types the same backend_decl. */
11829 add_dt_to_dt_list (gfc_symbol
*derived
)
11831 gfc_dt_list
*dt_list
;
11833 for (dt_list
= gfc_derived_types
; dt_list
; dt_list
= dt_list
->next
)
11834 if (derived
== dt_list
->derived
)
11837 dt_list
= gfc_get_dt_list ();
11838 dt_list
->next
= gfc_derived_types
;
11839 dt_list
->derived
= derived
;
11840 gfc_derived_types
= dt_list
;
11844 /* Ensure that a derived-type is really not abstract, meaning that every
11845 inherited DEFERRED binding is overridden by a non-DEFERRED one. */
11848 ensure_not_abstract_walker (gfc_symbol
* sub
, gfc_symtree
* st
)
11853 if (!ensure_not_abstract_walker (sub
, st
->left
))
11855 if (!ensure_not_abstract_walker (sub
, st
->right
))
11858 if (st
->n
.tb
&& st
->n
.tb
->deferred
)
11860 gfc_symtree
* overriding
;
11861 overriding
= gfc_find_typebound_proc (sub
, NULL
, st
->name
, true, NULL
);
11864 gcc_assert (overriding
->n
.tb
);
11865 if (overriding
->n
.tb
->deferred
)
11867 gfc_error ("Derived-type '%s' declared at %L must be ABSTRACT because"
11868 " '%s' is DEFERRED and not overridden",
11869 sub
->name
, &sub
->declared_at
, st
->name
);
11878 ensure_not_abstract (gfc_symbol
* sub
, gfc_symbol
* ancestor
)
11880 /* The algorithm used here is to recursively travel up the ancestry of sub
11881 and for each ancestor-type, check all bindings. If any of them is
11882 DEFERRED, look it up starting from sub and see if the found (overriding)
11883 binding is not DEFERRED.
11884 This is not the most efficient way to do this, but it should be ok and is
11885 clearer than something sophisticated. */
11887 gcc_assert (ancestor
&& !sub
->attr
.abstract
);
11889 if (!ancestor
->attr
.abstract
)
11892 /* Walk bindings of this ancestor. */
11893 if (ancestor
->f2k_derived
)
11896 t
= ensure_not_abstract_walker (sub
, ancestor
->f2k_derived
->tb_sym_root
);
11901 /* Find next ancestor type and recurse on it. */
11902 ancestor
= gfc_get_derived_super_type (ancestor
);
11904 return ensure_not_abstract (sub
, ancestor
);
11910 /* This check for typebound defined assignments is done recursively
11911 since the order in which derived types are resolved is not always in
11912 order of the declarations. */
11915 check_defined_assignments (gfc_symbol
*derived
)
11919 for (c
= derived
->components
; c
; c
= c
->next
)
11921 if (c
->ts
.type
!= BT_DERIVED
11923 || c
->attr
.allocatable
11924 || c
->attr
.proc_pointer_comp
11925 || c
->attr
.class_pointer
11926 || c
->attr
.proc_pointer
)
11929 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
11930 || (c
->ts
.u
.derived
->f2k_derived
11931 && c
->ts
.u
.derived
->f2k_derived
->tb_op
[INTRINSIC_ASSIGN
]))
11933 derived
->attr
.defined_assign_comp
= 1;
11937 check_defined_assignments (c
->ts
.u
.derived
);
11938 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
11940 derived
->attr
.defined_assign_comp
= 1;
11947 /* Resolve the components of a derived type. This does not have to wait until
11948 resolution stage, but can be done as soon as the dt declaration has been
11952 resolve_fl_derived0 (gfc_symbol
*sym
)
11954 gfc_symbol
* super_type
;
11957 if (sym
->attr
.unlimited_polymorphic
)
11960 super_type
= gfc_get_derived_super_type (sym
);
11963 if (super_type
&& sym
->attr
.coarray_comp
&& !super_type
->attr
.coarray_comp
)
11965 gfc_error ("As extending type '%s' at %L has a coarray component, "
11966 "parent type '%s' shall also have one", sym
->name
,
11967 &sym
->declared_at
, super_type
->name
);
11971 /* Ensure the extended type gets resolved before we do. */
11972 if (super_type
&& !resolve_fl_derived0 (super_type
))
11975 /* An ABSTRACT type must be extensible. */
11976 if (sym
->attr
.abstract
&& !gfc_type_is_extensible (sym
))
11978 gfc_error ("Non-extensible derived-type '%s' at %L must not be ABSTRACT",
11979 sym
->name
, &sym
->declared_at
);
11983 c
= (sym
->attr
.is_class
) ? sym
->components
->ts
.u
.derived
->components
11986 for ( ; c
!= NULL
; c
= c
->next
)
11988 if (c
->attr
.artificial
)
11991 /* See PRs 51550, 47545, 48654, 49050, 51075 - and 45170. */
11992 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
&& !c
->attr
.function
)
11994 gfc_error ("Deferred-length character component '%s' at %L is not "
11995 "yet supported", c
->name
, &c
->loc
);
12000 if ((!sym
->attr
.is_class
|| c
!= sym
->components
)
12001 && c
->attr
.codimension
12002 && (!c
->attr
.allocatable
|| (c
->as
&& c
->as
->type
!= AS_DEFERRED
)))
12004 gfc_error ("Coarray component '%s' at %L must be allocatable with "
12005 "deferred shape", c
->name
, &c
->loc
);
12010 if (c
->attr
.codimension
&& c
->ts
.type
== BT_DERIVED
12011 && c
->ts
.u
.derived
->ts
.is_iso_c
)
12013 gfc_error ("Component '%s' at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
12014 "shall not be a coarray", c
->name
, &c
->loc
);
12019 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
12020 && (c
->attr
.codimension
|| c
->attr
.pointer
|| c
->attr
.dimension
12021 || c
->attr
.allocatable
))
12023 gfc_error ("Component '%s' at %L with coarray component "
12024 "shall be a nonpointer, nonallocatable scalar",
12030 if (c
->attr
.contiguous
&& (!c
->attr
.dimension
|| !c
->attr
.pointer
))
12032 gfc_error ("Component '%s' at %L has the CONTIGUOUS attribute but "
12033 "is not an array pointer", c
->name
, &c
->loc
);
12037 if (c
->attr
.proc_pointer
&& c
->ts
.interface
)
12039 gfc_symbol
*ifc
= c
->ts
.interface
;
12041 if (!sym
->attr
.vtype
12042 && !check_proc_interface (ifc
, &c
->loc
))
12045 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
12047 /* Resolve interface and copy attributes. */
12048 if (ifc
->formal
&& !ifc
->formal_ns
)
12049 resolve_symbol (ifc
);
12050 if (ifc
->attr
.intrinsic
)
12051 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
12055 c
->ts
= ifc
->result
->ts
;
12056 c
->attr
.allocatable
= ifc
->result
->attr
.allocatable
;
12057 c
->attr
.pointer
= ifc
->result
->attr
.pointer
;
12058 c
->attr
.dimension
= ifc
->result
->attr
.dimension
;
12059 c
->as
= gfc_copy_array_spec (ifc
->result
->as
);
12060 c
->attr
.class_ok
= ifc
->result
->attr
.class_ok
;
12065 c
->attr
.allocatable
= ifc
->attr
.allocatable
;
12066 c
->attr
.pointer
= ifc
->attr
.pointer
;
12067 c
->attr
.dimension
= ifc
->attr
.dimension
;
12068 c
->as
= gfc_copy_array_spec (ifc
->as
);
12069 c
->attr
.class_ok
= ifc
->attr
.class_ok
;
12071 c
->ts
.interface
= ifc
;
12072 c
->attr
.function
= ifc
->attr
.function
;
12073 c
->attr
.subroutine
= ifc
->attr
.subroutine
;
12075 c
->attr
.pure
= ifc
->attr
.pure
;
12076 c
->attr
.elemental
= ifc
->attr
.elemental
;
12077 c
->attr
.recursive
= ifc
->attr
.recursive
;
12078 c
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
12079 c
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
12080 /* Copy char length. */
12081 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
12083 gfc_charlen
*cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
12084 if (cl
->length
&& !cl
->resolved
12085 && !gfc_resolve_expr (cl
->length
))
12091 else if (c
->attr
.proc_pointer
&& c
->ts
.type
== BT_UNKNOWN
)
12093 /* Since PPCs are not implicitly typed, a PPC without an explicit
12094 interface must be a subroutine. */
12095 gfc_add_subroutine (&c
->attr
, c
->name
, &c
->loc
);
12098 /* Procedure pointer components: Check PASS arg. */
12099 if (c
->attr
.proc_pointer
&& !c
->tb
->nopass
&& c
->tb
->pass_arg_num
== 0
12100 && !sym
->attr
.vtype
)
12102 gfc_symbol
* me_arg
;
12104 if (c
->tb
->pass_arg
)
12106 gfc_formal_arglist
* i
;
12108 /* If an explicit passing argument name is given, walk the arg-list
12109 and look for it. */
12112 c
->tb
->pass_arg_num
= 1;
12113 for (i
= c
->ts
.interface
->formal
; i
; i
= i
->next
)
12115 if (!strcmp (i
->sym
->name
, c
->tb
->pass_arg
))
12120 c
->tb
->pass_arg_num
++;
12125 gfc_error ("Procedure pointer component '%s' with PASS(%s) "
12126 "at %L has no argument '%s'", c
->name
,
12127 c
->tb
->pass_arg
, &c
->loc
, c
->tb
->pass_arg
);
12134 /* Otherwise, take the first one; there should in fact be at least
12136 c
->tb
->pass_arg_num
= 1;
12137 if (!c
->ts
.interface
->formal
)
12139 gfc_error ("Procedure pointer component '%s' with PASS at %L "
12140 "must have at least one argument",
12145 me_arg
= c
->ts
.interface
->formal
->sym
;
12148 /* Now check that the argument-type matches. */
12149 gcc_assert (me_arg
);
12150 if ((me_arg
->ts
.type
!= BT_DERIVED
&& me_arg
->ts
.type
!= BT_CLASS
)
12151 || (me_arg
->ts
.type
== BT_DERIVED
&& me_arg
->ts
.u
.derived
!= sym
)
12152 || (me_arg
->ts
.type
== BT_CLASS
12153 && CLASS_DATA (me_arg
)->ts
.u
.derived
!= sym
))
12155 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L must be of"
12156 " the derived type '%s'", me_arg
->name
, c
->name
,
12157 me_arg
->name
, &c
->loc
, sym
->name
);
12162 /* Check for C453. */
12163 if (me_arg
->attr
.dimension
)
12165 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
12166 "must be scalar", me_arg
->name
, c
->name
, me_arg
->name
,
12172 if (me_arg
->attr
.pointer
)
12174 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
12175 "may not have the POINTER attribute", me_arg
->name
,
12176 c
->name
, me_arg
->name
, &c
->loc
);
12181 if (me_arg
->attr
.allocatable
)
12183 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
12184 "may not be ALLOCATABLE", me_arg
->name
, c
->name
,
12185 me_arg
->name
, &c
->loc
);
12190 if (gfc_type_is_extensible (sym
) && me_arg
->ts
.type
!= BT_CLASS
)
12191 gfc_error ("Non-polymorphic passed-object dummy argument of '%s'"
12192 " at %L", c
->name
, &c
->loc
);
12196 /* Check type-spec if this is not the parent-type component. */
12197 if (((sym
->attr
.is_class
12198 && (!sym
->components
->ts
.u
.derived
->attr
.extension
12199 || c
!= sym
->components
->ts
.u
.derived
->components
))
12200 || (!sym
->attr
.is_class
12201 && (!sym
->attr
.extension
|| c
!= sym
->components
)))
12202 && !sym
->attr
.vtype
12203 && !resolve_typespec_used (&c
->ts
, &c
->loc
, c
->name
))
12206 /* If this type is an extension, set the accessibility of the parent
12209 && ((sym
->attr
.is_class
12210 && c
== sym
->components
->ts
.u
.derived
->components
)
12211 || (!sym
->attr
.is_class
&& c
== sym
->components
))
12212 && strcmp (super_type
->name
, c
->name
) == 0)
12213 c
->attr
.access
= super_type
->attr
.access
;
12215 /* If this type is an extension, see if this component has the same name
12216 as an inherited type-bound procedure. */
12217 if (super_type
&& !sym
->attr
.is_class
12218 && gfc_find_typebound_proc (super_type
, NULL
, c
->name
, true, NULL
))
12220 gfc_error ("Component '%s' of '%s' at %L has the same name as an"
12221 " inherited type-bound procedure",
12222 c
->name
, sym
->name
, &c
->loc
);
12226 if (c
->ts
.type
== BT_CHARACTER
&& !c
->attr
.proc_pointer
12227 && !c
->ts
.deferred
)
12229 if (c
->ts
.u
.cl
->length
== NULL
12230 || (!resolve_charlen(c
->ts
.u
.cl
))
12231 || !gfc_is_constant_expr (c
->ts
.u
.cl
->length
))
12233 gfc_error ("Character length of component '%s' needs to "
12234 "be a constant specification expression at %L",
12236 c
->ts
.u
.cl
->length
? &c
->ts
.u
.cl
->length
->where
: &c
->loc
);
12241 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
12242 && !c
->attr
.pointer
&& !c
->attr
.allocatable
)
12244 gfc_error ("Character component '%s' of '%s' at %L with deferred "
12245 "length must be a POINTER or ALLOCATABLE",
12246 c
->name
, sym
->name
, &c
->loc
);
12250 if (c
->ts
.type
== BT_DERIVED
12251 && sym
->component_access
!= ACCESS_PRIVATE
12252 && gfc_check_symbol_access (sym
)
12253 && !is_sym_host_assoc (c
->ts
.u
.derived
, sym
->ns
)
12254 && !c
->ts
.u
.derived
->attr
.use_assoc
12255 && !gfc_check_symbol_access (c
->ts
.u
.derived
)
12256 && !gfc_notify_std (GFC_STD_F2003
, "the component '%s' is a "
12257 "PRIVATE type and cannot be a component of "
12258 "'%s', which is PUBLIC at %L", c
->name
,
12259 sym
->name
, &sym
->declared_at
))
12262 if ((sym
->attr
.sequence
|| sym
->attr
.is_bind_c
) && c
->ts
.type
== BT_CLASS
)
12264 gfc_error ("Polymorphic component %s at %L in SEQUENCE or BIND(C) "
12265 "type %s", c
->name
, &c
->loc
, sym
->name
);
12269 if (sym
->attr
.sequence
)
12271 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.sequence
== 0)
12273 gfc_error ("Component %s of SEQUENCE type declared at %L does "
12274 "not have the SEQUENCE attribute",
12275 c
->ts
.u
.derived
->name
, &sym
->declared_at
);
12280 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.generic
)
12281 c
->ts
.u
.derived
= gfc_find_dt_in_generic (c
->ts
.u
.derived
);
12282 else if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
12283 && CLASS_DATA (c
)->ts
.u
.derived
->attr
.generic
)
12284 CLASS_DATA (c
)->ts
.u
.derived
12285 = gfc_find_dt_in_generic (CLASS_DATA (c
)->ts
.u
.derived
);
12287 if (!sym
->attr
.is_class
&& c
->ts
.type
== BT_DERIVED
&& !sym
->attr
.vtype
12288 && c
->attr
.pointer
&& c
->ts
.u
.derived
->components
== NULL
12289 && !c
->ts
.u
.derived
->attr
.zero_comp
)
12291 gfc_error ("The pointer component '%s' of '%s' at %L is a type "
12292 "that has not been declared", c
->name
, sym
->name
,
12297 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
12298 && CLASS_DATA (c
)->attr
.class_pointer
12299 && CLASS_DATA (c
)->ts
.u
.derived
->components
== NULL
12300 && !CLASS_DATA (c
)->ts
.u
.derived
->attr
.zero_comp
12301 && !UNLIMITED_POLY (c
))
12303 gfc_error ("The pointer component '%s' of '%s' at %L is a type "
12304 "that has not been declared", c
->name
, sym
->name
,
12310 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.flavor
!= FL_PROCEDURE
12311 && (!c
->attr
.class_ok
12312 || !(CLASS_DATA (c
)->attr
.class_pointer
12313 || CLASS_DATA (c
)->attr
.allocatable
)))
12315 gfc_error ("Component '%s' with CLASS at %L must be allocatable "
12316 "or pointer", c
->name
, &c
->loc
);
12317 /* Prevent a recurrence of the error. */
12318 c
->ts
.type
= BT_UNKNOWN
;
12322 /* Ensure that all the derived type components are put on the
12323 derived type list; even in formal namespaces, where derived type
12324 pointer components might not have been declared. */
12325 if (c
->ts
.type
== BT_DERIVED
12327 && c
->ts
.u
.derived
->components
12329 && sym
!= c
->ts
.u
.derived
)
12330 add_dt_to_dt_list (c
->ts
.u
.derived
);
12332 if (!gfc_resolve_array_spec (c
->as
,
12333 !(c
->attr
.pointer
|| c
->attr
.proc_pointer
12334 || c
->attr
.allocatable
)))
12337 if (c
->initializer
&& !sym
->attr
.vtype
12338 && !gfc_check_assign_symbol (sym
, c
, c
->initializer
))
12342 check_defined_assignments (sym
);
12344 if (!sym
->attr
.defined_assign_comp
&& super_type
)
12345 sym
->attr
.defined_assign_comp
12346 = super_type
->attr
.defined_assign_comp
;
12348 /* If this is a non-ABSTRACT type extending an ABSTRACT one, ensure that
12349 all DEFERRED bindings are overridden. */
12350 if (super_type
&& super_type
->attr
.abstract
&& !sym
->attr
.abstract
12351 && !sym
->attr
.is_class
12352 && !ensure_not_abstract (sym
, super_type
))
12355 /* Add derived type to the derived type list. */
12356 add_dt_to_dt_list (sym
);
12358 /* Check if the type is finalizable. This is done in order to ensure that the
12359 finalization wrapper is generated early enough. */
12360 gfc_is_finalizable (sym
, NULL
);
12366 /* The following procedure does the full resolution of a derived type,
12367 including resolution of all type-bound procedures (if present). In contrast
12368 to 'resolve_fl_derived0' this can only be done after the module has been
12369 parsed completely. */
12372 resolve_fl_derived (gfc_symbol
*sym
)
12374 gfc_symbol
*gen_dt
= NULL
;
12376 if (sym
->attr
.unlimited_polymorphic
)
12379 if (!sym
->attr
.is_class
)
12380 gfc_find_symbol (sym
->name
, sym
->ns
, 0, &gen_dt
);
12381 if (gen_dt
&& gen_dt
->generic
&& gen_dt
->generic
->next
12382 && (!gen_dt
->generic
->sym
->attr
.use_assoc
12383 || gen_dt
->generic
->sym
->module
!= gen_dt
->generic
->next
->sym
->module
)
12384 && !gfc_notify_std (GFC_STD_F2003
, "Generic name '%s' of function "
12385 "'%s' at %L being the same name as derived "
12386 "type at %L", sym
->name
,
12387 gen_dt
->generic
->sym
== sym
12388 ? gen_dt
->generic
->next
->sym
->name
12389 : gen_dt
->generic
->sym
->name
,
12390 gen_dt
->generic
->sym
== sym
12391 ? &gen_dt
->generic
->next
->sym
->declared_at
12392 : &gen_dt
->generic
->sym
->declared_at
,
12393 &sym
->declared_at
))
12396 /* Resolve the finalizer procedures. */
12397 if (!gfc_resolve_finalizers (sym
))
12400 if (sym
->attr
.is_class
&& sym
->ts
.u
.derived
== NULL
)
12402 /* Fix up incomplete CLASS symbols. */
12403 gfc_component
*data
= gfc_find_component (sym
, "_data", true, true);
12404 gfc_component
*vptr
= gfc_find_component (sym
, "_vptr", true, true);
12406 /* Nothing more to do for unlimited polymorphic entities. */
12407 if (data
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
12409 else if (vptr
->ts
.u
.derived
== NULL
)
12411 gfc_symbol
*vtab
= gfc_find_derived_vtab (data
->ts
.u
.derived
);
12413 vptr
->ts
.u
.derived
= vtab
->ts
.u
.derived
;
12417 if (!resolve_fl_derived0 (sym
))
12420 /* Resolve the type-bound procedures. */
12421 if (!resolve_typebound_procedures (sym
))
12429 resolve_fl_namelist (gfc_symbol
*sym
)
12434 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
12436 /* Check again, the check in match only works if NAMELIST comes
12438 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SIZE
)
12440 gfc_error ("Assumed size array '%s' in namelist '%s' at %L is not "
12441 "allowed", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
12445 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SHAPE
12446 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object '%s' "
12447 "with assumed shape in namelist '%s' at %L",
12448 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
12451 if (is_non_constant_shape_array (nl
->sym
)
12452 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object '%s' "
12453 "with nonconstant shape in namelist '%s' at %L",
12454 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
12457 if (nl
->sym
->ts
.type
== BT_CHARACTER
12458 && (nl
->sym
->ts
.u
.cl
->length
== NULL
12459 || !gfc_is_constant_expr (nl
->sym
->ts
.u
.cl
->length
))
12460 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST object '%s' with "
12461 "nonconstant character length in "
12462 "namelist '%s' at %L", nl
->sym
->name
,
12463 sym
->name
, &sym
->declared_at
))
12466 /* FIXME: Once UDDTIO is implemented, the following can be
12468 if (nl
->sym
->ts
.type
== BT_CLASS
)
12470 gfc_error ("NAMELIST object '%s' in namelist '%s' at %L is "
12471 "polymorphic and requires a defined input/output "
12472 "procedure", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
12476 if (nl
->sym
->ts
.type
== BT_DERIVED
12477 && (nl
->sym
->ts
.u
.derived
->attr
.alloc_comp
12478 || nl
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
12480 if (!gfc_notify_std (GFC_STD_F2003
, "NAMELIST object '%s' in "
12481 "namelist '%s' at %L with ALLOCATABLE "
12482 "or POINTER components", nl
->sym
->name
,
12483 sym
->name
, &sym
->declared_at
))
12486 /* FIXME: Once UDDTIO is implemented, the following can be
12488 gfc_error ("NAMELIST object '%s' in namelist '%s' at %L has "
12489 "ALLOCATABLE or POINTER components and thus requires "
12490 "a defined input/output procedure", nl
->sym
->name
,
12491 sym
->name
, &sym
->declared_at
);
12496 /* Reject PRIVATE objects in a PUBLIC namelist. */
12497 if (gfc_check_symbol_access (sym
))
12499 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
12501 if (!nl
->sym
->attr
.use_assoc
12502 && !is_sym_host_assoc (nl
->sym
, sym
->ns
)
12503 && !gfc_check_symbol_access (nl
->sym
))
12505 gfc_error ("NAMELIST object '%s' was declared PRIVATE and "
12506 "cannot be member of PUBLIC namelist '%s' at %L",
12507 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
12511 /* Types with private components that came here by USE-association. */
12512 if (nl
->sym
->ts
.type
== BT_DERIVED
12513 && derived_inaccessible (nl
->sym
->ts
.u
.derived
))
12515 gfc_error ("NAMELIST object '%s' has use-associated PRIVATE "
12516 "components and cannot be member of namelist '%s' at %L",
12517 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
12521 /* Types with private components that are defined in the same module. */
12522 if (nl
->sym
->ts
.type
== BT_DERIVED
12523 && !is_sym_host_assoc (nl
->sym
->ts
.u
.derived
, sym
->ns
)
12524 && nl
->sym
->ts
.u
.derived
->attr
.private_comp
)
12526 gfc_error ("NAMELIST object '%s' has PRIVATE components and "
12527 "cannot be a member of PUBLIC namelist '%s' at %L",
12528 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
12535 /* 14.1.2 A module or internal procedure represent local entities
12536 of the same type as a namelist member and so are not allowed. */
12537 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
12539 if (nl
->sym
->ts
.kind
!= 0 && nl
->sym
->attr
.flavor
== FL_VARIABLE
)
12542 if (nl
->sym
->attr
.function
&& nl
->sym
== nl
->sym
->result
)
12543 if ((nl
->sym
== sym
->ns
->proc_name
)
12545 (sym
->ns
->parent
&& nl
->sym
== sym
->ns
->parent
->proc_name
))
12550 gfc_find_symbol (nl
->sym
->name
, sym
->ns
, 1, &nlsym
);
12551 if (nlsym
&& nlsym
->attr
.flavor
== FL_PROCEDURE
)
12553 gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
12554 "attribute in '%s' at %L", nlsym
->name
,
12555 &sym
->declared_at
);
12565 resolve_fl_parameter (gfc_symbol
*sym
)
12567 /* A parameter array's shape needs to be constant. */
12568 if (sym
->as
!= NULL
12569 && (sym
->as
->type
== AS_DEFERRED
12570 || is_non_constant_shape_array (sym
)))
12572 gfc_error ("Parameter array '%s' at %L cannot be automatic "
12573 "or of deferred shape", sym
->name
, &sym
->declared_at
);
12577 /* Make sure a parameter that has been implicitly typed still
12578 matches the implicit type, since PARAMETER statements can precede
12579 IMPLICIT statements. */
12580 if (sym
->attr
.implicit_type
12581 && !gfc_compare_types (&sym
->ts
, gfc_get_default_type (sym
->name
,
12584 gfc_error ("Implicitly typed PARAMETER '%s' at %L doesn't match a "
12585 "later IMPLICIT type", sym
->name
, &sym
->declared_at
);
12589 /* Make sure the types of derived parameters are consistent. This
12590 type checking is deferred until resolution because the type may
12591 refer to a derived type from the host. */
12592 if (sym
->ts
.type
== BT_DERIVED
12593 && !gfc_compare_types (&sym
->ts
, &sym
->value
->ts
))
12595 gfc_error ("Incompatible derived type in PARAMETER at %L",
12596 &sym
->value
->where
);
12603 /* Do anything necessary to resolve a symbol. Right now, we just
12604 assume that an otherwise unknown symbol is a variable. This sort
12605 of thing commonly happens for symbols in module. */
12608 resolve_symbol (gfc_symbol
*sym
)
12610 int check_constant
, mp_flag
;
12611 gfc_symtree
*symtree
;
12612 gfc_symtree
*this_symtree
;
12615 symbol_attribute class_attr
;
12616 gfc_array_spec
*as
;
12617 bool saved_specification_expr
;
12623 if (sym
->attr
.artificial
)
12626 if (sym
->attr
.unlimited_polymorphic
)
12629 if (sym
->attr
.flavor
== FL_UNKNOWN
12630 || (sym
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.intrinsic
12631 && !sym
->attr
.generic
&& !sym
->attr
.external
12632 && sym
->attr
.if_source
== IFSRC_UNKNOWN
))
12635 /* If we find that a flavorless symbol is an interface in one of the
12636 parent namespaces, find its symtree in this namespace, free the
12637 symbol and set the symtree to point to the interface symbol. */
12638 for (ns
= gfc_current_ns
->parent
; ns
; ns
= ns
->parent
)
12640 symtree
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
12641 if (symtree
&& (symtree
->n
.sym
->generic
||
12642 (symtree
->n
.sym
->attr
.flavor
== FL_PROCEDURE
12643 && sym
->ns
->construct_entities
)))
12645 this_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
12647 gfc_release_symbol (sym
);
12648 symtree
->n
.sym
->refs
++;
12649 this_symtree
->n
.sym
= symtree
->n
.sym
;
12654 /* Otherwise give it a flavor according to such attributes as
12656 if (sym
->attr
.flavor
== FL_UNKNOWN
&& sym
->attr
.external
== 0
12657 && sym
->attr
.intrinsic
== 0)
12658 sym
->attr
.flavor
= FL_VARIABLE
;
12659 else if (sym
->attr
.flavor
== FL_UNKNOWN
)
12661 sym
->attr
.flavor
= FL_PROCEDURE
;
12662 if (sym
->attr
.dimension
)
12663 sym
->attr
.function
= 1;
12667 if (sym
->attr
.external
&& sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.function
)
12668 gfc_add_function (&sym
->attr
, sym
->name
, &sym
->declared_at
);
12670 if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
12671 && !resolve_procedure_interface (sym
))
12674 if (sym
->attr
.is_protected
&& !sym
->attr
.proc_pointer
12675 && (sym
->attr
.procedure
|| sym
->attr
.external
))
12677 if (sym
->attr
.external
)
12678 gfc_error ("PROTECTED attribute conflicts with EXTERNAL attribute "
12679 "at %L", &sym
->declared_at
);
12681 gfc_error ("PROCEDURE attribute conflicts with PROTECTED attribute "
12682 "at %L", &sym
->declared_at
);
12687 if (sym
->attr
.flavor
== FL_DERIVED
&& !resolve_fl_derived (sym
))
12690 /* Symbols that are module procedures with results (functions) have
12691 the types and array specification copied for type checking in
12692 procedures that call them, as well as for saving to a module
12693 file. These symbols can't stand the scrutiny that their results
12695 mp_flag
= (sym
->result
!= NULL
&& sym
->result
!= sym
);
12697 /* Make sure that the intrinsic is consistent with its internal
12698 representation. This needs to be done before assigning a default
12699 type to avoid spurious warnings. */
12700 if (sym
->attr
.flavor
!= FL_MODULE
&& sym
->attr
.intrinsic
12701 && !gfc_resolve_intrinsic (sym
, &sym
->declared_at
))
12704 /* Resolve associate names. */
12706 resolve_assoc_var (sym
, true);
12708 /* Assign default type to symbols that need one and don't have one. */
12709 if (sym
->ts
.type
== BT_UNKNOWN
)
12711 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
)
12713 gfc_set_default_type (sym
, 1, NULL
);
12716 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.external
12717 && !sym
->attr
.function
&& !sym
->attr
.subroutine
12718 && gfc_get_default_type (sym
->name
, sym
->ns
)->type
== BT_UNKNOWN
)
12719 gfc_add_subroutine (&sym
->attr
, sym
->name
, &sym
->declared_at
);
12721 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
12723 /* The specific case of an external procedure should emit an error
12724 in the case that there is no implicit type. */
12726 gfc_set_default_type (sym
, sym
->attr
.external
, NULL
);
12729 /* Result may be in another namespace. */
12730 resolve_symbol (sym
->result
);
12732 if (!sym
->result
->attr
.proc_pointer
)
12734 sym
->ts
= sym
->result
->ts
;
12735 sym
->as
= gfc_copy_array_spec (sym
->result
->as
);
12736 sym
->attr
.dimension
= sym
->result
->attr
.dimension
;
12737 sym
->attr
.pointer
= sym
->result
->attr
.pointer
;
12738 sym
->attr
.allocatable
= sym
->result
->attr
.allocatable
;
12739 sym
->attr
.contiguous
= sym
->result
->attr
.contiguous
;
12744 else if (mp_flag
&& sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
12746 bool saved_specification_expr
= specification_expr
;
12747 specification_expr
= true;
12748 gfc_resolve_array_spec (sym
->result
->as
, false);
12749 specification_expr
= saved_specification_expr
;
12752 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
12754 as
= CLASS_DATA (sym
)->as
;
12755 class_attr
= CLASS_DATA (sym
)->attr
;
12756 class_attr
.pointer
= class_attr
.class_pointer
;
12760 class_attr
= sym
->attr
;
12765 if (sym
->attr
.contiguous
12766 && (!class_attr
.dimension
12767 || (as
->type
!= AS_ASSUMED_SHAPE
&& as
->type
!= AS_ASSUMED_RANK
12768 && !class_attr
.pointer
)))
12770 gfc_error ("'%s' at %L has the CONTIGUOUS attribute but is not an "
12771 "array pointer or an assumed-shape or assumed-rank array",
12772 sym
->name
, &sym
->declared_at
);
12776 /* Assumed size arrays and assumed shape arrays must be dummy
12777 arguments. Array-spec's of implied-shape should have been resolved to
12778 AS_EXPLICIT already. */
12782 gcc_assert (as
->type
!= AS_IMPLIED_SHAPE
);
12783 if (((as
->type
== AS_ASSUMED_SIZE
&& !as
->cp_was_assumed
)
12784 || as
->type
== AS_ASSUMED_SHAPE
)
12785 && !sym
->attr
.dummy
&& !sym
->attr
.select_type_temporary
)
12787 if (as
->type
== AS_ASSUMED_SIZE
)
12788 gfc_error ("Assumed size array at %L must be a dummy argument",
12789 &sym
->declared_at
);
12791 gfc_error ("Assumed shape array at %L must be a dummy argument",
12792 &sym
->declared_at
);
12795 /* TS 29113, C535a. */
12796 if (as
->type
== AS_ASSUMED_RANK
&& !sym
->attr
.dummy
12797 && !sym
->attr
.select_type_temporary
)
12799 gfc_error ("Assumed-rank array at %L must be a dummy argument",
12800 &sym
->declared_at
);
12803 if (as
->type
== AS_ASSUMED_RANK
12804 && (sym
->attr
.codimension
|| sym
->attr
.value
))
12806 gfc_error ("Assumed-rank array at %L may not have the VALUE or "
12807 "CODIMENSION attribute", &sym
->declared_at
);
12812 /* Make sure symbols with known intent or optional are really dummy
12813 variable. Because of ENTRY statement, this has to be deferred
12814 until resolution time. */
12816 if (!sym
->attr
.dummy
12817 && (sym
->attr
.optional
|| sym
->attr
.intent
!= INTENT_UNKNOWN
))
12819 gfc_error ("Symbol at %L is not a DUMMY variable", &sym
->declared_at
);
12823 if (sym
->attr
.value
&& !sym
->attr
.dummy
)
12825 gfc_error ("'%s' at %L cannot have the VALUE attribute because "
12826 "it is not a dummy argument", sym
->name
, &sym
->declared_at
);
12830 if (sym
->attr
.value
&& sym
->ts
.type
== BT_CHARACTER
)
12832 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
12833 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
12835 gfc_error ("Character dummy variable '%s' at %L with VALUE "
12836 "attribute must have constant length",
12837 sym
->name
, &sym
->declared_at
);
12841 if (sym
->ts
.is_c_interop
12842 && mpz_cmp_si (cl
->length
->value
.integer
, 1) != 0)
12844 gfc_error ("C interoperable character dummy variable '%s' at %L "
12845 "with VALUE attribute must have length one",
12846 sym
->name
, &sym
->declared_at
);
12851 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
12852 && sym
->ts
.u
.derived
->attr
.generic
)
12854 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
12855 if (!sym
->ts
.u
.derived
)
12857 gfc_error ("The derived type '%s' at %L is of type '%s', "
12858 "which has not been defined", sym
->name
,
12859 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
12860 sym
->ts
.type
= BT_UNKNOWN
;
12865 /* Use the same constraints as TYPE(*), except for the type check
12866 and that only scalars and assumed-size arrays are permitted. */
12867 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
12869 if (!sym
->attr
.dummy
)
12871 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
12872 "a dummy argument", sym
->name
, &sym
->declared_at
);
12876 if (sym
->ts
.type
!= BT_ASSUMED
&& sym
->ts
.type
!= BT_INTEGER
12877 && sym
->ts
.type
!= BT_REAL
&& sym
->ts
.type
!= BT_LOGICAL
12878 && sym
->ts
.type
!= BT_COMPLEX
)
12880 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
12881 "of type TYPE(*) or of an numeric intrinsic type",
12882 sym
->name
, &sym
->declared_at
);
12886 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
12887 || sym
->attr
.pointer
|| sym
->attr
.value
)
12889 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
12890 "have the ALLOCATABLE, CODIMENSION, POINTER or VALUE "
12891 "attribute", sym
->name
, &sym
->declared_at
);
12895 if (sym
->attr
.intent
== INTENT_OUT
)
12897 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
12898 "have the INTENT(OUT) attribute",
12899 sym
->name
, &sym
->declared_at
);
12902 if (sym
->attr
.dimension
&& sym
->as
->type
!= AS_ASSUMED_SIZE
)
12904 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall "
12905 "either be a scalar or an assumed-size array",
12906 sym
->name
, &sym
->declared_at
);
12910 /* Set the type to TYPE(*) and add a dimension(*) to ensure
12911 NO_ARG_CHECK is correctly handled in trans*.c, e.g. with
12913 sym
->ts
.type
= BT_ASSUMED
;
12914 sym
->as
= gfc_get_array_spec ();
12915 sym
->as
->type
= AS_ASSUMED_SIZE
;
12917 sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
12919 else if (sym
->ts
.type
== BT_ASSUMED
)
12921 /* TS 29113, C407a. */
12922 if (!sym
->attr
.dummy
)
12924 gfc_error ("Assumed type of variable %s at %L is only permitted "
12925 "for dummy variables", sym
->name
, &sym
->declared_at
);
12928 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
12929 || sym
->attr
.pointer
|| sym
->attr
.value
)
12931 gfc_error ("Assumed-type variable %s at %L may not have the "
12932 "ALLOCATABLE, CODIMENSION, POINTER or VALUE attribute",
12933 sym
->name
, &sym
->declared_at
);
12936 if (sym
->attr
.intent
== INTENT_OUT
)
12938 gfc_error ("Assumed-type variable %s at %L may not have the "
12939 "INTENT(OUT) attribute",
12940 sym
->name
, &sym
->declared_at
);
12943 if (sym
->attr
.dimension
&& sym
->as
->type
== AS_EXPLICIT
)
12945 gfc_error ("Assumed-type variable %s at %L shall not be an "
12946 "explicit-shape array", sym
->name
, &sym
->declared_at
);
12951 /* If the symbol is marked as bind(c), verify it's type and kind. Do not
12952 do this for something that was implicitly typed because that is handled
12953 in gfc_set_default_type. Handle dummy arguments and procedure
12954 definitions separately. Also, anything that is use associated is not
12955 handled here but instead is handled in the module it is declared in.
12956 Finally, derived type definitions are allowed to be BIND(C) since that
12957 only implies that they're interoperable, and they are checked fully for
12958 interoperability when a variable is declared of that type. */
12959 if (sym
->attr
.is_bind_c
&& sym
->attr
.implicit_type
== 0 &&
12960 sym
->attr
.use_assoc
== 0 && sym
->attr
.dummy
== 0 &&
12961 sym
->attr
.flavor
!= FL_PROCEDURE
&& sym
->attr
.flavor
!= FL_DERIVED
)
12965 /* First, make sure the variable is declared at the
12966 module-level scope (J3/04-007, Section 15.3). */
12967 if (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
&&
12968 sym
->attr
.in_common
== 0)
12970 gfc_error ("Variable '%s' at %L cannot be BIND(C) because it "
12971 "is neither a COMMON block nor declared at the "
12972 "module level scope", sym
->name
, &(sym
->declared_at
));
12975 else if (sym
->common_head
!= NULL
)
12977 t
= verify_com_block_vars_c_interop (sym
->common_head
);
12981 /* If type() declaration, we need to verify that the components
12982 of the given type are all C interoperable, etc. */
12983 if (sym
->ts
.type
== BT_DERIVED
&&
12984 sym
->ts
.u
.derived
->attr
.is_c_interop
!= 1)
12986 /* Make sure the user marked the derived type as BIND(C). If
12987 not, call the verify routine. This could print an error
12988 for the derived type more than once if multiple variables
12989 of that type are declared. */
12990 if (sym
->ts
.u
.derived
->attr
.is_bind_c
!= 1)
12991 verify_bind_c_derived_type (sym
->ts
.u
.derived
);
12995 /* Verify the variable itself as C interoperable if it
12996 is BIND(C). It is not possible for this to succeed if
12997 the verify_bind_c_derived_type failed, so don't have to handle
12998 any error returned by verify_bind_c_derived_type. */
12999 t
= verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
13000 sym
->common_block
);
13005 /* clear the is_bind_c flag to prevent reporting errors more than
13006 once if something failed. */
13007 sym
->attr
.is_bind_c
= 0;
13012 /* If a derived type symbol has reached this point, without its
13013 type being declared, we have an error. Notice that most
13014 conditions that produce undefined derived types have already
13015 been dealt with. However, the likes of:
13016 implicit type(t) (t) ..... call foo (t) will get us here if
13017 the type is not declared in the scope of the implicit
13018 statement. Change the type to BT_UNKNOWN, both because it is so
13019 and to prevent an ICE. */
13020 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
13021 && sym
->ts
.u
.derived
->components
== NULL
13022 && !sym
->ts
.u
.derived
->attr
.zero_comp
)
13024 gfc_error ("The derived type '%s' at %L is of type '%s', "
13025 "which has not been defined", sym
->name
,
13026 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
13027 sym
->ts
.type
= BT_UNKNOWN
;
13031 /* Make sure that the derived type has been resolved and that the
13032 derived type is visible in the symbol's namespace, if it is a
13033 module function and is not PRIVATE. */
13034 if (sym
->ts
.type
== BT_DERIVED
13035 && sym
->ts
.u
.derived
->attr
.use_assoc
13036 && sym
->ns
->proc_name
13037 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
13038 && !resolve_fl_derived (sym
->ts
.u
.derived
))
13041 /* Unless the derived-type declaration is use associated, Fortran 95
13042 does not allow public entries of private derived types.
13043 See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
13044 161 in 95-006r3. */
13045 if (sym
->ts
.type
== BT_DERIVED
13046 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
13047 && !sym
->ts
.u
.derived
->attr
.use_assoc
13048 && gfc_check_symbol_access (sym
)
13049 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
13050 && !gfc_notify_std (GFC_STD_F2003
, "PUBLIC %s '%s' at %L of PRIVATE "
13051 "derived type '%s'",
13052 (sym
->attr
.flavor
== FL_PARAMETER
)
13053 ? "parameter" : "variable",
13054 sym
->name
, &sym
->declared_at
,
13055 sym
->ts
.u
.derived
->name
))
13058 /* F2008, C1302. */
13059 if (sym
->ts
.type
== BT_DERIVED
13060 && ((sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
13061 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
13062 || sym
->ts
.u
.derived
->attr
.lock_comp
)
13063 && !sym
->attr
.codimension
&& !sym
->ts
.u
.derived
->attr
.coarray_comp
)
13065 gfc_error ("Variable %s at %L of type LOCK_TYPE or with subcomponent of "
13066 "type LOCK_TYPE must be a coarray", sym
->name
,
13067 &sym
->declared_at
);
13071 /* An assumed-size array with INTENT(OUT) shall not be of a type for which
13072 default initialization is defined (5.1.2.4.4). */
13073 if (sym
->ts
.type
== BT_DERIVED
13075 && sym
->attr
.intent
== INTENT_OUT
13077 && sym
->as
->type
== AS_ASSUMED_SIZE
)
13079 for (c
= sym
->ts
.u
.derived
->components
; c
; c
= c
->next
)
13081 if (c
->initializer
)
13083 gfc_error ("The INTENT(OUT) dummy argument '%s' at %L is "
13084 "ASSUMED SIZE and so cannot have a default initializer",
13085 sym
->name
, &sym
->declared_at
);
13092 if (sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.dummy
13093 && sym
->attr
.intent
== INTENT_OUT
&& sym
->attr
.lock_comp
)
13095 gfc_error ("Dummy argument '%s' at %L of LOCK_TYPE shall not be "
13096 "INTENT(OUT)", sym
->name
, &sym
->declared_at
);
13101 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
13102 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
13103 && CLASS_DATA (sym
)->attr
.coarray_comp
))
13104 || class_attr
.codimension
)
13105 && (sym
->attr
.result
|| sym
->result
== sym
))
13107 gfc_error ("Function result '%s' at %L shall not be a coarray or have "
13108 "a coarray component", sym
->name
, &sym
->declared_at
);
13113 if (sym
->attr
.codimension
&& sym
->ts
.type
== BT_DERIVED
13114 && sym
->ts
.u
.derived
->ts
.is_iso_c
)
13116 gfc_error ("Variable '%s' at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
13117 "shall not be a coarray", sym
->name
, &sym
->declared_at
);
13122 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
13123 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
13124 && CLASS_DATA (sym
)->attr
.coarray_comp
))
13125 && (class_attr
.codimension
|| class_attr
.pointer
|| class_attr
.dimension
13126 || class_attr
.allocatable
))
13128 gfc_error ("Variable '%s' at %L with coarray component shall be a "
13129 "nonpointer, nonallocatable scalar, which is not a coarray",
13130 sym
->name
, &sym
->declared_at
);
13134 /* F2008, C526. The function-result case was handled above. */
13135 if (class_attr
.codimension
13136 && !(class_attr
.allocatable
|| sym
->attr
.dummy
|| sym
->attr
.save
13137 || sym
->attr
.select_type_temporary
13138 || sym
->ns
->save_all
13139 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
13140 || sym
->ns
->proc_name
->attr
.is_main_program
13141 || sym
->attr
.function
|| sym
->attr
.result
|| sym
->attr
.use_assoc
))
13143 gfc_error ("Variable '%s' at %L is a coarray and is not ALLOCATABLE, SAVE "
13144 "nor a dummy argument", sym
->name
, &sym
->declared_at
);
13148 else if (class_attr
.codimension
&& !sym
->attr
.select_type_temporary
13149 && !class_attr
.allocatable
&& as
&& as
->cotype
== AS_DEFERRED
)
13151 gfc_error ("Coarray variable '%s' at %L shall not have codimensions with "
13152 "deferred shape", sym
->name
, &sym
->declared_at
);
13155 else if (class_attr
.codimension
&& class_attr
.allocatable
&& as
13156 && (as
->cotype
!= AS_DEFERRED
|| as
->type
!= AS_DEFERRED
))
13158 gfc_error ("Allocatable coarray variable '%s' at %L must have "
13159 "deferred shape", sym
->name
, &sym
->declared_at
);
13164 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
13165 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
13166 && CLASS_DATA (sym
)->attr
.coarray_comp
))
13167 || (class_attr
.codimension
&& class_attr
.allocatable
))
13168 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
)
13170 gfc_error ("Variable '%s' at %L is INTENT(OUT) and can thus not be an "
13171 "allocatable coarray or have coarray components",
13172 sym
->name
, &sym
->declared_at
);
13176 if (class_attr
.codimension
&& sym
->attr
.dummy
13177 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.is_bind_c
)
13179 gfc_error ("Coarray dummy variable '%s' at %L not allowed in BIND(C) "
13180 "procedure '%s'", sym
->name
, &sym
->declared_at
,
13181 sym
->ns
->proc_name
->name
);
13185 if (sym
->ts
.type
== BT_LOGICAL
13186 && ((sym
->attr
.function
&& sym
->attr
.is_bind_c
&& sym
->result
== sym
)
13187 || ((sym
->attr
.dummy
|| sym
->attr
.result
) && sym
->ns
->proc_name
13188 && sym
->ns
->proc_name
->attr
.is_bind_c
)))
13191 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
13192 if (gfc_logical_kinds
[i
].kind
== sym
->ts
.kind
)
13194 if (!gfc_logical_kinds
[i
].c_bool
&& sym
->attr
.dummy
13195 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL dummy argument '%s' at "
13196 "%L with non-C_Bool kind in BIND(C) procedure "
13197 "'%s'", sym
->name
, &sym
->declared_at
,
13198 sym
->ns
->proc_name
->name
))
13200 else if (!gfc_logical_kinds
[i
].c_bool
13201 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL result variable "
13202 "'%s' at %L with non-C_Bool kind in "
13203 "BIND(C) procedure '%s'", sym
->name
,
13205 sym
->attr
.function
? sym
->name
13206 : sym
->ns
->proc_name
->name
))
13210 switch (sym
->attr
.flavor
)
13213 if (!resolve_fl_variable (sym
, mp_flag
))
13218 if (!resolve_fl_procedure (sym
, mp_flag
))
13223 if (!resolve_fl_namelist (sym
))
13228 if (!resolve_fl_parameter (sym
))
13236 /* Resolve array specifier. Check as well some constraints
13237 on COMMON blocks. */
13239 check_constant
= sym
->attr
.in_common
&& !sym
->attr
.pointer
;
13241 /* Set the formal_arg_flag so that check_conflict will not throw
13242 an error for host associated variables in the specification
13243 expression for an array_valued function. */
13244 if (sym
->attr
.function
&& sym
->as
)
13245 formal_arg_flag
= 1;
13247 saved_specification_expr
= specification_expr
;
13248 specification_expr
= true;
13249 gfc_resolve_array_spec (sym
->as
, check_constant
);
13250 specification_expr
= saved_specification_expr
;
13252 formal_arg_flag
= 0;
13254 /* Resolve formal namespaces. */
13255 if (sym
->formal_ns
&& sym
->formal_ns
!= gfc_current_ns
13256 && !sym
->attr
.contained
&& !sym
->attr
.intrinsic
)
13257 gfc_resolve (sym
->formal_ns
);
13259 /* Make sure the formal namespace is present. */
13260 if (sym
->formal
&& !sym
->formal_ns
)
13262 gfc_formal_arglist
*formal
= sym
->formal
;
13263 while (formal
&& !formal
->sym
)
13264 formal
= formal
->next
;
13268 sym
->formal_ns
= formal
->sym
->ns
;
13269 if (sym
->ns
!= formal
->sym
->ns
)
13270 sym
->formal_ns
->refs
++;
13274 /* Check threadprivate restrictions. */
13275 if (sym
->attr
.threadprivate
&& !sym
->attr
.save
&& !sym
->ns
->save_all
13276 && (!sym
->attr
.in_common
13277 && sym
->module
== NULL
13278 && (sym
->ns
->proc_name
== NULL
13279 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
13280 gfc_error ("Threadprivate at %L isn't SAVEd", &sym
->declared_at
);
13282 /* If we have come this far we can apply default-initializers, as
13283 described in 14.7.5, to those variables that have not already
13284 been assigned one. */
13285 if (sym
->ts
.type
== BT_DERIVED
13287 && !sym
->attr
.allocatable
13288 && !sym
->attr
.alloc_comp
)
13290 symbol_attribute
*a
= &sym
->attr
;
13292 if ((!a
->save
&& !a
->dummy
&& !a
->pointer
13293 && !a
->in_common
&& !a
->use_assoc
13294 && (a
->referenced
|| a
->result
)
13295 && !(a
->function
&& sym
!= sym
->result
))
13296 || (a
->dummy
&& a
->intent
== INTENT_OUT
&& !a
->pointer
))
13297 apply_default_init (sym
);
13300 if (sym
->ts
.type
== BT_CLASS
&& sym
->ns
== gfc_current_ns
13301 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
13302 && !CLASS_DATA (sym
)->attr
.class_pointer
13303 && !CLASS_DATA (sym
)->attr
.allocatable
)
13304 apply_default_init (sym
);
13306 /* If this symbol has a type-spec, check it. */
13307 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
13308 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
))
13309 if (!resolve_typespec_used (&sym
->ts
, &sym
->declared_at
, sym
->name
))
13314 /************* Resolve DATA statements *************/
13318 gfc_data_value
*vnode
;
13324 /* Advance the values structure to point to the next value in the data list. */
13327 next_data_value (void)
13329 while (mpz_cmp_ui (values
.left
, 0) == 0)
13332 if (values
.vnode
->next
== NULL
)
13335 values
.vnode
= values
.vnode
->next
;
13336 mpz_set (values
.left
, values
.vnode
->repeat
);
13344 check_data_variable (gfc_data_variable
*var
, locus
*where
)
13350 ar_type mark
= AR_UNKNOWN
;
13352 mpz_t section_index
[GFC_MAX_DIMENSIONS
];
13358 if (!gfc_resolve_expr (var
->expr
))
13362 mpz_init_set_si (offset
, 0);
13365 if (e
->expr_type
!= EXPR_VARIABLE
)
13366 gfc_internal_error ("check_data_variable(): Bad expression");
13368 sym
= e
->symtree
->n
.sym
;
13370 if (sym
->ns
->is_block_data
&& !sym
->attr
.in_common
)
13372 gfc_error ("BLOCK DATA element '%s' at %L must be in COMMON",
13373 sym
->name
, &sym
->declared_at
);
13376 if (e
->ref
== NULL
&& sym
->as
)
13378 gfc_error ("DATA array '%s' at %L must be specified in a previous"
13379 " declaration", sym
->name
, where
);
13383 has_pointer
= sym
->attr
.pointer
;
13385 if (gfc_is_coindexed (e
))
13387 gfc_error ("DATA element '%s' at %L cannot have a coindex", sym
->name
,
13392 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
13394 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.pointer
)
13398 && ref
->type
== REF_ARRAY
13399 && ref
->u
.ar
.type
!= AR_FULL
)
13401 gfc_error ("DATA element '%s' at %L is a pointer and so must "
13402 "be a full array", sym
->name
, where
);
13407 if (e
->rank
== 0 || has_pointer
)
13409 mpz_init_set_ui (size
, 1);
13416 /* Find the array section reference. */
13417 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
13419 if (ref
->type
!= REF_ARRAY
)
13421 if (ref
->u
.ar
.type
== AR_ELEMENT
)
13427 /* Set marks according to the reference pattern. */
13428 switch (ref
->u
.ar
.type
)
13436 /* Get the start position of array section. */
13437 gfc_get_section_index (ar
, section_index
, &offset
);
13442 gcc_unreachable ();
13445 if (!gfc_array_size (e
, &size
))
13447 gfc_error ("Nonconstant array section at %L in DATA statement",
13449 mpz_clear (offset
);
13456 while (mpz_cmp_ui (size
, 0) > 0)
13458 if (!next_data_value ())
13460 gfc_error ("DATA statement at %L has more variables than values",
13466 t
= gfc_check_assign (var
->expr
, values
.vnode
->expr
, 0);
13470 /* If we have more than one element left in the repeat count,
13471 and we have more than one element left in the target variable,
13472 then create a range assignment. */
13473 /* FIXME: Only done for full arrays for now, since array sections
13475 if (mark
== AR_FULL
&& ref
&& ref
->next
== NULL
13476 && mpz_cmp_ui (values
.left
, 1) > 0 && mpz_cmp_ui (size
, 1) > 0)
13480 if (mpz_cmp (size
, values
.left
) >= 0)
13482 mpz_init_set (range
, values
.left
);
13483 mpz_sub (size
, size
, values
.left
);
13484 mpz_set_ui (values
.left
, 0);
13488 mpz_init_set (range
, size
);
13489 mpz_sub (values
.left
, values
.left
, size
);
13490 mpz_set_ui (size
, 0);
13493 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
13496 mpz_add (offset
, offset
, range
);
13503 /* Assign initial value to symbol. */
13506 mpz_sub_ui (values
.left
, values
.left
, 1);
13507 mpz_sub_ui (size
, size
, 1);
13509 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
13514 if (mark
== AR_FULL
)
13515 mpz_add_ui (offset
, offset
, 1);
13517 /* Modify the array section indexes and recalculate the offset
13518 for next element. */
13519 else if (mark
== AR_SECTION
)
13520 gfc_advance_section (section_index
, ar
, &offset
);
13524 if (mark
== AR_SECTION
)
13526 for (i
= 0; i
< ar
->dimen
; i
++)
13527 mpz_clear (section_index
[i
]);
13531 mpz_clear (offset
);
13537 static bool traverse_data_var (gfc_data_variable
*, locus
*);
13539 /* Iterate over a list of elements in a DATA statement. */
13542 traverse_data_list (gfc_data_variable
*var
, locus
*where
)
13545 iterator_stack frame
;
13546 gfc_expr
*e
, *start
, *end
, *step
;
13547 bool retval
= true;
13549 mpz_init (frame
.value
);
13552 start
= gfc_copy_expr (var
->iter
.start
);
13553 end
= gfc_copy_expr (var
->iter
.end
);
13554 step
= gfc_copy_expr (var
->iter
.step
);
13556 if (!gfc_simplify_expr (start
, 1)
13557 || start
->expr_type
!= EXPR_CONSTANT
)
13559 gfc_error ("start of implied-do loop at %L could not be "
13560 "simplified to a constant value", &start
->where
);
13564 if (!gfc_simplify_expr (end
, 1)
13565 || end
->expr_type
!= EXPR_CONSTANT
)
13567 gfc_error ("end of implied-do loop at %L could not be "
13568 "simplified to a constant value", &start
->where
);
13572 if (!gfc_simplify_expr (step
, 1)
13573 || step
->expr_type
!= EXPR_CONSTANT
)
13575 gfc_error ("step of implied-do loop at %L could not be "
13576 "simplified to a constant value", &start
->where
);
13581 mpz_set (trip
, end
->value
.integer
);
13582 mpz_sub (trip
, trip
, start
->value
.integer
);
13583 mpz_add (trip
, trip
, step
->value
.integer
);
13585 mpz_div (trip
, trip
, step
->value
.integer
);
13587 mpz_set (frame
.value
, start
->value
.integer
);
13589 frame
.prev
= iter_stack
;
13590 frame
.variable
= var
->iter
.var
->symtree
;
13591 iter_stack
= &frame
;
13593 while (mpz_cmp_ui (trip
, 0) > 0)
13595 if (!traverse_data_var (var
->list
, where
))
13601 e
= gfc_copy_expr (var
->expr
);
13602 if (!gfc_simplify_expr (e
, 1))
13609 mpz_add (frame
.value
, frame
.value
, step
->value
.integer
);
13611 mpz_sub_ui (trip
, trip
, 1);
13615 mpz_clear (frame
.value
);
13618 gfc_free_expr (start
);
13619 gfc_free_expr (end
);
13620 gfc_free_expr (step
);
13622 iter_stack
= frame
.prev
;
13627 /* Type resolve variables in the variable list of a DATA statement. */
13630 traverse_data_var (gfc_data_variable
*var
, locus
*where
)
13634 for (; var
; var
= var
->next
)
13636 if (var
->expr
== NULL
)
13637 t
= traverse_data_list (var
, where
);
13639 t
= check_data_variable (var
, where
);
13649 /* Resolve the expressions and iterators associated with a data statement.
13650 This is separate from the assignment checking because data lists should
13651 only be resolved once. */
13654 resolve_data_variables (gfc_data_variable
*d
)
13656 for (; d
; d
= d
->next
)
13658 if (d
->list
== NULL
)
13660 if (!gfc_resolve_expr (d
->expr
))
13665 if (!gfc_resolve_iterator (&d
->iter
, false, true))
13668 if (!resolve_data_variables (d
->list
))
13677 /* Resolve a single DATA statement. We implement this by storing a pointer to
13678 the value list into static variables, and then recursively traversing the
13679 variables list, expanding iterators and such. */
13682 resolve_data (gfc_data
*d
)
13685 if (!resolve_data_variables (d
->var
))
13688 values
.vnode
= d
->value
;
13689 if (d
->value
== NULL
)
13690 mpz_set_ui (values
.left
, 0);
13692 mpz_set (values
.left
, d
->value
->repeat
);
13694 if (!traverse_data_var (d
->var
, &d
->where
))
13697 /* At this point, we better not have any values left. */
13699 if (next_data_value ())
13700 gfc_error ("DATA statement at %L has more values than variables",
13705 /* 12.6 Constraint: In a pure subprogram any variable which is in common or
13706 accessed by host or use association, is a dummy argument to a pure function,
13707 is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
13708 is storage associated with any such variable, shall not be used in the
13709 following contexts: (clients of this function). */
13711 /* Determines if a variable is not 'pure', i.e., not assignable within a pure
13712 procedure. Returns zero if assignment is OK, nonzero if there is a
13715 gfc_impure_variable (gfc_symbol
*sym
)
13720 if (sym
->attr
.use_assoc
|| sym
->attr
.in_common
)
13723 /* Check if the symbol's ns is inside the pure procedure. */
13724 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
13728 if (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
13732 proc
= sym
->ns
->proc_name
;
13733 if (sym
->attr
.dummy
13734 && ((proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_IN
)
13735 || proc
->attr
.function
))
13738 /* TODO: Sort out what can be storage associated, if anything, and include
13739 it here. In principle equivalences should be scanned but it does not
13740 seem to be possible to storage associate an impure variable this way. */
13745 /* Test whether a symbol is pure or not. For a NULL pointer, checks if the
13746 current namespace is inside a pure procedure. */
13749 gfc_pure (gfc_symbol
*sym
)
13751 symbol_attribute attr
;
13756 /* Check if the current namespace or one of its parents
13757 belongs to a pure procedure. */
13758 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
13760 sym
= ns
->proc_name
;
13764 if (attr
.flavor
== FL_PROCEDURE
&& attr
.pure
)
13772 return attr
.flavor
== FL_PROCEDURE
&& attr
.pure
;
13776 /* Test whether a symbol is implicitly pure or not. For a NULL pointer,
13777 checks if the current namespace is implicitly pure. Note that this
13778 function returns false for a PURE procedure. */
13781 gfc_implicit_pure (gfc_symbol
*sym
)
13787 /* Check if the current procedure is implicit_pure. Walk up
13788 the procedure list until we find a procedure. */
13789 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
13791 sym
= ns
->proc_name
;
13795 if (sym
->attr
.flavor
== FL_PROCEDURE
)
13800 return sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.implicit_pure
13801 && !sym
->attr
.pure
;
13805 /* Test whether the current procedure is elemental or not. */
13808 gfc_elemental (gfc_symbol
*sym
)
13810 symbol_attribute attr
;
13813 sym
= gfc_current_ns
->proc_name
;
13818 return attr
.flavor
== FL_PROCEDURE
&& attr
.elemental
;
13822 /* Warn about unused labels. */
13825 warn_unused_fortran_label (gfc_st_label
*label
)
13830 warn_unused_fortran_label (label
->left
);
13832 if (label
->defined
== ST_LABEL_UNKNOWN
)
13835 switch (label
->referenced
)
13837 case ST_LABEL_UNKNOWN
:
13838 gfc_warning ("Label %d at %L defined but not used", label
->value
,
13842 case ST_LABEL_BAD_TARGET
:
13843 gfc_warning ("Label %d at %L defined but cannot be used",
13844 label
->value
, &label
->where
);
13851 warn_unused_fortran_label (label
->right
);
13855 /* Returns the sequence type of a symbol or sequence. */
13858 sequence_type (gfc_typespec ts
)
13867 if (ts
.u
.derived
->components
== NULL
)
13868 return SEQ_NONDEFAULT
;
13870 result
= sequence_type (ts
.u
.derived
->components
->ts
);
13871 for (c
= ts
.u
.derived
->components
->next
; c
; c
= c
->next
)
13872 if (sequence_type (c
->ts
) != result
)
13878 if (ts
.kind
!= gfc_default_character_kind
)
13879 return SEQ_NONDEFAULT
;
13881 return SEQ_CHARACTER
;
13884 if (ts
.kind
!= gfc_default_integer_kind
)
13885 return SEQ_NONDEFAULT
;
13887 return SEQ_NUMERIC
;
13890 if (!(ts
.kind
== gfc_default_real_kind
13891 || ts
.kind
== gfc_default_double_kind
))
13892 return SEQ_NONDEFAULT
;
13894 return SEQ_NUMERIC
;
13897 if (ts
.kind
!= gfc_default_complex_kind
)
13898 return SEQ_NONDEFAULT
;
13900 return SEQ_NUMERIC
;
13903 if (ts
.kind
!= gfc_default_logical_kind
)
13904 return SEQ_NONDEFAULT
;
13906 return SEQ_NUMERIC
;
13909 return SEQ_NONDEFAULT
;
13914 /* Resolve derived type EQUIVALENCE object. */
13917 resolve_equivalence_derived (gfc_symbol
*derived
, gfc_symbol
*sym
, gfc_expr
*e
)
13919 gfc_component
*c
= derived
->components
;
13924 /* Shall not be an object of nonsequence derived type. */
13925 if (!derived
->attr
.sequence
)
13927 gfc_error ("Derived type variable '%s' at %L must have SEQUENCE "
13928 "attribute to be an EQUIVALENCE object", sym
->name
,
13933 /* Shall not have allocatable components. */
13934 if (derived
->attr
.alloc_comp
)
13936 gfc_error ("Derived type variable '%s' at %L cannot have ALLOCATABLE "
13937 "components to be an EQUIVALENCE object",sym
->name
,
13942 if (sym
->attr
.in_common
&& gfc_has_default_initializer (sym
->ts
.u
.derived
))
13944 gfc_error ("Derived type variable '%s' at %L with default "
13945 "initialization cannot be in EQUIVALENCE with a variable "
13946 "in COMMON", sym
->name
, &e
->where
);
13950 for (; c
; c
= c
->next
)
13952 if (c
->ts
.type
== BT_DERIVED
13953 && (!resolve_equivalence_derived(c
->ts
.u
.derived
, sym
, e
)))
13956 /* Shall not be an object of sequence derived type containing a pointer
13957 in the structure. */
13958 if (c
->attr
.pointer
)
13960 gfc_error ("Derived type variable '%s' at %L with pointer "
13961 "component(s) cannot be an EQUIVALENCE object",
13962 sym
->name
, &e
->where
);
13970 /* Resolve equivalence object.
13971 An EQUIVALENCE object shall not be a dummy argument, a pointer, a target,
13972 an allocatable array, an object of nonsequence derived type, an object of
13973 sequence derived type containing a pointer at any level of component
13974 selection, an automatic object, a function name, an entry name, a result
13975 name, a named constant, a structure component, or a subobject of any of
13976 the preceding objects. A substring shall not have length zero. A
13977 derived type shall not have components with default initialization nor
13978 shall two objects of an equivalence group be initialized.
13979 Either all or none of the objects shall have an protected attribute.
13980 The simple constraints are done in symbol.c(check_conflict) and the rest
13981 are implemented here. */
13984 resolve_equivalence (gfc_equiv
*eq
)
13987 gfc_symbol
*first_sym
;
13990 locus
*last_where
= NULL
;
13991 seq_type eq_type
, last_eq_type
;
13992 gfc_typespec
*last_ts
;
13993 int object
, cnt_protected
;
13996 last_ts
= &eq
->expr
->symtree
->n
.sym
->ts
;
13998 first_sym
= eq
->expr
->symtree
->n
.sym
;
14002 for (object
= 1; eq
; eq
= eq
->eq
, object
++)
14006 e
->ts
= e
->symtree
->n
.sym
->ts
;
14007 /* match_varspec might not know yet if it is seeing
14008 array reference or substring reference, as it doesn't
14010 if (e
->ref
&& e
->ref
->type
== REF_ARRAY
)
14012 gfc_ref
*ref
= e
->ref
;
14013 sym
= e
->symtree
->n
.sym
;
14015 if (sym
->attr
.dimension
)
14017 ref
->u
.ar
.as
= sym
->as
;
14021 /* For substrings, convert REF_ARRAY into REF_SUBSTRING. */
14022 if (e
->ts
.type
== BT_CHARACTER
14024 && ref
->type
== REF_ARRAY
14025 && ref
->u
.ar
.dimen
== 1
14026 && ref
->u
.ar
.dimen_type
[0] == DIMEN_RANGE
14027 && ref
->u
.ar
.stride
[0] == NULL
)
14029 gfc_expr
*start
= ref
->u
.ar
.start
[0];
14030 gfc_expr
*end
= ref
->u
.ar
.end
[0];
14033 /* Optimize away the (:) reference. */
14034 if (start
== NULL
&& end
== NULL
)
14037 e
->ref
= ref
->next
;
14039 e
->ref
->next
= ref
->next
;
14044 ref
->type
= REF_SUBSTRING
;
14046 start
= gfc_get_int_expr (gfc_default_integer_kind
,
14048 ref
->u
.ss
.start
= start
;
14049 if (end
== NULL
&& e
->ts
.u
.cl
)
14050 end
= gfc_copy_expr (e
->ts
.u
.cl
->length
);
14051 ref
->u
.ss
.end
= end
;
14052 ref
->u
.ss
.length
= e
->ts
.u
.cl
;
14059 /* Any further ref is an error. */
14062 gcc_assert (ref
->type
== REF_ARRAY
);
14063 gfc_error ("Syntax error in EQUIVALENCE statement at %L",
14069 if (!gfc_resolve_expr (e
))
14072 sym
= e
->symtree
->n
.sym
;
14074 if (sym
->attr
.is_protected
)
14076 if (cnt_protected
> 0 && cnt_protected
!= object
)
14078 gfc_error ("Either all or none of the objects in the "
14079 "EQUIVALENCE set at %L shall have the "
14080 "PROTECTED attribute",
14085 /* Shall not equivalence common block variables in a PURE procedure. */
14086 if (sym
->ns
->proc_name
14087 && sym
->ns
->proc_name
->attr
.pure
14088 && sym
->attr
.in_common
)
14090 gfc_error ("Common block member '%s' at %L cannot be an EQUIVALENCE "
14091 "object in the pure procedure '%s'",
14092 sym
->name
, &e
->where
, sym
->ns
->proc_name
->name
);
14096 /* Shall not be a named constant. */
14097 if (e
->expr_type
== EXPR_CONSTANT
)
14099 gfc_error ("Named constant '%s' at %L cannot be an EQUIVALENCE "
14100 "object", sym
->name
, &e
->where
);
14104 if (e
->ts
.type
== BT_DERIVED
14105 && !resolve_equivalence_derived (e
->ts
.u
.derived
, sym
, e
))
14108 /* Check that the types correspond correctly:
14110 A numeric sequence structure may be equivalenced to another sequence
14111 structure, an object of default integer type, default real type, double
14112 precision real type, default logical type such that components of the
14113 structure ultimately only become associated to objects of the same
14114 kind. A character sequence structure may be equivalenced to an object
14115 of default character kind or another character sequence structure.
14116 Other objects may be equivalenced only to objects of the same type and
14117 kind parameters. */
14119 /* Identical types are unconditionally OK. */
14120 if (object
== 1 || gfc_compare_types (last_ts
, &sym
->ts
))
14121 goto identical_types
;
14123 last_eq_type
= sequence_type (*last_ts
);
14124 eq_type
= sequence_type (sym
->ts
);
14126 /* Since the pair of objects is not of the same type, mixed or
14127 non-default sequences can be rejected. */
14129 msg
= "Sequence %s with mixed components in EQUIVALENCE "
14130 "statement at %L with different type objects";
14132 && last_eq_type
== SEQ_MIXED
14133 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
14134 || (eq_type
== SEQ_MIXED
14135 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
14138 msg
= "Non-default type object or sequence %s in EQUIVALENCE "
14139 "statement at %L with objects of different type";
14141 && last_eq_type
== SEQ_NONDEFAULT
14142 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
14143 || (eq_type
== SEQ_NONDEFAULT
14144 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
14147 msg
="Non-CHARACTER object '%s' in default CHARACTER "
14148 "EQUIVALENCE statement at %L";
14149 if (last_eq_type
== SEQ_CHARACTER
14150 && eq_type
!= SEQ_CHARACTER
14151 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
14154 msg
="Non-NUMERIC object '%s' in default NUMERIC "
14155 "EQUIVALENCE statement at %L";
14156 if (last_eq_type
== SEQ_NUMERIC
14157 && eq_type
!= SEQ_NUMERIC
14158 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
14163 last_where
= &e
->where
;
14168 /* Shall not be an automatic array. */
14169 if (e
->ref
->type
== REF_ARRAY
14170 && !gfc_resolve_array_spec (e
->ref
->u
.ar
.as
, 1))
14172 gfc_error ("Array '%s' at %L with non-constant bounds cannot be "
14173 "an EQUIVALENCE object", sym
->name
, &e
->where
);
14180 /* Shall not be a structure component. */
14181 if (r
->type
== REF_COMPONENT
)
14183 gfc_error ("Structure component '%s' at %L cannot be an "
14184 "EQUIVALENCE object",
14185 r
->u
.c
.component
->name
, &e
->where
);
14189 /* A substring shall not have length zero. */
14190 if (r
->type
== REF_SUBSTRING
)
14192 if (compare_bound (r
->u
.ss
.start
, r
->u
.ss
.end
) == CMP_GT
)
14194 gfc_error ("Substring at %L has length zero",
14195 &r
->u
.ss
.start
->where
);
14205 /* Resolve function and ENTRY types, issue diagnostics if needed. */
14208 resolve_fntype (gfc_namespace
*ns
)
14210 gfc_entry_list
*el
;
14213 if (ns
->proc_name
== NULL
|| !ns
->proc_name
->attr
.function
)
14216 /* If there are any entries, ns->proc_name is the entry master
14217 synthetic symbol and ns->entries->sym actual FUNCTION symbol. */
14219 sym
= ns
->entries
->sym
;
14221 sym
= ns
->proc_name
;
14222 if (sym
->result
== sym
14223 && sym
->ts
.type
== BT_UNKNOWN
14224 && !gfc_set_default_type (sym
, 0, NULL
)
14225 && !sym
->attr
.untyped
)
14227 gfc_error ("Function '%s' at %L has no IMPLICIT type",
14228 sym
->name
, &sym
->declared_at
);
14229 sym
->attr
.untyped
= 1;
14232 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->ts
.u
.derived
->attr
.use_assoc
14233 && !sym
->attr
.contained
14234 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
14235 && gfc_check_symbol_access (sym
))
14237 gfc_notify_std (GFC_STD_F2003
, "PUBLIC function '%s' at "
14238 "%L of PRIVATE type '%s'", sym
->name
,
14239 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
14243 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
14245 if (el
->sym
->result
== el
->sym
14246 && el
->sym
->ts
.type
== BT_UNKNOWN
14247 && !gfc_set_default_type (el
->sym
, 0, NULL
)
14248 && !el
->sym
->attr
.untyped
)
14250 gfc_error ("ENTRY '%s' at %L has no IMPLICIT type",
14251 el
->sym
->name
, &el
->sym
->declared_at
);
14252 el
->sym
->attr
.untyped
= 1;
14258 /* 12.3.2.1.1 Defined operators. */
14261 check_uop_procedure (gfc_symbol
*sym
, locus where
)
14263 gfc_formal_arglist
*formal
;
14265 if (!sym
->attr
.function
)
14267 gfc_error ("User operator procedure '%s' at %L must be a FUNCTION",
14268 sym
->name
, &where
);
14272 if (sym
->ts
.type
== BT_CHARACTER
14273 && !(sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
)
14274 && !(sym
->result
&& sym
->result
->ts
.u
.cl
14275 && sym
->result
->ts
.u
.cl
->length
))
14277 gfc_error ("User operator procedure '%s' at %L cannot be assumed "
14278 "character length", sym
->name
, &where
);
14282 formal
= gfc_sym_get_dummy_args (sym
);
14283 if (!formal
|| !formal
->sym
)
14285 gfc_error ("User operator procedure '%s' at %L must have at least "
14286 "one argument", sym
->name
, &where
);
14290 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
14292 gfc_error ("First argument of operator interface at %L must be "
14293 "INTENT(IN)", &where
);
14297 if (formal
->sym
->attr
.optional
)
14299 gfc_error ("First argument of operator interface at %L cannot be "
14300 "optional", &where
);
14304 formal
= formal
->next
;
14305 if (!formal
|| !formal
->sym
)
14308 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
14310 gfc_error ("Second argument of operator interface at %L must be "
14311 "INTENT(IN)", &where
);
14315 if (formal
->sym
->attr
.optional
)
14317 gfc_error ("Second argument of operator interface at %L cannot be "
14318 "optional", &where
);
14324 gfc_error ("Operator interface at %L must have, at most, two "
14325 "arguments", &where
);
14333 gfc_resolve_uops (gfc_symtree
*symtree
)
14335 gfc_interface
*itr
;
14337 if (symtree
== NULL
)
14340 gfc_resolve_uops (symtree
->left
);
14341 gfc_resolve_uops (symtree
->right
);
14343 for (itr
= symtree
->n
.uop
->op
; itr
; itr
= itr
->next
)
14344 check_uop_procedure (itr
->sym
, itr
->sym
->declared_at
);
14348 /* Examine all of the expressions associated with a program unit,
14349 assign types to all intermediate expressions, make sure that all
14350 assignments are to compatible types and figure out which names
14351 refer to which functions or subroutines. It doesn't check code
14352 block, which is handled by resolve_code. */
14355 resolve_types (gfc_namespace
*ns
)
14361 gfc_namespace
* old_ns
= gfc_current_ns
;
14363 /* Check that all IMPLICIT types are ok. */
14364 if (!ns
->seen_implicit_none
)
14367 for (letter
= 0; letter
!= GFC_LETTERS
; ++letter
)
14368 if (ns
->set_flag
[letter
]
14369 && !resolve_typespec_used (&ns
->default_type
[letter
],
14370 &ns
->implicit_loc
[letter
], NULL
))
14374 gfc_current_ns
= ns
;
14376 resolve_entries (ns
);
14378 resolve_common_vars (ns
->blank_common
.head
, false);
14379 resolve_common_blocks (ns
->common_root
);
14381 resolve_contained_functions (ns
);
14383 if (ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
14384 && ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
14385 resolve_formal_arglist (ns
->proc_name
);
14387 gfc_traverse_ns (ns
, resolve_bind_c_derived_types
);
14389 for (cl
= ns
->cl_list
; cl
; cl
= cl
->next
)
14390 resolve_charlen (cl
);
14392 gfc_traverse_ns (ns
, resolve_symbol
);
14394 resolve_fntype (ns
);
14396 for (n
= ns
->contained
; n
; n
= n
->sibling
)
14398 if (gfc_pure (ns
->proc_name
) && !gfc_pure (n
->proc_name
))
14399 gfc_error ("Contained procedure '%s' at %L of a PURE procedure must "
14400 "also be PURE", n
->proc_name
->name
,
14401 &n
->proc_name
->declared_at
);
14407 do_concurrent_flag
= 0;
14408 gfc_check_interfaces (ns
);
14410 gfc_traverse_ns (ns
, resolve_values
);
14416 for (d
= ns
->data
; d
; d
= d
->next
)
14420 gfc_traverse_ns (ns
, gfc_formalize_init_value
);
14422 gfc_traverse_ns (ns
, gfc_verify_binding_labels
);
14424 for (eq
= ns
->equiv
; eq
; eq
= eq
->next
)
14425 resolve_equivalence (eq
);
14427 /* Warn about unused labels. */
14428 if (warn_unused_label
)
14429 warn_unused_fortran_label (ns
->st_labels
);
14431 gfc_resolve_uops (ns
->uop_root
);
14433 gfc_current_ns
= old_ns
;
14437 /* Call resolve_code recursively. */
14440 resolve_codes (gfc_namespace
*ns
)
14443 bitmap_obstack old_obstack
;
14445 if (ns
->resolved
== 1)
14448 for (n
= ns
->contained
; n
; n
= n
->sibling
)
14451 gfc_current_ns
= ns
;
14453 /* Don't clear 'cs_base' if this is the namespace of a BLOCK construct. */
14454 if (!(ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_LABEL
))
14457 /* Set to an out of range value. */
14458 current_entry_id
= -1;
14460 old_obstack
= labels_obstack
;
14461 bitmap_obstack_initialize (&labels_obstack
);
14463 resolve_code (ns
->code
, ns
);
14465 bitmap_obstack_release (&labels_obstack
);
14466 labels_obstack
= old_obstack
;
14470 /* This function is called after a complete program unit has been compiled.
14471 Its purpose is to examine all of the expressions associated with a program
14472 unit, assign types to all intermediate expressions, make sure that all
14473 assignments are to compatible types and figure out which names refer to
14474 which functions or subroutines. */
14477 gfc_resolve (gfc_namespace
*ns
)
14479 gfc_namespace
*old_ns
;
14480 code_stack
*old_cs_base
;
14486 old_ns
= gfc_current_ns
;
14487 old_cs_base
= cs_base
;
14489 resolve_types (ns
);
14490 component_assignment_level
= 0;
14491 resolve_codes (ns
);
14493 gfc_current_ns
= old_ns
;
14494 cs_base
= old_cs_base
;
14497 gfc_run_passes (ns
);