1 /* Perform type resolution on the various structures.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
28 #include "arith.h" /* For gfc_compare_expr(). */
29 #include "dependency.h"
31 #include "target-memory.h" /* for gfc_simplify_transfer */
32 #include "constructor.h"
34 /* Types used in equivalence statements. */
38 SEQ_NONDEFAULT
, SEQ_NUMERIC
, SEQ_CHARACTER
, SEQ_MIXED
42 /* Stack to keep track of the nesting of blocks as we move through the
43 code. See resolve_branch() and resolve_code(). */
45 typedef struct code_stack
47 struct gfc_code
*head
, *current
;
48 struct code_stack
*prev
;
50 /* This bitmap keeps track of the targets valid for a branch from
51 inside this block except for END {IF|SELECT}s of enclosing
53 bitmap reachable_labels
;
57 static code_stack
*cs_base
= NULL
;
60 /* Nonzero if we're inside a FORALL block. */
62 static int forall_flag
;
64 /* Nonzero if we're inside a OpenMP WORKSHARE or PARALLEL WORKSHARE block. */
66 static int omp_workshare_flag
;
68 /* Nonzero if we are processing a formal arglist. The corresponding function
69 resets the flag each time that it is read. */
70 static int formal_arg_flag
= 0;
72 /* True if we are resolving a specification expression. */
73 static int specification_expr
= 0;
75 /* The id of the last entry seen. */
76 static int current_entry_id
;
78 /* We use bitmaps to determine if a branch target is valid. */
79 static bitmap_obstack labels_obstack
;
81 /* True when simplifying a EXPR_VARIABLE argument to an inquiry function. */
82 static bool inquiry_argument
= false;
85 gfc_is_formal_arg (void)
87 return formal_arg_flag
;
90 /* Is the symbol host associated? */
92 is_sym_host_assoc (gfc_symbol
*sym
, gfc_namespace
*ns
)
94 for (ns
= ns
->parent
; ns
; ns
= ns
->parent
)
103 /* Ensure a typespec used is valid; for instance, TYPE(t) is invalid if t is
104 an ABSTRACT derived-type. If where is not NULL, an error message with that
105 locus is printed, optionally using name. */
108 resolve_typespec_used (gfc_typespec
* ts
, locus
* where
, const char* name
)
110 if (ts
->type
== BT_DERIVED
&& ts
->u
.derived
->attr
.abstract
)
115 gfc_error ("'%s' at %L is of the ABSTRACT type '%s'",
116 name
, where
, ts
->u
.derived
->name
);
118 gfc_error ("ABSTRACT type '%s' used at %L",
119 ts
->u
.derived
->name
, where
);
129 /* Resolve types of formal argument lists. These have to be done early so that
130 the formal argument lists of module procedures can be copied to the
131 containing module before the individual procedures are resolved
132 individually. We also resolve argument lists of procedures in interface
133 blocks because they are self-contained scoping units.
135 Since a dummy argument cannot be a non-dummy procedure, the only
136 resort left for untyped names are the IMPLICIT types. */
139 resolve_formal_arglist (gfc_symbol
*proc
)
141 gfc_formal_arglist
*f
;
145 if (proc
->result
!= NULL
)
150 if (gfc_elemental (proc
)
151 || sym
->attr
.pointer
|| sym
->attr
.allocatable
152 || (sym
->as
&& sym
->as
->rank
> 0))
154 proc
->attr
.always_explicit
= 1;
155 sym
->attr
.always_explicit
= 1;
160 for (f
= proc
->formal
; f
; f
= f
->next
)
166 /* Alternate return placeholder. */
167 if (gfc_elemental (proc
))
168 gfc_error ("Alternate return specifier in elemental subroutine "
169 "'%s' at %L is not allowed", proc
->name
,
171 if (proc
->attr
.function
)
172 gfc_error ("Alternate return specifier in function "
173 "'%s' at %L is not allowed", proc
->name
,
178 if (sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
179 resolve_formal_arglist (sym
);
181 if (sym
->attr
.subroutine
|| sym
->attr
.external
|| sym
->attr
.intrinsic
)
183 if (gfc_pure (proc
) && !gfc_pure (sym
))
185 gfc_error ("Dummy procedure '%s' of PURE procedure at %L must "
186 "also be PURE", sym
->name
, &sym
->declared_at
);
190 if (gfc_elemental (proc
))
192 gfc_error ("Dummy procedure at %L not allowed in ELEMENTAL "
193 "procedure", &sym
->declared_at
);
197 if (sym
->attr
.function
198 && sym
->ts
.type
== BT_UNKNOWN
199 && sym
->attr
.intrinsic
)
201 gfc_intrinsic_sym
*isym
;
202 isym
= gfc_find_function (sym
->name
);
203 if (isym
== NULL
|| !isym
->specific
)
205 gfc_error ("Unable to find a specific INTRINSIC procedure "
206 "for the reference '%s' at %L", sym
->name
,
215 if (sym
->ts
.type
== BT_UNKNOWN
)
217 if (!sym
->attr
.function
|| sym
->result
== sym
)
218 gfc_set_default_type (sym
, 1, sym
->ns
);
221 gfc_resolve_array_spec (sym
->as
, 0);
223 /* We can't tell if an array with dimension (:) is assumed or deferred
224 shape until we know if it has the pointer or allocatable attributes.
226 if (sym
->as
&& sym
->as
->rank
> 0 && sym
->as
->type
== AS_DEFERRED
227 && !(sym
->attr
.pointer
|| sym
->attr
.allocatable
))
229 sym
->as
->type
= AS_ASSUMED_SHAPE
;
230 for (i
= 0; i
< sym
->as
->rank
; i
++)
231 sym
->as
->lower
[i
] = gfc_get_int_expr (gfc_default_integer_kind
,
235 if ((sym
->as
&& sym
->as
->rank
> 0 && sym
->as
->type
== AS_ASSUMED_SHAPE
)
236 || sym
->attr
.pointer
|| sym
->attr
.allocatable
|| sym
->attr
.target
237 || sym
->attr
.optional
)
239 proc
->attr
.always_explicit
= 1;
241 proc
->result
->attr
.always_explicit
= 1;
244 /* If the flavor is unknown at this point, it has to be a variable.
245 A procedure specification would have already set the type. */
247 if (sym
->attr
.flavor
== FL_UNKNOWN
)
248 gfc_add_flavor (&sym
->attr
, FL_VARIABLE
, sym
->name
, &sym
->declared_at
);
250 if (gfc_pure (proc
) && !sym
->attr
.pointer
251 && sym
->attr
.flavor
!= FL_PROCEDURE
)
253 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
)
254 gfc_error ("Argument '%s' of pure function '%s' at %L must be "
255 "INTENT(IN)", sym
->name
, proc
->name
,
258 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
)
259 gfc_error ("Argument '%s' of pure subroutine '%s' at %L must "
260 "have its INTENT specified", sym
->name
, proc
->name
,
264 if (gfc_elemental (proc
))
267 if (sym
->attr
.codimension
)
269 gfc_error ("Coarray dummy argument '%s' at %L to elemental "
270 "procedure", sym
->name
, &sym
->declared_at
);
276 gfc_error ("Argument '%s' of elemental procedure at %L must "
277 "be scalar", sym
->name
, &sym
->declared_at
);
281 if (sym
->attr
.pointer
)
283 gfc_error ("Argument '%s' of elemental procedure at %L cannot "
284 "have the POINTER attribute", sym
->name
,
289 if (sym
->attr
.flavor
== FL_PROCEDURE
)
291 gfc_error ("Dummy procedure '%s' not allowed in elemental "
292 "procedure '%s' at %L", sym
->name
, proc
->name
,
298 /* Each dummy shall be specified to be scalar. */
299 if (proc
->attr
.proc
== PROC_ST_FUNCTION
)
303 gfc_error ("Argument '%s' of statement function at %L must "
304 "be scalar", sym
->name
, &sym
->declared_at
);
308 if (sym
->ts
.type
== BT_CHARACTER
)
310 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
311 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
313 gfc_error ("Character-valued argument '%s' of statement "
314 "function at %L must have constant length",
315 sym
->name
, &sym
->declared_at
);
325 /* Work function called when searching for symbols that have argument lists
326 associated with them. */
329 find_arglists (gfc_symbol
*sym
)
331 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
|| sym
->ns
!= gfc_current_ns
)
334 resolve_formal_arglist (sym
);
338 /* Given a namespace, resolve all formal argument lists within the namespace.
342 resolve_formal_arglists (gfc_namespace
*ns
)
347 gfc_traverse_ns (ns
, find_arglists
);
352 resolve_contained_fntype (gfc_symbol
*sym
, gfc_namespace
*ns
)
356 /* If this namespace is not a function or an entry master function,
358 if (! sym
|| !(sym
->attr
.function
|| sym
->attr
.flavor
== FL_VARIABLE
)
359 || sym
->attr
.entry_master
)
362 /* Try to find out of what the return type is. */
363 if (sym
->result
->ts
.type
== BT_UNKNOWN
&& sym
->result
->ts
.interface
== NULL
)
365 t
= gfc_set_default_type (sym
->result
, 0, ns
);
367 if (t
== FAILURE
&& !sym
->result
->attr
.untyped
)
369 if (sym
->result
== sym
)
370 gfc_error ("Contained function '%s' at %L has no IMPLICIT type",
371 sym
->name
, &sym
->declared_at
);
372 else if (!sym
->result
->attr
.proc_pointer
)
373 gfc_error ("Result '%s' of contained function '%s' at %L has "
374 "no IMPLICIT type", sym
->result
->name
, sym
->name
,
375 &sym
->result
->declared_at
);
376 sym
->result
->attr
.untyped
= 1;
380 /* Fortran 95 Draft Standard, page 51, Section 5.1.1.5, on the Character
381 type, lists the only ways a character length value of * can be used:
382 dummy arguments of procedures, named constants, and function results
383 in external functions. Internal function results and results of module
384 procedures are not on this list, ergo, not permitted. */
386 if (sym
->result
->ts
.type
== BT_CHARACTER
)
388 gfc_charlen
*cl
= sym
->result
->ts
.u
.cl
;
389 if (!cl
|| !cl
->length
)
391 /* See if this is a module-procedure and adapt error message
394 gcc_assert (ns
->parent
&& ns
->parent
->proc_name
);
395 module_proc
= (ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
);
397 gfc_error ("Character-valued %s '%s' at %L must not be"
399 module_proc
? _("module procedure")
400 : _("internal function"),
401 sym
->name
, &sym
->declared_at
);
407 /* Add NEW_ARGS to the formal argument list of PROC, taking care not to
408 introduce duplicates. */
411 merge_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
413 gfc_formal_arglist
*f
, *new_arglist
;
416 for (; new_args
!= NULL
; new_args
= new_args
->next
)
418 new_sym
= new_args
->sym
;
419 /* See if this arg is already in the formal argument list. */
420 for (f
= proc
->formal
; f
; f
= f
->next
)
422 if (new_sym
== f
->sym
)
429 /* Add a new argument. Argument order is not important. */
430 new_arglist
= gfc_get_formal_arglist ();
431 new_arglist
->sym
= new_sym
;
432 new_arglist
->next
= proc
->formal
;
433 proc
->formal
= new_arglist
;
438 /* Flag the arguments that are not present in all entries. */
441 check_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
443 gfc_formal_arglist
*f
, *head
;
446 for (f
= proc
->formal
; f
; f
= f
->next
)
451 for (new_args
= head
; new_args
; new_args
= new_args
->next
)
453 if (new_args
->sym
== f
->sym
)
460 f
->sym
->attr
.not_always_present
= 1;
465 /* Resolve alternate entry points. If a symbol has multiple entry points we
466 create a new master symbol for the main routine, and turn the existing
467 symbol into an entry point. */
470 resolve_entries (gfc_namespace
*ns
)
472 gfc_namespace
*old_ns
;
476 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
477 static int master_count
= 0;
479 if (ns
->proc_name
== NULL
)
482 /* No need to do anything if this procedure doesn't have alternate entry
487 /* We may already have resolved alternate entry points. */
488 if (ns
->proc_name
->attr
.entry_master
)
491 /* If this isn't a procedure something has gone horribly wrong. */
492 gcc_assert (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
);
494 /* Remember the current namespace. */
495 old_ns
= gfc_current_ns
;
499 /* Add the main entry point to the list of entry points. */
500 el
= gfc_get_entry_list ();
501 el
->sym
= ns
->proc_name
;
503 el
->next
= ns
->entries
;
505 ns
->proc_name
->attr
.entry
= 1;
507 /* If it is a module function, it needs to be in the right namespace
508 so that gfc_get_fake_result_decl can gather up the results. The
509 need for this arose in get_proc_name, where these beasts were
510 left in their own namespace, to keep prior references linked to
511 the entry declaration.*/
512 if (ns
->proc_name
->attr
.function
513 && ns
->parent
&& ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
516 /* Do the same for entries where the master is not a module
517 procedure. These are retained in the module namespace because
518 of the module procedure declaration. */
519 for (el
= el
->next
; el
; el
= el
->next
)
520 if (el
->sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
521 && el
->sym
->attr
.mod_proc
)
525 /* Add an entry statement for it. */
532 /* Create a new symbol for the master function. */
533 /* Give the internal function a unique name (within this file).
534 Also include the function name so the user has some hope of figuring
535 out what is going on. */
536 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "master.%d.%s",
537 master_count
++, ns
->proc_name
->name
);
538 gfc_get_ha_symbol (name
, &proc
);
539 gcc_assert (proc
!= NULL
);
541 gfc_add_procedure (&proc
->attr
, PROC_INTERNAL
, proc
->name
, NULL
);
542 if (ns
->proc_name
->attr
.subroutine
)
543 gfc_add_subroutine (&proc
->attr
, proc
->name
, NULL
);
547 gfc_typespec
*ts
, *fts
;
548 gfc_array_spec
*as
, *fas
;
549 gfc_add_function (&proc
->attr
, proc
->name
, NULL
);
551 fas
= ns
->entries
->sym
->as
;
552 fas
= fas
? fas
: ns
->entries
->sym
->result
->as
;
553 fts
= &ns
->entries
->sym
->result
->ts
;
554 if (fts
->type
== BT_UNKNOWN
)
555 fts
= gfc_get_default_type (ns
->entries
->sym
->result
->name
, NULL
);
556 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
558 ts
= &el
->sym
->result
->ts
;
560 as
= as
? as
: el
->sym
->result
->as
;
561 if (ts
->type
== BT_UNKNOWN
)
562 ts
= gfc_get_default_type (el
->sym
->result
->name
, NULL
);
564 if (! gfc_compare_types (ts
, fts
)
565 || (el
->sym
->result
->attr
.dimension
566 != ns
->entries
->sym
->result
->attr
.dimension
)
567 || (el
->sym
->result
->attr
.pointer
568 != ns
->entries
->sym
->result
->attr
.pointer
))
570 else if (as
&& fas
&& ns
->entries
->sym
->result
!= el
->sym
->result
571 && gfc_compare_array_spec (as
, fas
) == 0)
572 gfc_error ("Function %s at %L has entries with mismatched "
573 "array specifications", ns
->entries
->sym
->name
,
574 &ns
->entries
->sym
->declared_at
);
575 /* The characteristics need to match and thus both need to have
576 the same string length, i.e. both len=*, or both len=4.
577 Having both len=<variable> is also possible, but difficult to
578 check at compile time. */
579 else if (ts
->type
== BT_CHARACTER
&& ts
->u
.cl
&& fts
->u
.cl
580 && (((ts
->u
.cl
->length
&& !fts
->u
.cl
->length
)
581 ||(!ts
->u
.cl
->length
&& fts
->u
.cl
->length
))
583 && ts
->u
.cl
->length
->expr_type
584 != fts
->u
.cl
->length
->expr_type
)
586 && ts
->u
.cl
->length
->expr_type
== EXPR_CONSTANT
587 && mpz_cmp (ts
->u
.cl
->length
->value
.integer
,
588 fts
->u
.cl
->length
->value
.integer
) != 0)))
589 gfc_notify_std (GFC_STD_GNU
, "Extension: Function %s at %L with "
590 "entries returning variables of different "
591 "string lengths", ns
->entries
->sym
->name
,
592 &ns
->entries
->sym
->declared_at
);
597 sym
= ns
->entries
->sym
->result
;
598 /* All result types the same. */
600 if (sym
->attr
.dimension
)
601 gfc_set_array_spec (proc
, gfc_copy_array_spec (sym
->as
), NULL
);
602 if (sym
->attr
.pointer
)
603 gfc_add_pointer (&proc
->attr
, NULL
);
607 /* Otherwise the result will be passed through a union by
609 proc
->attr
.mixed_entry_master
= 1;
610 for (el
= ns
->entries
; el
; el
= el
->next
)
612 sym
= el
->sym
->result
;
613 if (sym
->attr
.dimension
)
615 if (el
== ns
->entries
)
616 gfc_error ("FUNCTION result %s can't be an array in "
617 "FUNCTION %s at %L", sym
->name
,
618 ns
->entries
->sym
->name
, &sym
->declared_at
);
620 gfc_error ("ENTRY result %s can't be an array in "
621 "FUNCTION %s at %L", sym
->name
,
622 ns
->entries
->sym
->name
, &sym
->declared_at
);
624 else if (sym
->attr
.pointer
)
626 if (el
== ns
->entries
)
627 gfc_error ("FUNCTION result %s can't be a POINTER in "
628 "FUNCTION %s at %L", sym
->name
,
629 ns
->entries
->sym
->name
, &sym
->declared_at
);
631 gfc_error ("ENTRY result %s can't be a POINTER in "
632 "FUNCTION %s at %L", sym
->name
,
633 ns
->entries
->sym
->name
, &sym
->declared_at
);
638 if (ts
->type
== BT_UNKNOWN
)
639 ts
= gfc_get_default_type (sym
->name
, NULL
);
643 if (ts
->kind
== gfc_default_integer_kind
)
647 if (ts
->kind
== gfc_default_real_kind
648 || ts
->kind
== gfc_default_double_kind
)
652 if (ts
->kind
== gfc_default_complex_kind
)
656 if (ts
->kind
== gfc_default_logical_kind
)
660 /* We will issue error elsewhere. */
668 if (el
== ns
->entries
)
669 gfc_error ("FUNCTION result %s can't be of type %s "
670 "in FUNCTION %s at %L", sym
->name
,
671 gfc_typename (ts
), ns
->entries
->sym
->name
,
674 gfc_error ("ENTRY result %s can't be of type %s "
675 "in FUNCTION %s at %L", sym
->name
,
676 gfc_typename (ts
), ns
->entries
->sym
->name
,
683 proc
->attr
.access
= ACCESS_PRIVATE
;
684 proc
->attr
.entry_master
= 1;
686 /* Merge all the entry point arguments. */
687 for (el
= ns
->entries
; el
; el
= el
->next
)
688 merge_argument_lists (proc
, el
->sym
->formal
);
690 /* Check the master formal arguments for any that are not
691 present in all entry points. */
692 for (el
= ns
->entries
; el
; el
= el
->next
)
693 check_argument_lists (proc
, el
->sym
->formal
);
695 /* Use the master function for the function body. */
696 ns
->proc_name
= proc
;
698 /* Finalize the new symbols. */
699 gfc_commit_symbols ();
701 /* Restore the original namespace. */
702 gfc_current_ns
= old_ns
;
706 /* Resolve common variables. */
708 resolve_common_vars (gfc_symbol
*sym
, bool named_common
)
710 gfc_symbol
*csym
= sym
;
712 for (; csym
; csym
= csym
->common_next
)
714 if (csym
->value
|| csym
->attr
.data
)
716 if (!csym
->ns
->is_block_data
)
717 gfc_notify_std (GFC_STD_GNU
, "Variable '%s' at %L is in COMMON "
718 "but only in BLOCK DATA initialization is "
719 "allowed", csym
->name
, &csym
->declared_at
);
720 else if (!named_common
)
721 gfc_notify_std (GFC_STD_GNU
, "Initialized variable '%s' at %L is "
722 "in a blank COMMON but initialization is only "
723 "allowed in named common blocks", csym
->name
,
727 if (csym
->ts
.type
!= BT_DERIVED
)
730 if (!(csym
->ts
.u
.derived
->attr
.sequence
731 || csym
->ts
.u
.derived
->attr
.is_bind_c
))
732 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
733 "has neither the SEQUENCE nor the BIND(C) "
734 "attribute", csym
->name
, &csym
->declared_at
);
735 if (csym
->ts
.u
.derived
->attr
.alloc_comp
)
736 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
737 "has an ultimate component that is "
738 "allocatable", csym
->name
, &csym
->declared_at
);
739 if (gfc_has_default_initializer (csym
->ts
.u
.derived
))
740 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
741 "may not have default initializer", csym
->name
,
744 if (csym
->attr
.flavor
== FL_UNKNOWN
&& !csym
->attr
.proc_pointer
)
745 gfc_add_flavor (&csym
->attr
, FL_VARIABLE
, csym
->name
, &csym
->declared_at
);
749 /* Resolve common blocks. */
751 resolve_common_blocks (gfc_symtree
*common_root
)
755 if (common_root
== NULL
)
758 if (common_root
->left
)
759 resolve_common_blocks (common_root
->left
);
760 if (common_root
->right
)
761 resolve_common_blocks (common_root
->right
);
763 resolve_common_vars (common_root
->n
.common
->head
, true);
765 gfc_find_symbol (common_root
->name
, gfc_current_ns
, 0, &sym
);
769 if (sym
->attr
.flavor
== FL_PARAMETER
)
770 gfc_error ("COMMON block '%s' at %L is used as PARAMETER at %L",
771 sym
->name
, &common_root
->n
.common
->where
, &sym
->declared_at
);
773 if (sym
->attr
.intrinsic
)
774 gfc_error ("COMMON block '%s' at %L is also an intrinsic procedure",
775 sym
->name
, &common_root
->n
.common
->where
);
776 else if (sym
->attr
.result
777 || gfc_is_function_return_value (sym
, gfc_current_ns
))
778 gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: COMMON block '%s' at %L "
779 "that is also a function result", sym
->name
,
780 &common_root
->n
.common
->where
);
781 else if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.proc
!= PROC_INTERNAL
782 && sym
->attr
.proc
!= PROC_ST_FUNCTION
)
783 gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: COMMON block '%s' at %L "
784 "that is also a global procedure", sym
->name
,
785 &common_root
->n
.common
->where
);
789 /* Resolve contained function types. Because contained functions can call one
790 another, they have to be worked out before any of the contained procedures
793 The good news is that if a function doesn't already have a type, the only
794 way it can get one is through an IMPLICIT type or a RESULT variable, because
795 by definition contained functions are contained namespace they're contained
796 in, not in a sibling or parent namespace. */
799 resolve_contained_functions (gfc_namespace
*ns
)
801 gfc_namespace
*child
;
804 resolve_formal_arglists (ns
);
806 for (child
= ns
->contained
; child
; child
= child
->sibling
)
808 /* Resolve alternate entry points first. */
809 resolve_entries (child
);
811 /* Then check function return types. */
812 resolve_contained_fntype (child
->proc_name
, child
);
813 for (el
= child
->entries
; el
; el
= el
->next
)
814 resolve_contained_fntype (el
->sym
, child
);
819 /* Resolve all of the elements of a structure constructor and make sure that
820 the types are correct. */
823 resolve_structure_cons (gfc_expr
*expr
)
825 gfc_constructor
*cons
;
831 cons
= gfc_constructor_first (expr
->value
.constructor
);
832 /* A constructor may have references if it is the result of substituting a
833 parameter variable. In this case we just pull out the component we
836 comp
= expr
->ref
->u
.c
.sym
->components
;
838 comp
= expr
->ts
.u
.derived
->components
;
840 /* See if the user is trying to invoke a structure constructor for one of
841 the iso_c_binding derived types. */
842 if (expr
->ts
.type
== BT_DERIVED
&& expr
->ts
.u
.derived
843 && expr
->ts
.u
.derived
->ts
.is_iso_c
&& cons
844 && (cons
->expr
== NULL
|| cons
->expr
->expr_type
!= EXPR_NULL
))
846 gfc_error ("Components of structure constructor '%s' at %L are PRIVATE",
847 expr
->ts
.u
.derived
->name
, &(expr
->where
));
851 /* Return if structure constructor is c_null_(fun)prt. */
852 if (expr
->ts
.type
== BT_DERIVED
&& expr
->ts
.u
.derived
853 && expr
->ts
.u
.derived
->ts
.is_iso_c
&& cons
854 && cons
->expr
&& cons
->expr
->expr_type
== EXPR_NULL
)
857 for (; comp
&& cons
; comp
= comp
->next
, cons
= gfc_constructor_next (cons
))
864 if (gfc_resolve_expr (cons
->expr
) == FAILURE
)
870 rank
= comp
->as
? comp
->as
->rank
: 0;
871 if (cons
->expr
->expr_type
!= EXPR_NULL
&& rank
!= cons
->expr
->rank
872 && (comp
->attr
.allocatable
|| cons
->expr
->rank
))
874 gfc_error ("The rank of the element in the derived type "
875 "constructor at %L does not match that of the "
876 "component (%d/%d)", &cons
->expr
->where
,
877 cons
->expr
->rank
, rank
);
881 /* If we don't have the right type, try to convert it. */
883 if (!gfc_compare_types (&cons
->expr
->ts
, &comp
->ts
))
886 if (strcmp (comp
->name
, "$extends") == 0)
888 /* Can afford to be brutal with the $extends initializer.
889 The derived type can get lost because it is PRIVATE
890 but it is not usage constrained by the standard. */
891 cons
->expr
->ts
= comp
->ts
;
894 else if (comp
->attr
.pointer
&& cons
->expr
->ts
.type
!= BT_UNKNOWN
)
895 gfc_error ("The element in the derived type constructor at %L, "
896 "for pointer component '%s', is %s but should be %s",
897 &cons
->expr
->where
, comp
->name
,
898 gfc_basic_typename (cons
->expr
->ts
.type
),
899 gfc_basic_typename (comp
->ts
.type
));
901 t
= gfc_convert_type (cons
->expr
, &comp
->ts
, 1);
904 if (cons
->expr
->expr_type
== EXPR_NULL
905 && !(comp
->attr
.pointer
|| comp
->attr
.allocatable
906 || comp
->attr
.proc_pointer
907 || (comp
->ts
.type
== BT_CLASS
908 && (CLASS_DATA (comp
)->attr
.class_pointer
909 || CLASS_DATA (comp
)->attr
.allocatable
))))
912 gfc_error ("The NULL in the derived type constructor at %L is "
913 "being applied to component '%s', which is neither "
914 "a POINTER nor ALLOCATABLE", &cons
->expr
->where
,
918 if (!comp
->attr
.pointer
|| cons
->expr
->expr_type
== EXPR_NULL
)
921 a
= gfc_expr_attr (cons
->expr
);
923 if (!a
.pointer
&& !a
.target
)
926 gfc_error ("The element in the derived type constructor at %L, "
927 "for pointer component '%s' should be a POINTER or "
928 "a TARGET", &cons
->expr
->where
, comp
->name
);
931 /* F2003, C1272 (3). */
932 if (gfc_pure (NULL
) && cons
->expr
->expr_type
== EXPR_VARIABLE
933 && (gfc_impure_variable (cons
->expr
->symtree
->n
.sym
)
934 || gfc_is_coindexed (cons
->expr
)))
937 gfc_error ("Invalid expression in the derived type constructor for "
938 "pointer component '%s' at %L in PURE procedure",
939 comp
->name
, &cons
->expr
->where
);
947 /****************** Expression name resolution ******************/
949 /* Returns 0 if a symbol was not declared with a type or
950 attribute declaration statement, nonzero otherwise. */
953 was_declared (gfc_symbol
*sym
)
959 if (!a
.implicit_type
&& sym
->ts
.type
!= BT_UNKNOWN
)
962 if (a
.allocatable
|| a
.dimension
|| a
.dummy
|| a
.external
|| a
.intrinsic
963 || a
.optional
|| a
.pointer
|| a
.save
|| a
.target
|| a
.volatile_
964 || a
.value
|| a
.access
!= ACCESS_UNKNOWN
|| a
.intent
!= INTENT_UNKNOWN
965 || a
.asynchronous
|| a
.codimension
)
972 /* Determine if a symbol is generic or not. */
975 generic_sym (gfc_symbol
*sym
)
979 if (sym
->attr
.generic
||
980 (sym
->attr
.intrinsic
&& gfc_generic_intrinsic (sym
->name
)))
983 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
986 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
993 return generic_sym (s
);
1000 /* Determine if a symbol is specific or not. */
1003 specific_sym (gfc_symbol
*sym
)
1007 if (sym
->attr
.if_source
== IFSRC_IFBODY
1008 || sym
->attr
.proc
== PROC_MODULE
1009 || sym
->attr
.proc
== PROC_INTERNAL
1010 || sym
->attr
.proc
== PROC_ST_FUNCTION
1011 || (sym
->attr
.intrinsic
&& gfc_specific_intrinsic (sym
->name
))
1012 || sym
->attr
.external
)
1015 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1018 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1020 return (s
== NULL
) ? 0 : specific_sym (s
);
1024 /* Figure out if the procedure is specific, generic or unknown. */
1027 { PTYPE_GENERIC
= 1, PTYPE_SPECIFIC
, PTYPE_UNKNOWN
}
1031 procedure_kind (gfc_symbol
*sym
)
1033 if (generic_sym (sym
))
1034 return PTYPE_GENERIC
;
1036 if (specific_sym (sym
))
1037 return PTYPE_SPECIFIC
;
1039 return PTYPE_UNKNOWN
;
1042 /* Check references to assumed size arrays. The flag need_full_assumed_size
1043 is nonzero when matching actual arguments. */
1045 static int need_full_assumed_size
= 0;
1048 check_assumed_size_reference (gfc_symbol
*sym
, gfc_expr
*e
)
1050 if (need_full_assumed_size
|| !(sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
))
1053 /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong.
1054 What should it be? */
1055 if ((e
->ref
->u
.ar
.end
[e
->ref
->u
.ar
.as
->rank
- 1] == NULL
)
1056 && (e
->ref
->u
.ar
.as
->type
== AS_ASSUMED_SIZE
)
1057 && (e
->ref
->u
.ar
.type
== AR_FULL
))
1059 gfc_error ("The upper bound in the last dimension must "
1060 "appear in the reference to the assumed size "
1061 "array '%s' at %L", sym
->name
, &e
->where
);
1068 /* Look for bad assumed size array references in argument expressions
1069 of elemental and array valued intrinsic procedures. Since this is
1070 called from procedure resolution functions, it only recurses at
1074 resolve_assumed_size_actual (gfc_expr
*e
)
1079 switch (e
->expr_type
)
1082 if (e
->symtree
&& check_assumed_size_reference (e
->symtree
->n
.sym
, e
))
1087 if (resolve_assumed_size_actual (e
->value
.op
.op1
)
1088 || resolve_assumed_size_actual (e
->value
.op
.op2
))
1099 /* Check a generic procedure, passed as an actual argument, to see if
1100 there is a matching specific name. If none, it is an error, and if
1101 more than one, the reference is ambiguous. */
1103 count_specific_procs (gfc_expr
*e
)
1110 sym
= e
->symtree
->n
.sym
;
1112 for (p
= sym
->generic
; p
; p
= p
->next
)
1113 if (strcmp (sym
->name
, p
->sym
->name
) == 0)
1115 e
->symtree
= gfc_find_symtree (p
->sym
->ns
->sym_root
,
1121 gfc_error ("'%s' at %L is ambiguous", e
->symtree
->n
.sym
->name
,
1125 gfc_error ("GENERIC procedure '%s' is not allowed as an actual "
1126 "argument at %L", sym
->name
, &e
->where
);
1132 /* See if a call to sym could possibly be a not allowed RECURSION because of
1133 a missing RECURIVE declaration. This means that either sym is the current
1134 context itself, or sym is the parent of a contained procedure calling its
1135 non-RECURSIVE containing procedure.
1136 This also works if sym is an ENTRY. */
1139 is_illegal_recursion (gfc_symbol
* sym
, gfc_namespace
* context
)
1141 gfc_symbol
* proc_sym
;
1142 gfc_symbol
* context_proc
;
1143 gfc_namespace
* real_context
;
1145 if (sym
->attr
.flavor
== FL_PROGRAM
)
1148 gcc_assert (sym
->attr
.flavor
== FL_PROCEDURE
);
1150 /* If we've got an ENTRY, find real procedure. */
1151 if (sym
->attr
.entry
&& sym
->ns
->entries
)
1152 proc_sym
= sym
->ns
->entries
->sym
;
1156 /* If sym is RECURSIVE, all is well of course. */
1157 if (proc_sym
->attr
.recursive
|| gfc_option
.flag_recursive
)
1160 /* Find the context procedure's "real" symbol if it has entries.
1161 We look for a procedure symbol, so recurse on the parents if we don't
1162 find one (like in case of a BLOCK construct). */
1163 for (real_context
= context
; ; real_context
= real_context
->parent
)
1165 /* We should find something, eventually! */
1166 gcc_assert (real_context
);
1168 context_proc
= (real_context
->entries
? real_context
->entries
->sym
1169 : real_context
->proc_name
);
1171 /* In some special cases, there may not be a proc_name, like for this
1173 real(bad_kind()) function foo () ...
1174 when checking the call to bad_kind ().
1175 In these cases, we simply return here and assume that the
1180 if (context_proc
->attr
.flavor
!= FL_LABEL
)
1184 /* A call from sym's body to itself is recursion, of course. */
1185 if (context_proc
== proc_sym
)
1188 /* The same is true if context is a contained procedure and sym the
1190 if (context_proc
->attr
.contained
)
1192 gfc_symbol
* parent_proc
;
1194 gcc_assert (context
->parent
);
1195 parent_proc
= (context
->parent
->entries
? context
->parent
->entries
->sym
1196 : context
->parent
->proc_name
);
1198 if (parent_proc
== proc_sym
)
1206 /* Resolve an intrinsic procedure: Set its function/subroutine attribute,
1207 its typespec and formal argument list. */
1210 resolve_intrinsic (gfc_symbol
*sym
, locus
*loc
)
1212 gfc_intrinsic_sym
* isym
;
1218 /* We already know this one is an intrinsic, so we don't call
1219 gfc_is_intrinsic for full checking but rather use gfc_find_function and
1220 gfc_find_subroutine directly to check whether it is a function or
1223 if ((isym
= gfc_find_function (sym
->name
)))
1225 if (sym
->ts
.type
!= BT_UNKNOWN
&& gfc_option
.warn_surprising
1226 && !sym
->attr
.implicit_type
)
1227 gfc_warning ("Type specified for intrinsic function '%s' at %L is"
1228 " ignored", sym
->name
, &sym
->declared_at
);
1230 if (!sym
->attr
.function
&&
1231 gfc_add_function (&sym
->attr
, sym
->name
, loc
) == FAILURE
)
1236 else if ((isym
= gfc_find_subroutine (sym
->name
)))
1238 if (sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.implicit_type
)
1240 gfc_error ("Intrinsic subroutine '%s' at %L shall not have a type"
1241 " specifier", sym
->name
, &sym
->declared_at
);
1245 if (!sym
->attr
.subroutine
&&
1246 gfc_add_subroutine (&sym
->attr
, sym
->name
, loc
) == FAILURE
)
1251 gfc_error ("'%s' declared INTRINSIC at %L does not exist", sym
->name
,
1256 gfc_copy_formal_args_intr (sym
, isym
);
1258 /* Check it is actually available in the standard settings. */
1259 if (gfc_check_intrinsic_standard (isym
, &symstd
, false, sym
->declared_at
)
1262 gfc_error ("The intrinsic '%s' declared INTRINSIC at %L is not"
1263 " available in the current standard settings but %s. Use"
1264 " an appropriate -std=* option or enable -fall-intrinsics"
1265 " in order to use it.",
1266 sym
->name
, &sym
->declared_at
, symstd
);
1274 /* Resolve a procedure expression, like passing it to a called procedure or as
1275 RHS for a procedure pointer assignment. */
1278 resolve_procedure_expression (gfc_expr
* expr
)
1282 if (expr
->expr_type
!= EXPR_VARIABLE
)
1284 gcc_assert (expr
->symtree
);
1286 sym
= expr
->symtree
->n
.sym
;
1288 if (sym
->attr
.intrinsic
)
1289 resolve_intrinsic (sym
, &expr
->where
);
1291 if (sym
->attr
.flavor
!= FL_PROCEDURE
1292 || (sym
->attr
.function
&& sym
->result
== sym
))
1295 /* A non-RECURSIVE procedure that is used as procedure expression within its
1296 own body is in danger of being called recursively. */
1297 if (is_illegal_recursion (sym
, gfc_current_ns
))
1298 gfc_warning ("Non-RECURSIVE procedure '%s' at %L is possibly calling"
1299 " itself recursively. Declare it RECURSIVE or use"
1300 " -frecursive", sym
->name
, &expr
->where
);
1306 /* Resolve an actual argument list. Most of the time, this is just
1307 resolving the expressions in the list.
1308 The exception is that we sometimes have to decide whether arguments
1309 that look like procedure arguments are really simple variable
1313 resolve_actual_arglist (gfc_actual_arglist
*arg
, procedure_type ptype
,
1314 bool no_formal_args
)
1317 gfc_symtree
*parent_st
;
1319 int save_need_full_assumed_size
;
1320 gfc_component
*comp
;
1322 for (; arg
; arg
= arg
->next
)
1327 /* Check the label is a valid branching target. */
1330 if (arg
->label
->defined
== ST_LABEL_UNKNOWN
)
1332 gfc_error ("Label %d referenced at %L is never defined",
1333 arg
->label
->value
, &arg
->label
->where
);
1340 if (gfc_is_proc_ptr_comp (e
, &comp
))
1343 if (e
->expr_type
== EXPR_PPC
)
1345 if (comp
->as
!= NULL
)
1346 e
->rank
= comp
->as
->rank
;
1347 e
->expr_type
= EXPR_FUNCTION
;
1349 if (gfc_resolve_expr (e
) == FAILURE
)
1354 if (e
->expr_type
== EXPR_VARIABLE
1355 && e
->symtree
->n
.sym
->attr
.generic
1357 && count_specific_procs (e
) != 1)
1360 if (e
->ts
.type
!= BT_PROCEDURE
)
1362 save_need_full_assumed_size
= need_full_assumed_size
;
1363 if (e
->expr_type
!= EXPR_VARIABLE
)
1364 need_full_assumed_size
= 0;
1365 if (gfc_resolve_expr (e
) != SUCCESS
)
1367 need_full_assumed_size
= save_need_full_assumed_size
;
1371 /* See if the expression node should really be a variable reference. */
1373 sym
= e
->symtree
->n
.sym
;
1375 if (sym
->attr
.flavor
== FL_PROCEDURE
1376 || sym
->attr
.intrinsic
1377 || sym
->attr
.external
)
1381 /* If a procedure is not already determined to be something else
1382 check if it is intrinsic. */
1383 if (!sym
->attr
.intrinsic
1384 && !(sym
->attr
.external
|| sym
->attr
.use_assoc
1385 || sym
->attr
.if_source
== IFSRC_IFBODY
)
1386 && gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, e
->where
))
1387 sym
->attr
.intrinsic
= 1;
1389 if (sym
->attr
.proc
== PROC_ST_FUNCTION
)
1391 gfc_error ("Statement function '%s' at %L is not allowed as an "
1392 "actual argument", sym
->name
, &e
->where
);
1395 actual_ok
= gfc_intrinsic_actual_ok (sym
->name
,
1396 sym
->attr
.subroutine
);
1397 if (sym
->attr
.intrinsic
&& actual_ok
== 0)
1399 gfc_error ("Intrinsic '%s' at %L is not allowed as an "
1400 "actual argument", sym
->name
, &e
->where
);
1403 if (sym
->attr
.contained
&& !sym
->attr
.use_assoc
1404 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
1406 gfc_error ("Internal procedure '%s' is not allowed as an "
1407 "actual argument at %L", sym
->name
, &e
->where
);
1410 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
)
1412 gfc_error ("ELEMENTAL non-INTRINSIC procedure '%s' is not "
1413 "allowed as an actual argument at %L", sym
->name
,
1417 /* Check if a generic interface has a specific procedure
1418 with the same name before emitting an error. */
1419 if (sym
->attr
.generic
&& count_specific_procs (e
) != 1)
1422 /* Just in case a specific was found for the expression. */
1423 sym
= e
->symtree
->n
.sym
;
1425 /* If the symbol is the function that names the current (or
1426 parent) scope, then we really have a variable reference. */
1428 if (gfc_is_function_return_value (sym
, sym
->ns
))
1431 /* If all else fails, see if we have a specific intrinsic. */
1432 if (sym
->ts
.type
== BT_UNKNOWN
&& sym
->attr
.intrinsic
)
1434 gfc_intrinsic_sym
*isym
;
1436 isym
= gfc_find_function (sym
->name
);
1437 if (isym
== NULL
|| !isym
->specific
)
1439 gfc_error ("Unable to find a specific INTRINSIC procedure "
1440 "for the reference '%s' at %L", sym
->name
,
1445 sym
->attr
.intrinsic
= 1;
1446 sym
->attr
.function
= 1;
1449 if (gfc_resolve_expr (e
) == FAILURE
)
1454 /* See if the name is a module procedure in a parent unit. */
1456 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1459 if (gfc_find_sym_tree (sym
->name
, sym
->ns
->parent
, 1, &parent_st
))
1461 gfc_error ("Symbol '%s' at %L is ambiguous", sym
->name
, &e
->where
);
1465 if (parent_st
== NULL
)
1468 sym
= parent_st
->n
.sym
;
1469 e
->symtree
= parent_st
; /* Point to the right thing. */
1471 if (sym
->attr
.flavor
== FL_PROCEDURE
1472 || sym
->attr
.intrinsic
1473 || sym
->attr
.external
)
1475 if (gfc_resolve_expr (e
) == FAILURE
)
1481 e
->expr_type
= EXPR_VARIABLE
;
1483 if (sym
->as
!= NULL
)
1485 e
->rank
= sym
->as
->rank
;
1486 e
->ref
= gfc_get_ref ();
1487 e
->ref
->type
= REF_ARRAY
;
1488 e
->ref
->u
.ar
.type
= AR_FULL
;
1489 e
->ref
->u
.ar
.as
= sym
->as
;
1492 /* Expressions are assigned a default ts.type of BT_PROCEDURE in
1493 primary.c (match_actual_arg). If above code determines that it
1494 is a variable instead, it needs to be resolved as it was not
1495 done at the beginning of this function. */
1496 save_need_full_assumed_size
= need_full_assumed_size
;
1497 if (e
->expr_type
!= EXPR_VARIABLE
)
1498 need_full_assumed_size
= 0;
1499 if (gfc_resolve_expr (e
) != SUCCESS
)
1501 need_full_assumed_size
= save_need_full_assumed_size
;
1504 /* Check argument list functions %VAL, %LOC and %REF. There is
1505 nothing to do for %REF. */
1506 if (arg
->name
&& arg
->name
[0] == '%')
1508 if (strncmp ("%VAL", arg
->name
, 4) == 0)
1510 if (e
->ts
.type
== BT_CHARACTER
|| e
->ts
.type
== BT_DERIVED
)
1512 gfc_error ("By-value argument at %L is not of numeric "
1519 gfc_error ("By-value argument at %L cannot be an array or "
1520 "an array section", &e
->where
);
1524 /* Intrinsics are still PROC_UNKNOWN here. However,
1525 since same file external procedures are not resolvable
1526 in gfortran, it is a good deal easier to leave them to
1528 if (ptype
!= PROC_UNKNOWN
1529 && ptype
!= PROC_DUMMY
1530 && ptype
!= PROC_EXTERNAL
1531 && ptype
!= PROC_MODULE
)
1533 gfc_error ("By-value argument at %L is not allowed "
1534 "in this context", &e
->where
);
1539 /* Statement functions have already been excluded above. */
1540 else if (strncmp ("%LOC", arg
->name
, 4) == 0
1541 && e
->ts
.type
== BT_PROCEDURE
)
1543 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_INTERNAL
)
1545 gfc_error ("Passing internal procedure at %L by location "
1546 "not allowed", &e
->where
);
1552 /* Fortran 2008, C1237. */
1553 if (e
->expr_type
== EXPR_VARIABLE
&& gfc_is_coindexed (e
)
1554 && gfc_has_ultimate_pointer (e
))
1556 gfc_error ("Coindexed actual argument at %L with ultimate pointer "
1557 "component", &e
->where
);
1566 /* Do the checks of the actual argument list that are specific to elemental
1567 procedures. If called with c == NULL, we have a function, otherwise if
1568 expr == NULL, we have a subroutine. */
1571 resolve_elemental_actual (gfc_expr
*expr
, gfc_code
*c
)
1573 gfc_actual_arglist
*arg0
;
1574 gfc_actual_arglist
*arg
;
1575 gfc_symbol
*esym
= NULL
;
1576 gfc_intrinsic_sym
*isym
= NULL
;
1578 gfc_intrinsic_arg
*iformal
= NULL
;
1579 gfc_formal_arglist
*eformal
= NULL
;
1580 bool formal_optional
= false;
1581 bool set_by_optional
= false;
1585 /* Is this an elemental procedure? */
1586 if (expr
&& expr
->value
.function
.actual
!= NULL
)
1588 if (expr
->value
.function
.esym
!= NULL
1589 && expr
->value
.function
.esym
->attr
.elemental
)
1591 arg0
= expr
->value
.function
.actual
;
1592 esym
= expr
->value
.function
.esym
;
1594 else if (expr
->value
.function
.isym
!= NULL
1595 && expr
->value
.function
.isym
->elemental
)
1597 arg0
= expr
->value
.function
.actual
;
1598 isym
= expr
->value
.function
.isym
;
1603 else if (c
&& c
->ext
.actual
!= NULL
)
1605 arg0
= c
->ext
.actual
;
1607 if (c
->resolved_sym
)
1608 esym
= c
->resolved_sym
;
1610 esym
= c
->symtree
->n
.sym
;
1613 if (!esym
->attr
.elemental
)
1619 /* The rank of an elemental is the rank of its array argument(s). */
1620 for (arg
= arg0
; arg
; arg
= arg
->next
)
1622 if (arg
->expr
!= NULL
&& arg
->expr
->rank
> 0)
1624 rank
= arg
->expr
->rank
;
1625 if (arg
->expr
->expr_type
== EXPR_VARIABLE
1626 && arg
->expr
->symtree
->n
.sym
->attr
.optional
)
1627 set_by_optional
= true;
1629 /* Function specific; set the result rank and shape. */
1633 if (!expr
->shape
&& arg
->expr
->shape
)
1635 expr
->shape
= gfc_get_shape (rank
);
1636 for (i
= 0; i
< rank
; i
++)
1637 mpz_init_set (expr
->shape
[i
], arg
->expr
->shape
[i
]);
1644 /* If it is an array, it shall not be supplied as an actual argument
1645 to an elemental procedure unless an array of the same rank is supplied
1646 as an actual argument corresponding to a nonoptional dummy argument of
1647 that elemental procedure(12.4.1.5). */
1648 formal_optional
= false;
1650 iformal
= isym
->formal
;
1652 eformal
= esym
->formal
;
1654 for (arg
= arg0
; arg
; arg
= arg
->next
)
1658 if (eformal
->sym
&& eformal
->sym
->attr
.optional
)
1659 formal_optional
= true;
1660 eformal
= eformal
->next
;
1662 else if (isym
&& iformal
)
1664 if (iformal
->optional
)
1665 formal_optional
= true;
1666 iformal
= iformal
->next
;
1669 formal_optional
= true;
1671 if (pedantic
&& arg
->expr
!= NULL
1672 && arg
->expr
->expr_type
== EXPR_VARIABLE
1673 && arg
->expr
->symtree
->n
.sym
->attr
.optional
1676 && (set_by_optional
|| arg
->expr
->rank
!= rank
)
1677 && !(isym
&& isym
->id
== GFC_ISYM_CONVERSION
))
1679 gfc_warning ("'%s' at %L is an array and OPTIONAL; IF IT IS "
1680 "MISSING, it cannot be the actual argument of an "
1681 "ELEMENTAL procedure unless there is a non-optional "
1682 "argument with the same rank (12.4.1.5)",
1683 arg
->expr
->symtree
->n
.sym
->name
, &arg
->expr
->where
);
1688 for (arg
= arg0
; arg
; arg
= arg
->next
)
1690 if (arg
->expr
== NULL
|| arg
->expr
->rank
== 0)
1693 /* Being elemental, the last upper bound of an assumed size array
1694 argument must be present. */
1695 if (resolve_assumed_size_actual (arg
->expr
))
1698 /* Elemental procedure's array actual arguments must conform. */
1701 if (gfc_check_conformance (arg
->expr
, e
,
1702 "elemental procedure") == FAILURE
)
1709 /* INTENT(OUT) is only allowed for subroutines; if any actual argument
1710 is an array, the intent inout/out variable needs to be also an array. */
1711 if (rank
> 0 && esym
&& expr
== NULL
)
1712 for (eformal
= esym
->formal
, arg
= arg0
; arg
&& eformal
;
1713 arg
= arg
->next
, eformal
= eformal
->next
)
1714 if ((eformal
->sym
->attr
.intent
== INTENT_OUT
1715 || eformal
->sym
->attr
.intent
== INTENT_INOUT
)
1716 && arg
->expr
&& arg
->expr
->rank
== 0)
1718 gfc_error ("Actual argument at %L for INTENT(%s) dummy '%s' of "
1719 "ELEMENTAL subroutine '%s' is a scalar, but another "
1720 "actual argument is an array", &arg
->expr
->where
,
1721 (eformal
->sym
->attr
.intent
== INTENT_OUT
) ? "OUT"
1722 : "INOUT", eformal
->sym
->name
, esym
->name
);
1729 /* Go through each actual argument in ACTUAL and see if it can be
1730 implemented as an inlined, non-copying intrinsic. FNSYM is the
1731 function being called, or NULL if not known. */
1734 find_noncopying_intrinsics (gfc_symbol
*fnsym
, gfc_actual_arglist
*actual
)
1736 gfc_actual_arglist
*ap
;
1739 for (ap
= actual
; ap
; ap
= ap
->next
)
1741 && (expr
= gfc_get_noncopying_intrinsic_argument (ap
->expr
))
1742 && !gfc_check_fncall_dependency (expr
, INTENT_IN
, fnsym
, actual
,
1744 ap
->expr
->inline_noncopying_intrinsic
= 1;
1748 /* This function does the checking of references to global procedures
1749 as defined in sections 18.1 and 14.1, respectively, of the Fortran
1750 77 and 95 standards. It checks for a gsymbol for the name, making
1751 one if it does not already exist. If it already exists, then the
1752 reference being resolved must correspond to the type of gsymbol.
1753 Otherwise, the new symbol is equipped with the attributes of the
1754 reference. The corresponding code that is called in creating
1755 global entities is parse.c.
1757 In addition, for all but -std=legacy, the gsymbols are used to
1758 check the interfaces of external procedures from the same file.
1759 The namespace of the gsymbol is resolved and then, once this is
1760 done the interface is checked. */
1764 not_in_recursive (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
1766 if (!gsym_ns
->proc_name
->attr
.recursive
)
1769 if (sym
->ns
== gsym_ns
)
1772 if (sym
->ns
->parent
&& sym
->ns
->parent
== gsym_ns
)
1779 not_entry_self_reference (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
1781 if (gsym_ns
->entries
)
1783 gfc_entry_list
*entry
= gsym_ns
->entries
;
1785 for (; entry
; entry
= entry
->next
)
1787 if (strcmp (sym
->name
, entry
->sym
->name
) == 0)
1789 if (strcmp (gsym_ns
->proc_name
->name
,
1790 sym
->ns
->proc_name
->name
) == 0)
1794 && strcmp (gsym_ns
->proc_name
->name
,
1795 sym
->ns
->parent
->proc_name
->name
) == 0)
1804 resolve_global_procedure (gfc_symbol
*sym
, locus
*where
,
1805 gfc_actual_arglist
**actual
, int sub
)
1809 enum gfc_symbol_type type
;
1811 type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
1813 gsym
= gfc_get_gsymbol (sym
->name
);
1815 if ((gsym
->type
!= GSYM_UNKNOWN
&& gsym
->type
!= type
))
1816 gfc_global_used (gsym
, where
);
1818 if (gfc_option
.flag_whole_file
1819 && sym
->attr
.if_source
== IFSRC_UNKNOWN
1820 && gsym
->type
!= GSYM_UNKNOWN
1822 && gsym
->ns
->resolved
!= -1
1823 && gsym
->ns
->proc_name
1824 && not_in_recursive (sym
, gsym
->ns
)
1825 && not_entry_self_reference (sym
, gsym
->ns
))
1827 /* Resolve the gsymbol namespace if needed. */
1828 if (!gsym
->ns
->resolved
)
1830 gfc_dt_list
*old_dt_list
;
1832 /* Stash away derived types so that the backend_decls do not
1834 old_dt_list
= gfc_derived_types
;
1835 gfc_derived_types
= NULL
;
1837 gfc_resolve (gsym
->ns
);
1839 /* Store the new derived types with the global namespace. */
1840 if (gfc_derived_types
)
1841 gsym
->ns
->derived_types
= gfc_derived_types
;
1843 /* Restore the derived types of this namespace. */
1844 gfc_derived_types
= old_dt_list
;
1847 /* Make sure that translation for the gsymbol occurs before
1848 the procedure currently being resolved. */
1849 ns
= gfc_global_ns_list
;
1850 for (; ns
&& ns
!= gsym
->ns
; ns
= ns
->sibling
)
1852 if (ns
->sibling
== gsym
->ns
)
1854 ns
->sibling
= gsym
->ns
->sibling
;
1855 gsym
->ns
->sibling
= gfc_global_ns_list
;
1856 gfc_global_ns_list
= gsym
->ns
;
1861 /* Differences in constant character lengths. */
1862 if (sym
->attr
.function
&& sym
->ts
.type
== BT_CHARACTER
)
1864 long int l1
= 0, l2
= 0;
1865 gfc_charlen
*cl1
= sym
->ts
.u
.cl
;
1866 gfc_charlen
*cl2
= gsym
->ns
->proc_name
->ts
.u
.cl
;
1869 && cl1
->length
!= NULL
1870 && cl1
->length
->expr_type
== EXPR_CONSTANT
)
1871 l1
= mpz_get_si (cl1
->length
->value
.integer
);
1874 && cl2
->length
!= NULL
1875 && cl2
->length
->expr_type
== EXPR_CONSTANT
)
1876 l2
= mpz_get_si (cl2
->length
->value
.integer
);
1878 if (l1
&& l2
&& l1
!= l2
)
1879 gfc_error ("Character length mismatch in return type of "
1880 "function '%s' at %L (%ld/%ld)", sym
->name
,
1881 &sym
->declared_at
, l1
, l2
);
1884 /* Type mismatch of function return type and expected type. */
1885 if (sym
->attr
.function
1886 && !gfc_compare_types (&sym
->ts
, &gsym
->ns
->proc_name
->ts
))
1887 gfc_error ("Return type mismatch of function '%s' at %L (%s/%s)",
1888 sym
->name
, &sym
->declared_at
, gfc_typename (&sym
->ts
),
1889 gfc_typename (&gsym
->ns
->proc_name
->ts
));
1891 if (gsym
->ns
->proc_name
->formal
)
1893 gfc_formal_arglist
*arg
= gsym
->ns
->proc_name
->formal
;
1894 for ( ; arg
; arg
= arg
->next
)
1897 /* F2003, 12.3.1.1 (2a); F2008, 12.4.2.2 (2a) */
1898 else if (arg
->sym
->attr
.allocatable
1899 || arg
->sym
->attr
.asynchronous
1900 || arg
->sym
->attr
.optional
1901 || arg
->sym
->attr
.pointer
1902 || arg
->sym
->attr
.target
1903 || arg
->sym
->attr
.value
1904 || arg
->sym
->attr
.volatile_
)
1906 gfc_error ("Dummy argument '%s' of procedure '%s' at %L "
1907 "has an attribute that requires an explicit "
1908 "interface for this procedure", arg
->sym
->name
,
1909 sym
->name
, &sym
->declared_at
);
1912 /* F2003, 12.3.1.1 (2b); F2008, 12.4.2.2 (2b) */
1913 else if (arg
->sym
&& arg
->sym
->as
1914 && arg
->sym
->as
->type
== AS_ASSUMED_SHAPE
)
1916 gfc_error ("Procedure '%s' at %L with assumed-shape dummy "
1917 "argument '%s' must have an explicit interface",
1918 sym
->name
, &sym
->declared_at
, arg
->sym
->name
);
1921 /* F2008, 12.4.2.2 (2c) */
1922 else if (arg
->sym
->attr
.codimension
)
1924 gfc_error ("Procedure '%s' at %L with coarray dummy argument "
1925 "'%s' must have an explicit interface",
1926 sym
->name
, &sym
->declared_at
, arg
->sym
->name
);
1929 /* F2003, 12.3.1.1 (2c); F2008, 12.4.2.2 (2d) */
1930 else if (false) /* TODO: is a parametrized derived type */
1932 gfc_error ("Procedure '%s' at %L with parametrized derived "
1933 "type argument '%s' must have an explicit "
1934 "interface", sym
->name
, &sym
->declared_at
,
1938 /* F2003, 12.3.1.1 (2d); F2008, 12.4.2.2 (2e) */
1939 else if (arg
->sym
->ts
.type
== BT_CLASS
)
1941 gfc_error ("Procedure '%s' at %L with polymorphic dummy "
1942 "argument '%s' must have an explicit interface",
1943 sym
->name
, &sym
->declared_at
, arg
->sym
->name
);
1948 if (gsym
->ns
->proc_name
->attr
.function
)
1950 /* F2003, 12.3.1.1 (3a); F2008, 12.4.2.2 (3a) */
1951 if (gsym
->ns
->proc_name
->as
1952 && gsym
->ns
->proc_name
->as
->rank
1953 && (!sym
->as
|| sym
->as
->rank
!= gsym
->ns
->proc_name
->as
->rank
))
1954 gfc_error ("The reference to function '%s' at %L either needs an "
1955 "explicit INTERFACE or the rank is incorrect", sym
->name
,
1958 /* F2003, 12.3.1.1 (3b); F2008, 12.4.2.2 (3b) */
1959 if (gsym
->ns
->proc_name
->result
->attr
.pointer
1960 || gsym
->ns
->proc_name
->result
->attr
.allocatable
)
1961 gfc_error ("Function '%s' at %L with a POINTER or ALLOCATABLE "
1962 "result must have an explicit interface", sym
->name
,
1965 /* F2003, 12.3.1.1 (3c); F2008, 12.4.2.2 (3c) */
1966 if (sym
->ts
.type
== BT_CHARACTER
1967 && gsym
->ns
->proc_name
->ts
.u
.cl
->length
!= NULL
)
1969 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
1971 if (!sym
->attr
.entry_master
&& sym
->attr
.if_source
== IFSRC_UNKNOWN
1972 && cl
&& cl
->length
&& cl
->length
->expr_type
!= EXPR_CONSTANT
)
1974 gfc_error ("Nonconstant character-length function '%s' at %L "
1975 "must have an explicit interface", sym
->name
,
1981 /* F2003, 12.3.1.1 (4); F2008, 12.4.2.2 (4) */
1982 if (gsym
->ns
->proc_name
->attr
.elemental
)
1984 gfc_error ("ELEMENTAL procedure '%s' at %L must have an explicit "
1985 "interface", sym
->name
, &sym
->declared_at
);
1988 /* F2003, 12.3.1.1 (5); F2008, 12.4.2.2 (5) */
1989 if (gsym
->ns
->proc_name
->attr
.is_bind_c
)
1991 gfc_error ("Procedure '%s' at %L with BIND(C) attribute must have "
1992 "an explicit interface", sym
->name
, &sym
->declared_at
);
1995 if (gfc_option
.flag_whole_file
== 1
1996 || ((gfc_option
.warn_std
& GFC_STD_LEGACY
)
1997 && !(gfc_option
.warn_std
& GFC_STD_GNU
)))
1998 gfc_errors_to_warnings (1);
2000 gfc_procedure_use (gsym
->ns
->proc_name
, actual
, where
);
2002 gfc_errors_to_warnings (0);
2005 if (gsym
->type
== GSYM_UNKNOWN
)
2008 gsym
->where
= *where
;
2015 /************* Function resolution *************/
2017 /* Resolve a function call known to be generic.
2018 Section 14.1.2.4.1. */
2021 resolve_generic_f0 (gfc_expr
*expr
, gfc_symbol
*sym
)
2025 if (sym
->attr
.generic
)
2027 s
= gfc_search_interface (sym
->generic
, 0, &expr
->value
.function
.actual
);
2030 expr
->value
.function
.name
= s
->name
;
2031 expr
->value
.function
.esym
= s
;
2033 if (s
->ts
.type
!= BT_UNKNOWN
)
2035 else if (s
->result
!= NULL
&& s
->result
->ts
.type
!= BT_UNKNOWN
)
2036 expr
->ts
= s
->result
->ts
;
2039 expr
->rank
= s
->as
->rank
;
2040 else if (s
->result
!= NULL
&& s
->result
->as
!= NULL
)
2041 expr
->rank
= s
->result
->as
->rank
;
2043 gfc_set_sym_referenced (expr
->value
.function
.esym
);
2048 /* TODO: Need to search for elemental references in generic
2052 if (sym
->attr
.intrinsic
)
2053 return gfc_intrinsic_func_interface (expr
, 0);
2060 resolve_generic_f (gfc_expr
*expr
)
2065 sym
= expr
->symtree
->n
.sym
;
2069 m
= resolve_generic_f0 (expr
, sym
);
2072 else if (m
== MATCH_ERROR
)
2076 if (sym
->ns
->parent
== NULL
)
2078 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2082 if (!generic_sym (sym
))
2086 /* Last ditch attempt. See if the reference is to an intrinsic
2087 that possesses a matching interface. 14.1.2.4 */
2088 if (sym
&& !gfc_is_intrinsic (sym
, 0, expr
->where
))
2090 gfc_error ("There is no specific function for the generic '%s' at %L",
2091 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2095 m
= gfc_intrinsic_func_interface (expr
, 0);
2099 gfc_error ("Generic function '%s' at %L is not consistent with a "
2100 "specific intrinsic interface", expr
->symtree
->n
.sym
->name
,
2107 /* Resolve a function call known to be specific. */
2110 resolve_specific_f0 (gfc_symbol
*sym
, gfc_expr
*expr
)
2114 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
2116 if (sym
->attr
.dummy
)
2118 sym
->attr
.proc
= PROC_DUMMY
;
2122 sym
->attr
.proc
= PROC_EXTERNAL
;
2126 if (sym
->attr
.proc
== PROC_MODULE
2127 || sym
->attr
.proc
== PROC_ST_FUNCTION
2128 || sym
->attr
.proc
== PROC_INTERNAL
)
2131 if (sym
->attr
.intrinsic
)
2133 m
= gfc_intrinsic_func_interface (expr
, 1);
2137 gfc_error ("Function '%s' at %L is INTRINSIC but is not compatible "
2138 "with an intrinsic", sym
->name
, &expr
->where
);
2146 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2149 expr
->ts
= sym
->result
->ts
;
2152 expr
->value
.function
.name
= sym
->name
;
2153 expr
->value
.function
.esym
= sym
;
2154 if (sym
->as
!= NULL
)
2155 expr
->rank
= sym
->as
->rank
;
2162 resolve_specific_f (gfc_expr
*expr
)
2167 sym
= expr
->symtree
->n
.sym
;
2171 m
= resolve_specific_f0 (sym
, expr
);
2174 if (m
== MATCH_ERROR
)
2177 if (sym
->ns
->parent
== NULL
)
2180 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2186 gfc_error ("Unable to resolve the specific function '%s' at %L",
2187 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2193 /* Resolve a procedure call not known to be generic nor specific. */
2196 resolve_unknown_f (gfc_expr
*expr
)
2201 sym
= expr
->symtree
->n
.sym
;
2203 if (sym
->attr
.dummy
)
2205 sym
->attr
.proc
= PROC_DUMMY
;
2206 expr
->value
.function
.name
= sym
->name
;
2210 /* See if we have an intrinsic function reference. */
2212 if (gfc_is_intrinsic (sym
, 0, expr
->where
))
2214 if (gfc_intrinsic_func_interface (expr
, 1) == MATCH_YES
)
2219 /* The reference is to an external name. */
2221 sym
->attr
.proc
= PROC_EXTERNAL
;
2222 expr
->value
.function
.name
= sym
->name
;
2223 expr
->value
.function
.esym
= expr
->symtree
->n
.sym
;
2225 if (sym
->as
!= NULL
)
2226 expr
->rank
= sym
->as
->rank
;
2228 /* Type of the expression is either the type of the symbol or the
2229 default type of the symbol. */
2232 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2234 if (sym
->ts
.type
!= BT_UNKNOWN
)
2238 ts
= gfc_get_default_type (sym
->name
, sym
->ns
);
2240 if (ts
->type
== BT_UNKNOWN
)
2242 gfc_error ("Function '%s' at %L has no IMPLICIT type",
2243 sym
->name
, &expr
->where
);
2254 /* Return true, if the symbol is an external procedure. */
2256 is_external_proc (gfc_symbol
*sym
)
2258 if (!sym
->attr
.dummy
&& !sym
->attr
.contained
2259 && !(sym
->attr
.intrinsic
2260 || gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, sym
->declared_at
))
2261 && sym
->attr
.proc
!= PROC_ST_FUNCTION
2262 && !sym
->attr
.proc_pointer
2263 && !sym
->attr
.use_assoc
2271 /* Figure out if a function reference is pure or not. Also set the name
2272 of the function for a potential error message. Return nonzero if the
2273 function is PURE, zero if not. */
2275 pure_stmt_function (gfc_expr
*, gfc_symbol
*);
2278 pure_function (gfc_expr
*e
, const char **name
)
2284 if (e
->symtree
!= NULL
2285 && e
->symtree
->n
.sym
!= NULL
2286 && e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2287 return pure_stmt_function (e
, e
->symtree
->n
.sym
);
2289 if (e
->value
.function
.esym
)
2291 pure
= gfc_pure (e
->value
.function
.esym
);
2292 *name
= e
->value
.function
.esym
->name
;
2294 else if (e
->value
.function
.isym
)
2296 pure
= e
->value
.function
.isym
->pure
2297 || e
->value
.function
.isym
->elemental
;
2298 *name
= e
->value
.function
.isym
->name
;
2302 /* Implicit functions are not pure. */
2304 *name
= e
->value
.function
.name
;
2312 impure_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
,
2313 int *f ATTRIBUTE_UNUSED
)
2317 /* Don't bother recursing into other statement functions
2318 since they will be checked individually for purity. */
2319 if (e
->expr_type
!= EXPR_FUNCTION
2321 || e
->symtree
->n
.sym
== sym
2322 || e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2325 return pure_function (e
, &name
) ? false : true;
2330 pure_stmt_function (gfc_expr
*e
, gfc_symbol
*sym
)
2332 return gfc_traverse_expr (e
, sym
, impure_stmt_fcn
, 0) ? 0 : 1;
2337 is_scalar_expr_ptr (gfc_expr
*expr
)
2339 gfc_try retval
= SUCCESS
;
2344 /* See if we have a gfc_ref, which means we have a substring, array
2345 reference, or a component. */
2346 if (expr
->ref
!= NULL
)
2349 while (ref
->next
!= NULL
)
2355 if (ref
->u
.ss
.length
!= NULL
2356 && ref
->u
.ss
.length
->length
!= NULL
2358 && ref
->u
.ss
.start
->expr_type
== EXPR_CONSTANT
2360 && ref
->u
.ss
.end
->expr_type
== EXPR_CONSTANT
)
2362 start
= (int) mpz_get_si (ref
->u
.ss
.start
->value
.integer
);
2363 end
= (int) mpz_get_si (ref
->u
.ss
.end
->value
.integer
);
2364 if (end
- start
+ 1 != 1)
2371 if (ref
->u
.ar
.type
== AR_ELEMENT
)
2373 else if (ref
->u
.ar
.type
== AR_FULL
)
2375 /* The user can give a full array if the array is of size 1. */
2376 if (ref
->u
.ar
.as
!= NULL
2377 && ref
->u
.ar
.as
->rank
== 1
2378 && ref
->u
.ar
.as
->type
== AS_EXPLICIT
2379 && ref
->u
.ar
.as
->lower
[0] != NULL
2380 && ref
->u
.ar
.as
->lower
[0]->expr_type
== EXPR_CONSTANT
2381 && ref
->u
.ar
.as
->upper
[0] != NULL
2382 && ref
->u
.ar
.as
->upper
[0]->expr_type
== EXPR_CONSTANT
)
2384 /* If we have a character string, we need to check if
2385 its length is one. */
2386 if (expr
->ts
.type
== BT_CHARACTER
)
2388 if (expr
->ts
.u
.cl
== NULL
2389 || expr
->ts
.u
.cl
->length
== NULL
2390 || mpz_cmp_si (expr
->ts
.u
.cl
->length
->value
.integer
, 1)
2396 /* We have constant lower and upper bounds. If the
2397 difference between is 1, it can be considered a
2399 start
= (int) mpz_get_si
2400 (ref
->u
.ar
.as
->lower
[0]->value
.integer
);
2401 end
= (int) mpz_get_si
2402 (ref
->u
.ar
.as
->upper
[0]->value
.integer
);
2403 if (end
- start
+ 1 != 1)
2418 else if (expr
->ts
.type
== BT_CHARACTER
&& expr
->rank
== 0)
2420 /* Character string. Make sure it's of length 1. */
2421 if (expr
->ts
.u
.cl
== NULL
2422 || expr
->ts
.u
.cl
->length
== NULL
2423 || mpz_cmp_si (expr
->ts
.u
.cl
->length
->value
.integer
, 1) != 0)
2426 else if (expr
->rank
!= 0)
2433 /* Match one of the iso_c_binding functions (c_associated or c_loc)
2434 and, in the case of c_associated, set the binding label based on
2438 gfc_iso_c_func_interface (gfc_symbol
*sym
, gfc_actual_arglist
*args
,
2439 gfc_symbol
**new_sym
)
2441 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2442 char binding_label
[GFC_MAX_BINDING_LABEL_LEN
+ 1];
2443 int optional_arg
= 0;
2444 gfc_try retval
= SUCCESS
;
2445 gfc_symbol
*args_sym
;
2446 gfc_typespec
*arg_ts
;
2447 symbol_attribute arg_attr
;
2449 if (args
->expr
->expr_type
== EXPR_CONSTANT
2450 || args
->expr
->expr_type
== EXPR_OP
2451 || args
->expr
->expr_type
== EXPR_NULL
)
2453 gfc_error ("Argument to '%s' at %L is not a variable",
2454 sym
->name
, &(args
->expr
->where
));
2458 args_sym
= args
->expr
->symtree
->n
.sym
;
2460 /* The typespec for the actual arg should be that stored in the expr
2461 and not necessarily that of the expr symbol (args_sym), because
2462 the actual expression could be a part-ref of the expr symbol. */
2463 arg_ts
= &(args
->expr
->ts
);
2464 arg_attr
= gfc_expr_attr (args
->expr
);
2466 if (sym
->intmod_sym_id
== ISOCBINDING_ASSOCIATED
)
2468 /* If the user gave two args then they are providing something for
2469 the optional arg (the second cptr). Therefore, set the name and
2470 binding label to the c_associated for two cptrs. Otherwise,
2471 set c_associated to expect one cptr. */
2475 sprintf (name
, "%s_2", sym
->name
);
2476 sprintf (binding_label
, "%s_2", sym
->binding_label
);
2482 sprintf (name
, "%s_1", sym
->name
);
2483 sprintf (binding_label
, "%s_1", sym
->binding_label
);
2487 /* Get a new symbol for the version of c_associated that
2489 *new_sym
= get_iso_c_sym (sym
, name
, binding_label
, optional_arg
);
2491 else if (sym
->intmod_sym_id
== ISOCBINDING_LOC
2492 || sym
->intmod_sym_id
== ISOCBINDING_FUNLOC
)
2494 sprintf (name
, "%s", sym
->name
);
2495 sprintf (binding_label
, "%s", sym
->binding_label
);
2497 /* Error check the call. */
2498 if (args
->next
!= NULL
)
2500 gfc_error_now ("More actual than formal arguments in '%s' "
2501 "call at %L", name
, &(args
->expr
->where
));
2504 else if (sym
->intmod_sym_id
== ISOCBINDING_LOC
)
2506 /* Make sure we have either the target or pointer attribute. */
2507 if (!arg_attr
.target
&& !arg_attr
.pointer
)
2509 gfc_error_now ("Parameter '%s' to '%s' at %L must be either "
2510 "a TARGET or an associated pointer",
2512 sym
->name
, &(args
->expr
->where
));
2516 /* See if we have interoperable type and type param. */
2517 if (verify_c_interop (arg_ts
) == SUCCESS
2518 || gfc_check_any_c_kind (arg_ts
) == SUCCESS
)
2520 if (args_sym
->attr
.target
== 1)
2522 /* Case 1a, section 15.1.2.5, J3/04-007: variable that
2523 has the target attribute and is interoperable. */
2524 /* Case 1b, section 15.1.2.5, J3/04-007: allocated
2525 allocatable variable that has the TARGET attribute and
2526 is not an array of zero size. */
2527 if (args_sym
->attr
.allocatable
== 1)
2529 if (args_sym
->attr
.dimension
!= 0
2530 && (args_sym
->as
&& args_sym
->as
->rank
== 0))
2532 gfc_error_now ("Allocatable variable '%s' used as a "
2533 "parameter to '%s' at %L must not be "
2534 "an array of zero size",
2535 args_sym
->name
, sym
->name
,
2536 &(args
->expr
->where
));
2542 /* A non-allocatable target variable with C
2543 interoperable type and type parameters must be
2545 if (args_sym
&& args_sym
->attr
.dimension
)
2547 if (args_sym
->as
->type
== AS_ASSUMED_SHAPE
)
2549 gfc_error ("Assumed-shape array '%s' at %L "
2550 "cannot be an argument to the "
2551 "procedure '%s' because "
2552 "it is not C interoperable",
2554 &(args
->expr
->where
), sym
->name
);
2557 else if (args_sym
->as
->type
== AS_DEFERRED
)
2559 gfc_error ("Deferred-shape array '%s' at %L "
2560 "cannot be an argument to the "
2561 "procedure '%s' because "
2562 "it is not C interoperable",
2564 &(args
->expr
->where
), sym
->name
);
2569 /* Make sure it's not a character string. Arrays of
2570 any type should be ok if the variable is of a C
2571 interoperable type. */
2572 if (arg_ts
->type
== BT_CHARACTER
)
2573 if (arg_ts
->u
.cl
!= NULL
2574 && (arg_ts
->u
.cl
->length
== NULL
2575 || arg_ts
->u
.cl
->length
->expr_type
2578 (arg_ts
->u
.cl
->length
->value
.integer
, 1)
2580 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2582 gfc_error_now ("CHARACTER argument '%s' to '%s' "
2583 "at %L must have a length of 1",
2584 args_sym
->name
, sym
->name
,
2585 &(args
->expr
->where
));
2590 else if (arg_attr
.pointer
2591 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2593 /* Case 1c, section 15.1.2.5, J3/04-007: an associated
2595 gfc_error_now ("Argument '%s' to '%s' at %L must be an "
2596 "associated scalar POINTER", args_sym
->name
,
2597 sym
->name
, &(args
->expr
->where
));
2603 /* The parameter is not required to be C interoperable. If it
2604 is not C interoperable, it must be a nonpolymorphic scalar
2605 with no length type parameters. It still must have either
2606 the pointer or target attribute, and it can be
2607 allocatable (but must be allocated when c_loc is called). */
2608 if (args
->expr
->rank
!= 0
2609 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2611 gfc_error_now ("Parameter '%s' to '%s' at %L must be a "
2612 "scalar", args_sym
->name
, sym
->name
,
2613 &(args
->expr
->where
));
2616 else if (arg_ts
->type
== BT_CHARACTER
2617 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2619 gfc_error_now ("CHARACTER argument '%s' to '%s' at "
2620 "%L must have a length of 1",
2621 args_sym
->name
, sym
->name
,
2622 &(args
->expr
->where
));
2625 else if (arg_ts
->type
== BT_CLASS
)
2627 gfc_error_now ("Parameter '%s' to '%s' at %L must not be "
2628 "polymorphic", args_sym
->name
, sym
->name
,
2629 &(args
->expr
->where
));
2634 else if (sym
->intmod_sym_id
== ISOCBINDING_FUNLOC
)
2636 if (args_sym
->attr
.flavor
!= FL_PROCEDURE
)
2638 /* TODO: Update this error message to allow for procedure
2639 pointers once they are implemented. */
2640 gfc_error_now ("Parameter '%s' to '%s' at %L must be a "
2642 args_sym
->name
, sym
->name
,
2643 &(args
->expr
->where
));
2646 else if (args_sym
->attr
.is_bind_c
!= 1)
2648 gfc_error_now ("Parameter '%s' to '%s' at %L must be "
2650 args_sym
->name
, sym
->name
,
2651 &(args
->expr
->where
));
2656 /* for c_loc/c_funloc, the new symbol is the same as the old one */
2661 gfc_internal_error ("gfc_iso_c_func_interface(): Unhandled "
2662 "iso_c_binding function: '%s'!\n", sym
->name
);
2669 /* Resolve a function call, which means resolving the arguments, then figuring
2670 out which entity the name refers to. */
2671 /* TODO: Check procedure arguments so that an INTENT(IN) isn't passed
2672 to INTENT(OUT) or INTENT(INOUT). */
2675 resolve_function (gfc_expr
*expr
)
2677 gfc_actual_arglist
*arg
;
2682 procedure_type p
= PROC_INTRINSIC
;
2683 bool no_formal_args
;
2687 sym
= expr
->symtree
->n
.sym
;
2689 /* If this is a procedure pointer component, it has already been resolved. */
2690 if (gfc_is_proc_ptr_comp (expr
, NULL
))
2693 if (sym
&& sym
->attr
.intrinsic
2694 && resolve_intrinsic (sym
, &expr
->where
) == FAILURE
)
2697 if (sym
&& (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.subroutine
))
2699 gfc_error ("'%s' at %L is not a function", sym
->name
, &expr
->where
);
2703 /* If this ia a deferred TBP with an abstract interface (which may
2704 of course be referenced), expr->value.function.esym will be set. */
2705 if (sym
&& sym
->attr
.abstract
&& !expr
->value
.function
.esym
)
2707 gfc_error ("ABSTRACT INTERFACE '%s' must not be referenced at %L",
2708 sym
->name
, &expr
->where
);
2712 /* Switch off assumed size checking and do this again for certain kinds
2713 of procedure, once the procedure itself is resolved. */
2714 need_full_assumed_size
++;
2716 if (expr
->symtree
&& expr
->symtree
->n
.sym
)
2717 p
= expr
->symtree
->n
.sym
->attr
.proc
;
2719 if (expr
->value
.function
.isym
&& expr
->value
.function
.isym
->inquiry
)
2720 inquiry_argument
= true;
2721 no_formal_args
= sym
&& is_external_proc (sym
) && sym
->formal
== NULL
;
2723 if (resolve_actual_arglist (expr
->value
.function
.actual
,
2724 p
, no_formal_args
) == FAILURE
)
2726 inquiry_argument
= false;
2730 inquiry_argument
= false;
2732 /* Need to setup the call to the correct c_associated, depending on
2733 the number of cptrs to user gives to compare. */
2734 if (sym
&& sym
->attr
.is_iso_c
== 1)
2736 if (gfc_iso_c_func_interface (sym
, expr
->value
.function
.actual
, &sym
)
2740 /* Get the symtree for the new symbol (resolved func).
2741 the old one will be freed later, when it's no longer used. */
2742 gfc_find_sym_tree (sym
->name
, sym
->ns
, 1, &(expr
->symtree
));
2745 /* Resume assumed_size checking. */
2746 need_full_assumed_size
--;
2748 /* If the procedure is external, check for usage. */
2749 if (sym
&& is_external_proc (sym
))
2750 resolve_global_procedure (sym
, &expr
->where
,
2751 &expr
->value
.function
.actual
, 0);
2753 if (sym
&& sym
->ts
.type
== BT_CHARACTER
2755 && sym
->ts
.u
.cl
->length
== NULL
2757 && expr
->value
.function
.esym
== NULL
2758 && !sym
->attr
.contained
)
2760 /* Internal procedures are taken care of in resolve_contained_fntype. */
2761 gfc_error ("Function '%s' is declared CHARACTER(*) and cannot "
2762 "be used at %L since it is not a dummy argument",
2763 sym
->name
, &expr
->where
);
2767 /* See if function is already resolved. */
2769 if (expr
->value
.function
.name
!= NULL
)
2771 if (expr
->ts
.type
== BT_UNKNOWN
)
2777 /* Apply the rules of section 14.1.2. */
2779 switch (procedure_kind (sym
))
2782 t
= resolve_generic_f (expr
);
2785 case PTYPE_SPECIFIC
:
2786 t
= resolve_specific_f (expr
);
2790 t
= resolve_unknown_f (expr
);
2794 gfc_internal_error ("resolve_function(): bad function type");
2798 /* If the expression is still a function (it might have simplified),
2799 then we check to see if we are calling an elemental function. */
2801 if (expr
->expr_type
!= EXPR_FUNCTION
)
2804 temp
= need_full_assumed_size
;
2805 need_full_assumed_size
= 0;
2807 if (resolve_elemental_actual (expr
, NULL
) == FAILURE
)
2810 if (omp_workshare_flag
2811 && expr
->value
.function
.esym
2812 && ! gfc_elemental (expr
->value
.function
.esym
))
2814 gfc_error ("User defined non-ELEMENTAL function '%s' at %L not allowed "
2815 "in WORKSHARE construct", expr
->value
.function
.esym
->name
,
2820 #define GENERIC_ID expr->value.function.isym->id
2821 else if (expr
->value
.function
.actual
!= NULL
2822 && expr
->value
.function
.isym
!= NULL
2823 && GENERIC_ID
!= GFC_ISYM_LBOUND
2824 && GENERIC_ID
!= GFC_ISYM_LEN
2825 && GENERIC_ID
!= GFC_ISYM_LOC
2826 && GENERIC_ID
!= GFC_ISYM_PRESENT
)
2828 /* Array intrinsics must also have the last upper bound of an
2829 assumed size array argument. UBOUND and SIZE have to be
2830 excluded from the check if the second argument is anything
2833 for (arg
= expr
->value
.function
.actual
; arg
; arg
= arg
->next
)
2835 if ((GENERIC_ID
== GFC_ISYM_UBOUND
|| GENERIC_ID
== GFC_ISYM_SIZE
)
2836 && arg
->next
!= NULL
&& arg
->next
->expr
)
2838 if (arg
->next
->expr
->expr_type
!= EXPR_CONSTANT
)
2841 if (arg
->next
->name
&& strncmp(arg
->next
->name
, "kind", 4) == 0)
2844 if ((int)mpz_get_si (arg
->next
->expr
->value
.integer
)
2849 if (arg
->expr
!= NULL
2850 && arg
->expr
->rank
> 0
2851 && resolve_assumed_size_actual (arg
->expr
))
2857 need_full_assumed_size
= temp
;
2860 if (!pure_function (expr
, &name
) && name
)
2864 gfc_error ("reference to non-PURE function '%s' at %L inside a "
2865 "FORALL %s", name
, &expr
->where
,
2866 forall_flag
== 2 ? "mask" : "block");
2869 else if (gfc_pure (NULL
))
2871 gfc_error ("Function reference to '%s' at %L is to a non-PURE "
2872 "procedure within a PURE procedure", name
, &expr
->where
);
2877 /* Functions without the RECURSIVE attribution are not allowed to
2878 * call themselves. */
2879 if (expr
->value
.function
.esym
&& !expr
->value
.function
.esym
->attr
.recursive
)
2882 esym
= expr
->value
.function
.esym
;
2884 if (is_illegal_recursion (esym
, gfc_current_ns
))
2886 if (esym
->attr
.entry
&& esym
->ns
->entries
)
2887 gfc_error ("ENTRY '%s' at %L cannot be called recursively, as"
2888 " function '%s' is not RECURSIVE",
2889 esym
->name
, &expr
->where
, esym
->ns
->entries
->sym
->name
);
2891 gfc_error ("Function '%s' at %L cannot be called recursively, as it"
2892 " is not RECURSIVE", esym
->name
, &expr
->where
);
2898 /* Character lengths of use associated functions may contains references to
2899 symbols not referenced from the current program unit otherwise. Make sure
2900 those symbols are marked as referenced. */
2902 if (expr
->ts
.type
== BT_CHARACTER
&& expr
->value
.function
.esym
2903 && expr
->value
.function
.esym
->attr
.use_assoc
)
2905 gfc_expr_set_symbols_referenced (expr
->ts
.u
.cl
->length
);
2909 && !((expr
->value
.function
.esym
2910 && expr
->value
.function
.esym
->attr
.elemental
)
2912 (expr
->value
.function
.isym
2913 && expr
->value
.function
.isym
->elemental
)))
2914 find_noncopying_intrinsics (expr
->value
.function
.esym
,
2915 expr
->value
.function
.actual
);
2917 /* Make sure that the expression has a typespec that works. */
2918 if (expr
->ts
.type
== BT_UNKNOWN
)
2920 if (expr
->symtree
->n
.sym
->result
2921 && expr
->symtree
->n
.sym
->result
->ts
.type
!= BT_UNKNOWN
2922 && !expr
->symtree
->n
.sym
->result
->attr
.proc_pointer
)
2923 expr
->ts
= expr
->symtree
->n
.sym
->result
->ts
;
2930 /************* Subroutine resolution *************/
2933 pure_subroutine (gfc_code
*c
, gfc_symbol
*sym
)
2939 gfc_error ("Subroutine call to '%s' in FORALL block at %L is not PURE",
2940 sym
->name
, &c
->loc
);
2941 else if (gfc_pure (NULL
))
2942 gfc_error ("Subroutine call to '%s' at %L is not PURE", sym
->name
,
2948 resolve_generic_s0 (gfc_code
*c
, gfc_symbol
*sym
)
2952 if (sym
->attr
.generic
)
2954 s
= gfc_search_interface (sym
->generic
, 1, &c
->ext
.actual
);
2957 c
->resolved_sym
= s
;
2958 pure_subroutine (c
, s
);
2962 /* TODO: Need to search for elemental references in generic interface. */
2965 if (sym
->attr
.intrinsic
)
2966 return gfc_intrinsic_sub_interface (c
, 0);
2973 resolve_generic_s (gfc_code
*c
)
2978 sym
= c
->symtree
->n
.sym
;
2982 m
= resolve_generic_s0 (c
, sym
);
2985 else if (m
== MATCH_ERROR
)
2989 if (sym
->ns
->parent
== NULL
)
2991 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2995 if (!generic_sym (sym
))
2999 /* Last ditch attempt. See if the reference is to an intrinsic
3000 that possesses a matching interface. 14.1.2.4 */
3001 sym
= c
->symtree
->n
.sym
;
3003 if (!gfc_is_intrinsic (sym
, 1, c
->loc
))
3005 gfc_error ("There is no specific subroutine for the generic '%s' at %L",
3006 sym
->name
, &c
->loc
);
3010 m
= gfc_intrinsic_sub_interface (c
, 0);
3014 gfc_error ("Generic subroutine '%s' at %L is not consistent with an "
3015 "intrinsic subroutine interface", sym
->name
, &c
->loc
);
3021 /* Set the name and binding label of the subroutine symbol in the call
3022 expression represented by 'c' to include the type and kind of the
3023 second parameter. This function is for resolving the appropriate
3024 version of c_f_pointer() and c_f_procpointer(). For example, a
3025 call to c_f_pointer() for a default integer pointer could have a
3026 name of c_f_pointer_i4. If no second arg exists, which is an error
3027 for these two functions, it defaults to the generic symbol's name
3028 and binding label. */
3031 set_name_and_label (gfc_code
*c
, gfc_symbol
*sym
,
3032 char *name
, char *binding_label
)
3034 gfc_expr
*arg
= NULL
;
3038 /* The second arg of c_f_pointer and c_f_procpointer determines
3039 the type and kind for the procedure name. */
3040 arg
= c
->ext
.actual
->next
->expr
;
3044 /* Set up the name to have the given symbol's name,
3045 plus the type and kind. */
3046 /* a derived type is marked with the type letter 'u' */
3047 if (arg
->ts
.type
== BT_DERIVED
)
3050 kind
= 0; /* set the kind as 0 for now */
3054 type
= gfc_type_letter (arg
->ts
.type
);
3055 kind
= arg
->ts
.kind
;
3058 if (arg
->ts
.type
== BT_CHARACTER
)
3059 /* Kind info for character strings not needed. */
3062 sprintf (name
, "%s_%c%d", sym
->name
, type
, kind
);
3063 /* Set up the binding label as the given symbol's label plus
3064 the type and kind. */
3065 sprintf (binding_label
, "%s_%c%d", sym
->binding_label
, type
, kind
);
3069 /* If the second arg is missing, set the name and label as
3070 was, cause it should at least be found, and the missing
3071 arg error will be caught by compare_parameters(). */
3072 sprintf (name
, "%s", sym
->name
);
3073 sprintf (binding_label
, "%s", sym
->binding_label
);
3080 /* Resolve a generic version of the iso_c_binding procedure given
3081 (sym) to the specific one based on the type and kind of the
3082 argument(s). Currently, this function resolves c_f_pointer() and
3083 c_f_procpointer based on the type and kind of the second argument
3084 (FPTR). Other iso_c_binding procedures aren't specially handled.
3085 Upon successfully exiting, c->resolved_sym will hold the resolved
3086 symbol. Returns MATCH_ERROR if an error occurred; MATCH_YES
3090 gfc_iso_c_sub_interface (gfc_code
*c
, gfc_symbol
*sym
)
3092 gfc_symbol
*new_sym
;
3093 /* this is fine, since we know the names won't use the max */
3094 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3095 char binding_label
[GFC_MAX_BINDING_LABEL_LEN
+ 1];
3096 /* default to success; will override if find error */
3097 match m
= MATCH_YES
;
3099 /* Make sure the actual arguments are in the necessary order (based on the
3100 formal args) before resolving. */
3101 gfc_procedure_use (sym
, &c
->ext
.actual
, &(c
->loc
));
3103 if ((sym
->intmod_sym_id
== ISOCBINDING_F_POINTER
) ||
3104 (sym
->intmod_sym_id
== ISOCBINDING_F_PROCPOINTER
))
3106 set_name_and_label (c
, sym
, name
, binding_label
);
3108 if (sym
->intmod_sym_id
== ISOCBINDING_F_POINTER
)
3110 if (c
->ext
.actual
!= NULL
&& c
->ext
.actual
->next
!= NULL
)
3112 /* Make sure we got a third arg if the second arg has non-zero
3113 rank. We must also check that the type and rank are
3114 correct since we short-circuit this check in
3115 gfc_procedure_use() (called above to sort actual args). */
3116 if (c
->ext
.actual
->next
->expr
->rank
!= 0)
3118 if(c
->ext
.actual
->next
->next
== NULL
3119 || c
->ext
.actual
->next
->next
->expr
== NULL
)
3122 gfc_error ("Missing SHAPE parameter for call to %s "
3123 "at %L", sym
->name
, &(c
->loc
));
3125 else if (c
->ext
.actual
->next
->next
->expr
->ts
.type
3127 || c
->ext
.actual
->next
->next
->expr
->rank
!= 1)
3130 gfc_error ("SHAPE parameter for call to %s at %L must "
3131 "be a rank 1 INTEGER array", sym
->name
,
3138 if (m
!= MATCH_ERROR
)
3140 /* the 1 means to add the optional arg to formal list */
3141 new_sym
= get_iso_c_sym (sym
, name
, binding_label
, 1);
3143 /* for error reporting, say it's declared where the original was */
3144 new_sym
->declared_at
= sym
->declared_at
;
3149 /* no differences for c_loc or c_funloc */
3153 /* set the resolved symbol */
3154 if (m
!= MATCH_ERROR
)
3155 c
->resolved_sym
= new_sym
;
3157 c
->resolved_sym
= sym
;
3163 /* Resolve a subroutine call known to be specific. */
3166 resolve_specific_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3170 if(sym
->attr
.is_iso_c
)
3172 m
= gfc_iso_c_sub_interface (c
,sym
);
3176 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
3178 if (sym
->attr
.dummy
)
3180 sym
->attr
.proc
= PROC_DUMMY
;
3184 sym
->attr
.proc
= PROC_EXTERNAL
;
3188 if (sym
->attr
.proc
== PROC_MODULE
|| sym
->attr
.proc
== PROC_INTERNAL
)
3191 if (sym
->attr
.intrinsic
)
3193 m
= gfc_intrinsic_sub_interface (c
, 1);
3197 gfc_error ("Subroutine '%s' at %L is INTRINSIC but is not compatible "
3198 "with an intrinsic", sym
->name
, &c
->loc
);
3206 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3208 c
->resolved_sym
= sym
;
3209 pure_subroutine (c
, sym
);
3216 resolve_specific_s (gfc_code
*c
)
3221 sym
= c
->symtree
->n
.sym
;
3225 m
= resolve_specific_s0 (c
, sym
);
3228 if (m
== MATCH_ERROR
)
3231 if (sym
->ns
->parent
== NULL
)
3234 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3240 sym
= c
->symtree
->n
.sym
;
3241 gfc_error ("Unable to resolve the specific subroutine '%s' at %L",
3242 sym
->name
, &c
->loc
);
3248 /* Resolve a subroutine call not known to be generic nor specific. */
3251 resolve_unknown_s (gfc_code
*c
)
3255 sym
= c
->symtree
->n
.sym
;
3257 if (sym
->attr
.dummy
)
3259 sym
->attr
.proc
= PROC_DUMMY
;
3263 /* See if we have an intrinsic function reference. */
3265 if (gfc_is_intrinsic (sym
, 1, c
->loc
))
3267 if (gfc_intrinsic_sub_interface (c
, 1) == MATCH_YES
)
3272 /* The reference is to an external name. */
3275 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3277 c
->resolved_sym
= sym
;
3279 pure_subroutine (c
, sym
);
3285 /* Resolve a subroutine call. Although it was tempting to use the same code
3286 for functions, subroutines and functions are stored differently and this
3287 makes things awkward. */
3290 resolve_call (gfc_code
*c
)
3293 procedure_type ptype
= PROC_INTRINSIC
;
3294 gfc_symbol
*csym
, *sym
;
3295 bool no_formal_args
;
3297 csym
= c
->symtree
? c
->symtree
->n
.sym
: NULL
;
3299 if (csym
&& csym
->ts
.type
!= BT_UNKNOWN
)
3301 gfc_error ("'%s' at %L has a type, which is not consistent with "
3302 "the CALL at %L", csym
->name
, &csym
->declared_at
, &c
->loc
);
3306 if (csym
&& gfc_current_ns
->parent
&& csym
->ns
!= gfc_current_ns
)
3309 gfc_find_sym_tree (csym
->name
, gfc_current_ns
, 1, &st
);
3310 sym
= st
? st
->n
.sym
: NULL
;
3311 if (sym
&& csym
!= sym
3312 && sym
->ns
== gfc_current_ns
3313 && sym
->attr
.flavor
== FL_PROCEDURE
3314 && sym
->attr
.contained
)
3317 if (csym
->attr
.generic
)
3318 c
->symtree
->n
.sym
= sym
;
3321 csym
= c
->symtree
->n
.sym
;
3325 /* If this ia a deferred TBP with an abstract interface
3326 (which may of course be referenced), c->expr1 will be set. */
3327 if (csym
&& csym
->attr
.abstract
&& !c
->expr1
)
3329 gfc_error ("ABSTRACT INTERFACE '%s' must not be referenced at %L",
3330 csym
->name
, &c
->loc
);
3334 /* Subroutines without the RECURSIVE attribution are not allowed to
3335 * call themselves. */
3336 if (csym
&& is_illegal_recursion (csym
, gfc_current_ns
))
3338 if (csym
->attr
.entry
&& csym
->ns
->entries
)
3339 gfc_error ("ENTRY '%s' at %L cannot be called recursively, as"
3340 " subroutine '%s' is not RECURSIVE",
3341 csym
->name
, &c
->loc
, csym
->ns
->entries
->sym
->name
);
3343 gfc_error ("SUBROUTINE '%s' at %L cannot be called recursively, as it"
3344 " is not RECURSIVE", csym
->name
, &c
->loc
);
3349 /* Switch off assumed size checking and do this again for certain kinds
3350 of procedure, once the procedure itself is resolved. */
3351 need_full_assumed_size
++;
3354 ptype
= csym
->attr
.proc
;
3356 no_formal_args
= csym
&& is_external_proc (csym
) && csym
->formal
== NULL
;
3357 if (resolve_actual_arglist (c
->ext
.actual
, ptype
,
3358 no_formal_args
) == FAILURE
)
3361 /* Resume assumed_size checking. */
3362 need_full_assumed_size
--;
3364 /* If external, check for usage. */
3365 if (csym
&& is_external_proc (csym
))
3366 resolve_global_procedure (csym
, &c
->loc
, &c
->ext
.actual
, 1);
3369 if (c
->resolved_sym
== NULL
)
3371 c
->resolved_isym
= NULL
;
3372 switch (procedure_kind (csym
))
3375 t
= resolve_generic_s (c
);
3378 case PTYPE_SPECIFIC
:
3379 t
= resolve_specific_s (c
);
3383 t
= resolve_unknown_s (c
);
3387 gfc_internal_error ("resolve_subroutine(): bad function type");
3391 /* Some checks of elemental subroutine actual arguments. */
3392 if (resolve_elemental_actual (NULL
, c
) == FAILURE
)
3395 if (t
== SUCCESS
&& !(c
->resolved_sym
&& c
->resolved_sym
->attr
.elemental
))
3396 find_noncopying_intrinsics (c
->resolved_sym
, c
->ext
.actual
);
3401 /* Compare the shapes of two arrays that have non-NULL shapes. If both
3402 op1->shape and op2->shape are non-NULL return SUCCESS if their shapes
3403 match. If both op1->shape and op2->shape are non-NULL return FAILURE
3404 if their shapes do not match. If either op1->shape or op2->shape is
3405 NULL, return SUCCESS. */
3408 compare_shapes (gfc_expr
*op1
, gfc_expr
*op2
)
3415 if (op1
->shape
!= NULL
&& op2
->shape
!= NULL
)
3417 for (i
= 0; i
< op1
->rank
; i
++)
3419 if (mpz_cmp (op1
->shape
[i
], op2
->shape
[i
]) != 0)
3421 gfc_error ("Shapes for operands at %L and %L are not conformable",
3422 &op1
->where
, &op2
->where
);
3433 /* Resolve an operator expression node. This can involve replacing the
3434 operation with a user defined function call. */
3437 resolve_operator (gfc_expr
*e
)
3439 gfc_expr
*op1
, *op2
;
3441 bool dual_locus_error
;
3444 /* Resolve all subnodes-- give them types. */
3446 switch (e
->value
.op
.op
)
3449 if (gfc_resolve_expr (e
->value
.op
.op2
) == FAILURE
)
3452 /* Fall through... */
3455 case INTRINSIC_UPLUS
:
3456 case INTRINSIC_UMINUS
:
3457 case INTRINSIC_PARENTHESES
:
3458 if (gfc_resolve_expr (e
->value
.op
.op1
) == FAILURE
)
3463 /* Typecheck the new node. */
3465 op1
= e
->value
.op
.op1
;
3466 op2
= e
->value
.op
.op2
;
3467 dual_locus_error
= false;
3469 if ((op1
&& op1
->expr_type
== EXPR_NULL
)
3470 || (op2
&& op2
->expr_type
== EXPR_NULL
))
3472 sprintf (msg
, _("Invalid context for NULL() pointer at %%L"));
3476 switch (e
->value
.op
.op
)
3478 case INTRINSIC_UPLUS
:
3479 case INTRINSIC_UMINUS
:
3480 if (op1
->ts
.type
== BT_INTEGER
3481 || op1
->ts
.type
== BT_REAL
3482 || op1
->ts
.type
== BT_COMPLEX
)
3488 sprintf (msg
, _("Operand of unary numeric operator '%s' at %%L is %s"),
3489 gfc_op2string (e
->value
.op
.op
), gfc_typename (&e
->ts
));
3492 case INTRINSIC_PLUS
:
3493 case INTRINSIC_MINUS
:
3494 case INTRINSIC_TIMES
:
3495 case INTRINSIC_DIVIDE
:
3496 case INTRINSIC_POWER
:
3497 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3499 gfc_type_convert_binary (e
, 1);
3504 _("Operands of binary numeric operator '%s' at %%L are %s/%s"),
3505 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3506 gfc_typename (&op2
->ts
));
3509 case INTRINSIC_CONCAT
:
3510 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3511 && op1
->ts
.kind
== op2
->ts
.kind
)
3513 e
->ts
.type
= BT_CHARACTER
;
3514 e
->ts
.kind
= op1
->ts
.kind
;
3519 _("Operands of string concatenation operator at %%L are %s/%s"),
3520 gfc_typename (&op1
->ts
), gfc_typename (&op2
->ts
));
3526 case INTRINSIC_NEQV
:
3527 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3529 e
->ts
.type
= BT_LOGICAL
;
3530 e
->ts
.kind
= gfc_kind_max (op1
, op2
);
3531 if (op1
->ts
.kind
< e
->ts
.kind
)
3532 gfc_convert_type (op1
, &e
->ts
, 2);
3533 else if (op2
->ts
.kind
< e
->ts
.kind
)
3534 gfc_convert_type (op2
, &e
->ts
, 2);
3538 sprintf (msg
, _("Operands of logical operator '%s' at %%L are %s/%s"),
3539 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3540 gfc_typename (&op2
->ts
));
3545 if (op1
->ts
.type
== BT_LOGICAL
)
3547 e
->ts
.type
= BT_LOGICAL
;
3548 e
->ts
.kind
= op1
->ts
.kind
;
3552 sprintf (msg
, _("Operand of .not. operator at %%L is %s"),
3553 gfc_typename (&op1
->ts
));
3557 case INTRINSIC_GT_OS
:
3559 case INTRINSIC_GE_OS
:
3561 case INTRINSIC_LT_OS
:
3563 case INTRINSIC_LE_OS
:
3564 if (op1
->ts
.type
== BT_COMPLEX
|| op2
->ts
.type
== BT_COMPLEX
)
3566 strcpy (msg
, _("COMPLEX quantities cannot be compared at %L"));
3570 /* Fall through... */
3573 case INTRINSIC_EQ_OS
:
3575 case INTRINSIC_NE_OS
:
3576 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3577 && op1
->ts
.kind
== op2
->ts
.kind
)
3579 e
->ts
.type
= BT_LOGICAL
;
3580 e
->ts
.kind
= gfc_default_logical_kind
;
3584 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3586 gfc_type_convert_binary (e
, 1);
3588 e
->ts
.type
= BT_LOGICAL
;
3589 e
->ts
.kind
= gfc_default_logical_kind
;
3593 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3595 _("Logicals at %%L must be compared with %s instead of %s"),
3596 (e
->value
.op
.op
== INTRINSIC_EQ
3597 || e
->value
.op
.op
== INTRINSIC_EQ_OS
)
3598 ? ".eqv." : ".neqv.", gfc_op2string (e
->value
.op
.op
));
3601 _("Operands of comparison operator '%s' at %%L are %s/%s"),
3602 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3603 gfc_typename (&op2
->ts
));
3607 case INTRINSIC_USER
:
3608 if (e
->value
.op
.uop
->op
== NULL
)
3609 sprintf (msg
, _("Unknown operator '%s' at %%L"), e
->value
.op
.uop
->name
);
3610 else if (op2
== NULL
)
3611 sprintf (msg
, _("Operand of user operator '%s' at %%L is %s"),
3612 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
));
3614 sprintf (msg
, _("Operands of user operator '%s' at %%L are %s/%s"),
3615 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
),
3616 gfc_typename (&op2
->ts
));
3620 case INTRINSIC_PARENTHESES
:
3622 if (e
->ts
.type
== BT_CHARACTER
)
3623 e
->ts
.u
.cl
= op1
->ts
.u
.cl
;
3627 gfc_internal_error ("resolve_operator(): Bad intrinsic");
3630 /* Deal with arrayness of an operand through an operator. */
3634 switch (e
->value
.op
.op
)
3636 case INTRINSIC_PLUS
:
3637 case INTRINSIC_MINUS
:
3638 case INTRINSIC_TIMES
:
3639 case INTRINSIC_DIVIDE
:
3640 case INTRINSIC_POWER
:
3641 case INTRINSIC_CONCAT
:
3645 case INTRINSIC_NEQV
:
3647 case INTRINSIC_EQ_OS
:
3649 case INTRINSIC_NE_OS
:
3651 case INTRINSIC_GT_OS
:
3653 case INTRINSIC_GE_OS
:
3655 case INTRINSIC_LT_OS
:
3657 case INTRINSIC_LE_OS
:
3659 if (op1
->rank
== 0 && op2
->rank
== 0)
3662 if (op1
->rank
== 0 && op2
->rank
!= 0)
3664 e
->rank
= op2
->rank
;
3666 if (e
->shape
== NULL
)
3667 e
->shape
= gfc_copy_shape (op2
->shape
, op2
->rank
);
3670 if (op1
->rank
!= 0 && op2
->rank
== 0)
3672 e
->rank
= op1
->rank
;
3674 if (e
->shape
== NULL
)
3675 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3678 if (op1
->rank
!= 0 && op2
->rank
!= 0)
3680 if (op1
->rank
== op2
->rank
)
3682 e
->rank
= op1
->rank
;
3683 if (e
->shape
== NULL
)
3685 t
= compare_shapes (op1
, op2
);
3689 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3694 /* Allow higher level expressions to work. */
3697 /* Try user-defined operators, and otherwise throw an error. */
3698 dual_locus_error
= true;
3700 _("Inconsistent ranks for operator at %%L and %%L"));
3707 case INTRINSIC_PARENTHESES
:
3709 case INTRINSIC_UPLUS
:
3710 case INTRINSIC_UMINUS
:
3711 /* Simply copy arrayness attribute */
3712 e
->rank
= op1
->rank
;
3714 if (e
->shape
== NULL
)
3715 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3723 /* Attempt to simplify the expression. */
3726 t
= gfc_simplify_expr (e
, 0);
3727 /* Some calls do not succeed in simplification and return FAILURE
3728 even though there is no error; e.g. variable references to
3729 PARAMETER arrays. */
3730 if (!gfc_is_constant_expr (e
))
3739 if (gfc_extend_expr (e
, &real_error
) == SUCCESS
)
3746 if (dual_locus_error
)
3747 gfc_error (msg
, &op1
->where
, &op2
->where
);
3749 gfc_error (msg
, &e
->where
);
3755 /************** Array resolution subroutines **************/
3758 { CMP_LT
, CMP_EQ
, CMP_GT
, CMP_UNKNOWN
}
3761 /* Compare two integer expressions. */
3764 compare_bound (gfc_expr
*a
, gfc_expr
*b
)
3768 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
3769 || b
== NULL
|| b
->expr_type
!= EXPR_CONSTANT
)
3772 /* If either of the types isn't INTEGER, we must have
3773 raised an error earlier. */
3775 if (a
->ts
.type
!= BT_INTEGER
|| b
->ts
.type
!= BT_INTEGER
)
3778 i
= mpz_cmp (a
->value
.integer
, b
->value
.integer
);
3788 /* Compare an integer expression with an integer. */
3791 compare_bound_int (gfc_expr
*a
, int b
)
3795 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3798 if (a
->ts
.type
!= BT_INTEGER
)
3799 gfc_internal_error ("compare_bound_int(): Bad expression");
3801 i
= mpz_cmp_si (a
->value
.integer
, b
);
3811 /* Compare an integer expression with a mpz_t. */
3814 compare_bound_mpz_t (gfc_expr
*a
, mpz_t b
)
3818 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3821 if (a
->ts
.type
!= BT_INTEGER
)
3822 gfc_internal_error ("compare_bound_int(): Bad expression");
3824 i
= mpz_cmp (a
->value
.integer
, b
);
3834 /* Compute the last value of a sequence given by a triplet.
3835 Return 0 if it wasn't able to compute the last value, or if the
3836 sequence if empty, and 1 otherwise. */
3839 compute_last_value_for_triplet (gfc_expr
*start
, gfc_expr
*end
,
3840 gfc_expr
*stride
, mpz_t last
)
3844 if (start
== NULL
|| start
->expr_type
!= EXPR_CONSTANT
3845 || end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
3846 || (stride
!= NULL
&& stride
->expr_type
!= EXPR_CONSTANT
))
3849 if (start
->ts
.type
!= BT_INTEGER
|| end
->ts
.type
!= BT_INTEGER
3850 || (stride
!= NULL
&& stride
->ts
.type
!= BT_INTEGER
))
3853 if (stride
== NULL
|| compare_bound_int(stride
, 1) == CMP_EQ
)
3855 if (compare_bound (start
, end
) == CMP_GT
)
3857 mpz_set (last
, end
->value
.integer
);
3861 if (compare_bound_int (stride
, 0) == CMP_GT
)
3863 /* Stride is positive */
3864 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) > 0)
3869 /* Stride is negative */
3870 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) < 0)
3875 mpz_sub (rem
, end
->value
.integer
, start
->value
.integer
);
3876 mpz_tdiv_r (rem
, rem
, stride
->value
.integer
);
3877 mpz_sub (last
, end
->value
.integer
, rem
);
3884 /* Compare a single dimension of an array reference to the array
3888 check_dimension (int i
, gfc_array_ref
*ar
, gfc_array_spec
*as
)
3892 if (ar
->dimen_type
[i
] == DIMEN_STAR
)
3894 gcc_assert (ar
->stride
[i
] == NULL
);
3895 /* This implies [*] as [*:] and [*:3] are not possible. */
3896 if (ar
->start
[i
] == NULL
)
3898 gcc_assert (ar
->end
[i
] == NULL
);
3903 /* Given start, end and stride values, calculate the minimum and
3904 maximum referenced indexes. */
3906 switch (ar
->dimen_type
[i
])
3913 if (compare_bound (ar
->start
[i
], as
->lower
[i
]) == CMP_LT
)
3916 gfc_warning ("Array reference at %L is out of bounds "
3917 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
3918 mpz_get_si (ar
->start
[i
]->value
.integer
),
3919 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
3921 gfc_warning ("Array reference at %L is out of bounds "
3922 "(%ld < %ld) in codimension %d", &ar
->c_where
[i
],
3923 mpz_get_si (ar
->start
[i
]->value
.integer
),
3924 mpz_get_si (as
->lower
[i
]->value
.integer
),
3928 if (compare_bound (ar
->start
[i
], as
->upper
[i
]) == CMP_GT
)
3931 gfc_warning ("Array reference at %L is out of bounds "
3932 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
3933 mpz_get_si (ar
->start
[i
]->value
.integer
),
3934 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
3936 gfc_warning ("Array reference at %L is out of bounds "
3937 "(%ld > %ld) in codimension %d", &ar
->c_where
[i
],
3938 mpz_get_si (ar
->start
[i
]->value
.integer
),
3939 mpz_get_si (as
->upper
[i
]->value
.integer
),
3948 #define AR_START (ar->start[i] ? ar->start[i] : as->lower[i])
3949 #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i])
3951 comparison comp_start_end
= compare_bound (AR_START
, AR_END
);
3953 /* Check for zero stride, which is not allowed. */
3954 if (compare_bound_int (ar
->stride
[i
], 0) == CMP_EQ
)
3956 gfc_error ("Illegal stride of zero at %L", &ar
->c_where
[i
]);
3960 /* if start == len || (stride > 0 && start < len)
3961 || (stride < 0 && start > len),
3962 then the array section contains at least one element. In this
3963 case, there is an out-of-bounds access if
3964 (start < lower || start > upper). */
3965 if (compare_bound (AR_START
, AR_END
) == CMP_EQ
3966 || ((compare_bound_int (ar
->stride
[i
], 0) == CMP_GT
3967 || ar
->stride
[i
] == NULL
) && comp_start_end
== CMP_LT
)
3968 || (compare_bound_int (ar
->stride
[i
], 0) == CMP_LT
3969 && comp_start_end
== CMP_GT
))
3971 if (compare_bound (AR_START
, as
->lower
[i
]) == CMP_LT
)
3973 gfc_warning ("Lower array reference at %L is out of bounds "
3974 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
3975 mpz_get_si (AR_START
->value
.integer
),
3976 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
3979 if (compare_bound (AR_START
, as
->upper
[i
]) == CMP_GT
)
3981 gfc_warning ("Lower array reference at %L is out of bounds "
3982 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
3983 mpz_get_si (AR_START
->value
.integer
),
3984 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
3989 /* If we can compute the highest index of the array section,
3990 then it also has to be between lower and upper. */
3991 mpz_init (last_value
);
3992 if (compute_last_value_for_triplet (AR_START
, AR_END
, ar
->stride
[i
],
3995 if (compare_bound_mpz_t (as
->lower
[i
], last_value
) == CMP_GT
)
3997 gfc_warning ("Upper array reference at %L is out of bounds "
3998 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
3999 mpz_get_si (last_value
),
4000 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4001 mpz_clear (last_value
);
4004 if (compare_bound_mpz_t (as
->upper
[i
], last_value
) == CMP_LT
)
4006 gfc_warning ("Upper array reference at %L is out of bounds "
4007 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4008 mpz_get_si (last_value
),
4009 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4010 mpz_clear (last_value
);
4014 mpz_clear (last_value
);
4022 gfc_internal_error ("check_dimension(): Bad array reference");
4029 /* Compare an array reference with an array specification. */
4032 compare_spec_to_ref (gfc_array_ref
*ar
)
4039 /* TODO: Full array sections are only allowed as actual parameters. */
4040 if (as
->type
== AS_ASSUMED_SIZE
4041 && (/*ar->type == AR_FULL
4042 ||*/ (ar
->type
== AR_SECTION
4043 && ar
->dimen_type
[i
] == DIMEN_RANGE
&& ar
->end
[i
] == NULL
)))
4045 gfc_error ("Rightmost upper bound of assumed size array section "
4046 "not specified at %L", &ar
->where
);
4050 if (ar
->type
== AR_FULL
)
4053 if (as
->rank
!= ar
->dimen
)
4055 gfc_error ("Rank mismatch in array reference at %L (%d/%d)",
4056 &ar
->where
, ar
->dimen
, as
->rank
);
4060 /* ar->codimen == 0 is a local array. */
4061 if (as
->corank
!= ar
->codimen
&& ar
->codimen
!= 0)
4063 gfc_error ("Coindex rank mismatch in array reference at %L (%d/%d)",
4064 &ar
->where
, ar
->codimen
, as
->corank
);
4068 for (i
= 0; i
< as
->rank
; i
++)
4069 if (check_dimension (i
, ar
, as
) == FAILURE
)
4072 /* Local access has no coarray spec. */
4073 if (ar
->codimen
!= 0)
4074 for (i
= as
->rank
; i
< as
->rank
+ as
->corank
; i
++)
4076 if (ar
->dimen_type
[i
] != DIMEN_ELEMENT
&& !ar
->in_allocate
)
4078 gfc_error ("Coindex of codimension %d must be a scalar at %L",
4079 i
+ 1 - as
->rank
, &ar
->where
);
4082 if (check_dimension (i
, ar
, as
) == FAILURE
)
4090 /* Resolve one part of an array index. */
4093 gfc_resolve_index_1 (gfc_expr
*index
, int check_scalar
,
4094 int force_index_integer_kind
)
4101 if (gfc_resolve_expr (index
) == FAILURE
)
4104 if (check_scalar
&& index
->rank
!= 0)
4106 gfc_error ("Array index at %L must be scalar", &index
->where
);
4110 if (index
->ts
.type
!= BT_INTEGER
&& index
->ts
.type
!= BT_REAL
)
4112 gfc_error ("Array index at %L must be of INTEGER type, found %s",
4113 &index
->where
, gfc_basic_typename (index
->ts
.type
));
4117 if (index
->ts
.type
== BT_REAL
)
4118 if (gfc_notify_std (GFC_STD_LEGACY
, "Extension: REAL array index at %L",
4119 &index
->where
) == FAILURE
)
4122 if ((index
->ts
.kind
!= gfc_index_integer_kind
4123 && force_index_integer_kind
)
4124 || index
->ts
.type
!= BT_INTEGER
)
4127 ts
.type
= BT_INTEGER
;
4128 ts
.kind
= gfc_index_integer_kind
;
4130 gfc_convert_type_warn (index
, &ts
, 2, 0);
4136 /* Resolve one part of an array index. */
4139 gfc_resolve_index (gfc_expr
*index
, int check_scalar
)
4141 return gfc_resolve_index_1 (index
, check_scalar
, 1);
4144 /* Resolve a dim argument to an intrinsic function. */
4147 gfc_resolve_dim_arg (gfc_expr
*dim
)
4152 if (gfc_resolve_expr (dim
) == FAILURE
)
4157 gfc_error ("Argument dim at %L must be scalar", &dim
->where
);
4162 if (dim
->ts
.type
!= BT_INTEGER
)
4164 gfc_error ("Argument dim at %L must be of INTEGER type", &dim
->where
);
4168 if (dim
->ts
.kind
!= gfc_index_integer_kind
)
4173 ts
.type
= BT_INTEGER
;
4174 ts
.kind
= gfc_index_integer_kind
;
4176 gfc_convert_type_warn (dim
, &ts
, 2, 0);
4182 /* Given an expression that contains array references, update those array
4183 references to point to the right array specifications. While this is
4184 filled in during matching, this information is difficult to save and load
4185 in a module, so we take care of it here.
4187 The idea here is that the original array reference comes from the
4188 base symbol. We traverse the list of reference structures, setting
4189 the stored reference to references. Component references can
4190 provide an additional array specification. */
4193 find_array_spec (gfc_expr
*e
)
4197 gfc_symbol
*derived
;
4200 if (e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
)
4201 as
= CLASS_DATA (e
->symtree
->n
.sym
)->as
;
4203 as
= e
->symtree
->n
.sym
->as
;
4206 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4211 gfc_internal_error ("find_array_spec(): Missing spec");
4218 if (derived
== NULL
)
4219 derived
= e
->symtree
->n
.sym
->ts
.u
.derived
;
4221 if (derived
->attr
.is_class
)
4222 derived
= derived
->components
->ts
.u
.derived
;
4224 c
= derived
->components
;
4226 for (; c
; c
= c
->next
)
4227 if (c
== ref
->u
.c
.component
)
4229 /* Track the sequence of component references. */
4230 if (c
->ts
.type
== BT_DERIVED
)
4231 derived
= c
->ts
.u
.derived
;
4236 gfc_internal_error ("find_array_spec(): Component not found");
4238 if (c
->attr
.dimension
)
4241 gfc_internal_error ("find_array_spec(): unused as(1)");
4252 gfc_internal_error ("find_array_spec(): unused as(2)");
4256 /* Resolve an array reference. */
4259 resolve_array_ref (gfc_array_ref
*ar
)
4261 int i
, check_scalar
;
4264 for (i
= 0; i
< ar
->dimen
+ ar
->codimen
; i
++)
4266 check_scalar
= ar
->dimen_type
[i
] == DIMEN_RANGE
;
4268 /* Do not force gfc_index_integer_kind for the start. We can
4269 do fine with any integer kind. This avoids temporary arrays
4270 created for indexing with a vector. */
4271 if (gfc_resolve_index_1 (ar
->start
[i
], check_scalar
, 0) == FAILURE
)
4273 if (gfc_resolve_index (ar
->end
[i
], check_scalar
) == FAILURE
)
4275 if (gfc_resolve_index (ar
->stride
[i
], check_scalar
) == FAILURE
)
4280 if (ar
->dimen_type
[i
] == DIMEN_UNKNOWN
)
4284 ar
->dimen_type
[i
] = DIMEN_ELEMENT
;
4288 ar
->dimen_type
[i
] = DIMEN_VECTOR
;
4289 if (e
->expr_type
== EXPR_VARIABLE
4290 && e
->symtree
->n
.sym
->ts
.type
== BT_DERIVED
)
4291 ar
->start
[i
] = gfc_get_parentheses (e
);
4295 gfc_error ("Array index at %L is an array of rank %d",
4296 &ar
->c_where
[i
], e
->rank
);
4301 if (ar
->type
== AR_FULL
&& ar
->as
->rank
== 0)
4302 ar
->type
= AR_ELEMENT
;
4304 /* If the reference type is unknown, figure out what kind it is. */
4306 if (ar
->type
== AR_UNKNOWN
)
4308 ar
->type
= AR_ELEMENT
;
4309 for (i
= 0; i
< ar
->dimen
; i
++)
4310 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4311 || ar
->dimen_type
[i
] == DIMEN_VECTOR
)
4313 ar
->type
= AR_SECTION
;
4318 if (!ar
->as
->cray_pointee
&& compare_spec_to_ref (ar
) == FAILURE
)
4326 resolve_substring (gfc_ref
*ref
)
4328 int k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
4330 if (ref
->u
.ss
.start
!= NULL
)
4332 if (gfc_resolve_expr (ref
->u
.ss
.start
) == FAILURE
)
4335 if (ref
->u
.ss
.start
->ts
.type
!= BT_INTEGER
)
4337 gfc_error ("Substring start index at %L must be of type INTEGER",
4338 &ref
->u
.ss
.start
->where
);
4342 if (ref
->u
.ss
.start
->rank
!= 0)
4344 gfc_error ("Substring start index at %L must be scalar",
4345 &ref
->u
.ss
.start
->where
);
4349 if (compare_bound_int (ref
->u
.ss
.start
, 1) == CMP_LT
4350 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4351 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4353 gfc_error ("Substring start index at %L is less than one",
4354 &ref
->u
.ss
.start
->where
);
4359 if (ref
->u
.ss
.end
!= NULL
)
4361 if (gfc_resolve_expr (ref
->u
.ss
.end
) == FAILURE
)
4364 if (ref
->u
.ss
.end
->ts
.type
!= BT_INTEGER
)
4366 gfc_error ("Substring end index at %L must be of type INTEGER",
4367 &ref
->u
.ss
.end
->where
);
4371 if (ref
->u
.ss
.end
->rank
!= 0)
4373 gfc_error ("Substring end index at %L must be scalar",
4374 &ref
->u
.ss
.end
->where
);
4378 if (ref
->u
.ss
.length
!= NULL
4379 && compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.length
->length
) == CMP_GT
4380 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4381 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4383 gfc_error ("Substring end index at %L exceeds the string length",
4384 &ref
->u
.ss
.start
->where
);
4388 if (compare_bound_mpz_t (ref
->u
.ss
.end
,
4389 gfc_integer_kinds
[k
].huge
) == CMP_GT
4390 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4391 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4393 gfc_error ("Substring end index at %L is too large",
4394 &ref
->u
.ss
.end
->where
);
4403 /* This function supplies missing substring charlens. */
4406 gfc_resolve_substring_charlen (gfc_expr
*e
)
4409 gfc_expr
*start
, *end
;
4411 for (char_ref
= e
->ref
; char_ref
; char_ref
= char_ref
->next
)
4412 if (char_ref
->type
== REF_SUBSTRING
)
4418 gcc_assert (char_ref
->next
== NULL
);
4422 if (e
->ts
.u
.cl
->length
)
4423 gfc_free_expr (e
->ts
.u
.cl
->length
);
4424 else if (e
->expr_type
== EXPR_VARIABLE
4425 && e
->symtree
->n
.sym
->attr
.dummy
)
4429 e
->ts
.type
= BT_CHARACTER
;
4430 e
->ts
.kind
= gfc_default_character_kind
;
4433 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
4435 if (char_ref
->u
.ss
.start
)
4436 start
= gfc_copy_expr (char_ref
->u
.ss
.start
);
4438 start
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
4440 if (char_ref
->u
.ss
.end
)
4441 end
= gfc_copy_expr (char_ref
->u
.ss
.end
);
4442 else if (e
->expr_type
== EXPR_VARIABLE
)
4443 end
= gfc_copy_expr (e
->symtree
->n
.sym
->ts
.u
.cl
->length
);
4450 /* Length = (end - start +1). */
4451 e
->ts
.u
.cl
->length
= gfc_subtract (end
, start
);
4452 e
->ts
.u
.cl
->length
= gfc_add (e
->ts
.u
.cl
->length
,
4453 gfc_get_int_expr (gfc_default_integer_kind
,
4456 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
4457 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
4459 /* Make sure that the length is simplified. */
4460 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 1);
4461 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
4465 /* Resolve subtype references. */
4468 resolve_ref (gfc_expr
*expr
)
4470 int current_part_dimension
, n_components
, seen_part_dimension
;
4473 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4474 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.as
== NULL
)
4476 find_array_spec (expr
);
4480 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4484 if (resolve_array_ref (&ref
->u
.ar
) == FAILURE
)
4492 resolve_substring (ref
);
4496 /* Check constraints on part references. */
4498 current_part_dimension
= 0;
4499 seen_part_dimension
= 0;
4502 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4507 switch (ref
->u
.ar
.type
)
4510 /* Coarray scalar. */
4511 if (ref
->u
.ar
.as
->rank
== 0)
4513 current_part_dimension
= 0;
4518 current_part_dimension
= 1;
4522 current_part_dimension
= 0;
4526 gfc_internal_error ("resolve_ref(): Bad array reference");
4532 if (current_part_dimension
|| seen_part_dimension
)
4535 if (ref
->u
.c
.component
->attr
.pointer
4536 || ref
->u
.c
.component
->attr
.proc_pointer
)
4538 gfc_error ("Component to the right of a part reference "
4539 "with nonzero rank must not have the POINTER "
4540 "attribute at %L", &expr
->where
);
4543 else if (ref
->u
.c
.component
->attr
.allocatable
)
4545 gfc_error ("Component to the right of a part reference "
4546 "with nonzero rank must not have the ALLOCATABLE "
4547 "attribute at %L", &expr
->where
);
4559 if (((ref
->type
== REF_COMPONENT
&& n_components
> 1)
4560 || ref
->next
== NULL
)
4561 && current_part_dimension
4562 && seen_part_dimension
)
4564 gfc_error ("Two or more part references with nonzero rank must "
4565 "not be specified at %L", &expr
->where
);
4569 if (ref
->type
== REF_COMPONENT
)
4571 if (current_part_dimension
)
4572 seen_part_dimension
= 1;
4574 /* reset to make sure */
4575 current_part_dimension
= 0;
4583 /* Given an expression, determine its shape. This is easier than it sounds.
4584 Leaves the shape array NULL if it is not possible to determine the shape. */
4587 expression_shape (gfc_expr
*e
)
4589 mpz_t array
[GFC_MAX_DIMENSIONS
];
4592 if (e
->rank
== 0 || e
->shape
!= NULL
)
4595 for (i
= 0; i
< e
->rank
; i
++)
4596 if (gfc_array_dimen_size (e
, i
, &array
[i
]) == FAILURE
)
4599 e
->shape
= gfc_get_shape (e
->rank
);
4601 memcpy (e
->shape
, array
, e
->rank
* sizeof (mpz_t
));
4606 for (i
--; i
>= 0; i
--)
4607 mpz_clear (array
[i
]);
4611 /* Given a variable expression node, compute the rank of the expression by
4612 examining the base symbol and any reference structures it may have. */
4615 expression_rank (gfc_expr
*e
)
4620 /* Just to make sure, because EXPR_COMPCALL's also have an e->ref and that
4621 could lead to serious confusion... */
4622 gcc_assert (e
->expr_type
!= EXPR_COMPCALL
);
4626 if (e
->expr_type
== EXPR_ARRAY
)
4628 /* Constructors can have a rank different from one via RESHAPE(). */
4630 if (e
->symtree
== NULL
)
4636 e
->rank
= (e
->symtree
->n
.sym
->as
== NULL
)
4637 ? 0 : e
->symtree
->n
.sym
->as
->rank
;
4643 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4645 if (ref
->type
!= REF_ARRAY
)
4648 if (ref
->u
.ar
.type
== AR_FULL
)
4650 rank
= ref
->u
.ar
.as
->rank
;
4654 if (ref
->u
.ar
.type
== AR_SECTION
)
4656 /* Figure out the rank of the section. */
4658 gfc_internal_error ("expression_rank(): Two array specs");
4660 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
4661 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_RANGE
4662 || ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
4672 expression_shape (e
);
4676 /* Resolve a variable expression. */
4679 resolve_variable (gfc_expr
*e
)
4686 if (e
->symtree
== NULL
)
4689 if (e
->ref
&& resolve_ref (e
) == FAILURE
)
4692 sym
= e
->symtree
->n
.sym
;
4693 if (sym
->attr
.flavor
== FL_PROCEDURE
4694 && (!sym
->attr
.function
4695 || (sym
->attr
.function
&& sym
->result
4696 && sym
->result
->attr
.proc_pointer
4697 && !sym
->result
->attr
.function
)))
4699 e
->ts
.type
= BT_PROCEDURE
;
4700 goto resolve_procedure
;
4703 if (sym
->ts
.type
!= BT_UNKNOWN
)
4704 gfc_variable_attr (e
, &e
->ts
);
4707 /* Must be a simple variable reference. */
4708 if (gfc_set_default_type (sym
, 1, sym
->ns
) == FAILURE
)
4713 if (check_assumed_size_reference (sym
, e
))
4716 /* Deal with forward references to entries during resolve_code, to
4717 satisfy, at least partially, 12.5.2.5. */
4718 if (gfc_current_ns
->entries
4719 && current_entry_id
== sym
->entry_id
4722 && cs_base
->current
->op
!= EXEC_ENTRY
)
4724 gfc_entry_list
*entry
;
4725 gfc_formal_arglist
*formal
;
4729 /* If the symbol is a dummy... */
4730 if (sym
->attr
.dummy
&& sym
->ns
== gfc_current_ns
)
4732 entry
= gfc_current_ns
->entries
;
4735 /* ...test if the symbol is a parameter of previous entries. */
4736 for (; entry
&& entry
->id
<= current_entry_id
; entry
= entry
->next
)
4737 for (formal
= entry
->sym
->formal
; formal
; formal
= formal
->next
)
4739 if (formal
->sym
&& sym
->name
== formal
->sym
->name
)
4743 /* If it has not been seen as a dummy, this is an error. */
4746 if (specification_expr
)
4747 gfc_error ("Variable '%s', used in a specification expression"
4748 ", is referenced at %L before the ENTRY statement "
4749 "in which it is a parameter",
4750 sym
->name
, &cs_base
->current
->loc
);
4752 gfc_error ("Variable '%s' is used at %L before the ENTRY "
4753 "statement in which it is a parameter",
4754 sym
->name
, &cs_base
->current
->loc
);
4759 /* Now do the same check on the specification expressions. */
4760 specification_expr
= 1;
4761 if (sym
->ts
.type
== BT_CHARACTER
4762 && gfc_resolve_expr (sym
->ts
.u
.cl
->length
) == FAILURE
)
4766 for (n
= 0; n
< sym
->as
->rank
; n
++)
4768 specification_expr
= 1;
4769 if (gfc_resolve_expr (sym
->as
->lower
[n
]) == FAILURE
)
4771 specification_expr
= 1;
4772 if (gfc_resolve_expr (sym
->as
->upper
[n
]) == FAILURE
)
4775 specification_expr
= 0;
4778 /* Update the symbol's entry level. */
4779 sym
->entry_id
= current_entry_id
+ 1;
4782 /* If a symbol has been host_associated mark it. This is used latter,
4783 to identify if aliasing is possible via host association. */
4784 if (sym
->attr
.flavor
== FL_VARIABLE
4785 && gfc_current_ns
->parent
4786 && (gfc_current_ns
->parent
== sym
->ns
4787 || (gfc_current_ns
->parent
->parent
4788 && gfc_current_ns
->parent
->parent
== sym
->ns
)))
4789 sym
->attr
.host_assoc
= 1;
4792 if (t
== SUCCESS
&& resolve_procedure_expression (e
) == FAILURE
)
4795 /* F2008, C617 and C1229. */
4796 if (!inquiry_argument
&& (e
->ts
.type
== BT_CLASS
|| e
->ts
.type
== BT_DERIVED
)
4797 && gfc_is_coindexed (e
))
4799 gfc_ref
*ref
, *ref2
= NULL
;
4801 if (e
->ts
.type
== BT_CLASS
)
4803 gfc_error ("Polymorphic subobject of coindexed object at %L",
4808 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4810 if (ref
->type
== REF_COMPONENT
)
4812 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
4816 for ( ; ref
; ref
= ref
->next
)
4817 if (ref
->type
== REF_COMPONENT
)
4820 /* Expression itself is coindexed object. */
4824 c
= ref2
? ref2
->u
.c
.component
: e
->symtree
->n
.sym
->components
;
4825 for ( ; c
; c
= c
->next
)
4826 if (c
->attr
.allocatable
&& c
->ts
.type
== BT_CLASS
)
4828 gfc_error ("Coindexed object with polymorphic allocatable "
4829 "subcomponent at %L", &e
->where
);
4840 /* Checks to see that the correct symbol has been host associated.
4841 The only situation where this arises is that in which a twice
4842 contained function is parsed after the host association is made.
4843 Therefore, on detecting this, change the symbol in the expression
4844 and convert the array reference into an actual arglist if the old
4845 symbol is a variable. */
4847 check_host_association (gfc_expr
*e
)
4849 gfc_symbol
*sym
, *old_sym
;
4853 gfc_actual_arglist
*arg
, *tail
= NULL
;
4854 bool retval
= e
->expr_type
== EXPR_FUNCTION
;
4856 /* If the expression is the result of substitution in
4857 interface.c(gfc_extend_expr) because there is no way in
4858 which the host association can be wrong. */
4859 if (e
->symtree
== NULL
4860 || e
->symtree
->n
.sym
== NULL
4861 || e
->user_operator
)
4864 old_sym
= e
->symtree
->n
.sym
;
4866 if (gfc_current_ns
->parent
4867 && old_sym
->ns
!= gfc_current_ns
)
4869 /* Use the 'USE' name so that renamed module symbols are
4870 correctly handled. */
4871 gfc_find_symbol (e
->symtree
->name
, gfc_current_ns
, 1, &sym
);
4873 if (sym
&& old_sym
!= sym
4874 && sym
->ts
.type
== old_sym
->ts
.type
4875 && sym
->attr
.flavor
== FL_PROCEDURE
4876 && sym
->attr
.contained
)
4878 /* Clear the shape, since it might not be valid. */
4879 if (e
->shape
!= NULL
)
4881 for (n
= 0; n
< e
->rank
; n
++)
4882 mpz_clear (e
->shape
[n
]);
4884 gfc_free (e
->shape
);
4887 /* Give the expression the right symtree! */
4888 gfc_find_sym_tree (e
->symtree
->name
, NULL
, 1, &st
);
4889 gcc_assert (st
!= NULL
);
4891 if (old_sym
->attr
.flavor
== FL_PROCEDURE
4892 || e
->expr_type
== EXPR_FUNCTION
)
4894 /* Original was function so point to the new symbol, since
4895 the actual argument list is already attached to the
4897 e
->value
.function
.esym
= NULL
;
4902 /* Original was variable so convert array references into
4903 an actual arglist. This does not need any checking now
4904 since gfc_resolve_function will take care of it. */
4905 e
->value
.function
.actual
= NULL
;
4906 e
->expr_type
= EXPR_FUNCTION
;
4909 /* Ambiguity will not arise if the array reference is not
4910 the last reference. */
4911 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4912 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
4915 gcc_assert (ref
->type
== REF_ARRAY
);
4917 /* Grab the start expressions from the array ref and
4918 copy them into actual arguments. */
4919 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
4921 arg
= gfc_get_actual_arglist ();
4922 arg
->expr
= gfc_copy_expr (ref
->u
.ar
.start
[n
]);
4923 if (e
->value
.function
.actual
== NULL
)
4924 tail
= e
->value
.function
.actual
= arg
;
4932 /* Dump the reference list and set the rank. */
4933 gfc_free_ref_list (e
->ref
);
4935 e
->rank
= sym
->as
? sym
->as
->rank
: 0;
4938 gfc_resolve_expr (e
);
4942 /* This might have changed! */
4943 return e
->expr_type
== EXPR_FUNCTION
;
4948 gfc_resolve_character_operator (gfc_expr
*e
)
4950 gfc_expr
*op1
= e
->value
.op
.op1
;
4951 gfc_expr
*op2
= e
->value
.op
.op2
;
4952 gfc_expr
*e1
= NULL
;
4953 gfc_expr
*e2
= NULL
;
4955 gcc_assert (e
->value
.op
.op
== INTRINSIC_CONCAT
);
4957 if (op1
->ts
.u
.cl
&& op1
->ts
.u
.cl
->length
)
4958 e1
= gfc_copy_expr (op1
->ts
.u
.cl
->length
);
4959 else if (op1
->expr_type
== EXPR_CONSTANT
)
4960 e1
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
4961 op1
->value
.character
.length
);
4963 if (op2
->ts
.u
.cl
&& op2
->ts
.u
.cl
->length
)
4964 e2
= gfc_copy_expr (op2
->ts
.u
.cl
->length
);
4965 else if (op2
->expr_type
== EXPR_CONSTANT
)
4966 e2
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
4967 op2
->value
.character
.length
);
4969 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
4974 e
->ts
.u
.cl
->length
= gfc_add (e1
, e2
);
4975 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
4976 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
4977 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 0);
4978 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
4984 /* Ensure that an character expression has a charlen and, if possible, a
4985 length expression. */
4988 fixup_charlen (gfc_expr
*e
)
4990 /* The cases fall through so that changes in expression type and the need
4991 for multiple fixes are picked up. In all circumstances, a charlen should
4992 be available for the middle end to hang a backend_decl on. */
4993 switch (e
->expr_type
)
4996 gfc_resolve_character_operator (e
);
4999 if (e
->expr_type
== EXPR_ARRAY
)
5000 gfc_resolve_character_array_constructor (e
);
5002 case EXPR_SUBSTRING
:
5003 if (!e
->ts
.u
.cl
&& e
->ref
)
5004 gfc_resolve_substring_charlen (e
);
5008 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5015 /* Update an actual argument to include the passed-object for type-bound
5016 procedures at the right position. */
5018 static gfc_actual_arglist
*
5019 update_arglist_pass (gfc_actual_arglist
* lst
, gfc_expr
* po
, unsigned argpos
,
5022 gcc_assert (argpos
> 0);
5026 gfc_actual_arglist
* result
;
5028 result
= gfc_get_actual_arglist ();
5032 result
->name
= name
;
5038 lst
->next
= update_arglist_pass (lst
->next
, po
, argpos
- 1, name
);
5040 lst
= update_arglist_pass (NULL
, po
, argpos
- 1, name
);
5045 /* Extract the passed-object from an EXPR_COMPCALL (a copy of it). */
5048 extract_compcall_passed_object (gfc_expr
* e
)
5052 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5054 if (e
->value
.compcall
.base_object
)
5055 po
= gfc_copy_expr (e
->value
.compcall
.base_object
);
5058 po
= gfc_get_expr ();
5059 po
->expr_type
= EXPR_VARIABLE
;
5060 po
->symtree
= e
->symtree
;
5061 po
->ref
= gfc_copy_ref (e
->ref
);
5062 po
->where
= e
->where
;
5065 if (gfc_resolve_expr (po
) == FAILURE
)
5072 /* Update the arglist of an EXPR_COMPCALL expression to include the
5076 update_compcall_arglist (gfc_expr
* e
)
5079 gfc_typebound_proc
* tbp
;
5081 tbp
= e
->value
.compcall
.tbp
;
5086 po
= extract_compcall_passed_object (e
);
5090 if (tbp
->nopass
|| e
->value
.compcall
.ignore_pass
)
5096 gcc_assert (tbp
->pass_arg_num
> 0);
5097 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5105 /* Extract the passed object from a PPC call (a copy of it). */
5108 extract_ppc_passed_object (gfc_expr
*e
)
5113 po
= gfc_get_expr ();
5114 po
->expr_type
= EXPR_VARIABLE
;
5115 po
->symtree
= e
->symtree
;
5116 po
->ref
= gfc_copy_ref (e
->ref
);
5117 po
->where
= e
->where
;
5119 /* Remove PPC reference. */
5121 while ((*ref
)->next
)
5122 ref
= &(*ref
)->next
;
5123 gfc_free_ref_list (*ref
);
5126 if (gfc_resolve_expr (po
) == FAILURE
)
5133 /* Update the actual arglist of a procedure pointer component to include the
5137 update_ppc_arglist (gfc_expr
* e
)
5141 gfc_typebound_proc
* tb
;
5143 if (!gfc_is_proc_ptr_comp (e
, &ppc
))
5150 else if (tb
->nopass
)
5153 po
= extract_ppc_passed_object (e
);
5159 gfc_error ("Passed-object at %L must be scalar", &e
->where
);
5163 gcc_assert (tb
->pass_arg_num
> 0);
5164 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5172 /* Check that the object a TBP is called on is valid, i.e. it must not be
5173 of ABSTRACT type (as in subobject%abstract_parent%tbp()). */
5176 check_typebound_baseobject (gfc_expr
* e
)
5180 base
= extract_compcall_passed_object (e
);
5184 gcc_assert (base
->ts
.type
== BT_DERIVED
|| base
->ts
.type
== BT_CLASS
);
5186 if (base
->ts
.type
== BT_DERIVED
&& base
->ts
.u
.derived
->attr
.abstract
)
5188 gfc_error ("Base object for type-bound procedure call at %L is of"
5189 " ABSTRACT type '%s'", &e
->where
, base
->ts
.u
.derived
->name
);
5193 /* If the procedure called is NOPASS, the base object must be scalar. */
5194 if (e
->value
.compcall
.tbp
->nopass
&& base
->rank
> 0)
5196 gfc_error ("Base object for NOPASS type-bound procedure call at %L must"
5197 " be scalar", &e
->where
);
5201 /* FIXME: Remove once PR 41177 (this problem) is fixed completely. */
5204 gfc_error ("Non-scalar base object at %L currently not implemented",
5213 /* Resolve a call to a type-bound procedure, either function or subroutine,
5214 statically from the data in an EXPR_COMPCALL expression. The adapted
5215 arglist and the target-procedure symtree are returned. */
5218 resolve_typebound_static (gfc_expr
* e
, gfc_symtree
** target
,
5219 gfc_actual_arglist
** actual
)
5221 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5222 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5224 /* Update the actual arglist for PASS. */
5225 if (update_compcall_arglist (e
) == FAILURE
)
5228 *actual
= e
->value
.compcall
.actual
;
5229 *target
= e
->value
.compcall
.tbp
->u
.specific
;
5231 gfc_free_ref_list (e
->ref
);
5233 e
->value
.compcall
.actual
= NULL
;
5239 /* Get the ultimate declared type from an expression. In addition,
5240 return the last class/derived type reference and the copy of the
5243 get_declared_from_expr (gfc_ref
**class_ref
, gfc_ref
**new_ref
,
5246 gfc_symbol
*declared
;
5253 *new_ref
= gfc_copy_ref (e
->ref
);
5255 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5257 if (ref
->type
!= REF_COMPONENT
)
5260 if (ref
->u
.c
.component
->ts
.type
== BT_CLASS
5261 || ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
5263 declared
= ref
->u
.c
.component
->ts
.u
.derived
;
5269 if (declared
== NULL
)
5270 declared
= e
->symtree
->n
.sym
->ts
.u
.derived
;
5276 /* Given an EXPR_COMPCALL calling a GENERIC typebound procedure, figure out
5277 which of the specific bindings (if any) matches the arglist and transform
5278 the expression into a call of that binding. */
5281 resolve_typebound_generic_call (gfc_expr
* e
, const char **name
)
5283 gfc_typebound_proc
* genproc
;
5284 const char* genname
;
5286 gfc_symbol
*derived
;
5288 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5289 genname
= e
->value
.compcall
.name
;
5290 genproc
= e
->value
.compcall
.tbp
;
5292 if (!genproc
->is_generic
)
5295 /* Try the bindings on this type and in the inheritance hierarchy. */
5296 for (; genproc
; genproc
= genproc
->overridden
)
5300 gcc_assert (genproc
->is_generic
);
5301 for (g
= genproc
->u
.generic
; g
; g
= g
->next
)
5304 gfc_actual_arglist
* args
;
5307 gcc_assert (g
->specific
);
5309 if (g
->specific
->error
)
5312 target
= g
->specific
->u
.specific
->n
.sym
;
5314 /* Get the right arglist by handling PASS/NOPASS. */
5315 args
= gfc_copy_actual_arglist (e
->value
.compcall
.actual
);
5316 if (!g
->specific
->nopass
)
5319 po
= extract_compcall_passed_object (e
);
5323 gcc_assert (g
->specific
->pass_arg_num
> 0);
5324 gcc_assert (!g
->specific
->error
);
5325 args
= update_arglist_pass (args
, po
, g
->specific
->pass_arg_num
,
5326 g
->specific
->pass_arg
);
5328 resolve_actual_arglist (args
, target
->attr
.proc
,
5329 is_external_proc (target
) && !target
->formal
);
5331 /* Check if this arglist matches the formal. */
5332 matches
= gfc_arglist_matches_symbol (&args
, target
);
5334 /* Clean up and break out of the loop if we've found it. */
5335 gfc_free_actual_arglist (args
);
5338 e
->value
.compcall
.tbp
= g
->specific
;
5339 genname
= g
->specific_st
->name
;
5340 /* Pass along the name for CLASS methods, where the vtab
5341 procedure pointer component has to be referenced. */
5349 /* Nothing matching found! */
5350 gfc_error ("Found no matching specific binding for the call to the GENERIC"
5351 " '%s' at %L", genname
, &e
->where
);
5355 /* Make sure that we have the right specific instance for the name. */
5356 derived
= get_declared_from_expr (NULL
, NULL
, e
);
5358 st
= gfc_find_typebound_proc (derived
, NULL
, genname
, false, &e
->where
);
5360 e
->value
.compcall
.tbp
= st
->n
.tb
;
5366 /* Resolve a call to a type-bound subroutine. */
5369 resolve_typebound_call (gfc_code
* c
, const char **name
)
5371 gfc_actual_arglist
* newactual
;
5372 gfc_symtree
* target
;
5374 /* Check that's really a SUBROUTINE. */
5375 if (!c
->expr1
->value
.compcall
.tbp
->subroutine
)
5377 gfc_error ("'%s' at %L should be a SUBROUTINE",
5378 c
->expr1
->value
.compcall
.name
, &c
->loc
);
5382 if (check_typebound_baseobject (c
->expr1
) == FAILURE
)
5385 /* Pass along the name for CLASS methods, where the vtab
5386 procedure pointer component has to be referenced. */
5388 *name
= c
->expr1
->value
.compcall
.name
;
5390 if (resolve_typebound_generic_call (c
->expr1
, name
) == FAILURE
)
5393 /* Transform into an ordinary EXEC_CALL for now. */
5395 if (resolve_typebound_static (c
->expr1
, &target
, &newactual
) == FAILURE
)
5398 c
->ext
.actual
= newactual
;
5399 c
->symtree
= target
;
5400 c
->op
= (c
->expr1
->value
.compcall
.assign
? EXEC_ASSIGN_CALL
: EXEC_CALL
);
5402 gcc_assert (!c
->expr1
->ref
&& !c
->expr1
->value
.compcall
.actual
);
5404 gfc_free_expr (c
->expr1
);
5405 c
->expr1
= gfc_get_expr ();
5406 c
->expr1
->expr_type
= EXPR_FUNCTION
;
5407 c
->expr1
->symtree
= target
;
5408 c
->expr1
->where
= c
->loc
;
5410 return resolve_call (c
);
5414 /* Resolve a component-call expression. */
5416 resolve_compcall (gfc_expr
* e
, const char **name
)
5418 gfc_actual_arglist
* newactual
;
5419 gfc_symtree
* target
;
5421 /* Check that's really a FUNCTION. */
5422 if (!e
->value
.compcall
.tbp
->function
)
5424 gfc_error ("'%s' at %L should be a FUNCTION",
5425 e
->value
.compcall
.name
, &e
->where
);
5429 /* These must not be assign-calls! */
5430 gcc_assert (!e
->value
.compcall
.assign
);
5432 if (check_typebound_baseobject (e
) == FAILURE
)
5435 /* Pass along the name for CLASS methods, where the vtab
5436 procedure pointer component has to be referenced. */
5438 *name
= e
->value
.compcall
.name
;
5440 if (resolve_typebound_generic_call (e
, name
) == FAILURE
)
5442 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5444 /* Take the rank from the function's symbol. */
5445 if (e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
)
5446 e
->rank
= e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
->rank
;
5448 /* For now, we simply transform it into an EXPR_FUNCTION call with the same
5449 arglist to the TBP's binding target. */
5451 if (resolve_typebound_static (e
, &target
, &newactual
) == FAILURE
)
5454 e
->value
.function
.actual
= newactual
;
5455 e
->value
.function
.name
= NULL
;
5456 e
->value
.function
.esym
= target
->n
.sym
;
5457 e
->value
.function
.isym
= NULL
;
5458 e
->symtree
= target
;
5459 e
->ts
= target
->n
.sym
->ts
;
5460 e
->expr_type
= EXPR_FUNCTION
;
5462 /* Resolution is not necessary if this is a class subroutine; this
5463 function only has to identify the specific proc. Resolution of
5464 the call will be done next in resolve_typebound_call. */
5465 return gfc_resolve_expr (e
);
5470 /* Resolve a typebound function, or 'method'. First separate all
5471 the non-CLASS references by calling resolve_compcall directly. */
5474 resolve_typebound_function (gfc_expr
* e
)
5476 gfc_symbol
*declared
;
5486 return resolve_compcall (e
, NULL
);
5488 if (resolve_ref (e
) == FAILURE
)
5491 /* Get the CLASS declared type. */
5492 declared
= get_declared_from_expr (&class_ref
, &new_ref
, e
);
5494 /* Weed out cases of the ultimate component being a derived type. */
5495 if ((class_ref
&& class_ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
5496 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
5498 gfc_free_ref_list (new_ref
);
5499 return resolve_compcall (e
, NULL
);
5502 c
= gfc_find_component (declared
, "$data", true, true);
5503 declared
= c
->ts
.u
.derived
;
5505 /* Treat the call as if it is a typebound procedure, in order to roll
5506 out the correct name for the specific function. */
5507 if (resolve_compcall (e
, &name
) == FAILURE
)
5511 /* Then convert the expression to a procedure pointer component call. */
5512 e
->value
.function
.esym
= NULL
;
5518 /* '$vptr' points to the vtab, which contains the procedure pointers. */
5519 gfc_add_component_ref (e
, "$vptr");
5520 gfc_add_component_ref (e
, name
);
5522 /* Recover the typespec for the expression. This is really only
5523 necessary for generic procedures, where the additional call
5524 to gfc_add_component_ref seems to throw the collection of the
5525 correct typespec. */
5530 /* Resolve a typebound subroutine, or 'method'. First separate all
5531 the non-CLASS references by calling resolve_typebound_call
5535 resolve_typebound_subroutine (gfc_code
*code
)
5543 st
= code
->expr1
->symtree
;
5545 return resolve_typebound_call (code
, NULL
);
5547 if (resolve_ref (code
->expr1
) == FAILURE
)
5550 /* Get the CLASS declared type. */
5551 get_declared_from_expr (&class_ref
, &new_ref
, code
->expr1
);
5553 /* Weed out cases of the ultimate component being a derived type. */
5554 if ((class_ref
&& class_ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
5555 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
5557 gfc_free_ref_list (new_ref
);
5558 return resolve_typebound_call (code
, NULL
);
5561 if (resolve_typebound_call (code
, &name
) == FAILURE
)
5563 ts
= code
->expr1
->ts
;
5565 /* Then convert the expression to a procedure pointer component call. */
5566 code
->expr1
->value
.function
.esym
= NULL
;
5567 code
->expr1
->symtree
= st
;
5570 code
->expr1
->ref
= new_ref
;
5572 /* '$vptr' points to the vtab, which contains the procedure pointers. */
5573 gfc_add_component_ref (code
->expr1
, "$vptr");
5574 gfc_add_component_ref (code
->expr1
, name
);
5576 /* Recover the typespec for the expression. This is really only
5577 necessary for generic procedures, where the additional call
5578 to gfc_add_component_ref seems to throw the collection of the
5579 correct typespec. */
5580 code
->expr1
->ts
= ts
;
5585 /* Resolve a CALL to a Procedure Pointer Component (Subroutine). */
5588 resolve_ppc_call (gfc_code
* c
)
5590 gfc_component
*comp
;
5593 b
= gfc_is_proc_ptr_comp (c
->expr1
, &comp
);
5596 c
->resolved_sym
= c
->expr1
->symtree
->n
.sym
;
5597 c
->expr1
->expr_type
= EXPR_VARIABLE
;
5599 if (!comp
->attr
.subroutine
)
5600 gfc_add_subroutine (&comp
->attr
, comp
->name
, &c
->expr1
->where
);
5602 if (resolve_ref (c
->expr1
) == FAILURE
)
5605 if (update_ppc_arglist (c
->expr1
) == FAILURE
)
5608 c
->ext
.actual
= c
->expr1
->value
.compcall
.actual
;
5610 if (resolve_actual_arglist (c
->ext
.actual
, comp
->attr
.proc
,
5611 comp
->formal
== NULL
) == FAILURE
)
5614 gfc_ppc_use (comp
, &c
->expr1
->value
.compcall
.actual
, &c
->expr1
->where
);
5620 /* Resolve a Function Call to a Procedure Pointer Component (Function). */
5623 resolve_expr_ppc (gfc_expr
* e
)
5625 gfc_component
*comp
;
5628 b
= gfc_is_proc_ptr_comp (e
, &comp
);
5631 /* Convert to EXPR_FUNCTION. */
5632 e
->expr_type
= EXPR_FUNCTION
;
5633 e
->value
.function
.isym
= NULL
;
5634 e
->value
.function
.actual
= e
->value
.compcall
.actual
;
5636 if (comp
->as
!= NULL
)
5637 e
->rank
= comp
->as
->rank
;
5639 if (!comp
->attr
.function
)
5640 gfc_add_function (&comp
->attr
, comp
->name
, &e
->where
);
5642 if (resolve_ref (e
) == FAILURE
)
5645 if (resolve_actual_arglist (e
->value
.function
.actual
, comp
->attr
.proc
,
5646 comp
->formal
== NULL
) == FAILURE
)
5649 if (update_ppc_arglist (e
) == FAILURE
)
5652 gfc_ppc_use (comp
, &e
->value
.compcall
.actual
, &e
->where
);
5659 gfc_is_expandable_expr (gfc_expr
*e
)
5661 gfc_constructor
*con
;
5663 if (e
->expr_type
== EXPR_ARRAY
)
5665 /* Traverse the constructor looking for variables that are flavor
5666 parameter. Parameters must be expanded since they are fully used at
5668 con
= gfc_constructor_first (e
->value
.constructor
);
5669 for (; con
; con
= gfc_constructor_next (con
))
5671 if (con
->expr
->expr_type
== EXPR_VARIABLE
5672 && con
->expr
->symtree
5673 && (con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
5674 || con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_VARIABLE
))
5676 if (con
->expr
->expr_type
== EXPR_ARRAY
5677 && gfc_is_expandable_expr (con
->expr
))
5685 /* Resolve an expression. That is, make sure that types of operands agree
5686 with their operators, intrinsic operators are converted to function calls
5687 for overloaded types and unresolved function references are resolved. */
5690 gfc_resolve_expr (gfc_expr
*e
)
5698 /* inquiry_argument only applies to variables. */
5699 inquiry_save
= inquiry_argument
;
5700 if (e
->expr_type
!= EXPR_VARIABLE
)
5701 inquiry_argument
= false;
5703 switch (e
->expr_type
)
5706 t
= resolve_operator (e
);
5712 if (check_host_association (e
))
5713 t
= resolve_function (e
);
5716 t
= resolve_variable (e
);
5718 expression_rank (e
);
5721 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.u
.cl
== NULL
&& e
->ref
5722 && e
->ref
->type
!= REF_SUBSTRING
)
5723 gfc_resolve_substring_charlen (e
);
5728 t
= resolve_typebound_function (e
);
5731 case EXPR_SUBSTRING
:
5732 t
= resolve_ref (e
);
5741 t
= resolve_expr_ppc (e
);
5746 if (resolve_ref (e
) == FAILURE
)
5749 t
= gfc_resolve_array_constructor (e
);
5750 /* Also try to expand a constructor. */
5753 expression_rank (e
);
5754 if (gfc_is_constant_expr (e
) || gfc_is_expandable_expr (e
))
5755 gfc_expand_constructor (e
, false);
5758 /* This provides the opportunity for the length of constructors with
5759 character valued function elements to propagate the string length
5760 to the expression. */
5761 if (t
== SUCCESS
&& e
->ts
.type
== BT_CHARACTER
)
5763 /* For efficiency, we call gfc_expand_constructor for BT_CHARACTER
5764 here rather then add a duplicate test for it above. */
5765 gfc_expand_constructor (e
, false);
5766 t
= gfc_resolve_character_array_constructor (e
);
5771 case EXPR_STRUCTURE
:
5772 t
= resolve_ref (e
);
5776 t
= resolve_structure_cons (e
);
5780 t
= gfc_simplify_expr (e
, 0);
5784 gfc_internal_error ("gfc_resolve_expr(): Bad expression type");
5787 if (e
->ts
.type
== BT_CHARACTER
&& t
== SUCCESS
&& !e
->ts
.u
.cl
)
5790 inquiry_argument
= inquiry_save
;
5796 /* Resolve an expression from an iterator. They must be scalar and have
5797 INTEGER or (optionally) REAL type. */
5800 gfc_resolve_iterator_expr (gfc_expr
*expr
, bool real_ok
,
5801 const char *name_msgid
)
5803 if (gfc_resolve_expr (expr
) == FAILURE
)
5806 if (expr
->rank
!= 0)
5808 gfc_error ("%s at %L must be a scalar", _(name_msgid
), &expr
->where
);
5812 if (expr
->ts
.type
!= BT_INTEGER
)
5814 if (expr
->ts
.type
== BT_REAL
)
5817 return gfc_notify_std (GFC_STD_F95_DEL
,
5818 "Deleted feature: %s at %L must be integer",
5819 _(name_msgid
), &expr
->where
);
5822 gfc_error ("%s at %L must be INTEGER", _(name_msgid
),
5829 gfc_error ("%s at %L must be INTEGER", _(name_msgid
), &expr
->where
);
5837 /* Resolve the expressions in an iterator structure. If REAL_OK is
5838 false allow only INTEGER type iterators, otherwise allow REAL types. */
5841 gfc_resolve_iterator (gfc_iterator
*iter
, bool real_ok
)
5843 if (gfc_resolve_iterator_expr (iter
->var
, real_ok
, "Loop variable")
5847 if (gfc_pure (NULL
) && gfc_impure_variable (iter
->var
->symtree
->n
.sym
))
5849 gfc_error ("Cannot assign to loop variable in PURE procedure at %L",
5854 if (gfc_resolve_iterator_expr (iter
->start
, real_ok
,
5855 "Start expression in DO loop") == FAILURE
)
5858 if (gfc_resolve_iterator_expr (iter
->end
, real_ok
,
5859 "End expression in DO loop") == FAILURE
)
5862 if (gfc_resolve_iterator_expr (iter
->step
, real_ok
,
5863 "Step expression in DO loop") == FAILURE
)
5866 if (iter
->step
->expr_type
== EXPR_CONSTANT
)
5868 if ((iter
->step
->ts
.type
== BT_INTEGER
5869 && mpz_cmp_ui (iter
->step
->value
.integer
, 0) == 0)
5870 || (iter
->step
->ts
.type
== BT_REAL
5871 && mpfr_sgn (iter
->step
->value
.real
) == 0))
5873 gfc_error ("Step expression in DO loop at %L cannot be zero",
5874 &iter
->step
->where
);
5879 /* Convert start, end, and step to the same type as var. */
5880 if (iter
->start
->ts
.kind
!= iter
->var
->ts
.kind
5881 || iter
->start
->ts
.type
!= iter
->var
->ts
.type
)
5882 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 2);
5884 if (iter
->end
->ts
.kind
!= iter
->var
->ts
.kind
5885 || iter
->end
->ts
.type
!= iter
->var
->ts
.type
)
5886 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 2);
5888 if (iter
->step
->ts
.kind
!= iter
->var
->ts
.kind
5889 || iter
->step
->ts
.type
!= iter
->var
->ts
.type
)
5890 gfc_convert_type (iter
->step
, &iter
->var
->ts
, 2);
5892 if (iter
->start
->expr_type
== EXPR_CONSTANT
5893 && iter
->end
->expr_type
== EXPR_CONSTANT
5894 && iter
->step
->expr_type
== EXPR_CONSTANT
)
5897 if (iter
->start
->ts
.type
== BT_INTEGER
)
5899 sgn
= mpz_cmp_ui (iter
->step
->value
.integer
, 0);
5900 cmp
= mpz_cmp (iter
->end
->value
.integer
, iter
->start
->value
.integer
);
5904 sgn
= mpfr_sgn (iter
->step
->value
.real
);
5905 cmp
= mpfr_cmp (iter
->end
->value
.real
, iter
->start
->value
.real
);
5907 if ((sgn
> 0 && cmp
< 0) || (sgn
< 0 && cmp
> 0))
5908 gfc_warning ("DO loop at %L will be executed zero times",
5909 &iter
->step
->where
);
5916 /* Traversal function for find_forall_index. f == 2 signals that
5917 that variable itself is not to be checked - only the references. */
5920 forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int *f
)
5922 if (expr
->expr_type
!= EXPR_VARIABLE
)
5925 /* A scalar assignment */
5926 if (!expr
->ref
|| *f
== 1)
5928 if (expr
->symtree
->n
.sym
== sym
)
5940 /* Check whether the FORALL index appears in the expression or not.
5941 Returns SUCCESS if SYM is found in EXPR. */
5944 find_forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int f
)
5946 if (gfc_traverse_expr (expr
, sym
, forall_index
, f
))
5953 /* Resolve a list of FORALL iterators. The FORALL index-name is constrained
5954 to be a scalar INTEGER variable. The subscripts and stride are scalar
5955 INTEGERs, and if stride is a constant it must be nonzero.
5956 Furthermore "A subscript or stride in a forall-triplet-spec shall
5957 not contain a reference to any index-name in the
5958 forall-triplet-spec-list in which it appears." (7.5.4.1) */
5961 resolve_forall_iterators (gfc_forall_iterator
*it
)
5963 gfc_forall_iterator
*iter
, *iter2
;
5965 for (iter
= it
; iter
; iter
= iter
->next
)
5967 if (gfc_resolve_expr (iter
->var
) == SUCCESS
5968 && (iter
->var
->ts
.type
!= BT_INTEGER
|| iter
->var
->rank
!= 0))
5969 gfc_error ("FORALL index-name at %L must be a scalar INTEGER",
5972 if (gfc_resolve_expr (iter
->start
) == SUCCESS
5973 && (iter
->start
->ts
.type
!= BT_INTEGER
|| iter
->start
->rank
!= 0))
5974 gfc_error ("FORALL start expression at %L must be a scalar INTEGER",
5975 &iter
->start
->where
);
5976 if (iter
->var
->ts
.kind
!= iter
->start
->ts
.kind
)
5977 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 2);
5979 if (gfc_resolve_expr (iter
->end
) == SUCCESS
5980 && (iter
->end
->ts
.type
!= BT_INTEGER
|| iter
->end
->rank
!= 0))
5981 gfc_error ("FORALL end expression at %L must be a scalar INTEGER",
5983 if (iter
->var
->ts
.kind
!= iter
->end
->ts
.kind
)
5984 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 2);
5986 if (gfc_resolve_expr (iter
->stride
) == SUCCESS
)
5988 if (iter
->stride
->ts
.type
!= BT_INTEGER
|| iter
->stride
->rank
!= 0)
5989 gfc_error ("FORALL stride expression at %L must be a scalar %s",
5990 &iter
->stride
->where
, "INTEGER");
5992 if (iter
->stride
->expr_type
== EXPR_CONSTANT
5993 && mpz_cmp_ui(iter
->stride
->value
.integer
, 0) == 0)
5994 gfc_error ("FORALL stride expression at %L cannot be zero",
5995 &iter
->stride
->where
);
5997 if (iter
->var
->ts
.kind
!= iter
->stride
->ts
.kind
)
5998 gfc_convert_type (iter
->stride
, &iter
->var
->ts
, 2);
6001 for (iter
= it
; iter
; iter
= iter
->next
)
6002 for (iter2
= iter
; iter2
; iter2
= iter2
->next
)
6004 if (find_forall_index (iter2
->start
,
6005 iter
->var
->symtree
->n
.sym
, 0) == SUCCESS
6006 || find_forall_index (iter2
->end
,
6007 iter
->var
->symtree
->n
.sym
, 0) == SUCCESS
6008 || find_forall_index (iter2
->stride
,
6009 iter
->var
->symtree
->n
.sym
, 0) == SUCCESS
)
6010 gfc_error ("FORALL index '%s' may not appear in triplet "
6011 "specification at %L", iter
->var
->symtree
->name
,
6012 &iter2
->start
->where
);
6017 /* Given a pointer to a symbol that is a derived type, see if it's
6018 inaccessible, i.e. if it's defined in another module and the components are
6019 PRIVATE. The search is recursive if necessary. Returns zero if no
6020 inaccessible components are found, nonzero otherwise. */
6023 derived_inaccessible (gfc_symbol
*sym
)
6027 if (sym
->attr
.use_assoc
&& sym
->attr
.private_comp
)
6030 for (c
= sym
->components
; c
; c
= c
->next
)
6032 if (c
->ts
.type
== BT_DERIVED
&& derived_inaccessible (c
->ts
.u
.derived
))
6040 /* Resolve the argument of a deallocate expression. The expression must be
6041 a pointer or a full array. */
6044 resolve_deallocate_expr (gfc_expr
*e
)
6046 symbol_attribute attr
;
6047 int allocatable
, pointer
, check_intent_in
;
6052 /* Check INTENT(IN), unless the object is a sub-component of a pointer. */
6053 check_intent_in
= 1;
6055 if (gfc_resolve_expr (e
) == FAILURE
)
6058 if (e
->expr_type
!= EXPR_VARIABLE
)
6061 sym
= e
->symtree
->n
.sym
;
6063 if (sym
->ts
.type
== BT_CLASS
)
6065 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6066 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6070 allocatable
= sym
->attr
.allocatable
;
6071 pointer
= sym
->attr
.pointer
;
6073 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6076 check_intent_in
= 0;
6081 if (ref
->u
.ar
.type
!= AR_FULL
)
6086 c
= ref
->u
.c
.component
;
6087 if (c
->ts
.type
== BT_CLASS
)
6089 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
6090 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
6094 allocatable
= c
->attr
.allocatable
;
6095 pointer
= c
->attr
.pointer
;
6105 attr
= gfc_expr_attr (e
);
6107 if (allocatable
== 0 && attr
.pointer
== 0)
6110 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
6115 if (check_intent_in
&& sym
->attr
.intent
== INTENT_IN
)
6117 gfc_error ("Cannot deallocate INTENT(IN) variable '%s' at %L",
6118 sym
->name
, &e
->where
);
6122 if (e
->ts
.type
== BT_CLASS
)
6124 /* Only deallocate the DATA component. */
6125 gfc_add_component_ref (e
, "$data");
6132 /* Returns true if the expression e contains a reference to the symbol sym. */
6134 sym_in_expr (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
6136 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
== sym
)
6143 gfc_find_sym_in_expr (gfc_symbol
*sym
, gfc_expr
*e
)
6145 return gfc_traverse_expr (e
, sym
, sym_in_expr
, 0);
6149 /* Given the expression node e for an allocatable/pointer of derived type to be
6150 allocated, get the expression node to be initialized afterwards (needed for
6151 derived types with default initializers, and derived types with allocatable
6152 components that need nullification.) */
6155 gfc_expr_to_initialize (gfc_expr
*e
)
6161 result
= gfc_copy_expr (e
);
6163 /* Change the last array reference from AR_ELEMENT to AR_FULL. */
6164 for (ref
= result
->ref
; ref
; ref
= ref
->next
)
6165 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
6167 ref
->u
.ar
.type
= AR_FULL
;
6169 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
6170 ref
->u
.ar
.start
[i
] = ref
->u
.ar
.end
[i
] = ref
->u
.ar
.stride
[i
] = NULL
;
6172 result
->rank
= ref
->u
.ar
.dimen
;
6180 /* Used in resolve_allocate_expr to check that a allocation-object and
6181 a source-expr are conformable. This does not catch all possible
6182 cases; in particular a runtime checking is needed. */
6185 conformable_arrays (gfc_expr
*e1
, gfc_expr
*e2
)
6188 for (tail
= e2
->ref
; tail
&& tail
->next
; tail
= tail
->next
);
6190 /* First compare rank. */
6191 if (tail
&& e1
->rank
!= tail
->u
.ar
.as
->rank
)
6193 gfc_error ("Source-expr at %L must be scalar or have the "
6194 "same rank as the allocate-object at %L",
6195 &e1
->where
, &e2
->where
);
6206 for (i
= 0; i
< e1
->rank
; i
++)
6208 if (tail
->u
.ar
.end
[i
])
6210 mpz_set (s
, tail
->u
.ar
.end
[i
]->value
.integer
);
6211 mpz_sub (s
, s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6212 mpz_add_ui (s
, s
, 1);
6216 mpz_set (s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6219 if (mpz_cmp (e1
->shape
[i
], s
) != 0)
6221 gfc_error ("Source-expr at %L and allocate-object at %L must "
6222 "have the same shape", &e1
->where
, &e2
->where
);
6235 /* Resolve the expression in an ALLOCATE statement, doing the additional
6236 checks to see whether the expression is OK or not. The expression must
6237 have a trailing array reference that gives the size of the array. */
6240 resolve_allocate_expr (gfc_expr
*e
, gfc_code
*code
)
6242 int i
, pointer
, allocatable
, dimension
, check_intent_in
, is_abstract
;
6244 symbol_attribute attr
;
6245 gfc_ref
*ref
, *ref2
;
6247 gfc_symbol
*sym
= NULL
;
6251 /* Check INTENT(IN), unless the object is a sub-component of a pointer. */
6252 check_intent_in
= 1;
6254 /* Mark the ultimost array component as being in allocate to allow DIMEN_STAR
6255 checking of coarrays. */
6256 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6257 if (ref
->next
== NULL
)
6260 if (ref
&& ref
->type
== REF_ARRAY
)
6261 ref
->u
.ar
.in_allocate
= true;
6263 if (gfc_resolve_expr (e
) == FAILURE
)
6266 /* Make sure the expression is allocatable or a pointer. If it is
6267 pointer, the next-to-last reference must be a pointer. */
6271 sym
= e
->symtree
->n
.sym
;
6273 /* Check whether ultimate component is abstract and CLASS. */
6276 if (e
->expr_type
!= EXPR_VARIABLE
)
6279 attr
= gfc_expr_attr (e
);
6280 pointer
= attr
.pointer
;
6281 dimension
= attr
.dimension
;
6282 codimension
= attr
.codimension
;
6286 if (sym
->ts
.type
== BT_CLASS
)
6288 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6289 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6290 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
6291 codimension
= CLASS_DATA (sym
)->attr
.codimension
;
6292 is_abstract
= CLASS_DATA (sym
)->attr
.abstract
;
6296 allocatable
= sym
->attr
.allocatable
;
6297 pointer
= sym
->attr
.pointer
;
6298 dimension
= sym
->attr
.dimension
;
6299 codimension
= sym
->attr
.codimension
;
6302 for (ref
= e
->ref
; ref
; ref2
= ref
, ref
= ref
->next
)
6305 check_intent_in
= 0;
6310 if (ref
->next
!= NULL
)
6316 if (gfc_is_coindexed (e
))
6318 gfc_error ("Coindexed allocatable object at %L",
6323 c
= ref
->u
.c
.component
;
6324 if (c
->ts
.type
== BT_CLASS
)
6326 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
6327 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
6328 dimension
= CLASS_DATA (c
)->attr
.dimension
;
6329 codimension
= CLASS_DATA (c
)->attr
.codimension
;
6330 is_abstract
= CLASS_DATA (c
)->attr
.abstract
;
6334 allocatable
= c
->attr
.allocatable
;
6335 pointer
= c
->attr
.pointer
;
6336 dimension
= c
->attr
.dimension
;
6337 codimension
= c
->attr
.codimension
;
6338 is_abstract
= c
->attr
.abstract
;
6350 if (allocatable
== 0 && pointer
== 0)
6352 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
6357 /* Some checks for the SOURCE tag. */
6360 /* Check F03:C631. */
6361 if (!gfc_type_compatible (&e
->ts
, &code
->expr3
->ts
))
6363 gfc_error ("Type of entity at %L is type incompatible with "
6364 "source-expr at %L", &e
->where
, &code
->expr3
->where
);
6368 /* Check F03:C632 and restriction following Note 6.18. */
6369 if (code
->expr3
->rank
> 0
6370 && conformable_arrays (code
->expr3
, e
) == FAILURE
)
6373 /* Check F03:C633. */
6374 if (code
->expr3
->ts
.kind
!= e
->ts
.kind
)
6376 gfc_error ("The allocate-object at %L and the source-expr at %L "
6377 "shall have the same kind type parameter",
6378 &e
->where
, &code
->expr3
->where
);
6383 /* Check F08:C629. */
6384 if (is_abstract
&& code
->ext
.alloc
.ts
.type
== BT_UNKNOWN
6387 gcc_assert (e
->ts
.type
== BT_CLASS
);
6388 gfc_error ("Allocating %s of ABSTRACT base type at %L requires a "
6389 "type-spec or source-expr", sym
->name
, &e
->where
);
6393 if (check_intent_in
&& sym
->attr
.intent
== INTENT_IN
)
6395 gfc_error ("Cannot allocate INTENT(IN) variable '%s' at %L",
6396 sym
->name
, &e
->where
);
6400 if (!code
->expr3
|| code
->expr3
->mold
)
6402 /* Add default initializer for those derived types that need them. */
6403 gfc_expr
*init_e
= NULL
;
6406 if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
6407 ts
= code
->ext
.alloc
.ts
;
6408 else if (code
->expr3
)
6409 ts
= code
->expr3
->ts
;
6413 if (ts
.type
== BT_DERIVED
)
6414 init_e
= gfc_default_initializer (&ts
);
6415 /* FIXME: Use default init of dynamic type (cf. PR 44541). */
6416 else if (e
->ts
.type
== BT_CLASS
)
6417 init_e
= gfc_default_initializer (&ts
.u
.derived
->components
->ts
);
6421 gfc_code
*init_st
= gfc_get_code ();
6422 init_st
->loc
= code
->loc
;
6423 init_st
->op
= EXEC_INIT_ASSIGN
;
6424 init_st
->expr1
= gfc_expr_to_initialize (e
);
6425 init_st
->expr2
= init_e
;
6426 init_st
->next
= code
->next
;
6427 code
->next
= init_st
;
6431 if (pointer
|| (dimension
== 0 && codimension
== 0))
6434 /* Make sure the next-to-last reference node is an array specification. */
6436 if (ref2
== NULL
|| ref2
->type
!= REF_ARRAY
|| ref2
->u
.ar
.type
== AR_FULL
6437 || (dimension
&& ref2
->u
.ar
.dimen
== 0))
6439 gfc_error ("Array specification required in ALLOCATE statement "
6440 "at %L", &e
->where
);
6444 /* Make sure that the array section reference makes sense in the
6445 context of an ALLOCATE specification. */
6449 if (codimension
&& ar
->codimen
== 0)
6451 gfc_error ("Coarray specification required in ALLOCATE statement "
6452 "at %L", &e
->where
);
6456 for (i
= 0; i
< ar
->dimen
; i
++)
6458 if (ref2
->u
.ar
.type
== AR_ELEMENT
)
6461 switch (ar
->dimen_type
[i
])
6467 if (ar
->start
[i
] != NULL
6468 && ar
->end
[i
] != NULL
6469 && ar
->stride
[i
] == NULL
)
6472 /* Fall Through... */
6477 gfc_error ("Bad array specification in ALLOCATE statement at %L",
6483 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
6485 sym
= a
->expr
->symtree
->n
.sym
;
6487 /* TODO - check derived type components. */
6488 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
6491 if ((ar
->start
[i
] != NULL
6492 && gfc_find_sym_in_expr (sym
, ar
->start
[i
]))
6493 || (ar
->end
[i
] != NULL
6494 && gfc_find_sym_in_expr (sym
, ar
->end
[i
])))
6496 gfc_error ("'%s' must not appear in the array specification at "
6497 "%L in the same ALLOCATE statement where it is "
6498 "itself allocated", sym
->name
, &ar
->where
);
6504 for (i
= ar
->dimen
; i
< ar
->codimen
+ ar
->dimen
; i
++)
6506 if (ar
->dimen_type
[i
] == DIMEN_ELEMENT
6507 || ar
->dimen_type
[i
] == DIMEN_RANGE
)
6509 if (i
== (ar
->dimen
+ ar
->codimen
- 1))
6511 gfc_error ("Expected '*' in coindex specification in ALLOCATE "
6512 "statement at %L", &e
->where
);
6518 if (ar
->dimen_type
[i
] == DIMEN_STAR
&& i
== (ar
->dimen
+ ar
->codimen
- 1)
6519 && ar
->stride
[i
] == NULL
)
6522 gfc_error ("Bad coarray specification in ALLOCATE statement at %L",
6527 if (codimension
&& ar
->as
->rank
== 0)
6529 gfc_error ("Sorry, allocatable scalar coarrays are not yet supported "
6530 "at %L", &e
->where
);
6542 resolve_allocate_deallocate (gfc_code
*code
, const char *fcn
)
6544 gfc_expr
*stat
, *errmsg
, *pe
, *qe
;
6545 gfc_alloc
*a
, *p
, *q
;
6547 stat
= code
->expr1
? code
->expr1
: NULL
;
6549 errmsg
= code
->expr2
? code
->expr2
: NULL
;
6551 /* Check the stat variable. */
6554 if (stat
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
6555 gfc_error ("Stat-variable '%s' at %L cannot be INTENT(IN)",
6556 stat
->symtree
->n
.sym
->name
, &stat
->where
);
6558 if (gfc_pure (NULL
) && gfc_impure_variable (stat
->symtree
->n
.sym
))
6559 gfc_error ("Illegal stat-variable at %L for a PURE procedure",
6562 if ((stat
->ts
.type
!= BT_INTEGER
6563 && !(stat
->ref
&& (stat
->ref
->type
== REF_ARRAY
6564 || stat
->ref
->type
== REF_COMPONENT
)))
6566 gfc_error ("Stat-variable at %L must be a scalar INTEGER "
6567 "variable", &stat
->where
);
6569 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
6570 if (p
->expr
->symtree
->n
.sym
->name
== stat
->symtree
->n
.sym
->name
)
6572 gfc_ref
*ref1
, *ref2
;
6575 for (ref1
= p
->expr
->ref
, ref2
= stat
->ref
; ref1
&& ref2
;
6576 ref1
= ref1
->next
, ref2
= ref2
->next
)
6578 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
6580 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
6589 gfc_error ("Stat-variable at %L shall not be %sd within "
6590 "the same %s statement", &stat
->where
, fcn
, fcn
);
6596 /* Check the errmsg variable. */
6600 gfc_warning ("ERRMSG at %L is useless without a STAT tag",
6603 if (errmsg
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
6604 gfc_error ("Errmsg-variable '%s' at %L cannot be INTENT(IN)",
6605 errmsg
->symtree
->n
.sym
->name
, &errmsg
->where
);
6607 if (gfc_pure (NULL
) && gfc_impure_variable (errmsg
->symtree
->n
.sym
))
6608 gfc_error ("Illegal errmsg-variable at %L for a PURE procedure",
6611 if ((errmsg
->ts
.type
!= BT_CHARACTER
6613 && (errmsg
->ref
->type
== REF_ARRAY
6614 || errmsg
->ref
->type
== REF_COMPONENT
)))
6615 || errmsg
->rank
> 0 )
6616 gfc_error ("Errmsg-variable at %L must be a scalar CHARACTER "
6617 "variable", &errmsg
->where
);
6619 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
6620 if (p
->expr
->symtree
->n
.sym
->name
== errmsg
->symtree
->n
.sym
->name
)
6622 gfc_ref
*ref1
, *ref2
;
6625 for (ref1
= p
->expr
->ref
, ref2
= errmsg
->ref
; ref1
&& ref2
;
6626 ref1
= ref1
->next
, ref2
= ref2
->next
)
6628 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
6630 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
6639 gfc_error ("Errmsg-variable at %L shall not be %sd within "
6640 "the same %s statement", &errmsg
->where
, fcn
, fcn
);
6646 /* Check that an allocate-object appears only once in the statement.
6647 FIXME: Checking derived types is disabled. */
6648 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
6651 if ((pe
->ref
&& pe
->ref
->type
!= REF_COMPONENT
)
6652 && (pe
->symtree
->n
.sym
->ts
.type
!= BT_DERIVED
))
6654 for (q
= p
->next
; q
; q
= q
->next
)
6657 if ((qe
->ref
&& qe
->ref
->type
!= REF_COMPONENT
)
6658 && (qe
->symtree
->n
.sym
->ts
.type
!= BT_DERIVED
)
6659 && (pe
->symtree
->n
.sym
->name
== qe
->symtree
->n
.sym
->name
))
6660 gfc_error ("Allocate-object at %L also appears at %L",
6661 &pe
->where
, &qe
->where
);
6666 if (strcmp (fcn
, "ALLOCATE") == 0)
6668 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
6669 resolve_allocate_expr (a
->expr
, code
);
6673 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
6674 resolve_deallocate_expr (a
->expr
);
6679 /************ SELECT CASE resolution subroutines ************/
6681 /* Callback function for our mergesort variant. Determines interval
6682 overlaps for CASEs. Return <0 if op1 < op2, 0 for overlap, >0 for
6683 op1 > op2. Assumes we're not dealing with the default case.
6684 We have op1 = (:L), (K:L) or (K:) and op2 = (:N), (M:N) or (M:).
6685 There are nine situations to check. */
6688 compare_cases (const gfc_case
*op1
, const gfc_case
*op2
)
6692 if (op1
->low
== NULL
) /* op1 = (:L) */
6694 /* op2 = (:N), so overlap. */
6696 /* op2 = (M:) or (M:N), L < M */
6697 if (op2
->low
!= NULL
6698 && gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
6701 else if (op1
->high
== NULL
) /* op1 = (K:) */
6703 /* op2 = (M:), so overlap. */
6705 /* op2 = (:N) or (M:N), K > N */
6706 if (op2
->high
!= NULL
6707 && gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
6710 else /* op1 = (K:L) */
6712 if (op2
->low
== NULL
) /* op2 = (:N), K > N */
6713 retval
= (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
6715 else if (op2
->high
== NULL
) /* op2 = (M:), L < M */
6716 retval
= (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
6718 else /* op2 = (M:N) */
6722 if (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
6725 else if (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
6734 /* Merge-sort a double linked case list, detecting overlap in the
6735 process. LIST is the head of the double linked case list before it
6736 is sorted. Returns the head of the sorted list if we don't see any
6737 overlap, or NULL otherwise. */
6740 check_case_overlap (gfc_case
*list
)
6742 gfc_case
*p
, *q
, *e
, *tail
;
6743 int insize
, nmerges
, psize
, qsize
, cmp
, overlap_seen
;
6745 /* If the passed list was empty, return immediately. */
6752 /* Loop unconditionally. The only exit from this loop is a return
6753 statement, when we've finished sorting the case list. */
6760 /* Count the number of merges we do in this pass. */
6763 /* Loop while there exists a merge to be done. */
6768 /* Count this merge. */
6771 /* Cut the list in two pieces by stepping INSIZE places
6772 forward in the list, starting from P. */
6775 for (i
= 0; i
< insize
; i
++)
6784 /* Now we have two lists. Merge them! */
6785 while (psize
> 0 || (qsize
> 0 && q
!= NULL
))
6787 /* See from which the next case to merge comes from. */
6790 /* P is empty so the next case must come from Q. */
6795 else if (qsize
== 0 || q
== NULL
)
6804 cmp
= compare_cases (p
, q
);
6807 /* The whole case range for P is less than the
6815 /* The whole case range for Q is greater than
6816 the case range for P. */
6823 /* The cases overlap, or they are the same
6824 element in the list. Either way, we must
6825 issue an error and get the next case from P. */
6826 /* FIXME: Sort P and Q by line number. */
6827 gfc_error ("CASE label at %L overlaps with CASE "
6828 "label at %L", &p
->where
, &q
->where
);
6836 /* Add the next element to the merged list. */
6845 /* P has now stepped INSIZE places along, and so has Q. So
6846 they're the same. */
6851 /* If we have done only one merge or none at all, we've
6852 finished sorting the cases. */
6861 /* Otherwise repeat, merging lists twice the size. */
6867 /* Check to see if an expression is suitable for use in a CASE statement.
6868 Makes sure that all case expressions are scalar constants of the same
6869 type. Return FAILURE if anything is wrong. */
6872 validate_case_label_expr (gfc_expr
*e
, gfc_expr
*case_expr
)
6874 if (e
== NULL
) return SUCCESS
;
6876 if (e
->ts
.type
!= case_expr
->ts
.type
)
6878 gfc_error ("Expression in CASE statement at %L must be of type %s",
6879 &e
->where
, gfc_basic_typename (case_expr
->ts
.type
));
6883 /* C805 (R808) For a given case-construct, each case-value shall be of
6884 the same type as case-expr. For character type, length differences
6885 are allowed, but the kind type parameters shall be the same. */
6887 if (case_expr
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= case_expr
->ts
.kind
)
6889 gfc_error ("Expression in CASE statement at %L must be of kind %d",
6890 &e
->where
, case_expr
->ts
.kind
);
6894 /* Convert the case value kind to that of case expression kind,
6897 if (e
->ts
.kind
!= case_expr
->ts
.kind
)
6898 gfc_convert_type_warn (e
, &case_expr
->ts
, 2, 0);
6902 gfc_error ("Expression in CASE statement at %L must be scalar",
6911 /* Given a completely parsed select statement, we:
6913 - Validate all expressions and code within the SELECT.
6914 - Make sure that the selection expression is not of the wrong type.
6915 - Make sure that no case ranges overlap.
6916 - Eliminate unreachable cases and unreachable code resulting from
6917 removing case labels.
6919 The standard does allow unreachable cases, e.g. CASE (5:3). But
6920 they are a hassle for code generation, and to prevent that, we just
6921 cut them out here. This is not necessary for overlapping cases
6922 because they are illegal and we never even try to generate code.
6924 We have the additional caveat that a SELECT construct could have
6925 been a computed GOTO in the source code. Fortunately we can fairly
6926 easily work around that here: The case_expr for a "real" SELECT CASE
6927 is in code->expr1, but for a computed GOTO it is in code->expr2. All
6928 we have to do is make sure that the case_expr is a scalar integer
6932 resolve_select (gfc_code
*code
)
6935 gfc_expr
*case_expr
;
6936 gfc_case
*cp
, *default_case
, *tail
, *head
;
6937 int seen_unreachable
;
6943 if (code
->expr1
== NULL
)
6945 /* This was actually a computed GOTO statement. */
6946 case_expr
= code
->expr2
;
6947 if (case_expr
->ts
.type
!= BT_INTEGER
|| case_expr
->rank
!= 0)
6948 gfc_error ("Selection expression in computed GOTO statement "
6949 "at %L must be a scalar integer expression",
6952 /* Further checking is not necessary because this SELECT was built
6953 by the compiler, so it should always be OK. Just move the
6954 case_expr from expr2 to expr so that we can handle computed
6955 GOTOs as normal SELECTs from here on. */
6956 code
->expr1
= code
->expr2
;
6961 case_expr
= code
->expr1
;
6963 type
= case_expr
->ts
.type
;
6964 if (type
!= BT_LOGICAL
&& type
!= BT_INTEGER
&& type
!= BT_CHARACTER
)
6966 gfc_error ("Argument of SELECT statement at %L cannot be %s",
6967 &case_expr
->where
, gfc_typename (&case_expr
->ts
));
6969 /* Punt. Going on here just produce more garbage error messages. */
6973 if (case_expr
->rank
!= 0)
6975 gfc_error ("Argument of SELECT statement at %L must be a scalar "
6976 "expression", &case_expr
->where
);
6983 /* Raise a warning if an INTEGER case value exceeds the range of
6984 the case-expr. Later, all expressions will be promoted to the
6985 largest kind of all case-labels. */
6987 if (type
== BT_INTEGER
)
6988 for (body
= code
->block
; body
; body
= body
->block
)
6989 for (cp
= body
->ext
.case_list
; cp
; cp
= cp
->next
)
6992 && gfc_check_integer_range (cp
->low
->value
.integer
,
6993 case_expr
->ts
.kind
) != ARITH_OK
)
6994 gfc_warning ("Expression in CASE statement at %L is "
6995 "not in the range of %s", &cp
->low
->where
,
6996 gfc_typename (&case_expr
->ts
));
6999 && cp
->low
!= cp
->high
7000 && gfc_check_integer_range (cp
->high
->value
.integer
,
7001 case_expr
->ts
.kind
) != ARITH_OK
)
7002 gfc_warning ("Expression in CASE statement at %L is "
7003 "not in the range of %s", &cp
->high
->where
,
7004 gfc_typename (&case_expr
->ts
));
7007 /* PR 19168 has a long discussion concerning a mismatch of the kinds
7008 of the SELECT CASE expression and its CASE values. Walk the lists
7009 of case values, and if we find a mismatch, promote case_expr to
7010 the appropriate kind. */
7012 if (type
== BT_LOGICAL
|| type
== BT_INTEGER
)
7014 for (body
= code
->block
; body
; body
= body
->block
)
7016 /* Walk the case label list. */
7017 for (cp
= body
->ext
.case_list
; cp
; cp
= cp
->next
)
7019 /* Intercept the DEFAULT case. It does not have a kind. */
7020 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7023 /* Unreachable case ranges are discarded, so ignore. */
7024 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7025 && cp
->low
!= cp
->high
7026 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7030 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->low
))
7031 gfc_convert_type_warn (case_expr
, &cp
->low
->ts
, 2, 0);
7033 if (cp
->high
!= NULL
7034 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->high
))
7035 gfc_convert_type_warn (case_expr
, &cp
->high
->ts
, 2, 0);
7040 /* Assume there is no DEFAULT case. */
7041 default_case
= NULL
;
7046 for (body
= code
->block
; body
; body
= body
->block
)
7048 /* Assume the CASE list is OK, and all CASE labels can be matched. */
7050 seen_unreachable
= 0;
7052 /* Walk the case label list, making sure that all case labels
7054 for (cp
= body
->ext
.case_list
; cp
; cp
= cp
->next
)
7056 /* Count the number of cases in the whole construct. */
7059 /* Intercept the DEFAULT case. */
7060 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7062 if (default_case
!= NULL
)
7064 gfc_error ("The DEFAULT CASE at %L cannot be followed "
7065 "by a second DEFAULT CASE at %L",
7066 &default_case
->where
, &cp
->where
);
7077 /* Deal with single value cases and case ranges. Errors are
7078 issued from the validation function. */
7079 if (validate_case_label_expr (cp
->low
, case_expr
) != SUCCESS
7080 || validate_case_label_expr (cp
->high
, case_expr
) != SUCCESS
)
7086 if (type
== BT_LOGICAL
7087 && ((cp
->low
== NULL
|| cp
->high
== NULL
)
7088 || cp
->low
!= cp
->high
))
7090 gfc_error ("Logical range in CASE statement at %L is not "
7091 "allowed", &cp
->low
->where
);
7096 if (type
== BT_LOGICAL
&& cp
->low
->expr_type
== EXPR_CONSTANT
)
7099 value
= cp
->low
->value
.logical
== 0 ? 2 : 1;
7100 if (value
& seen_logical
)
7102 gfc_error ("Constant logical value in CASE statement "
7103 "is repeated at %L",
7108 seen_logical
|= value
;
7111 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7112 && cp
->low
!= cp
->high
7113 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7115 if (gfc_option
.warn_surprising
)
7116 gfc_warning ("Range specification at %L can never "
7117 "be matched", &cp
->where
);
7119 cp
->unreachable
= 1;
7120 seen_unreachable
= 1;
7124 /* If the case range can be matched, it can also overlap with
7125 other cases. To make sure it does not, we put it in a
7126 double linked list here. We sort that with a merge sort
7127 later on to detect any overlapping cases. */
7131 head
->right
= head
->left
= NULL
;
7136 tail
->right
->left
= tail
;
7143 /* It there was a failure in the previous case label, give up
7144 for this case label list. Continue with the next block. */
7148 /* See if any case labels that are unreachable have been seen.
7149 If so, we eliminate them. This is a bit of a kludge because
7150 the case lists for a single case statement (label) is a
7151 single forward linked lists. */
7152 if (seen_unreachable
)
7154 /* Advance until the first case in the list is reachable. */
7155 while (body
->ext
.case_list
!= NULL
7156 && body
->ext
.case_list
->unreachable
)
7158 gfc_case
*n
= body
->ext
.case_list
;
7159 body
->ext
.case_list
= body
->ext
.case_list
->next
;
7161 gfc_free_case_list (n
);
7164 /* Strip all other unreachable cases. */
7165 if (body
->ext
.case_list
)
7167 for (cp
= body
->ext
.case_list
; cp
->next
; cp
= cp
->next
)
7169 if (cp
->next
->unreachable
)
7171 gfc_case
*n
= cp
->next
;
7172 cp
->next
= cp
->next
->next
;
7174 gfc_free_case_list (n
);
7181 /* See if there were overlapping cases. If the check returns NULL,
7182 there was overlap. In that case we don't do anything. If head
7183 is non-NULL, we prepend the DEFAULT case. The sorted list can
7184 then used during code generation for SELECT CASE constructs with
7185 a case expression of a CHARACTER type. */
7188 head
= check_case_overlap (head
);
7190 /* Prepend the default_case if it is there. */
7191 if (head
!= NULL
&& default_case
)
7193 default_case
->left
= NULL
;
7194 default_case
->right
= head
;
7195 head
->left
= default_case
;
7199 /* Eliminate dead blocks that may be the result if we've seen
7200 unreachable case labels for a block. */
7201 for (body
= code
; body
&& body
->block
; body
= body
->block
)
7203 if (body
->block
->ext
.case_list
== NULL
)
7205 /* Cut the unreachable block from the code chain. */
7206 gfc_code
*c
= body
->block
;
7207 body
->block
= c
->block
;
7209 /* Kill the dead block, but not the blocks below it. */
7211 gfc_free_statements (c
);
7215 /* More than two cases is legal but insane for logical selects.
7216 Issue a warning for it. */
7217 if (gfc_option
.warn_surprising
&& type
== BT_LOGICAL
7219 gfc_warning ("Logical SELECT CASE block at %L has more that two cases",
7224 /* Check if a derived type is extensible. */
7227 gfc_type_is_extensible (gfc_symbol
*sym
)
7229 return !(sym
->attr
.is_bind_c
|| sym
->attr
.sequence
);
7233 /* Resolve a SELECT TYPE statement. */
7236 resolve_select_type (gfc_code
*code
)
7238 gfc_symbol
*selector_type
;
7239 gfc_code
*body
, *new_st
, *if_st
, *tail
;
7240 gfc_code
*class_is
= NULL
, *default_case
= NULL
;
7243 char name
[GFC_MAX_SYMBOL_LEN
];
7247 ns
= code
->ext
.block
.ns
;
7250 /* Check for F03:C813. */
7251 if (code
->expr1
->ts
.type
!= BT_CLASS
7252 && !(code
->expr2
&& code
->expr2
->ts
.type
== BT_CLASS
))
7254 gfc_error ("Selector shall be polymorphic in SELECT TYPE statement "
7255 "at %L", &code
->loc
);
7261 if (code
->expr1
->symtree
->n
.sym
->attr
.untyped
)
7262 code
->expr1
->symtree
->n
.sym
->ts
= code
->expr2
->ts
;
7263 selector_type
= CLASS_DATA (code
->expr2
)->ts
.u
.derived
;
7266 selector_type
= CLASS_DATA (code
->expr1
)->ts
.u
.derived
;
7268 /* Loop over TYPE IS / CLASS IS cases. */
7269 for (body
= code
->block
; body
; body
= body
->block
)
7271 c
= body
->ext
.case_list
;
7273 /* Check F03:C815. */
7274 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
7275 && !gfc_type_is_extensible (c
->ts
.u
.derived
))
7277 gfc_error ("Derived type '%s' at %L must be extensible",
7278 c
->ts
.u
.derived
->name
, &c
->where
);
7283 /* Check F03:C816. */
7284 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
7285 && !gfc_type_is_extension_of (selector_type
, c
->ts
.u
.derived
))
7287 gfc_error ("Derived type '%s' at %L must be an extension of '%s'",
7288 c
->ts
.u
.derived
->name
, &c
->where
, selector_type
->name
);
7293 /* Intercept the DEFAULT case. */
7294 if (c
->ts
.type
== BT_UNKNOWN
)
7296 /* Check F03:C818. */
7299 gfc_error ("The DEFAULT CASE at %L cannot be followed "
7300 "by a second DEFAULT CASE at %L",
7301 &default_case
->ext
.case_list
->where
, &c
->where
);
7306 default_case
= body
;
7315 /* Insert assignment for selector variable. */
7316 new_st
= gfc_get_code ();
7317 new_st
->op
= EXEC_ASSIGN
;
7318 new_st
->expr1
= gfc_copy_expr (code
->expr1
);
7319 new_st
->expr2
= gfc_copy_expr (code
->expr2
);
7323 /* Put SELECT TYPE statement inside a BLOCK. */
7324 new_st
= gfc_get_code ();
7325 new_st
->op
= code
->op
;
7326 new_st
->expr1
= code
->expr1
;
7327 new_st
->expr2
= code
->expr2
;
7328 new_st
->block
= code
->block
;
7332 ns
->code
->next
= new_st
;
7333 code
->op
= EXEC_BLOCK
;
7334 code
->ext
.block
.assoc
= NULL
;
7335 code
->expr1
= code
->expr2
= NULL
;
7340 /* Transform to EXEC_SELECT. */
7341 code
->op
= EXEC_SELECT
;
7342 gfc_add_component_ref (code
->expr1
, "$vptr");
7343 gfc_add_component_ref (code
->expr1
, "$hash");
7345 /* Loop over TYPE IS / CLASS IS cases. */
7346 for (body
= code
->block
; body
; body
= body
->block
)
7348 c
= body
->ext
.case_list
;
7350 if (c
->ts
.type
== BT_DERIVED
)
7351 c
->low
= c
->high
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
7352 c
->ts
.u
.derived
->hash_value
);
7354 else if (c
->ts
.type
== BT_UNKNOWN
)
7357 /* Assign temporary to selector. */
7358 if (c
->ts
.type
== BT_CLASS
)
7359 sprintf (name
, "tmp$class$%s", c
->ts
.u
.derived
->name
);
7361 sprintf (name
, "tmp$type$%s", c
->ts
.u
.derived
->name
);
7362 st
= gfc_find_symtree (ns
->sym_root
, name
);
7363 new_st
= gfc_get_code ();
7364 new_st
->expr1
= gfc_get_variable_expr (st
);
7365 new_st
->expr2
= gfc_get_variable_expr (code
->expr1
->symtree
);
7366 if (c
->ts
.type
== BT_DERIVED
)
7368 new_st
->op
= EXEC_POINTER_ASSIGN
;
7369 gfc_add_component_ref (new_st
->expr2
, "$data");
7372 new_st
->op
= EXEC_POINTER_ASSIGN
;
7373 new_st
->next
= body
->next
;
7374 body
->next
= new_st
;
7377 /* Take out CLASS IS cases for separate treatment. */
7379 while (body
&& body
->block
)
7381 if (body
->block
->ext
.case_list
->ts
.type
== BT_CLASS
)
7383 /* Add to class_is list. */
7384 if (class_is
== NULL
)
7386 class_is
= body
->block
;
7391 for (tail
= class_is
; tail
->block
; tail
= tail
->block
) ;
7392 tail
->block
= body
->block
;
7395 /* Remove from EXEC_SELECT list. */
7396 body
->block
= body
->block
->block
;
7409 /* Add a default case to hold the CLASS IS cases. */
7410 for (tail
= code
; tail
->block
; tail
= tail
->block
) ;
7411 tail
->block
= gfc_get_code ();
7413 tail
->op
= EXEC_SELECT_TYPE
;
7414 tail
->ext
.case_list
= gfc_get_case ();
7415 tail
->ext
.case_list
->ts
.type
= BT_UNKNOWN
;
7417 default_case
= tail
;
7420 /* More than one CLASS IS block? */
7421 if (class_is
->block
)
7425 /* Sort CLASS IS blocks by extension level. */
7429 for (c1
= &class_is
; (*c1
) && (*c1
)->block
; c1
= &((*c1
)->block
))
7432 /* F03:C817 (check for doubles). */
7433 if ((*c1
)->ext
.case_list
->ts
.u
.derived
->hash_value
7434 == c2
->ext
.case_list
->ts
.u
.derived
->hash_value
)
7436 gfc_error ("Double CLASS IS block in SELECT TYPE "
7437 "statement at %L", &c2
->ext
.case_list
->where
);
7440 if ((*c1
)->ext
.case_list
->ts
.u
.derived
->attr
.extension
7441 < c2
->ext
.case_list
->ts
.u
.derived
->attr
.extension
)
7444 (*c1
)->block
= c2
->block
;
7454 /* Generate IF chain. */
7455 if_st
= gfc_get_code ();
7456 if_st
->op
= EXEC_IF
;
7458 for (body
= class_is
; body
; body
= body
->block
)
7460 new_st
->block
= gfc_get_code ();
7461 new_st
= new_st
->block
;
7462 new_st
->op
= EXEC_IF
;
7463 /* Set up IF condition: Call _gfortran_is_extension_of. */
7464 new_st
->expr1
= gfc_get_expr ();
7465 new_st
->expr1
->expr_type
= EXPR_FUNCTION
;
7466 new_st
->expr1
->ts
.type
= BT_LOGICAL
;
7467 new_st
->expr1
->ts
.kind
= 4;
7468 new_st
->expr1
->value
.function
.name
= gfc_get_string (PREFIX ("is_extension_of"));
7469 new_st
->expr1
->value
.function
.isym
= XCNEW (gfc_intrinsic_sym
);
7470 new_st
->expr1
->value
.function
.isym
->id
= GFC_ISYM_EXTENDS_TYPE_OF
;
7471 /* Set up arguments. */
7472 new_st
->expr1
->value
.function
.actual
= gfc_get_actual_arglist ();
7473 new_st
->expr1
->value
.function
.actual
->expr
= gfc_get_variable_expr (code
->expr1
->symtree
);
7474 gfc_add_component_ref (new_st
->expr1
->value
.function
.actual
->expr
, "$vptr");
7475 vtab
= gfc_find_derived_vtab (body
->ext
.case_list
->ts
.u
.derived
);
7476 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
7477 new_st
->expr1
->value
.function
.actual
->next
= gfc_get_actual_arglist ();
7478 new_st
->expr1
->value
.function
.actual
->next
->expr
= gfc_get_variable_expr (st
);
7479 new_st
->next
= body
->next
;
7481 if (default_case
->next
)
7483 new_st
->block
= gfc_get_code ();
7484 new_st
= new_st
->block
;
7485 new_st
->op
= EXEC_IF
;
7486 new_st
->next
= default_case
->next
;
7489 /* Replace CLASS DEFAULT code by the IF chain. */
7490 default_case
->next
= if_st
;
7493 resolve_select (code
);
7498 /* Resolve a transfer statement. This is making sure that:
7499 -- a derived type being transferred has only non-pointer components
7500 -- a derived type being transferred doesn't have private components, unless
7501 it's being transferred from the module where the type was defined
7502 -- we're not trying to transfer a whole assumed size array. */
7505 resolve_transfer (gfc_code
*code
)
7514 if (exp
->expr_type
!= EXPR_VARIABLE
&& exp
->expr_type
!= EXPR_FUNCTION
)
7517 sym
= exp
->symtree
->n
.sym
;
7520 /* Go to actual component transferred. */
7521 for (ref
= code
->expr1
->ref
; ref
; ref
= ref
->next
)
7522 if (ref
->type
== REF_COMPONENT
)
7523 ts
= &ref
->u
.c
.component
->ts
;
7525 if (ts
->type
== BT_DERIVED
)
7527 /* Check that transferred derived type doesn't contain POINTER
7529 if (ts
->u
.derived
->attr
.pointer_comp
)
7531 gfc_error ("Data transfer element at %L cannot have "
7532 "POINTER components", &code
->loc
);
7536 if (ts
->u
.derived
->attr
.alloc_comp
)
7538 gfc_error ("Data transfer element at %L cannot have "
7539 "ALLOCATABLE components", &code
->loc
);
7543 if (derived_inaccessible (ts
->u
.derived
))
7545 gfc_error ("Data transfer element at %L cannot have "
7546 "PRIVATE components",&code
->loc
);
7551 if (sym
->as
!= NULL
&& sym
->as
->type
== AS_ASSUMED_SIZE
7552 && exp
->ref
->type
== REF_ARRAY
&& exp
->ref
->u
.ar
.type
== AR_FULL
)
7554 gfc_error ("Data transfer element at %L cannot be a full reference to "
7555 "an assumed-size array", &code
->loc
);
7561 /*********** Toplevel code resolution subroutines ***********/
7563 /* Find the set of labels that are reachable from this block. We also
7564 record the last statement in each block. */
7567 find_reachable_labels (gfc_code
*block
)
7574 cs_base
->reachable_labels
= bitmap_obstack_alloc (&labels_obstack
);
7576 /* Collect labels in this block. We don't keep those corresponding
7577 to END {IF|SELECT}, these are checked in resolve_branch by going
7578 up through the code_stack. */
7579 for (c
= block
; c
; c
= c
->next
)
7581 if (c
->here
&& c
->op
!= EXEC_END_BLOCK
)
7582 bitmap_set_bit (cs_base
->reachable_labels
, c
->here
->value
);
7585 /* Merge with labels from parent block. */
7588 gcc_assert (cs_base
->prev
->reachable_labels
);
7589 bitmap_ior_into (cs_base
->reachable_labels
,
7590 cs_base
->prev
->reachable_labels
);
7596 resolve_sync (gfc_code
*code
)
7598 /* Check imageset. The * case matches expr1 == NULL. */
7601 if (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
> 1)
7602 gfc_error ("Imageset argument at %L must be a scalar or rank-1 "
7603 "INTEGER expression", &code
->expr1
->where
);
7604 if (code
->expr1
->expr_type
== EXPR_CONSTANT
&& code
->expr1
->rank
== 0
7605 && mpz_cmp_si (code
->expr1
->value
.integer
, 1) < 0)
7606 gfc_error ("Imageset argument at %L must between 1 and num_images()",
7607 &code
->expr1
->where
);
7608 else if (code
->expr1
->expr_type
== EXPR_ARRAY
7609 && gfc_simplify_expr (code
->expr1
, 0) == SUCCESS
)
7611 gfc_constructor
*cons
;
7612 cons
= gfc_constructor_first (code
->expr1
->value
.constructor
);
7613 for (; cons
; cons
= gfc_constructor_next (cons
))
7614 if (cons
->expr
->expr_type
== EXPR_CONSTANT
7615 && mpz_cmp_si (cons
->expr
->value
.integer
, 1) < 0)
7616 gfc_error ("Imageset argument at %L must between 1 and "
7617 "num_images()", &cons
->expr
->where
);
7623 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
7624 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
7625 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
7626 &code
->expr2
->where
);
7630 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
7631 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
7632 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
7633 &code
->expr3
->where
);
7637 /* Given a branch to a label, see if the branch is conforming.
7638 The code node describes where the branch is located. */
7641 resolve_branch (gfc_st_label
*label
, gfc_code
*code
)
7648 /* Step one: is this a valid branching target? */
7650 if (label
->defined
== ST_LABEL_UNKNOWN
)
7652 gfc_error ("Label %d referenced at %L is never defined", label
->value
,
7657 if (label
->defined
!= ST_LABEL_TARGET
)
7659 gfc_error ("Statement at %L is not a valid branch target statement "
7660 "for the branch statement at %L", &label
->where
, &code
->loc
);
7664 /* Step two: make sure this branch is not a branch to itself ;-) */
7666 if (code
->here
== label
)
7668 gfc_warning ("Branch at %L may result in an infinite loop", &code
->loc
);
7672 /* Step three: See if the label is in the same block as the
7673 branching statement. The hard work has been done by setting up
7674 the bitmap reachable_labels. */
7676 if (bitmap_bit_p (cs_base
->reachable_labels
, label
->value
))
7678 /* Check now whether there is a CRITICAL construct; if so, check
7679 whether the label is still visible outside of the CRITICAL block,
7680 which is invalid. */
7681 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
7682 if (stack
->current
->op
== EXEC_CRITICAL
7683 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
7684 gfc_error ("GOTO statement at %L leaves CRITICAL construct for label"
7685 " at %L", &code
->loc
, &label
->where
);
7690 /* Step four: If we haven't found the label in the bitmap, it may
7691 still be the label of the END of the enclosing block, in which
7692 case we find it by going up the code_stack. */
7694 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
7696 if (stack
->current
->next
&& stack
->current
->next
->here
== label
)
7698 if (stack
->current
->op
== EXEC_CRITICAL
)
7700 /* Note: A label at END CRITICAL does not leave the CRITICAL
7701 construct as END CRITICAL is still part of it. */
7702 gfc_error ("GOTO statement at %L leaves CRITICAL construct for label"
7703 " at %L", &code
->loc
, &label
->where
);
7710 gcc_assert (stack
->current
->next
->op
== EXEC_END_BLOCK
);
7714 /* The label is not in an enclosing block, so illegal. This was
7715 allowed in Fortran 66, so we allow it as extension. No
7716 further checks are necessary in this case. */
7717 gfc_notify_std (GFC_STD_LEGACY
, "Label at %L is not in the same block "
7718 "as the GOTO statement at %L", &label
->where
,
7724 /* Check whether EXPR1 has the same shape as EXPR2. */
7727 resolve_where_shape (gfc_expr
*expr1
, gfc_expr
*expr2
)
7729 mpz_t shape
[GFC_MAX_DIMENSIONS
];
7730 mpz_t shape2
[GFC_MAX_DIMENSIONS
];
7731 gfc_try result
= FAILURE
;
7734 /* Compare the rank. */
7735 if (expr1
->rank
!= expr2
->rank
)
7738 /* Compare the size of each dimension. */
7739 for (i
=0; i
<expr1
->rank
; i
++)
7741 if (gfc_array_dimen_size (expr1
, i
, &shape
[i
]) == FAILURE
)
7744 if (gfc_array_dimen_size (expr2
, i
, &shape2
[i
]) == FAILURE
)
7747 if (mpz_cmp (shape
[i
], shape2
[i
]))
7751 /* When either of the two expression is an assumed size array, we
7752 ignore the comparison of dimension sizes. */
7757 for (i
--; i
>= 0; i
--)
7759 mpz_clear (shape
[i
]);
7760 mpz_clear (shape2
[i
]);
7766 /* Check whether a WHERE assignment target or a WHERE mask expression
7767 has the same shape as the outmost WHERE mask expression. */
7770 resolve_where (gfc_code
*code
, gfc_expr
*mask
)
7776 cblock
= code
->block
;
7778 /* Store the first WHERE mask-expr of the WHERE statement or construct.
7779 In case of nested WHERE, only the outmost one is stored. */
7780 if (mask
== NULL
) /* outmost WHERE */
7782 else /* inner WHERE */
7789 /* Check if the mask-expr has a consistent shape with the
7790 outmost WHERE mask-expr. */
7791 if (resolve_where_shape (cblock
->expr1
, e
) == FAILURE
)
7792 gfc_error ("WHERE mask at %L has inconsistent shape",
7793 &cblock
->expr1
->where
);
7796 /* the assignment statement of a WHERE statement, or the first
7797 statement in where-body-construct of a WHERE construct */
7798 cnext
= cblock
->next
;
7803 /* WHERE assignment statement */
7806 /* Check shape consistent for WHERE assignment target. */
7807 if (e
&& resolve_where_shape (cnext
->expr1
, e
) == FAILURE
)
7808 gfc_error ("WHERE assignment target at %L has "
7809 "inconsistent shape", &cnext
->expr1
->where
);
7813 case EXEC_ASSIGN_CALL
:
7814 resolve_call (cnext
);
7815 if (!cnext
->resolved_sym
->attr
.elemental
)
7816 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
7817 &cnext
->ext
.actual
->expr
->where
);
7820 /* WHERE or WHERE construct is part of a where-body-construct */
7822 resolve_where (cnext
, e
);
7826 gfc_error ("Unsupported statement inside WHERE at %L",
7829 /* the next statement within the same where-body-construct */
7830 cnext
= cnext
->next
;
7832 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
7833 cblock
= cblock
->block
;
7838 /* Resolve assignment in FORALL construct.
7839 NVAR is the number of FORALL index variables, and VAR_EXPR records the
7840 FORALL index variables. */
7843 gfc_resolve_assign_in_forall (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
7847 for (n
= 0; n
< nvar
; n
++)
7849 gfc_symbol
*forall_index
;
7851 forall_index
= var_expr
[n
]->symtree
->n
.sym
;
7853 /* Check whether the assignment target is one of the FORALL index
7855 if ((code
->expr1
->expr_type
== EXPR_VARIABLE
)
7856 && (code
->expr1
->symtree
->n
.sym
== forall_index
))
7857 gfc_error ("Assignment to a FORALL index variable at %L",
7858 &code
->expr1
->where
);
7861 /* If one of the FORALL index variables doesn't appear in the
7862 assignment variable, then there could be a many-to-one
7863 assignment. Emit a warning rather than an error because the
7864 mask could be resolving this problem. */
7865 if (find_forall_index (code
->expr1
, forall_index
, 0) == FAILURE
)
7866 gfc_warning ("The FORALL with index '%s' is not used on the "
7867 "left side of the assignment at %L and so might "
7868 "cause multiple assignment to this object",
7869 var_expr
[n
]->symtree
->name
, &code
->expr1
->where
);
7875 /* Resolve WHERE statement in FORALL construct. */
7878 gfc_resolve_where_code_in_forall (gfc_code
*code
, int nvar
,
7879 gfc_expr
**var_expr
)
7884 cblock
= code
->block
;
7887 /* the assignment statement of a WHERE statement, or the first
7888 statement in where-body-construct of a WHERE construct */
7889 cnext
= cblock
->next
;
7894 /* WHERE assignment statement */
7896 gfc_resolve_assign_in_forall (cnext
, nvar
, var_expr
);
7899 /* WHERE operator assignment statement */
7900 case EXEC_ASSIGN_CALL
:
7901 resolve_call (cnext
);
7902 if (!cnext
->resolved_sym
->attr
.elemental
)
7903 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
7904 &cnext
->ext
.actual
->expr
->where
);
7907 /* WHERE or WHERE construct is part of a where-body-construct */
7909 gfc_resolve_where_code_in_forall (cnext
, nvar
, var_expr
);
7913 gfc_error ("Unsupported statement inside WHERE at %L",
7916 /* the next statement within the same where-body-construct */
7917 cnext
= cnext
->next
;
7919 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
7920 cblock
= cblock
->block
;
7925 /* Traverse the FORALL body to check whether the following errors exist:
7926 1. For assignment, check if a many-to-one assignment happens.
7927 2. For WHERE statement, check the WHERE body to see if there is any
7928 many-to-one assignment. */
7931 gfc_resolve_forall_body (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
7935 c
= code
->block
->next
;
7941 case EXEC_POINTER_ASSIGN
:
7942 gfc_resolve_assign_in_forall (c
, nvar
, var_expr
);
7945 case EXEC_ASSIGN_CALL
:
7949 /* Because the gfc_resolve_blocks() will handle the nested FORALL,
7950 there is no need to handle it here. */
7954 gfc_resolve_where_code_in_forall(c
, nvar
, var_expr
);
7959 /* The next statement in the FORALL body. */
7965 /* Counts the number of iterators needed inside a forall construct, including
7966 nested forall constructs. This is used to allocate the needed memory
7967 in gfc_resolve_forall. */
7970 gfc_count_forall_iterators (gfc_code
*code
)
7972 int max_iters
, sub_iters
, current_iters
;
7973 gfc_forall_iterator
*fa
;
7975 gcc_assert(code
->op
== EXEC_FORALL
);
7979 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
7982 code
= code
->block
->next
;
7986 if (code
->op
== EXEC_FORALL
)
7988 sub_iters
= gfc_count_forall_iterators (code
);
7989 if (sub_iters
> max_iters
)
7990 max_iters
= sub_iters
;
7995 return current_iters
+ max_iters
;
7999 /* Given a FORALL construct, first resolve the FORALL iterator, then call
8000 gfc_resolve_forall_body to resolve the FORALL body. */
8003 gfc_resolve_forall (gfc_code
*code
, gfc_namespace
*ns
, int forall_save
)
8005 static gfc_expr
**var_expr
;
8006 static int total_var
= 0;
8007 static int nvar
= 0;
8009 gfc_forall_iterator
*fa
;
8014 /* Start to resolve a FORALL construct */
8015 if (forall_save
== 0)
8017 /* Count the total number of FORALL index in the nested FORALL
8018 construct in order to allocate the VAR_EXPR with proper size. */
8019 total_var
= gfc_count_forall_iterators (code
);
8021 /* Allocate VAR_EXPR with NUMBER_OF_FORALL_INDEX elements. */
8022 var_expr
= (gfc_expr
**) gfc_getmem (total_var
* sizeof (gfc_expr
*));
8025 /* The information about FORALL iterator, including FORALL index start, end
8026 and stride. The FORALL index can not appear in start, end or stride. */
8027 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
8029 /* Check if any outer FORALL index name is the same as the current
8031 for (i
= 0; i
< nvar
; i
++)
8033 if (fa
->var
->symtree
->n
.sym
== var_expr
[i
]->symtree
->n
.sym
)
8035 gfc_error ("An outer FORALL construct already has an index "
8036 "with this name %L", &fa
->var
->where
);
8040 /* Record the current FORALL index. */
8041 var_expr
[nvar
] = gfc_copy_expr (fa
->var
);
8045 /* No memory leak. */
8046 gcc_assert (nvar
<= total_var
);
8049 /* Resolve the FORALL body. */
8050 gfc_resolve_forall_body (code
, nvar
, var_expr
);
8052 /* May call gfc_resolve_forall to resolve the inner FORALL loop. */
8053 gfc_resolve_blocks (code
->block
, ns
);
8057 /* Free only the VAR_EXPRs allocated in this frame. */
8058 for (i
= nvar
; i
< tmp
; i
++)
8059 gfc_free_expr (var_expr
[i
]);
8063 /* We are in the outermost FORALL construct. */
8064 gcc_assert (forall_save
== 0);
8066 /* VAR_EXPR is not needed any more. */
8067 gfc_free (var_expr
);
8073 /* Resolve a BLOCK construct statement. */
8076 resolve_block_construct (gfc_code
* code
)
8078 /* For an ASSOCIATE block, the associations (and their targets) are already
8079 resolved during gfc_resolve_symbol. */
8081 /* Resolve the BLOCK's namespace. */
8082 gfc_resolve (code
->ext
.block
.ns
);
8086 /* Resolve lists of blocks found in IF, SELECT CASE, WHERE, FORALL, GOTO and
8089 static void resolve_code (gfc_code
*, gfc_namespace
*);
8092 gfc_resolve_blocks (gfc_code
*b
, gfc_namespace
*ns
)
8096 for (; b
; b
= b
->block
)
8098 t
= gfc_resolve_expr (b
->expr1
);
8099 if (gfc_resolve_expr (b
->expr2
) == FAILURE
)
8105 if (t
== SUCCESS
&& b
->expr1
!= NULL
8106 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
!= 0))
8107 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
8114 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
== 0))
8115 gfc_error ("WHERE/ELSEWHERE clause at %L requires a LOGICAL array",
8120 resolve_branch (b
->label1
, b
);
8124 resolve_block_construct (b
);
8128 case EXEC_SELECT_TYPE
:
8139 case EXEC_OMP_ATOMIC
:
8140 case EXEC_OMP_CRITICAL
:
8142 case EXEC_OMP_MASTER
:
8143 case EXEC_OMP_ORDERED
:
8144 case EXEC_OMP_PARALLEL
:
8145 case EXEC_OMP_PARALLEL_DO
:
8146 case EXEC_OMP_PARALLEL_SECTIONS
:
8147 case EXEC_OMP_PARALLEL_WORKSHARE
:
8148 case EXEC_OMP_SECTIONS
:
8149 case EXEC_OMP_SINGLE
:
8151 case EXEC_OMP_TASKWAIT
:
8152 case EXEC_OMP_WORKSHARE
:
8156 gfc_internal_error ("gfc_resolve_blocks(): Bad block type");
8159 resolve_code (b
->next
, ns
);
8164 /* Does everything to resolve an ordinary assignment. Returns true
8165 if this is an interface assignment. */
8167 resolve_ordinary_assign (gfc_code
*code
, gfc_namespace
*ns
)
8177 if (gfc_extend_assign (code
, ns
) == SUCCESS
)
8181 if (code
->op
== EXEC_ASSIGN_CALL
)
8183 lhs
= code
->ext
.actual
->expr
;
8184 rhsptr
= &code
->ext
.actual
->next
->expr
;
8188 gfc_actual_arglist
* args
;
8189 gfc_typebound_proc
* tbp
;
8191 gcc_assert (code
->op
== EXEC_COMPCALL
);
8193 args
= code
->expr1
->value
.compcall
.actual
;
8195 rhsptr
= &args
->next
->expr
;
8197 tbp
= code
->expr1
->value
.compcall
.tbp
;
8198 gcc_assert (!tbp
->is_generic
);
8201 /* Make a temporary rhs when there is a default initializer
8202 and rhs is the same symbol as the lhs. */
8203 if ((*rhsptr
)->expr_type
== EXPR_VARIABLE
8204 && (*rhsptr
)->symtree
->n
.sym
->ts
.type
== BT_DERIVED
8205 && gfc_has_default_initializer ((*rhsptr
)->symtree
->n
.sym
->ts
.u
.derived
)
8206 && (lhs
->symtree
->n
.sym
== (*rhsptr
)->symtree
->n
.sym
))
8207 *rhsptr
= gfc_get_parentheses (*rhsptr
);
8216 && gfc_notify_std (GFC_STD_GNU
, "Extension: BOZ literal at %L outside "
8217 "a DATA statement and outside INT/REAL/DBLE/CMPLX",
8218 &code
->loc
) == FAILURE
)
8221 /* Handle the case of a BOZ literal on the RHS. */
8222 if (rhs
->is_boz
&& lhs
->ts
.type
!= BT_INTEGER
)
8225 if (gfc_option
.warn_surprising
)
8226 gfc_warning ("BOZ literal at %L is bitwise transferred "
8227 "non-integer symbol '%s'", &code
->loc
,
8228 lhs
->symtree
->n
.sym
->name
);
8230 if (!gfc_convert_boz (rhs
, &lhs
->ts
))
8232 if ((rc
= gfc_range_check (rhs
)) != ARITH_OK
)
8234 if (rc
== ARITH_UNDERFLOW
)
8235 gfc_error ("Arithmetic underflow of bit-wise transferred BOZ at %L"
8236 ". This check can be disabled with the option "
8237 "-fno-range-check", &rhs
->where
);
8238 else if (rc
== ARITH_OVERFLOW
)
8239 gfc_error ("Arithmetic overflow of bit-wise transferred BOZ at %L"
8240 ". This check can be disabled with the option "
8241 "-fno-range-check", &rhs
->where
);
8242 else if (rc
== ARITH_NAN
)
8243 gfc_error ("Arithmetic NaN of bit-wise transferred BOZ at %L"
8244 ". This check can be disabled with the option "
8245 "-fno-range-check", &rhs
->where
);
8251 if (lhs
->ts
.type
== BT_CHARACTER
8252 && gfc_option
.warn_character_truncation
)
8254 if (lhs
->ts
.u
.cl
!= NULL
8255 && lhs
->ts
.u
.cl
->length
!= NULL
8256 && lhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
8257 llen
= mpz_get_si (lhs
->ts
.u
.cl
->length
->value
.integer
);
8259 if (rhs
->expr_type
== EXPR_CONSTANT
)
8260 rlen
= rhs
->value
.character
.length
;
8262 else if (rhs
->ts
.u
.cl
!= NULL
8263 && rhs
->ts
.u
.cl
->length
!= NULL
8264 && rhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
8265 rlen
= mpz_get_si (rhs
->ts
.u
.cl
->length
->value
.integer
);
8267 if (rlen
&& llen
&& rlen
> llen
)
8268 gfc_warning_now ("CHARACTER expression will be truncated "
8269 "in assignment (%d/%d) at %L",
8270 llen
, rlen
, &code
->loc
);
8273 /* Ensure that a vector index expression for the lvalue is evaluated
8274 to a temporary if the lvalue symbol is referenced in it. */
8277 for (ref
= lhs
->ref
; ref
; ref
= ref
->next
)
8278 if (ref
->type
== REF_ARRAY
)
8280 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
8281 if (ref
->u
.ar
.dimen_type
[n
] == DIMEN_VECTOR
8282 && gfc_find_sym_in_expr (lhs
->symtree
->n
.sym
,
8283 ref
->u
.ar
.start
[n
]))
8285 = gfc_get_parentheses (ref
->u
.ar
.start
[n
]);
8289 if (gfc_pure (NULL
))
8291 if (gfc_impure_variable (lhs
->symtree
->n
.sym
))
8293 gfc_error ("Cannot assign to variable '%s' in PURE "
8295 lhs
->symtree
->n
.sym
->name
,
8300 if (lhs
->ts
.type
== BT_DERIVED
8301 && lhs
->expr_type
== EXPR_VARIABLE
8302 && lhs
->ts
.u
.derived
->attr
.pointer_comp
8303 && rhs
->expr_type
== EXPR_VARIABLE
8304 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
8305 || gfc_is_coindexed (rhs
)))
8308 if (gfc_is_coindexed (rhs
))
8309 gfc_error ("Coindexed expression at %L is assigned to "
8310 "a derived type variable with a POINTER "
8311 "component in a PURE procedure",
8314 gfc_error ("The impure variable at %L is assigned to "
8315 "a derived type variable with a POINTER "
8316 "component in a PURE procedure (12.6)",
8321 /* Fortran 2008, C1283. */
8322 if (gfc_is_coindexed (lhs
))
8324 gfc_error ("Assignment to coindexed variable at %L in a PURE "
8325 "procedure", &rhs
->where
);
8331 /* FIXME: Valid in Fortran 2008, unless the LHS is both polymorphic
8332 and coindexed; cf. F2008, 7.2.1.2 and PR 43366. */
8333 if (lhs
->ts
.type
== BT_CLASS
)
8335 gfc_error ("Variable must not be polymorphic in assignment at %L",
8340 /* F2008, Section 7.2.1.2. */
8341 if (gfc_is_coindexed (lhs
) && gfc_has_ultimate_allocatable (lhs
))
8343 gfc_error ("Coindexed variable must not be have an allocatable ultimate "
8344 "component in assignment at %L", &lhs
->where
);
8348 gfc_check_assign (lhs
, rhs
, 1);
8353 /* Given a block of code, recursively resolve everything pointed to by this
8357 resolve_code (gfc_code
*code
, gfc_namespace
*ns
)
8359 int omp_workshare_save
;
8364 frame
.prev
= cs_base
;
8368 find_reachable_labels (code
);
8370 for (; code
; code
= code
->next
)
8372 frame
.current
= code
;
8373 forall_save
= forall_flag
;
8375 if (code
->op
== EXEC_FORALL
)
8378 gfc_resolve_forall (code
, ns
, forall_save
);
8381 else if (code
->block
)
8383 omp_workshare_save
= -1;
8386 case EXEC_OMP_PARALLEL_WORKSHARE
:
8387 omp_workshare_save
= omp_workshare_flag
;
8388 omp_workshare_flag
= 1;
8389 gfc_resolve_omp_parallel_blocks (code
, ns
);
8391 case EXEC_OMP_PARALLEL
:
8392 case EXEC_OMP_PARALLEL_DO
:
8393 case EXEC_OMP_PARALLEL_SECTIONS
:
8395 omp_workshare_save
= omp_workshare_flag
;
8396 omp_workshare_flag
= 0;
8397 gfc_resolve_omp_parallel_blocks (code
, ns
);
8400 gfc_resolve_omp_do_blocks (code
, ns
);
8402 case EXEC_SELECT_TYPE
:
8403 gfc_current_ns
= code
->ext
.block
.ns
;
8404 gfc_resolve_blocks (code
->block
, gfc_current_ns
);
8405 gfc_current_ns
= ns
;
8407 case EXEC_OMP_WORKSHARE
:
8408 omp_workshare_save
= omp_workshare_flag
;
8409 omp_workshare_flag
= 1;
8412 gfc_resolve_blocks (code
->block
, ns
);
8416 if (omp_workshare_save
!= -1)
8417 omp_workshare_flag
= omp_workshare_save
;
8421 if (code
->op
!= EXEC_COMPCALL
&& code
->op
!= EXEC_CALL_PPC
)
8422 t
= gfc_resolve_expr (code
->expr1
);
8423 forall_flag
= forall_save
;
8425 if (gfc_resolve_expr (code
->expr2
) == FAILURE
)
8428 if (code
->op
== EXEC_ALLOCATE
8429 && gfc_resolve_expr (code
->expr3
) == FAILURE
)
8435 case EXEC_END_BLOCK
:
8439 case EXEC_ERROR_STOP
:
8443 case EXEC_ASSIGN_CALL
:
8448 case EXEC_SYNC_IMAGES
:
8449 case EXEC_SYNC_MEMORY
:
8450 resolve_sync (code
);
8454 /* Keep track of which entry we are up to. */
8455 current_entry_id
= code
->ext
.entry
->id
;
8459 resolve_where (code
, NULL
);
8463 if (code
->expr1
!= NULL
)
8465 if (code
->expr1
->ts
.type
!= BT_INTEGER
)
8466 gfc_error ("ASSIGNED GOTO statement at %L requires an "
8467 "INTEGER variable", &code
->expr1
->where
);
8468 else if (code
->expr1
->symtree
->n
.sym
->attr
.assign
!= 1)
8469 gfc_error ("Variable '%s' has not been assigned a target "
8470 "label at %L", code
->expr1
->symtree
->n
.sym
->name
,
8471 &code
->expr1
->where
);
8474 resolve_branch (code
->label1
, code
);
8478 if (code
->expr1
!= NULL
8479 && (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
))
8480 gfc_error ("Alternate RETURN statement at %L requires a SCALAR-"
8481 "INTEGER return specifier", &code
->expr1
->where
);
8484 case EXEC_INIT_ASSIGN
:
8485 case EXEC_END_PROCEDURE
:
8492 if (resolve_ordinary_assign (code
, ns
))
8494 if (code
->op
== EXEC_COMPCALL
)
8501 case EXEC_LABEL_ASSIGN
:
8502 if (code
->label1
->defined
== ST_LABEL_UNKNOWN
)
8503 gfc_error ("Label %d referenced at %L is never defined",
8504 code
->label1
->value
, &code
->label1
->where
);
8506 && (code
->expr1
->expr_type
!= EXPR_VARIABLE
8507 || code
->expr1
->symtree
->n
.sym
->ts
.type
!= BT_INTEGER
8508 || code
->expr1
->symtree
->n
.sym
->ts
.kind
8509 != gfc_default_integer_kind
8510 || code
->expr1
->symtree
->n
.sym
->as
!= NULL
))
8511 gfc_error ("ASSIGN statement at %L requires a scalar "
8512 "default INTEGER variable", &code
->expr1
->where
);
8515 case EXEC_POINTER_ASSIGN
:
8519 gfc_check_pointer_assign (code
->expr1
, code
->expr2
);
8522 case EXEC_ARITHMETIC_IF
:
8524 && code
->expr1
->ts
.type
!= BT_INTEGER
8525 && code
->expr1
->ts
.type
!= BT_REAL
)
8526 gfc_error ("Arithmetic IF statement at %L requires a numeric "
8527 "expression", &code
->expr1
->where
);
8529 resolve_branch (code
->label1
, code
);
8530 resolve_branch (code
->label2
, code
);
8531 resolve_branch (code
->label3
, code
);
8535 if (t
== SUCCESS
&& code
->expr1
!= NULL
8536 && (code
->expr1
->ts
.type
!= BT_LOGICAL
8537 || code
->expr1
->rank
!= 0))
8538 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
8539 &code
->expr1
->where
);
8544 resolve_call (code
);
8549 resolve_typebound_subroutine (code
);
8553 resolve_ppc_call (code
);
8557 /* Select is complicated. Also, a SELECT construct could be
8558 a transformed computed GOTO. */
8559 resolve_select (code
);
8562 case EXEC_SELECT_TYPE
:
8563 resolve_select_type (code
);
8567 gfc_resolve (code
->ext
.block
.ns
);
8571 if (code
->ext
.iterator
!= NULL
)
8573 gfc_iterator
*iter
= code
->ext
.iterator
;
8574 if (gfc_resolve_iterator (iter
, true) != FAILURE
)
8575 gfc_resolve_do_iterator (code
, iter
->var
->symtree
->n
.sym
);
8580 if (code
->expr1
== NULL
)
8581 gfc_internal_error ("resolve_code(): No expression on DO WHILE");
8583 && (code
->expr1
->rank
!= 0
8584 || code
->expr1
->ts
.type
!= BT_LOGICAL
))
8585 gfc_error ("Exit condition of DO WHILE loop at %L must be "
8586 "a scalar LOGICAL expression", &code
->expr1
->where
);
8591 resolve_allocate_deallocate (code
, "ALLOCATE");
8595 case EXEC_DEALLOCATE
:
8597 resolve_allocate_deallocate (code
, "DEALLOCATE");
8602 if (gfc_resolve_open (code
->ext
.open
) == FAILURE
)
8605 resolve_branch (code
->ext
.open
->err
, code
);
8609 if (gfc_resolve_close (code
->ext
.close
) == FAILURE
)
8612 resolve_branch (code
->ext
.close
->err
, code
);
8615 case EXEC_BACKSPACE
:
8619 if (gfc_resolve_filepos (code
->ext
.filepos
) == FAILURE
)
8622 resolve_branch (code
->ext
.filepos
->err
, code
);
8626 if (gfc_resolve_inquire (code
->ext
.inquire
) == FAILURE
)
8629 resolve_branch (code
->ext
.inquire
->err
, code
);
8633 gcc_assert (code
->ext
.inquire
!= NULL
);
8634 if (gfc_resolve_inquire (code
->ext
.inquire
) == FAILURE
)
8637 resolve_branch (code
->ext
.inquire
->err
, code
);
8641 if (gfc_resolve_wait (code
->ext
.wait
) == FAILURE
)
8644 resolve_branch (code
->ext
.wait
->err
, code
);
8645 resolve_branch (code
->ext
.wait
->end
, code
);
8646 resolve_branch (code
->ext
.wait
->eor
, code
);
8651 if (gfc_resolve_dt (code
->ext
.dt
, &code
->loc
) == FAILURE
)
8654 resolve_branch (code
->ext
.dt
->err
, code
);
8655 resolve_branch (code
->ext
.dt
->end
, code
);
8656 resolve_branch (code
->ext
.dt
->eor
, code
);
8660 resolve_transfer (code
);
8664 resolve_forall_iterators (code
->ext
.forall_iterator
);
8666 if (code
->expr1
!= NULL
&& code
->expr1
->ts
.type
!= BT_LOGICAL
)
8667 gfc_error ("FORALL mask clause at %L requires a LOGICAL "
8668 "expression", &code
->expr1
->where
);
8671 case EXEC_OMP_ATOMIC
:
8672 case EXEC_OMP_BARRIER
:
8673 case EXEC_OMP_CRITICAL
:
8674 case EXEC_OMP_FLUSH
:
8676 case EXEC_OMP_MASTER
:
8677 case EXEC_OMP_ORDERED
:
8678 case EXEC_OMP_SECTIONS
:
8679 case EXEC_OMP_SINGLE
:
8680 case EXEC_OMP_TASKWAIT
:
8681 case EXEC_OMP_WORKSHARE
:
8682 gfc_resolve_omp_directive (code
, ns
);
8685 case EXEC_OMP_PARALLEL
:
8686 case EXEC_OMP_PARALLEL_DO
:
8687 case EXEC_OMP_PARALLEL_SECTIONS
:
8688 case EXEC_OMP_PARALLEL_WORKSHARE
:
8690 omp_workshare_save
= omp_workshare_flag
;
8691 omp_workshare_flag
= 0;
8692 gfc_resolve_omp_directive (code
, ns
);
8693 omp_workshare_flag
= omp_workshare_save
;
8697 gfc_internal_error ("resolve_code(): Bad statement code");
8701 cs_base
= frame
.prev
;
8705 /* Resolve initial values and make sure they are compatible with
8709 resolve_values (gfc_symbol
*sym
)
8711 if (sym
->value
== NULL
)
8714 if (gfc_resolve_expr (sym
->value
) == FAILURE
)
8717 gfc_check_assign_symbol (sym
, sym
->value
);
8721 /* Verify the binding labels for common blocks that are BIND(C). The label
8722 for a BIND(C) common block must be identical in all scoping units in which
8723 the common block is declared. Further, the binding label can not collide
8724 with any other global entity in the program. */
8727 resolve_bind_c_comms (gfc_symtree
*comm_block_tree
)
8729 if (comm_block_tree
->n
.common
->is_bind_c
== 1)
8731 gfc_gsymbol
*binding_label_gsym
;
8732 gfc_gsymbol
*comm_name_gsym
;
8734 /* See if a global symbol exists by the common block's name. It may
8735 be NULL if the common block is use-associated. */
8736 comm_name_gsym
= gfc_find_gsymbol (gfc_gsym_root
,
8737 comm_block_tree
->n
.common
->name
);
8738 if (comm_name_gsym
!= NULL
&& comm_name_gsym
->type
!= GSYM_COMMON
)
8739 gfc_error ("Binding label '%s' for common block '%s' at %L collides "
8740 "with the global entity '%s' at %L",
8741 comm_block_tree
->n
.common
->binding_label
,
8742 comm_block_tree
->n
.common
->name
,
8743 &(comm_block_tree
->n
.common
->where
),
8744 comm_name_gsym
->name
, &(comm_name_gsym
->where
));
8745 else if (comm_name_gsym
!= NULL
8746 && strcmp (comm_name_gsym
->name
,
8747 comm_block_tree
->n
.common
->name
) == 0)
8749 /* TODO: Need to make sure the fields of gfc_gsymbol are initialized
8751 if (comm_name_gsym
->binding_label
== NULL
)
8752 /* No binding label for common block stored yet; save this one. */
8753 comm_name_gsym
->binding_label
=
8754 comm_block_tree
->n
.common
->binding_label
;
8756 if (strcmp (comm_name_gsym
->binding_label
,
8757 comm_block_tree
->n
.common
->binding_label
) != 0)
8759 /* Common block names match but binding labels do not. */
8760 gfc_error ("Binding label '%s' for common block '%s' at %L "
8761 "does not match the binding label '%s' for common "
8763 comm_block_tree
->n
.common
->binding_label
,
8764 comm_block_tree
->n
.common
->name
,
8765 &(comm_block_tree
->n
.common
->where
),
8766 comm_name_gsym
->binding_label
,
8767 comm_name_gsym
->name
,
8768 &(comm_name_gsym
->where
));
8773 /* There is no binding label (NAME="") so we have nothing further to
8774 check and nothing to add as a global symbol for the label. */
8775 if (comm_block_tree
->n
.common
->binding_label
[0] == '\0' )
8778 binding_label_gsym
=
8779 gfc_find_gsymbol (gfc_gsym_root
,
8780 comm_block_tree
->n
.common
->binding_label
);
8781 if (binding_label_gsym
== NULL
)
8783 /* Need to make a global symbol for the binding label to prevent
8784 it from colliding with another. */
8785 binding_label_gsym
=
8786 gfc_get_gsymbol (comm_block_tree
->n
.common
->binding_label
);
8787 binding_label_gsym
->sym_name
= comm_block_tree
->n
.common
->name
;
8788 binding_label_gsym
->type
= GSYM_COMMON
;
8792 /* If comm_name_gsym is NULL, the name common block is use
8793 associated and the name could be colliding. */
8794 if (binding_label_gsym
->type
!= GSYM_COMMON
)
8795 gfc_error ("Binding label '%s' for common block '%s' at %L "
8796 "collides with the global entity '%s' at %L",
8797 comm_block_tree
->n
.common
->binding_label
,
8798 comm_block_tree
->n
.common
->name
,
8799 &(comm_block_tree
->n
.common
->where
),
8800 binding_label_gsym
->name
,
8801 &(binding_label_gsym
->where
));
8802 else if (comm_name_gsym
!= NULL
8803 && (strcmp (binding_label_gsym
->name
,
8804 comm_name_gsym
->binding_label
) != 0)
8805 && (strcmp (binding_label_gsym
->sym_name
,
8806 comm_name_gsym
->name
) != 0))
8807 gfc_error ("Binding label '%s' for common block '%s' at %L "
8808 "collides with global entity '%s' at %L",
8809 binding_label_gsym
->name
, binding_label_gsym
->sym_name
,
8810 &(comm_block_tree
->n
.common
->where
),
8811 comm_name_gsym
->name
, &(comm_name_gsym
->where
));
8819 /* Verify any BIND(C) derived types in the namespace so we can report errors
8820 for them once, rather than for each variable declared of that type. */
8823 resolve_bind_c_derived_types (gfc_symbol
*derived_sym
)
8825 if (derived_sym
!= NULL
&& derived_sym
->attr
.flavor
== FL_DERIVED
8826 && derived_sym
->attr
.is_bind_c
== 1)
8827 verify_bind_c_derived_type (derived_sym
);
8833 /* Verify that any binding labels used in a given namespace do not collide
8834 with the names or binding labels of any global symbols. */
8837 gfc_verify_binding_labels (gfc_symbol
*sym
)
8841 if (sym
!= NULL
&& sym
->attr
.is_bind_c
&& sym
->attr
.is_iso_c
== 0
8842 && sym
->attr
.flavor
!= FL_DERIVED
&& sym
->binding_label
[0] != '\0')
8844 gfc_gsymbol
*bind_c_sym
;
8846 bind_c_sym
= gfc_find_gsymbol (gfc_gsym_root
, sym
->binding_label
);
8847 if (bind_c_sym
!= NULL
8848 && strcmp (bind_c_sym
->name
, sym
->binding_label
) == 0)
8850 if (sym
->attr
.if_source
== IFSRC_DECL
8851 && (bind_c_sym
->type
!= GSYM_SUBROUTINE
8852 && bind_c_sym
->type
!= GSYM_FUNCTION
)
8853 && ((sym
->attr
.contained
== 1
8854 && strcmp (bind_c_sym
->sym_name
, sym
->name
) != 0)
8855 || (sym
->attr
.use_assoc
== 1
8856 && (strcmp (bind_c_sym
->mod_name
, sym
->module
) != 0))))
8858 /* Make sure global procedures don't collide with anything. */
8859 gfc_error ("Binding label '%s' at %L collides with the global "
8860 "entity '%s' at %L", sym
->binding_label
,
8861 &(sym
->declared_at
), bind_c_sym
->name
,
8862 &(bind_c_sym
->where
));
8865 else if (sym
->attr
.contained
== 0
8866 && (sym
->attr
.if_source
== IFSRC_IFBODY
8867 && sym
->attr
.flavor
== FL_PROCEDURE
)
8868 && (bind_c_sym
->sym_name
!= NULL
8869 && strcmp (bind_c_sym
->sym_name
, sym
->name
) != 0))
8871 /* Make sure procedures in interface bodies don't collide. */
8872 gfc_error ("Binding label '%s' in interface body at %L collides "
8873 "with the global entity '%s' at %L",
8875 &(sym
->declared_at
), bind_c_sym
->name
,
8876 &(bind_c_sym
->where
));
8879 else if (sym
->attr
.contained
== 0
8880 && sym
->attr
.if_source
== IFSRC_UNKNOWN
)
8881 if ((sym
->attr
.use_assoc
&& bind_c_sym
->mod_name
8882 && strcmp (bind_c_sym
->mod_name
, sym
->module
) != 0)
8883 || sym
->attr
.use_assoc
== 0)
8885 gfc_error ("Binding label '%s' at %L collides with global "
8886 "entity '%s' at %L", sym
->binding_label
,
8887 &(sym
->declared_at
), bind_c_sym
->name
,
8888 &(bind_c_sym
->where
));
8893 /* Clear the binding label to prevent checking multiple times. */
8894 sym
->binding_label
[0] = '\0';
8896 else if (bind_c_sym
== NULL
)
8898 bind_c_sym
= gfc_get_gsymbol (sym
->binding_label
);
8899 bind_c_sym
->where
= sym
->declared_at
;
8900 bind_c_sym
->sym_name
= sym
->name
;
8902 if (sym
->attr
.use_assoc
== 1)
8903 bind_c_sym
->mod_name
= sym
->module
;
8905 if (sym
->ns
->proc_name
!= NULL
)
8906 bind_c_sym
->mod_name
= sym
->ns
->proc_name
->name
;
8908 if (sym
->attr
.contained
== 0)
8910 if (sym
->attr
.subroutine
)
8911 bind_c_sym
->type
= GSYM_SUBROUTINE
;
8912 else if (sym
->attr
.function
)
8913 bind_c_sym
->type
= GSYM_FUNCTION
;
8921 /* Resolve an index expression. */
8924 resolve_index_expr (gfc_expr
*e
)
8926 if (gfc_resolve_expr (e
) == FAILURE
)
8929 if (gfc_simplify_expr (e
, 0) == FAILURE
)
8932 if (gfc_specification_expr (e
) == FAILURE
)
8938 /* Resolve a charlen structure. */
8941 resolve_charlen (gfc_charlen
*cl
)
8950 specification_expr
= 1;
8952 if (resolve_index_expr (cl
->length
) == FAILURE
)
8954 specification_expr
= 0;
8958 /* "If the character length parameter value evaluates to a negative
8959 value, the length of character entities declared is zero." */
8960 if (cl
->length
&& !gfc_extract_int (cl
->length
, &i
) && i
< 0)
8962 if (gfc_option
.warn_surprising
)
8963 gfc_warning_now ("CHARACTER variable at %L has negative length %d,"
8964 " the length has been set to zero",
8965 &cl
->length
->where
, i
);
8966 gfc_replace_expr (cl
->length
,
8967 gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 0));
8970 /* Check that the character length is not too large. */
8971 k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
8972 if (cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
8973 && cl
->length
->ts
.type
== BT_INTEGER
8974 && mpz_cmp (cl
->length
->value
.integer
, gfc_integer_kinds
[k
].huge
) > 0)
8976 gfc_error ("String length at %L is too large", &cl
->length
->where
);
8984 /* Test for non-constant shape arrays. */
8987 is_non_constant_shape_array (gfc_symbol
*sym
)
8993 not_constant
= false;
8994 if (sym
->as
!= NULL
)
8996 /* Unfortunately, !gfc_is_compile_time_shape hits a legal case that
8997 has not been simplified; parameter array references. Do the
8998 simplification now. */
8999 for (i
= 0; i
< sym
->as
->rank
+ sym
->as
->corank
; i
++)
9001 e
= sym
->as
->lower
[i
];
9002 if (e
&& (resolve_index_expr (e
) == FAILURE
9003 || !gfc_is_constant_expr (e
)))
9004 not_constant
= true;
9005 e
= sym
->as
->upper
[i
];
9006 if (e
&& (resolve_index_expr (e
) == FAILURE
9007 || !gfc_is_constant_expr (e
)))
9008 not_constant
= true;
9011 return not_constant
;
9014 /* Given a symbol and an initialization expression, add code to initialize
9015 the symbol to the function entry. */
9017 build_init_assign (gfc_symbol
*sym
, gfc_expr
*init
)
9021 gfc_namespace
*ns
= sym
->ns
;
9023 /* Search for the function namespace if this is a contained
9024 function without an explicit result. */
9025 if (sym
->attr
.function
&& sym
== sym
->result
9026 && sym
->name
!= sym
->ns
->proc_name
->name
)
9029 for (;ns
; ns
= ns
->sibling
)
9030 if (strcmp (ns
->proc_name
->name
, sym
->name
) == 0)
9036 gfc_free_expr (init
);
9040 /* Build an l-value expression for the result. */
9041 lval
= gfc_lval_expr_from_sym (sym
);
9043 /* Add the code at scope entry. */
9044 init_st
= gfc_get_code ();
9045 init_st
->next
= ns
->code
;
9048 /* Assign the default initializer to the l-value. */
9049 init_st
->loc
= sym
->declared_at
;
9050 init_st
->op
= EXEC_INIT_ASSIGN
;
9051 init_st
->expr1
= lval
;
9052 init_st
->expr2
= init
;
9055 /* Assign the default initializer to a derived type variable or result. */
9058 apply_default_init (gfc_symbol
*sym
)
9060 gfc_expr
*init
= NULL
;
9062 if (sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
9065 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
)
9066 init
= gfc_default_initializer (&sym
->ts
);
9071 build_init_assign (sym
, init
);
9074 /* Build an initializer for a local integer, real, complex, logical, or
9075 character variable, based on the command line flags finit-local-zero,
9076 finit-integer=, finit-real=, finit-logical=, and finit-runtime. Returns
9077 null if the symbol should not have a default initialization. */
9079 build_default_init_expr (gfc_symbol
*sym
)
9082 gfc_expr
*init_expr
;
9085 /* These symbols should never have a default initialization. */
9086 if ((sym
->attr
.dimension
&& !gfc_is_compile_time_shape (sym
->as
))
9087 || sym
->attr
.external
9089 || sym
->attr
.pointer
9090 || sym
->attr
.in_equivalence
9091 || sym
->attr
.in_common
9094 || sym
->attr
.cray_pointee
9095 || sym
->attr
.cray_pointer
)
9098 /* Now we'll try to build an initializer expression. */
9099 init_expr
= gfc_get_constant_expr (sym
->ts
.type
, sym
->ts
.kind
,
9102 /* We will only initialize integers, reals, complex, logicals, and
9103 characters, and only if the corresponding command-line flags
9104 were set. Otherwise, we free init_expr and return null. */
9105 switch (sym
->ts
.type
)
9108 if (gfc_option
.flag_init_integer
!= GFC_INIT_INTEGER_OFF
)
9109 mpz_set_si (init_expr
->value
.integer
,
9110 gfc_option
.flag_init_integer_value
);
9113 gfc_free_expr (init_expr
);
9119 switch (gfc_option
.flag_init_real
)
9121 case GFC_INIT_REAL_SNAN
:
9122 init_expr
->is_snan
= 1;
9124 case GFC_INIT_REAL_NAN
:
9125 mpfr_set_nan (init_expr
->value
.real
);
9128 case GFC_INIT_REAL_INF
:
9129 mpfr_set_inf (init_expr
->value
.real
, 1);
9132 case GFC_INIT_REAL_NEG_INF
:
9133 mpfr_set_inf (init_expr
->value
.real
, -1);
9136 case GFC_INIT_REAL_ZERO
:
9137 mpfr_set_ui (init_expr
->value
.real
, 0.0, GFC_RND_MODE
);
9141 gfc_free_expr (init_expr
);
9148 switch (gfc_option
.flag_init_real
)
9150 case GFC_INIT_REAL_SNAN
:
9151 init_expr
->is_snan
= 1;
9153 case GFC_INIT_REAL_NAN
:
9154 mpfr_set_nan (mpc_realref (init_expr
->value
.complex));
9155 mpfr_set_nan (mpc_imagref (init_expr
->value
.complex));
9158 case GFC_INIT_REAL_INF
:
9159 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), 1);
9160 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), 1);
9163 case GFC_INIT_REAL_NEG_INF
:
9164 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), -1);
9165 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), -1);
9168 case GFC_INIT_REAL_ZERO
:
9169 mpc_set_ui (init_expr
->value
.complex, 0, GFC_MPC_RND_MODE
);
9173 gfc_free_expr (init_expr
);
9180 if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_FALSE
)
9181 init_expr
->value
.logical
= 0;
9182 else if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_TRUE
)
9183 init_expr
->value
.logical
= 1;
9186 gfc_free_expr (init_expr
);
9192 /* For characters, the length must be constant in order to
9193 create a default initializer. */
9194 if (gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
9195 && sym
->ts
.u
.cl
->length
9196 && sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9198 char_len
= mpz_get_si (sym
->ts
.u
.cl
->length
->value
.integer
);
9199 init_expr
->value
.character
.length
= char_len
;
9200 init_expr
->value
.character
.string
= gfc_get_wide_string (char_len
+1);
9201 for (i
= 0; i
< char_len
; i
++)
9202 init_expr
->value
.character
.string
[i
]
9203 = (unsigned char) gfc_option
.flag_init_character_value
;
9207 gfc_free_expr (init_expr
);
9213 gfc_free_expr (init_expr
);
9219 /* Add an initialization expression to a local variable. */
9221 apply_default_init_local (gfc_symbol
*sym
)
9223 gfc_expr
*init
= NULL
;
9225 /* The symbol should be a variable or a function return value. */
9226 if ((sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
9227 || (sym
->attr
.function
&& sym
->result
!= sym
))
9230 /* Try to build the initializer expression. If we can't initialize
9231 this symbol, then init will be NULL. */
9232 init
= build_default_init_expr (sym
);
9236 /* For saved variables, we don't want to add an initializer at
9237 function entry, so we just add a static initializer. */
9238 if (sym
->attr
.save
|| sym
->ns
->save_all
9239 || gfc_option
.flag_max_stack_var_size
== 0)
9241 /* Don't clobber an existing initializer! */
9242 gcc_assert (sym
->value
== NULL
);
9247 build_init_assign (sym
, init
);
9250 /* Resolution of common features of flavors variable and procedure. */
9253 resolve_fl_var_and_proc (gfc_symbol
*sym
, int mp_flag
)
9255 /* Constraints on deferred shape variable. */
9256 if (sym
->as
== NULL
|| sym
->as
->type
!= AS_DEFERRED
)
9258 if (sym
->attr
.allocatable
)
9260 if (sym
->attr
.dimension
)
9262 gfc_error ("Allocatable array '%s' at %L must have "
9263 "a deferred shape", sym
->name
, &sym
->declared_at
);
9266 else if (gfc_notify_std (GFC_STD_F2003
, "Scalar object '%s' at %L "
9267 "may not be ALLOCATABLE", sym
->name
,
9268 &sym
->declared_at
) == FAILURE
)
9272 if (sym
->attr
.pointer
&& sym
->attr
.dimension
)
9274 gfc_error ("Array pointer '%s' at %L must have a deferred shape",
9275 sym
->name
, &sym
->declared_at
);
9282 if (!mp_flag
&& !sym
->attr
.allocatable
&& !sym
->attr
.pointer
9283 && !sym
->attr
.dummy
&& sym
->ts
.type
!= BT_CLASS
)
9285 gfc_error ("Array '%s' at %L cannot have a deferred shape",
9286 sym
->name
, &sym
->declared_at
);
9291 /* Constraints on polymorphic variables. */
9292 if (sym
->ts
.type
== BT_CLASS
&& !(sym
->result
&& sym
->result
!= sym
))
9295 if (sym
->attr
.class_ok
9296 && !gfc_type_is_extensible (CLASS_DATA (sym
)->ts
.u
.derived
))
9298 gfc_error ("Type '%s' of CLASS variable '%s' at %L is not extensible",
9299 CLASS_DATA (sym
)->ts
.u
.derived
->name
, sym
->name
,
9305 /* Assume that use associated symbols were checked in the module ns. */
9306 if (!sym
->attr
.class_ok
&& !sym
->attr
.use_assoc
)
9308 gfc_error ("CLASS variable '%s' at %L must be dummy, allocatable "
9309 "or pointer", sym
->name
, &sym
->declared_at
);
9318 /* Additional checks for symbols with flavor variable and derived
9319 type. To be called from resolve_fl_variable. */
9322 resolve_fl_variable_derived (gfc_symbol
*sym
, int no_init_flag
)
9324 gcc_assert (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
);
9326 /* Check to see if a derived type is blocked from being host
9327 associated by the presence of another class I symbol in the same
9328 namespace. 14.6.1.3 of the standard and the discussion on
9329 comp.lang.fortran. */
9330 if (sym
->ns
!= sym
->ts
.u
.derived
->ns
9331 && sym
->ns
->proc_name
->attr
.if_source
!= IFSRC_IFBODY
)
9334 gfc_find_symbol (sym
->ts
.u
.derived
->name
, sym
->ns
, 0, &s
);
9335 if (s
&& s
->attr
.flavor
!= FL_DERIVED
)
9337 gfc_error ("The type '%s' cannot be host associated at %L "
9338 "because it is blocked by an incompatible object "
9339 "of the same name declared at %L",
9340 sym
->ts
.u
.derived
->name
, &sym
->declared_at
,
9346 /* 4th constraint in section 11.3: "If an object of a type for which
9347 component-initialization is specified (R429) appears in the
9348 specification-part of a module and does not have the ALLOCATABLE
9349 or POINTER attribute, the object shall have the SAVE attribute."
9351 The check for initializers is performed with
9352 gfc_has_default_initializer because gfc_default_initializer generates
9353 a hidden default for allocatable components. */
9354 if (!(sym
->value
|| no_init_flag
) && sym
->ns
->proc_name
9355 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
9356 && !sym
->ns
->save_all
&& !sym
->attr
.save
9357 && !sym
->attr
.pointer
&& !sym
->attr
.allocatable
9358 && gfc_has_default_initializer (sym
->ts
.u
.derived
)
9359 && gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: Implied SAVE for "
9360 "module variable '%s' at %L, needed due to "
9361 "the default initialization", sym
->name
,
9362 &sym
->declared_at
) == FAILURE
)
9365 /* Assign default initializer. */
9366 if (!(sym
->value
|| sym
->attr
.pointer
|| sym
->attr
.allocatable
)
9367 && (!no_init_flag
|| sym
->attr
.intent
== INTENT_OUT
))
9369 sym
->value
= gfc_default_initializer (&sym
->ts
);
9376 /* Resolve symbols with flavor variable. */
9379 resolve_fl_variable (gfc_symbol
*sym
, int mp_flag
)
9381 int no_init_flag
, automatic_flag
;
9383 const char *auto_save_msg
;
9385 auto_save_msg
= "Automatic object '%s' at %L cannot have the "
9388 if (resolve_fl_var_and_proc (sym
, mp_flag
) == FAILURE
)
9391 /* Set this flag to check that variables are parameters of all entries.
9392 This check is effected by the call to gfc_resolve_expr through
9393 is_non_constant_shape_array. */
9394 specification_expr
= 1;
9396 if (sym
->ns
->proc_name
9397 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
9398 || sym
->ns
->proc_name
->attr
.is_main_program
)
9399 && !sym
->attr
.use_assoc
9400 && !sym
->attr
.allocatable
9401 && !sym
->attr
.pointer
9402 && is_non_constant_shape_array (sym
))
9404 /* The shape of a main program or module array needs to be
9406 gfc_error ("The module or main program array '%s' at %L must "
9407 "have constant shape", sym
->name
, &sym
->declared_at
);
9408 specification_expr
= 0;
9412 if (sym
->ts
.type
== BT_CHARACTER
)
9414 /* Make sure that character string variables with assumed length are
9416 e
= sym
->ts
.u
.cl
->length
;
9417 if (e
== NULL
&& !sym
->attr
.dummy
&& !sym
->attr
.result
)
9419 gfc_error ("Entity with assumed character length at %L must be a "
9420 "dummy argument or a PARAMETER", &sym
->declared_at
);
9424 if (e
&& sym
->attr
.save
&& !gfc_is_constant_expr (e
))
9426 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
9430 if (!gfc_is_constant_expr (e
)
9431 && !(e
->expr_type
== EXPR_VARIABLE
9432 && e
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
)
9433 && sym
->ns
->proc_name
9434 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
9435 || sym
->ns
->proc_name
->attr
.is_main_program
)
9436 && !sym
->attr
.use_assoc
)
9438 gfc_error ("'%s' at %L must have constant character length "
9439 "in this context", sym
->name
, &sym
->declared_at
);
9444 if (sym
->value
== NULL
&& sym
->attr
.referenced
)
9445 apply_default_init_local (sym
); /* Try to apply a default initialization. */
9447 /* Determine if the symbol may not have an initializer. */
9448 no_init_flag
= automatic_flag
= 0;
9449 if (sym
->attr
.allocatable
|| sym
->attr
.external
|| sym
->attr
.dummy
9450 || sym
->attr
.intrinsic
|| sym
->attr
.result
)
9452 else if ((sym
->attr
.dimension
|| sym
->attr
.codimension
) && !sym
->attr
.pointer
9453 && is_non_constant_shape_array (sym
))
9455 no_init_flag
= automatic_flag
= 1;
9457 /* Also, they must not have the SAVE attribute.
9458 SAVE_IMPLICIT is checked below. */
9459 if (sym
->attr
.save
== SAVE_EXPLICIT
)
9461 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
9466 /* Ensure that any initializer is simplified. */
9468 gfc_simplify_expr (sym
->value
, 1);
9470 /* Reject illegal initializers. */
9471 if (!sym
->mark
&& sym
->value
)
9473 if (sym
->attr
.allocatable
)
9474 gfc_error ("Allocatable '%s' at %L cannot have an initializer",
9475 sym
->name
, &sym
->declared_at
);
9476 else if (sym
->attr
.external
)
9477 gfc_error ("External '%s' at %L cannot have an initializer",
9478 sym
->name
, &sym
->declared_at
);
9479 else if (sym
->attr
.dummy
9480 && !(sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.intent
== INTENT_OUT
))
9481 gfc_error ("Dummy '%s' at %L cannot have an initializer",
9482 sym
->name
, &sym
->declared_at
);
9483 else if (sym
->attr
.intrinsic
)
9484 gfc_error ("Intrinsic '%s' at %L cannot have an initializer",
9485 sym
->name
, &sym
->declared_at
);
9486 else if (sym
->attr
.result
)
9487 gfc_error ("Function result '%s' at %L cannot have an initializer",
9488 sym
->name
, &sym
->declared_at
);
9489 else if (automatic_flag
)
9490 gfc_error ("Automatic array '%s' at %L cannot have an initializer",
9491 sym
->name
, &sym
->declared_at
);
9498 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
9499 return resolve_fl_variable_derived (sym
, no_init_flag
);
9505 /* Resolve a procedure. */
9508 resolve_fl_procedure (gfc_symbol
*sym
, int mp_flag
)
9510 gfc_formal_arglist
*arg
;
9512 if (sym
->attr
.function
9513 && resolve_fl_var_and_proc (sym
, mp_flag
) == FAILURE
)
9516 if (sym
->ts
.type
== BT_CHARACTER
)
9518 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
9520 if (cl
&& cl
->length
&& gfc_is_constant_expr (cl
->length
)
9521 && resolve_charlen (cl
) == FAILURE
)
9524 if ((!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
9525 && sym
->attr
.proc
== PROC_ST_FUNCTION
)
9527 gfc_error ("Character-valued statement function '%s' at %L must "
9528 "have constant length", sym
->name
, &sym
->declared_at
);
9533 /* Ensure that derived type for are not of a private type. Internal
9534 module procedures are excluded by 2.2.3.3 - i.e., they are not
9535 externally accessible and can access all the objects accessible in
9537 if (!(sym
->ns
->parent
9538 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
9539 && gfc_check_access(sym
->attr
.access
, sym
->ns
->default_access
))
9541 gfc_interface
*iface
;
9543 for (arg
= sym
->formal
; arg
; arg
= arg
->next
)
9546 && arg
->sym
->ts
.type
== BT_DERIVED
9547 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
9548 && !gfc_check_access (arg
->sym
->ts
.u
.derived
->attr
.access
,
9549 arg
->sym
->ts
.u
.derived
->ns
->default_access
)
9550 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' is of a "
9551 "PRIVATE type and cannot be a dummy argument"
9552 " of '%s', which is PUBLIC at %L",
9553 arg
->sym
->name
, sym
->name
, &sym
->declared_at
)
9556 /* Stop this message from recurring. */
9557 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
9562 /* PUBLIC interfaces may expose PRIVATE procedures that take types
9563 PRIVATE to the containing module. */
9564 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
9566 for (arg
= iface
->sym
->formal
; arg
; arg
= arg
->next
)
9569 && arg
->sym
->ts
.type
== BT_DERIVED
9570 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
9571 && !gfc_check_access (arg
->sym
->ts
.u
.derived
->attr
.access
,
9572 arg
->sym
->ts
.u
.derived
->ns
->default_access
)
9573 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: Procedure "
9574 "'%s' in PUBLIC interface '%s' at %L "
9575 "takes dummy arguments of '%s' which is "
9576 "PRIVATE", iface
->sym
->name
, sym
->name
,
9577 &iface
->sym
->declared_at
,
9578 gfc_typename (&arg
->sym
->ts
)) == FAILURE
)
9580 /* Stop this message from recurring. */
9581 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
9587 /* PUBLIC interfaces may expose PRIVATE procedures that take types
9588 PRIVATE to the containing module. */
9589 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
9591 for (arg
= iface
->sym
->formal
; arg
; arg
= arg
->next
)
9594 && arg
->sym
->ts
.type
== BT_DERIVED
9595 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
9596 && !gfc_check_access (arg
->sym
->ts
.u
.derived
->attr
.access
,
9597 arg
->sym
->ts
.u
.derived
->ns
->default_access
)
9598 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: Procedure "
9599 "'%s' in PUBLIC interface '%s' at %L "
9600 "takes dummy arguments of '%s' which is "
9601 "PRIVATE", iface
->sym
->name
, sym
->name
,
9602 &iface
->sym
->declared_at
,
9603 gfc_typename (&arg
->sym
->ts
)) == FAILURE
)
9605 /* Stop this message from recurring. */
9606 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
9613 if (sym
->attr
.function
&& sym
->value
&& sym
->attr
.proc
!= PROC_ST_FUNCTION
9614 && !sym
->attr
.proc_pointer
)
9616 gfc_error ("Function '%s' at %L cannot have an initializer",
9617 sym
->name
, &sym
->declared_at
);
9621 /* An external symbol may not have an initializer because it is taken to be
9622 a procedure. Exception: Procedure Pointers. */
9623 if (sym
->attr
.external
&& sym
->value
&& !sym
->attr
.proc_pointer
)
9625 gfc_error ("External object '%s' at %L may not have an initializer",
9626 sym
->name
, &sym
->declared_at
);
9630 /* An elemental function is required to return a scalar 12.7.1 */
9631 if (sym
->attr
.elemental
&& sym
->attr
.function
&& sym
->as
)
9633 gfc_error ("ELEMENTAL function '%s' at %L must have a scalar "
9634 "result", sym
->name
, &sym
->declared_at
);
9635 /* Reset so that the error only occurs once. */
9636 sym
->attr
.elemental
= 0;
9640 /* 5.1.1.5 of the Standard: A function name declared with an asterisk
9641 char-len-param shall not be array-valued, pointer-valued, recursive
9642 or pure. ....snip... A character value of * may only be used in the
9643 following ways: (i) Dummy arg of procedure - dummy associates with
9644 actual length; (ii) To declare a named constant; or (iii) External
9645 function - but length must be declared in calling scoping unit. */
9646 if (sym
->attr
.function
9647 && sym
->ts
.type
== BT_CHARACTER
9648 && sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
== NULL
)
9650 if ((sym
->as
&& sym
->as
->rank
) || (sym
->attr
.pointer
)
9651 || (sym
->attr
.recursive
) || (sym
->attr
.pure
))
9653 if (sym
->as
&& sym
->as
->rank
)
9654 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
9655 "array-valued", sym
->name
, &sym
->declared_at
);
9657 if (sym
->attr
.pointer
)
9658 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
9659 "pointer-valued", sym
->name
, &sym
->declared_at
);
9662 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
9663 "pure", sym
->name
, &sym
->declared_at
);
9665 if (sym
->attr
.recursive
)
9666 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
9667 "recursive", sym
->name
, &sym
->declared_at
);
9672 /* Appendix B.2 of the standard. Contained functions give an
9673 error anyway. Fixed-form is likely to be F77/legacy. */
9674 if (!sym
->attr
.contained
&& gfc_current_form
!= FORM_FIXED
)
9675 gfc_notify_std (GFC_STD_F95_OBS
, "Obsolescent feature: "
9676 "CHARACTER(*) function '%s' at %L",
9677 sym
->name
, &sym
->declared_at
);
9680 if (sym
->attr
.is_bind_c
&& sym
->attr
.is_c_interop
!= 1)
9682 gfc_formal_arglist
*curr_arg
;
9683 int has_non_interop_arg
= 0;
9685 if (verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
9686 sym
->common_block
) == FAILURE
)
9688 /* Clear these to prevent looking at them again if there was an
9690 sym
->attr
.is_bind_c
= 0;
9691 sym
->attr
.is_c_interop
= 0;
9692 sym
->ts
.is_c_interop
= 0;
9696 /* So far, no errors have been found. */
9697 sym
->attr
.is_c_interop
= 1;
9698 sym
->ts
.is_c_interop
= 1;
9701 curr_arg
= sym
->formal
;
9702 while (curr_arg
!= NULL
)
9704 /* Skip implicitly typed dummy args here. */
9705 if (curr_arg
->sym
->attr
.implicit_type
== 0)
9706 if (verify_c_interop_param (curr_arg
->sym
) == FAILURE
)
9707 /* If something is found to fail, record the fact so we
9708 can mark the symbol for the procedure as not being
9709 BIND(C) to try and prevent multiple errors being
9711 has_non_interop_arg
= 1;
9713 curr_arg
= curr_arg
->next
;
9716 /* See if any of the arguments were not interoperable and if so, clear
9717 the procedure symbol to prevent duplicate error messages. */
9718 if (has_non_interop_arg
!= 0)
9720 sym
->attr
.is_c_interop
= 0;
9721 sym
->ts
.is_c_interop
= 0;
9722 sym
->attr
.is_bind_c
= 0;
9726 if (!sym
->attr
.proc_pointer
)
9728 if (sym
->attr
.save
== SAVE_EXPLICIT
)
9730 gfc_error ("PROCEDURE attribute conflicts with SAVE attribute "
9731 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
9734 if (sym
->attr
.intent
)
9736 gfc_error ("PROCEDURE attribute conflicts with INTENT attribute "
9737 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
9740 if (sym
->attr
.subroutine
&& sym
->attr
.result
)
9742 gfc_error ("PROCEDURE attribute conflicts with RESULT attribute "
9743 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
9746 if (sym
->attr
.external
&& sym
->attr
.function
9747 && ((sym
->attr
.if_source
== IFSRC_DECL
&& !sym
->attr
.procedure
)
9748 || sym
->attr
.contained
))
9750 gfc_error ("EXTERNAL attribute conflicts with FUNCTION attribute "
9751 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
9754 if (strcmp ("ppr@", sym
->name
) == 0)
9756 gfc_error ("Procedure pointer result '%s' at %L "
9757 "is missing the pointer attribute",
9758 sym
->ns
->proc_name
->name
, &sym
->declared_at
);
9767 /* Resolve a list of finalizer procedures. That is, after they have hopefully
9768 been defined and we now know their defined arguments, check that they fulfill
9769 the requirements of the standard for procedures used as finalizers. */
9772 gfc_resolve_finalizers (gfc_symbol
* derived
)
9774 gfc_finalizer
* list
;
9775 gfc_finalizer
** prev_link
; /* For removing wrong entries from the list. */
9776 gfc_try result
= SUCCESS
;
9777 bool seen_scalar
= false;
9779 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->finalizers
)
9782 /* Walk over the list of finalizer-procedures, check them, and if any one
9783 does not fit in with the standard's definition, print an error and remove
9784 it from the list. */
9785 prev_link
= &derived
->f2k_derived
->finalizers
;
9786 for (list
= derived
->f2k_derived
->finalizers
; list
; list
= *prev_link
)
9792 /* Skip this finalizer if we already resolved it. */
9793 if (list
->proc_tree
)
9795 prev_link
= &(list
->next
);
9799 /* Check this exists and is a SUBROUTINE. */
9800 if (!list
->proc_sym
->attr
.subroutine
)
9802 gfc_error ("FINAL procedure '%s' at %L is not a SUBROUTINE",
9803 list
->proc_sym
->name
, &list
->where
);
9807 /* We should have exactly one argument. */
9808 if (!list
->proc_sym
->formal
|| list
->proc_sym
->formal
->next
)
9810 gfc_error ("FINAL procedure at %L must have exactly one argument",
9814 arg
= list
->proc_sym
->formal
->sym
;
9816 /* This argument must be of our type. */
9817 if (arg
->ts
.type
!= BT_DERIVED
|| arg
->ts
.u
.derived
!= derived
)
9819 gfc_error ("Argument of FINAL procedure at %L must be of type '%s'",
9820 &arg
->declared_at
, derived
->name
);
9824 /* It must neither be a pointer nor allocatable nor optional. */
9825 if (arg
->attr
.pointer
)
9827 gfc_error ("Argument of FINAL procedure at %L must not be a POINTER",
9831 if (arg
->attr
.allocatable
)
9833 gfc_error ("Argument of FINAL procedure at %L must not be"
9834 " ALLOCATABLE", &arg
->declared_at
);
9837 if (arg
->attr
.optional
)
9839 gfc_error ("Argument of FINAL procedure at %L must not be OPTIONAL",
9844 /* It must not be INTENT(OUT). */
9845 if (arg
->attr
.intent
== INTENT_OUT
)
9847 gfc_error ("Argument of FINAL procedure at %L must not be"
9848 " INTENT(OUT)", &arg
->declared_at
);
9852 /* Warn if the procedure is non-scalar and not assumed shape. */
9853 if (gfc_option
.warn_surprising
&& arg
->as
&& arg
->as
->rank
> 0
9854 && arg
->as
->type
!= AS_ASSUMED_SHAPE
)
9855 gfc_warning ("Non-scalar FINAL procedure at %L should have assumed"
9856 " shape argument", &arg
->declared_at
);
9858 /* Check that it does not match in kind and rank with a FINAL procedure
9859 defined earlier. To really loop over the *earlier* declarations,
9860 we need to walk the tail of the list as new ones were pushed at the
9862 /* TODO: Handle kind parameters once they are implemented. */
9863 my_rank
= (arg
->as
? arg
->as
->rank
: 0);
9864 for (i
= list
->next
; i
; i
= i
->next
)
9866 /* Argument list might be empty; that is an error signalled earlier,
9867 but we nevertheless continued resolving. */
9868 if (i
->proc_sym
->formal
)
9870 gfc_symbol
* i_arg
= i
->proc_sym
->formal
->sym
;
9871 const int i_rank
= (i_arg
->as
? i_arg
->as
->rank
: 0);
9872 if (i_rank
== my_rank
)
9874 gfc_error ("FINAL procedure '%s' declared at %L has the same"
9875 " rank (%d) as '%s'",
9876 list
->proc_sym
->name
, &list
->where
, my_rank
,
9883 /* Is this the/a scalar finalizer procedure? */
9884 if (!arg
->as
|| arg
->as
->rank
== 0)
9887 /* Find the symtree for this procedure. */
9888 gcc_assert (!list
->proc_tree
);
9889 list
->proc_tree
= gfc_find_sym_in_symtree (list
->proc_sym
);
9891 prev_link
= &list
->next
;
9894 /* Remove wrong nodes immediately from the list so we don't risk any
9895 troubles in the future when they might fail later expectations. */
9899 *prev_link
= list
->next
;
9900 gfc_free_finalizer (i
);
9903 /* Warn if we haven't seen a scalar finalizer procedure (but we know there
9904 were nodes in the list, must have been for arrays. It is surely a good
9905 idea to have a scalar version there if there's something to finalize. */
9906 if (gfc_option
.warn_surprising
&& result
== SUCCESS
&& !seen_scalar
)
9907 gfc_warning ("Only array FINAL procedures declared for derived type '%s'"
9908 " defined at %L, suggest also scalar one",
9909 derived
->name
, &derived
->declared_at
);
9911 /* TODO: Remove this error when finalization is finished. */
9912 gfc_error ("Finalization at %L is not yet implemented",
9913 &derived
->declared_at
);
9919 /* Check that it is ok for the typebound procedure proc to override the
9923 check_typebound_override (gfc_symtree
* proc
, gfc_symtree
* old
)
9926 const gfc_symbol
* proc_target
;
9927 const gfc_symbol
* old_target
;
9928 unsigned proc_pass_arg
, old_pass_arg
, argpos
;
9929 gfc_formal_arglist
* proc_formal
;
9930 gfc_formal_arglist
* old_formal
;
9932 /* This procedure should only be called for non-GENERIC proc. */
9933 gcc_assert (!proc
->n
.tb
->is_generic
);
9935 /* If the overwritten procedure is GENERIC, this is an error. */
9936 if (old
->n
.tb
->is_generic
)
9938 gfc_error ("Can't overwrite GENERIC '%s' at %L",
9939 old
->name
, &proc
->n
.tb
->where
);
9943 where
= proc
->n
.tb
->where
;
9944 proc_target
= proc
->n
.tb
->u
.specific
->n
.sym
;
9945 old_target
= old
->n
.tb
->u
.specific
->n
.sym
;
9947 /* Check that overridden binding is not NON_OVERRIDABLE. */
9948 if (old
->n
.tb
->non_overridable
)
9950 gfc_error ("'%s' at %L overrides a procedure binding declared"
9951 " NON_OVERRIDABLE", proc
->name
, &where
);
9955 /* It's an error to override a non-DEFERRED procedure with a DEFERRED one. */
9956 if (!old
->n
.tb
->deferred
&& proc
->n
.tb
->deferred
)
9958 gfc_error ("'%s' at %L must not be DEFERRED as it overrides a"
9959 " non-DEFERRED binding", proc
->name
, &where
);
9963 /* If the overridden binding is PURE, the overriding must be, too. */
9964 if (old_target
->attr
.pure
&& !proc_target
->attr
.pure
)
9966 gfc_error ("'%s' at %L overrides a PURE procedure and must also be PURE",
9967 proc
->name
, &where
);
9971 /* If the overridden binding is ELEMENTAL, the overriding must be, too. If it
9972 is not, the overriding must not be either. */
9973 if (old_target
->attr
.elemental
&& !proc_target
->attr
.elemental
)
9975 gfc_error ("'%s' at %L overrides an ELEMENTAL procedure and must also be"
9976 " ELEMENTAL", proc
->name
, &where
);
9979 if (!old_target
->attr
.elemental
&& proc_target
->attr
.elemental
)
9981 gfc_error ("'%s' at %L overrides a non-ELEMENTAL procedure and must not"
9982 " be ELEMENTAL, either", proc
->name
, &where
);
9986 /* If the overridden binding is a SUBROUTINE, the overriding must also be a
9988 if (old_target
->attr
.subroutine
&& !proc_target
->attr
.subroutine
)
9990 gfc_error ("'%s' at %L overrides a SUBROUTINE and must also be a"
9991 " SUBROUTINE", proc
->name
, &where
);
9995 /* If the overridden binding is a FUNCTION, the overriding must also be a
9996 FUNCTION and have the same characteristics. */
9997 if (old_target
->attr
.function
)
9999 if (!proc_target
->attr
.function
)
10001 gfc_error ("'%s' at %L overrides a FUNCTION and must also be a"
10002 " FUNCTION", proc
->name
, &where
);
10006 /* FIXME: Do more comprehensive checking (including, for instance, the
10007 rank and array-shape). */
10008 gcc_assert (proc_target
->result
&& old_target
->result
);
10009 if (!gfc_compare_types (&proc_target
->result
->ts
,
10010 &old_target
->result
->ts
))
10012 gfc_error ("'%s' at %L and the overridden FUNCTION should have"
10013 " matching result types", proc
->name
, &where
);
10018 /* If the overridden binding is PUBLIC, the overriding one must not be
10020 if (old
->n
.tb
->access
== ACCESS_PUBLIC
10021 && proc
->n
.tb
->access
== ACCESS_PRIVATE
)
10023 gfc_error ("'%s' at %L overrides a PUBLIC procedure and must not be"
10024 " PRIVATE", proc
->name
, &where
);
10028 /* Compare the formal argument lists of both procedures. This is also abused
10029 to find the position of the passed-object dummy arguments of both
10030 bindings as at least the overridden one might not yet be resolved and we
10031 need those positions in the check below. */
10032 proc_pass_arg
= old_pass_arg
= 0;
10033 if (!proc
->n
.tb
->nopass
&& !proc
->n
.tb
->pass_arg
)
10035 if (!old
->n
.tb
->nopass
&& !old
->n
.tb
->pass_arg
)
10038 for (proc_formal
= proc_target
->formal
, old_formal
= old_target
->formal
;
10039 proc_formal
&& old_formal
;
10040 proc_formal
= proc_formal
->next
, old_formal
= old_formal
->next
)
10042 if (proc
->n
.tb
->pass_arg
10043 && !strcmp (proc
->n
.tb
->pass_arg
, proc_formal
->sym
->name
))
10044 proc_pass_arg
= argpos
;
10045 if (old
->n
.tb
->pass_arg
10046 && !strcmp (old
->n
.tb
->pass_arg
, old_formal
->sym
->name
))
10047 old_pass_arg
= argpos
;
10049 /* Check that the names correspond. */
10050 if (strcmp (proc_formal
->sym
->name
, old_formal
->sym
->name
))
10052 gfc_error ("Dummy argument '%s' of '%s' at %L should be named '%s' as"
10053 " to match the corresponding argument of the overridden"
10054 " procedure", proc_formal
->sym
->name
, proc
->name
, &where
,
10055 old_formal
->sym
->name
);
10059 /* Check that the types correspond if neither is the passed-object
10061 /* FIXME: Do more comprehensive testing here. */
10062 if (proc_pass_arg
!= argpos
&& old_pass_arg
!= argpos
10063 && !gfc_compare_types (&proc_formal
->sym
->ts
, &old_formal
->sym
->ts
))
10065 gfc_error ("Types mismatch for dummy argument '%s' of '%s' %L "
10066 "in respect to the overridden procedure",
10067 proc_formal
->sym
->name
, proc
->name
, &where
);
10073 if (proc_formal
|| old_formal
)
10075 gfc_error ("'%s' at %L must have the same number of formal arguments as"
10076 " the overridden procedure", proc
->name
, &where
);
10080 /* If the overridden binding is NOPASS, the overriding one must also be
10082 if (old
->n
.tb
->nopass
&& !proc
->n
.tb
->nopass
)
10084 gfc_error ("'%s' at %L overrides a NOPASS binding and must also be"
10085 " NOPASS", proc
->name
, &where
);
10089 /* If the overridden binding is PASS(x), the overriding one must also be
10090 PASS and the passed-object dummy arguments must correspond. */
10091 if (!old
->n
.tb
->nopass
)
10093 if (proc
->n
.tb
->nopass
)
10095 gfc_error ("'%s' at %L overrides a binding with PASS and must also be"
10096 " PASS", proc
->name
, &where
);
10100 if (proc_pass_arg
!= old_pass_arg
)
10102 gfc_error ("Passed-object dummy argument of '%s' at %L must be at"
10103 " the same position as the passed-object dummy argument of"
10104 " the overridden procedure", proc
->name
, &where
);
10113 /* Check if two GENERIC targets are ambiguous and emit an error is they are. */
10116 check_generic_tbp_ambiguity (gfc_tbp_generic
* t1
, gfc_tbp_generic
* t2
,
10117 const char* generic_name
, locus where
)
10122 gcc_assert (t1
->specific
&& t2
->specific
);
10123 gcc_assert (!t1
->specific
->is_generic
);
10124 gcc_assert (!t2
->specific
->is_generic
);
10126 sym1
= t1
->specific
->u
.specific
->n
.sym
;
10127 sym2
= t2
->specific
->u
.specific
->n
.sym
;
10132 /* Both must be SUBROUTINEs or both must be FUNCTIONs. */
10133 if (sym1
->attr
.subroutine
!= sym2
->attr
.subroutine
10134 || sym1
->attr
.function
!= sym2
->attr
.function
)
10136 gfc_error ("'%s' and '%s' can't be mixed FUNCTION/SUBROUTINE for"
10137 " GENERIC '%s' at %L",
10138 sym1
->name
, sym2
->name
, generic_name
, &where
);
10142 /* Compare the interfaces. */
10143 if (gfc_compare_interfaces (sym1
, sym2
, sym2
->name
, 1, 0, NULL
, 0))
10145 gfc_error ("'%s' and '%s' for GENERIC '%s' at %L are ambiguous",
10146 sym1
->name
, sym2
->name
, generic_name
, &where
);
10154 /* Worker function for resolving a generic procedure binding; this is used to
10155 resolve GENERIC as well as user and intrinsic OPERATOR typebound procedures.
10157 The difference between those cases is finding possible inherited bindings
10158 that are overridden, as one has to look for them in tb_sym_root,
10159 tb_uop_root or tb_op, respectively. Thus the caller must already find
10160 the super-type and set p->overridden correctly. */
10163 resolve_tb_generic_targets (gfc_symbol
* super_type
,
10164 gfc_typebound_proc
* p
, const char* name
)
10166 gfc_tbp_generic
* target
;
10167 gfc_symtree
* first_target
;
10168 gfc_symtree
* inherited
;
10170 gcc_assert (p
&& p
->is_generic
);
10172 /* Try to find the specific bindings for the symtrees in our target-list. */
10173 gcc_assert (p
->u
.generic
);
10174 for (target
= p
->u
.generic
; target
; target
= target
->next
)
10175 if (!target
->specific
)
10177 gfc_typebound_proc
* overridden_tbp
;
10178 gfc_tbp_generic
* g
;
10179 const char* target_name
;
10181 target_name
= target
->specific_st
->name
;
10183 /* Defined for this type directly. */
10184 if (target
->specific_st
->n
.tb
)
10186 target
->specific
= target
->specific_st
->n
.tb
;
10187 goto specific_found
;
10190 /* Look for an inherited specific binding. */
10193 inherited
= gfc_find_typebound_proc (super_type
, NULL
, target_name
,
10198 gcc_assert (inherited
->n
.tb
);
10199 target
->specific
= inherited
->n
.tb
;
10200 goto specific_found
;
10204 gfc_error ("Undefined specific binding '%s' as target of GENERIC '%s'"
10205 " at %L", target_name
, name
, &p
->where
);
10208 /* Once we've found the specific binding, check it is not ambiguous with
10209 other specifics already found or inherited for the same GENERIC. */
10211 gcc_assert (target
->specific
);
10213 /* This must really be a specific binding! */
10214 if (target
->specific
->is_generic
)
10216 gfc_error ("GENERIC '%s' at %L must target a specific binding,"
10217 " '%s' is GENERIC, too", name
, &p
->where
, target_name
);
10221 /* Check those already resolved on this type directly. */
10222 for (g
= p
->u
.generic
; g
; g
= g
->next
)
10223 if (g
!= target
&& g
->specific
10224 && check_generic_tbp_ambiguity (target
, g
, name
, p
->where
)
10228 /* Check for ambiguity with inherited specific targets. */
10229 for (overridden_tbp
= p
->overridden
; overridden_tbp
;
10230 overridden_tbp
= overridden_tbp
->overridden
)
10231 if (overridden_tbp
->is_generic
)
10233 for (g
= overridden_tbp
->u
.generic
; g
; g
= g
->next
)
10235 gcc_assert (g
->specific
);
10236 if (check_generic_tbp_ambiguity (target
, g
,
10237 name
, p
->where
) == FAILURE
)
10243 /* If we attempt to "overwrite" a specific binding, this is an error. */
10244 if (p
->overridden
&& !p
->overridden
->is_generic
)
10246 gfc_error ("GENERIC '%s' at %L can't overwrite specific binding with"
10247 " the same name", name
, &p
->where
);
10251 /* Take the SUBROUTINE/FUNCTION attributes of the first specific target, as
10252 all must have the same attributes here. */
10253 first_target
= p
->u
.generic
->specific
->u
.specific
;
10254 gcc_assert (first_target
);
10255 p
->subroutine
= first_target
->n
.sym
->attr
.subroutine
;
10256 p
->function
= first_target
->n
.sym
->attr
.function
;
10262 /* Resolve a GENERIC procedure binding for a derived type. */
10265 resolve_typebound_generic (gfc_symbol
* derived
, gfc_symtree
* st
)
10267 gfc_symbol
* super_type
;
10269 /* Find the overridden binding if any. */
10270 st
->n
.tb
->overridden
= NULL
;
10271 super_type
= gfc_get_derived_super_type (derived
);
10274 gfc_symtree
* overridden
;
10275 overridden
= gfc_find_typebound_proc (super_type
, NULL
, st
->name
,
10278 if (overridden
&& overridden
->n
.tb
)
10279 st
->n
.tb
->overridden
= overridden
->n
.tb
;
10282 /* Resolve using worker function. */
10283 return resolve_tb_generic_targets (super_type
, st
->n
.tb
, st
->name
);
10287 /* Retrieve the target-procedure of an operator binding and do some checks in
10288 common for intrinsic and user-defined type-bound operators. */
10291 get_checked_tb_operator_target (gfc_tbp_generic
* target
, locus where
)
10293 gfc_symbol
* target_proc
;
10295 gcc_assert (target
->specific
&& !target
->specific
->is_generic
);
10296 target_proc
= target
->specific
->u
.specific
->n
.sym
;
10297 gcc_assert (target_proc
);
10299 /* All operator bindings must have a passed-object dummy argument. */
10300 if (target
->specific
->nopass
)
10302 gfc_error ("Type-bound operator at %L can't be NOPASS", &where
);
10306 return target_proc
;
10310 /* Resolve a type-bound intrinsic operator. */
10313 resolve_typebound_intrinsic_op (gfc_symbol
* derived
, gfc_intrinsic_op op
,
10314 gfc_typebound_proc
* p
)
10316 gfc_symbol
* super_type
;
10317 gfc_tbp_generic
* target
;
10319 /* If there's already an error here, do nothing (but don't fail again). */
10323 /* Operators should always be GENERIC bindings. */
10324 gcc_assert (p
->is_generic
);
10326 /* Look for an overridden binding. */
10327 super_type
= gfc_get_derived_super_type (derived
);
10328 if (super_type
&& super_type
->f2k_derived
)
10329 p
->overridden
= gfc_find_typebound_intrinsic_op (super_type
, NULL
,
10332 p
->overridden
= NULL
;
10334 /* Resolve general GENERIC properties using worker function. */
10335 if (resolve_tb_generic_targets (super_type
, p
, gfc_op2string (op
)) == FAILURE
)
10338 /* Check the targets to be procedures of correct interface. */
10339 for (target
= p
->u
.generic
; target
; target
= target
->next
)
10341 gfc_symbol
* target_proc
;
10343 target_proc
= get_checked_tb_operator_target (target
, p
->where
);
10347 if (!gfc_check_operator_interface (target_proc
, op
, p
->where
))
10359 /* Resolve a type-bound user operator (tree-walker callback). */
10361 static gfc_symbol
* resolve_bindings_derived
;
10362 static gfc_try resolve_bindings_result
;
10364 static gfc_try
check_uop_procedure (gfc_symbol
* sym
, locus where
);
10367 resolve_typebound_user_op (gfc_symtree
* stree
)
10369 gfc_symbol
* super_type
;
10370 gfc_tbp_generic
* target
;
10372 gcc_assert (stree
&& stree
->n
.tb
);
10374 if (stree
->n
.tb
->error
)
10377 /* Operators should always be GENERIC bindings. */
10378 gcc_assert (stree
->n
.tb
->is_generic
);
10380 /* Find overridden procedure, if any. */
10381 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
10382 if (super_type
&& super_type
->f2k_derived
)
10384 gfc_symtree
* overridden
;
10385 overridden
= gfc_find_typebound_user_op (super_type
, NULL
,
10386 stree
->name
, true, NULL
);
10388 if (overridden
&& overridden
->n
.tb
)
10389 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
10392 stree
->n
.tb
->overridden
= NULL
;
10394 /* Resolve basically using worker function. */
10395 if (resolve_tb_generic_targets (super_type
, stree
->n
.tb
, stree
->name
)
10399 /* Check the targets to be functions of correct interface. */
10400 for (target
= stree
->n
.tb
->u
.generic
; target
; target
= target
->next
)
10402 gfc_symbol
* target_proc
;
10404 target_proc
= get_checked_tb_operator_target (target
, stree
->n
.tb
->where
);
10408 if (check_uop_procedure (target_proc
, stree
->n
.tb
->where
) == FAILURE
)
10415 resolve_bindings_result
= FAILURE
;
10416 stree
->n
.tb
->error
= 1;
10420 /* Resolve the type-bound procedures for a derived type. */
10423 resolve_typebound_procedure (gfc_symtree
* stree
)
10427 gfc_symbol
* me_arg
;
10428 gfc_symbol
* super_type
;
10429 gfc_component
* comp
;
10431 gcc_assert (stree
);
10433 /* Undefined specific symbol from GENERIC target definition. */
10437 if (stree
->n
.tb
->error
)
10440 /* If this is a GENERIC binding, use that routine. */
10441 if (stree
->n
.tb
->is_generic
)
10443 if (resolve_typebound_generic (resolve_bindings_derived
, stree
)
10449 /* Get the target-procedure to check it. */
10450 gcc_assert (!stree
->n
.tb
->is_generic
);
10451 gcc_assert (stree
->n
.tb
->u
.specific
);
10452 proc
= stree
->n
.tb
->u
.specific
->n
.sym
;
10453 where
= stree
->n
.tb
->where
;
10455 /* Default access should already be resolved from the parser. */
10456 gcc_assert (stree
->n
.tb
->access
!= ACCESS_UNKNOWN
);
10458 /* It should be a module procedure or an external procedure with explicit
10459 interface. For DEFERRED bindings, abstract interfaces are ok as well. */
10460 if ((!proc
->attr
.subroutine
&& !proc
->attr
.function
)
10461 || (proc
->attr
.proc
!= PROC_MODULE
10462 && proc
->attr
.if_source
!= IFSRC_IFBODY
)
10463 || (proc
->attr
.abstract
&& !stree
->n
.tb
->deferred
))
10465 gfc_error ("'%s' must be a module procedure or an external procedure with"
10466 " an explicit interface at %L", proc
->name
, &where
);
10469 stree
->n
.tb
->subroutine
= proc
->attr
.subroutine
;
10470 stree
->n
.tb
->function
= proc
->attr
.function
;
10472 /* Find the super-type of the current derived type. We could do this once and
10473 store in a global if speed is needed, but as long as not I believe this is
10474 more readable and clearer. */
10475 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
10477 /* If PASS, resolve and check arguments if not already resolved / loaded
10478 from a .mod file. */
10479 if (!stree
->n
.tb
->nopass
&& stree
->n
.tb
->pass_arg_num
== 0)
10481 if (stree
->n
.tb
->pass_arg
)
10483 gfc_formal_arglist
* i
;
10485 /* If an explicit passing argument name is given, walk the arg-list
10486 and look for it. */
10489 stree
->n
.tb
->pass_arg_num
= 1;
10490 for (i
= proc
->formal
; i
; i
= i
->next
)
10492 if (!strcmp (i
->sym
->name
, stree
->n
.tb
->pass_arg
))
10497 ++stree
->n
.tb
->pass_arg_num
;
10502 gfc_error ("Procedure '%s' with PASS(%s) at %L has no"
10504 proc
->name
, stree
->n
.tb
->pass_arg
, &where
,
10505 stree
->n
.tb
->pass_arg
);
10511 /* Otherwise, take the first one; there should in fact be at least
10513 stree
->n
.tb
->pass_arg_num
= 1;
10516 gfc_error ("Procedure '%s' with PASS at %L must have at"
10517 " least one argument", proc
->name
, &where
);
10520 me_arg
= proc
->formal
->sym
;
10523 /* Now check that the argument-type matches and the passed-object
10524 dummy argument is generally fine. */
10526 gcc_assert (me_arg
);
10528 if (me_arg
->ts
.type
!= BT_CLASS
)
10530 gfc_error ("Non-polymorphic passed-object dummy argument of '%s'"
10531 " at %L", proc
->name
, &where
);
10535 if (CLASS_DATA (me_arg
)->ts
.u
.derived
10536 != resolve_bindings_derived
)
10538 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L must be of"
10539 " the derived-type '%s'", me_arg
->name
, proc
->name
,
10540 me_arg
->name
, &where
, resolve_bindings_derived
->name
);
10544 gcc_assert (me_arg
->ts
.type
== BT_CLASS
);
10545 if (CLASS_DATA (me_arg
)->as
&& CLASS_DATA (me_arg
)->as
->rank
> 0)
10547 gfc_error ("Passed-object dummy argument of '%s' at %L must be"
10548 " scalar", proc
->name
, &where
);
10551 if (CLASS_DATA (me_arg
)->attr
.allocatable
)
10553 gfc_error ("Passed-object dummy argument of '%s' at %L must not"
10554 " be ALLOCATABLE", proc
->name
, &where
);
10557 if (CLASS_DATA (me_arg
)->attr
.class_pointer
)
10559 gfc_error ("Passed-object dummy argument of '%s' at %L must not"
10560 " be POINTER", proc
->name
, &where
);
10565 /* If we are extending some type, check that we don't override a procedure
10566 flagged NON_OVERRIDABLE. */
10567 stree
->n
.tb
->overridden
= NULL
;
10570 gfc_symtree
* overridden
;
10571 overridden
= gfc_find_typebound_proc (super_type
, NULL
,
10572 stree
->name
, true, NULL
);
10574 if (overridden
&& overridden
->n
.tb
)
10575 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
10577 if (overridden
&& check_typebound_override (stree
, overridden
) == FAILURE
)
10581 /* See if there's a name collision with a component directly in this type. */
10582 for (comp
= resolve_bindings_derived
->components
; comp
; comp
= comp
->next
)
10583 if (!strcmp (comp
->name
, stree
->name
))
10585 gfc_error ("Procedure '%s' at %L has the same name as a component of"
10587 stree
->name
, &where
, resolve_bindings_derived
->name
);
10591 /* Try to find a name collision with an inherited component. */
10592 if (super_type
&& gfc_find_component (super_type
, stree
->name
, true, true))
10594 gfc_error ("Procedure '%s' at %L has the same name as an inherited"
10595 " component of '%s'",
10596 stree
->name
, &where
, resolve_bindings_derived
->name
);
10600 stree
->n
.tb
->error
= 0;
10604 resolve_bindings_result
= FAILURE
;
10605 stree
->n
.tb
->error
= 1;
10609 resolve_typebound_procedures (gfc_symbol
* derived
)
10613 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->tb_sym_root
)
10616 resolve_bindings_derived
= derived
;
10617 resolve_bindings_result
= SUCCESS
;
10619 if (derived
->f2k_derived
->tb_sym_root
)
10620 gfc_traverse_symtree (derived
->f2k_derived
->tb_sym_root
,
10621 &resolve_typebound_procedure
);
10623 if (derived
->f2k_derived
->tb_uop_root
)
10624 gfc_traverse_symtree (derived
->f2k_derived
->tb_uop_root
,
10625 &resolve_typebound_user_op
);
10627 for (op
= 0; op
!= GFC_INTRINSIC_OPS
; ++op
)
10629 gfc_typebound_proc
* p
= derived
->f2k_derived
->tb_op
[op
];
10630 if (p
&& resolve_typebound_intrinsic_op (derived
, (gfc_intrinsic_op
) op
,
10632 resolve_bindings_result
= FAILURE
;
10635 return resolve_bindings_result
;
10639 /* Add a derived type to the dt_list. The dt_list is used in trans-types.c
10640 to give all identical derived types the same backend_decl. */
10642 add_dt_to_dt_list (gfc_symbol
*derived
)
10644 gfc_dt_list
*dt_list
;
10646 for (dt_list
= gfc_derived_types
; dt_list
; dt_list
= dt_list
->next
)
10647 if (derived
== dt_list
->derived
)
10650 if (dt_list
== NULL
)
10652 dt_list
= gfc_get_dt_list ();
10653 dt_list
->next
= gfc_derived_types
;
10654 dt_list
->derived
= derived
;
10655 gfc_derived_types
= dt_list
;
10660 /* Ensure that a derived-type is really not abstract, meaning that every
10661 inherited DEFERRED binding is overridden by a non-DEFERRED one. */
10664 ensure_not_abstract_walker (gfc_symbol
* sub
, gfc_symtree
* st
)
10669 if (ensure_not_abstract_walker (sub
, st
->left
) == FAILURE
)
10671 if (ensure_not_abstract_walker (sub
, st
->right
) == FAILURE
)
10674 if (st
->n
.tb
&& st
->n
.tb
->deferred
)
10676 gfc_symtree
* overriding
;
10677 overriding
= gfc_find_typebound_proc (sub
, NULL
, st
->name
, true, NULL
);
10680 gcc_assert (overriding
->n
.tb
);
10681 if (overriding
->n
.tb
->deferred
)
10683 gfc_error ("Derived-type '%s' declared at %L must be ABSTRACT because"
10684 " '%s' is DEFERRED and not overridden",
10685 sub
->name
, &sub
->declared_at
, st
->name
);
10694 ensure_not_abstract (gfc_symbol
* sub
, gfc_symbol
* ancestor
)
10696 /* The algorithm used here is to recursively travel up the ancestry of sub
10697 and for each ancestor-type, check all bindings. If any of them is
10698 DEFERRED, look it up starting from sub and see if the found (overriding)
10699 binding is not DEFERRED.
10700 This is not the most efficient way to do this, but it should be ok and is
10701 clearer than something sophisticated. */
10703 gcc_assert (ancestor
&& !sub
->attr
.abstract
);
10705 if (!ancestor
->attr
.abstract
)
10708 /* Walk bindings of this ancestor. */
10709 if (ancestor
->f2k_derived
)
10712 t
= ensure_not_abstract_walker (sub
, ancestor
->f2k_derived
->tb_sym_root
);
10717 /* Find next ancestor type and recurse on it. */
10718 ancestor
= gfc_get_derived_super_type (ancestor
);
10720 return ensure_not_abstract (sub
, ancestor
);
10726 static void resolve_symbol (gfc_symbol
*sym
);
10729 /* Resolve the components of a derived type. */
10732 resolve_fl_derived (gfc_symbol
*sym
)
10734 gfc_symbol
* super_type
;
10738 super_type
= gfc_get_derived_super_type (sym
);
10740 if (sym
->attr
.is_class
&& sym
->ts
.u
.derived
== NULL
)
10742 /* Fix up incomplete CLASS symbols. */
10743 gfc_component
*data
= gfc_find_component (sym
, "$data", true, true);
10744 gfc_component
*vptr
= gfc_find_component (sym
, "$vptr", true, true);
10745 if (vptr
->ts
.u
.derived
== NULL
)
10747 gfc_symbol
*vtab
= gfc_find_derived_vtab (data
->ts
.u
.derived
);
10749 vptr
->ts
.u
.derived
= vtab
->ts
.u
.derived
;
10754 if (super_type
&& sym
->attr
.coarray_comp
&& !super_type
->attr
.coarray_comp
)
10756 gfc_error ("As extending type '%s' at %L has a coarray component, "
10757 "parent type '%s' shall also have one", sym
->name
,
10758 &sym
->declared_at
, super_type
->name
);
10762 /* Ensure the extended type gets resolved before we do. */
10763 if (super_type
&& resolve_fl_derived (super_type
) == FAILURE
)
10766 /* An ABSTRACT type must be extensible. */
10767 if (sym
->attr
.abstract
&& !gfc_type_is_extensible (sym
))
10769 gfc_error ("Non-extensible derived-type '%s' at %L must not be ABSTRACT",
10770 sym
->name
, &sym
->declared_at
);
10774 for (c
= sym
->components
; c
!= NULL
; c
= c
->next
)
10777 if (c
->attr
.codimension
/* FIXME: c->as check due to PR 43412. */
10778 && (!c
->attr
.allocatable
|| (c
->as
&& c
->as
->type
!= AS_DEFERRED
)))
10780 gfc_error ("Coarray component '%s' at %L must be allocatable with "
10781 "deferred shape", c
->name
, &c
->loc
);
10786 if (c
->attr
.codimension
&& c
->ts
.type
== BT_DERIVED
10787 && c
->ts
.u
.derived
->ts
.is_iso_c
)
10789 gfc_error ("Component '%s' at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
10790 "shall not be a coarray", c
->name
, &c
->loc
);
10795 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
10796 && (c
->attr
.codimension
|| c
->attr
.pointer
|| c
->attr
.dimension
10797 || c
->attr
.allocatable
))
10799 gfc_error ("Component '%s' at %L with coarray component "
10800 "shall be a nonpointer, nonallocatable scalar",
10806 if (c
->attr
.contiguous
&& (!c
->attr
.dimension
|| !c
->attr
.pointer
))
10808 gfc_error ("Component '%s' at %L has the CONTIGUOUS attribute but "
10809 "is not an array pointer", c
->name
, &c
->loc
);
10813 if (c
->attr
.proc_pointer
&& c
->ts
.interface
)
10815 if (c
->ts
.interface
->attr
.procedure
&& !sym
->attr
.vtype
)
10816 gfc_error ("Interface '%s', used by procedure pointer component "
10817 "'%s' at %L, is declared in a later PROCEDURE statement",
10818 c
->ts
.interface
->name
, c
->name
, &c
->loc
);
10820 /* Get the attributes from the interface (now resolved). */
10821 if (c
->ts
.interface
->attr
.if_source
10822 || c
->ts
.interface
->attr
.intrinsic
)
10824 gfc_symbol
*ifc
= c
->ts
.interface
;
10826 if (ifc
->formal
&& !ifc
->formal_ns
)
10827 resolve_symbol (ifc
);
10829 if (ifc
->attr
.intrinsic
)
10830 resolve_intrinsic (ifc
, &ifc
->declared_at
);
10834 c
->ts
= ifc
->result
->ts
;
10835 c
->attr
.allocatable
= ifc
->result
->attr
.allocatable
;
10836 c
->attr
.pointer
= ifc
->result
->attr
.pointer
;
10837 c
->attr
.dimension
= ifc
->result
->attr
.dimension
;
10838 c
->as
= gfc_copy_array_spec (ifc
->result
->as
);
10843 c
->attr
.allocatable
= ifc
->attr
.allocatable
;
10844 c
->attr
.pointer
= ifc
->attr
.pointer
;
10845 c
->attr
.dimension
= ifc
->attr
.dimension
;
10846 c
->as
= gfc_copy_array_spec (ifc
->as
);
10848 c
->ts
.interface
= ifc
;
10849 c
->attr
.function
= ifc
->attr
.function
;
10850 c
->attr
.subroutine
= ifc
->attr
.subroutine
;
10851 gfc_copy_formal_args_ppc (c
, ifc
);
10853 c
->attr
.pure
= ifc
->attr
.pure
;
10854 c
->attr
.elemental
= ifc
->attr
.elemental
;
10855 c
->attr
.recursive
= ifc
->attr
.recursive
;
10856 c
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
10857 c
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
10858 /* Replace symbols in array spec. */
10862 for (i
= 0; i
< c
->as
->rank
; i
++)
10864 gfc_expr_replace_comp (c
->as
->lower
[i
], c
);
10865 gfc_expr_replace_comp (c
->as
->upper
[i
], c
);
10868 /* Copy char length. */
10869 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
10871 gfc_charlen
*cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
10872 gfc_expr_replace_comp (cl
->length
, c
);
10873 if (cl
->length
&& !cl
->resolved
10874 && gfc_resolve_expr (cl
->length
) == FAILURE
)
10879 else if (!sym
->attr
.vtype
&& c
->ts
.interface
->name
[0] != '\0')
10881 gfc_error ("Interface '%s' of procedure pointer component "
10882 "'%s' at %L must be explicit", c
->ts
.interface
->name
,
10887 else if (c
->attr
.proc_pointer
&& c
->ts
.type
== BT_UNKNOWN
)
10889 /* Since PPCs are not implicitly typed, a PPC without an explicit
10890 interface must be a subroutine. */
10891 gfc_add_subroutine (&c
->attr
, c
->name
, &c
->loc
);
10894 /* Procedure pointer components: Check PASS arg. */
10895 if (c
->attr
.proc_pointer
&& !c
->tb
->nopass
&& c
->tb
->pass_arg_num
== 0
10896 && !sym
->attr
.vtype
)
10898 gfc_symbol
* me_arg
;
10900 if (c
->tb
->pass_arg
)
10902 gfc_formal_arglist
* i
;
10904 /* If an explicit passing argument name is given, walk the arg-list
10905 and look for it. */
10908 c
->tb
->pass_arg_num
= 1;
10909 for (i
= c
->formal
; i
; i
= i
->next
)
10911 if (!strcmp (i
->sym
->name
, c
->tb
->pass_arg
))
10916 c
->tb
->pass_arg_num
++;
10921 gfc_error ("Procedure pointer component '%s' with PASS(%s) "
10922 "at %L has no argument '%s'", c
->name
,
10923 c
->tb
->pass_arg
, &c
->loc
, c
->tb
->pass_arg
);
10930 /* Otherwise, take the first one; there should in fact be at least
10932 c
->tb
->pass_arg_num
= 1;
10935 gfc_error ("Procedure pointer component '%s' with PASS at %L "
10936 "must have at least one argument",
10941 me_arg
= c
->formal
->sym
;
10944 /* Now check that the argument-type matches. */
10945 gcc_assert (me_arg
);
10946 if ((me_arg
->ts
.type
!= BT_DERIVED
&& me_arg
->ts
.type
!= BT_CLASS
)
10947 || (me_arg
->ts
.type
== BT_DERIVED
&& me_arg
->ts
.u
.derived
!= sym
)
10948 || (me_arg
->ts
.type
== BT_CLASS
10949 && CLASS_DATA (me_arg
)->ts
.u
.derived
!= sym
))
10951 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L must be of"
10952 " the derived type '%s'", me_arg
->name
, c
->name
,
10953 me_arg
->name
, &c
->loc
, sym
->name
);
10958 /* Check for C453. */
10959 if (me_arg
->attr
.dimension
)
10961 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
10962 "must be scalar", me_arg
->name
, c
->name
, me_arg
->name
,
10968 if (me_arg
->attr
.pointer
)
10970 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
10971 "may not have the POINTER attribute", me_arg
->name
,
10972 c
->name
, me_arg
->name
, &c
->loc
);
10977 if (me_arg
->attr
.allocatable
)
10979 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
10980 "may not be ALLOCATABLE", me_arg
->name
, c
->name
,
10981 me_arg
->name
, &c
->loc
);
10986 if (gfc_type_is_extensible (sym
) && me_arg
->ts
.type
!= BT_CLASS
)
10987 gfc_error ("Non-polymorphic passed-object dummy argument of '%s'"
10988 " at %L", c
->name
, &c
->loc
);
10992 /* Check type-spec if this is not the parent-type component. */
10993 if ((!sym
->attr
.extension
|| c
!= sym
->components
)
10994 && resolve_typespec_used (&c
->ts
, &c
->loc
, c
->name
) == FAILURE
)
10997 /* If this type is an extension, set the accessibility of the parent
10999 if (super_type
&& c
== sym
->components
11000 && strcmp (super_type
->name
, c
->name
) == 0)
11001 c
->attr
.access
= super_type
->attr
.access
;
11003 /* If this type is an extension, see if this component has the same name
11004 as an inherited type-bound procedure. */
11005 if (super_type
&& !sym
->attr
.is_class
11006 && gfc_find_typebound_proc (super_type
, NULL
, c
->name
, true, NULL
))
11008 gfc_error ("Component '%s' of '%s' at %L has the same name as an"
11009 " inherited type-bound procedure",
11010 c
->name
, sym
->name
, &c
->loc
);
11014 if (c
->ts
.type
== BT_CHARACTER
&& !c
->attr
.proc_pointer
)
11016 if (c
->ts
.u
.cl
->length
== NULL
11017 || (resolve_charlen (c
->ts
.u
.cl
) == FAILURE
)
11018 || !gfc_is_constant_expr (c
->ts
.u
.cl
->length
))
11020 gfc_error ("Character length of component '%s' needs to "
11021 "be a constant specification expression at %L",
11023 c
->ts
.u
.cl
->length
? &c
->ts
.u
.cl
->length
->where
: &c
->loc
);
11028 if (c
->ts
.type
== BT_DERIVED
11029 && sym
->component_access
!= ACCESS_PRIVATE
11030 && gfc_check_access (sym
->attr
.access
, sym
->ns
->default_access
)
11031 && !is_sym_host_assoc (c
->ts
.u
.derived
, sym
->ns
)
11032 && !c
->ts
.u
.derived
->attr
.use_assoc
11033 && !gfc_check_access (c
->ts
.u
.derived
->attr
.access
,
11034 c
->ts
.u
.derived
->ns
->default_access
)
11035 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: the component '%s' "
11036 "is a PRIVATE type and cannot be a component of "
11037 "'%s', which is PUBLIC at %L", c
->name
,
11038 sym
->name
, &sym
->declared_at
) == FAILURE
)
11041 if (sym
->attr
.sequence
)
11043 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.sequence
== 0)
11045 gfc_error ("Component %s of SEQUENCE type declared at %L does "
11046 "not have the SEQUENCE attribute",
11047 c
->ts
.u
.derived
->name
, &sym
->declared_at
);
11052 if (!sym
->attr
.is_class
&& c
->ts
.type
== BT_DERIVED
&& c
->attr
.pointer
11053 && c
->ts
.u
.derived
->components
== NULL
11054 && !c
->ts
.u
.derived
->attr
.zero_comp
)
11056 gfc_error ("The pointer component '%s' of '%s' at %L is a type "
11057 "that has not been declared", c
->name
, sym
->name
,
11062 if (c
->ts
.type
== BT_CLASS
&& CLASS_DATA (c
)->attr
.class_pointer
11063 && CLASS_DATA (c
)->ts
.u
.derived
->components
== NULL
11064 && !CLASS_DATA (c
)->ts
.u
.derived
->attr
.zero_comp
)
11066 gfc_error ("The pointer component '%s' of '%s' at %L is a type "
11067 "that has not been declared", c
->name
, sym
->name
,
11073 if (c
->ts
.type
== BT_CLASS
11074 && !(CLASS_DATA (c
)->attr
.class_pointer
11075 || CLASS_DATA (c
)->attr
.allocatable
))
11077 gfc_error ("Component '%s' with CLASS at %L must be allocatable "
11078 "or pointer", c
->name
, &c
->loc
);
11082 /* Ensure that all the derived type components are put on the
11083 derived type list; even in formal namespaces, where derived type
11084 pointer components might not have been declared. */
11085 if (c
->ts
.type
== BT_DERIVED
11087 && c
->ts
.u
.derived
->components
11089 && sym
!= c
->ts
.u
.derived
)
11090 add_dt_to_dt_list (c
->ts
.u
.derived
);
11092 if (c
->attr
.pointer
|| c
->attr
.proc_pointer
|| c
->attr
.allocatable
11096 for (i
= 0; i
< c
->as
->rank
; i
++)
11098 if (c
->as
->lower
[i
] == NULL
11099 || (resolve_index_expr (c
->as
->lower
[i
]) == FAILURE
)
11100 || !gfc_is_constant_expr (c
->as
->lower
[i
])
11101 || c
->as
->upper
[i
] == NULL
11102 || (resolve_index_expr (c
->as
->upper
[i
]) == FAILURE
)
11103 || !gfc_is_constant_expr (c
->as
->upper
[i
]))
11105 gfc_error ("Component '%s' of '%s' at %L must have "
11106 "constant array bounds",
11107 c
->name
, sym
->name
, &c
->loc
);
11113 /* Resolve the type-bound procedures. */
11114 if (resolve_typebound_procedures (sym
) == FAILURE
)
11117 /* Resolve the finalizer procedures. */
11118 if (gfc_resolve_finalizers (sym
) == FAILURE
)
11121 /* If this is a non-ABSTRACT type extending an ABSTRACT one, ensure that
11122 all DEFERRED bindings are overridden. */
11123 if (super_type
&& super_type
->attr
.abstract
&& !sym
->attr
.abstract
11124 && !sym
->attr
.is_class
11125 && ensure_not_abstract (sym
, super_type
) == FAILURE
)
11128 /* Add derived type to the derived type list. */
11129 add_dt_to_dt_list (sym
);
11136 resolve_fl_namelist (gfc_symbol
*sym
)
11141 /* Reject PRIVATE objects in a PUBLIC namelist. */
11142 if (gfc_check_access(sym
->attr
.access
, sym
->ns
->default_access
))
11144 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
11146 if (!nl
->sym
->attr
.use_assoc
11147 && !is_sym_host_assoc (nl
->sym
, sym
->ns
)
11148 && !gfc_check_access(nl
->sym
->attr
.access
,
11149 nl
->sym
->ns
->default_access
))
11151 gfc_error ("NAMELIST object '%s' was declared PRIVATE and "
11152 "cannot be member of PUBLIC namelist '%s' at %L",
11153 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
11157 /* Types with private components that came here by USE-association. */
11158 if (nl
->sym
->ts
.type
== BT_DERIVED
11159 && derived_inaccessible (nl
->sym
->ts
.u
.derived
))
11161 gfc_error ("NAMELIST object '%s' has use-associated PRIVATE "
11162 "components and cannot be member of namelist '%s' at %L",
11163 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
11167 /* Types with private components that are defined in the same module. */
11168 if (nl
->sym
->ts
.type
== BT_DERIVED
11169 && !is_sym_host_assoc (nl
->sym
->ts
.u
.derived
, sym
->ns
)
11170 && !gfc_check_access (nl
->sym
->ts
.u
.derived
->attr
.private_comp
11171 ? ACCESS_PRIVATE
: ACCESS_UNKNOWN
,
11172 nl
->sym
->ns
->default_access
))
11174 gfc_error ("NAMELIST object '%s' has PRIVATE components and "
11175 "cannot be a member of PUBLIC namelist '%s' at %L",
11176 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
11182 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
11184 /* Reject namelist arrays of assumed shape. */
11185 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SHAPE
11186 && gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object '%s' "
11187 "must not have assumed shape in namelist "
11188 "'%s' at %L", nl
->sym
->name
, sym
->name
,
11189 &sym
->declared_at
) == FAILURE
)
11192 /* Reject namelist arrays that are not constant shape. */
11193 if (is_non_constant_shape_array (nl
->sym
))
11195 gfc_error ("NAMELIST array object '%s' must have constant "
11196 "shape in namelist '%s' at %L", nl
->sym
->name
,
11197 sym
->name
, &sym
->declared_at
);
11201 /* Namelist objects cannot have allocatable or pointer components. */
11202 if (nl
->sym
->ts
.type
!= BT_DERIVED
)
11205 if (nl
->sym
->ts
.u
.derived
->attr
.alloc_comp
)
11207 gfc_error ("NAMELIST object '%s' in namelist '%s' at %L cannot "
11208 "have ALLOCATABLE components",
11209 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
11213 if (nl
->sym
->ts
.u
.derived
->attr
.pointer_comp
)
11215 gfc_error ("NAMELIST object '%s' in namelist '%s' at %L cannot "
11216 "have POINTER components",
11217 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
11223 /* 14.1.2 A module or internal procedure represent local entities
11224 of the same type as a namelist member and so are not allowed. */
11225 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
11227 if (nl
->sym
->ts
.kind
!= 0 && nl
->sym
->attr
.flavor
== FL_VARIABLE
)
11230 if (nl
->sym
->attr
.function
&& nl
->sym
== nl
->sym
->result
)
11231 if ((nl
->sym
== sym
->ns
->proc_name
)
11233 (sym
->ns
->parent
&& nl
->sym
== sym
->ns
->parent
->proc_name
))
11237 if (nl
->sym
&& nl
->sym
->name
)
11238 gfc_find_symbol (nl
->sym
->name
, sym
->ns
, 1, &nlsym
);
11239 if (nlsym
&& nlsym
->attr
.flavor
== FL_PROCEDURE
)
11241 gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
11242 "attribute in '%s' at %L", nlsym
->name
,
11243 &sym
->declared_at
);
11253 resolve_fl_parameter (gfc_symbol
*sym
)
11255 /* A parameter array's shape needs to be constant. */
11256 if (sym
->as
!= NULL
11257 && (sym
->as
->type
== AS_DEFERRED
11258 || is_non_constant_shape_array (sym
)))
11260 gfc_error ("Parameter array '%s' at %L cannot be automatic "
11261 "or of deferred shape", sym
->name
, &sym
->declared_at
);
11265 /* Make sure a parameter that has been implicitly typed still
11266 matches the implicit type, since PARAMETER statements can precede
11267 IMPLICIT statements. */
11268 if (sym
->attr
.implicit_type
11269 && !gfc_compare_types (&sym
->ts
, gfc_get_default_type (sym
->name
,
11272 gfc_error ("Implicitly typed PARAMETER '%s' at %L doesn't match a "
11273 "later IMPLICIT type", sym
->name
, &sym
->declared_at
);
11277 /* Make sure the types of derived parameters are consistent. This
11278 type checking is deferred until resolution because the type may
11279 refer to a derived type from the host. */
11280 if (sym
->ts
.type
== BT_DERIVED
11281 && !gfc_compare_types (&sym
->ts
, &sym
->value
->ts
))
11283 gfc_error ("Incompatible derived type in PARAMETER at %L",
11284 &sym
->value
->where
);
11291 /* Do anything necessary to resolve a symbol. Right now, we just
11292 assume that an otherwise unknown symbol is a variable. This sort
11293 of thing commonly happens for symbols in module. */
11296 resolve_symbol (gfc_symbol
*sym
)
11298 int check_constant
, mp_flag
;
11299 gfc_symtree
*symtree
;
11300 gfc_symtree
*this_symtree
;
11304 /* Avoid double resolution of function result symbols. */
11305 if ((sym
->result
|| sym
->attr
.result
) && (sym
->ns
!= gfc_current_ns
))
11308 if (sym
->attr
.flavor
== FL_UNKNOWN
)
11311 /* If we find that a flavorless symbol is an interface in one of the
11312 parent namespaces, find its symtree in this namespace, free the
11313 symbol and set the symtree to point to the interface symbol. */
11314 for (ns
= gfc_current_ns
->parent
; ns
; ns
= ns
->parent
)
11316 symtree
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
11317 if (symtree
&& symtree
->n
.sym
->generic
)
11319 this_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
11323 gfc_free_symbol (sym
);
11324 symtree
->n
.sym
->refs
++;
11325 this_symtree
->n
.sym
= symtree
->n
.sym
;
11330 /* Otherwise give it a flavor according to such attributes as
11332 if (sym
->attr
.external
== 0 && sym
->attr
.intrinsic
== 0)
11333 sym
->attr
.flavor
= FL_VARIABLE
;
11336 sym
->attr
.flavor
= FL_PROCEDURE
;
11337 if (sym
->attr
.dimension
)
11338 sym
->attr
.function
= 1;
11342 if (sym
->attr
.external
&& sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.function
)
11343 gfc_add_function (&sym
->attr
, sym
->name
, &sym
->declared_at
);
11345 if (sym
->attr
.procedure
&& sym
->ts
.interface
11346 && sym
->attr
.if_source
!= IFSRC_DECL
)
11348 if (sym
->ts
.interface
== sym
)
11350 gfc_error ("PROCEDURE '%s' at %L may not be used as its own "
11351 "interface", sym
->name
, &sym
->declared_at
);
11354 if (sym
->ts
.interface
->attr
.procedure
)
11356 gfc_error ("Interface '%s', used by procedure '%s' at %L, is declared"
11357 " in a later PROCEDURE statement", sym
->ts
.interface
->name
,
11358 sym
->name
,&sym
->declared_at
);
11362 /* Get the attributes from the interface (now resolved). */
11363 if (sym
->ts
.interface
->attr
.if_source
11364 || sym
->ts
.interface
->attr
.intrinsic
)
11366 gfc_symbol
*ifc
= sym
->ts
.interface
;
11367 resolve_symbol (ifc
);
11369 if (ifc
->attr
.intrinsic
)
11370 resolve_intrinsic (ifc
, &ifc
->declared_at
);
11373 sym
->ts
= ifc
->result
->ts
;
11376 sym
->ts
.interface
= ifc
;
11377 sym
->attr
.function
= ifc
->attr
.function
;
11378 sym
->attr
.subroutine
= ifc
->attr
.subroutine
;
11379 gfc_copy_formal_args (sym
, ifc
);
11381 sym
->attr
.allocatable
= ifc
->attr
.allocatable
;
11382 sym
->attr
.pointer
= ifc
->attr
.pointer
;
11383 sym
->attr
.pure
= ifc
->attr
.pure
;
11384 sym
->attr
.elemental
= ifc
->attr
.elemental
;
11385 sym
->attr
.dimension
= ifc
->attr
.dimension
;
11386 sym
->attr
.contiguous
= ifc
->attr
.contiguous
;
11387 sym
->attr
.recursive
= ifc
->attr
.recursive
;
11388 sym
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
11389 sym
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
11390 /* Copy array spec. */
11391 sym
->as
= gfc_copy_array_spec (ifc
->as
);
11395 for (i
= 0; i
< sym
->as
->rank
; i
++)
11397 gfc_expr_replace_symbols (sym
->as
->lower
[i
], sym
);
11398 gfc_expr_replace_symbols (sym
->as
->upper
[i
], sym
);
11401 /* Copy char length. */
11402 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
11404 sym
->ts
.u
.cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
11405 gfc_expr_replace_symbols (sym
->ts
.u
.cl
->length
, sym
);
11406 if (sym
->ts
.u
.cl
->length
&& !sym
->ts
.u
.cl
->resolved
11407 && gfc_resolve_expr (sym
->ts
.u
.cl
->length
) == FAILURE
)
11411 else if (sym
->ts
.interface
->name
[0] != '\0')
11413 gfc_error ("Interface '%s' of procedure '%s' at %L must be explicit",
11414 sym
->ts
.interface
->name
, sym
->name
, &sym
->declared_at
);
11419 if (sym
->attr
.is_protected
&& !sym
->attr
.proc_pointer
11420 && (sym
->attr
.procedure
|| sym
->attr
.external
))
11422 if (sym
->attr
.external
)
11423 gfc_error ("PROTECTED attribute conflicts with EXTERNAL attribute "
11424 "at %L", &sym
->declared_at
);
11426 gfc_error ("PROCEDURE attribute conflicts with PROTECTED attribute "
11427 "at %L", &sym
->declared_at
);
11434 if (sym
->attr
.contiguous
11435 && (!sym
->attr
.dimension
|| (sym
->as
->type
!= AS_ASSUMED_SHAPE
11436 && !sym
->attr
.pointer
)))
11438 gfc_error ("'%s' at %L has the CONTIGUOUS attribute but is not an "
11439 "array pointer or an assumed-shape array", sym
->name
,
11440 &sym
->declared_at
);
11444 if (sym
->attr
.flavor
== FL_DERIVED
&& resolve_fl_derived (sym
) == FAILURE
)
11447 /* Symbols that are module procedures with results (functions) have
11448 the types and array specification copied for type checking in
11449 procedures that call them, as well as for saving to a module
11450 file. These symbols can't stand the scrutiny that their results
11452 mp_flag
= (sym
->result
!= NULL
&& sym
->result
!= sym
);
11454 /* Make sure that the intrinsic is consistent with its internal
11455 representation. This needs to be done before assigning a default
11456 type to avoid spurious warnings. */
11457 if (sym
->attr
.flavor
!= FL_MODULE
&& sym
->attr
.intrinsic
11458 && resolve_intrinsic (sym
, &sym
->declared_at
) == FAILURE
)
11461 /* For associate names, resolve corresponding expression and make sure
11462 they get their type-spec set this way. */
11465 gcc_assert (sym
->attr
.flavor
== FL_VARIABLE
);
11466 if (gfc_resolve_expr (sym
->assoc
->target
) != SUCCESS
)
11469 sym
->ts
= sym
->assoc
->target
->ts
;
11470 gcc_assert (sym
->ts
.type
!= BT_UNKNOWN
);
11473 /* Assign default type to symbols that need one and don't have one. */
11474 if (sym
->ts
.type
== BT_UNKNOWN
)
11476 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
)
11477 gfc_set_default_type (sym
, 1, NULL
);
11479 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.external
11480 && !sym
->attr
.function
&& !sym
->attr
.subroutine
11481 && gfc_get_default_type (sym
->name
, sym
->ns
)->type
== BT_UNKNOWN
)
11482 gfc_add_subroutine (&sym
->attr
, sym
->name
, &sym
->declared_at
);
11484 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
11486 /* The specific case of an external procedure should emit an error
11487 in the case that there is no implicit type. */
11489 gfc_set_default_type (sym
, sym
->attr
.external
, NULL
);
11492 /* Result may be in another namespace. */
11493 resolve_symbol (sym
->result
);
11495 if (!sym
->result
->attr
.proc_pointer
)
11497 sym
->ts
= sym
->result
->ts
;
11498 sym
->as
= gfc_copy_array_spec (sym
->result
->as
);
11499 sym
->attr
.dimension
= sym
->result
->attr
.dimension
;
11500 sym
->attr
.pointer
= sym
->result
->attr
.pointer
;
11501 sym
->attr
.allocatable
= sym
->result
->attr
.allocatable
;
11502 sym
->attr
.contiguous
= sym
->result
->attr
.contiguous
;
11508 /* Assumed size arrays and assumed shape arrays must be dummy
11511 if (sym
->as
!= NULL
11512 && ((sym
->as
->type
== AS_ASSUMED_SIZE
&& !sym
->as
->cp_was_assumed
)
11513 || sym
->as
->type
== AS_ASSUMED_SHAPE
)
11514 && sym
->attr
.dummy
== 0)
11516 if (sym
->as
->type
== AS_ASSUMED_SIZE
)
11517 gfc_error ("Assumed size array at %L must be a dummy argument",
11518 &sym
->declared_at
);
11520 gfc_error ("Assumed shape array at %L must be a dummy argument",
11521 &sym
->declared_at
);
11525 /* Make sure symbols with known intent or optional are really dummy
11526 variable. Because of ENTRY statement, this has to be deferred
11527 until resolution time. */
11529 if (!sym
->attr
.dummy
11530 && (sym
->attr
.optional
|| sym
->attr
.intent
!= INTENT_UNKNOWN
))
11532 gfc_error ("Symbol at %L is not a DUMMY variable", &sym
->declared_at
);
11536 if (sym
->attr
.value
&& !sym
->attr
.dummy
)
11538 gfc_error ("'%s' at %L cannot have the VALUE attribute because "
11539 "it is not a dummy argument", sym
->name
, &sym
->declared_at
);
11543 if (sym
->attr
.value
&& sym
->ts
.type
== BT_CHARACTER
)
11545 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
11546 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
11548 gfc_error ("Character dummy variable '%s' at %L with VALUE "
11549 "attribute must have constant length",
11550 sym
->name
, &sym
->declared_at
);
11554 if (sym
->ts
.is_c_interop
11555 && mpz_cmp_si (cl
->length
->value
.integer
, 1) != 0)
11557 gfc_error ("C interoperable character dummy variable '%s' at %L "
11558 "with VALUE attribute must have length one",
11559 sym
->name
, &sym
->declared_at
);
11564 /* If the symbol is marked as bind(c), verify it's type and kind. Do not
11565 do this for something that was implicitly typed because that is handled
11566 in gfc_set_default_type. Handle dummy arguments and procedure
11567 definitions separately. Also, anything that is use associated is not
11568 handled here but instead is handled in the module it is declared in.
11569 Finally, derived type definitions are allowed to be BIND(C) since that
11570 only implies that they're interoperable, and they are checked fully for
11571 interoperability when a variable is declared of that type. */
11572 if (sym
->attr
.is_bind_c
&& sym
->attr
.implicit_type
== 0 &&
11573 sym
->attr
.use_assoc
== 0 && sym
->attr
.dummy
== 0 &&
11574 sym
->attr
.flavor
!= FL_PROCEDURE
&& sym
->attr
.flavor
!= FL_DERIVED
)
11576 gfc_try t
= SUCCESS
;
11578 /* First, make sure the variable is declared at the
11579 module-level scope (J3/04-007, Section 15.3). */
11580 if (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
&&
11581 sym
->attr
.in_common
== 0)
11583 gfc_error ("Variable '%s' at %L cannot be BIND(C) because it "
11584 "is neither a COMMON block nor declared at the "
11585 "module level scope", sym
->name
, &(sym
->declared_at
));
11588 else if (sym
->common_head
!= NULL
)
11590 t
= verify_com_block_vars_c_interop (sym
->common_head
);
11594 /* If type() declaration, we need to verify that the components
11595 of the given type are all C interoperable, etc. */
11596 if (sym
->ts
.type
== BT_DERIVED
&&
11597 sym
->ts
.u
.derived
->attr
.is_c_interop
!= 1)
11599 /* Make sure the user marked the derived type as BIND(C). If
11600 not, call the verify routine. This could print an error
11601 for the derived type more than once if multiple variables
11602 of that type are declared. */
11603 if (sym
->ts
.u
.derived
->attr
.is_bind_c
!= 1)
11604 verify_bind_c_derived_type (sym
->ts
.u
.derived
);
11608 /* Verify the variable itself as C interoperable if it
11609 is BIND(C). It is not possible for this to succeed if
11610 the verify_bind_c_derived_type failed, so don't have to handle
11611 any error returned by verify_bind_c_derived_type. */
11612 t
= verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
11613 sym
->common_block
);
11618 /* clear the is_bind_c flag to prevent reporting errors more than
11619 once if something failed. */
11620 sym
->attr
.is_bind_c
= 0;
11625 /* If a derived type symbol has reached this point, without its
11626 type being declared, we have an error. Notice that most
11627 conditions that produce undefined derived types have already
11628 been dealt with. However, the likes of:
11629 implicit type(t) (t) ..... call foo (t) will get us here if
11630 the type is not declared in the scope of the implicit
11631 statement. Change the type to BT_UNKNOWN, both because it is so
11632 and to prevent an ICE. */
11633 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->components
== NULL
11634 && !sym
->ts
.u
.derived
->attr
.zero_comp
)
11636 gfc_error ("The derived type '%s' at %L is of type '%s', "
11637 "which has not been defined", sym
->name
,
11638 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
11639 sym
->ts
.type
= BT_UNKNOWN
;
11643 /* Make sure that the derived type has been resolved and that the
11644 derived type is visible in the symbol's namespace, if it is a
11645 module function and is not PRIVATE. */
11646 if (sym
->ts
.type
== BT_DERIVED
11647 && sym
->ts
.u
.derived
->attr
.use_assoc
11648 && sym
->ns
->proc_name
11649 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
11653 if (resolve_fl_derived (sym
->ts
.u
.derived
) == FAILURE
)
11656 gfc_find_symbol (sym
->ts
.u
.derived
->name
, sym
->ns
, 1, &ds
);
11657 if (!ds
&& sym
->attr
.function
11658 && gfc_check_access (sym
->attr
.access
, sym
->ns
->default_access
))
11660 symtree
= gfc_new_symtree (&sym
->ns
->sym_root
,
11661 sym
->ts
.u
.derived
->name
);
11662 symtree
->n
.sym
= sym
->ts
.u
.derived
;
11663 sym
->ts
.u
.derived
->refs
++;
11667 /* Unless the derived-type declaration is use associated, Fortran 95
11668 does not allow public entries of private derived types.
11669 See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
11670 161 in 95-006r3. */
11671 if (sym
->ts
.type
== BT_DERIVED
11672 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
11673 && !sym
->ts
.u
.derived
->attr
.use_assoc
11674 && gfc_check_access (sym
->attr
.access
, sym
->ns
->default_access
)
11675 && !gfc_check_access (sym
->ts
.u
.derived
->attr
.access
,
11676 sym
->ts
.u
.derived
->ns
->default_access
)
11677 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: PUBLIC %s '%s' at %L "
11678 "of PRIVATE derived type '%s'",
11679 (sym
->attr
.flavor
== FL_PARAMETER
) ? "parameter"
11680 : "variable", sym
->name
, &sym
->declared_at
,
11681 sym
->ts
.u
.derived
->name
) == FAILURE
)
11684 /* An assumed-size array with INTENT(OUT) shall not be of a type for which
11685 default initialization is defined (5.1.2.4.4). */
11686 if (sym
->ts
.type
== BT_DERIVED
11688 && sym
->attr
.intent
== INTENT_OUT
11690 && sym
->as
->type
== AS_ASSUMED_SIZE
)
11692 for (c
= sym
->ts
.u
.derived
->components
; c
; c
= c
->next
)
11694 if (c
->initializer
)
11696 gfc_error ("The INTENT(OUT) dummy argument '%s' at %L is "
11697 "ASSUMED SIZE and so cannot have a default initializer",
11698 sym
->name
, &sym
->declared_at
);
11705 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
11706 || sym
->attr
.codimension
)
11707 && sym
->attr
.result
)
11708 gfc_error ("Function result '%s' at %L shall not be a coarray or have "
11709 "a coarray component", sym
->name
, &sym
->declared_at
);
11712 if (sym
->attr
.codimension
&& sym
->ts
.type
== BT_DERIVED
11713 && sym
->ts
.u
.derived
->ts
.is_iso_c
)
11714 gfc_error ("Variable '%s' at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
11715 "shall not be a coarray", sym
->name
, &sym
->declared_at
);
11718 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
11719 && (sym
->attr
.codimension
|| sym
->attr
.pointer
|| sym
->attr
.dimension
11720 || sym
->attr
.allocatable
))
11721 gfc_error ("Variable '%s' at %L with coarray component "
11722 "shall be a nonpointer, nonallocatable scalar",
11723 sym
->name
, &sym
->declared_at
);
11725 /* F2008, C526. The function-result case was handled above. */
11726 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
11727 || sym
->attr
.codimension
)
11728 && !(sym
->attr
.allocatable
|| sym
->attr
.dummy
|| sym
->attr
.save
11729 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
11730 || sym
->ns
->proc_name
->attr
.is_main_program
11731 || sym
->attr
.function
|| sym
->attr
.result
|| sym
->attr
.use_assoc
))
11732 gfc_error ("Variable '%s' at %L is a coarray or has a coarray "
11733 "component and is not ALLOCATABLE, SAVE nor a "
11734 "dummy argument", sym
->name
, &sym
->declared_at
);
11735 /* F2008, C528. */ /* FIXME: sym->as check due to PR 43412. */
11736 else if (sym
->attr
.codimension
&& !sym
->attr
.allocatable
11737 && sym
->as
&& sym
->as
->cotype
== AS_DEFERRED
)
11738 gfc_error ("Coarray variable '%s' at %L shall not have codimensions with "
11739 "deferred shape", sym
->name
, &sym
->declared_at
);
11740 else if (sym
->attr
.codimension
&& sym
->attr
.allocatable
11741 && (sym
->as
->type
!= AS_DEFERRED
|| sym
->as
->cotype
!= AS_DEFERRED
))
11742 gfc_error ("Allocatable coarray variable '%s' at %L must have "
11743 "deferred shape", sym
->name
, &sym
->declared_at
);
11747 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
11748 || (sym
->attr
.codimension
&& sym
->attr
.allocatable
))
11749 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
)
11750 gfc_error ("Variable '%s' at %L is INTENT(OUT) and can thus not be an "
11751 "allocatable coarray or have coarray components",
11752 sym
->name
, &sym
->declared_at
);
11754 if (sym
->attr
.codimension
&& sym
->attr
.dummy
11755 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.is_bind_c
)
11756 gfc_error ("Coarray dummy variable '%s' at %L not allowed in BIND(C) "
11757 "procedure '%s'", sym
->name
, &sym
->declared_at
,
11758 sym
->ns
->proc_name
->name
);
11760 switch (sym
->attr
.flavor
)
11763 if (resolve_fl_variable (sym
, mp_flag
) == FAILURE
)
11768 if (resolve_fl_procedure (sym
, mp_flag
) == FAILURE
)
11773 if (resolve_fl_namelist (sym
) == FAILURE
)
11778 if (resolve_fl_parameter (sym
) == FAILURE
)
11786 /* Resolve array specifier. Check as well some constraints
11787 on COMMON blocks. */
11789 check_constant
= sym
->attr
.in_common
&& !sym
->attr
.pointer
;
11791 /* Set the formal_arg_flag so that check_conflict will not throw
11792 an error for host associated variables in the specification
11793 expression for an array_valued function. */
11794 if (sym
->attr
.function
&& sym
->as
)
11795 formal_arg_flag
= 1;
11797 gfc_resolve_array_spec (sym
->as
, check_constant
);
11799 formal_arg_flag
= 0;
11801 /* Resolve formal namespaces. */
11802 if (sym
->formal_ns
&& sym
->formal_ns
!= gfc_current_ns
11803 && !sym
->attr
.contained
&& !sym
->attr
.intrinsic
)
11804 gfc_resolve (sym
->formal_ns
);
11806 /* Make sure the formal namespace is present. */
11807 if (sym
->formal
&& !sym
->formal_ns
)
11809 gfc_formal_arglist
*formal
= sym
->formal
;
11810 while (formal
&& !formal
->sym
)
11811 formal
= formal
->next
;
11815 sym
->formal_ns
= formal
->sym
->ns
;
11816 sym
->formal_ns
->refs
++;
11820 /* Check threadprivate restrictions. */
11821 if (sym
->attr
.threadprivate
&& !sym
->attr
.save
&& !sym
->ns
->save_all
11822 && (!sym
->attr
.in_common
11823 && sym
->module
== NULL
11824 && (sym
->ns
->proc_name
== NULL
11825 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
11826 gfc_error ("Threadprivate at %L isn't SAVEd", &sym
->declared_at
);
11828 /* If we have come this far we can apply default-initializers, as
11829 described in 14.7.5, to those variables that have not already
11830 been assigned one. */
11831 if (sym
->ts
.type
== BT_DERIVED
11832 && sym
->attr
.referenced
11833 && sym
->ns
== gfc_current_ns
11835 && !sym
->attr
.allocatable
11836 && !sym
->attr
.alloc_comp
)
11838 symbol_attribute
*a
= &sym
->attr
;
11840 if ((!a
->save
&& !a
->dummy
&& !a
->pointer
11841 && !a
->in_common
&& !a
->use_assoc
11842 && !(a
->function
&& sym
!= sym
->result
))
11843 || (a
->dummy
&& a
->intent
== INTENT_OUT
&& !a
->pointer
))
11844 apply_default_init (sym
);
11847 /* If this symbol has a type-spec, check it. */
11848 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
11849 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
))
11850 if (resolve_typespec_used (&sym
->ts
, &sym
->declared_at
, sym
->name
)
11856 /************* Resolve DATA statements *************/
11860 gfc_data_value
*vnode
;
11866 /* Advance the values structure to point to the next value in the data list. */
11869 next_data_value (void)
11871 while (mpz_cmp_ui (values
.left
, 0) == 0)
11874 if (values
.vnode
->next
== NULL
)
11877 values
.vnode
= values
.vnode
->next
;
11878 mpz_set (values
.left
, values
.vnode
->repeat
);
11886 check_data_variable (gfc_data_variable
*var
, locus
*where
)
11892 ar_type mark
= AR_UNKNOWN
;
11894 mpz_t section_index
[GFC_MAX_DIMENSIONS
];
11900 if (gfc_resolve_expr (var
->expr
) == FAILURE
)
11904 mpz_init_set_si (offset
, 0);
11907 if (e
->expr_type
!= EXPR_VARIABLE
)
11908 gfc_internal_error ("check_data_variable(): Bad expression");
11910 sym
= e
->symtree
->n
.sym
;
11912 if (sym
->ns
->is_block_data
&& !sym
->attr
.in_common
)
11914 gfc_error ("BLOCK DATA element '%s' at %L must be in COMMON",
11915 sym
->name
, &sym
->declared_at
);
11918 if (e
->ref
== NULL
&& sym
->as
)
11920 gfc_error ("DATA array '%s' at %L must be specified in a previous"
11921 " declaration", sym
->name
, where
);
11925 has_pointer
= sym
->attr
.pointer
;
11927 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
11929 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.pointer
)
11932 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
)
11934 gfc_error ("DATA element '%s' at %L cannot have a coindex",
11940 && ref
->type
== REF_ARRAY
11941 && ref
->u
.ar
.type
!= AR_FULL
)
11943 gfc_error ("DATA element '%s' at %L is a pointer and so must "
11944 "be a full array", sym
->name
, where
);
11949 if (e
->rank
== 0 || has_pointer
)
11951 mpz_init_set_ui (size
, 1);
11958 /* Find the array section reference. */
11959 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
11961 if (ref
->type
!= REF_ARRAY
)
11963 if (ref
->u
.ar
.type
== AR_ELEMENT
)
11969 /* Set marks according to the reference pattern. */
11970 switch (ref
->u
.ar
.type
)
11978 /* Get the start position of array section. */
11979 gfc_get_section_index (ar
, section_index
, &offset
);
11984 gcc_unreachable ();
11987 if (gfc_array_size (e
, &size
) == FAILURE
)
11989 gfc_error ("Nonconstant array section at %L in DATA statement",
11991 mpz_clear (offset
);
11998 while (mpz_cmp_ui (size
, 0) > 0)
12000 if (next_data_value () == FAILURE
)
12002 gfc_error ("DATA statement at %L has more variables than values",
12008 t
= gfc_check_assign (var
->expr
, values
.vnode
->expr
, 0);
12012 /* If we have more than one element left in the repeat count,
12013 and we have more than one element left in the target variable,
12014 then create a range assignment. */
12015 /* FIXME: Only done for full arrays for now, since array sections
12017 if (mark
== AR_FULL
&& ref
&& ref
->next
== NULL
12018 && mpz_cmp_ui (values
.left
, 1) > 0 && mpz_cmp_ui (size
, 1) > 0)
12022 if (mpz_cmp (size
, values
.left
) >= 0)
12024 mpz_init_set (range
, values
.left
);
12025 mpz_sub (size
, size
, values
.left
);
12026 mpz_set_ui (values
.left
, 0);
12030 mpz_init_set (range
, size
);
12031 mpz_sub (values
.left
, values
.left
, size
);
12032 mpz_set_ui (size
, 0);
12035 t
= gfc_assign_data_value_range (var
->expr
, values
.vnode
->expr
,
12038 mpz_add (offset
, offset
, range
);
12045 /* Assign initial value to symbol. */
12048 mpz_sub_ui (values
.left
, values
.left
, 1);
12049 mpz_sub_ui (size
, size
, 1);
12051 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
, offset
);
12055 if (mark
== AR_FULL
)
12056 mpz_add_ui (offset
, offset
, 1);
12058 /* Modify the array section indexes and recalculate the offset
12059 for next element. */
12060 else if (mark
== AR_SECTION
)
12061 gfc_advance_section (section_index
, ar
, &offset
);
12065 if (mark
== AR_SECTION
)
12067 for (i
= 0; i
< ar
->dimen
; i
++)
12068 mpz_clear (section_index
[i
]);
12072 mpz_clear (offset
);
12078 static gfc_try
traverse_data_var (gfc_data_variable
*, locus
*);
12080 /* Iterate over a list of elements in a DATA statement. */
12083 traverse_data_list (gfc_data_variable
*var
, locus
*where
)
12086 iterator_stack frame
;
12087 gfc_expr
*e
, *start
, *end
, *step
;
12088 gfc_try retval
= SUCCESS
;
12090 mpz_init (frame
.value
);
12093 start
= gfc_copy_expr (var
->iter
.start
);
12094 end
= gfc_copy_expr (var
->iter
.end
);
12095 step
= gfc_copy_expr (var
->iter
.step
);
12097 if (gfc_simplify_expr (start
, 1) == FAILURE
12098 || start
->expr_type
!= EXPR_CONSTANT
)
12100 gfc_error ("start of implied-do loop at %L could not be "
12101 "simplified to a constant value", &start
->where
);
12105 if (gfc_simplify_expr (end
, 1) == FAILURE
12106 || end
->expr_type
!= EXPR_CONSTANT
)
12108 gfc_error ("end of implied-do loop at %L could not be "
12109 "simplified to a constant value", &start
->where
);
12113 if (gfc_simplify_expr (step
, 1) == FAILURE
12114 || step
->expr_type
!= EXPR_CONSTANT
)
12116 gfc_error ("step of implied-do loop at %L could not be "
12117 "simplified to a constant value", &start
->where
);
12122 mpz_set (trip
, end
->value
.integer
);
12123 mpz_sub (trip
, trip
, start
->value
.integer
);
12124 mpz_add (trip
, trip
, step
->value
.integer
);
12126 mpz_div (trip
, trip
, step
->value
.integer
);
12128 mpz_set (frame
.value
, start
->value
.integer
);
12130 frame
.prev
= iter_stack
;
12131 frame
.variable
= var
->iter
.var
->symtree
;
12132 iter_stack
= &frame
;
12134 while (mpz_cmp_ui (trip
, 0) > 0)
12136 if (traverse_data_var (var
->list
, where
) == FAILURE
)
12142 e
= gfc_copy_expr (var
->expr
);
12143 if (gfc_simplify_expr (e
, 1) == FAILURE
)
12150 mpz_add (frame
.value
, frame
.value
, step
->value
.integer
);
12152 mpz_sub_ui (trip
, trip
, 1);
12156 mpz_clear (frame
.value
);
12159 gfc_free_expr (start
);
12160 gfc_free_expr (end
);
12161 gfc_free_expr (step
);
12163 iter_stack
= frame
.prev
;
12168 /* Type resolve variables in the variable list of a DATA statement. */
12171 traverse_data_var (gfc_data_variable
*var
, locus
*where
)
12175 for (; var
; var
= var
->next
)
12177 if (var
->expr
== NULL
)
12178 t
= traverse_data_list (var
, where
);
12180 t
= check_data_variable (var
, where
);
12190 /* Resolve the expressions and iterators associated with a data statement.
12191 This is separate from the assignment checking because data lists should
12192 only be resolved once. */
12195 resolve_data_variables (gfc_data_variable
*d
)
12197 for (; d
; d
= d
->next
)
12199 if (d
->list
== NULL
)
12201 if (gfc_resolve_expr (d
->expr
) == FAILURE
)
12206 if (gfc_resolve_iterator (&d
->iter
, false) == FAILURE
)
12209 if (resolve_data_variables (d
->list
) == FAILURE
)
12218 /* Resolve a single DATA statement. We implement this by storing a pointer to
12219 the value list into static variables, and then recursively traversing the
12220 variables list, expanding iterators and such. */
12223 resolve_data (gfc_data
*d
)
12226 if (resolve_data_variables (d
->var
) == FAILURE
)
12229 values
.vnode
= d
->value
;
12230 if (d
->value
== NULL
)
12231 mpz_set_ui (values
.left
, 0);
12233 mpz_set (values
.left
, d
->value
->repeat
);
12235 if (traverse_data_var (d
->var
, &d
->where
) == FAILURE
)
12238 /* At this point, we better not have any values left. */
12240 if (next_data_value () == SUCCESS
)
12241 gfc_error ("DATA statement at %L has more values than variables",
12246 /* 12.6 Constraint: In a pure subprogram any variable which is in common or
12247 accessed by host or use association, is a dummy argument to a pure function,
12248 is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
12249 is storage associated with any such variable, shall not be used in the
12250 following contexts: (clients of this function). */
12252 /* Determines if a variable is not 'pure', i.e., not assignable within a pure
12253 procedure. Returns zero if assignment is OK, nonzero if there is a
12256 gfc_impure_variable (gfc_symbol
*sym
)
12261 if (sym
->attr
.use_assoc
|| sym
->attr
.in_common
)
12264 /* Check if the symbol's ns is inside the pure procedure. */
12265 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
12269 if (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
12273 proc
= sym
->ns
->proc_name
;
12274 if (sym
->attr
.dummy
&& gfc_pure (proc
)
12275 && ((proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_IN
)
12277 proc
->attr
.function
))
12280 /* TODO: Sort out what can be storage associated, if anything, and include
12281 it here. In principle equivalences should be scanned but it does not
12282 seem to be possible to storage associate an impure variable this way. */
12287 /* Test whether a symbol is pure or not. For a NULL pointer, checks if the
12288 current namespace is inside a pure procedure. */
12291 gfc_pure (gfc_symbol
*sym
)
12293 symbol_attribute attr
;
12298 /* Check if the current namespace or one of its parents
12299 belongs to a pure procedure. */
12300 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
12302 sym
= ns
->proc_name
;
12306 if (attr
.flavor
== FL_PROCEDURE
&& (attr
.pure
|| attr
.elemental
))
12314 return attr
.flavor
== FL_PROCEDURE
&& (attr
.pure
|| attr
.elemental
);
12318 /* Test whether the current procedure is elemental or not. */
12321 gfc_elemental (gfc_symbol
*sym
)
12323 symbol_attribute attr
;
12326 sym
= gfc_current_ns
->proc_name
;
12331 return attr
.flavor
== FL_PROCEDURE
&& attr
.elemental
;
12335 /* Warn about unused labels. */
12338 warn_unused_fortran_label (gfc_st_label
*label
)
12343 warn_unused_fortran_label (label
->left
);
12345 if (label
->defined
== ST_LABEL_UNKNOWN
)
12348 switch (label
->referenced
)
12350 case ST_LABEL_UNKNOWN
:
12351 gfc_warning ("Label %d at %L defined but not used", label
->value
,
12355 case ST_LABEL_BAD_TARGET
:
12356 gfc_warning ("Label %d at %L defined but cannot be used",
12357 label
->value
, &label
->where
);
12364 warn_unused_fortran_label (label
->right
);
12368 /* Returns the sequence type of a symbol or sequence. */
12371 sequence_type (gfc_typespec ts
)
12380 if (ts
.u
.derived
->components
== NULL
)
12381 return SEQ_NONDEFAULT
;
12383 result
= sequence_type (ts
.u
.derived
->components
->ts
);
12384 for (c
= ts
.u
.derived
->components
->next
; c
; c
= c
->next
)
12385 if (sequence_type (c
->ts
) != result
)
12391 if (ts
.kind
!= gfc_default_character_kind
)
12392 return SEQ_NONDEFAULT
;
12394 return SEQ_CHARACTER
;
12397 if (ts
.kind
!= gfc_default_integer_kind
)
12398 return SEQ_NONDEFAULT
;
12400 return SEQ_NUMERIC
;
12403 if (!(ts
.kind
== gfc_default_real_kind
12404 || ts
.kind
== gfc_default_double_kind
))
12405 return SEQ_NONDEFAULT
;
12407 return SEQ_NUMERIC
;
12410 if (ts
.kind
!= gfc_default_complex_kind
)
12411 return SEQ_NONDEFAULT
;
12413 return SEQ_NUMERIC
;
12416 if (ts
.kind
!= gfc_default_logical_kind
)
12417 return SEQ_NONDEFAULT
;
12419 return SEQ_NUMERIC
;
12422 return SEQ_NONDEFAULT
;
12427 /* Resolve derived type EQUIVALENCE object. */
12430 resolve_equivalence_derived (gfc_symbol
*derived
, gfc_symbol
*sym
, gfc_expr
*e
)
12432 gfc_component
*c
= derived
->components
;
12437 /* Shall not be an object of nonsequence derived type. */
12438 if (!derived
->attr
.sequence
)
12440 gfc_error ("Derived type variable '%s' at %L must have SEQUENCE "
12441 "attribute to be an EQUIVALENCE object", sym
->name
,
12446 /* Shall not have allocatable components. */
12447 if (derived
->attr
.alloc_comp
)
12449 gfc_error ("Derived type variable '%s' at %L cannot have ALLOCATABLE "
12450 "components to be an EQUIVALENCE object",sym
->name
,
12455 if (sym
->attr
.in_common
&& gfc_has_default_initializer (sym
->ts
.u
.derived
))
12457 gfc_error ("Derived type variable '%s' at %L with default "
12458 "initialization cannot be in EQUIVALENCE with a variable "
12459 "in COMMON", sym
->name
, &e
->where
);
12463 for (; c
; c
= c
->next
)
12465 if (c
->ts
.type
== BT_DERIVED
12466 && (resolve_equivalence_derived (c
->ts
.u
.derived
, sym
, e
) == FAILURE
))
12469 /* Shall not be an object of sequence derived type containing a pointer
12470 in the structure. */
12471 if (c
->attr
.pointer
)
12473 gfc_error ("Derived type variable '%s' at %L with pointer "
12474 "component(s) cannot be an EQUIVALENCE object",
12475 sym
->name
, &e
->where
);
12483 /* Resolve equivalence object.
12484 An EQUIVALENCE object shall not be a dummy argument, a pointer, a target,
12485 an allocatable array, an object of nonsequence derived type, an object of
12486 sequence derived type containing a pointer at any level of component
12487 selection, an automatic object, a function name, an entry name, a result
12488 name, a named constant, a structure component, or a subobject of any of
12489 the preceding objects. A substring shall not have length zero. A
12490 derived type shall not have components with default initialization nor
12491 shall two objects of an equivalence group be initialized.
12492 Either all or none of the objects shall have an protected attribute.
12493 The simple constraints are done in symbol.c(check_conflict) and the rest
12494 are implemented here. */
12497 resolve_equivalence (gfc_equiv
*eq
)
12500 gfc_symbol
*first_sym
;
12503 locus
*last_where
= NULL
;
12504 seq_type eq_type
, last_eq_type
;
12505 gfc_typespec
*last_ts
;
12506 int object
, cnt_protected
;
12509 last_ts
= &eq
->expr
->symtree
->n
.sym
->ts
;
12511 first_sym
= eq
->expr
->symtree
->n
.sym
;
12515 for (object
= 1; eq
; eq
= eq
->eq
, object
++)
12519 e
->ts
= e
->symtree
->n
.sym
->ts
;
12520 /* match_varspec might not know yet if it is seeing
12521 array reference or substring reference, as it doesn't
12523 if (e
->ref
&& e
->ref
->type
== REF_ARRAY
)
12525 gfc_ref
*ref
= e
->ref
;
12526 sym
= e
->symtree
->n
.sym
;
12528 if (sym
->attr
.dimension
)
12530 ref
->u
.ar
.as
= sym
->as
;
12534 /* For substrings, convert REF_ARRAY into REF_SUBSTRING. */
12535 if (e
->ts
.type
== BT_CHARACTER
12537 && ref
->type
== REF_ARRAY
12538 && ref
->u
.ar
.dimen
== 1
12539 && ref
->u
.ar
.dimen_type
[0] == DIMEN_RANGE
12540 && ref
->u
.ar
.stride
[0] == NULL
)
12542 gfc_expr
*start
= ref
->u
.ar
.start
[0];
12543 gfc_expr
*end
= ref
->u
.ar
.end
[0];
12546 /* Optimize away the (:) reference. */
12547 if (start
== NULL
&& end
== NULL
)
12550 e
->ref
= ref
->next
;
12552 e
->ref
->next
= ref
->next
;
12557 ref
->type
= REF_SUBSTRING
;
12559 start
= gfc_get_int_expr (gfc_default_integer_kind
,
12561 ref
->u
.ss
.start
= start
;
12562 if (end
== NULL
&& e
->ts
.u
.cl
)
12563 end
= gfc_copy_expr (e
->ts
.u
.cl
->length
);
12564 ref
->u
.ss
.end
= end
;
12565 ref
->u
.ss
.length
= e
->ts
.u
.cl
;
12572 /* Any further ref is an error. */
12575 gcc_assert (ref
->type
== REF_ARRAY
);
12576 gfc_error ("Syntax error in EQUIVALENCE statement at %L",
12582 if (gfc_resolve_expr (e
) == FAILURE
)
12585 sym
= e
->symtree
->n
.sym
;
12587 if (sym
->attr
.is_protected
)
12589 if (cnt_protected
> 0 && cnt_protected
!= object
)
12591 gfc_error ("Either all or none of the objects in the "
12592 "EQUIVALENCE set at %L shall have the "
12593 "PROTECTED attribute",
12598 /* Shall not equivalence common block variables in a PURE procedure. */
12599 if (sym
->ns
->proc_name
12600 && sym
->ns
->proc_name
->attr
.pure
12601 && sym
->attr
.in_common
)
12603 gfc_error ("Common block member '%s' at %L cannot be an EQUIVALENCE "
12604 "object in the pure procedure '%s'",
12605 sym
->name
, &e
->where
, sym
->ns
->proc_name
->name
);
12609 /* Shall not be a named constant. */
12610 if (e
->expr_type
== EXPR_CONSTANT
)
12612 gfc_error ("Named constant '%s' at %L cannot be an EQUIVALENCE "
12613 "object", sym
->name
, &e
->where
);
12617 if (e
->ts
.type
== BT_DERIVED
12618 && resolve_equivalence_derived (e
->ts
.u
.derived
, sym
, e
) == FAILURE
)
12621 /* Check that the types correspond correctly:
12623 A numeric sequence structure may be equivalenced to another sequence
12624 structure, an object of default integer type, default real type, double
12625 precision real type, default logical type such that components of the
12626 structure ultimately only become associated to objects of the same
12627 kind. A character sequence structure may be equivalenced to an object
12628 of default character kind or another character sequence structure.
12629 Other objects may be equivalenced only to objects of the same type and
12630 kind parameters. */
12632 /* Identical types are unconditionally OK. */
12633 if (object
== 1 || gfc_compare_types (last_ts
, &sym
->ts
))
12634 goto identical_types
;
12636 last_eq_type
= sequence_type (*last_ts
);
12637 eq_type
= sequence_type (sym
->ts
);
12639 /* Since the pair of objects is not of the same type, mixed or
12640 non-default sequences can be rejected. */
12642 msg
= "Sequence %s with mixed components in EQUIVALENCE "
12643 "statement at %L with different type objects";
12645 && last_eq_type
== SEQ_MIXED
12646 && gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
)
12648 || (eq_type
== SEQ_MIXED
12649 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
12650 &e
->where
) == FAILURE
))
12653 msg
= "Non-default type object or sequence %s in EQUIVALENCE "
12654 "statement at %L with objects of different type";
12656 && last_eq_type
== SEQ_NONDEFAULT
12657 && gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
,
12658 last_where
) == FAILURE
)
12659 || (eq_type
== SEQ_NONDEFAULT
12660 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
12661 &e
->where
) == FAILURE
))
12664 msg
="Non-CHARACTER object '%s' in default CHARACTER "
12665 "EQUIVALENCE statement at %L";
12666 if (last_eq_type
== SEQ_CHARACTER
12667 && eq_type
!= SEQ_CHARACTER
12668 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
12669 &e
->where
) == FAILURE
)
12672 msg
="Non-NUMERIC object '%s' in default NUMERIC "
12673 "EQUIVALENCE statement at %L";
12674 if (last_eq_type
== SEQ_NUMERIC
12675 && eq_type
!= SEQ_NUMERIC
12676 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
12677 &e
->where
) == FAILURE
)
12682 last_where
= &e
->where
;
12687 /* Shall not be an automatic array. */
12688 if (e
->ref
->type
== REF_ARRAY
12689 && gfc_resolve_array_spec (e
->ref
->u
.ar
.as
, 1) == FAILURE
)
12691 gfc_error ("Array '%s' at %L with non-constant bounds cannot be "
12692 "an EQUIVALENCE object", sym
->name
, &e
->where
);
12699 /* Shall not be a structure component. */
12700 if (r
->type
== REF_COMPONENT
)
12702 gfc_error ("Structure component '%s' at %L cannot be an "
12703 "EQUIVALENCE object",
12704 r
->u
.c
.component
->name
, &e
->where
);
12708 /* A substring shall not have length zero. */
12709 if (r
->type
== REF_SUBSTRING
)
12711 if (compare_bound (r
->u
.ss
.start
, r
->u
.ss
.end
) == CMP_GT
)
12713 gfc_error ("Substring at %L has length zero",
12714 &r
->u
.ss
.start
->where
);
12724 /* Resolve function and ENTRY types, issue diagnostics if needed. */
12727 resolve_fntype (gfc_namespace
*ns
)
12729 gfc_entry_list
*el
;
12732 if (ns
->proc_name
== NULL
|| !ns
->proc_name
->attr
.function
)
12735 /* If there are any entries, ns->proc_name is the entry master
12736 synthetic symbol and ns->entries->sym actual FUNCTION symbol. */
12738 sym
= ns
->entries
->sym
;
12740 sym
= ns
->proc_name
;
12741 if (sym
->result
== sym
12742 && sym
->ts
.type
== BT_UNKNOWN
12743 && gfc_set_default_type (sym
, 0, NULL
) == FAILURE
12744 && !sym
->attr
.untyped
)
12746 gfc_error ("Function '%s' at %L has no IMPLICIT type",
12747 sym
->name
, &sym
->declared_at
);
12748 sym
->attr
.untyped
= 1;
12751 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->ts
.u
.derived
->attr
.use_assoc
12752 && !sym
->attr
.contained
12753 && !gfc_check_access (sym
->ts
.u
.derived
->attr
.access
,
12754 sym
->ts
.u
.derived
->ns
->default_access
)
12755 && gfc_check_access (sym
->attr
.access
, sym
->ns
->default_access
))
12757 gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: PUBLIC function '%s' at "
12758 "%L of PRIVATE type '%s'", sym
->name
,
12759 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
12763 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
12765 if (el
->sym
->result
== el
->sym
12766 && el
->sym
->ts
.type
== BT_UNKNOWN
12767 && gfc_set_default_type (el
->sym
, 0, NULL
) == FAILURE
12768 && !el
->sym
->attr
.untyped
)
12770 gfc_error ("ENTRY '%s' at %L has no IMPLICIT type",
12771 el
->sym
->name
, &el
->sym
->declared_at
);
12772 el
->sym
->attr
.untyped
= 1;
12778 /* 12.3.2.1.1 Defined operators. */
12781 check_uop_procedure (gfc_symbol
*sym
, locus where
)
12783 gfc_formal_arglist
*formal
;
12785 if (!sym
->attr
.function
)
12787 gfc_error ("User operator procedure '%s' at %L must be a FUNCTION",
12788 sym
->name
, &where
);
12792 if (sym
->ts
.type
== BT_CHARACTER
12793 && !(sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
)
12794 && !(sym
->result
&& sym
->result
->ts
.u
.cl
12795 && sym
->result
->ts
.u
.cl
->length
))
12797 gfc_error ("User operator procedure '%s' at %L cannot be assumed "
12798 "character length", sym
->name
, &where
);
12802 formal
= sym
->formal
;
12803 if (!formal
|| !formal
->sym
)
12805 gfc_error ("User operator procedure '%s' at %L must have at least "
12806 "one argument", sym
->name
, &where
);
12810 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
12812 gfc_error ("First argument of operator interface at %L must be "
12813 "INTENT(IN)", &where
);
12817 if (formal
->sym
->attr
.optional
)
12819 gfc_error ("First argument of operator interface at %L cannot be "
12820 "optional", &where
);
12824 formal
= formal
->next
;
12825 if (!formal
|| !formal
->sym
)
12828 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
12830 gfc_error ("Second argument of operator interface at %L must be "
12831 "INTENT(IN)", &where
);
12835 if (formal
->sym
->attr
.optional
)
12837 gfc_error ("Second argument of operator interface at %L cannot be "
12838 "optional", &where
);
12844 gfc_error ("Operator interface at %L must have, at most, two "
12845 "arguments", &where
);
12853 gfc_resolve_uops (gfc_symtree
*symtree
)
12855 gfc_interface
*itr
;
12857 if (symtree
== NULL
)
12860 gfc_resolve_uops (symtree
->left
);
12861 gfc_resolve_uops (symtree
->right
);
12863 for (itr
= symtree
->n
.uop
->op
; itr
; itr
= itr
->next
)
12864 check_uop_procedure (itr
->sym
, itr
->sym
->declared_at
);
12868 /* Examine all of the expressions associated with a program unit,
12869 assign types to all intermediate expressions, make sure that all
12870 assignments are to compatible types and figure out which names
12871 refer to which functions or subroutines. It doesn't check code
12872 block, which is handled by resolve_code. */
12875 resolve_types (gfc_namespace
*ns
)
12881 gfc_namespace
* old_ns
= gfc_current_ns
;
12883 /* Check that all IMPLICIT types are ok. */
12884 if (!ns
->seen_implicit_none
)
12887 for (letter
= 0; letter
!= GFC_LETTERS
; ++letter
)
12888 if (ns
->set_flag
[letter
]
12889 && resolve_typespec_used (&ns
->default_type
[letter
],
12890 &ns
->implicit_loc
[letter
],
12895 gfc_current_ns
= ns
;
12897 resolve_entries (ns
);
12899 resolve_common_vars (ns
->blank_common
.head
, false);
12900 resolve_common_blocks (ns
->common_root
);
12902 resolve_contained_functions (ns
);
12904 gfc_traverse_ns (ns
, resolve_bind_c_derived_types
);
12906 for (cl
= ns
->cl_list
; cl
; cl
= cl
->next
)
12907 resolve_charlen (cl
);
12909 gfc_traverse_ns (ns
, resolve_symbol
);
12911 resolve_fntype (ns
);
12913 for (n
= ns
->contained
; n
; n
= n
->sibling
)
12915 if (gfc_pure (ns
->proc_name
) && !gfc_pure (n
->proc_name
))
12916 gfc_error ("Contained procedure '%s' at %L of a PURE procedure must "
12917 "also be PURE", n
->proc_name
->name
,
12918 &n
->proc_name
->declared_at
);
12924 gfc_check_interfaces (ns
);
12926 gfc_traverse_ns (ns
, resolve_values
);
12932 for (d
= ns
->data
; d
; d
= d
->next
)
12936 gfc_traverse_ns (ns
, gfc_formalize_init_value
);
12938 gfc_traverse_ns (ns
, gfc_verify_binding_labels
);
12940 if (ns
->common_root
!= NULL
)
12941 gfc_traverse_symtree (ns
->common_root
, resolve_bind_c_comms
);
12943 for (eq
= ns
->equiv
; eq
; eq
= eq
->next
)
12944 resolve_equivalence (eq
);
12946 /* Warn about unused labels. */
12947 if (warn_unused_label
)
12948 warn_unused_fortran_label (ns
->st_labels
);
12950 gfc_resolve_uops (ns
->uop_root
);
12952 gfc_current_ns
= old_ns
;
12956 /* Call resolve_code recursively. */
12959 resolve_codes (gfc_namespace
*ns
)
12962 bitmap_obstack old_obstack
;
12964 for (n
= ns
->contained
; n
; n
= n
->sibling
)
12967 gfc_current_ns
= ns
;
12969 /* Don't clear 'cs_base' if this is the namespace of a BLOCK construct. */
12970 if (!(ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_LABEL
))
12973 /* Set to an out of range value. */
12974 current_entry_id
= -1;
12976 old_obstack
= labels_obstack
;
12977 bitmap_obstack_initialize (&labels_obstack
);
12979 resolve_code (ns
->code
, ns
);
12981 bitmap_obstack_release (&labels_obstack
);
12982 labels_obstack
= old_obstack
;
12986 /* This function is called after a complete program unit has been compiled.
12987 Its purpose is to examine all of the expressions associated with a program
12988 unit, assign types to all intermediate expressions, make sure that all
12989 assignments are to compatible types and figure out which names refer to
12990 which functions or subroutines. */
12993 gfc_resolve (gfc_namespace
*ns
)
12995 gfc_namespace
*old_ns
;
12996 code_stack
*old_cs_base
;
13002 old_ns
= gfc_current_ns
;
13003 old_cs_base
= cs_base
;
13005 resolve_types (ns
);
13006 resolve_codes (ns
);
13008 gfc_current_ns
= old_ns
;
13009 cs_base
= old_cs_base
;