1 /* Perform type resolution on the various structures.
2 Copyright (C) 2001-2014 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
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 or DO CONCURRENT block. */
62 static int forall_flag
;
63 int gfc_do_concurrent_flag
;
65 /* True when we are resolving an expression that is an actual argument to
67 static bool actual_arg
= false;
68 /* True when we are resolving an expression that is the first actual argument
70 static bool first_actual_arg
= false;
73 /* Nonzero if we're inside a OpenMP WORKSHARE or PARALLEL WORKSHARE block. */
75 static int omp_workshare_flag
;
77 /* Nonzero if we are processing a formal arglist. The corresponding function
78 resets the flag each time that it is read. */
79 static int formal_arg_flag
= 0;
81 /* True if we are resolving a specification expression. */
82 static bool specification_expr
= false;
84 /* The id of the last entry seen. */
85 static int current_entry_id
;
87 /* We use bitmaps to determine if a branch target is valid. */
88 static bitmap_obstack labels_obstack
;
90 /* True when simplifying a EXPR_VARIABLE argument to an inquiry function. */
91 static bool inquiry_argument
= false;
95 gfc_is_formal_arg (void)
97 return formal_arg_flag
;
100 /* Is the symbol host associated? */
102 is_sym_host_assoc (gfc_symbol
*sym
, gfc_namespace
*ns
)
104 for (ns
= ns
->parent
; ns
; ns
= ns
->parent
)
113 /* Ensure a typespec used is valid; for instance, TYPE(t) is invalid if t is
114 an ABSTRACT derived-type. If where is not NULL, an error message with that
115 locus is printed, optionally using name. */
118 resolve_typespec_used (gfc_typespec
* ts
, locus
* where
, const char* name
)
120 if (ts
->type
== BT_DERIVED
&& ts
->u
.derived
->attr
.abstract
)
125 gfc_error ("'%s' at %L is of the ABSTRACT type '%s'",
126 name
, where
, ts
->u
.derived
->name
);
128 gfc_error ("ABSTRACT type '%s' used at %L",
129 ts
->u
.derived
->name
, where
);
140 check_proc_interface (gfc_symbol
*ifc
, locus
*where
)
142 /* Several checks for F08:C1216. */
143 if (ifc
->attr
.procedure
)
145 gfc_error ("Interface '%s' at %L is declared "
146 "in a later PROCEDURE statement", ifc
->name
, where
);
151 /* For generic interfaces, check if there is
152 a specific procedure with the same name. */
153 gfc_interface
*gen
= ifc
->generic
;
154 while (gen
&& strcmp (gen
->sym
->name
, ifc
->name
) != 0)
158 gfc_error ("Interface '%s' at %L may not be generic",
163 if (ifc
->attr
.proc
== PROC_ST_FUNCTION
)
165 gfc_error ("Interface '%s' at %L may not be a statement function",
169 if (gfc_is_intrinsic (ifc
, 0, ifc
->declared_at
)
170 || gfc_is_intrinsic (ifc
, 1, ifc
->declared_at
))
171 ifc
->attr
.intrinsic
= 1;
172 if (ifc
->attr
.intrinsic
&& !gfc_intrinsic_actual_ok (ifc
->name
, 0))
174 gfc_error ("Intrinsic procedure '%s' not allowed in "
175 "PROCEDURE statement at %L", ifc
->name
, where
);
178 if (!ifc
->attr
.if_source
&& !ifc
->attr
.intrinsic
&& ifc
->name
[0] != '\0')
180 gfc_error ("Interface '%s' at %L must be explicit", ifc
->name
, where
);
187 static void resolve_symbol (gfc_symbol
*sym
);
190 /* Resolve the interface for a PROCEDURE declaration or procedure pointer. */
193 resolve_procedure_interface (gfc_symbol
*sym
)
195 gfc_symbol
*ifc
= sym
->ts
.interface
;
202 gfc_error ("PROCEDURE '%s' at %L may not be used as its own interface",
203 sym
->name
, &sym
->declared_at
);
206 if (!check_proc_interface (ifc
, &sym
->declared_at
))
209 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
211 /* Resolve interface and copy attributes. */
212 resolve_symbol (ifc
);
213 if (ifc
->attr
.intrinsic
)
214 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
218 sym
->ts
= ifc
->result
->ts
;
223 sym
->ts
.interface
= ifc
;
224 sym
->attr
.function
= ifc
->attr
.function
;
225 sym
->attr
.subroutine
= ifc
->attr
.subroutine
;
227 sym
->attr
.allocatable
= ifc
->attr
.allocatable
;
228 sym
->attr
.pointer
= ifc
->attr
.pointer
;
229 sym
->attr
.pure
= ifc
->attr
.pure
;
230 sym
->attr
.elemental
= ifc
->attr
.elemental
;
231 sym
->attr
.dimension
= ifc
->attr
.dimension
;
232 sym
->attr
.contiguous
= ifc
->attr
.contiguous
;
233 sym
->attr
.recursive
= ifc
->attr
.recursive
;
234 sym
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
235 sym
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
236 sym
->attr
.is_bind_c
= ifc
->attr
.is_bind_c
;
237 sym
->attr
.class_ok
= ifc
->attr
.class_ok
;
238 /* Copy array spec. */
239 sym
->as
= gfc_copy_array_spec (ifc
->as
);
240 /* Copy char length. */
241 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
243 sym
->ts
.u
.cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
244 if (sym
->ts
.u
.cl
->length
&& !sym
->ts
.u
.cl
->resolved
245 && !gfc_resolve_expr (sym
->ts
.u
.cl
->length
))
254 /* Resolve types of formal argument lists. These have to be done early so that
255 the formal argument lists of module procedures can be copied to the
256 containing module before the individual procedures are resolved
257 individually. We also resolve argument lists of procedures in interface
258 blocks because they are self-contained scoping units.
260 Since a dummy argument cannot be a non-dummy procedure, the only
261 resort left for untyped names are the IMPLICIT types. */
264 resolve_formal_arglist (gfc_symbol
*proc
)
266 gfc_formal_arglist
*f
;
268 bool saved_specification_expr
;
271 if (proc
->result
!= NULL
)
276 if (gfc_elemental (proc
)
277 || sym
->attr
.pointer
|| sym
->attr
.allocatable
278 || (sym
->as
&& sym
->as
->rank
!= 0))
280 proc
->attr
.always_explicit
= 1;
281 sym
->attr
.always_explicit
= 1;
286 for (f
= proc
->formal
; f
; f
= f
->next
)
294 /* Alternate return placeholder. */
295 if (gfc_elemental (proc
))
296 gfc_error ("Alternate return specifier in elemental subroutine "
297 "'%s' at %L is not allowed", proc
->name
,
299 if (proc
->attr
.function
)
300 gfc_error ("Alternate return specifier in function "
301 "'%s' at %L is not allowed", proc
->name
,
305 else if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
306 && !resolve_procedure_interface (sym
))
309 if (strcmp (proc
->name
, sym
->name
) == 0)
311 gfc_error ("Self-referential argument "
312 "'%s' at %L is not allowed", sym
->name
,
317 if (sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
318 resolve_formal_arglist (sym
);
320 if (sym
->attr
.subroutine
|| sym
->attr
.external
)
322 if (sym
->attr
.flavor
== FL_UNKNOWN
)
323 gfc_add_flavor (&sym
->attr
, FL_PROCEDURE
, sym
->name
, &sym
->declared_at
);
327 if (sym
->ts
.type
== BT_UNKNOWN
&& !proc
->attr
.intrinsic
328 && (!sym
->attr
.function
|| sym
->result
== sym
))
329 gfc_set_default_type (sym
, 1, sym
->ns
);
332 as
= sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
333 ? CLASS_DATA (sym
)->as
: sym
->as
;
335 saved_specification_expr
= specification_expr
;
336 specification_expr
= true;
337 gfc_resolve_array_spec (as
, 0);
338 specification_expr
= saved_specification_expr
;
340 /* We can't tell if an array with dimension (:) is assumed or deferred
341 shape until we know if it has the pointer or allocatable attributes.
343 if (as
&& as
->rank
> 0 && as
->type
== AS_DEFERRED
344 && ((sym
->ts
.type
!= BT_CLASS
345 && !(sym
->attr
.pointer
|| sym
->attr
.allocatable
))
346 || (sym
->ts
.type
== BT_CLASS
347 && !(CLASS_DATA (sym
)->attr
.class_pointer
348 || CLASS_DATA (sym
)->attr
.allocatable
)))
349 && sym
->attr
.flavor
!= FL_PROCEDURE
)
351 as
->type
= AS_ASSUMED_SHAPE
;
352 for (i
= 0; i
< as
->rank
; i
++)
353 as
->lower
[i
] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
356 if ((as
&& as
->rank
> 0 && as
->type
== AS_ASSUMED_SHAPE
)
357 || (as
&& as
->type
== AS_ASSUMED_RANK
)
358 || sym
->attr
.pointer
|| sym
->attr
.allocatable
|| sym
->attr
.target
359 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
360 && (CLASS_DATA (sym
)->attr
.class_pointer
361 || CLASS_DATA (sym
)->attr
.allocatable
362 || CLASS_DATA (sym
)->attr
.target
))
363 || sym
->attr
.optional
)
365 proc
->attr
.always_explicit
= 1;
367 proc
->result
->attr
.always_explicit
= 1;
370 /* If the flavor is unknown at this point, it has to be a variable.
371 A procedure specification would have already set the type. */
373 if (sym
->attr
.flavor
== FL_UNKNOWN
)
374 gfc_add_flavor (&sym
->attr
, FL_VARIABLE
, sym
->name
, &sym
->declared_at
);
378 if (sym
->attr
.flavor
== FL_PROCEDURE
)
383 gfc_error ("Dummy procedure '%s' of PURE procedure at %L must "
384 "also be PURE", sym
->name
, &sym
->declared_at
);
388 else if (!sym
->attr
.pointer
)
390 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
)
393 gfc_notify_std (GFC_STD_F2008
, "Argument '%s'"
394 " of pure function '%s' at %L with VALUE "
395 "attribute but without INTENT(IN)",
396 sym
->name
, proc
->name
, &sym
->declared_at
);
398 gfc_error ("Argument '%s' of pure function '%s' at %L must "
399 "be INTENT(IN) or VALUE", sym
->name
, proc
->name
,
403 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
)
406 gfc_notify_std (GFC_STD_F2008
, "Argument '%s'"
407 " of pure subroutine '%s' at %L with VALUE "
408 "attribute but without INTENT", sym
->name
,
409 proc
->name
, &sym
->declared_at
);
411 gfc_error ("Argument '%s' of pure subroutine '%s' at %L "
412 "must have its INTENT specified or have the "
413 "VALUE attribute", sym
->name
, proc
->name
,
419 if (proc
->attr
.implicit_pure
)
421 if (sym
->attr
.flavor
== FL_PROCEDURE
)
424 proc
->attr
.implicit_pure
= 0;
426 else if (!sym
->attr
.pointer
)
428 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
430 proc
->attr
.implicit_pure
= 0;
432 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
434 proc
->attr
.implicit_pure
= 0;
438 if (gfc_elemental (proc
))
441 if (sym
->attr
.codimension
442 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
443 && CLASS_DATA (sym
)->attr
.codimension
))
445 gfc_error ("Coarray dummy argument '%s' at %L to elemental "
446 "procedure", sym
->name
, &sym
->declared_at
);
450 if (sym
->as
|| (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
451 && CLASS_DATA (sym
)->as
))
453 gfc_error ("Argument '%s' of elemental procedure at %L must "
454 "be scalar", sym
->name
, &sym
->declared_at
);
458 if (sym
->attr
.allocatable
459 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
460 && CLASS_DATA (sym
)->attr
.allocatable
))
462 gfc_error ("Argument '%s' of elemental procedure at %L cannot "
463 "have the ALLOCATABLE attribute", sym
->name
,
468 if (sym
->attr
.pointer
469 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
470 && CLASS_DATA (sym
)->attr
.class_pointer
))
472 gfc_error ("Argument '%s' of elemental procedure at %L cannot "
473 "have the POINTER attribute", sym
->name
,
478 if (sym
->attr
.flavor
== FL_PROCEDURE
)
480 gfc_error ("Dummy procedure '%s' not allowed in elemental "
481 "procedure '%s' at %L", sym
->name
, proc
->name
,
486 /* Fortran 2008 Corrigendum 1, C1290a. */
487 if (sym
->attr
.intent
== INTENT_UNKNOWN
&& !sym
->attr
.value
)
489 gfc_error ("Argument '%s' of elemental procedure '%s' at %L must "
490 "have its INTENT specified or have the VALUE "
491 "attribute", sym
->name
, proc
->name
,
497 /* Each dummy shall be specified to be scalar. */
498 if (proc
->attr
.proc
== PROC_ST_FUNCTION
)
502 gfc_error ("Argument '%s' of statement function at %L must "
503 "be scalar", sym
->name
, &sym
->declared_at
);
507 if (sym
->ts
.type
== BT_CHARACTER
)
509 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
510 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
512 gfc_error ("Character-valued argument '%s' of statement "
513 "function at %L must have constant length",
514 sym
->name
, &sym
->declared_at
);
524 /* Work function called when searching for symbols that have argument lists
525 associated with them. */
528 find_arglists (gfc_symbol
*sym
)
530 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
|| sym
->ns
!= gfc_current_ns
531 || sym
->attr
.flavor
== FL_DERIVED
|| sym
->attr
.intrinsic
)
534 resolve_formal_arglist (sym
);
538 /* Given a namespace, resolve all formal argument lists within the namespace.
542 resolve_formal_arglists (gfc_namespace
*ns
)
547 gfc_traverse_ns (ns
, find_arglists
);
552 resolve_contained_fntype (gfc_symbol
*sym
, gfc_namespace
*ns
)
556 /* If this namespace is not a function or an entry master function,
558 if (! sym
|| !(sym
->attr
.function
|| sym
->attr
.flavor
== FL_VARIABLE
)
559 || sym
->attr
.entry_master
)
562 /* Try to find out of what the return type is. */
563 if (sym
->result
->ts
.type
== BT_UNKNOWN
&& sym
->result
->ts
.interface
== NULL
)
565 t
= gfc_set_default_type (sym
->result
, 0, ns
);
567 if (!t
&& !sym
->result
->attr
.untyped
)
569 if (sym
->result
== sym
)
570 gfc_error ("Contained function '%s' at %L has no IMPLICIT type",
571 sym
->name
, &sym
->declared_at
);
572 else if (!sym
->result
->attr
.proc_pointer
)
573 gfc_error ("Result '%s' of contained function '%s' at %L has "
574 "no IMPLICIT type", sym
->result
->name
, sym
->name
,
575 &sym
->result
->declared_at
);
576 sym
->result
->attr
.untyped
= 1;
580 /* Fortran 95 Draft Standard, page 51, Section 5.1.1.5, on the Character
581 type, lists the only ways a character length value of * can be used:
582 dummy arguments of procedures, named constants, and function results
583 in external functions. Internal function results and results of module
584 procedures are not on this list, ergo, not permitted. */
586 if (sym
->result
->ts
.type
== BT_CHARACTER
)
588 gfc_charlen
*cl
= sym
->result
->ts
.u
.cl
;
589 if ((!cl
|| !cl
->length
) && !sym
->result
->ts
.deferred
)
591 /* See if this is a module-procedure and adapt error message
594 gcc_assert (ns
->parent
&& ns
->parent
->proc_name
);
595 module_proc
= (ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
);
597 gfc_error ("Character-valued %s '%s' at %L must not be"
599 module_proc
? _("module procedure")
600 : _("internal function"),
601 sym
->name
, &sym
->declared_at
);
607 /* Add NEW_ARGS to the formal argument list of PROC, taking care not to
608 introduce duplicates. */
611 merge_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
613 gfc_formal_arglist
*f
, *new_arglist
;
616 for (; new_args
!= NULL
; new_args
= new_args
->next
)
618 new_sym
= new_args
->sym
;
619 /* See if this arg is already in the formal argument list. */
620 for (f
= proc
->formal
; f
; f
= f
->next
)
622 if (new_sym
== f
->sym
)
629 /* Add a new argument. Argument order is not important. */
630 new_arglist
= gfc_get_formal_arglist ();
631 new_arglist
->sym
= new_sym
;
632 new_arglist
->next
= proc
->formal
;
633 proc
->formal
= new_arglist
;
638 /* Flag the arguments that are not present in all entries. */
641 check_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
643 gfc_formal_arglist
*f
, *head
;
646 for (f
= proc
->formal
; f
; f
= f
->next
)
651 for (new_args
= head
; new_args
; new_args
= new_args
->next
)
653 if (new_args
->sym
== f
->sym
)
660 f
->sym
->attr
.not_always_present
= 1;
665 /* Resolve alternate entry points. If a symbol has multiple entry points we
666 create a new master symbol for the main routine, and turn the existing
667 symbol into an entry point. */
670 resolve_entries (gfc_namespace
*ns
)
672 gfc_namespace
*old_ns
;
676 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
677 static int master_count
= 0;
679 if (ns
->proc_name
== NULL
)
682 /* No need to do anything if this procedure doesn't have alternate entry
687 /* We may already have resolved alternate entry points. */
688 if (ns
->proc_name
->attr
.entry_master
)
691 /* If this isn't a procedure something has gone horribly wrong. */
692 gcc_assert (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
);
694 /* Remember the current namespace. */
695 old_ns
= gfc_current_ns
;
699 /* Add the main entry point to the list of entry points. */
700 el
= gfc_get_entry_list ();
701 el
->sym
= ns
->proc_name
;
703 el
->next
= ns
->entries
;
705 ns
->proc_name
->attr
.entry
= 1;
707 /* If it is a module function, it needs to be in the right namespace
708 so that gfc_get_fake_result_decl can gather up the results. The
709 need for this arose in get_proc_name, where these beasts were
710 left in their own namespace, to keep prior references linked to
711 the entry declaration.*/
712 if (ns
->proc_name
->attr
.function
713 && ns
->parent
&& ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
716 /* Do the same for entries where the master is not a module
717 procedure. These are retained in the module namespace because
718 of the module procedure declaration. */
719 for (el
= el
->next
; el
; el
= el
->next
)
720 if (el
->sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
721 && el
->sym
->attr
.mod_proc
)
725 /* Add an entry statement for it. */
726 c
= gfc_get_code (EXEC_ENTRY
);
731 /* Create a new symbol for the master function. */
732 /* Give the internal function a unique name (within this file).
733 Also include the function name so the user has some hope of figuring
734 out what is going on. */
735 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "master.%d.%s",
736 master_count
++, ns
->proc_name
->name
);
737 gfc_get_ha_symbol (name
, &proc
);
738 gcc_assert (proc
!= NULL
);
740 gfc_add_procedure (&proc
->attr
, PROC_INTERNAL
, proc
->name
, NULL
);
741 if (ns
->proc_name
->attr
.subroutine
)
742 gfc_add_subroutine (&proc
->attr
, proc
->name
, NULL
);
746 gfc_typespec
*ts
, *fts
;
747 gfc_array_spec
*as
, *fas
;
748 gfc_add_function (&proc
->attr
, proc
->name
, NULL
);
750 fas
= ns
->entries
->sym
->as
;
751 fas
= fas
? fas
: ns
->entries
->sym
->result
->as
;
752 fts
= &ns
->entries
->sym
->result
->ts
;
753 if (fts
->type
== BT_UNKNOWN
)
754 fts
= gfc_get_default_type (ns
->entries
->sym
->result
->name
, NULL
);
755 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
757 ts
= &el
->sym
->result
->ts
;
759 as
= as
? as
: el
->sym
->result
->as
;
760 if (ts
->type
== BT_UNKNOWN
)
761 ts
= gfc_get_default_type (el
->sym
->result
->name
, NULL
);
763 if (! gfc_compare_types (ts
, fts
)
764 || (el
->sym
->result
->attr
.dimension
765 != ns
->entries
->sym
->result
->attr
.dimension
)
766 || (el
->sym
->result
->attr
.pointer
767 != ns
->entries
->sym
->result
->attr
.pointer
))
769 else if (as
&& fas
&& ns
->entries
->sym
->result
!= el
->sym
->result
770 && gfc_compare_array_spec (as
, fas
) == 0)
771 gfc_error ("Function %s at %L has entries with mismatched "
772 "array specifications", ns
->entries
->sym
->name
,
773 &ns
->entries
->sym
->declared_at
);
774 /* The characteristics need to match and thus both need to have
775 the same string length, i.e. both len=*, or both len=4.
776 Having both len=<variable> is also possible, but difficult to
777 check at compile time. */
778 else if (ts
->type
== BT_CHARACTER
&& ts
->u
.cl
&& fts
->u
.cl
779 && (((ts
->u
.cl
->length
&& !fts
->u
.cl
->length
)
780 ||(!ts
->u
.cl
->length
&& fts
->u
.cl
->length
))
782 && ts
->u
.cl
->length
->expr_type
783 != fts
->u
.cl
->length
->expr_type
)
785 && ts
->u
.cl
->length
->expr_type
== EXPR_CONSTANT
786 && mpz_cmp (ts
->u
.cl
->length
->value
.integer
,
787 fts
->u
.cl
->length
->value
.integer
) != 0)))
788 gfc_notify_std (GFC_STD_GNU
, "Function %s at %L with "
789 "entries returning variables of different "
790 "string lengths", ns
->entries
->sym
->name
,
791 &ns
->entries
->sym
->declared_at
);
796 sym
= ns
->entries
->sym
->result
;
797 /* All result types the same. */
799 if (sym
->attr
.dimension
)
800 gfc_set_array_spec (proc
, gfc_copy_array_spec (sym
->as
), NULL
);
801 if (sym
->attr
.pointer
)
802 gfc_add_pointer (&proc
->attr
, NULL
);
806 /* Otherwise the result will be passed through a union by
808 proc
->attr
.mixed_entry_master
= 1;
809 for (el
= ns
->entries
; el
; el
= el
->next
)
811 sym
= el
->sym
->result
;
812 if (sym
->attr
.dimension
)
814 if (el
== ns
->entries
)
815 gfc_error ("FUNCTION result %s can't be an array in "
816 "FUNCTION %s at %L", sym
->name
,
817 ns
->entries
->sym
->name
, &sym
->declared_at
);
819 gfc_error ("ENTRY result %s can't be an array in "
820 "FUNCTION %s at %L", sym
->name
,
821 ns
->entries
->sym
->name
, &sym
->declared_at
);
823 else if (sym
->attr
.pointer
)
825 if (el
== ns
->entries
)
826 gfc_error ("FUNCTION result %s can't be a POINTER in "
827 "FUNCTION %s at %L", sym
->name
,
828 ns
->entries
->sym
->name
, &sym
->declared_at
);
830 gfc_error ("ENTRY result %s can't be a POINTER in "
831 "FUNCTION %s at %L", sym
->name
,
832 ns
->entries
->sym
->name
, &sym
->declared_at
);
837 if (ts
->type
== BT_UNKNOWN
)
838 ts
= gfc_get_default_type (sym
->name
, NULL
);
842 if (ts
->kind
== gfc_default_integer_kind
)
846 if (ts
->kind
== gfc_default_real_kind
847 || ts
->kind
== gfc_default_double_kind
)
851 if (ts
->kind
== gfc_default_complex_kind
)
855 if (ts
->kind
== gfc_default_logical_kind
)
859 /* We will issue error elsewhere. */
867 if (el
== ns
->entries
)
868 gfc_error ("FUNCTION result %s can't be of type %s "
869 "in FUNCTION %s at %L", sym
->name
,
870 gfc_typename (ts
), ns
->entries
->sym
->name
,
873 gfc_error ("ENTRY result %s can't be of type %s "
874 "in FUNCTION %s at %L", sym
->name
,
875 gfc_typename (ts
), ns
->entries
->sym
->name
,
882 proc
->attr
.access
= ACCESS_PRIVATE
;
883 proc
->attr
.entry_master
= 1;
885 /* Merge all the entry point arguments. */
886 for (el
= ns
->entries
; el
; el
= el
->next
)
887 merge_argument_lists (proc
, el
->sym
->formal
);
889 /* Check the master formal arguments for any that are not
890 present in all entry points. */
891 for (el
= ns
->entries
; el
; el
= el
->next
)
892 check_argument_lists (proc
, el
->sym
->formal
);
894 /* Use the master function for the function body. */
895 ns
->proc_name
= proc
;
897 /* Finalize the new symbols. */
898 gfc_commit_symbols ();
900 /* Restore the original namespace. */
901 gfc_current_ns
= old_ns
;
905 /* Resolve common variables. */
907 resolve_common_vars (gfc_symbol
*sym
, bool named_common
)
909 gfc_symbol
*csym
= sym
;
911 for (; csym
; csym
= csym
->common_next
)
913 if (csym
->value
|| csym
->attr
.data
)
915 if (!csym
->ns
->is_block_data
)
916 gfc_notify_std (GFC_STD_GNU
, "Variable '%s' at %L is in COMMON "
917 "but only in BLOCK DATA initialization is "
918 "allowed", csym
->name
, &csym
->declared_at
);
919 else if (!named_common
)
920 gfc_notify_std (GFC_STD_GNU
, "Initialized variable '%s' at %L is "
921 "in a blank COMMON but initialization is only "
922 "allowed in named common blocks", csym
->name
,
926 if (UNLIMITED_POLY (csym
))
927 gfc_error_now ("'%s' in cannot appear in COMMON at %L "
928 "[F2008:C5100]", csym
->name
, &csym
->declared_at
);
930 if (csym
->ts
.type
!= BT_DERIVED
)
933 if (!(csym
->ts
.u
.derived
->attr
.sequence
934 || csym
->ts
.u
.derived
->attr
.is_bind_c
))
935 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
936 "has neither the SEQUENCE nor the BIND(C) "
937 "attribute", csym
->name
, &csym
->declared_at
);
938 if (csym
->ts
.u
.derived
->attr
.alloc_comp
)
939 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
940 "has an ultimate component that is "
941 "allocatable", csym
->name
, &csym
->declared_at
);
942 if (gfc_has_default_initializer (csym
->ts
.u
.derived
))
943 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
944 "may not have default initializer", csym
->name
,
947 if (csym
->attr
.flavor
== FL_UNKNOWN
&& !csym
->attr
.proc_pointer
)
948 gfc_add_flavor (&csym
->attr
, FL_VARIABLE
, csym
->name
, &csym
->declared_at
);
952 /* Resolve common blocks. */
954 resolve_common_blocks (gfc_symtree
*common_root
)
959 if (common_root
== NULL
)
962 if (common_root
->left
)
963 resolve_common_blocks (common_root
->left
);
964 if (common_root
->right
)
965 resolve_common_blocks (common_root
->right
);
967 resolve_common_vars (common_root
->n
.common
->head
, true);
969 /* The common name is a global name - in Fortran 2003 also if it has a
970 C binding name, since Fortran 2008 only the C binding name is a global
972 if (!common_root
->n
.common
->binding_label
973 || gfc_notification_std (GFC_STD_F2008
))
975 gsym
= gfc_find_gsymbol (gfc_gsym_root
,
976 common_root
->n
.common
->name
);
978 if (gsym
&& gfc_notification_std (GFC_STD_F2008
)
979 && gsym
->type
== GSYM_COMMON
980 && ((common_root
->n
.common
->binding_label
981 && (!gsym
->binding_label
982 || strcmp (common_root
->n
.common
->binding_label
,
983 gsym
->binding_label
) != 0))
984 || (!common_root
->n
.common
->binding_label
985 && gsym
->binding_label
)))
987 gfc_error ("In Fortran 2003 COMMON '%s' block at %L is a global "
988 "identifier and must thus have the same binding name "
989 "as the same-named COMMON block at %L: %s vs %s",
990 common_root
->n
.common
->name
, &common_root
->n
.common
->where
,
992 common_root
->n
.common
->binding_label
993 ? common_root
->n
.common
->binding_label
: "(blank)",
994 gsym
->binding_label
? gsym
->binding_label
: "(blank)");
998 if (gsym
&& gsym
->type
!= GSYM_COMMON
999 && !common_root
->n
.common
->binding_label
)
1001 gfc_error ("COMMON block '%s' at %L uses the same global identifier "
1003 common_root
->n
.common
->name
, &common_root
->n
.common
->where
,
1007 if (gsym
&& gsym
->type
!= GSYM_COMMON
)
1009 gfc_error ("Fortran 2008: COMMON block '%s' with binding label at "
1010 "%L sharing the identifier with global non-COMMON-block "
1011 "entity at %L", common_root
->n
.common
->name
,
1012 &common_root
->n
.common
->where
, &gsym
->where
);
1017 gsym
= gfc_get_gsymbol (common_root
->n
.common
->name
);
1018 gsym
->type
= GSYM_COMMON
;
1019 gsym
->where
= common_root
->n
.common
->where
;
1025 if (common_root
->n
.common
->binding_label
)
1027 gsym
= gfc_find_gsymbol (gfc_gsym_root
,
1028 common_root
->n
.common
->binding_label
);
1029 if (gsym
&& gsym
->type
!= GSYM_COMMON
)
1031 gfc_error ("COMMON block at %L with binding label %s uses the same "
1032 "global identifier as entity at %L",
1033 &common_root
->n
.common
->where
,
1034 common_root
->n
.common
->binding_label
, &gsym
->where
);
1039 gsym
= gfc_get_gsymbol (common_root
->n
.common
->binding_label
);
1040 gsym
->type
= GSYM_COMMON
;
1041 gsym
->where
= common_root
->n
.common
->where
;
1047 gfc_find_symbol (common_root
->name
, gfc_current_ns
, 0, &sym
);
1051 if (sym
->attr
.flavor
== FL_PARAMETER
)
1052 gfc_error ("COMMON block '%s' at %L is used as PARAMETER at %L",
1053 sym
->name
, &common_root
->n
.common
->where
, &sym
->declared_at
);
1055 if (sym
->attr
.external
)
1056 gfc_error ("COMMON block '%s' at %L can not have the EXTERNAL attribute",
1057 sym
->name
, &common_root
->n
.common
->where
);
1059 if (sym
->attr
.intrinsic
)
1060 gfc_error ("COMMON block '%s' at %L is also an intrinsic procedure",
1061 sym
->name
, &common_root
->n
.common
->where
);
1062 else if (sym
->attr
.result
1063 || gfc_is_function_return_value (sym
, gfc_current_ns
))
1064 gfc_notify_std (GFC_STD_F2003
, "COMMON block '%s' at %L "
1065 "that is also a function result", sym
->name
,
1066 &common_root
->n
.common
->where
);
1067 else if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.proc
!= PROC_INTERNAL
1068 && sym
->attr
.proc
!= PROC_ST_FUNCTION
)
1069 gfc_notify_std (GFC_STD_F2003
, "COMMON block '%s' at %L "
1070 "that is also a global procedure", sym
->name
,
1071 &common_root
->n
.common
->where
);
1075 /* Resolve contained function types. Because contained functions can call one
1076 another, they have to be worked out before any of the contained procedures
1079 The good news is that if a function doesn't already have a type, the only
1080 way it can get one is through an IMPLICIT type or a RESULT variable, because
1081 by definition contained functions are contained namespace they're contained
1082 in, not in a sibling or parent namespace. */
1085 resolve_contained_functions (gfc_namespace
*ns
)
1087 gfc_namespace
*child
;
1090 resolve_formal_arglists (ns
);
1092 for (child
= ns
->contained
; child
; child
= child
->sibling
)
1094 /* Resolve alternate entry points first. */
1095 resolve_entries (child
);
1097 /* Then check function return types. */
1098 resolve_contained_fntype (child
->proc_name
, child
);
1099 for (el
= child
->entries
; el
; el
= el
->next
)
1100 resolve_contained_fntype (el
->sym
, child
);
1105 static bool resolve_fl_derived0 (gfc_symbol
*sym
);
1108 /* Resolve all of the elements of a structure constructor and make sure that
1109 the types are correct. The 'init' flag indicates that the given
1110 constructor is an initializer. */
1113 resolve_structure_cons (gfc_expr
*expr
, int init
)
1115 gfc_constructor
*cons
;
1116 gfc_component
*comp
;
1122 if (expr
->ts
.type
== BT_DERIVED
)
1123 resolve_fl_derived0 (expr
->ts
.u
.derived
);
1125 cons
= gfc_constructor_first (expr
->value
.constructor
);
1127 /* A constructor may have references if it is the result of substituting a
1128 parameter variable. In this case we just pull out the component we
1131 comp
= expr
->ref
->u
.c
.sym
->components
;
1133 comp
= expr
->ts
.u
.derived
->components
;
1135 for (; comp
&& cons
; comp
= comp
->next
, cons
= gfc_constructor_next (cons
))
1142 if (!gfc_resolve_expr (cons
->expr
))
1148 rank
= comp
->as
? comp
->as
->rank
: 0;
1149 if (cons
->expr
->expr_type
!= EXPR_NULL
&& rank
!= cons
->expr
->rank
1150 && (comp
->attr
.allocatable
|| cons
->expr
->rank
))
1152 gfc_error ("The rank of the element in the structure "
1153 "constructor at %L does not match that of the "
1154 "component (%d/%d)", &cons
->expr
->where
,
1155 cons
->expr
->rank
, rank
);
1159 /* If we don't have the right type, try to convert it. */
1161 if (!comp
->attr
.proc_pointer
&&
1162 !gfc_compare_types (&cons
->expr
->ts
, &comp
->ts
))
1164 if (strcmp (comp
->name
, "_extends") == 0)
1166 /* Can afford to be brutal with the _extends initializer.
1167 The derived type can get lost because it is PRIVATE
1168 but it is not usage constrained by the standard. */
1169 cons
->expr
->ts
= comp
->ts
;
1171 else if (comp
->attr
.pointer
&& cons
->expr
->ts
.type
!= BT_UNKNOWN
)
1173 gfc_error ("The element in the structure constructor at %L, "
1174 "for pointer component '%s', is %s but should be %s",
1175 &cons
->expr
->where
, comp
->name
,
1176 gfc_basic_typename (cons
->expr
->ts
.type
),
1177 gfc_basic_typename (comp
->ts
.type
));
1182 bool t2
= gfc_convert_type (cons
->expr
, &comp
->ts
, 1);
1188 /* For strings, the length of the constructor should be the same as
1189 the one of the structure, ensure this if the lengths are known at
1190 compile time and when we are dealing with PARAMETER or structure
1192 if (cons
->expr
->ts
.type
== BT_CHARACTER
&& comp
->ts
.u
.cl
1193 && comp
->ts
.u
.cl
->length
1194 && comp
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1195 && cons
->expr
->ts
.u
.cl
&& cons
->expr
->ts
.u
.cl
->length
1196 && cons
->expr
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1197 && cons
->expr
->rank
!= 0
1198 && mpz_cmp (cons
->expr
->ts
.u
.cl
->length
->value
.integer
,
1199 comp
->ts
.u
.cl
->length
->value
.integer
) != 0)
1201 if (cons
->expr
->expr_type
== EXPR_VARIABLE
1202 && cons
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
)
1204 /* Wrap the parameter in an array constructor (EXPR_ARRAY)
1205 to make use of the gfc_resolve_character_array_constructor
1206 machinery. The expression is later simplified away to
1207 an array of string literals. */
1208 gfc_expr
*para
= cons
->expr
;
1209 cons
->expr
= gfc_get_expr ();
1210 cons
->expr
->ts
= para
->ts
;
1211 cons
->expr
->where
= para
->where
;
1212 cons
->expr
->expr_type
= EXPR_ARRAY
;
1213 cons
->expr
->rank
= para
->rank
;
1214 cons
->expr
->shape
= gfc_copy_shape (para
->shape
, para
->rank
);
1215 gfc_constructor_append_expr (&cons
->expr
->value
.constructor
,
1216 para
, &cons
->expr
->where
);
1218 if (cons
->expr
->expr_type
== EXPR_ARRAY
)
1221 p
= gfc_constructor_first (cons
->expr
->value
.constructor
);
1222 if (cons
->expr
->ts
.u
.cl
!= p
->expr
->ts
.u
.cl
)
1224 gfc_charlen
*cl
, *cl2
;
1227 for (cl
= gfc_current_ns
->cl_list
; cl
; cl
= cl
->next
)
1229 if (cl
== cons
->expr
->ts
.u
.cl
)
1237 cl2
->next
= cl
->next
;
1239 gfc_free_expr (cl
->length
);
1243 cons
->expr
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
1244 cons
->expr
->ts
.u
.cl
->length_from_typespec
= true;
1245 cons
->expr
->ts
.u
.cl
->length
= gfc_copy_expr (comp
->ts
.u
.cl
->length
);
1246 gfc_resolve_character_array_constructor (cons
->expr
);
1250 if (cons
->expr
->expr_type
== EXPR_NULL
1251 && !(comp
->attr
.pointer
|| comp
->attr
.allocatable
1252 || comp
->attr
.proc_pointer
|| comp
->ts
.f90_type
== BT_VOID
1253 || (comp
->ts
.type
== BT_CLASS
1254 && (CLASS_DATA (comp
)->attr
.class_pointer
1255 || CLASS_DATA (comp
)->attr
.allocatable
))))
1258 gfc_error ("The NULL in the structure constructor at %L is "
1259 "being applied to component '%s', which is neither "
1260 "a POINTER nor ALLOCATABLE", &cons
->expr
->where
,
1264 if (comp
->attr
.proc_pointer
&& comp
->ts
.interface
)
1266 /* Check procedure pointer interface. */
1267 gfc_symbol
*s2
= NULL
;
1272 c2
= gfc_get_proc_ptr_comp (cons
->expr
);
1275 s2
= c2
->ts
.interface
;
1278 else if (cons
->expr
->expr_type
== EXPR_FUNCTION
)
1280 s2
= cons
->expr
->symtree
->n
.sym
->result
;
1281 name
= cons
->expr
->symtree
->n
.sym
->result
->name
;
1283 else if (cons
->expr
->expr_type
!= EXPR_NULL
)
1285 s2
= cons
->expr
->symtree
->n
.sym
;
1286 name
= cons
->expr
->symtree
->n
.sym
->name
;
1289 if (s2
&& !gfc_compare_interfaces (comp
->ts
.interface
, s2
, name
, 0, 1,
1290 err
, sizeof (err
), NULL
, NULL
))
1292 gfc_error ("Interface mismatch for procedure-pointer component "
1293 "'%s' in structure constructor at %L: %s",
1294 comp
->name
, &cons
->expr
->where
, err
);
1299 if (!comp
->attr
.pointer
|| comp
->attr
.proc_pointer
1300 || cons
->expr
->expr_type
== EXPR_NULL
)
1303 a
= gfc_expr_attr (cons
->expr
);
1305 if (!a
.pointer
&& !a
.target
)
1308 gfc_error ("The element in the structure constructor at %L, "
1309 "for pointer component '%s' should be a POINTER or "
1310 "a TARGET", &cons
->expr
->where
, comp
->name
);
1315 /* F08:C461. Additional checks for pointer initialization. */
1319 gfc_error ("Pointer initialization target at %L "
1320 "must not be ALLOCATABLE ", &cons
->expr
->where
);
1325 gfc_error ("Pointer initialization target at %L "
1326 "must have the SAVE attribute", &cons
->expr
->where
);
1330 /* F2003, C1272 (3). */
1331 bool impure
= cons
->expr
->expr_type
== EXPR_VARIABLE
1332 && (gfc_impure_variable (cons
->expr
->symtree
->n
.sym
)
1333 || gfc_is_coindexed (cons
->expr
));
1334 if (impure
&& gfc_pure (NULL
))
1337 gfc_error ("Invalid expression in the structure constructor for "
1338 "pointer component '%s' at %L in PURE procedure",
1339 comp
->name
, &cons
->expr
->where
);
1343 gfc_unset_implicit_pure (NULL
);
1350 /****************** Expression name resolution ******************/
1352 /* Returns 0 if a symbol was not declared with a type or
1353 attribute declaration statement, nonzero otherwise. */
1356 was_declared (gfc_symbol
*sym
)
1362 if (!a
.implicit_type
&& sym
->ts
.type
!= BT_UNKNOWN
)
1365 if (a
.allocatable
|| a
.dimension
|| a
.dummy
|| a
.external
|| a
.intrinsic
1366 || a
.optional
|| a
.pointer
|| a
.save
|| a
.target
|| a
.volatile_
1367 || a
.value
|| a
.access
!= ACCESS_UNKNOWN
|| a
.intent
!= INTENT_UNKNOWN
1368 || a
.asynchronous
|| a
.codimension
)
1375 /* Determine if a symbol is generic or not. */
1378 generic_sym (gfc_symbol
*sym
)
1382 if (sym
->attr
.generic
||
1383 (sym
->attr
.intrinsic
&& gfc_generic_intrinsic (sym
->name
)))
1386 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1389 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1396 return generic_sym (s
);
1403 /* Determine if a symbol is specific or not. */
1406 specific_sym (gfc_symbol
*sym
)
1410 if (sym
->attr
.if_source
== IFSRC_IFBODY
1411 || sym
->attr
.proc
== PROC_MODULE
1412 || sym
->attr
.proc
== PROC_INTERNAL
1413 || sym
->attr
.proc
== PROC_ST_FUNCTION
1414 || (sym
->attr
.intrinsic
&& gfc_specific_intrinsic (sym
->name
))
1415 || sym
->attr
.external
)
1418 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1421 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1423 return (s
== NULL
) ? 0 : specific_sym (s
);
1427 /* Figure out if the procedure is specific, generic or unknown. */
1430 { PTYPE_GENERIC
= 1, PTYPE_SPECIFIC
, PTYPE_UNKNOWN
}
1434 procedure_kind (gfc_symbol
*sym
)
1436 if (generic_sym (sym
))
1437 return PTYPE_GENERIC
;
1439 if (specific_sym (sym
))
1440 return PTYPE_SPECIFIC
;
1442 return PTYPE_UNKNOWN
;
1445 /* Check references to assumed size arrays. The flag need_full_assumed_size
1446 is nonzero when matching actual arguments. */
1448 static int need_full_assumed_size
= 0;
1451 check_assumed_size_reference (gfc_symbol
*sym
, gfc_expr
*e
)
1453 if (need_full_assumed_size
|| !(sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
))
1456 /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong.
1457 What should it be? */
1458 if (e
->ref
&& (e
->ref
->u
.ar
.end
[e
->ref
->u
.ar
.as
->rank
- 1] == NULL
)
1459 && (e
->ref
->u
.ar
.as
->type
== AS_ASSUMED_SIZE
)
1460 && (e
->ref
->u
.ar
.type
== AR_FULL
))
1462 gfc_error ("The upper bound in the last dimension must "
1463 "appear in the reference to the assumed size "
1464 "array '%s' at %L", sym
->name
, &e
->where
);
1471 /* Look for bad assumed size array references in argument expressions
1472 of elemental and array valued intrinsic procedures. Since this is
1473 called from procedure resolution functions, it only recurses at
1477 resolve_assumed_size_actual (gfc_expr
*e
)
1482 switch (e
->expr_type
)
1485 if (e
->symtree
&& check_assumed_size_reference (e
->symtree
->n
.sym
, e
))
1490 if (resolve_assumed_size_actual (e
->value
.op
.op1
)
1491 || resolve_assumed_size_actual (e
->value
.op
.op2
))
1502 /* Check a generic procedure, passed as an actual argument, to see if
1503 there is a matching specific name. If none, it is an error, and if
1504 more than one, the reference is ambiguous. */
1506 count_specific_procs (gfc_expr
*e
)
1513 sym
= e
->symtree
->n
.sym
;
1515 for (p
= sym
->generic
; p
; p
= p
->next
)
1516 if (strcmp (sym
->name
, p
->sym
->name
) == 0)
1518 e
->symtree
= gfc_find_symtree (p
->sym
->ns
->sym_root
,
1524 gfc_error ("'%s' at %L is ambiguous", e
->symtree
->n
.sym
->name
,
1528 gfc_error ("GENERIC procedure '%s' is not allowed as an actual "
1529 "argument at %L", sym
->name
, &e
->where
);
1535 /* See if a call to sym could possibly be a not allowed RECURSION because of
1536 a missing RECURSIVE declaration. This means that either sym is the current
1537 context itself, or sym is the parent of a contained procedure calling its
1538 non-RECURSIVE containing procedure.
1539 This also works if sym is an ENTRY. */
1542 is_illegal_recursion (gfc_symbol
* sym
, gfc_namespace
* context
)
1544 gfc_symbol
* proc_sym
;
1545 gfc_symbol
* context_proc
;
1546 gfc_namespace
* real_context
;
1548 if (sym
->attr
.flavor
== FL_PROGRAM
1549 || sym
->attr
.flavor
== FL_DERIVED
)
1552 gcc_assert (sym
->attr
.flavor
== FL_PROCEDURE
);
1554 /* If we've got an ENTRY, find real procedure. */
1555 if (sym
->attr
.entry
&& sym
->ns
->entries
)
1556 proc_sym
= sym
->ns
->entries
->sym
;
1560 /* If sym is RECURSIVE, all is well of course. */
1561 if (proc_sym
->attr
.recursive
|| gfc_option
.flag_recursive
)
1564 /* Find the context procedure's "real" symbol if it has entries.
1565 We look for a procedure symbol, so recurse on the parents if we don't
1566 find one (like in case of a BLOCK construct). */
1567 for (real_context
= context
; ; real_context
= real_context
->parent
)
1569 /* We should find something, eventually! */
1570 gcc_assert (real_context
);
1572 context_proc
= (real_context
->entries
? real_context
->entries
->sym
1573 : real_context
->proc_name
);
1575 /* In some special cases, there may not be a proc_name, like for this
1577 real(bad_kind()) function foo () ...
1578 when checking the call to bad_kind ().
1579 In these cases, we simply return here and assume that the
1584 if (context_proc
->attr
.flavor
!= FL_LABEL
)
1588 /* A call from sym's body to itself is recursion, of course. */
1589 if (context_proc
== proc_sym
)
1592 /* The same is true if context is a contained procedure and sym the
1594 if (context_proc
->attr
.contained
)
1596 gfc_symbol
* parent_proc
;
1598 gcc_assert (context
->parent
);
1599 parent_proc
= (context
->parent
->entries
? context
->parent
->entries
->sym
1600 : context
->parent
->proc_name
);
1602 if (parent_proc
== proc_sym
)
1610 /* Resolve an intrinsic procedure: Set its function/subroutine attribute,
1611 its typespec and formal argument list. */
1614 gfc_resolve_intrinsic (gfc_symbol
*sym
, locus
*loc
)
1616 gfc_intrinsic_sym
* isym
= NULL
;
1622 /* Already resolved. */
1623 if (sym
->from_intmod
&& sym
->ts
.type
!= BT_UNKNOWN
)
1626 /* We already know this one is an intrinsic, so we don't call
1627 gfc_is_intrinsic for full checking but rather use gfc_find_function and
1628 gfc_find_subroutine directly to check whether it is a function or
1631 if (sym
->intmod_sym_id
&& sym
->attr
.subroutine
)
1633 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1634 isym
= gfc_intrinsic_subroutine_by_id (id
);
1636 else if (sym
->intmod_sym_id
)
1638 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1639 isym
= gfc_intrinsic_function_by_id (id
);
1641 else if (!sym
->attr
.subroutine
)
1642 isym
= gfc_find_function (sym
->name
);
1644 if (isym
&& !sym
->attr
.subroutine
)
1646 if (sym
->ts
.type
!= BT_UNKNOWN
&& gfc_option
.warn_surprising
1647 && !sym
->attr
.implicit_type
)
1648 gfc_warning ("Type specified for intrinsic function '%s' at %L is"
1649 " ignored", sym
->name
, &sym
->declared_at
);
1651 if (!sym
->attr
.function
&&
1652 !gfc_add_function(&sym
->attr
, sym
->name
, loc
))
1657 else if (isym
|| (isym
= gfc_find_subroutine (sym
->name
)))
1659 if (sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.implicit_type
)
1661 gfc_error ("Intrinsic subroutine '%s' at %L shall not have a type"
1662 " specifier", sym
->name
, &sym
->declared_at
);
1666 if (!sym
->attr
.subroutine
&&
1667 !gfc_add_subroutine(&sym
->attr
, sym
->name
, loc
))
1672 gfc_error ("'%s' declared INTRINSIC at %L does not exist", sym
->name
,
1677 gfc_copy_formal_args_intr (sym
, isym
);
1679 sym
->attr
.pure
= isym
->pure
;
1680 sym
->attr
.elemental
= isym
->elemental
;
1682 /* Check it is actually available in the standard settings. */
1683 if (!gfc_check_intrinsic_standard (isym
, &symstd
, false, sym
->declared_at
))
1685 gfc_error ("The intrinsic '%s' declared INTRINSIC at %L is not"
1686 " available in the current standard settings but %s. Use"
1687 " an appropriate -std=* option or enable -fall-intrinsics"
1688 " in order to use it.",
1689 sym
->name
, &sym
->declared_at
, symstd
);
1697 /* Resolve a procedure expression, like passing it to a called procedure or as
1698 RHS for a procedure pointer assignment. */
1701 resolve_procedure_expression (gfc_expr
* expr
)
1705 if (expr
->expr_type
!= EXPR_VARIABLE
)
1707 gcc_assert (expr
->symtree
);
1709 sym
= expr
->symtree
->n
.sym
;
1711 if (sym
->attr
.intrinsic
)
1712 gfc_resolve_intrinsic (sym
, &expr
->where
);
1714 if (sym
->attr
.flavor
!= FL_PROCEDURE
1715 || (sym
->attr
.function
&& sym
->result
== sym
))
1718 /* A non-RECURSIVE procedure that is used as procedure expression within its
1719 own body is in danger of being called recursively. */
1720 if (is_illegal_recursion (sym
, gfc_current_ns
))
1721 gfc_warning ("Non-RECURSIVE procedure '%s' at %L is possibly calling"
1722 " itself recursively. Declare it RECURSIVE or use"
1723 " -frecursive", sym
->name
, &expr
->where
);
1729 /* Resolve an actual argument list. Most of the time, this is just
1730 resolving the expressions in the list.
1731 The exception is that we sometimes have to decide whether arguments
1732 that look like procedure arguments are really simple variable
1736 resolve_actual_arglist (gfc_actual_arglist
*arg
, procedure_type ptype
,
1737 bool no_formal_args
)
1740 gfc_symtree
*parent_st
;
1742 int save_need_full_assumed_size
;
1743 bool return_value
= false;
1744 bool actual_arg_sav
= actual_arg
, first_actual_arg_sav
= first_actual_arg
;
1747 first_actual_arg
= true;
1749 for (; arg
; arg
= arg
->next
)
1754 /* Check the label is a valid branching target. */
1757 if (arg
->label
->defined
== ST_LABEL_UNKNOWN
)
1759 gfc_error ("Label %d referenced at %L is never defined",
1760 arg
->label
->value
, &arg
->label
->where
);
1764 first_actual_arg
= false;
1768 if (e
->expr_type
== EXPR_VARIABLE
1769 && e
->symtree
->n
.sym
->attr
.generic
1771 && count_specific_procs (e
) != 1)
1774 if (e
->ts
.type
!= BT_PROCEDURE
)
1776 save_need_full_assumed_size
= need_full_assumed_size
;
1777 if (e
->expr_type
!= EXPR_VARIABLE
)
1778 need_full_assumed_size
= 0;
1779 if (!gfc_resolve_expr (e
))
1781 need_full_assumed_size
= save_need_full_assumed_size
;
1785 /* See if the expression node should really be a variable reference. */
1787 sym
= e
->symtree
->n
.sym
;
1789 if (sym
->attr
.flavor
== FL_PROCEDURE
1790 || sym
->attr
.intrinsic
1791 || sym
->attr
.external
)
1795 /* If a procedure is not already determined to be something else
1796 check if it is intrinsic. */
1797 if (gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, e
->where
))
1798 sym
->attr
.intrinsic
= 1;
1800 if (sym
->attr
.proc
== PROC_ST_FUNCTION
)
1802 gfc_error ("Statement function '%s' at %L is not allowed as an "
1803 "actual argument", sym
->name
, &e
->where
);
1806 actual_ok
= gfc_intrinsic_actual_ok (sym
->name
,
1807 sym
->attr
.subroutine
);
1808 if (sym
->attr
.intrinsic
&& actual_ok
== 0)
1810 gfc_error ("Intrinsic '%s' at %L is not allowed as an "
1811 "actual argument", sym
->name
, &e
->where
);
1814 if (sym
->attr
.contained
&& !sym
->attr
.use_assoc
1815 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
1817 if (!gfc_notify_std (GFC_STD_F2008
, "Internal procedure '%s' is"
1818 " used as actual argument at %L",
1819 sym
->name
, &e
->where
))
1823 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
)
1825 gfc_error ("ELEMENTAL non-INTRINSIC procedure '%s' is not "
1826 "allowed as an actual argument at %L", sym
->name
,
1830 /* Check if a generic interface has a specific procedure
1831 with the same name before emitting an error. */
1832 if (sym
->attr
.generic
&& count_specific_procs (e
) != 1)
1835 /* Just in case a specific was found for the expression. */
1836 sym
= e
->symtree
->n
.sym
;
1838 /* If the symbol is the function that names the current (or
1839 parent) scope, then we really have a variable reference. */
1841 if (gfc_is_function_return_value (sym
, sym
->ns
))
1844 /* If all else fails, see if we have a specific intrinsic. */
1845 if (sym
->ts
.type
== BT_UNKNOWN
&& sym
->attr
.intrinsic
)
1847 gfc_intrinsic_sym
*isym
;
1849 isym
= gfc_find_function (sym
->name
);
1850 if (isym
== NULL
|| !isym
->specific
)
1852 gfc_error ("Unable to find a specific INTRINSIC procedure "
1853 "for the reference '%s' at %L", sym
->name
,
1858 sym
->attr
.intrinsic
= 1;
1859 sym
->attr
.function
= 1;
1862 if (!gfc_resolve_expr (e
))
1867 /* See if the name is a module procedure in a parent unit. */
1869 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1872 if (gfc_find_sym_tree (sym
->name
, sym
->ns
->parent
, 1, &parent_st
))
1874 gfc_error ("Symbol '%s' at %L is ambiguous", sym
->name
, &e
->where
);
1878 if (parent_st
== NULL
)
1881 sym
= parent_st
->n
.sym
;
1882 e
->symtree
= parent_st
; /* Point to the right thing. */
1884 if (sym
->attr
.flavor
== FL_PROCEDURE
1885 || sym
->attr
.intrinsic
1886 || sym
->attr
.external
)
1888 if (!gfc_resolve_expr (e
))
1894 e
->expr_type
= EXPR_VARIABLE
;
1896 if ((sym
->as
!= NULL
&& sym
->ts
.type
!= BT_CLASS
)
1897 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
1898 && CLASS_DATA (sym
)->as
))
1900 e
->rank
= sym
->ts
.type
== BT_CLASS
1901 ? CLASS_DATA (sym
)->as
->rank
: sym
->as
->rank
;
1902 e
->ref
= gfc_get_ref ();
1903 e
->ref
->type
= REF_ARRAY
;
1904 e
->ref
->u
.ar
.type
= AR_FULL
;
1905 e
->ref
->u
.ar
.as
= sym
->ts
.type
== BT_CLASS
1906 ? CLASS_DATA (sym
)->as
: sym
->as
;
1909 /* Expressions are assigned a default ts.type of BT_PROCEDURE in
1910 primary.c (match_actual_arg). If above code determines that it
1911 is a variable instead, it needs to be resolved as it was not
1912 done at the beginning of this function. */
1913 save_need_full_assumed_size
= need_full_assumed_size
;
1914 if (e
->expr_type
!= EXPR_VARIABLE
)
1915 need_full_assumed_size
= 0;
1916 if (!gfc_resolve_expr (e
))
1918 need_full_assumed_size
= save_need_full_assumed_size
;
1921 /* Check argument list functions %VAL, %LOC and %REF. There is
1922 nothing to do for %REF. */
1923 if (arg
->name
&& arg
->name
[0] == '%')
1925 if (strncmp ("%VAL", arg
->name
, 4) == 0)
1927 if (e
->ts
.type
== BT_CHARACTER
|| e
->ts
.type
== BT_DERIVED
)
1929 gfc_error ("By-value argument at %L is not of numeric "
1936 gfc_error ("By-value argument at %L cannot be an array or "
1937 "an array section", &e
->where
);
1941 /* Intrinsics are still PROC_UNKNOWN here. However,
1942 since same file external procedures are not resolvable
1943 in gfortran, it is a good deal easier to leave them to
1945 if (ptype
!= PROC_UNKNOWN
1946 && ptype
!= PROC_DUMMY
1947 && ptype
!= PROC_EXTERNAL
1948 && ptype
!= PROC_MODULE
)
1950 gfc_error ("By-value argument at %L is not allowed "
1951 "in this context", &e
->where
);
1956 /* Statement functions have already been excluded above. */
1957 else if (strncmp ("%LOC", arg
->name
, 4) == 0
1958 && e
->ts
.type
== BT_PROCEDURE
)
1960 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_INTERNAL
)
1962 gfc_error ("Passing internal procedure at %L by location "
1963 "not allowed", &e
->where
);
1969 /* Fortran 2008, C1237. */
1970 if (e
->expr_type
== EXPR_VARIABLE
&& gfc_is_coindexed (e
)
1971 && gfc_has_ultimate_pointer (e
))
1973 gfc_error ("Coindexed actual argument at %L with ultimate pointer "
1974 "component", &e
->where
);
1978 first_actual_arg
= false;
1981 return_value
= true;
1984 actual_arg
= actual_arg_sav
;
1985 first_actual_arg
= first_actual_arg_sav
;
1987 return return_value
;
1991 /* Do the checks of the actual argument list that are specific to elemental
1992 procedures. If called with c == NULL, we have a function, otherwise if
1993 expr == NULL, we have a subroutine. */
1996 resolve_elemental_actual (gfc_expr
*expr
, gfc_code
*c
)
1998 gfc_actual_arglist
*arg0
;
1999 gfc_actual_arglist
*arg
;
2000 gfc_symbol
*esym
= NULL
;
2001 gfc_intrinsic_sym
*isym
= NULL
;
2003 gfc_intrinsic_arg
*iformal
= NULL
;
2004 gfc_formal_arglist
*eformal
= NULL
;
2005 bool formal_optional
= false;
2006 bool set_by_optional
= false;
2010 /* Is this an elemental procedure? */
2011 if (expr
&& expr
->value
.function
.actual
!= NULL
)
2013 if (expr
->value
.function
.esym
!= NULL
2014 && expr
->value
.function
.esym
->attr
.elemental
)
2016 arg0
= expr
->value
.function
.actual
;
2017 esym
= expr
->value
.function
.esym
;
2019 else if (expr
->value
.function
.isym
!= NULL
2020 && expr
->value
.function
.isym
->elemental
)
2022 arg0
= expr
->value
.function
.actual
;
2023 isym
= expr
->value
.function
.isym
;
2028 else if (c
&& c
->ext
.actual
!= NULL
)
2030 arg0
= c
->ext
.actual
;
2032 if (c
->resolved_sym
)
2033 esym
= c
->resolved_sym
;
2035 esym
= c
->symtree
->n
.sym
;
2038 if (!esym
->attr
.elemental
)
2044 /* The rank of an elemental is the rank of its array argument(s). */
2045 for (arg
= arg0
; arg
; arg
= arg
->next
)
2047 if (arg
->expr
!= NULL
&& arg
->expr
->rank
!= 0)
2049 rank
= arg
->expr
->rank
;
2050 if (arg
->expr
->expr_type
== EXPR_VARIABLE
2051 && arg
->expr
->symtree
->n
.sym
->attr
.optional
)
2052 set_by_optional
= true;
2054 /* Function specific; set the result rank and shape. */
2058 if (!expr
->shape
&& arg
->expr
->shape
)
2060 expr
->shape
= gfc_get_shape (rank
);
2061 for (i
= 0; i
< rank
; i
++)
2062 mpz_init_set (expr
->shape
[i
], arg
->expr
->shape
[i
]);
2069 /* If it is an array, it shall not be supplied as an actual argument
2070 to an elemental procedure unless an array of the same rank is supplied
2071 as an actual argument corresponding to a nonoptional dummy argument of
2072 that elemental procedure(12.4.1.5). */
2073 formal_optional
= false;
2075 iformal
= isym
->formal
;
2077 eformal
= esym
->formal
;
2079 for (arg
= arg0
; arg
; arg
= arg
->next
)
2083 if (eformal
->sym
&& eformal
->sym
->attr
.optional
)
2084 formal_optional
= true;
2085 eformal
= eformal
->next
;
2087 else if (isym
&& iformal
)
2089 if (iformal
->optional
)
2090 formal_optional
= true;
2091 iformal
= iformal
->next
;
2094 formal_optional
= true;
2096 if (pedantic
&& arg
->expr
!= NULL
2097 && arg
->expr
->expr_type
== EXPR_VARIABLE
2098 && arg
->expr
->symtree
->n
.sym
->attr
.optional
2101 && (set_by_optional
|| arg
->expr
->rank
!= rank
)
2102 && !(isym
&& isym
->id
== GFC_ISYM_CONVERSION
))
2104 gfc_warning ("'%s' at %L is an array and OPTIONAL; IF IT IS "
2105 "MISSING, it cannot be the actual argument of an "
2106 "ELEMENTAL procedure unless there is a non-optional "
2107 "argument with the same rank (12.4.1.5)",
2108 arg
->expr
->symtree
->n
.sym
->name
, &arg
->expr
->where
);
2112 for (arg
= arg0
; arg
; arg
= arg
->next
)
2114 if (arg
->expr
== NULL
|| arg
->expr
->rank
== 0)
2117 /* Being elemental, the last upper bound of an assumed size array
2118 argument must be present. */
2119 if (resolve_assumed_size_actual (arg
->expr
))
2122 /* Elemental procedure's array actual arguments must conform. */
2125 if (!gfc_check_conformance (arg
->expr
, e
, "elemental procedure"))
2132 /* INTENT(OUT) is only allowed for subroutines; if any actual argument
2133 is an array, the intent inout/out variable needs to be also an array. */
2134 if (rank
> 0 && esym
&& expr
== NULL
)
2135 for (eformal
= esym
->formal
, arg
= arg0
; arg
&& eformal
;
2136 arg
= arg
->next
, eformal
= eformal
->next
)
2137 if ((eformal
->sym
->attr
.intent
== INTENT_OUT
2138 || eformal
->sym
->attr
.intent
== INTENT_INOUT
)
2139 && arg
->expr
&& arg
->expr
->rank
== 0)
2141 gfc_error ("Actual argument at %L for INTENT(%s) dummy '%s' of "
2142 "ELEMENTAL subroutine '%s' is a scalar, but another "
2143 "actual argument is an array", &arg
->expr
->where
,
2144 (eformal
->sym
->attr
.intent
== INTENT_OUT
) ? "OUT"
2145 : "INOUT", eformal
->sym
->name
, esym
->name
);
2152 /* This function does the checking of references to global procedures
2153 as defined in sections 18.1 and 14.1, respectively, of the Fortran
2154 77 and 95 standards. It checks for a gsymbol for the name, making
2155 one if it does not already exist. If it already exists, then the
2156 reference being resolved must correspond to the type of gsymbol.
2157 Otherwise, the new symbol is equipped with the attributes of the
2158 reference. The corresponding code that is called in creating
2159 global entities is parse.c.
2161 In addition, for all but -std=legacy, the gsymbols are used to
2162 check the interfaces of external procedures from the same file.
2163 The namespace of the gsymbol is resolved and then, once this is
2164 done the interface is checked. */
2168 not_in_recursive (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2170 if (!gsym_ns
->proc_name
->attr
.recursive
)
2173 if (sym
->ns
== gsym_ns
)
2176 if (sym
->ns
->parent
&& sym
->ns
->parent
== gsym_ns
)
2183 not_entry_self_reference (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2185 if (gsym_ns
->entries
)
2187 gfc_entry_list
*entry
= gsym_ns
->entries
;
2189 for (; entry
; entry
= entry
->next
)
2191 if (strcmp (sym
->name
, entry
->sym
->name
) == 0)
2193 if (strcmp (gsym_ns
->proc_name
->name
,
2194 sym
->ns
->proc_name
->name
) == 0)
2198 && strcmp (gsym_ns
->proc_name
->name
,
2199 sym
->ns
->parent
->proc_name
->name
) == 0)
2208 /* Check for the requirement of an explicit interface. F08:12.4.2.2. */
2211 gfc_explicit_interface_required (gfc_symbol
*sym
, char *errmsg
, int err_len
)
2213 gfc_formal_arglist
*arg
= gfc_sym_get_dummy_args (sym
);
2215 for ( ; arg
; arg
= arg
->next
)
2220 if (arg
->sym
->attr
.allocatable
) /* (2a) */
2222 strncpy (errmsg
, _("allocatable argument"), err_len
);
2225 else if (arg
->sym
->attr
.asynchronous
)
2227 strncpy (errmsg
, _("asynchronous argument"), err_len
);
2230 else if (arg
->sym
->attr
.optional
)
2232 strncpy (errmsg
, _("optional argument"), err_len
);
2235 else if (arg
->sym
->attr
.pointer
)
2237 strncpy (errmsg
, _("pointer argument"), err_len
);
2240 else if (arg
->sym
->attr
.target
)
2242 strncpy (errmsg
, _("target argument"), err_len
);
2245 else if (arg
->sym
->attr
.value
)
2247 strncpy (errmsg
, _("value argument"), err_len
);
2250 else if (arg
->sym
->attr
.volatile_
)
2252 strncpy (errmsg
, _("volatile argument"), err_len
);
2255 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_SHAPE
) /* (2b) */
2257 strncpy (errmsg
, _("assumed-shape argument"), err_len
);
2260 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_RANK
) /* TS 29113, 6.2. */
2262 strncpy (errmsg
, _("assumed-rank argument"), err_len
);
2265 else if (arg
->sym
->attr
.codimension
) /* (2c) */
2267 strncpy (errmsg
, _("coarray argument"), err_len
);
2270 else if (false) /* (2d) TODO: parametrized derived type */
2272 strncpy (errmsg
, _("parametrized derived type argument"), err_len
);
2275 else if (arg
->sym
->ts
.type
== BT_CLASS
) /* (2e) */
2277 strncpy (errmsg
, _("polymorphic argument"), err_len
);
2280 else if (arg
->sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
2282 strncpy (errmsg
, _("NO_ARG_CHECK attribute"), err_len
);
2285 else if (arg
->sym
->ts
.type
== BT_ASSUMED
)
2287 /* As assumed-type is unlimited polymorphic (cf. above).
2288 See also TS 29113, Note 6.1. */
2289 strncpy (errmsg
, _("assumed-type argument"), err_len
);
2294 if (sym
->attr
.function
)
2296 gfc_symbol
*res
= sym
->result
? sym
->result
: sym
;
2298 if (res
->attr
.dimension
) /* (3a) */
2300 strncpy (errmsg
, _("array result"), err_len
);
2303 else if (res
->attr
.pointer
|| res
->attr
.allocatable
) /* (3b) */
2305 strncpy (errmsg
, _("pointer or allocatable result"), err_len
);
2308 else if (res
->ts
.type
== BT_CHARACTER
&& res
->ts
.u
.cl
2309 && res
->ts
.u
.cl
->length
2310 && res
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
) /* (3c) */
2312 strncpy (errmsg
, _("result with non-constant character length"), err_len
);
2317 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
) /* (4) */
2319 strncpy (errmsg
, _("elemental procedure"), err_len
);
2322 else if (sym
->attr
.is_bind_c
) /* (5) */
2324 strncpy (errmsg
, _("bind(c) procedure"), err_len
);
2333 resolve_global_procedure (gfc_symbol
*sym
, locus
*where
,
2334 gfc_actual_arglist
**actual
, int sub
)
2338 enum gfc_symbol_type type
;
2341 type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
2343 gsym
= gfc_get_gsymbol (sym
->binding_label
? sym
->binding_label
: sym
->name
);
2345 if ((gsym
->type
!= GSYM_UNKNOWN
&& gsym
->type
!= type
))
2346 gfc_global_used (gsym
, where
);
2348 if ((sym
->attr
.if_source
== IFSRC_UNKNOWN
2349 || sym
->attr
.if_source
== IFSRC_IFBODY
)
2350 && gsym
->type
!= GSYM_UNKNOWN
2351 && !gsym
->binding_label
2353 && gsym
->ns
->resolved
!= -1
2354 && gsym
->ns
->proc_name
2355 && not_in_recursive (sym
, gsym
->ns
)
2356 && not_entry_self_reference (sym
, gsym
->ns
))
2358 gfc_symbol
*def_sym
;
2360 /* Resolve the gsymbol namespace if needed. */
2361 if (!gsym
->ns
->resolved
)
2363 gfc_dt_list
*old_dt_list
;
2364 struct gfc_omp_saved_state old_omp_state
;
2366 /* Stash away derived types so that the backend_decls do not
2368 old_dt_list
= gfc_derived_types
;
2369 gfc_derived_types
= NULL
;
2370 /* And stash away openmp state. */
2371 gfc_omp_save_and_clear_state (&old_omp_state
);
2373 gfc_resolve (gsym
->ns
);
2375 /* Store the new derived types with the global namespace. */
2376 if (gfc_derived_types
)
2377 gsym
->ns
->derived_types
= gfc_derived_types
;
2379 /* Restore the derived types of this namespace. */
2380 gfc_derived_types
= old_dt_list
;
2381 /* And openmp state. */
2382 gfc_omp_restore_state (&old_omp_state
);
2385 /* Make sure that translation for the gsymbol occurs before
2386 the procedure currently being resolved. */
2387 ns
= gfc_global_ns_list
;
2388 for (; ns
&& ns
!= gsym
->ns
; ns
= ns
->sibling
)
2390 if (ns
->sibling
== gsym
->ns
)
2392 ns
->sibling
= gsym
->ns
->sibling
;
2393 gsym
->ns
->sibling
= gfc_global_ns_list
;
2394 gfc_global_ns_list
= gsym
->ns
;
2399 def_sym
= gsym
->ns
->proc_name
;
2401 /* This can happen if a binding name has been specified. */
2402 if (gsym
->binding_label
&& gsym
->sym_name
!= def_sym
->name
)
2403 gfc_find_symbol (gsym
->sym_name
, gsym
->ns
, 0, &def_sym
);
2405 if (def_sym
->attr
.entry_master
)
2407 gfc_entry_list
*entry
;
2408 for (entry
= gsym
->ns
->entries
; entry
; entry
= entry
->next
)
2409 if (strcmp (entry
->sym
->name
, sym
->name
) == 0)
2411 def_sym
= entry
->sym
;
2416 if (sym
->attr
.function
&& !gfc_compare_types (&sym
->ts
, &def_sym
->ts
))
2418 gfc_error ("Return type mismatch of function '%s' at %L (%s/%s)",
2419 sym
->name
, &sym
->declared_at
, gfc_typename (&sym
->ts
),
2420 gfc_typename (&def_sym
->ts
));
2424 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
2425 && gfc_explicit_interface_required (def_sym
, reason
, sizeof(reason
)))
2427 gfc_error ("Explicit interface required for '%s' at %L: %s",
2428 sym
->name
, &sym
->declared_at
, reason
);
2432 if (!pedantic
&& (gfc_option
.allow_std
& GFC_STD_GNU
))
2433 /* Turn erros into warnings with -std=gnu and -std=legacy. */
2434 gfc_errors_to_warnings (1);
2436 if (!gfc_compare_interfaces (sym
, def_sym
, sym
->name
, 0, 1,
2437 reason
, sizeof(reason
), NULL
, NULL
))
2439 gfc_error ("Interface mismatch in global procedure '%s' at %L: %s ",
2440 sym
->name
, &sym
->declared_at
, reason
);
2445 || ((gfc_option
.warn_std
& GFC_STD_LEGACY
)
2446 && !(gfc_option
.warn_std
& GFC_STD_GNU
)))
2447 gfc_errors_to_warnings (1);
2449 if (sym
->attr
.if_source
!= IFSRC_IFBODY
)
2450 gfc_procedure_use (def_sym
, actual
, where
);
2454 gfc_errors_to_warnings (0);
2456 if (gsym
->type
== GSYM_UNKNOWN
)
2459 gsym
->where
= *where
;
2466 /************* Function resolution *************/
2468 /* Resolve a function call known to be generic.
2469 Section 14.1.2.4.1. */
2472 resolve_generic_f0 (gfc_expr
*expr
, gfc_symbol
*sym
)
2476 if (sym
->attr
.generic
)
2478 s
= gfc_search_interface (sym
->generic
, 0, &expr
->value
.function
.actual
);
2481 expr
->value
.function
.name
= s
->name
;
2482 expr
->value
.function
.esym
= s
;
2484 if (s
->ts
.type
!= BT_UNKNOWN
)
2486 else if (s
->result
!= NULL
&& s
->result
->ts
.type
!= BT_UNKNOWN
)
2487 expr
->ts
= s
->result
->ts
;
2490 expr
->rank
= s
->as
->rank
;
2491 else if (s
->result
!= NULL
&& s
->result
->as
!= NULL
)
2492 expr
->rank
= s
->result
->as
->rank
;
2494 gfc_set_sym_referenced (expr
->value
.function
.esym
);
2499 /* TODO: Need to search for elemental references in generic
2503 if (sym
->attr
.intrinsic
)
2504 return gfc_intrinsic_func_interface (expr
, 0);
2511 resolve_generic_f (gfc_expr
*expr
)
2515 gfc_interface
*intr
= NULL
;
2517 sym
= expr
->symtree
->n
.sym
;
2521 m
= resolve_generic_f0 (expr
, sym
);
2524 else if (m
== MATCH_ERROR
)
2529 for (intr
= sym
->generic
; intr
; intr
= intr
->next
)
2530 if (intr
->sym
->attr
.flavor
== FL_DERIVED
)
2533 if (sym
->ns
->parent
== NULL
)
2535 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2539 if (!generic_sym (sym
))
2543 /* Last ditch attempt. See if the reference is to an intrinsic
2544 that possesses a matching interface. 14.1.2.4 */
2545 if (sym
&& !intr
&& !gfc_is_intrinsic (sym
, 0, expr
->where
))
2547 gfc_error ("There is no specific function for the generic '%s' "
2548 "at %L", expr
->symtree
->n
.sym
->name
, &expr
->where
);
2554 if (!gfc_convert_to_structure_constructor (expr
, intr
->sym
, NULL
,
2557 return resolve_structure_cons (expr
, 0);
2560 m
= gfc_intrinsic_func_interface (expr
, 0);
2565 gfc_error ("Generic function '%s' at %L is not consistent with a "
2566 "specific intrinsic interface", expr
->symtree
->n
.sym
->name
,
2573 /* Resolve a function call known to be specific. */
2576 resolve_specific_f0 (gfc_symbol
*sym
, gfc_expr
*expr
)
2580 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
2582 if (sym
->attr
.dummy
)
2584 sym
->attr
.proc
= PROC_DUMMY
;
2588 sym
->attr
.proc
= PROC_EXTERNAL
;
2592 if (sym
->attr
.proc
== PROC_MODULE
2593 || sym
->attr
.proc
== PROC_ST_FUNCTION
2594 || sym
->attr
.proc
== PROC_INTERNAL
)
2597 if (sym
->attr
.intrinsic
)
2599 m
= gfc_intrinsic_func_interface (expr
, 1);
2603 gfc_error ("Function '%s' at %L is INTRINSIC but is not compatible "
2604 "with an intrinsic", sym
->name
, &expr
->where
);
2612 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2615 expr
->ts
= sym
->result
->ts
;
2618 expr
->value
.function
.name
= sym
->name
;
2619 expr
->value
.function
.esym
= sym
;
2620 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->as
)
2621 expr
->rank
= CLASS_DATA (sym
)->as
->rank
;
2622 else if (sym
->as
!= NULL
)
2623 expr
->rank
= sym
->as
->rank
;
2630 resolve_specific_f (gfc_expr
*expr
)
2635 sym
= expr
->symtree
->n
.sym
;
2639 m
= resolve_specific_f0 (sym
, expr
);
2642 if (m
== MATCH_ERROR
)
2645 if (sym
->ns
->parent
== NULL
)
2648 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2654 gfc_error ("Unable to resolve the specific function '%s' at %L",
2655 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2661 /* Resolve a procedure call not known to be generic nor specific. */
2664 resolve_unknown_f (gfc_expr
*expr
)
2669 sym
= expr
->symtree
->n
.sym
;
2671 if (sym
->attr
.dummy
)
2673 sym
->attr
.proc
= PROC_DUMMY
;
2674 expr
->value
.function
.name
= sym
->name
;
2678 /* See if we have an intrinsic function reference. */
2680 if (gfc_is_intrinsic (sym
, 0, expr
->where
))
2682 if (gfc_intrinsic_func_interface (expr
, 1) == MATCH_YES
)
2687 /* The reference is to an external name. */
2689 sym
->attr
.proc
= PROC_EXTERNAL
;
2690 expr
->value
.function
.name
= sym
->name
;
2691 expr
->value
.function
.esym
= expr
->symtree
->n
.sym
;
2693 if (sym
->as
!= NULL
)
2694 expr
->rank
= sym
->as
->rank
;
2696 /* Type of the expression is either the type of the symbol or the
2697 default type of the symbol. */
2700 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2702 if (sym
->ts
.type
!= BT_UNKNOWN
)
2706 ts
= gfc_get_default_type (sym
->name
, sym
->ns
);
2708 if (ts
->type
== BT_UNKNOWN
)
2710 gfc_error ("Function '%s' at %L has no IMPLICIT type",
2711 sym
->name
, &expr
->where
);
2722 /* Return true, if the symbol is an external procedure. */
2724 is_external_proc (gfc_symbol
*sym
)
2726 if (!sym
->attr
.dummy
&& !sym
->attr
.contained
2727 && !gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, sym
->declared_at
)
2728 && sym
->attr
.proc
!= PROC_ST_FUNCTION
2729 && !sym
->attr
.proc_pointer
2730 && !sym
->attr
.use_assoc
2738 /* Figure out if a function reference is pure or not. Also set the name
2739 of the function for a potential error message. Return nonzero if the
2740 function is PURE, zero if not. */
2742 pure_stmt_function (gfc_expr
*, gfc_symbol
*);
2745 pure_function (gfc_expr
*e
, const char **name
)
2751 if (e
->symtree
!= NULL
2752 && e
->symtree
->n
.sym
!= NULL
2753 && e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2754 return pure_stmt_function (e
, e
->symtree
->n
.sym
);
2756 if (e
->value
.function
.esym
)
2758 pure
= gfc_pure (e
->value
.function
.esym
);
2759 *name
= e
->value
.function
.esym
->name
;
2761 else if (e
->value
.function
.isym
)
2763 pure
= e
->value
.function
.isym
->pure
2764 || e
->value
.function
.isym
->elemental
;
2765 *name
= e
->value
.function
.isym
->name
;
2769 /* Implicit functions are not pure. */
2771 *name
= e
->value
.function
.name
;
2779 impure_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
,
2780 int *f ATTRIBUTE_UNUSED
)
2784 /* Don't bother recursing into other statement functions
2785 since they will be checked individually for purity. */
2786 if (e
->expr_type
!= EXPR_FUNCTION
2788 || e
->symtree
->n
.sym
== sym
2789 || e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
2792 return pure_function (e
, &name
) ? false : true;
2797 pure_stmt_function (gfc_expr
*e
, gfc_symbol
*sym
)
2799 return gfc_traverse_expr (e
, sym
, impure_stmt_fcn
, 0) ? 0 : 1;
2803 /* Resolve a function call, which means resolving the arguments, then figuring
2804 out which entity the name refers to. */
2807 resolve_function (gfc_expr
*expr
)
2809 gfc_actual_arglist
*arg
;
2814 procedure_type p
= PROC_INTRINSIC
;
2815 bool no_formal_args
;
2819 sym
= expr
->symtree
->n
.sym
;
2821 /* If this is a procedure pointer component, it has already been resolved. */
2822 if (gfc_is_proc_ptr_comp (expr
))
2825 if (sym
&& sym
->attr
.intrinsic
2826 && !gfc_resolve_intrinsic (sym
, &expr
->where
))
2829 if (sym
&& (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.subroutine
))
2831 gfc_error ("'%s' at %L is not a function", sym
->name
, &expr
->where
);
2835 /* If this ia a deferred TBP with an abstract interface (which may
2836 of course be referenced), expr->value.function.esym will be set. */
2837 if (sym
&& sym
->attr
.abstract
&& !expr
->value
.function
.esym
)
2839 gfc_error ("ABSTRACT INTERFACE '%s' must not be referenced at %L",
2840 sym
->name
, &expr
->where
);
2844 /* Switch off assumed size checking and do this again for certain kinds
2845 of procedure, once the procedure itself is resolved. */
2846 need_full_assumed_size
++;
2848 if (expr
->symtree
&& expr
->symtree
->n
.sym
)
2849 p
= expr
->symtree
->n
.sym
->attr
.proc
;
2851 if (expr
->value
.function
.isym
&& expr
->value
.function
.isym
->inquiry
)
2852 inquiry_argument
= true;
2853 no_formal_args
= sym
&& is_external_proc (sym
)
2854 && gfc_sym_get_dummy_args (sym
) == NULL
;
2856 if (!resolve_actual_arglist (expr
->value
.function
.actual
,
2859 inquiry_argument
= false;
2863 inquiry_argument
= false;
2865 /* Resume assumed_size checking. */
2866 need_full_assumed_size
--;
2868 /* If the procedure is external, check for usage. */
2869 if (sym
&& is_external_proc (sym
))
2870 resolve_global_procedure (sym
, &expr
->where
,
2871 &expr
->value
.function
.actual
, 0);
2873 if (sym
&& sym
->ts
.type
== BT_CHARACTER
2875 && sym
->ts
.u
.cl
->length
== NULL
2877 && !sym
->ts
.deferred
2878 && expr
->value
.function
.esym
== NULL
2879 && !sym
->attr
.contained
)
2881 /* Internal procedures are taken care of in resolve_contained_fntype. */
2882 gfc_error ("Function '%s' is declared CHARACTER(*) and cannot "
2883 "be used at %L since it is not a dummy argument",
2884 sym
->name
, &expr
->where
);
2888 /* See if function is already resolved. */
2890 if (expr
->value
.function
.name
!= NULL
)
2892 if (expr
->ts
.type
== BT_UNKNOWN
)
2898 /* Apply the rules of section 14.1.2. */
2900 switch (procedure_kind (sym
))
2903 t
= resolve_generic_f (expr
);
2906 case PTYPE_SPECIFIC
:
2907 t
= resolve_specific_f (expr
);
2911 t
= resolve_unknown_f (expr
);
2915 gfc_internal_error ("resolve_function(): bad function type");
2919 /* If the expression is still a function (it might have simplified),
2920 then we check to see if we are calling an elemental function. */
2922 if (expr
->expr_type
!= EXPR_FUNCTION
)
2925 temp
= need_full_assumed_size
;
2926 need_full_assumed_size
= 0;
2928 if (!resolve_elemental_actual (expr
, NULL
))
2931 if (omp_workshare_flag
2932 && expr
->value
.function
.esym
2933 && ! gfc_elemental (expr
->value
.function
.esym
))
2935 gfc_error ("User defined non-ELEMENTAL function '%s' at %L not allowed "
2936 "in WORKSHARE construct", expr
->value
.function
.esym
->name
,
2941 #define GENERIC_ID expr->value.function.isym->id
2942 else if (expr
->value
.function
.actual
!= NULL
2943 && expr
->value
.function
.isym
!= NULL
2944 && GENERIC_ID
!= GFC_ISYM_LBOUND
2945 && GENERIC_ID
!= GFC_ISYM_LCOBOUND
2946 && GENERIC_ID
!= GFC_ISYM_UCOBOUND
2947 && GENERIC_ID
!= GFC_ISYM_LEN
2948 && GENERIC_ID
!= GFC_ISYM_LOC
2949 && GENERIC_ID
!= GFC_ISYM_C_LOC
2950 && GENERIC_ID
!= GFC_ISYM_PRESENT
)
2952 /* Array intrinsics must also have the last upper bound of an
2953 assumed size array argument. UBOUND and SIZE have to be
2954 excluded from the check if the second argument is anything
2957 for (arg
= expr
->value
.function
.actual
; arg
; arg
= arg
->next
)
2959 if ((GENERIC_ID
== GFC_ISYM_UBOUND
|| GENERIC_ID
== GFC_ISYM_SIZE
)
2960 && arg
== expr
->value
.function
.actual
2961 && arg
->next
!= NULL
&& arg
->next
->expr
)
2963 if (arg
->next
->expr
->expr_type
!= EXPR_CONSTANT
)
2966 if (arg
->next
->name
&& strncmp (arg
->next
->name
, "kind", 4) == 0)
2969 if ((int)mpz_get_si (arg
->next
->expr
->value
.integer
)
2974 if (arg
->expr
!= NULL
2975 && arg
->expr
->rank
> 0
2976 && resolve_assumed_size_actual (arg
->expr
))
2982 need_full_assumed_size
= temp
;
2985 if (!pure_function (expr
, &name
) && name
)
2989 gfc_error ("Reference to non-PURE function '%s' at %L inside a "
2990 "FORALL %s", name
, &expr
->where
,
2991 forall_flag
== 2 ? "mask" : "block");
2994 else if (gfc_do_concurrent_flag
)
2996 gfc_error ("Reference to non-PURE function '%s' at %L inside a "
2997 "DO CONCURRENT %s", name
, &expr
->where
,
2998 gfc_do_concurrent_flag
== 2 ? "mask" : "block");
3001 else if (gfc_pure (NULL
))
3003 gfc_error ("Function reference to '%s' at %L is to a non-PURE "
3004 "procedure within a PURE procedure", name
, &expr
->where
);
3008 gfc_unset_implicit_pure (NULL
);
3011 /* Functions without the RECURSIVE attribution are not allowed to
3012 * call themselves. */
3013 if (expr
->value
.function
.esym
&& !expr
->value
.function
.esym
->attr
.recursive
)
3016 esym
= expr
->value
.function
.esym
;
3018 if (is_illegal_recursion (esym
, gfc_current_ns
))
3020 if (esym
->attr
.entry
&& esym
->ns
->entries
)
3021 gfc_error ("ENTRY '%s' at %L cannot be called recursively, as"
3022 " function '%s' is not RECURSIVE",
3023 esym
->name
, &expr
->where
, esym
->ns
->entries
->sym
->name
);
3025 gfc_error ("Function '%s' at %L cannot be called recursively, as it"
3026 " is not RECURSIVE", esym
->name
, &expr
->where
);
3032 /* Character lengths of use associated functions may contains references to
3033 symbols not referenced from the current program unit otherwise. Make sure
3034 those symbols are marked as referenced. */
3036 if (expr
->ts
.type
== BT_CHARACTER
&& expr
->value
.function
.esym
3037 && expr
->value
.function
.esym
->attr
.use_assoc
)
3039 gfc_expr_set_symbols_referenced (expr
->ts
.u
.cl
->length
);
3042 /* Make sure that the expression has a typespec that works. */
3043 if (expr
->ts
.type
== BT_UNKNOWN
)
3045 if (expr
->symtree
->n
.sym
->result
3046 && expr
->symtree
->n
.sym
->result
->ts
.type
!= BT_UNKNOWN
3047 && !expr
->symtree
->n
.sym
->result
->attr
.proc_pointer
)
3048 expr
->ts
= expr
->symtree
->n
.sym
->result
->ts
;
3055 /************* Subroutine resolution *************/
3058 pure_subroutine (gfc_code
*c
, gfc_symbol
*sym
)
3064 gfc_error ("Subroutine call to '%s' in FORALL block at %L is not PURE",
3065 sym
->name
, &c
->loc
);
3066 else if (gfc_do_concurrent_flag
)
3067 gfc_error ("Subroutine call to '%s' in DO CONCURRENT block at %L is not "
3068 "PURE", sym
->name
, &c
->loc
);
3069 else if (gfc_pure (NULL
))
3070 gfc_error ("Subroutine call to '%s' at %L is not PURE", sym
->name
,
3073 gfc_unset_implicit_pure (NULL
);
3078 resolve_generic_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3082 if (sym
->attr
.generic
)
3084 s
= gfc_search_interface (sym
->generic
, 1, &c
->ext
.actual
);
3087 c
->resolved_sym
= s
;
3088 pure_subroutine (c
, s
);
3092 /* TODO: Need to search for elemental references in generic interface. */
3095 if (sym
->attr
.intrinsic
)
3096 return gfc_intrinsic_sub_interface (c
, 0);
3103 resolve_generic_s (gfc_code
*c
)
3108 sym
= c
->symtree
->n
.sym
;
3112 m
= resolve_generic_s0 (c
, sym
);
3115 else if (m
== MATCH_ERROR
)
3119 if (sym
->ns
->parent
== NULL
)
3121 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3125 if (!generic_sym (sym
))
3129 /* Last ditch attempt. See if the reference is to an intrinsic
3130 that possesses a matching interface. 14.1.2.4 */
3131 sym
= c
->symtree
->n
.sym
;
3133 if (!gfc_is_intrinsic (sym
, 1, c
->loc
))
3135 gfc_error ("There is no specific subroutine for the generic '%s' at %L",
3136 sym
->name
, &c
->loc
);
3140 m
= gfc_intrinsic_sub_interface (c
, 0);
3144 gfc_error ("Generic subroutine '%s' at %L is not consistent with an "
3145 "intrinsic subroutine interface", sym
->name
, &c
->loc
);
3151 /* Resolve a subroutine call known to be specific. */
3154 resolve_specific_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3158 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
3160 if (sym
->attr
.dummy
)
3162 sym
->attr
.proc
= PROC_DUMMY
;
3166 sym
->attr
.proc
= PROC_EXTERNAL
;
3170 if (sym
->attr
.proc
== PROC_MODULE
|| sym
->attr
.proc
== PROC_INTERNAL
)
3173 if (sym
->attr
.intrinsic
)
3175 m
= gfc_intrinsic_sub_interface (c
, 1);
3179 gfc_error ("Subroutine '%s' at %L is INTRINSIC but is not compatible "
3180 "with an intrinsic", sym
->name
, &c
->loc
);
3188 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3190 c
->resolved_sym
= sym
;
3191 pure_subroutine (c
, sym
);
3198 resolve_specific_s (gfc_code
*c
)
3203 sym
= c
->symtree
->n
.sym
;
3207 m
= resolve_specific_s0 (c
, sym
);
3210 if (m
== MATCH_ERROR
)
3213 if (sym
->ns
->parent
== NULL
)
3216 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3222 sym
= c
->symtree
->n
.sym
;
3223 gfc_error ("Unable to resolve the specific subroutine '%s' at %L",
3224 sym
->name
, &c
->loc
);
3230 /* Resolve a subroutine call not known to be generic nor specific. */
3233 resolve_unknown_s (gfc_code
*c
)
3237 sym
= c
->symtree
->n
.sym
;
3239 if (sym
->attr
.dummy
)
3241 sym
->attr
.proc
= PROC_DUMMY
;
3245 /* See if we have an intrinsic function reference. */
3247 if (gfc_is_intrinsic (sym
, 1, c
->loc
))
3249 if (gfc_intrinsic_sub_interface (c
, 1) == MATCH_YES
)
3254 /* The reference is to an external name. */
3257 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3259 c
->resolved_sym
= sym
;
3261 pure_subroutine (c
, sym
);
3267 /* Resolve a subroutine call. Although it was tempting to use the same code
3268 for functions, subroutines and functions are stored differently and this
3269 makes things awkward. */
3272 resolve_call (gfc_code
*c
)
3275 procedure_type ptype
= PROC_INTRINSIC
;
3276 gfc_symbol
*csym
, *sym
;
3277 bool no_formal_args
;
3279 csym
= c
->symtree
? c
->symtree
->n
.sym
: NULL
;
3281 if (csym
&& csym
->ts
.type
!= BT_UNKNOWN
)
3283 gfc_error ("'%s' at %L has a type, which is not consistent with "
3284 "the CALL at %L", csym
->name
, &csym
->declared_at
, &c
->loc
);
3288 if (csym
&& gfc_current_ns
->parent
&& csym
->ns
!= gfc_current_ns
)
3291 gfc_find_sym_tree (c
->symtree
->name
, gfc_current_ns
, 1, &st
);
3292 sym
= st
? st
->n
.sym
: NULL
;
3293 if (sym
&& csym
!= sym
3294 && sym
->ns
== gfc_current_ns
3295 && sym
->attr
.flavor
== FL_PROCEDURE
3296 && sym
->attr
.contained
)
3299 if (csym
->attr
.generic
)
3300 c
->symtree
->n
.sym
= sym
;
3303 csym
= c
->symtree
->n
.sym
;
3307 /* If this ia a deferred TBP, c->expr1 will be set. */
3308 if (!c
->expr1
&& csym
)
3310 if (csym
->attr
.abstract
)
3312 gfc_error ("ABSTRACT INTERFACE '%s' must not be referenced at %L",
3313 csym
->name
, &c
->loc
);
3317 /* Subroutines without the RECURSIVE attribution are not allowed to
3319 if (is_illegal_recursion (csym
, gfc_current_ns
))
3321 if (csym
->attr
.entry
&& csym
->ns
->entries
)
3322 gfc_error ("ENTRY '%s' at %L cannot be called recursively, "
3323 "as subroutine '%s' is not RECURSIVE",
3324 csym
->name
, &c
->loc
, csym
->ns
->entries
->sym
->name
);
3326 gfc_error ("SUBROUTINE '%s' at %L cannot be called recursively, "
3327 "as it is not RECURSIVE", csym
->name
, &c
->loc
);
3333 /* Switch off assumed size checking and do this again for certain kinds
3334 of procedure, once the procedure itself is resolved. */
3335 need_full_assumed_size
++;
3338 ptype
= csym
->attr
.proc
;
3340 no_formal_args
= csym
&& is_external_proc (csym
)
3341 && gfc_sym_get_dummy_args (csym
) == NULL
;
3342 if (!resolve_actual_arglist (c
->ext
.actual
, ptype
, no_formal_args
))
3345 /* Resume assumed_size checking. */
3346 need_full_assumed_size
--;
3348 /* If external, check for usage. */
3349 if (csym
&& is_external_proc (csym
))
3350 resolve_global_procedure (csym
, &c
->loc
, &c
->ext
.actual
, 1);
3353 if (c
->resolved_sym
== NULL
)
3355 c
->resolved_isym
= NULL
;
3356 switch (procedure_kind (csym
))
3359 t
= resolve_generic_s (c
);
3362 case PTYPE_SPECIFIC
:
3363 t
= resolve_specific_s (c
);
3367 t
= resolve_unknown_s (c
);
3371 gfc_internal_error ("resolve_subroutine(): bad function type");
3375 /* Some checks of elemental subroutine actual arguments. */
3376 if (!resolve_elemental_actual (NULL
, c
))
3383 /* Compare the shapes of two arrays that have non-NULL shapes. If both
3384 op1->shape and op2->shape are non-NULL return true if their shapes
3385 match. If both op1->shape and op2->shape are non-NULL return false
3386 if their shapes do not match. If either op1->shape or op2->shape is
3387 NULL, return true. */
3390 compare_shapes (gfc_expr
*op1
, gfc_expr
*op2
)
3397 if (op1
->shape
!= NULL
&& op2
->shape
!= NULL
)
3399 for (i
= 0; i
< op1
->rank
; i
++)
3401 if (mpz_cmp (op1
->shape
[i
], op2
->shape
[i
]) != 0)
3403 gfc_error ("Shapes for operands at %L and %L are not conformable",
3404 &op1
->where
, &op2
->where
);
3415 /* Resolve an operator expression node. This can involve replacing the
3416 operation with a user defined function call. */
3419 resolve_operator (gfc_expr
*e
)
3421 gfc_expr
*op1
, *op2
;
3423 bool dual_locus_error
;
3426 /* Resolve all subnodes-- give them types. */
3428 switch (e
->value
.op
.op
)
3431 if (!gfc_resolve_expr (e
->value
.op
.op2
))
3434 /* Fall through... */
3437 case INTRINSIC_UPLUS
:
3438 case INTRINSIC_UMINUS
:
3439 case INTRINSIC_PARENTHESES
:
3440 if (!gfc_resolve_expr (e
->value
.op
.op1
))
3445 /* Typecheck the new node. */
3447 op1
= e
->value
.op
.op1
;
3448 op2
= e
->value
.op
.op2
;
3449 dual_locus_error
= false;
3451 if ((op1
&& op1
->expr_type
== EXPR_NULL
)
3452 || (op2
&& op2
->expr_type
== EXPR_NULL
))
3454 sprintf (msg
, _("Invalid context for NULL() pointer at %%L"));
3458 switch (e
->value
.op
.op
)
3460 case INTRINSIC_UPLUS
:
3461 case INTRINSIC_UMINUS
:
3462 if (op1
->ts
.type
== BT_INTEGER
3463 || op1
->ts
.type
== BT_REAL
3464 || op1
->ts
.type
== BT_COMPLEX
)
3470 sprintf (msg
, _("Operand of unary numeric operator '%s' at %%L is %s"),
3471 gfc_op2string (e
->value
.op
.op
), gfc_typename (&e
->ts
));
3474 case INTRINSIC_PLUS
:
3475 case INTRINSIC_MINUS
:
3476 case INTRINSIC_TIMES
:
3477 case INTRINSIC_DIVIDE
:
3478 case INTRINSIC_POWER
:
3479 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3481 gfc_type_convert_binary (e
, 1);
3486 _("Operands of binary numeric operator '%s' at %%L are %s/%s"),
3487 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3488 gfc_typename (&op2
->ts
));
3491 case INTRINSIC_CONCAT
:
3492 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3493 && op1
->ts
.kind
== op2
->ts
.kind
)
3495 e
->ts
.type
= BT_CHARACTER
;
3496 e
->ts
.kind
= op1
->ts
.kind
;
3501 _("Operands of string concatenation operator at %%L are %s/%s"),
3502 gfc_typename (&op1
->ts
), gfc_typename (&op2
->ts
));
3508 case INTRINSIC_NEQV
:
3509 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3511 e
->ts
.type
= BT_LOGICAL
;
3512 e
->ts
.kind
= gfc_kind_max (op1
, op2
);
3513 if (op1
->ts
.kind
< e
->ts
.kind
)
3514 gfc_convert_type (op1
, &e
->ts
, 2);
3515 else if (op2
->ts
.kind
< e
->ts
.kind
)
3516 gfc_convert_type (op2
, &e
->ts
, 2);
3520 sprintf (msg
, _("Operands of logical operator '%s' at %%L are %s/%s"),
3521 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3522 gfc_typename (&op2
->ts
));
3527 if (op1
->ts
.type
== BT_LOGICAL
)
3529 e
->ts
.type
= BT_LOGICAL
;
3530 e
->ts
.kind
= op1
->ts
.kind
;
3534 sprintf (msg
, _("Operand of .not. operator at %%L is %s"),
3535 gfc_typename (&op1
->ts
));
3539 case INTRINSIC_GT_OS
:
3541 case INTRINSIC_GE_OS
:
3543 case INTRINSIC_LT_OS
:
3545 case INTRINSIC_LE_OS
:
3546 if (op1
->ts
.type
== BT_COMPLEX
|| op2
->ts
.type
== BT_COMPLEX
)
3548 strcpy (msg
, _("COMPLEX quantities cannot be compared at %L"));
3552 /* Fall through... */
3555 case INTRINSIC_EQ_OS
:
3557 case INTRINSIC_NE_OS
:
3558 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3559 && op1
->ts
.kind
== op2
->ts
.kind
)
3561 e
->ts
.type
= BT_LOGICAL
;
3562 e
->ts
.kind
= gfc_default_logical_kind
;
3566 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3568 gfc_type_convert_binary (e
, 1);
3570 e
->ts
.type
= BT_LOGICAL
;
3571 e
->ts
.kind
= gfc_default_logical_kind
;
3573 if (gfc_option
.warn_compare_reals
)
3575 gfc_intrinsic_op op
= e
->value
.op
.op
;
3577 /* Type conversion has made sure that the types of op1 and op2
3578 agree, so it is only necessary to check the first one. */
3579 if ((op1
->ts
.type
== BT_REAL
|| op1
->ts
.type
== BT_COMPLEX
)
3580 && (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
3581 || op
== INTRINSIC_NE
|| op
== INTRINSIC_NE_OS
))
3585 if (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
)
3586 msg
= "Equality comparison for %s at %L";
3588 msg
= "Inequality comparison for %s at %L";
3590 gfc_warning (msg
, gfc_typename (&op1
->ts
), &op1
->where
);
3597 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3599 _("Logicals at %%L must be compared with %s instead of %s"),
3600 (e
->value
.op
.op
== INTRINSIC_EQ
3601 || e
->value
.op
.op
== INTRINSIC_EQ_OS
)
3602 ? ".eqv." : ".neqv.", gfc_op2string (e
->value
.op
.op
));
3605 _("Operands of comparison operator '%s' at %%L are %s/%s"),
3606 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3607 gfc_typename (&op2
->ts
));
3611 case INTRINSIC_USER
:
3612 if (e
->value
.op
.uop
->op
== NULL
)
3613 sprintf (msg
, _("Unknown operator '%s' at %%L"), e
->value
.op
.uop
->name
);
3614 else if (op2
== NULL
)
3615 sprintf (msg
, _("Operand of user operator '%s' at %%L is %s"),
3616 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
));
3619 sprintf (msg
, _("Operands of user operator '%s' at %%L are %s/%s"),
3620 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
),
3621 gfc_typename (&op2
->ts
));
3622 e
->value
.op
.uop
->op
->sym
->attr
.referenced
= 1;
3627 case INTRINSIC_PARENTHESES
:
3629 if (e
->ts
.type
== BT_CHARACTER
)
3630 e
->ts
.u
.cl
= op1
->ts
.u
.cl
;
3634 gfc_internal_error ("resolve_operator(): Bad intrinsic");
3637 /* Deal with arrayness of an operand through an operator. */
3641 switch (e
->value
.op
.op
)
3643 case INTRINSIC_PLUS
:
3644 case INTRINSIC_MINUS
:
3645 case INTRINSIC_TIMES
:
3646 case INTRINSIC_DIVIDE
:
3647 case INTRINSIC_POWER
:
3648 case INTRINSIC_CONCAT
:
3652 case INTRINSIC_NEQV
:
3654 case INTRINSIC_EQ_OS
:
3656 case INTRINSIC_NE_OS
:
3658 case INTRINSIC_GT_OS
:
3660 case INTRINSIC_GE_OS
:
3662 case INTRINSIC_LT_OS
:
3664 case INTRINSIC_LE_OS
:
3666 if (op1
->rank
== 0 && op2
->rank
== 0)
3669 if (op1
->rank
== 0 && op2
->rank
!= 0)
3671 e
->rank
= op2
->rank
;
3673 if (e
->shape
== NULL
)
3674 e
->shape
= gfc_copy_shape (op2
->shape
, op2
->rank
);
3677 if (op1
->rank
!= 0 && op2
->rank
== 0)
3679 e
->rank
= op1
->rank
;
3681 if (e
->shape
== NULL
)
3682 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3685 if (op1
->rank
!= 0 && op2
->rank
!= 0)
3687 if (op1
->rank
== op2
->rank
)
3689 e
->rank
= op1
->rank
;
3690 if (e
->shape
== NULL
)
3692 t
= compare_shapes (op1
, op2
);
3696 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3701 /* Allow higher level expressions to work. */
3704 /* Try user-defined operators, and otherwise throw an error. */
3705 dual_locus_error
= true;
3707 _("Inconsistent ranks for operator at %%L and %%L"));
3714 case INTRINSIC_PARENTHESES
:
3716 case INTRINSIC_UPLUS
:
3717 case INTRINSIC_UMINUS
:
3718 /* Simply copy arrayness attribute */
3719 e
->rank
= op1
->rank
;
3721 if (e
->shape
== NULL
)
3722 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3730 /* Attempt to simplify the expression. */
3733 t
= gfc_simplify_expr (e
, 0);
3734 /* Some calls do not succeed in simplification and return false
3735 even though there is no error; e.g. variable references to
3736 PARAMETER arrays. */
3737 if (!gfc_is_constant_expr (e
))
3745 match m
= gfc_extend_expr (e
);
3748 if (m
== MATCH_ERROR
)
3752 if (dual_locus_error
)
3753 gfc_error (msg
, &op1
->where
, &op2
->where
);
3755 gfc_error (msg
, &e
->where
);
3761 /************** Array resolution subroutines **************/
3764 { CMP_LT
, CMP_EQ
, CMP_GT
, CMP_UNKNOWN
}
3767 /* Compare two integer expressions. */
3770 compare_bound (gfc_expr
*a
, gfc_expr
*b
)
3774 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
3775 || b
== NULL
|| b
->expr_type
!= EXPR_CONSTANT
)
3778 /* If either of the types isn't INTEGER, we must have
3779 raised an error earlier. */
3781 if (a
->ts
.type
!= BT_INTEGER
|| b
->ts
.type
!= BT_INTEGER
)
3784 i
= mpz_cmp (a
->value
.integer
, b
->value
.integer
);
3794 /* Compare an integer expression with an integer. */
3797 compare_bound_int (gfc_expr
*a
, int b
)
3801 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3804 if (a
->ts
.type
!= BT_INTEGER
)
3805 gfc_internal_error ("compare_bound_int(): Bad expression");
3807 i
= mpz_cmp_si (a
->value
.integer
, b
);
3817 /* Compare an integer expression with a mpz_t. */
3820 compare_bound_mpz_t (gfc_expr
*a
, mpz_t b
)
3824 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3827 if (a
->ts
.type
!= BT_INTEGER
)
3828 gfc_internal_error ("compare_bound_int(): Bad expression");
3830 i
= mpz_cmp (a
->value
.integer
, b
);
3840 /* Compute the last value of a sequence given by a triplet.
3841 Return 0 if it wasn't able to compute the last value, or if the
3842 sequence if empty, and 1 otherwise. */
3845 compute_last_value_for_triplet (gfc_expr
*start
, gfc_expr
*end
,
3846 gfc_expr
*stride
, mpz_t last
)
3850 if (start
== NULL
|| start
->expr_type
!= EXPR_CONSTANT
3851 || end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
3852 || (stride
!= NULL
&& stride
->expr_type
!= EXPR_CONSTANT
))
3855 if (start
->ts
.type
!= BT_INTEGER
|| end
->ts
.type
!= BT_INTEGER
3856 || (stride
!= NULL
&& stride
->ts
.type
!= BT_INTEGER
))
3859 if (stride
== NULL
|| compare_bound_int (stride
, 1) == CMP_EQ
)
3861 if (compare_bound (start
, end
) == CMP_GT
)
3863 mpz_set (last
, end
->value
.integer
);
3867 if (compare_bound_int (stride
, 0) == CMP_GT
)
3869 /* Stride is positive */
3870 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) > 0)
3875 /* Stride is negative */
3876 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) < 0)
3881 mpz_sub (rem
, end
->value
.integer
, start
->value
.integer
);
3882 mpz_tdiv_r (rem
, rem
, stride
->value
.integer
);
3883 mpz_sub (last
, end
->value
.integer
, rem
);
3890 /* Compare a single dimension of an array reference to the array
3894 check_dimension (int i
, gfc_array_ref
*ar
, gfc_array_spec
*as
)
3898 if (ar
->dimen_type
[i
] == DIMEN_STAR
)
3900 gcc_assert (ar
->stride
[i
] == NULL
);
3901 /* This implies [*] as [*:] and [*:3] are not possible. */
3902 if (ar
->start
[i
] == NULL
)
3904 gcc_assert (ar
->end
[i
] == NULL
);
3909 /* Given start, end and stride values, calculate the minimum and
3910 maximum referenced indexes. */
3912 switch (ar
->dimen_type
[i
])
3915 case DIMEN_THIS_IMAGE
:
3920 if (compare_bound (ar
->start
[i
], as
->lower
[i
]) == CMP_LT
)
3923 gfc_warning ("Array reference at %L is out of bounds "
3924 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
3925 mpz_get_si (ar
->start
[i
]->value
.integer
),
3926 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
3928 gfc_warning ("Array reference at %L is out of bounds "
3929 "(%ld < %ld) in codimension %d", &ar
->c_where
[i
],
3930 mpz_get_si (ar
->start
[i
]->value
.integer
),
3931 mpz_get_si (as
->lower
[i
]->value
.integer
),
3935 if (compare_bound (ar
->start
[i
], as
->upper
[i
]) == CMP_GT
)
3938 gfc_warning ("Array reference at %L is out of bounds "
3939 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
3940 mpz_get_si (ar
->start
[i
]->value
.integer
),
3941 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
3943 gfc_warning ("Array reference at %L is out of bounds "
3944 "(%ld > %ld) in codimension %d", &ar
->c_where
[i
],
3945 mpz_get_si (ar
->start
[i
]->value
.integer
),
3946 mpz_get_si (as
->upper
[i
]->value
.integer
),
3955 #define AR_START (ar->start[i] ? ar->start[i] : as->lower[i])
3956 #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i])
3958 comparison comp_start_end
= compare_bound (AR_START
, AR_END
);
3960 /* Check for zero stride, which is not allowed. */
3961 if (compare_bound_int (ar
->stride
[i
], 0) == CMP_EQ
)
3963 gfc_error ("Illegal stride of zero at %L", &ar
->c_where
[i
]);
3967 /* if start == len || (stride > 0 && start < len)
3968 || (stride < 0 && start > len),
3969 then the array section contains at least one element. In this
3970 case, there is an out-of-bounds access if
3971 (start < lower || start > upper). */
3972 if (compare_bound (AR_START
, AR_END
) == CMP_EQ
3973 || ((compare_bound_int (ar
->stride
[i
], 0) == CMP_GT
3974 || ar
->stride
[i
] == NULL
) && comp_start_end
== CMP_LT
)
3975 || (compare_bound_int (ar
->stride
[i
], 0) == CMP_LT
3976 && comp_start_end
== CMP_GT
))
3978 if (compare_bound (AR_START
, as
->lower
[i
]) == CMP_LT
)
3980 gfc_warning ("Lower array reference at %L is out of bounds "
3981 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
3982 mpz_get_si (AR_START
->value
.integer
),
3983 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
3986 if (compare_bound (AR_START
, as
->upper
[i
]) == CMP_GT
)
3988 gfc_warning ("Lower array reference at %L is out of bounds "
3989 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
3990 mpz_get_si (AR_START
->value
.integer
),
3991 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
3996 /* If we can compute the highest index of the array section,
3997 then it also has to be between lower and upper. */
3998 mpz_init (last_value
);
3999 if (compute_last_value_for_triplet (AR_START
, AR_END
, ar
->stride
[i
],
4002 if (compare_bound_mpz_t (as
->lower
[i
], last_value
) == CMP_GT
)
4004 gfc_warning ("Upper array reference at %L is out of bounds "
4005 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4006 mpz_get_si (last_value
),
4007 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4008 mpz_clear (last_value
);
4011 if (compare_bound_mpz_t (as
->upper
[i
], last_value
) == CMP_LT
)
4013 gfc_warning ("Upper array reference at %L is out of bounds "
4014 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4015 mpz_get_si (last_value
),
4016 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4017 mpz_clear (last_value
);
4021 mpz_clear (last_value
);
4029 gfc_internal_error ("check_dimension(): Bad array reference");
4036 /* Compare an array reference with an array specification. */
4039 compare_spec_to_ref (gfc_array_ref
*ar
)
4046 /* TODO: Full array sections are only allowed as actual parameters. */
4047 if (as
->type
== AS_ASSUMED_SIZE
4048 && (/*ar->type == AR_FULL
4049 ||*/ (ar
->type
== AR_SECTION
4050 && ar
->dimen_type
[i
] == DIMEN_RANGE
&& ar
->end
[i
] == NULL
)))
4052 gfc_error ("Rightmost upper bound of assumed size array section "
4053 "not specified at %L", &ar
->where
);
4057 if (ar
->type
== AR_FULL
)
4060 if (as
->rank
!= ar
->dimen
)
4062 gfc_error ("Rank mismatch in array reference at %L (%d/%d)",
4063 &ar
->where
, ar
->dimen
, as
->rank
);
4067 /* ar->codimen == 0 is a local array. */
4068 if (as
->corank
!= ar
->codimen
&& ar
->codimen
!= 0)
4070 gfc_error ("Coindex rank mismatch in array reference at %L (%d/%d)",
4071 &ar
->where
, ar
->codimen
, as
->corank
);
4075 for (i
= 0; i
< as
->rank
; i
++)
4076 if (!check_dimension (i
, ar
, as
))
4079 /* Local access has no coarray spec. */
4080 if (ar
->codimen
!= 0)
4081 for (i
= as
->rank
; i
< as
->rank
+ as
->corank
; i
++)
4083 if (ar
->dimen_type
[i
] != DIMEN_ELEMENT
&& !ar
->in_allocate
4084 && ar
->dimen_type
[i
] != DIMEN_THIS_IMAGE
)
4086 gfc_error ("Coindex of codimension %d must be a scalar at %L",
4087 i
+ 1 - as
->rank
, &ar
->where
);
4090 if (!check_dimension (i
, ar
, as
))
4098 /* Resolve one part of an array index. */
4101 gfc_resolve_index_1 (gfc_expr
*index
, int check_scalar
,
4102 int force_index_integer_kind
)
4109 if (!gfc_resolve_expr (index
))
4112 if (check_scalar
&& index
->rank
!= 0)
4114 gfc_error ("Array index at %L must be scalar", &index
->where
);
4118 if (index
->ts
.type
!= BT_INTEGER
&& index
->ts
.type
!= BT_REAL
)
4120 gfc_error ("Array index at %L must be of INTEGER type, found %s",
4121 &index
->where
, gfc_basic_typename (index
->ts
.type
));
4125 if (index
->ts
.type
== BT_REAL
)
4126 if (!gfc_notify_std (GFC_STD_LEGACY
, "REAL array index at %L",
4130 if ((index
->ts
.kind
!= gfc_index_integer_kind
4131 && force_index_integer_kind
)
4132 || index
->ts
.type
!= BT_INTEGER
)
4135 ts
.type
= BT_INTEGER
;
4136 ts
.kind
= gfc_index_integer_kind
;
4138 gfc_convert_type_warn (index
, &ts
, 2, 0);
4144 /* Resolve one part of an array index. */
4147 gfc_resolve_index (gfc_expr
*index
, int check_scalar
)
4149 return gfc_resolve_index_1 (index
, check_scalar
, 1);
4152 /* Resolve a dim argument to an intrinsic function. */
4155 gfc_resolve_dim_arg (gfc_expr
*dim
)
4160 if (!gfc_resolve_expr (dim
))
4165 gfc_error ("Argument dim at %L must be scalar", &dim
->where
);
4170 if (dim
->ts
.type
!= BT_INTEGER
)
4172 gfc_error ("Argument dim at %L must be of INTEGER type", &dim
->where
);
4176 if (dim
->ts
.kind
!= gfc_index_integer_kind
)
4181 ts
.type
= BT_INTEGER
;
4182 ts
.kind
= gfc_index_integer_kind
;
4184 gfc_convert_type_warn (dim
, &ts
, 2, 0);
4190 /* Given an expression that contains array references, update those array
4191 references to point to the right array specifications. While this is
4192 filled in during matching, this information is difficult to save and load
4193 in a module, so we take care of it here.
4195 The idea here is that the original array reference comes from the
4196 base symbol. We traverse the list of reference structures, setting
4197 the stored reference to references. Component references can
4198 provide an additional array specification. */
4201 find_array_spec (gfc_expr
*e
)
4207 if (e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
)
4208 as
= CLASS_DATA (e
->symtree
->n
.sym
)->as
;
4210 as
= e
->symtree
->n
.sym
->as
;
4212 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4217 gfc_internal_error ("find_array_spec(): Missing spec");
4224 c
= ref
->u
.c
.component
;
4225 if (c
->attr
.dimension
)
4228 gfc_internal_error ("find_array_spec(): unused as(1)");
4239 gfc_internal_error ("find_array_spec(): unused as(2)");
4243 /* Resolve an array reference. */
4246 resolve_array_ref (gfc_array_ref
*ar
)
4248 int i
, check_scalar
;
4251 for (i
= 0; i
< ar
->dimen
+ ar
->codimen
; i
++)
4253 check_scalar
= ar
->dimen_type
[i
] == DIMEN_RANGE
;
4255 /* Do not force gfc_index_integer_kind for the start. We can
4256 do fine with any integer kind. This avoids temporary arrays
4257 created for indexing with a vector. */
4258 if (!gfc_resolve_index_1 (ar
->start
[i
], check_scalar
, 0))
4260 if (!gfc_resolve_index (ar
->end
[i
], check_scalar
))
4262 if (!gfc_resolve_index (ar
->stride
[i
], check_scalar
))
4267 if (ar
->dimen_type
[i
] == DIMEN_UNKNOWN
)
4271 ar
->dimen_type
[i
] = DIMEN_ELEMENT
;
4275 ar
->dimen_type
[i
] = DIMEN_VECTOR
;
4276 if (e
->expr_type
== EXPR_VARIABLE
4277 && e
->symtree
->n
.sym
->ts
.type
== BT_DERIVED
)
4278 ar
->start
[i
] = gfc_get_parentheses (e
);
4282 gfc_error ("Array index at %L is an array of rank %d",
4283 &ar
->c_where
[i
], e
->rank
);
4287 /* Fill in the upper bound, which may be lower than the
4288 specified one for something like a(2:10:5), which is
4289 identical to a(2:7:5). Only relevant for strides not equal
4290 to one. Don't try a division by zero. */
4291 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4292 && ar
->stride
[i
] != NULL
&& ar
->stride
[i
]->expr_type
== EXPR_CONSTANT
4293 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 1L) != 0
4294 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 0L) != 0)
4298 if (gfc_ref_dimen_size (ar
, i
, &size
, &end
))
4300 if (ar
->end
[i
] == NULL
)
4303 gfc_get_constant_expr (BT_INTEGER
, gfc_index_integer_kind
,
4305 mpz_set (ar
->end
[i
]->value
.integer
, end
);
4307 else if (ar
->end
[i
]->ts
.type
== BT_INTEGER
4308 && ar
->end
[i
]->expr_type
== EXPR_CONSTANT
)
4310 mpz_set (ar
->end
[i
]->value
.integer
, end
);
4321 if (ar
->type
== AR_FULL
)
4323 if (ar
->as
->rank
== 0)
4324 ar
->type
= AR_ELEMENT
;
4326 /* Make sure array is the same as array(:,:), this way
4327 we don't need to special case all the time. */
4328 ar
->dimen
= ar
->as
->rank
;
4329 for (i
= 0; i
< ar
->dimen
; i
++)
4331 ar
->dimen_type
[i
] = DIMEN_RANGE
;
4333 gcc_assert (ar
->start
[i
] == NULL
);
4334 gcc_assert (ar
->end
[i
] == NULL
);
4335 gcc_assert (ar
->stride
[i
] == NULL
);
4339 /* If the reference type is unknown, figure out what kind it is. */
4341 if (ar
->type
== AR_UNKNOWN
)
4343 ar
->type
= AR_ELEMENT
;
4344 for (i
= 0; i
< ar
->dimen
; i
++)
4345 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4346 || ar
->dimen_type
[i
] == DIMEN_VECTOR
)
4348 ar
->type
= AR_SECTION
;
4353 if (!ar
->as
->cray_pointee
&& !compare_spec_to_ref (ar
))
4356 if (ar
->as
->corank
&& ar
->codimen
== 0)
4359 ar
->codimen
= ar
->as
->corank
;
4360 for (n
= ar
->dimen
; n
< ar
->dimen
+ ar
->codimen
; n
++)
4361 ar
->dimen_type
[n
] = DIMEN_THIS_IMAGE
;
4369 resolve_substring (gfc_ref
*ref
)
4371 int k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
4373 if (ref
->u
.ss
.start
!= NULL
)
4375 if (!gfc_resolve_expr (ref
->u
.ss
.start
))
4378 if (ref
->u
.ss
.start
->ts
.type
!= BT_INTEGER
)
4380 gfc_error ("Substring start index at %L must be of type INTEGER",
4381 &ref
->u
.ss
.start
->where
);
4385 if (ref
->u
.ss
.start
->rank
!= 0)
4387 gfc_error ("Substring start index at %L must be scalar",
4388 &ref
->u
.ss
.start
->where
);
4392 if (compare_bound_int (ref
->u
.ss
.start
, 1) == CMP_LT
4393 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4394 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4396 gfc_error ("Substring start index at %L is less than one",
4397 &ref
->u
.ss
.start
->where
);
4402 if (ref
->u
.ss
.end
!= NULL
)
4404 if (!gfc_resolve_expr (ref
->u
.ss
.end
))
4407 if (ref
->u
.ss
.end
->ts
.type
!= BT_INTEGER
)
4409 gfc_error ("Substring end index at %L must be of type INTEGER",
4410 &ref
->u
.ss
.end
->where
);
4414 if (ref
->u
.ss
.end
->rank
!= 0)
4416 gfc_error ("Substring end index at %L must be scalar",
4417 &ref
->u
.ss
.end
->where
);
4421 if (ref
->u
.ss
.length
!= NULL
4422 && compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.length
->length
) == CMP_GT
4423 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4424 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4426 gfc_error ("Substring end index at %L exceeds the string length",
4427 &ref
->u
.ss
.start
->where
);
4431 if (compare_bound_mpz_t (ref
->u
.ss
.end
,
4432 gfc_integer_kinds
[k
].huge
) == CMP_GT
4433 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
4434 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
4436 gfc_error ("Substring end index at %L is too large",
4437 &ref
->u
.ss
.end
->where
);
4446 /* This function supplies missing substring charlens. */
4449 gfc_resolve_substring_charlen (gfc_expr
*e
)
4452 gfc_expr
*start
, *end
;
4454 for (char_ref
= e
->ref
; char_ref
; char_ref
= char_ref
->next
)
4455 if (char_ref
->type
== REF_SUBSTRING
)
4461 gcc_assert (char_ref
->next
== NULL
);
4465 if (e
->ts
.u
.cl
->length
)
4466 gfc_free_expr (e
->ts
.u
.cl
->length
);
4467 else if (e
->expr_type
== EXPR_VARIABLE
4468 && e
->symtree
->n
.sym
->attr
.dummy
)
4472 e
->ts
.type
= BT_CHARACTER
;
4473 e
->ts
.kind
= gfc_default_character_kind
;
4476 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
4478 if (char_ref
->u
.ss
.start
)
4479 start
= gfc_copy_expr (char_ref
->u
.ss
.start
);
4481 start
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
4483 if (char_ref
->u
.ss
.end
)
4484 end
= gfc_copy_expr (char_ref
->u
.ss
.end
);
4485 else if (e
->expr_type
== EXPR_VARIABLE
)
4486 end
= gfc_copy_expr (e
->symtree
->n
.sym
->ts
.u
.cl
->length
);
4492 gfc_free_expr (start
);
4493 gfc_free_expr (end
);
4497 /* Length = (end - start +1). */
4498 e
->ts
.u
.cl
->length
= gfc_subtract (end
, start
);
4499 e
->ts
.u
.cl
->length
= gfc_add (e
->ts
.u
.cl
->length
,
4500 gfc_get_int_expr (gfc_default_integer_kind
,
4503 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
4504 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
4506 /* Make sure that the length is simplified. */
4507 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 1);
4508 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
4512 /* Resolve subtype references. */
4515 resolve_ref (gfc_expr
*expr
)
4517 int current_part_dimension
, n_components
, seen_part_dimension
;
4520 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4521 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.as
== NULL
)
4523 find_array_spec (expr
);
4527 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4531 if (!resolve_array_ref (&ref
->u
.ar
))
4539 if (!resolve_substring (ref
))
4544 /* Check constraints on part references. */
4546 current_part_dimension
= 0;
4547 seen_part_dimension
= 0;
4550 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4555 switch (ref
->u
.ar
.type
)
4558 /* Coarray scalar. */
4559 if (ref
->u
.ar
.as
->rank
== 0)
4561 current_part_dimension
= 0;
4566 current_part_dimension
= 1;
4570 current_part_dimension
= 0;
4574 gfc_internal_error ("resolve_ref(): Bad array reference");
4580 if (current_part_dimension
|| seen_part_dimension
)
4583 if (ref
->u
.c
.component
->attr
.pointer
4584 || ref
->u
.c
.component
->attr
.proc_pointer
4585 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
4586 && CLASS_DATA (ref
->u
.c
.component
)->attr
.pointer
))
4588 gfc_error ("Component to the right of a part reference "
4589 "with nonzero rank must not have the POINTER "
4590 "attribute at %L", &expr
->where
);
4593 else if (ref
->u
.c
.component
->attr
.allocatable
4594 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
4595 && CLASS_DATA (ref
->u
.c
.component
)->attr
.allocatable
))
4598 gfc_error ("Component to the right of a part reference "
4599 "with nonzero rank must not have the ALLOCATABLE "
4600 "attribute at %L", &expr
->where
);
4612 if (((ref
->type
== REF_COMPONENT
&& n_components
> 1)
4613 || ref
->next
== NULL
)
4614 && current_part_dimension
4615 && seen_part_dimension
)
4617 gfc_error ("Two or more part references with nonzero rank must "
4618 "not be specified at %L", &expr
->where
);
4622 if (ref
->type
== REF_COMPONENT
)
4624 if (current_part_dimension
)
4625 seen_part_dimension
= 1;
4627 /* reset to make sure */
4628 current_part_dimension
= 0;
4636 /* Given an expression, determine its shape. This is easier than it sounds.
4637 Leaves the shape array NULL if it is not possible to determine the shape. */
4640 expression_shape (gfc_expr
*e
)
4642 mpz_t array
[GFC_MAX_DIMENSIONS
];
4645 if (e
->rank
<= 0 || e
->shape
!= NULL
)
4648 for (i
= 0; i
< e
->rank
; i
++)
4649 if (!gfc_array_dimen_size (e
, i
, &array
[i
]))
4652 e
->shape
= gfc_get_shape (e
->rank
);
4654 memcpy (e
->shape
, array
, e
->rank
* sizeof (mpz_t
));
4659 for (i
--; i
>= 0; i
--)
4660 mpz_clear (array
[i
]);
4664 /* Given a variable expression node, compute the rank of the expression by
4665 examining the base symbol and any reference structures it may have. */
4668 expression_rank (gfc_expr
*e
)
4673 /* Just to make sure, because EXPR_COMPCALL's also have an e->ref and that
4674 could lead to serious confusion... */
4675 gcc_assert (e
->expr_type
!= EXPR_COMPCALL
);
4679 if (e
->expr_type
== EXPR_ARRAY
)
4681 /* Constructors can have a rank different from one via RESHAPE(). */
4683 if (e
->symtree
== NULL
)
4689 e
->rank
= (e
->symtree
->n
.sym
->as
== NULL
)
4690 ? 0 : e
->symtree
->n
.sym
->as
->rank
;
4696 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4698 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.proc_pointer
4699 && ref
->u
.c
.component
->attr
.function
&& !ref
->next
)
4700 rank
= ref
->u
.c
.component
->as
? ref
->u
.c
.component
->as
->rank
: 0;
4702 if (ref
->type
!= REF_ARRAY
)
4705 if (ref
->u
.ar
.type
== AR_FULL
)
4707 rank
= ref
->u
.ar
.as
->rank
;
4711 if (ref
->u
.ar
.type
== AR_SECTION
)
4713 /* Figure out the rank of the section. */
4715 gfc_internal_error ("expression_rank(): Two array specs");
4717 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
4718 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_RANGE
4719 || ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
4729 expression_shape (e
);
4734 add_caf_get_intrinsic (gfc_expr
*e
)
4736 gfc_expr
*wrapper
, *tmp_expr
;
4740 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4741 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
4746 for (n
= ref
->u
.ar
.dimen
; n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
4747 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_ELEMENT
)
4750 tmp_expr
= XCNEW (gfc_expr
);
4752 wrapper
= gfc_build_intrinsic_call (gfc_current_ns
, GFC_ISYM_CAF_GET
,
4753 "caf_get", tmp_expr
->where
, 1, tmp_expr
);
4754 wrapper
->ts
= e
->ts
;
4755 wrapper
->rank
= e
->rank
;
4757 wrapper
->shape
= gfc_copy_shape (e
->shape
, e
->rank
);
4764 remove_caf_get_intrinsic (gfc_expr
*e
)
4766 gcc_assert (e
->expr_type
== EXPR_FUNCTION
&& e
->value
.function
.isym
4767 && e
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
);
4768 gfc_expr
*e2
= e
->value
.function
.actual
->expr
;
4769 e
->value
.function
.actual
->expr
=NULL
;
4770 gfc_free_actual_arglist (e
->value
.function
.actual
);
4771 gfc_free_shape (&e
->shape
, e
->rank
);
4777 /* Resolve a variable expression. */
4780 resolve_variable (gfc_expr
*e
)
4787 if (e
->symtree
== NULL
)
4789 sym
= e
->symtree
->n
.sym
;
4791 /* Use same check as for TYPE(*) below; this check has to be before TYPE(*)
4792 as ts.type is set to BT_ASSUMED in resolve_symbol. */
4793 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
4795 if (!actual_arg
|| inquiry_argument
)
4797 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may only "
4798 "be used as actual argument", sym
->name
, &e
->where
);
4802 /* TS 29113, 407b. */
4803 else if (e
->ts
.type
== BT_ASSUMED
)
4807 gfc_error ("Assumed-type variable %s at %L may only be used "
4808 "as actual argument", sym
->name
, &e
->where
);
4811 else if (inquiry_argument
&& !first_actual_arg
)
4813 /* FIXME: It doesn't work reliably as inquiry_argument is not set
4814 for all inquiry functions in resolve_function; the reason is
4815 that the function-name resolution happens too late in that
4817 gfc_error ("Assumed-type variable %s at %L as actual argument to "
4818 "an inquiry function shall be the first argument",
4819 sym
->name
, &e
->where
);
4823 /* TS 29113, C535b. */
4824 else if ((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
4825 && CLASS_DATA (sym
)->as
4826 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
4827 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
4828 && sym
->as
->type
== AS_ASSUMED_RANK
))
4832 gfc_error ("Assumed-rank variable %s at %L may only be used as "
4833 "actual argument", sym
->name
, &e
->where
);
4836 else if (inquiry_argument
&& !first_actual_arg
)
4838 /* FIXME: It doesn't work reliably as inquiry_argument is not set
4839 for all inquiry functions in resolve_function; the reason is
4840 that the function-name resolution happens too late in that
4842 gfc_error ("Assumed-rank variable %s at %L as actual argument "
4843 "to an inquiry function shall be the first argument",
4844 sym
->name
, &e
->where
);
4849 if ((sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
)) && e
->ref
4850 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
4851 && e
->ref
->next
== NULL
))
4853 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall not have "
4854 "a subobject reference", sym
->name
, &e
->ref
->u
.ar
.where
);
4857 /* TS 29113, 407b. */
4858 else if (e
->ts
.type
== BT_ASSUMED
&& e
->ref
4859 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
4860 && e
->ref
->next
== NULL
))
4862 gfc_error ("Assumed-type variable %s at %L shall not have a subobject "
4863 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
4867 /* TS 29113, C535b. */
4868 if (((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
4869 && CLASS_DATA (sym
)->as
4870 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
4871 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
4872 && sym
->as
->type
== AS_ASSUMED_RANK
))
4874 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
4875 && e
->ref
->next
== NULL
))
4877 gfc_error ("Assumed-rank variable %s at %L shall not have a subobject "
4878 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
4883 /* If this is an associate-name, it may be parsed with an array reference
4884 in error even though the target is scalar. Fail directly in this case.
4885 TODO Understand why class scalar expressions must be excluded. */
4886 if (sym
->assoc
&& !(sym
->ts
.type
== BT_CLASS
&& e
->rank
== 0))
4888 if (sym
->ts
.type
== BT_CLASS
)
4889 gfc_fix_class_refs (e
);
4890 if (!sym
->attr
.dimension
&& e
->ref
&& e
->ref
->type
== REF_ARRAY
)
4894 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.generic
)
4895 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
4897 /* On the other hand, the parser may not have known this is an array;
4898 in this case, we have to add a FULL reference. */
4899 if (sym
->assoc
&& sym
->attr
.dimension
&& !e
->ref
)
4901 e
->ref
= gfc_get_ref ();
4902 e
->ref
->type
= REF_ARRAY
;
4903 e
->ref
->u
.ar
.type
= AR_FULL
;
4904 e
->ref
->u
.ar
.dimen
= 0;
4907 if (e
->ref
&& !resolve_ref (e
))
4910 if (sym
->attr
.flavor
== FL_PROCEDURE
4911 && (!sym
->attr
.function
4912 || (sym
->attr
.function
&& sym
->result
4913 && sym
->result
->attr
.proc_pointer
4914 && !sym
->result
->attr
.function
)))
4916 e
->ts
.type
= BT_PROCEDURE
;
4917 goto resolve_procedure
;
4920 if (sym
->ts
.type
!= BT_UNKNOWN
)
4921 gfc_variable_attr (e
, &e
->ts
);
4924 /* Must be a simple variable reference. */
4925 if (!gfc_set_default_type (sym
, 1, sym
->ns
))
4930 if (check_assumed_size_reference (sym
, e
))
4933 /* Deal with forward references to entries during resolve_code, to
4934 satisfy, at least partially, 12.5.2.5. */
4935 if (gfc_current_ns
->entries
4936 && current_entry_id
== sym
->entry_id
4939 && cs_base
->current
->op
!= EXEC_ENTRY
)
4941 gfc_entry_list
*entry
;
4942 gfc_formal_arglist
*formal
;
4944 bool seen
, saved_specification_expr
;
4946 /* If the symbol is a dummy... */
4947 if (sym
->attr
.dummy
&& sym
->ns
== gfc_current_ns
)
4949 entry
= gfc_current_ns
->entries
;
4952 /* ...test if the symbol is a parameter of previous entries. */
4953 for (; entry
&& entry
->id
<= current_entry_id
; entry
= entry
->next
)
4954 for (formal
= entry
->sym
->formal
; formal
; formal
= formal
->next
)
4956 if (formal
->sym
&& sym
->name
== formal
->sym
->name
)
4963 /* If it has not been seen as a dummy, this is an error. */
4966 if (specification_expr
)
4967 gfc_error ("Variable '%s', used in a specification expression"
4968 ", is referenced at %L before the ENTRY statement "
4969 "in which it is a parameter",
4970 sym
->name
, &cs_base
->current
->loc
);
4972 gfc_error ("Variable '%s' is used at %L before the ENTRY "
4973 "statement in which it is a parameter",
4974 sym
->name
, &cs_base
->current
->loc
);
4979 /* Now do the same check on the specification expressions. */
4980 saved_specification_expr
= specification_expr
;
4981 specification_expr
= true;
4982 if (sym
->ts
.type
== BT_CHARACTER
4983 && !gfc_resolve_expr (sym
->ts
.u
.cl
->length
))
4987 for (n
= 0; n
< sym
->as
->rank
; n
++)
4989 if (!gfc_resolve_expr (sym
->as
->lower
[n
]))
4991 if (!gfc_resolve_expr (sym
->as
->upper
[n
]))
4994 specification_expr
= saved_specification_expr
;
4997 /* Update the symbol's entry level. */
4998 sym
->entry_id
= current_entry_id
+ 1;
5001 /* If a symbol has been host_associated mark it. This is used latter,
5002 to identify if aliasing is possible via host association. */
5003 if (sym
->attr
.flavor
== FL_VARIABLE
5004 && gfc_current_ns
->parent
5005 && (gfc_current_ns
->parent
== sym
->ns
5006 || (gfc_current_ns
->parent
->parent
5007 && gfc_current_ns
->parent
->parent
== sym
->ns
)))
5008 sym
->attr
.host_assoc
= 1;
5011 if (t
&& !resolve_procedure_expression (e
))
5014 /* F2008, C617 and C1229. */
5015 if (!inquiry_argument
&& (e
->ts
.type
== BT_CLASS
|| e
->ts
.type
== BT_DERIVED
)
5016 && gfc_is_coindexed (e
))
5018 gfc_ref
*ref
, *ref2
= NULL
;
5020 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5022 if (ref
->type
== REF_COMPONENT
)
5024 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
5028 for ( ; ref
; ref
= ref
->next
)
5029 if (ref
->type
== REF_COMPONENT
)
5032 /* Expression itself is not coindexed object. */
5033 if (ref
&& e
->ts
.type
== BT_CLASS
)
5035 gfc_error ("Polymorphic subobject of coindexed object at %L",
5040 /* Expression itself is coindexed object. */
5044 c
= ref2
? ref2
->u
.c
.component
: e
->symtree
->n
.sym
->components
;
5045 for ( ; c
; c
= c
->next
)
5046 if (c
->attr
.allocatable
&& c
->ts
.type
== BT_CLASS
)
5048 gfc_error ("Coindexed object with polymorphic allocatable "
5049 "subcomponent at %L", &e
->where
);
5057 expression_rank (e
);
5059 if (0 && t
&& gfc_option
.coarray
== GFC_FCOARRAY_LIB
&& gfc_is_coindexed (e
))
5060 add_caf_get_intrinsic (e
);
5066 /* Checks to see that the correct symbol has been host associated.
5067 The only situation where this arises is that in which a twice
5068 contained function is parsed after the host association is made.
5069 Therefore, on detecting this, change the symbol in the expression
5070 and convert the array reference into an actual arglist if the old
5071 symbol is a variable. */
5073 check_host_association (gfc_expr
*e
)
5075 gfc_symbol
*sym
, *old_sym
;
5079 gfc_actual_arglist
*arg
, *tail
= NULL
;
5080 bool retval
= e
->expr_type
== EXPR_FUNCTION
;
5082 /* If the expression is the result of substitution in
5083 interface.c(gfc_extend_expr) because there is no way in
5084 which the host association can be wrong. */
5085 if (e
->symtree
== NULL
5086 || e
->symtree
->n
.sym
== NULL
5087 || e
->user_operator
)
5090 old_sym
= e
->symtree
->n
.sym
;
5092 if (gfc_current_ns
->parent
5093 && old_sym
->ns
!= gfc_current_ns
)
5095 /* Use the 'USE' name so that renamed module symbols are
5096 correctly handled. */
5097 gfc_find_symbol (e
->symtree
->name
, gfc_current_ns
, 1, &sym
);
5099 if (sym
&& old_sym
!= sym
5100 && sym
->ts
.type
== old_sym
->ts
.type
5101 && sym
->attr
.flavor
== FL_PROCEDURE
5102 && sym
->attr
.contained
)
5104 /* Clear the shape, since it might not be valid. */
5105 gfc_free_shape (&e
->shape
, e
->rank
);
5107 /* Give the expression the right symtree! */
5108 gfc_find_sym_tree (e
->symtree
->name
, NULL
, 1, &st
);
5109 gcc_assert (st
!= NULL
);
5111 if (old_sym
->attr
.flavor
== FL_PROCEDURE
5112 || e
->expr_type
== EXPR_FUNCTION
)
5114 /* Original was function so point to the new symbol, since
5115 the actual argument list is already attached to the
5117 e
->value
.function
.esym
= NULL
;
5122 /* Original was variable so convert array references into
5123 an actual arglist. This does not need any checking now
5124 since resolve_function will take care of it. */
5125 e
->value
.function
.actual
= NULL
;
5126 e
->expr_type
= EXPR_FUNCTION
;
5129 /* Ambiguity will not arise if the array reference is not
5130 the last reference. */
5131 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5132 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
5135 gcc_assert (ref
->type
== REF_ARRAY
);
5137 /* Grab the start expressions from the array ref and
5138 copy them into actual arguments. */
5139 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
5141 arg
= gfc_get_actual_arglist ();
5142 arg
->expr
= gfc_copy_expr (ref
->u
.ar
.start
[n
]);
5143 if (e
->value
.function
.actual
== NULL
)
5144 tail
= e
->value
.function
.actual
= arg
;
5152 /* Dump the reference list and set the rank. */
5153 gfc_free_ref_list (e
->ref
);
5155 e
->rank
= sym
->as
? sym
->as
->rank
: 0;
5158 gfc_resolve_expr (e
);
5162 /* This might have changed! */
5163 return e
->expr_type
== EXPR_FUNCTION
;
5168 gfc_resolve_character_operator (gfc_expr
*e
)
5170 gfc_expr
*op1
= e
->value
.op
.op1
;
5171 gfc_expr
*op2
= e
->value
.op
.op2
;
5172 gfc_expr
*e1
= NULL
;
5173 gfc_expr
*e2
= NULL
;
5175 gcc_assert (e
->value
.op
.op
== INTRINSIC_CONCAT
);
5177 if (op1
->ts
.u
.cl
&& op1
->ts
.u
.cl
->length
)
5178 e1
= gfc_copy_expr (op1
->ts
.u
.cl
->length
);
5179 else if (op1
->expr_type
== EXPR_CONSTANT
)
5180 e1
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
5181 op1
->value
.character
.length
);
5183 if (op2
->ts
.u
.cl
&& op2
->ts
.u
.cl
->length
)
5184 e2
= gfc_copy_expr (op2
->ts
.u
.cl
->length
);
5185 else if (op2
->expr_type
== EXPR_CONSTANT
)
5186 e2
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
5187 op2
->value
.character
.length
);
5189 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5199 e
->ts
.u
.cl
->length
= gfc_add (e1
, e2
);
5200 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
5201 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
5202 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 0);
5203 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
5209 /* Ensure that an character expression has a charlen and, if possible, a
5210 length expression. */
5213 fixup_charlen (gfc_expr
*e
)
5215 /* The cases fall through so that changes in expression type and the need
5216 for multiple fixes are picked up. In all circumstances, a charlen should
5217 be available for the middle end to hang a backend_decl on. */
5218 switch (e
->expr_type
)
5221 gfc_resolve_character_operator (e
);
5224 if (e
->expr_type
== EXPR_ARRAY
)
5225 gfc_resolve_character_array_constructor (e
);
5227 case EXPR_SUBSTRING
:
5228 if (!e
->ts
.u
.cl
&& e
->ref
)
5229 gfc_resolve_substring_charlen (e
);
5233 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5240 /* Update an actual argument to include the passed-object for type-bound
5241 procedures at the right position. */
5243 static gfc_actual_arglist
*
5244 update_arglist_pass (gfc_actual_arglist
* lst
, gfc_expr
* po
, unsigned argpos
,
5247 gcc_assert (argpos
> 0);
5251 gfc_actual_arglist
* result
;
5253 result
= gfc_get_actual_arglist ();
5257 result
->name
= name
;
5263 lst
->next
= update_arglist_pass (lst
->next
, po
, argpos
- 1, name
);
5265 lst
= update_arglist_pass (NULL
, po
, argpos
- 1, name
);
5270 /* Extract the passed-object from an EXPR_COMPCALL (a copy of it). */
5273 extract_compcall_passed_object (gfc_expr
* e
)
5277 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5279 if (e
->value
.compcall
.base_object
)
5280 po
= gfc_copy_expr (e
->value
.compcall
.base_object
);
5283 po
= gfc_get_expr ();
5284 po
->expr_type
= EXPR_VARIABLE
;
5285 po
->symtree
= e
->symtree
;
5286 po
->ref
= gfc_copy_ref (e
->ref
);
5287 po
->where
= e
->where
;
5290 if (!gfc_resolve_expr (po
))
5297 /* Update the arglist of an EXPR_COMPCALL expression to include the
5301 update_compcall_arglist (gfc_expr
* e
)
5304 gfc_typebound_proc
* tbp
;
5306 tbp
= e
->value
.compcall
.tbp
;
5311 po
= extract_compcall_passed_object (e
);
5315 if (tbp
->nopass
|| e
->value
.compcall
.ignore_pass
)
5321 gcc_assert (tbp
->pass_arg_num
> 0);
5322 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5330 /* Extract the passed object from a PPC call (a copy of it). */
5333 extract_ppc_passed_object (gfc_expr
*e
)
5338 po
= gfc_get_expr ();
5339 po
->expr_type
= EXPR_VARIABLE
;
5340 po
->symtree
= e
->symtree
;
5341 po
->ref
= gfc_copy_ref (e
->ref
);
5342 po
->where
= e
->where
;
5344 /* Remove PPC reference. */
5346 while ((*ref
)->next
)
5347 ref
= &(*ref
)->next
;
5348 gfc_free_ref_list (*ref
);
5351 if (!gfc_resolve_expr (po
))
5358 /* Update the actual arglist of a procedure pointer component to include the
5362 update_ppc_arglist (gfc_expr
* e
)
5366 gfc_typebound_proc
* tb
;
5368 ppc
= gfc_get_proc_ptr_comp (e
);
5376 else if (tb
->nopass
)
5379 po
= extract_ppc_passed_object (e
);
5386 gfc_error ("Passed-object at %L must be scalar", &e
->where
);
5391 if (po
->ts
.type
== BT_DERIVED
&& po
->ts
.u
.derived
->attr
.abstract
)
5393 gfc_error ("Base object for procedure-pointer component call at %L is of"
5394 " ABSTRACT type '%s'", &e
->where
, po
->ts
.u
.derived
->name
);
5398 gcc_assert (tb
->pass_arg_num
> 0);
5399 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
5407 /* Check that the object a TBP is called on is valid, i.e. it must not be
5408 of ABSTRACT type (as in subobject%abstract_parent%tbp()). */
5411 check_typebound_baseobject (gfc_expr
* e
)
5414 bool return_value
= false;
5416 base
= extract_compcall_passed_object (e
);
5420 gcc_assert (base
->ts
.type
== BT_DERIVED
|| base
->ts
.type
== BT_CLASS
);
5422 if (base
->ts
.type
== BT_CLASS
&& !gfc_expr_attr (base
).class_ok
)
5426 if (base
->ts
.type
== BT_DERIVED
&& base
->ts
.u
.derived
->attr
.abstract
)
5428 gfc_error ("Base object for type-bound procedure call at %L is of"
5429 " ABSTRACT type '%s'", &e
->where
, base
->ts
.u
.derived
->name
);
5433 /* F08:C1230. If the procedure called is NOPASS,
5434 the base object must be scalar. */
5435 if (e
->value
.compcall
.tbp
->nopass
&& base
->rank
!= 0)
5437 gfc_error ("Base object for NOPASS type-bound procedure call at %L must"
5438 " be scalar", &e
->where
);
5442 return_value
= true;
5445 gfc_free_expr (base
);
5446 return return_value
;
5450 /* Resolve a call to a type-bound procedure, either function or subroutine,
5451 statically from the data in an EXPR_COMPCALL expression. The adapted
5452 arglist and the target-procedure symtree are returned. */
5455 resolve_typebound_static (gfc_expr
* e
, gfc_symtree
** target
,
5456 gfc_actual_arglist
** actual
)
5458 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5459 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5461 /* Update the actual arglist for PASS. */
5462 if (!update_compcall_arglist (e
))
5465 *actual
= e
->value
.compcall
.actual
;
5466 *target
= e
->value
.compcall
.tbp
->u
.specific
;
5468 gfc_free_ref_list (e
->ref
);
5470 e
->value
.compcall
.actual
= NULL
;
5472 /* If we find a deferred typebound procedure, check for derived types
5473 that an overriding typebound procedure has not been missed. */
5474 if (e
->value
.compcall
.name
5475 && !e
->value
.compcall
.tbp
->non_overridable
5476 && e
->value
.compcall
.base_object
5477 && e
->value
.compcall
.base_object
->ts
.type
== BT_DERIVED
)
5480 gfc_symbol
*derived
;
5482 /* Use the derived type of the base_object. */
5483 derived
= e
->value
.compcall
.base_object
->ts
.u
.derived
;
5486 /* If necessary, go through the inheritance chain. */
5487 while (!st
&& derived
)
5489 /* Look for the typebound procedure 'name'. */
5490 if (derived
->f2k_derived
&& derived
->f2k_derived
->tb_sym_root
)
5491 st
= gfc_find_symtree (derived
->f2k_derived
->tb_sym_root
,
5492 e
->value
.compcall
.name
);
5494 derived
= gfc_get_derived_super_type (derived
);
5497 /* Now find the specific name in the derived type namespace. */
5498 if (st
&& st
->n
.tb
&& st
->n
.tb
->u
.specific
)
5499 gfc_find_sym_tree (st
->n
.tb
->u
.specific
->name
,
5500 derived
->ns
, 1, &st
);
5508 /* Get the ultimate declared type from an expression. In addition,
5509 return the last class/derived type reference and the copy of the
5510 reference list. If check_types is set true, derived types are
5511 identified as well as class references. */
5513 get_declared_from_expr (gfc_ref
**class_ref
, gfc_ref
**new_ref
,
5514 gfc_expr
*e
, bool check_types
)
5516 gfc_symbol
*declared
;
5523 *new_ref
= gfc_copy_ref (e
->ref
);
5525 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5527 if (ref
->type
!= REF_COMPONENT
)
5530 if ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
5531 || (check_types
&& ref
->u
.c
.component
->ts
.type
== BT_DERIVED
))
5532 && ref
->u
.c
.component
->attr
.flavor
!= FL_PROCEDURE
)
5534 declared
= ref
->u
.c
.component
->ts
.u
.derived
;
5540 if (declared
== NULL
)
5541 declared
= e
->symtree
->n
.sym
->ts
.u
.derived
;
5547 /* Given an EXPR_COMPCALL calling a GENERIC typebound procedure, figure out
5548 which of the specific bindings (if any) matches the arglist and transform
5549 the expression into a call of that binding. */
5552 resolve_typebound_generic_call (gfc_expr
* e
, const char **name
)
5554 gfc_typebound_proc
* genproc
;
5555 const char* genname
;
5557 gfc_symbol
*derived
;
5559 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
5560 genname
= e
->value
.compcall
.name
;
5561 genproc
= e
->value
.compcall
.tbp
;
5563 if (!genproc
->is_generic
)
5566 /* Try the bindings on this type and in the inheritance hierarchy. */
5567 for (; genproc
; genproc
= genproc
->overridden
)
5571 gcc_assert (genproc
->is_generic
);
5572 for (g
= genproc
->u
.generic
; g
; g
= g
->next
)
5575 gfc_actual_arglist
* args
;
5578 gcc_assert (g
->specific
);
5580 if (g
->specific
->error
)
5583 target
= g
->specific
->u
.specific
->n
.sym
;
5585 /* Get the right arglist by handling PASS/NOPASS. */
5586 args
= gfc_copy_actual_arglist (e
->value
.compcall
.actual
);
5587 if (!g
->specific
->nopass
)
5590 po
= extract_compcall_passed_object (e
);
5593 gfc_free_actual_arglist (args
);
5597 gcc_assert (g
->specific
->pass_arg_num
> 0);
5598 gcc_assert (!g
->specific
->error
);
5599 args
= update_arglist_pass (args
, po
, g
->specific
->pass_arg_num
,
5600 g
->specific
->pass_arg
);
5602 resolve_actual_arglist (args
, target
->attr
.proc
,
5603 is_external_proc (target
)
5604 && gfc_sym_get_dummy_args (target
) == NULL
);
5606 /* Check if this arglist matches the formal. */
5607 matches
= gfc_arglist_matches_symbol (&args
, target
);
5609 /* Clean up and break out of the loop if we've found it. */
5610 gfc_free_actual_arglist (args
);
5613 e
->value
.compcall
.tbp
= g
->specific
;
5614 genname
= g
->specific_st
->name
;
5615 /* Pass along the name for CLASS methods, where the vtab
5616 procedure pointer component has to be referenced. */
5624 /* Nothing matching found! */
5625 gfc_error ("Found no matching specific binding for the call to the GENERIC"
5626 " '%s' at %L", genname
, &e
->where
);
5630 /* Make sure that we have the right specific instance for the name. */
5631 derived
= get_declared_from_expr (NULL
, NULL
, e
, true);
5633 st
= gfc_find_typebound_proc (derived
, NULL
, genname
, true, &e
->where
);
5635 e
->value
.compcall
.tbp
= st
->n
.tb
;
5641 /* Resolve a call to a type-bound subroutine. */
5644 resolve_typebound_call (gfc_code
* c
, const char **name
)
5646 gfc_actual_arglist
* newactual
;
5647 gfc_symtree
* target
;
5649 /* Check that's really a SUBROUTINE. */
5650 if (!c
->expr1
->value
.compcall
.tbp
->subroutine
)
5652 gfc_error ("'%s' at %L should be a SUBROUTINE",
5653 c
->expr1
->value
.compcall
.name
, &c
->loc
);
5657 if (!check_typebound_baseobject (c
->expr1
))
5660 /* Pass along the name for CLASS methods, where the vtab
5661 procedure pointer component has to be referenced. */
5663 *name
= c
->expr1
->value
.compcall
.name
;
5665 if (!resolve_typebound_generic_call (c
->expr1
, name
))
5668 /* Transform into an ordinary EXEC_CALL for now. */
5670 if (!resolve_typebound_static (c
->expr1
, &target
, &newactual
))
5673 c
->ext
.actual
= newactual
;
5674 c
->symtree
= target
;
5675 c
->op
= (c
->expr1
->value
.compcall
.assign
? EXEC_ASSIGN_CALL
: EXEC_CALL
);
5677 gcc_assert (!c
->expr1
->ref
&& !c
->expr1
->value
.compcall
.actual
);
5679 gfc_free_expr (c
->expr1
);
5680 c
->expr1
= gfc_get_expr ();
5681 c
->expr1
->expr_type
= EXPR_FUNCTION
;
5682 c
->expr1
->symtree
= target
;
5683 c
->expr1
->where
= c
->loc
;
5685 return resolve_call (c
);
5689 /* Resolve a component-call expression. */
5691 resolve_compcall (gfc_expr
* e
, const char **name
)
5693 gfc_actual_arglist
* newactual
;
5694 gfc_symtree
* target
;
5696 /* Check that's really a FUNCTION. */
5697 if (!e
->value
.compcall
.tbp
->function
)
5699 gfc_error ("'%s' at %L should be a FUNCTION",
5700 e
->value
.compcall
.name
, &e
->where
);
5704 /* These must not be assign-calls! */
5705 gcc_assert (!e
->value
.compcall
.assign
);
5707 if (!check_typebound_baseobject (e
))
5710 /* Pass along the name for CLASS methods, where the vtab
5711 procedure pointer component has to be referenced. */
5713 *name
= e
->value
.compcall
.name
;
5715 if (!resolve_typebound_generic_call (e
, name
))
5717 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
5719 /* Take the rank from the function's symbol. */
5720 if (e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
)
5721 e
->rank
= e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
->rank
;
5723 /* For now, we simply transform it into an EXPR_FUNCTION call with the same
5724 arglist to the TBP's binding target. */
5726 if (!resolve_typebound_static (e
, &target
, &newactual
))
5729 e
->value
.function
.actual
= newactual
;
5730 e
->value
.function
.name
= NULL
;
5731 e
->value
.function
.esym
= target
->n
.sym
;
5732 e
->value
.function
.isym
= NULL
;
5733 e
->symtree
= target
;
5734 e
->ts
= target
->n
.sym
->ts
;
5735 e
->expr_type
= EXPR_FUNCTION
;
5737 /* Resolution is not necessary if this is a class subroutine; this
5738 function only has to identify the specific proc. Resolution of
5739 the call will be done next in resolve_typebound_call. */
5740 return gfc_resolve_expr (e
);
5744 static bool resolve_fl_derived (gfc_symbol
*sym
);
5747 /* Resolve a typebound function, or 'method'. First separate all
5748 the non-CLASS references by calling resolve_compcall directly. */
5751 resolve_typebound_function (gfc_expr
* e
)
5753 gfc_symbol
*declared
;
5765 /* Deal with typebound operators for CLASS objects. */
5766 expr
= e
->value
.compcall
.base_object
;
5767 overridable
= !e
->value
.compcall
.tbp
->non_overridable
;
5768 if (expr
&& expr
->ts
.type
== BT_CLASS
&& e
->value
.compcall
.name
)
5770 /* If the base_object is not a variable, the corresponding actual
5771 argument expression must be stored in e->base_expression so
5772 that the corresponding tree temporary can be used as the base
5773 object in gfc_conv_procedure_call. */
5774 if (expr
->expr_type
!= EXPR_VARIABLE
)
5776 gfc_actual_arglist
*args
;
5778 for (args
= e
->value
.function
.actual
; args
; args
= args
->next
)
5780 if (expr
== args
->expr
)
5785 /* Since the typebound operators are generic, we have to ensure
5786 that any delays in resolution are corrected and that the vtab
5789 declared
= ts
.u
.derived
;
5790 c
= gfc_find_component (declared
, "_vptr", true, true);
5791 if (c
->ts
.u
.derived
== NULL
)
5792 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
5794 if (!resolve_compcall (e
, &name
))
5797 /* Use the generic name if it is there. */
5798 name
= name
? name
: e
->value
.function
.esym
->name
;
5799 e
->symtree
= expr
->symtree
;
5800 e
->ref
= gfc_copy_ref (expr
->ref
);
5801 get_declared_from_expr (&class_ref
, NULL
, e
, false);
5803 /* Trim away the extraneous references that emerge from nested
5804 use of interface.c (extend_expr). */
5805 if (class_ref
&& class_ref
->next
)
5807 gfc_free_ref_list (class_ref
->next
);
5808 class_ref
->next
= NULL
;
5810 else if (e
->ref
&& !class_ref
)
5812 gfc_free_ref_list (e
->ref
);
5816 gfc_add_vptr_component (e
);
5817 gfc_add_component_ref (e
, name
);
5818 e
->value
.function
.esym
= NULL
;
5819 if (expr
->expr_type
!= EXPR_VARIABLE
)
5820 e
->base_expr
= expr
;
5825 return resolve_compcall (e
, NULL
);
5827 if (!resolve_ref (e
))
5830 /* Get the CLASS declared type. */
5831 declared
= get_declared_from_expr (&class_ref
, &new_ref
, e
, true);
5833 if (!resolve_fl_derived (declared
))
5836 /* Weed out cases of the ultimate component being a derived type. */
5837 if ((class_ref
&& class_ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
5838 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
5840 gfc_free_ref_list (new_ref
);
5841 return resolve_compcall (e
, NULL
);
5844 c
= gfc_find_component (declared
, "_data", true, true);
5845 declared
= c
->ts
.u
.derived
;
5847 /* Treat the call as if it is a typebound procedure, in order to roll
5848 out the correct name for the specific function. */
5849 if (!resolve_compcall (e
, &name
))
5851 gfc_free_ref_list (new_ref
);
5858 /* Convert the expression to a procedure pointer component call. */
5859 e
->value
.function
.esym
= NULL
;
5865 /* '_vptr' points to the vtab, which contains the procedure pointers. */
5866 gfc_add_vptr_component (e
);
5867 gfc_add_component_ref (e
, name
);
5869 /* Recover the typespec for the expression. This is really only
5870 necessary for generic procedures, where the additional call
5871 to gfc_add_component_ref seems to throw the collection of the
5872 correct typespec. */
5876 gfc_free_ref_list (new_ref
);
5881 /* Resolve a typebound subroutine, or 'method'. First separate all
5882 the non-CLASS references by calling resolve_typebound_call
5886 resolve_typebound_subroutine (gfc_code
*code
)
5888 gfc_symbol
*declared
;
5898 st
= code
->expr1
->symtree
;
5900 /* Deal with typebound operators for CLASS objects. */
5901 expr
= code
->expr1
->value
.compcall
.base_object
;
5902 overridable
= !code
->expr1
->value
.compcall
.tbp
->non_overridable
;
5903 if (expr
&& expr
->ts
.type
== BT_CLASS
&& code
->expr1
->value
.compcall
.name
)
5905 /* If the base_object is not a variable, the corresponding actual
5906 argument expression must be stored in e->base_expression so
5907 that the corresponding tree temporary can be used as the base
5908 object in gfc_conv_procedure_call. */
5909 if (expr
->expr_type
!= EXPR_VARIABLE
)
5911 gfc_actual_arglist
*args
;
5913 args
= code
->expr1
->value
.function
.actual
;
5914 for (; args
; args
= args
->next
)
5915 if (expr
== args
->expr
)
5919 /* Since the typebound operators are generic, we have to ensure
5920 that any delays in resolution are corrected and that the vtab
5922 declared
= expr
->ts
.u
.derived
;
5923 c
= gfc_find_component (declared
, "_vptr", true, true);
5924 if (c
->ts
.u
.derived
== NULL
)
5925 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
5927 if (!resolve_typebound_call (code
, &name
))
5930 /* Use the generic name if it is there. */
5931 name
= name
? name
: code
->expr1
->value
.function
.esym
->name
;
5932 code
->expr1
->symtree
= expr
->symtree
;
5933 code
->expr1
->ref
= gfc_copy_ref (expr
->ref
);
5935 /* Trim away the extraneous references that emerge from nested
5936 use of interface.c (extend_expr). */
5937 get_declared_from_expr (&class_ref
, NULL
, code
->expr1
, false);
5938 if (class_ref
&& class_ref
->next
)
5940 gfc_free_ref_list (class_ref
->next
);
5941 class_ref
->next
= NULL
;
5943 else if (code
->expr1
->ref
&& !class_ref
)
5945 gfc_free_ref_list (code
->expr1
->ref
);
5946 code
->expr1
->ref
= NULL
;
5949 /* Now use the procedure in the vtable. */
5950 gfc_add_vptr_component (code
->expr1
);
5951 gfc_add_component_ref (code
->expr1
, name
);
5952 code
->expr1
->value
.function
.esym
= NULL
;
5953 if (expr
->expr_type
!= EXPR_VARIABLE
)
5954 code
->expr1
->base_expr
= expr
;
5959 return resolve_typebound_call (code
, NULL
);
5961 if (!resolve_ref (code
->expr1
))
5964 /* Get the CLASS declared type. */
5965 get_declared_from_expr (&class_ref
, &new_ref
, code
->expr1
, true);
5967 /* Weed out cases of the ultimate component being a derived type. */
5968 if ((class_ref
&& class_ref
->u
.c
.component
->ts
.type
== BT_DERIVED
)
5969 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
5971 gfc_free_ref_list (new_ref
);
5972 return resolve_typebound_call (code
, NULL
);
5975 if (!resolve_typebound_call (code
, &name
))
5977 gfc_free_ref_list (new_ref
);
5980 ts
= code
->expr1
->ts
;
5984 /* Convert the expression to a procedure pointer component call. */
5985 code
->expr1
->value
.function
.esym
= NULL
;
5986 code
->expr1
->symtree
= st
;
5989 code
->expr1
->ref
= new_ref
;
5991 /* '_vptr' points to the vtab, which contains the procedure pointers. */
5992 gfc_add_vptr_component (code
->expr1
);
5993 gfc_add_component_ref (code
->expr1
, name
);
5995 /* Recover the typespec for the expression. This is really only
5996 necessary for generic procedures, where the additional call
5997 to gfc_add_component_ref seems to throw the collection of the
5998 correct typespec. */
5999 code
->expr1
->ts
= ts
;
6002 gfc_free_ref_list (new_ref
);
6008 /* Resolve a CALL to a Procedure Pointer Component (Subroutine). */
6011 resolve_ppc_call (gfc_code
* c
)
6013 gfc_component
*comp
;
6015 comp
= gfc_get_proc_ptr_comp (c
->expr1
);
6016 gcc_assert (comp
!= NULL
);
6018 c
->resolved_sym
= c
->expr1
->symtree
->n
.sym
;
6019 c
->expr1
->expr_type
= EXPR_VARIABLE
;
6021 if (!comp
->attr
.subroutine
)
6022 gfc_add_subroutine (&comp
->attr
, comp
->name
, &c
->expr1
->where
);
6024 if (!resolve_ref (c
->expr1
))
6027 if (!update_ppc_arglist (c
->expr1
))
6030 c
->ext
.actual
= c
->expr1
->value
.compcall
.actual
;
6032 if (!resolve_actual_arglist (c
->ext
.actual
, comp
->attr
.proc
,
6033 !(comp
->ts
.interface
6034 && comp
->ts
.interface
->formal
)))
6037 gfc_ppc_use (comp
, &c
->expr1
->value
.compcall
.actual
, &c
->expr1
->where
);
6043 /* Resolve a Function Call to a Procedure Pointer Component (Function). */
6046 resolve_expr_ppc (gfc_expr
* e
)
6048 gfc_component
*comp
;
6050 comp
= gfc_get_proc_ptr_comp (e
);
6051 gcc_assert (comp
!= NULL
);
6053 /* Convert to EXPR_FUNCTION. */
6054 e
->expr_type
= EXPR_FUNCTION
;
6055 e
->value
.function
.isym
= NULL
;
6056 e
->value
.function
.actual
= e
->value
.compcall
.actual
;
6058 if (comp
->as
!= NULL
)
6059 e
->rank
= comp
->as
->rank
;
6061 if (!comp
->attr
.function
)
6062 gfc_add_function (&comp
->attr
, comp
->name
, &e
->where
);
6064 if (!resolve_ref (e
))
6067 if (!resolve_actual_arglist (e
->value
.function
.actual
, comp
->attr
.proc
,
6068 !(comp
->ts
.interface
6069 && comp
->ts
.interface
->formal
)))
6072 if (!update_ppc_arglist (e
))
6075 gfc_ppc_use (comp
, &e
->value
.compcall
.actual
, &e
->where
);
6082 gfc_is_expandable_expr (gfc_expr
*e
)
6084 gfc_constructor
*con
;
6086 if (e
->expr_type
== EXPR_ARRAY
)
6088 /* Traverse the constructor looking for variables that are flavor
6089 parameter. Parameters must be expanded since they are fully used at
6091 con
= gfc_constructor_first (e
->value
.constructor
);
6092 for (; con
; con
= gfc_constructor_next (con
))
6094 if (con
->expr
->expr_type
== EXPR_VARIABLE
6095 && con
->expr
->symtree
6096 && (con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
6097 || con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_VARIABLE
))
6099 if (con
->expr
->expr_type
== EXPR_ARRAY
6100 && gfc_is_expandable_expr (con
->expr
))
6108 /* Resolve an expression. That is, make sure that types of operands agree
6109 with their operators, intrinsic operators are converted to function calls
6110 for overloaded types and unresolved function references are resolved. */
6113 gfc_resolve_expr (gfc_expr
*e
)
6116 bool inquiry_save
, actual_arg_save
, first_actual_arg_save
;
6121 /* inquiry_argument only applies to variables. */
6122 inquiry_save
= inquiry_argument
;
6123 actual_arg_save
= actual_arg
;
6124 first_actual_arg_save
= first_actual_arg
;
6126 if (e
->expr_type
!= EXPR_VARIABLE
)
6128 inquiry_argument
= false;
6130 first_actual_arg
= false;
6133 switch (e
->expr_type
)
6136 t
= resolve_operator (e
);
6142 if (check_host_association (e
))
6143 t
= resolve_function (e
);
6145 t
= resolve_variable (e
);
6147 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.u
.cl
== NULL
&& e
->ref
6148 && e
->ref
->type
!= REF_SUBSTRING
)
6149 gfc_resolve_substring_charlen (e
);
6154 t
= resolve_typebound_function (e
);
6157 case EXPR_SUBSTRING
:
6158 t
= resolve_ref (e
);
6167 t
= resolve_expr_ppc (e
);
6172 if (!resolve_ref (e
))
6175 t
= gfc_resolve_array_constructor (e
);
6176 /* Also try to expand a constructor. */
6179 expression_rank (e
);
6180 if (gfc_is_constant_expr (e
) || gfc_is_expandable_expr (e
))
6181 gfc_expand_constructor (e
, false);
6184 /* This provides the opportunity for the length of constructors with
6185 character valued function elements to propagate the string length
6186 to the expression. */
6187 if (t
&& e
->ts
.type
== BT_CHARACTER
)
6189 /* For efficiency, we call gfc_expand_constructor for BT_CHARACTER
6190 here rather then add a duplicate test for it above. */
6191 gfc_expand_constructor (e
, false);
6192 t
= gfc_resolve_character_array_constructor (e
);
6197 case EXPR_STRUCTURE
:
6198 t
= resolve_ref (e
);
6202 t
= resolve_structure_cons (e
, 0);
6206 t
= gfc_simplify_expr (e
, 0);
6210 gfc_internal_error ("gfc_resolve_expr(): Bad expression type");
6213 if (e
->ts
.type
== BT_CHARACTER
&& t
&& !e
->ts
.u
.cl
)
6216 inquiry_argument
= inquiry_save
;
6217 actual_arg
= actual_arg_save
;
6218 first_actual_arg
= first_actual_arg_save
;
6224 /* Resolve an expression from an iterator. They must be scalar and have
6225 INTEGER or (optionally) REAL type. */
6228 gfc_resolve_iterator_expr (gfc_expr
*expr
, bool real_ok
,
6229 const char *name_msgid
)
6231 if (!gfc_resolve_expr (expr
))
6234 if (expr
->rank
!= 0)
6236 gfc_error ("%s at %L must be a scalar", _(name_msgid
), &expr
->where
);
6240 if (expr
->ts
.type
!= BT_INTEGER
)
6242 if (expr
->ts
.type
== BT_REAL
)
6245 return gfc_notify_std (GFC_STD_F95_DEL
,
6246 "%s at %L must be integer",
6247 _(name_msgid
), &expr
->where
);
6250 gfc_error ("%s at %L must be INTEGER", _(name_msgid
),
6257 gfc_error ("%s at %L must be INTEGER", _(name_msgid
), &expr
->where
);
6265 /* Resolve the expressions in an iterator structure. If REAL_OK is
6266 false allow only INTEGER type iterators, otherwise allow REAL types.
6267 Set own_scope to true for ac-implied-do and data-implied-do as those
6268 have a separate scope such that, e.g., a INTENT(IN) doesn't apply. */
6271 gfc_resolve_iterator (gfc_iterator
*iter
, bool real_ok
, bool own_scope
)
6273 if (!gfc_resolve_iterator_expr (iter
->var
, real_ok
, "Loop variable"))
6276 if (!gfc_check_vardef_context (iter
->var
, false, false, own_scope
,
6277 _("iterator variable")))
6280 if (!gfc_resolve_iterator_expr (iter
->start
, real_ok
,
6281 "Start expression in DO loop"))
6284 if (!gfc_resolve_iterator_expr (iter
->end
, real_ok
,
6285 "End expression in DO loop"))
6288 if (!gfc_resolve_iterator_expr (iter
->step
, real_ok
,
6289 "Step expression in DO loop"))
6292 if (iter
->step
->expr_type
== EXPR_CONSTANT
)
6294 if ((iter
->step
->ts
.type
== BT_INTEGER
6295 && mpz_cmp_ui (iter
->step
->value
.integer
, 0) == 0)
6296 || (iter
->step
->ts
.type
== BT_REAL
6297 && mpfr_sgn (iter
->step
->value
.real
) == 0))
6299 gfc_error ("Step expression in DO loop at %L cannot be zero",
6300 &iter
->step
->where
);
6305 /* Convert start, end, and step to the same type as var. */
6306 if (iter
->start
->ts
.kind
!= iter
->var
->ts
.kind
6307 || iter
->start
->ts
.type
!= iter
->var
->ts
.type
)
6308 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 2);
6310 if (iter
->end
->ts
.kind
!= iter
->var
->ts
.kind
6311 || iter
->end
->ts
.type
!= iter
->var
->ts
.type
)
6312 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 2);
6314 if (iter
->step
->ts
.kind
!= iter
->var
->ts
.kind
6315 || iter
->step
->ts
.type
!= iter
->var
->ts
.type
)
6316 gfc_convert_type (iter
->step
, &iter
->var
->ts
, 2);
6318 if (iter
->start
->expr_type
== EXPR_CONSTANT
6319 && iter
->end
->expr_type
== EXPR_CONSTANT
6320 && iter
->step
->expr_type
== EXPR_CONSTANT
)
6323 if (iter
->start
->ts
.type
== BT_INTEGER
)
6325 sgn
= mpz_cmp_ui (iter
->step
->value
.integer
, 0);
6326 cmp
= mpz_cmp (iter
->end
->value
.integer
, iter
->start
->value
.integer
);
6330 sgn
= mpfr_sgn (iter
->step
->value
.real
);
6331 cmp
= mpfr_cmp (iter
->end
->value
.real
, iter
->start
->value
.real
);
6333 if (gfc_option
.warn_zerotrip
&&
6334 ((sgn
> 0 && cmp
< 0) || (sgn
< 0 && cmp
> 0)))
6335 gfc_warning ("DO loop at %L will be executed zero times"
6336 " (use -Wno-zerotrip to suppress)",
6337 &iter
->step
->where
);
6344 /* Traversal function for find_forall_index. f == 2 signals that
6345 that variable itself is not to be checked - only the references. */
6348 forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int *f
)
6350 if (expr
->expr_type
!= EXPR_VARIABLE
)
6353 /* A scalar assignment */
6354 if (!expr
->ref
|| *f
== 1)
6356 if (expr
->symtree
->n
.sym
== sym
)
6368 /* Check whether the FORALL index appears in the expression or not.
6369 Returns true if SYM is found in EXPR. */
6372 find_forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int f
)
6374 if (gfc_traverse_expr (expr
, sym
, forall_index
, f
))
6381 /* Resolve a list of FORALL iterators. The FORALL index-name is constrained
6382 to be a scalar INTEGER variable. The subscripts and stride are scalar
6383 INTEGERs, and if stride is a constant it must be nonzero.
6384 Furthermore "A subscript or stride in a forall-triplet-spec shall
6385 not contain a reference to any index-name in the
6386 forall-triplet-spec-list in which it appears." (7.5.4.1) */
6389 resolve_forall_iterators (gfc_forall_iterator
*it
)
6391 gfc_forall_iterator
*iter
, *iter2
;
6393 for (iter
= it
; iter
; iter
= iter
->next
)
6395 if (gfc_resolve_expr (iter
->var
)
6396 && (iter
->var
->ts
.type
!= BT_INTEGER
|| iter
->var
->rank
!= 0))
6397 gfc_error ("FORALL index-name at %L must be a scalar INTEGER",
6400 if (gfc_resolve_expr (iter
->start
)
6401 && (iter
->start
->ts
.type
!= BT_INTEGER
|| iter
->start
->rank
!= 0))
6402 gfc_error ("FORALL start expression at %L must be a scalar INTEGER",
6403 &iter
->start
->where
);
6404 if (iter
->var
->ts
.kind
!= iter
->start
->ts
.kind
)
6405 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 1);
6407 if (gfc_resolve_expr (iter
->end
)
6408 && (iter
->end
->ts
.type
!= BT_INTEGER
|| iter
->end
->rank
!= 0))
6409 gfc_error ("FORALL end expression at %L must be a scalar INTEGER",
6411 if (iter
->var
->ts
.kind
!= iter
->end
->ts
.kind
)
6412 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 1);
6414 if (gfc_resolve_expr (iter
->stride
))
6416 if (iter
->stride
->ts
.type
!= BT_INTEGER
|| iter
->stride
->rank
!= 0)
6417 gfc_error ("FORALL stride expression at %L must be a scalar %s",
6418 &iter
->stride
->where
, "INTEGER");
6420 if (iter
->stride
->expr_type
== EXPR_CONSTANT
6421 && mpz_cmp_ui (iter
->stride
->value
.integer
, 0) == 0)
6422 gfc_error ("FORALL stride expression at %L cannot be zero",
6423 &iter
->stride
->where
);
6425 if (iter
->var
->ts
.kind
!= iter
->stride
->ts
.kind
)
6426 gfc_convert_type (iter
->stride
, &iter
->var
->ts
, 1);
6429 for (iter
= it
; iter
; iter
= iter
->next
)
6430 for (iter2
= iter
; iter2
; iter2
= iter2
->next
)
6432 if (find_forall_index (iter2
->start
, iter
->var
->symtree
->n
.sym
, 0)
6433 || find_forall_index (iter2
->end
, iter
->var
->symtree
->n
.sym
, 0)
6434 || find_forall_index (iter2
->stride
, iter
->var
->symtree
->n
.sym
, 0))
6435 gfc_error ("FORALL index '%s' may not appear in triplet "
6436 "specification at %L", iter
->var
->symtree
->name
,
6437 &iter2
->start
->where
);
6442 /* Given a pointer to a symbol that is a derived type, see if it's
6443 inaccessible, i.e. if it's defined in another module and the components are
6444 PRIVATE. The search is recursive if necessary. Returns zero if no
6445 inaccessible components are found, nonzero otherwise. */
6448 derived_inaccessible (gfc_symbol
*sym
)
6452 if (sym
->attr
.use_assoc
&& sym
->attr
.private_comp
)
6455 for (c
= sym
->components
; c
; c
= c
->next
)
6457 if (c
->ts
.type
== BT_DERIVED
&& derived_inaccessible (c
->ts
.u
.derived
))
6465 /* Resolve the argument of a deallocate expression. The expression must be
6466 a pointer or a full array. */
6469 resolve_deallocate_expr (gfc_expr
*e
)
6471 symbol_attribute attr
;
6472 int allocatable
, pointer
;
6478 if (!gfc_resolve_expr (e
))
6481 if (e
->expr_type
!= EXPR_VARIABLE
)
6484 sym
= e
->symtree
->n
.sym
;
6485 unlimited
= UNLIMITED_POLY(sym
);
6487 if (sym
->ts
.type
== BT_CLASS
)
6489 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6490 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6494 allocatable
= sym
->attr
.allocatable
;
6495 pointer
= sym
->attr
.pointer
;
6497 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6502 if (ref
->u
.ar
.type
!= AR_FULL
6503 && !(ref
->u
.ar
.type
== AR_ELEMENT
&& ref
->u
.ar
.as
->rank
== 0
6504 && ref
->u
.ar
.codimen
&& gfc_ref_this_image (ref
)))
6509 c
= ref
->u
.c
.component
;
6510 if (c
->ts
.type
== BT_CLASS
)
6512 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
6513 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
6517 allocatable
= c
->attr
.allocatable
;
6518 pointer
= c
->attr
.pointer
;
6528 attr
= gfc_expr_attr (e
);
6530 if (allocatable
== 0 && attr
.pointer
== 0 && !unlimited
)
6533 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
6539 if (gfc_is_coindexed (e
))
6541 gfc_error ("Coindexed allocatable object at %L", &e
->where
);
6546 && !gfc_check_vardef_context (e
, true, true, false,
6547 _("DEALLOCATE object")))
6549 if (!gfc_check_vardef_context (e
, false, true, false,
6550 _("DEALLOCATE object")))
6557 /* Returns true if the expression e contains a reference to the symbol sym. */
6559 sym_in_expr (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
6561 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
== sym
)
6568 gfc_find_sym_in_expr (gfc_symbol
*sym
, gfc_expr
*e
)
6570 return gfc_traverse_expr (e
, sym
, sym_in_expr
, 0);
6574 /* Given the expression node e for an allocatable/pointer of derived type to be
6575 allocated, get the expression node to be initialized afterwards (needed for
6576 derived types with default initializers, and derived types with allocatable
6577 components that need nullification.) */
6580 gfc_expr_to_initialize (gfc_expr
*e
)
6586 result
= gfc_copy_expr (e
);
6588 /* Change the last array reference from AR_ELEMENT to AR_FULL. */
6589 for (ref
= result
->ref
; ref
; ref
= ref
->next
)
6590 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
6592 ref
->u
.ar
.type
= AR_FULL
;
6594 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
6595 ref
->u
.ar
.start
[i
] = ref
->u
.ar
.end
[i
] = ref
->u
.ar
.stride
[i
] = NULL
;
6600 gfc_free_shape (&result
->shape
, result
->rank
);
6602 /* Recalculate rank, shape, etc. */
6603 gfc_resolve_expr (result
);
6608 /* If the last ref of an expression is an array ref, return a copy of the
6609 expression with that one removed. Otherwise, a copy of the original
6610 expression. This is used for allocate-expressions and pointer assignment
6611 LHS, where there may be an array specification that needs to be stripped
6612 off when using gfc_check_vardef_context. */
6615 remove_last_array_ref (gfc_expr
* e
)
6620 e2
= gfc_copy_expr (e
);
6621 for (r
= &e2
->ref
; *r
; r
= &(*r
)->next
)
6622 if ((*r
)->type
== REF_ARRAY
&& !(*r
)->next
)
6624 gfc_free_ref_list (*r
);
6633 /* Used in resolve_allocate_expr to check that a allocation-object and
6634 a source-expr are conformable. This does not catch all possible
6635 cases; in particular a runtime checking is needed. */
6638 conformable_arrays (gfc_expr
*e1
, gfc_expr
*e2
)
6641 for (tail
= e2
->ref
; tail
&& tail
->next
; tail
= tail
->next
);
6643 /* First compare rank. */
6644 if ((tail
&& e1
->rank
!= tail
->u
.ar
.as
->rank
)
6645 || (!tail
&& e1
->rank
!= e2
->rank
))
6647 gfc_error ("Source-expr at %L must be scalar or have the "
6648 "same rank as the allocate-object at %L",
6649 &e1
->where
, &e2
->where
);
6660 for (i
= 0; i
< e1
->rank
; i
++)
6662 if (tail
->u
.ar
.start
[i
] == NULL
)
6665 if (tail
->u
.ar
.end
[i
])
6667 mpz_set (s
, tail
->u
.ar
.end
[i
]->value
.integer
);
6668 mpz_sub (s
, s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6669 mpz_add_ui (s
, s
, 1);
6673 mpz_set (s
, tail
->u
.ar
.start
[i
]->value
.integer
);
6676 if (mpz_cmp (e1
->shape
[i
], s
) != 0)
6678 gfc_error ("Source-expr at %L and allocate-object at %L must "
6679 "have the same shape", &e1
->where
, &e2
->where
);
6692 /* Resolve the expression in an ALLOCATE statement, doing the additional
6693 checks to see whether the expression is OK or not. The expression must
6694 have a trailing array reference that gives the size of the array. */
6697 resolve_allocate_expr (gfc_expr
*e
, gfc_code
*code
)
6699 int i
, pointer
, allocatable
, dimension
, is_abstract
;
6703 symbol_attribute attr
;
6704 gfc_ref
*ref
, *ref2
;
6707 gfc_symbol
*sym
= NULL
;
6712 /* Mark the utmost array component as being in allocate to allow DIMEN_STAR
6713 checking of coarrays. */
6714 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6715 if (ref
->next
== NULL
)
6718 if (ref
&& ref
->type
== REF_ARRAY
)
6719 ref
->u
.ar
.in_allocate
= true;
6721 if (!gfc_resolve_expr (e
))
6724 /* Make sure the expression is allocatable or a pointer. If it is
6725 pointer, the next-to-last reference must be a pointer. */
6729 sym
= e
->symtree
->n
.sym
;
6731 /* Check whether ultimate component is abstract and CLASS. */
6734 /* Is the allocate-object unlimited polymorphic? */
6735 unlimited
= UNLIMITED_POLY(e
);
6737 if (e
->expr_type
!= EXPR_VARIABLE
)
6740 attr
= gfc_expr_attr (e
);
6741 pointer
= attr
.pointer
;
6742 dimension
= attr
.dimension
;
6743 codimension
= attr
.codimension
;
6747 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
6749 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
6750 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
6751 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
6752 codimension
= CLASS_DATA (sym
)->attr
.codimension
;
6753 is_abstract
= CLASS_DATA (sym
)->attr
.abstract
;
6757 allocatable
= sym
->attr
.allocatable
;
6758 pointer
= sym
->attr
.pointer
;
6759 dimension
= sym
->attr
.dimension
;
6760 codimension
= sym
->attr
.codimension
;
6765 for (ref
= e
->ref
; ref
; ref2
= ref
, ref
= ref
->next
)
6770 if (ref
->u
.ar
.codimen
> 0)
6773 for (n
= ref
->u
.ar
.dimen
;
6774 n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
6775 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_THIS_IMAGE
)
6782 if (ref
->next
!= NULL
)
6790 gfc_error ("Coindexed allocatable object at %L",
6795 c
= ref
->u
.c
.component
;
6796 if (c
->ts
.type
== BT_CLASS
)
6798 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
6799 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
6800 dimension
= CLASS_DATA (c
)->attr
.dimension
;
6801 codimension
= CLASS_DATA (c
)->attr
.codimension
;
6802 is_abstract
= CLASS_DATA (c
)->attr
.abstract
;
6806 allocatable
= c
->attr
.allocatable
;
6807 pointer
= c
->attr
.pointer
;
6808 dimension
= c
->attr
.dimension
;
6809 codimension
= c
->attr
.codimension
;
6810 is_abstract
= c
->attr
.abstract
;
6822 /* Check for F08:C628. */
6823 if (allocatable
== 0 && pointer
== 0 && !unlimited
)
6825 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
6830 /* Some checks for the SOURCE tag. */
6833 /* Check F03:C631. */
6834 if (!gfc_type_compatible (&e
->ts
, &code
->expr3
->ts
))
6836 gfc_error ("Type of entity at %L is type incompatible with "
6837 "source-expr at %L", &e
->where
, &code
->expr3
->where
);
6841 /* Check F03:C632 and restriction following Note 6.18. */
6842 if (code
->expr3
->rank
> 0 && !conformable_arrays (code
->expr3
, e
))
6845 /* Check F03:C633. */
6846 if (code
->expr3
->ts
.kind
!= e
->ts
.kind
&& !unlimited
)
6848 gfc_error ("The allocate-object at %L and the source-expr at %L "
6849 "shall have the same kind type parameter",
6850 &e
->where
, &code
->expr3
->where
);
6854 /* Check F2008, C642. */
6855 if (code
->expr3
->ts
.type
== BT_DERIVED
6856 && ((codimension
&& gfc_expr_attr (code
->expr3
).lock_comp
)
6857 || (code
->expr3
->ts
.u
.derived
->from_intmod
6858 == INTMOD_ISO_FORTRAN_ENV
6859 && code
->expr3
->ts
.u
.derived
->intmod_sym_id
6860 == ISOFORTRAN_LOCK_TYPE
)))
6862 gfc_error ("The source-expr at %L shall neither be of type "
6863 "LOCK_TYPE nor have a LOCK_TYPE component if "
6864 "allocate-object at %L is a coarray",
6865 &code
->expr3
->where
, &e
->where
);
6870 /* Check F08:C629. */
6871 if (is_abstract
&& code
->ext
.alloc
.ts
.type
== BT_UNKNOWN
6874 gcc_assert (e
->ts
.type
== BT_CLASS
);
6875 gfc_error ("Allocating %s of ABSTRACT base type at %L requires a "
6876 "type-spec or source-expr", sym
->name
, &e
->where
);
6880 if (code
->ext
.alloc
.ts
.type
== BT_CHARACTER
&& !e
->ts
.deferred
)
6882 int cmp
= gfc_dep_compare_expr (e
->ts
.u
.cl
->length
,
6883 code
->ext
.alloc
.ts
.u
.cl
->length
);
6884 if (cmp
== 1 || cmp
== -1 || cmp
== -3)
6886 gfc_error ("Allocating %s at %L with type-spec requires the same "
6887 "character-length parameter as in the declaration",
6888 sym
->name
, &e
->where
);
6893 /* In the variable definition context checks, gfc_expr_attr is used
6894 on the expression. This is fooled by the array specification
6895 present in e, thus we have to eliminate that one temporarily. */
6896 e2
= remove_last_array_ref (e
);
6899 t
= gfc_check_vardef_context (e2
, true, true, false,
6900 _("ALLOCATE object"));
6902 t
= gfc_check_vardef_context (e2
, false, true, false,
6903 _("ALLOCATE object"));
6908 if (e
->ts
.type
== BT_CLASS
&& CLASS_DATA (e
)->attr
.dimension
6909 && !code
->expr3
&& code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
6911 /* For class arrays, the initialization with SOURCE is done
6912 using _copy and trans_call. It is convenient to exploit that
6913 when the allocated type is different from the declared type but
6914 no SOURCE exists by setting expr3. */
6915 code
->expr3
= gfc_default_initializer (&code
->ext
.alloc
.ts
);
6917 else if (!code
->expr3
)
6919 /* Set up default initializer if needed. */
6923 if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
6924 ts
= code
->ext
.alloc
.ts
;
6928 if (ts
.type
== BT_CLASS
)
6929 ts
= ts
.u
.derived
->components
->ts
;
6931 if (ts
.type
== BT_DERIVED
&& (init_e
= gfc_default_initializer (&ts
)))
6933 gfc_code
*init_st
= gfc_get_code (EXEC_INIT_ASSIGN
);
6934 init_st
->loc
= code
->loc
;
6935 init_st
->expr1
= gfc_expr_to_initialize (e
);
6936 init_st
->expr2
= init_e
;
6937 init_st
->next
= code
->next
;
6938 code
->next
= init_st
;
6941 else if (code
->expr3
->mold
&& code
->expr3
->ts
.type
== BT_DERIVED
)
6943 /* Default initialization via MOLD (non-polymorphic). */
6944 gfc_expr
*rhs
= gfc_default_initializer (&code
->expr3
->ts
);
6945 gfc_resolve_expr (rhs
);
6946 gfc_free_expr (code
->expr3
);
6950 if (e
->ts
.type
== BT_CLASS
&& !unlimited
&& !UNLIMITED_POLY (code
->expr3
))
6952 /* Make sure the vtab symbol is present when
6953 the module variables are generated. */
6954 gfc_typespec ts
= e
->ts
;
6956 ts
= code
->expr3
->ts
;
6957 else if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
6958 ts
= code
->ext
.alloc
.ts
;
6960 gfc_find_derived_vtab (ts
.u
.derived
);
6963 e
= gfc_expr_to_initialize (e
);
6965 else if (unlimited
&& !UNLIMITED_POLY (code
->expr3
))
6967 /* Again, make sure the vtab symbol is present when
6968 the module variables are generated. */
6969 gfc_typespec
*ts
= NULL
;
6971 ts
= &code
->expr3
->ts
;
6973 ts
= &code
->ext
.alloc
.ts
;
6980 e
= gfc_expr_to_initialize (e
);
6983 if (dimension
== 0 && codimension
== 0)
6986 /* Make sure the last reference node is an array specification. */
6988 if (!ref2
|| ref2
->type
!= REF_ARRAY
|| ref2
->u
.ar
.type
== AR_FULL
6989 || (dimension
&& ref2
->u
.ar
.dimen
== 0))
6991 gfc_error ("Array specification required in ALLOCATE statement "
6992 "at %L", &e
->where
);
6996 /* Make sure that the array section reference makes sense in the
6997 context of an ALLOCATE specification. */
7002 for (i
= ar
->dimen
; i
< ar
->dimen
+ ar
->codimen
; i
++)
7003 if (ar
->dimen_type
[i
] == DIMEN_THIS_IMAGE
)
7005 gfc_error ("Coarray specification required in ALLOCATE statement "
7006 "at %L", &e
->where
);
7010 for (i
= 0; i
< ar
->dimen
; i
++)
7012 if (ref2
->u
.ar
.type
== AR_ELEMENT
)
7015 switch (ar
->dimen_type
[i
])
7021 if (ar
->start
[i
] != NULL
7022 && ar
->end
[i
] != NULL
7023 && ar
->stride
[i
] == NULL
)
7026 /* Fall Through... */
7031 case DIMEN_THIS_IMAGE
:
7032 gfc_error ("Bad array specification in ALLOCATE statement at %L",
7038 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7040 sym
= a
->expr
->symtree
->n
.sym
;
7042 /* TODO - check derived type components. */
7043 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
7046 if ((ar
->start
[i
] != NULL
7047 && gfc_find_sym_in_expr (sym
, ar
->start
[i
]))
7048 || (ar
->end
[i
] != NULL
7049 && gfc_find_sym_in_expr (sym
, ar
->end
[i
])))
7051 gfc_error ("'%s' must not appear in the array specification at "
7052 "%L in the same ALLOCATE statement where it is "
7053 "itself allocated", sym
->name
, &ar
->where
);
7059 for (i
= ar
->dimen
; i
< ar
->codimen
+ ar
->dimen
; i
++)
7061 if (ar
->dimen_type
[i
] == DIMEN_ELEMENT
7062 || ar
->dimen_type
[i
] == DIMEN_RANGE
)
7064 if (i
== (ar
->dimen
+ ar
->codimen
- 1))
7066 gfc_error ("Expected '*' in coindex specification in ALLOCATE "
7067 "statement at %L", &e
->where
);
7073 if (ar
->dimen_type
[i
] == DIMEN_STAR
&& i
== (ar
->dimen
+ ar
->codimen
- 1)
7074 && ar
->stride
[i
] == NULL
)
7077 gfc_error ("Bad coarray specification in ALLOCATE statement at %L",
7090 resolve_allocate_deallocate (gfc_code
*code
, const char *fcn
)
7092 gfc_expr
*stat
, *errmsg
, *pe
, *qe
;
7093 gfc_alloc
*a
, *p
, *q
;
7096 errmsg
= code
->expr2
;
7098 /* Check the stat variable. */
7101 gfc_check_vardef_context (stat
, false, false, false,
7102 _("STAT variable"));
7104 if ((stat
->ts
.type
!= BT_INTEGER
7105 && !(stat
->ref
&& (stat
->ref
->type
== REF_ARRAY
7106 || stat
->ref
->type
== REF_COMPONENT
)))
7108 gfc_error ("Stat-variable at %L must be a scalar INTEGER "
7109 "variable", &stat
->where
);
7111 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7112 if (p
->expr
->symtree
->n
.sym
->name
== stat
->symtree
->n
.sym
->name
)
7114 gfc_ref
*ref1
, *ref2
;
7117 for (ref1
= p
->expr
->ref
, ref2
= stat
->ref
; ref1
&& ref2
;
7118 ref1
= ref1
->next
, ref2
= ref2
->next
)
7120 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
7122 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
7131 gfc_error ("Stat-variable at %L shall not be %sd within "
7132 "the same %s statement", &stat
->where
, fcn
, fcn
);
7138 /* Check the errmsg variable. */
7142 gfc_warning ("ERRMSG at %L is useless without a STAT tag",
7145 gfc_check_vardef_context (errmsg
, false, false, false,
7146 _("ERRMSG variable"));
7148 if ((errmsg
->ts
.type
!= BT_CHARACTER
7150 && (errmsg
->ref
->type
== REF_ARRAY
7151 || errmsg
->ref
->type
== REF_COMPONENT
)))
7152 || errmsg
->rank
> 0 )
7153 gfc_error ("Errmsg-variable at %L must be a scalar CHARACTER "
7154 "variable", &errmsg
->where
);
7156 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7157 if (p
->expr
->symtree
->n
.sym
->name
== errmsg
->symtree
->n
.sym
->name
)
7159 gfc_ref
*ref1
, *ref2
;
7162 for (ref1
= p
->expr
->ref
, ref2
= errmsg
->ref
; ref1
&& ref2
;
7163 ref1
= ref1
->next
, ref2
= ref2
->next
)
7165 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
7167 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
7176 gfc_error ("Errmsg-variable at %L shall not be %sd within "
7177 "the same %s statement", &errmsg
->where
, fcn
, fcn
);
7183 /* Check that an allocate-object appears only once in the statement. */
7185 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
7188 for (q
= p
->next
; q
; q
= q
->next
)
7191 if (pe
->symtree
->n
.sym
->name
== qe
->symtree
->n
.sym
->name
)
7193 /* This is a potential collision. */
7194 gfc_ref
*pr
= pe
->ref
;
7195 gfc_ref
*qr
= qe
->ref
;
7197 /* Follow the references until
7198 a) They start to differ, in which case there is no error;
7199 you can deallocate a%b and a%c in a single statement
7200 b) Both of them stop, which is an error
7201 c) One of them stops, which is also an error. */
7204 if (pr
== NULL
&& qr
== NULL
)
7206 gfc_error ("Allocate-object at %L also appears at %L",
7207 &pe
->where
, &qe
->where
);
7210 else if (pr
!= NULL
&& qr
== NULL
)
7212 gfc_error ("Allocate-object at %L is subobject of"
7213 " object at %L", &pe
->where
, &qe
->where
);
7216 else if (pr
== NULL
&& qr
!= NULL
)
7218 gfc_error ("Allocate-object at %L is subobject of"
7219 " object at %L", &qe
->where
, &pe
->where
);
7222 /* Here, pr != NULL && qr != NULL */
7223 gcc_assert(pr
->type
== qr
->type
);
7224 if (pr
->type
== REF_ARRAY
)
7226 /* Handle cases like allocate(v(3)%x(3), v(2)%x(3)),
7228 gcc_assert (qr
->type
== REF_ARRAY
);
7230 if (pr
->next
&& qr
->next
)
7233 gfc_array_ref
*par
= &(pr
->u
.ar
);
7234 gfc_array_ref
*qar
= &(qr
->u
.ar
);
7236 for (i
=0; i
<par
->dimen
; i
++)
7238 if ((par
->start
[i
] != NULL
7239 || qar
->start
[i
] != NULL
)
7240 && gfc_dep_compare_expr (par
->start
[i
],
7241 qar
->start
[i
]) != 0)
7248 if (pr
->u
.c
.component
->name
!= qr
->u
.c
.component
->name
)
7261 if (strcmp (fcn
, "ALLOCATE") == 0)
7263 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7264 resolve_allocate_expr (a
->expr
, code
);
7268 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
7269 resolve_deallocate_expr (a
->expr
);
7274 /************ SELECT CASE resolution subroutines ************/
7276 /* Callback function for our mergesort variant. Determines interval
7277 overlaps for CASEs. Return <0 if op1 < op2, 0 for overlap, >0 for
7278 op1 > op2. Assumes we're not dealing with the default case.
7279 We have op1 = (:L), (K:L) or (K:) and op2 = (:N), (M:N) or (M:).
7280 There are nine situations to check. */
7283 compare_cases (const gfc_case
*op1
, const gfc_case
*op2
)
7287 if (op1
->low
== NULL
) /* op1 = (:L) */
7289 /* op2 = (:N), so overlap. */
7291 /* op2 = (M:) or (M:N), L < M */
7292 if (op2
->low
!= NULL
7293 && gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7296 else if (op1
->high
== NULL
) /* op1 = (K:) */
7298 /* op2 = (M:), so overlap. */
7300 /* op2 = (:N) or (M:N), K > N */
7301 if (op2
->high
!= NULL
7302 && gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7305 else /* op1 = (K:L) */
7307 if (op2
->low
== NULL
) /* op2 = (:N), K > N */
7308 retval
= (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7310 else if (op2
->high
== NULL
) /* op2 = (M:), L < M */
7311 retval
= (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7313 else /* op2 = (M:N) */
7317 if (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
7320 else if (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
7329 /* Merge-sort a double linked case list, detecting overlap in the
7330 process. LIST is the head of the double linked case list before it
7331 is sorted. Returns the head of the sorted list if we don't see any
7332 overlap, or NULL otherwise. */
7335 check_case_overlap (gfc_case
*list
)
7337 gfc_case
*p
, *q
, *e
, *tail
;
7338 int insize
, nmerges
, psize
, qsize
, cmp
, overlap_seen
;
7340 /* If the passed list was empty, return immediately. */
7347 /* Loop unconditionally. The only exit from this loop is a return
7348 statement, when we've finished sorting the case list. */
7355 /* Count the number of merges we do in this pass. */
7358 /* Loop while there exists a merge to be done. */
7363 /* Count this merge. */
7366 /* Cut the list in two pieces by stepping INSIZE places
7367 forward in the list, starting from P. */
7370 for (i
= 0; i
< insize
; i
++)
7379 /* Now we have two lists. Merge them! */
7380 while (psize
> 0 || (qsize
> 0 && q
!= NULL
))
7382 /* See from which the next case to merge comes from. */
7385 /* P is empty so the next case must come from Q. */
7390 else if (qsize
== 0 || q
== NULL
)
7399 cmp
= compare_cases (p
, q
);
7402 /* The whole case range for P is less than the
7410 /* The whole case range for Q is greater than
7411 the case range for P. */
7418 /* The cases overlap, or they are the same
7419 element in the list. Either way, we must
7420 issue an error and get the next case from P. */
7421 /* FIXME: Sort P and Q by line number. */
7422 gfc_error ("CASE label at %L overlaps with CASE "
7423 "label at %L", &p
->where
, &q
->where
);
7431 /* Add the next element to the merged list. */
7440 /* P has now stepped INSIZE places along, and so has Q. So
7441 they're the same. */
7446 /* If we have done only one merge or none at all, we've
7447 finished sorting the cases. */
7456 /* Otherwise repeat, merging lists twice the size. */
7462 /* Check to see if an expression is suitable for use in a CASE statement.
7463 Makes sure that all case expressions are scalar constants of the same
7464 type. Return false if anything is wrong. */
7467 validate_case_label_expr (gfc_expr
*e
, gfc_expr
*case_expr
)
7469 if (e
== NULL
) return true;
7471 if (e
->ts
.type
!= case_expr
->ts
.type
)
7473 gfc_error ("Expression in CASE statement at %L must be of type %s",
7474 &e
->where
, gfc_basic_typename (case_expr
->ts
.type
));
7478 /* C805 (R808) For a given case-construct, each case-value shall be of
7479 the same type as case-expr. For character type, length differences
7480 are allowed, but the kind type parameters shall be the same. */
7482 if (case_expr
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= case_expr
->ts
.kind
)
7484 gfc_error ("Expression in CASE statement at %L must be of kind %d",
7485 &e
->where
, case_expr
->ts
.kind
);
7489 /* Convert the case value kind to that of case expression kind,
7492 if (e
->ts
.kind
!= case_expr
->ts
.kind
)
7493 gfc_convert_type_warn (e
, &case_expr
->ts
, 2, 0);
7497 gfc_error ("Expression in CASE statement at %L must be scalar",
7506 /* Given a completely parsed select statement, we:
7508 - Validate all expressions and code within the SELECT.
7509 - Make sure that the selection expression is not of the wrong type.
7510 - Make sure that no case ranges overlap.
7511 - Eliminate unreachable cases and unreachable code resulting from
7512 removing case labels.
7514 The standard does allow unreachable cases, e.g. CASE (5:3). But
7515 they are a hassle for code generation, and to prevent that, we just
7516 cut them out here. This is not necessary for overlapping cases
7517 because they are illegal and we never even try to generate code.
7519 We have the additional caveat that a SELECT construct could have
7520 been a computed GOTO in the source code. Fortunately we can fairly
7521 easily work around that here: The case_expr for a "real" SELECT CASE
7522 is in code->expr1, but for a computed GOTO it is in code->expr2. All
7523 we have to do is make sure that the case_expr is a scalar integer
7527 resolve_select (gfc_code
*code
, bool select_type
)
7530 gfc_expr
*case_expr
;
7531 gfc_case
*cp
, *default_case
, *tail
, *head
;
7532 int seen_unreachable
;
7538 if (code
->expr1
== NULL
)
7540 /* This was actually a computed GOTO statement. */
7541 case_expr
= code
->expr2
;
7542 if (case_expr
->ts
.type
!= BT_INTEGER
|| case_expr
->rank
!= 0)
7543 gfc_error ("Selection expression in computed GOTO statement "
7544 "at %L must be a scalar integer expression",
7547 /* Further checking is not necessary because this SELECT was built
7548 by the compiler, so it should always be OK. Just move the
7549 case_expr from expr2 to expr so that we can handle computed
7550 GOTOs as normal SELECTs from here on. */
7551 code
->expr1
= code
->expr2
;
7556 case_expr
= code
->expr1
;
7557 type
= case_expr
->ts
.type
;
7560 if (type
!= BT_LOGICAL
&& type
!= BT_INTEGER
&& type
!= BT_CHARACTER
)
7562 gfc_error ("Argument of SELECT statement at %L cannot be %s",
7563 &case_expr
->where
, gfc_typename (&case_expr
->ts
));
7565 /* Punt. Going on here just produce more garbage error messages. */
7570 if (!select_type
&& case_expr
->rank
!= 0)
7572 gfc_error ("Argument of SELECT statement at %L must be a scalar "
7573 "expression", &case_expr
->where
);
7579 /* Raise a warning if an INTEGER case value exceeds the range of
7580 the case-expr. Later, all expressions will be promoted to the
7581 largest kind of all case-labels. */
7583 if (type
== BT_INTEGER
)
7584 for (body
= code
->block
; body
; body
= body
->block
)
7585 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7588 && gfc_check_integer_range (cp
->low
->value
.integer
,
7589 case_expr
->ts
.kind
) != ARITH_OK
)
7590 gfc_warning ("Expression in CASE statement at %L is "
7591 "not in the range of %s", &cp
->low
->where
,
7592 gfc_typename (&case_expr
->ts
));
7595 && cp
->low
!= cp
->high
7596 && gfc_check_integer_range (cp
->high
->value
.integer
,
7597 case_expr
->ts
.kind
) != ARITH_OK
)
7598 gfc_warning ("Expression in CASE statement at %L is "
7599 "not in the range of %s", &cp
->high
->where
,
7600 gfc_typename (&case_expr
->ts
));
7603 /* PR 19168 has a long discussion concerning a mismatch of the kinds
7604 of the SELECT CASE expression and its CASE values. Walk the lists
7605 of case values, and if we find a mismatch, promote case_expr to
7606 the appropriate kind. */
7608 if (type
== BT_LOGICAL
|| type
== BT_INTEGER
)
7610 for (body
= code
->block
; body
; body
= body
->block
)
7612 /* Walk the case label list. */
7613 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7615 /* Intercept the DEFAULT case. It does not have a kind. */
7616 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7619 /* Unreachable case ranges are discarded, so ignore. */
7620 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7621 && cp
->low
!= cp
->high
7622 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7626 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->low
))
7627 gfc_convert_type_warn (case_expr
, &cp
->low
->ts
, 2, 0);
7629 if (cp
->high
!= NULL
7630 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->high
))
7631 gfc_convert_type_warn (case_expr
, &cp
->high
->ts
, 2, 0);
7636 /* Assume there is no DEFAULT case. */
7637 default_case
= NULL
;
7642 for (body
= code
->block
; body
; body
= body
->block
)
7644 /* Assume the CASE list is OK, and all CASE labels can be matched. */
7646 seen_unreachable
= 0;
7648 /* Walk the case label list, making sure that all case labels
7650 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
7652 /* Count the number of cases in the whole construct. */
7655 /* Intercept the DEFAULT case. */
7656 if (cp
->low
== NULL
&& cp
->high
== NULL
)
7658 if (default_case
!= NULL
)
7660 gfc_error ("The DEFAULT CASE at %L cannot be followed "
7661 "by a second DEFAULT CASE at %L",
7662 &default_case
->where
, &cp
->where
);
7673 /* Deal with single value cases and case ranges. Errors are
7674 issued from the validation function. */
7675 if (!validate_case_label_expr (cp
->low
, case_expr
)
7676 || !validate_case_label_expr (cp
->high
, case_expr
))
7682 if (type
== BT_LOGICAL
7683 && ((cp
->low
== NULL
|| cp
->high
== NULL
)
7684 || cp
->low
!= cp
->high
))
7686 gfc_error ("Logical range in CASE statement at %L is not "
7687 "allowed", &cp
->low
->where
);
7692 if (type
== BT_LOGICAL
&& cp
->low
->expr_type
== EXPR_CONSTANT
)
7695 value
= cp
->low
->value
.logical
== 0 ? 2 : 1;
7696 if (value
& seen_logical
)
7698 gfc_error ("Constant logical value in CASE statement "
7699 "is repeated at %L",
7704 seen_logical
|= value
;
7707 if (cp
->low
!= NULL
&& cp
->high
!= NULL
7708 && cp
->low
!= cp
->high
7709 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
7711 if (gfc_option
.warn_surprising
)
7712 gfc_warning ("Range specification at %L can never "
7713 "be matched", &cp
->where
);
7715 cp
->unreachable
= 1;
7716 seen_unreachable
= 1;
7720 /* If the case range can be matched, it can also overlap with
7721 other cases. To make sure it does not, we put it in a
7722 double linked list here. We sort that with a merge sort
7723 later on to detect any overlapping cases. */
7727 head
->right
= head
->left
= NULL
;
7732 tail
->right
->left
= tail
;
7739 /* It there was a failure in the previous case label, give up
7740 for this case label list. Continue with the next block. */
7744 /* See if any case labels that are unreachable have been seen.
7745 If so, we eliminate them. This is a bit of a kludge because
7746 the case lists for a single case statement (label) is a
7747 single forward linked lists. */
7748 if (seen_unreachable
)
7750 /* Advance until the first case in the list is reachable. */
7751 while (body
->ext
.block
.case_list
!= NULL
7752 && body
->ext
.block
.case_list
->unreachable
)
7754 gfc_case
*n
= body
->ext
.block
.case_list
;
7755 body
->ext
.block
.case_list
= body
->ext
.block
.case_list
->next
;
7757 gfc_free_case_list (n
);
7760 /* Strip all other unreachable cases. */
7761 if (body
->ext
.block
.case_list
)
7763 for (cp
= body
->ext
.block
.case_list
; cp
->next
; cp
= cp
->next
)
7765 if (cp
->next
->unreachable
)
7767 gfc_case
*n
= cp
->next
;
7768 cp
->next
= cp
->next
->next
;
7770 gfc_free_case_list (n
);
7777 /* See if there were overlapping cases. If the check returns NULL,
7778 there was overlap. In that case we don't do anything. If head
7779 is non-NULL, we prepend the DEFAULT case. The sorted list can
7780 then used during code generation for SELECT CASE constructs with
7781 a case expression of a CHARACTER type. */
7784 head
= check_case_overlap (head
);
7786 /* Prepend the default_case if it is there. */
7787 if (head
!= NULL
&& default_case
)
7789 default_case
->left
= NULL
;
7790 default_case
->right
= head
;
7791 head
->left
= default_case
;
7795 /* Eliminate dead blocks that may be the result if we've seen
7796 unreachable case labels for a block. */
7797 for (body
= code
; body
&& body
->block
; body
= body
->block
)
7799 if (body
->block
->ext
.block
.case_list
== NULL
)
7801 /* Cut the unreachable block from the code chain. */
7802 gfc_code
*c
= body
->block
;
7803 body
->block
= c
->block
;
7805 /* Kill the dead block, but not the blocks below it. */
7807 gfc_free_statements (c
);
7811 /* More than two cases is legal but insane for logical selects.
7812 Issue a warning for it. */
7813 if (gfc_option
.warn_surprising
&& type
== BT_LOGICAL
7815 gfc_warning ("Logical SELECT CASE block at %L has more that two cases",
7820 /* Check if a derived type is extensible. */
7823 gfc_type_is_extensible (gfc_symbol
*sym
)
7825 return !(sym
->attr
.is_bind_c
|| sym
->attr
.sequence
7826 || (sym
->attr
.is_class
7827 && sym
->components
->ts
.u
.derived
->attr
.unlimited_polymorphic
));
7831 /* Resolve an associate-name: Resolve target and ensure the type-spec is
7832 correct as well as possibly the array-spec. */
7835 resolve_assoc_var (gfc_symbol
* sym
, bool resolve_target
)
7839 gcc_assert (sym
->assoc
);
7840 gcc_assert (sym
->attr
.flavor
== FL_VARIABLE
);
7842 /* If this is for SELECT TYPE, the target may not yet be set. In that
7843 case, return. Resolution will be called later manually again when
7845 target
= sym
->assoc
->target
;
7848 gcc_assert (!sym
->assoc
->dangling
);
7850 if (resolve_target
&& !gfc_resolve_expr (target
))
7853 /* For variable targets, we get some attributes from the target. */
7854 if (target
->expr_type
== EXPR_VARIABLE
)
7858 gcc_assert (target
->symtree
);
7859 tsym
= target
->symtree
->n
.sym
;
7861 sym
->attr
.asynchronous
= tsym
->attr
.asynchronous
;
7862 sym
->attr
.volatile_
= tsym
->attr
.volatile_
;
7864 sym
->attr
.target
= tsym
->attr
.target
7865 || gfc_expr_attr (target
).pointer
;
7866 if (is_subref_array (target
))
7867 sym
->attr
.subref_array_pointer
= 1;
7870 /* Get type if this was not already set. Note that it can be
7871 some other type than the target in case this is a SELECT TYPE
7872 selector! So we must not update when the type is already there. */
7873 if (sym
->ts
.type
== BT_UNKNOWN
)
7874 sym
->ts
= target
->ts
;
7875 gcc_assert (sym
->ts
.type
!= BT_UNKNOWN
);
7877 /* See if this is a valid association-to-variable. */
7878 sym
->assoc
->variable
= (target
->expr_type
== EXPR_VARIABLE
7879 && !gfc_has_vector_subscript (target
));
7881 /* Finally resolve if this is an array or not. */
7882 if (sym
->attr
.dimension
&& target
->rank
== 0)
7884 gfc_error ("Associate-name '%s' at %L is used as array",
7885 sym
->name
, &sym
->declared_at
);
7886 sym
->attr
.dimension
= 0;
7890 /* We cannot deal with class selectors that need temporaries. */
7891 if (target
->ts
.type
== BT_CLASS
7892 && gfc_ref_needs_temporary_p (target
->ref
))
7894 gfc_error ("CLASS selector at %L needs a temporary which is not "
7895 "yet implemented", &target
->where
);
7899 if (target
->ts
.type
!= BT_CLASS
&& target
->rank
> 0)
7900 sym
->attr
.dimension
= 1;
7901 else if (target
->ts
.type
== BT_CLASS
)
7902 gfc_fix_class_refs (target
);
7904 /* The associate-name will have a correct type by now. Make absolutely
7905 sure that it has not picked up a dimension attribute. */
7906 if (sym
->ts
.type
== BT_CLASS
)
7907 sym
->attr
.dimension
= 0;
7909 if (sym
->attr
.dimension
)
7911 sym
->as
= gfc_get_array_spec ();
7912 sym
->as
->rank
= target
->rank
;
7913 sym
->as
->type
= AS_DEFERRED
;
7915 /* Target must not be coindexed, thus the associate-variable
7917 sym
->as
->corank
= 0;
7920 /* Mark this as an associate variable. */
7921 sym
->attr
.associate_var
= 1;
7923 /* If the target is a good class object, so is the associate variable. */
7924 if (sym
->ts
.type
== BT_CLASS
&& gfc_expr_attr (target
).class_ok
)
7925 sym
->attr
.class_ok
= 1;
7929 /* Resolve a SELECT TYPE statement. */
7932 resolve_select_type (gfc_code
*code
, gfc_namespace
*old_ns
)
7934 gfc_symbol
*selector_type
;
7935 gfc_code
*body
, *new_st
, *if_st
, *tail
;
7936 gfc_code
*class_is
= NULL
, *default_case
= NULL
;
7939 char name
[GFC_MAX_SYMBOL_LEN
];
7944 ns
= code
->ext
.block
.ns
;
7947 /* Check for F03:C813. */
7948 if (code
->expr1
->ts
.type
!= BT_CLASS
7949 && !(code
->expr2
&& code
->expr2
->ts
.type
== BT_CLASS
))
7951 gfc_error ("Selector shall be polymorphic in SELECT TYPE statement "
7952 "at %L", &code
->loc
);
7956 if (!code
->expr1
->symtree
->n
.sym
->attr
.class_ok
)
7961 if (code
->expr1
->symtree
->n
.sym
->attr
.untyped
)
7962 code
->expr1
->symtree
->n
.sym
->ts
= code
->expr2
->ts
;
7963 selector_type
= CLASS_DATA (code
->expr2
)->ts
.u
.derived
;
7965 /* F2008: C803 The selector expression must not be coindexed. */
7966 if (gfc_is_coindexed (code
->expr2
))
7968 gfc_error ("Selector at %L must not be coindexed",
7969 &code
->expr2
->where
);
7976 selector_type
= CLASS_DATA (code
->expr1
)->ts
.u
.derived
;
7978 if (gfc_is_coindexed (code
->expr1
))
7980 gfc_error ("Selector at %L must not be coindexed",
7981 &code
->expr1
->where
);
7986 /* Loop over TYPE IS / CLASS IS cases. */
7987 for (body
= code
->block
; body
; body
= body
->block
)
7989 c
= body
->ext
.block
.case_list
;
7991 /* Check F03:C815. */
7992 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
7993 && !selector_type
->attr
.unlimited_polymorphic
7994 && !gfc_type_is_extensible (c
->ts
.u
.derived
))
7996 gfc_error ("Derived type '%s' at %L must be extensible",
7997 c
->ts
.u
.derived
->name
, &c
->where
);
8002 /* Check F03:C816. */
8003 if (c
->ts
.type
!= BT_UNKNOWN
&& !selector_type
->attr
.unlimited_polymorphic
8004 && ((c
->ts
.type
!= BT_DERIVED
&& c
->ts
.type
!= BT_CLASS
)
8005 || !gfc_type_is_extension_of (selector_type
, c
->ts
.u
.derived
)))
8007 if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
8008 gfc_error ("Derived type '%s' at %L must be an extension of '%s'",
8009 c
->ts
.u
.derived
->name
, &c
->where
, selector_type
->name
);
8011 gfc_error ("Unexpected intrinsic type '%s' at %L",
8012 gfc_basic_typename (c
->ts
.type
), &c
->where
);
8017 /* Check F03:C814. */
8018 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.u
.cl
->length
!= NULL
)
8020 gfc_error ("The type-spec at %L shall specify that each length "
8021 "type parameter is assumed", &c
->where
);
8026 /* Intercept the DEFAULT case. */
8027 if (c
->ts
.type
== BT_UNKNOWN
)
8029 /* Check F03:C818. */
8032 gfc_error ("The DEFAULT CASE at %L cannot be followed "
8033 "by a second DEFAULT CASE at %L",
8034 &default_case
->ext
.block
.case_list
->where
, &c
->where
);
8039 default_case
= body
;
8046 /* Transform SELECT TYPE statement to BLOCK and associate selector to
8047 target if present. If there are any EXIT statements referring to the
8048 SELECT TYPE construct, this is no problem because the gfc_code
8049 reference stays the same and EXIT is equally possible from the BLOCK
8050 it is changed to. */
8051 code
->op
= EXEC_BLOCK
;
8054 gfc_association_list
* assoc
;
8056 assoc
= gfc_get_association_list ();
8057 assoc
->st
= code
->expr1
->symtree
;
8058 assoc
->target
= gfc_copy_expr (code
->expr2
);
8059 assoc
->target
->where
= code
->expr2
->where
;
8060 /* assoc->variable will be set by resolve_assoc_var. */
8062 code
->ext
.block
.assoc
= assoc
;
8063 code
->expr1
->symtree
->n
.sym
->assoc
= assoc
;
8065 resolve_assoc_var (code
->expr1
->symtree
->n
.sym
, false);
8068 code
->ext
.block
.assoc
= NULL
;
8070 /* Add EXEC_SELECT to switch on type. */
8071 new_st
= gfc_get_code (code
->op
);
8072 new_st
->expr1
= code
->expr1
;
8073 new_st
->expr2
= code
->expr2
;
8074 new_st
->block
= code
->block
;
8075 code
->expr1
= code
->expr2
= NULL
;
8080 ns
->code
->next
= new_st
;
8082 code
->op
= EXEC_SELECT
;
8084 gfc_add_vptr_component (code
->expr1
);
8085 gfc_add_hash_component (code
->expr1
);
8087 /* Loop over TYPE IS / CLASS IS cases. */
8088 for (body
= code
->block
; body
; body
= body
->block
)
8090 c
= body
->ext
.block
.case_list
;
8092 if (c
->ts
.type
== BT_DERIVED
)
8093 c
->low
= c
->high
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
,
8094 c
->ts
.u
.derived
->hash_value
);
8095 else if (c
->ts
.type
!= BT_CLASS
&& c
->ts
.type
!= BT_UNKNOWN
)
8100 ivtab
= gfc_find_vtab (&c
->ts
);
8101 gcc_assert (ivtab
&& CLASS_DATA (ivtab
)->initializer
);
8102 e
= CLASS_DATA (ivtab
)->initializer
;
8103 c
->low
= c
->high
= gfc_copy_expr (e
);
8106 else if (c
->ts
.type
== BT_UNKNOWN
)
8109 /* Associate temporary to selector. This should only be done
8110 when this case is actually true, so build a new ASSOCIATE
8111 that does precisely this here (instead of using the
8114 if (c
->ts
.type
== BT_CLASS
)
8115 sprintf (name
, "__tmp_class_%s", c
->ts
.u
.derived
->name
);
8116 else if (c
->ts
.type
== BT_DERIVED
)
8117 sprintf (name
, "__tmp_type_%s", c
->ts
.u
.derived
->name
);
8118 else if (c
->ts
.type
== BT_CHARACTER
)
8120 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
8121 && c
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
8122 charlen
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
8123 sprintf (name
, "__tmp_%s_%d_%d", gfc_basic_typename (c
->ts
.type
),
8124 charlen
, c
->ts
.kind
);
8127 sprintf (name
, "__tmp_%s_%d", gfc_basic_typename (c
->ts
.type
),
8130 st
= gfc_find_symtree (ns
->sym_root
, name
);
8131 gcc_assert (st
->n
.sym
->assoc
);
8132 st
->n
.sym
->assoc
->target
= gfc_get_variable_expr (code
->expr1
->symtree
);
8133 st
->n
.sym
->assoc
->target
->where
= code
->expr1
->where
;
8134 if (c
->ts
.type
!= BT_CLASS
&& c
->ts
.type
!= BT_UNKNOWN
)
8135 gfc_add_data_component (st
->n
.sym
->assoc
->target
);
8137 new_st
= gfc_get_code (EXEC_BLOCK
);
8138 new_st
->ext
.block
.ns
= gfc_build_block_ns (ns
);
8139 new_st
->ext
.block
.ns
->code
= body
->next
;
8140 body
->next
= new_st
;
8142 /* Chain in the new list only if it is marked as dangling. Otherwise
8143 there is a CASE label overlap and this is already used. Just ignore,
8144 the error is diagnosed elsewhere. */
8145 if (st
->n
.sym
->assoc
->dangling
)
8147 new_st
->ext
.block
.assoc
= st
->n
.sym
->assoc
;
8148 st
->n
.sym
->assoc
->dangling
= 0;
8151 resolve_assoc_var (st
->n
.sym
, false);
8154 /* Take out CLASS IS cases for separate treatment. */
8156 while (body
&& body
->block
)
8158 if (body
->block
->ext
.block
.case_list
->ts
.type
== BT_CLASS
)
8160 /* Add to class_is list. */
8161 if (class_is
== NULL
)
8163 class_is
= body
->block
;
8168 for (tail
= class_is
; tail
->block
; tail
= tail
->block
) ;
8169 tail
->block
= body
->block
;
8172 /* Remove from EXEC_SELECT list. */
8173 body
->block
= body
->block
->block
;
8186 /* Add a default case to hold the CLASS IS cases. */
8187 for (tail
= code
; tail
->block
; tail
= tail
->block
) ;
8188 tail
->block
= gfc_get_code (EXEC_SELECT_TYPE
);
8190 tail
->ext
.block
.case_list
= gfc_get_case ();
8191 tail
->ext
.block
.case_list
->ts
.type
= BT_UNKNOWN
;
8193 default_case
= tail
;
8196 /* More than one CLASS IS block? */
8197 if (class_is
->block
)
8201 /* Sort CLASS IS blocks by extension level. */
8205 for (c1
= &class_is
; (*c1
) && (*c1
)->block
; c1
= &((*c1
)->block
))
8208 /* F03:C817 (check for doubles). */
8209 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->hash_value
8210 == c2
->ext
.block
.case_list
->ts
.u
.derived
->hash_value
)
8212 gfc_error ("Double CLASS IS block in SELECT TYPE "
8214 &c2
->ext
.block
.case_list
->where
);
8217 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
8218 < c2
->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
)
8221 (*c1
)->block
= c2
->block
;
8231 /* Generate IF chain. */
8232 if_st
= gfc_get_code (EXEC_IF
);
8234 for (body
= class_is
; body
; body
= body
->block
)
8236 new_st
->block
= gfc_get_code (EXEC_IF
);
8237 new_st
= new_st
->block
;
8238 /* Set up IF condition: Call _gfortran_is_extension_of. */
8239 new_st
->expr1
= gfc_get_expr ();
8240 new_st
->expr1
->expr_type
= EXPR_FUNCTION
;
8241 new_st
->expr1
->ts
.type
= BT_LOGICAL
;
8242 new_st
->expr1
->ts
.kind
= 4;
8243 new_st
->expr1
->value
.function
.name
= gfc_get_string (PREFIX ("is_extension_of"));
8244 new_st
->expr1
->value
.function
.isym
= XCNEW (gfc_intrinsic_sym
);
8245 new_st
->expr1
->value
.function
.isym
->id
= GFC_ISYM_EXTENDS_TYPE_OF
;
8246 /* Set up arguments. */
8247 new_st
->expr1
->value
.function
.actual
= gfc_get_actual_arglist ();
8248 new_st
->expr1
->value
.function
.actual
->expr
= gfc_get_variable_expr (code
->expr1
->symtree
);
8249 new_st
->expr1
->value
.function
.actual
->expr
->where
= code
->loc
;
8250 gfc_add_vptr_component (new_st
->expr1
->value
.function
.actual
->expr
);
8251 vtab
= gfc_find_derived_vtab (body
->ext
.block
.case_list
->ts
.u
.derived
);
8252 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
8253 new_st
->expr1
->value
.function
.actual
->next
= gfc_get_actual_arglist ();
8254 new_st
->expr1
->value
.function
.actual
->next
->expr
= gfc_get_variable_expr (st
);
8255 new_st
->next
= body
->next
;
8257 if (default_case
->next
)
8259 new_st
->block
= gfc_get_code (EXEC_IF
);
8260 new_st
= new_st
->block
;
8261 new_st
->next
= default_case
->next
;
8264 /* Replace CLASS DEFAULT code by the IF chain. */
8265 default_case
->next
= if_st
;
8268 /* Resolve the internal code. This can not be done earlier because
8269 it requires that the sym->assoc of selectors is set already. */
8270 gfc_current_ns
= ns
;
8271 gfc_resolve_blocks (code
->block
, gfc_current_ns
);
8272 gfc_current_ns
= old_ns
;
8274 resolve_select (code
, true);
8278 /* Resolve a transfer statement. This is making sure that:
8279 -- a derived type being transferred has only non-pointer components
8280 -- a derived type being transferred doesn't have private components, unless
8281 it's being transferred from the module where the type was defined
8282 -- we're not trying to transfer a whole assumed size array. */
8285 resolve_transfer (gfc_code
*code
)
8294 while (exp
!= NULL
&& exp
->expr_type
== EXPR_OP
8295 && exp
->value
.op
.op
== INTRINSIC_PARENTHESES
)
8296 exp
= exp
->value
.op
.op1
;
8298 if (exp
&& exp
->expr_type
== EXPR_NULL
8301 gfc_error ("Invalid context for NULL () intrinsic at %L",
8306 if (exp
== NULL
|| (exp
->expr_type
!= EXPR_VARIABLE
8307 && exp
->expr_type
!= EXPR_FUNCTION
))
8310 /* If we are reading, the variable will be changed. Note that
8311 code->ext.dt may be NULL if the TRANSFER is related to
8312 an INQUIRE statement -- but in this case, we are not reading, either. */
8313 if (code
->ext
.dt
&& code
->ext
.dt
->dt_io_kind
->value
.iokind
== M_READ
8314 && !gfc_check_vardef_context (exp
, false, false, false,
8318 sym
= exp
->symtree
->n
.sym
;
8321 /* Go to actual component transferred. */
8322 for (ref
= exp
->ref
; ref
; ref
= ref
->next
)
8323 if (ref
->type
== REF_COMPONENT
)
8324 ts
= &ref
->u
.c
.component
->ts
;
8326 if (ts
->type
== BT_CLASS
)
8328 /* FIXME: Test for defined input/output. */
8329 gfc_error ("Data transfer element at %L cannot be polymorphic unless "
8330 "it is processed by a defined input/output procedure",
8335 if (ts
->type
== BT_DERIVED
)
8337 /* Check that transferred derived type doesn't contain POINTER
8339 if (ts
->u
.derived
->attr
.pointer_comp
)
8341 gfc_error ("Data transfer element at %L cannot have POINTER "
8342 "components unless it is processed by a defined "
8343 "input/output procedure", &code
->loc
);
8348 if (ts
->u
.derived
->attr
.proc_pointer_comp
)
8350 gfc_error ("Data transfer element at %L cannot have "
8351 "procedure pointer components", &code
->loc
);
8355 if (ts
->u
.derived
->attr
.alloc_comp
)
8357 gfc_error ("Data transfer element at %L cannot have ALLOCATABLE "
8358 "components unless it is processed by a defined "
8359 "input/output procedure", &code
->loc
);
8363 /* C_PTR and C_FUNPTR have private components which means they can not
8364 be printed. However, if -std=gnu and not -pedantic, allow
8365 the component to be printed to help debugging. */
8366 if (ts
->u
.derived
->ts
.f90_type
== BT_VOID
)
8368 if (!gfc_notify_std (GFC_STD_GNU
, "Data transfer element at %L "
8369 "cannot have PRIVATE components", &code
->loc
))
8372 else if (derived_inaccessible (ts
->u
.derived
))
8374 gfc_error ("Data transfer element at %L cannot have "
8375 "PRIVATE components",&code
->loc
);
8380 if (sym
->as
!= NULL
&& sym
->as
->type
== AS_ASSUMED_SIZE
&& exp
->ref
8381 && exp
->ref
->type
== REF_ARRAY
&& exp
->ref
->u
.ar
.type
== AR_FULL
)
8383 gfc_error ("Data transfer element at %L cannot be a full reference to "
8384 "an assumed-size array", &code
->loc
);
8390 /*********** Toplevel code resolution subroutines ***********/
8392 /* Find the set of labels that are reachable from this block. We also
8393 record the last statement in each block. */
8396 find_reachable_labels (gfc_code
*block
)
8403 cs_base
->reachable_labels
= bitmap_obstack_alloc (&labels_obstack
);
8405 /* Collect labels in this block. We don't keep those corresponding
8406 to END {IF|SELECT}, these are checked in resolve_branch by going
8407 up through the code_stack. */
8408 for (c
= block
; c
; c
= c
->next
)
8410 if (c
->here
&& c
->op
!= EXEC_END_NESTED_BLOCK
)
8411 bitmap_set_bit (cs_base
->reachable_labels
, c
->here
->value
);
8414 /* Merge with labels from parent block. */
8417 gcc_assert (cs_base
->prev
->reachable_labels
);
8418 bitmap_ior_into (cs_base
->reachable_labels
,
8419 cs_base
->prev
->reachable_labels
);
8425 resolve_lock_unlock (gfc_code
*code
)
8427 if (code
->expr1
->ts
.type
!= BT_DERIVED
8428 || code
->expr1
->expr_type
!= EXPR_VARIABLE
8429 || code
->expr1
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
8430 || code
->expr1
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_LOCK_TYPE
8431 || code
->expr1
->rank
!= 0
8432 || (!gfc_is_coarray (code
->expr1
) && !gfc_is_coindexed (code
->expr1
)))
8433 gfc_error ("Lock variable at %L must be a scalar of type LOCK_TYPE",
8434 &code
->expr1
->where
);
8438 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
8439 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
8440 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
8441 &code
->expr2
->where
);
8444 && !gfc_check_vardef_context (code
->expr2
, false, false, false,
8445 _("STAT variable")))
8450 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
8451 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
8452 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
8453 &code
->expr3
->where
);
8456 && !gfc_check_vardef_context (code
->expr3
, false, false, false,
8457 _("ERRMSG variable")))
8460 /* Check ACQUIRED_LOCK. */
8462 && (code
->expr4
->ts
.type
!= BT_LOGICAL
|| code
->expr4
->rank
!= 0
8463 || code
->expr4
->expr_type
!= EXPR_VARIABLE
))
8464 gfc_error ("ACQUIRED_LOCK= argument at %L must be a scalar LOGICAL "
8465 "variable", &code
->expr4
->where
);
8468 && !gfc_check_vardef_context (code
->expr4
, false, false, false,
8469 _("ACQUIRED_LOCK variable")))
8475 resolve_sync (gfc_code
*code
)
8477 /* Check imageset. The * case matches expr1 == NULL. */
8480 if (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
> 1)
8481 gfc_error ("Imageset argument at %L must be a scalar or rank-1 "
8482 "INTEGER expression", &code
->expr1
->where
);
8483 if (code
->expr1
->expr_type
== EXPR_CONSTANT
&& code
->expr1
->rank
== 0
8484 && mpz_cmp_si (code
->expr1
->value
.integer
, 1) < 0)
8485 gfc_error ("Imageset argument at %L must between 1 and num_images()",
8486 &code
->expr1
->where
);
8487 else if (code
->expr1
->expr_type
== EXPR_ARRAY
8488 && gfc_simplify_expr (code
->expr1
, 0))
8490 gfc_constructor
*cons
;
8491 cons
= gfc_constructor_first (code
->expr1
->value
.constructor
);
8492 for (; cons
; cons
= gfc_constructor_next (cons
))
8493 if (cons
->expr
->expr_type
== EXPR_CONSTANT
8494 && mpz_cmp_si (cons
->expr
->value
.integer
, 1) < 0)
8495 gfc_error ("Imageset argument at %L must between 1 and "
8496 "num_images()", &cons
->expr
->where
);
8502 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
8503 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
8504 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
8505 &code
->expr2
->where
);
8509 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
8510 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
8511 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
8512 &code
->expr3
->where
);
8516 /* Given a branch to a label, see if the branch is conforming.
8517 The code node describes where the branch is located. */
8520 resolve_branch (gfc_st_label
*label
, gfc_code
*code
)
8527 /* Step one: is this a valid branching target? */
8529 if (label
->defined
== ST_LABEL_UNKNOWN
)
8531 gfc_error ("Label %d referenced at %L is never defined", label
->value
,
8536 if (label
->defined
!= ST_LABEL_TARGET
&& label
->defined
!= ST_LABEL_DO_TARGET
)
8538 gfc_error ("Statement at %L is not a valid branch target statement "
8539 "for the branch statement at %L", &label
->where
, &code
->loc
);
8543 /* Step two: make sure this branch is not a branch to itself ;-) */
8545 if (code
->here
== label
)
8547 gfc_warning ("Branch at %L may result in an infinite loop", &code
->loc
);
8551 /* Step three: See if the label is in the same block as the
8552 branching statement. The hard work has been done by setting up
8553 the bitmap reachable_labels. */
8555 if (bitmap_bit_p (cs_base
->reachable_labels
, label
->value
))
8557 /* Check now whether there is a CRITICAL construct; if so, check
8558 whether the label is still visible outside of the CRITICAL block,
8559 which is invalid. */
8560 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
8562 if (stack
->current
->op
== EXEC_CRITICAL
8563 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
8564 gfc_error ("GOTO statement at %L leaves CRITICAL construct for "
8565 "label at %L", &code
->loc
, &label
->where
);
8566 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
8567 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
8568 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct "
8569 "for label at %L", &code
->loc
, &label
->where
);
8575 /* Step four: If we haven't found the label in the bitmap, it may
8576 still be the label of the END of the enclosing block, in which
8577 case we find it by going up the code_stack. */
8579 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
8581 if (stack
->current
->next
&& stack
->current
->next
->here
== label
)
8583 if (stack
->current
->op
== EXEC_CRITICAL
)
8585 /* Note: A label at END CRITICAL does not leave the CRITICAL
8586 construct as END CRITICAL is still part of it. */
8587 gfc_error ("GOTO statement at %L leaves CRITICAL construct for label"
8588 " at %L", &code
->loc
, &label
->where
);
8591 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
)
8593 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct for "
8594 "label at %L", &code
->loc
, &label
->where
);
8601 gcc_assert (stack
->current
->next
->op
== EXEC_END_NESTED_BLOCK
);
8605 /* The label is not in an enclosing block, so illegal. This was
8606 allowed in Fortran 66, so we allow it as extension. No
8607 further checks are necessary in this case. */
8608 gfc_notify_std (GFC_STD_LEGACY
, "Label at %L is not in the same block "
8609 "as the GOTO statement at %L", &label
->where
,
8615 /* Check whether EXPR1 has the same shape as EXPR2. */
8618 resolve_where_shape (gfc_expr
*expr1
, gfc_expr
*expr2
)
8620 mpz_t shape
[GFC_MAX_DIMENSIONS
];
8621 mpz_t shape2
[GFC_MAX_DIMENSIONS
];
8622 bool result
= false;
8625 /* Compare the rank. */
8626 if (expr1
->rank
!= expr2
->rank
)
8629 /* Compare the size of each dimension. */
8630 for (i
=0; i
<expr1
->rank
; i
++)
8632 if (!gfc_array_dimen_size (expr1
, i
, &shape
[i
]))
8635 if (!gfc_array_dimen_size (expr2
, i
, &shape2
[i
]))
8638 if (mpz_cmp (shape
[i
], shape2
[i
]))
8642 /* When either of the two expression is an assumed size array, we
8643 ignore the comparison of dimension sizes. */
8648 gfc_clear_shape (shape
, i
);
8649 gfc_clear_shape (shape2
, i
);
8654 /* Check whether a WHERE assignment target or a WHERE mask expression
8655 has the same shape as the outmost WHERE mask expression. */
8658 resolve_where (gfc_code
*code
, gfc_expr
*mask
)
8664 cblock
= code
->block
;
8666 /* Store the first WHERE mask-expr of the WHERE statement or construct.
8667 In case of nested WHERE, only the outmost one is stored. */
8668 if (mask
== NULL
) /* outmost WHERE */
8670 else /* inner WHERE */
8677 /* Check if the mask-expr has a consistent shape with the
8678 outmost WHERE mask-expr. */
8679 if (!resolve_where_shape (cblock
->expr1
, e
))
8680 gfc_error ("WHERE mask at %L has inconsistent shape",
8681 &cblock
->expr1
->where
);
8684 /* the assignment statement of a WHERE statement, or the first
8685 statement in where-body-construct of a WHERE construct */
8686 cnext
= cblock
->next
;
8691 /* WHERE assignment statement */
8694 /* Check shape consistent for WHERE assignment target. */
8695 if (e
&& !resolve_where_shape (cnext
->expr1
, e
))
8696 gfc_error ("WHERE assignment target at %L has "
8697 "inconsistent shape", &cnext
->expr1
->where
);
8701 case EXEC_ASSIGN_CALL
:
8702 resolve_call (cnext
);
8703 if (!cnext
->resolved_sym
->attr
.elemental
)
8704 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
8705 &cnext
->ext
.actual
->expr
->where
);
8708 /* WHERE or WHERE construct is part of a where-body-construct */
8710 resolve_where (cnext
, e
);
8714 gfc_error ("Unsupported statement inside WHERE at %L",
8717 /* the next statement within the same where-body-construct */
8718 cnext
= cnext
->next
;
8720 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
8721 cblock
= cblock
->block
;
8726 /* Resolve assignment in FORALL construct.
8727 NVAR is the number of FORALL index variables, and VAR_EXPR records the
8728 FORALL index variables. */
8731 gfc_resolve_assign_in_forall (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
8735 for (n
= 0; n
< nvar
; n
++)
8737 gfc_symbol
*forall_index
;
8739 forall_index
= var_expr
[n
]->symtree
->n
.sym
;
8741 /* Check whether the assignment target is one of the FORALL index
8743 if ((code
->expr1
->expr_type
== EXPR_VARIABLE
)
8744 && (code
->expr1
->symtree
->n
.sym
== forall_index
))
8745 gfc_error ("Assignment to a FORALL index variable at %L",
8746 &code
->expr1
->where
);
8749 /* If one of the FORALL index variables doesn't appear in the
8750 assignment variable, then there could be a many-to-one
8751 assignment. Emit a warning rather than an error because the
8752 mask could be resolving this problem. */
8753 if (!find_forall_index (code
->expr1
, forall_index
, 0))
8754 gfc_warning ("The FORALL with index '%s' is not used on the "
8755 "left side of the assignment at %L and so might "
8756 "cause multiple assignment to this object",
8757 var_expr
[n
]->symtree
->name
, &code
->expr1
->where
);
8763 /* Resolve WHERE statement in FORALL construct. */
8766 gfc_resolve_where_code_in_forall (gfc_code
*code
, int nvar
,
8767 gfc_expr
**var_expr
)
8772 cblock
= code
->block
;
8775 /* the assignment statement of a WHERE statement, or the first
8776 statement in where-body-construct of a WHERE construct */
8777 cnext
= cblock
->next
;
8782 /* WHERE assignment statement */
8784 gfc_resolve_assign_in_forall (cnext
, nvar
, var_expr
);
8787 /* WHERE operator assignment statement */
8788 case EXEC_ASSIGN_CALL
:
8789 resolve_call (cnext
);
8790 if (!cnext
->resolved_sym
->attr
.elemental
)
8791 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
8792 &cnext
->ext
.actual
->expr
->where
);
8795 /* WHERE or WHERE construct is part of a where-body-construct */
8797 gfc_resolve_where_code_in_forall (cnext
, nvar
, var_expr
);
8801 gfc_error ("Unsupported statement inside WHERE at %L",
8804 /* the next statement within the same where-body-construct */
8805 cnext
= cnext
->next
;
8807 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
8808 cblock
= cblock
->block
;
8813 /* Traverse the FORALL body to check whether the following errors exist:
8814 1. For assignment, check if a many-to-one assignment happens.
8815 2. For WHERE statement, check the WHERE body to see if there is any
8816 many-to-one assignment. */
8819 gfc_resolve_forall_body (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
8823 c
= code
->block
->next
;
8829 case EXEC_POINTER_ASSIGN
:
8830 gfc_resolve_assign_in_forall (c
, nvar
, var_expr
);
8833 case EXEC_ASSIGN_CALL
:
8837 /* Because the gfc_resolve_blocks() will handle the nested FORALL,
8838 there is no need to handle it here. */
8842 gfc_resolve_where_code_in_forall(c
, nvar
, var_expr
);
8847 /* The next statement in the FORALL body. */
8853 /* Counts the number of iterators needed inside a forall construct, including
8854 nested forall constructs. This is used to allocate the needed memory
8855 in gfc_resolve_forall. */
8858 gfc_count_forall_iterators (gfc_code
*code
)
8860 int max_iters
, sub_iters
, current_iters
;
8861 gfc_forall_iterator
*fa
;
8863 gcc_assert(code
->op
== EXEC_FORALL
);
8867 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
8870 code
= code
->block
->next
;
8874 if (code
->op
== EXEC_FORALL
)
8876 sub_iters
= gfc_count_forall_iterators (code
);
8877 if (sub_iters
> max_iters
)
8878 max_iters
= sub_iters
;
8883 return current_iters
+ max_iters
;
8887 /* Given a FORALL construct, first resolve the FORALL iterator, then call
8888 gfc_resolve_forall_body to resolve the FORALL body. */
8891 gfc_resolve_forall (gfc_code
*code
, gfc_namespace
*ns
, int forall_save
)
8893 static gfc_expr
**var_expr
;
8894 static int total_var
= 0;
8895 static int nvar
= 0;
8897 gfc_forall_iterator
*fa
;
8902 /* Start to resolve a FORALL construct */
8903 if (forall_save
== 0)
8905 /* Count the total number of FORALL index in the nested FORALL
8906 construct in order to allocate the VAR_EXPR with proper size. */
8907 total_var
= gfc_count_forall_iterators (code
);
8909 /* Allocate VAR_EXPR with NUMBER_OF_FORALL_INDEX elements. */
8910 var_expr
= XCNEWVEC (gfc_expr
*, total_var
);
8913 /* The information about FORALL iterator, including FORALL index start, end
8914 and stride. The FORALL index can not appear in start, end or stride. */
8915 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
8917 /* Check if any outer FORALL index name is the same as the current
8919 for (i
= 0; i
< nvar
; i
++)
8921 if (fa
->var
->symtree
->n
.sym
== var_expr
[i
]->symtree
->n
.sym
)
8923 gfc_error ("An outer FORALL construct already has an index "
8924 "with this name %L", &fa
->var
->where
);
8928 /* Record the current FORALL index. */
8929 var_expr
[nvar
] = gfc_copy_expr (fa
->var
);
8933 /* No memory leak. */
8934 gcc_assert (nvar
<= total_var
);
8937 /* Resolve the FORALL body. */
8938 gfc_resolve_forall_body (code
, nvar
, var_expr
);
8940 /* May call gfc_resolve_forall to resolve the inner FORALL loop. */
8941 gfc_resolve_blocks (code
->block
, ns
);
8945 /* Free only the VAR_EXPRs allocated in this frame. */
8946 for (i
= nvar
; i
< tmp
; i
++)
8947 gfc_free_expr (var_expr
[i
]);
8951 /* We are in the outermost FORALL construct. */
8952 gcc_assert (forall_save
== 0);
8954 /* VAR_EXPR is not needed any more. */
8961 /* Resolve a BLOCK construct statement. */
8964 resolve_block_construct (gfc_code
* code
)
8966 /* Resolve the BLOCK's namespace. */
8967 gfc_resolve (code
->ext
.block
.ns
);
8969 /* For an ASSOCIATE block, the associations (and their targets) are already
8970 resolved during resolve_symbol. */
8974 /* Resolve lists of blocks found in IF, SELECT CASE, WHERE, FORALL, GOTO and
8977 static void resolve_code (gfc_code
*, gfc_namespace
*);
8980 gfc_resolve_blocks (gfc_code
*b
, gfc_namespace
*ns
)
8984 for (; b
; b
= b
->block
)
8986 t
= gfc_resolve_expr (b
->expr1
);
8987 if (!gfc_resolve_expr (b
->expr2
))
8993 if (t
&& b
->expr1
!= NULL
8994 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
!= 0))
8995 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
9002 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
== 0))
9003 gfc_error ("WHERE/ELSEWHERE clause at %L requires a LOGICAL array",
9008 resolve_branch (b
->label1
, b
);
9012 resolve_block_construct (b
);
9016 case EXEC_SELECT_TYPE
:
9020 case EXEC_DO_CONCURRENT
:
9028 case EXEC_OMP_ATOMIC
:
9029 case EXEC_OMP_CRITICAL
:
9031 case EXEC_OMP_DO_SIMD
:
9032 case EXEC_OMP_MASTER
:
9033 case EXEC_OMP_ORDERED
:
9034 case EXEC_OMP_PARALLEL
:
9035 case EXEC_OMP_PARALLEL_DO
:
9036 case EXEC_OMP_PARALLEL_DO_SIMD
:
9037 case EXEC_OMP_PARALLEL_SECTIONS
:
9038 case EXEC_OMP_PARALLEL_WORKSHARE
:
9039 case EXEC_OMP_SECTIONS
:
9041 case EXEC_OMP_SINGLE
:
9043 case EXEC_OMP_TASKGROUP
:
9044 case EXEC_OMP_TASKWAIT
:
9045 case EXEC_OMP_TASKYIELD
:
9046 case EXEC_OMP_WORKSHARE
:
9050 gfc_internal_error ("gfc_resolve_blocks(): Bad block type");
9053 resolve_code (b
->next
, ns
);
9058 /* Does everything to resolve an ordinary assignment. Returns true
9059 if this is an interface assignment. */
9061 resolve_ordinary_assign (gfc_code
*code
, gfc_namespace
*ns
)
9070 symbol_attribute attr
;
9072 if (gfc_extend_assign (code
, ns
))
9076 if (code
->op
== EXEC_ASSIGN_CALL
)
9078 lhs
= code
->ext
.actual
->expr
;
9079 rhsptr
= &code
->ext
.actual
->next
->expr
;
9083 gfc_actual_arglist
* args
;
9084 gfc_typebound_proc
* tbp
;
9086 gcc_assert (code
->op
== EXEC_COMPCALL
);
9088 args
= code
->expr1
->value
.compcall
.actual
;
9090 rhsptr
= &args
->next
->expr
;
9092 tbp
= code
->expr1
->value
.compcall
.tbp
;
9093 gcc_assert (!tbp
->is_generic
);
9096 /* Make a temporary rhs when there is a default initializer
9097 and rhs is the same symbol as the lhs. */
9098 if ((*rhsptr
)->expr_type
== EXPR_VARIABLE
9099 && (*rhsptr
)->symtree
->n
.sym
->ts
.type
== BT_DERIVED
9100 && gfc_has_default_initializer ((*rhsptr
)->symtree
->n
.sym
->ts
.u
.derived
)
9101 && (lhs
->symtree
->n
.sym
== (*rhsptr
)->symtree
->n
.sym
))
9102 *rhsptr
= gfc_get_parentheses (*rhsptr
);
9111 && !gfc_notify_std (GFC_STD_GNU
, "BOZ literal at %L outside "
9112 "a DATA statement and outside INT/REAL/DBLE/CMPLX",
9116 /* Handle the case of a BOZ literal on the RHS. */
9117 if (rhs
->is_boz
&& lhs
->ts
.type
!= BT_INTEGER
)
9120 if (gfc_option
.warn_surprising
)
9121 gfc_warning ("BOZ literal at %L is bitwise transferred "
9122 "non-integer symbol '%s'", &code
->loc
,
9123 lhs
->symtree
->n
.sym
->name
);
9125 if (!gfc_convert_boz (rhs
, &lhs
->ts
))
9127 if ((rc
= gfc_range_check (rhs
)) != ARITH_OK
)
9129 if (rc
== ARITH_UNDERFLOW
)
9130 gfc_error ("Arithmetic underflow of bit-wise transferred BOZ at %L"
9131 ". This check can be disabled with the option "
9132 "-fno-range-check", &rhs
->where
);
9133 else if (rc
== ARITH_OVERFLOW
)
9134 gfc_error ("Arithmetic overflow of bit-wise transferred BOZ at %L"
9135 ". This check can be disabled with the option "
9136 "-fno-range-check", &rhs
->where
);
9137 else if (rc
== ARITH_NAN
)
9138 gfc_error ("Arithmetic NaN of bit-wise transferred BOZ at %L"
9139 ". This check can be disabled with the option "
9140 "-fno-range-check", &rhs
->where
);
9145 if (lhs
->ts
.type
== BT_CHARACTER
9146 && gfc_option
.warn_character_truncation
)
9148 if (lhs
->ts
.u
.cl
!= NULL
9149 && lhs
->ts
.u
.cl
->length
!= NULL
9150 && lhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9151 llen
= mpz_get_si (lhs
->ts
.u
.cl
->length
->value
.integer
);
9153 if (rhs
->expr_type
== EXPR_CONSTANT
)
9154 rlen
= rhs
->value
.character
.length
;
9156 else if (rhs
->ts
.u
.cl
!= NULL
9157 && rhs
->ts
.u
.cl
->length
!= NULL
9158 && rhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9159 rlen
= mpz_get_si (rhs
->ts
.u
.cl
->length
->value
.integer
);
9161 if (rlen
&& llen
&& rlen
> llen
)
9162 gfc_warning_now ("CHARACTER expression will be truncated "
9163 "in assignment (%d/%d) at %L",
9164 llen
, rlen
, &code
->loc
);
9167 /* Ensure that a vector index expression for the lvalue is evaluated
9168 to a temporary if the lvalue symbol is referenced in it. */
9171 for (ref
= lhs
->ref
; ref
; ref
= ref
->next
)
9172 if (ref
->type
== REF_ARRAY
)
9174 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
9175 if (ref
->u
.ar
.dimen_type
[n
] == DIMEN_VECTOR
9176 && gfc_find_sym_in_expr (lhs
->symtree
->n
.sym
,
9177 ref
->u
.ar
.start
[n
]))
9179 = gfc_get_parentheses (ref
->u
.ar
.start
[n
]);
9183 if (gfc_pure (NULL
))
9185 if (lhs
->ts
.type
== BT_DERIVED
9186 && lhs
->expr_type
== EXPR_VARIABLE
9187 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9188 && rhs
->expr_type
== EXPR_VARIABLE
9189 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9190 || gfc_is_coindexed (rhs
)))
9193 if (gfc_is_coindexed (rhs
))
9194 gfc_error ("Coindexed expression at %L is assigned to "
9195 "a derived type variable with a POINTER "
9196 "component in a PURE procedure",
9199 gfc_error ("The impure variable at %L is assigned to "
9200 "a derived type variable with a POINTER "
9201 "component in a PURE procedure (12.6)",
9206 /* Fortran 2008, C1283. */
9207 if (gfc_is_coindexed (lhs
))
9209 gfc_error ("Assignment to coindexed variable at %L in a PURE "
9210 "procedure", &rhs
->where
);
9215 if (gfc_implicit_pure (NULL
))
9217 if (lhs
->expr_type
== EXPR_VARIABLE
9218 && lhs
->symtree
->n
.sym
!= gfc_current_ns
->proc_name
9219 && lhs
->symtree
->n
.sym
->ns
!= gfc_current_ns
)
9220 gfc_unset_implicit_pure (NULL
);
9222 if (lhs
->ts
.type
== BT_DERIVED
9223 && lhs
->expr_type
== EXPR_VARIABLE
9224 && lhs
->ts
.u
.derived
->attr
.pointer_comp
9225 && rhs
->expr_type
== EXPR_VARIABLE
9226 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
9227 || gfc_is_coindexed (rhs
)))
9228 gfc_unset_implicit_pure (NULL
);
9230 /* Fortran 2008, C1283. */
9231 if (gfc_is_coindexed (lhs
))
9232 gfc_unset_implicit_pure (NULL
);
9235 /* F2008, 7.2.1.2. */
9236 attr
= gfc_expr_attr (lhs
);
9237 if (lhs
->ts
.type
== BT_CLASS
&& attr
.allocatable
)
9239 if (attr
.codimension
)
9241 gfc_error ("Assignment to polymorphic coarray at %L is not "
9242 "permitted", &lhs
->where
);
9245 if (!gfc_notify_std (GFC_STD_F2008
, "Assignment to an allocatable "
9246 "polymorphic variable at %L", &lhs
->where
))
9248 if (!gfc_option
.flag_realloc_lhs
)
9250 gfc_error ("Assignment to an allocatable polymorphic variable at %L "
9251 "requires -frealloc-lhs", &lhs
->where
);
9255 gfc_error ("Assignment to an allocatable polymorphic variable at %L "
9256 "is not yet supported", &lhs
->where
);
9259 else if (lhs
->ts
.type
== BT_CLASS
)
9261 gfc_error ("Nonallocatable variable must not be polymorphic in intrinsic "
9262 "assignment at %L - check that there is a matching specific "
9263 "subroutine for '=' operator", &lhs
->where
);
9267 bool lhs_coindexed
= gfc_is_coindexed (lhs
);
9269 /* F2008, Section 7.2.1.2. */
9270 if (lhs_coindexed
&& gfc_has_ultimate_allocatable (lhs
))
9272 gfc_error ("Coindexed variable must not have an allocatable ultimate "
9273 "component in assignment at %L", &lhs
->where
);
9277 gfc_check_assign (lhs
, rhs
, 1);
9279 if (0 && lhs_coindexed
&& gfc_option
.coarray
== GFC_FCOARRAY_LIB
)
9281 code
->op
= EXEC_CALL
;
9282 gfc_get_sym_tree (GFC_PREFIX ("caf_send"), ns
, &code
->symtree
, true);
9283 code
->resolved_sym
= code
->symtree
->n
.sym
;
9284 code
->resolved_sym
->attr
.flavor
= FL_PROCEDURE
;
9285 code
->resolved_sym
->attr
.intrinsic
= 1;
9286 code
->resolved_sym
->attr
.subroutine
= 1;
9287 code
->resolved_isym
= gfc_intrinsic_subroutine_by_id (GFC_ISYM_CAF_SEND
);
9288 gfc_commit_symbol (code
->resolved_sym
);
9289 code
->ext
.actual
= gfc_get_actual_arglist ();
9290 code
->ext
.actual
->expr
= lhs
;
9291 code
->ext
.actual
->next
= gfc_get_actual_arglist ();
9292 code
->ext
.actual
->next
->expr
= rhs
;
9301 /* Add a component reference onto an expression. */
9304 add_comp_ref (gfc_expr
*e
, gfc_component
*c
)
9309 ref
= &((*ref
)->next
);
9310 *ref
= gfc_get_ref ();
9311 (*ref
)->type
= REF_COMPONENT
;
9312 (*ref
)->u
.c
.sym
= e
->ts
.u
.derived
;
9313 (*ref
)->u
.c
.component
= c
;
9316 /* Add a full array ref, as necessary. */
9319 gfc_add_full_array_ref (e
, c
->as
);
9320 e
->rank
= c
->as
->rank
;
9325 /* Build an assignment. Keep the argument 'op' for future use, so that
9326 pointer assignments can be made. */
9329 build_assignment (gfc_exec_op op
, gfc_expr
*expr1
, gfc_expr
*expr2
,
9330 gfc_component
*comp1
, gfc_component
*comp2
, locus loc
)
9332 gfc_code
*this_code
;
9334 this_code
= gfc_get_code (op
);
9335 this_code
->next
= NULL
;
9336 this_code
->expr1
= gfc_copy_expr (expr1
);
9337 this_code
->expr2
= gfc_copy_expr (expr2
);
9338 this_code
->loc
= loc
;
9341 add_comp_ref (this_code
->expr1
, comp1
);
9342 add_comp_ref (this_code
->expr2
, comp2
);
9349 /* Makes a temporary variable expression based on the characteristics of
9350 a given variable expression. */
9353 get_temp_from_expr (gfc_expr
*e
, gfc_namespace
*ns
)
9355 static int serial
= 0;
9356 char name
[GFC_MAX_SYMBOL_LEN
];
9359 gfc_array_ref
*aref
;
9362 sprintf (name
, GFC_PREFIX("DA%d"), serial
++);
9363 gfc_get_sym_tree (name
, ns
, &tmp
, false);
9364 gfc_add_type (tmp
->n
.sym
, &e
->ts
, NULL
);
9370 /* This function could be expanded to support other expression type
9371 but this is not needed here. */
9372 gcc_assert (e
->expr_type
== EXPR_VARIABLE
);
9374 /* Obtain the arrayspec for the temporary. */
9377 aref
= gfc_find_array_ref (e
);
9378 if (e
->expr_type
== EXPR_VARIABLE
9379 && e
->symtree
->n
.sym
->as
== aref
->as
)
9383 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
9384 if (ref
->type
== REF_COMPONENT
9385 && ref
->u
.c
.component
->as
== aref
->as
)
9393 /* Add the attributes and the arrayspec to the temporary. */
9394 tmp
->n
.sym
->attr
= gfc_expr_attr (e
);
9395 tmp
->n
.sym
->attr
.function
= 0;
9396 tmp
->n
.sym
->attr
.result
= 0;
9397 tmp
->n
.sym
->attr
.flavor
= FL_VARIABLE
;
9401 tmp
->n
.sym
->as
= gfc_copy_array_spec (as
);
9404 if (as
->type
== AS_DEFERRED
)
9405 tmp
->n
.sym
->attr
.allocatable
= 1;
9408 tmp
->n
.sym
->attr
.dimension
= 0;
9410 gfc_set_sym_referenced (tmp
->n
.sym
);
9411 gfc_commit_symbol (tmp
->n
.sym
);
9412 e
= gfc_lval_expr_from_sym (tmp
->n
.sym
);
9414 /* Should the lhs be a section, use its array ref for the
9415 temporary expression. */
9416 if (aref
&& aref
->type
!= AR_FULL
)
9418 gfc_free_ref_list (e
->ref
);
9419 e
->ref
= gfc_copy_ref (ref
);
9425 /* Add one line of code to the code chain, making sure that 'head' and
9426 'tail' are appropriately updated. */
9429 add_code_to_chain (gfc_code
**this_code
, gfc_code
**head
, gfc_code
**tail
)
9431 gcc_assert (this_code
);
9433 *head
= *tail
= *this_code
;
9435 *tail
= gfc_append_code (*tail
, *this_code
);
9440 /* Counts the potential number of part array references that would
9441 result from resolution of typebound defined assignments. */
9444 nonscalar_typebound_assign (gfc_symbol
*derived
, int depth
)
9447 int c_depth
= 0, t_depth
;
9449 for (c
= derived
->components
; c
; c
= c
->next
)
9451 if ((c
->ts
.type
!= BT_DERIVED
9453 || c
->attr
.allocatable
9454 || c
->attr
.proc_pointer_comp
9455 || c
->attr
.class_pointer
9456 || c
->attr
.proc_pointer
)
9457 && !c
->attr
.defined_assign_comp
)
9460 if (c
->as
&& c_depth
== 0)
9463 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
9464 t_depth
= nonscalar_typebound_assign (c
->ts
.u
.derived
,
9469 c_depth
= t_depth
> c_depth
? t_depth
: c_depth
;
9471 return depth
+ c_depth
;
9475 /* Implement 7.2.1.3 of the F08 standard:
9476 "An intrinsic assignment where the variable is of derived type is
9477 performed as if each component of the variable were assigned from the
9478 corresponding component of expr using pointer assignment (7.2.2) for
9479 each pointer component, defined assignment for each nonpointer
9480 nonallocatable component of a type that has a type-bound defined
9481 assignment consistent with the component, intrinsic assignment for
9482 each other nonpointer nonallocatable component, ..."
9484 The pointer assignments are taken care of by the intrinsic
9485 assignment of the structure itself. This function recursively adds
9486 defined assignments where required. The recursion is accomplished
9487 by calling resolve_code.
9489 When the lhs in a defined assignment has intent INOUT, we need a
9490 temporary for the lhs. In pseudo-code:
9492 ! Only call function lhs once.
9493 if (lhs is not a constant or an variable)
9496 ! Do the intrinsic assignment
9498 ! Now do the defined assignments
9499 do over components with typebound defined assignment [%cmp]
9500 #if one component's assignment procedure is INOUT
9502 #if expr2 non-variable
9508 t1%cmp {defined=} expr2%cmp
9514 expr1%cmp {defined=} expr2%cmp
9518 /* The temporary assignments have to be put on top of the additional
9519 code to avoid the result being changed by the intrinsic assignment.
9521 static int component_assignment_level
= 0;
9522 static gfc_code
*tmp_head
= NULL
, *tmp_tail
= NULL
;
9525 generate_component_assignments (gfc_code
**code
, gfc_namespace
*ns
)
9527 gfc_component
*comp1
, *comp2
;
9528 gfc_code
*this_code
= NULL
, *head
= NULL
, *tail
= NULL
;
9530 int error_count
, depth
;
9532 gfc_get_errors (NULL
, &error_count
);
9534 /* Filter out continuing processing after an error. */
9536 || (*code
)->expr1
->ts
.type
!= BT_DERIVED
9537 || (*code
)->expr2
->ts
.type
!= BT_DERIVED
)
9540 /* TODO: Handle more than one part array reference in assignments. */
9541 depth
= nonscalar_typebound_assign ((*code
)->expr1
->ts
.u
.derived
,
9542 (*code
)->expr1
->rank
? 1 : 0);
9545 gfc_warning ("TODO: type-bound defined assignment(s) at %L not "
9546 "done because multiple part array references would "
9547 "occur in intermediate expressions.", &(*code
)->loc
);
9551 component_assignment_level
++;
9553 /* Create a temporary so that functions get called only once. */
9554 if ((*code
)->expr2
->expr_type
!= EXPR_VARIABLE
9555 && (*code
)->expr2
->expr_type
!= EXPR_CONSTANT
)
9559 /* Assign the rhs to the temporary. */
9560 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
9561 this_code
= build_assignment (EXEC_ASSIGN
,
9562 tmp_expr
, (*code
)->expr2
,
9563 NULL
, NULL
, (*code
)->loc
);
9564 /* Add the code and substitute the rhs expression. */
9565 add_code_to_chain (&this_code
, &tmp_head
, &tmp_tail
);
9566 gfc_free_expr ((*code
)->expr2
);
9567 (*code
)->expr2
= tmp_expr
;
9570 /* Do the intrinsic assignment. This is not needed if the lhs is one
9571 of the temporaries generated here, since the intrinsic assignment
9572 to the final result already does this. */
9573 if ((*code
)->expr1
->symtree
->n
.sym
->name
[2] != '@')
9575 this_code
= build_assignment (EXEC_ASSIGN
,
9576 (*code
)->expr1
, (*code
)->expr2
,
9577 NULL
, NULL
, (*code
)->loc
);
9578 add_code_to_chain (&this_code
, &head
, &tail
);
9581 comp1
= (*code
)->expr1
->ts
.u
.derived
->components
;
9582 comp2
= (*code
)->expr2
->ts
.u
.derived
->components
;
9585 for (; comp1
; comp1
= comp1
->next
, comp2
= comp2
->next
)
9589 /* The intrinsic assignment does the right thing for pointers
9590 of all kinds and allocatable components. */
9591 if (comp1
->ts
.type
!= BT_DERIVED
9592 || comp1
->attr
.pointer
9593 || comp1
->attr
.allocatable
9594 || comp1
->attr
.proc_pointer_comp
9595 || comp1
->attr
.class_pointer
9596 || comp1
->attr
.proc_pointer
)
9599 /* Make an assigment for this component. */
9600 this_code
= build_assignment (EXEC_ASSIGN
,
9601 (*code
)->expr1
, (*code
)->expr2
,
9602 comp1
, comp2
, (*code
)->loc
);
9604 /* Convert the assignment if there is a defined assignment for
9605 this type. Otherwise, using the call from resolve_code,
9606 recurse into its components. */
9607 resolve_code (this_code
, ns
);
9609 if (this_code
->op
== EXEC_ASSIGN_CALL
)
9611 gfc_formal_arglist
*dummy_args
;
9613 /* Check that there is a typebound defined assignment. If not,
9614 then this must be a module defined assignment. We cannot
9615 use the defined_assign_comp attribute here because it must
9616 be this derived type that has the defined assignment and not
9618 if (!(comp1
->ts
.u
.derived
->f2k_derived
9619 && comp1
->ts
.u
.derived
->f2k_derived
9620 ->tb_op
[INTRINSIC_ASSIGN
]))
9622 gfc_free_statements (this_code
);
9627 /* If the first argument of the subroutine has intent INOUT
9628 a temporary must be generated and used instead. */
9629 rsym
= this_code
->resolved_sym
;
9630 dummy_args
= gfc_sym_get_dummy_args (rsym
);
9632 && dummy_args
->sym
->attr
.intent
== INTENT_INOUT
)
9634 gfc_code
*temp_code
;
9637 /* Build the temporary required for the assignment and put
9638 it at the head of the generated code. */
9641 t1
= get_temp_from_expr ((*code
)->expr1
, ns
);
9642 temp_code
= build_assignment (EXEC_ASSIGN
,
9644 NULL
, NULL
, (*code
)->loc
);
9646 /* For allocatable LHS, check whether it is allocated. Note
9647 that allocatable components with defined assignment are
9648 not yet support. See PR 57696. */
9649 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
)
9653 gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
9654 block
= gfc_get_code (EXEC_IF
);
9655 block
->block
= gfc_get_code (EXEC_IF
);
9657 = gfc_build_intrinsic_call (ns
,
9658 GFC_ISYM_ALLOCATED
, "allocated",
9659 (*code
)->loc
, 1, e
);
9660 block
->block
->next
= temp_code
;
9663 add_code_to_chain (&temp_code
, &tmp_head
, &tmp_tail
);
9666 /* Replace the first actual arg with the component of the
9668 gfc_free_expr (this_code
->ext
.actual
->expr
);
9669 this_code
->ext
.actual
->expr
= gfc_copy_expr (t1
);
9670 add_comp_ref (this_code
->ext
.actual
->expr
, comp1
);
9672 /* If the LHS variable is allocatable and wasn't allocated and
9673 the temporary is allocatable, pointer assign the address of
9674 the freshly allocated LHS to the temporary. */
9675 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
9676 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
9681 cond
= gfc_get_expr ();
9682 cond
->ts
.type
= BT_LOGICAL
;
9683 cond
->ts
.kind
= gfc_default_logical_kind
;
9684 cond
->expr_type
= EXPR_OP
;
9685 cond
->where
= (*code
)->loc
;
9686 cond
->value
.op
.op
= INTRINSIC_NOT
;
9687 cond
->value
.op
.op1
= gfc_build_intrinsic_call (ns
,
9688 GFC_ISYM_ALLOCATED
, "allocated",
9689 (*code
)->loc
, 1, gfc_copy_expr (t1
));
9690 block
= gfc_get_code (EXEC_IF
);
9691 block
->block
= gfc_get_code (EXEC_IF
);
9692 block
->block
->expr1
= cond
;
9693 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
9695 NULL
, NULL
, (*code
)->loc
);
9696 add_code_to_chain (&block
, &head
, &tail
);
9700 else if (this_code
->op
== EXEC_ASSIGN
&& !this_code
->next
)
9702 /* Don't add intrinsic assignments since they are already
9703 effected by the intrinsic assignment of the structure. */
9704 gfc_free_statements (this_code
);
9709 add_code_to_chain (&this_code
, &head
, &tail
);
9713 /* Transfer the value to the final result. */
9714 this_code
= build_assignment (EXEC_ASSIGN
,
9716 comp1
, comp2
, (*code
)->loc
);
9717 add_code_to_chain (&this_code
, &head
, &tail
);
9721 /* Put the temporary assignments at the top of the generated code. */
9722 if (tmp_head
&& component_assignment_level
== 1)
9724 gfc_append_code (tmp_head
, head
);
9726 tmp_head
= tmp_tail
= NULL
;
9729 // If we did a pointer assignment - thus, we need to ensure that the LHS is
9730 // not accidentally deallocated. Hence, nullify t1.
9731 if (t1
&& (*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
9732 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
9738 e
= gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
9739 cond
= gfc_build_intrinsic_call (ns
, GFC_ISYM_ASSOCIATED
, "associated",
9740 (*code
)->loc
, 2, gfc_copy_expr (t1
), e
);
9741 block
= gfc_get_code (EXEC_IF
);
9742 block
->block
= gfc_get_code (EXEC_IF
);
9743 block
->block
->expr1
= cond
;
9744 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
9745 t1
, gfc_get_null_expr (&(*code
)->loc
),
9746 NULL
, NULL
, (*code
)->loc
);
9747 gfc_append_code (tail
, block
);
9751 /* Now attach the remaining code chain to the input code. Step on
9752 to the end of the new code since resolution is complete. */
9753 gcc_assert ((*code
)->op
== EXEC_ASSIGN
);
9754 tail
->next
= (*code
)->next
;
9755 /* Overwrite 'code' because this would place the intrinsic assignment
9756 before the temporary for the lhs is created. */
9757 gfc_free_expr ((*code
)->expr1
);
9758 gfc_free_expr ((*code
)->expr2
);
9764 component_assignment_level
--;
9768 /* Given a block of code, recursively resolve everything pointed to by this
9772 resolve_code (gfc_code
*code
, gfc_namespace
*ns
)
9774 int omp_workshare_save
;
9775 int forall_save
, do_concurrent_save
;
9779 frame
.prev
= cs_base
;
9783 find_reachable_labels (code
);
9785 for (; code
; code
= code
->next
)
9787 frame
.current
= code
;
9788 forall_save
= forall_flag
;
9789 do_concurrent_save
= gfc_do_concurrent_flag
;
9791 if (code
->op
== EXEC_FORALL
)
9794 gfc_resolve_forall (code
, ns
, forall_save
);
9797 else if (code
->block
)
9799 omp_workshare_save
= -1;
9802 case EXEC_OMP_PARALLEL_WORKSHARE
:
9803 omp_workshare_save
= omp_workshare_flag
;
9804 omp_workshare_flag
= 1;
9805 gfc_resolve_omp_parallel_blocks (code
, ns
);
9807 case EXEC_OMP_PARALLEL
:
9808 case EXEC_OMP_PARALLEL_DO
:
9809 case EXEC_OMP_PARALLEL_DO_SIMD
:
9810 case EXEC_OMP_PARALLEL_SECTIONS
:
9812 omp_workshare_save
= omp_workshare_flag
;
9813 omp_workshare_flag
= 0;
9814 gfc_resolve_omp_parallel_blocks (code
, ns
);
9817 case EXEC_OMP_DO_SIMD
:
9819 gfc_resolve_omp_do_blocks (code
, ns
);
9821 case EXEC_SELECT_TYPE
:
9822 /* Blocks are handled in resolve_select_type because we have
9823 to transform the SELECT TYPE into ASSOCIATE first. */
9825 case EXEC_DO_CONCURRENT
:
9826 gfc_do_concurrent_flag
= 1;
9827 gfc_resolve_blocks (code
->block
, ns
);
9828 gfc_do_concurrent_flag
= 2;
9830 case EXEC_OMP_WORKSHARE
:
9831 omp_workshare_save
= omp_workshare_flag
;
9832 omp_workshare_flag
= 1;
9835 gfc_resolve_blocks (code
->block
, ns
);
9839 if (omp_workshare_save
!= -1)
9840 omp_workshare_flag
= omp_workshare_save
;
9844 if (code
->op
!= EXEC_COMPCALL
&& code
->op
!= EXEC_CALL_PPC
)
9845 t
= gfc_resolve_expr (code
->expr1
);
9846 forall_flag
= forall_save
;
9847 gfc_do_concurrent_flag
= do_concurrent_save
;
9849 if (!gfc_resolve_expr (code
->expr2
))
9852 if (code
->op
== EXEC_ALLOCATE
9853 && !gfc_resolve_expr (code
->expr3
))
9859 case EXEC_END_BLOCK
:
9860 case EXEC_END_NESTED_BLOCK
:
9864 case EXEC_ERROR_STOP
:
9868 case EXEC_ASSIGN_CALL
:
9873 case EXEC_SYNC_IMAGES
:
9874 case EXEC_SYNC_MEMORY
:
9875 resolve_sync (code
);
9880 resolve_lock_unlock (code
);
9884 /* Keep track of which entry we are up to. */
9885 current_entry_id
= code
->ext
.entry
->id
;
9889 resolve_where (code
, NULL
);
9893 if (code
->expr1
!= NULL
)
9895 if (code
->expr1
->ts
.type
!= BT_INTEGER
)
9896 gfc_error ("ASSIGNED GOTO statement at %L requires an "
9897 "INTEGER variable", &code
->expr1
->where
);
9898 else if (code
->expr1
->symtree
->n
.sym
->attr
.assign
!= 1)
9899 gfc_error ("Variable '%s' has not been assigned a target "
9900 "label at %L", code
->expr1
->symtree
->n
.sym
->name
,
9901 &code
->expr1
->where
);
9904 resolve_branch (code
->label1
, code
);
9908 if (code
->expr1
!= NULL
9909 && (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
))
9910 gfc_error ("Alternate RETURN statement at %L requires a SCALAR-"
9911 "INTEGER return specifier", &code
->expr1
->where
);
9914 case EXEC_INIT_ASSIGN
:
9915 case EXEC_END_PROCEDURE
:
9922 if (code
->expr1
->expr_type
== EXPR_FUNCTION
9923 && code
->expr1
->value
.function
.isym
9924 && code
->expr1
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
9925 remove_caf_get_intrinsic (code
->expr1
);
9927 if (!gfc_check_vardef_context (code
->expr1
, false, false, false,
9931 if (resolve_ordinary_assign (code
, ns
))
9933 if (code
->op
== EXEC_COMPCALL
)
9939 /* F03 7.4.1.3 for non-allocatable, non-pointer components. */
9940 if (code
->op
!= EXEC_CALL
&& code
->expr1
->ts
.type
== BT_DERIVED
9941 && code
->expr1
->ts
.u
.derived
->attr
.defined_assign_comp
)
9942 generate_component_assignments (&code
, ns
);
9946 case EXEC_LABEL_ASSIGN
:
9947 if (code
->label1
->defined
== ST_LABEL_UNKNOWN
)
9948 gfc_error ("Label %d referenced at %L is never defined",
9949 code
->label1
->value
, &code
->label1
->where
);
9951 && (code
->expr1
->expr_type
!= EXPR_VARIABLE
9952 || code
->expr1
->symtree
->n
.sym
->ts
.type
!= BT_INTEGER
9953 || code
->expr1
->symtree
->n
.sym
->ts
.kind
9954 != gfc_default_integer_kind
9955 || code
->expr1
->symtree
->n
.sym
->as
!= NULL
))
9956 gfc_error ("ASSIGN statement at %L requires a scalar "
9957 "default INTEGER variable", &code
->expr1
->where
);
9960 case EXEC_POINTER_ASSIGN
:
9967 /* This is both a variable definition and pointer assignment
9968 context, so check both of them. For rank remapping, a final
9969 array ref may be present on the LHS and fool gfc_expr_attr
9970 used in gfc_check_vardef_context. Remove it. */
9971 e
= remove_last_array_ref (code
->expr1
);
9972 t
= gfc_check_vardef_context (e
, true, false, false,
9973 _("pointer assignment"));
9975 t
= gfc_check_vardef_context (e
, false, false, false,
9976 _("pointer assignment"));
9981 gfc_check_pointer_assign (code
->expr1
, code
->expr2
);
9985 case EXEC_ARITHMETIC_IF
:
9987 && code
->expr1
->ts
.type
!= BT_INTEGER
9988 && code
->expr1
->ts
.type
!= BT_REAL
)
9989 gfc_error ("Arithmetic IF statement at %L requires a numeric "
9990 "expression", &code
->expr1
->where
);
9992 resolve_branch (code
->label1
, code
);
9993 resolve_branch (code
->label2
, code
);
9994 resolve_branch (code
->label3
, code
);
9998 if (t
&& code
->expr1
!= NULL
9999 && (code
->expr1
->ts
.type
!= BT_LOGICAL
10000 || code
->expr1
->rank
!= 0))
10001 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
10002 &code
->expr1
->where
);
10007 resolve_call (code
);
10010 case EXEC_COMPCALL
:
10012 resolve_typebound_subroutine (code
);
10015 case EXEC_CALL_PPC
:
10016 resolve_ppc_call (code
);
10020 /* Select is complicated. Also, a SELECT construct could be
10021 a transformed computed GOTO. */
10022 resolve_select (code
, false);
10025 case EXEC_SELECT_TYPE
:
10026 resolve_select_type (code
, ns
);
10030 resolve_block_construct (code
);
10034 if (code
->ext
.iterator
!= NULL
)
10036 gfc_iterator
*iter
= code
->ext
.iterator
;
10037 if (gfc_resolve_iterator (iter
, true, false))
10038 gfc_resolve_do_iterator (code
, iter
->var
->symtree
->n
.sym
);
10042 case EXEC_DO_WHILE
:
10043 if (code
->expr1
== NULL
)
10044 gfc_internal_error ("resolve_code(): No expression on DO WHILE");
10046 && (code
->expr1
->rank
!= 0
10047 || code
->expr1
->ts
.type
!= BT_LOGICAL
))
10048 gfc_error ("Exit condition of DO WHILE loop at %L must be "
10049 "a scalar LOGICAL expression", &code
->expr1
->where
);
10052 case EXEC_ALLOCATE
:
10054 resolve_allocate_deallocate (code
, "ALLOCATE");
10058 case EXEC_DEALLOCATE
:
10060 resolve_allocate_deallocate (code
, "DEALLOCATE");
10065 if (!gfc_resolve_open (code
->ext
.open
))
10068 resolve_branch (code
->ext
.open
->err
, code
);
10072 if (!gfc_resolve_close (code
->ext
.close
))
10075 resolve_branch (code
->ext
.close
->err
, code
);
10078 case EXEC_BACKSPACE
:
10082 if (!gfc_resolve_filepos (code
->ext
.filepos
))
10085 resolve_branch (code
->ext
.filepos
->err
, code
);
10089 if (!gfc_resolve_inquire (code
->ext
.inquire
))
10092 resolve_branch (code
->ext
.inquire
->err
, code
);
10095 case EXEC_IOLENGTH
:
10096 gcc_assert (code
->ext
.inquire
!= NULL
);
10097 if (!gfc_resolve_inquire (code
->ext
.inquire
))
10100 resolve_branch (code
->ext
.inquire
->err
, code
);
10104 if (!gfc_resolve_wait (code
->ext
.wait
))
10107 resolve_branch (code
->ext
.wait
->err
, code
);
10108 resolve_branch (code
->ext
.wait
->end
, code
);
10109 resolve_branch (code
->ext
.wait
->eor
, code
);
10114 if (!gfc_resolve_dt (code
->ext
.dt
, &code
->loc
))
10117 resolve_branch (code
->ext
.dt
->err
, code
);
10118 resolve_branch (code
->ext
.dt
->end
, code
);
10119 resolve_branch (code
->ext
.dt
->eor
, code
);
10122 case EXEC_TRANSFER
:
10123 resolve_transfer (code
);
10126 case EXEC_DO_CONCURRENT
:
10128 resolve_forall_iterators (code
->ext
.forall_iterator
);
10130 if (code
->expr1
!= NULL
10131 && (code
->expr1
->ts
.type
!= BT_LOGICAL
|| code
->expr1
->rank
))
10132 gfc_error ("FORALL mask clause at %L requires a scalar LOGICAL "
10133 "expression", &code
->expr1
->where
);
10136 case EXEC_OMP_ATOMIC
:
10137 case EXEC_OMP_BARRIER
:
10138 case EXEC_OMP_CANCEL
:
10139 case EXEC_OMP_CANCELLATION_POINT
:
10140 case EXEC_OMP_CRITICAL
:
10141 case EXEC_OMP_FLUSH
:
10143 case EXEC_OMP_DO_SIMD
:
10144 case EXEC_OMP_MASTER
:
10145 case EXEC_OMP_ORDERED
:
10146 case EXEC_OMP_SECTIONS
:
10147 case EXEC_OMP_SIMD
:
10148 case EXEC_OMP_SINGLE
:
10149 case EXEC_OMP_TASKGROUP
:
10150 case EXEC_OMP_TASKWAIT
:
10151 case EXEC_OMP_TASKYIELD
:
10152 case EXEC_OMP_WORKSHARE
:
10153 gfc_resolve_omp_directive (code
, ns
);
10156 case EXEC_OMP_PARALLEL
:
10157 case EXEC_OMP_PARALLEL_DO
:
10158 case EXEC_OMP_PARALLEL_DO_SIMD
:
10159 case EXEC_OMP_PARALLEL_SECTIONS
:
10160 case EXEC_OMP_PARALLEL_WORKSHARE
:
10161 case EXEC_OMP_TASK
:
10162 omp_workshare_save
= omp_workshare_flag
;
10163 omp_workshare_flag
= 0;
10164 gfc_resolve_omp_directive (code
, ns
);
10165 omp_workshare_flag
= omp_workshare_save
;
10169 gfc_internal_error ("resolve_code(): Bad statement code");
10173 cs_base
= frame
.prev
;
10177 /* Resolve initial values and make sure they are compatible with
10181 resolve_values (gfc_symbol
*sym
)
10185 if (sym
->value
== NULL
)
10188 if (sym
->value
->expr_type
== EXPR_STRUCTURE
)
10189 t
= resolve_structure_cons (sym
->value
, 1);
10191 t
= gfc_resolve_expr (sym
->value
);
10196 gfc_check_assign_symbol (sym
, NULL
, sym
->value
);
10200 /* Verify any BIND(C) derived types in the namespace so we can report errors
10201 for them once, rather than for each variable declared of that type. */
10204 resolve_bind_c_derived_types (gfc_symbol
*derived_sym
)
10206 if (derived_sym
!= NULL
&& derived_sym
->attr
.flavor
== FL_DERIVED
10207 && derived_sym
->attr
.is_bind_c
== 1)
10208 verify_bind_c_derived_type (derived_sym
);
10214 /* Verify that any binding labels used in a given namespace do not collide
10215 with the names or binding labels of any global symbols. Multiple INTERFACE
10216 for the same procedure are permitted. */
10219 gfc_verify_binding_labels (gfc_symbol
*sym
)
10222 const char *module
;
10224 if (!sym
|| !sym
->attr
.is_bind_c
|| sym
->attr
.is_iso_c
10225 || sym
->attr
.flavor
== FL_DERIVED
|| !sym
->binding_label
)
10228 gsym
= gfc_find_gsymbol (gfc_gsym_root
, sym
->binding_label
);
10231 module
= sym
->module
;
10232 else if (sym
->ns
&& sym
->ns
->proc_name
10233 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
10234 module
= sym
->ns
->proc_name
->name
;
10235 else if (sym
->ns
&& sym
->ns
->parent
10236 && sym
->ns
&& sym
->ns
->parent
->proc_name
10237 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
10238 module
= sym
->ns
->parent
->proc_name
->name
;
10244 && (gsym
->type
== GSYM_FUNCTION
|| gsym
->type
== GSYM_SUBROUTINE
)))
10247 gsym
= gfc_get_gsymbol (sym
->binding_label
);
10248 gsym
->where
= sym
->declared_at
;
10249 gsym
->sym_name
= sym
->name
;
10250 gsym
->binding_label
= sym
->binding_label
;
10251 gsym
->ns
= sym
->ns
;
10252 gsym
->mod_name
= module
;
10253 if (sym
->attr
.function
)
10254 gsym
->type
= GSYM_FUNCTION
;
10255 else if (sym
->attr
.subroutine
)
10256 gsym
->type
= GSYM_SUBROUTINE
;
10257 /* Mark as variable/procedure as defined, unless its an INTERFACE. */
10258 gsym
->defined
= sym
->attr
.if_source
!= IFSRC_IFBODY
;
10262 if (sym
->attr
.flavor
== FL_VARIABLE
&& gsym
->type
!= GSYM_UNKNOWN
)
10264 gfc_error ("Variable %s with binding label %s at %L uses the same global "
10265 "identifier as entity at %L", sym
->name
,
10266 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
10267 /* Clear the binding label to prevent checking multiple times. */
10268 sym
->binding_label
= NULL
;
10271 else if (sym
->attr
.flavor
== FL_VARIABLE
10272 && (strcmp (module
, gsym
->mod_name
) != 0
10273 || strcmp (sym
->name
, gsym
->sym_name
) != 0))
10275 /* This can only happen if the variable is defined in a module - if it
10276 isn't the same module, reject it. */
10277 gfc_error ("Variable %s from module %s with binding label %s at %L uses "
10278 "the same global identifier as entity at %L from module %s",
10279 sym
->name
, module
, sym
->binding_label
,
10280 &sym
->declared_at
, &gsym
->where
, gsym
->mod_name
);
10281 sym
->binding_label
= NULL
;
10283 else if ((sym
->attr
.function
|| sym
->attr
.subroutine
)
10284 && ((gsym
->type
!= GSYM_SUBROUTINE
&& gsym
->type
!= GSYM_FUNCTION
)
10285 || (gsym
->defined
&& sym
->attr
.if_source
!= IFSRC_IFBODY
))
10286 && sym
!= gsym
->ns
->proc_name
10287 && (module
!= gsym
->mod_name
10288 || strcmp (gsym
->sym_name
, sym
->name
) != 0
10289 || (module
&& strcmp (module
, gsym
->mod_name
) != 0)))
10291 /* Print an error if the procedure is defined multiple times; we have to
10292 exclude references to the same procedure via module association or
10293 multiple checks for the same procedure. */
10294 gfc_error ("Procedure %s with binding label %s at %L uses the same "
10295 "global identifier as entity at %L", sym
->name
,
10296 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
10297 sym
->binding_label
= NULL
;
10302 /* Resolve an index expression. */
10305 resolve_index_expr (gfc_expr
*e
)
10307 if (!gfc_resolve_expr (e
))
10310 if (!gfc_simplify_expr (e
, 0))
10313 if (!gfc_specification_expr (e
))
10320 /* Resolve a charlen structure. */
10323 resolve_charlen (gfc_charlen
*cl
)
10326 bool saved_specification_expr
;
10332 saved_specification_expr
= specification_expr
;
10333 specification_expr
= true;
10335 if (cl
->length_from_typespec
)
10337 if (!gfc_resolve_expr (cl
->length
))
10339 specification_expr
= saved_specification_expr
;
10343 if (!gfc_simplify_expr (cl
->length
, 0))
10345 specification_expr
= saved_specification_expr
;
10352 if (!resolve_index_expr (cl
->length
))
10354 specification_expr
= saved_specification_expr
;
10359 /* "If the character length parameter value evaluates to a negative
10360 value, the length of character entities declared is zero." */
10361 if (cl
->length
&& !gfc_extract_int (cl
->length
, &i
) && i
< 0)
10363 if (gfc_option
.warn_surprising
)
10364 gfc_warning_now ("CHARACTER variable at %L has negative length %d,"
10365 " the length has been set to zero",
10366 &cl
->length
->where
, i
);
10367 gfc_replace_expr (cl
->length
,
10368 gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 0));
10371 /* Check that the character length is not too large. */
10372 k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
10373 if (cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
10374 && cl
->length
->ts
.type
== BT_INTEGER
10375 && mpz_cmp (cl
->length
->value
.integer
, gfc_integer_kinds
[k
].huge
) > 0)
10377 gfc_error ("String length at %L is too large", &cl
->length
->where
);
10378 specification_expr
= saved_specification_expr
;
10382 specification_expr
= saved_specification_expr
;
10387 /* Test for non-constant shape arrays. */
10390 is_non_constant_shape_array (gfc_symbol
*sym
)
10396 not_constant
= false;
10397 if (sym
->as
!= NULL
)
10399 /* Unfortunately, !gfc_is_compile_time_shape hits a legal case that
10400 has not been simplified; parameter array references. Do the
10401 simplification now. */
10402 for (i
= 0; i
< sym
->as
->rank
+ sym
->as
->corank
; i
++)
10404 e
= sym
->as
->lower
[i
];
10405 if (e
&& (!resolve_index_expr(e
)
10406 || !gfc_is_constant_expr (e
)))
10407 not_constant
= true;
10408 e
= sym
->as
->upper
[i
];
10409 if (e
&& (!resolve_index_expr(e
)
10410 || !gfc_is_constant_expr (e
)))
10411 not_constant
= true;
10414 return not_constant
;
10417 /* Given a symbol and an initialization expression, add code to initialize
10418 the symbol to the function entry. */
10420 build_init_assign (gfc_symbol
*sym
, gfc_expr
*init
)
10424 gfc_namespace
*ns
= sym
->ns
;
10426 /* Search for the function namespace if this is a contained
10427 function without an explicit result. */
10428 if (sym
->attr
.function
&& sym
== sym
->result
10429 && sym
->name
!= sym
->ns
->proc_name
->name
)
10431 ns
= ns
->contained
;
10432 for (;ns
; ns
= ns
->sibling
)
10433 if (strcmp (ns
->proc_name
->name
, sym
->name
) == 0)
10439 gfc_free_expr (init
);
10443 /* Build an l-value expression for the result. */
10444 lval
= gfc_lval_expr_from_sym (sym
);
10446 /* Add the code at scope entry. */
10447 init_st
= gfc_get_code (EXEC_INIT_ASSIGN
);
10448 init_st
->next
= ns
->code
;
10449 ns
->code
= init_st
;
10451 /* Assign the default initializer to the l-value. */
10452 init_st
->loc
= sym
->declared_at
;
10453 init_st
->expr1
= lval
;
10454 init_st
->expr2
= init
;
10457 /* Assign the default initializer to a derived type variable or result. */
10460 apply_default_init (gfc_symbol
*sym
)
10462 gfc_expr
*init
= NULL
;
10464 if (sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
10467 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
)
10468 init
= gfc_default_initializer (&sym
->ts
);
10470 if (init
== NULL
&& sym
->ts
.type
!= BT_CLASS
)
10473 build_init_assign (sym
, init
);
10474 sym
->attr
.referenced
= 1;
10477 /* Build an initializer for a local integer, real, complex, logical, or
10478 character variable, based on the command line flags finit-local-zero,
10479 finit-integer=, finit-real=, finit-logical=, and finit-runtime. Returns
10480 null if the symbol should not have a default initialization. */
10482 build_default_init_expr (gfc_symbol
*sym
)
10485 gfc_expr
*init_expr
;
10488 /* These symbols should never have a default initialization. */
10489 if (sym
->attr
.allocatable
10490 || sym
->attr
.external
10492 || sym
->attr
.pointer
10493 || sym
->attr
.in_equivalence
10494 || sym
->attr
.in_common
10497 || sym
->attr
.cray_pointee
10498 || sym
->attr
.cray_pointer
10502 /* Now we'll try to build an initializer expression. */
10503 init_expr
= gfc_get_constant_expr (sym
->ts
.type
, sym
->ts
.kind
,
10504 &sym
->declared_at
);
10506 /* We will only initialize integers, reals, complex, logicals, and
10507 characters, and only if the corresponding command-line flags
10508 were set. Otherwise, we free init_expr and return null. */
10509 switch (sym
->ts
.type
)
10512 if (gfc_option
.flag_init_integer
!= GFC_INIT_INTEGER_OFF
)
10513 mpz_set_si (init_expr
->value
.integer
,
10514 gfc_option
.flag_init_integer_value
);
10517 gfc_free_expr (init_expr
);
10523 switch (gfc_option
.flag_init_real
)
10525 case GFC_INIT_REAL_SNAN
:
10526 init_expr
->is_snan
= 1;
10527 /* Fall through. */
10528 case GFC_INIT_REAL_NAN
:
10529 mpfr_set_nan (init_expr
->value
.real
);
10532 case GFC_INIT_REAL_INF
:
10533 mpfr_set_inf (init_expr
->value
.real
, 1);
10536 case GFC_INIT_REAL_NEG_INF
:
10537 mpfr_set_inf (init_expr
->value
.real
, -1);
10540 case GFC_INIT_REAL_ZERO
:
10541 mpfr_set_ui (init_expr
->value
.real
, 0.0, GFC_RND_MODE
);
10545 gfc_free_expr (init_expr
);
10552 switch (gfc_option
.flag_init_real
)
10554 case GFC_INIT_REAL_SNAN
:
10555 init_expr
->is_snan
= 1;
10556 /* Fall through. */
10557 case GFC_INIT_REAL_NAN
:
10558 mpfr_set_nan (mpc_realref (init_expr
->value
.complex));
10559 mpfr_set_nan (mpc_imagref (init_expr
->value
.complex));
10562 case GFC_INIT_REAL_INF
:
10563 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), 1);
10564 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), 1);
10567 case GFC_INIT_REAL_NEG_INF
:
10568 mpfr_set_inf (mpc_realref (init_expr
->value
.complex), -1);
10569 mpfr_set_inf (mpc_imagref (init_expr
->value
.complex), -1);
10572 case GFC_INIT_REAL_ZERO
:
10573 mpc_set_ui (init_expr
->value
.complex, 0, GFC_MPC_RND_MODE
);
10577 gfc_free_expr (init_expr
);
10584 if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_FALSE
)
10585 init_expr
->value
.logical
= 0;
10586 else if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_TRUE
)
10587 init_expr
->value
.logical
= 1;
10590 gfc_free_expr (init_expr
);
10596 /* For characters, the length must be constant in order to
10597 create a default initializer. */
10598 if (gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
10599 && sym
->ts
.u
.cl
->length
10600 && sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
10602 char_len
= mpz_get_si (sym
->ts
.u
.cl
->length
->value
.integer
);
10603 init_expr
->value
.character
.length
= char_len
;
10604 init_expr
->value
.character
.string
= gfc_get_wide_string (char_len
+1);
10605 for (i
= 0; i
< char_len
; i
++)
10606 init_expr
->value
.character
.string
[i
]
10607 = (unsigned char) gfc_option
.flag_init_character_value
;
10611 gfc_free_expr (init_expr
);
10614 if (!init_expr
&& gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
10615 && sym
->ts
.u
.cl
->length
&& gfc_option
.flag_max_stack_var_size
!= 0)
10617 gfc_actual_arglist
*arg
;
10618 init_expr
= gfc_get_expr ();
10619 init_expr
->where
= sym
->declared_at
;
10620 init_expr
->ts
= sym
->ts
;
10621 init_expr
->expr_type
= EXPR_FUNCTION
;
10622 init_expr
->value
.function
.isym
=
10623 gfc_intrinsic_function_by_id (GFC_ISYM_REPEAT
);
10624 init_expr
->value
.function
.name
= "repeat";
10625 arg
= gfc_get_actual_arglist ();
10626 arg
->expr
= gfc_get_character_expr (sym
->ts
.kind
, &sym
->declared_at
,
10628 arg
->expr
->value
.character
.string
[0]
10629 = gfc_option
.flag_init_character_value
;
10630 arg
->next
= gfc_get_actual_arglist ();
10631 arg
->next
->expr
= gfc_copy_expr (sym
->ts
.u
.cl
->length
);
10632 init_expr
->value
.function
.actual
= arg
;
10637 gfc_free_expr (init_expr
);
10643 /* Add an initialization expression to a local variable. */
10645 apply_default_init_local (gfc_symbol
*sym
)
10647 gfc_expr
*init
= NULL
;
10649 /* The symbol should be a variable or a function return value. */
10650 if ((sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
10651 || (sym
->attr
.function
&& sym
->result
!= sym
))
10654 /* Try to build the initializer expression. If we can't initialize
10655 this symbol, then init will be NULL. */
10656 init
= build_default_init_expr (sym
);
10660 /* For saved variables, we don't want to add an initializer at function
10661 entry, so we just add a static initializer. Note that automatic variables
10662 are stack allocated even with -fno-automatic; we have also to exclude
10663 result variable, which are also nonstatic. */
10664 if (sym
->attr
.save
|| sym
->ns
->save_all
10665 || (gfc_option
.flag_max_stack_var_size
== 0 && !sym
->attr
.result
10666 && (!sym
->attr
.dimension
|| !is_non_constant_shape_array (sym
))))
10668 /* Don't clobber an existing initializer! */
10669 gcc_assert (sym
->value
== NULL
);
10674 build_init_assign (sym
, init
);
10678 /* Resolution of common features of flavors variable and procedure. */
10681 resolve_fl_var_and_proc (gfc_symbol
*sym
, int mp_flag
)
10683 gfc_array_spec
*as
;
10685 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
10686 as
= CLASS_DATA (sym
)->as
;
10690 /* Constraints on deferred shape variable. */
10691 if (as
== NULL
|| as
->type
!= AS_DEFERRED
)
10693 bool pointer
, allocatable
, dimension
;
10695 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
10697 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
10698 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
10699 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
10703 pointer
= sym
->attr
.pointer
&& !sym
->attr
.select_type_temporary
;
10704 allocatable
= sym
->attr
.allocatable
;
10705 dimension
= sym
->attr
.dimension
;
10710 if (dimension
&& as
->type
!= AS_ASSUMED_RANK
)
10712 gfc_error ("Allocatable array '%s' at %L must have a deferred "
10713 "shape or assumed rank", sym
->name
, &sym
->declared_at
);
10716 else if (!gfc_notify_std (GFC_STD_F2003
, "Scalar object "
10717 "'%s' at %L may not be ALLOCATABLE",
10718 sym
->name
, &sym
->declared_at
))
10722 if (pointer
&& dimension
&& as
->type
!= AS_ASSUMED_RANK
)
10724 gfc_error ("Array pointer '%s' at %L must have a deferred shape or "
10725 "assumed rank", sym
->name
, &sym
->declared_at
);
10731 if (!mp_flag
&& !sym
->attr
.allocatable
&& !sym
->attr
.pointer
10732 && sym
->ts
.type
!= BT_CLASS
&& !sym
->assoc
)
10734 gfc_error ("Array '%s' at %L cannot have a deferred shape",
10735 sym
->name
, &sym
->declared_at
);
10740 /* Constraints on polymorphic variables. */
10741 if (sym
->ts
.type
== BT_CLASS
&& !(sym
->result
&& sym
->result
!= sym
))
10744 if (sym
->attr
.class_ok
10745 && !sym
->attr
.select_type_temporary
10746 && !UNLIMITED_POLY (sym
)
10747 && !gfc_type_is_extensible (CLASS_DATA (sym
)->ts
.u
.derived
))
10749 gfc_error ("Type '%s' of CLASS variable '%s' at %L is not extensible",
10750 CLASS_DATA (sym
)->ts
.u
.derived
->name
, sym
->name
,
10751 &sym
->declared_at
);
10756 /* Assume that use associated symbols were checked in the module ns.
10757 Class-variables that are associate-names are also something special
10758 and excepted from the test. */
10759 if (!sym
->attr
.class_ok
&& !sym
->attr
.use_assoc
&& !sym
->assoc
)
10761 gfc_error ("CLASS variable '%s' at %L must be dummy, allocatable "
10762 "or pointer", sym
->name
, &sym
->declared_at
);
10771 /* Additional checks for symbols with flavor variable and derived
10772 type. To be called from resolve_fl_variable. */
10775 resolve_fl_variable_derived (gfc_symbol
*sym
, int no_init_flag
)
10777 gcc_assert (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
);
10779 /* Check to see if a derived type is blocked from being host
10780 associated by the presence of another class I symbol in the same
10781 namespace. 14.6.1.3 of the standard and the discussion on
10782 comp.lang.fortran. */
10783 if (sym
->ns
!= sym
->ts
.u
.derived
->ns
10784 && sym
->ns
->proc_name
->attr
.if_source
!= IFSRC_IFBODY
)
10787 gfc_find_symbol (sym
->ts
.u
.derived
->name
, sym
->ns
, 0, &s
);
10788 if (s
&& s
->attr
.generic
)
10789 s
= gfc_find_dt_in_generic (s
);
10790 if (s
&& s
->attr
.flavor
!= FL_DERIVED
)
10792 gfc_error ("The type '%s' cannot be host associated at %L "
10793 "because it is blocked by an incompatible object "
10794 "of the same name declared at %L",
10795 sym
->ts
.u
.derived
->name
, &sym
->declared_at
,
10801 /* 4th constraint in section 11.3: "If an object of a type for which
10802 component-initialization is specified (R429) appears in the
10803 specification-part of a module and does not have the ALLOCATABLE
10804 or POINTER attribute, the object shall have the SAVE attribute."
10806 The check for initializers is performed with
10807 gfc_has_default_initializer because gfc_default_initializer generates
10808 a hidden default for allocatable components. */
10809 if (!(sym
->value
|| no_init_flag
) && sym
->ns
->proc_name
10810 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
10811 && !sym
->ns
->save_all
&& !sym
->attr
.save
10812 && !sym
->attr
.pointer
&& !sym
->attr
.allocatable
10813 && gfc_has_default_initializer (sym
->ts
.u
.derived
)
10814 && !gfc_notify_std (GFC_STD_F2008
, "Implied SAVE for module variable "
10815 "'%s' at %L, needed due to the default "
10816 "initialization", sym
->name
, &sym
->declared_at
))
10819 /* Assign default initializer. */
10820 if (!(sym
->value
|| sym
->attr
.pointer
|| sym
->attr
.allocatable
)
10821 && (!no_init_flag
|| sym
->attr
.intent
== INTENT_OUT
))
10823 sym
->value
= gfc_default_initializer (&sym
->ts
);
10830 /* Resolve symbols with flavor variable. */
10833 resolve_fl_variable (gfc_symbol
*sym
, int mp_flag
)
10835 int no_init_flag
, automatic_flag
;
10837 const char *auto_save_msg
;
10838 bool saved_specification_expr
;
10840 auto_save_msg
= "Automatic object '%s' at %L cannot have the "
10843 if (!resolve_fl_var_and_proc (sym
, mp_flag
))
10846 /* Set this flag to check that variables are parameters of all entries.
10847 This check is effected by the call to gfc_resolve_expr through
10848 is_non_constant_shape_array. */
10849 saved_specification_expr
= specification_expr
;
10850 specification_expr
= true;
10852 if (sym
->ns
->proc_name
10853 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
10854 || sym
->ns
->proc_name
->attr
.is_main_program
)
10855 && !sym
->attr
.use_assoc
10856 && !sym
->attr
.allocatable
10857 && !sym
->attr
.pointer
10858 && is_non_constant_shape_array (sym
))
10860 /* The shape of a main program or module array needs to be
10862 gfc_error ("The module or main program array '%s' at %L must "
10863 "have constant shape", sym
->name
, &sym
->declared_at
);
10864 specification_expr
= saved_specification_expr
;
10868 /* Constraints on deferred type parameter. */
10869 if (sym
->ts
.deferred
&& !(sym
->attr
.pointer
|| sym
->attr
.allocatable
))
10871 gfc_error ("Entity '%s' at %L has a deferred type parameter and "
10872 "requires either the pointer or allocatable attribute",
10873 sym
->name
, &sym
->declared_at
);
10874 specification_expr
= saved_specification_expr
;
10878 if (sym
->ts
.type
== BT_CHARACTER
)
10880 /* Make sure that character string variables with assumed length are
10881 dummy arguments. */
10882 e
= sym
->ts
.u
.cl
->length
;
10883 if (e
== NULL
&& !sym
->attr
.dummy
&& !sym
->attr
.result
10884 && !sym
->ts
.deferred
&& !sym
->attr
.select_type_temporary
)
10886 gfc_error ("Entity with assumed character length at %L must be a "
10887 "dummy argument or a PARAMETER", &sym
->declared_at
);
10888 specification_expr
= saved_specification_expr
;
10892 if (e
&& sym
->attr
.save
== SAVE_EXPLICIT
&& !gfc_is_constant_expr (e
))
10894 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
10895 specification_expr
= saved_specification_expr
;
10899 if (!gfc_is_constant_expr (e
)
10900 && !(e
->expr_type
== EXPR_VARIABLE
10901 && e
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
))
10903 if (!sym
->attr
.use_assoc
&& sym
->ns
->proc_name
10904 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
10905 || sym
->ns
->proc_name
->attr
.is_main_program
))
10907 gfc_error ("'%s' at %L must have constant character length "
10908 "in this context", sym
->name
, &sym
->declared_at
);
10909 specification_expr
= saved_specification_expr
;
10912 if (sym
->attr
.in_common
)
10914 gfc_error ("COMMON variable '%s' at %L must have constant "
10915 "character length", sym
->name
, &sym
->declared_at
);
10916 specification_expr
= saved_specification_expr
;
10922 if (sym
->value
== NULL
&& sym
->attr
.referenced
)
10923 apply_default_init_local (sym
); /* Try to apply a default initialization. */
10925 /* Determine if the symbol may not have an initializer. */
10926 no_init_flag
= automatic_flag
= 0;
10927 if (sym
->attr
.allocatable
|| sym
->attr
.external
|| sym
->attr
.dummy
10928 || sym
->attr
.intrinsic
|| sym
->attr
.result
)
10930 else if ((sym
->attr
.dimension
|| sym
->attr
.codimension
) && !sym
->attr
.pointer
10931 && is_non_constant_shape_array (sym
))
10933 no_init_flag
= automatic_flag
= 1;
10935 /* Also, they must not have the SAVE attribute.
10936 SAVE_IMPLICIT is checked below. */
10937 if (sym
->as
&& sym
->attr
.codimension
)
10939 int corank
= sym
->as
->corank
;
10940 sym
->as
->corank
= 0;
10941 no_init_flag
= automatic_flag
= is_non_constant_shape_array (sym
);
10942 sym
->as
->corank
= corank
;
10944 if (automatic_flag
&& sym
->attr
.save
== SAVE_EXPLICIT
)
10946 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
10947 specification_expr
= saved_specification_expr
;
10952 /* Ensure that any initializer is simplified. */
10954 gfc_simplify_expr (sym
->value
, 1);
10956 /* Reject illegal initializers. */
10957 if (!sym
->mark
&& sym
->value
)
10959 if (sym
->attr
.allocatable
|| (sym
->ts
.type
== BT_CLASS
10960 && CLASS_DATA (sym
)->attr
.allocatable
))
10961 gfc_error ("Allocatable '%s' at %L cannot have an initializer",
10962 sym
->name
, &sym
->declared_at
);
10963 else if (sym
->attr
.external
)
10964 gfc_error ("External '%s' at %L cannot have an initializer",
10965 sym
->name
, &sym
->declared_at
);
10966 else if (sym
->attr
.dummy
10967 && !(sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.intent
== INTENT_OUT
))
10968 gfc_error ("Dummy '%s' at %L cannot have an initializer",
10969 sym
->name
, &sym
->declared_at
);
10970 else if (sym
->attr
.intrinsic
)
10971 gfc_error ("Intrinsic '%s' at %L cannot have an initializer",
10972 sym
->name
, &sym
->declared_at
);
10973 else if (sym
->attr
.result
)
10974 gfc_error ("Function result '%s' at %L cannot have an initializer",
10975 sym
->name
, &sym
->declared_at
);
10976 else if (automatic_flag
)
10977 gfc_error ("Automatic array '%s' at %L cannot have an initializer",
10978 sym
->name
, &sym
->declared_at
);
10980 goto no_init_error
;
10981 specification_expr
= saved_specification_expr
;
10986 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
10988 bool res
= resolve_fl_variable_derived (sym
, no_init_flag
);
10989 specification_expr
= saved_specification_expr
;
10993 specification_expr
= saved_specification_expr
;
10998 /* Resolve a procedure. */
11001 resolve_fl_procedure (gfc_symbol
*sym
, int mp_flag
)
11003 gfc_formal_arglist
*arg
;
11005 if (sym
->attr
.function
11006 && !resolve_fl_var_and_proc (sym
, mp_flag
))
11009 if (sym
->ts
.type
== BT_CHARACTER
)
11011 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
11013 if (cl
&& cl
->length
&& gfc_is_constant_expr (cl
->length
)
11014 && !resolve_charlen (cl
))
11017 if ((!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
11018 && sym
->attr
.proc
== PROC_ST_FUNCTION
)
11020 gfc_error ("Character-valued statement function '%s' at %L must "
11021 "have constant length", sym
->name
, &sym
->declared_at
);
11026 /* Ensure that derived type for are not of a private type. Internal
11027 module procedures are excluded by 2.2.3.3 - i.e., they are not
11028 externally accessible and can access all the objects accessible in
11030 if (!(sym
->ns
->parent
11031 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
11032 && gfc_check_symbol_access (sym
))
11034 gfc_interface
*iface
;
11036 for (arg
= gfc_sym_get_dummy_args (sym
); arg
; arg
= arg
->next
)
11039 && arg
->sym
->ts
.type
== BT_DERIVED
11040 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
11041 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
11042 && !gfc_notify_std (GFC_STD_F2003
, "'%s' is of a PRIVATE type "
11043 "and cannot be a dummy argument"
11044 " of '%s', which is PUBLIC at %L",
11045 arg
->sym
->name
, sym
->name
,
11046 &sym
->declared_at
))
11048 /* Stop this message from recurring. */
11049 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
11054 /* PUBLIC interfaces may expose PRIVATE procedures that take types
11055 PRIVATE to the containing module. */
11056 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
11058 for (arg
= gfc_sym_get_dummy_args (iface
->sym
); arg
; arg
= arg
->next
)
11061 && arg
->sym
->ts
.type
== BT_DERIVED
11062 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
11063 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
11064 && !gfc_notify_std (GFC_STD_F2003
, "Procedure '%s' in "
11065 "PUBLIC interface '%s' at %L "
11066 "takes dummy arguments of '%s' which "
11067 "is PRIVATE", iface
->sym
->name
,
11068 sym
->name
, &iface
->sym
->declared_at
,
11069 gfc_typename(&arg
->sym
->ts
)))
11071 /* Stop this message from recurring. */
11072 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
11078 /* PUBLIC interfaces may expose PRIVATE procedures that take types
11079 PRIVATE to the containing module. */
11080 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
11082 for (arg
= gfc_sym_get_dummy_args (iface
->sym
); arg
; arg
= arg
->next
)
11085 && arg
->sym
->ts
.type
== BT_DERIVED
11086 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
11087 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
11088 && !gfc_notify_std (GFC_STD_F2003
, "Procedure '%s' in "
11089 "PUBLIC interface '%s' at %L takes "
11090 "dummy arguments of '%s' which is "
11091 "PRIVATE", iface
->sym
->name
,
11092 sym
->name
, &iface
->sym
->declared_at
,
11093 gfc_typename(&arg
->sym
->ts
)))
11095 /* Stop this message from recurring. */
11096 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
11103 if (sym
->attr
.function
&& sym
->value
&& sym
->attr
.proc
!= PROC_ST_FUNCTION
11104 && !sym
->attr
.proc_pointer
)
11106 gfc_error ("Function '%s' at %L cannot have an initializer",
11107 sym
->name
, &sym
->declared_at
);
11111 /* An external symbol may not have an initializer because it is taken to be
11112 a procedure. Exception: Procedure Pointers. */
11113 if (sym
->attr
.external
&& sym
->value
&& !sym
->attr
.proc_pointer
)
11115 gfc_error ("External object '%s' at %L may not have an initializer",
11116 sym
->name
, &sym
->declared_at
);
11120 /* An elemental function is required to return a scalar 12.7.1 */
11121 if (sym
->attr
.elemental
&& sym
->attr
.function
&& sym
->as
)
11123 gfc_error ("ELEMENTAL function '%s' at %L must have a scalar "
11124 "result", sym
->name
, &sym
->declared_at
);
11125 /* Reset so that the error only occurs once. */
11126 sym
->attr
.elemental
= 0;
11130 if (sym
->attr
.proc
== PROC_ST_FUNCTION
11131 && (sym
->attr
.allocatable
|| sym
->attr
.pointer
))
11133 gfc_error ("Statement function '%s' at %L may not have pointer or "
11134 "allocatable attribute", sym
->name
, &sym
->declared_at
);
11138 /* 5.1.1.5 of the Standard: A function name declared with an asterisk
11139 char-len-param shall not be array-valued, pointer-valued, recursive
11140 or pure. ....snip... A character value of * may only be used in the
11141 following ways: (i) Dummy arg of procedure - dummy associates with
11142 actual length; (ii) To declare a named constant; or (iii) External
11143 function - but length must be declared in calling scoping unit. */
11144 if (sym
->attr
.function
11145 && sym
->ts
.type
== BT_CHARACTER
&& !sym
->ts
.deferred
11146 && sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
== NULL
)
11148 if ((sym
->as
&& sym
->as
->rank
) || (sym
->attr
.pointer
)
11149 || (sym
->attr
.recursive
) || (sym
->attr
.pure
))
11151 if (sym
->as
&& sym
->as
->rank
)
11152 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
11153 "array-valued", sym
->name
, &sym
->declared_at
);
11155 if (sym
->attr
.pointer
)
11156 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
11157 "pointer-valued", sym
->name
, &sym
->declared_at
);
11159 if (sym
->attr
.pure
)
11160 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
11161 "pure", sym
->name
, &sym
->declared_at
);
11163 if (sym
->attr
.recursive
)
11164 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
11165 "recursive", sym
->name
, &sym
->declared_at
);
11170 /* Appendix B.2 of the standard. Contained functions give an
11171 error anyway. Fixed-form is likely to be F77/legacy. Deferred
11172 character length is an F2003 feature. */
11173 if (!sym
->attr
.contained
11174 && gfc_current_form
!= FORM_FIXED
11175 && !sym
->ts
.deferred
)
11176 gfc_notify_std (GFC_STD_F95_OBS
,
11177 "CHARACTER(*) function '%s' at %L",
11178 sym
->name
, &sym
->declared_at
);
11181 /* F2008, C1218. */
11182 if (sym
->attr
.elemental
)
11184 if (sym
->attr
.proc_pointer
)
11186 gfc_error ("Procedure pointer '%s' at %L shall not be elemental",
11187 sym
->name
, &sym
->declared_at
);
11190 if (sym
->attr
.dummy
)
11192 gfc_error ("Dummy procedure '%s' at %L shall not be elemental",
11193 sym
->name
, &sym
->declared_at
);
11198 if (sym
->attr
.is_bind_c
&& sym
->attr
.is_c_interop
!= 1)
11200 gfc_formal_arglist
*curr_arg
;
11201 int has_non_interop_arg
= 0;
11203 if (!verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
11204 sym
->common_block
))
11206 /* Clear these to prevent looking at them again if there was an
11208 sym
->attr
.is_bind_c
= 0;
11209 sym
->attr
.is_c_interop
= 0;
11210 sym
->ts
.is_c_interop
= 0;
11214 /* So far, no errors have been found. */
11215 sym
->attr
.is_c_interop
= 1;
11216 sym
->ts
.is_c_interop
= 1;
11219 curr_arg
= gfc_sym_get_dummy_args (sym
);
11220 while (curr_arg
!= NULL
)
11222 /* Skip implicitly typed dummy args here. */
11223 if (curr_arg
->sym
->attr
.implicit_type
== 0)
11224 if (!gfc_verify_c_interop_param (curr_arg
->sym
))
11225 /* If something is found to fail, record the fact so we
11226 can mark the symbol for the procedure as not being
11227 BIND(C) to try and prevent multiple errors being
11229 has_non_interop_arg
= 1;
11231 curr_arg
= curr_arg
->next
;
11234 /* See if any of the arguments were not interoperable and if so, clear
11235 the procedure symbol to prevent duplicate error messages. */
11236 if (has_non_interop_arg
!= 0)
11238 sym
->attr
.is_c_interop
= 0;
11239 sym
->ts
.is_c_interop
= 0;
11240 sym
->attr
.is_bind_c
= 0;
11244 if (!sym
->attr
.proc_pointer
)
11246 if (sym
->attr
.save
== SAVE_EXPLICIT
)
11248 gfc_error ("PROCEDURE attribute conflicts with SAVE attribute "
11249 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
11252 if (sym
->attr
.intent
)
11254 gfc_error ("PROCEDURE attribute conflicts with INTENT attribute "
11255 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
11258 if (sym
->attr
.subroutine
&& sym
->attr
.result
)
11260 gfc_error ("PROCEDURE attribute conflicts with RESULT attribute "
11261 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
11264 if (sym
->attr
.external
&& sym
->attr
.function
11265 && ((sym
->attr
.if_source
== IFSRC_DECL
&& !sym
->attr
.procedure
)
11266 || sym
->attr
.contained
))
11268 gfc_error ("EXTERNAL attribute conflicts with FUNCTION attribute "
11269 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
11272 if (strcmp ("ppr@", sym
->name
) == 0)
11274 gfc_error ("Procedure pointer result '%s' at %L "
11275 "is missing the pointer attribute",
11276 sym
->ns
->proc_name
->name
, &sym
->declared_at
);
11285 /* Resolve a list of finalizer procedures. That is, after they have hopefully
11286 been defined and we now know their defined arguments, check that they fulfill
11287 the requirements of the standard for procedures used as finalizers. */
11290 gfc_resolve_finalizers (gfc_symbol
* derived
, bool *finalizable
)
11292 gfc_finalizer
* list
;
11293 gfc_finalizer
** prev_link
; /* For removing wrong entries from the list. */
11294 bool result
= true;
11295 bool seen_scalar
= false;
11299 /* Return early when not finalizable. Additionally, ensure that derived-type
11300 components have a their finalizables resolved. */
11301 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->finalizers
)
11303 bool has_final
= false;
11304 for (c
= derived
->components
; c
; c
= c
->next
)
11305 if (c
->ts
.type
== BT_DERIVED
11306 && !c
->attr
.pointer
&& !c
->attr
.proc_pointer
&& !c
->attr
.allocatable
)
11308 bool has_final2
= false;
11309 if (!gfc_resolve_finalizers (c
->ts
.u
.derived
, &has_final
))
11310 return false; /* Error. */
11311 has_final
= has_final
|| has_final2
;
11316 *finalizable
= false;
11321 /* Walk over the list of finalizer-procedures, check them, and if any one
11322 does not fit in with the standard's definition, print an error and remove
11323 it from the list. */
11324 prev_link
= &derived
->f2k_derived
->finalizers
;
11325 for (list
= derived
->f2k_derived
->finalizers
; list
; list
= *prev_link
)
11327 gfc_formal_arglist
*dummy_args
;
11332 /* Skip this finalizer if we already resolved it. */
11333 if (list
->proc_tree
)
11335 prev_link
= &(list
->next
);
11339 /* Check this exists and is a SUBROUTINE. */
11340 if (!list
->proc_sym
->attr
.subroutine
)
11342 gfc_error ("FINAL procedure '%s' at %L is not a SUBROUTINE",
11343 list
->proc_sym
->name
, &list
->where
);
11347 /* We should have exactly one argument. */
11348 dummy_args
= gfc_sym_get_dummy_args (list
->proc_sym
);
11349 if (!dummy_args
|| dummy_args
->next
)
11351 gfc_error ("FINAL procedure at %L must have exactly one argument",
11355 arg
= dummy_args
->sym
;
11357 /* This argument must be of our type. */
11358 if (arg
->ts
.type
!= BT_DERIVED
|| arg
->ts
.u
.derived
!= derived
)
11360 gfc_error ("Argument of FINAL procedure at %L must be of type '%s'",
11361 &arg
->declared_at
, derived
->name
);
11365 /* It must neither be a pointer nor allocatable nor optional. */
11366 if (arg
->attr
.pointer
)
11368 gfc_error ("Argument of FINAL procedure at %L must not be a POINTER",
11369 &arg
->declared_at
);
11372 if (arg
->attr
.allocatable
)
11374 gfc_error ("Argument of FINAL procedure at %L must not be"
11375 " ALLOCATABLE", &arg
->declared_at
);
11378 if (arg
->attr
.optional
)
11380 gfc_error ("Argument of FINAL procedure at %L must not be OPTIONAL",
11381 &arg
->declared_at
);
11385 /* It must not be INTENT(OUT). */
11386 if (arg
->attr
.intent
== INTENT_OUT
)
11388 gfc_error ("Argument of FINAL procedure at %L must not be"
11389 " INTENT(OUT)", &arg
->declared_at
);
11393 /* Warn if the procedure is non-scalar and not assumed shape. */
11394 if (gfc_option
.warn_surprising
&& arg
->as
&& arg
->as
->rank
!= 0
11395 && arg
->as
->type
!= AS_ASSUMED_SHAPE
)
11396 gfc_warning ("Non-scalar FINAL procedure at %L should have assumed"
11397 " shape argument", &arg
->declared_at
);
11399 /* Check that it does not match in kind and rank with a FINAL procedure
11400 defined earlier. To really loop over the *earlier* declarations,
11401 we need to walk the tail of the list as new ones were pushed at the
11403 /* TODO: Handle kind parameters once they are implemented. */
11404 my_rank
= (arg
->as
? arg
->as
->rank
: 0);
11405 for (i
= list
->next
; i
; i
= i
->next
)
11407 gfc_formal_arglist
*dummy_args
;
11409 /* Argument list might be empty; that is an error signalled earlier,
11410 but we nevertheless continued resolving. */
11411 dummy_args
= gfc_sym_get_dummy_args (i
->proc_sym
);
11414 gfc_symbol
* i_arg
= dummy_args
->sym
;
11415 const int i_rank
= (i_arg
->as
? i_arg
->as
->rank
: 0);
11416 if (i_rank
== my_rank
)
11418 gfc_error ("FINAL procedure '%s' declared at %L has the same"
11419 " rank (%d) as '%s'",
11420 list
->proc_sym
->name
, &list
->where
, my_rank
,
11421 i
->proc_sym
->name
);
11427 /* Is this the/a scalar finalizer procedure? */
11428 if (!arg
->as
|| arg
->as
->rank
== 0)
11429 seen_scalar
= true;
11431 /* Find the symtree for this procedure. */
11432 gcc_assert (!list
->proc_tree
);
11433 list
->proc_tree
= gfc_find_sym_in_symtree (list
->proc_sym
);
11435 prev_link
= &list
->next
;
11438 /* Remove wrong nodes immediately from the list so we don't risk any
11439 troubles in the future when they might fail later expectations. */
11442 *prev_link
= list
->next
;
11443 gfc_free_finalizer (i
);
11447 if (result
== false)
11450 /* Warn if we haven't seen a scalar finalizer procedure (but we know there
11451 were nodes in the list, must have been for arrays. It is surely a good
11452 idea to have a scalar version there if there's something to finalize. */
11453 if (gfc_option
.warn_surprising
&& result
&& !seen_scalar
)
11454 gfc_warning ("Only array FINAL procedures declared for derived type '%s'"
11455 " defined at %L, suggest also scalar one",
11456 derived
->name
, &derived
->declared_at
);
11458 vtab
= gfc_find_derived_vtab (derived
);
11459 c
= vtab
->ts
.u
.derived
->components
->next
->next
->next
->next
->next
;
11460 gfc_set_sym_referenced (c
->initializer
->symtree
->n
.sym
);
11463 *finalizable
= true;
11469 /* Check if two GENERIC targets are ambiguous and emit an error is they are. */
11472 check_generic_tbp_ambiguity (gfc_tbp_generic
* t1
, gfc_tbp_generic
* t2
,
11473 const char* generic_name
, locus where
)
11475 gfc_symbol
*sym1
, *sym2
;
11476 const char *pass1
, *pass2
;
11477 gfc_formal_arglist
*dummy_args
;
11479 gcc_assert (t1
->specific
&& t2
->specific
);
11480 gcc_assert (!t1
->specific
->is_generic
);
11481 gcc_assert (!t2
->specific
->is_generic
);
11482 gcc_assert (t1
->is_operator
== t2
->is_operator
);
11484 sym1
= t1
->specific
->u
.specific
->n
.sym
;
11485 sym2
= t2
->specific
->u
.specific
->n
.sym
;
11490 /* Both must be SUBROUTINEs or both must be FUNCTIONs. */
11491 if (sym1
->attr
.subroutine
!= sym2
->attr
.subroutine
11492 || sym1
->attr
.function
!= sym2
->attr
.function
)
11494 gfc_error ("'%s' and '%s' can't be mixed FUNCTION/SUBROUTINE for"
11495 " GENERIC '%s' at %L",
11496 sym1
->name
, sym2
->name
, generic_name
, &where
);
11500 /* Determine PASS arguments. */
11501 if (t1
->specific
->nopass
)
11503 else if (t1
->specific
->pass_arg
)
11504 pass1
= t1
->specific
->pass_arg
;
11507 dummy_args
= gfc_sym_get_dummy_args (t1
->specific
->u
.specific
->n
.sym
);
11509 pass1
= dummy_args
->sym
->name
;
11513 if (t2
->specific
->nopass
)
11515 else if (t2
->specific
->pass_arg
)
11516 pass2
= t2
->specific
->pass_arg
;
11519 dummy_args
= gfc_sym_get_dummy_args (t2
->specific
->u
.specific
->n
.sym
);
11521 pass2
= dummy_args
->sym
->name
;
11526 /* Compare the interfaces. */
11527 if (gfc_compare_interfaces (sym1
, sym2
, sym2
->name
, !t1
->is_operator
, 0,
11528 NULL
, 0, pass1
, pass2
))
11530 gfc_error ("'%s' and '%s' for GENERIC '%s' at %L are ambiguous",
11531 sym1
->name
, sym2
->name
, generic_name
, &where
);
11539 /* Worker function for resolving a generic procedure binding; this is used to
11540 resolve GENERIC as well as user and intrinsic OPERATOR typebound procedures.
11542 The difference between those cases is finding possible inherited bindings
11543 that are overridden, as one has to look for them in tb_sym_root,
11544 tb_uop_root or tb_op, respectively. Thus the caller must already find
11545 the super-type and set p->overridden correctly. */
11548 resolve_tb_generic_targets (gfc_symbol
* super_type
,
11549 gfc_typebound_proc
* p
, const char* name
)
11551 gfc_tbp_generic
* target
;
11552 gfc_symtree
* first_target
;
11553 gfc_symtree
* inherited
;
11555 gcc_assert (p
&& p
->is_generic
);
11557 /* Try to find the specific bindings for the symtrees in our target-list. */
11558 gcc_assert (p
->u
.generic
);
11559 for (target
= p
->u
.generic
; target
; target
= target
->next
)
11560 if (!target
->specific
)
11562 gfc_typebound_proc
* overridden_tbp
;
11563 gfc_tbp_generic
* g
;
11564 const char* target_name
;
11566 target_name
= target
->specific_st
->name
;
11568 /* Defined for this type directly. */
11569 if (target
->specific_st
->n
.tb
&& !target
->specific_st
->n
.tb
->error
)
11571 target
->specific
= target
->specific_st
->n
.tb
;
11572 goto specific_found
;
11575 /* Look for an inherited specific binding. */
11578 inherited
= gfc_find_typebound_proc (super_type
, NULL
, target_name
,
11583 gcc_assert (inherited
->n
.tb
);
11584 target
->specific
= inherited
->n
.tb
;
11585 goto specific_found
;
11589 gfc_error ("Undefined specific binding '%s' as target of GENERIC '%s'"
11590 " at %L", target_name
, name
, &p
->where
);
11593 /* Once we've found the specific binding, check it is not ambiguous with
11594 other specifics already found or inherited for the same GENERIC. */
11596 gcc_assert (target
->specific
);
11598 /* This must really be a specific binding! */
11599 if (target
->specific
->is_generic
)
11601 gfc_error ("GENERIC '%s' at %L must target a specific binding,"
11602 " '%s' is GENERIC, too", name
, &p
->where
, target_name
);
11606 /* Check those already resolved on this type directly. */
11607 for (g
= p
->u
.generic
; g
; g
= g
->next
)
11608 if (g
!= target
&& g
->specific
11609 && !check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
11612 /* Check for ambiguity with inherited specific targets. */
11613 for (overridden_tbp
= p
->overridden
; overridden_tbp
;
11614 overridden_tbp
= overridden_tbp
->overridden
)
11615 if (overridden_tbp
->is_generic
)
11617 for (g
= overridden_tbp
->u
.generic
; g
; g
= g
->next
)
11619 gcc_assert (g
->specific
);
11620 if (!check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
11626 /* If we attempt to "overwrite" a specific binding, this is an error. */
11627 if (p
->overridden
&& !p
->overridden
->is_generic
)
11629 gfc_error ("GENERIC '%s' at %L can't overwrite specific binding with"
11630 " the same name", name
, &p
->where
);
11634 /* Take the SUBROUTINE/FUNCTION attributes of the first specific target, as
11635 all must have the same attributes here. */
11636 first_target
= p
->u
.generic
->specific
->u
.specific
;
11637 gcc_assert (first_target
);
11638 p
->subroutine
= first_target
->n
.sym
->attr
.subroutine
;
11639 p
->function
= first_target
->n
.sym
->attr
.function
;
11645 /* Resolve a GENERIC procedure binding for a derived type. */
11648 resolve_typebound_generic (gfc_symbol
* derived
, gfc_symtree
* st
)
11650 gfc_symbol
* super_type
;
11652 /* Find the overridden binding if any. */
11653 st
->n
.tb
->overridden
= NULL
;
11654 super_type
= gfc_get_derived_super_type (derived
);
11657 gfc_symtree
* overridden
;
11658 overridden
= gfc_find_typebound_proc (super_type
, NULL
, st
->name
,
11661 if (overridden
&& overridden
->n
.tb
)
11662 st
->n
.tb
->overridden
= overridden
->n
.tb
;
11665 /* Resolve using worker function. */
11666 return resolve_tb_generic_targets (super_type
, st
->n
.tb
, st
->name
);
11670 /* Retrieve the target-procedure of an operator binding and do some checks in
11671 common for intrinsic and user-defined type-bound operators. */
11674 get_checked_tb_operator_target (gfc_tbp_generic
* target
, locus where
)
11676 gfc_symbol
* target_proc
;
11678 gcc_assert (target
->specific
&& !target
->specific
->is_generic
);
11679 target_proc
= target
->specific
->u
.specific
->n
.sym
;
11680 gcc_assert (target_proc
);
11682 /* F08:C468. All operator bindings must have a passed-object dummy argument. */
11683 if (target
->specific
->nopass
)
11685 gfc_error ("Type-bound operator at %L can't be NOPASS", &where
);
11689 return target_proc
;
11693 /* Resolve a type-bound intrinsic operator. */
11696 resolve_typebound_intrinsic_op (gfc_symbol
* derived
, gfc_intrinsic_op op
,
11697 gfc_typebound_proc
* p
)
11699 gfc_symbol
* super_type
;
11700 gfc_tbp_generic
* target
;
11702 /* If there's already an error here, do nothing (but don't fail again). */
11706 /* Operators should always be GENERIC bindings. */
11707 gcc_assert (p
->is_generic
);
11709 /* Look for an overridden binding. */
11710 super_type
= gfc_get_derived_super_type (derived
);
11711 if (super_type
&& super_type
->f2k_derived
)
11712 p
->overridden
= gfc_find_typebound_intrinsic_op (super_type
, NULL
,
11715 p
->overridden
= NULL
;
11717 /* Resolve general GENERIC properties using worker function. */
11718 if (!resolve_tb_generic_targets (super_type
, p
, gfc_op2string(op
)))
11721 /* Check the targets to be procedures of correct interface. */
11722 for (target
= p
->u
.generic
; target
; target
= target
->next
)
11724 gfc_symbol
* target_proc
;
11726 target_proc
= get_checked_tb_operator_target (target
, p
->where
);
11730 if (!gfc_check_operator_interface (target_proc
, op
, p
->where
))
11733 /* Add target to non-typebound operator list. */
11734 if (!target
->specific
->deferred
&& !derived
->attr
.use_assoc
11735 && p
->access
!= ACCESS_PRIVATE
&& derived
->ns
== gfc_current_ns
)
11737 gfc_interface
*head
, *intr
;
11738 if (!gfc_check_new_interface (derived
->ns
->op
[op
], target_proc
, p
->where
))
11740 head
= derived
->ns
->op
[op
];
11741 intr
= gfc_get_interface ();
11742 intr
->sym
= target_proc
;
11743 intr
->where
= p
->where
;
11745 derived
->ns
->op
[op
] = intr
;
11757 /* Resolve a type-bound user operator (tree-walker callback). */
11759 static gfc_symbol
* resolve_bindings_derived
;
11760 static bool resolve_bindings_result
;
11762 static bool check_uop_procedure (gfc_symbol
* sym
, locus where
);
11765 resolve_typebound_user_op (gfc_symtree
* stree
)
11767 gfc_symbol
* super_type
;
11768 gfc_tbp_generic
* target
;
11770 gcc_assert (stree
&& stree
->n
.tb
);
11772 if (stree
->n
.tb
->error
)
11775 /* Operators should always be GENERIC bindings. */
11776 gcc_assert (stree
->n
.tb
->is_generic
);
11778 /* Find overridden procedure, if any. */
11779 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
11780 if (super_type
&& super_type
->f2k_derived
)
11782 gfc_symtree
* overridden
;
11783 overridden
= gfc_find_typebound_user_op (super_type
, NULL
,
11784 stree
->name
, true, NULL
);
11786 if (overridden
&& overridden
->n
.tb
)
11787 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
11790 stree
->n
.tb
->overridden
= NULL
;
11792 /* Resolve basically using worker function. */
11793 if (!resolve_tb_generic_targets (super_type
, stree
->n
.tb
, stree
->name
))
11796 /* Check the targets to be functions of correct interface. */
11797 for (target
= stree
->n
.tb
->u
.generic
; target
; target
= target
->next
)
11799 gfc_symbol
* target_proc
;
11801 target_proc
= get_checked_tb_operator_target (target
, stree
->n
.tb
->where
);
11805 if (!check_uop_procedure (target_proc
, stree
->n
.tb
->where
))
11812 resolve_bindings_result
= false;
11813 stree
->n
.tb
->error
= 1;
11817 /* Resolve the type-bound procedures for a derived type. */
11820 resolve_typebound_procedure (gfc_symtree
* stree
)
11824 gfc_symbol
* me_arg
;
11825 gfc_symbol
* super_type
;
11826 gfc_component
* comp
;
11828 gcc_assert (stree
);
11830 /* Undefined specific symbol from GENERIC target definition. */
11834 if (stree
->n
.tb
->error
)
11837 /* If this is a GENERIC binding, use that routine. */
11838 if (stree
->n
.tb
->is_generic
)
11840 if (!resolve_typebound_generic (resolve_bindings_derived
, stree
))
11845 /* Get the target-procedure to check it. */
11846 gcc_assert (!stree
->n
.tb
->is_generic
);
11847 gcc_assert (stree
->n
.tb
->u
.specific
);
11848 proc
= stree
->n
.tb
->u
.specific
->n
.sym
;
11849 where
= stree
->n
.tb
->where
;
11851 /* Default access should already be resolved from the parser. */
11852 gcc_assert (stree
->n
.tb
->access
!= ACCESS_UNKNOWN
);
11854 if (stree
->n
.tb
->deferred
)
11856 if (!check_proc_interface (proc
, &where
))
11861 /* Check for F08:C465. */
11862 if ((!proc
->attr
.subroutine
&& !proc
->attr
.function
)
11863 || (proc
->attr
.proc
!= PROC_MODULE
11864 && proc
->attr
.if_source
!= IFSRC_IFBODY
)
11865 || proc
->attr
.abstract
)
11867 gfc_error ("'%s' must be a module procedure or an external procedure with"
11868 " an explicit interface at %L", proc
->name
, &where
);
11873 stree
->n
.tb
->subroutine
= proc
->attr
.subroutine
;
11874 stree
->n
.tb
->function
= proc
->attr
.function
;
11876 /* Find the super-type of the current derived type. We could do this once and
11877 store in a global if speed is needed, but as long as not I believe this is
11878 more readable and clearer. */
11879 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
11881 /* If PASS, resolve and check arguments if not already resolved / loaded
11882 from a .mod file. */
11883 if (!stree
->n
.tb
->nopass
&& stree
->n
.tb
->pass_arg_num
== 0)
11885 gfc_formal_arglist
*dummy_args
;
11887 dummy_args
= gfc_sym_get_dummy_args (proc
);
11888 if (stree
->n
.tb
->pass_arg
)
11890 gfc_formal_arglist
*i
;
11892 /* If an explicit passing argument name is given, walk the arg-list
11893 and look for it. */
11896 stree
->n
.tb
->pass_arg_num
= 1;
11897 for (i
= dummy_args
; i
; i
= i
->next
)
11899 if (!strcmp (i
->sym
->name
, stree
->n
.tb
->pass_arg
))
11904 ++stree
->n
.tb
->pass_arg_num
;
11909 gfc_error ("Procedure '%s' with PASS(%s) at %L has no"
11911 proc
->name
, stree
->n
.tb
->pass_arg
, &where
,
11912 stree
->n
.tb
->pass_arg
);
11918 /* Otherwise, take the first one; there should in fact be at least
11920 stree
->n
.tb
->pass_arg_num
= 1;
11923 gfc_error ("Procedure '%s' with PASS at %L must have at"
11924 " least one argument", proc
->name
, &where
);
11927 me_arg
= dummy_args
->sym
;
11930 /* Now check that the argument-type matches and the passed-object
11931 dummy argument is generally fine. */
11933 gcc_assert (me_arg
);
11935 if (me_arg
->ts
.type
!= BT_CLASS
)
11937 gfc_error ("Non-polymorphic passed-object dummy argument of '%s'"
11938 " at %L", proc
->name
, &where
);
11942 if (CLASS_DATA (me_arg
)->ts
.u
.derived
11943 != resolve_bindings_derived
)
11945 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L must be of"
11946 " the derived-type '%s'", me_arg
->name
, proc
->name
,
11947 me_arg
->name
, &where
, resolve_bindings_derived
->name
);
11951 gcc_assert (me_arg
->ts
.type
== BT_CLASS
);
11952 if (CLASS_DATA (me_arg
)->as
&& CLASS_DATA (me_arg
)->as
->rank
!= 0)
11954 gfc_error ("Passed-object dummy argument of '%s' at %L must be"
11955 " scalar", proc
->name
, &where
);
11958 if (CLASS_DATA (me_arg
)->attr
.allocatable
)
11960 gfc_error ("Passed-object dummy argument of '%s' at %L must not"
11961 " be ALLOCATABLE", proc
->name
, &where
);
11964 if (CLASS_DATA (me_arg
)->attr
.class_pointer
)
11966 gfc_error ("Passed-object dummy argument of '%s' at %L must not"
11967 " be POINTER", proc
->name
, &where
);
11972 /* If we are extending some type, check that we don't override a procedure
11973 flagged NON_OVERRIDABLE. */
11974 stree
->n
.tb
->overridden
= NULL
;
11977 gfc_symtree
* overridden
;
11978 overridden
= gfc_find_typebound_proc (super_type
, NULL
,
11979 stree
->name
, true, NULL
);
11983 if (overridden
->n
.tb
)
11984 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
11986 if (!gfc_check_typebound_override (stree
, overridden
))
11991 /* See if there's a name collision with a component directly in this type. */
11992 for (comp
= resolve_bindings_derived
->components
; comp
; comp
= comp
->next
)
11993 if (!strcmp (comp
->name
, stree
->name
))
11995 gfc_error ("Procedure '%s' at %L has the same name as a component of"
11997 stree
->name
, &where
, resolve_bindings_derived
->name
);
12001 /* Try to find a name collision with an inherited component. */
12002 if (super_type
&& gfc_find_component (super_type
, stree
->name
, true, true))
12004 gfc_error ("Procedure '%s' at %L has the same name as an inherited"
12005 " component of '%s'",
12006 stree
->name
, &where
, resolve_bindings_derived
->name
);
12010 stree
->n
.tb
->error
= 0;
12014 resolve_bindings_result
= false;
12015 stree
->n
.tb
->error
= 1;
12020 resolve_typebound_procedures (gfc_symbol
* derived
)
12023 gfc_symbol
* super_type
;
12025 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->tb_sym_root
)
12028 super_type
= gfc_get_derived_super_type (derived
);
12030 resolve_symbol (super_type
);
12032 resolve_bindings_derived
= derived
;
12033 resolve_bindings_result
= true;
12035 if (derived
->f2k_derived
->tb_sym_root
)
12036 gfc_traverse_symtree (derived
->f2k_derived
->tb_sym_root
,
12037 &resolve_typebound_procedure
);
12039 if (derived
->f2k_derived
->tb_uop_root
)
12040 gfc_traverse_symtree (derived
->f2k_derived
->tb_uop_root
,
12041 &resolve_typebound_user_op
);
12043 for (op
= 0; op
!= GFC_INTRINSIC_OPS
; ++op
)
12045 gfc_typebound_proc
* p
= derived
->f2k_derived
->tb_op
[op
];
12046 if (p
&& !resolve_typebound_intrinsic_op (derived
,
12047 (gfc_intrinsic_op
)op
, p
))
12048 resolve_bindings_result
= false;
12051 return resolve_bindings_result
;
12055 /* Add a derived type to the dt_list. The dt_list is used in trans-types.c
12056 to give all identical derived types the same backend_decl. */
12058 add_dt_to_dt_list (gfc_symbol
*derived
)
12060 gfc_dt_list
*dt_list
;
12062 for (dt_list
= gfc_derived_types
; dt_list
; dt_list
= dt_list
->next
)
12063 if (derived
== dt_list
->derived
)
12066 dt_list
= gfc_get_dt_list ();
12067 dt_list
->next
= gfc_derived_types
;
12068 dt_list
->derived
= derived
;
12069 gfc_derived_types
= dt_list
;
12073 /* Ensure that a derived-type is really not abstract, meaning that every
12074 inherited DEFERRED binding is overridden by a non-DEFERRED one. */
12077 ensure_not_abstract_walker (gfc_symbol
* sub
, gfc_symtree
* st
)
12082 if (!ensure_not_abstract_walker (sub
, st
->left
))
12084 if (!ensure_not_abstract_walker (sub
, st
->right
))
12087 if (st
->n
.tb
&& st
->n
.tb
->deferred
)
12089 gfc_symtree
* overriding
;
12090 overriding
= gfc_find_typebound_proc (sub
, NULL
, st
->name
, true, NULL
);
12093 gcc_assert (overriding
->n
.tb
);
12094 if (overriding
->n
.tb
->deferred
)
12096 gfc_error ("Derived-type '%s' declared at %L must be ABSTRACT because"
12097 " '%s' is DEFERRED and not overridden",
12098 sub
->name
, &sub
->declared_at
, st
->name
);
12107 ensure_not_abstract (gfc_symbol
* sub
, gfc_symbol
* ancestor
)
12109 /* The algorithm used here is to recursively travel up the ancestry of sub
12110 and for each ancestor-type, check all bindings. If any of them is
12111 DEFERRED, look it up starting from sub and see if the found (overriding)
12112 binding is not DEFERRED.
12113 This is not the most efficient way to do this, but it should be ok and is
12114 clearer than something sophisticated. */
12116 gcc_assert (ancestor
&& !sub
->attr
.abstract
);
12118 if (!ancestor
->attr
.abstract
)
12121 /* Walk bindings of this ancestor. */
12122 if (ancestor
->f2k_derived
)
12125 t
= ensure_not_abstract_walker (sub
, ancestor
->f2k_derived
->tb_sym_root
);
12130 /* Find next ancestor type and recurse on it. */
12131 ancestor
= gfc_get_derived_super_type (ancestor
);
12133 return ensure_not_abstract (sub
, ancestor
);
12139 /* This check for typebound defined assignments is done recursively
12140 since the order in which derived types are resolved is not always in
12141 order of the declarations. */
12144 check_defined_assignments (gfc_symbol
*derived
)
12148 for (c
= derived
->components
; c
; c
= c
->next
)
12150 if (c
->ts
.type
!= BT_DERIVED
12152 || c
->attr
.allocatable
12153 || c
->attr
.proc_pointer_comp
12154 || c
->attr
.class_pointer
12155 || c
->attr
.proc_pointer
)
12158 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
12159 || (c
->ts
.u
.derived
->f2k_derived
12160 && c
->ts
.u
.derived
->f2k_derived
->tb_op
[INTRINSIC_ASSIGN
]))
12162 derived
->attr
.defined_assign_comp
= 1;
12166 check_defined_assignments (c
->ts
.u
.derived
);
12167 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
12169 derived
->attr
.defined_assign_comp
= 1;
12176 /* Resolve the components of a derived type. This does not have to wait until
12177 resolution stage, but can be done as soon as the dt declaration has been
12181 resolve_fl_derived0 (gfc_symbol
*sym
)
12183 gfc_symbol
* super_type
;
12186 if (sym
->attr
.unlimited_polymorphic
)
12189 super_type
= gfc_get_derived_super_type (sym
);
12192 if (super_type
&& sym
->attr
.coarray_comp
&& !super_type
->attr
.coarray_comp
)
12194 gfc_error ("As extending type '%s' at %L has a coarray component, "
12195 "parent type '%s' shall also have one", sym
->name
,
12196 &sym
->declared_at
, super_type
->name
);
12200 /* Ensure the extended type gets resolved before we do. */
12201 if (super_type
&& !resolve_fl_derived0 (super_type
))
12204 /* An ABSTRACT type must be extensible. */
12205 if (sym
->attr
.abstract
&& !gfc_type_is_extensible (sym
))
12207 gfc_error ("Non-extensible derived-type '%s' at %L must not be ABSTRACT",
12208 sym
->name
, &sym
->declared_at
);
12212 c
= (sym
->attr
.is_class
) ? sym
->components
->ts
.u
.derived
->components
12215 for ( ; c
!= NULL
; c
= c
->next
)
12217 if (c
->attr
.artificial
)
12221 if ((!sym
->attr
.is_class
|| c
!= sym
->components
)
12222 && c
->attr
.codimension
12223 && (!c
->attr
.allocatable
|| (c
->as
&& c
->as
->type
!= AS_DEFERRED
)))
12225 gfc_error ("Coarray component '%s' at %L must be allocatable with "
12226 "deferred shape", c
->name
, &c
->loc
);
12231 if (c
->attr
.codimension
&& c
->ts
.type
== BT_DERIVED
12232 && c
->ts
.u
.derived
->ts
.is_iso_c
)
12234 gfc_error ("Component '%s' at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
12235 "shall not be a coarray", c
->name
, &c
->loc
);
12240 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
12241 && (c
->attr
.codimension
|| c
->attr
.pointer
|| c
->attr
.dimension
12242 || c
->attr
.allocatable
))
12244 gfc_error ("Component '%s' at %L with coarray component "
12245 "shall be a nonpointer, nonallocatable scalar",
12251 if (c
->attr
.contiguous
&& (!c
->attr
.dimension
|| !c
->attr
.pointer
))
12253 gfc_error ("Component '%s' at %L has the CONTIGUOUS attribute but "
12254 "is not an array pointer", c
->name
, &c
->loc
);
12258 if (c
->attr
.proc_pointer
&& c
->ts
.interface
)
12260 gfc_symbol
*ifc
= c
->ts
.interface
;
12262 if (!sym
->attr
.vtype
12263 && !check_proc_interface (ifc
, &c
->loc
))
12266 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
12268 /* Resolve interface and copy attributes. */
12269 if (ifc
->formal
&& !ifc
->formal_ns
)
12270 resolve_symbol (ifc
);
12271 if (ifc
->attr
.intrinsic
)
12272 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
12276 c
->ts
= ifc
->result
->ts
;
12277 c
->attr
.allocatable
= ifc
->result
->attr
.allocatable
;
12278 c
->attr
.pointer
= ifc
->result
->attr
.pointer
;
12279 c
->attr
.dimension
= ifc
->result
->attr
.dimension
;
12280 c
->as
= gfc_copy_array_spec (ifc
->result
->as
);
12281 c
->attr
.class_ok
= ifc
->result
->attr
.class_ok
;
12286 c
->attr
.allocatable
= ifc
->attr
.allocatable
;
12287 c
->attr
.pointer
= ifc
->attr
.pointer
;
12288 c
->attr
.dimension
= ifc
->attr
.dimension
;
12289 c
->as
= gfc_copy_array_spec (ifc
->as
);
12290 c
->attr
.class_ok
= ifc
->attr
.class_ok
;
12292 c
->ts
.interface
= ifc
;
12293 c
->attr
.function
= ifc
->attr
.function
;
12294 c
->attr
.subroutine
= ifc
->attr
.subroutine
;
12296 c
->attr
.pure
= ifc
->attr
.pure
;
12297 c
->attr
.elemental
= ifc
->attr
.elemental
;
12298 c
->attr
.recursive
= ifc
->attr
.recursive
;
12299 c
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
12300 c
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
12301 /* Copy char length. */
12302 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
12304 gfc_charlen
*cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
12305 if (cl
->length
&& !cl
->resolved
12306 && !gfc_resolve_expr (cl
->length
))
12312 else if (c
->attr
.proc_pointer
&& c
->ts
.type
== BT_UNKNOWN
)
12314 /* Since PPCs are not implicitly typed, a PPC without an explicit
12315 interface must be a subroutine. */
12316 gfc_add_subroutine (&c
->attr
, c
->name
, &c
->loc
);
12319 /* Procedure pointer components: Check PASS arg. */
12320 if (c
->attr
.proc_pointer
&& !c
->tb
->nopass
&& c
->tb
->pass_arg_num
== 0
12321 && !sym
->attr
.vtype
)
12323 gfc_symbol
* me_arg
;
12325 if (c
->tb
->pass_arg
)
12327 gfc_formal_arglist
* i
;
12329 /* If an explicit passing argument name is given, walk the arg-list
12330 and look for it. */
12333 c
->tb
->pass_arg_num
= 1;
12334 for (i
= c
->ts
.interface
->formal
; i
; i
= i
->next
)
12336 if (!strcmp (i
->sym
->name
, c
->tb
->pass_arg
))
12341 c
->tb
->pass_arg_num
++;
12346 gfc_error ("Procedure pointer component '%s' with PASS(%s) "
12347 "at %L has no argument '%s'", c
->name
,
12348 c
->tb
->pass_arg
, &c
->loc
, c
->tb
->pass_arg
);
12355 /* Otherwise, take the first one; there should in fact be at least
12357 c
->tb
->pass_arg_num
= 1;
12358 if (!c
->ts
.interface
->formal
)
12360 gfc_error ("Procedure pointer component '%s' with PASS at %L "
12361 "must have at least one argument",
12366 me_arg
= c
->ts
.interface
->formal
->sym
;
12369 /* Now check that the argument-type matches. */
12370 gcc_assert (me_arg
);
12371 if ((me_arg
->ts
.type
!= BT_DERIVED
&& me_arg
->ts
.type
!= BT_CLASS
)
12372 || (me_arg
->ts
.type
== BT_DERIVED
&& me_arg
->ts
.u
.derived
!= sym
)
12373 || (me_arg
->ts
.type
== BT_CLASS
12374 && CLASS_DATA (me_arg
)->ts
.u
.derived
!= sym
))
12376 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L must be of"
12377 " the derived type '%s'", me_arg
->name
, c
->name
,
12378 me_arg
->name
, &c
->loc
, sym
->name
);
12383 /* Check for C453. */
12384 if (me_arg
->attr
.dimension
)
12386 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
12387 "must be scalar", me_arg
->name
, c
->name
, me_arg
->name
,
12393 if (me_arg
->attr
.pointer
)
12395 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
12396 "may not have the POINTER attribute", me_arg
->name
,
12397 c
->name
, me_arg
->name
, &c
->loc
);
12402 if (me_arg
->attr
.allocatable
)
12404 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L "
12405 "may not be ALLOCATABLE", me_arg
->name
, c
->name
,
12406 me_arg
->name
, &c
->loc
);
12411 if (gfc_type_is_extensible (sym
) && me_arg
->ts
.type
!= BT_CLASS
)
12412 gfc_error ("Non-polymorphic passed-object dummy argument of '%s'"
12413 " at %L", c
->name
, &c
->loc
);
12417 /* Check type-spec if this is not the parent-type component. */
12418 if (((sym
->attr
.is_class
12419 && (!sym
->components
->ts
.u
.derived
->attr
.extension
12420 || c
!= sym
->components
->ts
.u
.derived
->components
))
12421 || (!sym
->attr
.is_class
12422 && (!sym
->attr
.extension
|| c
!= sym
->components
)))
12423 && !sym
->attr
.vtype
12424 && !resolve_typespec_used (&c
->ts
, &c
->loc
, c
->name
))
12427 /* If this type is an extension, set the accessibility of the parent
12430 && ((sym
->attr
.is_class
12431 && c
== sym
->components
->ts
.u
.derived
->components
)
12432 || (!sym
->attr
.is_class
&& c
== sym
->components
))
12433 && strcmp (super_type
->name
, c
->name
) == 0)
12434 c
->attr
.access
= super_type
->attr
.access
;
12436 /* If this type is an extension, see if this component has the same name
12437 as an inherited type-bound procedure. */
12438 if (super_type
&& !sym
->attr
.is_class
12439 && gfc_find_typebound_proc (super_type
, NULL
, c
->name
, true, NULL
))
12441 gfc_error ("Component '%s' of '%s' at %L has the same name as an"
12442 " inherited type-bound procedure",
12443 c
->name
, sym
->name
, &c
->loc
);
12447 if (c
->ts
.type
== BT_CHARACTER
&& !c
->attr
.proc_pointer
12448 && !c
->ts
.deferred
)
12450 if (c
->ts
.u
.cl
->length
== NULL
12451 || (!resolve_charlen(c
->ts
.u
.cl
))
12452 || !gfc_is_constant_expr (c
->ts
.u
.cl
->length
))
12454 gfc_error ("Character length of component '%s' needs to "
12455 "be a constant specification expression at %L",
12457 c
->ts
.u
.cl
->length
? &c
->ts
.u
.cl
->length
->where
: &c
->loc
);
12462 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
12463 && !c
->attr
.pointer
&& !c
->attr
.allocatable
)
12465 gfc_error ("Character component '%s' of '%s' at %L with deferred "
12466 "length must be a POINTER or ALLOCATABLE",
12467 c
->name
, sym
->name
, &c
->loc
);
12471 /* Add the hidden deferred length field. */
12472 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
&& !c
->attr
.function
12473 && !sym
->attr
.is_class
)
12475 char name
[GFC_MAX_SYMBOL_LEN
+9];
12476 gfc_component
*strlen
;
12477 sprintf (name
, "_%s_length", c
->name
);
12478 strlen
= gfc_find_component (sym
, name
, true, true);
12479 if (strlen
== NULL
)
12481 if (!gfc_add_component (sym
, name
, &strlen
))
12483 strlen
->ts
.type
= BT_INTEGER
;
12484 strlen
->ts
.kind
= gfc_charlen_int_kind
;
12485 strlen
->attr
.access
= ACCESS_PRIVATE
;
12486 strlen
->attr
.deferred_parameter
= 1;
12490 if (c
->ts
.type
== BT_DERIVED
12491 && sym
->component_access
!= ACCESS_PRIVATE
12492 && gfc_check_symbol_access (sym
)
12493 && !is_sym_host_assoc (c
->ts
.u
.derived
, sym
->ns
)
12494 && !c
->ts
.u
.derived
->attr
.use_assoc
12495 && !gfc_check_symbol_access (c
->ts
.u
.derived
)
12496 && !gfc_notify_std (GFC_STD_F2003
, "the component '%s' is a "
12497 "PRIVATE type and cannot be a component of "
12498 "'%s', which is PUBLIC at %L", c
->name
,
12499 sym
->name
, &sym
->declared_at
))
12502 if ((sym
->attr
.sequence
|| sym
->attr
.is_bind_c
) && c
->ts
.type
== BT_CLASS
)
12504 gfc_error ("Polymorphic component %s at %L in SEQUENCE or BIND(C) "
12505 "type %s", c
->name
, &c
->loc
, sym
->name
);
12509 if (sym
->attr
.sequence
)
12511 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.sequence
== 0)
12513 gfc_error ("Component %s of SEQUENCE type declared at %L does "
12514 "not have the SEQUENCE attribute",
12515 c
->ts
.u
.derived
->name
, &sym
->declared_at
);
12520 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.generic
)
12521 c
->ts
.u
.derived
= gfc_find_dt_in_generic (c
->ts
.u
.derived
);
12522 else if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
12523 && CLASS_DATA (c
)->ts
.u
.derived
->attr
.generic
)
12524 CLASS_DATA (c
)->ts
.u
.derived
12525 = gfc_find_dt_in_generic (CLASS_DATA (c
)->ts
.u
.derived
);
12527 if (!sym
->attr
.is_class
&& c
->ts
.type
== BT_DERIVED
&& !sym
->attr
.vtype
12528 && c
->attr
.pointer
&& c
->ts
.u
.derived
->components
== NULL
12529 && !c
->ts
.u
.derived
->attr
.zero_comp
)
12531 gfc_error ("The pointer component '%s' of '%s' at %L is a type "
12532 "that has not been declared", c
->name
, sym
->name
,
12537 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
12538 && CLASS_DATA (c
)->attr
.class_pointer
12539 && CLASS_DATA (c
)->ts
.u
.derived
->components
== NULL
12540 && !CLASS_DATA (c
)->ts
.u
.derived
->attr
.zero_comp
12541 && !UNLIMITED_POLY (c
))
12543 gfc_error ("The pointer component '%s' of '%s' at %L is a type "
12544 "that has not been declared", c
->name
, sym
->name
,
12550 if (c
->ts
.type
== BT_CLASS
&& c
->attr
.flavor
!= FL_PROCEDURE
12551 && (!c
->attr
.class_ok
12552 || !(CLASS_DATA (c
)->attr
.class_pointer
12553 || CLASS_DATA (c
)->attr
.allocatable
)))
12555 gfc_error ("Component '%s' with CLASS at %L must be allocatable "
12556 "or pointer", c
->name
, &c
->loc
);
12557 /* Prevent a recurrence of the error. */
12558 c
->ts
.type
= BT_UNKNOWN
;
12562 /* Ensure that all the derived type components are put on the
12563 derived type list; even in formal namespaces, where derived type
12564 pointer components might not have been declared. */
12565 if (c
->ts
.type
== BT_DERIVED
12567 && c
->ts
.u
.derived
->components
12569 && sym
!= c
->ts
.u
.derived
)
12570 add_dt_to_dt_list (c
->ts
.u
.derived
);
12572 if (!gfc_resolve_array_spec (c
->as
,
12573 !(c
->attr
.pointer
|| c
->attr
.proc_pointer
12574 || c
->attr
.allocatable
)))
12577 if (c
->initializer
&& !sym
->attr
.vtype
12578 && !gfc_check_assign_symbol (sym
, c
, c
->initializer
))
12582 check_defined_assignments (sym
);
12584 if (!sym
->attr
.defined_assign_comp
&& super_type
)
12585 sym
->attr
.defined_assign_comp
12586 = super_type
->attr
.defined_assign_comp
;
12588 /* If this is a non-ABSTRACT type extending an ABSTRACT one, ensure that
12589 all DEFERRED bindings are overridden. */
12590 if (super_type
&& super_type
->attr
.abstract
&& !sym
->attr
.abstract
12591 && !sym
->attr
.is_class
12592 && !ensure_not_abstract (sym
, super_type
))
12595 /* Add derived type to the derived type list. */
12596 add_dt_to_dt_list (sym
);
12602 /* The following procedure does the full resolution of a derived type,
12603 including resolution of all type-bound procedures (if present). In contrast
12604 to 'resolve_fl_derived0' this can only be done after the module has been
12605 parsed completely. */
12608 resolve_fl_derived (gfc_symbol
*sym
)
12610 gfc_symbol
*gen_dt
= NULL
;
12612 if (sym
->attr
.unlimited_polymorphic
)
12615 if (!sym
->attr
.is_class
)
12616 gfc_find_symbol (sym
->name
, sym
->ns
, 0, &gen_dt
);
12617 if (gen_dt
&& gen_dt
->generic
&& gen_dt
->generic
->next
12618 && (!gen_dt
->generic
->sym
->attr
.use_assoc
12619 || gen_dt
->generic
->sym
->module
!= gen_dt
->generic
->next
->sym
->module
)
12620 && !gfc_notify_std (GFC_STD_F2003
, "Generic name '%s' of function "
12621 "'%s' at %L being the same name as derived "
12622 "type at %L", sym
->name
,
12623 gen_dt
->generic
->sym
== sym
12624 ? gen_dt
->generic
->next
->sym
->name
12625 : gen_dt
->generic
->sym
->name
,
12626 gen_dt
->generic
->sym
== sym
12627 ? &gen_dt
->generic
->next
->sym
->declared_at
12628 : &gen_dt
->generic
->sym
->declared_at
,
12629 &sym
->declared_at
))
12632 /* Resolve the finalizer procedures. */
12633 if (!gfc_resolve_finalizers (sym
, NULL
))
12636 if (sym
->attr
.is_class
&& sym
->ts
.u
.derived
== NULL
)
12638 /* Fix up incomplete CLASS symbols. */
12639 gfc_component
*data
= gfc_find_component (sym
, "_data", true, true);
12640 gfc_component
*vptr
= gfc_find_component (sym
, "_vptr", true, true);
12642 /* Nothing more to do for unlimited polymorphic entities. */
12643 if (data
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
12645 else if (vptr
->ts
.u
.derived
== NULL
)
12647 gfc_symbol
*vtab
= gfc_find_derived_vtab (data
->ts
.u
.derived
);
12649 vptr
->ts
.u
.derived
= vtab
->ts
.u
.derived
;
12653 if (!resolve_fl_derived0 (sym
))
12656 /* Resolve the type-bound procedures. */
12657 if (!resolve_typebound_procedures (sym
))
12665 resolve_fl_namelist (gfc_symbol
*sym
)
12670 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
12672 /* Check again, the check in match only works if NAMELIST comes
12674 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SIZE
)
12676 gfc_error ("Assumed size array '%s' in namelist '%s' at %L is not "
12677 "allowed", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
12681 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SHAPE
12682 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object '%s' "
12683 "with assumed shape in namelist '%s' at %L",
12684 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
12687 if (is_non_constant_shape_array (nl
->sym
)
12688 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object '%s' "
12689 "with nonconstant shape in namelist '%s' at %L",
12690 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
12693 if (nl
->sym
->ts
.type
== BT_CHARACTER
12694 && (nl
->sym
->ts
.u
.cl
->length
== NULL
12695 || !gfc_is_constant_expr (nl
->sym
->ts
.u
.cl
->length
))
12696 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST object '%s' with "
12697 "nonconstant character length in "
12698 "namelist '%s' at %L", nl
->sym
->name
,
12699 sym
->name
, &sym
->declared_at
))
12702 /* FIXME: Once UDDTIO is implemented, the following can be
12704 if (nl
->sym
->ts
.type
== BT_CLASS
)
12706 gfc_error ("NAMELIST object '%s' in namelist '%s' at %L is "
12707 "polymorphic and requires a defined input/output "
12708 "procedure", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
12712 if (nl
->sym
->ts
.type
== BT_DERIVED
12713 && (nl
->sym
->ts
.u
.derived
->attr
.alloc_comp
12714 || nl
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
12716 if (!gfc_notify_std (GFC_STD_F2003
, "NAMELIST object '%s' in "
12717 "namelist '%s' at %L with ALLOCATABLE "
12718 "or POINTER components", nl
->sym
->name
,
12719 sym
->name
, &sym
->declared_at
))
12722 /* FIXME: Once UDDTIO is implemented, the following can be
12724 gfc_error ("NAMELIST object '%s' in namelist '%s' at %L has "
12725 "ALLOCATABLE or POINTER components and thus requires "
12726 "a defined input/output procedure", nl
->sym
->name
,
12727 sym
->name
, &sym
->declared_at
);
12732 /* Reject PRIVATE objects in a PUBLIC namelist. */
12733 if (gfc_check_symbol_access (sym
))
12735 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
12737 if (!nl
->sym
->attr
.use_assoc
12738 && !is_sym_host_assoc (nl
->sym
, sym
->ns
)
12739 && !gfc_check_symbol_access (nl
->sym
))
12741 gfc_error ("NAMELIST object '%s' was declared PRIVATE and "
12742 "cannot be member of PUBLIC namelist '%s' at %L",
12743 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
12747 /* Types with private components that came here by USE-association. */
12748 if (nl
->sym
->ts
.type
== BT_DERIVED
12749 && derived_inaccessible (nl
->sym
->ts
.u
.derived
))
12751 gfc_error ("NAMELIST object '%s' has use-associated PRIVATE "
12752 "components and cannot be member of namelist '%s' at %L",
12753 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
12757 /* Types with private components that are defined in the same module. */
12758 if (nl
->sym
->ts
.type
== BT_DERIVED
12759 && !is_sym_host_assoc (nl
->sym
->ts
.u
.derived
, sym
->ns
)
12760 && nl
->sym
->ts
.u
.derived
->attr
.private_comp
)
12762 gfc_error ("NAMELIST object '%s' has PRIVATE components and "
12763 "cannot be a member of PUBLIC namelist '%s' at %L",
12764 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
12771 /* 14.1.2 A module or internal procedure represent local entities
12772 of the same type as a namelist member and so are not allowed. */
12773 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
12775 if (nl
->sym
->ts
.kind
!= 0 && nl
->sym
->attr
.flavor
== FL_VARIABLE
)
12778 if (nl
->sym
->attr
.function
&& nl
->sym
== nl
->sym
->result
)
12779 if ((nl
->sym
== sym
->ns
->proc_name
)
12781 (sym
->ns
->parent
&& nl
->sym
== sym
->ns
->parent
->proc_name
))
12786 gfc_find_symbol (nl
->sym
->name
, sym
->ns
, 1, &nlsym
);
12787 if (nlsym
&& nlsym
->attr
.flavor
== FL_PROCEDURE
)
12789 gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
12790 "attribute in '%s' at %L", nlsym
->name
,
12791 &sym
->declared_at
);
12801 resolve_fl_parameter (gfc_symbol
*sym
)
12803 /* A parameter array's shape needs to be constant. */
12804 if (sym
->as
!= NULL
12805 && (sym
->as
->type
== AS_DEFERRED
12806 || is_non_constant_shape_array (sym
)))
12808 gfc_error ("Parameter array '%s' at %L cannot be automatic "
12809 "or of deferred shape", sym
->name
, &sym
->declared_at
);
12813 /* Make sure a parameter that has been implicitly typed still
12814 matches the implicit type, since PARAMETER statements can precede
12815 IMPLICIT statements. */
12816 if (sym
->attr
.implicit_type
12817 && !gfc_compare_types (&sym
->ts
, gfc_get_default_type (sym
->name
,
12820 gfc_error ("Implicitly typed PARAMETER '%s' at %L doesn't match a "
12821 "later IMPLICIT type", sym
->name
, &sym
->declared_at
);
12825 /* Make sure the types of derived parameters are consistent. This
12826 type checking is deferred until resolution because the type may
12827 refer to a derived type from the host. */
12828 if (sym
->ts
.type
== BT_DERIVED
12829 && !gfc_compare_types (&sym
->ts
, &sym
->value
->ts
))
12831 gfc_error ("Incompatible derived type in PARAMETER at %L",
12832 &sym
->value
->where
);
12839 /* Do anything necessary to resolve a symbol. Right now, we just
12840 assume that an otherwise unknown symbol is a variable. This sort
12841 of thing commonly happens for symbols in module. */
12844 resolve_symbol (gfc_symbol
*sym
)
12846 int check_constant
, mp_flag
;
12847 gfc_symtree
*symtree
;
12848 gfc_symtree
*this_symtree
;
12851 symbol_attribute class_attr
;
12852 gfc_array_spec
*as
;
12853 bool saved_specification_expr
;
12859 if (sym
->attr
.artificial
)
12862 if (sym
->attr
.unlimited_polymorphic
)
12865 if (sym
->attr
.flavor
== FL_UNKNOWN
12866 || (sym
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.intrinsic
12867 && !sym
->attr
.generic
&& !sym
->attr
.external
12868 && sym
->attr
.if_source
== IFSRC_UNKNOWN
12869 && sym
->ts
.type
== BT_UNKNOWN
))
12872 /* If we find that a flavorless symbol is an interface in one of the
12873 parent namespaces, find its symtree in this namespace, free the
12874 symbol and set the symtree to point to the interface symbol. */
12875 for (ns
= gfc_current_ns
->parent
; ns
; ns
= ns
->parent
)
12877 symtree
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
12878 if (symtree
&& (symtree
->n
.sym
->generic
||
12879 (symtree
->n
.sym
->attr
.flavor
== FL_PROCEDURE
12880 && sym
->ns
->construct_entities
)))
12882 this_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
12884 gfc_release_symbol (sym
);
12885 symtree
->n
.sym
->refs
++;
12886 this_symtree
->n
.sym
= symtree
->n
.sym
;
12891 /* Otherwise give it a flavor according to such attributes as
12893 if (sym
->attr
.flavor
== FL_UNKNOWN
&& sym
->attr
.external
== 0
12894 && sym
->attr
.intrinsic
== 0)
12895 sym
->attr
.flavor
= FL_VARIABLE
;
12896 else if (sym
->attr
.flavor
== FL_UNKNOWN
)
12898 sym
->attr
.flavor
= FL_PROCEDURE
;
12899 if (sym
->attr
.dimension
)
12900 sym
->attr
.function
= 1;
12904 if (sym
->attr
.external
&& sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.function
)
12905 gfc_add_function (&sym
->attr
, sym
->name
, &sym
->declared_at
);
12907 if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
12908 && !resolve_procedure_interface (sym
))
12911 if (sym
->attr
.is_protected
&& !sym
->attr
.proc_pointer
12912 && (sym
->attr
.procedure
|| sym
->attr
.external
))
12914 if (sym
->attr
.external
)
12915 gfc_error ("PROTECTED attribute conflicts with EXTERNAL attribute "
12916 "at %L", &sym
->declared_at
);
12918 gfc_error ("PROCEDURE attribute conflicts with PROTECTED attribute "
12919 "at %L", &sym
->declared_at
);
12924 if (sym
->attr
.flavor
== FL_DERIVED
&& !resolve_fl_derived (sym
))
12927 /* Symbols that are module procedures with results (functions) have
12928 the types and array specification copied for type checking in
12929 procedures that call them, as well as for saving to a module
12930 file. These symbols can't stand the scrutiny that their results
12932 mp_flag
= (sym
->result
!= NULL
&& sym
->result
!= sym
);
12934 /* Make sure that the intrinsic is consistent with its internal
12935 representation. This needs to be done before assigning a default
12936 type to avoid spurious warnings. */
12937 if (sym
->attr
.flavor
!= FL_MODULE
&& sym
->attr
.intrinsic
12938 && !gfc_resolve_intrinsic (sym
, &sym
->declared_at
))
12941 /* Resolve associate names. */
12943 resolve_assoc_var (sym
, true);
12945 /* Assign default type to symbols that need one and don't have one. */
12946 if (sym
->ts
.type
== BT_UNKNOWN
)
12948 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
)
12950 gfc_set_default_type (sym
, 1, NULL
);
12953 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.external
12954 && !sym
->attr
.function
&& !sym
->attr
.subroutine
12955 && gfc_get_default_type (sym
->name
, sym
->ns
)->type
== BT_UNKNOWN
)
12956 gfc_add_subroutine (&sym
->attr
, sym
->name
, &sym
->declared_at
);
12958 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
12960 /* The specific case of an external procedure should emit an error
12961 in the case that there is no implicit type. */
12963 gfc_set_default_type (sym
, sym
->attr
.external
, NULL
);
12966 /* Result may be in another namespace. */
12967 resolve_symbol (sym
->result
);
12969 if (!sym
->result
->attr
.proc_pointer
)
12971 sym
->ts
= sym
->result
->ts
;
12972 sym
->as
= gfc_copy_array_spec (sym
->result
->as
);
12973 sym
->attr
.dimension
= sym
->result
->attr
.dimension
;
12974 sym
->attr
.pointer
= sym
->result
->attr
.pointer
;
12975 sym
->attr
.allocatable
= sym
->result
->attr
.allocatable
;
12976 sym
->attr
.contiguous
= sym
->result
->attr
.contiguous
;
12981 else if (mp_flag
&& sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
12983 bool saved_specification_expr
= specification_expr
;
12984 specification_expr
= true;
12985 gfc_resolve_array_spec (sym
->result
->as
, false);
12986 specification_expr
= saved_specification_expr
;
12989 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
)
12991 as
= CLASS_DATA (sym
)->as
;
12992 class_attr
= CLASS_DATA (sym
)->attr
;
12993 class_attr
.pointer
= class_attr
.class_pointer
;
12997 class_attr
= sym
->attr
;
13002 if (sym
->attr
.contiguous
13003 && (!class_attr
.dimension
13004 || (as
->type
!= AS_ASSUMED_SHAPE
&& as
->type
!= AS_ASSUMED_RANK
13005 && !class_attr
.pointer
)))
13007 gfc_error ("'%s' at %L has the CONTIGUOUS attribute but is not an "
13008 "array pointer or an assumed-shape or assumed-rank array",
13009 sym
->name
, &sym
->declared_at
);
13013 /* Assumed size arrays and assumed shape arrays must be dummy
13014 arguments. Array-spec's of implied-shape should have been resolved to
13015 AS_EXPLICIT already. */
13019 gcc_assert (as
->type
!= AS_IMPLIED_SHAPE
);
13020 if (((as
->type
== AS_ASSUMED_SIZE
&& !as
->cp_was_assumed
)
13021 || as
->type
== AS_ASSUMED_SHAPE
)
13022 && !sym
->attr
.dummy
&& !sym
->attr
.select_type_temporary
)
13024 if (as
->type
== AS_ASSUMED_SIZE
)
13025 gfc_error ("Assumed size array at %L must be a dummy argument",
13026 &sym
->declared_at
);
13028 gfc_error ("Assumed shape array at %L must be a dummy argument",
13029 &sym
->declared_at
);
13032 /* TS 29113, C535a. */
13033 if (as
->type
== AS_ASSUMED_RANK
&& !sym
->attr
.dummy
13034 && !sym
->attr
.select_type_temporary
)
13036 gfc_error ("Assumed-rank array at %L must be a dummy argument",
13037 &sym
->declared_at
);
13040 if (as
->type
== AS_ASSUMED_RANK
13041 && (sym
->attr
.codimension
|| sym
->attr
.value
))
13043 gfc_error ("Assumed-rank array at %L may not have the VALUE or "
13044 "CODIMENSION attribute", &sym
->declared_at
);
13049 /* Make sure symbols with known intent or optional are really dummy
13050 variable. Because of ENTRY statement, this has to be deferred
13051 until resolution time. */
13053 if (!sym
->attr
.dummy
13054 && (sym
->attr
.optional
|| sym
->attr
.intent
!= INTENT_UNKNOWN
))
13056 gfc_error ("Symbol at %L is not a DUMMY variable", &sym
->declared_at
);
13060 if (sym
->attr
.value
&& !sym
->attr
.dummy
)
13062 gfc_error ("'%s' at %L cannot have the VALUE attribute because "
13063 "it is not a dummy argument", sym
->name
, &sym
->declared_at
);
13067 if (sym
->attr
.value
&& sym
->ts
.type
== BT_CHARACTER
)
13069 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
13070 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
13072 gfc_error ("Character dummy variable '%s' at %L with VALUE "
13073 "attribute must have constant length",
13074 sym
->name
, &sym
->declared_at
);
13078 if (sym
->ts
.is_c_interop
13079 && mpz_cmp_si (cl
->length
->value
.integer
, 1) != 0)
13081 gfc_error ("C interoperable character dummy variable '%s' at %L "
13082 "with VALUE attribute must have length one",
13083 sym
->name
, &sym
->declared_at
);
13088 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
13089 && sym
->ts
.u
.derived
->attr
.generic
)
13091 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
13092 if (!sym
->ts
.u
.derived
)
13094 gfc_error ("The derived type '%s' at %L is of type '%s', "
13095 "which has not been defined", sym
->name
,
13096 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
13097 sym
->ts
.type
= BT_UNKNOWN
;
13102 /* Use the same constraints as TYPE(*), except for the type check
13103 and that only scalars and assumed-size arrays are permitted. */
13104 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
13106 if (!sym
->attr
.dummy
)
13108 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
13109 "a dummy argument", sym
->name
, &sym
->declared_at
);
13113 if (sym
->ts
.type
!= BT_ASSUMED
&& sym
->ts
.type
!= BT_INTEGER
13114 && sym
->ts
.type
!= BT_REAL
&& sym
->ts
.type
!= BT_LOGICAL
13115 && sym
->ts
.type
!= BT_COMPLEX
)
13117 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
13118 "of type TYPE(*) or of an numeric intrinsic type",
13119 sym
->name
, &sym
->declared_at
);
13123 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
13124 || sym
->attr
.pointer
|| sym
->attr
.value
)
13126 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
13127 "have the ALLOCATABLE, CODIMENSION, POINTER or VALUE "
13128 "attribute", sym
->name
, &sym
->declared_at
);
13132 if (sym
->attr
.intent
== INTENT_OUT
)
13134 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
13135 "have the INTENT(OUT) attribute",
13136 sym
->name
, &sym
->declared_at
);
13139 if (sym
->attr
.dimension
&& sym
->as
->type
!= AS_ASSUMED_SIZE
)
13141 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall "
13142 "either be a scalar or an assumed-size array",
13143 sym
->name
, &sym
->declared_at
);
13147 /* Set the type to TYPE(*) and add a dimension(*) to ensure
13148 NO_ARG_CHECK is correctly handled in trans*.c, e.g. with
13150 sym
->ts
.type
= BT_ASSUMED
;
13151 sym
->as
= gfc_get_array_spec ();
13152 sym
->as
->type
= AS_ASSUMED_SIZE
;
13154 sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
13156 else if (sym
->ts
.type
== BT_ASSUMED
)
13158 /* TS 29113, C407a. */
13159 if (!sym
->attr
.dummy
)
13161 gfc_error ("Assumed type of variable %s at %L is only permitted "
13162 "for dummy variables", sym
->name
, &sym
->declared_at
);
13165 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
13166 || sym
->attr
.pointer
|| sym
->attr
.value
)
13168 gfc_error ("Assumed-type variable %s at %L may not have the "
13169 "ALLOCATABLE, CODIMENSION, POINTER or VALUE attribute",
13170 sym
->name
, &sym
->declared_at
);
13173 if (sym
->attr
.intent
== INTENT_OUT
)
13175 gfc_error ("Assumed-type variable %s at %L may not have the "
13176 "INTENT(OUT) attribute",
13177 sym
->name
, &sym
->declared_at
);
13180 if (sym
->attr
.dimension
&& sym
->as
->type
== AS_EXPLICIT
)
13182 gfc_error ("Assumed-type variable %s at %L shall not be an "
13183 "explicit-shape array", sym
->name
, &sym
->declared_at
);
13188 /* If the symbol is marked as bind(c), verify it's type and kind. Do not
13189 do this for something that was implicitly typed because that is handled
13190 in gfc_set_default_type. Handle dummy arguments and procedure
13191 definitions separately. Also, anything that is use associated is not
13192 handled here but instead is handled in the module it is declared in.
13193 Finally, derived type definitions are allowed to be BIND(C) since that
13194 only implies that they're interoperable, and they are checked fully for
13195 interoperability when a variable is declared of that type. */
13196 if (sym
->attr
.is_bind_c
&& sym
->attr
.implicit_type
== 0 &&
13197 sym
->attr
.use_assoc
== 0 && sym
->attr
.dummy
== 0 &&
13198 sym
->attr
.flavor
!= FL_PROCEDURE
&& sym
->attr
.flavor
!= FL_DERIVED
)
13202 /* First, make sure the variable is declared at the
13203 module-level scope (J3/04-007, Section 15.3). */
13204 if (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
&&
13205 sym
->attr
.in_common
== 0)
13207 gfc_error ("Variable '%s' at %L cannot be BIND(C) because it "
13208 "is neither a COMMON block nor declared at the "
13209 "module level scope", sym
->name
, &(sym
->declared_at
));
13212 else if (sym
->common_head
!= NULL
)
13214 t
= verify_com_block_vars_c_interop (sym
->common_head
);
13218 /* If type() declaration, we need to verify that the components
13219 of the given type are all C interoperable, etc. */
13220 if (sym
->ts
.type
== BT_DERIVED
&&
13221 sym
->ts
.u
.derived
->attr
.is_c_interop
!= 1)
13223 /* Make sure the user marked the derived type as BIND(C). If
13224 not, call the verify routine. This could print an error
13225 for the derived type more than once if multiple variables
13226 of that type are declared. */
13227 if (sym
->ts
.u
.derived
->attr
.is_bind_c
!= 1)
13228 verify_bind_c_derived_type (sym
->ts
.u
.derived
);
13232 /* Verify the variable itself as C interoperable if it
13233 is BIND(C). It is not possible for this to succeed if
13234 the verify_bind_c_derived_type failed, so don't have to handle
13235 any error returned by verify_bind_c_derived_type. */
13236 t
= verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
13237 sym
->common_block
);
13242 /* clear the is_bind_c flag to prevent reporting errors more than
13243 once if something failed. */
13244 sym
->attr
.is_bind_c
= 0;
13249 /* If a derived type symbol has reached this point, without its
13250 type being declared, we have an error. Notice that most
13251 conditions that produce undefined derived types have already
13252 been dealt with. However, the likes of:
13253 implicit type(t) (t) ..... call foo (t) will get us here if
13254 the type is not declared in the scope of the implicit
13255 statement. Change the type to BT_UNKNOWN, both because it is so
13256 and to prevent an ICE. */
13257 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
13258 && sym
->ts
.u
.derived
->components
== NULL
13259 && !sym
->ts
.u
.derived
->attr
.zero_comp
)
13261 gfc_error ("The derived type '%s' at %L is of type '%s', "
13262 "which has not been defined", sym
->name
,
13263 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
13264 sym
->ts
.type
= BT_UNKNOWN
;
13268 /* Make sure that the derived type has been resolved and that the
13269 derived type is visible in the symbol's namespace, if it is a
13270 module function and is not PRIVATE. */
13271 if (sym
->ts
.type
== BT_DERIVED
13272 && sym
->ts
.u
.derived
->attr
.use_assoc
13273 && sym
->ns
->proc_name
13274 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
13275 && !resolve_fl_derived (sym
->ts
.u
.derived
))
13278 /* Unless the derived-type declaration is use associated, Fortran 95
13279 does not allow public entries of private derived types.
13280 See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
13281 161 in 95-006r3. */
13282 if (sym
->ts
.type
== BT_DERIVED
13283 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
13284 && !sym
->ts
.u
.derived
->attr
.use_assoc
13285 && gfc_check_symbol_access (sym
)
13286 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
13287 && !gfc_notify_std (GFC_STD_F2003
, "PUBLIC %s '%s' at %L of PRIVATE "
13288 "derived type '%s'",
13289 (sym
->attr
.flavor
== FL_PARAMETER
)
13290 ? "parameter" : "variable",
13291 sym
->name
, &sym
->declared_at
,
13292 sym
->ts
.u
.derived
->name
))
13295 /* F2008, C1302. */
13296 if (sym
->ts
.type
== BT_DERIVED
13297 && ((sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
13298 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
13299 || sym
->ts
.u
.derived
->attr
.lock_comp
)
13300 && !sym
->attr
.codimension
&& !sym
->ts
.u
.derived
->attr
.coarray_comp
)
13302 gfc_error ("Variable %s at %L of type LOCK_TYPE or with subcomponent of "
13303 "type LOCK_TYPE must be a coarray", sym
->name
,
13304 &sym
->declared_at
);
13308 /* An assumed-size array with INTENT(OUT) shall not be of a type for which
13309 default initialization is defined (5.1.2.4.4). */
13310 if (sym
->ts
.type
== BT_DERIVED
13312 && sym
->attr
.intent
== INTENT_OUT
13314 && sym
->as
->type
== AS_ASSUMED_SIZE
)
13316 for (c
= sym
->ts
.u
.derived
->components
; c
; c
= c
->next
)
13318 if (c
->initializer
)
13320 gfc_error ("The INTENT(OUT) dummy argument '%s' at %L is "
13321 "ASSUMED SIZE and so cannot have a default initializer",
13322 sym
->name
, &sym
->declared_at
);
13329 if (sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.dummy
13330 && sym
->attr
.intent
== INTENT_OUT
&& sym
->attr
.lock_comp
)
13332 gfc_error ("Dummy argument '%s' at %L of LOCK_TYPE shall not be "
13333 "INTENT(OUT)", sym
->name
, &sym
->declared_at
);
13338 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
13339 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
13340 && CLASS_DATA (sym
)->attr
.coarray_comp
))
13341 || class_attr
.codimension
)
13342 && (sym
->attr
.result
|| sym
->result
== sym
))
13344 gfc_error ("Function result '%s' at %L shall not be a coarray or have "
13345 "a coarray component", sym
->name
, &sym
->declared_at
);
13350 if (sym
->attr
.codimension
&& sym
->ts
.type
== BT_DERIVED
13351 && sym
->ts
.u
.derived
->ts
.is_iso_c
)
13353 gfc_error ("Variable '%s' at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
13354 "shall not be a coarray", sym
->name
, &sym
->declared_at
);
13359 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
13360 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
13361 && CLASS_DATA (sym
)->attr
.coarray_comp
))
13362 && (class_attr
.codimension
|| class_attr
.pointer
|| class_attr
.dimension
13363 || class_attr
.allocatable
))
13365 gfc_error ("Variable '%s' at %L with coarray component shall be a "
13366 "nonpointer, nonallocatable scalar, which is not a coarray",
13367 sym
->name
, &sym
->declared_at
);
13371 /* F2008, C526. The function-result case was handled above. */
13372 if (class_attr
.codimension
13373 && !(class_attr
.allocatable
|| sym
->attr
.dummy
|| sym
->attr
.save
13374 || sym
->attr
.select_type_temporary
13375 || sym
->ns
->save_all
13376 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
13377 || sym
->ns
->proc_name
->attr
.is_main_program
13378 || sym
->attr
.function
|| sym
->attr
.result
|| sym
->attr
.use_assoc
))
13380 gfc_error ("Variable '%s' at %L is a coarray and is not ALLOCATABLE, SAVE "
13381 "nor a dummy argument", sym
->name
, &sym
->declared_at
);
13385 else if (class_attr
.codimension
&& !sym
->attr
.select_type_temporary
13386 && !class_attr
.allocatable
&& as
&& as
->cotype
== AS_DEFERRED
)
13388 gfc_error ("Coarray variable '%s' at %L shall not have codimensions with "
13389 "deferred shape", sym
->name
, &sym
->declared_at
);
13392 else if (class_attr
.codimension
&& class_attr
.allocatable
&& as
13393 && (as
->cotype
!= AS_DEFERRED
|| as
->type
!= AS_DEFERRED
))
13395 gfc_error ("Allocatable coarray variable '%s' at %L must have "
13396 "deferred shape", sym
->name
, &sym
->declared_at
);
13401 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
13402 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
13403 && CLASS_DATA (sym
)->attr
.coarray_comp
))
13404 || (class_attr
.codimension
&& class_attr
.allocatable
))
13405 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
)
13407 gfc_error ("Variable '%s' at %L is INTENT(OUT) and can thus not be an "
13408 "allocatable coarray or have coarray components",
13409 sym
->name
, &sym
->declared_at
);
13413 if (class_attr
.codimension
&& sym
->attr
.dummy
13414 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.is_bind_c
)
13416 gfc_error ("Coarray dummy variable '%s' at %L not allowed in BIND(C) "
13417 "procedure '%s'", sym
->name
, &sym
->declared_at
,
13418 sym
->ns
->proc_name
->name
);
13422 if (sym
->ts
.type
== BT_LOGICAL
13423 && ((sym
->attr
.function
&& sym
->attr
.is_bind_c
&& sym
->result
== sym
)
13424 || ((sym
->attr
.dummy
|| sym
->attr
.result
) && sym
->ns
->proc_name
13425 && sym
->ns
->proc_name
->attr
.is_bind_c
)))
13428 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
13429 if (gfc_logical_kinds
[i
].kind
== sym
->ts
.kind
)
13431 if (!gfc_logical_kinds
[i
].c_bool
&& sym
->attr
.dummy
13432 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL dummy argument '%s' at "
13433 "%L with non-C_Bool kind in BIND(C) procedure "
13434 "'%s'", sym
->name
, &sym
->declared_at
,
13435 sym
->ns
->proc_name
->name
))
13437 else if (!gfc_logical_kinds
[i
].c_bool
13438 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL result variable "
13439 "'%s' at %L with non-C_Bool kind in "
13440 "BIND(C) procedure '%s'", sym
->name
,
13442 sym
->attr
.function
? sym
->name
13443 : sym
->ns
->proc_name
->name
))
13447 switch (sym
->attr
.flavor
)
13450 if (!resolve_fl_variable (sym
, mp_flag
))
13455 if (!resolve_fl_procedure (sym
, mp_flag
))
13460 if (!resolve_fl_namelist (sym
))
13465 if (!resolve_fl_parameter (sym
))
13473 /* Resolve array specifier. Check as well some constraints
13474 on COMMON blocks. */
13476 check_constant
= sym
->attr
.in_common
&& !sym
->attr
.pointer
;
13478 /* Set the formal_arg_flag so that check_conflict will not throw
13479 an error for host associated variables in the specification
13480 expression for an array_valued function. */
13481 if (sym
->attr
.function
&& sym
->as
)
13482 formal_arg_flag
= 1;
13484 saved_specification_expr
= specification_expr
;
13485 specification_expr
= true;
13486 gfc_resolve_array_spec (sym
->as
, check_constant
);
13487 specification_expr
= saved_specification_expr
;
13489 formal_arg_flag
= 0;
13491 /* Resolve formal namespaces. */
13492 if (sym
->formal_ns
&& sym
->formal_ns
!= gfc_current_ns
13493 && !sym
->attr
.contained
&& !sym
->attr
.intrinsic
)
13494 gfc_resolve (sym
->formal_ns
);
13496 /* Make sure the formal namespace is present. */
13497 if (sym
->formal
&& !sym
->formal_ns
)
13499 gfc_formal_arglist
*formal
= sym
->formal
;
13500 while (formal
&& !formal
->sym
)
13501 formal
= formal
->next
;
13505 sym
->formal_ns
= formal
->sym
->ns
;
13506 if (sym
->ns
!= formal
->sym
->ns
)
13507 sym
->formal_ns
->refs
++;
13511 /* Check threadprivate restrictions. */
13512 if (sym
->attr
.threadprivate
&& !sym
->attr
.save
&& !sym
->ns
->save_all
13513 && (!sym
->attr
.in_common
13514 && sym
->module
== NULL
13515 && (sym
->ns
->proc_name
== NULL
13516 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
13517 gfc_error ("Threadprivate at %L isn't SAVEd", &sym
->declared_at
);
13519 /* If we have come this far we can apply default-initializers, as
13520 described in 14.7.5, to those variables that have not already
13521 been assigned one. */
13522 if (sym
->ts
.type
== BT_DERIVED
13524 && !sym
->attr
.allocatable
13525 && !sym
->attr
.alloc_comp
)
13527 symbol_attribute
*a
= &sym
->attr
;
13529 if ((!a
->save
&& !a
->dummy
&& !a
->pointer
13530 && !a
->in_common
&& !a
->use_assoc
13531 && (a
->referenced
|| a
->result
)
13532 && !(a
->function
&& sym
!= sym
->result
))
13533 || (a
->dummy
&& a
->intent
== INTENT_OUT
&& !a
->pointer
))
13534 apply_default_init (sym
);
13537 if (sym
->ts
.type
== BT_CLASS
&& sym
->ns
== gfc_current_ns
13538 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
13539 && !CLASS_DATA (sym
)->attr
.class_pointer
13540 && !CLASS_DATA (sym
)->attr
.allocatable
)
13541 apply_default_init (sym
);
13543 /* If this symbol has a type-spec, check it. */
13544 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
13545 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
))
13546 if (!resolve_typespec_used (&sym
->ts
, &sym
->declared_at
, sym
->name
))
13551 /************* Resolve DATA statements *************/
13555 gfc_data_value
*vnode
;
13561 /* Advance the values structure to point to the next value in the data list. */
13564 next_data_value (void)
13566 while (mpz_cmp_ui (values
.left
, 0) == 0)
13569 if (values
.vnode
->next
== NULL
)
13572 values
.vnode
= values
.vnode
->next
;
13573 mpz_set (values
.left
, values
.vnode
->repeat
);
13581 check_data_variable (gfc_data_variable
*var
, locus
*where
)
13587 ar_type mark
= AR_UNKNOWN
;
13589 mpz_t section_index
[GFC_MAX_DIMENSIONS
];
13595 if (!gfc_resolve_expr (var
->expr
))
13599 mpz_init_set_si (offset
, 0);
13602 if (e
->expr_type
!= EXPR_VARIABLE
)
13603 gfc_internal_error ("check_data_variable(): Bad expression");
13605 sym
= e
->symtree
->n
.sym
;
13607 if (sym
->ns
->is_block_data
&& !sym
->attr
.in_common
)
13609 gfc_error ("BLOCK DATA element '%s' at %L must be in COMMON",
13610 sym
->name
, &sym
->declared_at
);
13613 if (e
->ref
== NULL
&& sym
->as
)
13615 gfc_error ("DATA array '%s' at %L must be specified in a previous"
13616 " declaration", sym
->name
, where
);
13620 has_pointer
= sym
->attr
.pointer
;
13622 if (gfc_is_coindexed (e
))
13624 gfc_error ("DATA element '%s' at %L cannot have a coindex", sym
->name
,
13629 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
13631 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.pointer
)
13635 && ref
->type
== REF_ARRAY
13636 && ref
->u
.ar
.type
!= AR_FULL
)
13638 gfc_error ("DATA element '%s' at %L is a pointer and so must "
13639 "be a full array", sym
->name
, where
);
13644 if (e
->rank
== 0 || has_pointer
)
13646 mpz_init_set_ui (size
, 1);
13653 /* Find the array section reference. */
13654 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
13656 if (ref
->type
!= REF_ARRAY
)
13658 if (ref
->u
.ar
.type
== AR_ELEMENT
)
13664 /* Set marks according to the reference pattern. */
13665 switch (ref
->u
.ar
.type
)
13673 /* Get the start position of array section. */
13674 gfc_get_section_index (ar
, section_index
, &offset
);
13679 gcc_unreachable ();
13682 if (!gfc_array_size (e
, &size
))
13684 gfc_error ("Nonconstant array section at %L in DATA statement",
13686 mpz_clear (offset
);
13693 while (mpz_cmp_ui (size
, 0) > 0)
13695 if (!next_data_value ())
13697 gfc_error ("DATA statement at %L has more variables than values",
13703 t
= gfc_check_assign (var
->expr
, values
.vnode
->expr
, 0);
13707 /* If we have more than one element left in the repeat count,
13708 and we have more than one element left in the target variable,
13709 then create a range assignment. */
13710 /* FIXME: Only done for full arrays for now, since array sections
13712 if (mark
== AR_FULL
&& ref
&& ref
->next
== NULL
13713 && mpz_cmp_ui (values
.left
, 1) > 0 && mpz_cmp_ui (size
, 1) > 0)
13717 if (mpz_cmp (size
, values
.left
) >= 0)
13719 mpz_init_set (range
, values
.left
);
13720 mpz_sub (size
, size
, values
.left
);
13721 mpz_set_ui (values
.left
, 0);
13725 mpz_init_set (range
, size
);
13726 mpz_sub (values
.left
, values
.left
, size
);
13727 mpz_set_ui (size
, 0);
13730 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
13733 mpz_add (offset
, offset
, range
);
13740 /* Assign initial value to symbol. */
13743 mpz_sub_ui (values
.left
, values
.left
, 1);
13744 mpz_sub_ui (size
, size
, 1);
13746 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
13751 if (mark
== AR_FULL
)
13752 mpz_add_ui (offset
, offset
, 1);
13754 /* Modify the array section indexes and recalculate the offset
13755 for next element. */
13756 else if (mark
== AR_SECTION
)
13757 gfc_advance_section (section_index
, ar
, &offset
);
13761 if (mark
== AR_SECTION
)
13763 for (i
= 0; i
< ar
->dimen
; i
++)
13764 mpz_clear (section_index
[i
]);
13768 mpz_clear (offset
);
13774 static bool traverse_data_var (gfc_data_variable
*, locus
*);
13776 /* Iterate over a list of elements in a DATA statement. */
13779 traverse_data_list (gfc_data_variable
*var
, locus
*where
)
13782 iterator_stack frame
;
13783 gfc_expr
*e
, *start
, *end
, *step
;
13784 bool retval
= true;
13786 mpz_init (frame
.value
);
13789 start
= gfc_copy_expr (var
->iter
.start
);
13790 end
= gfc_copy_expr (var
->iter
.end
);
13791 step
= gfc_copy_expr (var
->iter
.step
);
13793 if (!gfc_simplify_expr (start
, 1)
13794 || start
->expr_type
!= EXPR_CONSTANT
)
13796 gfc_error ("start of implied-do loop at %L could not be "
13797 "simplified to a constant value", &start
->where
);
13801 if (!gfc_simplify_expr (end
, 1)
13802 || end
->expr_type
!= EXPR_CONSTANT
)
13804 gfc_error ("end of implied-do loop at %L could not be "
13805 "simplified to a constant value", &start
->where
);
13809 if (!gfc_simplify_expr (step
, 1)
13810 || step
->expr_type
!= EXPR_CONSTANT
)
13812 gfc_error ("step of implied-do loop at %L could not be "
13813 "simplified to a constant value", &start
->where
);
13818 mpz_set (trip
, end
->value
.integer
);
13819 mpz_sub (trip
, trip
, start
->value
.integer
);
13820 mpz_add (trip
, trip
, step
->value
.integer
);
13822 mpz_div (trip
, trip
, step
->value
.integer
);
13824 mpz_set (frame
.value
, start
->value
.integer
);
13826 frame
.prev
= iter_stack
;
13827 frame
.variable
= var
->iter
.var
->symtree
;
13828 iter_stack
= &frame
;
13830 while (mpz_cmp_ui (trip
, 0) > 0)
13832 if (!traverse_data_var (var
->list
, where
))
13838 e
= gfc_copy_expr (var
->expr
);
13839 if (!gfc_simplify_expr (e
, 1))
13846 mpz_add (frame
.value
, frame
.value
, step
->value
.integer
);
13848 mpz_sub_ui (trip
, trip
, 1);
13852 mpz_clear (frame
.value
);
13855 gfc_free_expr (start
);
13856 gfc_free_expr (end
);
13857 gfc_free_expr (step
);
13859 iter_stack
= frame
.prev
;
13864 /* Type resolve variables in the variable list of a DATA statement. */
13867 traverse_data_var (gfc_data_variable
*var
, locus
*where
)
13871 for (; var
; var
= var
->next
)
13873 if (var
->expr
== NULL
)
13874 t
= traverse_data_list (var
, where
);
13876 t
= check_data_variable (var
, where
);
13886 /* Resolve the expressions and iterators associated with a data statement.
13887 This is separate from the assignment checking because data lists should
13888 only be resolved once. */
13891 resolve_data_variables (gfc_data_variable
*d
)
13893 for (; d
; d
= d
->next
)
13895 if (d
->list
== NULL
)
13897 if (!gfc_resolve_expr (d
->expr
))
13902 if (!gfc_resolve_iterator (&d
->iter
, false, true))
13905 if (!resolve_data_variables (d
->list
))
13914 /* Resolve a single DATA statement. We implement this by storing a pointer to
13915 the value list into static variables, and then recursively traversing the
13916 variables list, expanding iterators and such. */
13919 resolve_data (gfc_data
*d
)
13922 if (!resolve_data_variables (d
->var
))
13925 values
.vnode
= d
->value
;
13926 if (d
->value
== NULL
)
13927 mpz_set_ui (values
.left
, 0);
13929 mpz_set (values
.left
, d
->value
->repeat
);
13931 if (!traverse_data_var (d
->var
, &d
->where
))
13934 /* At this point, we better not have any values left. */
13936 if (next_data_value ())
13937 gfc_error ("DATA statement at %L has more values than variables",
13942 /* 12.6 Constraint: In a pure subprogram any variable which is in common or
13943 accessed by host or use association, is a dummy argument to a pure function,
13944 is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
13945 is storage associated with any such variable, shall not be used in the
13946 following contexts: (clients of this function). */
13948 /* Determines if a variable is not 'pure', i.e., not assignable within a pure
13949 procedure. Returns zero if assignment is OK, nonzero if there is a
13952 gfc_impure_variable (gfc_symbol
*sym
)
13957 if (sym
->attr
.use_assoc
|| sym
->attr
.in_common
)
13960 /* Check if the symbol's ns is inside the pure procedure. */
13961 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
13965 if (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
13969 proc
= sym
->ns
->proc_name
;
13970 if (sym
->attr
.dummy
13971 && ((proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_IN
)
13972 || proc
->attr
.function
))
13975 /* TODO: Sort out what can be storage associated, if anything, and include
13976 it here. In principle equivalences should be scanned but it does not
13977 seem to be possible to storage associate an impure variable this way. */
13982 /* Test whether a symbol is pure or not. For a NULL pointer, checks if the
13983 current namespace is inside a pure procedure. */
13986 gfc_pure (gfc_symbol
*sym
)
13988 symbol_attribute attr
;
13993 /* Check if the current namespace or one of its parents
13994 belongs to a pure procedure. */
13995 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
13997 sym
= ns
->proc_name
;
14001 if (attr
.flavor
== FL_PROCEDURE
&& attr
.pure
)
14009 return attr
.flavor
== FL_PROCEDURE
&& attr
.pure
;
14013 /* Test whether a symbol is implicitly pure or not. For a NULL pointer,
14014 checks if the current namespace is implicitly pure. Note that this
14015 function returns false for a PURE procedure. */
14018 gfc_implicit_pure (gfc_symbol
*sym
)
14024 /* Check if the current procedure is implicit_pure. Walk up
14025 the procedure list until we find a procedure. */
14026 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14028 sym
= ns
->proc_name
;
14032 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14037 return sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.implicit_pure
14038 && !sym
->attr
.pure
;
14043 gfc_unset_implicit_pure (gfc_symbol
*sym
)
14049 /* Check if the current procedure is implicit_pure. Walk up
14050 the procedure list until we find a procedure. */
14051 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
14053 sym
= ns
->proc_name
;
14057 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14062 if (sym
->attr
.flavor
== FL_PROCEDURE
)
14063 sym
->attr
.implicit_pure
= 0;
14065 sym
->attr
.pure
= 0;
14069 /* Test whether the current procedure is elemental or not. */
14072 gfc_elemental (gfc_symbol
*sym
)
14074 symbol_attribute attr
;
14077 sym
= gfc_current_ns
->proc_name
;
14082 return attr
.flavor
== FL_PROCEDURE
&& attr
.elemental
;
14086 /* Warn about unused labels. */
14089 warn_unused_fortran_label (gfc_st_label
*label
)
14094 warn_unused_fortran_label (label
->left
);
14096 if (label
->defined
== ST_LABEL_UNKNOWN
)
14099 switch (label
->referenced
)
14101 case ST_LABEL_UNKNOWN
:
14102 gfc_warning ("Label %d at %L defined but not used", label
->value
,
14106 case ST_LABEL_BAD_TARGET
:
14107 gfc_warning ("Label %d at %L defined but cannot be used",
14108 label
->value
, &label
->where
);
14115 warn_unused_fortran_label (label
->right
);
14119 /* Returns the sequence type of a symbol or sequence. */
14122 sequence_type (gfc_typespec ts
)
14131 if (ts
.u
.derived
->components
== NULL
)
14132 return SEQ_NONDEFAULT
;
14134 result
= sequence_type (ts
.u
.derived
->components
->ts
);
14135 for (c
= ts
.u
.derived
->components
->next
; c
; c
= c
->next
)
14136 if (sequence_type (c
->ts
) != result
)
14142 if (ts
.kind
!= gfc_default_character_kind
)
14143 return SEQ_NONDEFAULT
;
14145 return SEQ_CHARACTER
;
14148 if (ts
.kind
!= gfc_default_integer_kind
)
14149 return SEQ_NONDEFAULT
;
14151 return SEQ_NUMERIC
;
14154 if (!(ts
.kind
== gfc_default_real_kind
14155 || ts
.kind
== gfc_default_double_kind
))
14156 return SEQ_NONDEFAULT
;
14158 return SEQ_NUMERIC
;
14161 if (ts
.kind
!= gfc_default_complex_kind
)
14162 return SEQ_NONDEFAULT
;
14164 return SEQ_NUMERIC
;
14167 if (ts
.kind
!= gfc_default_logical_kind
)
14168 return SEQ_NONDEFAULT
;
14170 return SEQ_NUMERIC
;
14173 return SEQ_NONDEFAULT
;
14178 /* Resolve derived type EQUIVALENCE object. */
14181 resolve_equivalence_derived (gfc_symbol
*derived
, gfc_symbol
*sym
, gfc_expr
*e
)
14183 gfc_component
*c
= derived
->components
;
14188 /* Shall not be an object of nonsequence derived type. */
14189 if (!derived
->attr
.sequence
)
14191 gfc_error ("Derived type variable '%s' at %L must have SEQUENCE "
14192 "attribute to be an EQUIVALENCE object", sym
->name
,
14197 /* Shall not have allocatable components. */
14198 if (derived
->attr
.alloc_comp
)
14200 gfc_error ("Derived type variable '%s' at %L cannot have ALLOCATABLE "
14201 "components to be an EQUIVALENCE object",sym
->name
,
14206 if (sym
->attr
.in_common
&& gfc_has_default_initializer (sym
->ts
.u
.derived
))
14208 gfc_error ("Derived type variable '%s' at %L with default "
14209 "initialization cannot be in EQUIVALENCE with a variable "
14210 "in COMMON", sym
->name
, &e
->where
);
14214 for (; c
; c
= c
->next
)
14216 if (c
->ts
.type
== BT_DERIVED
14217 && (!resolve_equivalence_derived(c
->ts
.u
.derived
, sym
, e
)))
14220 /* Shall not be an object of sequence derived type containing a pointer
14221 in the structure. */
14222 if (c
->attr
.pointer
)
14224 gfc_error ("Derived type variable '%s' at %L with pointer "
14225 "component(s) cannot be an EQUIVALENCE object",
14226 sym
->name
, &e
->where
);
14234 /* Resolve equivalence object.
14235 An EQUIVALENCE object shall not be a dummy argument, a pointer, a target,
14236 an allocatable array, an object of nonsequence derived type, an object of
14237 sequence derived type containing a pointer at any level of component
14238 selection, an automatic object, a function name, an entry name, a result
14239 name, a named constant, a structure component, or a subobject of any of
14240 the preceding objects. A substring shall not have length zero. A
14241 derived type shall not have components with default initialization nor
14242 shall two objects of an equivalence group be initialized.
14243 Either all or none of the objects shall have an protected attribute.
14244 The simple constraints are done in symbol.c(check_conflict) and the rest
14245 are implemented here. */
14248 resolve_equivalence (gfc_equiv
*eq
)
14251 gfc_symbol
*first_sym
;
14254 locus
*last_where
= NULL
;
14255 seq_type eq_type
, last_eq_type
;
14256 gfc_typespec
*last_ts
;
14257 int object
, cnt_protected
;
14260 last_ts
= &eq
->expr
->symtree
->n
.sym
->ts
;
14262 first_sym
= eq
->expr
->symtree
->n
.sym
;
14266 for (object
= 1; eq
; eq
= eq
->eq
, object
++)
14270 e
->ts
= e
->symtree
->n
.sym
->ts
;
14271 /* match_varspec might not know yet if it is seeing
14272 array reference or substring reference, as it doesn't
14274 if (e
->ref
&& e
->ref
->type
== REF_ARRAY
)
14276 gfc_ref
*ref
= e
->ref
;
14277 sym
= e
->symtree
->n
.sym
;
14279 if (sym
->attr
.dimension
)
14281 ref
->u
.ar
.as
= sym
->as
;
14285 /* For substrings, convert REF_ARRAY into REF_SUBSTRING. */
14286 if (e
->ts
.type
== BT_CHARACTER
14288 && ref
->type
== REF_ARRAY
14289 && ref
->u
.ar
.dimen
== 1
14290 && ref
->u
.ar
.dimen_type
[0] == DIMEN_RANGE
14291 && ref
->u
.ar
.stride
[0] == NULL
)
14293 gfc_expr
*start
= ref
->u
.ar
.start
[0];
14294 gfc_expr
*end
= ref
->u
.ar
.end
[0];
14297 /* Optimize away the (:) reference. */
14298 if (start
== NULL
&& end
== NULL
)
14301 e
->ref
= ref
->next
;
14303 e
->ref
->next
= ref
->next
;
14308 ref
->type
= REF_SUBSTRING
;
14310 start
= gfc_get_int_expr (gfc_default_integer_kind
,
14312 ref
->u
.ss
.start
= start
;
14313 if (end
== NULL
&& e
->ts
.u
.cl
)
14314 end
= gfc_copy_expr (e
->ts
.u
.cl
->length
);
14315 ref
->u
.ss
.end
= end
;
14316 ref
->u
.ss
.length
= e
->ts
.u
.cl
;
14323 /* Any further ref is an error. */
14326 gcc_assert (ref
->type
== REF_ARRAY
);
14327 gfc_error ("Syntax error in EQUIVALENCE statement at %L",
14333 if (!gfc_resolve_expr (e
))
14336 sym
= e
->symtree
->n
.sym
;
14338 if (sym
->attr
.is_protected
)
14340 if (cnt_protected
> 0 && cnt_protected
!= object
)
14342 gfc_error ("Either all or none of the objects in the "
14343 "EQUIVALENCE set at %L shall have the "
14344 "PROTECTED attribute",
14349 /* Shall not equivalence common block variables in a PURE procedure. */
14350 if (sym
->ns
->proc_name
14351 && sym
->ns
->proc_name
->attr
.pure
14352 && sym
->attr
.in_common
)
14354 gfc_error ("Common block member '%s' at %L cannot be an EQUIVALENCE "
14355 "object in the pure procedure '%s'",
14356 sym
->name
, &e
->where
, sym
->ns
->proc_name
->name
);
14360 /* Shall not be a named constant. */
14361 if (e
->expr_type
== EXPR_CONSTANT
)
14363 gfc_error ("Named constant '%s' at %L cannot be an EQUIVALENCE "
14364 "object", sym
->name
, &e
->where
);
14368 if (e
->ts
.type
== BT_DERIVED
14369 && !resolve_equivalence_derived (e
->ts
.u
.derived
, sym
, e
))
14372 /* Check that the types correspond correctly:
14374 A numeric sequence structure may be equivalenced to another sequence
14375 structure, an object of default integer type, default real type, double
14376 precision real type, default logical type such that components of the
14377 structure ultimately only become associated to objects of the same
14378 kind. A character sequence structure may be equivalenced to an object
14379 of default character kind or another character sequence structure.
14380 Other objects may be equivalenced only to objects of the same type and
14381 kind parameters. */
14383 /* Identical types are unconditionally OK. */
14384 if (object
== 1 || gfc_compare_types (last_ts
, &sym
->ts
))
14385 goto identical_types
;
14387 last_eq_type
= sequence_type (*last_ts
);
14388 eq_type
= sequence_type (sym
->ts
);
14390 /* Since the pair of objects is not of the same type, mixed or
14391 non-default sequences can be rejected. */
14393 msg
= "Sequence %s with mixed components in EQUIVALENCE "
14394 "statement at %L with different type objects";
14396 && last_eq_type
== SEQ_MIXED
14397 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
14398 || (eq_type
== SEQ_MIXED
14399 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
14402 msg
= "Non-default type object or sequence %s in EQUIVALENCE "
14403 "statement at %L with objects of different type";
14405 && last_eq_type
== SEQ_NONDEFAULT
14406 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
14407 || (eq_type
== SEQ_NONDEFAULT
14408 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
14411 msg
="Non-CHARACTER object '%s' in default CHARACTER "
14412 "EQUIVALENCE statement at %L";
14413 if (last_eq_type
== SEQ_CHARACTER
14414 && eq_type
!= SEQ_CHARACTER
14415 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
14418 msg
="Non-NUMERIC object '%s' in default NUMERIC "
14419 "EQUIVALENCE statement at %L";
14420 if (last_eq_type
== SEQ_NUMERIC
14421 && eq_type
!= SEQ_NUMERIC
14422 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
14427 last_where
= &e
->where
;
14432 /* Shall not be an automatic array. */
14433 if (e
->ref
->type
== REF_ARRAY
14434 && !gfc_resolve_array_spec (e
->ref
->u
.ar
.as
, 1))
14436 gfc_error ("Array '%s' at %L with non-constant bounds cannot be "
14437 "an EQUIVALENCE object", sym
->name
, &e
->where
);
14444 /* Shall not be a structure component. */
14445 if (r
->type
== REF_COMPONENT
)
14447 gfc_error ("Structure component '%s' at %L cannot be an "
14448 "EQUIVALENCE object",
14449 r
->u
.c
.component
->name
, &e
->where
);
14453 /* A substring shall not have length zero. */
14454 if (r
->type
== REF_SUBSTRING
)
14456 if (compare_bound (r
->u
.ss
.start
, r
->u
.ss
.end
) == CMP_GT
)
14458 gfc_error ("Substring at %L has length zero",
14459 &r
->u
.ss
.start
->where
);
14469 /* Resolve function and ENTRY types, issue diagnostics if needed. */
14472 resolve_fntype (gfc_namespace
*ns
)
14474 gfc_entry_list
*el
;
14477 if (ns
->proc_name
== NULL
|| !ns
->proc_name
->attr
.function
)
14480 /* If there are any entries, ns->proc_name is the entry master
14481 synthetic symbol and ns->entries->sym actual FUNCTION symbol. */
14483 sym
= ns
->entries
->sym
;
14485 sym
= ns
->proc_name
;
14486 if (sym
->result
== sym
14487 && sym
->ts
.type
== BT_UNKNOWN
14488 && !gfc_set_default_type (sym
, 0, NULL
)
14489 && !sym
->attr
.untyped
)
14491 gfc_error ("Function '%s' at %L has no IMPLICIT type",
14492 sym
->name
, &sym
->declared_at
);
14493 sym
->attr
.untyped
= 1;
14496 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->ts
.u
.derived
->attr
.use_assoc
14497 && !sym
->attr
.contained
14498 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
14499 && gfc_check_symbol_access (sym
))
14501 gfc_notify_std (GFC_STD_F2003
, "PUBLIC function '%s' at "
14502 "%L of PRIVATE type '%s'", sym
->name
,
14503 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
14507 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
14509 if (el
->sym
->result
== el
->sym
14510 && el
->sym
->ts
.type
== BT_UNKNOWN
14511 && !gfc_set_default_type (el
->sym
, 0, NULL
)
14512 && !el
->sym
->attr
.untyped
)
14514 gfc_error ("ENTRY '%s' at %L has no IMPLICIT type",
14515 el
->sym
->name
, &el
->sym
->declared_at
);
14516 el
->sym
->attr
.untyped
= 1;
14522 /* 12.3.2.1.1 Defined operators. */
14525 check_uop_procedure (gfc_symbol
*sym
, locus where
)
14527 gfc_formal_arglist
*formal
;
14529 if (!sym
->attr
.function
)
14531 gfc_error ("User operator procedure '%s' at %L must be a FUNCTION",
14532 sym
->name
, &where
);
14536 if (sym
->ts
.type
== BT_CHARACTER
14537 && !(sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
)
14538 && !(sym
->result
&& sym
->result
->ts
.u
.cl
14539 && sym
->result
->ts
.u
.cl
->length
))
14541 gfc_error ("User operator procedure '%s' at %L cannot be assumed "
14542 "character length", sym
->name
, &where
);
14546 formal
= gfc_sym_get_dummy_args (sym
);
14547 if (!formal
|| !formal
->sym
)
14549 gfc_error ("User operator procedure '%s' at %L must have at least "
14550 "one argument", sym
->name
, &where
);
14554 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
14556 gfc_error ("First argument of operator interface at %L must be "
14557 "INTENT(IN)", &where
);
14561 if (formal
->sym
->attr
.optional
)
14563 gfc_error ("First argument of operator interface at %L cannot be "
14564 "optional", &where
);
14568 formal
= formal
->next
;
14569 if (!formal
|| !formal
->sym
)
14572 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
14574 gfc_error ("Second argument of operator interface at %L must be "
14575 "INTENT(IN)", &where
);
14579 if (formal
->sym
->attr
.optional
)
14581 gfc_error ("Second argument of operator interface at %L cannot be "
14582 "optional", &where
);
14588 gfc_error ("Operator interface at %L must have, at most, two "
14589 "arguments", &where
);
14597 gfc_resolve_uops (gfc_symtree
*symtree
)
14599 gfc_interface
*itr
;
14601 if (symtree
== NULL
)
14604 gfc_resolve_uops (symtree
->left
);
14605 gfc_resolve_uops (symtree
->right
);
14607 for (itr
= symtree
->n
.uop
->op
; itr
; itr
= itr
->next
)
14608 check_uop_procedure (itr
->sym
, itr
->sym
->declared_at
);
14612 /* Examine all of the expressions associated with a program unit,
14613 assign types to all intermediate expressions, make sure that all
14614 assignments are to compatible types and figure out which names
14615 refer to which functions or subroutines. It doesn't check code
14616 block, which is handled by resolve_code. */
14619 resolve_types (gfc_namespace
*ns
)
14625 gfc_namespace
* old_ns
= gfc_current_ns
;
14627 /* Check that all IMPLICIT types are ok. */
14628 if (!ns
->seen_implicit_none
)
14631 for (letter
= 0; letter
!= GFC_LETTERS
; ++letter
)
14632 if (ns
->set_flag
[letter
]
14633 && !resolve_typespec_used (&ns
->default_type
[letter
],
14634 &ns
->implicit_loc
[letter
], NULL
))
14638 gfc_current_ns
= ns
;
14640 resolve_entries (ns
);
14642 resolve_common_vars (ns
->blank_common
.head
, false);
14643 resolve_common_blocks (ns
->common_root
);
14645 resolve_contained_functions (ns
);
14647 if (ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
14648 && ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
14649 resolve_formal_arglist (ns
->proc_name
);
14651 gfc_traverse_ns (ns
, resolve_bind_c_derived_types
);
14653 for (cl
= ns
->cl_list
; cl
; cl
= cl
->next
)
14654 resolve_charlen (cl
);
14656 gfc_traverse_ns (ns
, resolve_symbol
);
14658 resolve_fntype (ns
);
14660 for (n
= ns
->contained
; n
; n
= n
->sibling
)
14662 if (gfc_pure (ns
->proc_name
) && !gfc_pure (n
->proc_name
))
14663 gfc_error ("Contained procedure '%s' at %L of a PURE procedure must "
14664 "also be PURE", n
->proc_name
->name
,
14665 &n
->proc_name
->declared_at
);
14671 gfc_do_concurrent_flag
= 0;
14672 gfc_check_interfaces (ns
);
14674 gfc_traverse_ns (ns
, resolve_values
);
14680 for (d
= ns
->data
; d
; d
= d
->next
)
14684 gfc_traverse_ns (ns
, gfc_formalize_init_value
);
14686 gfc_traverse_ns (ns
, gfc_verify_binding_labels
);
14688 for (eq
= ns
->equiv
; eq
; eq
= eq
->next
)
14689 resolve_equivalence (eq
);
14691 /* Warn about unused labels. */
14692 if (warn_unused_label
)
14693 warn_unused_fortran_label (ns
->st_labels
);
14695 gfc_resolve_uops (ns
->uop_root
);
14697 gfc_resolve_omp_declare_simd (ns
);
14699 gfc_current_ns
= old_ns
;
14703 /* Call resolve_code recursively. */
14706 resolve_codes (gfc_namespace
*ns
)
14709 bitmap_obstack old_obstack
;
14711 if (ns
->resolved
== 1)
14714 for (n
= ns
->contained
; n
; n
= n
->sibling
)
14717 gfc_current_ns
= ns
;
14719 /* Don't clear 'cs_base' if this is the namespace of a BLOCK construct. */
14720 if (!(ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_LABEL
))
14723 /* Set to an out of range value. */
14724 current_entry_id
= -1;
14726 old_obstack
= labels_obstack
;
14727 bitmap_obstack_initialize (&labels_obstack
);
14729 resolve_code (ns
->code
, ns
);
14731 bitmap_obstack_release (&labels_obstack
);
14732 labels_obstack
= old_obstack
;
14736 /* This function is called after a complete program unit has been compiled.
14737 Its purpose is to examine all of the expressions associated with a program
14738 unit, assign types to all intermediate expressions, make sure that all
14739 assignments are to compatible types and figure out which names refer to
14740 which functions or subroutines. */
14743 gfc_resolve (gfc_namespace
*ns
)
14745 gfc_namespace
*old_ns
;
14746 code_stack
*old_cs_base
;
14752 old_ns
= gfc_current_ns
;
14753 old_cs_base
= cs_base
;
14755 resolve_types (ns
);
14756 component_assignment_level
= 0;
14757 resolve_codes (ns
);
14759 gfc_current_ns
= old_ns
;
14760 cs_base
= old_cs_base
;
14763 gfc_run_passes (ns
);