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_OACC_ROUTINE
:
9377 case EXEC_OMP_ATOMIC
:
9378 case EXEC_OMP_CRITICAL
:
9379 case EXEC_OMP_DISTRIBUTE
:
9380 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
9381 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
9382 case EXEC_OMP_DISTRIBUTE_SIMD
:
9384 case EXEC_OMP_DO_SIMD
:
9385 case EXEC_OMP_MASTER
:
9386 case EXEC_OMP_ORDERED
:
9387 case EXEC_OMP_PARALLEL
:
9388 case EXEC_OMP_PARALLEL_DO
:
9389 case EXEC_OMP_PARALLEL_DO_SIMD
:
9390 case EXEC_OMP_PARALLEL_SECTIONS
:
9391 case EXEC_OMP_PARALLEL_WORKSHARE
:
9392 case EXEC_OMP_SECTIONS
:
9394 case EXEC_OMP_SINGLE
:
9395 case EXEC_OMP_TARGET
:
9396 case EXEC_OMP_TARGET_DATA
:
9397 case EXEC_OMP_TARGET_TEAMS
:
9398 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
9399 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
9400 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
9401 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
9402 case EXEC_OMP_TARGET_UPDATE
:
9404 case EXEC_OMP_TASKGROUP
:
9405 case EXEC_OMP_TASKWAIT
:
9406 case EXEC_OMP_TASKYIELD
:
9407 case EXEC_OMP_TEAMS
:
9408 case EXEC_OMP_TEAMS_DISTRIBUTE
:
9409 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
9410 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
9411 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
9412 case EXEC_OMP_WORKSHARE
:
9416 gfc_internal_error ("gfc_resolve_blocks(): Bad block type");
9419 gfc_resolve_code (b
->next
, ns
);
9424 /* Does everything to resolve an ordinary assignment. Returns true
9425 if this is an interface assignment. */
9427 resolve_ordinary_assign (gfc_code
*code
, gfc_namespace
*ns
)
9436 symbol_attribute attr
;
9438 if (gfc_extend_assign (code
, ns
))
9442 if (code
->op
== EXEC_ASSIGN_CALL
)
9444 lhs
= code
->ext
.actual
->expr
;
9445 rhsptr
= &code
->ext
.actual
->next
->expr
;
9449 gfc_actual_arglist
* args
;
9450 gfc_typebound_proc
* tbp
;
9452 gcc_assert (code
->op
== EXEC_COMPCALL
);
9454 args
= code
->expr1
->value
.compcall
.actual
;
9456 rhsptr
= &args
->next
->expr
;
9458 tbp
= code
->expr1
->value
.compcall
.tbp
;
9459 gcc_assert (!tbp
->is_generic
);
9462 /* Make a temporary rhs when there is a default initializer
9463 and rhs is the same symbol as the lhs. */
9464 if ((*rhsptr
)->expr_type
== EXPR_VARIABLE
9465 && (*rhsptr
)->symtree
->n
.sym
->ts
.type
== BT_DERIVED
9466 && gfc_has_default_initializer ((*rhsptr
)->symtree
->n
.sym
->ts
.u
.derived
)
9467 && (lhs
->symtree
->n
.sym
== (*rhsptr
)->symtree
->n
.sym
))
9468 *rhsptr
= gfc_get_parentheses (*rhsptr
);
9477 && !gfc_notify_std (GFC_STD_GNU
, "BOZ literal at %L outside "
9478 "a DATA statement and outside INT/REAL/DBLE/CMPLX",
9482 /* Handle the case of a BOZ literal on the RHS. */
9483 if (rhs
->is_boz
&& lhs
->ts
.type
!= BT_INTEGER
)
9486 if (warn_surprising
)
9487 gfc_warning (OPT_Wsurprising
,
9488 "BOZ literal at %L is bitwise transferred "
9489 "non-integer symbol %qs", &code
->loc
,
9490 lhs
->symtree
->n
.sym
->name
);
9492 if (!gfc_convert_boz (rhs
, &lhs
->ts
))
9494 if ((rc
= gfc_range_check (rhs
)) != ARITH_OK
)
9496 if (rc
== ARITH_UNDERFLOW
)
9497 gfc_error ("Arithmetic underflow of bit-wise transferred BOZ at %L"
9498 ". This check can be disabled with the option "
9499 "%<-fno-range-check%>", &rhs
->where
);
9500 else if (rc
== ARITH_OVERFLOW
)
9501 gfc_error ("Arithmetic overflow of bit-wise transferred BOZ at %L"
9502 ". This check can be disabled with the option "
9503 "%<-fno-range-check%>", &rhs
->where
);
9504 else if (rc
== ARITH_NAN
)
9505 gfc_error ("Arithmetic NaN of bit-wise transferred BOZ at %L"
9506 ". This check can be disabled with the option "
9507 "%<-fno-range-check%>", &rhs
->where
);
9512 if (lhs
->ts
.type
== BT_CHARACTER
9513 && warn_character_truncation
)
9515 if (lhs
->ts
.u
.cl
!= NULL
9516 && lhs
->ts
.u
.cl
->length
!= NULL
9517 && lhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9518 llen
= mpz_get_si (lhs
->ts
.u
.cl
->length
->value
.integer
);
9520 if (rhs
->expr_type
== EXPR_CONSTANT
)
9521 rlen
= rhs
->value
.character
.length
;
9523 else if (rhs
->ts
.u
.cl
!= NULL
9524 && rhs
->ts
.u
.cl
->length
!= NULL
9525 && rhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9526 rlen
= mpz_get_si (rhs
->ts
.u
.cl
->length
->value
.integer
);
9528 if (rlen
&& llen
&& rlen
> llen
)
9529 gfc_warning_now (OPT_Wcharacter_truncation
,
9530 "CHARACTER expression will be truncated "
9531 "in assignment (%d/%d) at %L",
9532 llen
, rlen
, &code
->loc
);
9535 /* Ensure that a vector index expression for the lvalue is evaluated
9536 to a temporary if the lvalue symbol is referenced in it. */
9539 for (ref
= lhs
->ref
; ref
; ref
= ref
->next
)
9540 if (ref
->type
== REF_ARRAY
)
9542 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
9543 if (ref
->u
.ar
.dimen_type
[n
] == DIMEN_VECTOR
9544 && gfc_find_sym_in_expr (lhs
->symtree
->n
.sym
,
9545 ref
->u
.ar
.start
[n
]))
9547 = gfc_get_parentheses (ref
->u
.ar
.start
[n
]);
9551 if (gfc_pure (NULL
))
9553 if (lhs
->ts
.type
== BT_DERIVED
9554 && lhs
->expr_type
== EXPR_VARIABLE
9555 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9556 && rhs
->expr_type
== EXPR_VARIABLE
9557 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9558 || gfc_is_coindexed (rhs
)))
9561 if (gfc_is_coindexed (rhs
))
9562 gfc_error ("Coindexed expression at %L is assigned to "
9563 "a derived type variable with a POINTER "
9564 "component in a PURE procedure",
9567 gfc_error ("The impure variable at %L is assigned to "
9568 "a derived type variable with a POINTER "
9569 "component in a PURE procedure (12.6)",
9574 /* Fortran 2008, C1283. */
9575 if (gfc_is_coindexed (lhs
))
9577 gfc_error ("Assignment to coindexed variable at %L in a PURE "
9578 "procedure", &rhs
->where
);
9583 if (gfc_implicit_pure (NULL
))
9585 if (lhs
->expr_type
== EXPR_VARIABLE
9586 && lhs
->symtree
->n
.sym
!= gfc_current_ns
->proc_name
9587 && lhs
->symtree
->n
.sym
->ns
!= gfc_current_ns
)
9588 gfc_unset_implicit_pure (NULL
);
9590 if (lhs
->ts
.type
== BT_DERIVED
9591 && lhs
->expr_type
== EXPR_VARIABLE
9592 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9593 && rhs
->expr_type
== EXPR_VARIABLE
9594 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9595 || gfc_is_coindexed (rhs
)))
9596 gfc_unset_implicit_pure (NULL
);
9598 /* Fortran 2008, C1283. */
9599 if (gfc_is_coindexed (lhs
))
9600 gfc_unset_implicit_pure (NULL
);
9603 /* F2008, 7.2.1.2. */
9604 attr
= gfc_expr_attr (lhs
);
9605 if (lhs
->ts
.type
== BT_CLASS
&& attr
.allocatable
)
9607 if (attr
.codimension
)
9609 gfc_error ("Assignment to polymorphic coarray at %L is not "
9610 "permitted", &lhs
->where
);
9613 if (!gfc_notify_std (GFC_STD_F2008
, "Assignment to an allocatable "
9614 "polymorphic variable at %L", &lhs
->where
))
9616 if (!flag_realloc_lhs
)
9618 gfc_error ("Assignment to an allocatable polymorphic variable at %L "
9619 "requires %<-frealloc-lhs%>", &lhs
->where
);
9623 gfc_error ("Assignment to an allocatable polymorphic variable at %L "
9624 "is not yet supported", &lhs
->where
);
9627 else if (lhs
->ts
.type
== BT_CLASS
)
9629 gfc_error ("Nonallocatable variable must not be polymorphic in intrinsic "
9630 "assignment at %L - check that there is a matching specific "
9631 "subroutine for '=' operator", &lhs
->where
);
9635 bool lhs_coindexed
= gfc_is_coindexed (lhs
);
9637 /* F2008, Section 7.2.1.2. */
9638 if (lhs_coindexed
&& gfc_has_ultimate_allocatable (lhs
))
9640 gfc_error ("Coindexed variable must not have an allocatable ultimate "
9641 "component in assignment at %L", &lhs
->where
);
9645 gfc_check_assign (lhs
, rhs
, 1);
9647 /* Assign the 'data' of a class object to a derived type. */
9648 if (lhs
->ts
.type
== BT_DERIVED
9649 && rhs
->ts
.type
== BT_CLASS
)
9650 gfc_add_data_component (rhs
);
9652 /* Insert a GFC_ISYM_CAF_SEND intrinsic, when the LHS is a coindexed variable.
9653 Additionally, insert this code when the RHS is a CAF as we then use the
9654 GFC_ISYM_CAF_SEND intrinsic just to avoid a temporary; but do not do so if
9655 the LHS is (re)allocatable or has a vector subscript. If the LHS is a
9656 noncoindexed array and the RHS is a coindexed scalar, use the normal code
9658 if (flag_coarray
== GFC_FCOARRAY_LIB
9660 || (code
->expr2
->expr_type
== EXPR_FUNCTION
9661 && code
->expr2
->value
.function
.isym
9662 && code
->expr2
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
9663 && (code
->expr1
->rank
== 0 || code
->expr2
->rank
!= 0)
9664 && !gfc_expr_attr (rhs
).allocatable
9665 && !gfc_has_vector_subscript (rhs
))))
9667 if (code
->expr2
->expr_type
== EXPR_FUNCTION
9668 && code
->expr2
->value
.function
.isym
9669 && code
->expr2
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
9670 remove_caf_get_intrinsic (code
->expr2
);
9671 code
->op
= EXEC_CALL
;
9672 gfc_get_sym_tree (GFC_PREFIX ("caf_send"), ns
, &code
->symtree
, true);
9673 code
->resolved_sym
= code
->symtree
->n
.sym
;
9674 code
->resolved_sym
->attr
.flavor
= FL_PROCEDURE
;
9675 code
->resolved_sym
->attr
.intrinsic
= 1;
9676 code
->resolved_sym
->attr
.subroutine
= 1;
9677 code
->resolved_isym
= gfc_intrinsic_subroutine_by_id (GFC_ISYM_CAF_SEND
);
9678 gfc_commit_symbol (code
->resolved_sym
);
9679 code
->ext
.actual
= gfc_get_actual_arglist ();
9680 code
->ext
.actual
->expr
= lhs
;
9681 code
->ext
.actual
->next
= gfc_get_actual_arglist ();
9682 code
->ext
.actual
->next
->expr
= rhs
;
9691 /* Add a component reference onto an expression. */
9694 add_comp_ref (gfc_expr
*e
, gfc_component
*c
)
9699 ref
= &((*ref
)->next
);
9700 *ref
= gfc_get_ref ();
9701 (*ref
)->type
= REF_COMPONENT
;
9702 (*ref
)->u
.c
.sym
= e
->ts
.u
.derived
;
9703 (*ref
)->u
.c
.component
= c
;
9706 /* Add a full array ref, as necessary. */
9709 gfc_add_full_array_ref (e
, c
->as
);
9710 e
->rank
= c
->as
->rank
;
9715 /* Build an assignment. Keep the argument 'op' for future use, so that
9716 pointer assignments can be made. */
9719 build_assignment (gfc_exec_op op
, gfc_expr
*expr1
, gfc_expr
*expr2
,
9720 gfc_component
*comp1
, gfc_component
*comp2
, locus loc
)
9722 gfc_code
*this_code
;
9724 this_code
= gfc_get_code (op
);
9725 this_code
->next
= NULL
;
9726 this_code
->expr1
= gfc_copy_expr (expr1
);
9727 this_code
->expr2
= gfc_copy_expr (expr2
);
9728 this_code
->loc
= loc
;
9731 add_comp_ref (this_code
->expr1
, comp1
);
9732 add_comp_ref (this_code
->expr2
, comp2
);
9739 /* Makes a temporary variable expression based on the characteristics of
9740 a given variable expression. */
9743 get_temp_from_expr (gfc_expr
*e
, gfc_namespace
*ns
)
9745 static int serial
= 0;
9746 char name
[GFC_MAX_SYMBOL_LEN
];
9749 gfc_array_ref
*aref
;
9752 sprintf (name
, GFC_PREFIX("DA%d"), serial
++);
9753 gfc_get_sym_tree (name
, ns
, &tmp
, false);
9754 gfc_add_type (tmp
->n
.sym
, &e
->ts
, NULL
);
9760 /* Obtain the arrayspec for the temporary. */
9761 if (e
->rank
&& e
->expr_type
!= EXPR_ARRAY
9762 && e
->expr_type
!= EXPR_FUNCTION
9763 && e
->expr_type
!= EXPR_OP
)
9765 aref
= gfc_find_array_ref (e
);
9766 if (e
->expr_type
== EXPR_VARIABLE
9767 && e
->symtree
->n
.sym
->as
== aref
->as
)
9771 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
9772 if (ref
->type
== REF_COMPONENT
9773 && ref
->u
.c
.component
->as
== aref
->as
)
9781 /* Add the attributes and the arrayspec to the temporary. */
9782 tmp
->n
.sym
->attr
= gfc_expr_attr (e
);
9783 tmp
->n
.sym
->attr
.function
= 0;
9784 tmp
->n
.sym
->attr
.result
= 0;
9785 tmp
->n
.sym
->attr
.flavor
= FL_VARIABLE
;
9789 tmp
->n
.sym
->as
= gfc_copy_array_spec (as
);
9792 if (as
->type
== AS_DEFERRED
)
9793 tmp
->n
.sym
->attr
.allocatable
= 1;
9795 else if (e
->rank
&& (e
->expr_type
== EXPR_ARRAY
9796 || e
->expr_type
== EXPR_FUNCTION
9797 || e
->expr_type
== EXPR_OP
))
9799 tmp
->n
.sym
->as
= gfc_get_array_spec ();
9800 tmp
->n
.sym
->as
->type
= AS_DEFERRED
;
9801 tmp
->n
.sym
->as
->rank
= e
->rank
;
9802 tmp
->n
.sym
->attr
.allocatable
= 1;
9803 tmp
->n
.sym
->attr
.dimension
= 1;
9806 tmp
->n
.sym
->attr
.dimension
= 0;
9808 gfc_set_sym_referenced (tmp
->n
.sym
);
9809 gfc_commit_symbol (tmp
->n
.sym
);
9810 e
= gfc_lval_expr_from_sym (tmp
->n
.sym
);
9812 /* Should the lhs be a section, use its array ref for the
9813 temporary expression. */
9814 if (aref
&& aref
->type
!= AR_FULL
)
9816 gfc_free_ref_list (e
->ref
);
9817 e
->ref
= gfc_copy_ref (ref
);
9823 /* Add one line of code to the code chain, making sure that 'head' and
9824 'tail' are appropriately updated. */
9827 add_code_to_chain (gfc_code
**this_code
, gfc_code
**head
, gfc_code
**tail
)
9829 gcc_assert (this_code
);
9831 *head
= *tail
= *this_code
;
9833 *tail
= gfc_append_code (*tail
, *this_code
);
9838 /* Counts the potential number of part array references that would
9839 result from resolution of typebound defined assignments. */
9842 nonscalar_typebound_assign (gfc_symbol
*derived
, int depth
)
9845 int c_depth
= 0, t_depth
;
9847 for (c
= derived
->components
; c
; c
= c
->next
)
9849 if ((c
->ts
.type
!= BT_DERIVED
9851 || c
->attr
.allocatable
9852 || c
->attr
.proc_pointer_comp
9853 || c
->attr
.class_pointer
9854 || c
->attr
.proc_pointer
)
9855 && !c
->attr
.defined_assign_comp
)
9858 if (c
->as
&& c_depth
== 0)
9861 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
9862 t_depth
= nonscalar_typebound_assign (c
->ts
.u
.derived
,
9867 c_depth
= t_depth
> c_depth
? t_depth
: c_depth
;
9869 return depth
+ c_depth
;
9873 /* Implement 7.2.1.3 of the F08 standard:
9874 "An intrinsic assignment where the variable is of derived type is
9875 performed as if each component of the variable were assigned from the
9876 corresponding component of expr using pointer assignment (7.2.2) for
9877 each pointer component, defined assignment for each nonpointer
9878 nonallocatable component of a type that has a type-bound defined
9879 assignment consistent with the component, intrinsic assignment for
9880 each other nonpointer nonallocatable component, ..."
9882 The pointer assignments are taken care of by the intrinsic
9883 assignment of the structure itself. This function recursively adds
9884 defined assignments where required. The recursion is accomplished
9885 by calling gfc_resolve_code.
9887 When the lhs in a defined assignment has intent INOUT, we need a
9888 temporary for the lhs. In pseudo-code:
9890 ! Only call function lhs once.
9891 if (lhs is not a constant or an variable)
9894 ! Do the intrinsic assignment
9896 ! Now do the defined assignments
9897 do over components with typebound defined assignment [%cmp]
9898 #if one component's assignment procedure is INOUT
9900 #if expr2 non-variable
9906 t1%cmp {defined=} expr2%cmp
9912 expr1%cmp {defined=} expr2%cmp
9916 /* The temporary assignments have to be put on top of the additional
9917 code to avoid the result being changed by the intrinsic assignment.
9919 static int component_assignment_level
= 0;
9920 static gfc_code
*tmp_head
= NULL
, *tmp_tail
= NULL
;
9923 generate_component_assignments (gfc_code
**code
, gfc_namespace
*ns
)
9925 gfc_component
*comp1
, *comp2
;
9926 gfc_code
*this_code
= NULL
, *head
= NULL
, *tail
= NULL
;
9928 int error_count
, depth
;
9930 gfc_get_errors (NULL
, &error_count
);
9932 /* Filter out continuing processing after an error. */
9934 || (*code
)->expr1
->ts
.type
!= BT_DERIVED
9935 || (*code
)->expr2
->ts
.type
!= BT_DERIVED
)
9938 /* TODO: Handle more than one part array reference in assignments. */
9939 depth
= nonscalar_typebound_assign ((*code
)->expr1
->ts
.u
.derived
,
9940 (*code
)->expr1
->rank
? 1 : 0);
9943 gfc_warning (0, "TODO: type-bound defined assignment(s) at %L not "
9944 "done because multiple part array references would "
9945 "occur in intermediate expressions.", &(*code
)->loc
);
9949 component_assignment_level
++;
9951 /* Create a temporary so that functions get called only once. */
9952 if ((*code
)->expr2
->expr_type
!= EXPR_VARIABLE
9953 && (*code
)->expr2
->expr_type
!= EXPR_CONSTANT
)
9957 /* Assign the rhs to the temporary. */
9958 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
9959 this_code
= build_assignment (EXEC_ASSIGN
,
9960 tmp_expr
, (*code
)->expr2
,
9961 NULL
, NULL
, (*code
)->loc
);
9962 /* Add the code and substitute the rhs expression. */
9963 add_code_to_chain (&this_code
, &tmp_head
, &tmp_tail
);
9964 gfc_free_expr ((*code
)->expr2
);
9965 (*code
)->expr2
= tmp_expr
;
9968 /* Do the intrinsic assignment. This is not needed if the lhs is one
9969 of the temporaries generated here, since the intrinsic assignment
9970 to the final result already does this. */
9971 if ((*code
)->expr1
->symtree
->n
.sym
->name
[2] != '@')
9973 this_code
= build_assignment (EXEC_ASSIGN
,
9974 (*code
)->expr1
, (*code
)->expr2
,
9975 NULL
, NULL
, (*code
)->loc
);
9976 add_code_to_chain (&this_code
, &head
, &tail
);
9979 comp1
= (*code
)->expr1
->ts
.u
.derived
->components
;
9980 comp2
= (*code
)->expr2
->ts
.u
.derived
->components
;
9983 for (; comp1
; comp1
= comp1
->next
, comp2
= comp2
->next
)
9987 /* The intrinsic assignment does the right thing for pointers
9988 of all kinds and allocatable components. */
9989 if (comp1
->ts
.type
!= BT_DERIVED
9990 || comp1
->attr
.pointer
9991 || comp1
->attr
.allocatable
9992 || comp1
->attr
.proc_pointer_comp
9993 || comp1
->attr
.class_pointer
9994 || comp1
->attr
.proc_pointer
)
9997 /* Make an assigment for this component. */
9998 this_code
= build_assignment (EXEC_ASSIGN
,
9999 (*code
)->expr1
, (*code
)->expr2
,
10000 comp1
, comp2
, (*code
)->loc
);
10002 /* Convert the assignment if there is a defined assignment for
10003 this type. Otherwise, using the call from gfc_resolve_code,
10004 recurse into its components. */
10005 gfc_resolve_code (this_code
, ns
);
10007 if (this_code
->op
== EXEC_ASSIGN_CALL
)
10009 gfc_formal_arglist
*dummy_args
;
10011 /* Check that there is a typebound defined assignment. If not,
10012 then this must be a module defined assignment. We cannot
10013 use the defined_assign_comp attribute here because it must
10014 be this derived type that has the defined assignment and not
10016 if (!(comp1
->ts
.u
.derived
->f2k_derived
10017 && comp1
->ts
.u
.derived
->f2k_derived
10018 ->tb_op
[INTRINSIC_ASSIGN
]))
10020 gfc_free_statements (this_code
);
10025 /* If the first argument of the subroutine has intent INOUT
10026 a temporary must be generated and used instead. */
10027 rsym
= this_code
->resolved_sym
;
10028 dummy_args
= gfc_sym_get_dummy_args (rsym
);
10030 && dummy_args
->sym
->attr
.intent
== INTENT_INOUT
)
10032 gfc_code
*temp_code
;
10035 /* Build the temporary required for the assignment and put
10036 it at the head of the generated code. */
10039 t1
= get_temp_from_expr ((*code
)->expr1
, ns
);
10040 temp_code
= build_assignment (EXEC_ASSIGN
,
10041 t1
, (*code
)->expr1
,
10042 NULL
, NULL
, (*code
)->loc
);
10044 /* For allocatable LHS, check whether it is allocated. Note
10045 that allocatable components with defined assignment are
10046 not yet support. See PR 57696. */
10047 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
)
10051 gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
10052 block
= gfc_get_code (EXEC_IF
);
10053 block
->block
= gfc_get_code (EXEC_IF
);
10054 block
->block
->expr1
10055 = gfc_build_intrinsic_call (ns
,
10056 GFC_ISYM_ALLOCATED
, "allocated",
10057 (*code
)->loc
, 1, e
);
10058 block
->block
->next
= temp_code
;
10061 add_code_to_chain (&temp_code
, &tmp_head
, &tmp_tail
);
10064 /* Replace the first actual arg with the component of the
10066 gfc_free_expr (this_code
->ext
.actual
->expr
);
10067 this_code
->ext
.actual
->expr
= gfc_copy_expr (t1
);
10068 add_comp_ref (this_code
->ext
.actual
->expr
, comp1
);
10070 /* If the LHS variable is allocatable and wasn't allocated and
10071 the temporary is allocatable, pointer assign the address of
10072 the freshly allocated LHS to the temporary. */
10073 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
10074 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
10079 cond
= gfc_get_expr ();
10080 cond
->ts
.type
= BT_LOGICAL
;
10081 cond
->ts
.kind
= gfc_default_logical_kind
;
10082 cond
->expr_type
= EXPR_OP
;
10083 cond
->where
= (*code
)->loc
;
10084 cond
->value
.op
.op
= INTRINSIC_NOT
;
10085 cond
->value
.op
.op1
= gfc_build_intrinsic_call (ns
,
10086 GFC_ISYM_ALLOCATED
, "allocated",
10087 (*code
)->loc
, 1, gfc_copy_expr (t1
));
10088 block
= gfc_get_code (EXEC_IF
);
10089 block
->block
= gfc_get_code (EXEC_IF
);
10090 block
->block
->expr1
= cond
;
10091 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
10092 t1
, (*code
)->expr1
,
10093 NULL
, NULL
, (*code
)->loc
);
10094 add_code_to_chain (&block
, &head
, &tail
);
10098 else if (this_code
->op
== EXEC_ASSIGN
&& !this_code
->next
)
10100 /* Don't add intrinsic assignments since they are already
10101 effected by the intrinsic assignment of the structure. */
10102 gfc_free_statements (this_code
);
10107 add_code_to_chain (&this_code
, &head
, &tail
);
10111 /* Transfer the value to the final result. */
10112 this_code
= build_assignment (EXEC_ASSIGN
,
10113 (*code
)->expr1
, t1
,
10114 comp1
, comp2
, (*code
)->loc
);
10115 add_code_to_chain (&this_code
, &head
, &tail
);
10119 /* Put the temporary assignments at the top of the generated code. */
10120 if (tmp_head
&& component_assignment_level
== 1)
10122 gfc_append_code (tmp_head
, head
);
10124 tmp_head
= tmp_tail
= NULL
;
10127 // If we did a pointer assignment - thus, we need to ensure that the LHS is
10128 // not accidentally deallocated. Hence, nullify t1.
10129 if (t1
&& (*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
10130 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
10136 e
= gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
10137 cond
= gfc_build_intrinsic_call (ns
, GFC_ISYM_ASSOCIATED
, "associated",
10138 (*code
)->loc
, 2, gfc_copy_expr (t1
), e
);
10139 block
= gfc_get_code (EXEC_IF
);
10140 block
->block
= gfc_get_code (EXEC_IF
);
10141 block
->block
->expr1
= cond
;
10142 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
10143 t1
, gfc_get_null_expr (&(*code
)->loc
),
10144 NULL
, NULL
, (*code
)->loc
);
10145 gfc_append_code (tail
, block
);
10149 /* Now attach the remaining code chain to the input code. Step on
10150 to the end of the new code since resolution is complete. */
10151 gcc_assert ((*code
)->op
== EXEC_ASSIGN
);
10152 tail
->next
= (*code
)->next
;
10153 /* Overwrite 'code' because this would place the intrinsic assignment
10154 before the temporary for the lhs is created. */
10155 gfc_free_expr ((*code
)->expr1
);
10156 gfc_free_expr ((*code
)->expr2
);
10162 component_assignment_level
--;
10166 /* F2008: Pointer function assignments are of the form:
10167 ptr_fcn (args) = expr
10168 This function breaks these assignments into two statements:
10169 temporary_pointer => ptr_fcn(args)
10170 temporary_pointer = expr */
10173 resolve_ptr_fcn_assign (gfc_code
**code
, gfc_namespace
*ns
)
10175 gfc_expr
*tmp_ptr_expr
;
10176 gfc_code
*this_code
;
10177 gfc_component
*comp
;
10180 if ((*code
)->expr1
->expr_type
!= EXPR_FUNCTION
)
10183 /* Even if standard does not support this feature, continue to build
10184 the two statements to avoid upsetting frontend_passes.c. */
10185 gfc_notify_std (GFC_STD_F2008
, "Pointer procedure assignment at "
10186 "%L", &(*code
)->loc
);
10188 comp
= gfc_get_proc_ptr_comp ((*code
)->expr1
);
10191 s
= comp
->ts
.interface
;
10193 s
= (*code
)->expr1
->symtree
->n
.sym
;
10195 if (s
== NULL
|| !s
->result
->attr
.pointer
)
10197 gfc_error ("The function result on the lhs of the assignment at "
10198 "%L must have the pointer attribute.",
10199 &(*code
)->expr1
->where
);
10200 (*code
)->op
= EXEC_NOP
;
10204 tmp_ptr_expr
= get_temp_from_expr ((*code
)->expr2
, ns
);
10206 /* get_temp_from_expression is set up for ordinary assignments. To that
10207 end, where array bounds are not known, arrays are made allocatable.
10208 Change the temporary to a pointer here. */
10209 tmp_ptr_expr
->symtree
->n
.sym
->attr
.pointer
= 1;
10210 tmp_ptr_expr
->symtree
->n
.sym
->attr
.allocatable
= 0;
10211 tmp_ptr_expr
->where
= (*code
)->loc
;
10213 this_code
= build_assignment (EXEC_ASSIGN
,
10214 tmp_ptr_expr
, (*code
)->expr2
,
10215 NULL
, NULL
, (*code
)->loc
);
10216 this_code
->next
= (*code
)->next
;
10217 (*code
)->next
= this_code
;
10218 (*code
)->op
= EXEC_POINTER_ASSIGN
;
10219 (*code
)->expr2
= (*code
)->expr1
;
10220 (*code
)->expr1
= tmp_ptr_expr
;
10226 /* Deferred character length assignments from an operator expression
10227 require a temporary because the character length of the lhs can
10228 change in the course of the assignment. */
10231 deferred_op_assign (gfc_code
**code
, gfc_namespace
*ns
)
10233 gfc_expr
*tmp_expr
;
10234 gfc_code
*this_code
;
10236 if (!((*code
)->expr1
->ts
.type
== BT_CHARACTER
10237 && (*code
)->expr1
->ts
.deferred
&& (*code
)->expr1
->rank
10238 && (*code
)->expr2
->expr_type
== EXPR_OP
))
10241 if (!gfc_check_dependency ((*code
)->expr1
, (*code
)->expr2
, 1))
10244 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
10245 tmp_expr
->where
= (*code
)->loc
;
10247 /* A new charlen is required to ensure that the variable string
10248 length is different to that of the original lhs. */
10249 tmp_expr
->ts
.u
.cl
= gfc_get_charlen();
10250 tmp_expr
->symtree
->n
.sym
->ts
.u
.cl
= tmp_expr
->ts
.u
.cl
;
10251 tmp_expr
->ts
.u
.cl
->next
= (*code
)->expr2
->ts
.u
.cl
->next
;
10252 (*code
)->expr2
->ts
.u
.cl
->next
= tmp_expr
->ts
.u
.cl
;
10254 tmp_expr
->symtree
->n
.sym
->ts
.deferred
= 1;
10256 this_code
= build_assignment (EXEC_ASSIGN
,
10258 gfc_copy_expr (tmp_expr
),
10259 NULL
, NULL
, (*code
)->loc
);
10261 (*code
)->expr1
= tmp_expr
;
10263 this_code
->next
= (*code
)->next
;
10264 (*code
)->next
= this_code
;
10270 /* Given a block of code, recursively resolve everything pointed to by this
10274 gfc_resolve_code (gfc_code
*code
, gfc_namespace
*ns
)
10276 int omp_workshare_save
;
10277 int forall_save
, do_concurrent_save
;
10281 frame
.prev
= cs_base
;
10285 find_reachable_labels (code
);
10287 for (; code
; code
= code
->next
)
10289 frame
.current
= code
;
10290 forall_save
= forall_flag
;
10291 do_concurrent_save
= gfc_do_concurrent_flag
;
10293 if (code
->op
== EXEC_FORALL
)
10296 gfc_resolve_forall (code
, ns
, forall_save
);
10299 else if (code
->block
)
10301 omp_workshare_save
= -1;
10304 case EXEC_OACC_PARALLEL_LOOP
:
10305 case EXEC_OACC_PARALLEL
:
10306 case EXEC_OACC_KERNELS_LOOP
:
10307 case EXEC_OACC_KERNELS
:
10308 case EXEC_OACC_DATA
:
10309 case EXEC_OACC_HOST_DATA
:
10310 case EXEC_OACC_LOOP
:
10311 gfc_resolve_oacc_blocks (code
, ns
);
10313 case EXEC_OMP_PARALLEL_WORKSHARE
:
10314 omp_workshare_save
= omp_workshare_flag
;
10315 omp_workshare_flag
= 1;
10316 gfc_resolve_omp_parallel_blocks (code
, ns
);
10318 case EXEC_OMP_PARALLEL
:
10319 case EXEC_OMP_PARALLEL_DO
:
10320 case EXEC_OMP_PARALLEL_DO_SIMD
:
10321 case EXEC_OMP_PARALLEL_SECTIONS
:
10322 case EXEC_OMP_TARGET_TEAMS
:
10323 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
10324 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10325 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10326 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
10327 case EXEC_OMP_TASK
:
10328 case EXEC_OMP_TEAMS
:
10329 case EXEC_OMP_TEAMS_DISTRIBUTE
:
10330 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10331 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10332 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
10333 omp_workshare_save
= omp_workshare_flag
;
10334 omp_workshare_flag
= 0;
10335 gfc_resolve_omp_parallel_blocks (code
, ns
);
10337 case EXEC_OMP_DISTRIBUTE
:
10338 case EXEC_OMP_DISTRIBUTE_SIMD
:
10340 case EXEC_OMP_DO_SIMD
:
10341 case EXEC_OMP_SIMD
:
10342 gfc_resolve_omp_do_blocks (code
, ns
);
10344 case EXEC_SELECT_TYPE
:
10345 /* Blocks are handled in resolve_select_type because we have
10346 to transform the SELECT TYPE into ASSOCIATE first. */
10348 case EXEC_DO_CONCURRENT
:
10349 gfc_do_concurrent_flag
= 1;
10350 gfc_resolve_blocks (code
->block
, ns
);
10351 gfc_do_concurrent_flag
= 2;
10353 case EXEC_OMP_WORKSHARE
:
10354 omp_workshare_save
= omp_workshare_flag
;
10355 omp_workshare_flag
= 1;
10358 gfc_resolve_blocks (code
->block
, ns
);
10362 if (omp_workshare_save
!= -1)
10363 omp_workshare_flag
= omp_workshare_save
;
10367 if (code
->op
!= EXEC_COMPCALL
&& code
->op
!= EXEC_CALL_PPC
)
10368 t
= gfc_resolve_expr (code
->expr1
);
10369 forall_flag
= forall_save
;
10370 gfc_do_concurrent_flag
= do_concurrent_save
;
10372 if (!gfc_resolve_expr (code
->expr2
))
10375 if (code
->op
== EXEC_ALLOCATE
10376 && !gfc_resolve_expr (code
->expr3
))
10382 case EXEC_END_BLOCK
:
10383 case EXEC_END_NESTED_BLOCK
:
10387 case EXEC_ERROR_STOP
:
10389 case EXEC_CONTINUE
:
10391 case EXEC_ASSIGN_CALL
:
10394 case EXEC_CRITICAL
:
10395 resolve_critical (code
);
10398 case EXEC_SYNC_ALL
:
10399 case EXEC_SYNC_IMAGES
:
10400 case EXEC_SYNC_MEMORY
:
10401 resolve_sync (code
);
10406 resolve_lock_unlock (code
);
10410 /* Keep track of which entry we are up to. */
10411 current_entry_id
= code
->ext
.entry
->id
;
10415 resolve_where (code
, NULL
);
10419 if (code
->expr1
!= NULL
)
10421 if (code
->expr1
->ts
.type
!= BT_INTEGER
)
10422 gfc_error ("ASSIGNED GOTO statement at %L requires an "
10423 "INTEGER variable", &code
->expr1
->where
);
10424 else if (code
->expr1
->symtree
->n
.sym
->attr
.assign
!= 1)
10425 gfc_error ("Variable %qs has not been assigned a target "
10426 "label at %L", code
->expr1
->symtree
->n
.sym
->name
,
10427 &code
->expr1
->where
);
10430 resolve_branch (code
->label1
, code
);
10434 if (code
->expr1
!= NULL
10435 && (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
))
10436 gfc_error ("Alternate RETURN statement at %L requires a SCALAR-"
10437 "INTEGER return specifier", &code
->expr1
->where
);
10440 case EXEC_INIT_ASSIGN
:
10441 case EXEC_END_PROCEDURE
:
10448 /* Remove a GFC_ISYM_CAF_GET inserted for a coindexed variable on
10450 if (code
->expr1
->expr_type
== EXPR_FUNCTION
10451 && code
->expr1
->value
.function
.isym
10452 && code
->expr1
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
10453 remove_caf_get_intrinsic (code
->expr1
);
10455 /* If this is a pointer function in an lvalue variable context,
10456 the new code will have to be resolved afresh. This is also the
10457 case with an error, where the code is transformed into NOP to
10458 prevent ICEs downstream. */
10459 if (resolve_ptr_fcn_assign (&code
, ns
)
10460 || code
->op
== EXEC_NOP
)
10463 if (!gfc_check_vardef_context (code
->expr1
, false, false, false,
10467 if (resolve_ordinary_assign (code
, ns
))
10469 if (code
->op
== EXEC_COMPCALL
)
10475 /* Check for dependencies in deferred character length array
10476 assignments and generate a temporary, if necessary. */
10477 if (code
->op
== EXEC_ASSIGN
&& deferred_op_assign (&code
, ns
))
10480 /* F03 7.4.1.3 for non-allocatable, non-pointer components. */
10481 if (code
->op
!= EXEC_CALL
&& code
->expr1
->ts
.type
== BT_DERIVED
10482 && code
->expr1
->ts
.u
.derived
10483 && code
->expr1
->ts
.u
.derived
->attr
.defined_assign_comp
)
10484 generate_component_assignments (&code
, ns
);
10488 case EXEC_LABEL_ASSIGN
:
10489 if (code
->label1
->defined
== ST_LABEL_UNKNOWN
)
10490 gfc_error ("Label %d referenced at %L is never defined",
10491 code
->label1
->value
, &code
->label1
->where
);
10493 && (code
->expr1
->expr_type
!= EXPR_VARIABLE
10494 || code
->expr1
->symtree
->n
.sym
->ts
.type
!= BT_INTEGER
10495 || code
->expr1
->symtree
->n
.sym
->ts
.kind
10496 != gfc_default_integer_kind
10497 || code
->expr1
->symtree
->n
.sym
->as
!= NULL
))
10498 gfc_error ("ASSIGN statement at %L requires a scalar "
10499 "default INTEGER variable", &code
->expr1
->where
);
10502 case EXEC_POINTER_ASSIGN
:
10509 /* This is both a variable definition and pointer assignment
10510 context, so check both of them. For rank remapping, a final
10511 array ref may be present on the LHS and fool gfc_expr_attr
10512 used in gfc_check_vardef_context. Remove it. */
10513 e
= remove_last_array_ref (code
->expr1
);
10514 t
= gfc_check_vardef_context (e
, true, false, false,
10515 _("pointer assignment"));
10517 t
= gfc_check_vardef_context (e
, false, false, false,
10518 _("pointer assignment"));
10523 gfc_check_pointer_assign (code
->expr1
, code
->expr2
);
10527 case EXEC_ARITHMETIC_IF
:
10529 gfc_expr
*e
= code
->expr1
;
10531 gfc_resolve_expr (e
);
10532 if (e
->expr_type
== EXPR_NULL
)
10533 gfc_error ("Invalid NULL at %L", &e
->where
);
10535 if (t
&& (e
->rank
> 0
10536 || !(e
->ts
.type
== BT_REAL
|| e
->ts
.type
== BT_INTEGER
)))
10537 gfc_error ("Arithmetic IF statement at %L requires a scalar "
10538 "REAL or INTEGER expression", &e
->where
);
10540 resolve_branch (code
->label1
, code
);
10541 resolve_branch (code
->label2
, code
);
10542 resolve_branch (code
->label3
, code
);
10547 if (t
&& code
->expr1
!= NULL
10548 && (code
->expr1
->ts
.type
!= BT_LOGICAL
10549 || code
->expr1
->rank
!= 0))
10550 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
10551 &code
->expr1
->where
);
10556 resolve_call (code
);
10559 case EXEC_COMPCALL
:
10561 resolve_typebound_subroutine (code
);
10564 case EXEC_CALL_PPC
:
10565 resolve_ppc_call (code
);
10569 /* Select is complicated. Also, a SELECT construct could be
10570 a transformed computed GOTO. */
10571 resolve_select (code
, false);
10574 case EXEC_SELECT_TYPE
:
10575 resolve_select_type (code
, ns
);
10579 resolve_block_construct (code
);
10583 if (code
->ext
.iterator
!= NULL
)
10585 gfc_iterator
*iter
= code
->ext
.iterator
;
10586 if (gfc_resolve_iterator (iter
, true, false))
10587 gfc_resolve_do_iterator (code
, iter
->var
->symtree
->n
.sym
);
10591 case EXEC_DO_WHILE
:
10592 if (code
->expr1
== NULL
)
10593 gfc_internal_error ("gfc_resolve_code(): No expression on "
10596 && (code
->expr1
->rank
!= 0
10597 || code
->expr1
->ts
.type
!= BT_LOGICAL
))
10598 gfc_error ("Exit condition of DO WHILE loop at %L must be "
10599 "a scalar LOGICAL expression", &code
->expr1
->where
);
10602 case EXEC_ALLOCATE
:
10604 resolve_allocate_deallocate (code
, "ALLOCATE");
10608 case EXEC_DEALLOCATE
:
10610 resolve_allocate_deallocate (code
, "DEALLOCATE");
10615 if (!gfc_resolve_open (code
->ext
.open
))
10618 resolve_branch (code
->ext
.open
->err
, code
);
10622 if (!gfc_resolve_close (code
->ext
.close
))
10625 resolve_branch (code
->ext
.close
->err
, code
);
10628 case EXEC_BACKSPACE
:
10632 if (!gfc_resolve_filepos (code
->ext
.filepos
))
10635 resolve_branch (code
->ext
.filepos
->err
, code
);
10639 if (!gfc_resolve_inquire (code
->ext
.inquire
))
10642 resolve_branch (code
->ext
.inquire
->err
, code
);
10645 case EXEC_IOLENGTH
:
10646 gcc_assert (code
->ext
.inquire
!= NULL
);
10647 if (!gfc_resolve_inquire (code
->ext
.inquire
))
10650 resolve_branch (code
->ext
.inquire
->err
, code
);
10654 if (!gfc_resolve_wait (code
->ext
.wait
))
10657 resolve_branch (code
->ext
.wait
->err
, code
);
10658 resolve_branch (code
->ext
.wait
->end
, code
);
10659 resolve_branch (code
->ext
.wait
->eor
, code
);
10664 if (!gfc_resolve_dt (code
->ext
.dt
, &code
->loc
))
10667 resolve_branch (code
->ext
.dt
->err
, code
);
10668 resolve_branch (code
->ext
.dt
->end
, code
);
10669 resolve_branch (code
->ext
.dt
->eor
, code
);
10672 case EXEC_TRANSFER
:
10673 resolve_transfer (code
);
10676 case EXEC_DO_CONCURRENT
:
10678 resolve_forall_iterators (code
->ext
.forall_iterator
);
10680 if (code
->expr1
!= NULL
10681 && (code
->expr1
->ts
.type
!= BT_LOGICAL
|| code
->expr1
->rank
))
10682 gfc_error ("FORALL mask clause at %L requires a scalar LOGICAL "
10683 "expression", &code
->expr1
->where
);
10686 case EXEC_OACC_PARALLEL_LOOP
:
10687 case EXEC_OACC_PARALLEL
:
10688 case EXEC_OACC_KERNELS_LOOP
:
10689 case EXEC_OACC_KERNELS
:
10690 case EXEC_OACC_DATA
:
10691 case EXEC_OACC_HOST_DATA
:
10692 case EXEC_OACC_LOOP
:
10693 case EXEC_OACC_UPDATE
:
10694 case EXEC_OACC_WAIT
:
10695 case EXEC_OACC_CACHE
:
10696 case EXEC_OACC_ENTER_DATA
:
10697 case EXEC_OACC_EXIT_DATA
:
10698 case EXEC_OACC_ATOMIC
:
10699 case EXEC_OACC_DECLARE
:
10700 gfc_resolve_oacc_directive (code
, ns
);
10703 case EXEC_OMP_ATOMIC
:
10704 case EXEC_OMP_BARRIER
:
10705 case EXEC_OMP_CANCEL
:
10706 case EXEC_OMP_CANCELLATION_POINT
:
10707 case EXEC_OMP_CRITICAL
:
10708 case EXEC_OMP_FLUSH
:
10709 case EXEC_OMP_DISTRIBUTE
:
10710 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
10711 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
10712 case EXEC_OMP_DISTRIBUTE_SIMD
:
10714 case EXEC_OMP_DO_SIMD
:
10715 case EXEC_OMP_MASTER
:
10716 case EXEC_OMP_ORDERED
:
10717 case EXEC_OMP_SECTIONS
:
10718 case EXEC_OMP_SIMD
:
10719 case EXEC_OMP_SINGLE
:
10720 case EXEC_OMP_TARGET
:
10721 case EXEC_OMP_TARGET_DATA
:
10722 case EXEC_OMP_TARGET_TEAMS
:
10723 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
10724 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10725 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10726 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
10727 case EXEC_OMP_TARGET_UPDATE
:
10728 case EXEC_OMP_TASK
:
10729 case EXEC_OMP_TASKGROUP
:
10730 case EXEC_OMP_TASKWAIT
:
10731 case EXEC_OMP_TASKYIELD
:
10732 case EXEC_OMP_TEAMS
:
10733 case EXEC_OMP_TEAMS_DISTRIBUTE
:
10734 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10735 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10736 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
10737 case EXEC_OMP_WORKSHARE
:
10738 gfc_resolve_omp_directive (code
, ns
);
10741 case EXEC_OMP_PARALLEL
:
10742 case EXEC_OMP_PARALLEL_DO
:
10743 case EXEC_OMP_PARALLEL_DO_SIMD
:
10744 case EXEC_OMP_PARALLEL_SECTIONS
:
10745 case EXEC_OMP_PARALLEL_WORKSHARE
:
10746 omp_workshare_save
= omp_workshare_flag
;
10747 omp_workshare_flag
= 0;
10748 gfc_resolve_omp_directive (code
, ns
);
10749 omp_workshare_flag
= omp_workshare_save
;
10753 gfc_internal_error ("gfc_resolve_code(): Bad statement code");
10757 cs_base
= frame
.prev
;
10761 /* Resolve initial values and make sure they are compatible with
10765 resolve_values (gfc_symbol
*sym
)
10769 if (sym
->value
== NULL
)
10772 if (sym
->value
->expr_type
== EXPR_STRUCTURE
)
10773 t
= resolve_structure_cons (sym
->value
, 1);
10775 t
= gfc_resolve_expr (sym
->value
);
10780 gfc_check_assign_symbol (sym
, NULL
, sym
->value
);
10784 /* Verify any BIND(C) derived types in the namespace so we can report errors
10785 for them once, rather than for each variable declared of that type. */
10788 resolve_bind_c_derived_types (gfc_symbol
*derived_sym
)
10790 if (derived_sym
!= NULL
&& derived_sym
->attr
.flavor
== FL_DERIVED
10791 && derived_sym
->attr
.is_bind_c
== 1)
10792 verify_bind_c_derived_type (derived_sym
);
10798 /* Verify that any binding labels used in a given namespace do not collide
10799 with the names or binding labels of any global symbols. Multiple INTERFACE
10800 for the same procedure are permitted. */
10803 gfc_verify_binding_labels (gfc_symbol
*sym
)
10806 const char *module
;
10808 if (!sym
|| !sym
->attr
.is_bind_c
|| sym
->attr
.is_iso_c
10809 || sym
->attr
.flavor
== FL_DERIVED
|| !sym
->binding_label
)
10812 gsym
= gfc_find_gsymbol (gfc_gsym_root
, sym
->binding_label
);
10815 module
= sym
->module
;
10816 else if (sym
->ns
&& sym
->ns
->proc_name
10817 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
10818 module
= sym
->ns
->proc_name
->name
;
10819 else if (sym
->ns
&& sym
->ns
->parent
10820 && sym
->ns
&& sym
->ns
->parent
->proc_name
10821 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
10822 module
= sym
->ns
->parent
->proc_name
->name
;
10828 && (gsym
->type
== GSYM_FUNCTION
|| gsym
->type
== GSYM_SUBROUTINE
)))
10831 gsym
= gfc_get_gsymbol (sym
->binding_label
);
10832 gsym
->where
= sym
->declared_at
;
10833 gsym
->sym_name
= sym
->name
;
10834 gsym
->binding_label
= sym
->binding_label
;
10835 gsym
->ns
= sym
->ns
;
10836 gsym
->mod_name
= module
;
10837 if (sym
->attr
.function
)
10838 gsym
->type
= GSYM_FUNCTION
;
10839 else if (sym
->attr
.subroutine
)
10840 gsym
->type
= GSYM_SUBROUTINE
;
10841 /* Mark as variable/procedure as defined, unless its an INTERFACE. */
10842 gsym
->defined
= sym
->attr
.if_source
!= IFSRC_IFBODY
;
10846 if (sym
->attr
.flavor
== FL_VARIABLE
&& gsym
->type
!= GSYM_UNKNOWN
)
10848 gfc_error ("Variable %s with binding label %s at %L uses the same global "
10849 "identifier as entity at %L", sym
->name
,
10850 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
10851 /* Clear the binding label to prevent checking multiple times. */
10852 sym
->binding_label
= NULL
;
10855 else if (sym
->attr
.flavor
== FL_VARIABLE
&& module
10856 && (strcmp (module
, gsym
->mod_name
) != 0
10857 || strcmp (sym
->name
, gsym
->sym_name
) != 0))
10859 /* This can only happen if the variable is defined in a module - if it
10860 isn't the same module, reject it. */
10861 gfc_error ("Variable %s from module %s with binding label %s at %L uses "
10862 "the same global identifier as entity at %L from module %s",
10863 sym
->name
, module
, sym
->binding_label
,
10864 &sym
->declared_at
, &gsym
->where
, gsym
->mod_name
);
10865 sym
->binding_label
= NULL
;
10867 else if ((sym
->attr
.function
|| sym
->attr
.subroutine
)
10868 && ((gsym
->type
!= GSYM_SUBROUTINE
&& gsym
->type
!= GSYM_FUNCTION
)
10869 || (gsym
->defined
&& sym
->attr
.if_source
!= IFSRC_IFBODY
))
10870 && sym
!= gsym
->ns
->proc_name
10871 && (module
!= gsym
->mod_name
10872 || strcmp (gsym
->sym_name
, sym
->name
) != 0
10873 || (module
&& strcmp (module
, gsym
->mod_name
) != 0)))
10875 /* Print an error if the procedure is defined multiple times; we have to
10876 exclude references to the same procedure via module association or
10877 multiple checks for the same procedure. */
10878 gfc_error ("Procedure %s with binding label %s at %L uses the same "
10879 "global identifier as entity at %L", sym
->name
,
10880 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
10881 sym
->binding_label
= NULL
;
10886 /* Resolve an index expression. */
10889 resolve_index_expr (gfc_expr
*e
)
10891 if (!gfc_resolve_expr (e
))
10894 if (!gfc_simplify_expr (e
, 0))
10897 if (!gfc_specification_expr (e
))
10904 /* Resolve a charlen structure. */
10907 resolve_charlen (gfc_charlen
*cl
)
10910 bool saved_specification_expr
;
10916 saved_specification_expr
= specification_expr
;
10917 specification_expr
= true;
10919 if (cl
->length_from_typespec
)
10921 if (!gfc_resolve_expr (cl
->length
))
10923 specification_expr
= saved_specification_expr
;
10927 if (!gfc_simplify_expr (cl
->length
, 0))
10929 specification_expr
= saved_specification_expr
;
10936 if (!resolve_index_expr (cl
->length
))
10938 specification_expr
= saved_specification_expr
;
10943 /* F2008, 4.4.3.2: If the character length parameter value evaluates to
10944 a negative value, the length of character entities declared is zero. */
10945 if (cl
->length
&& !gfc_extract_int (cl
->length
, &i
) && i
< 0)
10946 gfc_replace_expr (cl
->length
,
10947 gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 0));
10949 /* Check that the character length is not too large. */
10950 k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
10951 if (cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
10952 && cl
->length
->ts
.type
== BT_INTEGER
10953 && mpz_cmp (cl
->length
->value
.integer
, gfc_integer_kinds
[k
].huge
) > 0)
10955 gfc_error ("String length at %L is too large", &cl
->length
->where
);
10956 specification_expr
= saved_specification_expr
;
10960 specification_expr
= saved_specification_expr
;
10965 /* Test for non-constant shape arrays. */
10968 is_non_constant_shape_array (gfc_symbol
*sym
)
10974 not_constant
= false;
10975 if (sym
->as
!= NULL
)
10977 /* Unfortunately, !gfc_is_compile_time_shape hits a legal case that
10978 has not been simplified; parameter array references. Do the
10979 simplification now. */
10980 for (i
= 0; i
< sym
->as
->rank
+ sym
->as
->corank
; i
++)
10982 e
= sym
->as
->lower
[i
];
10983 if (e
&& (!resolve_index_expr(e
)
10984 || !gfc_is_constant_expr (e
)))
10985 not_constant
= true;
10986 e
= sym
->as
->upper
[i
];
10987 if (e
&& (!resolve_index_expr(e
)
10988 || !gfc_is_constant_expr (e
)))
10989 not_constant
= true;
10992 return not_constant
;
10995 /* Given a symbol and an initialization expression, add code to initialize
10996 the symbol to the function entry. */
10998 build_init_assign (gfc_symbol
*sym
, gfc_expr
*init
)
11002 gfc_namespace
*ns
= sym
->ns
;
11004 /* Search for the function namespace if this is a contained
11005 function without an explicit result. */
11006 if (sym
->attr
.function
&& sym
== sym
->result
11007 && sym
->name
!= sym
->ns
->proc_name
->name
)
11009 ns
= ns
->contained
;
11010 for (;ns
; ns
= ns
->sibling
)
11011 if (strcmp (ns
->proc_name
->name
, sym
->name
) == 0)
11017 gfc_free_expr (init
);
11021 /* Build an l-value expression for the result. */
11022 lval
= gfc_lval_expr_from_sym (sym
);
11024 /* Add the code at scope entry. */
11025 init_st
= gfc_get_code (EXEC_INIT_ASSIGN
);
11026 init_st
->next
= ns
->code
;
11027 ns
->code
= init_st
;
11029 /* Assign the default initializer to the l-value. */
11030 init_st
->loc
= sym
->declared_at
;
11031 init_st
->expr1
= lval
;
11032 init_st
->expr2
= init
;
11035 /* Assign the default initializer to a derived type variable or result. */
11038 apply_default_init (gfc_symbol
*sym
)
11040 gfc_expr
*init
= NULL
;
11042 if (sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
11045 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
)
11046 init
= gfc_default_initializer (&sym
->ts
);
11048 if (init
== NULL
&& sym
->ts
.type
!= BT_CLASS
)
11051 build_init_assign (sym
, init
);
11052 sym
->attr
.referenced
= 1;
11055 /* Build an initializer for a local integer, real, complex, logical, or
11056 character variable, based on the command line flags finit-local-zero,
11057 finit-integer=, finit-real=, finit-logical=, and finit-runtime. Returns
11058 null if the symbol should not have a default initialization. */
11060 build_default_init_expr (gfc_symbol
*sym
)
11063 gfc_expr
*init_expr
;
11066 /* These symbols should never have a default initialization. */
11067 if (sym
->attr
.allocatable
11068 || sym
->attr
.external
11070 || sym
->attr
.pointer
11071 || sym
->attr
.in_equivalence
11072 || sym
->attr
.in_common
11075 || sym
->attr
.cray_pointee
11076 || sym
->attr
.cray_pointer
11080 /* Now we'll try to build an initializer expression. */
11081 init_expr
= gfc_get_constant_expr (sym
->ts
.type
, sym
->ts
.kind
,
11082 &sym
->declared_at
);
11084 /* We will only initialize integers, reals, complex, logicals, and
11085 characters, and only if the corresponding command-line flags
11086 were set. Otherwise, we free init_expr and return null. */
11087 switch (sym
->ts
.type
)
11090 if (gfc_option
.flag_init_integer
!= GFC_INIT_INTEGER_OFF
)
11091 mpz_set_si (init_expr
->value
.integer
,
11092 gfc_option
.flag_init_integer_value
);
11095 gfc_free_expr (init_expr
);
11101 switch (flag_init_real
)
11103 case GFC_INIT_REAL_SNAN
:
11104 init_expr
->is_snan
= 1;
11105 /* Fall through. */
11106 case GFC_INIT_REAL_NAN
:
11107 mpfr_set_nan (init_expr
->value
.real
);
11110 case GFC_INIT_REAL_INF
:
11111 mpfr_set_inf (init_expr
->value
.real
, 1);
11114 case GFC_INIT_REAL_NEG_INF
:
11115 mpfr_set_inf (init_expr
->value
.real
, -1);
11118 case GFC_INIT_REAL_ZERO
:
11119 mpfr_set_ui (init_expr
->value
.real
, 0.0, GFC_RND_MODE
);
11123 gfc_free_expr (init_expr
);
11130 switch (flag_init_real
)
11132 case GFC_INIT_REAL_SNAN
:
11133 init_expr
->is_snan
= 1;
11134 /* Fall through. */
11135 case GFC_INIT_REAL_NAN
:
11136 mpfr_set_nan (mpc_realref (init_expr
->value
.complex));
11137 mpfr_set_nan (mpc_imagref (init_expr
->value
.complex));
11140 case GFC_INIT_REAL_INF
:
11141 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), 1);
11142 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), 1);
11145 case GFC_INIT_REAL_NEG_INF
:
11146 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), -1);
11147 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), -1);
11150 case GFC_INIT_REAL_ZERO
:
11151 mpc_set_ui (init_expr
->value
.complex, 0, GFC_MPC_RND_MODE
);
11155 gfc_free_expr (init_expr
);
11162 if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_FALSE
)
11163 init_expr
->value
.logical
= 0;
11164 else if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_TRUE
)
11165 init_expr
->value
.logical
= 1;
11168 gfc_free_expr (init_expr
);
11174 /* For characters, the length must be constant in order to
11175 create a default initializer. */
11176 if (gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
11177 && sym
->ts
.u
.cl
->length
11178 && sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
11180 char_len
= mpz_get_si (sym
->ts
.u
.cl
->length
->value
.integer
);
11181 init_expr
->value
.character
.length
= char_len
;
11182 init_expr
->value
.character
.string
= gfc_get_wide_string (char_len
+1);
11183 for (i
= 0; i
< char_len
; i
++)
11184 init_expr
->value
.character
.string
[i
]
11185 = (unsigned char) gfc_option
.flag_init_character_value
;
11189 gfc_free_expr (init_expr
);
11192 if (!init_expr
&& gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
11193 && sym
->ts
.u
.cl
->length
&& flag_max_stack_var_size
!= 0)
11195 gfc_actual_arglist
*arg
;
11196 init_expr
= gfc_get_expr ();
11197 init_expr
->where
= sym
->declared_at
;
11198 init_expr
->ts
= sym
->ts
;
11199 init_expr
->expr_type
= EXPR_FUNCTION
;
11200 init_expr
->value
.function
.isym
=
11201 gfc_intrinsic_function_by_id (GFC_ISYM_REPEAT
);
11202 init_expr
->value
.function
.name
= "repeat";
11203 arg
= gfc_get_actual_arglist ();
11204 arg
->expr
= gfc_get_character_expr (sym
->ts
.kind
, &sym
->declared_at
,
11206 arg
->expr
->value
.character
.string
[0]
11207 = gfc_option
.flag_init_character_value
;
11208 arg
->next
= gfc_get_actual_arglist ();
11209 arg
->next
->expr
= gfc_copy_expr (sym
->ts
.u
.cl
->length
);
11210 init_expr
->value
.function
.actual
= arg
;
11215 gfc_free_expr (init_expr
);
11221 /* Add an initialization expression to a local variable. */
11223 apply_default_init_local (gfc_symbol
*sym
)
11225 gfc_expr
*init
= NULL
;
11227 /* The symbol should be a variable or a function return value. */
11228 if ((sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
11229 || (sym
->attr
.function
&& sym
->result
!= sym
))
11232 /* Try to build the initializer expression. If we can't initialize
11233 this symbol, then init will be NULL. */
11234 init
= build_default_init_expr (sym
);
11238 /* For saved variables, we don't want to add an initializer at function
11239 entry, so we just add a static initializer. Note that automatic variables
11240 are stack allocated even with -fno-automatic; we have also to exclude
11241 result variable, which are also nonstatic. */
11242 if (sym
->attr
.save
|| sym
->ns
->save_all
11243 || (flag_max_stack_var_size
== 0 && !sym
->attr
.result
11244 && (sym
->ns
->proc_name
&& !sym
->ns
->proc_name
->attr
.recursive
)
11245 && (!sym
->attr
.dimension
|| !is_non_constant_shape_array (sym
))))
11247 /* Don't clobber an existing initializer! */
11248 gcc_assert (sym
->value
== NULL
);
11253 build_init_assign (sym
, init
);
11257 /* Resolution of common features of flavors variable and procedure. */
11260 resolve_fl_var_and_proc (gfc_symbol
*sym
, int mp_flag
)
11262 gfc_array_spec
*as
;
11264 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
11265 as
= CLASS_DATA (sym
)->as
;
11269 /* Constraints on deferred shape variable. */
11270 if (as
== NULL
|| as
->type
!= AS_DEFERRED
)
11272 bool pointer
, allocatable
, dimension
;
11274 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
11276 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
11277 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
11278 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
11282 pointer
= sym
->attr
.pointer
&& !sym
->attr
.select_type_temporary
;
11283 allocatable
= sym
->attr
.allocatable
;
11284 dimension
= sym
->attr
.dimension
;
11289 if (dimension
&& as
->type
!= AS_ASSUMED_RANK
)
11291 gfc_error ("Allocatable array %qs at %L must have a deferred "
11292 "shape or assumed rank", sym
->name
, &sym
->declared_at
);
11295 else if (!gfc_notify_std (GFC_STD_F2003
, "Scalar object "
11296 "%qs at %L may not be ALLOCATABLE",
11297 sym
->name
, &sym
->declared_at
))
11301 if (pointer
&& dimension
&& as
->type
!= AS_ASSUMED_RANK
)
11303 gfc_error ("Array pointer %qs at %L must have a deferred shape or "
11304 "assumed rank", sym
->name
, &sym
->declared_at
);
11310 if (!mp_flag
&& !sym
->attr
.allocatable
&& !sym
->attr
.pointer
11311 && sym
->ts
.type
!= BT_CLASS
&& !sym
->assoc
)
11313 gfc_error ("Array %qs at %L cannot have a deferred shape",
11314 sym
->name
, &sym
->declared_at
);
11319 /* Constraints on polymorphic variables. */
11320 if (sym
->ts
.type
== BT_CLASS
&& !(sym
->result
&& sym
->result
!= sym
))
11323 if (sym
->attr
.class_ok
11324 && !sym
->attr
.select_type_temporary
11325 && !UNLIMITED_POLY (sym
)
11326 && !gfc_type_is_extensible (CLASS_DATA (sym
)->ts
.u
.derived
))
11328 gfc_error ("Type %qs of CLASS variable %qs at %L is not extensible",
11329 CLASS_DATA (sym
)->ts
.u
.derived
->name
, sym
->name
,
11330 &sym
->declared_at
);
11335 /* Assume that use associated symbols were checked in the module ns.
11336 Class-variables that are associate-names are also something special
11337 and excepted from the test. */
11338 if (!sym
->attr
.class_ok
&& !sym
->attr
.use_assoc
&& !sym
->assoc
)
11340 gfc_error ("CLASS variable %qs at %L must be dummy, allocatable "
11341 "or pointer", sym
->name
, &sym
->declared_at
);
11350 /* Additional checks for symbols with flavor variable and derived
11351 type. To be called from resolve_fl_variable. */
11354 resolve_fl_variable_derived (gfc_symbol
*sym
, int no_init_flag
)
11356 gcc_assert (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
);
11358 /* Check to see if a derived type is blocked from being host
11359 associated by the presence of another class I symbol in the same
11360 namespace. 14.6.1.3 of the standard and the discussion on
11361 comp.lang.fortran. */
11362 if (sym
->ns
!= sym
->ts
.u
.derived
->ns
11363 && sym
->ns
->proc_name
->attr
.if_source
!= IFSRC_IFBODY
)
11366 gfc_find_symbol (sym
->ts
.u
.derived
->name
, sym
->ns
, 0, &s
);
11367 if (s
&& s
->attr
.generic
)
11368 s
= gfc_find_dt_in_generic (s
);
11369 if (s
&& s
->attr
.flavor
!= FL_DERIVED
)
11371 gfc_error ("The type %qs cannot be host associated at %L "
11372 "because it is blocked by an incompatible object "
11373 "of the same name declared at %L",
11374 sym
->ts
.u
.derived
->name
, &sym
->declared_at
,
11380 /* 4th constraint in section 11.3: "If an object of a type for which
11381 component-initialization is specified (R429) appears in the
11382 specification-part of a module and does not have the ALLOCATABLE
11383 or POINTER attribute, the object shall have the SAVE attribute."
11385 The check for initializers is performed with
11386 gfc_has_default_initializer because gfc_default_initializer generates
11387 a hidden default for allocatable components. */
11388 if (!(sym
->value
|| no_init_flag
) && sym
->ns
->proc_name
11389 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
11390 && !sym
->ns
->save_all
&& !sym
->attr
.save
11391 && !sym
->attr
.pointer
&& !sym
->attr
.allocatable
11392 && gfc_has_default_initializer (sym
->ts
.u
.derived
)
11393 && !gfc_notify_std (GFC_STD_F2008
, "Implied SAVE for module variable "
11394 "%qs at %L, needed due to the default "
11395 "initialization", sym
->name
, &sym
->declared_at
))
11398 /* Assign default initializer. */
11399 if (!(sym
->value
|| sym
->attr
.pointer
|| sym
->attr
.allocatable
)
11400 && (!no_init_flag
|| sym
->attr
.intent
== INTENT_OUT
))
11402 sym
->value
= gfc_default_initializer (&sym
->ts
);
11409 /* Resolve symbols with flavor variable. */
11412 resolve_fl_variable (gfc_symbol
*sym
, int mp_flag
)
11414 int no_init_flag
, automatic_flag
;
11416 const char *auto_save_msg
;
11417 bool saved_specification_expr
;
11419 auto_save_msg
= "Automatic object %qs at %L cannot have the "
11422 if (!resolve_fl_var_and_proc (sym
, mp_flag
))
11425 /* Set this flag to check that variables are parameters of all entries.
11426 This check is effected by the call to gfc_resolve_expr through
11427 is_non_constant_shape_array. */
11428 saved_specification_expr
= specification_expr
;
11429 specification_expr
= true;
11431 if (sym
->ns
->proc_name
11432 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
11433 || sym
->ns
->proc_name
->attr
.is_main_program
)
11434 && !sym
->attr
.use_assoc
11435 && !sym
->attr
.allocatable
11436 && !sym
->attr
.pointer
11437 && is_non_constant_shape_array (sym
))
11439 /* The shape of a main program or module array needs to be
11441 gfc_error ("The module or main program array %qs at %L must "
11442 "have constant shape", sym
->name
, &sym
->declared_at
);
11443 specification_expr
= saved_specification_expr
;
11447 /* Constraints on deferred type parameter. */
11448 if (sym
->ts
.deferred
11449 && !(sym
->attr
.pointer
11450 || sym
->attr
.allocatable
11451 || sym
->attr
.omp_udr_artificial_var
))
11453 gfc_error ("Entity %qs at %L has a deferred type parameter and "
11454 "requires either the pointer or allocatable attribute",
11455 sym
->name
, &sym
->declared_at
);
11456 specification_expr
= saved_specification_expr
;
11460 if (sym
->ts
.type
== BT_CHARACTER
)
11462 /* Make sure that character string variables with assumed length are
11463 dummy arguments. */
11464 e
= sym
->ts
.u
.cl
->length
;
11465 if (e
== NULL
&& !sym
->attr
.dummy
&& !sym
->attr
.result
11466 && !sym
->ts
.deferred
&& !sym
->attr
.select_type_temporary
11467 && !sym
->attr
.omp_udr_artificial_var
)
11469 gfc_error ("Entity with assumed character length at %L must be a "
11470 "dummy argument or a PARAMETER", &sym
->declared_at
);
11471 specification_expr
= saved_specification_expr
;
11475 if (e
&& sym
->attr
.save
== SAVE_EXPLICIT
&& !gfc_is_constant_expr (e
))
11477 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
11478 specification_expr
= saved_specification_expr
;
11482 if (!gfc_is_constant_expr (e
)
11483 && !(e
->expr_type
== EXPR_VARIABLE
11484 && e
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
))
11486 if (!sym
->attr
.use_assoc
&& sym
->ns
->proc_name
11487 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
11488 || sym
->ns
->proc_name
->attr
.is_main_program
))
11490 gfc_error ("%qs at %L must have constant character length "
11491 "in this context", sym
->name
, &sym
->declared_at
);
11492 specification_expr
= saved_specification_expr
;
11495 if (sym
->attr
.in_common
)
11497 gfc_error ("COMMON variable %qs at %L must have constant "
11498 "character length", sym
->name
, &sym
->declared_at
);
11499 specification_expr
= saved_specification_expr
;
11505 if (sym
->value
== NULL
&& sym
->attr
.referenced
)
11506 apply_default_init_local (sym
); /* Try to apply a default initialization. */
11508 /* Determine if the symbol may not have an initializer. */
11509 no_init_flag
= automatic_flag
= 0;
11510 if (sym
->attr
.allocatable
|| sym
->attr
.external
|| sym
->attr
.dummy
11511 || sym
->attr
.intrinsic
|| sym
->attr
.result
)
11513 else if ((sym
->attr
.dimension
|| sym
->attr
.codimension
) && !sym
->attr
.pointer
11514 && is_non_constant_shape_array (sym
))
11516 no_init_flag
= automatic_flag
= 1;
11518 /* Also, they must not have the SAVE attribute.
11519 SAVE_IMPLICIT is checked below. */
11520 if (sym
->as
&& sym
->attr
.codimension
)
11522 int corank
= sym
->as
->corank
;
11523 sym
->as
->corank
= 0;
11524 no_init_flag
= automatic_flag
= is_non_constant_shape_array (sym
);
11525 sym
->as
->corank
= corank
;
11527 if (automatic_flag
&& sym
->attr
.save
== SAVE_EXPLICIT
)
11529 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
11530 specification_expr
= saved_specification_expr
;
11535 /* Ensure that any initializer is simplified. */
11537 gfc_simplify_expr (sym
->value
, 1);
11539 /* Reject illegal initializers. */
11540 if (!sym
->mark
&& sym
->value
)
11542 if (sym
->attr
.allocatable
|| (sym
->ts
.type
== BT_CLASS
11543 && CLASS_DATA (sym
)->attr
.allocatable
))
11544 gfc_error ("Allocatable %qs at %L cannot have an initializer",
11545 sym
->name
, &sym
->declared_at
);
11546 else if (sym
->attr
.external
)
11547 gfc_error ("External %qs at %L cannot have an initializer",
11548 sym
->name
, &sym
->declared_at
);
11549 else if (sym
->attr
.dummy
11550 && !(sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.intent
== INTENT_OUT
))
11551 gfc_error ("Dummy %qs at %L cannot have an initializer",
11552 sym
->name
, &sym
->declared_at
);
11553 else if (sym
->attr
.intrinsic
)
11554 gfc_error ("Intrinsic %qs at %L cannot have an initializer",
11555 sym
->name
, &sym
->declared_at
);
11556 else if (sym
->attr
.result
)
11557 gfc_error ("Function result %qs at %L cannot have an initializer",
11558 sym
->name
, &sym
->declared_at
);
11559 else if (automatic_flag
)
11560 gfc_error ("Automatic array %qs at %L cannot have an initializer",
11561 sym
->name
, &sym
->declared_at
);
11563 goto no_init_error
;
11564 specification_expr
= saved_specification_expr
;
11569 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
11571 bool res
= resolve_fl_variable_derived (sym
, no_init_flag
);
11572 specification_expr
= saved_specification_expr
;
11576 specification_expr
= saved_specification_expr
;
11581 /* Compare the dummy characteristics of a module procedure interface
11582 declaration with the corresponding declaration in a submodule. */
11583 static gfc_formal_arglist
*new_formal
;
11584 static char errmsg
[200];
11587 compare_fsyms (gfc_symbol
*sym
)
11591 if (sym
== NULL
|| new_formal
== NULL
)
11594 fsym
= new_formal
->sym
;
11599 if (strcmp (sym
->name
, fsym
->name
) == 0)
11601 if (!gfc_check_dummy_characteristics (fsym
, sym
, true, errmsg
, 200))
11602 gfc_error ("%s at %L", errmsg
, &fsym
->declared_at
);
11607 /* Resolve a procedure. */
11610 resolve_fl_procedure (gfc_symbol
*sym
, int mp_flag
)
11612 gfc_formal_arglist
*arg
;
11614 if (sym
->attr
.function
11615 && !resolve_fl_var_and_proc (sym
, mp_flag
))
11618 if (sym
->ts
.type
== BT_CHARACTER
)
11620 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
11622 if (cl
&& cl
->length
&& gfc_is_constant_expr (cl
->length
)
11623 && !resolve_charlen (cl
))
11626 if ((!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
11627 && sym
->attr
.proc
== PROC_ST_FUNCTION
)
11629 gfc_error ("Character-valued statement function %qs at %L must "
11630 "have constant length", sym
->name
, &sym
->declared_at
);
11635 /* Ensure that derived type for are not of a private type. Internal
11636 module procedures are excluded by 2.2.3.3 - i.e., they are not
11637 externally accessible and can access all the objects accessible in
11639 if (!(sym
->ns
->parent
11640 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
11641 && gfc_check_symbol_access (sym
))
11643 gfc_interface
*iface
;
11645 for (arg
= gfc_sym_get_dummy_args (sym
); arg
; arg
= arg
->next
)
11648 && arg
->sym
->ts
.type
== BT_DERIVED
11649 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
11650 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
11651 && !gfc_notify_std (GFC_STD_F2003
, "%qs is of a PRIVATE type "
11652 "and cannot be a dummy argument"
11653 " of %qs, which is PUBLIC at %L",
11654 arg
->sym
->name
, sym
->name
,
11655 &sym
->declared_at
))
11657 /* Stop this message from recurring. */
11658 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
11663 /* PUBLIC interfaces may expose PRIVATE procedures that take types
11664 PRIVATE to the containing module. */
11665 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
11667 for (arg
= gfc_sym_get_dummy_args (iface
->sym
); arg
; arg
= arg
->next
)
11670 && arg
->sym
->ts
.type
== BT_DERIVED
11671 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
11672 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
11673 && !gfc_notify_std (GFC_STD_F2003
, "Procedure %qs in "
11674 "PUBLIC interface %qs at %L "
11675 "takes dummy arguments of %qs which "
11676 "is PRIVATE", iface
->sym
->name
,
11677 sym
->name
, &iface
->sym
->declared_at
,
11678 gfc_typename(&arg
->sym
->ts
)))
11680 /* Stop this message from recurring. */
11681 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
11688 if (sym
->attr
.function
&& sym
->value
&& sym
->attr
.proc
!= PROC_ST_FUNCTION
11689 && !sym
->attr
.proc_pointer
)
11691 gfc_error ("Function %qs at %L cannot have an initializer",
11692 sym
->name
, &sym
->declared_at
);
11696 /* An external symbol may not have an initializer because it is taken to be
11697 a procedure. Exception: Procedure Pointers. */
11698 if (sym
->attr
.external
&& sym
->value
&& !sym
->attr
.proc_pointer
)
11700 gfc_error ("External object %qs at %L may not have an initializer",
11701 sym
->name
, &sym
->declared_at
);
11705 /* An elemental function is required to return a scalar 12.7.1 */
11706 if (sym
->attr
.elemental
&& sym
->attr
.function
&& sym
->as
)
11708 gfc_error ("ELEMENTAL function %qs at %L must have a scalar "
11709 "result", sym
->name
, &sym
->declared_at
);
11710 /* Reset so that the error only occurs once. */
11711 sym
->attr
.elemental
= 0;
11715 if (sym
->attr
.proc
== PROC_ST_FUNCTION
11716 && (sym
->attr
.allocatable
|| sym
->attr
.pointer
))
11718 gfc_error ("Statement function %qs at %L may not have pointer or "
11719 "allocatable attribute", sym
->name
, &sym
->declared_at
);
11723 /* 5.1.1.5 of the Standard: A function name declared with an asterisk
11724 char-len-param shall not be array-valued, pointer-valued, recursive
11725 or pure. ....snip... A character value of * may only be used in the
11726 following ways: (i) Dummy arg of procedure - dummy associates with
11727 actual length; (ii) To declare a named constant; or (iii) External
11728 function - but length must be declared in calling scoping unit. */
11729 if (sym
->attr
.function
11730 && sym
->ts
.type
== BT_CHARACTER
&& !sym
->ts
.deferred
11731 && sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
== NULL
)
11733 if ((sym
->as
&& sym
->as
->rank
) || (sym
->attr
.pointer
)
11734 || (sym
->attr
.recursive
) || (sym
->attr
.pure
))
11736 if (sym
->as
&& sym
->as
->rank
)
11737 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11738 "array-valued", sym
->name
, &sym
->declared_at
);
11740 if (sym
->attr
.pointer
)
11741 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11742 "pointer-valued", sym
->name
, &sym
->declared_at
);
11744 if (sym
->attr
.pure
)
11745 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11746 "pure", sym
->name
, &sym
->declared_at
);
11748 if (sym
->attr
.recursive
)
11749 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
11750 "recursive", sym
->name
, &sym
->declared_at
);
11755 /* Appendix B.2 of the standard. Contained functions give an
11756 error anyway. Deferred character length is an F2003 feature.
11757 Don't warn on intrinsic conversion functions, which start
11758 with two underscores. */
11759 if (!sym
->attr
.contained
&& !sym
->ts
.deferred
11760 && (sym
->name
[0] != '_' || sym
->name
[1] != '_'))
11761 gfc_notify_std (GFC_STD_F95_OBS
,
11762 "CHARACTER(*) function %qs at %L",
11763 sym
->name
, &sym
->declared_at
);
11766 /* F2008, C1218. */
11767 if (sym
->attr
.elemental
)
11769 if (sym
->attr
.proc_pointer
)
11771 gfc_error ("Procedure pointer %qs at %L shall not be elemental",
11772 sym
->name
, &sym
->declared_at
);
11775 if (sym
->attr
.dummy
)
11777 gfc_error ("Dummy procedure %qs at %L shall not be elemental",
11778 sym
->name
, &sym
->declared_at
);
11783 if (sym
->attr
.is_bind_c
&& sym
->attr
.is_c_interop
!= 1)
11785 gfc_formal_arglist
*curr_arg
;
11786 int has_non_interop_arg
= 0;
11788 if (!verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
11789 sym
->common_block
))
11791 /* Clear these to prevent looking at them again if there was an
11793 sym
->attr
.is_bind_c
= 0;
11794 sym
->attr
.is_c_interop
= 0;
11795 sym
->ts
.is_c_interop
= 0;
11799 /* So far, no errors have been found. */
11800 sym
->attr
.is_c_interop
= 1;
11801 sym
->ts
.is_c_interop
= 1;
11804 curr_arg
= gfc_sym_get_dummy_args (sym
);
11805 while (curr_arg
!= NULL
)
11807 /* Skip implicitly typed dummy args here. */
11808 if (curr_arg
->sym
->attr
.implicit_type
== 0)
11809 if (!gfc_verify_c_interop_param (curr_arg
->sym
))
11810 /* If something is found to fail, record the fact so we
11811 can mark the symbol for the procedure as not being
11812 BIND(C) to try and prevent multiple errors being
11814 has_non_interop_arg
= 1;
11816 curr_arg
= curr_arg
->next
;
11819 /* See if any of the arguments were not interoperable and if so, clear
11820 the procedure symbol to prevent duplicate error messages. */
11821 if (has_non_interop_arg
!= 0)
11823 sym
->attr
.is_c_interop
= 0;
11824 sym
->ts
.is_c_interop
= 0;
11825 sym
->attr
.is_bind_c
= 0;
11829 if (!sym
->attr
.proc_pointer
)
11831 if (sym
->attr
.save
== SAVE_EXPLICIT
)
11833 gfc_error ("PROCEDURE attribute conflicts with SAVE attribute "
11834 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11837 if (sym
->attr
.intent
)
11839 gfc_error ("PROCEDURE attribute conflicts with INTENT attribute "
11840 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11843 if (sym
->attr
.subroutine
&& sym
->attr
.result
)
11845 gfc_error ("PROCEDURE attribute conflicts with RESULT attribute "
11846 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11849 if (sym
->attr
.external
&& sym
->attr
.function
11850 && ((sym
->attr
.if_source
== IFSRC_DECL
&& !sym
->attr
.procedure
)
11851 || sym
->attr
.contained
))
11853 gfc_error ("EXTERNAL attribute conflicts with FUNCTION attribute "
11854 "in %qs at %L", sym
->name
, &sym
->declared_at
);
11857 if (strcmp ("ppr@", sym
->name
) == 0)
11859 gfc_error ("Procedure pointer result %qs at %L "
11860 "is missing the pointer attribute",
11861 sym
->ns
->proc_name
->name
, &sym
->declared_at
);
11866 /* Assume that a procedure whose body is not known has references
11867 to external arrays. */
11868 if (sym
->attr
.if_source
!= IFSRC_DECL
)
11869 sym
->attr
.array_outer_dependency
= 1;
11871 /* Compare the characteristics of a module procedure with the
11872 interface declaration. Ideally this would be done with
11873 gfc_compare_interfaces but, at present, the formal interface
11874 cannot be copied to the ts.interface. */
11875 if (sym
->attr
.module_procedure
11876 && sym
->attr
.if_source
== IFSRC_DECL
)
11879 char name
[2*GFC_MAX_SYMBOL_LEN
+ 1];
11881 char *submodule_name
;
11882 strcpy (name
, sym
->ns
->proc_name
->name
);
11883 module_name
= strtok (name
, ".");
11884 submodule_name
= strtok (NULL
, ".");
11886 /* Stop the dummy characteristics test from using the interface
11887 symbol instead of 'sym'. */
11888 iface
= sym
->ts
.interface
;
11889 sym
->ts
.interface
= NULL
;
11894 /* Check the procedure characteristics. */
11895 if (sym
->attr
.pure
!= iface
->attr
.pure
)
11897 gfc_error ("Mismatch in PURE attribute between MODULE "
11898 "PROCEDURE at %L and its interface in %s",
11899 &sym
->declared_at
, module_name
);
11903 if (sym
->attr
.elemental
!= iface
->attr
.elemental
)
11905 gfc_error ("Mismatch in ELEMENTAL attribute between MODULE "
11906 "PROCEDURE at %L and its interface in %s",
11907 &sym
->declared_at
, module_name
);
11911 if (sym
->attr
.recursive
!= iface
->attr
.recursive
)
11913 gfc_error ("Mismatch in RECURSIVE attribute between MODULE "
11914 "PROCEDURE at %L and its interface in %s",
11915 &sym
->declared_at
, module_name
);
11919 /* Check the result characteristics. */
11920 if (!gfc_check_result_characteristics (sym
, iface
, errmsg
, 200))
11922 gfc_error ("%s between the MODULE PROCEDURE declaration "
11923 "in module %s and the declaration at %L in "
11924 "SUBMODULE %s", errmsg
, module_name
,
11925 &sym
->declared_at
, submodule_name
);
11930 /* Check the charcateristics of the formal arguments. */
11931 if (sym
->formal
&& sym
->formal_ns
)
11933 for (arg
= sym
->formal
; arg
&& arg
->sym
; arg
= arg
->next
)
11936 gfc_traverse_ns (sym
->formal_ns
, compare_fsyms
);
11940 sym
->ts
.interface
= iface
;
11946 /* Resolve a list of finalizer procedures. That is, after they have hopefully
11947 been defined and we now know their defined arguments, check that they fulfill
11948 the requirements of the standard for procedures used as finalizers. */
11951 gfc_resolve_finalizers (gfc_symbol
* derived
, bool *finalizable
)
11953 gfc_finalizer
* list
;
11954 gfc_finalizer
** prev_link
; /* For removing wrong entries from the list. */
11955 bool result
= true;
11956 bool seen_scalar
= false;
11959 gfc_symbol
*parent
= gfc_get_derived_super_type (derived
);
11962 gfc_resolve_finalizers (parent
, finalizable
);
11964 /* Return early when not finalizable. Additionally, ensure that derived-type
11965 components have a their finalizables resolved. */
11966 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->finalizers
)
11968 bool has_final
= false;
11969 for (c
= derived
->components
; c
; c
= c
->next
)
11970 if (c
->ts
.type
== BT_DERIVED
11971 && !c
->attr
.pointer
&& !c
->attr
.proc_pointer
&& !c
->attr
.allocatable
)
11973 bool has_final2
= false;
11974 if (!gfc_resolve_finalizers (c
->ts
.u
.derived
, &has_final
))
11975 return false; /* Error. */
11976 has_final
= has_final
|| has_final2
;
11981 *finalizable
= false;
11986 /* Walk over the list of finalizer-procedures, check them, and if any one
11987 does not fit in with the standard's definition, print an error and remove
11988 it from the list. */
11989 prev_link
= &derived
->f2k_derived
->finalizers
;
11990 for (list
= derived
->f2k_derived
->finalizers
; list
; list
= *prev_link
)
11992 gfc_formal_arglist
*dummy_args
;
11997 /* Skip this finalizer if we already resolved it. */
11998 if (list
->proc_tree
)
12000 prev_link
= &(list
->next
);
12004 /* Check this exists and is a SUBROUTINE. */
12005 if (!list
->proc_sym
->attr
.subroutine
)
12007 gfc_error ("FINAL procedure %qs at %L is not a SUBROUTINE",
12008 list
->proc_sym
->name
, &list
->where
);
12012 /* We should have exactly one argument. */
12013 dummy_args
= gfc_sym_get_dummy_args (list
->proc_sym
);
12014 if (!dummy_args
|| dummy_args
->next
)
12016 gfc_error ("FINAL procedure at %L must have exactly one argument",
12020 arg
= dummy_args
->sym
;
12022 /* This argument must be of our type. */
12023 if (arg
->ts
.type
!= BT_DERIVED
|| arg
->ts
.u
.derived
!= derived
)
12025 gfc_error ("Argument of FINAL procedure at %L must be of type %qs",
12026 &arg
->declared_at
, derived
->name
);
12030 /* It must neither be a pointer nor allocatable nor optional. */
12031 if (arg
->attr
.pointer
)
12033 gfc_error ("Argument of FINAL procedure at %L must not be a POINTER",
12034 &arg
->declared_at
);
12037 if (arg
->attr
.allocatable
)
12039 gfc_error ("Argument of FINAL procedure at %L must not be"
12040 " ALLOCATABLE", &arg
->declared_at
);
12043 if (arg
->attr
.optional
)
12045 gfc_error ("Argument of FINAL procedure at %L must not be OPTIONAL",
12046 &arg
->declared_at
);
12050 /* It must not be INTENT(OUT). */
12051 if (arg
->attr
.intent
== INTENT_OUT
)
12053 gfc_error ("Argument of FINAL procedure at %L must not be"
12054 " INTENT(OUT)", &arg
->declared_at
);
12058 /* Warn if the procedure is non-scalar and not assumed shape. */
12059 if (warn_surprising
&& arg
->as
&& arg
->as
->rank
!= 0
12060 && arg
->as
->type
!= AS_ASSUMED_SHAPE
)
12061 gfc_warning (OPT_Wsurprising
,
12062 "Non-scalar FINAL procedure at %L should have assumed"
12063 " shape argument", &arg
->declared_at
);
12065 /* Check that it does not match in kind and rank with a FINAL procedure
12066 defined earlier. To really loop over the *earlier* declarations,
12067 we need to walk the tail of the list as new ones were pushed at the
12069 /* TODO: Handle kind parameters once they are implemented. */
12070 my_rank
= (arg
->as
? arg
->as
->rank
: 0);
12071 for (i
= list
->next
; i
; i
= i
->next
)
12073 gfc_formal_arglist
*dummy_args
;
12075 /* Argument list might be empty; that is an error signalled earlier,
12076 but we nevertheless continued resolving. */
12077 dummy_args
= gfc_sym_get_dummy_args (i
->proc_sym
);
12080 gfc_symbol
* i_arg
= dummy_args
->sym
;
12081 const int i_rank
= (i_arg
->as
? i_arg
->as
->rank
: 0);
12082 if (i_rank
== my_rank
)
12084 gfc_error ("FINAL procedure %qs declared at %L has the same"
12085 " rank (%d) as %qs",
12086 list
->proc_sym
->name
, &list
->where
, my_rank
,
12087 i
->proc_sym
->name
);
12093 /* Is this the/a scalar finalizer procedure? */
12094 if (!arg
->as
|| arg
->as
->rank
== 0)
12095 seen_scalar
= true;
12097 /* Find the symtree for this procedure. */
12098 gcc_assert (!list
->proc_tree
);
12099 list
->proc_tree
= gfc_find_sym_in_symtree (list
->proc_sym
);
12101 prev_link
= &list
->next
;
12104 /* Remove wrong nodes immediately from the list so we don't risk any
12105 troubles in the future when they might fail later expectations. */
12108 *prev_link
= list
->next
;
12109 gfc_free_finalizer (i
);
12113 if (result
== false)
12116 /* Warn if we haven't seen a scalar finalizer procedure (but we know there
12117 were nodes in the list, must have been for arrays. It is surely a good
12118 idea to have a scalar version there if there's something to finalize. */
12119 if (warn_surprising
&& result
&& !seen_scalar
)
12120 gfc_warning (OPT_Wsurprising
,
12121 "Only array FINAL procedures declared for derived type %qs"
12122 " defined at %L, suggest also scalar one",
12123 derived
->name
, &derived
->declared_at
);
12125 vtab
= gfc_find_derived_vtab (derived
);
12126 c
= vtab
->ts
.u
.derived
->components
->next
->next
->next
->next
->next
;
12127 gfc_set_sym_referenced (c
->initializer
->symtree
->n
.sym
);
12130 *finalizable
= true;
12136 /* Check if two GENERIC targets are ambiguous and emit an error is they are. */
12139 check_generic_tbp_ambiguity (gfc_tbp_generic
* t1
, gfc_tbp_generic
* t2
,
12140 const char* generic_name
, locus where
)
12142 gfc_symbol
*sym1
, *sym2
;
12143 const char *pass1
, *pass2
;
12144 gfc_formal_arglist
*dummy_args
;
12146 gcc_assert (t1
->specific
&& t2
->specific
);
12147 gcc_assert (!t1
->specific
->is_generic
);
12148 gcc_assert (!t2
->specific
->is_generic
);
12149 gcc_assert (t1
->is_operator
== t2
->is_operator
);
12151 sym1
= t1
->specific
->u
.specific
->n
.sym
;
12152 sym2
= t2
->specific
->u
.specific
->n
.sym
;
12157 /* Both must be SUBROUTINEs or both must be FUNCTIONs. */
12158 if (sym1
->attr
.subroutine
!= sym2
->attr
.subroutine
12159 || sym1
->attr
.function
!= sym2
->attr
.function
)
12161 gfc_error ("%qs and %qs can't be mixed FUNCTION/SUBROUTINE for"
12162 " GENERIC %qs at %L",
12163 sym1
->name
, sym2
->name
, generic_name
, &where
);
12167 /* Determine PASS arguments. */
12168 if (t1
->specific
->nopass
)
12170 else if (t1
->specific
->pass_arg
)
12171 pass1
= t1
->specific
->pass_arg
;
12174 dummy_args
= gfc_sym_get_dummy_args (t1
->specific
->u
.specific
->n
.sym
);
12176 pass1
= dummy_args
->sym
->name
;
12180 if (t2
->specific
->nopass
)
12182 else if (t2
->specific
->pass_arg
)
12183 pass2
= t2
->specific
->pass_arg
;
12186 dummy_args
= gfc_sym_get_dummy_args (t2
->specific
->u
.specific
->n
.sym
);
12188 pass2
= dummy_args
->sym
->name
;
12193 /* Compare the interfaces. */
12194 if (gfc_compare_interfaces (sym1
, sym2
, sym2
->name
, !t1
->is_operator
, 0,
12195 NULL
, 0, pass1
, pass2
))
12197 gfc_error ("%qs and %qs for GENERIC %qs at %L are ambiguous",
12198 sym1
->name
, sym2
->name
, generic_name
, &where
);
12206 /* Worker function for resolving a generic procedure binding; this is used to
12207 resolve GENERIC as well as user and intrinsic OPERATOR typebound procedures.
12209 The difference between those cases is finding possible inherited bindings
12210 that are overridden, as one has to look for them in tb_sym_root,
12211 tb_uop_root or tb_op, respectively. Thus the caller must already find
12212 the super-type and set p->overridden correctly. */
12215 resolve_tb_generic_targets (gfc_symbol
* super_type
,
12216 gfc_typebound_proc
* p
, const char* name
)
12218 gfc_tbp_generic
* target
;
12219 gfc_symtree
* first_target
;
12220 gfc_symtree
* inherited
;
12222 gcc_assert (p
&& p
->is_generic
);
12224 /* Try to find the specific bindings for the symtrees in our target-list. */
12225 gcc_assert (p
->u
.generic
);
12226 for (target
= p
->u
.generic
; target
; target
= target
->next
)
12227 if (!target
->specific
)
12229 gfc_typebound_proc
* overridden_tbp
;
12230 gfc_tbp_generic
* g
;
12231 const char* target_name
;
12233 target_name
= target
->specific_st
->name
;
12235 /* Defined for this type directly. */
12236 if (target
->specific_st
->n
.tb
&& !target
->specific_st
->n
.tb
->error
)
12238 target
->specific
= target
->specific_st
->n
.tb
;
12239 goto specific_found
;
12242 /* Look for an inherited specific binding. */
12245 inherited
= gfc_find_typebound_proc (super_type
, NULL
, target_name
,
12250 gcc_assert (inherited
->n
.tb
);
12251 target
->specific
= inherited
->n
.tb
;
12252 goto specific_found
;
12256 gfc_error ("Undefined specific binding %qs as target of GENERIC %qs"
12257 " at %L", target_name
, name
, &p
->where
);
12260 /* Once we've found the specific binding, check it is not ambiguous with
12261 other specifics already found or inherited for the same GENERIC. */
12263 gcc_assert (target
->specific
);
12265 /* This must really be a specific binding! */
12266 if (target
->specific
->is_generic
)
12268 gfc_error ("GENERIC %qs at %L must target a specific binding,"
12269 " %qs is GENERIC, too", name
, &p
->where
, target_name
);
12273 /* Check those already resolved on this type directly. */
12274 for (g
= p
->u
.generic
; g
; g
= g
->next
)
12275 if (g
!= target
&& g
->specific
12276 && !check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
12279 /* Check for ambiguity with inherited specific targets. */
12280 for (overridden_tbp
= p
->overridden
; overridden_tbp
;
12281 overridden_tbp
= overridden_tbp
->overridden
)
12282 if (overridden_tbp
->is_generic
)
12284 for (g
= overridden_tbp
->u
.generic
; g
; g
= g
->next
)
12286 gcc_assert (g
->specific
);
12287 if (!check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
12293 /* If we attempt to "overwrite" a specific binding, this is an error. */
12294 if (p
->overridden
&& !p
->overridden
->is_generic
)
12296 gfc_error ("GENERIC %qs at %L can't overwrite specific binding with"
12297 " the same name", name
, &p
->where
);
12301 /* Take the SUBROUTINE/FUNCTION attributes of the first specific target, as
12302 all must have the same attributes here. */
12303 first_target
= p
->u
.generic
->specific
->u
.specific
;
12304 gcc_assert (first_target
);
12305 p
->subroutine
= first_target
->n
.sym
->attr
.subroutine
;
12306 p
->function
= first_target
->n
.sym
->attr
.function
;
12312 /* Resolve a GENERIC procedure binding for a derived type. */
12315 resolve_typebound_generic (gfc_symbol
* derived
, gfc_symtree
* st
)
12317 gfc_symbol
* super_type
;
12319 /* Find the overridden binding if any. */
12320 st
->n
.tb
->overridden
= NULL
;
12321 super_type
= gfc_get_derived_super_type (derived
);
12324 gfc_symtree
* overridden
;
12325 overridden
= gfc_find_typebound_proc (super_type
, NULL
, st
->name
,
12328 if (overridden
&& overridden
->n
.tb
)
12329 st
->n
.tb
->overridden
= overridden
->n
.tb
;
12332 /* Resolve using worker function. */
12333 return resolve_tb_generic_targets (super_type
, st
->n
.tb
, st
->name
);
12337 /* Retrieve the target-procedure of an operator binding and do some checks in
12338 common for intrinsic and user-defined type-bound operators. */
12341 get_checked_tb_operator_target (gfc_tbp_generic
* target
, locus where
)
12343 gfc_symbol
* target_proc
;
12345 gcc_assert (target
->specific
&& !target
->specific
->is_generic
);
12346 target_proc
= target
->specific
->u
.specific
->n
.sym
;
12347 gcc_assert (target_proc
);
12349 /* F08:C468. All operator bindings must have a passed-object dummy argument. */
12350 if (target
->specific
->nopass
)
12352 gfc_error ("Type-bound operator at %L can't be NOPASS", &where
);
12356 return target_proc
;
12360 /* Resolve a type-bound intrinsic operator. */
12363 resolve_typebound_intrinsic_op (gfc_symbol
* derived
, gfc_intrinsic_op op
,
12364 gfc_typebound_proc
* p
)
12366 gfc_symbol
* super_type
;
12367 gfc_tbp_generic
* target
;
12369 /* If there's already an error here, do nothing (but don't fail again). */
12373 /* Operators should always be GENERIC bindings. */
12374 gcc_assert (p
->is_generic
);
12376 /* Look for an overridden binding. */
12377 super_type
= gfc_get_derived_super_type (derived
);
12378 if (super_type
&& super_type
->f2k_derived
)
12379 p
->overridden
= gfc_find_typebound_intrinsic_op (super_type
, NULL
,
12382 p
->overridden
= NULL
;
12384 /* Resolve general GENERIC properties using worker function. */
12385 if (!resolve_tb_generic_targets (super_type
, p
, gfc_op2string(op
)))
12388 /* Check the targets to be procedures of correct interface. */
12389 for (target
= p
->u
.generic
; target
; target
= target
->next
)
12391 gfc_symbol
* target_proc
;
12393 target_proc
= get_checked_tb_operator_target (target
, p
->where
);
12397 if (!gfc_check_operator_interface (target_proc
, op
, p
->where
))
12400 /* Add target to non-typebound operator list. */
12401 if (!target
->specific
->deferred
&& !derived
->attr
.use_assoc
12402 && p
->access
!= ACCESS_PRIVATE
&& derived
->ns
== gfc_current_ns
)
12404 gfc_interface
*head
, *intr
;
12405 if (!gfc_check_new_interface (derived
->ns
->op
[op
], target_proc
, p
->where
))
12407 head
= derived
->ns
->op
[op
];
12408 intr
= gfc_get_interface ();
12409 intr
->sym
= target_proc
;
12410 intr
->where
= p
->where
;
12412 derived
->ns
->op
[op
] = intr
;
12424 /* Resolve a type-bound user operator (tree-walker callback). */
12426 static gfc_symbol
* resolve_bindings_derived
;
12427 static bool resolve_bindings_result
;
12429 static bool check_uop_procedure (gfc_symbol
* sym
, locus where
);
12432 resolve_typebound_user_op (gfc_symtree
* stree
)
12434 gfc_symbol
* super_type
;
12435 gfc_tbp_generic
* target
;
12437 gcc_assert (stree
&& stree
->n
.tb
);
12439 if (stree
->n
.tb
->error
)
12442 /* Operators should always be GENERIC bindings. */
12443 gcc_assert (stree
->n
.tb
->is_generic
);
12445 /* Find overridden procedure, if any. */
12446 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
12447 if (super_type
&& super_type
->f2k_derived
)
12449 gfc_symtree
* overridden
;
12450 overridden
= gfc_find_typebound_user_op (super_type
, NULL
,
12451 stree
->name
, true, NULL
);
12453 if (overridden
&& overridden
->n
.tb
)
12454 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
12457 stree
->n
.tb
->overridden
= NULL
;
12459 /* Resolve basically using worker function. */
12460 if (!resolve_tb_generic_targets (super_type
, stree
->n
.tb
, stree
->name
))
12463 /* Check the targets to be functions of correct interface. */
12464 for (target
= stree
->n
.tb
->u
.generic
; target
; target
= target
->next
)
12466 gfc_symbol
* target_proc
;
12468 target_proc
= get_checked_tb_operator_target (target
, stree
->n
.tb
->where
);
12472 if (!check_uop_procedure (target_proc
, stree
->n
.tb
->where
))
12479 resolve_bindings_result
= false;
12480 stree
->n
.tb
->error
= 1;
12484 /* Resolve the type-bound procedures for a derived type. */
12487 resolve_typebound_procedure (gfc_symtree
* stree
)
12491 gfc_symbol
* me_arg
;
12492 gfc_symbol
* super_type
;
12493 gfc_component
* comp
;
12495 gcc_assert (stree
);
12497 /* Undefined specific symbol from GENERIC target definition. */
12501 if (stree
->n
.tb
->error
)
12504 /* If this is a GENERIC binding, use that routine. */
12505 if (stree
->n
.tb
->is_generic
)
12507 if (!resolve_typebound_generic (resolve_bindings_derived
, stree
))
12512 /* Get the target-procedure to check it. */
12513 gcc_assert (!stree
->n
.tb
->is_generic
);
12514 gcc_assert (stree
->n
.tb
->u
.specific
);
12515 proc
= stree
->n
.tb
->u
.specific
->n
.sym
;
12516 where
= stree
->n
.tb
->where
;
12518 /* Default access should already be resolved from the parser. */
12519 gcc_assert (stree
->n
.tb
->access
!= ACCESS_UNKNOWN
);
12521 if (stree
->n
.tb
->deferred
)
12523 if (!check_proc_interface (proc
, &where
))
12528 /* Check for F08:C465. */
12529 if ((!proc
->attr
.subroutine
&& !proc
->attr
.function
)
12530 || (proc
->attr
.proc
!= PROC_MODULE
12531 && proc
->attr
.if_source
!= IFSRC_IFBODY
)
12532 || proc
->attr
.abstract
)
12534 gfc_error ("%qs must be a module procedure or an external procedure with"
12535 " an explicit interface at %L", proc
->name
, &where
);
12540 stree
->n
.tb
->subroutine
= proc
->attr
.subroutine
;
12541 stree
->n
.tb
->function
= proc
->attr
.function
;
12543 /* Find the super-type of the current derived type. We could do this once and
12544 store in a global if speed is needed, but as long as not I believe this is
12545 more readable and clearer. */
12546 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
12548 /* If PASS, resolve and check arguments if not already resolved / loaded
12549 from a .mod file. */
12550 if (!stree
->n
.tb
->nopass
&& stree
->n
.tb
->pass_arg_num
== 0)
12552 gfc_formal_arglist
*dummy_args
;
12554 dummy_args
= gfc_sym_get_dummy_args (proc
);
12555 if (stree
->n
.tb
->pass_arg
)
12557 gfc_formal_arglist
*i
;
12559 /* If an explicit passing argument name is given, walk the arg-list
12560 and look for it. */
12563 stree
->n
.tb
->pass_arg_num
= 1;
12564 for (i
= dummy_args
; i
; i
= i
->next
)
12566 if (!strcmp (i
->sym
->name
, stree
->n
.tb
->pass_arg
))
12571 ++stree
->n
.tb
->pass_arg_num
;
12576 gfc_error ("Procedure %qs with PASS(%s) at %L has no"
12578 proc
->name
, stree
->n
.tb
->pass_arg
, &where
,
12579 stree
->n
.tb
->pass_arg
);
12585 /* Otherwise, take the first one; there should in fact be at least
12587 stree
->n
.tb
->pass_arg_num
= 1;
12590 gfc_error ("Procedure %qs with PASS at %L must have at"
12591 " least one argument", proc
->name
, &where
);
12594 me_arg
= dummy_args
->sym
;
12597 /* Now check that the argument-type matches and the passed-object
12598 dummy argument is generally fine. */
12600 gcc_assert (me_arg
);
12602 if (me_arg
->ts
.type
!= BT_CLASS
)
12604 gfc_error ("Non-polymorphic passed-object dummy argument of %qs"
12605 " at %L", proc
->name
, &where
);
12609 if (CLASS_DATA (me_arg
)->ts
.u
.derived
12610 != resolve_bindings_derived
)
12612 gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of"
12613 " the derived-type %qs", me_arg
->name
, proc
->name
,
12614 me_arg
->name
, &where
, resolve_bindings_derived
->name
);
12618 gcc_assert (me_arg
->ts
.type
== BT_CLASS
);
12619 if (CLASS_DATA (me_arg
)->as
&& CLASS_DATA (me_arg
)->as
->rank
!= 0)
12621 gfc_error ("Passed-object dummy argument of %qs at %L must be"
12622 " scalar", proc
->name
, &where
);
12625 if (CLASS_DATA (me_arg
)->attr
.allocatable
)
12627 gfc_error ("Passed-object dummy argument of %qs at %L must not"
12628 " be ALLOCATABLE", proc
->name
, &where
);
12631 if (CLASS_DATA (me_arg
)->attr
.class_pointer
)
12633 gfc_error ("Passed-object dummy argument of %qs at %L must not"
12634 " be POINTER", proc
->name
, &where
);
12639 /* If we are extending some type, check that we don't override a procedure
12640 flagged NON_OVERRIDABLE. */
12641 stree
->n
.tb
->overridden
= NULL
;
12644 gfc_symtree
* overridden
;
12645 overridden
= gfc_find_typebound_proc (super_type
, NULL
,
12646 stree
->name
, true, NULL
);
12650 if (overridden
->n
.tb
)
12651 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
12653 if (!gfc_check_typebound_override (stree
, overridden
))
12658 /* See if there's a name collision with a component directly in this type. */
12659 for (comp
= resolve_bindings_derived
->components
; comp
; comp
= comp
->next
)
12660 if (!strcmp (comp
->name
, stree
->name
))
12662 gfc_error ("Procedure %qs at %L has the same name as a component of"
12664 stree
->name
, &where
, resolve_bindings_derived
->name
);
12668 /* Try to find a name collision with an inherited component. */
12669 if (super_type
&& gfc_find_component (super_type
, stree
->name
, true, true))
12671 gfc_error ("Procedure %qs at %L has the same name as an inherited"
12672 " component of %qs",
12673 stree
->name
, &where
, resolve_bindings_derived
->name
);
12677 stree
->n
.tb
->error
= 0;
12681 resolve_bindings_result
= false;
12682 stree
->n
.tb
->error
= 1;
12687 resolve_typebound_procedures (gfc_symbol
* derived
)
12690 gfc_symbol
* super_type
;
12692 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->tb_sym_root
)
12695 super_type
= gfc_get_derived_super_type (derived
);
12697 resolve_symbol (super_type
);
12699 resolve_bindings_derived
= derived
;
12700 resolve_bindings_result
= true;
12702 if (derived
->f2k_derived
->tb_sym_root
)
12703 gfc_traverse_symtree (derived
->f2k_derived
->tb_sym_root
,
12704 &resolve_typebound_procedure
);
12706 if (derived
->f2k_derived
->tb_uop_root
)
12707 gfc_traverse_symtree (derived
->f2k_derived
->tb_uop_root
,
12708 &resolve_typebound_user_op
);
12710 for (op
= 0; op
!= GFC_INTRINSIC_OPS
; ++op
)
12712 gfc_typebound_proc
* p
= derived
->f2k_derived
->tb_op
[op
];
12713 if (p
&& !resolve_typebound_intrinsic_op (derived
,
12714 (gfc_intrinsic_op
)op
, p
))
12715 resolve_bindings_result
= false;
12718 return resolve_bindings_result
;
12722 /* Add a derived type to the dt_list. The dt_list is used in trans-types.c
12723 to give all identical derived types the same backend_decl. */
12725 add_dt_to_dt_list (gfc_symbol
*derived
)
12727 gfc_dt_list
*dt_list
;
12729 for (dt_list
= gfc_derived_types
; dt_list
; dt_list
= dt_list
->next
)
12730 if (derived
== dt_list
->derived
)
12733 dt_list
= gfc_get_dt_list ();
12734 dt_list
->next
= gfc_derived_types
;
12735 dt_list
->derived
= derived
;
12736 gfc_derived_types
= dt_list
;
12740 /* Ensure that a derived-type is really not abstract, meaning that every
12741 inherited DEFERRED binding is overridden by a non-DEFERRED one. */
12744 ensure_not_abstract_walker (gfc_symbol
* sub
, gfc_symtree
* st
)
12749 if (!ensure_not_abstract_walker (sub
, st
->left
))
12751 if (!ensure_not_abstract_walker (sub
, st
->right
))
12754 if (st
->n
.tb
&& st
->n
.tb
->deferred
)
12756 gfc_symtree
* overriding
;
12757 overriding
= gfc_find_typebound_proc (sub
, NULL
, st
->name
, true, NULL
);
12760 gcc_assert (overriding
->n
.tb
);
12761 if (overriding
->n
.tb
->deferred
)
12763 gfc_error ("Derived-type %qs declared at %L must be ABSTRACT because"
12764 " %qs is DEFERRED and not overridden",
12765 sub
->name
, &sub
->declared_at
, st
->name
);
12774 ensure_not_abstract (gfc_symbol
* sub
, gfc_symbol
* ancestor
)
12776 /* The algorithm used here is to recursively travel up the ancestry of sub
12777 and for each ancestor-type, check all bindings. If any of them is
12778 DEFERRED, look it up starting from sub and see if the found (overriding)
12779 binding is not DEFERRED.
12780 This is not the most efficient way to do this, but it should be ok and is
12781 clearer than something sophisticated. */
12783 gcc_assert (ancestor
&& !sub
->attr
.abstract
);
12785 if (!ancestor
->attr
.abstract
)
12788 /* Walk bindings of this ancestor. */
12789 if (ancestor
->f2k_derived
)
12792 t
= ensure_not_abstract_walker (sub
, ancestor
->f2k_derived
->tb_sym_root
);
12797 /* Find next ancestor type and recurse on it. */
12798 ancestor
= gfc_get_derived_super_type (ancestor
);
12800 return ensure_not_abstract (sub
, ancestor
);
12806 /* This check for typebound defined assignments is done recursively
12807 since the order in which derived types are resolved is not always in
12808 order of the declarations. */
12811 check_defined_assignments (gfc_symbol
*derived
)
12815 for (c
= derived
->components
; c
; c
= c
->next
)
12817 if (c
->ts
.type
!= BT_DERIVED
12819 || c
->attr
.allocatable
12820 || c
->attr
.proc_pointer_comp
12821 || c
->attr
.class_pointer
12822 || c
->attr
.proc_pointer
)
12825 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
12826 || (c
->ts
.u
.derived
->f2k_derived
12827 && c
->ts
.u
.derived
->f2k_derived
->tb_op
[INTRINSIC_ASSIGN
]))
12829 derived
->attr
.defined_assign_comp
= 1;
12833 check_defined_assignments (c
->ts
.u
.derived
);
12834 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
12836 derived
->attr
.defined_assign_comp
= 1;
12843 /* Resolve the components of a derived type. This does not have to wait until
12844 resolution stage, but can be done as soon as the dt declaration has been
12848 resolve_fl_derived0 (gfc_symbol
*sym
)
12850 gfc_symbol
* super_type
;
12853 if (sym
->attr
.unlimited_polymorphic
)
12856 super_type
= gfc_get_derived_super_type (sym
);
12859 if (super_type
&& sym
->attr
.coarray_comp
&& !super_type
->attr
.coarray_comp
)
12861 gfc_error ("As extending type %qs at %L has a coarray component, "
12862 "parent type %qs shall also have one", sym
->name
,
12863 &sym
->declared_at
, super_type
->name
);
12867 /* Ensure the extended type gets resolved before we do. */
12868 if (super_type
&& !resolve_fl_derived0 (super_type
))
12871 /* An ABSTRACT type must be extensible. */
12872 if (sym
->attr
.abstract
&& !gfc_type_is_extensible (sym
))
12874 gfc_error ("Non-extensible derived-type %qs at %L must not be ABSTRACT",
12875 sym
->name
, &sym
->declared_at
);
12879 c
= (sym
->attr
.is_class
) ? sym
->components
->ts
.u
.derived
->components
12882 bool success
= true;
12884 for ( ; c
!= NULL
; c
= c
->next
)
12886 if (c
->attr
.artificial
)
12890 if ((!sym
->attr
.is_class
|| c
!= sym
->components
)
12891 && c
->attr
.codimension
12892 && (!c
->attr
.allocatable
|| (c
->as
&& c
->as
->type
!= AS_DEFERRED
)))
12894 gfc_error ("Coarray component %qs at %L must be allocatable with "
12895 "deferred shape", c
->name
, &c
->loc
);
12901 if (c
->attr
.codimension
&& c
->ts
.type
== BT_DERIVED
12902 && c
->ts
.u
.derived
->ts
.is_iso_c
)
12904 gfc_error ("Component %qs at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
12905 "shall not be a coarray", c
->name
, &c
->loc
);
12911 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
12912 && (c
->attr
.codimension
|| c
->attr
.pointer
|| c
->attr
.dimension
12913 || c
->attr
.allocatable
))
12915 gfc_error ("Component %qs at %L with coarray component "
12916 "shall be a nonpointer, nonallocatable scalar",
12923 if (c
->attr
.contiguous
&& (!c
->attr
.dimension
|| !c
->attr
.pointer
))
12925 gfc_error ("Component %qs at %L has the CONTIGUOUS attribute but "
12926 "is not an array pointer", c
->name
, &c
->loc
);
12931 if (c
->attr
.proc_pointer
&& c
->ts
.interface
)
12933 gfc_symbol
*ifc
= c
->ts
.interface
;
12935 if (!sym
->attr
.vtype
&& !check_proc_interface (ifc
, &c
->loc
))
12942 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
12944 /* Resolve interface and copy attributes. */
12945 if (ifc
->formal
&& !ifc
->formal_ns
)
12946 resolve_symbol (ifc
);
12947 if (ifc
->attr
.intrinsic
)
12948 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
12952 c
->ts
= ifc
->result
->ts
;
12953 c
->attr
.allocatable
= ifc
->result
->attr
.allocatable
;
12954 c
->attr
.pointer
= ifc
->result
->attr
.pointer
;
12955 c
->attr
.dimension
= ifc
->result
->attr
.dimension
;
12956 c
->as
= gfc_copy_array_spec (ifc
->result
->as
);
12957 c
->attr
.class_ok
= ifc
->result
->attr
.class_ok
;
12962 c
->attr
.allocatable
= ifc
->attr
.allocatable
;
12963 c
->attr
.pointer
= ifc
->attr
.pointer
;
12964 c
->attr
.dimension
= ifc
->attr
.dimension
;
12965 c
->as
= gfc_copy_array_spec (ifc
->as
);
12966 c
->attr
.class_ok
= ifc
->attr
.class_ok
;
12968 c
->ts
.interface
= ifc
;
12969 c
->attr
.function
= ifc
->attr
.function
;
12970 c
->attr
.subroutine
= ifc
->attr
.subroutine
;
12972 c
->attr
.pure
= ifc
->attr
.pure
;
12973 c
->attr
.elemental
= ifc
->attr
.elemental
;
12974 c
->attr
.recursive
= ifc
->attr
.recursive
;
12975 c
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
12976 c
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
12977 /* Copy char length. */
12978 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
12980 gfc_charlen
*cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
12981 if (cl
->length
&& !cl
->resolved
12982 && !gfc_resolve_expr (cl
->length
))
12992 else if (c
->attr
.proc_pointer
&& c
->ts
.type
== BT_UNKNOWN
)
12994 /* Since PPCs are not implicitly typed, a PPC without an explicit
12995 interface must be a subroutine. */
12996 gfc_add_subroutine (&c
->attr
, c
->name
, &c
->loc
);
12999 /* Procedure pointer components: Check PASS arg. */
13000 if (c
->attr
.proc_pointer
&& !c
->tb
->nopass
&& c
->tb
->pass_arg_num
== 0
13001 && !sym
->attr
.vtype
)
13003 gfc_symbol
* me_arg
;
13005 if (c
->tb
->pass_arg
)
13007 gfc_formal_arglist
* i
;
13009 /* If an explicit passing argument name is given, walk the arg-list
13010 and look for it. */
13013 c
->tb
->pass_arg_num
= 1;
13014 for (i
= c
->ts
.interface
->formal
; i
; i
= i
->next
)
13016 if (!strcmp (i
->sym
->name
, c
->tb
->pass_arg
))
13021 c
->tb
->pass_arg_num
++;
13026 gfc_error ("Procedure pointer component %qs with PASS(%s) "
13027 "at %L has no argument %qs", c
->name
,
13028 c
->tb
->pass_arg
, &c
->loc
, c
->tb
->pass_arg
);
13036 /* Otherwise, take the first one; there should in fact be at least
13038 c
->tb
->pass_arg_num
= 1;
13039 if (!c
->ts
.interface
->formal
)
13041 gfc_error ("Procedure pointer component %qs with PASS at %L "
13042 "must have at least one argument",
13048 me_arg
= c
->ts
.interface
->formal
->sym
;
13051 /* Now check that the argument-type matches. */
13052 gcc_assert (me_arg
);
13053 if ((me_arg
->ts
.type
!= BT_DERIVED
&& me_arg
->ts
.type
!= BT_CLASS
)
13054 || (me_arg
->ts
.type
== BT_DERIVED
&& me_arg
->ts
.u
.derived
!= sym
)
13055 || (me_arg
->ts
.type
== BT_CLASS
13056 && CLASS_DATA (me_arg
)->ts
.u
.derived
!= sym
))
13058 gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of"
13059 " the derived type %qs", me_arg
->name
, c
->name
,
13060 me_arg
->name
, &c
->loc
, sym
->name
);
13066 /* Check for C453. */
13067 if (me_arg
->attr
.dimension
)
13069 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
13070 "must be scalar", me_arg
->name
, c
->name
, me_arg
->name
,
13077 if (me_arg
->attr
.pointer
)
13079 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
13080 "may not have the POINTER attribute", me_arg
->name
,
13081 c
->name
, me_arg
->name
, &c
->loc
);
13087 if (me_arg
->attr
.allocatable
)
13089 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
13090 "may not be ALLOCATABLE", me_arg
->name
, c
->name
,
13091 me_arg
->name
, &c
->loc
);
13097 if (gfc_type_is_extensible (sym
) && me_arg
->ts
.type
!= BT_CLASS
)
13099 gfc_error ("Non-polymorphic passed-object dummy argument of %qs"
13100 " at %L", c
->name
, &c
->loc
);
13107 /* Check type-spec if this is not the parent-type component. */
13108 if (((sym
->attr
.is_class
13109 && (!sym
->components
->ts
.u
.derived
->attr
.extension
13110 || c
!= sym
->components
->ts
.u
.derived
->components
))
13111 || (!sym
->attr
.is_class
13112 && (!sym
->attr
.extension
|| c
!= sym
->components
)))
13113 && !sym
->attr
.vtype
13114 && !resolve_typespec_used (&c
->ts
, &c
->loc
, c
->name
))
13117 /* If this type is an extension, set the accessibility of the parent
13120 && ((sym
->attr
.is_class
13121 && c
== sym
->components
->ts
.u
.derived
->components
)
13122 || (!sym
->attr
.is_class
&& c
== sym
->components
))
13123 && strcmp (super_type
->name
, c
->name
) == 0)
13124 c
->attr
.access
= super_type
->attr
.access
;
13126 /* If this type is an extension, see if this component has the same name
13127 as an inherited type-bound procedure. */
13128 if (super_type
&& !sym
->attr
.is_class
13129 && gfc_find_typebound_proc (super_type
, NULL
, c
->name
, true, NULL
))
13131 gfc_error ("Component %qs of %qs at %L has the same name as an"
13132 " inherited type-bound procedure",
13133 c
->name
, sym
->name
, &c
->loc
);
13137 if (c
->ts
.type
== BT_CHARACTER
&& !c
->attr
.proc_pointer
13138 && !c
->ts
.deferred
)
13140 if (c
->ts
.u
.cl
->length
== NULL
13141 || (!resolve_charlen(c
->ts
.u
.cl
))
13142 || !gfc_is_constant_expr (c
->ts
.u
.cl
->length
))
13144 gfc_error ("Character length of component %qs needs to "
13145 "be a constant specification expression at %L",
13147 c
->ts
.u
.cl
->length
? &c
->ts
.u
.cl
->length
->where
: &c
->loc
);
13152 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
13153 && !c
->attr
.pointer
&& !c
->attr
.allocatable
)
13155 gfc_error ("Character component %qs of %qs at %L with deferred "
13156 "length must be a POINTER or ALLOCATABLE",
13157 c
->name
, sym
->name
, &c
->loc
);
13161 /* Add the hidden deferred length field. */
13162 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
&& !c
->attr
.function
13163 && !sym
->attr
.is_class
)
13165 char name
[GFC_MAX_SYMBOL_LEN
+9];
13166 gfc_component
*strlen
;
13167 sprintf (name
, "_%s_length", c
->name
);
13168 strlen
= gfc_find_component (sym
, name
, true, true);
13169 if (strlen
== NULL
)
13171 if (!gfc_add_component (sym
, name
, &strlen
))
13173 strlen
->ts
.type
= BT_INTEGER
;
13174 strlen
->ts
.kind
= gfc_charlen_int_kind
;
13175 strlen
->attr
.access
= ACCESS_PRIVATE
;
13176 strlen
->attr
.artificial
= 1;
13180 if (c
->ts
.type
== BT_DERIVED
13181 && sym
->component_access
!= ACCESS_PRIVATE
13182 && gfc_check_symbol_access (sym
)
13183 && !is_sym_host_assoc (c
->ts
.u
.derived
, sym
->ns
)
13184 && !c
->ts
.u
.derived
->attr
.use_assoc
13185 && !gfc_check_symbol_access (c
->ts
.u
.derived
)
13186 && !gfc_notify_std (GFC_STD_F2003
, "the component %qs is a "
13187 "PRIVATE type and cannot be a component of "
13188 "%qs, which is PUBLIC at %L", c
->name
,
13189 sym
->name
, &sym
->declared_at
))
13192 if ((sym
->attr
.sequence
|| sym
->attr
.is_bind_c
) && c
->ts
.type
== BT_CLASS
)
13194 gfc_error ("Polymorphic component %s at %L in SEQUENCE or BIND(C) "
13195 "type %s", c
->name
, &c
->loc
, sym
->name
);
13199 if (sym
->attr
.sequence
)
13201 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.sequence
== 0)
13203 gfc_error ("Component %s of SEQUENCE type declared at %L does "
13204 "not have the SEQUENCE attribute",
13205 c
->ts
.u
.derived
->name
, &sym
->declared_at
);
13210 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.generic
)
13211 c
->ts
.u
.derived
= gfc_find_dt_in_generic (c
->ts
.u
.derived
);
13212 else if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
13213 && CLASS_DATA (c
)->ts
.u
.derived
->attr
.generic
)
13214 CLASS_DATA (c
)->ts
.u
.derived
13215 = gfc_find_dt_in_generic (CLASS_DATA (c
)->ts
.u
.derived
);
13217 if (!sym
->attr
.is_class
&& c
->ts
.type
== BT_DERIVED
&& !sym
->attr
.vtype
13218 && c
->attr
.pointer
&& c
->ts
.u
.derived
->components
== NULL
13219 && !c
->ts
.u
.derived
->attr
.zero_comp
)
13221 gfc_error ("The pointer component %qs of %qs at %L is a type "
13222 "that has not been declared", c
->name
, sym
->name
,
13227 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
13228 && CLASS_DATA (c
)->attr
.class_pointer
13229 && CLASS_DATA (c
)->ts
.u
.derived
->components
== NULL
13230 && !CLASS_DATA (c
)->ts
.u
.derived
->attr
.zero_comp
13231 && !UNLIMITED_POLY (c
))
13233 gfc_error ("The pointer component %qs of %qs at %L is a type "
13234 "that has not been declared", c
->name
, sym
->name
,
13240 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.flavor
!= FL_PROCEDURE
13241 && (!c
->attr
.class_ok
13242 || !(CLASS_DATA (c
)->attr
.class_pointer
13243 || CLASS_DATA (c
)->attr
.allocatable
)))
13245 gfc_error ("Component %qs with CLASS at %L must be allocatable "
13246 "or pointer", c
->name
, &c
->loc
);
13247 /* Prevent a recurrence of the error. */
13248 c
->ts
.type
= BT_UNKNOWN
;
13252 /* Ensure that all the derived type components are put on the
13253 derived type list; even in formal namespaces, where derived type
13254 pointer components might not have been declared. */
13255 if (c
->ts
.type
== BT_DERIVED
13257 && c
->ts
.u
.derived
->components
13259 && sym
!= c
->ts
.u
.derived
)
13260 add_dt_to_dt_list (c
->ts
.u
.derived
);
13262 if (!gfc_resolve_array_spec (c
->as
,
13263 !(c
->attr
.pointer
|| c
->attr
.proc_pointer
13264 || c
->attr
.allocatable
)))
13267 if (c
->initializer
&& !sym
->attr
.vtype
13268 && !gfc_check_assign_symbol (sym
, c
, c
->initializer
))
13275 check_defined_assignments (sym
);
13277 if (!sym
->attr
.defined_assign_comp
&& super_type
)
13278 sym
->attr
.defined_assign_comp
13279 = super_type
->attr
.defined_assign_comp
;
13281 /* If this is a non-ABSTRACT type extending an ABSTRACT one, ensure that
13282 all DEFERRED bindings are overridden. */
13283 if (super_type
&& super_type
->attr
.abstract
&& !sym
->attr
.abstract
13284 && !sym
->attr
.is_class
13285 && !ensure_not_abstract (sym
, super_type
))
13288 /* Add derived type to the derived type list. */
13289 add_dt_to_dt_list (sym
);
13295 /* The following procedure does the full resolution of a derived type,
13296 including resolution of all type-bound procedures (if present). In contrast
13297 to 'resolve_fl_derived0' this can only be done after the module has been
13298 parsed completely. */
13301 resolve_fl_derived (gfc_symbol
*sym
)
13303 gfc_symbol
*gen_dt
= NULL
;
13305 if (sym
->attr
.unlimited_polymorphic
)
13308 if (!sym
->attr
.is_class
)
13309 gfc_find_symbol (sym
->name
, sym
->ns
, 0, &gen_dt
);
13310 if (gen_dt
&& gen_dt
->generic
&& gen_dt
->generic
->next
13311 && (!gen_dt
->generic
->sym
->attr
.use_assoc
13312 || gen_dt
->generic
->sym
->module
!= gen_dt
->generic
->next
->sym
->module
)
13313 && !gfc_notify_std (GFC_STD_F2003
, "Generic name %qs of function "
13314 "%qs at %L being the same name as derived "
13315 "type at %L", sym
->name
,
13316 gen_dt
->generic
->sym
== sym
13317 ? gen_dt
->generic
->next
->sym
->name
13318 : gen_dt
->generic
->sym
->name
,
13319 gen_dt
->generic
->sym
== sym
13320 ? &gen_dt
->generic
->next
->sym
->declared_at
13321 : &gen_dt
->generic
->sym
->declared_at
,
13322 &sym
->declared_at
))
13325 /* Resolve the finalizer procedures. */
13326 if (!gfc_resolve_finalizers (sym
, NULL
))
13329 if (sym
->attr
.is_class
&& sym
->ts
.u
.derived
== NULL
)
13331 /* Fix up incomplete CLASS symbols. */
13332 gfc_component
*data
= gfc_find_component (sym
, "_data", true, true);
13333 gfc_component
*vptr
= gfc_find_component (sym
, "_vptr", true, true);
13335 /* Nothing more to do for unlimited polymorphic entities. */
13336 if (data
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
13338 else if (vptr
->ts
.u
.derived
== NULL
)
13340 gfc_symbol
*vtab
= gfc_find_derived_vtab (data
->ts
.u
.derived
);
13342 vptr
->ts
.u
.derived
= vtab
->ts
.u
.derived
;
13346 if (!resolve_fl_derived0 (sym
))
13349 /* Resolve the type-bound procedures. */
13350 if (!resolve_typebound_procedures (sym
))
13358 resolve_fl_namelist (gfc_symbol
*sym
)
13363 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
13365 /* Check again, the check in match only works if NAMELIST comes
13367 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SIZE
)
13369 gfc_error ("Assumed size array %qs in namelist %qs at %L is not "
13370 "allowed", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13374 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SHAPE
13375 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object %qs "
13376 "with assumed shape in namelist %qs at %L",
13377 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
13380 if (is_non_constant_shape_array (nl
->sym
)
13381 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object %qs "
13382 "with nonconstant shape in namelist %qs at %L",
13383 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
13386 if (nl
->sym
->ts
.type
== BT_CHARACTER
13387 && (nl
->sym
->ts
.u
.cl
->length
== NULL
13388 || !gfc_is_constant_expr (nl
->sym
->ts
.u
.cl
->length
))
13389 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST object %qs with "
13390 "nonconstant character length in "
13391 "namelist %qs at %L", nl
->sym
->name
,
13392 sym
->name
, &sym
->declared_at
))
13395 /* FIXME: Once UDDTIO is implemented, the following can be
13397 if (nl
->sym
->ts
.type
== BT_CLASS
)
13399 gfc_error ("NAMELIST object %qs in namelist %qs at %L is "
13400 "polymorphic and requires a defined input/output "
13401 "procedure", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13405 if (nl
->sym
->ts
.type
== BT_DERIVED
13406 && (nl
->sym
->ts
.u
.derived
->attr
.alloc_comp
13407 || nl
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
13409 if (!gfc_notify_std (GFC_STD_F2003
, "NAMELIST object %qs in "
13410 "namelist %qs at %L with ALLOCATABLE "
13411 "or POINTER components", nl
->sym
->name
,
13412 sym
->name
, &sym
->declared_at
))
13415 /* FIXME: Once UDDTIO is implemented, the following can be
13417 gfc_error ("NAMELIST object %qs in namelist %qs at %L has "
13418 "ALLOCATABLE or POINTER components and thus requires "
13419 "a defined input/output procedure", nl
->sym
->name
,
13420 sym
->name
, &sym
->declared_at
);
13425 /* Reject PRIVATE objects in a PUBLIC namelist. */
13426 if (gfc_check_symbol_access (sym
))
13428 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
13430 if (!nl
->sym
->attr
.use_assoc
13431 && !is_sym_host_assoc (nl
->sym
, sym
->ns
)
13432 && !gfc_check_symbol_access (nl
->sym
))
13434 gfc_error ("NAMELIST object %qs was declared PRIVATE and "
13435 "cannot be member of PUBLIC namelist %qs at %L",
13436 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13440 /* Types with private components that came here by USE-association. */
13441 if (nl
->sym
->ts
.type
== BT_DERIVED
13442 && derived_inaccessible (nl
->sym
->ts
.u
.derived
))
13444 gfc_error ("NAMELIST object %qs has use-associated PRIVATE "
13445 "components and cannot be member of namelist %qs at %L",
13446 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13450 /* Types with private components that are defined in the same module. */
13451 if (nl
->sym
->ts
.type
== BT_DERIVED
13452 && !is_sym_host_assoc (nl
->sym
->ts
.u
.derived
, sym
->ns
)
13453 && nl
->sym
->ts
.u
.derived
->attr
.private_comp
)
13455 gfc_error ("NAMELIST object %qs has PRIVATE components and "
13456 "cannot be a member of PUBLIC namelist %qs at %L",
13457 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
13464 /* 14.1.2 A module or internal procedure represent local entities
13465 of the same type as a namelist member and so are not allowed. */
13466 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
13468 if (nl
->sym
->ts
.kind
!= 0 && nl
->sym
->attr
.flavor
== FL_VARIABLE
)
13471 if (nl
->sym
->attr
.function
&& nl
->sym
== nl
->sym
->result
)
13472 if ((nl
->sym
== sym
->ns
->proc_name
)
13474 (sym
->ns
->parent
&& nl
->sym
== sym
->ns
->parent
->proc_name
))
13479 gfc_find_symbol (nl
->sym
->name
, sym
->ns
, 1, &nlsym
);
13480 if (nlsym
&& nlsym
->attr
.flavor
== FL_PROCEDURE
)
13482 gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
13483 "attribute in %qs at %L", nlsym
->name
,
13484 &sym
->declared_at
);
13494 resolve_fl_parameter (gfc_symbol
*sym
)
13496 /* A parameter array's shape needs to be constant. */
13497 if (sym
->as
!= NULL
13498 && (sym
->as
->type
== AS_DEFERRED
13499 || is_non_constant_shape_array (sym
)))
13501 gfc_error ("Parameter array %qs at %L cannot be automatic "
13502 "or of deferred shape", sym
->name
, &sym
->declared_at
);
13506 /* Make sure a parameter that has been implicitly typed still
13507 matches the implicit type, since PARAMETER statements can precede
13508 IMPLICIT statements. */
13509 if (sym
->attr
.implicit_type
13510 && !gfc_compare_types (&sym
->ts
, gfc_get_default_type (sym
->name
,
13513 gfc_error ("Implicitly typed PARAMETER %qs at %L doesn't match a "
13514 "later IMPLICIT type", sym
->name
, &sym
->declared_at
);
13518 /* Make sure the types of derived parameters are consistent. This
13519 type checking is deferred until resolution because the type may
13520 refer to a derived type from the host. */
13521 if (sym
->ts
.type
== BT_DERIVED
13522 && !gfc_compare_types (&sym
->ts
, &sym
->value
->ts
))
13524 gfc_error ("Incompatible derived type in PARAMETER at %L",
13525 &sym
->value
->where
);
13532 /* Do anything necessary to resolve a symbol. Right now, we just
13533 assume that an otherwise unknown symbol is a variable. This sort
13534 of thing commonly happens for symbols in module. */
13537 resolve_symbol (gfc_symbol
*sym
)
13539 int check_constant
, mp_flag
;
13540 gfc_symtree
*symtree
;
13541 gfc_symtree
*this_symtree
;
13544 symbol_attribute class_attr
;
13545 gfc_array_spec
*as
;
13546 bool saved_specification_expr
;
13552 if (sym
->attr
.artificial
)
13555 if (sym
->attr
.unlimited_polymorphic
)
13558 if (sym
->attr
.flavor
== FL_UNKNOWN
13559 || (sym
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.intrinsic
13560 && !sym
->attr
.generic
&& !sym
->attr
.external
13561 && sym
->attr
.if_source
== IFSRC_UNKNOWN
13562 && sym
->ts
.type
== BT_UNKNOWN
))
13565 /* If we find that a flavorless symbol is an interface in one of the
13566 parent namespaces, find its symtree in this namespace, free the
13567 symbol and set the symtree to point to the interface symbol. */
13568 for (ns
= gfc_current_ns
->parent
; ns
; ns
= ns
->parent
)
13570 symtree
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
13571 if (symtree
&& (symtree
->n
.sym
->generic
||
13572 (symtree
->n
.sym
->attr
.flavor
== FL_PROCEDURE
13573 && sym
->ns
->construct_entities
)))
13575 this_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
13577 if (this_symtree
->n
.sym
== sym
)
13579 symtree
->n
.sym
->refs
++;
13580 gfc_release_symbol (sym
);
13581 this_symtree
->n
.sym
= symtree
->n
.sym
;
13587 /* Otherwise give it a flavor according to such attributes as
13589 if (sym
->attr
.flavor
== FL_UNKNOWN
&& sym
->attr
.external
== 0
13590 && sym
->attr
.intrinsic
== 0)
13591 sym
->attr
.flavor
= FL_VARIABLE
;
13592 else if (sym
->attr
.flavor
== FL_UNKNOWN
)
13594 sym
->attr
.flavor
= FL_PROCEDURE
;
13595 if (sym
->attr
.dimension
)
13596 sym
->attr
.function
= 1;
13600 if (sym
->attr
.external
&& sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.function
)
13601 gfc_add_function (&sym
->attr
, sym
->name
, &sym
->declared_at
);
13603 if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
13604 && !resolve_procedure_interface (sym
))
13607 if (sym
->attr
.is_protected
&& !sym
->attr
.proc_pointer
13608 && (sym
->attr
.procedure
|| sym
->attr
.external
))
13610 if (sym
->attr
.external
)
13611 gfc_error ("PROTECTED attribute conflicts with EXTERNAL attribute "
13612 "at %L", &sym
->declared_at
);
13614 gfc_error ("PROCEDURE attribute conflicts with PROTECTED attribute "
13615 "at %L", &sym
->declared_at
);
13620 if (sym
->attr
.flavor
== FL_DERIVED
&& !resolve_fl_derived (sym
))
13623 /* Symbols that are module procedures with results (functions) have
13624 the types and array specification copied for type checking in
13625 procedures that call them, as well as for saving to a module
13626 file. These symbols can't stand the scrutiny that their results
13628 mp_flag
= (sym
->result
!= NULL
&& sym
->result
!= sym
);
13630 /* Make sure that the intrinsic is consistent with its internal
13631 representation. This needs to be done before assigning a default
13632 type to avoid spurious warnings. */
13633 if (sym
->attr
.flavor
!= FL_MODULE
&& sym
->attr
.intrinsic
13634 && !gfc_resolve_intrinsic (sym
, &sym
->declared_at
))
13637 /* Resolve associate names. */
13639 resolve_assoc_var (sym
, true);
13641 /* Assign default type to symbols that need one and don't have one. */
13642 if (sym
->ts
.type
== BT_UNKNOWN
)
13644 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
)
13646 gfc_set_default_type (sym
, 1, NULL
);
13649 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.external
13650 && !sym
->attr
.function
&& !sym
->attr
.subroutine
13651 && gfc_get_default_type (sym
->name
, sym
->ns
)->type
== BT_UNKNOWN
)
13652 gfc_add_subroutine (&sym
->attr
, sym
->name
, &sym
->declared_at
);
13654 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
13656 /* The specific case of an external procedure should emit an error
13657 in the case that there is no implicit type. */
13659 gfc_set_default_type (sym
, sym
->attr
.external
, NULL
);
13662 /* Result may be in another namespace. */
13663 resolve_symbol (sym
->result
);
13665 if (!sym
->result
->attr
.proc_pointer
)
13667 sym
->ts
= sym
->result
->ts
;
13668 sym
->as
= gfc_copy_array_spec (sym
->result
->as
);
13669 sym
->attr
.dimension
= sym
->result
->attr
.dimension
;
13670 sym
->attr
.pointer
= sym
->result
->attr
.pointer
;
13671 sym
->attr
.allocatable
= sym
->result
->attr
.allocatable
;
13672 sym
->attr
.contiguous
= sym
->result
->attr
.contiguous
;
13677 else if (mp_flag
&& sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
13679 bool saved_specification_expr
= specification_expr
;
13680 specification_expr
= true;
13681 gfc_resolve_array_spec (sym
->result
->as
, false);
13682 specification_expr
= saved_specification_expr
;
13685 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
13687 as
= CLASS_DATA (sym
)->as
;
13688 class_attr
= CLASS_DATA (sym
)->attr
;
13689 class_attr
.pointer
= class_attr
.class_pointer
;
13693 class_attr
= sym
->attr
;
13698 if (sym
->attr
.contiguous
13699 && (!class_attr
.dimension
13700 || (as
->type
!= AS_ASSUMED_SHAPE
&& as
->type
!= AS_ASSUMED_RANK
13701 && !class_attr
.pointer
)))
13703 gfc_error ("%qs at %L has the CONTIGUOUS attribute but is not an "
13704 "array pointer or an assumed-shape or assumed-rank array",
13705 sym
->name
, &sym
->declared_at
);
13709 /* Assumed size arrays and assumed shape arrays must be dummy
13710 arguments. Array-spec's of implied-shape should have been resolved to
13711 AS_EXPLICIT already. */
13715 gcc_assert (as
->type
!= AS_IMPLIED_SHAPE
);
13716 if (((as
->type
== AS_ASSUMED_SIZE
&& !as
->cp_was_assumed
)
13717 || as
->type
== AS_ASSUMED_SHAPE
)
13718 && !sym
->attr
.dummy
&& !sym
->attr
.select_type_temporary
)
13720 if (as
->type
== AS_ASSUMED_SIZE
)
13721 gfc_error ("Assumed size array at %L must be a dummy argument",
13722 &sym
->declared_at
);
13724 gfc_error ("Assumed shape array at %L must be a dummy argument",
13725 &sym
->declared_at
);
13728 /* TS 29113, C535a. */
13729 if (as
->type
== AS_ASSUMED_RANK
&& !sym
->attr
.dummy
13730 && !sym
->attr
.select_type_temporary
)
13732 gfc_error ("Assumed-rank array at %L must be a dummy argument",
13733 &sym
->declared_at
);
13736 if (as
->type
== AS_ASSUMED_RANK
13737 && (sym
->attr
.codimension
|| sym
->attr
.value
))
13739 gfc_error ("Assumed-rank array at %L may not have the VALUE or "
13740 "CODIMENSION attribute", &sym
->declared_at
);
13745 /* Make sure symbols with known intent or optional are really dummy
13746 variable. Because of ENTRY statement, this has to be deferred
13747 until resolution time. */
13749 if (!sym
->attr
.dummy
13750 && (sym
->attr
.optional
|| sym
->attr
.intent
!= INTENT_UNKNOWN
))
13752 gfc_error ("Symbol at %L is not a DUMMY variable", &sym
->declared_at
);
13756 if (sym
->attr
.value
&& !sym
->attr
.dummy
)
13758 gfc_error ("%qs at %L cannot have the VALUE attribute because "
13759 "it is not a dummy argument", sym
->name
, &sym
->declared_at
);
13763 if (sym
->attr
.value
&& sym
->ts
.type
== BT_CHARACTER
)
13765 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
13766 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
13768 gfc_error ("Character dummy variable %qs at %L with VALUE "
13769 "attribute must have constant length",
13770 sym
->name
, &sym
->declared_at
);
13774 if (sym
->ts
.is_c_interop
13775 && mpz_cmp_si (cl
->length
->value
.integer
, 1) != 0)
13777 gfc_error ("C interoperable character dummy variable %qs at %L "
13778 "with VALUE attribute must have length one",
13779 sym
->name
, &sym
->declared_at
);
13784 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
13785 && sym
->ts
.u
.derived
->attr
.generic
)
13787 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
13788 if (!sym
->ts
.u
.derived
)
13790 gfc_error ("The derived type %qs at %L is of type %qs, "
13791 "which has not been defined", sym
->name
,
13792 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
13793 sym
->ts
.type
= BT_UNKNOWN
;
13798 /* Use the same constraints as TYPE(*), except for the type check
13799 and that only scalars and assumed-size arrays are permitted. */
13800 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
13802 if (!sym
->attr
.dummy
)
13804 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
13805 "a dummy argument", sym
->name
, &sym
->declared_at
);
13809 if (sym
->ts
.type
!= BT_ASSUMED
&& sym
->ts
.type
!= BT_INTEGER
13810 && sym
->ts
.type
!= BT_REAL
&& sym
->ts
.type
!= BT_LOGICAL
13811 && sym
->ts
.type
!= BT_COMPLEX
)
13813 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
13814 "of type TYPE(*) or of an numeric intrinsic type",
13815 sym
->name
, &sym
->declared_at
);
13819 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
13820 || sym
->attr
.pointer
|| sym
->attr
.value
)
13822 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
13823 "have the ALLOCATABLE, CODIMENSION, POINTER or VALUE "
13824 "attribute", sym
->name
, &sym
->declared_at
);
13828 if (sym
->attr
.intent
== INTENT_OUT
)
13830 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
13831 "have the INTENT(OUT) attribute",
13832 sym
->name
, &sym
->declared_at
);
13835 if (sym
->attr
.dimension
&& sym
->as
->type
!= AS_ASSUMED_SIZE
)
13837 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall "
13838 "either be a scalar or an assumed-size array",
13839 sym
->name
, &sym
->declared_at
);
13843 /* Set the type to TYPE(*) and add a dimension(*) to ensure
13844 NO_ARG_CHECK is correctly handled in trans*.c, e.g. with
13846 sym
->ts
.type
= BT_ASSUMED
;
13847 sym
->as
= gfc_get_array_spec ();
13848 sym
->as
->type
= AS_ASSUMED_SIZE
;
13850 sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
13852 else if (sym
->ts
.type
== BT_ASSUMED
)
13854 /* TS 29113, C407a. */
13855 if (!sym
->attr
.dummy
)
13857 gfc_error ("Assumed type of variable %s at %L is only permitted "
13858 "for dummy variables", sym
->name
, &sym
->declared_at
);
13861 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
13862 || sym
->attr
.pointer
|| sym
->attr
.value
)
13864 gfc_error ("Assumed-type variable %s at %L may not have the "
13865 "ALLOCATABLE, CODIMENSION, POINTER or VALUE attribute",
13866 sym
->name
, &sym
->declared_at
);
13869 if (sym
->attr
.intent
== INTENT_OUT
)
13871 gfc_error ("Assumed-type variable %s at %L may not have the "
13872 "INTENT(OUT) attribute",
13873 sym
->name
, &sym
->declared_at
);
13876 if (sym
->attr
.dimension
&& sym
->as
->type
== AS_EXPLICIT
)
13878 gfc_error ("Assumed-type variable %s at %L shall not be an "
13879 "explicit-shape array", sym
->name
, &sym
->declared_at
);
13884 /* If the symbol is marked as bind(c), verify it's type and kind. Do not
13885 do this for something that was implicitly typed because that is handled
13886 in gfc_set_default_type. Handle dummy arguments and procedure
13887 definitions separately. Also, anything that is use associated is not
13888 handled here but instead is handled in the module it is declared in.
13889 Finally, derived type definitions are allowed to be BIND(C) since that
13890 only implies that they're interoperable, and they are checked fully for
13891 interoperability when a variable is declared of that type. */
13892 if (sym
->attr
.is_bind_c
&& sym
->attr
.implicit_type
== 0 &&
13893 sym
->attr
.use_assoc
== 0 && sym
->attr
.dummy
== 0 &&
13894 sym
->attr
.flavor
!= FL_PROCEDURE
&& sym
->attr
.flavor
!= FL_DERIVED
)
13898 /* First, make sure the variable is declared at the
13899 module-level scope (J3/04-007, Section 15.3). */
13900 if (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
&&
13901 sym
->attr
.in_common
== 0)
13903 gfc_error ("Variable %qs at %L cannot be BIND(C) because it "
13904 "is neither a COMMON block nor declared at the "
13905 "module level scope", sym
->name
, &(sym
->declared_at
));
13908 else if (sym
->common_head
!= NULL
)
13910 t
= verify_com_block_vars_c_interop (sym
->common_head
);
13914 /* If type() declaration, we need to verify that the components
13915 of the given type are all C interoperable, etc. */
13916 if (sym
->ts
.type
== BT_DERIVED
&&
13917 sym
->ts
.u
.derived
->attr
.is_c_interop
!= 1)
13919 /* Make sure the user marked the derived type as BIND(C). If
13920 not, call the verify routine. This could print an error
13921 for the derived type more than once if multiple variables
13922 of that type are declared. */
13923 if (sym
->ts
.u
.derived
->attr
.is_bind_c
!= 1)
13924 verify_bind_c_derived_type (sym
->ts
.u
.derived
);
13928 /* Verify the variable itself as C interoperable if it
13929 is BIND(C). It is not possible for this to succeed if
13930 the verify_bind_c_derived_type failed, so don't have to handle
13931 any error returned by verify_bind_c_derived_type. */
13932 t
= verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
13933 sym
->common_block
);
13938 /* clear the is_bind_c flag to prevent reporting errors more than
13939 once if something failed. */
13940 sym
->attr
.is_bind_c
= 0;
13945 /* If a derived type symbol has reached this point, without its
13946 type being declared, we have an error. Notice that most
13947 conditions that produce undefined derived types have already
13948 been dealt with. However, the likes of:
13949 implicit type(t) (t) ..... call foo (t) will get us here if
13950 the type is not declared in the scope of the implicit
13951 statement. Change the type to BT_UNKNOWN, both because it is so
13952 and to prevent an ICE. */
13953 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
13954 && sym
->ts
.u
.derived
->components
== NULL
13955 && !sym
->ts
.u
.derived
->attr
.zero_comp
)
13957 gfc_error ("The derived type %qs at %L is of type %qs, "
13958 "which has not been defined", sym
->name
,
13959 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
13960 sym
->ts
.type
= BT_UNKNOWN
;
13964 /* Make sure that the derived type has been resolved and that the
13965 derived type is visible in the symbol's namespace, if it is a
13966 module function and is not PRIVATE. */
13967 if (sym
->ts
.type
== BT_DERIVED
13968 && sym
->ts
.u
.derived
->attr
.use_assoc
13969 && sym
->ns
->proc_name
13970 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
13971 && !resolve_fl_derived (sym
->ts
.u
.derived
))
13974 /* Unless the derived-type declaration is use associated, Fortran 95
13975 does not allow public entries of private derived types.
13976 See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
13977 161 in 95-006r3. */
13978 if (sym
->ts
.type
== BT_DERIVED
13979 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
13980 && !sym
->ts
.u
.derived
->attr
.use_assoc
13981 && gfc_check_symbol_access (sym
)
13982 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
13983 && !gfc_notify_std (GFC_STD_F2003
, "PUBLIC %s %qs at %L of PRIVATE "
13984 "derived type %qs",
13985 (sym
->attr
.flavor
== FL_PARAMETER
)
13986 ? "parameter" : "variable",
13987 sym
->name
, &sym
->declared_at
,
13988 sym
->ts
.u
.derived
->name
))
13991 /* F2008, C1302. */
13992 if (sym
->ts
.type
== BT_DERIVED
13993 && ((sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
13994 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
13995 || sym
->ts
.u
.derived
->attr
.lock_comp
)
13996 && !sym
->attr
.codimension
&& !sym
->ts
.u
.derived
->attr
.coarray_comp
)
13998 gfc_error ("Variable %s at %L of type LOCK_TYPE or with subcomponent of "
13999 "type LOCK_TYPE must be a coarray", sym
->name
,
14000 &sym
->declared_at
);
14004 /* An assumed-size array with INTENT(OUT) shall not be of a type for which
14005 default initialization is defined (5.1.2.4.4). */
14006 if (sym
->ts
.type
== BT_DERIVED
14008 && sym
->attr
.intent
== INTENT_OUT
14010 && sym
->as
->type
== AS_ASSUMED_SIZE
)
14012 for (c
= sym
->ts
.u
.derived
->components
; c
; c
= c
->next
)
14014 if (c
->initializer
)
14016 gfc_error ("The INTENT(OUT) dummy argument %qs at %L is "
14017 "ASSUMED SIZE and so cannot have a default initializer",
14018 sym
->name
, &sym
->declared_at
);
14025 if (sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.dummy
14026 && sym
->attr
.intent
== INTENT_OUT
&& sym
->attr
.lock_comp
)
14028 gfc_error ("Dummy argument %qs at %L of LOCK_TYPE shall not be "
14029 "INTENT(OUT)", sym
->name
, &sym
->declared_at
);
14034 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
14035 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
14036 && CLASS_DATA (sym
)->attr
.coarray_comp
))
14037 || class_attr
.codimension
)
14038 && (sym
->attr
.result
|| sym
->result
== sym
))
14040 gfc_error ("Function result %qs at %L shall not be a coarray or have "
14041 "a coarray component", sym
->name
, &sym
->declared_at
);
14046 if (sym
->attr
.codimension
&& sym
->ts
.type
== BT_DERIVED
14047 && sym
->ts
.u
.derived
->ts
.is_iso_c
)
14049 gfc_error ("Variable %qs at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
14050 "shall not be a coarray", sym
->name
, &sym
->declared_at
);
14055 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
14056 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
14057 && CLASS_DATA (sym
)->attr
.coarray_comp
))
14058 && (class_attr
.codimension
|| class_attr
.pointer
|| class_attr
.dimension
14059 || class_attr
.allocatable
))
14061 gfc_error ("Variable %qs at %L with coarray component shall be a "
14062 "nonpointer, nonallocatable scalar, which is not a coarray",
14063 sym
->name
, &sym
->declared_at
);
14067 /* F2008, C526. The function-result case was handled above. */
14068 if (class_attr
.codimension
14069 && !(class_attr
.allocatable
|| sym
->attr
.dummy
|| sym
->attr
.save
14070 || sym
->attr
.select_type_temporary
14071 || sym
->ns
->save_all
14072 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
14073 || sym
->ns
->proc_name
->attr
.is_main_program
14074 || sym
->attr
.function
|| sym
->attr
.result
|| sym
->attr
.use_assoc
))
14076 gfc_error ("Variable %qs at %L is a coarray and is not ALLOCATABLE, SAVE "
14077 "nor a dummy argument", sym
->name
, &sym
->declared_at
);
14081 else if (class_attr
.codimension
&& !sym
->attr
.select_type_temporary
14082 && !class_attr
.allocatable
&& as
&& as
->cotype
== AS_DEFERRED
)
14084 gfc_error ("Coarray variable %qs at %L shall not have codimensions with "
14085 "deferred shape", sym
->name
, &sym
->declared_at
);
14088 else if (class_attr
.codimension
&& class_attr
.allocatable
&& as
14089 && (as
->cotype
!= AS_DEFERRED
|| as
->type
!= AS_DEFERRED
))
14091 gfc_error ("Allocatable coarray variable %qs at %L must have "
14092 "deferred shape", sym
->name
, &sym
->declared_at
);
14097 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
14098 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
14099 && CLASS_DATA (sym
)->attr
.coarray_comp
))
14100 || (class_attr
.codimension
&& class_attr
.allocatable
))
14101 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
)
14103 gfc_error ("Variable %qs at %L is INTENT(OUT) and can thus not be an "
14104 "allocatable coarray or have coarray components",
14105 sym
->name
, &sym
->declared_at
);
14109 if (class_attr
.codimension
&& sym
->attr
.dummy
14110 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.is_bind_c
)
14112 gfc_error ("Coarray dummy variable %qs at %L not allowed in BIND(C) "
14113 "procedure %qs", sym
->name
, &sym
->declared_at
,
14114 sym
->ns
->proc_name
->name
);
14118 if (sym
->ts
.type
== BT_LOGICAL
14119 && ((sym
->attr
.function
&& sym
->attr
.is_bind_c
&& sym
->result
== sym
)
14120 || ((sym
->attr
.dummy
|| sym
->attr
.result
) && sym
->ns
->proc_name
14121 && sym
->ns
->proc_name
->attr
.is_bind_c
)))
14124 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
14125 if (gfc_logical_kinds
[i
].kind
== sym
->ts
.kind
)
14127 if (!gfc_logical_kinds
[i
].c_bool
&& sym
->attr
.dummy
14128 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL dummy argument %qs at "
14129 "%L with non-C_Bool kind in BIND(C) procedure "
14130 "%qs", sym
->name
, &sym
->declared_at
,
14131 sym
->ns
->proc_name
->name
))
14133 else if (!gfc_logical_kinds
[i
].c_bool
14134 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL result variable "
14135 "%qs at %L with non-C_Bool kind in "
14136 "BIND(C) procedure %qs", sym
->name
,
14138 sym
->attr
.function
? sym
->name
14139 : sym
->ns
->proc_name
->name
))
14143 switch (sym
->attr
.flavor
)
14146 if (!resolve_fl_variable (sym
, mp_flag
))
14151 if (!resolve_fl_procedure (sym
, mp_flag
))
14156 if (!resolve_fl_namelist (sym
))
14161 if (!resolve_fl_parameter (sym
))
14169 /* Resolve array specifier. Check as well some constraints
14170 on COMMON blocks. */
14172 check_constant
= sym
->attr
.in_common
&& !sym
->attr
.pointer
;
14174 /* Set the formal_arg_flag so that check_conflict will not throw
14175 an error for host associated variables in the specification
14176 expression for an array_valued function. */
14177 if (sym
->attr
.function
&& sym
->as
)
14178 formal_arg_flag
= 1;
14180 saved_specification_expr
= specification_expr
;
14181 specification_expr
= true;
14182 gfc_resolve_array_spec (sym
->as
, check_constant
);
14183 specification_expr
= saved_specification_expr
;
14185 formal_arg_flag
= 0;
14187 /* Resolve formal namespaces. */
14188 if (sym
->formal_ns
&& sym
->formal_ns
!= gfc_current_ns
14189 && !sym
->attr
.contained
&& !sym
->attr
.intrinsic
)
14190 gfc_resolve (sym
->formal_ns
);
14192 /* Make sure the formal namespace is present. */
14193 if (sym
->formal
&& !sym
->formal_ns
)
14195 gfc_formal_arglist
*formal
= sym
->formal
;
14196 while (formal
&& !formal
->sym
)
14197 formal
= formal
->next
;
14201 sym
->formal_ns
= formal
->sym
->ns
;
14202 if (sym
->ns
!= formal
->sym
->ns
)
14203 sym
->formal_ns
->refs
++;
14207 /* Check threadprivate restrictions. */
14208 if (sym
->attr
.threadprivate
&& !sym
->attr
.save
&& !sym
->ns
->save_all
14209 && (!sym
->attr
.in_common
14210 && sym
->module
== NULL
14211 && (sym
->ns
->proc_name
== NULL
14212 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
14213 gfc_error ("Threadprivate at %L isn't SAVEd", &sym
->declared_at
);
14215 /* Check omp declare target restrictions. */
14216 if (sym
->attr
.omp_declare_target
14217 && sym
->attr
.flavor
== FL_VARIABLE
14219 && !sym
->ns
->save_all
14220 && (!sym
->attr
.in_common
14221 && sym
->module
== NULL
14222 && (sym
->ns
->proc_name
== NULL
14223 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
14224 gfc_error ("!$OMP DECLARE TARGET variable %qs at %L isn't SAVEd",
14225 sym
->name
, &sym
->declared_at
);
14227 /* If we have come this far we can apply default-initializers, as
14228 described in 14.7.5, to those variables that have not already
14229 been assigned one. */
14230 if (sym
->ts
.type
== BT_DERIVED
14232 && !sym
->attr
.allocatable
14233 && !sym
->attr
.alloc_comp
)
14235 symbol_attribute
*a
= &sym
->attr
;
14237 if ((!a
->save
&& !a
->dummy
&& !a
->pointer
14238 && !a
->in_common
&& !a
->use_assoc
14239 && !a
->result
&& !a
->function
)
14240 || (a
->dummy
&& a
->intent
== INTENT_OUT
&& !a
->pointer
))
14241 apply_default_init (sym
);
14242 else if (a
->function
&& sym
->result
&& a
->access
!= ACCESS_PRIVATE
14243 && (sym
->ts
.u
.derived
->attr
.alloc_comp
14244 || sym
->ts
.u
.derived
->attr
.pointer_comp
))
14245 /* Mark the result symbol to be referenced, when it has allocatable
14247 sym
->result
->attr
.referenced
= 1;
14250 if (sym
->ts
.type
== BT_CLASS
&& sym
->ns
== gfc_current_ns
14251 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
14252 && !CLASS_DATA (sym
)->attr
.class_pointer
14253 && !CLASS_DATA (sym
)->attr
.allocatable
)
14254 apply_default_init (sym
);
14256 /* If this symbol has a type-spec, check it. */
14257 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
14258 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
))
14259 if (!resolve_typespec_used (&sym
->ts
, &sym
->declared_at
, sym
->name
))
14264 /************* Resolve DATA statements *************/
14268 gfc_data_value
*vnode
;
14274 /* Advance the values structure to point to the next value in the data list. */
14277 next_data_value (void)
14279 while (mpz_cmp_ui (values
.left
, 0) == 0)
14282 if (values
.vnode
->next
== NULL
)
14285 values
.vnode
= values
.vnode
->next
;
14286 mpz_set (values
.left
, values
.vnode
->repeat
);
14294 check_data_variable (gfc_data_variable
*var
, locus
*where
)
14300 ar_type mark
= AR_UNKNOWN
;
14302 mpz_t section_index
[GFC_MAX_DIMENSIONS
];
14308 if (!gfc_resolve_expr (var
->expr
))
14312 mpz_init_set_si (offset
, 0);
14315 if (e
->expr_type
!= EXPR_VARIABLE
)
14316 gfc_internal_error ("check_data_variable(): Bad expression");
14318 sym
= e
->symtree
->n
.sym
;
14320 if (sym
->ns
->is_block_data
&& !sym
->attr
.in_common
)
14322 gfc_error ("BLOCK DATA element %qs at %L must be in COMMON",
14323 sym
->name
, &sym
->declared_at
);
14326 if (e
->ref
== NULL
&& sym
->as
)
14328 gfc_error ("DATA array %qs at %L must be specified in a previous"
14329 " declaration", sym
->name
, where
);
14333 has_pointer
= sym
->attr
.pointer
;
14335 if (gfc_is_coindexed (e
))
14337 gfc_error ("DATA element %qs at %L cannot have a coindex", sym
->name
,
14342 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
14344 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.pointer
)
14348 && ref
->type
== REF_ARRAY
14349 && ref
->u
.ar
.type
!= AR_FULL
)
14351 gfc_error ("DATA element %qs at %L is a pointer and so must "
14352 "be a full array", sym
->name
, where
);
14357 if (e
->rank
== 0 || has_pointer
)
14359 mpz_init_set_ui (size
, 1);
14366 /* Find the array section reference. */
14367 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
14369 if (ref
->type
!= REF_ARRAY
)
14371 if (ref
->u
.ar
.type
== AR_ELEMENT
)
14377 /* Set marks according to the reference pattern. */
14378 switch (ref
->u
.ar
.type
)
14386 /* Get the start position of array section. */
14387 gfc_get_section_index (ar
, section_index
, &offset
);
14392 gcc_unreachable ();
14395 if (!gfc_array_size (e
, &size
))
14397 gfc_error ("Nonconstant array section at %L in DATA statement",
14399 mpz_clear (offset
);
14406 while (mpz_cmp_ui (size
, 0) > 0)
14408 if (!next_data_value ())
14410 gfc_error ("DATA statement at %L has more variables than values",
14416 t
= gfc_check_assign (var
->expr
, values
.vnode
->expr
, 0);
14420 /* If we have more than one element left in the repeat count,
14421 and we have more than one element left in the target variable,
14422 then create a range assignment. */
14423 /* FIXME: Only done for full arrays for now, since array sections
14425 if (mark
== AR_FULL
&& ref
&& ref
->next
== NULL
14426 && mpz_cmp_ui (values
.left
, 1) > 0 && mpz_cmp_ui (size
, 1) > 0)
14430 if (mpz_cmp (size
, values
.left
) >= 0)
14432 mpz_init_set (range
, values
.left
);
14433 mpz_sub (size
, size
, values
.left
);
14434 mpz_set_ui (values
.left
, 0);
14438 mpz_init_set (range
, size
);
14439 mpz_sub (values
.left
, values
.left
, size
);
14440 mpz_set_ui (size
, 0);
14443 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
14446 mpz_add (offset
, offset
, range
);
14453 /* Assign initial value to symbol. */
14456 mpz_sub_ui (values
.left
, values
.left
, 1);
14457 mpz_sub_ui (size
, size
, 1);
14459 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
14464 if (mark
== AR_FULL
)
14465 mpz_add_ui (offset
, offset
, 1);
14467 /* Modify the array section indexes and recalculate the offset
14468 for next element. */
14469 else if (mark
== AR_SECTION
)
14470 gfc_advance_section (section_index
, ar
, &offset
);
14474 if (mark
== AR_SECTION
)
14476 for (i
= 0; i
< ar
->dimen
; i
++)
14477 mpz_clear (section_index
[i
]);
14481 mpz_clear (offset
);
14487 static bool traverse_data_var (gfc_data_variable
*, locus
*);
14489 /* Iterate over a list of elements in a DATA statement. */
14492 traverse_data_list (gfc_data_variable
*var
, locus
*where
)
14495 iterator_stack frame
;
14496 gfc_expr
*e
, *start
, *end
, *step
;
14497 bool retval
= true;
14499 mpz_init (frame
.value
);
14502 start
= gfc_copy_expr (var
->iter
.start
);
14503 end
= gfc_copy_expr (var
->iter
.end
);
14504 step
= gfc_copy_expr (var
->iter
.step
);
14506 if (!gfc_simplify_expr (start
, 1)
14507 || start
->expr_type
!= EXPR_CONSTANT
)
14509 gfc_error ("start of implied-do loop at %L could not be "
14510 "simplified to a constant value", &start
->where
);
14514 if (!gfc_simplify_expr (end
, 1)
14515 || end
->expr_type
!= EXPR_CONSTANT
)
14517 gfc_error ("end of implied-do loop at %L could not be "
14518 "simplified to a constant value", &start
->where
);
14522 if (!gfc_simplify_expr (step
, 1)
14523 || step
->expr_type
!= EXPR_CONSTANT
)
14525 gfc_error ("step of implied-do loop at %L could not be "
14526 "simplified to a constant value", &start
->where
);
14531 mpz_set (trip
, end
->value
.integer
);
14532 mpz_sub (trip
, trip
, start
->value
.integer
);
14533 mpz_add (trip
, trip
, step
->value
.integer
);
14535 mpz_div (trip
, trip
, step
->value
.integer
);
14537 mpz_set (frame
.value
, start
->value
.integer
);
14539 frame
.prev
= iter_stack
;
14540 frame
.variable
= var
->iter
.var
->symtree
;
14541 iter_stack
= &frame
;
14543 while (mpz_cmp_ui (trip
, 0) > 0)
14545 if (!traverse_data_var (var
->list
, where
))
14551 e
= gfc_copy_expr (var
->expr
);
14552 if (!gfc_simplify_expr (e
, 1))
14559 mpz_add (frame
.value
, frame
.value
, step
->value
.integer
);
14561 mpz_sub_ui (trip
, trip
, 1);
14565 mpz_clear (frame
.value
);
14568 gfc_free_expr (start
);
14569 gfc_free_expr (end
);
14570 gfc_free_expr (step
);
14572 iter_stack
= frame
.prev
;
14577 /* Type resolve variables in the variable list of a DATA statement. */
14580 traverse_data_var (gfc_data_variable
*var
, locus
*where
)
14584 for (; var
; var
= var
->next
)
14586 if (var
->expr
== NULL
)
14587 t
= traverse_data_list (var
, where
);
14589 t
= check_data_variable (var
, where
);
14599 /* Resolve the expressions and iterators associated with a data statement.
14600 This is separate from the assignment checking because data lists should
14601 only be resolved once. */
14604 resolve_data_variables (gfc_data_variable
*d
)
14606 for (; d
; d
= d
->next
)
14608 if (d
->list
== NULL
)
14610 if (!gfc_resolve_expr (d
->expr
))
14615 if (!gfc_resolve_iterator (&d
->iter
, false, true))
14618 if (!resolve_data_variables (d
->list
))
14627 /* Resolve a single DATA statement. We implement this by storing a pointer to
14628 the value list into static variables, and then recursively traversing the
14629 variables list, expanding iterators and such. */
14632 resolve_data (gfc_data
*d
)
14635 if (!resolve_data_variables (d
->var
))
14638 values
.vnode
= d
->value
;
14639 if (d
->value
== NULL
)
14640 mpz_set_ui (values
.left
, 0);
14642 mpz_set (values
.left
, d
->value
->repeat
);
14644 if (!traverse_data_var (d
->var
, &d
->where
))
14647 /* At this point, we better not have any values left. */
14649 if (next_data_value ())
14650 gfc_error ("DATA statement at %L has more values than variables",
14655 /* 12.6 Constraint: In a pure subprogram any variable which is in common or
14656 accessed by host or use association, is a dummy argument to a pure function,
14657 is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
14658 is storage associated with any such variable, shall not be used in the
14659 following contexts: (clients of this function). */
14661 /* Determines if a variable is not 'pure', i.e., not assignable within a pure
14662 procedure. Returns zero if assignment is OK, nonzero if there is a
14665 gfc_impure_variable (gfc_symbol
*sym
)
14670 if (sym
->attr
.use_assoc
|| sym
->attr
.in_common
)
14673 /* Check if the symbol's ns is inside the pure procedure. */
14674 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14678 if (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
14682 proc
= sym
->ns
->proc_name
;
14683 if (sym
->attr
.dummy
14684 && ((proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_IN
)
14685 || proc
->attr
.function
))
14688 /* TODO: Sort out what can be storage associated, if anything, and include
14689 it here. In principle equivalences should be scanned but it does not
14690 seem to be possible to storage associate an impure variable this way. */
14695 /* Test whether a symbol is pure or not. For a NULL pointer, checks if the
14696 current namespace is inside a pure procedure. */
14699 gfc_pure (gfc_symbol
*sym
)
14701 symbol_attribute attr
;
14706 /* Check if the current namespace or one of its parents
14707 belongs to a pure procedure. */
14708 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14710 sym
= ns
->proc_name
;
14714 if (attr
.flavor
== FL_PROCEDURE
&& attr
.pure
)
14722 return attr
.flavor
== FL_PROCEDURE
&& attr
.pure
;
14726 /* Test whether a symbol is implicitly pure or not. For a NULL pointer,
14727 checks if the current namespace is implicitly pure. Note that this
14728 function returns false for a PURE procedure. */
14731 gfc_implicit_pure (gfc_symbol
*sym
)
14737 /* Check if the current procedure is implicit_pure. Walk up
14738 the procedure list until we find a procedure. */
14739 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14741 sym
= ns
->proc_name
;
14745 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14750 return sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.implicit_pure
14751 && !sym
->attr
.pure
;
14756 gfc_unset_implicit_pure (gfc_symbol
*sym
)
14762 /* Check if the current procedure is implicit_pure. Walk up
14763 the procedure list until we find a procedure. */
14764 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14766 sym
= ns
->proc_name
;
14770 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14775 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14776 sym
->attr
.implicit_pure
= 0;
14778 sym
->attr
.pure
= 0;
14782 /* Test whether the current procedure is elemental or not. */
14785 gfc_elemental (gfc_symbol
*sym
)
14787 symbol_attribute attr
;
14790 sym
= gfc_current_ns
->proc_name
;
14795 return attr
.flavor
== FL_PROCEDURE
&& attr
.elemental
;
14799 /* Warn about unused labels. */
14802 warn_unused_fortran_label (gfc_st_label
*label
)
14807 warn_unused_fortran_label (label
->left
);
14809 if (label
->defined
== ST_LABEL_UNKNOWN
)
14812 switch (label
->referenced
)
14814 case ST_LABEL_UNKNOWN
:
14815 gfc_warning (0, "Label %d at %L defined but not used", label
->value
,
14819 case ST_LABEL_BAD_TARGET
:
14820 gfc_warning (0, "Label %d at %L defined but cannot be used",
14821 label
->value
, &label
->where
);
14828 warn_unused_fortran_label (label
->right
);
14832 /* Returns the sequence type of a symbol or sequence. */
14835 sequence_type (gfc_typespec ts
)
14844 if (ts
.u
.derived
->components
== NULL
)
14845 return SEQ_NONDEFAULT
;
14847 result
= sequence_type (ts
.u
.derived
->components
->ts
);
14848 for (c
= ts
.u
.derived
->components
->next
; c
; c
= c
->next
)
14849 if (sequence_type (c
->ts
) != result
)
14855 if (ts
.kind
!= gfc_default_character_kind
)
14856 return SEQ_NONDEFAULT
;
14858 return SEQ_CHARACTER
;
14861 if (ts
.kind
!= gfc_default_integer_kind
)
14862 return SEQ_NONDEFAULT
;
14864 return SEQ_NUMERIC
;
14867 if (!(ts
.kind
== gfc_default_real_kind
14868 || ts
.kind
== gfc_default_double_kind
))
14869 return SEQ_NONDEFAULT
;
14871 return SEQ_NUMERIC
;
14874 if (ts
.kind
!= gfc_default_complex_kind
)
14875 return SEQ_NONDEFAULT
;
14877 return SEQ_NUMERIC
;
14880 if (ts
.kind
!= gfc_default_logical_kind
)
14881 return SEQ_NONDEFAULT
;
14883 return SEQ_NUMERIC
;
14886 return SEQ_NONDEFAULT
;
14891 /* Resolve derived type EQUIVALENCE object. */
14894 resolve_equivalence_derived (gfc_symbol
*derived
, gfc_symbol
*sym
, gfc_expr
*e
)
14896 gfc_component
*c
= derived
->components
;
14901 /* Shall not be an object of nonsequence derived type. */
14902 if (!derived
->attr
.sequence
)
14904 gfc_error ("Derived type variable %qs at %L must have SEQUENCE "
14905 "attribute to be an EQUIVALENCE object", sym
->name
,
14910 /* Shall not have allocatable components. */
14911 if (derived
->attr
.alloc_comp
)
14913 gfc_error ("Derived type variable %qs at %L cannot have ALLOCATABLE "
14914 "components to be an EQUIVALENCE object",sym
->name
,
14919 if (sym
->attr
.in_common
&& gfc_has_default_initializer (sym
->ts
.u
.derived
))
14921 gfc_error ("Derived type variable %qs at %L with default "
14922 "initialization cannot be in EQUIVALENCE with a variable "
14923 "in COMMON", sym
->name
, &e
->where
);
14927 for (; c
; c
= c
->next
)
14929 if (c
->ts
.type
== BT_DERIVED
14930 && (!resolve_equivalence_derived(c
->ts
.u
.derived
, sym
, e
)))
14933 /* Shall not be an object of sequence derived type containing a pointer
14934 in the structure. */
14935 if (c
->attr
.pointer
)
14937 gfc_error ("Derived type variable %qs at %L with pointer "
14938 "component(s) cannot be an EQUIVALENCE object",
14939 sym
->name
, &e
->where
);
14947 /* Resolve equivalence object.
14948 An EQUIVALENCE object shall not be a dummy argument, a pointer, a target,
14949 an allocatable array, an object of nonsequence derived type, an object of
14950 sequence derived type containing a pointer at any level of component
14951 selection, an automatic object, a function name, an entry name, a result
14952 name, a named constant, a structure component, or a subobject of any of
14953 the preceding objects. A substring shall not have length zero. A
14954 derived type shall not have components with default initialization nor
14955 shall two objects of an equivalence group be initialized.
14956 Either all or none of the objects shall have an protected attribute.
14957 The simple constraints are done in symbol.c(check_conflict) and the rest
14958 are implemented here. */
14961 resolve_equivalence (gfc_equiv
*eq
)
14964 gfc_symbol
*first_sym
;
14967 locus
*last_where
= NULL
;
14968 seq_type eq_type
, last_eq_type
;
14969 gfc_typespec
*last_ts
;
14970 int object
, cnt_protected
;
14973 last_ts
= &eq
->expr
->symtree
->n
.sym
->ts
;
14975 first_sym
= eq
->expr
->symtree
->n
.sym
;
14979 for (object
= 1; eq
; eq
= eq
->eq
, object
++)
14983 e
->ts
= e
->symtree
->n
.sym
->ts
;
14984 /* match_varspec might not know yet if it is seeing
14985 array reference or substring reference, as it doesn't
14987 if (e
->ref
&& e
->ref
->type
== REF_ARRAY
)
14989 gfc_ref
*ref
= e
->ref
;
14990 sym
= e
->symtree
->n
.sym
;
14992 if (sym
->attr
.dimension
)
14994 ref
->u
.ar
.as
= sym
->as
;
14998 /* For substrings, convert REF_ARRAY into REF_SUBSTRING. */
14999 if (e
->ts
.type
== BT_CHARACTER
15001 && ref
->type
== REF_ARRAY
15002 && ref
->u
.ar
.dimen
== 1
15003 && ref
->u
.ar
.dimen_type
[0] == DIMEN_RANGE
15004 && ref
->u
.ar
.stride
[0] == NULL
)
15006 gfc_expr
*start
= ref
->u
.ar
.start
[0];
15007 gfc_expr
*end
= ref
->u
.ar
.end
[0];
15010 /* Optimize away the (:) reference. */
15011 if (start
== NULL
&& end
== NULL
)
15014 e
->ref
= ref
->next
;
15016 e
->ref
->next
= ref
->next
;
15021 ref
->type
= REF_SUBSTRING
;
15023 start
= gfc_get_int_expr (gfc_default_integer_kind
,
15025 ref
->u
.ss
.start
= start
;
15026 if (end
== NULL
&& e
->ts
.u
.cl
)
15027 end
= gfc_copy_expr (e
->ts
.u
.cl
->length
);
15028 ref
->u
.ss
.end
= end
;
15029 ref
->u
.ss
.length
= e
->ts
.u
.cl
;
15036 /* Any further ref is an error. */
15039 gcc_assert (ref
->type
== REF_ARRAY
);
15040 gfc_error ("Syntax error in EQUIVALENCE statement at %L",
15046 if (!gfc_resolve_expr (e
))
15049 sym
= e
->symtree
->n
.sym
;
15051 if (sym
->attr
.is_protected
)
15053 if (cnt_protected
> 0 && cnt_protected
!= object
)
15055 gfc_error ("Either all or none of the objects in the "
15056 "EQUIVALENCE set at %L shall have the "
15057 "PROTECTED attribute",
15062 /* Shall not equivalence common block variables in a PURE procedure. */
15063 if (sym
->ns
->proc_name
15064 && sym
->ns
->proc_name
->attr
.pure
15065 && sym
->attr
.in_common
)
15067 gfc_error ("Common block member %qs at %L cannot be an EQUIVALENCE "
15068 "object in the pure procedure %qs",
15069 sym
->name
, &e
->where
, sym
->ns
->proc_name
->name
);
15073 /* Shall not be a named constant. */
15074 if (e
->expr_type
== EXPR_CONSTANT
)
15076 gfc_error ("Named constant %qs at %L cannot be an EQUIVALENCE "
15077 "object", sym
->name
, &e
->where
);
15081 if (e
->ts
.type
== BT_DERIVED
15082 && !resolve_equivalence_derived (e
->ts
.u
.derived
, sym
, e
))
15085 /* Check that the types correspond correctly:
15087 A numeric sequence structure may be equivalenced to another sequence
15088 structure, an object of default integer type, default real type, double
15089 precision real type, default logical type such that components of the
15090 structure ultimately only become associated to objects of the same
15091 kind. A character sequence structure may be equivalenced to an object
15092 of default character kind or another character sequence structure.
15093 Other objects may be equivalenced only to objects of the same type and
15094 kind parameters. */
15096 /* Identical types are unconditionally OK. */
15097 if (object
== 1 || gfc_compare_types (last_ts
, &sym
->ts
))
15098 goto identical_types
;
15100 last_eq_type
= sequence_type (*last_ts
);
15101 eq_type
= sequence_type (sym
->ts
);
15103 /* Since the pair of objects is not of the same type, mixed or
15104 non-default sequences can be rejected. */
15106 msg
= "Sequence %s with mixed components in EQUIVALENCE "
15107 "statement at %L with different type objects";
15109 && last_eq_type
== SEQ_MIXED
15110 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
15111 || (eq_type
== SEQ_MIXED
15112 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
15115 msg
= "Non-default type object or sequence %s in EQUIVALENCE "
15116 "statement at %L with objects of different type";
15118 && last_eq_type
== SEQ_NONDEFAULT
15119 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
15120 || (eq_type
== SEQ_NONDEFAULT
15121 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
15124 msg
="Non-CHARACTER object %qs in default CHARACTER "
15125 "EQUIVALENCE statement at %L";
15126 if (last_eq_type
== SEQ_CHARACTER
15127 && eq_type
!= SEQ_CHARACTER
15128 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
15131 msg
="Non-NUMERIC object %qs in default NUMERIC "
15132 "EQUIVALENCE statement at %L";
15133 if (last_eq_type
== SEQ_NUMERIC
15134 && eq_type
!= SEQ_NUMERIC
15135 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
15140 last_where
= &e
->where
;
15145 /* Shall not be an automatic array. */
15146 if (e
->ref
->type
== REF_ARRAY
15147 && !gfc_resolve_array_spec (e
->ref
->u
.ar
.as
, 1))
15149 gfc_error ("Array %qs at %L with non-constant bounds cannot be "
15150 "an EQUIVALENCE object", sym
->name
, &e
->where
);
15157 /* Shall not be a structure component. */
15158 if (r
->type
== REF_COMPONENT
)
15160 gfc_error ("Structure component %qs at %L cannot be an "
15161 "EQUIVALENCE object",
15162 r
->u
.c
.component
->name
, &e
->where
);
15166 /* A substring shall not have length zero. */
15167 if (r
->type
== REF_SUBSTRING
)
15169 if (compare_bound (r
->u
.ss
.start
, r
->u
.ss
.end
) == CMP_GT
)
15171 gfc_error ("Substring at %L has length zero",
15172 &r
->u
.ss
.start
->where
);
15182 /* Resolve function and ENTRY types, issue diagnostics if needed. */
15185 resolve_fntype (gfc_namespace
*ns
)
15187 gfc_entry_list
*el
;
15190 if (ns
->proc_name
== NULL
|| !ns
->proc_name
->attr
.function
)
15193 /* If there are any entries, ns->proc_name is the entry master
15194 synthetic symbol and ns->entries->sym actual FUNCTION symbol. */
15196 sym
= ns
->entries
->sym
;
15198 sym
= ns
->proc_name
;
15199 if (sym
->result
== sym
15200 && sym
->ts
.type
== BT_UNKNOWN
15201 && !gfc_set_default_type (sym
, 0, NULL
)
15202 && !sym
->attr
.untyped
)
15204 gfc_error ("Function %qs at %L has no IMPLICIT type",
15205 sym
->name
, &sym
->declared_at
);
15206 sym
->attr
.untyped
= 1;
15209 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->ts
.u
.derived
->attr
.use_assoc
15210 && !sym
->attr
.contained
15211 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
15212 && gfc_check_symbol_access (sym
))
15214 gfc_notify_std (GFC_STD_F2003
, "PUBLIC function %qs at "
15215 "%L of PRIVATE type %qs", sym
->name
,
15216 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
15220 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
15222 if (el
->sym
->result
== el
->sym
15223 && el
->sym
->ts
.type
== BT_UNKNOWN
15224 && !gfc_set_default_type (el
->sym
, 0, NULL
)
15225 && !el
->sym
->attr
.untyped
)
15227 gfc_error ("ENTRY %qs at %L has no IMPLICIT type",
15228 el
->sym
->name
, &el
->sym
->declared_at
);
15229 el
->sym
->attr
.untyped
= 1;
15235 /* 12.3.2.1.1 Defined operators. */
15238 check_uop_procedure (gfc_symbol
*sym
, locus where
)
15240 gfc_formal_arglist
*formal
;
15242 if (!sym
->attr
.function
)
15244 gfc_error ("User operator procedure %qs at %L must be a FUNCTION",
15245 sym
->name
, &where
);
15249 if (sym
->ts
.type
== BT_CHARACTER
15250 && !(sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
)
15251 && !(sym
->result
&& sym
->result
->ts
.u
.cl
15252 && sym
->result
->ts
.u
.cl
->length
))
15254 gfc_error ("User operator procedure %qs at %L cannot be assumed "
15255 "character length", sym
->name
, &where
);
15259 formal
= gfc_sym_get_dummy_args (sym
);
15260 if (!formal
|| !formal
->sym
)
15262 gfc_error ("User operator procedure %qs at %L must have at least "
15263 "one argument", sym
->name
, &where
);
15267 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
15269 gfc_error ("First argument of operator interface at %L must be "
15270 "INTENT(IN)", &where
);
15274 if (formal
->sym
->attr
.optional
)
15276 gfc_error ("First argument of operator interface at %L cannot be "
15277 "optional", &where
);
15281 formal
= formal
->next
;
15282 if (!formal
|| !formal
->sym
)
15285 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
15287 gfc_error ("Second argument of operator interface at %L must be "
15288 "INTENT(IN)", &where
);
15292 if (formal
->sym
->attr
.optional
)
15294 gfc_error ("Second argument of operator interface at %L cannot be "
15295 "optional", &where
);
15301 gfc_error ("Operator interface at %L must have, at most, two "
15302 "arguments", &where
);
15310 gfc_resolve_uops (gfc_symtree
*symtree
)
15312 gfc_interface
*itr
;
15314 if (symtree
== NULL
)
15317 gfc_resolve_uops (symtree
->left
);
15318 gfc_resolve_uops (symtree
->right
);
15320 for (itr
= symtree
->n
.uop
->op
; itr
; itr
= itr
->next
)
15321 check_uop_procedure (itr
->sym
, itr
->sym
->declared_at
);
15325 /* Examine all of the expressions associated with a program unit,
15326 assign types to all intermediate expressions, make sure that all
15327 assignments are to compatible types and figure out which names
15328 refer to which functions or subroutines. It doesn't check code
15329 block, which is handled by gfc_resolve_code. */
15332 resolve_types (gfc_namespace
*ns
)
15338 gfc_namespace
* old_ns
= gfc_current_ns
;
15340 if (ns
->types_resolved
)
15343 /* Check that all IMPLICIT types are ok. */
15344 if (!ns
->seen_implicit_none
)
15347 for (letter
= 0; letter
!= GFC_LETTERS
; ++letter
)
15348 if (ns
->set_flag
[letter
]
15349 && !resolve_typespec_used (&ns
->default_type
[letter
],
15350 &ns
->implicit_loc
[letter
], NULL
))
15354 gfc_current_ns
= ns
;
15356 resolve_entries (ns
);
15358 resolve_common_vars (&ns
->blank_common
, false);
15359 resolve_common_blocks (ns
->common_root
);
15361 resolve_contained_functions (ns
);
15363 if (ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
15364 && ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
15365 resolve_formal_arglist (ns
->proc_name
);
15367 gfc_traverse_ns (ns
, resolve_bind_c_derived_types
);
15369 for (cl
= ns
->cl_list
; cl
; cl
= cl
->next
)
15370 resolve_charlen (cl
);
15372 gfc_traverse_ns (ns
, resolve_symbol
);
15374 resolve_fntype (ns
);
15376 for (n
= ns
->contained
; n
; n
= n
->sibling
)
15378 if (gfc_pure (ns
->proc_name
) && !gfc_pure (n
->proc_name
))
15379 gfc_error ("Contained procedure %qs at %L of a PURE procedure must "
15380 "also be PURE", n
->proc_name
->name
,
15381 &n
->proc_name
->declared_at
);
15387 gfc_do_concurrent_flag
= 0;
15388 gfc_check_interfaces (ns
);
15390 gfc_traverse_ns (ns
, resolve_values
);
15396 for (d
= ns
->data
; d
; d
= d
->next
)
15400 gfc_traverse_ns (ns
, gfc_formalize_init_value
);
15402 gfc_traverse_ns (ns
, gfc_verify_binding_labels
);
15404 for (eq
= ns
->equiv
; eq
; eq
= eq
->next
)
15405 resolve_equivalence (eq
);
15407 /* Warn about unused labels. */
15408 if (warn_unused_label
)
15409 warn_unused_fortran_label (ns
->st_labels
);
15411 gfc_resolve_uops (ns
->uop_root
);
15413 gfc_resolve_omp_declare_simd (ns
);
15415 gfc_resolve_omp_udrs (ns
->omp_udr_root
);
15417 ns
->types_resolved
= 1;
15419 gfc_current_ns
= old_ns
;
15423 /* Call gfc_resolve_code recursively. */
15426 resolve_codes (gfc_namespace
*ns
)
15429 bitmap_obstack old_obstack
;
15431 if (ns
->resolved
== 1)
15434 for (n
= ns
->contained
; n
; n
= n
->sibling
)
15437 gfc_current_ns
= ns
;
15439 /* Don't clear 'cs_base' if this is the namespace of a BLOCK construct. */
15440 if (!(ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_LABEL
))
15443 /* Set to an out of range value. */
15444 current_entry_id
= -1;
15446 old_obstack
= labels_obstack
;
15447 bitmap_obstack_initialize (&labels_obstack
);
15449 gfc_resolve_oacc_declare (ns
);
15450 gfc_resolve_code (ns
->code
, ns
);
15452 bitmap_obstack_release (&labels_obstack
);
15453 labels_obstack
= old_obstack
;
15457 /* This function is called after a complete program unit has been compiled.
15458 Its purpose is to examine all of the expressions associated with a program
15459 unit, assign types to all intermediate expressions, make sure that all
15460 assignments are to compatible types and figure out which names refer to
15461 which functions or subroutines. */
15464 gfc_resolve (gfc_namespace
*ns
)
15466 gfc_namespace
*old_ns
;
15467 code_stack
*old_cs_base
;
15468 struct gfc_omp_saved_state old_omp_state
;
15474 old_ns
= gfc_current_ns
;
15475 old_cs_base
= cs_base
;
15477 /* As gfc_resolve can be called during resolution of an OpenMP construct
15478 body, we should clear any state associated to it, so that say NS's
15479 DO loops are not interpreted as OpenMP loops. */
15480 gfc_omp_save_and_clear_state (&old_omp_state
);
15482 resolve_types (ns
);
15483 component_assignment_level
= 0;
15484 resolve_codes (ns
);
15486 gfc_current_ns
= old_ns
;
15487 cs_base
= old_cs_base
;
15490 gfc_run_passes (ns
);
15492 gfc_omp_restore_state (&old_omp_state
);