1 /* Perform type resolution on the various structures.
2 Copyright (C) 2001-2021 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 #include "arith.h" /* For gfc_compare_expr(). */
28 #include "dependency.h"
30 #include "target-memory.h" /* for gfc_simplify_transfer */
31 #include "constructor.h"
33 /* Types used in equivalence statements. */
37 SEQ_NONDEFAULT
, SEQ_NUMERIC
, SEQ_CHARACTER
, SEQ_MIXED
40 /* Stack to keep track of the nesting of blocks as we move through the
41 code. See resolve_branch() and gfc_resolve_code(). */
43 typedef struct code_stack
45 struct gfc_code
*head
, *current
;
46 struct code_stack
*prev
;
48 /* This bitmap keeps track of the targets valid for a branch from
49 inside this block except for END {IF|SELECT}s of enclosing
51 bitmap reachable_labels
;
55 static code_stack
*cs_base
= NULL
;
58 /* Nonzero if we're inside a FORALL or DO CONCURRENT block. */
60 static int forall_flag
;
61 int gfc_do_concurrent_flag
;
63 /* True when we are resolving an expression that is an actual argument to
65 static bool actual_arg
= false;
66 /* True when we are resolving an expression that is the first actual argument
68 static bool first_actual_arg
= false;
71 /* Nonzero if we're inside a OpenMP WORKSHARE or PARALLEL WORKSHARE block. */
73 static int omp_workshare_flag
;
75 /* True if we are processing a formal arglist. The corresponding function
76 resets the flag each time that it is read. */
77 static bool formal_arg_flag
= false;
79 /* True if we are resolving a specification expression. */
80 static bool specification_expr
= false;
82 /* The id of the last entry seen. */
83 static int current_entry_id
;
85 /* We use bitmaps to determine if a branch target is valid. */
86 static bitmap_obstack labels_obstack
;
88 /* True when simplifying a EXPR_VARIABLE argument to an inquiry function. */
89 static bool inquiry_argument
= false;
93 gfc_is_formal_arg (void)
95 return formal_arg_flag
;
98 /* Is the symbol host associated? */
100 is_sym_host_assoc (gfc_symbol
*sym
, gfc_namespace
*ns
)
102 for (ns
= ns
->parent
; ns
; ns
= ns
->parent
)
111 /* Ensure a typespec used is valid; for instance, TYPE(t) is invalid if t is
112 an ABSTRACT derived-type. If where is not NULL, an error message with that
113 locus is printed, optionally using name. */
116 resolve_typespec_used (gfc_typespec
* ts
, locus
* where
, const char* name
)
118 if (ts
->type
== BT_DERIVED
&& ts
->u
.derived
->attr
.abstract
)
123 gfc_error ("%qs at %L is of the ABSTRACT type %qs",
124 name
, where
, ts
->u
.derived
->name
);
126 gfc_error ("ABSTRACT type %qs used at %L",
127 ts
->u
.derived
->name
, where
);
138 check_proc_interface (gfc_symbol
*ifc
, locus
*where
)
140 /* Several checks for F08:C1216. */
141 if (ifc
->attr
.procedure
)
143 gfc_error ("Interface %qs at %L is declared "
144 "in a later PROCEDURE statement", ifc
->name
, where
);
149 /* For generic interfaces, check if there is
150 a specific procedure with the same name. */
151 gfc_interface
*gen
= ifc
->generic
;
152 while (gen
&& strcmp (gen
->sym
->name
, ifc
->name
) != 0)
156 gfc_error ("Interface %qs at %L may not be generic",
161 if (ifc
->attr
.proc
== PROC_ST_FUNCTION
)
163 gfc_error ("Interface %qs at %L may not be a statement function",
167 if (gfc_is_intrinsic (ifc
, 0, ifc
->declared_at
)
168 || gfc_is_intrinsic (ifc
, 1, ifc
->declared_at
))
169 ifc
->attr
.intrinsic
= 1;
170 if (ifc
->attr
.intrinsic
&& !gfc_intrinsic_actual_ok (ifc
->name
, 0))
172 gfc_error ("Intrinsic procedure %qs not allowed in "
173 "PROCEDURE statement at %L", ifc
->name
, where
);
176 if (!ifc
->attr
.if_source
&& !ifc
->attr
.intrinsic
&& ifc
->name
[0] != '\0')
178 gfc_error ("Interface %qs at %L must be explicit", ifc
->name
, where
);
185 static void resolve_symbol (gfc_symbol
*sym
);
188 /* Resolve the interface for a PROCEDURE declaration or procedure pointer. */
191 resolve_procedure_interface (gfc_symbol
*sym
)
193 gfc_symbol
*ifc
= sym
->ts
.interface
;
200 gfc_error ("PROCEDURE %qs at %L may not be used as its own interface",
201 sym
->name
, &sym
->declared_at
);
204 if (!check_proc_interface (ifc
, &sym
->declared_at
))
207 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
209 /* Resolve interface and copy attributes. */
210 resolve_symbol (ifc
);
211 if (ifc
->attr
.intrinsic
)
212 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
216 sym
->ts
= ifc
->result
->ts
;
217 sym
->attr
.allocatable
= ifc
->result
->attr
.allocatable
;
218 sym
->attr
.pointer
= ifc
->result
->attr
.pointer
;
219 sym
->attr
.dimension
= ifc
->result
->attr
.dimension
;
220 sym
->attr
.class_ok
= ifc
->result
->attr
.class_ok
;
221 sym
->as
= gfc_copy_array_spec (ifc
->result
->as
);
227 sym
->attr
.allocatable
= ifc
->attr
.allocatable
;
228 sym
->attr
.pointer
= ifc
->attr
.pointer
;
229 sym
->attr
.dimension
= ifc
->attr
.dimension
;
230 sym
->attr
.class_ok
= ifc
->attr
.class_ok
;
231 sym
->as
= gfc_copy_array_spec (ifc
->as
);
233 sym
->ts
.interface
= ifc
;
234 sym
->attr
.function
= ifc
->attr
.function
;
235 sym
->attr
.subroutine
= ifc
->attr
.subroutine
;
237 sym
->attr
.pure
= ifc
->attr
.pure
;
238 sym
->attr
.elemental
= ifc
->attr
.elemental
;
239 sym
->attr
.contiguous
= ifc
->attr
.contiguous
;
240 sym
->attr
.recursive
= ifc
->attr
.recursive
;
241 sym
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
242 sym
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
243 sym
->attr
.is_bind_c
= ifc
->attr
.is_bind_c
;
244 /* Copy char length. */
245 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
247 sym
->ts
.u
.cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
248 if (sym
->ts
.u
.cl
->length
&& !sym
->ts
.u
.cl
->resolved
249 && !gfc_resolve_expr (sym
->ts
.u
.cl
->length
))
258 /* Resolve types of formal argument lists. These have to be done early so that
259 the formal argument lists of module procedures can be copied to the
260 containing module before the individual procedures are resolved
261 individually. We also resolve argument lists of procedures in interface
262 blocks because they are self-contained scoping units.
264 Since a dummy argument cannot be a non-dummy procedure, the only
265 resort left for untyped names are the IMPLICIT types. */
268 gfc_resolve_formal_arglist (gfc_symbol
*proc
)
270 gfc_formal_arglist
*f
;
272 bool saved_specification_expr
;
275 if (proc
->result
!= NULL
)
280 if (gfc_elemental (proc
)
281 || sym
->attr
.pointer
|| sym
->attr
.allocatable
282 || (sym
->as
&& sym
->as
->rank
!= 0))
284 proc
->attr
.always_explicit
= 1;
285 sym
->attr
.always_explicit
= 1;
288 formal_arg_flag
= true;
290 for (f
= proc
->formal
; f
; f
= f
->next
)
298 /* Alternate return placeholder. */
299 if (gfc_elemental (proc
))
300 gfc_error ("Alternate return specifier in elemental subroutine "
301 "%qs at %L is not allowed", proc
->name
,
303 if (proc
->attr
.function
)
304 gfc_error ("Alternate return specifier in function "
305 "%qs at %L is not allowed", proc
->name
,
309 else if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
310 && !resolve_procedure_interface (sym
))
313 if (strcmp (proc
->name
, sym
->name
) == 0)
315 gfc_error ("Self-referential argument "
316 "%qs at %L is not allowed", sym
->name
,
321 if (sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
322 gfc_resolve_formal_arglist (sym
);
324 if (sym
->attr
.subroutine
|| sym
->attr
.external
)
326 if (sym
->attr
.flavor
== FL_UNKNOWN
)
327 gfc_add_flavor (&sym
->attr
, FL_PROCEDURE
, sym
->name
, &sym
->declared_at
);
331 if (sym
->ts
.type
== BT_UNKNOWN
&& !proc
->attr
.intrinsic
332 && (!sym
->attr
.function
|| sym
->result
== sym
))
333 gfc_set_default_type (sym
, 1, sym
->ns
);
336 as
= sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
337 ? CLASS_DATA (sym
)->as
: sym
->as
;
339 saved_specification_expr
= specification_expr
;
340 specification_expr
= true;
341 gfc_resolve_array_spec (as
, 0);
342 specification_expr
= saved_specification_expr
;
344 /* We can't tell if an array with dimension (:) is assumed or deferred
345 shape until we know if it has the pointer or allocatable attributes.
347 if (as
&& as
->rank
> 0 && as
->type
== AS_DEFERRED
348 && ((sym
->ts
.type
!= BT_CLASS
349 && !(sym
->attr
.pointer
|| sym
->attr
.allocatable
))
350 || (sym
->ts
.type
== BT_CLASS
351 && !(CLASS_DATA (sym
)->attr
.class_pointer
352 || CLASS_DATA (sym
)->attr
.allocatable
)))
353 && sym
->attr
.flavor
!= FL_PROCEDURE
)
355 as
->type
= AS_ASSUMED_SHAPE
;
356 for (i
= 0; i
< as
->rank
; i
++)
357 as
->lower
[i
] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
360 if ((as
&& as
->rank
> 0 && as
->type
== AS_ASSUMED_SHAPE
)
361 || (as
&& as
->type
== AS_ASSUMED_RANK
)
362 || sym
->attr
.pointer
|| sym
->attr
.allocatable
|| sym
->attr
.target
363 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
364 && (CLASS_DATA (sym
)->attr
.class_pointer
365 || CLASS_DATA (sym
)->attr
.allocatable
366 || CLASS_DATA (sym
)->attr
.target
))
367 || sym
->attr
.optional
)
369 proc
->attr
.always_explicit
= 1;
371 proc
->result
->attr
.always_explicit
= 1;
374 /* If the flavor is unknown at this point, it has to be a variable.
375 A procedure specification would have already set the type. */
377 if (sym
->attr
.flavor
== FL_UNKNOWN
)
378 gfc_add_flavor (&sym
->attr
, FL_VARIABLE
, sym
->name
, &sym
->declared_at
);
382 if (sym
->attr
.flavor
== FL_PROCEDURE
)
387 gfc_error ("Dummy procedure %qs of PURE procedure at %L must "
388 "also be PURE", sym
->name
, &sym
->declared_at
);
392 else if (!sym
->attr
.pointer
)
394 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
)
397 gfc_notify_std (GFC_STD_F2008
, "Argument %qs"
398 " of pure function %qs at %L with VALUE "
399 "attribute but without INTENT(IN)",
400 sym
->name
, proc
->name
, &sym
->declared_at
);
402 gfc_error ("Argument %qs of pure function %qs at %L must "
403 "be INTENT(IN) or VALUE", sym
->name
, proc
->name
,
407 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
)
410 gfc_notify_std (GFC_STD_F2008
, "Argument %qs"
411 " of pure subroutine %qs at %L with VALUE "
412 "attribute but without INTENT", sym
->name
,
413 proc
->name
, &sym
->declared_at
);
415 gfc_error ("Argument %qs of pure subroutine %qs at %L "
416 "must have its INTENT specified or have the "
417 "VALUE attribute", sym
->name
, proc
->name
,
423 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.intent
== INTENT_OUT
)
425 gfc_error ("INTENT(OUT) argument %qs of pure procedure %qs at %L"
426 " may not be polymorphic", sym
->name
, proc
->name
,
432 if (proc
->attr
.implicit_pure
)
434 if (sym
->attr
.flavor
== FL_PROCEDURE
)
437 proc
->attr
.implicit_pure
= 0;
439 else if (!sym
->attr
.pointer
)
441 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
443 proc
->attr
.implicit_pure
= 0;
445 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
447 proc
->attr
.implicit_pure
= 0;
451 if (gfc_elemental (proc
))
454 if (sym
->attr
.codimension
455 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
456 && CLASS_DATA (sym
)->attr
.codimension
))
458 gfc_error ("Coarray dummy argument %qs at %L to elemental "
459 "procedure", sym
->name
, &sym
->declared_at
);
463 if (sym
->as
|| (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
464 && CLASS_DATA (sym
)->as
))
466 gfc_error ("Argument %qs of elemental procedure at %L must "
467 "be scalar", sym
->name
, &sym
->declared_at
);
471 if (sym
->attr
.allocatable
472 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
473 && CLASS_DATA (sym
)->attr
.allocatable
))
475 gfc_error ("Argument %qs of elemental procedure at %L cannot "
476 "have the ALLOCATABLE attribute", sym
->name
,
481 if (sym
->attr
.pointer
482 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
483 && CLASS_DATA (sym
)->attr
.class_pointer
))
485 gfc_error ("Argument %qs of elemental procedure at %L cannot "
486 "have the POINTER attribute", sym
->name
,
491 if (sym
->attr
.flavor
== FL_PROCEDURE
)
493 gfc_error ("Dummy procedure %qs not allowed in elemental "
494 "procedure %qs at %L", sym
->name
, proc
->name
,
499 /* Fortran 2008 Corrigendum 1, C1290a. */
500 if (sym
->attr
.intent
== INTENT_UNKNOWN
&& !sym
->attr
.value
)
502 gfc_error ("Argument %qs of elemental procedure %qs at %L must "
503 "have its INTENT specified or have the VALUE "
504 "attribute", sym
->name
, proc
->name
,
510 /* Each dummy shall be specified to be scalar. */
511 if (proc
->attr
.proc
== PROC_ST_FUNCTION
)
515 /* F03:C1263 (R1238) The function-name and each dummy-arg-name
516 shall be specified, explicitly or implicitly, to be scalar. */
517 gfc_error ("Argument '%s' of statement function '%s' at %L "
518 "must be scalar", sym
->name
, proc
->name
,
523 if (sym
->ts
.type
== BT_CHARACTER
)
525 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
526 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
528 gfc_error ("Character-valued argument %qs of statement "
529 "function at %L must have constant length",
530 sym
->name
, &sym
->declared_at
);
536 formal_arg_flag
= false;
540 /* Work function called when searching for symbols that have argument lists
541 associated with them. */
544 find_arglists (gfc_symbol
*sym
)
546 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
|| sym
->ns
!= gfc_current_ns
547 || gfc_fl_struct (sym
->attr
.flavor
) || sym
->attr
.intrinsic
)
550 gfc_resolve_formal_arglist (sym
);
554 /* Given a namespace, resolve all formal argument lists within the namespace.
558 resolve_formal_arglists (gfc_namespace
*ns
)
563 gfc_traverse_ns (ns
, find_arglists
);
568 resolve_contained_fntype (gfc_symbol
*sym
, gfc_namespace
*ns
)
572 if (sym
&& sym
->attr
.flavor
== FL_PROCEDURE
574 && sym
->ns
->parent
->proc_name
575 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_PROCEDURE
576 && !strcmp (sym
->name
, sym
->ns
->parent
->proc_name
->name
))
577 gfc_error ("Contained procedure %qs at %L has the same name as its "
578 "encompassing procedure", sym
->name
, &sym
->declared_at
);
580 /* If this namespace is not a function or an entry master function,
582 if (! sym
|| !(sym
->attr
.function
|| sym
->attr
.flavor
== FL_VARIABLE
)
583 || sym
->attr
.entry_master
)
589 /* Try to find out of what the return type is. */
590 if (sym
->result
->ts
.type
== BT_UNKNOWN
&& sym
->result
->ts
.interface
== NULL
)
592 t
= gfc_set_default_type (sym
->result
, 0, ns
);
594 if (!t
&& !sym
->result
->attr
.untyped
)
596 if (sym
->result
== sym
)
597 gfc_error ("Contained function %qs at %L has no IMPLICIT type",
598 sym
->name
, &sym
->declared_at
);
599 else if (!sym
->result
->attr
.proc_pointer
)
600 gfc_error ("Result %qs of contained function %qs at %L has "
601 "no IMPLICIT type", sym
->result
->name
, sym
->name
,
602 &sym
->result
->declared_at
);
603 sym
->result
->attr
.untyped
= 1;
607 /* Fortran 2008 Draft Standard, page 535, C418, on type-param-value
608 type, lists the only ways a character length value of * can be used:
609 dummy arguments of procedures, named constants, function results and
610 in allocate statements if the allocate_object is an assumed length dummy
611 in external functions. Internal function results and results of module
612 procedures are not on this list, ergo, not permitted. */
614 if (sym
->result
->ts
.type
== BT_CHARACTER
)
616 gfc_charlen
*cl
= sym
->result
->ts
.u
.cl
;
617 if ((!cl
|| !cl
->length
) && !sym
->result
->ts
.deferred
)
619 /* See if this is a module-procedure and adapt error message
622 gcc_assert (ns
->parent
&& ns
->parent
->proc_name
);
623 module_proc
= (ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
);
625 gfc_error (module_proc
626 ? G_("Character-valued module procedure %qs at %L"
627 " must not be assumed length")
628 : G_("Character-valued internal function %qs at %L"
629 " must not be assumed length"),
630 sym
->name
, &sym
->declared_at
);
636 /* Add NEW_ARGS to the formal argument list of PROC, taking care not to
637 introduce duplicates. */
640 merge_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
642 gfc_formal_arglist
*f
, *new_arglist
;
645 for (; new_args
!= NULL
; new_args
= new_args
->next
)
647 new_sym
= new_args
->sym
;
648 /* See if this arg is already in the formal argument list. */
649 for (f
= proc
->formal
; f
; f
= f
->next
)
651 if (new_sym
== f
->sym
)
658 /* Add a new argument. Argument order is not important. */
659 new_arglist
= gfc_get_formal_arglist ();
660 new_arglist
->sym
= new_sym
;
661 new_arglist
->next
= proc
->formal
;
662 proc
->formal
= new_arglist
;
667 /* Flag the arguments that are not present in all entries. */
670 check_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
672 gfc_formal_arglist
*f
, *head
;
675 for (f
= proc
->formal
; f
; f
= f
->next
)
680 for (new_args
= head
; new_args
; new_args
= new_args
->next
)
682 if (new_args
->sym
== f
->sym
)
689 f
->sym
->attr
.not_always_present
= 1;
694 /* Resolve alternate entry points. If a symbol has multiple entry points we
695 create a new master symbol for the main routine, and turn the existing
696 symbol into an entry point. */
699 resolve_entries (gfc_namespace
*ns
)
701 gfc_namespace
*old_ns
;
705 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
706 static int master_count
= 0;
708 if (ns
->proc_name
== NULL
)
711 /* No need to do anything if this procedure doesn't have alternate entry
716 /* We may already have resolved alternate entry points. */
717 if (ns
->proc_name
->attr
.entry_master
)
720 /* If this isn't a procedure something has gone horribly wrong. */
721 gcc_assert (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
);
723 /* Remember the current namespace. */
724 old_ns
= gfc_current_ns
;
728 /* Add the main entry point to the list of entry points. */
729 el
= gfc_get_entry_list ();
730 el
->sym
= ns
->proc_name
;
732 el
->next
= ns
->entries
;
734 ns
->proc_name
->attr
.entry
= 1;
736 /* If it is a module function, it needs to be in the right namespace
737 so that gfc_get_fake_result_decl can gather up the results. The
738 need for this arose in get_proc_name, where these beasts were
739 left in their own namespace, to keep prior references linked to
740 the entry declaration.*/
741 if (ns
->proc_name
->attr
.function
742 && ns
->parent
&& ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
745 /* Do the same for entries where the master is not a module
746 procedure. These are retained in the module namespace because
747 of the module procedure declaration. */
748 for (el
= el
->next
; el
; el
= el
->next
)
749 if (el
->sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
750 && el
->sym
->attr
.mod_proc
)
754 /* Add an entry statement for it. */
755 c
= gfc_get_code (EXEC_ENTRY
);
760 /* Create a new symbol for the master function. */
761 /* Give the internal function a unique name (within this file).
762 Also include the function name so the user has some hope of figuring
763 out what is going on. */
764 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "master.%d.%s",
765 master_count
++, ns
->proc_name
->name
);
766 gfc_get_ha_symbol (name
, &proc
);
767 gcc_assert (proc
!= NULL
);
769 gfc_add_procedure (&proc
->attr
, PROC_INTERNAL
, proc
->name
, NULL
);
770 if (ns
->proc_name
->attr
.subroutine
)
771 gfc_add_subroutine (&proc
->attr
, proc
->name
, NULL
);
775 gfc_typespec
*ts
, *fts
;
776 gfc_array_spec
*as
, *fas
;
777 gfc_add_function (&proc
->attr
, proc
->name
, NULL
);
779 fas
= ns
->entries
->sym
->as
;
780 fas
= fas
? fas
: ns
->entries
->sym
->result
->as
;
781 fts
= &ns
->entries
->sym
->result
->ts
;
782 if (fts
->type
== BT_UNKNOWN
)
783 fts
= gfc_get_default_type (ns
->entries
->sym
->result
->name
, NULL
);
784 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
786 ts
= &el
->sym
->result
->ts
;
788 as
= as
? as
: el
->sym
->result
->as
;
789 if (ts
->type
== BT_UNKNOWN
)
790 ts
= gfc_get_default_type (el
->sym
->result
->name
, NULL
);
792 if (! gfc_compare_types (ts
, fts
)
793 || (el
->sym
->result
->attr
.dimension
794 != ns
->entries
->sym
->result
->attr
.dimension
)
795 || (el
->sym
->result
->attr
.pointer
796 != ns
->entries
->sym
->result
->attr
.pointer
))
798 else if (as
&& fas
&& ns
->entries
->sym
->result
!= el
->sym
->result
799 && gfc_compare_array_spec (as
, fas
) == 0)
800 gfc_error ("Function %s at %L has entries with mismatched "
801 "array specifications", ns
->entries
->sym
->name
,
802 &ns
->entries
->sym
->declared_at
);
803 /* The characteristics need to match and thus both need to have
804 the same string length, i.e. both len=*, or both len=4.
805 Having both len=<variable> is also possible, but difficult to
806 check at compile time. */
807 else if (ts
->type
== BT_CHARACTER
&& ts
->u
.cl
&& fts
->u
.cl
808 && (((ts
->u
.cl
->length
&& !fts
->u
.cl
->length
)
809 ||(!ts
->u
.cl
->length
&& fts
->u
.cl
->length
))
811 && ts
->u
.cl
->length
->expr_type
812 != fts
->u
.cl
->length
->expr_type
)
814 && ts
->u
.cl
->length
->expr_type
== EXPR_CONSTANT
815 && mpz_cmp (ts
->u
.cl
->length
->value
.integer
,
816 fts
->u
.cl
->length
->value
.integer
) != 0)))
817 gfc_notify_std (GFC_STD_GNU
, "Function %s at %L with "
818 "entries returning variables of different "
819 "string lengths", ns
->entries
->sym
->name
,
820 &ns
->entries
->sym
->declared_at
);
825 sym
= ns
->entries
->sym
->result
;
826 /* All result types the same. */
828 if (sym
->attr
.dimension
)
829 gfc_set_array_spec (proc
, gfc_copy_array_spec (sym
->as
), NULL
);
830 if (sym
->attr
.pointer
)
831 gfc_add_pointer (&proc
->attr
, NULL
);
835 /* Otherwise the result will be passed through a union by
837 proc
->attr
.mixed_entry_master
= 1;
838 for (el
= ns
->entries
; el
; el
= el
->next
)
840 sym
= el
->sym
->result
;
841 if (sym
->attr
.dimension
)
843 if (el
== ns
->entries
)
844 gfc_error ("FUNCTION result %s cannot be an array in "
845 "FUNCTION %s at %L", sym
->name
,
846 ns
->entries
->sym
->name
, &sym
->declared_at
);
848 gfc_error ("ENTRY result %s cannot be an array in "
849 "FUNCTION %s at %L", sym
->name
,
850 ns
->entries
->sym
->name
, &sym
->declared_at
);
852 else if (sym
->attr
.pointer
)
854 if (el
== ns
->entries
)
855 gfc_error ("FUNCTION result %s cannot be a POINTER in "
856 "FUNCTION %s at %L", sym
->name
,
857 ns
->entries
->sym
->name
, &sym
->declared_at
);
859 gfc_error ("ENTRY result %s cannot be a POINTER in "
860 "FUNCTION %s at %L", sym
->name
,
861 ns
->entries
->sym
->name
, &sym
->declared_at
);
866 if (ts
->type
== BT_UNKNOWN
)
867 ts
= gfc_get_default_type (sym
->name
, NULL
);
871 if (ts
->kind
== gfc_default_integer_kind
)
875 if (ts
->kind
== gfc_default_real_kind
876 || ts
->kind
== gfc_default_double_kind
)
880 if (ts
->kind
== gfc_default_complex_kind
)
884 if (ts
->kind
== gfc_default_logical_kind
)
888 /* We will issue error elsewhere. */
896 if (el
== ns
->entries
)
897 gfc_error ("FUNCTION result %s cannot be of type %s "
898 "in FUNCTION %s at %L", sym
->name
,
899 gfc_typename (ts
), ns
->entries
->sym
->name
,
902 gfc_error ("ENTRY result %s cannot be of type %s "
903 "in FUNCTION %s at %L", sym
->name
,
904 gfc_typename (ts
), ns
->entries
->sym
->name
,
911 proc
->attr
.access
= ACCESS_PRIVATE
;
912 proc
->attr
.entry_master
= 1;
914 /* Merge all the entry point arguments. */
915 for (el
= ns
->entries
; el
; el
= el
->next
)
916 merge_argument_lists (proc
, el
->sym
->formal
);
918 /* Check the master formal arguments for any that are not
919 present in all entry points. */
920 for (el
= ns
->entries
; el
; el
= el
->next
)
921 check_argument_lists (proc
, el
->sym
->formal
);
923 /* Use the master function for the function body. */
924 ns
->proc_name
= proc
;
926 /* Finalize the new symbols. */
927 gfc_commit_symbols ();
929 /* Restore the original namespace. */
930 gfc_current_ns
= old_ns
;
934 /* Resolve common variables. */
936 resolve_common_vars (gfc_common_head
*common_block
, bool named_common
)
938 gfc_symbol
*csym
= common_block
->head
;
941 for (; csym
; csym
= csym
->common_next
)
943 gsym
= gfc_find_gsymbol (gfc_gsym_root
, csym
->name
);
944 if (gsym
&& (gsym
->type
== GSYM_MODULE
|| gsym
->type
== GSYM_PROGRAM
))
945 gfc_error_now ("Global entity %qs at %L cannot appear in a "
946 "COMMON block at %L", gsym
->name
,
947 &gsym
->where
, &csym
->common_block
->where
);
949 /* gfc_add_in_common may have been called before, but the reported errors
950 have been ignored to continue parsing.
951 We do the checks again here. */
952 if (!csym
->attr
.use_assoc
)
954 gfc_add_in_common (&csym
->attr
, csym
->name
, &common_block
->where
);
955 gfc_notify_std (GFC_STD_F2018_OBS
, "COMMON block at %L",
956 &common_block
->where
);
959 if (csym
->value
|| csym
->attr
.data
)
961 if (!csym
->ns
->is_block_data
)
962 gfc_notify_std (GFC_STD_GNU
, "Variable %qs at %L is in COMMON "
963 "but only in BLOCK DATA initialization is "
964 "allowed", csym
->name
, &csym
->declared_at
);
965 else if (!named_common
)
966 gfc_notify_std (GFC_STD_GNU
, "Initialized variable %qs at %L is "
967 "in a blank COMMON but initialization is only "
968 "allowed in named common blocks", csym
->name
,
972 if (UNLIMITED_POLY (csym
))
973 gfc_error_now ("%qs in cannot appear in COMMON at %L "
974 "[F2008:C5100]", csym
->name
, &csym
->declared_at
);
976 if (csym
->ts
.type
!= BT_DERIVED
)
979 if (!(csym
->ts
.u
.derived
->attr
.sequence
980 || csym
->ts
.u
.derived
->attr
.is_bind_c
))
981 gfc_error_now ("Derived type variable %qs in COMMON at %L "
982 "has neither the SEQUENCE nor the BIND(C) "
983 "attribute", csym
->name
, &csym
->declared_at
);
984 if (csym
->ts
.u
.derived
->attr
.alloc_comp
)
985 gfc_error_now ("Derived type variable %qs in COMMON at %L "
986 "has an ultimate component that is "
987 "allocatable", csym
->name
, &csym
->declared_at
);
988 if (gfc_has_default_initializer (csym
->ts
.u
.derived
))
989 gfc_error_now ("Derived type variable %qs in COMMON at %L "
990 "may not have default initializer", csym
->name
,
993 if (csym
->attr
.flavor
== FL_UNKNOWN
&& !csym
->attr
.proc_pointer
)
994 gfc_add_flavor (&csym
->attr
, FL_VARIABLE
, csym
->name
, &csym
->declared_at
);
998 /* Resolve common blocks. */
1000 resolve_common_blocks (gfc_symtree
*common_root
)
1005 if (common_root
== NULL
)
1008 if (common_root
->left
)
1009 resolve_common_blocks (common_root
->left
);
1010 if (common_root
->right
)
1011 resolve_common_blocks (common_root
->right
);
1013 resolve_common_vars (common_root
->n
.common
, true);
1015 /* The common name is a global name - in Fortran 2003 also if it has a
1016 C binding name, since Fortran 2008 only the C binding name is a global
1018 if (!common_root
->n
.common
->binding_label
1019 || gfc_notification_std (GFC_STD_F2008
))
1021 gsym
= gfc_find_gsymbol (gfc_gsym_root
,
1022 common_root
->n
.common
->name
);
1024 if (gsym
&& gfc_notification_std (GFC_STD_F2008
)
1025 && gsym
->type
== GSYM_COMMON
1026 && ((common_root
->n
.common
->binding_label
1027 && (!gsym
->binding_label
1028 || strcmp (common_root
->n
.common
->binding_label
,
1029 gsym
->binding_label
) != 0))
1030 || (!common_root
->n
.common
->binding_label
1031 && gsym
->binding_label
)))
1033 gfc_error ("In Fortran 2003 COMMON %qs block at %L is a global "
1034 "identifier and must thus have the same binding name "
1035 "as the same-named COMMON block at %L: %s vs %s",
1036 common_root
->n
.common
->name
, &common_root
->n
.common
->where
,
1038 common_root
->n
.common
->binding_label
1039 ? common_root
->n
.common
->binding_label
: "(blank)",
1040 gsym
->binding_label
? gsym
->binding_label
: "(blank)");
1044 if (gsym
&& gsym
->type
!= GSYM_COMMON
1045 && !common_root
->n
.common
->binding_label
)
1047 gfc_error ("COMMON block %qs at %L uses the same global identifier "
1049 common_root
->n
.common
->name
, &common_root
->n
.common
->where
,
1053 if (gsym
&& gsym
->type
!= GSYM_COMMON
)
1055 gfc_error ("Fortran 2008: COMMON block %qs with binding label at "
1056 "%L sharing the identifier with global non-COMMON-block "
1057 "entity at %L", common_root
->n
.common
->name
,
1058 &common_root
->n
.common
->where
, &gsym
->where
);
1063 gsym
= gfc_get_gsymbol (common_root
->n
.common
->name
, false);
1064 gsym
->type
= GSYM_COMMON
;
1065 gsym
->where
= common_root
->n
.common
->where
;
1071 if (common_root
->n
.common
->binding_label
)
1073 gsym
= gfc_find_gsymbol (gfc_gsym_root
,
1074 common_root
->n
.common
->binding_label
);
1075 if (gsym
&& gsym
->type
!= GSYM_COMMON
)
1077 gfc_error ("COMMON block at %L with binding label %qs uses the same "
1078 "global identifier as entity at %L",
1079 &common_root
->n
.common
->where
,
1080 common_root
->n
.common
->binding_label
, &gsym
->where
);
1085 gsym
= gfc_get_gsymbol (common_root
->n
.common
->binding_label
, true);
1086 gsym
->type
= GSYM_COMMON
;
1087 gsym
->where
= common_root
->n
.common
->where
;
1093 gfc_find_symbol (common_root
->name
, gfc_current_ns
, 0, &sym
);
1097 if (sym
->attr
.flavor
== FL_PARAMETER
)
1098 gfc_error ("COMMON block %qs at %L is used as PARAMETER at %L",
1099 sym
->name
, &common_root
->n
.common
->where
, &sym
->declared_at
);
1101 if (sym
->attr
.external
)
1102 gfc_error ("COMMON block %qs at %L cannot have the EXTERNAL attribute",
1103 sym
->name
, &common_root
->n
.common
->where
);
1105 if (sym
->attr
.intrinsic
)
1106 gfc_error ("COMMON block %qs at %L is also an intrinsic procedure",
1107 sym
->name
, &common_root
->n
.common
->where
);
1108 else if (sym
->attr
.result
1109 || gfc_is_function_return_value (sym
, gfc_current_ns
))
1110 gfc_notify_std (GFC_STD_F2003
, "COMMON block %qs at %L "
1111 "that is also a function result", sym
->name
,
1112 &common_root
->n
.common
->where
);
1113 else if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.proc
!= PROC_INTERNAL
1114 && sym
->attr
.proc
!= PROC_ST_FUNCTION
)
1115 gfc_notify_std (GFC_STD_F2003
, "COMMON block %qs at %L "
1116 "that is also a global procedure", sym
->name
,
1117 &common_root
->n
.common
->where
);
1121 /* Resolve contained function types. Because contained functions can call one
1122 another, they have to be worked out before any of the contained procedures
1125 The good news is that if a function doesn't already have a type, the only
1126 way it can get one is through an IMPLICIT type or a RESULT variable, because
1127 by definition contained functions are contained namespace they're contained
1128 in, not in a sibling or parent namespace. */
1131 resolve_contained_functions (gfc_namespace
*ns
)
1133 gfc_namespace
*child
;
1136 resolve_formal_arglists (ns
);
1138 for (child
= ns
->contained
; child
; child
= child
->sibling
)
1140 /* Resolve alternate entry points first. */
1141 resolve_entries (child
);
1143 /* Then check function return types. */
1144 resolve_contained_fntype (child
->proc_name
, child
);
1145 for (el
= child
->entries
; el
; el
= el
->next
)
1146 resolve_contained_fntype (el
->sym
, child
);
1152 /* A Parameterized Derived Type constructor must contain values for
1153 the PDT KIND parameters or they must have a default initializer.
1154 Go through the constructor picking out the KIND expressions,
1155 storing them in 'param_list' and then call gfc_get_pdt_instance
1156 to obtain the PDT instance. */
1158 static gfc_actual_arglist
*param_list
, *param_tail
, *param
;
1161 get_pdt_spec_expr (gfc_component
*c
, gfc_expr
*expr
)
1163 param
= gfc_get_actual_arglist ();
1165 param_list
= param_tail
= param
;
1168 param_tail
->next
= param
;
1169 param_tail
= param_tail
->next
;
1172 param_tail
->name
= c
->name
;
1174 param_tail
->expr
= gfc_copy_expr (expr
);
1175 else if (c
->initializer
)
1176 param_tail
->expr
= gfc_copy_expr (c
->initializer
);
1179 param_tail
->spec_type
= SPEC_ASSUMED
;
1180 if (c
->attr
.pdt_kind
)
1182 gfc_error ("The KIND parameter %qs in the PDT constructor "
1183 "at %C has no value", param
->name
);
1192 get_pdt_constructor (gfc_expr
*expr
, gfc_constructor
**constr
,
1193 gfc_symbol
*derived
)
1195 gfc_constructor
*cons
= NULL
;
1196 gfc_component
*comp
;
1199 if (expr
&& expr
->expr_type
== EXPR_STRUCTURE
)
1200 cons
= gfc_constructor_first (expr
->value
.constructor
);
1205 comp
= derived
->components
;
1207 for (; comp
&& cons
; comp
= comp
->next
, cons
= gfc_constructor_next (cons
))
1210 && cons
->expr
->expr_type
== EXPR_STRUCTURE
1211 && comp
->ts
.type
== BT_DERIVED
)
1213 t
= get_pdt_constructor (cons
->expr
, NULL
, comp
->ts
.u
.derived
);
1217 else if (comp
->ts
.type
== BT_DERIVED
)
1219 t
= get_pdt_constructor (NULL
, &cons
, comp
->ts
.u
.derived
);
1223 else if ((comp
->attr
.pdt_kind
|| comp
->attr
.pdt_len
)
1224 && derived
->attr
.pdt_template
)
1226 t
= get_pdt_spec_expr (comp
, cons
->expr
);
1235 static bool resolve_fl_derived0 (gfc_symbol
*sym
);
1236 static bool resolve_fl_struct (gfc_symbol
*sym
);
1239 /* Resolve all of the elements of a structure constructor and make sure that
1240 the types are correct. The 'init' flag indicates that the given
1241 constructor is an initializer. */
1244 resolve_structure_cons (gfc_expr
*expr
, int init
)
1246 gfc_constructor
*cons
;
1247 gfc_component
*comp
;
1253 if (expr
->ts
.type
== BT_DERIVED
|| expr
->ts
.type
== BT_UNION
)
1255 if (expr
->ts
.u
.derived
->attr
.flavor
== FL_DERIVED
)
1256 resolve_fl_derived0 (expr
->ts
.u
.derived
);
1258 resolve_fl_struct (expr
->ts
.u
.derived
);
1260 /* If this is a Parameterized Derived Type template, find the
1261 instance corresponding to the PDT kind parameters. */
1262 if (expr
->ts
.u
.derived
->attr
.pdt_template
)
1265 t
= get_pdt_constructor (expr
, NULL
, expr
->ts
.u
.derived
);
1268 gfc_get_pdt_instance (param_list
, &expr
->ts
.u
.derived
, NULL
);
1270 expr
->param_list
= gfc_copy_actual_arglist (param_list
);
1273 gfc_free_actual_arglist (param_list
);
1275 if (!expr
->ts
.u
.derived
->attr
.pdt_type
)
1280 cons
= gfc_constructor_first (expr
->value
.constructor
);
1282 /* A constructor may have references if it is the result of substituting a
1283 parameter variable. In this case we just pull out the component we
1286 comp
= expr
->ref
->u
.c
.sym
->components
;
1288 comp
= expr
->ts
.u
.derived
->components
;
1290 for (; comp
&& cons
; comp
= comp
->next
, cons
= gfc_constructor_next (cons
))
1297 /* Unions use an EXPR_NULL contrived expression to tell the translation
1298 phase to generate an initializer of the appropriate length.
1300 if (cons
->expr
->ts
.type
== BT_UNION
&& cons
->expr
->expr_type
== EXPR_NULL
)
1303 if (!gfc_resolve_expr (cons
->expr
))
1309 rank
= comp
->as
? comp
->as
->rank
: 0;
1310 if (comp
->ts
.type
== BT_CLASS
1311 && !comp
->ts
.u
.derived
->attr
.unlimited_polymorphic
1312 && CLASS_DATA (comp
)->as
)
1313 rank
= CLASS_DATA (comp
)->as
->rank
;
1315 if (cons
->expr
->expr_type
!= EXPR_NULL
&& rank
!= cons
->expr
->rank
1316 && (comp
->attr
.allocatable
|| cons
->expr
->rank
))
1318 gfc_error ("The rank of the element in the structure "
1319 "constructor at %L does not match that of the "
1320 "component (%d/%d)", &cons
->expr
->where
,
1321 cons
->expr
->rank
, rank
);
1325 /* If we don't have the right type, try to convert it. */
1327 if (!comp
->attr
.proc_pointer
&&
1328 !gfc_compare_types (&cons
->expr
->ts
, &comp
->ts
))
1330 if (strcmp (comp
->name
, "_extends") == 0)
1332 /* Can afford to be brutal with the _extends initializer.
1333 The derived type can get lost because it is PRIVATE
1334 but it is not usage constrained by the standard. */
1335 cons
->expr
->ts
= comp
->ts
;
1337 else if (comp
->attr
.pointer
&& cons
->expr
->ts
.type
!= BT_UNKNOWN
)
1339 gfc_error ("The element in the structure constructor at %L, "
1340 "for pointer component %qs, is %s but should be %s",
1341 &cons
->expr
->where
, comp
->name
,
1342 gfc_basic_typename (cons
->expr
->ts
.type
),
1343 gfc_basic_typename (comp
->ts
.type
));
1348 bool t2
= gfc_convert_type (cons
->expr
, &comp
->ts
, 1);
1354 /* For strings, the length of the constructor should be the same as
1355 the one of the structure, ensure this if the lengths are known at
1356 compile time and when we are dealing with PARAMETER or structure
1358 if (cons
->expr
->ts
.type
== BT_CHARACTER
&& comp
->ts
.u
.cl
1359 && comp
->ts
.u
.cl
->length
1360 && comp
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1361 && cons
->expr
->ts
.u
.cl
&& cons
->expr
->ts
.u
.cl
->length
1362 && cons
->expr
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
1363 && cons
->expr
->rank
!= 0
1364 && mpz_cmp (cons
->expr
->ts
.u
.cl
->length
->value
.integer
,
1365 comp
->ts
.u
.cl
->length
->value
.integer
) != 0)
1367 if (cons
->expr
->expr_type
== EXPR_VARIABLE
1368 && cons
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
)
1370 /* Wrap the parameter in an array constructor (EXPR_ARRAY)
1371 to make use of the gfc_resolve_character_array_constructor
1372 machinery. The expression is later simplified away to
1373 an array of string literals. */
1374 gfc_expr
*para
= cons
->expr
;
1375 cons
->expr
= gfc_get_expr ();
1376 cons
->expr
->ts
= para
->ts
;
1377 cons
->expr
->where
= para
->where
;
1378 cons
->expr
->expr_type
= EXPR_ARRAY
;
1379 cons
->expr
->rank
= para
->rank
;
1380 cons
->expr
->shape
= gfc_copy_shape (para
->shape
, para
->rank
);
1381 gfc_constructor_append_expr (&cons
->expr
->value
.constructor
,
1382 para
, &cons
->expr
->where
);
1385 if (cons
->expr
->expr_type
== EXPR_ARRAY
)
1387 /* Rely on the cleanup of the namespace to deal correctly with
1388 the old charlen. (There was a block here that attempted to
1389 remove the charlen but broke the chain in so doing.) */
1390 cons
->expr
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
1391 cons
->expr
->ts
.u
.cl
->length_from_typespec
= true;
1392 cons
->expr
->ts
.u
.cl
->length
= gfc_copy_expr (comp
->ts
.u
.cl
->length
);
1393 gfc_resolve_character_array_constructor (cons
->expr
);
1397 if (cons
->expr
->expr_type
== EXPR_NULL
1398 && !(comp
->attr
.pointer
|| comp
->attr
.allocatable
1399 || comp
->attr
.proc_pointer
|| comp
->ts
.f90_type
== BT_VOID
1400 || (comp
->ts
.type
== BT_CLASS
1401 && (CLASS_DATA (comp
)->attr
.class_pointer
1402 || CLASS_DATA (comp
)->attr
.allocatable
))))
1405 gfc_error ("The NULL in the structure constructor at %L is "
1406 "being applied to component %qs, which is neither "
1407 "a POINTER nor ALLOCATABLE", &cons
->expr
->where
,
1411 if (comp
->attr
.proc_pointer
&& comp
->ts
.interface
)
1413 /* Check procedure pointer interface. */
1414 gfc_symbol
*s2
= NULL
;
1419 c2
= gfc_get_proc_ptr_comp (cons
->expr
);
1422 s2
= c2
->ts
.interface
;
1425 else if (cons
->expr
->expr_type
== EXPR_FUNCTION
)
1427 s2
= cons
->expr
->symtree
->n
.sym
->result
;
1428 name
= cons
->expr
->symtree
->n
.sym
->result
->name
;
1430 else if (cons
->expr
->expr_type
!= EXPR_NULL
)
1432 s2
= cons
->expr
->symtree
->n
.sym
;
1433 name
= cons
->expr
->symtree
->n
.sym
->name
;
1436 if (s2
&& !gfc_compare_interfaces (comp
->ts
.interface
, s2
, name
, 0, 1,
1437 err
, sizeof (err
), NULL
, NULL
))
1439 gfc_error_opt (0, "Interface mismatch for procedure-pointer "
1440 "component %qs in structure constructor at %L:"
1441 " %s", comp
->name
, &cons
->expr
->where
, err
);
1446 if (!comp
->attr
.pointer
|| comp
->attr
.proc_pointer
1447 || cons
->expr
->expr_type
== EXPR_NULL
)
1450 a
= gfc_expr_attr (cons
->expr
);
1452 if (!a
.pointer
&& !a
.target
)
1455 gfc_error ("The element in the structure constructor at %L, "
1456 "for pointer component %qs should be a POINTER or "
1457 "a TARGET", &cons
->expr
->where
, comp
->name
);
1462 /* F08:C461. Additional checks for pointer initialization. */
1466 gfc_error ("Pointer initialization target at %L "
1467 "must not be ALLOCATABLE", &cons
->expr
->where
);
1472 gfc_error ("Pointer initialization target at %L "
1473 "must have the SAVE attribute", &cons
->expr
->where
);
1477 /* F2003, C1272 (3). */
1478 bool impure
= cons
->expr
->expr_type
== EXPR_VARIABLE
1479 && (gfc_impure_variable (cons
->expr
->symtree
->n
.sym
)
1480 || gfc_is_coindexed (cons
->expr
));
1481 if (impure
&& gfc_pure (NULL
))
1484 gfc_error ("Invalid expression in the structure constructor for "
1485 "pointer component %qs at %L in PURE procedure",
1486 comp
->name
, &cons
->expr
->where
);
1490 gfc_unset_implicit_pure (NULL
);
1497 /****************** Expression name resolution ******************/
1499 /* Returns 0 if a symbol was not declared with a type or
1500 attribute declaration statement, nonzero otherwise. */
1503 was_declared (gfc_symbol
*sym
)
1509 if (!a
.implicit_type
&& sym
->ts
.type
!= BT_UNKNOWN
)
1512 if (a
.allocatable
|| a
.dimension
|| a
.dummy
|| a
.external
|| a
.intrinsic
1513 || a
.optional
|| a
.pointer
|| a
.save
|| a
.target
|| a
.volatile_
1514 || a
.value
|| a
.access
!= ACCESS_UNKNOWN
|| a
.intent
!= INTENT_UNKNOWN
1515 || a
.asynchronous
|| a
.codimension
)
1522 /* Determine if a symbol is generic or not. */
1525 generic_sym (gfc_symbol
*sym
)
1529 if (sym
->attr
.generic
||
1530 (sym
->attr
.intrinsic
&& gfc_generic_intrinsic (sym
->name
)))
1533 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1536 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1543 return generic_sym (s
);
1550 /* Determine if a symbol is specific or not. */
1553 specific_sym (gfc_symbol
*sym
)
1557 if (sym
->attr
.if_source
== IFSRC_IFBODY
1558 || sym
->attr
.proc
== PROC_MODULE
1559 || sym
->attr
.proc
== PROC_INTERNAL
1560 || sym
->attr
.proc
== PROC_ST_FUNCTION
1561 || (sym
->attr
.intrinsic
&& gfc_specific_intrinsic (sym
->name
))
1562 || sym
->attr
.external
)
1565 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1568 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
1570 return (s
== NULL
) ? 0 : specific_sym (s
);
1574 /* Figure out if the procedure is specific, generic or unknown. */
1577 { PTYPE_GENERIC
= 1, PTYPE_SPECIFIC
, PTYPE_UNKNOWN
};
1580 procedure_kind (gfc_symbol
*sym
)
1582 if (generic_sym (sym
))
1583 return PTYPE_GENERIC
;
1585 if (specific_sym (sym
))
1586 return PTYPE_SPECIFIC
;
1588 return PTYPE_UNKNOWN
;
1591 /* Check references to assumed size arrays. The flag need_full_assumed_size
1592 is nonzero when matching actual arguments. */
1594 static int need_full_assumed_size
= 0;
1597 check_assumed_size_reference (gfc_symbol
*sym
, gfc_expr
*e
)
1599 if (need_full_assumed_size
|| !(sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
))
1602 /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong.
1603 What should it be? */
1604 if (e
->ref
&& (e
->ref
->u
.ar
.end
[e
->ref
->u
.ar
.as
->rank
- 1] == NULL
)
1605 && (e
->ref
->u
.ar
.as
->type
== AS_ASSUMED_SIZE
)
1606 && (e
->ref
->u
.ar
.type
== AR_FULL
))
1608 gfc_error ("The upper bound in the last dimension must "
1609 "appear in the reference to the assumed size "
1610 "array %qs at %L", sym
->name
, &e
->where
);
1617 /* Look for bad assumed size array references in argument expressions
1618 of elemental and array valued intrinsic procedures. Since this is
1619 called from procedure resolution functions, it only recurses at
1623 resolve_assumed_size_actual (gfc_expr
*e
)
1628 switch (e
->expr_type
)
1631 if (e
->symtree
&& check_assumed_size_reference (e
->symtree
->n
.sym
, e
))
1636 if (resolve_assumed_size_actual (e
->value
.op
.op1
)
1637 || resolve_assumed_size_actual (e
->value
.op
.op2
))
1648 /* Check a generic procedure, passed as an actual argument, to see if
1649 there is a matching specific name. If none, it is an error, and if
1650 more than one, the reference is ambiguous. */
1652 count_specific_procs (gfc_expr
*e
)
1659 sym
= e
->symtree
->n
.sym
;
1661 for (p
= sym
->generic
; p
; p
= p
->next
)
1662 if (strcmp (sym
->name
, p
->sym
->name
) == 0)
1664 e
->symtree
= gfc_find_symtree (p
->sym
->ns
->sym_root
,
1670 gfc_error ("%qs at %L is ambiguous", e
->symtree
->n
.sym
->name
,
1674 gfc_error ("GENERIC procedure %qs is not allowed as an actual "
1675 "argument at %L", sym
->name
, &e
->where
);
1681 /* See if a call to sym could possibly be a not allowed RECURSION because of
1682 a missing RECURSIVE declaration. This means that either sym is the current
1683 context itself, or sym is the parent of a contained procedure calling its
1684 non-RECURSIVE containing procedure.
1685 This also works if sym is an ENTRY. */
1688 is_illegal_recursion (gfc_symbol
* sym
, gfc_namespace
* context
)
1690 gfc_symbol
* proc_sym
;
1691 gfc_symbol
* context_proc
;
1692 gfc_namespace
* real_context
;
1694 if (sym
->attr
.flavor
== FL_PROGRAM
1695 || gfc_fl_struct (sym
->attr
.flavor
))
1698 /* If we've got an ENTRY, find real procedure. */
1699 if (sym
->attr
.entry
&& sym
->ns
->entries
)
1700 proc_sym
= sym
->ns
->entries
->sym
;
1704 /* If sym is RECURSIVE, all is well of course. */
1705 if (proc_sym
->attr
.recursive
|| flag_recursive
)
1708 /* Find the context procedure's "real" symbol if it has entries.
1709 We look for a procedure symbol, so recurse on the parents if we don't
1710 find one (like in case of a BLOCK construct). */
1711 for (real_context
= context
; ; real_context
= real_context
->parent
)
1713 /* We should find something, eventually! */
1714 gcc_assert (real_context
);
1716 context_proc
= (real_context
->entries
? real_context
->entries
->sym
1717 : real_context
->proc_name
);
1719 /* In some special cases, there may not be a proc_name, like for this
1721 real(bad_kind()) function foo () ...
1722 when checking the call to bad_kind ().
1723 In these cases, we simply return here and assume that the
1728 if (context_proc
->attr
.flavor
!= FL_LABEL
)
1732 /* A call from sym's body to itself is recursion, of course. */
1733 if (context_proc
== proc_sym
)
1736 /* The same is true if context is a contained procedure and sym the
1738 if (context_proc
->attr
.contained
)
1740 gfc_symbol
* parent_proc
;
1742 gcc_assert (context
->parent
);
1743 parent_proc
= (context
->parent
->entries
? context
->parent
->entries
->sym
1744 : context
->parent
->proc_name
);
1746 if (parent_proc
== proc_sym
)
1754 /* Resolve an intrinsic procedure: Set its function/subroutine attribute,
1755 its typespec and formal argument list. */
1758 gfc_resolve_intrinsic (gfc_symbol
*sym
, locus
*loc
)
1760 gfc_intrinsic_sym
* isym
= NULL
;
1763 if (sym
->resolve_symbol_called
>= 2)
1766 sym
->resolve_symbol_called
= 2;
1768 /* Already resolved. */
1769 if (sym
->from_intmod
&& sym
->ts
.type
!= BT_UNKNOWN
)
1772 /* We already know this one is an intrinsic, so we don't call
1773 gfc_is_intrinsic for full checking but rather use gfc_find_function and
1774 gfc_find_subroutine directly to check whether it is a function or
1777 if (sym
->intmod_sym_id
&& sym
->attr
.subroutine
)
1779 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1780 isym
= gfc_intrinsic_subroutine_by_id (id
);
1782 else if (sym
->intmod_sym_id
)
1784 gfc_isym_id id
= gfc_isym_id_by_intmod_sym (sym
);
1785 isym
= gfc_intrinsic_function_by_id (id
);
1787 else if (!sym
->attr
.subroutine
)
1788 isym
= gfc_find_function (sym
->name
);
1790 if (isym
&& !sym
->attr
.subroutine
)
1792 if (sym
->ts
.type
!= BT_UNKNOWN
&& warn_surprising
1793 && !sym
->attr
.implicit_type
)
1794 gfc_warning (OPT_Wsurprising
,
1795 "Type specified for intrinsic function %qs at %L is"
1796 " ignored", sym
->name
, &sym
->declared_at
);
1798 if (!sym
->attr
.function
&&
1799 !gfc_add_function(&sym
->attr
, sym
->name
, loc
))
1804 else if (isym
|| (isym
= gfc_find_subroutine (sym
->name
)))
1806 if (sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.implicit_type
)
1808 gfc_error ("Intrinsic subroutine %qs at %L shall not have a type"
1809 " specifier", sym
->name
, &sym
->declared_at
);
1813 if (!sym
->attr
.subroutine
&&
1814 !gfc_add_subroutine(&sym
->attr
, sym
->name
, loc
))
1819 gfc_error ("%qs declared INTRINSIC at %L does not exist", sym
->name
,
1824 gfc_copy_formal_args_intr (sym
, isym
, NULL
);
1826 sym
->attr
.pure
= isym
->pure
;
1827 sym
->attr
.elemental
= isym
->elemental
;
1829 /* Check it is actually available in the standard settings. */
1830 if (!gfc_check_intrinsic_standard (isym
, &symstd
, false, sym
->declared_at
))
1832 gfc_error ("The intrinsic %qs declared INTRINSIC at %L is not "
1833 "available in the current standard settings but %s. Use "
1834 "an appropriate %<-std=*%> option or enable "
1835 "%<-fall-intrinsics%> in order to use it.",
1836 sym
->name
, &sym
->declared_at
, symstd
);
1844 /* Resolve a procedure expression, like passing it to a called procedure or as
1845 RHS for a procedure pointer assignment. */
1848 resolve_procedure_expression (gfc_expr
* expr
)
1852 if (expr
->expr_type
!= EXPR_VARIABLE
)
1854 gcc_assert (expr
->symtree
);
1856 sym
= expr
->symtree
->n
.sym
;
1858 if (sym
->attr
.intrinsic
)
1859 gfc_resolve_intrinsic (sym
, &expr
->where
);
1861 if (sym
->attr
.flavor
!= FL_PROCEDURE
1862 || (sym
->attr
.function
&& sym
->result
== sym
))
1865 /* A non-RECURSIVE procedure that is used as procedure expression within its
1866 own body is in danger of being called recursively. */
1867 if (is_illegal_recursion (sym
, gfc_current_ns
))
1868 gfc_warning (0, "Non-RECURSIVE procedure %qs at %L is possibly calling"
1869 " itself recursively. Declare it RECURSIVE or use"
1870 " %<-frecursive%>", sym
->name
, &expr
->where
);
1876 /* Check that name is not a derived type. */
1879 is_dt_name (const char *name
)
1881 gfc_symbol
*dt_list
, *dt_first
;
1883 dt_list
= dt_first
= gfc_derived_types
;
1884 for (; dt_list
; dt_list
= dt_list
->dt_next
)
1886 if (strcmp(dt_list
->name
, name
) == 0)
1888 if (dt_first
== dt_list
->dt_next
)
1895 /* Resolve an actual argument list. Most of the time, this is just
1896 resolving the expressions in the list.
1897 The exception is that we sometimes have to decide whether arguments
1898 that look like procedure arguments are really simple variable
1902 resolve_actual_arglist (gfc_actual_arglist
*arg
, procedure_type ptype
,
1903 bool no_formal_args
)
1906 gfc_symtree
*parent_st
;
1908 gfc_component
*comp
;
1909 int save_need_full_assumed_size
;
1910 bool return_value
= false;
1911 bool actual_arg_sav
= actual_arg
, first_actual_arg_sav
= first_actual_arg
;
1914 first_actual_arg
= true;
1916 for (; arg
; arg
= arg
->next
)
1921 /* Check the label is a valid branching target. */
1924 if (arg
->label
->defined
== ST_LABEL_UNKNOWN
)
1926 gfc_error ("Label %d referenced at %L is never defined",
1927 arg
->label
->value
, &arg
->label
->where
);
1931 first_actual_arg
= false;
1935 if (e
->expr_type
== EXPR_VARIABLE
1936 && e
->symtree
->n
.sym
->attr
.generic
1938 && count_specific_procs (e
) != 1)
1941 if (e
->ts
.type
!= BT_PROCEDURE
)
1943 save_need_full_assumed_size
= need_full_assumed_size
;
1944 if (e
->expr_type
!= EXPR_VARIABLE
)
1945 need_full_assumed_size
= 0;
1946 if (!gfc_resolve_expr (e
))
1948 need_full_assumed_size
= save_need_full_assumed_size
;
1952 /* See if the expression node should really be a variable reference. */
1954 sym
= e
->symtree
->n
.sym
;
1956 if (sym
->attr
.flavor
== FL_PROCEDURE
&& is_dt_name (sym
->name
))
1958 gfc_error ("Derived type %qs is used as an actual "
1959 "argument at %L", sym
->name
, &e
->where
);
1963 if (sym
->attr
.flavor
== FL_PROCEDURE
1964 || sym
->attr
.intrinsic
1965 || sym
->attr
.external
)
1969 /* If a procedure is not already determined to be something else
1970 check if it is intrinsic. */
1971 if (gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, e
->where
))
1972 sym
->attr
.intrinsic
= 1;
1974 if (sym
->attr
.proc
== PROC_ST_FUNCTION
)
1976 gfc_error ("Statement function %qs at %L is not allowed as an "
1977 "actual argument", sym
->name
, &e
->where
);
1980 actual_ok
= gfc_intrinsic_actual_ok (sym
->name
,
1981 sym
->attr
.subroutine
);
1982 if (sym
->attr
.intrinsic
&& actual_ok
== 0)
1984 gfc_error ("Intrinsic %qs at %L is not allowed as an "
1985 "actual argument", sym
->name
, &e
->where
);
1988 if (sym
->attr
.contained
&& !sym
->attr
.use_assoc
1989 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
1991 if (!gfc_notify_std (GFC_STD_F2008
, "Internal procedure %qs is"
1992 " used as actual argument at %L",
1993 sym
->name
, &e
->where
))
1997 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
)
1999 gfc_error ("ELEMENTAL non-INTRINSIC procedure %qs is not "
2000 "allowed as an actual argument at %L", sym
->name
,
2004 /* Check if a generic interface has a specific procedure
2005 with the same name before emitting an error. */
2006 if (sym
->attr
.generic
&& count_specific_procs (e
) != 1)
2009 /* Just in case a specific was found for the expression. */
2010 sym
= e
->symtree
->n
.sym
;
2012 /* If the symbol is the function that names the current (or
2013 parent) scope, then we really have a variable reference. */
2015 if (gfc_is_function_return_value (sym
, sym
->ns
))
2018 /* If all else fails, see if we have a specific intrinsic. */
2019 if (sym
->ts
.type
== BT_UNKNOWN
&& sym
->attr
.intrinsic
)
2021 gfc_intrinsic_sym
*isym
;
2023 isym
= gfc_find_function (sym
->name
);
2024 if (isym
== NULL
|| !isym
->specific
)
2026 gfc_error ("Unable to find a specific INTRINSIC procedure "
2027 "for the reference %qs at %L", sym
->name
,
2032 sym
->attr
.intrinsic
= 1;
2033 sym
->attr
.function
= 1;
2036 if (!gfc_resolve_expr (e
))
2041 /* See if the name is a module procedure in a parent unit. */
2043 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
2046 if (gfc_find_sym_tree (sym
->name
, sym
->ns
->parent
, 1, &parent_st
))
2048 gfc_error ("Symbol %qs at %L is ambiguous", sym
->name
, &e
->where
);
2052 if (parent_st
== NULL
)
2055 sym
= parent_st
->n
.sym
;
2056 e
->symtree
= parent_st
; /* Point to the right thing. */
2058 if (sym
->attr
.flavor
== FL_PROCEDURE
2059 || sym
->attr
.intrinsic
2060 || sym
->attr
.external
)
2062 if (!gfc_resolve_expr (e
))
2068 e
->expr_type
= EXPR_VARIABLE
;
2070 if ((sym
->as
!= NULL
&& sym
->ts
.type
!= BT_CLASS
)
2071 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
2072 && CLASS_DATA (sym
)->as
))
2074 e
->rank
= sym
->ts
.type
== BT_CLASS
2075 ? CLASS_DATA (sym
)->as
->rank
: sym
->as
->rank
;
2076 e
->ref
= gfc_get_ref ();
2077 e
->ref
->type
= REF_ARRAY
;
2078 e
->ref
->u
.ar
.type
= AR_FULL
;
2079 e
->ref
->u
.ar
.as
= sym
->ts
.type
== BT_CLASS
2080 ? CLASS_DATA (sym
)->as
: sym
->as
;
2083 /* Expressions are assigned a default ts.type of BT_PROCEDURE in
2084 primary.c (match_actual_arg). If above code determines that it
2085 is a variable instead, it needs to be resolved as it was not
2086 done at the beginning of this function. */
2087 save_need_full_assumed_size
= need_full_assumed_size
;
2088 if (e
->expr_type
!= EXPR_VARIABLE
)
2089 need_full_assumed_size
= 0;
2090 if (!gfc_resolve_expr (e
))
2092 need_full_assumed_size
= save_need_full_assumed_size
;
2095 /* Check argument list functions %VAL, %LOC and %REF. There is
2096 nothing to do for %REF. */
2097 if (arg
->name
&& arg
->name
[0] == '%')
2099 if (strcmp ("%VAL", arg
->name
) == 0)
2101 if (e
->ts
.type
== BT_CHARACTER
|| e
->ts
.type
== BT_DERIVED
)
2103 gfc_error ("By-value argument at %L is not of numeric "
2110 gfc_error ("By-value argument at %L cannot be an array or "
2111 "an array section", &e
->where
);
2115 /* Intrinsics are still PROC_UNKNOWN here. However,
2116 since same file external procedures are not resolvable
2117 in gfortran, it is a good deal easier to leave them to
2119 if (ptype
!= PROC_UNKNOWN
2120 && ptype
!= PROC_DUMMY
2121 && ptype
!= PROC_EXTERNAL
2122 && ptype
!= PROC_MODULE
)
2124 gfc_error ("By-value argument at %L is not allowed "
2125 "in this context", &e
->where
);
2130 /* Statement functions have already been excluded above. */
2131 else if (strcmp ("%LOC", arg
->name
) == 0
2132 && e
->ts
.type
== BT_PROCEDURE
)
2134 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_INTERNAL
)
2136 gfc_error ("Passing internal procedure at %L by location "
2137 "not allowed", &e
->where
);
2143 comp
= gfc_get_proc_ptr_comp(e
);
2144 if (e
->expr_type
== EXPR_VARIABLE
2145 && comp
&& comp
->attr
.elemental
)
2147 gfc_error ("ELEMENTAL procedure pointer component %qs is not "
2148 "allowed as an actual argument at %L", comp
->name
,
2152 /* Fortran 2008, C1237. */
2153 if (e
->expr_type
== EXPR_VARIABLE
&& gfc_is_coindexed (e
)
2154 && gfc_has_ultimate_pointer (e
))
2156 gfc_error ("Coindexed actual argument at %L with ultimate pointer "
2157 "component", &e
->where
);
2161 first_actual_arg
= false;
2164 return_value
= true;
2167 actual_arg
= actual_arg_sav
;
2168 first_actual_arg
= first_actual_arg_sav
;
2170 return return_value
;
2174 /* Do the checks of the actual argument list that are specific to elemental
2175 procedures. If called with c == NULL, we have a function, otherwise if
2176 expr == NULL, we have a subroutine. */
2179 resolve_elemental_actual (gfc_expr
*expr
, gfc_code
*c
)
2181 gfc_actual_arglist
*arg0
;
2182 gfc_actual_arglist
*arg
;
2183 gfc_symbol
*esym
= NULL
;
2184 gfc_intrinsic_sym
*isym
= NULL
;
2186 gfc_intrinsic_arg
*iformal
= NULL
;
2187 gfc_formal_arglist
*eformal
= NULL
;
2188 bool formal_optional
= false;
2189 bool set_by_optional
= false;
2193 /* Is this an elemental procedure? */
2194 if (expr
&& expr
->value
.function
.actual
!= NULL
)
2196 if (expr
->value
.function
.esym
!= NULL
2197 && expr
->value
.function
.esym
->attr
.elemental
)
2199 arg0
= expr
->value
.function
.actual
;
2200 esym
= expr
->value
.function
.esym
;
2202 else if (expr
->value
.function
.isym
!= NULL
2203 && expr
->value
.function
.isym
->elemental
)
2205 arg0
= expr
->value
.function
.actual
;
2206 isym
= expr
->value
.function
.isym
;
2211 else if (c
&& c
->ext
.actual
!= NULL
)
2213 arg0
= c
->ext
.actual
;
2215 if (c
->resolved_sym
)
2216 esym
= c
->resolved_sym
;
2218 esym
= c
->symtree
->n
.sym
;
2221 if (!esym
->attr
.elemental
)
2227 /* The rank of an elemental is the rank of its array argument(s). */
2228 for (arg
= arg0
; arg
; arg
= arg
->next
)
2230 if (arg
->expr
!= NULL
&& arg
->expr
->rank
!= 0)
2232 rank
= arg
->expr
->rank
;
2233 if (arg
->expr
->expr_type
== EXPR_VARIABLE
2234 && arg
->expr
->symtree
->n
.sym
->attr
.optional
)
2235 set_by_optional
= true;
2237 /* Function specific; set the result rank and shape. */
2241 if (!expr
->shape
&& arg
->expr
->shape
)
2243 expr
->shape
= gfc_get_shape (rank
);
2244 for (i
= 0; i
< rank
; i
++)
2245 mpz_init_set (expr
->shape
[i
], arg
->expr
->shape
[i
]);
2252 /* If it is an array, it shall not be supplied as an actual argument
2253 to an elemental procedure unless an array of the same rank is supplied
2254 as an actual argument corresponding to a nonoptional dummy argument of
2255 that elemental procedure(12.4.1.5). */
2256 formal_optional
= false;
2258 iformal
= isym
->formal
;
2260 eformal
= esym
->formal
;
2262 for (arg
= arg0
; arg
; arg
= arg
->next
)
2266 if (eformal
->sym
&& eformal
->sym
->attr
.optional
)
2267 formal_optional
= true;
2268 eformal
= eformal
->next
;
2270 else if (isym
&& iformal
)
2272 if (iformal
->optional
)
2273 formal_optional
= true;
2274 iformal
= iformal
->next
;
2277 formal_optional
= true;
2279 if (pedantic
&& arg
->expr
!= NULL
2280 && arg
->expr
->expr_type
== EXPR_VARIABLE
2281 && arg
->expr
->symtree
->n
.sym
->attr
.optional
2284 && (set_by_optional
|| arg
->expr
->rank
!= rank
)
2285 && !(isym
&& isym
->id
== GFC_ISYM_CONVERSION
))
2288 gfc_actual_arglist
*a
;
2290 /* Scan the argument list for a non-optional argument with the
2291 same rank as arg. */
2292 for (a
= arg0
; a
; a
= a
->next
)
2294 && a
->expr
->rank
== arg
->expr
->rank
2295 && !a
->expr
->symtree
->n
.sym
->attr
.optional
)
2302 gfc_warning (OPT_Wpedantic
,
2303 "%qs at %L is an array and OPTIONAL; If it is not "
2304 "present, then it cannot be the actual argument of "
2305 "an ELEMENTAL procedure unless there is a non-optional"
2306 " argument with the same rank "
2307 "(Fortran 2018, 15.5.2.12)",
2308 arg
->expr
->symtree
->n
.sym
->name
, &arg
->expr
->where
);
2312 for (arg
= arg0
; arg
; arg
= arg
->next
)
2314 if (arg
->expr
== NULL
|| arg
->expr
->rank
== 0)
2317 /* Being elemental, the last upper bound of an assumed size array
2318 argument must be present. */
2319 if (resolve_assumed_size_actual (arg
->expr
))
2322 /* Elemental procedure's array actual arguments must conform. */
2325 if (!gfc_check_conformance (arg
->expr
, e
, _("elemental procedure")))
2332 /* INTENT(OUT) is only allowed for subroutines; if any actual argument
2333 is an array, the intent inout/out variable needs to be also an array. */
2334 if (rank
> 0 && esym
&& expr
== NULL
)
2335 for (eformal
= esym
->formal
, arg
= arg0
; arg
&& eformal
;
2336 arg
= arg
->next
, eformal
= eformal
->next
)
2337 if ((eformal
->sym
->attr
.intent
== INTENT_OUT
2338 || eformal
->sym
->attr
.intent
== INTENT_INOUT
)
2339 && arg
->expr
&& arg
->expr
->rank
== 0)
2341 gfc_error ("Actual argument at %L for INTENT(%s) dummy %qs of "
2342 "ELEMENTAL subroutine %qs is a scalar, but another "
2343 "actual argument is an array", &arg
->expr
->where
,
2344 (eformal
->sym
->attr
.intent
== INTENT_OUT
) ? "OUT"
2345 : "INOUT", eformal
->sym
->name
, esym
->name
);
2352 /* This function does the checking of references to global procedures
2353 as defined in sections 18.1 and 14.1, respectively, of the Fortran
2354 77 and 95 standards. It checks for a gsymbol for the name, making
2355 one if it does not already exist. If it already exists, then the
2356 reference being resolved must correspond to the type of gsymbol.
2357 Otherwise, the new symbol is equipped with the attributes of the
2358 reference. The corresponding code that is called in creating
2359 global entities is parse.c.
2361 In addition, for all but -std=legacy, the gsymbols are used to
2362 check the interfaces of external procedures from the same file.
2363 The namespace of the gsymbol is resolved and then, once this is
2364 done the interface is checked. */
2368 not_in_recursive (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2370 if (!gsym_ns
->proc_name
->attr
.recursive
)
2373 if (sym
->ns
== gsym_ns
)
2376 if (sym
->ns
->parent
&& sym
->ns
->parent
== gsym_ns
)
2383 not_entry_self_reference (gfc_symbol
*sym
, gfc_namespace
*gsym_ns
)
2385 if (gsym_ns
->entries
)
2387 gfc_entry_list
*entry
= gsym_ns
->entries
;
2389 for (; entry
; entry
= entry
->next
)
2391 if (strcmp (sym
->name
, entry
->sym
->name
) == 0)
2393 if (strcmp (gsym_ns
->proc_name
->name
,
2394 sym
->ns
->proc_name
->name
) == 0)
2398 && strcmp (gsym_ns
->proc_name
->name
,
2399 sym
->ns
->parent
->proc_name
->name
) == 0)
2408 /* Check for the requirement of an explicit interface. F08:12.4.2.2. */
2411 gfc_explicit_interface_required (gfc_symbol
*sym
, char *errmsg
, int err_len
)
2413 gfc_formal_arglist
*arg
= gfc_sym_get_dummy_args (sym
);
2415 for ( ; arg
; arg
= arg
->next
)
2420 if (arg
->sym
->attr
.allocatable
) /* (2a) */
2422 strncpy (errmsg
, _("allocatable argument"), err_len
);
2425 else if (arg
->sym
->attr
.asynchronous
)
2427 strncpy (errmsg
, _("asynchronous argument"), err_len
);
2430 else if (arg
->sym
->attr
.optional
)
2432 strncpy (errmsg
, _("optional argument"), err_len
);
2435 else if (arg
->sym
->attr
.pointer
)
2437 strncpy (errmsg
, _("pointer argument"), err_len
);
2440 else if (arg
->sym
->attr
.target
)
2442 strncpy (errmsg
, _("target argument"), err_len
);
2445 else if (arg
->sym
->attr
.value
)
2447 strncpy (errmsg
, _("value argument"), err_len
);
2450 else if (arg
->sym
->attr
.volatile_
)
2452 strncpy (errmsg
, _("volatile argument"), err_len
);
2455 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_SHAPE
) /* (2b) */
2457 strncpy (errmsg
, _("assumed-shape argument"), err_len
);
2460 else if (arg
->sym
->as
&& arg
->sym
->as
->type
== AS_ASSUMED_RANK
) /* TS 29113, 6.2. */
2462 strncpy (errmsg
, _("assumed-rank argument"), err_len
);
2465 else if (arg
->sym
->attr
.codimension
) /* (2c) */
2467 strncpy (errmsg
, _("coarray argument"), err_len
);
2470 else if (false) /* (2d) TODO: parametrized derived type */
2472 strncpy (errmsg
, _("parametrized derived type argument"), err_len
);
2475 else if (arg
->sym
->ts
.type
== BT_CLASS
) /* (2e) */
2477 strncpy (errmsg
, _("polymorphic argument"), err_len
);
2480 else if (arg
->sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
2482 strncpy (errmsg
, _("NO_ARG_CHECK attribute"), err_len
);
2485 else if (arg
->sym
->ts
.type
== BT_ASSUMED
)
2487 /* As assumed-type is unlimited polymorphic (cf. above).
2488 See also TS 29113, Note 6.1. */
2489 strncpy (errmsg
, _("assumed-type argument"), err_len
);
2494 if (sym
->attr
.function
)
2496 gfc_symbol
*res
= sym
->result
? sym
->result
: sym
;
2498 if (res
->attr
.dimension
) /* (3a) */
2500 strncpy (errmsg
, _("array result"), err_len
);
2503 else if (res
->attr
.pointer
|| res
->attr
.allocatable
) /* (3b) */
2505 strncpy (errmsg
, _("pointer or allocatable result"), err_len
);
2508 else if (res
->ts
.type
== BT_CHARACTER
&& res
->ts
.u
.cl
2509 && res
->ts
.u
.cl
->length
2510 && res
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
) /* (3c) */
2512 strncpy (errmsg
, _("result with non-constant character length"), err_len
);
2517 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
) /* (4) */
2519 strncpy (errmsg
, _("elemental procedure"), err_len
);
2522 else if (sym
->attr
.is_bind_c
) /* (5) */
2524 strncpy (errmsg
, _("bind(c) procedure"), err_len
);
2533 resolve_global_procedure (gfc_symbol
*sym
, locus
*where
, int sub
)
2537 enum gfc_symbol_type type
;
2540 type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
2542 gsym
= gfc_get_gsymbol (sym
->binding_label
? sym
->binding_label
: sym
->name
,
2543 sym
->binding_label
!= NULL
);
2545 if ((gsym
->type
!= GSYM_UNKNOWN
&& gsym
->type
!= type
))
2546 gfc_global_used (gsym
, where
);
2548 if ((sym
->attr
.if_source
== IFSRC_UNKNOWN
2549 || sym
->attr
.if_source
== IFSRC_IFBODY
)
2550 && gsym
->type
!= GSYM_UNKNOWN
2551 && !gsym
->binding_label
2553 && gsym
->ns
->proc_name
2554 && not_in_recursive (sym
, gsym
->ns
)
2555 && not_entry_self_reference (sym
, gsym
->ns
))
2557 gfc_symbol
*def_sym
;
2558 def_sym
= gsym
->ns
->proc_name
;
2560 if (gsym
->ns
->resolved
!= -1)
2563 /* Resolve the gsymbol namespace if needed. */
2564 if (!gsym
->ns
->resolved
)
2566 gfc_symbol
*old_dt_list
;
2568 /* Stash away derived types so that the backend_decls
2569 do not get mixed up. */
2570 old_dt_list
= gfc_derived_types
;
2571 gfc_derived_types
= NULL
;
2573 gfc_resolve (gsym
->ns
);
2575 /* Store the new derived types with the global namespace. */
2576 if (gfc_derived_types
)
2577 gsym
->ns
->derived_types
= gfc_derived_types
;
2579 /* Restore the derived types of this namespace. */
2580 gfc_derived_types
= old_dt_list
;
2583 /* Make sure that translation for the gsymbol occurs before
2584 the procedure currently being resolved. */
2585 ns
= gfc_global_ns_list
;
2586 for (; ns
&& ns
!= gsym
->ns
; ns
= ns
->sibling
)
2588 if (ns
->sibling
== gsym
->ns
)
2590 ns
->sibling
= gsym
->ns
->sibling
;
2591 gsym
->ns
->sibling
= gfc_global_ns_list
;
2592 gfc_global_ns_list
= gsym
->ns
;
2597 /* This can happen if a binding name has been specified. */
2598 if (gsym
->binding_label
&& gsym
->sym_name
!= def_sym
->name
)
2599 gfc_find_symbol (gsym
->sym_name
, gsym
->ns
, 0, &def_sym
);
2601 if (def_sym
->attr
.entry_master
|| def_sym
->attr
.entry
)
2603 gfc_entry_list
*entry
;
2604 for (entry
= gsym
->ns
->entries
; entry
; entry
= entry
->next
)
2605 if (strcmp (entry
->sym
->name
, sym
->name
) == 0)
2607 def_sym
= entry
->sym
;
2613 if (sym
->attr
.function
&& !gfc_compare_types (&sym
->ts
, &def_sym
->ts
))
2615 gfc_error ("Return type mismatch of function %qs at %L (%s/%s)",
2616 sym
->name
, &sym
->declared_at
, gfc_typename (&sym
->ts
),
2617 gfc_typename (&def_sym
->ts
));
2621 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
2622 && gfc_explicit_interface_required (def_sym
, reason
, sizeof(reason
)))
2624 gfc_error ("Explicit interface required for %qs at %L: %s",
2625 sym
->name
, &sym
->declared_at
, reason
);
2629 bool bad_result_characteristics
;
2630 if (!gfc_compare_interfaces (sym
, def_sym
, sym
->name
, 0, 1,
2631 reason
, sizeof(reason
), NULL
, NULL
,
2632 &bad_result_characteristics
))
2634 /* Turn erros into warnings with -std=gnu and -std=legacy,
2635 unless a function returns a wrong type, which can lead
2636 to all kinds of ICEs and wrong code. */
2638 if (!pedantic
&& (gfc_option
.allow_std
& GFC_STD_GNU
)
2639 && !bad_result_characteristics
)
2640 gfc_errors_to_warnings (true);
2642 gfc_error ("Interface mismatch in global procedure %qs at %L: %s",
2643 sym
->name
, &sym
->declared_at
, reason
);
2645 gfc_errors_to_warnings (false);
2652 if (gsym
->type
== GSYM_UNKNOWN
)
2655 gsym
->where
= *where
;
2662 /************* Function resolution *************/
2664 /* Resolve a function call known to be generic.
2665 Section 14.1.2.4.1. */
2668 resolve_generic_f0 (gfc_expr
*expr
, gfc_symbol
*sym
)
2672 if (sym
->attr
.generic
)
2674 s
= gfc_search_interface (sym
->generic
, 0, &expr
->value
.function
.actual
);
2677 expr
->value
.function
.name
= s
->name
;
2678 expr
->value
.function
.esym
= s
;
2680 if (s
->ts
.type
!= BT_UNKNOWN
)
2682 else if (s
->result
!= NULL
&& s
->result
->ts
.type
!= BT_UNKNOWN
)
2683 expr
->ts
= s
->result
->ts
;
2686 expr
->rank
= s
->as
->rank
;
2687 else if (s
->result
!= NULL
&& s
->result
->as
!= NULL
)
2688 expr
->rank
= s
->result
->as
->rank
;
2690 gfc_set_sym_referenced (expr
->value
.function
.esym
);
2695 /* TODO: Need to search for elemental references in generic
2699 if (sym
->attr
.intrinsic
)
2700 return gfc_intrinsic_func_interface (expr
, 0);
2707 resolve_generic_f (gfc_expr
*expr
)
2711 gfc_interface
*intr
= NULL
;
2713 sym
= expr
->symtree
->n
.sym
;
2717 m
= resolve_generic_f0 (expr
, sym
);
2720 else if (m
== MATCH_ERROR
)
2725 for (intr
= sym
->generic
; intr
; intr
= intr
->next
)
2726 if (gfc_fl_struct (intr
->sym
->attr
.flavor
))
2729 if (sym
->ns
->parent
== NULL
)
2731 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2735 if (!generic_sym (sym
))
2739 /* Last ditch attempt. See if the reference is to an intrinsic
2740 that possesses a matching interface. 14.1.2.4 */
2741 if (sym
&& !intr
&& !gfc_is_intrinsic (sym
, 0, expr
->where
))
2743 if (gfc_init_expr_flag
)
2744 gfc_error ("Function %qs in initialization expression at %L "
2745 "must be an intrinsic function",
2746 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2748 gfc_error ("There is no specific function for the generic %qs "
2749 "at %L", expr
->symtree
->n
.sym
->name
, &expr
->where
);
2755 if (!gfc_convert_to_structure_constructor (expr
, intr
->sym
, NULL
,
2758 if (!gfc_use_derived (expr
->ts
.u
.derived
))
2760 return resolve_structure_cons (expr
, 0);
2763 m
= gfc_intrinsic_func_interface (expr
, 0);
2768 gfc_error ("Generic function %qs at %L is not consistent with a "
2769 "specific intrinsic interface", expr
->symtree
->n
.sym
->name
,
2776 /* Resolve a function call known to be specific. */
2779 resolve_specific_f0 (gfc_symbol
*sym
, gfc_expr
*expr
)
2783 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
2785 if (sym
->attr
.dummy
)
2787 sym
->attr
.proc
= PROC_DUMMY
;
2791 sym
->attr
.proc
= PROC_EXTERNAL
;
2795 if (sym
->attr
.proc
== PROC_MODULE
2796 || sym
->attr
.proc
== PROC_ST_FUNCTION
2797 || sym
->attr
.proc
== PROC_INTERNAL
)
2800 if (sym
->attr
.intrinsic
)
2802 m
= gfc_intrinsic_func_interface (expr
, 1);
2806 gfc_error ("Function %qs at %L is INTRINSIC but is not compatible "
2807 "with an intrinsic", sym
->name
, &expr
->where
);
2815 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2818 expr
->ts
= sym
->result
->ts
;
2821 expr
->value
.function
.name
= sym
->name
;
2822 expr
->value
.function
.esym
= sym
;
2823 /* Prevent crash when sym->ts.u.derived->components is not set due to previous
2825 if (sym
->ts
.type
== BT_CLASS
&& !CLASS_DATA (sym
))
2827 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->as
)
2828 expr
->rank
= CLASS_DATA (sym
)->as
->rank
;
2829 else if (sym
->as
!= NULL
)
2830 expr
->rank
= sym
->as
->rank
;
2837 resolve_specific_f (gfc_expr
*expr
)
2842 sym
= expr
->symtree
->n
.sym
;
2846 m
= resolve_specific_f0 (sym
, expr
);
2849 if (m
== MATCH_ERROR
)
2852 if (sym
->ns
->parent
== NULL
)
2855 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2861 gfc_error ("Unable to resolve the specific function %qs at %L",
2862 expr
->symtree
->n
.sym
->name
, &expr
->where
);
2867 /* Recursively append candidate SYM to CANDIDATES. Store the number of
2868 candidates in CANDIDATES_LEN. */
2871 lookup_function_fuzzy_find_candidates (gfc_symtree
*sym
,
2873 size_t &candidates_len
)
2879 if ((sym
->n
.sym
->ts
.type
!= BT_UNKNOWN
|| sym
->n
.sym
->attr
.external
)
2880 && sym
->n
.sym
->attr
.flavor
== FL_PROCEDURE
)
2881 vec_push (candidates
, candidates_len
, sym
->name
);
2885 lookup_function_fuzzy_find_candidates (p
, candidates
, candidates_len
);
2889 lookup_function_fuzzy_find_candidates (p
, candidates
, candidates_len
);
2893 /* Lookup function FN fuzzily, taking names in SYMROOT into account. */
2896 gfc_lookup_function_fuzzy (const char *fn
, gfc_symtree
*symroot
)
2898 char **candidates
= NULL
;
2899 size_t candidates_len
= 0;
2900 lookup_function_fuzzy_find_candidates (symroot
, candidates
, candidates_len
);
2901 return gfc_closest_fuzzy_match (fn
, candidates
);
2905 /* Resolve a procedure call not known to be generic nor specific. */
2908 resolve_unknown_f (gfc_expr
*expr
)
2913 sym
= expr
->symtree
->n
.sym
;
2915 if (sym
->attr
.dummy
)
2917 sym
->attr
.proc
= PROC_DUMMY
;
2918 expr
->value
.function
.name
= sym
->name
;
2922 /* See if we have an intrinsic function reference. */
2924 if (gfc_is_intrinsic (sym
, 0, expr
->where
))
2926 if (gfc_intrinsic_func_interface (expr
, 1) == MATCH_YES
)
2931 /* The reference is to an external name. */
2933 sym
->attr
.proc
= PROC_EXTERNAL
;
2934 expr
->value
.function
.name
= sym
->name
;
2935 expr
->value
.function
.esym
= expr
->symtree
->n
.sym
;
2937 if (sym
->as
!= NULL
)
2938 expr
->rank
= sym
->as
->rank
;
2940 /* Type of the expression is either the type of the symbol or the
2941 default type of the symbol. */
2944 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
2946 if (sym
->ts
.type
!= BT_UNKNOWN
)
2950 ts
= gfc_get_default_type (sym
->name
, sym
->ns
);
2952 if (ts
->type
== BT_UNKNOWN
)
2955 = gfc_lookup_function_fuzzy (sym
->name
, sym
->ns
->sym_root
);
2957 gfc_error ("Function %qs at %L has no IMPLICIT type"
2958 "; did you mean %qs?",
2959 sym
->name
, &expr
->where
, guessed
);
2961 gfc_error ("Function %qs at %L has no IMPLICIT type",
2962 sym
->name
, &expr
->where
);
2973 /* Return true, if the symbol is an external procedure. */
2975 is_external_proc (gfc_symbol
*sym
)
2977 if (!sym
->attr
.dummy
&& !sym
->attr
.contained
2978 && !gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, sym
->declared_at
)
2979 && sym
->attr
.proc
!= PROC_ST_FUNCTION
2980 && !sym
->attr
.proc_pointer
2981 && !sym
->attr
.use_assoc
2989 /* Figure out if a function reference is pure or not. Also set the name
2990 of the function for a potential error message. Return nonzero if the
2991 function is PURE, zero if not. */
2993 pure_stmt_function (gfc_expr
*, gfc_symbol
*);
2996 gfc_pure_function (gfc_expr
*e
, const char **name
)
2999 gfc_component
*comp
;
3003 if (e
->symtree
!= NULL
3004 && e
->symtree
->n
.sym
!= NULL
3005 && e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
3006 return pure_stmt_function (e
, e
->symtree
->n
.sym
);
3008 comp
= gfc_get_proc_ptr_comp (e
);
3011 pure
= gfc_pure (comp
->ts
.interface
);
3014 else if (e
->value
.function
.esym
)
3016 pure
= gfc_pure (e
->value
.function
.esym
);
3017 *name
= e
->value
.function
.esym
->name
;
3019 else if (e
->value
.function
.isym
)
3021 pure
= e
->value
.function
.isym
->pure
3022 || e
->value
.function
.isym
->elemental
;
3023 *name
= e
->value
.function
.isym
->name
;
3027 /* Implicit functions are not pure. */
3029 *name
= e
->value
.function
.name
;
3036 /* Check if the expression is a reference to an implicitly pure function. */
3039 gfc_implicit_pure_function (gfc_expr
*e
)
3041 gfc_component
*comp
= gfc_get_proc_ptr_comp (e
);
3043 return gfc_implicit_pure (comp
->ts
.interface
);
3044 else if (e
->value
.function
.esym
)
3045 return gfc_implicit_pure (e
->value
.function
.esym
);
3052 impure_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
,
3053 int *f ATTRIBUTE_UNUSED
)
3057 /* Don't bother recursing into other statement functions
3058 since they will be checked individually for purity. */
3059 if (e
->expr_type
!= EXPR_FUNCTION
3061 || e
->symtree
->n
.sym
== sym
3062 || e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
3065 return gfc_pure_function (e
, &name
) ? false : true;
3070 pure_stmt_function (gfc_expr
*e
, gfc_symbol
*sym
)
3072 return gfc_traverse_expr (e
, sym
, impure_stmt_fcn
, 0) ? 0 : 1;
3076 /* Check if an impure function is allowed in the current context. */
3078 static bool check_pure_function (gfc_expr
*e
)
3080 const char *name
= NULL
;
3081 if (!gfc_pure_function (e
, &name
) && name
)
3085 gfc_error ("Reference to impure function %qs at %L inside a "
3086 "FORALL %s", name
, &e
->where
,
3087 forall_flag
== 2 ? "mask" : "block");
3090 else if (gfc_do_concurrent_flag
)
3092 gfc_error ("Reference to impure function %qs at %L inside a "
3093 "DO CONCURRENT %s", name
, &e
->where
,
3094 gfc_do_concurrent_flag
== 2 ? "mask" : "block");
3097 else if (gfc_pure (NULL
))
3099 gfc_error ("Reference to impure function %qs at %L "
3100 "within a PURE procedure", name
, &e
->where
);
3103 if (!gfc_implicit_pure_function (e
))
3104 gfc_unset_implicit_pure (NULL
);
3110 /* Update current procedure's array_outer_dependency flag, considering
3111 a call to procedure SYM. */
3114 update_current_proc_array_outer_dependency (gfc_symbol
*sym
)
3116 /* Check to see if this is a sibling function that has not yet
3118 gfc_namespace
*sibling
= gfc_current_ns
->sibling
;
3119 for (; sibling
; sibling
= sibling
->sibling
)
3121 if (sibling
->proc_name
== sym
)
3123 gfc_resolve (sibling
);
3128 /* If SYM has references to outer arrays, so has the procedure calling
3129 SYM. If SYM is a procedure pointer, we can assume the worst. */
3130 if ((sym
->attr
.array_outer_dependency
|| sym
->attr
.proc_pointer
)
3131 && gfc_current_ns
->proc_name
)
3132 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
3136 /* Resolve a function call, which means resolving the arguments, then figuring
3137 out which entity the name refers to. */
3140 resolve_function (gfc_expr
*expr
)
3142 gfc_actual_arglist
*arg
;
3146 procedure_type p
= PROC_INTRINSIC
;
3147 bool no_formal_args
;
3151 sym
= expr
->symtree
->n
.sym
;
3153 /* If this is a procedure pointer component, it has already been resolved. */
3154 if (gfc_is_proc_ptr_comp (expr
))
3157 /* Avoid re-resolving the arguments of caf_get, which can lead to inserting
3159 if (sym
&& sym
->attr
.intrinsic
3160 && (sym
->intmod_sym_id
== GFC_ISYM_CAF_GET
3161 || sym
->intmod_sym_id
== GFC_ISYM_CAF_SEND
))
3166 gfc_error ("Unexpected junk after %qs at %L", expr
->symtree
->n
.sym
->name
,
3171 if (sym
&& sym
->attr
.intrinsic
3172 && !gfc_resolve_intrinsic (sym
, &expr
->where
))
3175 if (sym
&& (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.subroutine
))
3177 gfc_error ("%qs at %L is not a function", sym
->name
, &expr
->where
);
3181 /* If this is a deferred TBP with an abstract interface (which may
3182 of course be referenced), expr->value.function.esym will be set. */
3183 if (sym
&& sym
->attr
.abstract
&& !expr
->value
.function
.esym
)
3185 gfc_error ("ABSTRACT INTERFACE %qs must not be referenced at %L",
3186 sym
->name
, &expr
->where
);
3190 /* If this is a deferred TBP with an abstract interface, its result
3191 cannot be an assumed length character (F2003: C418). */
3192 if (sym
&& sym
->attr
.abstract
&& sym
->attr
.function
3193 && sym
->result
->ts
.u
.cl
3194 && sym
->result
->ts
.u
.cl
->length
== NULL
3195 && !sym
->result
->ts
.deferred
)
3197 gfc_error ("ABSTRACT INTERFACE %qs at %L must not have an assumed "
3198 "character length result (F2008: C418)", sym
->name
,
3203 /* Switch off assumed size checking and do this again for certain kinds
3204 of procedure, once the procedure itself is resolved. */
3205 need_full_assumed_size
++;
3207 if (expr
->symtree
&& expr
->symtree
->n
.sym
)
3208 p
= expr
->symtree
->n
.sym
->attr
.proc
;
3210 if (expr
->value
.function
.isym
&& expr
->value
.function
.isym
->inquiry
)
3211 inquiry_argument
= true;
3212 no_formal_args
= sym
&& is_external_proc (sym
)
3213 && gfc_sym_get_dummy_args (sym
) == NULL
;
3215 if (!resolve_actual_arglist (expr
->value
.function
.actual
,
3218 inquiry_argument
= false;
3222 inquiry_argument
= false;
3224 /* Resume assumed_size checking. */
3225 need_full_assumed_size
--;
3227 /* If the procedure is external, check for usage. */
3228 if (sym
&& is_external_proc (sym
))
3229 resolve_global_procedure (sym
, &expr
->where
, 0);
3231 if (sym
&& sym
->ts
.type
== BT_CHARACTER
3233 && sym
->ts
.u
.cl
->length
== NULL
3235 && !sym
->ts
.deferred
3236 && expr
->value
.function
.esym
== NULL
3237 && !sym
->attr
.contained
)
3239 /* Internal procedures are taken care of in resolve_contained_fntype. */
3240 gfc_error ("Function %qs is declared CHARACTER(*) and cannot "
3241 "be used at %L since it is not a dummy argument",
3242 sym
->name
, &expr
->where
);
3246 /* See if function is already resolved. */
3248 if (expr
->value
.function
.name
!= NULL
3249 || expr
->value
.function
.isym
!= NULL
)
3251 if (expr
->ts
.type
== BT_UNKNOWN
)
3257 /* Apply the rules of section 14.1.2. */
3259 switch (procedure_kind (sym
))
3262 t
= resolve_generic_f (expr
);
3265 case PTYPE_SPECIFIC
:
3266 t
= resolve_specific_f (expr
);
3270 t
= resolve_unknown_f (expr
);
3274 gfc_internal_error ("resolve_function(): bad function type");
3278 /* If the expression is still a function (it might have simplified),
3279 then we check to see if we are calling an elemental function. */
3281 if (expr
->expr_type
!= EXPR_FUNCTION
)
3284 /* Walk the argument list looking for invalid BOZ. */
3285 for (arg
= expr
->value
.function
.actual
; arg
; arg
= arg
->next
)
3286 if (arg
->expr
&& arg
->expr
->ts
.type
== BT_BOZ
)
3288 gfc_error ("A BOZ literal constant at %L cannot appear as an "
3289 "actual argument in a function reference",
3294 temp
= need_full_assumed_size
;
3295 need_full_assumed_size
= 0;
3297 if (!resolve_elemental_actual (expr
, NULL
))
3300 if (omp_workshare_flag
3301 && expr
->value
.function
.esym
3302 && ! gfc_elemental (expr
->value
.function
.esym
))
3304 gfc_error ("User defined non-ELEMENTAL function %qs at %L not allowed "
3305 "in WORKSHARE construct", expr
->value
.function
.esym
->name
,
3310 #define GENERIC_ID expr->value.function.isym->id
3311 else if (expr
->value
.function
.actual
!= NULL
3312 && expr
->value
.function
.isym
!= NULL
3313 && GENERIC_ID
!= GFC_ISYM_LBOUND
3314 && GENERIC_ID
!= GFC_ISYM_LCOBOUND
3315 && GENERIC_ID
!= GFC_ISYM_UCOBOUND
3316 && GENERIC_ID
!= GFC_ISYM_LEN
3317 && GENERIC_ID
!= GFC_ISYM_LOC
3318 && GENERIC_ID
!= GFC_ISYM_C_LOC
3319 && GENERIC_ID
!= GFC_ISYM_PRESENT
)
3321 /* Array intrinsics must also have the last upper bound of an
3322 assumed size array argument. UBOUND and SIZE have to be
3323 excluded from the check if the second argument is anything
3326 for (arg
= expr
->value
.function
.actual
; arg
; arg
= arg
->next
)
3328 if ((GENERIC_ID
== GFC_ISYM_UBOUND
|| GENERIC_ID
== GFC_ISYM_SIZE
)
3329 && arg
== expr
->value
.function
.actual
3330 && arg
->next
!= NULL
&& arg
->next
->expr
)
3332 if (arg
->next
->expr
->expr_type
!= EXPR_CONSTANT
)
3335 if (arg
->next
->name
&& strcmp (arg
->next
->name
, "kind") == 0)
3338 if ((int)mpz_get_si (arg
->next
->expr
->value
.integer
)
3343 if (arg
->expr
!= NULL
3344 && arg
->expr
->rank
> 0
3345 && resolve_assumed_size_actual (arg
->expr
))
3351 need_full_assumed_size
= temp
;
3353 if (!check_pure_function(expr
))
3356 /* Functions without the RECURSIVE attribution are not allowed to
3357 * call themselves. */
3358 if (expr
->value
.function
.esym
&& !expr
->value
.function
.esym
->attr
.recursive
)
3361 esym
= expr
->value
.function
.esym
;
3363 if (is_illegal_recursion (esym
, gfc_current_ns
))
3365 if (esym
->attr
.entry
&& esym
->ns
->entries
)
3366 gfc_error ("ENTRY %qs at %L cannot be called recursively, as"
3367 " function %qs is not RECURSIVE",
3368 esym
->name
, &expr
->where
, esym
->ns
->entries
->sym
->name
);
3370 gfc_error ("Function %qs at %L cannot be called recursively, as it"
3371 " is not RECURSIVE", esym
->name
, &expr
->where
);
3377 /* Character lengths of use associated functions may contains references to
3378 symbols not referenced from the current program unit otherwise. Make sure
3379 those symbols are marked as referenced. */
3381 if (expr
->ts
.type
== BT_CHARACTER
&& expr
->value
.function
.esym
3382 && expr
->value
.function
.esym
->attr
.use_assoc
)
3384 gfc_expr_set_symbols_referenced (expr
->ts
.u
.cl
->length
);
3387 /* Make sure that the expression has a typespec that works. */
3388 if (expr
->ts
.type
== BT_UNKNOWN
)
3390 if (expr
->symtree
->n
.sym
->result
3391 && expr
->symtree
->n
.sym
->result
->ts
.type
!= BT_UNKNOWN
3392 && !expr
->symtree
->n
.sym
->result
->attr
.proc_pointer
)
3393 expr
->ts
= expr
->symtree
->n
.sym
->result
->ts
;
3396 if (!expr
->ref
&& !expr
->value
.function
.isym
)
3398 if (expr
->value
.function
.esym
)
3399 update_current_proc_array_outer_dependency (expr
->value
.function
.esym
);
3401 update_current_proc_array_outer_dependency (sym
);
3404 /* typebound procedure: Assume the worst. */
3405 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
3407 if (expr
->value
.function
.esym
3408 && expr
->value
.function
.esym
->attr
.ext_attr
& (1 << EXT_ATTR_DEPRECATED
))
3409 gfc_warning (OPT_Wdeprecated_declarations
,
3410 "Using function %qs at %L is deprecated",
3411 sym
->name
, &expr
->where
);
3416 /************* Subroutine resolution *************/
3419 pure_subroutine (gfc_symbol
*sym
, const char *name
, locus
*loc
)
3426 gfc_error ("Subroutine call to %qs in FORALL block at %L is not PURE",
3430 else if (gfc_do_concurrent_flag
)
3432 gfc_error ("Subroutine call to %qs in DO CONCURRENT block at %L is not "
3436 else if (gfc_pure (NULL
))
3438 gfc_error ("Subroutine call to %qs at %L is not PURE", name
, loc
);
3442 gfc_unset_implicit_pure (NULL
);
3448 resolve_generic_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3452 if (sym
->attr
.generic
)
3454 s
= gfc_search_interface (sym
->generic
, 1, &c
->ext
.actual
);
3457 c
->resolved_sym
= s
;
3458 if (!pure_subroutine (s
, s
->name
, &c
->loc
))
3463 /* TODO: Need to search for elemental references in generic interface. */
3466 if (sym
->attr
.intrinsic
)
3467 return gfc_intrinsic_sub_interface (c
, 0);
3474 resolve_generic_s (gfc_code
*c
)
3479 sym
= c
->symtree
->n
.sym
;
3483 m
= resolve_generic_s0 (c
, sym
);
3486 else if (m
== MATCH_ERROR
)
3490 if (sym
->ns
->parent
== NULL
)
3492 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3496 if (!generic_sym (sym
))
3500 /* Last ditch attempt. See if the reference is to an intrinsic
3501 that possesses a matching interface. 14.1.2.4 */
3502 sym
= c
->symtree
->n
.sym
;
3504 if (!gfc_is_intrinsic (sym
, 1, c
->loc
))
3506 gfc_error ("There is no specific subroutine for the generic %qs at %L",
3507 sym
->name
, &c
->loc
);
3511 m
= gfc_intrinsic_sub_interface (c
, 0);
3515 gfc_error ("Generic subroutine %qs at %L is not consistent with an "
3516 "intrinsic subroutine interface", sym
->name
, &c
->loc
);
3522 /* Resolve a subroutine call known to be specific. */
3525 resolve_specific_s0 (gfc_code
*c
, gfc_symbol
*sym
)
3529 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
3531 if (sym
->attr
.dummy
)
3533 sym
->attr
.proc
= PROC_DUMMY
;
3537 sym
->attr
.proc
= PROC_EXTERNAL
;
3541 if (sym
->attr
.proc
== PROC_MODULE
|| sym
->attr
.proc
== PROC_INTERNAL
)
3544 if (sym
->attr
.intrinsic
)
3546 m
= gfc_intrinsic_sub_interface (c
, 1);
3550 gfc_error ("Subroutine %qs at %L is INTRINSIC but is not compatible "
3551 "with an intrinsic", sym
->name
, &c
->loc
);
3559 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3561 c
->resolved_sym
= sym
;
3562 if (!pure_subroutine (sym
, sym
->name
, &c
->loc
))
3570 resolve_specific_s (gfc_code
*c
)
3575 sym
= c
->symtree
->n
.sym
;
3579 m
= resolve_specific_s0 (c
, sym
);
3582 if (m
== MATCH_ERROR
)
3585 if (sym
->ns
->parent
== NULL
)
3588 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
3594 sym
= c
->symtree
->n
.sym
;
3595 gfc_error ("Unable to resolve the specific subroutine %qs at %L",
3596 sym
->name
, &c
->loc
);
3602 /* Resolve a subroutine call not known to be generic nor specific. */
3605 resolve_unknown_s (gfc_code
*c
)
3609 sym
= c
->symtree
->n
.sym
;
3611 if (sym
->attr
.dummy
)
3613 sym
->attr
.proc
= PROC_DUMMY
;
3617 /* See if we have an intrinsic function reference. */
3619 if (gfc_is_intrinsic (sym
, 1, c
->loc
))
3621 if (gfc_intrinsic_sub_interface (c
, 1) == MATCH_YES
)
3626 /* The reference is to an external name. */
3629 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
3631 c
->resolved_sym
= sym
;
3633 return pure_subroutine (sym
, sym
->name
, &c
->loc
);
3637 /* Resolve a subroutine call. Although it was tempting to use the same code
3638 for functions, subroutines and functions are stored differently and this
3639 makes things awkward. */
3642 resolve_call (gfc_code
*c
)
3645 procedure_type ptype
= PROC_INTRINSIC
;
3646 gfc_symbol
*csym
, *sym
;
3647 bool no_formal_args
;
3649 csym
= c
->symtree
? c
->symtree
->n
.sym
: NULL
;
3651 if (csym
&& csym
->ts
.type
!= BT_UNKNOWN
)
3653 gfc_error ("%qs at %L has a type, which is not consistent with "
3654 "the CALL at %L", csym
->name
, &csym
->declared_at
, &c
->loc
);
3658 if (csym
&& gfc_current_ns
->parent
&& csym
->ns
!= gfc_current_ns
)
3661 gfc_find_sym_tree (c
->symtree
->name
, gfc_current_ns
, 1, &st
);
3662 sym
= st
? st
->n
.sym
: NULL
;
3663 if (sym
&& csym
!= sym
3664 && sym
->ns
== gfc_current_ns
3665 && sym
->attr
.flavor
== FL_PROCEDURE
3666 && sym
->attr
.contained
)
3669 if (csym
->attr
.generic
)
3670 c
->symtree
->n
.sym
= sym
;
3673 csym
= c
->symtree
->n
.sym
;
3677 /* If this ia a deferred TBP, c->expr1 will be set. */
3678 if (!c
->expr1
&& csym
)
3680 if (csym
->attr
.abstract
)
3682 gfc_error ("ABSTRACT INTERFACE %qs must not be referenced at %L",
3683 csym
->name
, &c
->loc
);
3687 /* Subroutines without the RECURSIVE attribution are not allowed to
3689 if (is_illegal_recursion (csym
, gfc_current_ns
))
3691 if (csym
->attr
.entry
&& csym
->ns
->entries
)
3692 gfc_error ("ENTRY %qs at %L cannot be called recursively, "
3693 "as subroutine %qs is not RECURSIVE",
3694 csym
->name
, &c
->loc
, csym
->ns
->entries
->sym
->name
);
3696 gfc_error ("SUBROUTINE %qs at %L cannot be called recursively, "
3697 "as it is not RECURSIVE", csym
->name
, &c
->loc
);
3703 /* Switch off assumed size checking and do this again for certain kinds
3704 of procedure, once the procedure itself is resolved. */
3705 need_full_assumed_size
++;
3708 ptype
= csym
->attr
.proc
;
3710 no_formal_args
= csym
&& is_external_proc (csym
)
3711 && gfc_sym_get_dummy_args (csym
) == NULL
;
3712 if (!resolve_actual_arglist (c
->ext
.actual
, ptype
, no_formal_args
))
3715 /* Resume assumed_size checking. */
3716 need_full_assumed_size
--;
3718 /* If external, check for usage. */
3719 if (csym
&& is_external_proc (csym
))
3720 resolve_global_procedure (csym
, &c
->loc
, 1);
3723 if (c
->resolved_sym
== NULL
)
3725 c
->resolved_isym
= NULL
;
3726 switch (procedure_kind (csym
))
3729 t
= resolve_generic_s (c
);
3732 case PTYPE_SPECIFIC
:
3733 t
= resolve_specific_s (c
);
3737 t
= resolve_unknown_s (c
);
3741 gfc_internal_error ("resolve_subroutine(): bad function type");
3745 /* Some checks of elemental subroutine actual arguments. */
3746 if (!resolve_elemental_actual (NULL
, c
))
3750 update_current_proc_array_outer_dependency (csym
);
3752 /* Typebound procedure: Assume the worst. */
3753 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
3756 && c
->resolved_sym
->attr
.ext_attr
& (1 << EXT_ATTR_DEPRECATED
))
3757 gfc_warning (OPT_Wdeprecated_declarations
,
3758 "Using subroutine %qs at %L is deprecated",
3759 c
->resolved_sym
->name
, &c
->loc
);
3765 /* Compare the shapes of two arrays that have non-NULL shapes. If both
3766 op1->shape and op2->shape are non-NULL return true if their shapes
3767 match. If both op1->shape and op2->shape are non-NULL return false
3768 if their shapes do not match. If either op1->shape or op2->shape is
3769 NULL, return true. */
3772 compare_shapes (gfc_expr
*op1
, gfc_expr
*op2
)
3779 if (op1
->shape
!= NULL
&& op2
->shape
!= NULL
)
3781 for (i
= 0; i
< op1
->rank
; i
++)
3783 if (mpz_cmp (op1
->shape
[i
], op2
->shape
[i
]) != 0)
3785 gfc_error ("Shapes for operands at %L and %L are not conformable",
3786 &op1
->where
, &op2
->where
);
3796 /* Convert a logical operator to the corresponding bitwise intrinsic call.
3797 For example A .AND. B becomes IAND(A, B). */
3799 logical_to_bitwise (gfc_expr
*e
)
3801 gfc_expr
*tmp
, *op1
, *op2
;
3803 gfc_actual_arglist
*args
= NULL
;
3805 gcc_assert (e
->expr_type
== EXPR_OP
);
3807 isym
= GFC_ISYM_NONE
;
3808 op1
= e
->value
.op
.op1
;
3809 op2
= e
->value
.op
.op2
;
3811 switch (e
->value
.op
.op
)
3814 isym
= GFC_ISYM_NOT
;
3817 isym
= GFC_ISYM_IAND
;
3820 isym
= GFC_ISYM_IOR
;
3822 case INTRINSIC_NEQV
:
3823 isym
= GFC_ISYM_IEOR
;
3826 /* "Bitwise eqv" is just the complement of NEQV === IEOR.
3827 Change the old expression to NEQV, which will get replaced by IEOR,
3828 and wrap it in NOT. */
3829 tmp
= gfc_copy_expr (e
);
3830 tmp
->value
.op
.op
= INTRINSIC_NEQV
;
3831 tmp
= logical_to_bitwise (tmp
);
3832 isym
= GFC_ISYM_NOT
;
3837 gfc_internal_error ("logical_to_bitwise(): Bad intrinsic");
3840 /* Inherit the original operation's operands as arguments. */
3841 args
= gfc_get_actual_arglist ();
3845 args
->next
= gfc_get_actual_arglist ();
3846 args
->next
->expr
= op2
;
3849 /* Convert the expression to a function call. */
3850 e
->expr_type
= EXPR_FUNCTION
;
3851 e
->value
.function
.actual
= args
;
3852 e
->value
.function
.isym
= gfc_intrinsic_function_by_id (isym
);
3853 e
->value
.function
.name
= e
->value
.function
.isym
->name
;
3854 e
->value
.function
.esym
= NULL
;
3856 /* Make up a pre-resolved function call symtree if we need to. */
3857 if (!e
->symtree
|| !e
->symtree
->n
.sym
)
3860 gfc_get_ha_sym_tree (e
->value
.function
.isym
->name
, &e
->symtree
);
3861 sym
= e
->symtree
->n
.sym
;
3863 sym
->attr
.flavor
= FL_PROCEDURE
;
3864 sym
->attr
.function
= 1;
3865 sym
->attr
.elemental
= 1;
3867 sym
->attr
.referenced
= 1;
3868 gfc_intrinsic_symbol (sym
);
3869 gfc_commit_symbol (sym
);
3872 args
->name
= e
->value
.function
.isym
->formal
->name
;
3873 if (e
->value
.function
.isym
->formal
->next
)
3874 args
->next
->name
= e
->value
.function
.isym
->formal
->next
->name
;
3879 /* Recursively append candidate UOP to CANDIDATES. Store the number of
3880 candidates in CANDIDATES_LEN. */
3882 lookup_uop_fuzzy_find_candidates (gfc_symtree
*uop
,
3884 size_t &candidates_len
)
3891 /* Not sure how to properly filter here. Use all for a start.
3892 n.uop.op is NULL for empty interface operators (is that legal?) disregard
3893 these as i suppose they don't make terribly sense. */
3895 if (uop
->n
.uop
->op
!= NULL
)
3896 vec_push (candidates
, candidates_len
, uop
->name
);
3900 lookup_uop_fuzzy_find_candidates (p
, candidates
, candidates_len
);
3904 lookup_uop_fuzzy_find_candidates (p
, candidates
, candidates_len
);
3907 /* Lookup user-operator OP fuzzily, taking names in UOP into account. */
3910 lookup_uop_fuzzy (const char *op
, gfc_symtree
*uop
)
3912 char **candidates
= NULL
;
3913 size_t candidates_len
= 0;
3914 lookup_uop_fuzzy_find_candidates (uop
, candidates
, candidates_len
);
3915 return gfc_closest_fuzzy_match (op
, candidates
);
3919 /* Callback finding an impure function as an operand to an .and. or
3920 .or. expression. Remember the last function warned about to
3921 avoid double warnings when recursing. */
3924 impure_function_callback (gfc_expr
**e
, int *walk_subtrees ATTRIBUTE_UNUSED
,
3929 static gfc_expr
*last
= NULL
;
3930 bool *found
= (bool *) data
;
3932 if (f
->expr_type
== EXPR_FUNCTION
)
3935 if (f
!= last
&& !gfc_pure_function (f
, &name
)
3936 && !gfc_implicit_pure_function (f
))
3939 gfc_warning (OPT_Wfunction_elimination
,
3940 "Impure function %qs at %L might not be evaluated",
3943 gfc_warning (OPT_Wfunction_elimination
,
3944 "Impure function at %L might not be evaluated",
3953 /* Return true if TYPE is character based, false otherwise. */
3956 is_character_based (bt type
)
3958 return type
== BT_CHARACTER
|| type
== BT_HOLLERITH
;
3962 /* If expression is a hollerith, convert it to character and issue a warning
3963 for the conversion. */
3966 convert_hollerith_to_character (gfc_expr
*e
)
3968 if (e
->ts
.type
== BT_HOLLERITH
)
3972 t
.type
= BT_CHARACTER
;
3973 t
.kind
= e
->ts
.kind
;
3974 gfc_convert_type_warn (e
, &t
, 2, 1);
3978 /* Convert to numeric and issue a warning for the conversion. */
3981 convert_to_numeric (gfc_expr
*a
, gfc_expr
*b
)
3985 t
.type
= b
->ts
.type
;
3986 t
.kind
= b
->ts
.kind
;
3987 gfc_convert_type_warn (a
, &t
, 2, 1);
3990 /* Resolve an operator expression node. This can involve replacing the
3991 operation with a user defined function call. */
3994 resolve_operator (gfc_expr
*e
)
3996 gfc_expr
*op1
, *op2
;
3998 bool dual_locus_error
;
4001 /* Resolve all subnodes-- give them types. */
4003 switch (e
->value
.op
.op
)
4006 if (!gfc_resolve_expr (e
->value
.op
.op2
))
4012 case INTRINSIC_UPLUS
:
4013 case INTRINSIC_UMINUS
:
4014 case INTRINSIC_PARENTHESES
:
4015 if (!gfc_resolve_expr (e
->value
.op
.op1
))
4018 && e
->value
.op
.op1
->ts
.type
== BT_BOZ
&& !e
->value
.op
.op2
)
4020 gfc_error ("BOZ literal constant at %L cannot be an operand of "
4021 "unary operator %qs", &e
->value
.op
.op1
->where
,
4022 gfc_op2string (e
->value
.op
.op
));
4028 /* Typecheck the new node. */
4030 op1
= e
->value
.op
.op1
;
4031 op2
= e
->value
.op
.op2
;
4032 if (op1
== NULL
&& op2
== NULL
)
4035 dual_locus_error
= false;
4037 /* op1 and op2 cannot both be BOZ. */
4038 if (op1
&& op1
->ts
.type
== BT_BOZ
4039 && op2
&& op2
->ts
.type
== BT_BOZ
)
4041 gfc_error ("Operands at %L and %L cannot appear as operands of "
4042 "binary operator %qs", &op1
->where
, &op2
->where
,
4043 gfc_op2string (e
->value
.op
.op
));
4047 if ((op1
&& op1
->expr_type
== EXPR_NULL
)
4048 || (op2
&& op2
->expr_type
== EXPR_NULL
))
4050 sprintf (msg
, _("Invalid context for NULL() pointer at %%L"));
4054 switch (e
->value
.op
.op
)
4056 case INTRINSIC_UPLUS
:
4057 case INTRINSIC_UMINUS
:
4058 if (op1
->ts
.type
== BT_INTEGER
4059 || op1
->ts
.type
== BT_REAL
4060 || op1
->ts
.type
== BT_COMPLEX
)
4066 sprintf (msg
, _("Operand of unary numeric operator %%<%s%%> at %%L is %s"),
4067 gfc_op2string (e
->value
.op
.op
), gfc_typename (e
));
4070 case INTRINSIC_PLUS
:
4071 case INTRINSIC_MINUS
:
4072 case INTRINSIC_TIMES
:
4073 case INTRINSIC_DIVIDE
:
4074 case INTRINSIC_POWER
:
4075 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
4077 gfc_type_convert_binary (e
, 1);
4081 if (op1
->ts
.type
== BT_DERIVED
|| op2
->ts
.type
== BT_DERIVED
)
4083 _("Unexpected derived-type entities in binary intrinsic "
4084 "numeric operator %%<%s%%> at %%L"),
4085 gfc_op2string (e
->value
.op
.op
));
4088 _("Operands of binary numeric operator %%<%s%%> at %%L are %s/%s"),
4089 gfc_op2string (e
->value
.op
.op
), gfc_typename (op1
),
4090 gfc_typename (op2
));
4093 case INTRINSIC_CONCAT
:
4094 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
4095 && op1
->ts
.kind
== op2
->ts
.kind
)
4097 e
->ts
.type
= BT_CHARACTER
;
4098 e
->ts
.kind
= op1
->ts
.kind
;
4103 _("Operands of string concatenation operator at %%L are %s/%s"),
4104 gfc_typename (op1
), gfc_typename (op2
));
4110 case INTRINSIC_NEQV
:
4111 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
4113 e
->ts
.type
= BT_LOGICAL
;
4114 e
->ts
.kind
= gfc_kind_max (op1
, op2
);
4115 if (op1
->ts
.kind
< e
->ts
.kind
)
4116 gfc_convert_type (op1
, &e
->ts
, 2);
4117 else if (op2
->ts
.kind
< e
->ts
.kind
)
4118 gfc_convert_type (op2
, &e
->ts
, 2);
4120 if (flag_frontend_optimize
&&
4121 (e
->value
.op
.op
== INTRINSIC_AND
|| e
->value
.op
.op
== INTRINSIC_OR
))
4123 /* Warn about short-circuiting
4124 with impure function as second operand. */
4126 gfc_expr_walker (&op2
, impure_function_callback
, &op2_f
);
4131 /* Logical ops on integers become bitwise ops with -fdec. */
4133 && (op1
->ts
.type
== BT_INTEGER
|| op2
->ts
.type
== BT_INTEGER
))
4135 e
->ts
.type
= BT_INTEGER
;
4136 e
->ts
.kind
= gfc_kind_max (op1
, op2
);
4137 if (op1
->ts
.type
!= e
->ts
.type
|| op1
->ts
.kind
!= e
->ts
.kind
)
4138 gfc_convert_type (op1
, &e
->ts
, 1);
4139 if (op2
->ts
.type
!= e
->ts
.type
|| op2
->ts
.kind
!= e
->ts
.kind
)
4140 gfc_convert_type (op2
, &e
->ts
, 1);
4141 e
= logical_to_bitwise (e
);
4145 sprintf (msg
, _("Operands of logical operator %%<%s%%> at %%L are %s/%s"),
4146 gfc_op2string (e
->value
.op
.op
), gfc_typename (op1
),
4147 gfc_typename (op2
));
4152 /* Logical ops on integers become bitwise ops with -fdec. */
4153 if (flag_dec
&& op1
->ts
.type
== BT_INTEGER
)
4155 e
->ts
.type
= BT_INTEGER
;
4156 e
->ts
.kind
= op1
->ts
.kind
;
4157 e
= logical_to_bitwise (e
);
4161 if (op1
->ts
.type
== BT_LOGICAL
)
4163 e
->ts
.type
= BT_LOGICAL
;
4164 e
->ts
.kind
= op1
->ts
.kind
;
4168 sprintf (msg
, _("Operand of .not. operator at %%L is %s"),
4169 gfc_typename (op1
));
4173 case INTRINSIC_GT_OS
:
4175 case INTRINSIC_GE_OS
:
4177 case INTRINSIC_LT_OS
:
4179 case INTRINSIC_LE_OS
:
4180 if (op1
->ts
.type
== BT_COMPLEX
|| op2
->ts
.type
== BT_COMPLEX
)
4182 strcpy (msg
, _("COMPLEX quantities cannot be compared at %L"));
4189 case INTRINSIC_EQ_OS
:
4191 case INTRINSIC_NE_OS
:
4194 && is_character_based (op1
->ts
.type
)
4195 && is_character_based (op2
->ts
.type
))
4197 convert_hollerith_to_character (op1
);
4198 convert_hollerith_to_character (op2
);
4201 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
4202 && op1
->ts
.kind
== op2
->ts
.kind
)
4204 e
->ts
.type
= BT_LOGICAL
;
4205 e
->ts
.kind
= gfc_default_logical_kind
;
4209 /* If op1 is BOZ, then op2 is not!. Try to convert to type of op2. */
4210 if (op1
->ts
.type
== BT_BOZ
)
4212 if (gfc_invalid_boz (G_("BOZ literal constant near %L cannot appear "
4213 "as an operand of a relational operator"),
4217 if (op2
->ts
.type
== BT_INTEGER
&& !gfc_boz2int (op1
, op2
->ts
.kind
))
4220 if (op2
->ts
.type
== BT_REAL
&& !gfc_boz2real (op1
, op2
->ts
.kind
))
4224 /* If op2 is BOZ, then op1 is not!. Try to convert to type of op2. */
4225 if (op2
->ts
.type
== BT_BOZ
)
4227 if (gfc_invalid_boz (G_("BOZ literal constant near %L cannot appear"
4228 " as an operand of a relational operator"),
4232 if (op1
->ts
.type
== BT_INTEGER
&& !gfc_boz2int (op2
, op1
->ts
.kind
))
4235 if (op1
->ts
.type
== BT_REAL
&& !gfc_boz2real (op2
, op1
->ts
.kind
))
4239 && op1
->ts
.type
== BT_HOLLERITH
&& gfc_numeric_ts (&op2
->ts
))
4240 convert_to_numeric (op1
, op2
);
4243 && gfc_numeric_ts (&op1
->ts
) && op2
->ts
.type
== BT_HOLLERITH
)
4244 convert_to_numeric (op2
, op1
);
4246 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
4248 gfc_type_convert_binary (e
, 1);
4250 e
->ts
.type
= BT_LOGICAL
;
4251 e
->ts
.kind
= gfc_default_logical_kind
;
4253 if (warn_compare_reals
)
4255 gfc_intrinsic_op op
= e
->value
.op
.op
;
4257 /* Type conversion has made sure that the types of op1 and op2
4258 agree, so it is only necessary to check the first one. */
4259 if ((op1
->ts
.type
== BT_REAL
|| op1
->ts
.type
== BT_COMPLEX
)
4260 && (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
4261 || op
== INTRINSIC_NE
|| op
== INTRINSIC_NE_OS
))
4265 if (op
== INTRINSIC_EQ
|| op
== INTRINSIC_EQ_OS
)
4266 msg
= G_("Equality comparison for %s at %L");
4268 msg
= G_("Inequality comparison for %s at %L");
4270 gfc_warning (OPT_Wcompare_reals
, msg
,
4271 gfc_typename (op1
), &op1
->where
);
4278 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
4280 _("Logicals at %%L must be compared with %s instead of %s"),
4281 (e
->value
.op
.op
== INTRINSIC_EQ
4282 || e
->value
.op
.op
== INTRINSIC_EQ_OS
)
4283 ? ".eqv." : ".neqv.", gfc_op2string (e
->value
.op
.op
));
4286 _("Operands of comparison operator %%<%s%%> at %%L are %s/%s"),
4287 gfc_op2string (e
->value
.op
.op
), gfc_typename (op1
),
4288 gfc_typename (op2
));
4292 case INTRINSIC_USER
:
4293 if (e
->value
.op
.uop
->op
== NULL
)
4295 const char *name
= e
->value
.op
.uop
->name
;
4296 const char *guessed
;
4297 guessed
= lookup_uop_fuzzy (name
, e
->value
.op
.uop
->ns
->uop_root
);
4299 sprintf (msg
, _("Unknown operator %%<%s%%> at %%L; did you mean '%s'?"),
4302 sprintf (msg
, _("Unknown operator %%<%s%%> at %%L"), name
);
4304 else if (op2
== NULL
)
4305 sprintf (msg
, _("Operand of user operator %%<%s%%> at %%L is %s"),
4306 e
->value
.op
.uop
->name
, gfc_typename (op1
));
4309 sprintf (msg
, _("Operands of user operator %%<%s%%> at %%L are %s/%s"),
4310 e
->value
.op
.uop
->name
, gfc_typename (op1
),
4311 gfc_typename (op2
));
4312 e
->value
.op
.uop
->op
->sym
->attr
.referenced
= 1;
4317 case INTRINSIC_PARENTHESES
:
4319 if (e
->ts
.type
== BT_CHARACTER
)
4320 e
->ts
.u
.cl
= op1
->ts
.u
.cl
;
4324 gfc_internal_error ("resolve_operator(): Bad intrinsic");
4327 /* Deal with arrayness of an operand through an operator. */
4329 switch (e
->value
.op
.op
)
4331 case INTRINSIC_PLUS
:
4332 case INTRINSIC_MINUS
:
4333 case INTRINSIC_TIMES
:
4334 case INTRINSIC_DIVIDE
:
4335 case INTRINSIC_POWER
:
4336 case INTRINSIC_CONCAT
:
4340 case INTRINSIC_NEQV
:
4342 case INTRINSIC_EQ_OS
:
4344 case INTRINSIC_NE_OS
:
4346 case INTRINSIC_GT_OS
:
4348 case INTRINSIC_GE_OS
:
4350 case INTRINSIC_LT_OS
:
4352 case INTRINSIC_LE_OS
:
4354 if (op1
->rank
== 0 && op2
->rank
== 0)
4357 if (op1
->rank
== 0 && op2
->rank
!= 0)
4359 e
->rank
= op2
->rank
;
4361 if (e
->shape
== NULL
)
4362 e
->shape
= gfc_copy_shape (op2
->shape
, op2
->rank
);
4365 if (op1
->rank
!= 0 && op2
->rank
== 0)
4367 e
->rank
= op1
->rank
;
4369 if (e
->shape
== NULL
)
4370 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
4373 if (op1
->rank
!= 0 && op2
->rank
!= 0)
4375 if (op1
->rank
== op2
->rank
)
4377 e
->rank
= op1
->rank
;
4378 if (e
->shape
== NULL
)
4380 t
= compare_shapes (op1
, op2
);
4384 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
4389 /* Allow higher level expressions to work. */
4392 /* Try user-defined operators, and otherwise throw an error. */
4393 dual_locus_error
= true;
4395 _("Inconsistent ranks for operator at %%L and %%L"));
4402 case INTRINSIC_PARENTHESES
:
4404 case INTRINSIC_UPLUS
:
4405 case INTRINSIC_UMINUS
:
4406 /* Simply copy arrayness attribute */
4407 e
->rank
= op1
->rank
;
4409 if (e
->shape
== NULL
)
4410 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
4420 /* Attempt to simplify the expression. */
4423 t
= gfc_simplify_expr (e
, 0);
4424 /* Some calls do not succeed in simplification and return false
4425 even though there is no error; e.g. variable references to
4426 PARAMETER arrays. */
4427 if (!gfc_is_constant_expr (e
))
4435 match m
= gfc_extend_expr (e
);
4438 if (m
== MATCH_ERROR
)
4442 if (dual_locus_error
)
4443 gfc_error (msg
, &op1
->where
, &op2
->where
);
4445 gfc_error (msg
, &e
->where
);
4451 /************** Array resolution subroutines **************/
4454 { CMP_LT
, CMP_EQ
, CMP_GT
, CMP_UNKNOWN
};
4456 /* Compare two integer expressions. */
4458 static compare_result
4459 compare_bound (gfc_expr
*a
, gfc_expr
*b
)
4463 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
4464 || b
== NULL
|| b
->expr_type
!= EXPR_CONSTANT
)
4467 /* If either of the types isn't INTEGER, we must have
4468 raised an error earlier. */
4470 if (a
->ts
.type
!= BT_INTEGER
|| b
->ts
.type
!= BT_INTEGER
)
4473 i
= mpz_cmp (a
->value
.integer
, b
->value
.integer
);
4483 /* Compare an integer expression with an integer. */
4485 static compare_result
4486 compare_bound_int (gfc_expr
*a
, int b
)
4490 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
4493 if (a
->ts
.type
!= BT_INTEGER
)
4494 gfc_internal_error ("compare_bound_int(): Bad expression");
4496 i
= mpz_cmp_si (a
->value
.integer
, b
);
4506 /* Compare an integer expression with a mpz_t. */
4508 static compare_result
4509 compare_bound_mpz_t (gfc_expr
*a
, mpz_t b
)
4513 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
4516 if (a
->ts
.type
!= BT_INTEGER
)
4517 gfc_internal_error ("compare_bound_int(): Bad expression");
4519 i
= mpz_cmp (a
->value
.integer
, b
);
4529 /* Compute the last value of a sequence given by a triplet.
4530 Return 0 if it wasn't able to compute the last value, or if the
4531 sequence if empty, and 1 otherwise. */
4534 compute_last_value_for_triplet (gfc_expr
*start
, gfc_expr
*end
,
4535 gfc_expr
*stride
, mpz_t last
)
4539 if (start
== NULL
|| start
->expr_type
!= EXPR_CONSTANT
4540 || end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
4541 || (stride
!= NULL
&& stride
->expr_type
!= EXPR_CONSTANT
))
4544 if (start
->ts
.type
!= BT_INTEGER
|| end
->ts
.type
!= BT_INTEGER
4545 || (stride
!= NULL
&& stride
->ts
.type
!= BT_INTEGER
))
4548 if (stride
== NULL
|| compare_bound_int (stride
, 1) == CMP_EQ
)
4550 if (compare_bound (start
, end
) == CMP_GT
)
4552 mpz_set (last
, end
->value
.integer
);
4556 if (compare_bound_int (stride
, 0) == CMP_GT
)
4558 /* Stride is positive */
4559 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) > 0)
4564 /* Stride is negative */
4565 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) < 0)
4570 mpz_sub (rem
, end
->value
.integer
, start
->value
.integer
);
4571 mpz_tdiv_r (rem
, rem
, stride
->value
.integer
);
4572 mpz_sub (last
, end
->value
.integer
, rem
);
4579 /* Compare a single dimension of an array reference to the array
4583 check_dimension (int i
, gfc_array_ref
*ar
, gfc_array_spec
*as
)
4587 if (ar
->dimen_type
[i
] == DIMEN_STAR
)
4589 gcc_assert (ar
->stride
[i
] == NULL
);
4590 /* This implies [*] as [*:] and [*:3] are not possible. */
4591 if (ar
->start
[i
] == NULL
)
4593 gcc_assert (ar
->end
[i
] == NULL
);
4598 /* Given start, end and stride values, calculate the minimum and
4599 maximum referenced indexes. */
4601 switch (ar
->dimen_type
[i
])
4604 case DIMEN_THIS_IMAGE
:
4609 if (compare_bound (ar
->start
[i
], as
->lower
[i
]) == CMP_LT
)
4612 gfc_warning (0, "Array reference at %L is out of bounds "
4613 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4614 mpz_get_si (ar
->start
[i
]->value
.integer
),
4615 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4617 gfc_warning (0, "Array reference at %L is out of bounds "
4618 "(%ld < %ld) in codimension %d", &ar
->c_where
[i
],
4619 mpz_get_si (ar
->start
[i
]->value
.integer
),
4620 mpz_get_si (as
->lower
[i
]->value
.integer
),
4624 if (compare_bound (ar
->start
[i
], as
->upper
[i
]) == CMP_GT
)
4627 gfc_warning (0, "Array reference at %L is out of bounds "
4628 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4629 mpz_get_si (ar
->start
[i
]->value
.integer
),
4630 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4632 gfc_warning (0, "Array reference at %L is out of bounds "
4633 "(%ld > %ld) in codimension %d", &ar
->c_where
[i
],
4634 mpz_get_si (ar
->start
[i
]->value
.integer
),
4635 mpz_get_si (as
->upper
[i
]->value
.integer
),
4644 #define AR_START (ar->start[i] ? ar->start[i] : as->lower[i])
4645 #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i])
4647 compare_result comp_start_end
= compare_bound (AR_START
, AR_END
);
4649 /* Check for zero stride, which is not allowed. */
4650 if (compare_bound_int (ar
->stride
[i
], 0) == CMP_EQ
)
4652 gfc_error ("Illegal stride of zero at %L", &ar
->c_where
[i
]);
4656 /* if start == len || (stride > 0 && start < len)
4657 || (stride < 0 && start > len),
4658 then the array section contains at least one element. In this
4659 case, there is an out-of-bounds access if
4660 (start < lower || start > upper). */
4661 if (compare_bound (AR_START
, AR_END
) == CMP_EQ
4662 || ((compare_bound_int (ar
->stride
[i
], 0) == CMP_GT
4663 || ar
->stride
[i
] == NULL
) && comp_start_end
== CMP_LT
)
4664 || (compare_bound_int (ar
->stride
[i
], 0) == CMP_LT
4665 && comp_start_end
== CMP_GT
))
4667 if (compare_bound (AR_START
, as
->lower
[i
]) == CMP_LT
)
4669 gfc_warning (0, "Lower array reference at %L is out of bounds "
4670 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4671 mpz_get_si (AR_START
->value
.integer
),
4672 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4675 if (compare_bound (AR_START
, as
->upper
[i
]) == CMP_GT
)
4677 gfc_warning (0, "Lower array reference at %L is out of bounds "
4678 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4679 mpz_get_si (AR_START
->value
.integer
),
4680 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4685 /* If we can compute the highest index of the array section,
4686 then it also has to be between lower and upper. */
4687 mpz_init (last_value
);
4688 if (compute_last_value_for_triplet (AR_START
, AR_END
, ar
->stride
[i
],
4691 if (compare_bound_mpz_t (as
->lower
[i
], last_value
) == CMP_GT
)
4693 gfc_warning (0, "Upper array reference at %L is out of bounds "
4694 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
4695 mpz_get_si (last_value
),
4696 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
4697 mpz_clear (last_value
);
4700 if (compare_bound_mpz_t (as
->upper
[i
], last_value
) == CMP_LT
)
4702 gfc_warning (0, "Upper array reference at %L is out of bounds "
4703 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
4704 mpz_get_si (last_value
),
4705 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
4706 mpz_clear (last_value
);
4710 mpz_clear (last_value
);
4718 gfc_internal_error ("check_dimension(): Bad array reference");
4725 /* Compare an array reference with an array specification. */
4728 compare_spec_to_ref (gfc_array_ref
*ar
)
4735 /* TODO: Full array sections are only allowed as actual parameters. */
4736 if (as
->type
== AS_ASSUMED_SIZE
4737 && (/*ar->type == AR_FULL
4738 ||*/ (ar
->type
== AR_SECTION
4739 && ar
->dimen_type
[i
] == DIMEN_RANGE
&& ar
->end
[i
] == NULL
)))
4741 gfc_error ("Rightmost upper bound of assumed size array section "
4742 "not specified at %L", &ar
->where
);
4746 if (ar
->type
== AR_FULL
)
4749 if (as
->rank
!= ar
->dimen
)
4751 gfc_error ("Rank mismatch in array reference at %L (%d/%d)",
4752 &ar
->where
, ar
->dimen
, as
->rank
);
4756 /* ar->codimen == 0 is a local array. */
4757 if (as
->corank
!= ar
->codimen
&& ar
->codimen
!= 0)
4759 gfc_error ("Coindex rank mismatch in array reference at %L (%d/%d)",
4760 &ar
->where
, ar
->codimen
, as
->corank
);
4764 for (i
= 0; i
< as
->rank
; i
++)
4765 if (!check_dimension (i
, ar
, as
))
4768 /* Local access has no coarray spec. */
4769 if (ar
->codimen
!= 0)
4770 for (i
= as
->rank
; i
< as
->rank
+ as
->corank
; i
++)
4772 if (ar
->dimen_type
[i
] != DIMEN_ELEMENT
&& !ar
->in_allocate
4773 && ar
->dimen_type
[i
] != DIMEN_THIS_IMAGE
)
4775 gfc_error ("Coindex of codimension %d must be a scalar at %L",
4776 i
+ 1 - as
->rank
, &ar
->where
);
4779 if (!check_dimension (i
, ar
, as
))
4787 /* Resolve one part of an array index. */
4790 gfc_resolve_index_1 (gfc_expr
*index
, int check_scalar
,
4791 int force_index_integer_kind
)
4798 if (!gfc_resolve_expr (index
))
4801 if (check_scalar
&& index
->rank
!= 0)
4803 gfc_error ("Array index at %L must be scalar", &index
->where
);
4807 if (index
->ts
.type
!= BT_INTEGER
&& index
->ts
.type
!= BT_REAL
)
4809 gfc_error ("Array index at %L must be of INTEGER type, found %s",
4810 &index
->where
, gfc_basic_typename (index
->ts
.type
));
4814 if (index
->ts
.type
== BT_REAL
)
4815 if (!gfc_notify_std (GFC_STD_LEGACY
, "REAL array index at %L",
4819 if ((index
->ts
.kind
!= gfc_index_integer_kind
4820 && force_index_integer_kind
)
4821 || index
->ts
.type
!= BT_INTEGER
)
4824 ts
.type
= BT_INTEGER
;
4825 ts
.kind
= gfc_index_integer_kind
;
4827 gfc_convert_type_warn (index
, &ts
, 2, 0);
4833 /* Resolve one part of an array index. */
4836 gfc_resolve_index (gfc_expr
*index
, int check_scalar
)
4838 return gfc_resolve_index_1 (index
, check_scalar
, 1);
4841 /* Resolve a dim argument to an intrinsic function. */
4844 gfc_resolve_dim_arg (gfc_expr
*dim
)
4849 if (!gfc_resolve_expr (dim
))
4854 gfc_error ("Argument dim at %L must be scalar", &dim
->where
);
4859 if (dim
->ts
.type
!= BT_INTEGER
)
4861 gfc_error ("Argument dim at %L must be of INTEGER type", &dim
->where
);
4865 if (dim
->ts
.kind
!= gfc_index_integer_kind
)
4870 ts
.type
= BT_INTEGER
;
4871 ts
.kind
= gfc_index_integer_kind
;
4873 gfc_convert_type_warn (dim
, &ts
, 2, 0);
4879 /* Given an expression that contains array references, update those array
4880 references to point to the right array specifications. While this is
4881 filled in during matching, this information is difficult to save and load
4882 in a module, so we take care of it here.
4884 The idea here is that the original array reference comes from the
4885 base symbol. We traverse the list of reference structures, setting
4886 the stored reference to references. Component references can
4887 provide an additional array specification. */
4890 find_array_spec (gfc_expr
*e
)
4895 bool class_as
= false;
4897 if (e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
)
4899 as
= CLASS_DATA (e
->symtree
->n
.sym
)->as
;
4903 as
= e
->symtree
->n
.sym
->as
;
4905 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4910 gfc_internal_error ("find_array_spec(): Missing spec");
4917 c
= ref
->u
.c
.component
;
4918 if (c
->attr
.dimension
)
4920 if (as
!= NULL
&& !(class_as
&& as
== c
->as
))
4921 gfc_internal_error ("find_array_spec(): unused as(1)");
4933 gfc_internal_error ("find_array_spec(): unused as(2)");
4937 /* Resolve an array reference. */
4940 resolve_array_ref (gfc_array_ref
*ar
)
4942 int i
, check_scalar
;
4945 for (i
= 0; i
< ar
->dimen
+ ar
->codimen
; i
++)
4947 check_scalar
= ar
->dimen_type
[i
] == DIMEN_RANGE
;
4949 /* Do not force gfc_index_integer_kind for the start. We can
4950 do fine with any integer kind. This avoids temporary arrays
4951 created for indexing with a vector. */
4952 if (!gfc_resolve_index_1 (ar
->start
[i
], check_scalar
, 0))
4954 if (!gfc_resolve_index (ar
->end
[i
], check_scalar
))
4956 if (!gfc_resolve_index (ar
->stride
[i
], check_scalar
))
4961 if (ar
->dimen_type
[i
] == DIMEN_UNKNOWN
)
4965 ar
->dimen_type
[i
] = DIMEN_ELEMENT
;
4969 ar
->dimen_type
[i
] = DIMEN_VECTOR
;
4970 if (e
->expr_type
== EXPR_VARIABLE
4971 && e
->symtree
->n
.sym
->ts
.type
== BT_DERIVED
)
4972 ar
->start
[i
] = gfc_get_parentheses (e
);
4976 gfc_error ("Array index at %L is an array of rank %d",
4977 &ar
->c_where
[i
], e
->rank
);
4981 /* Fill in the upper bound, which may be lower than the
4982 specified one for something like a(2:10:5), which is
4983 identical to a(2:7:5). Only relevant for strides not equal
4984 to one. Don't try a division by zero. */
4985 if (ar
->dimen_type
[i
] == DIMEN_RANGE
4986 && ar
->stride
[i
] != NULL
&& ar
->stride
[i
]->expr_type
== EXPR_CONSTANT
4987 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 1L) != 0
4988 && mpz_cmp_si (ar
->stride
[i
]->value
.integer
, 0L) != 0)
4992 if (gfc_ref_dimen_size (ar
, i
, &size
, &end
))
4994 if (ar
->end
[i
] == NULL
)
4997 gfc_get_constant_expr (BT_INTEGER
, gfc_index_integer_kind
,
4999 mpz_set (ar
->end
[i
]->value
.integer
, end
);
5001 else if (ar
->end
[i
]->ts
.type
== BT_INTEGER
5002 && ar
->end
[i
]->expr_type
== EXPR_CONSTANT
)
5004 mpz_set (ar
->end
[i
]->value
.integer
, end
);
5015 if (ar
->type
== AR_FULL
)
5017 if (ar
->as
->rank
== 0)
5018 ar
->type
= AR_ELEMENT
;
5020 /* Make sure array is the same as array(:,:), this way
5021 we don't need to special case all the time. */
5022 ar
->dimen
= ar
->as
->rank
;
5023 for (i
= 0; i
< ar
->dimen
; i
++)
5025 ar
->dimen_type
[i
] = DIMEN_RANGE
;
5027 gcc_assert (ar
->start
[i
] == NULL
);
5028 gcc_assert (ar
->end
[i
] == NULL
);
5029 gcc_assert (ar
->stride
[i
] == NULL
);
5033 /* If the reference type is unknown, figure out what kind it is. */
5035 if (ar
->type
== AR_UNKNOWN
)
5037 ar
->type
= AR_ELEMENT
;
5038 for (i
= 0; i
< ar
->dimen
; i
++)
5039 if (ar
->dimen_type
[i
] == DIMEN_RANGE
5040 || ar
->dimen_type
[i
] == DIMEN_VECTOR
)
5042 ar
->type
= AR_SECTION
;
5047 if (!ar
->as
->cray_pointee
&& !compare_spec_to_ref (ar
))
5050 if (ar
->as
->corank
&& ar
->codimen
== 0)
5053 ar
->codimen
= ar
->as
->corank
;
5054 for (n
= ar
->dimen
; n
< ar
->dimen
+ ar
->codimen
; n
++)
5055 ar
->dimen_type
[n
] = DIMEN_THIS_IMAGE
;
5063 resolve_substring (gfc_ref
*ref
, bool *equal_length
)
5065 int k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
5067 if (ref
->u
.ss
.start
!= NULL
)
5069 if (!gfc_resolve_expr (ref
->u
.ss
.start
))
5072 if (ref
->u
.ss
.start
->ts
.type
!= BT_INTEGER
)
5074 gfc_error ("Substring start index at %L must be of type INTEGER",
5075 &ref
->u
.ss
.start
->where
);
5079 if (ref
->u
.ss
.start
->rank
!= 0)
5081 gfc_error ("Substring start index at %L must be scalar",
5082 &ref
->u
.ss
.start
->where
);
5086 if (compare_bound_int (ref
->u
.ss
.start
, 1) == CMP_LT
5087 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
5088 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
5090 gfc_error ("Substring start index at %L is less than one",
5091 &ref
->u
.ss
.start
->where
);
5096 if (ref
->u
.ss
.end
!= NULL
)
5098 if (!gfc_resolve_expr (ref
->u
.ss
.end
))
5101 if (ref
->u
.ss
.end
->ts
.type
!= BT_INTEGER
)
5103 gfc_error ("Substring end index at %L must be of type INTEGER",
5104 &ref
->u
.ss
.end
->where
);
5108 if (ref
->u
.ss
.end
->rank
!= 0)
5110 gfc_error ("Substring end index at %L must be scalar",
5111 &ref
->u
.ss
.end
->where
);
5115 if (ref
->u
.ss
.length
!= NULL
5116 && compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.length
->length
) == CMP_GT
5117 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
5118 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
5120 gfc_error ("Substring end index at %L exceeds the string length",
5121 &ref
->u
.ss
.start
->where
);
5125 if (compare_bound_mpz_t (ref
->u
.ss
.end
,
5126 gfc_integer_kinds
[k
].huge
) == CMP_GT
5127 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
5128 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
5130 gfc_error ("Substring end index at %L is too large",
5131 &ref
->u
.ss
.end
->where
);
5134 /* If the substring has the same length as the original
5135 variable, the reference itself can be deleted. */
5137 if (ref
->u
.ss
.length
!= NULL
5138 && compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.length
->length
) == CMP_EQ
5139 && compare_bound_int (ref
->u
.ss
.start
, 1) == CMP_EQ
)
5140 *equal_length
= true;
5147 /* This function supplies missing substring charlens. */
5150 gfc_resolve_substring_charlen (gfc_expr
*e
)
5153 gfc_expr
*start
, *end
;
5154 gfc_typespec
*ts
= NULL
;
5157 for (char_ref
= e
->ref
; char_ref
; char_ref
= char_ref
->next
)
5159 if (char_ref
->type
== REF_SUBSTRING
|| char_ref
->type
== REF_INQUIRY
)
5161 if (char_ref
->type
== REF_COMPONENT
)
5162 ts
= &char_ref
->u
.c
.component
->ts
;
5165 if (!char_ref
|| char_ref
->type
== REF_INQUIRY
)
5168 gcc_assert (char_ref
->next
== NULL
);
5172 if (e
->ts
.u
.cl
->length
)
5173 gfc_free_expr (e
->ts
.u
.cl
->length
);
5174 else if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.dummy
)
5179 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
5181 if (char_ref
->u
.ss
.start
)
5182 start
= gfc_copy_expr (char_ref
->u
.ss
.start
);
5184 start
= gfc_get_int_expr (gfc_charlen_int_kind
, NULL
, 1);
5186 if (char_ref
->u
.ss
.end
)
5187 end
= gfc_copy_expr (char_ref
->u
.ss
.end
);
5188 else if (e
->expr_type
== EXPR_VARIABLE
)
5191 ts
= &e
->symtree
->n
.sym
->ts
;
5192 end
= gfc_copy_expr (ts
->u
.cl
->length
);
5199 gfc_free_expr (start
);
5200 gfc_free_expr (end
);
5204 /* Length = (end - start + 1).
5205 Check first whether it has a constant length. */
5206 if (gfc_dep_difference (end
, start
, &diff
))
5208 gfc_expr
*len
= gfc_get_constant_expr (BT_INTEGER
, gfc_charlen_int_kind
,
5211 mpz_add_ui (len
->value
.integer
, diff
, 1);
5213 e
->ts
.u
.cl
->length
= len
;
5214 /* The check for length < 0 is handled below */
5218 e
->ts
.u
.cl
->length
= gfc_subtract (end
, start
);
5219 e
->ts
.u
.cl
->length
= gfc_add (e
->ts
.u
.cl
->length
,
5220 gfc_get_int_expr (gfc_charlen_int_kind
,
5224 /* F2008, 6.4.1: Both the starting point and the ending point shall
5225 be within the range 1, 2, ..., n unless the starting point exceeds
5226 the ending point, in which case the substring has length zero. */
5228 if (mpz_cmp_si (e
->ts
.u
.cl
->length
->value
.integer
, 0) < 0)
5229 mpz_set_si (e
->ts
.u
.cl
->length
->value
.integer
, 0);
5231 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
5232 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
5234 /* Make sure that the length is simplified. */
5235 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 1);
5236 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
5240 /* Resolve subtype references. */
5243 gfc_resolve_ref (gfc_expr
*expr
)
5245 int current_part_dimension
, n_components
, seen_part_dimension
, dim
;
5246 gfc_ref
*ref
, **prev
, *array_ref
;
5249 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
5250 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.as
== NULL
)
5252 find_array_spec (expr
);
5256 for (prev
= &expr
->ref
; *prev
!= NULL
;
5257 prev
= *prev
== NULL
? prev
: &(*prev
)->next
)
5258 switch ((*prev
)->type
)
5261 if (!resolve_array_ref (&(*prev
)->u
.ar
))
5270 equal_length
= false;
5271 if (!resolve_substring (*prev
, &equal_length
))
5274 if (expr
->expr_type
!= EXPR_SUBSTRING
&& equal_length
)
5276 /* Remove the reference and move the charlen, if any. */
5280 expr
->ts
.u
.cl
= ref
->u
.ss
.length
;
5281 ref
->u
.ss
.length
= NULL
;
5282 gfc_free_ref_list (ref
);
5287 /* Check constraints on part references. */
5289 current_part_dimension
= 0;
5290 seen_part_dimension
= 0;
5294 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
5300 switch (ref
->u
.ar
.type
)
5303 /* Coarray scalar. */
5304 if (ref
->u
.ar
.as
->rank
== 0)
5306 current_part_dimension
= 0;
5311 current_part_dimension
= 1;
5316 current_part_dimension
= 0;
5320 gfc_internal_error ("resolve_ref(): Bad array reference");
5326 if (current_part_dimension
|| seen_part_dimension
)
5329 if (ref
->u
.c
.component
->attr
.pointer
5330 || ref
->u
.c
.component
->attr
.proc_pointer
5331 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
5332 && CLASS_DATA (ref
->u
.c
.component
)->attr
.pointer
))
5334 gfc_error ("Component to the right of a part reference "
5335 "with nonzero rank must not have the POINTER "
5336 "attribute at %L", &expr
->where
);
5339 else if (ref
->u
.c
.component
->attr
.allocatable
5340 || (ref
->u
.c
.component
->ts
.type
== BT_CLASS
5341 && CLASS_DATA (ref
->u
.c
.component
)->attr
.allocatable
))
5344 gfc_error ("Component to the right of a part reference "
5345 "with nonzero rank must not have the ALLOCATABLE "
5346 "attribute at %L", &expr
->where
);
5358 /* Implement requirement in note 9.7 of F2018 that the result of the
5359 LEN inquiry be a scalar. */
5360 if (ref
->u
.i
== INQUIRY_LEN
&& array_ref
&& expr
->ts
.deferred
)
5362 array_ref
->u
.ar
.type
= AR_ELEMENT
;
5364 /* INQUIRY_LEN is not evaluated from the rest of the expr
5365 but directly from the string length. This means that setting
5366 the array indices to one does not matter but might trigger
5367 a runtime bounds error. Suppress the check. */
5368 expr
->no_bounds_check
= 1;
5369 for (dim
= 0; dim
< array_ref
->u
.ar
.dimen
; dim
++)
5371 array_ref
->u
.ar
.dimen_type
[dim
] = DIMEN_ELEMENT
;
5372 if (array_ref
->u
.ar
.start
[dim
])
5373 gfc_free_expr (array_ref
->u
.ar
.start
[dim
]);
5374 array_ref
->u
.ar
.start
[dim
]
5375 = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
5376 if (array_ref
->u
.ar
.end
[dim
])
5377 gfc_free_expr (array_ref
->u
.ar
.end
[dim
]);
5378 if (array_ref
->u
.ar
.stride
[dim
])
5379 gfc_free_expr (array_ref
->u
.ar
.stride
[dim
]);
5385 if (((ref
->type
== REF_COMPONENT
&& n_components
> 1)
5386 || ref
->next
== NULL
)
5387 && current_part_dimension
5388 && seen_part_dimension
)
5390 gfc_error ("Two or more part references with nonzero rank must "
5391 "not be specified at %L", &expr
->where
);
5395 if (ref
->type
== REF_COMPONENT
)
5397 if (current_part_dimension
)
5398 seen_part_dimension
= 1;
5400 /* reset to make sure */
5401 current_part_dimension
= 0;
5409 /* Given an expression, determine its shape. This is easier than it sounds.
5410 Leaves the shape array NULL if it is not possible to determine the shape. */
5413 expression_shape (gfc_expr
*e
)
5415 mpz_t array
[GFC_MAX_DIMENSIONS
];
5418 if (e
->rank
<= 0 || e
->shape
!= NULL
)
5421 for (i
= 0; i
< e
->rank
; i
++)
5422 if (!gfc_array_dimen_size (e
, i
, &array
[i
]))
5425 e
->shape
= gfc_get_shape (e
->rank
);
5427 memcpy (e
->shape
, array
, e
->rank
* sizeof (mpz_t
));
5432 for (i
--; i
>= 0; i
--)
5433 mpz_clear (array
[i
]);
5437 /* Given a variable expression node, compute the rank of the expression by
5438 examining the base symbol and any reference structures it may have. */
5441 gfc_expression_rank (gfc_expr
*e
)
5446 /* Just to make sure, because EXPR_COMPCALL's also have an e->ref and that
5447 could lead to serious confusion... */
5448 gcc_assert (e
->expr_type
!= EXPR_COMPCALL
);
5452 if (e
->expr_type
== EXPR_ARRAY
)
5454 /* Constructors can have a rank different from one via RESHAPE(). */
5456 e
->rank
= ((e
->symtree
== NULL
|| e
->symtree
->n
.sym
->as
== NULL
)
5457 ? 0 : e
->symtree
->n
.sym
->as
->rank
);
5463 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5465 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.proc_pointer
5466 && ref
->u
.c
.component
->attr
.function
&& !ref
->next
)
5467 rank
= ref
->u
.c
.component
->as
? ref
->u
.c
.component
->as
->rank
: 0;
5469 if (ref
->type
!= REF_ARRAY
)
5472 if (ref
->u
.ar
.type
== AR_FULL
)
5474 rank
= ref
->u
.ar
.as
->rank
;
5478 if (ref
->u
.ar
.type
== AR_SECTION
)
5480 /* Figure out the rank of the section. */
5482 gfc_internal_error ("gfc_expression_rank(): Two array specs");
5484 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
5485 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_RANGE
5486 || ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
5496 expression_shape (e
);
5501 add_caf_get_intrinsic (gfc_expr
*e
)
5503 gfc_expr
*wrapper
, *tmp_expr
;
5507 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5508 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
5513 for (n
= ref
->u
.ar
.dimen
; n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
5514 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_ELEMENT
)
5517 tmp_expr
= XCNEW (gfc_expr
);
5519 wrapper
= gfc_build_intrinsic_call (gfc_current_ns
, GFC_ISYM_CAF_GET
,
5520 "caf_get", tmp_expr
->where
, 1, tmp_expr
);
5521 wrapper
->ts
= e
->ts
;
5522 wrapper
->rank
= e
->rank
;
5524 wrapper
->shape
= gfc_copy_shape (e
->shape
, e
->rank
);
5531 remove_caf_get_intrinsic (gfc_expr
*e
)
5533 gcc_assert (e
->expr_type
== EXPR_FUNCTION
&& e
->value
.function
.isym
5534 && e
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
);
5535 gfc_expr
*e2
= e
->value
.function
.actual
->expr
;
5536 e
->value
.function
.actual
->expr
= NULL
;
5537 gfc_free_actual_arglist (e
->value
.function
.actual
);
5538 gfc_free_shape (&e
->shape
, e
->rank
);
5544 /* Resolve a variable expression. */
5547 resolve_variable (gfc_expr
*e
)
5554 if (e
->symtree
== NULL
)
5556 sym
= e
->symtree
->n
.sym
;
5558 /* Use same check as for TYPE(*) below; this check has to be before TYPE(*)
5559 as ts.type is set to BT_ASSUMED in resolve_symbol. */
5560 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
5562 if (!actual_arg
|| inquiry_argument
)
5564 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may only "
5565 "be used as actual argument", sym
->name
, &e
->where
);
5569 /* TS 29113, 407b. */
5570 else if (e
->ts
.type
== BT_ASSUMED
)
5574 gfc_error ("Assumed-type variable %s at %L may only be used "
5575 "as actual argument", sym
->name
, &e
->where
);
5578 else if (inquiry_argument
&& !first_actual_arg
)
5580 /* FIXME: It doesn't work reliably as inquiry_argument is not set
5581 for all inquiry functions in resolve_function; the reason is
5582 that the function-name resolution happens too late in that
5584 gfc_error ("Assumed-type variable %s at %L as actual argument to "
5585 "an inquiry function shall be the first argument",
5586 sym
->name
, &e
->where
);
5590 /* TS 29113, C535b. */
5591 else if (((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
5592 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
5593 && CLASS_DATA (sym
)->as
5594 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
5595 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
5596 && sym
->as
->type
== AS_ASSUMED_RANK
))
5597 && !sym
->attr
.select_rank_temporary
)
5600 && !(cs_base
&& cs_base
->current
5601 && cs_base
->current
->op
== EXEC_SELECT_RANK
))
5603 gfc_error ("Assumed-rank variable %s at %L may only be used as "
5604 "actual argument", sym
->name
, &e
->where
);
5607 else if (inquiry_argument
&& !first_actual_arg
)
5609 /* FIXME: It doesn't work reliably as inquiry_argument is not set
5610 for all inquiry functions in resolve_function; the reason is
5611 that the function-name resolution happens too late in that
5613 gfc_error ("Assumed-rank variable %s at %L as actual argument "
5614 "to an inquiry function shall be the first argument",
5615 sym
->name
, &e
->where
);
5620 if ((sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
)) && e
->ref
5621 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
5622 && e
->ref
->next
== NULL
))
5624 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall not have "
5625 "a subobject reference", sym
->name
, &e
->ref
->u
.ar
.where
);
5628 /* TS 29113, 407b. */
5629 else if (e
->ts
.type
== BT_ASSUMED
&& e
->ref
5630 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
5631 && e
->ref
->next
== NULL
))
5633 gfc_error ("Assumed-type variable %s at %L shall not have a subobject "
5634 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
5638 /* TS 29113, C535b. */
5639 if (((sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
5640 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
5641 && CLASS_DATA (sym
)->as
5642 && CLASS_DATA (sym
)->as
->type
== AS_ASSUMED_RANK
)
5643 || (sym
->ts
.type
!= BT_CLASS
&& sym
->as
5644 && sym
->as
->type
== AS_ASSUMED_RANK
))
5646 && !(e
->ref
->type
== REF_ARRAY
&& e
->ref
->u
.ar
.type
== AR_FULL
5647 && e
->ref
->next
== NULL
))
5649 gfc_error ("Assumed-rank variable %s at %L shall not have a subobject "
5650 "reference", sym
->name
, &e
->ref
->u
.ar
.where
);
5654 /* For variables that are used in an associate (target => object) where
5655 the object's basetype is array valued while the target is scalar,
5656 the ts' type of the component refs is still array valued, which
5657 can't be translated that way. */
5658 if (sym
->assoc
&& e
->rank
== 0 && e
->ref
&& sym
->ts
.type
== BT_CLASS
5659 && sym
->assoc
->target
&& sym
->assoc
->target
->ts
.type
== BT_CLASS
5660 && CLASS_DATA (sym
->assoc
->target
)->as
)
5662 gfc_ref
*ref
= e
->ref
;
5668 ref
->u
.c
.sym
= sym
->ts
.u
.derived
;
5669 /* Stop the loop. */
5679 /* If this is an associate-name, it may be parsed with an array reference
5680 in error even though the target is scalar. Fail directly in this case.
5681 TODO Understand why class scalar expressions must be excluded. */
5682 if (sym
->assoc
&& !(sym
->ts
.type
== BT_CLASS
&& e
->rank
== 0))
5684 if (sym
->ts
.type
== BT_CLASS
)
5685 gfc_fix_class_refs (e
);
5686 if (!sym
->attr
.dimension
&& e
->ref
&& e
->ref
->type
== REF_ARRAY
)
5688 else if (sym
->attr
.dimension
&& (!e
->ref
|| e
->ref
->type
!= REF_ARRAY
))
5690 /* This can happen because the parser did not detect that the
5691 associate name is an array and the expression had no array
5693 gfc_ref
*ref
= gfc_get_ref ();
5694 ref
->type
= REF_ARRAY
;
5695 ref
->u
.ar
= *gfc_get_array_ref();
5696 ref
->u
.ar
.type
= AR_FULL
;
5699 ref
->u
.ar
.as
= sym
->as
;
5700 ref
->u
.ar
.dimen
= sym
->as
->rank
;
5708 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.generic
)
5709 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
5711 /* On the other hand, the parser may not have known this is an array;
5712 in this case, we have to add a FULL reference. */
5713 if (sym
->assoc
&& sym
->attr
.dimension
&& !e
->ref
)
5715 e
->ref
= gfc_get_ref ();
5716 e
->ref
->type
= REF_ARRAY
;
5717 e
->ref
->u
.ar
.type
= AR_FULL
;
5718 e
->ref
->u
.ar
.dimen
= 0;
5721 /* Like above, but for class types, where the checking whether an array
5722 ref is present is more complicated. Furthermore make sure not to add
5723 the full array ref to _vptr or _len refs. */
5724 if (sym
->assoc
&& sym
->ts
.type
== BT_CLASS
5725 && CLASS_DATA (sym
)->attr
.dimension
5726 && (e
->ts
.type
!= BT_DERIVED
|| !e
->ts
.u
.derived
->attr
.vtype
))
5728 gfc_ref
*ref
, *newref
;
5730 newref
= gfc_get_ref ();
5731 newref
->type
= REF_ARRAY
;
5732 newref
->u
.ar
.type
= AR_FULL
;
5733 newref
->u
.ar
.dimen
= 0;
5734 /* Because this is an associate var and the first ref either is a ref to
5735 the _data component or not, no traversal of the ref chain is
5736 needed. The array ref needs to be inserted after the _data ref,
5737 or when that is not present, which may happend for polymorphic
5738 types, then at the first position. */
5742 else if (ref
->type
== REF_COMPONENT
5743 && strcmp ("_data", ref
->u
.c
.component
->name
) == 0)
5745 if (!ref
->next
|| ref
->next
->type
!= REF_ARRAY
)
5747 newref
->next
= ref
->next
;
5751 /* Array ref present already. */
5752 gfc_free_ref_list (newref
);
5754 else if (ref
->type
== REF_ARRAY
)
5755 /* Array ref present already. */
5756 gfc_free_ref_list (newref
);
5764 if (e
->ref
&& !gfc_resolve_ref (e
))
5767 if (sym
->attr
.flavor
== FL_PROCEDURE
5768 && (!sym
->attr
.function
5769 || (sym
->attr
.function
&& sym
->result
5770 && sym
->result
->attr
.proc_pointer
5771 && !sym
->result
->attr
.function
)))
5773 e
->ts
.type
= BT_PROCEDURE
;
5774 goto resolve_procedure
;
5777 if (sym
->ts
.type
!= BT_UNKNOWN
)
5778 gfc_variable_attr (e
, &e
->ts
);
5779 else if (sym
->attr
.flavor
== FL_PROCEDURE
5780 && sym
->attr
.function
&& sym
->result
5781 && sym
->result
->ts
.type
!= BT_UNKNOWN
5782 && sym
->result
->attr
.proc_pointer
)
5783 e
->ts
= sym
->result
->ts
;
5786 /* Must be a simple variable reference. */
5787 if (!gfc_set_default_type (sym
, 1, sym
->ns
))
5792 if (check_assumed_size_reference (sym
, e
))
5795 /* Deal with forward references to entries during gfc_resolve_code, to
5796 satisfy, at least partially, 12.5.2.5. */
5797 if (gfc_current_ns
->entries
5798 && current_entry_id
== sym
->entry_id
5801 && cs_base
->current
->op
!= EXEC_ENTRY
)
5803 gfc_entry_list
*entry
;
5804 gfc_formal_arglist
*formal
;
5806 bool seen
, saved_specification_expr
;
5808 /* If the symbol is a dummy... */
5809 if (sym
->attr
.dummy
&& sym
->ns
== gfc_current_ns
)
5811 entry
= gfc_current_ns
->entries
;
5814 /* ...test if the symbol is a parameter of previous entries. */
5815 for (; entry
&& entry
->id
<= current_entry_id
; entry
= entry
->next
)
5816 for (formal
= entry
->sym
->formal
; formal
; formal
= formal
->next
)
5818 if (formal
->sym
&& sym
->name
== formal
->sym
->name
)
5825 /* If it has not been seen as a dummy, this is an error. */
5828 if (specification_expr
)
5829 gfc_error ("Variable %qs, used in a specification expression"
5830 ", is referenced at %L before the ENTRY statement "
5831 "in which it is a parameter",
5832 sym
->name
, &cs_base
->current
->loc
);
5834 gfc_error ("Variable %qs is used at %L before the ENTRY "
5835 "statement in which it is a parameter",
5836 sym
->name
, &cs_base
->current
->loc
);
5841 /* Now do the same check on the specification expressions. */
5842 saved_specification_expr
= specification_expr
;
5843 specification_expr
= true;
5844 if (sym
->ts
.type
== BT_CHARACTER
5845 && !gfc_resolve_expr (sym
->ts
.u
.cl
->length
))
5849 for (n
= 0; n
< sym
->as
->rank
; n
++)
5851 if (!gfc_resolve_expr (sym
->as
->lower
[n
]))
5853 if (!gfc_resolve_expr (sym
->as
->upper
[n
]))
5856 specification_expr
= saved_specification_expr
;
5859 /* Update the symbol's entry level. */
5860 sym
->entry_id
= current_entry_id
+ 1;
5863 /* If a symbol has been host_associated mark it. This is used latter,
5864 to identify if aliasing is possible via host association. */
5865 if (sym
->attr
.flavor
== FL_VARIABLE
5866 && gfc_current_ns
->parent
5867 && (gfc_current_ns
->parent
== sym
->ns
5868 || (gfc_current_ns
->parent
->parent
5869 && gfc_current_ns
->parent
->parent
== sym
->ns
)))
5870 sym
->attr
.host_assoc
= 1;
5872 if (gfc_current_ns
->proc_name
5873 && sym
->attr
.dimension
5874 && (sym
->ns
!= gfc_current_ns
5875 || sym
->attr
.use_assoc
5876 || sym
->attr
.in_common
))
5877 gfc_current_ns
->proc_name
->attr
.array_outer_dependency
= 1;
5880 if (t
&& !resolve_procedure_expression (e
))
5883 /* F2008, C617 and C1229. */
5884 if (!inquiry_argument
&& (e
->ts
.type
== BT_CLASS
|| e
->ts
.type
== BT_DERIVED
)
5885 && gfc_is_coindexed (e
))
5887 gfc_ref
*ref
, *ref2
= NULL
;
5889 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5891 if (ref
->type
== REF_COMPONENT
)
5893 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.codimen
> 0)
5897 for ( ; ref
; ref
= ref
->next
)
5898 if (ref
->type
== REF_COMPONENT
)
5901 /* Expression itself is not coindexed object. */
5902 if (ref
&& e
->ts
.type
== BT_CLASS
)
5904 gfc_error ("Polymorphic subobject of coindexed object at %L",
5909 /* Expression itself is coindexed object. */
5913 c
= ref2
? ref2
->u
.c
.component
: e
->symtree
->n
.sym
->components
;
5914 for ( ; c
; c
= c
->next
)
5915 if (c
->attr
.allocatable
&& c
->ts
.type
== BT_CLASS
)
5917 gfc_error ("Coindexed object with polymorphic allocatable "
5918 "subcomponent at %L", &e
->where
);
5926 gfc_expression_rank (e
);
5928 if (t
&& flag_coarray
== GFC_FCOARRAY_LIB
&& gfc_is_coindexed (e
))
5929 add_caf_get_intrinsic (e
);
5931 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_DEPRECATED
) && sym
!= sym
->result
)
5932 gfc_warning (OPT_Wdeprecated_declarations
,
5933 "Using variable %qs at %L is deprecated",
5934 sym
->name
, &e
->where
);
5935 /* Simplify cases where access to a parameter array results in a
5936 single constant. Suppress errors since those will have been
5937 issued before, as warnings. */
5938 if (e
->rank
== 0 && sym
->as
&& sym
->attr
.flavor
== FL_PARAMETER
)
5940 gfc_push_suppress_errors ();
5941 gfc_simplify_expr (e
, 1);
5942 gfc_pop_suppress_errors ();
5949 /* Checks to see that the correct symbol has been host associated.
5950 The only situation where this arises is that in which a twice
5951 contained function is parsed after the host association is made.
5952 Therefore, on detecting this, change the symbol in the expression
5953 and convert the array reference into an actual arglist if the old
5954 symbol is a variable. */
5956 check_host_association (gfc_expr
*e
)
5958 gfc_symbol
*sym
, *old_sym
;
5962 gfc_actual_arglist
*arg
, *tail
= NULL
;
5963 bool retval
= e
->expr_type
== EXPR_FUNCTION
;
5965 /* If the expression is the result of substitution in
5966 interface.c(gfc_extend_expr) because there is no way in
5967 which the host association can be wrong. */
5968 if (e
->symtree
== NULL
5969 || e
->symtree
->n
.sym
== NULL
5970 || e
->user_operator
)
5973 old_sym
= e
->symtree
->n
.sym
;
5975 if (gfc_current_ns
->parent
5976 && old_sym
->ns
!= gfc_current_ns
)
5978 /* Use the 'USE' name so that renamed module symbols are
5979 correctly handled. */
5980 gfc_find_symbol (e
->symtree
->name
, gfc_current_ns
, 1, &sym
);
5982 if (sym
&& old_sym
!= sym
5983 && sym
->ts
.type
== old_sym
->ts
.type
5984 && sym
->attr
.flavor
== FL_PROCEDURE
5985 && sym
->attr
.contained
)
5987 /* Clear the shape, since it might not be valid. */
5988 gfc_free_shape (&e
->shape
, e
->rank
);
5990 /* Give the expression the right symtree! */
5991 gfc_find_sym_tree (e
->symtree
->name
, NULL
, 1, &st
);
5992 gcc_assert (st
!= NULL
);
5994 if (old_sym
->attr
.flavor
== FL_PROCEDURE
5995 || e
->expr_type
== EXPR_FUNCTION
)
5997 /* Original was function so point to the new symbol, since
5998 the actual argument list is already attached to the
6000 e
->value
.function
.esym
= NULL
;
6005 /* Original was variable so convert array references into
6006 an actual arglist. This does not need any checking now
6007 since resolve_function will take care of it. */
6008 e
->value
.function
.actual
= NULL
;
6009 e
->expr_type
= EXPR_FUNCTION
;
6012 /* Ambiguity will not arise if the array reference is not
6013 the last reference. */
6014 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6015 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
6018 if ((ref
== NULL
|| ref
->type
!= REF_ARRAY
)
6019 && sym
->attr
.proc
== PROC_INTERNAL
)
6021 gfc_error ("%qs at %L is host associated at %L into "
6022 "a contained procedure with an internal "
6023 "procedure of the same name", sym
->name
,
6024 &old_sym
->declared_at
, &e
->where
);
6028 gcc_assert (ref
->type
== REF_ARRAY
);
6030 /* Grab the start expressions from the array ref and
6031 copy them into actual arguments. */
6032 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
6034 arg
= gfc_get_actual_arglist ();
6035 arg
->expr
= gfc_copy_expr (ref
->u
.ar
.start
[n
]);
6036 if (e
->value
.function
.actual
== NULL
)
6037 tail
= e
->value
.function
.actual
= arg
;
6045 /* Dump the reference list and set the rank. */
6046 gfc_free_ref_list (e
->ref
);
6048 e
->rank
= sym
->as
? sym
->as
->rank
: 0;
6051 gfc_resolve_expr (e
);
6055 /* This might have changed! */
6056 return e
->expr_type
== EXPR_FUNCTION
;
6061 gfc_resolve_character_operator (gfc_expr
*e
)
6063 gfc_expr
*op1
= e
->value
.op
.op1
;
6064 gfc_expr
*op2
= e
->value
.op
.op2
;
6065 gfc_expr
*e1
= NULL
;
6066 gfc_expr
*e2
= NULL
;
6068 gcc_assert (e
->value
.op
.op
== INTRINSIC_CONCAT
);
6070 if (op1
->ts
.u
.cl
&& op1
->ts
.u
.cl
->length
)
6071 e1
= gfc_copy_expr (op1
->ts
.u
.cl
->length
);
6072 else if (op1
->expr_type
== EXPR_CONSTANT
)
6073 e1
= gfc_get_int_expr (gfc_charlen_int_kind
, NULL
,
6074 op1
->value
.character
.length
);
6076 if (op2
->ts
.u
.cl
&& op2
->ts
.u
.cl
->length
)
6077 e2
= gfc_copy_expr (op2
->ts
.u
.cl
->length
);
6078 else if (op2
->expr_type
== EXPR_CONSTANT
)
6079 e2
= gfc_get_int_expr (gfc_charlen_int_kind
, NULL
,
6080 op2
->value
.character
.length
);
6082 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
6092 e
->ts
.u
.cl
->length
= gfc_add (e1
, e2
);
6093 e
->ts
.u
.cl
->length
->ts
.type
= BT_INTEGER
;
6094 e
->ts
.u
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;
6095 gfc_simplify_expr (e
->ts
.u
.cl
->length
, 0);
6096 gfc_resolve_expr (e
->ts
.u
.cl
->length
);
6102 /* Ensure that an character expression has a charlen and, if possible, a
6103 length expression. */
6106 fixup_charlen (gfc_expr
*e
)
6108 /* The cases fall through so that changes in expression type and the need
6109 for multiple fixes are picked up. In all circumstances, a charlen should
6110 be available for the middle end to hang a backend_decl on. */
6111 switch (e
->expr_type
)
6114 gfc_resolve_character_operator (e
);
6118 if (e
->expr_type
== EXPR_ARRAY
)
6119 gfc_resolve_character_array_constructor (e
);
6122 case EXPR_SUBSTRING
:
6123 if (!e
->ts
.u
.cl
&& e
->ref
)
6124 gfc_resolve_substring_charlen (e
);
6129 e
->ts
.u
.cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
6136 /* Update an actual argument to include the passed-object for type-bound
6137 procedures at the right position. */
6139 static gfc_actual_arglist
*
6140 update_arglist_pass (gfc_actual_arglist
* lst
, gfc_expr
* po
, unsigned argpos
,
6143 gcc_assert (argpos
> 0);
6147 gfc_actual_arglist
* result
;
6149 result
= gfc_get_actual_arglist ();
6153 result
->name
= name
;
6159 lst
->next
= update_arglist_pass (lst
->next
, po
, argpos
- 1, name
);
6161 lst
= update_arglist_pass (NULL
, po
, argpos
- 1, name
);
6166 /* Extract the passed-object from an EXPR_COMPCALL (a copy of it). */
6169 extract_compcall_passed_object (gfc_expr
* e
)
6173 if (e
->expr_type
== EXPR_UNKNOWN
)
6175 gfc_error ("Error in typebound call at %L",
6180 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
6182 if (e
->value
.compcall
.base_object
)
6183 po
= gfc_copy_expr (e
->value
.compcall
.base_object
);
6186 po
= gfc_get_expr ();
6187 po
->expr_type
= EXPR_VARIABLE
;
6188 po
->symtree
= e
->symtree
;
6189 po
->ref
= gfc_copy_ref (e
->ref
);
6190 po
->where
= e
->where
;
6193 if (!gfc_resolve_expr (po
))
6200 /* Update the arglist of an EXPR_COMPCALL expression to include the
6204 update_compcall_arglist (gfc_expr
* e
)
6207 gfc_typebound_proc
* tbp
;
6209 tbp
= e
->value
.compcall
.tbp
;
6214 po
= extract_compcall_passed_object (e
);
6218 if (tbp
->nopass
|| e
->value
.compcall
.ignore_pass
)
6224 if (tbp
->pass_arg_num
<= 0)
6227 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
6235 /* Extract the passed object from a PPC call (a copy of it). */
6238 extract_ppc_passed_object (gfc_expr
*e
)
6243 po
= gfc_get_expr ();
6244 po
->expr_type
= EXPR_VARIABLE
;
6245 po
->symtree
= e
->symtree
;
6246 po
->ref
= gfc_copy_ref (e
->ref
);
6247 po
->where
= e
->where
;
6249 /* Remove PPC reference. */
6251 while ((*ref
)->next
)
6252 ref
= &(*ref
)->next
;
6253 gfc_free_ref_list (*ref
);
6256 if (!gfc_resolve_expr (po
))
6263 /* Update the actual arglist of a procedure pointer component to include the
6267 update_ppc_arglist (gfc_expr
* e
)
6271 gfc_typebound_proc
* tb
;
6273 ppc
= gfc_get_proc_ptr_comp (e
);
6281 else if (tb
->nopass
)
6284 po
= extract_ppc_passed_object (e
);
6291 gfc_error ("Passed-object at %L must be scalar", &e
->where
);
6296 if (po
->ts
.type
== BT_DERIVED
&& po
->ts
.u
.derived
->attr
.abstract
)
6298 gfc_error ("Base object for procedure-pointer component call at %L is of"
6299 " ABSTRACT type %qs", &e
->where
, po
->ts
.u
.derived
->name
);
6303 gcc_assert (tb
->pass_arg_num
> 0);
6304 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
6312 /* Check that the object a TBP is called on is valid, i.e. it must not be
6313 of ABSTRACT type (as in subobject%abstract_parent%tbp()). */
6316 check_typebound_baseobject (gfc_expr
* e
)
6319 bool return_value
= false;
6321 base
= extract_compcall_passed_object (e
);
6325 if (base
->ts
.type
!= BT_DERIVED
&& base
->ts
.type
!= BT_CLASS
)
6327 gfc_error ("Error in typebound call at %L", &e
->where
);
6331 if (base
->ts
.type
== BT_CLASS
&& !gfc_expr_attr (base
).class_ok
)
6335 if (base
->ts
.type
== BT_DERIVED
&& base
->ts
.u
.derived
->attr
.abstract
)
6337 gfc_error ("Base object for type-bound procedure call at %L is of"
6338 " ABSTRACT type %qs", &e
->where
, base
->ts
.u
.derived
->name
);
6342 /* F08:C1230. If the procedure called is NOPASS,
6343 the base object must be scalar. */
6344 if (e
->value
.compcall
.tbp
->nopass
&& base
->rank
!= 0)
6346 gfc_error ("Base object for NOPASS type-bound procedure call at %L must"
6347 " be scalar", &e
->where
);
6351 return_value
= true;
6354 gfc_free_expr (base
);
6355 return return_value
;
6359 /* Resolve a call to a type-bound procedure, either function or subroutine,
6360 statically from the data in an EXPR_COMPCALL expression. The adapted
6361 arglist and the target-procedure symtree are returned. */
6364 resolve_typebound_static (gfc_expr
* e
, gfc_symtree
** target
,
6365 gfc_actual_arglist
** actual
)
6367 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
6368 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
6370 /* Update the actual arglist for PASS. */
6371 if (!update_compcall_arglist (e
))
6374 *actual
= e
->value
.compcall
.actual
;
6375 *target
= e
->value
.compcall
.tbp
->u
.specific
;
6377 gfc_free_ref_list (e
->ref
);
6379 e
->value
.compcall
.actual
= NULL
;
6381 /* If we find a deferred typebound procedure, check for derived types
6382 that an overriding typebound procedure has not been missed. */
6383 if (e
->value
.compcall
.name
6384 && !e
->value
.compcall
.tbp
->non_overridable
6385 && e
->value
.compcall
.base_object
6386 && e
->value
.compcall
.base_object
->ts
.type
== BT_DERIVED
)
6389 gfc_symbol
*derived
;
6391 /* Use the derived type of the base_object. */
6392 derived
= e
->value
.compcall
.base_object
->ts
.u
.derived
;
6395 /* If necessary, go through the inheritance chain. */
6396 while (!st
&& derived
)
6398 /* Look for the typebound procedure 'name'. */
6399 if (derived
->f2k_derived
&& derived
->f2k_derived
->tb_sym_root
)
6400 st
= gfc_find_symtree (derived
->f2k_derived
->tb_sym_root
,
6401 e
->value
.compcall
.name
);
6403 derived
= gfc_get_derived_super_type (derived
);
6406 /* Now find the specific name in the derived type namespace. */
6407 if (st
&& st
->n
.tb
&& st
->n
.tb
->u
.specific
)
6408 gfc_find_sym_tree (st
->n
.tb
->u
.specific
->name
,
6409 derived
->ns
, 1, &st
);
6417 /* Get the ultimate declared type from an expression. In addition,
6418 return the last class/derived type reference and the copy of the
6419 reference list. If check_types is set true, derived types are
6420 identified as well as class references. */
6422 get_declared_from_expr (gfc_ref
**class_ref
, gfc_ref
**new_ref
,
6423 gfc_expr
*e
, bool check_types
)
6425 gfc_symbol
*declared
;
6432 *new_ref
= gfc_copy_ref (e
->ref
);
6434 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
6436 if (ref
->type
!= REF_COMPONENT
)
6439 if ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
6440 || (check_types
&& gfc_bt_struct (ref
->u
.c
.component
->ts
.type
)))
6441 && ref
->u
.c
.component
->attr
.flavor
!= FL_PROCEDURE
)
6443 declared
= ref
->u
.c
.component
->ts
.u
.derived
;
6449 if (declared
== NULL
)
6450 declared
= e
->symtree
->n
.sym
->ts
.u
.derived
;
6456 /* Given an EXPR_COMPCALL calling a GENERIC typebound procedure, figure out
6457 which of the specific bindings (if any) matches the arglist and transform
6458 the expression into a call of that binding. */
6461 resolve_typebound_generic_call (gfc_expr
* e
, const char **name
)
6463 gfc_typebound_proc
* genproc
;
6464 const char* genname
;
6466 gfc_symbol
*derived
;
6468 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
6469 genname
= e
->value
.compcall
.name
;
6470 genproc
= e
->value
.compcall
.tbp
;
6472 if (!genproc
->is_generic
)
6475 /* Try the bindings on this type and in the inheritance hierarchy. */
6476 for (; genproc
; genproc
= genproc
->overridden
)
6480 gcc_assert (genproc
->is_generic
);
6481 for (g
= genproc
->u
.generic
; g
; g
= g
->next
)
6484 gfc_actual_arglist
* args
;
6487 gcc_assert (g
->specific
);
6489 if (g
->specific
->error
)
6492 target
= g
->specific
->u
.specific
->n
.sym
;
6494 /* Get the right arglist by handling PASS/NOPASS. */
6495 args
= gfc_copy_actual_arglist (e
->value
.compcall
.actual
);
6496 if (!g
->specific
->nopass
)
6499 po
= extract_compcall_passed_object (e
);
6502 gfc_free_actual_arglist (args
);
6506 gcc_assert (g
->specific
->pass_arg_num
> 0);
6507 gcc_assert (!g
->specific
->error
);
6508 args
= update_arglist_pass (args
, po
, g
->specific
->pass_arg_num
,
6509 g
->specific
->pass_arg
);
6511 resolve_actual_arglist (args
, target
->attr
.proc
,
6512 is_external_proc (target
)
6513 && gfc_sym_get_dummy_args (target
) == NULL
);
6515 /* Check if this arglist matches the formal. */
6516 matches
= gfc_arglist_matches_symbol (&args
, target
);
6518 /* Clean up and break out of the loop if we've found it. */
6519 gfc_free_actual_arglist (args
);
6522 e
->value
.compcall
.tbp
= g
->specific
;
6523 genname
= g
->specific_st
->name
;
6524 /* Pass along the name for CLASS methods, where the vtab
6525 procedure pointer component has to be referenced. */
6533 /* Nothing matching found! */
6534 gfc_error ("Found no matching specific binding for the call to the GENERIC"
6535 " %qs at %L", genname
, &e
->where
);
6539 /* Make sure that we have the right specific instance for the name. */
6540 derived
= get_declared_from_expr (NULL
, NULL
, e
, true);
6542 st
= gfc_find_typebound_proc (derived
, NULL
, genname
, true, &e
->where
);
6544 e
->value
.compcall
.tbp
= st
->n
.tb
;
6550 /* Resolve a call to a type-bound subroutine. */
6553 resolve_typebound_call (gfc_code
* c
, const char **name
, bool *overridable
)
6555 gfc_actual_arglist
* newactual
;
6556 gfc_symtree
* target
;
6558 /* Check that's really a SUBROUTINE. */
6559 if (!c
->expr1
->value
.compcall
.tbp
->subroutine
)
6561 if (!c
->expr1
->value
.compcall
.tbp
->is_generic
6562 && c
->expr1
->value
.compcall
.tbp
->u
.specific
6563 && c
->expr1
->value
.compcall
.tbp
->u
.specific
->n
.sym
6564 && c
->expr1
->value
.compcall
.tbp
->u
.specific
->n
.sym
->attr
.subroutine
)
6565 c
->expr1
->value
.compcall
.tbp
->subroutine
= 1;
6568 gfc_error ("%qs at %L should be a SUBROUTINE",
6569 c
->expr1
->value
.compcall
.name
, &c
->loc
);
6574 if (!check_typebound_baseobject (c
->expr1
))
6577 /* Pass along the name for CLASS methods, where the vtab
6578 procedure pointer component has to be referenced. */
6580 *name
= c
->expr1
->value
.compcall
.name
;
6582 if (!resolve_typebound_generic_call (c
->expr1
, name
))
6585 /* Pass along the NON_OVERRIDABLE attribute of the specific TBP. */
6587 *overridable
= !c
->expr1
->value
.compcall
.tbp
->non_overridable
;
6589 /* Transform into an ordinary EXEC_CALL for now. */
6591 if (!resolve_typebound_static (c
->expr1
, &target
, &newactual
))
6594 c
->ext
.actual
= newactual
;
6595 c
->symtree
= target
;
6596 c
->op
= (c
->expr1
->value
.compcall
.assign
? EXEC_ASSIGN_CALL
: EXEC_CALL
);
6598 gcc_assert (!c
->expr1
->ref
&& !c
->expr1
->value
.compcall
.actual
);
6600 gfc_free_expr (c
->expr1
);
6601 c
->expr1
= gfc_get_expr ();
6602 c
->expr1
->expr_type
= EXPR_FUNCTION
;
6603 c
->expr1
->symtree
= target
;
6604 c
->expr1
->where
= c
->loc
;
6606 return resolve_call (c
);
6610 /* Resolve a component-call expression. */
6612 resolve_compcall (gfc_expr
* e
, const char **name
)
6614 gfc_actual_arglist
* newactual
;
6615 gfc_symtree
* target
;
6617 /* Check that's really a FUNCTION. */
6618 if (!e
->value
.compcall
.tbp
->function
)
6620 gfc_error ("%qs at %L should be a FUNCTION",
6621 e
->value
.compcall
.name
, &e
->where
);
6626 /* These must not be assign-calls! */
6627 gcc_assert (!e
->value
.compcall
.assign
);
6629 if (!check_typebound_baseobject (e
))
6632 /* Pass along the name for CLASS methods, where the vtab
6633 procedure pointer component has to be referenced. */
6635 *name
= e
->value
.compcall
.name
;
6637 if (!resolve_typebound_generic_call (e
, name
))
6639 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
6641 /* Take the rank from the function's symbol. */
6642 if (e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
)
6643 e
->rank
= e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
->rank
;
6645 /* For now, we simply transform it into an EXPR_FUNCTION call with the same
6646 arglist to the TBP's binding target. */
6648 if (!resolve_typebound_static (e
, &target
, &newactual
))
6651 e
->value
.function
.actual
= newactual
;
6652 e
->value
.function
.name
= NULL
;
6653 e
->value
.function
.esym
= target
->n
.sym
;
6654 e
->value
.function
.isym
= NULL
;
6655 e
->symtree
= target
;
6656 e
->ts
= target
->n
.sym
->ts
;
6657 e
->expr_type
= EXPR_FUNCTION
;
6659 /* Resolution is not necessary if this is a class subroutine; this
6660 function only has to identify the specific proc. Resolution of
6661 the call will be done next in resolve_typebound_call. */
6662 return gfc_resolve_expr (e
);
6666 static bool resolve_fl_derived (gfc_symbol
*sym
);
6669 /* Resolve a typebound function, or 'method'. First separate all
6670 the non-CLASS references by calling resolve_compcall directly. */
6673 resolve_typebound_function (gfc_expr
* e
)
6675 gfc_symbol
*declared
;
6687 /* Deal with typebound operators for CLASS objects. */
6688 expr
= e
->value
.compcall
.base_object
;
6689 overridable
= !e
->value
.compcall
.tbp
->non_overridable
;
6690 if (expr
&& expr
->ts
.type
== BT_CLASS
&& e
->value
.compcall
.name
)
6692 /* Since the typebound operators are generic, we have to ensure
6693 that any delays in resolution are corrected and that the vtab
6696 declared
= ts
.u
.derived
;
6697 c
= gfc_find_component (declared
, "_vptr", true, true, NULL
);
6698 if (c
->ts
.u
.derived
== NULL
)
6699 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
6701 if (!resolve_compcall (e
, &name
))
6704 /* Use the generic name if it is there. */
6705 name
= name
? name
: e
->value
.function
.esym
->name
;
6706 e
->symtree
= expr
->symtree
;
6707 e
->ref
= gfc_copy_ref (expr
->ref
);
6708 get_declared_from_expr (&class_ref
, NULL
, e
, false);
6710 /* Trim away the extraneous references that emerge from nested
6711 use of interface.c (extend_expr). */
6712 if (class_ref
&& class_ref
->next
)
6714 gfc_free_ref_list (class_ref
->next
);
6715 class_ref
->next
= NULL
;
6717 else if (e
->ref
&& !class_ref
&& expr
->ts
.type
!= BT_CLASS
)
6719 gfc_free_ref_list (e
->ref
);
6723 gfc_add_vptr_component (e
);
6724 gfc_add_component_ref (e
, name
);
6725 e
->value
.function
.esym
= NULL
;
6726 if (expr
->expr_type
!= EXPR_VARIABLE
)
6727 e
->base_expr
= expr
;
6732 return resolve_compcall (e
, NULL
);
6734 if (!gfc_resolve_ref (e
))
6737 /* Get the CLASS declared type. */
6738 declared
= get_declared_from_expr (&class_ref
, &new_ref
, e
, true);
6740 if (!resolve_fl_derived (declared
))
6743 /* Weed out cases of the ultimate component being a derived type. */
6744 if ((class_ref
&& gfc_bt_struct (class_ref
->u
.c
.component
->ts
.type
))
6745 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
6747 gfc_free_ref_list (new_ref
);
6748 return resolve_compcall (e
, NULL
);
6751 c
= gfc_find_component (declared
, "_data", true, true, NULL
);
6753 /* Treat the call as if it is a typebound procedure, in order to roll
6754 out the correct name for the specific function. */
6755 if (!resolve_compcall (e
, &name
))
6757 gfc_free_ref_list (new_ref
);
6764 /* Convert the expression to a procedure pointer component call. */
6765 e
->value
.function
.esym
= NULL
;
6771 /* '_vptr' points to the vtab, which contains the procedure pointers. */
6772 gfc_add_vptr_component (e
);
6773 gfc_add_component_ref (e
, name
);
6775 /* Recover the typespec for the expression. This is really only
6776 necessary for generic procedures, where the additional call
6777 to gfc_add_component_ref seems to throw the collection of the
6778 correct typespec. */
6782 gfc_free_ref_list (new_ref
);
6787 /* Resolve a typebound subroutine, or 'method'. First separate all
6788 the non-CLASS references by calling resolve_typebound_call
6792 resolve_typebound_subroutine (gfc_code
*code
)
6794 gfc_symbol
*declared
;
6804 st
= code
->expr1
->symtree
;
6806 /* Deal with typebound operators for CLASS objects. */
6807 expr
= code
->expr1
->value
.compcall
.base_object
;
6808 overridable
= !code
->expr1
->value
.compcall
.tbp
->non_overridable
;
6809 if (expr
&& expr
->ts
.type
== BT_CLASS
&& code
->expr1
->value
.compcall
.name
)
6811 /* If the base_object is not a variable, the corresponding actual
6812 argument expression must be stored in e->base_expression so
6813 that the corresponding tree temporary can be used as the base
6814 object in gfc_conv_procedure_call. */
6815 if (expr
->expr_type
!= EXPR_VARIABLE
)
6817 gfc_actual_arglist
*args
;
6819 args
= code
->expr1
->value
.function
.actual
;
6820 for (; args
; args
= args
->next
)
6821 if (expr
== args
->expr
)
6825 /* Since the typebound operators are generic, we have to ensure
6826 that any delays in resolution are corrected and that the vtab
6828 declared
= expr
->ts
.u
.derived
;
6829 c
= gfc_find_component (declared
, "_vptr", true, true, NULL
);
6830 if (c
->ts
.u
.derived
== NULL
)
6831 c
->ts
.u
.derived
= gfc_find_derived_vtab (declared
);
6833 if (!resolve_typebound_call (code
, &name
, NULL
))
6836 /* Use the generic name if it is there. */
6837 name
= name
? name
: code
->expr1
->value
.function
.esym
->name
;
6838 code
->expr1
->symtree
= expr
->symtree
;
6839 code
->expr1
->ref
= gfc_copy_ref (expr
->ref
);
6841 /* Trim away the extraneous references that emerge from nested
6842 use of interface.c (extend_expr). */
6843 get_declared_from_expr (&class_ref
, NULL
, code
->expr1
, false);
6844 if (class_ref
&& class_ref
->next
)
6846 gfc_free_ref_list (class_ref
->next
);
6847 class_ref
->next
= NULL
;
6849 else if (code
->expr1
->ref
&& !class_ref
)
6851 gfc_free_ref_list (code
->expr1
->ref
);
6852 code
->expr1
->ref
= NULL
;
6855 /* Now use the procedure in the vtable. */
6856 gfc_add_vptr_component (code
->expr1
);
6857 gfc_add_component_ref (code
->expr1
, name
);
6858 code
->expr1
->value
.function
.esym
= NULL
;
6859 if (expr
->expr_type
!= EXPR_VARIABLE
)
6860 code
->expr1
->base_expr
= expr
;
6865 return resolve_typebound_call (code
, NULL
, NULL
);
6867 if (!gfc_resolve_ref (code
->expr1
))
6870 /* Get the CLASS declared type. */
6871 get_declared_from_expr (&class_ref
, &new_ref
, code
->expr1
, true);
6873 /* Weed out cases of the ultimate component being a derived type. */
6874 if ((class_ref
&& gfc_bt_struct (class_ref
->u
.c
.component
->ts
.type
))
6875 || (!class_ref
&& st
->n
.sym
->ts
.type
!= BT_CLASS
))
6877 gfc_free_ref_list (new_ref
);
6878 return resolve_typebound_call (code
, NULL
, NULL
);
6881 if (!resolve_typebound_call (code
, &name
, &overridable
))
6883 gfc_free_ref_list (new_ref
);
6886 ts
= code
->expr1
->ts
;
6890 /* Convert the expression to a procedure pointer component call. */
6891 code
->expr1
->value
.function
.esym
= NULL
;
6892 code
->expr1
->symtree
= st
;
6895 code
->expr1
->ref
= new_ref
;
6897 /* '_vptr' points to the vtab, which contains the procedure pointers. */
6898 gfc_add_vptr_component (code
->expr1
);
6899 gfc_add_component_ref (code
->expr1
, name
);
6901 /* Recover the typespec for the expression. This is really only
6902 necessary for generic procedures, where the additional call
6903 to gfc_add_component_ref seems to throw the collection of the
6904 correct typespec. */
6905 code
->expr1
->ts
= ts
;
6908 gfc_free_ref_list (new_ref
);
6914 /* Resolve a CALL to a Procedure Pointer Component (Subroutine). */
6917 resolve_ppc_call (gfc_code
* c
)
6919 gfc_component
*comp
;
6921 comp
= gfc_get_proc_ptr_comp (c
->expr1
);
6922 gcc_assert (comp
!= NULL
);
6924 c
->resolved_sym
= c
->expr1
->symtree
->n
.sym
;
6925 c
->expr1
->expr_type
= EXPR_VARIABLE
;
6927 if (!comp
->attr
.subroutine
)
6928 gfc_add_subroutine (&comp
->attr
, comp
->name
, &c
->expr1
->where
);
6930 if (!gfc_resolve_ref (c
->expr1
))
6933 if (!update_ppc_arglist (c
->expr1
))
6936 c
->ext
.actual
= c
->expr1
->value
.compcall
.actual
;
6938 if (!resolve_actual_arglist (c
->ext
.actual
, comp
->attr
.proc
,
6939 !(comp
->ts
.interface
6940 && comp
->ts
.interface
->formal
)))
6943 if (!pure_subroutine (comp
->ts
.interface
, comp
->name
, &c
->expr1
->where
))
6946 gfc_ppc_use (comp
, &c
->expr1
->value
.compcall
.actual
, &c
->expr1
->where
);
6952 /* Resolve a Function Call to a Procedure Pointer Component (Function). */
6955 resolve_expr_ppc (gfc_expr
* e
)
6957 gfc_component
*comp
;
6959 comp
= gfc_get_proc_ptr_comp (e
);
6960 gcc_assert (comp
!= NULL
);
6962 /* Convert to EXPR_FUNCTION. */
6963 e
->expr_type
= EXPR_FUNCTION
;
6964 e
->value
.function
.isym
= NULL
;
6965 e
->value
.function
.actual
= e
->value
.compcall
.actual
;
6967 if (comp
->as
!= NULL
)
6968 e
->rank
= comp
->as
->rank
;
6970 if (!comp
->attr
.function
)
6971 gfc_add_function (&comp
->attr
, comp
->name
, &e
->where
);
6973 if (!gfc_resolve_ref (e
))
6976 if (!resolve_actual_arglist (e
->value
.function
.actual
, comp
->attr
.proc
,
6977 !(comp
->ts
.interface
6978 && comp
->ts
.interface
->formal
)))
6981 if (!update_ppc_arglist (e
))
6984 if (!check_pure_function(e
))
6987 gfc_ppc_use (comp
, &e
->value
.compcall
.actual
, &e
->where
);
6994 gfc_is_expandable_expr (gfc_expr
*e
)
6996 gfc_constructor
*con
;
6998 if (e
->expr_type
== EXPR_ARRAY
)
7000 /* Traverse the constructor looking for variables that are flavor
7001 parameter. Parameters must be expanded since they are fully used at
7003 con
= gfc_constructor_first (e
->value
.constructor
);
7004 for (; con
; con
= gfc_constructor_next (con
))
7006 if (con
->expr
->expr_type
== EXPR_VARIABLE
7007 && con
->expr
->symtree
7008 && (con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
7009 || con
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_VARIABLE
))
7011 if (con
->expr
->expr_type
== EXPR_ARRAY
7012 && gfc_is_expandable_expr (con
->expr
))
7021 /* Sometimes variables in specification expressions of the result
7022 of module procedures in submodules wind up not being the 'real'
7023 dummy. Find this, if possible, in the namespace of the first
7027 fixup_unique_dummy (gfc_expr
*e
)
7029 gfc_symtree
*st
= NULL
;
7030 gfc_symbol
*s
= NULL
;
7032 if (e
->symtree
->n
.sym
->ns
->proc_name
7033 && e
->symtree
->n
.sym
->ns
->proc_name
->formal
)
7034 s
= e
->symtree
->n
.sym
->ns
->proc_name
->formal
->sym
;
7037 st
= gfc_find_symtree (s
->ns
->sym_root
, e
->symtree
->n
.sym
->name
);
7040 && st
->n
.sym
!= NULL
7041 && st
->n
.sym
->attr
.dummy
)
7045 /* Resolve an expression. That is, make sure that types of operands agree
7046 with their operators, intrinsic operators are converted to function calls
7047 for overloaded types and unresolved function references are resolved. */
7050 gfc_resolve_expr (gfc_expr
*e
)
7053 bool inquiry_save
, actual_arg_save
, first_actual_arg_save
;
7055 if (e
== NULL
|| e
->do_not_resolve_again
)
7058 /* inquiry_argument only applies to variables. */
7059 inquiry_save
= inquiry_argument
;
7060 actual_arg_save
= actual_arg
;
7061 first_actual_arg_save
= first_actual_arg
;
7063 if (e
->expr_type
!= EXPR_VARIABLE
)
7065 inquiry_argument
= false;
7067 first_actual_arg
= false;
7069 else if (e
->symtree
!= NULL
7070 && *e
->symtree
->name
== '@'
7071 && e
->symtree
->n
.sym
->attr
.dummy
)
7073 /* Deal with submodule specification expressions that are not
7074 found to be referenced in module.c(read_cleanup). */
7075 fixup_unique_dummy (e
);
7078 switch (e
->expr_type
)
7081 t
= resolve_operator (e
);
7087 if (check_host_association (e
))
7088 t
= resolve_function (e
);
7090 t
= resolve_variable (e
);
7092 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.u
.cl
== NULL
&& e
->ref
7093 && e
->ref
->type
!= REF_SUBSTRING
)
7094 gfc_resolve_substring_charlen (e
);
7099 t
= resolve_typebound_function (e
);
7102 case EXPR_SUBSTRING
:
7103 t
= gfc_resolve_ref (e
);
7112 t
= resolve_expr_ppc (e
);
7117 if (!gfc_resolve_ref (e
))
7120 t
= gfc_resolve_array_constructor (e
);
7121 /* Also try to expand a constructor. */
7124 gfc_expression_rank (e
);
7125 if (gfc_is_constant_expr (e
) || gfc_is_expandable_expr (e
))
7126 gfc_expand_constructor (e
, false);
7129 /* This provides the opportunity for the length of constructors with
7130 character valued function elements to propagate the string length
7131 to the expression. */
7132 if (t
&& e
->ts
.type
== BT_CHARACTER
)
7134 /* For efficiency, we call gfc_expand_constructor for BT_CHARACTER
7135 here rather then add a duplicate test for it above. */
7136 gfc_expand_constructor (e
, false);
7137 t
= gfc_resolve_character_array_constructor (e
);
7142 case EXPR_STRUCTURE
:
7143 t
= gfc_resolve_ref (e
);
7147 t
= resolve_structure_cons (e
, 0);
7151 t
= gfc_simplify_expr (e
, 0);
7155 gfc_internal_error ("gfc_resolve_expr(): Bad expression type");
7158 if (e
->ts
.type
== BT_CHARACTER
&& t
&& !e
->ts
.u
.cl
)
7161 inquiry_argument
= inquiry_save
;
7162 actual_arg
= actual_arg_save
;
7163 first_actual_arg
= first_actual_arg_save
;
7165 /* For some reason, resolving these expressions a second time mangles
7166 the typespec of the expression itself. */
7167 if (t
&& e
->expr_type
== EXPR_VARIABLE
7168 && e
->symtree
->n
.sym
->attr
.select_rank_temporary
7169 && UNLIMITED_POLY (e
->symtree
->n
.sym
))
7170 e
->do_not_resolve_again
= 1;
7176 /* Resolve an expression from an iterator. They must be scalar and have
7177 INTEGER or (optionally) REAL type. */
7180 gfc_resolve_iterator_expr (gfc_expr
*expr
, bool real_ok
,
7181 const char *name_msgid
)
7183 if (!gfc_resolve_expr (expr
))
7186 if (expr
->rank
!= 0)
7188 gfc_error ("%s at %L must be a scalar", _(name_msgid
), &expr
->where
);
7192 if (expr
->ts
.type
!= BT_INTEGER
)
7194 if (expr
->ts
.type
== BT_REAL
)
7197 return gfc_notify_std (GFC_STD_F95_DEL
,
7198 "%s at %L must be integer",
7199 _(name_msgid
), &expr
->where
);
7202 gfc_error ("%s at %L must be INTEGER", _(name_msgid
),
7209 gfc_error ("%s at %L must be INTEGER", _(name_msgid
), &expr
->where
);
7217 /* Resolve the expressions in an iterator structure. If REAL_OK is
7218 false allow only INTEGER type iterators, otherwise allow REAL types.
7219 Set own_scope to true for ac-implied-do and data-implied-do as those
7220 have a separate scope such that, e.g., a INTENT(IN) doesn't apply. */
7223 gfc_resolve_iterator (gfc_iterator
*iter
, bool real_ok
, bool own_scope
)
7225 if (!gfc_resolve_iterator_expr (iter
->var
, real_ok
, "Loop variable"))
7228 if (!gfc_check_vardef_context (iter
->var
, false, false, own_scope
,
7229 _("iterator variable")))
7232 if (!gfc_resolve_iterator_expr (iter
->start
, real_ok
,
7233 "Start expression in DO loop"))
7236 if (!gfc_resolve_iterator_expr (iter
->end
, real_ok
,
7237 "End expression in DO loop"))
7240 if (!gfc_resolve_iterator_expr (iter
->step
, real_ok
,
7241 "Step expression in DO loop"))
7244 /* Convert start, end, and step to the same type as var. */
7245 if (iter
->start
->ts
.kind
!= iter
->var
->ts
.kind
7246 || iter
->start
->ts
.type
!= iter
->var
->ts
.type
)
7247 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 1);
7249 if (iter
->end
->ts
.kind
!= iter
->var
->ts
.kind
7250 || iter
->end
->ts
.type
!= iter
->var
->ts
.type
)
7251 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 1);
7253 if (iter
->step
->ts
.kind
!= iter
->var
->ts
.kind
7254 || iter
->step
->ts
.type
!= iter
->var
->ts
.type
)
7255 gfc_convert_type (iter
->step
, &iter
->var
->ts
, 1);
7257 if (iter
->step
->expr_type
== EXPR_CONSTANT
)
7259 if ((iter
->step
->ts
.type
== BT_INTEGER
7260 && mpz_cmp_ui (iter
->step
->value
.integer
, 0) == 0)
7261 || (iter
->step
->ts
.type
== BT_REAL
7262 && mpfr_sgn (iter
->step
->value
.real
) == 0))
7264 gfc_error ("Step expression in DO loop at %L cannot be zero",
7265 &iter
->step
->where
);
7270 if (iter
->start
->expr_type
== EXPR_CONSTANT
7271 && iter
->end
->expr_type
== EXPR_CONSTANT
7272 && iter
->step
->expr_type
== EXPR_CONSTANT
)
7275 if (iter
->start
->ts
.type
== BT_INTEGER
)
7277 sgn
= mpz_cmp_ui (iter
->step
->value
.integer
, 0);
7278 cmp
= mpz_cmp (iter
->end
->value
.integer
, iter
->start
->value
.integer
);
7282 sgn
= mpfr_sgn (iter
->step
->value
.real
);
7283 cmp
= mpfr_cmp (iter
->end
->value
.real
, iter
->start
->value
.real
);
7285 if (warn_zerotrip
&& ((sgn
> 0 && cmp
< 0) || (sgn
< 0 && cmp
> 0)))
7286 gfc_warning (OPT_Wzerotrip
,
7287 "DO loop at %L will be executed zero times",
7288 &iter
->step
->where
);
7291 if (iter
->end
->expr_type
== EXPR_CONSTANT
7292 && iter
->end
->ts
.type
== BT_INTEGER
7293 && iter
->step
->expr_type
== EXPR_CONSTANT
7294 && iter
->step
->ts
.type
== BT_INTEGER
7295 && (mpz_cmp_si (iter
->step
->value
.integer
, -1L) == 0
7296 || mpz_cmp_si (iter
->step
->value
.integer
, 1L) == 0))
7298 bool is_step_positive
= mpz_cmp_ui (iter
->step
->value
.integer
, 1) == 0;
7299 int k
= gfc_validate_kind (BT_INTEGER
, iter
->end
->ts
.kind
, false);
7301 if (is_step_positive
7302 && mpz_cmp (iter
->end
->value
.integer
, gfc_integer_kinds
[k
].huge
) == 0)
7303 gfc_warning (OPT_Wundefined_do_loop
,
7304 "DO loop at %L is undefined as it overflows",
7305 &iter
->step
->where
);
7306 else if (!is_step_positive
7307 && mpz_cmp (iter
->end
->value
.integer
,
7308 gfc_integer_kinds
[k
].min_int
) == 0)
7309 gfc_warning (OPT_Wundefined_do_loop
,
7310 "DO loop at %L is undefined as it underflows",
7311 &iter
->step
->where
);
7318 /* Traversal function for find_forall_index. f == 2 signals that
7319 that variable itself is not to be checked - only the references. */
7322 forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int *f
)
7324 if (expr
->expr_type
!= EXPR_VARIABLE
)
7327 /* A scalar assignment */
7328 if (!expr
->ref
|| *f
== 1)
7330 if (expr
->symtree
->n
.sym
== sym
)
7342 /* Check whether the FORALL index appears in the expression or not.
7343 Returns true if SYM is found in EXPR. */
7346 find_forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int f
)
7348 if (gfc_traverse_expr (expr
, sym
, forall_index
, f
))
7355 /* Resolve a list of FORALL iterators. The FORALL index-name is constrained
7356 to be a scalar INTEGER variable. The subscripts and stride are scalar
7357 INTEGERs, and if stride is a constant it must be nonzero.
7358 Furthermore "A subscript or stride in a forall-triplet-spec shall
7359 not contain a reference to any index-name in the
7360 forall-triplet-spec-list in which it appears." (7.5.4.1) */
7363 resolve_forall_iterators (gfc_forall_iterator
*it
)
7365 gfc_forall_iterator
*iter
, *iter2
;
7367 for (iter
= it
; iter
; iter
= iter
->next
)
7369 if (gfc_resolve_expr (iter
->var
)
7370 && (iter
->var
->ts
.type
!= BT_INTEGER
|| iter
->var
->rank
!= 0))
7371 gfc_error ("FORALL index-name at %L must be a scalar INTEGER",
7374 if (gfc_resolve_expr (iter
->start
)
7375 && (iter
->start
->ts
.type
!= BT_INTEGER
|| iter
->start
->rank
!= 0))
7376 gfc_error ("FORALL start expression at %L must be a scalar INTEGER",
7377 &iter
->start
->where
);
7378 if (iter
->var
->ts
.kind
!= iter
->start
->ts
.kind
)
7379 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 1);
7381 if (gfc_resolve_expr (iter
->end
)
7382 && (iter
->end
->ts
.type
!= BT_INTEGER
|| iter
->end
->rank
!= 0))
7383 gfc_error ("FORALL end expression at %L must be a scalar INTEGER",
7385 if (iter
->var
->ts
.kind
!= iter
->end
->ts
.kind
)
7386 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 1);
7388 if (gfc_resolve_expr (iter
->stride
))
7390 if (iter
->stride
->ts
.type
!= BT_INTEGER
|| iter
->stride
->rank
!= 0)
7391 gfc_error ("FORALL stride expression at %L must be a scalar %s",
7392 &iter
->stride
->where
, "INTEGER");
7394 if (iter
->stride
->expr_type
== EXPR_CONSTANT
7395 && mpz_cmp_ui (iter
->stride
->value
.integer
, 0) == 0)
7396 gfc_error ("FORALL stride expression at %L cannot be zero",
7397 &iter
->stride
->where
);
7399 if (iter
->var
->ts
.kind
!= iter
->stride
->ts
.kind
)
7400 gfc_convert_type (iter
->stride
, &iter
->var
->ts
, 1);
7403 for (iter
= it
; iter
; iter
= iter
->next
)
7404 for (iter2
= iter
; iter2
; iter2
= iter2
->next
)
7406 if (find_forall_index (iter2
->start
, iter
->var
->symtree
->n
.sym
, 0)
7407 || find_forall_index (iter2
->end
, iter
->var
->symtree
->n
.sym
, 0)
7408 || find_forall_index (iter2
->stride
, iter
->var
->symtree
->n
.sym
, 0))
7409 gfc_error ("FORALL index %qs may not appear in triplet "
7410 "specification at %L", iter
->var
->symtree
->name
,
7411 &iter2
->start
->where
);
7416 /* Given a pointer to a symbol that is a derived type, see if it's
7417 inaccessible, i.e. if it's defined in another module and the components are
7418 PRIVATE. The search is recursive if necessary. Returns zero if no
7419 inaccessible components are found, nonzero otherwise. */
7422 derived_inaccessible (gfc_symbol
*sym
)
7426 if (sym
->attr
.use_assoc
&& sym
->attr
.private_comp
)
7429 for (c
= sym
->components
; c
; c
= c
->next
)
7431 /* Prevent an infinite loop through this function. */
7432 if (c
->ts
.type
== BT_DERIVED
&& c
->attr
.pointer
7433 && sym
== c
->ts
.u
.derived
)
7436 if (c
->ts
.type
== BT_DERIVED
&& derived_inaccessible (c
->ts
.u
.derived
))
7444 /* Resolve the argument of a deallocate expression. The expression must be
7445 a pointer or a full array. */
7448 resolve_deallocate_expr (gfc_expr
*e
)
7450 symbol_attribute attr
;
7451 int allocatable
, pointer
;
7457 if (!gfc_resolve_expr (e
))
7460 if (e
->expr_type
!= EXPR_VARIABLE
)
7463 sym
= e
->symtree
->n
.sym
;
7464 unlimited
= UNLIMITED_POLY(sym
);
7466 if (sym
->ts
.type
== BT_CLASS
)
7468 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
7469 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
7473 allocatable
= sym
->attr
.allocatable
;
7474 pointer
= sym
->attr
.pointer
;
7476 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
7481 if (ref
->u
.ar
.type
!= AR_FULL
7482 && !(ref
->u
.ar
.type
== AR_ELEMENT
&& ref
->u
.ar
.as
->rank
== 0
7483 && ref
->u
.ar
.codimen
&& gfc_ref_this_image (ref
)))
7488 c
= ref
->u
.c
.component
;
7489 if (c
->ts
.type
== BT_CLASS
)
7491 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
7492 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
7496 allocatable
= c
->attr
.allocatable
;
7497 pointer
= c
->attr
.pointer
;
7508 attr
= gfc_expr_attr (e
);
7510 if (allocatable
== 0 && attr
.pointer
== 0 && !unlimited
)
7513 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
7519 if (gfc_is_coindexed (e
))
7521 gfc_error ("Coindexed allocatable object at %L", &e
->where
);
7526 && !gfc_check_vardef_context (e
, true, true, false,
7527 _("DEALLOCATE object")))
7529 if (!gfc_check_vardef_context (e
, false, true, false,
7530 _("DEALLOCATE object")))
7537 /* Returns true if the expression e contains a reference to the symbol sym. */
7539 sym_in_expr (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
7541 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
== sym
)
7548 gfc_find_sym_in_expr (gfc_symbol
*sym
, gfc_expr
*e
)
7550 return gfc_traverse_expr (e
, sym
, sym_in_expr
, 0);
7554 /* Given the expression node e for an allocatable/pointer of derived type to be
7555 allocated, get the expression node to be initialized afterwards (needed for
7556 derived types with default initializers, and derived types with allocatable
7557 components that need nullification.) */
7560 gfc_expr_to_initialize (gfc_expr
*e
)
7566 result
= gfc_copy_expr (e
);
7568 /* Change the last array reference from AR_ELEMENT to AR_FULL. */
7569 for (ref
= result
->ref
; ref
; ref
= ref
->next
)
7570 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
7572 if (ref
->u
.ar
.dimen
== 0
7573 && ref
->u
.ar
.as
&& ref
->u
.ar
.as
->corank
)
7576 ref
->u
.ar
.type
= AR_FULL
;
7578 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
7579 ref
->u
.ar
.start
[i
] = ref
->u
.ar
.end
[i
] = ref
->u
.ar
.stride
[i
] = NULL
;
7584 gfc_free_shape (&result
->shape
, result
->rank
);
7586 /* Recalculate rank, shape, etc. */
7587 gfc_resolve_expr (result
);
7592 /* If the last ref of an expression is an array ref, return a copy of the
7593 expression with that one removed. Otherwise, a copy of the original
7594 expression. This is used for allocate-expressions and pointer assignment
7595 LHS, where there may be an array specification that needs to be stripped
7596 off when using gfc_check_vardef_context. */
7599 remove_last_array_ref (gfc_expr
* e
)
7604 e2
= gfc_copy_expr (e
);
7605 for (r
= &e2
->ref
; *r
; r
= &(*r
)->next
)
7606 if ((*r
)->type
== REF_ARRAY
&& !(*r
)->next
)
7608 gfc_free_ref_list (*r
);
7617 /* Used in resolve_allocate_expr to check that a allocation-object and
7618 a source-expr are conformable. This does not catch all possible
7619 cases; in particular a runtime checking is needed. */
7622 conformable_arrays (gfc_expr
*e1
, gfc_expr
*e2
)
7625 for (tail
= e2
->ref
; tail
&& tail
->next
; tail
= tail
->next
);
7627 /* First compare rank. */
7628 if ((tail
&& (!tail
->u
.ar
.as
|| e1
->rank
!= tail
->u
.ar
.as
->rank
))
7629 || (!tail
&& e1
->rank
!= e2
->rank
))
7631 gfc_error ("Source-expr at %L must be scalar or have the "
7632 "same rank as the allocate-object at %L",
7633 &e1
->where
, &e2
->where
);
7644 for (i
= 0; i
< e1
->rank
; i
++)
7646 if (tail
->u
.ar
.start
[i
] == NULL
)
7649 if (tail
->u
.ar
.end
[i
])
7651 mpz_set (s
, tail
->u
.ar
.end
[i
]->value
.integer
);
7652 mpz_sub (s
, s
, tail
->u
.ar
.start
[i
]->value
.integer
);
7653 mpz_add_ui (s
, s
, 1);
7657 mpz_set (s
, tail
->u
.ar
.start
[i
]->value
.integer
);
7660 if (mpz_cmp (e1
->shape
[i
], s
) != 0)
7662 gfc_error ("Source-expr at %L and allocate-object at %L must "
7663 "have the same shape", &e1
->where
, &e2
->where
);
7676 /* Resolve the expression in an ALLOCATE statement, doing the additional
7677 checks to see whether the expression is OK or not. The expression must
7678 have a trailing array reference that gives the size of the array. */
7681 resolve_allocate_expr (gfc_expr
*e
, gfc_code
*code
, bool *array_alloc_wo_spec
)
7683 int i
, pointer
, allocatable
, dimension
, is_abstract
;
7687 symbol_attribute attr
;
7688 gfc_ref
*ref
, *ref2
;
7691 gfc_symbol
*sym
= NULL
;
7696 /* Mark the utmost array component as being in allocate to allow DIMEN_STAR
7697 checking of coarrays. */
7698 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
7699 if (ref
->next
== NULL
)
7702 if (ref
&& ref
->type
== REF_ARRAY
)
7703 ref
->u
.ar
.in_allocate
= true;
7705 if (!gfc_resolve_expr (e
))
7708 /* Make sure the expression is allocatable or a pointer. If it is
7709 pointer, the next-to-last reference must be a pointer. */
7713 sym
= e
->symtree
->n
.sym
;
7715 /* Check whether ultimate component is abstract and CLASS. */
7718 /* Is the allocate-object unlimited polymorphic? */
7719 unlimited
= UNLIMITED_POLY(e
);
7721 if (e
->expr_type
!= EXPR_VARIABLE
)
7724 attr
= gfc_expr_attr (e
);
7725 pointer
= attr
.pointer
;
7726 dimension
= attr
.dimension
;
7727 codimension
= attr
.codimension
;
7731 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
7733 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
7734 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
7735 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
7736 codimension
= CLASS_DATA (sym
)->attr
.codimension
;
7737 is_abstract
= CLASS_DATA (sym
)->attr
.abstract
;
7741 allocatable
= sym
->attr
.allocatable
;
7742 pointer
= sym
->attr
.pointer
;
7743 dimension
= sym
->attr
.dimension
;
7744 codimension
= sym
->attr
.codimension
;
7749 for (ref
= e
->ref
; ref
; ref2
= ref
, ref
= ref
->next
)
7754 if (ref
->u
.ar
.codimen
> 0)
7757 for (n
= ref
->u
.ar
.dimen
;
7758 n
< ref
->u
.ar
.dimen
+ ref
->u
.ar
.codimen
; n
++)
7759 if (ref
->u
.ar
.dimen_type
[n
] != DIMEN_THIS_IMAGE
)
7766 if (ref
->next
!= NULL
)
7774 gfc_error ("Coindexed allocatable object at %L",
7779 c
= ref
->u
.c
.component
;
7780 if (c
->ts
.type
== BT_CLASS
)
7782 allocatable
= CLASS_DATA (c
)->attr
.allocatable
;
7783 pointer
= CLASS_DATA (c
)->attr
.class_pointer
;
7784 dimension
= CLASS_DATA (c
)->attr
.dimension
;
7785 codimension
= CLASS_DATA (c
)->attr
.codimension
;
7786 is_abstract
= CLASS_DATA (c
)->attr
.abstract
;
7790 allocatable
= c
->attr
.allocatable
;
7791 pointer
= c
->attr
.pointer
;
7792 dimension
= c
->attr
.dimension
;
7793 codimension
= c
->attr
.codimension
;
7794 is_abstract
= c
->attr
.abstract
;
7807 /* Check for F08:C628. */
7808 if (allocatable
== 0 && pointer
== 0 && !unlimited
)
7810 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
7815 /* Some checks for the SOURCE tag. */
7818 /* Check F03:C631. */
7819 if (!gfc_type_compatible (&e
->ts
, &code
->expr3
->ts
))
7821 gfc_error ("Type of entity at %L is type incompatible with "
7822 "source-expr at %L", &e
->where
, &code
->expr3
->where
);
7826 /* Check F03:C632 and restriction following Note 6.18. */
7827 if (code
->expr3
->rank
> 0 && !conformable_arrays (code
->expr3
, e
))
7830 /* Check F03:C633. */
7831 if (code
->expr3
->ts
.kind
!= e
->ts
.kind
&& !unlimited
)
7833 gfc_error ("The allocate-object at %L and the source-expr at %L "
7834 "shall have the same kind type parameter",
7835 &e
->where
, &code
->expr3
->where
);
7839 /* Check F2008, C642. */
7840 if (code
->expr3
->ts
.type
== BT_DERIVED
7841 && ((codimension
&& gfc_expr_attr (code
->expr3
).lock_comp
)
7842 || (code
->expr3
->ts
.u
.derived
->from_intmod
7843 == INTMOD_ISO_FORTRAN_ENV
7844 && code
->expr3
->ts
.u
.derived
->intmod_sym_id
7845 == ISOFORTRAN_LOCK_TYPE
)))
7847 gfc_error ("The source-expr at %L shall neither be of type "
7848 "LOCK_TYPE nor have a LOCK_TYPE component if "
7849 "allocate-object at %L is a coarray",
7850 &code
->expr3
->where
, &e
->where
);
7854 /* Check TS18508, C702/C703. */
7855 if (code
->expr3
->ts
.type
== BT_DERIVED
7856 && ((codimension
&& gfc_expr_attr (code
->expr3
).event_comp
)
7857 || (code
->expr3
->ts
.u
.derived
->from_intmod
7858 == INTMOD_ISO_FORTRAN_ENV
7859 && code
->expr3
->ts
.u
.derived
->intmod_sym_id
7860 == ISOFORTRAN_EVENT_TYPE
)))
7862 gfc_error ("The source-expr at %L shall neither be of type "
7863 "EVENT_TYPE nor have a EVENT_TYPE component if "
7864 "allocate-object at %L is a coarray",
7865 &code
->expr3
->where
, &e
->where
);
7870 /* Check F08:C629. */
7871 if (is_abstract
&& code
->ext
.alloc
.ts
.type
== BT_UNKNOWN
7874 gcc_assert (e
->ts
.type
== BT_CLASS
);
7875 gfc_error ("Allocating %s of ABSTRACT base type at %L requires a "
7876 "type-spec or source-expr", sym
->name
, &e
->where
);
7880 /* Check F08:C632. */
7881 if (code
->ext
.alloc
.ts
.type
== BT_CHARACTER
&& !e
->ts
.deferred
7882 && !UNLIMITED_POLY (e
))
7886 if (!e
->ts
.u
.cl
->length
)
7889 cmp
= gfc_dep_compare_expr (e
->ts
.u
.cl
->length
,
7890 code
->ext
.alloc
.ts
.u
.cl
->length
);
7891 if (cmp
== 1 || cmp
== -1 || cmp
== -3)
7893 gfc_error ("Allocating %s at %L with type-spec requires the same "
7894 "character-length parameter as in the declaration",
7895 sym
->name
, &e
->where
);
7900 /* In the variable definition context checks, gfc_expr_attr is used
7901 on the expression. This is fooled by the array specification
7902 present in e, thus we have to eliminate that one temporarily. */
7903 e2
= remove_last_array_ref (e
);
7906 t
= gfc_check_vardef_context (e2
, true, true, false,
7907 _("ALLOCATE object"));
7909 t
= gfc_check_vardef_context (e2
, false, true, false,
7910 _("ALLOCATE object"));
7915 if (e
->ts
.type
== BT_CLASS
&& CLASS_DATA (e
)->attr
.dimension
7916 && !code
->expr3
&& code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
7918 /* For class arrays, the initialization with SOURCE is done
7919 using _copy and trans_call. It is convenient to exploit that
7920 when the allocated type is different from the declared type but
7921 no SOURCE exists by setting expr3. */
7922 code
->expr3
= gfc_default_initializer (&code
->ext
.alloc
.ts
);
7924 else if (flag_coarray
!= GFC_FCOARRAY_LIB
&& e
->ts
.type
== BT_DERIVED
7925 && e
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
7926 && e
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
7928 /* We have to zero initialize the integer variable. */
7929 code
->expr3
= gfc_get_int_expr (gfc_default_integer_kind
, &e
->where
, 0);
7932 if (e
->ts
.type
== BT_CLASS
&& !unlimited
&& !UNLIMITED_POLY (code
->expr3
))
7934 /* Make sure the vtab symbol is present when
7935 the module variables are generated. */
7936 gfc_typespec ts
= e
->ts
;
7938 ts
= code
->expr3
->ts
;
7939 else if (code
->ext
.alloc
.ts
.type
== BT_DERIVED
)
7940 ts
= code
->ext
.alloc
.ts
;
7942 /* Finding the vtab also publishes the type's symbol. Therefore this
7943 statement is necessary. */
7944 gfc_find_derived_vtab (ts
.u
.derived
);
7946 else if (unlimited
&& !UNLIMITED_POLY (code
->expr3
))
7948 /* Again, make sure the vtab symbol is present when
7949 the module variables are generated. */
7950 gfc_typespec
*ts
= NULL
;
7952 ts
= &code
->expr3
->ts
;
7954 ts
= &code
->ext
.alloc
.ts
;
7958 /* Finding the vtab also publishes the type's symbol. Therefore this
7959 statement is necessary. */
7963 if (dimension
== 0 && codimension
== 0)
7966 /* Make sure the last reference node is an array specification. */
7968 if (!ref2
|| ref2
->type
!= REF_ARRAY
|| ref2
->u
.ar
.type
== AR_FULL
7969 || (dimension
&& ref2
->u
.ar
.dimen
== 0))
7974 if (!gfc_notify_std (GFC_STD_F2008
, "Array specification required "
7975 "in ALLOCATE statement at %L", &e
->where
))
7977 if (code
->expr3
->rank
!= 0)
7978 *array_alloc_wo_spec
= true;
7981 gfc_error ("Array specification or array-valued SOURCE= "
7982 "expression required in ALLOCATE statement at %L",
7989 gfc_error ("Array specification required in ALLOCATE statement "
7990 "at %L", &e
->where
);
7995 /* Make sure that the array section reference makes sense in the
7996 context of an ALLOCATE specification. */
8001 for (i
= ar
->dimen
; i
< ar
->dimen
+ ar
->codimen
; i
++)
8003 switch (ar
->dimen_type
[i
])
8005 case DIMEN_THIS_IMAGE
:
8006 gfc_error ("Coarray specification required in ALLOCATE statement "
8007 "at %L", &e
->where
);
8011 if (ar
->start
[i
] == 0 || ar
->end
[i
] == 0)
8013 /* If ar->stride[i] is NULL, we issued a previous error. */
8014 if (ar
->stride
[i
] == NULL
)
8015 gfc_error ("Bad array specification in ALLOCATE statement "
8016 "at %L", &e
->where
);
8019 else if (gfc_dep_compare_expr (ar
->start
[i
], ar
->end
[i
]) == 1)
8021 gfc_error ("Upper cobound is less than lower cobound at %L",
8022 &ar
->start
[i
]->where
);
8028 if (ar
->start
[i
]->expr_type
== EXPR_CONSTANT
)
8030 gcc_assert (ar
->start
[i
]->ts
.type
== BT_INTEGER
);
8031 if (mpz_cmp_si (ar
->start
[i
]->value
.integer
, 1) < 0)
8033 gfc_error ("Upper cobound is less than lower cobound "
8034 "of 1 at %L", &ar
->start
[i
]->where
);
8044 gfc_error ("Bad array specification in ALLOCATE statement at %L",
8050 for (i
= 0; i
< ar
->dimen
; i
++)
8052 if (ar
->type
== AR_ELEMENT
|| ar
->type
== AR_FULL
)
8055 switch (ar
->dimen_type
[i
])
8061 if (ar
->start
[i
] != NULL
8062 && ar
->end
[i
] != NULL
8063 && ar
->stride
[i
] == NULL
)
8071 case DIMEN_THIS_IMAGE
:
8072 gfc_error ("Bad array specification in ALLOCATE statement at %L",
8078 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
8080 sym
= a
->expr
->symtree
->n
.sym
;
8082 /* TODO - check derived type components. */
8083 if (gfc_bt_struct (sym
->ts
.type
) || sym
->ts
.type
== BT_CLASS
)
8086 if ((ar
->start
[i
] != NULL
8087 && gfc_find_sym_in_expr (sym
, ar
->start
[i
]))
8088 || (ar
->end
[i
] != NULL
8089 && gfc_find_sym_in_expr (sym
, ar
->end
[i
])))
8091 gfc_error ("%qs must not appear in the array specification at "
8092 "%L in the same ALLOCATE statement where it is "
8093 "itself allocated", sym
->name
, &ar
->where
);
8099 for (i
= ar
->dimen
; i
< ar
->codimen
+ ar
->dimen
; i
++)
8101 if (ar
->dimen_type
[i
] == DIMEN_ELEMENT
8102 || ar
->dimen_type
[i
] == DIMEN_RANGE
)
8104 if (i
== (ar
->dimen
+ ar
->codimen
- 1))
8106 gfc_error ("Expected '*' in coindex specification in ALLOCATE "
8107 "statement at %L", &e
->where
);
8113 if (ar
->dimen_type
[i
] == DIMEN_STAR
&& i
== (ar
->dimen
+ ar
->codimen
- 1)
8114 && ar
->stride
[i
] == NULL
)
8117 gfc_error ("Bad coarray specification in ALLOCATE statement at %L",
8131 resolve_allocate_deallocate (gfc_code
*code
, const char *fcn
)
8133 gfc_expr
*stat
, *errmsg
, *pe
, *qe
;
8134 gfc_alloc
*a
, *p
, *q
;
8137 errmsg
= code
->expr2
;
8139 /* Check the stat variable. */
8142 gfc_check_vardef_context (stat
, false, false, false,
8143 _("STAT variable"));
8145 if ((stat
->ts
.type
!= BT_INTEGER
8146 && !(stat
->ref
&& (stat
->ref
->type
== REF_ARRAY
8147 || stat
->ref
->type
== REF_COMPONENT
)))
8149 gfc_error ("Stat-variable at %L must be a scalar INTEGER "
8150 "variable", &stat
->where
);
8152 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
8153 if (p
->expr
->symtree
->n
.sym
->name
== stat
->symtree
->n
.sym
->name
)
8155 gfc_ref
*ref1
, *ref2
;
8158 for (ref1
= p
->expr
->ref
, ref2
= stat
->ref
; ref1
&& ref2
;
8159 ref1
= ref1
->next
, ref2
= ref2
->next
)
8161 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
8163 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
8172 gfc_error ("Stat-variable at %L shall not be %sd within "
8173 "the same %s statement", &stat
->where
, fcn
, fcn
);
8179 /* Check the errmsg variable. */
8183 gfc_warning (0, "ERRMSG at %L is useless without a STAT tag",
8186 gfc_check_vardef_context (errmsg
, false, false, false,
8187 _("ERRMSG variable"));
8189 /* F18:R928 alloc-opt is ERRMSG = errmsg-variable
8190 F18:R930 errmsg-variable is scalar-default-char-variable
8191 F18:R906 default-char-variable is variable
8192 F18:C906 default-char-variable shall be default character. */
8193 if ((errmsg
->ts
.type
!= BT_CHARACTER
8195 && (errmsg
->ref
->type
== REF_ARRAY
8196 || errmsg
->ref
->type
== REF_COMPONENT
)))
8198 || errmsg
->ts
.kind
!= gfc_default_character_kind
)
8199 gfc_error ("ERRMSG variable at %L shall be a scalar default CHARACTER "
8200 "variable", &errmsg
->where
);
8202 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
8203 if (p
->expr
->symtree
->n
.sym
->name
== errmsg
->symtree
->n
.sym
->name
)
8205 gfc_ref
*ref1
, *ref2
;
8208 for (ref1
= p
->expr
->ref
, ref2
= errmsg
->ref
; ref1
&& ref2
;
8209 ref1
= ref1
->next
, ref2
= ref2
->next
)
8211 if (ref1
->type
!= REF_COMPONENT
|| ref2
->type
!= REF_COMPONENT
)
8213 if (ref1
->u
.c
.component
->name
!= ref2
->u
.c
.component
->name
)
8222 gfc_error ("Errmsg-variable at %L shall not be %sd within "
8223 "the same %s statement", &errmsg
->where
, fcn
, fcn
);
8229 /* Check that an allocate-object appears only once in the statement. */
8231 for (p
= code
->ext
.alloc
.list
; p
; p
= p
->next
)
8234 for (q
= p
->next
; q
; q
= q
->next
)
8237 if (pe
->symtree
->n
.sym
->name
== qe
->symtree
->n
.sym
->name
)
8239 /* This is a potential collision. */
8240 gfc_ref
*pr
= pe
->ref
;
8241 gfc_ref
*qr
= qe
->ref
;
8243 /* Follow the references until
8244 a) They start to differ, in which case there is no error;
8245 you can deallocate a%b and a%c in a single statement
8246 b) Both of them stop, which is an error
8247 c) One of them stops, which is also an error. */
8250 if (pr
== NULL
&& qr
== NULL
)
8252 gfc_error ("Allocate-object at %L also appears at %L",
8253 &pe
->where
, &qe
->where
);
8256 else if (pr
!= NULL
&& qr
== NULL
)
8258 gfc_error ("Allocate-object at %L is subobject of"
8259 " object at %L", &pe
->where
, &qe
->where
);
8262 else if (pr
== NULL
&& qr
!= NULL
)
8264 gfc_error ("Allocate-object at %L is subobject of"
8265 " object at %L", &qe
->where
, &pe
->where
);
8268 /* Here, pr != NULL && qr != NULL */
8269 gcc_assert(pr
->type
== qr
->type
);
8270 if (pr
->type
== REF_ARRAY
)
8272 /* Handle cases like allocate(v(3)%x(3), v(2)%x(3)),
8274 gcc_assert (qr
->type
== REF_ARRAY
);
8276 if (pr
->next
&& qr
->next
)
8279 gfc_array_ref
*par
= &(pr
->u
.ar
);
8280 gfc_array_ref
*qar
= &(qr
->u
.ar
);
8282 for (i
=0; i
<par
->dimen
; i
++)
8284 if ((par
->start
[i
] != NULL
8285 || qar
->start
[i
] != NULL
)
8286 && gfc_dep_compare_expr (par
->start
[i
],
8287 qar
->start
[i
]) != 0)
8294 if (pr
->u
.c
.component
->name
!= qr
->u
.c
.component
->name
)
8307 if (strcmp (fcn
, "ALLOCATE") == 0)
8309 bool arr_alloc_wo_spec
= false;
8311 /* Resolving the expr3 in the loop over all objects to allocate would
8312 execute loop invariant code for each loop item. Therefore do it just
8314 if (code
->expr3
&& code
->expr3
->mold
8315 && code
->expr3
->ts
.type
== BT_DERIVED
)
8317 /* Default initialization via MOLD (non-polymorphic). */
8318 gfc_expr
*rhs
= gfc_default_initializer (&code
->expr3
->ts
);
8321 gfc_resolve_expr (rhs
);
8322 gfc_free_expr (code
->expr3
);
8326 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
8327 resolve_allocate_expr (a
->expr
, code
, &arr_alloc_wo_spec
);
8329 if (arr_alloc_wo_spec
&& code
->expr3
)
8331 /* Mark the allocate to have to take the array specification
8333 code
->ext
.alloc
.arr_spec_from_expr3
= 1;
8338 for (a
= code
->ext
.alloc
.list
; a
; a
= a
->next
)
8339 resolve_deallocate_expr (a
->expr
);
8344 /************ SELECT CASE resolution subroutines ************/
8346 /* Callback function for our mergesort variant. Determines interval
8347 overlaps for CASEs. Return <0 if op1 < op2, 0 for overlap, >0 for
8348 op1 > op2. Assumes we're not dealing with the default case.
8349 We have op1 = (:L), (K:L) or (K:) and op2 = (:N), (M:N) or (M:).
8350 There are nine situations to check. */
8353 compare_cases (const gfc_case
*op1
, const gfc_case
*op2
)
8357 if (op1
->low
== NULL
) /* op1 = (:L) */
8359 /* op2 = (:N), so overlap. */
8361 /* op2 = (M:) or (M:N), L < M */
8362 if (op2
->low
!= NULL
8363 && gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
8366 else if (op1
->high
== NULL
) /* op1 = (K:) */
8368 /* op2 = (M:), so overlap. */
8370 /* op2 = (:N) or (M:N), K > N */
8371 if (op2
->high
!= NULL
8372 && gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
8375 else /* op1 = (K:L) */
8377 if (op2
->low
== NULL
) /* op2 = (:N), K > N */
8378 retval
= (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
8380 else if (op2
->high
== NULL
) /* op2 = (M:), L < M */
8381 retval
= (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
8383 else /* op2 = (M:N) */
8387 if (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
8390 else if (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
8399 /* Merge-sort a double linked case list, detecting overlap in the
8400 process. LIST is the head of the double linked case list before it
8401 is sorted. Returns the head of the sorted list if we don't see any
8402 overlap, or NULL otherwise. */
8405 check_case_overlap (gfc_case
*list
)
8407 gfc_case
*p
, *q
, *e
, *tail
;
8408 int insize
, nmerges
, psize
, qsize
, cmp
, overlap_seen
;
8410 /* If the passed list was empty, return immediately. */
8417 /* Loop unconditionally. The only exit from this loop is a return
8418 statement, when we've finished sorting the case list. */
8425 /* Count the number of merges we do in this pass. */
8428 /* Loop while there exists a merge to be done. */
8433 /* Count this merge. */
8436 /* Cut the list in two pieces by stepping INSIZE places
8437 forward in the list, starting from P. */
8440 for (i
= 0; i
< insize
; i
++)
8449 /* Now we have two lists. Merge them! */
8450 while (psize
> 0 || (qsize
> 0 && q
!= NULL
))
8452 /* See from which the next case to merge comes from. */
8455 /* P is empty so the next case must come from Q. */
8460 else if (qsize
== 0 || q
== NULL
)
8469 cmp
= compare_cases (p
, q
);
8472 /* The whole case range for P is less than the
8480 /* The whole case range for Q is greater than
8481 the case range for P. */
8488 /* The cases overlap, or they are the same
8489 element in the list. Either way, we must
8490 issue an error and get the next case from P. */
8491 /* FIXME: Sort P and Q by line number. */
8492 gfc_error ("CASE label at %L overlaps with CASE "
8493 "label at %L", &p
->where
, &q
->where
);
8501 /* Add the next element to the merged list. */
8510 /* P has now stepped INSIZE places along, and so has Q. So
8511 they're the same. */
8516 /* If we have done only one merge or none at all, we've
8517 finished sorting the cases. */
8526 /* Otherwise repeat, merging lists twice the size. */
8532 /* Check to see if an expression is suitable for use in a CASE statement.
8533 Makes sure that all case expressions are scalar constants of the same
8534 type. Return false if anything is wrong. */
8537 validate_case_label_expr (gfc_expr
*e
, gfc_expr
*case_expr
)
8539 if (e
== NULL
) return true;
8541 if (e
->ts
.type
!= case_expr
->ts
.type
)
8543 gfc_error ("Expression in CASE statement at %L must be of type %s",
8544 &e
->where
, gfc_basic_typename (case_expr
->ts
.type
));
8548 /* C805 (R808) For a given case-construct, each case-value shall be of
8549 the same type as case-expr. For character type, length differences
8550 are allowed, but the kind type parameters shall be the same. */
8552 if (case_expr
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= case_expr
->ts
.kind
)
8554 gfc_error ("Expression in CASE statement at %L must be of kind %d",
8555 &e
->where
, case_expr
->ts
.kind
);
8559 /* Convert the case value kind to that of case expression kind,
8562 if (e
->ts
.kind
!= case_expr
->ts
.kind
)
8563 gfc_convert_type_warn (e
, &case_expr
->ts
, 2, 0);
8567 gfc_error ("Expression in CASE statement at %L must be scalar",
8576 /* Given a completely parsed select statement, we:
8578 - Validate all expressions and code within the SELECT.
8579 - Make sure that the selection expression is not of the wrong type.
8580 - Make sure that no case ranges overlap.
8581 - Eliminate unreachable cases and unreachable code resulting from
8582 removing case labels.
8584 The standard does allow unreachable cases, e.g. CASE (5:3). But
8585 they are a hassle for code generation, and to prevent that, we just
8586 cut them out here. This is not necessary for overlapping cases
8587 because they are illegal and we never even try to generate code.
8589 We have the additional caveat that a SELECT construct could have
8590 been a computed GOTO in the source code. Fortunately we can fairly
8591 easily work around that here: The case_expr for a "real" SELECT CASE
8592 is in code->expr1, but for a computed GOTO it is in code->expr2. All
8593 we have to do is make sure that the case_expr is a scalar integer
8597 resolve_select (gfc_code
*code
, bool select_type
)
8600 gfc_expr
*case_expr
;
8601 gfc_case
*cp
, *default_case
, *tail
, *head
;
8602 int seen_unreachable
;
8608 if (code
->expr1
== NULL
)
8610 /* This was actually a computed GOTO statement. */
8611 case_expr
= code
->expr2
;
8612 if (case_expr
->ts
.type
!= BT_INTEGER
|| case_expr
->rank
!= 0)
8613 gfc_error ("Selection expression in computed GOTO statement "
8614 "at %L must be a scalar integer expression",
8617 /* Further checking is not necessary because this SELECT was built
8618 by the compiler, so it should always be OK. Just move the
8619 case_expr from expr2 to expr so that we can handle computed
8620 GOTOs as normal SELECTs from here on. */
8621 code
->expr1
= code
->expr2
;
8626 case_expr
= code
->expr1
;
8627 type
= case_expr
->ts
.type
;
8630 if (type
!= BT_LOGICAL
&& type
!= BT_INTEGER
&& type
!= BT_CHARACTER
)
8632 gfc_error ("Argument of SELECT statement at %L cannot be %s",
8633 &case_expr
->where
, gfc_typename (case_expr
));
8635 /* Punt. Going on here just produce more garbage error messages. */
8640 if (!select_type
&& case_expr
->rank
!= 0)
8642 gfc_error ("Argument of SELECT statement at %L must be a scalar "
8643 "expression", &case_expr
->where
);
8649 /* Raise a warning if an INTEGER case value exceeds the range of
8650 the case-expr. Later, all expressions will be promoted to the
8651 largest kind of all case-labels. */
8653 if (type
== BT_INTEGER
)
8654 for (body
= code
->block
; body
; body
= body
->block
)
8655 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
8658 && gfc_check_integer_range (cp
->low
->value
.integer
,
8659 case_expr
->ts
.kind
) != ARITH_OK
)
8660 gfc_warning (0, "Expression in CASE statement at %L is "
8661 "not in the range of %s", &cp
->low
->where
,
8662 gfc_typename (case_expr
));
8665 && cp
->low
!= cp
->high
8666 && gfc_check_integer_range (cp
->high
->value
.integer
,
8667 case_expr
->ts
.kind
) != ARITH_OK
)
8668 gfc_warning (0, "Expression in CASE statement at %L is "
8669 "not in the range of %s", &cp
->high
->where
,
8670 gfc_typename (case_expr
));
8673 /* PR 19168 has a long discussion concerning a mismatch of the kinds
8674 of the SELECT CASE expression and its CASE values. Walk the lists
8675 of case values, and if we find a mismatch, promote case_expr to
8676 the appropriate kind. */
8678 if (type
== BT_LOGICAL
|| type
== BT_INTEGER
)
8680 for (body
= code
->block
; body
; body
= body
->block
)
8682 /* Walk the case label list. */
8683 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
8685 /* Intercept the DEFAULT case. It does not have a kind. */
8686 if (cp
->low
== NULL
&& cp
->high
== NULL
)
8689 /* Unreachable case ranges are discarded, so ignore. */
8690 if (cp
->low
!= NULL
&& cp
->high
!= NULL
8691 && cp
->low
!= cp
->high
8692 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
8696 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->low
))
8697 gfc_convert_type_warn (case_expr
, &cp
->low
->ts
, 2, 0);
8699 if (cp
->high
!= NULL
8700 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->high
))
8701 gfc_convert_type_warn (case_expr
, &cp
->high
->ts
, 2, 0);
8706 /* Assume there is no DEFAULT case. */
8707 default_case
= NULL
;
8712 for (body
= code
->block
; body
; body
= body
->block
)
8714 /* Assume the CASE list is OK, and all CASE labels can be matched. */
8716 seen_unreachable
= 0;
8718 /* Walk the case label list, making sure that all case labels
8720 for (cp
= body
->ext
.block
.case_list
; cp
; cp
= cp
->next
)
8722 /* Count the number of cases in the whole construct. */
8725 /* Intercept the DEFAULT case. */
8726 if (cp
->low
== NULL
&& cp
->high
== NULL
)
8728 if (default_case
!= NULL
)
8730 gfc_error ("The DEFAULT CASE at %L cannot be followed "
8731 "by a second DEFAULT CASE at %L",
8732 &default_case
->where
, &cp
->where
);
8743 /* Deal with single value cases and case ranges. Errors are
8744 issued from the validation function. */
8745 if (!validate_case_label_expr (cp
->low
, case_expr
)
8746 || !validate_case_label_expr (cp
->high
, case_expr
))
8752 if (type
== BT_LOGICAL
8753 && ((cp
->low
== NULL
|| cp
->high
== NULL
)
8754 || cp
->low
!= cp
->high
))
8756 gfc_error ("Logical range in CASE statement at %L is not "
8757 "allowed", &cp
->low
->where
);
8762 if (type
== BT_LOGICAL
&& cp
->low
->expr_type
== EXPR_CONSTANT
)
8765 value
= cp
->low
->value
.logical
== 0 ? 2 : 1;
8766 if (value
& seen_logical
)
8768 gfc_error ("Constant logical value in CASE statement "
8769 "is repeated at %L",
8774 seen_logical
|= value
;
8777 if (cp
->low
!= NULL
&& cp
->high
!= NULL
8778 && cp
->low
!= cp
->high
8779 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
8781 if (warn_surprising
)
8782 gfc_warning (OPT_Wsurprising
,
8783 "Range specification at %L can never be matched",
8786 cp
->unreachable
= 1;
8787 seen_unreachable
= 1;
8791 /* If the case range can be matched, it can also overlap with
8792 other cases. To make sure it does not, we put it in a
8793 double linked list here. We sort that with a merge sort
8794 later on to detect any overlapping cases. */
8798 head
->right
= head
->left
= NULL
;
8803 tail
->right
->left
= tail
;
8810 /* It there was a failure in the previous case label, give up
8811 for this case label list. Continue with the next block. */
8815 /* See if any case labels that are unreachable have been seen.
8816 If so, we eliminate them. This is a bit of a kludge because
8817 the case lists for a single case statement (label) is a
8818 single forward linked lists. */
8819 if (seen_unreachable
)
8821 /* Advance until the first case in the list is reachable. */
8822 while (body
->ext
.block
.case_list
!= NULL
8823 && body
->ext
.block
.case_list
->unreachable
)
8825 gfc_case
*n
= body
->ext
.block
.case_list
;
8826 body
->ext
.block
.case_list
= body
->ext
.block
.case_list
->next
;
8828 gfc_free_case_list (n
);
8831 /* Strip all other unreachable cases. */
8832 if (body
->ext
.block
.case_list
)
8834 for (cp
= body
->ext
.block
.case_list
; cp
&& cp
->next
; cp
= cp
->next
)
8836 if (cp
->next
->unreachable
)
8838 gfc_case
*n
= cp
->next
;
8839 cp
->next
= cp
->next
->next
;
8841 gfc_free_case_list (n
);
8848 /* See if there were overlapping cases. If the check returns NULL,
8849 there was overlap. In that case we don't do anything. If head
8850 is non-NULL, we prepend the DEFAULT case. The sorted list can
8851 then used during code generation for SELECT CASE constructs with
8852 a case expression of a CHARACTER type. */
8855 head
= check_case_overlap (head
);
8857 /* Prepend the default_case if it is there. */
8858 if (head
!= NULL
&& default_case
)
8860 default_case
->left
= NULL
;
8861 default_case
->right
= head
;
8862 head
->left
= default_case
;
8866 /* Eliminate dead blocks that may be the result if we've seen
8867 unreachable case labels for a block. */
8868 for (body
= code
; body
&& body
->block
; body
= body
->block
)
8870 if (body
->block
->ext
.block
.case_list
== NULL
)
8872 /* Cut the unreachable block from the code chain. */
8873 gfc_code
*c
= body
->block
;
8874 body
->block
= c
->block
;
8876 /* Kill the dead block, but not the blocks below it. */
8878 gfc_free_statements (c
);
8882 /* More than two cases is legal but insane for logical selects.
8883 Issue a warning for it. */
8884 if (warn_surprising
&& type
== BT_LOGICAL
&& ncases
> 2)
8885 gfc_warning (OPT_Wsurprising
,
8886 "Logical SELECT CASE block at %L has more that two cases",
8891 /* Check if a derived type is extensible. */
8894 gfc_type_is_extensible (gfc_symbol
*sym
)
8896 return !(sym
->attr
.is_bind_c
|| sym
->attr
.sequence
8897 || (sym
->attr
.is_class
8898 && sym
->components
->ts
.u
.derived
->attr
.unlimited_polymorphic
));
8903 resolve_types (gfc_namespace
*ns
);
8905 /* Resolve an associate-name: Resolve target and ensure the type-spec is
8906 correct as well as possibly the array-spec. */
8909 resolve_assoc_var (gfc_symbol
* sym
, bool resolve_target
)
8913 gcc_assert (sym
->assoc
);
8914 gcc_assert (sym
->attr
.flavor
== FL_VARIABLE
);
8916 /* If this is for SELECT TYPE, the target may not yet be set. In that
8917 case, return. Resolution will be called later manually again when
8919 target
= sym
->assoc
->target
;
8922 gcc_assert (!sym
->assoc
->dangling
);
8924 if (resolve_target
&& !gfc_resolve_expr (target
))
8927 /* For variable targets, we get some attributes from the target. */
8928 if (target
->expr_type
== EXPR_VARIABLE
)
8930 gfc_symbol
*tsym
, *dsym
;
8932 gcc_assert (target
->symtree
);
8933 tsym
= target
->symtree
->n
.sym
;
8935 if (gfc_expr_attr (target
).proc_pointer
)
8937 gfc_error ("Associating entity %qs at %L is a procedure pointer",
8938 tsym
->name
, &target
->where
);
8942 if (tsym
->attr
.flavor
== FL_PROCEDURE
&& tsym
->generic
8943 && (dsym
= gfc_find_dt_in_generic (tsym
)) != NULL
8944 && dsym
->attr
.flavor
== FL_DERIVED
)
8946 gfc_error ("Derived type %qs cannot be used as a variable at %L",
8947 tsym
->name
, &target
->where
);
8951 if (tsym
->attr
.flavor
== FL_PROCEDURE
)
8953 bool is_error
= true;
8954 if (tsym
->attr
.function
&& tsym
->result
== tsym
)
8955 for (gfc_namespace
*ns
= sym
->ns
; ns
; ns
= ns
->parent
)
8956 if (tsym
== ns
->proc_name
)
8963 gfc_error ("Associating entity %qs at %L is a procedure name",
8964 tsym
->name
, &target
->where
);
8969 sym
->attr
.asynchronous
= tsym
->attr
.asynchronous
;
8970 sym
->attr
.volatile_
= tsym
->attr
.volatile_
;
8972 sym
->attr
.target
= tsym
->attr
.target
8973 || gfc_expr_attr (target
).pointer
;
8974 if (is_subref_array (target
))
8975 sym
->attr
.subref_array_pointer
= 1;
8977 else if (target
->ts
.type
== BT_PROCEDURE
)
8979 gfc_error ("Associating selector-expression at %L yields a procedure",
8984 if (target
->expr_type
== EXPR_NULL
)
8986 gfc_error ("Selector at %L cannot be NULL()", &target
->where
);
8989 else if (target
->ts
.type
== BT_UNKNOWN
)
8991 gfc_error ("Selector at %L has no type", &target
->where
);
8995 /* Get type if this was not already set. Note that it can be
8996 some other type than the target in case this is a SELECT TYPE
8997 selector! So we must not update when the type is already there. */
8998 if (sym
->ts
.type
== BT_UNKNOWN
)
8999 sym
->ts
= target
->ts
;
9001 gcc_assert (sym
->ts
.type
!= BT_UNKNOWN
);
9003 /* See if this is a valid association-to-variable. */
9004 sym
->assoc
->variable
= (target
->expr_type
== EXPR_VARIABLE
9005 && !gfc_has_vector_subscript (target
));
9007 /* Finally resolve if this is an array or not. */
9008 if (sym
->attr
.dimension
&& target
->rank
== 0)
9010 /* primary.c makes the assumption that a reference to an associate
9011 name followed by a left parenthesis is an array reference. */
9012 if (sym
->ts
.type
!= BT_CHARACTER
)
9013 gfc_error ("Associate-name %qs at %L is used as array",
9014 sym
->name
, &sym
->declared_at
);
9015 sym
->attr
.dimension
= 0;
9020 /* We cannot deal with class selectors that need temporaries. */
9021 if (target
->ts
.type
== BT_CLASS
9022 && gfc_ref_needs_temporary_p (target
->ref
))
9024 gfc_error ("CLASS selector at %L needs a temporary which is not "
9025 "yet implemented", &target
->where
);
9029 if (target
->ts
.type
== BT_CLASS
)
9030 gfc_fix_class_refs (target
);
9032 if (target
->rank
!= 0 && !sym
->attr
.select_rank_temporary
)
9035 /* The rank may be incorrectly guessed at parsing, therefore make sure
9036 it is corrected now. */
9037 if (sym
->ts
.type
!= BT_CLASS
&& (!sym
->as
|| sym
->assoc
->rankguessed
))
9040 sym
->as
= gfc_get_array_spec ();
9042 as
->rank
= target
->rank
;
9043 as
->type
= AS_DEFERRED
;
9044 as
->corank
= gfc_get_corank (target
);
9045 sym
->attr
.dimension
= 1;
9046 if (as
->corank
!= 0)
9047 sym
->attr
.codimension
= 1;
9049 else if (sym
->ts
.type
== BT_CLASS
9051 && (!CLASS_DATA (sym
)->as
|| sym
->assoc
->rankguessed
))
9053 if (!CLASS_DATA (sym
)->as
)
9054 CLASS_DATA (sym
)->as
= gfc_get_array_spec ();
9055 as
= CLASS_DATA (sym
)->as
;
9056 as
->rank
= target
->rank
;
9057 as
->type
= AS_DEFERRED
;
9058 as
->corank
= gfc_get_corank (target
);
9059 CLASS_DATA (sym
)->attr
.dimension
= 1;
9060 if (as
->corank
!= 0)
9061 CLASS_DATA (sym
)->attr
.codimension
= 1;
9064 else if (!sym
->attr
.select_rank_temporary
)
9066 /* target's rank is 0, but the type of the sym is still array valued,
9067 which has to be corrected. */
9068 if (sym
->ts
.type
== BT_CLASS
&& sym
->ts
.u
.derived
9069 && CLASS_DATA (sym
) && CLASS_DATA (sym
)->as
)
9072 symbol_attribute attr
;
9073 /* The associated variable's type is still the array type
9074 correct this now. */
9075 gfc_typespec
*ts
= &target
->ts
;
9078 for (ref
= target
->ref
; ref
!= NULL
; ref
= ref
->next
)
9083 ts
= &ref
->u
.c
.component
->ts
;
9086 if (ts
->type
== BT_CLASS
)
9087 ts
= &ts
->u
.derived
->components
->ts
;
9093 /* Create a scalar instance of the current class type. Because the
9094 rank of a class array goes into its name, the type has to be
9095 rebuild. The alternative of (re-)setting just the attributes
9096 and as in the current type, destroys the type also in other
9100 sym
->ts
.type
= BT_CLASS
;
9101 attr
= CLASS_DATA (sym
) ? CLASS_DATA (sym
)->attr
: sym
->attr
;
9103 attr
.associate_var
= 1;
9104 attr
.dimension
= attr
.codimension
= 0;
9105 attr
.class_pointer
= 1;
9106 if (!gfc_build_class_symbol (&sym
->ts
, &attr
, &as
))
9108 /* Make sure the _vptr is set. */
9109 c
= gfc_find_component (sym
->ts
.u
.derived
, "_vptr", true, true, NULL
);
9110 if (c
->ts
.u
.derived
== NULL
)
9111 c
->ts
.u
.derived
= gfc_find_derived_vtab (sym
->ts
.u
.derived
);
9112 CLASS_DATA (sym
)->attr
.pointer
= 1;
9113 CLASS_DATA (sym
)->attr
.class_pointer
= 1;
9114 gfc_set_sym_referenced (sym
->ts
.u
.derived
);
9115 gfc_commit_symbol (sym
->ts
.u
.derived
);
9116 /* _vptr now has the _vtab in it, change it to the _vtype. */
9117 if (c
->ts
.u
.derived
->attr
.vtab
)
9118 c
->ts
.u
.derived
= c
->ts
.u
.derived
->ts
.u
.derived
;
9119 c
->ts
.u
.derived
->ns
->types_resolved
= 0;
9120 resolve_types (c
->ts
.u
.derived
->ns
);
9124 /* Mark this as an associate variable. */
9125 sym
->attr
.associate_var
= 1;
9127 /* Fix up the type-spec for CHARACTER types. */
9128 if (sym
->ts
.type
== BT_CHARACTER
&& !sym
->attr
.select_type_temporary
)
9131 sym
->ts
.u
.cl
= target
->ts
.u
.cl
;
9133 if (sym
->ts
.deferred
&& target
->expr_type
== EXPR_VARIABLE
9134 && target
->symtree
->n
.sym
->attr
.dummy
9135 && sym
->ts
.u
.cl
== target
->ts
.u
.cl
)
9137 sym
->ts
.u
.cl
= gfc_new_charlen (sym
->ns
, NULL
);
9138 sym
->ts
.deferred
= 1;
9141 if (!sym
->ts
.u
.cl
->length
9142 && !sym
->ts
.deferred
9143 && target
->expr_type
== EXPR_CONSTANT
)
9145 sym
->ts
.u
.cl
->length
=
9146 gfc_get_int_expr (gfc_charlen_int_kind
, NULL
,
9147 target
->value
.character
.length
);
9149 else if ((!sym
->ts
.u
.cl
->length
9150 || sym
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
9151 && target
->expr_type
!= EXPR_VARIABLE
)
9153 sym
->ts
.u
.cl
= gfc_new_charlen (sym
->ns
, NULL
);
9154 sym
->ts
.deferred
= 1;
9156 /* This is reset in trans-stmt.c after the assignment
9157 of the target expression to the associate name. */
9158 sym
->attr
.allocatable
= 1;
9162 /* If the target is a good class object, so is the associate variable. */
9163 if (sym
->ts
.type
== BT_CLASS
&& gfc_expr_attr (target
).class_ok
)
9164 sym
->attr
.class_ok
= 1;
9168 /* Ensure that SELECT TYPE expressions have the correct rank and a full
9169 array reference, where necessary. The symbols are artificial and so
9170 the dimension attribute and arrayspec can also be set. In addition,
9171 sometimes the expr1 arrives as BT_DERIVED, when the symbol is BT_CLASS.
9172 This is corrected here as well.*/
9175 fixup_array_ref (gfc_expr
**expr1
, gfc_expr
*expr2
,
9176 int rank
, gfc_ref
*ref
)
9178 gfc_ref
*nref
= (*expr1
)->ref
;
9179 gfc_symbol
*sym1
= (*expr1
)->symtree
->n
.sym
;
9180 gfc_symbol
*sym2
= expr2
? expr2
->symtree
->n
.sym
: NULL
;
9181 (*expr1
)->rank
= rank
;
9182 if (sym1
->ts
.type
== BT_CLASS
)
9184 if ((*expr1
)->ts
.type
!= BT_CLASS
)
9185 (*expr1
)->ts
= sym1
->ts
;
9187 CLASS_DATA (sym1
)->attr
.dimension
= 1;
9188 if (CLASS_DATA (sym1
)->as
== NULL
&& sym2
)
9189 CLASS_DATA (sym1
)->as
9190 = gfc_copy_array_spec (CLASS_DATA (sym2
)->as
);
9194 sym1
->attr
.dimension
= 1;
9195 if (sym1
->as
== NULL
&& sym2
)
9196 sym1
->as
= gfc_copy_array_spec (sym2
->as
);
9199 for (; nref
; nref
= nref
->next
)
9200 if (nref
->next
== NULL
)
9203 if (ref
&& nref
&& nref
->type
!= REF_ARRAY
)
9204 nref
->next
= gfc_copy_ref (ref
);
9205 else if (ref
&& !nref
)
9206 (*expr1
)->ref
= gfc_copy_ref (ref
);
9211 build_loc_call (gfc_expr
*sym_expr
)
9214 loc_call
= gfc_get_expr ();
9215 loc_call
->expr_type
= EXPR_FUNCTION
;
9216 gfc_get_sym_tree ("_loc", gfc_current_ns
, &loc_call
->symtree
, false);
9217 loc_call
->symtree
->n
.sym
->attr
.flavor
= FL_PROCEDURE
;
9218 loc_call
->symtree
->n
.sym
->attr
.intrinsic
= 1;
9219 loc_call
->symtree
->n
.sym
->result
= loc_call
->symtree
->n
.sym
;
9220 gfc_commit_symbol (loc_call
->symtree
->n
.sym
);
9221 loc_call
->ts
.type
= BT_INTEGER
;
9222 loc_call
->ts
.kind
= gfc_index_integer_kind
;
9223 loc_call
->value
.function
.isym
= gfc_intrinsic_function_by_id (GFC_ISYM_LOC
);
9224 loc_call
->value
.function
.actual
= gfc_get_actual_arglist ();
9225 loc_call
->value
.function
.actual
->expr
= sym_expr
;
9226 loc_call
->where
= sym_expr
->where
;
9230 /* Resolve a SELECT TYPE statement. */
9233 resolve_select_type (gfc_code
*code
, gfc_namespace
*old_ns
)
9235 gfc_symbol
*selector_type
;
9236 gfc_code
*body
, *new_st
, *if_st
, *tail
;
9237 gfc_code
*class_is
= NULL
, *default_case
= NULL
;
9240 char name
[GFC_MAX_SYMBOL_LEN
];
9244 gfc_ref
* ref
= NULL
;
9245 gfc_expr
*selector_expr
= NULL
;
9247 ns
= code
->ext
.block
.ns
;
9250 /* Check for F03:C813. */
9251 if (code
->expr1
->ts
.type
!= BT_CLASS
9252 && !(code
->expr2
&& code
->expr2
->ts
.type
== BT_CLASS
))
9254 gfc_error ("Selector shall be polymorphic in SELECT TYPE statement "
9255 "at %L", &code
->loc
);
9259 if (!code
->expr1
->symtree
->n
.sym
->attr
.class_ok
)
9264 gfc_ref
*ref2
= NULL
;
9265 for (ref
= code
->expr2
->ref
; ref
!= NULL
; ref
= ref
->next
)
9266 if (ref
->type
== REF_COMPONENT
9267 && ref
->u
.c
.component
->ts
.type
== BT_CLASS
)
9272 if (code
->expr1
->symtree
->n
.sym
->attr
.untyped
)
9273 code
->expr1
->symtree
->n
.sym
->ts
= ref2
->u
.c
.component
->ts
;
9274 selector_type
= CLASS_DATA (ref2
->u
.c
.component
)->ts
.u
.derived
;
9278 if (code
->expr1
->symtree
->n
.sym
->attr
.untyped
)
9279 code
->expr1
->symtree
->n
.sym
->ts
= code
->expr2
->ts
;
9280 selector_type
= CLASS_DATA (code
->expr2
)
9281 ? CLASS_DATA (code
->expr2
)->ts
.u
.derived
: code
->expr2
->ts
.u
.derived
;
9284 if (code
->expr2
->rank
9285 && code
->expr1
->ts
.type
== BT_CLASS
9286 && CLASS_DATA (code
->expr1
)->as
)
9287 CLASS_DATA (code
->expr1
)->as
->rank
= code
->expr2
->rank
;
9289 /* F2008: C803 The selector expression must not be coindexed. */
9290 if (gfc_is_coindexed (code
->expr2
))
9292 gfc_error ("Selector at %L must not be coindexed",
9293 &code
->expr2
->where
);
9300 selector_type
= CLASS_DATA (code
->expr1
)->ts
.u
.derived
;
9302 if (gfc_is_coindexed (code
->expr1
))
9304 gfc_error ("Selector at %L must not be coindexed",
9305 &code
->expr1
->where
);
9310 /* Loop over TYPE IS / CLASS IS cases. */
9311 for (body
= code
->block
; body
; body
= body
->block
)
9313 c
= body
->ext
.block
.case_list
;
9317 /* Check for repeated cases. */
9318 for (tail
= code
->block
; tail
; tail
= tail
->block
)
9320 gfc_case
*d
= tail
->ext
.block
.case_list
;
9324 if (c
->ts
.type
== d
->ts
.type
9325 && ((c
->ts
.type
== BT_DERIVED
9326 && c
->ts
.u
.derived
&& d
->ts
.u
.derived
9327 && !strcmp (c
->ts
.u
.derived
->name
,
9328 d
->ts
.u
.derived
->name
))
9329 || c
->ts
.type
== BT_UNKNOWN
9330 || (!(c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
9331 && c
->ts
.kind
== d
->ts
.kind
)))
9333 gfc_error ("TYPE IS at %L overlaps with TYPE IS at %L",
9334 &c
->where
, &d
->where
);
9340 /* Check F03:C815. */
9341 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
9342 && !selector_type
->attr
.unlimited_polymorphic
9343 && !gfc_type_is_extensible (c
->ts
.u
.derived
))
9345 gfc_error ("Derived type %qs at %L must be extensible",
9346 c
->ts
.u
.derived
->name
, &c
->where
);
9351 /* Check F03:C816. */
9352 if (c
->ts
.type
!= BT_UNKNOWN
&& !selector_type
->attr
.unlimited_polymorphic
9353 && ((c
->ts
.type
!= BT_DERIVED
&& c
->ts
.type
!= BT_CLASS
)
9354 || !gfc_type_is_extension_of (selector_type
, c
->ts
.u
.derived
)))
9356 if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
9357 gfc_error ("Derived type %qs at %L must be an extension of %qs",
9358 c
->ts
.u
.derived
->name
, &c
->where
, selector_type
->name
);
9360 gfc_error ("Unexpected intrinsic type %qs at %L",
9361 gfc_basic_typename (c
->ts
.type
), &c
->where
);
9366 /* Check F03:C814. */
9367 if (c
->ts
.type
== BT_CHARACTER
9368 && (c
->ts
.u
.cl
->length
!= NULL
|| c
->ts
.deferred
))
9370 gfc_error ("The type-spec at %L shall specify that each length "
9371 "type parameter is assumed", &c
->where
);
9376 /* Intercept the DEFAULT case. */
9377 if (c
->ts
.type
== BT_UNKNOWN
)
9379 /* Check F03:C818. */
9382 gfc_error ("The DEFAULT CASE at %L cannot be followed "
9383 "by a second DEFAULT CASE at %L",
9384 &default_case
->ext
.block
.case_list
->where
, &c
->where
);
9389 default_case
= body
;
9396 /* Transform SELECT TYPE statement to BLOCK and associate selector to
9397 target if present. If there are any EXIT statements referring to the
9398 SELECT TYPE construct, this is no problem because the gfc_code
9399 reference stays the same and EXIT is equally possible from the BLOCK
9400 it is changed to. */
9401 code
->op
= EXEC_BLOCK
;
9404 gfc_association_list
* assoc
;
9406 assoc
= gfc_get_association_list ();
9407 assoc
->st
= code
->expr1
->symtree
;
9408 assoc
->target
= gfc_copy_expr (code
->expr2
);
9409 assoc
->target
->where
= code
->expr2
->where
;
9410 /* assoc->variable will be set by resolve_assoc_var. */
9412 code
->ext
.block
.assoc
= assoc
;
9413 code
->expr1
->symtree
->n
.sym
->assoc
= assoc
;
9415 resolve_assoc_var (code
->expr1
->symtree
->n
.sym
, false);
9418 code
->ext
.block
.assoc
= NULL
;
9420 /* Ensure that the selector rank and arrayspec are available to
9421 correct expressions in which they might be missing. */
9422 if (code
->expr2
&& code
->expr2
->rank
)
9424 rank
= code
->expr2
->rank
;
9425 for (ref
= code
->expr2
->ref
; ref
; ref
= ref
->next
)
9426 if (ref
->next
== NULL
)
9428 if (ref
&& ref
->type
== REF_ARRAY
)
9429 ref
= gfc_copy_ref (ref
);
9431 /* Fixup expr1 if necessary. */
9433 fixup_array_ref (&code
->expr1
, code
->expr2
, rank
, ref
);
9435 else if (code
->expr1
->rank
)
9437 rank
= code
->expr1
->rank
;
9438 for (ref
= code
->expr1
->ref
; ref
; ref
= ref
->next
)
9439 if (ref
->next
== NULL
)
9441 if (ref
&& ref
->type
== REF_ARRAY
)
9442 ref
= gfc_copy_ref (ref
);
9445 /* Add EXEC_SELECT to switch on type. */
9446 new_st
= gfc_get_code (code
->op
);
9447 new_st
->expr1
= code
->expr1
;
9448 new_st
->expr2
= code
->expr2
;
9449 new_st
->block
= code
->block
;
9450 code
->expr1
= code
->expr2
= NULL
;
9455 ns
->code
->next
= new_st
;
9457 code
->op
= EXEC_SELECT_TYPE
;
9459 /* Use the intrinsic LOC function to generate an integer expression
9460 for the vtable of the selector. Note that the rank of the selector
9461 expression has to be set to zero. */
9462 gfc_add_vptr_component (code
->expr1
);
9463 code
->expr1
->rank
= 0;
9464 code
->expr1
= build_loc_call (code
->expr1
);
9465 selector_expr
= code
->expr1
->value
.function
.actual
->expr
;
9467 /* Loop over TYPE IS / CLASS IS cases. */
9468 for (body
= code
->block
; body
; body
= body
->block
)
9472 c
= body
->ext
.block
.case_list
;
9474 /* Generate an index integer expression for address of the
9475 TYPE/CLASS vtable and store it in c->low. The hash expression
9476 is stored in c->high and is used to resolve intrinsic cases. */
9477 if (c
->ts
.type
!= BT_UNKNOWN
)
9479 if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
9481 vtab
= gfc_find_derived_vtab (c
->ts
.u
.derived
);
9483 c
->high
= gfc_get_int_expr (gfc_integer_4_kind
, NULL
,
9484 c
->ts
.u
.derived
->hash_value
);
9488 vtab
= gfc_find_vtab (&c
->ts
);
9489 gcc_assert (vtab
&& CLASS_DATA (vtab
)->initializer
);
9490 e
= CLASS_DATA (vtab
)->initializer
;
9491 c
->high
= gfc_copy_expr (e
);
9492 if (c
->high
->ts
.kind
!= gfc_integer_4_kind
)
9495 ts
.kind
= gfc_integer_4_kind
;
9496 ts
.type
= BT_INTEGER
;
9497 gfc_convert_type_warn (c
->high
, &ts
, 2, 0);
9501 e
= gfc_lval_expr_from_sym (vtab
);
9502 c
->low
= build_loc_call (e
);
9507 /* Associate temporary to selector. This should only be done
9508 when this case is actually true, so build a new ASSOCIATE
9509 that does precisely this here (instead of using the
9512 if (c
->ts
.type
== BT_CLASS
)
9513 sprintf (name
, "__tmp_class_%s", c
->ts
.u
.derived
->name
);
9514 else if (c
->ts
.type
== BT_DERIVED
)
9515 sprintf (name
, "__tmp_type_%s", c
->ts
.u
.derived
->name
);
9516 else if (c
->ts
.type
== BT_CHARACTER
)
9518 HOST_WIDE_INT charlen
= 0;
9519 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
9520 && c
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9521 charlen
= gfc_mpz_get_hwi (c
->ts
.u
.cl
->length
->value
.integer
);
9522 snprintf (name
, sizeof (name
),
9523 "__tmp_%s_" HOST_WIDE_INT_PRINT_DEC
"_%d",
9524 gfc_basic_typename (c
->ts
.type
), charlen
, c
->ts
.kind
);
9527 sprintf (name
, "__tmp_%s_%d", gfc_basic_typename (c
->ts
.type
),
9530 st
= gfc_find_symtree (ns
->sym_root
, name
);
9531 gcc_assert (st
->n
.sym
->assoc
);
9532 st
->n
.sym
->assoc
->target
= gfc_get_variable_expr (selector_expr
->symtree
);
9533 st
->n
.sym
->assoc
->target
->where
= selector_expr
->where
;
9534 if (c
->ts
.type
!= BT_CLASS
&& c
->ts
.type
!= BT_UNKNOWN
)
9536 gfc_add_data_component (st
->n
.sym
->assoc
->target
);
9537 /* Fixup the target expression if necessary. */
9539 fixup_array_ref (&st
->n
.sym
->assoc
->target
, NULL
, rank
, ref
);
9542 new_st
= gfc_get_code (EXEC_BLOCK
);
9543 new_st
->ext
.block
.ns
= gfc_build_block_ns (ns
);
9544 new_st
->ext
.block
.ns
->code
= body
->next
;
9545 body
->next
= new_st
;
9547 /* Chain in the new list only if it is marked as dangling. Otherwise
9548 there is a CASE label overlap and this is already used. Just ignore,
9549 the error is diagnosed elsewhere. */
9550 if (st
->n
.sym
->assoc
->dangling
)
9552 new_st
->ext
.block
.assoc
= st
->n
.sym
->assoc
;
9553 st
->n
.sym
->assoc
->dangling
= 0;
9556 resolve_assoc_var (st
->n
.sym
, false);
9559 /* Take out CLASS IS cases for separate treatment. */
9561 while (body
&& body
->block
)
9563 if (body
->block
->ext
.block
.case_list
->ts
.type
== BT_CLASS
)
9565 /* Add to class_is list. */
9566 if (class_is
== NULL
)
9568 class_is
= body
->block
;
9573 for (tail
= class_is
; tail
->block
; tail
= tail
->block
) ;
9574 tail
->block
= body
->block
;
9577 /* Remove from EXEC_SELECT list. */
9578 body
->block
= body
->block
->block
;
9591 /* Add a default case to hold the CLASS IS cases. */
9592 for (tail
= code
; tail
->block
; tail
= tail
->block
) ;
9593 tail
->block
= gfc_get_code (EXEC_SELECT_TYPE
);
9595 tail
->ext
.block
.case_list
= gfc_get_case ();
9596 tail
->ext
.block
.case_list
->ts
.type
= BT_UNKNOWN
;
9598 default_case
= tail
;
9601 /* More than one CLASS IS block? */
9602 if (class_is
->block
)
9606 /* Sort CLASS IS blocks by extension level. */
9610 for (c1
= &class_is
; (*c1
) && (*c1
)->block
; c1
= &((*c1
)->block
))
9613 /* F03:C817 (check for doubles). */
9614 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->hash_value
9615 == c2
->ext
.block
.case_list
->ts
.u
.derived
->hash_value
)
9617 gfc_error ("Double CLASS IS block in SELECT TYPE "
9619 &c2
->ext
.block
.case_list
->where
);
9622 if ((*c1
)->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
9623 < c2
->ext
.block
.case_list
->ts
.u
.derived
->attr
.extension
)
9626 (*c1
)->block
= c2
->block
;
9636 /* Generate IF chain. */
9637 if_st
= gfc_get_code (EXEC_IF
);
9639 for (body
= class_is
; body
; body
= body
->block
)
9641 new_st
->block
= gfc_get_code (EXEC_IF
);
9642 new_st
= new_st
->block
;
9643 /* Set up IF condition: Call _gfortran_is_extension_of. */
9644 new_st
->expr1
= gfc_get_expr ();
9645 new_st
->expr1
->expr_type
= EXPR_FUNCTION
;
9646 new_st
->expr1
->ts
.type
= BT_LOGICAL
;
9647 new_st
->expr1
->ts
.kind
= 4;
9648 new_st
->expr1
->value
.function
.name
= gfc_get_string (PREFIX ("is_extension_of"));
9649 new_st
->expr1
->value
.function
.isym
= XCNEW (gfc_intrinsic_sym
);
9650 new_st
->expr1
->value
.function
.isym
->id
= GFC_ISYM_EXTENDS_TYPE_OF
;
9651 /* Set up arguments. */
9652 new_st
->expr1
->value
.function
.actual
= gfc_get_actual_arglist ();
9653 new_st
->expr1
->value
.function
.actual
->expr
= gfc_get_variable_expr (selector_expr
->symtree
);
9654 new_st
->expr1
->value
.function
.actual
->expr
->where
= code
->loc
;
9655 new_st
->expr1
->where
= code
->loc
;
9656 gfc_add_vptr_component (new_st
->expr1
->value
.function
.actual
->expr
);
9657 vtab
= gfc_find_derived_vtab (body
->ext
.block
.case_list
->ts
.u
.derived
);
9658 st
= gfc_find_symtree (vtab
->ns
->sym_root
, vtab
->name
);
9659 new_st
->expr1
->value
.function
.actual
->next
= gfc_get_actual_arglist ();
9660 new_st
->expr1
->value
.function
.actual
->next
->expr
= gfc_get_variable_expr (st
);
9661 new_st
->expr1
->value
.function
.actual
->next
->expr
->where
= code
->loc
;
9662 /* Set up types in formal arg list. */
9663 new_st
->expr1
->value
.function
.isym
->formal
= XCNEW (gfc_intrinsic_arg
);
9664 new_st
->expr1
->value
.function
.isym
->formal
->ts
= new_st
->expr1
->value
.function
.actual
->expr
->ts
;
9665 new_st
->expr1
->value
.function
.isym
->formal
->next
= XCNEW (gfc_intrinsic_arg
);
9666 new_st
->expr1
->value
.function
.isym
->formal
->next
->ts
= new_st
->expr1
->value
.function
.actual
->next
->expr
->ts
;
9668 new_st
->next
= body
->next
;
9670 if (default_case
->next
)
9672 new_st
->block
= gfc_get_code (EXEC_IF
);
9673 new_st
= new_st
->block
;
9674 new_st
->next
= default_case
->next
;
9677 /* Replace CLASS DEFAULT code by the IF chain. */
9678 default_case
->next
= if_st
;
9681 /* Resolve the internal code. This cannot be done earlier because
9682 it requires that the sym->assoc of selectors is set already. */
9683 gfc_current_ns
= ns
;
9684 gfc_resolve_blocks (code
->block
, gfc_current_ns
);
9685 gfc_current_ns
= old_ns
;
9692 /* Resolve a SELECT RANK statement. */
9695 resolve_select_rank (gfc_code
*code
, gfc_namespace
*old_ns
)
9698 gfc_code
*body
, *new_st
, *tail
;
9700 char tname
[GFC_MAX_SYMBOL_LEN
+ 7];
9701 char name
[2 * GFC_MAX_SYMBOL_LEN
];
9703 gfc_expr
*selector_expr
= NULL
;
9705 HOST_WIDE_INT charlen
= 0;
9707 ns
= code
->ext
.block
.ns
;
9710 code
->op
= EXEC_BLOCK
;
9713 gfc_association_list
* assoc
;
9715 assoc
= gfc_get_association_list ();
9716 assoc
->st
= code
->expr1
->symtree
;
9717 assoc
->target
= gfc_copy_expr (code
->expr2
);
9718 assoc
->target
->where
= code
->expr2
->where
;
9719 /* assoc->variable will be set by resolve_assoc_var. */
9721 code
->ext
.block
.assoc
= assoc
;
9722 code
->expr1
->symtree
->n
.sym
->assoc
= assoc
;
9724 resolve_assoc_var (code
->expr1
->symtree
->n
.sym
, false);
9727 code
->ext
.block
.assoc
= NULL
;
9729 /* Loop over RANK cases. Note that returning on the errors causes a
9730 cascade of further errors because the case blocks do not compile
9732 for (body
= code
->block
; body
; body
= body
->block
)
9734 c
= body
->ext
.block
.case_list
;
9736 case_value
= (int) mpz_get_si (c
->low
->value
.integer
);
9740 /* Check for repeated cases. */
9741 for (tail
= code
->block
; tail
; tail
= tail
->block
)
9743 gfc_case
*d
= tail
->ext
.block
.case_list
;
9749 /* Check F2018: C1153. */
9750 if (!c
->low
&& !d
->low
)
9751 gfc_error ("RANK DEFAULT at %L is repeated at %L",
9752 &c
->where
, &d
->where
);
9754 if (!c
->low
|| !d
->low
)
9757 /* Check F2018: C1153. */
9758 case_value2
= (int) mpz_get_si (d
->low
->value
.integer
);
9759 if ((case_value
== case_value2
) && case_value
== -1)
9760 gfc_error ("RANK (*) at %L is repeated at %L",
9761 &c
->where
, &d
->where
);
9762 else if (case_value
== case_value2
)
9763 gfc_error ("RANK (%i) at %L is repeated at %L",
9764 case_value
, &c
->where
, &d
->where
);
9770 /* Check F2018: C1155. */
9771 if (case_value
== -1 && (gfc_expr_attr (code
->expr1
).allocatable
9772 || gfc_expr_attr (code
->expr1
).pointer
))
9773 gfc_error ("RANK (*) at %L cannot be used with the pointer or "
9774 "allocatable selector at %L", &c
->where
, &code
->expr1
->where
);
9776 if (case_value
== -1 && (gfc_expr_attr (code
->expr1
).allocatable
9777 || gfc_expr_attr (code
->expr1
).pointer
))
9778 gfc_error ("RANK (*) at %L cannot be used with the pointer or "
9779 "allocatable selector at %L", &c
->where
, &code
->expr1
->where
);
9782 /* Add EXEC_SELECT to switch on rank. */
9783 new_st
= gfc_get_code (code
->op
);
9784 new_st
->expr1
= code
->expr1
;
9785 new_st
->expr2
= code
->expr2
;
9786 new_st
->block
= code
->block
;
9787 code
->expr1
= code
->expr2
= NULL
;
9792 ns
->code
->next
= new_st
;
9794 code
->op
= EXEC_SELECT_RANK
;
9796 selector_expr
= code
->expr1
;
9798 /* Loop over SELECT RANK cases. */
9799 for (body
= code
->block
; body
; body
= body
->block
)
9801 c
= body
->ext
.block
.case_list
;
9804 /* Pass on the default case. */
9808 /* Associate temporary to selector. This should only be done
9809 when this case is actually true, so build a new ASSOCIATE
9810 that does precisely this here (instead of using the
9812 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
9813 && c
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
9814 charlen
= gfc_mpz_get_hwi (c
->ts
.u
.cl
->length
->value
.integer
);
9816 if (c
->ts
.type
== BT_CLASS
)
9817 sprintf (tname
, "class_%s", c
->ts
.u
.derived
->name
);
9818 else if (c
->ts
.type
== BT_DERIVED
)
9819 sprintf (tname
, "type_%s", c
->ts
.u
.derived
->name
);
9820 else if (c
->ts
.type
!= BT_CHARACTER
)
9821 sprintf (tname
, "%s_%d", gfc_basic_typename (c
->ts
.type
), c
->ts
.kind
);
9823 sprintf (tname
, "%s_" HOST_WIDE_INT_PRINT_DEC
"_%d",
9824 gfc_basic_typename (c
->ts
.type
), charlen
, c
->ts
.kind
);
9826 case_value
= (int) mpz_get_si (c
->low
->value
.integer
);
9827 if (case_value
>= 0)
9828 sprintf (name
, "__tmp_%s_rank_%d", tname
, case_value
);
9830 sprintf (name
, "__tmp_%s_rank_m%d", tname
, -case_value
);
9832 st
= gfc_find_symtree (ns
->sym_root
, name
);
9833 gcc_assert (st
->n
.sym
->assoc
);
9835 st
->n
.sym
->assoc
->target
= gfc_get_variable_expr (selector_expr
->symtree
);
9836 st
->n
.sym
->assoc
->target
->where
= selector_expr
->where
;
9838 new_st
= gfc_get_code (EXEC_BLOCK
);
9839 new_st
->ext
.block
.ns
= gfc_build_block_ns (ns
);
9840 new_st
->ext
.block
.ns
->code
= body
->next
;
9841 body
->next
= new_st
;
9843 /* Chain in the new list only if it is marked as dangling. Otherwise
9844 there is a CASE label overlap and this is already used. Just ignore,
9845 the error is diagnosed elsewhere. */
9846 if (st
->n
.sym
->assoc
->dangling
)
9848 new_st
->ext
.block
.assoc
= st
->n
.sym
->assoc
;
9849 st
->n
.sym
->assoc
->dangling
= 0;
9852 resolve_assoc_var (st
->n
.sym
, false);
9855 gfc_current_ns
= ns
;
9856 gfc_resolve_blocks (code
->block
, gfc_current_ns
);
9857 gfc_current_ns
= old_ns
;
9861 /* Resolve a transfer statement. This is making sure that:
9862 -- a derived type being transferred has only non-pointer components
9863 -- a derived type being transferred doesn't have private components, unless
9864 it's being transferred from the module where the type was defined
9865 -- we're not trying to transfer a whole assumed size array. */
9868 resolve_transfer (gfc_code
*code
)
9870 gfc_symbol
*sym
, *derived
;
9874 bool formatted
= false;
9875 gfc_dt
*dt
= code
->ext
.dt
;
9876 gfc_symbol
*dtio_sub
= NULL
;
9880 while (exp
!= NULL
&& exp
->expr_type
== EXPR_OP
9881 && exp
->value
.op
.op
== INTRINSIC_PARENTHESES
)
9882 exp
= exp
->value
.op
.op1
;
9884 if (exp
&& exp
->expr_type
== EXPR_NULL
9887 gfc_error ("Invalid context for NULL () intrinsic at %L",
9892 if (exp
== NULL
|| (exp
->expr_type
!= EXPR_VARIABLE
9893 && exp
->expr_type
!= EXPR_FUNCTION
9894 && exp
->expr_type
!= EXPR_STRUCTURE
))
9897 /* If we are reading, the variable will be changed. Note that
9898 code->ext.dt may be NULL if the TRANSFER is related to
9899 an INQUIRE statement -- but in this case, we are not reading, either. */
9900 if (dt
&& dt
->dt_io_kind
->value
.iokind
== M_READ
9901 && !gfc_check_vardef_context (exp
, false, false, false,
9905 const gfc_typespec
*ts
= exp
->expr_type
== EXPR_STRUCTURE
9906 || exp
->expr_type
== EXPR_FUNCTION
9907 ? &exp
->ts
: &exp
->symtree
->n
.sym
->ts
;
9909 /* Go to actual component transferred. */
9910 for (ref
= exp
->ref
; ref
; ref
= ref
->next
)
9911 if (ref
->type
== REF_COMPONENT
)
9912 ts
= &ref
->u
.c
.component
->ts
;
9914 if (dt
&& dt
->dt_io_kind
->value
.iokind
!= M_INQUIRE
9915 && (ts
->type
== BT_DERIVED
|| ts
->type
== BT_CLASS
))
9917 derived
= ts
->u
.derived
;
9919 /* Determine when to use the formatted DTIO procedure. */
9920 if (dt
&& (dt
->format_expr
|| dt
->format_label
))
9923 write
= dt
->dt_io_kind
->value
.iokind
== M_WRITE
9924 || dt
->dt_io_kind
->value
.iokind
== M_PRINT
;
9925 dtio_sub
= gfc_find_specific_dtio_proc (derived
, write
, formatted
);
9927 if (dtio_sub
!= NULL
&& exp
->expr_type
== EXPR_VARIABLE
)
9930 sym
= exp
->symtree
->n
.sym
->ns
->proc_name
;
9931 /* Check to see if this is a nested DTIO call, with the
9932 dummy as the io-list object. */
9933 if (sym
&& sym
== dtio_sub
&& sym
->formal
9934 && sym
->formal
->sym
== exp
->symtree
->n
.sym
9935 && exp
->ref
== NULL
)
9937 if (!sym
->attr
.recursive
)
9939 gfc_error ("DTIO %s procedure at %L must be recursive",
9940 sym
->name
, &sym
->declared_at
);
9947 if (ts
->type
== BT_CLASS
&& dtio_sub
== NULL
)
9949 gfc_error ("Data transfer element at %L cannot be polymorphic unless "
9950 "it is processed by a defined input/output procedure",
9955 if (ts
->type
== BT_DERIVED
)
9957 /* Check that transferred derived type doesn't contain POINTER
9958 components unless it is processed by a defined input/output
9960 if (ts
->u
.derived
->attr
.pointer_comp
&& dtio_sub
== NULL
)
9962 gfc_error ("Data transfer element at %L cannot have POINTER "
9963 "components unless it is processed by a defined "
9964 "input/output procedure", &code
->loc
);
9969 if (ts
->u
.derived
->attr
.proc_pointer_comp
)
9971 gfc_error ("Data transfer element at %L cannot have "
9972 "procedure pointer components", &code
->loc
);
9976 if (ts
->u
.derived
->attr
.alloc_comp
&& dtio_sub
== NULL
)
9978 gfc_error ("Data transfer element at %L cannot have ALLOCATABLE "
9979 "components unless it is processed by a defined "
9980 "input/output procedure", &code
->loc
);
9984 /* C_PTR and C_FUNPTR have private components which means they cannot
9985 be printed. However, if -std=gnu and not -pedantic, allow
9986 the component to be printed to help debugging. */
9987 if (ts
->u
.derived
->ts
.f90_type
== BT_VOID
)
9989 if (!gfc_notify_std (GFC_STD_GNU
, "Data transfer element at %L "
9990 "cannot have PRIVATE components", &code
->loc
))
9993 else if (derived_inaccessible (ts
->u
.derived
) && dtio_sub
== NULL
)
9995 gfc_error ("Data transfer element at %L cannot have "
9996 "PRIVATE components unless it is processed by "
9997 "a defined input/output procedure", &code
->loc
);
10002 if (exp
->expr_type
== EXPR_STRUCTURE
)
10005 sym
= exp
->symtree
->n
.sym
;
10007 if (sym
->as
!= NULL
&& sym
->as
->type
== AS_ASSUMED_SIZE
&& exp
->ref
10008 && exp
->ref
->type
== REF_ARRAY
&& exp
->ref
->u
.ar
.type
== AR_FULL
)
10010 gfc_error ("Data transfer element at %L cannot be a full reference to "
10011 "an assumed-size array", &code
->loc
);
10017 /*********** Toplevel code resolution subroutines ***********/
10019 /* Find the set of labels that are reachable from this block. We also
10020 record the last statement in each block. */
10023 find_reachable_labels (gfc_code
*block
)
10030 cs_base
->reachable_labels
= bitmap_alloc (&labels_obstack
);
10032 /* Collect labels in this block. We don't keep those corresponding
10033 to END {IF|SELECT}, these are checked in resolve_branch by going
10034 up through the code_stack. */
10035 for (c
= block
; c
; c
= c
->next
)
10037 if (c
->here
&& c
->op
!= EXEC_END_NESTED_BLOCK
)
10038 bitmap_set_bit (cs_base
->reachable_labels
, c
->here
->value
);
10041 /* Merge with labels from parent block. */
10044 gcc_assert (cs_base
->prev
->reachable_labels
);
10045 bitmap_ior_into (cs_base
->reachable_labels
,
10046 cs_base
->prev
->reachable_labels
);
10052 resolve_lock_unlock_event (gfc_code
*code
)
10054 if (code
->expr1
->expr_type
== EXPR_FUNCTION
10055 && code
->expr1
->value
.function
.isym
10056 && code
->expr1
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
10057 remove_caf_get_intrinsic (code
->expr1
);
10059 if ((code
->op
== EXEC_LOCK
|| code
->op
== EXEC_UNLOCK
)
10060 && (code
->expr1
->ts
.type
!= BT_DERIVED
10061 || code
->expr1
->expr_type
!= EXPR_VARIABLE
10062 || code
->expr1
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
10063 || code
->expr1
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_LOCK_TYPE
10064 || code
->expr1
->rank
!= 0
10065 || (!gfc_is_coarray (code
->expr1
) &&
10066 !gfc_is_coindexed (code
->expr1
))))
10067 gfc_error ("Lock variable at %L must be a scalar of type LOCK_TYPE",
10068 &code
->expr1
->where
);
10069 else if ((code
->op
== EXEC_EVENT_POST
|| code
->op
== EXEC_EVENT_WAIT
)
10070 && (code
->expr1
->ts
.type
!= BT_DERIVED
10071 || code
->expr1
->expr_type
!= EXPR_VARIABLE
10072 || code
->expr1
->ts
.u
.derived
->from_intmod
10073 != INTMOD_ISO_FORTRAN_ENV
10074 || code
->expr1
->ts
.u
.derived
->intmod_sym_id
10075 != ISOFORTRAN_EVENT_TYPE
10076 || code
->expr1
->rank
!= 0))
10077 gfc_error ("Event variable at %L must be a scalar of type EVENT_TYPE",
10078 &code
->expr1
->where
);
10079 else if (code
->op
== EXEC_EVENT_POST
&& !gfc_is_coarray (code
->expr1
)
10080 && !gfc_is_coindexed (code
->expr1
))
10081 gfc_error ("Event variable argument at %L must be a coarray or coindexed",
10082 &code
->expr1
->where
);
10083 else if (code
->op
== EXEC_EVENT_WAIT
&& !gfc_is_coarray (code
->expr1
))
10084 gfc_error ("Event variable argument at %L must be a coarray but not "
10085 "coindexed", &code
->expr1
->where
);
10089 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
10090 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
10091 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
10092 &code
->expr2
->where
);
10095 && !gfc_check_vardef_context (code
->expr2
, false, false, false,
10096 _("STAT variable")))
10099 /* Check ERRMSG. */
10101 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
10102 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
10103 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
10104 &code
->expr3
->where
);
10107 && !gfc_check_vardef_context (code
->expr3
, false, false, false,
10108 _("ERRMSG variable")))
10111 /* Check for LOCK the ACQUIRED_LOCK. */
10112 if (code
->op
!= EXEC_EVENT_WAIT
&& code
->expr4
10113 && (code
->expr4
->ts
.type
!= BT_LOGICAL
|| code
->expr4
->rank
!= 0
10114 || code
->expr4
->expr_type
!= EXPR_VARIABLE
))
10115 gfc_error ("ACQUIRED_LOCK= argument at %L must be a scalar LOGICAL "
10116 "variable", &code
->expr4
->where
);
10118 if (code
->op
!= EXEC_EVENT_WAIT
&& code
->expr4
10119 && !gfc_check_vardef_context (code
->expr4
, false, false, false,
10120 _("ACQUIRED_LOCK variable")))
10123 /* Check for EVENT WAIT the UNTIL_COUNT. */
10124 if (code
->op
== EXEC_EVENT_WAIT
&& code
->expr4
)
10126 if (!gfc_resolve_expr (code
->expr4
) || code
->expr4
->ts
.type
!= BT_INTEGER
10127 || code
->expr4
->rank
!= 0)
10128 gfc_error ("UNTIL_COUNT= argument at %L must be a scalar INTEGER "
10129 "expression", &code
->expr4
->where
);
10135 resolve_critical (gfc_code
*code
)
10137 gfc_symtree
*symtree
;
10138 gfc_symbol
*lock_type
;
10139 char name
[GFC_MAX_SYMBOL_LEN
];
10140 static int serial
= 0;
10142 if (flag_coarray
!= GFC_FCOARRAY_LIB
)
10145 symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
10146 GFC_PREFIX ("lock_type"));
10148 lock_type
= symtree
->n
.sym
;
10151 if (gfc_get_sym_tree (GFC_PREFIX ("lock_type"), gfc_current_ns
, &symtree
,
10153 gcc_unreachable ();
10154 lock_type
= symtree
->n
.sym
;
10155 lock_type
->attr
.flavor
= FL_DERIVED
;
10156 lock_type
->attr
.zero_comp
= 1;
10157 lock_type
->from_intmod
= INTMOD_ISO_FORTRAN_ENV
;
10158 lock_type
->intmod_sym_id
= ISOFORTRAN_LOCK_TYPE
;
10161 sprintf(name
, GFC_PREFIX ("lock_var") "%d",serial
++);
10162 if (gfc_get_sym_tree (name
, gfc_current_ns
, &symtree
, false) != 0)
10163 gcc_unreachable ();
10165 code
->resolved_sym
= symtree
->n
.sym
;
10166 symtree
->n
.sym
->attr
.flavor
= FL_VARIABLE
;
10167 symtree
->n
.sym
->attr
.referenced
= 1;
10168 symtree
->n
.sym
->attr
.artificial
= 1;
10169 symtree
->n
.sym
->attr
.codimension
= 1;
10170 symtree
->n
.sym
->ts
.type
= BT_DERIVED
;
10171 symtree
->n
.sym
->ts
.u
.derived
= lock_type
;
10172 symtree
->n
.sym
->as
= gfc_get_array_spec ();
10173 symtree
->n
.sym
->as
->corank
= 1;
10174 symtree
->n
.sym
->as
->type
= AS_EXPLICIT
;
10175 symtree
->n
.sym
->as
->cotype
= AS_EXPLICIT
;
10176 symtree
->n
.sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
,
10178 gfc_commit_symbols();
10183 resolve_sync (gfc_code
*code
)
10185 /* Check imageset. The * case matches expr1 == NULL. */
10188 if (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
> 1)
10189 gfc_error ("Imageset argument at %L must be a scalar or rank-1 "
10190 "INTEGER expression", &code
->expr1
->where
);
10191 if (code
->expr1
->expr_type
== EXPR_CONSTANT
&& code
->expr1
->rank
== 0
10192 && mpz_cmp_si (code
->expr1
->value
.integer
, 1) < 0)
10193 gfc_error ("Imageset argument at %L must between 1 and num_images()",
10194 &code
->expr1
->where
);
10195 else if (code
->expr1
->expr_type
== EXPR_ARRAY
10196 && gfc_simplify_expr (code
->expr1
, 0))
10198 gfc_constructor
*cons
;
10199 cons
= gfc_constructor_first (code
->expr1
->value
.constructor
);
10200 for (; cons
; cons
= gfc_constructor_next (cons
))
10201 if (cons
->expr
->expr_type
== EXPR_CONSTANT
10202 && mpz_cmp_si (cons
->expr
->value
.integer
, 1) < 0)
10203 gfc_error ("Imageset argument at %L must between 1 and "
10204 "num_images()", &cons
->expr
->where
);
10209 gfc_resolve_expr (code
->expr2
);
10211 && (code
->expr2
->ts
.type
!= BT_INTEGER
|| code
->expr2
->rank
!= 0
10212 || code
->expr2
->expr_type
!= EXPR_VARIABLE
))
10213 gfc_error ("STAT= argument at %L must be a scalar INTEGER variable",
10214 &code
->expr2
->where
);
10216 /* Check ERRMSG. */
10217 gfc_resolve_expr (code
->expr3
);
10219 && (code
->expr3
->ts
.type
!= BT_CHARACTER
|| code
->expr3
->rank
!= 0
10220 || code
->expr3
->expr_type
!= EXPR_VARIABLE
))
10221 gfc_error ("ERRMSG= argument at %L must be a scalar CHARACTER variable",
10222 &code
->expr3
->where
);
10226 /* Given a branch to a label, see if the branch is conforming.
10227 The code node describes where the branch is located. */
10230 resolve_branch (gfc_st_label
*label
, gfc_code
*code
)
10237 /* Step one: is this a valid branching target? */
10239 if (label
->defined
== ST_LABEL_UNKNOWN
)
10241 gfc_error ("Label %d referenced at %L is never defined", label
->value
,
10246 if (label
->defined
!= ST_LABEL_TARGET
&& label
->defined
!= ST_LABEL_DO_TARGET
)
10248 gfc_error ("Statement at %L is not a valid branch target statement "
10249 "for the branch statement at %L", &label
->where
, &code
->loc
);
10253 /* Step two: make sure this branch is not a branch to itself ;-) */
10255 if (code
->here
== label
)
10258 "Branch at %L may result in an infinite loop", &code
->loc
);
10262 /* Step three: See if the label is in the same block as the
10263 branching statement. The hard work has been done by setting up
10264 the bitmap reachable_labels. */
10266 if (bitmap_bit_p (cs_base
->reachable_labels
, label
->value
))
10268 /* Check now whether there is a CRITICAL construct; if so, check
10269 whether the label is still visible outside of the CRITICAL block,
10270 which is invalid. */
10271 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
10273 if (stack
->current
->op
== EXEC_CRITICAL
10274 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
10275 gfc_error ("GOTO statement at %L leaves CRITICAL construct for "
10276 "label at %L", &code
->loc
, &label
->where
);
10277 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
10278 && bitmap_bit_p (stack
->reachable_labels
, label
->value
))
10279 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct "
10280 "for label at %L", &code
->loc
, &label
->where
);
10286 /* Step four: If we haven't found the label in the bitmap, it may
10287 still be the label of the END of the enclosing block, in which
10288 case we find it by going up the code_stack. */
10290 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
10292 if (stack
->current
->next
&& stack
->current
->next
->here
== label
)
10294 if (stack
->current
->op
== EXEC_CRITICAL
)
10296 /* Note: A label at END CRITICAL does not leave the CRITICAL
10297 construct as END CRITICAL is still part of it. */
10298 gfc_error ("GOTO statement at %L leaves CRITICAL construct for label"
10299 " at %L", &code
->loc
, &label
->where
);
10302 else if (stack
->current
->op
== EXEC_DO_CONCURRENT
)
10304 gfc_error ("GOTO statement at %L leaves DO CONCURRENT construct for "
10305 "label at %L", &code
->loc
, &label
->where
);
10312 gcc_assert (stack
->current
->next
->op
== EXEC_END_NESTED_BLOCK
);
10316 /* The label is not in an enclosing block, so illegal. This was
10317 allowed in Fortran 66, so we allow it as extension. No
10318 further checks are necessary in this case. */
10319 gfc_notify_std (GFC_STD_LEGACY
, "Label at %L is not in the same block "
10320 "as the GOTO statement at %L", &label
->where
,
10326 /* Check whether EXPR1 has the same shape as EXPR2. */
10329 resolve_where_shape (gfc_expr
*expr1
, gfc_expr
*expr2
)
10331 mpz_t shape
[GFC_MAX_DIMENSIONS
];
10332 mpz_t shape2
[GFC_MAX_DIMENSIONS
];
10333 bool result
= false;
10336 /* Compare the rank. */
10337 if (expr1
->rank
!= expr2
->rank
)
10340 /* Compare the size of each dimension. */
10341 for (i
=0; i
<expr1
->rank
; i
++)
10343 if (!gfc_array_dimen_size (expr1
, i
, &shape
[i
]))
10346 if (!gfc_array_dimen_size (expr2
, i
, &shape2
[i
]))
10349 if (mpz_cmp (shape
[i
], shape2
[i
]))
10353 /* When either of the two expression is an assumed size array, we
10354 ignore the comparison of dimension sizes. */
10359 gfc_clear_shape (shape
, i
);
10360 gfc_clear_shape (shape2
, i
);
10365 /* Check whether a WHERE assignment target or a WHERE mask expression
10366 has the same shape as the outmost WHERE mask expression. */
10369 resolve_where (gfc_code
*code
, gfc_expr
*mask
)
10373 gfc_expr
*e
= NULL
;
10375 cblock
= code
->block
;
10377 /* Store the first WHERE mask-expr of the WHERE statement or construct.
10378 In case of nested WHERE, only the outmost one is stored. */
10379 if (mask
== NULL
) /* outmost WHERE */
10381 else /* inner WHERE */
10388 /* Check if the mask-expr has a consistent shape with the
10389 outmost WHERE mask-expr. */
10390 if (!resolve_where_shape (cblock
->expr1
, e
))
10391 gfc_error ("WHERE mask at %L has inconsistent shape",
10392 &cblock
->expr1
->where
);
10395 /* the assignment statement of a WHERE statement, or the first
10396 statement in where-body-construct of a WHERE construct */
10397 cnext
= cblock
->next
;
10402 /* WHERE assignment statement */
10405 /* Check shape consistent for WHERE assignment target. */
10406 if (e
&& !resolve_where_shape (cnext
->expr1
, e
))
10407 gfc_error ("WHERE assignment target at %L has "
10408 "inconsistent shape", &cnext
->expr1
->where
);
10412 case EXEC_ASSIGN_CALL
:
10413 resolve_call (cnext
);
10414 if (!cnext
->resolved_sym
->attr
.elemental
)
10415 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
10416 &cnext
->ext
.actual
->expr
->where
);
10419 /* WHERE or WHERE construct is part of a where-body-construct */
10421 resolve_where (cnext
, e
);
10425 gfc_error ("Unsupported statement inside WHERE at %L",
10428 /* the next statement within the same where-body-construct */
10429 cnext
= cnext
->next
;
10431 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
10432 cblock
= cblock
->block
;
10437 /* Resolve assignment in FORALL construct.
10438 NVAR is the number of FORALL index variables, and VAR_EXPR records the
10439 FORALL index variables. */
10442 gfc_resolve_assign_in_forall (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
10446 for (n
= 0; n
< nvar
; n
++)
10448 gfc_symbol
*forall_index
;
10450 forall_index
= var_expr
[n
]->symtree
->n
.sym
;
10452 /* Check whether the assignment target is one of the FORALL index
10454 if ((code
->expr1
->expr_type
== EXPR_VARIABLE
)
10455 && (code
->expr1
->symtree
->n
.sym
== forall_index
))
10456 gfc_error ("Assignment to a FORALL index variable at %L",
10457 &code
->expr1
->where
);
10460 /* If one of the FORALL index variables doesn't appear in the
10461 assignment variable, then there could be a many-to-one
10462 assignment. Emit a warning rather than an error because the
10463 mask could be resolving this problem. */
10464 if (!find_forall_index (code
->expr1
, forall_index
, 0))
10465 gfc_warning (0, "The FORALL with index %qs is not used on the "
10466 "left side of the assignment at %L and so might "
10467 "cause multiple assignment to this object",
10468 var_expr
[n
]->symtree
->name
, &code
->expr1
->where
);
10474 /* Resolve WHERE statement in FORALL construct. */
10477 gfc_resolve_where_code_in_forall (gfc_code
*code
, int nvar
,
10478 gfc_expr
**var_expr
)
10483 cblock
= code
->block
;
10486 /* the assignment statement of a WHERE statement, or the first
10487 statement in where-body-construct of a WHERE construct */
10488 cnext
= cblock
->next
;
10493 /* WHERE assignment statement */
10495 gfc_resolve_assign_in_forall (cnext
, nvar
, var_expr
);
10498 /* WHERE operator assignment statement */
10499 case EXEC_ASSIGN_CALL
:
10500 resolve_call (cnext
);
10501 if (!cnext
->resolved_sym
->attr
.elemental
)
10502 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
10503 &cnext
->ext
.actual
->expr
->where
);
10506 /* WHERE or WHERE construct is part of a where-body-construct */
10508 gfc_resolve_where_code_in_forall (cnext
, nvar
, var_expr
);
10512 gfc_error ("Unsupported statement inside WHERE at %L",
10515 /* the next statement within the same where-body-construct */
10516 cnext
= cnext
->next
;
10518 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
10519 cblock
= cblock
->block
;
10524 /* Traverse the FORALL body to check whether the following errors exist:
10525 1. For assignment, check if a many-to-one assignment happens.
10526 2. For WHERE statement, check the WHERE body to see if there is any
10527 many-to-one assignment. */
10530 gfc_resolve_forall_body (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
10534 c
= code
->block
->next
;
10540 case EXEC_POINTER_ASSIGN
:
10541 gfc_resolve_assign_in_forall (c
, nvar
, var_expr
);
10544 case EXEC_ASSIGN_CALL
:
10548 /* Because the gfc_resolve_blocks() will handle the nested FORALL,
10549 there is no need to handle it here. */
10553 gfc_resolve_where_code_in_forall(c
, nvar
, var_expr
);
10558 /* The next statement in the FORALL body. */
10564 /* Counts the number of iterators needed inside a forall construct, including
10565 nested forall constructs. This is used to allocate the needed memory
10566 in gfc_resolve_forall. */
10569 gfc_count_forall_iterators (gfc_code
*code
)
10571 int max_iters
, sub_iters
, current_iters
;
10572 gfc_forall_iterator
*fa
;
10574 gcc_assert(code
->op
== EXEC_FORALL
);
10578 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
10581 code
= code
->block
->next
;
10585 if (code
->op
== EXEC_FORALL
)
10587 sub_iters
= gfc_count_forall_iterators (code
);
10588 if (sub_iters
> max_iters
)
10589 max_iters
= sub_iters
;
10594 return current_iters
+ max_iters
;
10598 /* Given a FORALL construct, first resolve the FORALL iterator, then call
10599 gfc_resolve_forall_body to resolve the FORALL body. */
10602 gfc_resolve_forall (gfc_code
*code
, gfc_namespace
*ns
, int forall_save
)
10604 static gfc_expr
**var_expr
;
10605 static int total_var
= 0;
10606 static int nvar
= 0;
10607 int i
, old_nvar
, tmp
;
10608 gfc_forall_iterator
*fa
;
10612 if (!gfc_notify_std (GFC_STD_F2018_OBS
, "FORALL construct at %L", &code
->loc
))
10615 /* Start to resolve a FORALL construct */
10616 if (forall_save
== 0)
10618 /* Count the total number of FORALL indices in the nested FORALL
10619 construct in order to allocate the VAR_EXPR with proper size. */
10620 total_var
= gfc_count_forall_iterators (code
);
10622 /* Allocate VAR_EXPR with NUMBER_OF_FORALL_INDEX elements. */
10623 var_expr
= XCNEWVEC (gfc_expr
*, total_var
);
10626 /* The information about FORALL iterator, including FORALL indices start, end
10627 and stride. An outer FORALL indice cannot appear in start, end or stride. */
10628 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
10630 /* Fortran 20008: C738 (R753). */
10631 if (fa
->var
->ref
&& fa
->var
->ref
->type
== REF_ARRAY
)
10633 gfc_error ("FORALL index-name at %L must be a scalar variable "
10634 "of type integer", &fa
->var
->where
);
10638 /* Check if any outer FORALL index name is the same as the current
10640 for (i
= 0; i
< nvar
; i
++)
10642 if (fa
->var
->symtree
->n
.sym
== var_expr
[i
]->symtree
->n
.sym
)
10643 gfc_error ("An outer FORALL construct already has an index "
10644 "with this name %L", &fa
->var
->where
);
10647 /* Record the current FORALL index. */
10648 var_expr
[nvar
] = gfc_copy_expr (fa
->var
);
10652 /* No memory leak. */
10653 gcc_assert (nvar
<= total_var
);
10656 /* Resolve the FORALL body. */
10657 gfc_resolve_forall_body (code
, nvar
, var_expr
);
10659 /* May call gfc_resolve_forall to resolve the inner FORALL loop. */
10660 gfc_resolve_blocks (code
->block
, ns
);
10664 /* Free only the VAR_EXPRs allocated in this frame. */
10665 for (i
= nvar
; i
< tmp
; i
++)
10666 gfc_free_expr (var_expr
[i
]);
10670 /* We are in the outermost FORALL construct. */
10671 gcc_assert (forall_save
== 0);
10673 /* VAR_EXPR is not needed any more. */
10680 /* Resolve a BLOCK construct statement. */
10683 resolve_block_construct (gfc_code
* code
)
10685 /* Resolve the BLOCK's namespace. */
10686 gfc_resolve (code
->ext
.block
.ns
);
10688 /* For an ASSOCIATE block, the associations (and their targets) are already
10689 resolved during resolve_symbol. */
10693 /* Resolve lists of blocks found in IF, SELECT CASE, WHERE, FORALL, GOTO and
10697 gfc_resolve_blocks (gfc_code
*b
, gfc_namespace
*ns
)
10701 for (; b
; b
= b
->block
)
10703 t
= gfc_resolve_expr (b
->expr1
);
10704 if (!gfc_resolve_expr (b
->expr2
))
10710 if (t
&& b
->expr1
!= NULL
10711 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
!= 0))
10712 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
10718 && b
->expr1
!= NULL
10719 && (b
->expr1
->ts
.type
!= BT_LOGICAL
|| b
->expr1
->rank
== 0))
10720 gfc_error ("WHERE/ELSEWHERE clause at %L requires a LOGICAL array",
10725 resolve_branch (b
->label1
, b
);
10729 resolve_block_construct (b
);
10733 case EXEC_SELECT_TYPE
:
10734 case EXEC_SELECT_RANK
:
10737 case EXEC_DO_WHILE
:
10738 case EXEC_DO_CONCURRENT
:
10739 case EXEC_CRITICAL
:
10742 case EXEC_IOLENGTH
:
10746 case EXEC_OMP_ATOMIC
:
10747 case EXEC_OACC_ATOMIC
:
10749 /* Verify this before calling gfc_resolve_code, which might
10751 gcc_assert (b
->next
&& b
->next
->op
== EXEC_ASSIGN
);
10752 gcc_assert ((!b
->ext
.omp_clauses
->capture
10753 && b
->next
->next
== NULL
)
10754 || (b
->ext
.omp_clauses
->capture
10755 && b
->next
->next
!= NULL
10756 && b
->next
->next
->op
== EXEC_ASSIGN
10757 && b
->next
->next
->next
== NULL
));
10761 case EXEC_OACC_PARALLEL_LOOP
:
10762 case EXEC_OACC_PARALLEL
:
10763 case EXEC_OACC_KERNELS_LOOP
:
10764 case EXEC_OACC_KERNELS
:
10765 case EXEC_OACC_SERIAL_LOOP
:
10766 case EXEC_OACC_SERIAL
:
10767 case EXEC_OACC_DATA
:
10768 case EXEC_OACC_HOST_DATA
:
10769 case EXEC_OACC_LOOP
:
10770 case EXEC_OACC_UPDATE
:
10771 case EXEC_OACC_WAIT
:
10772 case EXEC_OACC_CACHE
:
10773 case EXEC_OACC_ENTER_DATA
:
10774 case EXEC_OACC_EXIT_DATA
:
10775 case EXEC_OACC_ROUTINE
:
10776 case EXEC_OMP_CRITICAL
:
10777 case EXEC_OMP_DISTRIBUTE
:
10778 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
10779 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
10780 case EXEC_OMP_DISTRIBUTE_SIMD
:
10782 case EXEC_OMP_DO_SIMD
:
10783 case EXEC_OMP_MASTER
:
10784 case EXEC_OMP_ORDERED
:
10785 case EXEC_OMP_PARALLEL
:
10786 case EXEC_OMP_PARALLEL_DO
:
10787 case EXEC_OMP_PARALLEL_DO_SIMD
:
10788 case EXEC_OMP_PARALLEL_SECTIONS
:
10789 case EXEC_OMP_PARALLEL_WORKSHARE
:
10790 case EXEC_OMP_SECTIONS
:
10791 case EXEC_OMP_SIMD
:
10792 case EXEC_OMP_SINGLE
:
10793 case EXEC_OMP_TARGET
:
10794 case EXEC_OMP_TARGET_DATA
:
10795 case EXEC_OMP_TARGET_ENTER_DATA
:
10796 case EXEC_OMP_TARGET_EXIT_DATA
:
10797 case EXEC_OMP_TARGET_PARALLEL
:
10798 case EXEC_OMP_TARGET_PARALLEL_DO
:
10799 case EXEC_OMP_TARGET_PARALLEL_DO_SIMD
:
10800 case EXEC_OMP_TARGET_SIMD
:
10801 case EXEC_OMP_TARGET_TEAMS
:
10802 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
10803 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10804 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10805 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
10806 case EXEC_OMP_TARGET_UPDATE
:
10807 case EXEC_OMP_TASK
:
10808 case EXEC_OMP_TASKGROUP
:
10809 case EXEC_OMP_TASKLOOP
:
10810 case EXEC_OMP_TASKLOOP_SIMD
:
10811 case EXEC_OMP_TASKWAIT
:
10812 case EXEC_OMP_TASKYIELD
:
10813 case EXEC_OMP_TEAMS
:
10814 case EXEC_OMP_TEAMS_DISTRIBUTE
:
10815 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
10816 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
10817 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
10818 case EXEC_OMP_WORKSHARE
:
10822 gfc_internal_error ("gfc_resolve_blocks(): Bad block type");
10825 gfc_resolve_code (b
->next
, ns
);
10830 /* Does everything to resolve an ordinary assignment. Returns true
10831 if this is an interface assignment. */
10833 resolve_ordinary_assign (gfc_code
*code
, gfc_namespace
*ns
)
10840 symbol_attribute attr
;
10842 if (gfc_extend_assign (code
, ns
))
10846 if (code
->op
== EXEC_ASSIGN_CALL
)
10848 lhs
= code
->ext
.actual
->expr
;
10849 rhsptr
= &code
->ext
.actual
->next
->expr
;
10853 gfc_actual_arglist
* args
;
10854 gfc_typebound_proc
* tbp
;
10856 gcc_assert (code
->op
== EXEC_COMPCALL
);
10858 args
= code
->expr1
->value
.compcall
.actual
;
10860 rhsptr
= &args
->next
->expr
;
10862 tbp
= code
->expr1
->value
.compcall
.tbp
;
10863 gcc_assert (!tbp
->is_generic
);
10866 /* Make a temporary rhs when there is a default initializer
10867 and rhs is the same symbol as the lhs. */
10868 if ((*rhsptr
)->expr_type
== EXPR_VARIABLE
10869 && (*rhsptr
)->symtree
->n
.sym
->ts
.type
== BT_DERIVED
10870 && gfc_has_default_initializer ((*rhsptr
)->symtree
->n
.sym
->ts
.u
.derived
)
10871 && (lhs
->symtree
->n
.sym
== (*rhsptr
)->symtree
->n
.sym
))
10872 *rhsptr
= gfc_get_parentheses (*rhsptr
);
10880 if ((gfc_numeric_ts (&lhs
->ts
) || lhs
->ts
.type
== BT_LOGICAL
)
10881 && rhs
->ts
.type
== BT_CHARACTER
10882 && (rhs
->expr_type
!= EXPR_CONSTANT
|| !flag_dec_char_conversions
))
10884 /* Use of -fdec-char-conversions allows assignment of character data
10885 to non-character variables. This not permited for nonconstant
10887 gfc_error ("Cannot convert %s to %s at %L", gfc_typename (rhs
),
10888 gfc_typename (lhs
), &rhs
->where
);
10892 /* Handle the case of a BOZ literal on the RHS. */
10893 if (rhs
->ts
.type
== BT_BOZ
)
10895 if (gfc_invalid_boz ("BOZ literal constant at %L is neither a DATA "
10896 "statement value nor an actual argument of "
10897 "INT/REAL/DBLE/CMPLX intrinsic subprogram",
10901 switch (lhs
->ts
.type
)
10904 if (!gfc_boz2int (rhs
, lhs
->ts
.kind
))
10908 if (!gfc_boz2real (rhs
, lhs
->ts
.kind
))
10912 gfc_error ("Invalid use of BOZ literal constant at %L", &rhs
->where
);
10917 if (lhs
->ts
.type
== BT_CHARACTER
&& warn_character_truncation
)
10919 HOST_WIDE_INT llen
= 0, rlen
= 0;
10920 if (lhs
->ts
.u
.cl
!= NULL
10921 && lhs
->ts
.u
.cl
->length
!= NULL
10922 && lhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
10923 llen
= gfc_mpz_get_hwi (lhs
->ts
.u
.cl
->length
->value
.integer
);
10925 if (rhs
->expr_type
== EXPR_CONSTANT
)
10926 rlen
= rhs
->value
.character
.length
;
10928 else if (rhs
->ts
.u
.cl
!= NULL
10929 && rhs
->ts
.u
.cl
->length
!= NULL
10930 && rhs
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
10931 rlen
= gfc_mpz_get_hwi (rhs
->ts
.u
.cl
->length
->value
.integer
);
10933 if (rlen
&& llen
&& rlen
> llen
)
10934 gfc_warning_now (OPT_Wcharacter_truncation
,
10935 "CHARACTER expression will be truncated "
10936 "in assignment (%ld/%ld) at %L",
10937 (long) llen
, (long) rlen
, &code
->loc
);
10940 /* Ensure that a vector index expression for the lvalue is evaluated
10941 to a temporary if the lvalue symbol is referenced in it. */
10944 for (ref
= lhs
->ref
; ref
; ref
= ref
->next
)
10945 if (ref
->type
== REF_ARRAY
)
10947 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
10948 if (ref
->u
.ar
.dimen_type
[n
] == DIMEN_VECTOR
10949 && gfc_find_sym_in_expr (lhs
->symtree
->n
.sym
,
10950 ref
->u
.ar
.start
[n
]))
10952 = gfc_get_parentheses (ref
->u
.ar
.start
[n
]);
10956 if (gfc_pure (NULL
))
10958 if (lhs
->ts
.type
== BT_DERIVED
10959 && lhs
->expr_type
== EXPR_VARIABLE
10960 && lhs
->ts
.u
.derived
->attr
.pointer_comp
10961 && rhs
->expr_type
== EXPR_VARIABLE
10962 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
10963 || gfc_is_coindexed (rhs
)))
10965 /* F2008, C1283. */
10966 if (gfc_is_coindexed (rhs
))
10967 gfc_error ("Coindexed expression at %L is assigned to "
10968 "a derived type variable with a POINTER "
10969 "component in a PURE procedure",
10972 /* F2008, C1283 (4). */
10973 gfc_error ("In a pure subprogram an INTENT(IN) dummy argument "
10974 "shall not be used as the expr at %L of an intrinsic "
10975 "assignment statement in which the variable is of a "
10976 "derived type if the derived type has a pointer "
10977 "component at any level of component selection.",
10982 /* Fortran 2008, C1283. */
10983 if (gfc_is_coindexed (lhs
))
10985 gfc_error ("Assignment to coindexed variable at %L in a PURE "
10986 "procedure", &rhs
->where
);
10991 if (gfc_implicit_pure (NULL
))
10993 if (lhs
->expr_type
== EXPR_VARIABLE
10994 && lhs
->symtree
->n
.sym
!= gfc_current_ns
->proc_name
10995 && lhs
->symtree
->n
.sym
->ns
!= gfc_current_ns
)
10996 gfc_unset_implicit_pure (NULL
);
10998 if (lhs
->ts
.type
== BT_DERIVED
10999 && lhs
->expr_type
== EXPR_VARIABLE
11000 && lhs
->ts
.u
.derived
->attr
.pointer_comp
11001 && rhs
->expr_type
== EXPR_VARIABLE
11002 && (gfc_impure_variable (rhs
->symtree
->n
.sym
)
11003 || gfc_is_coindexed (rhs
)))
11004 gfc_unset_implicit_pure (NULL
);
11006 /* Fortran 2008, C1283. */
11007 if (gfc_is_coindexed (lhs
))
11008 gfc_unset_implicit_pure (NULL
);
11011 /* F2008, 7.2.1.2. */
11012 attr
= gfc_expr_attr (lhs
);
11013 if (lhs
->ts
.type
== BT_CLASS
&& attr
.allocatable
)
11015 if (attr
.codimension
)
11017 gfc_error ("Assignment to polymorphic coarray at %L is not "
11018 "permitted", &lhs
->where
);
11021 if (!gfc_notify_std (GFC_STD_F2008
, "Assignment to an allocatable "
11022 "polymorphic variable at %L", &lhs
->where
))
11024 if (!flag_realloc_lhs
)
11026 gfc_error ("Assignment to an allocatable polymorphic variable at %L "
11027 "requires %<-frealloc-lhs%>", &lhs
->where
);
11031 else if (lhs
->ts
.type
== BT_CLASS
)
11033 gfc_error ("Nonallocatable variable must not be polymorphic in intrinsic "
11034 "assignment at %L - check that there is a matching specific "
11035 "subroutine for '=' operator", &lhs
->where
);
11039 bool lhs_coindexed
= gfc_is_coindexed (lhs
);
11041 /* F2008, Section 7.2.1.2. */
11042 if (lhs_coindexed
&& gfc_has_ultimate_allocatable (lhs
))
11044 gfc_error ("Coindexed variable must not have an allocatable ultimate "
11045 "component in assignment at %L", &lhs
->where
);
11049 /* Assign the 'data' of a class object to a derived type. */
11050 if (lhs
->ts
.type
== BT_DERIVED
11051 && rhs
->ts
.type
== BT_CLASS
11052 && rhs
->expr_type
!= EXPR_ARRAY
)
11053 gfc_add_data_component (rhs
);
11055 /* Make sure there is a vtable and, in particular, a _copy for the
11057 if (lhs
->ts
.type
== BT_CLASS
&& rhs
->ts
.type
!= BT_CLASS
)
11058 gfc_find_vtab (&rhs
->ts
);
11060 bool caf_convert_to_send
= flag_coarray
== GFC_FCOARRAY_LIB
11062 || (code
->expr2
->expr_type
== EXPR_FUNCTION
11063 && code
->expr2
->value
.function
.isym
11064 && code
->expr2
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
11065 && (code
->expr1
->rank
== 0 || code
->expr2
->rank
!= 0)
11066 && !gfc_expr_attr (rhs
).allocatable
11067 && !gfc_has_vector_subscript (rhs
)));
11069 gfc_check_assign (lhs
, rhs
, 1, !caf_convert_to_send
);
11071 /* Insert a GFC_ISYM_CAF_SEND intrinsic, when the LHS is a coindexed variable.
11072 Additionally, insert this code when the RHS is a CAF as we then use the
11073 GFC_ISYM_CAF_SEND intrinsic just to avoid a temporary; but do not do so if
11074 the LHS is (re)allocatable or has a vector subscript. If the LHS is a
11075 noncoindexed array and the RHS is a coindexed scalar, use the normal code
11077 if (caf_convert_to_send
)
11079 if (code
->expr2
->expr_type
== EXPR_FUNCTION
11080 && code
->expr2
->value
.function
.isym
11081 && code
->expr2
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
11082 remove_caf_get_intrinsic (code
->expr2
);
11083 code
->op
= EXEC_CALL
;
11084 gfc_get_sym_tree (GFC_PREFIX ("caf_send"), ns
, &code
->symtree
, true);
11085 code
->resolved_sym
= code
->symtree
->n
.sym
;
11086 code
->resolved_sym
->attr
.flavor
= FL_PROCEDURE
;
11087 code
->resolved_sym
->attr
.intrinsic
= 1;
11088 code
->resolved_sym
->attr
.subroutine
= 1;
11089 code
->resolved_isym
= gfc_intrinsic_subroutine_by_id (GFC_ISYM_CAF_SEND
);
11090 gfc_commit_symbol (code
->resolved_sym
);
11091 code
->ext
.actual
= gfc_get_actual_arglist ();
11092 code
->ext
.actual
->expr
= lhs
;
11093 code
->ext
.actual
->next
= gfc_get_actual_arglist ();
11094 code
->ext
.actual
->next
->expr
= rhs
;
11095 code
->expr1
= NULL
;
11096 code
->expr2
= NULL
;
11103 /* Add a component reference onto an expression. */
11106 add_comp_ref (gfc_expr
*e
, gfc_component
*c
)
11111 ref
= &((*ref
)->next
);
11112 *ref
= gfc_get_ref ();
11113 (*ref
)->type
= REF_COMPONENT
;
11114 (*ref
)->u
.c
.sym
= e
->ts
.u
.derived
;
11115 (*ref
)->u
.c
.component
= c
;
11118 /* Add a full array ref, as necessary. */
11121 gfc_add_full_array_ref (e
, c
->as
);
11122 e
->rank
= c
->as
->rank
;
11127 /* Build an assignment. Keep the argument 'op' for future use, so that
11128 pointer assignments can be made. */
11131 build_assignment (gfc_exec_op op
, gfc_expr
*expr1
, gfc_expr
*expr2
,
11132 gfc_component
*comp1
, gfc_component
*comp2
, locus loc
)
11134 gfc_code
*this_code
;
11136 this_code
= gfc_get_code (op
);
11137 this_code
->next
= NULL
;
11138 this_code
->expr1
= gfc_copy_expr (expr1
);
11139 this_code
->expr2
= gfc_copy_expr (expr2
);
11140 this_code
->loc
= loc
;
11141 if (comp1
&& comp2
)
11143 add_comp_ref (this_code
->expr1
, comp1
);
11144 add_comp_ref (this_code
->expr2
, comp2
);
11151 /* Makes a temporary variable expression based on the characteristics of
11152 a given variable expression. */
11155 get_temp_from_expr (gfc_expr
*e
, gfc_namespace
*ns
)
11157 static int serial
= 0;
11158 char name
[GFC_MAX_SYMBOL_LEN
];
11160 gfc_array_spec
*as
;
11161 gfc_array_ref
*aref
;
11164 sprintf (name
, GFC_PREFIX("DA%d"), serial
++);
11165 gfc_get_sym_tree (name
, ns
, &tmp
, false);
11166 gfc_add_type (tmp
->n
.sym
, &e
->ts
, NULL
);
11168 if (e
->expr_type
== EXPR_CONSTANT
&& e
->ts
.type
== BT_CHARACTER
)
11169 tmp
->n
.sym
->ts
.u
.cl
->length
= gfc_get_int_expr (gfc_charlen_int_kind
,
11171 e
->value
.character
.length
);
11177 /* Obtain the arrayspec for the temporary. */
11178 if (e
->rank
&& e
->expr_type
!= EXPR_ARRAY
11179 && e
->expr_type
!= EXPR_FUNCTION
11180 && e
->expr_type
!= EXPR_OP
)
11182 aref
= gfc_find_array_ref (e
);
11183 if (e
->expr_type
== EXPR_VARIABLE
11184 && e
->symtree
->n
.sym
->as
== aref
->as
)
11188 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
11189 if (ref
->type
== REF_COMPONENT
11190 && ref
->u
.c
.component
->as
== aref
->as
)
11198 /* Add the attributes and the arrayspec to the temporary. */
11199 tmp
->n
.sym
->attr
= gfc_expr_attr (e
);
11200 tmp
->n
.sym
->attr
.function
= 0;
11201 tmp
->n
.sym
->attr
.proc_pointer
= 0;
11202 tmp
->n
.sym
->attr
.result
= 0;
11203 tmp
->n
.sym
->attr
.flavor
= FL_VARIABLE
;
11204 tmp
->n
.sym
->attr
.dummy
= 0;
11205 tmp
->n
.sym
->attr
.use_assoc
= 0;
11206 tmp
->n
.sym
->attr
.intent
= INTENT_UNKNOWN
;
11210 tmp
->n
.sym
->as
= gfc_copy_array_spec (as
);
11213 if (as
->type
== AS_DEFERRED
)
11214 tmp
->n
.sym
->attr
.allocatable
= 1;
11216 else if (e
->rank
&& (e
->expr_type
== EXPR_ARRAY
11217 || e
->expr_type
== EXPR_FUNCTION
11218 || e
->expr_type
== EXPR_OP
))
11220 tmp
->n
.sym
->as
= gfc_get_array_spec ();
11221 tmp
->n
.sym
->as
->type
= AS_DEFERRED
;
11222 tmp
->n
.sym
->as
->rank
= e
->rank
;
11223 tmp
->n
.sym
->attr
.allocatable
= 1;
11224 tmp
->n
.sym
->attr
.dimension
= 1;
11227 tmp
->n
.sym
->attr
.dimension
= 0;
11229 gfc_set_sym_referenced (tmp
->n
.sym
);
11230 gfc_commit_symbol (tmp
->n
.sym
);
11231 e
= gfc_lval_expr_from_sym (tmp
->n
.sym
);
11233 /* Should the lhs be a section, use its array ref for the
11234 temporary expression. */
11235 if (aref
&& aref
->type
!= AR_FULL
)
11237 gfc_free_ref_list (e
->ref
);
11238 e
->ref
= gfc_copy_ref (ref
);
11244 /* Add one line of code to the code chain, making sure that 'head' and
11245 'tail' are appropriately updated. */
11248 add_code_to_chain (gfc_code
**this_code
, gfc_code
**head
, gfc_code
**tail
)
11250 gcc_assert (this_code
);
11252 *head
= *tail
= *this_code
;
11254 *tail
= gfc_append_code (*tail
, *this_code
);
11259 /* Counts the potential number of part array references that would
11260 result from resolution of typebound defined assignments. */
11263 nonscalar_typebound_assign (gfc_symbol
*derived
, int depth
)
11266 int c_depth
= 0, t_depth
;
11268 for (c
= derived
->components
; c
; c
= c
->next
)
11270 if ((!gfc_bt_struct (c
->ts
.type
)
11272 || c
->attr
.allocatable
11273 || c
->attr
.proc_pointer_comp
11274 || c
->attr
.class_pointer
11275 || c
->attr
.proc_pointer
)
11276 && !c
->attr
.defined_assign_comp
)
11279 if (c
->as
&& c_depth
== 0)
11282 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
11283 t_depth
= nonscalar_typebound_assign (c
->ts
.u
.derived
,
11288 c_depth
= t_depth
> c_depth
? t_depth
: c_depth
;
11290 return depth
+ c_depth
;
11294 /* Implement 7.2.1.3 of the F08 standard:
11295 "An intrinsic assignment where the variable is of derived type is
11296 performed as if each component of the variable were assigned from the
11297 corresponding component of expr using pointer assignment (7.2.2) for
11298 each pointer component, defined assignment for each nonpointer
11299 nonallocatable component of a type that has a type-bound defined
11300 assignment consistent with the component, intrinsic assignment for
11301 each other nonpointer nonallocatable component, ..."
11303 The pointer assignments are taken care of by the intrinsic
11304 assignment of the structure itself. This function recursively adds
11305 defined assignments where required. The recursion is accomplished
11306 by calling gfc_resolve_code.
11308 When the lhs in a defined assignment has intent INOUT, we need a
11309 temporary for the lhs. In pseudo-code:
11311 ! Only call function lhs once.
11312 if (lhs is not a constant or an variable)
11315 ! Do the intrinsic assignment
11317 ! Now do the defined assignments
11318 do over components with typebound defined assignment [%cmp]
11319 #if one component's assignment procedure is INOUT
11321 #if expr2 non-variable
11327 t1%cmp {defined=} expr2%cmp
11333 expr1%cmp {defined=} expr2%cmp
11337 /* The temporary assignments have to be put on top of the additional
11338 code to avoid the result being changed by the intrinsic assignment.
11340 static int component_assignment_level
= 0;
11341 static gfc_code
*tmp_head
= NULL
, *tmp_tail
= NULL
;
11344 generate_component_assignments (gfc_code
**code
, gfc_namespace
*ns
)
11346 gfc_component
*comp1
, *comp2
;
11347 gfc_code
*this_code
= NULL
, *head
= NULL
, *tail
= NULL
;
11349 int error_count
, depth
;
11351 gfc_get_errors (NULL
, &error_count
);
11353 /* Filter out continuing processing after an error. */
11355 || (*code
)->expr1
->ts
.type
!= BT_DERIVED
11356 || (*code
)->expr2
->ts
.type
!= BT_DERIVED
)
11359 /* TODO: Handle more than one part array reference in assignments. */
11360 depth
= nonscalar_typebound_assign ((*code
)->expr1
->ts
.u
.derived
,
11361 (*code
)->expr1
->rank
? 1 : 0);
11364 gfc_warning (0, "TODO: type-bound defined assignment(s) at %L not "
11365 "done because multiple part array references would "
11366 "occur in intermediate expressions.", &(*code
)->loc
);
11370 component_assignment_level
++;
11372 /* Create a temporary so that functions get called only once. */
11373 if ((*code
)->expr2
->expr_type
!= EXPR_VARIABLE
11374 && (*code
)->expr2
->expr_type
!= EXPR_CONSTANT
)
11376 gfc_expr
*tmp_expr
;
11378 /* Assign the rhs to the temporary. */
11379 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
11380 this_code
= build_assignment (EXEC_ASSIGN
,
11381 tmp_expr
, (*code
)->expr2
,
11382 NULL
, NULL
, (*code
)->loc
);
11383 /* Add the code and substitute the rhs expression. */
11384 add_code_to_chain (&this_code
, &tmp_head
, &tmp_tail
);
11385 gfc_free_expr ((*code
)->expr2
);
11386 (*code
)->expr2
= tmp_expr
;
11389 /* Do the intrinsic assignment. This is not needed if the lhs is one
11390 of the temporaries generated here, since the intrinsic assignment
11391 to the final result already does this. */
11392 if ((*code
)->expr1
->symtree
->n
.sym
->name
[2] != '@')
11394 this_code
= build_assignment (EXEC_ASSIGN
,
11395 (*code
)->expr1
, (*code
)->expr2
,
11396 NULL
, NULL
, (*code
)->loc
);
11397 add_code_to_chain (&this_code
, &head
, &tail
);
11400 comp1
= (*code
)->expr1
->ts
.u
.derived
->components
;
11401 comp2
= (*code
)->expr2
->ts
.u
.derived
->components
;
11404 for (; comp1
; comp1
= comp1
->next
, comp2
= comp2
->next
)
11406 bool inout
= false;
11408 /* The intrinsic assignment does the right thing for pointers
11409 of all kinds and allocatable components. */
11410 if (!gfc_bt_struct (comp1
->ts
.type
)
11411 || comp1
->attr
.pointer
11412 || comp1
->attr
.allocatable
11413 || comp1
->attr
.proc_pointer_comp
11414 || comp1
->attr
.class_pointer
11415 || comp1
->attr
.proc_pointer
)
11418 /* Make an assigment for this component. */
11419 this_code
= build_assignment (EXEC_ASSIGN
,
11420 (*code
)->expr1
, (*code
)->expr2
,
11421 comp1
, comp2
, (*code
)->loc
);
11423 /* Convert the assignment if there is a defined assignment for
11424 this type. Otherwise, using the call from gfc_resolve_code,
11425 recurse into its components. */
11426 gfc_resolve_code (this_code
, ns
);
11428 if (this_code
->op
== EXEC_ASSIGN_CALL
)
11430 gfc_formal_arglist
*dummy_args
;
11432 /* Check that there is a typebound defined assignment. If not,
11433 then this must be a module defined assignment. We cannot
11434 use the defined_assign_comp attribute here because it must
11435 be this derived type that has the defined assignment and not
11437 if (!(comp1
->ts
.u
.derived
->f2k_derived
11438 && comp1
->ts
.u
.derived
->f2k_derived
11439 ->tb_op
[INTRINSIC_ASSIGN
]))
11441 gfc_free_statements (this_code
);
11446 /* If the first argument of the subroutine has intent INOUT
11447 a temporary must be generated and used instead. */
11448 rsym
= this_code
->resolved_sym
;
11449 dummy_args
= gfc_sym_get_dummy_args (rsym
);
11451 && dummy_args
->sym
->attr
.intent
== INTENT_INOUT
)
11453 gfc_code
*temp_code
;
11456 /* Build the temporary required for the assignment and put
11457 it at the head of the generated code. */
11460 t1
= get_temp_from_expr ((*code
)->expr1
, ns
);
11461 temp_code
= build_assignment (EXEC_ASSIGN
,
11462 t1
, (*code
)->expr1
,
11463 NULL
, NULL
, (*code
)->loc
);
11465 /* For allocatable LHS, check whether it is allocated. Note
11466 that allocatable components with defined assignment are
11467 not yet support. See PR 57696. */
11468 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
)
11472 gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
11473 block
= gfc_get_code (EXEC_IF
);
11474 block
->block
= gfc_get_code (EXEC_IF
);
11475 block
->block
->expr1
11476 = gfc_build_intrinsic_call (ns
,
11477 GFC_ISYM_ALLOCATED
, "allocated",
11478 (*code
)->loc
, 1, e
);
11479 block
->block
->next
= temp_code
;
11482 add_code_to_chain (&temp_code
, &tmp_head
, &tmp_tail
);
11485 /* Replace the first actual arg with the component of the
11487 gfc_free_expr (this_code
->ext
.actual
->expr
);
11488 this_code
->ext
.actual
->expr
= gfc_copy_expr (t1
);
11489 add_comp_ref (this_code
->ext
.actual
->expr
, comp1
);
11491 /* If the LHS variable is allocatable and wasn't allocated and
11492 the temporary is allocatable, pointer assign the address of
11493 the freshly allocated LHS to the temporary. */
11494 if ((*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
11495 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
11500 cond
= gfc_get_expr ();
11501 cond
->ts
.type
= BT_LOGICAL
;
11502 cond
->ts
.kind
= gfc_default_logical_kind
;
11503 cond
->expr_type
= EXPR_OP
;
11504 cond
->where
= (*code
)->loc
;
11505 cond
->value
.op
.op
= INTRINSIC_NOT
;
11506 cond
->value
.op
.op1
= gfc_build_intrinsic_call (ns
,
11507 GFC_ISYM_ALLOCATED
, "allocated",
11508 (*code
)->loc
, 1, gfc_copy_expr (t1
));
11509 block
= gfc_get_code (EXEC_IF
);
11510 block
->block
= gfc_get_code (EXEC_IF
);
11511 block
->block
->expr1
= cond
;
11512 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
11513 t1
, (*code
)->expr1
,
11514 NULL
, NULL
, (*code
)->loc
);
11515 add_code_to_chain (&block
, &head
, &tail
);
11519 else if (this_code
->op
== EXEC_ASSIGN
&& !this_code
->next
)
11521 /* Don't add intrinsic assignments since they are already
11522 effected by the intrinsic assignment of the structure. */
11523 gfc_free_statements (this_code
);
11528 add_code_to_chain (&this_code
, &head
, &tail
);
11532 /* Transfer the value to the final result. */
11533 this_code
= build_assignment (EXEC_ASSIGN
,
11534 (*code
)->expr1
, t1
,
11535 comp1
, comp2
, (*code
)->loc
);
11536 add_code_to_chain (&this_code
, &head
, &tail
);
11540 /* Put the temporary assignments at the top of the generated code. */
11541 if (tmp_head
&& component_assignment_level
== 1)
11543 gfc_append_code (tmp_head
, head
);
11545 tmp_head
= tmp_tail
= NULL
;
11548 // If we did a pointer assignment - thus, we need to ensure that the LHS is
11549 // not accidentally deallocated. Hence, nullify t1.
11550 if (t1
&& (*code
)->expr1
->symtree
->n
.sym
->attr
.allocatable
11551 && gfc_expr_attr ((*code
)->expr1
).allocatable
)
11557 e
= gfc_lval_expr_from_sym ((*code
)->expr1
->symtree
->n
.sym
);
11558 cond
= gfc_build_intrinsic_call (ns
, GFC_ISYM_ASSOCIATED
, "associated",
11559 (*code
)->loc
, 2, gfc_copy_expr (t1
), e
);
11560 block
= gfc_get_code (EXEC_IF
);
11561 block
->block
= gfc_get_code (EXEC_IF
);
11562 block
->block
->expr1
= cond
;
11563 block
->block
->next
= build_assignment (EXEC_POINTER_ASSIGN
,
11564 t1
, gfc_get_null_expr (&(*code
)->loc
),
11565 NULL
, NULL
, (*code
)->loc
);
11566 gfc_append_code (tail
, block
);
11570 /* Now attach the remaining code chain to the input code. Step on
11571 to the end of the new code since resolution is complete. */
11572 gcc_assert ((*code
)->op
== EXEC_ASSIGN
);
11573 tail
->next
= (*code
)->next
;
11574 /* Overwrite 'code' because this would place the intrinsic assignment
11575 before the temporary for the lhs is created. */
11576 gfc_free_expr ((*code
)->expr1
);
11577 gfc_free_expr ((*code
)->expr2
);
11583 component_assignment_level
--;
11587 /* F2008: Pointer function assignments are of the form:
11588 ptr_fcn (args) = expr
11589 This function breaks these assignments into two statements:
11590 temporary_pointer => ptr_fcn(args)
11591 temporary_pointer = expr */
11594 resolve_ptr_fcn_assign (gfc_code
**code
, gfc_namespace
*ns
)
11596 gfc_expr
*tmp_ptr_expr
;
11597 gfc_code
*this_code
;
11598 gfc_component
*comp
;
11601 if ((*code
)->expr1
->expr_type
!= EXPR_FUNCTION
)
11604 /* Even if standard does not support this feature, continue to build
11605 the two statements to avoid upsetting frontend_passes.c. */
11606 gfc_notify_std (GFC_STD_F2008
, "Pointer procedure assignment at "
11607 "%L", &(*code
)->loc
);
11609 comp
= gfc_get_proc_ptr_comp ((*code
)->expr1
);
11612 s
= comp
->ts
.interface
;
11614 s
= (*code
)->expr1
->symtree
->n
.sym
;
11616 if (s
== NULL
|| !s
->result
->attr
.pointer
)
11618 gfc_error ("The function result on the lhs of the assignment at "
11619 "%L must have the pointer attribute.",
11620 &(*code
)->expr1
->where
);
11621 (*code
)->op
= EXEC_NOP
;
11625 tmp_ptr_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
11627 /* get_temp_from_expression is set up for ordinary assignments. To that
11628 end, where array bounds are not known, arrays are made allocatable.
11629 Change the temporary to a pointer here. */
11630 tmp_ptr_expr
->symtree
->n
.sym
->attr
.pointer
= 1;
11631 tmp_ptr_expr
->symtree
->n
.sym
->attr
.allocatable
= 0;
11632 tmp_ptr_expr
->where
= (*code
)->loc
;
11634 this_code
= build_assignment (EXEC_ASSIGN
,
11635 tmp_ptr_expr
, (*code
)->expr2
,
11636 NULL
, NULL
, (*code
)->loc
);
11637 this_code
->next
= (*code
)->next
;
11638 (*code
)->next
= this_code
;
11639 (*code
)->op
= EXEC_POINTER_ASSIGN
;
11640 (*code
)->expr2
= (*code
)->expr1
;
11641 (*code
)->expr1
= tmp_ptr_expr
;
11647 /* Deferred character length assignments from an operator expression
11648 require a temporary because the character length of the lhs can
11649 change in the course of the assignment. */
11652 deferred_op_assign (gfc_code
**code
, gfc_namespace
*ns
)
11654 gfc_expr
*tmp_expr
;
11655 gfc_code
*this_code
;
11657 if (!((*code
)->expr1
->ts
.type
== BT_CHARACTER
11658 && (*code
)->expr1
->ts
.deferred
&& (*code
)->expr1
->rank
11659 && (*code
)->expr2
->expr_type
== EXPR_OP
))
11662 if (!gfc_check_dependency ((*code
)->expr1
, (*code
)->expr2
, 1))
11665 if (gfc_expr_attr ((*code
)->expr1
).pointer
)
11668 tmp_expr
= get_temp_from_expr ((*code
)->expr1
, ns
);
11669 tmp_expr
->where
= (*code
)->loc
;
11671 /* A new charlen is required to ensure that the variable string
11672 length is different to that of the original lhs. */
11673 tmp_expr
->ts
.u
.cl
= gfc_get_charlen();
11674 tmp_expr
->symtree
->n
.sym
->ts
.u
.cl
= tmp_expr
->ts
.u
.cl
;
11675 tmp_expr
->ts
.u
.cl
->next
= (*code
)->expr2
->ts
.u
.cl
->next
;
11676 (*code
)->expr2
->ts
.u
.cl
->next
= tmp_expr
->ts
.u
.cl
;
11678 tmp_expr
->symtree
->n
.sym
->ts
.deferred
= 1;
11680 this_code
= build_assignment (EXEC_ASSIGN
,
11682 gfc_copy_expr (tmp_expr
),
11683 NULL
, NULL
, (*code
)->loc
);
11685 (*code
)->expr1
= tmp_expr
;
11687 this_code
->next
= (*code
)->next
;
11688 (*code
)->next
= this_code
;
11694 /* Given a block of code, recursively resolve everything pointed to by this
11698 gfc_resolve_code (gfc_code
*code
, gfc_namespace
*ns
)
11700 int omp_workshare_save
;
11701 int forall_save
, do_concurrent_save
;
11705 frame
.prev
= cs_base
;
11709 find_reachable_labels (code
);
11711 for (; code
; code
= code
->next
)
11713 frame
.current
= code
;
11714 forall_save
= forall_flag
;
11715 do_concurrent_save
= gfc_do_concurrent_flag
;
11717 if (code
->op
== EXEC_FORALL
)
11720 gfc_resolve_forall (code
, ns
, forall_save
);
11723 else if (code
->block
)
11725 omp_workshare_save
= -1;
11728 case EXEC_OACC_PARALLEL_LOOP
:
11729 case EXEC_OACC_PARALLEL
:
11730 case EXEC_OACC_KERNELS_LOOP
:
11731 case EXEC_OACC_KERNELS
:
11732 case EXEC_OACC_SERIAL_LOOP
:
11733 case EXEC_OACC_SERIAL
:
11734 case EXEC_OACC_DATA
:
11735 case EXEC_OACC_HOST_DATA
:
11736 case EXEC_OACC_LOOP
:
11737 gfc_resolve_oacc_blocks (code
, ns
);
11739 case EXEC_OMP_PARALLEL_WORKSHARE
:
11740 omp_workshare_save
= omp_workshare_flag
;
11741 omp_workshare_flag
= 1;
11742 gfc_resolve_omp_parallel_blocks (code
, ns
);
11744 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
11745 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
11746 case EXEC_OMP_PARALLEL
:
11747 case EXEC_OMP_PARALLEL_DO
:
11748 case EXEC_OMP_PARALLEL_DO_SIMD
:
11749 case EXEC_OMP_PARALLEL_SECTIONS
:
11750 case EXEC_OMP_TARGET_PARALLEL
:
11751 case EXEC_OMP_TARGET_PARALLEL_DO
:
11752 case EXEC_OMP_TARGET_PARALLEL_DO_SIMD
:
11753 case EXEC_OMP_TARGET_TEAMS
:
11754 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
11755 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
11756 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
11757 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
11758 case EXEC_OMP_TASK
:
11759 case EXEC_OMP_TASKLOOP
:
11760 case EXEC_OMP_TASKLOOP_SIMD
:
11761 case EXEC_OMP_TEAMS
:
11762 case EXEC_OMP_TEAMS_DISTRIBUTE
:
11763 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
11764 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
11765 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
11766 omp_workshare_save
= omp_workshare_flag
;
11767 omp_workshare_flag
= 0;
11768 gfc_resolve_omp_parallel_blocks (code
, ns
);
11770 case EXEC_OMP_DISTRIBUTE
:
11771 case EXEC_OMP_DISTRIBUTE_SIMD
:
11773 case EXEC_OMP_DO_SIMD
:
11774 case EXEC_OMP_SIMD
:
11775 case EXEC_OMP_TARGET_SIMD
:
11776 gfc_resolve_omp_do_blocks (code
, ns
);
11778 case EXEC_SELECT_TYPE
:
11779 case EXEC_SELECT_RANK
:
11780 /* Blocks are handled in resolve_select_type/rank because we
11781 have to transform the SELECT TYPE into ASSOCIATE first. */
11783 case EXEC_DO_CONCURRENT
:
11784 gfc_do_concurrent_flag
= 1;
11785 gfc_resolve_blocks (code
->block
, ns
);
11786 gfc_do_concurrent_flag
= 2;
11788 case EXEC_OMP_WORKSHARE
:
11789 omp_workshare_save
= omp_workshare_flag
;
11790 omp_workshare_flag
= 1;
11793 gfc_resolve_blocks (code
->block
, ns
);
11797 if (omp_workshare_save
!= -1)
11798 omp_workshare_flag
= omp_workshare_save
;
11802 if (code
->op
!= EXEC_COMPCALL
&& code
->op
!= EXEC_CALL_PPC
)
11803 t
= gfc_resolve_expr (code
->expr1
);
11804 forall_flag
= forall_save
;
11805 gfc_do_concurrent_flag
= do_concurrent_save
;
11807 if (!gfc_resolve_expr (code
->expr2
))
11810 if (code
->op
== EXEC_ALLOCATE
11811 && !gfc_resolve_expr (code
->expr3
))
11817 case EXEC_END_BLOCK
:
11818 case EXEC_END_NESTED_BLOCK
:
11822 case EXEC_ERROR_STOP
:
11824 case EXEC_CONTINUE
:
11826 case EXEC_ASSIGN_CALL
:
11829 case EXEC_CRITICAL
:
11830 resolve_critical (code
);
11833 case EXEC_SYNC_ALL
:
11834 case EXEC_SYNC_IMAGES
:
11835 case EXEC_SYNC_MEMORY
:
11836 resolve_sync (code
);
11841 case EXEC_EVENT_POST
:
11842 case EXEC_EVENT_WAIT
:
11843 resolve_lock_unlock_event (code
);
11846 case EXEC_FAIL_IMAGE
:
11847 case EXEC_FORM_TEAM
:
11848 case EXEC_CHANGE_TEAM
:
11849 case EXEC_END_TEAM
:
11850 case EXEC_SYNC_TEAM
:
11854 /* Keep track of which entry we are up to. */
11855 current_entry_id
= code
->ext
.entry
->id
;
11859 resolve_where (code
, NULL
);
11863 if (code
->expr1
!= NULL
)
11865 if (code
->expr1
->expr_type
!= EXPR_VARIABLE
11866 || code
->expr1
->ts
.type
!= BT_INTEGER
11867 || (code
->expr1
->ref
11868 && code
->expr1
->ref
->type
== REF_ARRAY
)
11869 || code
->expr1
->symtree
== NULL
11870 || (code
->expr1
->symtree
->n
.sym
11871 && (code
->expr1
->symtree
->n
.sym
->attr
.flavor
11873 gfc_error ("ASSIGNED GOTO statement at %L requires a "
11874 "scalar INTEGER variable", &code
->expr1
->where
);
11875 else if (code
->expr1
->symtree
->n
.sym
11876 && code
->expr1
->symtree
->n
.sym
->attr
.assign
!= 1)
11877 gfc_error ("Variable %qs has not been assigned a target "
11878 "label at %L", code
->expr1
->symtree
->n
.sym
->name
,
11879 &code
->expr1
->where
);
11882 resolve_branch (code
->label1
, code
);
11886 if (code
->expr1
!= NULL
11887 && (code
->expr1
->ts
.type
!= BT_INTEGER
|| code
->expr1
->rank
))
11888 gfc_error ("Alternate RETURN statement at %L requires a SCALAR-"
11889 "INTEGER return specifier", &code
->expr1
->where
);
11892 case EXEC_INIT_ASSIGN
:
11893 case EXEC_END_PROCEDURE
:
11900 if (code
->expr1
->ts
.type
== BT_CLASS
)
11901 gfc_find_vtab (&code
->expr2
->ts
);
11903 /* Remove a GFC_ISYM_CAF_GET inserted for a coindexed variable on
11905 if (code
->expr1
->expr_type
== EXPR_FUNCTION
11906 && code
->expr1
->value
.function
.isym
11907 && code
->expr1
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
11908 remove_caf_get_intrinsic (code
->expr1
);
11910 /* If this is a pointer function in an lvalue variable context,
11911 the new code will have to be resolved afresh. This is also the
11912 case with an error, where the code is transformed into NOP to
11913 prevent ICEs downstream. */
11914 if (resolve_ptr_fcn_assign (&code
, ns
)
11915 || code
->op
== EXEC_NOP
)
11918 if (!gfc_check_vardef_context (code
->expr1
, false, false, false,
11922 if (resolve_ordinary_assign (code
, ns
))
11924 if (code
->op
== EXEC_COMPCALL
)
11930 /* Check for dependencies in deferred character length array
11931 assignments and generate a temporary, if necessary. */
11932 if (code
->op
== EXEC_ASSIGN
&& deferred_op_assign (&code
, ns
))
11935 /* F03 7.4.1.3 for non-allocatable, non-pointer components. */
11936 if (code
->op
!= EXEC_CALL
&& code
->expr1
->ts
.type
== BT_DERIVED
11937 && code
->expr1
->ts
.u
.derived
11938 && code
->expr1
->ts
.u
.derived
->attr
.defined_assign_comp
)
11939 generate_component_assignments (&code
, ns
);
11943 case EXEC_LABEL_ASSIGN
:
11944 if (code
->label1
->defined
== ST_LABEL_UNKNOWN
)
11945 gfc_error ("Label %d referenced at %L is never defined",
11946 code
->label1
->value
, &code
->label1
->where
);
11948 && (code
->expr1
->expr_type
!= EXPR_VARIABLE
11949 || code
->expr1
->symtree
->n
.sym
->ts
.type
!= BT_INTEGER
11950 || code
->expr1
->symtree
->n
.sym
->ts
.kind
11951 != gfc_default_integer_kind
11952 || code
->expr1
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
11953 || code
->expr1
->symtree
->n
.sym
->as
!= NULL
))
11954 gfc_error ("ASSIGN statement at %L requires a scalar "
11955 "default INTEGER variable", &code
->expr1
->where
);
11958 case EXEC_POINTER_ASSIGN
:
11965 /* This is both a variable definition and pointer assignment
11966 context, so check both of them. For rank remapping, a final
11967 array ref may be present on the LHS and fool gfc_expr_attr
11968 used in gfc_check_vardef_context. Remove it. */
11969 e
= remove_last_array_ref (code
->expr1
);
11970 t
= gfc_check_vardef_context (e
, true, false, false,
11971 _("pointer assignment"));
11973 t
= gfc_check_vardef_context (e
, false, false, false,
11974 _("pointer assignment"));
11977 t
= gfc_check_pointer_assign (code
->expr1
, code
->expr2
, !t
) && t
;
11982 /* Assigning a class object always is a regular assign. */
11983 if (code
->expr2
->ts
.type
== BT_CLASS
11984 && code
->expr1
->ts
.type
== BT_CLASS
11985 && !CLASS_DATA (code
->expr2
)->attr
.dimension
11986 && !(gfc_expr_attr (code
->expr1
).proc_pointer
11987 && code
->expr2
->expr_type
== EXPR_VARIABLE
11988 && code
->expr2
->symtree
->n
.sym
->attr
.flavor
11990 code
->op
= EXEC_ASSIGN
;
11994 case EXEC_ARITHMETIC_IF
:
11996 gfc_expr
*e
= code
->expr1
;
11998 gfc_resolve_expr (e
);
11999 if (e
->expr_type
== EXPR_NULL
)
12000 gfc_error ("Invalid NULL at %L", &e
->where
);
12002 if (t
&& (e
->rank
> 0
12003 || !(e
->ts
.type
== BT_REAL
|| e
->ts
.type
== BT_INTEGER
)))
12004 gfc_error ("Arithmetic IF statement at %L requires a scalar "
12005 "REAL or INTEGER expression", &e
->where
);
12007 resolve_branch (code
->label1
, code
);
12008 resolve_branch (code
->label2
, code
);
12009 resolve_branch (code
->label3
, code
);
12014 if (t
&& code
->expr1
!= NULL
12015 && (code
->expr1
->ts
.type
!= BT_LOGICAL
12016 || code
->expr1
->rank
!= 0))
12017 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
12018 &code
->expr1
->where
);
12023 resolve_call (code
);
12026 case EXEC_COMPCALL
:
12028 resolve_typebound_subroutine (code
);
12031 case EXEC_CALL_PPC
:
12032 resolve_ppc_call (code
);
12036 /* Select is complicated. Also, a SELECT construct could be
12037 a transformed computed GOTO. */
12038 resolve_select (code
, false);
12041 case EXEC_SELECT_TYPE
:
12042 resolve_select_type (code
, ns
);
12045 case EXEC_SELECT_RANK
:
12046 resolve_select_rank (code
, ns
);
12050 resolve_block_construct (code
);
12054 if (code
->ext
.iterator
!= NULL
)
12056 gfc_iterator
*iter
= code
->ext
.iterator
;
12057 if (gfc_resolve_iterator (iter
, true, false))
12058 gfc_resolve_do_iterator (code
, iter
->var
->symtree
->n
.sym
,
12063 case EXEC_DO_WHILE
:
12064 if (code
->expr1
== NULL
)
12065 gfc_internal_error ("gfc_resolve_code(): No expression on "
12068 && (code
->expr1
->rank
!= 0
12069 || code
->expr1
->ts
.type
!= BT_LOGICAL
))
12070 gfc_error ("Exit condition of DO WHILE loop at %L must be "
12071 "a scalar LOGICAL expression", &code
->expr1
->where
);
12074 case EXEC_ALLOCATE
:
12076 resolve_allocate_deallocate (code
, "ALLOCATE");
12080 case EXEC_DEALLOCATE
:
12082 resolve_allocate_deallocate (code
, "DEALLOCATE");
12087 if (!gfc_resolve_open (code
->ext
.open
, &code
->loc
))
12090 resolve_branch (code
->ext
.open
->err
, code
);
12094 if (!gfc_resolve_close (code
->ext
.close
, &code
->loc
))
12097 resolve_branch (code
->ext
.close
->err
, code
);
12100 case EXEC_BACKSPACE
:
12104 if (!gfc_resolve_filepos (code
->ext
.filepos
, &code
->loc
))
12107 resolve_branch (code
->ext
.filepos
->err
, code
);
12111 if (!gfc_resolve_inquire (code
->ext
.inquire
))
12114 resolve_branch (code
->ext
.inquire
->err
, code
);
12117 case EXEC_IOLENGTH
:
12118 gcc_assert (code
->ext
.inquire
!= NULL
);
12119 if (!gfc_resolve_inquire (code
->ext
.inquire
))
12122 resolve_branch (code
->ext
.inquire
->err
, code
);
12126 if (!gfc_resolve_wait (code
->ext
.wait
))
12129 resolve_branch (code
->ext
.wait
->err
, code
);
12130 resolve_branch (code
->ext
.wait
->end
, code
);
12131 resolve_branch (code
->ext
.wait
->eor
, code
);
12136 if (!gfc_resolve_dt (code
, code
->ext
.dt
, &code
->loc
))
12139 resolve_branch (code
->ext
.dt
->err
, code
);
12140 resolve_branch (code
->ext
.dt
->end
, code
);
12141 resolve_branch (code
->ext
.dt
->eor
, code
);
12144 case EXEC_TRANSFER
:
12145 resolve_transfer (code
);
12148 case EXEC_DO_CONCURRENT
:
12150 resolve_forall_iterators (code
->ext
.forall_iterator
);
12152 if (code
->expr1
!= NULL
12153 && (code
->expr1
->ts
.type
!= BT_LOGICAL
|| code
->expr1
->rank
))
12154 gfc_error ("FORALL mask clause at %L requires a scalar LOGICAL "
12155 "expression", &code
->expr1
->where
);
12158 case EXEC_OACC_PARALLEL_LOOP
:
12159 case EXEC_OACC_PARALLEL
:
12160 case EXEC_OACC_KERNELS_LOOP
:
12161 case EXEC_OACC_KERNELS
:
12162 case EXEC_OACC_SERIAL_LOOP
:
12163 case EXEC_OACC_SERIAL
:
12164 case EXEC_OACC_DATA
:
12165 case EXEC_OACC_HOST_DATA
:
12166 case EXEC_OACC_LOOP
:
12167 case EXEC_OACC_UPDATE
:
12168 case EXEC_OACC_WAIT
:
12169 case EXEC_OACC_CACHE
:
12170 case EXEC_OACC_ENTER_DATA
:
12171 case EXEC_OACC_EXIT_DATA
:
12172 case EXEC_OACC_ATOMIC
:
12173 case EXEC_OACC_DECLARE
:
12174 gfc_resolve_oacc_directive (code
, ns
);
12177 case EXEC_OMP_ATOMIC
:
12178 case EXEC_OMP_BARRIER
:
12179 case EXEC_OMP_CANCEL
:
12180 case EXEC_OMP_CANCELLATION_POINT
:
12181 case EXEC_OMP_CRITICAL
:
12182 case EXEC_OMP_FLUSH
:
12183 case EXEC_OMP_DISTRIBUTE
:
12184 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO
:
12185 case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
12186 case EXEC_OMP_DISTRIBUTE_SIMD
:
12188 case EXEC_OMP_DO_SIMD
:
12189 case EXEC_OMP_MASTER
:
12190 case EXEC_OMP_ORDERED
:
12191 case EXEC_OMP_SCAN
:
12192 case EXEC_OMP_SECTIONS
:
12193 case EXEC_OMP_SIMD
:
12194 case EXEC_OMP_SINGLE
:
12195 case EXEC_OMP_TARGET
:
12196 case EXEC_OMP_TARGET_DATA
:
12197 case EXEC_OMP_TARGET_ENTER_DATA
:
12198 case EXEC_OMP_TARGET_EXIT_DATA
:
12199 case EXEC_OMP_TARGET_PARALLEL
:
12200 case EXEC_OMP_TARGET_PARALLEL_DO
:
12201 case EXEC_OMP_TARGET_PARALLEL_DO_SIMD
:
12202 case EXEC_OMP_TARGET_SIMD
:
12203 case EXEC_OMP_TARGET_TEAMS
:
12204 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE
:
12205 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
12206 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
12207 case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
12208 case EXEC_OMP_TARGET_UPDATE
:
12209 case EXEC_OMP_TASK
:
12210 case EXEC_OMP_TASKGROUP
:
12211 case EXEC_OMP_TASKLOOP
:
12212 case EXEC_OMP_TASKLOOP_SIMD
:
12213 case EXEC_OMP_TASKWAIT
:
12214 case EXEC_OMP_TASKYIELD
:
12215 case EXEC_OMP_TEAMS
:
12216 case EXEC_OMP_TEAMS_DISTRIBUTE
:
12217 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
12218 case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
12219 case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD
:
12220 case EXEC_OMP_WORKSHARE
:
12221 gfc_resolve_omp_directive (code
, ns
);
12224 case EXEC_OMP_PARALLEL
:
12225 case EXEC_OMP_PARALLEL_DO
:
12226 case EXEC_OMP_PARALLEL_DO_SIMD
:
12227 case EXEC_OMP_PARALLEL_SECTIONS
:
12228 case EXEC_OMP_PARALLEL_WORKSHARE
:
12229 omp_workshare_save
= omp_workshare_flag
;
12230 omp_workshare_flag
= 0;
12231 gfc_resolve_omp_directive (code
, ns
);
12232 omp_workshare_flag
= omp_workshare_save
;
12236 gfc_internal_error ("gfc_resolve_code(): Bad statement code");
12240 cs_base
= frame
.prev
;
12244 /* Resolve initial values and make sure they are compatible with
12248 resolve_values (gfc_symbol
*sym
)
12252 if (sym
->value
== NULL
)
12255 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_DEPRECATED
))
12256 gfc_warning (OPT_Wdeprecated_declarations
,
12257 "Using parameter %qs declared at %L is deprecated",
12258 sym
->name
, &sym
->declared_at
);
12260 if (sym
->value
->expr_type
== EXPR_STRUCTURE
)
12261 t
= resolve_structure_cons (sym
->value
, 1);
12263 t
= gfc_resolve_expr (sym
->value
);
12268 gfc_check_assign_symbol (sym
, NULL
, sym
->value
);
12272 /* Verify any BIND(C) derived types in the namespace so we can report errors
12273 for them once, rather than for each variable declared of that type. */
12276 resolve_bind_c_derived_types (gfc_symbol
*derived_sym
)
12278 if (derived_sym
!= NULL
&& derived_sym
->attr
.flavor
== FL_DERIVED
12279 && derived_sym
->attr
.is_bind_c
== 1)
12280 verify_bind_c_derived_type (derived_sym
);
12286 /* Check the interfaces of DTIO procedures associated with derived
12287 type 'sym'. These procedures can either have typebound bindings or
12288 can appear in DTIO generic interfaces. */
12291 gfc_verify_DTIO_procedures (gfc_symbol
*sym
)
12293 if (!sym
|| sym
->attr
.flavor
!= FL_DERIVED
)
12296 gfc_check_dtio_interfaces (sym
);
12301 /* Verify that any binding labels used in a given namespace do not collide
12302 with the names or binding labels of any global symbols. Multiple INTERFACE
12303 for the same procedure are permitted. */
12306 gfc_verify_binding_labels (gfc_symbol
*sym
)
12309 const char *module
;
12311 if (!sym
|| !sym
->attr
.is_bind_c
|| sym
->attr
.is_iso_c
12312 || sym
->attr
.flavor
== FL_DERIVED
|| !sym
->binding_label
)
12315 gsym
= gfc_find_case_gsymbol (gfc_gsym_root
, sym
->binding_label
);
12318 module
= sym
->module
;
12319 else if (sym
->ns
&& sym
->ns
->proc_name
12320 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
12321 module
= sym
->ns
->proc_name
->name
;
12322 else if (sym
->ns
&& sym
->ns
->parent
12323 && sym
->ns
&& sym
->ns
->parent
->proc_name
12324 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
12325 module
= sym
->ns
->parent
->proc_name
->name
;
12331 && (gsym
->type
== GSYM_FUNCTION
|| gsym
->type
== GSYM_SUBROUTINE
)))
12334 gsym
= gfc_get_gsymbol (sym
->binding_label
, true);
12335 gsym
->where
= sym
->declared_at
;
12336 gsym
->sym_name
= sym
->name
;
12337 gsym
->binding_label
= sym
->binding_label
;
12338 gsym
->ns
= sym
->ns
;
12339 gsym
->mod_name
= module
;
12340 if (sym
->attr
.function
)
12341 gsym
->type
= GSYM_FUNCTION
;
12342 else if (sym
->attr
.subroutine
)
12343 gsym
->type
= GSYM_SUBROUTINE
;
12344 /* Mark as variable/procedure as defined, unless its an INTERFACE. */
12345 gsym
->defined
= sym
->attr
.if_source
!= IFSRC_IFBODY
;
12349 if (sym
->attr
.flavor
== FL_VARIABLE
&& gsym
->type
!= GSYM_UNKNOWN
)
12351 gfc_error ("Variable %qs with binding label %qs at %L uses the same global "
12352 "identifier as entity at %L", sym
->name
,
12353 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
12354 /* Clear the binding label to prevent checking multiple times. */
12355 sym
->binding_label
= NULL
;
12359 if (sym
->attr
.flavor
== FL_VARIABLE
&& module
12360 && (strcmp (module
, gsym
->mod_name
) != 0
12361 || strcmp (sym
->name
, gsym
->sym_name
) != 0))
12363 /* This can only happen if the variable is defined in a module - if it
12364 isn't the same module, reject it. */
12365 gfc_error ("Variable %qs from module %qs with binding label %qs at %L "
12366 "uses the same global identifier as entity at %L from module %qs",
12367 sym
->name
, module
, sym
->binding_label
,
12368 &sym
->declared_at
, &gsym
->where
, gsym
->mod_name
);
12369 sym
->binding_label
= NULL
;
12373 if ((sym
->attr
.function
|| sym
->attr
.subroutine
)
12374 && ((gsym
->type
!= GSYM_SUBROUTINE
&& gsym
->type
!= GSYM_FUNCTION
)
12375 || (gsym
->defined
&& sym
->attr
.if_source
!= IFSRC_IFBODY
))
12376 && (sym
!= gsym
->ns
->proc_name
&& sym
->attr
.entry
== 0)
12377 && (module
!= gsym
->mod_name
12378 || strcmp (gsym
->sym_name
, sym
->name
) != 0
12379 || (module
&& strcmp (module
, gsym
->mod_name
) != 0)))
12381 /* Print an error if the procedure is defined multiple times; we have to
12382 exclude references to the same procedure via module association or
12383 multiple checks for the same procedure. */
12384 gfc_error ("Procedure %qs with binding label %qs at %L uses the same "
12385 "global identifier as entity at %L", sym
->name
,
12386 sym
->binding_label
, &sym
->declared_at
, &gsym
->where
);
12387 sym
->binding_label
= NULL
;
12392 /* Resolve an index expression. */
12395 resolve_index_expr (gfc_expr
*e
)
12397 if (!gfc_resolve_expr (e
))
12400 if (!gfc_simplify_expr (e
, 0))
12403 if (!gfc_specification_expr (e
))
12410 /* Resolve a charlen structure. */
12413 resolve_charlen (gfc_charlen
*cl
)
12416 bool saved_specification_expr
;
12422 saved_specification_expr
= specification_expr
;
12423 specification_expr
= true;
12425 if (cl
->length_from_typespec
)
12427 if (!gfc_resolve_expr (cl
->length
))
12429 specification_expr
= saved_specification_expr
;
12433 if (!gfc_simplify_expr (cl
->length
, 0))
12435 specification_expr
= saved_specification_expr
;
12439 /* cl->length has been resolved. It should have an integer type. */
12440 if (cl
->length
->ts
.type
!= BT_INTEGER
|| cl
->length
->rank
!= 0)
12442 gfc_error ("Scalar INTEGER expression expected at %L",
12443 &cl
->length
->where
);
12449 if (!resolve_index_expr (cl
->length
))
12451 specification_expr
= saved_specification_expr
;
12456 /* F2008, 4.4.3.2: If the character length parameter value evaluates to
12457 a negative value, the length of character entities declared is zero. */
12458 if (cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
12459 && mpz_sgn (cl
->length
->value
.integer
) < 0)
12460 gfc_replace_expr (cl
->length
,
12461 gfc_get_int_expr (gfc_charlen_int_kind
, NULL
, 0));
12463 /* Check that the character length is not too large. */
12464 k
= gfc_validate_kind (BT_INTEGER
, gfc_charlen_int_kind
, false);
12465 if (cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
12466 && cl
->length
->ts
.type
== BT_INTEGER
12467 && mpz_cmp (cl
->length
->value
.integer
, gfc_integer_kinds
[k
].huge
) > 0)
12469 gfc_error ("String length at %L is too large", &cl
->length
->where
);
12470 specification_expr
= saved_specification_expr
;
12474 specification_expr
= saved_specification_expr
;
12479 /* Test for non-constant shape arrays. */
12482 is_non_constant_shape_array (gfc_symbol
*sym
)
12488 not_constant
= false;
12489 if (sym
->as
!= NULL
)
12491 /* Unfortunately, !gfc_is_compile_time_shape hits a legal case that
12492 has not been simplified; parameter array references. Do the
12493 simplification now. */
12494 for (i
= 0; i
< sym
->as
->rank
+ sym
->as
->corank
; i
++)
12496 if (i
== GFC_MAX_DIMENSIONS
)
12499 e
= sym
->as
->lower
[i
];
12500 if (e
&& (!resolve_index_expr(e
)
12501 || !gfc_is_constant_expr (e
)))
12502 not_constant
= true;
12503 e
= sym
->as
->upper
[i
];
12504 if (e
&& (!resolve_index_expr(e
)
12505 || !gfc_is_constant_expr (e
)))
12506 not_constant
= true;
12509 return not_constant
;
12512 /* Given a symbol and an initialization expression, add code to initialize
12513 the symbol to the function entry. */
12515 build_init_assign (gfc_symbol
*sym
, gfc_expr
*init
)
12519 gfc_namespace
*ns
= sym
->ns
;
12521 /* Search for the function namespace if this is a contained
12522 function without an explicit result. */
12523 if (sym
->attr
.function
&& sym
== sym
->result
12524 && sym
->name
!= sym
->ns
->proc_name
->name
)
12526 ns
= ns
->contained
;
12527 for (;ns
; ns
= ns
->sibling
)
12528 if (strcmp (ns
->proc_name
->name
, sym
->name
) == 0)
12534 gfc_free_expr (init
);
12538 /* Build an l-value expression for the result. */
12539 lval
= gfc_lval_expr_from_sym (sym
);
12541 /* Add the code at scope entry. */
12542 init_st
= gfc_get_code (EXEC_INIT_ASSIGN
);
12543 init_st
->next
= ns
->code
;
12544 ns
->code
= init_st
;
12546 /* Assign the default initializer to the l-value. */
12547 init_st
->loc
= sym
->declared_at
;
12548 init_st
->expr1
= lval
;
12549 init_st
->expr2
= init
;
12553 /* Whether or not we can generate a default initializer for a symbol. */
12556 can_generate_init (gfc_symbol
*sym
)
12558 symbol_attribute
*a
;
12563 /* These symbols should never have a default initialization. */
12568 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)
12569 && (CLASS_DATA (sym
)->attr
.class_pointer
12570 || CLASS_DATA (sym
)->attr
.proc_pointer
))
12571 || a
->in_equivalence
12578 || (!a
->referenced
&& !a
->result
)
12579 || (a
->dummy
&& a
->intent
!= INTENT_OUT
)
12580 || (a
->function
&& sym
!= sym
->result
)
12585 /* Assign the default initializer to a derived type variable or result. */
12588 apply_default_init (gfc_symbol
*sym
)
12590 gfc_expr
*init
= NULL
;
12592 if (sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
12595 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
)
12596 init
= gfc_generate_initializer (&sym
->ts
, can_generate_init (sym
));
12598 if (init
== NULL
&& sym
->ts
.type
!= BT_CLASS
)
12601 build_init_assign (sym
, init
);
12602 sym
->attr
.referenced
= 1;
12606 /* Build an initializer for a local. Returns null if the symbol should not have
12607 a default initialization. */
12610 build_default_init_expr (gfc_symbol
*sym
)
12612 /* These symbols should never have a default initialization. */
12613 if (sym
->attr
.allocatable
12614 || sym
->attr
.external
12616 || sym
->attr
.pointer
12617 || sym
->attr
.in_equivalence
12618 || sym
->attr
.in_common
12621 || sym
->attr
.cray_pointee
12622 || sym
->attr
.cray_pointer
12626 /* Get the appropriate init expression. */
12627 return gfc_build_default_init_expr (&sym
->ts
, &sym
->declared_at
);
12630 /* Add an initialization expression to a local variable. */
12632 apply_default_init_local (gfc_symbol
*sym
)
12634 gfc_expr
*init
= NULL
;
12636 /* The symbol should be a variable or a function return value. */
12637 if ((sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
12638 || (sym
->attr
.function
&& sym
->result
!= sym
))
12641 /* Try to build the initializer expression. If we can't initialize
12642 this symbol, then init will be NULL. */
12643 init
= build_default_init_expr (sym
);
12647 /* For saved variables, we don't want to add an initializer at function
12648 entry, so we just add a static initializer. Note that automatic variables
12649 are stack allocated even with -fno-automatic; we have also to exclude
12650 result variable, which are also nonstatic. */
12651 if (!sym
->attr
.automatic
12652 && (sym
->attr
.save
|| sym
->ns
->save_all
12653 || (flag_max_stack_var_size
== 0 && !sym
->attr
.result
12654 && (sym
->ns
->proc_name
&& !sym
->ns
->proc_name
->attr
.recursive
)
12655 && (!sym
->attr
.dimension
|| !is_non_constant_shape_array (sym
)))))
12657 /* Don't clobber an existing initializer! */
12658 gcc_assert (sym
->value
== NULL
);
12663 build_init_assign (sym
, init
);
12667 /* Resolution of common features of flavors variable and procedure. */
12670 resolve_fl_var_and_proc (gfc_symbol
*sym
, int mp_flag
)
12672 gfc_array_spec
*as
;
12674 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
12675 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
))
12676 as
= CLASS_DATA (sym
)->as
;
12680 /* Constraints on deferred shape variable. */
12681 if (as
== NULL
|| as
->type
!= AS_DEFERRED
)
12683 bool pointer
, allocatable
, dimension
;
12685 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
12686 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
))
12688 pointer
= CLASS_DATA (sym
)->attr
.class_pointer
;
12689 allocatable
= CLASS_DATA (sym
)->attr
.allocatable
;
12690 dimension
= CLASS_DATA (sym
)->attr
.dimension
;
12694 pointer
= sym
->attr
.pointer
&& !sym
->attr
.select_type_temporary
;
12695 allocatable
= sym
->attr
.allocatable
;
12696 dimension
= sym
->attr
.dimension
;
12701 if (dimension
&& as
->type
!= AS_ASSUMED_RANK
)
12703 gfc_error ("Allocatable array %qs at %L must have a deferred "
12704 "shape or assumed rank", sym
->name
, &sym
->declared_at
);
12707 else if (!gfc_notify_std (GFC_STD_F2003
, "Scalar object "
12708 "%qs at %L may not be ALLOCATABLE",
12709 sym
->name
, &sym
->declared_at
))
12713 if (pointer
&& dimension
&& as
->type
!= AS_ASSUMED_RANK
)
12715 gfc_error ("Array pointer %qs at %L must have a deferred shape or "
12716 "assumed rank", sym
->name
, &sym
->declared_at
);
12723 if (!mp_flag
&& !sym
->attr
.allocatable
&& !sym
->attr
.pointer
12724 && sym
->ts
.type
!= BT_CLASS
&& !sym
->assoc
)
12726 gfc_error ("Array %qs at %L cannot have a deferred shape",
12727 sym
->name
, &sym
->declared_at
);
12732 /* Constraints on polymorphic variables. */
12733 if (sym
->ts
.type
== BT_CLASS
&& !(sym
->result
&& sym
->result
!= sym
))
12736 if (sym
->attr
.class_ok
12737 && sym
->ts
.u
.derived
12738 && !sym
->attr
.select_type_temporary
12739 && !UNLIMITED_POLY (sym
)
12740 && !gfc_type_is_extensible (CLASS_DATA (sym
)->ts
.u
.derived
))
12742 gfc_error ("Type %qs of CLASS variable %qs at %L is not extensible",
12743 CLASS_DATA (sym
)->ts
.u
.derived
->name
, sym
->name
,
12744 &sym
->declared_at
);
12749 /* Assume that use associated symbols were checked in the module ns.
12750 Class-variables that are associate-names are also something special
12751 and excepted from the test. */
12752 if (!sym
->attr
.class_ok
&& !sym
->attr
.use_assoc
&& !sym
->assoc
)
12754 gfc_error ("CLASS variable %qs at %L must be dummy, allocatable "
12755 "or pointer", sym
->name
, &sym
->declared_at
);
12764 /* Additional checks for symbols with flavor variable and derived
12765 type. To be called from resolve_fl_variable. */
12768 resolve_fl_variable_derived (gfc_symbol
*sym
, int no_init_flag
)
12770 gcc_assert (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
);
12772 /* Check to see if a derived type is blocked from being host
12773 associated by the presence of another class I symbol in the same
12774 namespace. 14.6.1.3 of the standard and the discussion on
12775 comp.lang.fortran. */
12776 if (sym
->ts
.u
.derived
12777 && sym
->ns
!= sym
->ts
.u
.derived
->ns
12778 && !sym
->ts
.u
.derived
->attr
.use_assoc
12779 && sym
->ns
->proc_name
->attr
.if_source
!= IFSRC_IFBODY
)
12782 gfc_find_symbol (sym
->ts
.u
.derived
->name
, sym
->ns
, 0, &s
);
12783 if (s
&& s
->attr
.generic
)
12784 s
= gfc_find_dt_in_generic (s
);
12785 if (s
&& !gfc_fl_struct (s
->attr
.flavor
))
12787 gfc_error ("The type %qs cannot be host associated at %L "
12788 "because it is blocked by an incompatible object "
12789 "of the same name declared at %L",
12790 sym
->ts
.u
.derived
->name
, &sym
->declared_at
,
12796 /* 4th constraint in section 11.3: "If an object of a type for which
12797 component-initialization is specified (R429) appears in the
12798 specification-part of a module and does not have the ALLOCATABLE
12799 or POINTER attribute, the object shall have the SAVE attribute."
12801 The check for initializers is performed with
12802 gfc_has_default_initializer because gfc_default_initializer generates
12803 a hidden default for allocatable components. */
12804 if (!(sym
->value
|| no_init_flag
) && sym
->ns
->proc_name
12805 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
12806 && !(sym
->ns
->save_all
&& !sym
->attr
.automatic
) && !sym
->attr
.save
12807 && !sym
->attr
.pointer
&& !sym
->attr
.allocatable
12808 && gfc_has_default_initializer (sym
->ts
.u
.derived
)
12809 && !gfc_notify_std (GFC_STD_F2008
, "Implied SAVE for module variable "
12810 "%qs at %L, needed due to the default "
12811 "initialization", sym
->name
, &sym
->declared_at
))
12814 /* Assign default initializer. */
12815 if (!(sym
->value
|| sym
->attr
.pointer
|| sym
->attr
.allocatable
)
12816 && (!no_init_flag
|| sym
->attr
.intent
== INTENT_OUT
))
12817 sym
->value
= gfc_generate_initializer (&sym
->ts
, can_generate_init (sym
));
12823 /* F2008, C402 (R401): A colon shall not be used as a type-param-value
12824 except in the declaration of an entity or component that has the POINTER
12825 or ALLOCATABLE attribute. */
12828 deferred_requirements (gfc_symbol
*sym
)
12830 if (sym
->ts
.deferred
12831 && !(sym
->attr
.pointer
12832 || sym
->attr
.allocatable
12833 || sym
->attr
.associate_var
12834 || sym
->attr
.omp_udr_artificial_var
))
12836 /* If a function has a result variable, only check the variable. */
12837 if (sym
->result
&& sym
->name
!= sym
->result
->name
)
12840 gfc_error ("Entity %qs at %L has a deferred type parameter and "
12841 "requires either the POINTER or ALLOCATABLE attribute",
12842 sym
->name
, &sym
->declared_at
);
12849 /* Resolve symbols with flavor variable. */
12852 resolve_fl_variable (gfc_symbol
*sym
, int mp_flag
)
12854 const char *auto_save_msg
= "Automatic object %qs at %L cannot have the "
12857 if (!resolve_fl_var_and_proc (sym
, mp_flag
))
12860 /* Set this flag to check that variables are parameters of all entries.
12861 This check is effected by the call to gfc_resolve_expr through
12862 is_non_constant_shape_array. */
12863 bool saved_specification_expr
= specification_expr
;
12864 specification_expr
= true;
12866 if (sym
->ns
->proc_name
12867 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
12868 || sym
->ns
->proc_name
->attr
.is_main_program
)
12869 && !sym
->attr
.use_assoc
12870 && !sym
->attr
.allocatable
12871 && !sym
->attr
.pointer
12872 && is_non_constant_shape_array (sym
))
12874 /* F08:C541. The shape of an array defined in a main program or module
12875 * needs to be constant. */
12876 gfc_error ("The module or main program array %qs at %L must "
12877 "have constant shape", sym
->name
, &sym
->declared_at
);
12878 specification_expr
= saved_specification_expr
;
12882 /* Constraints on deferred type parameter. */
12883 if (!deferred_requirements (sym
))
12886 if (sym
->ts
.type
== BT_CHARACTER
&& !sym
->attr
.associate_var
)
12888 /* Make sure that character string variables with assumed length are
12889 dummy arguments. */
12890 gfc_expr
*e
= NULL
;
12893 e
= sym
->ts
.u
.cl
->length
;
12897 if (e
== NULL
&& !sym
->attr
.dummy
&& !sym
->attr
.result
12898 && !sym
->ts
.deferred
&& !sym
->attr
.select_type_temporary
12899 && !sym
->attr
.omp_udr_artificial_var
)
12901 gfc_error ("Entity with assumed character length at %L must be a "
12902 "dummy argument or a PARAMETER", &sym
->declared_at
);
12903 specification_expr
= saved_specification_expr
;
12907 if (e
&& sym
->attr
.save
== SAVE_EXPLICIT
&& !gfc_is_constant_expr (e
))
12909 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
12910 specification_expr
= saved_specification_expr
;
12914 if (!gfc_is_constant_expr (e
)
12915 && !(e
->expr_type
== EXPR_VARIABLE
12916 && e
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
))
12918 if (!sym
->attr
.use_assoc
&& sym
->ns
->proc_name
12919 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
12920 || sym
->ns
->proc_name
->attr
.is_main_program
))
12922 gfc_error ("%qs at %L must have constant character length "
12923 "in this context", sym
->name
, &sym
->declared_at
);
12924 specification_expr
= saved_specification_expr
;
12927 if (sym
->attr
.in_common
)
12929 gfc_error ("COMMON variable %qs at %L must have constant "
12930 "character length", sym
->name
, &sym
->declared_at
);
12931 specification_expr
= saved_specification_expr
;
12937 if (sym
->value
== NULL
&& sym
->attr
.referenced
)
12938 apply_default_init_local (sym
); /* Try to apply a default initialization. */
12940 /* Determine if the symbol may not have an initializer. */
12941 int no_init_flag
= 0, automatic_flag
= 0;
12942 if (sym
->attr
.allocatable
|| sym
->attr
.external
|| sym
->attr
.dummy
12943 || sym
->attr
.intrinsic
|| sym
->attr
.result
)
12945 else if ((sym
->attr
.dimension
|| sym
->attr
.codimension
) && !sym
->attr
.pointer
12946 && is_non_constant_shape_array (sym
))
12948 no_init_flag
= automatic_flag
= 1;
12950 /* Also, they must not have the SAVE attribute.
12951 SAVE_IMPLICIT is checked below. */
12952 if (sym
->as
&& sym
->attr
.codimension
)
12954 int corank
= sym
->as
->corank
;
12955 sym
->as
->corank
= 0;
12956 no_init_flag
= automatic_flag
= is_non_constant_shape_array (sym
);
12957 sym
->as
->corank
= corank
;
12959 if (automatic_flag
&& sym
->attr
.save
== SAVE_EXPLICIT
)
12961 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
12962 specification_expr
= saved_specification_expr
;
12967 /* Ensure that any initializer is simplified. */
12969 gfc_simplify_expr (sym
->value
, 1);
12971 /* Reject illegal initializers. */
12972 if (!sym
->mark
&& sym
->value
)
12974 if (sym
->attr
.allocatable
|| (sym
->ts
.type
== BT_CLASS
12975 && CLASS_DATA (sym
)->attr
.allocatable
))
12976 gfc_error ("Allocatable %qs at %L cannot have an initializer",
12977 sym
->name
, &sym
->declared_at
);
12978 else if (sym
->attr
.external
)
12979 gfc_error ("External %qs at %L cannot have an initializer",
12980 sym
->name
, &sym
->declared_at
);
12981 else if (sym
->attr
.dummy
)
12982 gfc_error ("Dummy %qs at %L cannot have an initializer",
12983 sym
->name
, &sym
->declared_at
);
12984 else if (sym
->attr
.intrinsic
)
12985 gfc_error ("Intrinsic %qs at %L cannot have an initializer",
12986 sym
->name
, &sym
->declared_at
);
12987 else if (sym
->attr
.result
)
12988 gfc_error ("Function result %qs at %L cannot have an initializer",
12989 sym
->name
, &sym
->declared_at
);
12990 else if (automatic_flag
)
12991 gfc_error ("Automatic array %qs at %L cannot have an initializer",
12992 sym
->name
, &sym
->declared_at
);
12994 goto no_init_error
;
12995 specification_expr
= saved_specification_expr
;
13000 if (sym
->ts
.type
== BT_DERIVED
|| sym
->ts
.type
== BT_CLASS
)
13002 bool res
= resolve_fl_variable_derived (sym
, no_init_flag
);
13003 specification_expr
= saved_specification_expr
;
13007 specification_expr
= saved_specification_expr
;
13012 /* Compare the dummy characteristics of a module procedure interface
13013 declaration with the corresponding declaration in a submodule. */
13014 static gfc_formal_arglist
*new_formal
;
13015 static char errmsg
[200];
13018 compare_fsyms (gfc_symbol
*sym
)
13022 if (sym
== NULL
|| new_formal
== NULL
)
13025 fsym
= new_formal
->sym
;
13030 if (strcmp (sym
->name
, fsym
->name
) == 0)
13032 if (!gfc_check_dummy_characteristics (fsym
, sym
, true, errmsg
, 200))
13033 gfc_error ("%s at %L", errmsg
, &fsym
->declared_at
);
13038 /* Resolve a procedure. */
13041 resolve_fl_procedure (gfc_symbol
*sym
, int mp_flag
)
13043 gfc_formal_arglist
*arg
;
13045 if (sym
->attr
.function
13046 && !resolve_fl_var_and_proc (sym
, mp_flag
))
13049 /* Constraints on deferred type parameter. */
13050 if (!deferred_requirements (sym
))
13053 if (sym
->ts
.type
== BT_CHARACTER
)
13055 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
13057 if (cl
&& cl
->length
&& gfc_is_constant_expr (cl
->length
)
13058 && !resolve_charlen (cl
))
13061 if ((!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
13062 && sym
->attr
.proc
== PROC_ST_FUNCTION
)
13064 gfc_error ("Character-valued statement function %qs at %L must "
13065 "have constant length", sym
->name
, &sym
->declared_at
);
13070 /* Ensure that derived type for are not of a private type. Internal
13071 module procedures are excluded by 2.2.3.3 - i.e., they are not
13072 externally accessible and can access all the objects accessible in
13074 if (!(sym
->ns
->parent
&& sym
->ns
->parent
->proc_name
13075 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
13076 && gfc_check_symbol_access (sym
))
13078 gfc_interface
*iface
;
13080 for (arg
= gfc_sym_get_dummy_args (sym
); arg
; arg
= arg
->next
)
13083 && arg
->sym
->ts
.type
== BT_DERIVED
13084 && arg
->sym
->ts
.u
.derived
13085 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
13086 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
13087 && !gfc_notify_std (GFC_STD_F2003
, "%qs is of a PRIVATE type "
13088 "and cannot be a dummy argument"
13089 " of %qs, which is PUBLIC at %L",
13090 arg
->sym
->name
, sym
->name
,
13091 &sym
->declared_at
))
13093 /* Stop this message from recurring. */
13094 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
13099 /* PUBLIC interfaces may expose PRIVATE procedures that take types
13100 PRIVATE to the containing module. */
13101 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
13103 for (arg
= gfc_sym_get_dummy_args (iface
->sym
); arg
; arg
= arg
->next
)
13106 && arg
->sym
->ts
.type
== BT_DERIVED
13107 && !arg
->sym
->ts
.u
.derived
->attr
.use_assoc
13108 && !gfc_check_symbol_access (arg
->sym
->ts
.u
.derived
)
13109 && !gfc_notify_std (GFC_STD_F2003
, "Procedure %qs in "
13110 "PUBLIC interface %qs at %L "
13111 "takes dummy arguments of %qs which "
13112 "is PRIVATE", iface
->sym
->name
,
13113 sym
->name
, &iface
->sym
->declared_at
,
13114 gfc_typename(&arg
->sym
->ts
)))
13116 /* Stop this message from recurring. */
13117 arg
->sym
->ts
.u
.derived
->attr
.access
= ACCESS_PUBLIC
;
13124 if (sym
->attr
.function
&& sym
->value
&& sym
->attr
.proc
!= PROC_ST_FUNCTION
13125 && !sym
->attr
.proc_pointer
)
13127 gfc_error ("Function %qs at %L cannot have an initializer",
13128 sym
->name
, &sym
->declared_at
);
13130 /* Make sure no second error is issued for this. */
13131 sym
->value
->error
= 1;
13135 /* An external symbol may not have an initializer because it is taken to be
13136 a procedure. Exception: Procedure Pointers. */
13137 if (sym
->attr
.external
&& sym
->value
&& !sym
->attr
.proc_pointer
)
13139 gfc_error ("External object %qs at %L may not have an initializer",
13140 sym
->name
, &sym
->declared_at
);
13144 /* An elemental function is required to return a scalar 12.7.1 */
13145 if (sym
->attr
.elemental
&& sym
->attr
.function
13146 && (sym
->as
|| (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->as
)))
13148 gfc_error ("ELEMENTAL function %qs at %L must have a scalar "
13149 "result", sym
->name
, &sym
->declared_at
);
13150 /* Reset so that the error only occurs once. */
13151 sym
->attr
.elemental
= 0;
13155 if (sym
->attr
.proc
== PROC_ST_FUNCTION
13156 && (sym
->attr
.allocatable
|| sym
->attr
.pointer
))
13158 gfc_error ("Statement function %qs at %L may not have pointer or "
13159 "allocatable attribute", sym
->name
, &sym
->declared_at
);
13163 /* 5.1.1.5 of the Standard: A function name declared with an asterisk
13164 char-len-param shall not be array-valued, pointer-valued, recursive
13165 or pure. ....snip... A character value of * may only be used in the
13166 following ways: (i) Dummy arg of procedure - dummy associates with
13167 actual length; (ii) To declare a named constant; or (iii) External
13168 function - but length must be declared in calling scoping unit. */
13169 if (sym
->attr
.function
13170 && sym
->ts
.type
== BT_CHARACTER
&& !sym
->ts
.deferred
13171 && sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
== NULL
)
13173 if ((sym
->as
&& sym
->as
->rank
) || (sym
->attr
.pointer
)
13174 || (sym
->attr
.recursive
) || (sym
->attr
.pure
))
13176 if (sym
->as
&& sym
->as
->rank
)
13177 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
13178 "array-valued", sym
->name
, &sym
->declared_at
);
13180 if (sym
->attr
.pointer
)
13181 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
13182 "pointer-valued", sym
->name
, &sym
->declared_at
);
13184 if (sym
->attr
.pure
)
13185 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
13186 "pure", sym
->name
, &sym
->declared_at
);
13188 if (sym
->attr
.recursive
)
13189 gfc_error ("CHARACTER(*) function %qs at %L cannot be "
13190 "recursive", sym
->name
, &sym
->declared_at
);
13195 /* Appendix B.2 of the standard. Contained functions give an
13196 error anyway. Deferred character length is an F2003 feature.
13197 Don't warn on intrinsic conversion functions, which start
13198 with two underscores. */
13199 if (!sym
->attr
.contained
&& !sym
->ts
.deferred
13200 && (sym
->name
[0] != '_' || sym
->name
[1] != '_'))
13201 gfc_notify_std (GFC_STD_F95_OBS
,
13202 "CHARACTER(*) function %qs at %L",
13203 sym
->name
, &sym
->declared_at
);
13206 /* F2008, C1218. */
13207 if (sym
->attr
.elemental
)
13209 if (sym
->attr
.proc_pointer
)
13211 const char* name
= (sym
->attr
.result
? sym
->ns
->proc_name
->name
13213 gfc_error ("Procedure pointer %qs at %L shall not be elemental",
13214 name
, &sym
->declared_at
);
13217 if (sym
->attr
.dummy
)
13219 gfc_error ("Dummy procedure %qs at %L shall not be elemental",
13220 sym
->name
, &sym
->declared_at
);
13225 /* F2018, C15100: "The result of an elemental function shall be scalar,
13226 and shall not have the POINTER or ALLOCATABLE attribute." The scalar
13227 pointer is tested and caught elsewhere. */
13228 if (sym
->attr
.elemental
&& sym
->result
13229 && (sym
->result
->attr
.allocatable
|| sym
->result
->attr
.pointer
))
13231 gfc_error ("Function result variable %qs at %L of elemental "
13232 "function %qs shall not have an ALLOCATABLE or POINTER "
13233 "attribute", sym
->result
->name
,
13234 &sym
->result
->declared_at
, sym
->name
);
13238 if (sym
->attr
.is_bind_c
&& sym
->attr
.is_c_interop
!= 1)
13240 gfc_formal_arglist
*curr_arg
;
13241 int has_non_interop_arg
= 0;
13243 if (!verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
13244 sym
->common_block
))
13246 /* Clear these to prevent looking at them again if there was an
13248 sym
->attr
.is_bind_c
= 0;
13249 sym
->attr
.is_c_interop
= 0;
13250 sym
->ts
.is_c_interop
= 0;
13254 /* So far, no errors have been found. */
13255 sym
->attr
.is_c_interop
= 1;
13256 sym
->ts
.is_c_interop
= 1;
13259 curr_arg
= gfc_sym_get_dummy_args (sym
);
13260 while (curr_arg
!= NULL
)
13262 /* Skip implicitly typed dummy args here. */
13263 if (curr_arg
->sym
&& curr_arg
->sym
->attr
.implicit_type
== 0)
13264 if (!gfc_verify_c_interop_param (curr_arg
->sym
))
13265 /* If something is found to fail, record the fact so we
13266 can mark the symbol for the procedure as not being
13267 BIND(C) to try and prevent multiple errors being
13269 has_non_interop_arg
= 1;
13271 curr_arg
= curr_arg
->next
;
13274 /* See if any of the arguments were not interoperable and if so, clear
13275 the procedure symbol to prevent duplicate error messages. */
13276 if (has_non_interop_arg
!= 0)
13278 sym
->attr
.is_c_interop
= 0;
13279 sym
->ts
.is_c_interop
= 0;
13280 sym
->attr
.is_bind_c
= 0;
13284 if (!sym
->attr
.proc_pointer
)
13286 if (sym
->attr
.save
== SAVE_EXPLICIT
)
13288 gfc_error ("PROCEDURE attribute conflicts with SAVE attribute "
13289 "in %qs at %L", sym
->name
, &sym
->declared_at
);
13292 if (sym
->attr
.intent
)
13294 gfc_error ("PROCEDURE attribute conflicts with INTENT attribute "
13295 "in %qs at %L", sym
->name
, &sym
->declared_at
);
13298 if (sym
->attr
.subroutine
&& sym
->attr
.result
)
13300 gfc_error ("PROCEDURE attribute conflicts with RESULT attribute "
13301 "in %qs at %L", sym
->ns
->proc_name
->name
, &sym
->declared_at
);
13304 if (sym
->attr
.external
&& sym
->attr
.function
&& !sym
->attr
.module_procedure
13305 && ((sym
->attr
.if_source
== IFSRC_DECL
&& !sym
->attr
.procedure
)
13306 || sym
->attr
.contained
))
13308 gfc_error ("EXTERNAL attribute conflicts with FUNCTION attribute "
13309 "in %qs at %L", sym
->name
, &sym
->declared_at
);
13312 if (strcmp ("ppr@", sym
->name
) == 0)
13314 gfc_error ("Procedure pointer result %qs at %L "
13315 "is missing the pointer attribute",
13316 sym
->ns
->proc_name
->name
, &sym
->declared_at
);
13321 /* Assume that a procedure whose body is not known has references
13322 to external arrays. */
13323 if (sym
->attr
.if_source
!= IFSRC_DECL
)
13324 sym
->attr
.array_outer_dependency
= 1;
13326 /* Compare the characteristics of a module procedure with the
13327 interface declaration. Ideally this would be done with
13328 gfc_compare_interfaces but, at present, the formal interface
13329 cannot be copied to the ts.interface. */
13330 if (sym
->attr
.module_procedure
13331 && sym
->attr
.if_source
== IFSRC_DECL
)
13334 char name
[2*GFC_MAX_SYMBOL_LEN
+ 1];
13336 char *submodule_name
;
13337 strcpy (name
, sym
->ns
->proc_name
->name
);
13338 module_name
= strtok (name
, ".");
13339 submodule_name
= strtok (NULL
, ".");
13341 iface
= sym
->tlink
;
13344 /* Make sure that the result uses the correct charlen for deferred
13346 if (iface
&& sym
->result
13347 && iface
->ts
.type
== BT_CHARACTER
13348 && iface
->ts
.deferred
)
13349 sym
->result
->ts
.u
.cl
= iface
->ts
.u
.cl
;
13354 /* Check the procedure characteristics. */
13355 if (sym
->attr
.elemental
!= iface
->attr
.elemental
)
13357 gfc_error ("Mismatch in ELEMENTAL attribute between MODULE "
13358 "PROCEDURE at %L and its interface in %s",
13359 &sym
->declared_at
, module_name
);
13363 if (sym
->attr
.pure
!= iface
->attr
.pure
)
13365 gfc_error ("Mismatch in PURE attribute between MODULE "
13366 "PROCEDURE at %L and its interface in %s",
13367 &sym
->declared_at
, module_name
);
13371 if (sym
->attr
.recursive
!= iface
->attr
.recursive
)
13373 gfc_error ("Mismatch in RECURSIVE attribute between MODULE "
13374 "PROCEDURE at %L and its interface in %s",
13375 &sym
->declared_at
, module_name
);
13379 /* Check the result characteristics. */
13380 if (!gfc_check_result_characteristics (sym
, iface
, errmsg
, 200))
13382 gfc_error ("%s between the MODULE PROCEDURE declaration "
13383 "in MODULE %qs and the declaration at %L in "
13385 errmsg
, module_name
, &sym
->declared_at
,
13386 submodule_name
? submodule_name
: module_name
);
13391 /* Check the characteristics of the formal arguments. */
13392 if (sym
->formal
&& sym
->formal_ns
)
13394 for (arg
= sym
->formal
; arg
&& arg
->sym
; arg
= arg
->next
)
13397 gfc_traverse_ns (sym
->formal_ns
, compare_fsyms
);
13405 /* Resolve a list of finalizer procedures. That is, after they have hopefully
13406 been defined and we now know their defined arguments, check that they fulfill
13407 the requirements of the standard for procedures used as finalizers. */
13410 gfc_resolve_finalizers (gfc_symbol
* derived
, bool *finalizable
)
13412 gfc_finalizer
* list
;
13413 gfc_finalizer
** prev_link
; /* For removing wrong entries from the list. */
13414 bool result
= true;
13415 bool seen_scalar
= false;
13418 gfc_symbol
*parent
= gfc_get_derived_super_type (derived
);
13421 gfc_resolve_finalizers (parent
, finalizable
);
13423 /* Ensure that derived-type components have a their finalizers resolved. */
13424 bool has_final
= derived
->f2k_derived
&& derived
->f2k_derived
->finalizers
;
13425 for (c
= derived
->components
; c
; c
= c
->next
)
13426 if (c
->ts
.type
== BT_DERIVED
13427 && !c
->attr
.pointer
&& !c
->attr
.proc_pointer
&& !c
->attr
.allocatable
)
13429 bool has_final2
= false;
13430 if (!gfc_resolve_finalizers (c
->ts
.u
.derived
, &has_final2
))
13431 return false; /* Error. */
13432 has_final
= has_final
|| has_final2
;
13434 /* Return early if not finalizable. */
13438 *finalizable
= false;
13442 /* Walk over the list of finalizer-procedures, check them, and if any one
13443 does not fit in with the standard's definition, print an error and remove
13444 it from the list. */
13445 prev_link
= &derived
->f2k_derived
->finalizers
;
13446 for (list
= derived
->f2k_derived
->finalizers
; list
; list
= *prev_link
)
13448 gfc_formal_arglist
*dummy_args
;
13453 /* Skip this finalizer if we already resolved it. */
13454 if (list
->proc_tree
)
13456 if (list
->proc_tree
->n
.sym
->formal
->sym
->as
== NULL
13457 || list
->proc_tree
->n
.sym
->formal
->sym
->as
->rank
== 0)
13458 seen_scalar
= true;
13459 prev_link
= &(list
->next
);
13463 /* Check this exists and is a SUBROUTINE. */
13464 if (!list
->proc_sym
->attr
.subroutine
)
13466 gfc_error ("FINAL procedure %qs at %L is not a SUBROUTINE",
13467 list
->proc_sym
->name
, &list
->where
);
13471 /* We should have exactly one argument. */
13472 dummy_args
= gfc_sym_get_dummy_args (list
->proc_sym
);
13473 if (!dummy_args
|| dummy_args
->next
)
13475 gfc_error ("FINAL procedure at %L must have exactly one argument",
13479 arg
= dummy_args
->sym
;
13481 /* This argument must be of our type. */
13482 if (arg
->ts
.type
!= BT_DERIVED
|| arg
->ts
.u
.derived
!= derived
)
13484 gfc_error ("Argument of FINAL procedure at %L must be of type %qs",
13485 &arg
->declared_at
, derived
->name
);
13489 /* It must neither be a pointer nor allocatable nor optional. */
13490 if (arg
->attr
.pointer
)
13492 gfc_error ("Argument of FINAL procedure at %L must not be a POINTER",
13493 &arg
->declared_at
);
13496 if (arg
->attr
.allocatable
)
13498 gfc_error ("Argument of FINAL procedure at %L must not be"
13499 " ALLOCATABLE", &arg
->declared_at
);
13502 if (arg
->attr
.optional
)
13504 gfc_error ("Argument of FINAL procedure at %L must not be OPTIONAL",
13505 &arg
->declared_at
);
13509 /* It must not be INTENT(OUT). */
13510 if (arg
->attr
.intent
== INTENT_OUT
)
13512 gfc_error ("Argument of FINAL procedure at %L must not be"
13513 " INTENT(OUT)", &arg
->declared_at
);
13517 /* Warn if the procedure is non-scalar and not assumed shape. */
13518 if (warn_surprising
&& arg
->as
&& arg
->as
->rank
!= 0
13519 && arg
->as
->type
!= AS_ASSUMED_SHAPE
)
13520 gfc_warning (OPT_Wsurprising
,
13521 "Non-scalar FINAL procedure at %L should have assumed"
13522 " shape argument", &arg
->declared_at
);
13524 /* Check that it does not match in kind and rank with a FINAL procedure
13525 defined earlier. To really loop over the *earlier* declarations,
13526 we need to walk the tail of the list as new ones were pushed at the
13528 /* TODO: Handle kind parameters once they are implemented. */
13529 my_rank
= (arg
->as
? arg
->as
->rank
: 0);
13530 for (i
= list
->next
; i
; i
= i
->next
)
13532 gfc_formal_arglist
*dummy_args
;
13534 /* Argument list might be empty; that is an error signalled earlier,
13535 but we nevertheless continued resolving. */
13536 dummy_args
= gfc_sym_get_dummy_args (i
->proc_sym
);
13539 gfc_symbol
* i_arg
= dummy_args
->sym
;
13540 const int i_rank
= (i_arg
->as
? i_arg
->as
->rank
: 0);
13541 if (i_rank
== my_rank
)
13543 gfc_error ("FINAL procedure %qs declared at %L has the same"
13544 " rank (%d) as %qs",
13545 list
->proc_sym
->name
, &list
->where
, my_rank
,
13546 i
->proc_sym
->name
);
13552 /* Is this the/a scalar finalizer procedure? */
13554 seen_scalar
= true;
13556 /* Find the symtree for this procedure. */
13557 gcc_assert (!list
->proc_tree
);
13558 list
->proc_tree
= gfc_find_sym_in_symtree (list
->proc_sym
);
13560 prev_link
= &list
->next
;
13563 /* Remove wrong nodes immediately from the list so we don't risk any
13564 troubles in the future when they might fail later expectations. */
13567 *prev_link
= list
->next
;
13568 gfc_free_finalizer (i
);
13572 if (result
== false)
13575 /* Warn if we haven't seen a scalar finalizer procedure (but we know there
13576 were nodes in the list, must have been for arrays. It is surely a good
13577 idea to have a scalar version there if there's something to finalize. */
13578 if (warn_surprising
&& derived
->f2k_derived
->finalizers
&& !seen_scalar
)
13579 gfc_warning (OPT_Wsurprising
,
13580 "Only array FINAL procedures declared for derived type %qs"
13581 " defined at %L, suggest also scalar one",
13582 derived
->name
, &derived
->declared_at
);
13584 vtab
= gfc_find_derived_vtab (derived
);
13585 c
= vtab
->ts
.u
.derived
->components
->next
->next
->next
->next
->next
;
13586 gfc_set_sym_referenced (c
->initializer
->symtree
->n
.sym
);
13589 *finalizable
= true;
13595 /* Check if two GENERIC targets are ambiguous and emit an error is they are. */
13598 check_generic_tbp_ambiguity (gfc_tbp_generic
* t1
, gfc_tbp_generic
* t2
,
13599 const char* generic_name
, locus where
)
13601 gfc_symbol
*sym1
, *sym2
;
13602 const char *pass1
, *pass2
;
13603 gfc_formal_arglist
*dummy_args
;
13605 gcc_assert (t1
->specific
&& t2
->specific
);
13606 gcc_assert (!t1
->specific
->is_generic
);
13607 gcc_assert (!t2
->specific
->is_generic
);
13608 gcc_assert (t1
->is_operator
== t2
->is_operator
);
13610 sym1
= t1
->specific
->u
.specific
->n
.sym
;
13611 sym2
= t2
->specific
->u
.specific
->n
.sym
;
13616 /* Both must be SUBROUTINEs or both must be FUNCTIONs. */
13617 if (sym1
->attr
.subroutine
!= sym2
->attr
.subroutine
13618 || sym1
->attr
.function
!= sym2
->attr
.function
)
13620 gfc_error ("%qs and %qs cannot be mixed FUNCTION/SUBROUTINE for"
13621 " GENERIC %qs at %L",
13622 sym1
->name
, sym2
->name
, generic_name
, &where
);
13626 /* Determine PASS arguments. */
13627 if (t1
->specific
->nopass
)
13629 else if (t1
->specific
->pass_arg
)
13630 pass1
= t1
->specific
->pass_arg
;
13633 dummy_args
= gfc_sym_get_dummy_args (t1
->specific
->u
.specific
->n
.sym
);
13635 pass1
= dummy_args
->sym
->name
;
13639 if (t2
->specific
->nopass
)
13641 else if (t2
->specific
->pass_arg
)
13642 pass2
= t2
->specific
->pass_arg
;
13645 dummy_args
= gfc_sym_get_dummy_args (t2
->specific
->u
.specific
->n
.sym
);
13647 pass2
= dummy_args
->sym
->name
;
13652 /* Compare the interfaces. */
13653 if (gfc_compare_interfaces (sym1
, sym2
, sym2
->name
, !t1
->is_operator
, 0,
13654 NULL
, 0, pass1
, pass2
))
13656 gfc_error ("%qs and %qs for GENERIC %qs at %L are ambiguous",
13657 sym1
->name
, sym2
->name
, generic_name
, &where
);
13665 /* Worker function for resolving a generic procedure binding; this is used to
13666 resolve GENERIC as well as user and intrinsic OPERATOR typebound procedures.
13668 The difference between those cases is finding possible inherited bindings
13669 that are overridden, as one has to look for them in tb_sym_root,
13670 tb_uop_root or tb_op, respectively. Thus the caller must already find
13671 the super-type and set p->overridden correctly. */
13674 resolve_tb_generic_targets (gfc_symbol
* super_type
,
13675 gfc_typebound_proc
* p
, const char* name
)
13677 gfc_tbp_generic
* target
;
13678 gfc_symtree
* first_target
;
13679 gfc_symtree
* inherited
;
13681 gcc_assert (p
&& p
->is_generic
);
13683 /* Try to find the specific bindings for the symtrees in our target-list. */
13684 gcc_assert (p
->u
.generic
);
13685 for (target
= p
->u
.generic
; target
; target
= target
->next
)
13686 if (!target
->specific
)
13688 gfc_typebound_proc
* overridden_tbp
;
13689 gfc_tbp_generic
* g
;
13690 const char* target_name
;
13692 target_name
= target
->specific_st
->name
;
13694 /* Defined for this type directly. */
13695 if (target
->specific_st
->n
.tb
&& !target
->specific_st
->n
.tb
->error
)
13697 target
->specific
= target
->specific_st
->n
.tb
;
13698 goto specific_found
;
13701 /* Look for an inherited specific binding. */
13704 inherited
= gfc_find_typebound_proc (super_type
, NULL
, target_name
,
13709 gcc_assert (inherited
->n
.tb
);
13710 target
->specific
= inherited
->n
.tb
;
13711 goto specific_found
;
13715 gfc_error ("Undefined specific binding %qs as target of GENERIC %qs"
13716 " at %L", target_name
, name
, &p
->where
);
13719 /* Once we've found the specific binding, check it is not ambiguous with
13720 other specifics already found or inherited for the same GENERIC. */
13722 gcc_assert (target
->specific
);
13724 /* This must really be a specific binding! */
13725 if (target
->specific
->is_generic
)
13727 gfc_error ("GENERIC %qs at %L must target a specific binding,"
13728 " %qs is GENERIC, too", name
, &p
->where
, target_name
);
13732 /* Check those already resolved on this type directly. */
13733 for (g
= p
->u
.generic
; g
; g
= g
->next
)
13734 if (g
!= target
&& g
->specific
13735 && !check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
13738 /* Check for ambiguity with inherited specific targets. */
13739 for (overridden_tbp
= p
->overridden
; overridden_tbp
;
13740 overridden_tbp
= overridden_tbp
->overridden
)
13741 if (overridden_tbp
->is_generic
)
13743 for (g
= overridden_tbp
->u
.generic
; g
; g
= g
->next
)
13745 gcc_assert (g
->specific
);
13746 if (!check_generic_tbp_ambiguity (target
, g
, name
, p
->where
))
13752 /* If we attempt to "overwrite" a specific binding, this is an error. */
13753 if (p
->overridden
&& !p
->overridden
->is_generic
)
13755 gfc_error ("GENERIC %qs at %L cannot overwrite specific binding with"
13756 " the same name", name
, &p
->where
);
13760 /* Take the SUBROUTINE/FUNCTION attributes of the first specific target, as
13761 all must have the same attributes here. */
13762 first_target
= p
->u
.generic
->specific
->u
.specific
;
13763 gcc_assert (first_target
);
13764 p
->subroutine
= first_target
->n
.sym
->attr
.subroutine
;
13765 p
->function
= first_target
->n
.sym
->attr
.function
;
13771 /* Resolve a GENERIC procedure binding for a derived type. */
13774 resolve_typebound_generic (gfc_symbol
* derived
, gfc_symtree
* st
)
13776 gfc_symbol
* super_type
;
13778 /* Find the overridden binding if any. */
13779 st
->n
.tb
->overridden
= NULL
;
13780 super_type
= gfc_get_derived_super_type (derived
);
13783 gfc_symtree
* overridden
;
13784 overridden
= gfc_find_typebound_proc (super_type
, NULL
, st
->name
,
13787 if (overridden
&& overridden
->n
.tb
)
13788 st
->n
.tb
->overridden
= overridden
->n
.tb
;
13791 /* Resolve using worker function. */
13792 return resolve_tb_generic_targets (super_type
, st
->n
.tb
, st
->name
);
13796 /* Retrieve the target-procedure of an operator binding and do some checks in
13797 common for intrinsic and user-defined type-bound operators. */
13800 get_checked_tb_operator_target (gfc_tbp_generic
* target
, locus where
)
13802 gfc_symbol
* target_proc
;
13804 gcc_assert (target
->specific
&& !target
->specific
->is_generic
);
13805 target_proc
= target
->specific
->u
.specific
->n
.sym
;
13806 gcc_assert (target_proc
);
13808 /* F08:C468. All operator bindings must have a passed-object dummy argument. */
13809 if (target
->specific
->nopass
)
13811 gfc_error ("Type-bound operator at %L cannot be NOPASS", &where
);
13815 return target_proc
;
13819 /* Resolve a type-bound intrinsic operator. */
13822 resolve_typebound_intrinsic_op (gfc_symbol
* derived
, gfc_intrinsic_op op
,
13823 gfc_typebound_proc
* p
)
13825 gfc_symbol
* super_type
;
13826 gfc_tbp_generic
* target
;
13828 /* If there's already an error here, do nothing (but don't fail again). */
13832 /* Operators should always be GENERIC bindings. */
13833 gcc_assert (p
->is_generic
);
13835 /* Look for an overridden binding. */
13836 super_type
= gfc_get_derived_super_type (derived
);
13837 if (super_type
&& super_type
->f2k_derived
)
13838 p
->overridden
= gfc_find_typebound_intrinsic_op (super_type
, NULL
,
13841 p
->overridden
= NULL
;
13843 /* Resolve general GENERIC properties using worker function. */
13844 if (!resolve_tb_generic_targets (super_type
, p
, gfc_op2string(op
)))
13847 /* Check the targets to be procedures of correct interface. */
13848 for (target
= p
->u
.generic
; target
; target
= target
->next
)
13850 gfc_symbol
* target_proc
;
13852 target_proc
= get_checked_tb_operator_target (target
, p
->where
);
13856 if (!gfc_check_operator_interface (target_proc
, op
, p
->where
))
13859 /* Add target to non-typebound operator list. */
13860 if (!target
->specific
->deferred
&& !derived
->attr
.use_assoc
13861 && p
->access
!= ACCESS_PRIVATE
&& derived
->ns
== gfc_current_ns
)
13863 gfc_interface
*head
, *intr
;
13865 /* Preempt 'gfc_check_new_interface' for submodules, where the
13866 mechanism for handling module procedures winds up resolving
13867 operator interfaces twice and would otherwise cause an error. */
13868 for (intr
= derived
->ns
->op
[op
]; intr
; intr
= intr
->next
)
13869 if (intr
->sym
== target_proc
13870 && target_proc
->attr
.used_in_submodule
)
13873 if (!gfc_check_new_interface (derived
->ns
->op
[op
],
13874 target_proc
, p
->where
))
13876 head
= derived
->ns
->op
[op
];
13877 intr
= gfc_get_interface ();
13878 intr
->sym
= target_proc
;
13879 intr
->where
= p
->where
;
13881 derived
->ns
->op
[op
] = intr
;
13893 /* Resolve a type-bound user operator (tree-walker callback). */
13895 static gfc_symbol
* resolve_bindings_derived
;
13896 static bool resolve_bindings_result
;
13898 static bool check_uop_procedure (gfc_symbol
* sym
, locus where
);
13901 resolve_typebound_user_op (gfc_symtree
* stree
)
13903 gfc_symbol
* super_type
;
13904 gfc_tbp_generic
* target
;
13906 gcc_assert (stree
&& stree
->n
.tb
);
13908 if (stree
->n
.tb
->error
)
13911 /* Operators should always be GENERIC bindings. */
13912 gcc_assert (stree
->n
.tb
->is_generic
);
13914 /* Find overridden procedure, if any. */
13915 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
13916 if (super_type
&& super_type
->f2k_derived
)
13918 gfc_symtree
* overridden
;
13919 overridden
= gfc_find_typebound_user_op (super_type
, NULL
,
13920 stree
->name
, true, NULL
);
13922 if (overridden
&& overridden
->n
.tb
)
13923 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
13926 stree
->n
.tb
->overridden
= NULL
;
13928 /* Resolve basically using worker function. */
13929 if (!resolve_tb_generic_targets (super_type
, stree
->n
.tb
, stree
->name
))
13932 /* Check the targets to be functions of correct interface. */
13933 for (target
= stree
->n
.tb
->u
.generic
; target
; target
= target
->next
)
13935 gfc_symbol
* target_proc
;
13937 target_proc
= get_checked_tb_operator_target (target
, stree
->n
.tb
->where
);
13941 if (!check_uop_procedure (target_proc
, stree
->n
.tb
->where
))
13948 resolve_bindings_result
= false;
13949 stree
->n
.tb
->error
= 1;
13953 /* Resolve the type-bound procedures for a derived type. */
13956 resolve_typebound_procedure (gfc_symtree
* stree
)
13960 gfc_symbol
* me_arg
;
13961 gfc_symbol
* super_type
;
13962 gfc_component
* comp
;
13964 gcc_assert (stree
);
13966 /* Undefined specific symbol from GENERIC target definition. */
13970 if (stree
->n
.tb
->error
)
13973 /* If this is a GENERIC binding, use that routine. */
13974 if (stree
->n
.tb
->is_generic
)
13976 if (!resolve_typebound_generic (resolve_bindings_derived
, stree
))
13981 /* Get the target-procedure to check it. */
13982 gcc_assert (!stree
->n
.tb
->is_generic
);
13983 gcc_assert (stree
->n
.tb
->u
.specific
);
13984 proc
= stree
->n
.tb
->u
.specific
->n
.sym
;
13985 where
= stree
->n
.tb
->where
;
13987 /* Default access should already be resolved from the parser. */
13988 gcc_assert (stree
->n
.tb
->access
!= ACCESS_UNKNOWN
);
13990 if (stree
->n
.tb
->deferred
)
13992 if (!check_proc_interface (proc
, &where
))
13997 /* If proc has not been resolved at this point, proc->name may
13998 actually be a USE associated entity. See PR fortran/89647. */
13999 if (!proc
->resolve_symbol_called
14000 && proc
->attr
.function
== 0 && proc
->attr
.subroutine
== 0)
14003 gfc_find_symbol (proc
->name
, gfc_current_ns
->parent
, 1, &tmp
);
14004 if (tmp
&& tmp
->attr
.use_assoc
)
14006 proc
->module
= tmp
->module
;
14007 proc
->attr
.proc
= tmp
->attr
.proc
;
14008 proc
->attr
.function
= tmp
->attr
.function
;
14009 proc
->attr
.subroutine
= tmp
->attr
.subroutine
;
14010 proc
->attr
.use_assoc
= tmp
->attr
.use_assoc
;
14011 proc
->ts
= tmp
->ts
;
14012 proc
->result
= tmp
->result
;
14016 /* Check for F08:C465. */
14017 if ((!proc
->attr
.subroutine
&& !proc
->attr
.function
)
14018 || (proc
->attr
.proc
!= PROC_MODULE
14019 && proc
->attr
.if_source
!= IFSRC_IFBODY
)
14020 || proc
->attr
.abstract
)
14022 gfc_error ("%qs must be a module procedure or an external "
14023 "procedure with an explicit interface at %L",
14024 proc
->name
, &where
);
14029 stree
->n
.tb
->subroutine
= proc
->attr
.subroutine
;
14030 stree
->n
.tb
->function
= proc
->attr
.function
;
14032 /* Find the super-type of the current derived type. We could do this once and
14033 store in a global if speed is needed, but as long as not I believe this is
14034 more readable and clearer. */
14035 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
14037 /* If PASS, resolve and check arguments if not already resolved / loaded
14038 from a .mod file. */
14039 if (!stree
->n
.tb
->nopass
&& stree
->n
.tb
->pass_arg_num
== 0)
14041 gfc_formal_arglist
*dummy_args
;
14043 dummy_args
= gfc_sym_get_dummy_args (proc
);
14044 if (stree
->n
.tb
->pass_arg
)
14046 gfc_formal_arglist
*i
;
14048 /* If an explicit passing argument name is given, walk the arg-list
14049 and look for it. */
14052 stree
->n
.tb
->pass_arg_num
= 1;
14053 for (i
= dummy_args
; i
; i
= i
->next
)
14055 if (!strcmp (i
->sym
->name
, stree
->n
.tb
->pass_arg
))
14060 ++stree
->n
.tb
->pass_arg_num
;
14065 gfc_error ("Procedure %qs with PASS(%s) at %L has no"
14067 proc
->name
, stree
->n
.tb
->pass_arg
, &where
,
14068 stree
->n
.tb
->pass_arg
);
14074 /* Otherwise, take the first one; there should in fact be at least
14076 stree
->n
.tb
->pass_arg_num
= 1;
14079 gfc_error ("Procedure %qs with PASS at %L must have at"
14080 " least one argument", proc
->name
, &where
);
14083 me_arg
= dummy_args
->sym
;
14086 /* Now check that the argument-type matches and the passed-object
14087 dummy argument is generally fine. */
14089 gcc_assert (me_arg
);
14091 if (me_arg
->ts
.type
!= BT_CLASS
)
14093 gfc_error ("Non-polymorphic passed-object dummy argument of %qs"
14094 " at %L", proc
->name
, &where
);
14098 if (CLASS_DATA (me_arg
)->ts
.u
.derived
14099 != resolve_bindings_derived
)
14101 gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of"
14102 " the derived-type %qs", me_arg
->name
, proc
->name
,
14103 me_arg
->name
, &where
, resolve_bindings_derived
->name
);
14107 gcc_assert (me_arg
->ts
.type
== BT_CLASS
);
14108 if (CLASS_DATA (me_arg
)->as
&& CLASS_DATA (me_arg
)->as
->rank
!= 0)
14110 gfc_error ("Passed-object dummy argument of %qs at %L must be"
14111 " scalar", proc
->name
, &where
);
14114 if (CLASS_DATA (me_arg
)->attr
.allocatable
)
14116 gfc_error ("Passed-object dummy argument of %qs at %L must not"
14117 " be ALLOCATABLE", proc
->name
, &where
);
14120 if (CLASS_DATA (me_arg
)->attr
.class_pointer
)
14122 gfc_error ("Passed-object dummy argument of %qs at %L must not"
14123 " be POINTER", proc
->name
, &where
);
14128 /* If we are extending some type, check that we don't override a procedure
14129 flagged NON_OVERRIDABLE. */
14130 stree
->n
.tb
->overridden
= NULL
;
14133 gfc_symtree
* overridden
;
14134 overridden
= gfc_find_typebound_proc (super_type
, NULL
,
14135 stree
->name
, true, NULL
);
14139 if (overridden
->n
.tb
)
14140 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
14142 if (!gfc_check_typebound_override (stree
, overridden
))
14147 /* See if there's a name collision with a component directly in this type. */
14148 for (comp
= resolve_bindings_derived
->components
; comp
; comp
= comp
->next
)
14149 if (!strcmp (comp
->name
, stree
->name
))
14151 gfc_error ("Procedure %qs at %L has the same name as a component of"
14153 stree
->name
, &where
, resolve_bindings_derived
->name
);
14157 /* Try to find a name collision with an inherited component. */
14158 if (super_type
&& gfc_find_component (super_type
, stree
->name
, true, true,
14161 gfc_error ("Procedure %qs at %L has the same name as an inherited"
14162 " component of %qs",
14163 stree
->name
, &where
, resolve_bindings_derived
->name
);
14167 stree
->n
.tb
->error
= 0;
14171 resolve_bindings_result
= false;
14172 stree
->n
.tb
->error
= 1;
14177 resolve_typebound_procedures (gfc_symbol
* derived
)
14180 gfc_symbol
* super_type
;
14182 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->tb_sym_root
)
14185 super_type
= gfc_get_derived_super_type (derived
);
14187 resolve_symbol (super_type
);
14189 resolve_bindings_derived
= derived
;
14190 resolve_bindings_result
= true;
14192 if (derived
->f2k_derived
->tb_sym_root
)
14193 gfc_traverse_symtree (derived
->f2k_derived
->tb_sym_root
,
14194 &resolve_typebound_procedure
);
14196 if (derived
->f2k_derived
->tb_uop_root
)
14197 gfc_traverse_symtree (derived
->f2k_derived
->tb_uop_root
,
14198 &resolve_typebound_user_op
);
14200 for (op
= 0; op
!= GFC_INTRINSIC_OPS
; ++op
)
14202 gfc_typebound_proc
* p
= derived
->f2k_derived
->tb_op
[op
];
14203 if (p
&& !resolve_typebound_intrinsic_op (derived
,
14204 (gfc_intrinsic_op
)op
, p
))
14205 resolve_bindings_result
= false;
14208 return resolve_bindings_result
;
14212 /* Add a derived type to the dt_list. The dt_list is used in trans-types.c
14213 to give all identical derived types the same backend_decl. */
14215 add_dt_to_dt_list (gfc_symbol
*derived
)
14217 if (!derived
->dt_next
)
14219 if (gfc_derived_types
)
14221 derived
->dt_next
= gfc_derived_types
->dt_next
;
14222 gfc_derived_types
->dt_next
= derived
;
14226 derived
->dt_next
= derived
;
14228 gfc_derived_types
= derived
;
14233 /* Ensure that a derived-type is really not abstract, meaning that every
14234 inherited DEFERRED binding is overridden by a non-DEFERRED one. */
14237 ensure_not_abstract_walker (gfc_symbol
* sub
, gfc_symtree
* st
)
14242 if (!ensure_not_abstract_walker (sub
, st
->left
))
14244 if (!ensure_not_abstract_walker (sub
, st
->right
))
14247 if (st
->n
.tb
&& st
->n
.tb
->deferred
)
14249 gfc_symtree
* overriding
;
14250 overriding
= gfc_find_typebound_proc (sub
, NULL
, st
->name
, true, NULL
);
14253 gcc_assert (overriding
->n
.tb
);
14254 if (overriding
->n
.tb
->deferred
)
14256 gfc_error ("Derived-type %qs declared at %L must be ABSTRACT because"
14257 " %qs is DEFERRED and not overridden",
14258 sub
->name
, &sub
->declared_at
, st
->name
);
14267 ensure_not_abstract (gfc_symbol
* sub
, gfc_symbol
* ancestor
)
14269 /* The algorithm used here is to recursively travel up the ancestry of sub
14270 and for each ancestor-type, check all bindings. If any of them is
14271 DEFERRED, look it up starting from sub and see if the found (overriding)
14272 binding is not DEFERRED.
14273 This is not the most efficient way to do this, but it should be ok and is
14274 clearer than something sophisticated. */
14276 gcc_assert (ancestor
&& !sub
->attr
.abstract
);
14278 if (!ancestor
->attr
.abstract
)
14281 /* Walk bindings of this ancestor. */
14282 if (ancestor
->f2k_derived
)
14285 t
= ensure_not_abstract_walker (sub
, ancestor
->f2k_derived
->tb_sym_root
);
14290 /* Find next ancestor type and recurse on it. */
14291 ancestor
= gfc_get_derived_super_type (ancestor
);
14293 return ensure_not_abstract (sub
, ancestor
);
14299 /* This check for typebound defined assignments is done recursively
14300 since the order in which derived types are resolved is not always in
14301 order of the declarations. */
14304 check_defined_assignments (gfc_symbol
*derived
)
14308 for (c
= derived
->components
; c
; c
= c
->next
)
14310 if (!gfc_bt_struct (c
->ts
.type
)
14312 || c
->attr
.allocatable
14313 || c
->attr
.proc_pointer_comp
14314 || c
->attr
.class_pointer
14315 || c
->attr
.proc_pointer
)
14318 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
14319 || (c
->ts
.u
.derived
->f2k_derived
14320 && c
->ts
.u
.derived
->f2k_derived
->tb_op
[INTRINSIC_ASSIGN
]))
14322 derived
->attr
.defined_assign_comp
= 1;
14326 check_defined_assignments (c
->ts
.u
.derived
);
14327 if (c
->ts
.u
.derived
->attr
.defined_assign_comp
)
14329 derived
->attr
.defined_assign_comp
= 1;
14336 /* Resolve a single component of a derived type or structure. */
14339 resolve_component (gfc_component
*c
, gfc_symbol
*sym
)
14341 gfc_symbol
*super_type
;
14342 symbol_attribute
*attr
;
14344 if (c
->attr
.artificial
)
14347 /* Do not allow vtype components to be resolved in nameless namespaces
14348 such as block data because the procedure pointers will cause ICEs
14349 and vtables are not needed in these contexts. */
14350 if (sym
->attr
.vtype
&& sym
->attr
.use_assoc
14351 && sym
->ns
->proc_name
== NULL
)
14355 if ((!sym
->attr
.is_class
|| c
!= sym
->components
)
14356 && c
->attr
.codimension
14357 && (!c
->attr
.allocatable
|| (c
->as
&& c
->as
->type
!= AS_DEFERRED
)))
14359 gfc_error ("Coarray component %qs at %L must be allocatable with "
14360 "deferred shape", c
->name
, &c
->loc
);
14365 if (c
->attr
.codimension
&& c
->ts
.type
== BT_DERIVED
14366 && c
->ts
.u
.derived
->ts
.is_iso_c
)
14368 gfc_error ("Component %qs at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
14369 "shall not be a coarray", c
->name
, &c
->loc
);
14374 if (gfc_bt_struct (c
->ts
.type
) && c
->ts
.u
.derived
->attr
.coarray_comp
14375 && (c
->attr
.codimension
|| c
->attr
.pointer
|| c
->attr
.dimension
14376 || c
->attr
.allocatable
))
14378 gfc_error ("Component %qs at %L with coarray component "
14379 "shall be a nonpointer, nonallocatable scalar",
14385 if (c
->ts
.type
== BT_CLASS
)
14387 if (CLASS_DATA (c
))
14389 attr
= &(CLASS_DATA (c
)->attr
);
14391 /* Fix up contiguous attribute. */
14392 if (c
->attr
.contiguous
)
14393 attr
->contiguous
= 1;
14401 if (attr
&& attr
->contiguous
&& (!attr
->dimension
|| !attr
->pointer
))
14403 gfc_error ("Component %qs at %L has the CONTIGUOUS attribute but "
14404 "is not an array pointer", c
->name
, &c
->loc
);
14408 /* F2003, 15.2.1 - length has to be one. */
14409 if (sym
->attr
.is_bind_c
&& c
->ts
.type
== BT_CHARACTER
14410 && (c
->ts
.u
.cl
== NULL
|| c
->ts
.u
.cl
->length
== NULL
14411 || !gfc_is_constant_expr (c
->ts
.u
.cl
->length
)
14412 || mpz_cmp_si (c
->ts
.u
.cl
->length
->value
.integer
, 1) != 0))
14414 gfc_error ("Component %qs of BIND(C) type at %L must have length one",
14419 if (c
->attr
.proc_pointer
&& c
->ts
.interface
)
14421 gfc_symbol
*ifc
= c
->ts
.interface
;
14423 if (!sym
->attr
.vtype
&& !check_proc_interface (ifc
, &c
->loc
))
14429 if (ifc
->attr
.if_source
|| ifc
->attr
.intrinsic
)
14431 /* Resolve interface and copy attributes. */
14432 if (ifc
->formal
&& !ifc
->formal_ns
)
14433 resolve_symbol (ifc
);
14434 if (ifc
->attr
.intrinsic
)
14435 gfc_resolve_intrinsic (ifc
, &ifc
->declared_at
);
14439 c
->ts
= ifc
->result
->ts
;
14440 c
->attr
.allocatable
= ifc
->result
->attr
.allocatable
;
14441 c
->attr
.pointer
= ifc
->result
->attr
.pointer
;
14442 c
->attr
.dimension
= ifc
->result
->attr
.dimension
;
14443 c
->as
= gfc_copy_array_spec (ifc
->result
->as
);
14444 c
->attr
.class_ok
= ifc
->result
->attr
.class_ok
;
14449 c
->attr
.allocatable
= ifc
->attr
.allocatable
;
14450 c
->attr
.pointer
= ifc
->attr
.pointer
;
14451 c
->attr
.dimension
= ifc
->attr
.dimension
;
14452 c
->as
= gfc_copy_array_spec (ifc
->as
);
14453 c
->attr
.class_ok
= ifc
->attr
.class_ok
;
14455 c
->ts
.interface
= ifc
;
14456 c
->attr
.function
= ifc
->attr
.function
;
14457 c
->attr
.subroutine
= ifc
->attr
.subroutine
;
14459 c
->attr
.pure
= ifc
->attr
.pure
;
14460 c
->attr
.elemental
= ifc
->attr
.elemental
;
14461 c
->attr
.recursive
= ifc
->attr
.recursive
;
14462 c
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
14463 c
->attr
.ext_attr
|= ifc
->attr
.ext_attr
;
14464 /* Copy char length. */
14465 if (ifc
->ts
.type
== BT_CHARACTER
&& ifc
->ts
.u
.cl
)
14467 gfc_charlen
*cl
= gfc_new_charlen (sym
->ns
, ifc
->ts
.u
.cl
);
14468 if (cl
->length
&& !cl
->resolved
14469 && !gfc_resolve_expr (cl
->length
))
14478 else if (c
->attr
.proc_pointer
&& c
->ts
.type
== BT_UNKNOWN
)
14480 /* Since PPCs are not implicitly typed, a PPC without an explicit
14481 interface must be a subroutine. */
14482 gfc_add_subroutine (&c
->attr
, c
->name
, &c
->loc
);
14485 /* Procedure pointer components: Check PASS arg. */
14486 if (c
->attr
.proc_pointer
&& !c
->tb
->nopass
&& c
->tb
->pass_arg_num
== 0
14487 && !sym
->attr
.vtype
)
14489 gfc_symbol
* me_arg
;
14491 if (c
->tb
->pass_arg
)
14493 gfc_formal_arglist
* i
;
14495 /* If an explicit passing argument name is given, walk the arg-list
14496 and look for it. */
14499 c
->tb
->pass_arg_num
= 1;
14500 for (i
= c
->ts
.interface
->formal
; i
; i
= i
->next
)
14502 if (!strcmp (i
->sym
->name
, c
->tb
->pass_arg
))
14507 c
->tb
->pass_arg_num
++;
14512 gfc_error ("Procedure pointer component %qs with PASS(%s) "
14513 "at %L has no argument %qs", c
->name
,
14514 c
->tb
->pass_arg
, &c
->loc
, c
->tb
->pass_arg
);
14521 /* Otherwise, take the first one; there should in fact be at least
14523 c
->tb
->pass_arg_num
= 1;
14524 if (!c
->ts
.interface
->formal
)
14526 gfc_error ("Procedure pointer component %qs with PASS at %L "
14527 "must have at least one argument",
14532 me_arg
= c
->ts
.interface
->formal
->sym
;
14535 /* Now check that the argument-type matches. */
14536 gcc_assert (me_arg
);
14537 if ((me_arg
->ts
.type
!= BT_DERIVED
&& me_arg
->ts
.type
!= BT_CLASS
)
14538 || (me_arg
->ts
.type
== BT_DERIVED
&& me_arg
->ts
.u
.derived
!= sym
)
14539 || (me_arg
->ts
.type
== BT_CLASS
14540 && CLASS_DATA (me_arg
)->ts
.u
.derived
!= sym
))
14542 gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of"
14543 " the derived type %qs", me_arg
->name
, c
->name
,
14544 me_arg
->name
, &c
->loc
, sym
->name
);
14549 /* Check for F03:C453. */
14550 if (CLASS_DATA (me_arg
)->attr
.dimension
)
14552 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
14553 "must be scalar", me_arg
->name
, c
->name
, me_arg
->name
,
14559 if (CLASS_DATA (me_arg
)->attr
.class_pointer
)
14561 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
14562 "may not have the POINTER attribute", me_arg
->name
,
14563 c
->name
, me_arg
->name
, &c
->loc
);
14568 if (CLASS_DATA (me_arg
)->attr
.allocatable
)
14570 gfc_error ("Argument %qs of %qs with PASS(%s) at %L "
14571 "may not be ALLOCATABLE", me_arg
->name
, c
->name
,
14572 me_arg
->name
, &c
->loc
);
14577 if (gfc_type_is_extensible (sym
) && me_arg
->ts
.type
!= BT_CLASS
)
14579 gfc_error ("Non-polymorphic passed-object dummy argument of %qs"
14580 " at %L", c
->name
, &c
->loc
);
14586 /* Check type-spec if this is not the parent-type component. */
14587 if (((sym
->attr
.is_class
14588 && (!sym
->components
->ts
.u
.derived
->attr
.extension
14589 || c
!= sym
->components
->ts
.u
.derived
->components
))
14590 || (!sym
->attr
.is_class
14591 && (!sym
->attr
.extension
|| c
!= sym
->components
)))
14592 && !sym
->attr
.vtype
14593 && !resolve_typespec_used (&c
->ts
, &c
->loc
, c
->name
))
14596 super_type
= gfc_get_derived_super_type (sym
);
14598 /* If this type is an extension, set the accessibility of the parent
14601 && ((sym
->attr
.is_class
14602 && c
== sym
->components
->ts
.u
.derived
->components
)
14603 || (!sym
->attr
.is_class
&& c
== sym
->components
))
14604 && strcmp (super_type
->name
, c
->name
) == 0)
14605 c
->attr
.access
= super_type
->attr
.access
;
14607 /* If this type is an extension, see if this component has the same name
14608 as an inherited type-bound procedure. */
14609 if (super_type
&& !sym
->attr
.is_class
14610 && gfc_find_typebound_proc (super_type
, NULL
, c
->name
, true, NULL
))
14612 gfc_error ("Component %qs of %qs at %L has the same name as an"
14613 " inherited type-bound procedure",
14614 c
->name
, sym
->name
, &c
->loc
);
14618 if (c
->ts
.type
== BT_CHARACTER
&& !c
->attr
.proc_pointer
14619 && !c
->ts
.deferred
)
14621 if (c
->ts
.u
.cl
->length
== NULL
14622 || (!resolve_charlen(c
->ts
.u
.cl
))
14623 || !gfc_is_constant_expr (c
->ts
.u
.cl
->length
))
14625 gfc_error ("Character length of component %qs needs to "
14626 "be a constant specification expression at %L",
14628 c
->ts
.u
.cl
->length
? &c
->ts
.u
.cl
->length
->where
: &c
->loc
);
14633 if (c
->ts
.type
== BT_CHARACTER
&& c
->ts
.deferred
14634 && !c
->attr
.pointer
&& !c
->attr
.allocatable
)
14636 gfc_error ("Character component %qs of %qs at %L with deferred "
14637 "length must be a POINTER or ALLOCATABLE",
14638 c
->name
, sym
->name
, &c
->loc
);
14642 /* Add the hidden deferred length field. */
14643 if (c
->ts
.type
== BT_CHARACTER
14644 && (c
->ts
.deferred
|| c
->attr
.pdt_string
)
14645 && !c
->attr
.function
14646 && !sym
->attr
.is_class
)
14648 char name
[GFC_MAX_SYMBOL_LEN
+9];
14649 gfc_component
*strlen
;
14650 sprintf (name
, "_%s_length", c
->name
);
14651 strlen
= gfc_find_component (sym
, name
, true, true, NULL
);
14652 if (strlen
== NULL
)
14654 if (!gfc_add_component (sym
, name
, &strlen
))
14656 strlen
->ts
.type
= BT_INTEGER
;
14657 strlen
->ts
.kind
= gfc_charlen_int_kind
;
14658 strlen
->attr
.access
= ACCESS_PRIVATE
;
14659 strlen
->attr
.artificial
= 1;
14663 if (c
->ts
.type
== BT_DERIVED
14664 && sym
->component_access
!= ACCESS_PRIVATE
14665 && gfc_check_symbol_access (sym
)
14666 && !is_sym_host_assoc (c
->ts
.u
.derived
, sym
->ns
)
14667 && !c
->ts
.u
.derived
->attr
.use_assoc
14668 && !gfc_check_symbol_access (c
->ts
.u
.derived
)
14669 && !gfc_notify_std (GFC_STD_F2003
, "the component %qs is a "
14670 "PRIVATE type and cannot be a component of "
14671 "%qs, which is PUBLIC at %L", c
->name
,
14672 sym
->name
, &sym
->declared_at
))
14675 if ((sym
->attr
.sequence
|| sym
->attr
.is_bind_c
) && c
->ts
.type
== BT_CLASS
)
14677 gfc_error ("Polymorphic component %s at %L in SEQUENCE or BIND(C) "
14678 "type %s", c
->name
, &c
->loc
, sym
->name
);
14682 if (sym
->attr
.sequence
)
14684 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.sequence
== 0)
14686 gfc_error ("Component %s of SEQUENCE type declared at %L does "
14687 "not have the SEQUENCE attribute",
14688 c
->ts
.u
.derived
->name
, &sym
->declared_at
);
14693 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.generic
)
14694 c
->ts
.u
.derived
= gfc_find_dt_in_generic (c
->ts
.u
.derived
);
14695 else if (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
14696 && CLASS_DATA (c
)->ts
.u
.derived
->attr
.generic
)
14697 CLASS_DATA (c
)->ts
.u
.derived
14698 = gfc_find_dt_in_generic (CLASS_DATA (c
)->ts
.u
.derived
);
14700 /* If an allocatable component derived type is of the same type as
14701 the enclosing derived type, we need a vtable generating so that
14702 the __deallocate procedure is created. */
14703 if ((c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
14704 && c
->ts
.u
.derived
== sym
&& c
->attr
.allocatable
== 1)
14705 gfc_find_vtab (&c
->ts
);
14707 /* Ensure that all the derived type components are put on the
14708 derived type list; even in formal namespaces, where derived type
14709 pointer components might not have been declared. */
14710 if (c
->ts
.type
== BT_DERIVED
14712 && c
->ts
.u
.derived
->components
14714 && sym
!= c
->ts
.u
.derived
)
14715 add_dt_to_dt_list (c
->ts
.u
.derived
);
14717 if (!gfc_resolve_array_spec (c
->as
,
14718 !(c
->attr
.pointer
|| c
->attr
.proc_pointer
14719 || c
->attr
.allocatable
)))
14722 if (c
->initializer
&& !sym
->attr
.vtype
14723 && !c
->attr
.pdt_kind
&& !c
->attr
.pdt_len
14724 && !gfc_check_assign_symbol (sym
, c
, c
->initializer
))
14731 /* Be nice about the locus for a structure expression - show the locus of the
14732 first non-null sub-expression if we can. */
14735 cons_where (gfc_expr
*struct_expr
)
14737 gfc_constructor
*cons
;
14739 gcc_assert (struct_expr
&& struct_expr
->expr_type
== EXPR_STRUCTURE
);
14741 cons
= gfc_constructor_first (struct_expr
->value
.constructor
);
14742 for (; cons
; cons
= gfc_constructor_next (cons
))
14744 if (cons
->expr
&& cons
->expr
->expr_type
!= EXPR_NULL
)
14745 return &cons
->expr
->where
;
14748 return &struct_expr
->where
;
14751 /* Resolve the components of a structure type. Much less work than derived
14755 resolve_fl_struct (gfc_symbol
*sym
)
14758 gfc_expr
*init
= NULL
;
14761 /* Make sure UNIONs do not have overlapping initializers. */
14762 if (sym
->attr
.flavor
== FL_UNION
)
14764 for (c
= sym
->components
; c
; c
= c
->next
)
14766 if (init
&& c
->initializer
)
14768 gfc_error ("Conflicting initializers in union at %L and %L",
14769 cons_where (init
), cons_where (c
->initializer
));
14770 gfc_free_expr (c
->initializer
);
14771 c
->initializer
= NULL
;
14774 init
= c
->initializer
;
14779 for (c
= sym
->components
; c
; c
= c
->next
)
14780 if (!resolve_component (c
, sym
))
14786 if (sym
->components
)
14787 add_dt_to_dt_list (sym
);
14793 /* Resolve the components of a derived type. This does not have to wait until
14794 resolution stage, but can be done as soon as the dt declaration has been
14798 resolve_fl_derived0 (gfc_symbol
*sym
)
14800 gfc_symbol
* super_type
;
14802 gfc_formal_arglist
*f
;
14805 if (sym
->attr
.unlimited_polymorphic
)
14808 super_type
= gfc_get_derived_super_type (sym
);
14811 if (super_type
&& sym
->attr
.coarray_comp
&& !super_type
->attr
.coarray_comp
)
14813 gfc_error ("As extending type %qs at %L has a coarray component, "
14814 "parent type %qs shall also have one", sym
->name
,
14815 &sym
->declared_at
, super_type
->name
);
14819 /* Ensure the extended type gets resolved before we do. */
14820 if (super_type
&& !resolve_fl_derived0 (super_type
))
14823 /* An ABSTRACT type must be extensible. */
14824 if (sym
->attr
.abstract
&& !gfc_type_is_extensible (sym
))
14826 gfc_error ("Non-extensible derived-type %qs at %L must not be ABSTRACT",
14827 sym
->name
, &sym
->declared_at
);
14831 c
= (sym
->attr
.is_class
) ? sym
->components
->ts
.u
.derived
->components
14835 for ( ; c
!= NULL
; c
= c
->next
)
14836 if (!resolve_component (c
, sym
))
14842 /* Now add the caf token field, where needed. */
14843 if (flag_coarray
!= GFC_FCOARRAY_NONE
14844 && !sym
->attr
.is_class
&& !sym
->attr
.vtype
)
14846 for (c
= sym
->components
; c
; c
= c
->next
)
14847 if (!c
->attr
.dimension
&& !c
->attr
.codimension
14848 && (c
->attr
.allocatable
|| c
->attr
.pointer
))
14850 char name
[GFC_MAX_SYMBOL_LEN
+9];
14851 gfc_component
*token
;
14852 sprintf (name
, "_caf_%s", c
->name
);
14853 token
= gfc_find_component (sym
, name
, true, true, NULL
);
14856 if (!gfc_add_component (sym
, name
, &token
))
14858 token
->ts
.type
= BT_VOID
;
14859 token
->ts
.kind
= gfc_default_integer_kind
;
14860 token
->attr
.access
= ACCESS_PRIVATE
;
14861 token
->attr
.artificial
= 1;
14862 token
->attr
.caf_token
= 1;
14867 check_defined_assignments (sym
);
14869 if (!sym
->attr
.defined_assign_comp
&& super_type
)
14870 sym
->attr
.defined_assign_comp
14871 = super_type
->attr
.defined_assign_comp
;
14873 /* If this is a non-ABSTRACT type extending an ABSTRACT one, ensure that
14874 all DEFERRED bindings are overridden. */
14875 if (super_type
&& super_type
->attr
.abstract
&& !sym
->attr
.abstract
14876 && !sym
->attr
.is_class
14877 && !ensure_not_abstract (sym
, super_type
))
14880 /* Check that there is a component for every PDT parameter. */
14881 if (sym
->attr
.pdt_template
)
14883 for (f
= sym
->formal
; f
; f
= f
->next
)
14887 c
= gfc_find_component (sym
, f
->sym
->name
, true, true, NULL
);
14890 gfc_error ("Parameterized type %qs does not have a component "
14891 "corresponding to parameter %qs at %L", sym
->name
,
14892 f
->sym
->name
, &sym
->declared_at
);
14898 /* Add derived type to the derived type list. */
14899 add_dt_to_dt_list (sym
);
14905 /* The following procedure does the full resolution of a derived type,
14906 including resolution of all type-bound procedures (if present). In contrast
14907 to 'resolve_fl_derived0' this can only be done after the module has been
14908 parsed completely. */
14911 resolve_fl_derived (gfc_symbol
*sym
)
14913 gfc_symbol
*gen_dt
= NULL
;
14915 if (sym
->attr
.unlimited_polymorphic
)
14918 if (!sym
->attr
.is_class
)
14919 gfc_find_symbol (sym
->name
, sym
->ns
, 0, &gen_dt
);
14920 if (gen_dt
&& gen_dt
->generic
&& gen_dt
->generic
->next
14921 && (!gen_dt
->generic
->sym
->attr
.use_assoc
14922 || gen_dt
->generic
->sym
->module
!= gen_dt
->generic
->next
->sym
->module
)
14923 && !gfc_notify_std (GFC_STD_F2003
, "Generic name %qs of function "
14924 "%qs at %L being the same name as derived "
14925 "type at %L", sym
->name
,
14926 gen_dt
->generic
->sym
== sym
14927 ? gen_dt
->generic
->next
->sym
->name
14928 : gen_dt
->generic
->sym
->name
,
14929 gen_dt
->generic
->sym
== sym
14930 ? &gen_dt
->generic
->next
->sym
->declared_at
14931 : &gen_dt
->generic
->sym
->declared_at
,
14932 &sym
->declared_at
))
14935 if (sym
->components
== NULL
&& !sym
->attr
.zero_comp
&& !sym
->attr
.use_assoc
)
14937 gfc_error ("Derived type %qs at %L has not been declared",
14938 sym
->name
, &sym
->declared_at
);
14942 /* Resolve the finalizer procedures. */
14943 if (!gfc_resolve_finalizers (sym
, NULL
))
14946 if (sym
->attr
.is_class
&& sym
->ts
.u
.derived
== NULL
)
14948 /* Fix up incomplete CLASS symbols. */
14949 gfc_component
*data
= gfc_find_component (sym
, "_data", true, true, NULL
);
14950 gfc_component
*vptr
= gfc_find_component (sym
, "_vptr", true, true, NULL
);
14952 /* Nothing more to do for unlimited polymorphic entities. */
14953 if (data
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
14955 else if (vptr
->ts
.u
.derived
== NULL
)
14957 gfc_symbol
*vtab
= gfc_find_derived_vtab (data
->ts
.u
.derived
);
14959 vptr
->ts
.u
.derived
= vtab
->ts
.u
.derived
;
14960 if (!resolve_fl_derived0 (vptr
->ts
.u
.derived
))
14965 if (!resolve_fl_derived0 (sym
))
14968 /* Resolve the type-bound procedures. */
14969 if (!resolve_typebound_procedures (sym
))
14972 /* Generate module vtables subject to their accessibility and their not
14973 being vtables or pdt templates. If this is not done class declarations
14974 in external procedures wind up with their own version and so SELECT TYPE
14975 fails because the vptrs do not have the same address. */
14976 if (gfc_option
.allow_std
& GFC_STD_F2003
14977 && sym
->ns
->proc_name
14978 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
14979 && sym
->attr
.access
!= ACCESS_PRIVATE
14980 && !(sym
->attr
.use_assoc
|| sym
->attr
.vtype
|| sym
->attr
.pdt_template
))
14982 gfc_symbol
*vtab
= gfc_find_derived_vtab (sym
);
14983 gfc_set_sym_referenced (vtab
);
14991 resolve_fl_namelist (gfc_symbol
*sym
)
14996 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
14998 /* Check again, the check in match only works if NAMELIST comes
15000 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SIZE
)
15002 gfc_error ("Assumed size array %qs in namelist %qs at %L is not "
15003 "allowed", nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
15007 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SHAPE
15008 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object %qs "
15009 "with assumed shape in namelist %qs at %L",
15010 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
15013 if (is_non_constant_shape_array (nl
->sym
)
15014 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object %qs "
15015 "with nonconstant shape in namelist %qs at %L",
15016 nl
->sym
->name
, sym
->name
, &sym
->declared_at
))
15019 if (nl
->sym
->ts
.type
== BT_CHARACTER
15020 && (nl
->sym
->ts
.u
.cl
->length
== NULL
15021 || !gfc_is_constant_expr (nl
->sym
->ts
.u
.cl
->length
))
15022 && !gfc_notify_std (GFC_STD_F2003
, "NAMELIST object %qs with "
15023 "nonconstant character length in "
15024 "namelist %qs at %L", nl
->sym
->name
,
15025 sym
->name
, &sym
->declared_at
))
15030 /* Reject PRIVATE objects in a PUBLIC namelist. */
15031 if (gfc_check_symbol_access (sym
))
15033 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
15035 if (!nl
->sym
->attr
.use_assoc
15036 && !is_sym_host_assoc (nl
->sym
, sym
->ns
)
15037 && !gfc_check_symbol_access (nl
->sym
))
15039 gfc_error ("NAMELIST object %qs was declared PRIVATE and "
15040 "cannot be member of PUBLIC namelist %qs at %L",
15041 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
15045 if (nl
->sym
->ts
.type
== BT_DERIVED
15046 && (nl
->sym
->ts
.u
.derived
->attr
.alloc_comp
15047 || nl
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
15049 if (!gfc_notify_std (GFC_STD_F2003
, "NAMELIST object %qs in "
15050 "namelist %qs at %L with ALLOCATABLE "
15051 "or POINTER components", nl
->sym
->name
,
15052 sym
->name
, &sym
->declared_at
))
15057 /* Types with private components that came here by USE-association. */
15058 if (nl
->sym
->ts
.type
== BT_DERIVED
15059 && derived_inaccessible (nl
->sym
->ts
.u
.derived
))
15061 gfc_error ("NAMELIST object %qs has use-associated PRIVATE "
15062 "components and cannot be member of namelist %qs at %L",
15063 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
15067 /* Types with private components that are defined in the same module. */
15068 if (nl
->sym
->ts
.type
== BT_DERIVED
15069 && !is_sym_host_assoc (nl
->sym
->ts
.u
.derived
, sym
->ns
)
15070 && nl
->sym
->ts
.u
.derived
->attr
.private_comp
)
15072 gfc_error ("NAMELIST object %qs has PRIVATE components and "
15073 "cannot be a member of PUBLIC namelist %qs at %L",
15074 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
15081 /* 14.1.2 A module or internal procedure represent local entities
15082 of the same type as a namelist member and so are not allowed. */
15083 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
15085 if (nl
->sym
->ts
.kind
!= 0 && nl
->sym
->attr
.flavor
== FL_VARIABLE
)
15088 if (nl
->sym
->attr
.function
&& nl
->sym
== nl
->sym
->result
)
15089 if ((nl
->sym
== sym
->ns
->proc_name
)
15091 (sym
->ns
->parent
&& nl
->sym
== sym
->ns
->parent
->proc_name
))
15096 gfc_find_symbol (nl
->sym
->name
, sym
->ns
, 1, &nlsym
);
15097 if (nlsym
&& nlsym
->attr
.flavor
== FL_PROCEDURE
)
15099 gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
15100 "attribute in %qs at %L", nlsym
->name
,
15101 &sym
->declared_at
);
15111 resolve_fl_parameter (gfc_symbol
*sym
)
15113 /* A parameter array's shape needs to be constant. */
15114 if (sym
->as
!= NULL
15115 && (sym
->as
->type
== AS_DEFERRED
15116 || is_non_constant_shape_array (sym
)))
15118 gfc_error ("Parameter array %qs at %L cannot be automatic "
15119 "or of deferred shape", sym
->name
, &sym
->declared_at
);
15123 /* Constraints on deferred type parameter. */
15124 if (!deferred_requirements (sym
))
15127 /* Make sure a parameter that has been implicitly typed still
15128 matches the implicit type, since PARAMETER statements can precede
15129 IMPLICIT statements. */
15130 if (sym
->attr
.implicit_type
15131 && !gfc_compare_types (&sym
->ts
, gfc_get_default_type (sym
->name
,
15134 gfc_error ("Implicitly typed PARAMETER %qs at %L doesn't match a "
15135 "later IMPLICIT type", sym
->name
, &sym
->declared_at
);
15139 /* Make sure the types of derived parameters are consistent. This
15140 type checking is deferred until resolution because the type may
15141 refer to a derived type from the host. */
15142 if (sym
->ts
.type
== BT_DERIVED
15143 && !gfc_compare_types (&sym
->ts
, &sym
->value
->ts
))
15145 gfc_error ("Incompatible derived type in PARAMETER at %L",
15146 &sym
->value
->where
);
15150 /* F03:C509,C514. */
15151 if (sym
->ts
.type
== BT_CLASS
)
15153 gfc_error ("CLASS variable %qs at %L cannot have the PARAMETER attribute",
15154 sym
->name
, &sym
->declared_at
);
15162 /* Called by resolve_symbol to check PDTs. */
15165 resolve_pdt (gfc_symbol
* sym
)
15167 gfc_symbol
*derived
= NULL
;
15168 gfc_actual_arglist
*param
;
15170 bool const_len_exprs
= true;
15171 bool assumed_len_exprs
= false;
15172 symbol_attribute
*attr
;
15174 if (sym
->ts
.type
== BT_DERIVED
)
15176 derived
= sym
->ts
.u
.derived
;
15177 attr
= &(sym
->attr
);
15179 else if (sym
->ts
.type
== BT_CLASS
)
15181 derived
= CLASS_DATA (sym
)->ts
.u
.derived
;
15182 attr
= &(CLASS_DATA (sym
)->attr
);
15185 gcc_unreachable ();
15187 gcc_assert (derived
->attr
.pdt_type
);
15189 for (param
= sym
->param_list
; param
; param
= param
->next
)
15191 c
= gfc_find_component (derived
, param
->name
, false, true, NULL
);
15193 if (c
->attr
.pdt_kind
)
15196 if (param
->expr
&& !gfc_is_constant_expr (param
->expr
)
15197 && c
->attr
.pdt_len
)
15198 const_len_exprs
= false;
15199 else if (param
->spec_type
== SPEC_ASSUMED
)
15200 assumed_len_exprs
= true;
15202 if (param
->spec_type
== SPEC_DEFERRED
15203 && !attr
->allocatable
&& !attr
->pointer
)
15204 gfc_error ("The object %qs at %L has a deferred LEN "
15205 "parameter %qs and is neither allocatable "
15206 "nor a pointer", sym
->name
, &sym
->declared_at
,
15211 if (!const_len_exprs
15212 && (sym
->ns
->proc_name
->attr
.is_main_program
15213 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
15214 || sym
->attr
.save
!= SAVE_NONE
))
15215 gfc_error ("The AUTOMATIC object %qs at %L must not have the "
15216 "SAVE attribute or be a variable declared in the "
15217 "main program, a module or a submodule(F08/C513)",
15218 sym
->name
, &sym
->declared_at
);
15220 if (assumed_len_exprs
&& !(sym
->attr
.dummy
15221 || sym
->attr
.select_type_temporary
|| sym
->attr
.associate_var
))
15222 gfc_error ("The object %qs at %L with ASSUMED type parameters "
15223 "must be a dummy or a SELECT TYPE selector(F08/4.2)",
15224 sym
->name
, &sym
->declared_at
);
15228 /* Do anything necessary to resolve a symbol. Right now, we just
15229 assume that an otherwise unknown symbol is a variable. This sort
15230 of thing commonly happens for symbols in module. */
15233 resolve_symbol (gfc_symbol
*sym
)
15235 int check_constant
, mp_flag
;
15236 gfc_symtree
*symtree
;
15237 gfc_symtree
*this_symtree
;
15240 symbol_attribute class_attr
;
15241 gfc_array_spec
*as
;
15242 bool saved_specification_expr
;
15244 if (sym
->resolve_symbol_called
>= 1)
15246 sym
->resolve_symbol_called
= 1;
15248 /* No symbol will ever have union type; only components can be unions.
15249 Union type declaration symbols have type BT_UNKNOWN but flavor FL_UNION
15250 (just like derived type declaration symbols have flavor FL_DERIVED). */
15251 gcc_assert (sym
->ts
.type
!= BT_UNION
);
15253 /* Coarrayed polymorphic objects with allocatable or pointer components are
15254 yet unsupported for -fcoarray=lib. */
15255 if (flag_coarray
== GFC_FCOARRAY_LIB
&& sym
->ts
.type
== BT_CLASS
15256 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
15257 && CLASS_DATA (sym
)->attr
.codimension
15258 && CLASS_DATA (sym
)->ts
.u
.derived
15259 && (CLASS_DATA (sym
)->ts
.u
.derived
->attr
.alloc_comp
15260 || CLASS_DATA (sym
)->ts
.u
.derived
->attr
.pointer_comp
))
15262 gfc_error ("Sorry, allocatable/pointer components in polymorphic (CLASS) "
15263 "type coarrays at %L are unsupported", &sym
->declared_at
);
15267 if (sym
->attr
.artificial
)
15270 if (sym
->attr
.unlimited_polymorphic
)
15273 if (sym
->attr
.flavor
== FL_UNKNOWN
15274 || (sym
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.intrinsic
15275 && !sym
->attr
.generic
&& !sym
->attr
.external
15276 && sym
->attr
.if_source
== IFSRC_UNKNOWN
15277 && sym
->ts
.type
== BT_UNKNOWN
))
15280 /* If we find that a flavorless symbol is an interface in one of the
15281 parent namespaces, find its symtree in this namespace, free the
15282 symbol and set the symtree to point to the interface symbol. */
15283 for (ns
= gfc_current_ns
->parent
; ns
; ns
= ns
->parent
)
15285 symtree
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
15286 if (symtree
&& (symtree
->n
.sym
->generic
||
15287 (symtree
->n
.sym
->attr
.flavor
== FL_PROCEDURE
15288 && sym
->ns
->construct_entities
)))
15290 this_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
15292 if (this_symtree
->n
.sym
== sym
)
15294 symtree
->n
.sym
->refs
++;
15295 gfc_release_symbol (sym
);
15296 this_symtree
->n
.sym
= symtree
->n
.sym
;
15302 /* Otherwise give it a flavor according to such attributes as
15304 if (sym
->attr
.flavor
== FL_UNKNOWN
&& sym
->attr
.external
== 0
15305 && sym
->attr
.intrinsic
== 0)
15306 sym
->attr
.flavor
= FL_VARIABLE
;
15307 else if (sym
->attr
.flavor
== FL_UNKNOWN
)
15309 sym
->attr
.flavor
= FL_PROCEDURE
;
15310 if (sym
->attr
.dimension
)
15311 sym
->attr
.function
= 1;
15315 if (sym
->attr
.external
&& sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.function
)
15316 gfc_add_function (&sym
->attr
, sym
->name
, &sym
->declared_at
);
15318 if (sym
->attr
.procedure
&& sym
->attr
.if_source
!= IFSRC_DECL
15319 && !resolve_procedure_interface (sym
))
15322 if (sym
->attr
.is_protected
&& !sym
->attr
.proc_pointer
15323 && (sym
->attr
.procedure
|| sym
->attr
.external
))
15325 if (sym
->attr
.external
)
15326 gfc_error ("PROTECTED attribute conflicts with EXTERNAL attribute "
15327 "at %L", &sym
->declared_at
);
15329 gfc_error ("PROCEDURE attribute conflicts with PROTECTED attribute "
15330 "at %L", &sym
->declared_at
);
15335 if (sym
->attr
.flavor
== FL_DERIVED
&& !resolve_fl_derived (sym
))
15338 else if ((sym
->attr
.flavor
== FL_STRUCT
|| sym
->attr
.flavor
== FL_UNION
)
15339 && !resolve_fl_struct (sym
))
15342 /* Symbols that are module procedures with results (functions) have
15343 the types and array specification copied for type checking in
15344 procedures that call them, as well as for saving to a module
15345 file. These symbols can't stand the scrutiny that their results
15347 mp_flag
= (sym
->result
!= NULL
&& sym
->result
!= sym
);
15349 /* Make sure that the intrinsic is consistent with its internal
15350 representation. This needs to be done before assigning a default
15351 type to avoid spurious warnings. */
15352 if (sym
->attr
.flavor
!= FL_MODULE
&& sym
->attr
.intrinsic
15353 && !gfc_resolve_intrinsic (sym
, &sym
->declared_at
))
15356 /* Resolve associate names. */
15358 resolve_assoc_var (sym
, true);
15360 /* Assign default type to symbols that need one and don't have one. */
15361 if (sym
->ts
.type
== BT_UNKNOWN
)
15363 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
)
15365 gfc_set_default_type (sym
, 1, NULL
);
15368 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.external
15369 && !sym
->attr
.function
&& !sym
->attr
.subroutine
15370 && gfc_get_default_type (sym
->name
, sym
->ns
)->type
== BT_UNKNOWN
)
15371 gfc_add_subroutine (&sym
->attr
, sym
->name
, &sym
->declared_at
);
15373 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
15375 /* The specific case of an external procedure should emit an error
15376 in the case that there is no implicit type. */
15379 if (!sym
->attr
.mixed_entry_master
)
15380 gfc_set_default_type (sym
, sym
->attr
.external
, NULL
);
15384 /* Result may be in another namespace. */
15385 resolve_symbol (sym
->result
);
15387 if (!sym
->result
->attr
.proc_pointer
)
15389 sym
->ts
= sym
->result
->ts
;
15390 sym
->as
= gfc_copy_array_spec (sym
->result
->as
);
15391 sym
->attr
.dimension
= sym
->result
->attr
.dimension
;
15392 sym
->attr
.pointer
= sym
->result
->attr
.pointer
;
15393 sym
->attr
.allocatable
= sym
->result
->attr
.allocatable
;
15394 sym
->attr
.contiguous
= sym
->result
->attr
.contiguous
;
15399 else if (mp_flag
&& sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
15401 bool saved_specification_expr
= specification_expr
;
15402 bool saved_formal_arg_flag
= formal_arg_flag
;
15404 specification_expr
= true;
15405 formal_arg_flag
= true;
15406 gfc_resolve_array_spec (sym
->result
->as
, false);
15407 formal_arg_flag
= saved_formal_arg_flag
;
15408 specification_expr
= saved_specification_expr
;
15411 if (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
&& sym
->ts
.u
.derived
)
15413 as
= CLASS_DATA (sym
)->as
;
15414 class_attr
= CLASS_DATA (sym
)->attr
;
15415 class_attr
.pointer
= class_attr
.class_pointer
;
15419 class_attr
= sym
->attr
;
15424 if (sym
->attr
.contiguous
15425 && (!class_attr
.dimension
15426 || (as
->type
!= AS_ASSUMED_SHAPE
&& as
->type
!= AS_ASSUMED_RANK
15427 && !class_attr
.pointer
)))
15429 gfc_error ("%qs at %L has the CONTIGUOUS attribute but is not an "
15430 "array pointer or an assumed-shape or assumed-rank array",
15431 sym
->name
, &sym
->declared_at
);
15435 /* Assumed size arrays and assumed shape arrays must be dummy
15436 arguments. Array-spec's of implied-shape should have been resolved to
15437 AS_EXPLICIT already. */
15441 /* If AS_IMPLIED_SHAPE makes it to here, it must be a bad
15442 specification expression. */
15443 if (as
->type
== AS_IMPLIED_SHAPE
)
15446 for (i
=0; i
<as
->rank
; i
++)
15448 if (as
->lower
[i
] != NULL
&& as
->upper
[i
] == NULL
)
15450 gfc_error ("Bad specification for assumed size array at %L",
15451 &as
->lower
[i
]->where
);
15458 if (((as
->type
== AS_ASSUMED_SIZE
&& !as
->cp_was_assumed
)
15459 || as
->type
== AS_ASSUMED_SHAPE
)
15460 && !sym
->attr
.dummy
&& !sym
->attr
.select_type_temporary
)
15462 if (as
->type
== AS_ASSUMED_SIZE
)
15463 gfc_error ("Assumed size array at %L must be a dummy argument",
15464 &sym
->declared_at
);
15466 gfc_error ("Assumed shape array at %L must be a dummy argument",
15467 &sym
->declared_at
);
15470 /* TS 29113, C535a. */
15471 if (as
->type
== AS_ASSUMED_RANK
&& !sym
->attr
.dummy
15472 && !sym
->attr
.select_type_temporary
15473 && !(cs_base
&& cs_base
->current
15474 && cs_base
->current
->op
== EXEC_SELECT_RANK
))
15476 gfc_error ("Assumed-rank array at %L must be a dummy argument",
15477 &sym
->declared_at
);
15480 if (as
->type
== AS_ASSUMED_RANK
15481 && (sym
->attr
.codimension
|| sym
->attr
.value
))
15483 gfc_error ("Assumed-rank array at %L may not have the VALUE or "
15484 "CODIMENSION attribute", &sym
->declared_at
);
15489 /* Make sure symbols with known intent or optional are really dummy
15490 variable. Because of ENTRY statement, this has to be deferred
15491 until resolution time. */
15493 if (!sym
->attr
.dummy
15494 && (sym
->attr
.optional
|| sym
->attr
.intent
!= INTENT_UNKNOWN
))
15496 gfc_error ("Symbol at %L is not a DUMMY variable", &sym
->declared_at
);
15500 if (sym
->attr
.value
&& !sym
->attr
.dummy
)
15502 gfc_error ("%qs at %L cannot have the VALUE attribute because "
15503 "it is not a dummy argument", sym
->name
, &sym
->declared_at
);
15507 if (sym
->attr
.value
&& sym
->ts
.type
== BT_CHARACTER
)
15509 gfc_charlen
*cl
= sym
->ts
.u
.cl
;
15510 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
15512 gfc_error ("Character dummy variable %qs at %L with VALUE "
15513 "attribute must have constant length",
15514 sym
->name
, &sym
->declared_at
);
15518 if (sym
->ts
.is_c_interop
15519 && mpz_cmp_si (cl
->length
->value
.integer
, 1) != 0)
15521 gfc_error ("C interoperable character dummy variable %qs at %L "
15522 "with VALUE attribute must have length one",
15523 sym
->name
, &sym
->declared_at
);
15528 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
15529 && sym
->ts
.u
.derived
->attr
.generic
)
15531 sym
->ts
.u
.derived
= gfc_find_dt_in_generic (sym
->ts
.u
.derived
);
15532 if (!sym
->ts
.u
.derived
)
15534 gfc_error ("The derived type %qs at %L is of type %qs, "
15535 "which has not been defined", sym
->name
,
15536 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
15537 sym
->ts
.type
= BT_UNKNOWN
;
15542 /* Use the same constraints as TYPE(*), except for the type check
15543 and that only scalars and assumed-size arrays are permitted. */
15544 if (sym
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
15546 if (!sym
->attr
.dummy
)
15548 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
15549 "a dummy argument", sym
->name
, &sym
->declared_at
);
15553 if (sym
->ts
.type
!= BT_ASSUMED
&& sym
->ts
.type
!= BT_INTEGER
15554 && sym
->ts
.type
!= BT_REAL
&& sym
->ts
.type
!= BT_LOGICAL
15555 && sym
->ts
.type
!= BT_COMPLEX
)
15557 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall be "
15558 "of type TYPE(*) or of an numeric intrinsic type",
15559 sym
->name
, &sym
->declared_at
);
15563 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
15564 || sym
->attr
.pointer
|| sym
->attr
.value
)
15566 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
15567 "have the ALLOCATABLE, CODIMENSION, POINTER or VALUE "
15568 "attribute", sym
->name
, &sym
->declared_at
);
15572 if (sym
->attr
.intent
== INTENT_OUT
)
15574 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may not "
15575 "have the INTENT(OUT) attribute",
15576 sym
->name
, &sym
->declared_at
);
15579 if (sym
->attr
.dimension
&& sym
->as
->type
!= AS_ASSUMED_SIZE
)
15581 gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall "
15582 "either be a scalar or an assumed-size array",
15583 sym
->name
, &sym
->declared_at
);
15587 /* Set the type to TYPE(*) and add a dimension(*) to ensure
15588 NO_ARG_CHECK is correctly handled in trans*.c, e.g. with
15590 sym
->ts
.type
= BT_ASSUMED
;
15591 sym
->as
= gfc_get_array_spec ();
15592 sym
->as
->type
= AS_ASSUMED_SIZE
;
15594 sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
15596 else if (sym
->ts
.type
== BT_ASSUMED
)
15598 /* TS 29113, C407a. */
15599 if (!sym
->attr
.dummy
)
15601 gfc_error ("Assumed type of variable %s at %L is only permitted "
15602 "for dummy variables", sym
->name
, &sym
->declared_at
);
15605 if (sym
->attr
.allocatable
|| sym
->attr
.codimension
15606 || sym
->attr
.pointer
|| sym
->attr
.value
)
15608 gfc_error ("Assumed-type variable %s at %L may not have the "
15609 "ALLOCATABLE, CODIMENSION, POINTER or VALUE attribute",
15610 sym
->name
, &sym
->declared_at
);
15613 if (sym
->attr
.intent
== INTENT_OUT
)
15615 gfc_error ("Assumed-type variable %s at %L may not have the "
15616 "INTENT(OUT) attribute",
15617 sym
->name
, &sym
->declared_at
);
15620 if (sym
->attr
.dimension
&& sym
->as
->type
== AS_EXPLICIT
)
15622 gfc_error ("Assumed-type variable %s at %L shall not be an "
15623 "explicit-shape array", sym
->name
, &sym
->declared_at
);
15628 /* If the symbol is marked as bind(c), that it is declared at module level
15629 scope and verify its type and kind. Do not do the latter for symbols
15630 that are implicitly typed because that is handled in
15631 gfc_set_default_type. Handle dummy arguments and procedure definitions
15632 separately. Also, anything that is use associated is not handled here
15633 but instead is handled in the module it is declared in. Finally, derived
15634 type definitions are allowed to be BIND(C) since that only implies that
15635 they're interoperable, and they are checked fully for interoperability
15636 when a variable is declared of that type. */
15637 if (sym
->attr
.is_bind_c
&& sym
->attr
.use_assoc
== 0
15638 && sym
->attr
.dummy
== 0 && sym
->attr
.flavor
!= FL_PROCEDURE
15639 && sym
->attr
.flavor
!= FL_DERIVED
)
15643 /* First, make sure the variable is declared at the
15644 module-level scope (J3/04-007, Section 15.3). */
15645 if (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
&&
15646 sym
->attr
.in_common
== 0)
15648 gfc_error ("Variable %qs at %L cannot be BIND(C) because it "
15649 "is neither a COMMON block nor declared at the "
15650 "module level scope", sym
->name
, &(sym
->declared_at
));
15653 else if (sym
->ts
.type
== BT_CHARACTER
15654 && (sym
->ts
.u
.cl
== NULL
|| sym
->ts
.u
.cl
->length
== NULL
15655 || !gfc_is_constant_expr (sym
->ts
.u
.cl
->length
)
15656 || mpz_cmp_si (sym
->ts
.u
.cl
->length
->value
.integer
, 1) != 0))
15658 gfc_error ("BIND(C) Variable %qs at %L must have length one",
15659 sym
->name
, &sym
->declared_at
);
15662 else if (sym
->common_head
!= NULL
&& sym
->attr
.implicit_type
== 0)
15664 t
= verify_com_block_vars_c_interop (sym
->common_head
);
15666 else if (sym
->attr
.implicit_type
== 0)
15668 /* If type() declaration, we need to verify that the components
15669 of the given type are all C interoperable, etc. */
15670 if (sym
->ts
.type
== BT_DERIVED
&&
15671 sym
->ts
.u
.derived
->attr
.is_c_interop
!= 1)
15673 /* Make sure the user marked the derived type as BIND(C). If
15674 not, call the verify routine. This could print an error
15675 for the derived type more than once if multiple variables
15676 of that type are declared. */
15677 if (sym
->ts
.u
.derived
->attr
.is_bind_c
!= 1)
15678 verify_bind_c_derived_type (sym
->ts
.u
.derived
);
15682 /* Verify the variable itself as C interoperable if it
15683 is BIND(C). It is not possible for this to succeed if
15684 the verify_bind_c_derived_type failed, so don't have to handle
15685 any error returned by verify_bind_c_derived_type. */
15686 t
= verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
15687 sym
->common_block
);
15692 /* clear the is_bind_c flag to prevent reporting errors more than
15693 once if something failed. */
15694 sym
->attr
.is_bind_c
= 0;
15699 /* If a derived type symbol has reached this point, without its
15700 type being declared, we have an error. Notice that most
15701 conditions that produce undefined derived types have already
15702 been dealt with. However, the likes of:
15703 implicit type(t) (t) ..... call foo (t) will get us here if
15704 the type is not declared in the scope of the implicit
15705 statement. Change the type to BT_UNKNOWN, both because it is so
15706 and to prevent an ICE. */
15707 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->attr
.is_iso_c
15708 && sym
->ts
.u
.derived
->components
== NULL
15709 && !sym
->ts
.u
.derived
->attr
.zero_comp
)
15711 gfc_error ("The derived type %qs at %L is of type %qs, "
15712 "which has not been defined", sym
->name
,
15713 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
15714 sym
->ts
.type
= BT_UNKNOWN
;
15718 /* Make sure that the derived type has been resolved and that the
15719 derived type is visible in the symbol's namespace, if it is a
15720 module function and is not PRIVATE. */
15721 if (sym
->ts
.type
== BT_DERIVED
15722 && sym
->ts
.u
.derived
->attr
.use_assoc
15723 && sym
->ns
->proc_name
15724 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
15725 && !resolve_fl_derived (sym
->ts
.u
.derived
))
15728 /* Unless the derived-type declaration is use associated, Fortran 95
15729 does not allow public entries of private derived types.
15730 See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
15731 161 in 95-006r3. */
15732 if (sym
->ts
.type
== BT_DERIVED
15733 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
15734 && !sym
->ts
.u
.derived
->attr
.use_assoc
15735 && gfc_check_symbol_access (sym
)
15736 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
15737 && !gfc_notify_std (GFC_STD_F2003
, "PUBLIC %s %qs at %L of PRIVATE "
15738 "derived type %qs",
15739 (sym
->attr
.flavor
== FL_PARAMETER
)
15740 ? "parameter" : "variable",
15741 sym
->name
, &sym
->declared_at
,
15742 sym
->ts
.u
.derived
->name
))
15745 /* F2008, C1302. */
15746 if (sym
->ts
.type
== BT_DERIVED
15747 && ((sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
15748 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
15749 || sym
->ts
.u
.derived
->attr
.lock_comp
)
15750 && !sym
->attr
.codimension
&& !sym
->ts
.u
.derived
->attr
.coarray_comp
)
15752 gfc_error ("Variable %s at %L of type LOCK_TYPE or with subcomponent of "
15753 "type LOCK_TYPE must be a coarray", sym
->name
,
15754 &sym
->declared_at
);
15758 /* TS18508, C702/C703. */
15759 if (sym
->ts
.type
== BT_DERIVED
15760 && ((sym
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
15761 && sym
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
15762 || sym
->ts
.u
.derived
->attr
.event_comp
)
15763 && !sym
->attr
.codimension
&& !sym
->ts
.u
.derived
->attr
.coarray_comp
)
15765 gfc_error ("Variable %s at %L of type EVENT_TYPE or with subcomponent of "
15766 "type EVENT_TYPE must be a coarray", sym
->name
,
15767 &sym
->declared_at
);
15771 /* An assumed-size array with INTENT(OUT) shall not be of a type for which
15772 default initialization is defined (5.1.2.4.4). */
15773 if (sym
->ts
.type
== BT_DERIVED
15775 && sym
->attr
.intent
== INTENT_OUT
15777 && sym
->as
->type
== AS_ASSUMED_SIZE
)
15779 for (c
= sym
->ts
.u
.derived
->components
; c
; c
= c
->next
)
15781 if (c
->initializer
)
15783 gfc_error ("The INTENT(OUT) dummy argument %qs at %L is "
15784 "ASSUMED SIZE and so cannot have a default initializer",
15785 sym
->name
, &sym
->declared_at
);
15792 if (sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.dummy
15793 && sym
->attr
.intent
== INTENT_OUT
&& sym
->attr
.lock_comp
)
15795 gfc_error ("Dummy argument %qs at %L of LOCK_TYPE shall not be "
15796 "INTENT(OUT)", sym
->name
, &sym
->declared_at
);
15801 if (sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.dummy
15802 && sym
->attr
.intent
== INTENT_OUT
&& sym
->attr
.event_comp
)
15804 gfc_error ("Dummy argument %qs at %L of EVENT_TYPE shall not be "
15805 "INTENT(OUT)", sym
->name
, &sym
->declared_at
);
15810 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
15811 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
15812 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
15813 && CLASS_DATA (sym
)->attr
.coarray_comp
))
15814 || class_attr
.codimension
)
15815 && (sym
->attr
.result
|| sym
->result
== sym
))
15817 gfc_error ("Function result %qs at %L shall not be a coarray or have "
15818 "a coarray component", sym
->name
, &sym
->declared_at
);
15823 if (sym
->attr
.codimension
&& sym
->ts
.type
== BT_DERIVED
15824 && sym
->ts
.u
.derived
->ts
.is_iso_c
)
15826 gfc_error ("Variable %qs at %L of TYPE(C_PTR) or TYPE(C_FUNPTR) "
15827 "shall not be a coarray", sym
->name
, &sym
->declared_at
);
15832 if (((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
15833 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
15834 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
15835 && CLASS_DATA (sym
)->attr
.coarray_comp
))
15836 && (class_attr
.codimension
|| class_attr
.pointer
|| class_attr
.dimension
15837 || class_attr
.allocatable
))
15839 gfc_error ("Variable %qs at %L with coarray component shall be a "
15840 "nonpointer, nonallocatable scalar, which is not a coarray",
15841 sym
->name
, &sym
->declared_at
);
15845 /* F2008, C526. The function-result case was handled above. */
15846 if (class_attr
.codimension
15847 && !(class_attr
.allocatable
|| sym
->attr
.dummy
|| sym
->attr
.save
15848 || sym
->attr
.select_type_temporary
15849 || sym
->attr
.associate_var
15850 || (sym
->ns
->save_all
&& !sym
->attr
.automatic
)
15851 || sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
15852 || sym
->ns
->proc_name
->attr
.is_main_program
15853 || sym
->attr
.function
|| sym
->attr
.result
|| sym
->attr
.use_assoc
))
15855 gfc_error ("Variable %qs at %L is a coarray and is not ALLOCATABLE, SAVE "
15856 "nor a dummy argument", sym
->name
, &sym
->declared_at
);
15860 else if (class_attr
.codimension
&& !sym
->attr
.select_type_temporary
15861 && !class_attr
.allocatable
&& as
&& as
->cotype
== AS_DEFERRED
)
15863 gfc_error ("Coarray variable %qs at %L shall not have codimensions with "
15864 "deferred shape", sym
->name
, &sym
->declared_at
);
15867 else if (class_attr
.codimension
&& class_attr
.allocatable
&& as
15868 && (as
->cotype
!= AS_DEFERRED
|| as
->type
!= AS_DEFERRED
))
15870 gfc_error ("Allocatable coarray variable %qs at %L must have "
15871 "deferred shape", sym
->name
, &sym
->declared_at
);
15876 if ((((sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.u
.derived
->attr
.coarray_comp
)
15877 || (sym
->ts
.type
== BT_CLASS
&& sym
->attr
.class_ok
15878 && sym
->ts
.u
.derived
&& CLASS_DATA (sym
)
15879 && CLASS_DATA (sym
)->attr
.coarray_comp
))
15880 || (class_attr
.codimension
&& class_attr
.allocatable
))
15881 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
)
15883 gfc_error ("Variable %qs at %L is INTENT(OUT) and can thus not be an "
15884 "allocatable coarray or have coarray components",
15885 sym
->name
, &sym
->declared_at
);
15889 if (class_attr
.codimension
&& sym
->attr
.dummy
15890 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.is_bind_c
)
15892 gfc_error ("Coarray dummy variable %qs at %L not allowed in BIND(C) "
15893 "procedure %qs", sym
->name
, &sym
->declared_at
,
15894 sym
->ns
->proc_name
->name
);
15898 if (sym
->ts
.type
== BT_LOGICAL
15899 && ((sym
->attr
.function
&& sym
->attr
.is_bind_c
&& sym
->result
== sym
)
15900 || ((sym
->attr
.dummy
|| sym
->attr
.result
) && sym
->ns
->proc_name
15901 && sym
->ns
->proc_name
->attr
.is_bind_c
)))
15904 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
15905 if (gfc_logical_kinds
[i
].kind
== sym
->ts
.kind
)
15907 if (!gfc_logical_kinds
[i
].c_bool
&& sym
->attr
.dummy
15908 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL dummy argument %qs at "
15909 "%L with non-C_Bool kind in BIND(C) procedure "
15910 "%qs", sym
->name
, &sym
->declared_at
,
15911 sym
->ns
->proc_name
->name
))
15913 else if (!gfc_logical_kinds
[i
].c_bool
15914 && !gfc_notify_std (GFC_STD_GNU
, "LOGICAL result variable "
15915 "%qs at %L with non-C_Bool kind in "
15916 "BIND(C) procedure %qs", sym
->name
,
15918 sym
->attr
.function
? sym
->name
15919 : sym
->ns
->proc_name
->name
))
15923 switch (sym
->attr
.flavor
)
15926 if (!resolve_fl_variable (sym
, mp_flag
))
15931 if (sym
->formal
&& !sym
->formal_ns
)
15933 /* Check that none of the arguments are a namelist. */
15934 gfc_formal_arglist
*formal
= sym
->formal
;
15936 for (; formal
; formal
= formal
->next
)
15937 if (formal
->sym
&& formal
->sym
->attr
.flavor
== FL_NAMELIST
)
15939 gfc_error ("Namelist %qs cannot be an argument to "
15940 "subroutine or function at %L",
15941 formal
->sym
->name
, &sym
->declared_at
);
15946 if (!resolve_fl_procedure (sym
, mp_flag
))
15951 if (!resolve_fl_namelist (sym
))
15956 if (!resolve_fl_parameter (sym
))
15964 /* Resolve array specifier. Check as well some constraints
15965 on COMMON blocks. */
15967 check_constant
= sym
->attr
.in_common
&& !sym
->attr
.pointer
;
15969 /* Set the formal_arg_flag so that check_conflict will not throw
15970 an error for host associated variables in the specification
15971 expression for an array_valued function. */
15972 if ((sym
->attr
.function
|| sym
->attr
.result
) && sym
->as
)
15973 formal_arg_flag
= true;
15975 saved_specification_expr
= specification_expr
;
15976 specification_expr
= true;
15977 gfc_resolve_array_spec (sym
->as
, check_constant
);
15978 specification_expr
= saved_specification_expr
;
15980 formal_arg_flag
= false;
15982 /* Resolve formal namespaces. */
15983 if (sym
->formal_ns
&& sym
->formal_ns
!= gfc_current_ns
15984 && !sym
->attr
.contained
&& !sym
->attr
.intrinsic
)
15985 gfc_resolve (sym
->formal_ns
);
15987 /* Make sure the formal namespace is present. */
15988 if (sym
->formal
&& !sym
->formal_ns
)
15990 gfc_formal_arglist
*formal
= sym
->formal
;
15991 while (formal
&& !formal
->sym
)
15992 formal
= formal
->next
;
15996 sym
->formal_ns
= formal
->sym
->ns
;
15997 if (sym
->formal_ns
&& sym
->ns
!= formal
->sym
->ns
)
15998 sym
->formal_ns
->refs
++;
16002 /* Check threadprivate restrictions. */
16003 if (sym
->attr
.threadprivate
&& !sym
->attr
.save
16004 && !(sym
->ns
->save_all
&& !sym
->attr
.automatic
)
16005 && (!sym
->attr
.in_common
16006 && sym
->module
== NULL
16007 && (sym
->ns
->proc_name
== NULL
16008 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
16009 gfc_error ("Threadprivate at %L isn't SAVEd", &sym
->declared_at
);
16011 /* Check omp declare target restrictions. */
16012 if (sym
->attr
.omp_declare_target
16013 && sym
->attr
.flavor
== FL_VARIABLE
16015 && !(sym
->ns
->save_all
&& !sym
->attr
.automatic
)
16016 && (!sym
->attr
.in_common
16017 && sym
->module
== NULL
16018 && (sym
->ns
->proc_name
== NULL
16019 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
16020 gfc_error ("!$OMP DECLARE TARGET variable %qs at %L isn't SAVEd",
16021 sym
->name
, &sym
->declared_at
);
16023 /* If we have come this far we can apply default-initializers, as
16024 described in 14.7.5, to those variables that have not already
16025 been assigned one. */
16026 if (sym
->ts
.type
== BT_DERIVED
16028 && !sym
->attr
.allocatable
16029 && !sym
->attr
.alloc_comp
)
16031 symbol_attribute
*a
= &sym
->attr
;
16033 if ((!a
->save
&& !a
->dummy
&& !a
->pointer
16034 && !a
->in_common
&& !a
->use_assoc
16036 && !((a
->function
|| a
->result
)
16038 || sym
->ts
.u
.derived
->attr
.alloc_comp
16039 || sym
->ts
.u
.derived
->attr
.pointer_comp
))
16040 && !(a
->function
&& sym
!= sym
->result
))
16041 || (a
->dummy
&& a
->intent
== INTENT_OUT
&& !a
->pointer
))
16042 apply_default_init (sym
);
16043 else if (a
->function
&& sym
->result
&& a
->access
!= ACCESS_PRIVATE
16044 && (sym
->ts
.u
.derived
->attr
.alloc_comp
16045 || sym
->ts
.u
.derived
->attr
.pointer_comp
))
16046 /* Mark the result symbol to be referenced, when it has allocatable
16048 sym
->result
->attr
.referenced
= 1;
16051 if (sym
->ts
.type
== BT_CLASS
&& sym
->ns
== gfc_current_ns
16052 && sym
->attr
.dummy
&& sym
->attr
.intent
== INTENT_OUT
16053 && !CLASS_DATA (sym
)->attr
.class_pointer
16054 && !CLASS_DATA (sym
)->attr
.allocatable
)
16055 apply_default_init (sym
);
16057 /* If this symbol has a type-spec, check it. */
16058 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
16059 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
))
16060 if (!resolve_typespec_used (&sym
->ts
, &sym
->declared_at
, sym
->name
))
16063 if (sym
->param_list
)
16068 /************* Resolve DATA statements *************/
16072 gfc_data_value
*vnode
;
16078 /* Advance the values structure to point to the next value in the data list. */
16081 next_data_value (void)
16083 while (mpz_cmp_ui (values
.left
, 0) == 0)
16086 if (values
.vnode
->next
== NULL
)
16089 values
.vnode
= values
.vnode
->next
;
16090 mpz_set (values
.left
, values
.vnode
->repeat
);
16098 check_data_variable (gfc_data_variable
*var
, locus
*where
)
16104 ar_type mark
= AR_UNKNOWN
;
16106 mpz_t section_index
[GFC_MAX_DIMENSIONS
];
16112 if (!gfc_resolve_expr (var
->expr
))
16116 mpz_init_set_si (offset
, 0);
16119 if (e
->expr_type
== EXPR_FUNCTION
&& e
->value
.function
.isym
16120 && e
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
16121 e
= e
->value
.function
.actual
->expr
;
16123 if (e
->expr_type
!= EXPR_VARIABLE
)
16125 gfc_error ("Expecting definable entity near %L", where
);
16129 sym
= e
->symtree
->n
.sym
;
16131 if (sym
->ns
->is_block_data
&& !sym
->attr
.in_common
)
16133 gfc_error ("BLOCK DATA element %qs at %L must be in COMMON",
16134 sym
->name
, &sym
->declared_at
);
16138 if (e
->ref
== NULL
&& sym
->as
)
16140 gfc_error ("DATA array %qs at %L must be specified in a previous"
16141 " declaration", sym
->name
, where
);
16145 if (gfc_is_coindexed (e
))
16147 gfc_error ("DATA element %qs at %L cannot have a coindex", sym
->name
,
16152 has_pointer
= sym
->attr
.pointer
;
16154 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
16156 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.pointer
)
16161 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.type
!= AR_FULL
)
16163 gfc_error ("DATA element %qs at %L is a pointer and so must "
16164 "be a full array", sym
->name
, where
);
16168 if (values
.vnode
->expr
->expr_type
== EXPR_CONSTANT
)
16170 gfc_error ("DATA object near %L has the pointer attribute "
16171 "and the corresponding DATA value is not a valid "
16172 "initial-data-target", where
);
16177 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.allocatable
)
16179 gfc_error ("DATA element %qs at %L cannot have the ALLOCATABLE "
16180 "attribute", ref
->u
.c
.component
->name
, &e
->where
);
16185 if (e
->rank
== 0 || has_pointer
)
16187 mpz_init_set_ui (size
, 1);
16194 /* Find the array section reference. */
16195 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
16197 if (ref
->type
!= REF_ARRAY
)
16199 if (ref
->u
.ar
.type
== AR_ELEMENT
)
16205 /* Set marks according to the reference pattern. */
16206 switch (ref
->u
.ar
.type
)
16214 /* Get the start position of array section. */
16215 gfc_get_section_index (ar
, section_index
, &offset
);
16220 gcc_unreachable ();
16223 if (!gfc_array_size (e
, &size
))
16225 gfc_error ("Nonconstant array section at %L in DATA statement",
16227 mpz_clear (offset
);
16234 while (mpz_cmp_ui (size
, 0) > 0)
16236 if (!next_data_value ())
16238 gfc_error ("DATA statement at %L has more variables than values",
16244 t
= gfc_check_assign (var
->expr
, values
.vnode
->expr
, 0);
16248 /* If we have more than one element left in the repeat count,
16249 and we have more than one element left in the target variable,
16250 then create a range assignment. */
16251 /* FIXME: Only done for full arrays for now, since array sections
16253 if (mark
== AR_FULL
&& ref
&& ref
->next
== NULL
16254 && mpz_cmp_ui (values
.left
, 1) > 0 && mpz_cmp_ui (size
, 1) > 0)
16258 if (mpz_cmp (size
, values
.left
) >= 0)
16260 mpz_init_set (range
, values
.left
);
16261 mpz_sub (size
, size
, values
.left
);
16262 mpz_set_ui (values
.left
, 0);
16266 mpz_init_set (range
, size
);
16267 mpz_sub (values
.left
, values
.left
, size
);
16268 mpz_set_ui (size
, 0);
16271 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
16274 mpz_add (offset
, offset
, range
);
16281 /* Assign initial value to symbol. */
16284 mpz_sub_ui (values
.left
, values
.left
, 1);
16285 mpz_sub_ui (size
, size
, 1);
16287 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
,
16292 if (mark
== AR_FULL
)
16293 mpz_add_ui (offset
, offset
, 1);
16295 /* Modify the array section indexes and recalculate the offset
16296 for next element. */
16297 else if (mark
== AR_SECTION
)
16298 gfc_advance_section (section_index
, ar
, &offset
);
16302 if (mark
== AR_SECTION
)
16304 for (i
= 0; i
< ar
->dimen
; i
++)
16305 mpz_clear (section_index
[i
]);
16309 mpz_clear (offset
);
16315 static bool traverse_data_var (gfc_data_variable
*, locus
*);
16317 /* Iterate over a list of elements in a DATA statement. */
16320 traverse_data_list (gfc_data_variable
*var
, locus
*where
)
16323 iterator_stack frame
;
16324 gfc_expr
*e
, *start
, *end
, *step
;
16325 bool retval
= true;
16327 mpz_init (frame
.value
);
16330 start
= gfc_copy_expr (var
->iter
.start
);
16331 end
= gfc_copy_expr (var
->iter
.end
);
16332 step
= gfc_copy_expr (var
->iter
.step
);
16334 if (!gfc_simplify_expr (start
, 1)
16335 || start
->expr_type
!= EXPR_CONSTANT
)
16337 gfc_error ("start of implied-do loop at %L could not be "
16338 "simplified to a constant value", &start
->where
);
16342 if (!gfc_simplify_expr (end
, 1)
16343 || end
->expr_type
!= EXPR_CONSTANT
)
16345 gfc_error ("end of implied-do loop at %L could not be "
16346 "simplified to a constant value", &end
->where
);
16350 if (!gfc_simplify_expr (step
, 1)
16351 || step
->expr_type
!= EXPR_CONSTANT
)
16353 gfc_error ("step of implied-do loop at %L could not be "
16354 "simplified to a constant value", &step
->where
);
16358 if (mpz_cmp_si (step
->value
.integer
, 0) == 0)
16360 gfc_error ("step of implied-do loop at %L shall not be zero",
16366 mpz_set (trip
, end
->value
.integer
);
16367 mpz_sub (trip
, trip
, start
->value
.integer
);
16368 mpz_add (trip
, trip
, step
->value
.integer
);
16370 mpz_div (trip
, trip
, step
->value
.integer
);
16372 mpz_set (frame
.value
, start
->value
.integer
);
16374 frame
.prev
= iter_stack
;
16375 frame
.variable
= var
->iter
.var
->symtree
;
16376 iter_stack
= &frame
;
16378 while (mpz_cmp_ui (trip
, 0) > 0)
16380 if (!traverse_data_var (var
->list
, where
))
16386 e
= gfc_copy_expr (var
->expr
);
16387 if (!gfc_simplify_expr (e
, 1))
16394 mpz_add (frame
.value
, frame
.value
, step
->value
.integer
);
16396 mpz_sub_ui (trip
, trip
, 1);
16400 mpz_clear (frame
.value
);
16403 gfc_free_expr (start
);
16404 gfc_free_expr (end
);
16405 gfc_free_expr (step
);
16407 iter_stack
= frame
.prev
;
16412 /* Type resolve variables in the variable list of a DATA statement. */
16415 traverse_data_var (gfc_data_variable
*var
, locus
*where
)
16419 for (; var
; var
= var
->next
)
16421 if (var
->expr
== NULL
)
16422 t
= traverse_data_list (var
, where
);
16424 t
= check_data_variable (var
, where
);
16434 /* Resolve the expressions and iterators associated with a data statement.
16435 This is separate from the assignment checking because data lists should
16436 only be resolved once. */
16439 resolve_data_variables (gfc_data_variable
*d
)
16441 for (; d
; d
= d
->next
)
16443 if (d
->list
== NULL
)
16445 if (!gfc_resolve_expr (d
->expr
))
16450 if (!gfc_resolve_iterator (&d
->iter
, false, true))
16453 if (!resolve_data_variables (d
->list
))
16462 /* Resolve a single DATA statement. We implement this by storing a pointer to
16463 the value list into static variables, and then recursively traversing the
16464 variables list, expanding iterators and such. */
16467 resolve_data (gfc_data
*d
)
16470 if (!resolve_data_variables (d
->var
))
16473 values
.vnode
= d
->value
;
16474 if (d
->value
== NULL
)
16475 mpz_set_ui (values
.left
, 0);
16477 mpz_set (values
.left
, d
->value
->repeat
);
16479 if (!traverse_data_var (d
->var
, &d
->where
))
16482 /* At this point, we better not have any values left. */
16484 if (next_data_value ())
16485 gfc_error ("DATA statement at %L has more values than variables",
16490 /* 12.6 Constraint: In a pure subprogram any variable which is in common or
16491 accessed by host or use association, is a dummy argument to a pure function,
16492 is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
16493 is storage associated with any such variable, shall not be used in the
16494 following contexts: (clients of this function). */
16496 /* Determines if a variable is not 'pure', i.e., not assignable within a pure
16497 procedure. Returns zero if assignment is OK, nonzero if there is a
16500 gfc_impure_variable (gfc_symbol
*sym
)
16505 if (sym
->attr
.use_assoc
|| sym
->attr
.in_common
)
16508 /* Check if the symbol's ns is inside the pure procedure. */
16509 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
16513 if (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
16517 proc
= sym
->ns
->proc_name
;
16518 if (sym
->attr
.dummy
16519 && !sym
->attr
.value
16520 && ((proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_IN
)
16521 || proc
->attr
.function
))
16524 /* TODO: Sort out what can be storage associated, if anything, and include
16525 it here. In principle equivalences should be scanned but it does not
16526 seem to be possible to storage associate an impure variable this way. */
16531 /* Test whether a symbol is pure or not. For a NULL pointer, checks if the
16532 current namespace is inside a pure procedure. */
16535 gfc_pure (gfc_symbol
*sym
)
16537 symbol_attribute attr
;
16542 /* Check if the current namespace or one of its parents
16543 belongs to a pure procedure. */
16544 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
16546 sym
= ns
->proc_name
;
16550 if (attr
.flavor
== FL_PROCEDURE
&& attr
.pure
)
16558 return attr
.flavor
== FL_PROCEDURE
&& attr
.pure
;
16562 /* Test whether a symbol is implicitly pure or not. For a NULL pointer,
16563 checks if the current namespace is implicitly pure. Note that this
16564 function returns false for a PURE procedure. */
16567 gfc_implicit_pure (gfc_symbol
*sym
)
16573 /* Check if the current procedure is implicit_pure. Walk up
16574 the procedure list until we find a procedure. */
16575 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
16577 sym
= ns
->proc_name
;
16581 if (sym
->attr
.flavor
== FL_PROCEDURE
)
16586 return sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.implicit_pure
16587 && !sym
->attr
.pure
;
16592 gfc_unset_implicit_pure (gfc_symbol
*sym
)
16598 /* Check if the current procedure is implicit_pure. Walk up
16599 the procedure list until we find a procedure. */
16600 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
16602 sym
= ns
->proc_name
;
16606 if (sym
->attr
.flavor
== FL_PROCEDURE
)
16611 if (sym
->attr
.flavor
== FL_PROCEDURE
)
16612 sym
->attr
.implicit_pure
= 0;
16614 sym
->attr
.pure
= 0;
16618 /* Test whether the current procedure is elemental or not. */
16621 gfc_elemental (gfc_symbol
*sym
)
16623 symbol_attribute attr
;
16626 sym
= gfc_current_ns
->proc_name
;
16631 return attr
.flavor
== FL_PROCEDURE
&& attr
.elemental
;
16635 /* Warn about unused labels. */
16638 warn_unused_fortran_label (gfc_st_label
*label
)
16643 warn_unused_fortran_label (label
->left
);
16645 if (label
->defined
== ST_LABEL_UNKNOWN
)
16648 switch (label
->referenced
)
16650 case ST_LABEL_UNKNOWN
:
16651 gfc_warning (OPT_Wunused_label
, "Label %d at %L defined but not used",
16652 label
->value
, &label
->where
);
16655 case ST_LABEL_BAD_TARGET
:
16656 gfc_warning (OPT_Wunused_label
,
16657 "Label %d at %L defined but cannot be used",
16658 label
->value
, &label
->where
);
16665 warn_unused_fortran_label (label
->right
);
16669 /* Returns the sequence type of a symbol or sequence. */
16672 sequence_type (gfc_typespec ts
)
16681 if (ts
.u
.derived
->components
== NULL
)
16682 return SEQ_NONDEFAULT
;
16684 result
= sequence_type (ts
.u
.derived
->components
->ts
);
16685 for (c
= ts
.u
.derived
->components
->next
; c
; c
= c
->next
)
16686 if (sequence_type (c
->ts
) != result
)
16692 if (ts
.kind
!= gfc_default_character_kind
)
16693 return SEQ_NONDEFAULT
;
16695 return SEQ_CHARACTER
;
16698 if (ts
.kind
!= gfc_default_integer_kind
)
16699 return SEQ_NONDEFAULT
;
16701 return SEQ_NUMERIC
;
16704 if (!(ts
.kind
== gfc_default_real_kind
16705 || ts
.kind
== gfc_default_double_kind
))
16706 return SEQ_NONDEFAULT
;
16708 return SEQ_NUMERIC
;
16711 if (ts
.kind
!= gfc_default_complex_kind
)
16712 return SEQ_NONDEFAULT
;
16714 return SEQ_NUMERIC
;
16717 if (ts
.kind
!= gfc_default_logical_kind
)
16718 return SEQ_NONDEFAULT
;
16720 return SEQ_NUMERIC
;
16723 return SEQ_NONDEFAULT
;
16728 /* Resolve derived type EQUIVALENCE object. */
16731 resolve_equivalence_derived (gfc_symbol
*derived
, gfc_symbol
*sym
, gfc_expr
*e
)
16733 gfc_component
*c
= derived
->components
;
16738 /* Shall not be an object of nonsequence derived type. */
16739 if (!derived
->attr
.sequence
)
16741 gfc_error ("Derived type variable %qs at %L must have SEQUENCE "
16742 "attribute to be an EQUIVALENCE object", sym
->name
,
16747 /* Shall not have allocatable components. */
16748 if (derived
->attr
.alloc_comp
)
16750 gfc_error ("Derived type variable %qs at %L cannot have ALLOCATABLE "
16751 "components to be an EQUIVALENCE object",sym
->name
,
16756 if (sym
->attr
.in_common
&& gfc_has_default_initializer (sym
->ts
.u
.derived
))
16758 gfc_error ("Derived type variable %qs at %L with default "
16759 "initialization cannot be in EQUIVALENCE with a variable "
16760 "in COMMON", sym
->name
, &e
->where
);
16764 for (; c
; c
= c
->next
)
16766 if (gfc_bt_struct (c
->ts
.type
)
16767 && (!resolve_equivalence_derived(c
->ts
.u
.derived
, sym
, e
)))
16770 /* Shall not be an object of sequence derived type containing a pointer
16771 in the structure. */
16772 if (c
->attr
.pointer
)
16774 gfc_error ("Derived type variable %qs at %L with pointer "
16775 "component(s) cannot be an EQUIVALENCE object",
16776 sym
->name
, &e
->where
);
16784 /* Resolve equivalence object.
16785 An EQUIVALENCE object shall not be a dummy argument, a pointer, a target,
16786 an allocatable array, an object of nonsequence derived type, an object of
16787 sequence derived type containing a pointer at any level of component
16788 selection, an automatic object, a function name, an entry name, a result
16789 name, a named constant, a structure component, or a subobject of any of
16790 the preceding objects. A substring shall not have length zero. A
16791 derived type shall not have components with default initialization nor
16792 shall two objects of an equivalence group be initialized.
16793 Either all or none of the objects shall have an protected attribute.
16794 The simple constraints are done in symbol.c(check_conflict) and the rest
16795 are implemented here. */
16798 resolve_equivalence (gfc_equiv
*eq
)
16801 gfc_symbol
*first_sym
;
16804 locus
*last_where
= NULL
;
16805 seq_type eq_type
, last_eq_type
;
16806 gfc_typespec
*last_ts
;
16807 int object
, cnt_protected
;
16810 last_ts
= &eq
->expr
->symtree
->n
.sym
->ts
;
16812 first_sym
= eq
->expr
->symtree
->n
.sym
;
16816 for (object
= 1; eq
; eq
= eq
->eq
, object
++)
16820 e
->ts
= e
->symtree
->n
.sym
->ts
;
16821 /* match_varspec might not know yet if it is seeing
16822 array reference or substring reference, as it doesn't
16824 if (e
->ref
&& e
->ref
->type
== REF_ARRAY
)
16826 gfc_ref
*ref
= e
->ref
;
16827 sym
= e
->symtree
->n
.sym
;
16829 if (sym
->attr
.dimension
)
16831 ref
->u
.ar
.as
= sym
->as
;
16835 /* For substrings, convert REF_ARRAY into REF_SUBSTRING. */
16836 if (e
->ts
.type
== BT_CHARACTER
16838 && ref
->type
== REF_ARRAY
16839 && ref
->u
.ar
.dimen
== 1
16840 && ref
->u
.ar
.dimen_type
[0] == DIMEN_RANGE
16841 && ref
->u
.ar
.stride
[0] == NULL
)
16843 gfc_expr
*start
= ref
->u
.ar
.start
[0];
16844 gfc_expr
*end
= ref
->u
.ar
.end
[0];
16847 /* Optimize away the (:) reference. */
16848 if (start
== NULL
&& end
== NULL
)
16851 e
->ref
= ref
->next
;
16853 e
->ref
->next
= ref
->next
;
16858 ref
->type
= REF_SUBSTRING
;
16860 start
= gfc_get_int_expr (gfc_charlen_int_kind
,
16862 ref
->u
.ss
.start
= start
;
16863 if (end
== NULL
&& e
->ts
.u
.cl
)
16864 end
= gfc_copy_expr (e
->ts
.u
.cl
->length
);
16865 ref
->u
.ss
.end
= end
;
16866 ref
->u
.ss
.length
= e
->ts
.u
.cl
;
16873 /* Any further ref is an error. */
16876 gcc_assert (ref
->type
== REF_ARRAY
);
16877 gfc_error ("Syntax error in EQUIVALENCE statement at %L",
16883 if (!gfc_resolve_expr (e
))
16886 sym
= e
->symtree
->n
.sym
;
16888 if (sym
->attr
.is_protected
)
16890 if (cnt_protected
> 0 && cnt_protected
!= object
)
16892 gfc_error ("Either all or none of the objects in the "
16893 "EQUIVALENCE set at %L shall have the "
16894 "PROTECTED attribute",
16899 /* Shall not equivalence common block variables in a PURE procedure. */
16900 if (sym
->ns
->proc_name
16901 && sym
->ns
->proc_name
->attr
.pure
16902 && sym
->attr
.in_common
)
16904 /* Need to check for symbols that may have entered the pure
16905 procedure via a USE statement. */
16906 bool saw_sym
= false;
16907 if (sym
->ns
->use_stmts
)
16910 for (r
= sym
->ns
->use_stmts
->rename
; r
; r
= r
->next
)
16911 if (strcmp(r
->use_name
, sym
->name
) == 0) saw_sym
= true;
16917 gfc_error ("COMMON block member %qs at %L cannot be an "
16918 "EQUIVALENCE object in the pure procedure %qs",
16919 sym
->name
, &e
->where
, sym
->ns
->proc_name
->name
);
16923 /* Shall not be a named constant. */
16924 if (e
->expr_type
== EXPR_CONSTANT
)
16926 gfc_error ("Named constant %qs at %L cannot be an EQUIVALENCE "
16927 "object", sym
->name
, &e
->where
);
16931 if (e
->ts
.type
== BT_DERIVED
16932 && !resolve_equivalence_derived (e
->ts
.u
.derived
, sym
, e
))
16935 /* Check that the types correspond correctly:
16937 A numeric sequence structure may be equivalenced to another sequence
16938 structure, an object of default integer type, default real type, double
16939 precision real type, default logical type such that components of the
16940 structure ultimately only become associated to objects of the same
16941 kind. A character sequence structure may be equivalenced to an object
16942 of default character kind or another character sequence structure.
16943 Other objects may be equivalenced only to objects of the same type and
16944 kind parameters. */
16946 /* Identical types are unconditionally OK. */
16947 if (object
== 1 || gfc_compare_types (last_ts
, &sym
->ts
))
16948 goto identical_types
;
16950 last_eq_type
= sequence_type (*last_ts
);
16951 eq_type
= sequence_type (sym
->ts
);
16953 /* Since the pair of objects is not of the same type, mixed or
16954 non-default sequences can be rejected. */
16956 msg
= "Sequence %s with mixed components in EQUIVALENCE "
16957 "statement at %L with different type objects";
16959 && last_eq_type
== SEQ_MIXED
16960 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
16961 || (eq_type
== SEQ_MIXED
16962 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
16965 msg
= "Non-default type object or sequence %s in EQUIVALENCE "
16966 "statement at %L with objects of different type";
16968 && last_eq_type
== SEQ_NONDEFAULT
16969 && !gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
))
16970 || (eq_type
== SEQ_NONDEFAULT
16971 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
)))
16974 msg
="Non-CHARACTER object %qs in default CHARACTER "
16975 "EQUIVALENCE statement at %L";
16976 if (last_eq_type
== SEQ_CHARACTER
16977 && eq_type
!= SEQ_CHARACTER
16978 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
16981 msg
="Non-NUMERIC object %qs in default NUMERIC "
16982 "EQUIVALENCE statement at %L";
16983 if (last_eq_type
== SEQ_NUMERIC
16984 && eq_type
!= SEQ_NUMERIC
16985 && !gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
, &e
->where
))
16991 last_where
= &e
->where
;
16996 /* Shall not be an automatic array. */
16997 if (e
->ref
->type
== REF_ARRAY
&& is_non_constant_shape_array (sym
))
16999 gfc_error ("Array %qs at %L with non-constant bounds cannot be "
17000 "an EQUIVALENCE object", sym
->name
, &e
->where
);
17007 /* Shall not be a structure component. */
17008 if (r
->type
== REF_COMPONENT
)
17010 gfc_error ("Structure component %qs at %L cannot be an "
17011 "EQUIVALENCE object",
17012 r
->u
.c
.component
->name
, &e
->where
);
17016 /* A substring shall not have length zero. */
17017 if (r
->type
== REF_SUBSTRING
)
17019 if (compare_bound (r
->u
.ss
.start
, r
->u
.ss
.end
) == CMP_GT
)
17021 gfc_error ("Substring at %L has length zero",
17022 &r
->u
.ss
.start
->where
);
17032 /* Function called by resolve_fntype to flag other symbols used in the
17033 length type parameter specification of function results. */
17036 flag_fn_result_spec (gfc_expr
*expr
,
17038 int *f ATTRIBUTE_UNUSED
)
17043 if (expr
->expr_type
== EXPR_VARIABLE
)
17045 s
= expr
->symtree
->n
.sym
;
17046 for (ns
= s
->ns
; ns
; ns
= ns
->parent
)
17052 gfc_error ("Self reference in character length expression "
17053 "for %qs at %L", sym
->name
, &expr
->where
);
17057 if (!s
->fn_result_spec
17058 && s
->attr
.flavor
== FL_PARAMETER
)
17060 /* Function contained in a module.... */
17061 if (ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_MODULE
)
17064 s
->fn_result_spec
= 1;
17065 /* Make sure that this symbol is translated as a module
17067 st
= gfc_get_unique_symtree (ns
);
17071 /* ... which is use associated and called. */
17072 else if (s
->attr
.use_assoc
|| s
->attr
.used_in_submodule
17074 /* External function matched with an interface. */
17077 && s
->ns
->proc_name
->attr
.if_source
== IFSRC_DECL
)
17078 || s
->ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
17079 && s
->ns
->proc_name
->attr
.function
))
17080 s
->fn_result_spec
= 1;
17087 /* Resolve function and ENTRY types, issue diagnostics if needed. */
17090 resolve_fntype (gfc_namespace
*ns
)
17092 gfc_entry_list
*el
;
17095 if (ns
->proc_name
== NULL
|| !ns
->proc_name
->attr
.function
)
17098 /* If there are any entries, ns->proc_name is the entry master
17099 synthetic symbol and ns->entries->sym actual FUNCTION symbol. */
17101 sym
= ns
->entries
->sym
;
17103 sym
= ns
->proc_name
;
17104 if (sym
->result
== sym
17105 && sym
->ts
.type
== BT_UNKNOWN
17106 && !gfc_set_default_type (sym
, 0, NULL
)
17107 && !sym
->attr
.untyped
)
17109 gfc_error ("Function %qs at %L has no IMPLICIT type",
17110 sym
->name
, &sym
->declared_at
);
17111 sym
->attr
.untyped
= 1;
17114 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->ts
.u
.derived
->attr
.use_assoc
17115 && !sym
->attr
.contained
17116 && !gfc_check_symbol_access (sym
->ts
.u
.derived
)
17117 && gfc_check_symbol_access (sym
))
17119 gfc_notify_std (GFC_STD_F2003
, "PUBLIC function %qs at "
17120 "%L of PRIVATE type %qs", sym
->name
,
17121 &sym
->declared_at
, sym
->ts
.u
.derived
->name
);
17125 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
17127 if (el
->sym
->result
== el
->sym
17128 && el
->sym
->ts
.type
== BT_UNKNOWN
17129 && !gfc_set_default_type (el
->sym
, 0, NULL
)
17130 && !el
->sym
->attr
.untyped
)
17132 gfc_error ("ENTRY %qs at %L has no IMPLICIT type",
17133 el
->sym
->name
, &el
->sym
->declared_at
);
17134 el
->sym
->attr
.untyped
= 1;
17138 if (sym
->ts
.type
== BT_CHARACTER
)
17139 gfc_traverse_expr (sym
->ts
.u
.cl
->length
, sym
, flag_fn_result_spec
, 0);
17143 /* 12.3.2.1.1 Defined operators. */
17146 check_uop_procedure (gfc_symbol
*sym
, locus where
)
17148 gfc_formal_arglist
*formal
;
17150 if (!sym
->attr
.function
)
17152 gfc_error ("User operator procedure %qs at %L must be a FUNCTION",
17153 sym
->name
, &where
);
17157 if (sym
->ts
.type
== BT_CHARACTER
17158 && !((sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
) || sym
->ts
.deferred
)
17159 && !(sym
->result
&& ((sym
->result
->ts
.u
.cl
17160 && sym
->result
->ts
.u
.cl
->length
) || sym
->result
->ts
.deferred
)))
17162 gfc_error ("User operator procedure %qs at %L cannot be assumed "
17163 "character length", sym
->name
, &where
);
17167 formal
= gfc_sym_get_dummy_args (sym
);
17168 if (!formal
|| !formal
->sym
)
17170 gfc_error ("User operator procedure %qs at %L must have at least "
17171 "one argument", sym
->name
, &where
);
17175 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
17177 gfc_error ("First argument of operator interface at %L must be "
17178 "INTENT(IN)", &where
);
17182 if (formal
->sym
->attr
.optional
)
17184 gfc_error ("First argument of operator interface at %L cannot be "
17185 "optional", &where
);
17189 formal
= formal
->next
;
17190 if (!formal
|| !formal
->sym
)
17193 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
17195 gfc_error ("Second argument of operator interface at %L must be "
17196 "INTENT(IN)", &where
);
17200 if (formal
->sym
->attr
.optional
)
17202 gfc_error ("Second argument of operator interface at %L cannot be "
17203 "optional", &where
);
17209 gfc_error ("Operator interface at %L must have, at most, two "
17210 "arguments", &where
);
17218 gfc_resolve_uops (gfc_symtree
*symtree
)
17220 gfc_interface
*itr
;
17222 if (symtree
== NULL
)
17225 gfc_resolve_uops (symtree
->left
);
17226 gfc_resolve_uops (symtree
->right
);
17228 for (itr
= symtree
->n
.uop
->op
; itr
; itr
= itr
->next
)
17229 check_uop_procedure (itr
->sym
, itr
->sym
->declared_at
);
17233 /* Examine all of the expressions associated with a program unit,
17234 assign types to all intermediate expressions, make sure that all
17235 assignments are to compatible types and figure out which names
17236 refer to which functions or subroutines. It doesn't check code
17237 block, which is handled by gfc_resolve_code. */
17240 resolve_types (gfc_namespace
*ns
)
17246 gfc_namespace
* old_ns
= gfc_current_ns
;
17247 bool recursive
= ns
->proc_name
&& ns
->proc_name
->attr
.recursive
;
17249 if (ns
->types_resolved
)
17252 /* Check that all IMPLICIT types are ok. */
17253 if (!ns
->seen_implicit_none
)
17256 for (letter
= 0; letter
!= GFC_LETTERS
; ++letter
)
17257 if (ns
->set_flag
[letter
]
17258 && !resolve_typespec_used (&ns
->default_type
[letter
],
17259 &ns
->implicit_loc
[letter
], NULL
))
17263 gfc_current_ns
= ns
;
17265 resolve_entries (ns
);
17267 resolve_common_vars (&ns
->blank_common
, false);
17268 resolve_common_blocks (ns
->common_root
);
17270 resolve_contained_functions (ns
);
17272 if (ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
17273 && ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
17274 gfc_resolve_formal_arglist (ns
->proc_name
);
17276 gfc_traverse_ns (ns
, resolve_bind_c_derived_types
);
17278 for (cl
= ns
->cl_list
; cl
; cl
= cl
->next
)
17279 resolve_charlen (cl
);
17281 gfc_traverse_ns (ns
, resolve_symbol
);
17283 resolve_fntype (ns
);
17285 for (n
= ns
->contained
; n
; n
= n
->sibling
)
17287 if (gfc_pure (ns
->proc_name
) && !gfc_pure (n
->proc_name
))
17288 gfc_error ("Contained procedure %qs at %L of a PURE procedure must "
17289 "also be PURE", n
->proc_name
->name
,
17290 &n
->proc_name
->declared_at
);
17296 gfc_do_concurrent_flag
= 0;
17297 gfc_check_interfaces (ns
);
17299 gfc_traverse_ns (ns
, resolve_values
);
17301 if (ns
->save_all
|| (!flag_automatic
&& !recursive
))
17305 for (d
= ns
->data
; d
; d
= d
->next
)
17309 gfc_traverse_ns (ns
, gfc_formalize_init_value
);
17311 gfc_traverse_ns (ns
, gfc_verify_binding_labels
);
17313 for (eq
= ns
->equiv
; eq
; eq
= eq
->next
)
17314 resolve_equivalence (eq
);
17316 /* Warn about unused labels. */
17317 if (warn_unused_label
)
17318 warn_unused_fortran_label (ns
->st_labels
);
17320 gfc_resolve_uops (ns
->uop_root
);
17322 gfc_traverse_ns (ns
, gfc_verify_DTIO_procedures
);
17324 gfc_resolve_omp_declare_simd (ns
);
17326 gfc_resolve_omp_udrs (ns
->omp_udr_root
);
17328 ns
->types_resolved
= 1;
17330 gfc_current_ns
= old_ns
;
17334 /* Call gfc_resolve_code recursively. */
17337 resolve_codes (gfc_namespace
*ns
)
17340 bitmap_obstack old_obstack
;
17342 if (ns
->resolved
== 1)
17345 for (n
= ns
->contained
; n
; n
= n
->sibling
)
17348 gfc_current_ns
= ns
;
17350 /* Don't clear 'cs_base' if this is the namespace of a BLOCK construct. */
17351 if (!(ns
->proc_name
&& ns
->proc_name
->attr
.flavor
== FL_LABEL
))
17354 /* Set to an out of range value. */
17355 current_entry_id
= -1;
17357 old_obstack
= labels_obstack
;
17358 bitmap_obstack_initialize (&labels_obstack
);
17360 gfc_resolve_oacc_declare (ns
);
17361 gfc_resolve_oacc_routines (ns
);
17362 gfc_resolve_omp_local_vars (ns
);
17363 gfc_resolve_code (ns
->code
, ns
);
17365 bitmap_obstack_release (&labels_obstack
);
17366 labels_obstack
= old_obstack
;
17370 /* This function is called after a complete program unit has been compiled.
17371 Its purpose is to examine all of the expressions associated with a program
17372 unit, assign types to all intermediate expressions, make sure that all
17373 assignments are to compatible types and figure out which names refer to
17374 which functions or subroutines. */
17377 gfc_resolve (gfc_namespace
*ns
)
17379 gfc_namespace
*old_ns
;
17380 code_stack
*old_cs_base
;
17381 struct gfc_omp_saved_state old_omp_state
;
17387 old_ns
= gfc_current_ns
;
17388 old_cs_base
= cs_base
;
17390 /* As gfc_resolve can be called during resolution of an OpenMP construct
17391 body, we should clear any state associated to it, so that say NS's
17392 DO loops are not interpreted as OpenMP loops. */
17393 if (!ns
->construct_entities
)
17394 gfc_omp_save_and_clear_state (&old_omp_state
);
17396 resolve_types (ns
);
17397 component_assignment_level
= 0;
17398 resolve_codes (ns
);
17400 gfc_current_ns
= old_ns
;
17401 cs_base
= old_cs_base
;
17404 gfc_run_passes (ns
);
17406 if (!ns
->construct_entities
)
17407 gfc_omp_restore_state (&old_omp_state
);