1 /* Perform type resolution on the various structures.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 Free Software Foundation, Inc.
5 Contributed by Andy Vaught
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
29 #include "arith.h" /* For gfc_compare_expr(). */
30 #include "dependency.h"
32 #include "target-memory.h" /* for gfc_simplify_transfer */
33 #include "constructor.h"
35 /* Types used in equivalence statements. */
39 SEQ_NONDEFAULT
, SEQ_NUMERIC
, SEQ_CHARACTER
, SEQ_MIXED
43 /* Stack to keep track of the nesting of blocks as we move through the
44 code. See resolve_branch() and resolve_code(). */
46 typedef struct code_stack
48 struct gfc_code
*head
, *current
;
49 struct code_stack
*prev
;
51 /* This bitmap keeps track of the targets valid for a branch from
52 inside this block except for END {IF|SELECT}s of enclosing
54 bitmap reachable_labels
;
58 static code_stack
*cs_base
= NULL
;
61 /* Nonzero if we're inside a FORALL or DO CONCURRENT block. */
63 static int forall_flag
;
64 static int do_concurrent_flag
;
66 /* Nonzero if we're inside a OpenMP WORKSHARE or PARALLEL WORKSHARE block. */
68 static int omp_workshare_flag
;
70 /* Nonzero if we are processing a formal arglist. The corresponding function
71 resets the flag each time that it is read. */
72 static int formal_arg_flag
= 0;
74 /* True if we are resolving a specification expression. */
75 static int specification_expr
= 0;
77 /* The id of the last entry seen. */
78 static int current_entry_id
;
80 /* We use bitmaps to determine if a branch target is valid. */
81 static bitmap_obstack labels_obstack
;
83 /* True when simplifying a EXPR_VARIABLE argument to an inquiry function. */
84 static bool inquiry_argument
= false;
87 gfc_is_formal_arg (void)
89 return formal_arg_flag
;
92 /* Is the symbol host associated? */
94 is_sym_host_assoc (gfc_symbol
*sym
, gfc_namespace
*ns
)
96 for (ns
= ns
->parent
; ns
; ns
= ns
->parent
)
105 /* Ensure a typespec used is valid; for instance, TYPE(t) is invalid if t is
106 an ABSTRACT derived-type. If where is not NULL, an error message with that
107 locus is printed, optionally using name. */
110 resolve_typespec_used (gfc_typespec
* ts
, locus
* where
, const char* name
)
112 if (ts
->type
== BT_DERIVED
&& ts
->u
.derived
->attr
.abstract
)
117 gfc_error ("'%s' at %L is of the ABSTRACT type '%s'",
118 name
, where
, ts
->u
.derived
->name
);
120 gfc_error ("ABSTRACT type '%s' used at %L",
121 ts
->u
.derived
->name
, where
);
131 static void resolve_symbol (gfc_symbol
*sym
);
132 static gfc_try
resolve_intrinsic (gfc_symbol
*sym
, locus
*loc
);
135 /* Resolve the interface for a PROCEDURE declaration or procedure pointer. */
138 resolve_procedure_interface (gfc_symbol
*sym
)
140 if (sym
->ts
.interface
== sym
)
142 gfc_error ("PROCEDURE '%s' at %L may not be used as its own interface",
143 sym
->name
, &sym
->declared_at
);
146 if (sym
->ts
.interface
->attr
.procedure
)
148 gfc_error ("Interface '%s', used by procedure '%s' at %L, is declared "
149 "in a later PROCEDURE statement", sym
->ts
.interface
->name
,
150 sym
->name
, &sym
->declared_at
);
154 /* Get the attributes from the interface (now resolved). */
155 if (sym
->ts
.interface
->attr
.if_source
|| sym
->ts
.interface
->attr
.intrinsic
)
157 gfc_symbol
*ifc
= sym
->ts
.interface
;
158 resolve_symbol (ifc
);
160 if (ifc
->attr
.intrinsic
)
161 resolve_intrinsic (ifc
, &ifc
->declared_at
);
165 sym
->ts
= ifc
->result
->ts
;
170 sym
->ts
.interface
= ifc
;
171 sym
->attr
.function
= ifc
->attr
.function
;
172 sym
->attr
.subroutine
= ifc
->attr
.subroutine
;
173 gfc_copy_formal_args (sym
, ifc
);
175 sym
->attr
.allocatable
= ifc
->attr
.allocatable
;
176 sym
->attr
.pointer
= ifc
->attr
.pointer
;
177 sym
->attr
.pure
= ifc
->attr
.pure
;
178 sym
->attr
.elemental
= ifc
->attr
.elemental
;
179 sym
->attr
.dimension
= ifc
->attr
.dimension
;
180 sym
->attr
.contiguous
= ifc
->attr
.contiguous
;
181 sym
->attr
.recursive
= ifc
->attr
.recursive
;
182 sym
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
183 sym
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
184 sym
->attr
.is_bind_c
= ifc
->attr
.is_bind_c
;
185 /* Copy array spec. */
186 sym
->as
= gfc_copy_array_spec (ifc
->as
);
190 for (i
= 0; i
< sym
->as
->rank
; i
++)
192 gfc_expr_replace_symbols (sym
->as
->lower
[i
], sym
);
193 gfc_expr_replace_symbols (sym
->as
->upper
[i
], sym
);
196 /* Copy char length. */
197 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
199 sym
->ts
.u
.cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
200 gfc_expr_replace_symbols (sym
->ts
.u
.cl
->length
, sym
);
201 if (sym
->ts
.u
.cl
->length
&& !sym
->ts
.u
.cl
->resolved
202 && gfc_resolve_expr (sym
->ts
.u
.cl
->length
) == FAILURE
)
206 else if (sym
->ts
.interface
->name
[0] != '\0')
208 gfc_error ("Interface '%s' of procedure '%s' at %L must be explicit",
209 sym
->ts
.interface
->name
, sym
->name
, &sym
->declared_at
);
217 /* Resolve types of formal argument lists. These have to be done early so that
218 the formal argument lists of module procedures can be copied to the
219 containing module before the individual procedures are resolved
220 individually. We also resolve argument lists of procedures in interface
221 blocks because they are self-contained scoping units.
223 Since a dummy argument cannot be a non-dummy procedure, the only
224 resort left for untyped names are the IMPLICIT types. */
227 resolve_formal_arglist (gfc_symbol
*proc
)
229 gfc_formal_arglist
*f
;
233 if (proc
->result
!= NULL
)
238 if (gfc_elemental (proc
)
239 || sym
->attr
.pointer
|| sym
->attr
.allocatable
240 || (sym
->as
&& sym
->as
->rank
> 0))
242 proc
->attr
.always_explicit
= 1;
243 sym
->attr
.always_explicit
= 1;
248 for (f
= proc
->formal
; f
; f
= f
->next
)
254 /* Alternate return placeholder. */
255 if (gfc_elemental (proc
))
256 gfc_error ("Alternate return specifier in elemental subroutine "
257 "'%s' at %L is not allowed", proc
->name
,
259 if (proc
->attr
.function
)
260 gfc_error ("Alternate return specifier in function "
261 "'%s' at %L is not allowed", proc
->name
,
265 else if (sym
->attr
.procedure
&& sym
->ts
.interface
266 && sym
->attr
.if_source
!= IFSRC_DECL
)
267 resolve_procedure_interface (sym
);
269 if (sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
270 resolve_formal_arglist (sym
);
272 if (sym
->attr
.subroutine
|| sym
->attr
.external
)
274 if (sym
->attr
.flavor
== FL_UNKNOWN
)
275 gfc_add_flavor (&sym
->attr
, FL_PROCEDURE
, sym
->name
, &sym
->declared_at
);
279 if (sym
->ts
.type
== BT_UNKNOWN
&& !proc
->attr
.intrinsic
280 && (!sym
->attr
.function
|| sym
->result
== sym
))
281 gfc_set_default_type (sym
, 1, sym
->ns
);
284 gfc_resolve_array_spec (sym
->as
, 0);
286 /* We can't tell if an array with dimension (:) is assumed or deferred
287 shape until we know if it has the pointer or allocatable attributes.
289 if (sym
->as
&& sym
->as
->rank
> 0 && sym
->as
->type
== AS_DEFERRED
290 && !(sym
->attr
.pointer
|| sym
->attr
.allocatable
)
291 && sym
->attr
.flavor
!= FL_PROCEDURE
)
293 sym
->as
->type
= AS_ASSUMED_SHAPE
;
294 for (i
= 0; i
< sym
->as
->rank
; i
++)
295 sym
->as
->lower
[i
] = gfc_get_int_expr (gfc_default_integer_kind
,
299 if ((sym
->as
&& sym
->as
->rank
> 0 && sym
->as
->type
== AS_ASSUMED_SHAPE
)
300 || sym
->attr
.pointer
|| sym
->attr
.allocatable
|| sym
->attr
.target
301 || sym
->attr
.optional
)
303 proc
->attr
.always_explicit
= 1;
305 proc
->result
->attr
.always_explicit
= 1;
308 /* If the flavor is unknown at this point, it has to be a variable.
309 A procedure specification would have already set the type. */
311 if (sym
->attr
.flavor
== FL_UNKNOWN
)
312 gfc_add_flavor (&sym
->attr
, FL_VARIABLE
, sym
->name
, &sym
->declared_at
);
316 if (sym
->attr
.flavor
== FL_PROCEDURE
)
321 gfc_error ("Dummy procedure '%s' of PURE procedure at %L must "
322 "also be PURE", sym
->name
, &sym
->declared_at
);
326 else if (!sym
->attr
.pointer
)
328 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
)
331 gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: Argument '%s'"
332 " of pure function '%s' at %L with VALUE "
333 "attribute but without INTENT(IN)",
334 sym
->name
, proc
->name
, &sym
->declared_at
);
336 gfc_error ("Argument '%s' of pure function '%s' at %L must "
337 "be INTENT(IN) or VALUE", sym
->name
, proc
->name
,
341 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
)
344 gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: Argument '%s'"
345 " of pure subroutine '%s' at %L with VALUE "
346 "attribute but without INTENT", sym
->name
,
347 proc
->name
, &sym
->declared_at
);
349 gfc_error ("Argument '%s' of pure subroutine '%s' at %L "
350 "must have its INTENT specified or have the "
351 "VALUE attribute", sym
->name
, proc
->name
,
357 if (proc
->attr
.implicit_pure
)
359 if (sym
->attr
.flavor
== FL_PROCEDURE
)
362 proc
->attr
.implicit_pure
= 0;
364 else if (!sym
->attr
.pointer
)
366 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
)
367 proc
->attr
.implicit_pure
= 0;
369 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
)
370 proc
->attr
.implicit_pure
= 0;
374 if (gfc_elemental (proc
))
377 if (sym
->attr
.codimension
)
379 gfc_error ("Coarray dummy argument '%s' at %L to elemental "
380 "procedure", sym
->name
, &sym
->declared_at
);
386 gfc_error ("Argument '%s' of elemental procedure at %L must "
387 "be scalar", sym
->name
, &sym
->declared_at
);
391 if (sym
->attr
.allocatable
)
393 gfc_error ("Argument '%s' of elemental procedure at %L cannot "
394 "have the ALLOCATABLE attribute", sym
->name
,
399 if (sym
->attr
.pointer
)
401 gfc_error ("Argument '%s' of elemental procedure at %L cannot "
402 "have the POINTER attribute", sym
->name
,
407 if (sym
->attr
.flavor
== FL_PROCEDURE
)
409 gfc_error ("Dummy procedure '%s' not allowed in elemental "
410 "procedure '%s' at %L", sym
->name
, proc
->name
,
415 if (sym
->attr
.intent
== INTENT_UNKNOWN
)
417 gfc_error ("Argument '%s' of elemental procedure '%s' at %L must "
418 "have its INTENT specified", sym
->name
, proc
->name
,
424 /* Each dummy shall be specified to be scalar. */
425 if (proc
->attr
.proc
== PROC_ST_FUNCTION
)
429 gfc_error ("Argument '%s' of statement function at %L must "
430 "be scalar", sym
->name
, &sym
->declared_at
);
434 if (sym
->ts
.type
== BT_CHARACTER
)
436 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
437 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
439 gfc_error ("Character-valued argument '%s' of statement "
440 "function at %L must have constant length",
441 sym
->name
, &sym
->declared_at
);
451 /* Work function called when searching for symbols that have argument lists
452 associated with them. */
455 find_arglists (gfc_symbol
*sym
)
457 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
|| sym
->ns
!= gfc_current_ns
)
460 resolve_formal_arglist (sym
);
464 /* Given a namespace, resolve all formal argument lists within the namespace.
468 resolve_formal_arglists (gfc_namespace
*ns
)
473 gfc_traverse_ns (ns
, find_arglists
);
478 resolve_contained_fntype (gfc_symbol
*sym
, gfc_namespace
*ns
)
482 /* If this namespace is not a function or an entry master function,
484 if (! sym
|| !(sym
->attr
.function
|| sym
->attr
.flavor
== FL_VARIABLE
)
485 || sym
->attr
.entry_master
)
488 /* Try to find out of what the return type is. */
489 if (sym
->result
->ts
.type
== BT_UNKNOWN
&& sym
->result
->ts
.interface
== NULL
)
491 t
= gfc_set_default_type (sym
->result
, 0, ns
);
493 if (t
== FAILURE
&& !sym
->result
->attr
.untyped
)
495 if (sym
->result
== sym
)
496 gfc_error ("Contained function '%s' at %L has no IMPLICIT type",
497 sym
->name
, &sym
->declared_at
);
498 else if (!sym
->result
->attr
.proc_pointer
)
499 gfc_error ("Result '%s' of contained function '%s' at %L has "
500 "no IMPLICIT type", sym
->result
->name
, sym
->name
,
501 &sym
->result
->declared_at
);
502 sym
->result
->attr
.untyped
= 1;
506 /* Fortran 95 Draft Standard, page 51, Section 5.1.1.5, on the Character
507 type, lists the only ways a character length value of * can be used:
508 dummy arguments of procedures, named constants, and function results
509 in external functions. Internal function results and results of module
510 procedures are not on this list, ergo, not permitted. */
512 if (sym
->result
->ts
.type
== BT_CHARACTER
)
514 gfc_charlen
*cl
= sym
->result
->ts
.u
.cl
;
515 if ((!cl
|| !cl
->length
) && !sym
->result
->ts
.deferred
)
517 /* See if this is a module-procedure and adapt error message
520 gcc_assert (ns
->parent
&& ns
->parent
->proc_name
);
521 module_proc
= (ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
);
523 gfc_error ("Character-valued %s '%s' at %L must not be"
525 module_proc
? _("module procedure")
526 : _("internal function"),
527 sym
->name
, &sym
->declared_at
);
533 /* Add NEW_ARGS to the formal argument list of PROC, taking care not to
534 introduce duplicates. */
537 merge_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
539 gfc_formal_arglist
*f
, *new_arglist
;
542 for (; new_args
!= NULL
; new_args
= new_args
->next
)
544 new_sym
= new_args
->sym
;
545 /* See if this arg is already in the formal argument list. */
546 for (f
= proc
->formal
; f
; f
= f
->next
)
548 if (new_sym
== f
->sym
)
555 /* Add a new argument. Argument order is not important. */
556 new_arglist
= gfc_get_formal_arglist ();
557 new_arglist
->sym
= new_sym
;
558 new_arglist
->next
= proc
->formal
;
559 proc
->formal
= new_arglist
;
564 /* Flag the arguments that are not present in all entries. */
567 check_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
569 gfc_formal_arglist
*f
, *head
;
572 for (f
= proc
->formal
; f
; f
= f
->next
)
577 for (new_args
= head
; new_args
; new_args
= new_args
->next
)
579 if (new_args
->sym
== f
->sym
)
586 f
->sym
->attr
.not_always_present
= 1;
591 /* Resolve alternate entry points. If a symbol has multiple entry points we
592 create a new master symbol for the main routine, and turn the existing
593 symbol into an entry point. */
596 resolve_entries (gfc_namespace
*ns
)
598 gfc_namespace
*old_ns
;
602 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
603 static int master_count
= 0;
605 if (ns
->proc_name
== NULL
)
608 /* No need to do anything if this procedure doesn't have alternate entry
613 /* We may already have resolved alternate entry points. */
614 if (ns
->proc_name
->attr
.entry_master
)
617 /* If this isn't a procedure something has gone horribly wrong. */
618 gcc_assert (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
);
620 /* Remember the current namespace. */
621 old_ns
= gfc_current_ns
;
625 /* Add the main entry point to the list of entry points. */
626 el
= gfc_get_entry_list ();
627 el
->sym
= ns
->proc_name
;
629 el
->next
= ns
->entries
;
631 ns
->proc_name
->attr
.entry
= 1;
633 /* If it is a module function, it needs to be in the right namespace
634 so that gfc_get_fake_result_decl can gather up the results. The
635 need for this arose in get_proc_name, where these beasts were
636 left in their own namespace, to keep prior references linked to
637 the entry declaration.*/
638 if (ns
->proc_name
->attr
.function
639 && ns
->parent
&& ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
642 /* Do the same for entries where the master is not a module
643 procedure. These are retained in the module namespace because
644 of the module procedure declaration. */
645 for (el
= el
->next
; el
; el
= el
->next
)
646 if (el
->sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
647 && el
->sym
->attr
.mod_proc
)
651 /* Add an entry statement for it. */
658 /* Create a new symbol for the master function. */
659 /* Give the internal function a unique name (within this file).
660 Also include the function name so the user has some hope of figuring
661 out what is going on. */
662 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "master.%d.%s",
663 master_count
++, ns
->proc_name
->name
);
664 gfc_get_ha_symbol (name
, &proc
);
665 gcc_assert (proc
!= NULL
);
667 gfc_add_procedure (&proc
->attr
, PROC_INTERNAL
, proc
->name
, NULL
);
668 if (ns
->proc_name
->attr
.subroutine
)
669 gfc_add_subroutine (&proc
->attr
, proc
->name
, NULL
);
673 gfc_typespec
*ts
, *fts
;
674 gfc_array_spec
*as
, *fas
;
675 gfc_add_function (&proc
->attr
, proc
->name
, NULL
);
677 fas
= ns
->entries
->sym
->as
;
678 fas
= fas
? fas
: ns
->entries
->sym
->result
->as
;
679 fts
= &ns
->entries
->sym
->result
->ts
;
680 if (fts
->type
== BT_UNKNOWN
)
681 fts
= gfc_get_default_type (ns
->entries
->sym
->result
->name
, NULL
);
682 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
684 ts
= &el
->sym
->result
->ts
;
686 as
= as
? as
: el
->sym
->result
->as
;
687 if (ts
->type
== BT_UNKNOWN
)
688 ts
= gfc_get_default_type (el
->sym
->result
->name
, NULL
);
690 if (! gfc_compare_types (ts
, fts
)
691 || (el
->sym
->result
->attr
.dimension
692 != ns
->entries
->sym
->result
->attr
.dimension
)
693 || (el
->sym
->result
->attr
.pointer
694 != ns
->entries
->sym
->result
->attr
.pointer
))
696 else if (as
&& fas
&& ns
->entries
->sym
->result
!= el
->sym
->result
697 && gfc_compare_array_spec (as
, fas
) == 0)
698 gfc_error ("Function %s at %L has entries with mismatched "
699 "array specifications", ns
->entries
->sym
->name
,
700 &ns
->entries
->sym
->declared_at
);
701 /* The characteristics need to match and thus both need to have
702 the same string length, i.e. both len=*, or both len=4.
703 Having both len=<variable> is also possible, but difficult to
704 check at compile time. */
705 else if (ts
->type
== BT_CHARACTER
&& ts
->u
.cl
&& fts
->u
.cl
706 && (((ts
->u
.cl
->length
&& !fts
->u
.cl
->length
)
707 ||(!ts
->u
.cl
->length
&& fts
->u
.cl
->length
))
709 && ts
->u
.cl
->length
->expr_type
710 != fts
->u
.cl
->length
->expr_type
)
712 && ts
->u
.cl
->length
->expr_type
== EXPR_CONSTANT
713 && mpz_cmp (ts
->u
.cl
->length
->value
.integer
,
714 fts
->u
.cl
->length
->value
.integer
) != 0)))
715 gfc_notify_std (GFC_STD_GNU
, "Extension: Function %s at %L with "
716 "entries returning variables of different "
717 "string lengths", ns
->entries
->sym
->name
,
718 &ns
->entries
->sym
->declared_at
);
723 sym
= ns
->entries
->sym
->result
;
724 /* All result types the same. */
726 if (sym
->attr
.dimension
)
727 gfc_set_array_spec (proc
, gfc_copy_array_spec (sym
->as
), NULL
);
728 if (sym
->attr
.pointer
)
729 gfc_add_pointer (&proc
->attr
, NULL
);
733 /* Otherwise the result will be passed through a union by
735 proc
->attr
.mixed_entry_master
= 1;
736 for (el
= ns
->entries
; el
; el
= el
->next
)
738 sym
= el
->sym
->result
;
739 if (sym
->attr
.dimension
)
741 if (el
== ns
->entries
)
742 gfc_error ("FUNCTION result %s can't be an array in "
743 "FUNCTION %s at %L", sym
->name
,
744 ns
->entries
->sym
->name
, &sym
->declared_at
);
746 gfc_error ("ENTRY result %s can't be an array in "
747 "FUNCTION %s at %L", sym
->name
,
748 ns
->entries
->sym
->name
, &sym
->declared_at
);
750 else if (sym
->attr
.pointer
)
752 if (el
== ns
->entries
)
753 gfc_error ("FUNCTION result %s can't be a POINTER in "
754 "FUNCTION %s at %L", sym
->name
,
755 ns
->entries
->sym
->name
, &sym
->declared_at
);
757 gfc_error ("ENTRY result %s can't be a POINTER in "
758 "FUNCTION %s at %L", sym
->name
,
759 ns
->entries
->sym
->name
, &sym
->declared_at
);
764 if (ts
->type
== BT_UNKNOWN
)
765 ts
= gfc_get_default_type (sym
->name
, NULL
);
769 if (ts
->kind
== gfc_default_integer_kind
)
773 if (ts
->kind
== gfc_default_real_kind
774 || ts
->kind
== gfc_default_double_kind
)
778 if (ts
->kind
== gfc_default_complex_kind
)
782 if (ts
->kind
== gfc_default_logical_kind
)
786 /* We will issue error elsewhere. */
794 if (el
== ns
->entries
)
795 gfc_error ("FUNCTION result %s can't be of type %s "
796 "in FUNCTION %s at %L", sym
->name
,
797 gfc_typename (ts
), ns
->entries
->sym
->name
,
800 gfc_error ("ENTRY result %s can't be of type %s "
801 "in FUNCTION %s at %L", sym
->name
,
802 gfc_typename (ts
), ns
->entries
->sym
->name
,
809 proc
->attr
.access
= ACCESS_PRIVATE
;
810 proc
->attr
.entry_master
= 1;
812 /* Merge all the entry point arguments. */
813 for (el
= ns
->entries
; el
; el
= el
->next
)
814 merge_argument_lists (proc
, el
->sym
->formal
);
816 /* Check the master formal arguments for any that are not
817 present in all entry points. */
818 for (el
= ns
->entries
; el
; el
= el
->next
)
819 check_argument_lists (proc
, el
->sym
->formal
);
821 /* Use the master function for the function body. */
822 ns
->proc_name
= proc
;
824 /* Finalize the new symbols. */
825 gfc_commit_symbols ();
827 /* Restore the original namespace. */
828 gfc_current_ns
= old_ns
;
832 /* Resolve common variables. */
834 resolve_common_vars (gfc_symbol
*sym
, bool named_common
)
836 gfc_symbol
*csym
= sym
;
838 for (; csym
; csym
= csym
->common_next
)
840 if (csym
->value
|| csym
->attr
.data
)
842 if (!csym
->ns
->is_block_data
)
843 gfc_notify_std (GFC_STD_GNU
, "Variable '%s' at %L is in COMMON "
844 "but only in BLOCK DATA initialization is "
845 "allowed", csym
->name
, &csym
->declared_at
);
846 else if (!named_common
)
847 gfc_notify_std (GFC_STD_GNU
, "Initialized variable '%s' at %L is "
848 "in a blank COMMON but initialization is only "
849 "allowed in named common blocks", csym
->name
,
853 if (csym
->ts
.type
!= BT_DERIVED
)
856 if (!(csym
->ts
.u
.derived
->attr
.sequence
857 || csym
->ts
.u
.derived
->attr
.is_bind_c
))
858 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
859 "has neither the SEQUENCE nor the BIND(C) "
860 "attribute", csym
->name
, &csym
->declared_at
);
861 if (csym
->ts
.u
.derived
->attr
.alloc_comp
)
862 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
863 "has an ultimate component that is "
864 "allocatable", csym
->name
, &csym
->declared_at
);
865 if (gfc_has_default_initializer (csym
->ts
.u
.derived
))
866 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
867 "may not have default initializer", csym
->name
,
870 if (csym
->attr
.flavor
== FL_UNKNOWN
&& !csym
->attr
.proc_pointer
)
871 gfc_add_flavor (&csym
->attr
, FL_VARIABLE
, csym
->name
, &csym
->declared_at
);
875 /* Resolve common blocks. */
877 resolve_common_blocks (gfc_symtree
*common_root
)
881 if (common_root
== NULL
)
884 if (common_root
->left
)
885 resolve_common_blocks (common_root
->left
);
886 if (common_root
->right
)
887 resolve_common_blocks (common_root
->right
);
889 resolve_common_vars (common_root
->n
.common
->head
, true);
891 gfc_find_symbol (common_root
->name
, gfc_current_ns
, 0, &sym
);
895 if (sym
->attr
.flavor
== FL_PARAMETER
)
896 gfc_error ("COMMON block '%s' at %L is used as PARAMETER at %L",
897 sym
->name
, &common_root
->n
.common
->where
, &sym
->declared_at
);
899 if (sym
->attr
.external
)
900 gfc_error ("COMMON block '%s' at %L can not have the EXTERNAL attribute",
901 sym
->name
, &common_root
->n
.common
->where
);
903 if (sym
->attr
.intrinsic
)
904 gfc_error ("COMMON block '%s' at %L is also an intrinsic procedure",
905 sym
->name
, &common_root
->n
.common
->where
);
906 else if (sym
->attr
.result
907 || gfc_is_function_return_value (sym
, gfc_current_ns
))
908 gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: COMMON block '%s' at %L "
909 "that is also a function result", sym
->name
,
910 &common_root
->n
.common
->where
);
911 else if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.proc
!= PROC_INTERNAL
912 && sym
->attr
.proc
!= PROC_ST_FUNCTION
)
913 gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: COMMON block '%s' at %L "
914 "that is also a global procedure", sym
->name
,
915 &common_root
->n
.common
->where
);
919 /* Resolve contained function types. Because contained functions can call one
920 another, they have to be worked out before any of the contained procedures
923 The good news is that if a function doesn't already have a type, the only
924 way it can get one is through an IMPLICIT type or a RESULT variable, because
925 by definition contained functions are contained namespace they're contained
926 in, not in a sibling or parent namespace. */
929 resolve_contained_functions (gfc_namespace
*ns
)
931 gfc_namespace
*child
;
934 resolve_formal_arglists (ns
);
936 for (child
= ns
->contained
; child
; child
= child
->sibling
)
938 /* Resolve alternate entry points first. */
939 resolve_entries (child
);
941 /* Then check function return types. */
942 resolve_contained_fntype (child
->proc_name
, child
);
943 for (el
= child
->entries
; el
; el
= el
->next
)
944 resolve_contained_fntype (el
->sym
, child
);
949 static gfc_try
resolve_fl_derived0 (gfc_symbol
*sym
);
952 /* Resolve all of the elements of a structure constructor and make sure that
953 the types are correct. The 'init' flag indicates that the given
954 constructor is an initializer. */
957 resolve_structure_cons (gfc_expr
*expr
, int init
)
959 gfc_constructor
*cons
;
966 if (expr
->ts
.type
== BT_DERIVED
)
967 resolve_fl_derived0 (expr
->ts
.u
.derived
);
969 cons
= gfc_constructor_first (expr
->value
.constructor
);
970 /* A constructor may have references if it is the result of substituting a
971 parameter variable. In this case we just pull out the component we
974 comp
= expr
->ref
->u
.c
.sym
->components
;
976 comp
= expr
->ts
.u
.derived
->components
;
978 /* See if the user is trying to invoke a structure constructor for one of
979 the iso_c_binding derived types. */
980 if (expr
->ts
.type
== BT_DERIVED
&& expr
->ts
.u
.derived
981 && expr
->ts
.u
.derived
->ts
.is_iso_c
&& cons
982 && (cons
->expr
== NULL
|| cons
->expr
->expr_type
!= EXPR_NULL
))
984 gfc_error ("Components of structure constructor '%s' at %L are PRIVATE",
985 expr
->ts
.u
.derived
->name
, &(expr
->where
));
989 /* Return if structure constructor is c_null_(fun)prt. */
990 if (expr
->ts
.type
== BT_DERIVED
&& expr
->ts
.u
.derived
991 && expr
->ts
.u
.derived
->ts
.is_iso_c
&& cons
992 && cons
->expr
&& cons
->expr
->expr_type
== EXPR_NULL
)
995 for (; comp
&& cons
; comp
= comp
->next
, cons
= gfc_constructor_next (cons
))
1002 if (gfc_resolve_expr (cons
->expr
) == FAILURE
)
1008 rank
= comp
->as
? comp
->as
->rank
: 0;
1009 if (cons
->expr
->expr_type
!= EXPR_NULL
&& rank
!= cons
->expr
->rank
1010 && (comp
->attr
.allocatable
|| cons
->expr
->rank
))
1012 gfc_error ("The rank of the element in the structure "
1013 "constructor at %L does not match that of the "
1014 "component (%d/%d)", &cons
->expr
->where
,
1015 cons
->expr
->rank
, rank
);
1019 /* If we don't have the right type, try to convert it. */
1021 if (!comp
->attr
.proc_pointer
&&
1022 !gfc_compare_types (&cons
->expr
->ts
, &comp
->ts
))
1025 if (strcmp (comp
->name
, "_extends") == 0)
1027 /* Can afford to be brutal with the _extends initializer.
1028 The derived type can get lost because it is PRIVATE
1029 but it is not usage constrained by the standard. */
1030 cons
->expr
->ts
= comp
->ts
;
1033 else if (comp
->attr
.pointer
&& cons
->expr
->ts
.type
!= BT_UNKNOWN
)
1034 gfc_error ("The element in the structure constructor at %L, "
1035 "for pointer component '%s', is %s but should be %s",
1036 &cons
->expr
->where
, comp
->name
,
1037 gfc_basic_typename (cons
->expr
->ts
.type
),
1038 gfc_basic_typename (comp
->ts
.type
));
1040 t
= gfc_convert_type (cons
->expr
, &comp
->ts
, 1);
1043 /* For strings, the length of the constructor should be the same as
1044 the one of the structure, ensure this if the lengths are known at
1045 compile time and when we are dealing with PARAMETER or structure
1047 if (cons
->expr
->ts
.type
== BT_CHARACTER
&& comp
->ts
.u
.cl
1048 && comp
->ts
.u
.cl
->length
1049 && comp
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1050 && cons
->expr
->ts
.u
.cl
&& cons
->expr
->ts
.u
.cl
->length
1051 && cons
->expr
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1052 && mpz_cmp (cons
->expr
->ts
.u
.cl
->length
->value
.integer
,
1053 comp
->ts
.u
.cl
->length
->value
.integer
) != 0)
1055 if (cons
->expr
->expr_type
== EXPR_VARIABLE
1056 && cons
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
)
1058 /* Wrap the parameter in an array constructor (EXPR_ARRAY)
1059 to make use of the gfc_resolve_character_array_constructor
1060 machinery. The expression is later simplified away to
1061 an array of string literals. */
1062 gfc_expr
*para
= cons
->expr
;
1063 cons
->expr
= gfc_get_expr ();
1064 cons
->expr
->ts
= para
->ts
;
1065 cons
->expr
->where
= para
->where
;
1066 cons
->expr
->expr_type
= EXPR_ARRAY
;
1067 cons
->expr
->rank
= para
->rank
;
1068 cons
->expr
->shape
= gfc_copy_shape (para
->shape
, para
->rank
);
1069 gfc_constructor_append_expr (&cons
->expr
->value
.constructor
,
1070 para
, &cons
->expr
->where
);
1072 if (cons
->expr
->expr_type
== EXPR_ARRAY
)
1075 p
= gfc_constructor_first (cons
->expr
->value
.constructor
);
1076 if (cons
->expr
->ts
.u
.cl
!= p
->expr
->ts
.u
.cl
)
1078 gfc_charlen
*cl
, *cl2
;
1081 for (cl
= gfc_current_ns
->cl_list
; cl
; cl
= cl
->next
)
1083 if (cl
== cons
->expr
->ts
.u
.cl
)
1091 cl2
->next
= cl
->next
;
1093 gfc_free_expr (cl
->length
);
1097 cons
->expr
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
1098 cons
->expr
->ts
.u
.cl
->length_from_typespec
= true;
1099 cons
->expr
->ts
.u
.cl
->length
= gfc_copy_expr (comp
->ts
.u
.cl
->length
);
1100 gfc_resolve_character_array_constructor (cons
->expr
);
1104 if (cons
->expr
->expr_type
== EXPR_NULL
1105 && !(comp
->attr
.pointer
|| comp
->attr
.allocatable
1106 || comp
->attr
.proc_pointer
1107 || (comp
->ts
.type
== BT_CLASS
1108 && (CLASS_DATA (comp
)->attr
.class_pointer
1109 || CLASS_DATA (comp
)->attr
.allocatable
))))
1112 gfc_error ("The NULL in the structure constructor at %L is "
1113 "being applied to component '%s', which is neither "
1114 "a POINTER nor ALLOCATABLE", &cons
->expr
->where
,
1118 if (comp
->attr
.proc_pointer
&& comp
->ts
.interface
)
1120 /* Check procedure pointer interface. */
1121 gfc_symbol
*s2
= NULL
;
1126 if (gfc_is_proc_ptr_comp (cons
->expr
, &c2
))
1128 s2
= c2
->ts
.interface
;
1131 else if (cons
->expr
->expr_type
== EXPR_FUNCTION
)
1133 s2
= cons
->expr
->symtree
->n
.sym
->result
;
1134 name
= cons
->expr
->symtree
->n
.sym
->result
->name
;
1136 else if (cons
->expr
->expr_type
!= EXPR_NULL
)
1138 s2
= cons
->expr
->symtree
->n
.sym
;
1139 name
= cons
->expr
->symtree
->n
.sym
->name
;
1142 if (s2
&& !gfc_compare_interfaces (comp
->ts
.interface
, s2
, name
, 0, 1,
1145 gfc_error ("Interface mismatch for procedure-pointer component "
1146 "'%s' in structure constructor at %L: %s",
1147 comp
->name
, &cons
->expr
->where
, err
);
1152 if (!comp
->attr
.pointer
|| comp
->attr
.proc_pointer
1153 || cons
->expr
->expr_type
== EXPR_NULL
)
1156 a
= gfc_expr_attr (cons
->expr
);
1158 if (!a
.pointer
&& !a
.target
)
1161 gfc_error ("The element in the structure constructor at %L, "
1162 "for pointer component '%s' should be a POINTER or "
1163 "a TARGET", &cons
->expr
->where
, comp
->name
);
1168 /* F08:C461. Additional checks for pointer initialization. */
1172 gfc_error ("Pointer initialization target at %L "
1173 "must not be ALLOCATABLE ", &cons
->expr
->where
);
1178 gfc_error ("Pointer initialization target at %L "
1179 "must have the SAVE attribute", &cons
->expr
->where
);
1183 /* F2003, C1272 (3). */
1184 if (gfc_pure (NULL
) && cons
->expr
->expr_type
== EXPR_VARIABLE
1185 && (gfc_impure_variable (cons
->expr
->symtree
->n
.sym
)
1186 || gfc_is_coindexed (cons
->expr
)))
1189 gfc_error ("Invalid expression in the structure constructor for "
1190 "pointer component '%s' at %L in PURE procedure",
1191 comp
->name
, &cons
->expr
->where
);
1194 if (gfc_implicit_pure (NULL
)
1195 && cons
->expr
->expr_type
== EXPR_VARIABLE
1196 && (gfc_impure_variable (cons
->expr
->symtree
->n
.sym
)
1197 || gfc_is_coindexed (cons
->expr
)))
1198 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
1206 /****************** Expression name resolution ******************/
1208 /* Returns 0 if a symbol was not declared with a type or
1209 attribute declaration statement, nonzero otherwise. */
1212 was_declared (gfc_symbol
*sym
)
1218 if (!a
.implicit_type
&& sym
->ts
.type
!= BT_UNKNOWN
)
1221 if (a
.allocatable
|| a
.dimension
|| a
.dummy
|| a
.external
|| a
.intrinsic
1222 || a
.optional
|| a
.pointer
|| a
.save
|| a
.target
|| a
.volatile_
1223 || a
.value
|| a
.access
!= ACCESS_UNKNOWN
|| a
.intent
!= INTENT_UNKNOWN
1224 || a
.asynchronous
|| a
.codimension
)
1231 /* Determine if a symbol is generic or not. */
1234 generic_sym (gfc_symbol
*sym
)
1238 if (sym
->attr
.generic
||
1239 (sym
->attr
.intrinsic
&& gfc_generic_intrinsic (sym
->name
)))
1242 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1245 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1252 return generic_sym (s
);
1259 /* Determine if a symbol is specific or not. */
1262 specific_sym (gfc_symbol
*sym
)
1266 if (sym
->attr
.if_source
== IFSRC_IFBODY
1267 || sym
->attr
.proc
== PROC_MODULE
1268 || sym
->attr
.proc
== PROC_INTERNAL
1269 || sym
->attr
.proc
== PROC_ST_FUNCTION
1270 || (sym
->attr
.intrinsic
&& gfc_specific_intrinsic (sym
->name
))
1271 || sym
->attr
.external
)
1274 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1277 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1279 return (s
== NULL
) ? 0 : specific_sym (s
);
1283 /* Figure out if the procedure is specific, generic or unknown. */
1286 { PTYPE_GENERIC
= 1, PTYPE_SPECIFIC
, PTYPE_UNKNOWN
}
1290 procedure_kind (gfc_symbol
*sym
)
1292 if (generic_sym (sym
))
1293 return PTYPE_GENERIC
;
1295 if (specific_sym (sym
))
1296 return PTYPE_SPECIFIC
;
1298 return PTYPE_UNKNOWN
;
1301 /* Check references to assumed size arrays. The flag need_full_assumed_size
1302 is nonzero when matching actual arguments. */
1304 static int need_full_assumed_size
= 0;
1307 check_assumed_size_reference (gfc_symbol
*sym
, gfc_expr
*e
)
1309 if (need_full_assumed_size
|| !(sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
))
1312 /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong.
1313 What should it be? */
1314 if ((e
->ref
->u
.ar
.end
[e
->ref
->u
.ar
.as
->rank
- 1] == NULL
)
1315 && (e
->ref
->u
.ar
.as
->type
== AS_ASSUMED_SIZE
)
1316 && (e
->ref
->u
.ar
.type
== AR_FULL
))
1318 gfc_error ("The upper bound in the last dimension must "
1319 "appear in the reference to the assumed size "
1320 "array '%s' at %L", sym
->name
, &e
->where
);
1327 /* Look for bad assumed size array references in argument expressions
1328 of elemental and array valued intrinsic procedures. Since this is
1329 called from procedure resolution functions, it only recurses at
1333 resolve_assumed_size_actual (gfc_expr
*e
)
1338 switch (e
->expr_type
)
1341 if (e
->symtree
&& check_assumed_size_reference (e
->symtree
->n
.sym
, e
))
1346 if (resolve_assumed_size_actual (e
->value
.op
.op1
)
1347 || resolve_assumed_size_actual (e
->value
.op
.op2
))
1358 /* Check a generic procedure, passed as an actual argument, to see if
1359 there is a matching specific name. If none, it is an error, and if
1360 more than one, the reference is ambiguous. */
1362 count_specific_procs (gfc_expr
*e
)
1369 sym
= e
->symtree
->n
.sym
;
1371 for (p
= sym
->generic
; p
; p
= p
->next
)
1372 if (strcmp (sym
->name
, p
->sym
->name
) == 0)
1374 e
->symtree
= gfc_find_symtree (p
->sym
->ns
->sym_root
,
1380 gfc_error ("'%s' at %L is ambiguous", e
->symtree
->n
.sym
->name
,
1384 gfc_error ("GENERIC procedure '%s' is not allowed as an actual "
1385 "argument at %L", sym
->name
, &e
->where
);
1391 /* See if a call to sym could possibly be a not allowed RECURSION because of
1392 a missing RECURIVE declaration. This means that either sym is the current
1393 context itself, or sym is the parent of a contained procedure calling its
1394 non-RECURSIVE containing procedure.
1395 This also works if sym is an ENTRY. */
1398 is_illegal_recursion (gfc_symbol
* sym
, gfc_namespace
* context
)
1400 gfc_symbol
* proc_sym
;
1401 gfc_symbol
* context_proc
;
1402 gfc_namespace
* real_context
;
1404 if (sym
->attr
.flavor
== FL_PROGRAM
)
1407 gcc_assert (sym
->attr
.flavor
== FL_PROCEDURE
);
1409 /* If we've got an ENTRY, find real procedure. */
1410 if (sym
->attr
.entry
&& sym
->ns
->entries
)
1411 proc_sym
= sym
->ns
->entries
->sym
;
1415 /* If sym is RECURSIVE, all is well of course. */
1416 if (proc_sym
->attr
.recursive
|| gfc_option
.flag_recursive
)
1419 /* Find the context procedure's "real" symbol if it has entries.
1420 We look for a procedure symbol, so recurse on the parents if we don't
1421 find one (like in case of a BLOCK construct). */
1422 for (real_context
= context
; ; real_context
= real_context
->parent
)
1424 /* We should find something, eventually! */
1425 gcc_assert (real_context
);
1427 context_proc
= (real_context
->entries
? real_context
->entries
->sym
1428 : real_context
->proc_name
);
1430 /* In some special cases, there may not be a proc_name, like for this
1432 real(bad_kind()) function foo () ...
1433 when checking the call to bad_kind ().
1434 In these cases, we simply return here and assume that the
1439 if (context_proc
->attr
.flavor
!= FL_LABEL
)
1443 /* A call from sym's body to itself is recursion, of course. */
1444 if (context_proc
== proc_sym
)
1447 /* The same is true if context is a contained procedure and sym the
1449 if (context_proc
->attr
.contained
)
1451 gfc_symbol
* parent_proc
;
1453 gcc_assert (context
->parent
);
1454 parent_proc
= (context
->parent
->entries
? context
->parent
->entries
->sym
1455 : context
->parent
->proc_name
);
1457 if (parent_proc
== proc_sym
)
1465 /* Resolve an intrinsic procedure: Set its function/subroutine attribute,
1466 its typespec and formal argument list. */
1469 resolve_intrinsic (gfc_symbol
*sym
, locus
*loc
)
1471 gfc_intrinsic_sym
* isym
= NULL
;
1477 /* Already resolved. */
1478 if (sym
->from_intmod
&& sym
->ts
.type
!= BT_UNKNOWN
)
1481 /* We already know this one is an intrinsic, so we don't call
1482 gfc_is_intrinsic for full checking but rather use gfc_find_function and
1483 gfc_find_subroutine directly to check whether it is a function or
1486 if (sym
->intmod_sym_id
)
1487 isym
= gfc_intrinsic_function_by_id ((gfc_isym_id
) sym
->intmod_sym_id
);
1489 isym
= gfc_find_function (sym
->name
);
1493 if (sym
->ts
.type
!= BT_UNKNOWN
&& gfc_option
.warn_surprising
1494 && !sym
->attr
.implicit_type
)
1495 gfc_warning ("Type specified for intrinsic function '%s' at %L is"
1496 " ignored", sym
->name
, &sym
->declared_at
);
1498 if (!sym
->attr
.function
&&
1499 gfc_add_function (&sym
->attr
, sym
->name
, loc
) == FAILURE
)
1504 else if ((isym
= gfc_find_subroutine (sym
->name
)))
1506 if (sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.implicit_type
)
1508 gfc_error ("Intrinsic subroutine '%s' at %L shall not have a type"
1509 " specifier", sym
->name
, &sym
->declared_at
);
1513 if (!sym
->attr
.subroutine
&&
1514 gfc_add_subroutine (&sym
->attr
, sym
->name
, loc
) == FAILURE
)
1519 gfc_error ("'%s' declared INTRINSIC at %L does not exist", sym
->name
,
1524 gfc_copy_formal_args_intr (sym
, isym
);
1526 /* Check it is actually available in the standard settings. */
1527 if (gfc_check_intrinsic_standard (isym
, &symstd
, false, sym
->declared_at
)
1530 gfc_error ("The intrinsic '%s' declared INTRINSIC at %L is not"
1531 " available in the current standard settings but %s. Use"
1532 " an appropriate -std=* option or enable -fall-intrinsics"
1533 " in order to use it.",
1534 sym
->name
, &sym
->declared_at
, symstd
);
1542 /* Resolve a procedure expression, like passing it to a called procedure or as
1543 RHS for a procedure pointer assignment. */
1546 resolve_procedure_expression (gfc_expr
* expr
)
1550 if (expr
->expr_type
!= EXPR_VARIABLE
)
1552 gcc_assert (expr
->symtree
);
1554 sym
= expr
->symtree
->n
.sym
;
1556 if (sym
->attr
.intrinsic
)
1557 resolve_intrinsic (sym
, &expr
->where
);
1559 if (sym
->attr
.flavor
!= FL_PROCEDURE
1560 || (sym
->attr
.function
&& sym
->result
== sym
))
1563 /* A non-RECURSIVE procedure that is used as procedure expression within its
1564 own body is in danger of being called recursively. */
1565 if (is_illegal_recursion (sym
, gfc_current_ns
))
1566 gfc_warning ("Non-RECURSIVE procedure '%s' at %L is possibly calling"
1567 " itself recursively. Declare it RECURSIVE or use"
1568 " -frecursive", sym
->name
, &expr
->where
);
1574 /* Resolve an actual argument list. Most of the time, this is just
1575 resolving the expressions in the list.
1576 The exception is that we sometimes have to decide whether arguments
1577 that look like procedure arguments are really simple variable
1581 resolve_actual_arglist (gfc_actual_arglist
*arg
, procedure_type ptype
,
1582 bool no_formal_args
)
1585 gfc_symtree
*parent_st
;
1587 int save_need_full_assumed_size
;
1589 for (; arg
; arg
= arg
->next
)
1594 /* Check the label is a valid branching target. */
1597 if (arg
->label
->defined
== ST_LABEL_UNKNOWN
)
1599 gfc_error ("Label %d referenced at %L is never defined",
1600 arg
->label
->value
, &arg
->label
->where
);
1607 if (e
->expr_type
== EXPR_VARIABLE
1608 && e
->symtree
->n
.sym
->attr
.generic
1610 && count_specific_procs (e
) != 1)
1613 if (e
->ts
.type
!= BT_PROCEDURE
)
1615 save_need_full_assumed_size
= need_full_assumed_size
;
1616 if (e
->expr_type
!= EXPR_VARIABLE
)
1617 need_full_assumed_size
= 0;
1618 if (gfc_resolve_expr (e
) != SUCCESS
)
1620 need_full_assumed_size
= save_need_full_assumed_size
;
1624 /* See if the expression node should really be a variable reference. */
1626 sym
= e
->symtree
->n
.sym
;
1628 if (sym
->attr
.flavor
== FL_PROCEDURE
1629 || sym
->attr
.intrinsic
1630 || sym
->attr
.external
)
1634 /* If a procedure is not already determined to be something else
1635 check if it is intrinsic. */
1636 if (!sym
->attr
.intrinsic
1637 && !(sym
->attr
.external
|| sym
->attr
.use_assoc
1638 || sym
->attr
.if_source
== IFSRC_IFBODY
)
1639 && gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, e
->where
))
1640 sym
->attr
.intrinsic
= 1;
1642 if (sym
->attr
.proc
== PROC_ST_FUNCTION
)
1644 gfc_error ("Statement function '%s' at %L is not allowed as an "
1645 "actual argument", sym
->name
, &e
->where
);
1648 actual_ok
= gfc_intrinsic_actual_ok (sym
->name
,
1649 sym
->attr
.subroutine
);
1650 if (sym
->attr
.intrinsic
&& actual_ok
== 0)
1652 gfc_error ("Intrinsic '%s' at %L is not allowed as an "
1653 "actual argument", sym
->name
, &e
->where
);
1656 if (sym
->attr
.contained
&& !sym
->attr
.use_assoc
1657 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
1659 if (gfc_notify_std (GFC_STD_F2008
,
1660 "Fortran 2008: Internal procedure '%s' is"
1661 " used as actual argument at %L",
1662 sym
->name
, &e
->where
) == FAILURE
)
1666 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
)
1668 gfc_error ("ELEMENTAL non-INTRINSIC procedure '%s' is not "
1669 "allowed as an actual argument at %L", sym
->name
,
1673 /* Check if a generic interface has a specific procedure
1674 with the same name before emitting an error. */
1675 if (sym
->attr
.generic
&& count_specific_procs (e
) != 1)
1678 /* Just in case a specific was found for the expression. */
1679 sym
= e
->symtree
->n
.sym
;
1681 /* If the symbol is the function that names the current (or
1682 parent) scope, then we really have a variable reference. */
1684 if (gfc_is_function_return_value (sym
, sym
->ns
))
1687 /* If all else fails, see if we have a specific intrinsic. */
1688 if (sym
->ts
.type
== BT_UNKNOWN
&& sym
->attr
.intrinsic
)
1690 gfc_intrinsic_sym
*isym
;
1692 isym
= gfc_find_function (sym
->name
);
1693 if (isym
== NULL
|| !isym
->specific
)
1695 gfc_error ("Unable to find a specific INTRINSIC procedure "
1696 "for the reference '%s' at %L", sym
->name
,
1701 sym
->attr
.intrinsic
= 1;
1702 sym
->attr
.function
= 1;
1705 if (gfc_resolve_expr (e
) == FAILURE
)
1710 /* See if the name is a module procedure in a parent unit. */
1712 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1715 if (gfc_find_sym_tree (sym
->name
, sym
->ns
->parent
, 1, &parent_st
))
1717 gfc_error ("Symbol '%s' at %L is ambiguous", sym
->name
, &e
->where
);
1721 if (parent_st
== NULL
)
1724 sym
= parent_st
->n
.sym
;
1725 e
->symtree
= parent_st
; /* Point to the right thing. */
1727 if (sym
->attr
.flavor
== FL_PROCEDURE
1728 || sym
->attr
.intrinsic
1729 || sym
->attr
.external
)
1731 if (gfc_resolve_expr (e
) == FAILURE
)
1737 e
->expr_type
= EXPR_VARIABLE
;
1739 if (sym
->as
!= NULL
)
1741 e
->rank
= sym
->as
->rank
;
1742 e
->ref
= gfc_get_ref ();
1743 e
->ref
->type
= REF_ARRAY
;
1744 e
->ref
->u
.ar
.type
= AR_FULL
;
1745 e
->ref
->u
.ar
.as
= sym
->as
;
1748 /* Expressions are assigned a default ts.type of BT_PROCEDURE in
1749 primary.c (match_actual_arg). If above code determines that it
1750 is a variable instead, it needs to be resolved as it was not
1751 done at the beginning of this function. */
1752 save_need_full_assumed_size
= need_full_assumed_size
;
1753 if (e
->expr_type
!= EXPR_VARIABLE
)
1754 need_full_assumed_size
= 0;
1755 if (gfc_resolve_expr (e
) != SUCCESS
)
1757 need_full_assumed_size
= save_need_full_assumed_size
;
1760 /* Check argument list functions %VAL, %LOC and %REF. There is
1761 nothing to do for %REF. */
1762 if (arg
->name
&& arg
->name
[0] == '%')
1764 if (strncmp ("%VAL", arg
->name
, 4) == 0)
1766 if (e
->ts
.type
== BT_CHARACTER
|| e
->ts
.type
== BT_DERIVED
)
1768 gfc_error ("By-value argument at %L is not of numeric "
1775 gfc_error ("By-value argument at %L cannot be an array or "
1776 "an array section", &e
->where
);
1780 /* Intrinsics are still PROC_UNKNOWN here. However,
1781 since same file external procedures are not resolvable
1782 in gfortran, it is a good deal easier to leave them to
1784 if (ptype
!= PROC_UNKNOWN
1785 && ptype
!= PROC_DUMMY
1786 && ptype
!= PROC_EXTERNAL
1787 && ptype
!= PROC_MODULE
)
1789 gfc_error ("By-value argument at %L is not allowed "
1790 "in this context", &e
->where
);
1795 /* Statement functions have already been excluded above. */
1796 else if (strncmp ("%LOC", arg
->name
, 4) == 0
1797 && e
->ts
.type
== BT_PROCEDURE
)
1799 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_INTERNAL
)
1801 gfc_error ("Passing internal procedure at %L by location "
1802 "not allowed", &e
->where
);
1808 /* Fortran 2008, C1237. */
1809 if (e
->expr_type
== EXPR_VARIABLE
&& gfc_is_coindexed (e
)
1810 && gfc_has_ultimate_pointer (e
))
1812 gfc_error ("Coindexed actual argument at %L with ultimate pointer "
1813 "component", &e
->where
);
1822 /* Do the checks of the actual argument list that are specific to elemental
1823 procedures. If called with c == NULL, we have a function, otherwise if
1824 expr == NULL, we have a subroutine. */
1827 resolve_elemental_actual (gfc_expr
*expr
, gfc_code
*c
)
1829 gfc_actual_arglist
*arg0
;
1830 gfc_actual_arglist
*arg
;
1831 gfc_symbol
*esym
= NULL
;
1832 gfc_intrinsic_sym
*isym
= NULL
;
1834 gfc_intrinsic_arg
*iformal
= NULL
;
1835 gfc_formal_arglist
*eformal
= NULL
;
1836 bool formal_optional
= false;
1837 bool set_by_optional
= false;
1841 /* Is this an elemental procedure? */
1842 if (expr
&& expr
->value
.function
.actual
!= NULL
)
1844 if (expr
->value
.function
.esym
!= NULL
1845 && expr
->value
.function
.esym
->attr
.elemental
)
1847 arg0
= expr
->value
.function
.actual
;
1848 esym
= expr
->value
.function
.esym
;
1850 else if (expr
->value
.function
.isym
!= NULL
1851 && expr
->value
.function
.isym
->elemental
)
1853 arg0
= expr
->value
.function
.actual
;
1854 isym
= expr
->value
.function
.isym
;
1859 else if (c
&& c
->ext
.actual
!= NULL
)
1861 arg0
= c
->ext
.actual
;
1863 if (c
->resolved_sym
)
1864 esym
= c
->resolved_sym
;
1866 esym
= c
->symtree
->n
.sym
;
1869 if (!esym
->attr
.elemental
)
1875 /* The rank of an elemental is the rank of its array argument(s). */
1876 for (arg
= arg0
; arg
; arg
= arg
->next
)
1878 if (arg
->expr
!= NULL
&& arg
->expr
->rank
> 0)
1880 rank
= arg
->expr
->rank
;
1881 if (arg
->expr
->expr_type
== EXPR_VARIABLE
1882 && arg
->expr
->symtree
->n
.sym
->attr
.optional
)
1883 set_by_optional
= true;
1885 /* Function specific; set the result rank and shape. */
1889 if (!expr
->shape
&& arg
->expr
->shape
)
1891 expr
->shape
= gfc_get_shape (rank
);
1892 for (i
= 0; i
< rank
; i
++)
1893 mpz_init_set (expr
->shape
[i
], arg
->expr
->shape
[i
]);
1900 /* If it is an array, it shall not be supplied as an actual argument
1901 to an elemental procedure unless an array of the same rank is supplied
1902 as an actual argument corresponding to a nonoptional dummy argument of
1903 that elemental procedure(12.4.1.5). */
1904 formal_optional
= false;
1906 iformal
= isym
->formal
;
1908 eformal
= esym
->formal
;
1910 for (arg
= arg0
; arg
; arg
= arg
->next
)
1914 if (eformal
->sym
&& eformal
->sym
->attr
.optional
)
1915 formal_optional
= true;
1916 eformal
= eformal
->next
;
1918 else if (isym
&& iformal
)
1920 if (iformal
->optional
)
1921 formal_optional
= true;
1922 iformal
= iformal
->next
;
1925 formal_optional
= true;
1927 if (pedantic
&& arg
->expr
!= NULL
1928 && arg
->expr
->expr_type
== EXPR_VARIABLE
1929 && arg
->expr
->symtree
->n
.sym
->attr
.optional
1932 && (set_by_optional
|| arg
->expr
->rank
!= rank
)
1933 && !(isym
&& isym
->id
== GFC_ISYM_CONVERSION
))
1935 gfc_warning ("'%s' at %L is an array and OPTIONAL; IF IT IS "
1936 "MISSING, it cannot be the actual argument of an "
1937 "ELEMENTAL procedure unless there is a non-optional "
1938 "argument with the same rank (12.4.1.5)",
1939 arg
->expr
->symtree
->n
.sym
->name
, &arg
->expr
->where
);
1944 for (arg
= arg0
; arg
; arg
= arg
->next
)
1946 if (arg
->expr
== NULL
|| arg
->expr
->rank
== 0)
1949 /* Being elemental, the last upper bound of an assumed size array
1950 argument must be present. */
1951 if (resolve_assumed_size_actual (arg
->expr
))
1954 /* Elemental procedure's array actual arguments must conform. */
1957 if (gfc_check_conformance (arg
->expr
, e
,
1958 "elemental procedure") == FAILURE
)
1965 /* INTENT(OUT) is only allowed for subroutines; if any actual argument
1966 is an array, the intent inout/out variable needs to be also an array. */
1967 if (rank
> 0 && esym
&& expr
== NULL
)
1968 for (eformal
= esym
->formal
, arg
= arg0
; arg
&& eformal
;
1969 arg
= arg
->next
, eformal
= eformal
->next
)
1970 if ((eformal
->sym
->attr
.intent
== INTENT_OUT
1971 || eformal
->sym
->attr
.intent
== INTENT_INOUT
)
1972 && arg
->expr
&& arg
->expr
->rank
== 0)
1974 gfc_error ("Actual argument at %L for INTENT(%s) dummy '%s' of "
1975 "ELEMENTAL subroutine '%s' is a scalar, but another "
1976 "actual argument is an array", &arg
->expr
->where
,
1977 (eformal
->sym
->attr
.intent
== INTENT_OUT
) ? "OUT"
1978 : "INOUT", eformal
->sym
->name
, esym
->name
);
1985 /* This function does the checking of references to global procedures
1986 as defined in sections 18.1 and 14.1, respectively, of the Fortran
1987 77 and 95 standards. It checks for a gsymbol for the name, making
1988 one if it does not already exist. If it already exists, then the
1989 reference being resolved must correspond to the type of gsymbol.
1990 Otherwise, the new symbol is equipped with the attributes of the
1991 reference. The corresponding code that is called in creating
1992 global entities is parse.c.
1994 In addition, for all but -std=legacy, the gsymbols are used to
1995 check the interfaces of external procedures from the same file.
1996 The namespace of the gsymbol is resolved and then, once this is
1997 done the interface is checked. */
2001 not_in_recursive (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2003 if (!gsym_ns
->proc_name
->attr
.recursive
)
2006 if (sym
->ns
== gsym_ns
)
2009 if (sym
->ns
->parent
&& sym
->ns
->parent
== gsym_ns
)
2016 not_entry_self_reference (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2018 if (gsym_ns
->entries
)
2020 gfc_entry_list
*entry
= gsym_ns
->entries
;
2022 for (; entry
; entry
= entry
->next
)
2024 if (strcmp (sym
->name
, entry
->sym
->name
) == 0)
2026 if (strcmp (gsym_ns
->proc_name
->name
,
2027 sym
->ns
->proc_name
->name
) == 0)
2031 && strcmp (gsym_ns
->proc_name
->name
,
2032 sym
->ns
->parent
->proc_name
->name
) == 0)
2041 resolve_global_procedure (gfc_symbol
*sym
, locus
*where
,
2042 gfc_actual_arglist
**actual
, int sub
)
2046 enum gfc_symbol_type type
;
2048 type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
2050 gsym
= gfc_get_gsymbol (sym
->name
);
2052 if ((gsym
->type
!= GSYM_UNKNOWN
&& gsym
->type
!= type
))
2053 gfc_global_used (gsym
, where
);
2055 if (gfc_option
.flag_whole_file
2056 && (sym
->attr
.if_source
== IFSRC_UNKNOWN
2057 || sym
->attr
.if_source
== IFSRC_IFBODY
)
2058 && gsym
->type
!= GSYM_UNKNOWN
2060 && gsym
->ns
->resolved
!= -1
2061 && gsym
->ns
->proc_name
2062 && not_in_recursive (sym
, gsym
->ns
)
2063 && not_entry_self_reference (sym
, gsym
->ns
))
2065 gfc_symbol
*def_sym
;
2067 /* Resolve the gsymbol namespace if needed. */
2068 if (!gsym
->ns
->resolved
)
2070 gfc_dt_list
*old_dt_list
;
2071 struct gfc_omp_saved_state old_omp_state
;
2073 /* Stash away derived types so that the backend_decls do not
2075 old_dt_list
= gfc_derived_types
;
2076 gfc_derived_types
= NULL
;
2077 /* And stash away openmp state. */
2078 gfc_omp_save_and_clear_state (&old_omp_state
);
2080 gfc_resolve (gsym
->ns
);
2082 /* Store the new derived types with the global namespace. */
2083 if (gfc_derived_types
)
2084 gsym
->ns
->derived_types
= gfc_derived_types
;
2086 /* Restore the derived types of this namespace. */
2087 gfc_derived_types
= old_dt_list
;
2088 /* And openmp state. */
2089 gfc_omp_restore_state (&old_omp_state
);
2092 /* Make sure that translation for the gsymbol occurs before
2093 the procedure currently being resolved. */
2094 ns
= gfc_global_ns_list
;
2095 for (; ns
&& ns
!= gsym
->ns
; ns
= ns
->sibling
)
2097 if (ns
->sibling
== gsym
->ns
)
2099 ns
->sibling
= gsym
->ns
->sibling
;
2100 gsym
->ns
->sibling
= gfc_global_ns_list
;
2101 gfc_global_ns_list
= gsym
->ns
;
2106 def_sym
= gsym
->ns
->proc_name
;
2107 if (def_sym
->attr
.entry_master
)
2109 gfc_entry_list
*entry
;
2110 for (entry
= gsym
->ns
->entries
; entry
; entry
= entry
->next
)
2111 if (strcmp (entry
->sym
->name
, sym
->name
) == 0)
2113 def_sym
= entry
->sym
;
2118 /* Differences in constant character lengths. */
2119 if (sym
->attr
.function
&& sym
->ts
.type
== BT_CHARACTER
)
2121 long int l1
= 0, l2
= 0;
2122 gfc_charlen
*cl1
= sym
->ts
.u
.cl
;
2123 gfc_charlen
*cl2
= def_sym
->ts
.u
.cl
;
2126 && cl1
->length
!= NULL
2127 && cl1
->length
->expr_type
== EXPR_CONSTANT
)
2128 l1
= mpz_get_si (cl1
->length
->value
.integer
);
2131 && cl2
->length
!= NULL
2132 && cl2
->length
->expr_type
== EXPR_CONSTANT
)
2133 l2
= mpz_get_si (cl2
->length
->value
.integer
);
2135 if (l1
&& l2
&& l1
!= l2
)
2136 gfc_error ("Character length mismatch in return type of "
2137 "function '%s' at %L (%ld/%ld)", sym
->name
,
2138 &sym
->declared_at
, l1
, l2
);
2141 /* Type mismatch of function return type and expected type. */
2142 if (sym
->attr
.function
2143 && !gfc_compare_types (&sym
->ts
, &def_sym
->ts
))
2144 gfc_error ("Return type mismatch of function '%s' at %L (%s/%s)",
2145 sym
->name
, &sym
->declared_at
, gfc_typename (&sym
->ts
),
2146 gfc_typename (&def_sym
->ts
));
2148 if (def_sym
->formal
&& sym
->attr
.if_source
!= IFSRC_IFBODY
)
2150 gfc_formal_arglist
*arg
= def_sym
->formal
;
2151 for ( ; arg
; arg
= arg
->next
)
2154 /* F2003, 12.3.1.1 (2a); F2008, 12.4.2.2 (2a) */
2155 else if (arg
->sym
->attr
.allocatable
2156 || arg
->sym
->attr
.asynchronous
2157 || arg
->sym
->attr
.optional
2158 || arg
->sym
->attr
.pointer
2159 || arg
->sym
->attr
.target
2160 || arg
->sym
->attr
.value
2161 || arg
->sym
->attr
.volatile_
)
2163 gfc_error ("Dummy argument '%s' of procedure '%s' at %L "
2164 "has an attribute that requires an explicit "
2165 "interface for this procedure", arg
->sym
->name
,
2166 sym
->name
, &sym
->declared_at
);
2169 /* F2003, 12.3.1.1 (2b); F2008, 12.4.2.2 (2b) */
2170 else if (arg
->sym
&& arg
->sym
->as
2171 && arg
->sym
->as
->type
== AS_ASSUMED_SHAPE
)
2173 gfc_error ("Procedure '%s' at %L with assumed-shape dummy "
2174 "argument '%s' must have an explicit interface",
2175 sym
->name
, &sym
->declared_at
, arg
->sym
->name
);
2178 /* F2008, 12.4.2.2 (2c) */
2179 else if (arg
->sym
->attr
.codimension
)
2181 gfc_error ("Procedure '%s' at %L with coarray dummy argument "
2182 "'%s' must have an explicit interface",
2183 sym
->name
, &sym
->declared_at
, arg
->sym
->name
);
2186 /* F2003, 12.3.1.1 (2c); F2008, 12.4.2.2 (2d) */
2187 else if (false) /* TODO: is a parametrized derived type */
2189 gfc_error ("Procedure '%s' at %L with parametrized derived "
2190 "type argument '%s' must have an explicit "
2191 "interface", sym
->name
, &sym
->declared_at
,
2195 /* F2003, 12.3.1.1 (2d); F2008, 12.4.2.2 (2e) */
2196 else if (arg
->sym
->ts
.type
== BT_CLASS
)
2198 gfc_error ("Procedure '%s' at %L with polymorphic dummy "
2199 "argument '%s' must have an explicit interface",
2200 sym
->name
, &sym
->declared_at
, arg
->sym
->name
);
2205 if (def_sym
->attr
.function
)
2207 /* F2003, 12.3.1.1 (3a); F2008, 12.4.2.2 (3a) */
2208 if (def_sym
->as
&& def_sym
->as
->rank
2209 && (!sym
->as
|| sym
->as
->rank
!= def_sym
->as
->rank
))
2210 gfc_error ("The reference to function '%s' at %L either needs an "
2211 "explicit INTERFACE or the rank is incorrect", sym
->name
,
2214 /* F2003, 12.3.1.1 (3b); F2008, 12.4.2.2 (3b) */
2215 if ((def_sym
->result
->attr
.pointer
2216 || def_sym
->result
->attr
.allocatable
)
2217 && (sym
->attr
.if_source
!= IFSRC_IFBODY
2218 || def_sym
->result
->attr
.pointer
2219 != sym
->result
->attr
.pointer
2220 || def_sym
->result
->attr
.allocatable
2221 != sym
->result
->attr
.allocatable
))
2222 gfc_error ("Function '%s' at %L with a POINTER or ALLOCATABLE "
2223 "result must have an explicit interface", sym
->name
,
2226 /* F2003, 12.3.1.1 (3c); F2008, 12.4.2.2 (3c) */
2227 if (sym
->ts
.type
== BT_CHARACTER
&& sym
->attr
.if_source
!= IFSRC_IFBODY
2228 && def_sym
->ts
.type
== BT_CHARACTER
&& def_sym
->ts
.u
.cl
->length
!= NULL
)
2230 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
2232 if (!sym
->attr
.entry_master
&& sym
->attr
.if_source
== IFSRC_UNKNOWN
2233 && cl
&& cl
->length
&& cl
->length
->expr_type
!= EXPR_CONSTANT
)
2235 gfc_error ("Nonconstant character-length function '%s' at %L "
2236 "must have an explicit interface", sym
->name
,
2242 /* F2003, 12.3.1.1 (4); F2008, 12.4.2.2 (4) */
2243 if (def_sym
->attr
.elemental
&& !sym
->attr
.elemental
)
2245 gfc_error ("ELEMENTAL procedure '%s' at %L must have an explicit "
2246 "interface", sym
->name
, &sym
->declared_at
);
2249 /* F2003, 12.3.1.1 (5); F2008, 12.4.2.2 (5) */
2250 if (def_sym
->attr
.is_bind_c
&& !sym
->attr
.is_bind_c
)
2252 gfc_error ("Procedure '%s' at %L with BIND(C) attribute must have "
2253 "an explicit interface", sym
->name
, &sym
->declared_at
);
2256 if (gfc_option
.flag_whole_file
== 1
2257 || ((gfc_option
.warn_std
& GFC_STD_LEGACY
)
2258 && !(gfc_option
.warn_std
& GFC_STD_GNU
)))
2259 gfc_errors_to_warnings (1);
2261 if (sym
->attr
.if_source
!= IFSRC_IFBODY
)
2262 gfc_procedure_use (def_sym
, actual
, where
);
2264 gfc_errors_to_warnings (0);
2267 if (gsym
->type
== GSYM_UNKNOWN
)
2270 gsym
->where
= *where
;
2277 /************* Function resolution *************/
2279 /* Resolve a function call known to be generic.
2280 Section 14.1.2.4.1. */
2283 resolve_generic_f0 (gfc_expr
*expr
, gfc_symbol
*sym
)
2287 if (sym
->attr
.generic
)
2289 s
= gfc_search_interface (sym
->generic
, 0, &expr
->value
.function
.actual
);
2292 expr
->value
.function
.name
= s
->name
;
2293 expr
->value
.function
.esym
= s
;
2295 if (s
->ts
.type
!= BT_UNKNOWN
)
2297 else if (s
->result
!= NULL
&& s
->result
->ts
.type
!= BT_UNKNOWN
)
2298 expr
->ts
= s
->result
->ts
;
2301 expr
->rank
= s
->as
->rank
;
2302 else if (s
->result
!= NULL
&& s
->result
->as
!= NULL
)
2303 expr
->rank
= s
->result
->as
->rank
;
2305 gfc_set_sym_referenced (expr
->value
.function
.esym
);
2310 /* TODO: Need to search for elemental references in generic
2314 if (sym
->attr
.intrinsic
)
2315 return gfc_intrinsic_func_interface (expr
, 0);
2322 resolve_generic_f (gfc_expr
*expr
)
2327 sym
= expr
->symtree
->n
.sym
;
2331 m
= resolve_generic_f0 (expr
, sym
);
2334 else if (m
== MATCH_ERROR
)
2338 if (sym
->ns
->parent
== NULL
)
2340 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2344 if (!generic_sym (sym
))
2348 /* Last ditch attempt. See if the reference is to an intrinsic
2349 that possesses a matching interface. 14.1.2.4 */
2350 if (sym
&& !gfc_is_intrinsic (sym
, 0, expr
->where
))
2352 gfc_error ("There is no specific function for the generic '%s' at %L",
2353 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2357 m
= gfc_intrinsic_func_interface (expr
, 0);
2361 gfc_error ("Generic function '%s' at %L is not consistent with a "
2362 "specific intrinsic interface", expr
->symtree
->n
.sym
->name
,
2369 /* Resolve a function call known to be specific. */
2372 resolve_specific_f0 (gfc_symbol
*sym
, gfc_expr
*expr
)
2376 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
2378 if (sym
->attr
.dummy
)
2380 sym
->attr
.proc
= PROC_DUMMY
;
2384 sym
->attr
.proc
= PROC_EXTERNAL
;
2388 if (sym
->attr
.proc
== PROC_MODULE
2389 || sym
->attr
.proc
== PROC_ST_FUNCTION
2390 || sym
->attr
.proc
== PROC_INTERNAL
)
2393 if (sym
->attr
.intrinsic
)
2395 m
= gfc_intrinsic_func_interface (expr
, 1);
2399 gfc_error ("Function '%s' at %L is INTRINSIC but is not compatible "
2400 "with an intrinsic", sym
->name
, &expr
->where
);
2408 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2411 expr
->ts
= sym
->result
->ts
;
2414 expr
->value
.function
.name
= sym
->name
;
2415 expr
->value
.function
.esym
= sym
;
2416 if (sym
->as
!= NULL
)
2417 expr
->rank
= sym
->as
->rank
;
2424 resolve_specific_f (gfc_expr
*expr
)
2429 sym
= expr
->symtree
->n
.sym
;
2433 m
= resolve_specific_f0 (sym
, expr
);
2436 if (m
== MATCH_ERROR
)
2439 if (sym
->ns
->parent
== NULL
)
2442 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2448 gfc_error ("Unable to resolve the specific function '%s' at %L",
2449 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2455 /* Resolve a procedure call not known to be generic nor specific. */
2458 resolve_unknown_f (gfc_expr
*expr
)
2463 sym
= expr
->symtree
->n
.sym
;
2465 if (sym
->attr
.dummy
)
2467 sym
->attr
.proc
= PROC_DUMMY
;
2468 expr
->value
.function
.name
= sym
->name
;
2472 /* See if we have an intrinsic function reference. */
2474 if (gfc_is_intrinsic (sym
, 0, expr
->where
))
2476 if (gfc_intrinsic_func_interface (expr
, 1) == MATCH_YES
)
2481 /* The reference is to an external name. */
2483 sym
->attr
.proc
= PROC_EXTERNAL
;
2484 expr
->value
.function
.name
= sym
->name
;
2485 expr
->value
.function
.esym
= expr
->symtree
->n
.sym
;
2487 if (sym
->as
!= NULL
)
2488 expr
->rank
= sym
->as
->rank
;
2490 /* Type of the expression is either the type of the symbol or the
2491 default type of the symbol. */
2494 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2496 if (sym
->ts
.type
!= BT_UNKNOWN
)
2500 ts
= gfc_get_default_type (sym
->name
, sym
->ns
);
2502 if (ts
->type
== BT_UNKNOWN
)
2504 gfc_error ("Function '%s' at %L has no IMPLICIT type",
2505 sym
->name
, &expr
->where
);
2516 /* Return true, if the symbol is an external procedure. */
2518 is_external_proc (gfc_symbol
*sym
)
2520 if (!sym
->attr
.dummy
&& !sym
->attr
.contained
2521 && !(sym
->attr
.intrinsic
2522 || gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, sym
->declared_at
))
2523 && sym
->attr
.proc
!= PROC_ST_FUNCTION
2524 && !sym
->attr
.proc_pointer
2525 && !sym
->attr
.use_assoc
2533 /* Figure out if a function reference is pure or not. Also set the name
2534 of the function for a potential error message. Return nonzero if the
2535 function is PURE, zero if not. */
2537 pure_stmt_function (gfc_expr
*, gfc_symbol
*);
2540 pure_function (gfc_expr
*e
, const char **name
)
2546 if (e
->symtree
!= NULL
2547 && e
->symtree
->n
.sym
!= NULL
2548 && e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2549 return pure_stmt_function (e
, e
->symtree
->n
.sym
);
2551 if (e
->value
.function
.esym
)
2553 pure
= gfc_pure (e
->value
.function
.esym
);
2554 *name
= e
->value
.function
.esym
->name
;
2556 else if (e
->value
.function
.isym
)
2558 pure
= e
->value
.function
.isym
->pure
2559 || e
->value
.function
.isym
->elemental
;
2560 *name
= e
->value
.function
.isym
->name
;
2564 /* Implicit functions are not pure. */
2566 *name
= e
->value
.function
.name
;
2574 impure_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
,
2575 int *f ATTRIBUTE_UNUSED
)
2579 /* Don't bother recursing into other statement functions
2580 since they will be checked individually for purity. */
2581 if (e
->expr_type
!= EXPR_FUNCTION
2583 || e
->symtree
->n
.sym
== sym
2584 || e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2587 return pure_function (e
, &name
) ? false : true;
2592 pure_stmt_function (gfc_expr
*e
, gfc_symbol
*sym
)
2594 return gfc_traverse_expr (e
, sym
, impure_stmt_fcn
, 0) ? 0 : 1;
2599 is_scalar_expr_ptr (gfc_expr
*expr
)
2601 gfc_try retval
= SUCCESS
;
2606 /* See if we have a gfc_ref, which means we have a substring, array
2607 reference, or a component. */
2608 if (expr
->ref
!= NULL
)
2611 while (ref
->next
!= NULL
)
2617 if (ref
->u
.ss
.start
== NULL
|| ref
->u
.ss
.end
== NULL
2618 || gfc_dep_compare_expr (ref
->u
.ss
.start
, ref
->u
.ss
.end
) != 0)
2623 if (ref
->u
.ar
.type
== AR_ELEMENT
)
2625 else if (ref
->u
.ar
.type
== AR_FULL
)
2627 /* The user can give a full array if the array is of size 1. */
2628 if (ref
->u
.ar
.as
!= NULL
2629 && ref
->u
.ar
.as
->rank
== 1
2630 && ref
->u
.ar
.as
->type
== AS_EXPLICIT
2631 && ref
->u
.ar
.as
->lower
[0] != NULL
2632 && ref
->u
.ar
.as
->lower
[0]->expr_type
== EXPR_CONSTANT
2633 && ref
->u
.ar
.as
->upper
[0] != NULL
2634 && ref
->u
.ar
.as
->upper
[0]->expr_type
== EXPR_CONSTANT
)
2636 /* If we have a character string, we need to check if
2637 its length is one. */
2638 if (expr
->ts
.type
== BT_CHARACTER
)
2640 if (expr
->ts
.u
.cl
== NULL
2641 || expr
->ts
.u
.cl
->length
== NULL
2642 || mpz_cmp_si (expr
->ts
.u
.cl
->length
->value
.integer
, 1)
2648 /* We have constant lower and upper bounds. If the
2649 difference between is 1, it can be considered a
2651 FIXME: Use gfc_dep_compare_expr instead. */
2652 start
= (int) mpz_get_si
2653 (ref
->u
.ar
.as
->lower
[0]->value
.integer
);
2654 end
= (int) mpz_get_si
2655 (ref
->u
.ar
.as
->upper
[0]->value
.integer
);
2656 if (end
- start
+ 1 != 1)
2671 else if (expr
->ts
.type
== BT_CHARACTER
&& expr
->rank
== 0)
2673 /* Character string. Make sure it's of length 1. */
2674 if (expr
->ts
.u
.cl
== NULL
2675 || expr
->ts
.u
.cl
->length
== NULL
2676 || mpz_cmp_si (expr
->ts
.u
.cl
->length
->value
.integer
, 1) != 0)
2679 else if (expr
->rank
!= 0)
2686 /* Match one of the iso_c_binding functions (c_associated or c_loc)
2687 and, in the case of c_associated, set the binding label based on
2691 gfc_iso_c_func_interface (gfc_symbol
*sym
, gfc_actual_arglist
*args
,
2692 gfc_symbol
**new_sym
)
2694 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2695 char binding_label
[GFC_MAX_BINDING_LABEL_LEN
+ 1];
2696 int optional_arg
= 0;
2697 gfc_try retval
= SUCCESS
;
2698 gfc_symbol
*args_sym
;
2699 gfc_typespec
*arg_ts
;
2700 symbol_attribute arg_attr
;
2702 if (args
->expr
->expr_type
== EXPR_CONSTANT
2703 || args
->expr
->expr_type
== EXPR_OP
2704 || args
->expr
->expr_type
== EXPR_NULL
)
2706 gfc_error ("Argument to '%s' at %L is not a variable",
2707 sym
->name
, &(args
->expr
->where
));
2711 args_sym
= args
->expr
->symtree
->n
.sym
;
2713 /* The typespec for the actual arg should be that stored in the expr
2714 and not necessarily that of the expr symbol (args_sym), because
2715 the actual expression could be a part-ref of the expr symbol. */
2716 arg_ts
= &(args
->expr
->ts
);
2717 arg_attr
= gfc_expr_attr (args
->expr
);
2719 if (sym
->intmod_sym_id
== ISOCBINDING_ASSOCIATED
)
2721 /* If the user gave two args then they are providing something for
2722 the optional arg (the second cptr). Therefore, set the name and
2723 binding label to the c_associated for two cptrs. Otherwise,
2724 set c_associated to expect one cptr. */
2728 sprintf (name
, "%s_2", sym
->name
);
2729 sprintf (binding_label
, "%s_2", sym
->binding_label
);
2735 sprintf (name
, "%s_1", sym
->name
);
2736 sprintf (binding_label
, "%s_1", sym
->binding_label
);
2740 /* Get a new symbol for the version of c_associated that
2742 *new_sym
= get_iso_c_sym (sym
, name
, binding_label
, optional_arg
);
2744 else if (sym
->intmod_sym_id
== ISOCBINDING_LOC
2745 || sym
->intmod_sym_id
== ISOCBINDING_FUNLOC
)
2747 sprintf (name
, "%s", sym
->name
);
2748 sprintf (binding_label
, "%s", sym
->binding_label
);
2750 /* Error check the call. */
2751 if (args
->next
!= NULL
)
2753 gfc_error_now ("More actual than formal arguments in '%s' "
2754 "call at %L", name
, &(args
->expr
->where
));
2757 else if (sym
->intmod_sym_id
== ISOCBINDING_LOC
)
2762 /* Make sure we have either the target or pointer attribute. */
2763 if (!arg_attr
.target
&& !arg_attr
.pointer
)
2765 gfc_error_now ("Parameter '%s' to '%s' at %L must be either "
2766 "a TARGET or an associated pointer",
2768 sym
->name
, &(args
->expr
->where
));
2772 if (gfc_is_coindexed (args
->expr
))
2774 gfc_error_now ("Coindexed argument not permitted"
2775 " in '%s' call at %L", name
,
2776 &(args
->expr
->where
));
2780 /* Follow references to make sure there are no array
2782 seen_section
= false;
2784 for (ref
=args
->expr
->ref
; ref
; ref
= ref
->next
)
2786 if (ref
->type
== REF_ARRAY
)
2788 if (ref
->u
.ar
.type
== AR_SECTION
)
2789 seen_section
= true;
2791 if (ref
->u
.ar
.type
!= AR_ELEMENT
)
2794 for (r
= ref
->next
; r
; r
=r
->next
)
2795 if (r
->type
== REF_COMPONENT
)
2797 gfc_error_now ("Array section not permitted"
2798 " in '%s' call at %L", name
,
2799 &(args
->expr
->where
));
2807 if (seen_section
&& retval
== SUCCESS
)
2808 gfc_warning ("Array section in '%s' call at %L", name
,
2809 &(args
->expr
->where
));
2811 /* See if we have interoperable type and type param. */
2812 if (gfc_verify_c_interop (arg_ts
) == SUCCESS
2813 || gfc_check_any_c_kind (arg_ts
) == SUCCESS
)
2815 if (args_sym
->attr
.target
== 1)
2817 /* Case 1a, section 15.1.2.5, J3/04-007: variable that
2818 has the target attribute and is interoperable. */
2819 /* Case 1b, section 15.1.2.5, J3/04-007: allocated
2820 allocatable variable that has the TARGET attribute and
2821 is not an array of zero size. */
2822 if (args_sym
->attr
.allocatable
== 1)
2824 if (args_sym
->attr
.dimension
!= 0
2825 && (args_sym
->as
&& args_sym
->as
->rank
== 0))
2827 gfc_error_now ("Allocatable variable '%s' used as a "
2828 "parameter to '%s' at %L must not be "
2829 "an array of zero size",
2830 args_sym
->name
, sym
->name
,
2831 &(args
->expr
->where
));
2837 /* A non-allocatable target variable with C
2838 interoperable type and type parameters must be
2840 if (args_sym
&& args_sym
->attr
.dimension
)
2842 if (args_sym
->as
->type
== AS_ASSUMED_SHAPE
)
2844 gfc_error ("Assumed-shape array '%s' at %L "
2845 "cannot be an argument to the "
2846 "procedure '%s' because "
2847 "it is not C interoperable",
2849 &(args
->expr
->where
), sym
->name
);
2852 else if (args_sym
->as
->type
== AS_DEFERRED
)
2854 gfc_error ("Deferred-shape array '%s' at %L "
2855 "cannot be an argument to the "
2856 "procedure '%s' because "
2857 "it is not C interoperable",
2859 &(args
->expr
->where
), sym
->name
);
2864 /* Make sure it's not a character string. Arrays of
2865 any type should be ok if the variable is of a C
2866 interoperable type. */
2867 if (arg_ts
->type
== BT_CHARACTER
)
2868 if (arg_ts
->u
.cl
!= NULL
2869 && (arg_ts
->u
.cl
->length
== NULL
2870 || arg_ts
->u
.cl
->length
->expr_type
2873 (arg_ts
->u
.cl
->length
->value
.integer
, 1)
2875 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2877 gfc_error_now ("CHARACTER argument '%s' to '%s' "
2878 "at %L must have a length of 1",
2879 args_sym
->name
, sym
->name
,
2880 &(args
->expr
->where
));
2885 else if (arg_attr
.pointer
2886 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2888 /* Case 1c, section 15.1.2.5, J3/04-007: an associated
2890 gfc_error_now ("Argument '%s' to '%s' at %L must be an "
2891 "associated scalar POINTER", args_sym
->name
,
2892 sym
->name
, &(args
->expr
->where
));
2898 /* The parameter is not required to be C interoperable. If it
2899 is not C interoperable, it must be a nonpolymorphic scalar
2900 with no length type parameters. It still must have either
2901 the pointer or target attribute, and it can be
2902 allocatable (but must be allocated when c_loc is called). */
2903 if (args
->expr
->rank
!= 0
2904 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2906 gfc_error_now ("Parameter '%s' to '%s' at %L must be a "
2907 "scalar", args_sym
->name
, sym
->name
,
2908 &(args
->expr
->where
));
2911 else if (arg_ts
->type
== BT_CHARACTER
2912 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2914 gfc_error_now ("CHARACTER argument '%s' to '%s' at "
2915 "%L must have a length of 1",
2916 args_sym
->name
, sym
->name
,
2917 &(args
->expr
->where
));
2920 else if (arg_ts
->type
== BT_CLASS
)
2922 gfc_error_now ("Parameter '%s' to '%s' at %L must not be "
2923 "polymorphic", args_sym
->name
, sym
->name
,
2924 &(args
->expr
->where
));
2929 else if (sym
->intmod_sym_id
== ISOCBINDING_FUNLOC
)
2931 if (args_sym
->attr
.flavor
!= FL_PROCEDURE
)
2933 /* TODO: Update this error message to allow for procedure
2934 pointers once they are implemented. */
2935 gfc_error_now ("Parameter '%s' to '%s' at %L must be a "
2937 args_sym
->name
, sym
->name
,
2938 &(args
->expr
->where
));
2941 else if (args_sym
->attr
.is_bind_c
!= 1)
2943 gfc_error_now ("Parameter '%s' to '%s' at %L must be "
2945 args_sym
->name
, sym
->name
,
2946 &(args
->expr
->where
));
2951 /* for c_loc/c_funloc, the new symbol is the same as the old one */
2956 gfc_internal_error ("gfc_iso_c_func_interface(): Unhandled "
2957 "iso_c_binding function: '%s'!\n", sym
->name
);
2964 /* Resolve a function call, which means resolving the arguments, then figuring
2965 out which entity the name refers to. */
2968 resolve_function (gfc_expr
*expr
)
2970 gfc_actual_arglist
*arg
;
2975 procedure_type p
= PROC_INTRINSIC
;
2976 bool no_formal_args
;
2980 sym
= expr
->symtree
->n
.sym
;
2982 /* If this is a procedure pointer component, it has already been resolved. */
2983 if (gfc_is_proc_ptr_comp (expr
, NULL
))
2986 if (sym
&& sym
->attr
.intrinsic
2987 && resolve_intrinsic (sym
, &expr
->where
) == FAILURE
)
2990 if (sym
&& (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.subroutine
))
2992 gfc_error ("'%s' at %L is not a function", sym
->name
, &expr
->where
);
2996 /* If this ia a deferred TBP with an abstract interface (which may
2997 of course be referenced), expr->value.function.esym will be set. */
2998 if (sym
&& sym
->attr
.abstract
&& !expr
->value
.function
.esym
)
3000 gfc_error ("ABSTRACT INTERFACE '%s' must not be referenced at %L",
3001 sym
->name
, &expr
->where
);
3005 /* Switch off assumed size checking and do this again for certain kinds
3006 of procedure, once the procedure itself is resolved. */
3007 need_full_assumed_size
++;
3009 if (expr
->symtree
&& expr
->symtree
->n
.sym
)
3010 p
= expr
->symtree
->n
.sym
->attr
.proc
;
3012 if (expr
->value
.function
.isym
&& expr
->value
.function
.isym
->inquiry
)
3013 inquiry_argument
= true;
3014 no_formal_args
= sym
&& is_external_proc (sym
) && sym
->formal
== NULL
;
3016 if (resolve_actual_arglist (expr
->value
.function
.actual
,
3017 p
, no_formal_args
) == FAILURE
)
3019 inquiry_argument
= false;
3023 inquiry_argument
= false;
3025 /* Need to setup the call to the correct c_associated, depending on
3026 the number of cptrs to user gives to compare. */
3027 if (sym
&& sym
->attr
.is_iso_c
== 1)
3029 if (gfc_iso_c_func_interface (sym
, expr
->value
.function
.actual
, &sym
)
3033 /* Get the symtree for the new symbol (resolved func).
3034 the old one will be freed later, when it's no longer used. */
3035 gfc_find_sym_tree (sym
->name
, sym
->ns
, 1, &(expr
->symtree
));
3038 /* Resume assumed_size checking. */
3039 need_full_assumed_size
--;
3041 /* If the procedure is external, check for usage. */
3042 if (sym
&& is_external_proc (sym
))
3043 resolve_global_procedure (sym
, &expr
->where
,
3044 &expr
->value
.function
.actual
, 0);
3046 if (sym
&& sym
->ts
.type
== BT_CHARACTER
3048 && sym
->ts
.u
.cl
->length
== NULL
3050 && !sym
->ts
.deferred
3051 && expr
->value
.function
.esym
== NULL
3052 && !sym
->attr
.contained
)
3054 /* Internal procedures are taken care of in resolve_contained_fntype. */
3055 gfc_error ("Function '%s' is declared CHARACTER(*) and cannot "
3056 "be used at %L since it is not a dummy argument",
3057 sym
->name
, &expr
->where
);
3061 /* See if function is already resolved. */
3063 if (expr
->value
.function
.name
!= NULL
)
3065 if (expr
->ts
.type
== BT_UNKNOWN
)
3071 /* Apply the rules of section 14.1.2. */
3073 switch (procedure_kind (sym
))
3076 t
= resolve_generic_f (expr
);
3079 case PTYPE_SPECIFIC
:
3080 t
= resolve_specific_f (expr
);
3084 t
= resolve_unknown_f (expr
);
3088 gfc_internal_error ("resolve_function(): bad function type");
3092 /* If the expression is still a function (it might have simplified),
3093 then we check to see if we are calling an elemental function. */
3095 if (expr
->expr_type
!= EXPR_FUNCTION
)
3098 temp
= need_full_assumed_size
;
3099 need_full_assumed_size
= 0;
3101 if (resolve_elemental_actual (expr
, NULL
) == FAILURE
)
3104 if (omp_workshare_flag
3105 && expr
->value
.function
.esym
3106 && ! gfc_elemental (expr
->value
.function
.esym
))
3108 gfc_error ("User defined non-ELEMENTAL function '%s' at %L not allowed "
3109 "in WORKSHARE construct", expr
->value
.function
.esym
->name
,
3114 #define GENERIC_ID expr->value.function.isym->id
3115 else if (expr
->value
.function
.actual
!= NULL
3116 && expr
->value
.function
.isym
!= NULL
3117 && GENERIC_ID
!= GFC_ISYM_LBOUND
3118 && GENERIC_ID
!= GFC_ISYM_LEN
3119 && GENERIC_ID
!= GFC_ISYM_LOC
3120 && GENERIC_ID
!= GFC_ISYM_PRESENT
)
3122 /* Array intrinsics must also have the last upper bound of an
3123 assumed size array argument. UBOUND and SIZE have to be
3124 excluded from the check if the second argument is anything
3127 for (arg
= expr
->value
.function
.actual
; arg
; arg
= arg
->next
)
3129 if ((GENERIC_ID
== GFC_ISYM_UBOUND
|| GENERIC_ID
== GFC_ISYM_SIZE
)
3130 && arg
->next
!= NULL
&& arg
->next
->expr
)
3132 if (arg
->next
->expr
->expr_type
!= EXPR_CONSTANT
)
3135 if (arg
->next
->name
&& strncmp(arg
->next
->name
, "kind", 4) == 0)
3138 if ((int)mpz_get_si (arg
->next
->expr
->value
.integer
)
3143 if (arg
->expr
!= NULL
3144 && arg
->expr
->rank
> 0
3145 && resolve_assumed_size_actual (arg
->expr
))
3151 need_full_assumed_size
= temp
;
3154 if (!pure_function (expr
, &name
) && name
)
3158 gfc_error ("Reference to non-PURE function '%s' at %L inside a "
3159 "FORALL %s", name
, &expr
->where
,
3160 forall_flag
== 2 ? "mask" : "block");
3163 else if (do_concurrent_flag
)
3165 gfc_error ("Reference to non-PURE function '%s' at %L inside a "
3166 "DO CONCURRENT %s", name
, &expr
->where
,
3167 do_concurrent_flag
== 2 ? "mask" : "block");
3170 else if (gfc_pure (NULL
))
3172 gfc_error ("Function reference to '%s' at %L is to a non-PURE "
3173 "procedure within a PURE procedure", name
, &expr
->where
);
3178 if (!pure_function (expr
, &name
) && name
&& gfc_implicit_pure (NULL
))
3179 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
3181 /* Functions without the RECURSIVE attribution are not allowed to
3182 * call themselves. */
3183 if (expr
->value
.function
.esym
&& !expr
->value
.function
.esym
->attr
.recursive
)
3186 esym
= expr
->value
.function
.esym
;
3188 if (is_illegal_recursion (esym
, gfc_current_ns
))
3190 if (esym
->attr
.entry
&& esym
->ns
->entries
)
3191 gfc_error ("ENTRY '%s' at %L cannot be called recursively, as"
3192 " function '%s' is not RECURSIVE",
3193 esym
->name
, &expr
->where
, esym
->ns
->entries
->sym
->name
);
3195 gfc_error ("Function '%s' at %L cannot be called recursively, as it"
3196 " is not RECURSIVE", esym
->name
, &expr
->where
);
3202 /* Character lengths of use associated functions may contains references to
3203 symbols not referenced from the current program unit otherwise. Make sure
3204 those symbols are marked as referenced. */
3206 if (expr
->ts
.type
== BT_CHARACTER
&& expr
->value
.function
.esym
3207 && expr
->value
.function
.esym
->attr
.use_assoc
)
3209 gfc_expr_set_symbols_referenced (expr
->ts
.u
.cl
->length
);
3212 /* Make sure that the expression has a typespec that works. */
3213 if (expr
->ts
.type
== BT_UNKNOWN
)
3215 if (expr
->symtree
->n
.sym
->result
3216 && expr
->symtree
->n
.sym
->result
->ts
.type
!= BT_UNKNOWN
3217 && !expr
->symtree
->n
.sym
->result
->attr
.proc_pointer
)
3218 expr
->ts
= expr
->symtree
->n
.sym
->result
->ts
;
3225 /************* Subroutine resolution *************/
3228 pure_subroutine (gfc_code
*c
, gfc_symbol
*sym
)
3234 gfc_error ("Subroutine call to '%s' in FORALL block at %L is not PURE",
3235 sym
->name
, &c
->loc
);
3236 else if (do_concurrent_flag
)
3237 gfc_error ("Subroutine call to '%s' in DO CONCURRENT block at %L is not "
3238 "PURE", sym
->name
, &c
->loc
);
3239 else if (gfc_pure (NULL
))
3240 gfc_error ("Subroutine call to '%s' at %L is not PURE", sym
->name
,
3246 resolve_generic_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3250 if (sym
->attr
.generic
)
3252 s
= gfc_search_interface (sym
->generic
, 1, &c
->ext
.actual
);
3255 c
->resolved_sym
= s
;
3256 pure_subroutine (c
, s
);
3260 /* TODO: Need to search for elemental references in generic interface. */
3263 if (sym
->attr
.intrinsic
)
3264 return gfc_intrinsic_sub_interface (c
, 0);
3271 resolve_generic_s (gfc_code
*c
)
3276 sym
= c
->symtree
->n
.sym
;
3280 m
= resolve_generic_s0 (c
, sym
);
3283 else if (m
== MATCH_ERROR
)
3287 if (sym
->ns
->parent
== NULL
)
3289 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3293 if (!generic_sym (sym
))
3297 /* Last ditch attempt. See if the reference is to an intrinsic
3298 that possesses a matching interface. 14.1.2.4 */
3299 sym
= c
->symtree
->n
.sym
;
3301 if (!gfc_is_intrinsic (sym
, 1, c
->loc
))
3303 gfc_error ("There is no specific subroutine for the generic '%s' at %L",
3304 sym
->name
, &c
->loc
);
3308 m
= gfc_intrinsic_sub_interface (c
, 0);
3312 gfc_error ("Generic subroutine '%s' at %L is not consistent with an "
3313 "intrinsic subroutine interface", sym
->name
, &c
->loc
);
3319 /* Set the name and binding label of the subroutine symbol in the call
3320 expression represented by 'c' to include the type and kind of the
3321 second parameter. This function is for resolving the appropriate
3322 version of c_f_pointer() and c_f_procpointer(). For example, a
3323 call to c_f_pointer() for a default integer pointer could have a
3324 name of c_f_pointer_i4. If no second arg exists, which is an error
3325 for these two functions, it defaults to the generic symbol's name
3326 and binding label. */
3329 set_name_and_label (gfc_code
*c
, gfc_symbol
*sym
,
3330 char *name
, char *binding_label
)
3332 gfc_expr
*arg
= NULL
;
3336 /* The second arg of c_f_pointer and c_f_procpointer determines
3337 the type and kind for the procedure name. */
3338 arg
= c
->ext
.actual
->next
->expr
;
3342 /* Set up the name to have the given symbol's name,
3343 plus the type and kind. */
3344 /* a derived type is marked with the type letter 'u' */
3345 if (arg
->ts
.type
== BT_DERIVED
)
3348 kind
= 0; /* set the kind as 0 for now */
3352 type
= gfc_type_letter (arg
->ts
.type
);
3353 kind
= arg
->ts
.kind
;
3356 if (arg
->ts
.type
== BT_CHARACTER
)
3357 /* Kind info for character strings not needed. */
3360 sprintf (name
, "%s_%c%d", sym
->name
, type
, kind
);
3361 /* Set up the binding label as the given symbol's label plus
3362 the type and kind. */
3363 sprintf (binding_label
, "%s_%c%d", sym
->binding_label
, type
, kind
);
3367 /* If the second arg is missing, set the name and label as
3368 was, cause it should at least be found, and the missing
3369 arg error will be caught by compare_parameters(). */
3370 sprintf (name
, "%s", sym
->name
);
3371 sprintf (binding_label
, "%s", sym
->binding_label
);
3378 /* Resolve a generic version of the iso_c_binding procedure given
3379 (sym) to the specific one based on the type and kind of the
3380 argument(s). Currently, this function resolves c_f_pointer() and
3381 c_f_procpointer based on the type and kind of the second argument
3382 (FPTR). Other iso_c_binding procedures aren't specially handled.
3383 Upon successfully exiting, c->resolved_sym will hold the resolved
3384 symbol. Returns MATCH_ERROR if an error occurred; MATCH_YES
3388 gfc_iso_c_sub_interface (gfc_code
*c
, gfc_symbol
*sym
)
3390 gfc_symbol
*new_sym
;
3391 /* this is fine, since we know the names won't use the max */
3392 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3393 char binding_label
[GFC_MAX_BINDING_LABEL_LEN
+ 1];
3394 /* default to success; will override if find error */
3395 match m
= MATCH_YES
;
3397 /* Make sure the actual arguments are in the necessary order (based on the
3398 formal args) before resolving. */
3399 gfc_procedure_use (sym
, &c
->ext
.actual
, &(c
->loc
));
3401 if ((sym
->intmod_sym_id
== ISOCBINDING_F_POINTER
) ||
3402 (sym
->intmod_sym_id
== ISOCBINDING_F_PROCPOINTER
))
3404 set_name_and_label (c
, sym
, name
, binding_label
);
3406 if (sym
->intmod_sym_id
== ISOCBINDING_F_POINTER
)
3408 if (c
->ext
.actual
!= NULL
&& c
->ext
.actual
->next
!= NULL
)
3410 /* Make sure we got a third arg if the second arg has non-zero
3411 rank. We must also check that the type and rank are
3412 correct since we short-circuit this check in
3413 gfc_procedure_use() (called above to sort actual args). */
3414 if (c
->ext
.actual
->next
->expr
->rank
!= 0)
3416 if(c
->ext
.actual
->next
->next
== NULL
3417 || c
->ext
.actual
->next
->next
->expr
== NULL
)
3420 gfc_error ("Missing SHAPE parameter for call to %s "
3421 "at %L", sym
->name
, &(c
->loc
));
3423 else if (c
->ext
.actual
->next
->next
->expr
->ts
.type
3425 || c
->ext
.actual
->next
->next
->expr
->rank
!= 1)
3428 gfc_error ("SHAPE parameter for call to %s at %L must "
3429 "be a rank 1 INTEGER array", sym
->name
,
3436 if (m
!= MATCH_ERROR
)
3438 /* the 1 means to add the optional arg to formal list */
3439 new_sym
= get_iso_c_sym (sym
, name
, binding_label
, 1);
3441 /* for error reporting, say it's declared where the original was */
3442 new_sym
->declared_at
= sym
->declared_at
;
3447 /* no differences for c_loc or c_funloc */
3451 /* set the resolved symbol */
3452 if (m
!= MATCH_ERROR
)
3453 c
->resolved_sym
= new_sym
;
3455 c
->resolved_sym
= sym
;
3461 /* Resolve a subroutine call known to be specific. */
3464 resolve_specific_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3468 if(sym
->attr
.is_iso_c
)
3470 m
= gfc_iso_c_sub_interface (c
,sym
);
3474 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
3476 if (sym
->attr
.dummy
)
3478 sym
->attr
.proc
= PROC_DUMMY
;
3482 sym
->attr
.proc
= PROC_EXTERNAL
;
3486 if (sym
->attr
.proc
== PROC_MODULE
|| sym
->attr
.proc
== PROC_INTERNAL
)
3489 if (sym
->attr
.intrinsic
)
3491 m
= gfc_intrinsic_sub_interface (c
, 1);
3495 gfc_error ("Subroutine '%s' at %L is INTRINSIC but is not compatible "
3496 "with an intrinsic", sym
->name
, &c
->loc
);
3504 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3506 c
->resolved_sym
= sym
;
3507 pure_subroutine (c
, sym
);
3514 resolve_specific_s (gfc_code
*c
)
3519 sym
= c
->symtree
->n
.sym
;
3523 m
= resolve_specific_s0 (c
, sym
);
3526 if (m
== MATCH_ERROR
)
3529 if (sym
->ns
->parent
== NULL
)
3532 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3538 sym
= c
->symtree
->n
.sym
;
3539 gfc_error ("Unable to resolve the specific subroutine '%s' at %L",
3540 sym
->name
, &c
->loc
);
3546 /* Resolve a subroutine call not known to be generic nor specific. */
3549 resolve_unknown_s (gfc_code
*c
)
3553 sym
= c
->symtree
->n
.sym
;
3555 if (sym
->attr
.dummy
)
3557 sym
->attr
.proc
= PROC_DUMMY
;
3561 /* See if we have an intrinsic function reference. */
3563 if (gfc_is_intrinsic (sym
, 1, c
->loc
))
3565 if (gfc_intrinsic_sub_interface (c
, 1) == MATCH_YES
)
3570 /* The reference is to an external name. */
3573 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3575 c
->resolved_sym
= sym
;
3577 pure_subroutine (c
, sym
);
3583 /* Resolve a subroutine call. Although it was tempting to use the same code
3584 for functions, subroutines and functions are stored differently and this
3585 makes things awkward. */
3588 resolve_call (gfc_code
*c
)
3591 procedure_type ptype
= PROC_INTRINSIC
;
3592 gfc_symbol
*csym
, *sym
;
3593 bool no_formal_args
;
3595 csym
= c
->symtree
? c
->symtree
->n
.sym
: NULL
;
3597 if (csym
&& csym
->ts
.type
!= BT_UNKNOWN
)
3599 gfc_error ("'%s' at %L has a type, which is not consistent with "
3600 "the CALL at %L", csym
->name
, &csym
->declared_at
, &c
->loc
);
3604 if (csym
&& gfc_current_ns
->parent
&& csym
->ns
!= gfc_current_ns
)
3607 gfc_find_sym_tree (csym
->name
, gfc_current_ns
, 1, &st
);
3608 sym
= st
? st
->n
.sym
: NULL
;
3609 if (sym
&& csym
!= sym
3610 && sym
->ns
== gfc_current_ns
3611 && sym
->attr
.flavor
== FL_PROCEDURE
3612 && sym
->attr
.contained
)
3615 if (csym
->attr
.generic
)
3616 c
->symtree
->n
.sym
= sym
;
3619 csym
= c
->symtree
->n
.sym
;
3623 /* If this ia a deferred TBP with an abstract interface
3624 (which may of course be referenced), c->expr1 will be set. */
3625 if (csym
&& csym
->attr
.abstract
&& !c
->expr1
)
3627 gfc_error ("ABSTRACT INTERFACE '%s' must not be referenced at %L",
3628 csym
->name
, &c
->loc
);
3632 /* Subroutines without the RECURSIVE attribution are not allowed to
3633 * call themselves. */
3634 if (csym
&& is_illegal_recursion (csym
, gfc_current_ns
))
3636 if (csym
->attr
.entry
&& csym
->ns
->entries
)
3637 gfc_error ("ENTRY '%s' at %L cannot be called recursively, as"
3638 " subroutine '%s' is not RECURSIVE",
3639 csym
->name
, &c
->loc
, csym
->ns
->entries
->sym
->name
);
3641 gfc_error ("SUBROUTINE '%s' at %L cannot be called recursively, as it"
3642 " is not RECURSIVE", csym
->name
, &c
->loc
);
3647 /* Switch off assumed size checking and do this again for certain kinds
3648 of procedure, once the procedure itself is resolved. */
3649 need_full_assumed_size
++;
3652 ptype
= csym
->attr
.proc
;
3654 no_formal_args
= csym
&& is_external_proc (csym
) && csym
->formal
== NULL
;
3655 if (resolve_actual_arglist (c
->ext
.actual
, ptype
,
3656 no_formal_args
) == FAILURE
)
3659 /* Resume assumed_size checking. */
3660 need_full_assumed_size
--;
3662 /* If external, check for usage. */
3663 if (csym
&& is_external_proc (csym
))
3664 resolve_global_procedure (csym
, &c
->loc
, &c
->ext
.actual
, 1);
3667 if (c
->resolved_sym
== NULL
)
3669 c
->resolved_isym
= NULL
;
3670 switch (procedure_kind (csym
))
3673 t
= resolve_generic_s (c
);
3676 case PTYPE_SPECIFIC
:
3677 t
= resolve_specific_s (c
);
3681 t
= resolve_unknown_s (c
);
3685 gfc_internal_error ("resolve_subroutine(): bad function type");
3689 /* Some checks of elemental subroutine actual arguments. */
3690 if (resolve_elemental_actual (NULL
, c
) == FAILURE
)
3697 /* Compare the shapes of two arrays that have non-NULL shapes. If both
3698 op1->shape and op2->shape are non-NULL return SUCCESS if their shapes
3699 match. If both op1->shape and op2->shape are non-NULL return FAILURE
3700 if their shapes do not match. If either op1->shape or op2->shape is
3701 NULL, return SUCCESS. */
3704 compare_shapes (gfc_expr
*op1
, gfc_expr
*op2
)
3711 if (op1
->shape
!= NULL
&& op2
->shape
!= NULL
)
3713 for (i
= 0; i
< op1
->rank
; i
++)
3715 if (mpz_cmp (op1
->shape
[i
], op2
->shape
[i
]) != 0)
3717 gfc_error ("Shapes for operands at %L and %L are not conformable",
3718 &op1
->where
, &op2
->where
);
3729 /* Resolve an operator expression node. This can involve replacing the
3730 operation with a user defined function call. */
3733 resolve_operator (gfc_expr
*e
)
3735 gfc_expr
*op1
, *op2
;
3737 bool dual_locus_error
;
3740 /* Resolve all subnodes-- give them types. */
3742 switch (e
->value
.op
.op
)
3745 if (gfc_resolve_expr (e
->value
.op
.op2
) == FAILURE
)
3748 /* Fall through... */
3751 case INTRINSIC_UPLUS
:
3752 case INTRINSIC_UMINUS
:
3753 case INTRINSIC_PARENTHESES
:
3754 if (gfc_resolve_expr (e
->value
.op
.op1
) == FAILURE
)
3759 /* Typecheck the new node. */
3761 op1
= e
->value
.op
.op1
;
3762 op2
= e
->value
.op
.op2
;
3763 dual_locus_error
= false;
3765 if ((op1
&& op1
->expr_type
== EXPR_NULL
)
3766 || (op2
&& op2
->expr_type
== EXPR_NULL
))
3768 sprintf (msg
, _("Invalid context for NULL() pointer at %%L"));
3772 switch (e
->value
.op
.op
)
3774 case INTRINSIC_UPLUS
:
3775 case INTRINSIC_UMINUS
:
3776 if (op1
->ts
.type
== BT_INTEGER
3777 || op1
->ts
.type
== BT_REAL
3778 || op1
->ts
.type
== BT_COMPLEX
)
3784 sprintf (msg
, _("Operand of unary numeric operator '%s' at %%L is %s"),
3785 gfc_op2string (e
->value
.op
.op
), gfc_typename (&e
->ts
));
3788 case INTRINSIC_PLUS
:
3789 case INTRINSIC_MINUS
:
3790 case INTRINSIC_TIMES
:
3791 case INTRINSIC_DIVIDE
:
3792 case INTRINSIC_POWER
:
3793 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3795 gfc_type_convert_binary (e
, 1);
3800 _("Operands of binary numeric operator '%s' at %%L are %s/%s"),
3801 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3802 gfc_typename (&op2
->ts
));
3805 case INTRINSIC_CONCAT
:
3806 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3807 && op1
->ts
.kind
== op2
->ts
.kind
)
3809 e
->ts
.type
= BT_CHARACTER
;
3810 e
->ts
.kind
= op1
->ts
.kind
;
3815 _("Operands of string concatenation operator at %%L are %s/%s"),
3816 gfc_typename (&op1
->ts
), gfc_typename (&op2
->ts
));
3822 case INTRINSIC_NEQV
:
3823 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3825 e
->ts
.type
= BT_LOGICAL
;
3826 e
->ts
.kind
= gfc_kind_max (op1
, op2
);
3827 if (op1
->ts
.kind
< e
->ts
.kind
)
3828 gfc_convert_type (op1
, &e
->ts
, 2);
3829 else if (op2
->ts
.kind
< e
->ts
.kind
)
3830 gfc_convert_type (op2
, &e
->ts
, 2);
3834 sprintf (msg
, _("Operands of logical operator '%s' at %%L are %s/%s"),
3835 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3836 gfc_typename (&op2
->ts
));
3841 if (op1
->ts
.type
== BT_LOGICAL
)
3843 e
->ts
.type
= BT_LOGICAL
;
3844 e
->ts
.kind
= op1
->ts
.kind
;
3848 sprintf (msg
, _("Operand of .not. operator at %%L is %s"),
3849 gfc_typename (&op1
->ts
));
3853 case INTRINSIC_GT_OS
:
3855 case INTRINSIC_GE_OS
:
3857 case INTRINSIC_LT_OS
:
3859 case INTRINSIC_LE_OS
:
3860 if (op1
->ts
.type
== BT_COMPLEX
|| op2
->ts
.type
== BT_COMPLEX
)
3862 strcpy (msg
, _("COMPLEX quantities cannot be compared at %L"));
3866 /* Fall through... */
3869 case INTRINSIC_EQ_OS
:
3871 case INTRINSIC_NE_OS
:
3872 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3873 && op1
->ts
.kind
== op2
->ts
.kind
)
3875 e
->ts
.type
= BT_LOGICAL
;
3876 e
->ts
.kind
= gfc_default_logical_kind
;
3880 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3882 gfc_type_convert_binary (e
, 1);
3884 e
->ts
.type
= BT_LOGICAL
;
3885 e
->ts
.kind
= gfc_default_logical_kind
;
3889 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3891 _("Logicals at %%L must be compared with %s instead of %s"),
3892 (e
->value
.op
.op
== INTRINSIC_EQ
3893 || e
->value
.op
.op
== INTRINSIC_EQ_OS
)
3894 ? ".eqv." : ".neqv.", gfc_op2string (e
->value
.op
.op
));
3897 _("Operands of comparison operator '%s' at %%L are %s/%s"),
3898 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3899 gfc_typename (&op2
->ts
));
3903 case INTRINSIC_USER
:
3904 if (e
->value
.op
.uop
->op
== NULL
)
3905 sprintf (msg
, _("Unknown operator '%s' at %%L"), e
->value
.op
.uop
->name
);
3906 else if (op2
== NULL
)
3907 sprintf (msg
, _("Operand of user operator '%s' at %%L is %s"),
3908 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
));
3911 sprintf (msg
, _("Operands of user operator '%s' at %%L are %s/%s"),
3912 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
),
3913 gfc_typename (&op2
->ts
));
3914 e
->value
.op
.uop
->op
->sym
->attr
.referenced
= 1;
3919 case INTRINSIC_PARENTHESES
:
3921 if (e
->ts
.type
== BT_CHARACTER
)
3922 e
->ts
.u
.cl
= op1
->ts
.u
.cl
;
3926 gfc_internal_error ("resolve_operator(): Bad intrinsic");
3929 /* Deal with arrayness of an operand through an operator. */
3933 switch (e
->value
.op
.op
)
3935 case INTRINSIC_PLUS
:
3936 case INTRINSIC_MINUS
:
3937 case INTRINSIC_TIMES
:
3938 case INTRINSIC_DIVIDE
:
3939 case INTRINSIC_POWER
:
3940 case INTRINSIC_CONCAT
:
3944 case INTRINSIC_NEQV
:
3946 case INTRINSIC_EQ_OS
:
3948 case INTRINSIC_NE_OS
:
3950 case INTRINSIC_GT_OS
:
3952 case INTRINSIC_GE_OS
:
3954 case INTRINSIC_LT_OS
:
3956 case INTRINSIC_LE_OS
:
3958 if (op1
->rank
== 0 && op2
->rank
== 0)
3961 if (op1
->rank
== 0 && op2
->rank
!= 0)
3963 e
->rank
= op2
->rank
;
3965 if (e
->shape
== NULL
)
3966 e
->shape
= gfc_copy_shape (op2
->shape
, op2
->rank
);
3969 if (op1
->rank
!= 0 && op2
->rank
== 0)
3971 e
->rank
= op1
->rank
;
3973 if (e
->shape
== NULL
)
3974 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3977 if (op1
->rank
!= 0 && op2
->rank
!= 0)
3979 if (op1
->rank
== op2
->rank
)
3981 e
->rank
= op1
->rank
;
3982 if (e
->shape
== NULL
)
3984 t
= compare_shapes (op1
, op2
);
3988 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3993 /* Allow higher level expressions to work. */
3996 /* Try user-defined operators, and otherwise throw an error. */
3997 dual_locus_error
= true;
3999 _("Inconsistent ranks for operator at %%L and %%L"));
4006 case INTRINSIC_PARENTHESES
:
4008 case INTRINSIC_UPLUS
:
4009 case INTRINSIC_UMINUS
:
4010 /* Simply copy arrayness attribute */
4011 e
->rank
= op1
->rank
;
4013 if (e
->shape
== NULL
)
4014 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
4022 /* Attempt to simplify the expression. */
4025 t
= gfc_simplify_expr (e
, 0);
4026 /* Some calls do not succeed in simplification and return FAILURE
4027 even though there is no error; e.g. variable references to
4028 PARAMETER arrays. */
4029 if (!gfc_is_constant_expr (e
))
4038 if (gfc_extend_expr (e
, &real_error
) == SUCCESS
)
4045 if (dual_locus_error
)
4046 gfc_error (msg
, &op1
->where
, &op2
->where
);
4048 gfc_error (msg
, &e
->where
);
4054 /************** Array resolution subroutines **************/
4057 { CMP_LT
, CMP_EQ
, CMP_GT
, CMP_UNKNOWN
}
4060 /* Compare two integer expressions. */
4063 compare_bound (gfc_expr
*a
, gfc_expr
*b
)
4067 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
4068 || b
== NULL
|| b
->expr_type
!= EXPR_CONSTANT
)
4071 /* If either of the types isn't INTEGER, we must have
4072 raised an error earlier. */
4074 if (a
->ts
.type
!= BT_INTEGER
|| b
->ts
.type
!= BT_INTEGER
)
4077 i
= mpz_cmp (a
->value
.integer
, b
->value
.integer
);
4087 /* Compare an integer expression with an integer. */
4090 compare_bound_int (gfc_expr
*a
, int b
)
4094 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
4097 if (a
->ts
.type
!= BT_INTEGER
)
4098 gfc_internal_error ("compare_bound_int(): Bad expression");
4100 i
= mpz_cmp_si (a
->value
.integer
, b
);
4110 /* Compare an integer expression with a mpz_t. */
4113 compare_bound_mpz_t (gfc_expr
*a
, mpz_t b
)
4117 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
4120 if (a
->ts
.type
!= BT_INTEGER
)
4121 gfc_internal_error ("compare_bound_int(): Bad expression");
4123 i
= mpz_cmp (a
->value
.integer
, b
);
4133 /* Compute the last value of a sequence given by a triplet.
4134 Return 0 if it wasn't able to compute the last value, or if the
4135 sequence if empty, and 1 otherwise. */
4138 compute_last_value_for_triplet (gfc_expr
*start
, gfc_expr
*end
,
4139 gfc_expr
*stride
, mpz_t last
)
4143 if (start
== NULL
|| start
->expr_type
!= EXPR_CONSTANT
4144 || end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
4145 || (stride
!= NULL
&& stride
->expr_type
!= EXPR_CONSTANT
))
4148 if (start
->ts
.type
!= BT_INTEGER
|| end
->ts
.type
!= BT_INTEGER
4149 || (stride
!= NULL
&& stride
->ts
.type
!= BT_INTEGER
))
4152 if (stride
== NULL
|| compare_bound_int(stride
, 1) == CMP_EQ
)
4154 if (compare_bound (start
, end
) == CMP_GT
)
4156 mpz_set (last
, end
->value
.integer
);
4160 if (compare_bound_int (stride
, 0) == CMP_GT
)
4162 /* Stride is positive */
4163 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) > 0)
4168 /* Stride is negative */
4169 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) < 0)
4174 mpz_sub (rem
, end
->value
.integer
, start
->value
.integer
);
4175 mpz_tdiv_r (rem
, rem
, stride
->value
.integer
);
4176 mpz_sub (last
, end
->value
.integer
, rem
);
4183 /* Compare a single dimension of an array reference to the array
4187 check_dimension (int i
, gfc_array_ref
*ar
, gfc_array_spec
*as
)
4191 if (ar
->dimen_type
[i
] == DIMEN_STAR
)
4193 gcc_assert (ar
->stride
[i
] == NULL
);
4194 /* This implies [*] as [*:] and [*:3] are not possible. */
4195 if (ar
->start
[i
] == NULL
)
4197 gcc_assert (ar
->end
[i
] == NULL
);
4202 /* Given start, end and stride values, calculate the minimum and
4203 maximum referenced indexes. */
4205 switch (ar
->dimen_type
[i
])
4208 case DIMEN_THIS_IMAGE
:
4213 if (compare_bound (ar
->start
[i
], as
->lower
[i
]) == CMP_LT
)
4216 gfc_warning ("Array reference at %L is out of bounds "
4217 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4218 mpz_get_si (ar
->start
[i
]->value
.integer
),
4219 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4221 gfc_warning ("Array reference at %L is out of bounds "
4222 "(%ld < %ld) in codimension %d", &ar
->c_where
[i
],
4223 mpz_get_si (ar
->start
[i
]->value
.integer
),
4224 mpz_get_si (as
->lower
[i
]->value
.integer
),
4228 if (compare_bound (ar
->start
[i
], as
->upper
[i
]) == CMP_GT
)
4231 gfc_warning ("Array reference at %L is out of bounds "
4232 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4233 mpz_get_si (ar
->start
[i
]->value
.integer
),
4234 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4236 gfc_warning ("Array reference at %L is out of bounds "
4237 "(%ld > %ld) in codimension %d", &ar
->c_where
[i
],
4238 mpz_get_si (ar
->start
[i
]->value
.integer
),
4239 mpz_get_si (as
->upper
[i
]->value
.integer
),
4248 #define AR_START (ar->start[i] ? ar->start[i] : as->lower[i])
4249 #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i])
4251 comparison comp_start_end
= compare_bound (AR_START
, AR_END
);
4253 /* Check for zero stride, which is not allowed. */
4254 if (compare_bound_int (ar
->stride
[i
], 0) == CMP_EQ
)
4256 gfc_error ("Illegal stride of zero at %L", &ar
->c_where
[i
]);
4260 /* if start == len || (stride > 0 && start < len)
4261 || (stride < 0 && start > len),
4262 then the array section contains at least one element. In this
4263 case, there is an out-of-bounds access if
4264 (start < lower || start > upper). */
4265 if (compare_bound (AR_START
, AR_END
) == CMP_EQ
4266 || ((compare_bound_int (ar
->stride
[i
], 0) == CMP_GT
4267 || ar
->stride
[i
] == NULL
) && comp_start_end
== CMP_LT
)
4268 || (compare_bound_int (ar
->stride
[i
], 0) == CMP_LT
4269 && comp_start_end
== CMP_GT
))
4271 if (compare_bound (AR_START
, as
->lower
[i
]) == CMP_LT
)
4273 gfc_warning ("Lower array reference at %L is out of bounds "
4274 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4275 mpz_get_si (AR_START
->value
.integer
),
4276 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4279 if (compare_bound (AR_START
, as
->upper
[i
]) == CMP_GT
)
4281 gfc_warning ("Lower array reference at %L is out of bounds "
4282 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4283 mpz_get_si (AR_START
->value
.integer
),
4284 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4289 /* If we can compute the highest index of the array section,
4290 then it also has to be between lower and upper. */
4291 mpz_init (last_value
);
4292 if (compute_last_value_for_triplet (AR_START
, AR_END
, ar
->stride
[i
],
4295 if (compare_bound_mpz_t (as
->lower
[i
], last_value
) == CMP_GT
)
4297 gfc_warning ("Upper array reference at %L is out of bounds "
4298 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4299 mpz_get_si (last_value
),
4300 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4301 mpz_clear (last_value
);
4304 if (compare_bound_mpz_t (as
->upper
[i
], last_value
) == CMP_LT
)
4306 gfc_warning ("Upper array reference at %L is out of bounds "
4307 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4308 mpz_get_si (last_value
),
4309 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4310 mpz_clear (last_value
);
4314 mpz_clear (last_value
);
4322 gfc_internal_error ("check_dimension(): Bad array reference");
4329 /* Compare an array reference with an array specification. */
4332 compare_spec_to_ref (gfc_array_ref
*ar
)
4339 /* TODO: Full array sections are only allowed as actual parameters. */
4340 if (as
->type
== AS_ASSUMED_SIZE
4341 && (/*ar->type == AR_FULL
4342 ||*/ (ar
->type
== AR_SECTION
4343 && ar
->dimen_type
[i
] == DIMEN_RANGE
&& ar
->end
[i
] == NULL
)))
4345 gfc_error ("Rightmost upper bound of assumed size array section "
4346 "not specified at %L", &ar
->where
);
4350 if (ar
->type
== AR_FULL
)
4353 if (as
->rank
!= ar
->dimen
)
4355 gfc_error ("Rank mismatch in array reference at %L (%d/%d)",
4356 &ar
->where
, ar
->dimen
, as
->rank
);
4360 /* ar->codimen == 0 is a local array. */
4361 if (as
->corank
!= ar
->codimen
&& ar
->codimen
!= 0)
4363 gfc_error ("Coindex rank mismatch in array reference at %L (%d/%d)",
4364 &ar
->where
, ar
->codimen
, as
->corank
);
4368 for (i
= 0; i
< as
->rank
; i
++)
4369 if (check_dimension (i
, ar
, as
) == FAILURE
)
4372 /* Local access has no coarray spec. */
4373 if (ar
->codimen
!= 0)
4374 for (i
= as
->rank
; i
< as
->rank
+ as
->corank
; i
++)
4376 if (ar
->dimen_type
[i
] != DIMEN_ELEMENT
&& !ar
->in_allocate
4377 && ar
->dimen_type
[i
] != DIMEN_THIS_IMAGE
)
4379 gfc_error ("Coindex of codimension %d must be a scalar at %L",
4380 i
+ 1 - as
->rank
, &ar
->where
);
4383 if (check_dimension (i
, ar
, as
) == FAILURE
)
4391 /* Resolve one part of an array index. */
4394 gfc_resolve_index_1 (gfc_expr
*index
, int check_scalar
,
4395 int force_index_integer_kind
)
4402 if (gfc_resolve_expr (index
) == FAILURE
)
4405 if (check_scalar
&& index
->rank
!= 0)
4407 gfc_error ("Array index at %L must be scalar", &index
->where
);
4411 if (index
->ts
.type
!= BT_INTEGER
&& index
->ts
.type
!= BT_REAL
)
4413 gfc_error ("Array index at %L must be of INTEGER type, found %s",
4414 &index
->where
, gfc_basic_typename (index
->ts
.type
));
4418 if (index
->ts
.type
== BT_REAL
)
4419 if (gfc_notify_std (GFC_STD_LEGACY
, "Extension: REAL array index at %L",
4420 &index
->where
) == FAILURE
)
4423 if ((index
->ts
.kind
!= gfc_index_integer_kind
4424 && force_index_integer_kind
)
4425 || index
->ts
.type
!= BT_INTEGER
)
4428 ts
.type
= BT_INTEGER
;
4429 ts
.kind
= gfc_index_integer_kind
;
4431 gfc_convert_type_warn (index
, &ts
, 2, 0);
4437 /* Resolve one part of an array index. */
4440 gfc_resolve_index (gfc_expr
*index
, int check_scalar
)
4442 return gfc_resolve_index_1 (index
, check_scalar
, 1);
4445 /* Resolve a dim argument to an intrinsic function. */
4448 gfc_resolve_dim_arg (gfc_expr
*dim
)
4453 if (gfc_resolve_expr (dim
) == FAILURE
)
4458 gfc_error ("Argument dim at %L must be scalar", &dim
->where
);
4463 if (dim
->ts
.type
!= BT_INTEGER
)
4465 gfc_error ("Argument dim at %L must be of INTEGER type", &dim
->where
);
4469 if (dim
->ts
.kind
!= gfc_index_integer_kind
)
4474 ts
.type
= BT_INTEGER
;
4475 ts
.kind
= gfc_index_integer_kind
;
4477 gfc_convert_type_warn (dim
, &ts
, 2, 0);
4483 /* Given an expression that contains array references, update those array
4484 references to point to the right array specifications. While this is
4485 filled in during matching, this information is difficult to save and load
4486 in a module, so we take care of it here.
4488 The idea here is that the original array reference comes from the
4489 base symbol. We traverse the list of reference structures, setting
4490 the stored reference to references. Component references can
4491 provide an additional array specification. */
4494 find_array_spec (gfc_expr
*e
)
4498 gfc_symbol
*derived
;
4501 if (e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
)
4502 as
= CLASS_DATA (e
->symtree
->n
.sym
)->as
;
4504 as
= e
->symtree
->n
.sym
->as
;
4507 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4512 gfc_internal_error ("find_array_spec(): Missing spec");
4519 if (derived
== NULL
)
4520 derived
= e
->symtree
->n
.sym
->ts
.u
.derived
;
4522 if (derived
->attr
.is_class
)
4523 derived
= derived
->components
->ts
.u
.derived
;
4525 c
= derived
->components
;
4527 for (; c
; c
= c
->next
)
4528 if (c
== ref
->u
.c
.component
)
4530 /* Track the sequence of component references. */
4531 if (c
->ts
.type
== BT_DERIVED
)
4532 derived
= c
->ts
.u
.derived
;
4537 gfc_internal_error ("find_array_spec(): Component not found");
4539 if (c
->attr
.dimension
)
4542 gfc_internal_error ("find_array_spec(): unused as(1)");
4553 gfc_internal_error ("find_array_spec(): unused as(2)");
4557 /* Resolve an array reference. */
4560 resolve_array_ref (gfc_array_ref
*ar
)
4562 int i
, check_scalar
;
4565 for (i
= 0; i
< ar
->dimen
+ ar
->codimen
; i
++)
4567 check_scalar
= ar
->dimen_type
[i
] == DIMEN_RANGE
;
4569 /* Do not force gfc_index_integer_kind for the start. We can
4570 do fine with any integer kind. This avoids temporary arrays
4571 created for indexing with a vector. */
4572 if (gfc_resolve_index_1 (ar
->start
[i
], check_scalar
, 0) == FAILURE
)
4574 if (gfc_resolve_index (ar
->end
[i
], check_scalar
) == FAILURE
)
4576 if (gfc_resolve_index (ar
->stride
[i
], check_scalar
) == FAILURE
)
4581 if (ar
->dimen_type
[i
] == DIMEN_UNKNOWN
)
4585 ar
->dimen_type
[i
] = DIMEN_ELEMENT
;
4589 ar
->dimen_type
[i
] = DIMEN_VECTOR
;
4590 if (e
->expr_type
== EXPR_VARIABLE
4591 && e
->symtree
->n
.sym
->ts
.type
== BT_DERIVED
)
4592 ar
->start
[i
] = gfc_get_parentheses (e
);
4596 gfc_error ("Array index at %L is an array of rank %d",
4597 &ar
->c_where
[i
], e
->rank
);
4601 /* Fill in the upper bound, which may be lower than the
4602 specified one for something like a(2:10:5), which is
4603 identical to a(2:7:5). Only relevant for strides not equal
4604 to one. Don't try a division by zero. */
4605 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4606 && ar
->stride
[i
] != NULL
&& ar
->stride
[i
]->expr_type
== EXPR_CONSTANT
4607 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 1L) != 0
4608 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 0L) != 0)
4612 if (gfc_ref_dimen_size (ar
, i
, &size
, &end
) == SUCCESS
)
4614 if (ar
->end
[i
] == NULL
)
4617 gfc_get_constant_expr (BT_INTEGER
, gfc_index_integer_kind
,
4619 mpz_set (ar
->end
[i
]->value
.integer
, end
);
4621 else if (ar
->end
[i
]->ts
.type
== BT_INTEGER
4622 && ar
->end
[i
]->expr_type
== EXPR_CONSTANT
)
4624 mpz_set (ar
->end
[i
]->value
.integer
, end
);
4635 if (ar
->type
== AR_FULL
)
4637 if (ar
->as
->rank
== 0)
4638 ar
->type
= AR_ELEMENT
;
4640 /* Make sure array is the same as array(:,:), this way
4641 we don't need to special case all the time. */
4642 ar
->dimen
= ar
->as
->rank
;
4643 for (i
= 0; i
< ar
->dimen
; i
++)
4645 ar
->dimen_type
[i
] = DIMEN_RANGE
;
4647 gcc_assert (ar
->start
[i
] == NULL
);
4648 gcc_assert (ar
->end
[i
] == NULL
);
4649 gcc_assert (ar
->stride
[i
] == NULL
);
4653 /* If the reference type is unknown, figure out what kind it is. */
4655 if (ar
->type
== AR_UNKNOWN
)
4657 ar
->type
= AR_ELEMENT
;
4658 for (i
= 0; i
< ar
->dimen
; i
++)
4659 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4660 || ar
->dimen_type
[i
] == DIMEN_VECTOR
)
4662 ar
->type
= AR_SECTION
;
4667 if (!ar
->as
->cray_pointee
&& compare_spec_to_ref (ar
) == FAILURE
)
4670 if (ar
->as
->corank
&& ar
->codimen
== 0)
4673 ar
->codimen
= ar
->as
->corank
;
4674 for (n
= ar
->dimen
; n
< ar
->dimen
+ ar
->codimen
; n
++)
4675 ar
->dimen_type
[n
] = DIMEN_THIS_IMAGE
;
4683 resolve_substring (gfc_ref
*ref
)
4685 int k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
4687 if (ref
->u
.ss
.start
!= NULL
)
4689 if (gfc_resolve_expr (ref
->u
.ss
.start
) == FAILURE
)
4692 if (ref
->u
.ss
.start
->ts
.type
!= BT_INTEGER
)
4694 gfc_error ("Substring start index at %L must be of type INTEGER",
4695 &ref
->u
.ss
.start
->where
);
4699 if (ref
->u
.ss
.start
->rank
!= 0)
4701 gfc_error ("Substring start index at %L must be scalar",
4702 &ref
->u
.ss
.start
->where
);
4706 if (compare_bound_int (ref
->u
.ss
.start
, 1) == CMP_LT
4707 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4708 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4710 gfc_error ("Substring start index at %L is less than one",
4711 &ref
->u
.ss
.start
->where
);
4716 if (ref
->u
.ss
.end
!= NULL
)
4718 if (gfc_resolve_expr (ref
->u
.ss
.end
) == FAILURE
)
4721 if (ref
->u
.ss
.end
->ts
.type
!= BT_INTEGER
)
4723 gfc_error ("Substring end index at %L must be of type INTEGER",
4724 &ref
->u
.ss
.end
->where
);
4728 if (ref
->u
.ss
.end
->rank
!= 0)
4730 gfc_error ("Substring end index at %L must be scalar",
4731 &ref
->u
.ss
.end
->where
);
4735 if (ref
->u
.ss
.length
!= NULL
4736 && compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.length
->length
) == CMP_GT
4737 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4738 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4740 gfc_error ("Substring end index at %L exceeds the string length",
4741 &ref
->u
.ss
.start
->where
);
4745 if (compare_bound_mpz_t (ref
->u
.ss
.end
,
4746 gfc_integer_kinds
[k
].huge
) == CMP_GT
4747 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4748 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4750 gfc_error ("Substring end index at %L is too large",
4751 &ref
->u
.ss
.end
->where
);
4760 /* This function supplies missing substring charlens. */
4763 gfc_resolve_substring_charlen (gfc_expr
*e
)
4766 gfc_expr
*start
, *end
;
4768 for (char_ref
= e
->ref
; char_ref
; char_ref
= char_ref
->next
)
4769 if (char_ref
->type
== REF_SUBSTRING
)
4775 gcc_assert (char_ref
->next
== NULL
);
4779 if (e
->ts
.u
.cl
->length
)
4780 gfc_free_expr (e
->ts
.u
.cl
->length
);
4781 else if (e
->expr_type
== EXPR_VARIABLE
4782 && e
->symtree
->n
.sym
->attr
.dummy
)
4786 e
->ts
.type
= BT_CHARACTER
;
4787 e
->ts
.kind
= gfc_default_character_kind
;
4790 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
4792 if (char_ref
->u
.ss
.start
)
4793 start
= gfc_copy_expr (char_ref
->u
.ss
.start
);
4795 start
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
4797 if (char_ref
->u
.ss
.end
)
4798 end
= gfc_copy_expr (char_ref
->u
.ss
.end
);
4799 else if (e
->expr_type
== EXPR_VARIABLE
)
4800 end
= gfc_copy_expr (e
->symtree
->n
.sym
->ts
.u
.cl
->length
);
4807 /* Length = (end - start +1). */
4808 e
->ts
.u
.cl
->length
= gfc_subtract (end
, start
);
4809 e
->ts
.u
.cl
->length
= gfc_add (e
->ts
.u
.cl
->length
,
4810 gfc_get_int_expr (gfc_default_integer_kind
,
4813 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
4814 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
4816 /* Make sure that the length is simplified. */
4817 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 1);
4818 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
4822 /* Resolve subtype references. */
4825 resolve_ref (gfc_expr
*expr
)
4827 int current_part_dimension
, n_components
, seen_part_dimension
;
4830 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4831 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.as
== NULL
)
4833 find_array_spec (expr
);
4837 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4841 if (resolve_array_ref (&ref
->u
.ar
) == FAILURE
)
4849 if (resolve_substring (ref
) == FAILURE
)
4854 /* Check constraints on part references. */
4856 current_part_dimension
= 0;
4857 seen_part_dimension
= 0;
4860 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4865 switch (ref
->u
.ar
.type
)
4868 /* Coarray scalar. */
4869 if (ref
->u
.ar
.as
->rank
== 0)
4871 current_part_dimension
= 0;
4876 current_part_dimension
= 1;
4880 current_part_dimension
= 0;
4884 gfc_internal_error ("resolve_ref(): Bad array reference");
4890 if (current_part_dimension
|| seen_part_dimension
)
4893 if (ref
->u
.c
.component
->attr
.pointer
4894 || ref
->u
.c
.component
->attr
.proc_pointer
)
4896 gfc_error ("Component to the right of a part reference "
4897 "with nonzero rank must not have the POINTER "
4898 "attribute at %L", &expr
->where
);
4901 else if (ref
->u
.c
.component
->attr
.allocatable
)
4903 gfc_error ("Component to the right of a part reference "
4904 "with nonzero rank must not have the ALLOCATABLE "
4905 "attribute at %L", &expr
->where
);
4917 if (((ref
->type
== REF_COMPONENT
&& n_components
> 1)
4918 || ref
->next
== NULL
)
4919 && current_part_dimension
4920 && seen_part_dimension
)
4922 gfc_error ("Two or more part references with nonzero rank must "
4923 "not be specified at %L", &expr
->where
);
4927 if (ref
->type
== REF_COMPONENT
)
4929 if (current_part_dimension
)
4930 seen_part_dimension
= 1;
4932 /* reset to make sure */
4933 current_part_dimension
= 0;
4941 /* Given an expression, determine its shape. This is easier than it sounds.
4942 Leaves the shape array NULL if it is not possible to determine the shape. */
4945 expression_shape (gfc_expr
*e
)
4947 mpz_t array
[GFC_MAX_DIMENSIONS
];
4950 if (e
->rank
== 0 || e
->shape
!= NULL
)
4953 for (i
= 0; i
< e
->rank
; i
++)
4954 if (gfc_array_dimen_size (e
, i
, &array
[i
]) == FAILURE
)
4957 e
->shape
= gfc_get_shape (e
->rank
);
4959 memcpy (e
->shape
, array
, e
->rank
* sizeof (mpz_t
));
4964 for (i
--; i
>= 0; i
--)
4965 mpz_clear (array
[i
]);
4969 /* Given a variable expression node, compute the rank of the expression by
4970 examining the base symbol and any reference structures it may have. */
4973 expression_rank (gfc_expr
*e
)
4978 /* Just to make sure, because EXPR_COMPCALL's also have an e->ref and that
4979 could lead to serious confusion... */
4980 gcc_assert (e
->expr_type
!= EXPR_COMPCALL
);
4984 if (e
->expr_type
== EXPR_ARRAY
)
4986 /* Constructors can have a rank different from one via RESHAPE(). */
4988 if (e
->symtree
== NULL
)
4994 e
->rank
= (e
->symtree
->n
.sym
->as
== NULL
)
4995 ? 0 : e
->symtree
->n
.sym
->as
->rank
;
5001 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5003 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.proc_pointer
5004 && ref
->u
.c
.component
->attr
.function
&& !ref
->next
)
5005 rank
= ref
->u
.c
.component
->as
? ref
->u
.c
.component
->as
->rank
: 0;
5007 if (ref
->type
!= REF_ARRAY
)
5010 if (ref
->u
.ar
.type
== AR_FULL
)
5012 rank
= ref
->u
.ar
.as
->rank
;
5016 if (ref
->u
.ar
.type
== AR_SECTION
)
5018 /* Figure out the rank of the section. */
5020 gfc_internal_error ("expression_rank(): Two array specs");
5022 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
5023 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_RANGE
5024 || ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
5034 expression_shape (e
);
5038 /* Resolve a variable expression. */
5041 resolve_variable (gfc_expr
*e
)
5048 if (e
->symtree
== NULL
)
5050 sym
= e
->symtree
->n
.sym
;
5052 /* If this is an associate-name, it may be parsed with an array reference
5053 in error even though the target is scalar. Fail directly in this case. */
5054 if (sym
->assoc
&& !sym
->attr
.dimension
&& e
->ref
&& e
->ref
->type
== REF_ARRAY
)
5057 /* On the other hand, the parser may not have known this is an array;
5058 in this case, we have to add a FULL reference. */
5059 if (sym
->assoc
&& sym
->attr
.dimension
&& !e
->ref
)
5061 e
->ref
= gfc_get_ref ();
5062 e
->ref
->type
= REF_ARRAY
;
5063 e
->ref
->u
.ar
.type
= AR_FULL
;
5064 e
->ref
->u
.ar
.dimen
= 0;
5067 if (e
->ref
&& resolve_ref (e
) == FAILURE
)
5070 if (sym
->attr
.flavor
== FL_PROCEDURE
5071 && (!sym
->attr
.function
5072 || (sym
->attr
.function
&& sym
->result
5073 && sym
->result
->attr
.proc_pointer
5074 && !sym
->result
->attr
.function
)))
5076 e
->ts
.type
= BT_PROCEDURE
;
5077 goto resolve_procedure
;
5080 if (sym
->ts
.type
!= BT_UNKNOWN
)
5081 gfc_variable_attr (e
, &e
->ts
);
5084 /* Must be a simple variable reference. */
5085 if (gfc_set_default_type (sym
, 1, sym
->ns
) == FAILURE
)
5090 if (check_assumed_size_reference (sym
, e
))
5093 /* Deal with forward references to entries during resolve_code, to
5094 satisfy, at least partially, 12.5.2.5. */
5095 if (gfc_current_ns
->entries
5096 && current_entry_id
== sym
->entry_id
5099 && cs_base
->current
->op
!= EXEC_ENTRY
)
5101 gfc_entry_list
*entry
;
5102 gfc_formal_arglist
*formal
;
5106 /* If the symbol is a dummy... */
5107 if (sym
->attr
.dummy
&& sym
->ns
== gfc_current_ns
)
5109 entry
= gfc_current_ns
->entries
;
5112 /* ...test if the symbol is a parameter of previous entries. */
5113 for (; entry
&& entry
->id
<= current_entry_id
; entry
= entry
->next
)
5114 for (formal
= entry
->sym
->formal
; formal
; formal
= formal
->next
)
5116 if (formal
->sym
&& sym
->name
== formal
->sym
->name
)
5120 /* If it has not been seen as a dummy, this is an error. */
5123 if (specification_expr
)
5124 gfc_error ("Variable '%s', used in a specification expression"
5125 ", is referenced at %L before the ENTRY statement "
5126 "in which it is a parameter",
5127 sym
->name
, &cs_base
->current
->loc
);
5129 gfc_error ("Variable '%s' is used at %L before the ENTRY "
5130 "statement in which it is a parameter",
5131 sym
->name
, &cs_base
->current
->loc
);
5136 /* Now do the same check on the specification expressions. */
5137 specification_expr
= 1;
5138 if (sym
->ts
.type
== BT_CHARACTER
5139 && gfc_resolve_expr (sym
->ts
.u
.cl
->length
) == FAILURE
)
5143 for (n
= 0; n
< sym
->as
->rank
; n
++)
5145 specification_expr
= 1;
5146 if (gfc_resolve_expr (sym
->as
->lower
[n
]) == FAILURE
)
5148 specification_expr
= 1;
5149 if (gfc_resolve_expr (sym
->as
->upper
[n
]) == FAILURE
)
5152 specification_expr
= 0;
5155 /* Update the symbol's entry level. */
5156 sym
->entry_id
= current_entry_id
+ 1;
5159 /* If a symbol has been host_associated mark it. This is used latter,
5160 to identify if aliasing is possible via host association. */
5161 if (sym
->attr
.flavor
== FL_VARIABLE
5162 && gfc_current_ns
->parent
5163 && (gfc_current_ns
->parent
== sym
->ns
5164 || (gfc_current_ns
->parent
->parent
5165 && gfc_current_ns
->parent
->parent
== sym
->ns
)))
5166 sym
->attr
.host_assoc
= 1;
5169 if (t
== SUCCESS
&& resolve_procedure_expression (e
) == FAILURE
)
5172 /* F2008, C617 and C1229. */
5173 if (!inquiry_argument
&& (e
->ts
.type
== BT_CLASS
|| e
->ts
.type
== BT_DERIVED
)
5174 && gfc_is_coindexed (e
))
5176 gfc_ref
*ref
, *ref2
= NULL
;
5178 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5180 if (ref
->type
== REF_COMPONENT
)
5182 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
5186 for ( ; ref
; ref
= ref
->next
)
5187 if (ref
->type
== REF_COMPONENT
)
5190 /* Expression itself is not coindexed object. */
5191 if (ref
&& e
->ts
.type
== BT_CLASS
)
5193 gfc_error ("Polymorphic subobject of coindexed object at %L",
5198 /* Expression itself is coindexed object. */
5202 c
= ref2
? ref2
->u
.c
.component
: e
->symtree
->n
.sym
->components
;
5203 for ( ; c
; c
= c
->next
)
5204 if (c
->attr
.allocatable
&& c
->ts
.type
== BT_CLASS
)
5206 gfc_error ("Coindexed object with polymorphic allocatable "
5207 "subcomponent at %L", &e
->where
);
5218 /* Checks to see that the correct symbol has been host associated.
5219 The only situation where this arises is that in which a twice
5220 contained function is parsed after the host association is made.
5221 Therefore, on detecting this, change the symbol in the expression
5222 and convert the array reference into an actual arglist if the old
5223 symbol is a variable. */
5225 check_host_association (gfc_expr
*e
)
5227 gfc_symbol
*sym
, *old_sym
;
5231 gfc_actual_arglist
*arg
, *tail
= NULL
;
5232 bool retval
= e
->expr_type
== EXPR_FUNCTION
;
5234 /* If the expression is the result of substitution in
5235 interface.c(gfc_extend_expr) because there is no way in
5236 which the host association can be wrong. */
5237 if (e
->symtree
== NULL
5238 || e
->symtree
->n
.sym
== NULL
5239 || e
->user_operator
)
5242 old_sym
= e
->symtree
->n
.sym
;
5244 if (gfc_current_ns
->parent
5245 && old_sym
->ns
!= gfc_current_ns
)
5247 /* Use the 'USE' name so that renamed module symbols are
5248 correctly handled. */
5249 gfc_find_symbol (e
->symtree
->name
, gfc_current_ns
, 1, &sym
);
5251 if (sym
&& old_sym
!= sym
5252 && sym
->ts
.type
== old_sym
->ts
.type
5253 && sym
->attr
.flavor
== FL_PROCEDURE
5254 && sym
->attr
.contained
)
5256 /* Clear the shape, since it might not be valid. */
5257 gfc_free_shape (&e
->shape
, e
->rank
);
5259 /* Give the expression the right symtree! */
5260 gfc_find_sym_tree (e
->symtree
->name
, NULL
, 1, &st
);
5261 gcc_assert (st
!= NULL
);
5263 if (old_sym
->attr
.flavor
== FL_PROCEDURE
5264 || e
->expr_type
== EXPR_FUNCTION
)
5266 /* Original was function so point to the new symbol, since
5267 the actual argument list is already attached to the
5269 e
->value
.function
.esym
= NULL
;
5274 /* Original was variable so convert array references into
5275 an actual arglist. This does not need any checking now
5276 since resolve_function will take care of it. */
5277 e
->value
.function
.actual
= NULL
;
5278 e
->expr_type
= EXPR_FUNCTION
;
5281 /* Ambiguity will not arise if the array reference is not
5282 the last reference. */
5283 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5284 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
5287 gcc_assert (ref
->type
== REF_ARRAY
);
5289 /* Grab the start expressions from the array ref and
5290 copy them into actual arguments. */
5291 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
5293 arg
= gfc_get_actual_arglist ();
5294 arg
->expr
= gfc_copy_expr (ref
->u
.ar
.start
[n
]);
5295 if (e
->value
.function
.actual
== NULL
)
5296 tail
= e
->value
.function
.actual
= arg
;
5304 /* Dump the reference list and set the rank. */
5305 gfc_free_ref_list (e
->ref
);
5307 e
->rank
= sym
->as
? sym
->as
->rank
: 0;
5310 gfc_resolve_expr (e
);
5314 /* This might have changed! */
5315 return e
->expr_type
== EXPR_FUNCTION
;
5320 gfc_resolve_character_operator (gfc_expr
*e
)
5322 gfc_expr
*op1
= e
->value
.op
.op1
;
5323 gfc_expr
*op2
= e
->value
.op
.op2
;
5324 gfc_expr
*e1
= NULL
;
5325 gfc_expr
*e2
= NULL
;
5327 gcc_assert (e
->value
.op
.op
== INTRINSIC_CONCAT
);
5329 if (op1
->ts
.u
.cl
&& op1
->ts
.u
.cl
->length
)
5330 e1
= gfc_copy_expr (op1
->ts
.u
.cl
->length
);
5331 else if (op1
->expr_type
== EXPR_CONSTANT
)
5332 e1
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
5333 op1
->value
.character
.length
);
5335 if (op2
->ts
.u
.cl
&& op2
->ts
.u
.cl
->length
)
5336 e2
= gfc_copy_expr (op2
->ts
.u
.cl
->length
);
5337 else if (op2
->expr_type
== EXPR_CONSTANT
)
5338 e2
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
5339 op2
->value
.character
.length
);
5341 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5346 e
->ts
.u
.cl
->length
= gfc_add (e1
, e2
);
5347 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
5348 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
5349 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 0);
5350 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
5356 /* Ensure that an character expression has a charlen and, if possible, a
5357 length expression. */
5360 fixup_charlen (gfc_expr
*e
)
5362 /* The cases fall through so that changes in expression type and the need
5363 for multiple fixes are picked up. In all circumstances, a charlen should
5364 be available for the middle end to hang a backend_decl on. */
5365 switch (e
->expr_type
)
5368 gfc_resolve_character_operator (e
);
5371 if (e
->expr_type
== EXPR_ARRAY
)
5372 gfc_resolve_character_array_constructor (e
);
5374 case EXPR_SUBSTRING
:
5375 if (!e
->ts
.u
.cl
&& e
->ref
)
5376 gfc_resolve_substring_charlen (e
);
5380 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5387 /* Update an actual argument to include the passed-object for type-bound
5388 procedures at the right position. */
5390 static gfc_actual_arglist
*
5391 update_arglist_pass (gfc_actual_arglist
* lst
, gfc_expr
* po
, unsigned argpos
,
5394 gcc_assert (argpos
> 0);
5398 gfc_actual_arglist
* result
;
5400 result
= gfc_get_actual_arglist ();
5404 result
->name
= name
;
5410 lst
->next
= update_arglist_pass (lst
->next
, po
, argpos
- 1, name
);
5412 lst
= update_arglist_pass (NULL
, po
, argpos
- 1, name
);
5417 /* Extract the passed-object from an EXPR_COMPCALL (a copy of it). */
5420 extract_compcall_passed_object (gfc_expr
* e
)
5424 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5426 if (e
->value
.compcall
.base_object
)
5427 po
= gfc_copy_expr (e
->value
.compcall
.base_object
);
5430 po
= gfc_get_expr ();
5431 po
->expr_type
= EXPR_VARIABLE
;
5432 po
->symtree
= e
->symtree
;
5433 po
->ref
= gfc_copy_ref (e
->ref
);
5434 po
->where
= e
->where
;
5437 if (gfc_resolve_expr (po
) == FAILURE
)
5444 /* Update the arglist of an EXPR_COMPCALL expression to include the
5448 update_compcall_arglist (gfc_expr
* e
)
5451 gfc_typebound_proc
* tbp
;
5453 tbp
= e
->value
.compcall
.tbp
;
5458 po
= extract_compcall_passed_object (e
);
5462 if (tbp
->nopass
|| e
->value
.compcall
.ignore_pass
)
5468 gcc_assert (tbp
->pass_arg_num
> 0);
5469 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5477 /* Extract the passed object from a PPC call (a copy of it). */
5480 extract_ppc_passed_object (gfc_expr
*e
)
5485 po
= gfc_get_expr ();
5486 po
->expr_type
= EXPR_VARIABLE
;
5487 po
->symtree
= e
->symtree
;
5488 po
->ref
= gfc_copy_ref (e
->ref
);
5489 po
->where
= e
->where
;
5491 /* Remove PPC reference. */
5493 while ((*ref
)->next
)
5494 ref
= &(*ref
)->next
;
5495 gfc_free_ref_list (*ref
);
5498 if (gfc_resolve_expr (po
) == FAILURE
)
5505 /* Update the actual arglist of a procedure pointer component to include the
5509 update_ppc_arglist (gfc_expr
* e
)
5513 gfc_typebound_proc
* tb
;
5515 if (!gfc_is_proc_ptr_comp (e
, &ppc
))
5522 else if (tb
->nopass
)
5525 po
= extract_ppc_passed_object (e
);
5532 gfc_error ("Passed-object at %L must be scalar", &e
->where
);
5537 if (po
->ts
.type
== BT_DERIVED
&& po
->ts
.u
.derived
->attr
.abstract
)
5539 gfc_error ("Base object for procedure-pointer component call at %L is of"
5540 " ABSTRACT type '%s'", &e
->where
, po
->ts
.u
.derived
->name
);
5544 gcc_assert (tb
->pass_arg_num
> 0);
5545 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5553 /* Check that the object a TBP is called on is valid, i.e. it must not be
5554 of ABSTRACT type (as in subobject%abstract_parent%tbp()). */
5557 check_typebound_baseobject (gfc_expr
* e
)
5560 gfc_try return_value
= FAILURE
;
5562 base
= extract_compcall_passed_object (e
);
5566 gcc_assert (base
->ts
.type
== BT_DERIVED
|| base
->ts
.type
== BT_CLASS
);
5569 if (base
->ts
.type
== BT_DERIVED
&& base
->ts
.u
.derived
->attr
.abstract
)
5571 gfc_error ("Base object for type-bound procedure call at %L is of"
5572 " ABSTRACT type '%s'", &e
->where
, base
->ts
.u
.derived
->name
);
5576 /* F08:C1230. If the procedure called is NOPASS,
5577 the base object must be scalar. */
5578 if (e
->value
.compcall
.tbp
->nopass
&& base
->rank
> 0)
5580 gfc_error ("Base object for NOPASS type-bound procedure call at %L must"
5581 " be scalar", &e
->where
);
5585 /* FIXME: Remove once PR 43214 is fixed (TBP with non-scalar PASS). */
5588 gfc_error ("Non-scalar base object at %L currently not implemented",
5593 return_value
= SUCCESS
;
5596 gfc_free_expr (base
);
5597 return return_value
;
5601 /* Resolve a call to a type-bound procedure, either function or subroutine,
5602 statically from the data in an EXPR_COMPCALL expression. The adapted
5603 arglist and the target-procedure symtree are returned. */
5606 resolve_typebound_static (gfc_expr
* e
, gfc_symtree
** target
,
5607 gfc_actual_arglist
** actual
)
5609 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5610 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5612 /* Update the actual arglist for PASS. */
5613 if (update_compcall_arglist (e
) == FAILURE
)
5616 *actual
= e
->value
.compcall
.actual
;
5617 *target
= e
->value
.compcall
.tbp
->u
.specific
;
5619 gfc_free_ref_list (e
->ref
);
5621 e
->value
.compcall
.actual
= NULL
;
5627 /* Get the ultimate declared type from an expression. In addition,
5628 return the last class/derived type reference and the copy of the
5631 get_declared_from_expr (gfc_ref
**class_ref
, gfc_ref
**new_ref
,
5634 gfc_symbol
*declared
;
5641 *new_ref
= gfc_copy_ref (e
->ref
);
5643 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5645 if (ref
->type
!= REF_COMPONENT
)
5648 if (ref
->u
.c
.component
->ts
.type
== BT_CLASS
5649 || ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
5651 declared
= ref
->u
.c
.component
->ts
.u
.derived
;
5657 if (declared
== NULL
)
5658 declared
= e
->symtree
->n
.sym
->ts
.u
.derived
;
5664 /* Given an EXPR_COMPCALL calling a GENERIC typebound procedure, figure out
5665 which of the specific bindings (if any) matches the arglist and transform
5666 the expression into a call of that binding. */
5669 resolve_typebound_generic_call (gfc_expr
* e
, const char **name
)
5671 gfc_typebound_proc
* genproc
;
5672 const char* genname
;
5674 gfc_symbol
*derived
;
5676 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5677 genname
= e
->value
.compcall
.name
;
5678 genproc
= e
->value
.compcall
.tbp
;
5680 if (!genproc
->is_generic
)
5683 /* Try the bindings on this type and in the inheritance hierarchy. */
5684 for (; genproc
; genproc
= genproc
->overridden
)
5688 gcc_assert (genproc
->is_generic
);
5689 for (g
= genproc
->u
.generic
; g
; g
= g
->next
)
5692 gfc_actual_arglist
* args
;
5695 gcc_assert (g
->specific
);
5697 if (g
->specific
->error
)
5700 target
= g
->specific
->u
.specific
->n
.sym
;
5702 /* Get the right arglist by handling PASS/NOPASS. */
5703 args
= gfc_copy_actual_arglist (e
->value
.compcall
.actual
);
5704 if (!g
->specific
->nopass
)
5707 po
= extract_compcall_passed_object (e
);
5711 gcc_assert (g
->specific
->pass_arg_num
> 0);
5712 gcc_assert (!g
->specific
->error
);
5713 args
= update_arglist_pass (args
, po
, g
->specific
->pass_arg_num
,
5714 g
->specific
->pass_arg
);
5716 resolve_actual_arglist (args
, target
->attr
.proc
,
5717 is_external_proc (target
) && !target
->formal
);
5719 /* Check if this arglist matches the formal. */
5720 matches
= gfc_arglist_matches_symbol (&args
, target
);
5722 /* Clean up and break out of the loop if we've found it. */
5723 gfc_free_actual_arglist (args
);
5726 e
->value
.compcall
.tbp
= g
->specific
;
5727 genname
= g
->specific_st
->name
;
5728 /* Pass along the name for CLASS methods, where the vtab
5729 procedure pointer component has to be referenced. */
5737 /* Nothing matching found! */
5738 gfc_error ("Found no matching specific binding for the call to the GENERIC"
5739 " '%s' at %L", genname
, &e
->where
);
5743 /* Make sure that we have the right specific instance for the name. */
5744 derived
= get_declared_from_expr (NULL
, NULL
, e
);
5746 st
= gfc_find_typebound_proc (derived
, NULL
, genname
, true, &e
->where
);
5748 e
->value
.compcall
.tbp
= st
->n
.tb
;
5754 /* Resolve a call to a type-bound subroutine. */
5757 resolve_typebound_call (gfc_code
* c
, const char **name
)
5759 gfc_actual_arglist
* newactual
;
5760 gfc_symtree
* target
;
5762 /* Check that's really a SUBROUTINE. */
5763 if (!c
->expr1
->value
.compcall
.tbp
->subroutine
)
5765 gfc_error ("'%s' at %L should be a SUBROUTINE",
5766 c
->expr1
->value
.compcall
.name
, &c
->loc
);
5770 if (check_typebound_baseobject (c
->expr1
) == FAILURE
)
5773 /* Pass along the name for CLASS methods, where the vtab
5774 procedure pointer component has to be referenced. */
5776 *name
= c
->expr1
->value
.compcall
.name
;
5778 if (resolve_typebound_generic_call (c
->expr1
, name
) == FAILURE
)
5781 /* Transform into an ordinary EXEC_CALL for now. */
5783 if (resolve_typebound_static (c
->expr1
, &target
, &newactual
) == FAILURE
)
5786 c
->ext
.actual
= newactual
;
5787 c
->symtree
= target
;
5788 c
->op
= (c
->expr1
->value
.compcall
.assign
? EXEC_ASSIGN_CALL
: EXEC_CALL
);
5790 gcc_assert (!c
->expr1
->ref
&& !c
->expr1
->value
.compcall
.actual
);
5792 gfc_free_expr (c
->expr1
);
5793 c
->expr1
= gfc_get_expr ();
5794 c
->expr1
->expr_type
= EXPR_FUNCTION
;
5795 c
->expr1
->symtree
= target
;
5796 c
->expr1
->where
= c
->loc
;
5798 return resolve_call (c
);
5802 /* Resolve a component-call expression. */
5804 resolve_compcall (gfc_expr
* e
, const char **name
)
5806 gfc_actual_arglist
* newactual
;
5807 gfc_symtree
* target
;
5809 /* Check that's really a FUNCTION. */
5810 if (!e
->value
.compcall
.tbp
->function
)
5812 gfc_error ("'%s' at %L should be a FUNCTION",
5813 e
->value
.compcall
.name
, &e
->where
);
5817 /* These must not be assign-calls! */
5818 gcc_assert (!e
->value
.compcall
.assign
);
5820 if (check_typebound_baseobject (e
) == FAILURE
)
5823 /* Pass along the name for CLASS methods, where the vtab
5824 procedure pointer component has to be referenced. */
5826 *name
= e
->value
.compcall
.name
;
5828 if (resolve_typebound_generic_call (e
, name
) == FAILURE
)
5830 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5832 /* Take the rank from the function's symbol. */
5833 if (e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
)
5834 e
->rank
= e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
->rank
;
5836 /* For now, we simply transform it into an EXPR_FUNCTION call with the same
5837 arglist to the TBP's binding target. */
5839 if (resolve_typebound_static (e
, &target
, &newactual
) == FAILURE
)
5842 e
->value
.function
.actual
= newactual
;
5843 e
->value
.function
.name
= NULL
;
5844 e
->value
.function
.esym
= target
->n
.sym
;
5845 e
->value
.function
.isym
= NULL
;
5846 e
->symtree
= target
;
5847 e
->ts
= target
->n
.sym
->ts
;
5848 e
->expr_type
= EXPR_FUNCTION
;
5850 /* Resolution is not necessary if this is a class subroutine; this
5851 function only has to identify the specific proc. Resolution of
5852 the call will be done next in resolve_typebound_call. */
5853 return gfc_resolve_expr (e
);
5858 /* Resolve a typebound function, or 'method'. First separate all
5859 the non-CLASS references by calling resolve_compcall directly. */
5862 resolve_typebound_function (gfc_expr
* e
)
5864 gfc_symbol
*declared
;
5875 /* Deal with typebound operators for CLASS objects. */
5876 expr
= e
->value
.compcall
.base_object
;
5877 if (expr
&& expr
->ts
.type
== BT_CLASS
&& e
->value
.compcall
.name
)
5879 /* Since the typebound operators are generic, we have to ensure
5880 that any delays in resolution are corrected and that the vtab
5883 declared
= ts
.u
.derived
;
5884 c
= gfc_find_component (declared
, "_vptr", true, true);
5885 if (c
->ts
.u
.derived
== NULL
)
5886 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
5888 if (resolve_compcall (e
, &name
) == FAILURE
)
5891 /* Use the generic name if it is there. */
5892 name
= name
? name
: e
->value
.function
.esym
->name
;
5893 e
->symtree
= expr
->symtree
;
5894 e
->ref
= gfc_copy_ref (expr
->ref
);
5895 gfc_add_vptr_component (e
);
5896 gfc_add_component_ref (e
, name
);
5897 e
->value
.function
.esym
= NULL
;
5902 return resolve_compcall (e
, NULL
);
5904 if (resolve_ref (e
) == FAILURE
)
5907 /* Get the CLASS declared type. */
5908 declared
= get_declared_from_expr (&class_ref
, &new_ref
, e
);
5910 /* Weed out cases of the ultimate component being a derived type. */
5911 if ((class_ref
&& class_ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
5912 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
5914 gfc_free_ref_list (new_ref
);
5915 return resolve_compcall (e
, NULL
);
5918 c
= gfc_find_component (declared
, "_data", true, true);
5919 declared
= c
->ts
.u
.derived
;
5921 /* Treat the call as if it is a typebound procedure, in order to roll
5922 out the correct name for the specific function. */
5923 if (resolve_compcall (e
, &name
) == FAILURE
)
5927 /* Then convert the expression to a procedure pointer component call. */
5928 e
->value
.function
.esym
= NULL
;
5934 /* '_vptr' points to the vtab, which contains the procedure pointers. */
5935 gfc_add_vptr_component (e
);
5936 gfc_add_component_ref (e
, name
);
5938 /* Recover the typespec for the expression. This is really only
5939 necessary for generic procedures, where the additional call
5940 to gfc_add_component_ref seems to throw the collection of the
5941 correct typespec. */
5946 /* Resolve a typebound subroutine, or 'method'. First separate all
5947 the non-CLASS references by calling resolve_typebound_call
5951 resolve_typebound_subroutine (gfc_code
*code
)
5953 gfc_symbol
*declared
;
5962 st
= code
->expr1
->symtree
;
5964 /* Deal with typebound operators for CLASS objects. */
5965 expr
= code
->expr1
->value
.compcall
.base_object
;
5966 if (expr
&& expr
->ts
.type
== BT_CLASS
&& code
->expr1
->value
.compcall
.name
)
5968 /* Since the typebound operators are generic, we have to ensure
5969 that any delays in resolution are corrected and that the vtab
5971 declared
= expr
->ts
.u
.derived
;
5972 c
= gfc_find_component (declared
, "_vptr", true, true);
5973 if (c
->ts
.u
.derived
== NULL
)
5974 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
5976 if (resolve_typebound_call (code
, &name
) == FAILURE
)
5979 /* Use the generic name if it is there. */
5980 name
= name
? name
: code
->expr1
->value
.function
.esym
->name
;
5981 code
->expr1
->symtree
= expr
->symtree
;
5982 code
->expr1
->ref
= gfc_copy_ref (expr
->ref
);
5983 gfc_add_vptr_component (code
->expr1
);
5984 gfc_add_component_ref (code
->expr1
, name
);
5985 code
->expr1
->value
.function
.esym
= NULL
;
5990 return resolve_typebound_call (code
, NULL
);
5992 if (resolve_ref (code
->expr1
) == FAILURE
)
5995 /* Get the CLASS declared type. */
5996 get_declared_from_expr (&class_ref
, &new_ref
, code
->expr1
);
5998 /* Weed out cases of the ultimate component being a derived type. */
5999 if ((class_ref
&& class_ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
6000 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
6002 gfc_free_ref_list (new_ref
);
6003 return resolve_typebound_call (code
, NULL
);
6006 if (resolve_typebound_call (code
, &name
) == FAILURE
)
6008 ts
= code
->expr1
->ts
;
6010 /* Then convert the expression to a procedure pointer component call. */
6011 code
->expr1
->value
.function
.esym
= NULL
;
6012 code
->expr1
->symtree
= st
;
6015 code
->expr1
->ref
= new_ref
;
6017 /* '_vptr' points to the vtab, which contains the procedure pointers. */
6018 gfc_add_vptr_component (code
->expr1
);
6019 gfc_add_component_ref (code
->expr1
, name
);
6021 /* Recover the typespec for the expression. This is really only
6022 necessary for generic procedures, where the additional call
6023 to gfc_add_component_ref seems to throw the collection of the
6024 correct typespec. */
6025 code
->expr1
->ts
= ts
;
6030 /* Resolve a CALL to a Procedure Pointer Component (Subroutine). */
6033 resolve_ppc_call (gfc_code
* c
)
6035 gfc_component
*comp
;
6038 b
= gfc_is_proc_ptr_comp (c
->expr1
, &comp
);
6041 c
->resolved_sym
= c
->expr1
->symtree
->n
.sym
;
6042 c
->expr1
->expr_type
= EXPR_VARIABLE
;
6044 if (!comp
->attr
.subroutine
)
6045 gfc_add_subroutine (&comp
->attr
, comp
->name
, &c
->expr1
->where
);
6047 if (resolve_ref (c
->expr1
) == FAILURE
)
6050 if (update_ppc_arglist (c
->expr1
) == FAILURE
)
6053 c
->ext
.actual
= c
->expr1
->value
.compcall
.actual
;
6055 if (resolve_actual_arglist (c
->ext
.actual
, comp
->attr
.proc
,
6056 comp
->formal
== NULL
) == FAILURE
)
6059 gfc_ppc_use (comp
, &c
->expr1
->value
.compcall
.actual
, &c
->expr1
->where
);
6065 /* Resolve a Function Call to a Procedure Pointer Component (Function). */
6068 resolve_expr_ppc (gfc_expr
* e
)
6070 gfc_component
*comp
;
6073 b
= gfc_is_proc_ptr_comp (e
, &comp
);
6076 /* Convert to EXPR_FUNCTION. */
6077 e
->expr_type
= EXPR_FUNCTION
;
6078 e
->value
.function
.isym
= NULL
;
6079 e
->value
.function
.actual
= e
->value
.compcall
.actual
;
6081 if (comp
->as
!= NULL
)
6082 e
->rank
= comp
->as
->rank
;
6084 if (!comp
->attr
.function
)
6085 gfc_add_function (&comp
->attr
, comp
->name
, &e
->where
);
6087 if (resolve_ref (e
) == FAILURE
)
6090 if (resolve_actual_arglist (e
->value
.function
.actual
, comp
->attr
.proc
,
6091 comp
->formal
== NULL
) == FAILURE
)
6094 if (update_ppc_arglist (e
) == FAILURE
)
6097 gfc_ppc_use (comp
, &e
->value
.compcall
.actual
, &e
->where
);
6104 gfc_is_expandable_expr (gfc_expr
*e
)
6106 gfc_constructor
*con
;
6108 if (e
->expr_type
== EXPR_ARRAY
)
6110 /* Traverse the constructor looking for variables that are flavor
6111 parameter. Parameters must be expanded since they are fully used at
6113 con
= gfc_constructor_first (e
->value
.constructor
);
6114 for (; con
; con
= gfc_constructor_next (con
))
6116 if (con
->expr
->expr_type
== EXPR_VARIABLE
6117 && con
->expr
->symtree
6118 && (con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
6119 || con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_VARIABLE
))
6121 if (con
->expr
->expr_type
== EXPR_ARRAY
6122 && gfc_is_expandable_expr (con
->expr
))
6130 /* Resolve an expression. That is, make sure that types of operands agree
6131 with their operators, intrinsic operators are converted to function calls
6132 for overloaded types and unresolved function references are resolved. */
6135 gfc_resolve_expr (gfc_expr
*e
)
6143 /* inquiry_argument only applies to variables. */
6144 inquiry_save
= inquiry_argument
;
6145 if (e
->expr_type
!= EXPR_VARIABLE
)
6146 inquiry_argument
= false;
6148 switch (e
->expr_type
)
6151 t
= resolve_operator (e
);
6157 if (check_host_association (e
))
6158 t
= resolve_function (e
);
6161 t
= resolve_variable (e
);
6163 expression_rank (e
);
6166 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.u
.cl
== NULL
&& e
->ref
6167 && e
->ref
->type
!= REF_SUBSTRING
)
6168 gfc_resolve_substring_charlen (e
);
6173 t
= resolve_typebound_function (e
);
6176 case EXPR_SUBSTRING
:
6177 t
= resolve_ref (e
);
6186 t
= resolve_expr_ppc (e
);
6191 if (resolve_ref (e
) == FAILURE
)
6194 t
= gfc_resolve_array_constructor (e
);
6195 /* Also try to expand a constructor. */
6198 expression_rank (e
);
6199 if (gfc_is_constant_expr (e
) || gfc_is_expandable_expr (e
))
6200 gfc_expand_constructor (e
, false);
6203 /* This provides the opportunity for the length of constructors with
6204 character valued function elements to propagate the string length
6205 to the expression. */
6206 if (t
== SUCCESS
&& e
->ts
.type
== BT_CHARACTER
)
6208 /* For efficiency, we call gfc_expand_constructor for BT_CHARACTER
6209 here rather then add a duplicate test for it above. */
6210 gfc_expand_constructor (e
, false);
6211 t
= gfc_resolve_character_array_constructor (e
);
6216 case EXPR_STRUCTURE
:
6217 t
= resolve_ref (e
);
6221 t
= resolve_structure_cons (e
, 0);
6225 t
= gfc_simplify_expr (e
, 0);
6229 gfc_internal_error ("gfc_resolve_expr(): Bad expression type");
6232 if (e
->ts
.type
== BT_CHARACTER
&& t
== SUCCESS
&& !e
->ts
.u
.cl
)
6235 inquiry_argument
= inquiry_save
;
6241 /* Resolve an expression from an iterator. They must be scalar and have
6242 INTEGER or (optionally) REAL type. */
6245 gfc_resolve_iterator_expr (gfc_expr
*expr
, bool real_ok
,
6246 const char *name_msgid
)
6248 if (gfc_resolve_expr (expr
) == FAILURE
)
6251 if (expr
->rank
!= 0)
6253 gfc_error ("%s at %L must be a scalar", _(name_msgid
), &expr
->where
);
6257 if (expr
->ts
.type
!= BT_INTEGER
)
6259 if (expr
->ts
.type
== BT_REAL
)
6262 return gfc_notify_std (GFC_STD_F95_DEL
,
6263 "Deleted feature: %s at %L must be integer",
6264 _(name_msgid
), &expr
->where
);
6267 gfc_error ("%s at %L must be INTEGER", _(name_msgid
),
6274 gfc_error ("%s at %L must be INTEGER", _(name_msgid
), &expr
->where
);
6282 /* Resolve the expressions in an iterator structure. If REAL_OK is
6283 false allow only INTEGER type iterators, otherwise allow REAL types. */
6286 gfc_resolve_iterator (gfc_iterator
*iter
, bool real_ok
)
6288 if (gfc_resolve_iterator_expr (iter
->var
, real_ok
, "Loop variable")
6292 if (gfc_check_vardef_context (iter
->var
, false, false, _("iterator variable"))
6296 if (gfc_resolve_iterator_expr (iter
->start
, real_ok
,
6297 "Start expression in DO loop") == FAILURE
)
6300 if (gfc_resolve_iterator_expr (iter
->end
, real_ok
,
6301 "End expression in DO loop") == FAILURE
)
6304 if (gfc_resolve_iterator_expr (iter
->step
, real_ok
,
6305 "Step expression in DO loop") == FAILURE
)
6308 if (iter
->step
->expr_type
== EXPR_CONSTANT
)
6310 if ((iter
->step
->ts
.type
== BT_INTEGER
6311 && mpz_cmp_ui (iter
->step
->value
.integer
, 0) == 0)
6312 || (iter
->step
->ts
.type
== BT_REAL
6313 && mpfr_sgn (iter
->step
->value
.real
) == 0))
6315 gfc_error ("Step expression in DO loop at %L cannot be zero",
6316 &iter
->step
->where
);
6321 /* Convert start, end, and step to the same type as var. */
6322 if (iter
->start
->ts
.kind
!= iter
->var
->ts
.kind
6323 || iter
->start
->ts
.type
!= iter
->var
->ts
.type
)
6324 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 2);
6326 if (iter
->end
->ts
.kind
!= iter
->var
->ts
.kind
6327 || iter
->end
->ts
.type
!= iter
->var
->ts
.type
)
6328 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 2);
6330 if (iter
->step
->ts
.kind
!= iter
->var
->ts
.kind
6331 || iter
->step
->ts
.type
!= iter
->var
->ts
.type
)
6332 gfc_convert_type (iter
->step
, &iter
->var
->ts
, 2);
6334 if (iter
->start
->expr_type
== EXPR_CONSTANT
6335 && iter
->end
->expr_type
== EXPR_CONSTANT
6336 && iter
->step
->expr_type
== EXPR_CONSTANT
)
6339 if (iter
->start
->ts
.type
== BT_INTEGER
)
6341 sgn
= mpz_cmp_ui (iter
->step
->value
.integer
, 0);
6342 cmp
= mpz_cmp (iter
->end
->value
.integer
, iter
->start
->value
.integer
);
6346 sgn
= mpfr_sgn (iter
->step
->value
.real
);
6347 cmp
= mpfr_cmp (iter
->end
->value
.real
, iter
->start
->value
.real
);
6349 if ((sgn
> 0 && cmp
< 0) || (sgn
< 0 && cmp
> 0))
6350 gfc_warning ("DO loop at %L will be executed zero times",
6351 &iter
->step
->where
);
6358 /* Traversal function for find_forall_index. f == 2 signals that
6359 that variable itself is not to be checked - only the references. */
6362 forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int *f
)
6364 if (expr
->expr_type
!= EXPR_VARIABLE
)
6367 /* A scalar assignment */
6368 if (!expr
->ref
|| *f
== 1)
6370 if (expr
->symtree
->n
.sym
== sym
)
6382 /* Check whether the FORALL index appears in the expression or not.
6383 Returns SUCCESS if SYM is found in EXPR. */
6386 find_forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int f
)
6388 if (gfc_traverse_expr (expr
, sym
, forall_index
, f
))
6395 /* Resolve a list of FORALL iterators. The FORALL index-name is constrained
6396 to be a scalar INTEGER variable. The subscripts and stride are scalar
6397 INTEGERs, and if stride is a constant it must be nonzero.
6398 Furthermore "A subscript or stride in a forall-triplet-spec shall
6399 not contain a reference to any index-name in the
6400 forall-triplet-spec-list in which it appears." (7.5.4.1) */
6403 resolve_forall_iterators (gfc_forall_iterator
*it
)
6405 gfc_forall_iterator
*iter
, *iter2
;
6407 for (iter
= it
; iter
; iter
= iter
->next
)
6409 if (gfc_resolve_expr (iter
->var
) == SUCCESS
6410 && (iter
->var
->ts
.type
!= BT_INTEGER
|| iter
->var
->rank
!= 0))
6411 gfc_error ("FORALL index-name at %L must be a scalar INTEGER",
6414 if (gfc_resolve_expr (iter
->start
) == SUCCESS
6415 && (iter
->start
->ts
.type
!= BT_INTEGER
|| iter
->start
->rank
!= 0))
6416 gfc_error ("FORALL start expression at %L must be a scalar INTEGER",
6417 &iter
->start
->where
);
6418 if (iter
->var
->ts
.kind
!= iter
->start
->ts
.kind
)
6419 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 2);
6421 if (gfc_resolve_expr (iter
->end
) == SUCCESS
6422 && (iter
->end
->ts
.type
!= BT_INTEGER
|| iter
->end
->rank
!= 0))
6423 gfc_error ("FORALL end expression at %L must be a scalar INTEGER",
6425 if (iter
->var
->ts
.kind
!= iter
->end
->ts
.kind
)
6426 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 2);
6428 if (gfc_resolve_expr (iter
->stride
) == SUCCESS
)
6430 if (iter
->stride
->ts
.type
!= BT_INTEGER
|| iter
->stride
->rank
!= 0)
6431 gfc_error ("FORALL stride expression at %L must be a scalar %s",
6432 &iter
->stride
->where
, "INTEGER");
6434 if (iter
->stride
->expr_type
== EXPR_CONSTANT
6435 && mpz_cmp_ui(iter
->stride
->value
.integer
, 0) == 0)
6436 gfc_error ("FORALL stride expression at %L cannot be zero",
6437 &iter
->stride
->where
);
6439 if (iter
->var
->ts
.kind
!= iter
->stride
->ts
.kind
)
6440 gfc_convert_type (iter
->stride
, &iter
->var
->ts
, 2);
6443 for (iter
= it
; iter
; iter
= iter
->next
)
6444 for (iter2
= iter
; iter2
; iter2
= iter2
->next
)
6446 if (find_forall_index (iter2
->start
,
6447 iter
->var
->symtree
->n
.sym
, 0) == SUCCESS
6448 || find_forall_index (iter2
->end
,
6449 iter
->var
->symtree
->n
.sym
, 0) == SUCCESS
6450 || find_forall_index (iter2
->stride
,
6451 iter
->var
->symtree
->n
.sym
, 0) == SUCCESS
)
6452 gfc_error ("FORALL index '%s' may not appear in triplet "
6453 "specification at %L", iter
->var
->symtree
->name
,
6454 &iter2
->start
->where
);
6459 /* Given a pointer to a symbol that is a derived type, see if it's
6460 inaccessible, i.e. if it's defined in another module and the components are
6461 PRIVATE. The search is recursive if necessary. Returns zero if no
6462 inaccessible components are found, nonzero otherwise. */
6465 derived_inaccessible (gfc_symbol
*sym
)
6469 if (sym
->attr
.use_assoc
&& sym
->attr
.private_comp
)
6472 for (c
= sym
->components
; c
; c
= c
->next
)
6474 if (c
->ts
.type
== BT_DERIVED
&& derived_inaccessible (c
->ts
.u
.derived
))
6482 /* Resolve the argument of a deallocate expression. The expression must be
6483 a pointer or a full array. */
6486 resolve_deallocate_expr (gfc_expr
*e
)
6488 symbol_attribute attr
;
6489 int allocatable
, pointer
;
6494 if (gfc_resolve_expr (e
) == FAILURE
)
6497 if (e
->expr_type
!= EXPR_VARIABLE
)
6500 sym
= e
->symtree
->n
.sym
;
6502 if (sym
->ts
.type
== BT_CLASS
)
6504 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6505 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6509 allocatable
= sym
->attr
.allocatable
;
6510 pointer
= sym
->attr
.pointer
;
6512 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6517 if (ref
->u
.ar
.type
!= AR_FULL
6518 && !(ref
->u
.ar
.type
== AR_ELEMENT
&& ref
->u
.ar
.as
->rank
== 0
6519 && ref
->u
.ar
.codimen
&& gfc_ref_this_image (ref
)))
6524 c
= ref
->u
.c
.component
;
6525 if (c
->ts
.type
== BT_CLASS
)
6527 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
6528 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
6532 allocatable
= c
->attr
.allocatable
;
6533 pointer
= c
->attr
.pointer
;
6543 attr
= gfc_expr_attr (e
);
6545 if (allocatable
== 0 && attr
.pointer
== 0)
6548 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
6554 if (gfc_is_coindexed (e
))
6556 gfc_error ("Coindexed allocatable object at %L", &e
->where
);
6561 && gfc_check_vardef_context (e
, true, true, _("DEALLOCATE object"))
6564 if (gfc_check_vardef_context (e
, false, true, _("DEALLOCATE object"))
6572 /* Returns true if the expression e contains a reference to the symbol sym. */
6574 sym_in_expr (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
6576 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
== sym
)
6583 gfc_find_sym_in_expr (gfc_symbol
*sym
, gfc_expr
*e
)
6585 return gfc_traverse_expr (e
, sym
, sym_in_expr
, 0);
6589 /* Given the expression node e for an allocatable/pointer of derived type to be
6590 allocated, get the expression node to be initialized afterwards (needed for
6591 derived types with default initializers, and derived types with allocatable
6592 components that need nullification.) */
6595 gfc_expr_to_initialize (gfc_expr
*e
)
6601 result
= gfc_copy_expr (e
);
6603 /* Change the last array reference from AR_ELEMENT to AR_FULL. */
6604 for (ref
= result
->ref
; ref
; ref
= ref
->next
)
6605 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
6607 ref
->u
.ar
.type
= AR_FULL
;
6609 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
6610 ref
->u
.ar
.start
[i
] = ref
->u
.ar
.end
[i
] = ref
->u
.ar
.stride
[i
] = NULL
;
6615 gfc_free_shape (&result
->shape
, result
->rank
);
6617 /* Recalculate rank, shape, etc. */
6618 gfc_resolve_expr (result
);
6623 /* If the last ref of an expression is an array ref, return a copy of the
6624 expression with that one removed. Otherwise, a copy of the original
6625 expression. This is used for allocate-expressions and pointer assignment
6626 LHS, where there may be an array specification that needs to be stripped
6627 off when using gfc_check_vardef_context. */
6630 remove_last_array_ref (gfc_expr
* e
)
6635 e2
= gfc_copy_expr (e
);
6636 for (r
= &e2
->ref
; *r
; r
= &(*r
)->next
)
6637 if ((*r
)->type
== REF_ARRAY
&& !(*r
)->next
)
6639 gfc_free_ref_list (*r
);
6648 /* Used in resolve_allocate_expr to check that a allocation-object and
6649 a source-expr are conformable. This does not catch all possible
6650 cases; in particular a runtime checking is needed. */
6653 conformable_arrays (gfc_expr
*e1
, gfc_expr
*e2
)
6656 for (tail
= e2
->ref
; tail
&& tail
->next
; tail
= tail
->next
);
6658 /* First compare rank. */
6659 if (tail
&& e1
->rank
!= tail
->u
.ar
.as
->rank
)
6661 gfc_error ("Source-expr at %L must be scalar or have the "
6662 "same rank as the allocate-object at %L",
6663 &e1
->where
, &e2
->where
);
6674 for (i
= 0; i
< e1
->rank
; i
++)
6676 if (tail
->u
.ar
.end
[i
])
6678 mpz_set (s
, tail
->u
.ar
.end
[i
]->value
.integer
);
6679 mpz_sub (s
, s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6680 mpz_add_ui (s
, s
, 1);
6684 mpz_set (s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6687 if (mpz_cmp (e1
->shape
[i
], s
) != 0)
6689 gfc_error ("Source-expr at %L and allocate-object at %L must "
6690 "have the same shape", &e1
->where
, &e2
->where
);
6703 /* Resolve the expression in an ALLOCATE statement, doing the additional
6704 checks to see whether the expression is OK or not. The expression must
6705 have a trailing array reference that gives the size of the array. */
6708 resolve_allocate_expr (gfc_expr
*e
, gfc_code
*code
)
6710 int i
, pointer
, allocatable
, dimension
, is_abstract
;
6713 symbol_attribute attr
;
6714 gfc_ref
*ref
, *ref2
;
6717 gfc_symbol
*sym
= NULL
;
6722 /* Mark the ultimost array component as being in allocate to allow DIMEN_STAR
6723 checking of coarrays. */
6724 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6725 if (ref
->next
== NULL
)
6728 if (ref
&& ref
->type
== REF_ARRAY
)
6729 ref
->u
.ar
.in_allocate
= true;
6731 if (gfc_resolve_expr (e
) == FAILURE
)
6734 /* Make sure the expression is allocatable or a pointer. If it is
6735 pointer, the next-to-last reference must be a pointer. */
6739 sym
= e
->symtree
->n
.sym
;
6741 /* Check whether ultimate component is abstract and CLASS. */
6744 if (e
->expr_type
!= EXPR_VARIABLE
)
6747 attr
= gfc_expr_attr (e
);
6748 pointer
= attr
.pointer
;
6749 dimension
= attr
.dimension
;
6750 codimension
= attr
.codimension
;
6754 if (sym
->ts
.type
== BT_CLASS
)
6756 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6757 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6758 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
6759 codimension
= CLASS_DATA (sym
)->attr
.codimension
;
6760 is_abstract
= CLASS_DATA (sym
)->attr
.abstract
;
6764 allocatable
= sym
->attr
.allocatable
;
6765 pointer
= sym
->attr
.pointer
;
6766 dimension
= sym
->attr
.dimension
;
6767 codimension
= sym
->attr
.codimension
;
6772 for (ref
= e
->ref
; ref
; ref2
= ref
, ref
= ref
->next
)
6777 if (ref
->u
.ar
.codimen
> 0)
6780 for (n
= ref
->u
.ar
.dimen
;
6781 n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
6782 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_THIS_IMAGE
)
6789 if (ref
->next
!= NULL
)
6797 gfc_error ("Coindexed allocatable object at %L",
6802 c
= ref
->u
.c
.component
;
6803 if (c
->ts
.type
== BT_CLASS
)
6805 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
6806 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
6807 dimension
= CLASS_DATA (c
)->attr
.dimension
;
6808 codimension
= CLASS_DATA (c
)->attr
.codimension
;
6809 is_abstract
= CLASS_DATA (c
)->attr
.abstract
;
6813 allocatable
= c
->attr
.allocatable
;
6814 pointer
= c
->attr
.pointer
;
6815 dimension
= c
->attr
.dimension
;
6816 codimension
= c
->attr
.codimension
;
6817 is_abstract
= c
->attr
.abstract
;
6829 if (allocatable
== 0 && pointer
== 0)
6831 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
6836 /* Some checks for the SOURCE tag. */
6839 /* Check F03:C631. */
6840 if (!gfc_type_compatible (&e
->ts
, &code
->expr3
->ts
))
6842 gfc_error ("Type of entity at %L is type incompatible with "
6843 "source-expr at %L", &e
->where
, &code
->expr3
->where
);
6847 /* Check F03:C632 and restriction following Note 6.18. */
6848 if (code
->expr3
->rank
> 0
6849 && conformable_arrays (code
->expr3
, e
) == FAILURE
)
6852 /* Check F03:C633. */
6853 if (code
->expr3
->ts
.kind
!= e
->ts
.kind
)
6855 gfc_error ("The allocate-object at %L and the source-expr at %L "
6856 "shall have the same kind type parameter",
6857 &e
->where
, &code
->expr3
->where
);
6861 /* Check F2008, C642. */
6862 if (code
->expr3
->ts
.type
== BT_DERIVED
6863 && ((codimension
&& gfc_expr_attr (code
->expr3
).lock_comp
)
6864 || (code
->expr3
->ts
.u
.derived
->from_intmod
6865 == INTMOD_ISO_FORTRAN_ENV
6866 && code
->expr3
->ts
.u
.derived
->intmod_sym_id
6867 == ISOFORTRAN_LOCK_TYPE
)))
6869 gfc_error ("The source-expr at %L shall neither be of type "
6870 "LOCK_TYPE nor have a LOCK_TYPE component if "
6871 "allocate-object at %L is a coarray",
6872 &code
->expr3
->where
, &e
->where
);
6877 /* Check F08:C629. */
6878 if (is_abstract
&& code
->ext
.alloc
.ts
.type
== BT_UNKNOWN
6881 gcc_assert (e
->ts
.type
== BT_CLASS
);
6882 gfc_error ("Allocating %s of ABSTRACT base type at %L requires a "
6883 "type-spec or source-expr", sym
->name
, &e
->where
);
6887 /* In the variable definition context checks, gfc_expr_attr is used
6888 on the expression. This is fooled by the array specification
6889 present in e, thus we have to eliminate that one temporarily. */
6890 e2
= remove_last_array_ref (e
);
6892 if (t
== SUCCESS
&& pointer
)
6893 t
= gfc_check_vardef_context (e2
, true, true, _("ALLOCATE object"));
6895 t
= gfc_check_vardef_context (e2
, false, true, _("ALLOCATE object"));
6902 /* Set up default initializer if needed. */
6906 if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
6907 ts
= code
->ext
.alloc
.ts
;
6911 if (ts
.type
== BT_CLASS
)
6912 ts
= ts
.u
.derived
->components
->ts
;
6914 if (ts
.type
== BT_DERIVED
&& (init_e
= gfc_default_initializer (&ts
)))
6916 gfc_code
*init_st
= gfc_get_code ();
6917 init_st
->loc
= code
->loc
;
6918 init_st
->op
= EXEC_INIT_ASSIGN
;
6919 init_st
->expr1
= gfc_expr_to_initialize (e
);
6920 init_st
->expr2
= init_e
;
6921 init_st
->next
= code
->next
;
6922 code
->next
= init_st
;
6925 else if (code
->expr3
->mold
&& code
->expr3
->ts
.type
== BT_DERIVED
)
6927 /* Default initialization via MOLD (non-polymorphic). */
6928 gfc_expr
*rhs
= gfc_default_initializer (&code
->expr3
->ts
);
6929 gfc_resolve_expr (rhs
);
6930 gfc_free_expr (code
->expr3
);
6934 if (e
->ts
.type
== BT_CLASS
)
6936 /* Make sure the vtab symbol is present when
6937 the module variables are generated. */
6938 gfc_typespec ts
= e
->ts
;
6940 ts
= code
->expr3
->ts
;
6941 else if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
6942 ts
= code
->ext
.alloc
.ts
;
6943 gfc_find_derived_vtab (ts
.u
.derived
);
6946 if (dimension
== 0 && codimension
== 0)
6949 /* Make sure the last reference node is an array specifiction. */
6951 if (!ref2
|| ref2
->type
!= REF_ARRAY
|| ref2
->u
.ar
.type
== AR_FULL
6952 || (dimension
&& ref2
->u
.ar
.dimen
== 0))
6954 gfc_error ("Array specification required in ALLOCATE statement "
6955 "at %L", &e
->where
);
6959 /* Make sure that the array section reference makes sense in the
6960 context of an ALLOCATE specification. */
6965 for (i
= ar
->dimen
; i
< ar
->dimen
+ ar
->codimen
; i
++)
6966 if (ar
->dimen_type
[i
] == DIMEN_THIS_IMAGE
)
6968 gfc_error ("Coarray specification required in ALLOCATE statement "
6969 "at %L", &e
->where
);
6973 for (i
= 0; i
< ar
->dimen
; i
++)
6975 if (ref2
->u
.ar
.type
== AR_ELEMENT
)
6978 switch (ar
->dimen_type
[i
])
6984 if (ar
->start
[i
] != NULL
6985 && ar
->end
[i
] != NULL
6986 && ar
->stride
[i
] == NULL
)
6989 /* Fall Through... */
6994 case DIMEN_THIS_IMAGE
:
6995 gfc_error ("Bad array specification in ALLOCATE statement at %L",
7001 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7003 sym
= a
->expr
->symtree
->n
.sym
;
7005 /* TODO - check derived type components. */
7006 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
7009 if ((ar
->start
[i
] != NULL
7010 && gfc_find_sym_in_expr (sym
, ar
->start
[i
]))
7011 || (ar
->end
[i
] != NULL
7012 && gfc_find_sym_in_expr (sym
, ar
->end
[i
])))
7014 gfc_error ("'%s' must not appear in the array specification at "
7015 "%L in the same ALLOCATE statement where it is "
7016 "itself allocated", sym
->name
, &ar
->where
);
7022 for (i
= ar
->dimen
; i
< ar
->codimen
+ ar
->dimen
; i
++)
7024 if (ar
->dimen_type
[i
] == DIMEN_ELEMENT
7025 || ar
->dimen_type
[i
] == DIMEN_RANGE
)
7027 if (i
== (ar
->dimen
+ ar
->codimen
- 1))
7029 gfc_error ("Expected '*' in coindex specification in ALLOCATE "
7030 "statement at %L", &e
->where
);
7036 if (ar
->dimen_type
[i
] == DIMEN_STAR
&& i
== (ar
->dimen
+ ar
->codimen
- 1)
7037 && ar
->stride
[i
] == NULL
)
7040 gfc_error ("Bad coarray specification in ALLOCATE statement at %L",
7053 resolve_allocate_deallocate (gfc_code
*code
, const char *fcn
)
7055 gfc_expr
*stat
, *errmsg
, *pe
, *qe
;
7056 gfc_alloc
*a
, *p
, *q
;
7059 errmsg
= code
->expr2
;
7061 /* Check the stat variable. */
7064 gfc_check_vardef_context (stat
, false, false, _("STAT variable"));
7066 if ((stat
->ts
.type
!= BT_INTEGER
7067 && !(stat
->ref
&& (stat
->ref
->type
== REF_ARRAY
7068 || stat
->ref
->type
== REF_COMPONENT
)))
7070 gfc_error ("Stat-variable at %L must be a scalar INTEGER "
7071 "variable", &stat
->where
);
7073 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7074 if (p
->expr
->symtree
->n
.sym
->name
== stat
->symtree
->n
.sym
->name
)
7076 gfc_ref
*ref1
, *ref2
;
7079 for (ref1
= p
->expr
->ref
, ref2
= stat
->ref
; ref1
&& ref2
;
7080 ref1
= ref1
->next
, ref2
= ref2
->next
)
7082 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
7084 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
7093 gfc_error ("Stat-variable at %L shall not be %sd within "
7094 "the same %s statement", &stat
->where
, fcn
, fcn
);
7100 /* Check the errmsg variable. */
7104 gfc_warning ("ERRMSG at %L is useless without a STAT tag",
7107 gfc_check_vardef_context (errmsg
, false, false, _("ERRMSG variable"));
7109 if ((errmsg
->ts
.type
!= BT_CHARACTER
7111 && (errmsg
->ref
->type
== REF_ARRAY
7112 || errmsg
->ref
->type
== REF_COMPONENT
)))
7113 || errmsg
->rank
> 0 )
7114 gfc_error ("Errmsg-variable at %L must be a scalar CHARACTER "
7115 "variable", &errmsg
->where
);
7117 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7118 if (p
->expr
->symtree
->n
.sym
->name
== errmsg
->symtree
->n
.sym
->name
)
7120 gfc_ref
*ref1
, *ref2
;
7123 for (ref1
= p
->expr
->ref
, ref2
= errmsg
->ref
; ref1
&& ref2
;
7124 ref1
= ref1
->next
, ref2
= ref2
->next
)
7126 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
7128 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
7137 gfc_error ("Errmsg-variable at %L shall not be %sd within "
7138 "the same %s statement", &errmsg
->where
, fcn
, fcn
);
7144 /* Check that an allocate-object appears only once in the statement.
7145 FIXME: Checking derived types is disabled. */
7146 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7149 for (q
= p
->next
; q
; q
= q
->next
)
7152 if (pe
->symtree
->n
.sym
->name
== qe
->symtree
->n
.sym
->name
)
7154 /* This is a potential collision. */
7155 gfc_ref
*pr
= pe
->ref
;
7156 gfc_ref
*qr
= qe
->ref
;
7158 /* Follow the references until
7159 a) They start to differ, in which case there is no error;
7160 you can deallocate a%b and a%c in a single statement
7161 b) Both of them stop, which is an error
7162 c) One of them stops, which is also an error. */
7165 if (pr
== NULL
&& qr
== NULL
)
7167 gfc_error ("Allocate-object at %L also appears at %L",
7168 &pe
->where
, &qe
->where
);
7171 else if (pr
!= NULL
&& qr
== NULL
)
7173 gfc_error ("Allocate-object at %L is subobject of"
7174 " object at %L", &pe
->where
, &qe
->where
);
7177 else if (pr
== NULL
&& qr
!= NULL
)
7179 gfc_error ("Allocate-object at %L is subobject of"
7180 " object at %L", &qe
->where
, &pe
->where
);
7183 /* Here, pr != NULL && qr != NULL */
7184 gcc_assert(pr
->type
== qr
->type
);
7185 if (pr
->type
== REF_ARRAY
)
7187 /* Handle cases like allocate(v(3)%x(3), v(2)%x(3)),
7189 gcc_assert (qr
->type
== REF_ARRAY
);
7191 if (pr
->next
&& qr
->next
)
7193 gfc_array_ref
*par
= &(pr
->u
.ar
);
7194 gfc_array_ref
*qar
= &(qr
->u
.ar
);
7195 if (gfc_dep_compare_expr (par
->start
[0],
7196 qar
->start
[0]) != 0)
7202 if (pr
->u
.c
.component
->name
!= qr
->u
.c
.component
->name
)
7213 if (strcmp (fcn
, "ALLOCATE") == 0)
7215 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7216 resolve_allocate_expr (a
->expr
, code
);
7220 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7221 resolve_deallocate_expr (a
->expr
);
7226 /************ SELECT CASE resolution subroutines ************/
7228 /* Callback function for our mergesort variant. Determines interval
7229 overlaps for CASEs. Return <0 if op1 < op2, 0 for overlap, >0 for
7230 op1 > op2. Assumes we're not dealing with the default case.
7231 We have op1 = (:L), (K:L) or (K:) and op2 = (:N), (M:N) or (M:).
7232 There are nine situations to check. */
7235 compare_cases (const gfc_case
*op1
, const gfc_case
*op2
)
7239 if (op1
->low
== NULL
) /* op1 = (:L) */
7241 /* op2 = (:N), so overlap. */
7243 /* op2 = (M:) or (M:N), L < M */
7244 if (op2
->low
!= NULL
7245 && gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7248 else if (op1
->high
== NULL
) /* op1 = (K:) */
7250 /* op2 = (M:), so overlap. */
7252 /* op2 = (:N) or (M:N), K > N */
7253 if (op2
->high
!= NULL
7254 && gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7257 else /* op1 = (K:L) */
7259 if (op2
->low
== NULL
) /* op2 = (:N), K > N */
7260 retval
= (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7262 else if (op2
->high
== NULL
) /* op2 = (M:), L < M */
7263 retval
= (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7265 else /* op2 = (M:N) */
7269 if (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7272 else if (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7281 /* Merge-sort a double linked case list, detecting overlap in the
7282 process. LIST is the head of the double linked case list before it
7283 is sorted. Returns the head of the sorted list if we don't see any
7284 overlap, or NULL otherwise. */
7287 check_case_overlap (gfc_case
*list
)
7289 gfc_case
*p
, *q
, *e
, *tail
;
7290 int insize
, nmerges
, psize
, qsize
, cmp
, overlap_seen
;
7292 /* If the passed list was empty, return immediately. */
7299 /* Loop unconditionally. The only exit from this loop is a return
7300 statement, when we've finished sorting the case list. */
7307 /* Count the number of merges we do in this pass. */
7310 /* Loop while there exists a merge to be done. */
7315 /* Count this merge. */
7318 /* Cut the list in two pieces by stepping INSIZE places
7319 forward in the list, starting from P. */
7322 for (i
= 0; i
< insize
; i
++)
7331 /* Now we have two lists. Merge them! */
7332 while (psize
> 0 || (qsize
> 0 && q
!= NULL
))
7334 /* See from which the next case to merge comes from. */
7337 /* P is empty so the next case must come from Q. */
7342 else if (qsize
== 0 || q
== NULL
)
7351 cmp
= compare_cases (p
, q
);
7354 /* The whole case range for P is less than the
7362 /* The whole case range for Q is greater than
7363 the case range for P. */
7370 /* The cases overlap, or they are the same
7371 element in the list. Either way, we must
7372 issue an error and get the next case from P. */
7373 /* FIXME: Sort P and Q by line number. */
7374 gfc_error ("CASE label at %L overlaps with CASE "
7375 "label at %L", &p
->where
, &q
->where
);
7383 /* Add the next element to the merged list. */
7392 /* P has now stepped INSIZE places along, and so has Q. So
7393 they're the same. */
7398 /* If we have done only one merge or none at all, we've
7399 finished sorting the cases. */
7408 /* Otherwise repeat, merging lists twice the size. */
7414 /* Check to see if an expression is suitable for use in a CASE statement.
7415 Makes sure that all case expressions are scalar constants of the same
7416 type. Return FAILURE if anything is wrong. */
7419 validate_case_label_expr (gfc_expr
*e
, gfc_expr
*case_expr
)
7421 if (e
== NULL
) return SUCCESS
;
7423 if (e
->ts
.type
!= case_expr
->ts
.type
)
7425 gfc_error ("Expression in CASE statement at %L must be of type %s",
7426 &e
->where
, gfc_basic_typename (case_expr
->ts
.type
));
7430 /* C805 (R808) For a given case-construct, each case-value shall be of
7431 the same type as case-expr. For character type, length differences
7432 are allowed, but the kind type parameters shall be the same. */
7434 if (case_expr
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= case_expr
->ts
.kind
)
7436 gfc_error ("Expression in CASE statement at %L must be of kind %d",
7437 &e
->where
, case_expr
->ts
.kind
);
7441 /* Convert the case value kind to that of case expression kind,
7444 if (e
->ts
.kind
!= case_expr
->ts
.kind
)
7445 gfc_convert_type_warn (e
, &case_expr
->ts
, 2, 0);
7449 gfc_error ("Expression in CASE statement at %L must be scalar",
7458 /* Given a completely parsed select statement, we:
7460 - Validate all expressions and code within the SELECT.
7461 - Make sure that the selection expression is not of the wrong type.
7462 - Make sure that no case ranges overlap.
7463 - Eliminate unreachable cases and unreachable code resulting from
7464 removing case labels.
7466 The standard does allow unreachable cases, e.g. CASE (5:3). But
7467 they are a hassle for code generation, and to prevent that, we just
7468 cut them out here. This is not necessary for overlapping cases
7469 because they are illegal and we never even try to generate code.
7471 We have the additional caveat that a SELECT construct could have
7472 been a computed GOTO in the source code. Fortunately we can fairly
7473 easily work around that here: The case_expr for a "real" SELECT CASE
7474 is in code->expr1, but for a computed GOTO it is in code->expr2. All
7475 we have to do is make sure that the case_expr is a scalar integer
7479 resolve_select (gfc_code
*code
)
7482 gfc_expr
*case_expr
;
7483 gfc_case
*cp
, *default_case
, *tail
, *head
;
7484 int seen_unreachable
;
7490 if (code
->expr1
== NULL
)
7492 /* This was actually a computed GOTO statement. */
7493 case_expr
= code
->expr2
;
7494 if (case_expr
->ts
.type
!= BT_INTEGER
|| case_expr
->rank
!= 0)
7495 gfc_error ("Selection expression in computed GOTO statement "
7496 "at %L must be a scalar integer expression",
7499 /* Further checking is not necessary because this SELECT was built
7500 by the compiler, so it should always be OK. Just move the
7501 case_expr from expr2 to expr so that we can handle computed
7502 GOTOs as normal SELECTs from here on. */
7503 code
->expr1
= code
->expr2
;
7508 case_expr
= code
->expr1
;
7510 type
= case_expr
->ts
.type
;
7511 if (type
!= BT_LOGICAL
&& type
!= BT_INTEGER
&& type
!= BT_CHARACTER
)
7513 gfc_error ("Argument of SELECT statement at %L cannot be %s",
7514 &case_expr
->where
, gfc_typename (&case_expr
->ts
));
7516 /* Punt. Going on here just produce more garbage error messages. */
7520 if (case_expr
->rank
!= 0)
7522 gfc_error ("Argument of SELECT statement at %L must be a scalar "
7523 "expression", &case_expr
->where
);
7530 /* Raise a warning if an INTEGER case value exceeds the range of
7531 the case-expr. Later, all expressions will be promoted to the
7532 largest kind of all case-labels. */
7534 if (type
== BT_INTEGER
)
7535 for (body
= code
->block
; body
; body
= body
->block
)
7536 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7539 && gfc_check_integer_range (cp
->low
->value
.integer
,
7540 case_expr
->ts
.kind
) != ARITH_OK
)
7541 gfc_warning ("Expression in CASE statement at %L is "
7542 "not in the range of %s", &cp
->low
->where
,
7543 gfc_typename (&case_expr
->ts
));
7546 && cp
->low
!= cp
->high
7547 && gfc_check_integer_range (cp
->high
->value
.integer
,
7548 case_expr
->ts
.kind
) != ARITH_OK
)
7549 gfc_warning ("Expression in CASE statement at %L is "
7550 "not in the range of %s", &cp
->high
->where
,
7551 gfc_typename (&case_expr
->ts
));
7554 /* PR 19168 has a long discussion concerning a mismatch of the kinds
7555 of the SELECT CASE expression and its CASE values. Walk the lists
7556 of case values, and if we find a mismatch, promote case_expr to
7557 the appropriate kind. */
7559 if (type
== BT_LOGICAL
|| type
== BT_INTEGER
)
7561 for (body
= code
->block
; body
; body
= body
->block
)
7563 /* Walk the case label list. */
7564 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7566 /* Intercept the DEFAULT case. It does not have a kind. */
7567 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7570 /* Unreachable case ranges are discarded, so ignore. */
7571 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7572 && cp
->low
!= cp
->high
7573 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7577 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->low
))
7578 gfc_convert_type_warn (case_expr
, &cp
->low
->ts
, 2, 0);
7580 if (cp
->high
!= NULL
7581 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->high
))
7582 gfc_convert_type_warn (case_expr
, &cp
->high
->ts
, 2, 0);
7587 /* Assume there is no DEFAULT case. */
7588 default_case
= NULL
;
7593 for (body
= code
->block
; body
; body
= body
->block
)
7595 /* Assume the CASE list is OK, and all CASE labels can be matched. */
7597 seen_unreachable
= 0;
7599 /* Walk the case label list, making sure that all case labels
7601 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7603 /* Count the number of cases in the whole construct. */
7606 /* Intercept the DEFAULT case. */
7607 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7609 if (default_case
!= NULL
)
7611 gfc_error ("The DEFAULT CASE at %L cannot be followed "
7612 "by a second DEFAULT CASE at %L",
7613 &default_case
->where
, &cp
->where
);
7624 /* Deal with single value cases and case ranges. Errors are
7625 issued from the validation function. */
7626 if (validate_case_label_expr (cp
->low
, case_expr
) != SUCCESS
7627 || validate_case_label_expr (cp
->high
, case_expr
) != SUCCESS
)
7633 if (type
== BT_LOGICAL
7634 && ((cp
->low
== NULL
|| cp
->high
== NULL
)
7635 || cp
->low
!= cp
->high
))
7637 gfc_error ("Logical range in CASE statement at %L is not "
7638 "allowed", &cp
->low
->where
);
7643 if (type
== BT_LOGICAL
&& cp
->low
->expr_type
== EXPR_CONSTANT
)
7646 value
= cp
->low
->value
.logical
== 0 ? 2 : 1;
7647 if (value
& seen_logical
)
7649 gfc_error ("Constant logical value in CASE statement "
7650 "is repeated at %L",
7655 seen_logical
|= value
;
7658 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7659 && cp
->low
!= cp
->high
7660 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7662 if (gfc_option
.warn_surprising
)
7663 gfc_warning ("Range specification at %L can never "
7664 "be matched", &cp
->where
);
7666 cp
->unreachable
= 1;
7667 seen_unreachable
= 1;
7671 /* If the case range can be matched, it can also overlap with
7672 other cases. To make sure it does not, we put it in a
7673 double linked list here. We sort that with a merge sort
7674 later on to detect any overlapping cases. */
7678 head
->right
= head
->left
= NULL
;
7683 tail
->right
->left
= tail
;
7690 /* It there was a failure in the previous case label, give up
7691 for this case label list. Continue with the next block. */
7695 /* See if any case labels that are unreachable have been seen.
7696 If so, we eliminate them. This is a bit of a kludge because
7697 the case lists for a single case statement (label) is a
7698 single forward linked lists. */
7699 if (seen_unreachable
)
7701 /* Advance until the first case in the list is reachable. */
7702 while (body
->ext
.block
.case_list
!= NULL
7703 && body
->ext
.block
.case_list
->unreachable
)
7705 gfc_case
*n
= body
->ext
.block
.case_list
;
7706 body
->ext
.block
.case_list
= body
->ext
.block
.case_list
->next
;
7708 gfc_free_case_list (n
);
7711 /* Strip all other unreachable cases. */
7712 if (body
->ext
.block
.case_list
)
7714 for (cp
= body
->ext
.block
.case_list
; cp
->next
; cp
= cp
->next
)
7716 if (cp
->next
->unreachable
)
7718 gfc_case
*n
= cp
->next
;
7719 cp
->next
= cp
->next
->next
;
7721 gfc_free_case_list (n
);
7728 /* See if there were overlapping cases. If the check returns NULL,
7729 there was overlap. In that case we don't do anything. If head
7730 is non-NULL, we prepend the DEFAULT case. The sorted list can
7731 then used during code generation for SELECT CASE constructs with
7732 a case expression of a CHARACTER type. */
7735 head
= check_case_overlap (head
);
7737 /* Prepend the default_case if it is there. */
7738 if (head
!= NULL
&& default_case
)
7740 default_case
->left
= NULL
;
7741 default_case
->right
= head
;
7742 head
->left
= default_case
;
7746 /* Eliminate dead blocks that may be the result if we've seen
7747 unreachable case labels for a block. */
7748 for (body
= code
; body
&& body
->block
; body
= body
->block
)
7750 if (body
->block
->ext
.block
.case_list
== NULL
)
7752 /* Cut the unreachable block from the code chain. */
7753 gfc_code
*c
= body
->block
;
7754 body
->block
= c
->block
;
7756 /* Kill the dead block, but not the blocks below it. */
7758 gfc_free_statements (c
);
7762 /* More than two cases is legal but insane for logical selects.
7763 Issue a warning for it. */
7764 if (gfc_option
.warn_surprising
&& type
== BT_LOGICAL
7766 gfc_warning ("Logical SELECT CASE block at %L has more that two cases",
7771 /* Check if a derived type is extensible. */
7774 gfc_type_is_extensible (gfc_symbol
*sym
)
7776 return !(sym
->attr
.is_bind_c
|| sym
->attr
.sequence
);
7780 /* Resolve an associate name: Resolve target and ensure the type-spec is
7781 correct as well as possibly the array-spec. */
7784 resolve_assoc_var (gfc_symbol
* sym
, bool resolve_target
)
7788 gcc_assert (sym
->assoc
);
7789 gcc_assert (sym
->attr
.flavor
== FL_VARIABLE
);
7791 /* If this is for SELECT TYPE, the target may not yet be set. In that
7792 case, return. Resolution will be called later manually again when
7794 target
= sym
->assoc
->target
;
7797 gcc_assert (!sym
->assoc
->dangling
);
7799 if (resolve_target
&& gfc_resolve_expr (target
) != SUCCESS
)
7802 /* For variable targets, we get some attributes from the target. */
7803 if (target
->expr_type
== EXPR_VARIABLE
)
7807 gcc_assert (target
->symtree
);
7808 tsym
= target
->symtree
->n
.sym
;
7810 sym
->attr
.asynchronous
= tsym
->attr
.asynchronous
;
7811 sym
->attr
.volatile_
= tsym
->attr
.volatile_
;
7813 sym
->attr
.target
= (tsym
->attr
.target
|| tsym
->attr
.pointer
);
7816 /* Get type if this was not already set. Note that it can be
7817 some other type than the target in case this is a SELECT TYPE
7818 selector! So we must not update when the type is already there. */
7819 if (sym
->ts
.type
== BT_UNKNOWN
)
7820 sym
->ts
= target
->ts
;
7821 gcc_assert (sym
->ts
.type
!= BT_UNKNOWN
);
7823 /* See if this is a valid association-to-variable. */
7824 sym
->assoc
->variable
= (target
->expr_type
== EXPR_VARIABLE
7825 && !gfc_has_vector_subscript (target
));
7827 /* Finally resolve if this is an array or not. */
7828 if (sym
->attr
.dimension
&& target
->rank
== 0)
7830 gfc_error ("Associate-name '%s' at %L is used as array",
7831 sym
->name
, &sym
->declared_at
);
7832 sym
->attr
.dimension
= 0;
7835 if (target
->rank
> 0)
7836 sym
->attr
.dimension
= 1;
7838 if (sym
->attr
.dimension
)
7840 sym
->as
= gfc_get_array_spec ();
7841 sym
->as
->rank
= target
->rank
;
7842 sym
->as
->type
= AS_DEFERRED
;
7844 /* Target must not be coindexed, thus the associate-variable
7846 sym
->as
->corank
= 0;
7851 /* Resolve a SELECT TYPE statement. */
7854 resolve_select_type (gfc_code
*code
, gfc_namespace
*old_ns
)
7856 gfc_symbol
*selector_type
;
7857 gfc_code
*body
, *new_st
, *if_st
, *tail
;
7858 gfc_code
*class_is
= NULL
, *default_case
= NULL
;
7861 char name
[GFC_MAX_SYMBOL_LEN
];
7865 ns
= code
->ext
.block
.ns
;
7868 /* Check for F03:C813. */
7869 if (code
->expr1
->ts
.type
!= BT_CLASS
7870 && !(code
->expr2
&& code
->expr2
->ts
.type
== BT_CLASS
))
7872 gfc_error ("Selector shall be polymorphic in SELECT TYPE statement "
7873 "at %L", &code
->loc
);
7879 if (code
->expr1
->symtree
->n
.sym
->attr
.untyped
)
7880 code
->expr1
->symtree
->n
.sym
->ts
= code
->expr2
->ts
;
7881 selector_type
= CLASS_DATA (code
->expr2
)->ts
.u
.derived
;
7884 selector_type
= CLASS_DATA (code
->expr1
)->ts
.u
.derived
;
7886 /* Loop over TYPE IS / CLASS IS cases. */
7887 for (body
= code
->block
; body
; body
= body
->block
)
7889 c
= body
->ext
.block
.case_list
;
7891 /* Check F03:C815. */
7892 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
7893 && !gfc_type_is_extensible (c
->ts
.u
.derived
))
7895 gfc_error ("Derived type '%s' at %L must be extensible",
7896 c
->ts
.u
.derived
->name
, &c
->where
);
7901 /* Check F03:C816. */
7902 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
7903 && !gfc_type_is_extension_of (selector_type
, c
->ts
.u
.derived
))
7905 gfc_error ("Derived type '%s' at %L must be an extension of '%s'",
7906 c
->ts
.u
.derived
->name
, &c
->where
, selector_type
->name
);
7911 /* Intercept the DEFAULT case. */
7912 if (c
->ts
.type
== BT_UNKNOWN
)
7914 /* Check F03:C818. */
7917 gfc_error ("The DEFAULT CASE at %L cannot be followed "
7918 "by a second DEFAULT CASE at %L",
7919 &default_case
->ext
.block
.case_list
->where
, &c
->where
);
7924 default_case
= body
;
7931 /* Transform SELECT TYPE statement to BLOCK and associate selector to
7932 target if present. If there are any EXIT statements referring to the
7933 SELECT TYPE construct, this is no problem because the gfc_code
7934 reference stays the same and EXIT is equally possible from the BLOCK
7935 it is changed to. */
7936 code
->op
= EXEC_BLOCK
;
7939 gfc_association_list
* assoc
;
7941 assoc
= gfc_get_association_list ();
7942 assoc
->st
= code
->expr1
->symtree
;
7943 assoc
->target
= gfc_copy_expr (code
->expr2
);
7944 /* assoc->variable will be set by resolve_assoc_var. */
7946 code
->ext
.block
.assoc
= assoc
;
7947 code
->expr1
->symtree
->n
.sym
->assoc
= assoc
;
7949 resolve_assoc_var (code
->expr1
->symtree
->n
.sym
, false);
7952 code
->ext
.block
.assoc
= NULL
;
7954 /* Add EXEC_SELECT to switch on type. */
7955 new_st
= gfc_get_code ();
7956 new_st
->op
= code
->op
;
7957 new_st
->expr1
= code
->expr1
;
7958 new_st
->expr2
= code
->expr2
;
7959 new_st
->block
= code
->block
;
7960 code
->expr1
= code
->expr2
= NULL
;
7965 ns
->code
->next
= new_st
;
7967 code
->op
= EXEC_SELECT
;
7968 gfc_add_vptr_component (code
->expr1
);
7969 gfc_add_hash_component (code
->expr1
);
7971 /* Loop over TYPE IS / CLASS IS cases. */
7972 for (body
= code
->block
; body
; body
= body
->block
)
7974 c
= body
->ext
.block
.case_list
;
7976 if (c
->ts
.type
== BT_DERIVED
)
7977 c
->low
= c
->high
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
7978 c
->ts
.u
.derived
->hash_value
);
7980 else if (c
->ts
.type
== BT_UNKNOWN
)
7983 /* Associate temporary to selector. This should only be done
7984 when this case is actually true, so build a new ASSOCIATE
7985 that does precisely this here (instead of using the
7988 if (c
->ts
.type
== BT_CLASS
)
7989 sprintf (name
, "__tmp_class_%s", c
->ts
.u
.derived
->name
);
7991 sprintf (name
, "__tmp_type_%s", c
->ts
.u
.derived
->name
);
7992 st
= gfc_find_symtree (ns
->sym_root
, name
);
7993 gcc_assert (st
->n
.sym
->assoc
);
7994 st
->n
.sym
->assoc
->target
= gfc_get_variable_expr (code
->expr1
->symtree
);
7995 if (c
->ts
.type
== BT_DERIVED
)
7996 gfc_add_data_component (st
->n
.sym
->assoc
->target
);
7998 new_st
= gfc_get_code ();
7999 new_st
->op
= EXEC_BLOCK
;
8000 new_st
->ext
.block
.ns
= gfc_build_block_ns (ns
);
8001 new_st
->ext
.block
.ns
->code
= body
->next
;
8002 body
->next
= new_st
;
8004 /* Chain in the new list only if it is marked as dangling. Otherwise
8005 there is a CASE label overlap and this is already used. Just ignore,
8006 the error is diagonsed elsewhere. */
8007 if (st
->n
.sym
->assoc
->dangling
)
8009 new_st
->ext
.block
.assoc
= st
->n
.sym
->assoc
;
8010 st
->n
.sym
->assoc
->dangling
= 0;
8013 resolve_assoc_var (st
->n
.sym
, false);
8016 /* Take out CLASS IS cases for separate treatment. */
8018 while (body
&& body
->block
)
8020 if (body
->block
->ext
.block
.case_list
->ts
.type
== BT_CLASS
)
8022 /* Add to class_is list. */
8023 if (class_is
== NULL
)
8025 class_is
= body
->block
;
8030 for (tail
= class_is
; tail
->block
; tail
= tail
->block
) ;
8031 tail
->block
= body
->block
;
8034 /* Remove from EXEC_SELECT list. */
8035 body
->block
= body
->block
->block
;
8048 /* Add a default case to hold the CLASS IS cases. */
8049 for (tail
= code
; tail
->block
; tail
= tail
->block
) ;
8050 tail
->block
= gfc_get_code ();
8052 tail
->op
= EXEC_SELECT_TYPE
;
8053 tail
->ext
.block
.case_list
= gfc_get_case ();
8054 tail
->ext
.block
.case_list
->ts
.type
= BT_UNKNOWN
;
8056 default_case
= tail
;
8059 /* More than one CLASS IS block? */
8060 if (class_is
->block
)
8064 /* Sort CLASS IS blocks by extension level. */
8068 for (c1
= &class_is
; (*c1
) && (*c1
)->block
; c1
= &((*c1
)->block
))
8071 /* F03:C817 (check for doubles). */
8072 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->hash_value
8073 == c2
->ext
.block
.case_list
->ts
.u
.derived
->hash_value
)
8075 gfc_error ("Double CLASS IS block in SELECT TYPE "
8077 &c2
->ext
.block
.case_list
->where
);
8080 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
8081 < c2
->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
)
8084 (*c1
)->block
= c2
->block
;
8094 /* Generate IF chain. */
8095 if_st
= gfc_get_code ();
8096 if_st
->op
= EXEC_IF
;
8098 for (body
= class_is
; body
; body
= body
->block
)
8100 new_st
->block
= gfc_get_code ();
8101 new_st
= new_st
->block
;
8102 new_st
->op
= EXEC_IF
;
8103 /* Set up IF condition: Call _gfortran_is_extension_of. */
8104 new_st
->expr1
= gfc_get_expr ();
8105 new_st
->expr1
->expr_type
= EXPR_FUNCTION
;
8106 new_st
->expr1
->ts
.type
= BT_LOGICAL
;
8107 new_st
->expr1
->ts
.kind
= 4;
8108 new_st
->expr1
->value
.function
.name
= gfc_get_string (PREFIX ("is_extension_of"));
8109 new_st
->expr1
->value
.function
.isym
= XCNEW (gfc_intrinsic_sym
);
8110 new_st
->expr1
->value
.function
.isym
->id
= GFC_ISYM_EXTENDS_TYPE_OF
;
8111 /* Set up arguments. */
8112 new_st
->expr1
->value
.function
.actual
= gfc_get_actual_arglist ();
8113 new_st
->expr1
->value
.function
.actual
->expr
= gfc_get_variable_expr (code
->expr1
->symtree
);
8114 new_st
->expr1
->value
.function
.actual
->expr
->where
= code
->loc
;
8115 gfc_add_vptr_component (new_st
->expr1
->value
.function
.actual
->expr
);
8116 vtab
= gfc_find_derived_vtab (body
->ext
.block
.case_list
->ts
.u
.derived
);
8117 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
8118 new_st
->expr1
->value
.function
.actual
->next
= gfc_get_actual_arglist ();
8119 new_st
->expr1
->value
.function
.actual
->next
->expr
= gfc_get_variable_expr (st
);
8120 new_st
->next
= body
->next
;
8122 if (default_case
->next
)
8124 new_st
->block
= gfc_get_code ();
8125 new_st
= new_st
->block
;
8126 new_st
->op
= EXEC_IF
;
8127 new_st
->next
= default_case
->next
;
8130 /* Replace CLASS DEFAULT code by the IF chain. */
8131 default_case
->next
= if_st
;
8134 /* Resolve the internal code. This can not be done earlier because
8135 it requires that the sym->assoc of selectors is set already. */
8136 gfc_current_ns
= ns
;
8137 gfc_resolve_blocks (code
->block
, gfc_current_ns
);
8138 gfc_current_ns
= old_ns
;
8140 resolve_select (code
);
8144 /* Resolve a transfer statement. This is making sure that:
8145 -- a derived type being transferred has only non-pointer components
8146 -- a derived type being transferred doesn't have private components, unless
8147 it's being transferred from the module where the type was defined
8148 -- we're not trying to transfer a whole assumed size array. */
8151 resolve_transfer (gfc_code
*code
)
8160 while (exp
!= NULL
&& exp
->expr_type
== EXPR_OP
8161 && exp
->value
.op
.op
== INTRINSIC_PARENTHESES
)
8162 exp
= exp
->value
.op
.op1
;
8164 if (exp
&& exp
->expr_type
== EXPR_NULL
&& exp
->ts
.type
== BT_UNKNOWN
)
8166 gfc_error ("NULL intrinsic at %L in data transfer statement requires "
8167 "MOLD=", &exp
->where
);
8171 if (exp
== NULL
|| (exp
->expr_type
!= EXPR_VARIABLE
8172 && exp
->expr_type
!= EXPR_FUNCTION
))
8175 /* If we are reading, the variable will be changed. Note that
8176 code->ext.dt may be NULL if the TRANSFER is related to
8177 an INQUIRE statement -- but in this case, we are not reading, either. */
8178 if (code
->ext
.dt
&& code
->ext
.dt
->dt_io_kind
->value
.iokind
== M_READ
8179 && gfc_check_vardef_context (exp
, false, false, _("item in READ"))
8183 sym
= exp
->symtree
->n
.sym
;
8186 /* Go to actual component transferred. */
8187 for (ref
= exp
->ref
; ref
; ref
= ref
->next
)
8188 if (ref
->type
== REF_COMPONENT
)
8189 ts
= &ref
->u
.c
.component
->ts
;
8191 if (ts
->type
== BT_CLASS
)
8193 /* FIXME: Test for defined input/output. */
8194 gfc_error ("Data transfer element at %L cannot be polymorphic unless "
8195 "it is processed by a defined input/output procedure",
8200 if (ts
->type
== BT_DERIVED
)
8202 /* Check that transferred derived type doesn't contain POINTER
8204 if (ts
->u
.derived
->attr
.pointer_comp
)
8206 gfc_error ("Data transfer element at %L cannot have POINTER "
8207 "components unless it is processed by a defined "
8208 "input/output procedure", &code
->loc
);
8213 if (ts
->u
.derived
->attr
.proc_pointer_comp
)
8215 gfc_error ("Data transfer element at %L cannot have "
8216 "procedure pointer components", &code
->loc
);
8220 if (ts
->u
.derived
->attr
.alloc_comp
)
8222 gfc_error ("Data transfer element at %L cannot have ALLOCATABLE "
8223 "components unless it is processed by a defined "
8224 "input/output procedure", &code
->loc
);
8228 if (derived_inaccessible (ts
->u
.derived
))
8230 gfc_error ("Data transfer element at %L cannot have "
8231 "PRIVATE components",&code
->loc
);
8236 if (sym
->as
!= NULL
&& sym
->as
->type
== AS_ASSUMED_SIZE
&& exp
->ref
8237 && exp
->ref
->type
== REF_ARRAY
&& exp
->ref
->u
.ar
.type
== AR_FULL
)
8239 gfc_error ("Data transfer element at %L cannot be a full reference to "
8240 "an assumed-size array", &code
->loc
);
8246 /*********** Toplevel code resolution subroutines ***********/
8248 /* Find the set of labels that are reachable from this block. We also
8249 record the last statement in each block. */
8252 find_reachable_labels (gfc_code
*block
)
8259 cs_base
->reachable_labels
= bitmap_obstack_alloc (&labels_obstack
);
8261 /* Collect labels in this block. We don't keep those corresponding
8262 to END {IF|SELECT}, these are checked in resolve_branch by going
8263 up through the code_stack. */
8264 for (c
= block
; c
; c
= c
->next
)
8266 if (c
->here
&& c
->op
!= EXEC_END_NESTED_BLOCK
)
8267 bitmap_set_bit (cs_base
->reachable_labels
, c
->here
->value
);
8270 /* Merge with labels from parent block. */
8273 gcc_assert (cs_base
->prev
->reachable_labels
);
8274 bitmap_ior_into (cs_base
->reachable_labels
,
8275 cs_base
->prev
->reachable_labels
);
8281 resolve_lock_unlock (gfc_code
*code
)
8283 if (code
->expr1
->ts
.type
!= BT_DERIVED
8284 || code
->expr1
->expr_type
!= EXPR_VARIABLE
8285 || code
->expr1
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
8286 || code
->expr1
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_LOCK_TYPE
8287 || code
->expr1
->rank
!= 0
8288 || (!gfc_is_coarray (code
->expr1
) && !gfc_is_coindexed (code
->expr1
)))
8289 gfc_error ("Lock variable at %L must be a scalar of type LOCK_TYPE",
8290 &code
->expr1
->where
);
8294 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
8295 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
8296 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
8297 &code
->expr2
->where
);
8300 && gfc_check_vardef_context (code
->expr2
, false, false,
8301 _("STAT variable")) == FAILURE
)
8306 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
8307 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
8308 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
8309 &code
->expr3
->where
);
8312 && gfc_check_vardef_context (code
->expr3
, false, false,
8313 _("ERRMSG variable")) == FAILURE
)
8316 /* Check ACQUIRED_LOCK. */
8318 && (code
->expr4
->ts
.type
!= BT_LOGICAL
|| code
->expr4
->rank
!= 0
8319 || code
->expr4
->expr_type
!= EXPR_VARIABLE
))
8320 gfc_error ("ACQUIRED_LOCK= argument at %L must be a scalar LOGICAL "
8321 "variable", &code
->expr4
->where
);
8324 && gfc_check_vardef_context (code
->expr4
, false, false,
8325 _("ACQUIRED_LOCK variable")) == FAILURE
)
8331 resolve_sync (gfc_code
*code
)
8333 /* Check imageset. The * case matches expr1 == NULL. */
8336 if (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
> 1)
8337 gfc_error ("Imageset argument at %L must be a scalar or rank-1 "
8338 "INTEGER expression", &code
->expr1
->where
);
8339 if (code
->expr1
->expr_type
== EXPR_CONSTANT
&& code
->expr1
->rank
== 0
8340 && mpz_cmp_si (code
->expr1
->value
.integer
, 1) < 0)
8341 gfc_error ("Imageset argument at %L must between 1 and num_images()",
8342 &code
->expr1
->where
);
8343 else if (code
->expr1
->expr_type
== EXPR_ARRAY
8344 && gfc_simplify_expr (code
->expr1
, 0) == SUCCESS
)
8346 gfc_constructor
*cons
;
8347 cons
= gfc_constructor_first (code
->expr1
->value
.constructor
);
8348 for (; cons
; cons
= gfc_constructor_next (cons
))
8349 if (cons
->expr
->expr_type
== EXPR_CONSTANT
8350 && mpz_cmp_si (cons
->expr
->value
.integer
, 1) < 0)
8351 gfc_error ("Imageset argument at %L must between 1 and "
8352 "num_images()", &cons
->expr
->where
);
8358 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
8359 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
8360 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
8361 &code
->expr2
->where
);
8365 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
8366 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
8367 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
8368 &code
->expr3
->where
);
8372 /* Given a branch to a label, see if the branch is conforming.
8373 The code node describes where the branch is located. */
8376 resolve_branch (gfc_st_label
*label
, gfc_code
*code
)
8383 /* Step one: is this a valid branching target? */
8385 if (label
->defined
== ST_LABEL_UNKNOWN
)
8387 gfc_error ("Label %d referenced at %L is never defined", label
->value
,
8392 if (label
->defined
!= ST_LABEL_TARGET
)
8394 gfc_error ("Statement at %L is not a valid branch target statement "
8395 "for the branch statement at %L", &label
->where
, &code
->loc
);
8399 /* Step two: make sure this branch is not a branch to itself ;-) */
8401 if (code
->here
== label
)
8403 gfc_warning ("Branch at %L may result in an infinite loop", &code
->loc
);
8407 /* Step three: See if the label is in the same block as the
8408 branching statement. The hard work has been done by setting up
8409 the bitmap reachable_labels. */
8411 if (bitmap_bit_p (cs_base
->reachable_labels
, label
->value
))
8413 /* Check now whether there is a CRITICAL construct; if so, check
8414 whether the label is still visible outside of the CRITICAL block,
8415 which is invalid. */
8416 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
8418 if (stack
->current
->op
== EXEC_CRITICAL
8419 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
8420 gfc_error ("GOTO statement at %L leaves CRITICAL construct for "
8421 "label at %L", &code
->loc
, &label
->where
);
8422 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
8423 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
8424 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct "
8425 "for label at %L", &code
->loc
, &label
->where
);
8431 /* Step four: If we haven't found the label in the bitmap, it may
8432 still be the label of the END of the enclosing block, in which
8433 case we find it by going up the code_stack. */
8435 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
8437 if (stack
->current
->next
&& stack
->current
->next
->here
== label
)
8439 if (stack
->current
->op
== EXEC_CRITICAL
)
8441 /* Note: A label at END CRITICAL does not leave the CRITICAL
8442 construct as END CRITICAL is still part of it. */
8443 gfc_error ("GOTO statement at %L leaves CRITICAL construct for label"
8444 " at %L", &code
->loc
, &label
->where
);
8447 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
)
8449 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct for "
8450 "label at %L", &code
->loc
, &label
->where
);
8457 gcc_assert (stack
->current
->next
->op
== EXEC_END_NESTED_BLOCK
);
8461 /* The label is not in an enclosing block, so illegal. This was
8462 allowed in Fortran 66, so we allow it as extension. No
8463 further checks are necessary in this case. */
8464 gfc_notify_std (GFC_STD_LEGACY
, "Label at %L is not in the same block "
8465 "as the GOTO statement at %L", &label
->where
,
8471 /* Check whether EXPR1 has the same shape as EXPR2. */
8474 resolve_where_shape (gfc_expr
*expr1
, gfc_expr
*expr2
)
8476 mpz_t shape
[GFC_MAX_DIMENSIONS
];
8477 mpz_t shape2
[GFC_MAX_DIMENSIONS
];
8478 gfc_try result
= FAILURE
;
8481 /* Compare the rank. */
8482 if (expr1
->rank
!= expr2
->rank
)
8485 /* Compare the size of each dimension. */
8486 for (i
=0; i
<expr1
->rank
; i
++)
8488 if (gfc_array_dimen_size (expr1
, i
, &shape
[i
]) == FAILURE
)
8491 if (gfc_array_dimen_size (expr2
, i
, &shape2
[i
]) == FAILURE
)
8494 if (mpz_cmp (shape
[i
], shape2
[i
]))
8498 /* When either of the two expression is an assumed size array, we
8499 ignore the comparison of dimension sizes. */
8504 gfc_clear_shape (shape
, i
);
8505 gfc_clear_shape (shape2
, i
);
8510 /* Check whether a WHERE assignment target or a WHERE mask expression
8511 has the same shape as the outmost WHERE mask expression. */
8514 resolve_where (gfc_code
*code
, gfc_expr
*mask
)
8520 cblock
= code
->block
;
8522 /* Store the first WHERE mask-expr of the WHERE statement or construct.
8523 In case of nested WHERE, only the outmost one is stored. */
8524 if (mask
== NULL
) /* outmost WHERE */
8526 else /* inner WHERE */
8533 /* Check if the mask-expr has a consistent shape with the
8534 outmost WHERE mask-expr. */
8535 if (resolve_where_shape (cblock
->expr1
, e
) == FAILURE
)
8536 gfc_error ("WHERE mask at %L has inconsistent shape",
8537 &cblock
->expr1
->where
);
8540 /* the assignment statement of a WHERE statement, or the first
8541 statement in where-body-construct of a WHERE construct */
8542 cnext
= cblock
->next
;
8547 /* WHERE assignment statement */
8550 /* Check shape consistent for WHERE assignment target. */
8551 if (e
&& resolve_where_shape (cnext
->expr1
, e
) == FAILURE
)
8552 gfc_error ("WHERE assignment target at %L has "
8553 "inconsistent shape", &cnext
->expr1
->where
);
8557 case EXEC_ASSIGN_CALL
:
8558 resolve_call (cnext
);
8559 if (!cnext
->resolved_sym
->attr
.elemental
)
8560 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
8561 &cnext
->ext
.actual
->expr
->where
);
8564 /* WHERE or WHERE construct is part of a where-body-construct */
8566 resolve_where (cnext
, e
);
8570 gfc_error ("Unsupported statement inside WHERE at %L",
8573 /* the next statement within the same where-body-construct */
8574 cnext
= cnext
->next
;
8576 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
8577 cblock
= cblock
->block
;
8582 /* Resolve assignment in FORALL construct.
8583 NVAR is the number of FORALL index variables, and VAR_EXPR records the
8584 FORALL index variables. */
8587 gfc_resolve_assign_in_forall (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
8591 for (n
= 0; n
< nvar
; n
++)
8593 gfc_symbol
*forall_index
;
8595 forall_index
= var_expr
[n
]->symtree
->n
.sym
;
8597 /* Check whether the assignment target is one of the FORALL index
8599 if ((code
->expr1
->expr_type
== EXPR_VARIABLE
)
8600 && (code
->expr1
->symtree
->n
.sym
== forall_index
))
8601 gfc_error ("Assignment to a FORALL index variable at %L",
8602 &code
->expr1
->where
);
8605 /* If one of the FORALL index variables doesn't appear in the
8606 assignment variable, then there could be a many-to-one
8607 assignment. Emit a warning rather than an error because the
8608 mask could be resolving this problem. */
8609 if (find_forall_index (code
->expr1
, forall_index
, 0) == FAILURE
)
8610 gfc_warning ("The FORALL with index '%s' is not used on the "
8611 "left side of the assignment at %L and so might "
8612 "cause multiple assignment to this object",
8613 var_expr
[n
]->symtree
->name
, &code
->expr1
->where
);
8619 /* Resolve WHERE statement in FORALL construct. */
8622 gfc_resolve_where_code_in_forall (gfc_code
*code
, int nvar
,
8623 gfc_expr
**var_expr
)
8628 cblock
= code
->block
;
8631 /* the assignment statement of a WHERE statement, or the first
8632 statement in where-body-construct of a WHERE construct */
8633 cnext
= cblock
->next
;
8638 /* WHERE assignment statement */
8640 gfc_resolve_assign_in_forall (cnext
, nvar
, var_expr
);
8643 /* WHERE operator assignment statement */
8644 case EXEC_ASSIGN_CALL
:
8645 resolve_call (cnext
);
8646 if (!cnext
->resolved_sym
->attr
.elemental
)
8647 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
8648 &cnext
->ext
.actual
->expr
->where
);
8651 /* WHERE or WHERE construct is part of a where-body-construct */
8653 gfc_resolve_where_code_in_forall (cnext
, nvar
, var_expr
);
8657 gfc_error ("Unsupported statement inside WHERE at %L",
8660 /* the next statement within the same where-body-construct */
8661 cnext
= cnext
->next
;
8663 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
8664 cblock
= cblock
->block
;
8669 /* Traverse the FORALL body to check whether the following errors exist:
8670 1. For assignment, check if a many-to-one assignment happens.
8671 2. For WHERE statement, check the WHERE body to see if there is any
8672 many-to-one assignment. */
8675 gfc_resolve_forall_body (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
8679 c
= code
->block
->next
;
8685 case EXEC_POINTER_ASSIGN
:
8686 gfc_resolve_assign_in_forall (c
, nvar
, var_expr
);
8689 case EXEC_ASSIGN_CALL
:
8693 /* Because the gfc_resolve_blocks() will handle the nested FORALL,
8694 there is no need to handle it here. */
8698 gfc_resolve_where_code_in_forall(c
, nvar
, var_expr
);
8703 /* The next statement in the FORALL body. */
8709 /* Counts the number of iterators needed inside a forall construct, including
8710 nested forall constructs. This is used to allocate the needed memory
8711 in gfc_resolve_forall. */
8714 gfc_count_forall_iterators (gfc_code
*code
)
8716 int max_iters
, sub_iters
, current_iters
;
8717 gfc_forall_iterator
*fa
;
8719 gcc_assert(code
->op
== EXEC_FORALL
);
8723 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
8726 code
= code
->block
->next
;
8730 if (code
->op
== EXEC_FORALL
)
8732 sub_iters
= gfc_count_forall_iterators (code
);
8733 if (sub_iters
> max_iters
)
8734 max_iters
= sub_iters
;
8739 return current_iters
+ max_iters
;
8743 /* Given a FORALL construct, first resolve the FORALL iterator, then call
8744 gfc_resolve_forall_body to resolve the FORALL body. */
8747 gfc_resolve_forall (gfc_code
*code
, gfc_namespace
*ns
, int forall_save
)
8749 static gfc_expr
**var_expr
;
8750 static int total_var
= 0;
8751 static int nvar
= 0;
8753 gfc_forall_iterator
*fa
;
8758 /* Start to resolve a FORALL construct */
8759 if (forall_save
== 0)
8761 /* Count the total number of FORALL index in the nested FORALL
8762 construct in order to allocate the VAR_EXPR with proper size. */
8763 total_var
= gfc_count_forall_iterators (code
);
8765 /* Allocate VAR_EXPR with NUMBER_OF_FORALL_INDEX elements. */
8766 var_expr
= XCNEWVEC (gfc_expr
*, total_var
);
8769 /* The information about FORALL iterator, including FORALL index start, end
8770 and stride. The FORALL index can not appear in start, end or stride. */
8771 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
8773 /* Check if any outer FORALL index name is the same as the current
8775 for (i
= 0; i
< nvar
; i
++)
8777 if (fa
->var
->symtree
->n
.sym
== var_expr
[i
]->symtree
->n
.sym
)
8779 gfc_error ("An outer FORALL construct already has an index "
8780 "with this name %L", &fa
->var
->where
);
8784 /* Record the current FORALL index. */
8785 var_expr
[nvar
] = gfc_copy_expr (fa
->var
);
8789 /* No memory leak. */
8790 gcc_assert (nvar
<= total_var
);
8793 /* Resolve the FORALL body. */
8794 gfc_resolve_forall_body (code
, nvar
, var_expr
);
8796 /* May call gfc_resolve_forall to resolve the inner FORALL loop. */
8797 gfc_resolve_blocks (code
->block
, ns
);
8801 /* Free only the VAR_EXPRs allocated in this frame. */
8802 for (i
= nvar
; i
< tmp
; i
++)
8803 gfc_free_expr (var_expr
[i
]);
8807 /* We are in the outermost FORALL construct. */
8808 gcc_assert (forall_save
== 0);
8810 /* VAR_EXPR is not needed any more. */
8817 /* Resolve a BLOCK construct statement. */
8820 resolve_block_construct (gfc_code
* code
)
8822 /* Resolve the BLOCK's namespace. */
8823 gfc_resolve (code
->ext
.block
.ns
);
8825 /* For an ASSOCIATE block, the associations (and their targets) are already
8826 resolved during resolve_symbol. */
8830 /* Resolve lists of blocks found in IF, SELECT CASE, WHERE, FORALL, GOTO and
8833 static void resolve_code (gfc_code
*, gfc_namespace
*);
8836 gfc_resolve_blocks (gfc_code
*b
, gfc_namespace
*ns
)
8840 for (; b
; b
= b
->block
)
8842 t
= gfc_resolve_expr (b
->expr1
);
8843 if (gfc_resolve_expr (b
->expr2
) == FAILURE
)
8849 if (t
== SUCCESS
&& b
->expr1
!= NULL
8850 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
!= 0))
8851 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
8858 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
== 0))
8859 gfc_error ("WHERE/ELSEWHERE clause at %L requires a LOGICAL array",
8864 resolve_branch (b
->label1
, b
);
8868 resolve_block_construct (b
);
8872 case EXEC_SELECT_TYPE
:
8876 case EXEC_DO_CONCURRENT
:
8884 case EXEC_OMP_ATOMIC
:
8885 case EXEC_OMP_CRITICAL
:
8887 case EXEC_OMP_MASTER
:
8888 case EXEC_OMP_ORDERED
:
8889 case EXEC_OMP_PARALLEL
:
8890 case EXEC_OMP_PARALLEL_DO
:
8891 case EXEC_OMP_PARALLEL_SECTIONS
:
8892 case EXEC_OMP_PARALLEL_WORKSHARE
:
8893 case EXEC_OMP_SECTIONS
:
8894 case EXEC_OMP_SINGLE
:
8896 case EXEC_OMP_TASKWAIT
:
8897 case EXEC_OMP_TASKYIELD
:
8898 case EXEC_OMP_WORKSHARE
:
8902 gfc_internal_error ("gfc_resolve_blocks(): Bad block type");
8905 resolve_code (b
->next
, ns
);
8910 /* Does everything to resolve an ordinary assignment. Returns true
8911 if this is an interface assignment. */
8913 resolve_ordinary_assign (gfc_code
*code
, gfc_namespace
*ns
)
8923 if (gfc_extend_assign (code
, ns
) == SUCCESS
)
8927 if (code
->op
== EXEC_ASSIGN_CALL
)
8929 lhs
= code
->ext
.actual
->expr
;
8930 rhsptr
= &code
->ext
.actual
->next
->expr
;
8934 gfc_actual_arglist
* args
;
8935 gfc_typebound_proc
* tbp
;
8937 gcc_assert (code
->op
== EXEC_COMPCALL
);
8939 args
= code
->expr1
->value
.compcall
.actual
;
8941 rhsptr
= &args
->next
->expr
;
8943 tbp
= code
->expr1
->value
.compcall
.tbp
;
8944 gcc_assert (!tbp
->is_generic
);
8947 /* Make a temporary rhs when there is a default initializer
8948 and rhs is the same symbol as the lhs. */
8949 if ((*rhsptr
)->expr_type
== EXPR_VARIABLE
8950 && (*rhsptr
)->symtree
->n
.sym
->ts
.type
== BT_DERIVED
8951 && gfc_has_default_initializer ((*rhsptr
)->symtree
->n
.sym
->ts
.u
.derived
)
8952 && (lhs
->symtree
->n
.sym
== (*rhsptr
)->symtree
->n
.sym
))
8953 *rhsptr
= gfc_get_parentheses (*rhsptr
);
8962 && gfc_notify_std (GFC_STD_GNU
, "Extension: BOZ literal at %L outside "
8963 "a DATA statement and outside INT/REAL/DBLE/CMPLX",
8964 &code
->loc
) == FAILURE
)
8967 /* Handle the case of a BOZ literal on the RHS. */
8968 if (rhs
->is_boz
&& lhs
->ts
.type
!= BT_INTEGER
)
8971 if (gfc_option
.warn_surprising
)
8972 gfc_warning ("BOZ literal at %L is bitwise transferred "
8973 "non-integer symbol '%s'", &code
->loc
,
8974 lhs
->symtree
->n
.sym
->name
);
8976 if (!gfc_convert_boz (rhs
, &lhs
->ts
))
8978 if ((rc
= gfc_range_check (rhs
)) != ARITH_OK
)
8980 if (rc
== ARITH_UNDERFLOW
)
8981 gfc_error ("Arithmetic underflow of bit-wise transferred BOZ at %L"
8982 ". This check can be disabled with the option "
8983 "-fno-range-check", &rhs
->where
);
8984 else if (rc
== ARITH_OVERFLOW
)
8985 gfc_error ("Arithmetic overflow of bit-wise transferred BOZ at %L"
8986 ". This check can be disabled with the option "
8987 "-fno-range-check", &rhs
->where
);
8988 else if (rc
== ARITH_NAN
)
8989 gfc_error ("Arithmetic NaN of bit-wise transferred BOZ at %L"
8990 ". This check can be disabled with the option "
8991 "-fno-range-check", &rhs
->where
);
8996 if (lhs
->ts
.type
== BT_CHARACTER
8997 && gfc_option
.warn_character_truncation
)
8999 if (lhs
->ts
.u
.cl
!= NULL
9000 && lhs
->ts
.u
.cl
->length
!= NULL
9001 && lhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9002 llen
= mpz_get_si (lhs
->ts
.u
.cl
->length
->value
.integer
);
9004 if (rhs
->expr_type
== EXPR_CONSTANT
)
9005 rlen
= rhs
->value
.character
.length
;
9007 else if (rhs
->ts
.u
.cl
!= NULL
9008 && rhs
->ts
.u
.cl
->length
!= NULL
9009 && rhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9010 rlen
= mpz_get_si (rhs
->ts
.u
.cl
->length
->value
.integer
);
9012 if (rlen
&& llen
&& rlen
> llen
)
9013 gfc_warning_now ("CHARACTER expression will be truncated "
9014 "in assignment (%d/%d) at %L",
9015 llen
, rlen
, &code
->loc
);
9018 /* Ensure that a vector index expression for the lvalue is evaluated
9019 to a temporary if the lvalue symbol is referenced in it. */
9022 for (ref
= lhs
->ref
; ref
; ref
= ref
->next
)
9023 if (ref
->type
== REF_ARRAY
)
9025 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
9026 if (ref
->u
.ar
.dimen_type
[n
] == DIMEN_VECTOR
9027 && gfc_find_sym_in_expr (lhs
->symtree
->n
.sym
,
9028 ref
->u
.ar
.start
[n
]))
9030 = gfc_get_parentheses (ref
->u
.ar
.start
[n
]);
9034 if (gfc_pure (NULL
))
9036 if (lhs
->ts
.type
== BT_DERIVED
9037 && lhs
->expr_type
== EXPR_VARIABLE
9038 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9039 && rhs
->expr_type
== EXPR_VARIABLE
9040 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9041 || gfc_is_coindexed (rhs
)))
9044 if (gfc_is_coindexed (rhs
))
9045 gfc_error ("Coindexed expression at %L is assigned to "
9046 "a derived type variable with a POINTER "
9047 "component in a PURE procedure",
9050 gfc_error ("The impure variable at %L is assigned to "
9051 "a derived type variable with a POINTER "
9052 "component in a PURE procedure (12.6)",
9057 /* Fortran 2008, C1283. */
9058 if (gfc_is_coindexed (lhs
))
9060 gfc_error ("Assignment to coindexed variable at %L in a PURE "
9061 "procedure", &rhs
->where
);
9066 if (gfc_implicit_pure (NULL
))
9068 if (lhs
->expr_type
== EXPR_VARIABLE
9069 && lhs
->symtree
->n
.sym
!= gfc_current_ns
->proc_name
9070 && lhs
->symtree
->n
.sym
->ns
!= gfc_current_ns
)
9071 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
9073 if (lhs
->ts
.type
== BT_DERIVED
9074 && lhs
->expr_type
== EXPR_VARIABLE
9075 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9076 && rhs
->expr_type
== EXPR_VARIABLE
9077 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9078 || gfc_is_coindexed (rhs
)))
9079 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
9081 /* Fortran 2008, C1283. */
9082 if (gfc_is_coindexed (lhs
))
9083 gfc_current_ns
->proc_name
->attr
.implicit_pure
= 0;
9087 /* FIXME: Valid in Fortran 2008, unless the LHS is both polymorphic
9088 and coindexed; cf. F2008, 7.2.1.2 and PR 43366. */
9089 if (lhs
->ts
.type
== BT_CLASS
)
9091 gfc_error ("Variable must not be polymorphic in assignment at %L",
9096 /* F2008, Section 7.2.1.2. */
9097 if (gfc_is_coindexed (lhs
) && gfc_has_ultimate_allocatable (lhs
))
9099 gfc_error ("Coindexed variable must not be have an allocatable ultimate "
9100 "component in assignment at %L", &lhs
->where
);
9104 gfc_check_assign (lhs
, rhs
, 1);
9109 /* Given a block of code, recursively resolve everything pointed to by this
9113 resolve_code (gfc_code
*code
, gfc_namespace
*ns
)
9115 int omp_workshare_save
;
9116 int forall_save
, do_concurrent_save
;
9120 frame
.prev
= cs_base
;
9124 find_reachable_labels (code
);
9126 for (; code
; code
= code
->next
)
9128 frame
.current
= code
;
9129 forall_save
= forall_flag
;
9130 do_concurrent_save
= do_concurrent_flag
;
9132 if (code
->op
== EXEC_FORALL
)
9135 gfc_resolve_forall (code
, ns
, forall_save
);
9138 else if (code
->block
)
9140 omp_workshare_save
= -1;
9143 case EXEC_OMP_PARALLEL_WORKSHARE
:
9144 omp_workshare_save
= omp_workshare_flag
;
9145 omp_workshare_flag
= 1;
9146 gfc_resolve_omp_parallel_blocks (code
, ns
);
9148 case EXEC_OMP_PARALLEL
:
9149 case EXEC_OMP_PARALLEL_DO
:
9150 case EXEC_OMP_PARALLEL_SECTIONS
:
9152 omp_workshare_save
= omp_workshare_flag
;
9153 omp_workshare_flag
= 0;
9154 gfc_resolve_omp_parallel_blocks (code
, ns
);
9157 gfc_resolve_omp_do_blocks (code
, ns
);
9159 case EXEC_SELECT_TYPE
:
9160 /* Blocks are handled in resolve_select_type because we have
9161 to transform the SELECT TYPE into ASSOCIATE first. */
9163 case EXEC_DO_CONCURRENT
:
9164 do_concurrent_flag
= 1;
9165 gfc_resolve_blocks (code
->block
, ns
);
9166 do_concurrent_flag
= 2;
9168 case EXEC_OMP_WORKSHARE
:
9169 omp_workshare_save
= omp_workshare_flag
;
9170 omp_workshare_flag
= 1;
9173 gfc_resolve_blocks (code
->block
, ns
);
9177 if (omp_workshare_save
!= -1)
9178 omp_workshare_flag
= omp_workshare_save
;
9182 if (code
->op
!= EXEC_COMPCALL
&& code
->op
!= EXEC_CALL_PPC
)
9183 t
= gfc_resolve_expr (code
->expr1
);
9184 forall_flag
= forall_save
;
9185 do_concurrent_flag
= do_concurrent_save
;
9187 if (gfc_resolve_expr (code
->expr2
) == FAILURE
)
9190 if (code
->op
== EXEC_ALLOCATE
9191 && gfc_resolve_expr (code
->expr3
) == FAILURE
)
9197 case EXEC_END_BLOCK
:
9198 case EXEC_END_NESTED_BLOCK
:
9202 case EXEC_ERROR_STOP
:
9206 case EXEC_ASSIGN_CALL
:
9211 case EXEC_SYNC_IMAGES
:
9212 case EXEC_SYNC_MEMORY
:
9213 resolve_sync (code
);
9218 resolve_lock_unlock (code
);
9222 /* Keep track of which entry we are up to. */
9223 current_entry_id
= code
->ext
.entry
->id
;
9227 resolve_where (code
, NULL
);
9231 if (code
->expr1
!= NULL
)
9233 if (code
->expr1
->ts
.type
!= BT_INTEGER
)
9234 gfc_error ("ASSIGNED GOTO statement at %L requires an "
9235 "INTEGER variable", &code
->expr1
->where
);
9236 else if (code
->expr1
->symtree
->n
.sym
->attr
.assign
!= 1)
9237 gfc_error ("Variable '%s' has not been assigned a target "
9238 "label at %L", code
->expr1
->symtree
->n
.sym
->name
,
9239 &code
->expr1
->where
);
9242 resolve_branch (code
->label1
, code
);
9246 if (code
->expr1
!= NULL
9247 && (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
))
9248 gfc_error ("Alternate RETURN statement at %L requires a SCALAR-"
9249 "INTEGER return specifier", &code
->expr1
->where
);
9252 case EXEC_INIT_ASSIGN
:
9253 case EXEC_END_PROCEDURE
:
9260 if (gfc_check_vardef_context (code
->expr1
, false, false,
9261 _("assignment")) == FAILURE
)
9264 if (resolve_ordinary_assign (code
, ns
))
9266 if (code
->op
== EXEC_COMPCALL
)
9273 case EXEC_LABEL_ASSIGN
:
9274 if (code
->label1
->defined
== ST_LABEL_UNKNOWN
)
9275 gfc_error ("Label %d referenced at %L is never defined",
9276 code
->label1
->value
, &code
->label1
->where
);
9278 && (code
->expr1
->expr_type
!= EXPR_VARIABLE
9279 || code
->expr1
->symtree
->n
.sym
->ts
.type
!= BT_INTEGER
9280 || code
->expr1
->symtree
->n
.sym
->ts
.kind
9281 != gfc_default_integer_kind
9282 || code
->expr1
->symtree
->n
.sym
->as
!= NULL
))
9283 gfc_error ("ASSIGN statement at %L requires a scalar "
9284 "default INTEGER variable", &code
->expr1
->where
);
9287 case EXEC_POINTER_ASSIGN
:
9294 /* This is both a variable definition and pointer assignment
9295 context, so check both of them. For rank remapping, a final
9296 array ref may be present on the LHS and fool gfc_expr_attr
9297 used in gfc_check_vardef_context. Remove it. */
9298 e
= remove_last_array_ref (code
->expr1
);
9299 t
= gfc_check_vardef_context (e
, true, false,
9300 _("pointer assignment"));
9302 t
= gfc_check_vardef_context (e
, false, false,
9303 _("pointer assignment"));
9308 gfc_check_pointer_assign (code
->expr1
, code
->expr2
);
9312 case EXEC_ARITHMETIC_IF
:
9314 && code
->expr1
->ts
.type
!= BT_INTEGER
9315 && code
->expr1
->ts
.type
!= BT_REAL
)
9316 gfc_error ("Arithmetic IF statement at %L requires a numeric "
9317 "expression", &code
->expr1
->where
);
9319 resolve_branch (code
->label1
, code
);
9320 resolve_branch (code
->label2
, code
);
9321 resolve_branch (code
->label3
, code
);
9325 if (t
== SUCCESS
&& code
->expr1
!= NULL
9326 && (code
->expr1
->ts
.type
!= BT_LOGICAL
9327 || code
->expr1
->rank
!= 0))
9328 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
9329 &code
->expr1
->where
);
9334 resolve_call (code
);
9339 resolve_typebound_subroutine (code
);
9343 resolve_ppc_call (code
);
9347 /* Select is complicated. Also, a SELECT construct could be
9348 a transformed computed GOTO. */
9349 resolve_select (code
);
9352 case EXEC_SELECT_TYPE
:
9353 resolve_select_type (code
, ns
);
9357 resolve_block_construct (code
);
9361 if (code
->ext
.iterator
!= NULL
)
9363 gfc_iterator
*iter
= code
->ext
.iterator
;
9364 if (gfc_resolve_iterator (iter
, true) != FAILURE
)
9365 gfc_resolve_do_iterator (code
, iter
->var
->symtree
->n
.sym
);
9370 if (code
->expr1
== NULL
)
9371 gfc_internal_error ("resolve_code(): No expression on DO WHILE");
9373 && (code
->expr1
->rank
!= 0
9374 || code
->expr1
->ts
.type
!= BT_LOGICAL
))
9375 gfc_error ("Exit condition of DO WHILE loop at %L must be "
9376 "a scalar LOGICAL expression", &code
->expr1
->where
);
9381 resolve_allocate_deallocate (code
, "ALLOCATE");
9385 case EXEC_DEALLOCATE
:
9387 resolve_allocate_deallocate (code
, "DEALLOCATE");
9392 if (gfc_resolve_open (code
->ext
.open
) == FAILURE
)
9395 resolve_branch (code
->ext
.open
->err
, code
);
9399 if (gfc_resolve_close (code
->ext
.close
) == FAILURE
)
9402 resolve_branch (code
->ext
.close
->err
, code
);
9405 case EXEC_BACKSPACE
:
9409 if (gfc_resolve_filepos (code
->ext
.filepos
) == FAILURE
)
9412 resolve_branch (code
->ext
.filepos
->err
, code
);
9416 if (gfc_resolve_inquire (code
->ext
.inquire
) == FAILURE
)
9419 resolve_branch (code
->ext
.inquire
->err
, code
);
9423 gcc_assert (code
->ext
.inquire
!= NULL
);
9424 if (gfc_resolve_inquire (code
->ext
.inquire
) == FAILURE
)
9427 resolve_branch (code
->ext
.inquire
->err
, code
);
9431 if (gfc_resolve_wait (code
->ext
.wait
) == FAILURE
)
9434 resolve_branch (code
->ext
.wait
->err
, code
);
9435 resolve_branch (code
->ext
.wait
->end
, code
);
9436 resolve_branch (code
->ext
.wait
->eor
, code
);
9441 if (gfc_resolve_dt (code
->ext
.dt
, &code
->loc
) == FAILURE
)
9444 resolve_branch (code
->ext
.dt
->err
, code
);
9445 resolve_branch (code
->ext
.dt
->end
, code
);
9446 resolve_branch (code
->ext
.dt
->eor
, code
);
9450 resolve_transfer (code
);
9453 case EXEC_DO_CONCURRENT
:
9455 resolve_forall_iterators (code
->ext
.forall_iterator
);
9457 if (code
->expr1
!= NULL
9458 && (code
->expr1
->ts
.type
!= BT_LOGICAL
|| code
->expr1
->rank
))
9459 gfc_error ("FORALL mask clause at %L requires a scalar LOGICAL "
9460 "expression", &code
->expr1
->where
);
9463 case EXEC_OMP_ATOMIC
:
9464 case EXEC_OMP_BARRIER
:
9465 case EXEC_OMP_CRITICAL
:
9466 case EXEC_OMP_FLUSH
:
9468 case EXEC_OMP_MASTER
:
9469 case EXEC_OMP_ORDERED
:
9470 case EXEC_OMP_SECTIONS
:
9471 case EXEC_OMP_SINGLE
:
9472 case EXEC_OMP_TASKWAIT
:
9473 case EXEC_OMP_TASKYIELD
:
9474 case EXEC_OMP_WORKSHARE
:
9475 gfc_resolve_omp_directive (code
, ns
);
9478 case EXEC_OMP_PARALLEL
:
9479 case EXEC_OMP_PARALLEL_DO
:
9480 case EXEC_OMP_PARALLEL_SECTIONS
:
9481 case EXEC_OMP_PARALLEL_WORKSHARE
:
9483 omp_workshare_save
= omp_workshare_flag
;
9484 omp_workshare_flag
= 0;
9485 gfc_resolve_omp_directive (code
, ns
);
9486 omp_workshare_flag
= omp_workshare_save
;
9490 gfc_internal_error ("resolve_code(): Bad statement code");
9494 cs_base
= frame
.prev
;
9498 /* Resolve initial values and make sure they are compatible with
9502 resolve_values (gfc_symbol
*sym
)
9506 if (sym
->value
== NULL
)
9509 if (sym
->value
->expr_type
== EXPR_STRUCTURE
)
9510 t
= resolve_structure_cons (sym
->value
, 1);
9512 t
= gfc_resolve_expr (sym
->value
);
9517 gfc_check_assign_symbol (sym
, sym
->value
);
9521 /* Verify the binding labels for common blocks that are BIND(C). The label
9522 for a BIND(C) common block must be identical in all scoping units in which
9523 the common block is declared. Further, the binding label can not collide
9524 with any other global entity in the program. */
9527 resolve_bind_c_comms (gfc_symtree
*comm_block_tree
)
9529 if (comm_block_tree
->n
.common
->is_bind_c
== 1)
9531 gfc_gsymbol
*binding_label_gsym
;
9532 gfc_gsymbol
*comm_name_gsym
;
9534 /* See if a global symbol exists by the common block's name. It may
9535 be NULL if the common block is use-associated. */
9536 comm_name_gsym
= gfc_find_gsymbol (gfc_gsym_root
,
9537 comm_block_tree
->n
.common
->name
);
9538 if (comm_name_gsym
!= NULL
&& comm_name_gsym
->type
!= GSYM_COMMON
)
9539 gfc_error ("Binding label '%s' for common block '%s' at %L collides "
9540 "with the global entity '%s' at %L",
9541 comm_block_tree
->n
.common
->binding_label
,
9542 comm_block_tree
->n
.common
->name
,
9543 &(comm_block_tree
->n
.common
->where
),
9544 comm_name_gsym
->name
, &(comm_name_gsym
->where
));
9545 else if (comm_name_gsym
!= NULL
9546 && strcmp (comm_name_gsym
->name
,
9547 comm_block_tree
->n
.common
->name
) == 0)
9549 /* TODO: Need to make sure the fields of gfc_gsymbol are initialized
9551 if (comm_name_gsym
->binding_label
== NULL
)
9552 /* No binding label for common block stored yet; save this one. */
9553 comm_name_gsym
->binding_label
=
9554 comm_block_tree
->n
.common
->binding_label
;
9556 if (strcmp (comm_name_gsym
->binding_label
,
9557 comm_block_tree
->n
.common
->binding_label
) != 0)
9559 /* Common block names match but binding labels do not. */
9560 gfc_error ("Binding label '%s' for common block '%s' at %L "
9561 "does not match the binding label '%s' for common "
9563 comm_block_tree
->n
.common
->binding_label
,
9564 comm_block_tree
->n
.common
->name
,
9565 &(comm_block_tree
->n
.common
->where
),
9566 comm_name_gsym
->binding_label
,
9567 comm_name_gsym
->name
,
9568 &(comm_name_gsym
->where
));
9573 /* There is no binding label (NAME="") so we have nothing further to
9574 check and nothing to add as a global symbol for the label. */
9575 if (comm_block_tree
->n
.common
->binding_label
[0] == '\0' )
9578 binding_label_gsym
=
9579 gfc_find_gsymbol (gfc_gsym_root
,
9580 comm_block_tree
->n
.common
->binding_label
);
9581 if (binding_label_gsym
== NULL
)
9583 /* Need to make a global symbol for the binding label to prevent
9584 it from colliding with another. */
9585 binding_label_gsym
=
9586 gfc_get_gsymbol (comm_block_tree
->n
.common
->binding_label
);
9587 binding_label_gsym
->sym_name
= comm_block_tree
->n
.common
->name
;
9588 binding_label_gsym
->type
= GSYM_COMMON
;
9592 /* If comm_name_gsym is NULL, the name common block is use
9593 associated and the name could be colliding. */
9594 if (binding_label_gsym
->type
!= GSYM_COMMON
)
9595 gfc_error ("Binding label '%s' for common block '%s' at %L "
9596 "collides with the global entity '%s' at %L",
9597 comm_block_tree
->n
.common
->binding_label
,
9598 comm_block_tree
->n
.common
->name
,
9599 &(comm_block_tree
->n
.common
->where
),
9600 binding_label_gsym
->name
,
9601 &(binding_label_gsym
->where
));
9602 else if (comm_name_gsym
!= NULL
9603 && (strcmp (binding_label_gsym
->name
,
9604 comm_name_gsym
->binding_label
) != 0)
9605 && (strcmp (binding_label_gsym
->sym_name
,
9606 comm_name_gsym
->name
) != 0))
9607 gfc_error ("Binding label '%s' for common block '%s' at %L "
9608 "collides with global entity '%s' at %L",
9609 binding_label_gsym
->name
, binding_label_gsym
->sym_name
,
9610 &(comm_block_tree
->n
.common
->where
),
9611 comm_name_gsym
->name
, &(comm_name_gsym
->where
));
9619 /* Verify any BIND(C) derived types in the namespace so we can report errors
9620 for them once, rather than for each variable declared of that type. */
9623 resolve_bind_c_derived_types (gfc_symbol
*derived_sym
)
9625 if (derived_sym
!= NULL
&& derived_sym
->attr
.flavor
== FL_DERIVED
9626 && derived_sym
->attr
.is_bind_c
== 1)
9627 verify_bind_c_derived_type (derived_sym
);
9633 /* Verify that any binding labels used in a given namespace do not collide
9634 with the names or binding labels of any global symbols. */
9637 gfc_verify_binding_labels (gfc_symbol
*sym
)
9641 if (sym
!= NULL
&& sym
->attr
.is_bind_c
&& sym
->attr
.is_iso_c
== 0
9642 && sym
->attr
.flavor
!= FL_DERIVED
&& sym
->binding_label
[0] != '\0')
9644 gfc_gsymbol
*bind_c_sym
;
9646 bind_c_sym
= gfc_find_gsymbol (gfc_gsym_root
, sym
->binding_label
);
9647 if (bind_c_sym
!= NULL
9648 && strcmp (bind_c_sym
->name
, sym
->binding_label
) == 0)
9650 if (sym
->attr
.if_source
== IFSRC_DECL
9651 && (bind_c_sym
->type
!= GSYM_SUBROUTINE
9652 && bind_c_sym
->type
!= GSYM_FUNCTION
)
9653 && ((sym
->attr
.contained
== 1
9654 && strcmp (bind_c_sym
->sym_name
, sym
->name
) != 0)
9655 || (sym
->attr
.use_assoc
== 1
9656 && (strcmp (bind_c_sym
->mod_name
, sym
->module
) != 0))))
9658 /* Make sure global procedures don't collide with anything. */
9659 gfc_error ("Binding label '%s' at %L collides with the global "
9660 "entity '%s' at %L", sym
->binding_label
,
9661 &(sym
->declared_at
), bind_c_sym
->name
,
9662 &(bind_c_sym
->where
));
9665 else if (sym
->attr
.contained
== 0
9666 && (sym
->attr
.if_source
== IFSRC_IFBODY
9667 && sym
->attr
.flavor
== FL_PROCEDURE
)
9668 && (bind_c_sym
->sym_name
!= NULL
9669 && strcmp (bind_c_sym
->sym_name
, sym
->name
) != 0))
9671 /* Make sure procedures in interface bodies don't collide. */
9672 gfc_error ("Binding label '%s' in interface body at %L collides "
9673 "with the global entity '%s' at %L",
9675 &(sym
->declared_at
), bind_c_sym
->name
,
9676 &(bind_c_sym
->where
));
9679 else if (sym
->attr
.contained
== 0
9680 && sym
->attr
.if_source
== IFSRC_UNKNOWN
)
9681 if ((sym
->attr
.use_assoc
&& bind_c_sym
->mod_name
9682 && strcmp (bind_c_sym
->mod_name
, sym
->module
) != 0)
9683 || sym
->attr
.use_assoc
== 0)
9685 gfc_error ("Binding label '%s' at %L collides with global "
9686 "entity '%s' at %L", sym
->binding_label
,
9687 &(sym
->declared_at
), bind_c_sym
->name
,
9688 &(bind_c_sym
->where
));
9693 /* Clear the binding label to prevent checking multiple times. */
9694 sym
->binding_label
[0] = '\0';
9696 else if (bind_c_sym
== NULL
)
9698 bind_c_sym
= gfc_get_gsymbol (sym
->binding_label
);
9699 bind_c_sym
->where
= sym
->declared_at
;
9700 bind_c_sym
->sym_name
= sym
->name
;
9702 if (sym
->attr
.use_assoc
== 1)
9703 bind_c_sym
->mod_name
= sym
->module
;
9705 if (sym
->ns
->proc_name
!= NULL
)
9706 bind_c_sym
->mod_name
= sym
->ns
->proc_name
->name
;
9708 if (sym
->attr
.contained
== 0)
9710 if (sym
->attr
.subroutine
)
9711 bind_c_sym
->type
= GSYM_SUBROUTINE
;
9712 else if (sym
->attr
.function
)
9713 bind_c_sym
->type
= GSYM_FUNCTION
;
9721 /* Resolve an index expression. */
9724 resolve_index_expr (gfc_expr
*e
)
9726 if (gfc_resolve_expr (e
) == FAILURE
)
9729 if (gfc_simplify_expr (e
, 0) == FAILURE
)
9732 if (gfc_specification_expr (e
) == FAILURE
)
9739 /* Resolve a charlen structure. */
9742 resolve_charlen (gfc_charlen
*cl
)
9751 specification_expr
= 1;
9753 if (resolve_index_expr (cl
->length
) == FAILURE
)
9755 specification_expr
= 0;
9759 /* "If the character length parameter value evaluates to a negative
9760 value, the length of character entities declared is zero." */
9761 if (cl
->length
&& !gfc_extract_int (cl
->length
, &i
) && i
< 0)
9763 if (gfc_option
.warn_surprising
)
9764 gfc_warning_now ("CHARACTER variable at %L has negative length %d,"
9765 " the length has been set to zero",
9766 &cl
->length
->where
, i
);
9767 gfc_replace_expr (cl
->length
,
9768 gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 0));
9771 /* Check that the character length is not too large. */
9772 k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
9773 if (cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
9774 && cl
->length
->ts
.type
== BT_INTEGER
9775 && mpz_cmp (cl
->length
->value
.integer
, gfc_integer_kinds
[k
].huge
) > 0)
9777 gfc_error ("String length at %L is too large", &cl
->length
->where
);
9785 /* Test for non-constant shape arrays. */
9788 is_non_constant_shape_array (gfc_symbol
*sym
)
9794 not_constant
= false;
9795 if (sym
->as
!= NULL
)
9797 /* Unfortunately, !gfc_is_compile_time_shape hits a legal case that
9798 has not been simplified; parameter array references. Do the
9799 simplification now. */
9800 for (i
= 0; i
< sym
->as
->rank
+ sym
->as
->corank
; i
++)
9802 e
= sym
->as
->lower
[i
];
9803 if (e
&& (resolve_index_expr (e
) == FAILURE
9804 || !gfc_is_constant_expr (e
)))
9805 not_constant
= true;
9806 e
= sym
->as
->upper
[i
];
9807 if (e
&& (resolve_index_expr (e
) == FAILURE
9808 || !gfc_is_constant_expr (e
)))
9809 not_constant
= true;
9812 return not_constant
;
9815 /* Given a symbol and an initialization expression, add code to initialize
9816 the symbol to the function entry. */
9818 build_init_assign (gfc_symbol
*sym
, gfc_expr
*init
)
9822 gfc_namespace
*ns
= sym
->ns
;
9824 /* Search for the function namespace if this is a contained
9825 function without an explicit result. */
9826 if (sym
->attr
.function
&& sym
== sym
->result
9827 && sym
->name
!= sym
->ns
->proc_name
->name
)
9830 for (;ns
; ns
= ns
->sibling
)
9831 if (strcmp (ns
->proc_name
->name
, sym
->name
) == 0)
9837 gfc_free_expr (init
);
9841 /* Build an l-value expression for the result. */
9842 lval
= gfc_lval_expr_from_sym (sym
);
9844 /* Add the code at scope entry. */
9845 init_st
= gfc_get_code ();
9846 init_st
->next
= ns
->code
;
9849 /* Assign the default initializer to the l-value. */
9850 init_st
->loc
= sym
->declared_at
;
9851 init_st
->op
= EXEC_INIT_ASSIGN
;
9852 init_st
->expr1
= lval
;
9853 init_st
->expr2
= init
;
9856 /* Assign the default initializer to a derived type variable or result. */
9859 apply_default_init (gfc_symbol
*sym
)
9861 gfc_expr
*init
= NULL
;
9863 if (sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
9866 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
)
9867 init
= gfc_default_initializer (&sym
->ts
);
9869 if (init
== NULL
&& sym
->ts
.type
!= BT_CLASS
)
9872 build_init_assign (sym
, init
);
9873 sym
->attr
.referenced
= 1;
9876 /* Build an initializer for a local integer, real, complex, logical, or
9877 character variable, based on the command line flags finit-local-zero,
9878 finit-integer=, finit-real=, finit-logical=, and finit-runtime. Returns
9879 null if the symbol should not have a default initialization. */
9881 build_default_init_expr (gfc_symbol
*sym
)
9884 gfc_expr
*init_expr
;
9887 /* These symbols should never have a default initialization. */
9888 if ((sym
->attr
.dimension
&& !gfc_is_compile_time_shape (sym
->as
))
9889 || sym
->attr
.external
9891 || sym
->attr
.pointer
9892 || sym
->attr
.in_equivalence
9893 || sym
->attr
.in_common
9896 || sym
->attr
.cray_pointee
9897 || sym
->attr
.cray_pointer
)
9900 /* Now we'll try to build an initializer expression. */
9901 init_expr
= gfc_get_constant_expr (sym
->ts
.type
, sym
->ts
.kind
,
9904 /* We will only initialize integers, reals, complex, logicals, and
9905 characters, and only if the corresponding command-line flags
9906 were set. Otherwise, we free init_expr and return null. */
9907 switch (sym
->ts
.type
)
9910 if (gfc_option
.flag_init_integer
!= GFC_INIT_INTEGER_OFF
)
9911 mpz_set_si (init_expr
->value
.integer
,
9912 gfc_option
.flag_init_integer_value
);
9915 gfc_free_expr (init_expr
);
9921 switch (gfc_option
.flag_init_real
)
9923 case GFC_INIT_REAL_SNAN
:
9924 init_expr
->is_snan
= 1;
9926 case GFC_INIT_REAL_NAN
:
9927 mpfr_set_nan (init_expr
->value
.real
);
9930 case GFC_INIT_REAL_INF
:
9931 mpfr_set_inf (init_expr
->value
.real
, 1);
9934 case GFC_INIT_REAL_NEG_INF
:
9935 mpfr_set_inf (init_expr
->value
.real
, -1);
9938 case GFC_INIT_REAL_ZERO
:
9939 mpfr_set_ui (init_expr
->value
.real
, 0.0, GFC_RND_MODE
);
9943 gfc_free_expr (init_expr
);
9950 switch (gfc_option
.flag_init_real
)
9952 case GFC_INIT_REAL_SNAN
:
9953 init_expr
->is_snan
= 1;
9955 case GFC_INIT_REAL_NAN
:
9956 mpfr_set_nan (mpc_realref (init_expr
->value
.complex));
9957 mpfr_set_nan (mpc_imagref (init_expr
->value
.complex));
9960 case GFC_INIT_REAL_INF
:
9961 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), 1);
9962 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), 1);
9965 case GFC_INIT_REAL_NEG_INF
:
9966 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), -1);
9967 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), -1);
9970 case GFC_INIT_REAL_ZERO
:
9971 mpc_set_ui (init_expr
->value
.complex, 0, GFC_MPC_RND_MODE
);
9975 gfc_free_expr (init_expr
);
9982 if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_FALSE
)
9983 init_expr
->value
.logical
= 0;
9984 else if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_TRUE
)
9985 init_expr
->value
.logical
= 1;
9988 gfc_free_expr (init_expr
);
9994 /* For characters, the length must be constant in order to
9995 create a default initializer. */
9996 if (gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
9997 && sym
->ts
.u
.cl
->length
9998 && sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
10000 char_len
= mpz_get_si (sym
->ts
.u
.cl
->length
->value
.integer
);
10001 init_expr
->value
.character
.length
= char_len
;
10002 init_expr
->value
.character
.string
= gfc_get_wide_string (char_len
+1);
10003 for (i
= 0; i
< char_len
; i
++)
10004 init_expr
->value
.character
.string
[i
]
10005 = (unsigned char) gfc_option
.flag_init_character_value
;
10009 gfc_free_expr (init_expr
);
10015 gfc_free_expr (init_expr
);
10021 /* Add an initialization expression to a local variable. */
10023 apply_default_init_local (gfc_symbol
*sym
)
10025 gfc_expr
*init
= NULL
;
10027 /* The symbol should be a variable or a function return value. */
10028 if ((sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
10029 || (sym
->attr
.function
&& sym
->result
!= sym
))
10032 /* Try to build the initializer expression. If we can't initialize
10033 this symbol, then init will be NULL. */
10034 init
= build_default_init_expr (sym
);
10038 /* For saved variables, we don't want to add an initializer at
10039 function entry, so we just add a static initializer. */
10040 if (sym
->attr
.save
|| sym
->ns
->save_all
10041 || gfc_option
.flag_max_stack_var_size
== 0)
10043 /* Don't clobber an existing initializer! */
10044 gcc_assert (sym
->value
== NULL
);
10049 build_init_assign (sym
, init
);
10053 /* Resolution of common features of flavors variable and procedure. */
10056 resolve_fl_var_and_proc (gfc_symbol
*sym
, int mp_flag
)
10058 /* Avoid double diagnostics for function result symbols. */
10059 if ((sym
->result
|| sym
->attr
.result
) && !sym
->attr
.dummy
10060 && (sym
->ns
!= gfc_current_ns
))
10063 /* Constraints on deferred shape variable. */
10064 if (sym
->as
== NULL
|| sym
->as
->type
!= AS_DEFERRED
)
10066 if (sym
->attr
.allocatable
)
10068 if (sym
->attr
.dimension
)
10070 gfc_error ("Allocatable array '%s' at %L must have "
10071 "a deferred shape", sym
->name
, &sym
->declared_at
);
10074 else if (gfc_notify_std (GFC_STD_F2003
, "Scalar object '%s' at %L "
10075 "may not be ALLOCATABLE", sym
->name
,
10076 &sym
->declared_at
) == FAILURE
)
10080 if (sym
->attr
.pointer
&& sym
->attr
.dimension
)
10082 gfc_error ("Array pointer '%s' at %L must have a deferred shape",
10083 sym
->name
, &sym
->declared_at
);
10089 if (!mp_flag
&& !sym
->attr
.allocatable
&& !sym
->attr
.pointer
10090 && sym
->ts
.type
!= BT_CLASS
&& !sym
->assoc
)
10092 gfc_error ("Array '%s' at %L cannot have a deferred shape",
10093 sym
->name
, &sym
->declared_at
);
10098 /* Constraints on polymorphic variables. */
10099 if (sym
->ts
.type
== BT_CLASS
&& !(sym
->result
&& sym
->result
!= sym
))
10102 if (sym
->attr
.class_ok
10103 && !gfc_type_is_extensible (CLASS_DATA (sym
)->ts
.u
.derived
))
10105 gfc_error ("Type '%s' of CLASS variable '%s' at %L is not extensible",
10106 CLASS_DATA (sym
)->ts
.u
.derived
->name
, sym
->name
,
10107 &sym
->declared_at
);
10112 /* Assume that use associated symbols were checked in the module ns.
10113 Class-variables that are associate-names are also something special
10114 and excepted from the test. */
10115 if (!sym
->attr
.class_ok
&& !sym
->attr
.use_assoc
&& !sym
->assoc
)
10117 gfc_error ("CLASS variable '%s' at %L must be dummy, allocatable "
10118 "or pointer", sym
->name
, &sym
->declared_at
);
10127 /* Additional checks for symbols with flavor variable and derived
10128 type. To be called from resolve_fl_variable. */
10131 resolve_fl_variable_derived (gfc_symbol
*sym
, int no_init_flag
)
10133 gcc_assert (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
);
10135 /* Check to see if a derived type is blocked from being host
10136 associated by the presence of another class I symbol in the same
10137 namespace. 14.6.1.3 of the standard and the discussion on
10138 comp.lang.fortran. */
10139 if (sym
->ns
!= sym
->ts
.u
.derived
->ns
10140 && sym
->ns
->proc_name
->attr
.if_source
!= IFSRC_IFBODY
)
10143 gfc_find_symbol (sym
->ts
.u
.derived
->name
, sym
->ns
, 0, &s
);
10144 if (s
&& s
->attr
.flavor
!= FL_DERIVED
)
10146 gfc_error ("The type '%s' cannot be host associated at %L "
10147 "because it is blocked by an incompatible object "
10148 "of the same name declared at %L",
10149 sym
->ts
.u
.derived
->name
, &sym
->declared_at
,
10155 /* 4th constraint in section 11.3: "If an object of a type for which
10156 component-initialization is specified (R429) appears in the
10157 specification-part of a module and does not have the ALLOCATABLE
10158 or POINTER attribute, the object shall have the SAVE attribute."
10160 The check for initializers is performed with
10161 gfc_has_default_initializer because gfc_default_initializer generates
10162 a hidden default for allocatable components. */
10163 if (!(sym
->value
|| no_init_flag
) && sym
->ns
->proc_name
10164 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
10165 && !sym
->ns
->save_all
&& !sym
->attr
.save
10166 && !sym
->attr
.pointer
&& !sym
->attr
.allocatable
10167 && gfc_has_default_initializer (sym
->ts
.u
.derived
)
10168 && gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: Implied SAVE for "
10169 "module variable '%s' at %L, needed due to "
10170 "the default initialization", sym
->name
,
10171 &sym
->declared_at
) == FAILURE
)
10174 /* Assign default initializer. */
10175 if (!(sym
->value
|| sym
->attr
.pointer
|| sym
->attr
.allocatable
)
10176 && (!no_init_flag
|| sym
->attr
.intent
== INTENT_OUT
))
10178 sym
->value
= gfc_default_initializer (&sym
->ts
);
10185 /* Resolve symbols with flavor variable. */
10188 resolve_fl_variable (gfc_symbol
*sym
, int mp_flag
)
10190 int no_init_flag
, automatic_flag
;
10192 const char *auto_save_msg
;
10194 auto_save_msg
= "Automatic object '%s' at %L cannot have the "
10197 if (resolve_fl_var_and_proc (sym
, mp_flag
) == FAILURE
)
10200 /* Set this flag to check that variables are parameters of all entries.
10201 This check is effected by the call to gfc_resolve_expr through
10202 is_non_constant_shape_array. */
10203 specification_expr
= 1;
10205 if (sym
->ns
->proc_name
10206 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
10207 || sym
->ns
->proc_name
->attr
.is_main_program
)
10208 && !sym
->attr
.use_assoc
10209 && !sym
->attr
.allocatable
10210 && !sym
->attr
.pointer
10211 && is_non_constant_shape_array (sym
))
10213 /* The shape of a main program or module array needs to be
10215 gfc_error ("The module or main program array '%s' at %L must "
10216 "have constant shape", sym
->name
, &sym
->declared_at
);
10217 specification_expr
= 0;
10221 /* Constraints on deferred type parameter. */
10222 if (sym
->ts
.deferred
&& !(sym
->attr
.pointer
|| sym
->attr
.allocatable
))
10224 gfc_error ("Entity '%s' at %L has a deferred type parameter and "
10225 "requires either the pointer or allocatable attribute",
10226 sym
->name
, &sym
->declared_at
);
10230 if (sym
->ts
.type
== BT_CHARACTER
)
10232 /* Make sure that character string variables with assumed length are
10233 dummy arguments. */
10234 e
= sym
->ts
.u
.cl
->length
;
10235 if (e
== NULL
&& !sym
->attr
.dummy
&& !sym
->attr
.result
10236 && !sym
->ts
.deferred
)
10238 gfc_error ("Entity with assumed character length at %L must be a "
10239 "dummy argument or a PARAMETER", &sym
->declared_at
);
10243 if (e
&& sym
->attr
.save
== SAVE_EXPLICIT
&& !gfc_is_constant_expr (e
))
10245 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
10249 if (!gfc_is_constant_expr (e
)
10250 && !(e
->expr_type
== EXPR_VARIABLE
10251 && e
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
))
10253 if (!sym
->attr
.use_assoc
&& sym
->ns
->proc_name
10254 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
10255 || sym
->ns
->proc_name
->attr
.is_main_program
))
10257 gfc_error ("'%s' at %L must have constant character length "
10258 "in this context", sym
->name
, &sym
->declared_at
);
10261 if (sym
->attr
.in_common
)
10263 gfc_error ("COMMON variable '%s' at %L must have constant "
10264 "character length", sym
->name
, &sym
->declared_at
);
10270 if (sym
->value
== NULL
&& sym
->attr
.referenced
)
10271 apply_default_init_local (sym
); /* Try to apply a default initialization. */
10273 /* Determine if the symbol may not have an initializer. */
10274 no_init_flag
= automatic_flag
= 0;
10275 if (sym
->attr
.allocatable
|| sym
->attr
.external
|| sym
->attr
.dummy
10276 || sym
->attr
.intrinsic
|| sym
->attr
.result
)
10278 else if ((sym
->attr
.dimension
|| sym
->attr
.codimension
) && !sym
->attr
.pointer
10279 && is_non_constant_shape_array (sym
))
10281 no_init_flag
= automatic_flag
= 1;
10283 /* Also, they must not have the SAVE attribute.
10284 SAVE_IMPLICIT is checked below. */
10285 if (sym
->as
&& sym
->attr
.codimension
)
10287 int corank
= sym
->as
->corank
;
10288 sym
->as
->corank
= 0;
10289 no_init_flag
= automatic_flag
= is_non_constant_shape_array (sym
);
10290 sym
->as
->corank
= corank
;
10292 if (automatic_flag
&& sym
->attr
.save
== SAVE_EXPLICIT
)
10294 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
10299 /* Ensure that any initializer is simplified. */
10301 gfc_simplify_expr (sym
->value
, 1);
10303 /* Reject illegal initializers. */
10304 if (!sym
->mark
&& sym
->value
)
10306 if (sym
->attr
.allocatable
|| (sym
->ts
.type
== BT_CLASS
10307 && CLASS_DATA (sym
)->attr
.allocatable
))
10308 gfc_error ("Allocatable '%s' at %L cannot have an initializer",
10309 sym
->name
, &sym
->declared_at
);
10310 else if (sym
->attr
.external
)
10311 gfc_error ("External '%s' at %L cannot have an initializer",
10312 sym
->name
, &sym
->declared_at
);
10313 else if (sym
->attr
.dummy
10314 && !(sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.intent
== INTENT_OUT
))
10315 gfc_error ("Dummy '%s' at %L cannot have an initializer",
10316 sym
->name
, &sym
->declared_at
);
10317 else if (sym
->attr
.intrinsic
)
10318 gfc_error ("Intrinsic '%s' at %L cannot have an initializer",
10319 sym
->name
, &sym
->declared_at
);
10320 else if (sym
->attr
.result
)
10321 gfc_error ("Function result '%s' at %L cannot have an initializer",
10322 sym
->name
, &sym
->declared_at
);
10323 else if (automatic_flag
)
10324 gfc_error ("Automatic array '%s' at %L cannot have an initializer",
10325 sym
->name
, &sym
->declared_at
);
10327 goto no_init_error
;
10332 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
10333 return resolve_fl_variable_derived (sym
, no_init_flag
);
10339 /* Resolve a procedure. */
10342 resolve_fl_procedure (gfc_symbol
*sym
, int mp_flag
)
10344 gfc_formal_arglist
*arg
;
10346 if (sym
->attr
.function
10347 && resolve_fl_var_and_proc (sym
, mp_flag
) == FAILURE
)
10350 if (sym
->ts
.type
== BT_CHARACTER
)
10352 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
10354 if (cl
&& cl
->length
&& gfc_is_constant_expr (cl
->length
)
10355 && resolve_charlen (cl
) == FAILURE
)
10358 if ((!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
10359 && sym
->attr
.proc
== PROC_ST_FUNCTION
)
10361 gfc_error ("Character-valued statement function '%s' at %L must "
10362 "have constant length", sym
->name
, &sym
->declared_at
);
10367 /* Ensure that derived type for are not of a private type. Internal
10368 module procedures are excluded by 2.2.3.3 - i.e., they are not
10369 externally accessible and can access all the objects accessible in
10371 if (!(sym
->ns
->parent
10372 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
10373 && gfc_check_symbol_access (sym
))
10375 gfc_interface
*iface
;
10377 for (arg
= sym
->formal
; arg
; arg
= arg
->next
)
10380 && arg
->sym
->ts
.type
== BT_DERIVED
10381 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
10382 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
10383 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' is of a "
10384 "PRIVATE type and cannot be a dummy argument"
10385 " of '%s', which is PUBLIC at %L",
10386 arg
->sym
->name
, sym
->name
, &sym
->declared_at
)
10389 /* Stop this message from recurring. */
10390 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
10395 /* PUBLIC interfaces may expose PRIVATE procedures that take types
10396 PRIVATE to the containing module. */
10397 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
10399 for (arg
= iface
->sym
->formal
; arg
; arg
= arg
->next
)
10402 && arg
->sym
->ts
.type
== BT_DERIVED
10403 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
10404 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
10405 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: Procedure "
10406 "'%s' in PUBLIC interface '%s' at %L "
10407 "takes dummy arguments of '%s' which is "
10408 "PRIVATE", iface
->sym
->name
, sym
->name
,
10409 &iface
->sym
->declared_at
,
10410 gfc_typename (&arg
->sym
->ts
)) == FAILURE
)
10412 /* Stop this message from recurring. */
10413 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
10419 /* PUBLIC interfaces may expose PRIVATE procedures that take types
10420 PRIVATE to the containing module. */
10421 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
10423 for (arg
= iface
->sym
->formal
; arg
; arg
= arg
->next
)
10426 && arg
->sym
->ts
.type
== BT_DERIVED
10427 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
10428 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
10429 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: Procedure "
10430 "'%s' in PUBLIC interface '%s' at %L "
10431 "takes dummy arguments of '%s' which is "
10432 "PRIVATE", iface
->sym
->name
, sym
->name
,
10433 &iface
->sym
->declared_at
,
10434 gfc_typename (&arg
->sym
->ts
)) == FAILURE
)
10436 /* Stop this message from recurring. */
10437 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
10444 if (sym
->attr
.function
&& sym
->value
&& sym
->attr
.proc
!= PROC_ST_FUNCTION
10445 && !sym
->attr
.proc_pointer
)
10447 gfc_error ("Function '%s' at %L cannot have an initializer",
10448 sym
->name
, &sym
->declared_at
);
10452 /* An external symbol may not have an initializer because it is taken to be
10453 a procedure. Exception: Procedure Pointers. */
10454 if (sym
->attr
.external
&& sym
->value
&& !sym
->attr
.proc_pointer
)
10456 gfc_error ("External object '%s' at %L may not have an initializer",
10457 sym
->name
, &sym
->declared_at
);
10461 /* An elemental function is required to return a scalar 12.7.1 */
10462 if (sym
->attr
.elemental
&& sym
->attr
.function
&& sym
->as
)
10464 gfc_error ("ELEMENTAL function '%s' at %L must have a scalar "
10465 "result", sym
->name
, &sym
->declared_at
);
10466 /* Reset so that the error only occurs once. */
10467 sym
->attr
.elemental
= 0;
10471 if (sym
->attr
.proc
== PROC_ST_FUNCTION
10472 && (sym
->attr
.allocatable
|| sym
->attr
.pointer
))
10474 gfc_error ("Statement function '%s' at %L may not have pointer or "
10475 "allocatable attribute", sym
->name
, &sym
->declared_at
);
10479 /* 5.1.1.5 of the Standard: A function name declared with an asterisk
10480 char-len-param shall not be array-valued, pointer-valued, recursive
10481 or pure. ....snip... A character value of * may only be used in the
10482 following ways: (i) Dummy arg of procedure - dummy associates with
10483 actual length; (ii) To declare a named constant; or (iii) External
10484 function - but length must be declared in calling scoping unit. */
10485 if (sym
->attr
.function
10486 && sym
->ts
.type
== BT_CHARACTER
10487 && sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
== NULL
)
10489 if ((sym
->as
&& sym
->as
->rank
) || (sym
->attr
.pointer
)
10490 || (sym
->attr
.recursive
) || (sym
->attr
.pure
))
10492 if (sym
->as
&& sym
->as
->rank
)
10493 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
10494 "array-valued", sym
->name
, &sym
->declared_at
);
10496 if (sym
->attr
.pointer
)
10497 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
10498 "pointer-valued", sym
->name
, &sym
->declared_at
);
10500 if (sym
->attr
.pure
)
10501 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
10502 "pure", sym
->name
, &sym
->declared_at
);
10504 if (sym
->attr
.recursive
)
10505 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
10506 "recursive", sym
->name
, &sym
->declared_at
);
10511 /* Appendix B.2 of the standard. Contained functions give an
10512 error anyway. Fixed-form is likely to be F77/legacy. Deferred
10513 character length is an F2003 feature. */
10514 if (!sym
->attr
.contained
10515 && gfc_current_form
!= FORM_FIXED
10516 && !sym
->ts
.deferred
)
10517 gfc_notify_std (GFC_STD_F95_OBS
, "Obsolescent feature: "
10518 "CHARACTER(*) function '%s' at %L",
10519 sym
->name
, &sym
->declared_at
);
10522 if (sym
->attr
.is_bind_c
&& sym
->attr
.is_c_interop
!= 1)
10524 gfc_formal_arglist
*curr_arg
;
10525 int has_non_interop_arg
= 0;
10527 if (verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
10528 sym
->common_block
) == FAILURE
)
10530 /* Clear these to prevent looking at them again if there was an
10532 sym
->attr
.is_bind_c
= 0;
10533 sym
->attr
.is_c_interop
= 0;
10534 sym
->ts
.is_c_interop
= 0;
10538 /* So far, no errors have been found. */
10539 sym
->attr
.is_c_interop
= 1;
10540 sym
->ts
.is_c_interop
= 1;
10543 curr_arg
= sym
->formal
;
10544 while (curr_arg
!= NULL
)
10546 /* Skip implicitly typed dummy args here. */
10547 if (curr_arg
->sym
->attr
.implicit_type
== 0)
10548 if (gfc_verify_c_interop_param (curr_arg
->sym
) == FAILURE
)
10549 /* If something is found to fail, record the fact so we
10550 can mark the symbol for the procedure as not being
10551 BIND(C) to try and prevent multiple errors being
10553 has_non_interop_arg
= 1;
10555 curr_arg
= curr_arg
->next
;
10558 /* See if any of the arguments were not interoperable and if so, clear
10559 the procedure symbol to prevent duplicate error messages. */
10560 if (has_non_interop_arg
!= 0)
10562 sym
->attr
.is_c_interop
= 0;
10563 sym
->ts
.is_c_interop
= 0;
10564 sym
->attr
.is_bind_c
= 0;
10568 if (!sym
->attr
.proc_pointer
)
10570 if (sym
->attr
.save
== SAVE_EXPLICIT
)
10572 gfc_error ("PROCEDURE attribute conflicts with SAVE attribute "
10573 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
10576 if (sym
->attr
.intent
)
10578 gfc_error ("PROCEDURE attribute conflicts with INTENT attribute "
10579 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
10582 if (sym
->attr
.subroutine
&& sym
->attr
.result
)
10584 gfc_error ("PROCEDURE attribute conflicts with RESULT attribute "
10585 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
10588 if (sym
->attr
.external
&& sym
->attr
.function
10589 && ((sym
->attr
.if_source
== IFSRC_DECL
&& !sym
->attr
.procedure
)
10590 || sym
->attr
.contained
))
10592 gfc_error ("EXTERNAL attribute conflicts with FUNCTION attribute "
10593 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
10596 if (strcmp ("ppr@", sym
->name
) == 0)
10598 gfc_error ("Procedure pointer result '%s' at %L "
10599 "is missing the pointer attribute",
10600 sym
->ns
->proc_name
->name
, &sym
->declared_at
);
10609 /* Resolve a list of finalizer procedures. That is, after they have hopefully
10610 been defined and we now know their defined arguments, check that they fulfill
10611 the requirements of the standard for procedures used as finalizers. */
10614 gfc_resolve_finalizers (gfc_symbol
* derived
)
10616 gfc_finalizer
* list
;
10617 gfc_finalizer
** prev_link
; /* For removing wrong entries from the list. */
10618 gfc_try result
= SUCCESS
;
10619 bool seen_scalar
= false;
10621 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->finalizers
)
10624 /* Walk over the list of finalizer-procedures, check them, and if any one
10625 does not fit in with the standard's definition, print an error and remove
10626 it from the list. */
10627 prev_link
= &derived
->f2k_derived
->finalizers
;
10628 for (list
= derived
->f2k_derived
->finalizers
; list
; list
= *prev_link
)
10634 /* Skip this finalizer if we already resolved it. */
10635 if (list
->proc_tree
)
10637 prev_link
= &(list
->next
);
10641 /* Check this exists and is a SUBROUTINE. */
10642 if (!list
->proc_sym
->attr
.subroutine
)
10644 gfc_error ("FINAL procedure '%s' at %L is not a SUBROUTINE",
10645 list
->proc_sym
->name
, &list
->where
);
10649 /* We should have exactly one argument. */
10650 if (!list
->proc_sym
->formal
|| list
->proc_sym
->formal
->next
)
10652 gfc_error ("FINAL procedure at %L must have exactly one argument",
10656 arg
= list
->proc_sym
->formal
->sym
;
10658 /* This argument must be of our type. */
10659 if (arg
->ts
.type
!= BT_DERIVED
|| arg
->ts
.u
.derived
!= derived
)
10661 gfc_error ("Argument of FINAL procedure at %L must be of type '%s'",
10662 &arg
->declared_at
, derived
->name
);
10666 /* It must neither be a pointer nor allocatable nor optional. */
10667 if (arg
->attr
.pointer
)
10669 gfc_error ("Argument of FINAL procedure at %L must not be a POINTER",
10670 &arg
->declared_at
);
10673 if (arg
->attr
.allocatable
)
10675 gfc_error ("Argument of FINAL procedure at %L must not be"
10676 " ALLOCATABLE", &arg
->declared_at
);
10679 if (arg
->attr
.optional
)
10681 gfc_error ("Argument of FINAL procedure at %L must not be OPTIONAL",
10682 &arg
->declared_at
);
10686 /* It must not be INTENT(OUT). */
10687 if (arg
->attr
.intent
== INTENT_OUT
)
10689 gfc_error ("Argument of FINAL procedure at %L must not be"
10690 " INTENT(OUT)", &arg
->declared_at
);
10694 /* Warn if the procedure is non-scalar and not assumed shape. */
10695 if (gfc_option
.warn_surprising
&& arg
->as
&& arg
->as
->rank
> 0
10696 && arg
->as
->type
!= AS_ASSUMED_SHAPE
)
10697 gfc_warning ("Non-scalar FINAL procedure at %L should have assumed"
10698 " shape argument", &arg
->declared_at
);
10700 /* Check that it does not match in kind and rank with a FINAL procedure
10701 defined earlier. To really loop over the *earlier* declarations,
10702 we need to walk the tail of the list as new ones were pushed at the
10704 /* TODO: Handle kind parameters once they are implemented. */
10705 my_rank
= (arg
->as
? arg
->as
->rank
: 0);
10706 for (i
= list
->next
; i
; i
= i
->next
)
10708 /* Argument list might be empty; that is an error signalled earlier,
10709 but we nevertheless continued resolving. */
10710 if (i
->proc_sym
->formal
)
10712 gfc_symbol
* i_arg
= i
->proc_sym
->formal
->sym
;
10713 const int i_rank
= (i_arg
->as
? i_arg
->as
->rank
: 0);
10714 if (i_rank
== my_rank
)
10716 gfc_error ("FINAL procedure '%s' declared at %L has the same"
10717 " rank (%d) as '%s'",
10718 list
->proc_sym
->name
, &list
->where
, my_rank
,
10719 i
->proc_sym
->name
);
10725 /* Is this the/a scalar finalizer procedure? */
10726 if (!arg
->as
|| arg
->as
->rank
== 0)
10727 seen_scalar
= true;
10729 /* Find the symtree for this procedure. */
10730 gcc_assert (!list
->proc_tree
);
10731 list
->proc_tree
= gfc_find_sym_in_symtree (list
->proc_sym
);
10733 prev_link
= &list
->next
;
10736 /* Remove wrong nodes immediately from the list so we don't risk any
10737 troubles in the future when they might fail later expectations. */
10741 *prev_link
= list
->next
;
10742 gfc_free_finalizer (i
);
10745 /* Warn if we haven't seen a scalar finalizer procedure (but we know there
10746 were nodes in the list, must have been for arrays. It is surely a good
10747 idea to have a scalar version there if there's something to finalize. */
10748 if (gfc_option
.warn_surprising
&& result
== SUCCESS
&& !seen_scalar
)
10749 gfc_warning ("Only array FINAL procedures declared for derived type '%s'"
10750 " defined at %L, suggest also scalar one",
10751 derived
->name
, &derived
->declared_at
);
10753 /* TODO: Remove this error when finalization is finished. */
10754 gfc_error ("Finalization at %L is not yet implemented",
10755 &derived
->declared_at
);
10761 /* Check if two GENERIC targets are ambiguous and emit an error is they are. */
10764 check_generic_tbp_ambiguity (gfc_tbp_generic
* t1
, gfc_tbp_generic
* t2
,
10765 const char* generic_name
, locus where
)
10770 gcc_assert (t1
->specific
&& t2
->specific
);
10771 gcc_assert (!t1
->specific
->is_generic
);
10772 gcc_assert (!t2
->specific
->is_generic
);
10774 sym1
= t1
->specific
->u
.specific
->n
.sym
;
10775 sym2
= t2
->specific
->u
.specific
->n
.sym
;
10780 /* Both must be SUBROUTINEs or both must be FUNCTIONs. */
10781 if (sym1
->attr
.subroutine
!= sym2
->attr
.subroutine
10782 || sym1
->attr
.function
!= sym2
->attr
.function
)
10784 gfc_error ("'%s' and '%s' can't be mixed FUNCTION/SUBROUTINE for"
10785 " GENERIC '%s' at %L",
10786 sym1
->name
, sym2
->name
, generic_name
, &where
);
10790 /* Compare the interfaces. */
10791 if (gfc_compare_interfaces (sym1
, sym2
, sym2
->name
, 1, 0, NULL
, 0))
10793 gfc_error ("'%s' and '%s' for GENERIC '%s' at %L are ambiguous",
10794 sym1
->name
, sym2
->name
, generic_name
, &where
);
10802 /* Worker function for resolving a generic procedure binding; this is used to
10803 resolve GENERIC as well as user and intrinsic OPERATOR typebound procedures.
10805 The difference between those cases is finding possible inherited bindings
10806 that are overridden, as one has to look for them in tb_sym_root,
10807 tb_uop_root or tb_op, respectively. Thus the caller must already find
10808 the super-type and set p->overridden correctly. */
10811 resolve_tb_generic_targets (gfc_symbol
* super_type
,
10812 gfc_typebound_proc
* p
, const char* name
)
10814 gfc_tbp_generic
* target
;
10815 gfc_symtree
* first_target
;
10816 gfc_symtree
* inherited
;
10818 gcc_assert (p
&& p
->is_generic
);
10820 /* Try to find the specific bindings for the symtrees in our target-list. */
10821 gcc_assert (p
->u
.generic
);
10822 for (target
= p
->u
.generic
; target
; target
= target
->next
)
10823 if (!target
->specific
)
10825 gfc_typebound_proc
* overridden_tbp
;
10826 gfc_tbp_generic
* g
;
10827 const char* target_name
;
10829 target_name
= target
->specific_st
->name
;
10831 /* Defined for this type directly. */
10832 if (target
->specific_st
->n
.tb
&& !target
->specific_st
->n
.tb
->error
)
10834 target
->specific
= target
->specific_st
->n
.tb
;
10835 goto specific_found
;
10838 /* Look for an inherited specific binding. */
10841 inherited
= gfc_find_typebound_proc (super_type
, NULL
, target_name
,
10846 gcc_assert (inherited
->n
.tb
);
10847 target
->specific
= inherited
->n
.tb
;
10848 goto specific_found
;
10852 gfc_error ("Undefined specific binding '%s' as target of GENERIC '%s'"
10853 " at %L", target_name
, name
, &p
->where
);
10856 /* Once we've found the specific binding, check it is not ambiguous with
10857 other specifics already found or inherited for the same GENERIC. */
10859 gcc_assert (target
->specific
);
10861 /* This must really be a specific binding! */
10862 if (target
->specific
->is_generic
)
10864 gfc_error ("GENERIC '%s' at %L must target a specific binding,"
10865 " '%s' is GENERIC, too", name
, &p
->where
, target_name
);
10869 /* Check those already resolved on this type directly. */
10870 for (g
= p
->u
.generic
; g
; g
= g
->next
)
10871 if (g
!= target
&& g
->specific
10872 && check_generic_tbp_ambiguity (target
, g
, name
, p
->where
)
10876 /* Check for ambiguity with inherited specific targets. */
10877 for (overridden_tbp
= p
->overridden
; overridden_tbp
;
10878 overridden_tbp
= overridden_tbp
->overridden
)
10879 if (overridden_tbp
->is_generic
)
10881 for (g
= overridden_tbp
->u
.generic
; g
; g
= g
->next
)
10883 gcc_assert (g
->specific
);
10884 if (check_generic_tbp_ambiguity (target
, g
,
10885 name
, p
->where
) == FAILURE
)
10891 /* If we attempt to "overwrite" a specific binding, this is an error. */
10892 if (p
->overridden
&& !p
->overridden
->is_generic
)
10894 gfc_error ("GENERIC '%s' at %L can't overwrite specific binding with"
10895 " the same name", name
, &p
->where
);
10899 /* Take the SUBROUTINE/FUNCTION attributes of the first specific target, as
10900 all must have the same attributes here. */
10901 first_target
= p
->u
.generic
->specific
->u
.specific
;
10902 gcc_assert (first_target
);
10903 p
->subroutine
= first_target
->n
.sym
->attr
.subroutine
;
10904 p
->function
= first_target
->n
.sym
->attr
.function
;
10910 /* Resolve a GENERIC procedure binding for a derived type. */
10913 resolve_typebound_generic (gfc_symbol
* derived
, gfc_symtree
* st
)
10915 gfc_symbol
* super_type
;
10917 /* Find the overridden binding if any. */
10918 st
->n
.tb
->overridden
= NULL
;
10919 super_type
= gfc_get_derived_super_type (derived
);
10922 gfc_symtree
* overridden
;
10923 overridden
= gfc_find_typebound_proc (super_type
, NULL
, st
->name
,
10926 if (overridden
&& overridden
->n
.tb
)
10927 st
->n
.tb
->overridden
= overridden
->n
.tb
;
10930 /* Resolve using worker function. */
10931 return resolve_tb_generic_targets (super_type
, st
->n
.tb
, st
->name
);
10935 /* Retrieve the target-procedure of an operator binding and do some checks in
10936 common for intrinsic and user-defined type-bound operators. */
10939 get_checked_tb_operator_target (gfc_tbp_generic
* target
, locus where
)
10941 gfc_symbol
* target_proc
;
10943 gcc_assert (target
->specific
&& !target
->specific
->is_generic
);
10944 target_proc
= target
->specific
->u
.specific
->n
.sym
;
10945 gcc_assert (target_proc
);
10947 /* All operator bindings must have a passed-object dummy argument. */
10948 if (target
->specific
->nopass
)
10950 gfc_error ("Type-bound operator at %L can't be NOPASS", &where
);
10954 return target_proc
;
10958 /* Resolve a type-bound intrinsic operator. */
10961 resolve_typebound_intrinsic_op (gfc_symbol
* derived
, gfc_intrinsic_op op
,
10962 gfc_typebound_proc
* p
)
10964 gfc_symbol
* super_type
;
10965 gfc_tbp_generic
* target
;
10967 /* If there's already an error here, do nothing (but don't fail again). */
10971 /* Operators should always be GENERIC bindings. */
10972 gcc_assert (p
->is_generic
);
10974 /* Look for an overridden binding. */
10975 super_type
= gfc_get_derived_super_type (derived
);
10976 if (super_type
&& super_type
->f2k_derived
)
10977 p
->overridden
= gfc_find_typebound_intrinsic_op (super_type
, NULL
,
10980 p
->overridden
= NULL
;
10982 /* Resolve general GENERIC properties using worker function. */
10983 if (resolve_tb_generic_targets (super_type
, p
, gfc_op2string (op
)) == FAILURE
)
10986 /* Check the targets to be procedures of correct interface. */
10987 for (target
= p
->u
.generic
; target
; target
= target
->next
)
10989 gfc_symbol
* target_proc
;
10991 target_proc
= get_checked_tb_operator_target (target
, p
->where
);
10995 if (!gfc_check_operator_interface (target_proc
, op
, p
->where
))
11007 /* Resolve a type-bound user operator (tree-walker callback). */
11009 static gfc_symbol
* resolve_bindings_derived
;
11010 static gfc_try resolve_bindings_result
;
11012 static gfc_try
check_uop_procedure (gfc_symbol
* sym
, locus where
);
11015 resolve_typebound_user_op (gfc_symtree
* stree
)
11017 gfc_symbol
* super_type
;
11018 gfc_tbp_generic
* target
;
11020 gcc_assert (stree
&& stree
->n
.tb
);
11022 if (stree
->n
.tb
->error
)
11025 /* Operators should always be GENERIC bindings. */
11026 gcc_assert (stree
->n
.tb
->is_generic
);
11028 /* Find overridden procedure, if any. */
11029 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
11030 if (super_type
&& super_type
->f2k_derived
)
11032 gfc_symtree
* overridden
;
11033 overridden
= gfc_find_typebound_user_op (super_type
, NULL
,
11034 stree
->name
, true, NULL
);
11036 if (overridden
&& overridden
->n
.tb
)
11037 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
11040 stree
->n
.tb
->overridden
= NULL
;
11042 /* Resolve basically using worker function. */
11043 if (resolve_tb_generic_targets (super_type
, stree
->n
.tb
, stree
->name
)
11047 /* Check the targets to be functions of correct interface. */
11048 for (target
= stree
->n
.tb
->u
.generic
; target
; target
= target
->next
)
11050 gfc_symbol
* target_proc
;
11052 target_proc
= get_checked_tb_operator_target (target
, stree
->n
.tb
->where
);
11056 if (check_uop_procedure (target_proc
, stree
->n
.tb
->where
) == FAILURE
)
11063 resolve_bindings_result
= FAILURE
;
11064 stree
->n
.tb
->error
= 1;
11068 /* Resolve the type-bound procedures for a derived type. */
11071 resolve_typebound_procedure (gfc_symtree
* stree
)
11075 gfc_symbol
* me_arg
;
11076 gfc_symbol
* super_type
;
11077 gfc_component
* comp
;
11079 gcc_assert (stree
);
11081 /* Undefined specific symbol from GENERIC target definition. */
11085 if (stree
->n
.tb
->error
)
11088 /* If this is a GENERIC binding, use that routine. */
11089 if (stree
->n
.tb
->is_generic
)
11091 if (resolve_typebound_generic (resolve_bindings_derived
, stree
)
11097 /* Get the target-procedure to check it. */
11098 gcc_assert (!stree
->n
.tb
->is_generic
);
11099 gcc_assert (stree
->n
.tb
->u
.specific
);
11100 proc
= stree
->n
.tb
->u
.specific
->n
.sym
;
11101 where
= stree
->n
.tb
->where
;
11103 /* Default access should already be resolved from the parser. */
11104 gcc_assert (stree
->n
.tb
->access
!= ACCESS_UNKNOWN
);
11106 /* It should be a module procedure or an external procedure with explicit
11107 interface. For DEFERRED bindings, abstract interfaces are ok as well. */
11108 if ((!proc
->attr
.subroutine
&& !proc
->attr
.function
)
11109 || (proc
->attr
.proc
!= PROC_MODULE
11110 && proc
->attr
.if_source
!= IFSRC_IFBODY
)
11111 || (proc
->attr
.abstract
&& !stree
->n
.tb
->deferred
))
11113 gfc_error ("'%s' must be a module procedure or an external procedure with"
11114 " an explicit interface at %L", proc
->name
, &where
);
11117 stree
->n
.tb
->subroutine
= proc
->attr
.subroutine
;
11118 stree
->n
.tb
->function
= proc
->attr
.function
;
11120 /* Find the super-type of the current derived type. We could do this once and
11121 store in a global if speed is needed, but as long as not I believe this is
11122 more readable and clearer. */
11123 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
11125 /* If PASS, resolve and check arguments if not already resolved / loaded
11126 from a .mod file. */
11127 if (!stree
->n
.tb
->nopass
&& stree
->n
.tb
->pass_arg_num
== 0)
11129 if (stree
->n
.tb
->pass_arg
)
11131 gfc_formal_arglist
* i
;
11133 /* If an explicit passing argument name is given, walk the arg-list
11134 and look for it. */
11137 stree
->n
.tb
->pass_arg_num
= 1;
11138 for (i
= proc
->formal
; i
; i
= i
->next
)
11140 if (!strcmp (i
->sym
->name
, stree
->n
.tb
->pass_arg
))
11145 ++stree
->n
.tb
->pass_arg_num
;
11150 gfc_error ("Procedure '%s' with PASS(%s) at %L has no"
11152 proc
->name
, stree
->n
.tb
->pass_arg
, &where
,
11153 stree
->n
.tb
->pass_arg
);
11159 /* Otherwise, take the first one; there should in fact be at least
11161 stree
->n
.tb
->pass_arg_num
= 1;
11164 gfc_error ("Procedure '%s' with PASS at %L must have at"
11165 " least one argument", proc
->name
, &where
);
11168 me_arg
= proc
->formal
->sym
;
11171 /* Now check that the argument-type matches and the passed-object
11172 dummy argument is generally fine. */
11174 gcc_assert (me_arg
);
11176 if (me_arg
->ts
.type
!= BT_CLASS
)
11178 gfc_error ("Non-polymorphic passed-object dummy argument of '%s'"
11179 " at %L", proc
->name
, &where
);
11183 if (CLASS_DATA (me_arg
)->ts
.u
.derived
11184 != resolve_bindings_derived
)
11186 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L must be of"
11187 " the derived-type '%s'", me_arg
->name
, proc
->name
,
11188 me_arg
->name
, &where
, resolve_bindings_derived
->name
);
11192 gcc_assert (me_arg
->ts
.type
== BT_CLASS
);
11193 if (CLASS_DATA (me_arg
)->as
&& CLASS_DATA (me_arg
)->as
->rank
> 0)
11195 gfc_error ("Passed-object dummy argument of '%s' at %L must be"
11196 " scalar", proc
->name
, &where
);
11199 if (CLASS_DATA (me_arg
)->attr
.allocatable
)
11201 gfc_error ("Passed-object dummy argument of '%s' at %L must not"
11202 " be ALLOCATABLE", proc
->name
, &where
);
11205 if (CLASS_DATA (me_arg
)->attr
.class_pointer
)
11207 gfc_error ("Passed-object dummy argument of '%s' at %L must not"
11208 " be POINTER", proc
->name
, &where
);
11213 /* If we are extending some type, check that we don't override a procedure
11214 flagged NON_OVERRIDABLE. */
11215 stree
->n
.tb
->overridden
= NULL
;
11218 gfc_symtree
* overridden
;
11219 overridden
= gfc_find_typebound_proc (super_type
, NULL
,
11220 stree
->name
, true, NULL
);
11224 if (overridden
->n
.tb
)
11225 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
11227 if (gfc_check_typebound_override (stree
, overridden
) == FAILURE
)
11232 /* See if there's a name collision with a component directly in this type. */
11233 for (comp
= resolve_bindings_derived
->components
; comp
; comp
= comp
->next
)
11234 if (!strcmp (comp
->name
, stree
->name
))
11236 gfc_error ("Procedure '%s' at %L has the same name as a component of"
11238 stree
->name
, &where
, resolve_bindings_derived
->name
);
11242 /* Try to find a name collision with an inherited component. */
11243 if (super_type
&& gfc_find_component (super_type
, stree
->name
, true, true))
11245 gfc_error ("Procedure '%s' at %L has the same name as an inherited"
11246 " component of '%s'",
11247 stree
->name
, &where
, resolve_bindings_derived
->name
);
11251 stree
->n
.tb
->error
= 0;
11255 resolve_bindings_result
= FAILURE
;
11256 stree
->n
.tb
->error
= 1;
11261 resolve_typebound_procedures (gfc_symbol
* derived
)
11264 gfc_symbol
* super_type
;
11266 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->tb_sym_root
)
11269 super_type
= gfc_get_derived_super_type (derived
);
11271 resolve_typebound_procedures (super_type
);
11273 resolve_bindings_derived
= derived
;
11274 resolve_bindings_result
= SUCCESS
;
11276 /* Make sure the vtab has been generated. */
11277 gfc_find_derived_vtab (derived
);
11279 if (derived
->f2k_derived
->tb_sym_root
)
11280 gfc_traverse_symtree (derived
->f2k_derived
->tb_sym_root
,
11281 &resolve_typebound_procedure
);
11283 if (derived
->f2k_derived
->tb_uop_root
)
11284 gfc_traverse_symtree (derived
->f2k_derived
->tb_uop_root
,
11285 &resolve_typebound_user_op
);
11287 for (op
= 0; op
!= GFC_INTRINSIC_OPS
; ++op
)
11289 gfc_typebound_proc
* p
= derived
->f2k_derived
->tb_op
[op
];
11290 if (p
&& resolve_typebound_intrinsic_op (derived
, (gfc_intrinsic_op
) op
,
11292 resolve_bindings_result
= FAILURE
;
11295 return resolve_bindings_result
;
11299 /* Add a derived type to the dt_list. The dt_list is used in trans-types.c
11300 to give all identical derived types the same backend_decl. */
11302 add_dt_to_dt_list (gfc_symbol
*derived
)
11304 gfc_dt_list
*dt_list
;
11306 for (dt_list
= gfc_derived_types
; dt_list
; dt_list
= dt_list
->next
)
11307 if (derived
== dt_list
->derived
)
11310 dt_list
= gfc_get_dt_list ();
11311 dt_list
->next
= gfc_derived_types
;
11312 dt_list
->derived
= derived
;
11313 gfc_derived_types
= dt_list
;
11317 /* Ensure that a derived-type is really not abstract, meaning that every
11318 inherited DEFERRED binding is overridden by a non-DEFERRED one. */
11321 ensure_not_abstract_walker (gfc_symbol
* sub
, gfc_symtree
* st
)
11326 if (ensure_not_abstract_walker (sub
, st
->left
) == FAILURE
)
11328 if (ensure_not_abstract_walker (sub
, st
->right
) == FAILURE
)
11331 if (st
->n
.tb
&& st
->n
.tb
->deferred
)
11333 gfc_symtree
* overriding
;
11334 overriding
= gfc_find_typebound_proc (sub
, NULL
, st
->name
, true, NULL
);
11337 gcc_assert (overriding
->n
.tb
);
11338 if (overriding
->n
.tb
->deferred
)
11340 gfc_error ("Derived-type '%s' declared at %L must be ABSTRACT because"
11341 " '%s' is DEFERRED and not overridden",
11342 sub
->name
, &sub
->declared_at
, st
->name
);
11351 ensure_not_abstract (gfc_symbol
* sub
, gfc_symbol
* ancestor
)
11353 /* The algorithm used here is to recursively travel up the ancestry of sub
11354 and for each ancestor-type, check all bindings. If any of them is
11355 DEFERRED, look it up starting from sub and see if the found (overriding)
11356 binding is not DEFERRED.
11357 This is not the most efficient way to do this, but it should be ok and is
11358 clearer than something sophisticated. */
11360 gcc_assert (ancestor
&& !sub
->attr
.abstract
);
11362 if (!ancestor
->attr
.abstract
)
11365 /* Walk bindings of this ancestor. */
11366 if (ancestor
->f2k_derived
)
11369 t
= ensure_not_abstract_walker (sub
, ancestor
->f2k_derived
->tb_sym_root
);
11374 /* Find next ancestor type and recurse on it. */
11375 ancestor
= gfc_get_derived_super_type (ancestor
);
11377 return ensure_not_abstract (sub
, ancestor
);
11383 /* Resolve the components of a derived type. This does not have to wait until
11384 resolution stage, but can be done as soon as the dt declaration has been
11388 resolve_fl_derived0 (gfc_symbol
*sym
)
11390 gfc_symbol
* super_type
;
11393 super_type
= gfc_get_derived_super_type (sym
);
11396 if (super_type
&& sym
->attr
.coarray_comp
&& !super_type
->attr
.coarray_comp
)
11398 gfc_error ("As extending type '%s' at %L has a coarray component, "
11399 "parent type '%s' shall also have one", sym
->name
,
11400 &sym
->declared_at
, super_type
->name
);
11404 /* Ensure the extended type gets resolved before we do. */
11405 if (super_type
&& resolve_fl_derived0 (super_type
) == FAILURE
)
11408 /* An ABSTRACT type must be extensible. */
11409 if (sym
->attr
.abstract
&& !gfc_type_is_extensible (sym
))
11411 gfc_error ("Non-extensible derived-type '%s' at %L must not be ABSTRACT",
11412 sym
->name
, &sym
->declared_at
);
11416 for (c
= sym
->components
; c
!= NULL
; c
= c
->next
)
11419 if (c
->attr
.codimension
/* FIXME: c->as check due to PR 43412. */
11420 && (!c
->attr
.allocatable
|| (c
->as
&& c
->as
->type
!= AS_DEFERRED
)))
11422 gfc_error ("Coarray component '%s' at %L must be allocatable with "
11423 "deferred shape", c
->name
, &c
->loc
);
11428 if (c
->attr
.codimension
&& c
->ts
.type
== BT_DERIVED
11429 && c
->ts
.u
.derived
->ts
.is_iso_c
)
11431 gfc_error ("Component '%s' at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
11432 "shall not be a coarray", c
->name
, &c
->loc
);
11437 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
11438 && (c
->attr
.codimension
|| c
->attr
.pointer
|| c
->attr
.dimension
11439 || c
->attr
.allocatable
))
11441 gfc_error ("Component '%s' at %L with coarray component "
11442 "shall be a nonpointer, nonallocatable scalar",
11448 if (c
->attr
.contiguous
&& (!c
->attr
.dimension
|| !c
->attr
.pointer
))
11450 gfc_error ("Component '%s' at %L has the CONTIGUOUS attribute but "
11451 "is not an array pointer", c
->name
, &c
->loc
);
11455 if (c
->attr
.proc_pointer
&& c
->ts
.interface
)
11457 if (c
->ts
.interface
->attr
.procedure
&& !sym
->attr
.vtype
)
11458 gfc_error ("Interface '%s', used by procedure pointer component "
11459 "'%s' at %L, is declared in a later PROCEDURE statement",
11460 c
->ts
.interface
->name
, c
->name
, &c
->loc
);
11462 /* Get the attributes from the interface (now resolved). */
11463 if (c
->ts
.interface
->attr
.if_source
11464 || c
->ts
.interface
->attr
.intrinsic
)
11466 gfc_symbol
*ifc
= c
->ts
.interface
;
11468 if (ifc
->formal
&& !ifc
->formal_ns
)
11469 resolve_symbol (ifc
);
11471 if (ifc
->attr
.intrinsic
)
11472 resolve_intrinsic (ifc
, &ifc
->declared_at
);
11476 c
->ts
= ifc
->result
->ts
;
11477 c
->attr
.allocatable
= ifc
->result
->attr
.allocatable
;
11478 c
->attr
.pointer
= ifc
->result
->attr
.pointer
;
11479 c
->attr
.dimension
= ifc
->result
->attr
.dimension
;
11480 c
->as
= gfc_copy_array_spec (ifc
->result
->as
);
11485 c
->attr
.allocatable
= ifc
->attr
.allocatable
;
11486 c
->attr
.pointer
= ifc
->attr
.pointer
;
11487 c
->attr
.dimension
= ifc
->attr
.dimension
;
11488 c
->as
= gfc_copy_array_spec (ifc
->as
);
11490 c
->ts
.interface
= ifc
;
11491 c
->attr
.function
= ifc
->attr
.function
;
11492 c
->attr
.subroutine
= ifc
->attr
.subroutine
;
11493 gfc_copy_formal_args_ppc (c
, ifc
);
11495 c
->attr
.pure
= ifc
->attr
.pure
;
11496 c
->attr
.elemental
= ifc
->attr
.elemental
;
11497 c
->attr
.recursive
= ifc
->attr
.recursive
;
11498 c
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
11499 c
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
11500 /* Replace symbols in array spec. */
11504 for (i
= 0; i
< c
->as
->rank
; i
++)
11506 gfc_expr_replace_comp (c
->as
->lower
[i
], c
);
11507 gfc_expr_replace_comp (c
->as
->upper
[i
], c
);
11510 /* Copy char length. */
11511 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
11513 gfc_charlen
*cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
11514 gfc_expr_replace_comp (cl
->length
, c
);
11515 if (cl
->length
&& !cl
->resolved
11516 && gfc_resolve_expr (cl
->length
) == FAILURE
)
11521 else if (!sym
->attr
.vtype
&& c
->ts
.interface
->name
[0] != '\0')
11523 gfc_error ("Interface '%s' of procedure pointer component "
11524 "'%s' at %L must be explicit", c
->ts
.interface
->name
,
11529 else if (c
->attr
.proc_pointer
&& c
->ts
.type
== BT_UNKNOWN
)
11531 /* Since PPCs are not implicitly typed, a PPC without an explicit
11532 interface must be a subroutine. */
11533 gfc_add_subroutine (&c
->attr
, c
->name
, &c
->loc
);
11536 /* Procedure pointer components: Check PASS arg. */
11537 if (c
->attr
.proc_pointer
&& !c
->tb
->nopass
&& c
->tb
->pass_arg_num
== 0
11538 && !sym
->attr
.vtype
)
11540 gfc_symbol
* me_arg
;
11542 if (c
->tb
->pass_arg
)
11544 gfc_formal_arglist
* i
;
11546 /* If an explicit passing argument name is given, walk the arg-list
11547 and look for it. */
11550 c
->tb
->pass_arg_num
= 1;
11551 for (i
= c
->formal
; i
; i
= i
->next
)
11553 if (!strcmp (i
->sym
->name
, c
->tb
->pass_arg
))
11558 c
->tb
->pass_arg_num
++;
11563 gfc_error ("Procedure pointer component '%s' with PASS(%s) "
11564 "at %L has no argument '%s'", c
->name
,
11565 c
->tb
->pass_arg
, &c
->loc
, c
->tb
->pass_arg
);
11572 /* Otherwise, take the first one; there should in fact be at least
11574 c
->tb
->pass_arg_num
= 1;
11577 gfc_error ("Procedure pointer component '%s' with PASS at %L "
11578 "must have at least one argument",
11583 me_arg
= c
->formal
->sym
;
11586 /* Now check that the argument-type matches. */
11587 gcc_assert (me_arg
);
11588 if ((me_arg
->ts
.type
!= BT_DERIVED
&& me_arg
->ts
.type
!= BT_CLASS
)
11589 || (me_arg
->ts
.type
== BT_DERIVED
&& me_arg
->ts
.u
.derived
!= sym
)
11590 || (me_arg
->ts
.type
== BT_CLASS
11591 && CLASS_DATA (me_arg
)->ts
.u
.derived
!= sym
))
11593 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L must be of"
11594 " the derived type '%s'", me_arg
->name
, c
->name
,
11595 me_arg
->name
, &c
->loc
, sym
->name
);
11600 /* Check for C453. */
11601 if (me_arg
->attr
.dimension
)
11603 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
11604 "must be scalar", me_arg
->name
, c
->name
, me_arg
->name
,
11610 if (me_arg
->attr
.pointer
)
11612 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
11613 "may not have the POINTER attribute", me_arg
->name
,
11614 c
->name
, me_arg
->name
, &c
->loc
);
11619 if (me_arg
->attr
.allocatable
)
11621 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
11622 "may not be ALLOCATABLE", me_arg
->name
, c
->name
,
11623 me_arg
->name
, &c
->loc
);
11628 if (gfc_type_is_extensible (sym
) && me_arg
->ts
.type
!= BT_CLASS
)
11629 gfc_error ("Non-polymorphic passed-object dummy argument of '%s'"
11630 " at %L", c
->name
, &c
->loc
);
11634 /* Check type-spec if this is not the parent-type component. */
11635 if ((!sym
->attr
.extension
|| c
!= sym
->components
) && !sym
->attr
.vtype
11636 && resolve_typespec_used (&c
->ts
, &c
->loc
, c
->name
) == FAILURE
)
11639 /* If this type is an extension, set the accessibility of the parent
11641 if (super_type
&& c
== sym
->components
11642 && strcmp (super_type
->name
, c
->name
) == 0)
11643 c
->attr
.access
= super_type
->attr
.access
;
11645 /* If this type is an extension, see if this component has the same name
11646 as an inherited type-bound procedure. */
11647 if (super_type
&& !sym
->attr
.is_class
11648 && gfc_find_typebound_proc (super_type
, NULL
, c
->name
, true, NULL
))
11650 gfc_error ("Component '%s' of '%s' at %L has the same name as an"
11651 " inherited type-bound procedure",
11652 c
->name
, sym
->name
, &c
->loc
);
11656 if (c
->ts
.type
== BT_CHARACTER
&& !c
->attr
.proc_pointer
11657 && !c
->ts
.deferred
)
11659 if (c
->ts
.u
.cl
->length
== NULL
11660 || (resolve_charlen (c
->ts
.u
.cl
) == FAILURE
)
11661 || !gfc_is_constant_expr (c
->ts
.u
.cl
->length
))
11663 gfc_error ("Character length of component '%s' needs to "
11664 "be a constant specification expression at %L",
11666 c
->ts
.u
.cl
->length
? &c
->ts
.u
.cl
->length
->where
: &c
->loc
);
11671 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
11672 && !c
->attr
.pointer
&& !c
->attr
.allocatable
)
11674 gfc_error ("Character component '%s' of '%s' at %L with deferred "
11675 "length must be a POINTER or ALLOCATABLE",
11676 c
->name
, sym
->name
, &c
->loc
);
11680 if (c
->ts
.type
== BT_DERIVED
11681 && sym
->component_access
!= ACCESS_PRIVATE
11682 && gfc_check_symbol_access (sym
)
11683 && !is_sym_host_assoc (c
->ts
.u
.derived
, sym
->ns
)
11684 && !c
->ts
.u
.derived
->attr
.use_assoc
11685 && !gfc_check_symbol_access (c
->ts
.u
.derived
)
11686 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: the component '%s' "
11687 "is a PRIVATE type and cannot be a component of "
11688 "'%s', which is PUBLIC at %L", c
->name
,
11689 sym
->name
, &sym
->declared_at
) == FAILURE
)
11692 if ((sym
->attr
.sequence
|| sym
->attr
.is_bind_c
) && c
->ts
.type
== BT_CLASS
)
11694 gfc_error ("Polymorphic component %s at %L in SEQUENCE or BIND(C) "
11695 "type %s", c
->name
, &c
->loc
, sym
->name
);
11699 if (sym
->attr
.sequence
)
11701 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.sequence
== 0)
11703 gfc_error ("Component %s of SEQUENCE type declared at %L does "
11704 "not have the SEQUENCE attribute",
11705 c
->ts
.u
.derived
->name
, &sym
->declared_at
);
11710 if (!sym
->attr
.is_class
&& c
->ts
.type
== BT_DERIVED
&& !sym
->attr
.vtype
11711 && c
->attr
.pointer
&& c
->ts
.u
.derived
->components
== NULL
11712 && !c
->ts
.u
.derived
->attr
.zero_comp
)
11714 gfc_error ("The pointer component '%s' of '%s' at %L is a type "
11715 "that has not been declared", c
->name
, sym
->name
,
11720 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
11721 && CLASS_DATA (c
)->attr
.class_pointer
11722 && CLASS_DATA (c
)->ts
.u
.derived
->components
== NULL
11723 && !CLASS_DATA (c
)->ts
.u
.derived
->attr
.zero_comp
)
11725 gfc_error ("The pointer component '%s' of '%s' at %L is a type "
11726 "that has not been declared", c
->name
, sym
->name
,
11732 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.flavor
!= FL_PROCEDURE
11733 && (!c
->attr
.class_ok
11734 || !(CLASS_DATA (c
)->attr
.class_pointer
11735 || CLASS_DATA (c
)->attr
.allocatable
)))
11737 gfc_error ("Component '%s' with CLASS at %L must be allocatable "
11738 "or pointer", c
->name
, &c
->loc
);
11742 /* Ensure that all the derived type components are put on the
11743 derived type list; even in formal namespaces, where derived type
11744 pointer components might not have been declared. */
11745 if (c
->ts
.type
== BT_DERIVED
11747 && c
->ts
.u
.derived
->components
11749 && sym
!= c
->ts
.u
.derived
)
11750 add_dt_to_dt_list (c
->ts
.u
.derived
);
11752 if (gfc_resolve_array_spec (c
->as
, !(c
->attr
.pointer
11753 || c
->attr
.proc_pointer
11754 || c
->attr
.allocatable
)) == FAILURE
)
11758 /* If this is a non-ABSTRACT type extending an ABSTRACT one, ensure that
11759 all DEFERRED bindings are overridden. */
11760 if (super_type
&& super_type
->attr
.abstract
&& !sym
->attr
.abstract
11761 && !sym
->attr
.is_class
11762 && ensure_not_abstract (sym
, super_type
) == FAILURE
)
11765 /* Add derived type to the derived type list. */
11766 add_dt_to_dt_list (sym
);
11772 /* The following procedure does the full resolution of a derived type,
11773 including resolution of all type-bound procedures (if present). In contrast
11774 to 'resolve_fl_derived0' this can only be done after the module has been
11775 parsed completely. */
11778 resolve_fl_derived (gfc_symbol
*sym
)
11780 if (sym
->attr
.is_class
&& sym
->ts
.u
.derived
== NULL
)
11782 /* Fix up incomplete CLASS symbols. */
11783 gfc_component
*data
= gfc_find_component (sym
, "_data", true, true);
11784 gfc_component
*vptr
= gfc_find_component (sym
, "_vptr", true, true);
11785 if (vptr
->ts
.u
.derived
== NULL
)
11787 gfc_symbol
*vtab
= gfc_find_derived_vtab (data
->ts
.u
.derived
);
11789 vptr
->ts
.u
.derived
= vtab
->ts
.u
.derived
;
11793 if (resolve_fl_derived0 (sym
) == FAILURE
)
11796 /* Resolve the type-bound procedures. */
11797 if (resolve_typebound_procedures (sym
) == FAILURE
)
11800 /* Resolve the finalizer procedures. */
11801 if (gfc_resolve_finalizers (sym
) == FAILURE
)
11809 resolve_fl_namelist (gfc_symbol
*sym
)
11814 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
11816 /* Check again, the check in match only works if NAMELIST comes
11818 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SIZE
)
11820 gfc_error ("Assumed size array '%s' in namelist '%s' at %L is not "
11821 "allowed", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
11825 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SHAPE
11826 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: NAMELIST array "
11827 "object '%s' with assumed shape in namelist "
11828 "'%s' at %L", nl
->sym
->name
, sym
->name
,
11829 &sym
->declared_at
) == FAILURE
)
11832 if (is_non_constant_shape_array (nl
->sym
)
11833 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: NAMELIST array "
11834 "object '%s' with nonconstant shape in namelist "
11835 "'%s' at %L", nl
->sym
->name
, sym
->name
,
11836 &sym
->declared_at
) == FAILURE
)
11839 if (nl
->sym
->ts
.type
== BT_CHARACTER
11840 && (nl
->sym
->ts
.u
.cl
->length
== NULL
11841 || !gfc_is_constant_expr (nl
->sym
->ts
.u
.cl
->length
))
11842 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: NAMELIST object "
11843 "'%s' with nonconstant character length in "
11844 "namelist '%s' at %L", nl
->sym
->name
, sym
->name
,
11845 &sym
->declared_at
) == FAILURE
)
11848 /* FIXME: Once UDDTIO is implemented, the following can be
11850 if (nl
->sym
->ts
.type
== BT_CLASS
)
11852 gfc_error ("NAMELIST object '%s' in namelist '%s' at %L is "
11853 "polymorphic and requires a defined input/output "
11854 "procedure", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
11858 if (nl
->sym
->ts
.type
== BT_DERIVED
11859 && (nl
->sym
->ts
.u
.derived
->attr
.alloc_comp
11860 || nl
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
11862 if (gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: NAMELIST object "
11863 "'%s' in namelist '%s' at %L with ALLOCATABLE "
11864 "or POINTER components", nl
->sym
->name
,
11865 sym
->name
, &sym
->declared_at
) == FAILURE
)
11868 /* FIXME: Once UDDTIO is implemented, the following can be
11870 gfc_error ("NAMELIST object '%s' in namelist '%s' at %L has "
11871 "ALLOCATABLE or POINTER components and thus requires "
11872 "a defined input/output procedure", nl
->sym
->name
,
11873 sym
->name
, &sym
->declared_at
);
11878 /* Reject PRIVATE objects in a PUBLIC namelist. */
11879 if (gfc_check_symbol_access (sym
))
11881 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
11883 if (!nl
->sym
->attr
.use_assoc
11884 && !is_sym_host_assoc (nl
->sym
, sym
->ns
)
11885 && !gfc_check_symbol_access (nl
->sym
))
11887 gfc_error ("NAMELIST object '%s' was declared PRIVATE and "
11888 "cannot be member of PUBLIC namelist '%s' at %L",
11889 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
11893 /* Types with private components that came here by USE-association. */
11894 if (nl
->sym
->ts
.type
== BT_DERIVED
11895 && derived_inaccessible (nl
->sym
->ts
.u
.derived
))
11897 gfc_error ("NAMELIST object '%s' has use-associated PRIVATE "
11898 "components and cannot be member of namelist '%s' at %L",
11899 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
11903 /* Types with private components that are defined in the same module. */
11904 if (nl
->sym
->ts
.type
== BT_DERIVED
11905 && !is_sym_host_assoc (nl
->sym
->ts
.u
.derived
, sym
->ns
)
11906 && nl
->sym
->ts
.u
.derived
->attr
.private_comp
)
11908 gfc_error ("NAMELIST object '%s' has PRIVATE components and "
11909 "cannot be a member of PUBLIC namelist '%s' at %L",
11910 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
11917 /* 14.1.2 A module or internal procedure represent local entities
11918 of the same type as a namelist member and so are not allowed. */
11919 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
11921 if (nl
->sym
->ts
.kind
!= 0 && nl
->sym
->attr
.flavor
== FL_VARIABLE
)
11924 if (nl
->sym
->attr
.function
&& nl
->sym
== nl
->sym
->result
)
11925 if ((nl
->sym
== sym
->ns
->proc_name
)
11927 (sym
->ns
->parent
&& nl
->sym
== sym
->ns
->parent
->proc_name
))
11931 if (nl
->sym
&& nl
->sym
->name
)
11932 gfc_find_symbol (nl
->sym
->name
, sym
->ns
, 1, &nlsym
);
11933 if (nlsym
&& nlsym
->attr
.flavor
== FL_PROCEDURE
)
11935 gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
11936 "attribute in '%s' at %L", nlsym
->name
,
11937 &sym
->declared_at
);
11947 resolve_fl_parameter (gfc_symbol
*sym
)
11949 /* A parameter array's shape needs to be constant. */
11950 if (sym
->as
!= NULL
11951 && (sym
->as
->type
== AS_DEFERRED
11952 || is_non_constant_shape_array (sym
)))
11954 gfc_error ("Parameter array '%s' at %L cannot be automatic "
11955 "or of deferred shape", sym
->name
, &sym
->declared_at
);
11959 /* Make sure a parameter that has been implicitly typed still
11960 matches the implicit type, since PARAMETER statements can precede
11961 IMPLICIT statements. */
11962 if (sym
->attr
.implicit_type
11963 && !gfc_compare_types (&sym
->ts
, gfc_get_default_type (sym
->name
,
11966 gfc_error ("Implicitly typed PARAMETER '%s' at %L doesn't match a "
11967 "later IMPLICIT type", sym
->name
, &sym
->declared_at
);
11971 /* Make sure the types of derived parameters are consistent. This
11972 type checking is deferred until resolution because the type may
11973 refer to a derived type from the host. */
11974 if (sym
->ts
.type
== BT_DERIVED
11975 && !gfc_compare_types (&sym
->ts
, &sym
->value
->ts
))
11977 gfc_error ("Incompatible derived type in PARAMETER at %L",
11978 &sym
->value
->where
);
11985 /* Do anything necessary to resolve a symbol. Right now, we just
11986 assume that an otherwise unknown symbol is a variable. This sort
11987 of thing commonly happens for symbols in module. */
11990 resolve_symbol (gfc_symbol
*sym
)
11992 int check_constant
, mp_flag
;
11993 gfc_symtree
*symtree
;
11994 gfc_symtree
*this_symtree
;
11998 if (sym
->attr
.flavor
== FL_UNKNOWN
)
12001 /* If we find that a flavorless symbol is an interface in one of the
12002 parent namespaces, find its symtree in this namespace, free the
12003 symbol and set the symtree to point to the interface symbol. */
12004 for (ns
= gfc_current_ns
->parent
; ns
; ns
= ns
->parent
)
12006 symtree
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
12007 if (symtree
&& (symtree
->n
.sym
->generic
||
12008 (symtree
->n
.sym
->attr
.flavor
== FL_PROCEDURE
12009 && sym
->ns
->construct_entities
)))
12011 this_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
12013 gfc_release_symbol (sym
);
12014 symtree
->n
.sym
->refs
++;
12015 this_symtree
->n
.sym
= symtree
->n
.sym
;
12020 /* Otherwise give it a flavor according to such attributes as
12022 if (sym
->attr
.external
== 0 && sym
->attr
.intrinsic
== 0)
12023 sym
->attr
.flavor
= FL_VARIABLE
;
12026 sym
->attr
.flavor
= FL_PROCEDURE
;
12027 if (sym
->attr
.dimension
)
12028 sym
->attr
.function
= 1;
12032 if (sym
->attr
.external
&& sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.function
)
12033 gfc_add_function (&sym
->attr
, sym
->name
, &sym
->declared_at
);
12035 if (sym
->attr
.procedure
&& sym
->ts
.interface
12036 && sym
->attr
.if_source
!= IFSRC_DECL
12037 && resolve_procedure_interface (sym
) == FAILURE
)
12040 if (sym
->attr
.is_protected
&& !sym
->attr
.proc_pointer
12041 && (sym
->attr
.procedure
|| sym
->attr
.external
))
12043 if (sym
->attr
.external
)
12044 gfc_error ("PROTECTED attribute conflicts with EXTERNAL attribute "
12045 "at %L", &sym
->declared_at
);
12047 gfc_error ("PROCEDURE attribute conflicts with PROTECTED attribute "
12048 "at %L", &sym
->declared_at
);
12055 if (sym
->attr
.contiguous
12056 && (!sym
->attr
.dimension
|| (sym
->as
->type
!= AS_ASSUMED_SHAPE
12057 && !sym
->attr
.pointer
)))
12059 gfc_error ("'%s' at %L has the CONTIGUOUS attribute but is not an "
12060 "array pointer or an assumed-shape array", sym
->name
,
12061 &sym
->declared_at
);
12065 if (sym
->attr
.flavor
== FL_DERIVED
&& resolve_fl_derived (sym
) == FAILURE
)
12068 /* Symbols that are module procedures with results (functions) have
12069 the types and array specification copied for type checking in
12070 procedures that call them, as well as for saving to a module
12071 file. These symbols can't stand the scrutiny that their results
12073 mp_flag
= (sym
->result
!= NULL
&& sym
->result
!= sym
);
12075 /* Make sure that the intrinsic is consistent with its internal
12076 representation. This needs to be done before assigning a default
12077 type to avoid spurious warnings. */
12078 if (sym
->attr
.flavor
!= FL_MODULE
&& sym
->attr
.intrinsic
12079 && resolve_intrinsic (sym
, &sym
->declared_at
) == FAILURE
)
12082 /* Resolve associate names. */
12084 resolve_assoc_var (sym
, true);
12086 /* Assign default type to symbols that need one and don't have one. */
12087 if (sym
->ts
.type
== BT_UNKNOWN
)
12089 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
)
12090 gfc_set_default_type (sym
, 1, NULL
);
12092 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.external
12093 && !sym
->attr
.function
&& !sym
->attr
.subroutine
12094 && gfc_get_default_type (sym
->name
, sym
->ns
)->type
== BT_UNKNOWN
)
12095 gfc_add_subroutine (&sym
->attr
, sym
->name
, &sym
->declared_at
);
12097 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
12099 /* The specific case of an external procedure should emit an error
12100 in the case that there is no implicit type. */
12102 gfc_set_default_type (sym
, sym
->attr
.external
, NULL
);
12105 /* Result may be in another namespace. */
12106 resolve_symbol (sym
->result
);
12108 if (!sym
->result
->attr
.proc_pointer
)
12110 sym
->ts
= sym
->result
->ts
;
12111 sym
->as
= gfc_copy_array_spec (sym
->result
->as
);
12112 sym
->attr
.dimension
= sym
->result
->attr
.dimension
;
12113 sym
->attr
.pointer
= sym
->result
->attr
.pointer
;
12114 sym
->attr
.allocatable
= sym
->result
->attr
.allocatable
;
12115 sym
->attr
.contiguous
= sym
->result
->attr
.contiguous
;
12120 else if (mp_flag
&& sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
12121 gfc_resolve_array_spec (sym
->result
->as
, false);
12123 /* Assumed size arrays and assumed shape arrays must be dummy
12124 arguments. Array-spec's of implied-shape should have been resolved to
12125 AS_EXPLICIT already. */
12129 gcc_assert (sym
->as
->type
!= AS_IMPLIED_SHAPE
);
12130 if (((sym
->as
->type
== AS_ASSUMED_SIZE
&& !sym
->as
->cp_was_assumed
)
12131 || sym
->as
->type
== AS_ASSUMED_SHAPE
)
12132 && sym
->attr
.dummy
== 0)
12134 if (sym
->as
->type
== AS_ASSUMED_SIZE
)
12135 gfc_error ("Assumed size array at %L must be a dummy argument",
12136 &sym
->declared_at
);
12138 gfc_error ("Assumed shape array at %L must be a dummy argument",
12139 &sym
->declared_at
);
12144 /* Make sure symbols with known intent or optional are really dummy
12145 variable. Because of ENTRY statement, this has to be deferred
12146 until resolution time. */
12148 if (!sym
->attr
.dummy
12149 && (sym
->attr
.optional
|| sym
->attr
.intent
!= INTENT_UNKNOWN
))
12151 gfc_error ("Symbol at %L is not a DUMMY variable", &sym
->declared_at
);
12155 if (sym
->attr
.value
&& !sym
->attr
.dummy
)
12157 gfc_error ("'%s' at %L cannot have the VALUE attribute because "
12158 "it is not a dummy argument", sym
->name
, &sym
->declared_at
);
12162 if (sym
->attr
.value
&& sym
->ts
.type
== BT_CHARACTER
)
12164 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
12165 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
12167 gfc_error ("Character dummy variable '%s' at %L with VALUE "
12168 "attribute must have constant length",
12169 sym
->name
, &sym
->declared_at
);
12173 if (sym
->ts
.is_c_interop
12174 && mpz_cmp_si (cl
->length
->value
.integer
, 1) != 0)
12176 gfc_error ("C interoperable character dummy variable '%s' at %L "
12177 "with VALUE attribute must have length one",
12178 sym
->name
, &sym
->declared_at
);
12183 /* If the symbol is marked as bind(c), verify it's type and kind. Do not
12184 do this for something that was implicitly typed because that is handled
12185 in gfc_set_default_type. Handle dummy arguments and procedure
12186 definitions separately. Also, anything that is use associated is not
12187 handled here but instead is handled in the module it is declared in.
12188 Finally, derived type definitions are allowed to be BIND(C) since that
12189 only implies that they're interoperable, and they are checked fully for
12190 interoperability when a variable is declared of that type. */
12191 if (sym
->attr
.is_bind_c
&& sym
->attr
.implicit_type
== 0 &&
12192 sym
->attr
.use_assoc
== 0 && sym
->attr
.dummy
== 0 &&
12193 sym
->attr
.flavor
!= FL_PROCEDURE
&& sym
->attr
.flavor
!= FL_DERIVED
)
12195 gfc_try t
= SUCCESS
;
12197 /* First, make sure the variable is declared at the
12198 module-level scope (J3/04-007, Section 15.3). */
12199 if (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
&&
12200 sym
->attr
.in_common
== 0)
12202 gfc_error ("Variable '%s' at %L cannot be BIND(C) because it "
12203 "is neither a COMMON block nor declared at the "
12204 "module level scope", sym
->name
, &(sym
->declared_at
));
12207 else if (sym
->common_head
!= NULL
)
12209 t
= verify_com_block_vars_c_interop (sym
->common_head
);
12213 /* If type() declaration, we need to verify that the components
12214 of the given type are all C interoperable, etc. */
12215 if (sym
->ts
.type
== BT_DERIVED
&&
12216 sym
->ts
.u
.derived
->attr
.is_c_interop
!= 1)
12218 /* Make sure the user marked the derived type as BIND(C). If
12219 not, call the verify routine. This could print an error
12220 for the derived type more than once if multiple variables
12221 of that type are declared. */
12222 if (sym
->ts
.u
.derived
->attr
.is_bind_c
!= 1)
12223 verify_bind_c_derived_type (sym
->ts
.u
.derived
);
12227 /* Verify the variable itself as C interoperable if it
12228 is BIND(C). It is not possible for this to succeed if
12229 the verify_bind_c_derived_type failed, so don't have to handle
12230 any error returned by verify_bind_c_derived_type. */
12231 t
= verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
12232 sym
->common_block
);
12237 /* clear the is_bind_c flag to prevent reporting errors more than
12238 once if something failed. */
12239 sym
->attr
.is_bind_c
= 0;
12244 /* If a derived type symbol has reached this point, without its
12245 type being declared, we have an error. Notice that most
12246 conditions that produce undefined derived types have already
12247 been dealt with. However, the likes of:
12248 implicit type(t) (t) ..... call foo (t) will get us here if
12249 the type is not declared in the scope of the implicit
12250 statement. Change the type to BT_UNKNOWN, both because it is so
12251 and to prevent an ICE. */
12252 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->components
== NULL
12253 && !sym
->ts
.u
.derived
->attr
.zero_comp
)
12255 gfc_error ("The derived type '%s' at %L is of type '%s', "
12256 "which has not been defined", sym
->name
,
12257 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
12258 sym
->ts
.type
= BT_UNKNOWN
;
12262 /* Make sure that the derived type has been resolved and that the
12263 derived type is visible in the symbol's namespace, if it is a
12264 module function and is not PRIVATE. */
12265 if (sym
->ts
.type
== BT_DERIVED
12266 && sym
->ts
.u
.derived
->attr
.use_assoc
12267 && sym
->ns
->proc_name
12268 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
12272 if (resolve_fl_derived (sym
->ts
.u
.derived
) == FAILURE
)
12275 gfc_find_symbol (sym
->ts
.u
.derived
->name
, sym
->ns
, 1, &ds
);
12276 if (!ds
&& sym
->attr
.function
&& gfc_check_symbol_access (sym
))
12278 symtree
= gfc_new_symtree (&sym
->ns
->sym_root
,
12279 sym
->ts
.u
.derived
->name
);
12280 symtree
->n
.sym
= sym
->ts
.u
.derived
;
12281 sym
->ts
.u
.derived
->refs
++;
12285 /* Unless the derived-type declaration is use associated, Fortran 95
12286 does not allow public entries of private derived types.
12287 See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
12288 161 in 95-006r3. */
12289 if (sym
->ts
.type
== BT_DERIVED
12290 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
12291 && !sym
->ts
.u
.derived
->attr
.use_assoc
12292 && gfc_check_symbol_access (sym
)
12293 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
12294 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: PUBLIC %s '%s' at %L "
12295 "of PRIVATE derived type '%s'",
12296 (sym
->attr
.flavor
== FL_PARAMETER
) ? "parameter"
12297 : "variable", sym
->name
, &sym
->declared_at
,
12298 sym
->ts
.u
.derived
->name
) == FAILURE
)
12301 /* F2008, C1302. */
12302 if (sym
->ts
.type
== BT_DERIVED
12303 && ((sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
12304 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
12305 || sym
->ts
.u
.derived
->attr
.lock_comp
)
12306 && !sym
->attr
.codimension
&& !sym
->ts
.u
.derived
->attr
.coarray_comp
)
12308 gfc_error ("Variable %s at %L of type LOCK_TYPE or with subcomponent of "
12309 "type LOCK_TYPE must be a coarray", sym
->name
,
12310 &sym
->declared_at
);
12314 /* An assumed-size array with INTENT(OUT) shall not be of a type for which
12315 default initialization is defined (5.1.2.4.4). */
12316 if (sym
->ts
.type
== BT_DERIVED
12318 && sym
->attr
.intent
== INTENT_OUT
12320 && sym
->as
->type
== AS_ASSUMED_SIZE
)
12322 for (c
= sym
->ts
.u
.derived
->components
; c
; c
= c
->next
)
12324 if (c
->initializer
)
12326 gfc_error ("The INTENT(OUT) dummy argument '%s' at %L is "
12327 "ASSUMED SIZE and so cannot have a default initializer",
12328 sym
->name
, &sym
->declared_at
);
12335 if (sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.dummy
12336 && sym
->attr
.intent
== INTENT_OUT
&& sym
->attr
.lock_comp
)
12338 gfc_error ("Dummy argument '%s' at %L of LOCK_TYPE shall not be "
12339 "INTENT(OUT)", sym
->name
, &sym
->declared_at
);
12344 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
12345 || sym
->attr
.codimension
)
12346 && (sym
->attr
.result
|| sym
->result
== sym
))
12348 gfc_error ("Function result '%s' at %L shall not be a coarray or have "
12349 "a coarray component", sym
->name
, &sym
->declared_at
);
12354 if (sym
->attr
.codimension
&& sym
->ts
.type
== BT_DERIVED
12355 && sym
->ts
.u
.derived
->ts
.is_iso_c
)
12357 gfc_error ("Variable '%s' at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
12358 "shall not be a coarray", sym
->name
, &sym
->declared_at
);
12363 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
12364 && (sym
->attr
.codimension
|| sym
->attr
.pointer
|| sym
->attr
.dimension
12365 || sym
->attr
.allocatable
))
12367 gfc_error ("Variable '%s' at %L with coarray component "
12368 "shall be a nonpointer, nonallocatable scalar",
12369 sym
->name
, &sym
->declared_at
);
12373 /* F2008, C526. The function-result case was handled above. */
12374 if (sym
->attr
.codimension
12375 && !(sym
->attr
.allocatable
|| sym
->attr
.dummy
|| sym
->attr
.save
12376 || sym
->ns
->save_all
12377 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
12378 || sym
->ns
->proc_name
->attr
.is_main_program
12379 || sym
->attr
.function
|| sym
->attr
.result
|| sym
->attr
.use_assoc
))
12381 gfc_error ("Variable '%s' at %L is a coarray and is not ALLOCATABLE, SAVE "
12382 "nor a dummy argument", sym
->name
, &sym
->declared_at
);
12385 /* F2008, C528. */ /* FIXME: sym->as check due to PR 43412. */
12386 else if (sym
->attr
.codimension
&& !sym
->attr
.allocatable
12387 && sym
->as
&& sym
->as
->cotype
== AS_DEFERRED
)
12389 gfc_error ("Coarray variable '%s' at %L shall not have codimensions with "
12390 "deferred shape", sym
->name
, &sym
->declared_at
);
12393 else if (sym
->attr
.codimension
&& sym
->attr
.allocatable
12394 && (sym
->as
->type
!= AS_DEFERRED
|| sym
->as
->cotype
!= AS_DEFERRED
))
12396 gfc_error ("Allocatable coarray variable '%s' at %L must have "
12397 "deferred shape", sym
->name
, &sym
->declared_at
);
12402 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
12403 || (sym
->attr
.codimension
&& sym
->attr
.allocatable
))
12404 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
)
12406 gfc_error ("Variable '%s' at %L is INTENT(OUT) and can thus not be an "
12407 "allocatable coarray or have coarray components",
12408 sym
->name
, &sym
->declared_at
);
12412 if (sym
->attr
.codimension
&& sym
->attr
.dummy
12413 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.is_bind_c
)
12415 gfc_error ("Coarray dummy variable '%s' at %L not allowed in BIND(C) "
12416 "procedure '%s'", sym
->name
, &sym
->declared_at
,
12417 sym
->ns
->proc_name
->name
);
12421 switch (sym
->attr
.flavor
)
12424 if (resolve_fl_variable (sym
, mp_flag
) == FAILURE
)
12429 if (resolve_fl_procedure (sym
, mp_flag
) == FAILURE
)
12434 if (resolve_fl_namelist (sym
) == FAILURE
)
12439 if (resolve_fl_parameter (sym
) == FAILURE
)
12447 /* Resolve array specifier. Check as well some constraints
12448 on COMMON blocks. */
12450 check_constant
= sym
->attr
.in_common
&& !sym
->attr
.pointer
;
12452 /* Set the formal_arg_flag so that check_conflict will not throw
12453 an error for host associated variables in the specification
12454 expression for an array_valued function. */
12455 if (sym
->attr
.function
&& sym
->as
)
12456 formal_arg_flag
= 1;
12458 gfc_resolve_array_spec (sym
->as
, check_constant
);
12460 formal_arg_flag
= 0;
12462 /* Resolve formal namespaces. */
12463 if (sym
->formal_ns
&& sym
->formal_ns
!= gfc_current_ns
12464 && !sym
->attr
.contained
&& !sym
->attr
.intrinsic
)
12465 gfc_resolve (sym
->formal_ns
);
12467 /* Make sure the formal namespace is present. */
12468 if (sym
->formal
&& !sym
->formal_ns
)
12470 gfc_formal_arglist
*formal
= sym
->formal
;
12471 while (formal
&& !formal
->sym
)
12472 formal
= formal
->next
;
12476 sym
->formal_ns
= formal
->sym
->ns
;
12477 sym
->formal_ns
->refs
++;
12481 /* Check threadprivate restrictions. */
12482 if (sym
->attr
.threadprivate
&& !sym
->attr
.save
&& !sym
->ns
->save_all
12483 && (!sym
->attr
.in_common
12484 && sym
->module
== NULL
12485 && (sym
->ns
->proc_name
== NULL
12486 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
12487 gfc_error ("Threadprivate at %L isn't SAVEd", &sym
->declared_at
);
12489 /* If we have come this far we can apply default-initializers, as
12490 described in 14.7.5, to those variables that have not already
12491 been assigned one. */
12492 if (sym
->ts
.type
== BT_DERIVED
12493 && sym
->ns
== gfc_current_ns
12495 && !sym
->attr
.allocatable
12496 && !sym
->attr
.alloc_comp
)
12498 symbol_attribute
*a
= &sym
->attr
;
12500 if ((!a
->save
&& !a
->dummy
&& !a
->pointer
12501 && !a
->in_common
&& !a
->use_assoc
12502 && (a
->referenced
|| a
->result
)
12503 && !(a
->function
&& sym
!= sym
->result
))
12504 || (a
->dummy
&& a
->intent
== INTENT_OUT
&& !a
->pointer
))
12505 apply_default_init (sym
);
12508 if (sym
->ts
.type
== BT_CLASS
&& sym
->ns
== gfc_current_ns
12509 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
12510 && !CLASS_DATA (sym
)->attr
.class_pointer
12511 && !CLASS_DATA (sym
)->attr
.allocatable
)
12512 apply_default_init (sym
);
12514 /* If this symbol has a type-spec, check it. */
12515 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
12516 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
))
12517 if (resolve_typespec_used (&sym
->ts
, &sym
->declared_at
, sym
->name
)
12523 /************* Resolve DATA statements *************/
12527 gfc_data_value
*vnode
;
12533 /* Advance the values structure to point to the next value in the data list. */
12536 next_data_value (void)
12538 while (mpz_cmp_ui (values
.left
, 0) == 0)
12541 if (values
.vnode
->next
== NULL
)
12544 values
.vnode
= values
.vnode
->next
;
12545 mpz_set (values
.left
, values
.vnode
->repeat
);
12553 check_data_variable (gfc_data_variable
*var
, locus
*where
)
12559 ar_type mark
= AR_UNKNOWN
;
12561 mpz_t section_index
[GFC_MAX_DIMENSIONS
];
12567 if (gfc_resolve_expr (var
->expr
) == FAILURE
)
12571 mpz_init_set_si (offset
, 0);
12574 if (e
->expr_type
!= EXPR_VARIABLE
)
12575 gfc_internal_error ("check_data_variable(): Bad expression");
12577 sym
= e
->symtree
->n
.sym
;
12579 if (sym
->ns
->is_block_data
&& !sym
->attr
.in_common
)
12581 gfc_error ("BLOCK DATA element '%s' at %L must be in COMMON",
12582 sym
->name
, &sym
->declared_at
);
12585 if (e
->ref
== NULL
&& sym
->as
)
12587 gfc_error ("DATA array '%s' at %L must be specified in a previous"
12588 " declaration", sym
->name
, where
);
12592 has_pointer
= sym
->attr
.pointer
;
12594 if (gfc_is_coindexed (e
))
12596 gfc_error ("DATA element '%s' at %L cannot have a coindex", sym
->name
,
12601 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
12603 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.pointer
)
12607 && ref
->type
== REF_ARRAY
12608 && ref
->u
.ar
.type
!= AR_FULL
)
12610 gfc_error ("DATA element '%s' at %L is a pointer and so must "
12611 "be a full array", sym
->name
, where
);
12616 if (e
->rank
== 0 || has_pointer
)
12618 mpz_init_set_ui (size
, 1);
12625 /* Find the array section reference. */
12626 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
12628 if (ref
->type
!= REF_ARRAY
)
12630 if (ref
->u
.ar
.type
== AR_ELEMENT
)
12636 /* Set marks according to the reference pattern. */
12637 switch (ref
->u
.ar
.type
)
12645 /* Get the start position of array section. */
12646 gfc_get_section_index (ar
, section_index
, &offset
);
12651 gcc_unreachable ();
12654 if (gfc_array_size (e
, &size
) == FAILURE
)
12656 gfc_error ("Nonconstant array section at %L in DATA statement",
12658 mpz_clear (offset
);
12665 while (mpz_cmp_ui (size
, 0) > 0)
12667 if (next_data_value () == FAILURE
)
12669 gfc_error ("DATA statement at %L has more variables than values",
12675 t
= gfc_check_assign (var
->expr
, values
.vnode
->expr
, 0);
12679 /* If we have more than one element left in the repeat count,
12680 and we have more than one element left in the target variable,
12681 then create a range assignment. */
12682 /* FIXME: Only done for full arrays for now, since array sections
12684 if (mark
== AR_FULL
&& ref
&& ref
->next
== NULL
12685 && mpz_cmp_ui (values
.left
, 1) > 0 && mpz_cmp_ui (size
, 1) > 0)
12689 if (mpz_cmp (size
, values
.left
) >= 0)
12691 mpz_init_set (range
, values
.left
);
12692 mpz_sub (size
, size
, values
.left
);
12693 mpz_set_ui (values
.left
, 0);
12697 mpz_init_set (range
, size
);
12698 mpz_sub (values
.left
, values
.left
, size
);
12699 mpz_set_ui (size
, 0);
12702 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
12705 mpz_add (offset
, offset
, range
);
12712 /* Assign initial value to symbol. */
12715 mpz_sub_ui (values
.left
, values
.left
, 1);
12716 mpz_sub_ui (size
, size
, 1);
12718 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
12723 if (mark
== AR_FULL
)
12724 mpz_add_ui (offset
, offset
, 1);
12726 /* Modify the array section indexes and recalculate the offset
12727 for next element. */
12728 else if (mark
== AR_SECTION
)
12729 gfc_advance_section (section_index
, ar
, &offset
);
12733 if (mark
== AR_SECTION
)
12735 for (i
= 0; i
< ar
->dimen
; i
++)
12736 mpz_clear (section_index
[i
]);
12740 mpz_clear (offset
);
12746 static gfc_try
traverse_data_var (gfc_data_variable
*, locus
*);
12748 /* Iterate over a list of elements in a DATA statement. */
12751 traverse_data_list (gfc_data_variable
*var
, locus
*where
)
12754 iterator_stack frame
;
12755 gfc_expr
*e
, *start
, *end
, *step
;
12756 gfc_try retval
= SUCCESS
;
12758 mpz_init (frame
.value
);
12761 start
= gfc_copy_expr (var
->iter
.start
);
12762 end
= gfc_copy_expr (var
->iter
.end
);
12763 step
= gfc_copy_expr (var
->iter
.step
);
12765 if (gfc_simplify_expr (start
, 1) == FAILURE
12766 || start
->expr_type
!= EXPR_CONSTANT
)
12768 gfc_error ("start of implied-do loop at %L could not be "
12769 "simplified to a constant value", &start
->where
);
12773 if (gfc_simplify_expr (end
, 1) == FAILURE
12774 || end
->expr_type
!= EXPR_CONSTANT
)
12776 gfc_error ("end of implied-do loop at %L could not be "
12777 "simplified to a constant value", &start
->where
);
12781 if (gfc_simplify_expr (step
, 1) == FAILURE
12782 || step
->expr_type
!= EXPR_CONSTANT
)
12784 gfc_error ("step of implied-do loop at %L could not be "
12785 "simplified to a constant value", &start
->where
);
12790 mpz_set (trip
, end
->value
.integer
);
12791 mpz_sub (trip
, trip
, start
->value
.integer
);
12792 mpz_add (trip
, trip
, step
->value
.integer
);
12794 mpz_div (trip
, trip
, step
->value
.integer
);
12796 mpz_set (frame
.value
, start
->value
.integer
);
12798 frame
.prev
= iter_stack
;
12799 frame
.variable
= var
->iter
.var
->symtree
;
12800 iter_stack
= &frame
;
12802 while (mpz_cmp_ui (trip
, 0) > 0)
12804 if (traverse_data_var (var
->list
, where
) == FAILURE
)
12810 e
= gfc_copy_expr (var
->expr
);
12811 if (gfc_simplify_expr (e
, 1) == FAILURE
)
12818 mpz_add (frame
.value
, frame
.value
, step
->value
.integer
);
12820 mpz_sub_ui (trip
, trip
, 1);
12824 mpz_clear (frame
.value
);
12827 gfc_free_expr (start
);
12828 gfc_free_expr (end
);
12829 gfc_free_expr (step
);
12831 iter_stack
= frame
.prev
;
12836 /* Type resolve variables in the variable list of a DATA statement. */
12839 traverse_data_var (gfc_data_variable
*var
, locus
*where
)
12843 for (; var
; var
= var
->next
)
12845 if (var
->expr
== NULL
)
12846 t
= traverse_data_list (var
, where
);
12848 t
= check_data_variable (var
, where
);
12858 /* Resolve the expressions and iterators associated with a data statement.
12859 This is separate from the assignment checking because data lists should
12860 only be resolved once. */
12863 resolve_data_variables (gfc_data_variable
*d
)
12865 for (; d
; d
= d
->next
)
12867 if (d
->list
== NULL
)
12869 if (gfc_resolve_expr (d
->expr
) == FAILURE
)
12874 if (gfc_resolve_iterator (&d
->iter
, false) == FAILURE
)
12877 if (resolve_data_variables (d
->list
) == FAILURE
)
12886 /* Resolve a single DATA statement. We implement this by storing a pointer to
12887 the value list into static variables, and then recursively traversing the
12888 variables list, expanding iterators and such. */
12891 resolve_data (gfc_data
*d
)
12894 if (resolve_data_variables (d
->var
) == FAILURE
)
12897 values
.vnode
= d
->value
;
12898 if (d
->value
== NULL
)
12899 mpz_set_ui (values
.left
, 0);
12901 mpz_set (values
.left
, d
->value
->repeat
);
12903 if (traverse_data_var (d
->var
, &d
->where
) == FAILURE
)
12906 /* At this point, we better not have any values left. */
12908 if (next_data_value () == SUCCESS
)
12909 gfc_error ("DATA statement at %L has more values than variables",
12914 /* 12.6 Constraint: In a pure subprogram any variable which is in common or
12915 accessed by host or use association, is a dummy argument to a pure function,
12916 is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
12917 is storage associated with any such variable, shall not be used in the
12918 following contexts: (clients of this function). */
12920 /* Determines if a variable is not 'pure', i.e., not assignable within a pure
12921 procedure. Returns zero if assignment is OK, nonzero if there is a
12924 gfc_impure_variable (gfc_symbol
*sym
)
12929 if (sym
->attr
.use_assoc
|| sym
->attr
.in_common
)
12932 /* Check if the symbol's ns is inside the pure procedure. */
12933 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
12937 if (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
12941 proc
= sym
->ns
->proc_name
;
12942 if (sym
->attr
.dummy
&& gfc_pure (proc
)
12943 && ((proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_IN
)
12945 proc
->attr
.function
))
12948 /* TODO: Sort out what can be storage associated, if anything, and include
12949 it here. In principle equivalences should be scanned but it does not
12950 seem to be possible to storage associate an impure variable this way. */
12955 /* Test whether a symbol is pure or not. For a NULL pointer, checks if the
12956 current namespace is inside a pure procedure. */
12959 gfc_pure (gfc_symbol
*sym
)
12961 symbol_attribute attr
;
12966 /* Check if the current namespace or one of its parents
12967 belongs to a pure procedure. */
12968 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
12970 sym
= ns
->proc_name
;
12974 if (attr
.flavor
== FL_PROCEDURE
&& attr
.pure
)
12982 return attr
.flavor
== FL_PROCEDURE
&& attr
.pure
;
12986 /* Test whether a symbol is implicitly pure or not. For a NULL pointer,
12987 checks if the current namespace is implicitly pure. Note that this
12988 function returns false for a PURE procedure. */
12991 gfc_implicit_pure (gfc_symbol
*sym
)
12993 symbol_attribute attr
;
12997 /* Check if the current namespace is implicit_pure. */
12998 sym
= gfc_current_ns
->proc_name
;
13002 if (attr
.flavor
== FL_PROCEDURE
13003 && attr
.implicit_pure
&& !attr
.pure
)
13010 return attr
.flavor
== FL_PROCEDURE
&& attr
.implicit_pure
&& !attr
.pure
;
13014 /* Test whether the current procedure is elemental or not. */
13017 gfc_elemental (gfc_symbol
*sym
)
13019 symbol_attribute attr
;
13022 sym
= gfc_current_ns
->proc_name
;
13027 return attr
.flavor
== FL_PROCEDURE
&& attr
.elemental
;
13031 /* Warn about unused labels. */
13034 warn_unused_fortran_label (gfc_st_label
*label
)
13039 warn_unused_fortran_label (label
->left
);
13041 if (label
->defined
== ST_LABEL_UNKNOWN
)
13044 switch (label
->referenced
)
13046 case ST_LABEL_UNKNOWN
:
13047 gfc_warning ("Label %d at %L defined but not used", label
->value
,
13051 case ST_LABEL_BAD_TARGET
:
13052 gfc_warning ("Label %d at %L defined but cannot be used",
13053 label
->value
, &label
->where
);
13060 warn_unused_fortran_label (label
->right
);
13064 /* Returns the sequence type of a symbol or sequence. */
13067 sequence_type (gfc_typespec ts
)
13076 if (ts
.u
.derived
->components
== NULL
)
13077 return SEQ_NONDEFAULT
;
13079 result
= sequence_type (ts
.u
.derived
->components
->ts
);
13080 for (c
= ts
.u
.derived
->components
->next
; c
; c
= c
->next
)
13081 if (sequence_type (c
->ts
) != result
)
13087 if (ts
.kind
!= gfc_default_character_kind
)
13088 return SEQ_NONDEFAULT
;
13090 return SEQ_CHARACTER
;
13093 if (ts
.kind
!= gfc_default_integer_kind
)
13094 return SEQ_NONDEFAULT
;
13096 return SEQ_NUMERIC
;
13099 if (!(ts
.kind
== gfc_default_real_kind
13100 || ts
.kind
== gfc_default_double_kind
))
13101 return SEQ_NONDEFAULT
;
13103 return SEQ_NUMERIC
;
13106 if (ts
.kind
!= gfc_default_complex_kind
)
13107 return SEQ_NONDEFAULT
;
13109 return SEQ_NUMERIC
;
13112 if (ts
.kind
!= gfc_default_logical_kind
)
13113 return SEQ_NONDEFAULT
;
13115 return SEQ_NUMERIC
;
13118 return SEQ_NONDEFAULT
;
13123 /* Resolve derived type EQUIVALENCE object. */
13126 resolve_equivalence_derived (gfc_symbol
*derived
, gfc_symbol
*sym
, gfc_expr
*e
)
13128 gfc_component
*c
= derived
->components
;
13133 /* Shall not be an object of nonsequence derived type. */
13134 if (!derived
->attr
.sequence
)
13136 gfc_error ("Derived type variable '%s' at %L must have SEQUENCE "
13137 "attribute to be an EQUIVALENCE object", sym
->name
,
13142 /* Shall not have allocatable components. */
13143 if (derived
->attr
.alloc_comp
)
13145 gfc_error ("Derived type variable '%s' at %L cannot have ALLOCATABLE "
13146 "components to be an EQUIVALENCE object",sym
->name
,
13151 if (sym
->attr
.in_common
&& gfc_has_default_initializer (sym
->ts
.u
.derived
))
13153 gfc_error ("Derived type variable '%s' at %L with default "
13154 "initialization cannot be in EQUIVALENCE with a variable "
13155 "in COMMON", sym
->name
, &e
->where
);
13159 for (; c
; c
= c
->next
)
13161 if (c
->ts
.type
== BT_DERIVED
13162 && (resolve_equivalence_derived (c
->ts
.u
.derived
, sym
, e
) == FAILURE
))
13165 /* Shall not be an object of sequence derived type containing a pointer
13166 in the structure. */
13167 if (c
->attr
.pointer
)
13169 gfc_error ("Derived type variable '%s' at %L with pointer "
13170 "component(s) cannot be an EQUIVALENCE object",
13171 sym
->name
, &e
->where
);
13179 /* Resolve equivalence object.
13180 An EQUIVALENCE object shall not be a dummy argument, a pointer, a target,
13181 an allocatable array, an object of nonsequence derived type, an object of
13182 sequence derived type containing a pointer at any level of component
13183 selection, an automatic object, a function name, an entry name, a result
13184 name, a named constant, a structure component, or a subobject of any of
13185 the preceding objects. A substring shall not have length zero. A
13186 derived type shall not have components with default initialization nor
13187 shall two objects of an equivalence group be initialized.
13188 Either all or none of the objects shall have an protected attribute.
13189 The simple constraints are done in symbol.c(check_conflict) and the rest
13190 are implemented here. */
13193 resolve_equivalence (gfc_equiv
*eq
)
13196 gfc_symbol
*first_sym
;
13199 locus
*last_where
= NULL
;
13200 seq_type eq_type
, last_eq_type
;
13201 gfc_typespec
*last_ts
;
13202 int object
, cnt_protected
;
13205 last_ts
= &eq
->expr
->symtree
->n
.sym
->ts
;
13207 first_sym
= eq
->expr
->symtree
->n
.sym
;
13211 for (object
= 1; eq
; eq
= eq
->eq
, object
++)
13215 e
->ts
= e
->symtree
->n
.sym
->ts
;
13216 /* match_varspec might not know yet if it is seeing
13217 array reference or substring reference, as it doesn't
13219 if (e
->ref
&& e
->ref
->type
== REF_ARRAY
)
13221 gfc_ref
*ref
= e
->ref
;
13222 sym
= e
->symtree
->n
.sym
;
13224 if (sym
->attr
.dimension
)
13226 ref
->u
.ar
.as
= sym
->as
;
13230 /* For substrings, convert REF_ARRAY into REF_SUBSTRING. */
13231 if (e
->ts
.type
== BT_CHARACTER
13233 && ref
->type
== REF_ARRAY
13234 && ref
->u
.ar
.dimen
== 1
13235 && ref
->u
.ar
.dimen_type
[0] == DIMEN_RANGE
13236 && ref
->u
.ar
.stride
[0] == NULL
)
13238 gfc_expr
*start
= ref
->u
.ar
.start
[0];
13239 gfc_expr
*end
= ref
->u
.ar
.end
[0];
13242 /* Optimize away the (:) reference. */
13243 if (start
== NULL
&& end
== NULL
)
13246 e
->ref
= ref
->next
;
13248 e
->ref
->next
= ref
->next
;
13253 ref
->type
= REF_SUBSTRING
;
13255 start
= gfc_get_int_expr (gfc_default_integer_kind
,
13257 ref
->u
.ss
.start
= start
;
13258 if (end
== NULL
&& e
->ts
.u
.cl
)
13259 end
= gfc_copy_expr (e
->ts
.u
.cl
->length
);
13260 ref
->u
.ss
.end
= end
;
13261 ref
->u
.ss
.length
= e
->ts
.u
.cl
;
13268 /* Any further ref is an error. */
13271 gcc_assert (ref
->type
== REF_ARRAY
);
13272 gfc_error ("Syntax error in EQUIVALENCE statement at %L",
13278 if (gfc_resolve_expr (e
) == FAILURE
)
13281 sym
= e
->symtree
->n
.sym
;
13283 if (sym
->attr
.is_protected
)
13285 if (cnt_protected
> 0 && cnt_protected
!= object
)
13287 gfc_error ("Either all or none of the objects in the "
13288 "EQUIVALENCE set at %L shall have the "
13289 "PROTECTED attribute",
13294 /* Shall not equivalence common block variables in a PURE procedure. */
13295 if (sym
->ns
->proc_name
13296 && sym
->ns
->proc_name
->attr
.pure
13297 && sym
->attr
.in_common
)
13299 gfc_error ("Common block member '%s' at %L cannot be an EQUIVALENCE "
13300 "object in the pure procedure '%s'",
13301 sym
->name
, &e
->where
, sym
->ns
->proc_name
->name
);
13305 /* Shall not be a named constant. */
13306 if (e
->expr_type
== EXPR_CONSTANT
)
13308 gfc_error ("Named constant '%s' at %L cannot be an EQUIVALENCE "
13309 "object", sym
->name
, &e
->where
);
13313 if (e
->ts
.type
== BT_DERIVED
13314 && resolve_equivalence_derived (e
->ts
.u
.derived
, sym
, e
) == FAILURE
)
13317 /* Check that the types correspond correctly:
13319 A numeric sequence structure may be equivalenced to another sequence
13320 structure, an object of default integer type, default real type, double
13321 precision real type, default logical type such that components of the
13322 structure ultimately only become associated to objects of the same
13323 kind. A character sequence structure may be equivalenced to an object
13324 of default character kind or another character sequence structure.
13325 Other objects may be equivalenced only to objects of the same type and
13326 kind parameters. */
13328 /* Identical types are unconditionally OK. */
13329 if (object
== 1 || gfc_compare_types (last_ts
, &sym
->ts
))
13330 goto identical_types
;
13332 last_eq_type
= sequence_type (*last_ts
);
13333 eq_type
= sequence_type (sym
->ts
);
13335 /* Since the pair of objects is not of the same type, mixed or
13336 non-default sequences can be rejected. */
13338 msg
= "Sequence %s with mixed components in EQUIVALENCE "
13339 "statement at %L with different type objects";
13341 && last_eq_type
== SEQ_MIXED
13342 && gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
)
13344 || (eq_type
== SEQ_MIXED
13345 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
13346 &e
->where
) == FAILURE
))
13349 msg
= "Non-default type object or sequence %s in EQUIVALENCE "
13350 "statement at %L with objects of different type";
13352 && last_eq_type
== SEQ_NONDEFAULT
13353 && gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
,
13354 last_where
) == FAILURE
)
13355 || (eq_type
== SEQ_NONDEFAULT
13356 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
13357 &e
->where
) == FAILURE
))
13360 msg
="Non-CHARACTER object '%s' in default CHARACTER "
13361 "EQUIVALENCE statement at %L";
13362 if (last_eq_type
== SEQ_CHARACTER
13363 && eq_type
!= SEQ_CHARACTER
13364 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
13365 &e
->where
) == FAILURE
)
13368 msg
="Non-NUMERIC object '%s' in default NUMERIC "
13369 "EQUIVALENCE statement at %L";
13370 if (last_eq_type
== SEQ_NUMERIC
13371 && eq_type
!= SEQ_NUMERIC
13372 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
13373 &e
->where
) == FAILURE
)
13378 last_where
= &e
->where
;
13383 /* Shall not be an automatic array. */
13384 if (e
->ref
->type
== REF_ARRAY
13385 && gfc_resolve_array_spec (e
->ref
->u
.ar
.as
, 1) == FAILURE
)
13387 gfc_error ("Array '%s' at %L with non-constant bounds cannot be "
13388 "an EQUIVALENCE object", sym
->name
, &e
->where
);
13395 /* Shall not be a structure component. */
13396 if (r
->type
== REF_COMPONENT
)
13398 gfc_error ("Structure component '%s' at %L cannot be an "
13399 "EQUIVALENCE object",
13400 r
->u
.c
.component
->name
, &e
->where
);
13404 /* A substring shall not have length zero. */
13405 if (r
->type
== REF_SUBSTRING
)
13407 if (compare_bound (r
->u
.ss
.start
, r
->u
.ss
.end
) == CMP_GT
)
13409 gfc_error ("Substring at %L has length zero",
13410 &r
->u
.ss
.start
->where
);
13420 /* Resolve function and ENTRY types, issue diagnostics if needed. */
13423 resolve_fntype (gfc_namespace
*ns
)
13425 gfc_entry_list
*el
;
13428 if (ns
->proc_name
== NULL
|| !ns
->proc_name
->attr
.function
)
13431 /* If there are any entries, ns->proc_name is the entry master
13432 synthetic symbol and ns->entries->sym actual FUNCTION symbol. */
13434 sym
= ns
->entries
->sym
;
13436 sym
= ns
->proc_name
;
13437 if (sym
->result
== sym
13438 && sym
->ts
.type
== BT_UNKNOWN
13439 && gfc_set_default_type (sym
, 0, NULL
) == FAILURE
13440 && !sym
->attr
.untyped
)
13442 gfc_error ("Function '%s' at %L has no IMPLICIT type",
13443 sym
->name
, &sym
->declared_at
);
13444 sym
->attr
.untyped
= 1;
13447 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->ts
.u
.derived
->attr
.use_assoc
13448 && !sym
->attr
.contained
13449 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
13450 && gfc_check_symbol_access (sym
))
13452 gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: PUBLIC function '%s' at "
13453 "%L of PRIVATE type '%s'", sym
->name
,
13454 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
13458 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
13460 if (el
->sym
->result
== el
->sym
13461 && el
->sym
->ts
.type
== BT_UNKNOWN
13462 && gfc_set_default_type (el
->sym
, 0, NULL
) == FAILURE
13463 && !el
->sym
->attr
.untyped
)
13465 gfc_error ("ENTRY '%s' at %L has no IMPLICIT type",
13466 el
->sym
->name
, &el
->sym
->declared_at
);
13467 el
->sym
->attr
.untyped
= 1;
13473 /* 12.3.2.1.1 Defined operators. */
13476 check_uop_procedure (gfc_symbol
*sym
, locus where
)
13478 gfc_formal_arglist
*formal
;
13480 if (!sym
->attr
.function
)
13482 gfc_error ("User operator procedure '%s' at %L must be a FUNCTION",
13483 sym
->name
, &where
);
13487 if (sym
->ts
.type
== BT_CHARACTER
13488 && !(sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
)
13489 && !(sym
->result
&& sym
->result
->ts
.u
.cl
13490 && sym
->result
->ts
.u
.cl
->length
))
13492 gfc_error ("User operator procedure '%s' at %L cannot be assumed "
13493 "character length", sym
->name
, &where
);
13497 formal
= sym
->formal
;
13498 if (!formal
|| !formal
->sym
)
13500 gfc_error ("User operator procedure '%s' at %L must have at least "
13501 "one argument", sym
->name
, &where
);
13505 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
13507 gfc_error ("First argument of operator interface at %L must be "
13508 "INTENT(IN)", &where
);
13512 if (formal
->sym
->attr
.optional
)
13514 gfc_error ("First argument of operator interface at %L cannot be "
13515 "optional", &where
);
13519 formal
= formal
->next
;
13520 if (!formal
|| !formal
->sym
)
13523 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
13525 gfc_error ("Second argument of operator interface at %L must be "
13526 "INTENT(IN)", &where
);
13530 if (formal
->sym
->attr
.optional
)
13532 gfc_error ("Second argument of operator interface at %L cannot be "
13533 "optional", &where
);
13539 gfc_error ("Operator interface at %L must have, at most, two "
13540 "arguments", &where
);
13548 gfc_resolve_uops (gfc_symtree
*symtree
)
13550 gfc_interface
*itr
;
13552 if (symtree
== NULL
)
13555 gfc_resolve_uops (symtree
->left
);
13556 gfc_resolve_uops (symtree
->right
);
13558 for (itr
= symtree
->n
.uop
->op
; itr
; itr
= itr
->next
)
13559 check_uop_procedure (itr
->sym
, itr
->sym
->declared_at
);
13563 /* Examine all of the expressions associated with a program unit,
13564 assign types to all intermediate expressions, make sure that all
13565 assignments are to compatible types and figure out which names
13566 refer to which functions or subroutines. It doesn't check code
13567 block, which is handled by resolve_code. */
13570 resolve_types (gfc_namespace
*ns
)
13576 gfc_namespace
* old_ns
= gfc_current_ns
;
13578 /* Check that all IMPLICIT types are ok. */
13579 if (!ns
->seen_implicit_none
)
13582 for (letter
= 0; letter
!= GFC_LETTERS
; ++letter
)
13583 if (ns
->set_flag
[letter
]
13584 && resolve_typespec_used (&ns
->default_type
[letter
],
13585 &ns
->implicit_loc
[letter
],
13590 gfc_current_ns
= ns
;
13592 resolve_entries (ns
);
13594 resolve_common_vars (ns
->blank_common
.head
, false);
13595 resolve_common_blocks (ns
->common_root
);
13597 resolve_contained_functions (ns
);
13599 if (ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
13600 && ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
13601 resolve_formal_arglist (ns
->proc_name
);
13603 gfc_traverse_ns (ns
, resolve_bind_c_derived_types
);
13605 for (cl
= ns
->cl_list
; cl
; cl
= cl
->next
)
13606 resolve_charlen (cl
);
13608 gfc_traverse_ns (ns
, resolve_symbol
);
13610 resolve_fntype (ns
);
13612 for (n
= ns
->contained
; n
; n
= n
->sibling
)
13614 if (gfc_pure (ns
->proc_name
) && !gfc_pure (n
->proc_name
))
13615 gfc_error ("Contained procedure '%s' at %L of a PURE procedure must "
13616 "also be PURE", n
->proc_name
->name
,
13617 &n
->proc_name
->declared_at
);
13623 do_concurrent_flag
= 0;
13624 gfc_check_interfaces (ns
);
13626 gfc_traverse_ns (ns
, resolve_values
);
13632 for (d
= ns
->data
; d
; d
= d
->next
)
13636 gfc_traverse_ns (ns
, gfc_formalize_init_value
);
13638 gfc_traverse_ns (ns
, gfc_verify_binding_labels
);
13640 if (ns
->common_root
!= NULL
)
13641 gfc_traverse_symtree (ns
->common_root
, resolve_bind_c_comms
);
13643 for (eq
= ns
->equiv
; eq
; eq
= eq
->next
)
13644 resolve_equivalence (eq
);
13646 /* Warn about unused labels. */
13647 if (warn_unused_label
)
13648 warn_unused_fortran_label (ns
->st_labels
);
13650 gfc_resolve_uops (ns
->uop_root
);
13652 gfc_current_ns
= old_ns
;
13656 /* Call resolve_code recursively. */
13659 resolve_codes (gfc_namespace
*ns
)
13662 bitmap_obstack old_obstack
;
13664 if (ns
->resolved
== 1)
13667 for (n
= ns
->contained
; n
; n
= n
->sibling
)
13670 gfc_current_ns
= ns
;
13672 /* Don't clear 'cs_base' if this is the namespace of a BLOCK construct. */
13673 if (!(ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_LABEL
))
13676 /* Set to an out of range value. */
13677 current_entry_id
= -1;
13679 old_obstack
= labels_obstack
;
13680 bitmap_obstack_initialize (&labels_obstack
);
13682 resolve_code (ns
->code
, ns
);
13684 bitmap_obstack_release (&labels_obstack
);
13685 labels_obstack
= old_obstack
;
13689 /* This function is called after a complete program unit has been compiled.
13690 Its purpose is to examine all of the expressions associated with a program
13691 unit, assign types to all intermediate expressions, make sure that all
13692 assignments are to compatible types and figure out which names refer to
13693 which functions or subroutines. */
13696 gfc_resolve (gfc_namespace
*ns
)
13698 gfc_namespace
*old_ns
;
13699 code_stack
*old_cs_base
;
13705 old_ns
= gfc_current_ns
;
13706 old_cs_base
= cs_base
;
13708 resolve_types (ns
);
13709 resolve_codes (ns
);
13711 gfc_current_ns
= old_ns
;
13712 cs_base
= old_cs_base
;
13715 gfc_run_passes (ns
);