1 /* Perform type resolution on the various structures.
2 Copyright (C) 2001-2015 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 || sym
->attr
.flavor
== FL_DERIVED
|| 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
);
1121 /* Resolve all of the elements of a structure constructor and make sure that
1122 the types are correct. The 'init' flag indicates that the given
1123 constructor is an initializer. */
1126 resolve_structure_cons (gfc_expr
*expr
, int init
)
1128 gfc_constructor
*cons
;
1129 gfc_component
*comp
;
1135 if (expr
->ts
.type
== BT_DERIVED
)
1136 resolve_fl_derived0 (expr
->ts
.u
.derived
);
1138 cons
= gfc_constructor_first (expr
->value
.constructor
);
1140 /* A constructor may have references if it is the result of substituting a
1141 parameter variable. In this case we just pull out the component we
1144 comp
= expr
->ref
->u
.c
.sym
->components
;
1146 comp
= expr
->ts
.u
.derived
->components
;
1148 for (; comp
&& cons
; comp
= comp
->next
, cons
= gfc_constructor_next (cons
))
1155 if (!gfc_resolve_expr (cons
->expr
))
1161 rank
= comp
->as
? comp
->as
->rank
: 0;
1162 if (comp
->ts
.type
== BT_CLASS
&& CLASS_DATA (comp
)->as
)
1163 rank
= CLASS_DATA (comp
)->as
->rank
;
1165 if (cons
->expr
->expr_type
!= EXPR_NULL
&& rank
!= cons
->expr
->rank
1166 && (comp
->attr
.allocatable
|| cons
->expr
->rank
))
1168 gfc_error ("The rank of the element in the structure "
1169 "constructor at %L does not match that of the "
1170 "component (%d/%d)", &cons
->expr
->where
,
1171 cons
->expr
->rank
, rank
);
1175 /* If we don't have the right type, try to convert it. */
1177 if (!comp
->attr
.proc_pointer
&&
1178 !gfc_compare_types (&cons
->expr
->ts
, &comp
->ts
))
1180 if (strcmp (comp
->name
, "_extends") == 0)
1182 /* Can afford to be brutal with the _extends initializer.
1183 The derived type can get lost because it is PRIVATE
1184 but it is not usage constrained by the standard. */
1185 cons
->expr
->ts
= comp
->ts
;
1187 else if (comp
->attr
.pointer
&& cons
->expr
->ts
.type
!= BT_UNKNOWN
)
1189 gfc_error ("The element in the structure constructor at %L, "
1190 "for pointer component %qs, is %s but should be %s",
1191 &cons
->expr
->where
, comp
->name
,
1192 gfc_basic_typename (cons
->expr
->ts
.type
),
1193 gfc_basic_typename (comp
->ts
.type
));
1198 bool t2
= gfc_convert_type (cons
->expr
, &comp
->ts
, 1);
1204 /* For strings, the length of the constructor should be the same as
1205 the one of the structure, ensure this if the lengths are known at
1206 compile time and when we are dealing with PARAMETER or structure
1208 if (cons
->expr
->ts
.type
== BT_CHARACTER
&& comp
->ts
.u
.cl
1209 && comp
->ts
.u
.cl
->length
1210 && comp
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1211 && cons
->expr
->ts
.u
.cl
&& cons
->expr
->ts
.u
.cl
->length
1212 && cons
->expr
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1213 && cons
->expr
->rank
!= 0
1214 && mpz_cmp (cons
->expr
->ts
.u
.cl
->length
->value
.integer
,
1215 comp
->ts
.u
.cl
->length
->value
.integer
) != 0)
1217 if (cons
->expr
->expr_type
== EXPR_VARIABLE
1218 && cons
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
)
1220 /* Wrap the parameter in an array constructor (EXPR_ARRAY)
1221 to make use of the gfc_resolve_character_array_constructor
1222 machinery. The expression is later simplified away to
1223 an array of string literals. */
1224 gfc_expr
*para
= cons
->expr
;
1225 cons
->expr
= gfc_get_expr ();
1226 cons
->expr
->ts
= para
->ts
;
1227 cons
->expr
->where
= para
->where
;
1228 cons
->expr
->expr_type
= EXPR_ARRAY
;
1229 cons
->expr
->rank
= para
->rank
;
1230 cons
->expr
->shape
= gfc_copy_shape (para
->shape
, para
->rank
);
1231 gfc_constructor_append_expr (&cons
->expr
->value
.constructor
,
1232 para
, &cons
->expr
->where
);
1234 if (cons
->expr
->expr_type
== EXPR_ARRAY
)
1237 p
= gfc_constructor_first (cons
->expr
->value
.constructor
);
1238 if (cons
->expr
->ts
.u
.cl
!= p
->expr
->ts
.u
.cl
)
1240 gfc_charlen
*cl
, *cl2
;
1243 for (cl
= gfc_current_ns
->cl_list
; cl
; cl
= cl
->next
)
1245 if (cl
== cons
->expr
->ts
.u
.cl
)
1253 cl2
->next
= cl
->next
;
1255 gfc_free_expr (cl
->length
);
1259 cons
->expr
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
1260 cons
->expr
->ts
.u
.cl
->length_from_typespec
= true;
1261 cons
->expr
->ts
.u
.cl
->length
= gfc_copy_expr (comp
->ts
.u
.cl
->length
);
1262 gfc_resolve_character_array_constructor (cons
->expr
);
1266 if (cons
->expr
->expr_type
== EXPR_NULL
1267 && !(comp
->attr
.pointer
|| comp
->attr
.allocatable
1268 || comp
->attr
.proc_pointer
|| comp
->ts
.f90_type
== BT_VOID
1269 || (comp
->ts
.type
== BT_CLASS
1270 && (CLASS_DATA (comp
)->attr
.class_pointer
1271 || CLASS_DATA (comp
)->attr
.allocatable
))))
1274 gfc_error ("The NULL in the structure constructor at %L is "
1275 "being applied to component %qs, which is neither "
1276 "a POINTER nor ALLOCATABLE", &cons
->expr
->where
,
1280 if (comp
->attr
.proc_pointer
&& comp
->ts
.interface
)
1282 /* Check procedure pointer interface. */
1283 gfc_symbol
*s2
= NULL
;
1288 c2
= gfc_get_proc_ptr_comp (cons
->expr
);
1291 s2
= c2
->ts
.interface
;
1294 else if (cons
->expr
->expr_type
== EXPR_FUNCTION
)
1296 s2
= cons
->expr
->symtree
->n
.sym
->result
;
1297 name
= cons
->expr
->symtree
->n
.sym
->result
->name
;
1299 else if (cons
->expr
->expr_type
!= EXPR_NULL
)
1301 s2
= cons
->expr
->symtree
->n
.sym
;
1302 name
= cons
->expr
->symtree
->n
.sym
->name
;
1305 if (s2
&& !gfc_compare_interfaces (comp
->ts
.interface
, s2
, name
, 0, 1,
1306 err
, sizeof (err
), NULL
, NULL
))
1308 gfc_error ("Interface mismatch for procedure-pointer component "
1309 "%qs in structure constructor at %L: %s",
1310 comp
->name
, &cons
->expr
->where
, err
);
1315 if (!comp
->attr
.pointer
|| comp
->attr
.proc_pointer
1316 || cons
->expr
->expr_type
== EXPR_NULL
)
1319 a
= gfc_expr_attr (cons
->expr
);
1321 if (!a
.pointer
&& !a
.target
)
1324 gfc_error ("The element in the structure constructor at %L, "
1325 "for pointer component %qs should be a POINTER or "
1326 "a TARGET", &cons
->expr
->where
, comp
->name
);
1331 /* F08:C461. Additional checks for pointer initialization. */
1335 gfc_error ("Pointer initialization target at %L "
1336 "must not be ALLOCATABLE ", &cons
->expr
->where
);
1341 gfc_error ("Pointer initialization target at %L "
1342 "must have the SAVE attribute", &cons
->expr
->where
);
1346 /* F2003, C1272 (3). */
1347 bool impure
= cons
->expr
->expr_type
== EXPR_VARIABLE
1348 && (gfc_impure_variable (cons
->expr
->symtree
->n
.sym
)
1349 || gfc_is_coindexed (cons
->expr
));
1350 if (impure
&& gfc_pure (NULL
))
1353 gfc_error ("Invalid expression in the structure constructor for "
1354 "pointer component %qs at %L in PURE procedure",
1355 comp
->name
, &cons
->expr
->where
);
1359 gfc_unset_implicit_pure (NULL
);
1366 /****************** Expression name resolution ******************/
1368 /* Returns 0 if a symbol was not declared with a type or
1369 attribute declaration statement, nonzero otherwise. */
1372 was_declared (gfc_symbol
*sym
)
1378 if (!a
.implicit_type
&& sym
->ts
.type
!= BT_UNKNOWN
)
1381 if (a
.allocatable
|| a
.dimension
|| a
.dummy
|| a
.external
|| a
.intrinsic
1382 || a
.optional
|| a
.pointer
|| a
.save
|| a
.target
|| a
.volatile_
1383 || a
.value
|| a
.access
!= ACCESS_UNKNOWN
|| a
.intent
!= INTENT_UNKNOWN
1384 || a
.asynchronous
|| a
.codimension
)
1391 /* Determine if a symbol is generic or not. */
1394 generic_sym (gfc_symbol
*sym
)
1398 if (sym
->attr
.generic
||
1399 (sym
->attr
.intrinsic
&& gfc_generic_intrinsic (sym
->name
)))
1402 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1405 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1412 return generic_sym (s
);
1419 /* Determine if a symbol is specific or not. */
1422 specific_sym (gfc_symbol
*sym
)
1426 if (sym
->attr
.if_source
== IFSRC_IFBODY
1427 || sym
->attr
.proc
== PROC_MODULE
1428 || sym
->attr
.proc
== PROC_INTERNAL
1429 || sym
->attr
.proc
== PROC_ST_FUNCTION
1430 || (sym
->attr
.intrinsic
&& gfc_specific_intrinsic (sym
->name
))
1431 || sym
->attr
.external
)
1434 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1437 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1439 return (s
== NULL
) ? 0 : specific_sym (s
);
1443 /* Figure out if the procedure is specific, generic or unknown. */
1446 { PTYPE_GENERIC
= 1, PTYPE_SPECIFIC
, PTYPE_UNKNOWN
};
1449 procedure_kind (gfc_symbol
*sym
)
1451 if (generic_sym (sym
))
1452 return PTYPE_GENERIC
;
1454 if (specific_sym (sym
))
1455 return PTYPE_SPECIFIC
;
1457 return PTYPE_UNKNOWN
;
1460 /* Check references to assumed size arrays. The flag need_full_assumed_size
1461 is nonzero when matching actual arguments. */
1463 static int need_full_assumed_size
= 0;
1466 check_assumed_size_reference (gfc_symbol
*sym
, gfc_expr
*e
)
1468 if (need_full_assumed_size
|| !(sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
))
1471 /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong.
1472 What should it be? */
1473 if (e
->ref
&& (e
->ref
->u
.ar
.end
[e
->ref
->u
.ar
.as
->rank
- 1] == NULL
)
1474 && (e
->ref
->u
.ar
.as
->type
== AS_ASSUMED_SIZE
)
1475 && (e
->ref
->u
.ar
.type
== AR_FULL
))
1477 gfc_error ("The upper bound in the last dimension must "
1478 "appear in the reference to the assumed size "
1479 "array %qs at %L", sym
->name
, &e
->where
);
1486 /* Look for bad assumed size array references in argument expressions
1487 of elemental and array valued intrinsic procedures. Since this is
1488 called from procedure resolution functions, it only recurses at
1492 resolve_assumed_size_actual (gfc_expr
*e
)
1497 switch (e
->expr_type
)
1500 if (e
->symtree
&& check_assumed_size_reference (e
->symtree
->n
.sym
, e
))
1505 if (resolve_assumed_size_actual (e
->value
.op
.op1
)
1506 || resolve_assumed_size_actual (e
->value
.op
.op2
))
1517 /* Check a generic procedure, passed as an actual argument, to see if
1518 there is a matching specific name. If none, it is an error, and if
1519 more than one, the reference is ambiguous. */
1521 count_specific_procs (gfc_expr
*e
)
1528 sym
= e
->symtree
->n
.sym
;
1530 for (p
= sym
->generic
; p
; p
= p
->next
)
1531 if (strcmp (sym
->name
, p
->sym
->name
) == 0)
1533 e
->symtree
= gfc_find_symtree (p
->sym
->ns
->sym_root
,
1539 gfc_error ("%qs at %L is ambiguous", e
->symtree
->n
.sym
->name
,
1543 gfc_error ("GENERIC procedure %qs is not allowed as an actual "
1544 "argument at %L", sym
->name
, &e
->where
);
1550 /* See if a call to sym could possibly be a not allowed RECURSION because of
1551 a missing RECURSIVE declaration. This means that either sym is the current
1552 context itself, or sym is the parent of a contained procedure calling its
1553 non-RECURSIVE containing procedure.
1554 This also works if sym is an ENTRY. */
1557 is_illegal_recursion (gfc_symbol
* sym
, gfc_namespace
* context
)
1559 gfc_symbol
* proc_sym
;
1560 gfc_symbol
* context_proc
;
1561 gfc_namespace
* real_context
;
1563 if (sym
->attr
.flavor
== FL_PROGRAM
1564 || sym
->attr
.flavor
== FL_DERIVED
)
1567 gcc_assert (sym
->attr
.flavor
== FL_PROCEDURE
);
1569 /* If we've got an ENTRY, find real procedure. */
1570 if (sym
->attr
.entry
&& sym
->ns
->entries
)
1571 proc_sym
= sym
->ns
->entries
->sym
;
1575 /* If sym is RECURSIVE, all is well of course. */
1576 if (proc_sym
->attr
.recursive
|| flag_recursive
)
1579 /* Find the context procedure's "real" symbol if it has entries.
1580 We look for a procedure symbol, so recurse on the parents if we don't
1581 find one (like in case of a BLOCK construct). */
1582 for (real_context
= context
; ; real_context
= real_context
->parent
)
1584 /* We should find something, eventually! */
1585 gcc_assert (real_context
);
1587 context_proc
= (real_context
->entries
? real_context
->entries
->sym
1588 : real_context
->proc_name
);
1590 /* In some special cases, there may not be a proc_name, like for this
1592 real(bad_kind()) function foo () ...
1593 when checking the call to bad_kind ().
1594 In these cases, we simply return here and assume that the
1599 if (context_proc
->attr
.flavor
!= FL_LABEL
)
1603 /* A call from sym's body to itself is recursion, of course. */
1604 if (context_proc
== proc_sym
)
1607 /* The same is true if context is a contained procedure and sym the
1609 if (context_proc
->attr
.contained
)
1611 gfc_symbol
* parent_proc
;
1613 gcc_assert (context
->parent
);
1614 parent_proc
= (context
->parent
->entries
? context
->parent
->entries
->sym
1615 : context
->parent
->proc_name
);
1617 if (parent_proc
== proc_sym
)
1625 /* Resolve an intrinsic procedure: Set its function/subroutine attribute,
1626 its typespec and formal argument list. */
1629 gfc_resolve_intrinsic (gfc_symbol
*sym
, locus
*loc
)
1631 gfc_intrinsic_sym
* isym
= NULL
;
1637 /* Already resolved. */
1638 if (sym
->from_intmod
&& sym
->ts
.type
!= BT_UNKNOWN
)
1641 /* We already know this one is an intrinsic, so we don't call
1642 gfc_is_intrinsic for full checking but rather use gfc_find_function and
1643 gfc_find_subroutine directly to check whether it is a function or
1646 if (sym
->intmod_sym_id
&& sym
->attr
.subroutine
)
1648 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1649 isym
= gfc_intrinsic_subroutine_by_id (id
);
1651 else if (sym
->intmod_sym_id
)
1653 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1654 isym
= gfc_intrinsic_function_by_id (id
);
1656 else if (!sym
->attr
.subroutine
)
1657 isym
= gfc_find_function (sym
->name
);
1659 if (isym
&& !sym
->attr
.subroutine
)
1661 if (sym
->ts
.type
!= BT_UNKNOWN
&& warn_surprising
1662 && !sym
->attr
.implicit_type
)
1663 gfc_warning (OPT_Wsurprising
,
1664 "Type specified for intrinsic function %qs at %L is"
1665 " ignored", sym
->name
, &sym
->declared_at
);
1667 if (!sym
->attr
.function
&&
1668 !gfc_add_function(&sym
->attr
, sym
->name
, loc
))
1673 else if (isym
|| (isym
= gfc_find_subroutine (sym
->name
)))
1675 if (sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.implicit_type
)
1677 gfc_error ("Intrinsic subroutine %qs at %L shall not have a type"
1678 " specifier", sym
->name
, &sym
->declared_at
);
1682 if (!sym
->attr
.subroutine
&&
1683 !gfc_add_subroutine(&sym
->attr
, sym
->name
, loc
))
1688 gfc_error ("%qs declared INTRINSIC at %L does not exist", sym
->name
,
1693 gfc_copy_formal_args_intr (sym
, isym
, NULL
);
1695 sym
->attr
.pure
= isym
->pure
;
1696 sym
->attr
.elemental
= isym
->elemental
;
1698 /* Check it is actually available in the standard settings. */
1699 if (!gfc_check_intrinsic_standard (isym
, &symstd
, false, sym
->declared_at
))
1701 gfc_error ("The intrinsic %qs declared INTRINSIC at %L is not "
1702 "available in the current standard settings but %s. Use "
1703 "an appropriate %<-std=*%> option or enable "
1704 "%<-fall-intrinsics%> in order to use it.",
1705 sym
->name
, &sym
->declared_at
, symstd
);
1713 /* Resolve a procedure expression, like passing it to a called procedure or as
1714 RHS for a procedure pointer assignment. */
1717 resolve_procedure_expression (gfc_expr
* expr
)
1721 if (expr
->expr_type
!= EXPR_VARIABLE
)
1723 gcc_assert (expr
->symtree
);
1725 sym
= expr
->symtree
->n
.sym
;
1727 if (sym
->attr
.intrinsic
)
1728 gfc_resolve_intrinsic (sym
, &expr
->where
);
1730 if (sym
->attr
.flavor
!= FL_PROCEDURE
1731 || (sym
->attr
.function
&& sym
->result
== sym
))
1734 /* A non-RECURSIVE procedure that is used as procedure expression within its
1735 own body is in danger of being called recursively. */
1736 if (is_illegal_recursion (sym
, gfc_current_ns
))
1737 gfc_warning (0, "Non-RECURSIVE procedure %qs at %L is possibly calling"
1738 " itself recursively. Declare it RECURSIVE or use"
1739 " %<-frecursive%>", sym
->name
, &expr
->where
);
1745 /* Resolve an actual argument list. Most of the time, this is just
1746 resolving the expressions in the list.
1747 The exception is that we sometimes have to decide whether arguments
1748 that look like procedure arguments are really simple variable
1752 resolve_actual_arglist (gfc_actual_arglist
*arg
, procedure_type ptype
,
1753 bool no_formal_args
)
1756 gfc_symtree
*parent_st
;
1758 gfc_component
*comp
;
1759 int save_need_full_assumed_size
;
1760 bool return_value
= false;
1761 bool actual_arg_sav
= actual_arg
, first_actual_arg_sav
= first_actual_arg
;
1764 first_actual_arg
= true;
1766 for (; arg
; arg
= arg
->next
)
1771 /* Check the label is a valid branching target. */
1774 if (arg
->label
->defined
== ST_LABEL_UNKNOWN
)
1776 gfc_error ("Label %d referenced at %L is never defined",
1777 arg
->label
->value
, &arg
->label
->where
);
1781 first_actual_arg
= false;
1785 if (e
->expr_type
== EXPR_VARIABLE
1786 && e
->symtree
->n
.sym
->attr
.generic
1788 && count_specific_procs (e
) != 1)
1791 if (e
->ts
.type
!= BT_PROCEDURE
)
1793 save_need_full_assumed_size
= need_full_assumed_size
;
1794 if (e
->expr_type
!= EXPR_VARIABLE
)
1795 need_full_assumed_size
= 0;
1796 if (!gfc_resolve_expr (e
))
1798 need_full_assumed_size
= save_need_full_assumed_size
;
1802 /* See if the expression node should really be a variable reference. */
1804 sym
= e
->symtree
->n
.sym
;
1806 if (sym
->attr
.flavor
== FL_PROCEDURE
1807 || sym
->attr
.intrinsic
1808 || sym
->attr
.external
)
1812 /* If a procedure is not already determined to be something else
1813 check if it is intrinsic. */
1814 if (gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, e
->where
))
1815 sym
->attr
.intrinsic
= 1;
1817 if (sym
->attr
.proc
== PROC_ST_FUNCTION
)
1819 gfc_error ("Statement function %qs at %L is not allowed as an "
1820 "actual argument", sym
->name
, &e
->where
);
1823 actual_ok
= gfc_intrinsic_actual_ok (sym
->name
,
1824 sym
->attr
.subroutine
);
1825 if (sym
->attr
.intrinsic
&& actual_ok
== 0)
1827 gfc_error ("Intrinsic %qs at %L is not allowed as an "
1828 "actual argument", sym
->name
, &e
->where
);
1831 if (sym
->attr
.contained
&& !sym
->attr
.use_assoc
1832 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
1834 if (!gfc_notify_std (GFC_STD_F2008
, "Internal procedure %qs is"
1835 " used as actual argument at %L",
1836 sym
->name
, &e
->where
))
1840 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
)
1842 gfc_error ("ELEMENTAL non-INTRINSIC procedure %qs is not "
1843 "allowed as an actual argument at %L", sym
->name
,
1847 /* Check if a generic interface has a specific procedure
1848 with the same name before emitting an error. */
1849 if (sym
->attr
.generic
&& count_specific_procs (e
) != 1)
1852 /* Just in case a specific was found for the expression. */
1853 sym
= e
->symtree
->n
.sym
;
1855 /* If the symbol is the function that names the current (or
1856 parent) scope, then we really have a variable reference. */
1858 if (gfc_is_function_return_value (sym
, sym
->ns
))
1861 /* If all else fails, see if we have a specific intrinsic. */
1862 if (sym
->ts
.type
== BT_UNKNOWN
&& sym
->attr
.intrinsic
)
1864 gfc_intrinsic_sym
*isym
;
1866 isym
= gfc_find_function (sym
->name
);
1867 if (isym
== NULL
|| !isym
->specific
)
1869 gfc_error ("Unable to find a specific INTRINSIC procedure "
1870 "for the reference %qs at %L", sym
->name
,
1875 sym
->attr
.intrinsic
= 1;
1876 sym
->attr
.function
= 1;
1879 if (!gfc_resolve_expr (e
))
1884 /* See if the name is a module procedure in a parent unit. */
1886 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1889 if (gfc_find_sym_tree (sym
->name
, sym
->ns
->parent
, 1, &parent_st
))
1891 gfc_error ("Symbol %qs at %L is ambiguous", sym
->name
, &e
->where
);
1895 if (parent_st
== NULL
)
1898 sym
= parent_st
->n
.sym
;
1899 e
->symtree
= parent_st
; /* Point to the right thing. */
1901 if (sym
->attr
.flavor
== FL_PROCEDURE
1902 || sym
->attr
.intrinsic
1903 || sym
->attr
.external
)
1905 if (!gfc_resolve_expr (e
))
1911 e
->expr_type
= EXPR_VARIABLE
;
1913 if ((sym
->as
!= NULL
&& sym
->ts
.type
!= BT_CLASS
)
1914 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
1915 && CLASS_DATA (sym
)->as
))
1917 e
->rank
= sym
->ts
.type
== BT_CLASS
1918 ? CLASS_DATA (sym
)->as
->rank
: sym
->as
->rank
;
1919 e
->ref
= gfc_get_ref ();
1920 e
->ref
->type
= REF_ARRAY
;
1921 e
->ref
->u
.ar
.type
= AR_FULL
;
1922 e
->ref
->u
.ar
.as
= sym
->ts
.type
== BT_CLASS
1923 ? CLASS_DATA (sym
)->as
: sym
->as
;
1926 /* Expressions are assigned a default ts.type of BT_PROCEDURE in
1927 primary.c (match_actual_arg). If above code determines that it
1928 is a variable instead, it needs to be resolved as it was not
1929 done at the beginning of this function. */
1930 save_need_full_assumed_size
= need_full_assumed_size
;
1931 if (e
->expr_type
!= EXPR_VARIABLE
)
1932 need_full_assumed_size
= 0;
1933 if (!gfc_resolve_expr (e
))
1935 need_full_assumed_size
= save_need_full_assumed_size
;
1938 /* Check argument list functions %VAL, %LOC and %REF. There is
1939 nothing to do for %REF. */
1940 if (arg
->name
&& arg
->name
[0] == '%')
1942 if (strncmp ("%VAL", arg
->name
, 4) == 0)
1944 if (e
->ts
.type
== BT_CHARACTER
|| e
->ts
.type
== BT_DERIVED
)
1946 gfc_error ("By-value argument at %L is not of numeric "
1953 gfc_error ("By-value argument at %L cannot be an array or "
1954 "an array section", &e
->where
);
1958 /* Intrinsics are still PROC_UNKNOWN here. However,
1959 since same file external procedures are not resolvable
1960 in gfortran, it is a good deal easier to leave them to
1962 if (ptype
!= PROC_UNKNOWN
1963 && ptype
!= PROC_DUMMY
1964 && ptype
!= PROC_EXTERNAL
1965 && ptype
!= PROC_MODULE
)
1967 gfc_error ("By-value argument at %L is not allowed "
1968 "in this context", &e
->where
);
1973 /* Statement functions have already been excluded above. */
1974 else if (strncmp ("%LOC", arg
->name
, 4) == 0
1975 && e
->ts
.type
== BT_PROCEDURE
)
1977 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_INTERNAL
)
1979 gfc_error ("Passing internal procedure at %L by location "
1980 "not allowed", &e
->where
);
1986 comp
= gfc_get_proc_ptr_comp(e
);
1987 if (e
->expr_type
== EXPR_VARIABLE
1988 && comp
&& comp
->attr
.elemental
)
1990 gfc_error ("ELEMENTAL procedure pointer component %qs is not "
1991 "allowed as an actual argument at %L", comp
->name
,
1995 /* Fortran 2008, C1237. */
1996 if (e
->expr_type
== EXPR_VARIABLE
&& gfc_is_coindexed (e
)
1997 && gfc_has_ultimate_pointer (e
))
1999 gfc_error ("Coindexed actual argument at %L with ultimate pointer "
2000 "component", &e
->where
);
2004 first_actual_arg
= false;
2007 return_value
= true;
2010 actual_arg
= actual_arg_sav
;
2011 first_actual_arg
= first_actual_arg_sav
;
2013 return return_value
;
2017 /* Do the checks of the actual argument list that are specific to elemental
2018 procedures. If called with c == NULL, we have a function, otherwise if
2019 expr == NULL, we have a subroutine. */
2022 resolve_elemental_actual (gfc_expr
*expr
, gfc_code
*c
)
2024 gfc_actual_arglist
*arg0
;
2025 gfc_actual_arglist
*arg
;
2026 gfc_symbol
*esym
= NULL
;
2027 gfc_intrinsic_sym
*isym
= NULL
;
2029 gfc_intrinsic_arg
*iformal
= NULL
;
2030 gfc_formal_arglist
*eformal
= NULL
;
2031 bool formal_optional
= false;
2032 bool set_by_optional
= false;
2036 /* Is this an elemental procedure? */
2037 if (expr
&& expr
->value
.function
.actual
!= NULL
)
2039 if (expr
->value
.function
.esym
!= NULL
2040 && expr
->value
.function
.esym
->attr
.elemental
)
2042 arg0
= expr
->value
.function
.actual
;
2043 esym
= expr
->value
.function
.esym
;
2045 else if (expr
->value
.function
.isym
!= NULL
2046 && expr
->value
.function
.isym
->elemental
)
2048 arg0
= expr
->value
.function
.actual
;
2049 isym
= expr
->value
.function
.isym
;
2054 else if (c
&& c
->ext
.actual
!= NULL
)
2056 arg0
= c
->ext
.actual
;
2058 if (c
->resolved_sym
)
2059 esym
= c
->resolved_sym
;
2061 esym
= c
->symtree
->n
.sym
;
2064 if (!esym
->attr
.elemental
)
2070 /* The rank of an elemental is the rank of its array argument(s). */
2071 for (arg
= arg0
; arg
; arg
= arg
->next
)
2073 if (arg
->expr
!= NULL
&& arg
->expr
->rank
!= 0)
2075 rank
= arg
->expr
->rank
;
2076 if (arg
->expr
->expr_type
== EXPR_VARIABLE
2077 && arg
->expr
->symtree
->n
.sym
->attr
.optional
)
2078 set_by_optional
= true;
2080 /* Function specific; set the result rank and shape. */
2084 if (!expr
->shape
&& arg
->expr
->shape
)
2086 expr
->shape
= gfc_get_shape (rank
);
2087 for (i
= 0; i
< rank
; i
++)
2088 mpz_init_set (expr
->shape
[i
], arg
->expr
->shape
[i
]);
2095 /* If it is an array, it shall not be supplied as an actual argument
2096 to an elemental procedure unless an array of the same rank is supplied
2097 as an actual argument corresponding to a nonoptional dummy argument of
2098 that elemental procedure(12.4.1.5). */
2099 formal_optional
= false;
2101 iformal
= isym
->formal
;
2103 eformal
= esym
->formal
;
2105 for (arg
= arg0
; arg
; arg
= arg
->next
)
2109 if (eformal
->sym
&& eformal
->sym
->attr
.optional
)
2110 formal_optional
= true;
2111 eformal
= eformal
->next
;
2113 else if (isym
&& iformal
)
2115 if (iformal
->optional
)
2116 formal_optional
= true;
2117 iformal
= iformal
->next
;
2120 formal_optional
= true;
2122 if (pedantic
&& arg
->expr
!= NULL
2123 && arg
->expr
->expr_type
== EXPR_VARIABLE
2124 && arg
->expr
->symtree
->n
.sym
->attr
.optional
2127 && (set_by_optional
|| arg
->expr
->rank
!= rank
)
2128 && !(isym
&& isym
->id
== GFC_ISYM_CONVERSION
))
2130 gfc_warning (0, "%qs at %L is an array and OPTIONAL; IF IT IS "
2131 "MISSING, it cannot be the actual argument of an "
2132 "ELEMENTAL procedure unless there is a non-optional "
2133 "argument with the same rank (12.4.1.5)",
2134 arg
->expr
->symtree
->n
.sym
->name
, &arg
->expr
->where
);
2138 for (arg
= arg0
; arg
; arg
= arg
->next
)
2140 if (arg
->expr
== NULL
|| arg
->expr
->rank
== 0)
2143 /* Being elemental, the last upper bound of an assumed size array
2144 argument must be present. */
2145 if (resolve_assumed_size_actual (arg
->expr
))
2148 /* Elemental procedure's array actual arguments must conform. */
2151 if (!gfc_check_conformance (arg
->expr
, e
, "elemental procedure"))
2158 /* INTENT(OUT) is only allowed for subroutines; if any actual argument
2159 is an array, the intent inout/out variable needs to be also an array. */
2160 if (rank
> 0 && esym
&& expr
== NULL
)
2161 for (eformal
= esym
->formal
, arg
= arg0
; arg
&& eformal
;
2162 arg
= arg
->next
, eformal
= eformal
->next
)
2163 if ((eformal
->sym
->attr
.intent
== INTENT_OUT
2164 || eformal
->sym
->attr
.intent
== INTENT_INOUT
)
2165 && arg
->expr
&& arg
->expr
->rank
== 0)
2167 gfc_error ("Actual argument at %L for INTENT(%s) dummy %qs of "
2168 "ELEMENTAL subroutine %qs is a scalar, but another "
2169 "actual argument is an array", &arg
->expr
->where
,
2170 (eformal
->sym
->attr
.intent
== INTENT_OUT
) ? "OUT"
2171 : "INOUT", eformal
->sym
->name
, esym
->name
);
2178 /* This function does the checking of references to global procedures
2179 as defined in sections 18.1 and 14.1, respectively, of the Fortran
2180 77 and 95 standards. It checks for a gsymbol for the name, making
2181 one if it does not already exist. If it already exists, then the
2182 reference being resolved must correspond to the type of gsymbol.
2183 Otherwise, the new symbol is equipped with the attributes of the
2184 reference. The corresponding code that is called in creating
2185 global entities is parse.c.
2187 In addition, for all but -std=legacy, the gsymbols are used to
2188 check the interfaces of external procedures from the same file.
2189 The namespace of the gsymbol is resolved and then, once this is
2190 done the interface is checked. */
2194 not_in_recursive (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2196 if (!gsym_ns
->proc_name
->attr
.recursive
)
2199 if (sym
->ns
== gsym_ns
)
2202 if (sym
->ns
->parent
&& sym
->ns
->parent
== gsym_ns
)
2209 not_entry_self_reference (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2211 if (gsym_ns
->entries
)
2213 gfc_entry_list
*entry
= gsym_ns
->entries
;
2215 for (; entry
; entry
= entry
->next
)
2217 if (strcmp (sym
->name
, entry
->sym
->name
) == 0)
2219 if (strcmp (gsym_ns
->proc_name
->name
,
2220 sym
->ns
->proc_name
->name
) == 0)
2224 && strcmp (gsym_ns
->proc_name
->name
,
2225 sym
->ns
->parent
->proc_name
->name
) == 0)
2234 /* Check for the requirement of an explicit interface. F08:12.4.2.2. */
2237 gfc_explicit_interface_required (gfc_symbol
*sym
, char *errmsg
, int err_len
)
2239 gfc_formal_arglist
*arg
= gfc_sym_get_dummy_args (sym
);
2241 for ( ; arg
; arg
= arg
->next
)
2246 if (arg
->sym
->attr
.allocatable
) /* (2a) */
2248 strncpy (errmsg
, _("allocatable argument"), err_len
);
2251 else if (arg
->sym
->attr
.asynchronous
)
2253 strncpy (errmsg
, _("asynchronous argument"), err_len
);
2256 else if (arg
->sym
->attr
.optional
)
2258 strncpy (errmsg
, _("optional argument"), err_len
);
2261 else if (arg
->sym
->attr
.pointer
)
2263 strncpy (errmsg
, _("pointer argument"), err_len
);
2266 else if (arg
->sym
->attr
.target
)
2268 strncpy (errmsg
, _("target argument"), err_len
);
2271 else if (arg
->sym
->attr
.value
)
2273 strncpy (errmsg
, _("value argument"), err_len
);
2276 else if (arg
->sym
->attr
.volatile_
)
2278 strncpy (errmsg
, _("volatile argument"), err_len
);
2281 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_SHAPE
) /* (2b) */
2283 strncpy (errmsg
, _("assumed-shape argument"), err_len
);
2286 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_RANK
) /* TS 29113, 6.2. */
2288 strncpy (errmsg
, _("assumed-rank argument"), err_len
);
2291 else if (arg
->sym
->attr
.codimension
) /* (2c) */
2293 strncpy (errmsg
, _("coarray argument"), err_len
);
2296 else if (false) /* (2d) TODO: parametrized derived type */
2298 strncpy (errmsg
, _("parametrized derived type argument"), err_len
);
2301 else if (arg
->sym
->ts
.type
== BT_CLASS
) /* (2e) */
2303 strncpy (errmsg
, _("polymorphic argument"), err_len
);
2306 else if (arg
->sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
2308 strncpy (errmsg
, _("NO_ARG_CHECK attribute"), err_len
);
2311 else if (arg
->sym
->ts
.type
== BT_ASSUMED
)
2313 /* As assumed-type is unlimited polymorphic (cf. above).
2314 See also TS 29113, Note 6.1. */
2315 strncpy (errmsg
, _("assumed-type argument"), err_len
);
2320 if (sym
->attr
.function
)
2322 gfc_symbol
*res
= sym
->result
? sym
->result
: sym
;
2324 if (res
->attr
.dimension
) /* (3a) */
2326 strncpy (errmsg
, _("array result"), err_len
);
2329 else if (res
->attr
.pointer
|| res
->attr
.allocatable
) /* (3b) */
2331 strncpy (errmsg
, _("pointer or allocatable result"), err_len
);
2334 else if (res
->ts
.type
== BT_CHARACTER
&& res
->ts
.u
.cl
2335 && res
->ts
.u
.cl
->length
2336 && res
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
) /* (3c) */
2338 strncpy (errmsg
, _("result with non-constant character length"), err_len
);
2343 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
) /* (4) */
2345 strncpy (errmsg
, _("elemental procedure"), err_len
);
2348 else if (sym
->attr
.is_bind_c
) /* (5) */
2350 strncpy (errmsg
, _("bind(c) procedure"), err_len
);
2359 resolve_global_procedure (gfc_symbol
*sym
, locus
*where
,
2360 gfc_actual_arglist
**actual
, int sub
)
2364 enum gfc_symbol_type type
;
2367 type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
2369 gsym
= gfc_get_gsymbol (sym
->binding_label
? sym
->binding_label
: sym
->name
);
2371 if ((gsym
->type
!= GSYM_UNKNOWN
&& gsym
->type
!= type
))
2372 gfc_global_used (gsym
, where
);
2374 if ((sym
->attr
.if_source
== IFSRC_UNKNOWN
2375 || sym
->attr
.if_source
== IFSRC_IFBODY
)
2376 && gsym
->type
!= GSYM_UNKNOWN
2377 && !gsym
->binding_label
2379 && gsym
->ns
->resolved
!= -1
2380 && gsym
->ns
->proc_name
2381 && not_in_recursive (sym
, gsym
->ns
)
2382 && not_entry_self_reference (sym
, gsym
->ns
))
2384 gfc_symbol
*def_sym
;
2386 /* Resolve the gsymbol namespace if needed. */
2387 if (!gsym
->ns
->resolved
)
2389 gfc_dt_list
*old_dt_list
;
2391 /* Stash away derived types so that the backend_decls do not
2393 old_dt_list
= gfc_derived_types
;
2394 gfc_derived_types
= NULL
;
2396 gfc_resolve (gsym
->ns
);
2398 /* Store the new derived types with the global namespace. */
2399 if (gfc_derived_types
)
2400 gsym
->ns
->derived_types
= gfc_derived_types
;
2402 /* Restore the derived types of this namespace. */
2403 gfc_derived_types
= old_dt_list
;
2406 /* Make sure that translation for the gsymbol occurs before
2407 the procedure currently being resolved. */
2408 ns
= gfc_global_ns_list
;
2409 for (; ns
&& ns
!= gsym
->ns
; ns
= ns
->sibling
)
2411 if (ns
->sibling
== gsym
->ns
)
2413 ns
->sibling
= gsym
->ns
->sibling
;
2414 gsym
->ns
->sibling
= gfc_global_ns_list
;
2415 gfc_global_ns_list
= gsym
->ns
;
2420 def_sym
= gsym
->ns
->proc_name
;
2422 /* This can happen if a binding name has been specified. */
2423 if (gsym
->binding_label
&& gsym
->sym_name
!= def_sym
->name
)
2424 gfc_find_symbol (gsym
->sym_name
, gsym
->ns
, 0, &def_sym
);
2426 if (def_sym
->attr
.entry_master
)
2428 gfc_entry_list
*entry
;
2429 for (entry
= gsym
->ns
->entries
; entry
; entry
= entry
->next
)
2430 if (strcmp (entry
->sym
->name
, sym
->name
) == 0)
2432 def_sym
= entry
->sym
;
2437 if (sym
->attr
.function
&& !gfc_compare_types (&sym
->ts
, &def_sym
->ts
))
2439 gfc_error ("Return type mismatch of function %qs at %L (%s/%s)",
2440 sym
->name
, &sym
->declared_at
, gfc_typename (&sym
->ts
),
2441 gfc_typename (&def_sym
->ts
));
2445 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
2446 && gfc_explicit_interface_required (def_sym
, reason
, sizeof(reason
)))
2448 gfc_error ("Explicit interface required for %qs at %L: %s",
2449 sym
->name
, &sym
->declared_at
, reason
);
2453 if (!pedantic
&& (gfc_option
.allow_std
& GFC_STD_GNU
))
2454 /* Turn erros into warnings with -std=gnu and -std=legacy. */
2455 gfc_errors_to_warnings (true);
2457 if (!gfc_compare_interfaces (sym
, def_sym
, sym
->name
, 0, 1,
2458 reason
, sizeof(reason
), NULL
, NULL
))
2460 gfc_error ("Interface mismatch in global procedure %qs at %L: %s ",
2461 sym
->name
, &sym
->declared_at
, reason
);
2466 || ((gfc_option
.warn_std
& GFC_STD_LEGACY
)
2467 && !(gfc_option
.warn_std
& GFC_STD_GNU
)))
2468 gfc_errors_to_warnings (true);
2470 if (sym
->attr
.if_source
!= IFSRC_IFBODY
)
2471 gfc_procedure_use (def_sym
, actual
, where
);
2475 gfc_errors_to_warnings (false);
2477 if (gsym
->type
== GSYM_UNKNOWN
)
2480 gsym
->where
= *where
;
2487 /************* Function resolution *************/
2489 /* Resolve a function call known to be generic.
2490 Section 14.1.2.4.1. */
2493 resolve_generic_f0 (gfc_expr
*expr
, gfc_symbol
*sym
)
2497 if (sym
->attr
.generic
)
2499 s
= gfc_search_interface (sym
->generic
, 0, &expr
->value
.function
.actual
);
2502 expr
->value
.function
.name
= s
->name
;
2503 expr
->value
.function
.esym
= s
;
2505 if (s
->ts
.type
!= BT_UNKNOWN
)
2507 else if (s
->result
!= NULL
&& s
->result
->ts
.type
!= BT_UNKNOWN
)
2508 expr
->ts
= s
->result
->ts
;
2511 expr
->rank
= s
->as
->rank
;
2512 else if (s
->result
!= NULL
&& s
->result
->as
!= NULL
)
2513 expr
->rank
= s
->result
->as
->rank
;
2515 gfc_set_sym_referenced (expr
->value
.function
.esym
);
2520 /* TODO: Need to search for elemental references in generic
2524 if (sym
->attr
.intrinsic
)
2525 return gfc_intrinsic_func_interface (expr
, 0);
2532 resolve_generic_f (gfc_expr
*expr
)
2536 gfc_interface
*intr
= NULL
;
2538 sym
= expr
->symtree
->n
.sym
;
2542 m
= resolve_generic_f0 (expr
, sym
);
2545 else if (m
== MATCH_ERROR
)
2550 for (intr
= sym
->generic
; intr
; intr
= intr
->next
)
2551 if (intr
->sym
->attr
.flavor
== FL_DERIVED
)
2554 if (sym
->ns
->parent
== NULL
)
2556 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2560 if (!generic_sym (sym
))
2564 /* Last ditch attempt. See if the reference is to an intrinsic
2565 that possesses a matching interface. 14.1.2.4 */
2566 if (sym
&& !intr
&& !gfc_is_intrinsic (sym
, 0, expr
->where
))
2568 gfc_error ("There is no specific function for the generic %qs "
2569 "at %L", expr
->symtree
->n
.sym
->name
, &expr
->where
);
2575 if (!gfc_convert_to_structure_constructor (expr
, intr
->sym
, NULL
,
2578 return resolve_structure_cons (expr
, 0);
2581 m
= gfc_intrinsic_func_interface (expr
, 0);
2586 gfc_error ("Generic function %qs at %L is not consistent with a "
2587 "specific intrinsic interface", expr
->symtree
->n
.sym
->name
,
2594 /* Resolve a function call known to be specific. */
2597 resolve_specific_f0 (gfc_symbol
*sym
, gfc_expr
*expr
)
2601 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
2603 if (sym
->attr
.dummy
)
2605 sym
->attr
.proc
= PROC_DUMMY
;
2609 sym
->attr
.proc
= PROC_EXTERNAL
;
2613 if (sym
->attr
.proc
== PROC_MODULE
2614 || sym
->attr
.proc
== PROC_ST_FUNCTION
2615 || sym
->attr
.proc
== PROC_INTERNAL
)
2618 if (sym
->attr
.intrinsic
)
2620 m
= gfc_intrinsic_func_interface (expr
, 1);
2624 gfc_error ("Function %qs at %L is INTRINSIC but is not compatible "
2625 "with an intrinsic", sym
->name
, &expr
->where
);
2633 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2636 expr
->ts
= sym
->result
->ts
;
2639 expr
->value
.function
.name
= sym
->name
;
2640 expr
->value
.function
.esym
= sym
;
2641 /* Prevent crash when sym->ts.u.derived->components is not set due to previous
2643 if (sym
->ts
.type
== BT_CLASS
&& !CLASS_DATA (sym
))
2645 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->as
)
2646 expr
->rank
= CLASS_DATA (sym
)->as
->rank
;
2647 else if (sym
->as
!= NULL
)
2648 expr
->rank
= sym
->as
->rank
;
2655 resolve_specific_f (gfc_expr
*expr
)
2660 sym
= expr
->symtree
->n
.sym
;
2664 m
= resolve_specific_f0 (sym
, expr
);
2667 if (m
== MATCH_ERROR
)
2670 if (sym
->ns
->parent
== NULL
)
2673 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2679 gfc_error ("Unable to resolve the specific function %qs at %L",
2680 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2686 /* Resolve a procedure call not known to be generic nor specific. */
2689 resolve_unknown_f (gfc_expr
*expr
)
2694 sym
= expr
->symtree
->n
.sym
;
2696 if (sym
->attr
.dummy
)
2698 sym
->attr
.proc
= PROC_DUMMY
;
2699 expr
->value
.function
.name
= sym
->name
;
2703 /* See if we have an intrinsic function reference. */
2705 if (gfc_is_intrinsic (sym
, 0, expr
->where
))
2707 if (gfc_intrinsic_func_interface (expr
, 1) == MATCH_YES
)
2712 /* The reference is to an external name. */
2714 sym
->attr
.proc
= PROC_EXTERNAL
;
2715 expr
->value
.function
.name
= sym
->name
;
2716 expr
->value
.function
.esym
= expr
->symtree
->n
.sym
;
2718 if (sym
->as
!= NULL
)
2719 expr
->rank
= sym
->as
->rank
;
2721 /* Type of the expression is either the type of the symbol or the
2722 default type of the symbol. */
2725 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2727 if (sym
->ts
.type
!= BT_UNKNOWN
)
2731 ts
= gfc_get_default_type (sym
->name
, sym
->ns
);
2733 if (ts
->type
== BT_UNKNOWN
)
2735 gfc_error ("Function %qs at %L has no IMPLICIT type",
2736 sym
->name
, &expr
->where
);
2747 /* Return true, if the symbol is an external procedure. */
2749 is_external_proc (gfc_symbol
*sym
)
2751 if (!sym
->attr
.dummy
&& !sym
->attr
.contained
2752 && !gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, sym
->declared_at
)
2753 && sym
->attr
.proc
!= PROC_ST_FUNCTION
2754 && !sym
->attr
.proc_pointer
2755 && !sym
->attr
.use_assoc
2763 /* Figure out if a function reference is pure or not. Also set the name
2764 of the function for a potential error message. Return nonzero if the
2765 function is PURE, zero if not. */
2767 pure_stmt_function (gfc_expr
*, gfc_symbol
*);
2770 pure_function (gfc_expr
*e
, const char **name
)
2773 gfc_component
*comp
;
2777 if (e
->symtree
!= NULL
2778 && e
->symtree
->n
.sym
!= NULL
2779 && e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2780 return pure_stmt_function (e
, e
->symtree
->n
.sym
);
2782 comp
= gfc_get_proc_ptr_comp (e
);
2785 pure
= gfc_pure (comp
->ts
.interface
);
2788 else if (e
->value
.function
.esym
)
2790 pure
= gfc_pure (e
->value
.function
.esym
);
2791 *name
= e
->value
.function
.esym
->name
;
2793 else if (e
->value
.function
.isym
)
2795 pure
= e
->value
.function
.isym
->pure
2796 || e
->value
.function
.isym
->elemental
;
2797 *name
= e
->value
.function
.isym
->name
;
2801 /* Implicit functions are not pure. */
2803 *name
= e
->value
.function
.name
;
2811 impure_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
,
2812 int *f ATTRIBUTE_UNUSED
)
2816 /* Don't bother recursing into other statement functions
2817 since they will be checked individually for purity. */
2818 if (e
->expr_type
!= EXPR_FUNCTION
2820 || e
->symtree
->n
.sym
== sym
2821 || e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2824 return pure_function (e
, &name
) ? false : true;
2829 pure_stmt_function (gfc_expr
*e
, gfc_symbol
*sym
)
2831 return gfc_traverse_expr (e
, sym
, impure_stmt_fcn
, 0) ? 0 : 1;
2835 /* Check if an impure function is allowed in the current context. */
2837 static bool check_pure_function (gfc_expr
*e
)
2839 const char *name
= NULL
;
2840 if (!pure_function (e
, &name
) && name
)
2844 gfc_error ("Reference to impure function %qs at %L inside a "
2845 "FORALL %s", name
, &e
->where
,
2846 forall_flag
== 2 ? "mask" : "block");
2849 else if (gfc_do_concurrent_flag
)
2851 gfc_error ("Reference to impure function %qs at %L inside a "
2852 "DO CONCURRENT %s", name
, &e
->where
,
2853 gfc_do_concurrent_flag
== 2 ? "mask" : "block");
2856 else if (gfc_pure (NULL
))
2858 gfc_error ("Reference to impure function %qs at %L "
2859 "within a PURE procedure", name
, &e
->where
);
2862 gfc_unset_implicit_pure (NULL
);
2868 /* Update current procedure's array_outer_dependency flag, considering
2869 a call to procedure SYM. */
2872 update_current_proc_array_outer_dependency (gfc_symbol
*sym
)
2874 /* Check to see if this is a sibling function that has not yet
2876 gfc_namespace
*sibling
= gfc_current_ns
->sibling
;
2877 for (; sibling
; sibling
= sibling
->sibling
)
2879 if (sibling
->proc_name
== sym
)
2881 gfc_resolve (sibling
);
2886 /* If SYM has references to outer arrays, so has the procedure calling
2887 SYM. If SYM is a procedure pointer, we can assume the worst. */
2888 if (sym
->attr
.array_outer_dependency
2889 || sym
->attr
.proc_pointer
)
2890 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
2894 /* Resolve a function call, which means resolving the arguments, then figuring
2895 out which entity the name refers to. */
2898 resolve_function (gfc_expr
*expr
)
2900 gfc_actual_arglist
*arg
;
2904 procedure_type p
= PROC_INTRINSIC
;
2905 bool no_formal_args
;
2909 sym
= expr
->symtree
->n
.sym
;
2911 /* If this is a procedure pointer component, it has already been resolved. */
2912 if (gfc_is_proc_ptr_comp (expr
))
2915 if (sym
&& sym
->attr
.intrinsic
2916 && !gfc_resolve_intrinsic (sym
, &expr
->where
))
2919 if (sym
&& (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.subroutine
))
2921 gfc_error ("%qs at %L is not a function", sym
->name
, &expr
->where
);
2925 /* If this ia a deferred TBP with an abstract interface (which may
2926 of course be referenced), expr->value.function.esym will be set. */
2927 if (sym
&& sym
->attr
.abstract
&& !expr
->value
.function
.esym
)
2929 gfc_error ("ABSTRACT INTERFACE %qs must not be referenced at %L",
2930 sym
->name
, &expr
->where
);
2934 /* Switch off assumed size checking and do this again for certain kinds
2935 of procedure, once the procedure itself is resolved. */
2936 need_full_assumed_size
++;
2938 if (expr
->symtree
&& expr
->symtree
->n
.sym
)
2939 p
= expr
->symtree
->n
.sym
->attr
.proc
;
2941 if (expr
->value
.function
.isym
&& expr
->value
.function
.isym
->inquiry
)
2942 inquiry_argument
= true;
2943 no_formal_args
= sym
&& is_external_proc (sym
)
2944 && gfc_sym_get_dummy_args (sym
) == NULL
;
2946 if (!resolve_actual_arglist (expr
->value
.function
.actual
,
2949 inquiry_argument
= false;
2953 inquiry_argument
= false;
2955 /* Resume assumed_size checking. */
2956 need_full_assumed_size
--;
2958 /* If the procedure is external, check for usage. */
2959 if (sym
&& is_external_proc (sym
))
2960 resolve_global_procedure (sym
, &expr
->where
,
2961 &expr
->value
.function
.actual
, 0);
2963 if (sym
&& sym
->ts
.type
== BT_CHARACTER
2965 && sym
->ts
.u
.cl
->length
== NULL
2967 && !sym
->ts
.deferred
2968 && expr
->value
.function
.esym
== NULL
2969 && !sym
->attr
.contained
)
2971 /* Internal procedures are taken care of in resolve_contained_fntype. */
2972 gfc_error ("Function %qs is declared CHARACTER(*) and cannot "
2973 "be used at %L since it is not a dummy argument",
2974 sym
->name
, &expr
->where
);
2978 /* See if function is already resolved. */
2980 if (expr
->value
.function
.name
!= NULL
2981 || expr
->value
.function
.isym
!= NULL
)
2983 if (expr
->ts
.type
== BT_UNKNOWN
)
2989 /* Apply the rules of section 14.1.2. */
2991 switch (procedure_kind (sym
))
2994 t
= resolve_generic_f (expr
);
2997 case PTYPE_SPECIFIC
:
2998 t
= resolve_specific_f (expr
);
3002 t
= resolve_unknown_f (expr
);
3006 gfc_internal_error ("resolve_function(): bad function type");
3010 /* If the expression is still a function (it might have simplified),
3011 then we check to see if we are calling an elemental function. */
3013 if (expr
->expr_type
!= EXPR_FUNCTION
)
3016 temp
= need_full_assumed_size
;
3017 need_full_assumed_size
= 0;
3019 if (!resolve_elemental_actual (expr
, NULL
))
3022 if (omp_workshare_flag
3023 && expr
->value
.function
.esym
3024 && ! gfc_elemental (expr
->value
.function
.esym
))
3026 gfc_error ("User defined non-ELEMENTAL function %qs at %L not allowed "
3027 "in WORKSHARE construct", expr
->value
.function
.esym
->name
,
3032 #define GENERIC_ID expr->value.function.isym->id
3033 else if (expr
->value
.function
.actual
!= NULL
3034 && expr
->value
.function
.isym
!= NULL
3035 && GENERIC_ID
!= GFC_ISYM_LBOUND
3036 && GENERIC_ID
!= GFC_ISYM_LCOBOUND
3037 && GENERIC_ID
!= GFC_ISYM_UCOBOUND
3038 && GENERIC_ID
!= GFC_ISYM_LEN
3039 && GENERIC_ID
!= GFC_ISYM_LOC
3040 && GENERIC_ID
!= GFC_ISYM_C_LOC
3041 && GENERIC_ID
!= GFC_ISYM_PRESENT
)
3043 /* Array intrinsics must also have the last upper bound of an
3044 assumed size array argument. UBOUND and SIZE have to be
3045 excluded from the check if the second argument is anything
3048 for (arg
= expr
->value
.function
.actual
; arg
; arg
= arg
->next
)
3050 if ((GENERIC_ID
== GFC_ISYM_UBOUND
|| GENERIC_ID
== GFC_ISYM_SIZE
)
3051 && arg
== expr
->value
.function
.actual
3052 && arg
->next
!= NULL
&& arg
->next
->expr
)
3054 if (arg
->next
->expr
->expr_type
!= EXPR_CONSTANT
)
3057 if (arg
->next
->name
&& strncmp (arg
->next
->name
, "kind", 4) == 0)
3060 if ((int)mpz_get_si (arg
->next
->expr
->value
.integer
)
3065 if (arg
->expr
!= NULL
3066 && arg
->expr
->rank
> 0
3067 && resolve_assumed_size_actual (arg
->expr
))
3073 need_full_assumed_size
= temp
;
3075 if (!check_pure_function(expr
))
3078 /* Functions without the RECURSIVE attribution are not allowed to
3079 * call themselves. */
3080 if (expr
->value
.function
.esym
&& !expr
->value
.function
.esym
->attr
.recursive
)
3083 esym
= expr
->value
.function
.esym
;
3085 if (is_illegal_recursion (esym
, gfc_current_ns
))
3087 if (esym
->attr
.entry
&& esym
->ns
->entries
)
3088 gfc_error ("ENTRY %qs at %L cannot be called recursively, as"
3089 " function %qs is not RECURSIVE",
3090 esym
->name
, &expr
->where
, esym
->ns
->entries
->sym
->name
);
3092 gfc_error ("Function %qs at %L cannot be called recursively, as it"
3093 " is not RECURSIVE", esym
->name
, &expr
->where
);
3099 /* Character lengths of use associated functions may contains references to
3100 symbols not referenced from the current program unit otherwise. Make sure
3101 those symbols are marked as referenced. */
3103 if (expr
->ts
.type
== BT_CHARACTER
&& expr
->value
.function
.esym
3104 && expr
->value
.function
.esym
->attr
.use_assoc
)
3106 gfc_expr_set_symbols_referenced (expr
->ts
.u
.cl
->length
);
3109 /* Make sure that the expression has a typespec that works. */
3110 if (expr
->ts
.type
== BT_UNKNOWN
)
3112 if (expr
->symtree
->n
.sym
->result
3113 && expr
->symtree
->n
.sym
->result
->ts
.type
!= BT_UNKNOWN
3114 && !expr
->symtree
->n
.sym
->result
->attr
.proc_pointer
)
3115 expr
->ts
= expr
->symtree
->n
.sym
->result
->ts
;
3118 if (!expr
->ref
&& !expr
->value
.function
.isym
)
3120 if (expr
->value
.function
.esym
)
3121 update_current_proc_array_outer_dependency (expr
->value
.function
.esym
);
3123 update_current_proc_array_outer_dependency (sym
);
3126 /* typebound procedure: Assume the worst. */
3127 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
3133 /************* Subroutine resolution *************/
3136 pure_subroutine (gfc_symbol
*sym
, const char *name
, locus
*loc
)
3143 gfc_error ("Subroutine call to %qs in FORALL block at %L is not PURE",
3147 else if (gfc_do_concurrent_flag
)
3149 gfc_error ("Subroutine call to %qs in DO CONCURRENT block at %L is not "
3153 else if (gfc_pure (NULL
))
3155 gfc_error ("Subroutine call to %qs at %L is not PURE", name
, loc
);
3159 gfc_unset_implicit_pure (NULL
);
3165 resolve_generic_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3169 if (sym
->attr
.generic
)
3171 s
= gfc_search_interface (sym
->generic
, 1, &c
->ext
.actual
);
3174 c
->resolved_sym
= s
;
3175 if (!pure_subroutine (s
, s
->name
, &c
->loc
))
3180 /* TODO: Need to search for elemental references in generic interface. */
3183 if (sym
->attr
.intrinsic
)
3184 return gfc_intrinsic_sub_interface (c
, 0);
3191 resolve_generic_s (gfc_code
*c
)
3196 sym
= c
->symtree
->n
.sym
;
3200 m
= resolve_generic_s0 (c
, sym
);
3203 else if (m
== MATCH_ERROR
)
3207 if (sym
->ns
->parent
== NULL
)
3209 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3213 if (!generic_sym (sym
))
3217 /* Last ditch attempt. See if the reference is to an intrinsic
3218 that possesses a matching interface. 14.1.2.4 */
3219 sym
= c
->symtree
->n
.sym
;
3221 if (!gfc_is_intrinsic (sym
, 1, c
->loc
))
3223 gfc_error ("There is no specific subroutine for the generic %qs at %L",
3224 sym
->name
, &c
->loc
);
3228 m
= gfc_intrinsic_sub_interface (c
, 0);
3232 gfc_error ("Generic subroutine %qs at %L is not consistent with an "
3233 "intrinsic subroutine interface", sym
->name
, &c
->loc
);
3239 /* Resolve a subroutine call known to be specific. */
3242 resolve_specific_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3246 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
3248 if (sym
->attr
.dummy
)
3250 sym
->attr
.proc
= PROC_DUMMY
;
3254 sym
->attr
.proc
= PROC_EXTERNAL
;
3258 if (sym
->attr
.proc
== PROC_MODULE
|| sym
->attr
.proc
== PROC_INTERNAL
)
3261 if (sym
->attr
.intrinsic
)
3263 m
= gfc_intrinsic_sub_interface (c
, 1);
3267 gfc_error ("Subroutine %qs at %L is INTRINSIC but is not compatible "
3268 "with an intrinsic", sym
->name
, &c
->loc
);
3276 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3278 c
->resolved_sym
= sym
;
3279 if (!pure_subroutine (sym
, sym
->name
, &c
->loc
))
3287 resolve_specific_s (gfc_code
*c
)
3292 sym
= c
->symtree
->n
.sym
;
3296 m
= resolve_specific_s0 (c
, sym
);
3299 if (m
== MATCH_ERROR
)
3302 if (sym
->ns
->parent
== NULL
)
3305 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3311 sym
= c
->symtree
->n
.sym
;
3312 gfc_error ("Unable to resolve the specific subroutine %qs at %L",
3313 sym
->name
, &c
->loc
);
3319 /* Resolve a subroutine call not known to be generic nor specific. */
3322 resolve_unknown_s (gfc_code
*c
)
3326 sym
= c
->symtree
->n
.sym
;
3328 if (sym
->attr
.dummy
)
3330 sym
->attr
.proc
= PROC_DUMMY
;
3334 /* See if we have an intrinsic function reference. */
3336 if (gfc_is_intrinsic (sym
, 1, c
->loc
))
3338 if (gfc_intrinsic_sub_interface (c
, 1) == MATCH_YES
)
3343 /* The reference is to an external name. */
3346 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3348 c
->resolved_sym
= sym
;
3350 return pure_subroutine (sym
, sym
->name
, &c
->loc
);
3354 /* Resolve a subroutine call. Although it was tempting to use the same code
3355 for functions, subroutines and functions are stored differently and this
3356 makes things awkward. */
3359 resolve_call (gfc_code
*c
)
3362 procedure_type ptype
= PROC_INTRINSIC
;
3363 gfc_symbol
*csym
, *sym
;
3364 bool no_formal_args
;
3366 csym
= c
->symtree
? c
->symtree
->n
.sym
: NULL
;
3368 if (csym
&& csym
->ts
.type
!= BT_UNKNOWN
)
3370 gfc_error ("%qs at %L has a type, which is not consistent with "
3371 "the CALL at %L", csym
->name
, &csym
->declared_at
, &c
->loc
);
3375 if (csym
&& gfc_current_ns
->parent
&& csym
->ns
!= gfc_current_ns
)
3378 gfc_find_sym_tree (c
->symtree
->name
, gfc_current_ns
, 1, &st
);
3379 sym
= st
? st
->n
.sym
: NULL
;
3380 if (sym
&& csym
!= sym
3381 && sym
->ns
== gfc_current_ns
3382 && sym
->attr
.flavor
== FL_PROCEDURE
3383 && sym
->attr
.contained
)
3386 if (csym
->attr
.generic
)
3387 c
->symtree
->n
.sym
= sym
;
3390 csym
= c
->symtree
->n
.sym
;
3394 /* If this ia a deferred TBP, c->expr1 will be set. */
3395 if (!c
->expr1
&& csym
)
3397 if (csym
->attr
.abstract
)
3399 gfc_error ("ABSTRACT INTERFACE %qs must not be referenced at %L",
3400 csym
->name
, &c
->loc
);
3404 /* Subroutines without the RECURSIVE attribution are not allowed to
3406 if (is_illegal_recursion (csym
, gfc_current_ns
))
3408 if (csym
->attr
.entry
&& csym
->ns
->entries
)
3409 gfc_error ("ENTRY %qs at %L cannot be called recursively, "
3410 "as subroutine %qs is not RECURSIVE",
3411 csym
->name
, &c
->loc
, csym
->ns
->entries
->sym
->name
);
3413 gfc_error ("SUBROUTINE %qs at %L cannot be called recursively, "
3414 "as it is not RECURSIVE", csym
->name
, &c
->loc
);
3420 /* Switch off assumed size checking and do this again for certain kinds
3421 of procedure, once the procedure itself is resolved. */
3422 need_full_assumed_size
++;
3425 ptype
= csym
->attr
.proc
;
3427 no_formal_args
= csym
&& is_external_proc (csym
)
3428 && gfc_sym_get_dummy_args (csym
) == NULL
;
3429 if (!resolve_actual_arglist (c
->ext
.actual
, ptype
, no_formal_args
))
3432 /* Resume assumed_size checking. */
3433 need_full_assumed_size
--;
3435 /* If external, check for usage. */
3436 if (csym
&& is_external_proc (csym
))
3437 resolve_global_procedure (csym
, &c
->loc
, &c
->ext
.actual
, 1);
3440 if (c
->resolved_sym
== NULL
)
3442 c
->resolved_isym
= NULL
;
3443 switch (procedure_kind (csym
))
3446 t
= resolve_generic_s (c
);
3449 case PTYPE_SPECIFIC
:
3450 t
= resolve_specific_s (c
);
3454 t
= resolve_unknown_s (c
);
3458 gfc_internal_error ("resolve_subroutine(): bad function type");
3462 /* Some checks of elemental subroutine actual arguments. */
3463 if (!resolve_elemental_actual (NULL
, c
))
3467 update_current_proc_array_outer_dependency (csym
);
3469 /* Typebound procedure: Assume the worst. */
3470 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
3476 /* Compare the shapes of two arrays that have non-NULL shapes. If both
3477 op1->shape and op2->shape are non-NULL return true if their shapes
3478 match. If both op1->shape and op2->shape are non-NULL return false
3479 if their shapes do not match. If either op1->shape or op2->shape is
3480 NULL, return true. */
3483 compare_shapes (gfc_expr
*op1
, gfc_expr
*op2
)
3490 if (op1
->shape
!= NULL
&& op2
->shape
!= NULL
)
3492 for (i
= 0; i
< op1
->rank
; i
++)
3494 if (mpz_cmp (op1
->shape
[i
], op2
->shape
[i
]) != 0)
3496 gfc_error ("Shapes for operands at %L and %L are not conformable",
3497 &op1
->where
, &op2
->where
);
3508 /* Resolve an operator expression node. This can involve replacing the
3509 operation with a user defined function call. */
3512 resolve_operator (gfc_expr
*e
)
3514 gfc_expr
*op1
, *op2
;
3516 bool dual_locus_error
;
3519 /* Resolve all subnodes-- give them types. */
3521 switch (e
->value
.op
.op
)
3524 if (!gfc_resolve_expr (e
->value
.op
.op2
))
3527 /* Fall through... */
3530 case INTRINSIC_UPLUS
:
3531 case INTRINSIC_UMINUS
:
3532 case INTRINSIC_PARENTHESES
:
3533 if (!gfc_resolve_expr (e
->value
.op
.op1
))
3538 /* Typecheck the new node. */
3540 op1
= e
->value
.op
.op1
;
3541 op2
= e
->value
.op
.op2
;
3542 dual_locus_error
= false;
3544 if ((op1
&& op1
->expr_type
== EXPR_NULL
)
3545 || (op2
&& op2
->expr_type
== EXPR_NULL
))
3547 sprintf (msg
, _("Invalid context for NULL() pointer at %%L"));
3551 switch (e
->value
.op
.op
)
3553 case INTRINSIC_UPLUS
:
3554 case INTRINSIC_UMINUS
:
3555 if (op1
->ts
.type
== BT_INTEGER
3556 || op1
->ts
.type
== BT_REAL
3557 || op1
->ts
.type
== BT_COMPLEX
)
3563 sprintf (msg
, _("Operand of unary numeric operator '%s' at %%L is %s"),
3564 gfc_op2string (e
->value
.op
.op
), gfc_typename (&e
->ts
));
3567 case INTRINSIC_PLUS
:
3568 case INTRINSIC_MINUS
:
3569 case INTRINSIC_TIMES
:
3570 case INTRINSIC_DIVIDE
:
3571 case INTRINSIC_POWER
:
3572 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3574 gfc_type_convert_binary (e
, 1);
3579 _("Operands of binary numeric operator '%s' at %%L are %s/%s"),
3580 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3581 gfc_typename (&op2
->ts
));
3584 case INTRINSIC_CONCAT
:
3585 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3586 && op1
->ts
.kind
== op2
->ts
.kind
)
3588 e
->ts
.type
= BT_CHARACTER
;
3589 e
->ts
.kind
= op1
->ts
.kind
;
3594 _("Operands of string concatenation operator at %%L are %s/%s"),
3595 gfc_typename (&op1
->ts
), gfc_typename (&op2
->ts
));
3601 case INTRINSIC_NEQV
:
3602 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3604 e
->ts
.type
= BT_LOGICAL
;
3605 e
->ts
.kind
= gfc_kind_max (op1
, op2
);
3606 if (op1
->ts
.kind
< e
->ts
.kind
)
3607 gfc_convert_type (op1
, &e
->ts
, 2);
3608 else if (op2
->ts
.kind
< e
->ts
.kind
)
3609 gfc_convert_type (op2
, &e
->ts
, 2);
3613 sprintf (msg
, _("Operands of logical operator '%s' at %%L are %s/%s"),
3614 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3615 gfc_typename (&op2
->ts
));
3620 if (op1
->ts
.type
== BT_LOGICAL
)
3622 e
->ts
.type
= BT_LOGICAL
;
3623 e
->ts
.kind
= op1
->ts
.kind
;
3627 sprintf (msg
, _("Operand of .not. operator at %%L is %s"),
3628 gfc_typename (&op1
->ts
));
3632 case INTRINSIC_GT_OS
:
3634 case INTRINSIC_GE_OS
:
3636 case INTRINSIC_LT_OS
:
3638 case INTRINSIC_LE_OS
:
3639 if (op1
->ts
.type
== BT_COMPLEX
|| op2
->ts
.type
== BT_COMPLEX
)
3641 strcpy (msg
, _("COMPLEX quantities cannot be compared at %L"));
3645 /* Fall through... */
3648 case INTRINSIC_EQ_OS
:
3650 case INTRINSIC_NE_OS
:
3651 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3652 && op1
->ts
.kind
== op2
->ts
.kind
)
3654 e
->ts
.type
= BT_LOGICAL
;
3655 e
->ts
.kind
= gfc_default_logical_kind
;
3659 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3661 gfc_type_convert_binary (e
, 1);
3663 e
->ts
.type
= BT_LOGICAL
;
3664 e
->ts
.kind
= gfc_default_logical_kind
;
3666 if (warn_compare_reals
)
3668 gfc_intrinsic_op op
= e
->value
.op
.op
;
3670 /* Type conversion has made sure that the types of op1 and op2
3671 agree, so it is only necessary to check the first one. */
3672 if ((op1
->ts
.type
== BT_REAL
|| op1
->ts
.type
== BT_COMPLEX
)
3673 && (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
3674 || op
== INTRINSIC_NE
|| op
== INTRINSIC_NE_OS
))
3678 if (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
)
3679 msg
= "Equality comparison for %s at %L";
3681 msg
= "Inequality comparison for %s at %L";
3683 gfc_warning (0, msg
, gfc_typename (&op1
->ts
), &op1
->where
);
3690 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3692 _("Logicals at %%L must be compared with %s instead of %s"),
3693 (e
->value
.op
.op
== INTRINSIC_EQ
3694 || e
->value
.op
.op
== INTRINSIC_EQ_OS
)
3695 ? ".eqv." : ".neqv.", gfc_op2string (e
->value
.op
.op
));
3698 _("Operands of comparison operator '%s' at %%L are %s/%s"),
3699 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3700 gfc_typename (&op2
->ts
));
3704 case INTRINSIC_USER
:
3705 if (e
->value
.op
.uop
->op
== NULL
)
3706 sprintf (msg
, _("Unknown operator '%s' at %%L"), e
->value
.op
.uop
->name
);
3707 else if (op2
== NULL
)
3708 sprintf (msg
, _("Operand of user operator '%s' at %%L is %s"),
3709 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
));
3712 sprintf (msg
, _("Operands of user operator '%s' at %%L are %s/%s"),
3713 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
),
3714 gfc_typename (&op2
->ts
));
3715 e
->value
.op
.uop
->op
->sym
->attr
.referenced
= 1;
3720 case INTRINSIC_PARENTHESES
:
3722 if (e
->ts
.type
== BT_CHARACTER
)
3723 e
->ts
.u
.cl
= op1
->ts
.u
.cl
;
3727 gfc_internal_error ("resolve_operator(): Bad intrinsic");
3730 /* Deal with arrayness of an operand through an operator. */
3734 switch (e
->value
.op
.op
)
3736 case INTRINSIC_PLUS
:
3737 case INTRINSIC_MINUS
:
3738 case INTRINSIC_TIMES
:
3739 case INTRINSIC_DIVIDE
:
3740 case INTRINSIC_POWER
:
3741 case INTRINSIC_CONCAT
:
3745 case INTRINSIC_NEQV
:
3747 case INTRINSIC_EQ_OS
:
3749 case INTRINSIC_NE_OS
:
3751 case INTRINSIC_GT_OS
:
3753 case INTRINSIC_GE_OS
:
3755 case INTRINSIC_LT_OS
:
3757 case INTRINSIC_LE_OS
:
3759 if (op1
->rank
== 0 && op2
->rank
== 0)
3762 if (op1
->rank
== 0 && op2
->rank
!= 0)
3764 e
->rank
= op2
->rank
;
3766 if (e
->shape
== NULL
)
3767 e
->shape
= gfc_copy_shape (op2
->shape
, op2
->rank
);
3770 if (op1
->rank
!= 0 && op2
->rank
== 0)
3772 e
->rank
= op1
->rank
;
3774 if (e
->shape
== NULL
)
3775 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3778 if (op1
->rank
!= 0 && op2
->rank
!= 0)
3780 if (op1
->rank
== op2
->rank
)
3782 e
->rank
= op1
->rank
;
3783 if (e
->shape
== NULL
)
3785 t
= compare_shapes (op1
, op2
);
3789 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3794 /* Allow higher level expressions to work. */
3797 /* Try user-defined operators, and otherwise throw an error. */
3798 dual_locus_error
= true;
3800 _("Inconsistent ranks for operator at %%L and %%L"));
3807 case INTRINSIC_PARENTHESES
:
3809 case INTRINSIC_UPLUS
:
3810 case INTRINSIC_UMINUS
:
3811 /* Simply copy arrayness attribute */
3812 e
->rank
= op1
->rank
;
3814 if (e
->shape
== NULL
)
3815 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3823 /* Attempt to simplify the expression. */
3826 t
= gfc_simplify_expr (e
, 0);
3827 /* Some calls do not succeed in simplification and return false
3828 even though there is no error; e.g. variable references to
3829 PARAMETER arrays. */
3830 if (!gfc_is_constant_expr (e
))
3838 match m
= gfc_extend_expr (e
);
3841 if (m
== MATCH_ERROR
)
3845 if (dual_locus_error
)
3846 gfc_error (msg
, &op1
->where
, &op2
->where
);
3848 gfc_error (msg
, &e
->where
);
3854 /************** Array resolution subroutines **************/
3857 { CMP_LT
, CMP_EQ
, CMP_GT
, CMP_UNKNOWN
};
3859 /* Compare two integer expressions. */
3861 static compare_result
3862 compare_bound (gfc_expr
*a
, gfc_expr
*b
)
3866 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
3867 || b
== NULL
|| b
->expr_type
!= EXPR_CONSTANT
)
3870 /* If either of the types isn't INTEGER, we must have
3871 raised an error earlier. */
3873 if (a
->ts
.type
!= BT_INTEGER
|| b
->ts
.type
!= BT_INTEGER
)
3876 i
= mpz_cmp (a
->value
.integer
, b
->value
.integer
);
3886 /* Compare an integer expression with an integer. */
3888 static compare_result
3889 compare_bound_int (gfc_expr
*a
, int b
)
3893 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3896 if (a
->ts
.type
!= BT_INTEGER
)
3897 gfc_internal_error ("compare_bound_int(): Bad expression");
3899 i
= mpz_cmp_si (a
->value
.integer
, b
);
3909 /* Compare an integer expression with a mpz_t. */
3911 static compare_result
3912 compare_bound_mpz_t (gfc_expr
*a
, mpz_t b
)
3916 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3919 if (a
->ts
.type
!= BT_INTEGER
)
3920 gfc_internal_error ("compare_bound_int(): Bad expression");
3922 i
= mpz_cmp (a
->value
.integer
, b
);
3932 /* Compute the last value of a sequence given by a triplet.
3933 Return 0 if it wasn't able to compute the last value, or if the
3934 sequence if empty, and 1 otherwise. */
3937 compute_last_value_for_triplet (gfc_expr
*start
, gfc_expr
*end
,
3938 gfc_expr
*stride
, mpz_t last
)
3942 if (start
== NULL
|| start
->expr_type
!= EXPR_CONSTANT
3943 || end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
3944 || (stride
!= NULL
&& stride
->expr_type
!= EXPR_CONSTANT
))
3947 if (start
->ts
.type
!= BT_INTEGER
|| end
->ts
.type
!= BT_INTEGER
3948 || (stride
!= NULL
&& stride
->ts
.type
!= BT_INTEGER
))
3951 if (stride
== NULL
|| compare_bound_int (stride
, 1) == CMP_EQ
)
3953 if (compare_bound (start
, end
) == CMP_GT
)
3955 mpz_set (last
, end
->value
.integer
);
3959 if (compare_bound_int (stride
, 0) == CMP_GT
)
3961 /* Stride is positive */
3962 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) > 0)
3967 /* Stride is negative */
3968 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) < 0)
3973 mpz_sub (rem
, end
->value
.integer
, start
->value
.integer
);
3974 mpz_tdiv_r (rem
, rem
, stride
->value
.integer
);
3975 mpz_sub (last
, end
->value
.integer
, rem
);
3982 /* Compare a single dimension of an array reference to the array
3986 check_dimension (int i
, gfc_array_ref
*ar
, gfc_array_spec
*as
)
3990 if (ar
->dimen_type
[i
] == DIMEN_STAR
)
3992 gcc_assert (ar
->stride
[i
] == NULL
);
3993 /* This implies [*] as [*:] and [*:3] are not possible. */
3994 if (ar
->start
[i
] == NULL
)
3996 gcc_assert (ar
->end
[i
] == NULL
);
4001 /* Given start, end and stride values, calculate the minimum and
4002 maximum referenced indexes. */
4004 switch (ar
->dimen_type
[i
])
4007 case DIMEN_THIS_IMAGE
:
4012 if (compare_bound (ar
->start
[i
], as
->lower
[i
]) == CMP_LT
)
4015 gfc_warning (0, "Array reference at %L is out of bounds "
4016 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4017 mpz_get_si (ar
->start
[i
]->value
.integer
),
4018 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4020 gfc_warning (0, "Array reference at %L is out of bounds "
4021 "(%ld < %ld) in codimension %d", &ar
->c_where
[i
],
4022 mpz_get_si (ar
->start
[i
]->value
.integer
),
4023 mpz_get_si (as
->lower
[i
]->value
.integer
),
4027 if (compare_bound (ar
->start
[i
], as
->upper
[i
]) == CMP_GT
)
4030 gfc_warning (0, "Array reference at %L is out of bounds "
4031 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4032 mpz_get_si (ar
->start
[i
]->value
.integer
),
4033 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4035 gfc_warning (0, "Array reference at %L is out of bounds "
4036 "(%ld > %ld) in codimension %d", &ar
->c_where
[i
],
4037 mpz_get_si (ar
->start
[i
]->value
.integer
),
4038 mpz_get_si (as
->upper
[i
]->value
.integer
),
4047 #define AR_START (ar->start[i] ? ar->start[i] : as->lower[i])
4048 #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i])
4050 compare_result comp_start_end
= compare_bound (AR_START
, AR_END
);
4052 /* Check for zero stride, which is not allowed. */
4053 if (compare_bound_int (ar
->stride
[i
], 0) == CMP_EQ
)
4055 gfc_error ("Illegal stride of zero at %L", &ar
->c_where
[i
]);
4059 /* if start == len || (stride > 0 && start < len)
4060 || (stride < 0 && start > len),
4061 then the array section contains at least one element. In this
4062 case, there is an out-of-bounds access if
4063 (start < lower || start > upper). */
4064 if (compare_bound (AR_START
, AR_END
) == CMP_EQ
4065 || ((compare_bound_int (ar
->stride
[i
], 0) == CMP_GT
4066 || ar
->stride
[i
] == NULL
) && comp_start_end
== CMP_LT
)
4067 || (compare_bound_int (ar
->stride
[i
], 0) == CMP_LT
4068 && comp_start_end
== CMP_GT
))
4070 if (compare_bound (AR_START
, as
->lower
[i
]) == CMP_LT
)
4072 gfc_warning (0, "Lower array reference at %L is out of bounds "
4073 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4074 mpz_get_si (AR_START
->value
.integer
),
4075 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4078 if (compare_bound (AR_START
, as
->upper
[i
]) == CMP_GT
)
4080 gfc_warning (0, "Lower array reference at %L is out of bounds "
4081 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4082 mpz_get_si (AR_START
->value
.integer
),
4083 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4088 /* If we can compute the highest index of the array section,
4089 then it also has to be between lower and upper. */
4090 mpz_init (last_value
);
4091 if (compute_last_value_for_triplet (AR_START
, AR_END
, ar
->stride
[i
],
4094 if (compare_bound_mpz_t (as
->lower
[i
], last_value
) == CMP_GT
)
4096 gfc_warning (0, "Upper array reference at %L is out of bounds "
4097 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4098 mpz_get_si (last_value
),
4099 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4100 mpz_clear (last_value
);
4103 if (compare_bound_mpz_t (as
->upper
[i
], last_value
) == CMP_LT
)
4105 gfc_warning (0, "Upper array reference at %L is out of bounds "
4106 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4107 mpz_get_si (last_value
),
4108 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4109 mpz_clear (last_value
);
4113 mpz_clear (last_value
);
4121 gfc_internal_error ("check_dimension(): Bad array reference");
4128 /* Compare an array reference with an array specification. */
4131 compare_spec_to_ref (gfc_array_ref
*ar
)
4138 /* TODO: Full array sections are only allowed as actual parameters. */
4139 if (as
->type
== AS_ASSUMED_SIZE
4140 && (/*ar->type == AR_FULL
4141 ||*/ (ar
->type
== AR_SECTION
4142 && ar
->dimen_type
[i
] == DIMEN_RANGE
&& ar
->end
[i
] == NULL
)))
4144 gfc_error ("Rightmost upper bound of assumed size array section "
4145 "not specified at %L", &ar
->where
);
4149 if (ar
->type
== AR_FULL
)
4152 if (as
->rank
!= ar
->dimen
)
4154 gfc_error ("Rank mismatch in array reference at %L (%d/%d)",
4155 &ar
->where
, ar
->dimen
, as
->rank
);
4159 /* ar->codimen == 0 is a local array. */
4160 if (as
->corank
!= ar
->codimen
&& ar
->codimen
!= 0)
4162 gfc_error ("Coindex rank mismatch in array reference at %L (%d/%d)",
4163 &ar
->where
, ar
->codimen
, as
->corank
);
4167 for (i
= 0; i
< as
->rank
; i
++)
4168 if (!check_dimension (i
, ar
, as
))
4171 /* Local access has no coarray spec. */
4172 if (ar
->codimen
!= 0)
4173 for (i
= as
->rank
; i
< as
->rank
+ as
->corank
; i
++)
4175 if (ar
->dimen_type
[i
] != DIMEN_ELEMENT
&& !ar
->in_allocate
4176 && ar
->dimen_type
[i
] != DIMEN_THIS_IMAGE
)
4178 gfc_error ("Coindex of codimension %d must be a scalar at %L",
4179 i
+ 1 - as
->rank
, &ar
->where
);
4182 if (!check_dimension (i
, ar
, as
))
4190 /* Resolve one part of an array index. */
4193 gfc_resolve_index_1 (gfc_expr
*index
, int check_scalar
,
4194 int force_index_integer_kind
)
4201 if (!gfc_resolve_expr (index
))
4204 if (check_scalar
&& index
->rank
!= 0)
4206 gfc_error ("Array index at %L must be scalar", &index
->where
);
4210 if (index
->ts
.type
!= BT_INTEGER
&& index
->ts
.type
!= BT_REAL
)
4212 gfc_error ("Array index at %L must be of INTEGER type, found %s",
4213 &index
->where
, gfc_basic_typename (index
->ts
.type
));
4217 if (index
->ts
.type
== BT_REAL
)
4218 if (!gfc_notify_std (GFC_STD_LEGACY
, "REAL array index at %L",
4222 if ((index
->ts
.kind
!= gfc_index_integer_kind
4223 && force_index_integer_kind
)
4224 || index
->ts
.type
!= BT_INTEGER
)
4227 ts
.type
= BT_INTEGER
;
4228 ts
.kind
= gfc_index_integer_kind
;
4230 gfc_convert_type_warn (index
, &ts
, 2, 0);
4236 /* Resolve one part of an array index. */
4239 gfc_resolve_index (gfc_expr
*index
, int check_scalar
)
4241 return gfc_resolve_index_1 (index
, check_scalar
, 1);
4244 /* Resolve a dim argument to an intrinsic function. */
4247 gfc_resolve_dim_arg (gfc_expr
*dim
)
4252 if (!gfc_resolve_expr (dim
))
4257 gfc_error ("Argument dim at %L must be scalar", &dim
->where
);
4262 if (dim
->ts
.type
!= BT_INTEGER
)
4264 gfc_error ("Argument dim at %L must be of INTEGER type", &dim
->where
);
4268 if (dim
->ts
.kind
!= gfc_index_integer_kind
)
4273 ts
.type
= BT_INTEGER
;
4274 ts
.kind
= gfc_index_integer_kind
;
4276 gfc_convert_type_warn (dim
, &ts
, 2, 0);
4282 /* Given an expression that contains array references, update those array
4283 references to point to the right array specifications. While this is
4284 filled in during matching, this information is difficult to save and load
4285 in a module, so we take care of it here.
4287 The idea here is that the original array reference comes from the
4288 base symbol. We traverse the list of reference structures, setting
4289 the stored reference to references. Component references can
4290 provide an additional array specification. */
4293 find_array_spec (gfc_expr
*e
)
4299 if (e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
)
4300 as
= CLASS_DATA (e
->symtree
->n
.sym
)->as
;
4302 as
= e
->symtree
->n
.sym
->as
;
4304 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4309 gfc_internal_error ("find_array_spec(): Missing spec");
4316 c
= ref
->u
.c
.component
;
4317 if (c
->attr
.dimension
)
4320 gfc_internal_error ("find_array_spec(): unused as(1)");
4331 gfc_internal_error ("find_array_spec(): unused as(2)");
4335 /* Resolve an array reference. */
4338 resolve_array_ref (gfc_array_ref
*ar
)
4340 int i
, check_scalar
;
4343 for (i
= 0; i
< ar
->dimen
+ ar
->codimen
; i
++)
4345 check_scalar
= ar
->dimen_type
[i
] == DIMEN_RANGE
;
4347 /* Do not force gfc_index_integer_kind for the start. We can
4348 do fine with any integer kind. This avoids temporary arrays
4349 created for indexing with a vector. */
4350 if (!gfc_resolve_index_1 (ar
->start
[i
], check_scalar
, 0))
4352 if (!gfc_resolve_index (ar
->end
[i
], check_scalar
))
4354 if (!gfc_resolve_index (ar
->stride
[i
], check_scalar
))
4359 if (ar
->dimen_type
[i
] == DIMEN_UNKNOWN
)
4363 ar
->dimen_type
[i
] = DIMEN_ELEMENT
;
4367 ar
->dimen_type
[i
] = DIMEN_VECTOR
;
4368 if (e
->expr_type
== EXPR_VARIABLE
4369 && e
->symtree
->n
.sym
->ts
.type
== BT_DERIVED
)
4370 ar
->start
[i
] = gfc_get_parentheses (e
);
4374 gfc_error ("Array index at %L is an array of rank %d",
4375 &ar
->c_where
[i
], e
->rank
);
4379 /* Fill in the upper bound, which may be lower than the
4380 specified one for something like a(2:10:5), which is
4381 identical to a(2:7:5). Only relevant for strides not equal
4382 to one. Don't try a division by zero. */
4383 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4384 && ar
->stride
[i
] != NULL
&& ar
->stride
[i
]->expr_type
== EXPR_CONSTANT
4385 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 1L) != 0
4386 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 0L) != 0)
4390 if (gfc_ref_dimen_size (ar
, i
, &size
, &end
))
4392 if (ar
->end
[i
] == NULL
)
4395 gfc_get_constant_expr (BT_INTEGER
, gfc_index_integer_kind
,
4397 mpz_set (ar
->end
[i
]->value
.integer
, end
);
4399 else if (ar
->end
[i
]->ts
.type
== BT_INTEGER
4400 && ar
->end
[i
]->expr_type
== EXPR_CONSTANT
)
4402 mpz_set (ar
->end
[i
]->value
.integer
, end
);
4413 if (ar
->type
== AR_FULL
)
4415 if (ar
->as
->rank
== 0)
4416 ar
->type
= AR_ELEMENT
;
4418 /* Make sure array is the same as array(:,:), this way
4419 we don't need to special case all the time. */
4420 ar
->dimen
= ar
->as
->rank
;
4421 for (i
= 0; i
< ar
->dimen
; i
++)
4423 ar
->dimen_type
[i
] = DIMEN_RANGE
;
4425 gcc_assert (ar
->start
[i
] == NULL
);
4426 gcc_assert (ar
->end
[i
] == NULL
);
4427 gcc_assert (ar
->stride
[i
] == NULL
);
4431 /* If the reference type is unknown, figure out what kind it is. */
4433 if (ar
->type
== AR_UNKNOWN
)
4435 ar
->type
= AR_ELEMENT
;
4436 for (i
= 0; i
< ar
->dimen
; i
++)
4437 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4438 || ar
->dimen_type
[i
] == DIMEN_VECTOR
)
4440 ar
->type
= AR_SECTION
;
4445 if (!ar
->as
->cray_pointee
&& !compare_spec_to_ref (ar
))
4448 if (ar
->as
->corank
&& ar
->codimen
== 0)
4451 ar
->codimen
= ar
->as
->corank
;
4452 for (n
= ar
->dimen
; n
< ar
->dimen
+ ar
->codimen
; n
++)
4453 ar
->dimen_type
[n
] = DIMEN_THIS_IMAGE
;
4461 resolve_substring (gfc_ref
*ref
)
4463 int k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
4465 if (ref
->u
.ss
.start
!= NULL
)
4467 if (!gfc_resolve_expr (ref
->u
.ss
.start
))
4470 if (ref
->u
.ss
.start
->ts
.type
!= BT_INTEGER
)
4472 gfc_error ("Substring start index at %L must be of type INTEGER",
4473 &ref
->u
.ss
.start
->where
);
4477 if (ref
->u
.ss
.start
->rank
!= 0)
4479 gfc_error ("Substring start index at %L must be scalar",
4480 &ref
->u
.ss
.start
->where
);
4484 if (compare_bound_int (ref
->u
.ss
.start
, 1) == CMP_LT
4485 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4486 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4488 gfc_error ("Substring start index at %L is less than one",
4489 &ref
->u
.ss
.start
->where
);
4494 if (ref
->u
.ss
.end
!= NULL
)
4496 if (!gfc_resolve_expr (ref
->u
.ss
.end
))
4499 if (ref
->u
.ss
.end
->ts
.type
!= BT_INTEGER
)
4501 gfc_error ("Substring end index at %L must be of type INTEGER",
4502 &ref
->u
.ss
.end
->where
);
4506 if (ref
->u
.ss
.end
->rank
!= 0)
4508 gfc_error ("Substring end index at %L must be scalar",
4509 &ref
->u
.ss
.end
->where
);
4513 if (ref
->u
.ss
.length
!= NULL
4514 && compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.length
->length
) == CMP_GT
4515 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4516 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4518 gfc_error ("Substring end index at %L exceeds the string length",
4519 &ref
->u
.ss
.start
->where
);
4523 if (compare_bound_mpz_t (ref
->u
.ss
.end
,
4524 gfc_integer_kinds
[k
].huge
) == CMP_GT
4525 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4526 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4528 gfc_error ("Substring end index at %L is too large",
4529 &ref
->u
.ss
.end
->where
);
4538 /* This function supplies missing substring charlens. */
4541 gfc_resolve_substring_charlen (gfc_expr
*e
)
4544 gfc_expr
*start
, *end
;
4545 gfc_typespec
*ts
= NULL
;
4547 for (char_ref
= e
->ref
; char_ref
; char_ref
= char_ref
->next
)
4549 if (char_ref
->type
== REF_SUBSTRING
)
4551 if (char_ref
->type
== REF_COMPONENT
)
4552 ts
= &char_ref
->u
.c
.component
->ts
;
4558 gcc_assert (char_ref
->next
== NULL
);
4562 if (e
->ts
.u
.cl
->length
)
4563 gfc_free_expr (e
->ts
.u
.cl
->length
);
4564 else if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.dummy
)
4568 e
->ts
.type
= BT_CHARACTER
;
4569 e
->ts
.kind
= gfc_default_character_kind
;
4572 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
4574 if (char_ref
->u
.ss
.start
)
4575 start
= gfc_copy_expr (char_ref
->u
.ss
.start
);
4577 start
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
4579 if (char_ref
->u
.ss
.end
)
4580 end
= gfc_copy_expr (char_ref
->u
.ss
.end
);
4581 else if (e
->expr_type
== EXPR_VARIABLE
)
4584 ts
= &e
->symtree
->n
.sym
->ts
;
4585 end
= gfc_copy_expr (ts
->u
.cl
->length
);
4592 gfc_free_expr (start
);
4593 gfc_free_expr (end
);
4597 /* Length = (end - start + 1). */
4598 e
->ts
.u
.cl
->length
= gfc_subtract (end
, start
);
4599 e
->ts
.u
.cl
->length
= gfc_add (e
->ts
.u
.cl
->length
,
4600 gfc_get_int_expr (gfc_default_integer_kind
,
4603 /* F2008, 6.4.1: Both the starting point and the ending point shall
4604 be within the range 1, 2, ..., n unless the starting point exceeds
4605 the ending point, in which case the substring has length zero. */
4607 if (mpz_cmp_si (e
->ts
.u
.cl
->length
->value
.integer
, 0) < 0)
4608 mpz_set_si (e
->ts
.u
.cl
->length
->value
.integer
, 0);
4610 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
4611 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
4613 /* Make sure that the length is simplified. */
4614 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 1);
4615 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
4619 /* Resolve subtype references. */
4622 resolve_ref (gfc_expr
*expr
)
4624 int current_part_dimension
, n_components
, seen_part_dimension
;
4627 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4628 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.as
== NULL
)
4630 find_array_spec (expr
);
4634 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4638 if (!resolve_array_ref (&ref
->u
.ar
))
4646 if (!resolve_substring (ref
))
4651 /* Check constraints on part references. */
4653 current_part_dimension
= 0;
4654 seen_part_dimension
= 0;
4657 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4662 switch (ref
->u
.ar
.type
)
4665 /* Coarray scalar. */
4666 if (ref
->u
.ar
.as
->rank
== 0)
4668 current_part_dimension
= 0;
4673 current_part_dimension
= 1;
4677 current_part_dimension
= 0;
4681 gfc_internal_error ("resolve_ref(): Bad array reference");
4687 if (current_part_dimension
|| seen_part_dimension
)
4690 if (ref
->u
.c
.component
->attr
.pointer
4691 || ref
->u
.c
.component
->attr
.proc_pointer
4692 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
4693 && CLASS_DATA (ref
->u
.c
.component
)->attr
.pointer
))
4695 gfc_error ("Component to the right of a part reference "
4696 "with nonzero rank must not have the POINTER "
4697 "attribute at %L", &expr
->where
);
4700 else if (ref
->u
.c
.component
->attr
.allocatable
4701 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
4702 && CLASS_DATA (ref
->u
.c
.component
)->attr
.allocatable
))
4705 gfc_error ("Component to the right of a part reference "
4706 "with nonzero rank must not have the ALLOCATABLE "
4707 "attribute at %L", &expr
->where
);
4719 if (((ref
->type
== REF_COMPONENT
&& n_components
> 1)
4720 || ref
->next
== NULL
)
4721 && current_part_dimension
4722 && seen_part_dimension
)
4724 gfc_error ("Two or more part references with nonzero rank must "
4725 "not be specified at %L", &expr
->where
);
4729 if (ref
->type
== REF_COMPONENT
)
4731 if (current_part_dimension
)
4732 seen_part_dimension
= 1;
4734 /* reset to make sure */
4735 current_part_dimension
= 0;
4743 /* Given an expression, determine its shape. This is easier than it sounds.
4744 Leaves the shape array NULL if it is not possible to determine the shape. */
4747 expression_shape (gfc_expr
*e
)
4749 mpz_t array
[GFC_MAX_DIMENSIONS
];
4752 if (e
->rank
<= 0 || e
->shape
!= NULL
)
4755 for (i
= 0; i
< e
->rank
; i
++)
4756 if (!gfc_array_dimen_size (e
, i
, &array
[i
]))
4759 e
->shape
= gfc_get_shape (e
->rank
);
4761 memcpy (e
->shape
, array
, e
->rank
* sizeof (mpz_t
));
4766 for (i
--; i
>= 0; i
--)
4767 mpz_clear (array
[i
]);
4771 /* Given a variable expression node, compute the rank of the expression by
4772 examining the base symbol and any reference structures it may have. */
4775 expression_rank (gfc_expr
*e
)
4780 /* Just to make sure, because EXPR_COMPCALL's also have an e->ref and that
4781 could lead to serious confusion... */
4782 gcc_assert (e
->expr_type
!= EXPR_COMPCALL
);
4786 if (e
->expr_type
== EXPR_ARRAY
)
4788 /* Constructors can have a rank different from one via RESHAPE(). */
4790 if (e
->symtree
== NULL
)
4796 e
->rank
= (e
->symtree
->n
.sym
->as
== NULL
)
4797 ? 0 : e
->symtree
->n
.sym
->as
->rank
;
4803 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4805 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.proc_pointer
4806 && ref
->u
.c
.component
->attr
.function
&& !ref
->next
)
4807 rank
= ref
->u
.c
.component
->as
? ref
->u
.c
.component
->as
->rank
: 0;
4809 if (ref
->type
!= REF_ARRAY
)
4812 if (ref
->u
.ar
.type
== AR_FULL
)
4814 rank
= ref
->u
.ar
.as
->rank
;
4818 if (ref
->u
.ar
.type
== AR_SECTION
)
4820 /* Figure out the rank of the section. */
4822 gfc_internal_error ("expression_rank(): Two array specs");
4824 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
4825 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_RANGE
4826 || ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
4836 expression_shape (e
);
4841 add_caf_get_intrinsic (gfc_expr
*e
)
4843 gfc_expr
*wrapper
, *tmp_expr
;
4847 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4848 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
4853 for (n
= ref
->u
.ar
.dimen
; n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
4854 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_ELEMENT
)
4857 tmp_expr
= XCNEW (gfc_expr
);
4859 wrapper
= gfc_build_intrinsic_call (gfc_current_ns
, GFC_ISYM_CAF_GET
,
4860 "caf_get", tmp_expr
->where
, 1, tmp_expr
);
4861 wrapper
->ts
= e
->ts
;
4862 wrapper
->rank
= e
->rank
;
4864 wrapper
->shape
= gfc_copy_shape (e
->shape
, e
->rank
);
4871 remove_caf_get_intrinsic (gfc_expr
*e
)
4873 gcc_assert (e
->expr_type
== EXPR_FUNCTION
&& e
->value
.function
.isym
4874 && e
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
);
4875 gfc_expr
*e2
= e
->value
.function
.actual
->expr
;
4876 e
->value
.function
.actual
->expr
= NULL
;
4877 gfc_free_actual_arglist (e
->value
.function
.actual
);
4878 gfc_free_shape (&e
->shape
, e
->rank
);
4884 /* Resolve a variable expression. */
4887 resolve_variable (gfc_expr
*e
)
4894 if (e
->symtree
== NULL
)
4896 sym
= e
->symtree
->n
.sym
;
4898 /* Use same check as for TYPE(*) below; this check has to be before TYPE(*)
4899 as ts.type is set to BT_ASSUMED in resolve_symbol. */
4900 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
4902 if (!actual_arg
|| inquiry_argument
)
4904 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may only "
4905 "be used as actual argument", sym
->name
, &e
->where
);
4909 /* TS 29113, 407b. */
4910 else if (e
->ts
.type
== BT_ASSUMED
)
4914 gfc_error ("Assumed-type variable %s at %L may only be used "
4915 "as actual argument", sym
->name
, &e
->where
);
4918 else if (inquiry_argument
&& !first_actual_arg
)
4920 /* FIXME: It doesn't work reliably as inquiry_argument is not set
4921 for all inquiry functions in resolve_function; the reason is
4922 that the function-name resolution happens too late in that
4924 gfc_error ("Assumed-type variable %s at %L as actual argument to "
4925 "an inquiry function shall be the first argument",
4926 sym
->name
, &e
->where
);
4930 /* TS 29113, C535b. */
4931 else if ((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
4932 && CLASS_DATA (sym
)->as
4933 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
4934 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
4935 && sym
->as
->type
== AS_ASSUMED_RANK
))
4939 gfc_error ("Assumed-rank variable %s at %L may only be used as "
4940 "actual argument", sym
->name
, &e
->where
);
4943 else if (inquiry_argument
&& !first_actual_arg
)
4945 /* FIXME: It doesn't work reliably as inquiry_argument is not set
4946 for all inquiry functions in resolve_function; the reason is
4947 that the function-name resolution happens too late in that
4949 gfc_error ("Assumed-rank variable %s at %L as actual argument "
4950 "to an inquiry function shall be the first argument",
4951 sym
->name
, &e
->where
);
4956 if ((sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
)) && e
->ref
4957 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
4958 && e
->ref
->next
== NULL
))
4960 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall not have "
4961 "a subobject reference", sym
->name
, &e
->ref
->u
.ar
.where
);
4964 /* TS 29113, 407b. */
4965 else if (e
->ts
.type
== BT_ASSUMED
&& e
->ref
4966 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
4967 && e
->ref
->next
== NULL
))
4969 gfc_error ("Assumed-type variable %s at %L shall not have a subobject "
4970 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
4974 /* TS 29113, C535b. */
4975 if (((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
4976 && CLASS_DATA (sym
)->as
4977 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
4978 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
4979 && sym
->as
->type
== AS_ASSUMED_RANK
))
4981 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
4982 && e
->ref
->next
== NULL
))
4984 gfc_error ("Assumed-rank variable %s at %L shall not have a subobject "
4985 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
4989 /* For variables that are used in an associate (target => object) where
4990 the object's basetype is array valued while the target is scalar,
4991 the ts' type of the component refs is still array valued, which
4992 can't be translated that way. */
4993 if (sym
->assoc
&& e
->rank
== 0 && e
->ref
&& sym
->ts
.type
== BT_CLASS
4994 && sym
->assoc
->target
->ts
.type
== BT_CLASS
4995 && CLASS_DATA (sym
->assoc
->target
)->as
)
4997 gfc_ref
*ref
= e
->ref
;
5003 ref
->u
.c
.sym
= sym
->ts
.u
.derived
;
5004 /* Stop the loop. */
5014 /* If this is an associate-name, it may be parsed with an array reference
5015 in error even though the target is scalar. Fail directly in this case.
5016 TODO Understand why class scalar expressions must be excluded. */
5017 if (sym
->assoc
&& !(sym
->ts
.type
== BT_CLASS
&& e
->rank
== 0))
5019 if (sym
->ts
.type
== BT_CLASS
)
5020 gfc_fix_class_refs (e
);
5021 if (!sym
->attr
.dimension
&& e
->ref
&& e
->ref
->type
== REF_ARRAY
)
5025 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.generic
)
5026 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
5028 /* On the other hand, the parser may not have known this is an array;
5029 in this case, we have to add a FULL reference. */
5030 if (sym
->assoc
&& sym
->attr
.dimension
&& !e
->ref
)
5032 e
->ref
= gfc_get_ref ();
5033 e
->ref
->type
= REF_ARRAY
;
5034 e
->ref
->u
.ar
.type
= AR_FULL
;
5035 e
->ref
->u
.ar
.dimen
= 0;
5038 /* Like above, but for class types, where the checking whether an array
5039 ref is present is more complicated. Furthermore make sure not to add
5040 the full array ref to _vptr or _len refs. */
5041 if (sym
->assoc
&& sym
->ts
.type
== BT_CLASS
5042 && CLASS_DATA (sym
)->attr
.dimension
5043 && (e
->ts
.type
!= BT_DERIVED
|| !e
->ts
.u
.derived
->attr
.vtype
))
5045 gfc_ref
*ref
, *newref
;
5047 newref
= gfc_get_ref ();
5048 newref
->type
= REF_ARRAY
;
5049 newref
->u
.ar
.type
= AR_FULL
;
5050 newref
->u
.ar
.dimen
= 0;
5051 /* Because this is an associate var and the first ref either is a ref to
5052 the _data component or not, no traversal of the ref chain is
5053 needed. The array ref needs to be inserted after the _data ref,
5054 or when that is not present, which may happend for polymorphic
5055 types, then at the first position. */
5059 else if (ref
->type
== REF_COMPONENT
5060 && strcmp ("_data", ref
->u
.c
.component
->name
) == 0)
5062 if (!ref
->next
|| ref
->next
->type
!= REF_ARRAY
)
5064 newref
->next
= ref
->next
;
5068 /* Array ref present already. */
5069 gfc_free_ref_list (newref
);
5071 else if (ref
->type
== REF_ARRAY
)
5072 /* Array ref present already. */
5073 gfc_free_ref_list (newref
);
5081 if (e
->ref
&& !resolve_ref (e
))
5084 if (sym
->attr
.flavor
== FL_PROCEDURE
5085 && (!sym
->attr
.function
5086 || (sym
->attr
.function
&& sym
->result
5087 && sym
->result
->attr
.proc_pointer
5088 && !sym
->result
->attr
.function
)))
5090 e
->ts
.type
= BT_PROCEDURE
;
5091 goto resolve_procedure
;
5094 if (sym
->ts
.type
!= BT_UNKNOWN
)
5095 gfc_variable_attr (e
, &e
->ts
);
5098 /* Must be a simple variable reference. */
5099 if (!gfc_set_default_type (sym
, 1, sym
->ns
))
5104 if (check_assumed_size_reference (sym
, e
))
5107 /* Deal with forward references to entries during gfc_resolve_code, to
5108 satisfy, at least partially, 12.5.2.5. */
5109 if (gfc_current_ns
->entries
5110 && current_entry_id
== sym
->entry_id
5113 && cs_base
->current
->op
!= EXEC_ENTRY
)
5115 gfc_entry_list
*entry
;
5116 gfc_formal_arglist
*formal
;
5118 bool seen
, saved_specification_expr
;
5120 /* If the symbol is a dummy... */
5121 if (sym
->attr
.dummy
&& sym
->ns
== gfc_current_ns
)
5123 entry
= gfc_current_ns
->entries
;
5126 /* ...test if the symbol is a parameter of previous entries. */
5127 for (; entry
&& entry
->id
<= current_entry_id
; entry
= entry
->next
)
5128 for (formal
= entry
->sym
->formal
; formal
; formal
= formal
->next
)
5130 if (formal
->sym
&& sym
->name
== formal
->sym
->name
)
5137 /* If it has not been seen as a dummy, this is an error. */
5140 if (specification_expr
)
5141 gfc_error ("Variable %qs, used in a specification expression"
5142 ", is referenced at %L before the ENTRY statement "
5143 "in which it is a parameter",
5144 sym
->name
, &cs_base
->current
->loc
);
5146 gfc_error ("Variable %qs is used at %L before the ENTRY "
5147 "statement in which it is a parameter",
5148 sym
->name
, &cs_base
->current
->loc
);
5153 /* Now do the same check on the specification expressions. */
5154 saved_specification_expr
= specification_expr
;
5155 specification_expr
= true;
5156 if (sym
->ts
.type
== BT_CHARACTER
5157 && !gfc_resolve_expr (sym
->ts
.u
.cl
->length
))
5161 for (n
= 0; n
< sym
->as
->rank
; n
++)
5163 if (!gfc_resolve_expr (sym
->as
->lower
[n
]))
5165 if (!gfc_resolve_expr (sym
->as
->upper
[n
]))
5168 specification_expr
= saved_specification_expr
;
5171 /* Update the symbol's entry level. */
5172 sym
->entry_id
= current_entry_id
+ 1;
5175 /* If a symbol has been host_associated mark it. This is used latter,
5176 to identify if aliasing is possible via host association. */
5177 if (sym
->attr
.flavor
== FL_VARIABLE
5178 && gfc_current_ns
->parent
5179 && (gfc_current_ns
->parent
== sym
->ns
5180 || (gfc_current_ns
->parent
->parent
5181 && gfc_current_ns
->parent
->parent
== sym
->ns
)))
5182 sym
->attr
.host_assoc
= 1;
5184 if (gfc_current_ns
->proc_name
5185 && sym
->attr
.dimension
5186 && (sym
->ns
!= gfc_current_ns
5187 || sym
->attr
.use_assoc
5188 || sym
->attr
.in_common
))
5189 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
5192 if (t
&& !resolve_procedure_expression (e
))
5195 /* F2008, C617 and C1229. */
5196 if (!inquiry_argument
&& (e
->ts
.type
== BT_CLASS
|| e
->ts
.type
== BT_DERIVED
)
5197 && gfc_is_coindexed (e
))
5199 gfc_ref
*ref
, *ref2
= NULL
;
5201 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5203 if (ref
->type
== REF_COMPONENT
)
5205 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
5209 for ( ; ref
; ref
= ref
->next
)
5210 if (ref
->type
== REF_COMPONENT
)
5213 /* Expression itself is not coindexed object. */
5214 if (ref
&& e
->ts
.type
== BT_CLASS
)
5216 gfc_error ("Polymorphic subobject of coindexed object at %L",
5221 /* Expression itself is coindexed object. */
5225 c
= ref2
? ref2
->u
.c
.component
: e
->symtree
->n
.sym
->components
;
5226 for ( ; c
; c
= c
->next
)
5227 if (c
->attr
.allocatable
&& c
->ts
.type
== BT_CLASS
)
5229 gfc_error ("Coindexed object with polymorphic allocatable "
5230 "subcomponent at %L", &e
->where
);
5238 expression_rank (e
);
5240 if (t
&& flag_coarray
== GFC_FCOARRAY_LIB
&& gfc_is_coindexed (e
))
5241 add_caf_get_intrinsic (e
);
5247 /* Checks to see that the correct symbol has been host associated.
5248 The only situation where this arises is that in which a twice
5249 contained function is parsed after the host association is made.
5250 Therefore, on detecting this, change the symbol in the expression
5251 and convert the array reference into an actual arglist if the old
5252 symbol is a variable. */
5254 check_host_association (gfc_expr
*e
)
5256 gfc_symbol
*sym
, *old_sym
;
5260 gfc_actual_arglist
*arg
, *tail
= NULL
;
5261 bool retval
= e
->expr_type
== EXPR_FUNCTION
;
5263 /* If the expression is the result of substitution in
5264 interface.c(gfc_extend_expr) because there is no way in
5265 which the host association can be wrong. */
5266 if (e
->symtree
== NULL
5267 || e
->symtree
->n
.sym
== NULL
5268 || e
->user_operator
)
5271 old_sym
= e
->symtree
->n
.sym
;
5273 if (gfc_current_ns
->parent
5274 && old_sym
->ns
!= gfc_current_ns
)
5276 /* Use the 'USE' name so that renamed module symbols are
5277 correctly handled. */
5278 gfc_find_symbol (e
->symtree
->name
, gfc_current_ns
, 1, &sym
);
5280 if (sym
&& old_sym
!= sym
5281 && sym
->ts
.type
== old_sym
->ts
.type
5282 && sym
->attr
.flavor
== FL_PROCEDURE
5283 && sym
->attr
.contained
)
5285 /* Clear the shape, since it might not be valid. */
5286 gfc_free_shape (&e
->shape
, e
->rank
);
5288 /* Give the expression the right symtree! */
5289 gfc_find_sym_tree (e
->symtree
->name
, NULL
, 1, &st
);
5290 gcc_assert (st
!= NULL
);
5292 if (old_sym
->attr
.flavor
== FL_PROCEDURE
5293 || e
->expr_type
== EXPR_FUNCTION
)
5295 /* Original was function so point to the new symbol, since
5296 the actual argument list is already attached to the
5298 e
->value
.function
.esym
= NULL
;
5303 /* Original was variable so convert array references into
5304 an actual arglist. This does not need any checking now
5305 since resolve_function will take care of it. */
5306 e
->value
.function
.actual
= NULL
;
5307 e
->expr_type
= EXPR_FUNCTION
;
5310 /* Ambiguity will not arise if the array reference is not
5311 the last reference. */
5312 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5313 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
5316 gcc_assert (ref
->type
== REF_ARRAY
);
5318 /* Grab the start expressions from the array ref and
5319 copy them into actual arguments. */
5320 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
5322 arg
= gfc_get_actual_arglist ();
5323 arg
->expr
= gfc_copy_expr (ref
->u
.ar
.start
[n
]);
5324 if (e
->value
.function
.actual
== NULL
)
5325 tail
= e
->value
.function
.actual
= arg
;
5333 /* Dump the reference list and set the rank. */
5334 gfc_free_ref_list (e
->ref
);
5336 e
->rank
= sym
->as
? sym
->as
->rank
: 0;
5339 gfc_resolve_expr (e
);
5343 /* This might have changed! */
5344 return e
->expr_type
== EXPR_FUNCTION
;
5349 gfc_resolve_character_operator (gfc_expr
*e
)
5351 gfc_expr
*op1
= e
->value
.op
.op1
;
5352 gfc_expr
*op2
= e
->value
.op
.op2
;
5353 gfc_expr
*e1
= NULL
;
5354 gfc_expr
*e2
= NULL
;
5356 gcc_assert (e
->value
.op
.op
== INTRINSIC_CONCAT
);
5358 if (op1
->ts
.u
.cl
&& op1
->ts
.u
.cl
->length
)
5359 e1
= gfc_copy_expr (op1
->ts
.u
.cl
->length
);
5360 else if (op1
->expr_type
== EXPR_CONSTANT
)
5361 e1
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
5362 op1
->value
.character
.length
);
5364 if (op2
->ts
.u
.cl
&& op2
->ts
.u
.cl
->length
)
5365 e2
= gfc_copy_expr (op2
->ts
.u
.cl
->length
);
5366 else if (op2
->expr_type
== EXPR_CONSTANT
)
5367 e2
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
5368 op2
->value
.character
.length
);
5370 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5380 e
->ts
.u
.cl
->length
= gfc_add (e1
, e2
);
5381 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
5382 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
5383 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 0);
5384 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
5390 /* Ensure that an character expression has a charlen and, if possible, a
5391 length expression. */
5394 fixup_charlen (gfc_expr
*e
)
5396 /* The cases fall through so that changes in expression type and the need
5397 for multiple fixes are picked up. In all circumstances, a charlen should
5398 be available for the middle end to hang a backend_decl on. */
5399 switch (e
->expr_type
)
5402 gfc_resolve_character_operator (e
);
5405 if (e
->expr_type
== EXPR_ARRAY
)
5406 gfc_resolve_character_array_constructor (e
);
5408 case EXPR_SUBSTRING
:
5409 if (!e
->ts
.u
.cl
&& e
->ref
)
5410 gfc_resolve_substring_charlen (e
);
5414 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5421 /* Update an actual argument to include the passed-object for type-bound
5422 procedures at the right position. */
5424 static gfc_actual_arglist
*
5425 update_arglist_pass (gfc_actual_arglist
* lst
, gfc_expr
* po
, unsigned argpos
,
5428 gcc_assert (argpos
> 0);
5432 gfc_actual_arglist
* result
;
5434 result
= gfc_get_actual_arglist ();
5438 result
->name
= name
;
5444 lst
->next
= update_arglist_pass (lst
->next
, po
, argpos
- 1, name
);
5446 lst
= update_arglist_pass (NULL
, po
, argpos
- 1, name
);
5451 /* Extract the passed-object from an EXPR_COMPCALL (a copy of it). */
5454 extract_compcall_passed_object (gfc_expr
* e
)
5458 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5460 if (e
->value
.compcall
.base_object
)
5461 po
= gfc_copy_expr (e
->value
.compcall
.base_object
);
5464 po
= gfc_get_expr ();
5465 po
->expr_type
= EXPR_VARIABLE
;
5466 po
->symtree
= e
->symtree
;
5467 po
->ref
= gfc_copy_ref (e
->ref
);
5468 po
->where
= e
->where
;
5471 if (!gfc_resolve_expr (po
))
5478 /* Update the arglist of an EXPR_COMPCALL expression to include the
5482 update_compcall_arglist (gfc_expr
* e
)
5485 gfc_typebound_proc
* tbp
;
5487 tbp
= e
->value
.compcall
.tbp
;
5492 po
= extract_compcall_passed_object (e
);
5496 if (tbp
->nopass
|| e
->value
.compcall
.ignore_pass
)
5502 gcc_assert (tbp
->pass_arg_num
> 0);
5503 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5511 /* Extract the passed object from a PPC call (a copy of it). */
5514 extract_ppc_passed_object (gfc_expr
*e
)
5519 po
= gfc_get_expr ();
5520 po
->expr_type
= EXPR_VARIABLE
;
5521 po
->symtree
= e
->symtree
;
5522 po
->ref
= gfc_copy_ref (e
->ref
);
5523 po
->where
= e
->where
;
5525 /* Remove PPC reference. */
5527 while ((*ref
)->next
)
5528 ref
= &(*ref
)->next
;
5529 gfc_free_ref_list (*ref
);
5532 if (!gfc_resolve_expr (po
))
5539 /* Update the actual arglist of a procedure pointer component to include the
5543 update_ppc_arglist (gfc_expr
* e
)
5547 gfc_typebound_proc
* tb
;
5549 ppc
= gfc_get_proc_ptr_comp (e
);
5557 else if (tb
->nopass
)
5560 po
= extract_ppc_passed_object (e
);
5567 gfc_error ("Passed-object at %L must be scalar", &e
->where
);
5572 if (po
->ts
.type
== BT_DERIVED
&& po
->ts
.u
.derived
->attr
.abstract
)
5574 gfc_error ("Base object for procedure-pointer component call at %L is of"
5575 " ABSTRACT type %qs", &e
->where
, po
->ts
.u
.derived
->name
);
5579 gcc_assert (tb
->pass_arg_num
> 0);
5580 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5588 /* Check that the object a TBP is called on is valid, i.e. it must not be
5589 of ABSTRACT type (as in subobject%abstract_parent%tbp()). */
5592 check_typebound_baseobject (gfc_expr
* e
)
5595 bool return_value
= false;
5597 base
= extract_compcall_passed_object (e
);
5601 gcc_assert (base
->ts
.type
== BT_DERIVED
|| base
->ts
.type
== BT_CLASS
);
5603 if (base
->ts
.type
== BT_CLASS
&& !gfc_expr_attr (base
).class_ok
)
5607 if (base
->ts
.type
== BT_DERIVED
&& base
->ts
.u
.derived
->attr
.abstract
)
5609 gfc_error ("Base object for type-bound procedure call at %L is of"
5610 " ABSTRACT type %qs", &e
->where
, base
->ts
.u
.derived
->name
);
5614 /* F08:C1230. If the procedure called is NOPASS,
5615 the base object must be scalar. */
5616 if (e
->value
.compcall
.tbp
->nopass
&& base
->rank
!= 0)
5618 gfc_error ("Base object for NOPASS type-bound procedure call at %L must"
5619 " be scalar", &e
->where
);
5623 return_value
= true;
5626 gfc_free_expr (base
);
5627 return return_value
;
5631 /* Resolve a call to a type-bound procedure, either function or subroutine,
5632 statically from the data in an EXPR_COMPCALL expression. The adapted
5633 arglist and the target-procedure symtree are returned. */
5636 resolve_typebound_static (gfc_expr
* e
, gfc_symtree
** target
,
5637 gfc_actual_arglist
** actual
)
5639 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5640 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5642 /* Update the actual arglist for PASS. */
5643 if (!update_compcall_arglist (e
))
5646 *actual
= e
->value
.compcall
.actual
;
5647 *target
= e
->value
.compcall
.tbp
->u
.specific
;
5649 gfc_free_ref_list (e
->ref
);
5651 e
->value
.compcall
.actual
= NULL
;
5653 /* If we find a deferred typebound procedure, check for derived types
5654 that an overriding typebound procedure has not been missed. */
5655 if (e
->value
.compcall
.name
5656 && !e
->value
.compcall
.tbp
->non_overridable
5657 && e
->value
.compcall
.base_object
5658 && e
->value
.compcall
.base_object
->ts
.type
== BT_DERIVED
)
5661 gfc_symbol
*derived
;
5663 /* Use the derived type of the base_object. */
5664 derived
= e
->value
.compcall
.base_object
->ts
.u
.derived
;
5667 /* If necessary, go through the inheritance chain. */
5668 while (!st
&& derived
)
5670 /* Look for the typebound procedure 'name'. */
5671 if (derived
->f2k_derived
&& derived
->f2k_derived
->tb_sym_root
)
5672 st
= gfc_find_symtree (derived
->f2k_derived
->tb_sym_root
,
5673 e
->value
.compcall
.name
);
5675 derived
= gfc_get_derived_super_type (derived
);
5678 /* Now find the specific name in the derived type namespace. */
5679 if (st
&& st
->n
.tb
&& st
->n
.tb
->u
.specific
)
5680 gfc_find_sym_tree (st
->n
.tb
->u
.specific
->name
,
5681 derived
->ns
, 1, &st
);
5689 /* Get the ultimate declared type from an expression. In addition,
5690 return the last class/derived type reference and the copy of the
5691 reference list. If check_types is set true, derived types are
5692 identified as well as class references. */
5694 get_declared_from_expr (gfc_ref
**class_ref
, gfc_ref
**new_ref
,
5695 gfc_expr
*e
, bool check_types
)
5697 gfc_symbol
*declared
;
5704 *new_ref
= gfc_copy_ref (e
->ref
);
5706 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5708 if (ref
->type
!= REF_COMPONENT
)
5711 if ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
5712 || (check_types
&& ref
->u
.c
.component
->ts
.type
== BT_DERIVED
))
5713 && ref
->u
.c
.component
->attr
.flavor
!= FL_PROCEDURE
)
5715 declared
= ref
->u
.c
.component
->ts
.u
.derived
;
5721 if (declared
== NULL
)
5722 declared
= e
->symtree
->n
.sym
->ts
.u
.derived
;
5728 /* Given an EXPR_COMPCALL calling a GENERIC typebound procedure, figure out
5729 which of the specific bindings (if any) matches the arglist and transform
5730 the expression into a call of that binding. */
5733 resolve_typebound_generic_call (gfc_expr
* e
, const char **name
)
5735 gfc_typebound_proc
* genproc
;
5736 const char* genname
;
5738 gfc_symbol
*derived
;
5740 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5741 genname
= e
->value
.compcall
.name
;
5742 genproc
= e
->value
.compcall
.tbp
;
5744 if (!genproc
->is_generic
)
5747 /* Try the bindings on this type and in the inheritance hierarchy. */
5748 for (; genproc
; genproc
= genproc
->overridden
)
5752 gcc_assert (genproc
->is_generic
);
5753 for (g
= genproc
->u
.generic
; g
; g
= g
->next
)
5756 gfc_actual_arglist
* args
;
5759 gcc_assert (g
->specific
);
5761 if (g
->specific
->error
)
5764 target
= g
->specific
->u
.specific
->n
.sym
;
5766 /* Get the right arglist by handling PASS/NOPASS. */
5767 args
= gfc_copy_actual_arglist (e
->value
.compcall
.actual
);
5768 if (!g
->specific
->nopass
)
5771 po
= extract_compcall_passed_object (e
);
5774 gfc_free_actual_arglist (args
);
5778 gcc_assert (g
->specific
->pass_arg_num
> 0);
5779 gcc_assert (!g
->specific
->error
);
5780 args
= update_arglist_pass (args
, po
, g
->specific
->pass_arg_num
,
5781 g
->specific
->pass_arg
);
5783 resolve_actual_arglist (args
, target
->attr
.proc
,
5784 is_external_proc (target
)
5785 && gfc_sym_get_dummy_args (target
) == NULL
);
5787 /* Check if this arglist matches the formal. */
5788 matches
= gfc_arglist_matches_symbol (&args
, target
);
5790 /* Clean up and break out of the loop if we've found it. */
5791 gfc_free_actual_arglist (args
);
5794 e
->value
.compcall
.tbp
= g
->specific
;
5795 genname
= g
->specific_st
->name
;
5796 /* Pass along the name for CLASS methods, where the vtab
5797 procedure pointer component has to be referenced. */
5805 /* Nothing matching found! */
5806 gfc_error ("Found no matching specific binding for the call to the GENERIC"
5807 " %qs at %L", genname
, &e
->where
);
5811 /* Make sure that we have the right specific instance for the name. */
5812 derived
= get_declared_from_expr (NULL
, NULL
, e
, true);
5814 st
= gfc_find_typebound_proc (derived
, NULL
, genname
, true, &e
->where
);
5816 e
->value
.compcall
.tbp
= st
->n
.tb
;
5822 /* Resolve a call to a type-bound subroutine. */
5825 resolve_typebound_call (gfc_code
* c
, const char **name
, bool *overridable
)
5827 gfc_actual_arglist
* newactual
;
5828 gfc_symtree
* target
;
5830 /* Check that's really a SUBROUTINE. */
5831 if (!c
->expr1
->value
.compcall
.tbp
->subroutine
)
5833 gfc_error ("%qs at %L should be a SUBROUTINE",
5834 c
->expr1
->value
.compcall
.name
, &c
->loc
);
5838 if (!check_typebound_baseobject (c
->expr1
))
5841 /* Pass along the name for CLASS methods, where the vtab
5842 procedure pointer component has to be referenced. */
5844 *name
= c
->expr1
->value
.compcall
.name
;
5846 if (!resolve_typebound_generic_call (c
->expr1
, name
))
5849 /* Pass along the NON_OVERRIDABLE attribute of the specific TBP. */
5851 *overridable
= !c
->expr1
->value
.compcall
.tbp
->non_overridable
;
5853 /* Transform into an ordinary EXEC_CALL for now. */
5855 if (!resolve_typebound_static (c
->expr1
, &target
, &newactual
))
5858 c
->ext
.actual
= newactual
;
5859 c
->symtree
= target
;
5860 c
->op
= (c
->expr1
->value
.compcall
.assign
? EXEC_ASSIGN_CALL
: EXEC_CALL
);
5862 gcc_assert (!c
->expr1
->ref
&& !c
->expr1
->value
.compcall
.actual
);
5864 gfc_free_expr (c
->expr1
);
5865 c
->expr1
= gfc_get_expr ();
5866 c
->expr1
->expr_type
= EXPR_FUNCTION
;
5867 c
->expr1
->symtree
= target
;
5868 c
->expr1
->where
= c
->loc
;
5870 return resolve_call (c
);
5874 /* Resolve a component-call expression. */
5876 resolve_compcall (gfc_expr
* e
, const char **name
)
5878 gfc_actual_arglist
* newactual
;
5879 gfc_symtree
* target
;
5881 /* Check that's really a FUNCTION. */
5882 if (!e
->value
.compcall
.tbp
->function
)
5884 gfc_error ("%qs at %L should be a FUNCTION",
5885 e
->value
.compcall
.name
, &e
->where
);
5889 /* These must not be assign-calls! */
5890 gcc_assert (!e
->value
.compcall
.assign
);
5892 if (!check_typebound_baseobject (e
))
5895 /* Pass along the name for CLASS methods, where the vtab
5896 procedure pointer component has to be referenced. */
5898 *name
= e
->value
.compcall
.name
;
5900 if (!resolve_typebound_generic_call (e
, name
))
5902 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5904 /* Take the rank from the function's symbol. */
5905 if (e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
)
5906 e
->rank
= e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
->rank
;
5908 /* For now, we simply transform it into an EXPR_FUNCTION call with the same
5909 arglist to the TBP's binding target. */
5911 if (!resolve_typebound_static (e
, &target
, &newactual
))
5914 e
->value
.function
.actual
= newactual
;
5915 e
->value
.function
.name
= NULL
;
5916 e
->value
.function
.esym
= target
->n
.sym
;
5917 e
->value
.function
.isym
= NULL
;
5918 e
->symtree
= target
;
5919 e
->ts
= target
->n
.sym
->ts
;
5920 e
->expr_type
= EXPR_FUNCTION
;
5922 /* Resolution is not necessary if this is a class subroutine; this
5923 function only has to identify the specific proc. Resolution of
5924 the call will be done next in resolve_typebound_call. */
5925 return gfc_resolve_expr (e
);
5929 static bool resolve_fl_derived (gfc_symbol
*sym
);
5932 /* Resolve a typebound function, or 'method'. First separate all
5933 the non-CLASS references by calling resolve_compcall directly. */
5936 resolve_typebound_function (gfc_expr
* e
)
5938 gfc_symbol
*declared
;
5950 /* Deal with typebound operators for CLASS objects. */
5951 expr
= e
->value
.compcall
.base_object
;
5952 overridable
= !e
->value
.compcall
.tbp
->non_overridable
;
5953 if (expr
&& expr
->ts
.type
== BT_CLASS
&& e
->value
.compcall
.name
)
5955 /* If the base_object is not a variable, the corresponding actual
5956 argument expression must be stored in e->base_expression so
5957 that the corresponding tree temporary can be used as the base
5958 object in gfc_conv_procedure_call. */
5959 if (expr
->expr_type
!= EXPR_VARIABLE
)
5961 gfc_actual_arglist
*args
;
5963 for (args
= e
->value
.function
.actual
; args
; args
= args
->next
)
5965 if (expr
== args
->expr
)
5970 /* Since the typebound operators are generic, we have to ensure
5971 that any delays in resolution are corrected and that the vtab
5974 declared
= ts
.u
.derived
;
5975 c
= gfc_find_component (declared
, "_vptr", true, true);
5976 if (c
->ts
.u
.derived
== NULL
)
5977 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
5979 if (!resolve_compcall (e
, &name
))
5982 /* Use the generic name if it is there. */
5983 name
= name
? name
: e
->value
.function
.esym
->name
;
5984 e
->symtree
= expr
->symtree
;
5985 e
->ref
= gfc_copy_ref (expr
->ref
);
5986 get_declared_from_expr (&class_ref
, NULL
, e
, false);
5988 /* Trim away the extraneous references that emerge from nested
5989 use of interface.c (extend_expr). */
5990 if (class_ref
&& class_ref
->next
)
5992 gfc_free_ref_list (class_ref
->next
);
5993 class_ref
->next
= NULL
;
5995 else if (e
->ref
&& !class_ref
)
5997 gfc_free_ref_list (e
->ref
);
6001 gfc_add_vptr_component (e
);
6002 gfc_add_component_ref (e
, name
);
6003 e
->value
.function
.esym
= NULL
;
6004 if (expr
->expr_type
!= EXPR_VARIABLE
)
6005 e
->base_expr
= expr
;
6010 return resolve_compcall (e
, NULL
);
6012 if (!resolve_ref (e
))
6015 /* Get the CLASS declared type. */
6016 declared
= get_declared_from_expr (&class_ref
, &new_ref
, e
, true);
6018 if (!resolve_fl_derived (declared
))
6021 /* Weed out cases of the ultimate component being a derived type. */
6022 if ((class_ref
&& class_ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
6023 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
6025 gfc_free_ref_list (new_ref
);
6026 return resolve_compcall (e
, NULL
);
6029 c
= gfc_find_component (declared
, "_data", true, true);
6030 declared
= c
->ts
.u
.derived
;
6032 /* Treat the call as if it is a typebound procedure, in order to roll
6033 out the correct name for the specific function. */
6034 if (!resolve_compcall (e
, &name
))
6036 gfc_free_ref_list (new_ref
);
6043 /* Convert the expression to a procedure pointer component call. */
6044 e
->value
.function
.esym
= NULL
;
6050 /* '_vptr' points to the vtab, which contains the procedure pointers. */
6051 gfc_add_vptr_component (e
);
6052 gfc_add_component_ref (e
, name
);
6054 /* Recover the typespec for the expression. This is really only
6055 necessary for generic procedures, where the additional call
6056 to gfc_add_component_ref seems to throw the collection of the
6057 correct typespec. */
6061 gfc_free_ref_list (new_ref
);
6066 /* Resolve a typebound subroutine, or 'method'. First separate all
6067 the non-CLASS references by calling resolve_typebound_call
6071 resolve_typebound_subroutine (gfc_code
*code
)
6073 gfc_symbol
*declared
;
6083 st
= code
->expr1
->symtree
;
6085 /* Deal with typebound operators for CLASS objects. */
6086 expr
= code
->expr1
->value
.compcall
.base_object
;
6087 overridable
= !code
->expr1
->value
.compcall
.tbp
->non_overridable
;
6088 if (expr
&& expr
->ts
.type
== BT_CLASS
&& code
->expr1
->value
.compcall
.name
)
6090 /* If the base_object is not a variable, the corresponding actual
6091 argument expression must be stored in e->base_expression so
6092 that the corresponding tree temporary can be used as the base
6093 object in gfc_conv_procedure_call. */
6094 if (expr
->expr_type
!= EXPR_VARIABLE
)
6096 gfc_actual_arglist
*args
;
6098 args
= code
->expr1
->value
.function
.actual
;
6099 for (; args
; args
= args
->next
)
6100 if (expr
== args
->expr
)
6104 /* Since the typebound operators are generic, we have to ensure
6105 that any delays in resolution are corrected and that the vtab
6107 declared
= expr
->ts
.u
.derived
;
6108 c
= gfc_find_component (declared
, "_vptr", true, true);
6109 if (c
->ts
.u
.derived
== NULL
)
6110 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
6112 if (!resolve_typebound_call (code
, &name
, NULL
))
6115 /* Use the generic name if it is there. */
6116 name
= name
? name
: code
->expr1
->value
.function
.esym
->name
;
6117 code
->expr1
->symtree
= expr
->symtree
;
6118 code
->expr1
->ref
= gfc_copy_ref (expr
->ref
);
6120 /* Trim away the extraneous references that emerge from nested
6121 use of interface.c (extend_expr). */
6122 get_declared_from_expr (&class_ref
, NULL
, code
->expr1
, false);
6123 if (class_ref
&& class_ref
->next
)
6125 gfc_free_ref_list (class_ref
->next
);
6126 class_ref
->next
= NULL
;
6128 else if (code
->expr1
->ref
&& !class_ref
)
6130 gfc_free_ref_list (code
->expr1
->ref
);
6131 code
->expr1
->ref
= NULL
;
6134 /* Now use the procedure in the vtable. */
6135 gfc_add_vptr_component (code
->expr1
);
6136 gfc_add_component_ref (code
->expr1
, name
);
6137 code
->expr1
->value
.function
.esym
= NULL
;
6138 if (expr
->expr_type
!= EXPR_VARIABLE
)
6139 code
->expr1
->base_expr
= expr
;
6144 return resolve_typebound_call (code
, NULL
, NULL
);
6146 if (!resolve_ref (code
->expr1
))
6149 /* Get the CLASS declared type. */
6150 get_declared_from_expr (&class_ref
, &new_ref
, code
->expr1
, true);
6152 /* Weed out cases of the ultimate component being a derived type. */
6153 if ((class_ref
&& class_ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
6154 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
6156 gfc_free_ref_list (new_ref
);
6157 return resolve_typebound_call (code
, NULL
, NULL
);
6160 if (!resolve_typebound_call (code
, &name
, &overridable
))
6162 gfc_free_ref_list (new_ref
);
6165 ts
= code
->expr1
->ts
;
6169 /* Convert the expression to a procedure pointer component call. */
6170 code
->expr1
->value
.function
.esym
= NULL
;
6171 code
->expr1
->symtree
= st
;
6174 code
->expr1
->ref
= new_ref
;
6176 /* '_vptr' points to the vtab, which contains the procedure pointers. */
6177 gfc_add_vptr_component (code
->expr1
);
6178 gfc_add_component_ref (code
->expr1
, name
);
6180 /* Recover the typespec for the expression. This is really only
6181 necessary for generic procedures, where the additional call
6182 to gfc_add_component_ref seems to throw the collection of the
6183 correct typespec. */
6184 code
->expr1
->ts
= ts
;
6187 gfc_free_ref_list (new_ref
);
6193 /* Resolve a CALL to a Procedure Pointer Component (Subroutine). */
6196 resolve_ppc_call (gfc_code
* c
)
6198 gfc_component
*comp
;
6200 comp
= gfc_get_proc_ptr_comp (c
->expr1
);
6201 gcc_assert (comp
!= NULL
);
6203 c
->resolved_sym
= c
->expr1
->symtree
->n
.sym
;
6204 c
->expr1
->expr_type
= EXPR_VARIABLE
;
6206 if (!comp
->attr
.subroutine
)
6207 gfc_add_subroutine (&comp
->attr
, comp
->name
, &c
->expr1
->where
);
6209 if (!resolve_ref (c
->expr1
))
6212 if (!update_ppc_arglist (c
->expr1
))
6215 c
->ext
.actual
= c
->expr1
->value
.compcall
.actual
;
6217 if (!resolve_actual_arglist (c
->ext
.actual
, comp
->attr
.proc
,
6218 !(comp
->ts
.interface
6219 && comp
->ts
.interface
->formal
)))
6222 if (!pure_subroutine (comp
->ts
.interface
, comp
->name
, &c
->expr1
->where
))
6225 gfc_ppc_use (comp
, &c
->expr1
->value
.compcall
.actual
, &c
->expr1
->where
);
6231 /* Resolve a Function Call to a Procedure Pointer Component (Function). */
6234 resolve_expr_ppc (gfc_expr
* e
)
6236 gfc_component
*comp
;
6238 comp
= gfc_get_proc_ptr_comp (e
);
6239 gcc_assert (comp
!= NULL
);
6241 /* Convert to EXPR_FUNCTION. */
6242 e
->expr_type
= EXPR_FUNCTION
;
6243 e
->value
.function
.isym
= NULL
;
6244 e
->value
.function
.actual
= e
->value
.compcall
.actual
;
6246 if (comp
->as
!= NULL
)
6247 e
->rank
= comp
->as
->rank
;
6249 if (!comp
->attr
.function
)
6250 gfc_add_function (&comp
->attr
, comp
->name
, &e
->where
);
6252 if (!resolve_ref (e
))
6255 if (!resolve_actual_arglist (e
->value
.function
.actual
, comp
->attr
.proc
,
6256 !(comp
->ts
.interface
6257 && comp
->ts
.interface
->formal
)))
6260 if (!update_ppc_arglist (e
))
6263 if (!check_pure_function(e
))
6266 gfc_ppc_use (comp
, &e
->value
.compcall
.actual
, &e
->where
);
6273 gfc_is_expandable_expr (gfc_expr
*e
)
6275 gfc_constructor
*con
;
6277 if (e
->expr_type
== EXPR_ARRAY
)
6279 /* Traverse the constructor looking for variables that are flavor
6280 parameter. Parameters must be expanded since they are fully used at
6282 con
= gfc_constructor_first (e
->value
.constructor
);
6283 for (; con
; con
= gfc_constructor_next (con
))
6285 if (con
->expr
->expr_type
== EXPR_VARIABLE
6286 && con
->expr
->symtree
6287 && (con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
6288 || con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_VARIABLE
))
6290 if (con
->expr
->expr_type
== EXPR_ARRAY
6291 && gfc_is_expandable_expr (con
->expr
))
6299 /* Resolve an expression. That is, make sure that types of operands agree
6300 with their operators, intrinsic operators are converted to function calls
6301 for overloaded types and unresolved function references are resolved. */
6304 gfc_resolve_expr (gfc_expr
*e
)
6307 bool inquiry_save
, actual_arg_save
, first_actual_arg_save
;
6312 /* inquiry_argument only applies to variables. */
6313 inquiry_save
= inquiry_argument
;
6314 actual_arg_save
= actual_arg
;
6315 first_actual_arg_save
= first_actual_arg
;
6317 if (e
->expr_type
!= EXPR_VARIABLE
)
6319 inquiry_argument
= false;
6321 first_actual_arg
= false;
6324 switch (e
->expr_type
)
6327 t
= resolve_operator (e
);
6333 if (check_host_association (e
))
6334 t
= resolve_function (e
);
6336 t
= resolve_variable (e
);
6338 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.u
.cl
== NULL
&& e
->ref
6339 && e
->ref
->type
!= REF_SUBSTRING
)
6340 gfc_resolve_substring_charlen (e
);
6345 t
= resolve_typebound_function (e
);
6348 case EXPR_SUBSTRING
:
6349 t
= resolve_ref (e
);
6358 t
= resolve_expr_ppc (e
);
6363 if (!resolve_ref (e
))
6366 t
= gfc_resolve_array_constructor (e
);
6367 /* Also try to expand a constructor. */
6370 expression_rank (e
);
6371 if (gfc_is_constant_expr (e
) || gfc_is_expandable_expr (e
))
6372 gfc_expand_constructor (e
, false);
6375 /* This provides the opportunity for the length of constructors with
6376 character valued function elements to propagate the string length
6377 to the expression. */
6378 if (t
&& e
->ts
.type
== BT_CHARACTER
)
6380 /* For efficiency, we call gfc_expand_constructor for BT_CHARACTER
6381 here rather then add a duplicate test for it above. */
6382 gfc_expand_constructor (e
, false);
6383 t
= gfc_resolve_character_array_constructor (e
);
6388 case EXPR_STRUCTURE
:
6389 t
= resolve_ref (e
);
6393 t
= resolve_structure_cons (e
, 0);
6397 t
= gfc_simplify_expr (e
, 0);
6401 gfc_internal_error ("gfc_resolve_expr(): Bad expression type");
6404 if (e
->ts
.type
== BT_CHARACTER
&& t
&& !e
->ts
.u
.cl
)
6407 inquiry_argument
= inquiry_save
;
6408 actual_arg
= actual_arg_save
;
6409 first_actual_arg
= first_actual_arg_save
;
6415 /* Resolve an expression from an iterator. They must be scalar and have
6416 INTEGER or (optionally) REAL type. */
6419 gfc_resolve_iterator_expr (gfc_expr
*expr
, bool real_ok
,
6420 const char *name_msgid
)
6422 if (!gfc_resolve_expr (expr
))
6425 if (expr
->rank
!= 0)
6427 gfc_error ("%s at %L must be a scalar", _(name_msgid
), &expr
->where
);
6431 if (expr
->ts
.type
!= BT_INTEGER
)
6433 if (expr
->ts
.type
== BT_REAL
)
6436 return gfc_notify_std (GFC_STD_F95_DEL
,
6437 "%s at %L must be integer",
6438 _(name_msgid
), &expr
->where
);
6441 gfc_error ("%s at %L must be INTEGER", _(name_msgid
),
6448 gfc_error ("%s at %L must be INTEGER", _(name_msgid
), &expr
->where
);
6456 /* Resolve the expressions in an iterator structure. If REAL_OK is
6457 false allow only INTEGER type iterators, otherwise allow REAL types.
6458 Set own_scope to true for ac-implied-do and data-implied-do as those
6459 have a separate scope such that, e.g., a INTENT(IN) doesn't apply. */
6462 gfc_resolve_iterator (gfc_iterator
*iter
, bool real_ok
, bool own_scope
)
6464 if (!gfc_resolve_iterator_expr (iter
->var
, real_ok
, "Loop variable"))
6467 if (!gfc_check_vardef_context (iter
->var
, false, false, own_scope
,
6468 _("iterator variable")))
6471 if (!gfc_resolve_iterator_expr (iter
->start
, real_ok
,
6472 "Start expression in DO loop"))
6475 if (!gfc_resolve_iterator_expr (iter
->end
, real_ok
,
6476 "End expression in DO loop"))
6479 if (!gfc_resolve_iterator_expr (iter
->step
, real_ok
,
6480 "Step expression in DO loop"))
6483 if (iter
->step
->expr_type
== EXPR_CONSTANT
)
6485 if ((iter
->step
->ts
.type
== BT_INTEGER
6486 && mpz_cmp_ui (iter
->step
->value
.integer
, 0) == 0)
6487 || (iter
->step
->ts
.type
== BT_REAL
6488 && mpfr_sgn (iter
->step
->value
.real
) == 0))
6490 gfc_error ("Step expression in DO loop at %L cannot be zero",
6491 &iter
->step
->where
);
6496 /* Convert start, end, and step to the same type as var. */
6497 if (iter
->start
->ts
.kind
!= iter
->var
->ts
.kind
6498 || iter
->start
->ts
.type
!= iter
->var
->ts
.type
)
6499 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 2);
6501 if (iter
->end
->ts
.kind
!= iter
->var
->ts
.kind
6502 || iter
->end
->ts
.type
!= iter
->var
->ts
.type
)
6503 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 2);
6505 if (iter
->step
->ts
.kind
!= iter
->var
->ts
.kind
6506 || iter
->step
->ts
.type
!= iter
->var
->ts
.type
)
6507 gfc_convert_type (iter
->step
, &iter
->var
->ts
, 2);
6509 if (iter
->start
->expr_type
== EXPR_CONSTANT
6510 && iter
->end
->expr_type
== EXPR_CONSTANT
6511 && iter
->step
->expr_type
== EXPR_CONSTANT
)
6514 if (iter
->start
->ts
.type
== BT_INTEGER
)
6516 sgn
= mpz_cmp_ui (iter
->step
->value
.integer
, 0);
6517 cmp
= mpz_cmp (iter
->end
->value
.integer
, iter
->start
->value
.integer
);
6521 sgn
= mpfr_sgn (iter
->step
->value
.real
);
6522 cmp
= mpfr_cmp (iter
->end
->value
.real
, iter
->start
->value
.real
);
6524 if (warn_zerotrip
&& ((sgn
> 0 && cmp
< 0) || (sgn
< 0 && cmp
> 0)))
6525 gfc_warning (OPT_Wzerotrip
,
6526 "DO loop at %L will be executed zero times",
6527 &iter
->step
->where
);
6534 /* Traversal function for find_forall_index. f == 2 signals that
6535 that variable itself is not to be checked - only the references. */
6538 forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int *f
)
6540 if (expr
->expr_type
!= EXPR_VARIABLE
)
6543 /* A scalar assignment */
6544 if (!expr
->ref
|| *f
== 1)
6546 if (expr
->symtree
->n
.sym
== sym
)
6558 /* Check whether the FORALL index appears in the expression or not.
6559 Returns true if SYM is found in EXPR. */
6562 find_forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int f
)
6564 if (gfc_traverse_expr (expr
, sym
, forall_index
, f
))
6571 /* Resolve a list of FORALL iterators. The FORALL index-name is constrained
6572 to be a scalar INTEGER variable. The subscripts and stride are scalar
6573 INTEGERs, and if stride is a constant it must be nonzero.
6574 Furthermore "A subscript or stride in a forall-triplet-spec shall
6575 not contain a reference to any index-name in the
6576 forall-triplet-spec-list in which it appears." (7.5.4.1) */
6579 resolve_forall_iterators (gfc_forall_iterator
*it
)
6581 gfc_forall_iterator
*iter
, *iter2
;
6583 for (iter
= it
; iter
; iter
= iter
->next
)
6585 if (gfc_resolve_expr (iter
->var
)
6586 && (iter
->var
->ts
.type
!= BT_INTEGER
|| iter
->var
->rank
!= 0))
6587 gfc_error ("FORALL index-name at %L must be a scalar INTEGER",
6590 if (gfc_resolve_expr (iter
->start
)
6591 && (iter
->start
->ts
.type
!= BT_INTEGER
|| iter
->start
->rank
!= 0))
6592 gfc_error ("FORALL start expression at %L must be a scalar INTEGER",
6593 &iter
->start
->where
);
6594 if (iter
->var
->ts
.kind
!= iter
->start
->ts
.kind
)
6595 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 1);
6597 if (gfc_resolve_expr (iter
->end
)
6598 && (iter
->end
->ts
.type
!= BT_INTEGER
|| iter
->end
->rank
!= 0))
6599 gfc_error ("FORALL end expression at %L must be a scalar INTEGER",
6601 if (iter
->var
->ts
.kind
!= iter
->end
->ts
.kind
)
6602 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 1);
6604 if (gfc_resolve_expr (iter
->stride
))
6606 if (iter
->stride
->ts
.type
!= BT_INTEGER
|| iter
->stride
->rank
!= 0)
6607 gfc_error ("FORALL stride expression at %L must be a scalar %s",
6608 &iter
->stride
->where
, "INTEGER");
6610 if (iter
->stride
->expr_type
== EXPR_CONSTANT
6611 && mpz_cmp_ui (iter
->stride
->value
.integer
, 0) == 0)
6612 gfc_error ("FORALL stride expression at %L cannot be zero",
6613 &iter
->stride
->where
);
6615 if (iter
->var
->ts
.kind
!= iter
->stride
->ts
.kind
)
6616 gfc_convert_type (iter
->stride
, &iter
->var
->ts
, 1);
6619 for (iter
= it
; iter
; iter
= iter
->next
)
6620 for (iter2
= iter
; iter2
; iter2
= iter2
->next
)
6622 if (find_forall_index (iter2
->start
, iter
->var
->symtree
->n
.sym
, 0)
6623 || find_forall_index (iter2
->end
, iter
->var
->symtree
->n
.sym
, 0)
6624 || find_forall_index (iter2
->stride
, iter
->var
->symtree
->n
.sym
, 0))
6625 gfc_error ("FORALL index %qs may not appear in triplet "
6626 "specification at %L", iter
->var
->symtree
->name
,
6627 &iter2
->start
->where
);
6632 /* Given a pointer to a symbol that is a derived type, see if it's
6633 inaccessible, i.e. if it's defined in another module and the components are
6634 PRIVATE. The search is recursive if necessary. Returns zero if no
6635 inaccessible components are found, nonzero otherwise. */
6638 derived_inaccessible (gfc_symbol
*sym
)
6642 if (sym
->attr
.use_assoc
&& sym
->attr
.private_comp
)
6645 for (c
= sym
->components
; c
; c
= c
->next
)
6647 if (c
->ts
.type
== BT_DERIVED
&& derived_inaccessible (c
->ts
.u
.derived
))
6655 /* Resolve the argument of a deallocate expression. The expression must be
6656 a pointer or a full array. */
6659 resolve_deallocate_expr (gfc_expr
*e
)
6661 symbol_attribute attr
;
6662 int allocatable
, pointer
;
6668 if (!gfc_resolve_expr (e
))
6671 if (e
->expr_type
!= EXPR_VARIABLE
)
6674 sym
= e
->symtree
->n
.sym
;
6675 unlimited
= UNLIMITED_POLY(sym
);
6677 if (sym
->ts
.type
== BT_CLASS
)
6679 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6680 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6684 allocatable
= sym
->attr
.allocatable
;
6685 pointer
= sym
->attr
.pointer
;
6687 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6692 if (ref
->u
.ar
.type
!= AR_FULL
6693 && !(ref
->u
.ar
.type
== AR_ELEMENT
&& ref
->u
.ar
.as
->rank
== 0
6694 && ref
->u
.ar
.codimen
&& gfc_ref_this_image (ref
)))
6699 c
= ref
->u
.c
.component
;
6700 if (c
->ts
.type
== BT_CLASS
)
6702 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
6703 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
6707 allocatable
= c
->attr
.allocatable
;
6708 pointer
= c
->attr
.pointer
;
6718 attr
= gfc_expr_attr (e
);
6720 if (allocatable
== 0 && attr
.pointer
== 0 && !unlimited
)
6723 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
6729 if (gfc_is_coindexed (e
))
6731 gfc_error ("Coindexed allocatable object at %L", &e
->where
);
6736 && !gfc_check_vardef_context (e
, true, true, false,
6737 _("DEALLOCATE object")))
6739 if (!gfc_check_vardef_context (e
, false, true, false,
6740 _("DEALLOCATE object")))
6747 /* Returns true if the expression e contains a reference to the symbol sym. */
6749 sym_in_expr (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
6751 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
== sym
)
6758 gfc_find_sym_in_expr (gfc_symbol
*sym
, gfc_expr
*e
)
6760 return gfc_traverse_expr (e
, sym
, sym_in_expr
, 0);
6764 /* Given the expression node e for an allocatable/pointer of derived type to be
6765 allocated, get the expression node to be initialized afterwards (needed for
6766 derived types with default initializers, and derived types with allocatable
6767 components that need nullification.) */
6770 gfc_expr_to_initialize (gfc_expr
*e
)
6776 result
= gfc_copy_expr (e
);
6778 /* Change the last array reference from AR_ELEMENT to AR_FULL. */
6779 for (ref
= result
->ref
; ref
; ref
= ref
->next
)
6780 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
6782 ref
->u
.ar
.type
= AR_FULL
;
6784 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
6785 ref
->u
.ar
.start
[i
] = ref
->u
.ar
.end
[i
] = ref
->u
.ar
.stride
[i
] = NULL
;
6790 gfc_free_shape (&result
->shape
, result
->rank
);
6792 /* Recalculate rank, shape, etc. */
6793 gfc_resolve_expr (result
);
6798 /* If the last ref of an expression is an array ref, return a copy of the
6799 expression with that one removed. Otherwise, a copy of the original
6800 expression. This is used for allocate-expressions and pointer assignment
6801 LHS, where there may be an array specification that needs to be stripped
6802 off when using gfc_check_vardef_context. */
6805 remove_last_array_ref (gfc_expr
* e
)
6810 e2
= gfc_copy_expr (e
);
6811 for (r
= &e2
->ref
; *r
; r
= &(*r
)->next
)
6812 if ((*r
)->type
== REF_ARRAY
&& !(*r
)->next
)
6814 gfc_free_ref_list (*r
);
6823 /* Used in resolve_allocate_expr to check that a allocation-object and
6824 a source-expr are conformable. This does not catch all possible
6825 cases; in particular a runtime checking is needed. */
6828 conformable_arrays (gfc_expr
*e1
, gfc_expr
*e2
)
6831 for (tail
= e2
->ref
; tail
&& tail
->next
; tail
= tail
->next
);
6833 /* First compare rank. */
6834 if ((tail
&& e1
->rank
!= tail
->u
.ar
.as
->rank
)
6835 || (!tail
&& e1
->rank
!= e2
->rank
))
6837 gfc_error ("Source-expr at %L must be scalar or have the "
6838 "same rank as the allocate-object at %L",
6839 &e1
->where
, &e2
->where
);
6850 for (i
= 0; i
< e1
->rank
; i
++)
6852 if (tail
->u
.ar
.start
[i
] == NULL
)
6855 if (tail
->u
.ar
.end
[i
])
6857 mpz_set (s
, tail
->u
.ar
.end
[i
]->value
.integer
);
6858 mpz_sub (s
, s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6859 mpz_add_ui (s
, s
, 1);
6863 mpz_set (s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6866 if (mpz_cmp (e1
->shape
[i
], s
) != 0)
6868 gfc_error ("Source-expr at %L and allocate-object at %L must "
6869 "have the same shape", &e1
->where
, &e2
->where
);
6882 /* Resolve the expression in an ALLOCATE statement, doing the additional
6883 checks to see whether the expression is OK or not. The expression must
6884 have a trailing array reference that gives the size of the array. */
6887 resolve_allocate_expr (gfc_expr
*e
, gfc_code
*code
, bool *array_alloc_wo_spec
)
6889 int i
, pointer
, allocatable
, dimension
, is_abstract
;
6893 symbol_attribute attr
;
6894 gfc_ref
*ref
, *ref2
;
6897 gfc_symbol
*sym
= NULL
;
6902 /* Mark the utmost array component as being in allocate to allow DIMEN_STAR
6903 checking of coarrays. */
6904 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6905 if (ref
->next
== NULL
)
6908 if (ref
&& ref
->type
== REF_ARRAY
)
6909 ref
->u
.ar
.in_allocate
= true;
6911 if (!gfc_resolve_expr (e
))
6914 /* Make sure the expression is allocatable or a pointer. If it is
6915 pointer, the next-to-last reference must be a pointer. */
6919 sym
= e
->symtree
->n
.sym
;
6921 /* Check whether ultimate component is abstract and CLASS. */
6924 /* Is the allocate-object unlimited polymorphic? */
6925 unlimited
= UNLIMITED_POLY(e
);
6927 if (e
->expr_type
!= EXPR_VARIABLE
)
6930 attr
= gfc_expr_attr (e
);
6931 pointer
= attr
.pointer
;
6932 dimension
= attr
.dimension
;
6933 codimension
= attr
.codimension
;
6937 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
6939 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6940 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6941 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
6942 codimension
= CLASS_DATA (sym
)->attr
.codimension
;
6943 is_abstract
= CLASS_DATA (sym
)->attr
.abstract
;
6947 allocatable
= sym
->attr
.allocatable
;
6948 pointer
= sym
->attr
.pointer
;
6949 dimension
= sym
->attr
.dimension
;
6950 codimension
= sym
->attr
.codimension
;
6955 for (ref
= e
->ref
; ref
; ref2
= ref
, ref
= ref
->next
)
6960 if (ref
->u
.ar
.codimen
> 0)
6963 for (n
= ref
->u
.ar
.dimen
;
6964 n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
6965 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_THIS_IMAGE
)
6972 if (ref
->next
!= NULL
)
6980 gfc_error ("Coindexed allocatable object at %L",
6985 c
= ref
->u
.c
.component
;
6986 if (c
->ts
.type
== BT_CLASS
)
6988 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
6989 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
6990 dimension
= CLASS_DATA (c
)->attr
.dimension
;
6991 codimension
= CLASS_DATA (c
)->attr
.codimension
;
6992 is_abstract
= CLASS_DATA (c
)->attr
.abstract
;
6996 allocatable
= c
->attr
.allocatable
;
6997 pointer
= c
->attr
.pointer
;
6998 dimension
= c
->attr
.dimension
;
6999 codimension
= c
->attr
.codimension
;
7000 is_abstract
= c
->attr
.abstract
;
7012 /* Check for F08:C628. */
7013 if (allocatable
== 0 && pointer
== 0 && !unlimited
)
7015 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
7020 /* Some checks for the SOURCE tag. */
7023 /* Check F03:C631. */
7024 if (!gfc_type_compatible (&e
->ts
, &code
->expr3
->ts
))
7026 gfc_error ("Type of entity at %L is type incompatible with "
7027 "source-expr at %L", &e
->where
, &code
->expr3
->where
);
7031 /* Check F03:C632 and restriction following Note 6.18. */
7032 if (code
->expr3
->rank
> 0 && !conformable_arrays (code
->expr3
, e
))
7035 /* Check F03:C633. */
7036 if (code
->expr3
->ts
.kind
!= e
->ts
.kind
&& !unlimited
)
7038 gfc_error ("The allocate-object at %L and the source-expr at %L "
7039 "shall have the same kind type parameter",
7040 &e
->where
, &code
->expr3
->where
);
7044 /* Check F2008, C642. */
7045 if (code
->expr3
->ts
.type
== BT_DERIVED
7046 && ((codimension
&& gfc_expr_attr (code
->expr3
).lock_comp
)
7047 || (code
->expr3
->ts
.u
.derived
->from_intmod
7048 == INTMOD_ISO_FORTRAN_ENV
7049 && code
->expr3
->ts
.u
.derived
->intmod_sym_id
7050 == ISOFORTRAN_LOCK_TYPE
)))
7052 gfc_error ("The source-expr at %L shall neither be of type "
7053 "LOCK_TYPE nor have a LOCK_TYPE component if "
7054 "allocate-object at %L is a coarray",
7055 &code
->expr3
->where
, &e
->where
);
7060 /* Check F08:C629. */
7061 if (is_abstract
&& code
->ext
.alloc
.ts
.type
== BT_UNKNOWN
7064 gcc_assert (e
->ts
.type
== BT_CLASS
);
7065 gfc_error ("Allocating %s of ABSTRACT base type at %L requires a "
7066 "type-spec or source-expr", sym
->name
, &e
->where
);
7070 /* Check F08:C632. */
7071 if (code
->ext
.alloc
.ts
.type
== BT_CHARACTER
&& !e
->ts
.deferred
7072 && !UNLIMITED_POLY (e
))
7074 int cmp
= gfc_dep_compare_expr (e
->ts
.u
.cl
->length
,
7075 code
->ext
.alloc
.ts
.u
.cl
->length
);
7076 if (cmp
== 1 || cmp
== -1 || cmp
== -3)
7078 gfc_error ("Allocating %s at %L with type-spec requires the same "
7079 "character-length parameter as in the declaration",
7080 sym
->name
, &e
->where
);
7085 /* In the variable definition context checks, gfc_expr_attr is used
7086 on the expression. This is fooled by the array specification
7087 present in e, thus we have to eliminate that one temporarily. */
7088 e2
= remove_last_array_ref (e
);
7091 t
= gfc_check_vardef_context (e2
, true, true, false,
7092 _("ALLOCATE object"));
7094 t
= gfc_check_vardef_context (e2
, false, true, false,
7095 _("ALLOCATE object"));
7100 if (e
->ts
.type
== BT_CLASS
&& CLASS_DATA (e
)->attr
.dimension
7101 && !code
->expr3
&& code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
7103 /* For class arrays, the initialization with SOURCE is done
7104 using _copy and trans_call. It is convenient to exploit that
7105 when the allocated type is different from the declared type but
7106 no SOURCE exists by setting expr3. */
7107 code
->expr3
= gfc_default_initializer (&code
->ext
.alloc
.ts
);
7109 else if (!code
->expr3
)
7111 /* Set up default initializer if needed. */
7115 if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
7116 ts
= code
->ext
.alloc
.ts
;
7120 if (ts
.type
== BT_CLASS
)
7121 ts
= ts
.u
.derived
->components
->ts
;
7123 if (ts
.type
== BT_DERIVED
&& (init_e
= gfc_default_initializer (&ts
)))
7125 gfc_code
*init_st
= gfc_get_code (EXEC_INIT_ASSIGN
);
7126 init_st
->loc
= code
->loc
;
7127 init_st
->expr1
= gfc_expr_to_initialize (e
);
7128 init_st
->expr2
= init_e
;
7129 init_st
->next
= code
->next
;
7130 code
->next
= init_st
;
7133 else if (code
->expr3
->mold
&& code
->expr3
->ts
.type
== BT_DERIVED
)
7135 /* Default initialization via MOLD (non-polymorphic). */
7136 gfc_expr
*rhs
= gfc_default_initializer (&code
->expr3
->ts
);
7139 gfc_resolve_expr (rhs
);
7140 gfc_free_expr (code
->expr3
);
7145 if (e
->ts
.type
== BT_CLASS
&& !unlimited
&& !UNLIMITED_POLY (code
->expr3
))
7147 /* Make sure the vtab symbol is present when
7148 the module variables are generated. */
7149 gfc_typespec ts
= e
->ts
;
7151 ts
= code
->expr3
->ts
;
7152 else if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
7153 ts
= code
->ext
.alloc
.ts
;
7155 gfc_find_derived_vtab (ts
.u
.derived
);
7158 e
= gfc_expr_to_initialize (e
);
7160 else if (unlimited
&& !UNLIMITED_POLY (code
->expr3
))
7162 /* Again, make sure the vtab symbol is present when
7163 the module variables are generated. */
7164 gfc_typespec
*ts
= NULL
;
7166 ts
= &code
->expr3
->ts
;
7168 ts
= &code
->ext
.alloc
.ts
;
7175 e
= gfc_expr_to_initialize (e
);
7178 if (dimension
== 0 && codimension
== 0)
7181 /* Make sure the last reference node is an array specification. */
7183 if (!ref2
|| ref2
->type
!= REF_ARRAY
|| ref2
->u
.ar
.type
== AR_FULL
7184 || (dimension
&& ref2
->u
.ar
.dimen
== 0))
7189 if (!gfc_notify_std (GFC_STD_F2008
, "Array specification required "
7190 "in ALLOCATE statement at %L", &e
->where
))
7192 *array_alloc_wo_spec
= true;
7196 gfc_error ("Array specification required in ALLOCATE statement "
7197 "at %L", &e
->where
);
7202 /* Make sure that the array section reference makes sense in the
7203 context of an ALLOCATE specification. */
7208 for (i
= ar
->dimen
; i
< ar
->dimen
+ ar
->codimen
; i
++)
7209 if (ar
->dimen_type
[i
] == DIMEN_THIS_IMAGE
)
7211 gfc_error ("Coarray specification required in ALLOCATE statement "
7212 "at %L", &e
->where
);
7216 for (i
= 0; i
< ar
->dimen
; i
++)
7218 if (ar
->type
== AR_ELEMENT
|| ar
->type
== AR_FULL
)
7221 switch (ar
->dimen_type
[i
])
7227 if (ar
->start
[i
] != NULL
7228 && ar
->end
[i
] != NULL
7229 && ar
->stride
[i
] == NULL
)
7232 /* Fall Through... */
7237 case DIMEN_THIS_IMAGE
:
7238 gfc_error ("Bad array specification in ALLOCATE statement at %L",
7244 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7246 sym
= a
->expr
->symtree
->n
.sym
;
7248 /* TODO - check derived type components. */
7249 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
7252 if ((ar
->start
[i
] != NULL
7253 && gfc_find_sym_in_expr (sym
, ar
->start
[i
]))
7254 || (ar
->end
[i
] != NULL
7255 && gfc_find_sym_in_expr (sym
, ar
->end
[i
])))
7257 gfc_error ("%qs must not appear in the array specification at "
7258 "%L in the same ALLOCATE statement where it is "
7259 "itself allocated", sym
->name
, &ar
->where
);
7265 for (i
= ar
->dimen
; i
< ar
->codimen
+ ar
->dimen
; i
++)
7267 if (ar
->dimen_type
[i
] == DIMEN_ELEMENT
7268 || ar
->dimen_type
[i
] == DIMEN_RANGE
)
7270 if (i
== (ar
->dimen
+ ar
->codimen
- 1))
7272 gfc_error ("Expected '*' in coindex specification in ALLOCATE "
7273 "statement at %L", &e
->where
);
7279 if (ar
->dimen_type
[i
] == DIMEN_STAR
&& i
== (ar
->dimen
+ ar
->codimen
- 1)
7280 && ar
->stride
[i
] == NULL
)
7283 gfc_error ("Bad coarray specification in ALLOCATE statement at %L",
7297 resolve_allocate_deallocate (gfc_code
*code
, const char *fcn
)
7299 gfc_expr
*stat
, *errmsg
, *pe
, *qe
;
7300 gfc_alloc
*a
, *p
, *q
;
7303 errmsg
= code
->expr2
;
7305 /* Check the stat variable. */
7308 gfc_check_vardef_context (stat
, false, false, false,
7309 _("STAT variable"));
7311 if ((stat
->ts
.type
!= BT_INTEGER
7312 && !(stat
->ref
&& (stat
->ref
->type
== REF_ARRAY
7313 || stat
->ref
->type
== REF_COMPONENT
)))
7315 gfc_error ("Stat-variable at %L must be a scalar INTEGER "
7316 "variable", &stat
->where
);
7318 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7319 if (p
->expr
->symtree
->n
.sym
->name
== stat
->symtree
->n
.sym
->name
)
7321 gfc_ref
*ref1
, *ref2
;
7324 for (ref1
= p
->expr
->ref
, ref2
= stat
->ref
; ref1
&& ref2
;
7325 ref1
= ref1
->next
, ref2
= ref2
->next
)
7327 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
7329 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
7338 gfc_error ("Stat-variable at %L shall not be %sd within "
7339 "the same %s statement", &stat
->where
, fcn
, fcn
);
7345 /* Check the errmsg variable. */
7349 gfc_warning (0, "ERRMSG at %L is useless without a STAT tag",
7352 gfc_check_vardef_context (errmsg
, false, false, false,
7353 _("ERRMSG variable"));
7355 if ((errmsg
->ts
.type
!= BT_CHARACTER
7357 && (errmsg
->ref
->type
== REF_ARRAY
7358 || errmsg
->ref
->type
== REF_COMPONENT
)))
7359 || errmsg
->rank
> 0 )
7360 gfc_error ("Errmsg-variable at %L must be a scalar CHARACTER "
7361 "variable", &errmsg
->where
);
7363 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7364 if (p
->expr
->symtree
->n
.sym
->name
== errmsg
->symtree
->n
.sym
->name
)
7366 gfc_ref
*ref1
, *ref2
;
7369 for (ref1
= p
->expr
->ref
, ref2
= errmsg
->ref
; ref1
&& ref2
;
7370 ref1
= ref1
->next
, ref2
= ref2
->next
)
7372 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
7374 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
7383 gfc_error ("Errmsg-variable at %L shall not be %sd within "
7384 "the same %s statement", &errmsg
->where
, fcn
, fcn
);
7390 /* Check that an allocate-object appears only once in the statement. */
7392 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7395 for (q
= p
->next
; q
; q
= q
->next
)
7398 if (pe
->symtree
->n
.sym
->name
== qe
->symtree
->n
.sym
->name
)
7400 /* This is a potential collision. */
7401 gfc_ref
*pr
= pe
->ref
;
7402 gfc_ref
*qr
= qe
->ref
;
7404 /* Follow the references until
7405 a) They start to differ, in which case there is no error;
7406 you can deallocate a%b and a%c in a single statement
7407 b) Both of them stop, which is an error
7408 c) One of them stops, which is also an error. */
7411 if (pr
== NULL
&& qr
== NULL
)
7413 gfc_error ("Allocate-object at %L also appears at %L",
7414 &pe
->where
, &qe
->where
);
7417 else if (pr
!= NULL
&& qr
== NULL
)
7419 gfc_error ("Allocate-object at %L is subobject of"
7420 " object at %L", &pe
->where
, &qe
->where
);
7423 else if (pr
== NULL
&& qr
!= NULL
)
7425 gfc_error ("Allocate-object at %L is subobject of"
7426 " object at %L", &qe
->where
, &pe
->where
);
7429 /* Here, pr != NULL && qr != NULL */
7430 gcc_assert(pr
->type
== qr
->type
);
7431 if (pr
->type
== REF_ARRAY
)
7433 /* Handle cases like allocate(v(3)%x(3), v(2)%x(3)),
7435 gcc_assert (qr
->type
== REF_ARRAY
);
7437 if (pr
->next
&& qr
->next
)
7440 gfc_array_ref
*par
= &(pr
->u
.ar
);
7441 gfc_array_ref
*qar
= &(qr
->u
.ar
);
7443 for (i
=0; i
<par
->dimen
; i
++)
7445 if ((par
->start
[i
] != NULL
7446 || qar
->start
[i
] != NULL
)
7447 && gfc_dep_compare_expr (par
->start
[i
],
7448 qar
->start
[i
]) != 0)
7455 if (pr
->u
.c
.component
->name
!= qr
->u
.c
.component
->name
)
7468 if (strcmp (fcn
, "ALLOCATE") == 0)
7470 bool arr_alloc_wo_spec
= false;
7471 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7472 resolve_allocate_expr (a
->expr
, code
, &arr_alloc_wo_spec
);
7474 if (arr_alloc_wo_spec
&& code
->expr3
)
7476 /* Mark the allocate to have to take the array specification
7478 code
->ext
.alloc
.arr_spec_from_expr3
= 1;
7483 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7484 resolve_deallocate_expr (a
->expr
);
7489 /************ SELECT CASE resolution subroutines ************/
7491 /* Callback function for our mergesort variant. Determines interval
7492 overlaps for CASEs. Return <0 if op1 < op2, 0 for overlap, >0 for
7493 op1 > op2. Assumes we're not dealing with the default case.
7494 We have op1 = (:L), (K:L) or (K:) and op2 = (:N), (M:N) or (M:).
7495 There are nine situations to check. */
7498 compare_cases (const gfc_case
*op1
, const gfc_case
*op2
)
7502 if (op1
->low
== NULL
) /* op1 = (:L) */
7504 /* op2 = (:N), so overlap. */
7506 /* op2 = (M:) or (M:N), L < M */
7507 if (op2
->low
!= NULL
7508 && gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7511 else if (op1
->high
== NULL
) /* op1 = (K:) */
7513 /* op2 = (M:), so overlap. */
7515 /* op2 = (:N) or (M:N), K > N */
7516 if (op2
->high
!= NULL
7517 && gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7520 else /* op1 = (K:L) */
7522 if (op2
->low
== NULL
) /* op2 = (:N), K > N */
7523 retval
= (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7525 else if (op2
->high
== NULL
) /* op2 = (M:), L < M */
7526 retval
= (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7528 else /* op2 = (M:N) */
7532 if (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7535 else if (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7544 /* Merge-sort a double linked case list, detecting overlap in the
7545 process. LIST is the head of the double linked case list before it
7546 is sorted. Returns the head of the sorted list if we don't see any
7547 overlap, or NULL otherwise. */
7550 check_case_overlap (gfc_case
*list
)
7552 gfc_case
*p
, *q
, *e
, *tail
;
7553 int insize
, nmerges
, psize
, qsize
, cmp
, overlap_seen
;
7555 /* If the passed list was empty, return immediately. */
7562 /* Loop unconditionally. The only exit from this loop is a return
7563 statement, when we've finished sorting the case list. */
7570 /* Count the number of merges we do in this pass. */
7573 /* Loop while there exists a merge to be done. */
7578 /* Count this merge. */
7581 /* Cut the list in two pieces by stepping INSIZE places
7582 forward in the list, starting from P. */
7585 for (i
= 0; i
< insize
; i
++)
7594 /* Now we have two lists. Merge them! */
7595 while (psize
> 0 || (qsize
> 0 && q
!= NULL
))
7597 /* See from which the next case to merge comes from. */
7600 /* P is empty so the next case must come from Q. */
7605 else if (qsize
== 0 || q
== NULL
)
7614 cmp
= compare_cases (p
, q
);
7617 /* The whole case range for P is less than the
7625 /* The whole case range for Q is greater than
7626 the case range for P. */
7633 /* The cases overlap, or they are the same
7634 element in the list. Either way, we must
7635 issue an error and get the next case from P. */
7636 /* FIXME: Sort P and Q by line number. */
7637 gfc_error ("CASE label at %L overlaps with CASE "
7638 "label at %L", &p
->where
, &q
->where
);
7646 /* Add the next element to the merged list. */
7655 /* P has now stepped INSIZE places along, and so has Q. So
7656 they're the same. */
7661 /* If we have done only one merge or none at all, we've
7662 finished sorting the cases. */
7671 /* Otherwise repeat, merging lists twice the size. */
7677 /* Check to see if an expression is suitable for use in a CASE statement.
7678 Makes sure that all case expressions are scalar constants of the same
7679 type. Return false if anything is wrong. */
7682 validate_case_label_expr (gfc_expr
*e
, gfc_expr
*case_expr
)
7684 if (e
== NULL
) return true;
7686 if (e
->ts
.type
!= case_expr
->ts
.type
)
7688 gfc_error ("Expression in CASE statement at %L must be of type %s",
7689 &e
->where
, gfc_basic_typename (case_expr
->ts
.type
));
7693 /* C805 (R808) For a given case-construct, each case-value shall be of
7694 the same type as case-expr. For character type, length differences
7695 are allowed, but the kind type parameters shall be the same. */
7697 if (case_expr
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= case_expr
->ts
.kind
)
7699 gfc_error ("Expression in CASE statement at %L must be of kind %d",
7700 &e
->where
, case_expr
->ts
.kind
);
7704 /* Convert the case value kind to that of case expression kind,
7707 if (e
->ts
.kind
!= case_expr
->ts
.kind
)
7708 gfc_convert_type_warn (e
, &case_expr
->ts
, 2, 0);
7712 gfc_error ("Expression in CASE statement at %L must be scalar",
7721 /* Given a completely parsed select statement, we:
7723 - Validate all expressions and code within the SELECT.
7724 - Make sure that the selection expression is not of the wrong type.
7725 - Make sure that no case ranges overlap.
7726 - Eliminate unreachable cases and unreachable code resulting from
7727 removing case labels.
7729 The standard does allow unreachable cases, e.g. CASE (5:3). But
7730 they are a hassle for code generation, and to prevent that, we just
7731 cut them out here. This is not necessary for overlapping cases
7732 because they are illegal and we never even try to generate code.
7734 We have the additional caveat that a SELECT construct could have
7735 been a computed GOTO in the source code. Fortunately we can fairly
7736 easily work around that here: The case_expr for a "real" SELECT CASE
7737 is in code->expr1, but for a computed GOTO it is in code->expr2. All
7738 we have to do is make sure that the case_expr is a scalar integer
7742 resolve_select (gfc_code
*code
, bool select_type
)
7745 gfc_expr
*case_expr
;
7746 gfc_case
*cp
, *default_case
, *tail
, *head
;
7747 int seen_unreachable
;
7753 if (code
->expr1
== NULL
)
7755 /* This was actually a computed GOTO statement. */
7756 case_expr
= code
->expr2
;
7757 if (case_expr
->ts
.type
!= BT_INTEGER
|| case_expr
->rank
!= 0)
7758 gfc_error ("Selection expression in computed GOTO statement "
7759 "at %L must be a scalar integer expression",
7762 /* Further checking is not necessary because this SELECT was built
7763 by the compiler, so it should always be OK. Just move the
7764 case_expr from expr2 to expr so that we can handle computed
7765 GOTOs as normal SELECTs from here on. */
7766 code
->expr1
= code
->expr2
;
7771 case_expr
= code
->expr1
;
7772 type
= case_expr
->ts
.type
;
7775 if (type
!= BT_LOGICAL
&& type
!= BT_INTEGER
&& type
!= BT_CHARACTER
)
7777 gfc_error ("Argument of SELECT statement at %L cannot be %s",
7778 &case_expr
->where
, gfc_typename (&case_expr
->ts
));
7780 /* Punt. Going on here just produce more garbage error messages. */
7785 if (!select_type
&& case_expr
->rank
!= 0)
7787 gfc_error ("Argument of SELECT statement at %L must be a scalar "
7788 "expression", &case_expr
->where
);
7794 /* Raise a warning if an INTEGER case value exceeds the range of
7795 the case-expr. Later, all expressions will be promoted to the
7796 largest kind of all case-labels. */
7798 if (type
== BT_INTEGER
)
7799 for (body
= code
->block
; body
; body
= body
->block
)
7800 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7803 && gfc_check_integer_range (cp
->low
->value
.integer
,
7804 case_expr
->ts
.kind
) != ARITH_OK
)
7805 gfc_warning (0, "Expression in CASE statement at %L is "
7806 "not in the range of %s", &cp
->low
->where
,
7807 gfc_typename (&case_expr
->ts
));
7810 && cp
->low
!= cp
->high
7811 && gfc_check_integer_range (cp
->high
->value
.integer
,
7812 case_expr
->ts
.kind
) != ARITH_OK
)
7813 gfc_warning (0, "Expression in CASE statement at %L is "
7814 "not in the range of %s", &cp
->high
->where
,
7815 gfc_typename (&case_expr
->ts
));
7818 /* PR 19168 has a long discussion concerning a mismatch of the kinds
7819 of the SELECT CASE expression and its CASE values. Walk the lists
7820 of case values, and if we find a mismatch, promote case_expr to
7821 the appropriate kind. */
7823 if (type
== BT_LOGICAL
|| type
== BT_INTEGER
)
7825 for (body
= code
->block
; body
; body
= body
->block
)
7827 /* Walk the case label list. */
7828 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7830 /* Intercept the DEFAULT case. It does not have a kind. */
7831 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7834 /* Unreachable case ranges are discarded, so ignore. */
7835 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7836 && cp
->low
!= cp
->high
7837 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7841 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->low
))
7842 gfc_convert_type_warn (case_expr
, &cp
->low
->ts
, 2, 0);
7844 if (cp
->high
!= NULL
7845 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->high
))
7846 gfc_convert_type_warn (case_expr
, &cp
->high
->ts
, 2, 0);
7851 /* Assume there is no DEFAULT case. */
7852 default_case
= NULL
;
7857 for (body
= code
->block
; body
; body
= body
->block
)
7859 /* Assume the CASE list is OK, and all CASE labels can be matched. */
7861 seen_unreachable
= 0;
7863 /* Walk the case label list, making sure that all case labels
7865 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7867 /* Count the number of cases in the whole construct. */
7870 /* Intercept the DEFAULT case. */
7871 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7873 if (default_case
!= NULL
)
7875 gfc_error ("The DEFAULT CASE at %L cannot be followed "
7876 "by a second DEFAULT CASE at %L",
7877 &default_case
->where
, &cp
->where
);
7888 /* Deal with single value cases and case ranges. Errors are
7889 issued from the validation function. */
7890 if (!validate_case_label_expr (cp
->low
, case_expr
)
7891 || !validate_case_label_expr (cp
->high
, case_expr
))
7897 if (type
== BT_LOGICAL
7898 && ((cp
->low
== NULL
|| cp
->high
== NULL
)
7899 || cp
->low
!= cp
->high
))
7901 gfc_error ("Logical range in CASE statement at %L is not "
7902 "allowed", &cp
->low
->where
);
7907 if (type
== BT_LOGICAL
&& cp
->low
->expr_type
== EXPR_CONSTANT
)
7910 value
= cp
->low
->value
.logical
== 0 ? 2 : 1;
7911 if (value
& seen_logical
)
7913 gfc_error ("Constant logical value in CASE statement "
7914 "is repeated at %L",
7919 seen_logical
|= value
;
7922 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7923 && cp
->low
!= cp
->high
7924 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7926 if (warn_surprising
)
7927 gfc_warning (OPT_Wsurprising
,
7928 "Range specification at %L can never be matched",
7931 cp
->unreachable
= 1;
7932 seen_unreachable
= 1;
7936 /* If the case range can be matched, it can also overlap with
7937 other cases. To make sure it does not, we put it in a
7938 double linked list here. We sort that with a merge sort
7939 later on to detect any overlapping cases. */
7943 head
->right
= head
->left
= NULL
;
7948 tail
->right
->left
= tail
;
7955 /* It there was a failure in the previous case label, give up
7956 for this case label list. Continue with the next block. */
7960 /* See if any case labels that are unreachable have been seen.
7961 If so, we eliminate them. This is a bit of a kludge because
7962 the case lists for a single case statement (label) is a
7963 single forward linked lists. */
7964 if (seen_unreachable
)
7966 /* Advance until the first case in the list is reachable. */
7967 while (body
->ext
.block
.case_list
!= NULL
7968 && body
->ext
.block
.case_list
->unreachable
)
7970 gfc_case
*n
= body
->ext
.block
.case_list
;
7971 body
->ext
.block
.case_list
= body
->ext
.block
.case_list
->next
;
7973 gfc_free_case_list (n
);
7976 /* Strip all other unreachable cases. */
7977 if (body
->ext
.block
.case_list
)
7979 for (cp
= body
->ext
.block
.case_list
; cp
&& cp
->next
; cp
= cp
->next
)
7981 if (cp
->next
->unreachable
)
7983 gfc_case
*n
= cp
->next
;
7984 cp
->next
= cp
->next
->next
;
7986 gfc_free_case_list (n
);
7993 /* See if there were overlapping cases. If the check returns NULL,
7994 there was overlap. In that case we don't do anything. If head
7995 is non-NULL, we prepend the DEFAULT case. The sorted list can
7996 then used during code generation for SELECT CASE constructs with
7997 a case expression of a CHARACTER type. */
8000 head
= check_case_overlap (head
);
8002 /* Prepend the default_case if it is there. */
8003 if (head
!= NULL
&& default_case
)
8005 default_case
->left
= NULL
;
8006 default_case
->right
= head
;
8007 head
->left
= default_case
;
8011 /* Eliminate dead blocks that may be the result if we've seen
8012 unreachable case labels for a block. */
8013 for (body
= code
; body
&& body
->block
; body
= body
->block
)
8015 if (body
->block
->ext
.block
.case_list
== NULL
)
8017 /* Cut the unreachable block from the code chain. */
8018 gfc_code
*c
= body
->block
;
8019 body
->block
= c
->block
;
8021 /* Kill the dead block, but not the blocks below it. */
8023 gfc_free_statements (c
);
8027 /* More than two cases is legal but insane for logical selects.
8028 Issue a warning for it. */
8029 if (warn_surprising
&& type
== BT_LOGICAL
&& ncases
> 2)
8030 gfc_warning (OPT_Wsurprising
,
8031 "Logical SELECT CASE block at %L has more that two cases",
8036 /* Check if a derived type is extensible. */
8039 gfc_type_is_extensible (gfc_symbol
*sym
)
8041 return !(sym
->attr
.is_bind_c
|| sym
->attr
.sequence
8042 || (sym
->attr
.is_class
8043 && sym
->components
->ts
.u
.derived
->attr
.unlimited_polymorphic
));
8048 resolve_types (gfc_namespace
*ns
);
8050 /* Resolve an associate-name: Resolve target and ensure the type-spec is
8051 correct as well as possibly the array-spec. */
8054 resolve_assoc_var (gfc_symbol
* sym
, bool resolve_target
)
8058 gcc_assert (sym
->assoc
);
8059 gcc_assert (sym
->attr
.flavor
== FL_VARIABLE
);
8061 /* If this is for SELECT TYPE, the target may not yet be set. In that
8062 case, return. Resolution will be called later manually again when
8064 target
= sym
->assoc
->target
;
8067 gcc_assert (!sym
->assoc
->dangling
);
8069 if (resolve_target
&& !gfc_resolve_expr (target
))
8072 /* For variable targets, we get some attributes from the target. */
8073 if (target
->expr_type
== EXPR_VARIABLE
)
8077 gcc_assert (target
->symtree
);
8078 tsym
= target
->symtree
->n
.sym
;
8080 sym
->attr
.asynchronous
= tsym
->attr
.asynchronous
;
8081 sym
->attr
.volatile_
= tsym
->attr
.volatile_
;
8083 sym
->attr
.target
= tsym
->attr
.target
8084 || gfc_expr_attr (target
).pointer
;
8085 if (is_subref_array (target
))
8086 sym
->attr
.subref_array_pointer
= 1;
8089 /* Get type if this was not already set. Note that it can be
8090 some other type than the target in case this is a SELECT TYPE
8091 selector! So we must not update when the type is already there. */
8092 if (sym
->ts
.type
== BT_UNKNOWN
)
8093 sym
->ts
= target
->ts
;
8094 gcc_assert (sym
->ts
.type
!= BT_UNKNOWN
);
8096 /* See if this is a valid association-to-variable. */
8097 sym
->assoc
->variable
= (target
->expr_type
== EXPR_VARIABLE
8098 && !gfc_has_vector_subscript (target
));
8100 /* Finally resolve if this is an array or not. */
8101 if (sym
->attr
.dimension
&& target
->rank
== 0)
8103 /* primary.c makes the assumption that a reference to an associate
8104 name followed by a left parenthesis is an array reference. */
8105 if (sym
->ts
.type
!= BT_CHARACTER
)
8106 gfc_error ("Associate-name %qs at %L is used as array",
8107 sym
->name
, &sym
->declared_at
);
8108 sym
->attr
.dimension
= 0;
8113 /* We cannot deal with class selectors that need temporaries. */
8114 if (target
->ts
.type
== BT_CLASS
8115 && gfc_ref_needs_temporary_p (target
->ref
))
8117 gfc_error ("CLASS selector at %L needs a temporary which is not "
8118 "yet implemented", &target
->where
);
8122 if (target
->ts
.type
== BT_CLASS
)
8123 gfc_fix_class_refs (target
);
8125 if (target
->rank
!= 0)
8128 if (sym
->ts
.type
!= BT_CLASS
&& !sym
->as
)
8130 as
= gfc_get_array_spec ();
8131 as
->rank
= target
->rank
;
8132 as
->type
= AS_DEFERRED
;
8133 as
->corank
= gfc_get_corank (target
);
8134 sym
->attr
.dimension
= 1;
8135 if (as
->corank
!= 0)
8136 sym
->attr
.codimension
= 1;
8142 /* target's rank is 0, but the type of the sym is still array valued,
8143 which has to be corrected. */
8144 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->as
)
8147 symbol_attribute attr
;
8148 /* The associated variable's type is still the array type
8149 correct this now. */
8150 gfc_typespec
*ts
= &target
->ts
;
8153 for (ref
= target
->ref
; ref
!= NULL
; ref
= ref
->next
)
8158 ts
= &ref
->u
.c
.component
->ts
;
8161 if (ts
->type
== BT_CLASS
)
8162 ts
= &ts
->u
.derived
->components
->ts
;
8168 /* Create a scalar instance of the current class type. Because the
8169 rank of a class array goes into its name, the type has to be
8170 rebuild. The alternative of (re-)setting just the attributes
8171 and as in the current type, destroys the type also in other
8175 sym
->ts
.type
= BT_CLASS
;
8176 attr
= CLASS_DATA (sym
)->attr
;
8178 attr
.associate_var
= 1;
8179 attr
.dimension
= attr
.codimension
= 0;
8180 attr
.class_pointer
= 1;
8181 if (!gfc_build_class_symbol (&sym
->ts
, &attr
, &as
))
8183 /* Make sure the _vptr is set. */
8184 c
= gfc_find_component (sym
->ts
.u
.derived
, "_vptr", true, true);
8185 if (c
->ts
.u
.derived
== NULL
)
8186 c
->ts
.u
.derived
= gfc_find_derived_vtab (sym
->ts
.u
.derived
);
8187 CLASS_DATA (sym
)->attr
.pointer
= 1;
8188 CLASS_DATA (sym
)->attr
.class_pointer
= 1;
8189 gfc_set_sym_referenced (sym
->ts
.u
.derived
);
8190 gfc_commit_symbol (sym
->ts
.u
.derived
);
8191 /* _vptr now has the _vtab in it, change it to the _vtype. */
8192 if (c
->ts
.u
.derived
->attr
.vtab
)
8193 c
->ts
.u
.derived
= c
->ts
.u
.derived
->ts
.u
.derived
;
8194 c
->ts
.u
.derived
->ns
->types_resolved
= 0;
8195 resolve_types (c
->ts
.u
.derived
->ns
);
8199 /* Mark this as an associate variable. */
8200 sym
->attr
.associate_var
= 1;
8202 /* If the target is a good class object, so is the associate variable. */
8203 if (sym
->ts
.type
== BT_CLASS
&& gfc_expr_attr (target
).class_ok
)
8204 sym
->attr
.class_ok
= 1;
8208 /* Resolve a SELECT TYPE statement. */
8211 resolve_select_type (gfc_code
*code
, gfc_namespace
*old_ns
)
8213 gfc_symbol
*selector_type
;
8214 gfc_code
*body
, *new_st
, *if_st
, *tail
;
8215 gfc_code
*class_is
= NULL
, *default_case
= NULL
;
8218 char name
[GFC_MAX_SYMBOL_LEN
];
8223 ns
= code
->ext
.block
.ns
;
8226 /* Check for F03:C813. */
8227 if (code
->expr1
->ts
.type
!= BT_CLASS
8228 && !(code
->expr2
&& code
->expr2
->ts
.type
== BT_CLASS
))
8230 gfc_error ("Selector shall be polymorphic in SELECT TYPE statement "
8231 "at %L", &code
->loc
);
8235 if (!code
->expr1
->symtree
->n
.sym
->attr
.class_ok
)
8240 if (code
->expr1
->symtree
->n
.sym
->attr
.untyped
)
8241 code
->expr1
->symtree
->n
.sym
->ts
= code
->expr2
->ts
;
8242 selector_type
= CLASS_DATA (code
->expr2
)->ts
.u
.derived
;
8244 /* F2008: C803 The selector expression must not be coindexed. */
8245 if (gfc_is_coindexed (code
->expr2
))
8247 gfc_error ("Selector at %L must not be coindexed",
8248 &code
->expr2
->where
);
8255 selector_type
= CLASS_DATA (code
->expr1
)->ts
.u
.derived
;
8257 if (gfc_is_coindexed (code
->expr1
))
8259 gfc_error ("Selector at %L must not be coindexed",
8260 &code
->expr1
->where
);
8265 /* Loop over TYPE IS / CLASS IS cases. */
8266 for (body
= code
->block
; body
; body
= body
->block
)
8268 c
= body
->ext
.block
.case_list
;
8270 /* Check F03:C815. */
8271 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
8272 && !selector_type
->attr
.unlimited_polymorphic
8273 && !gfc_type_is_extensible (c
->ts
.u
.derived
))
8275 gfc_error ("Derived type %qs at %L must be extensible",
8276 c
->ts
.u
.derived
->name
, &c
->where
);
8281 /* Check F03:C816. */
8282 if (c
->ts
.type
!= BT_UNKNOWN
&& !selector_type
->attr
.unlimited_polymorphic
8283 && ((c
->ts
.type
!= BT_DERIVED
&& c
->ts
.type
!= BT_CLASS
)
8284 || !gfc_type_is_extension_of (selector_type
, c
->ts
.u
.derived
)))
8286 if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
8287 gfc_error ("Derived type %qs at %L must be an extension of %qs",
8288 c
->ts
.u
.derived
->name
, &c
->where
, selector_type
->name
);
8290 gfc_error ("Unexpected intrinsic type %qs at %L",
8291 gfc_basic_typename (c
->ts
.type
), &c
->where
);
8296 /* Check F03:C814. */
8297 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.u
.cl
->length
!= NULL
)
8299 gfc_error ("The type-spec at %L shall specify that each length "
8300 "type parameter is assumed", &c
->where
);
8305 /* Intercept the DEFAULT case. */
8306 if (c
->ts
.type
== BT_UNKNOWN
)
8308 /* Check F03:C818. */
8311 gfc_error ("The DEFAULT CASE at %L cannot be followed "
8312 "by a second DEFAULT CASE at %L",
8313 &default_case
->ext
.block
.case_list
->where
, &c
->where
);
8318 default_case
= body
;
8325 /* Transform SELECT TYPE statement to BLOCK and associate selector to
8326 target if present. If there are any EXIT statements referring to the
8327 SELECT TYPE construct, this is no problem because the gfc_code
8328 reference stays the same and EXIT is equally possible from the BLOCK
8329 it is changed to. */
8330 code
->op
= EXEC_BLOCK
;
8333 gfc_association_list
* assoc
;
8335 assoc
= gfc_get_association_list ();
8336 assoc
->st
= code
->expr1
->symtree
;
8337 assoc
->target
= gfc_copy_expr (code
->expr2
);
8338 assoc
->target
->where
= code
->expr2
->where
;
8339 /* assoc->variable will be set by resolve_assoc_var. */
8341 code
->ext
.block
.assoc
= assoc
;
8342 code
->expr1
->symtree
->n
.sym
->assoc
= assoc
;
8344 resolve_assoc_var (code
->expr1
->symtree
->n
.sym
, false);
8347 code
->ext
.block
.assoc
= NULL
;
8349 /* Add EXEC_SELECT to switch on type. */
8350 new_st
= gfc_get_code (code
->op
);
8351 new_st
->expr1
= code
->expr1
;
8352 new_st
->expr2
= code
->expr2
;
8353 new_st
->block
= code
->block
;
8354 code
->expr1
= code
->expr2
= NULL
;
8359 ns
->code
->next
= new_st
;
8361 code
->op
= EXEC_SELECT
;
8363 gfc_add_vptr_component (code
->expr1
);
8364 gfc_add_hash_component (code
->expr1
);
8366 /* Loop over TYPE IS / CLASS IS cases. */
8367 for (body
= code
->block
; body
; body
= body
->block
)
8369 c
= body
->ext
.block
.case_list
;
8371 if (c
->ts
.type
== BT_DERIVED
)
8372 c
->low
= c
->high
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
8373 c
->ts
.u
.derived
->hash_value
);
8374 else if (c
->ts
.type
!= BT_CLASS
&& c
->ts
.type
!= BT_UNKNOWN
)
8379 ivtab
= gfc_find_vtab (&c
->ts
);
8380 gcc_assert (ivtab
&& CLASS_DATA (ivtab
)->initializer
);
8381 e
= CLASS_DATA (ivtab
)->initializer
;
8382 c
->low
= c
->high
= gfc_copy_expr (e
);
8385 else if (c
->ts
.type
== BT_UNKNOWN
)
8388 /* Associate temporary to selector. This should only be done
8389 when this case is actually true, so build a new ASSOCIATE
8390 that does precisely this here (instead of using the
8393 if (c
->ts
.type
== BT_CLASS
)
8394 sprintf (name
, "__tmp_class_%s", c
->ts
.u
.derived
->name
);
8395 else if (c
->ts
.type
== BT_DERIVED
)
8396 sprintf (name
, "__tmp_type_%s", c
->ts
.u
.derived
->name
);
8397 else if (c
->ts
.type
== BT_CHARACTER
)
8399 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
8400 && c
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
8401 charlen
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
8402 sprintf (name
, "__tmp_%s_%d_%d", gfc_basic_typename (c
->ts
.type
),
8403 charlen
, c
->ts
.kind
);
8406 sprintf (name
, "__tmp_%s_%d", gfc_basic_typename (c
->ts
.type
),
8409 st
= gfc_find_symtree (ns
->sym_root
, name
);
8410 gcc_assert (st
->n
.sym
->assoc
);
8411 st
->n
.sym
->assoc
->target
= gfc_get_variable_expr (code
->expr1
->symtree
);
8412 st
->n
.sym
->assoc
->target
->where
= code
->expr1
->where
;
8413 if (c
->ts
.type
!= BT_CLASS
&& c
->ts
.type
!= BT_UNKNOWN
)
8414 gfc_add_data_component (st
->n
.sym
->assoc
->target
);
8416 new_st
= gfc_get_code (EXEC_BLOCK
);
8417 new_st
->ext
.block
.ns
= gfc_build_block_ns (ns
);
8418 new_st
->ext
.block
.ns
->code
= body
->next
;
8419 body
->next
= new_st
;
8421 /* Chain in the new list only if it is marked as dangling. Otherwise
8422 there is a CASE label overlap and this is already used. Just ignore,
8423 the error is diagnosed elsewhere. */
8424 if (st
->n
.sym
->assoc
->dangling
)
8426 new_st
->ext
.block
.assoc
= st
->n
.sym
->assoc
;
8427 st
->n
.sym
->assoc
->dangling
= 0;
8430 resolve_assoc_var (st
->n
.sym
, false);
8433 /* Take out CLASS IS cases for separate treatment. */
8435 while (body
&& body
->block
)
8437 if (body
->block
->ext
.block
.case_list
->ts
.type
== BT_CLASS
)
8439 /* Add to class_is list. */
8440 if (class_is
== NULL
)
8442 class_is
= body
->block
;
8447 for (tail
= class_is
; tail
->block
; tail
= tail
->block
) ;
8448 tail
->block
= body
->block
;
8451 /* Remove from EXEC_SELECT list. */
8452 body
->block
= body
->block
->block
;
8465 /* Add a default case to hold the CLASS IS cases. */
8466 for (tail
= code
; tail
->block
; tail
= tail
->block
) ;
8467 tail
->block
= gfc_get_code (EXEC_SELECT_TYPE
);
8469 tail
->ext
.block
.case_list
= gfc_get_case ();
8470 tail
->ext
.block
.case_list
->ts
.type
= BT_UNKNOWN
;
8472 default_case
= tail
;
8475 /* More than one CLASS IS block? */
8476 if (class_is
->block
)
8480 /* Sort CLASS IS blocks by extension level. */
8484 for (c1
= &class_is
; (*c1
) && (*c1
)->block
; c1
= &((*c1
)->block
))
8487 /* F03:C817 (check for doubles). */
8488 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->hash_value
8489 == c2
->ext
.block
.case_list
->ts
.u
.derived
->hash_value
)
8491 gfc_error ("Double CLASS IS block in SELECT TYPE "
8493 &c2
->ext
.block
.case_list
->where
);
8496 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
8497 < c2
->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
)
8500 (*c1
)->block
= c2
->block
;
8510 /* Generate IF chain. */
8511 if_st
= gfc_get_code (EXEC_IF
);
8513 for (body
= class_is
; body
; body
= body
->block
)
8515 new_st
->block
= gfc_get_code (EXEC_IF
);
8516 new_st
= new_st
->block
;
8517 /* Set up IF condition: Call _gfortran_is_extension_of. */
8518 new_st
->expr1
= gfc_get_expr ();
8519 new_st
->expr1
->expr_type
= EXPR_FUNCTION
;
8520 new_st
->expr1
->ts
.type
= BT_LOGICAL
;
8521 new_st
->expr1
->ts
.kind
= 4;
8522 new_st
->expr1
->value
.function
.name
= gfc_get_string (PREFIX ("is_extension_of"));
8523 new_st
->expr1
->value
.function
.isym
= XCNEW (gfc_intrinsic_sym
);
8524 new_st
->expr1
->value
.function
.isym
->id
= GFC_ISYM_EXTENDS_TYPE_OF
;
8525 /* Set up arguments. */
8526 new_st
->expr1
->value
.function
.actual
= gfc_get_actual_arglist ();
8527 new_st
->expr1
->value
.function
.actual
->expr
= gfc_get_variable_expr (code
->expr1
->symtree
);
8528 new_st
->expr1
->value
.function
.actual
->expr
->where
= code
->loc
;
8529 gfc_add_vptr_component (new_st
->expr1
->value
.function
.actual
->expr
);
8530 vtab
= gfc_find_derived_vtab (body
->ext
.block
.case_list
->ts
.u
.derived
);
8531 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
8532 new_st
->expr1
->value
.function
.actual
->next
= gfc_get_actual_arglist ();
8533 new_st
->expr1
->value
.function
.actual
->next
->expr
= gfc_get_variable_expr (st
);
8534 new_st
->next
= body
->next
;
8536 if (default_case
->next
)
8538 new_st
->block
= gfc_get_code (EXEC_IF
);
8539 new_st
= new_st
->block
;
8540 new_st
->next
= default_case
->next
;
8543 /* Replace CLASS DEFAULT code by the IF chain. */
8544 default_case
->next
= if_st
;
8547 /* Resolve the internal code. This can not be done earlier because
8548 it requires that the sym->assoc of selectors is set already. */
8549 gfc_current_ns
= ns
;
8550 gfc_resolve_blocks (code
->block
, gfc_current_ns
);
8551 gfc_current_ns
= old_ns
;
8553 resolve_select (code
, true);
8557 /* Resolve a transfer statement. This is making sure that:
8558 -- a derived type being transferred has only non-pointer components
8559 -- a derived type being transferred doesn't have private components, unless
8560 it's being transferred from the module where the type was defined
8561 -- we're not trying to transfer a whole assumed size array. */
8564 resolve_transfer (gfc_code
*code
)
8573 while (exp
!= NULL
&& exp
->expr_type
== EXPR_OP
8574 && exp
->value
.op
.op
== INTRINSIC_PARENTHESES
)
8575 exp
= exp
->value
.op
.op1
;
8577 if (exp
&& exp
->expr_type
== EXPR_NULL
8580 gfc_error ("Invalid context for NULL () intrinsic at %L",
8585 if (exp
== NULL
|| (exp
->expr_type
!= EXPR_VARIABLE
8586 && exp
->expr_type
!= EXPR_FUNCTION
8587 && exp
->expr_type
!= EXPR_STRUCTURE
))
8590 /* If we are reading, the variable will be changed. Note that
8591 code->ext.dt may be NULL if the TRANSFER is related to
8592 an INQUIRE statement -- but in this case, we are not reading, either. */
8593 if (code
->ext
.dt
&& code
->ext
.dt
->dt_io_kind
->value
.iokind
== M_READ
8594 && !gfc_check_vardef_context (exp
, false, false, false,
8598 ts
= exp
->expr_type
== EXPR_STRUCTURE
? &exp
->ts
: &exp
->symtree
->n
.sym
->ts
;
8600 /* Go to actual component transferred. */
8601 for (ref
= exp
->ref
; ref
; ref
= ref
->next
)
8602 if (ref
->type
== REF_COMPONENT
)
8603 ts
= &ref
->u
.c
.component
->ts
;
8605 if (ts
->type
== BT_CLASS
)
8607 /* FIXME: Test for defined input/output. */
8608 gfc_error ("Data transfer element at %L cannot be polymorphic unless "
8609 "it is processed by a defined input/output procedure",
8614 if (ts
->type
== BT_DERIVED
)
8616 /* Check that transferred derived type doesn't contain POINTER
8618 if (ts
->u
.derived
->attr
.pointer_comp
)
8620 gfc_error ("Data transfer element at %L cannot have POINTER "
8621 "components unless it is processed by a defined "
8622 "input/output procedure", &code
->loc
);
8627 if (ts
->u
.derived
->attr
.proc_pointer_comp
)
8629 gfc_error ("Data transfer element at %L cannot have "
8630 "procedure pointer components", &code
->loc
);
8634 if (ts
->u
.derived
->attr
.alloc_comp
)
8636 gfc_error ("Data transfer element at %L cannot have ALLOCATABLE "
8637 "components unless it is processed by a defined "
8638 "input/output procedure", &code
->loc
);
8642 /* C_PTR and C_FUNPTR have private components which means they can not
8643 be printed. However, if -std=gnu and not -pedantic, allow
8644 the component to be printed to help debugging. */
8645 if (ts
->u
.derived
->ts
.f90_type
== BT_VOID
)
8647 if (!gfc_notify_std (GFC_STD_GNU
, "Data transfer element at %L "
8648 "cannot have PRIVATE components", &code
->loc
))
8651 else if (derived_inaccessible (ts
->u
.derived
))
8653 gfc_error ("Data transfer element at %L cannot have "
8654 "PRIVATE components",&code
->loc
);
8659 if (exp
->expr_type
== EXPR_STRUCTURE
)
8662 sym
= exp
->symtree
->n
.sym
;
8664 if (sym
->as
!= NULL
&& sym
->as
->type
== AS_ASSUMED_SIZE
&& exp
->ref
8665 && exp
->ref
->type
== REF_ARRAY
&& exp
->ref
->u
.ar
.type
== AR_FULL
)
8667 gfc_error ("Data transfer element at %L cannot be a full reference to "
8668 "an assumed-size array", &code
->loc
);
8674 /*********** Toplevel code resolution subroutines ***********/
8676 /* Find the set of labels that are reachable from this block. We also
8677 record the last statement in each block. */
8680 find_reachable_labels (gfc_code
*block
)
8687 cs_base
->reachable_labels
= bitmap_obstack_alloc (&labels_obstack
);
8689 /* Collect labels in this block. We don't keep those corresponding
8690 to END {IF|SELECT}, these are checked in resolve_branch by going
8691 up through the code_stack. */
8692 for (c
= block
; c
; c
= c
->next
)
8694 if (c
->here
&& c
->op
!= EXEC_END_NESTED_BLOCK
)
8695 bitmap_set_bit (cs_base
->reachable_labels
, c
->here
->value
);
8698 /* Merge with labels from parent block. */
8701 gcc_assert (cs_base
->prev
->reachable_labels
);
8702 bitmap_ior_into (cs_base
->reachable_labels
,
8703 cs_base
->prev
->reachable_labels
);
8709 resolve_lock_unlock (gfc_code
*code
)
8711 if (code
->expr1
->expr_type
== EXPR_FUNCTION
8712 && code
->expr1
->value
.function
.isym
8713 && code
->expr1
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
8714 remove_caf_get_intrinsic (code
->expr1
);
8716 if (code
->expr1
->ts
.type
!= BT_DERIVED
8717 || code
->expr1
->expr_type
!= EXPR_VARIABLE
8718 || code
->expr1
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
8719 || code
->expr1
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_LOCK_TYPE
8720 || code
->expr1
->rank
!= 0
8721 || (!gfc_is_coarray (code
->expr1
) && !gfc_is_coindexed (code
->expr1
)))
8722 gfc_error ("Lock variable at %L must be a scalar of type LOCK_TYPE",
8723 &code
->expr1
->where
);
8727 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
8728 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
8729 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
8730 &code
->expr2
->where
);
8733 && !gfc_check_vardef_context (code
->expr2
, false, false, false,
8734 _("STAT variable")))
8739 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
8740 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
8741 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
8742 &code
->expr3
->where
);
8745 && !gfc_check_vardef_context (code
->expr3
, false, false, false,
8746 _("ERRMSG variable")))
8749 /* Check ACQUIRED_LOCK. */
8751 && (code
->expr4
->ts
.type
!= BT_LOGICAL
|| code
->expr4
->rank
!= 0
8752 || code
->expr4
->expr_type
!= EXPR_VARIABLE
))
8753 gfc_error ("ACQUIRED_LOCK= argument at %L must be a scalar LOGICAL "
8754 "variable", &code
->expr4
->where
);
8757 && !gfc_check_vardef_context (code
->expr4
, false, false, false,
8758 _("ACQUIRED_LOCK variable")))
8764 resolve_critical (gfc_code
*code
)
8766 gfc_symtree
*symtree
;
8767 gfc_symbol
*lock_type
;
8768 char name
[GFC_MAX_SYMBOL_LEN
];
8769 static int serial
= 0;
8771 if (flag_coarray
!= GFC_FCOARRAY_LIB
)
8774 symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
8775 GFC_PREFIX ("lock_type"));
8777 lock_type
= symtree
->n
.sym
;
8780 if (gfc_get_sym_tree (GFC_PREFIX ("lock_type"), gfc_current_ns
, &symtree
,
8783 lock_type
= symtree
->n
.sym
;
8784 lock_type
->attr
.flavor
= FL_DERIVED
;
8785 lock_type
->attr
.zero_comp
= 1;
8786 lock_type
->from_intmod
= INTMOD_ISO_FORTRAN_ENV
;
8787 lock_type
->intmod_sym_id
= ISOFORTRAN_LOCK_TYPE
;
8790 sprintf(name
, GFC_PREFIX ("lock_var") "%d",serial
++);
8791 if (gfc_get_sym_tree (name
, gfc_current_ns
, &symtree
, false) != 0)
8794 code
->resolved_sym
= symtree
->n
.sym
;
8795 symtree
->n
.sym
->attr
.flavor
= FL_VARIABLE
;
8796 symtree
->n
.sym
->attr
.referenced
= 1;
8797 symtree
->n
.sym
->attr
.artificial
= 1;
8798 symtree
->n
.sym
->attr
.codimension
= 1;
8799 symtree
->n
.sym
->ts
.type
= BT_DERIVED
;
8800 symtree
->n
.sym
->ts
.u
.derived
= lock_type
;
8801 symtree
->n
.sym
->as
= gfc_get_array_spec ();
8802 symtree
->n
.sym
->as
->corank
= 1;
8803 symtree
->n
.sym
->as
->type
= AS_EXPLICIT
;
8804 symtree
->n
.sym
->as
->cotype
= AS_EXPLICIT
;
8805 symtree
->n
.sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
,
8811 resolve_sync (gfc_code
*code
)
8813 /* Check imageset. The * case matches expr1 == NULL. */
8816 if (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
> 1)
8817 gfc_error ("Imageset argument at %L must be a scalar or rank-1 "
8818 "INTEGER expression", &code
->expr1
->where
);
8819 if (code
->expr1
->expr_type
== EXPR_CONSTANT
&& code
->expr1
->rank
== 0
8820 && mpz_cmp_si (code
->expr1
->value
.integer
, 1) < 0)
8821 gfc_error ("Imageset argument at %L must between 1 and num_images()",
8822 &code
->expr1
->where
);
8823 else if (code
->expr1
->expr_type
== EXPR_ARRAY
8824 && gfc_simplify_expr (code
->expr1
, 0))
8826 gfc_constructor
*cons
;
8827 cons
= gfc_constructor_first (code
->expr1
->value
.constructor
);
8828 for (; cons
; cons
= gfc_constructor_next (cons
))
8829 if (cons
->expr
->expr_type
== EXPR_CONSTANT
8830 && mpz_cmp_si (cons
->expr
->value
.integer
, 1) < 0)
8831 gfc_error ("Imageset argument at %L must between 1 and "
8832 "num_images()", &cons
->expr
->where
);
8838 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
8839 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
8840 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
8841 &code
->expr2
->where
);
8845 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
8846 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
8847 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
8848 &code
->expr3
->where
);
8852 /* Given a branch to a label, see if the branch is conforming.
8853 The code node describes where the branch is located. */
8856 resolve_branch (gfc_st_label
*label
, gfc_code
*code
)
8863 /* Step one: is this a valid branching target? */
8865 if (label
->defined
== ST_LABEL_UNKNOWN
)
8867 gfc_error ("Label %d referenced at %L is never defined", label
->value
,
8872 if (label
->defined
!= ST_LABEL_TARGET
&& label
->defined
!= ST_LABEL_DO_TARGET
)
8874 gfc_error ("Statement at %L is not a valid branch target statement "
8875 "for the branch statement at %L", &label
->where
, &code
->loc
);
8879 /* Step two: make sure this branch is not a branch to itself ;-) */
8881 if (code
->here
== label
)
8884 "Branch at %L may result in an infinite loop", &code
->loc
);
8888 /* Step three: See if the label is in the same block as the
8889 branching statement. The hard work has been done by setting up
8890 the bitmap reachable_labels. */
8892 if (bitmap_bit_p (cs_base
->reachable_labels
, label
->value
))
8894 /* Check now whether there is a CRITICAL construct; if so, check
8895 whether the label is still visible outside of the CRITICAL block,
8896 which is invalid. */
8897 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
8899 if (stack
->current
->op
== EXEC_CRITICAL
8900 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
8901 gfc_error ("GOTO statement at %L leaves CRITICAL construct for "
8902 "label at %L", &code
->loc
, &label
->where
);
8903 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
8904 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
8905 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct "
8906 "for label at %L", &code
->loc
, &label
->where
);
8912 /* Step four: If we haven't found the label in the bitmap, it may
8913 still be the label of the END of the enclosing block, in which
8914 case we find it by going up the code_stack. */
8916 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
8918 if (stack
->current
->next
&& stack
->current
->next
->here
== label
)
8920 if (stack
->current
->op
== EXEC_CRITICAL
)
8922 /* Note: A label at END CRITICAL does not leave the CRITICAL
8923 construct as END CRITICAL is still part of it. */
8924 gfc_error ("GOTO statement at %L leaves CRITICAL construct for label"
8925 " at %L", &code
->loc
, &label
->where
);
8928 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
)
8930 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct for "
8931 "label at %L", &code
->loc
, &label
->where
);
8938 gcc_assert (stack
->current
->next
->op
== EXEC_END_NESTED_BLOCK
);
8942 /* The label is not in an enclosing block, so illegal. This was
8943 allowed in Fortran 66, so we allow it as extension. No
8944 further checks are necessary in this case. */
8945 gfc_notify_std (GFC_STD_LEGACY
, "Label at %L is not in the same block "
8946 "as the GOTO statement at %L", &label
->where
,
8952 /* Check whether EXPR1 has the same shape as EXPR2. */
8955 resolve_where_shape (gfc_expr
*expr1
, gfc_expr
*expr2
)
8957 mpz_t shape
[GFC_MAX_DIMENSIONS
];
8958 mpz_t shape2
[GFC_MAX_DIMENSIONS
];
8959 bool result
= false;
8962 /* Compare the rank. */
8963 if (expr1
->rank
!= expr2
->rank
)
8966 /* Compare the size of each dimension. */
8967 for (i
=0; i
<expr1
->rank
; i
++)
8969 if (!gfc_array_dimen_size (expr1
, i
, &shape
[i
]))
8972 if (!gfc_array_dimen_size (expr2
, i
, &shape2
[i
]))
8975 if (mpz_cmp (shape
[i
], shape2
[i
]))
8979 /* When either of the two expression is an assumed size array, we
8980 ignore the comparison of dimension sizes. */
8985 gfc_clear_shape (shape
, i
);
8986 gfc_clear_shape (shape2
, i
);
8991 /* Check whether a WHERE assignment target or a WHERE mask expression
8992 has the same shape as the outmost WHERE mask expression. */
8995 resolve_where (gfc_code
*code
, gfc_expr
*mask
)
9001 cblock
= code
->block
;
9003 /* Store the first WHERE mask-expr of the WHERE statement or construct.
9004 In case of nested WHERE, only the outmost one is stored. */
9005 if (mask
== NULL
) /* outmost WHERE */
9007 else /* inner WHERE */
9014 /* Check if the mask-expr has a consistent shape with the
9015 outmost WHERE mask-expr. */
9016 if (!resolve_where_shape (cblock
->expr1
, e
))
9017 gfc_error ("WHERE mask at %L has inconsistent shape",
9018 &cblock
->expr1
->where
);
9021 /* the assignment statement of a WHERE statement, or the first
9022 statement in where-body-construct of a WHERE construct */
9023 cnext
= cblock
->next
;
9028 /* WHERE assignment statement */
9031 /* Check shape consistent for WHERE assignment target. */
9032 if (e
&& !resolve_where_shape (cnext
->expr1
, e
))
9033 gfc_error ("WHERE assignment target at %L has "
9034 "inconsistent shape", &cnext
->expr1
->where
);
9038 case EXEC_ASSIGN_CALL
:
9039 resolve_call (cnext
);
9040 if (!cnext
->resolved_sym
->attr
.elemental
)
9041 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
9042 &cnext
->ext
.actual
->expr
->where
);
9045 /* WHERE or WHERE construct is part of a where-body-construct */
9047 resolve_where (cnext
, e
);
9051 gfc_error ("Unsupported statement inside WHERE at %L",
9054 /* the next statement within the same where-body-construct */
9055 cnext
= cnext
->next
;
9057 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
9058 cblock
= cblock
->block
;
9063 /* Resolve assignment in FORALL construct.
9064 NVAR is the number of FORALL index variables, and VAR_EXPR records the
9065 FORALL index variables. */
9068 gfc_resolve_assign_in_forall (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
9072 for (n
= 0; n
< nvar
; n
++)
9074 gfc_symbol
*forall_index
;
9076 forall_index
= var_expr
[n
]->symtree
->n
.sym
;
9078 /* Check whether the assignment target is one of the FORALL index
9080 if ((code
->expr1
->expr_type
== EXPR_VARIABLE
)
9081 && (code
->expr1
->symtree
->n
.sym
== forall_index
))
9082 gfc_error ("Assignment to a FORALL index variable at %L",
9083 &code
->expr1
->where
);
9086 /* If one of the FORALL index variables doesn't appear in the
9087 assignment variable, then there could be a many-to-one
9088 assignment. Emit a warning rather than an error because the
9089 mask could be resolving this problem. */
9090 if (!find_forall_index (code
->expr1
, forall_index
, 0))
9091 gfc_warning (0, "The FORALL with index %qs is not used on the "
9092 "left side of the assignment at %L and so might "
9093 "cause multiple assignment to this object",
9094 var_expr
[n
]->symtree
->name
, &code
->expr1
->where
);
9100 /* Resolve WHERE statement in FORALL construct. */
9103 gfc_resolve_where_code_in_forall (gfc_code
*code
, int nvar
,
9104 gfc_expr
**var_expr
)
9109 cblock
= code
->block
;
9112 /* the assignment statement of a WHERE statement, or the first
9113 statement in where-body-construct of a WHERE construct */
9114 cnext
= cblock
->next
;
9119 /* WHERE assignment statement */
9121 gfc_resolve_assign_in_forall (cnext
, nvar
, var_expr
);
9124 /* WHERE operator assignment statement */
9125 case EXEC_ASSIGN_CALL
:
9126 resolve_call (cnext
);
9127 if (!cnext
->resolved_sym
->attr
.elemental
)
9128 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
9129 &cnext
->ext
.actual
->expr
->where
);
9132 /* WHERE or WHERE construct is part of a where-body-construct */
9134 gfc_resolve_where_code_in_forall (cnext
, nvar
, var_expr
);
9138 gfc_error ("Unsupported statement inside WHERE at %L",
9141 /* the next statement within the same where-body-construct */
9142 cnext
= cnext
->next
;
9144 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
9145 cblock
= cblock
->block
;
9150 /* Traverse the FORALL body to check whether the following errors exist:
9151 1. For assignment, check if a many-to-one assignment happens.
9152 2. For WHERE statement, check the WHERE body to see if there is any
9153 many-to-one assignment. */
9156 gfc_resolve_forall_body (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
9160 c
= code
->block
->next
;
9166 case EXEC_POINTER_ASSIGN
:
9167 gfc_resolve_assign_in_forall (c
, nvar
, var_expr
);
9170 case EXEC_ASSIGN_CALL
:
9174 /* Because the gfc_resolve_blocks() will handle the nested FORALL,
9175 there is no need to handle it here. */
9179 gfc_resolve_where_code_in_forall(c
, nvar
, var_expr
);
9184 /* The next statement in the FORALL body. */
9190 /* Counts the number of iterators needed inside a forall construct, including
9191 nested forall constructs. This is used to allocate the needed memory
9192 in gfc_resolve_forall. */
9195 gfc_count_forall_iterators (gfc_code
*code
)
9197 int max_iters
, sub_iters
, current_iters
;
9198 gfc_forall_iterator
*fa
;
9200 gcc_assert(code
->op
== EXEC_FORALL
);
9204 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
9207 code
= code
->block
->next
;
9211 if (code
->op
== EXEC_FORALL
)
9213 sub_iters
= gfc_count_forall_iterators (code
);
9214 if (sub_iters
> max_iters
)
9215 max_iters
= sub_iters
;
9220 return current_iters
+ max_iters
;
9224 /* Given a FORALL construct, first resolve the FORALL iterator, then call
9225 gfc_resolve_forall_body to resolve the FORALL body. */
9228 gfc_resolve_forall (gfc_code
*code
, gfc_namespace
*ns
, int forall_save
)
9230 static gfc_expr
**var_expr
;
9231 static int total_var
= 0;
9232 static int nvar
= 0;
9234 gfc_forall_iterator
*fa
;
9239 /* Start to resolve a FORALL construct */
9240 if (forall_save
== 0)
9242 /* Count the total number of FORALL index in the nested FORALL
9243 construct in order to allocate the VAR_EXPR with proper size. */
9244 total_var
= gfc_count_forall_iterators (code
);
9246 /* Allocate VAR_EXPR with NUMBER_OF_FORALL_INDEX elements. */
9247 var_expr
= XCNEWVEC (gfc_expr
*, total_var
);
9250 /* The information about FORALL iterator, including FORALL index start, end
9251 and stride. The FORALL index can not appear in start, end or stride. */
9252 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
9254 /* Check if any outer FORALL index name is the same as the current
9256 for (i
= 0; i
< nvar
; i
++)
9258 if (fa
->var
->symtree
->n
.sym
== var_expr
[i
]->symtree
->n
.sym
)
9260 gfc_error ("An outer FORALL construct already has an index "
9261 "with this name %L", &fa
->var
->where
);
9265 /* Record the current FORALL index. */
9266 var_expr
[nvar
] = gfc_copy_expr (fa
->var
);
9270 /* No memory leak. */
9271 gcc_assert (nvar
<= total_var
);
9274 /* Resolve the FORALL body. */
9275 gfc_resolve_forall_body (code
, nvar
, var_expr
);
9277 /* May call gfc_resolve_forall to resolve the inner FORALL loop. */
9278 gfc_resolve_blocks (code
->block
, ns
);
9282 /* Free only the VAR_EXPRs allocated in this frame. */
9283 for (i
= nvar
; i
< tmp
; i
++)
9284 gfc_free_expr (var_expr
[i
]);
9288 /* We are in the outermost FORALL construct. */
9289 gcc_assert (forall_save
== 0);
9291 /* VAR_EXPR is not needed any more. */
9298 /* Resolve a BLOCK construct statement. */
9301 resolve_block_construct (gfc_code
* code
)
9303 /* Resolve the BLOCK's namespace. */
9304 gfc_resolve (code
->ext
.block
.ns
);
9306 /* For an ASSOCIATE block, the associations (and their targets) are already
9307 resolved during resolve_symbol. */
9311 /* Resolve lists of blocks found in IF, SELECT CASE, WHERE, FORALL, GOTO and
9315 gfc_resolve_blocks (gfc_code
*b
, gfc_namespace
*ns
)
9319 for (; b
; b
= b
->block
)
9321 t
= gfc_resolve_expr (b
->expr1
);
9322 if (!gfc_resolve_expr (b
->expr2
))
9328 if (t
&& b
->expr1
!= NULL
9329 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
!= 0))
9330 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
9337 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
== 0))
9338 gfc_error ("WHERE/ELSEWHERE clause at %L requires a LOGICAL array",
9343 resolve_branch (b
->label1
, b
);
9347 resolve_block_construct (b
);
9351 case EXEC_SELECT_TYPE
:
9355 case EXEC_DO_CONCURRENT
:
9363 case EXEC_OACC_PARALLEL_LOOP
:
9364 case EXEC_OACC_PARALLEL
:
9365 case EXEC_OACC_KERNELS_LOOP
:
9366 case EXEC_OACC_KERNELS
:
9367 case EXEC_OACC_DATA
:
9368 case EXEC_OACC_HOST_DATA
:
9369 case EXEC_OACC_LOOP
:
9370 case EXEC_OACC_UPDATE
:
9371 case EXEC_OACC_WAIT
:
9372 case EXEC_OACC_CACHE
:
9373 case EXEC_OACC_ENTER_DATA
:
9374 case EXEC_OACC_EXIT_DATA
:
9375 case EXEC_OACC_ATOMIC
:
9376 case EXEC_OMP_ATOMIC
:
9377 case EXEC_OMP_CRITICAL
:
9378 case EXEC_OMP_DISTRIBUTE
:
9379 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
9380 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
9381 case EXEC_OMP_DISTRIBUTE_SIMD
:
9383 case EXEC_OMP_DO_SIMD
:
9384 case EXEC_OMP_MASTER
:
9385 case EXEC_OMP_ORDERED
:
9386 case EXEC_OMP_PARALLEL
:
9387 case EXEC_OMP_PARALLEL_DO
:
9388 case EXEC_OMP_PARALLEL_DO_SIMD
:
9389 case EXEC_OMP_PARALLEL_SECTIONS
:
9390 case EXEC_OMP_PARALLEL_WORKSHARE
:
9391 case EXEC_OMP_SECTIONS
:
9393 case EXEC_OMP_SINGLE
:
9394 case EXEC_OMP_TARGET
:
9395 case EXEC_OMP_TARGET_DATA
:
9396 case EXEC_OMP_TARGET_TEAMS
:
9397 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
9398 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
9399 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
9400 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
9401 case EXEC_OMP_TARGET_UPDATE
:
9403 case EXEC_OMP_TASKGROUP
:
9404 case EXEC_OMP_TASKWAIT
:
9405 case EXEC_OMP_TASKYIELD
:
9406 case EXEC_OMP_TEAMS
:
9407 case EXEC_OMP_TEAMS_DISTRIBUTE
:
9408 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
9409 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
9410 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
9411 case EXEC_OMP_WORKSHARE
:
9415 gfc_internal_error ("gfc_resolve_blocks(): Bad block type");
9418 gfc_resolve_code (b
->next
, ns
);
9423 /* Does everything to resolve an ordinary assignment. Returns true
9424 if this is an interface assignment. */
9426 resolve_ordinary_assign (gfc_code
*code
, gfc_namespace
*ns
)
9435 symbol_attribute attr
;
9437 if (gfc_extend_assign (code
, ns
))
9441 if (code
->op
== EXEC_ASSIGN_CALL
)
9443 lhs
= code
->ext
.actual
->expr
;
9444 rhsptr
= &code
->ext
.actual
->next
->expr
;
9448 gfc_actual_arglist
* args
;
9449 gfc_typebound_proc
* tbp
;
9451 gcc_assert (code
->op
== EXEC_COMPCALL
);
9453 args
= code
->expr1
->value
.compcall
.actual
;
9455 rhsptr
= &args
->next
->expr
;
9457 tbp
= code
->expr1
->value
.compcall
.tbp
;
9458 gcc_assert (!tbp
->is_generic
);
9461 /* Make a temporary rhs when there is a default initializer
9462 and rhs is the same symbol as the lhs. */
9463 if ((*rhsptr
)->expr_type
== EXPR_VARIABLE
9464 && (*rhsptr
)->symtree
->n
.sym
->ts
.type
== BT_DERIVED
9465 && gfc_has_default_initializer ((*rhsptr
)->symtree
->n
.sym
->ts
.u
.derived
)
9466 && (lhs
->symtree
->n
.sym
== (*rhsptr
)->symtree
->n
.sym
))
9467 *rhsptr
= gfc_get_parentheses (*rhsptr
);
9476 && !gfc_notify_std (GFC_STD_GNU
, "BOZ literal at %L outside "
9477 "a DATA statement and outside INT/REAL/DBLE/CMPLX",
9481 /* Handle the case of a BOZ literal on the RHS. */
9482 if (rhs
->is_boz
&& lhs
->ts
.type
!= BT_INTEGER
)
9485 if (warn_surprising
)
9486 gfc_warning (OPT_Wsurprising
,
9487 "BOZ literal at %L is bitwise transferred "
9488 "non-integer symbol %qs", &code
->loc
,
9489 lhs
->symtree
->n
.sym
->name
);
9491 if (!gfc_convert_boz (rhs
, &lhs
->ts
))
9493 if ((rc
= gfc_range_check (rhs
)) != ARITH_OK
)
9495 if (rc
== ARITH_UNDERFLOW
)
9496 gfc_error ("Arithmetic underflow of bit-wise transferred BOZ at %L"
9497 ". This check can be disabled with the option "
9498 "%<-fno-range-check%>", &rhs
->where
);
9499 else if (rc
== ARITH_OVERFLOW
)
9500 gfc_error ("Arithmetic overflow of bit-wise transferred BOZ at %L"
9501 ". This check can be disabled with the option "
9502 "%<-fno-range-check%>", &rhs
->where
);
9503 else if (rc
== ARITH_NAN
)
9504 gfc_error ("Arithmetic NaN of bit-wise transferred BOZ at %L"
9505 ". This check can be disabled with the option "
9506 "%<-fno-range-check%>", &rhs
->where
);
9511 if (lhs
->ts
.type
== BT_CHARACTER
9512 && warn_character_truncation
)
9514 if (lhs
->ts
.u
.cl
!= NULL
9515 && lhs
->ts
.u
.cl
->length
!= NULL
9516 && lhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9517 llen
= mpz_get_si (lhs
->ts
.u
.cl
->length
->value
.integer
);
9519 if (rhs
->expr_type
== EXPR_CONSTANT
)
9520 rlen
= rhs
->value
.character
.length
;
9522 else if (rhs
->ts
.u
.cl
!= NULL
9523 && rhs
->ts
.u
.cl
->length
!= NULL
9524 && rhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9525 rlen
= mpz_get_si (rhs
->ts
.u
.cl
->length
->value
.integer
);
9527 if (rlen
&& llen
&& rlen
> llen
)
9528 gfc_warning_now (OPT_Wcharacter_truncation
,
9529 "CHARACTER expression will be truncated "
9530 "in assignment (%d/%d) at %L",
9531 llen
, rlen
, &code
->loc
);
9534 /* Ensure that a vector index expression for the lvalue is evaluated
9535 to a temporary if the lvalue symbol is referenced in it. */
9538 for (ref
= lhs
->ref
; ref
; ref
= ref
->next
)
9539 if (ref
->type
== REF_ARRAY
)
9541 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
9542 if (ref
->u
.ar
.dimen_type
[n
] == DIMEN_VECTOR
9543 && gfc_find_sym_in_expr (lhs
->symtree
->n
.sym
,
9544 ref
->u
.ar
.start
[n
]))
9546 = gfc_get_parentheses (ref
->u
.ar
.start
[n
]);
9550 if (gfc_pure (NULL
))
9552 if (lhs
->ts
.type
== BT_DERIVED
9553 && lhs
->expr_type
== EXPR_VARIABLE
9554 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9555 && rhs
->expr_type
== EXPR_VARIABLE
9556 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9557 || gfc_is_coindexed (rhs
)))
9560 if (gfc_is_coindexed (rhs
))
9561 gfc_error ("Coindexed expression at %L is assigned to "
9562 "a derived type variable with a POINTER "
9563 "component in a PURE procedure",
9566 gfc_error ("The impure variable at %L is assigned to "
9567 "a derived type variable with a POINTER "
9568 "component in a PURE procedure (12.6)",
9573 /* Fortran 2008, C1283. */
9574 if (gfc_is_coindexed (lhs
))
9576 gfc_error ("Assignment to coindexed variable at %L in a PURE "
9577 "procedure", &rhs
->where
);
9582 if (gfc_implicit_pure (NULL
))
9584 if (lhs
->expr_type
== EXPR_VARIABLE
9585 && lhs
->symtree
->n
.sym
!= gfc_current_ns
->proc_name
9586 && lhs
->symtree
->n
.sym
->ns
!= gfc_current_ns
)
9587 gfc_unset_implicit_pure (NULL
);
9589 if (lhs
->ts
.type
== BT_DERIVED
9590 && lhs
->expr_type
== EXPR_VARIABLE
9591 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9592 && rhs
->expr_type
== EXPR_VARIABLE
9593 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9594 || gfc_is_coindexed (rhs
)))
9595 gfc_unset_implicit_pure (NULL
);
9597 /* Fortran 2008, C1283. */
9598 if (gfc_is_coindexed (lhs
))
9599 gfc_unset_implicit_pure (NULL
);
9602 /* F2008, 7.2.1.2. */
9603 attr
= gfc_expr_attr (lhs
);
9604 if (lhs
->ts
.type
== BT_CLASS
&& attr
.allocatable
)
9606 if (attr
.codimension
)
9608 gfc_error ("Assignment to polymorphic coarray at %L is not "
9609 "permitted", &lhs
->where
);
9612 if (!gfc_notify_std (GFC_STD_F2008
, "Assignment to an allocatable "
9613 "polymorphic variable at %L", &lhs
->where
))
9615 if (!flag_realloc_lhs
)
9617 gfc_error ("Assignment to an allocatable polymorphic variable at %L "
9618 "requires %<-frealloc-lhs%>", &lhs
->where
);
9622 gfc_error ("Assignment to an allocatable polymorphic variable at %L "
9623 "is not yet supported", &lhs
->where
);
9626 else if (lhs
->ts
.type
== BT_CLASS
)
9628 gfc_error ("Nonallocatable variable must not be polymorphic in intrinsic "
9629 "assignment at %L - check that there is a matching specific "
9630 "subroutine for '=' operator", &lhs
->where
);
9634 bool lhs_coindexed
= gfc_is_coindexed (lhs
);
9636 /* F2008, Section 7.2.1.2. */
9637 if (lhs_coindexed
&& gfc_has_ultimate_allocatable (lhs
))
9639 gfc_error ("Coindexed variable must not have an allocatable ultimate "
9640 "component in assignment at %L", &lhs
->where
);
9644 gfc_check_assign (lhs
, rhs
, 1);
9646 /* Assign the 'data' of a class object to a derived type. */
9647 if (lhs
->ts
.type
== BT_DERIVED
9648 && rhs
->ts
.type
== BT_CLASS
)
9649 gfc_add_data_component (rhs
);
9651 /* Insert a GFC_ISYM_CAF_SEND intrinsic, when the LHS is a coindexed variable.
9652 Additionally, insert this code when the RHS is a CAF as we then use the
9653 GFC_ISYM_CAF_SEND intrinsic just to avoid a temporary; but do not do so if
9654 the LHS is (re)allocatable or has a vector subscript. If the LHS is a
9655 noncoindexed array and the RHS is a coindexed scalar, use the normal code
9657 if (flag_coarray
== GFC_FCOARRAY_LIB
9659 || (code
->expr2
->expr_type
== EXPR_FUNCTION
9660 && code
->expr2
->value
.function
.isym
9661 && code
->expr2
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
9662 && (code
->expr1
->rank
== 0 || code
->expr2
->rank
!= 0)
9663 && !gfc_expr_attr (rhs
).allocatable
9664 && !gfc_has_vector_subscript (rhs
))))
9666 if (code
->expr2
->expr_type
== EXPR_FUNCTION
9667 && code
->expr2
->value
.function
.isym
9668 && code
->expr2
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
9669 remove_caf_get_intrinsic (code
->expr2
);
9670 code
->op
= EXEC_CALL
;
9671 gfc_get_sym_tree (GFC_PREFIX ("caf_send"), ns
, &code
->symtree
, true);
9672 code
->resolved_sym
= code
->symtree
->n
.sym
;
9673 code
->resolved_sym
->attr
.flavor
= FL_PROCEDURE
;
9674 code
->resolved_sym
->attr
.intrinsic
= 1;
9675 code
->resolved_sym
->attr
.subroutine
= 1;
9676 code
->resolved_isym
= gfc_intrinsic_subroutine_by_id (GFC_ISYM_CAF_SEND
);
9677 gfc_commit_symbol (code
->resolved_sym
);
9678 code
->ext
.actual
= gfc_get_actual_arglist ();
9679 code
->ext
.actual
->expr
= lhs
;
9680 code
->ext
.actual
->next
= gfc_get_actual_arglist ();
9681 code
->ext
.actual
->next
->expr
= rhs
;
9690 /* Add a component reference onto an expression. */
9693 add_comp_ref (gfc_expr
*e
, gfc_component
*c
)
9698 ref
= &((*ref
)->next
);
9699 *ref
= gfc_get_ref ();
9700 (*ref
)->type
= REF_COMPONENT
;
9701 (*ref
)->u
.c
.sym
= e
->ts
.u
.derived
;
9702 (*ref
)->u
.c
.component
= c
;
9705 /* Add a full array ref, as necessary. */
9708 gfc_add_full_array_ref (e
, c
->as
);
9709 e
->rank
= c
->as
->rank
;
9714 /* Build an assignment. Keep the argument 'op' for future use, so that
9715 pointer assignments can be made. */
9718 build_assignment (gfc_exec_op op
, gfc_expr
*expr1
, gfc_expr
*expr2
,
9719 gfc_component
*comp1
, gfc_component
*comp2
, locus loc
)
9721 gfc_code
*this_code
;
9723 this_code
= gfc_get_code (op
);
9724 this_code
->next
= NULL
;
9725 this_code
->expr1
= gfc_copy_expr (expr1
);
9726 this_code
->expr2
= gfc_copy_expr (expr2
);
9727 this_code
->loc
= loc
;
9730 add_comp_ref (this_code
->expr1
, comp1
);
9731 add_comp_ref (this_code
->expr2
, comp2
);
9738 /* Makes a temporary variable expression based on the characteristics of
9739 a given variable expression. */
9742 get_temp_from_expr (gfc_expr
*e
, gfc_namespace
*ns
)
9744 static int serial
= 0;
9745 char name
[GFC_MAX_SYMBOL_LEN
];
9748 gfc_array_ref
*aref
;
9751 sprintf (name
, GFC_PREFIX("DA%d"), serial
++);
9752 gfc_get_sym_tree (name
, ns
, &tmp
, false);
9753 gfc_add_type (tmp
->n
.sym
, &e
->ts
, NULL
);
9759 /* Obtain the arrayspec for the temporary. */
9760 if (e
->rank
&& e
->expr_type
!= EXPR_ARRAY
9761 && e
->expr_type
!= EXPR_FUNCTION
9762 && e
->expr_type
!= EXPR_OP
)
9764 aref
= gfc_find_array_ref (e
);
9765 if (e
->expr_type
== EXPR_VARIABLE
9766 && e
->symtree
->n
.sym
->as
== aref
->as
)
9770 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
9771 if (ref
->type
== REF_COMPONENT
9772 && ref
->u
.c
.component
->as
== aref
->as
)
9780 /* Add the attributes and the arrayspec to the temporary. */
9781 tmp
->n
.sym
->attr
= gfc_expr_attr (e
);
9782 tmp
->n
.sym
->attr
.function
= 0;
9783 tmp
->n
.sym
->attr
.result
= 0;
9784 tmp
->n
.sym
->attr
.flavor
= FL_VARIABLE
;
9788 tmp
->n
.sym
->as
= gfc_copy_array_spec (as
);
9791 if (as
->type
== AS_DEFERRED
)
9792 tmp
->n
.sym
->attr
.allocatable
= 1;
9794 else if (e
->rank
&& (e
->expr_type
== EXPR_ARRAY
9795 || e
->expr_type
== EXPR_FUNCTION
9796 || e
->expr_type
== EXPR_OP
))
9798 tmp
->n
.sym
->as
= gfc_get_array_spec ();
9799 tmp
->n
.sym
->as
->type
= AS_DEFERRED
;
9800 tmp
->n
.sym
->as
->rank
= e
->rank
;
9801 tmp
->n
.sym
->attr
.allocatable
= 1;
9802 tmp
->n
.sym
->attr
.dimension
= 1;
9805 tmp
->n
.sym
->attr
.dimension
= 0;
9807 gfc_set_sym_referenced (tmp
->n
.sym
);
9808 gfc_commit_symbol (tmp
->n
.sym
);
9809 e
= gfc_lval_expr_from_sym (tmp
->n
.sym
);
9811 /* Should the lhs be a section, use its array ref for the
9812 temporary expression. */
9813 if (aref
&& aref
->type
!= AR_FULL
)
9815 gfc_free_ref_list (e
->ref
);
9816 e
->ref
= gfc_copy_ref (ref
);
9822 /* Add one line of code to the code chain, making sure that 'head' and
9823 'tail' are appropriately updated. */
9826 add_code_to_chain (gfc_code
**this_code
, gfc_code
**head
, gfc_code
**tail
)
9828 gcc_assert (this_code
);
9830 *head
= *tail
= *this_code
;
9832 *tail
= gfc_append_code (*tail
, *this_code
);
9837 /* Counts the potential number of part array references that would
9838 result from resolution of typebound defined assignments. */
9841 nonscalar_typebound_assign (gfc_symbol
*derived
, int depth
)
9844 int c_depth
= 0, t_depth
;
9846 for (c
= derived
->components
; c
; c
= c
->next
)
9848 if ((c
->ts
.type
!= BT_DERIVED
9850 || c
->attr
.allocatable
9851 || c
->attr
.proc_pointer_comp
9852 || c
->attr
.class_pointer
9853 || c
->attr
.proc_pointer
)
9854 && !c
->attr
.defined_assign_comp
)
9857 if (c
->as
&& c_depth
== 0)
9860 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
9861 t_depth
= nonscalar_typebound_assign (c
->ts
.u
.derived
,
9866 c_depth
= t_depth
> c_depth
? t_depth
: c_depth
;
9868 return depth
+ c_depth
;
9872 /* Implement 7.2.1.3 of the F08 standard:
9873 "An intrinsic assignment where the variable is of derived type is
9874 performed as if each component of the variable were assigned from the
9875 corresponding component of expr using pointer assignment (7.2.2) for
9876 each pointer component, defined assignment for each nonpointer
9877 nonallocatable component of a type that has a type-bound defined
9878 assignment consistent with the component, intrinsic assignment for
9879 each other nonpointer nonallocatable component, ..."
9881 The pointer assignments are taken care of by the intrinsic
9882 assignment of the structure itself. This function recursively adds
9883 defined assignments where required. The recursion is accomplished
9884 by calling gfc_resolve_code.
9886 When the lhs in a defined assignment has intent INOUT, we need a
9887 temporary for the lhs. In pseudo-code:
9889 ! Only call function lhs once.
9890 if (lhs is not a constant or an variable)
9893 ! Do the intrinsic assignment
9895 ! Now do the defined assignments
9896 do over components with typebound defined assignment [%cmp]
9897 #if one component's assignment procedure is INOUT
9899 #if expr2 non-variable
9905 t1%cmp {defined=} expr2%cmp
9911 expr1%cmp {defined=} expr2%cmp
9915 /* The temporary assignments have to be put on top of the additional
9916 code to avoid the result being changed by the intrinsic assignment.
9918 static int component_assignment_level
= 0;
9919 static gfc_code
*tmp_head
= NULL
, *tmp_tail
= NULL
;
9922 generate_component_assignments (gfc_code
**code
, gfc_namespace
*ns
)
9924 gfc_component
*comp1
, *comp2
;
9925 gfc_code
*this_code
= NULL
, *head
= NULL
, *tail
= NULL
;
9927 int error_count
, depth
;
9929 gfc_get_errors (NULL
, &error_count
);
9931 /* Filter out continuing processing after an error. */
9933 || (*code
)->expr1
->ts
.type
!= BT_DERIVED
9934 || (*code
)->expr2
->ts
.type
!= BT_DERIVED
)
9937 /* TODO: Handle more than one part array reference in assignments. */
9938 depth
= nonscalar_typebound_assign ((*code
)->expr1
->ts
.u
.derived
,
9939 (*code
)->expr1
->rank
? 1 : 0);
9942 gfc_warning (0, "TODO: type-bound defined assignment(s) at %L not "
9943 "done because multiple part array references would "
9944 "occur in intermediate expressions.", &(*code
)->loc
);
9948 component_assignment_level
++;
9950 /* Create a temporary so that functions get called only once. */
9951 if ((*code
)->expr2
->expr_type
!= EXPR_VARIABLE
9952 && (*code
)->expr2
->expr_type
!= EXPR_CONSTANT
)
9956 /* Assign the rhs to the temporary. */
9957 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
9958 this_code
= build_assignment (EXEC_ASSIGN
,
9959 tmp_expr
, (*code
)->expr2
,
9960 NULL
, NULL
, (*code
)->loc
);
9961 /* Add the code and substitute the rhs expression. */
9962 add_code_to_chain (&this_code
, &tmp_head
, &tmp_tail
);
9963 gfc_free_expr ((*code
)->expr2
);
9964 (*code
)->expr2
= tmp_expr
;
9967 /* Do the intrinsic assignment. This is not needed if the lhs is one
9968 of the temporaries generated here, since the intrinsic assignment
9969 to the final result already does this. */
9970 if ((*code
)->expr1
->symtree
->n
.sym
->name
[2] != '@')
9972 this_code
= build_assignment (EXEC_ASSIGN
,
9973 (*code
)->expr1
, (*code
)->expr2
,
9974 NULL
, NULL
, (*code
)->loc
);
9975 add_code_to_chain (&this_code
, &head
, &tail
);
9978 comp1
= (*code
)->expr1
->ts
.u
.derived
->components
;
9979 comp2
= (*code
)->expr2
->ts
.u
.derived
->components
;
9982 for (; comp1
; comp1
= comp1
->next
, comp2
= comp2
->next
)
9986 /* The intrinsic assignment does the right thing for pointers
9987 of all kinds and allocatable components. */
9988 if (comp1
->ts
.type
!= BT_DERIVED
9989 || comp1
->attr
.pointer
9990 || comp1
->attr
.allocatable
9991 || comp1
->attr
.proc_pointer_comp
9992 || comp1
->attr
.class_pointer
9993 || comp1
->attr
.proc_pointer
)
9996 /* Make an assigment for this component. */
9997 this_code
= build_assignment (EXEC_ASSIGN
,
9998 (*code
)->expr1
, (*code
)->expr2
,
9999 comp1
, comp2
, (*code
)->loc
);
10001 /* Convert the assignment if there is a defined assignment for
10002 this type. Otherwise, using the call from gfc_resolve_code,
10003 recurse into its components. */
10004 gfc_resolve_code (this_code
, ns
);
10006 if (this_code
->op
== EXEC_ASSIGN_CALL
)
10008 gfc_formal_arglist
*dummy_args
;
10010 /* Check that there is a typebound defined assignment. If not,
10011 then this must be a module defined assignment. We cannot
10012 use the defined_assign_comp attribute here because it must
10013 be this derived type that has the defined assignment and not
10015 if (!(comp1
->ts
.u
.derived
->f2k_derived
10016 && comp1
->ts
.u
.derived
->f2k_derived
10017 ->tb_op
[INTRINSIC_ASSIGN
]))
10019 gfc_free_statements (this_code
);
10024 /* If the first argument of the subroutine has intent INOUT
10025 a temporary must be generated and used instead. */
10026 rsym
= this_code
->resolved_sym
;
10027 dummy_args
= gfc_sym_get_dummy_args (rsym
);
10029 && dummy_args
->sym
->attr
.intent
== INTENT_INOUT
)
10031 gfc_code
*temp_code
;
10034 /* Build the temporary required for the assignment and put
10035 it at the head of the generated code. */
10038 t1
= get_temp_from_expr ((*code
)->expr1
, ns
);
10039 temp_code
= build_assignment (EXEC_ASSIGN
,
10040 t1
, (*code
)->expr1
,
10041 NULL
, NULL
, (*code
)->loc
);
10043 /* For allocatable LHS, check whether it is allocated. Note
10044 that allocatable components with defined assignment are
10045 not yet support. See PR 57696. */
10046 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
)
10050 gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
10051 block
= gfc_get_code (EXEC_IF
);
10052 block
->block
= gfc_get_code (EXEC_IF
);
10053 block
->block
->expr1
10054 = gfc_build_intrinsic_call (ns
,
10055 GFC_ISYM_ALLOCATED
, "allocated",
10056 (*code
)->loc
, 1, e
);
10057 block
->block
->next
= temp_code
;
10060 add_code_to_chain (&temp_code
, &tmp_head
, &tmp_tail
);
10063 /* Replace the first actual arg with the component of the
10065 gfc_free_expr (this_code
->ext
.actual
->expr
);
10066 this_code
->ext
.actual
->expr
= gfc_copy_expr (t1
);
10067 add_comp_ref (this_code
->ext
.actual
->expr
, comp1
);
10069 /* If the LHS variable is allocatable and wasn't allocated and
10070 the temporary is allocatable, pointer assign the address of
10071 the freshly allocated LHS to the temporary. */
10072 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
10073 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
10078 cond
= gfc_get_expr ();
10079 cond
->ts
.type
= BT_LOGICAL
;
10080 cond
->ts
.kind
= gfc_default_logical_kind
;
10081 cond
->expr_type
= EXPR_OP
;
10082 cond
->where
= (*code
)->loc
;
10083 cond
->value
.op
.op
= INTRINSIC_NOT
;
10084 cond
->value
.op
.op1
= gfc_build_intrinsic_call (ns
,
10085 GFC_ISYM_ALLOCATED
, "allocated",
10086 (*code
)->loc
, 1, gfc_copy_expr (t1
));
10087 block
= gfc_get_code (EXEC_IF
);
10088 block
->block
= gfc_get_code (EXEC_IF
);
10089 block
->block
->expr1
= cond
;
10090 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
10091 t1
, (*code
)->expr1
,
10092 NULL
, NULL
, (*code
)->loc
);
10093 add_code_to_chain (&block
, &head
, &tail
);
10097 else if (this_code
->op
== EXEC_ASSIGN
&& !this_code
->next
)
10099 /* Don't add intrinsic assignments since they are already
10100 effected by the intrinsic assignment of the structure. */
10101 gfc_free_statements (this_code
);
10106 add_code_to_chain (&this_code
, &head
, &tail
);
10110 /* Transfer the value to the final result. */
10111 this_code
= build_assignment (EXEC_ASSIGN
,
10112 (*code
)->expr1
, t1
,
10113 comp1
, comp2
, (*code
)->loc
);
10114 add_code_to_chain (&this_code
, &head
, &tail
);
10118 /* Put the temporary assignments at the top of the generated code. */
10119 if (tmp_head
&& component_assignment_level
== 1)
10121 gfc_append_code (tmp_head
, head
);
10123 tmp_head
= tmp_tail
= NULL
;
10126 // If we did a pointer assignment - thus, we need to ensure that the LHS is
10127 // not accidentally deallocated. Hence, nullify t1.
10128 if (t1
&& (*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
10129 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
10135 e
= gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
10136 cond
= gfc_build_intrinsic_call (ns
, GFC_ISYM_ASSOCIATED
, "associated",
10137 (*code
)->loc
, 2, gfc_copy_expr (t1
), e
);
10138 block
= gfc_get_code (EXEC_IF
);
10139 block
->block
= gfc_get_code (EXEC_IF
);
10140 block
->block
->expr1
= cond
;
10141 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
10142 t1
, gfc_get_null_expr (&(*code
)->loc
),
10143 NULL
, NULL
, (*code
)->loc
);
10144 gfc_append_code (tail
, block
);
10148 /* Now attach the remaining code chain to the input code. Step on
10149 to the end of the new code since resolution is complete. */
10150 gcc_assert ((*code
)->op
== EXEC_ASSIGN
);
10151 tail
->next
= (*code
)->next
;
10152 /* Overwrite 'code' because this would place the intrinsic assignment
10153 before the temporary for the lhs is created. */
10154 gfc_free_expr ((*code
)->expr1
);
10155 gfc_free_expr ((*code
)->expr2
);
10161 component_assignment_level
--;
10165 /* F2008: Pointer function assignments are of the form:
10166 ptr_fcn (args) = expr
10167 This function breaks these assignments into two statements:
10168 temporary_pointer => ptr_fcn(args)
10169 temporary_pointer = expr */
10172 resolve_ptr_fcn_assign (gfc_code
**code
, gfc_namespace
*ns
)
10174 gfc_expr
*tmp_ptr_expr
;
10175 gfc_code
*this_code
;
10176 gfc_component
*comp
;
10179 if ((*code
)->expr1
->expr_type
!= EXPR_FUNCTION
)
10182 /* Even if standard does not support this feature, continue to build
10183 the two statements to avoid upsetting frontend_passes.c. */
10184 gfc_notify_std (GFC_STD_F2008
, "Pointer procedure assignment at "
10185 "%L", &(*code
)->loc
);
10187 comp
= gfc_get_proc_ptr_comp ((*code
)->expr1
);
10190 s
= comp
->ts
.interface
;
10192 s
= (*code
)->expr1
->symtree
->n
.sym
;
10194 if (s
== NULL
|| !s
->result
->attr
.pointer
)
10196 gfc_error ("The function result on the lhs of the assignment at "
10197 "%L must have the pointer attribute.",
10198 &(*code
)->expr1
->where
);
10199 (*code
)->op
= EXEC_NOP
;
10203 tmp_ptr_expr
= get_temp_from_expr ((*code
)->expr2
, ns
);
10205 /* get_temp_from_expression is set up for ordinary assignments. To that
10206 end, where array bounds are not known, arrays are made allocatable.
10207 Change the temporary to a pointer here. */
10208 tmp_ptr_expr
->symtree
->n
.sym
->attr
.pointer
= 1;
10209 tmp_ptr_expr
->symtree
->n
.sym
->attr
.allocatable
= 0;
10210 tmp_ptr_expr
->where
= (*code
)->loc
;
10212 this_code
= build_assignment (EXEC_ASSIGN
,
10213 tmp_ptr_expr
, (*code
)->expr2
,
10214 NULL
, NULL
, (*code
)->loc
);
10215 this_code
->next
= (*code
)->next
;
10216 (*code
)->next
= this_code
;
10217 (*code
)->op
= EXEC_POINTER_ASSIGN
;
10218 (*code
)->expr2
= (*code
)->expr1
;
10219 (*code
)->expr1
= tmp_ptr_expr
;
10225 /* Deferred character length assignments from an operator expression
10226 require a temporary because the character length of the lhs can
10227 change in the course of the assignment. */
10230 deferred_op_assign (gfc_code
**code
, gfc_namespace
*ns
)
10232 gfc_expr
*tmp_expr
;
10233 gfc_code
*this_code
;
10235 if (!((*code
)->expr1
->ts
.type
== BT_CHARACTER
10236 && (*code
)->expr1
->ts
.deferred
&& (*code
)->expr1
->rank
10237 && (*code
)->expr2
->expr_type
== EXPR_OP
))
10240 if (!gfc_check_dependency ((*code
)->expr1
, (*code
)->expr2
, 1))
10243 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
10244 tmp_expr
->where
= (*code
)->loc
;
10246 /* A new charlen is required to ensure that the variable string
10247 length is different to that of the original lhs. */
10248 tmp_expr
->ts
.u
.cl
= gfc_get_charlen();
10249 tmp_expr
->symtree
->n
.sym
->ts
.u
.cl
= tmp_expr
->ts
.u
.cl
;
10250 tmp_expr
->ts
.u
.cl
->next
= (*code
)->expr2
->ts
.u
.cl
->next
;
10251 (*code
)->expr2
->ts
.u
.cl
->next
= tmp_expr
->ts
.u
.cl
;
10253 tmp_expr
->symtree
->n
.sym
->ts
.deferred
= 1;
10255 this_code
= build_assignment (EXEC_ASSIGN
,
10257 gfc_copy_expr (tmp_expr
),
10258 NULL
, NULL
, (*code
)->loc
);
10260 (*code
)->expr1
= tmp_expr
;
10262 this_code
->next
= (*code
)->next
;
10263 (*code
)->next
= this_code
;
10269 /* Given a block of code, recursively resolve everything pointed to by this
10273 gfc_resolve_code (gfc_code
*code
, gfc_namespace
*ns
)
10275 int omp_workshare_save
;
10276 int forall_save
, do_concurrent_save
;
10280 frame
.prev
= cs_base
;
10284 find_reachable_labels (code
);
10286 for (; code
; code
= code
->next
)
10288 frame
.current
= code
;
10289 forall_save
= forall_flag
;
10290 do_concurrent_save
= gfc_do_concurrent_flag
;
10292 if (code
->op
== EXEC_FORALL
)
10295 gfc_resolve_forall (code
, ns
, forall_save
);
10298 else if (code
->block
)
10300 omp_workshare_save
= -1;
10303 case EXEC_OACC_PARALLEL_LOOP
:
10304 case EXEC_OACC_PARALLEL
:
10305 case EXEC_OACC_KERNELS_LOOP
:
10306 case EXEC_OACC_KERNELS
:
10307 case EXEC_OACC_DATA
:
10308 case EXEC_OACC_HOST_DATA
:
10309 case EXEC_OACC_LOOP
:
10310 gfc_resolve_oacc_blocks (code
, ns
);
10312 case EXEC_OMP_PARALLEL_WORKSHARE
:
10313 omp_workshare_save
= omp_workshare_flag
;
10314 omp_workshare_flag
= 1;
10315 gfc_resolve_omp_parallel_blocks (code
, ns
);
10317 case EXEC_OMP_PARALLEL
:
10318 case EXEC_OMP_PARALLEL_DO
:
10319 case EXEC_OMP_PARALLEL_DO_SIMD
:
10320 case EXEC_OMP_PARALLEL_SECTIONS
:
10321 case EXEC_OMP_TARGET_TEAMS
:
10322 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
10323 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10324 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10325 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
10326 case EXEC_OMP_TASK
:
10327 case EXEC_OMP_TEAMS
:
10328 case EXEC_OMP_TEAMS_DISTRIBUTE
:
10329 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10330 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10331 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
10332 omp_workshare_save
= omp_workshare_flag
;
10333 omp_workshare_flag
= 0;
10334 gfc_resolve_omp_parallel_blocks (code
, ns
);
10336 case EXEC_OMP_DISTRIBUTE
:
10337 case EXEC_OMP_DISTRIBUTE_SIMD
:
10339 case EXEC_OMP_DO_SIMD
:
10340 case EXEC_OMP_SIMD
:
10341 gfc_resolve_omp_do_blocks (code
, ns
);
10343 case EXEC_SELECT_TYPE
:
10344 /* Blocks are handled in resolve_select_type because we have
10345 to transform the SELECT TYPE into ASSOCIATE first. */
10347 case EXEC_DO_CONCURRENT
:
10348 gfc_do_concurrent_flag
= 1;
10349 gfc_resolve_blocks (code
->block
, ns
);
10350 gfc_do_concurrent_flag
= 2;
10352 case EXEC_OMP_WORKSHARE
:
10353 omp_workshare_save
= omp_workshare_flag
;
10354 omp_workshare_flag
= 1;
10357 gfc_resolve_blocks (code
->block
, ns
);
10361 if (omp_workshare_save
!= -1)
10362 omp_workshare_flag
= omp_workshare_save
;
10366 if (code
->op
!= EXEC_COMPCALL
&& code
->op
!= EXEC_CALL_PPC
)
10367 t
= gfc_resolve_expr (code
->expr1
);
10368 forall_flag
= forall_save
;
10369 gfc_do_concurrent_flag
= do_concurrent_save
;
10371 if (!gfc_resolve_expr (code
->expr2
))
10374 if (code
->op
== EXEC_ALLOCATE
10375 && !gfc_resolve_expr (code
->expr3
))
10381 case EXEC_END_BLOCK
:
10382 case EXEC_END_NESTED_BLOCK
:
10386 case EXEC_ERROR_STOP
:
10388 case EXEC_CONTINUE
:
10390 case EXEC_ASSIGN_CALL
:
10393 case EXEC_CRITICAL
:
10394 resolve_critical (code
);
10397 case EXEC_SYNC_ALL
:
10398 case EXEC_SYNC_IMAGES
:
10399 case EXEC_SYNC_MEMORY
:
10400 resolve_sync (code
);
10405 resolve_lock_unlock (code
);
10409 /* Keep track of which entry we are up to. */
10410 current_entry_id
= code
->ext
.entry
->id
;
10414 resolve_where (code
, NULL
);
10418 if (code
->expr1
!= NULL
)
10420 if (code
->expr1
->ts
.type
!= BT_INTEGER
)
10421 gfc_error ("ASSIGNED GOTO statement at %L requires an "
10422 "INTEGER variable", &code
->expr1
->where
);
10423 else if (code
->expr1
->symtree
->n
.sym
->attr
.assign
!= 1)
10424 gfc_error ("Variable %qs has not been assigned a target "
10425 "label at %L", code
->expr1
->symtree
->n
.sym
->name
,
10426 &code
->expr1
->where
);
10429 resolve_branch (code
->label1
, code
);
10433 if (code
->expr1
!= NULL
10434 && (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
))
10435 gfc_error ("Alternate RETURN statement at %L requires a SCALAR-"
10436 "INTEGER return specifier", &code
->expr1
->where
);
10439 case EXEC_INIT_ASSIGN
:
10440 case EXEC_END_PROCEDURE
:
10447 /* Remove a GFC_ISYM_CAF_GET inserted for a coindexed variable on
10449 if (code
->expr1
->expr_type
== EXPR_FUNCTION
10450 && code
->expr1
->value
.function
.isym
10451 && code
->expr1
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
10452 remove_caf_get_intrinsic (code
->expr1
);
10454 /* If this is a pointer function in an lvalue variable context,
10455 the new code will have to be resolved afresh. This is also the
10456 case with an error, where the code is transformed into NOP to
10457 prevent ICEs downstream. */
10458 if (resolve_ptr_fcn_assign (&code
, ns
)
10459 || code
->op
== EXEC_NOP
)
10462 if (!gfc_check_vardef_context (code
->expr1
, false, false, false,
10466 if (resolve_ordinary_assign (code
, ns
))
10468 if (code
->op
== EXEC_COMPCALL
)
10474 /* Check for dependencies in deferred character length array
10475 assignments and generate a temporary, if necessary. */
10476 if (code
->op
== EXEC_ASSIGN
&& deferred_op_assign (&code
, ns
))
10479 /* F03 7.4.1.3 for non-allocatable, non-pointer components. */
10480 if (code
->op
!= EXEC_CALL
&& code
->expr1
->ts
.type
== BT_DERIVED
10481 && code
->expr1
->ts
.u
.derived
10482 && code
->expr1
->ts
.u
.derived
->attr
.defined_assign_comp
)
10483 generate_component_assignments (&code
, ns
);
10487 case EXEC_LABEL_ASSIGN
:
10488 if (code
->label1
->defined
== ST_LABEL_UNKNOWN
)
10489 gfc_error ("Label %d referenced at %L is never defined",
10490 code
->label1
->value
, &code
->label1
->where
);
10492 && (code
->expr1
->expr_type
!= EXPR_VARIABLE
10493 || code
->expr1
->symtree
->n
.sym
->ts
.type
!= BT_INTEGER
10494 || code
->expr1
->symtree
->n
.sym
->ts
.kind
10495 != gfc_default_integer_kind
10496 || code
->expr1
->symtree
->n
.sym
->as
!= NULL
))
10497 gfc_error ("ASSIGN statement at %L requires a scalar "
10498 "default INTEGER variable", &code
->expr1
->where
);
10501 case EXEC_POINTER_ASSIGN
:
10508 /* This is both a variable definition and pointer assignment
10509 context, so check both of them. For rank remapping, a final
10510 array ref may be present on the LHS and fool gfc_expr_attr
10511 used in gfc_check_vardef_context. Remove it. */
10512 e
= remove_last_array_ref (code
->expr1
);
10513 t
= gfc_check_vardef_context (e
, true, false, false,
10514 _("pointer assignment"));
10516 t
= gfc_check_vardef_context (e
, false, false, false,
10517 _("pointer assignment"));
10522 gfc_check_pointer_assign (code
->expr1
, code
->expr2
);
10526 case EXEC_ARITHMETIC_IF
:
10528 gfc_expr
*e
= code
->expr1
;
10530 gfc_resolve_expr (e
);
10531 if (e
->expr_type
== EXPR_NULL
)
10532 gfc_error ("Invalid NULL at %L", &e
->where
);
10534 if (t
&& (e
->rank
> 0
10535 || !(e
->ts
.type
== BT_REAL
|| e
->ts
.type
== BT_INTEGER
)))
10536 gfc_error ("Arithmetic IF statement at %L requires a scalar "
10537 "REAL or INTEGER expression", &e
->where
);
10539 resolve_branch (code
->label1
, code
);
10540 resolve_branch (code
->label2
, code
);
10541 resolve_branch (code
->label3
, code
);
10546 if (t
&& code
->expr1
!= NULL
10547 && (code
->expr1
->ts
.type
!= BT_LOGICAL
10548 || code
->expr1
->rank
!= 0))
10549 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
10550 &code
->expr1
->where
);
10555 resolve_call (code
);
10558 case EXEC_COMPCALL
:
10560 resolve_typebound_subroutine (code
);
10563 case EXEC_CALL_PPC
:
10564 resolve_ppc_call (code
);
10568 /* Select is complicated. Also, a SELECT construct could be
10569 a transformed computed GOTO. */
10570 resolve_select (code
, false);
10573 case EXEC_SELECT_TYPE
:
10574 resolve_select_type (code
, ns
);
10578 resolve_block_construct (code
);
10582 if (code
->ext
.iterator
!= NULL
)
10584 gfc_iterator
*iter
= code
->ext
.iterator
;
10585 if (gfc_resolve_iterator (iter
, true, false))
10586 gfc_resolve_do_iterator (code
, iter
->var
->symtree
->n
.sym
);
10590 case EXEC_DO_WHILE
:
10591 if (code
->expr1
== NULL
)
10592 gfc_internal_error ("gfc_resolve_code(): No expression on "
10595 && (code
->expr1
->rank
!= 0
10596 || code
->expr1
->ts
.type
!= BT_LOGICAL
))
10597 gfc_error ("Exit condition of DO WHILE loop at %L must be "
10598 "a scalar LOGICAL expression", &code
->expr1
->where
);
10601 case EXEC_ALLOCATE
:
10603 resolve_allocate_deallocate (code
, "ALLOCATE");
10607 case EXEC_DEALLOCATE
:
10609 resolve_allocate_deallocate (code
, "DEALLOCATE");
10614 if (!gfc_resolve_open (code
->ext
.open
))
10617 resolve_branch (code
->ext
.open
->err
, code
);
10621 if (!gfc_resolve_close (code
->ext
.close
))
10624 resolve_branch (code
->ext
.close
->err
, code
);
10627 case EXEC_BACKSPACE
:
10631 if (!gfc_resolve_filepos (code
->ext
.filepos
))
10634 resolve_branch (code
->ext
.filepos
->err
, code
);
10638 if (!gfc_resolve_inquire (code
->ext
.inquire
))
10641 resolve_branch (code
->ext
.inquire
->err
, code
);
10644 case EXEC_IOLENGTH
:
10645 gcc_assert (code
->ext
.inquire
!= NULL
);
10646 if (!gfc_resolve_inquire (code
->ext
.inquire
))
10649 resolve_branch (code
->ext
.inquire
->err
, code
);
10653 if (!gfc_resolve_wait (code
->ext
.wait
))
10656 resolve_branch (code
->ext
.wait
->err
, code
);
10657 resolve_branch (code
->ext
.wait
->end
, code
);
10658 resolve_branch (code
->ext
.wait
->eor
, code
);
10663 if (!gfc_resolve_dt (code
->ext
.dt
, &code
->loc
))
10666 resolve_branch (code
->ext
.dt
->err
, code
);
10667 resolve_branch (code
->ext
.dt
->end
, code
);
10668 resolve_branch (code
->ext
.dt
->eor
, code
);
10671 case EXEC_TRANSFER
:
10672 resolve_transfer (code
);
10675 case EXEC_DO_CONCURRENT
:
10677 resolve_forall_iterators (code
->ext
.forall_iterator
);
10679 if (code
->expr1
!= NULL
10680 && (code
->expr1
->ts
.type
!= BT_LOGICAL
|| code
->expr1
->rank
))
10681 gfc_error ("FORALL mask clause at %L requires a scalar LOGICAL "
10682 "expression", &code
->expr1
->where
);
10685 case EXEC_OACC_PARALLEL_LOOP
:
10686 case EXEC_OACC_PARALLEL
:
10687 case EXEC_OACC_KERNELS_LOOP
:
10688 case EXEC_OACC_KERNELS
:
10689 case EXEC_OACC_DATA
:
10690 case EXEC_OACC_HOST_DATA
:
10691 case EXEC_OACC_LOOP
:
10692 case EXEC_OACC_UPDATE
:
10693 case EXEC_OACC_WAIT
:
10694 case EXEC_OACC_CACHE
:
10695 case EXEC_OACC_ENTER_DATA
:
10696 case EXEC_OACC_EXIT_DATA
:
10697 case EXEC_OACC_ATOMIC
:
10698 case EXEC_OACC_DECLARE
:
10699 gfc_resolve_oacc_directive (code
, ns
);
10702 case EXEC_OMP_ATOMIC
:
10703 case EXEC_OMP_BARRIER
:
10704 case EXEC_OMP_CANCEL
:
10705 case EXEC_OMP_CANCELLATION_POINT
:
10706 case EXEC_OMP_CRITICAL
:
10707 case EXEC_OMP_FLUSH
:
10708 case EXEC_OMP_DISTRIBUTE
:
10709 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
10710 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
10711 case EXEC_OMP_DISTRIBUTE_SIMD
:
10713 case EXEC_OMP_DO_SIMD
:
10714 case EXEC_OMP_MASTER
:
10715 case EXEC_OMP_ORDERED
:
10716 case EXEC_OMP_SECTIONS
:
10717 case EXEC_OMP_SIMD
:
10718 case EXEC_OMP_SINGLE
:
10719 case EXEC_OMP_TARGET
:
10720 case EXEC_OMP_TARGET_DATA
:
10721 case EXEC_OMP_TARGET_TEAMS
:
10722 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
10723 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10724 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10725 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
10726 case EXEC_OMP_TARGET_UPDATE
:
10727 case EXEC_OMP_TASK
:
10728 case EXEC_OMP_TASKGROUP
:
10729 case EXEC_OMP_TASKWAIT
:
10730 case EXEC_OMP_TASKYIELD
:
10731 case EXEC_OMP_TEAMS
:
10732 case EXEC_OMP_TEAMS_DISTRIBUTE
:
10733 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10734 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10735 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
10736 case EXEC_OMP_WORKSHARE
:
10737 gfc_resolve_omp_directive (code
, ns
);
10740 case EXEC_OMP_PARALLEL
:
10741 case EXEC_OMP_PARALLEL_DO
:
10742 case EXEC_OMP_PARALLEL_DO_SIMD
:
10743 case EXEC_OMP_PARALLEL_SECTIONS
:
10744 case EXEC_OMP_PARALLEL_WORKSHARE
:
10745 omp_workshare_save
= omp_workshare_flag
;
10746 omp_workshare_flag
= 0;
10747 gfc_resolve_omp_directive (code
, ns
);
10748 omp_workshare_flag
= omp_workshare_save
;
10752 gfc_internal_error ("gfc_resolve_code(): Bad statement code");
10756 cs_base
= frame
.prev
;
10760 /* Resolve initial values and make sure they are compatible with
10764 resolve_values (gfc_symbol
*sym
)
10768 if (sym
->value
== NULL
)
10771 if (sym
->value
->expr_type
== EXPR_STRUCTURE
)
10772 t
= resolve_structure_cons (sym
->value
, 1);
10774 t
= gfc_resolve_expr (sym
->value
);
10779 gfc_check_assign_symbol (sym
, NULL
, sym
->value
);
10783 /* Verify any BIND(C) derived types in the namespace so we can report errors
10784 for them once, rather than for each variable declared of that type. */
10787 resolve_bind_c_derived_types (gfc_symbol
*derived_sym
)
10789 if (derived_sym
!= NULL
&& derived_sym
->attr
.flavor
== FL_DERIVED
10790 && derived_sym
->attr
.is_bind_c
== 1)
10791 verify_bind_c_derived_type (derived_sym
);
10797 /* Verify that any binding labels used in a given namespace do not collide
10798 with the names or binding labels of any global symbols. Multiple INTERFACE
10799 for the same procedure are permitted. */
10802 gfc_verify_binding_labels (gfc_symbol
*sym
)
10805 const char *module
;
10807 if (!sym
|| !sym
->attr
.is_bind_c
|| sym
->attr
.is_iso_c
10808 || sym
->attr
.flavor
== FL_DERIVED
|| !sym
->binding_label
)
10811 gsym
= gfc_find_gsymbol (gfc_gsym_root
, sym
->binding_label
);
10814 module
= sym
->module
;
10815 else if (sym
->ns
&& sym
->ns
->proc_name
10816 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
10817 module
= sym
->ns
->proc_name
->name
;
10818 else if (sym
->ns
&& sym
->ns
->parent
10819 && sym
->ns
&& sym
->ns
->parent
->proc_name
10820 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
10821 module
= sym
->ns
->parent
->proc_name
->name
;
10827 && (gsym
->type
== GSYM_FUNCTION
|| gsym
->type
== GSYM_SUBROUTINE
)))
10830 gsym
= gfc_get_gsymbol (sym
->binding_label
);
10831 gsym
->where
= sym
->declared_at
;
10832 gsym
->sym_name
= sym
->name
;
10833 gsym
->binding_label
= sym
->binding_label
;
10834 gsym
->ns
= sym
->ns
;
10835 gsym
->mod_name
= module
;
10836 if (sym
->attr
.function
)
10837 gsym
->type
= GSYM_FUNCTION
;
10838 else if (sym
->attr
.subroutine
)
10839 gsym
->type
= GSYM_SUBROUTINE
;
10840 /* Mark as variable/procedure as defined, unless its an INTERFACE. */
10841 gsym
->defined
= sym
->attr
.if_source
!= IFSRC_IFBODY
;
10845 if (sym
->attr
.flavor
== FL_VARIABLE
&& gsym
->type
!= GSYM_UNKNOWN
)
10847 gfc_error ("Variable %s with binding label %s at %L uses the same global "
10848 "identifier as entity at %L", sym
->name
,
10849 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
10850 /* Clear the binding label to prevent checking multiple times. */
10851 sym
->binding_label
= NULL
;
10854 else if (sym
->attr
.flavor
== FL_VARIABLE
&& module
10855 && (strcmp (module
, gsym
->mod_name
) != 0
10856 || strcmp (sym
->name
, gsym
->sym_name
) != 0))
10858 /* This can only happen if the variable is defined in a module - if it
10859 isn't the same module, reject it. */
10860 gfc_error ("Variable %s from module %s with binding label %s at %L uses "
10861 "the same global identifier as entity at %L from module %s",
10862 sym
->name
, module
, sym
->binding_label
,
10863 &sym
->declared_at
, &gsym
->where
, gsym
->mod_name
);
10864 sym
->binding_label
= NULL
;
10866 else if ((sym
->attr
.function
|| sym
->attr
.subroutine
)
10867 && ((gsym
->type
!= GSYM_SUBROUTINE
&& gsym
->type
!= GSYM_FUNCTION
)
10868 || (gsym
->defined
&& sym
->attr
.if_source
!= IFSRC_IFBODY
))
10869 && sym
!= gsym
->ns
->proc_name
10870 && (module
!= gsym
->mod_name
10871 || strcmp (gsym
->sym_name
, sym
->name
) != 0
10872 || (module
&& strcmp (module
, gsym
->mod_name
) != 0)))
10874 /* Print an error if the procedure is defined multiple times; we have to
10875 exclude references to the same procedure via module association or
10876 multiple checks for the same procedure. */
10877 gfc_error ("Procedure %s with binding label %s at %L uses the same "
10878 "global identifier as entity at %L", sym
->name
,
10879 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
10880 sym
->binding_label
= NULL
;
10885 /* Resolve an index expression. */
10888 resolve_index_expr (gfc_expr
*e
)
10890 if (!gfc_resolve_expr (e
))
10893 if (!gfc_simplify_expr (e
, 0))
10896 if (!gfc_specification_expr (e
))
10903 /* Resolve a charlen structure. */
10906 resolve_charlen (gfc_charlen
*cl
)
10909 bool saved_specification_expr
;
10915 saved_specification_expr
= specification_expr
;
10916 specification_expr
= true;
10918 if (cl
->length_from_typespec
)
10920 if (!gfc_resolve_expr (cl
->length
))
10922 specification_expr
= saved_specification_expr
;
10926 if (!gfc_simplify_expr (cl
->length
, 0))
10928 specification_expr
= saved_specification_expr
;
10935 if (!resolve_index_expr (cl
->length
))
10937 specification_expr
= saved_specification_expr
;
10942 /* F2008, 4.4.3.2: If the character length parameter value evaluates to
10943 a negative value, the length of character entities declared is zero. */
10944 if (cl
->length
&& !gfc_extract_int (cl
->length
, &i
) && i
< 0)
10945 gfc_replace_expr (cl
->length
,
10946 gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 0));
10948 /* Check that the character length is not too large. */
10949 k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
10950 if (cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
10951 && cl
->length
->ts
.type
== BT_INTEGER
10952 && mpz_cmp (cl
->length
->value
.integer
, gfc_integer_kinds
[k
].huge
) > 0)
10954 gfc_error ("String length at %L is too large", &cl
->length
->where
);
10955 specification_expr
= saved_specification_expr
;
10959 specification_expr
= saved_specification_expr
;
10964 /* Test for non-constant shape arrays. */
10967 is_non_constant_shape_array (gfc_symbol
*sym
)
10973 not_constant
= false;
10974 if (sym
->as
!= NULL
)
10976 /* Unfortunately, !gfc_is_compile_time_shape hits a legal case that
10977 has not been simplified; parameter array references. Do the
10978 simplification now. */
10979 for (i
= 0; i
< sym
->as
->rank
+ sym
->as
->corank
; i
++)
10981 e
= sym
->as
->lower
[i
];
10982 if (e
&& (!resolve_index_expr(e
)
10983 || !gfc_is_constant_expr (e
)))
10984 not_constant
= true;
10985 e
= sym
->as
->upper
[i
];
10986 if (e
&& (!resolve_index_expr(e
)
10987 || !gfc_is_constant_expr (e
)))
10988 not_constant
= true;
10991 return not_constant
;
10994 /* Given a symbol and an initialization expression, add code to initialize
10995 the symbol to the function entry. */
10997 build_init_assign (gfc_symbol
*sym
, gfc_expr
*init
)
11001 gfc_namespace
*ns
= sym
->ns
;
11003 /* Search for the function namespace if this is a contained
11004 function without an explicit result. */
11005 if (sym
->attr
.function
&& sym
== sym
->result
11006 && sym
->name
!= sym
->ns
->proc_name
->name
)
11008 ns
= ns
->contained
;
11009 for (;ns
; ns
= ns
->sibling
)
11010 if (strcmp (ns
->proc_name
->name
, sym
->name
) == 0)
11016 gfc_free_expr (init
);
11020 /* Build an l-value expression for the result. */
11021 lval
= gfc_lval_expr_from_sym (sym
);
11023 /* Add the code at scope entry. */
11024 init_st
= gfc_get_code (EXEC_INIT_ASSIGN
);
11025 init_st
->next
= ns
->code
;
11026 ns
->code
= init_st
;
11028 /* Assign the default initializer to the l-value. */
11029 init_st
->loc
= sym
->declared_at
;
11030 init_st
->expr1
= lval
;
11031 init_st
->expr2
= init
;
11034 /* Assign the default initializer to a derived type variable or result. */
11037 apply_default_init (gfc_symbol
*sym
)
11039 gfc_expr
*init
= NULL
;
11041 if (sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
11044 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
)
11045 init
= gfc_default_initializer (&sym
->ts
);
11047 if (init
== NULL
&& sym
->ts
.type
!= BT_CLASS
)
11050 build_init_assign (sym
, init
);
11051 sym
->attr
.referenced
= 1;
11054 /* Build an initializer for a local integer, real, complex, logical, or
11055 character variable, based on the command line flags finit-local-zero,
11056 finit-integer=, finit-real=, finit-logical=, and finit-runtime. Returns
11057 null if the symbol should not have a default initialization. */
11059 build_default_init_expr (gfc_symbol
*sym
)
11062 gfc_expr
*init_expr
;
11065 /* These symbols should never have a default initialization. */
11066 if (sym
->attr
.allocatable
11067 || sym
->attr
.external
11069 || sym
->attr
.pointer
11070 || sym
->attr
.in_equivalence
11071 || sym
->attr
.in_common
11074 || sym
->attr
.cray_pointee
11075 || sym
->attr
.cray_pointer
11079 /* Now we'll try to build an initializer expression. */
11080 init_expr
= gfc_get_constant_expr (sym
->ts
.type
, sym
->ts
.kind
,
11081 &sym
->declared_at
);
11083 /* We will only initialize integers, reals, complex, logicals, and
11084 characters, and only if the corresponding command-line flags
11085 were set. Otherwise, we free init_expr and return null. */
11086 switch (sym
->ts
.type
)
11089 if (gfc_option
.flag_init_integer
!= GFC_INIT_INTEGER_OFF
)
11090 mpz_set_si (init_expr
->value
.integer
,
11091 gfc_option
.flag_init_integer_value
);
11094 gfc_free_expr (init_expr
);
11100 switch (flag_init_real
)
11102 case GFC_INIT_REAL_SNAN
:
11103 init_expr
->is_snan
= 1;
11104 /* Fall through. */
11105 case GFC_INIT_REAL_NAN
:
11106 mpfr_set_nan (init_expr
->value
.real
);
11109 case GFC_INIT_REAL_INF
:
11110 mpfr_set_inf (init_expr
->value
.real
, 1);
11113 case GFC_INIT_REAL_NEG_INF
:
11114 mpfr_set_inf (init_expr
->value
.real
, -1);
11117 case GFC_INIT_REAL_ZERO
:
11118 mpfr_set_ui (init_expr
->value
.real
, 0.0, GFC_RND_MODE
);
11122 gfc_free_expr (init_expr
);
11129 switch (flag_init_real
)
11131 case GFC_INIT_REAL_SNAN
:
11132 init_expr
->is_snan
= 1;
11133 /* Fall through. */
11134 case GFC_INIT_REAL_NAN
:
11135 mpfr_set_nan (mpc_realref (init_expr
->value
.complex));
11136 mpfr_set_nan (mpc_imagref (init_expr
->value
.complex));
11139 case GFC_INIT_REAL_INF
:
11140 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), 1);
11141 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), 1);
11144 case GFC_INIT_REAL_NEG_INF
:
11145 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), -1);
11146 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), -1);
11149 case GFC_INIT_REAL_ZERO
:
11150 mpc_set_ui (init_expr
->value
.complex, 0, GFC_MPC_RND_MODE
);
11154 gfc_free_expr (init_expr
);
11161 if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_FALSE
)
11162 init_expr
->value
.logical
= 0;
11163 else if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_TRUE
)
11164 init_expr
->value
.logical
= 1;
11167 gfc_free_expr (init_expr
);
11173 /* For characters, the length must be constant in order to
11174 create a default initializer. */
11175 if (gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
11176 && sym
->ts
.u
.cl
->length
11177 && sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
11179 char_len
= mpz_get_si (sym
->ts
.u
.cl
->length
->value
.integer
);
11180 init_expr
->value
.character
.length
= char_len
;
11181 init_expr
->value
.character
.string
= gfc_get_wide_string (char_len
+1);
11182 for (i
= 0; i
< char_len
; i
++)
11183 init_expr
->value
.character
.string
[i
]
11184 = (unsigned char) gfc_option
.flag_init_character_value
;
11188 gfc_free_expr (init_expr
);
11191 if (!init_expr
&& gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
11192 && sym
->ts
.u
.cl
->length
&& flag_max_stack_var_size
!= 0)
11194 gfc_actual_arglist
*arg
;
11195 init_expr
= gfc_get_expr ();
11196 init_expr
->where
= sym
->declared_at
;
11197 init_expr
->ts
= sym
->ts
;
11198 init_expr
->expr_type
= EXPR_FUNCTION
;
11199 init_expr
->value
.function
.isym
=
11200 gfc_intrinsic_function_by_id (GFC_ISYM_REPEAT
);
11201 init_expr
->value
.function
.name
= "repeat";
11202 arg
= gfc_get_actual_arglist ();
11203 arg
->expr
= gfc_get_character_expr (sym
->ts
.kind
, &sym
->declared_at
,
11205 arg
->expr
->value
.character
.string
[0]
11206 = gfc_option
.flag_init_character_value
;
11207 arg
->next
= gfc_get_actual_arglist ();
11208 arg
->next
->expr
= gfc_copy_expr (sym
->ts
.u
.cl
->length
);
11209 init_expr
->value
.function
.actual
= arg
;
11214 gfc_free_expr (init_expr
);
11220 /* Add an initialization expression to a local variable. */
11222 apply_default_init_local (gfc_symbol
*sym
)
11224 gfc_expr
*init
= NULL
;
11226 /* The symbol should be a variable or a function return value. */
11227 if ((sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
11228 || (sym
->attr
.function
&& sym
->result
!= sym
))
11231 /* Try to build the initializer expression. If we can't initialize
11232 this symbol, then init will be NULL. */
11233 init
= build_default_init_expr (sym
);
11237 /* For saved variables, we don't want to add an initializer at function
11238 entry, so we just add a static initializer. Note that automatic variables
11239 are stack allocated even with -fno-automatic; we have also to exclude
11240 result variable, which are also nonstatic. */
11241 if (sym
->attr
.save
|| sym
->ns
->save_all
11242 || (flag_max_stack_var_size
== 0 && !sym
->attr
.result
11243 && (sym
->ns
->proc_name
&& !sym
->ns
->proc_name
->attr
.recursive
)
11244 && (!sym
->attr
.dimension
|| !is_non_constant_shape_array (sym
))))
11246 /* Don't clobber an existing initializer! */
11247 gcc_assert (sym
->value
== NULL
);
11252 build_init_assign (sym
, init
);
11256 /* Resolution of common features of flavors variable and procedure. */
11259 resolve_fl_var_and_proc (gfc_symbol
*sym
, int mp_flag
)
11261 gfc_array_spec
*as
;
11263 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
11264 as
= CLASS_DATA (sym
)->as
;
11268 /* Constraints on deferred shape variable. */
11269 if (as
== NULL
|| as
->type
!= AS_DEFERRED
)
11271 bool pointer
, allocatable
, dimension
;
11273 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
11275 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
11276 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
11277 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
11281 pointer
= sym
->attr
.pointer
&& !sym
->attr
.select_type_temporary
;
11282 allocatable
= sym
->attr
.allocatable
;
11283 dimension
= sym
->attr
.dimension
;
11288 if (dimension
&& as
->type
!= AS_ASSUMED_RANK
)
11290 gfc_error ("Allocatable array %qs at %L must have a deferred "
11291 "shape or assumed rank", sym
->name
, &sym
->declared_at
);
11294 else if (!gfc_notify_std (GFC_STD_F2003
, "Scalar object "
11295 "%qs at %L may not be ALLOCATABLE",
11296 sym
->name
, &sym
->declared_at
))
11300 if (pointer
&& dimension
&& as
->type
!= AS_ASSUMED_RANK
)
11302 gfc_error ("Array pointer %qs at %L must have a deferred shape or "
11303 "assumed rank", sym
->name
, &sym
->declared_at
);
11309 if (!mp_flag
&& !sym
->attr
.allocatable
&& !sym
->attr
.pointer
11310 && sym
->ts
.type
!= BT_CLASS
&& !sym
->assoc
)
11312 gfc_error ("Array %qs at %L cannot have a deferred shape",
11313 sym
->name
, &sym
->declared_at
);
11318 /* Constraints on polymorphic variables. */
11319 if (sym
->ts
.type
== BT_CLASS
&& !(sym
->result
&& sym
->result
!= sym
))
11322 if (sym
->attr
.class_ok
11323 && !sym
->attr
.select_type_temporary
11324 && !UNLIMITED_POLY (sym
)
11325 && !gfc_type_is_extensible (CLASS_DATA (sym
)->ts
.u
.derived
))
11327 gfc_error ("Type %qs of CLASS variable %qs at %L is not extensible",
11328 CLASS_DATA (sym
)->ts
.u
.derived
->name
, sym
->name
,
11329 &sym
->declared_at
);
11334 /* Assume that use associated symbols were checked in the module ns.
11335 Class-variables that are associate-names are also something special
11336 and excepted from the test. */
11337 if (!sym
->attr
.class_ok
&& !sym
->attr
.use_assoc
&& !sym
->assoc
)
11339 gfc_error ("CLASS variable %qs at %L must be dummy, allocatable "
11340 "or pointer", sym
->name
, &sym
->declared_at
);
11349 /* Additional checks for symbols with flavor variable and derived
11350 type. To be called from resolve_fl_variable. */
11353 resolve_fl_variable_derived (gfc_symbol
*sym
, int no_init_flag
)
11355 gcc_assert (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
);
11357 /* Check to see if a derived type is blocked from being host
11358 associated by the presence of another class I symbol in the same
11359 namespace. 14.6.1.3 of the standard and the discussion on
11360 comp.lang.fortran. */
11361 if (sym
->ns
!= sym
->ts
.u
.derived
->ns
11362 && sym
->ns
->proc_name
->attr
.if_source
!= IFSRC_IFBODY
)
11365 gfc_find_symbol (sym
->ts
.u
.derived
->name
, sym
->ns
, 0, &s
);
11366 if (s
&& s
->attr
.generic
)
11367 s
= gfc_find_dt_in_generic (s
);
11368 if (s
&& s
->attr
.flavor
!= FL_DERIVED
)
11370 gfc_error ("The type %qs cannot be host associated at %L "
11371 "because it is blocked by an incompatible object "
11372 "of the same name declared at %L",
11373 sym
->ts
.u
.derived
->name
, &sym
->declared_at
,
11379 /* 4th constraint in section 11.3: "If an object of a type for which
11380 component-initialization is specified (R429) appears in the
11381 specification-part of a module and does not have the ALLOCATABLE
11382 or POINTER attribute, the object shall have the SAVE attribute."
11384 The check for initializers is performed with
11385 gfc_has_default_initializer because gfc_default_initializer generates
11386 a hidden default for allocatable components. */
11387 if (!(sym
->value
|| no_init_flag
) && sym
->ns
->proc_name
11388 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
11389 && !sym
->ns
->save_all
&& !sym
->attr
.save
11390 && !sym
->attr
.pointer
&& !sym
->attr
.allocatable
11391 && gfc_has_default_initializer (sym
->ts
.u
.derived
)
11392 && !gfc_notify_std (GFC_STD_F2008
, "Implied SAVE for module variable "
11393 "%qs at %L, needed due to the default "
11394 "initialization", sym
->name
, &sym
->declared_at
))
11397 /* Assign default initializer. */
11398 if (!(sym
->value
|| sym
->attr
.pointer
|| sym
->attr
.allocatable
)
11399 && (!no_init_flag
|| sym
->attr
.intent
== INTENT_OUT
))
11401 sym
->value
= gfc_default_initializer (&sym
->ts
);
11408 /* Resolve symbols with flavor variable. */
11411 resolve_fl_variable (gfc_symbol
*sym
, int mp_flag
)
11413 int no_init_flag
, automatic_flag
;
11415 const char *auto_save_msg
;
11416 bool saved_specification_expr
;
11418 auto_save_msg
= "Automatic object %qs at %L cannot have the "
11421 if (!resolve_fl_var_and_proc (sym
, mp_flag
))
11424 /* Set this flag to check that variables are parameters of all entries.
11425 This check is effected by the call to gfc_resolve_expr through
11426 is_non_constant_shape_array. */
11427 saved_specification_expr
= specification_expr
;
11428 specification_expr
= true;
11430 if (sym
->ns
->proc_name
11431 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
11432 || sym
->ns
->proc_name
->attr
.is_main_program
)
11433 && !sym
->attr
.use_assoc
11434 && !sym
->attr
.allocatable
11435 && !sym
->attr
.pointer
11436 && is_non_constant_shape_array (sym
))
11438 /* The shape of a main program or module array needs to be
11440 gfc_error ("The module or main program array %qs at %L must "
11441 "have constant shape", sym
->name
, &sym
->declared_at
);
11442 specification_expr
= saved_specification_expr
;
11446 /* Constraints on deferred type parameter. */
11447 if (sym
->ts
.deferred
11448 && !(sym
->attr
.pointer
11449 || sym
->attr
.allocatable
11450 || sym
->attr
.omp_udr_artificial_var
))
11452 gfc_error ("Entity %qs at %L has a deferred type parameter and "
11453 "requires either the pointer or allocatable attribute",
11454 sym
->name
, &sym
->declared_at
);
11455 specification_expr
= saved_specification_expr
;
11459 if (sym
->ts
.type
== BT_CHARACTER
)
11461 /* Make sure that character string variables with assumed length are
11462 dummy arguments. */
11463 e
= sym
->ts
.u
.cl
->length
;
11464 if (e
== NULL
&& !sym
->attr
.dummy
&& !sym
->attr
.result
11465 && !sym
->ts
.deferred
&& !sym
->attr
.select_type_temporary
11466 && !sym
->attr
.omp_udr_artificial_var
)
11468 gfc_error ("Entity with assumed character length at %L must be a "
11469 "dummy argument or a PARAMETER", &sym
->declared_at
);
11470 specification_expr
= saved_specification_expr
;
11474 if (e
&& sym
->attr
.save
== SAVE_EXPLICIT
&& !gfc_is_constant_expr (e
))
11476 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
11477 specification_expr
= saved_specification_expr
;
11481 if (!gfc_is_constant_expr (e
)
11482 && !(e
->expr_type
== EXPR_VARIABLE
11483 && e
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
))
11485 if (!sym
->attr
.use_assoc
&& sym
->ns
->proc_name
11486 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
11487 || sym
->ns
->proc_name
->attr
.is_main_program
))
11489 gfc_error ("%qs at %L must have constant character length "
11490 "in this context", sym
->name
, &sym
->declared_at
);
11491 specification_expr
= saved_specification_expr
;
11494 if (sym
->attr
.in_common
)
11496 gfc_error ("COMMON variable %qs at %L must have constant "
11497 "character length", sym
->name
, &sym
->declared_at
);
11498 specification_expr
= saved_specification_expr
;
11504 if (sym
->value
== NULL
&& sym
->attr
.referenced
)
11505 apply_default_init_local (sym
); /* Try to apply a default initialization. */
11507 /* Determine if the symbol may not have an initializer. */
11508 no_init_flag
= automatic_flag
= 0;
11509 if (sym
->attr
.allocatable
|| sym
->attr
.external
|| sym
->attr
.dummy
11510 || sym
->attr
.intrinsic
|| sym
->attr
.result
)
11512 else if ((sym
->attr
.dimension
|| sym
->attr
.codimension
) && !sym
->attr
.pointer
11513 && is_non_constant_shape_array (sym
))
11515 no_init_flag
= automatic_flag
= 1;
11517 /* Also, they must not have the SAVE attribute.
11518 SAVE_IMPLICIT is checked below. */
11519 if (sym
->as
&& sym
->attr
.codimension
)
11521 int corank
= sym
->as
->corank
;
11522 sym
->as
->corank
= 0;
11523 no_init_flag
= automatic_flag
= is_non_constant_shape_array (sym
);
11524 sym
->as
->corank
= corank
;
11526 if (automatic_flag
&& sym
->attr
.save
== SAVE_EXPLICIT
)
11528 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
11529 specification_expr
= saved_specification_expr
;
11534 /* Ensure that any initializer is simplified. */
11536 gfc_simplify_expr (sym
->value
, 1);
11538 /* Reject illegal initializers. */
11539 if (!sym
->mark
&& sym
->value
)
11541 if (sym
->attr
.allocatable
|| (sym
->ts
.type
== BT_CLASS
11542 && CLASS_DATA (sym
)->attr
.allocatable
))
11543 gfc_error ("Allocatable %qs at %L cannot have an initializer",
11544 sym
->name
, &sym
->declared_at
);
11545 else if (sym
->attr
.external
)
11546 gfc_error ("External %qs at %L cannot have an initializer",
11547 sym
->name
, &sym
->declared_at
);
11548 else if (sym
->attr
.dummy
11549 && !(sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.intent
== INTENT_OUT
))
11550 gfc_error ("Dummy %qs at %L cannot have an initializer",
11551 sym
->name
, &sym
->declared_at
);
11552 else if (sym
->attr
.intrinsic
)
11553 gfc_error ("Intrinsic %qs at %L cannot have an initializer",
11554 sym
->name
, &sym
->declared_at
);
11555 else if (sym
->attr
.result
)
11556 gfc_error ("Function result %qs at %L cannot have an initializer",
11557 sym
->name
, &sym
->declared_at
);
11558 else if (automatic_flag
)
11559 gfc_error ("Automatic array %qs at %L cannot have an initializer",
11560 sym
->name
, &sym
->declared_at
);
11562 goto no_init_error
;
11563 specification_expr
= saved_specification_expr
;
11568 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
11570 bool res
= resolve_fl_variable_derived (sym
, no_init_flag
);
11571 specification_expr
= saved_specification_expr
;
11575 specification_expr
= saved_specification_expr
;
11580 /* Compare the dummy characteristics of a module procedure interface
11581 declaration with the corresponding declaration in a submodule. */
11582 static gfc_formal_arglist
*new_formal
;
11583 static char errmsg
[200];
11586 compare_fsyms (gfc_symbol
*sym
)
11590 if (sym
== NULL
|| new_formal
== NULL
)
11593 fsym
= new_formal
->sym
;
11598 if (strcmp (sym
->name
, fsym
->name
) == 0)
11600 if (!gfc_check_dummy_characteristics (fsym
, sym
, true, errmsg
, 200))
11601 gfc_error ("%s at %L", errmsg
, &fsym
->declared_at
);
11606 /* Resolve a procedure. */
11609 resolve_fl_procedure (gfc_symbol
*sym
, int mp_flag
)
11611 gfc_formal_arglist
*arg
;
11613 if (sym
->attr
.function
11614 && !resolve_fl_var_and_proc (sym
, mp_flag
))
11617 if (sym
->ts
.type
== BT_CHARACTER
)
11619 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
11621 if (cl
&& cl
->length
&& gfc_is_constant_expr (cl
->length
)
11622 && !resolve_charlen (cl
))
11625 if ((!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
11626 && sym
->attr
.proc
== PROC_ST_FUNCTION
)
11628 gfc_error ("Character-valued statement function %qs at %L must "
11629 "have constant length", sym
->name
, &sym
->declared_at
);
11634 /* Ensure that derived type for are not of a private type. Internal
11635 module procedures are excluded by 2.2.3.3 - i.e., they are not
11636 externally accessible and can access all the objects accessible in
11638 if (!(sym
->ns
->parent
11639 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
11640 && gfc_check_symbol_access (sym
))
11642 gfc_interface
*iface
;
11644 for (arg
= gfc_sym_get_dummy_args (sym
); arg
; arg
= arg
->next
)
11647 && arg
->sym
->ts
.type
== BT_DERIVED
11648 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
11649 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
11650 && !gfc_notify_std (GFC_STD_F2003
, "%qs is of a PRIVATE type "
11651 "and cannot be a dummy argument"
11652 " of %qs, which is PUBLIC at %L",
11653 arg
->sym
->name
, sym
->name
,
11654 &sym
->declared_at
))
11656 /* Stop this message from recurring. */
11657 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
11662 /* PUBLIC interfaces may expose PRIVATE procedures that take types
11663 PRIVATE to the containing module. */
11664 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
11666 for (arg
= gfc_sym_get_dummy_args (iface
->sym
); arg
; arg
= arg
->next
)
11669 && arg
->sym
->ts
.type
== BT_DERIVED
11670 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
11671 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
11672 && !gfc_notify_std (GFC_STD_F2003
, "Procedure %qs in "
11673 "PUBLIC interface %qs at %L "
11674 "takes dummy arguments of %qs which "
11675 "is PRIVATE", iface
->sym
->name
,
11676 sym
->name
, &iface
->sym
->declared_at
,
11677 gfc_typename(&arg
->sym
->ts
)))
11679 /* Stop this message from recurring. */
11680 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
11687 if (sym
->attr
.function
&& sym
->value
&& sym
->attr
.proc
!= PROC_ST_FUNCTION
11688 && !sym
->attr
.proc_pointer
)
11690 gfc_error ("Function %qs at %L cannot have an initializer",
11691 sym
->name
, &sym
->declared_at
);
11695 /* An external symbol may not have an initializer because it is taken to be
11696 a procedure. Exception: Procedure Pointers. */
11697 if (sym
->attr
.external
&& sym
->value
&& !sym
->attr
.proc_pointer
)
11699 gfc_error ("External object %qs at %L may not have an initializer",
11700 sym
->name
, &sym
->declared_at
);
11704 /* An elemental function is required to return a scalar 12.7.1 */
11705 if (sym
->attr
.elemental
&& sym
->attr
.function
&& sym
->as
)
11707 gfc_error ("ELEMENTAL function %qs at %L must have a scalar "
11708 "result", sym
->name
, &sym
->declared_at
);
11709 /* Reset so that the error only occurs once. */
11710 sym
->attr
.elemental
= 0;
11714 if (sym
->attr
.proc
== PROC_ST_FUNCTION
11715 && (sym
->attr
.allocatable
|| sym
->attr
.pointer
))
11717 gfc_error ("Statement function %qs at %L may not have pointer or "
11718 "allocatable attribute", sym
->name
, &sym
->declared_at
);
11722 /* 5.1.1.5 of the Standard: A function name declared with an asterisk
11723 char-len-param shall not be array-valued, pointer-valued, recursive
11724 or pure. ....snip... A character value of * may only be used in the
11725 following ways: (i) Dummy arg of procedure - dummy associates with
11726 actual length; (ii) To declare a named constant; or (iii) External
11727 function - but length must be declared in calling scoping unit. */
11728 if (sym
->attr
.function
11729 && sym
->ts
.type
== BT_CHARACTER
&& !sym
->ts
.deferred
11730 && sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
== NULL
)
11732 if ((sym
->as
&& sym
->as
->rank
) || (sym
->attr
.pointer
)
11733 || (sym
->attr
.recursive
) || (sym
->attr
.pure
))
11735 if (sym
->as
&& sym
->as
->rank
)
11736 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11737 "array-valued", sym
->name
, &sym
->declared_at
);
11739 if (sym
->attr
.pointer
)
11740 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11741 "pointer-valued", sym
->name
, &sym
->declared_at
);
11743 if (sym
->attr
.pure
)
11744 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11745 "pure", sym
->name
, &sym
->declared_at
);
11747 if (sym
->attr
.recursive
)
11748 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11749 "recursive", sym
->name
, &sym
->declared_at
);
11754 /* Appendix B.2 of the standard. Contained functions give an
11755 error anyway. Deferred character length is an F2003 feature.
11756 Don't warn on intrinsic conversion functions, which start
11757 with two underscores. */
11758 if (!sym
->attr
.contained
&& !sym
->ts
.deferred
11759 && (sym
->name
[0] != '_' || sym
->name
[1] != '_'))
11760 gfc_notify_std (GFC_STD_F95_OBS
,
11761 "CHARACTER(*) function %qs at %L",
11762 sym
->name
, &sym
->declared_at
);
11765 /* F2008, C1218. */
11766 if (sym
->attr
.elemental
)
11768 if (sym
->attr
.proc_pointer
)
11770 gfc_error ("Procedure pointer %qs at %L shall not be elemental",
11771 sym
->name
, &sym
->declared_at
);
11774 if (sym
->attr
.dummy
)
11776 gfc_error ("Dummy procedure %qs at %L shall not be elemental",
11777 sym
->name
, &sym
->declared_at
);
11782 if (sym
->attr
.is_bind_c
&& sym
->attr
.is_c_interop
!= 1)
11784 gfc_formal_arglist
*curr_arg
;
11785 int has_non_interop_arg
= 0;
11787 if (!verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
11788 sym
->common_block
))
11790 /* Clear these to prevent looking at them again if there was an
11792 sym
->attr
.is_bind_c
= 0;
11793 sym
->attr
.is_c_interop
= 0;
11794 sym
->ts
.is_c_interop
= 0;
11798 /* So far, no errors have been found. */
11799 sym
->attr
.is_c_interop
= 1;
11800 sym
->ts
.is_c_interop
= 1;
11803 curr_arg
= gfc_sym_get_dummy_args (sym
);
11804 while (curr_arg
!= NULL
)
11806 /* Skip implicitly typed dummy args here. */
11807 if (curr_arg
->sym
->attr
.implicit_type
== 0)
11808 if (!gfc_verify_c_interop_param (curr_arg
->sym
))
11809 /* If something is found to fail, record the fact so we
11810 can mark the symbol for the procedure as not being
11811 BIND(C) to try and prevent multiple errors being
11813 has_non_interop_arg
= 1;
11815 curr_arg
= curr_arg
->next
;
11818 /* See if any of the arguments were not interoperable and if so, clear
11819 the procedure symbol to prevent duplicate error messages. */
11820 if (has_non_interop_arg
!= 0)
11822 sym
->attr
.is_c_interop
= 0;
11823 sym
->ts
.is_c_interop
= 0;
11824 sym
->attr
.is_bind_c
= 0;
11828 if (!sym
->attr
.proc_pointer
)
11830 if (sym
->attr
.save
== SAVE_EXPLICIT
)
11832 gfc_error ("PROCEDURE attribute conflicts with SAVE attribute "
11833 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11836 if (sym
->attr
.intent
)
11838 gfc_error ("PROCEDURE attribute conflicts with INTENT attribute "
11839 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11842 if (sym
->attr
.subroutine
&& sym
->attr
.result
)
11844 gfc_error ("PROCEDURE attribute conflicts with RESULT attribute "
11845 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11848 if (sym
->attr
.external
&& sym
->attr
.function
11849 && ((sym
->attr
.if_source
== IFSRC_DECL
&& !sym
->attr
.procedure
)
11850 || sym
->attr
.contained
))
11852 gfc_error ("EXTERNAL attribute conflicts with FUNCTION attribute "
11853 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11856 if (strcmp ("ppr@", sym
->name
) == 0)
11858 gfc_error ("Procedure pointer result %qs at %L "
11859 "is missing the pointer attribute",
11860 sym
->ns
->proc_name
->name
, &sym
->declared_at
);
11865 /* Assume that a procedure whose body is not known has references
11866 to external arrays. */
11867 if (sym
->attr
.if_source
!= IFSRC_DECL
)
11868 sym
->attr
.array_outer_dependency
= 1;
11870 /* Compare the characteristics of a module procedure with the
11871 interface declaration. Ideally this would be done with
11872 gfc_compare_interfaces but, at present, the formal interface
11873 cannot be copied to the ts.interface. */
11874 if (sym
->attr
.module_procedure
11875 && sym
->attr
.if_source
== IFSRC_DECL
)
11878 char name
[2*GFC_MAX_SYMBOL_LEN
+ 1];
11880 char *submodule_name
;
11881 strcpy (name
, sym
->ns
->proc_name
->name
);
11882 module_name
= strtok (name
, ".");
11883 submodule_name
= strtok (NULL
, ".");
11885 /* Stop the dummy characteristics test from using the interface
11886 symbol instead of 'sym'. */
11887 iface
= sym
->ts
.interface
;
11888 sym
->ts
.interface
= NULL
;
11893 /* Check the procedure characteristics. */
11894 if (sym
->attr
.pure
!= iface
->attr
.pure
)
11896 gfc_error ("Mismatch in PURE attribute between MODULE "
11897 "PROCEDURE at %L and its interface in %s",
11898 &sym
->declared_at
, module_name
);
11902 if (sym
->attr
.elemental
!= iface
->attr
.elemental
)
11904 gfc_error ("Mismatch in ELEMENTAL attribute between MODULE "
11905 "PROCEDURE at %L and its interface in %s",
11906 &sym
->declared_at
, module_name
);
11910 if (sym
->attr
.recursive
!= iface
->attr
.recursive
)
11912 gfc_error ("Mismatch in RECURSIVE attribute between MODULE "
11913 "PROCEDURE at %L and its interface in %s",
11914 &sym
->declared_at
, module_name
);
11918 /* Check the result characteristics. */
11919 if (!gfc_check_result_characteristics (sym
, iface
, errmsg
, 200))
11921 gfc_error ("%s between the MODULE PROCEDURE declaration "
11922 "in module %s and the declaration at %L in "
11923 "SUBMODULE %s", errmsg
, module_name
,
11924 &sym
->declared_at
, submodule_name
);
11929 /* Check the charcateristics of the formal arguments. */
11930 if (sym
->formal
&& sym
->formal_ns
)
11932 for (arg
= sym
->formal
; arg
&& arg
->sym
; arg
= arg
->next
)
11935 gfc_traverse_ns (sym
->formal_ns
, compare_fsyms
);
11939 sym
->ts
.interface
= iface
;
11945 /* Resolve a list of finalizer procedures. That is, after they have hopefully
11946 been defined and we now know their defined arguments, check that they fulfill
11947 the requirements of the standard for procedures used as finalizers. */
11950 gfc_resolve_finalizers (gfc_symbol
* derived
, bool *finalizable
)
11952 gfc_finalizer
* list
;
11953 gfc_finalizer
** prev_link
; /* For removing wrong entries from the list. */
11954 bool result
= true;
11955 bool seen_scalar
= false;
11958 gfc_symbol
*parent
= gfc_get_derived_super_type (derived
);
11961 gfc_resolve_finalizers (parent
, finalizable
);
11963 /* Return early when not finalizable. Additionally, ensure that derived-type
11964 components have a their finalizables resolved. */
11965 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->finalizers
)
11967 bool has_final
= false;
11968 for (c
= derived
->components
; c
; c
= c
->next
)
11969 if (c
->ts
.type
== BT_DERIVED
11970 && !c
->attr
.pointer
&& !c
->attr
.proc_pointer
&& !c
->attr
.allocatable
)
11972 bool has_final2
= false;
11973 if (!gfc_resolve_finalizers (c
->ts
.u
.derived
, &has_final
))
11974 return false; /* Error. */
11975 has_final
= has_final
|| has_final2
;
11980 *finalizable
= false;
11985 /* Walk over the list of finalizer-procedures, check them, and if any one
11986 does not fit in with the standard's definition, print an error and remove
11987 it from the list. */
11988 prev_link
= &derived
->f2k_derived
->finalizers
;
11989 for (list
= derived
->f2k_derived
->finalizers
; list
; list
= *prev_link
)
11991 gfc_formal_arglist
*dummy_args
;
11996 /* Skip this finalizer if we already resolved it. */
11997 if (list
->proc_tree
)
11999 prev_link
= &(list
->next
);
12003 /* Check this exists and is a SUBROUTINE. */
12004 if (!list
->proc_sym
->attr
.subroutine
)
12006 gfc_error ("FINAL procedure %qs at %L is not a SUBROUTINE",
12007 list
->proc_sym
->name
, &list
->where
);
12011 /* We should have exactly one argument. */
12012 dummy_args
= gfc_sym_get_dummy_args (list
->proc_sym
);
12013 if (!dummy_args
|| dummy_args
->next
)
12015 gfc_error ("FINAL procedure at %L must have exactly one argument",
12019 arg
= dummy_args
->sym
;
12021 /* This argument must be of our type. */
12022 if (arg
->ts
.type
!= BT_DERIVED
|| arg
->ts
.u
.derived
!= derived
)
12024 gfc_error ("Argument of FINAL procedure at %L must be of type %qs",
12025 &arg
->declared_at
, derived
->name
);
12029 /* It must neither be a pointer nor allocatable nor optional. */
12030 if (arg
->attr
.pointer
)
12032 gfc_error ("Argument of FINAL procedure at %L must not be a POINTER",
12033 &arg
->declared_at
);
12036 if (arg
->attr
.allocatable
)
12038 gfc_error ("Argument of FINAL procedure at %L must not be"
12039 " ALLOCATABLE", &arg
->declared_at
);
12042 if (arg
->attr
.optional
)
12044 gfc_error ("Argument of FINAL procedure at %L must not be OPTIONAL",
12045 &arg
->declared_at
);
12049 /* It must not be INTENT(OUT). */
12050 if (arg
->attr
.intent
== INTENT_OUT
)
12052 gfc_error ("Argument of FINAL procedure at %L must not be"
12053 " INTENT(OUT)", &arg
->declared_at
);
12057 /* Warn if the procedure is non-scalar and not assumed shape. */
12058 if (warn_surprising
&& arg
->as
&& arg
->as
->rank
!= 0
12059 && arg
->as
->type
!= AS_ASSUMED_SHAPE
)
12060 gfc_warning (OPT_Wsurprising
,
12061 "Non-scalar FINAL procedure at %L should have assumed"
12062 " shape argument", &arg
->declared_at
);
12064 /* Check that it does not match in kind and rank with a FINAL procedure
12065 defined earlier. To really loop over the *earlier* declarations,
12066 we need to walk the tail of the list as new ones were pushed at the
12068 /* TODO: Handle kind parameters once they are implemented. */
12069 my_rank
= (arg
->as
? arg
->as
->rank
: 0);
12070 for (i
= list
->next
; i
; i
= i
->next
)
12072 gfc_formal_arglist
*dummy_args
;
12074 /* Argument list might be empty; that is an error signalled earlier,
12075 but we nevertheless continued resolving. */
12076 dummy_args
= gfc_sym_get_dummy_args (i
->proc_sym
);
12079 gfc_symbol
* i_arg
= dummy_args
->sym
;
12080 const int i_rank
= (i_arg
->as
? i_arg
->as
->rank
: 0);
12081 if (i_rank
== my_rank
)
12083 gfc_error ("FINAL procedure %qs declared at %L has the same"
12084 " rank (%d) as %qs",
12085 list
->proc_sym
->name
, &list
->where
, my_rank
,
12086 i
->proc_sym
->name
);
12092 /* Is this the/a scalar finalizer procedure? */
12093 if (!arg
->as
|| arg
->as
->rank
== 0)
12094 seen_scalar
= true;
12096 /* Find the symtree for this procedure. */
12097 gcc_assert (!list
->proc_tree
);
12098 list
->proc_tree
= gfc_find_sym_in_symtree (list
->proc_sym
);
12100 prev_link
= &list
->next
;
12103 /* Remove wrong nodes immediately from the list so we don't risk any
12104 troubles in the future when they might fail later expectations. */
12107 *prev_link
= list
->next
;
12108 gfc_free_finalizer (i
);
12112 if (result
== false)
12115 /* Warn if we haven't seen a scalar finalizer procedure (but we know there
12116 were nodes in the list, must have been for arrays. It is surely a good
12117 idea to have a scalar version there if there's something to finalize. */
12118 if (warn_surprising
&& result
&& !seen_scalar
)
12119 gfc_warning (OPT_Wsurprising
,
12120 "Only array FINAL procedures declared for derived type %qs"
12121 " defined at %L, suggest also scalar one",
12122 derived
->name
, &derived
->declared_at
);
12124 vtab
= gfc_find_derived_vtab (derived
);
12125 c
= vtab
->ts
.u
.derived
->components
->next
->next
->next
->next
->next
;
12126 gfc_set_sym_referenced (c
->initializer
->symtree
->n
.sym
);
12129 *finalizable
= true;
12135 /* Check if two GENERIC targets are ambiguous and emit an error is they are. */
12138 check_generic_tbp_ambiguity (gfc_tbp_generic
* t1
, gfc_tbp_generic
* t2
,
12139 const char* generic_name
, locus where
)
12141 gfc_symbol
*sym1
, *sym2
;
12142 const char *pass1
, *pass2
;
12143 gfc_formal_arglist
*dummy_args
;
12145 gcc_assert (t1
->specific
&& t2
->specific
);
12146 gcc_assert (!t1
->specific
->is_generic
);
12147 gcc_assert (!t2
->specific
->is_generic
);
12148 gcc_assert (t1
->is_operator
== t2
->is_operator
);
12150 sym1
= t1
->specific
->u
.specific
->n
.sym
;
12151 sym2
= t2
->specific
->u
.specific
->n
.sym
;
12156 /* Both must be SUBROUTINEs or both must be FUNCTIONs. */
12157 if (sym1
->attr
.subroutine
!= sym2
->attr
.subroutine
12158 || sym1
->attr
.function
!= sym2
->attr
.function
)
12160 gfc_error ("%qs and %qs can't be mixed FUNCTION/SUBROUTINE for"
12161 " GENERIC %qs at %L",
12162 sym1
->name
, sym2
->name
, generic_name
, &where
);
12166 /* Determine PASS arguments. */
12167 if (t1
->specific
->nopass
)
12169 else if (t1
->specific
->pass_arg
)
12170 pass1
= t1
->specific
->pass_arg
;
12173 dummy_args
= gfc_sym_get_dummy_args (t1
->specific
->u
.specific
->n
.sym
);
12175 pass1
= dummy_args
->sym
->name
;
12179 if (t2
->specific
->nopass
)
12181 else if (t2
->specific
->pass_arg
)
12182 pass2
= t2
->specific
->pass_arg
;
12185 dummy_args
= gfc_sym_get_dummy_args (t2
->specific
->u
.specific
->n
.sym
);
12187 pass2
= dummy_args
->sym
->name
;
12192 /* Compare the interfaces. */
12193 if (gfc_compare_interfaces (sym1
, sym2
, sym2
->name
, !t1
->is_operator
, 0,
12194 NULL
, 0, pass1
, pass2
))
12196 gfc_error ("%qs and %qs for GENERIC %qs at %L are ambiguous",
12197 sym1
->name
, sym2
->name
, generic_name
, &where
);
12205 /* Worker function for resolving a generic procedure binding; this is used to
12206 resolve GENERIC as well as user and intrinsic OPERATOR typebound procedures.
12208 The difference between those cases is finding possible inherited bindings
12209 that are overridden, as one has to look for them in tb_sym_root,
12210 tb_uop_root or tb_op, respectively. Thus the caller must already find
12211 the super-type and set p->overridden correctly. */
12214 resolve_tb_generic_targets (gfc_symbol
* super_type
,
12215 gfc_typebound_proc
* p
, const char* name
)
12217 gfc_tbp_generic
* target
;
12218 gfc_symtree
* first_target
;
12219 gfc_symtree
* inherited
;
12221 gcc_assert (p
&& p
->is_generic
);
12223 /* Try to find the specific bindings for the symtrees in our target-list. */
12224 gcc_assert (p
->u
.generic
);
12225 for (target
= p
->u
.generic
; target
; target
= target
->next
)
12226 if (!target
->specific
)
12228 gfc_typebound_proc
* overridden_tbp
;
12229 gfc_tbp_generic
* g
;
12230 const char* target_name
;
12232 target_name
= target
->specific_st
->name
;
12234 /* Defined for this type directly. */
12235 if (target
->specific_st
->n
.tb
&& !target
->specific_st
->n
.tb
->error
)
12237 target
->specific
= target
->specific_st
->n
.tb
;
12238 goto specific_found
;
12241 /* Look for an inherited specific binding. */
12244 inherited
= gfc_find_typebound_proc (super_type
, NULL
, target_name
,
12249 gcc_assert (inherited
->n
.tb
);
12250 target
->specific
= inherited
->n
.tb
;
12251 goto specific_found
;
12255 gfc_error ("Undefined specific binding %qs as target of GENERIC %qs"
12256 " at %L", target_name
, name
, &p
->where
);
12259 /* Once we've found the specific binding, check it is not ambiguous with
12260 other specifics already found or inherited for the same GENERIC. */
12262 gcc_assert (target
->specific
);
12264 /* This must really be a specific binding! */
12265 if (target
->specific
->is_generic
)
12267 gfc_error ("GENERIC %qs at %L must target a specific binding,"
12268 " %qs is GENERIC, too", name
, &p
->where
, target_name
);
12272 /* Check those already resolved on this type directly. */
12273 for (g
= p
->u
.generic
; g
; g
= g
->next
)
12274 if (g
!= target
&& g
->specific
12275 && !check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
12278 /* Check for ambiguity with inherited specific targets. */
12279 for (overridden_tbp
= p
->overridden
; overridden_tbp
;
12280 overridden_tbp
= overridden_tbp
->overridden
)
12281 if (overridden_tbp
->is_generic
)
12283 for (g
= overridden_tbp
->u
.generic
; g
; g
= g
->next
)
12285 gcc_assert (g
->specific
);
12286 if (!check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
12292 /* If we attempt to "overwrite" a specific binding, this is an error. */
12293 if (p
->overridden
&& !p
->overridden
->is_generic
)
12295 gfc_error ("GENERIC %qs at %L can't overwrite specific binding with"
12296 " the same name", name
, &p
->where
);
12300 /* Take the SUBROUTINE/FUNCTION attributes of the first specific target, as
12301 all must have the same attributes here. */
12302 first_target
= p
->u
.generic
->specific
->u
.specific
;
12303 gcc_assert (first_target
);
12304 p
->subroutine
= first_target
->n
.sym
->attr
.subroutine
;
12305 p
->function
= first_target
->n
.sym
->attr
.function
;
12311 /* Resolve a GENERIC procedure binding for a derived type. */
12314 resolve_typebound_generic (gfc_symbol
* derived
, gfc_symtree
* st
)
12316 gfc_symbol
* super_type
;
12318 /* Find the overridden binding if any. */
12319 st
->n
.tb
->overridden
= NULL
;
12320 super_type
= gfc_get_derived_super_type (derived
);
12323 gfc_symtree
* overridden
;
12324 overridden
= gfc_find_typebound_proc (super_type
, NULL
, st
->name
,
12327 if (overridden
&& overridden
->n
.tb
)
12328 st
->n
.tb
->overridden
= overridden
->n
.tb
;
12331 /* Resolve using worker function. */
12332 return resolve_tb_generic_targets (super_type
, st
->n
.tb
, st
->name
);
12336 /* Retrieve the target-procedure of an operator binding and do some checks in
12337 common for intrinsic and user-defined type-bound operators. */
12340 get_checked_tb_operator_target (gfc_tbp_generic
* target
, locus where
)
12342 gfc_symbol
* target_proc
;
12344 gcc_assert (target
->specific
&& !target
->specific
->is_generic
);
12345 target_proc
= target
->specific
->u
.specific
->n
.sym
;
12346 gcc_assert (target_proc
);
12348 /* F08:C468. All operator bindings must have a passed-object dummy argument. */
12349 if (target
->specific
->nopass
)
12351 gfc_error ("Type-bound operator at %L can't be NOPASS", &where
);
12355 return target_proc
;
12359 /* Resolve a type-bound intrinsic operator. */
12362 resolve_typebound_intrinsic_op (gfc_symbol
* derived
, gfc_intrinsic_op op
,
12363 gfc_typebound_proc
* p
)
12365 gfc_symbol
* super_type
;
12366 gfc_tbp_generic
* target
;
12368 /* If there's already an error here, do nothing (but don't fail again). */
12372 /* Operators should always be GENERIC bindings. */
12373 gcc_assert (p
->is_generic
);
12375 /* Look for an overridden binding. */
12376 super_type
= gfc_get_derived_super_type (derived
);
12377 if (super_type
&& super_type
->f2k_derived
)
12378 p
->overridden
= gfc_find_typebound_intrinsic_op (super_type
, NULL
,
12381 p
->overridden
= NULL
;
12383 /* Resolve general GENERIC properties using worker function. */
12384 if (!resolve_tb_generic_targets (super_type
, p
, gfc_op2string(op
)))
12387 /* Check the targets to be procedures of correct interface. */
12388 for (target
= p
->u
.generic
; target
; target
= target
->next
)
12390 gfc_symbol
* target_proc
;
12392 target_proc
= get_checked_tb_operator_target (target
, p
->where
);
12396 if (!gfc_check_operator_interface (target_proc
, op
, p
->where
))
12399 /* Add target to non-typebound operator list. */
12400 if (!target
->specific
->deferred
&& !derived
->attr
.use_assoc
12401 && p
->access
!= ACCESS_PRIVATE
&& derived
->ns
== gfc_current_ns
)
12403 gfc_interface
*head
, *intr
;
12404 if (!gfc_check_new_interface (derived
->ns
->op
[op
], target_proc
, p
->where
))
12406 head
= derived
->ns
->op
[op
];
12407 intr
= gfc_get_interface ();
12408 intr
->sym
= target_proc
;
12409 intr
->where
= p
->where
;
12411 derived
->ns
->op
[op
] = intr
;
12423 /* Resolve a type-bound user operator (tree-walker callback). */
12425 static gfc_symbol
* resolve_bindings_derived
;
12426 static bool resolve_bindings_result
;
12428 static bool check_uop_procedure (gfc_symbol
* sym
, locus where
);
12431 resolve_typebound_user_op (gfc_symtree
* stree
)
12433 gfc_symbol
* super_type
;
12434 gfc_tbp_generic
* target
;
12436 gcc_assert (stree
&& stree
->n
.tb
);
12438 if (stree
->n
.tb
->error
)
12441 /* Operators should always be GENERIC bindings. */
12442 gcc_assert (stree
->n
.tb
->is_generic
);
12444 /* Find overridden procedure, if any. */
12445 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
12446 if (super_type
&& super_type
->f2k_derived
)
12448 gfc_symtree
* overridden
;
12449 overridden
= gfc_find_typebound_user_op (super_type
, NULL
,
12450 stree
->name
, true, NULL
);
12452 if (overridden
&& overridden
->n
.tb
)
12453 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
12456 stree
->n
.tb
->overridden
= NULL
;
12458 /* Resolve basically using worker function. */
12459 if (!resolve_tb_generic_targets (super_type
, stree
->n
.tb
, stree
->name
))
12462 /* Check the targets to be functions of correct interface. */
12463 for (target
= stree
->n
.tb
->u
.generic
; target
; target
= target
->next
)
12465 gfc_symbol
* target_proc
;
12467 target_proc
= get_checked_tb_operator_target (target
, stree
->n
.tb
->where
);
12471 if (!check_uop_procedure (target_proc
, stree
->n
.tb
->where
))
12478 resolve_bindings_result
= false;
12479 stree
->n
.tb
->error
= 1;
12483 /* Resolve the type-bound procedures for a derived type. */
12486 resolve_typebound_procedure (gfc_symtree
* stree
)
12490 gfc_symbol
* me_arg
;
12491 gfc_symbol
* super_type
;
12492 gfc_component
* comp
;
12494 gcc_assert (stree
);
12496 /* Undefined specific symbol from GENERIC target definition. */
12500 if (stree
->n
.tb
->error
)
12503 /* If this is a GENERIC binding, use that routine. */
12504 if (stree
->n
.tb
->is_generic
)
12506 if (!resolve_typebound_generic (resolve_bindings_derived
, stree
))
12511 /* Get the target-procedure to check it. */
12512 gcc_assert (!stree
->n
.tb
->is_generic
);
12513 gcc_assert (stree
->n
.tb
->u
.specific
);
12514 proc
= stree
->n
.tb
->u
.specific
->n
.sym
;
12515 where
= stree
->n
.tb
->where
;
12517 /* Default access should already be resolved from the parser. */
12518 gcc_assert (stree
->n
.tb
->access
!= ACCESS_UNKNOWN
);
12520 if (stree
->n
.tb
->deferred
)
12522 if (!check_proc_interface (proc
, &where
))
12527 /* Check for F08:C465. */
12528 if ((!proc
->attr
.subroutine
&& !proc
->attr
.function
)
12529 || (proc
->attr
.proc
!= PROC_MODULE
12530 && proc
->attr
.if_source
!= IFSRC_IFBODY
)
12531 || proc
->attr
.abstract
)
12533 gfc_error ("%qs must be a module procedure or an external procedure with"
12534 " an explicit interface at %L", proc
->name
, &where
);
12539 stree
->n
.tb
->subroutine
= proc
->attr
.subroutine
;
12540 stree
->n
.tb
->function
= proc
->attr
.function
;
12542 /* Find the super-type of the current derived type. We could do this once and
12543 store in a global if speed is needed, but as long as not I believe this is
12544 more readable and clearer. */
12545 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
12547 /* If PASS, resolve and check arguments if not already resolved / loaded
12548 from a .mod file. */
12549 if (!stree
->n
.tb
->nopass
&& stree
->n
.tb
->pass_arg_num
== 0)
12551 gfc_formal_arglist
*dummy_args
;
12553 dummy_args
= gfc_sym_get_dummy_args (proc
);
12554 if (stree
->n
.tb
->pass_arg
)
12556 gfc_formal_arglist
*i
;
12558 /* If an explicit passing argument name is given, walk the arg-list
12559 and look for it. */
12562 stree
->n
.tb
->pass_arg_num
= 1;
12563 for (i
= dummy_args
; i
; i
= i
->next
)
12565 if (!strcmp (i
->sym
->name
, stree
->n
.tb
->pass_arg
))
12570 ++stree
->n
.tb
->pass_arg_num
;
12575 gfc_error ("Procedure %qs with PASS(%s) at %L has no"
12577 proc
->name
, stree
->n
.tb
->pass_arg
, &where
,
12578 stree
->n
.tb
->pass_arg
);
12584 /* Otherwise, take the first one; there should in fact be at least
12586 stree
->n
.tb
->pass_arg_num
= 1;
12589 gfc_error ("Procedure %qs with PASS at %L must have at"
12590 " least one argument", proc
->name
, &where
);
12593 me_arg
= dummy_args
->sym
;
12596 /* Now check that the argument-type matches and the passed-object
12597 dummy argument is generally fine. */
12599 gcc_assert (me_arg
);
12601 if (me_arg
->ts
.type
!= BT_CLASS
)
12603 gfc_error ("Non-polymorphic passed-object dummy argument of %qs"
12604 " at %L", proc
->name
, &where
);
12608 if (CLASS_DATA (me_arg
)->ts
.u
.derived
12609 != resolve_bindings_derived
)
12611 gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of"
12612 " the derived-type %qs", me_arg
->name
, proc
->name
,
12613 me_arg
->name
, &where
, resolve_bindings_derived
->name
);
12617 gcc_assert (me_arg
->ts
.type
== BT_CLASS
);
12618 if (CLASS_DATA (me_arg
)->as
&& CLASS_DATA (me_arg
)->as
->rank
!= 0)
12620 gfc_error ("Passed-object dummy argument of %qs at %L must be"
12621 " scalar", proc
->name
, &where
);
12624 if (CLASS_DATA (me_arg
)->attr
.allocatable
)
12626 gfc_error ("Passed-object dummy argument of %qs at %L must not"
12627 " be ALLOCATABLE", proc
->name
, &where
);
12630 if (CLASS_DATA (me_arg
)->attr
.class_pointer
)
12632 gfc_error ("Passed-object dummy argument of %qs at %L must not"
12633 " be POINTER", proc
->name
, &where
);
12638 /* If we are extending some type, check that we don't override a procedure
12639 flagged NON_OVERRIDABLE. */
12640 stree
->n
.tb
->overridden
= NULL
;
12643 gfc_symtree
* overridden
;
12644 overridden
= gfc_find_typebound_proc (super_type
, NULL
,
12645 stree
->name
, true, NULL
);
12649 if (overridden
->n
.tb
)
12650 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
12652 if (!gfc_check_typebound_override (stree
, overridden
))
12657 /* See if there's a name collision with a component directly in this type. */
12658 for (comp
= resolve_bindings_derived
->components
; comp
; comp
= comp
->next
)
12659 if (!strcmp (comp
->name
, stree
->name
))
12661 gfc_error ("Procedure %qs at %L has the same name as a component of"
12663 stree
->name
, &where
, resolve_bindings_derived
->name
);
12667 /* Try to find a name collision with an inherited component. */
12668 if (super_type
&& gfc_find_component (super_type
, stree
->name
, true, true))
12670 gfc_error ("Procedure %qs at %L has the same name as an inherited"
12671 " component of %qs",
12672 stree
->name
, &where
, resolve_bindings_derived
->name
);
12676 stree
->n
.tb
->error
= 0;
12680 resolve_bindings_result
= false;
12681 stree
->n
.tb
->error
= 1;
12686 resolve_typebound_procedures (gfc_symbol
* derived
)
12689 gfc_symbol
* super_type
;
12691 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->tb_sym_root
)
12694 super_type
= gfc_get_derived_super_type (derived
);
12696 resolve_symbol (super_type
);
12698 resolve_bindings_derived
= derived
;
12699 resolve_bindings_result
= true;
12701 if (derived
->f2k_derived
->tb_sym_root
)
12702 gfc_traverse_symtree (derived
->f2k_derived
->tb_sym_root
,
12703 &resolve_typebound_procedure
);
12705 if (derived
->f2k_derived
->tb_uop_root
)
12706 gfc_traverse_symtree (derived
->f2k_derived
->tb_uop_root
,
12707 &resolve_typebound_user_op
);
12709 for (op
= 0; op
!= GFC_INTRINSIC_OPS
; ++op
)
12711 gfc_typebound_proc
* p
= derived
->f2k_derived
->tb_op
[op
];
12712 if (p
&& !resolve_typebound_intrinsic_op (derived
,
12713 (gfc_intrinsic_op
)op
, p
))
12714 resolve_bindings_result
= false;
12717 return resolve_bindings_result
;
12721 /* Add a derived type to the dt_list. The dt_list is used in trans-types.c
12722 to give all identical derived types the same backend_decl. */
12724 add_dt_to_dt_list (gfc_symbol
*derived
)
12726 gfc_dt_list
*dt_list
;
12728 for (dt_list
= gfc_derived_types
; dt_list
; dt_list
= dt_list
->next
)
12729 if (derived
== dt_list
->derived
)
12732 dt_list
= gfc_get_dt_list ();
12733 dt_list
->next
= gfc_derived_types
;
12734 dt_list
->derived
= derived
;
12735 gfc_derived_types
= dt_list
;
12739 /* Ensure that a derived-type is really not abstract, meaning that every
12740 inherited DEFERRED binding is overridden by a non-DEFERRED one. */
12743 ensure_not_abstract_walker (gfc_symbol
* sub
, gfc_symtree
* st
)
12748 if (!ensure_not_abstract_walker (sub
, st
->left
))
12750 if (!ensure_not_abstract_walker (sub
, st
->right
))
12753 if (st
->n
.tb
&& st
->n
.tb
->deferred
)
12755 gfc_symtree
* overriding
;
12756 overriding
= gfc_find_typebound_proc (sub
, NULL
, st
->name
, true, NULL
);
12759 gcc_assert (overriding
->n
.tb
);
12760 if (overriding
->n
.tb
->deferred
)
12762 gfc_error ("Derived-type %qs declared at %L must be ABSTRACT because"
12763 " %qs is DEFERRED and not overridden",
12764 sub
->name
, &sub
->declared_at
, st
->name
);
12773 ensure_not_abstract (gfc_symbol
* sub
, gfc_symbol
* ancestor
)
12775 /* The algorithm used here is to recursively travel up the ancestry of sub
12776 and for each ancestor-type, check all bindings. If any of them is
12777 DEFERRED, look it up starting from sub and see if the found (overriding)
12778 binding is not DEFERRED.
12779 This is not the most efficient way to do this, but it should be ok and is
12780 clearer than something sophisticated. */
12782 gcc_assert (ancestor
&& !sub
->attr
.abstract
);
12784 if (!ancestor
->attr
.abstract
)
12787 /* Walk bindings of this ancestor. */
12788 if (ancestor
->f2k_derived
)
12791 t
= ensure_not_abstract_walker (sub
, ancestor
->f2k_derived
->tb_sym_root
);
12796 /* Find next ancestor type and recurse on it. */
12797 ancestor
= gfc_get_derived_super_type (ancestor
);
12799 return ensure_not_abstract (sub
, ancestor
);
12805 /* This check for typebound defined assignments is done recursively
12806 since the order in which derived types are resolved is not always in
12807 order of the declarations. */
12810 check_defined_assignments (gfc_symbol
*derived
)
12814 for (c
= derived
->components
; c
; c
= c
->next
)
12816 if (c
->ts
.type
!= BT_DERIVED
12818 || c
->attr
.allocatable
12819 || c
->attr
.proc_pointer_comp
12820 || c
->attr
.class_pointer
12821 || c
->attr
.proc_pointer
)
12824 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
12825 || (c
->ts
.u
.derived
->f2k_derived
12826 && c
->ts
.u
.derived
->f2k_derived
->tb_op
[INTRINSIC_ASSIGN
]))
12828 derived
->attr
.defined_assign_comp
= 1;
12832 check_defined_assignments (c
->ts
.u
.derived
);
12833 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
12835 derived
->attr
.defined_assign_comp
= 1;
12842 /* Resolve the components of a derived type. This does not have to wait until
12843 resolution stage, but can be done as soon as the dt declaration has been
12847 resolve_fl_derived0 (gfc_symbol
*sym
)
12849 gfc_symbol
* super_type
;
12852 if (sym
->attr
.unlimited_polymorphic
)
12855 super_type
= gfc_get_derived_super_type (sym
);
12858 if (super_type
&& sym
->attr
.coarray_comp
&& !super_type
->attr
.coarray_comp
)
12860 gfc_error ("As extending type %qs at %L has a coarray component, "
12861 "parent type %qs shall also have one", sym
->name
,
12862 &sym
->declared_at
, super_type
->name
);
12866 /* Ensure the extended type gets resolved before we do. */
12867 if (super_type
&& !resolve_fl_derived0 (super_type
))
12870 /* An ABSTRACT type must be extensible. */
12871 if (sym
->attr
.abstract
&& !gfc_type_is_extensible (sym
))
12873 gfc_error ("Non-extensible derived-type %qs at %L must not be ABSTRACT",
12874 sym
->name
, &sym
->declared_at
);
12878 c
= (sym
->attr
.is_class
) ? sym
->components
->ts
.u
.derived
->components
12881 bool success
= true;
12883 for ( ; c
!= NULL
; c
= c
->next
)
12885 if (c
->attr
.artificial
)
12889 if ((!sym
->attr
.is_class
|| c
!= sym
->components
)
12890 && c
->attr
.codimension
12891 && (!c
->attr
.allocatable
|| (c
->as
&& c
->as
->type
!= AS_DEFERRED
)))
12893 gfc_error ("Coarray component %qs at %L must be allocatable with "
12894 "deferred shape", c
->name
, &c
->loc
);
12900 if (c
->attr
.codimension
&& c
->ts
.type
== BT_DERIVED
12901 && c
->ts
.u
.derived
->ts
.is_iso_c
)
12903 gfc_error ("Component %qs at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
12904 "shall not be a coarray", c
->name
, &c
->loc
);
12910 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
12911 && (c
->attr
.codimension
|| c
->attr
.pointer
|| c
->attr
.dimension
12912 || c
->attr
.allocatable
))
12914 gfc_error ("Component %qs at %L with coarray component "
12915 "shall be a nonpointer, nonallocatable scalar",
12922 if (c
->attr
.contiguous
&& (!c
->attr
.dimension
|| !c
->attr
.pointer
))
12924 gfc_error ("Component %qs at %L has the CONTIGUOUS attribute but "
12925 "is not an array pointer", c
->name
, &c
->loc
);
12930 if (c
->attr
.proc_pointer
&& c
->ts
.interface
)
12932 gfc_symbol
*ifc
= c
->ts
.interface
;
12934 if (!sym
->attr
.vtype
&& !check_proc_interface (ifc
, &c
->loc
))
12941 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
12943 /* Resolve interface and copy attributes. */
12944 if (ifc
->formal
&& !ifc
->formal_ns
)
12945 resolve_symbol (ifc
);
12946 if (ifc
->attr
.intrinsic
)
12947 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
12951 c
->ts
= ifc
->result
->ts
;
12952 c
->attr
.allocatable
= ifc
->result
->attr
.allocatable
;
12953 c
->attr
.pointer
= ifc
->result
->attr
.pointer
;
12954 c
->attr
.dimension
= ifc
->result
->attr
.dimension
;
12955 c
->as
= gfc_copy_array_spec (ifc
->result
->as
);
12956 c
->attr
.class_ok
= ifc
->result
->attr
.class_ok
;
12961 c
->attr
.allocatable
= ifc
->attr
.allocatable
;
12962 c
->attr
.pointer
= ifc
->attr
.pointer
;
12963 c
->attr
.dimension
= ifc
->attr
.dimension
;
12964 c
->as
= gfc_copy_array_spec (ifc
->as
);
12965 c
->attr
.class_ok
= ifc
->attr
.class_ok
;
12967 c
->ts
.interface
= ifc
;
12968 c
->attr
.function
= ifc
->attr
.function
;
12969 c
->attr
.subroutine
= ifc
->attr
.subroutine
;
12971 c
->attr
.pure
= ifc
->attr
.pure
;
12972 c
->attr
.elemental
= ifc
->attr
.elemental
;
12973 c
->attr
.recursive
= ifc
->attr
.recursive
;
12974 c
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
12975 c
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
12976 /* Copy char length. */
12977 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
12979 gfc_charlen
*cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
12980 if (cl
->length
&& !cl
->resolved
12981 && !gfc_resolve_expr (cl
->length
))
12991 else if (c
->attr
.proc_pointer
&& c
->ts
.type
== BT_UNKNOWN
)
12993 /* Since PPCs are not implicitly typed, a PPC without an explicit
12994 interface must be a subroutine. */
12995 gfc_add_subroutine (&c
->attr
, c
->name
, &c
->loc
);
12998 /* Procedure pointer components: Check PASS arg. */
12999 if (c
->attr
.proc_pointer
&& !c
->tb
->nopass
&& c
->tb
->pass_arg_num
== 0
13000 && !sym
->attr
.vtype
)
13002 gfc_symbol
* me_arg
;
13004 if (c
->tb
->pass_arg
)
13006 gfc_formal_arglist
* i
;
13008 /* If an explicit passing argument name is given, walk the arg-list
13009 and look for it. */
13012 c
->tb
->pass_arg_num
= 1;
13013 for (i
= c
->ts
.interface
->formal
; i
; i
= i
->next
)
13015 if (!strcmp (i
->sym
->name
, c
->tb
->pass_arg
))
13020 c
->tb
->pass_arg_num
++;
13025 gfc_error ("Procedure pointer component %qs with PASS(%s) "
13026 "at %L has no argument %qs", c
->name
,
13027 c
->tb
->pass_arg
, &c
->loc
, c
->tb
->pass_arg
);
13035 /* Otherwise, take the first one; there should in fact be at least
13037 c
->tb
->pass_arg_num
= 1;
13038 if (!c
->ts
.interface
->formal
)
13040 gfc_error ("Procedure pointer component %qs with PASS at %L "
13041 "must have at least one argument",
13047 me_arg
= c
->ts
.interface
->formal
->sym
;
13050 /* Now check that the argument-type matches. */
13051 gcc_assert (me_arg
);
13052 if ((me_arg
->ts
.type
!= BT_DERIVED
&& me_arg
->ts
.type
!= BT_CLASS
)
13053 || (me_arg
->ts
.type
== BT_DERIVED
&& me_arg
->ts
.u
.derived
!= sym
)
13054 || (me_arg
->ts
.type
== BT_CLASS
13055 && CLASS_DATA (me_arg
)->ts
.u
.derived
!= sym
))
13057 gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of"
13058 " the derived type %qs", me_arg
->name
, c
->name
,
13059 me_arg
->name
, &c
->loc
, sym
->name
);
13065 /* Check for C453. */
13066 if (me_arg
->attr
.dimension
)
13068 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
13069 "must be scalar", me_arg
->name
, c
->name
, me_arg
->name
,
13076 if (me_arg
->attr
.pointer
)
13078 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
13079 "may not have the POINTER attribute", me_arg
->name
,
13080 c
->name
, me_arg
->name
, &c
->loc
);
13086 if (me_arg
->attr
.allocatable
)
13088 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
13089 "may not be ALLOCATABLE", me_arg
->name
, c
->name
,
13090 me_arg
->name
, &c
->loc
);
13096 if (gfc_type_is_extensible (sym
) && me_arg
->ts
.type
!= BT_CLASS
)
13098 gfc_error ("Non-polymorphic passed-object dummy argument of %qs"
13099 " at %L", c
->name
, &c
->loc
);
13106 /* Check type-spec if this is not the parent-type component. */
13107 if (((sym
->attr
.is_class
13108 && (!sym
->components
->ts
.u
.derived
->attr
.extension
13109 || c
!= sym
->components
->ts
.u
.derived
->components
))
13110 || (!sym
->attr
.is_class
13111 && (!sym
->attr
.extension
|| c
!= sym
->components
)))
13112 && !sym
->attr
.vtype
13113 && !resolve_typespec_used (&c
->ts
, &c
->loc
, c
->name
))
13116 /* If this type is an extension, set the accessibility of the parent
13119 && ((sym
->attr
.is_class
13120 && c
== sym
->components
->ts
.u
.derived
->components
)
13121 || (!sym
->attr
.is_class
&& c
== sym
->components
))
13122 && strcmp (super_type
->name
, c
->name
) == 0)
13123 c
->attr
.access
= super_type
->attr
.access
;
13125 /* If this type is an extension, see if this component has the same name
13126 as an inherited type-bound procedure. */
13127 if (super_type
&& !sym
->attr
.is_class
13128 && gfc_find_typebound_proc (super_type
, NULL
, c
->name
, true, NULL
))
13130 gfc_error ("Component %qs of %qs at %L has the same name as an"
13131 " inherited type-bound procedure",
13132 c
->name
, sym
->name
, &c
->loc
);
13136 if (c
->ts
.type
== BT_CHARACTER
&& !c
->attr
.proc_pointer
13137 && !c
->ts
.deferred
)
13139 if (c
->ts
.u
.cl
->length
== NULL
13140 || (!resolve_charlen(c
->ts
.u
.cl
))
13141 || !gfc_is_constant_expr (c
->ts
.u
.cl
->length
))
13143 gfc_error ("Character length of component %qs needs to "
13144 "be a constant specification expression at %L",
13146 c
->ts
.u
.cl
->length
? &c
->ts
.u
.cl
->length
->where
: &c
->loc
);
13151 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
13152 && !c
->attr
.pointer
&& !c
->attr
.allocatable
)
13154 gfc_error ("Character component %qs of %qs at %L with deferred "
13155 "length must be a POINTER or ALLOCATABLE",
13156 c
->name
, sym
->name
, &c
->loc
);
13160 /* Add the hidden deferred length field. */
13161 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
&& !c
->attr
.function
13162 && !sym
->attr
.is_class
)
13164 char name
[GFC_MAX_SYMBOL_LEN
+9];
13165 gfc_component
*strlen
;
13166 sprintf (name
, "_%s_length", c
->name
);
13167 strlen
= gfc_find_component (sym
, name
, true, true);
13168 if (strlen
== NULL
)
13170 if (!gfc_add_component (sym
, name
, &strlen
))
13172 strlen
->ts
.type
= BT_INTEGER
;
13173 strlen
->ts
.kind
= gfc_charlen_int_kind
;
13174 strlen
->attr
.access
= ACCESS_PRIVATE
;
13175 strlen
->attr
.artificial
= 1;
13179 if (c
->ts
.type
== BT_DERIVED
13180 && sym
->component_access
!= ACCESS_PRIVATE
13181 && gfc_check_symbol_access (sym
)
13182 && !is_sym_host_assoc (c
->ts
.u
.derived
, sym
->ns
)
13183 && !c
->ts
.u
.derived
->attr
.use_assoc
13184 && !gfc_check_symbol_access (c
->ts
.u
.derived
)
13185 && !gfc_notify_std (GFC_STD_F2003
, "the component %qs is a "
13186 "PRIVATE type and cannot be a component of "
13187 "%qs, which is PUBLIC at %L", c
->name
,
13188 sym
->name
, &sym
->declared_at
))
13191 if ((sym
->attr
.sequence
|| sym
->attr
.is_bind_c
) && c
->ts
.type
== BT_CLASS
)
13193 gfc_error ("Polymorphic component %s at %L in SEQUENCE or BIND(C) "
13194 "type %s", c
->name
, &c
->loc
, sym
->name
);
13198 if (sym
->attr
.sequence
)
13200 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.sequence
== 0)
13202 gfc_error ("Component %s of SEQUENCE type declared at %L does "
13203 "not have the SEQUENCE attribute",
13204 c
->ts
.u
.derived
->name
, &sym
->declared_at
);
13209 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.generic
)
13210 c
->ts
.u
.derived
= gfc_find_dt_in_generic (c
->ts
.u
.derived
);
13211 else if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
13212 && CLASS_DATA (c
)->ts
.u
.derived
->attr
.generic
)
13213 CLASS_DATA (c
)->ts
.u
.derived
13214 = gfc_find_dt_in_generic (CLASS_DATA (c
)->ts
.u
.derived
);
13216 if (!sym
->attr
.is_class
&& c
->ts
.type
== BT_DERIVED
&& !sym
->attr
.vtype
13217 && c
->attr
.pointer
&& c
->ts
.u
.derived
->components
== NULL
13218 && !c
->ts
.u
.derived
->attr
.zero_comp
)
13220 gfc_error ("The pointer component %qs of %qs at %L is a type "
13221 "that has not been declared", c
->name
, sym
->name
,
13226 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
13227 && CLASS_DATA (c
)->attr
.class_pointer
13228 && CLASS_DATA (c
)->ts
.u
.derived
->components
== NULL
13229 && !CLASS_DATA (c
)->ts
.u
.derived
->attr
.zero_comp
13230 && !UNLIMITED_POLY (c
))
13232 gfc_error ("The pointer component %qs of %qs at %L is a type "
13233 "that has not been declared", c
->name
, sym
->name
,
13239 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.flavor
!= FL_PROCEDURE
13240 && (!c
->attr
.class_ok
13241 || !(CLASS_DATA (c
)->attr
.class_pointer
13242 || CLASS_DATA (c
)->attr
.allocatable
)))
13244 gfc_error ("Component %qs with CLASS at %L must be allocatable "
13245 "or pointer", c
->name
, &c
->loc
);
13246 /* Prevent a recurrence of the error. */
13247 c
->ts
.type
= BT_UNKNOWN
;
13251 /* Ensure that all the derived type components are put on the
13252 derived type list; even in formal namespaces, where derived type
13253 pointer components might not have been declared. */
13254 if (c
->ts
.type
== BT_DERIVED
13256 && c
->ts
.u
.derived
->components
13258 && sym
!= c
->ts
.u
.derived
)
13259 add_dt_to_dt_list (c
->ts
.u
.derived
);
13261 if (!gfc_resolve_array_spec (c
->as
,
13262 !(c
->attr
.pointer
|| c
->attr
.proc_pointer
13263 || c
->attr
.allocatable
)))
13266 if (c
->initializer
&& !sym
->attr
.vtype
13267 && !gfc_check_assign_symbol (sym
, c
, c
->initializer
))
13274 check_defined_assignments (sym
);
13276 if (!sym
->attr
.defined_assign_comp
&& super_type
)
13277 sym
->attr
.defined_assign_comp
13278 = super_type
->attr
.defined_assign_comp
;
13280 /* If this is a non-ABSTRACT type extending an ABSTRACT one, ensure that
13281 all DEFERRED bindings are overridden. */
13282 if (super_type
&& super_type
->attr
.abstract
&& !sym
->attr
.abstract
13283 && !sym
->attr
.is_class
13284 && !ensure_not_abstract (sym
, super_type
))
13287 /* Add derived type to the derived type list. */
13288 add_dt_to_dt_list (sym
);
13294 /* The following procedure does the full resolution of a derived type,
13295 including resolution of all type-bound procedures (if present). In contrast
13296 to 'resolve_fl_derived0' this can only be done after the module has been
13297 parsed completely. */
13300 resolve_fl_derived (gfc_symbol
*sym
)
13302 gfc_symbol
*gen_dt
= NULL
;
13304 if (sym
->attr
.unlimited_polymorphic
)
13307 if (!sym
->attr
.is_class
)
13308 gfc_find_symbol (sym
->name
, sym
->ns
, 0, &gen_dt
);
13309 if (gen_dt
&& gen_dt
->generic
&& gen_dt
->generic
->next
13310 && (!gen_dt
->generic
->sym
->attr
.use_assoc
13311 || gen_dt
->generic
->sym
->module
!= gen_dt
->generic
->next
->sym
->module
)
13312 && !gfc_notify_std (GFC_STD_F2003
, "Generic name %qs of function "
13313 "%qs at %L being the same name as derived "
13314 "type at %L", sym
->name
,
13315 gen_dt
->generic
->sym
== sym
13316 ? gen_dt
->generic
->next
->sym
->name
13317 : gen_dt
->generic
->sym
->name
,
13318 gen_dt
->generic
->sym
== sym
13319 ? &gen_dt
->generic
->next
->sym
->declared_at
13320 : &gen_dt
->generic
->sym
->declared_at
,
13321 &sym
->declared_at
))
13324 /* Resolve the finalizer procedures. */
13325 if (!gfc_resolve_finalizers (sym
, NULL
))
13328 if (sym
->attr
.is_class
&& sym
->ts
.u
.derived
== NULL
)
13330 /* Fix up incomplete CLASS symbols. */
13331 gfc_component
*data
= gfc_find_component (sym
, "_data", true, true);
13332 gfc_component
*vptr
= gfc_find_component (sym
, "_vptr", true, true);
13334 /* Nothing more to do for unlimited polymorphic entities. */
13335 if (data
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
13337 else if (vptr
->ts
.u
.derived
== NULL
)
13339 gfc_symbol
*vtab
= gfc_find_derived_vtab (data
->ts
.u
.derived
);
13341 vptr
->ts
.u
.derived
= vtab
->ts
.u
.derived
;
13345 if (!resolve_fl_derived0 (sym
))
13348 /* Resolve the type-bound procedures. */
13349 if (!resolve_typebound_procedures (sym
))
13357 resolve_fl_namelist (gfc_symbol
*sym
)
13362 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
13364 /* Check again, the check in match only works if NAMELIST comes
13366 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SIZE
)
13368 gfc_error ("Assumed size array %qs in namelist %qs at %L is not "
13369 "allowed", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13373 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SHAPE
13374 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object %qs "
13375 "with assumed shape in namelist %qs at %L",
13376 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
13379 if (is_non_constant_shape_array (nl
->sym
)
13380 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object %qs "
13381 "with nonconstant shape in namelist %qs at %L",
13382 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
13385 if (nl
->sym
->ts
.type
== BT_CHARACTER
13386 && (nl
->sym
->ts
.u
.cl
->length
== NULL
13387 || !gfc_is_constant_expr (nl
->sym
->ts
.u
.cl
->length
))
13388 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST object %qs with "
13389 "nonconstant character length in "
13390 "namelist %qs at %L", nl
->sym
->name
,
13391 sym
->name
, &sym
->declared_at
))
13394 /* FIXME: Once UDDTIO is implemented, the following can be
13396 if (nl
->sym
->ts
.type
== BT_CLASS
)
13398 gfc_error ("NAMELIST object %qs in namelist %qs at %L is "
13399 "polymorphic and requires a defined input/output "
13400 "procedure", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13404 if (nl
->sym
->ts
.type
== BT_DERIVED
13405 && (nl
->sym
->ts
.u
.derived
->attr
.alloc_comp
13406 || nl
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
13408 if (!gfc_notify_std (GFC_STD_F2003
, "NAMELIST object %qs in "
13409 "namelist %qs at %L with ALLOCATABLE "
13410 "or POINTER components", nl
->sym
->name
,
13411 sym
->name
, &sym
->declared_at
))
13414 /* FIXME: Once UDDTIO is implemented, the following can be
13416 gfc_error ("NAMELIST object %qs in namelist %qs at %L has "
13417 "ALLOCATABLE or POINTER components and thus requires "
13418 "a defined input/output procedure", nl
->sym
->name
,
13419 sym
->name
, &sym
->declared_at
);
13424 /* Reject PRIVATE objects in a PUBLIC namelist. */
13425 if (gfc_check_symbol_access (sym
))
13427 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
13429 if (!nl
->sym
->attr
.use_assoc
13430 && !is_sym_host_assoc (nl
->sym
, sym
->ns
)
13431 && !gfc_check_symbol_access (nl
->sym
))
13433 gfc_error ("NAMELIST object %qs was declared PRIVATE and "
13434 "cannot be member of PUBLIC namelist %qs at %L",
13435 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13439 /* Types with private components that came here by USE-association. */
13440 if (nl
->sym
->ts
.type
== BT_DERIVED
13441 && derived_inaccessible (nl
->sym
->ts
.u
.derived
))
13443 gfc_error ("NAMELIST object %qs has use-associated PRIVATE "
13444 "components and cannot be member of namelist %qs at %L",
13445 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13449 /* Types with private components that are defined in the same module. */
13450 if (nl
->sym
->ts
.type
== BT_DERIVED
13451 && !is_sym_host_assoc (nl
->sym
->ts
.u
.derived
, sym
->ns
)
13452 && nl
->sym
->ts
.u
.derived
->attr
.private_comp
)
13454 gfc_error ("NAMELIST object %qs has PRIVATE components and "
13455 "cannot be a member of PUBLIC namelist %qs at %L",
13456 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13463 /* 14.1.2 A module or internal procedure represent local entities
13464 of the same type as a namelist member and so are not allowed. */
13465 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
13467 if (nl
->sym
->ts
.kind
!= 0 && nl
->sym
->attr
.flavor
== FL_VARIABLE
)
13470 if (nl
->sym
->attr
.function
&& nl
->sym
== nl
->sym
->result
)
13471 if ((nl
->sym
== sym
->ns
->proc_name
)
13473 (sym
->ns
->parent
&& nl
->sym
== sym
->ns
->parent
->proc_name
))
13478 gfc_find_symbol (nl
->sym
->name
, sym
->ns
, 1, &nlsym
);
13479 if (nlsym
&& nlsym
->attr
.flavor
== FL_PROCEDURE
)
13481 gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
13482 "attribute in %qs at %L", nlsym
->name
,
13483 &sym
->declared_at
);
13493 resolve_fl_parameter (gfc_symbol
*sym
)
13495 /* A parameter array's shape needs to be constant. */
13496 if (sym
->as
!= NULL
13497 && (sym
->as
->type
== AS_DEFERRED
13498 || is_non_constant_shape_array (sym
)))
13500 gfc_error ("Parameter array %qs at %L cannot be automatic "
13501 "or of deferred shape", sym
->name
, &sym
->declared_at
);
13505 /* Make sure a parameter that has been implicitly typed still
13506 matches the implicit type, since PARAMETER statements can precede
13507 IMPLICIT statements. */
13508 if (sym
->attr
.implicit_type
13509 && !gfc_compare_types (&sym
->ts
, gfc_get_default_type (sym
->name
,
13512 gfc_error ("Implicitly typed PARAMETER %qs at %L doesn't match a "
13513 "later IMPLICIT type", sym
->name
, &sym
->declared_at
);
13517 /* Make sure the types of derived parameters are consistent. This
13518 type checking is deferred until resolution because the type may
13519 refer to a derived type from the host. */
13520 if (sym
->ts
.type
== BT_DERIVED
13521 && !gfc_compare_types (&sym
->ts
, &sym
->value
->ts
))
13523 gfc_error ("Incompatible derived type in PARAMETER at %L",
13524 &sym
->value
->where
);
13531 /* Do anything necessary to resolve a symbol. Right now, we just
13532 assume that an otherwise unknown symbol is a variable. This sort
13533 of thing commonly happens for symbols in module. */
13536 resolve_symbol (gfc_symbol
*sym
)
13538 int check_constant
, mp_flag
;
13539 gfc_symtree
*symtree
;
13540 gfc_symtree
*this_symtree
;
13543 symbol_attribute class_attr
;
13544 gfc_array_spec
*as
;
13545 bool saved_specification_expr
;
13551 if (sym
->attr
.artificial
)
13554 if (sym
->attr
.unlimited_polymorphic
)
13557 if (sym
->attr
.flavor
== FL_UNKNOWN
13558 || (sym
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.intrinsic
13559 && !sym
->attr
.generic
&& !sym
->attr
.external
13560 && sym
->attr
.if_source
== IFSRC_UNKNOWN
13561 && sym
->ts
.type
== BT_UNKNOWN
))
13564 /* If we find that a flavorless symbol is an interface in one of the
13565 parent namespaces, find its symtree in this namespace, free the
13566 symbol and set the symtree to point to the interface symbol. */
13567 for (ns
= gfc_current_ns
->parent
; ns
; ns
= ns
->parent
)
13569 symtree
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
13570 if (symtree
&& (symtree
->n
.sym
->generic
||
13571 (symtree
->n
.sym
->attr
.flavor
== FL_PROCEDURE
13572 && sym
->ns
->construct_entities
)))
13574 this_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
13576 if (this_symtree
->n
.sym
== sym
)
13578 symtree
->n
.sym
->refs
++;
13579 gfc_release_symbol (sym
);
13580 this_symtree
->n
.sym
= symtree
->n
.sym
;
13586 /* Otherwise give it a flavor according to such attributes as
13588 if (sym
->attr
.flavor
== FL_UNKNOWN
&& sym
->attr
.external
== 0
13589 && sym
->attr
.intrinsic
== 0)
13590 sym
->attr
.flavor
= FL_VARIABLE
;
13591 else if (sym
->attr
.flavor
== FL_UNKNOWN
)
13593 sym
->attr
.flavor
= FL_PROCEDURE
;
13594 if (sym
->attr
.dimension
)
13595 sym
->attr
.function
= 1;
13599 if (sym
->attr
.external
&& sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.function
)
13600 gfc_add_function (&sym
->attr
, sym
->name
, &sym
->declared_at
);
13602 if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
13603 && !resolve_procedure_interface (sym
))
13606 if (sym
->attr
.is_protected
&& !sym
->attr
.proc_pointer
13607 && (sym
->attr
.procedure
|| sym
->attr
.external
))
13609 if (sym
->attr
.external
)
13610 gfc_error ("PROTECTED attribute conflicts with EXTERNAL attribute "
13611 "at %L", &sym
->declared_at
);
13613 gfc_error ("PROCEDURE attribute conflicts with PROTECTED attribute "
13614 "at %L", &sym
->declared_at
);
13619 if (sym
->attr
.flavor
== FL_DERIVED
&& !resolve_fl_derived (sym
))
13622 /* Symbols that are module procedures with results (functions) have
13623 the types and array specification copied for type checking in
13624 procedures that call them, as well as for saving to a module
13625 file. These symbols can't stand the scrutiny that their results
13627 mp_flag
= (sym
->result
!= NULL
&& sym
->result
!= sym
);
13629 /* Make sure that the intrinsic is consistent with its internal
13630 representation. This needs to be done before assigning a default
13631 type to avoid spurious warnings. */
13632 if (sym
->attr
.flavor
!= FL_MODULE
&& sym
->attr
.intrinsic
13633 && !gfc_resolve_intrinsic (sym
, &sym
->declared_at
))
13636 /* Resolve associate names. */
13638 resolve_assoc_var (sym
, true);
13640 /* Assign default type to symbols that need one and don't have one. */
13641 if (sym
->ts
.type
== BT_UNKNOWN
)
13643 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
)
13645 gfc_set_default_type (sym
, 1, NULL
);
13648 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.external
13649 && !sym
->attr
.function
&& !sym
->attr
.subroutine
13650 && gfc_get_default_type (sym
->name
, sym
->ns
)->type
== BT_UNKNOWN
)
13651 gfc_add_subroutine (&sym
->attr
, sym
->name
, &sym
->declared_at
);
13653 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
13655 /* The specific case of an external procedure should emit an error
13656 in the case that there is no implicit type. */
13658 gfc_set_default_type (sym
, sym
->attr
.external
, NULL
);
13661 /* Result may be in another namespace. */
13662 resolve_symbol (sym
->result
);
13664 if (!sym
->result
->attr
.proc_pointer
)
13666 sym
->ts
= sym
->result
->ts
;
13667 sym
->as
= gfc_copy_array_spec (sym
->result
->as
);
13668 sym
->attr
.dimension
= sym
->result
->attr
.dimension
;
13669 sym
->attr
.pointer
= sym
->result
->attr
.pointer
;
13670 sym
->attr
.allocatable
= sym
->result
->attr
.allocatable
;
13671 sym
->attr
.contiguous
= sym
->result
->attr
.contiguous
;
13676 else if (mp_flag
&& sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
13678 bool saved_specification_expr
= specification_expr
;
13679 specification_expr
= true;
13680 gfc_resolve_array_spec (sym
->result
->as
, false);
13681 specification_expr
= saved_specification_expr
;
13684 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
13686 as
= CLASS_DATA (sym
)->as
;
13687 class_attr
= CLASS_DATA (sym
)->attr
;
13688 class_attr
.pointer
= class_attr
.class_pointer
;
13692 class_attr
= sym
->attr
;
13697 if (sym
->attr
.contiguous
13698 && (!class_attr
.dimension
13699 || (as
->type
!= AS_ASSUMED_SHAPE
&& as
->type
!= AS_ASSUMED_RANK
13700 && !class_attr
.pointer
)))
13702 gfc_error ("%qs at %L has the CONTIGUOUS attribute but is not an "
13703 "array pointer or an assumed-shape or assumed-rank array",
13704 sym
->name
, &sym
->declared_at
);
13708 /* Assumed size arrays and assumed shape arrays must be dummy
13709 arguments. Array-spec's of implied-shape should have been resolved to
13710 AS_EXPLICIT already. */
13714 gcc_assert (as
->type
!= AS_IMPLIED_SHAPE
);
13715 if (((as
->type
== AS_ASSUMED_SIZE
&& !as
->cp_was_assumed
)
13716 || as
->type
== AS_ASSUMED_SHAPE
)
13717 && !sym
->attr
.dummy
&& !sym
->attr
.select_type_temporary
)
13719 if (as
->type
== AS_ASSUMED_SIZE
)
13720 gfc_error ("Assumed size array at %L must be a dummy argument",
13721 &sym
->declared_at
);
13723 gfc_error ("Assumed shape array at %L must be a dummy argument",
13724 &sym
->declared_at
);
13727 /* TS 29113, C535a. */
13728 if (as
->type
== AS_ASSUMED_RANK
&& !sym
->attr
.dummy
13729 && !sym
->attr
.select_type_temporary
)
13731 gfc_error ("Assumed-rank array at %L must be a dummy argument",
13732 &sym
->declared_at
);
13735 if (as
->type
== AS_ASSUMED_RANK
13736 && (sym
->attr
.codimension
|| sym
->attr
.value
))
13738 gfc_error ("Assumed-rank array at %L may not have the VALUE or "
13739 "CODIMENSION attribute", &sym
->declared_at
);
13744 /* Make sure symbols with known intent or optional are really dummy
13745 variable. Because of ENTRY statement, this has to be deferred
13746 until resolution time. */
13748 if (!sym
->attr
.dummy
13749 && (sym
->attr
.optional
|| sym
->attr
.intent
!= INTENT_UNKNOWN
))
13751 gfc_error ("Symbol at %L is not a DUMMY variable", &sym
->declared_at
);
13755 if (sym
->attr
.value
&& !sym
->attr
.dummy
)
13757 gfc_error ("%qs at %L cannot have the VALUE attribute because "
13758 "it is not a dummy argument", sym
->name
, &sym
->declared_at
);
13762 if (sym
->attr
.value
&& sym
->ts
.type
== BT_CHARACTER
)
13764 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
13765 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
13767 gfc_error ("Character dummy variable %qs at %L with VALUE "
13768 "attribute must have constant length",
13769 sym
->name
, &sym
->declared_at
);
13773 if (sym
->ts
.is_c_interop
13774 && mpz_cmp_si (cl
->length
->value
.integer
, 1) != 0)
13776 gfc_error ("C interoperable character dummy variable %qs at %L "
13777 "with VALUE attribute must have length one",
13778 sym
->name
, &sym
->declared_at
);
13783 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
13784 && sym
->ts
.u
.derived
->attr
.generic
)
13786 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
13787 if (!sym
->ts
.u
.derived
)
13789 gfc_error ("The derived type %qs at %L is of type %qs, "
13790 "which has not been defined", sym
->name
,
13791 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
13792 sym
->ts
.type
= BT_UNKNOWN
;
13797 /* Use the same constraints as TYPE(*), except for the type check
13798 and that only scalars and assumed-size arrays are permitted. */
13799 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
13801 if (!sym
->attr
.dummy
)
13803 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
13804 "a dummy argument", sym
->name
, &sym
->declared_at
);
13808 if (sym
->ts
.type
!= BT_ASSUMED
&& sym
->ts
.type
!= BT_INTEGER
13809 && sym
->ts
.type
!= BT_REAL
&& sym
->ts
.type
!= BT_LOGICAL
13810 && sym
->ts
.type
!= BT_COMPLEX
)
13812 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
13813 "of type TYPE(*) or of an numeric intrinsic type",
13814 sym
->name
, &sym
->declared_at
);
13818 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
13819 || sym
->attr
.pointer
|| sym
->attr
.value
)
13821 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
13822 "have the ALLOCATABLE, CODIMENSION, POINTER or VALUE "
13823 "attribute", sym
->name
, &sym
->declared_at
);
13827 if (sym
->attr
.intent
== INTENT_OUT
)
13829 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
13830 "have the INTENT(OUT) attribute",
13831 sym
->name
, &sym
->declared_at
);
13834 if (sym
->attr
.dimension
&& sym
->as
->type
!= AS_ASSUMED_SIZE
)
13836 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall "
13837 "either be a scalar or an assumed-size array",
13838 sym
->name
, &sym
->declared_at
);
13842 /* Set the type to TYPE(*) and add a dimension(*) to ensure
13843 NO_ARG_CHECK is correctly handled in trans*.c, e.g. with
13845 sym
->ts
.type
= BT_ASSUMED
;
13846 sym
->as
= gfc_get_array_spec ();
13847 sym
->as
->type
= AS_ASSUMED_SIZE
;
13849 sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
13851 else if (sym
->ts
.type
== BT_ASSUMED
)
13853 /* TS 29113, C407a. */
13854 if (!sym
->attr
.dummy
)
13856 gfc_error ("Assumed type of variable %s at %L is only permitted "
13857 "for dummy variables", sym
->name
, &sym
->declared_at
);
13860 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
13861 || sym
->attr
.pointer
|| sym
->attr
.value
)
13863 gfc_error ("Assumed-type variable %s at %L may not have the "
13864 "ALLOCATABLE, CODIMENSION, POINTER or VALUE attribute",
13865 sym
->name
, &sym
->declared_at
);
13868 if (sym
->attr
.intent
== INTENT_OUT
)
13870 gfc_error ("Assumed-type variable %s at %L may not have the "
13871 "INTENT(OUT) attribute",
13872 sym
->name
, &sym
->declared_at
);
13875 if (sym
->attr
.dimension
&& sym
->as
->type
== AS_EXPLICIT
)
13877 gfc_error ("Assumed-type variable %s at %L shall not be an "
13878 "explicit-shape array", sym
->name
, &sym
->declared_at
);
13883 /* If the symbol is marked as bind(c), verify it's type and kind. Do not
13884 do this for something that was implicitly typed because that is handled
13885 in gfc_set_default_type. Handle dummy arguments and procedure
13886 definitions separately. Also, anything that is use associated is not
13887 handled here but instead is handled in the module it is declared in.
13888 Finally, derived type definitions are allowed to be BIND(C) since that
13889 only implies that they're interoperable, and they are checked fully for
13890 interoperability when a variable is declared of that type. */
13891 if (sym
->attr
.is_bind_c
&& sym
->attr
.implicit_type
== 0 &&
13892 sym
->attr
.use_assoc
== 0 && sym
->attr
.dummy
== 0 &&
13893 sym
->attr
.flavor
!= FL_PROCEDURE
&& sym
->attr
.flavor
!= FL_DERIVED
)
13897 /* First, make sure the variable is declared at the
13898 module-level scope (J3/04-007, Section 15.3). */
13899 if (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
&&
13900 sym
->attr
.in_common
== 0)
13902 gfc_error ("Variable %qs at %L cannot be BIND(C) because it "
13903 "is neither a COMMON block nor declared at the "
13904 "module level scope", sym
->name
, &(sym
->declared_at
));
13907 else if (sym
->common_head
!= NULL
)
13909 t
= verify_com_block_vars_c_interop (sym
->common_head
);
13913 /* If type() declaration, we need to verify that the components
13914 of the given type are all C interoperable, etc. */
13915 if (sym
->ts
.type
== BT_DERIVED
&&
13916 sym
->ts
.u
.derived
->attr
.is_c_interop
!= 1)
13918 /* Make sure the user marked the derived type as BIND(C). If
13919 not, call the verify routine. This could print an error
13920 for the derived type more than once if multiple variables
13921 of that type are declared. */
13922 if (sym
->ts
.u
.derived
->attr
.is_bind_c
!= 1)
13923 verify_bind_c_derived_type (sym
->ts
.u
.derived
);
13927 /* Verify the variable itself as C interoperable if it
13928 is BIND(C). It is not possible for this to succeed if
13929 the verify_bind_c_derived_type failed, so don't have to handle
13930 any error returned by verify_bind_c_derived_type. */
13931 t
= verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
13932 sym
->common_block
);
13937 /* clear the is_bind_c flag to prevent reporting errors more than
13938 once if something failed. */
13939 sym
->attr
.is_bind_c
= 0;
13944 /* If a derived type symbol has reached this point, without its
13945 type being declared, we have an error. Notice that most
13946 conditions that produce undefined derived types have already
13947 been dealt with. However, the likes of:
13948 implicit type(t) (t) ..... call foo (t) will get us here if
13949 the type is not declared in the scope of the implicit
13950 statement. Change the type to BT_UNKNOWN, both because it is so
13951 and to prevent an ICE. */
13952 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
13953 && sym
->ts
.u
.derived
->components
== NULL
13954 && !sym
->ts
.u
.derived
->attr
.zero_comp
)
13956 gfc_error ("The derived type %qs at %L is of type %qs, "
13957 "which has not been defined", sym
->name
,
13958 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
13959 sym
->ts
.type
= BT_UNKNOWN
;
13963 /* Make sure that the derived type has been resolved and that the
13964 derived type is visible in the symbol's namespace, if it is a
13965 module function and is not PRIVATE. */
13966 if (sym
->ts
.type
== BT_DERIVED
13967 && sym
->ts
.u
.derived
->attr
.use_assoc
13968 && sym
->ns
->proc_name
13969 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
13970 && !resolve_fl_derived (sym
->ts
.u
.derived
))
13973 /* Unless the derived-type declaration is use associated, Fortran 95
13974 does not allow public entries of private derived types.
13975 See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
13976 161 in 95-006r3. */
13977 if (sym
->ts
.type
== BT_DERIVED
13978 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
13979 && !sym
->ts
.u
.derived
->attr
.use_assoc
13980 && gfc_check_symbol_access (sym
)
13981 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
13982 && !gfc_notify_std (GFC_STD_F2003
, "PUBLIC %s %qs at %L of PRIVATE "
13983 "derived type %qs",
13984 (sym
->attr
.flavor
== FL_PARAMETER
)
13985 ? "parameter" : "variable",
13986 sym
->name
, &sym
->declared_at
,
13987 sym
->ts
.u
.derived
->name
))
13990 /* F2008, C1302. */
13991 if (sym
->ts
.type
== BT_DERIVED
13992 && ((sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
13993 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
13994 || sym
->ts
.u
.derived
->attr
.lock_comp
)
13995 && !sym
->attr
.codimension
&& !sym
->ts
.u
.derived
->attr
.coarray_comp
)
13997 gfc_error ("Variable %s at %L of type LOCK_TYPE or with subcomponent of "
13998 "type LOCK_TYPE must be a coarray", sym
->name
,
13999 &sym
->declared_at
);
14003 /* An assumed-size array with INTENT(OUT) shall not be of a type for which
14004 default initialization is defined (5.1.2.4.4). */
14005 if (sym
->ts
.type
== BT_DERIVED
14007 && sym
->attr
.intent
== INTENT_OUT
14009 && sym
->as
->type
== AS_ASSUMED_SIZE
)
14011 for (c
= sym
->ts
.u
.derived
->components
; c
; c
= c
->next
)
14013 if (c
->initializer
)
14015 gfc_error ("The INTENT(OUT) dummy argument %qs at %L is "
14016 "ASSUMED SIZE and so cannot have a default initializer",
14017 sym
->name
, &sym
->declared_at
);
14024 if (sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.dummy
14025 && sym
->attr
.intent
== INTENT_OUT
&& sym
->attr
.lock_comp
)
14027 gfc_error ("Dummy argument %qs at %L of LOCK_TYPE shall not be "
14028 "INTENT(OUT)", sym
->name
, &sym
->declared_at
);
14033 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
14034 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
14035 && CLASS_DATA (sym
)->attr
.coarray_comp
))
14036 || class_attr
.codimension
)
14037 && (sym
->attr
.result
|| sym
->result
== sym
))
14039 gfc_error ("Function result %qs at %L shall not be a coarray or have "
14040 "a coarray component", sym
->name
, &sym
->declared_at
);
14045 if (sym
->attr
.codimension
&& sym
->ts
.type
== BT_DERIVED
14046 && sym
->ts
.u
.derived
->ts
.is_iso_c
)
14048 gfc_error ("Variable %qs at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
14049 "shall not be a coarray", sym
->name
, &sym
->declared_at
);
14054 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
14055 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
14056 && CLASS_DATA (sym
)->attr
.coarray_comp
))
14057 && (class_attr
.codimension
|| class_attr
.pointer
|| class_attr
.dimension
14058 || class_attr
.allocatable
))
14060 gfc_error ("Variable %qs at %L with coarray component shall be a "
14061 "nonpointer, nonallocatable scalar, which is not a coarray",
14062 sym
->name
, &sym
->declared_at
);
14066 /* F2008, C526. The function-result case was handled above. */
14067 if (class_attr
.codimension
14068 && !(class_attr
.allocatable
|| sym
->attr
.dummy
|| sym
->attr
.save
14069 || sym
->attr
.select_type_temporary
14070 || sym
->ns
->save_all
14071 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
14072 || sym
->ns
->proc_name
->attr
.is_main_program
14073 || sym
->attr
.function
|| sym
->attr
.result
|| sym
->attr
.use_assoc
))
14075 gfc_error ("Variable %qs at %L is a coarray and is not ALLOCATABLE, SAVE "
14076 "nor a dummy argument", sym
->name
, &sym
->declared_at
);
14080 else if (class_attr
.codimension
&& !sym
->attr
.select_type_temporary
14081 && !class_attr
.allocatable
&& as
&& as
->cotype
== AS_DEFERRED
)
14083 gfc_error ("Coarray variable %qs at %L shall not have codimensions with "
14084 "deferred shape", sym
->name
, &sym
->declared_at
);
14087 else if (class_attr
.codimension
&& class_attr
.allocatable
&& as
14088 && (as
->cotype
!= AS_DEFERRED
|| as
->type
!= AS_DEFERRED
))
14090 gfc_error ("Allocatable coarray variable %qs at %L must have "
14091 "deferred shape", sym
->name
, &sym
->declared_at
);
14096 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
14097 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
14098 && CLASS_DATA (sym
)->attr
.coarray_comp
))
14099 || (class_attr
.codimension
&& class_attr
.allocatable
))
14100 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
)
14102 gfc_error ("Variable %qs at %L is INTENT(OUT) and can thus not be an "
14103 "allocatable coarray or have coarray components",
14104 sym
->name
, &sym
->declared_at
);
14108 if (class_attr
.codimension
&& sym
->attr
.dummy
14109 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.is_bind_c
)
14111 gfc_error ("Coarray dummy variable %qs at %L not allowed in BIND(C) "
14112 "procedure %qs", sym
->name
, &sym
->declared_at
,
14113 sym
->ns
->proc_name
->name
);
14117 if (sym
->ts
.type
== BT_LOGICAL
14118 && ((sym
->attr
.function
&& sym
->attr
.is_bind_c
&& sym
->result
== sym
)
14119 || ((sym
->attr
.dummy
|| sym
->attr
.result
) && sym
->ns
->proc_name
14120 && sym
->ns
->proc_name
->attr
.is_bind_c
)))
14123 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
14124 if (gfc_logical_kinds
[i
].kind
== sym
->ts
.kind
)
14126 if (!gfc_logical_kinds
[i
].c_bool
&& sym
->attr
.dummy
14127 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL dummy argument %qs at "
14128 "%L with non-C_Bool kind in BIND(C) procedure "
14129 "%qs", sym
->name
, &sym
->declared_at
,
14130 sym
->ns
->proc_name
->name
))
14132 else if (!gfc_logical_kinds
[i
].c_bool
14133 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL result variable "
14134 "%qs at %L with non-C_Bool kind in "
14135 "BIND(C) procedure %qs", sym
->name
,
14137 sym
->attr
.function
? sym
->name
14138 : sym
->ns
->proc_name
->name
))
14142 switch (sym
->attr
.flavor
)
14145 if (!resolve_fl_variable (sym
, mp_flag
))
14150 if (!resolve_fl_procedure (sym
, mp_flag
))
14155 if (!resolve_fl_namelist (sym
))
14160 if (!resolve_fl_parameter (sym
))
14168 /* Resolve array specifier. Check as well some constraints
14169 on COMMON blocks. */
14171 check_constant
= sym
->attr
.in_common
&& !sym
->attr
.pointer
;
14173 /* Set the formal_arg_flag so that check_conflict will not throw
14174 an error for host associated variables in the specification
14175 expression for an array_valued function. */
14176 if (sym
->attr
.function
&& sym
->as
)
14177 formal_arg_flag
= 1;
14179 saved_specification_expr
= specification_expr
;
14180 specification_expr
= true;
14181 gfc_resolve_array_spec (sym
->as
, check_constant
);
14182 specification_expr
= saved_specification_expr
;
14184 formal_arg_flag
= 0;
14186 /* Resolve formal namespaces. */
14187 if (sym
->formal_ns
&& sym
->formal_ns
!= gfc_current_ns
14188 && !sym
->attr
.contained
&& !sym
->attr
.intrinsic
)
14189 gfc_resolve (sym
->formal_ns
);
14191 /* Make sure the formal namespace is present. */
14192 if (sym
->formal
&& !sym
->formal_ns
)
14194 gfc_formal_arglist
*formal
= sym
->formal
;
14195 while (formal
&& !formal
->sym
)
14196 formal
= formal
->next
;
14200 sym
->formal_ns
= formal
->sym
->ns
;
14201 if (sym
->ns
!= formal
->sym
->ns
)
14202 sym
->formal_ns
->refs
++;
14206 /* Check threadprivate restrictions. */
14207 if (sym
->attr
.threadprivate
&& !sym
->attr
.save
&& !sym
->ns
->save_all
14208 && (!sym
->attr
.in_common
14209 && sym
->module
== NULL
14210 && (sym
->ns
->proc_name
== NULL
14211 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
14212 gfc_error ("Threadprivate at %L isn't SAVEd", &sym
->declared_at
);
14214 /* Check omp declare target restrictions. */
14215 if (sym
->attr
.omp_declare_target
14216 && sym
->attr
.flavor
== FL_VARIABLE
14218 && !sym
->ns
->save_all
14219 && (!sym
->attr
.in_common
14220 && sym
->module
== NULL
14221 && (sym
->ns
->proc_name
== NULL
14222 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
14223 gfc_error ("!$OMP DECLARE TARGET variable %qs at %L isn't SAVEd",
14224 sym
->name
, &sym
->declared_at
);
14226 /* If we have come this far we can apply default-initializers, as
14227 described in 14.7.5, to those variables that have not already
14228 been assigned one. */
14229 if (sym
->ts
.type
== BT_DERIVED
14231 && !sym
->attr
.allocatable
14232 && !sym
->attr
.alloc_comp
)
14234 symbol_attribute
*a
= &sym
->attr
;
14236 if ((!a
->save
&& !a
->dummy
&& !a
->pointer
14237 && !a
->in_common
&& !a
->use_assoc
14238 && !a
->result
&& !a
->function
)
14239 || (a
->dummy
&& a
->intent
== INTENT_OUT
&& !a
->pointer
))
14240 apply_default_init (sym
);
14241 else if (a
->function
&& sym
->result
&& a
->access
!= ACCESS_PRIVATE
14242 && (sym
->ts
.u
.derived
->attr
.alloc_comp
14243 || sym
->ts
.u
.derived
->attr
.pointer_comp
))
14244 /* Mark the result symbol to be referenced, when it has allocatable
14246 sym
->result
->attr
.referenced
= 1;
14249 if (sym
->ts
.type
== BT_CLASS
&& sym
->ns
== gfc_current_ns
14250 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
14251 && !CLASS_DATA (sym
)->attr
.class_pointer
14252 && !CLASS_DATA (sym
)->attr
.allocatable
)
14253 apply_default_init (sym
);
14255 /* If this symbol has a type-spec, check it. */
14256 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
14257 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
))
14258 if (!resolve_typespec_used (&sym
->ts
, &sym
->declared_at
, sym
->name
))
14263 /************* Resolve DATA statements *************/
14267 gfc_data_value
*vnode
;
14273 /* Advance the values structure to point to the next value in the data list. */
14276 next_data_value (void)
14278 while (mpz_cmp_ui (values
.left
, 0) == 0)
14281 if (values
.vnode
->next
== NULL
)
14284 values
.vnode
= values
.vnode
->next
;
14285 mpz_set (values
.left
, values
.vnode
->repeat
);
14293 check_data_variable (gfc_data_variable
*var
, locus
*where
)
14299 ar_type mark
= AR_UNKNOWN
;
14301 mpz_t section_index
[GFC_MAX_DIMENSIONS
];
14307 if (!gfc_resolve_expr (var
->expr
))
14311 mpz_init_set_si (offset
, 0);
14314 if (e
->expr_type
!= EXPR_VARIABLE
)
14315 gfc_internal_error ("check_data_variable(): Bad expression");
14317 sym
= e
->symtree
->n
.sym
;
14319 if (sym
->ns
->is_block_data
&& !sym
->attr
.in_common
)
14321 gfc_error ("BLOCK DATA element %qs at %L must be in COMMON",
14322 sym
->name
, &sym
->declared_at
);
14325 if (e
->ref
== NULL
&& sym
->as
)
14327 gfc_error ("DATA array %qs at %L must be specified in a previous"
14328 " declaration", sym
->name
, where
);
14332 has_pointer
= sym
->attr
.pointer
;
14334 if (gfc_is_coindexed (e
))
14336 gfc_error ("DATA element %qs at %L cannot have a coindex", sym
->name
,
14341 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
14343 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.pointer
)
14347 && ref
->type
== REF_ARRAY
14348 && ref
->u
.ar
.type
!= AR_FULL
)
14350 gfc_error ("DATA element %qs at %L is a pointer and so must "
14351 "be a full array", sym
->name
, where
);
14356 if (e
->rank
== 0 || has_pointer
)
14358 mpz_init_set_ui (size
, 1);
14365 /* Find the array section reference. */
14366 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
14368 if (ref
->type
!= REF_ARRAY
)
14370 if (ref
->u
.ar
.type
== AR_ELEMENT
)
14376 /* Set marks according to the reference pattern. */
14377 switch (ref
->u
.ar
.type
)
14385 /* Get the start position of array section. */
14386 gfc_get_section_index (ar
, section_index
, &offset
);
14391 gcc_unreachable ();
14394 if (!gfc_array_size (e
, &size
))
14396 gfc_error ("Nonconstant array section at %L in DATA statement",
14398 mpz_clear (offset
);
14405 while (mpz_cmp_ui (size
, 0) > 0)
14407 if (!next_data_value ())
14409 gfc_error ("DATA statement at %L has more variables than values",
14415 t
= gfc_check_assign (var
->expr
, values
.vnode
->expr
, 0);
14419 /* If we have more than one element left in the repeat count,
14420 and we have more than one element left in the target variable,
14421 then create a range assignment. */
14422 /* FIXME: Only done for full arrays for now, since array sections
14424 if (mark
== AR_FULL
&& ref
&& ref
->next
== NULL
14425 && mpz_cmp_ui (values
.left
, 1) > 0 && mpz_cmp_ui (size
, 1) > 0)
14429 if (mpz_cmp (size
, values
.left
) >= 0)
14431 mpz_init_set (range
, values
.left
);
14432 mpz_sub (size
, size
, values
.left
);
14433 mpz_set_ui (values
.left
, 0);
14437 mpz_init_set (range
, size
);
14438 mpz_sub (values
.left
, values
.left
, size
);
14439 mpz_set_ui (size
, 0);
14442 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
14445 mpz_add (offset
, offset
, range
);
14452 /* Assign initial value to symbol. */
14455 mpz_sub_ui (values
.left
, values
.left
, 1);
14456 mpz_sub_ui (size
, size
, 1);
14458 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
14463 if (mark
== AR_FULL
)
14464 mpz_add_ui (offset
, offset
, 1);
14466 /* Modify the array section indexes and recalculate the offset
14467 for next element. */
14468 else if (mark
== AR_SECTION
)
14469 gfc_advance_section (section_index
, ar
, &offset
);
14473 if (mark
== AR_SECTION
)
14475 for (i
= 0; i
< ar
->dimen
; i
++)
14476 mpz_clear (section_index
[i
]);
14480 mpz_clear (offset
);
14486 static bool traverse_data_var (gfc_data_variable
*, locus
*);
14488 /* Iterate over a list of elements in a DATA statement. */
14491 traverse_data_list (gfc_data_variable
*var
, locus
*where
)
14494 iterator_stack frame
;
14495 gfc_expr
*e
, *start
, *end
, *step
;
14496 bool retval
= true;
14498 mpz_init (frame
.value
);
14501 start
= gfc_copy_expr (var
->iter
.start
);
14502 end
= gfc_copy_expr (var
->iter
.end
);
14503 step
= gfc_copy_expr (var
->iter
.step
);
14505 if (!gfc_simplify_expr (start
, 1)
14506 || start
->expr_type
!= EXPR_CONSTANT
)
14508 gfc_error ("start of implied-do loop at %L could not be "
14509 "simplified to a constant value", &start
->where
);
14513 if (!gfc_simplify_expr (end
, 1)
14514 || end
->expr_type
!= EXPR_CONSTANT
)
14516 gfc_error ("end of implied-do loop at %L could not be "
14517 "simplified to a constant value", &start
->where
);
14521 if (!gfc_simplify_expr (step
, 1)
14522 || step
->expr_type
!= EXPR_CONSTANT
)
14524 gfc_error ("step of implied-do loop at %L could not be "
14525 "simplified to a constant value", &start
->where
);
14530 mpz_set (trip
, end
->value
.integer
);
14531 mpz_sub (trip
, trip
, start
->value
.integer
);
14532 mpz_add (trip
, trip
, step
->value
.integer
);
14534 mpz_div (trip
, trip
, step
->value
.integer
);
14536 mpz_set (frame
.value
, start
->value
.integer
);
14538 frame
.prev
= iter_stack
;
14539 frame
.variable
= var
->iter
.var
->symtree
;
14540 iter_stack
= &frame
;
14542 while (mpz_cmp_ui (trip
, 0) > 0)
14544 if (!traverse_data_var (var
->list
, where
))
14550 e
= gfc_copy_expr (var
->expr
);
14551 if (!gfc_simplify_expr (e
, 1))
14558 mpz_add (frame
.value
, frame
.value
, step
->value
.integer
);
14560 mpz_sub_ui (trip
, trip
, 1);
14564 mpz_clear (frame
.value
);
14567 gfc_free_expr (start
);
14568 gfc_free_expr (end
);
14569 gfc_free_expr (step
);
14571 iter_stack
= frame
.prev
;
14576 /* Type resolve variables in the variable list of a DATA statement. */
14579 traverse_data_var (gfc_data_variable
*var
, locus
*where
)
14583 for (; var
; var
= var
->next
)
14585 if (var
->expr
== NULL
)
14586 t
= traverse_data_list (var
, where
);
14588 t
= check_data_variable (var
, where
);
14598 /* Resolve the expressions and iterators associated with a data statement.
14599 This is separate from the assignment checking because data lists should
14600 only be resolved once. */
14603 resolve_data_variables (gfc_data_variable
*d
)
14605 for (; d
; d
= d
->next
)
14607 if (d
->list
== NULL
)
14609 if (!gfc_resolve_expr (d
->expr
))
14614 if (!gfc_resolve_iterator (&d
->iter
, false, true))
14617 if (!resolve_data_variables (d
->list
))
14626 /* Resolve a single DATA statement. We implement this by storing a pointer to
14627 the value list into static variables, and then recursively traversing the
14628 variables list, expanding iterators and such. */
14631 resolve_data (gfc_data
*d
)
14634 if (!resolve_data_variables (d
->var
))
14637 values
.vnode
= d
->value
;
14638 if (d
->value
== NULL
)
14639 mpz_set_ui (values
.left
, 0);
14641 mpz_set (values
.left
, d
->value
->repeat
);
14643 if (!traverse_data_var (d
->var
, &d
->where
))
14646 /* At this point, we better not have any values left. */
14648 if (next_data_value ())
14649 gfc_error ("DATA statement at %L has more values than variables",
14654 /* 12.6 Constraint: In a pure subprogram any variable which is in common or
14655 accessed by host or use association, is a dummy argument to a pure function,
14656 is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
14657 is storage associated with any such variable, shall not be used in the
14658 following contexts: (clients of this function). */
14660 /* Determines if a variable is not 'pure', i.e., not assignable within a pure
14661 procedure. Returns zero if assignment is OK, nonzero if there is a
14664 gfc_impure_variable (gfc_symbol
*sym
)
14669 if (sym
->attr
.use_assoc
|| sym
->attr
.in_common
)
14672 /* Check if the symbol's ns is inside the pure procedure. */
14673 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14677 if (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
14681 proc
= sym
->ns
->proc_name
;
14682 if (sym
->attr
.dummy
14683 && ((proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_IN
)
14684 || proc
->attr
.function
))
14687 /* TODO: Sort out what can be storage associated, if anything, and include
14688 it here. In principle equivalences should be scanned but it does not
14689 seem to be possible to storage associate an impure variable this way. */
14694 /* Test whether a symbol is pure or not. For a NULL pointer, checks if the
14695 current namespace is inside a pure procedure. */
14698 gfc_pure (gfc_symbol
*sym
)
14700 symbol_attribute attr
;
14705 /* Check if the current namespace or one of its parents
14706 belongs to a pure procedure. */
14707 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14709 sym
= ns
->proc_name
;
14713 if (attr
.flavor
== FL_PROCEDURE
&& attr
.pure
)
14721 return attr
.flavor
== FL_PROCEDURE
&& attr
.pure
;
14725 /* Test whether a symbol is implicitly pure or not. For a NULL pointer,
14726 checks if the current namespace is implicitly pure. Note that this
14727 function returns false for a PURE procedure. */
14730 gfc_implicit_pure (gfc_symbol
*sym
)
14736 /* Check if the current procedure is implicit_pure. Walk up
14737 the procedure list until we find a procedure. */
14738 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14740 sym
= ns
->proc_name
;
14744 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14749 return sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.implicit_pure
14750 && !sym
->attr
.pure
;
14755 gfc_unset_implicit_pure (gfc_symbol
*sym
)
14761 /* Check if the current procedure is implicit_pure. Walk up
14762 the procedure list until we find a procedure. */
14763 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14765 sym
= ns
->proc_name
;
14769 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14774 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14775 sym
->attr
.implicit_pure
= 0;
14777 sym
->attr
.pure
= 0;
14781 /* Test whether the current procedure is elemental or not. */
14784 gfc_elemental (gfc_symbol
*sym
)
14786 symbol_attribute attr
;
14789 sym
= gfc_current_ns
->proc_name
;
14794 return attr
.flavor
== FL_PROCEDURE
&& attr
.elemental
;
14798 /* Warn about unused labels. */
14801 warn_unused_fortran_label (gfc_st_label
*label
)
14806 warn_unused_fortran_label (label
->left
);
14808 if (label
->defined
== ST_LABEL_UNKNOWN
)
14811 switch (label
->referenced
)
14813 case ST_LABEL_UNKNOWN
:
14814 gfc_warning (0, "Label %d at %L defined but not used", label
->value
,
14818 case ST_LABEL_BAD_TARGET
:
14819 gfc_warning (0, "Label %d at %L defined but cannot be used",
14820 label
->value
, &label
->where
);
14827 warn_unused_fortran_label (label
->right
);
14831 /* Returns the sequence type of a symbol or sequence. */
14834 sequence_type (gfc_typespec ts
)
14843 if (ts
.u
.derived
->components
== NULL
)
14844 return SEQ_NONDEFAULT
;
14846 result
= sequence_type (ts
.u
.derived
->components
->ts
);
14847 for (c
= ts
.u
.derived
->components
->next
; c
; c
= c
->next
)
14848 if (sequence_type (c
->ts
) != result
)
14854 if (ts
.kind
!= gfc_default_character_kind
)
14855 return SEQ_NONDEFAULT
;
14857 return SEQ_CHARACTER
;
14860 if (ts
.kind
!= gfc_default_integer_kind
)
14861 return SEQ_NONDEFAULT
;
14863 return SEQ_NUMERIC
;
14866 if (!(ts
.kind
== gfc_default_real_kind
14867 || ts
.kind
== gfc_default_double_kind
))
14868 return SEQ_NONDEFAULT
;
14870 return SEQ_NUMERIC
;
14873 if (ts
.kind
!= gfc_default_complex_kind
)
14874 return SEQ_NONDEFAULT
;
14876 return SEQ_NUMERIC
;
14879 if (ts
.kind
!= gfc_default_logical_kind
)
14880 return SEQ_NONDEFAULT
;
14882 return SEQ_NUMERIC
;
14885 return SEQ_NONDEFAULT
;
14890 /* Resolve derived type EQUIVALENCE object. */
14893 resolve_equivalence_derived (gfc_symbol
*derived
, gfc_symbol
*sym
, gfc_expr
*e
)
14895 gfc_component
*c
= derived
->components
;
14900 /* Shall not be an object of nonsequence derived type. */
14901 if (!derived
->attr
.sequence
)
14903 gfc_error ("Derived type variable %qs at %L must have SEQUENCE "
14904 "attribute to be an EQUIVALENCE object", sym
->name
,
14909 /* Shall not have allocatable components. */
14910 if (derived
->attr
.alloc_comp
)
14912 gfc_error ("Derived type variable %qs at %L cannot have ALLOCATABLE "
14913 "components to be an EQUIVALENCE object",sym
->name
,
14918 if (sym
->attr
.in_common
&& gfc_has_default_initializer (sym
->ts
.u
.derived
))
14920 gfc_error ("Derived type variable %qs at %L with default "
14921 "initialization cannot be in EQUIVALENCE with a variable "
14922 "in COMMON", sym
->name
, &e
->where
);
14926 for (; c
; c
= c
->next
)
14928 if (c
->ts
.type
== BT_DERIVED
14929 && (!resolve_equivalence_derived(c
->ts
.u
.derived
, sym
, e
)))
14932 /* Shall not be an object of sequence derived type containing a pointer
14933 in the structure. */
14934 if (c
->attr
.pointer
)
14936 gfc_error ("Derived type variable %qs at %L with pointer "
14937 "component(s) cannot be an EQUIVALENCE object",
14938 sym
->name
, &e
->where
);
14946 /* Resolve equivalence object.
14947 An EQUIVALENCE object shall not be a dummy argument, a pointer, a target,
14948 an allocatable array, an object of nonsequence derived type, an object of
14949 sequence derived type containing a pointer at any level of component
14950 selection, an automatic object, a function name, an entry name, a result
14951 name, a named constant, a structure component, or a subobject of any of
14952 the preceding objects. A substring shall not have length zero. A
14953 derived type shall not have components with default initialization nor
14954 shall two objects of an equivalence group be initialized.
14955 Either all or none of the objects shall have an protected attribute.
14956 The simple constraints are done in symbol.c(check_conflict) and the rest
14957 are implemented here. */
14960 resolve_equivalence (gfc_equiv
*eq
)
14963 gfc_symbol
*first_sym
;
14966 locus
*last_where
= NULL
;
14967 seq_type eq_type
, last_eq_type
;
14968 gfc_typespec
*last_ts
;
14969 int object
, cnt_protected
;
14972 last_ts
= &eq
->expr
->symtree
->n
.sym
->ts
;
14974 first_sym
= eq
->expr
->symtree
->n
.sym
;
14978 for (object
= 1; eq
; eq
= eq
->eq
, object
++)
14982 e
->ts
= e
->symtree
->n
.sym
->ts
;
14983 /* match_varspec might not know yet if it is seeing
14984 array reference or substring reference, as it doesn't
14986 if (e
->ref
&& e
->ref
->type
== REF_ARRAY
)
14988 gfc_ref
*ref
= e
->ref
;
14989 sym
= e
->symtree
->n
.sym
;
14991 if (sym
->attr
.dimension
)
14993 ref
->u
.ar
.as
= sym
->as
;
14997 /* For substrings, convert REF_ARRAY into REF_SUBSTRING. */
14998 if (e
->ts
.type
== BT_CHARACTER
15000 && ref
->type
== REF_ARRAY
15001 && ref
->u
.ar
.dimen
== 1
15002 && ref
->u
.ar
.dimen_type
[0] == DIMEN_RANGE
15003 && ref
->u
.ar
.stride
[0] == NULL
)
15005 gfc_expr
*start
= ref
->u
.ar
.start
[0];
15006 gfc_expr
*end
= ref
->u
.ar
.end
[0];
15009 /* Optimize away the (:) reference. */
15010 if (start
== NULL
&& end
== NULL
)
15013 e
->ref
= ref
->next
;
15015 e
->ref
->next
= ref
->next
;
15020 ref
->type
= REF_SUBSTRING
;
15022 start
= gfc_get_int_expr (gfc_default_integer_kind
,
15024 ref
->u
.ss
.start
= start
;
15025 if (end
== NULL
&& e
->ts
.u
.cl
)
15026 end
= gfc_copy_expr (e
->ts
.u
.cl
->length
);
15027 ref
->u
.ss
.end
= end
;
15028 ref
->u
.ss
.length
= e
->ts
.u
.cl
;
15035 /* Any further ref is an error. */
15038 gcc_assert (ref
->type
== REF_ARRAY
);
15039 gfc_error ("Syntax error in EQUIVALENCE statement at %L",
15045 if (!gfc_resolve_expr (e
))
15048 sym
= e
->symtree
->n
.sym
;
15050 if (sym
->attr
.is_protected
)
15052 if (cnt_protected
> 0 && cnt_protected
!= object
)
15054 gfc_error ("Either all or none of the objects in the "
15055 "EQUIVALENCE set at %L shall have the "
15056 "PROTECTED attribute",
15061 /* Shall not equivalence common block variables in a PURE procedure. */
15062 if (sym
->ns
->proc_name
15063 && sym
->ns
->proc_name
->attr
.pure
15064 && sym
->attr
.in_common
)
15066 gfc_error ("Common block member %qs at %L cannot be an EQUIVALENCE "
15067 "object in the pure procedure %qs",
15068 sym
->name
, &e
->where
, sym
->ns
->proc_name
->name
);
15072 /* Shall not be a named constant. */
15073 if (e
->expr_type
== EXPR_CONSTANT
)
15075 gfc_error ("Named constant %qs at %L cannot be an EQUIVALENCE "
15076 "object", sym
->name
, &e
->where
);
15080 if (e
->ts
.type
== BT_DERIVED
15081 && !resolve_equivalence_derived (e
->ts
.u
.derived
, sym
, e
))
15084 /* Check that the types correspond correctly:
15086 A numeric sequence structure may be equivalenced to another sequence
15087 structure, an object of default integer type, default real type, double
15088 precision real type, default logical type such that components of the
15089 structure ultimately only become associated to objects of the same
15090 kind. A character sequence structure may be equivalenced to an object
15091 of default character kind or another character sequence structure.
15092 Other objects may be equivalenced only to objects of the same type and
15093 kind parameters. */
15095 /* Identical types are unconditionally OK. */
15096 if (object
== 1 || gfc_compare_types (last_ts
, &sym
->ts
))
15097 goto identical_types
;
15099 last_eq_type
= sequence_type (*last_ts
);
15100 eq_type
= sequence_type (sym
->ts
);
15102 /* Since the pair of objects is not of the same type, mixed or
15103 non-default sequences can be rejected. */
15105 msg
= "Sequence %s with mixed components in EQUIVALENCE "
15106 "statement at %L with different type objects";
15108 && last_eq_type
== SEQ_MIXED
15109 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
15110 || (eq_type
== SEQ_MIXED
15111 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
15114 msg
= "Non-default type object or sequence %s in EQUIVALENCE "
15115 "statement at %L with objects of different type";
15117 && last_eq_type
== SEQ_NONDEFAULT
15118 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
15119 || (eq_type
== SEQ_NONDEFAULT
15120 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
15123 msg
="Non-CHARACTER object %qs in default CHARACTER "
15124 "EQUIVALENCE statement at %L";
15125 if (last_eq_type
== SEQ_CHARACTER
15126 && eq_type
!= SEQ_CHARACTER
15127 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
15130 msg
="Non-NUMERIC object %qs in default NUMERIC "
15131 "EQUIVALENCE statement at %L";
15132 if (last_eq_type
== SEQ_NUMERIC
15133 && eq_type
!= SEQ_NUMERIC
15134 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
15139 last_where
= &e
->where
;
15144 /* Shall not be an automatic array. */
15145 if (e
->ref
->type
== REF_ARRAY
15146 && !gfc_resolve_array_spec (e
->ref
->u
.ar
.as
, 1))
15148 gfc_error ("Array %qs at %L with non-constant bounds cannot be "
15149 "an EQUIVALENCE object", sym
->name
, &e
->where
);
15156 /* Shall not be a structure component. */
15157 if (r
->type
== REF_COMPONENT
)
15159 gfc_error ("Structure component %qs at %L cannot be an "
15160 "EQUIVALENCE object",
15161 r
->u
.c
.component
->name
, &e
->where
);
15165 /* A substring shall not have length zero. */
15166 if (r
->type
== REF_SUBSTRING
)
15168 if (compare_bound (r
->u
.ss
.start
, r
->u
.ss
.end
) == CMP_GT
)
15170 gfc_error ("Substring at %L has length zero",
15171 &r
->u
.ss
.start
->where
);
15181 /* Resolve function and ENTRY types, issue diagnostics if needed. */
15184 resolve_fntype (gfc_namespace
*ns
)
15186 gfc_entry_list
*el
;
15189 if (ns
->proc_name
== NULL
|| !ns
->proc_name
->attr
.function
)
15192 /* If there are any entries, ns->proc_name is the entry master
15193 synthetic symbol and ns->entries->sym actual FUNCTION symbol. */
15195 sym
= ns
->entries
->sym
;
15197 sym
= ns
->proc_name
;
15198 if (sym
->result
== sym
15199 && sym
->ts
.type
== BT_UNKNOWN
15200 && !gfc_set_default_type (sym
, 0, NULL
)
15201 && !sym
->attr
.untyped
)
15203 gfc_error ("Function %qs at %L has no IMPLICIT type",
15204 sym
->name
, &sym
->declared_at
);
15205 sym
->attr
.untyped
= 1;
15208 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->ts
.u
.derived
->attr
.use_assoc
15209 && !sym
->attr
.contained
15210 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
15211 && gfc_check_symbol_access (sym
))
15213 gfc_notify_std (GFC_STD_F2003
, "PUBLIC function %qs at "
15214 "%L of PRIVATE type %qs", sym
->name
,
15215 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
15219 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
15221 if (el
->sym
->result
== el
->sym
15222 && el
->sym
->ts
.type
== BT_UNKNOWN
15223 && !gfc_set_default_type (el
->sym
, 0, NULL
)
15224 && !el
->sym
->attr
.untyped
)
15226 gfc_error ("ENTRY %qs at %L has no IMPLICIT type",
15227 el
->sym
->name
, &el
->sym
->declared_at
);
15228 el
->sym
->attr
.untyped
= 1;
15234 /* 12.3.2.1.1 Defined operators. */
15237 check_uop_procedure (gfc_symbol
*sym
, locus where
)
15239 gfc_formal_arglist
*formal
;
15241 if (!sym
->attr
.function
)
15243 gfc_error ("User operator procedure %qs at %L must be a FUNCTION",
15244 sym
->name
, &where
);
15248 if (sym
->ts
.type
== BT_CHARACTER
15249 && !(sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
)
15250 && !(sym
->result
&& sym
->result
->ts
.u
.cl
15251 && sym
->result
->ts
.u
.cl
->length
))
15253 gfc_error ("User operator procedure %qs at %L cannot be assumed "
15254 "character length", sym
->name
, &where
);
15258 formal
= gfc_sym_get_dummy_args (sym
);
15259 if (!formal
|| !formal
->sym
)
15261 gfc_error ("User operator procedure %qs at %L must have at least "
15262 "one argument", sym
->name
, &where
);
15266 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
15268 gfc_error ("First argument of operator interface at %L must be "
15269 "INTENT(IN)", &where
);
15273 if (formal
->sym
->attr
.optional
)
15275 gfc_error ("First argument of operator interface at %L cannot be "
15276 "optional", &where
);
15280 formal
= formal
->next
;
15281 if (!formal
|| !formal
->sym
)
15284 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
15286 gfc_error ("Second argument of operator interface at %L must be "
15287 "INTENT(IN)", &where
);
15291 if (formal
->sym
->attr
.optional
)
15293 gfc_error ("Second argument of operator interface at %L cannot be "
15294 "optional", &where
);
15300 gfc_error ("Operator interface at %L must have, at most, two "
15301 "arguments", &where
);
15309 gfc_resolve_uops (gfc_symtree
*symtree
)
15311 gfc_interface
*itr
;
15313 if (symtree
== NULL
)
15316 gfc_resolve_uops (symtree
->left
);
15317 gfc_resolve_uops (symtree
->right
);
15319 for (itr
= symtree
->n
.uop
->op
; itr
; itr
= itr
->next
)
15320 check_uop_procedure (itr
->sym
, itr
->sym
->declared_at
);
15324 /* Examine all of the expressions associated with a program unit,
15325 assign types to all intermediate expressions, make sure that all
15326 assignments are to compatible types and figure out which names
15327 refer to which functions or subroutines. It doesn't check code
15328 block, which is handled by gfc_resolve_code. */
15331 resolve_types (gfc_namespace
*ns
)
15337 gfc_namespace
* old_ns
= gfc_current_ns
;
15339 if (ns
->types_resolved
)
15342 /* Check that all IMPLICIT types are ok. */
15343 if (!ns
->seen_implicit_none
)
15346 for (letter
= 0; letter
!= GFC_LETTERS
; ++letter
)
15347 if (ns
->set_flag
[letter
]
15348 && !resolve_typespec_used (&ns
->default_type
[letter
],
15349 &ns
->implicit_loc
[letter
], NULL
))
15353 gfc_current_ns
= ns
;
15355 resolve_entries (ns
);
15357 resolve_common_vars (&ns
->blank_common
, false);
15358 resolve_common_blocks (ns
->common_root
);
15360 resolve_contained_functions (ns
);
15362 if (ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
15363 && ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
15364 resolve_formal_arglist (ns
->proc_name
);
15366 gfc_traverse_ns (ns
, resolve_bind_c_derived_types
);
15368 for (cl
= ns
->cl_list
; cl
; cl
= cl
->next
)
15369 resolve_charlen (cl
);
15371 gfc_traverse_ns (ns
, resolve_symbol
);
15373 resolve_fntype (ns
);
15375 for (n
= ns
->contained
; n
; n
= n
->sibling
)
15377 if (gfc_pure (ns
->proc_name
) && !gfc_pure (n
->proc_name
))
15378 gfc_error ("Contained procedure %qs at %L of a PURE procedure must "
15379 "also be PURE", n
->proc_name
->name
,
15380 &n
->proc_name
->declared_at
);
15386 gfc_do_concurrent_flag
= 0;
15387 gfc_check_interfaces (ns
);
15389 gfc_traverse_ns (ns
, resolve_values
);
15395 for (d
= ns
->data
; d
; d
= d
->next
)
15399 gfc_traverse_ns (ns
, gfc_formalize_init_value
);
15401 gfc_traverse_ns (ns
, gfc_verify_binding_labels
);
15403 for (eq
= ns
->equiv
; eq
; eq
= eq
->next
)
15404 resolve_equivalence (eq
);
15406 /* Warn about unused labels. */
15407 if (warn_unused_label
)
15408 warn_unused_fortran_label (ns
->st_labels
);
15410 gfc_resolve_uops (ns
->uop_root
);
15412 gfc_resolve_omp_declare_simd (ns
);
15414 gfc_resolve_omp_udrs (ns
->omp_udr_root
);
15416 ns
->types_resolved
= 1;
15418 gfc_current_ns
= old_ns
;
15422 /* Call gfc_resolve_code recursively. */
15425 resolve_codes (gfc_namespace
*ns
)
15428 bitmap_obstack old_obstack
;
15430 if (ns
->resolved
== 1)
15433 for (n
= ns
->contained
; n
; n
= n
->sibling
)
15436 gfc_current_ns
= ns
;
15438 /* Don't clear 'cs_base' if this is the namespace of a BLOCK construct. */
15439 if (!(ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_LABEL
))
15442 /* Set to an out of range value. */
15443 current_entry_id
= -1;
15445 old_obstack
= labels_obstack
;
15446 bitmap_obstack_initialize (&labels_obstack
);
15448 gfc_resolve_oacc_declare (ns
);
15449 gfc_resolve_code (ns
->code
, ns
);
15451 bitmap_obstack_release (&labels_obstack
);
15452 labels_obstack
= old_obstack
;
15456 /* This function is called after a complete program unit has been compiled.
15457 Its purpose is to examine all of the expressions associated with a program
15458 unit, assign types to all intermediate expressions, make sure that all
15459 assignments are to compatible types and figure out which names refer to
15460 which functions or subroutines. */
15463 gfc_resolve (gfc_namespace
*ns
)
15465 gfc_namespace
*old_ns
;
15466 code_stack
*old_cs_base
;
15467 struct gfc_omp_saved_state old_omp_state
;
15473 old_ns
= gfc_current_ns
;
15474 old_cs_base
= cs_base
;
15476 /* As gfc_resolve can be called during resolution of an OpenMP construct
15477 body, we should clear any state associated to it, so that say NS's
15478 DO loops are not interpreted as OpenMP loops. */
15479 gfc_omp_save_and_clear_state (&old_omp_state
);
15481 resolve_types (ns
);
15482 component_assignment_level
= 0;
15483 resolve_codes (ns
);
15485 gfc_current_ns
= old_ns
;
15486 cs_base
= old_cs_base
;
15489 gfc_run_passes (ns
);
15491 gfc_omp_restore_state (&old_omp_state
);