1 /* Perform type resolution on the various structures.
2 Copyright (C) 2001-2016 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 #include "arith.h" /* For gfc_compare_expr(). */
28 #include "dependency.h"
30 #include "target-memory.h" /* for gfc_simplify_transfer */
31 #include "constructor.h"
33 /* Types used in equivalence statements. */
37 SEQ_NONDEFAULT
, SEQ_NUMERIC
, SEQ_CHARACTER
, SEQ_MIXED
40 /* Stack to keep track of the nesting of blocks as we move through the
41 code. See resolve_branch() and gfc_resolve_code(). */
43 typedef struct code_stack
45 struct gfc_code
*head
, *current
;
46 struct code_stack
*prev
;
48 /* This bitmap keeps track of the targets valid for a branch from
49 inside this block except for END {IF|SELECT}s of enclosing
51 bitmap reachable_labels
;
55 static code_stack
*cs_base
= NULL
;
58 /* Nonzero if we're inside a FORALL or DO CONCURRENT block. */
60 static int forall_flag
;
61 int gfc_do_concurrent_flag
;
63 /* True when we are resolving an expression that is an actual argument to
65 static bool actual_arg
= false;
66 /* True when we are resolving an expression that is the first actual argument
68 static bool first_actual_arg
= false;
71 /* Nonzero if we're inside a OpenMP WORKSHARE or PARALLEL WORKSHARE block. */
73 static int omp_workshare_flag
;
75 /* Nonzero if we are processing a formal arglist. The corresponding function
76 resets the flag each time that it is read. */
77 static int formal_arg_flag
= 0;
79 /* True if we are resolving a specification expression. */
80 static bool specification_expr
= false;
82 /* The id of the last entry seen. */
83 static int current_entry_id
;
85 /* We use bitmaps to determine if a branch target is valid. */
86 static bitmap_obstack labels_obstack
;
88 /* True when simplifying a EXPR_VARIABLE argument to an inquiry function. */
89 static bool inquiry_argument
= false;
93 gfc_is_formal_arg (void)
95 return formal_arg_flag
;
98 /* Is the symbol host associated? */
100 is_sym_host_assoc (gfc_symbol
*sym
, gfc_namespace
*ns
)
102 for (ns
= ns
->parent
; ns
; ns
= ns
->parent
)
111 /* Ensure a typespec used is valid; for instance, TYPE(t) is invalid if t is
112 an ABSTRACT derived-type. If where is not NULL, an error message with that
113 locus is printed, optionally using name. */
116 resolve_typespec_used (gfc_typespec
* ts
, locus
* where
, const char* name
)
118 if (ts
->type
== BT_DERIVED
&& ts
->u
.derived
->attr
.abstract
)
123 gfc_error ("%qs at %L is of the ABSTRACT type %qs",
124 name
, where
, ts
->u
.derived
->name
);
126 gfc_error ("ABSTRACT type %qs used at %L",
127 ts
->u
.derived
->name
, where
);
138 check_proc_interface (gfc_symbol
*ifc
, locus
*where
)
140 /* Several checks for F08:C1216. */
141 if (ifc
->attr
.procedure
)
143 gfc_error ("Interface %qs at %L is declared "
144 "in a later PROCEDURE statement", ifc
->name
, where
);
149 /* For generic interfaces, check if there is
150 a specific procedure with the same name. */
151 gfc_interface
*gen
= ifc
->generic
;
152 while (gen
&& strcmp (gen
->sym
->name
, ifc
->name
) != 0)
156 gfc_error ("Interface %qs at %L may not be generic",
161 if (ifc
->attr
.proc
== PROC_ST_FUNCTION
)
163 gfc_error ("Interface %qs at %L may not be a statement function",
167 if (gfc_is_intrinsic (ifc
, 0, ifc
->declared_at
)
168 || gfc_is_intrinsic (ifc
, 1, ifc
->declared_at
))
169 ifc
->attr
.intrinsic
= 1;
170 if (ifc
->attr
.intrinsic
&& !gfc_intrinsic_actual_ok (ifc
->name
, 0))
172 gfc_error ("Intrinsic procedure %qs not allowed in "
173 "PROCEDURE statement at %L", ifc
->name
, where
);
176 if (!ifc
->attr
.if_source
&& !ifc
->attr
.intrinsic
&& ifc
->name
[0] != '\0')
178 gfc_error ("Interface %qs at %L must be explicit", ifc
->name
, where
);
185 static void resolve_symbol (gfc_symbol
*sym
);
188 /* Resolve the interface for a PROCEDURE declaration or procedure pointer. */
191 resolve_procedure_interface (gfc_symbol
*sym
)
193 gfc_symbol
*ifc
= sym
->ts
.interface
;
200 gfc_error ("PROCEDURE %qs at %L may not be used as its own interface",
201 sym
->name
, &sym
->declared_at
);
204 if (!check_proc_interface (ifc
, &sym
->declared_at
))
207 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
209 /* Resolve interface and copy attributes. */
210 resolve_symbol (ifc
);
211 if (ifc
->attr
.intrinsic
)
212 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
216 sym
->ts
= ifc
->result
->ts
;
221 sym
->ts
.interface
= ifc
;
222 sym
->attr
.function
= ifc
->attr
.function
;
223 sym
->attr
.subroutine
= ifc
->attr
.subroutine
;
225 sym
->attr
.allocatable
= ifc
->attr
.allocatable
;
226 sym
->attr
.pointer
= ifc
->attr
.pointer
;
227 sym
->attr
.pure
= ifc
->attr
.pure
;
228 sym
->attr
.elemental
= ifc
->attr
.elemental
;
229 sym
->attr
.dimension
= ifc
->attr
.dimension
;
230 sym
->attr
.contiguous
= ifc
->attr
.contiguous
;
231 sym
->attr
.recursive
= ifc
->attr
.recursive
;
232 sym
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
233 sym
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
234 sym
->attr
.is_bind_c
= ifc
->attr
.is_bind_c
;
235 sym
->attr
.class_ok
= ifc
->attr
.class_ok
;
236 /* Copy array spec. */
237 sym
->as
= gfc_copy_array_spec (ifc
->as
);
238 /* Copy char length. */
239 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
241 sym
->ts
.u
.cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
242 if (sym
->ts
.u
.cl
->length
&& !sym
->ts
.u
.cl
->resolved
243 && !gfc_resolve_expr (sym
->ts
.u
.cl
->length
))
252 /* Resolve types of formal argument lists. These have to be done early so that
253 the formal argument lists of module procedures can be copied to the
254 containing module before the individual procedures are resolved
255 individually. We also resolve argument lists of procedures in interface
256 blocks because they are self-contained scoping units.
258 Since a dummy argument cannot be a non-dummy procedure, the only
259 resort left for untyped names are the IMPLICIT types. */
262 resolve_formal_arglist (gfc_symbol
*proc
)
264 gfc_formal_arglist
*f
;
266 bool saved_specification_expr
;
269 if (proc
->result
!= NULL
)
274 if (gfc_elemental (proc
)
275 || sym
->attr
.pointer
|| sym
->attr
.allocatable
276 || (sym
->as
&& sym
->as
->rank
!= 0))
278 proc
->attr
.always_explicit
= 1;
279 sym
->attr
.always_explicit
= 1;
284 for (f
= proc
->formal
; f
; f
= f
->next
)
292 /* Alternate return placeholder. */
293 if (gfc_elemental (proc
))
294 gfc_error ("Alternate return specifier in elemental subroutine "
295 "%qs at %L is not allowed", proc
->name
,
297 if (proc
->attr
.function
)
298 gfc_error ("Alternate return specifier in function "
299 "%qs at %L is not allowed", proc
->name
,
303 else if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
304 && !resolve_procedure_interface (sym
))
307 if (strcmp (proc
->name
, sym
->name
) == 0)
309 gfc_error ("Self-referential argument "
310 "%qs at %L is not allowed", sym
->name
,
315 if (sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
316 resolve_formal_arglist (sym
);
318 if (sym
->attr
.subroutine
|| sym
->attr
.external
)
320 if (sym
->attr
.flavor
== FL_UNKNOWN
)
321 gfc_add_flavor (&sym
->attr
, FL_PROCEDURE
, sym
->name
, &sym
->declared_at
);
325 if (sym
->ts
.type
== BT_UNKNOWN
&& !proc
->attr
.intrinsic
326 && (!sym
->attr
.function
|| sym
->result
== sym
))
327 gfc_set_default_type (sym
, 1, sym
->ns
);
330 as
= sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
331 ? CLASS_DATA (sym
)->as
: sym
->as
;
333 saved_specification_expr
= specification_expr
;
334 specification_expr
= true;
335 gfc_resolve_array_spec (as
, 0);
336 specification_expr
= saved_specification_expr
;
338 /* We can't tell if an array with dimension (:) is assumed or deferred
339 shape until we know if it has the pointer or allocatable attributes.
341 if (as
&& as
->rank
> 0 && as
->type
== AS_DEFERRED
342 && ((sym
->ts
.type
!= BT_CLASS
343 && !(sym
->attr
.pointer
|| sym
->attr
.allocatable
))
344 || (sym
->ts
.type
== BT_CLASS
345 && !(CLASS_DATA (sym
)->attr
.class_pointer
346 || CLASS_DATA (sym
)->attr
.allocatable
)))
347 && sym
->attr
.flavor
!= FL_PROCEDURE
)
349 as
->type
= AS_ASSUMED_SHAPE
;
350 for (i
= 0; i
< as
->rank
; i
++)
351 as
->lower
[i
] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
354 if ((as
&& as
->rank
> 0 && as
->type
== AS_ASSUMED_SHAPE
)
355 || (as
&& as
->type
== AS_ASSUMED_RANK
)
356 || sym
->attr
.pointer
|| sym
->attr
.allocatable
|| sym
->attr
.target
357 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
358 && (CLASS_DATA (sym
)->attr
.class_pointer
359 || CLASS_DATA (sym
)->attr
.allocatable
360 || CLASS_DATA (sym
)->attr
.target
))
361 || sym
->attr
.optional
)
363 proc
->attr
.always_explicit
= 1;
365 proc
->result
->attr
.always_explicit
= 1;
368 /* If the flavor is unknown at this point, it has to be a variable.
369 A procedure specification would have already set the type. */
371 if (sym
->attr
.flavor
== FL_UNKNOWN
)
372 gfc_add_flavor (&sym
->attr
, FL_VARIABLE
, sym
->name
, &sym
->declared_at
);
376 if (sym
->attr
.flavor
== FL_PROCEDURE
)
381 gfc_error ("Dummy procedure %qs of PURE procedure at %L must "
382 "also be PURE", sym
->name
, &sym
->declared_at
);
386 else if (!sym
->attr
.pointer
)
388 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
)
391 gfc_notify_std (GFC_STD_F2008
, "Argument %qs"
392 " of pure function %qs at %L with VALUE "
393 "attribute but without INTENT(IN)",
394 sym
->name
, proc
->name
, &sym
->declared_at
);
396 gfc_error ("Argument %qs of pure function %qs at %L must "
397 "be INTENT(IN) or VALUE", sym
->name
, proc
->name
,
401 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
)
404 gfc_notify_std (GFC_STD_F2008
, "Argument %qs"
405 " of pure subroutine %qs at %L with VALUE "
406 "attribute but without INTENT", sym
->name
,
407 proc
->name
, &sym
->declared_at
);
409 gfc_error ("Argument %qs of pure subroutine %qs at %L "
410 "must have its INTENT specified or have the "
411 "VALUE attribute", sym
->name
, proc
->name
,
417 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.intent
== INTENT_OUT
)
419 gfc_error ("INTENT(OUT) argument %qs of pure procedure %qs at %L"
420 " may not be polymorphic", sym
->name
, proc
->name
,
426 if (proc
->attr
.implicit_pure
)
428 if (sym
->attr
.flavor
== FL_PROCEDURE
)
431 proc
->attr
.implicit_pure
= 0;
433 else if (!sym
->attr
.pointer
)
435 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
437 proc
->attr
.implicit_pure
= 0;
439 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
441 proc
->attr
.implicit_pure
= 0;
445 if (gfc_elemental (proc
))
448 if (sym
->attr
.codimension
449 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
450 && CLASS_DATA (sym
)->attr
.codimension
))
452 gfc_error ("Coarray dummy argument %qs at %L to elemental "
453 "procedure", sym
->name
, &sym
->declared_at
);
457 if (sym
->as
|| (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
458 && CLASS_DATA (sym
)->as
))
460 gfc_error ("Argument %qs of elemental procedure at %L must "
461 "be scalar", sym
->name
, &sym
->declared_at
);
465 if (sym
->attr
.allocatable
466 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
467 && CLASS_DATA (sym
)->attr
.allocatable
))
469 gfc_error ("Argument %qs of elemental procedure at %L cannot "
470 "have the ALLOCATABLE attribute", sym
->name
,
475 if (sym
->attr
.pointer
476 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
477 && CLASS_DATA (sym
)->attr
.class_pointer
))
479 gfc_error ("Argument %qs of elemental procedure at %L cannot "
480 "have the POINTER attribute", sym
->name
,
485 if (sym
->attr
.flavor
== FL_PROCEDURE
)
487 gfc_error ("Dummy procedure %qs not allowed in elemental "
488 "procedure %qs at %L", sym
->name
, proc
->name
,
493 /* Fortran 2008 Corrigendum 1, C1290a. */
494 if (sym
->attr
.intent
== INTENT_UNKNOWN
&& !sym
->attr
.value
)
496 gfc_error ("Argument %qs of elemental procedure %qs at %L must "
497 "have its INTENT specified or have the VALUE "
498 "attribute", sym
->name
, proc
->name
,
504 /* Each dummy shall be specified to be scalar. */
505 if (proc
->attr
.proc
== PROC_ST_FUNCTION
)
509 gfc_error ("Argument %qs of statement function at %L must "
510 "be scalar", sym
->name
, &sym
->declared_at
);
514 if (sym
->ts
.type
== BT_CHARACTER
)
516 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
517 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
519 gfc_error ("Character-valued argument %qs of statement "
520 "function at %L must have constant length",
521 sym
->name
, &sym
->declared_at
);
531 /* Work function called when searching for symbols that have argument lists
532 associated with them. */
535 find_arglists (gfc_symbol
*sym
)
537 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
|| sym
->ns
!= gfc_current_ns
538 || gfc_fl_struct (sym
->attr
.flavor
) || sym
->attr
.intrinsic
)
541 resolve_formal_arglist (sym
);
545 /* Given a namespace, resolve all formal argument lists within the namespace.
549 resolve_formal_arglists (gfc_namespace
*ns
)
554 gfc_traverse_ns (ns
, find_arglists
);
559 resolve_contained_fntype (gfc_symbol
*sym
, gfc_namespace
*ns
)
563 /* If this namespace is not a function or an entry master function,
565 if (! sym
|| !(sym
->attr
.function
|| sym
->attr
.flavor
== FL_VARIABLE
)
566 || sym
->attr
.entry_master
)
569 /* Try to find out of what the return type is. */
570 if (sym
->result
->ts
.type
== BT_UNKNOWN
&& sym
->result
->ts
.interface
== NULL
)
572 t
= gfc_set_default_type (sym
->result
, 0, ns
);
574 if (!t
&& !sym
->result
->attr
.untyped
)
576 if (sym
->result
== sym
)
577 gfc_error ("Contained function %qs at %L has no IMPLICIT type",
578 sym
->name
, &sym
->declared_at
);
579 else if (!sym
->result
->attr
.proc_pointer
)
580 gfc_error ("Result %qs of contained function %qs at %L has "
581 "no IMPLICIT type", sym
->result
->name
, sym
->name
,
582 &sym
->result
->declared_at
);
583 sym
->result
->attr
.untyped
= 1;
587 /* Fortran 95 Draft Standard, page 51, Section 5.1.1.5, on the Character
588 type, lists the only ways a character length value of * can be used:
589 dummy arguments of procedures, named constants, and function results
590 in external functions. Internal function results and results of module
591 procedures are not on this list, ergo, not permitted. */
593 if (sym
->result
->ts
.type
== BT_CHARACTER
)
595 gfc_charlen
*cl
= sym
->result
->ts
.u
.cl
;
596 if ((!cl
|| !cl
->length
) && !sym
->result
->ts
.deferred
)
598 /* See if this is a module-procedure and adapt error message
601 gcc_assert (ns
->parent
&& ns
->parent
->proc_name
);
602 module_proc
= (ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
);
604 gfc_error ("Character-valued %s %qs at %L must not be"
606 module_proc
? _("module procedure")
607 : _("internal function"),
608 sym
->name
, &sym
->declared_at
);
614 /* Add NEW_ARGS to the formal argument list of PROC, taking care not to
615 introduce duplicates. */
618 merge_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
620 gfc_formal_arglist
*f
, *new_arglist
;
623 for (; new_args
!= NULL
; new_args
= new_args
->next
)
625 new_sym
= new_args
->sym
;
626 /* See if this arg is already in the formal argument list. */
627 for (f
= proc
->formal
; f
; f
= f
->next
)
629 if (new_sym
== f
->sym
)
636 /* Add a new argument. Argument order is not important. */
637 new_arglist
= gfc_get_formal_arglist ();
638 new_arglist
->sym
= new_sym
;
639 new_arglist
->next
= proc
->formal
;
640 proc
->formal
= new_arglist
;
645 /* Flag the arguments that are not present in all entries. */
648 check_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
650 gfc_formal_arglist
*f
, *head
;
653 for (f
= proc
->formal
; f
; f
= f
->next
)
658 for (new_args
= head
; new_args
; new_args
= new_args
->next
)
660 if (new_args
->sym
== f
->sym
)
667 f
->sym
->attr
.not_always_present
= 1;
672 /* Resolve alternate entry points. If a symbol has multiple entry points we
673 create a new master symbol for the main routine, and turn the existing
674 symbol into an entry point. */
677 resolve_entries (gfc_namespace
*ns
)
679 gfc_namespace
*old_ns
;
683 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
684 static int master_count
= 0;
686 if (ns
->proc_name
== NULL
)
689 /* No need to do anything if this procedure doesn't have alternate entry
694 /* We may already have resolved alternate entry points. */
695 if (ns
->proc_name
->attr
.entry_master
)
698 /* If this isn't a procedure something has gone horribly wrong. */
699 gcc_assert (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
);
701 /* Remember the current namespace. */
702 old_ns
= gfc_current_ns
;
706 /* Add the main entry point to the list of entry points. */
707 el
= gfc_get_entry_list ();
708 el
->sym
= ns
->proc_name
;
710 el
->next
= ns
->entries
;
712 ns
->proc_name
->attr
.entry
= 1;
714 /* If it is a module function, it needs to be in the right namespace
715 so that gfc_get_fake_result_decl can gather up the results. The
716 need for this arose in get_proc_name, where these beasts were
717 left in their own namespace, to keep prior references linked to
718 the entry declaration.*/
719 if (ns
->proc_name
->attr
.function
720 && ns
->parent
&& ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
723 /* Do the same for entries where the master is not a module
724 procedure. These are retained in the module namespace because
725 of the module procedure declaration. */
726 for (el
= el
->next
; el
; el
= el
->next
)
727 if (el
->sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
728 && el
->sym
->attr
.mod_proc
)
732 /* Add an entry statement for it. */
733 c
= gfc_get_code (EXEC_ENTRY
);
738 /* Create a new symbol for the master function. */
739 /* Give the internal function a unique name (within this file).
740 Also include the function name so the user has some hope of figuring
741 out what is going on. */
742 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "master.%d.%s",
743 master_count
++, ns
->proc_name
->name
);
744 gfc_get_ha_symbol (name
, &proc
);
745 gcc_assert (proc
!= NULL
);
747 gfc_add_procedure (&proc
->attr
, PROC_INTERNAL
, proc
->name
, NULL
);
748 if (ns
->proc_name
->attr
.subroutine
)
749 gfc_add_subroutine (&proc
->attr
, proc
->name
, NULL
);
753 gfc_typespec
*ts
, *fts
;
754 gfc_array_spec
*as
, *fas
;
755 gfc_add_function (&proc
->attr
, proc
->name
, NULL
);
757 fas
= ns
->entries
->sym
->as
;
758 fas
= fas
? fas
: ns
->entries
->sym
->result
->as
;
759 fts
= &ns
->entries
->sym
->result
->ts
;
760 if (fts
->type
== BT_UNKNOWN
)
761 fts
= gfc_get_default_type (ns
->entries
->sym
->result
->name
, NULL
);
762 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
764 ts
= &el
->sym
->result
->ts
;
766 as
= as
? as
: el
->sym
->result
->as
;
767 if (ts
->type
== BT_UNKNOWN
)
768 ts
= gfc_get_default_type (el
->sym
->result
->name
, NULL
);
770 if (! gfc_compare_types (ts
, fts
)
771 || (el
->sym
->result
->attr
.dimension
772 != ns
->entries
->sym
->result
->attr
.dimension
)
773 || (el
->sym
->result
->attr
.pointer
774 != ns
->entries
->sym
->result
->attr
.pointer
))
776 else if (as
&& fas
&& ns
->entries
->sym
->result
!= el
->sym
->result
777 && gfc_compare_array_spec (as
, fas
) == 0)
778 gfc_error ("Function %s at %L has entries with mismatched "
779 "array specifications", ns
->entries
->sym
->name
,
780 &ns
->entries
->sym
->declared_at
);
781 /* The characteristics need to match and thus both need to have
782 the same string length, i.e. both len=*, or both len=4.
783 Having both len=<variable> is also possible, but difficult to
784 check at compile time. */
785 else if (ts
->type
== BT_CHARACTER
&& ts
->u
.cl
&& fts
->u
.cl
786 && (((ts
->u
.cl
->length
&& !fts
->u
.cl
->length
)
787 ||(!ts
->u
.cl
->length
&& fts
->u
.cl
->length
))
789 && ts
->u
.cl
->length
->expr_type
790 != fts
->u
.cl
->length
->expr_type
)
792 && ts
->u
.cl
->length
->expr_type
== EXPR_CONSTANT
793 && mpz_cmp (ts
->u
.cl
->length
->value
.integer
,
794 fts
->u
.cl
->length
->value
.integer
) != 0)))
795 gfc_notify_std (GFC_STD_GNU
, "Function %s at %L with "
796 "entries returning variables of different "
797 "string lengths", ns
->entries
->sym
->name
,
798 &ns
->entries
->sym
->declared_at
);
803 sym
= ns
->entries
->sym
->result
;
804 /* All result types the same. */
806 if (sym
->attr
.dimension
)
807 gfc_set_array_spec (proc
, gfc_copy_array_spec (sym
->as
), NULL
);
808 if (sym
->attr
.pointer
)
809 gfc_add_pointer (&proc
->attr
, NULL
);
813 /* Otherwise the result will be passed through a union by
815 proc
->attr
.mixed_entry_master
= 1;
816 for (el
= ns
->entries
; el
; el
= el
->next
)
818 sym
= el
->sym
->result
;
819 if (sym
->attr
.dimension
)
821 if (el
== ns
->entries
)
822 gfc_error ("FUNCTION result %s can't be an array in "
823 "FUNCTION %s at %L", sym
->name
,
824 ns
->entries
->sym
->name
, &sym
->declared_at
);
826 gfc_error ("ENTRY result %s can't be an array in "
827 "FUNCTION %s at %L", sym
->name
,
828 ns
->entries
->sym
->name
, &sym
->declared_at
);
830 else if (sym
->attr
.pointer
)
832 if (el
== ns
->entries
)
833 gfc_error ("FUNCTION result %s can't be a POINTER in "
834 "FUNCTION %s at %L", sym
->name
,
835 ns
->entries
->sym
->name
, &sym
->declared_at
);
837 gfc_error ("ENTRY result %s can't be a POINTER in "
838 "FUNCTION %s at %L", sym
->name
,
839 ns
->entries
->sym
->name
, &sym
->declared_at
);
844 if (ts
->type
== BT_UNKNOWN
)
845 ts
= gfc_get_default_type (sym
->name
, NULL
);
849 if (ts
->kind
== gfc_default_integer_kind
)
853 if (ts
->kind
== gfc_default_real_kind
854 || ts
->kind
== gfc_default_double_kind
)
858 if (ts
->kind
== gfc_default_complex_kind
)
862 if (ts
->kind
== gfc_default_logical_kind
)
866 /* We will issue error elsewhere. */
874 if (el
== ns
->entries
)
875 gfc_error ("FUNCTION result %s can't be of type %s "
876 "in FUNCTION %s at %L", sym
->name
,
877 gfc_typename (ts
), ns
->entries
->sym
->name
,
880 gfc_error ("ENTRY result %s can't be of type %s "
881 "in FUNCTION %s at %L", sym
->name
,
882 gfc_typename (ts
), ns
->entries
->sym
->name
,
889 proc
->attr
.access
= ACCESS_PRIVATE
;
890 proc
->attr
.entry_master
= 1;
892 /* Merge all the entry point arguments. */
893 for (el
= ns
->entries
; el
; el
= el
->next
)
894 merge_argument_lists (proc
, el
->sym
->formal
);
896 /* Check the master formal arguments for any that are not
897 present in all entry points. */
898 for (el
= ns
->entries
; el
; el
= el
->next
)
899 check_argument_lists (proc
, el
->sym
->formal
);
901 /* Use the master function for the function body. */
902 ns
->proc_name
= proc
;
904 /* Finalize the new symbols. */
905 gfc_commit_symbols ();
907 /* Restore the original namespace. */
908 gfc_current_ns
= old_ns
;
912 /* Resolve common variables. */
914 resolve_common_vars (gfc_common_head
*common_block
, bool named_common
)
916 gfc_symbol
*csym
= common_block
->head
;
918 for (; csym
; csym
= csym
->common_next
)
920 /* gfc_add_in_common may have been called before, but the reported errors
921 have been ignored to continue parsing.
922 We do the checks again here. */
923 if (!csym
->attr
.use_assoc
)
924 gfc_add_in_common (&csym
->attr
, csym
->name
, &common_block
->where
);
926 if (csym
->value
|| csym
->attr
.data
)
928 if (!csym
->ns
->is_block_data
)
929 gfc_notify_std (GFC_STD_GNU
, "Variable %qs at %L is in COMMON "
930 "but only in BLOCK DATA initialization is "
931 "allowed", csym
->name
, &csym
->declared_at
);
932 else if (!named_common
)
933 gfc_notify_std (GFC_STD_GNU
, "Initialized variable %qs at %L is "
934 "in a blank COMMON but initialization is only "
935 "allowed in named common blocks", csym
->name
,
939 if (UNLIMITED_POLY (csym
))
940 gfc_error_now ("%qs in cannot appear in COMMON at %L "
941 "[F2008:C5100]", csym
->name
, &csym
->declared_at
);
943 if (csym
->ts
.type
!= BT_DERIVED
)
946 if (!(csym
->ts
.u
.derived
->attr
.sequence
947 || csym
->ts
.u
.derived
->attr
.is_bind_c
))
948 gfc_error_now ("Derived type variable %qs in COMMON at %L "
949 "has neither the SEQUENCE nor the BIND(C) "
950 "attribute", csym
->name
, &csym
->declared_at
);
951 if (csym
->ts
.u
.derived
->attr
.alloc_comp
)
952 gfc_error_now ("Derived type variable %qs in COMMON at %L "
953 "has an ultimate component that is "
954 "allocatable", csym
->name
, &csym
->declared_at
);
955 if (gfc_has_default_initializer (csym
->ts
.u
.derived
))
956 gfc_error_now ("Derived type variable %qs in COMMON at %L "
957 "may not have default initializer", csym
->name
,
960 if (csym
->attr
.flavor
== FL_UNKNOWN
&& !csym
->attr
.proc_pointer
)
961 gfc_add_flavor (&csym
->attr
, FL_VARIABLE
, csym
->name
, &csym
->declared_at
);
965 /* Resolve common blocks. */
967 resolve_common_blocks (gfc_symtree
*common_root
)
972 if (common_root
== NULL
)
975 if (common_root
->left
)
976 resolve_common_blocks (common_root
->left
);
977 if (common_root
->right
)
978 resolve_common_blocks (common_root
->right
);
980 resolve_common_vars (common_root
->n
.common
, true);
982 /* The common name is a global name - in Fortran 2003 also if it has a
983 C binding name, since Fortran 2008 only the C binding name is a global
985 if (!common_root
->n
.common
->binding_label
986 || gfc_notification_std (GFC_STD_F2008
))
988 gsym
= gfc_find_gsymbol (gfc_gsym_root
,
989 common_root
->n
.common
->name
);
991 if (gsym
&& gfc_notification_std (GFC_STD_F2008
)
992 && gsym
->type
== GSYM_COMMON
993 && ((common_root
->n
.common
->binding_label
994 && (!gsym
->binding_label
995 || strcmp (common_root
->n
.common
->binding_label
,
996 gsym
->binding_label
) != 0))
997 || (!common_root
->n
.common
->binding_label
998 && gsym
->binding_label
)))
1000 gfc_error ("In Fortran 2003 COMMON %qs block at %L is a global "
1001 "identifier and must thus have the same binding name "
1002 "as the same-named COMMON block at %L: %s vs %s",
1003 common_root
->n
.common
->name
, &common_root
->n
.common
->where
,
1005 common_root
->n
.common
->binding_label
1006 ? common_root
->n
.common
->binding_label
: "(blank)",
1007 gsym
->binding_label
? gsym
->binding_label
: "(blank)");
1011 if (gsym
&& gsym
->type
!= GSYM_COMMON
1012 && !common_root
->n
.common
->binding_label
)
1014 gfc_error ("COMMON block %qs at %L uses the same global identifier "
1016 common_root
->n
.common
->name
, &common_root
->n
.common
->where
,
1020 if (gsym
&& gsym
->type
!= GSYM_COMMON
)
1022 gfc_error ("Fortran 2008: COMMON block %qs with binding label at "
1023 "%L sharing the identifier with global non-COMMON-block "
1024 "entity at %L", common_root
->n
.common
->name
,
1025 &common_root
->n
.common
->where
, &gsym
->where
);
1030 gsym
= gfc_get_gsymbol (common_root
->n
.common
->name
);
1031 gsym
->type
= GSYM_COMMON
;
1032 gsym
->where
= common_root
->n
.common
->where
;
1038 if (common_root
->n
.common
->binding_label
)
1040 gsym
= gfc_find_gsymbol (gfc_gsym_root
,
1041 common_root
->n
.common
->binding_label
);
1042 if (gsym
&& gsym
->type
!= GSYM_COMMON
)
1044 gfc_error ("COMMON block at %L with binding label %s uses the same "
1045 "global identifier as entity at %L",
1046 &common_root
->n
.common
->where
,
1047 common_root
->n
.common
->binding_label
, &gsym
->where
);
1052 gsym
= gfc_get_gsymbol (common_root
->n
.common
->binding_label
);
1053 gsym
->type
= GSYM_COMMON
;
1054 gsym
->where
= common_root
->n
.common
->where
;
1060 gfc_find_symbol (common_root
->name
, gfc_current_ns
, 0, &sym
);
1064 if (sym
->attr
.flavor
== FL_PARAMETER
)
1065 gfc_error ("COMMON block %qs at %L is used as PARAMETER at %L",
1066 sym
->name
, &common_root
->n
.common
->where
, &sym
->declared_at
);
1068 if (sym
->attr
.external
)
1069 gfc_error ("COMMON block %qs at %L can not have the EXTERNAL attribute",
1070 sym
->name
, &common_root
->n
.common
->where
);
1072 if (sym
->attr
.intrinsic
)
1073 gfc_error ("COMMON block %qs at %L is also an intrinsic procedure",
1074 sym
->name
, &common_root
->n
.common
->where
);
1075 else if (sym
->attr
.result
1076 || gfc_is_function_return_value (sym
, gfc_current_ns
))
1077 gfc_notify_std (GFC_STD_F2003
, "COMMON block %qs at %L "
1078 "that is also a function result", sym
->name
,
1079 &common_root
->n
.common
->where
);
1080 else if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.proc
!= PROC_INTERNAL
1081 && sym
->attr
.proc
!= PROC_ST_FUNCTION
)
1082 gfc_notify_std (GFC_STD_F2003
, "COMMON block %qs at %L "
1083 "that is also a global procedure", sym
->name
,
1084 &common_root
->n
.common
->where
);
1088 /* Resolve contained function types. Because contained functions can call one
1089 another, they have to be worked out before any of the contained procedures
1092 The good news is that if a function doesn't already have a type, the only
1093 way it can get one is through an IMPLICIT type or a RESULT variable, because
1094 by definition contained functions are contained namespace they're contained
1095 in, not in a sibling or parent namespace. */
1098 resolve_contained_functions (gfc_namespace
*ns
)
1100 gfc_namespace
*child
;
1103 resolve_formal_arglists (ns
);
1105 for (child
= ns
->contained
; child
; child
= child
->sibling
)
1107 /* Resolve alternate entry points first. */
1108 resolve_entries (child
);
1110 /* Then check function return types. */
1111 resolve_contained_fntype (child
->proc_name
, child
);
1112 for (el
= child
->entries
; el
; el
= el
->next
)
1113 resolve_contained_fntype (el
->sym
, child
);
1118 static bool resolve_fl_derived0 (gfc_symbol
*sym
);
1119 static bool resolve_fl_struct (gfc_symbol
*sym
);
1122 /* Resolve all of the elements of a structure constructor and make sure that
1123 the types are correct. The 'init' flag indicates that the given
1124 constructor is an initializer. */
1127 resolve_structure_cons (gfc_expr
*expr
, int init
)
1129 gfc_constructor
*cons
;
1130 gfc_component
*comp
;
1136 if (expr
->ts
.type
== BT_DERIVED
|| expr
->ts
.type
== BT_UNION
)
1138 if (expr
->ts
.u
.derived
->attr
.flavor
== FL_DERIVED
)
1139 resolve_fl_derived0 (expr
->ts
.u
.derived
);
1141 resolve_fl_struct (expr
->ts
.u
.derived
);
1144 cons
= gfc_constructor_first (expr
->value
.constructor
);
1146 /* A constructor may have references if it is the result of substituting a
1147 parameter variable. In this case we just pull out the component we
1150 comp
= expr
->ref
->u
.c
.sym
->components
;
1152 comp
= expr
->ts
.u
.derived
->components
;
1154 for (; comp
&& cons
; comp
= comp
->next
, cons
= gfc_constructor_next (cons
))
1161 if (!gfc_resolve_expr (cons
->expr
))
1167 rank
= comp
->as
? comp
->as
->rank
: 0;
1168 if (comp
->ts
.type
== BT_CLASS
&& CLASS_DATA (comp
)->as
)
1169 rank
= CLASS_DATA (comp
)->as
->rank
;
1171 if (cons
->expr
->expr_type
!= EXPR_NULL
&& rank
!= cons
->expr
->rank
1172 && (comp
->attr
.allocatable
|| cons
->expr
->rank
))
1174 gfc_error ("The rank of the element in the structure "
1175 "constructor at %L does not match that of the "
1176 "component (%d/%d)", &cons
->expr
->where
,
1177 cons
->expr
->rank
, rank
);
1181 /* If we don't have the right type, try to convert it. */
1183 if (!comp
->attr
.proc_pointer
&&
1184 !gfc_compare_types (&cons
->expr
->ts
, &comp
->ts
))
1186 if (strcmp (comp
->name
, "_extends") == 0)
1188 /* Can afford to be brutal with the _extends initializer.
1189 The derived type can get lost because it is PRIVATE
1190 but it is not usage constrained by the standard. */
1191 cons
->expr
->ts
= comp
->ts
;
1193 else if (comp
->attr
.pointer
&& cons
->expr
->ts
.type
!= BT_UNKNOWN
)
1195 gfc_error ("The element in the structure constructor at %L, "
1196 "for pointer component %qs, is %s but should be %s",
1197 &cons
->expr
->where
, comp
->name
,
1198 gfc_basic_typename (cons
->expr
->ts
.type
),
1199 gfc_basic_typename (comp
->ts
.type
));
1204 bool t2
= gfc_convert_type (cons
->expr
, &comp
->ts
, 1);
1210 /* For strings, the length of the constructor should be the same as
1211 the one of the structure, ensure this if the lengths are known at
1212 compile time and when we are dealing with PARAMETER or structure
1214 if (cons
->expr
->ts
.type
== BT_CHARACTER
&& comp
->ts
.u
.cl
1215 && comp
->ts
.u
.cl
->length
1216 && comp
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1217 && cons
->expr
->ts
.u
.cl
&& cons
->expr
->ts
.u
.cl
->length
1218 && cons
->expr
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1219 && cons
->expr
->rank
!= 0
1220 && mpz_cmp (cons
->expr
->ts
.u
.cl
->length
->value
.integer
,
1221 comp
->ts
.u
.cl
->length
->value
.integer
) != 0)
1223 if (cons
->expr
->expr_type
== EXPR_VARIABLE
1224 && cons
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
)
1226 /* Wrap the parameter in an array constructor (EXPR_ARRAY)
1227 to make use of the gfc_resolve_character_array_constructor
1228 machinery. The expression is later simplified away to
1229 an array of string literals. */
1230 gfc_expr
*para
= cons
->expr
;
1231 cons
->expr
= gfc_get_expr ();
1232 cons
->expr
->ts
= para
->ts
;
1233 cons
->expr
->where
= para
->where
;
1234 cons
->expr
->expr_type
= EXPR_ARRAY
;
1235 cons
->expr
->rank
= para
->rank
;
1236 cons
->expr
->shape
= gfc_copy_shape (para
->shape
, para
->rank
);
1237 gfc_constructor_append_expr (&cons
->expr
->value
.constructor
,
1238 para
, &cons
->expr
->where
);
1240 if (cons
->expr
->expr_type
== EXPR_ARRAY
)
1243 p
= gfc_constructor_first (cons
->expr
->value
.constructor
);
1244 if (cons
->expr
->ts
.u
.cl
!= p
->expr
->ts
.u
.cl
)
1246 gfc_charlen
*cl
, *cl2
;
1249 for (cl
= gfc_current_ns
->cl_list
; cl
; cl
= cl
->next
)
1251 if (cl
== cons
->expr
->ts
.u
.cl
)
1259 cl2
->next
= cl
->next
;
1261 gfc_free_expr (cl
->length
);
1265 cons
->expr
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
1266 cons
->expr
->ts
.u
.cl
->length_from_typespec
= true;
1267 cons
->expr
->ts
.u
.cl
->length
= gfc_copy_expr (comp
->ts
.u
.cl
->length
);
1268 gfc_resolve_character_array_constructor (cons
->expr
);
1272 if (cons
->expr
->expr_type
== EXPR_NULL
1273 && !(comp
->attr
.pointer
|| comp
->attr
.allocatable
1274 || comp
->attr
.proc_pointer
|| comp
->ts
.f90_type
== BT_VOID
1275 || (comp
->ts
.type
== BT_CLASS
1276 && (CLASS_DATA (comp
)->attr
.class_pointer
1277 || CLASS_DATA (comp
)->attr
.allocatable
))))
1280 gfc_error ("The NULL in the structure constructor at %L is "
1281 "being applied to component %qs, which is neither "
1282 "a POINTER nor ALLOCATABLE", &cons
->expr
->where
,
1286 if (comp
->attr
.proc_pointer
&& comp
->ts
.interface
)
1288 /* Check procedure pointer interface. */
1289 gfc_symbol
*s2
= NULL
;
1294 c2
= gfc_get_proc_ptr_comp (cons
->expr
);
1297 s2
= c2
->ts
.interface
;
1300 else if (cons
->expr
->expr_type
== EXPR_FUNCTION
)
1302 s2
= cons
->expr
->symtree
->n
.sym
->result
;
1303 name
= cons
->expr
->symtree
->n
.sym
->result
->name
;
1305 else if (cons
->expr
->expr_type
!= EXPR_NULL
)
1307 s2
= cons
->expr
->symtree
->n
.sym
;
1308 name
= cons
->expr
->symtree
->n
.sym
->name
;
1311 if (s2
&& !gfc_compare_interfaces (comp
->ts
.interface
, s2
, name
, 0, 1,
1312 err
, sizeof (err
), NULL
, NULL
))
1314 gfc_error ("Interface mismatch for procedure-pointer component "
1315 "%qs in structure constructor at %L: %s",
1316 comp
->name
, &cons
->expr
->where
, err
);
1321 if (!comp
->attr
.pointer
|| comp
->attr
.proc_pointer
1322 || cons
->expr
->expr_type
== EXPR_NULL
)
1325 a
= gfc_expr_attr (cons
->expr
);
1327 if (!a
.pointer
&& !a
.target
)
1330 gfc_error ("The element in the structure constructor at %L, "
1331 "for pointer component %qs should be a POINTER or "
1332 "a TARGET", &cons
->expr
->where
, comp
->name
);
1337 /* F08:C461. Additional checks for pointer initialization. */
1341 gfc_error ("Pointer initialization target at %L "
1342 "must not be ALLOCATABLE ", &cons
->expr
->where
);
1347 gfc_error ("Pointer initialization target at %L "
1348 "must have the SAVE attribute", &cons
->expr
->where
);
1352 /* F2003, C1272 (3). */
1353 bool impure
= cons
->expr
->expr_type
== EXPR_VARIABLE
1354 && (gfc_impure_variable (cons
->expr
->symtree
->n
.sym
)
1355 || gfc_is_coindexed (cons
->expr
));
1356 if (impure
&& gfc_pure (NULL
))
1359 gfc_error ("Invalid expression in the structure constructor for "
1360 "pointer component %qs at %L in PURE procedure",
1361 comp
->name
, &cons
->expr
->where
);
1365 gfc_unset_implicit_pure (NULL
);
1372 /****************** Expression name resolution ******************/
1374 /* Returns 0 if a symbol was not declared with a type or
1375 attribute declaration statement, nonzero otherwise. */
1378 was_declared (gfc_symbol
*sym
)
1384 if (!a
.implicit_type
&& sym
->ts
.type
!= BT_UNKNOWN
)
1387 if (a
.allocatable
|| a
.dimension
|| a
.dummy
|| a
.external
|| a
.intrinsic
1388 || a
.optional
|| a
.pointer
|| a
.save
|| a
.target
|| a
.volatile_
1389 || a
.value
|| a
.access
!= ACCESS_UNKNOWN
|| a
.intent
!= INTENT_UNKNOWN
1390 || a
.asynchronous
|| a
.codimension
)
1397 /* Determine if a symbol is generic or not. */
1400 generic_sym (gfc_symbol
*sym
)
1404 if (sym
->attr
.generic
||
1405 (sym
->attr
.intrinsic
&& gfc_generic_intrinsic (sym
->name
)))
1408 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1411 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1418 return generic_sym (s
);
1425 /* Determine if a symbol is specific or not. */
1428 specific_sym (gfc_symbol
*sym
)
1432 if (sym
->attr
.if_source
== IFSRC_IFBODY
1433 || sym
->attr
.proc
== PROC_MODULE
1434 || sym
->attr
.proc
== PROC_INTERNAL
1435 || sym
->attr
.proc
== PROC_ST_FUNCTION
1436 || (sym
->attr
.intrinsic
&& gfc_specific_intrinsic (sym
->name
))
1437 || sym
->attr
.external
)
1440 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1443 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1445 return (s
== NULL
) ? 0 : specific_sym (s
);
1449 /* Figure out if the procedure is specific, generic or unknown. */
1452 { PTYPE_GENERIC
= 1, PTYPE_SPECIFIC
, PTYPE_UNKNOWN
};
1455 procedure_kind (gfc_symbol
*sym
)
1457 if (generic_sym (sym
))
1458 return PTYPE_GENERIC
;
1460 if (specific_sym (sym
))
1461 return PTYPE_SPECIFIC
;
1463 return PTYPE_UNKNOWN
;
1466 /* Check references to assumed size arrays. The flag need_full_assumed_size
1467 is nonzero when matching actual arguments. */
1469 static int need_full_assumed_size
= 0;
1472 check_assumed_size_reference (gfc_symbol
*sym
, gfc_expr
*e
)
1474 if (need_full_assumed_size
|| !(sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
))
1477 /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong.
1478 What should it be? */
1479 if (e
->ref
&& (e
->ref
->u
.ar
.end
[e
->ref
->u
.ar
.as
->rank
- 1] == NULL
)
1480 && (e
->ref
->u
.ar
.as
->type
== AS_ASSUMED_SIZE
)
1481 && (e
->ref
->u
.ar
.type
== AR_FULL
))
1483 gfc_error ("The upper bound in the last dimension must "
1484 "appear in the reference to the assumed size "
1485 "array %qs at %L", sym
->name
, &e
->where
);
1492 /* Look for bad assumed size array references in argument expressions
1493 of elemental and array valued intrinsic procedures. Since this is
1494 called from procedure resolution functions, it only recurses at
1498 resolve_assumed_size_actual (gfc_expr
*e
)
1503 switch (e
->expr_type
)
1506 if (e
->symtree
&& check_assumed_size_reference (e
->symtree
->n
.sym
, e
))
1511 if (resolve_assumed_size_actual (e
->value
.op
.op1
)
1512 || resolve_assumed_size_actual (e
->value
.op
.op2
))
1523 /* Check a generic procedure, passed as an actual argument, to see if
1524 there is a matching specific name. If none, it is an error, and if
1525 more than one, the reference is ambiguous. */
1527 count_specific_procs (gfc_expr
*e
)
1534 sym
= e
->symtree
->n
.sym
;
1536 for (p
= sym
->generic
; p
; p
= p
->next
)
1537 if (strcmp (sym
->name
, p
->sym
->name
) == 0)
1539 e
->symtree
= gfc_find_symtree (p
->sym
->ns
->sym_root
,
1545 gfc_error ("%qs at %L is ambiguous", e
->symtree
->n
.sym
->name
,
1549 gfc_error ("GENERIC procedure %qs is not allowed as an actual "
1550 "argument at %L", sym
->name
, &e
->where
);
1556 /* See if a call to sym could possibly be a not allowed RECURSION because of
1557 a missing RECURSIVE declaration. This means that either sym is the current
1558 context itself, or sym is the parent of a contained procedure calling its
1559 non-RECURSIVE containing procedure.
1560 This also works if sym is an ENTRY. */
1563 is_illegal_recursion (gfc_symbol
* sym
, gfc_namespace
* context
)
1565 gfc_symbol
* proc_sym
;
1566 gfc_symbol
* context_proc
;
1567 gfc_namespace
* real_context
;
1569 if (sym
->attr
.flavor
== FL_PROGRAM
1570 || gfc_fl_struct (sym
->attr
.flavor
))
1573 gcc_assert (sym
->attr
.flavor
== FL_PROCEDURE
);
1575 /* If we've got an ENTRY, find real procedure. */
1576 if (sym
->attr
.entry
&& sym
->ns
->entries
)
1577 proc_sym
= sym
->ns
->entries
->sym
;
1581 /* If sym is RECURSIVE, all is well of course. */
1582 if (proc_sym
->attr
.recursive
|| flag_recursive
)
1585 /* Find the context procedure's "real" symbol if it has entries.
1586 We look for a procedure symbol, so recurse on the parents if we don't
1587 find one (like in case of a BLOCK construct). */
1588 for (real_context
= context
; ; real_context
= real_context
->parent
)
1590 /* We should find something, eventually! */
1591 gcc_assert (real_context
);
1593 context_proc
= (real_context
->entries
? real_context
->entries
->sym
1594 : real_context
->proc_name
);
1596 /* In some special cases, there may not be a proc_name, like for this
1598 real(bad_kind()) function foo () ...
1599 when checking the call to bad_kind ().
1600 In these cases, we simply return here and assume that the
1605 if (context_proc
->attr
.flavor
!= FL_LABEL
)
1609 /* A call from sym's body to itself is recursion, of course. */
1610 if (context_proc
== proc_sym
)
1613 /* The same is true if context is a contained procedure and sym the
1615 if (context_proc
->attr
.contained
)
1617 gfc_symbol
* parent_proc
;
1619 gcc_assert (context
->parent
);
1620 parent_proc
= (context
->parent
->entries
? context
->parent
->entries
->sym
1621 : context
->parent
->proc_name
);
1623 if (parent_proc
== proc_sym
)
1631 /* Resolve an intrinsic procedure: Set its function/subroutine attribute,
1632 its typespec and formal argument list. */
1635 gfc_resolve_intrinsic (gfc_symbol
*sym
, locus
*loc
)
1637 gfc_intrinsic_sym
* isym
= NULL
;
1643 /* Already resolved. */
1644 if (sym
->from_intmod
&& sym
->ts
.type
!= BT_UNKNOWN
)
1647 /* We already know this one is an intrinsic, so we don't call
1648 gfc_is_intrinsic for full checking but rather use gfc_find_function and
1649 gfc_find_subroutine directly to check whether it is a function or
1652 if (sym
->intmod_sym_id
&& sym
->attr
.subroutine
)
1654 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1655 isym
= gfc_intrinsic_subroutine_by_id (id
);
1657 else if (sym
->intmod_sym_id
)
1659 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1660 isym
= gfc_intrinsic_function_by_id (id
);
1662 else if (!sym
->attr
.subroutine
)
1663 isym
= gfc_find_function (sym
->name
);
1665 if (isym
&& !sym
->attr
.subroutine
)
1667 if (sym
->ts
.type
!= BT_UNKNOWN
&& warn_surprising
1668 && !sym
->attr
.implicit_type
)
1669 gfc_warning (OPT_Wsurprising
,
1670 "Type specified for intrinsic function %qs at %L is"
1671 " ignored", sym
->name
, &sym
->declared_at
);
1673 if (!sym
->attr
.function
&&
1674 !gfc_add_function(&sym
->attr
, sym
->name
, loc
))
1679 else if (isym
|| (isym
= gfc_find_subroutine (sym
->name
)))
1681 if (sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.implicit_type
)
1683 gfc_error ("Intrinsic subroutine %qs at %L shall not have a type"
1684 " specifier", sym
->name
, &sym
->declared_at
);
1688 if (!sym
->attr
.subroutine
&&
1689 !gfc_add_subroutine(&sym
->attr
, sym
->name
, loc
))
1694 gfc_error ("%qs declared INTRINSIC at %L does not exist", sym
->name
,
1699 gfc_copy_formal_args_intr (sym
, isym
, NULL
);
1701 sym
->attr
.pure
= isym
->pure
;
1702 sym
->attr
.elemental
= isym
->elemental
;
1704 /* Check it is actually available in the standard settings. */
1705 if (!gfc_check_intrinsic_standard (isym
, &symstd
, false, sym
->declared_at
))
1707 gfc_error ("The intrinsic %qs declared INTRINSIC at %L is not "
1708 "available in the current standard settings but %s. Use "
1709 "an appropriate %<-std=*%> option or enable "
1710 "%<-fall-intrinsics%> in order to use it.",
1711 sym
->name
, &sym
->declared_at
, symstd
);
1719 /* Resolve a procedure expression, like passing it to a called procedure or as
1720 RHS for a procedure pointer assignment. */
1723 resolve_procedure_expression (gfc_expr
* expr
)
1727 if (expr
->expr_type
!= EXPR_VARIABLE
)
1729 gcc_assert (expr
->symtree
);
1731 sym
= expr
->symtree
->n
.sym
;
1733 if (sym
->attr
.intrinsic
)
1734 gfc_resolve_intrinsic (sym
, &expr
->where
);
1736 if (sym
->attr
.flavor
!= FL_PROCEDURE
1737 || (sym
->attr
.function
&& sym
->result
== sym
))
1740 /* A non-RECURSIVE procedure that is used as procedure expression within its
1741 own body is in danger of being called recursively. */
1742 if (is_illegal_recursion (sym
, gfc_current_ns
))
1743 gfc_warning (0, "Non-RECURSIVE procedure %qs at %L is possibly calling"
1744 " itself recursively. Declare it RECURSIVE or use"
1745 " %<-frecursive%>", sym
->name
, &expr
->where
);
1751 /* Resolve an actual argument list. Most of the time, this is just
1752 resolving the expressions in the list.
1753 The exception is that we sometimes have to decide whether arguments
1754 that look like procedure arguments are really simple variable
1758 resolve_actual_arglist (gfc_actual_arglist
*arg
, procedure_type ptype
,
1759 bool no_formal_args
)
1762 gfc_symtree
*parent_st
;
1764 gfc_component
*comp
;
1765 int save_need_full_assumed_size
;
1766 bool return_value
= false;
1767 bool actual_arg_sav
= actual_arg
, first_actual_arg_sav
= first_actual_arg
;
1770 first_actual_arg
= true;
1772 for (; arg
; arg
= arg
->next
)
1777 /* Check the label is a valid branching target. */
1780 if (arg
->label
->defined
== ST_LABEL_UNKNOWN
)
1782 gfc_error ("Label %d referenced at %L is never defined",
1783 arg
->label
->value
, &arg
->label
->where
);
1787 first_actual_arg
= false;
1791 if (e
->expr_type
== EXPR_VARIABLE
1792 && e
->symtree
->n
.sym
->attr
.generic
1794 && count_specific_procs (e
) != 1)
1797 if (e
->ts
.type
!= BT_PROCEDURE
)
1799 save_need_full_assumed_size
= need_full_assumed_size
;
1800 if (e
->expr_type
!= EXPR_VARIABLE
)
1801 need_full_assumed_size
= 0;
1802 if (!gfc_resolve_expr (e
))
1804 need_full_assumed_size
= save_need_full_assumed_size
;
1808 /* See if the expression node should really be a variable reference. */
1810 sym
= e
->symtree
->n
.sym
;
1812 if (sym
->attr
.flavor
== FL_PROCEDURE
1813 || sym
->attr
.intrinsic
1814 || sym
->attr
.external
)
1818 /* If a procedure is not already determined to be something else
1819 check if it is intrinsic. */
1820 if (gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, e
->where
))
1821 sym
->attr
.intrinsic
= 1;
1823 if (sym
->attr
.proc
== PROC_ST_FUNCTION
)
1825 gfc_error ("Statement function %qs at %L is not allowed as an "
1826 "actual argument", sym
->name
, &e
->where
);
1829 actual_ok
= gfc_intrinsic_actual_ok (sym
->name
,
1830 sym
->attr
.subroutine
);
1831 if (sym
->attr
.intrinsic
&& actual_ok
== 0)
1833 gfc_error ("Intrinsic %qs at %L is not allowed as an "
1834 "actual argument", sym
->name
, &e
->where
);
1837 if (sym
->attr
.contained
&& !sym
->attr
.use_assoc
1838 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
1840 if (!gfc_notify_std (GFC_STD_F2008
, "Internal procedure %qs is"
1841 " used as actual argument at %L",
1842 sym
->name
, &e
->where
))
1846 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
)
1848 gfc_error ("ELEMENTAL non-INTRINSIC procedure %qs is not "
1849 "allowed as an actual argument at %L", sym
->name
,
1853 /* Check if a generic interface has a specific procedure
1854 with the same name before emitting an error. */
1855 if (sym
->attr
.generic
&& count_specific_procs (e
) != 1)
1858 /* Just in case a specific was found for the expression. */
1859 sym
= e
->symtree
->n
.sym
;
1861 /* If the symbol is the function that names the current (or
1862 parent) scope, then we really have a variable reference. */
1864 if (gfc_is_function_return_value (sym
, sym
->ns
))
1867 /* If all else fails, see if we have a specific intrinsic. */
1868 if (sym
->ts
.type
== BT_UNKNOWN
&& sym
->attr
.intrinsic
)
1870 gfc_intrinsic_sym
*isym
;
1872 isym
= gfc_find_function (sym
->name
);
1873 if (isym
== NULL
|| !isym
->specific
)
1875 gfc_error ("Unable to find a specific INTRINSIC procedure "
1876 "for the reference %qs at %L", sym
->name
,
1881 sym
->attr
.intrinsic
= 1;
1882 sym
->attr
.function
= 1;
1885 if (!gfc_resolve_expr (e
))
1890 /* See if the name is a module procedure in a parent unit. */
1892 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1895 if (gfc_find_sym_tree (sym
->name
, sym
->ns
->parent
, 1, &parent_st
))
1897 gfc_error ("Symbol %qs at %L is ambiguous", sym
->name
, &e
->where
);
1901 if (parent_st
== NULL
)
1904 sym
= parent_st
->n
.sym
;
1905 e
->symtree
= parent_st
; /* Point to the right thing. */
1907 if (sym
->attr
.flavor
== FL_PROCEDURE
1908 || sym
->attr
.intrinsic
1909 || sym
->attr
.external
)
1911 if (!gfc_resolve_expr (e
))
1917 e
->expr_type
= EXPR_VARIABLE
;
1919 if ((sym
->as
!= NULL
&& sym
->ts
.type
!= BT_CLASS
)
1920 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
1921 && CLASS_DATA (sym
)->as
))
1923 e
->rank
= sym
->ts
.type
== BT_CLASS
1924 ? CLASS_DATA (sym
)->as
->rank
: sym
->as
->rank
;
1925 e
->ref
= gfc_get_ref ();
1926 e
->ref
->type
= REF_ARRAY
;
1927 e
->ref
->u
.ar
.type
= AR_FULL
;
1928 e
->ref
->u
.ar
.as
= sym
->ts
.type
== BT_CLASS
1929 ? CLASS_DATA (sym
)->as
: sym
->as
;
1932 /* Expressions are assigned a default ts.type of BT_PROCEDURE in
1933 primary.c (match_actual_arg). If above code determines that it
1934 is a variable instead, it needs to be resolved as it was not
1935 done at the beginning of this function. */
1936 save_need_full_assumed_size
= need_full_assumed_size
;
1937 if (e
->expr_type
!= EXPR_VARIABLE
)
1938 need_full_assumed_size
= 0;
1939 if (!gfc_resolve_expr (e
))
1941 need_full_assumed_size
= save_need_full_assumed_size
;
1944 /* Check argument list functions %VAL, %LOC and %REF. There is
1945 nothing to do for %REF. */
1946 if (arg
->name
&& arg
->name
[0] == '%')
1948 if (strncmp ("%VAL", arg
->name
, 4) == 0)
1950 if (e
->ts
.type
== BT_CHARACTER
|| e
->ts
.type
== BT_DERIVED
)
1952 gfc_error ("By-value argument at %L is not of numeric "
1959 gfc_error ("By-value argument at %L cannot be an array or "
1960 "an array section", &e
->where
);
1964 /* Intrinsics are still PROC_UNKNOWN here. However,
1965 since same file external procedures are not resolvable
1966 in gfortran, it is a good deal easier to leave them to
1968 if (ptype
!= PROC_UNKNOWN
1969 && ptype
!= PROC_DUMMY
1970 && ptype
!= PROC_EXTERNAL
1971 && ptype
!= PROC_MODULE
)
1973 gfc_error ("By-value argument at %L is not allowed "
1974 "in this context", &e
->where
);
1979 /* Statement functions have already been excluded above. */
1980 else if (strncmp ("%LOC", arg
->name
, 4) == 0
1981 && e
->ts
.type
== BT_PROCEDURE
)
1983 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_INTERNAL
)
1985 gfc_error ("Passing internal procedure at %L by location "
1986 "not allowed", &e
->where
);
1992 comp
= gfc_get_proc_ptr_comp(e
);
1993 if (e
->expr_type
== EXPR_VARIABLE
1994 && comp
&& comp
->attr
.elemental
)
1996 gfc_error ("ELEMENTAL procedure pointer component %qs is not "
1997 "allowed as an actual argument at %L", comp
->name
,
2001 /* Fortran 2008, C1237. */
2002 if (e
->expr_type
== EXPR_VARIABLE
&& gfc_is_coindexed (e
)
2003 && gfc_has_ultimate_pointer (e
))
2005 gfc_error ("Coindexed actual argument at %L with ultimate pointer "
2006 "component", &e
->where
);
2010 first_actual_arg
= false;
2013 return_value
= true;
2016 actual_arg
= actual_arg_sav
;
2017 first_actual_arg
= first_actual_arg_sav
;
2019 return return_value
;
2023 /* Do the checks of the actual argument list that are specific to elemental
2024 procedures. If called with c == NULL, we have a function, otherwise if
2025 expr == NULL, we have a subroutine. */
2028 resolve_elemental_actual (gfc_expr
*expr
, gfc_code
*c
)
2030 gfc_actual_arglist
*arg0
;
2031 gfc_actual_arglist
*arg
;
2032 gfc_symbol
*esym
= NULL
;
2033 gfc_intrinsic_sym
*isym
= NULL
;
2035 gfc_intrinsic_arg
*iformal
= NULL
;
2036 gfc_formal_arglist
*eformal
= NULL
;
2037 bool formal_optional
= false;
2038 bool set_by_optional
= false;
2042 /* Is this an elemental procedure? */
2043 if (expr
&& expr
->value
.function
.actual
!= NULL
)
2045 if (expr
->value
.function
.esym
!= NULL
2046 && expr
->value
.function
.esym
->attr
.elemental
)
2048 arg0
= expr
->value
.function
.actual
;
2049 esym
= expr
->value
.function
.esym
;
2051 else if (expr
->value
.function
.isym
!= NULL
2052 && expr
->value
.function
.isym
->elemental
)
2054 arg0
= expr
->value
.function
.actual
;
2055 isym
= expr
->value
.function
.isym
;
2060 else if (c
&& c
->ext
.actual
!= NULL
)
2062 arg0
= c
->ext
.actual
;
2064 if (c
->resolved_sym
)
2065 esym
= c
->resolved_sym
;
2067 esym
= c
->symtree
->n
.sym
;
2070 if (!esym
->attr
.elemental
)
2076 /* The rank of an elemental is the rank of its array argument(s). */
2077 for (arg
= arg0
; arg
; arg
= arg
->next
)
2079 if (arg
->expr
!= NULL
&& arg
->expr
->rank
!= 0)
2081 rank
= arg
->expr
->rank
;
2082 if (arg
->expr
->expr_type
== EXPR_VARIABLE
2083 && arg
->expr
->symtree
->n
.sym
->attr
.optional
)
2084 set_by_optional
= true;
2086 /* Function specific; set the result rank and shape. */
2090 if (!expr
->shape
&& arg
->expr
->shape
)
2092 expr
->shape
= gfc_get_shape (rank
);
2093 for (i
= 0; i
< rank
; i
++)
2094 mpz_init_set (expr
->shape
[i
], arg
->expr
->shape
[i
]);
2101 /* If it is an array, it shall not be supplied as an actual argument
2102 to an elemental procedure unless an array of the same rank is supplied
2103 as an actual argument corresponding to a nonoptional dummy argument of
2104 that elemental procedure(12.4.1.5). */
2105 formal_optional
= false;
2107 iformal
= isym
->formal
;
2109 eformal
= esym
->formal
;
2111 for (arg
= arg0
; arg
; arg
= arg
->next
)
2115 if (eformal
->sym
&& eformal
->sym
->attr
.optional
)
2116 formal_optional
= true;
2117 eformal
= eformal
->next
;
2119 else if (isym
&& iformal
)
2121 if (iformal
->optional
)
2122 formal_optional
= true;
2123 iformal
= iformal
->next
;
2126 formal_optional
= true;
2128 if (pedantic
&& arg
->expr
!= NULL
2129 && arg
->expr
->expr_type
== EXPR_VARIABLE
2130 && arg
->expr
->symtree
->n
.sym
->attr
.optional
2133 && (set_by_optional
|| arg
->expr
->rank
!= rank
)
2134 && !(isym
&& isym
->id
== GFC_ISYM_CONVERSION
))
2136 gfc_warning (0, "%qs at %L is an array and OPTIONAL; IF IT IS "
2137 "MISSING, it cannot be the actual argument of an "
2138 "ELEMENTAL procedure unless there is a non-optional "
2139 "argument with the same rank (12.4.1.5)",
2140 arg
->expr
->symtree
->n
.sym
->name
, &arg
->expr
->where
);
2144 for (arg
= arg0
; arg
; arg
= arg
->next
)
2146 if (arg
->expr
== NULL
|| arg
->expr
->rank
== 0)
2149 /* Being elemental, the last upper bound of an assumed size array
2150 argument must be present. */
2151 if (resolve_assumed_size_actual (arg
->expr
))
2154 /* Elemental procedure's array actual arguments must conform. */
2157 if (!gfc_check_conformance (arg
->expr
, e
, "elemental procedure"))
2164 /* INTENT(OUT) is only allowed for subroutines; if any actual argument
2165 is an array, the intent inout/out variable needs to be also an array. */
2166 if (rank
> 0 && esym
&& expr
== NULL
)
2167 for (eformal
= esym
->formal
, arg
= arg0
; arg
&& eformal
;
2168 arg
= arg
->next
, eformal
= eformal
->next
)
2169 if ((eformal
->sym
->attr
.intent
== INTENT_OUT
2170 || eformal
->sym
->attr
.intent
== INTENT_INOUT
)
2171 && arg
->expr
&& arg
->expr
->rank
== 0)
2173 gfc_error ("Actual argument at %L for INTENT(%s) dummy %qs of "
2174 "ELEMENTAL subroutine %qs is a scalar, but another "
2175 "actual argument is an array", &arg
->expr
->where
,
2176 (eformal
->sym
->attr
.intent
== INTENT_OUT
) ? "OUT"
2177 : "INOUT", eformal
->sym
->name
, esym
->name
);
2184 /* This function does the checking of references to global procedures
2185 as defined in sections 18.1 and 14.1, respectively, of the Fortran
2186 77 and 95 standards. It checks for a gsymbol for the name, making
2187 one if it does not already exist. If it already exists, then the
2188 reference being resolved must correspond to the type of gsymbol.
2189 Otherwise, the new symbol is equipped with the attributes of the
2190 reference. The corresponding code that is called in creating
2191 global entities is parse.c.
2193 In addition, for all but -std=legacy, the gsymbols are used to
2194 check the interfaces of external procedures from the same file.
2195 The namespace of the gsymbol is resolved and then, once this is
2196 done the interface is checked. */
2200 not_in_recursive (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2202 if (!gsym_ns
->proc_name
->attr
.recursive
)
2205 if (sym
->ns
== gsym_ns
)
2208 if (sym
->ns
->parent
&& sym
->ns
->parent
== gsym_ns
)
2215 not_entry_self_reference (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2217 if (gsym_ns
->entries
)
2219 gfc_entry_list
*entry
= gsym_ns
->entries
;
2221 for (; entry
; entry
= entry
->next
)
2223 if (strcmp (sym
->name
, entry
->sym
->name
) == 0)
2225 if (strcmp (gsym_ns
->proc_name
->name
,
2226 sym
->ns
->proc_name
->name
) == 0)
2230 && strcmp (gsym_ns
->proc_name
->name
,
2231 sym
->ns
->parent
->proc_name
->name
) == 0)
2240 /* Check for the requirement of an explicit interface. F08:12.4.2.2. */
2243 gfc_explicit_interface_required (gfc_symbol
*sym
, char *errmsg
, int err_len
)
2245 gfc_formal_arglist
*arg
= gfc_sym_get_dummy_args (sym
);
2247 for ( ; arg
; arg
= arg
->next
)
2252 if (arg
->sym
->attr
.allocatable
) /* (2a) */
2254 strncpy (errmsg
, _("allocatable argument"), err_len
);
2257 else if (arg
->sym
->attr
.asynchronous
)
2259 strncpy (errmsg
, _("asynchronous argument"), err_len
);
2262 else if (arg
->sym
->attr
.optional
)
2264 strncpy (errmsg
, _("optional argument"), err_len
);
2267 else if (arg
->sym
->attr
.pointer
)
2269 strncpy (errmsg
, _("pointer argument"), err_len
);
2272 else if (arg
->sym
->attr
.target
)
2274 strncpy (errmsg
, _("target argument"), err_len
);
2277 else if (arg
->sym
->attr
.value
)
2279 strncpy (errmsg
, _("value argument"), err_len
);
2282 else if (arg
->sym
->attr
.volatile_
)
2284 strncpy (errmsg
, _("volatile argument"), err_len
);
2287 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_SHAPE
) /* (2b) */
2289 strncpy (errmsg
, _("assumed-shape argument"), err_len
);
2292 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_RANK
) /* TS 29113, 6.2. */
2294 strncpy (errmsg
, _("assumed-rank argument"), err_len
);
2297 else if (arg
->sym
->attr
.codimension
) /* (2c) */
2299 strncpy (errmsg
, _("coarray argument"), err_len
);
2302 else if (false) /* (2d) TODO: parametrized derived type */
2304 strncpy (errmsg
, _("parametrized derived type argument"), err_len
);
2307 else if (arg
->sym
->ts
.type
== BT_CLASS
) /* (2e) */
2309 strncpy (errmsg
, _("polymorphic argument"), err_len
);
2312 else if (arg
->sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
2314 strncpy (errmsg
, _("NO_ARG_CHECK attribute"), err_len
);
2317 else if (arg
->sym
->ts
.type
== BT_ASSUMED
)
2319 /* As assumed-type is unlimited polymorphic (cf. above).
2320 See also TS 29113, Note 6.1. */
2321 strncpy (errmsg
, _("assumed-type argument"), err_len
);
2326 if (sym
->attr
.function
)
2328 gfc_symbol
*res
= sym
->result
? sym
->result
: sym
;
2330 if (res
->attr
.dimension
) /* (3a) */
2332 strncpy (errmsg
, _("array result"), err_len
);
2335 else if (res
->attr
.pointer
|| res
->attr
.allocatable
) /* (3b) */
2337 strncpy (errmsg
, _("pointer or allocatable result"), err_len
);
2340 else if (res
->ts
.type
== BT_CHARACTER
&& res
->ts
.u
.cl
2341 && res
->ts
.u
.cl
->length
2342 && res
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
) /* (3c) */
2344 strncpy (errmsg
, _("result with non-constant character length"), err_len
);
2349 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
) /* (4) */
2351 strncpy (errmsg
, _("elemental procedure"), err_len
);
2354 else if (sym
->attr
.is_bind_c
) /* (5) */
2356 strncpy (errmsg
, _("bind(c) procedure"), err_len
);
2365 resolve_global_procedure (gfc_symbol
*sym
, locus
*where
,
2366 gfc_actual_arglist
**actual
, int sub
)
2370 enum gfc_symbol_type type
;
2373 type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
2375 gsym
= gfc_get_gsymbol (sym
->binding_label
? sym
->binding_label
: sym
->name
);
2377 if ((gsym
->type
!= GSYM_UNKNOWN
&& gsym
->type
!= type
))
2378 gfc_global_used (gsym
, where
);
2380 if ((sym
->attr
.if_source
== IFSRC_UNKNOWN
2381 || sym
->attr
.if_source
== IFSRC_IFBODY
)
2382 && gsym
->type
!= GSYM_UNKNOWN
2383 && !gsym
->binding_label
2385 && gsym
->ns
->resolved
!= -1
2386 && gsym
->ns
->proc_name
2387 && not_in_recursive (sym
, gsym
->ns
)
2388 && not_entry_self_reference (sym
, gsym
->ns
))
2390 gfc_symbol
*def_sym
;
2392 /* Resolve the gsymbol namespace if needed. */
2393 if (!gsym
->ns
->resolved
)
2395 gfc_dt_list
*old_dt_list
;
2397 /* Stash away derived types so that the backend_decls do not
2399 old_dt_list
= gfc_derived_types
;
2400 gfc_derived_types
= NULL
;
2402 gfc_resolve (gsym
->ns
);
2404 /* Store the new derived types with the global namespace. */
2405 if (gfc_derived_types
)
2406 gsym
->ns
->derived_types
= gfc_derived_types
;
2408 /* Restore the derived types of this namespace. */
2409 gfc_derived_types
= old_dt_list
;
2412 /* Make sure that translation for the gsymbol occurs before
2413 the procedure currently being resolved. */
2414 ns
= gfc_global_ns_list
;
2415 for (; ns
&& ns
!= gsym
->ns
; ns
= ns
->sibling
)
2417 if (ns
->sibling
== gsym
->ns
)
2419 ns
->sibling
= gsym
->ns
->sibling
;
2420 gsym
->ns
->sibling
= gfc_global_ns_list
;
2421 gfc_global_ns_list
= gsym
->ns
;
2426 def_sym
= gsym
->ns
->proc_name
;
2428 /* This can happen if a binding name has been specified. */
2429 if (gsym
->binding_label
&& gsym
->sym_name
!= def_sym
->name
)
2430 gfc_find_symbol (gsym
->sym_name
, gsym
->ns
, 0, &def_sym
);
2432 if (def_sym
->attr
.entry_master
)
2434 gfc_entry_list
*entry
;
2435 for (entry
= gsym
->ns
->entries
; entry
; entry
= entry
->next
)
2436 if (strcmp (entry
->sym
->name
, sym
->name
) == 0)
2438 def_sym
= entry
->sym
;
2443 if (sym
->attr
.function
&& !gfc_compare_types (&sym
->ts
, &def_sym
->ts
))
2445 gfc_error ("Return type mismatch of function %qs at %L (%s/%s)",
2446 sym
->name
, &sym
->declared_at
, gfc_typename (&sym
->ts
),
2447 gfc_typename (&def_sym
->ts
));
2451 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
2452 && gfc_explicit_interface_required (def_sym
, reason
, sizeof(reason
)))
2454 gfc_error ("Explicit interface required for %qs at %L: %s",
2455 sym
->name
, &sym
->declared_at
, reason
);
2459 if (!pedantic
&& (gfc_option
.allow_std
& GFC_STD_GNU
))
2460 /* Turn erros into warnings with -std=gnu and -std=legacy. */
2461 gfc_errors_to_warnings (true);
2463 if (!gfc_compare_interfaces (sym
, def_sym
, sym
->name
, 0, 1,
2464 reason
, sizeof(reason
), NULL
, NULL
))
2466 gfc_error ("Interface mismatch in global procedure %qs at %L: %s ",
2467 sym
->name
, &sym
->declared_at
, reason
);
2472 || ((gfc_option
.warn_std
& GFC_STD_LEGACY
)
2473 && !(gfc_option
.warn_std
& GFC_STD_GNU
)))
2474 gfc_errors_to_warnings (true);
2476 if (sym
->attr
.if_source
!= IFSRC_IFBODY
)
2477 gfc_procedure_use (def_sym
, actual
, where
);
2481 gfc_errors_to_warnings (false);
2483 if (gsym
->type
== GSYM_UNKNOWN
)
2486 gsym
->where
= *where
;
2493 /************* Function resolution *************/
2495 /* Resolve a function call known to be generic.
2496 Section 14.1.2.4.1. */
2499 resolve_generic_f0 (gfc_expr
*expr
, gfc_symbol
*sym
)
2503 if (sym
->attr
.generic
)
2505 s
= gfc_search_interface (sym
->generic
, 0, &expr
->value
.function
.actual
);
2508 expr
->value
.function
.name
= s
->name
;
2509 expr
->value
.function
.esym
= s
;
2511 if (s
->ts
.type
!= BT_UNKNOWN
)
2513 else if (s
->result
!= NULL
&& s
->result
->ts
.type
!= BT_UNKNOWN
)
2514 expr
->ts
= s
->result
->ts
;
2517 expr
->rank
= s
->as
->rank
;
2518 else if (s
->result
!= NULL
&& s
->result
->as
!= NULL
)
2519 expr
->rank
= s
->result
->as
->rank
;
2521 gfc_set_sym_referenced (expr
->value
.function
.esym
);
2526 /* TODO: Need to search for elemental references in generic
2530 if (sym
->attr
.intrinsic
)
2531 return gfc_intrinsic_func_interface (expr
, 0);
2538 resolve_generic_f (gfc_expr
*expr
)
2542 gfc_interface
*intr
= NULL
;
2544 sym
= expr
->symtree
->n
.sym
;
2548 m
= resolve_generic_f0 (expr
, sym
);
2551 else if (m
== MATCH_ERROR
)
2556 for (intr
= sym
->generic
; intr
; intr
= intr
->next
)
2557 if (gfc_fl_struct (intr
->sym
->attr
.flavor
))
2560 if (sym
->ns
->parent
== NULL
)
2562 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2566 if (!generic_sym (sym
))
2570 /* Last ditch attempt. See if the reference is to an intrinsic
2571 that possesses a matching interface. 14.1.2.4 */
2572 if (sym
&& !intr
&& !gfc_is_intrinsic (sym
, 0, expr
->where
))
2574 if (gfc_init_expr_flag
)
2575 gfc_error ("Function %qs in initialization expression at %L "
2576 "must be an intrinsic function",
2577 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2579 gfc_error ("There is no specific function for the generic %qs "
2580 "at %L", expr
->symtree
->n
.sym
->name
, &expr
->where
);
2586 if (!gfc_convert_to_structure_constructor (expr
, intr
->sym
, NULL
,
2589 return resolve_structure_cons (expr
, 0);
2592 m
= gfc_intrinsic_func_interface (expr
, 0);
2597 gfc_error ("Generic function %qs at %L is not consistent with a "
2598 "specific intrinsic interface", expr
->symtree
->n
.sym
->name
,
2605 /* Resolve a function call known to be specific. */
2608 resolve_specific_f0 (gfc_symbol
*sym
, gfc_expr
*expr
)
2612 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
2614 if (sym
->attr
.dummy
)
2616 sym
->attr
.proc
= PROC_DUMMY
;
2620 sym
->attr
.proc
= PROC_EXTERNAL
;
2624 if (sym
->attr
.proc
== PROC_MODULE
2625 || sym
->attr
.proc
== PROC_ST_FUNCTION
2626 || sym
->attr
.proc
== PROC_INTERNAL
)
2629 if (sym
->attr
.intrinsic
)
2631 m
= gfc_intrinsic_func_interface (expr
, 1);
2635 gfc_error ("Function %qs at %L is INTRINSIC but is not compatible "
2636 "with an intrinsic", sym
->name
, &expr
->where
);
2644 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2647 expr
->ts
= sym
->result
->ts
;
2650 expr
->value
.function
.name
= sym
->name
;
2651 expr
->value
.function
.esym
= sym
;
2652 /* Prevent crash when sym->ts.u.derived->components is not set due to previous
2654 if (sym
->ts
.type
== BT_CLASS
&& !CLASS_DATA (sym
))
2656 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->as
)
2657 expr
->rank
= CLASS_DATA (sym
)->as
->rank
;
2658 else if (sym
->as
!= NULL
)
2659 expr
->rank
= sym
->as
->rank
;
2666 resolve_specific_f (gfc_expr
*expr
)
2671 sym
= expr
->symtree
->n
.sym
;
2675 m
= resolve_specific_f0 (sym
, expr
);
2678 if (m
== MATCH_ERROR
)
2681 if (sym
->ns
->parent
== NULL
)
2684 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2690 gfc_error ("Unable to resolve the specific function %qs at %L",
2691 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2697 /* Resolve a procedure call not known to be generic nor specific. */
2700 resolve_unknown_f (gfc_expr
*expr
)
2705 sym
= expr
->symtree
->n
.sym
;
2707 if (sym
->attr
.dummy
)
2709 sym
->attr
.proc
= PROC_DUMMY
;
2710 expr
->value
.function
.name
= sym
->name
;
2714 /* See if we have an intrinsic function reference. */
2716 if (gfc_is_intrinsic (sym
, 0, expr
->where
))
2718 if (gfc_intrinsic_func_interface (expr
, 1) == MATCH_YES
)
2723 /* The reference is to an external name. */
2725 sym
->attr
.proc
= PROC_EXTERNAL
;
2726 expr
->value
.function
.name
= sym
->name
;
2727 expr
->value
.function
.esym
= expr
->symtree
->n
.sym
;
2729 if (sym
->as
!= NULL
)
2730 expr
->rank
= sym
->as
->rank
;
2732 /* Type of the expression is either the type of the symbol or the
2733 default type of the symbol. */
2736 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2738 if (sym
->ts
.type
!= BT_UNKNOWN
)
2742 ts
= gfc_get_default_type (sym
->name
, sym
->ns
);
2744 if (ts
->type
== BT_UNKNOWN
)
2746 gfc_error ("Function %qs at %L has no IMPLICIT type",
2747 sym
->name
, &expr
->where
);
2758 /* Return true, if the symbol is an external procedure. */
2760 is_external_proc (gfc_symbol
*sym
)
2762 if (!sym
->attr
.dummy
&& !sym
->attr
.contained
2763 && !gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, sym
->declared_at
)
2764 && sym
->attr
.proc
!= PROC_ST_FUNCTION
2765 && !sym
->attr
.proc_pointer
2766 && !sym
->attr
.use_assoc
2774 /* Figure out if a function reference is pure or not. Also set the name
2775 of the function for a potential error message. Return nonzero if the
2776 function is PURE, zero if not. */
2778 pure_stmt_function (gfc_expr
*, gfc_symbol
*);
2781 pure_function (gfc_expr
*e
, const char **name
)
2784 gfc_component
*comp
;
2788 if (e
->symtree
!= NULL
2789 && e
->symtree
->n
.sym
!= NULL
2790 && e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2791 return pure_stmt_function (e
, e
->symtree
->n
.sym
);
2793 comp
= gfc_get_proc_ptr_comp (e
);
2796 pure
= gfc_pure (comp
->ts
.interface
);
2799 else if (e
->value
.function
.esym
)
2801 pure
= gfc_pure (e
->value
.function
.esym
);
2802 *name
= e
->value
.function
.esym
->name
;
2804 else if (e
->value
.function
.isym
)
2806 pure
= e
->value
.function
.isym
->pure
2807 || e
->value
.function
.isym
->elemental
;
2808 *name
= e
->value
.function
.isym
->name
;
2812 /* Implicit functions are not pure. */
2814 *name
= e
->value
.function
.name
;
2822 impure_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
,
2823 int *f ATTRIBUTE_UNUSED
)
2827 /* Don't bother recursing into other statement functions
2828 since they will be checked individually for purity. */
2829 if (e
->expr_type
!= EXPR_FUNCTION
2831 || e
->symtree
->n
.sym
== sym
2832 || e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2835 return pure_function (e
, &name
) ? false : true;
2840 pure_stmt_function (gfc_expr
*e
, gfc_symbol
*sym
)
2842 return gfc_traverse_expr (e
, sym
, impure_stmt_fcn
, 0) ? 0 : 1;
2846 /* Check if an impure function is allowed in the current context. */
2848 static bool check_pure_function (gfc_expr
*e
)
2850 const char *name
= NULL
;
2851 if (!pure_function (e
, &name
) && name
)
2855 gfc_error ("Reference to impure function %qs at %L inside a "
2856 "FORALL %s", name
, &e
->where
,
2857 forall_flag
== 2 ? "mask" : "block");
2860 else if (gfc_do_concurrent_flag
)
2862 gfc_error ("Reference to impure function %qs at %L inside a "
2863 "DO CONCURRENT %s", name
, &e
->where
,
2864 gfc_do_concurrent_flag
== 2 ? "mask" : "block");
2867 else if (gfc_pure (NULL
))
2869 gfc_error ("Reference to impure function %qs at %L "
2870 "within a PURE procedure", name
, &e
->where
);
2873 gfc_unset_implicit_pure (NULL
);
2879 /* Update current procedure's array_outer_dependency flag, considering
2880 a call to procedure SYM. */
2883 update_current_proc_array_outer_dependency (gfc_symbol
*sym
)
2885 /* Check to see if this is a sibling function that has not yet
2887 gfc_namespace
*sibling
= gfc_current_ns
->sibling
;
2888 for (; sibling
; sibling
= sibling
->sibling
)
2890 if (sibling
->proc_name
== sym
)
2892 gfc_resolve (sibling
);
2897 /* If SYM has references to outer arrays, so has the procedure calling
2898 SYM. If SYM is a procedure pointer, we can assume the worst. */
2899 if (sym
->attr
.array_outer_dependency
2900 || sym
->attr
.proc_pointer
)
2901 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
2905 /* Resolve a function call, which means resolving the arguments, then figuring
2906 out which entity the name refers to. */
2909 resolve_function (gfc_expr
*expr
)
2911 gfc_actual_arglist
*arg
;
2915 procedure_type p
= PROC_INTRINSIC
;
2916 bool no_formal_args
;
2920 sym
= expr
->symtree
->n
.sym
;
2922 /* If this is a procedure pointer component, it has already been resolved. */
2923 if (gfc_is_proc_ptr_comp (expr
))
2926 /* Avoid re-resolving the arguments of caf_get, which can lead to inserting
2928 if (sym
&& sym
->attr
.intrinsic
2929 && (sym
->intmod_sym_id
== GFC_ISYM_CAF_GET
2930 || sym
->intmod_sym_id
== GFC_ISYM_CAF_SEND
))
2933 if (sym
&& sym
->attr
.intrinsic
2934 && !gfc_resolve_intrinsic (sym
, &expr
->where
))
2937 if (sym
&& (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.subroutine
))
2939 gfc_error ("%qs at %L is not a function", sym
->name
, &expr
->where
);
2943 /* If this ia a deferred TBP with an abstract interface (which may
2944 of course be referenced), expr->value.function.esym will be set. */
2945 if (sym
&& sym
->attr
.abstract
&& !expr
->value
.function
.esym
)
2947 gfc_error ("ABSTRACT INTERFACE %qs must not be referenced at %L",
2948 sym
->name
, &expr
->where
);
2952 /* Switch off assumed size checking and do this again for certain kinds
2953 of procedure, once the procedure itself is resolved. */
2954 need_full_assumed_size
++;
2956 if (expr
->symtree
&& expr
->symtree
->n
.sym
)
2957 p
= expr
->symtree
->n
.sym
->attr
.proc
;
2959 if (expr
->value
.function
.isym
&& expr
->value
.function
.isym
->inquiry
)
2960 inquiry_argument
= true;
2961 no_formal_args
= sym
&& is_external_proc (sym
)
2962 && gfc_sym_get_dummy_args (sym
) == NULL
;
2964 if (!resolve_actual_arglist (expr
->value
.function
.actual
,
2967 inquiry_argument
= false;
2971 inquiry_argument
= false;
2973 /* Resume assumed_size checking. */
2974 need_full_assumed_size
--;
2976 /* If the procedure is external, check for usage. */
2977 if (sym
&& is_external_proc (sym
))
2978 resolve_global_procedure (sym
, &expr
->where
,
2979 &expr
->value
.function
.actual
, 0);
2981 if (sym
&& sym
->ts
.type
== BT_CHARACTER
2983 && sym
->ts
.u
.cl
->length
== NULL
2985 && !sym
->ts
.deferred
2986 && expr
->value
.function
.esym
== NULL
2987 && !sym
->attr
.contained
)
2989 /* Internal procedures are taken care of in resolve_contained_fntype. */
2990 gfc_error ("Function %qs is declared CHARACTER(*) and cannot "
2991 "be used at %L since it is not a dummy argument",
2992 sym
->name
, &expr
->where
);
2996 /* See if function is already resolved. */
2998 if (expr
->value
.function
.name
!= NULL
2999 || expr
->value
.function
.isym
!= NULL
)
3001 if (expr
->ts
.type
== BT_UNKNOWN
)
3007 /* Apply the rules of section 14.1.2. */
3009 switch (procedure_kind (sym
))
3012 t
= resolve_generic_f (expr
);
3015 case PTYPE_SPECIFIC
:
3016 t
= resolve_specific_f (expr
);
3020 t
= resolve_unknown_f (expr
);
3024 gfc_internal_error ("resolve_function(): bad function type");
3028 /* If the expression is still a function (it might have simplified),
3029 then we check to see if we are calling an elemental function. */
3031 if (expr
->expr_type
!= EXPR_FUNCTION
)
3034 temp
= need_full_assumed_size
;
3035 need_full_assumed_size
= 0;
3037 if (!resolve_elemental_actual (expr
, NULL
))
3040 if (omp_workshare_flag
3041 && expr
->value
.function
.esym
3042 && ! gfc_elemental (expr
->value
.function
.esym
))
3044 gfc_error ("User defined non-ELEMENTAL function %qs at %L not allowed "
3045 "in WORKSHARE construct", expr
->value
.function
.esym
->name
,
3050 #define GENERIC_ID expr->value.function.isym->id
3051 else if (expr
->value
.function
.actual
!= NULL
3052 && expr
->value
.function
.isym
!= NULL
3053 && GENERIC_ID
!= GFC_ISYM_LBOUND
3054 && GENERIC_ID
!= GFC_ISYM_LCOBOUND
3055 && GENERIC_ID
!= GFC_ISYM_UCOBOUND
3056 && GENERIC_ID
!= GFC_ISYM_LEN
3057 && GENERIC_ID
!= GFC_ISYM_LOC
3058 && GENERIC_ID
!= GFC_ISYM_C_LOC
3059 && GENERIC_ID
!= GFC_ISYM_PRESENT
)
3061 /* Array intrinsics must also have the last upper bound of an
3062 assumed size array argument. UBOUND and SIZE have to be
3063 excluded from the check if the second argument is anything
3066 for (arg
= expr
->value
.function
.actual
; arg
; arg
= arg
->next
)
3068 if ((GENERIC_ID
== GFC_ISYM_UBOUND
|| GENERIC_ID
== GFC_ISYM_SIZE
)
3069 && arg
== expr
->value
.function
.actual
3070 && arg
->next
!= NULL
&& arg
->next
->expr
)
3072 if (arg
->next
->expr
->expr_type
!= EXPR_CONSTANT
)
3075 if (arg
->next
->name
&& strncmp (arg
->next
->name
, "kind", 4) == 0)
3078 if ((int)mpz_get_si (arg
->next
->expr
->value
.integer
)
3083 if (arg
->expr
!= NULL
3084 && arg
->expr
->rank
> 0
3085 && resolve_assumed_size_actual (arg
->expr
))
3091 need_full_assumed_size
= temp
;
3093 if (!check_pure_function(expr
))
3096 /* Functions without the RECURSIVE attribution are not allowed to
3097 * call themselves. */
3098 if (expr
->value
.function
.esym
&& !expr
->value
.function
.esym
->attr
.recursive
)
3101 esym
= expr
->value
.function
.esym
;
3103 if (is_illegal_recursion (esym
, gfc_current_ns
))
3105 if (esym
->attr
.entry
&& esym
->ns
->entries
)
3106 gfc_error ("ENTRY %qs at %L cannot be called recursively, as"
3107 " function %qs is not RECURSIVE",
3108 esym
->name
, &expr
->where
, esym
->ns
->entries
->sym
->name
);
3110 gfc_error ("Function %qs at %L cannot be called recursively, as it"
3111 " is not RECURSIVE", esym
->name
, &expr
->where
);
3117 /* Character lengths of use associated functions may contains references to
3118 symbols not referenced from the current program unit otherwise. Make sure
3119 those symbols are marked as referenced. */
3121 if (expr
->ts
.type
== BT_CHARACTER
&& expr
->value
.function
.esym
3122 && expr
->value
.function
.esym
->attr
.use_assoc
)
3124 gfc_expr_set_symbols_referenced (expr
->ts
.u
.cl
->length
);
3127 /* Make sure that the expression has a typespec that works. */
3128 if (expr
->ts
.type
== BT_UNKNOWN
)
3130 if (expr
->symtree
->n
.sym
->result
3131 && expr
->symtree
->n
.sym
->result
->ts
.type
!= BT_UNKNOWN
3132 && !expr
->symtree
->n
.sym
->result
->attr
.proc_pointer
)
3133 expr
->ts
= expr
->symtree
->n
.sym
->result
->ts
;
3136 if (!expr
->ref
&& !expr
->value
.function
.isym
)
3138 if (expr
->value
.function
.esym
)
3139 update_current_proc_array_outer_dependency (expr
->value
.function
.esym
);
3141 update_current_proc_array_outer_dependency (sym
);
3144 /* typebound procedure: Assume the worst. */
3145 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
3151 /************* Subroutine resolution *************/
3154 pure_subroutine (gfc_symbol
*sym
, const char *name
, locus
*loc
)
3161 gfc_error ("Subroutine call to %qs in FORALL block at %L is not PURE",
3165 else if (gfc_do_concurrent_flag
)
3167 gfc_error ("Subroutine call to %qs in DO CONCURRENT block at %L is not "
3171 else if (gfc_pure (NULL
))
3173 gfc_error ("Subroutine call to %qs at %L is not PURE", name
, loc
);
3177 gfc_unset_implicit_pure (NULL
);
3183 resolve_generic_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3187 if (sym
->attr
.generic
)
3189 s
= gfc_search_interface (sym
->generic
, 1, &c
->ext
.actual
);
3192 c
->resolved_sym
= s
;
3193 if (!pure_subroutine (s
, s
->name
, &c
->loc
))
3198 /* TODO: Need to search for elemental references in generic interface. */
3201 if (sym
->attr
.intrinsic
)
3202 return gfc_intrinsic_sub_interface (c
, 0);
3209 resolve_generic_s (gfc_code
*c
)
3214 sym
= c
->symtree
->n
.sym
;
3218 m
= resolve_generic_s0 (c
, sym
);
3221 else if (m
== MATCH_ERROR
)
3225 if (sym
->ns
->parent
== NULL
)
3227 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3231 if (!generic_sym (sym
))
3235 /* Last ditch attempt. See if the reference is to an intrinsic
3236 that possesses a matching interface. 14.1.2.4 */
3237 sym
= c
->symtree
->n
.sym
;
3239 if (!gfc_is_intrinsic (sym
, 1, c
->loc
))
3241 gfc_error ("There is no specific subroutine for the generic %qs at %L",
3242 sym
->name
, &c
->loc
);
3246 m
= gfc_intrinsic_sub_interface (c
, 0);
3250 gfc_error ("Generic subroutine %qs at %L is not consistent with an "
3251 "intrinsic subroutine interface", sym
->name
, &c
->loc
);
3257 /* Resolve a subroutine call known to be specific. */
3260 resolve_specific_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3264 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
3266 if (sym
->attr
.dummy
)
3268 sym
->attr
.proc
= PROC_DUMMY
;
3272 sym
->attr
.proc
= PROC_EXTERNAL
;
3276 if (sym
->attr
.proc
== PROC_MODULE
|| sym
->attr
.proc
== PROC_INTERNAL
)
3279 if (sym
->attr
.intrinsic
)
3281 m
= gfc_intrinsic_sub_interface (c
, 1);
3285 gfc_error ("Subroutine %qs at %L is INTRINSIC but is not compatible "
3286 "with an intrinsic", sym
->name
, &c
->loc
);
3294 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3296 c
->resolved_sym
= sym
;
3297 if (!pure_subroutine (sym
, sym
->name
, &c
->loc
))
3305 resolve_specific_s (gfc_code
*c
)
3310 sym
= c
->symtree
->n
.sym
;
3314 m
= resolve_specific_s0 (c
, sym
);
3317 if (m
== MATCH_ERROR
)
3320 if (sym
->ns
->parent
== NULL
)
3323 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3329 sym
= c
->symtree
->n
.sym
;
3330 gfc_error ("Unable to resolve the specific subroutine %qs at %L",
3331 sym
->name
, &c
->loc
);
3337 /* Resolve a subroutine call not known to be generic nor specific. */
3340 resolve_unknown_s (gfc_code
*c
)
3344 sym
= c
->symtree
->n
.sym
;
3346 if (sym
->attr
.dummy
)
3348 sym
->attr
.proc
= PROC_DUMMY
;
3352 /* See if we have an intrinsic function reference. */
3354 if (gfc_is_intrinsic (sym
, 1, c
->loc
))
3356 if (gfc_intrinsic_sub_interface (c
, 1) == MATCH_YES
)
3361 /* The reference is to an external name. */
3364 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3366 c
->resolved_sym
= sym
;
3368 return pure_subroutine (sym
, sym
->name
, &c
->loc
);
3372 /* Resolve a subroutine call. Although it was tempting to use the same code
3373 for functions, subroutines and functions are stored differently and this
3374 makes things awkward. */
3377 resolve_call (gfc_code
*c
)
3380 procedure_type ptype
= PROC_INTRINSIC
;
3381 gfc_symbol
*csym
, *sym
;
3382 bool no_formal_args
;
3384 csym
= c
->symtree
? c
->symtree
->n
.sym
: NULL
;
3386 if (csym
&& csym
->ts
.type
!= BT_UNKNOWN
)
3388 gfc_error ("%qs at %L has a type, which is not consistent with "
3389 "the CALL at %L", csym
->name
, &csym
->declared_at
, &c
->loc
);
3393 if (csym
&& gfc_current_ns
->parent
&& csym
->ns
!= gfc_current_ns
)
3396 gfc_find_sym_tree (c
->symtree
->name
, gfc_current_ns
, 1, &st
);
3397 sym
= st
? st
->n
.sym
: NULL
;
3398 if (sym
&& csym
!= sym
3399 && sym
->ns
== gfc_current_ns
3400 && sym
->attr
.flavor
== FL_PROCEDURE
3401 && sym
->attr
.contained
)
3404 if (csym
->attr
.generic
)
3405 c
->symtree
->n
.sym
= sym
;
3408 csym
= c
->symtree
->n
.sym
;
3412 /* If this ia a deferred TBP, c->expr1 will be set. */
3413 if (!c
->expr1
&& csym
)
3415 if (csym
->attr
.abstract
)
3417 gfc_error ("ABSTRACT INTERFACE %qs must not be referenced at %L",
3418 csym
->name
, &c
->loc
);
3422 /* Subroutines without the RECURSIVE attribution are not allowed to
3424 if (is_illegal_recursion (csym
, gfc_current_ns
))
3426 if (csym
->attr
.entry
&& csym
->ns
->entries
)
3427 gfc_error ("ENTRY %qs at %L cannot be called recursively, "
3428 "as subroutine %qs is not RECURSIVE",
3429 csym
->name
, &c
->loc
, csym
->ns
->entries
->sym
->name
);
3431 gfc_error ("SUBROUTINE %qs at %L cannot be called recursively, "
3432 "as it is not RECURSIVE", csym
->name
, &c
->loc
);
3438 /* Switch off assumed size checking and do this again for certain kinds
3439 of procedure, once the procedure itself is resolved. */
3440 need_full_assumed_size
++;
3443 ptype
= csym
->attr
.proc
;
3445 no_formal_args
= csym
&& is_external_proc (csym
)
3446 && gfc_sym_get_dummy_args (csym
) == NULL
;
3447 if (!resolve_actual_arglist (c
->ext
.actual
, ptype
, no_formal_args
))
3450 /* Resume assumed_size checking. */
3451 need_full_assumed_size
--;
3453 /* If external, check for usage. */
3454 if (csym
&& is_external_proc (csym
))
3455 resolve_global_procedure (csym
, &c
->loc
, &c
->ext
.actual
, 1);
3458 if (c
->resolved_sym
== NULL
)
3460 c
->resolved_isym
= NULL
;
3461 switch (procedure_kind (csym
))
3464 t
= resolve_generic_s (c
);
3467 case PTYPE_SPECIFIC
:
3468 t
= resolve_specific_s (c
);
3472 t
= resolve_unknown_s (c
);
3476 gfc_internal_error ("resolve_subroutine(): bad function type");
3480 /* Some checks of elemental subroutine actual arguments. */
3481 if (!resolve_elemental_actual (NULL
, c
))
3485 update_current_proc_array_outer_dependency (csym
);
3487 /* Typebound procedure: Assume the worst. */
3488 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
3494 /* Compare the shapes of two arrays that have non-NULL shapes. If both
3495 op1->shape and op2->shape are non-NULL return true if their shapes
3496 match. If both op1->shape and op2->shape are non-NULL return false
3497 if their shapes do not match. If either op1->shape or op2->shape is
3498 NULL, return true. */
3501 compare_shapes (gfc_expr
*op1
, gfc_expr
*op2
)
3508 if (op1
->shape
!= NULL
&& op2
->shape
!= NULL
)
3510 for (i
= 0; i
< op1
->rank
; i
++)
3512 if (mpz_cmp (op1
->shape
[i
], op2
->shape
[i
]) != 0)
3514 gfc_error ("Shapes for operands at %L and %L are not conformable",
3515 &op1
->where
, &op2
->where
);
3526 /* Resolve an operator expression node. This can involve replacing the
3527 operation with a user defined function call. */
3530 resolve_operator (gfc_expr
*e
)
3532 gfc_expr
*op1
, *op2
;
3534 bool dual_locus_error
;
3537 /* Resolve all subnodes-- give them types. */
3539 switch (e
->value
.op
.op
)
3542 if (!gfc_resolve_expr (e
->value
.op
.op2
))
3545 /* Fall through... */
3548 case INTRINSIC_UPLUS
:
3549 case INTRINSIC_UMINUS
:
3550 case INTRINSIC_PARENTHESES
:
3551 if (!gfc_resolve_expr (e
->value
.op
.op1
))
3556 /* Typecheck the new node. */
3558 op1
= e
->value
.op
.op1
;
3559 op2
= e
->value
.op
.op2
;
3560 dual_locus_error
= false;
3562 if ((op1
&& op1
->expr_type
== EXPR_NULL
)
3563 || (op2
&& op2
->expr_type
== EXPR_NULL
))
3565 sprintf (msg
, _("Invalid context for NULL() pointer at %%L"));
3569 switch (e
->value
.op
.op
)
3571 case INTRINSIC_UPLUS
:
3572 case INTRINSIC_UMINUS
:
3573 if (op1
->ts
.type
== BT_INTEGER
3574 || op1
->ts
.type
== BT_REAL
3575 || op1
->ts
.type
== BT_COMPLEX
)
3581 sprintf (msg
, _("Operand of unary numeric operator %%<%s%%> at %%L is %s"),
3582 gfc_op2string (e
->value
.op
.op
), gfc_typename (&e
->ts
));
3585 case INTRINSIC_PLUS
:
3586 case INTRINSIC_MINUS
:
3587 case INTRINSIC_TIMES
:
3588 case INTRINSIC_DIVIDE
:
3589 case INTRINSIC_POWER
:
3590 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3592 gfc_type_convert_binary (e
, 1);
3597 _("Operands of binary numeric operator %%<%s%%> at %%L are %s/%s"),
3598 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3599 gfc_typename (&op2
->ts
));
3602 case INTRINSIC_CONCAT
:
3603 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3604 && op1
->ts
.kind
== op2
->ts
.kind
)
3606 e
->ts
.type
= BT_CHARACTER
;
3607 e
->ts
.kind
= op1
->ts
.kind
;
3612 _("Operands of string concatenation operator at %%L are %s/%s"),
3613 gfc_typename (&op1
->ts
), gfc_typename (&op2
->ts
));
3619 case INTRINSIC_NEQV
:
3620 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3622 e
->ts
.type
= BT_LOGICAL
;
3623 e
->ts
.kind
= gfc_kind_max (op1
, op2
);
3624 if (op1
->ts
.kind
< e
->ts
.kind
)
3625 gfc_convert_type (op1
, &e
->ts
, 2);
3626 else if (op2
->ts
.kind
< e
->ts
.kind
)
3627 gfc_convert_type (op2
, &e
->ts
, 2);
3631 sprintf (msg
, _("Operands of logical operator %%<%s%%> at %%L are %s/%s"),
3632 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3633 gfc_typename (&op2
->ts
));
3638 if (op1
->ts
.type
== BT_LOGICAL
)
3640 e
->ts
.type
= BT_LOGICAL
;
3641 e
->ts
.kind
= op1
->ts
.kind
;
3645 sprintf (msg
, _("Operand of .not. operator at %%L is %s"),
3646 gfc_typename (&op1
->ts
));
3650 case INTRINSIC_GT_OS
:
3652 case INTRINSIC_GE_OS
:
3654 case INTRINSIC_LT_OS
:
3656 case INTRINSIC_LE_OS
:
3657 if (op1
->ts
.type
== BT_COMPLEX
|| op2
->ts
.type
== BT_COMPLEX
)
3659 strcpy (msg
, _("COMPLEX quantities cannot be compared at %L"));
3663 /* Fall through... */
3666 case INTRINSIC_EQ_OS
:
3668 case INTRINSIC_NE_OS
:
3669 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3670 && op1
->ts
.kind
== op2
->ts
.kind
)
3672 e
->ts
.type
= BT_LOGICAL
;
3673 e
->ts
.kind
= gfc_default_logical_kind
;
3677 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3679 gfc_type_convert_binary (e
, 1);
3681 e
->ts
.type
= BT_LOGICAL
;
3682 e
->ts
.kind
= gfc_default_logical_kind
;
3684 if (warn_compare_reals
)
3686 gfc_intrinsic_op op
= e
->value
.op
.op
;
3688 /* Type conversion has made sure that the types of op1 and op2
3689 agree, so it is only necessary to check the first one. */
3690 if ((op1
->ts
.type
== BT_REAL
|| op1
->ts
.type
== BT_COMPLEX
)
3691 && (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
3692 || op
== INTRINSIC_NE
|| op
== INTRINSIC_NE_OS
))
3696 if (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
)
3697 msg
= "Equality comparison for %s at %L";
3699 msg
= "Inequality comparison for %s at %L";
3701 gfc_warning (0, msg
, gfc_typename (&op1
->ts
), &op1
->where
);
3708 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3710 _("Logicals at %%L must be compared with %s instead of %s"),
3711 (e
->value
.op
.op
== INTRINSIC_EQ
3712 || e
->value
.op
.op
== INTRINSIC_EQ_OS
)
3713 ? ".eqv." : ".neqv.", gfc_op2string (e
->value
.op
.op
));
3716 _("Operands of comparison operator %%<%s%%> at %%L are %s/%s"),
3717 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3718 gfc_typename (&op2
->ts
));
3722 case INTRINSIC_USER
:
3723 if (e
->value
.op
.uop
->op
== NULL
)
3724 sprintf (msg
, _("Unknown operator %%<%s%%> at %%L"),
3725 e
->value
.op
.uop
->name
);
3726 else if (op2
== NULL
)
3727 sprintf (msg
, _("Operand of user operator %%<%s%%> at %%L is %s"),
3728 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
));
3731 sprintf (msg
, _("Operands of user operator %%<%s%%> at %%L are %s/%s"),
3732 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
),
3733 gfc_typename (&op2
->ts
));
3734 e
->value
.op
.uop
->op
->sym
->attr
.referenced
= 1;
3739 case INTRINSIC_PARENTHESES
:
3741 if (e
->ts
.type
== BT_CHARACTER
)
3742 e
->ts
.u
.cl
= op1
->ts
.u
.cl
;
3746 gfc_internal_error ("resolve_operator(): Bad intrinsic");
3749 /* Deal with arrayness of an operand through an operator. */
3753 switch (e
->value
.op
.op
)
3755 case INTRINSIC_PLUS
:
3756 case INTRINSIC_MINUS
:
3757 case INTRINSIC_TIMES
:
3758 case INTRINSIC_DIVIDE
:
3759 case INTRINSIC_POWER
:
3760 case INTRINSIC_CONCAT
:
3764 case INTRINSIC_NEQV
:
3766 case INTRINSIC_EQ_OS
:
3768 case INTRINSIC_NE_OS
:
3770 case INTRINSIC_GT_OS
:
3772 case INTRINSIC_GE_OS
:
3774 case INTRINSIC_LT_OS
:
3776 case INTRINSIC_LE_OS
:
3778 if (op1
->rank
== 0 && op2
->rank
== 0)
3781 if (op1
->rank
== 0 && op2
->rank
!= 0)
3783 e
->rank
= op2
->rank
;
3785 if (e
->shape
== NULL
)
3786 e
->shape
= gfc_copy_shape (op2
->shape
, op2
->rank
);
3789 if (op1
->rank
!= 0 && op2
->rank
== 0)
3791 e
->rank
= op1
->rank
;
3793 if (e
->shape
== NULL
)
3794 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3797 if (op1
->rank
!= 0 && op2
->rank
!= 0)
3799 if (op1
->rank
== op2
->rank
)
3801 e
->rank
= op1
->rank
;
3802 if (e
->shape
== NULL
)
3804 t
= compare_shapes (op1
, op2
);
3808 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3813 /* Allow higher level expressions to work. */
3816 /* Try user-defined operators, and otherwise throw an error. */
3817 dual_locus_error
= true;
3819 _("Inconsistent ranks for operator at %%L and %%L"));
3826 case INTRINSIC_PARENTHESES
:
3828 case INTRINSIC_UPLUS
:
3829 case INTRINSIC_UMINUS
:
3830 /* Simply copy arrayness attribute */
3831 e
->rank
= op1
->rank
;
3833 if (e
->shape
== NULL
)
3834 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3842 /* Attempt to simplify the expression. */
3845 t
= gfc_simplify_expr (e
, 0);
3846 /* Some calls do not succeed in simplification and return false
3847 even though there is no error; e.g. variable references to
3848 PARAMETER arrays. */
3849 if (!gfc_is_constant_expr (e
))
3857 match m
= gfc_extend_expr (e
);
3860 if (m
== MATCH_ERROR
)
3864 if (dual_locus_error
)
3865 gfc_error (msg
, &op1
->where
, &op2
->where
);
3867 gfc_error (msg
, &e
->where
);
3873 /************** Array resolution subroutines **************/
3876 { CMP_LT
, CMP_EQ
, CMP_GT
, CMP_UNKNOWN
};
3878 /* Compare two integer expressions. */
3880 static compare_result
3881 compare_bound (gfc_expr
*a
, gfc_expr
*b
)
3885 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
3886 || b
== NULL
|| b
->expr_type
!= EXPR_CONSTANT
)
3889 /* If either of the types isn't INTEGER, we must have
3890 raised an error earlier. */
3892 if (a
->ts
.type
!= BT_INTEGER
|| b
->ts
.type
!= BT_INTEGER
)
3895 i
= mpz_cmp (a
->value
.integer
, b
->value
.integer
);
3905 /* Compare an integer expression with an integer. */
3907 static compare_result
3908 compare_bound_int (gfc_expr
*a
, int b
)
3912 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3915 if (a
->ts
.type
!= BT_INTEGER
)
3916 gfc_internal_error ("compare_bound_int(): Bad expression");
3918 i
= mpz_cmp_si (a
->value
.integer
, b
);
3928 /* Compare an integer expression with a mpz_t. */
3930 static compare_result
3931 compare_bound_mpz_t (gfc_expr
*a
, mpz_t b
)
3935 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3938 if (a
->ts
.type
!= BT_INTEGER
)
3939 gfc_internal_error ("compare_bound_int(): Bad expression");
3941 i
= mpz_cmp (a
->value
.integer
, b
);
3951 /* Compute the last value of a sequence given by a triplet.
3952 Return 0 if it wasn't able to compute the last value, or if the
3953 sequence if empty, and 1 otherwise. */
3956 compute_last_value_for_triplet (gfc_expr
*start
, gfc_expr
*end
,
3957 gfc_expr
*stride
, mpz_t last
)
3961 if (start
== NULL
|| start
->expr_type
!= EXPR_CONSTANT
3962 || end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
3963 || (stride
!= NULL
&& stride
->expr_type
!= EXPR_CONSTANT
))
3966 if (start
->ts
.type
!= BT_INTEGER
|| end
->ts
.type
!= BT_INTEGER
3967 || (stride
!= NULL
&& stride
->ts
.type
!= BT_INTEGER
))
3970 if (stride
== NULL
|| compare_bound_int (stride
, 1) == CMP_EQ
)
3972 if (compare_bound (start
, end
) == CMP_GT
)
3974 mpz_set (last
, end
->value
.integer
);
3978 if (compare_bound_int (stride
, 0) == CMP_GT
)
3980 /* Stride is positive */
3981 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) > 0)
3986 /* Stride is negative */
3987 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) < 0)
3992 mpz_sub (rem
, end
->value
.integer
, start
->value
.integer
);
3993 mpz_tdiv_r (rem
, rem
, stride
->value
.integer
);
3994 mpz_sub (last
, end
->value
.integer
, rem
);
4001 /* Compare a single dimension of an array reference to the array
4005 check_dimension (int i
, gfc_array_ref
*ar
, gfc_array_spec
*as
)
4009 if (ar
->dimen_type
[i
] == DIMEN_STAR
)
4011 gcc_assert (ar
->stride
[i
] == NULL
);
4012 /* This implies [*] as [*:] and [*:3] are not possible. */
4013 if (ar
->start
[i
] == NULL
)
4015 gcc_assert (ar
->end
[i
] == NULL
);
4020 /* Given start, end and stride values, calculate the minimum and
4021 maximum referenced indexes. */
4023 switch (ar
->dimen_type
[i
])
4026 case DIMEN_THIS_IMAGE
:
4031 if (compare_bound (ar
->start
[i
], as
->lower
[i
]) == CMP_LT
)
4034 gfc_warning (0, "Array reference at %L is out of bounds "
4035 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4036 mpz_get_si (ar
->start
[i
]->value
.integer
),
4037 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4039 gfc_warning (0, "Array reference at %L is out of bounds "
4040 "(%ld < %ld) in codimension %d", &ar
->c_where
[i
],
4041 mpz_get_si (ar
->start
[i
]->value
.integer
),
4042 mpz_get_si (as
->lower
[i
]->value
.integer
),
4046 if (compare_bound (ar
->start
[i
], as
->upper
[i
]) == CMP_GT
)
4049 gfc_warning (0, "Array reference at %L is out of bounds "
4050 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4051 mpz_get_si (ar
->start
[i
]->value
.integer
),
4052 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4054 gfc_warning (0, "Array reference at %L is out of bounds "
4055 "(%ld > %ld) in codimension %d", &ar
->c_where
[i
],
4056 mpz_get_si (ar
->start
[i
]->value
.integer
),
4057 mpz_get_si (as
->upper
[i
]->value
.integer
),
4066 #define AR_START (ar->start[i] ? ar->start[i] : as->lower[i])
4067 #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i])
4069 compare_result comp_start_end
= compare_bound (AR_START
, AR_END
);
4071 /* Check for zero stride, which is not allowed. */
4072 if (compare_bound_int (ar
->stride
[i
], 0) == CMP_EQ
)
4074 gfc_error ("Illegal stride of zero at %L", &ar
->c_where
[i
]);
4078 /* if start == len || (stride > 0 && start < len)
4079 || (stride < 0 && start > len),
4080 then the array section contains at least one element. In this
4081 case, there is an out-of-bounds access if
4082 (start < lower || start > upper). */
4083 if (compare_bound (AR_START
, AR_END
) == CMP_EQ
4084 || ((compare_bound_int (ar
->stride
[i
], 0) == CMP_GT
4085 || ar
->stride
[i
] == NULL
) && comp_start_end
== CMP_LT
)
4086 || (compare_bound_int (ar
->stride
[i
], 0) == CMP_LT
4087 && comp_start_end
== CMP_GT
))
4089 if (compare_bound (AR_START
, as
->lower
[i
]) == CMP_LT
)
4091 gfc_warning (0, "Lower array reference at %L is out of bounds "
4092 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4093 mpz_get_si (AR_START
->value
.integer
),
4094 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4097 if (compare_bound (AR_START
, as
->upper
[i
]) == CMP_GT
)
4099 gfc_warning (0, "Lower array reference at %L is out of bounds "
4100 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4101 mpz_get_si (AR_START
->value
.integer
),
4102 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4107 /* If we can compute the highest index of the array section,
4108 then it also has to be between lower and upper. */
4109 mpz_init (last_value
);
4110 if (compute_last_value_for_triplet (AR_START
, AR_END
, ar
->stride
[i
],
4113 if (compare_bound_mpz_t (as
->lower
[i
], last_value
) == CMP_GT
)
4115 gfc_warning (0, "Upper array reference at %L is out of bounds "
4116 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4117 mpz_get_si (last_value
),
4118 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4119 mpz_clear (last_value
);
4122 if (compare_bound_mpz_t (as
->upper
[i
], last_value
) == CMP_LT
)
4124 gfc_warning (0, "Upper array reference at %L is out of bounds "
4125 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4126 mpz_get_si (last_value
),
4127 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4128 mpz_clear (last_value
);
4132 mpz_clear (last_value
);
4140 gfc_internal_error ("check_dimension(): Bad array reference");
4147 /* Compare an array reference with an array specification. */
4150 compare_spec_to_ref (gfc_array_ref
*ar
)
4157 /* TODO: Full array sections are only allowed as actual parameters. */
4158 if (as
->type
== AS_ASSUMED_SIZE
4159 && (/*ar->type == AR_FULL
4160 ||*/ (ar
->type
== AR_SECTION
4161 && ar
->dimen_type
[i
] == DIMEN_RANGE
&& ar
->end
[i
] == NULL
)))
4163 gfc_error ("Rightmost upper bound of assumed size array section "
4164 "not specified at %L", &ar
->where
);
4168 if (ar
->type
== AR_FULL
)
4171 if (as
->rank
!= ar
->dimen
)
4173 gfc_error ("Rank mismatch in array reference at %L (%d/%d)",
4174 &ar
->where
, ar
->dimen
, as
->rank
);
4178 /* ar->codimen == 0 is a local array. */
4179 if (as
->corank
!= ar
->codimen
&& ar
->codimen
!= 0)
4181 gfc_error ("Coindex rank mismatch in array reference at %L (%d/%d)",
4182 &ar
->where
, ar
->codimen
, as
->corank
);
4186 for (i
= 0; i
< as
->rank
; i
++)
4187 if (!check_dimension (i
, ar
, as
))
4190 /* Local access has no coarray spec. */
4191 if (ar
->codimen
!= 0)
4192 for (i
= as
->rank
; i
< as
->rank
+ as
->corank
; i
++)
4194 if (ar
->dimen_type
[i
] != DIMEN_ELEMENT
&& !ar
->in_allocate
4195 && ar
->dimen_type
[i
] != DIMEN_THIS_IMAGE
)
4197 gfc_error ("Coindex of codimension %d must be a scalar at %L",
4198 i
+ 1 - as
->rank
, &ar
->where
);
4201 if (!check_dimension (i
, ar
, as
))
4209 /* Resolve one part of an array index. */
4212 gfc_resolve_index_1 (gfc_expr
*index
, int check_scalar
,
4213 int force_index_integer_kind
)
4220 if (!gfc_resolve_expr (index
))
4223 if (check_scalar
&& index
->rank
!= 0)
4225 gfc_error ("Array index at %L must be scalar", &index
->where
);
4229 if (index
->ts
.type
!= BT_INTEGER
&& index
->ts
.type
!= BT_REAL
)
4231 gfc_error ("Array index at %L must be of INTEGER type, found %s",
4232 &index
->where
, gfc_basic_typename (index
->ts
.type
));
4236 if (index
->ts
.type
== BT_REAL
)
4237 if (!gfc_notify_std (GFC_STD_LEGACY
, "REAL array index at %L",
4241 if ((index
->ts
.kind
!= gfc_index_integer_kind
4242 && force_index_integer_kind
)
4243 || index
->ts
.type
!= BT_INTEGER
)
4246 ts
.type
= BT_INTEGER
;
4247 ts
.kind
= gfc_index_integer_kind
;
4249 gfc_convert_type_warn (index
, &ts
, 2, 0);
4255 /* Resolve one part of an array index. */
4258 gfc_resolve_index (gfc_expr
*index
, int check_scalar
)
4260 return gfc_resolve_index_1 (index
, check_scalar
, 1);
4263 /* Resolve a dim argument to an intrinsic function. */
4266 gfc_resolve_dim_arg (gfc_expr
*dim
)
4271 if (!gfc_resolve_expr (dim
))
4276 gfc_error ("Argument dim at %L must be scalar", &dim
->where
);
4281 if (dim
->ts
.type
!= BT_INTEGER
)
4283 gfc_error ("Argument dim at %L must be of INTEGER type", &dim
->where
);
4287 if (dim
->ts
.kind
!= gfc_index_integer_kind
)
4292 ts
.type
= BT_INTEGER
;
4293 ts
.kind
= gfc_index_integer_kind
;
4295 gfc_convert_type_warn (dim
, &ts
, 2, 0);
4301 /* Given an expression that contains array references, update those array
4302 references to point to the right array specifications. While this is
4303 filled in during matching, this information is difficult to save and load
4304 in a module, so we take care of it here.
4306 The idea here is that the original array reference comes from the
4307 base symbol. We traverse the list of reference structures, setting
4308 the stored reference to references. Component references can
4309 provide an additional array specification. */
4312 find_array_spec (gfc_expr
*e
)
4318 if (e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
)
4319 as
= CLASS_DATA (e
->symtree
->n
.sym
)->as
;
4321 as
= e
->symtree
->n
.sym
->as
;
4323 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4328 gfc_internal_error ("find_array_spec(): Missing spec");
4335 c
= ref
->u
.c
.component
;
4336 if (c
->attr
.dimension
)
4339 gfc_internal_error ("find_array_spec(): unused as(1)");
4350 gfc_internal_error ("find_array_spec(): unused as(2)");
4354 /* Resolve an array reference. */
4357 resolve_array_ref (gfc_array_ref
*ar
)
4359 int i
, check_scalar
;
4362 for (i
= 0; i
< ar
->dimen
+ ar
->codimen
; i
++)
4364 check_scalar
= ar
->dimen_type
[i
] == DIMEN_RANGE
;
4366 /* Do not force gfc_index_integer_kind for the start. We can
4367 do fine with any integer kind. This avoids temporary arrays
4368 created for indexing with a vector. */
4369 if (!gfc_resolve_index_1 (ar
->start
[i
], check_scalar
, 0))
4371 if (!gfc_resolve_index (ar
->end
[i
], check_scalar
))
4373 if (!gfc_resolve_index (ar
->stride
[i
], check_scalar
))
4378 if (ar
->dimen_type
[i
] == DIMEN_UNKNOWN
)
4382 ar
->dimen_type
[i
] = DIMEN_ELEMENT
;
4386 ar
->dimen_type
[i
] = DIMEN_VECTOR
;
4387 if (e
->expr_type
== EXPR_VARIABLE
4388 && e
->symtree
->n
.sym
->ts
.type
== BT_DERIVED
)
4389 ar
->start
[i
] = gfc_get_parentheses (e
);
4393 gfc_error ("Array index at %L is an array of rank %d",
4394 &ar
->c_where
[i
], e
->rank
);
4398 /* Fill in the upper bound, which may be lower than the
4399 specified one for something like a(2:10:5), which is
4400 identical to a(2:7:5). Only relevant for strides not equal
4401 to one. Don't try a division by zero. */
4402 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4403 && ar
->stride
[i
] != NULL
&& ar
->stride
[i
]->expr_type
== EXPR_CONSTANT
4404 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 1L) != 0
4405 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 0L) != 0)
4409 if (gfc_ref_dimen_size (ar
, i
, &size
, &end
))
4411 if (ar
->end
[i
] == NULL
)
4414 gfc_get_constant_expr (BT_INTEGER
, gfc_index_integer_kind
,
4416 mpz_set (ar
->end
[i
]->value
.integer
, end
);
4418 else if (ar
->end
[i
]->ts
.type
== BT_INTEGER
4419 && ar
->end
[i
]->expr_type
== EXPR_CONSTANT
)
4421 mpz_set (ar
->end
[i
]->value
.integer
, end
);
4432 if (ar
->type
== AR_FULL
)
4434 if (ar
->as
->rank
== 0)
4435 ar
->type
= AR_ELEMENT
;
4437 /* Make sure array is the same as array(:,:), this way
4438 we don't need to special case all the time. */
4439 ar
->dimen
= ar
->as
->rank
;
4440 for (i
= 0; i
< ar
->dimen
; i
++)
4442 ar
->dimen_type
[i
] = DIMEN_RANGE
;
4444 gcc_assert (ar
->start
[i
] == NULL
);
4445 gcc_assert (ar
->end
[i
] == NULL
);
4446 gcc_assert (ar
->stride
[i
] == NULL
);
4450 /* If the reference type is unknown, figure out what kind it is. */
4452 if (ar
->type
== AR_UNKNOWN
)
4454 ar
->type
= AR_ELEMENT
;
4455 for (i
= 0; i
< ar
->dimen
; i
++)
4456 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4457 || ar
->dimen_type
[i
] == DIMEN_VECTOR
)
4459 ar
->type
= AR_SECTION
;
4464 if (!ar
->as
->cray_pointee
&& !compare_spec_to_ref (ar
))
4467 if (ar
->as
->corank
&& ar
->codimen
== 0)
4470 ar
->codimen
= ar
->as
->corank
;
4471 for (n
= ar
->dimen
; n
< ar
->dimen
+ ar
->codimen
; n
++)
4472 ar
->dimen_type
[n
] = DIMEN_THIS_IMAGE
;
4480 resolve_substring (gfc_ref
*ref
)
4482 int k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
4484 if (ref
->u
.ss
.start
!= NULL
)
4486 if (!gfc_resolve_expr (ref
->u
.ss
.start
))
4489 if (ref
->u
.ss
.start
->ts
.type
!= BT_INTEGER
)
4491 gfc_error ("Substring start index at %L must be of type INTEGER",
4492 &ref
->u
.ss
.start
->where
);
4496 if (ref
->u
.ss
.start
->rank
!= 0)
4498 gfc_error ("Substring start index at %L must be scalar",
4499 &ref
->u
.ss
.start
->where
);
4503 if (compare_bound_int (ref
->u
.ss
.start
, 1) == CMP_LT
4504 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4505 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4507 gfc_error ("Substring start index at %L is less than one",
4508 &ref
->u
.ss
.start
->where
);
4513 if (ref
->u
.ss
.end
!= NULL
)
4515 if (!gfc_resolve_expr (ref
->u
.ss
.end
))
4518 if (ref
->u
.ss
.end
->ts
.type
!= BT_INTEGER
)
4520 gfc_error ("Substring end index at %L must be of type INTEGER",
4521 &ref
->u
.ss
.end
->where
);
4525 if (ref
->u
.ss
.end
->rank
!= 0)
4527 gfc_error ("Substring end index at %L must be scalar",
4528 &ref
->u
.ss
.end
->where
);
4532 if (ref
->u
.ss
.length
!= NULL
4533 && compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.length
->length
) == CMP_GT
4534 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4535 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4537 gfc_error ("Substring end index at %L exceeds the string length",
4538 &ref
->u
.ss
.start
->where
);
4542 if (compare_bound_mpz_t (ref
->u
.ss
.end
,
4543 gfc_integer_kinds
[k
].huge
) == CMP_GT
4544 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4545 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4547 gfc_error ("Substring end index at %L is too large",
4548 &ref
->u
.ss
.end
->where
);
4557 /* This function supplies missing substring charlens. */
4560 gfc_resolve_substring_charlen (gfc_expr
*e
)
4563 gfc_expr
*start
, *end
;
4564 gfc_typespec
*ts
= NULL
;
4566 for (char_ref
= e
->ref
; char_ref
; char_ref
= char_ref
->next
)
4568 if (char_ref
->type
== REF_SUBSTRING
)
4570 if (char_ref
->type
== REF_COMPONENT
)
4571 ts
= &char_ref
->u
.c
.component
->ts
;
4577 gcc_assert (char_ref
->next
== NULL
);
4581 if (e
->ts
.u
.cl
->length
)
4582 gfc_free_expr (e
->ts
.u
.cl
->length
);
4583 else if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.dummy
)
4587 e
->ts
.type
= BT_CHARACTER
;
4588 e
->ts
.kind
= gfc_default_character_kind
;
4591 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
4593 if (char_ref
->u
.ss
.start
)
4594 start
= gfc_copy_expr (char_ref
->u
.ss
.start
);
4596 start
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
4598 if (char_ref
->u
.ss
.end
)
4599 end
= gfc_copy_expr (char_ref
->u
.ss
.end
);
4600 else if (e
->expr_type
== EXPR_VARIABLE
)
4603 ts
= &e
->symtree
->n
.sym
->ts
;
4604 end
= gfc_copy_expr (ts
->u
.cl
->length
);
4611 gfc_free_expr (start
);
4612 gfc_free_expr (end
);
4616 /* Length = (end - start + 1). */
4617 e
->ts
.u
.cl
->length
= gfc_subtract (end
, start
);
4618 e
->ts
.u
.cl
->length
= gfc_add (e
->ts
.u
.cl
->length
,
4619 gfc_get_int_expr (gfc_default_integer_kind
,
4622 /* F2008, 6.4.1: Both the starting point and the ending point shall
4623 be within the range 1, 2, ..., n unless the starting point exceeds
4624 the ending point, in which case the substring has length zero. */
4626 if (mpz_cmp_si (e
->ts
.u
.cl
->length
->value
.integer
, 0) < 0)
4627 mpz_set_si (e
->ts
.u
.cl
->length
->value
.integer
, 0);
4629 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
4630 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
4632 /* Make sure that the length is simplified. */
4633 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 1);
4634 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
4638 /* Resolve subtype references. */
4641 resolve_ref (gfc_expr
*expr
)
4643 int current_part_dimension
, n_components
, seen_part_dimension
;
4646 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4647 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.as
== NULL
)
4649 find_array_spec (expr
);
4653 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4657 if (!resolve_array_ref (&ref
->u
.ar
))
4665 if (!resolve_substring (ref
))
4670 /* Check constraints on part references. */
4672 current_part_dimension
= 0;
4673 seen_part_dimension
= 0;
4676 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4681 switch (ref
->u
.ar
.type
)
4684 /* Coarray scalar. */
4685 if (ref
->u
.ar
.as
->rank
== 0)
4687 current_part_dimension
= 0;
4692 current_part_dimension
= 1;
4696 current_part_dimension
= 0;
4700 gfc_internal_error ("resolve_ref(): Bad array reference");
4706 if (current_part_dimension
|| seen_part_dimension
)
4709 if (ref
->u
.c
.component
->attr
.pointer
4710 || ref
->u
.c
.component
->attr
.proc_pointer
4711 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
4712 && CLASS_DATA (ref
->u
.c
.component
)->attr
.pointer
))
4714 gfc_error ("Component to the right of a part reference "
4715 "with nonzero rank must not have the POINTER "
4716 "attribute at %L", &expr
->where
);
4719 else if (ref
->u
.c
.component
->attr
.allocatable
4720 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
4721 && CLASS_DATA (ref
->u
.c
.component
)->attr
.allocatable
))
4724 gfc_error ("Component to the right of a part reference "
4725 "with nonzero rank must not have the ALLOCATABLE "
4726 "attribute at %L", &expr
->where
);
4738 if (((ref
->type
== REF_COMPONENT
&& n_components
> 1)
4739 || ref
->next
== NULL
)
4740 && current_part_dimension
4741 && seen_part_dimension
)
4743 gfc_error ("Two or more part references with nonzero rank must "
4744 "not be specified at %L", &expr
->where
);
4748 if (ref
->type
== REF_COMPONENT
)
4750 if (current_part_dimension
)
4751 seen_part_dimension
= 1;
4753 /* reset to make sure */
4754 current_part_dimension
= 0;
4762 /* Given an expression, determine its shape. This is easier than it sounds.
4763 Leaves the shape array NULL if it is not possible to determine the shape. */
4766 expression_shape (gfc_expr
*e
)
4768 mpz_t array
[GFC_MAX_DIMENSIONS
];
4771 if (e
->rank
<= 0 || e
->shape
!= NULL
)
4774 for (i
= 0; i
< e
->rank
; i
++)
4775 if (!gfc_array_dimen_size (e
, i
, &array
[i
]))
4778 e
->shape
= gfc_get_shape (e
->rank
);
4780 memcpy (e
->shape
, array
, e
->rank
* sizeof (mpz_t
));
4785 for (i
--; i
>= 0; i
--)
4786 mpz_clear (array
[i
]);
4790 /* Given a variable expression node, compute the rank of the expression by
4791 examining the base symbol and any reference structures it may have. */
4794 expression_rank (gfc_expr
*e
)
4799 /* Just to make sure, because EXPR_COMPCALL's also have an e->ref and that
4800 could lead to serious confusion... */
4801 gcc_assert (e
->expr_type
!= EXPR_COMPCALL
);
4805 if (e
->expr_type
== EXPR_ARRAY
)
4807 /* Constructors can have a rank different from one via RESHAPE(). */
4809 if (e
->symtree
== NULL
)
4815 e
->rank
= (e
->symtree
->n
.sym
->as
== NULL
)
4816 ? 0 : e
->symtree
->n
.sym
->as
->rank
;
4822 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4824 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.proc_pointer
4825 && ref
->u
.c
.component
->attr
.function
&& !ref
->next
)
4826 rank
= ref
->u
.c
.component
->as
? ref
->u
.c
.component
->as
->rank
: 0;
4828 if (ref
->type
!= REF_ARRAY
)
4831 if (ref
->u
.ar
.type
== AR_FULL
)
4833 rank
= ref
->u
.ar
.as
->rank
;
4837 if (ref
->u
.ar
.type
== AR_SECTION
)
4839 /* Figure out the rank of the section. */
4841 gfc_internal_error ("expression_rank(): Two array specs");
4843 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
4844 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_RANGE
4845 || ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
4855 expression_shape (e
);
4860 add_caf_get_intrinsic (gfc_expr
*e
)
4862 gfc_expr
*wrapper
, *tmp_expr
;
4866 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4867 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
4872 for (n
= ref
->u
.ar
.dimen
; n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
4873 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_ELEMENT
)
4876 tmp_expr
= XCNEW (gfc_expr
);
4878 wrapper
= gfc_build_intrinsic_call (gfc_current_ns
, GFC_ISYM_CAF_GET
,
4879 "caf_get", tmp_expr
->where
, 1, tmp_expr
);
4880 wrapper
->ts
= e
->ts
;
4881 wrapper
->rank
= e
->rank
;
4883 wrapper
->shape
= gfc_copy_shape (e
->shape
, e
->rank
);
4890 remove_caf_get_intrinsic (gfc_expr
*e
)
4892 gcc_assert (e
->expr_type
== EXPR_FUNCTION
&& e
->value
.function
.isym
4893 && e
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
);
4894 gfc_expr
*e2
= e
->value
.function
.actual
->expr
;
4895 e
->value
.function
.actual
->expr
= NULL
;
4896 gfc_free_actual_arglist (e
->value
.function
.actual
);
4897 gfc_free_shape (&e
->shape
, e
->rank
);
4903 /* Resolve a variable expression. */
4906 resolve_variable (gfc_expr
*e
)
4913 if (e
->symtree
== NULL
)
4915 sym
= e
->symtree
->n
.sym
;
4917 /* Use same check as for TYPE(*) below; this check has to be before TYPE(*)
4918 as ts.type is set to BT_ASSUMED in resolve_symbol. */
4919 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
4921 if (!actual_arg
|| inquiry_argument
)
4923 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may only "
4924 "be used as actual argument", sym
->name
, &e
->where
);
4928 /* TS 29113, 407b. */
4929 else if (e
->ts
.type
== BT_ASSUMED
)
4933 gfc_error ("Assumed-type variable %s at %L may only be used "
4934 "as actual argument", sym
->name
, &e
->where
);
4937 else if (inquiry_argument
&& !first_actual_arg
)
4939 /* FIXME: It doesn't work reliably as inquiry_argument is not set
4940 for all inquiry functions in resolve_function; the reason is
4941 that the function-name resolution happens too late in that
4943 gfc_error ("Assumed-type variable %s at %L as actual argument to "
4944 "an inquiry function shall be the first argument",
4945 sym
->name
, &e
->where
);
4949 /* TS 29113, C535b. */
4950 else if ((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
4951 && CLASS_DATA (sym
)->as
4952 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
4953 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
4954 && sym
->as
->type
== AS_ASSUMED_RANK
))
4958 gfc_error ("Assumed-rank variable %s at %L may only be used as "
4959 "actual argument", sym
->name
, &e
->where
);
4962 else if (inquiry_argument
&& !first_actual_arg
)
4964 /* FIXME: It doesn't work reliably as inquiry_argument is not set
4965 for all inquiry functions in resolve_function; the reason is
4966 that the function-name resolution happens too late in that
4968 gfc_error ("Assumed-rank variable %s at %L as actual argument "
4969 "to an inquiry function shall be the first argument",
4970 sym
->name
, &e
->where
);
4975 if ((sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
)) && e
->ref
4976 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
4977 && e
->ref
->next
== NULL
))
4979 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall not have "
4980 "a subobject reference", sym
->name
, &e
->ref
->u
.ar
.where
);
4983 /* TS 29113, 407b. */
4984 else if (e
->ts
.type
== BT_ASSUMED
&& e
->ref
4985 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
4986 && e
->ref
->next
== NULL
))
4988 gfc_error ("Assumed-type variable %s at %L shall not have a subobject "
4989 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
4993 /* TS 29113, C535b. */
4994 if (((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
4995 && CLASS_DATA (sym
)->as
4996 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
4997 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
4998 && sym
->as
->type
== AS_ASSUMED_RANK
))
5000 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
5001 && e
->ref
->next
== NULL
))
5003 gfc_error ("Assumed-rank variable %s at %L shall not have a subobject "
5004 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
5008 /* For variables that are used in an associate (target => object) where
5009 the object's basetype is array valued while the target is scalar,
5010 the ts' type of the component refs is still array valued, which
5011 can't be translated that way. */
5012 if (sym
->assoc
&& e
->rank
== 0 && e
->ref
&& sym
->ts
.type
== BT_CLASS
5013 && sym
->assoc
->target
->ts
.type
== BT_CLASS
5014 && CLASS_DATA (sym
->assoc
->target
)->as
)
5016 gfc_ref
*ref
= e
->ref
;
5022 ref
->u
.c
.sym
= sym
->ts
.u
.derived
;
5023 /* Stop the loop. */
5033 /* If this is an associate-name, it may be parsed with an array reference
5034 in error even though the target is scalar. Fail directly in this case.
5035 TODO Understand why class scalar expressions must be excluded. */
5036 if (sym
->assoc
&& !(sym
->ts
.type
== BT_CLASS
&& e
->rank
== 0))
5038 if (sym
->ts
.type
== BT_CLASS
)
5039 gfc_fix_class_refs (e
);
5040 if (!sym
->attr
.dimension
&& e
->ref
&& e
->ref
->type
== REF_ARRAY
)
5044 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.generic
)
5045 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
5047 /* On the other hand, the parser may not have known this is an array;
5048 in this case, we have to add a FULL reference. */
5049 if (sym
->assoc
&& sym
->attr
.dimension
&& !e
->ref
)
5051 e
->ref
= gfc_get_ref ();
5052 e
->ref
->type
= REF_ARRAY
;
5053 e
->ref
->u
.ar
.type
= AR_FULL
;
5054 e
->ref
->u
.ar
.dimen
= 0;
5057 /* Like above, but for class types, where the checking whether an array
5058 ref is present is more complicated. Furthermore make sure not to add
5059 the full array ref to _vptr or _len refs. */
5060 if (sym
->assoc
&& sym
->ts
.type
== BT_CLASS
5061 && CLASS_DATA (sym
)->attr
.dimension
5062 && (e
->ts
.type
!= BT_DERIVED
|| !e
->ts
.u
.derived
->attr
.vtype
))
5064 gfc_ref
*ref
, *newref
;
5066 newref
= gfc_get_ref ();
5067 newref
->type
= REF_ARRAY
;
5068 newref
->u
.ar
.type
= AR_FULL
;
5069 newref
->u
.ar
.dimen
= 0;
5070 /* Because this is an associate var and the first ref either is a ref to
5071 the _data component or not, no traversal of the ref chain is
5072 needed. The array ref needs to be inserted after the _data ref,
5073 or when that is not present, which may happend for polymorphic
5074 types, then at the first position. */
5078 else if (ref
->type
== REF_COMPONENT
5079 && strcmp ("_data", ref
->u
.c
.component
->name
) == 0)
5081 if (!ref
->next
|| ref
->next
->type
!= REF_ARRAY
)
5083 newref
->next
= ref
->next
;
5087 /* Array ref present already. */
5088 gfc_free_ref_list (newref
);
5090 else if (ref
->type
== REF_ARRAY
)
5091 /* Array ref present already. */
5092 gfc_free_ref_list (newref
);
5100 if (e
->ref
&& !resolve_ref (e
))
5103 if (sym
->attr
.flavor
== FL_PROCEDURE
5104 && (!sym
->attr
.function
5105 || (sym
->attr
.function
&& sym
->result
5106 && sym
->result
->attr
.proc_pointer
5107 && !sym
->result
->attr
.function
)))
5109 e
->ts
.type
= BT_PROCEDURE
;
5110 goto resolve_procedure
;
5113 if (sym
->ts
.type
!= BT_UNKNOWN
)
5114 gfc_variable_attr (e
, &e
->ts
);
5117 /* Must be a simple variable reference. */
5118 if (!gfc_set_default_type (sym
, 1, sym
->ns
))
5123 if (check_assumed_size_reference (sym
, e
))
5126 /* Deal with forward references to entries during gfc_resolve_code, to
5127 satisfy, at least partially, 12.5.2.5. */
5128 if (gfc_current_ns
->entries
5129 && current_entry_id
== sym
->entry_id
5132 && cs_base
->current
->op
!= EXEC_ENTRY
)
5134 gfc_entry_list
*entry
;
5135 gfc_formal_arglist
*formal
;
5137 bool seen
, saved_specification_expr
;
5139 /* If the symbol is a dummy... */
5140 if (sym
->attr
.dummy
&& sym
->ns
== gfc_current_ns
)
5142 entry
= gfc_current_ns
->entries
;
5145 /* ...test if the symbol is a parameter of previous entries. */
5146 for (; entry
&& entry
->id
<= current_entry_id
; entry
= entry
->next
)
5147 for (formal
= entry
->sym
->formal
; formal
; formal
= formal
->next
)
5149 if (formal
->sym
&& sym
->name
== formal
->sym
->name
)
5156 /* If it has not been seen as a dummy, this is an error. */
5159 if (specification_expr
)
5160 gfc_error ("Variable %qs, used in a specification expression"
5161 ", is referenced at %L before the ENTRY statement "
5162 "in which it is a parameter",
5163 sym
->name
, &cs_base
->current
->loc
);
5165 gfc_error ("Variable %qs is used at %L before the ENTRY "
5166 "statement in which it is a parameter",
5167 sym
->name
, &cs_base
->current
->loc
);
5172 /* Now do the same check on the specification expressions. */
5173 saved_specification_expr
= specification_expr
;
5174 specification_expr
= true;
5175 if (sym
->ts
.type
== BT_CHARACTER
5176 && !gfc_resolve_expr (sym
->ts
.u
.cl
->length
))
5180 for (n
= 0; n
< sym
->as
->rank
; n
++)
5182 if (!gfc_resolve_expr (sym
->as
->lower
[n
]))
5184 if (!gfc_resolve_expr (sym
->as
->upper
[n
]))
5187 specification_expr
= saved_specification_expr
;
5190 /* Update the symbol's entry level. */
5191 sym
->entry_id
= current_entry_id
+ 1;
5194 /* If a symbol has been host_associated mark it. This is used latter,
5195 to identify if aliasing is possible via host association. */
5196 if (sym
->attr
.flavor
== FL_VARIABLE
5197 && gfc_current_ns
->parent
5198 && (gfc_current_ns
->parent
== sym
->ns
5199 || (gfc_current_ns
->parent
->parent
5200 && gfc_current_ns
->parent
->parent
== sym
->ns
)))
5201 sym
->attr
.host_assoc
= 1;
5203 if (gfc_current_ns
->proc_name
5204 && sym
->attr
.dimension
5205 && (sym
->ns
!= gfc_current_ns
5206 || sym
->attr
.use_assoc
5207 || sym
->attr
.in_common
))
5208 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
5211 if (t
&& !resolve_procedure_expression (e
))
5214 /* F2008, C617 and C1229. */
5215 if (!inquiry_argument
&& (e
->ts
.type
== BT_CLASS
|| e
->ts
.type
== BT_DERIVED
)
5216 && gfc_is_coindexed (e
))
5218 gfc_ref
*ref
, *ref2
= NULL
;
5220 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5222 if (ref
->type
== REF_COMPONENT
)
5224 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
5228 for ( ; ref
; ref
= ref
->next
)
5229 if (ref
->type
== REF_COMPONENT
)
5232 /* Expression itself is not coindexed object. */
5233 if (ref
&& e
->ts
.type
== BT_CLASS
)
5235 gfc_error ("Polymorphic subobject of coindexed object at %L",
5240 /* Expression itself is coindexed object. */
5244 c
= ref2
? ref2
->u
.c
.component
: e
->symtree
->n
.sym
->components
;
5245 for ( ; c
; c
= c
->next
)
5246 if (c
->attr
.allocatable
&& c
->ts
.type
== BT_CLASS
)
5248 gfc_error ("Coindexed object with polymorphic allocatable "
5249 "subcomponent at %L", &e
->where
);
5257 expression_rank (e
);
5259 if (t
&& flag_coarray
== GFC_FCOARRAY_LIB
&& gfc_is_coindexed (e
))
5260 add_caf_get_intrinsic (e
);
5266 /* Checks to see that the correct symbol has been host associated.
5267 The only situation where this arises is that in which a twice
5268 contained function is parsed after the host association is made.
5269 Therefore, on detecting this, change the symbol in the expression
5270 and convert the array reference into an actual arglist if the old
5271 symbol is a variable. */
5273 check_host_association (gfc_expr
*e
)
5275 gfc_symbol
*sym
, *old_sym
;
5279 gfc_actual_arglist
*arg
, *tail
= NULL
;
5280 bool retval
= e
->expr_type
== EXPR_FUNCTION
;
5282 /* If the expression is the result of substitution in
5283 interface.c(gfc_extend_expr) because there is no way in
5284 which the host association can be wrong. */
5285 if (e
->symtree
== NULL
5286 || e
->symtree
->n
.sym
== NULL
5287 || e
->user_operator
)
5290 old_sym
= e
->symtree
->n
.sym
;
5292 if (gfc_current_ns
->parent
5293 && old_sym
->ns
!= gfc_current_ns
)
5295 /* Use the 'USE' name so that renamed module symbols are
5296 correctly handled. */
5297 gfc_find_symbol (e
->symtree
->name
, gfc_current_ns
, 1, &sym
);
5299 if (sym
&& old_sym
!= sym
5300 && sym
->ts
.type
== old_sym
->ts
.type
5301 && sym
->attr
.flavor
== FL_PROCEDURE
5302 && sym
->attr
.contained
)
5304 /* Clear the shape, since it might not be valid. */
5305 gfc_free_shape (&e
->shape
, e
->rank
);
5307 /* Give the expression the right symtree! */
5308 gfc_find_sym_tree (e
->symtree
->name
, NULL
, 1, &st
);
5309 gcc_assert (st
!= NULL
);
5311 if (old_sym
->attr
.flavor
== FL_PROCEDURE
5312 || e
->expr_type
== EXPR_FUNCTION
)
5314 /* Original was function so point to the new symbol, since
5315 the actual argument list is already attached to the
5317 e
->value
.function
.esym
= NULL
;
5322 /* Original was variable so convert array references into
5323 an actual arglist. This does not need any checking now
5324 since resolve_function will take care of it. */
5325 e
->value
.function
.actual
= NULL
;
5326 e
->expr_type
= EXPR_FUNCTION
;
5329 /* Ambiguity will not arise if the array reference is not
5330 the last reference. */
5331 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5332 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
5335 gcc_assert (ref
->type
== REF_ARRAY
);
5337 /* Grab the start expressions from the array ref and
5338 copy them into actual arguments. */
5339 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
5341 arg
= gfc_get_actual_arglist ();
5342 arg
->expr
= gfc_copy_expr (ref
->u
.ar
.start
[n
]);
5343 if (e
->value
.function
.actual
== NULL
)
5344 tail
= e
->value
.function
.actual
= arg
;
5352 /* Dump the reference list and set the rank. */
5353 gfc_free_ref_list (e
->ref
);
5355 e
->rank
= sym
->as
? sym
->as
->rank
: 0;
5358 gfc_resolve_expr (e
);
5362 /* This might have changed! */
5363 return e
->expr_type
== EXPR_FUNCTION
;
5368 gfc_resolve_character_operator (gfc_expr
*e
)
5370 gfc_expr
*op1
= e
->value
.op
.op1
;
5371 gfc_expr
*op2
= e
->value
.op
.op2
;
5372 gfc_expr
*e1
= NULL
;
5373 gfc_expr
*e2
= NULL
;
5375 gcc_assert (e
->value
.op
.op
== INTRINSIC_CONCAT
);
5377 if (op1
->ts
.u
.cl
&& op1
->ts
.u
.cl
->length
)
5378 e1
= gfc_copy_expr (op1
->ts
.u
.cl
->length
);
5379 else if (op1
->expr_type
== EXPR_CONSTANT
)
5380 e1
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
5381 op1
->value
.character
.length
);
5383 if (op2
->ts
.u
.cl
&& op2
->ts
.u
.cl
->length
)
5384 e2
= gfc_copy_expr (op2
->ts
.u
.cl
->length
);
5385 else if (op2
->expr_type
== EXPR_CONSTANT
)
5386 e2
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
5387 op2
->value
.character
.length
);
5389 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5399 e
->ts
.u
.cl
->length
= gfc_add (e1
, e2
);
5400 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
5401 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
5402 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 0);
5403 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
5409 /* Ensure that an character expression has a charlen and, if possible, a
5410 length expression. */
5413 fixup_charlen (gfc_expr
*e
)
5415 /* The cases fall through so that changes in expression type and the need
5416 for multiple fixes are picked up. In all circumstances, a charlen should
5417 be available for the middle end to hang a backend_decl on. */
5418 switch (e
->expr_type
)
5421 gfc_resolve_character_operator (e
);
5424 if (e
->expr_type
== EXPR_ARRAY
)
5425 gfc_resolve_character_array_constructor (e
);
5427 case EXPR_SUBSTRING
:
5428 if (!e
->ts
.u
.cl
&& e
->ref
)
5429 gfc_resolve_substring_charlen (e
);
5433 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5440 /* Update an actual argument to include the passed-object for type-bound
5441 procedures at the right position. */
5443 static gfc_actual_arglist
*
5444 update_arglist_pass (gfc_actual_arglist
* lst
, gfc_expr
* po
, unsigned argpos
,
5447 gcc_assert (argpos
> 0);
5451 gfc_actual_arglist
* result
;
5453 result
= gfc_get_actual_arglist ();
5457 result
->name
= name
;
5463 lst
->next
= update_arglist_pass (lst
->next
, po
, argpos
- 1, name
);
5465 lst
= update_arglist_pass (NULL
, po
, argpos
- 1, name
);
5470 /* Extract the passed-object from an EXPR_COMPCALL (a copy of it). */
5473 extract_compcall_passed_object (gfc_expr
* e
)
5477 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5479 if (e
->value
.compcall
.base_object
)
5480 po
= gfc_copy_expr (e
->value
.compcall
.base_object
);
5483 po
= gfc_get_expr ();
5484 po
->expr_type
= EXPR_VARIABLE
;
5485 po
->symtree
= e
->symtree
;
5486 po
->ref
= gfc_copy_ref (e
->ref
);
5487 po
->where
= e
->where
;
5490 if (!gfc_resolve_expr (po
))
5497 /* Update the arglist of an EXPR_COMPCALL expression to include the
5501 update_compcall_arglist (gfc_expr
* e
)
5504 gfc_typebound_proc
* tbp
;
5506 tbp
= e
->value
.compcall
.tbp
;
5511 po
= extract_compcall_passed_object (e
);
5515 if (tbp
->nopass
|| e
->value
.compcall
.ignore_pass
)
5521 gcc_assert (tbp
->pass_arg_num
> 0);
5522 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5530 /* Extract the passed object from a PPC call (a copy of it). */
5533 extract_ppc_passed_object (gfc_expr
*e
)
5538 po
= gfc_get_expr ();
5539 po
->expr_type
= EXPR_VARIABLE
;
5540 po
->symtree
= e
->symtree
;
5541 po
->ref
= gfc_copy_ref (e
->ref
);
5542 po
->where
= e
->where
;
5544 /* Remove PPC reference. */
5546 while ((*ref
)->next
)
5547 ref
= &(*ref
)->next
;
5548 gfc_free_ref_list (*ref
);
5551 if (!gfc_resolve_expr (po
))
5558 /* Update the actual arglist of a procedure pointer component to include the
5562 update_ppc_arglist (gfc_expr
* e
)
5566 gfc_typebound_proc
* tb
;
5568 ppc
= gfc_get_proc_ptr_comp (e
);
5576 else if (tb
->nopass
)
5579 po
= extract_ppc_passed_object (e
);
5586 gfc_error ("Passed-object at %L must be scalar", &e
->where
);
5591 if (po
->ts
.type
== BT_DERIVED
&& po
->ts
.u
.derived
->attr
.abstract
)
5593 gfc_error ("Base object for procedure-pointer component call at %L is of"
5594 " ABSTRACT type %qs", &e
->where
, po
->ts
.u
.derived
->name
);
5598 gcc_assert (tb
->pass_arg_num
> 0);
5599 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5607 /* Check that the object a TBP is called on is valid, i.e. it must not be
5608 of ABSTRACT type (as in subobject%abstract_parent%tbp()). */
5611 check_typebound_baseobject (gfc_expr
* e
)
5614 bool return_value
= false;
5616 base
= extract_compcall_passed_object (e
);
5620 gcc_assert (base
->ts
.type
== BT_DERIVED
|| base
->ts
.type
== BT_CLASS
);
5622 if (base
->ts
.type
== BT_CLASS
&& !gfc_expr_attr (base
).class_ok
)
5626 if (base
->ts
.type
== BT_DERIVED
&& base
->ts
.u
.derived
->attr
.abstract
)
5628 gfc_error ("Base object for type-bound procedure call at %L is of"
5629 " ABSTRACT type %qs", &e
->where
, base
->ts
.u
.derived
->name
);
5633 /* F08:C1230. If the procedure called is NOPASS,
5634 the base object must be scalar. */
5635 if (e
->value
.compcall
.tbp
->nopass
&& base
->rank
!= 0)
5637 gfc_error ("Base object for NOPASS type-bound procedure call at %L must"
5638 " be scalar", &e
->where
);
5642 return_value
= true;
5645 gfc_free_expr (base
);
5646 return return_value
;
5650 /* Resolve a call to a type-bound procedure, either function or subroutine,
5651 statically from the data in an EXPR_COMPCALL expression. The adapted
5652 arglist and the target-procedure symtree are returned. */
5655 resolve_typebound_static (gfc_expr
* e
, gfc_symtree
** target
,
5656 gfc_actual_arglist
** actual
)
5658 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5659 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5661 /* Update the actual arglist for PASS. */
5662 if (!update_compcall_arglist (e
))
5665 *actual
= e
->value
.compcall
.actual
;
5666 *target
= e
->value
.compcall
.tbp
->u
.specific
;
5668 gfc_free_ref_list (e
->ref
);
5670 e
->value
.compcall
.actual
= NULL
;
5672 /* If we find a deferred typebound procedure, check for derived types
5673 that an overriding typebound procedure has not been missed. */
5674 if (e
->value
.compcall
.name
5675 && !e
->value
.compcall
.tbp
->non_overridable
5676 && e
->value
.compcall
.base_object
5677 && e
->value
.compcall
.base_object
->ts
.type
== BT_DERIVED
)
5680 gfc_symbol
*derived
;
5682 /* Use the derived type of the base_object. */
5683 derived
= e
->value
.compcall
.base_object
->ts
.u
.derived
;
5686 /* If necessary, go through the inheritance chain. */
5687 while (!st
&& derived
)
5689 /* Look for the typebound procedure 'name'. */
5690 if (derived
->f2k_derived
&& derived
->f2k_derived
->tb_sym_root
)
5691 st
= gfc_find_symtree (derived
->f2k_derived
->tb_sym_root
,
5692 e
->value
.compcall
.name
);
5694 derived
= gfc_get_derived_super_type (derived
);
5697 /* Now find the specific name in the derived type namespace. */
5698 if (st
&& st
->n
.tb
&& st
->n
.tb
->u
.specific
)
5699 gfc_find_sym_tree (st
->n
.tb
->u
.specific
->name
,
5700 derived
->ns
, 1, &st
);
5708 /* Get the ultimate declared type from an expression. In addition,
5709 return the last class/derived type reference and the copy of the
5710 reference list. If check_types is set true, derived types are
5711 identified as well as class references. */
5713 get_declared_from_expr (gfc_ref
**class_ref
, gfc_ref
**new_ref
,
5714 gfc_expr
*e
, bool check_types
)
5716 gfc_symbol
*declared
;
5723 *new_ref
= gfc_copy_ref (e
->ref
);
5725 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5727 if (ref
->type
!= REF_COMPONENT
)
5730 if ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
5731 || (check_types
&& gfc_bt_struct (ref
->u
.c
.component
->ts
.type
)))
5732 && ref
->u
.c
.component
->attr
.flavor
!= FL_PROCEDURE
)
5734 declared
= ref
->u
.c
.component
->ts
.u
.derived
;
5740 if (declared
== NULL
)
5741 declared
= e
->symtree
->n
.sym
->ts
.u
.derived
;
5747 /* Given an EXPR_COMPCALL calling a GENERIC typebound procedure, figure out
5748 which of the specific bindings (if any) matches the arglist and transform
5749 the expression into a call of that binding. */
5752 resolve_typebound_generic_call (gfc_expr
* e
, const char **name
)
5754 gfc_typebound_proc
* genproc
;
5755 const char* genname
;
5757 gfc_symbol
*derived
;
5759 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5760 genname
= e
->value
.compcall
.name
;
5761 genproc
= e
->value
.compcall
.tbp
;
5763 if (!genproc
->is_generic
)
5766 /* Try the bindings on this type and in the inheritance hierarchy. */
5767 for (; genproc
; genproc
= genproc
->overridden
)
5771 gcc_assert (genproc
->is_generic
);
5772 for (g
= genproc
->u
.generic
; g
; g
= g
->next
)
5775 gfc_actual_arglist
* args
;
5778 gcc_assert (g
->specific
);
5780 if (g
->specific
->error
)
5783 target
= g
->specific
->u
.specific
->n
.sym
;
5785 /* Get the right arglist by handling PASS/NOPASS. */
5786 args
= gfc_copy_actual_arglist (e
->value
.compcall
.actual
);
5787 if (!g
->specific
->nopass
)
5790 po
= extract_compcall_passed_object (e
);
5793 gfc_free_actual_arglist (args
);
5797 gcc_assert (g
->specific
->pass_arg_num
> 0);
5798 gcc_assert (!g
->specific
->error
);
5799 args
= update_arglist_pass (args
, po
, g
->specific
->pass_arg_num
,
5800 g
->specific
->pass_arg
);
5802 resolve_actual_arglist (args
, target
->attr
.proc
,
5803 is_external_proc (target
)
5804 && gfc_sym_get_dummy_args (target
) == NULL
);
5806 /* Check if this arglist matches the formal. */
5807 matches
= gfc_arglist_matches_symbol (&args
, target
);
5809 /* Clean up and break out of the loop if we've found it. */
5810 gfc_free_actual_arglist (args
);
5813 e
->value
.compcall
.tbp
= g
->specific
;
5814 genname
= g
->specific_st
->name
;
5815 /* Pass along the name for CLASS methods, where the vtab
5816 procedure pointer component has to be referenced. */
5824 /* Nothing matching found! */
5825 gfc_error ("Found no matching specific binding for the call to the GENERIC"
5826 " %qs at %L", genname
, &e
->where
);
5830 /* Make sure that we have the right specific instance for the name. */
5831 derived
= get_declared_from_expr (NULL
, NULL
, e
, true);
5833 st
= gfc_find_typebound_proc (derived
, NULL
, genname
, true, &e
->where
);
5835 e
->value
.compcall
.tbp
= st
->n
.tb
;
5841 /* Resolve a call to a type-bound subroutine. */
5844 resolve_typebound_call (gfc_code
* c
, const char **name
, bool *overridable
)
5846 gfc_actual_arglist
* newactual
;
5847 gfc_symtree
* target
;
5849 /* Check that's really a SUBROUTINE. */
5850 if (!c
->expr1
->value
.compcall
.tbp
->subroutine
)
5852 gfc_error ("%qs at %L should be a SUBROUTINE",
5853 c
->expr1
->value
.compcall
.name
, &c
->loc
);
5857 if (!check_typebound_baseobject (c
->expr1
))
5860 /* Pass along the name for CLASS methods, where the vtab
5861 procedure pointer component has to be referenced. */
5863 *name
= c
->expr1
->value
.compcall
.name
;
5865 if (!resolve_typebound_generic_call (c
->expr1
, name
))
5868 /* Pass along the NON_OVERRIDABLE attribute of the specific TBP. */
5870 *overridable
= !c
->expr1
->value
.compcall
.tbp
->non_overridable
;
5872 /* Transform into an ordinary EXEC_CALL for now. */
5874 if (!resolve_typebound_static (c
->expr1
, &target
, &newactual
))
5877 c
->ext
.actual
= newactual
;
5878 c
->symtree
= target
;
5879 c
->op
= (c
->expr1
->value
.compcall
.assign
? EXEC_ASSIGN_CALL
: EXEC_CALL
);
5881 gcc_assert (!c
->expr1
->ref
&& !c
->expr1
->value
.compcall
.actual
);
5883 gfc_free_expr (c
->expr1
);
5884 c
->expr1
= gfc_get_expr ();
5885 c
->expr1
->expr_type
= EXPR_FUNCTION
;
5886 c
->expr1
->symtree
= target
;
5887 c
->expr1
->where
= c
->loc
;
5889 return resolve_call (c
);
5893 /* Resolve a component-call expression. */
5895 resolve_compcall (gfc_expr
* e
, const char **name
)
5897 gfc_actual_arglist
* newactual
;
5898 gfc_symtree
* target
;
5900 /* Check that's really a FUNCTION. */
5901 if (!e
->value
.compcall
.tbp
->function
)
5903 gfc_error ("%qs at %L should be a FUNCTION",
5904 e
->value
.compcall
.name
, &e
->where
);
5908 /* These must not be assign-calls! */
5909 gcc_assert (!e
->value
.compcall
.assign
);
5911 if (!check_typebound_baseobject (e
))
5914 /* Pass along the name for CLASS methods, where the vtab
5915 procedure pointer component has to be referenced. */
5917 *name
= e
->value
.compcall
.name
;
5919 if (!resolve_typebound_generic_call (e
, name
))
5921 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5923 /* Take the rank from the function's symbol. */
5924 if (e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
)
5925 e
->rank
= e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
->rank
;
5927 /* For now, we simply transform it into an EXPR_FUNCTION call with the same
5928 arglist to the TBP's binding target. */
5930 if (!resolve_typebound_static (e
, &target
, &newactual
))
5933 e
->value
.function
.actual
= newactual
;
5934 e
->value
.function
.name
= NULL
;
5935 e
->value
.function
.esym
= target
->n
.sym
;
5936 e
->value
.function
.isym
= NULL
;
5937 e
->symtree
= target
;
5938 e
->ts
= target
->n
.sym
->ts
;
5939 e
->expr_type
= EXPR_FUNCTION
;
5941 /* Resolution is not necessary if this is a class subroutine; this
5942 function only has to identify the specific proc. Resolution of
5943 the call will be done next in resolve_typebound_call. */
5944 return gfc_resolve_expr (e
);
5948 static bool resolve_fl_derived (gfc_symbol
*sym
);
5951 /* Resolve a typebound function, or 'method'. First separate all
5952 the non-CLASS references by calling resolve_compcall directly. */
5955 resolve_typebound_function (gfc_expr
* e
)
5957 gfc_symbol
*declared
;
5969 /* Deal with typebound operators for CLASS objects. */
5970 expr
= e
->value
.compcall
.base_object
;
5971 overridable
= !e
->value
.compcall
.tbp
->non_overridable
;
5972 if (expr
&& expr
->ts
.type
== BT_CLASS
&& e
->value
.compcall
.name
)
5974 /* If the base_object is not a variable, the corresponding actual
5975 argument expression must be stored in e->base_expression so
5976 that the corresponding tree temporary can be used as the base
5977 object in gfc_conv_procedure_call. */
5978 if (expr
->expr_type
!= EXPR_VARIABLE
)
5980 gfc_actual_arglist
*args
;
5982 for (args
= e
->value
.function
.actual
; args
; args
= args
->next
)
5984 if (expr
== args
->expr
)
5989 /* Since the typebound operators are generic, we have to ensure
5990 that any delays in resolution are corrected and that the vtab
5993 declared
= ts
.u
.derived
;
5994 c
= gfc_find_component (declared
, "_vptr", true, true, NULL
);
5995 if (c
->ts
.u
.derived
== NULL
)
5996 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
5998 if (!resolve_compcall (e
, &name
))
6001 /* Use the generic name if it is there. */
6002 name
= name
? name
: e
->value
.function
.esym
->name
;
6003 e
->symtree
= expr
->symtree
;
6004 e
->ref
= gfc_copy_ref (expr
->ref
);
6005 get_declared_from_expr (&class_ref
, NULL
, e
, false);
6007 /* Trim away the extraneous references that emerge from nested
6008 use of interface.c (extend_expr). */
6009 if (class_ref
&& class_ref
->next
)
6011 gfc_free_ref_list (class_ref
->next
);
6012 class_ref
->next
= NULL
;
6014 else if (e
->ref
&& !class_ref
)
6016 gfc_free_ref_list (e
->ref
);
6020 gfc_add_vptr_component (e
);
6021 gfc_add_component_ref (e
, name
);
6022 e
->value
.function
.esym
= NULL
;
6023 if (expr
->expr_type
!= EXPR_VARIABLE
)
6024 e
->base_expr
= expr
;
6029 return resolve_compcall (e
, NULL
);
6031 if (!resolve_ref (e
))
6034 /* Get the CLASS declared type. */
6035 declared
= get_declared_from_expr (&class_ref
, &new_ref
, e
, true);
6037 if (!resolve_fl_derived (declared
))
6040 /* Weed out cases of the ultimate component being a derived type. */
6041 if ((class_ref
&& gfc_bt_struct (class_ref
->u
.c
.component
->ts
.type
))
6042 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
6044 gfc_free_ref_list (new_ref
);
6045 return resolve_compcall (e
, NULL
);
6048 c
= gfc_find_component (declared
, "_data", true, true, NULL
);
6049 declared
= c
->ts
.u
.derived
;
6051 /* Treat the call as if it is a typebound procedure, in order to roll
6052 out the correct name for the specific function. */
6053 if (!resolve_compcall (e
, &name
))
6055 gfc_free_ref_list (new_ref
);
6062 /* Convert the expression to a procedure pointer component call. */
6063 e
->value
.function
.esym
= NULL
;
6069 /* '_vptr' points to the vtab, which contains the procedure pointers. */
6070 gfc_add_vptr_component (e
);
6071 gfc_add_component_ref (e
, name
);
6073 /* Recover the typespec for the expression. This is really only
6074 necessary for generic procedures, where the additional call
6075 to gfc_add_component_ref seems to throw the collection of the
6076 correct typespec. */
6080 gfc_free_ref_list (new_ref
);
6085 /* Resolve a typebound subroutine, or 'method'. First separate all
6086 the non-CLASS references by calling resolve_typebound_call
6090 resolve_typebound_subroutine (gfc_code
*code
)
6092 gfc_symbol
*declared
;
6102 st
= code
->expr1
->symtree
;
6104 /* Deal with typebound operators for CLASS objects. */
6105 expr
= code
->expr1
->value
.compcall
.base_object
;
6106 overridable
= !code
->expr1
->value
.compcall
.tbp
->non_overridable
;
6107 if (expr
&& expr
->ts
.type
== BT_CLASS
&& code
->expr1
->value
.compcall
.name
)
6109 /* If the base_object is not a variable, the corresponding actual
6110 argument expression must be stored in e->base_expression so
6111 that the corresponding tree temporary can be used as the base
6112 object in gfc_conv_procedure_call. */
6113 if (expr
->expr_type
!= EXPR_VARIABLE
)
6115 gfc_actual_arglist
*args
;
6117 args
= code
->expr1
->value
.function
.actual
;
6118 for (; args
; args
= args
->next
)
6119 if (expr
== args
->expr
)
6123 /* Since the typebound operators are generic, we have to ensure
6124 that any delays in resolution are corrected and that the vtab
6126 declared
= expr
->ts
.u
.derived
;
6127 c
= gfc_find_component (declared
, "_vptr", true, true, NULL
);
6128 if (c
->ts
.u
.derived
== NULL
)
6129 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
6131 if (!resolve_typebound_call (code
, &name
, NULL
))
6134 /* Use the generic name if it is there. */
6135 name
= name
? name
: code
->expr1
->value
.function
.esym
->name
;
6136 code
->expr1
->symtree
= expr
->symtree
;
6137 code
->expr1
->ref
= gfc_copy_ref (expr
->ref
);
6139 /* Trim away the extraneous references that emerge from nested
6140 use of interface.c (extend_expr). */
6141 get_declared_from_expr (&class_ref
, NULL
, code
->expr1
, false);
6142 if (class_ref
&& class_ref
->next
)
6144 gfc_free_ref_list (class_ref
->next
);
6145 class_ref
->next
= NULL
;
6147 else if (code
->expr1
->ref
&& !class_ref
)
6149 gfc_free_ref_list (code
->expr1
->ref
);
6150 code
->expr1
->ref
= NULL
;
6153 /* Now use the procedure in the vtable. */
6154 gfc_add_vptr_component (code
->expr1
);
6155 gfc_add_component_ref (code
->expr1
, name
);
6156 code
->expr1
->value
.function
.esym
= NULL
;
6157 if (expr
->expr_type
!= EXPR_VARIABLE
)
6158 code
->expr1
->base_expr
= expr
;
6163 return resolve_typebound_call (code
, NULL
, NULL
);
6165 if (!resolve_ref (code
->expr1
))
6168 /* Get the CLASS declared type. */
6169 get_declared_from_expr (&class_ref
, &new_ref
, code
->expr1
, true);
6171 /* Weed out cases of the ultimate component being a derived type. */
6172 if ((class_ref
&& gfc_bt_struct (class_ref
->u
.c
.component
->ts
.type
))
6173 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
6175 gfc_free_ref_list (new_ref
);
6176 return resolve_typebound_call (code
, NULL
, NULL
);
6179 if (!resolve_typebound_call (code
, &name
, &overridable
))
6181 gfc_free_ref_list (new_ref
);
6184 ts
= code
->expr1
->ts
;
6188 /* Convert the expression to a procedure pointer component call. */
6189 code
->expr1
->value
.function
.esym
= NULL
;
6190 code
->expr1
->symtree
= st
;
6193 code
->expr1
->ref
= new_ref
;
6195 /* '_vptr' points to the vtab, which contains the procedure pointers. */
6196 gfc_add_vptr_component (code
->expr1
);
6197 gfc_add_component_ref (code
->expr1
, name
);
6199 /* Recover the typespec for the expression. This is really only
6200 necessary for generic procedures, where the additional call
6201 to gfc_add_component_ref seems to throw the collection of the
6202 correct typespec. */
6203 code
->expr1
->ts
= ts
;
6206 gfc_free_ref_list (new_ref
);
6212 /* Resolve a CALL to a Procedure Pointer Component (Subroutine). */
6215 resolve_ppc_call (gfc_code
* c
)
6217 gfc_component
*comp
;
6219 comp
= gfc_get_proc_ptr_comp (c
->expr1
);
6220 gcc_assert (comp
!= NULL
);
6222 c
->resolved_sym
= c
->expr1
->symtree
->n
.sym
;
6223 c
->expr1
->expr_type
= EXPR_VARIABLE
;
6225 if (!comp
->attr
.subroutine
)
6226 gfc_add_subroutine (&comp
->attr
, comp
->name
, &c
->expr1
->where
);
6228 if (!resolve_ref (c
->expr1
))
6231 if (!update_ppc_arglist (c
->expr1
))
6234 c
->ext
.actual
= c
->expr1
->value
.compcall
.actual
;
6236 if (!resolve_actual_arglist (c
->ext
.actual
, comp
->attr
.proc
,
6237 !(comp
->ts
.interface
6238 && comp
->ts
.interface
->formal
)))
6241 if (!pure_subroutine (comp
->ts
.interface
, comp
->name
, &c
->expr1
->where
))
6244 gfc_ppc_use (comp
, &c
->expr1
->value
.compcall
.actual
, &c
->expr1
->where
);
6250 /* Resolve a Function Call to a Procedure Pointer Component (Function). */
6253 resolve_expr_ppc (gfc_expr
* e
)
6255 gfc_component
*comp
;
6257 comp
= gfc_get_proc_ptr_comp (e
);
6258 gcc_assert (comp
!= NULL
);
6260 /* Convert to EXPR_FUNCTION. */
6261 e
->expr_type
= EXPR_FUNCTION
;
6262 e
->value
.function
.isym
= NULL
;
6263 e
->value
.function
.actual
= e
->value
.compcall
.actual
;
6265 if (comp
->as
!= NULL
)
6266 e
->rank
= comp
->as
->rank
;
6268 if (!comp
->attr
.function
)
6269 gfc_add_function (&comp
->attr
, comp
->name
, &e
->where
);
6271 if (!resolve_ref (e
))
6274 if (!resolve_actual_arglist (e
->value
.function
.actual
, comp
->attr
.proc
,
6275 !(comp
->ts
.interface
6276 && comp
->ts
.interface
->formal
)))
6279 if (!update_ppc_arglist (e
))
6282 if (!check_pure_function(e
))
6285 gfc_ppc_use (comp
, &e
->value
.compcall
.actual
, &e
->where
);
6292 gfc_is_expandable_expr (gfc_expr
*e
)
6294 gfc_constructor
*con
;
6296 if (e
->expr_type
== EXPR_ARRAY
)
6298 /* Traverse the constructor looking for variables that are flavor
6299 parameter. Parameters must be expanded since they are fully used at
6301 con
= gfc_constructor_first (e
->value
.constructor
);
6302 for (; con
; con
= gfc_constructor_next (con
))
6304 if (con
->expr
->expr_type
== EXPR_VARIABLE
6305 && con
->expr
->symtree
6306 && (con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
6307 || con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_VARIABLE
))
6309 if (con
->expr
->expr_type
== EXPR_ARRAY
6310 && gfc_is_expandable_expr (con
->expr
))
6318 /* Resolve an expression. That is, make sure that types of operands agree
6319 with their operators, intrinsic operators are converted to function calls
6320 for overloaded types and unresolved function references are resolved. */
6323 gfc_resolve_expr (gfc_expr
*e
)
6326 bool inquiry_save
, actual_arg_save
, first_actual_arg_save
;
6331 /* inquiry_argument only applies to variables. */
6332 inquiry_save
= inquiry_argument
;
6333 actual_arg_save
= actual_arg
;
6334 first_actual_arg_save
= first_actual_arg
;
6336 if (e
->expr_type
!= EXPR_VARIABLE
)
6338 inquiry_argument
= false;
6340 first_actual_arg
= false;
6343 switch (e
->expr_type
)
6346 t
= resolve_operator (e
);
6352 if (check_host_association (e
))
6353 t
= resolve_function (e
);
6355 t
= resolve_variable (e
);
6357 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.u
.cl
== NULL
&& e
->ref
6358 && e
->ref
->type
!= REF_SUBSTRING
)
6359 gfc_resolve_substring_charlen (e
);
6364 t
= resolve_typebound_function (e
);
6367 case EXPR_SUBSTRING
:
6368 t
= resolve_ref (e
);
6377 t
= resolve_expr_ppc (e
);
6382 if (!resolve_ref (e
))
6385 t
= gfc_resolve_array_constructor (e
);
6386 /* Also try to expand a constructor. */
6389 expression_rank (e
);
6390 if (gfc_is_constant_expr (e
) || gfc_is_expandable_expr (e
))
6391 gfc_expand_constructor (e
, false);
6394 /* This provides the opportunity for the length of constructors with
6395 character valued function elements to propagate the string length
6396 to the expression. */
6397 if (t
&& e
->ts
.type
== BT_CHARACTER
)
6399 /* For efficiency, we call gfc_expand_constructor for BT_CHARACTER
6400 here rather then add a duplicate test for it above. */
6401 gfc_expand_constructor (e
, false);
6402 t
= gfc_resolve_character_array_constructor (e
);
6407 case EXPR_STRUCTURE
:
6408 t
= resolve_ref (e
);
6412 t
= resolve_structure_cons (e
, 0);
6416 t
= gfc_simplify_expr (e
, 0);
6420 gfc_internal_error ("gfc_resolve_expr(): Bad expression type");
6423 if (e
->ts
.type
== BT_CHARACTER
&& t
&& !e
->ts
.u
.cl
)
6426 inquiry_argument
= inquiry_save
;
6427 actual_arg
= actual_arg_save
;
6428 first_actual_arg
= first_actual_arg_save
;
6434 /* Resolve an expression from an iterator. They must be scalar and have
6435 INTEGER or (optionally) REAL type. */
6438 gfc_resolve_iterator_expr (gfc_expr
*expr
, bool real_ok
,
6439 const char *name_msgid
)
6441 if (!gfc_resolve_expr (expr
))
6444 if (expr
->rank
!= 0)
6446 gfc_error ("%s at %L must be a scalar", _(name_msgid
), &expr
->where
);
6450 if (expr
->ts
.type
!= BT_INTEGER
)
6452 if (expr
->ts
.type
== BT_REAL
)
6455 return gfc_notify_std (GFC_STD_F95_DEL
,
6456 "%s at %L must be integer",
6457 _(name_msgid
), &expr
->where
);
6460 gfc_error ("%s at %L must be INTEGER", _(name_msgid
),
6467 gfc_error ("%s at %L must be INTEGER", _(name_msgid
), &expr
->where
);
6475 /* Resolve the expressions in an iterator structure. If REAL_OK is
6476 false allow only INTEGER type iterators, otherwise allow REAL types.
6477 Set own_scope to true for ac-implied-do and data-implied-do as those
6478 have a separate scope such that, e.g., a INTENT(IN) doesn't apply. */
6481 gfc_resolve_iterator (gfc_iterator
*iter
, bool real_ok
, bool own_scope
)
6483 if (!gfc_resolve_iterator_expr (iter
->var
, real_ok
, "Loop variable"))
6486 if (!gfc_check_vardef_context (iter
->var
, false, false, own_scope
,
6487 _("iterator variable")))
6490 if (!gfc_resolve_iterator_expr (iter
->start
, real_ok
,
6491 "Start expression in DO loop"))
6494 if (!gfc_resolve_iterator_expr (iter
->end
, real_ok
,
6495 "End expression in DO loop"))
6498 if (!gfc_resolve_iterator_expr (iter
->step
, real_ok
,
6499 "Step expression in DO loop"))
6502 if (iter
->step
->expr_type
== EXPR_CONSTANT
)
6504 if ((iter
->step
->ts
.type
== BT_INTEGER
6505 && mpz_cmp_ui (iter
->step
->value
.integer
, 0) == 0)
6506 || (iter
->step
->ts
.type
== BT_REAL
6507 && mpfr_sgn (iter
->step
->value
.real
) == 0))
6509 gfc_error ("Step expression in DO loop at %L cannot be zero",
6510 &iter
->step
->where
);
6515 /* Convert start, end, and step to the same type as var. */
6516 if (iter
->start
->ts
.kind
!= iter
->var
->ts
.kind
6517 || iter
->start
->ts
.type
!= iter
->var
->ts
.type
)
6518 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 1);
6520 if (iter
->end
->ts
.kind
!= iter
->var
->ts
.kind
6521 || iter
->end
->ts
.type
!= iter
->var
->ts
.type
)
6522 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 1);
6524 if (iter
->step
->ts
.kind
!= iter
->var
->ts
.kind
6525 || iter
->step
->ts
.type
!= iter
->var
->ts
.type
)
6526 gfc_convert_type (iter
->step
, &iter
->var
->ts
, 1);
6528 if (iter
->start
->expr_type
== EXPR_CONSTANT
6529 && iter
->end
->expr_type
== EXPR_CONSTANT
6530 && iter
->step
->expr_type
== EXPR_CONSTANT
)
6533 if (iter
->start
->ts
.type
== BT_INTEGER
)
6535 sgn
= mpz_cmp_ui (iter
->step
->value
.integer
, 0);
6536 cmp
= mpz_cmp (iter
->end
->value
.integer
, iter
->start
->value
.integer
);
6540 sgn
= mpfr_sgn (iter
->step
->value
.real
);
6541 cmp
= mpfr_cmp (iter
->end
->value
.real
, iter
->start
->value
.real
);
6543 if (warn_zerotrip
&& ((sgn
> 0 && cmp
< 0) || (sgn
< 0 && cmp
> 0)))
6544 gfc_warning (OPT_Wzerotrip
,
6545 "DO loop at %L will be executed zero times",
6546 &iter
->step
->where
);
6549 if (iter
->end
->expr_type
== EXPR_CONSTANT
6550 && iter
->end
->ts
.type
== BT_INTEGER
6551 && iter
->step
->expr_type
== EXPR_CONSTANT
6552 && iter
->step
->ts
.type
== BT_INTEGER
6553 && (mpz_cmp_si (iter
->step
->value
.integer
, -1L) == 0
6554 || mpz_cmp_si (iter
->step
->value
.integer
, 1L) == 0))
6556 bool is_step_positive
= mpz_cmp_ui (iter
->step
->value
.integer
, 1) == 0;
6557 int k
= gfc_validate_kind (BT_INTEGER
, iter
->end
->ts
.kind
, false);
6559 if (is_step_positive
6560 && mpz_cmp (iter
->end
->value
.integer
, gfc_integer_kinds
[k
].huge
) == 0)
6561 gfc_warning (OPT_Wundefined_do_loop
,
6562 "DO loop at %L is undefined as it overflows",
6563 &iter
->step
->where
);
6564 else if (!is_step_positive
6565 && mpz_cmp (iter
->end
->value
.integer
,
6566 gfc_integer_kinds
[k
].min_int
) == 0)
6567 gfc_warning (OPT_Wundefined_do_loop
,
6568 "DO loop at %L is undefined as it underflows",
6569 &iter
->step
->where
);
6576 /* Traversal function for find_forall_index. f == 2 signals that
6577 that variable itself is not to be checked - only the references. */
6580 forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int *f
)
6582 if (expr
->expr_type
!= EXPR_VARIABLE
)
6585 /* A scalar assignment */
6586 if (!expr
->ref
|| *f
== 1)
6588 if (expr
->symtree
->n
.sym
== sym
)
6600 /* Check whether the FORALL index appears in the expression or not.
6601 Returns true if SYM is found in EXPR. */
6604 find_forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int f
)
6606 if (gfc_traverse_expr (expr
, sym
, forall_index
, f
))
6613 /* Resolve a list of FORALL iterators. The FORALL index-name is constrained
6614 to be a scalar INTEGER variable. The subscripts and stride are scalar
6615 INTEGERs, and if stride is a constant it must be nonzero.
6616 Furthermore "A subscript or stride in a forall-triplet-spec shall
6617 not contain a reference to any index-name in the
6618 forall-triplet-spec-list in which it appears." (7.5.4.1) */
6621 resolve_forall_iterators (gfc_forall_iterator
*it
)
6623 gfc_forall_iterator
*iter
, *iter2
;
6625 for (iter
= it
; iter
; iter
= iter
->next
)
6627 if (gfc_resolve_expr (iter
->var
)
6628 && (iter
->var
->ts
.type
!= BT_INTEGER
|| iter
->var
->rank
!= 0))
6629 gfc_error ("FORALL index-name at %L must be a scalar INTEGER",
6632 if (gfc_resolve_expr (iter
->start
)
6633 && (iter
->start
->ts
.type
!= BT_INTEGER
|| iter
->start
->rank
!= 0))
6634 gfc_error ("FORALL start expression at %L must be a scalar INTEGER",
6635 &iter
->start
->where
);
6636 if (iter
->var
->ts
.kind
!= iter
->start
->ts
.kind
)
6637 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 1);
6639 if (gfc_resolve_expr (iter
->end
)
6640 && (iter
->end
->ts
.type
!= BT_INTEGER
|| iter
->end
->rank
!= 0))
6641 gfc_error ("FORALL end expression at %L must be a scalar INTEGER",
6643 if (iter
->var
->ts
.kind
!= iter
->end
->ts
.kind
)
6644 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 1);
6646 if (gfc_resolve_expr (iter
->stride
))
6648 if (iter
->stride
->ts
.type
!= BT_INTEGER
|| iter
->stride
->rank
!= 0)
6649 gfc_error ("FORALL stride expression at %L must be a scalar %s",
6650 &iter
->stride
->where
, "INTEGER");
6652 if (iter
->stride
->expr_type
== EXPR_CONSTANT
6653 && mpz_cmp_ui (iter
->stride
->value
.integer
, 0) == 0)
6654 gfc_error ("FORALL stride expression at %L cannot be zero",
6655 &iter
->stride
->where
);
6657 if (iter
->var
->ts
.kind
!= iter
->stride
->ts
.kind
)
6658 gfc_convert_type (iter
->stride
, &iter
->var
->ts
, 1);
6661 for (iter
= it
; iter
; iter
= iter
->next
)
6662 for (iter2
= iter
; iter2
; iter2
= iter2
->next
)
6664 if (find_forall_index (iter2
->start
, iter
->var
->symtree
->n
.sym
, 0)
6665 || find_forall_index (iter2
->end
, iter
->var
->symtree
->n
.sym
, 0)
6666 || find_forall_index (iter2
->stride
, iter
->var
->symtree
->n
.sym
, 0))
6667 gfc_error ("FORALL index %qs may not appear in triplet "
6668 "specification at %L", iter
->var
->symtree
->name
,
6669 &iter2
->start
->where
);
6674 /* Given a pointer to a symbol that is a derived type, see if it's
6675 inaccessible, i.e. if it's defined in another module and the components are
6676 PRIVATE. The search is recursive if necessary. Returns zero if no
6677 inaccessible components are found, nonzero otherwise. */
6680 derived_inaccessible (gfc_symbol
*sym
)
6684 if (sym
->attr
.use_assoc
&& sym
->attr
.private_comp
)
6687 for (c
= sym
->components
; c
; c
= c
->next
)
6689 if (c
->ts
.type
== BT_DERIVED
&& derived_inaccessible (c
->ts
.u
.derived
))
6697 /* Resolve the argument of a deallocate expression. The expression must be
6698 a pointer or a full array. */
6701 resolve_deallocate_expr (gfc_expr
*e
)
6703 symbol_attribute attr
;
6704 int allocatable
, pointer
;
6710 if (!gfc_resolve_expr (e
))
6713 if (e
->expr_type
!= EXPR_VARIABLE
)
6716 sym
= e
->symtree
->n
.sym
;
6717 unlimited
= UNLIMITED_POLY(sym
);
6719 if (sym
->ts
.type
== BT_CLASS
)
6721 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6722 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6726 allocatable
= sym
->attr
.allocatable
;
6727 pointer
= sym
->attr
.pointer
;
6729 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6734 if (ref
->u
.ar
.type
!= AR_FULL
6735 && !(ref
->u
.ar
.type
== AR_ELEMENT
&& ref
->u
.ar
.as
->rank
== 0
6736 && ref
->u
.ar
.codimen
&& gfc_ref_this_image (ref
)))
6741 c
= ref
->u
.c
.component
;
6742 if (c
->ts
.type
== BT_CLASS
)
6744 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
6745 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
6749 allocatable
= c
->attr
.allocatable
;
6750 pointer
= c
->attr
.pointer
;
6760 attr
= gfc_expr_attr (e
);
6762 if (allocatable
== 0 && attr
.pointer
== 0 && !unlimited
)
6765 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
6771 if (gfc_is_coindexed (e
))
6773 gfc_error ("Coindexed allocatable object at %L", &e
->where
);
6778 && !gfc_check_vardef_context (e
, true, true, false,
6779 _("DEALLOCATE object")))
6781 if (!gfc_check_vardef_context (e
, false, true, false,
6782 _("DEALLOCATE object")))
6789 /* Returns true if the expression e contains a reference to the symbol sym. */
6791 sym_in_expr (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
6793 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
== sym
)
6800 gfc_find_sym_in_expr (gfc_symbol
*sym
, gfc_expr
*e
)
6802 return gfc_traverse_expr (e
, sym
, sym_in_expr
, 0);
6806 /* Given the expression node e for an allocatable/pointer of derived type to be
6807 allocated, get the expression node to be initialized afterwards (needed for
6808 derived types with default initializers, and derived types with allocatable
6809 components that need nullification.) */
6812 gfc_expr_to_initialize (gfc_expr
*e
)
6818 result
= gfc_copy_expr (e
);
6820 /* Change the last array reference from AR_ELEMENT to AR_FULL. */
6821 for (ref
= result
->ref
; ref
; ref
= ref
->next
)
6822 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
6824 ref
->u
.ar
.type
= AR_FULL
;
6826 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
6827 ref
->u
.ar
.start
[i
] = ref
->u
.ar
.end
[i
] = ref
->u
.ar
.stride
[i
] = NULL
;
6832 gfc_free_shape (&result
->shape
, result
->rank
);
6834 /* Recalculate rank, shape, etc. */
6835 gfc_resolve_expr (result
);
6840 /* If the last ref of an expression is an array ref, return a copy of the
6841 expression with that one removed. Otherwise, a copy of the original
6842 expression. This is used for allocate-expressions and pointer assignment
6843 LHS, where there may be an array specification that needs to be stripped
6844 off when using gfc_check_vardef_context. */
6847 remove_last_array_ref (gfc_expr
* e
)
6852 e2
= gfc_copy_expr (e
);
6853 for (r
= &e2
->ref
; *r
; r
= &(*r
)->next
)
6854 if ((*r
)->type
== REF_ARRAY
&& !(*r
)->next
)
6856 gfc_free_ref_list (*r
);
6865 /* Used in resolve_allocate_expr to check that a allocation-object and
6866 a source-expr are conformable. This does not catch all possible
6867 cases; in particular a runtime checking is needed. */
6870 conformable_arrays (gfc_expr
*e1
, gfc_expr
*e2
)
6873 for (tail
= e2
->ref
; tail
&& tail
->next
; tail
= tail
->next
);
6875 /* First compare rank. */
6876 if ((tail
&& e1
->rank
!= tail
->u
.ar
.as
->rank
)
6877 || (!tail
&& e1
->rank
!= e2
->rank
))
6879 gfc_error ("Source-expr at %L must be scalar or have the "
6880 "same rank as the allocate-object at %L",
6881 &e1
->where
, &e2
->where
);
6892 for (i
= 0; i
< e1
->rank
; i
++)
6894 if (tail
->u
.ar
.start
[i
] == NULL
)
6897 if (tail
->u
.ar
.end
[i
])
6899 mpz_set (s
, tail
->u
.ar
.end
[i
]->value
.integer
);
6900 mpz_sub (s
, s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6901 mpz_add_ui (s
, s
, 1);
6905 mpz_set (s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6908 if (mpz_cmp (e1
->shape
[i
], s
) != 0)
6910 gfc_error ("Source-expr at %L and allocate-object at %L must "
6911 "have the same shape", &e1
->where
, &e2
->where
);
6924 /* Resolve the expression in an ALLOCATE statement, doing the additional
6925 checks to see whether the expression is OK or not. The expression must
6926 have a trailing array reference that gives the size of the array. */
6929 resolve_allocate_expr (gfc_expr
*e
, gfc_code
*code
, bool *array_alloc_wo_spec
)
6931 int i
, pointer
, allocatable
, dimension
, is_abstract
;
6935 symbol_attribute attr
;
6936 gfc_ref
*ref
, *ref2
;
6939 gfc_symbol
*sym
= NULL
;
6944 /* Mark the utmost array component as being in allocate to allow DIMEN_STAR
6945 checking of coarrays. */
6946 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6947 if (ref
->next
== NULL
)
6950 if (ref
&& ref
->type
== REF_ARRAY
)
6951 ref
->u
.ar
.in_allocate
= true;
6953 if (!gfc_resolve_expr (e
))
6956 /* Make sure the expression is allocatable or a pointer. If it is
6957 pointer, the next-to-last reference must be a pointer. */
6961 sym
= e
->symtree
->n
.sym
;
6963 /* Check whether ultimate component is abstract and CLASS. */
6966 /* Is the allocate-object unlimited polymorphic? */
6967 unlimited
= UNLIMITED_POLY(e
);
6969 if (e
->expr_type
!= EXPR_VARIABLE
)
6972 attr
= gfc_expr_attr (e
);
6973 pointer
= attr
.pointer
;
6974 dimension
= attr
.dimension
;
6975 codimension
= attr
.codimension
;
6979 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
6981 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6982 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6983 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
6984 codimension
= CLASS_DATA (sym
)->attr
.codimension
;
6985 is_abstract
= CLASS_DATA (sym
)->attr
.abstract
;
6989 allocatable
= sym
->attr
.allocatable
;
6990 pointer
= sym
->attr
.pointer
;
6991 dimension
= sym
->attr
.dimension
;
6992 codimension
= sym
->attr
.codimension
;
6997 for (ref
= e
->ref
; ref
; ref2
= ref
, ref
= ref
->next
)
7002 if (ref
->u
.ar
.codimen
> 0)
7005 for (n
= ref
->u
.ar
.dimen
;
7006 n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
7007 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_THIS_IMAGE
)
7014 if (ref
->next
!= NULL
)
7022 gfc_error ("Coindexed allocatable object at %L",
7027 c
= ref
->u
.c
.component
;
7028 if (c
->ts
.type
== BT_CLASS
)
7030 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
7031 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
7032 dimension
= CLASS_DATA (c
)->attr
.dimension
;
7033 codimension
= CLASS_DATA (c
)->attr
.codimension
;
7034 is_abstract
= CLASS_DATA (c
)->attr
.abstract
;
7038 allocatable
= c
->attr
.allocatable
;
7039 pointer
= c
->attr
.pointer
;
7040 dimension
= c
->attr
.dimension
;
7041 codimension
= c
->attr
.codimension
;
7042 is_abstract
= c
->attr
.abstract
;
7054 /* Check for F08:C628. */
7055 if (allocatable
== 0 && pointer
== 0 && !unlimited
)
7057 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
7062 /* Some checks for the SOURCE tag. */
7065 /* Check F03:C631. */
7066 if (!gfc_type_compatible (&e
->ts
, &code
->expr3
->ts
))
7068 gfc_error ("Type of entity at %L is type incompatible with "
7069 "source-expr at %L", &e
->where
, &code
->expr3
->where
);
7073 /* Check F03:C632 and restriction following Note 6.18. */
7074 if (code
->expr3
->rank
> 0 && !conformable_arrays (code
->expr3
, e
))
7077 /* Check F03:C633. */
7078 if (code
->expr3
->ts
.kind
!= e
->ts
.kind
&& !unlimited
)
7080 gfc_error ("The allocate-object at %L and the source-expr at %L "
7081 "shall have the same kind type parameter",
7082 &e
->where
, &code
->expr3
->where
);
7086 /* Check F2008, C642. */
7087 if (code
->expr3
->ts
.type
== BT_DERIVED
7088 && ((codimension
&& gfc_expr_attr (code
->expr3
).lock_comp
)
7089 || (code
->expr3
->ts
.u
.derived
->from_intmod
7090 == INTMOD_ISO_FORTRAN_ENV
7091 && code
->expr3
->ts
.u
.derived
->intmod_sym_id
7092 == ISOFORTRAN_LOCK_TYPE
)))
7094 gfc_error ("The source-expr at %L shall neither be of type "
7095 "LOCK_TYPE nor have a LOCK_TYPE component if "
7096 "allocate-object at %L is a coarray",
7097 &code
->expr3
->where
, &e
->where
);
7101 /* Check TS18508, C702/C703. */
7102 if (code
->expr3
->ts
.type
== BT_DERIVED
7103 && ((codimension
&& gfc_expr_attr (code
->expr3
).event_comp
)
7104 || (code
->expr3
->ts
.u
.derived
->from_intmod
7105 == INTMOD_ISO_FORTRAN_ENV
7106 && code
->expr3
->ts
.u
.derived
->intmod_sym_id
7107 == ISOFORTRAN_EVENT_TYPE
)))
7109 gfc_error ("The source-expr at %L shall neither be of type "
7110 "EVENT_TYPE nor have a EVENT_TYPE component if "
7111 "allocate-object at %L is a coarray",
7112 &code
->expr3
->where
, &e
->where
);
7117 /* Check F08:C629. */
7118 if (is_abstract
&& code
->ext
.alloc
.ts
.type
== BT_UNKNOWN
7121 gcc_assert (e
->ts
.type
== BT_CLASS
);
7122 gfc_error ("Allocating %s of ABSTRACT base type at %L requires a "
7123 "type-spec or source-expr", sym
->name
, &e
->where
);
7127 /* Check F08:C632. */
7128 if (code
->ext
.alloc
.ts
.type
== BT_CHARACTER
&& !e
->ts
.deferred
7129 && !UNLIMITED_POLY (e
))
7131 int cmp
= gfc_dep_compare_expr (e
->ts
.u
.cl
->length
,
7132 code
->ext
.alloc
.ts
.u
.cl
->length
);
7133 if (cmp
== 1 || cmp
== -1 || cmp
== -3)
7135 gfc_error ("Allocating %s at %L with type-spec requires the same "
7136 "character-length parameter as in the declaration",
7137 sym
->name
, &e
->where
);
7142 /* In the variable definition context checks, gfc_expr_attr is used
7143 on the expression. This is fooled by the array specification
7144 present in e, thus we have to eliminate that one temporarily. */
7145 e2
= remove_last_array_ref (e
);
7148 t
= gfc_check_vardef_context (e2
, true, true, false,
7149 _("ALLOCATE object"));
7151 t
= gfc_check_vardef_context (e2
, false, true, false,
7152 _("ALLOCATE object"));
7157 if (e
->ts
.type
== BT_CLASS
&& CLASS_DATA (e
)->attr
.dimension
7158 && !code
->expr3
&& code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
7160 /* For class arrays, the initialization with SOURCE is done
7161 using _copy and trans_call. It is convenient to exploit that
7162 when the allocated type is different from the declared type but
7163 no SOURCE exists by setting expr3. */
7164 code
->expr3
= gfc_default_initializer (&code
->ext
.alloc
.ts
);
7166 else if (flag_coarray
!= GFC_FCOARRAY_LIB
&& e
->ts
.type
== BT_DERIVED
7167 && e
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
7168 && e
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
7170 /* We have to zero initialize the integer variable. */
7171 code
->expr3
= gfc_get_int_expr (gfc_default_integer_kind
, &e
->where
, 0);
7173 else if (!code
->expr3
)
7175 /* Set up default initializer if needed. */
7179 if (gfc_bt_struct (code
->ext
.alloc
.ts
.type
))
7180 ts
= code
->ext
.alloc
.ts
;
7184 if (ts
.type
== BT_CLASS
)
7185 ts
= ts
.u
.derived
->components
->ts
;
7187 if (gfc_bt_struct (ts
.type
) && (init_e
= gfc_default_initializer (&ts
)))
7189 gfc_code
*init_st
= gfc_get_code (EXEC_INIT_ASSIGN
);
7190 init_st
->loc
= code
->loc
;
7191 init_st
->expr1
= gfc_expr_to_initialize (e
);
7192 init_st
->expr2
= init_e
;
7193 init_st
->next
= code
->next
;
7194 code
->next
= init_st
;
7197 else if (code
->expr3
->mold
&& code
->expr3
->ts
.type
== BT_DERIVED
)
7199 /* Default initialization via MOLD (non-polymorphic). */
7200 gfc_expr
*rhs
= gfc_default_initializer (&code
->expr3
->ts
);
7203 gfc_resolve_expr (rhs
);
7204 gfc_free_expr (code
->expr3
);
7209 if (e
->ts
.type
== BT_CLASS
&& !unlimited
&& !UNLIMITED_POLY (code
->expr3
))
7211 /* Make sure the vtab symbol is present when
7212 the module variables are generated. */
7213 gfc_typespec ts
= e
->ts
;
7215 ts
= code
->expr3
->ts
;
7216 else if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
7217 ts
= code
->ext
.alloc
.ts
;
7219 gfc_find_derived_vtab (ts
.u
.derived
);
7222 e
= gfc_expr_to_initialize (e
);
7224 else if (unlimited
&& !UNLIMITED_POLY (code
->expr3
))
7226 /* Again, make sure the vtab symbol is present when
7227 the module variables are generated. */
7228 gfc_typespec
*ts
= NULL
;
7230 ts
= &code
->expr3
->ts
;
7232 ts
= &code
->ext
.alloc
.ts
;
7239 e
= gfc_expr_to_initialize (e
);
7242 if (dimension
== 0 && codimension
== 0)
7245 /* Make sure the last reference node is an array specification. */
7247 if (!ref2
|| ref2
->type
!= REF_ARRAY
|| ref2
->u
.ar
.type
== AR_FULL
7248 || (dimension
&& ref2
->u
.ar
.dimen
== 0))
7253 if (!gfc_notify_std (GFC_STD_F2008
, "Array specification required "
7254 "in ALLOCATE statement at %L", &e
->where
))
7256 if (code
->expr3
->rank
!= 0)
7257 *array_alloc_wo_spec
= true;
7260 gfc_error ("Array specification or array-valued SOURCE= "
7261 "expression required in ALLOCATE statement at %L",
7268 gfc_error ("Array specification required in ALLOCATE statement "
7269 "at %L", &e
->where
);
7274 /* Make sure that the array section reference makes sense in the
7275 context of an ALLOCATE specification. */
7280 for (i
= ar
->dimen
; i
< ar
->dimen
+ ar
->codimen
; i
++)
7281 if (ar
->dimen_type
[i
] == DIMEN_THIS_IMAGE
)
7283 gfc_error ("Coarray specification required in ALLOCATE statement "
7284 "at %L", &e
->where
);
7288 for (i
= 0; i
< ar
->dimen
; i
++)
7290 if (ar
->type
== AR_ELEMENT
|| ar
->type
== AR_FULL
)
7293 switch (ar
->dimen_type
[i
])
7299 if (ar
->start
[i
] != NULL
7300 && ar
->end
[i
] != NULL
7301 && ar
->stride
[i
] == NULL
)
7304 /* Fall Through... */
7309 case DIMEN_THIS_IMAGE
:
7310 gfc_error ("Bad array specification in ALLOCATE statement at %L",
7316 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7318 sym
= a
->expr
->symtree
->n
.sym
;
7320 /* TODO - check derived type components. */
7321 if (gfc_bt_struct (sym
->ts
.type
) || sym
->ts
.type
== BT_CLASS
)
7324 if ((ar
->start
[i
] != NULL
7325 && gfc_find_sym_in_expr (sym
, ar
->start
[i
]))
7326 || (ar
->end
[i
] != NULL
7327 && gfc_find_sym_in_expr (sym
, ar
->end
[i
])))
7329 gfc_error ("%qs must not appear in the array specification at "
7330 "%L in the same ALLOCATE statement where it is "
7331 "itself allocated", sym
->name
, &ar
->where
);
7337 for (i
= ar
->dimen
; i
< ar
->codimen
+ ar
->dimen
; i
++)
7339 if (ar
->dimen_type
[i
] == DIMEN_ELEMENT
7340 || ar
->dimen_type
[i
] == DIMEN_RANGE
)
7342 if (i
== (ar
->dimen
+ ar
->codimen
- 1))
7344 gfc_error ("Expected '*' in coindex specification in ALLOCATE "
7345 "statement at %L", &e
->where
);
7351 if (ar
->dimen_type
[i
] == DIMEN_STAR
&& i
== (ar
->dimen
+ ar
->codimen
- 1)
7352 && ar
->stride
[i
] == NULL
)
7355 gfc_error ("Bad coarray specification in ALLOCATE statement at %L",
7369 resolve_allocate_deallocate (gfc_code
*code
, const char *fcn
)
7371 gfc_expr
*stat
, *errmsg
, *pe
, *qe
;
7372 gfc_alloc
*a
, *p
, *q
;
7375 errmsg
= code
->expr2
;
7377 /* Check the stat variable. */
7380 gfc_check_vardef_context (stat
, false, false, false,
7381 _("STAT variable"));
7383 if ((stat
->ts
.type
!= BT_INTEGER
7384 && !(stat
->ref
&& (stat
->ref
->type
== REF_ARRAY
7385 || stat
->ref
->type
== REF_COMPONENT
)))
7387 gfc_error ("Stat-variable at %L must be a scalar INTEGER "
7388 "variable", &stat
->where
);
7390 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7391 if (p
->expr
->symtree
->n
.sym
->name
== stat
->symtree
->n
.sym
->name
)
7393 gfc_ref
*ref1
, *ref2
;
7396 for (ref1
= p
->expr
->ref
, ref2
= stat
->ref
; ref1
&& ref2
;
7397 ref1
= ref1
->next
, ref2
= ref2
->next
)
7399 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
7401 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
7410 gfc_error ("Stat-variable at %L shall not be %sd within "
7411 "the same %s statement", &stat
->where
, fcn
, fcn
);
7417 /* Check the errmsg variable. */
7421 gfc_warning (0, "ERRMSG at %L is useless without a STAT tag",
7424 gfc_check_vardef_context (errmsg
, false, false, false,
7425 _("ERRMSG variable"));
7427 if ((errmsg
->ts
.type
!= BT_CHARACTER
7429 && (errmsg
->ref
->type
== REF_ARRAY
7430 || errmsg
->ref
->type
== REF_COMPONENT
)))
7431 || errmsg
->rank
> 0 )
7432 gfc_error ("Errmsg-variable at %L must be a scalar CHARACTER "
7433 "variable", &errmsg
->where
);
7435 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7436 if (p
->expr
->symtree
->n
.sym
->name
== errmsg
->symtree
->n
.sym
->name
)
7438 gfc_ref
*ref1
, *ref2
;
7441 for (ref1
= p
->expr
->ref
, ref2
= errmsg
->ref
; ref1
&& ref2
;
7442 ref1
= ref1
->next
, ref2
= ref2
->next
)
7444 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
7446 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
7455 gfc_error ("Errmsg-variable at %L shall not be %sd within "
7456 "the same %s statement", &errmsg
->where
, fcn
, fcn
);
7462 /* Check that an allocate-object appears only once in the statement. */
7464 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7467 for (q
= p
->next
; q
; q
= q
->next
)
7470 if (pe
->symtree
->n
.sym
->name
== qe
->symtree
->n
.sym
->name
)
7472 /* This is a potential collision. */
7473 gfc_ref
*pr
= pe
->ref
;
7474 gfc_ref
*qr
= qe
->ref
;
7476 /* Follow the references until
7477 a) They start to differ, in which case there is no error;
7478 you can deallocate a%b and a%c in a single statement
7479 b) Both of them stop, which is an error
7480 c) One of them stops, which is also an error. */
7483 if (pr
== NULL
&& qr
== NULL
)
7485 gfc_error ("Allocate-object at %L also appears at %L",
7486 &pe
->where
, &qe
->where
);
7489 else if (pr
!= NULL
&& qr
== NULL
)
7491 gfc_error ("Allocate-object at %L is subobject of"
7492 " object at %L", &pe
->where
, &qe
->where
);
7495 else if (pr
== NULL
&& qr
!= NULL
)
7497 gfc_error ("Allocate-object at %L is subobject of"
7498 " object at %L", &qe
->where
, &pe
->where
);
7501 /* Here, pr != NULL && qr != NULL */
7502 gcc_assert(pr
->type
== qr
->type
);
7503 if (pr
->type
== REF_ARRAY
)
7505 /* Handle cases like allocate(v(3)%x(3), v(2)%x(3)),
7507 gcc_assert (qr
->type
== REF_ARRAY
);
7509 if (pr
->next
&& qr
->next
)
7512 gfc_array_ref
*par
= &(pr
->u
.ar
);
7513 gfc_array_ref
*qar
= &(qr
->u
.ar
);
7515 for (i
=0; i
<par
->dimen
; i
++)
7517 if ((par
->start
[i
] != NULL
7518 || qar
->start
[i
] != NULL
)
7519 && gfc_dep_compare_expr (par
->start
[i
],
7520 qar
->start
[i
]) != 0)
7527 if (pr
->u
.c
.component
->name
!= qr
->u
.c
.component
->name
)
7540 if (strcmp (fcn
, "ALLOCATE") == 0)
7542 bool arr_alloc_wo_spec
= false;
7543 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7544 resolve_allocate_expr (a
->expr
, code
, &arr_alloc_wo_spec
);
7546 if (arr_alloc_wo_spec
&& code
->expr3
)
7548 /* Mark the allocate to have to take the array specification
7550 code
->ext
.alloc
.arr_spec_from_expr3
= 1;
7555 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7556 resolve_deallocate_expr (a
->expr
);
7561 /************ SELECT CASE resolution subroutines ************/
7563 /* Callback function for our mergesort variant. Determines interval
7564 overlaps for CASEs. Return <0 if op1 < op2, 0 for overlap, >0 for
7565 op1 > op2. Assumes we're not dealing with the default case.
7566 We have op1 = (:L), (K:L) or (K:) and op2 = (:N), (M:N) or (M:).
7567 There are nine situations to check. */
7570 compare_cases (const gfc_case
*op1
, const gfc_case
*op2
)
7574 if (op1
->low
== NULL
) /* op1 = (:L) */
7576 /* op2 = (:N), so overlap. */
7578 /* op2 = (M:) or (M:N), L < M */
7579 if (op2
->low
!= NULL
7580 && gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7583 else if (op1
->high
== NULL
) /* op1 = (K:) */
7585 /* op2 = (M:), so overlap. */
7587 /* op2 = (:N) or (M:N), K > N */
7588 if (op2
->high
!= NULL
7589 && gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7592 else /* op1 = (K:L) */
7594 if (op2
->low
== NULL
) /* op2 = (:N), K > N */
7595 retval
= (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7597 else if (op2
->high
== NULL
) /* op2 = (M:), L < M */
7598 retval
= (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7600 else /* op2 = (M:N) */
7604 if (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7607 else if (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7616 /* Merge-sort a double linked case list, detecting overlap in the
7617 process. LIST is the head of the double linked case list before it
7618 is sorted. Returns the head of the sorted list if we don't see any
7619 overlap, or NULL otherwise. */
7622 check_case_overlap (gfc_case
*list
)
7624 gfc_case
*p
, *q
, *e
, *tail
;
7625 int insize
, nmerges
, psize
, qsize
, cmp
, overlap_seen
;
7627 /* If the passed list was empty, return immediately. */
7634 /* Loop unconditionally. The only exit from this loop is a return
7635 statement, when we've finished sorting the case list. */
7642 /* Count the number of merges we do in this pass. */
7645 /* Loop while there exists a merge to be done. */
7650 /* Count this merge. */
7653 /* Cut the list in two pieces by stepping INSIZE places
7654 forward in the list, starting from P. */
7657 for (i
= 0; i
< insize
; i
++)
7666 /* Now we have two lists. Merge them! */
7667 while (psize
> 0 || (qsize
> 0 && q
!= NULL
))
7669 /* See from which the next case to merge comes from. */
7672 /* P is empty so the next case must come from Q. */
7677 else if (qsize
== 0 || q
== NULL
)
7686 cmp
= compare_cases (p
, q
);
7689 /* The whole case range for P is less than the
7697 /* The whole case range for Q is greater than
7698 the case range for P. */
7705 /* The cases overlap, or they are the same
7706 element in the list. Either way, we must
7707 issue an error and get the next case from P. */
7708 /* FIXME: Sort P and Q by line number. */
7709 gfc_error ("CASE label at %L overlaps with CASE "
7710 "label at %L", &p
->where
, &q
->where
);
7718 /* Add the next element to the merged list. */
7727 /* P has now stepped INSIZE places along, and so has Q. So
7728 they're the same. */
7733 /* If we have done only one merge or none at all, we've
7734 finished sorting the cases. */
7743 /* Otherwise repeat, merging lists twice the size. */
7749 /* Check to see if an expression is suitable for use in a CASE statement.
7750 Makes sure that all case expressions are scalar constants of the same
7751 type. Return false if anything is wrong. */
7754 validate_case_label_expr (gfc_expr
*e
, gfc_expr
*case_expr
)
7756 if (e
== NULL
) return true;
7758 if (e
->ts
.type
!= case_expr
->ts
.type
)
7760 gfc_error ("Expression in CASE statement at %L must be of type %s",
7761 &e
->where
, gfc_basic_typename (case_expr
->ts
.type
));
7765 /* C805 (R808) For a given case-construct, each case-value shall be of
7766 the same type as case-expr. For character type, length differences
7767 are allowed, but the kind type parameters shall be the same. */
7769 if (case_expr
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= case_expr
->ts
.kind
)
7771 gfc_error ("Expression in CASE statement at %L must be of kind %d",
7772 &e
->where
, case_expr
->ts
.kind
);
7776 /* Convert the case value kind to that of case expression kind,
7779 if (e
->ts
.kind
!= case_expr
->ts
.kind
)
7780 gfc_convert_type_warn (e
, &case_expr
->ts
, 2, 0);
7784 gfc_error ("Expression in CASE statement at %L must be scalar",
7793 /* Given a completely parsed select statement, we:
7795 - Validate all expressions and code within the SELECT.
7796 - Make sure that the selection expression is not of the wrong type.
7797 - Make sure that no case ranges overlap.
7798 - Eliminate unreachable cases and unreachable code resulting from
7799 removing case labels.
7801 The standard does allow unreachable cases, e.g. CASE (5:3). But
7802 they are a hassle for code generation, and to prevent that, we just
7803 cut them out here. This is not necessary for overlapping cases
7804 because they are illegal and we never even try to generate code.
7806 We have the additional caveat that a SELECT construct could have
7807 been a computed GOTO in the source code. Fortunately we can fairly
7808 easily work around that here: The case_expr for a "real" SELECT CASE
7809 is in code->expr1, but for a computed GOTO it is in code->expr2. All
7810 we have to do is make sure that the case_expr is a scalar integer
7814 resolve_select (gfc_code
*code
, bool select_type
)
7817 gfc_expr
*case_expr
;
7818 gfc_case
*cp
, *default_case
, *tail
, *head
;
7819 int seen_unreachable
;
7825 if (code
->expr1
== NULL
)
7827 /* This was actually a computed GOTO statement. */
7828 case_expr
= code
->expr2
;
7829 if (case_expr
->ts
.type
!= BT_INTEGER
|| case_expr
->rank
!= 0)
7830 gfc_error ("Selection expression in computed GOTO statement "
7831 "at %L must be a scalar integer expression",
7834 /* Further checking is not necessary because this SELECT was built
7835 by the compiler, so it should always be OK. Just move the
7836 case_expr from expr2 to expr so that we can handle computed
7837 GOTOs as normal SELECTs from here on. */
7838 code
->expr1
= code
->expr2
;
7843 case_expr
= code
->expr1
;
7844 type
= case_expr
->ts
.type
;
7847 if (type
!= BT_LOGICAL
&& type
!= BT_INTEGER
&& type
!= BT_CHARACTER
)
7849 gfc_error ("Argument of SELECT statement at %L cannot be %s",
7850 &case_expr
->where
, gfc_typename (&case_expr
->ts
));
7852 /* Punt. Going on here just produce more garbage error messages. */
7857 if (!select_type
&& case_expr
->rank
!= 0)
7859 gfc_error ("Argument of SELECT statement at %L must be a scalar "
7860 "expression", &case_expr
->where
);
7866 /* Raise a warning if an INTEGER case value exceeds the range of
7867 the case-expr. Later, all expressions will be promoted to the
7868 largest kind of all case-labels. */
7870 if (type
== BT_INTEGER
)
7871 for (body
= code
->block
; body
; body
= body
->block
)
7872 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7875 && gfc_check_integer_range (cp
->low
->value
.integer
,
7876 case_expr
->ts
.kind
) != ARITH_OK
)
7877 gfc_warning (0, "Expression in CASE statement at %L is "
7878 "not in the range of %s", &cp
->low
->where
,
7879 gfc_typename (&case_expr
->ts
));
7882 && cp
->low
!= cp
->high
7883 && gfc_check_integer_range (cp
->high
->value
.integer
,
7884 case_expr
->ts
.kind
) != ARITH_OK
)
7885 gfc_warning (0, "Expression in CASE statement at %L is "
7886 "not in the range of %s", &cp
->high
->where
,
7887 gfc_typename (&case_expr
->ts
));
7890 /* PR 19168 has a long discussion concerning a mismatch of the kinds
7891 of the SELECT CASE expression and its CASE values. Walk the lists
7892 of case values, and if we find a mismatch, promote case_expr to
7893 the appropriate kind. */
7895 if (type
== BT_LOGICAL
|| type
== BT_INTEGER
)
7897 for (body
= code
->block
; body
; body
= body
->block
)
7899 /* Walk the case label list. */
7900 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7902 /* Intercept the DEFAULT case. It does not have a kind. */
7903 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7906 /* Unreachable case ranges are discarded, so ignore. */
7907 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7908 && cp
->low
!= cp
->high
7909 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7913 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->low
))
7914 gfc_convert_type_warn (case_expr
, &cp
->low
->ts
, 2, 0);
7916 if (cp
->high
!= NULL
7917 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->high
))
7918 gfc_convert_type_warn (case_expr
, &cp
->high
->ts
, 2, 0);
7923 /* Assume there is no DEFAULT case. */
7924 default_case
= NULL
;
7929 for (body
= code
->block
; body
; body
= body
->block
)
7931 /* Assume the CASE list is OK, and all CASE labels can be matched. */
7933 seen_unreachable
= 0;
7935 /* Walk the case label list, making sure that all case labels
7937 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7939 /* Count the number of cases in the whole construct. */
7942 /* Intercept the DEFAULT case. */
7943 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7945 if (default_case
!= NULL
)
7947 gfc_error ("The DEFAULT CASE at %L cannot be followed "
7948 "by a second DEFAULT CASE at %L",
7949 &default_case
->where
, &cp
->where
);
7960 /* Deal with single value cases and case ranges. Errors are
7961 issued from the validation function. */
7962 if (!validate_case_label_expr (cp
->low
, case_expr
)
7963 || !validate_case_label_expr (cp
->high
, case_expr
))
7969 if (type
== BT_LOGICAL
7970 && ((cp
->low
== NULL
|| cp
->high
== NULL
)
7971 || cp
->low
!= cp
->high
))
7973 gfc_error ("Logical range in CASE statement at %L is not "
7974 "allowed", &cp
->low
->where
);
7979 if (type
== BT_LOGICAL
&& cp
->low
->expr_type
== EXPR_CONSTANT
)
7982 value
= cp
->low
->value
.logical
== 0 ? 2 : 1;
7983 if (value
& seen_logical
)
7985 gfc_error ("Constant logical value in CASE statement "
7986 "is repeated at %L",
7991 seen_logical
|= value
;
7994 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7995 && cp
->low
!= cp
->high
7996 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7998 if (warn_surprising
)
7999 gfc_warning (OPT_Wsurprising
,
8000 "Range specification at %L can never be matched",
8003 cp
->unreachable
= 1;
8004 seen_unreachable
= 1;
8008 /* If the case range can be matched, it can also overlap with
8009 other cases. To make sure it does not, we put it in a
8010 double linked list here. We sort that with a merge sort
8011 later on to detect any overlapping cases. */
8015 head
->right
= head
->left
= NULL
;
8020 tail
->right
->left
= tail
;
8027 /* It there was a failure in the previous case label, give up
8028 for this case label list. Continue with the next block. */
8032 /* See if any case labels that are unreachable have been seen.
8033 If so, we eliminate them. This is a bit of a kludge because
8034 the case lists for a single case statement (label) is a
8035 single forward linked lists. */
8036 if (seen_unreachable
)
8038 /* Advance until the first case in the list is reachable. */
8039 while (body
->ext
.block
.case_list
!= NULL
8040 && body
->ext
.block
.case_list
->unreachable
)
8042 gfc_case
*n
= body
->ext
.block
.case_list
;
8043 body
->ext
.block
.case_list
= body
->ext
.block
.case_list
->next
;
8045 gfc_free_case_list (n
);
8048 /* Strip all other unreachable cases. */
8049 if (body
->ext
.block
.case_list
)
8051 for (cp
= body
->ext
.block
.case_list
; cp
&& cp
->next
; cp
= cp
->next
)
8053 if (cp
->next
->unreachable
)
8055 gfc_case
*n
= cp
->next
;
8056 cp
->next
= cp
->next
->next
;
8058 gfc_free_case_list (n
);
8065 /* See if there were overlapping cases. If the check returns NULL,
8066 there was overlap. In that case we don't do anything. If head
8067 is non-NULL, we prepend the DEFAULT case. The sorted list can
8068 then used during code generation for SELECT CASE constructs with
8069 a case expression of a CHARACTER type. */
8072 head
= check_case_overlap (head
);
8074 /* Prepend the default_case if it is there. */
8075 if (head
!= NULL
&& default_case
)
8077 default_case
->left
= NULL
;
8078 default_case
->right
= head
;
8079 head
->left
= default_case
;
8083 /* Eliminate dead blocks that may be the result if we've seen
8084 unreachable case labels for a block. */
8085 for (body
= code
; body
&& body
->block
; body
= body
->block
)
8087 if (body
->block
->ext
.block
.case_list
== NULL
)
8089 /* Cut the unreachable block from the code chain. */
8090 gfc_code
*c
= body
->block
;
8091 body
->block
= c
->block
;
8093 /* Kill the dead block, but not the blocks below it. */
8095 gfc_free_statements (c
);
8099 /* More than two cases is legal but insane for logical selects.
8100 Issue a warning for it. */
8101 if (warn_surprising
&& type
== BT_LOGICAL
&& ncases
> 2)
8102 gfc_warning (OPT_Wsurprising
,
8103 "Logical SELECT CASE block at %L has more that two cases",
8108 /* Check if a derived type is extensible. */
8111 gfc_type_is_extensible (gfc_symbol
*sym
)
8113 return !(sym
->attr
.is_bind_c
|| sym
->attr
.sequence
8114 || (sym
->attr
.is_class
8115 && sym
->components
->ts
.u
.derived
->attr
.unlimited_polymorphic
));
8120 resolve_types (gfc_namespace
*ns
);
8122 /* Resolve an associate-name: Resolve target and ensure the type-spec is
8123 correct as well as possibly the array-spec. */
8126 resolve_assoc_var (gfc_symbol
* sym
, bool resolve_target
)
8130 gcc_assert (sym
->assoc
);
8131 gcc_assert (sym
->attr
.flavor
== FL_VARIABLE
);
8133 /* If this is for SELECT TYPE, the target may not yet be set. In that
8134 case, return. Resolution will be called later manually again when
8136 target
= sym
->assoc
->target
;
8139 gcc_assert (!sym
->assoc
->dangling
);
8141 if (resolve_target
&& !gfc_resolve_expr (target
))
8144 /* For variable targets, we get some attributes from the target. */
8145 if (target
->expr_type
== EXPR_VARIABLE
)
8149 gcc_assert (target
->symtree
);
8150 tsym
= target
->symtree
->n
.sym
;
8152 sym
->attr
.asynchronous
= tsym
->attr
.asynchronous
;
8153 sym
->attr
.volatile_
= tsym
->attr
.volatile_
;
8155 sym
->attr
.target
= tsym
->attr
.target
8156 || gfc_expr_attr (target
).pointer
;
8157 if (is_subref_array (target
))
8158 sym
->attr
.subref_array_pointer
= 1;
8161 /* Get type if this was not already set. Note that it can be
8162 some other type than the target in case this is a SELECT TYPE
8163 selector! So we must not update when the type is already there. */
8164 if (sym
->ts
.type
== BT_UNKNOWN
)
8165 sym
->ts
= target
->ts
;
8166 gcc_assert (sym
->ts
.type
!= BT_UNKNOWN
);
8168 /* See if this is a valid association-to-variable. */
8169 sym
->assoc
->variable
= (target
->expr_type
== EXPR_VARIABLE
8170 && !gfc_has_vector_subscript (target
));
8172 /* Finally resolve if this is an array or not. */
8173 if (sym
->attr
.dimension
&& target
->rank
== 0)
8175 /* primary.c makes the assumption that a reference to an associate
8176 name followed by a left parenthesis is an array reference. */
8177 if (sym
->ts
.type
!= BT_CHARACTER
)
8178 gfc_error ("Associate-name %qs at %L is used as array",
8179 sym
->name
, &sym
->declared_at
);
8180 sym
->attr
.dimension
= 0;
8185 /* We cannot deal with class selectors that need temporaries. */
8186 if (target
->ts
.type
== BT_CLASS
8187 && gfc_ref_needs_temporary_p (target
->ref
))
8189 gfc_error ("CLASS selector at %L needs a temporary which is not "
8190 "yet implemented", &target
->where
);
8194 if (target
->ts
.type
== BT_CLASS
)
8195 gfc_fix_class_refs (target
);
8197 if (target
->rank
!= 0)
8200 /* The rank may be incorrectly guessed at parsing, therefore make sure
8201 it is corrected now. */
8202 if (sym
->ts
.type
!= BT_CLASS
&& (!sym
->as
|| sym
->assoc
->rankguessed
))
8205 sym
->as
= gfc_get_array_spec ();
8207 as
->rank
= target
->rank
;
8208 as
->type
= AS_DEFERRED
;
8209 as
->corank
= gfc_get_corank (target
);
8210 sym
->attr
.dimension
= 1;
8211 if (as
->corank
!= 0)
8212 sym
->attr
.codimension
= 1;
8217 /* target's rank is 0, but the type of the sym is still array valued,
8218 which has to be corrected. */
8219 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->as
)
8222 symbol_attribute attr
;
8223 /* The associated variable's type is still the array type
8224 correct this now. */
8225 gfc_typespec
*ts
= &target
->ts
;
8228 for (ref
= target
->ref
; ref
!= NULL
; ref
= ref
->next
)
8233 ts
= &ref
->u
.c
.component
->ts
;
8236 if (ts
->type
== BT_CLASS
)
8237 ts
= &ts
->u
.derived
->components
->ts
;
8243 /* Create a scalar instance of the current class type. Because the
8244 rank of a class array goes into its name, the type has to be
8245 rebuild. The alternative of (re-)setting just the attributes
8246 and as in the current type, destroys the type also in other
8250 sym
->ts
.type
= BT_CLASS
;
8251 attr
= CLASS_DATA (sym
)->attr
;
8253 attr
.associate_var
= 1;
8254 attr
.dimension
= attr
.codimension
= 0;
8255 attr
.class_pointer
= 1;
8256 if (!gfc_build_class_symbol (&sym
->ts
, &attr
, &as
))
8258 /* Make sure the _vptr is set. */
8259 c
= gfc_find_component (sym
->ts
.u
.derived
, "_vptr", true, true, NULL
);
8260 if (c
->ts
.u
.derived
== NULL
)
8261 c
->ts
.u
.derived
= gfc_find_derived_vtab (sym
->ts
.u
.derived
);
8262 CLASS_DATA (sym
)->attr
.pointer
= 1;
8263 CLASS_DATA (sym
)->attr
.class_pointer
= 1;
8264 gfc_set_sym_referenced (sym
->ts
.u
.derived
);
8265 gfc_commit_symbol (sym
->ts
.u
.derived
);
8266 /* _vptr now has the _vtab in it, change it to the _vtype. */
8267 if (c
->ts
.u
.derived
->attr
.vtab
)
8268 c
->ts
.u
.derived
= c
->ts
.u
.derived
->ts
.u
.derived
;
8269 c
->ts
.u
.derived
->ns
->types_resolved
= 0;
8270 resolve_types (c
->ts
.u
.derived
->ns
);
8274 /* Mark this as an associate variable. */
8275 sym
->attr
.associate_var
= 1;
8277 /* If the target is a good class object, so is the associate variable. */
8278 if (sym
->ts
.type
== BT_CLASS
&& gfc_expr_attr (target
).class_ok
)
8279 sym
->attr
.class_ok
= 1;
8283 /* Resolve a SELECT TYPE statement. */
8286 resolve_select_type (gfc_code
*code
, gfc_namespace
*old_ns
)
8288 gfc_symbol
*selector_type
;
8289 gfc_code
*body
, *new_st
, *if_st
, *tail
;
8290 gfc_code
*class_is
= NULL
, *default_case
= NULL
;
8293 char name
[GFC_MAX_SYMBOL_LEN
];
8298 ns
= code
->ext
.block
.ns
;
8301 /* Check for F03:C813. */
8302 if (code
->expr1
->ts
.type
!= BT_CLASS
8303 && !(code
->expr2
&& code
->expr2
->ts
.type
== BT_CLASS
))
8305 gfc_error ("Selector shall be polymorphic in SELECT TYPE statement "
8306 "at %L", &code
->loc
);
8310 if (!code
->expr1
->symtree
->n
.sym
->attr
.class_ok
)
8315 if (code
->expr1
->symtree
->n
.sym
->attr
.untyped
)
8316 code
->expr1
->symtree
->n
.sym
->ts
= code
->expr2
->ts
;
8317 selector_type
= CLASS_DATA (code
->expr2
)->ts
.u
.derived
;
8319 /* F2008: C803 The selector expression must not be coindexed. */
8320 if (gfc_is_coindexed (code
->expr2
))
8322 gfc_error ("Selector at %L must not be coindexed",
8323 &code
->expr2
->where
);
8330 selector_type
= CLASS_DATA (code
->expr1
)->ts
.u
.derived
;
8332 if (gfc_is_coindexed (code
->expr1
))
8334 gfc_error ("Selector at %L must not be coindexed",
8335 &code
->expr1
->where
);
8340 /* Loop over TYPE IS / CLASS IS cases. */
8341 for (body
= code
->block
; body
; body
= body
->block
)
8343 c
= body
->ext
.block
.case_list
;
8345 /* Check F03:C815. */
8346 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
8347 && !selector_type
->attr
.unlimited_polymorphic
8348 && !gfc_type_is_extensible (c
->ts
.u
.derived
))
8350 gfc_error ("Derived type %qs at %L must be extensible",
8351 c
->ts
.u
.derived
->name
, &c
->where
);
8356 /* Check F03:C816. */
8357 if (c
->ts
.type
!= BT_UNKNOWN
&& !selector_type
->attr
.unlimited_polymorphic
8358 && ((c
->ts
.type
!= BT_DERIVED
&& c
->ts
.type
!= BT_CLASS
)
8359 || !gfc_type_is_extension_of (selector_type
, c
->ts
.u
.derived
)))
8361 if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
8362 gfc_error ("Derived type %qs at %L must be an extension of %qs",
8363 c
->ts
.u
.derived
->name
, &c
->where
, selector_type
->name
);
8365 gfc_error ("Unexpected intrinsic type %qs at %L",
8366 gfc_basic_typename (c
->ts
.type
), &c
->where
);
8371 /* Check F03:C814. */
8372 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.u
.cl
->length
!= NULL
)
8374 gfc_error ("The type-spec at %L shall specify that each length "
8375 "type parameter is assumed", &c
->where
);
8380 /* Intercept the DEFAULT case. */
8381 if (c
->ts
.type
== BT_UNKNOWN
)
8383 /* Check F03:C818. */
8386 gfc_error ("The DEFAULT CASE at %L cannot be followed "
8387 "by a second DEFAULT CASE at %L",
8388 &default_case
->ext
.block
.case_list
->where
, &c
->where
);
8393 default_case
= body
;
8400 /* Transform SELECT TYPE statement to BLOCK and associate selector to
8401 target if present. If there are any EXIT statements referring to the
8402 SELECT TYPE construct, this is no problem because the gfc_code
8403 reference stays the same and EXIT is equally possible from the BLOCK
8404 it is changed to. */
8405 code
->op
= EXEC_BLOCK
;
8408 gfc_association_list
* assoc
;
8410 assoc
= gfc_get_association_list ();
8411 assoc
->st
= code
->expr1
->symtree
;
8412 assoc
->target
= gfc_copy_expr (code
->expr2
);
8413 assoc
->target
->where
= code
->expr2
->where
;
8414 /* assoc->variable will be set by resolve_assoc_var. */
8416 code
->ext
.block
.assoc
= assoc
;
8417 code
->expr1
->symtree
->n
.sym
->assoc
= assoc
;
8419 resolve_assoc_var (code
->expr1
->symtree
->n
.sym
, false);
8422 code
->ext
.block
.assoc
= NULL
;
8424 /* Add EXEC_SELECT to switch on type. */
8425 new_st
= gfc_get_code (code
->op
);
8426 new_st
->expr1
= code
->expr1
;
8427 new_st
->expr2
= code
->expr2
;
8428 new_st
->block
= code
->block
;
8429 code
->expr1
= code
->expr2
= NULL
;
8434 ns
->code
->next
= new_st
;
8436 code
->op
= EXEC_SELECT
;
8438 gfc_add_vptr_component (code
->expr1
);
8439 gfc_add_hash_component (code
->expr1
);
8441 /* Loop over TYPE IS / CLASS IS cases. */
8442 for (body
= code
->block
; body
; body
= body
->block
)
8444 c
= body
->ext
.block
.case_list
;
8446 if (c
->ts
.type
== BT_DERIVED
)
8447 c
->low
= c
->high
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
8448 c
->ts
.u
.derived
->hash_value
);
8449 else if (c
->ts
.type
!= BT_CLASS
&& c
->ts
.type
!= BT_UNKNOWN
)
8454 ivtab
= gfc_find_vtab (&c
->ts
);
8455 gcc_assert (ivtab
&& CLASS_DATA (ivtab
)->initializer
);
8456 e
= CLASS_DATA (ivtab
)->initializer
;
8457 c
->low
= c
->high
= gfc_copy_expr (e
);
8460 else if (c
->ts
.type
== BT_UNKNOWN
)
8463 /* Associate temporary to selector. This should only be done
8464 when this case is actually true, so build a new ASSOCIATE
8465 that does precisely this here (instead of using the
8468 if (c
->ts
.type
== BT_CLASS
)
8469 sprintf (name
, "__tmp_class_%s", c
->ts
.u
.derived
->name
);
8470 else if (c
->ts
.type
== BT_DERIVED
)
8471 sprintf (name
, "__tmp_type_%s", c
->ts
.u
.derived
->name
);
8472 else if (c
->ts
.type
== BT_CHARACTER
)
8474 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
8475 && c
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
8476 charlen
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
8477 sprintf (name
, "__tmp_%s_%d_%d", gfc_basic_typename (c
->ts
.type
),
8478 charlen
, c
->ts
.kind
);
8481 sprintf (name
, "__tmp_%s_%d", gfc_basic_typename (c
->ts
.type
),
8484 st
= gfc_find_symtree (ns
->sym_root
, name
);
8485 gcc_assert (st
->n
.sym
->assoc
);
8486 st
->n
.sym
->assoc
->target
= gfc_get_variable_expr (code
->expr1
->symtree
);
8487 st
->n
.sym
->assoc
->target
->where
= code
->expr1
->where
;
8488 if (c
->ts
.type
!= BT_CLASS
&& c
->ts
.type
!= BT_UNKNOWN
)
8489 gfc_add_data_component (st
->n
.sym
->assoc
->target
);
8491 new_st
= gfc_get_code (EXEC_BLOCK
);
8492 new_st
->ext
.block
.ns
= gfc_build_block_ns (ns
);
8493 new_st
->ext
.block
.ns
->code
= body
->next
;
8494 body
->next
= new_st
;
8496 /* Chain in the new list only if it is marked as dangling. Otherwise
8497 there is a CASE label overlap and this is already used. Just ignore,
8498 the error is diagnosed elsewhere. */
8499 if (st
->n
.sym
->assoc
->dangling
)
8501 new_st
->ext
.block
.assoc
= st
->n
.sym
->assoc
;
8502 st
->n
.sym
->assoc
->dangling
= 0;
8505 resolve_assoc_var (st
->n
.sym
, false);
8508 /* Take out CLASS IS cases for separate treatment. */
8510 while (body
&& body
->block
)
8512 if (body
->block
->ext
.block
.case_list
->ts
.type
== BT_CLASS
)
8514 /* Add to class_is list. */
8515 if (class_is
== NULL
)
8517 class_is
= body
->block
;
8522 for (tail
= class_is
; tail
->block
; tail
= tail
->block
) ;
8523 tail
->block
= body
->block
;
8526 /* Remove from EXEC_SELECT list. */
8527 body
->block
= body
->block
->block
;
8540 /* Add a default case to hold the CLASS IS cases. */
8541 for (tail
= code
; tail
->block
; tail
= tail
->block
) ;
8542 tail
->block
= gfc_get_code (EXEC_SELECT_TYPE
);
8544 tail
->ext
.block
.case_list
= gfc_get_case ();
8545 tail
->ext
.block
.case_list
->ts
.type
= BT_UNKNOWN
;
8547 default_case
= tail
;
8550 /* More than one CLASS IS block? */
8551 if (class_is
->block
)
8555 /* Sort CLASS IS blocks by extension level. */
8559 for (c1
= &class_is
; (*c1
) && (*c1
)->block
; c1
= &((*c1
)->block
))
8562 /* F03:C817 (check for doubles). */
8563 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->hash_value
8564 == c2
->ext
.block
.case_list
->ts
.u
.derived
->hash_value
)
8566 gfc_error ("Double CLASS IS block in SELECT TYPE "
8568 &c2
->ext
.block
.case_list
->where
);
8571 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
8572 < c2
->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
)
8575 (*c1
)->block
= c2
->block
;
8585 /* Generate IF chain. */
8586 if_st
= gfc_get_code (EXEC_IF
);
8588 for (body
= class_is
; body
; body
= body
->block
)
8590 new_st
->block
= gfc_get_code (EXEC_IF
);
8591 new_st
= new_st
->block
;
8592 /* Set up IF condition: Call _gfortran_is_extension_of. */
8593 new_st
->expr1
= gfc_get_expr ();
8594 new_st
->expr1
->expr_type
= EXPR_FUNCTION
;
8595 new_st
->expr1
->ts
.type
= BT_LOGICAL
;
8596 new_st
->expr1
->ts
.kind
= 4;
8597 new_st
->expr1
->value
.function
.name
= gfc_get_string (PREFIX ("is_extension_of"));
8598 new_st
->expr1
->value
.function
.isym
= XCNEW (gfc_intrinsic_sym
);
8599 new_st
->expr1
->value
.function
.isym
->id
= GFC_ISYM_EXTENDS_TYPE_OF
;
8600 /* Set up arguments. */
8601 new_st
->expr1
->value
.function
.actual
= gfc_get_actual_arglist ();
8602 new_st
->expr1
->value
.function
.actual
->expr
= gfc_get_variable_expr (code
->expr1
->symtree
);
8603 new_st
->expr1
->value
.function
.actual
->expr
->where
= code
->loc
;
8604 gfc_add_vptr_component (new_st
->expr1
->value
.function
.actual
->expr
);
8605 vtab
= gfc_find_derived_vtab (body
->ext
.block
.case_list
->ts
.u
.derived
);
8606 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
8607 new_st
->expr1
->value
.function
.actual
->next
= gfc_get_actual_arglist ();
8608 new_st
->expr1
->value
.function
.actual
->next
->expr
= gfc_get_variable_expr (st
);
8609 new_st
->next
= body
->next
;
8611 if (default_case
->next
)
8613 new_st
->block
= gfc_get_code (EXEC_IF
);
8614 new_st
= new_st
->block
;
8615 new_st
->next
= default_case
->next
;
8618 /* Replace CLASS DEFAULT code by the IF chain. */
8619 default_case
->next
= if_st
;
8622 /* Resolve the internal code. This can not be done earlier because
8623 it requires that the sym->assoc of selectors is set already. */
8624 gfc_current_ns
= ns
;
8625 gfc_resolve_blocks (code
->block
, gfc_current_ns
);
8626 gfc_current_ns
= old_ns
;
8628 resolve_select (code
, true);
8632 /* Resolve a transfer statement. This is making sure that:
8633 -- a derived type being transferred has only non-pointer components
8634 -- a derived type being transferred doesn't have private components, unless
8635 it's being transferred from the module where the type was defined
8636 -- we're not trying to transfer a whole assumed size array. */
8639 resolve_transfer (gfc_code
*code
)
8648 while (exp
!= NULL
&& exp
->expr_type
== EXPR_OP
8649 && exp
->value
.op
.op
== INTRINSIC_PARENTHESES
)
8650 exp
= exp
->value
.op
.op1
;
8652 if (exp
&& exp
->expr_type
== EXPR_NULL
8655 gfc_error ("Invalid context for NULL () intrinsic at %L",
8660 if (exp
== NULL
|| (exp
->expr_type
!= EXPR_VARIABLE
8661 && exp
->expr_type
!= EXPR_FUNCTION
8662 && exp
->expr_type
!= EXPR_STRUCTURE
))
8665 /* If we are reading, the variable will be changed. Note that
8666 code->ext.dt may be NULL if the TRANSFER is related to
8667 an INQUIRE statement -- but in this case, we are not reading, either. */
8668 if (code
->ext
.dt
&& code
->ext
.dt
->dt_io_kind
->value
.iokind
== M_READ
8669 && !gfc_check_vardef_context (exp
, false, false, false,
8673 ts
= exp
->expr_type
== EXPR_STRUCTURE
? &exp
->ts
: &exp
->symtree
->n
.sym
->ts
;
8675 /* Go to actual component transferred. */
8676 for (ref
= exp
->ref
; ref
; ref
= ref
->next
)
8677 if (ref
->type
== REF_COMPONENT
)
8678 ts
= &ref
->u
.c
.component
->ts
;
8680 if (ts
->type
== BT_CLASS
)
8682 /* FIXME: Test for defined input/output. */
8683 gfc_error ("Data transfer element at %L cannot be polymorphic unless "
8684 "it is processed by a defined input/output procedure",
8689 if (ts
->type
== BT_DERIVED
)
8691 /* Check that transferred derived type doesn't contain POINTER
8693 if (ts
->u
.derived
->attr
.pointer_comp
)
8695 gfc_error ("Data transfer element at %L cannot have POINTER "
8696 "components unless it is processed by a defined "
8697 "input/output procedure", &code
->loc
);
8702 if (ts
->u
.derived
->attr
.proc_pointer_comp
)
8704 gfc_error ("Data transfer element at %L cannot have "
8705 "procedure pointer components", &code
->loc
);
8709 if (ts
->u
.derived
->attr
.alloc_comp
)
8711 gfc_error ("Data transfer element at %L cannot have ALLOCATABLE "
8712 "components unless it is processed by a defined "
8713 "input/output procedure", &code
->loc
);
8717 /* C_PTR and C_FUNPTR have private components which means they can not
8718 be printed. However, if -std=gnu and not -pedantic, allow
8719 the component to be printed to help debugging. */
8720 if (ts
->u
.derived
->ts
.f90_type
== BT_VOID
)
8722 if (!gfc_notify_std (GFC_STD_GNU
, "Data transfer element at %L "
8723 "cannot have PRIVATE components", &code
->loc
))
8726 else if (derived_inaccessible (ts
->u
.derived
))
8728 gfc_error ("Data transfer element at %L cannot have "
8729 "PRIVATE components",&code
->loc
);
8734 if (exp
->expr_type
== EXPR_STRUCTURE
)
8737 sym
= exp
->symtree
->n
.sym
;
8739 if (sym
->as
!= NULL
&& sym
->as
->type
== AS_ASSUMED_SIZE
&& exp
->ref
8740 && exp
->ref
->type
== REF_ARRAY
&& exp
->ref
->u
.ar
.type
== AR_FULL
)
8742 gfc_error ("Data transfer element at %L cannot be a full reference to "
8743 "an assumed-size array", &code
->loc
);
8749 /*********** Toplevel code resolution subroutines ***********/
8751 /* Find the set of labels that are reachable from this block. We also
8752 record the last statement in each block. */
8755 find_reachable_labels (gfc_code
*block
)
8762 cs_base
->reachable_labels
= bitmap_obstack_alloc (&labels_obstack
);
8764 /* Collect labels in this block. We don't keep those corresponding
8765 to END {IF|SELECT}, these are checked in resolve_branch by going
8766 up through the code_stack. */
8767 for (c
= block
; c
; c
= c
->next
)
8769 if (c
->here
&& c
->op
!= EXEC_END_NESTED_BLOCK
)
8770 bitmap_set_bit (cs_base
->reachable_labels
, c
->here
->value
);
8773 /* Merge with labels from parent block. */
8776 gcc_assert (cs_base
->prev
->reachable_labels
);
8777 bitmap_ior_into (cs_base
->reachable_labels
,
8778 cs_base
->prev
->reachable_labels
);
8784 resolve_lock_unlock_event (gfc_code
*code
)
8786 if (code
->expr1
->expr_type
== EXPR_FUNCTION
8787 && code
->expr1
->value
.function
.isym
8788 && code
->expr1
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
8789 remove_caf_get_intrinsic (code
->expr1
);
8791 if ((code
->op
== EXEC_LOCK
|| code
->op
== EXEC_UNLOCK
)
8792 && (code
->expr1
->ts
.type
!= BT_DERIVED
8793 || code
->expr1
->expr_type
!= EXPR_VARIABLE
8794 || code
->expr1
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
8795 || code
->expr1
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_LOCK_TYPE
8796 || code
->expr1
->rank
!= 0
8797 || (!gfc_is_coarray (code
->expr1
) &&
8798 !gfc_is_coindexed (code
->expr1
))))
8799 gfc_error ("Lock variable at %L must be a scalar of type LOCK_TYPE",
8800 &code
->expr1
->where
);
8801 else if ((code
->op
== EXEC_EVENT_POST
|| code
->op
== EXEC_EVENT_WAIT
)
8802 && (code
->expr1
->ts
.type
!= BT_DERIVED
8803 || code
->expr1
->expr_type
!= EXPR_VARIABLE
8804 || code
->expr1
->ts
.u
.derived
->from_intmod
8805 != INTMOD_ISO_FORTRAN_ENV
8806 || code
->expr1
->ts
.u
.derived
->intmod_sym_id
8807 != ISOFORTRAN_EVENT_TYPE
8808 || code
->expr1
->rank
!= 0))
8809 gfc_error ("Event variable at %L must be a scalar of type EVENT_TYPE",
8810 &code
->expr1
->where
);
8811 else if (code
->op
== EXEC_EVENT_POST
&& !gfc_is_coarray (code
->expr1
)
8812 && !gfc_is_coindexed (code
->expr1
))
8813 gfc_error ("Event variable argument at %L must be a coarray or coindexed",
8814 &code
->expr1
->where
);
8815 else if (code
->op
== EXEC_EVENT_WAIT
&& !gfc_is_coarray (code
->expr1
))
8816 gfc_error ("Event variable argument at %L must be a coarray but not "
8817 "coindexed", &code
->expr1
->where
);
8821 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
8822 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
8823 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
8824 &code
->expr2
->where
);
8827 && !gfc_check_vardef_context (code
->expr2
, false, false, false,
8828 _("STAT variable")))
8833 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
8834 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
8835 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
8836 &code
->expr3
->where
);
8839 && !gfc_check_vardef_context (code
->expr3
, false, false, false,
8840 _("ERRMSG variable")))
8843 /* Check for LOCK the ACQUIRED_LOCK. */
8844 if (code
->op
!= EXEC_EVENT_WAIT
&& code
->expr4
8845 && (code
->expr4
->ts
.type
!= BT_LOGICAL
|| code
->expr4
->rank
!= 0
8846 || code
->expr4
->expr_type
!= EXPR_VARIABLE
))
8847 gfc_error ("ACQUIRED_LOCK= argument at %L must be a scalar LOGICAL "
8848 "variable", &code
->expr4
->where
);
8850 if (code
->op
!= EXEC_EVENT_WAIT
&& code
->expr4
8851 && !gfc_check_vardef_context (code
->expr4
, false, false, false,
8852 _("ACQUIRED_LOCK variable")))
8855 /* Check for EVENT WAIT the UNTIL_COUNT. */
8856 if (code
->op
== EXEC_EVENT_WAIT
&& code
->expr4
8857 && (code
->expr4
->ts
.type
!= BT_INTEGER
|| code
->expr4
->rank
!= 0))
8858 gfc_error ("UNTIL_COUNT= argument at %L must be a scalar INTEGER "
8859 "expression", &code
->expr4
->where
);
8864 resolve_critical (gfc_code
*code
)
8866 gfc_symtree
*symtree
;
8867 gfc_symbol
*lock_type
;
8868 char name
[GFC_MAX_SYMBOL_LEN
];
8869 static int serial
= 0;
8871 if (flag_coarray
!= GFC_FCOARRAY_LIB
)
8874 symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
8875 GFC_PREFIX ("lock_type"));
8877 lock_type
= symtree
->n
.sym
;
8880 if (gfc_get_sym_tree (GFC_PREFIX ("lock_type"), gfc_current_ns
, &symtree
,
8883 lock_type
= symtree
->n
.sym
;
8884 lock_type
->attr
.flavor
= FL_DERIVED
;
8885 lock_type
->attr
.zero_comp
= 1;
8886 lock_type
->from_intmod
= INTMOD_ISO_FORTRAN_ENV
;
8887 lock_type
->intmod_sym_id
= ISOFORTRAN_LOCK_TYPE
;
8890 sprintf(name
, GFC_PREFIX ("lock_var") "%d",serial
++);
8891 if (gfc_get_sym_tree (name
, gfc_current_ns
, &symtree
, false) != 0)
8894 code
->resolved_sym
= symtree
->n
.sym
;
8895 symtree
->n
.sym
->attr
.flavor
= FL_VARIABLE
;
8896 symtree
->n
.sym
->attr
.referenced
= 1;
8897 symtree
->n
.sym
->attr
.artificial
= 1;
8898 symtree
->n
.sym
->attr
.codimension
= 1;
8899 symtree
->n
.sym
->ts
.type
= BT_DERIVED
;
8900 symtree
->n
.sym
->ts
.u
.derived
= lock_type
;
8901 symtree
->n
.sym
->as
= gfc_get_array_spec ();
8902 symtree
->n
.sym
->as
->corank
= 1;
8903 symtree
->n
.sym
->as
->type
= AS_EXPLICIT
;
8904 symtree
->n
.sym
->as
->cotype
= AS_EXPLICIT
;
8905 symtree
->n
.sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
,
8907 gfc_commit_symbols();
8912 resolve_sync (gfc_code
*code
)
8914 /* Check imageset. The * case matches expr1 == NULL. */
8917 if (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
> 1)
8918 gfc_error ("Imageset argument at %L must be a scalar or rank-1 "
8919 "INTEGER expression", &code
->expr1
->where
);
8920 if (code
->expr1
->expr_type
== EXPR_CONSTANT
&& code
->expr1
->rank
== 0
8921 && mpz_cmp_si (code
->expr1
->value
.integer
, 1) < 0)
8922 gfc_error ("Imageset argument at %L must between 1 and num_images()",
8923 &code
->expr1
->where
);
8924 else if (code
->expr1
->expr_type
== EXPR_ARRAY
8925 && gfc_simplify_expr (code
->expr1
, 0))
8927 gfc_constructor
*cons
;
8928 cons
= gfc_constructor_first (code
->expr1
->value
.constructor
);
8929 for (; cons
; cons
= gfc_constructor_next (cons
))
8930 if (cons
->expr
->expr_type
== EXPR_CONSTANT
8931 && mpz_cmp_si (cons
->expr
->value
.integer
, 1) < 0)
8932 gfc_error ("Imageset argument at %L must between 1 and "
8933 "num_images()", &cons
->expr
->where
);
8939 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
8940 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
8941 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
8942 &code
->expr2
->where
);
8946 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
8947 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
8948 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
8949 &code
->expr3
->where
);
8953 /* Given a branch to a label, see if the branch is conforming.
8954 The code node describes where the branch is located. */
8957 resolve_branch (gfc_st_label
*label
, gfc_code
*code
)
8964 /* Step one: is this a valid branching target? */
8966 if (label
->defined
== ST_LABEL_UNKNOWN
)
8968 gfc_error ("Label %d referenced at %L is never defined", label
->value
,
8973 if (label
->defined
!= ST_LABEL_TARGET
&& label
->defined
!= ST_LABEL_DO_TARGET
)
8975 gfc_error ("Statement at %L is not a valid branch target statement "
8976 "for the branch statement at %L", &label
->where
, &code
->loc
);
8980 /* Step two: make sure this branch is not a branch to itself ;-) */
8982 if (code
->here
== label
)
8985 "Branch at %L may result in an infinite loop", &code
->loc
);
8989 /* Step three: See if the label is in the same block as the
8990 branching statement. The hard work has been done by setting up
8991 the bitmap reachable_labels. */
8993 if (bitmap_bit_p (cs_base
->reachable_labels
, label
->value
))
8995 /* Check now whether there is a CRITICAL construct; if so, check
8996 whether the label is still visible outside of the CRITICAL block,
8997 which is invalid. */
8998 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
9000 if (stack
->current
->op
== EXEC_CRITICAL
9001 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
9002 gfc_error ("GOTO statement at %L leaves CRITICAL construct for "
9003 "label at %L", &code
->loc
, &label
->where
);
9004 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
9005 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
9006 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct "
9007 "for label at %L", &code
->loc
, &label
->where
);
9013 /* Step four: If we haven't found the label in the bitmap, it may
9014 still be the label of the END of the enclosing block, in which
9015 case we find it by going up the code_stack. */
9017 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
9019 if (stack
->current
->next
&& stack
->current
->next
->here
== label
)
9021 if (stack
->current
->op
== EXEC_CRITICAL
)
9023 /* Note: A label at END CRITICAL does not leave the CRITICAL
9024 construct as END CRITICAL is still part of it. */
9025 gfc_error ("GOTO statement at %L leaves CRITICAL construct for label"
9026 " at %L", &code
->loc
, &label
->where
);
9029 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
)
9031 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct for "
9032 "label at %L", &code
->loc
, &label
->where
);
9039 gcc_assert (stack
->current
->next
->op
== EXEC_END_NESTED_BLOCK
);
9043 /* The label is not in an enclosing block, so illegal. This was
9044 allowed in Fortran 66, so we allow it as extension. No
9045 further checks are necessary in this case. */
9046 gfc_notify_std (GFC_STD_LEGACY
, "Label at %L is not in the same block "
9047 "as the GOTO statement at %L", &label
->where
,
9053 /* Check whether EXPR1 has the same shape as EXPR2. */
9056 resolve_where_shape (gfc_expr
*expr1
, gfc_expr
*expr2
)
9058 mpz_t shape
[GFC_MAX_DIMENSIONS
];
9059 mpz_t shape2
[GFC_MAX_DIMENSIONS
];
9060 bool result
= false;
9063 /* Compare the rank. */
9064 if (expr1
->rank
!= expr2
->rank
)
9067 /* Compare the size of each dimension. */
9068 for (i
=0; i
<expr1
->rank
; i
++)
9070 if (!gfc_array_dimen_size (expr1
, i
, &shape
[i
]))
9073 if (!gfc_array_dimen_size (expr2
, i
, &shape2
[i
]))
9076 if (mpz_cmp (shape
[i
], shape2
[i
]))
9080 /* When either of the two expression is an assumed size array, we
9081 ignore the comparison of dimension sizes. */
9086 gfc_clear_shape (shape
, i
);
9087 gfc_clear_shape (shape2
, i
);
9092 /* Check whether a WHERE assignment target or a WHERE mask expression
9093 has the same shape as the outmost WHERE mask expression. */
9096 resolve_where (gfc_code
*code
, gfc_expr
*mask
)
9102 cblock
= code
->block
;
9104 /* Store the first WHERE mask-expr of the WHERE statement or construct.
9105 In case of nested WHERE, only the outmost one is stored. */
9106 if (mask
== NULL
) /* outmost WHERE */
9108 else /* inner WHERE */
9115 /* Check if the mask-expr has a consistent shape with the
9116 outmost WHERE mask-expr. */
9117 if (!resolve_where_shape (cblock
->expr1
, e
))
9118 gfc_error ("WHERE mask at %L has inconsistent shape",
9119 &cblock
->expr1
->where
);
9122 /* the assignment statement of a WHERE statement, or the first
9123 statement in where-body-construct of a WHERE construct */
9124 cnext
= cblock
->next
;
9129 /* WHERE assignment statement */
9132 /* Check shape consistent for WHERE assignment target. */
9133 if (e
&& !resolve_where_shape (cnext
->expr1
, e
))
9134 gfc_error ("WHERE assignment target at %L has "
9135 "inconsistent shape", &cnext
->expr1
->where
);
9139 case EXEC_ASSIGN_CALL
:
9140 resolve_call (cnext
);
9141 if (!cnext
->resolved_sym
->attr
.elemental
)
9142 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
9143 &cnext
->ext
.actual
->expr
->where
);
9146 /* WHERE or WHERE construct is part of a where-body-construct */
9148 resolve_where (cnext
, e
);
9152 gfc_error ("Unsupported statement inside WHERE at %L",
9155 /* the next statement within the same where-body-construct */
9156 cnext
= cnext
->next
;
9158 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
9159 cblock
= cblock
->block
;
9164 /* Resolve assignment in FORALL construct.
9165 NVAR is the number of FORALL index variables, and VAR_EXPR records the
9166 FORALL index variables. */
9169 gfc_resolve_assign_in_forall (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
9173 for (n
= 0; n
< nvar
; n
++)
9175 gfc_symbol
*forall_index
;
9177 forall_index
= var_expr
[n
]->symtree
->n
.sym
;
9179 /* Check whether the assignment target is one of the FORALL index
9181 if ((code
->expr1
->expr_type
== EXPR_VARIABLE
)
9182 && (code
->expr1
->symtree
->n
.sym
== forall_index
))
9183 gfc_error ("Assignment to a FORALL index variable at %L",
9184 &code
->expr1
->where
);
9187 /* If one of the FORALL index variables doesn't appear in the
9188 assignment variable, then there could be a many-to-one
9189 assignment. Emit a warning rather than an error because the
9190 mask could be resolving this problem. */
9191 if (!find_forall_index (code
->expr1
, forall_index
, 0))
9192 gfc_warning (0, "The FORALL with index %qs is not used on the "
9193 "left side of the assignment at %L and so might "
9194 "cause multiple assignment to this object",
9195 var_expr
[n
]->symtree
->name
, &code
->expr1
->where
);
9201 /* Resolve WHERE statement in FORALL construct. */
9204 gfc_resolve_where_code_in_forall (gfc_code
*code
, int nvar
,
9205 gfc_expr
**var_expr
)
9210 cblock
= code
->block
;
9213 /* the assignment statement of a WHERE statement, or the first
9214 statement in where-body-construct of a WHERE construct */
9215 cnext
= cblock
->next
;
9220 /* WHERE assignment statement */
9222 gfc_resolve_assign_in_forall (cnext
, nvar
, var_expr
);
9225 /* WHERE operator assignment statement */
9226 case EXEC_ASSIGN_CALL
:
9227 resolve_call (cnext
);
9228 if (!cnext
->resolved_sym
->attr
.elemental
)
9229 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
9230 &cnext
->ext
.actual
->expr
->where
);
9233 /* WHERE or WHERE construct is part of a where-body-construct */
9235 gfc_resolve_where_code_in_forall (cnext
, nvar
, var_expr
);
9239 gfc_error ("Unsupported statement inside WHERE at %L",
9242 /* the next statement within the same where-body-construct */
9243 cnext
= cnext
->next
;
9245 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
9246 cblock
= cblock
->block
;
9251 /* Traverse the FORALL body to check whether the following errors exist:
9252 1. For assignment, check if a many-to-one assignment happens.
9253 2. For WHERE statement, check the WHERE body to see if there is any
9254 many-to-one assignment. */
9257 gfc_resolve_forall_body (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
9261 c
= code
->block
->next
;
9267 case EXEC_POINTER_ASSIGN
:
9268 gfc_resolve_assign_in_forall (c
, nvar
, var_expr
);
9271 case EXEC_ASSIGN_CALL
:
9275 /* Because the gfc_resolve_blocks() will handle the nested FORALL,
9276 there is no need to handle it here. */
9280 gfc_resolve_where_code_in_forall(c
, nvar
, var_expr
);
9285 /* The next statement in the FORALL body. */
9291 /* Counts the number of iterators needed inside a forall construct, including
9292 nested forall constructs. This is used to allocate the needed memory
9293 in gfc_resolve_forall. */
9296 gfc_count_forall_iterators (gfc_code
*code
)
9298 int max_iters
, sub_iters
, current_iters
;
9299 gfc_forall_iterator
*fa
;
9301 gcc_assert(code
->op
== EXEC_FORALL
);
9305 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
9308 code
= code
->block
->next
;
9312 if (code
->op
== EXEC_FORALL
)
9314 sub_iters
= gfc_count_forall_iterators (code
);
9315 if (sub_iters
> max_iters
)
9316 max_iters
= sub_iters
;
9321 return current_iters
+ max_iters
;
9325 /* Given a FORALL construct, first resolve the FORALL iterator, then call
9326 gfc_resolve_forall_body to resolve the FORALL body. */
9329 gfc_resolve_forall (gfc_code
*code
, gfc_namespace
*ns
, int forall_save
)
9331 static gfc_expr
**var_expr
;
9332 static int total_var
= 0;
9333 static int nvar
= 0;
9335 gfc_forall_iterator
*fa
;
9340 /* Start to resolve a FORALL construct */
9341 if (forall_save
== 0)
9343 /* Count the total number of FORALL index in the nested FORALL
9344 construct in order to allocate the VAR_EXPR with proper size. */
9345 total_var
= gfc_count_forall_iterators (code
);
9347 /* Allocate VAR_EXPR with NUMBER_OF_FORALL_INDEX elements. */
9348 var_expr
= XCNEWVEC (gfc_expr
*, total_var
);
9351 /* The information about FORALL iterator, including FORALL index start, end
9352 and stride. The FORALL index can not appear in start, end or stride. */
9353 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
9355 /* Check if any outer FORALL index name is the same as the current
9357 for (i
= 0; i
< nvar
; i
++)
9359 if (fa
->var
->symtree
->n
.sym
== var_expr
[i
]->symtree
->n
.sym
)
9361 gfc_error ("An outer FORALL construct already has an index "
9362 "with this name %L", &fa
->var
->where
);
9366 /* Record the current FORALL index. */
9367 var_expr
[nvar
] = gfc_copy_expr (fa
->var
);
9371 /* No memory leak. */
9372 gcc_assert (nvar
<= total_var
);
9375 /* Resolve the FORALL body. */
9376 gfc_resolve_forall_body (code
, nvar
, var_expr
);
9378 /* May call gfc_resolve_forall to resolve the inner FORALL loop. */
9379 gfc_resolve_blocks (code
->block
, ns
);
9383 /* Free only the VAR_EXPRs allocated in this frame. */
9384 for (i
= nvar
; i
< tmp
; i
++)
9385 gfc_free_expr (var_expr
[i
]);
9389 /* We are in the outermost FORALL construct. */
9390 gcc_assert (forall_save
== 0);
9392 /* VAR_EXPR is not needed any more. */
9399 /* Resolve a BLOCK construct statement. */
9402 resolve_block_construct (gfc_code
* code
)
9404 /* Resolve the BLOCK's namespace. */
9405 gfc_resolve (code
->ext
.block
.ns
);
9407 /* For an ASSOCIATE block, the associations (and their targets) are already
9408 resolved during resolve_symbol. */
9412 /* Resolve lists of blocks found in IF, SELECT CASE, WHERE, FORALL, GOTO and
9416 gfc_resolve_blocks (gfc_code
*b
, gfc_namespace
*ns
)
9420 for (; b
; b
= b
->block
)
9422 t
= gfc_resolve_expr (b
->expr1
);
9423 if (!gfc_resolve_expr (b
->expr2
))
9429 if (t
&& b
->expr1
!= NULL
9430 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
!= 0))
9431 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
9438 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
== 0))
9439 gfc_error ("WHERE/ELSEWHERE clause at %L requires a LOGICAL array",
9444 resolve_branch (b
->label1
, b
);
9448 resolve_block_construct (b
);
9452 case EXEC_SELECT_TYPE
:
9456 case EXEC_DO_CONCURRENT
:
9464 case EXEC_OACC_PARALLEL_LOOP
:
9465 case EXEC_OACC_PARALLEL
:
9466 case EXEC_OACC_KERNELS_LOOP
:
9467 case EXEC_OACC_KERNELS
:
9468 case EXEC_OACC_DATA
:
9469 case EXEC_OACC_HOST_DATA
:
9470 case EXEC_OACC_LOOP
:
9471 case EXEC_OACC_UPDATE
:
9472 case EXEC_OACC_WAIT
:
9473 case EXEC_OACC_CACHE
:
9474 case EXEC_OACC_ENTER_DATA
:
9475 case EXEC_OACC_EXIT_DATA
:
9476 case EXEC_OACC_ATOMIC
:
9477 case EXEC_OACC_ROUTINE
:
9478 case EXEC_OMP_ATOMIC
:
9479 case EXEC_OMP_CRITICAL
:
9480 case EXEC_OMP_DISTRIBUTE
:
9481 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
9482 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
9483 case EXEC_OMP_DISTRIBUTE_SIMD
:
9485 case EXEC_OMP_DO_SIMD
:
9486 case EXEC_OMP_MASTER
:
9487 case EXEC_OMP_ORDERED
:
9488 case EXEC_OMP_PARALLEL
:
9489 case EXEC_OMP_PARALLEL_DO
:
9490 case EXEC_OMP_PARALLEL_DO_SIMD
:
9491 case EXEC_OMP_PARALLEL_SECTIONS
:
9492 case EXEC_OMP_PARALLEL_WORKSHARE
:
9493 case EXEC_OMP_SECTIONS
:
9495 case EXEC_OMP_SINGLE
:
9496 case EXEC_OMP_TARGET
:
9497 case EXEC_OMP_TARGET_DATA
:
9498 case EXEC_OMP_TARGET_TEAMS
:
9499 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
9500 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
9501 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
9502 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
9503 case EXEC_OMP_TARGET_UPDATE
:
9505 case EXEC_OMP_TASKGROUP
:
9506 case EXEC_OMP_TASKWAIT
:
9507 case EXEC_OMP_TASKYIELD
:
9508 case EXEC_OMP_TEAMS
:
9509 case EXEC_OMP_TEAMS_DISTRIBUTE
:
9510 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
9511 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
9512 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
9513 case EXEC_OMP_WORKSHARE
:
9517 gfc_internal_error ("gfc_resolve_blocks(): Bad block type");
9520 gfc_resolve_code (b
->next
, ns
);
9525 /* Does everything to resolve an ordinary assignment. Returns true
9526 if this is an interface assignment. */
9528 resolve_ordinary_assign (gfc_code
*code
, gfc_namespace
*ns
)
9537 symbol_attribute attr
;
9539 if (gfc_extend_assign (code
, ns
))
9543 if (code
->op
== EXEC_ASSIGN_CALL
)
9545 lhs
= code
->ext
.actual
->expr
;
9546 rhsptr
= &code
->ext
.actual
->next
->expr
;
9550 gfc_actual_arglist
* args
;
9551 gfc_typebound_proc
* tbp
;
9553 gcc_assert (code
->op
== EXEC_COMPCALL
);
9555 args
= code
->expr1
->value
.compcall
.actual
;
9557 rhsptr
= &args
->next
->expr
;
9559 tbp
= code
->expr1
->value
.compcall
.tbp
;
9560 gcc_assert (!tbp
->is_generic
);
9563 /* Make a temporary rhs when there is a default initializer
9564 and rhs is the same symbol as the lhs. */
9565 if ((*rhsptr
)->expr_type
== EXPR_VARIABLE
9566 && (*rhsptr
)->symtree
->n
.sym
->ts
.type
== BT_DERIVED
9567 && gfc_has_default_initializer ((*rhsptr
)->symtree
->n
.sym
->ts
.u
.derived
)
9568 && (lhs
->symtree
->n
.sym
== (*rhsptr
)->symtree
->n
.sym
))
9569 *rhsptr
= gfc_get_parentheses (*rhsptr
);
9578 && !gfc_notify_std (GFC_STD_GNU
, "BOZ literal at %L outside "
9579 "a DATA statement and outside INT/REAL/DBLE/CMPLX",
9583 /* Handle the case of a BOZ literal on the RHS. */
9584 if (rhs
->is_boz
&& lhs
->ts
.type
!= BT_INTEGER
)
9587 if (warn_surprising
)
9588 gfc_warning (OPT_Wsurprising
,
9589 "BOZ literal at %L is bitwise transferred "
9590 "non-integer symbol %qs", &code
->loc
,
9591 lhs
->symtree
->n
.sym
->name
);
9593 if (!gfc_convert_boz (rhs
, &lhs
->ts
))
9595 if ((rc
= gfc_range_check (rhs
)) != ARITH_OK
)
9597 if (rc
== ARITH_UNDERFLOW
)
9598 gfc_error ("Arithmetic underflow of bit-wise transferred BOZ at %L"
9599 ". This check can be disabled with the option "
9600 "%<-fno-range-check%>", &rhs
->where
);
9601 else if (rc
== ARITH_OVERFLOW
)
9602 gfc_error ("Arithmetic overflow of bit-wise transferred BOZ at %L"
9603 ". This check can be disabled with the option "
9604 "%<-fno-range-check%>", &rhs
->where
);
9605 else if (rc
== ARITH_NAN
)
9606 gfc_error ("Arithmetic NaN of bit-wise transferred BOZ at %L"
9607 ". This check can be disabled with the option "
9608 "%<-fno-range-check%>", &rhs
->where
);
9613 if (lhs
->ts
.type
== BT_CHARACTER
9614 && warn_character_truncation
)
9616 if (lhs
->ts
.u
.cl
!= NULL
9617 && lhs
->ts
.u
.cl
->length
!= NULL
9618 && lhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9619 llen
= mpz_get_si (lhs
->ts
.u
.cl
->length
->value
.integer
);
9621 if (rhs
->expr_type
== EXPR_CONSTANT
)
9622 rlen
= rhs
->value
.character
.length
;
9624 else if (rhs
->ts
.u
.cl
!= NULL
9625 && rhs
->ts
.u
.cl
->length
!= NULL
9626 && rhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9627 rlen
= mpz_get_si (rhs
->ts
.u
.cl
->length
->value
.integer
);
9629 if (rlen
&& llen
&& rlen
> llen
)
9630 gfc_warning_now (OPT_Wcharacter_truncation
,
9631 "CHARACTER expression will be truncated "
9632 "in assignment (%d/%d) at %L",
9633 llen
, rlen
, &code
->loc
);
9636 /* Ensure that a vector index expression for the lvalue is evaluated
9637 to a temporary if the lvalue symbol is referenced in it. */
9640 for (ref
= lhs
->ref
; ref
; ref
= ref
->next
)
9641 if (ref
->type
== REF_ARRAY
)
9643 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
9644 if (ref
->u
.ar
.dimen_type
[n
] == DIMEN_VECTOR
9645 && gfc_find_sym_in_expr (lhs
->symtree
->n
.sym
,
9646 ref
->u
.ar
.start
[n
]))
9648 = gfc_get_parentheses (ref
->u
.ar
.start
[n
]);
9652 if (gfc_pure (NULL
))
9654 if (lhs
->ts
.type
== BT_DERIVED
9655 && lhs
->expr_type
== EXPR_VARIABLE
9656 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9657 && rhs
->expr_type
== EXPR_VARIABLE
9658 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9659 || gfc_is_coindexed (rhs
)))
9662 if (gfc_is_coindexed (rhs
))
9663 gfc_error ("Coindexed expression at %L is assigned to "
9664 "a derived type variable with a POINTER "
9665 "component in a PURE procedure",
9668 gfc_error ("The impure variable at %L is assigned to "
9669 "a derived type variable with a POINTER "
9670 "component in a PURE procedure (12.6)",
9675 /* Fortran 2008, C1283. */
9676 if (gfc_is_coindexed (lhs
))
9678 gfc_error ("Assignment to coindexed variable at %L in a PURE "
9679 "procedure", &rhs
->where
);
9684 if (gfc_implicit_pure (NULL
))
9686 if (lhs
->expr_type
== EXPR_VARIABLE
9687 && lhs
->symtree
->n
.sym
!= gfc_current_ns
->proc_name
9688 && lhs
->symtree
->n
.sym
->ns
!= gfc_current_ns
)
9689 gfc_unset_implicit_pure (NULL
);
9691 if (lhs
->ts
.type
== BT_DERIVED
9692 && lhs
->expr_type
== EXPR_VARIABLE
9693 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9694 && rhs
->expr_type
== EXPR_VARIABLE
9695 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9696 || gfc_is_coindexed (rhs
)))
9697 gfc_unset_implicit_pure (NULL
);
9699 /* Fortran 2008, C1283. */
9700 if (gfc_is_coindexed (lhs
))
9701 gfc_unset_implicit_pure (NULL
);
9704 /* F2008, 7.2.1.2. */
9705 attr
= gfc_expr_attr (lhs
);
9706 if (lhs
->ts
.type
== BT_CLASS
&& attr
.allocatable
)
9708 if (attr
.codimension
)
9710 gfc_error ("Assignment to polymorphic coarray at %L is not "
9711 "permitted", &lhs
->where
);
9714 if (!gfc_notify_std (GFC_STD_F2008
, "Assignment to an allocatable "
9715 "polymorphic variable at %L", &lhs
->where
))
9717 if (!flag_realloc_lhs
)
9719 gfc_error ("Assignment to an allocatable polymorphic variable at %L "
9720 "requires %<-frealloc-lhs%>", &lhs
->where
);
9724 gfc_error ("Assignment to an allocatable polymorphic variable at %L "
9725 "is not yet supported", &lhs
->where
);
9728 else if (lhs
->ts
.type
== BT_CLASS
)
9730 gfc_error ("Nonallocatable variable must not be polymorphic in intrinsic "
9731 "assignment at %L - check that there is a matching specific "
9732 "subroutine for '=' operator", &lhs
->where
);
9736 bool lhs_coindexed
= gfc_is_coindexed (lhs
);
9738 /* F2008, Section 7.2.1.2. */
9739 if (lhs_coindexed
&& gfc_has_ultimate_allocatable (lhs
))
9741 gfc_error ("Coindexed variable must not have an allocatable ultimate "
9742 "component in assignment at %L", &lhs
->where
);
9746 gfc_check_assign (lhs
, rhs
, 1);
9748 /* Assign the 'data' of a class object to a derived type. */
9749 if (lhs
->ts
.type
== BT_DERIVED
9750 && rhs
->ts
.type
== BT_CLASS
)
9751 gfc_add_data_component (rhs
);
9753 /* Insert a GFC_ISYM_CAF_SEND intrinsic, when the LHS is a coindexed variable.
9754 Additionally, insert this code when the RHS is a CAF as we then use the
9755 GFC_ISYM_CAF_SEND intrinsic just to avoid a temporary; but do not do so if
9756 the LHS is (re)allocatable or has a vector subscript. If the LHS is a
9757 noncoindexed array and the RHS is a coindexed scalar, use the normal code
9759 if (flag_coarray
== GFC_FCOARRAY_LIB
9761 || (code
->expr2
->expr_type
== EXPR_FUNCTION
9762 && code
->expr2
->value
.function
.isym
9763 && code
->expr2
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
9764 && (code
->expr1
->rank
== 0 || code
->expr2
->rank
!= 0)
9765 && !gfc_expr_attr (rhs
).allocatable
9766 && !gfc_has_vector_subscript (rhs
))))
9768 if (code
->expr2
->expr_type
== EXPR_FUNCTION
9769 && code
->expr2
->value
.function
.isym
9770 && code
->expr2
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
9771 remove_caf_get_intrinsic (code
->expr2
);
9772 code
->op
= EXEC_CALL
;
9773 gfc_get_sym_tree (GFC_PREFIX ("caf_send"), ns
, &code
->symtree
, true);
9774 code
->resolved_sym
= code
->symtree
->n
.sym
;
9775 code
->resolved_sym
->attr
.flavor
= FL_PROCEDURE
;
9776 code
->resolved_sym
->attr
.intrinsic
= 1;
9777 code
->resolved_sym
->attr
.subroutine
= 1;
9778 code
->resolved_isym
= gfc_intrinsic_subroutine_by_id (GFC_ISYM_CAF_SEND
);
9779 gfc_commit_symbol (code
->resolved_sym
);
9780 code
->ext
.actual
= gfc_get_actual_arglist ();
9781 code
->ext
.actual
->expr
= lhs
;
9782 code
->ext
.actual
->next
= gfc_get_actual_arglist ();
9783 code
->ext
.actual
->next
->expr
= rhs
;
9792 /* Add a component reference onto an expression. */
9795 add_comp_ref (gfc_expr
*e
, gfc_component
*c
)
9800 ref
= &((*ref
)->next
);
9801 *ref
= gfc_get_ref ();
9802 (*ref
)->type
= REF_COMPONENT
;
9803 (*ref
)->u
.c
.sym
= e
->ts
.u
.derived
;
9804 (*ref
)->u
.c
.component
= c
;
9807 /* Add a full array ref, as necessary. */
9810 gfc_add_full_array_ref (e
, c
->as
);
9811 e
->rank
= c
->as
->rank
;
9816 /* Build an assignment. Keep the argument 'op' for future use, so that
9817 pointer assignments can be made. */
9820 build_assignment (gfc_exec_op op
, gfc_expr
*expr1
, gfc_expr
*expr2
,
9821 gfc_component
*comp1
, gfc_component
*comp2
, locus loc
)
9823 gfc_code
*this_code
;
9825 this_code
= gfc_get_code (op
);
9826 this_code
->next
= NULL
;
9827 this_code
->expr1
= gfc_copy_expr (expr1
);
9828 this_code
->expr2
= gfc_copy_expr (expr2
);
9829 this_code
->loc
= loc
;
9832 add_comp_ref (this_code
->expr1
, comp1
);
9833 add_comp_ref (this_code
->expr2
, comp2
);
9840 /* Makes a temporary variable expression based on the characteristics of
9841 a given variable expression. */
9844 get_temp_from_expr (gfc_expr
*e
, gfc_namespace
*ns
)
9846 static int serial
= 0;
9847 char name
[GFC_MAX_SYMBOL_LEN
];
9850 gfc_array_ref
*aref
;
9853 sprintf (name
, GFC_PREFIX("DA%d"), serial
++);
9854 gfc_get_sym_tree (name
, ns
, &tmp
, false);
9855 gfc_add_type (tmp
->n
.sym
, &e
->ts
, NULL
);
9861 /* Obtain the arrayspec for the temporary. */
9862 if (e
->rank
&& e
->expr_type
!= EXPR_ARRAY
9863 && e
->expr_type
!= EXPR_FUNCTION
9864 && e
->expr_type
!= EXPR_OP
)
9866 aref
= gfc_find_array_ref (e
);
9867 if (e
->expr_type
== EXPR_VARIABLE
9868 && e
->symtree
->n
.sym
->as
== aref
->as
)
9872 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
9873 if (ref
->type
== REF_COMPONENT
9874 && ref
->u
.c
.component
->as
== aref
->as
)
9882 /* Add the attributes and the arrayspec to the temporary. */
9883 tmp
->n
.sym
->attr
= gfc_expr_attr (e
);
9884 tmp
->n
.sym
->attr
.function
= 0;
9885 tmp
->n
.sym
->attr
.result
= 0;
9886 tmp
->n
.sym
->attr
.flavor
= FL_VARIABLE
;
9890 tmp
->n
.sym
->as
= gfc_copy_array_spec (as
);
9893 if (as
->type
== AS_DEFERRED
)
9894 tmp
->n
.sym
->attr
.allocatable
= 1;
9896 else if (e
->rank
&& (e
->expr_type
== EXPR_ARRAY
9897 || e
->expr_type
== EXPR_FUNCTION
9898 || e
->expr_type
== EXPR_OP
))
9900 tmp
->n
.sym
->as
= gfc_get_array_spec ();
9901 tmp
->n
.sym
->as
->type
= AS_DEFERRED
;
9902 tmp
->n
.sym
->as
->rank
= e
->rank
;
9903 tmp
->n
.sym
->attr
.allocatable
= 1;
9904 tmp
->n
.sym
->attr
.dimension
= 1;
9907 tmp
->n
.sym
->attr
.dimension
= 0;
9909 gfc_set_sym_referenced (tmp
->n
.sym
);
9910 gfc_commit_symbol (tmp
->n
.sym
);
9911 e
= gfc_lval_expr_from_sym (tmp
->n
.sym
);
9913 /* Should the lhs be a section, use its array ref for the
9914 temporary expression. */
9915 if (aref
&& aref
->type
!= AR_FULL
)
9917 gfc_free_ref_list (e
->ref
);
9918 e
->ref
= gfc_copy_ref (ref
);
9924 /* Add one line of code to the code chain, making sure that 'head' and
9925 'tail' are appropriately updated. */
9928 add_code_to_chain (gfc_code
**this_code
, gfc_code
**head
, gfc_code
**tail
)
9930 gcc_assert (this_code
);
9932 *head
= *tail
= *this_code
;
9934 *tail
= gfc_append_code (*tail
, *this_code
);
9939 /* Counts the potential number of part array references that would
9940 result from resolution of typebound defined assignments. */
9943 nonscalar_typebound_assign (gfc_symbol
*derived
, int depth
)
9946 int c_depth
= 0, t_depth
;
9948 for (c
= derived
->components
; c
; c
= c
->next
)
9950 if ((!gfc_bt_struct (c
->ts
.type
)
9952 || c
->attr
.allocatable
9953 || c
->attr
.proc_pointer_comp
9954 || c
->attr
.class_pointer
9955 || c
->attr
.proc_pointer
)
9956 && !c
->attr
.defined_assign_comp
)
9959 if (c
->as
&& c_depth
== 0)
9962 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
9963 t_depth
= nonscalar_typebound_assign (c
->ts
.u
.derived
,
9968 c_depth
= t_depth
> c_depth
? t_depth
: c_depth
;
9970 return depth
+ c_depth
;
9974 /* Implement 7.2.1.3 of the F08 standard:
9975 "An intrinsic assignment where the variable is of derived type is
9976 performed as if each component of the variable were assigned from the
9977 corresponding component of expr using pointer assignment (7.2.2) for
9978 each pointer component, defined assignment for each nonpointer
9979 nonallocatable component of a type that has a type-bound defined
9980 assignment consistent with the component, intrinsic assignment for
9981 each other nonpointer nonallocatable component, ..."
9983 The pointer assignments are taken care of by the intrinsic
9984 assignment of the structure itself. This function recursively adds
9985 defined assignments where required. The recursion is accomplished
9986 by calling gfc_resolve_code.
9988 When the lhs in a defined assignment has intent INOUT, we need a
9989 temporary for the lhs. In pseudo-code:
9991 ! Only call function lhs once.
9992 if (lhs is not a constant or an variable)
9995 ! Do the intrinsic assignment
9997 ! Now do the defined assignments
9998 do over components with typebound defined assignment [%cmp]
9999 #if one component's assignment procedure is INOUT
10001 #if expr2 non-variable
10007 t1%cmp {defined=} expr2%cmp
10013 expr1%cmp {defined=} expr2%cmp
10017 /* The temporary assignments have to be put on top of the additional
10018 code to avoid the result being changed by the intrinsic assignment.
10020 static int component_assignment_level
= 0;
10021 static gfc_code
*tmp_head
= NULL
, *tmp_tail
= NULL
;
10024 generate_component_assignments (gfc_code
**code
, gfc_namespace
*ns
)
10026 gfc_component
*comp1
, *comp2
;
10027 gfc_code
*this_code
= NULL
, *head
= NULL
, *tail
= NULL
;
10029 int error_count
, depth
;
10031 gfc_get_errors (NULL
, &error_count
);
10033 /* Filter out continuing processing after an error. */
10035 || (*code
)->expr1
->ts
.type
!= BT_DERIVED
10036 || (*code
)->expr2
->ts
.type
!= BT_DERIVED
)
10039 /* TODO: Handle more than one part array reference in assignments. */
10040 depth
= nonscalar_typebound_assign ((*code
)->expr1
->ts
.u
.derived
,
10041 (*code
)->expr1
->rank
? 1 : 0);
10044 gfc_warning (0, "TODO: type-bound defined assignment(s) at %L not "
10045 "done because multiple part array references would "
10046 "occur in intermediate expressions.", &(*code
)->loc
);
10050 component_assignment_level
++;
10052 /* Create a temporary so that functions get called only once. */
10053 if ((*code
)->expr2
->expr_type
!= EXPR_VARIABLE
10054 && (*code
)->expr2
->expr_type
!= EXPR_CONSTANT
)
10056 gfc_expr
*tmp_expr
;
10058 /* Assign the rhs to the temporary. */
10059 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
10060 this_code
= build_assignment (EXEC_ASSIGN
,
10061 tmp_expr
, (*code
)->expr2
,
10062 NULL
, NULL
, (*code
)->loc
);
10063 /* Add the code and substitute the rhs expression. */
10064 add_code_to_chain (&this_code
, &tmp_head
, &tmp_tail
);
10065 gfc_free_expr ((*code
)->expr2
);
10066 (*code
)->expr2
= tmp_expr
;
10069 /* Do the intrinsic assignment. This is not needed if the lhs is one
10070 of the temporaries generated here, since the intrinsic assignment
10071 to the final result already does this. */
10072 if ((*code
)->expr1
->symtree
->n
.sym
->name
[2] != '@')
10074 this_code
= build_assignment (EXEC_ASSIGN
,
10075 (*code
)->expr1
, (*code
)->expr2
,
10076 NULL
, NULL
, (*code
)->loc
);
10077 add_code_to_chain (&this_code
, &head
, &tail
);
10080 comp1
= (*code
)->expr1
->ts
.u
.derived
->components
;
10081 comp2
= (*code
)->expr2
->ts
.u
.derived
->components
;
10084 for (; comp1
; comp1
= comp1
->next
, comp2
= comp2
->next
)
10086 bool inout
= false;
10088 /* The intrinsic assignment does the right thing for pointers
10089 of all kinds and allocatable components. */
10090 if (!gfc_bt_struct (comp1
->ts
.type
)
10091 || comp1
->attr
.pointer
10092 || comp1
->attr
.allocatable
10093 || comp1
->attr
.proc_pointer_comp
10094 || comp1
->attr
.class_pointer
10095 || comp1
->attr
.proc_pointer
)
10098 /* Make an assigment for this component. */
10099 this_code
= build_assignment (EXEC_ASSIGN
,
10100 (*code
)->expr1
, (*code
)->expr2
,
10101 comp1
, comp2
, (*code
)->loc
);
10103 /* Convert the assignment if there is a defined assignment for
10104 this type. Otherwise, using the call from gfc_resolve_code,
10105 recurse into its components. */
10106 gfc_resolve_code (this_code
, ns
);
10108 if (this_code
->op
== EXEC_ASSIGN_CALL
)
10110 gfc_formal_arglist
*dummy_args
;
10112 /* Check that there is a typebound defined assignment. If not,
10113 then this must be a module defined assignment. We cannot
10114 use the defined_assign_comp attribute here because it must
10115 be this derived type that has the defined assignment and not
10117 if (!(comp1
->ts
.u
.derived
->f2k_derived
10118 && comp1
->ts
.u
.derived
->f2k_derived
10119 ->tb_op
[INTRINSIC_ASSIGN
]))
10121 gfc_free_statements (this_code
);
10126 /* If the first argument of the subroutine has intent INOUT
10127 a temporary must be generated and used instead. */
10128 rsym
= this_code
->resolved_sym
;
10129 dummy_args
= gfc_sym_get_dummy_args (rsym
);
10131 && dummy_args
->sym
->attr
.intent
== INTENT_INOUT
)
10133 gfc_code
*temp_code
;
10136 /* Build the temporary required for the assignment and put
10137 it at the head of the generated code. */
10140 t1
= get_temp_from_expr ((*code
)->expr1
, ns
);
10141 temp_code
= build_assignment (EXEC_ASSIGN
,
10142 t1
, (*code
)->expr1
,
10143 NULL
, NULL
, (*code
)->loc
);
10145 /* For allocatable LHS, check whether it is allocated. Note
10146 that allocatable components with defined assignment are
10147 not yet support. See PR 57696. */
10148 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
)
10152 gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
10153 block
= gfc_get_code (EXEC_IF
);
10154 block
->block
= gfc_get_code (EXEC_IF
);
10155 block
->block
->expr1
10156 = gfc_build_intrinsic_call (ns
,
10157 GFC_ISYM_ALLOCATED
, "allocated",
10158 (*code
)->loc
, 1, e
);
10159 block
->block
->next
= temp_code
;
10162 add_code_to_chain (&temp_code
, &tmp_head
, &tmp_tail
);
10165 /* Replace the first actual arg with the component of the
10167 gfc_free_expr (this_code
->ext
.actual
->expr
);
10168 this_code
->ext
.actual
->expr
= gfc_copy_expr (t1
);
10169 add_comp_ref (this_code
->ext
.actual
->expr
, comp1
);
10171 /* If the LHS variable is allocatable and wasn't allocated and
10172 the temporary is allocatable, pointer assign the address of
10173 the freshly allocated LHS to the temporary. */
10174 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
10175 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
10180 cond
= gfc_get_expr ();
10181 cond
->ts
.type
= BT_LOGICAL
;
10182 cond
->ts
.kind
= gfc_default_logical_kind
;
10183 cond
->expr_type
= EXPR_OP
;
10184 cond
->where
= (*code
)->loc
;
10185 cond
->value
.op
.op
= INTRINSIC_NOT
;
10186 cond
->value
.op
.op1
= gfc_build_intrinsic_call (ns
,
10187 GFC_ISYM_ALLOCATED
, "allocated",
10188 (*code
)->loc
, 1, gfc_copy_expr (t1
));
10189 block
= gfc_get_code (EXEC_IF
);
10190 block
->block
= gfc_get_code (EXEC_IF
);
10191 block
->block
->expr1
= cond
;
10192 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
10193 t1
, (*code
)->expr1
,
10194 NULL
, NULL
, (*code
)->loc
);
10195 add_code_to_chain (&block
, &head
, &tail
);
10199 else if (this_code
->op
== EXEC_ASSIGN
&& !this_code
->next
)
10201 /* Don't add intrinsic assignments since they are already
10202 effected by the intrinsic assignment of the structure. */
10203 gfc_free_statements (this_code
);
10208 add_code_to_chain (&this_code
, &head
, &tail
);
10212 /* Transfer the value to the final result. */
10213 this_code
= build_assignment (EXEC_ASSIGN
,
10214 (*code
)->expr1
, t1
,
10215 comp1
, comp2
, (*code
)->loc
);
10216 add_code_to_chain (&this_code
, &head
, &tail
);
10220 /* Put the temporary assignments at the top of the generated code. */
10221 if (tmp_head
&& component_assignment_level
== 1)
10223 gfc_append_code (tmp_head
, head
);
10225 tmp_head
= tmp_tail
= NULL
;
10228 // If we did a pointer assignment - thus, we need to ensure that the LHS is
10229 // not accidentally deallocated. Hence, nullify t1.
10230 if (t1
&& (*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
10231 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
10237 e
= gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
10238 cond
= gfc_build_intrinsic_call (ns
, GFC_ISYM_ASSOCIATED
, "associated",
10239 (*code
)->loc
, 2, gfc_copy_expr (t1
), e
);
10240 block
= gfc_get_code (EXEC_IF
);
10241 block
->block
= gfc_get_code (EXEC_IF
);
10242 block
->block
->expr1
= cond
;
10243 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
10244 t1
, gfc_get_null_expr (&(*code
)->loc
),
10245 NULL
, NULL
, (*code
)->loc
);
10246 gfc_append_code (tail
, block
);
10250 /* Now attach the remaining code chain to the input code. Step on
10251 to the end of the new code since resolution is complete. */
10252 gcc_assert ((*code
)->op
== EXEC_ASSIGN
);
10253 tail
->next
= (*code
)->next
;
10254 /* Overwrite 'code' because this would place the intrinsic assignment
10255 before the temporary for the lhs is created. */
10256 gfc_free_expr ((*code
)->expr1
);
10257 gfc_free_expr ((*code
)->expr2
);
10263 component_assignment_level
--;
10267 /* F2008: Pointer function assignments are of the form:
10268 ptr_fcn (args) = expr
10269 This function breaks these assignments into two statements:
10270 temporary_pointer => ptr_fcn(args)
10271 temporary_pointer = expr */
10274 resolve_ptr_fcn_assign (gfc_code
**code
, gfc_namespace
*ns
)
10276 gfc_expr
*tmp_ptr_expr
;
10277 gfc_code
*this_code
;
10278 gfc_component
*comp
;
10281 if ((*code
)->expr1
->expr_type
!= EXPR_FUNCTION
)
10284 /* Even if standard does not support this feature, continue to build
10285 the two statements to avoid upsetting frontend_passes.c. */
10286 gfc_notify_std (GFC_STD_F2008
, "Pointer procedure assignment at "
10287 "%L", &(*code
)->loc
);
10289 comp
= gfc_get_proc_ptr_comp ((*code
)->expr1
);
10292 s
= comp
->ts
.interface
;
10294 s
= (*code
)->expr1
->symtree
->n
.sym
;
10296 if (s
== NULL
|| !s
->result
->attr
.pointer
)
10298 gfc_error ("The function result on the lhs of the assignment at "
10299 "%L must have the pointer attribute.",
10300 &(*code
)->expr1
->where
);
10301 (*code
)->op
= EXEC_NOP
;
10305 tmp_ptr_expr
= get_temp_from_expr ((*code
)->expr2
, ns
);
10307 /* get_temp_from_expression is set up for ordinary assignments. To that
10308 end, where array bounds are not known, arrays are made allocatable.
10309 Change the temporary to a pointer here. */
10310 tmp_ptr_expr
->symtree
->n
.sym
->attr
.pointer
= 1;
10311 tmp_ptr_expr
->symtree
->n
.sym
->attr
.allocatable
= 0;
10312 tmp_ptr_expr
->where
= (*code
)->loc
;
10314 this_code
= build_assignment (EXEC_ASSIGN
,
10315 tmp_ptr_expr
, (*code
)->expr2
,
10316 NULL
, NULL
, (*code
)->loc
);
10317 this_code
->next
= (*code
)->next
;
10318 (*code
)->next
= this_code
;
10319 (*code
)->op
= EXEC_POINTER_ASSIGN
;
10320 (*code
)->expr2
= (*code
)->expr1
;
10321 (*code
)->expr1
= tmp_ptr_expr
;
10327 /* Deferred character length assignments from an operator expression
10328 require a temporary because the character length of the lhs can
10329 change in the course of the assignment. */
10332 deferred_op_assign (gfc_code
**code
, gfc_namespace
*ns
)
10334 gfc_expr
*tmp_expr
;
10335 gfc_code
*this_code
;
10337 if (!((*code
)->expr1
->ts
.type
== BT_CHARACTER
10338 && (*code
)->expr1
->ts
.deferred
&& (*code
)->expr1
->rank
10339 && (*code
)->expr2
->expr_type
== EXPR_OP
))
10342 if (!gfc_check_dependency ((*code
)->expr1
, (*code
)->expr2
, 1))
10345 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
10346 tmp_expr
->where
= (*code
)->loc
;
10348 /* A new charlen is required to ensure that the variable string
10349 length is different to that of the original lhs. */
10350 tmp_expr
->ts
.u
.cl
= gfc_get_charlen();
10351 tmp_expr
->symtree
->n
.sym
->ts
.u
.cl
= tmp_expr
->ts
.u
.cl
;
10352 tmp_expr
->ts
.u
.cl
->next
= (*code
)->expr2
->ts
.u
.cl
->next
;
10353 (*code
)->expr2
->ts
.u
.cl
->next
= tmp_expr
->ts
.u
.cl
;
10355 tmp_expr
->symtree
->n
.sym
->ts
.deferred
= 1;
10357 this_code
= build_assignment (EXEC_ASSIGN
,
10359 gfc_copy_expr (tmp_expr
),
10360 NULL
, NULL
, (*code
)->loc
);
10362 (*code
)->expr1
= tmp_expr
;
10364 this_code
->next
= (*code
)->next
;
10365 (*code
)->next
= this_code
;
10371 /* Given a block of code, recursively resolve everything pointed to by this
10375 gfc_resolve_code (gfc_code
*code
, gfc_namespace
*ns
)
10377 int omp_workshare_save
;
10378 int forall_save
, do_concurrent_save
;
10382 frame
.prev
= cs_base
;
10386 find_reachable_labels (code
);
10388 for (; code
; code
= code
->next
)
10390 frame
.current
= code
;
10391 forall_save
= forall_flag
;
10392 do_concurrent_save
= gfc_do_concurrent_flag
;
10394 if (code
->op
== EXEC_FORALL
)
10397 gfc_resolve_forall (code
, ns
, forall_save
);
10400 else if (code
->block
)
10402 omp_workshare_save
= -1;
10405 case EXEC_OACC_PARALLEL_LOOP
:
10406 case EXEC_OACC_PARALLEL
:
10407 case EXEC_OACC_KERNELS_LOOP
:
10408 case EXEC_OACC_KERNELS
:
10409 case EXEC_OACC_DATA
:
10410 case EXEC_OACC_HOST_DATA
:
10411 case EXEC_OACC_LOOP
:
10412 gfc_resolve_oacc_blocks (code
, ns
);
10414 case EXEC_OMP_PARALLEL_WORKSHARE
:
10415 omp_workshare_save
= omp_workshare_flag
;
10416 omp_workshare_flag
= 1;
10417 gfc_resolve_omp_parallel_blocks (code
, ns
);
10419 case EXEC_OMP_PARALLEL
:
10420 case EXEC_OMP_PARALLEL_DO
:
10421 case EXEC_OMP_PARALLEL_DO_SIMD
:
10422 case EXEC_OMP_PARALLEL_SECTIONS
:
10423 case EXEC_OMP_TARGET_TEAMS
:
10424 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
10425 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10426 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10427 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
10428 case EXEC_OMP_TASK
:
10429 case EXEC_OMP_TEAMS
:
10430 case EXEC_OMP_TEAMS_DISTRIBUTE
:
10431 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10432 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10433 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
10434 omp_workshare_save
= omp_workshare_flag
;
10435 omp_workshare_flag
= 0;
10436 gfc_resolve_omp_parallel_blocks (code
, ns
);
10438 case EXEC_OMP_DISTRIBUTE
:
10439 case EXEC_OMP_DISTRIBUTE_SIMD
:
10441 case EXEC_OMP_DO_SIMD
:
10442 case EXEC_OMP_SIMD
:
10443 gfc_resolve_omp_do_blocks (code
, ns
);
10445 case EXEC_SELECT_TYPE
:
10446 /* Blocks are handled in resolve_select_type because we have
10447 to transform the SELECT TYPE into ASSOCIATE first. */
10449 case EXEC_DO_CONCURRENT
:
10450 gfc_do_concurrent_flag
= 1;
10451 gfc_resolve_blocks (code
->block
, ns
);
10452 gfc_do_concurrent_flag
= 2;
10454 case EXEC_OMP_WORKSHARE
:
10455 omp_workshare_save
= omp_workshare_flag
;
10456 omp_workshare_flag
= 1;
10459 gfc_resolve_blocks (code
->block
, ns
);
10463 if (omp_workshare_save
!= -1)
10464 omp_workshare_flag
= omp_workshare_save
;
10468 if (code
->op
!= EXEC_COMPCALL
&& code
->op
!= EXEC_CALL_PPC
)
10469 t
= gfc_resolve_expr (code
->expr1
);
10470 forall_flag
= forall_save
;
10471 gfc_do_concurrent_flag
= do_concurrent_save
;
10473 if (!gfc_resolve_expr (code
->expr2
))
10476 if (code
->op
== EXEC_ALLOCATE
10477 && !gfc_resolve_expr (code
->expr3
))
10483 case EXEC_END_BLOCK
:
10484 case EXEC_END_NESTED_BLOCK
:
10488 case EXEC_ERROR_STOP
:
10490 case EXEC_CONTINUE
:
10492 case EXEC_ASSIGN_CALL
:
10495 case EXEC_CRITICAL
:
10496 resolve_critical (code
);
10499 case EXEC_SYNC_ALL
:
10500 case EXEC_SYNC_IMAGES
:
10501 case EXEC_SYNC_MEMORY
:
10502 resolve_sync (code
);
10507 case EXEC_EVENT_POST
:
10508 case EXEC_EVENT_WAIT
:
10509 resolve_lock_unlock_event (code
);
10513 /* Keep track of which entry we are up to. */
10514 current_entry_id
= code
->ext
.entry
->id
;
10518 resolve_where (code
, NULL
);
10522 if (code
->expr1
!= NULL
)
10524 if (code
->expr1
->ts
.type
!= BT_INTEGER
)
10525 gfc_error ("ASSIGNED GOTO statement at %L requires an "
10526 "INTEGER variable", &code
->expr1
->where
);
10527 else if (code
->expr1
->symtree
->n
.sym
->attr
.assign
!= 1)
10528 gfc_error ("Variable %qs has not been assigned a target "
10529 "label at %L", code
->expr1
->symtree
->n
.sym
->name
,
10530 &code
->expr1
->where
);
10533 resolve_branch (code
->label1
, code
);
10537 if (code
->expr1
!= NULL
10538 && (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
))
10539 gfc_error ("Alternate RETURN statement at %L requires a SCALAR-"
10540 "INTEGER return specifier", &code
->expr1
->where
);
10543 case EXEC_INIT_ASSIGN
:
10544 case EXEC_END_PROCEDURE
:
10551 /* Remove a GFC_ISYM_CAF_GET inserted for a coindexed variable on
10553 if (code
->expr1
->expr_type
== EXPR_FUNCTION
10554 && code
->expr1
->value
.function
.isym
10555 && code
->expr1
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
10556 remove_caf_get_intrinsic (code
->expr1
);
10558 /* If this is a pointer function in an lvalue variable context,
10559 the new code will have to be resolved afresh. This is also the
10560 case with an error, where the code is transformed into NOP to
10561 prevent ICEs downstream. */
10562 if (resolve_ptr_fcn_assign (&code
, ns
)
10563 || code
->op
== EXEC_NOP
)
10566 if (!gfc_check_vardef_context (code
->expr1
, false, false, false,
10570 if (resolve_ordinary_assign (code
, ns
))
10572 if (code
->op
== EXEC_COMPCALL
)
10578 /* Check for dependencies in deferred character length array
10579 assignments and generate a temporary, if necessary. */
10580 if (code
->op
== EXEC_ASSIGN
&& deferred_op_assign (&code
, ns
))
10583 /* F03 7.4.1.3 for non-allocatable, non-pointer components. */
10584 if (code
->op
!= EXEC_CALL
&& code
->expr1
->ts
.type
== BT_DERIVED
10585 && code
->expr1
->ts
.u
.derived
10586 && code
->expr1
->ts
.u
.derived
->attr
.defined_assign_comp
)
10587 generate_component_assignments (&code
, ns
);
10591 case EXEC_LABEL_ASSIGN
:
10592 if (code
->label1
->defined
== ST_LABEL_UNKNOWN
)
10593 gfc_error ("Label %d referenced at %L is never defined",
10594 code
->label1
->value
, &code
->label1
->where
);
10596 && (code
->expr1
->expr_type
!= EXPR_VARIABLE
10597 || code
->expr1
->symtree
->n
.sym
->ts
.type
!= BT_INTEGER
10598 || code
->expr1
->symtree
->n
.sym
->ts
.kind
10599 != gfc_default_integer_kind
10600 || code
->expr1
->symtree
->n
.sym
->as
!= NULL
))
10601 gfc_error ("ASSIGN statement at %L requires a scalar "
10602 "default INTEGER variable", &code
->expr1
->where
);
10605 case EXEC_POINTER_ASSIGN
:
10612 /* This is both a variable definition and pointer assignment
10613 context, so check both of them. For rank remapping, a final
10614 array ref may be present on the LHS and fool gfc_expr_attr
10615 used in gfc_check_vardef_context. Remove it. */
10616 e
= remove_last_array_ref (code
->expr1
);
10617 t
= gfc_check_vardef_context (e
, true, false, false,
10618 _("pointer assignment"));
10620 t
= gfc_check_vardef_context (e
, false, false, false,
10621 _("pointer assignment"));
10626 gfc_check_pointer_assign (code
->expr1
, code
->expr2
);
10630 case EXEC_ARITHMETIC_IF
:
10632 gfc_expr
*e
= code
->expr1
;
10634 gfc_resolve_expr (e
);
10635 if (e
->expr_type
== EXPR_NULL
)
10636 gfc_error ("Invalid NULL at %L", &e
->where
);
10638 if (t
&& (e
->rank
> 0
10639 || !(e
->ts
.type
== BT_REAL
|| e
->ts
.type
== BT_INTEGER
)))
10640 gfc_error ("Arithmetic IF statement at %L requires a scalar "
10641 "REAL or INTEGER expression", &e
->where
);
10643 resolve_branch (code
->label1
, code
);
10644 resolve_branch (code
->label2
, code
);
10645 resolve_branch (code
->label3
, code
);
10650 if (t
&& code
->expr1
!= NULL
10651 && (code
->expr1
->ts
.type
!= BT_LOGICAL
10652 || code
->expr1
->rank
!= 0))
10653 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
10654 &code
->expr1
->where
);
10659 resolve_call (code
);
10662 case EXEC_COMPCALL
:
10664 resolve_typebound_subroutine (code
);
10667 case EXEC_CALL_PPC
:
10668 resolve_ppc_call (code
);
10672 /* Select is complicated. Also, a SELECT construct could be
10673 a transformed computed GOTO. */
10674 resolve_select (code
, false);
10677 case EXEC_SELECT_TYPE
:
10678 resolve_select_type (code
, ns
);
10682 resolve_block_construct (code
);
10686 if (code
->ext
.iterator
!= NULL
)
10688 gfc_iterator
*iter
= code
->ext
.iterator
;
10689 if (gfc_resolve_iterator (iter
, true, false))
10690 gfc_resolve_do_iterator (code
, iter
->var
->symtree
->n
.sym
);
10694 case EXEC_DO_WHILE
:
10695 if (code
->expr1
== NULL
)
10696 gfc_internal_error ("gfc_resolve_code(): No expression on "
10699 && (code
->expr1
->rank
!= 0
10700 || code
->expr1
->ts
.type
!= BT_LOGICAL
))
10701 gfc_error ("Exit condition of DO WHILE loop at %L must be "
10702 "a scalar LOGICAL expression", &code
->expr1
->where
);
10705 case EXEC_ALLOCATE
:
10707 resolve_allocate_deallocate (code
, "ALLOCATE");
10711 case EXEC_DEALLOCATE
:
10713 resolve_allocate_deallocate (code
, "DEALLOCATE");
10718 if (!gfc_resolve_open (code
->ext
.open
))
10721 resolve_branch (code
->ext
.open
->err
, code
);
10725 if (!gfc_resolve_close (code
->ext
.close
))
10728 resolve_branch (code
->ext
.close
->err
, code
);
10731 case EXEC_BACKSPACE
:
10735 if (!gfc_resolve_filepos (code
->ext
.filepos
))
10738 resolve_branch (code
->ext
.filepos
->err
, code
);
10742 if (!gfc_resolve_inquire (code
->ext
.inquire
))
10745 resolve_branch (code
->ext
.inquire
->err
, code
);
10748 case EXEC_IOLENGTH
:
10749 gcc_assert (code
->ext
.inquire
!= NULL
);
10750 if (!gfc_resolve_inquire (code
->ext
.inquire
))
10753 resolve_branch (code
->ext
.inquire
->err
, code
);
10757 if (!gfc_resolve_wait (code
->ext
.wait
))
10760 resolve_branch (code
->ext
.wait
->err
, code
);
10761 resolve_branch (code
->ext
.wait
->end
, code
);
10762 resolve_branch (code
->ext
.wait
->eor
, code
);
10767 if (!gfc_resolve_dt (code
->ext
.dt
, &code
->loc
))
10770 resolve_branch (code
->ext
.dt
->err
, code
);
10771 resolve_branch (code
->ext
.dt
->end
, code
);
10772 resolve_branch (code
->ext
.dt
->eor
, code
);
10775 case EXEC_TRANSFER
:
10776 resolve_transfer (code
);
10779 case EXEC_DO_CONCURRENT
:
10781 resolve_forall_iterators (code
->ext
.forall_iterator
);
10783 if (code
->expr1
!= NULL
10784 && (code
->expr1
->ts
.type
!= BT_LOGICAL
|| code
->expr1
->rank
))
10785 gfc_error ("FORALL mask clause at %L requires a scalar LOGICAL "
10786 "expression", &code
->expr1
->where
);
10789 case EXEC_OACC_PARALLEL_LOOP
:
10790 case EXEC_OACC_PARALLEL
:
10791 case EXEC_OACC_KERNELS_LOOP
:
10792 case EXEC_OACC_KERNELS
:
10793 case EXEC_OACC_DATA
:
10794 case EXEC_OACC_HOST_DATA
:
10795 case EXEC_OACC_LOOP
:
10796 case EXEC_OACC_UPDATE
:
10797 case EXEC_OACC_WAIT
:
10798 case EXEC_OACC_CACHE
:
10799 case EXEC_OACC_ENTER_DATA
:
10800 case EXEC_OACC_EXIT_DATA
:
10801 case EXEC_OACC_ATOMIC
:
10802 case EXEC_OACC_DECLARE
:
10803 gfc_resolve_oacc_directive (code
, ns
);
10806 case EXEC_OMP_ATOMIC
:
10807 case EXEC_OMP_BARRIER
:
10808 case EXEC_OMP_CANCEL
:
10809 case EXEC_OMP_CANCELLATION_POINT
:
10810 case EXEC_OMP_CRITICAL
:
10811 case EXEC_OMP_FLUSH
:
10812 case EXEC_OMP_DISTRIBUTE
:
10813 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
10814 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
10815 case EXEC_OMP_DISTRIBUTE_SIMD
:
10817 case EXEC_OMP_DO_SIMD
:
10818 case EXEC_OMP_MASTER
:
10819 case EXEC_OMP_ORDERED
:
10820 case EXEC_OMP_SECTIONS
:
10821 case EXEC_OMP_SIMD
:
10822 case EXEC_OMP_SINGLE
:
10823 case EXEC_OMP_TARGET
:
10824 case EXEC_OMP_TARGET_DATA
:
10825 case EXEC_OMP_TARGET_TEAMS
:
10826 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
10827 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10828 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10829 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
10830 case EXEC_OMP_TARGET_UPDATE
:
10831 case EXEC_OMP_TASK
:
10832 case EXEC_OMP_TASKGROUP
:
10833 case EXEC_OMP_TASKWAIT
:
10834 case EXEC_OMP_TASKYIELD
:
10835 case EXEC_OMP_TEAMS
:
10836 case EXEC_OMP_TEAMS_DISTRIBUTE
:
10837 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10838 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10839 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
10840 case EXEC_OMP_WORKSHARE
:
10841 gfc_resolve_omp_directive (code
, ns
);
10844 case EXEC_OMP_PARALLEL
:
10845 case EXEC_OMP_PARALLEL_DO
:
10846 case EXEC_OMP_PARALLEL_DO_SIMD
:
10847 case EXEC_OMP_PARALLEL_SECTIONS
:
10848 case EXEC_OMP_PARALLEL_WORKSHARE
:
10849 omp_workshare_save
= omp_workshare_flag
;
10850 omp_workshare_flag
= 0;
10851 gfc_resolve_omp_directive (code
, ns
);
10852 omp_workshare_flag
= omp_workshare_save
;
10856 gfc_internal_error ("gfc_resolve_code(): Bad statement code");
10860 cs_base
= frame
.prev
;
10864 /* Resolve initial values and make sure they are compatible with
10868 resolve_values (gfc_symbol
*sym
)
10872 if (sym
->value
== NULL
)
10875 if (sym
->value
->expr_type
== EXPR_STRUCTURE
)
10876 t
= resolve_structure_cons (sym
->value
, 1);
10878 t
= gfc_resolve_expr (sym
->value
);
10883 gfc_check_assign_symbol (sym
, NULL
, sym
->value
);
10887 /* Verify any BIND(C) derived types in the namespace so we can report errors
10888 for them once, rather than for each variable declared of that type. */
10891 resolve_bind_c_derived_types (gfc_symbol
*derived_sym
)
10893 if (derived_sym
!= NULL
&& derived_sym
->attr
.flavor
== FL_DERIVED
10894 && derived_sym
->attr
.is_bind_c
== 1)
10895 verify_bind_c_derived_type (derived_sym
);
10901 /* Verify that any binding labels used in a given namespace do not collide
10902 with the names or binding labels of any global symbols. Multiple INTERFACE
10903 for the same procedure are permitted. */
10906 gfc_verify_binding_labels (gfc_symbol
*sym
)
10909 const char *module
;
10911 if (!sym
|| !sym
->attr
.is_bind_c
|| sym
->attr
.is_iso_c
10912 || sym
->attr
.flavor
== FL_DERIVED
|| !sym
->binding_label
)
10915 gsym
= gfc_find_gsymbol (gfc_gsym_root
, sym
->binding_label
);
10918 module
= sym
->module
;
10919 else if (sym
->ns
&& sym
->ns
->proc_name
10920 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
10921 module
= sym
->ns
->proc_name
->name
;
10922 else if (sym
->ns
&& sym
->ns
->parent
10923 && sym
->ns
&& sym
->ns
->parent
->proc_name
10924 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
10925 module
= sym
->ns
->parent
->proc_name
->name
;
10931 && (gsym
->type
== GSYM_FUNCTION
|| gsym
->type
== GSYM_SUBROUTINE
)))
10934 gsym
= gfc_get_gsymbol (sym
->binding_label
);
10935 gsym
->where
= sym
->declared_at
;
10936 gsym
->sym_name
= sym
->name
;
10937 gsym
->binding_label
= sym
->binding_label
;
10938 gsym
->ns
= sym
->ns
;
10939 gsym
->mod_name
= module
;
10940 if (sym
->attr
.function
)
10941 gsym
->type
= GSYM_FUNCTION
;
10942 else if (sym
->attr
.subroutine
)
10943 gsym
->type
= GSYM_SUBROUTINE
;
10944 /* Mark as variable/procedure as defined, unless its an INTERFACE. */
10945 gsym
->defined
= sym
->attr
.if_source
!= IFSRC_IFBODY
;
10949 if (sym
->attr
.flavor
== FL_VARIABLE
&& gsym
->type
!= GSYM_UNKNOWN
)
10951 gfc_error ("Variable %s with binding label %s at %L uses the same global "
10952 "identifier as entity at %L", sym
->name
,
10953 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
10954 /* Clear the binding label to prevent checking multiple times. */
10955 sym
->binding_label
= NULL
;
10958 else if (sym
->attr
.flavor
== FL_VARIABLE
&& module
10959 && (strcmp (module
, gsym
->mod_name
) != 0
10960 || strcmp (sym
->name
, gsym
->sym_name
) != 0))
10962 /* This can only happen if the variable is defined in a module - if it
10963 isn't the same module, reject it. */
10964 gfc_error ("Variable %s from module %s with binding label %s at %L uses "
10965 "the same global identifier as entity at %L from module %s",
10966 sym
->name
, module
, sym
->binding_label
,
10967 &sym
->declared_at
, &gsym
->where
, gsym
->mod_name
);
10968 sym
->binding_label
= NULL
;
10970 else if ((sym
->attr
.function
|| sym
->attr
.subroutine
)
10971 && ((gsym
->type
!= GSYM_SUBROUTINE
&& gsym
->type
!= GSYM_FUNCTION
)
10972 || (gsym
->defined
&& sym
->attr
.if_source
!= IFSRC_IFBODY
))
10973 && sym
!= gsym
->ns
->proc_name
10974 && (module
!= gsym
->mod_name
10975 || strcmp (gsym
->sym_name
, sym
->name
) != 0
10976 || (module
&& strcmp (module
, gsym
->mod_name
) != 0)))
10978 /* Print an error if the procedure is defined multiple times; we have to
10979 exclude references to the same procedure via module association or
10980 multiple checks for the same procedure. */
10981 gfc_error ("Procedure %s with binding label %s at %L uses the same "
10982 "global identifier as entity at %L", sym
->name
,
10983 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
10984 sym
->binding_label
= NULL
;
10989 /* Resolve an index expression. */
10992 resolve_index_expr (gfc_expr
*e
)
10994 if (!gfc_resolve_expr (e
))
10997 if (!gfc_simplify_expr (e
, 0))
11000 if (!gfc_specification_expr (e
))
11007 /* Resolve a charlen structure. */
11010 resolve_charlen (gfc_charlen
*cl
)
11013 bool saved_specification_expr
;
11019 saved_specification_expr
= specification_expr
;
11020 specification_expr
= true;
11022 if (cl
->length_from_typespec
)
11024 if (!gfc_resolve_expr (cl
->length
))
11026 specification_expr
= saved_specification_expr
;
11030 if (!gfc_simplify_expr (cl
->length
, 0))
11032 specification_expr
= saved_specification_expr
;
11039 if (!resolve_index_expr (cl
->length
))
11041 specification_expr
= saved_specification_expr
;
11046 /* F2008, 4.4.3.2: If the character length parameter value evaluates to
11047 a negative value, the length of character entities declared is zero. */
11048 if (cl
->length
&& !gfc_extract_int (cl
->length
, &i
) && i
< 0)
11049 gfc_replace_expr (cl
->length
,
11050 gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 0));
11052 /* Check that the character length is not too large. */
11053 k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
11054 if (cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
11055 && cl
->length
->ts
.type
== BT_INTEGER
11056 && mpz_cmp (cl
->length
->value
.integer
, gfc_integer_kinds
[k
].huge
) > 0)
11058 gfc_error ("String length at %L is too large", &cl
->length
->where
);
11059 specification_expr
= saved_specification_expr
;
11063 specification_expr
= saved_specification_expr
;
11068 /* Test for non-constant shape arrays. */
11071 is_non_constant_shape_array (gfc_symbol
*sym
)
11077 not_constant
= false;
11078 if (sym
->as
!= NULL
)
11080 /* Unfortunately, !gfc_is_compile_time_shape hits a legal case that
11081 has not been simplified; parameter array references. Do the
11082 simplification now. */
11083 for (i
= 0; i
< sym
->as
->rank
+ sym
->as
->corank
; i
++)
11085 e
= sym
->as
->lower
[i
];
11086 if (e
&& (!resolve_index_expr(e
)
11087 || !gfc_is_constant_expr (e
)))
11088 not_constant
= true;
11089 e
= sym
->as
->upper
[i
];
11090 if (e
&& (!resolve_index_expr(e
)
11091 || !gfc_is_constant_expr (e
)))
11092 not_constant
= true;
11095 return not_constant
;
11098 /* Given a symbol and an initialization expression, add code to initialize
11099 the symbol to the function entry. */
11101 build_init_assign (gfc_symbol
*sym
, gfc_expr
*init
)
11105 gfc_namespace
*ns
= sym
->ns
;
11107 /* Search for the function namespace if this is a contained
11108 function without an explicit result. */
11109 if (sym
->attr
.function
&& sym
== sym
->result
11110 && sym
->name
!= sym
->ns
->proc_name
->name
)
11112 ns
= ns
->contained
;
11113 for (;ns
; ns
= ns
->sibling
)
11114 if (strcmp (ns
->proc_name
->name
, sym
->name
) == 0)
11120 gfc_free_expr (init
);
11124 /* Build an l-value expression for the result. */
11125 lval
= gfc_lval_expr_from_sym (sym
);
11127 /* Add the code at scope entry. */
11128 init_st
= gfc_get_code (EXEC_INIT_ASSIGN
);
11129 init_st
->next
= ns
->code
;
11130 ns
->code
= init_st
;
11132 /* Assign the default initializer to the l-value. */
11133 init_st
->loc
= sym
->declared_at
;
11134 init_st
->expr1
= lval
;
11135 init_st
->expr2
= init
;
11138 /* Assign the default initializer to a derived type variable or result. */
11141 apply_default_init (gfc_symbol
*sym
)
11143 gfc_expr
*init
= NULL
;
11145 if (sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
11148 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
)
11149 init
= gfc_default_initializer (&sym
->ts
);
11151 if (init
== NULL
&& sym
->ts
.type
!= BT_CLASS
)
11154 build_init_assign (sym
, init
);
11155 sym
->attr
.referenced
= 1;
11158 /* Build an initializer for a local integer, real, complex, logical, or
11159 character variable, based on the command line flags finit-local-zero,
11160 finit-integer=, finit-real=, finit-logical=, and finit-runtime. Returns
11161 null if the symbol should not have a default initialization. */
11163 build_default_init_expr (gfc_symbol
*sym
)
11166 gfc_expr
*init_expr
;
11169 /* These symbols should never have a default initialization. */
11170 if (sym
->attr
.allocatable
11171 || sym
->attr
.external
11173 || sym
->attr
.pointer
11174 || sym
->attr
.in_equivalence
11175 || sym
->attr
.in_common
11178 || sym
->attr
.cray_pointee
11179 || sym
->attr
.cray_pointer
11183 /* Now we'll try to build an initializer expression. */
11184 init_expr
= gfc_get_constant_expr (sym
->ts
.type
, sym
->ts
.kind
,
11185 &sym
->declared_at
);
11187 /* We will only initialize integers, reals, complex, logicals, and
11188 characters, and only if the corresponding command-line flags
11189 were set. Otherwise, we free init_expr and return null. */
11190 switch (sym
->ts
.type
)
11193 if (gfc_option
.flag_init_integer
!= GFC_INIT_INTEGER_OFF
)
11194 mpz_set_si (init_expr
->value
.integer
,
11195 gfc_option
.flag_init_integer_value
);
11198 gfc_free_expr (init_expr
);
11204 switch (flag_init_real
)
11206 case GFC_INIT_REAL_SNAN
:
11207 init_expr
->is_snan
= 1;
11208 /* Fall through. */
11209 case GFC_INIT_REAL_NAN
:
11210 mpfr_set_nan (init_expr
->value
.real
);
11213 case GFC_INIT_REAL_INF
:
11214 mpfr_set_inf (init_expr
->value
.real
, 1);
11217 case GFC_INIT_REAL_NEG_INF
:
11218 mpfr_set_inf (init_expr
->value
.real
, -1);
11221 case GFC_INIT_REAL_ZERO
:
11222 mpfr_set_ui (init_expr
->value
.real
, 0.0, GFC_RND_MODE
);
11226 gfc_free_expr (init_expr
);
11233 switch (flag_init_real
)
11235 case GFC_INIT_REAL_SNAN
:
11236 init_expr
->is_snan
= 1;
11237 /* Fall through. */
11238 case GFC_INIT_REAL_NAN
:
11239 mpfr_set_nan (mpc_realref (init_expr
->value
.complex));
11240 mpfr_set_nan (mpc_imagref (init_expr
->value
.complex));
11243 case GFC_INIT_REAL_INF
:
11244 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), 1);
11245 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), 1);
11248 case GFC_INIT_REAL_NEG_INF
:
11249 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), -1);
11250 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), -1);
11253 case GFC_INIT_REAL_ZERO
:
11254 mpc_set_ui (init_expr
->value
.complex, 0, GFC_MPC_RND_MODE
);
11258 gfc_free_expr (init_expr
);
11265 if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_FALSE
)
11266 init_expr
->value
.logical
= 0;
11267 else if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_TRUE
)
11268 init_expr
->value
.logical
= 1;
11271 gfc_free_expr (init_expr
);
11277 /* For characters, the length must be constant in order to
11278 create a default initializer. */
11279 if (gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
11280 && sym
->ts
.u
.cl
->length
11281 && sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
11283 char_len
= mpz_get_si (sym
->ts
.u
.cl
->length
->value
.integer
);
11284 init_expr
->value
.character
.length
= char_len
;
11285 init_expr
->value
.character
.string
= gfc_get_wide_string (char_len
+1);
11286 for (i
= 0; i
< char_len
; i
++)
11287 init_expr
->value
.character
.string
[i
]
11288 = (unsigned char) gfc_option
.flag_init_character_value
;
11292 gfc_free_expr (init_expr
);
11295 if (!init_expr
&& gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
11296 && sym
->ts
.u
.cl
->length
&& flag_max_stack_var_size
!= 0)
11298 gfc_actual_arglist
*arg
;
11299 init_expr
= gfc_get_expr ();
11300 init_expr
->where
= sym
->declared_at
;
11301 init_expr
->ts
= sym
->ts
;
11302 init_expr
->expr_type
= EXPR_FUNCTION
;
11303 init_expr
->value
.function
.isym
=
11304 gfc_intrinsic_function_by_id (GFC_ISYM_REPEAT
);
11305 init_expr
->value
.function
.name
= "repeat";
11306 arg
= gfc_get_actual_arglist ();
11307 arg
->expr
= gfc_get_character_expr (sym
->ts
.kind
, &sym
->declared_at
,
11309 arg
->expr
->value
.character
.string
[0]
11310 = gfc_option
.flag_init_character_value
;
11311 arg
->next
= gfc_get_actual_arglist ();
11312 arg
->next
->expr
= gfc_copy_expr (sym
->ts
.u
.cl
->length
);
11313 init_expr
->value
.function
.actual
= arg
;
11318 gfc_free_expr (init_expr
);
11324 /* Add an initialization expression to a local variable. */
11326 apply_default_init_local (gfc_symbol
*sym
)
11328 gfc_expr
*init
= NULL
;
11330 /* The symbol should be a variable or a function return value. */
11331 if ((sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
11332 || (sym
->attr
.function
&& sym
->result
!= sym
))
11335 /* Try to build the initializer expression. If we can't initialize
11336 this symbol, then init will be NULL. */
11337 init
= build_default_init_expr (sym
);
11341 /* For saved variables, we don't want to add an initializer at function
11342 entry, so we just add a static initializer. Note that automatic variables
11343 are stack allocated even with -fno-automatic; we have also to exclude
11344 result variable, which are also nonstatic. */
11345 if (sym
->attr
.save
|| sym
->ns
->save_all
11346 || (flag_max_stack_var_size
== 0 && !sym
->attr
.result
11347 && (sym
->ns
->proc_name
&& !sym
->ns
->proc_name
->attr
.recursive
)
11348 && (!sym
->attr
.dimension
|| !is_non_constant_shape_array (sym
))))
11350 /* Don't clobber an existing initializer! */
11351 gcc_assert (sym
->value
== NULL
);
11356 build_init_assign (sym
, init
);
11360 /* Resolution of common features of flavors variable and procedure. */
11363 resolve_fl_var_and_proc (gfc_symbol
*sym
, int mp_flag
)
11365 gfc_array_spec
*as
;
11367 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
11368 as
= CLASS_DATA (sym
)->as
;
11372 /* Constraints on deferred shape variable. */
11373 if (as
== NULL
|| as
->type
!= AS_DEFERRED
)
11375 bool pointer
, allocatable
, dimension
;
11377 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
11379 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
11380 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
11381 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
11385 pointer
= sym
->attr
.pointer
&& !sym
->attr
.select_type_temporary
;
11386 allocatable
= sym
->attr
.allocatable
;
11387 dimension
= sym
->attr
.dimension
;
11392 if (dimension
&& as
->type
!= AS_ASSUMED_RANK
)
11394 gfc_error ("Allocatable array %qs at %L must have a deferred "
11395 "shape or assumed rank", sym
->name
, &sym
->declared_at
);
11398 else if (!gfc_notify_std (GFC_STD_F2003
, "Scalar object "
11399 "%qs at %L may not be ALLOCATABLE",
11400 sym
->name
, &sym
->declared_at
))
11404 if (pointer
&& dimension
&& as
->type
!= AS_ASSUMED_RANK
)
11406 gfc_error ("Array pointer %qs at %L must have a deferred shape or "
11407 "assumed rank", sym
->name
, &sym
->declared_at
);
11413 if (!mp_flag
&& !sym
->attr
.allocatable
&& !sym
->attr
.pointer
11414 && sym
->ts
.type
!= BT_CLASS
&& !sym
->assoc
)
11416 gfc_error ("Array %qs at %L cannot have a deferred shape",
11417 sym
->name
, &sym
->declared_at
);
11422 /* Constraints on polymorphic variables. */
11423 if (sym
->ts
.type
== BT_CLASS
&& !(sym
->result
&& sym
->result
!= sym
))
11426 if (sym
->attr
.class_ok
11427 && !sym
->attr
.select_type_temporary
11428 && !UNLIMITED_POLY (sym
)
11429 && !gfc_type_is_extensible (CLASS_DATA (sym
)->ts
.u
.derived
))
11431 gfc_error ("Type %qs of CLASS variable %qs at %L is not extensible",
11432 CLASS_DATA (sym
)->ts
.u
.derived
->name
, sym
->name
,
11433 &sym
->declared_at
);
11438 /* Assume that use associated symbols were checked in the module ns.
11439 Class-variables that are associate-names are also something special
11440 and excepted from the test. */
11441 if (!sym
->attr
.class_ok
&& !sym
->attr
.use_assoc
&& !sym
->assoc
)
11443 gfc_error ("CLASS variable %qs at %L must be dummy, allocatable "
11444 "or pointer", sym
->name
, &sym
->declared_at
);
11453 /* Additional checks for symbols with flavor variable and derived
11454 type. To be called from resolve_fl_variable. */
11457 resolve_fl_variable_derived (gfc_symbol
*sym
, int no_init_flag
)
11459 gcc_assert (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
);
11461 /* Check to see if a derived type is blocked from being host
11462 associated by the presence of another class I symbol in the same
11463 namespace. 14.6.1.3 of the standard and the discussion on
11464 comp.lang.fortran. */
11465 if (sym
->ns
!= sym
->ts
.u
.derived
->ns
11466 && sym
->ns
->proc_name
->attr
.if_source
!= IFSRC_IFBODY
)
11469 gfc_find_symbol (sym
->ts
.u
.derived
->name
, sym
->ns
, 0, &s
);
11470 if (s
&& s
->attr
.generic
)
11471 s
= gfc_find_dt_in_generic (s
);
11472 if (s
&& !gfc_fl_struct (s
->attr
.flavor
))
11474 gfc_error ("The type %qs cannot be host associated at %L "
11475 "because it is blocked by an incompatible object "
11476 "of the same name declared at %L",
11477 sym
->ts
.u
.derived
->name
, &sym
->declared_at
,
11483 /* 4th constraint in section 11.3: "If an object of a type for which
11484 component-initialization is specified (R429) appears in the
11485 specification-part of a module and does not have the ALLOCATABLE
11486 or POINTER attribute, the object shall have the SAVE attribute."
11488 The check for initializers is performed with
11489 gfc_has_default_initializer because gfc_default_initializer generates
11490 a hidden default for allocatable components. */
11491 if (!(sym
->value
|| no_init_flag
) && sym
->ns
->proc_name
11492 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
11493 && !sym
->ns
->save_all
&& !sym
->attr
.save
11494 && !sym
->attr
.pointer
&& !sym
->attr
.allocatable
11495 && gfc_has_default_initializer (sym
->ts
.u
.derived
)
11496 && !gfc_notify_std (GFC_STD_F2008
, "Implied SAVE for module variable "
11497 "%qs at %L, needed due to the default "
11498 "initialization", sym
->name
, &sym
->declared_at
))
11501 /* Assign default initializer. */
11502 if (!(sym
->value
|| sym
->attr
.pointer
|| sym
->attr
.allocatable
)
11503 && (!no_init_flag
|| sym
->attr
.intent
== INTENT_OUT
))
11505 sym
->value
= gfc_default_initializer (&sym
->ts
);
11512 /* Resolve symbols with flavor variable. */
11515 resolve_fl_variable (gfc_symbol
*sym
, int mp_flag
)
11517 int no_init_flag
, automatic_flag
;
11519 const char *auto_save_msg
;
11520 bool saved_specification_expr
;
11522 auto_save_msg
= "Automatic object %qs at %L cannot have the "
11525 if (!resolve_fl_var_and_proc (sym
, mp_flag
))
11528 /* Set this flag to check that variables are parameters of all entries.
11529 This check is effected by the call to gfc_resolve_expr through
11530 is_non_constant_shape_array. */
11531 saved_specification_expr
= specification_expr
;
11532 specification_expr
= true;
11534 if (sym
->ns
->proc_name
11535 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
11536 || sym
->ns
->proc_name
->attr
.is_main_program
)
11537 && !sym
->attr
.use_assoc
11538 && !sym
->attr
.allocatable
11539 && !sym
->attr
.pointer
11540 && is_non_constant_shape_array (sym
))
11542 /* The shape of a main program or module array needs to be
11544 gfc_error ("The module or main program array %qs at %L must "
11545 "have constant shape", sym
->name
, &sym
->declared_at
);
11546 specification_expr
= saved_specification_expr
;
11550 /* Constraints on deferred type parameter. */
11551 if (sym
->ts
.deferred
11552 && !(sym
->attr
.pointer
11553 || sym
->attr
.allocatable
11554 || sym
->attr
.omp_udr_artificial_var
))
11556 gfc_error ("Entity %qs at %L has a deferred type parameter and "
11557 "requires either the pointer or allocatable attribute",
11558 sym
->name
, &sym
->declared_at
);
11559 specification_expr
= saved_specification_expr
;
11563 if (sym
->ts
.type
== BT_CHARACTER
)
11565 /* Make sure that character string variables with assumed length are
11566 dummy arguments. */
11567 e
= sym
->ts
.u
.cl
->length
;
11568 if (e
== NULL
&& !sym
->attr
.dummy
&& !sym
->attr
.result
11569 && !sym
->ts
.deferred
&& !sym
->attr
.select_type_temporary
11570 && !sym
->attr
.omp_udr_artificial_var
)
11572 gfc_error ("Entity with assumed character length at %L must be a "
11573 "dummy argument or a PARAMETER", &sym
->declared_at
);
11574 specification_expr
= saved_specification_expr
;
11578 if (e
&& sym
->attr
.save
== SAVE_EXPLICIT
&& !gfc_is_constant_expr (e
))
11580 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
11581 specification_expr
= saved_specification_expr
;
11585 if (!gfc_is_constant_expr (e
)
11586 && !(e
->expr_type
== EXPR_VARIABLE
11587 && e
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
))
11589 if (!sym
->attr
.use_assoc
&& sym
->ns
->proc_name
11590 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
11591 || sym
->ns
->proc_name
->attr
.is_main_program
))
11593 gfc_error ("%qs at %L must have constant character length "
11594 "in this context", sym
->name
, &sym
->declared_at
);
11595 specification_expr
= saved_specification_expr
;
11598 if (sym
->attr
.in_common
)
11600 gfc_error ("COMMON variable %qs at %L must have constant "
11601 "character length", sym
->name
, &sym
->declared_at
);
11602 specification_expr
= saved_specification_expr
;
11608 if (sym
->value
== NULL
&& sym
->attr
.referenced
)
11609 apply_default_init_local (sym
); /* Try to apply a default initialization. */
11611 /* Determine if the symbol may not have an initializer. */
11612 no_init_flag
= automatic_flag
= 0;
11613 if (sym
->attr
.allocatable
|| sym
->attr
.external
|| sym
->attr
.dummy
11614 || sym
->attr
.intrinsic
|| sym
->attr
.result
)
11616 else if ((sym
->attr
.dimension
|| sym
->attr
.codimension
) && !sym
->attr
.pointer
11617 && is_non_constant_shape_array (sym
))
11619 no_init_flag
= automatic_flag
= 1;
11621 /* Also, they must not have the SAVE attribute.
11622 SAVE_IMPLICIT is checked below. */
11623 if (sym
->as
&& sym
->attr
.codimension
)
11625 int corank
= sym
->as
->corank
;
11626 sym
->as
->corank
= 0;
11627 no_init_flag
= automatic_flag
= is_non_constant_shape_array (sym
);
11628 sym
->as
->corank
= corank
;
11630 if (automatic_flag
&& sym
->attr
.save
== SAVE_EXPLICIT
)
11632 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
11633 specification_expr
= saved_specification_expr
;
11638 /* Ensure that any initializer is simplified. */
11640 gfc_simplify_expr (sym
->value
, 1);
11642 /* Reject illegal initializers. */
11643 if (!sym
->mark
&& sym
->value
)
11645 if (sym
->attr
.allocatable
|| (sym
->ts
.type
== BT_CLASS
11646 && CLASS_DATA (sym
)->attr
.allocatable
))
11647 gfc_error ("Allocatable %qs at %L cannot have an initializer",
11648 sym
->name
, &sym
->declared_at
);
11649 else if (sym
->attr
.external
)
11650 gfc_error ("External %qs at %L cannot have an initializer",
11651 sym
->name
, &sym
->declared_at
);
11652 else if (sym
->attr
.dummy
11653 && !(sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.intent
== INTENT_OUT
))
11654 gfc_error ("Dummy %qs at %L cannot have an initializer",
11655 sym
->name
, &sym
->declared_at
);
11656 else if (sym
->attr
.intrinsic
)
11657 gfc_error ("Intrinsic %qs at %L cannot have an initializer",
11658 sym
->name
, &sym
->declared_at
);
11659 else if (sym
->attr
.result
)
11660 gfc_error ("Function result %qs at %L cannot have an initializer",
11661 sym
->name
, &sym
->declared_at
);
11662 else if (automatic_flag
)
11663 gfc_error ("Automatic array %qs at %L cannot have an initializer",
11664 sym
->name
, &sym
->declared_at
);
11666 goto no_init_error
;
11667 specification_expr
= saved_specification_expr
;
11672 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
11674 bool res
= resolve_fl_variable_derived (sym
, no_init_flag
);
11675 specification_expr
= saved_specification_expr
;
11679 specification_expr
= saved_specification_expr
;
11684 /* Compare the dummy characteristics of a module procedure interface
11685 declaration with the corresponding declaration in a submodule. */
11686 static gfc_formal_arglist
*new_formal
;
11687 static char errmsg
[200];
11690 compare_fsyms (gfc_symbol
*sym
)
11694 if (sym
== NULL
|| new_formal
== NULL
)
11697 fsym
= new_formal
->sym
;
11702 if (strcmp (sym
->name
, fsym
->name
) == 0)
11704 if (!gfc_check_dummy_characteristics (fsym
, sym
, true, errmsg
, 200))
11705 gfc_error ("%s at %L", errmsg
, &fsym
->declared_at
);
11710 /* Resolve a procedure. */
11713 resolve_fl_procedure (gfc_symbol
*sym
, int mp_flag
)
11715 gfc_formal_arglist
*arg
;
11717 if (sym
->attr
.function
11718 && !resolve_fl_var_and_proc (sym
, mp_flag
))
11721 if (sym
->ts
.type
== BT_CHARACTER
)
11723 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
11725 if (cl
&& cl
->length
&& gfc_is_constant_expr (cl
->length
)
11726 && !resolve_charlen (cl
))
11729 if ((!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
11730 && sym
->attr
.proc
== PROC_ST_FUNCTION
)
11732 gfc_error ("Character-valued statement function %qs at %L must "
11733 "have constant length", sym
->name
, &sym
->declared_at
);
11738 /* Ensure that derived type for are not of a private type. Internal
11739 module procedures are excluded by 2.2.3.3 - i.e., they are not
11740 externally accessible and can access all the objects accessible in
11742 if (!(sym
->ns
->parent
11743 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
11744 && gfc_check_symbol_access (sym
))
11746 gfc_interface
*iface
;
11748 for (arg
= gfc_sym_get_dummy_args (sym
); arg
; arg
= arg
->next
)
11751 && arg
->sym
->ts
.type
== BT_DERIVED
11752 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
11753 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
11754 && !gfc_notify_std (GFC_STD_F2003
, "%qs is of a PRIVATE type "
11755 "and cannot be a dummy argument"
11756 " of %qs, which is PUBLIC at %L",
11757 arg
->sym
->name
, sym
->name
,
11758 &sym
->declared_at
))
11760 /* Stop this message from recurring. */
11761 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
11766 /* PUBLIC interfaces may expose PRIVATE procedures that take types
11767 PRIVATE to the containing module. */
11768 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
11770 for (arg
= gfc_sym_get_dummy_args (iface
->sym
); arg
; arg
= arg
->next
)
11773 && arg
->sym
->ts
.type
== BT_DERIVED
11774 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
11775 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
11776 && !gfc_notify_std (GFC_STD_F2003
, "Procedure %qs in "
11777 "PUBLIC interface %qs at %L "
11778 "takes dummy arguments of %qs which "
11779 "is PRIVATE", iface
->sym
->name
,
11780 sym
->name
, &iface
->sym
->declared_at
,
11781 gfc_typename(&arg
->sym
->ts
)))
11783 /* Stop this message from recurring. */
11784 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
11791 if (sym
->attr
.function
&& sym
->value
&& sym
->attr
.proc
!= PROC_ST_FUNCTION
11792 && !sym
->attr
.proc_pointer
)
11794 gfc_error ("Function %qs at %L cannot have an initializer",
11795 sym
->name
, &sym
->declared_at
);
11799 /* An external symbol may not have an initializer because it is taken to be
11800 a procedure. Exception: Procedure Pointers. */
11801 if (sym
->attr
.external
&& sym
->value
&& !sym
->attr
.proc_pointer
)
11803 gfc_error ("External object %qs at %L may not have an initializer",
11804 sym
->name
, &sym
->declared_at
);
11808 /* An elemental function is required to return a scalar 12.7.1 */
11809 if (sym
->attr
.elemental
&& sym
->attr
.function
&& sym
->as
)
11811 gfc_error ("ELEMENTAL function %qs at %L must have a scalar "
11812 "result", sym
->name
, &sym
->declared_at
);
11813 /* Reset so that the error only occurs once. */
11814 sym
->attr
.elemental
= 0;
11818 if (sym
->attr
.proc
== PROC_ST_FUNCTION
11819 && (sym
->attr
.allocatable
|| sym
->attr
.pointer
))
11821 gfc_error ("Statement function %qs at %L may not have pointer or "
11822 "allocatable attribute", sym
->name
, &sym
->declared_at
);
11826 /* 5.1.1.5 of the Standard: A function name declared with an asterisk
11827 char-len-param shall not be array-valued, pointer-valued, recursive
11828 or pure. ....snip... A character value of * may only be used in the
11829 following ways: (i) Dummy arg of procedure - dummy associates with
11830 actual length; (ii) To declare a named constant; or (iii) External
11831 function - but length must be declared in calling scoping unit. */
11832 if (sym
->attr
.function
11833 && sym
->ts
.type
== BT_CHARACTER
&& !sym
->ts
.deferred
11834 && sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
== NULL
)
11836 if ((sym
->as
&& sym
->as
->rank
) || (sym
->attr
.pointer
)
11837 || (sym
->attr
.recursive
) || (sym
->attr
.pure
))
11839 if (sym
->as
&& sym
->as
->rank
)
11840 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11841 "array-valued", sym
->name
, &sym
->declared_at
);
11843 if (sym
->attr
.pointer
)
11844 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11845 "pointer-valued", sym
->name
, &sym
->declared_at
);
11847 if (sym
->attr
.pure
)
11848 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11849 "pure", sym
->name
, &sym
->declared_at
);
11851 if (sym
->attr
.recursive
)
11852 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11853 "recursive", sym
->name
, &sym
->declared_at
);
11858 /* Appendix B.2 of the standard. Contained functions give an
11859 error anyway. Deferred character length is an F2003 feature.
11860 Don't warn on intrinsic conversion functions, which start
11861 with two underscores. */
11862 if (!sym
->attr
.contained
&& !sym
->ts
.deferred
11863 && (sym
->name
[0] != '_' || sym
->name
[1] != '_'))
11864 gfc_notify_std (GFC_STD_F95_OBS
,
11865 "CHARACTER(*) function %qs at %L",
11866 sym
->name
, &sym
->declared_at
);
11869 /* F2008, C1218. */
11870 if (sym
->attr
.elemental
)
11872 if (sym
->attr
.proc_pointer
)
11874 gfc_error ("Procedure pointer %qs at %L shall not be elemental",
11875 sym
->name
, &sym
->declared_at
);
11878 if (sym
->attr
.dummy
)
11880 gfc_error ("Dummy procedure %qs at %L shall not be elemental",
11881 sym
->name
, &sym
->declared_at
);
11886 if (sym
->attr
.is_bind_c
&& sym
->attr
.is_c_interop
!= 1)
11888 gfc_formal_arglist
*curr_arg
;
11889 int has_non_interop_arg
= 0;
11891 if (!verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
11892 sym
->common_block
))
11894 /* Clear these to prevent looking at them again if there was an
11896 sym
->attr
.is_bind_c
= 0;
11897 sym
->attr
.is_c_interop
= 0;
11898 sym
->ts
.is_c_interop
= 0;
11902 /* So far, no errors have been found. */
11903 sym
->attr
.is_c_interop
= 1;
11904 sym
->ts
.is_c_interop
= 1;
11907 curr_arg
= gfc_sym_get_dummy_args (sym
);
11908 while (curr_arg
!= NULL
)
11910 /* Skip implicitly typed dummy args here. */
11911 if (curr_arg
->sym
->attr
.implicit_type
== 0)
11912 if (!gfc_verify_c_interop_param (curr_arg
->sym
))
11913 /* If something is found to fail, record the fact so we
11914 can mark the symbol for the procedure as not being
11915 BIND(C) to try and prevent multiple errors being
11917 has_non_interop_arg
= 1;
11919 curr_arg
= curr_arg
->next
;
11922 /* See if any of the arguments were not interoperable and if so, clear
11923 the procedure symbol to prevent duplicate error messages. */
11924 if (has_non_interop_arg
!= 0)
11926 sym
->attr
.is_c_interop
= 0;
11927 sym
->ts
.is_c_interop
= 0;
11928 sym
->attr
.is_bind_c
= 0;
11932 if (!sym
->attr
.proc_pointer
)
11934 if (sym
->attr
.save
== SAVE_EXPLICIT
)
11936 gfc_error ("PROCEDURE attribute conflicts with SAVE attribute "
11937 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11940 if (sym
->attr
.intent
)
11942 gfc_error ("PROCEDURE attribute conflicts with INTENT attribute "
11943 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11946 if (sym
->attr
.subroutine
&& sym
->attr
.result
)
11948 gfc_error ("PROCEDURE attribute conflicts with RESULT attribute "
11949 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11952 if (sym
->attr
.external
&& sym
->attr
.function
&& !sym
->attr
.module_procedure
11953 && ((sym
->attr
.if_source
== IFSRC_DECL
&& !sym
->attr
.procedure
)
11954 || sym
->attr
.contained
))
11956 gfc_error ("EXTERNAL attribute conflicts with FUNCTION attribute "
11957 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11960 if (strcmp ("ppr@", sym
->name
) == 0)
11962 gfc_error ("Procedure pointer result %qs at %L "
11963 "is missing the pointer attribute",
11964 sym
->ns
->proc_name
->name
, &sym
->declared_at
);
11969 /* Assume that a procedure whose body is not known has references
11970 to external arrays. */
11971 if (sym
->attr
.if_source
!= IFSRC_DECL
)
11972 sym
->attr
.array_outer_dependency
= 1;
11974 /* Compare the characteristics of a module procedure with the
11975 interface declaration. Ideally this would be done with
11976 gfc_compare_interfaces but, at present, the formal interface
11977 cannot be copied to the ts.interface. */
11978 if (sym
->attr
.module_procedure
11979 && sym
->attr
.if_source
== IFSRC_DECL
)
11982 char name
[2*GFC_MAX_SYMBOL_LEN
+ 1];
11984 char *submodule_name
;
11985 strcpy (name
, sym
->ns
->proc_name
->name
);
11986 module_name
= strtok (name
, ".");
11987 submodule_name
= strtok (NULL
, ".");
11989 /* Stop the dummy characteristics test from using the interface
11990 symbol instead of 'sym'. */
11991 iface
= sym
->ts
.interface
;
11992 sym
->ts
.interface
= NULL
;
11997 /* Check the procedure characteristics. */
11998 if (sym
->attr
.elemental
!= iface
->attr
.elemental
)
12000 gfc_error ("Mismatch in ELEMENTAL attribute between MODULE "
12001 "PROCEDURE at %L and its interface in %s",
12002 &sym
->declared_at
, module_name
);
12006 if (sym
->attr
.pure
!= iface
->attr
.pure
)
12008 gfc_error ("Mismatch in PURE attribute between MODULE "
12009 "PROCEDURE at %L and its interface in %s",
12010 &sym
->declared_at
, module_name
);
12014 if (sym
->attr
.recursive
!= iface
->attr
.recursive
)
12016 gfc_error ("Mismatch in RECURSIVE attribute between MODULE "
12017 "PROCEDURE at %L and its interface in %s",
12018 &sym
->declared_at
, module_name
);
12022 /* Check the result characteristics. */
12023 if (!gfc_check_result_characteristics (sym
, iface
, errmsg
, 200))
12025 gfc_error ("%s between the MODULE PROCEDURE declaration "
12026 "in module %s and the declaration at %L in "
12027 "SUBMODULE %s", errmsg
, module_name
,
12028 &sym
->declared_at
, submodule_name
);
12033 /* Check the charcateristics of the formal arguments. */
12034 if (sym
->formal
&& sym
->formal_ns
)
12036 for (arg
= sym
->formal
; arg
&& arg
->sym
; arg
= arg
->next
)
12039 gfc_traverse_ns (sym
->formal_ns
, compare_fsyms
);
12043 sym
->ts
.interface
= iface
;
12049 /* Resolve a list of finalizer procedures. That is, after they have hopefully
12050 been defined and we now know their defined arguments, check that they fulfill
12051 the requirements of the standard for procedures used as finalizers. */
12054 gfc_resolve_finalizers (gfc_symbol
* derived
, bool *finalizable
)
12056 gfc_finalizer
* list
;
12057 gfc_finalizer
** prev_link
; /* For removing wrong entries from the list. */
12058 bool result
= true;
12059 bool seen_scalar
= false;
12062 gfc_symbol
*parent
= gfc_get_derived_super_type (derived
);
12065 gfc_resolve_finalizers (parent
, finalizable
);
12067 /* Return early when not finalizable. Additionally, ensure that derived-type
12068 components have a their finalizables resolved. */
12069 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->finalizers
)
12071 bool has_final
= false;
12072 for (c
= derived
->components
; c
; c
= c
->next
)
12073 if (c
->ts
.type
== BT_DERIVED
12074 && !c
->attr
.pointer
&& !c
->attr
.proc_pointer
&& !c
->attr
.allocatable
)
12076 bool has_final2
= false;
12077 if (!gfc_resolve_finalizers (c
->ts
.u
.derived
, &has_final
))
12078 return false; /* Error. */
12079 has_final
= has_final
|| has_final2
;
12084 *finalizable
= false;
12089 /* Walk over the list of finalizer-procedures, check them, and if any one
12090 does not fit in with the standard's definition, print an error and remove
12091 it from the list. */
12092 prev_link
= &derived
->f2k_derived
->finalizers
;
12093 for (list
= derived
->f2k_derived
->finalizers
; list
; list
= *prev_link
)
12095 gfc_formal_arglist
*dummy_args
;
12100 /* Skip this finalizer if we already resolved it. */
12101 if (list
->proc_tree
)
12103 prev_link
= &(list
->next
);
12107 /* Check this exists and is a SUBROUTINE. */
12108 if (!list
->proc_sym
->attr
.subroutine
)
12110 gfc_error ("FINAL procedure %qs at %L is not a SUBROUTINE",
12111 list
->proc_sym
->name
, &list
->where
);
12115 /* We should have exactly one argument. */
12116 dummy_args
= gfc_sym_get_dummy_args (list
->proc_sym
);
12117 if (!dummy_args
|| dummy_args
->next
)
12119 gfc_error ("FINAL procedure at %L must have exactly one argument",
12123 arg
= dummy_args
->sym
;
12125 /* This argument must be of our type. */
12126 if (arg
->ts
.type
!= BT_DERIVED
|| arg
->ts
.u
.derived
!= derived
)
12128 gfc_error ("Argument of FINAL procedure at %L must be of type %qs",
12129 &arg
->declared_at
, derived
->name
);
12133 /* It must neither be a pointer nor allocatable nor optional. */
12134 if (arg
->attr
.pointer
)
12136 gfc_error ("Argument of FINAL procedure at %L must not be a POINTER",
12137 &arg
->declared_at
);
12140 if (arg
->attr
.allocatable
)
12142 gfc_error ("Argument of FINAL procedure at %L must not be"
12143 " ALLOCATABLE", &arg
->declared_at
);
12146 if (arg
->attr
.optional
)
12148 gfc_error ("Argument of FINAL procedure at %L must not be OPTIONAL",
12149 &arg
->declared_at
);
12153 /* It must not be INTENT(OUT). */
12154 if (arg
->attr
.intent
== INTENT_OUT
)
12156 gfc_error ("Argument of FINAL procedure at %L must not be"
12157 " INTENT(OUT)", &arg
->declared_at
);
12161 /* Warn if the procedure is non-scalar and not assumed shape. */
12162 if (warn_surprising
&& arg
->as
&& arg
->as
->rank
!= 0
12163 && arg
->as
->type
!= AS_ASSUMED_SHAPE
)
12164 gfc_warning (OPT_Wsurprising
,
12165 "Non-scalar FINAL procedure at %L should have assumed"
12166 " shape argument", &arg
->declared_at
);
12168 /* Check that it does not match in kind and rank with a FINAL procedure
12169 defined earlier. To really loop over the *earlier* declarations,
12170 we need to walk the tail of the list as new ones were pushed at the
12172 /* TODO: Handle kind parameters once they are implemented. */
12173 my_rank
= (arg
->as
? arg
->as
->rank
: 0);
12174 for (i
= list
->next
; i
; i
= i
->next
)
12176 gfc_formal_arglist
*dummy_args
;
12178 /* Argument list might be empty; that is an error signalled earlier,
12179 but we nevertheless continued resolving. */
12180 dummy_args
= gfc_sym_get_dummy_args (i
->proc_sym
);
12183 gfc_symbol
* i_arg
= dummy_args
->sym
;
12184 const int i_rank
= (i_arg
->as
? i_arg
->as
->rank
: 0);
12185 if (i_rank
== my_rank
)
12187 gfc_error ("FINAL procedure %qs declared at %L has the same"
12188 " rank (%d) as %qs",
12189 list
->proc_sym
->name
, &list
->where
, my_rank
,
12190 i
->proc_sym
->name
);
12196 /* Is this the/a scalar finalizer procedure? */
12197 if (!arg
->as
|| arg
->as
->rank
== 0)
12198 seen_scalar
= true;
12200 /* Find the symtree for this procedure. */
12201 gcc_assert (!list
->proc_tree
);
12202 list
->proc_tree
= gfc_find_sym_in_symtree (list
->proc_sym
);
12204 prev_link
= &list
->next
;
12207 /* Remove wrong nodes immediately from the list so we don't risk any
12208 troubles in the future when they might fail later expectations. */
12211 *prev_link
= list
->next
;
12212 gfc_free_finalizer (i
);
12216 if (result
== false)
12219 /* Warn if we haven't seen a scalar finalizer procedure (but we know there
12220 were nodes in the list, must have been for arrays. It is surely a good
12221 idea to have a scalar version there if there's something to finalize. */
12222 if (warn_surprising
&& result
&& !seen_scalar
)
12223 gfc_warning (OPT_Wsurprising
,
12224 "Only array FINAL procedures declared for derived type %qs"
12225 " defined at %L, suggest also scalar one",
12226 derived
->name
, &derived
->declared_at
);
12228 vtab
= gfc_find_derived_vtab (derived
);
12229 c
= vtab
->ts
.u
.derived
->components
->next
->next
->next
->next
->next
;
12230 gfc_set_sym_referenced (c
->initializer
->symtree
->n
.sym
);
12233 *finalizable
= true;
12239 /* Check if two GENERIC targets are ambiguous and emit an error is they are. */
12242 check_generic_tbp_ambiguity (gfc_tbp_generic
* t1
, gfc_tbp_generic
* t2
,
12243 const char* generic_name
, locus where
)
12245 gfc_symbol
*sym1
, *sym2
;
12246 const char *pass1
, *pass2
;
12247 gfc_formal_arglist
*dummy_args
;
12249 gcc_assert (t1
->specific
&& t2
->specific
);
12250 gcc_assert (!t1
->specific
->is_generic
);
12251 gcc_assert (!t2
->specific
->is_generic
);
12252 gcc_assert (t1
->is_operator
== t2
->is_operator
);
12254 sym1
= t1
->specific
->u
.specific
->n
.sym
;
12255 sym2
= t2
->specific
->u
.specific
->n
.sym
;
12260 /* Both must be SUBROUTINEs or both must be FUNCTIONs. */
12261 if (sym1
->attr
.subroutine
!= sym2
->attr
.subroutine
12262 || sym1
->attr
.function
!= sym2
->attr
.function
)
12264 gfc_error ("%qs and %qs can't be mixed FUNCTION/SUBROUTINE for"
12265 " GENERIC %qs at %L",
12266 sym1
->name
, sym2
->name
, generic_name
, &where
);
12270 /* Determine PASS arguments. */
12271 if (t1
->specific
->nopass
)
12273 else if (t1
->specific
->pass_arg
)
12274 pass1
= t1
->specific
->pass_arg
;
12277 dummy_args
= gfc_sym_get_dummy_args (t1
->specific
->u
.specific
->n
.sym
);
12279 pass1
= dummy_args
->sym
->name
;
12283 if (t2
->specific
->nopass
)
12285 else if (t2
->specific
->pass_arg
)
12286 pass2
= t2
->specific
->pass_arg
;
12289 dummy_args
= gfc_sym_get_dummy_args (t2
->specific
->u
.specific
->n
.sym
);
12291 pass2
= dummy_args
->sym
->name
;
12296 /* Compare the interfaces. */
12297 if (gfc_compare_interfaces (sym1
, sym2
, sym2
->name
, !t1
->is_operator
, 0,
12298 NULL
, 0, pass1
, pass2
))
12300 gfc_error ("%qs and %qs for GENERIC %qs at %L are ambiguous",
12301 sym1
->name
, sym2
->name
, generic_name
, &where
);
12309 /* Worker function for resolving a generic procedure binding; this is used to
12310 resolve GENERIC as well as user and intrinsic OPERATOR typebound procedures.
12312 The difference between those cases is finding possible inherited bindings
12313 that are overridden, as one has to look for them in tb_sym_root,
12314 tb_uop_root or tb_op, respectively. Thus the caller must already find
12315 the super-type and set p->overridden correctly. */
12318 resolve_tb_generic_targets (gfc_symbol
* super_type
,
12319 gfc_typebound_proc
* p
, const char* name
)
12321 gfc_tbp_generic
* target
;
12322 gfc_symtree
* first_target
;
12323 gfc_symtree
* inherited
;
12325 gcc_assert (p
&& p
->is_generic
);
12327 /* Try to find the specific bindings for the symtrees in our target-list. */
12328 gcc_assert (p
->u
.generic
);
12329 for (target
= p
->u
.generic
; target
; target
= target
->next
)
12330 if (!target
->specific
)
12332 gfc_typebound_proc
* overridden_tbp
;
12333 gfc_tbp_generic
* g
;
12334 const char* target_name
;
12336 target_name
= target
->specific_st
->name
;
12338 /* Defined for this type directly. */
12339 if (target
->specific_st
->n
.tb
&& !target
->specific_st
->n
.tb
->error
)
12341 target
->specific
= target
->specific_st
->n
.tb
;
12342 goto specific_found
;
12345 /* Look for an inherited specific binding. */
12348 inherited
= gfc_find_typebound_proc (super_type
, NULL
, target_name
,
12353 gcc_assert (inherited
->n
.tb
);
12354 target
->specific
= inherited
->n
.tb
;
12355 goto specific_found
;
12359 gfc_error ("Undefined specific binding %qs as target of GENERIC %qs"
12360 " at %L", target_name
, name
, &p
->where
);
12363 /* Once we've found the specific binding, check it is not ambiguous with
12364 other specifics already found or inherited for the same GENERIC. */
12366 gcc_assert (target
->specific
);
12368 /* This must really be a specific binding! */
12369 if (target
->specific
->is_generic
)
12371 gfc_error ("GENERIC %qs at %L must target a specific binding,"
12372 " %qs is GENERIC, too", name
, &p
->where
, target_name
);
12376 /* Check those already resolved on this type directly. */
12377 for (g
= p
->u
.generic
; g
; g
= g
->next
)
12378 if (g
!= target
&& g
->specific
12379 && !check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
12382 /* Check for ambiguity with inherited specific targets. */
12383 for (overridden_tbp
= p
->overridden
; overridden_tbp
;
12384 overridden_tbp
= overridden_tbp
->overridden
)
12385 if (overridden_tbp
->is_generic
)
12387 for (g
= overridden_tbp
->u
.generic
; g
; g
= g
->next
)
12389 gcc_assert (g
->specific
);
12390 if (!check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
12396 /* If we attempt to "overwrite" a specific binding, this is an error. */
12397 if (p
->overridden
&& !p
->overridden
->is_generic
)
12399 gfc_error ("GENERIC %qs at %L can't overwrite specific binding with"
12400 " the same name", name
, &p
->where
);
12404 /* Take the SUBROUTINE/FUNCTION attributes of the first specific target, as
12405 all must have the same attributes here. */
12406 first_target
= p
->u
.generic
->specific
->u
.specific
;
12407 gcc_assert (first_target
);
12408 p
->subroutine
= first_target
->n
.sym
->attr
.subroutine
;
12409 p
->function
= first_target
->n
.sym
->attr
.function
;
12415 /* Resolve a GENERIC procedure binding for a derived type. */
12418 resolve_typebound_generic (gfc_symbol
* derived
, gfc_symtree
* st
)
12420 gfc_symbol
* super_type
;
12422 /* Find the overridden binding if any. */
12423 st
->n
.tb
->overridden
= NULL
;
12424 super_type
= gfc_get_derived_super_type (derived
);
12427 gfc_symtree
* overridden
;
12428 overridden
= gfc_find_typebound_proc (super_type
, NULL
, st
->name
,
12431 if (overridden
&& overridden
->n
.tb
)
12432 st
->n
.tb
->overridden
= overridden
->n
.tb
;
12435 /* Resolve using worker function. */
12436 return resolve_tb_generic_targets (super_type
, st
->n
.tb
, st
->name
);
12440 /* Retrieve the target-procedure of an operator binding and do some checks in
12441 common for intrinsic and user-defined type-bound operators. */
12444 get_checked_tb_operator_target (gfc_tbp_generic
* target
, locus where
)
12446 gfc_symbol
* target_proc
;
12448 gcc_assert (target
->specific
&& !target
->specific
->is_generic
);
12449 target_proc
= target
->specific
->u
.specific
->n
.sym
;
12450 gcc_assert (target_proc
);
12452 /* F08:C468. All operator bindings must have a passed-object dummy argument. */
12453 if (target
->specific
->nopass
)
12455 gfc_error ("Type-bound operator at %L can't be NOPASS", &where
);
12459 return target_proc
;
12463 /* Resolve a type-bound intrinsic operator. */
12466 resolve_typebound_intrinsic_op (gfc_symbol
* derived
, gfc_intrinsic_op op
,
12467 gfc_typebound_proc
* p
)
12469 gfc_symbol
* super_type
;
12470 gfc_tbp_generic
* target
;
12472 /* If there's already an error here, do nothing (but don't fail again). */
12476 /* Operators should always be GENERIC bindings. */
12477 gcc_assert (p
->is_generic
);
12479 /* Look for an overridden binding. */
12480 super_type
= gfc_get_derived_super_type (derived
);
12481 if (super_type
&& super_type
->f2k_derived
)
12482 p
->overridden
= gfc_find_typebound_intrinsic_op (super_type
, NULL
,
12485 p
->overridden
= NULL
;
12487 /* Resolve general GENERIC properties using worker function. */
12488 if (!resolve_tb_generic_targets (super_type
, p
, gfc_op2string(op
)))
12491 /* Check the targets to be procedures of correct interface. */
12492 for (target
= p
->u
.generic
; target
; target
= target
->next
)
12494 gfc_symbol
* target_proc
;
12496 target_proc
= get_checked_tb_operator_target (target
, p
->where
);
12500 if (!gfc_check_operator_interface (target_proc
, op
, p
->where
))
12503 /* Add target to non-typebound operator list. */
12504 if (!target
->specific
->deferred
&& !derived
->attr
.use_assoc
12505 && p
->access
!= ACCESS_PRIVATE
&& derived
->ns
== gfc_current_ns
)
12507 gfc_interface
*head
, *intr
;
12508 if (!gfc_check_new_interface (derived
->ns
->op
[op
], target_proc
, p
->where
))
12510 head
= derived
->ns
->op
[op
];
12511 intr
= gfc_get_interface ();
12512 intr
->sym
= target_proc
;
12513 intr
->where
= p
->where
;
12515 derived
->ns
->op
[op
] = intr
;
12527 /* Resolve a type-bound user operator (tree-walker callback). */
12529 static gfc_symbol
* resolve_bindings_derived
;
12530 static bool resolve_bindings_result
;
12532 static bool check_uop_procedure (gfc_symbol
* sym
, locus where
);
12535 resolve_typebound_user_op (gfc_symtree
* stree
)
12537 gfc_symbol
* super_type
;
12538 gfc_tbp_generic
* target
;
12540 gcc_assert (stree
&& stree
->n
.tb
);
12542 if (stree
->n
.tb
->error
)
12545 /* Operators should always be GENERIC bindings. */
12546 gcc_assert (stree
->n
.tb
->is_generic
);
12548 /* Find overridden procedure, if any. */
12549 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
12550 if (super_type
&& super_type
->f2k_derived
)
12552 gfc_symtree
* overridden
;
12553 overridden
= gfc_find_typebound_user_op (super_type
, NULL
,
12554 stree
->name
, true, NULL
);
12556 if (overridden
&& overridden
->n
.tb
)
12557 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
12560 stree
->n
.tb
->overridden
= NULL
;
12562 /* Resolve basically using worker function. */
12563 if (!resolve_tb_generic_targets (super_type
, stree
->n
.tb
, stree
->name
))
12566 /* Check the targets to be functions of correct interface. */
12567 for (target
= stree
->n
.tb
->u
.generic
; target
; target
= target
->next
)
12569 gfc_symbol
* target_proc
;
12571 target_proc
= get_checked_tb_operator_target (target
, stree
->n
.tb
->where
);
12575 if (!check_uop_procedure (target_proc
, stree
->n
.tb
->where
))
12582 resolve_bindings_result
= false;
12583 stree
->n
.tb
->error
= 1;
12587 /* Resolve the type-bound procedures for a derived type. */
12590 resolve_typebound_procedure (gfc_symtree
* stree
)
12594 gfc_symbol
* me_arg
;
12595 gfc_symbol
* super_type
;
12596 gfc_component
* comp
;
12598 gcc_assert (stree
);
12600 /* Undefined specific symbol from GENERIC target definition. */
12604 if (stree
->n
.tb
->error
)
12607 /* If this is a GENERIC binding, use that routine. */
12608 if (stree
->n
.tb
->is_generic
)
12610 if (!resolve_typebound_generic (resolve_bindings_derived
, stree
))
12615 /* Get the target-procedure to check it. */
12616 gcc_assert (!stree
->n
.tb
->is_generic
);
12617 gcc_assert (stree
->n
.tb
->u
.specific
);
12618 proc
= stree
->n
.tb
->u
.specific
->n
.sym
;
12619 where
= stree
->n
.tb
->where
;
12621 /* Default access should already be resolved from the parser. */
12622 gcc_assert (stree
->n
.tb
->access
!= ACCESS_UNKNOWN
);
12624 if (stree
->n
.tb
->deferred
)
12626 if (!check_proc_interface (proc
, &where
))
12631 /* Check for F08:C465. */
12632 if ((!proc
->attr
.subroutine
&& !proc
->attr
.function
)
12633 || (proc
->attr
.proc
!= PROC_MODULE
12634 && proc
->attr
.if_source
!= IFSRC_IFBODY
)
12635 || proc
->attr
.abstract
)
12637 gfc_error ("%qs must be a module procedure or an external procedure with"
12638 " an explicit interface at %L", proc
->name
, &where
);
12643 stree
->n
.tb
->subroutine
= proc
->attr
.subroutine
;
12644 stree
->n
.tb
->function
= proc
->attr
.function
;
12646 /* Find the super-type of the current derived type. We could do this once and
12647 store in a global if speed is needed, but as long as not I believe this is
12648 more readable and clearer. */
12649 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
12651 /* If PASS, resolve and check arguments if not already resolved / loaded
12652 from a .mod file. */
12653 if (!stree
->n
.tb
->nopass
&& stree
->n
.tb
->pass_arg_num
== 0)
12655 gfc_formal_arglist
*dummy_args
;
12657 dummy_args
= gfc_sym_get_dummy_args (proc
);
12658 if (stree
->n
.tb
->pass_arg
)
12660 gfc_formal_arglist
*i
;
12662 /* If an explicit passing argument name is given, walk the arg-list
12663 and look for it. */
12666 stree
->n
.tb
->pass_arg_num
= 1;
12667 for (i
= dummy_args
; i
; i
= i
->next
)
12669 if (!strcmp (i
->sym
->name
, stree
->n
.tb
->pass_arg
))
12674 ++stree
->n
.tb
->pass_arg_num
;
12679 gfc_error ("Procedure %qs with PASS(%s) at %L has no"
12681 proc
->name
, stree
->n
.tb
->pass_arg
, &where
,
12682 stree
->n
.tb
->pass_arg
);
12688 /* Otherwise, take the first one; there should in fact be at least
12690 stree
->n
.tb
->pass_arg_num
= 1;
12693 gfc_error ("Procedure %qs with PASS at %L must have at"
12694 " least one argument", proc
->name
, &where
);
12697 me_arg
= dummy_args
->sym
;
12700 /* Now check that the argument-type matches and the passed-object
12701 dummy argument is generally fine. */
12703 gcc_assert (me_arg
);
12705 if (me_arg
->ts
.type
!= BT_CLASS
)
12707 gfc_error ("Non-polymorphic passed-object dummy argument of %qs"
12708 " at %L", proc
->name
, &where
);
12712 if (CLASS_DATA (me_arg
)->ts
.u
.derived
12713 != resolve_bindings_derived
)
12715 gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of"
12716 " the derived-type %qs", me_arg
->name
, proc
->name
,
12717 me_arg
->name
, &where
, resolve_bindings_derived
->name
);
12721 gcc_assert (me_arg
->ts
.type
== BT_CLASS
);
12722 if (CLASS_DATA (me_arg
)->as
&& CLASS_DATA (me_arg
)->as
->rank
!= 0)
12724 gfc_error ("Passed-object dummy argument of %qs at %L must be"
12725 " scalar", proc
->name
, &where
);
12728 if (CLASS_DATA (me_arg
)->attr
.allocatable
)
12730 gfc_error ("Passed-object dummy argument of %qs at %L must not"
12731 " be ALLOCATABLE", proc
->name
, &where
);
12734 if (CLASS_DATA (me_arg
)->attr
.class_pointer
)
12736 gfc_error ("Passed-object dummy argument of %qs at %L must not"
12737 " be POINTER", proc
->name
, &where
);
12742 /* If we are extending some type, check that we don't override a procedure
12743 flagged NON_OVERRIDABLE. */
12744 stree
->n
.tb
->overridden
= NULL
;
12747 gfc_symtree
* overridden
;
12748 overridden
= gfc_find_typebound_proc (super_type
, NULL
,
12749 stree
->name
, true, NULL
);
12753 if (overridden
->n
.tb
)
12754 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
12756 if (!gfc_check_typebound_override (stree
, overridden
))
12761 /* See if there's a name collision with a component directly in this type. */
12762 for (comp
= resolve_bindings_derived
->components
; comp
; comp
= comp
->next
)
12763 if (!strcmp (comp
->name
, stree
->name
))
12765 gfc_error ("Procedure %qs at %L has the same name as a component of"
12767 stree
->name
, &where
, resolve_bindings_derived
->name
);
12771 /* Try to find a name collision with an inherited component. */
12772 if (super_type
&& gfc_find_component (super_type
, stree
->name
, true, true,
12775 gfc_error ("Procedure %qs at %L has the same name as an inherited"
12776 " component of %qs",
12777 stree
->name
, &where
, resolve_bindings_derived
->name
);
12781 stree
->n
.tb
->error
= 0;
12785 resolve_bindings_result
= false;
12786 stree
->n
.tb
->error
= 1;
12791 resolve_typebound_procedures (gfc_symbol
* derived
)
12794 gfc_symbol
* super_type
;
12796 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->tb_sym_root
)
12799 super_type
= gfc_get_derived_super_type (derived
);
12801 resolve_symbol (super_type
);
12803 resolve_bindings_derived
= derived
;
12804 resolve_bindings_result
= true;
12806 if (derived
->f2k_derived
->tb_sym_root
)
12807 gfc_traverse_symtree (derived
->f2k_derived
->tb_sym_root
,
12808 &resolve_typebound_procedure
);
12810 if (derived
->f2k_derived
->tb_uop_root
)
12811 gfc_traverse_symtree (derived
->f2k_derived
->tb_uop_root
,
12812 &resolve_typebound_user_op
);
12814 for (op
= 0; op
!= GFC_INTRINSIC_OPS
; ++op
)
12816 gfc_typebound_proc
* p
= derived
->f2k_derived
->tb_op
[op
];
12817 if (p
&& !resolve_typebound_intrinsic_op (derived
,
12818 (gfc_intrinsic_op
)op
, p
))
12819 resolve_bindings_result
= false;
12822 return resolve_bindings_result
;
12826 /* Add a derived type to the dt_list. The dt_list is used in trans-types.c
12827 to give all identical derived types the same backend_decl. */
12829 add_dt_to_dt_list (gfc_symbol
*derived
)
12831 gfc_dt_list
*dt_list
;
12833 for (dt_list
= gfc_derived_types
; dt_list
; dt_list
= dt_list
->next
)
12834 if (derived
== dt_list
->derived
)
12837 dt_list
= gfc_get_dt_list ();
12838 dt_list
->next
= gfc_derived_types
;
12839 dt_list
->derived
= derived
;
12840 gfc_derived_types
= dt_list
;
12844 /* Ensure that a derived-type is really not abstract, meaning that every
12845 inherited DEFERRED binding is overridden by a non-DEFERRED one. */
12848 ensure_not_abstract_walker (gfc_symbol
* sub
, gfc_symtree
* st
)
12853 if (!ensure_not_abstract_walker (sub
, st
->left
))
12855 if (!ensure_not_abstract_walker (sub
, st
->right
))
12858 if (st
->n
.tb
&& st
->n
.tb
->deferred
)
12860 gfc_symtree
* overriding
;
12861 overriding
= gfc_find_typebound_proc (sub
, NULL
, st
->name
, true, NULL
);
12864 gcc_assert (overriding
->n
.tb
);
12865 if (overriding
->n
.tb
->deferred
)
12867 gfc_error ("Derived-type %qs declared at %L must be ABSTRACT because"
12868 " %qs is DEFERRED and not overridden",
12869 sub
->name
, &sub
->declared_at
, st
->name
);
12878 ensure_not_abstract (gfc_symbol
* sub
, gfc_symbol
* ancestor
)
12880 /* The algorithm used here is to recursively travel up the ancestry of sub
12881 and for each ancestor-type, check all bindings. If any of them is
12882 DEFERRED, look it up starting from sub and see if the found (overriding)
12883 binding is not DEFERRED.
12884 This is not the most efficient way to do this, but it should be ok and is
12885 clearer than something sophisticated. */
12887 gcc_assert (ancestor
&& !sub
->attr
.abstract
);
12889 if (!ancestor
->attr
.abstract
)
12892 /* Walk bindings of this ancestor. */
12893 if (ancestor
->f2k_derived
)
12896 t
= ensure_not_abstract_walker (sub
, ancestor
->f2k_derived
->tb_sym_root
);
12901 /* Find next ancestor type and recurse on it. */
12902 ancestor
= gfc_get_derived_super_type (ancestor
);
12904 return ensure_not_abstract (sub
, ancestor
);
12910 /* This check for typebound defined assignments is done recursively
12911 since the order in which derived types are resolved is not always in
12912 order of the declarations. */
12915 check_defined_assignments (gfc_symbol
*derived
)
12919 for (c
= derived
->components
; c
; c
= c
->next
)
12921 if (!gfc_bt_struct (c
->ts
.type
)
12923 || c
->attr
.allocatable
12924 || c
->attr
.proc_pointer_comp
12925 || c
->attr
.class_pointer
12926 || c
->attr
.proc_pointer
)
12929 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
12930 || (c
->ts
.u
.derived
->f2k_derived
12931 && c
->ts
.u
.derived
->f2k_derived
->tb_op
[INTRINSIC_ASSIGN
]))
12933 derived
->attr
.defined_assign_comp
= 1;
12937 check_defined_assignments (c
->ts
.u
.derived
);
12938 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
12940 derived
->attr
.defined_assign_comp
= 1;
12947 /* Resolve a single component of a derived type or structure. */
12950 resolve_component (gfc_component
*c
, gfc_symbol
*sym
)
12952 gfc_symbol
*super_type
;
12954 if (c
->attr
.artificial
)
12958 if ((!sym
->attr
.is_class
|| c
!= sym
->components
)
12959 && c
->attr
.codimension
12960 && (!c
->attr
.allocatable
|| (c
->as
&& c
->as
->type
!= AS_DEFERRED
)))
12962 gfc_error ("Coarray component %qs at %L must be allocatable with "
12963 "deferred shape", c
->name
, &c
->loc
);
12968 if (c
->attr
.codimension
&& c
->ts
.type
== BT_DERIVED
12969 && c
->ts
.u
.derived
->ts
.is_iso_c
)
12971 gfc_error ("Component %qs at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
12972 "shall not be a coarray", c
->name
, &c
->loc
);
12977 if (gfc_bt_struct (c
->ts
.type
) && c
->ts
.u
.derived
->attr
.coarray_comp
12978 && (c
->attr
.codimension
|| c
->attr
.pointer
|| c
->attr
.dimension
12979 || c
->attr
.allocatable
))
12981 gfc_error ("Component %qs at %L with coarray component "
12982 "shall be a nonpointer, nonallocatable scalar",
12988 if (c
->attr
.contiguous
&& (!c
->attr
.dimension
|| !c
->attr
.pointer
))
12990 gfc_error ("Component %qs at %L has the CONTIGUOUS attribute but "
12991 "is not an array pointer", c
->name
, &c
->loc
);
12995 if (c
->attr
.proc_pointer
&& c
->ts
.interface
)
12997 gfc_symbol
*ifc
= c
->ts
.interface
;
12999 if (!sym
->attr
.vtype
&& !check_proc_interface (ifc
, &c
->loc
))
13005 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
13007 /* Resolve interface and copy attributes. */
13008 if (ifc
->formal
&& !ifc
->formal_ns
)
13009 resolve_symbol (ifc
);
13010 if (ifc
->attr
.intrinsic
)
13011 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
13015 c
->ts
= ifc
->result
->ts
;
13016 c
->attr
.allocatable
= ifc
->result
->attr
.allocatable
;
13017 c
->attr
.pointer
= ifc
->result
->attr
.pointer
;
13018 c
->attr
.dimension
= ifc
->result
->attr
.dimension
;
13019 c
->as
= gfc_copy_array_spec (ifc
->result
->as
);
13020 c
->attr
.class_ok
= ifc
->result
->attr
.class_ok
;
13025 c
->attr
.allocatable
= ifc
->attr
.allocatable
;
13026 c
->attr
.pointer
= ifc
->attr
.pointer
;
13027 c
->attr
.dimension
= ifc
->attr
.dimension
;
13028 c
->as
= gfc_copy_array_spec (ifc
->as
);
13029 c
->attr
.class_ok
= ifc
->attr
.class_ok
;
13031 c
->ts
.interface
= ifc
;
13032 c
->attr
.function
= ifc
->attr
.function
;
13033 c
->attr
.subroutine
= ifc
->attr
.subroutine
;
13035 c
->attr
.pure
= ifc
->attr
.pure
;
13036 c
->attr
.elemental
= ifc
->attr
.elemental
;
13037 c
->attr
.recursive
= ifc
->attr
.recursive
;
13038 c
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
13039 c
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
13040 /* Copy char length. */
13041 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
13043 gfc_charlen
*cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
13044 if (cl
->length
&& !cl
->resolved
13045 && !gfc_resolve_expr (cl
->length
))
13054 else if (c
->attr
.proc_pointer
&& c
->ts
.type
== BT_UNKNOWN
)
13056 /* Since PPCs are not implicitly typed, a PPC without an explicit
13057 interface must be a subroutine. */
13058 gfc_add_subroutine (&c
->attr
, c
->name
, &c
->loc
);
13061 /* Procedure pointer components: Check PASS arg. */
13062 if (c
->attr
.proc_pointer
&& !c
->tb
->nopass
&& c
->tb
->pass_arg_num
== 0
13063 && !sym
->attr
.vtype
)
13065 gfc_symbol
* me_arg
;
13067 if (c
->tb
->pass_arg
)
13069 gfc_formal_arglist
* i
;
13071 /* If an explicit passing argument name is given, walk the arg-list
13072 and look for it. */
13075 c
->tb
->pass_arg_num
= 1;
13076 for (i
= c
->ts
.interface
->formal
; i
; i
= i
->next
)
13078 if (!strcmp (i
->sym
->name
, c
->tb
->pass_arg
))
13083 c
->tb
->pass_arg_num
++;
13088 gfc_error ("Procedure pointer component %qs with PASS(%s) "
13089 "at %L has no argument %qs", c
->name
,
13090 c
->tb
->pass_arg
, &c
->loc
, c
->tb
->pass_arg
);
13097 /* Otherwise, take the first one; there should in fact be at least
13099 c
->tb
->pass_arg_num
= 1;
13100 if (!c
->ts
.interface
->formal
)
13102 gfc_error ("Procedure pointer component %qs with PASS at %L "
13103 "must have at least one argument",
13108 me_arg
= c
->ts
.interface
->formal
->sym
;
13111 /* Now check that the argument-type matches. */
13112 gcc_assert (me_arg
);
13113 if ((me_arg
->ts
.type
!= BT_DERIVED
&& me_arg
->ts
.type
!= BT_CLASS
)
13114 || (me_arg
->ts
.type
== BT_DERIVED
&& me_arg
->ts
.u
.derived
!= sym
)
13115 || (me_arg
->ts
.type
== BT_CLASS
13116 && CLASS_DATA (me_arg
)->ts
.u
.derived
!= sym
))
13118 gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of"
13119 " the derived type %qs", me_arg
->name
, c
->name
,
13120 me_arg
->name
, &c
->loc
, sym
->name
);
13125 /* Check for C453. */
13126 if (me_arg
->attr
.dimension
)
13128 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
13129 "must be scalar", me_arg
->name
, c
->name
, me_arg
->name
,
13135 if (me_arg
->attr
.pointer
)
13137 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
13138 "may not have the POINTER attribute", me_arg
->name
,
13139 c
->name
, me_arg
->name
, &c
->loc
);
13144 if (me_arg
->attr
.allocatable
)
13146 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
13147 "may not be ALLOCATABLE", me_arg
->name
, c
->name
,
13148 me_arg
->name
, &c
->loc
);
13153 if (gfc_type_is_extensible (sym
) && me_arg
->ts
.type
!= BT_CLASS
)
13155 gfc_error ("Non-polymorphic passed-object dummy argument of %qs"
13156 " at %L", c
->name
, &c
->loc
);
13162 /* Check type-spec if this is not the parent-type component. */
13163 if (((sym
->attr
.is_class
13164 && (!sym
->components
->ts
.u
.derived
->attr
.extension
13165 || c
!= sym
->components
->ts
.u
.derived
->components
))
13166 || (!sym
->attr
.is_class
13167 && (!sym
->attr
.extension
|| c
!= sym
->components
)))
13168 && !sym
->attr
.vtype
13169 && !resolve_typespec_used (&c
->ts
, &c
->loc
, c
->name
))
13172 super_type
= gfc_get_derived_super_type (sym
);
13174 /* If this type is an extension, set the accessibility of the parent
13177 && ((sym
->attr
.is_class
13178 && c
== sym
->components
->ts
.u
.derived
->components
)
13179 || (!sym
->attr
.is_class
&& c
== sym
->components
))
13180 && strcmp (super_type
->name
, c
->name
) == 0)
13181 c
->attr
.access
= super_type
->attr
.access
;
13183 /* If this type is an extension, see if this component has the same name
13184 as an inherited type-bound procedure. */
13185 if (super_type
&& !sym
->attr
.is_class
13186 && gfc_find_typebound_proc (super_type
, NULL
, c
->name
, true, NULL
))
13188 gfc_error ("Component %qs of %qs at %L has the same name as an"
13189 " inherited type-bound procedure",
13190 c
->name
, sym
->name
, &c
->loc
);
13194 if (c
->ts
.type
== BT_CHARACTER
&& !c
->attr
.proc_pointer
13195 && !c
->ts
.deferred
)
13197 if (c
->ts
.u
.cl
->length
== NULL
13198 || (!resolve_charlen(c
->ts
.u
.cl
))
13199 || !gfc_is_constant_expr (c
->ts
.u
.cl
->length
))
13201 gfc_error ("Character length of component %qs needs to "
13202 "be a constant specification expression at %L",
13204 c
->ts
.u
.cl
->length
? &c
->ts
.u
.cl
->length
->where
: &c
->loc
);
13209 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
13210 && !c
->attr
.pointer
&& !c
->attr
.allocatable
)
13212 gfc_error ("Character component %qs of %qs at %L with deferred "
13213 "length must be a POINTER or ALLOCATABLE",
13214 c
->name
, sym
->name
, &c
->loc
);
13218 /* Add the hidden deferred length field. */
13219 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
&& !c
->attr
.function
13220 && !sym
->attr
.is_class
)
13222 char name
[GFC_MAX_SYMBOL_LEN
+9];
13223 gfc_component
*strlen
;
13224 sprintf (name
, "_%s_length", c
->name
);
13225 strlen
= gfc_find_component (sym
, name
, true, true, NULL
);
13226 if (strlen
== NULL
)
13228 if (!gfc_add_component (sym
, name
, &strlen
))
13230 strlen
->ts
.type
= BT_INTEGER
;
13231 strlen
->ts
.kind
= gfc_charlen_int_kind
;
13232 strlen
->attr
.access
= ACCESS_PRIVATE
;
13233 strlen
->attr
.artificial
= 1;
13237 if (c
->ts
.type
== BT_DERIVED
13238 && sym
->component_access
!= ACCESS_PRIVATE
13239 && gfc_check_symbol_access (sym
)
13240 && !is_sym_host_assoc (c
->ts
.u
.derived
, sym
->ns
)
13241 && !c
->ts
.u
.derived
->attr
.use_assoc
13242 && !gfc_check_symbol_access (c
->ts
.u
.derived
)
13243 && !gfc_notify_std (GFC_STD_F2003
, "the component %qs is a "
13244 "PRIVATE type and cannot be a component of "
13245 "%qs, which is PUBLIC at %L", c
->name
,
13246 sym
->name
, &sym
->declared_at
))
13249 if ((sym
->attr
.sequence
|| sym
->attr
.is_bind_c
) && c
->ts
.type
== BT_CLASS
)
13251 gfc_error ("Polymorphic component %s at %L in SEQUENCE or BIND(C) "
13252 "type %s", c
->name
, &c
->loc
, sym
->name
);
13256 if (sym
->attr
.sequence
)
13258 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.sequence
== 0)
13260 gfc_error ("Component %s of SEQUENCE type declared at %L does "
13261 "not have the SEQUENCE attribute",
13262 c
->ts
.u
.derived
->name
, &sym
->declared_at
);
13267 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.generic
)
13268 c
->ts
.u
.derived
= gfc_find_dt_in_generic (c
->ts
.u
.derived
);
13269 else if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
13270 && CLASS_DATA (c
)->ts
.u
.derived
->attr
.generic
)
13271 CLASS_DATA (c
)->ts
.u
.derived
13272 = gfc_find_dt_in_generic (CLASS_DATA (c
)->ts
.u
.derived
);
13274 if (!sym
->attr
.is_class
&& c
->ts
.type
== BT_DERIVED
&& !sym
->attr
.vtype
13275 && c
->attr
.pointer
&& c
->ts
.u
.derived
->components
== NULL
13276 && !c
->ts
.u
.derived
->attr
.zero_comp
)
13278 gfc_error ("The pointer component %qs of %qs at %L is a type "
13279 "that has not been declared", c
->name
, sym
->name
,
13284 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
13285 && CLASS_DATA (c
)->attr
.class_pointer
13286 && CLASS_DATA (c
)->ts
.u
.derived
->components
== NULL
13287 && !CLASS_DATA (c
)->ts
.u
.derived
->attr
.zero_comp
13288 && !UNLIMITED_POLY (c
))
13290 gfc_error ("The pointer component %qs of %qs at %L is a type "
13291 "that has not been declared", c
->name
, sym
->name
,
13297 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.flavor
!= FL_PROCEDURE
13298 && (!c
->attr
.class_ok
13299 || !(CLASS_DATA (c
)->attr
.class_pointer
13300 || CLASS_DATA (c
)->attr
.allocatable
)))
13302 gfc_error ("Component %qs with CLASS at %L must be allocatable "
13303 "or pointer", c
->name
, &c
->loc
);
13304 /* Prevent a recurrence of the error. */
13305 c
->ts
.type
= BT_UNKNOWN
;
13309 /* Ensure that all the derived type components are put on the
13310 derived type list; even in formal namespaces, where derived type
13311 pointer components might not have been declared. */
13312 if (c
->ts
.type
== BT_DERIVED
13314 && c
->ts
.u
.derived
->components
13316 && sym
!= c
->ts
.u
.derived
)
13317 add_dt_to_dt_list (c
->ts
.u
.derived
);
13319 if (!gfc_resolve_array_spec (c
->as
,
13320 !(c
->attr
.pointer
|| c
->attr
.proc_pointer
13321 || c
->attr
.allocatable
)))
13324 if (c
->initializer
&& !sym
->attr
.vtype
13325 && !gfc_check_assign_symbol (sym
, c
, c
->initializer
))
13332 /* Be nice about the locus for a structure expression - show the locus of the
13333 first non-null sub-expression if we can. */
13336 cons_where (gfc_expr
*struct_expr
)
13338 gfc_constructor
*cons
;
13340 gcc_assert (struct_expr
&& struct_expr
->expr_type
== EXPR_STRUCTURE
);
13342 cons
= gfc_constructor_first (struct_expr
->value
.constructor
);
13343 for (; cons
; cons
= gfc_constructor_next (cons
))
13345 if (cons
->expr
&& cons
->expr
->expr_type
!= EXPR_NULL
)
13346 return &cons
->expr
->where
;
13349 return &struct_expr
->where
;
13352 /* Resolve the components of a structure type. Much less work than derived
13356 resolve_fl_struct (gfc_symbol
*sym
)
13359 gfc_expr
*init
= NULL
;
13362 /* Make sure UNIONs do not have overlapping initializers. */
13363 if (sym
->attr
.flavor
== FL_UNION
)
13365 for (c
= sym
->components
; c
; c
= c
->next
)
13367 if (init
&& c
->initializer
)
13369 gfc_error ("Conflicting initializers in union at %L and %L",
13370 cons_where (init
), cons_where (c
->initializer
));
13371 gfc_free_expr (c
->initializer
);
13372 c
->initializer
= NULL
;
13375 init
= c
->initializer
;
13380 for (c
= sym
->components
; c
; c
= c
->next
)
13381 if (!resolve_component (c
, sym
))
13387 if (sym
->components
)
13388 add_dt_to_dt_list (sym
);
13394 /* Resolve the components of a derived type. This does not have to wait until
13395 resolution stage, but can be done as soon as the dt declaration has been
13399 resolve_fl_derived0 (gfc_symbol
*sym
)
13401 gfc_symbol
* super_type
;
13405 if (sym
->attr
.unlimited_polymorphic
)
13408 super_type
= gfc_get_derived_super_type (sym
);
13411 if (super_type
&& sym
->attr
.coarray_comp
&& !super_type
->attr
.coarray_comp
)
13413 gfc_error ("As extending type %qs at %L has a coarray component, "
13414 "parent type %qs shall also have one", sym
->name
,
13415 &sym
->declared_at
, super_type
->name
);
13419 /* Ensure the extended type gets resolved before we do. */
13420 if (super_type
&& !resolve_fl_derived0 (super_type
))
13423 /* An ABSTRACT type must be extensible. */
13424 if (sym
->attr
.abstract
&& !gfc_type_is_extensible (sym
))
13426 gfc_error ("Non-extensible derived-type %qs at %L must not be ABSTRACT",
13427 sym
->name
, &sym
->declared_at
);
13431 c
= (sym
->attr
.is_class
) ? sym
->components
->ts
.u
.derived
->components
13435 for ( ; c
!= NULL
; c
= c
->next
)
13436 if (!resolve_component (c
, sym
))
13442 check_defined_assignments (sym
);
13444 if (!sym
->attr
.defined_assign_comp
&& super_type
)
13445 sym
->attr
.defined_assign_comp
13446 = super_type
->attr
.defined_assign_comp
;
13448 /* If this is a non-ABSTRACT type extending an ABSTRACT one, ensure that
13449 all DEFERRED bindings are overridden. */
13450 if (super_type
&& super_type
->attr
.abstract
&& !sym
->attr
.abstract
13451 && !sym
->attr
.is_class
13452 && !ensure_not_abstract (sym
, super_type
))
13455 /* Add derived type to the derived type list. */
13456 add_dt_to_dt_list (sym
);
13462 /* The following procedure does the full resolution of a derived type,
13463 including resolution of all type-bound procedures (if present). In contrast
13464 to 'resolve_fl_derived0' this can only be done after the module has been
13465 parsed completely. */
13468 resolve_fl_derived (gfc_symbol
*sym
)
13470 gfc_symbol
*gen_dt
= NULL
;
13472 if (sym
->attr
.unlimited_polymorphic
)
13475 if (!sym
->attr
.is_class
)
13476 gfc_find_symbol (sym
->name
, sym
->ns
, 0, &gen_dt
);
13477 if (gen_dt
&& gen_dt
->generic
&& gen_dt
->generic
->next
13478 && (!gen_dt
->generic
->sym
->attr
.use_assoc
13479 || gen_dt
->generic
->sym
->module
!= gen_dt
->generic
->next
->sym
->module
)
13480 && !gfc_notify_std (GFC_STD_F2003
, "Generic name %qs of function "
13481 "%qs at %L being the same name as derived "
13482 "type at %L", sym
->name
,
13483 gen_dt
->generic
->sym
== sym
13484 ? gen_dt
->generic
->next
->sym
->name
13485 : gen_dt
->generic
->sym
->name
,
13486 gen_dt
->generic
->sym
== sym
13487 ? &gen_dt
->generic
->next
->sym
->declared_at
13488 : &gen_dt
->generic
->sym
->declared_at
,
13489 &sym
->declared_at
))
13492 /* Resolve the finalizer procedures. */
13493 if (!gfc_resolve_finalizers (sym
, NULL
))
13496 if (sym
->attr
.is_class
&& sym
->ts
.u
.derived
== NULL
)
13498 /* Fix up incomplete CLASS symbols. */
13499 gfc_component
*data
= gfc_find_component (sym
, "_data", true, true, NULL
);
13500 gfc_component
*vptr
= gfc_find_component (sym
, "_vptr", true, true, NULL
);
13502 /* Nothing more to do for unlimited polymorphic entities. */
13503 if (data
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
13505 else if (vptr
->ts
.u
.derived
== NULL
)
13507 gfc_symbol
*vtab
= gfc_find_derived_vtab (data
->ts
.u
.derived
);
13509 vptr
->ts
.u
.derived
= vtab
->ts
.u
.derived
;
13513 if (!resolve_fl_derived0 (sym
))
13516 /* Resolve the type-bound procedures. */
13517 if (!resolve_typebound_procedures (sym
))
13525 resolve_fl_namelist (gfc_symbol
*sym
)
13530 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
13532 /* Check again, the check in match only works if NAMELIST comes
13534 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SIZE
)
13536 gfc_error ("Assumed size array %qs in namelist %qs at %L is not "
13537 "allowed", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13541 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SHAPE
13542 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object %qs "
13543 "with assumed shape in namelist %qs at %L",
13544 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
13547 if (is_non_constant_shape_array (nl
->sym
)
13548 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object %qs "
13549 "with nonconstant shape in namelist %qs at %L",
13550 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
13553 if (nl
->sym
->ts
.type
== BT_CHARACTER
13554 && (nl
->sym
->ts
.u
.cl
->length
== NULL
13555 || !gfc_is_constant_expr (nl
->sym
->ts
.u
.cl
->length
))
13556 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST object %qs with "
13557 "nonconstant character length in "
13558 "namelist %qs at %L", nl
->sym
->name
,
13559 sym
->name
, &sym
->declared_at
))
13562 /* FIXME: Once UDDTIO is implemented, the following can be
13564 if (nl
->sym
->ts
.type
== BT_CLASS
)
13566 gfc_error ("NAMELIST object %qs in namelist %qs at %L is "
13567 "polymorphic and requires a defined input/output "
13568 "procedure", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13572 if (nl
->sym
->ts
.type
== BT_DERIVED
13573 && (nl
->sym
->ts
.u
.derived
->attr
.alloc_comp
13574 || nl
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
13576 if (!gfc_notify_std (GFC_STD_F2003
, "NAMELIST object %qs in "
13577 "namelist %qs at %L with ALLOCATABLE "
13578 "or POINTER components", nl
->sym
->name
,
13579 sym
->name
, &sym
->declared_at
))
13582 /* FIXME: Once UDDTIO is implemented, the following can be
13584 gfc_error ("NAMELIST object %qs in namelist %qs at %L has "
13585 "ALLOCATABLE or POINTER components and thus requires "
13586 "a defined input/output procedure", nl
->sym
->name
,
13587 sym
->name
, &sym
->declared_at
);
13592 /* Reject PRIVATE objects in a PUBLIC namelist. */
13593 if (gfc_check_symbol_access (sym
))
13595 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
13597 if (!nl
->sym
->attr
.use_assoc
13598 && !is_sym_host_assoc (nl
->sym
, sym
->ns
)
13599 && !gfc_check_symbol_access (nl
->sym
))
13601 gfc_error ("NAMELIST object %qs was declared PRIVATE and "
13602 "cannot be member of PUBLIC namelist %qs at %L",
13603 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13607 /* Types with private components that came here by USE-association. */
13608 if (nl
->sym
->ts
.type
== BT_DERIVED
13609 && derived_inaccessible (nl
->sym
->ts
.u
.derived
))
13611 gfc_error ("NAMELIST object %qs has use-associated PRIVATE "
13612 "components and cannot be member of namelist %qs at %L",
13613 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13617 /* Types with private components that are defined in the same module. */
13618 if (nl
->sym
->ts
.type
== BT_DERIVED
13619 && !is_sym_host_assoc (nl
->sym
->ts
.u
.derived
, sym
->ns
)
13620 && nl
->sym
->ts
.u
.derived
->attr
.private_comp
)
13622 gfc_error ("NAMELIST object %qs has PRIVATE components and "
13623 "cannot be a member of PUBLIC namelist %qs at %L",
13624 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13631 /* 14.1.2 A module or internal procedure represent local entities
13632 of the same type as a namelist member and so are not allowed. */
13633 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
13635 if (nl
->sym
->ts
.kind
!= 0 && nl
->sym
->attr
.flavor
== FL_VARIABLE
)
13638 if (nl
->sym
->attr
.function
&& nl
->sym
== nl
->sym
->result
)
13639 if ((nl
->sym
== sym
->ns
->proc_name
)
13641 (sym
->ns
->parent
&& nl
->sym
== sym
->ns
->parent
->proc_name
))
13646 gfc_find_symbol (nl
->sym
->name
, sym
->ns
, 1, &nlsym
);
13647 if (nlsym
&& nlsym
->attr
.flavor
== FL_PROCEDURE
)
13649 gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
13650 "attribute in %qs at %L", nlsym
->name
,
13651 &sym
->declared_at
);
13661 resolve_fl_parameter (gfc_symbol
*sym
)
13663 /* A parameter array's shape needs to be constant. */
13664 if (sym
->as
!= NULL
13665 && (sym
->as
->type
== AS_DEFERRED
13666 || is_non_constant_shape_array (sym
)))
13668 gfc_error ("Parameter array %qs at %L cannot be automatic "
13669 "or of deferred shape", sym
->name
, &sym
->declared_at
);
13673 /* Make sure a parameter that has been implicitly typed still
13674 matches the implicit type, since PARAMETER statements can precede
13675 IMPLICIT statements. */
13676 if (sym
->attr
.implicit_type
13677 && !gfc_compare_types (&sym
->ts
, gfc_get_default_type (sym
->name
,
13680 gfc_error ("Implicitly typed PARAMETER %qs at %L doesn't match a "
13681 "later IMPLICIT type", sym
->name
, &sym
->declared_at
);
13685 /* Make sure the types of derived parameters are consistent. This
13686 type checking is deferred until resolution because the type may
13687 refer to a derived type from the host. */
13688 if (sym
->ts
.type
== BT_DERIVED
13689 && !gfc_compare_types (&sym
->ts
, &sym
->value
->ts
))
13691 gfc_error ("Incompatible derived type in PARAMETER at %L",
13692 &sym
->value
->where
);
13699 /* Do anything necessary to resolve a symbol. Right now, we just
13700 assume that an otherwise unknown symbol is a variable. This sort
13701 of thing commonly happens for symbols in module. */
13704 resolve_symbol (gfc_symbol
*sym
)
13706 int check_constant
, mp_flag
;
13707 gfc_symtree
*symtree
;
13708 gfc_symtree
*this_symtree
;
13711 symbol_attribute class_attr
;
13712 gfc_array_spec
*as
;
13713 bool saved_specification_expr
;
13719 /* No symbol will ever have union type; only components can be unions.
13720 Union type declaration symbols have type BT_UNKNOWN but flavor FL_UNION
13721 (just like derived type declaration symbols have flavor FL_DERIVED). */
13722 gcc_assert (sym
->ts
.type
!= BT_UNION
);
13724 if (sym
->attr
.artificial
)
13727 if (sym
->attr
.unlimited_polymorphic
)
13730 if (sym
->attr
.flavor
== FL_UNKNOWN
13731 || (sym
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.intrinsic
13732 && !sym
->attr
.generic
&& !sym
->attr
.external
13733 && sym
->attr
.if_source
== IFSRC_UNKNOWN
13734 && sym
->ts
.type
== BT_UNKNOWN
))
13737 /* If we find that a flavorless symbol is an interface in one of the
13738 parent namespaces, find its symtree in this namespace, free the
13739 symbol and set the symtree to point to the interface symbol. */
13740 for (ns
= gfc_current_ns
->parent
; ns
; ns
= ns
->parent
)
13742 symtree
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
13743 if (symtree
&& (symtree
->n
.sym
->generic
||
13744 (symtree
->n
.sym
->attr
.flavor
== FL_PROCEDURE
13745 && sym
->ns
->construct_entities
)))
13747 this_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
13749 if (this_symtree
->n
.sym
== sym
)
13751 symtree
->n
.sym
->refs
++;
13752 gfc_release_symbol (sym
);
13753 this_symtree
->n
.sym
= symtree
->n
.sym
;
13759 /* Otherwise give it a flavor according to such attributes as
13761 if (sym
->attr
.flavor
== FL_UNKNOWN
&& sym
->attr
.external
== 0
13762 && sym
->attr
.intrinsic
== 0)
13763 sym
->attr
.flavor
= FL_VARIABLE
;
13764 else if (sym
->attr
.flavor
== FL_UNKNOWN
)
13766 sym
->attr
.flavor
= FL_PROCEDURE
;
13767 if (sym
->attr
.dimension
)
13768 sym
->attr
.function
= 1;
13772 if (sym
->attr
.external
&& sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.function
)
13773 gfc_add_function (&sym
->attr
, sym
->name
, &sym
->declared_at
);
13775 if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
13776 && !resolve_procedure_interface (sym
))
13779 if (sym
->attr
.is_protected
&& !sym
->attr
.proc_pointer
13780 && (sym
->attr
.procedure
|| sym
->attr
.external
))
13782 if (sym
->attr
.external
)
13783 gfc_error ("PROTECTED attribute conflicts with EXTERNAL attribute "
13784 "at %L", &sym
->declared_at
);
13786 gfc_error ("PROCEDURE attribute conflicts with PROTECTED attribute "
13787 "at %L", &sym
->declared_at
);
13792 if (sym
->attr
.flavor
== FL_DERIVED
&& !resolve_fl_derived (sym
))
13795 else if ((sym
->attr
.flavor
== FL_STRUCT
|| sym
->attr
.flavor
== FL_UNION
)
13796 && !resolve_fl_struct (sym
))
13799 /* Symbols that are module procedures with results (functions) have
13800 the types and array specification copied for type checking in
13801 procedures that call them, as well as for saving to a module
13802 file. These symbols can't stand the scrutiny that their results
13804 mp_flag
= (sym
->result
!= NULL
&& sym
->result
!= sym
);
13806 /* Make sure that the intrinsic is consistent with its internal
13807 representation. This needs to be done before assigning a default
13808 type to avoid spurious warnings. */
13809 if (sym
->attr
.flavor
!= FL_MODULE
&& sym
->attr
.intrinsic
13810 && !gfc_resolve_intrinsic (sym
, &sym
->declared_at
))
13813 /* Resolve associate names. */
13815 resolve_assoc_var (sym
, true);
13817 /* Assign default type to symbols that need one and don't have one. */
13818 if (sym
->ts
.type
== BT_UNKNOWN
)
13820 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
)
13822 gfc_set_default_type (sym
, 1, NULL
);
13825 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.external
13826 && !sym
->attr
.function
&& !sym
->attr
.subroutine
13827 && gfc_get_default_type (sym
->name
, sym
->ns
)->type
== BT_UNKNOWN
)
13828 gfc_add_subroutine (&sym
->attr
, sym
->name
, &sym
->declared_at
);
13830 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
13832 /* The specific case of an external procedure should emit an error
13833 in the case that there is no implicit type. */
13835 gfc_set_default_type (sym
, sym
->attr
.external
, NULL
);
13838 /* Result may be in another namespace. */
13839 resolve_symbol (sym
->result
);
13841 if (!sym
->result
->attr
.proc_pointer
)
13843 sym
->ts
= sym
->result
->ts
;
13844 sym
->as
= gfc_copy_array_spec (sym
->result
->as
);
13845 sym
->attr
.dimension
= sym
->result
->attr
.dimension
;
13846 sym
->attr
.pointer
= sym
->result
->attr
.pointer
;
13847 sym
->attr
.allocatable
= sym
->result
->attr
.allocatable
;
13848 sym
->attr
.contiguous
= sym
->result
->attr
.contiguous
;
13853 else if (mp_flag
&& sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
13855 bool saved_specification_expr
= specification_expr
;
13856 specification_expr
= true;
13857 gfc_resolve_array_spec (sym
->result
->as
, false);
13858 specification_expr
= saved_specification_expr
;
13861 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
13863 as
= CLASS_DATA (sym
)->as
;
13864 class_attr
= CLASS_DATA (sym
)->attr
;
13865 class_attr
.pointer
= class_attr
.class_pointer
;
13869 class_attr
= sym
->attr
;
13874 if (sym
->attr
.contiguous
13875 && (!class_attr
.dimension
13876 || (as
->type
!= AS_ASSUMED_SHAPE
&& as
->type
!= AS_ASSUMED_RANK
13877 && !class_attr
.pointer
)))
13879 gfc_error ("%qs at %L has the CONTIGUOUS attribute but is not an "
13880 "array pointer or an assumed-shape or assumed-rank array",
13881 sym
->name
, &sym
->declared_at
);
13885 /* Assumed size arrays and assumed shape arrays must be dummy
13886 arguments. Array-spec's of implied-shape should have been resolved to
13887 AS_EXPLICIT already. */
13891 gcc_assert (as
->type
!= AS_IMPLIED_SHAPE
);
13892 if (((as
->type
== AS_ASSUMED_SIZE
&& !as
->cp_was_assumed
)
13893 || as
->type
== AS_ASSUMED_SHAPE
)
13894 && !sym
->attr
.dummy
&& !sym
->attr
.select_type_temporary
)
13896 if (as
->type
== AS_ASSUMED_SIZE
)
13897 gfc_error ("Assumed size array at %L must be a dummy argument",
13898 &sym
->declared_at
);
13900 gfc_error ("Assumed shape array at %L must be a dummy argument",
13901 &sym
->declared_at
);
13904 /* TS 29113, C535a. */
13905 if (as
->type
== AS_ASSUMED_RANK
&& !sym
->attr
.dummy
13906 && !sym
->attr
.select_type_temporary
)
13908 gfc_error ("Assumed-rank array at %L must be a dummy argument",
13909 &sym
->declared_at
);
13912 if (as
->type
== AS_ASSUMED_RANK
13913 && (sym
->attr
.codimension
|| sym
->attr
.value
))
13915 gfc_error ("Assumed-rank array at %L may not have the VALUE or "
13916 "CODIMENSION attribute", &sym
->declared_at
);
13921 /* Make sure symbols with known intent or optional are really dummy
13922 variable. Because of ENTRY statement, this has to be deferred
13923 until resolution time. */
13925 if (!sym
->attr
.dummy
13926 && (sym
->attr
.optional
|| sym
->attr
.intent
!= INTENT_UNKNOWN
))
13928 gfc_error ("Symbol at %L is not a DUMMY variable", &sym
->declared_at
);
13932 if (sym
->attr
.value
&& !sym
->attr
.dummy
)
13934 gfc_error ("%qs at %L cannot have the VALUE attribute because "
13935 "it is not a dummy argument", sym
->name
, &sym
->declared_at
);
13939 if (sym
->attr
.value
&& sym
->ts
.type
== BT_CHARACTER
)
13941 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
13942 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
13944 gfc_error ("Character dummy variable %qs at %L with VALUE "
13945 "attribute must have constant length",
13946 sym
->name
, &sym
->declared_at
);
13950 if (sym
->ts
.is_c_interop
13951 && mpz_cmp_si (cl
->length
->value
.integer
, 1) != 0)
13953 gfc_error ("C interoperable character dummy variable %qs at %L "
13954 "with VALUE attribute must have length one",
13955 sym
->name
, &sym
->declared_at
);
13960 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
13961 && sym
->ts
.u
.derived
->attr
.generic
)
13963 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
13964 if (!sym
->ts
.u
.derived
)
13966 gfc_error ("The derived type %qs at %L is of type %qs, "
13967 "which has not been defined", sym
->name
,
13968 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
13969 sym
->ts
.type
= BT_UNKNOWN
;
13974 /* Use the same constraints as TYPE(*), except for the type check
13975 and that only scalars and assumed-size arrays are permitted. */
13976 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
13978 if (!sym
->attr
.dummy
)
13980 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
13981 "a dummy argument", sym
->name
, &sym
->declared_at
);
13985 if (sym
->ts
.type
!= BT_ASSUMED
&& sym
->ts
.type
!= BT_INTEGER
13986 && sym
->ts
.type
!= BT_REAL
&& sym
->ts
.type
!= BT_LOGICAL
13987 && sym
->ts
.type
!= BT_COMPLEX
)
13989 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
13990 "of type TYPE(*) or of an numeric intrinsic type",
13991 sym
->name
, &sym
->declared_at
);
13995 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
13996 || sym
->attr
.pointer
|| sym
->attr
.value
)
13998 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
13999 "have the ALLOCATABLE, CODIMENSION, POINTER or VALUE "
14000 "attribute", sym
->name
, &sym
->declared_at
);
14004 if (sym
->attr
.intent
== INTENT_OUT
)
14006 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
14007 "have the INTENT(OUT) attribute",
14008 sym
->name
, &sym
->declared_at
);
14011 if (sym
->attr
.dimension
&& sym
->as
->type
!= AS_ASSUMED_SIZE
)
14013 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall "
14014 "either be a scalar or an assumed-size array",
14015 sym
->name
, &sym
->declared_at
);
14019 /* Set the type to TYPE(*) and add a dimension(*) to ensure
14020 NO_ARG_CHECK is correctly handled in trans*.c, e.g. with
14022 sym
->ts
.type
= BT_ASSUMED
;
14023 sym
->as
= gfc_get_array_spec ();
14024 sym
->as
->type
= AS_ASSUMED_SIZE
;
14026 sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
14028 else if (sym
->ts
.type
== BT_ASSUMED
)
14030 /* TS 29113, C407a. */
14031 if (!sym
->attr
.dummy
)
14033 gfc_error ("Assumed type of variable %s at %L is only permitted "
14034 "for dummy variables", sym
->name
, &sym
->declared_at
);
14037 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
14038 || sym
->attr
.pointer
|| sym
->attr
.value
)
14040 gfc_error ("Assumed-type variable %s at %L may not have the "
14041 "ALLOCATABLE, CODIMENSION, POINTER or VALUE attribute",
14042 sym
->name
, &sym
->declared_at
);
14045 if (sym
->attr
.intent
== INTENT_OUT
)
14047 gfc_error ("Assumed-type variable %s at %L may not have the "
14048 "INTENT(OUT) attribute",
14049 sym
->name
, &sym
->declared_at
);
14052 if (sym
->attr
.dimension
&& sym
->as
->type
== AS_EXPLICIT
)
14054 gfc_error ("Assumed-type variable %s at %L shall not be an "
14055 "explicit-shape array", sym
->name
, &sym
->declared_at
);
14060 /* If the symbol is marked as bind(c), verify it's type and kind. Do not
14061 do this for something that was implicitly typed because that is handled
14062 in gfc_set_default_type. Handle dummy arguments and procedure
14063 definitions separately. Also, anything that is use associated is not
14064 handled here but instead is handled in the module it is declared in.
14065 Finally, derived type definitions are allowed to be BIND(C) since that
14066 only implies that they're interoperable, and they are checked fully for
14067 interoperability when a variable is declared of that type. */
14068 if (sym
->attr
.is_bind_c
&& sym
->attr
.implicit_type
== 0 &&
14069 sym
->attr
.use_assoc
== 0 && sym
->attr
.dummy
== 0 &&
14070 sym
->attr
.flavor
!= FL_PROCEDURE
&& sym
->attr
.flavor
!= FL_DERIVED
)
14074 /* First, make sure the variable is declared at the
14075 module-level scope (J3/04-007, Section 15.3). */
14076 if (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
&&
14077 sym
->attr
.in_common
== 0)
14079 gfc_error ("Variable %qs at %L cannot be BIND(C) because it "
14080 "is neither a COMMON block nor declared at the "
14081 "module level scope", sym
->name
, &(sym
->declared_at
));
14084 else if (sym
->common_head
!= NULL
)
14086 t
= verify_com_block_vars_c_interop (sym
->common_head
);
14090 /* If type() declaration, we need to verify that the components
14091 of the given type are all C interoperable, etc. */
14092 if (sym
->ts
.type
== BT_DERIVED
&&
14093 sym
->ts
.u
.derived
->attr
.is_c_interop
!= 1)
14095 /* Make sure the user marked the derived type as BIND(C). If
14096 not, call the verify routine. This could print an error
14097 for the derived type more than once if multiple variables
14098 of that type are declared. */
14099 if (sym
->ts
.u
.derived
->attr
.is_bind_c
!= 1)
14100 verify_bind_c_derived_type (sym
->ts
.u
.derived
);
14104 /* Verify the variable itself as C interoperable if it
14105 is BIND(C). It is not possible for this to succeed if
14106 the verify_bind_c_derived_type failed, so don't have to handle
14107 any error returned by verify_bind_c_derived_type. */
14108 t
= verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
14109 sym
->common_block
);
14114 /* clear the is_bind_c flag to prevent reporting errors more than
14115 once if something failed. */
14116 sym
->attr
.is_bind_c
= 0;
14121 /* If a derived type symbol has reached this point, without its
14122 type being declared, we have an error. Notice that most
14123 conditions that produce undefined derived types have already
14124 been dealt with. However, the likes of:
14125 implicit type(t) (t) ..... call foo (t) will get us here if
14126 the type is not declared in the scope of the implicit
14127 statement. Change the type to BT_UNKNOWN, both because it is so
14128 and to prevent an ICE. */
14129 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
14130 && sym
->ts
.u
.derived
->components
== NULL
14131 && !sym
->ts
.u
.derived
->attr
.zero_comp
)
14133 gfc_error ("The derived type %qs at %L is of type %qs, "
14134 "which has not been defined", sym
->name
,
14135 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
14136 sym
->ts
.type
= BT_UNKNOWN
;
14140 /* Make sure that the derived type has been resolved and that the
14141 derived type is visible in the symbol's namespace, if it is a
14142 module function and is not PRIVATE. */
14143 if (sym
->ts
.type
== BT_DERIVED
14144 && sym
->ts
.u
.derived
->attr
.use_assoc
14145 && sym
->ns
->proc_name
14146 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
14147 && !resolve_fl_derived (sym
->ts
.u
.derived
))
14150 /* Unless the derived-type declaration is use associated, Fortran 95
14151 does not allow public entries of private derived types.
14152 See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
14153 161 in 95-006r3. */
14154 if (sym
->ts
.type
== BT_DERIVED
14155 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
14156 && !sym
->ts
.u
.derived
->attr
.use_assoc
14157 && gfc_check_symbol_access (sym
)
14158 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
14159 && !gfc_notify_std (GFC_STD_F2003
, "PUBLIC %s %qs at %L of PRIVATE "
14160 "derived type %qs",
14161 (sym
->attr
.flavor
== FL_PARAMETER
)
14162 ? "parameter" : "variable",
14163 sym
->name
, &sym
->declared_at
,
14164 sym
->ts
.u
.derived
->name
))
14167 /* F2008, C1302. */
14168 if (sym
->ts
.type
== BT_DERIVED
14169 && ((sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
14170 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
14171 || sym
->ts
.u
.derived
->attr
.lock_comp
)
14172 && !sym
->attr
.codimension
&& !sym
->ts
.u
.derived
->attr
.coarray_comp
)
14174 gfc_error ("Variable %s at %L of type LOCK_TYPE or with subcomponent of "
14175 "type LOCK_TYPE must be a coarray", sym
->name
,
14176 &sym
->declared_at
);
14180 /* TS18508, C702/C703. */
14181 if (sym
->ts
.type
== BT_DERIVED
14182 && ((sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
14183 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
14184 || sym
->ts
.u
.derived
->attr
.event_comp
)
14185 && !sym
->attr
.codimension
&& !sym
->ts
.u
.derived
->attr
.coarray_comp
)
14187 gfc_error ("Variable %s at %L of type EVENT_TYPE or with subcomponent of "
14188 "type LOCK_TYPE must be a coarray", sym
->name
,
14189 &sym
->declared_at
);
14193 /* An assumed-size array with INTENT(OUT) shall not be of a type for which
14194 default initialization is defined (5.1.2.4.4). */
14195 if (sym
->ts
.type
== BT_DERIVED
14197 && sym
->attr
.intent
== INTENT_OUT
14199 && sym
->as
->type
== AS_ASSUMED_SIZE
)
14201 for (c
= sym
->ts
.u
.derived
->components
; c
; c
= c
->next
)
14203 if (c
->initializer
)
14205 gfc_error ("The INTENT(OUT) dummy argument %qs at %L is "
14206 "ASSUMED SIZE and so cannot have a default initializer",
14207 sym
->name
, &sym
->declared_at
);
14214 if (sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.dummy
14215 && sym
->attr
.intent
== INTENT_OUT
&& sym
->attr
.lock_comp
)
14217 gfc_error ("Dummy argument %qs at %L of LOCK_TYPE shall not be "
14218 "INTENT(OUT)", sym
->name
, &sym
->declared_at
);
14223 if (sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.dummy
14224 && sym
->attr
.intent
== INTENT_OUT
&& sym
->attr
.event_comp
)
14226 gfc_error ("Dummy argument %qs at %L of EVENT_TYPE shall not be "
14227 "INTENT(OUT)", sym
->name
, &sym
->declared_at
);
14232 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
14233 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
14234 && CLASS_DATA (sym
)->attr
.coarray_comp
))
14235 || class_attr
.codimension
)
14236 && (sym
->attr
.result
|| sym
->result
== sym
))
14238 gfc_error ("Function result %qs at %L shall not be a coarray or have "
14239 "a coarray component", sym
->name
, &sym
->declared_at
);
14244 if (sym
->attr
.codimension
&& sym
->ts
.type
== BT_DERIVED
14245 && sym
->ts
.u
.derived
->ts
.is_iso_c
)
14247 gfc_error ("Variable %qs at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
14248 "shall not be a coarray", sym
->name
, &sym
->declared_at
);
14253 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
14254 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
14255 && CLASS_DATA (sym
)->attr
.coarray_comp
))
14256 && (class_attr
.codimension
|| class_attr
.pointer
|| class_attr
.dimension
14257 || class_attr
.allocatable
))
14259 gfc_error ("Variable %qs at %L with coarray component shall be a "
14260 "nonpointer, nonallocatable scalar, which is not a coarray",
14261 sym
->name
, &sym
->declared_at
);
14265 /* F2008, C526. The function-result case was handled above. */
14266 if (class_attr
.codimension
14267 && !(class_attr
.allocatable
|| sym
->attr
.dummy
|| sym
->attr
.save
14268 || sym
->attr
.select_type_temporary
14269 || sym
->ns
->save_all
14270 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
14271 || sym
->ns
->proc_name
->attr
.is_main_program
14272 || sym
->attr
.function
|| sym
->attr
.result
|| sym
->attr
.use_assoc
))
14274 gfc_error ("Variable %qs at %L is a coarray and is not ALLOCATABLE, SAVE "
14275 "nor a dummy argument", sym
->name
, &sym
->declared_at
);
14279 else if (class_attr
.codimension
&& !sym
->attr
.select_type_temporary
14280 && !class_attr
.allocatable
&& as
&& as
->cotype
== AS_DEFERRED
)
14282 gfc_error ("Coarray variable %qs at %L shall not have codimensions with "
14283 "deferred shape", sym
->name
, &sym
->declared_at
);
14286 else if (class_attr
.codimension
&& class_attr
.allocatable
&& as
14287 && (as
->cotype
!= AS_DEFERRED
|| as
->type
!= AS_DEFERRED
))
14289 gfc_error ("Allocatable coarray variable %qs at %L must have "
14290 "deferred shape", sym
->name
, &sym
->declared_at
);
14295 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
14296 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
14297 && CLASS_DATA (sym
)->attr
.coarray_comp
))
14298 || (class_attr
.codimension
&& class_attr
.allocatable
))
14299 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
)
14301 gfc_error ("Variable %qs at %L is INTENT(OUT) and can thus not be an "
14302 "allocatable coarray or have coarray components",
14303 sym
->name
, &sym
->declared_at
);
14307 if (class_attr
.codimension
&& sym
->attr
.dummy
14308 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.is_bind_c
)
14310 gfc_error ("Coarray dummy variable %qs at %L not allowed in BIND(C) "
14311 "procedure %qs", sym
->name
, &sym
->declared_at
,
14312 sym
->ns
->proc_name
->name
);
14316 if (sym
->ts
.type
== BT_LOGICAL
14317 && ((sym
->attr
.function
&& sym
->attr
.is_bind_c
&& sym
->result
== sym
)
14318 || ((sym
->attr
.dummy
|| sym
->attr
.result
) && sym
->ns
->proc_name
14319 && sym
->ns
->proc_name
->attr
.is_bind_c
)))
14322 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
14323 if (gfc_logical_kinds
[i
].kind
== sym
->ts
.kind
)
14325 if (!gfc_logical_kinds
[i
].c_bool
&& sym
->attr
.dummy
14326 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL dummy argument %qs at "
14327 "%L with non-C_Bool kind in BIND(C) procedure "
14328 "%qs", sym
->name
, &sym
->declared_at
,
14329 sym
->ns
->proc_name
->name
))
14331 else if (!gfc_logical_kinds
[i
].c_bool
14332 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL result variable "
14333 "%qs at %L with non-C_Bool kind in "
14334 "BIND(C) procedure %qs", sym
->name
,
14336 sym
->attr
.function
? sym
->name
14337 : sym
->ns
->proc_name
->name
))
14341 switch (sym
->attr
.flavor
)
14344 if (!resolve_fl_variable (sym
, mp_flag
))
14349 if (sym
->formal
&& !sym
->formal_ns
)
14351 /* Check that none of the arguments are a namelist. */
14352 gfc_formal_arglist
*formal
= sym
->formal
;
14354 for (; formal
; formal
= formal
->next
)
14355 if (formal
->sym
&& formal
->sym
->attr
.flavor
== FL_NAMELIST
)
14357 gfc_error ("Namelist '%s' can not be an argument to "
14358 "subroutine or function at %L",
14359 formal
->sym
->name
, &sym
->declared_at
);
14364 if (!resolve_fl_procedure (sym
, mp_flag
))
14369 if (!resolve_fl_namelist (sym
))
14374 if (!resolve_fl_parameter (sym
))
14382 /* Resolve array specifier. Check as well some constraints
14383 on COMMON blocks. */
14385 check_constant
= sym
->attr
.in_common
&& !sym
->attr
.pointer
;
14387 /* Set the formal_arg_flag so that check_conflict will not throw
14388 an error for host associated variables in the specification
14389 expression for an array_valued function. */
14390 if (sym
->attr
.function
&& sym
->as
)
14391 formal_arg_flag
= 1;
14393 saved_specification_expr
= specification_expr
;
14394 specification_expr
= true;
14395 gfc_resolve_array_spec (sym
->as
, check_constant
);
14396 specification_expr
= saved_specification_expr
;
14398 formal_arg_flag
= 0;
14400 /* Resolve formal namespaces. */
14401 if (sym
->formal_ns
&& sym
->formal_ns
!= gfc_current_ns
14402 && !sym
->attr
.contained
&& !sym
->attr
.intrinsic
)
14403 gfc_resolve (sym
->formal_ns
);
14405 /* Make sure the formal namespace is present. */
14406 if (sym
->formal
&& !sym
->formal_ns
)
14408 gfc_formal_arglist
*formal
= sym
->formal
;
14409 while (formal
&& !formal
->sym
)
14410 formal
= formal
->next
;
14414 sym
->formal_ns
= formal
->sym
->ns
;
14415 if (sym
->ns
!= formal
->sym
->ns
)
14416 sym
->formal_ns
->refs
++;
14420 /* Check threadprivate restrictions. */
14421 if (sym
->attr
.threadprivate
&& !sym
->attr
.save
&& !sym
->ns
->save_all
14422 && (!sym
->attr
.in_common
14423 && sym
->module
== NULL
14424 && (sym
->ns
->proc_name
== NULL
14425 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
14426 gfc_error ("Threadprivate at %L isn't SAVEd", &sym
->declared_at
);
14428 /* Check omp declare target restrictions. */
14429 if (sym
->attr
.omp_declare_target
14430 && sym
->attr
.flavor
== FL_VARIABLE
14432 && !sym
->ns
->save_all
14433 && (!sym
->attr
.in_common
14434 && sym
->module
== NULL
14435 && (sym
->ns
->proc_name
== NULL
14436 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
14437 gfc_error ("!$OMP DECLARE TARGET variable %qs at %L isn't SAVEd",
14438 sym
->name
, &sym
->declared_at
);
14440 /* If we have come this far we can apply default-initializers, as
14441 described in 14.7.5, to those variables that have not already
14442 been assigned one. */
14443 if (sym
->ts
.type
== BT_DERIVED
14445 && !sym
->attr
.allocatable
14446 && !sym
->attr
.alloc_comp
)
14448 symbol_attribute
*a
= &sym
->attr
;
14450 if ((!a
->save
&& !a
->dummy
&& !a
->pointer
14451 && !a
->in_common
&& !a
->use_assoc
14452 && !a
->result
&& !a
->function
)
14453 || (a
->dummy
&& a
->intent
== INTENT_OUT
&& !a
->pointer
))
14454 apply_default_init (sym
);
14455 else if (a
->function
&& sym
->result
&& a
->access
!= ACCESS_PRIVATE
14456 && (sym
->ts
.u
.derived
->attr
.alloc_comp
14457 || sym
->ts
.u
.derived
->attr
.pointer_comp
))
14458 /* Mark the result symbol to be referenced, when it has allocatable
14460 sym
->result
->attr
.referenced
= 1;
14463 if (sym
->ts
.type
== BT_CLASS
&& sym
->ns
== gfc_current_ns
14464 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
14465 && !CLASS_DATA (sym
)->attr
.class_pointer
14466 && !CLASS_DATA (sym
)->attr
.allocatable
)
14467 apply_default_init (sym
);
14469 /* If this symbol has a type-spec, check it. */
14470 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
14471 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
))
14472 if (!resolve_typespec_used (&sym
->ts
, &sym
->declared_at
, sym
->name
))
14477 /************* Resolve DATA statements *************/
14481 gfc_data_value
*vnode
;
14487 /* Advance the values structure to point to the next value in the data list. */
14490 next_data_value (void)
14492 while (mpz_cmp_ui (values
.left
, 0) == 0)
14495 if (values
.vnode
->next
== NULL
)
14498 values
.vnode
= values
.vnode
->next
;
14499 mpz_set (values
.left
, values
.vnode
->repeat
);
14507 check_data_variable (gfc_data_variable
*var
, locus
*where
)
14513 ar_type mark
= AR_UNKNOWN
;
14515 mpz_t section_index
[GFC_MAX_DIMENSIONS
];
14521 if (!gfc_resolve_expr (var
->expr
))
14525 mpz_init_set_si (offset
, 0);
14528 if (e
->expr_type
== EXPR_FUNCTION
&& e
->value
.function
.isym
14529 && e
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
14530 e
= e
->value
.function
.actual
->expr
;
14532 if (e
->expr_type
!= EXPR_VARIABLE
)
14533 gfc_internal_error ("check_data_variable(): Bad expression");
14535 sym
= e
->symtree
->n
.sym
;
14537 if (sym
->ns
->is_block_data
&& !sym
->attr
.in_common
)
14539 gfc_error ("BLOCK DATA element %qs at %L must be in COMMON",
14540 sym
->name
, &sym
->declared_at
);
14543 if (e
->ref
== NULL
&& sym
->as
)
14545 gfc_error ("DATA array %qs at %L must be specified in a previous"
14546 " declaration", sym
->name
, where
);
14550 has_pointer
= sym
->attr
.pointer
;
14552 if (gfc_is_coindexed (e
))
14554 gfc_error ("DATA element %qs at %L cannot have a coindex", sym
->name
,
14559 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
14561 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.pointer
)
14565 && ref
->type
== REF_ARRAY
14566 && ref
->u
.ar
.type
!= AR_FULL
)
14568 gfc_error ("DATA element %qs at %L is a pointer and so must "
14569 "be a full array", sym
->name
, where
);
14574 if (e
->rank
== 0 || has_pointer
)
14576 mpz_init_set_ui (size
, 1);
14583 /* Find the array section reference. */
14584 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
14586 if (ref
->type
!= REF_ARRAY
)
14588 if (ref
->u
.ar
.type
== AR_ELEMENT
)
14594 /* Set marks according to the reference pattern. */
14595 switch (ref
->u
.ar
.type
)
14603 /* Get the start position of array section. */
14604 gfc_get_section_index (ar
, section_index
, &offset
);
14609 gcc_unreachable ();
14612 if (!gfc_array_size (e
, &size
))
14614 gfc_error ("Nonconstant array section at %L in DATA statement",
14616 mpz_clear (offset
);
14623 while (mpz_cmp_ui (size
, 0) > 0)
14625 if (!next_data_value ())
14627 gfc_error ("DATA statement at %L has more variables than values",
14633 t
= gfc_check_assign (var
->expr
, values
.vnode
->expr
, 0);
14637 /* If we have more than one element left in the repeat count,
14638 and we have more than one element left in the target variable,
14639 then create a range assignment. */
14640 /* FIXME: Only done for full arrays for now, since array sections
14642 if (mark
== AR_FULL
&& ref
&& ref
->next
== NULL
14643 && mpz_cmp_ui (values
.left
, 1) > 0 && mpz_cmp_ui (size
, 1) > 0)
14647 if (mpz_cmp (size
, values
.left
) >= 0)
14649 mpz_init_set (range
, values
.left
);
14650 mpz_sub (size
, size
, values
.left
);
14651 mpz_set_ui (values
.left
, 0);
14655 mpz_init_set (range
, size
);
14656 mpz_sub (values
.left
, values
.left
, size
);
14657 mpz_set_ui (size
, 0);
14660 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
14663 mpz_add (offset
, offset
, range
);
14670 /* Assign initial value to symbol. */
14673 mpz_sub_ui (values
.left
, values
.left
, 1);
14674 mpz_sub_ui (size
, size
, 1);
14676 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
14681 if (mark
== AR_FULL
)
14682 mpz_add_ui (offset
, offset
, 1);
14684 /* Modify the array section indexes and recalculate the offset
14685 for next element. */
14686 else if (mark
== AR_SECTION
)
14687 gfc_advance_section (section_index
, ar
, &offset
);
14691 if (mark
== AR_SECTION
)
14693 for (i
= 0; i
< ar
->dimen
; i
++)
14694 mpz_clear (section_index
[i
]);
14698 mpz_clear (offset
);
14704 static bool traverse_data_var (gfc_data_variable
*, locus
*);
14706 /* Iterate over a list of elements in a DATA statement. */
14709 traverse_data_list (gfc_data_variable
*var
, locus
*where
)
14712 iterator_stack frame
;
14713 gfc_expr
*e
, *start
, *end
, *step
;
14714 bool retval
= true;
14716 mpz_init (frame
.value
);
14719 start
= gfc_copy_expr (var
->iter
.start
);
14720 end
= gfc_copy_expr (var
->iter
.end
);
14721 step
= gfc_copy_expr (var
->iter
.step
);
14723 if (!gfc_simplify_expr (start
, 1)
14724 || start
->expr_type
!= EXPR_CONSTANT
)
14726 gfc_error ("start of implied-do loop at %L could not be "
14727 "simplified to a constant value", &start
->where
);
14731 if (!gfc_simplify_expr (end
, 1)
14732 || end
->expr_type
!= EXPR_CONSTANT
)
14734 gfc_error ("end of implied-do loop at %L could not be "
14735 "simplified to a constant value", &start
->where
);
14739 if (!gfc_simplify_expr (step
, 1)
14740 || step
->expr_type
!= EXPR_CONSTANT
)
14742 gfc_error ("step of implied-do loop at %L could not be "
14743 "simplified to a constant value", &start
->where
);
14748 mpz_set (trip
, end
->value
.integer
);
14749 mpz_sub (trip
, trip
, start
->value
.integer
);
14750 mpz_add (trip
, trip
, step
->value
.integer
);
14752 mpz_div (trip
, trip
, step
->value
.integer
);
14754 mpz_set (frame
.value
, start
->value
.integer
);
14756 frame
.prev
= iter_stack
;
14757 frame
.variable
= var
->iter
.var
->symtree
;
14758 iter_stack
= &frame
;
14760 while (mpz_cmp_ui (trip
, 0) > 0)
14762 if (!traverse_data_var (var
->list
, where
))
14768 e
= gfc_copy_expr (var
->expr
);
14769 if (!gfc_simplify_expr (e
, 1))
14776 mpz_add (frame
.value
, frame
.value
, step
->value
.integer
);
14778 mpz_sub_ui (trip
, trip
, 1);
14782 mpz_clear (frame
.value
);
14785 gfc_free_expr (start
);
14786 gfc_free_expr (end
);
14787 gfc_free_expr (step
);
14789 iter_stack
= frame
.prev
;
14794 /* Type resolve variables in the variable list of a DATA statement. */
14797 traverse_data_var (gfc_data_variable
*var
, locus
*where
)
14801 for (; var
; var
= var
->next
)
14803 if (var
->expr
== NULL
)
14804 t
= traverse_data_list (var
, where
);
14806 t
= check_data_variable (var
, where
);
14816 /* Resolve the expressions and iterators associated with a data statement.
14817 This is separate from the assignment checking because data lists should
14818 only be resolved once. */
14821 resolve_data_variables (gfc_data_variable
*d
)
14823 for (; d
; d
= d
->next
)
14825 if (d
->list
== NULL
)
14827 if (!gfc_resolve_expr (d
->expr
))
14832 if (!gfc_resolve_iterator (&d
->iter
, false, true))
14835 if (!resolve_data_variables (d
->list
))
14844 /* Resolve a single DATA statement. We implement this by storing a pointer to
14845 the value list into static variables, and then recursively traversing the
14846 variables list, expanding iterators and such. */
14849 resolve_data (gfc_data
*d
)
14852 if (!resolve_data_variables (d
->var
))
14855 values
.vnode
= d
->value
;
14856 if (d
->value
== NULL
)
14857 mpz_set_ui (values
.left
, 0);
14859 mpz_set (values
.left
, d
->value
->repeat
);
14861 if (!traverse_data_var (d
->var
, &d
->where
))
14864 /* At this point, we better not have any values left. */
14866 if (next_data_value ())
14867 gfc_error ("DATA statement at %L has more values than variables",
14872 /* 12.6 Constraint: In a pure subprogram any variable which is in common or
14873 accessed by host or use association, is a dummy argument to a pure function,
14874 is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
14875 is storage associated with any such variable, shall not be used in the
14876 following contexts: (clients of this function). */
14878 /* Determines if a variable is not 'pure', i.e., not assignable within a pure
14879 procedure. Returns zero if assignment is OK, nonzero if there is a
14882 gfc_impure_variable (gfc_symbol
*sym
)
14887 if (sym
->attr
.use_assoc
|| sym
->attr
.in_common
)
14890 /* Check if the symbol's ns is inside the pure procedure. */
14891 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14895 if (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
14899 proc
= sym
->ns
->proc_name
;
14900 if (sym
->attr
.dummy
14901 && ((proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_IN
)
14902 || proc
->attr
.function
))
14905 /* TODO: Sort out what can be storage associated, if anything, and include
14906 it here. In principle equivalences should be scanned but it does not
14907 seem to be possible to storage associate an impure variable this way. */
14912 /* Test whether a symbol is pure or not. For a NULL pointer, checks if the
14913 current namespace is inside a pure procedure. */
14916 gfc_pure (gfc_symbol
*sym
)
14918 symbol_attribute attr
;
14923 /* Check if the current namespace or one of its parents
14924 belongs to a pure procedure. */
14925 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14927 sym
= ns
->proc_name
;
14931 if (attr
.flavor
== FL_PROCEDURE
&& attr
.pure
)
14939 return attr
.flavor
== FL_PROCEDURE
&& attr
.pure
;
14943 /* Test whether a symbol is implicitly pure or not. For a NULL pointer,
14944 checks if the current namespace is implicitly pure. Note that this
14945 function returns false for a PURE procedure. */
14948 gfc_implicit_pure (gfc_symbol
*sym
)
14954 /* Check if the current procedure is implicit_pure. Walk up
14955 the procedure list until we find a procedure. */
14956 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14958 sym
= ns
->proc_name
;
14962 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14967 return sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.implicit_pure
14968 && !sym
->attr
.pure
;
14973 gfc_unset_implicit_pure (gfc_symbol
*sym
)
14979 /* Check if the current procedure is implicit_pure. Walk up
14980 the procedure list until we find a procedure. */
14981 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14983 sym
= ns
->proc_name
;
14987 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14992 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14993 sym
->attr
.implicit_pure
= 0;
14995 sym
->attr
.pure
= 0;
14999 /* Test whether the current procedure is elemental or not. */
15002 gfc_elemental (gfc_symbol
*sym
)
15004 symbol_attribute attr
;
15007 sym
= gfc_current_ns
->proc_name
;
15012 return attr
.flavor
== FL_PROCEDURE
&& attr
.elemental
;
15016 /* Warn about unused labels. */
15019 warn_unused_fortran_label (gfc_st_label
*label
)
15024 warn_unused_fortran_label (label
->left
);
15026 if (label
->defined
== ST_LABEL_UNKNOWN
)
15029 switch (label
->referenced
)
15031 case ST_LABEL_UNKNOWN
:
15032 gfc_warning (0, "Label %d at %L defined but not used", label
->value
,
15036 case ST_LABEL_BAD_TARGET
:
15037 gfc_warning (0, "Label %d at %L defined but cannot be used",
15038 label
->value
, &label
->where
);
15045 warn_unused_fortran_label (label
->right
);
15049 /* Returns the sequence type of a symbol or sequence. */
15052 sequence_type (gfc_typespec ts
)
15061 if (ts
.u
.derived
->components
== NULL
)
15062 return SEQ_NONDEFAULT
;
15064 result
= sequence_type (ts
.u
.derived
->components
->ts
);
15065 for (c
= ts
.u
.derived
->components
->next
; c
; c
= c
->next
)
15066 if (sequence_type (c
->ts
) != result
)
15072 if (ts
.kind
!= gfc_default_character_kind
)
15073 return SEQ_NONDEFAULT
;
15075 return SEQ_CHARACTER
;
15078 if (ts
.kind
!= gfc_default_integer_kind
)
15079 return SEQ_NONDEFAULT
;
15081 return SEQ_NUMERIC
;
15084 if (!(ts
.kind
== gfc_default_real_kind
15085 || ts
.kind
== gfc_default_double_kind
))
15086 return SEQ_NONDEFAULT
;
15088 return SEQ_NUMERIC
;
15091 if (ts
.kind
!= gfc_default_complex_kind
)
15092 return SEQ_NONDEFAULT
;
15094 return SEQ_NUMERIC
;
15097 if (ts
.kind
!= gfc_default_logical_kind
)
15098 return SEQ_NONDEFAULT
;
15100 return SEQ_NUMERIC
;
15103 return SEQ_NONDEFAULT
;
15108 /* Resolve derived type EQUIVALENCE object. */
15111 resolve_equivalence_derived (gfc_symbol
*derived
, gfc_symbol
*sym
, gfc_expr
*e
)
15113 gfc_component
*c
= derived
->components
;
15118 /* Shall not be an object of nonsequence derived type. */
15119 if (!derived
->attr
.sequence
)
15121 gfc_error ("Derived type variable %qs at %L must have SEQUENCE "
15122 "attribute to be an EQUIVALENCE object", sym
->name
,
15127 /* Shall not have allocatable components. */
15128 if (derived
->attr
.alloc_comp
)
15130 gfc_error ("Derived type variable %qs at %L cannot have ALLOCATABLE "
15131 "components to be an EQUIVALENCE object",sym
->name
,
15136 if (sym
->attr
.in_common
&& gfc_has_default_initializer (sym
->ts
.u
.derived
))
15138 gfc_error ("Derived type variable %qs at %L with default "
15139 "initialization cannot be in EQUIVALENCE with a variable "
15140 "in COMMON", sym
->name
, &e
->where
);
15144 for (; c
; c
= c
->next
)
15146 if (gfc_bt_struct (c
->ts
.type
)
15147 && (!resolve_equivalence_derived(c
->ts
.u
.derived
, sym
, e
)))
15150 /* Shall not be an object of sequence derived type containing a pointer
15151 in the structure. */
15152 if (c
->attr
.pointer
)
15154 gfc_error ("Derived type variable %qs at %L with pointer "
15155 "component(s) cannot be an EQUIVALENCE object",
15156 sym
->name
, &e
->where
);
15164 /* Resolve equivalence object.
15165 An EQUIVALENCE object shall not be a dummy argument, a pointer, a target,
15166 an allocatable array, an object of nonsequence derived type, an object of
15167 sequence derived type containing a pointer at any level of component
15168 selection, an automatic object, a function name, an entry name, a result
15169 name, a named constant, a structure component, or a subobject of any of
15170 the preceding objects. A substring shall not have length zero. A
15171 derived type shall not have components with default initialization nor
15172 shall two objects of an equivalence group be initialized.
15173 Either all or none of the objects shall have an protected attribute.
15174 The simple constraints are done in symbol.c(check_conflict) and the rest
15175 are implemented here. */
15178 resolve_equivalence (gfc_equiv
*eq
)
15181 gfc_symbol
*first_sym
;
15184 locus
*last_where
= NULL
;
15185 seq_type eq_type
, last_eq_type
;
15186 gfc_typespec
*last_ts
;
15187 int object
, cnt_protected
;
15190 last_ts
= &eq
->expr
->symtree
->n
.sym
->ts
;
15192 first_sym
= eq
->expr
->symtree
->n
.sym
;
15196 for (object
= 1; eq
; eq
= eq
->eq
, object
++)
15200 e
->ts
= e
->symtree
->n
.sym
->ts
;
15201 /* match_varspec might not know yet if it is seeing
15202 array reference or substring reference, as it doesn't
15204 if (e
->ref
&& e
->ref
->type
== REF_ARRAY
)
15206 gfc_ref
*ref
= e
->ref
;
15207 sym
= e
->symtree
->n
.sym
;
15209 if (sym
->attr
.dimension
)
15211 ref
->u
.ar
.as
= sym
->as
;
15215 /* For substrings, convert REF_ARRAY into REF_SUBSTRING. */
15216 if (e
->ts
.type
== BT_CHARACTER
15218 && ref
->type
== REF_ARRAY
15219 && ref
->u
.ar
.dimen
== 1
15220 && ref
->u
.ar
.dimen_type
[0] == DIMEN_RANGE
15221 && ref
->u
.ar
.stride
[0] == NULL
)
15223 gfc_expr
*start
= ref
->u
.ar
.start
[0];
15224 gfc_expr
*end
= ref
->u
.ar
.end
[0];
15227 /* Optimize away the (:) reference. */
15228 if (start
== NULL
&& end
== NULL
)
15231 e
->ref
= ref
->next
;
15233 e
->ref
->next
= ref
->next
;
15238 ref
->type
= REF_SUBSTRING
;
15240 start
= gfc_get_int_expr (gfc_default_integer_kind
,
15242 ref
->u
.ss
.start
= start
;
15243 if (end
== NULL
&& e
->ts
.u
.cl
)
15244 end
= gfc_copy_expr (e
->ts
.u
.cl
->length
);
15245 ref
->u
.ss
.end
= end
;
15246 ref
->u
.ss
.length
= e
->ts
.u
.cl
;
15253 /* Any further ref is an error. */
15256 gcc_assert (ref
->type
== REF_ARRAY
);
15257 gfc_error ("Syntax error in EQUIVALENCE statement at %L",
15263 if (!gfc_resolve_expr (e
))
15266 sym
= e
->symtree
->n
.sym
;
15268 if (sym
->attr
.is_protected
)
15270 if (cnt_protected
> 0 && cnt_protected
!= object
)
15272 gfc_error ("Either all or none of the objects in the "
15273 "EQUIVALENCE set at %L shall have the "
15274 "PROTECTED attribute",
15279 /* Shall not equivalence common block variables in a PURE procedure. */
15280 if (sym
->ns
->proc_name
15281 && sym
->ns
->proc_name
->attr
.pure
15282 && sym
->attr
.in_common
)
15284 gfc_error ("Common block member %qs at %L cannot be an EQUIVALENCE "
15285 "object in the pure procedure %qs",
15286 sym
->name
, &e
->where
, sym
->ns
->proc_name
->name
);
15290 /* Shall not be a named constant. */
15291 if (e
->expr_type
== EXPR_CONSTANT
)
15293 gfc_error ("Named constant %qs at %L cannot be an EQUIVALENCE "
15294 "object", sym
->name
, &e
->where
);
15298 if (e
->ts
.type
== BT_DERIVED
15299 && !resolve_equivalence_derived (e
->ts
.u
.derived
, sym
, e
))
15302 /* Check that the types correspond correctly:
15304 A numeric sequence structure may be equivalenced to another sequence
15305 structure, an object of default integer type, default real type, double
15306 precision real type, default logical type such that components of the
15307 structure ultimately only become associated to objects of the same
15308 kind. A character sequence structure may be equivalenced to an object
15309 of default character kind or another character sequence structure.
15310 Other objects may be equivalenced only to objects of the same type and
15311 kind parameters. */
15313 /* Identical types are unconditionally OK. */
15314 if (object
== 1 || gfc_compare_types (last_ts
, &sym
->ts
))
15315 goto identical_types
;
15317 last_eq_type
= sequence_type (*last_ts
);
15318 eq_type
= sequence_type (sym
->ts
);
15320 /* Since the pair of objects is not of the same type, mixed or
15321 non-default sequences can be rejected. */
15323 msg
= "Sequence %s with mixed components in EQUIVALENCE "
15324 "statement at %L with different type objects";
15326 && last_eq_type
== SEQ_MIXED
15327 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
15328 || (eq_type
== SEQ_MIXED
15329 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
15332 msg
= "Non-default type object or sequence %s in EQUIVALENCE "
15333 "statement at %L with objects of different type";
15335 && last_eq_type
== SEQ_NONDEFAULT
15336 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
15337 || (eq_type
== SEQ_NONDEFAULT
15338 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
15341 msg
="Non-CHARACTER object %qs in default CHARACTER "
15342 "EQUIVALENCE statement at %L";
15343 if (last_eq_type
== SEQ_CHARACTER
15344 && eq_type
!= SEQ_CHARACTER
15345 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
15348 msg
="Non-NUMERIC object %qs in default NUMERIC "
15349 "EQUIVALENCE statement at %L";
15350 if (last_eq_type
== SEQ_NUMERIC
15351 && eq_type
!= SEQ_NUMERIC
15352 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
15357 last_where
= &e
->where
;
15362 /* Shall not be an automatic array. */
15363 if (e
->ref
->type
== REF_ARRAY
15364 && !gfc_resolve_array_spec (e
->ref
->u
.ar
.as
, 1))
15366 gfc_error ("Array %qs at %L with non-constant bounds cannot be "
15367 "an EQUIVALENCE object", sym
->name
, &e
->where
);
15374 /* Shall not be a structure component. */
15375 if (r
->type
== REF_COMPONENT
)
15377 gfc_error ("Structure component %qs at %L cannot be an "
15378 "EQUIVALENCE object",
15379 r
->u
.c
.component
->name
, &e
->where
);
15383 /* A substring shall not have length zero. */
15384 if (r
->type
== REF_SUBSTRING
)
15386 if (compare_bound (r
->u
.ss
.start
, r
->u
.ss
.end
) == CMP_GT
)
15388 gfc_error ("Substring at %L has length zero",
15389 &r
->u
.ss
.start
->where
);
15399 /* Resolve function and ENTRY types, issue diagnostics if needed. */
15402 resolve_fntype (gfc_namespace
*ns
)
15404 gfc_entry_list
*el
;
15407 if (ns
->proc_name
== NULL
|| !ns
->proc_name
->attr
.function
)
15410 /* If there are any entries, ns->proc_name is the entry master
15411 synthetic symbol and ns->entries->sym actual FUNCTION symbol. */
15413 sym
= ns
->entries
->sym
;
15415 sym
= ns
->proc_name
;
15416 if (sym
->result
== sym
15417 && sym
->ts
.type
== BT_UNKNOWN
15418 && !gfc_set_default_type (sym
, 0, NULL
)
15419 && !sym
->attr
.untyped
)
15421 gfc_error ("Function %qs at %L has no IMPLICIT type",
15422 sym
->name
, &sym
->declared_at
);
15423 sym
->attr
.untyped
= 1;
15426 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->ts
.u
.derived
->attr
.use_assoc
15427 && !sym
->attr
.contained
15428 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
15429 && gfc_check_symbol_access (sym
))
15431 gfc_notify_std (GFC_STD_F2003
, "PUBLIC function %qs at "
15432 "%L of PRIVATE type %qs", sym
->name
,
15433 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
15437 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
15439 if (el
->sym
->result
== el
->sym
15440 && el
->sym
->ts
.type
== BT_UNKNOWN
15441 && !gfc_set_default_type (el
->sym
, 0, NULL
)
15442 && !el
->sym
->attr
.untyped
)
15444 gfc_error ("ENTRY %qs at %L has no IMPLICIT type",
15445 el
->sym
->name
, &el
->sym
->declared_at
);
15446 el
->sym
->attr
.untyped
= 1;
15452 /* 12.3.2.1.1 Defined operators. */
15455 check_uop_procedure (gfc_symbol
*sym
, locus where
)
15457 gfc_formal_arglist
*formal
;
15459 if (!sym
->attr
.function
)
15461 gfc_error ("User operator procedure %qs at %L must be a FUNCTION",
15462 sym
->name
, &where
);
15466 if (sym
->ts
.type
== BT_CHARACTER
15467 && !((sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
) || sym
->ts
.deferred
)
15468 && !(sym
->result
&& ((sym
->result
->ts
.u
.cl
15469 && sym
->result
->ts
.u
.cl
->length
) || sym
->result
->ts
.deferred
)))
15471 gfc_error ("User operator procedure %qs at %L cannot be assumed "
15472 "character length", sym
->name
, &where
);
15476 formal
= gfc_sym_get_dummy_args (sym
);
15477 if (!formal
|| !formal
->sym
)
15479 gfc_error ("User operator procedure %qs at %L must have at least "
15480 "one argument", sym
->name
, &where
);
15484 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
15486 gfc_error ("First argument of operator interface at %L must be "
15487 "INTENT(IN)", &where
);
15491 if (formal
->sym
->attr
.optional
)
15493 gfc_error ("First argument of operator interface at %L cannot be "
15494 "optional", &where
);
15498 formal
= formal
->next
;
15499 if (!formal
|| !formal
->sym
)
15502 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
15504 gfc_error ("Second argument of operator interface at %L must be "
15505 "INTENT(IN)", &where
);
15509 if (formal
->sym
->attr
.optional
)
15511 gfc_error ("Second argument of operator interface at %L cannot be "
15512 "optional", &where
);
15518 gfc_error ("Operator interface at %L must have, at most, two "
15519 "arguments", &where
);
15527 gfc_resolve_uops (gfc_symtree
*symtree
)
15529 gfc_interface
*itr
;
15531 if (symtree
== NULL
)
15534 gfc_resolve_uops (symtree
->left
);
15535 gfc_resolve_uops (symtree
->right
);
15537 for (itr
= symtree
->n
.uop
->op
; itr
; itr
= itr
->next
)
15538 check_uop_procedure (itr
->sym
, itr
->sym
->declared_at
);
15542 /* Examine all of the expressions associated with a program unit,
15543 assign types to all intermediate expressions, make sure that all
15544 assignments are to compatible types and figure out which names
15545 refer to which functions or subroutines. It doesn't check code
15546 block, which is handled by gfc_resolve_code. */
15549 resolve_types (gfc_namespace
*ns
)
15555 gfc_namespace
* old_ns
= gfc_current_ns
;
15557 if (ns
->types_resolved
)
15560 /* Check that all IMPLICIT types are ok. */
15561 if (!ns
->seen_implicit_none
)
15564 for (letter
= 0; letter
!= GFC_LETTERS
; ++letter
)
15565 if (ns
->set_flag
[letter
]
15566 && !resolve_typespec_used (&ns
->default_type
[letter
],
15567 &ns
->implicit_loc
[letter
], NULL
))
15571 gfc_current_ns
= ns
;
15573 resolve_entries (ns
);
15575 resolve_common_vars (&ns
->blank_common
, false);
15576 resolve_common_blocks (ns
->common_root
);
15578 resolve_contained_functions (ns
);
15580 if (ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
15581 && ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
15582 resolve_formal_arglist (ns
->proc_name
);
15584 gfc_traverse_ns (ns
, resolve_bind_c_derived_types
);
15586 for (cl
= ns
->cl_list
; cl
; cl
= cl
->next
)
15587 resolve_charlen (cl
);
15589 gfc_traverse_ns (ns
, resolve_symbol
);
15591 resolve_fntype (ns
);
15593 for (n
= ns
->contained
; n
; n
= n
->sibling
)
15595 if (gfc_pure (ns
->proc_name
) && !gfc_pure (n
->proc_name
))
15596 gfc_error ("Contained procedure %qs at %L of a PURE procedure must "
15597 "also be PURE", n
->proc_name
->name
,
15598 &n
->proc_name
->declared_at
);
15604 gfc_do_concurrent_flag
= 0;
15605 gfc_check_interfaces (ns
);
15607 gfc_traverse_ns (ns
, resolve_values
);
15613 for (d
= ns
->data
; d
; d
= d
->next
)
15617 gfc_traverse_ns (ns
, gfc_formalize_init_value
);
15619 gfc_traverse_ns (ns
, gfc_verify_binding_labels
);
15621 for (eq
= ns
->equiv
; eq
; eq
= eq
->next
)
15622 resolve_equivalence (eq
);
15624 /* Warn about unused labels. */
15625 if (warn_unused_label
)
15626 warn_unused_fortran_label (ns
->st_labels
);
15628 gfc_resolve_uops (ns
->uop_root
);
15630 gfc_resolve_omp_declare_simd (ns
);
15632 gfc_resolve_omp_udrs (ns
->omp_udr_root
);
15634 ns
->types_resolved
= 1;
15636 gfc_current_ns
= old_ns
;
15640 /* Call gfc_resolve_code recursively. */
15643 resolve_codes (gfc_namespace
*ns
)
15646 bitmap_obstack old_obstack
;
15648 if (ns
->resolved
== 1)
15651 for (n
= ns
->contained
; n
; n
= n
->sibling
)
15654 gfc_current_ns
= ns
;
15656 /* Don't clear 'cs_base' if this is the namespace of a BLOCK construct. */
15657 if (!(ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_LABEL
))
15660 /* Set to an out of range value. */
15661 current_entry_id
= -1;
15663 old_obstack
= labels_obstack
;
15664 bitmap_obstack_initialize (&labels_obstack
);
15666 gfc_resolve_oacc_declare (ns
);
15667 gfc_resolve_code (ns
->code
, ns
);
15669 bitmap_obstack_release (&labels_obstack
);
15670 labels_obstack
= old_obstack
;
15674 /* This function is called after a complete program unit has been compiled.
15675 Its purpose is to examine all of the expressions associated with a program
15676 unit, assign types to all intermediate expressions, make sure that all
15677 assignments are to compatible types and figure out which names refer to
15678 which functions or subroutines. */
15681 gfc_resolve (gfc_namespace
*ns
)
15683 gfc_namespace
*old_ns
;
15684 code_stack
*old_cs_base
;
15685 struct gfc_omp_saved_state old_omp_state
;
15691 old_ns
= gfc_current_ns
;
15692 old_cs_base
= cs_base
;
15694 /* As gfc_resolve can be called during resolution of an OpenMP construct
15695 body, we should clear any state associated to it, so that say NS's
15696 DO loops are not interpreted as OpenMP loops. */
15697 gfc_omp_save_and_clear_state (&old_omp_state
);
15699 resolve_types (ns
);
15700 component_assignment_level
= 0;
15701 resolve_codes (ns
);
15703 gfc_current_ns
= old_ns
;
15704 cs_base
= old_cs_base
;
15707 gfc_run_passes (ns
);
15709 gfc_omp_restore_state (&old_omp_state
);