1 /* Deal with interfaces.
2 Copyright (C) 2000-2025 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/>. */
22 /* Deal with interfaces. An explicit interface is represented as a
23 singly linked list of formal argument structures attached to the
24 relevant symbols. For an implicit interface, the arguments don't
25 point to symbols. Explicit interfaces point to namespaces that
26 contain the symbols within that interface.
28 Implicit interfaces are linked together in a singly linked list
29 along the next_if member of symbol nodes. Since a particular
30 symbol can only have a single explicit interface, the symbol cannot
31 be part of multiple lists and a single next-member suffices.
33 This is not the case for general classes, though. An operator
34 definition is independent of just about all other uses and has it's
38 Nameless interfaces create symbols with explicit interfaces within
39 the current namespace. They are otherwise unlinked.
42 The generic name points to a linked list of symbols. Each symbol
43 has an explicit interface. Each explicit interface has its own
44 namespace containing the arguments. Module procedures are symbols in
45 which the interface is added later when the module procedure is parsed.
48 User-defined operators are stored in a their own set of symtrees
49 separate from regular symbols. The symtrees point to gfc_user_op
50 structures which in turn head up a list of relevant interfaces.
52 Extended intrinsics and assignment:
53 The head of these interface lists are stored in the containing namespace.
56 An implicit interface is represented as a singly linked list of
57 formal argument list structures that don't point to any symbol
58 nodes -- they just contain types.
61 When a subprogram is defined, the program unit's name points to an
62 interface as usual, but the link to the namespace is NULL and the
63 formal argument list points to symbols within the same namespace as
64 the program unit name. */
68 #include "coretypes.h"
74 /* The current_interface structure holds information about the
75 interface currently being parsed. This structure is saved and
76 restored during recursive interfaces. */
78 gfc_interface_info current_interface
;
81 /* Free the leading members of the gfc_interface linked list given in INTR
82 up to the END element (exclusive: the END element is not freed).
83 If END is not nullptr, it is assumed that END is in the linked list starting
87 free_interface_elements_until (gfc_interface
*intr
, gfc_interface
*end
)
91 for (; intr
!= end
; intr
= next
)
99 /* Free a singly linked list of gfc_interface structures. */
102 gfc_free_interface (gfc_interface
*intr
)
104 free_interface_elements_until (intr
, nullptr);
108 /* Update the interface pointer given by IFC_PTR to make it point to TAIL.
109 It is expected that TAIL (if non-null) is in the list pointed to by
110 IFC_PTR, hence the tail of it. The members of the list before TAIL are
111 freed before the pointer reassignment. */
114 gfc_drop_interface_elements_before (gfc_interface
**ifc_ptr
,
117 if (ifc_ptr
== nullptr)
120 free_interface_elements_until (*ifc_ptr
, tail
);
125 /* Change the operators unary plus and minus into binary plus and
126 minus respectively, leaving the rest unchanged. */
128 static gfc_intrinsic_op
129 fold_unary_intrinsic (gfc_intrinsic_op op
)
133 case INTRINSIC_UPLUS
:
136 case INTRINSIC_UMINUS
:
137 op
= INTRINSIC_MINUS
;
147 /* Return the operator depending on the DTIO moded string. Note that
148 these are not operators in the normal sense and so have been placed
149 beyond GFC_INTRINSIC_END in gfortran.h:enum gfc_intrinsic_op. */
151 static gfc_intrinsic_op
154 if (strcmp (mode
, "formatted") == 0)
155 return INTRINSIC_FORMATTED
;
156 if (strcmp (mode
, "unformatted") == 0)
157 return INTRINSIC_UNFORMATTED
;
158 return INTRINSIC_NONE
;
162 /* Match a generic specification. Depending on which type of
163 interface is found, the 'name' or 'op' pointers may be set.
164 This subroutine doesn't return MATCH_NO. */
167 gfc_match_generic_spec (interface_type
*type
,
169 gfc_intrinsic_op
*op
)
171 char buffer
[GFC_MAX_SYMBOL_LEN
+ 1];
175 if (gfc_match (" assignment ( = )") == MATCH_YES
)
177 *type
= INTERFACE_INTRINSIC_OP
;
178 *op
= INTRINSIC_ASSIGN
;
182 if (gfc_match (" operator ( %o )", &i
) == MATCH_YES
)
184 *type
= INTERFACE_INTRINSIC_OP
;
185 *op
= fold_unary_intrinsic (i
);
189 *op
= INTRINSIC_NONE
;
190 if (gfc_match (" operator ( ") == MATCH_YES
)
192 m
= gfc_match_defined_op_name (buffer
, 1);
198 m
= gfc_match_char (')');
204 strcpy (name
, buffer
);
205 *type
= INTERFACE_USER_OP
;
209 if (gfc_match (" read ( %n )", buffer
) == MATCH_YES
)
211 *op
= dtio_op (buffer
);
212 if (*op
== INTRINSIC_FORMATTED
)
214 strcpy (name
, gfc_code2string (dtio_procs
, DTIO_RF
));
215 *type
= INTERFACE_DTIO
;
217 if (*op
== INTRINSIC_UNFORMATTED
)
219 strcpy (name
, gfc_code2string (dtio_procs
, DTIO_RUF
));
220 *type
= INTERFACE_DTIO
;
222 if (*op
!= INTRINSIC_NONE
)
226 if (gfc_match (" write ( %n )", buffer
) == MATCH_YES
)
228 *op
= dtio_op (buffer
);
229 if (*op
== INTRINSIC_FORMATTED
)
231 strcpy (name
, gfc_code2string (dtio_procs
, DTIO_WF
));
232 *type
= INTERFACE_DTIO
;
234 if (*op
== INTRINSIC_UNFORMATTED
)
236 strcpy (name
, gfc_code2string (dtio_procs
, DTIO_WUF
));
237 *type
= INTERFACE_DTIO
;
239 if (*op
!= INTRINSIC_NONE
)
243 if (gfc_match_name (buffer
) == MATCH_YES
)
245 strcpy (name
, buffer
);
246 *type
= INTERFACE_GENERIC
;
250 *type
= INTERFACE_NAMELESS
;
254 gfc_error ("Syntax error in generic specification at %C");
259 /* Match one of the five F95 forms of an interface statement. The
260 matcher for the abstract interface follows. */
263 gfc_match_interface (void)
265 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
271 m
= gfc_match_space ();
273 if (gfc_match_generic_spec (&type
, name
, &op
) == MATCH_ERROR
)
276 /* If we're not looking at the end of the statement now, or if this
277 is not a nameless interface but we did not see a space, punt. */
278 if (gfc_match_eos () != MATCH_YES
279 || (type
!= INTERFACE_NAMELESS
&& m
!= MATCH_YES
))
281 gfc_error ("Syntax error: Trailing garbage in INTERFACE statement "
286 current_interface
.type
= type
;
291 case INTERFACE_GENERIC
:
292 if (gfc_get_symbol (name
, NULL
, &sym
))
295 if (!sym
->attr
.generic
296 && !gfc_add_generic (&sym
->attr
, sym
->name
, NULL
))
301 gfc_error ("Dummy procedure %qs at %C cannot have a "
302 "generic interface", sym
->name
);
306 current_interface
.sym
= gfc_new_block
= sym
;
309 case INTERFACE_USER_OP
:
310 current_interface
.uop
= gfc_get_uop (name
);
313 case INTERFACE_INTRINSIC_OP
:
314 current_interface
.op
= op
;
317 case INTERFACE_NAMELESS
:
318 case INTERFACE_ABSTRACT
:
327 /* Match a F2003 abstract interface. */
330 gfc_match_abstract_interface (void)
334 if (!gfc_notify_std (GFC_STD_F2003
, "ABSTRACT INTERFACE at %C"))
337 m
= gfc_match_eos ();
341 gfc_error ("Syntax error in ABSTRACT INTERFACE statement at %C");
345 current_interface
.type
= INTERFACE_ABSTRACT
;
351 /* Match the different sort of generic-specs that can be present after
352 the END INTERFACE itself. */
355 gfc_match_end_interface (void)
357 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
362 m
= gfc_match_space ();
364 if (gfc_match_generic_spec (&type
, name
, &op
) == MATCH_ERROR
)
367 /* If we're not looking at the end of the statement now, or if this
368 is not a nameless interface but we did not see a space, punt. */
369 if (gfc_match_eos () != MATCH_YES
370 || (type
!= INTERFACE_NAMELESS
&& m
!= MATCH_YES
))
372 gfc_error ("Syntax error: Trailing garbage in END INTERFACE "
379 switch (current_interface
.type
)
381 case INTERFACE_NAMELESS
:
382 case INTERFACE_ABSTRACT
:
383 if (type
!= INTERFACE_NAMELESS
)
385 gfc_error ("Expected a nameless interface at %C");
391 case INTERFACE_INTRINSIC_OP
:
392 if (type
!= current_interface
.type
|| op
!= current_interface
.op
)
395 if (current_interface
.op
== INTRINSIC_ASSIGN
)
398 gfc_error ("Expected %<END INTERFACE ASSIGNMENT (=)%> at %C");
403 s1
= gfc_op2string (current_interface
.op
);
404 s2
= gfc_op2string (op
);
406 /* The following if-statements are used to enforce C1202
408 if ((strcmp(s1
, "==") == 0 && strcmp (s2
, ".eq.") == 0)
409 || (strcmp(s1
, ".eq.") == 0 && strcmp (s2
, "==") == 0))
411 if ((strcmp(s1
, "/=") == 0 && strcmp (s2
, ".ne.") == 0)
412 || (strcmp(s1
, ".ne.") == 0 && strcmp (s2
, "/=") == 0))
414 if ((strcmp(s1
, "<=") == 0 && strcmp (s2
, ".le.") == 0)
415 || (strcmp(s1
, ".le.") == 0 && strcmp (s2
, "<=") == 0))
417 if ((strcmp(s1
, "<") == 0 && strcmp (s2
, ".lt.") == 0)
418 || (strcmp(s1
, ".lt.") == 0 && strcmp (s2
, "<") == 0))
420 if ((strcmp(s1
, ">=") == 0 && strcmp (s2
, ".ge.") == 0)
421 || (strcmp(s1
, ".ge.") == 0 && strcmp (s2
, ">=") == 0))
423 if ((strcmp(s1
, ">") == 0 && strcmp (s2
, ".gt.") == 0)
424 || (strcmp(s1
, ".gt.") == 0 && strcmp (s2
, ">") == 0))
428 if (strcmp(s2
, "none") == 0)
429 gfc_error ("Expecting %<END INTERFACE OPERATOR (%s)%> "
432 gfc_error ("Expecting %<END INTERFACE OPERATOR (%s)%> at %C, "
433 "but got %qs", s1
, s2
);
440 case INTERFACE_USER_OP
:
441 /* Comparing the symbol node names is OK because only use-associated
442 symbols can be renamed. */
443 if (type
!= current_interface
.type
444 || strcmp (current_interface
.uop
->name
, name
) != 0)
446 gfc_error ("Expecting %<END INTERFACE OPERATOR (.%s.)%> at %C",
447 current_interface
.uop
->name
);
454 case INTERFACE_GENERIC
:
455 /* If a use-associated symbol is renamed, check the local_name. */
456 const char *local_name
= current_interface
.sym
->name
;
458 if (current_interface
.sym
->attr
.use_assoc
459 && current_interface
.sym
->attr
.use_rename
460 && current_interface
.sym
->ns
->use_stmts
->rename
461 && (current_interface
.sym
->ns
->use_stmts
->rename
->local_name
[0]
463 local_name
= current_interface
.sym
->ns
->use_stmts
->rename
->local_name
;
465 if (type
!= current_interface
.type
466 || strcmp (local_name
, name
) != 0)
468 gfc_error ("Expecting %<END INTERFACE %s%> at %C", local_name
);
479 /* Return whether the component was defined anonymously. */
482 is_anonymous_component (gfc_component
*cmp
)
484 /* Only UNION and MAP components are anonymous. In the case of a MAP,
485 the derived type symbol is FL_STRUCT and the component name looks like mM*.
486 This is the only case in which the second character of a component name is
488 return cmp
->ts
.type
== BT_UNION
489 || (cmp
->ts
.type
== BT_DERIVED
490 && cmp
->ts
.u
.derived
->attr
.flavor
== FL_STRUCT
491 && cmp
->name
[0] && cmp
->name
[1] && ISUPPER (cmp
->name
[1]));
495 /* Return whether the derived type was defined anonymously. */
498 is_anonymous_dt (gfc_symbol
*derived
)
500 /* UNION and MAP types are always anonymous. Otherwise, only nested STRUCTURE
501 types can be anonymous. For anonymous MAP/STRUCTURE, we have FL_STRUCT
502 and the type name looks like XX*. This is the only case in which the
503 second character of a type name is uppercase. */
504 return derived
->attr
.flavor
== FL_UNION
505 || (derived
->attr
.flavor
== FL_STRUCT
506 && derived
->name
[0] && derived
->name
[1] && ISUPPER (derived
->name
[1]));
510 /* Compare components according to 4.4.2 of the Fortran standard. */
513 compare_components (gfc_component
*cmp1
, gfc_component
*cmp2
,
514 gfc_symbol
*derived1
, gfc_symbol
*derived2
)
516 /* Compare names, but not for anonymous components such as UNION or MAP. */
517 if (!is_anonymous_component (cmp1
) && !is_anonymous_component (cmp2
)
518 && strcmp (cmp1
->name
, cmp2
->name
) != 0)
521 if (cmp1
->attr
.access
!= cmp2
->attr
.access
)
524 if (cmp1
->attr
.pointer
!= cmp2
->attr
.pointer
)
527 if (cmp1
->attr
.dimension
!= cmp2
->attr
.dimension
)
530 if (cmp1
->attr
.codimension
!= cmp2
->attr
.codimension
)
533 if (cmp1
->attr
.allocatable
!= cmp2
->attr
.allocatable
)
536 if (cmp1
->attr
.dimension
&& gfc_compare_array_spec (cmp1
->as
, cmp2
->as
) == 0)
539 if (cmp1
->attr
.codimension
540 && gfc_compare_array_spec (cmp1
->as
, cmp2
->as
) == 0)
543 if (cmp1
->ts
.type
== BT_CHARACTER
&& cmp2
->ts
.type
== BT_CHARACTER
)
545 gfc_charlen
*l1
= cmp1
->ts
.u
.cl
;
546 gfc_charlen
*l2
= cmp2
->ts
.u
.cl
;
547 if (l1
&& l2
&& l1
->length
&& l2
->length
548 && l1
->length
->expr_type
== EXPR_CONSTANT
549 && l2
->length
->expr_type
== EXPR_CONSTANT
550 && gfc_dep_compare_expr (l1
->length
, l2
->length
) != 0)
554 /* Make sure that link lists do not put this function into an
555 endless recursive loop! */
556 if (!(cmp1
->ts
.type
== BT_DERIVED
&& derived1
== cmp1
->ts
.u
.derived
)
557 && !(cmp2
->ts
.type
== BT_DERIVED
&& derived2
== cmp2
->ts
.u
.derived
)
558 && !gfc_compare_types (&cmp1
->ts
, &cmp2
->ts
))
561 else if ( (cmp1
->ts
.type
== BT_DERIVED
&& derived1
== cmp1
->ts
.u
.derived
)
562 && !(cmp2
->ts
.type
== BT_DERIVED
&& derived2
== cmp2
->ts
.u
.derived
))
565 else if (!(cmp1
->ts
.type
== BT_DERIVED
&& derived1
== cmp1
->ts
.u
.derived
)
566 && (cmp2
->ts
.type
== BT_DERIVED
&& derived2
== cmp2
->ts
.u
.derived
))
573 /* Compare two union types by comparing the components of their maps.
574 Because unions and maps are anonymous their types get special internal
575 names; therefore the usual derived type comparison will fail on them.
577 Returns nonzero if equal, as with gfc_compare_derived_types. Also as with
578 gfc_compare_derived_types, 'equal' is closer to meaning 'duplicate
579 definitions' than 'equivalent structure'. */
582 compare_union_types (gfc_symbol
*un1
, gfc_symbol
*un2
)
584 gfc_component
*map1
, *map2
, *cmp1
, *cmp2
;
585 gfc_symbol
*map1_t
, *map2_t
;
587 if (un1
->attr
.flavor
!= FL_UNION
|| un2
->attr
.flavor
!= FL_UNION
)
590 if (un1
->attr
.zero_comp
!= un2
->attr
.zero_comp
)
593 if (un1
->attr
.zero_comp
)
596 map1
= un1
->components
;
597 map2
= un2
->components
;
599 /* In terms of 'equality' here we are worried about types which are
600 declared the same in two places, not types that represent equivalent
601 structures. (This is common because of FORTRAN's weird scoping rules.)
602 Though two unions with their maps in different orders could be equivalent,
603 we will say they are not equal for the purposes of this test; therefore
604 we compare the maps sequentially. */
607 map1_t
= map1
->ts
.u
.derived
;
608 map2_t
= map2
->ts
.u
.derived
;
610 cmp1
= map1_t
->components
;
611 cmp2
= map2_t
->components
;
613 /* Protect against null components. */
614 if (map1_t
->attr
.zero_comp
!= map2_t
->attr
.zero_comp
)
617 if (map1_t
->attr
.zero_comp
)
622 /* No two fields will ever point to the same map type unless they are
623 the same component, because one map field is created with its type
624 declaration. Therefore don't worry about recursion here. */
625 /* TODO: worry about recursion into parent types of the unions? */
626 if (!compare_components (cmp1
, cmp2
, map1_t
, map2_t
))
632 if (cmp1
== NULL
&& cmp2
== NULL
)
634 if (cmp1
== NULL
|| cmp2
== NULL
)
641 if (map1
== NULL
&& map2
== NULL
)
643 if (map1
== NULL
|| map2
== NULL
)
652 /* Compare two derived types using the criteria in 4.4.2 of the standard,
653 recursing through gfc_compare_types for the components. */
656 gfc_compare_derived_types (gfc_symbol
*derived1
, gfc_symbol
*derived2
)
658 gfc_component
*cmp1
, *cmp2
;
660 if (derived1
== derived2
)
663 if (!derived1
|| !derived2
)
664 gfc_internal_error ("gfc_compare_derived_types: invalid derived type");
666 if (derived1
->attr
.unlimited_polymorphic
667 && derived2
->attr
.unlimited_polymorphic
)
670 if (derived1
->attr
.unlimited_polymorphic
671 != derived2
->attr
.unlimited_polymorphic
)
674 /* Compare UNION types specially. */
675 if (derived1
->attr
.flavor
== FL_UNION
|| derived2
->attr
.flavor
== FL_UNION
)
676 return compare_union_types (derived1
, derived2
);
678 /* Special case for comparing derived types across namespaces. If the
679 true names and module names are the same and the module name is
680 nonnull, then they are equal. */
681 if (strcmp (derived1
->name
, derived2
->name
) == 0
682 && derived1
->module
!= NULL
&& derived2
->module
!= NULL
683 && strcmp (derived1
->module
, derived2
->module
) == 0)
686 /* Compare type via the rules of the standard. Both types must have the
687 SEQUENCE or BIND(C) attribute to be equal. We also compare types
688 recursively if they are class descriptors types or virtual tables types.
689 STRUCTUREs are special because they can be anonymous; therefore two
690 structures with different names may be equal. */
692 /* Compare names, but not for anonymous types such as UNION or MAP. */
693 if (!is_anonymous_dt (derived1
) && !is_anonymous_dt (derived2
)
694 && strcmp (derived1
->name
, derived2
->name
) != 0)
697 if (derived1
->component_access
== ACCESS_PRIVATE
698 || derived2
->component_access
== ACCESS_PRIVATE
)
701 if (!(derived1
->attr
.sequence
&& derived2
->attr
.sequence
)
702 && !(derived1
->attr
.is_bind_c
&& derived2
->attr
.is_bind_c
)
703 && !(derived1
->attr
.is_class
&& derived2
->attr
.is_class
)
704 && !(derived1
->attr
.vtype
&& derived2
->attr
.vtype
)
705 && !(derived1
->attr
.pdt_type
&& derived2
->attr
.pdt_type
))
708 /* Protect against null components. */
709 if (derived1
->attr
.zero_comp
!= derived2
->attr
.zero_comp
)
712 if (derived1
->attr
.zero_comp
)
715 cmp1
= derived1
->components
;
716 cmp2
= derived2
->components
;
718 /* Since subtypes of SEQUENCE types must be SEQUENCE types as well, a
719 simple test can speed things up. Otherwise, lots of things have to
723 if (!compare_components (cmp1
, cmp2
, derived1
, derived2
))
729 if (cmp1
== NULL
&& cmp2
== NULL
)
731 if (cmp1
== NULL
|| cmp2
== NULL
)
739 /* Compare two typespecs, recursively if necessary. */
742 gfc_compare_types (gfc_typespec
*ts1
, gfc_typespec
*ts2
)
744 /* See if one of the typespecs is a BT_VOID, which is what is being used
745 to allow the funcs like c_f_pointer to accept any pointer type.
746 TODO: Possibly should narrow this to just the one typespec coming in
747 that is for the formal arg, but oh well. */
748 if (ts1
->type
== BT_VOID
|| ts2
->type
== BT_VOID
)
751 /* Special case for our C interop types. FIXME: There should be a
752 better way of doing this. When ISO C binding is cleared up,
753 this can probably be removed. See PR 57048. */
755 if ((ts1
->type
== BT_INTEGER
756 && ts2
->type
== BT_DERIVED
757 && ts1
->f90_type
== BT_VOID
758 && ts2
->u
.derived
->from_intmod
== INTMOD_ISO_C_BINDING
760 && strcmp (ts1
->u
.derived
->name
, ts2
->u
.derived
->name
) == 0)
761 || (ts2
->type
== BT_INTEGER
762 && ts1
->type
== BT_DERIVED
763 && ts2
->f90_type
== BT_VOID
764 && ts1
->u
.derived
->from_intmod
== INTMOD_ISO_C_BINDING
766 && strcmp (ts1
->u
.derived
->name
, ts2
->u
.derived
->name
) == 0))
769 /* The _data component is not always present, therefore check for its
770 presence before assuming, that its derived->attr is available.
771 When the _data component is not present, then nevertheless the
772 unlimited_polymorphic flag may be set in the derived type's attr. */
773 if (ts1
->type
== BT_CLASS
&& ts1
->u
.derived
->components
774 && ((ts1
->u
.derived
->attr
.is_class
775 && ts1
->u
.derived
->components
->ts
.u
.derived
->attr
776 .unlimited_polymorphic
)
777 || ts1
->u
.derived
->attr
.unlimited_polymorphic
))
781 if (ts2
->type
== BT_CLASS
&& ts1
->type
== BT_DERIVED
782 && ts2
->u
.derived
->components
783 && ((ts2
->u
.derived
->attr
.is_class
784 && ts2
->u
.derived
->components
->ts
.u
.derived
->attr
785 .unlimited_polymorphic
)
786 || ts2
->u
.derived
->attr
.unlimited_polymorphic
)
787 && (ts1
->u
.derived
->attr
.sequence
|| ts1
->u
.derived
->attr
.is_bind_c
))
790 if (ts1
->type
!= ts2
->type
791 && ((ts1
->type
!= BT_DERIVED
&& ts1
->type
!= BT_CLASS
)
792 || (ts2
->type
!= BT_DERIVED
&& ts2
->type
!= BT_CLASS
)))
795 if (ts1
->type
== BT_UNION
)
796 return compare_union_types (ts1
->u
.derived
, ts2
->u
.derived
);
798 if (ts1
->type
!= BT_DERIVED
&& ts1
->type
!= BT_CLASS
)
799 return (ts1
->kind
== ts2
->kind
);
801 /* Compare derived types. */
802 return gfc_type_compatible (ts1
, ts2
);
807 compare_type (gfc_symbol
*s1
, gfc_symbol
*s2
)
809 if (s2
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
812 return gfc_compare_types (&s1
->ts
, &s2
->ts
) || s2
->ts
.type
== BT_ASSUMED
;
817 compare_type_characteristics (gfc_symbol
*s1
, gfc_symbol
*s2
)
819 /* TYPE and CLASS of the same declared type are type compatible,
820 but have different characteristics. */
821 if ((s1
->ts
.type
== BT_CLASS
&& s2
->ts
.type
== BT_DERIVED
)
822 || (s1
->ts
.type
== BT_DERIVED
&& s2
->ts
.type
== BT_CLASS
))
825 return compare_type (s1
, s2
);
830 compare_rank (gfc_symbol
*s1
, gfc_symbol
*s2
)
832 gfc_array_spec
*as1
, *as2
;
835 if (s2
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
838 as1
= (s1
->ts
.type
== BT_CLASS
839 && !s1
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
840 ? CLASS_DATA (s1
)->as
: s1
->as
;
841 as2
= (s2
->ts
.type
== BT_CLASS
842 && !s2
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
843 ? CLASS_DATA (s2
)->as
: s2
->as
;
845 r1
= as1
? as1
->rank
: 0;
846 r2
= as2
? as2
->rank
: 0;
848 if (r1
!= r2
&& (!as2
|| as2
->type
!= AS_ASSUMED_RANK
))
849 return false; /* Ranks differ. */
855 /* Given two symbols that are formal arguments, compare their ranks
856 and types. Returns true if they have the same rank and type,
860 compare_type_rank (gfc_symbol
*s1
, gfc_symbol
*s2
)
862 return compare_type (s1
, s2
) && compare_rank (s1
, s2
);
866 /* Given two symbols that are formal arguments, compare their types
867 and rank and their formal interfaces if they are both dummy
868 procedures. Returns true if the same, false if different. */
871 compare_type_rank_if (gfc_symbol
*s1
, gfc_symbol
*s2
)
873 if (s1
== NULL
|| s2
== NULL
)
879 if (s1
->attr
.flavor
!= FL_PROCEDURE
&& s2
->attr
.flavor
!= FL_PROCEDURE
)
880 return compare_type_rank (s1
, s2
);
882 if (s1
->attr
.flavor
!= FL_PROCEDURE
|| s2
->attr
.flavor
!= FL_PROCEDURE
)
885 /* At this point, both symbols are procedures. It can happen that
886 external procedures are compared, where one is identified by usage
887 to be a function or subroutine but the other is not. Check TKR
888 nonetheless for these cases. */
889 if (s1
->attr
.function
== 0 && s1
->attr
.subroutine
== 0)
890 return s1
->attr
.external
? compare_type_rank (s1
, s2
) : false;
892 if (s2
->attr
.function
== 0 && s2
->attr
.subroutine
== 0)
893 return s2
->attr
.external
? compare_type_rank (s1
, s2
) : false;
895 /* Now the type of procedure has been identified. */
896 if (s1
->attr
.function
!= s2
->attr
.function
897 || s1
->attr
.subroutine
!= s2
->attr
.subroutine
)
900 if (s1
->attr
.function
&& !compare_type_rank (s1
, s2
))
903 /* Originally, gfortran recursed here to check the interfaces of passed
904 procedures. This is explicitly not required by the standard. */
909 /* Given a formal argument list and a keyword name, search the list
910 for that keyword. Returns the correct symbol node if found, NULL
914 find_keyword_arg (const char *name
, gfc_formal_arglist
*f
)
916 for (; f
; f
= f
->next
)
917 if (strcmp (f
->sym
->name
, name
) == 0)
924 /******** Interface checking subroutines **********/
927 /* Given an operator interface and the operator, make sure that all
928 interfaces for that operator are legal. */
931 gfc_check_operator_interface (gfc_symbol
*sym
, gfc_intrinsic_op op
,
934 gfc_formal_arglist
*formal
;
937 int args
, r1
, r2
, k1
, k2
;
942 t1
= t2
= BT_UNKNOWN
;
943 i1
= i2
= INTENT_UNKNOWN
;
947 for (formal
= gfc_sym_get_dummy_args (sym
); formal
; formal
= formal
->next
)
949 gfc_symbol
*fsym
= formal
->sym
;
952 gfc_error ("Alternate return cannot appear in operator "
953 "interface at %L", &sym
->declared_at
);
959 i1
= fsym
->attr
.intent
;
960 r1
= (fsym
->as
!= NULL
) ? fsym
->as
->rank
: 0;
966 i2
= fsym
->attr
.intent
;
967 r2
= (fsym
->as
!= NULL
) ? fsym
->as
->rank
: 0;
973 /* Only +, - and .not. can be unary operators.
974 .not. cannot be a binary operator. */
975 if (args
== 0 || args
> 2 || (args
== 1 && op
!= INTRINSIC_PLUS
976 && op
!= INTRINSIC_MINUS
977 && op
!= INTRINSIC_NOT
)
978 || (args
== 2 && op
== INTRINSIC_NOT
))
980 if (op
== INTRINSIC_ASSIGN
)
981 gfc_error ("Assignment operator interface at %L must have "
982 "two arguments", &sym
->declared_at
);
984 gfc_error ("Operator interface at %L has the wrong number of arguments",
989 /* Check that intrinsics are mapped to functions, except
990 INTRINSIC_ASSIGN which should map to a subroutine. */
991 if (op
== INTRINSIC_ASSIGN
)
993 gfc_formal_arglist
*dummy_args
;
995 if (!sym
->attr
.subroutine
)
997 gfc_error ("Assignment operator interface at %L must be "
998 "a SUBROUTINE", &sym
->declared_at
);
1002 /* Allowed are (per F2003, 12.3.2.1.2 Defined assignments):
1003 - First argument an array with different rank than second,
1004 - First argument is a scalar and second an array,
1005 - Types and kinds do not conform, or
1006 - First argument is of derived type. */
1007 dummy_args
= gfc_sym_get_dummy_args (sym
);
1008 if (dummy_args
->sym
->ts
.type
!= BT_DERIVED
1009 && dummy_args
->sym
->ts
.type
!= BT_CLASS
1010 && (r2
== 0 || r1
== r2
)
1011 && (dummy_args
->sym
->ts
.type
== dummy_args
->next
->sym
->ts
.type
1012 || (gfc_numeric_ts (&dummy_args
->sym
->ts
)
1013 && gfc_numeric_ts (&dummy_args
->next
->sym
->ts
))))
1015 gfc_error ("Assignment operator interface at %L must not redefine "
1016 "an INTRINSIC type assignment", &sym
->declared_at
);
1022 if (!sym
->attr
.function
)
1024 gfc_error ("Intrinsic operator interface at %L must be a FUNCTION",
1030 /* Check intents on operator interfaces. */
1031 if (op
== INTRINSIC_ASSIGN
)
1033 if (i1
!= INTENT_OUT
&& i1
!= INTENT_INOUT
)
1035 gfc_error ("First argument of defined assignment at %L must be "
1036 "INTENT(OUT) or INTENT(INOUT)", &sym
->declared_at
);
1040 if (i2
!= INTENT_IN
)
1042 gfc_error ("Second argument of defined assignment at %L must be "
1043 "INTENT(IN)", &sym
->declared_at
);
1049 if (i1
!= INTENT_IN
)
1051 gfc_error ("First argument of operator interface at %L must be "
1052 "INTENT(IN)", &sym
->declared_at
);
1056 if (args
== 2 && i2
!= INTENT_IN
)
1058 gfc_error ("Second argument of operator interface at %L must be "
1059 "INTENT(IN)", &sym
->declared_at
);
1064 /* From now on, all we have to do is check that the operator definition
1065 doesn't conflict with an intrinsic operator. The rules for this
1066 game are defined in 7.1.2 and 7.1.3 of both F95 and F2003 standards,
1067 as well as 12.3.2.1.1 of Fortran 2003:
1069 "If the operator is an intrinsic-operator (R310), the number of
1070 function arguments shall be consistent with the intrinsic uses of
1071 that operator, and the types, kind type parameters, or ranks of the
1072 dummy arguments shall differ from those required for the intrinsic
1073 operation (7.1.2)." */
1075 #define IS_NUMERIC_TYPE(t) \
1076 ((t) == BT_INTEGER || (t) == BT_REAL || (t) == BT_COMPLEX)
1078 /* Unary ops are easy, do them first. */
1079 if (op
== INTRINSIC_NOT
)
1081 if (t1
== BT_LOGICAL
)
1087 if (args
== 1 && (op
== INTRINSIC_PLUS
|| op
== INTRINSIC_MINUS
))
1089 if (IS_NUMERIC_TYPE (t1
))
1095 /* Character intrinsic operators have same character kind, thus
1096 operator definitions with operands of different character kinds
1098 if (t1
== BT_CHARACTER
&& t2
== BT_CHARACTER
&& k1
!= k2
)
1101 /* Intrinsic operators always perform on arguments of same rank,
1102 so different ranks is also always safe. (rank == 0) is an exception
1103 to that, because all intrinsic operators are elemental. */
1104 if (r1
!= r2
&& r1
!= 0 && r2
!= 0)
1110 case INTRINSIC_EQ_OS
:
1112 case INTRINSIC_NE_OS
:
1113 if (t1
== BT_CHARACTER
&& t2
== BT_CHARACTER
)
1117 case INTRINSIC_PLUS
:
1118 case INTRINSIC_MINUS
:
1119 case INTRINSIC_TIMES
:
1120 case INTRINSIC_DIVIDE
:
1121 case INTRINSIC_POWER
:
1122 if (IS_NUMERIC_TYPE (t1
) && IS_NUMERIC_TYPE (t2
))
1127 case INTRINSIC_GT_OS
:
1129 case INTRINSIC_GE_OS
:
1131 case INTRINSIC_LT_OS
:
1133 case INTRINSIC_LE_OS
:
1134 if (t1
== BT_CHARACTER
&& t2
== BT_CHARACTER
)
1136 if ((t1
== BT_INTEGER
|| t1
== BT_REAL
)
1137 && (t2
== BT_INTEGER
|| t2
== BT_REAL
))
1141 case INTRINSIC_CONCAT
:
1142 if (t1
== BT_CHARACTER
&& t2
== BT_CHARACTER
)
1149 case INTRINSIC_NEQV
:
1150 if (t1
== BT_LOGICAL
&& t2
== BT_LOGICAL
)
1160 #undef IS_NUMERIC_TYPE
1163 gfc_error ("Operator interface at %L conflicts with intrinsic interface",
1169 /* Given a pair of formal argument lists, we see if the two lists can
1170 be distinguished by counting the number of nonoptional arguments of
1171 a given type/rank in f1 and seeing if there are less then that
1172 number of those arguments in f2 (including optional arguments).
1173 Since this test is asymmetric, it has to be called twice to make it
1174 symmetric. Returns nonzero if the argument lists are incompatible
1175 by this test. This subroutine implements rule 1 of section F03:16.2.3.
1176 'p1' and 'p2' are the PASS arguments of both procedures (if applicable). */
1179 count_types_test (gfc_formal_arglist
*f1
, gfc_formal_arglist
*f2
,
1180 const char *p1
, const char *p2
)
1182 int ac1
, ac2
, i
, j
, k
, n1
;
1183 gfc_formal_arglist
*f
;
1196 for (f
= f1
; f
; f
= f
->next
)
1199 /* Build an array of integers that gives the same integer to
1200 arguments of the same type/rank. */
1201 arg
= XCNEWVEC (arginfo
, n1
);
1204 for (i
= 0; i
< n1
; i
++, f
= f
->next
)
1207 arg
[i
].sym
= f
->sym
;
1212 for (i
= 0; i
< n1
; i
++)
1214 if (arg
[i
].flag
!= -1)
1217 if (arg
[i
].sym
&& (arg
[i
].sym
->attr
.optional
1218 || (p1
&& strcmp (arg
[i
].sym
->name
, p1
) == 0)))
1219 continue; /* Skip OPTIONAL and PASS arguments. */
1223 /* Find other non-optional, non-pass arguments of the same type/rank. */
1224 for (j
= i
+ 1; j
< n1
; j
++)
1225 if ((arg
[j
].sym
== NULL
1226 || !(arg
[j
].sym
->attr
.optional
1227 || (p1
&& strcmp (arg
[j
].sym
->name
, p1
) == 0)))
1228 && (compare_type_rank_if (arg
[i
].sym
, arg
[j
].sym
)
1229 || compare_type_rank_if (arg
[j
].sym
, arg
[i
].sym
)))
1235 /* Now loop over each distinct type found in f1. */
1239 for (i
= 0; i
< n1
; i
++)
1241 if (arg
[i
].flag
!= k
)
1245 for (j
= i
+ 1; j
< n1
; j
++)
1246 if (arg
[j
].flag
== k
)
1249 /* Count the number of non-pass arguments in f2 with that type,
1250 including those that are optional. */
1253 for (f
= f2
; f
; f
= f
->next
)
1254 if ((!p2
|| strcmp (f
->sym
->name
, p2
) != 0)
1255 && (compare_type_rank_if (arg
[i
].sym
, f
->sym
)
1256 || compare_type_rank_if (f
->sym
, arg
[i
].sym
)))
1274 /* Returns true if two dummy arguments are distinguishable due to their POINTER
1275 and ALLOCATABLE attributes according to F2018 section 15.4.3.4.5 (3).
1276 The function is asymmetric wrt to the arguments s1 and s2 and should always
1277 be called twice (with flipped arguments in the second call). */
1280 compare_ptr_alloc(gfc_symbol
*s1
, gfc_symbol
*s2
)
1282 /* Is s1 allocatable? */
1283 const bool a1
= s1
->ts
.type
== BT_CLASS
?
1284 CLASS_DATA(s1
)->attr
.allocatable
: s1
->attr
.allocatable
;
1285 /* Is s2 a pointer? */
1286 const bool p2
= s2
->ts
.type
== BT_CLASS
?
1287 CLASS_DATA(s2
)->attr
.class_pointer
: s2
->attr
.pointer
;
1288 return a1
&& p2
&& (s2
->attr
.intent
!= INTENT_IN
);
1292 /* Perform the correspondence test in rule (3) of F08:C1215.
1293 Returns zero if no argument is found that satisfies this rule,
1294 nonzero otherwise. 'p1' and 'p2' are the PASS arguments of both procedures
1297 This test is also not symmetric in f1 and f2 and must be called
1298 twice. This test finds problems caused by sorting the actual
1299 argument list with keywords. For example:
1303 INTEGER :: A ; REAL :: B
1307 INTEGER :: A ; REAL :: B
1311 At this point, 'CALL FOO(A=1, B=1.0)' is ambiguous. */
1314 generic_correspondence (gfc_formal_arglist
*f1
, gfc_formal_arglist
*f2
,
1315 const char *p1
, const char *p2
)
1317 gfc_formal_arglist
*f2_save
, *g
;
1324 if (!f1
->sym
|| f1
->sym
->attr
.optional
)
1327 if (p1
&& strcmp (f1
->sym
->name
, p1
) == 0)
1329 if (f2
&& p2
&& strcmp (f2
->sym
->name
, p2
) == 0)
1332 if (f2
!= NULL
&& (compare_type_rank (f1
->sym
, f2
->sym
)
1333 || compare_type_rank (f2
->sym
, f1
->sym
))
1334 && !((gfc_option
.allow_std
& GFC_STD_F2008
)
1335 && (compare_ptr_alloc(f1
->sym
, f2
->sym
)
1336 || compare_ptr_alloc(f2
->sym
, f1
->sym
))))
1339 /* Now search for a disambiguating keyword argument starting at
1340 the current non-match. */
1341 for (g
= f1
; g
; g
= g
->next
)
1343 if (g
->sym
->attr
.optional
|| (p1
&& strcmp (g
->sym
->name
, p1
) == 0))
1346 sym
= find_keyword_arg (g
->sym
->name
, f2_save
);
1347 if (sym
== NULL
|| !compare_type_rank (g
->sym
, sym
)
1348 || ((gfc_option
.allow_std
& GFC_STD_F2008
)
1349 && (compare_ptr_alloc(sym
, g
->sym
)
1350 || compare_ptr_alloc(g
->sym
, sym
))))
1366 symbol_rank (gfc_symbol
*sym
)
1368 gfc_array_spec
*as
= NULL
;
1370 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
1371 as
= CLASS_DATA (sym
)->as
;
1375 return as
? as
->rank
: 0;
1379 /* Check if the characteristics of two dummy arguments match,
1383 gfc_check_dummy_characteristics (gfc_symbol
*s1
, gfc_symbol
*s2
,
1384 bool type_must_agree
, char *errmsg
,
1387 if (s1
== NULL
|| s2
== NULL
)
1388 return s1
== s2
? true : false;
1390 if (s1
->attr
.proc
== PROC_ST_FUNCTION
|| s2
->attr
.proc
== PROC_ST_FUNCTION
)
1392 strncpy (errmsg
, "Statement function", err_len
);
1396 /* Check type and rank. */
1397 if (type_must_agree
)
1399 if (!compare_type_characteristics (s1
, s2
)
1400 || !compare_type_characteristics (s2
, s1
))
1402 snprintf (errmsg
, err_len
, "Type mismatch in argument '%s' (%s/%s)",
1403 s1
->name
, gfc_dummy_typename (&s1
->ts
),
1404 gfc_dummy_typename (&s2
->ts
));
1407 if (!compare_rank (s1
, s2
))
1409 snprintf (errmsg
, err_len
, "Rank mismatch in argument '%s' (%i/%i)",
1410 s1
->name
, symbol_rank (s1
), symbol_rank (s2
));
1415 /* A lot of information is missing for artificially generated
1416 formal arguments, let's not look into that. */
1418 if (!s1
->attr
.artificial
&& !s2
->attr
.artificial
)
1421 if (s1
->attr
.intent
!= s2
->attr
.intent
)
1423 snprintf (errmsg
, err_len
, "INTENT mismatch in argument '%s'",
1428 /* Check OPTIONAL attribute. */
1429 if (s1
->attr
.optional
!= s2
->attr
.optional
)
1431 snprintf (errmsg
, err_len
, "OPTIONAL mismatch in argument '%s'",
1436 /* Check ALLOCATABLE attribute. */
1437 if (s1
->attr
.allocatable
!= s2
->attr
.allocatable
)
1439 snprintf (errmsg
, err_len
, "ALLOCATABLE mismatch in argument '%s'",
1444 /* Check POINTER attribute. */
1445 if (s1
->attr
.pointer
!= s2
->attr
.pointer
)
1447 snprintf (errmsg
, err_len
, "POINTER mismatch in argument '%s'",
1452 /* Check TARGET attribute. */
1453 if (s1
->attr
.target
!= s2
->attr
.target
)
1455 snprintf (errmsg
, err_len
, "TARGET mismatch in argument '%s'",
1460 /* Check ASYNCHRONOUS attribute. */
1461 if (s1
->attr
.asynchronous
!= s2
->attr
.asynchronous
)
1463 snprintf (errmsg
, err_len
, "ASYNCHRONOUS mismatch in argument '%s'",
1468 /* Check CONTIGUOUS attribute. */
1469 if (s1
->attr
.contiguous
!= s2
->attr
.contiguous
)
1471 snprintf (errmsg
, err_len
, "CONTIGUOUS mismatch in argument '%s'",
1476 /* Check VALUE attribute. */
1477 if (s1
->attr
.value
!= s2
->attr
.value
)
1479 snprintf (errmsg
, err_len
, "VALUE mismatch in argument '%s'",
1484 /* Check VOLATILE attribute. */
1485 if (s1
->attr
.volatile_
!= s2
->attr
.volatile_
)
1487 snprintf (errmsg
, err_len
, "VOLATILE mismatch in argument '%s'",
1493 /* Check interface of dummy procedures. */
1494 if (s1
->attr
.flavor
== FL_PROCEDURE
)
1497 if (!gfc_compare_interfaces (s1
, s2
, s2
->name
, 0, 1, err
, sizeof(err
),
1500 snprintf (errmsg
, err_len
, "Interface mismatch in dummy procedure "
1501 "'%s': %s", s1
->name
, err
);
1506 /* Check string length. */
1507 if (s1
->ts
.type
== BT_CHARACTER
1508 && s1
->ts
.u
.cl
&& s1
->ts
.u
.cl
->length
1509 && s2
->ts
.u
.cl
&& s2
->ts
.u
.cl
->length
)
1511 int compval
= gfc_dep_compare_expr (s1
->ts
.u
.cl
->length
,
1512 s2
->ts
.u
.cl
->length
);
1518 snprintf (errmsg
, err_len
, "Character length mismatch "
1519 "in argument '%s'", s1
->name
);
1523 /* FIXME: Implement a warning for this case.
1524 gfc_warning (0, "Possible character length mismatch in argument %qs",
1532 gfc_internal_error ("check_dummy_characteristics: Unexpected result "
1533 "%i of gfc_dep_compare_expr", compval
);
1538 /* Check array shape. */
1539 if (s1
->as
&& s2
->as
)
1542 gfc_expr
*shape1
, *shape2
;
1544 /* Sometimes the ambiguity between deferred shape and assumed shape
1545 does not get resolved in module procedures, where the only explicit
1546 declaration of the dummy is in the interface. */
1547 if (s1
->ns
->proc_name
&& s1
->ns
->proc_name
->attr
.module_procedure
1548 && s1
->as
->type
== AS_ASSUMED_SHAPE
1549 && s2
->as
->type
== AS_DEFERRED
)
1551 s2
->as
->type
= AS_ASSUMED_SHAPE
;
1552 for (i
= 0; i
< s2
->as
->rank
; i
++)
1553 if (s1
->as
->lower
[i
] != NULL
)
1554 s2
->as
->lower
[i
] = gfc_copy_expr (s1
->as
->lower
[i
]);
1557 if (s1
->as
->type
!= s2
->as
->type
)
1559 snprintf (errmsg
, err_len
, "Shape mismatch in argument '%s'",
1564 if (s1
->as
->corank
!= s2
->as
->corank
)
1566 snprintf (errmsg
, err_len
, "Corank mismatch in argument '%s' (%i/%i)",
1567 s1
->name
, s1
->as
->corank
, s2
->as
->corank
);
1571 if (s1
->as
->type
== AS_EXPLICIT
)
1572 for (i
= 0; i
< s1
->as
->rank
+ MAX (0, s1
->as
->corank
-1); i
++)
1574 shape1
= gfc_subtract (gfc_copy_expr (s1
->as
->upper
[i
]),
1575 gfc_copy_expr (s1
->as
->lower
[i
]));
1576 shape2
= gfc_subtract (gfc_copy_expr (s2
->as
->upper
[i
]),
1577 gfc_copy_expr (s2
->as
->lower
[i
]));
1578 compval
= gfc_dep_compare_expr (shape1
, shape2
);
1579 gfc_free_expr (shape1
);
1580 gfc_free_expr (shape2
);
1586 if (i
< s1
->as
->rank
)
1587 snprintf (errmsg
, err_len
, "Shape mismatch in dimension %i of"
1588 " argument '%s'", i
+ 1, s1
->name
);
1590 snprintf (errmsg
, err_len
, "Shape mismatch in codimension %i "
1591 "of argument '%s'", i
- s1
->as
->rank
+ 1, s1
->name
);
1595 /* FIXME: Implement a warning for this case.
1596 gfc_warning (0, "Possible shape mismatch in argument %qs",
1604 gfc_internal_error ("check_dummy_characteristics: Unexpected "
1605 "result %i of gfc_dep_compare_expr",
1616 /* Check if the characteristics of two function results match,
1620 gfc_check_result_characteristics (gfc_symbol
*s1
, gfc_symbol
*s2
,
1621 char *errmsg
, int err_len
)
1623 gfc_symbol
*r1
, *r2
;
1625 if (s1
->ts
.interface
&& s1
->ts
.interface
->result
)
1626 r1
= s1
->ts
.interface
->result
;
1628 r1
= s1
->result
? s1
->result
: s1
;
1630 if (s2
->ts
.interface
&& s2
->ts
.interface
->result
)
1631 r2
= s2
->ts
.interface
->result
;
1633 r2
= s2
->result
? s2
->result
: s2
;
1635 if (r1
->ts
.type
== BT_UNKNOWN
)
1638 /* Check type and rank. */
1639 if (!compare_type_characteristics (r1
, r2
))
1641 snprintf (errmsg
, err_len
, "Type mismatch in function result (%s/%s)",
1642 gfc_typename (&r1
->ts
), gfc_typename (&r2
->ts
));
1645 if (!compare_rank (r1
, r2
))
1647 snprintf (errmsg
, err_len
, "Rank mismatch in function result (%i/%i)",
1648 symbol_rank (r1
), symbol_rank (r2
));
1652 /* Check ALLOCATABLE attribute. */
1653 if (r1
->attr
.allocatable
!= r2
->attr
.allocatable
)
1655 snprintf (errmsg
, err_len
, "ALLOCATABLE attribute mismatch in "
1660 /* Check POINTER attribute. */
1661 if (r1
->attr
.pointer
!= r2
->attr
.pointer
)
1663 snprintf (errmsg
, err_len
, "POINTER attribute mismatch in "
1668 /* Check CONTIGUOUS attribute. */
1669 if (r1
->attr
.contiguous
!= r2
->attr
.contiguous
)
1671 snprintf (errmsg
, err_len
, "CONTIGUOUS attribute mismatch in "
1676 /* Check PROCEDURE POINTER attribute. */
1677 if (r1
!= s1
&& r1
->attr
.proc_pointer
!= r2
->attr
.proc_pointer
)
1679 snprintf (errmsg
, err_len
, "PROCEDURE POINTER mismatch in "
1684 /* Check string length. */
1685 if (r1
->ts
.type
== BT_CHARACTER
&& r1
->ts
.u
.cl
&& r2
->ts
.u
.cl
)
1687 if (r1
->ts
.deferred
!= r2
->ts
.deferred
)
1689 snprintf (errmsg
, err_len
, "Character length mismatch "
1690 "in function result");
1694 if (r1
->ts
.u
.cl
->length
&& r2
->ts
.u
.cl
->length
)
1696 int compval
= gfc_dep_compare_expr (r1
->ts
.u
.cl
->length
,
1697 r2
->ts
.u
.cl
->length
);
1703 snprintf (errmsg
, err_len
, "Character length mismatch "
1704 "in function result");
1708 if (r1
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
1710 snprintf (errmsg
, err_len
,
1711 "Function declared with a non-constant character "
1712 "length referenced with a constant length");
1715 else if (r2
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
1717 snprintf (errmsg
, err_len
,
1718 "Function declared with a constant character "
1719 "length referenced with a non-constant length");
1722 /* Warn if length expression types are different, except for
1723 possibly false positives where complex expressions might have
1725 else if ((r1
->ts
.u
.cl
->length
->expr_type
1726 != r2
->ts
.u
.cl
->length
->expr_type
)
1727 && (r1
->ts
.u
.cl
->length
->expr_type
!= EXPR_OP
1728 || r2
->ts
.u
.cl
->length
->expr_type
!= EXPR_OP
))
1729 gfc_warning (0, "Possible character length mismatch in "
1730 "function result between %L and %L",
1731 &r1
->declared_at
, &r2
->declared_at
);
1738 gfc_internal_error ("check_result_characteristics (1): Unexpected "
1739 "result %i of gfc_dep_compare_expr", compval
);
1745 /* Check array shape. */
1746 if (!r1
->attr
.allocatable
&& !r1
->attr
.pointer
&& r1
->as
&& r2
->as
)
1749 gfc_expr
*shape1
, *shape2
;
1751 if (r1
->as
->type
!= r2
->as
->type
)
1753 snprintf (errmsg
, err_len
, "Shape mismatch in function result");
1757 if (r1
->as
->type
== AS_EXPLICIT
)
1758 for (i
= 0; i
< r1
->as
->rank
+ r1
->as
->corank
; i
++)
1760 shape1
= gfc_subtract (gfc_copy_expr (r1
->as
->upper
[i
]),
1761 gfc_copy_expr (r1
->as
->lower
[i
]));
1762 shape2
= gfc_subtract (gfc_copy_expr (r2
->as
->upper
[i
]),
1763 gfc_copy_expr (r2
->as
->lower
[i
]));
1764 compval
= gfc_dep_compare_expr (shape1
, shape2
);
1765 gfc_free_expr (shape1
);
1766 gfc_free_expr (shape2
);
1772 snprintf (errmsg
, err_len
, "Shape mismatch in dimension %i of "
1773 "function result", i
+ 1);
1777 /* FIXME: Implement a warning for this case.
1778 gfc_warning (0, "Possible shape mismatch in return value");*/
1785 gfc_internal_error ("check_result_characteristics (2): "
1786 "Unexpected result %i of "
1787 "gfc_dep_compare_expr", compval
);
1797 /* 'Compare' two formal interfaces associated with a pair of symbols.
1798 We return true if there exists an actual argument list that
1799 would be ambiguous between the two interfaces, zero otherwise.
1800 'strict_flag' specifies whether all the characteristics are
1801 required to match, which is not the case for ambiguity checks.
1802 'p1' and 'p2' are the PASS arguments of both procedures (if applicable). */
1805 gfc_compare_interfaces (gfc_symbol
*s1
, gfc_symbol
*s2
, const char *name2
,
1806 int generic_flag
, int strict_flag
,
1807 char *errmsg
, int err_len
,
1808 const char *p1
, const char *p2
,
1809 bool *bad_result_characteristics
)
1811 gfc_formal_arglist
*f1
, *f2
;
1813 gcc_assert (name2
!= NULL
);
1815 if (bad_result_characteristics
)
1816 *bad_result_characteristics
= false;
1818 if (s1
->attr
.function
&& (s2
->attr
.subroutine
1819 || (!s2
->attr
.function
&& s2
->ts
.type
== BT_UNKNOWN
1820 && gfc_get_default_type (name2
, s2
->ns
)->type
== BT_UNKNOWN
)))
1823 snprintf (errmsg
, err_len
, "'%s' is not a function", name2
);
1827 if (s1
->attr
.subroutine
&& s2
->attr
.function
)
1830 snprintf (errmsg
, err_len
, "'%s' is not a subroutine", name2
);
1834 if (s2
->attr
.subroutine
&& s1
->attr
.flavor
== FL_VARIABLE
)
1837 snprintf (errmsg
, err_len
, "subroutine proc pointer '%s' passed "
1838 "to dummy variable '%s'", name2
, s1
->name
);
1842 /* Do strict checks on all characteristics
1843 (for dummy procedures and procedure pointer assignments). */
1844 if (!generic_flag
&& strict_flag
)
1846 if (s1
->attr
.function
&& s2
->attr
.function
)
1848 /* If both are functions, check result characteristics. */
1849 if (!gfc_check_result_characteristics (s1
, s2
, errmsg
, err_len
)
1850 || !gfc_check_result_characteristics (s2
, s1
, errmsg
, err_len
))
1852 if (bad_result_characteristics
)
1853 *bad_result_characteristics
= true;
1858 if (s1
->attr
.pure
&& !s2
->attr
.pure
)
1860 snprintf (errmsg
, err_len
, "Mismatch in PURE attribute");
1863 if (s1
->attr
.elemental
&& !s2
->attr
.elemental
)
1865 snprintf (errmsg
, err_len
, "Mismatch in ELEMENTAL attribute");
1870 if (s1
->attr
.if_source
== IFSRC_UNKNOWN
1871 || s2
->attr
.if_source
== IFSRC_UNKNOWN
)
1874 f1
= gfc_sym_get_dummy_args (s1
);
1875 f2
= gfc_sym_get_dummy_args (s2
);
1877 /* Special case: No arguments. */
1878 if (f1
== NULL
&& f2
== NULL
)
1883 if (count_types_test (f1
, f2
, p1
, p2
)
1884 || count_types_test (f2
, f1
, p2
, p1
))
1887 /* Special case: alternate returns. If both f1->sym and f2->sym are
1888 NULL, then the leading formal arguments are alternate returns.
1889 The previous conditional should catch argument lists with
1890 different number of argument. */
1891 if (f1
&& f1
->sym
== NULL
&& f2
&& f2
->sym
== NULL
)
1894 if (generic_correspondence (f1
, f2
, p1
, p2
)
1895 || generic_correspondence (f2
, f1
, p2
, p1
))
1899 /* Perform the abbreviated correspondence test for operators (the
1900 arguments cannot be optional and are always ordered correctly).
1901 This is also done when comparing interfaces for dummy procedures and in
1902 procedure pointer assignments. */
1904 for (; f1
|| f2
; f1
= f1
->next
, f2
= f2
->next
)
1906 /* Check existence. */
1907 if (f1
== NULL
|| f2
== NULL
)
1910 snprintf (errmsg
, err_len
, "'%s' has the wrong number of "
1911 "arguments", name2
);
1917 /* Check all characteristics. */
1918 if (!gfc_check_dummy_characteristics (f1
->sym
, f2
->sym
, true,
1924 /* Operators: Only check type and rank of arguments. */
1925 if (!compare_type (f2
->sym
, f1
->sym
))
1928 snprintf (errmsg
, err_len
, "Type mismatch in argument '%s' "
1929 "(%s/%s)", f1
->sym
->name
,
1930 gfc_typename (&f1
->sym
->ts
),
1931 gfc_typename (&f2
->sym
->ts
));
1934 if (!compare_rank (f2
->sym
, f1
->sym
))
1937 snprintf (errmsg
, err_len
, "Rank mismatch in argument "
1938 "'%s' (%i/%i)", f1
->sym
->name
,
1939 symbol_rank (f1
->sym
), symbol_rank (f2
->sym
));
1942 if ((gfc_option
.allow_std
& GFC_STD_F2008
)
1943 && (compare_ptr_alloc(f1
->sym
, f2
->sym
)
1944 || compare_ptr_alloc(f2
->sym
, f1
->sym
)))
1947 snprintf (errmsg
, err_len
, "Mismatching POINTER/ALLOCATABLE "
1948 "attribute in argument '%s' ", f1
->sym
->name
);
1958 /* Given a pointer to an interface pointer, remove duplicate
1959 interfaces and make sure that all symbols are either functions
1960 or subroutines, and all of the same kind. Returns true if
1961 something goes wrong. */
1964 check_interface0 (gfc_interface
*p
, const char *interface_name
)
1966 gfc_interface
*psave
, *q
, *qlast
;
1969 for (; p
; p
= p
->next
)
1971 /* Make sure all symbols in the interface have been defined as
1972 functions or subroutines. */
1973 if (((!p
->sym
->attr
.function
&& !p
->sym
->attr
.subroutine
)
1974 || !p
->sym
->attr
.if_source
)
1975 && !gfc_fl_struct (p
->sym
->attr
.flavor
))
1978 = gfc_lookup_function_fuzzy (p
->sym
->name
, p
->sym
->ns
->sym_root
);
1980 if (p
->sym
->attr
.external
)
1982 gfc_error ("Procedure %qs in %s at %L has no explicit interface"
1983 "; did you mean %qs?",
1984 p
->sym
->name
, interface_name
, &p
->sym
->declared_at
,
1987 gfc_error ("Procedure %qs in %s at %L has no explicit interface",
1988 p
->sym
->name
, interface_name
, &p
->sym
->declared_at
);
1991 gfc_error ("Procedure %qs in %s at %L is neither function nor "
1992 "subroutine; did you mean %qs?", p
->sym
->name
,
1993 interface_name
, &p
->sym
->declared_at
, guessed
);
1995 gfc_error ("Procedure %qs in %s at %L is neither function nor "
1996 "subroutine", p
->sym
->name
, interface_name
,
1997 &p
->sym
->declared_at
);
2001 /* Verify that procedures are either all SUBROUTINEs or all FUNCTIONs. */
2002 if ((psave
->sym
->attr
.function
&& !p
->sym
->attr
.function
2003 && !gfc_fl_struct (p
->sym
->attr
.flavor
))
2004 || (psave
->sym
->attr
.subroutine
&& !p
->sym
->attr
.subroutine
))
2006 if (!gfc_fl_struct (p
->sym
->attr
.flavor
))
2007 gfc_error ("In %s at %L procedures must be either all SUBROUTINEs"
2008 " or all FUNCTIONs", interface_name
,
2009 &p
->sym
->declared_at
);
2010 else if (p
->sym
->attr
.flavor
== FL_DERIVED
)
2011 gfc_error ("In %s at %L procedures must be all FUNCTIONs as the "
2012 "generic name is also the name of a derived type",
2013 interface_name
, &p
->sym
->declared_at
);
2017 /* F2003, C1207. F2008, C1207. */
2018 if (p
->sym
->attr
.proc
== PROC_INTERNAL
2019 && !gfc_notify_std (GFC_STD_F2008
, "Internal procedure "
2020 "%qs in %s at %L", p
->sym
->name
,
2021 interface_name
, &p
->sym
->declared_at
))
2026 /* Remove duplicate interfaces in this interface list. */
2027 for (; p
; p
= p
->next
)
2031 for (q
= p
->next
; q
;)
2033 if (p
->sym
!= q
->sym
)
2040 /* Duplicate interface. */
2041 qlast
->next
= q
->next
;
2052 /* Check lists of interfaces to make sure that no two interfaces are
2053 ambiguous. Duplicate interfaces (from the same symbol) are OK here. */
2056 check_interface1 (gfc_interface
*p
, gfc_interface
*q0
,
2057 int generic_flag
, const char *interface_name
,
2061 for (; p
; p
= p
->next
)
2062 for (q
= q0
; q
; q
= q
->next
)
2064 if (p
->sym
== q
->sym
)
2065 continue; /* Duplicates OK here. */
2067 if (p
->sym
->name
== q
->sym
->name
&& p
->sym
->module
== q
->sym
->module
)
2070 if (!gfc_fl_struct (p
->sym
->attr
.flavor
)
2071 && !gfc_fl_struct (q
->sym
->attr
.flavor
)
2072 && gfc_compare_interfaces (p
->sym
, q
->sym
, q
->sym
->name
,
2073 generic_flag
, 0, NULL
, 0, NULL
, NULL
))
2076 gfc_error ("Ambiguous interfaces in %s for %qs at %L "
2077 "and %qs at %L", interface_name
,
2078 q
->sym
->name
, &q
->sym
->declared_at
,
2079 p
->sym
->name
, &p
->sym
->declared_at
);
2080 else if (!p
->sym
->attr
.use_assoc
&& q
->sym
->attr
.use_assoc
)
2081 gfc_warning (0, "Ambiguous interfaces in %s for %qs at %L "
2082 "and %qs at %L", interface_name
,
2083 q
->sym
->name
, &q
->sym
->declared_at
,
2084 p
->sym
->name
, &p
->sym
->declared_at
);
2086 gfc_warning (0, "Although not referenced, %qs has ambiguous "
2087 "interfaces at %L", interface_name
, &p
->where
);
2095 /* Check the generic and operator interfaces of symbols to make sure
2096 that none of the interfaces conflict. The check has to be done
2097 after all of the symbols are actually loaded. */
2100 check_sym_interfaces (gfc_symbol
*sym
)
2102 /* Provide sufficient space to hold "generic interface 'symbol.symbol'". */
2103 char interface_name
[2*GFC_MAX_SYMBOL_LEN
+2 + sizeof("generic interface ''")];
2106 if (sym
->ns
!= gfc_current_ns
)
2109 if (sym
->generic
!= NULL
)
2111 size_t len
= strlen (sym
->name
) + sizeof("generic interface ''");
2112 gcc_assert (len
< sizeof (interface_name
));
2113 sprintf (interface_name
, "generic interface '%s'", sym
->name
);
2114 if (check_interface0 (sym
->generic
, interface_name
))
2117 for (p
= sym
->generic
; p
; p
= p
->next
)
2119 if (p
->sym
->attr
.mod_proc
2120 && !p
->sym
->attr
.module_procedure
2121 && (p
->sym
->attr
.if_source
!= IFSRC_DECL
2122 || p
->sym
->attr
.procedure
))
2124 gfc_error ("%qs at %L is not a module procedure",
2125 p
->sym
->name
, &p
->where
);
2130 /* Originally, this test was applied to host interfaces too;
2131 this is incorrect since host associated symbols, from any
2132 source, cannot be ambiguous with local symbols. */
2133 check_interface1 (sym
->generic
, sym
->generic
, 1, interface_name
,
2134 sym
->attr
.referenced
|| !sym
->attr
.use_assoc
);
2140 check_uop_interfaces (gfc_user_op
*uop
)
2142 char interface_name
[GFC_MAX_SYMBOL_LEN
+ sizeof("operator interface ''")];
2146 sprintf (interface_name
, "operator interface '%s'", uop
->name
);
2147 if (check_interface0 (uop
->op
, interface_name
))
2150 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
2152 uop2
= gfc_find_uop (uop
->name
, ns
);
2156 check_interface1 (uop
->op
, uop2
->op
, 0,
2157 interface_name
, true);
2161 /* Given an intrinsic op, return an equivalent op if one exists,
2162 or INTRINSIC_NONE otherwise. */
2165 gfc_equivalent_op (gfc_intrinsic_op op
)
2170 return INTRINSIC_EQ_OS
;
2172 case INTRINSIC_EQ_OS
:
2173 return INTRINSIC_EQ
;
2176 return INTRINSIC_NE_OS
;
2178 case INTRINSIC_NE_OS
:
2179 return INTRINSIC_NE
;
2182 return INTRINSIC_GT_OS
;
2184 case INTRINSIC_GT_OS
:
2185 return INTRINSIC_GT
;
2188 return INTRINSIC_GE_OS
;
2190 case INTRINSIC_GE_OS
:
2191 return INTRINSIC_GE
;
2194 return INTRINSIC_LT_OS
;
2196 case INTRINSIC_LT_OS
:
2197 return INTRINSIC_LT
;
2200 return INTRINSIC_LE_OS
;
2202 case INTRINSIC_LE_OS
:
2203 return INTRINSIC_LE
;
2206 return INTRINSIC_NONE
;
2210 /* For the namespace, check generic, user operator and intrinsic
2211 operator interfaces for consistency and to remove duplicate
2212 interfaces. We traverse the whole namespace, counting on the fact
2213 that most symbols will not have generic or operator interfaces. */
2216 gfc_check_interfaces (gfc_namespace
*ns
)
2218 gfc_namespace
*old_ns
, *ns2
;
2219 char interface_name
[GFC_MAX_SYMBOL_LEN
+ sizeof("intrinsic '' operator")];
2222 old_ns
= gfc_current_ns
;
2223 gfc_current_ns
= ns
;
2225 gfc_traverse_ns (ns
, check_sym_interfaces
);
2227 gfc_traverse_user_op (ns
, check_uop_interfaces
);
2229 for (i
= GFC_INTRINSIC_BEGIN
; i
!= GFC_INTRINSIC_END
; i
++)
2231 if (i
== INTRINSIC_USER
)
2234 if (i
== INTRINSIC_ASSIGN
)
2235 strcpy (interface_name
, "intrinsic assignment operator");
2237 sprintf (interface_name
, "intrinsic '%s' operator",
2238 gfc_op2string ((gfc_intrinsic_op
) i
));
2240 if (check_interface0 (ns
->op
[i
], interface_name
))
2244 gfc_check_operator_interface (ns
->op
[i
]->sym
, (gfc_intrinsic_op
) i
,
2247 for (ns2
= ns
; ns2
; ns2
= ns2
->parent
)
2249 gfc_intrinsic_op other_op
;
2251 if (check_interface1 (ns
->op
[i
], ns2
->op
[i
], 0,
2252 interface_name
, true))
2255 /* i should be gfc_intrinsic_op, but has to be int with this cast
2256 here for stupid C++ compatibility rules. */
2257 other_op
= gfc_equivalent_op ((gfc_intrinsic_op
) i
);
2258 if (other_op
!= INTRINSIC_NONE
2259 && check_interface1 (ns
->op
[i
], ns2
->op
[other_op
],
2260 0, interface_name
, true))
2266 gfc_current_ns
= old_ns
;
2270 /* Given a symbol of a formal argument list and an expression, if the
2271 formal argument is allocatable, check that the actual argument is
2272 allocatable. Returns true if compatible, zero if not compatible. */
2275 compare_allocatable (gfc_symbol
*formal
, gfc_expr
*actual
)
2277 if (formal
->attr
.allocatable
2278 || (formal
->ts
.type
== BT_CLASS
&& CLASS_DATA (formal
)->attr
.allocatable
))
2280 symbol_attribute attr
= gfc_expr_attr (actual
);
2281 if (actual
->ts
.type
== BT_CLASS
&& !attr
.class_ok
)
2283 else if (!attr
.allocatable
)
2291 /* Given a symbol of a formal argument list and an expression, if the
2292 formal argument is a pointer, see if the actual argument is a
2293 pointer. Returns nonzero if compatible, zero if not compatible. */
2296 compare_pointer (gfc_symbol
*formal
, gfc_expr
*actual
)
2298 symbol_attribute attr
;
2300 if (formal
->attr
.pointer
2301 || (formal
->ts
.type
== BT_CLASS
&& CLASS_DATA (formal
)
2302 && CLASS_DATA (formal
)->attr
.class_pointer
))
2304 attr
= gfc_expr_attr (actual
);
2306 /* Fortran 2008 allows non-pointer actual arguments. */
2307 if (!attr
.pointer
&& attr
.target
&& formal
->attr
.intent
== INTENT_IN
)
2318 /* Emit clear error messages for rank mismatch. */
2321 argument_rank_mismatch (const char *name
, locus
*where
,
2322 int rank1
, int rank2
, locus
*where_formal
)
2325 /* TS 29113, C407b. */
2326 if (where_formal
== NULL
)
2329 gfc_error ("The assumed-rank array at %L requires that the dummy "
2330 "argument %qs has assumed-rank", where
, name
);
2331 else if (rank1
== 0)
2332 gfc_error_opt (0, "Rank mismatch in argument %qs "
2333 "at %L (scalar and rank-%d)", name
, where
, rank2
);
2334 else if (rank2
== 0)
2335 gfc_error_opt (0, "Rank mismatch in argument %qs "
2336 "at %L (rank-%d and scalar)", name
, where
, rank1
);
2338 gfc_error_opt (0, "Rank mismatch in argument %qs "
2339 "at %L (rank-%d and rank-%d)", name
, where
, rank1
,
2345 /* This is an assumed rank-actual passed to a function without
2346 an explicit interface, which is already diagnosed in
2347 gfc_procedure_use. */
2350 gfc_error_opt (0, "Rank mismatch between actual argument at %L "
2351 "and actual argument at %L (scalar and rank-%d)",
2352 where
, where_formal
, rank2
);
2353 else if (rank2
== 0)
2354 gfc_error_opt (0, "Rank mismatch between actual argument at %L "
2355 "and actual argument at %L (rank-%d and scalar)",
2356 where
, where_formal
, rank1
);
2358 gfc_error_opt (0, "Rank mismatch between actual argument at %L "
2359 "and actual argument at %L (rank-%d and rank-%d)", where
,
2360 where_formal
, rank1
, rank2
);
2365 /* Under certain conditions, a scalar actual argument can be passed
2366 to an array dummy argument - see F2018, 15.5.2.4, paragraph 14.
2367 This function returns true for these conditions so that an error
2368 or warning for this can be suppressed later. Always return false
2369 for expressions with rank > 0. */
2372 maybe_dummy_array_arg (gfc_expr
*e
)
2376 bool array_pointer
= false;
2377 bool assumed_shape
= false;
2378 bool scalar_ref
= true;
2383 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
== 1)
2386 /* If this comes from a constructor, it has been an array element
2389 if (e
->expr_type
== EXPR_CONSTANT
)
2390 return e
->from_constructor
;
2392 if (e
->expr_type
!= EXPR_VARIABLE
)
2395 s
= e
->symtree
->n
.sym
;
2397 if (s
->attr
.dimension
)
2400 array_pointer
= s
->attr
.pointer
;
2403 if (s
->as
&& s
->as
->type
== AS_ASSUMED_SHAPE
)
2404 assumed_shape
= true;
2406 for (ref
=e
->ref
; ref
; ref
=ref
->next
)
2408 if (ref
->type
== REF_COMPONENT
)
2410 symbol_attribute
*attr
;
2411 attr
= &ref
->u
.c
.component
->attr
;
2412 if (attr
->dimension
)
2414 array_pointer
= attr
->pointer
;
2415 assumed_shape
= false;
2423 return !(scalar_ref
|| array_pointer
|| assumed_shape
);
2426 /* Given a symbol of a formal argument list and an expression, see if
2427 the two are compatible as arguments. Returns true if
2428 compatible, false if not compatible. */
2431 compare_parameter (gfc_symbol
*formal
, gfc_expr
*actual
,
2432 int ranks_must_agree
, int is_elemental
, locus
*where
)
2435 bool rank_check
, is_pointer
;
2438 bool codimension
= false;
2439 gfc_array_spec
*formal_as
;
2440 const char *actual_name
;
2442 /* If the formal arg has type BT_VOID, it's to one of the iso_c_binding
2443 procs c_f_pointer or c_f_procpointer, and we need to accept most
2444 pointers the user could give us. This should allow that. */
2445 if (formal
->ts
.type
== BT_VOID
)
2448 if (formal
->ts
.type
== BT_DERIVED
2449 && formal
->ts
.u
.derived
&& formal
->ts
.u
.derived
->ts
.is_iso_c
2450 && actual
->ts
.type
== BT_DERIVED
2451 && actual
->ts
.u
.derived
&& actual
->ts
.u
.derived
->ts
.is_iso_c
)
2453 if (formal
->ts
.u
.derived
->intmod_sym_id
2454 != actual
->ts
.u
.derived
->intmod_sym_id
)
2457 if (ranks_must_agree
2458 && symbol_rank (formal
) != actual
->rank
2459 && symbol_rank (formal
) != -1)
2462 argument_rank_mismatch (formal
->name
, &actual
->where
,
2463 symbol_rank (formal
), actual
->rank
,
2470 if (formal
->ts
.type
== BT_CLASS
&& actual
->ts
.type
== BT_DERIVED
)
2471 /* Make sure the vtab symbol is present when
2472 the module variables are generated. */
2473 gfc_find_derived_vtab (actual
->ts
.u
.derived
);
2475 if (actual
->ts
.type
== BT_PROCEDURE
)
2477 gfc_symbol
*act_sym
= actual
->symtree
->n
.sym
;
2479 if (formal
->attr
.flavor
!= FL_PROCEDURE
&& !act_sym
->ts
.interface
)
2482 gfc_error ("Invalid procedure argument at %L", &actual
->where
);
2485 else if (act_sym
->ts
.interface
2486 && !gfc_compare_interfaces (formal
, act_sym
->ts
.interface
,
2487 act_sym
->name
, 0, 1, err
,
2488 sizeof(err
),NULL
, NULL
))
2492 /* Artificially generated symbol names would only confuse. */
2493 if (formal
->attr
.artificial
)
2494 gfc_error_opt (0, "Interface mismatch in dummy procedure "
2495 "at %L conflicts with %L: %s", &actual
->where
,
2496 &formal
->declared_at
, err
);
2498 gfc_error_opt (0, "Interface mismatch in dummy procedure %qs "
2499 "at %L: %s", formal
->name
, &actual
->where
, err
);
2504 if (!gfc_compare_interfaces (formal
, act_sym
, act_sym
->name
, 0, 1, err
,
2505 sizeof(err
), NULL
, NULL
))
2509 if (formal
->attr
.artificial
)
2510 gfc_error_opt (0, "Interface mismatch in dummy procedure "
2511 "at %L conflicts with %L: %s", &actual
->where
,
2512 &formal
->declared_at
, err
);
2514 gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at "
2515 "%L: %s", formal
->name
, &actual
->where
, err
);
2521 /* The actual symbol may disagree with a global symbol. If so, issue an
2522 error, but only if no previous error has been reported on the formal
2524 actual_name
= act_sym
->name
;
2525 if (!formal
->error
&& actual_name
)
2528 gsym
= gfc_find_gsymbol (gfc_gsym_root
, actual_name
);
2531 if (gsym
->type
== GSYM_SUBROUTINE
&& formal
->attr
.function
)
2533 gfc_error ("Passing global subroutine %qs declared at %L "
2534 "as function at %L", actual_name
, &gsym
->where
,
2538 if (gsym
->type
== GSYM_FUNCTION
&& formal
->attr
.subroutine
)
2540 gfc_error ("Passing global function %qs declared at %L "
2541 "as subroutine at %L", actual_name
, &gsym
->where
,
2545 if (gsym
->type
== GSYM_FUNCTION
)
2547 gfc_symbol
*global_asym
;
2548 gfc_find_symbol (actual_name
, gsym
->ns
, 0, &global_asym
);
2549 if (global_asym
!= NULL
)
2551 if (formal
->attr
.subroutine
)
2553 gfc_error ("Mismatch between subroutine and "
2554 "function at %L", &actual
->where
);
2557 else if (formal
->attr
.function
)
2561 if (global_asym
->result
)
2562 ts
= global_asym
->result
->ts
;
2564 ts
= global_asym
->ts
;
2566 if (!gfc_compare_types (&ts
,
2569 gfc_error ("Type mismatch at %L passing global "
2570 "function %qs declared at %L (%s/%s)",
2571 &actual
->where
, actual_name
,
2573 gfc_typename (&global_asym
->ts
),
2574 gfc_dummy_typename (&formal
->ts
));
2580 /* The global symbol is a function. Set the formal
2581 argument acordingly. */
2582 formal
->attr
.function
= 1;
2583 formal
->ts
= global_asym
->ts
;
2590 if (formal
->attr
.function
&& !act_sym
->attr
.function
)
2592 gfc_add_function (&act_sym
->attr
, act_sym
->name
,
2593 &act_sym
->declared_at
);
2594 if (act_sym
->ts
.type
== BT_UNKNOWN
2595 && !gfc_set_default_type (act_sym
, 1, act_sym
->ns
))
2598 else if (formal
->attr
.subroutine
&& !act_sym
->attr
.subroutine
)
2599 gfc_add_subroutine (&act_sym
->attr
, act_sym
->name
,
2600 &act_sym
->declared_at
);
2604 ppc
= gfc_get_proc_ptr_comp (actual
);
2605 if (ppc
&& ppc
->ts
.interface
)
2607 if (!gfc_compare_interfaces (formal
, ppc
->ts
.interface
, ppc
->name
, 0, 1,
2608 err
, sizeof(err
), NULL
, NULL
))
2611 gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at %L:"
2612 " %s", formal
->name
, &actual
->where
, err
);
2618 if (formal
->attr
.pointer
&& formal
->attr
.contiguous
2619 && !gfc_is_simply_contiguous (actual
, true, false))
2622 gfc_error ("Actual argument to contiguous pointer dummy %qs at %L "
2623 "must be simply contiguous", formal
->name
, &actual
->where
);
2627 symbol_attribute actual_attr
= gfc_expr_attr (actual
);
2628 if (actual
->ts
.type
== BT_CLASS
&& !actual_attr
.class_ok
)
2631 if ((actual
->expr_type
!= EXPR_NULL
|| actual
->ts
.type
!= BT_UNKNOWN
)
2632 && actual
->ts
.type
!= BT_HOLLERITH
2633 && formal
->ts
.type
!= BT_ASSUMED
2634 && !(formal
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
2635 && !gfc_compare_types (&formal
->ts
, &actual
->ts
)
2636 && !(formal
->ts
.type
== BT_DERIVED
&& actual
->ts
.type
== BT_CLASS
2637 && gfc_compare_derived_types (formal
->ts
.u
.derived
,
2638 CLASS_DATA (actual
)->ts
.u
.derived
)))
2642 if (formal
->attr
.artificial
)
2644 if (!flag_allow_argument_mismatch
|| !formal
->error
)
2645 gfc_error_opt (0, "Type mismatch between actual argument at %L "
2646 "and actual argument at %L (%s/%s).",
2648 &formal
->declared_at
,
2649 gfc_typename (actual
),
2650 gfc_dummy_typename (&formal
->ts
));
2655 gfc_error_opt (0, "Type mismatch in argument %qs at %L; passed %s "
2656 "to %s", formal
->name
, where
, gfc_typename (actual
),
2657 gfc_dummy_typename (&formal
->ts
));
2662 if (actual
->ts
.type
== BT_ASSUMED
&& formal
->ts
.type
!= BT_ASSUMED
)
2665 gfc_error ("Assumed-type actual argument at %L requires that dummy "
2666 "argument %qs is of assumed type", &actual
->where
,
2671 /* TS29113 C407c; F2018 C711. */
2672 if (actual
->ts
.type
== BT_ASSUMED
2673 && symbol_rank (formal
) == -1
2674 && actual
->rank
!= -1
2675 && !(actual
->symtree
->n
.sym
->as
2676 && actual
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SHAPE
))
2679 gfc_error ("Assumed-type actual argument at %L corresponding to "
2680 "assumed-rank dummy argument %qs must be "
2681 "assumed-shape or assumed-rank",
2682 &actual
->where
, formal
->name
);
2686 /* F2008, 12.5.2.5; IR F08/0073. */
2687 if (formal
->ts
.type
== BT_CLASS
&& formal
->attr
.class_ok
2688 && actual
->expr_type
!= EXPR_NULL
2689 && ((CLASS_DATA (formal
)->attr
.class_pointer
2690 && formal
->attr
.intent
!= INTENT_IN
)
2691 || CLASS_DATA (formal
)->attr
.allocatable
))
2693 if (actual
->ts
.type
!= BT_CLASS
)
2696 gfc_error ("Actual argument to %qs at %L must be polymorphic",
2697 formal
->name
, &actual
->where
);
2701 if ((!UNLIMITED_POLY (formal
) || !UNLIMITED_POLY(actual
))
2702 && !gfc_compare_derived_types (CLASS_DATA (actual
)->ts
.u
.derived
,
2703 CLASS_DATA (formal
)->ts
.u
.derived
))
2706 gfc_error ("Actual argument to %qs at %L must have the same "
2707 "declared type", formal
->name
, &actual
->where
);
2712 /* F08: 12.5.2.5 Allocatable and pointer dummy variables. However, this
2713 is necessary also for F03, so retain error for both.
2714 NOTE: Other type/kind errors pre-empt this error. Since they are F03
2715 compatible, no attempt has been made to channel to this one. */
2716 if (UNLIMITED_POLY (formal
) && !UNLIMITED_POLY (actual
)
2717 && (CLASS_DATA (formal
)->attr
.allocatable
2718 ||CLASS_DATA (formal
)->attr
.class_pointer
))
2721 gfc_error ("Actual argument to %qs at %L must be unlimited "
2722 "polymorphic since the formal argument is a "
2723 "pointer or allocatable unlimited polymorphic "
2724 "entity [F2008: 12.5.2.5]", formal
->name
,
2729 if (formal
->ts
.type
== BT_CLASS
&& formal
->attr
.class_ok
)
2730 codimension
= CLASS_DATA (formal
)->attr
.codimension
;
2732 codimension
= formal
->attr
.codimension
;
2734 if (codimension
&& !gfc_is_coarray (actual
))
2737 gfc_error ("Actual argument to %qs at %L must be a coarray",
2738 formal
->name
, &actual
->where
);
2742 formal_as
= (formal
->ts
.type
== BT_CLASS
2743 ? CLASS_DATA (formal
)->as
: formal
->as
);
2745 if (codimension
&& formal
->attr
.allocatable
)
2747 gfc_ref
*last
= NULL
;
2749 for (ref
= actual
->ref
; ref
; ref
= ref
->next
)
2750 if (ref
->type
== REF_COMPONENT
)
2753 /* F2008, 12.5.2.6. */
2754 if ((last
&& last
->u
.c
.component
->as
->corank
!= formal
->as
->corank
)
2756 && actual
->symtree
->n
.sym
->as
->corank
!= formal
->as
->corank
))
2759 gfc_error ("Corank mismatch in argument %qs at %L (%d and %d)",
2760 formal
->name
, &actual
->where
, formal
->as
->corank
,
2761 last
? last
->u
.c
.component
->as
->corank
2762 : actual
->symtree
->n
.sym
->as
->corank
);
2769 /* F2008, 12.5.2.8 + Corrig 2 (IR F08/0048). */
2770 /* F2018, 12.5.2.8. */
2771 if (formal
->attr
.dimension
2772 && (formal
->attr
.contiguous
|| formal
->as
->type
!= AS_ASSUMED_SHAPE
)
2773 && actual_attr
.dimension
2774 && !gfc_is_simply_contiguous (actual
, true, true))
2777 gfc_error ("Actual argument to %qs at %L must be simply "
2778 "contiguous or an element of such an array",
2779 formal
->name
, &actual
->where
);
2783 /* F2008, C1303 and C1304. */
2784 if (formal
->attr
.intent
!= INTENT_INOUT
2785 && (((formal
->ts
.type
== BT_DERIVED
|| formal
->ts
.type
== BT_CLASS
)
2786 && formal
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2787 && formal
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
2788 || formal
->attr
.lock_comp
))
2792 gfc_error ("Actual argument to non-INTENT(INOUT) dummy %qs at %L, "
2793 "which is LOCK_TYPE or has a LOCK_TYPE component",
2794 formal
->name
, &actual
->where
);
2798 /* TS18508, C702/C703. */
2799 if (formal
->attr
.intent
!= INTENT_INOUT
2800 && (((formal
->ts
.type
== BT_DERIVED
|| formal
->ts
.type
== BT_CLASS
)
2801 && formal
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2802 && formal
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
2803 || formal
->attr
.event_comp
))
2807 gfc_error ("Actual argument to non-INTENT(INOUT) dummy %qs at %L, "
2808 "which is EVENT_TYPE or has a EVENT_TYPE component",
2809 formal
->name
, &actual
->where
);
2814 /* F2008, C1239/C1240. */
2815 if (actual
->expr_type
== EXPR_VARIABLE
2816 && (actual
->symtree
->n
.sym
->attr
.asynchronous
2817 || actual
->symtree
->n
.sym
->attr
.volatile_
)
2818 && (formal
->attr
.asynchronous
|| formal
->attr
.volatile_
)
2819 && actual
->rank
&& formal
->as
2820 && !gfc_is_simply_contiguous (actual
, true, false)
2821 && ((formal
->as
->type
!= AS_ASSUMED_SHAPE
2822 && formal
->as
->type
!= AS_ASSUMED_RANK
&& !formal
->attr
.pointer
)
2823 || formal
->attr
.contiguous
))
2826 gfc_error ("Dummy argument %qs has to be a pointer, assumed-shape or "
2827 "assumed-rank array without CONTIGUOUS attribute - as actual"
2828 " argument at %L is not simply contiguous and both are "
2829 "ASYNCHRONOUS or VOLATILE", formal
->name
, &actual
->where
);
2833 if (formal
->attr
.allocatable
&& !codimension
2834 && actual_attr
.codimension
)
2836 if (formal
->attr
.intent
== INTENT_OUT
)
2839 gfc_error ("Passing coarray at %L to allocatable, noncoarray, "
2840 "INTENT(OUT) dummy argument %qs", &actual
->where
,
2844 else if (warn_surprising
&& where
&& formal
->attr
.intent
!= INTENT_IN
)
2845 gfc_warning (OPT_Wsurprising
,
2846 "Passing coarray at %L to allocatable, noncoarray dummy "
2847 "argument %qs, which is invalid if the allocation status"
2848 " is modified", &actual
->where
, formal
->name
);
2851 /* If the rank is the same or the formal argument has assumed-rank. */
2852 if (symbol_rank (formal
) == actual
->rank
|| symbol_rank (formal
) == -1)
2855 rank_check
= where
!= NULL
&& !is_elemental
&& formal_as
2856 && (formal_as
->type
== AS_ASSUMED_SHAPE
2857 || formal_as
->type
== AS_DEFERRED
)
2858 && !(actual
->expr_type
== EXPR_NULL
2859 && actual
->ts
.type
== BT_UNKNOWN
);
2861 /* Skip rank checks for NO_ARG_CHECK. */
2862 if (formal
->attr
.ext_attr
& (1 << EXT_ATTR_NO_ARG_CHECK
))
2865 /* Scalar & coindexed, see: F2008, Section 12.5.2.4. */
2866 if (rank_check
|| ranks_must_agree
2867 || (formal
->attr
.pointer
&& actual
->expr_type
!= EXPR_NULL
)
2868 || (actual
->rank
!= 0
2869 && !(is_elemental
|| formal
->attr
.dimension
2870 || (formal
->ts
.type
== BT_CLASS
2871 && CLASS_DATA (formal
)->attr
.dimension
)))
2872 || (actual
->rank
== 0
2873 && ((formal
->ts
.type
== BT_CLASS
2874 && CLASS_DATA (formal
)->as
->type
== AS_ASSUMED_SHAPE
)
2875 || (formal
->ts
.type
!= BT_CLASS
2876 && formal
->as
->type
== AS_ASSUMED_SHAPE
))
2877 && actual
->expr_type
!= EXPR_NULL
)
2878 || (actual
->rank
== 0
2879 && (formal
->attr
.dimension
2880 || (formal
->ts
.type
== BT_CLASS
2881 && CLASS_DATA (formal
)->attr
.dimension
))
2882 && gfc_is_coindexed (actual
))
2883 /* Assumed-rank actual argument; F2018 C838. */
2884 || actual
->rank
== -1)
2887 && (!formal
->attr
.artificial
|| (!formal
->maybe_array
2888 && !maybe_dummy_array_arg (actual
))))
2890 locus
*where_formal
;
2891 if (formal
->attr
.artificial
)
2892 where_formal
= &formal
->declared_at
;
2894 where_formal
= NULL
;
2896 argument_rank_mismatch (formal
->name
, &actual
->where
,
2897 symbol_rank (formal
), actual
->rank
,
2902 else if (actual
->rank
!= 0
2903 && (is_elemental
|| formal
->attr
.dimension
2904 || (formal
->ts
.type
== BT_CLASS
2905 && CLASS_DATA (formal
)->attr
.dimension
)))
2908 /* At this point, we are considering a scalar passed to an array. This
2909 is valid (cf. F95 12.4.1.1, F2003 12.4.1.2, and F2008 12.5.2.4),
2910 - if the actual argument is (a substring of) an element of a
2911 non-assumed-shape/non-pointer/non-polymorphic array; or
2912 - (F2003) if the actual argument is of type character of default/c_char
2914 - (F2018) if the dummy argument is type(*). */
2916 is_pointer
= actual
->expr_type
== EXPR_VARIABLE
2917 ? actual
->symtree
->n
.sym
->attr
.pointer
: false;
2919 for (ref
= actual
->ref
; ref
; ref
= ref
->next
)
2921 if (ref
->type
== REF_COMPONENT
)
2922 is_pointer
= ref
->u
.c
.component
->attr
.pointer
;
2923 else if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.type
== AR_ELEMENT
2924 && ref
->u
.ar
.dimen
> 0
2926 || (ref
->next
->type
== REF_SUBSTRING
&& !ref
->next
->next
)))
2930 if (actual
->ts
.type
== BT_CLASS
&& actual
->expr_type
!= EXPR_NULL
)
2933 gfc_error ("Polymorphic scalar passed to array dummy argument %qs "
2934 "at %L", formal
->name
, &actual
->where
);
2938 if (actual
->expr_type
!= EXPR_NULL
&& ref
&& actual
->ts
.type
!= BT_CHARACTER
2939 && (is_pointer
|| ref
->u
.ar
.as
->type
== AS_ASSUMED_SHAPE
))
2943 if (formal
->attr
.artificial
)
2944 gfc_error ("Element of assumed-shape or pointer array "
2945 "as actual argument at %L cannot correspond to "
2946 "actual argument at %L",
2947 &actual
->where
, &formal
->declared_at
);
2949 gfc_error ("Element of assumed-shape or pointer "
2950 "array passed to array dummy argument %qs at %L",
2951 formal
->name
, &actual
->where
);
2956 if (actual
->ts
.type
== BT_CHARACTER
&& actual
->expr_type
!= EXPR_NULL
2957 && (!ref
|| is_pointer
|| ref
->u
.ar
.as
->type
== AS_ASSUMED_SHAPE
))
2959 if (formal
->ts
.kind
!= 1 && (gfc_option
.allow_std
& GFC_STD_GNU
) == 0)
2962 gfc_error ("Extension: Scalar non-default-kind, non-C_CHAR-kind "
2963 "CHARACTER actual argument with array dummy argument "
2964 "%qs at %L", formal
->name
, &actual
->where
);
2968 if (where
&& (gfc_option
.allow_std
& GFC_STD_F2003
) == 0)
2970 gfc_error ("Fortran 2003: Scalar CHARACTER actual argument with "
2971 "array dummy argument %qs at %L",
2972 formal
->name
, &actual
->where
);
2976 return ((gfc_option
.allow_std
& GFC_STD_F2003
) != 0);
2979 if (ref
== NULL
&& actual
->expr_type
!= EXPR_NULL
)
2981 if (actual
->rank
== 0
2982 && formal
->ts
.type
== BT_ASSUMED
2984 && formal
->as
->type
== AS_ASSUMED_SIZE
)
2985 /* This is new in F2018, type(*) is new in TS29113, but gfortran does
2986 not differentiate. Thus, if type(*) exists, it is valid;
2987 otherwise, type(*) is already rejected. */
2990 && (!formal
->attr
.artificial
|| (!formal
->maybe_array
2991 && !maybe_dummy_array_arg (actual
))))
2993 locus
*where_formal
;
2994 if (formal
->attr
.artificial
)
2995 where_formal
= &formal
->declared_at
;
2997 where_formal
= NULL
;
2999 argument_rank_mismatch (formal
->name
, &actual
->where
,
3000 symbol_rank (formal
), actual
->rank
,
3010 /* Returns the storage size of a symbol (formal argument) or
3011 zero if it cannot be determined. */
3013 static unsigned long
3014 get_sym_storage_size (gfc_symbol
*sym
)
3017 unsigned long strlen
, elements
;
3019 if (sym
->ts
.type
== BT_CHARACTER
)
3021 if (sym
->ts
.u
.cl
&& sym
->ts
.u
.cl
->length
3022 && sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
3023 && sym
->ts
.u
.cl
->length
->ts
.type
== BT_INTEGER
)
3024 strlen
= mpz_get_ui (sym
->ts
.u
.cl
->length
->value
.integer
);
3031 if (symbol_rank (sym
) == 0)
3035 if (sym
->as
->type
!= AS_EXPLICIT
)
3037 for (i
= 0; i
< sym
->as
->rank
; i
++)
3039 if (sym
->as
->upper
[i
]->expr_type
!= EXPR_CONSTANT
3040 || sym
->as
->lower
[i
]->expr_type
!= EXPR_CONSTANT
3041 || sym
->as
->upper
[i
]->ts
.type
!= BT_INTEGER
3042 || sym
->as
->lower
[i
]->ts
.type
!= BT_INTEGER
)
3045 elements
*= mpz_get_si (sym
->as
->upper
[i
]->value
.integer
)
3046 - mpz_get_si (sym
->as
->lower
[i
]->value
.integer
) + 1L;
3049 return strlen
*elements
;
3053 /* Returns the storage size of an expression (actual argument) or
3054 zero if it cannot be determined. For an array element, it returns
3055 the remaining size as the element sequence consists of all storage
3056 units of the actual argument up to the end of the array. */
3058 static unsigned long
3059 get_expr_storage_size (gfc_expr
*e
)
3062 long int strlen
, elements
;
3063 long int substrlen
= 0;
3064 bool is_str_storage
= false;
3070 if (e
->ts
.type
== BT_CHARACTER
)
3072 if (e
->ts
.u
.cl
&& e
->ts
.u
.cl
->length
3073 && e
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
3074 && e
->ts
.u
.cl
->length
->ts
.type
== BT_INTEGER
)
3075 strlen
= mpz_get_si (e
->ts
.u
.cl
->length
->value
.integer
);
3076 else if (e
->expr_type
== EXPR_CONSTANT
3077 && (e
->ts
.u
.cl
== NULL
|| e
->ts
.u
.cl
->length
== NULL
))
3078 strlen
= e
->value
.character
.length
;
3083 strlen
= 1; /* Length per element. */
3085 if (e
->rank
== 0 && !e
->ref
)
3093 for (i
= 0; i
< e
->rank
; i
++)
3094 elements
*= mpz_get_si (e
->shape
[i
]);
3095 return elements
*strlen
;
3098 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
3100 if (ref
->type
== REF_SUBSTRING
&& ref
->u
.ss
.start
3101 && ref
->u
.ss
.start
->expr_type
== EXPR_CONSTANT
)
3105 /* The string length is the substring length.
3106 Set now to full string length. */
3107 if (!ref
->u
.ss
.length
|| !ref
->u
.ss
.length
->length
3108 || ref
->u
.ss
.length
->length
->expr_type
!= EXPR_CONSTANT
)
3111 strlen
= mpz_get_ui (ref
->u
.ss
.length
->length
->value
.integer
);
3113 substrlen
= strlen
- mpz_get_ui (ref
->u
.ss
.start
->value
.integer
) + 1;
3117 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.type
== AR_SECTION
)
3118 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
3120 long int start
, end
, stride
;
3123 if (ref
->u
.ar
.stride
[i
])
3125 if (ref
->u
.ar
.stride
[i
]->expr_type
== EXPR_CONSTANT
3126 && ref
->u
.ar
.stride
[i
]->ts
.type
== BT_INTEGER
)
3127 stride
= mpz_get_si (ref
->u
.ar
.stride
[i
]->value
.integer
);
3132 if (ref
->u
.ar
.start
[i
])
3134 if (ref
->u
.ar
.start
[i
]->expr_type
== EXPR_CONSTANT
3135 && ref
->u
.ar
.start
[i
]->ts
.type
== BT_INTEGER
)
3136 start
= mpz_get_si (ref
->u
.ar
.start
[i
]->value
.integer
);
3140 else if (ref
->u
.ar
.as
->lower
[i
]
3141 && ref
->u
.ar
.as
->lower
[i
]->expr_type
== EXPR_CONSTANT
3142 && ref
->u
.ar
.as
->lower
[i
]->ts
.type
== BT_INTEGER
)
3143 start
= mpz_get_si (ref
->u
.ar
.as
->lower
[i
]->value
.integer
);
3147 if (ref
->u
.ar
.end
[i
])
3149 if (ref
->u
.ar
.end
[i
]->expr_type
== EXPR_CONSTANT
3150 && ref
->u
.ar
.end
[i
]->ts
.type
== BT_INTEGER
)
3151 end
= mpz_get_si (ref
->u
.ar
.end
[i
]->value
.integer
);
3155 else if (ref
->u
.ar
.as
->upper
[i
]
3156 && ref
->u
.ar
.as
->upper
[i
]->expr_type
== EXPR_CONSTANT
3157 && ref
->u
.ar
.as
->upper
[i
]->ts
.type
== BT_INTEGER
)
3158 end
= mpz_get_si (ref
->u
.ar
.as
->upper
[i
]->value
.integer
);
3162 elements
*= (end
- start
)/stride
+ 1L;
3164 else if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.type
== AR_FULL
)
3165 for (i
= 0; i
< ref
->u
.ar
.as
->rank
; i
++)
3167 if (ref
->u
.ar
.as
->lower
[i
] && ref
->u
.ar
.as
->upper
[i
]
3168 && ref
->u
.ar
.as
->lower
[i
]->expr_type
== EXPR_CONSTANT
3169 && ref
->u
.ar
.as
->lower
[i
]->ts
.type
== BT_INTEGER
3170 && ref
->u
.ar
.as
->upper
[i
]->expr_type
== EXPR_CONSTANT
3171 && ref
->u
.ar
.as
->upper
[i
]->ts
.type
== BT_INTEGER
)
3172 elements
*= mpz_get_si (ref
->u
.ar
.as
->upper
[i
]->value
.integer
)
3173 - mpz_get_si (ref
->u
.ar
.as
->lower
[i
]->value
.integer
)
3178 else if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.type
== AR_ELEMENT
3179 && e
->expr_type
== EXPR_VARIABLE
)
3181 if (ref
->u
.ar
.as
->type
== AS_ASSUMED_SHAPE
3182 || e
->symtree
->n
.sym
->attr
.pointer
)
3188 /* Determine the number of remaining elements in the element
3189 sequence for array element designators. */
3190 is_str_storage
= true;
3191 for (i
= ref
->u
.ar
.dimen
- 1; i
>= 0; i
--)
3193 if (ref
->u
.ar
.start
[i
] == NULL
3194 || ref
->u
.ar
.start
[i
]->expr_type
!= EXPR_CONSTANT
3195 || ref
->u
.ar
.as
->upper
[i
] == NULL
3196 || ref
->u
.ar
.as
->lower
[i
] == NULL
3197 || ref
->u
.ar
.as
->upper
[i
]->expr_type
!= EXPR_CONSTANT
3198 || ref
->u
.ar
.as
->lower
[i
]->expr_type
!= EXPR_CONSTANT
3199 || ref
->u
.ar
.as
->upper
[i
]->ts
.type
!= BT_INTEGER
3200 || ref
->u
.ar
.as
->lower
[i
]->ts
.type
!= BT_INTEGER
)
3205 * (mpz_get_si (ref
->u
.ar
.as
->upper
[i
]->value
.integer
)
3206 - mpz_get_si (ref
->u
.ar
.as
->lower
[i
]->value
.integer
)
3208 - (mpz_get_si (ref
->u
.ar
.start
[i
]->value
.integer
)
3209 - mpz_get_si (ref
->u
.ar
.as
->lower
[i
]->value
.integer
));
3212 else if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.function
3213 && ref
->u
.c
.component
->attr
.proc_pointer
3214 && ref
->u
.c
.component
->attr
.dimension
)
3216 /* Array-valued procedure-pointer components. */
3217 gfc_array_spec
*as
= ref
->u
.c
.component
->as
;
3218 for (i
= 0; i
< as
->rank
; i
++)
3220 if (!as
->upper
[i
] || !as
->lower
[i
]
3221 || as
->upper
[i
]->expr_type
!= EXPR_CONSTANT
3222 || as
->lower
[i
]->expr_type
!= EXPR_CONSTANT
3223 || as
->upper
[i
]->ts
.type
!= BT_INTEGER
3224 || as
->lower
[i
]->ts
.type
!= BT_INTEGER
)
3228 * (mpz_get_si (as
->upper
[i
]->value
.integer
)
3229 - mpz_get_si (as
->lower
[i
]->value
.integer
) + 1L);
3235 return (is_str_storage
) ? substrlen
+ (elements
-1)*strlen
3238 return elements
*strlen
;
3242 /* Given an expression, check whether it is an array section
3243 which has a vector subscript. */
3246 gfc_has_vector_subscript (gfc_expr
*e
)
3251 if (e
== NULL
|| e
->rank
== 0 || e
->expr_type
!= EXPR_VARIABLE
)
3254 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
3255 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.type
== AR_SECTION
)
3256 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
3257 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
3265 is_procptr_result (gfc_expr
*expr
)
3267 gfc_component
*c
= gfc_get_proc_ptr_comp (expr
);
3269 return (c
->ts
.interface
&& (c
->ts
.interface
->attr
.proc_pointer
== 1));
3271 return ((expr
->symtree
->n
.sym
->result
!= expr
->symtree
->n
.sym
)
3272 && (expr
->symtree
->n
.sym
->result
->attr
.proc_pointer
== 1));
3276 /* Recursively append candidate argument ARG to CANDIDATES. Store the
3277 number of total candidates in CANDIDATES_LEN. */
3280 lookup_arg_fuzzy_find_candidates (gfc_formal_arglist
*arg
,
3282 size_t &candidates_len
)
3284 for (gfc_formal_arglist
*p
= arg
; p
&& p
->sym
; p
= p
->next
)
3285 vec_push (candidates
, candidates_len
, p
->sym
->name
);
3289 /* Lookup argument ARG fuzzily, taking names in ARGUMENTS into account. */
3292 lookup_arg_fuzzy (const char *arg
, gfc_formal_arglist
*arguments
)
3294 char **candidates
= NULL
;
3295 size_t candidates_len
= 0;
3296 lookup_arg_fuzzy_find_candidates (arguments
, candidates
, candidates_len
);
3297 return gfc_closest_fuzzy_match (arg
, candidates
);
3301 static gfc_dummy_arg
*
3302 get_nonintrinsic_dummy_arg (gfc_formal_arglist
*formal
)
3304 gfc_dummy_arg
* const dummy_arg
= gfc_get_dummy_arg ();
3306 dummy_arg
->intrinsicness
= GFC_NON_INTRINSIC_DUMMY_ARG
;
3307 dummy_arg
->u
.non_intrinsic
= formal
;
3313 /* Given formal and actual argument lists, see if they are compatible.
3314 If they are compatible, the actual argument list is sorted to
3315 correspond with the formal list, and elements for missing optional
3316 arguments are inserted. If WHERE pointer is nonnull, then we issue
3317 errors when things don't match instead of just returning the status
3321 gfc_compare_actual_formal (gfc_actual_arglist
**ap
, gfc_formal_arglist
*formal
,
3322 int ranks_must_agree
, int is_elemental
,
3323 bool in_statement_function
, locus
*where
)
3325 gfc_actual_arglist
**new_arg
, *a
, *actual
;
3326 gfc_formal_arglist
*f
;
3328 unsigned long actual_size
, formal_size
;
3329 bool full_array
= false;
3330 gfc_array_ref
*actual_arr_ref
;
3331 gfc_array_spec
*fas
, *aas
;
3332 bool pointer_dummy
, pointer_arg
, allocatable_arg
;
3333 bool procptr_dummy
, optional_dummy
, allocatable_dummy
;
3339 if (actual
== NULL
&& formal
== NULL
)
3343 for (f
= formal
; f
; f
= f
->next
)
3346 new_arg
= XALLOCAVEC (gfc_actual_arglist
*, n
);
3348 for (i
= 0; i
< n
; i
++)
3355 for (a
= actual
; a
; a
= a
->next
, f
= f
->next
)
3357 if (a
->name
!= NULL
&& in_statement_function
)
3359 gfc_error ("Keyword argument %qs at %L is invalid in "
3360 "a statement function", a
->name
, &a
->expr
->where
);
3364 /* Look for keywords but ignore g77 extensions like %VAL. */
3365 if (a
->name
!= NULL
&& a
->name
[0] != '%')
3368 for (f
= formal
; f
; f
= f
->next
, i
++)
3372 if (strcmp (f
->sym
->name
, a
->name
) == 0)
3380 const char *guessed
= lookup_arg_fuzzy (a
->name
, formal
);
3382 gfc_error ("Keyword argument %qs at %L is not in "
3383 "the procedure; did you mean %qs?",
3384 a
->name
, &a
->expr
->where
, guessed
);
3386 gfc_error ("Keyword argument %qs at %L is not in "
3387 "the procedure", a
->name
, &a
->expr
->where
);
3392 if (new_arg
[i
] != NULL
)
3395 gfc_error ("Keyword argument %qs at %L is already associated "
3396 "with another actual argument", a
->name
,
3405 gfc_error ("More actual than formal arguments in procedure "
3406 "call at %L", where
);
3410 if (f
->sym
== NULL
&& a
->expr
== NULL
)
3415 /* These errors have to be issued, otherwise an ICE can occur.
3418 gfc_error_now ("Missing alternate return specifier in subroutine "
3419 "call at %L", where
);
3424 if (a
->associated_dummy
)
3425 free (a
->associated_dummy
);
3426 a
->associated_dummy
= get_nonintrinsic_dummy_arg (f
);
3429 if (a
->expr
== NULL
)
3431 if (f
->sym
->attr
.optional
)
3436 gfc_error_now ("Unexpected alternate return specifier in "
3437 "subroutine call at %L", where
);
3442 /* Make sure that intrinsic vtables exist for calls to unlimited
3443 polymorphic formal arguments. */
3444 if (UNLIMITED_POLY (f
->sym
)
3445 && a
->expr
->ts
.type
!= BT_DERIVED
3446 && a
->expr
->ts
.type
!= BT_CLASS
3447 && a
->expr
->ts
.type
!= BT_ASSUMED
)
3448 gfc_find_vtab (&a
->expr
->ts
);
3450 /* Interp J3/22-146:
3451 "If the context of the reference to NULL is an <actual argument>
3452 corresponding to an <assumed-rank> dummy argument, MOLD shall be
3454 if (a
->expr
->expr_type
== EXPR_NULL
3455 && a
->expr
->ts
.type
== BT_UNKNOWN
3457 && f
->sym
->as
->type
== AS_ASSUMED_RANK
)
3459 gfc_error ("Intrinsic %<NULL()%> without %<MOLD%> argument at %L "
3460 "passed to assumed-rank dummy %qs",
3461 &a
->expr
->where
, f
->sym
->name
);
3467 && a
->expr
->expr_type
== EXPR_VARIABLE
3468 && a
->expr
->symtree
->n
.sym
->as
3469 && a
->expr
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
3471 && f
->sym
->as
->type
== AS_ASSUMED_RANK
)
3472 gfc_warning (0, "The assumed-size dummy %qs is being passed at %L to "
3473 "an assumed-rank dummy %qs", a
->expr
->symtree
->name
,
3474 &a
->expr
->where
, f
->sym
->name
);
3476 if (a
->expr
->expr_type
== EXPR_NULL
3477 && a
->expr
->ts
.type
== BT_UNKNOWN
3478 && f
->sym
->ts
.type
== BT_CHARACTER
3479 && !f
->sym
->ts
.deferred
3481 && f
->sym
->ts
.u
.cl
->length
== NULL
)
3483 gfc_error ("Intrinsic %<NULL()%> without %<MOLD%> argument at %L "
3484 "passed to assumed-length dummy %qs",
3485 &a
->expr
->where
, f
->sym
->name
);
3490 /* Allow passing of NULL() as disassociated pointer, procedure
3491 pointer, or unallocated allocatable (F2008+) to a respective dummy
3493 pointer_dummy
= ((f
->sym
->ts
.type
!= BT_CLASS
3494 && f
->sym
->attr
.pointer
)
3495 || (f
->sym
->ts
.type
== BT_CLASS
3496 && CLASS_DATA (f
->sym
)->attr
.class_pointer
));
3498 procptr_dummy
= ((f
->sym
->ts
.type
!= BT_CLASS
3499 && f
->sym
->attr
.proc_pointer
)
3500 || (f
->sym
->ts
.type
== BT_CLASS
3501 && CLASS_DATA (f
->sym
)->attr
.proc_pointer
));
3503 optional_dummy
= f
->sym
->attr
.optional
;
3505 allocatable_dummy
= ((f
->sym
->ts
.type
!= BT_CLASS
3506 && f
->sym
->attr
.allocatable
)
3507 || (f
->sym
->ts
.type
== BT_CLASS
3508 && CLASS_DATA (f
->sym
)->attr
.allocatable
));
3510 if (a
->expr
->expr_type
== EXPR_NULL
3514 && (gfc_option
.allow_std
& GFC_STD_F2008
) != 0)
3515 && !(allocatable_dummy
3516 && (gfc_option
.allow_std
& GFC_STD_F2008
) != 0))
3519 && (!f
->sym
->attr
.optional
3520 || (f
->sym
->ts
.type
!= BT_CLASS
&& f
->sym
->attr
.allocatable
)
3521 || (f
->sym
->ts
.type
== BT_CLASS
3522 && CLASS_DATA (f
->sym
)->attr
.allocatable
)))
3523 gfc_error ("Unexpected NULL() intrinsic at %L to dummy %qs",
3524 where
, f
->sym
->name
);
3526 gfc_error ("Fortran 2008: Null pointer at %L to non-pointer "
3527 "dummy %qs", where
, f
->sym
->name
);
3532 if (!compare_parameter (f
->sym
, a
->expr
, ranks_must_agree
,
3533 is_elemental
, where
))
3539 /* TS 29113, 6.3p2; F2018 15.5.2.4. */
3540 if (f
->sym
->ts
.type
== BT_ASSUMED
3541 && (a
->expr
->ts
.type
== BT_DERIVED
3542 || (a
->expr
->ts
.type
== BT_CLASS
&& CLASS_DATA (a
->expr
))))
3544 gfc_symbol
*derived
= (a
->expr
->ts
.type
== BT_DERIVED
3545 ? a
->expr
->ts
.u
.derived
3546 : CLASS_DATA (a
->expr
)->ts
.u
.derived
);
3547 gfc_namespace
*f2k_derived
= derived
->f2k_derived
;
3548 if (derived
->attr
.pdt_type
3550 && (f2k_derived
->finalizers
|| f2k_derived
->tb_sym_root
)))
3552 gfc_error ("Actual argument at %L to assumed-type dummy "
3553 "has type parameters or is of "
3554 "derived type with type-bound or FINAL procedures",
3561 if (UNLIMITED_POLY (a
->expr
)
3562 && !(f
->sym
->ts
.type
== BT_ASSUMED
|| UNLIMITED_POLY (f
->sym
)))
3564 gfc_error ("Unlimited polymorphic actual argument at %L is not "
3565 "matched with either an unlimited polymorphic or "
3566 "assumed type dummy argument", &a
->expr
->where
);
3571 /* Special case for character arguments. For allocatable, pointer
3572 and assumed-shape dummies, the string length needs to match
3574 if (a
->expr
->ts
.type
== BT_CHARACTER
3575 && a
->expr
->ts
.u
.cl
&& a
->expr
->ts
.u
.cl
->length
3576 && a
->expr
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
3577 && a
->expr
->ts
.u
.cl
->length
->ts
.type
== BT_INTEGER
3578 && f
->sym
->ts
.type
== BT_CHARACTER
&& f
->sym
->ts
.u
.cl
3579 && f
->sym
->ts
.u
.cl
->length
3580 && f
->sym
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
3581 && f
->sym
->ts
.u
.cl
->length
->ts
.type
== BT_INTEGER
3582 && (f
->sym
->attr
.pointer
|| f
->sym
->attr
.allocatable
3583 || (f
->sym
->as
&& f
->sym
->as
->type
== AS_ASSUMED_SHAPE
))
3584 && (mpz_cmp (a
->expr
->ts
.u
.cl
->length
->value
.integer
,
3585 f
->sym
->ts
.u
.cl
->length
->value
.integer
) != 0))
3587 if (where
&& (f
->sym
->attr
.pointer
|| f
->sym
->attr
.allocatable
))
3588 gfc_warning (0, "Character length mismatch (%ld/%ld) between actual "
3589 "argument and pointer or allocatable dummy argument "
3591 mpz_get_si (a
->expr
->ts
.u
.cl
->length
->value
.integer
),
3592 mpz_get_si (f
->sym
->ts
.u
.cl
->length
->value
.integer
),
3593 f
->sym
->name
, &a
->expr
->where
);
3595 gfc_warning (0, "Character length mismatch (%ld/%ld) between actual "
3596 "argument and assumed-shape dummy argument %qs "
3598 mpz_get_si (a
->expr
->ts
.u
.cl
->length
->value
.integer
),
3599 mpz_get_si (f
->sym
->ts
.u
.cl
->length
->value
.integer
),
3600 f
->sym
->name
, &a
->expr
->where
);
3605 if ((f
->sym
->attr
.pointer
|| f
->sym
->attr
.allocatable
)
3606 && f
->sym
->ts
.deferred
!= a
->expr
->ts
.deferred
3607 && a
->expr
->ts
.type
== BT_CHARACTER
)
3610 gfc_error ("Actual argument at %L to allocatable or "
3611 "pointer dummy argument %qs must have a deferred "
3612 "length type parameter if and only if the dummy has one",
3613 &a
->expr
->where
, f
->sym
->name
);
3618 if (f
->sym
->ts
.type
== BT_CLASS
)
3619 goto skip_size_check
;
3621 /* Skip size check for NULL() actual without MOLD argument. */
3622 if (a
->expr
->expr_type
== EXPR_NULL
&& a
->expr
->ts
.type
== BT_UNKNOWN
)
3623 goto skip_size_check
;
3625 actual_size
= get_expr_storage_size (a
->expr
);
3626 formal_size
= get_sym_storage_size (f
->sym
);
3627 if (actual_size
!= 0 && actual_size
< formal_size
3628 && a
->expr
->ts
.type
!= BT_PROCEDURE
3629 && f
->sym
->attr
.flavor
!= FL_PROCEDURE
)
3631 if (a
->expr
->ts
.type
== BT_CHARACTER
&& !f
->sym
->as
&& where
)
3633 gfc_warning (0, "Character length of actual argument shorter "
3634 "than of dummy argument %qs (%lu/%lu) at %L",
3635 f
->sym
->name
, actual_size
, formal_size
,
3637 goto skip_size_check
;
3641 /* Emit a warning for -std=legacy and an error otherwise. */
3642 if (gfc_option
.warn_std
== 0)
3643 gfc_warning (0, "Actual argument contains too few "
3644 "elements for dummy argument %qs (%lu/%lu) "
3645 "at %L", f
->sym
->name
, actual_size
,
3646 formal_size
, &a
->expr
->where
);
3648 gfc_error_now ("Actual argument contains too few "
3649 "elements for dummy argument %qs (%lu/%lu) "
3650 "at %L", f
->sym
->name
, actual_size
,
3651 formal_size
, &a
->expr
->where
);
3659 /* Satisfy either: F03:12.4.1.3 by ensuring that a procedure pointer
3660 actual argument is provided for a procedure pointer formal argument;
3661 or: F08:12.5.2.9 (F18:15.5.2.10) by ensuring that the effective
3662 argument shall be an external, internal, module, or dummy procedure.
3663 The interfaces are checked elsewhere. */
3664 if (f
->sym
->attr
.proc_pointer
3665 && !((a
->expr
->expr_type
== EXPR_VARIABLE
3666 && (a
->expr
->symtree
->n
.sym
->attr
.proc_pointer
3667 || gfc_is_proc_ptr_comp (a
->expr
)))
3668 || (a
->expr
->ts
.type
== BT_PROCEDURE
3669 && f
->sym
->ts
.interface
)
3670 || (a
->expr
->expr_type
== EXPR_FUNCTION
3671 && is_procptr_result (a
->expr
))))
3674 gfc_error ("Expected a procedure pointer for argument %qs at %L",
3675 f
->sym
->name
, &a
->expr
->where
);
3680 /* Satisfy F03:12.4.1.3 by ensuring that a procedure actual argument is
3681 provided for a procedure formal argument. */
3682 if (f
->sym
->attr
.flavor
== FL_PROCEDURE
3683 && !((a
->expr
->expr_type
== EXPR_VARIABLE
3684 && (a
->expr
->symtree
->n
.sym
->attr
.flavor
== FL_PROCEDURE
3685 || a
->expr
->symtree
->n
.sym
->attr
.proc_pointer
3686 || gfc_is_proc_ptr_comp (a
->expr
)))
3687 || (a
->expr
->expr_type
== EXPR_FUNCTION
3688 && is_procptr_result (a
->expr
))))
3691 gfc_error ("Expected a procedure for argument %qs at %L",
3692 f
->sym
->name
, &a
->expr
->where
);
3697 /* Class array variables and expressions store array info in a
3698 different place from non-class objects; consolidate the logic
3699 to access it here instead of repeating it below. Note that
3700 pointer_arg and allocatable_arg are not fully general and are
3701 only used in a specific situation below with an assumed-rank
3703 if (f
->sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (f
->sym
))
3705 gfc_component
*classdata
= CLASS_DATA (f
->sym
);
3706 fas
= classdata
->as
;
3707 pointer_dummy
= classdata
->attr
.class_pointer
;
3712 pointer_dummy
= f
->sym
->attr
.pointer
;
3715 if (a
->expr
->expr_type
!= EXPR_VARIABLE
3716 && !(a
->expr
->expr_type
== EXPR_NULL
3717 && a
->expr
->ts
.type
!= BT_UNKNOWN
))
3720 pointer_arg
= false;
3721 allocatable_arg
= false;
3723 else if (a
->expr
->ts
.type
== BT_CLASS
3724 && a
->expr
->symtree
->n
.sym
3725 && CLASS_DATA (a
->expr
->symtree
->n
.sym
))
3727 gfc_component
*classdata
= CLASS_DATA (a
->expr
->symtree
->n
.sym
);
3728 aas
= classdata
->as
;
3729 pointer_arg
= classdata
->attr
.class_pointer
;
3730 allocatable_arg
= classdata
->attr
.allocatable
;
3734 aas
= a
->expr
->symtree
->n
.sym
->as
;
3735 pointer_arg
= a
->expr
->symtree
->n
.sym
->attr
.pointer
;
3736 allocatable_arg
= a
->expr
->symtree
->n
.sym
->attr
.allocatable
;
3739 /* F2018:9.5.2(2) permits assumed-size whole array expressions as
3740 actual arguments only if the shape is not required; thus it
3741 cannot be passed to an assumed-shape array dummy.
3742 F2018:15.5.2.(2) permits passing a nonpointer actual to an
3743 intent(in) pointer dummy argument and this is accepted by
3744 the compare_pointer check below, but this also requires shape
3746 There's more discussion of this in PR94110. */
3748 && (fas
->type
== AS_ASSUMED_SHAPE
3749 || fas
->type
== AS_DEFERRED
3750 || (fas
->type
== AS_ASSUMED_RANK
&& pointer_dummy
))
3752 && aas
->type
== AS_ASSUMED_SIZE
3753 && (a
->expr
->ref
== NULL
3754 || (a
->expr
->ref
->type
== REF_ARRAY
3755 && a
->expr
->ref
->u
.ar
.type
== AR_FULL
)))
3758 gfc_error ("Actual argument for %qs cannot be an assumed-size"
3759 " array at %L", f
->sym
->name
, where
);
3764 /* Diagnose F2018 C839 (TS29113 C535c). Here the problem is
3765 passing an assumed-size array to an INTENT(OUT) assumed-rank
3766 dummy when it doesn't have the size information needed to run
3767 initializers and finalizers. */
3768 if (f
->sym
->attr
.intent
== INTENT_OUT
3770 && fas
->type
== AS_ASSUMED_RANK
3772 && ((aas
->type
== AS_ASSUMED_SIZE
3773 && (a
->expr
->ref
== NULL
3774 || (a
->expr
->ref
->type
== REF_ARRAY
3775 && a
->expr
->ref
->u
.ar
.type
== AR_FULL
)))
3776 || (aas
->type
== AS_ASSUMED_RANK
3778 && !allocatable_arg
))
3779 && (a
->expr
->ts
.type
== BT_CLASS
3780 || (a
->expr
->ts
.type
== BT_DERIVED
3781 && (gfc_is_finalizable (a
->expr
->ts
.u
.derived
, NULL
)
3782 || gfc_has_ultimate_allocatable (a
->expr
)
3783 || gfc_has_default_initializer
3784 (a
->expr
->ts
.u
.derived
)))))
3787 gfc_error ("Actual argument to assumed-rank INTENT(OUT) "
3788 "dummy %qs at %L cannot be of unknown size",
3789 f
->sym
->name
, where
);
3794 if (a
->expr
->expr_type
!= EXPR_NULL
)
3796 int cmp
= compare_pointer (f
->sym
, a
->expr
);
3797 bool pre2008
= ((gfc_option
.allow_std
& GFC_STD_F2008
) == 0);
3799 if (pre2008
&& cmp
== 0)
3802 gfc_error ("Actual argument for %qs at %L must be a pointer",
3803 f
->sym
->name
, &a
->expr
->where
);
3808 if (pre2008
&& cmp
== 2)
3811 gfc_error ("Fortran 2008: Non-pointer actual argument at %L to "
3812 "pointer dummy %qs", &a
->expr
->where
, f
->sym
->name
);
3817 if (!pre2008
&& cmp
== 0)
3820 gfc_error ("Actual argument for %qs at %L must be a pointer "
3821 "or a valid target for the dummy pointer in a "
3822 "pointer assignment statement",
3823 f
->sym
->name
, &a
->expr
->where
);
3830 /* Fortran 2008, C1242. */
3831 if (f
->sym
->attr
.pointer
&& gfc_is_coindexed (a
->expr
))
3834 gfc_error ("Coindexed actual argument at %L to pointer "
3836 &a
->expr
->where
, f
->sym
->name
);
3841 /* Fortran 2008, 12.5.2.5 (no constraint). */
3842 if (a
->expr
->expr_type
== EXPR_VARIABLE
3843 && f
->sym
->attr
.intent
!= INTENT_IN
3844 && f
->sym
->attr
.allocatable
3845 && gfc_is_coindexed (a
->expr
))
3848 gfc_error ("Coindexed actual argument at %L to allocatable "
3849 "dummy %qs requires INTENT(IN)",
3850 &a
->expr
->where
, f
->sym
->name
);
3855 /* Fortran 2008, C1237. */
3856 if (a
->expr
->expr_type
== EXPR_VARIABLE
3857 && (f
->sym
->attr
.asynchronous
|| f
->sym
->attr
.volatile_
)
3858 && gfc_is_coindexed (a
->expr
)
3859 && (a
->expr
->symtree
->n
.sym
->attr
.volatile_
3860 || a
->expr
->symtree
->n
.sym
->attr
.asynchronous
))
3863 gfc_error ("Coindexed ASYNCHRONOUS or VOLATILE actual argument at "
3864 "%L requires that dummy %qs has neither "
3865 "ASYNCHRONOUS nor VOLATILE", &a
->expr
->where
,
3871 /* Fortran 2008, 12.5.2.4 (no constraint). */
3872 if (a
->expr
->expr_type
== EXPR_VARIABLE
3873 && f
->sym
->attr
.intent
!= INTENT_IN
&& !f
->sym
->attr
.value
3874 && gfc_is_coindexed (a
->expr
)
3875 && gfc_has_ultimate_allocatable (a
->expr
))
3878 gfc_error ("Coindexed actual argument at %L with allocatable "
3879 "ultimate component to dummy %qs requires either VALUE "
3880 "or INTENT(IN)", &a
->expr
->where
, f
->sym
->name
);
3885 if (f
->sym
->ts
.type
== BT_CLASS
3886 && CLASS_DATA (f
->sym
)->attr
.allocatable
3887 && gfc_is_class_array_ref (a
->expr
, &full_array
)
3891 gfc_error ("Actual CLASS array argument for %qs must be a full "
3892 "array at %L", f
->sym
->name
, &a
->expr
->where
);
3898 if (a
->expr
->expr_type
!= EXPR_NULL
3899 && !compare_allocatable (f
->sym
, a
->expr
))
3902 gfc_error ("Actual argument for %qs must be ALLOCATABLE at %L",
3903 f
->sym
->name
, &a
->expr
->where
);
3908 if (a
->expr
->expr_type
== EXPR_FUNCTION
3909 && a
->expr
->value
.function
.esym
3910 && f
->sym
->attr
.allocatable
)
3913 gfc_error ("Actual argument for %qs at %L is a function result "
3914 "and the dummy argument is ALLOCATABLE",
3915 f
->sym
->name
, &a
->expr
->where
);
3920 /* Check intent = OUT/INOUT for definable actual argument. */
3921 if (!in_statement_function
3922 && (f
->sym
->attr
.intent
== INTENT_OUT
3923 || f
->sym
->attr
.intent
== INTENT_INOUT
))
3925 const char* context
= (where
3926 ? _("actual argument to INTENT = OUT/INOUT")
3929 if (((f
->sym
->ts
.type
== BT_CLASS
&& f
->sym
->attr
.class_ok
3930 && CLASS_DATA (f
->sym
)->attr
.class_pointer
)
3931 || (f
->sym
->ts
.type
!= BT_CLASS
&& f
->sym
->attr
.pointer
))
3932 && !gfc_check_vardef_context (a
->expr
, true, false, false, context
))
3937 if (!gfc_check_vardef_context (a
->expr
, false, false, false, context
))
3944 if ((f
->sym
->attr
.intent
== INTENT_OUT
3945 || f
->sym
->attr
.intent
== INTENT_INOUT
3946 || f
->sym
->attr
.volatile_
3947 || f
->sym
->attr
.asynchronous
)
3948 && gfc_has_vector_subscript (a
->expr
))
3951 gfc_error ("Array-section actual argument with vector "
3952 "subscripts at %L is incompatible with INTENT(OUT), "
3953 "INTENT(INOUT), VOLATILE or ASYNCHRONOUS attribute "
3954 "of the dummy argument %qs",
3955 &a
->expr
->where
, f
->sym
->name
);
3960 /* C1232 (R1221) For an actual argument which is an array section or
3961 an assumed-shape array, the dummy argument shall be an assumed-
3962 shape array, if the dummy argument has the VOLATILE attribute. */
3964 if (f
->sym
->attr
.volatile_
3965 && a
->expr
->expr_type
== EXPR_VARIABLE
3966 && a
->expr
->symtree
->n
.sym
->as
3967 && a
->expr
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SHAPE
3968 && !(fas
&& fas
->type
== AS_ASSUMED_SHAPE
))
3971 gfc_error ("Assumed-shape actual argument at %L is "
3972 "incompatible with the non-assumed-shape "
3973 "dummy argument %qs due to VOLATILE attribute",
3974 &a
->expr
->where
,f
->sym
->name
);
3979 /* Find the last array_ref. */
3980 actual_arr_ref
= NULL
;
3982 actual_arr_ref
= gfc_find_array_ref (a
->expr
, true);
3984 if (f
->sym
->attr
.volatile_
3985 && actual_arr_ref
&& actual_arr_ref
->type
== AR_SECTION
3986 && !(fas
&& fas
->type
== AS_ASSUMED_SHAPE
))
3989 gfc_error ("Array-section actual argument at %L is "
3990 "incompatible with the non-assumed-shape "
3991 "dummy argument %qs due to VOLATILE attribute",
3992 &a
->expr
->where
, f
->sym
->name
);
3997 /* C1233 (R1221) For an actual argument which is a pointer array, the
3998 dummy argument shall be an assumed-shape or pointer array, if the
3999 dummy argument has the VOLATILE attribute. */
4001 if (f
->sym
->attr
.volatile_
4002 && a
->expr
->expr_type
== EXPR_VARIABLE
4003 && a
->expr
->symtree
->n
.sym
->attr
.pointer
4004 && a
->expr
->symtree
->n
.sym
->as
4006 && (fas
->type
== AS_ASSUMED_SHAPE
4007 || f
->sym
->attr
.pointer
)))
4010 gfc_error ("Pointer-array actual argument at %L requires "
4011 "an assumed-shape or pointer-array dummy "
4012 "argument %qs due to VOLATILE attribute",
4013 &a
->expr
->where
,f
->sym
->name
);
4025 /* Give up now if we saw any bad argument. */
4029 /* Make sure missing actual arguments are optional. */
4031 for (f
= formal
; f
; f
= f
->next
, i
++)
4033 if (new_arg
[i
] != NULL
)
4038 gfc_error ("Missing alternate return spec in subroutine call "
4042 /* For CLASS, the optional attribute might be set at either location. */
4043 if (((f
->sym
->ts
.type
!= BT_CLASS
|| !CLASS_DATA (f
->sym
)->attr
.optional
)
4044 && !f
->sym
->attr
.optional
)
4045 || (in_statement_function
4046 && (f
->sym
->attr
.optional
4047 || (f
->sym
->ts
.type
== BT_CLASS
4048 && CLASS_DATA (f
->sym
)->attr
.optional
))))
4051 gfc_error ("Missing actual argument for argument %qs at %L",
4052 f
->sym
->name
, where
);
4057 /* We should have handled the cases where the formal arglist is null
4061 /* The argument lists are compatible. We now relink a new actual
4062 argument list with null arguments in the right places. The head
4063 of the list remains the head. */
4064 for (f
= formal
, i
= 0; f
; f
= f
->next
, i
++)
4065 if (new_arg
[i
] == NULL
)
4067 new_arg
[i
] = gfc_get_actual_arglist ();
4068 new_arg
[i
]->associated_dummy
= get_nonintrinsic_dummy_arg (f
);
4073 std::swap (*new_arg
[0], *actual
);
4074 std::swap (new_arg
[0], new_arg
[na
]);
4077 for (i
= 0; i
< n
- 1; i
++)
4078 new_arg
[i
]->next
= new_arg
[i
+ 1];
4080 new_arg
[i
]->next
= NULL
;
4082 if (*ap
== NULL
&& n
> 0)
4091 gfc_formal_arglist
*f
;
4092 gfc_actual_arglist
*a
;
4096 /* qsort comparison function for argument pairs, with the following
4098 - p->a->expr == NULL
4099 - p->a->expr->expr_type != EXPR_VARIABLE
4100 - by gfc_symbol pointer value (larger first). */
4103 pair_cmp (const void *p1
, const void *p2
)
4105 const gfc_actual_arglist
*a1
, *a2
;
4107 /* *p1 and *p2 are elements of the to-be-sorted array. */
4108 a1
= ((const argpair
*) p1
)->a
;
4109 a2
= ((const argpair
*) p2
)->a
;
4118 if (a1
->expr
->expr_type
!= EXPR_VARIABLE
)
4120 if (a2
->expr
->expr_type
!= EXPR_VARIABLE
)
4124 if (a2
->expr
->expr_type
!= EXPR_VARIABLE
)
4126 if (a1
->expr
->symtree
->n
.sym
> a2
->expr
->symtree
->n
.sym
)
4128 return a1
->expr
->symtree
->n
.sym
< a2
->expr
->symtree
->n
.sym
;
4132 /* Given two expressions from some actual arguments, test whether they
4133 refer to the same expression. The analysis is conservative.
4134 Returning false will produce no warning. */
4137 compare_actual_expr (gfc_expr
*e1
, gfc_expr
*e2
)
4139 const gfc_ref
*r1
, *r2
;
4142 || e1
->expr_type
!= EXPR_VARIABLE
4143 || e2
->expr_type
!= EXPR_VARIABLE
4144 || e1
->symtree
->n
.sym
!= e2
->symtree
->n
.sym
)
4147 /* TODO: improve comparison, see expr.cc:show_ref(). */
4148 for (r1
= e1
->ref
, r2
= e2
->ref
; r1
&& r2
; r1
= r1
->next
, r2
= r2
->next
)
4150 if (r1
->type
!= r2
->type
)
4155 if (r1
->u
.ar
.type
!= r2
->u
.ar
.type
)
4157 /* TODO: At the moment, consider only full arrays;
4158 we could do better. */
4159 if (r1
->u
.ar
.type
!= AR_FULL
|| r2
->u
.ar
.type
!= AR_FULL
)
4164 if (r1
->u
.c
.component
!= r2
->u
.c
.component
)
4172 if (e1
->symtree
->n
.sym
->ts
.type
== BT_COMPLEX
4173 && e1
->ts
.type
== BT_REAL
&& e2
->ts
.type
== BT_REAL
4174 && r1
->u
.i
!= r2
->u
.i
)
4179 gfc_internal_error ("compare_actual_expr(): Bad component code");
4188 /* Given formal and actual argument lists that correspond to one
4189 another, check that identical actual arguments aren't not
4190 associated with some incompatible INTENTs. */
4193 check_some_aliasing (gfc_formal_arglist
*f
, gfc_actual_arglist
*a
)
4195 sym_intent f1_intent
, f2_intent
;
4196 gfc_formal_arglist
*f1
;
4197 gfc_actual_arglist
*a1
;
4203 for (f1
= f
, a1
= a
;; f1
= f1
->next
, a1
= a1
->next
)
4205 if (f1
== NULL
&& a1
== NULL
)
4207 if (f1
== NULL
|| a1
== NULL
)
4208 gfc_internal_error ("check_some_aliasing(): List mismatch");
4213 p
= XALLOCAVEC (argpair
, n
);
4215 for (i
= 0, f1
= f
, a1
= a
; i
< n
; i
++, f1
= f1
->next
, a1
= a1
->next
)
4221 qsort (p
, n
, sizeof (argpair
), pair_cmp
);
4223 for (i
= 0; i
< n
; i
++)
4226 || p
[i
].a
->expr
->expr_type
!= EXPR_VARIABLE
4227 || p
[i
].a
->expr
->ts
.type
== BT_PROCEDURE
)
4229 f1_intent
= p
[i
].f
->sym
->attr
.intent
;
4230 for (j
= i
+ 1; j
< n
; j
++)
4232 /* Expected order after the sort. */
4233 if (!p
[j
].a
->expr
|| p
[j
].a
->expr
->expr_type
!= EXPR_VARIABLE
)
4234 gfc_internal_error ("check_some_aliasing(): corrupted data");
4236 /* Are the expression the same? */
4237 if (!compare_actual_expr (p
[i
].a
->expr
, p
[j
].a
->expr
))
4239 f2_intent
= p
[j
].f
->sym
->attr
.intent
;
4240 if ((f1_intent
== INTENT_IN
&& f2_intent
== INTENT_OUT
)
4241 || (f1_intent
== INTENT_OUT
&& f2_intent
== INTENT_IN
)
4242 || (f1_intent
== INTENT_OUT
&& f2_intent
== INTENT_OUT
))
4244 gfc_warning (0, "Same actual argument associated with INTENT(%s) "
4245 "argument %qs and INTENT(%s) argument %qs at %L",
4246 gfc_intent_string (f1_intent
), p
[i
].f
->sym
->name
,
4247 gfc_intent_string (f2_intent
), p
[j
].f
->sym
->name
,
4248 &p
[i
].a
->expr
->where
);
4258 /* Given formal and actual argument lists that correspond to one
4259 another, check that they are compatible in the sense that intents
4260 are not mismatched. */
4263 check_intents (gfc_formal_arglist
*f
, gfc_actual_arglist
*a
)
4265 sym_intent f_intent
;
4267 for (;; f
= f
->next
, a
= a
->next
)
4271 if (f
== NULL
&& a
== NULL
)
4273 if (f
== NULL
|| a
== NULL
)
4274 gfc_internal_error ("check_intents(): List mismatch");
4276 if (a
->expr
&& a
->expr
->expr_type
== EXPR_FUNCTION
4277 && a
->expr
->value
.function
.isym
4278 && a
->expr
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
4279 expr
= a
->expr
->value
.function
.actual
->expr
;
4283 if (expr
== NULL
|| expr
->expr_type
!= EXPR_VARIABLE
)
4286 f_intent
= f
->sym
->attr
.intent
;
4288 if (gfc_pure (NULL
) && gfc_impure_variable (expr
->symtree
->n
.sym
))
4290 if ((f
->sym
->ts
.type
== BT_CLASS
&& f
->sym
->attr
.class_ok
4291 && CLASS_DATA (f
->sym
)->attr
.class_pointer
)
4292 || (f
->sym
->ts
.type
!= BT_CLASS
&& f
->sym
->attr
.pointer
))
4294 gfc_error ("Procedure argument at %L is local to a PURE "
4295 "procedure and has the POINTER attribute",
4301 /* Fortran 2008, C1283. */
4302 if (gfc_pure (NULL
) && gfc_is_coindexed (expr
))
4304 if (f_intent
== INTENT_INOUT
|| f_intent
== INTENT_OUT
)
4306 gfc_error ("Coindexed actual argument at %L in PURE procedure "
4307 "is passed to an INTENT(%s) argument",
4308 &expr
->where
, gfc_intent_string (f_intent
));
4312 if ((f
->sym
->ts
.type
== BT_CLASS
&& f
->sym
->attr
.class_ok
4313 && CLASS_DATA (f
->sym
)->attr
.class_pointer
)
4314 || (f
->sym
->ts
.type
!= BT_CLASS
&& f
->sym
->attr
.pointer
))
4316 gfc_error ("Coindexed actual argument at %L in PURE procedure "
4317 "is passed to a POINTER dummy argument",
4323 /* F2008, Section 12.5.2.4. */
4324 if (expr
->ts
.type
== BT_CLASS
&& f
->sym
->ts
.type
== BT_CLASS
4325 && gfc_is_coindexed (expr
))
4327 gfc_error ("Coindexed polymorphic actual argument at %L is passed "
4328 "polymorphic dummy argument %qs",
4329 &expr
->where
, f
->sym
->name
);
4338 /* Check how a procedure is used against its interface. If all goes
4339 well, the actual argument list will also end up being properly
4343 gfc_procedure_use (gfc_symbol
*sym
, gfc_actual_arglist
**ap
, locus
*where
)
4345 gfc_actual_arglist
*a
;
4346 gfc_formal_arglist
*dummy_args
;
4347 bool implicit
= false;
4349 /* Warn about calls with an implicit interface. Special case
4350 for calling a ISO_C_BINDING because c_loc and c_funloc
4351 are pseudo-unknown. Additionally, warn about procedures not
4352 explicitly declared at all if requested. */
4353 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
&& !sym
->attr
.is_iso_c
)
4355 bool has_implicit_none_export
= false;
4357 if (sym
->attr
.proc
== PROC_UNKNOWN
)
4358 for (gfc_namespace
*ns
= sym
->ns
; ns
; ns
= ns
->parent
)
4359 if (ns
->has_implicit_none_export
)
4361 has_implicit_none_export
= true;
4364 if (has_implicit_none_export
)
4367 = gfc_lookup_function_fuzzy (sym
->name
, sym
->ns
->sym_root
);
4369 gfc_error ("Procedure %qs called at %L is not explicitly declared"
4370 "; did you mean %qs?",
4371 sym
->name
, where
, guessed
);
4373 gfc_error ("Procedure %qs called at %L is not explicitly declared",
4377 if (warn_implicit_interface
)
4378 gfc_warning (OPT_Wimplicit_interface
,
4379 "Procedure %qs called with an implicit interface at %L",
4381 else if (warn_implicit_procedure
&& sym
->attr
.proc
== PROC_UNKNOWN
)
4382 gfc_warning (OPT_Wimplicit_procedure
,
4383 "Procedure %qs called at %L is not explicitly declared",
4385 gfc_find_proc_namespace (sym
->ns
)->implicit_interface_calls
= 1;
4388 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
)
4390 if (sym
->attr
.pointer
)
4392 gfc_error ("The pointer object %qs at %L must have an explicit "
4393 "function interface or be declared as array",
4398 if (sym
->attr
.allocatable
&& !sym
->attr
.external
)
4400 gfc_error ("The allocatable object %qs at %L must have an explicit "
4401 "function interface or be declared as array",
4406 if (sym
->attr
.allocatable
)
4408 gfc_error ("Allocatable function %qs at %L must have an explicit "
4409 "function interface", sym
->name
, where
);
4413 for (a
= *ap
; a
; a
= a
->next
)
4415 if (a
->expr
&& a
->expr
->error
)
4418 /* F2018, 15.4.2.2 Explicit interface is required for a
4419 polymorphic dummy argument, so there is no way to
4420 legally have a class appear in an argument with an
4421 implicit interface. */
4423 if (implicit
&& a
->expr
&& a
->expr
->ts
.type
== BT_CLASS
)
4425 gfc_error ("Explicit interface required for polymorphic "
4426 "argument at %L",&a
->expr
->where
);
4431 /* Skip g77 keyword extensions like %VAL, %REF, %LOC. */
4432 if (a
->name
!= NULL
&& a
->name
[0] != '%')
4434 gfc_error ("Keyword argument requires explicit interface "
4435 "for procedure %qs at %L", sym
->name
, &a
->expr
->where
);
4439 /* TS 29113, 6.2. */
4440 if (a
->expr
&& a
->expr
->ts
.type
== BT_ASSUMED
4441 && sym
->intmod_sym_id
!= ISOCBINDING_LOC
)
4443 gfc_error ("Assumed-type argument %s at %L requires an explicit "
4444 "interface", a
->expr
->symtree
->n
.sym
->name
,
4450 /* F2008, C1303 and C1304. */
4452 && (a
->expr
->ts
.type
== BT_DERIVED
|| a
->expr
->ts
.type
== BT_CLASS
)
4453 && a
->expr
->ts
.u
.derived
4454 && ((a
->expr
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
4455 && a
->expr
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
4456 || gfc_expr_attr (a
->expr
).lock_comp
))
4458 gfc_error ("Actual argument of LOCK_TYPE or with LOCK_TYPE "
4459 "component at %L requires an explicit interface for "
4460 "procedure %qs", &a
->expr
->where
, sym
->name
);
4466 && (a
->expr
->ts
.type
== BT_DERIVED
|| a
->expr
->ts
.type
== BT_CLASS
)
4467 && a
->expr
->ts
.u
.derived
4468 && ((a
->expr
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
4469 && a
->expr
->ts
.u
.derived
->intmod_sym_id
4470 == ISOFORTRAN_EVENT_TYPE
)
4471 || gfc_expr_attr (a
->expr
).event_comp
))
4473 gfc_error ("Actual argument of EVENT_TYPE or with EVENT_TYPE "
4474 "component at %L requires an explicit interface for "
4475 "procedure %qs", &a
->expr
->where
, sym
->name
);
4480 if (a
->expr
&& a
->expr
->expr_type
== EXPR_NULL
4481 && a
->expr
->ts
.type
== BT_UNKNOWN
)
4483 gfc_error ("MOLD argument to NULL required at %L",
4489 if (a
->expr
&& a
->expr
->expr_type
== EXPR_NULL
)
4491 gfc_error ("Passing intrinsic NULL as actual argument at %L "
4492 "requires an explicit interface", &a
->expr
->where
);
4497 /* TS 29113, C407b. */
4498 if (a
->expr
&& a
->expr
->expr_type
== EXPR_VARIABLE
4499 && symbol_rank (a
->expr
->symtree
->n
.sym
) == -1)
4501 gfc_error ("Assumed-rank argument requires an explicit interface "
4502 "at %L", &a
->expr
->where
);
4511 dummy_args
= gfc_sym_get_dummy_args (sym
);
4513 /* For a statement function, check that types and type parameters of actual
4514 arguments and dummy arguments match. */
4515 if (!gfc_compare_actual_formal (ap
, dummy_args
, 0, sym
->attr
.elemental
,
4516 sym
->attr
.proc
== PROC_ST_FUNCTION
, where
))
4519 if (!check_intents (dummy_args
, *ap
))
4523 check_some_aliasing (dummy_args
, *ap
);
4529 /* Check how a procedure pointer component is used against its interface.
4530 If all goes well, the actual argument list will also end up being properly
4531 sorted. Completely analogous to gfc_procedure_use. */
4534 gfc_ppc_use (gfc_component
*comp
, gfc_actual_arglist
**ap
, locus
*where
)
4536 /* Warn about calls with an implicit interface. Special case
4537 for calling a ISO_C_BINDING because c_loc and c_funloc
4538 are pseudo-unknown. */
4539 if (warn_implicit_interface
4540 && comp
->attr
.if_source
== IFSRC_UNKNOWN
4541 && !comp
->attr
.is_iso_c
)
4542 gfc_warning (OPT_Wimplicit_interface
,
4543 "Procedure pointer component %qs called with an implicit "
4544 "interface at %L", comp
->name
, where
);
4546 if (comp
->attr
.if_source
== IFSRC_UNKNOWN
)
4548 gfc_actual_arglist
*a
;
4549 for (a
= *ap
; a
; a
= a
->next
)
4551 /* Skip g77 keyword extensions like %VAL, %REF, %LOC. */
4552 if (a
->name
!= NULL
&& a
->name
[0] != '%')
4554 gfc_error ("Keyword argument requires explicit interface "
4555 "for procedure pointer component %qs at %L",
4556 comp
->name
, &a
->expr
->where
);
4564 if (!gfc_compare_actual_formal (ap
, comp
->ts
.interface
->formal
, 0,
4565 comp
->attr
.elemental
, false, where
))
4568 check_intents (comp
->ts
.interface
->formal
, *ap
);
4570 check_some_aliasing (comp
->ts
.interface
->formal
, *ap
);
4574 /* Try if an actual argument list matches the formal list of a symbol,
4575 respecting the symbol's attributes like ELEMENTAL. This is used for
4576 GENERIC resolution. */
4579 gfc_arglist_matches_symbol (gfc_actual_arglist
** args
, gfc_symbol
* sym
)
4581 gfc_formal_arglist
*dummy_args
;
4584 if (sym
->attr
.flavor
!= FL_PROCEDURE
)
4587 dummy_args
= gfc_sym_get_dummy_args (sym
);
4589 r
= !sym
->attr
.elemental
;
4590 if (gfc_compare_actual_formal (args
, dummy_args
, r
, !r
, false, NULL
))
4592 check_intents (dummy_args
, *args
);
4594 check_some_aliasing (dummy_args
, *args
);
4602 /* Given an interface pointer and an actual argument list, search for
4603 a formal argument list that matches the actual. If found, returns
4604 a pointer to the symbol of the correct interface. Returns NULL if
4608 gfc_search_interface (gfc_interface
*intr
, int sub_flag
,
4609 gfc_actual_arglist
**ap
)
4611 gfc_symbol
*elem_sym
= NULL
;
4612 gfc_symbol
*null_sym
= NULL
;
4613 locus null_expr_loc
;
4614 gfc_actual_arglist
*a
;
4615 bool has_null_arg
= false;
4617 for (a
= *ap
; a
; a
= a
->next
)
4618 if (a
->expr
&& a
->expr
->expr_type
== EXPR_NULL
4619 && a
->expr
->ts
.type
== BT_UNKNOWN
)
4621 has_null_arg
= true;
4622 null_expr_loc
= a
->expr
->where
;
4626 for (; intr
; intr
= intr
->next
)
4628 if (gfc_fl_struct (intr
->sym
->attr
.flavor
))
4630 if (sub_flag
&& intr
->sym
->attr
.function
)
4632 if (!sub_flag
&& intr
->sym
->attr
.subroutine
)
4635 if (gfc_arglist_matches_symbol (ap
, intr
->sym
))
4637 if (has_null_arg
&& null_sym
)
4639 gfc_error ("MOLD= required in NULL() argument at %L: Ambiguity "
4640 "between specific functions %s and %s",
4641 &null_expr_loc
, null_sym
->name
, intr
->sym
->name
);
4644 else if (has_null_arg
)
4646 null_sym
= intr
->sym
;
4650 /* Satisfy 12.4.4.1 such that an elemental match has lower
4651 weight than a non-elemental match. */
4652 if (intr
->sym
->attr
.elemental
)
4654 elem_sym
= intr
->sym
;
4664 return elem_sym
? elem_sym
: NULL
;
4668 /* Do a brute force recursive search for a symbol. */
4670 static gfc_symtree
*
4671 find_symtree0 (gfc_symtree
*root
, gfc_symbol
*sym
)
4675 if (root
->n
.sym
== sym
)
4680 st
= find_symtree0 (root
->left
, sym
);
4681 if (root
->right
&& ! st
)
4682 st
= find_symtree0 (root
->right
, sym
);
4687 /* Find a symtree for a symbol. */
4690 gfc_find_sym_in_symtree (gfc_symbol
*sym
)
4695 /* First try to find it by name. */
4696 gfc_find_sym_tree (sym
->name
, gfc_current_ns
, 1, &st
);
4697 if (st
&& st
->n
.sym
== sym
)
4700 /* If it's been renamed, resort to a brute-force search. */
4701 /* TODO: avoid having to do this search. If the symbol doesn't exist
4702 in the symtree for the current namespace, it should probably be added. */
4703 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
4705 st
= find_symtree0 (ns
->sym_root
, sym
);
4709 gfc_internal_error ("Unable to find symbol %qs", sym
->name
);
4714 /* See if the arglist to an operator-call contains a derived-type argument
4715 with a matching type-bound operator. If so, return the matching specific
4716 procedure defined as operator-target as well as the base-object to use
4717 (which is the found derived-type argument with operator). The generic
4718 name, if any, is transmitted to the final expression via 'gname'. */
4720 static gfc_typebound_proc
*
4721 matching_typebound_op (gfc_expr
** tb_base
,
4722 gfc_actual_arglist
* args
,
4723 gfc_intrinsic_op op
, const char* uop
,
4724 const char ** gname
)
4726 gfc_actual_arglist
* base
;
4728 for (base
= args
; base
; base
= base
->next
)
4729 if (base
->expr
->ts
.type
== BT_DERIVED
|| base
->expr
->ts
.type
== BT_CLASS
)
4731 gfc_typebound_proc
* tb
;
4732 gfc_symbol
* derived
;
4735 while (base
->expr
->expr_type
== EXPR_OP
4736 && base
->expr
->value
.op
.op
== INTRINSIC_PARENTHESES
)
4737 base
->expr
= base
->expr
->value
.op
.op1
;
4739 if (base
->expr
->ts
.type
== BT_CLASS
)
4741 if (!base
->expr
->ts
.u
.derived
|| CLASS_DATA (base
->expr
) == NULL
4742 || !gfc_expr_attr (base
->expr
).class_ok
)
4744 derived
= CLASS_DATA (base
->expr
)->ts
.u
.derived
;
4747 derived
= base
->expr
->ts
.u
.derived
;
4749 if (op
== INTRINSIC_USER
)
4751 gfc_symtree
* tb_uop
;
4754 tb_uop
= gfc_find_typebound_user_op (derived
, &result
, uop
,
4763 tb
= gfc_find_typebound_intrinsic_op (derived
, &result
, op
,
4766 /* This means we hit a PRIVATE operator which is use-associated and
4767 should thus not be seen. */
4771 /* Look through the super-type hierarchy for a matching specific
4773 for (; tb
; tb
= tb
->overridden
)
4777 gcc_assert (tb
->is_generic
);
4778 for (g
= tb
->u
.generic
; g
; g
= g
->next
)
4781 gfc_actual_arglist
* argcopy
;
4784 gcc_assert (g
->specific
);
4785 if (g
->specific
->error
)
4788 target
= g
->specific
->u
.specific
->n
.sym
;
4790 /* Check if this arglist matches the formal. */
4791 argcopy
= gfc_copy_actual_arglist (args
);
4792 matches
= gfc_arglist_matches_symbol (&argcopy
, target
);
4793 gfc_free_actual_arglist (argcopy
);
4795 /* Return if we found a match. */
4798 *tb_base
= base
->expr
;
4799 *gname
= g
->specific_st
->name
;
4810 /* For the 'actual arglist' of an operator call and a specific typebound
4811 procedure that has been found the target of a type-bound operator, build the
4812 appropriate EXPR_COMPCALL and resolve it. We take this indirection over
4813 type-bound procedures rather than resolving type-bound operators 'directly'
4814 so that we can reuse the existing logic. */
4817 build_compcall_for_operator (gfc_expr
* e
, gfc_actual_arglist
* actual
,
4818 gfc_expr
* base
, gfc_typebound_proc
* target
,
4821 e
->expr_type
= EXPR_COMPCALL
;
4822 e
->value
.compcall
.tbp
= target
;
4823 e
->value
.compcall
.name
= gname
? gname
: "$op";
4824 e
->value
.compcall
.actual
= actual
;
4825 e
->value
.compcall
.base_object
= base
;
4826 e
->value
.compcall
.ignore_pass
= 1;
4827 e
->value
.compcall
.assign
= 0;
4828 if (e
->ts
.type
== BT_UNKNOWN
4829 && target
->function
)
4831 if (target
->is_generic
)
4832 e
->ts
= target
->u
.generic
->specific
->u
.specific
->n
.sym
->ts
;
4834 e
->ts
= target
->u
.specific
->n
.sym
->ts
;
4839 /* This subroutine is called when an expression is being resolved.
4840 The expression node in question is either a user defined operator
4841 or an intrinsic operator with arguments that aren't compatible
4842 with the operator. This subroutine builds an actual argument list
4843 corresponding to the operands, then searches for a compatible
4844 interface. If one is found, the expression node is replaced with
4845 the appropriate function call. We use the 'match' enum to specify
4846 whether a replacement has been made or not, or if an error occurred. */
4849 gfc_extend_expr (gfc_expr
*e
)
4851 gfc_actual_arglist
*actual
;
4857 gfc_typebound_proc
* tbo
;
4862 actual
= gfc_get_actual_arglist ();
4863 actual
->expr
= e
->value
.op
.op1
;
4867 if (e
->value
.op
.op2
!= NULL
)
4869 actual
->next
= gfc_get_actual_arglist ();
4870 actual
->next
->expr
= e
->value
.op
.op2
;
4873 i
= fold_unary_intrinsic (e
->value
.op
.op
);
4875 /* See if we find a matching type-bound operator. */
4876 if (i
== INTRINSIC_USER
)
4877 tbo
= matching_typebound_op (&tb_base
, actual
,
4878 i
, e
->value
.op
.uop
->name
, &gname
);
4882 #define CHECK_OS_COMPARISON(comp) \
4883 case INTRINSIC_##comp: \
4884 case INTRINSIC_##comp##_OS: \
4885 tbo = matching_typebound_op (&tb_base, actual, \
4886 INTRINSIC_##comp, NULL, &gname); \
4888 tbo = matching_typebound_op (&tb_base, actual, \
4889 INTRINSIC_##comp##_OS, NULL, &gname); \
4891 CHECK_OS_COMPARISON(EQ
)
4892 CHECK_OS_COMPARISON(NE
)
4893 CHECK_OS_COMPARISON(GT
)
4894 CHECK_OS_COMPARISON(GE
)
4895 CHECK_OS_COMPARISON(LT
)
4896 CHECK_OS_COMPARISON(LE
)
4897 #undef CHECK_OS_COMPARISON
4900 tbo
= matching_typebound_op (&tb_base
, actual
, i
, NULL
, &gname
);
4904 /* If there is a matching typebound-operator, replace the expression with
4905 a call to it and succeed. */
4908 gcc_assert (tb_base
);
4909 build_compcall_for_operator (e
, actual
, tb_base
, tbo
, gname
);
4911 if (!gfc_resolve_expr (e
))
4917 if (i
== INTRINSIC_USER
)
4919 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
4921 uop
= gfc_find_uop (e
->value
.op
.uop
->name
, ns
);
4925 sym
= gfc_search_interface (uop
->op
, 0, &actual
);
4932 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
4934 /* Due to the distinction between '==' and '.eq.' and friends, one has
4935 to check if either is defined. */
4938 #define CHECK_OS_COMPARISON(comp) \
4939 case INTRINSIC_##comp: \
4940 case INTRINSIC_##comp##_OS: \
4941 sym = gfc_search_interface (ns->op[INTRINSIC_##comp], 0, &actual); \
4943 sym = gfc_search_interface (ns->op[INTRINSIC_##comp##_OS], 0, &actual); \
4945 CHECK_OS_COMPARISON(EQ
)
4946 CHECK_OS_COMPARISON(NE
)
4947 CHECK_OS_COMPARISON(GT
)
4948 CHECK_OS_COMPARISON(GE
)
4949 CHECK_OS_COMPARISON(LT
)
4950 CHECK_OS_COMPARISON(LE
)
4951 #undef CHECK_OS_COMPARISON
4954 sym
= gfc_search_interface (ns
->op
[i
], 0, &actual
);
4961 /* F2018(15.4.3.4.2) requires that the use of unlimited polymorphic
4962 formal arguments does not override the intrinsic uses. */
4963 gfc_push_suppress_errors ();
4965 && (UNLIMITED_POLY (sym
->formal
->sym
)
4966 || (sym
->formal
->next
4967 && UNLIMITED_POLY (sym
->formal
->next
->sym
)))
4968 && !gfc_check_operator_interface (sym
, e
->value
.op
.op
, e
->where
))
4970 gfc_pop_suppress_errors ();
4973 /* TODO: Do an ambiguity-check and error if multiple matching interfaces are
4974 found rather than just taking the first one and not checking further. */
4978 /* Don't use gfc_free_actual_arglist(). */
4979 free (actual
->next
);
4984 /* Change the expression node to a function call. */
4985 e
->expr_type
= EXPR_FUNCTION
;
4986 e
->symtree
= gfc_find_sym_in_symtree (sym
);
4987 e
->value
.function
.actual
= actual
;
4988 e
->value
.function
.esym
= NULL
;
4989 e
->value
.function
.isym
= NULL
;
4990 e
->value
.function
.name
= NULL
;
4991 e
->user_operator
= 1;
4993 if (!gfc_resolve_expr (e
))
5000 /* Tries to replace an assignment code node with a subroutine call to the
5001 subroutine associated with the assignment operator. Return true if the node
5002 was replaced. On false, no error is generated. */
5005 gfc_extend_assign (gfc_code
*c
, gfc_namespace
*ns
)
5007 gfc_actual_arglist
*actual
;
5008 gfc_expr
*lhs
, *rhs
, *tb_base
;
5009 gfc_symbol
*sym
= NULL
;
5010 const char *gname
= NULL
;
5011 gfc_typebound_proc
* tbo
;
5016 /* Don't allow an intrinsic assignment with a BOZ rhs to be replaced. */
5017 if (c
->op
== EXEC_ASSIGN
5018 && c
->expr1
->expr_type
== EXPR_VARIABLE
5019 && c
->expr2
->expr_type
== EXPR_CONSTANT
&& c
->expr2
->ts
.type
== BT_BOZ
)
5022 /* Don't allow an intrinsic assignment to be replaced. */
5023 if (lhs
->ts
.type
!= BT_DERIVED
&& lhs
->ts
.type
!= BT_CLASS
5024 && (rhs
->rank
== 0 || rhs
->rank
== lhs
->rank
)
5025 && (lhs
->ts
.type
== rhs
->ts
.type
5026 || (gfc_numeric_ts (&lhs
->ts
) && gfc_numeric_ts (&rhs
->ts
))))
5029 actual
= gfc_get_actual_arglist ();
5032 actual
->next
= gfc_get_actual_arglist ();
5033 actual
->next
->expr
= rhs
;
5035 /* TODO: Ambiguity-check, see above for gfc_extend_expr. */
5037 /* See if we find a matching type-bound assignment. */
5038 tbo
= matching_typebound_op (&tb_base
, actual
, INTRINSIC_ASSIGN
,
5043 /* Success: Replace the expression with a type-bound call. */
5044 gcc_assert (tb_base
);
5045 c
->expr1
= gfc_get_expr ();
5046 build_compcall_for_operator (c
->expr1
, actual
, tb_base
, tbo
, gname
);
5047 c
->expr1
->value
.compcall
.assign
= 1;
5048 c
->expr1
->where
= c
->loc
;
5050 c
->op
= EXEC_COMPCALL
;
5054 /* See if we find an 'ordinary' (non-typebound) assignment procedure. */
5055 for (; ns
; ns
= ns
->parent
)
5057 sym
= gfc_search_interface (ns
->op
[INTRINSIC_ASSIGN
], 1, &actual
);
5064 /* Success: Replace the assignment with the call. */
5065 c
->op
= EXEC_ASSIGN_CALL
;
5066 c
->symtree
= gfc_find_sym_in_symtree (sym
);
5069 c
->ext
.actual
= actual
;
5073 /* Failure: No assignment procedure found. */
5074 free (actual
->next
);
5080 /* Make sure that the interface just parsed is not already present in
5081 the given interface list. Ambiguity isn't checked yet since module
5082 procedures can be present without interfaces. */
5085 gfc_check_new_interface (gfc_interface
*base
, gfc_symbol
*new_sym
, locus loc
)
5089 for (ip
= base
; ip
; ip
= ip
->next
)
5091 if (ip
->sym
== new_sym
)
5093 gfc_error ("Entity %qs at %L is already present in the interface",
5094 new_sym
->name
, &loc
);
5103 /* Add a symbol to the current interface. */
5106 gfc_add_interface (gfc_symbol
*new_sym
)
5108 gfc_interface
**head
, *intr
;
5112 switch (current_interface
.type
)
5114 case INTERFACE_NAMELESS
:
5115 case INTERFACE_ABSTRACT
:
5118 case INTERFACE_INTRINSIC_OP
:
5119 for (ns
= current_interface
.ns
; ns
; ns
= ns
->parent
)
5120 switch (current_interface
.op
)
5123 case INTRINSIC_EQ_OS
:
5124 if (!gfc_check_new_interface (ns
->op
[INTRINSIC_EQ
], new_sym
,
5126 || !gfc_check_new_interface (ns
->op
[INTRINSIC_EQ_OS
],
5127 new_sym
, gfc_current_locus
))
5132 case INTRINSIC_NE_OS
:
5133 if (!gfc_check_new_interface (ns
->op
[INTRINSIC_NE
], new_sym
,
5135 || !gfc_check_new_interface (ns
->op
[INTRINSIC_NE_OS
],
5136 new_sym
, gfc_current_locus
))
5141 case INTRINSIC_GT_OS
:
5142 if (!gfc_check_new_interface (ns
->op
[INTRINSIC_GT
],
5143 new_sym
, gfc_current_locus
)
5144 || !gfc_check_new_interface (ns
->op
[INTRINSIC_GT_OS
],
5145 new_sym
, gfc_current_locus
))
5150 case INTRINSIC_GE_OS
:
5151 if (!gfc_check_new_interface (ns
->op
[INTRINSIC_GE
],
5152 new_sym
, gfc_current_locus
)
5153 || !gfc_check_new_interface (ns
->op
[INTRINSIC_GE_OS
],
5154 new_sym
, gfc_current_locus
))
5159 case INTRINSIC_LT_OS
:
5160 if (!gfc_check_new_interface (ns
->op
[INTRINSIC_LT
],
5161 new_sym
, gfc_current_locus
)
5162 || !gfc_check_new_interface (ns
->op
[INTRINSIC_LT_OS
],
5163 new_sym
, gfc_current_locus
))
5168 case INTRINSIC_LE_OS
:
5169 if (!gfc_check_new_interface (ns
->op
[INTRINSIC_LE
],
5170 new_sym
, gfc_current_locus
)
5171 || !gfc_check_new_interface (ns
->op
[INTRINSIC_LE_OS
],
5172 new_sym
, gfc_current_locus
))
5177 if (!gfc_check_new_interface (ns
->op
[current_interface
.op
],
5178 new_sym
, gfc_current_locus
))
5182 head
= ¤t_interface
.ns
->op
[current_interface
.op
];
5185 case INTERFACE_GENERIC
:
5186 case INTERFACE_DTIO
:
5187 for (ns
= current_interface
.ns
; ns
; ns
= ns
->parent
)
5189 gfc_find_symbol (current_interface
.sym
->name
, ns
, 0, &sym
);
5193 if (!gfc_check_new_interface (sym
->generic
,
5194 new_sym
, gfc_current_locus
))
5198 head
= ¤t_interface
.sym
->generic
;
5201 case INTERFACE_USER_OP
:
5202 if (!gfc_check_new_interface (current_interface
.uop
->op
,
5203 new_sym
, gfc_current_locus
))
5206 head
= ¤t_interface
.uop
->op
;
5210 gfc_internal_error ("gfc_add_interface(): Bad interface type");
5213 intr
= gfc_get_interface ();
5214 intr
->sym
= new_sym
;
5215 intr
->where
= gfc_current_locus
;
5225 gfc_current_interface_head (void)
5227 switch (current_interface
.type
)
5229 case INTERFACE_INTRINSIC_OP
:
5230 return current_interface
.ns
->op
[current_interface
.op
];
5232 case INTERFACE_GENERIC
:
5233 case INTERFACE_DTIO
:
5234 return current_interface
.sym
->generic
;
5236 case INTERFACE_USER_OP
:
5237 return current_interface
.uop
->op
;
5246 gfc_set_current_interface_head (gfc_interface
*i
)
5248 switch (current_interface
.type
)
5250 case INTERFACE_INTRINSIC_OP
:
5251 current_interface
.ns
->op
[current_interface
.op
] = i
;
5254 case INTERFACE_GENERIC
:
5255 case INTERFACE_DTIO
:
5256 current_interface
.sym
->generic
= i
;
5259 case INTERFACE_USER_OP
:
5260 current_interface
.uop
->op
= i
;
5269 /* Gets rid of a formal argument list. We do not free symbols.
5270 Symbols are freed when a namespace is freed. */
5273 gfc_free_formal_arglist (gfc_formal_arglist
*p
)
5275 gfc_formal_arglist
*q
;
5285 /* Check that it is ok for the type-bound procedure 'proc' to override the
5286 procedure 'old', cf. F08:4.5.7.3. */
5289 gfc_check_typebound_override (gfc_symtree
* proc
, gfc_symtree
* old
)
5292 gfc_symbol
*proc_target
, *old_target
;
5293 unsigned proc_pass_arg
, old_pass_arg
, argpos
;
5294 gfc_formal_arglist
*proc_formal
, *old_formal
;
5298 /* This procedure should only be called for non-GENERIC proc. */
5299 gcc_assert (!proc
->n
.tb
->is_generic
);
5301 /* If the overwritten procedure is GENERIC, this is an error. */
5302 if (old
->n
.tb
->is_generic
)
5304 gfc_error ("Cannot overwrite GENERIC %qs at %L",
5305 old
->name
, &proc
->n
.tb
->where
);
5309 where
= proc
->n
.tb
->where
;
5310 proc_target
= proc
->n
.tb
->u
.specific
->n
.sym
;
5311 old_target
= old
->n
.tb
->u
.specific
->n
.sym
;
5313 /* Check that overridden binding is not NON_OVERRIDABLE. */
5314 if (old
->n
.tb
->non_overridable
)
5316 gfc_error ("%qs at %L overrides a procedure binding declared"
5317 " NON_OVERRIDABLE", proc
->name
, &where
);
5321 /* It's an error to override a non-DEFERRED procedure with a DEFERRED one. */
5322 if (!old
->n
.tb
->deferred
&& proc
->n
.tb
->deferred
)
5324 gfc_error ("%qs at %L must not be DEFERRED as it overrides a"
5325 " non-DEFERRED binding", proc
->name
, &where
);
5329 /* If the overridden binding is PURE, the overriding must be, too. */
5330 if (old_target
->attr
.pure
&& !proc_target
->attr
.pure
)
5332 gfc_error ("%qs at %L overrides a PURE procedure and must also be PURE",
5333 proc
->name
, &where
);
5337 /* If the overridden binding is ELEMENTAL, the overriding must be, too. If it
5338 is not, the overriding must not be either. */
5339 if (old_target
->attr
.elemental
&& !proc_target
->attr
.elemental
)
5341 gfc_error ("%qs at %L overrides an ELEMENTAL procedure and must also be"
5342 " ELEMENTAL", proc
->name
, &where
);
5345 if (!old_target
->attr
.elemental
&& proc_target
->attr
.elemental
)
5347 gfc_error ("%qs at %L overrides a non-ELEMENTAL procedure and must not"
5348 " be ELEMENTAL, either", proc
->name
, &where
);
5352 /* If the overridden binding is a SUBROUTINE, the overriding must also be a
5354 if (old_target
->attr
.subroutine
&& !proc_target
->attr
.subroutine
)
5356 gfc_error ("%qs at %L overrides a SUBROUTINE and must also be a"
5357 " SUBROUTINE", proc
->name
, &where
);
5361 /* If the overridden binding is a FUNCTION, the overriding must also be a
5362 FUNCTION and have the same characteristics. */
5363 if (old_target
->attr
.function
)
5365 if (!proc_target
->attr
.function
)
5367 gfc_error ("%qs at %L overrides a FUNCTION and must also be a"
5368 " FUNCTION", proc
->name
, &where
);
5372 if (!gfc_check_result_characteristics (proc_target
, old_target
,
5375 gfc_error ("Result mismatch for the overriding procedure "
5376 "%qs at %L: %s", proc
->name
, &where
, err
);
5381 /* If the overridden binding is PUBLIC, the overriding one must not be
5383 if (old
->n
.tb
->access
== ACCESS_PUBLIC
5384 && proc
->n
.tb
->access
== ACCESS_PRIVATE
)
5386 gfc_error ("%qs at %L overrides a PUBLIC procedure and must not be"
5387 " PRIVATE", proc
->name
, &where
);
5391 /* Compare the formal argument lists of both procedures. This is also abused
5392 to find the position of the passed-object dummy arguments of both
5393 bindings as at least the overridden one might not yet be resolved and we
5394 need those positions in the check below. */
5395 proc_pass_arg
= old_pass_arg
= 0;
5396 if (!proc
->n
.tb
->nopass
&& !proc
->n
.tb
->pass_arg
)
5398 if (!old
->n
.tb
->nopass
&& !old
->n
.tb
->pass_arg
)
5401 proc_formal
= gfc_sym_get_dummy_args (proc_target
);
5402 old_formal
= gfc_sym_get_dummy_args (old_target
);
5403 for ( ; proc_formal
&& old_formal
;
5404 proc_formal
= proc_formal
->next
, old_formal
= old_formal
->next
)
5406 if (proc
->n
.tb
->pass_arg
5407 && !strcmp (proc
->n
.tb
->pass_arg
, proc_formal
->sym
->name
))
5408 proc_pass_arg
= argpos
;
5409 if (old
->n
.tb
->pass_arg
5410 && !strcmp (old
->n
.tb
->pass_arg
, old_formal
->sym
->name
))
5411 old_pass_arg
= argpos
;
5413 /* Check that the names correspond. */
5414 if (strcmp (proc_formal
->sym
->name
, old_formal
->sym
->name
))
5416 gfc_error ("Dummy argument %qs of %qs at %L should be named %qs as"
5417 " to match the corresponding argument of the overridden"
5418 " procedure", proc_formal
->sym
->name
, proc
->name
, &where
,
5419 old_formal
->sym
->name
);
5423 check_type
= proc_pass_arg
!= argpos
&& old_pass_arg
!= argpos
;
5424 if (!gfc_check_dummy_characteristics (proc_formal
->sym
, old_formal
->sym
,
5425 check_type
, err
, sizeof(err
)))
5427 gfc_error_opt (0, "Argument mismatch for the overriding procedure "
5428 "%qs at %L: %s", proc
->name
, &where
, err
);
5434 if (proc_formal
|| old_formal
)
5436 gfc_error ("%qs at %L must have the same number of formal arguments as"
5437 " the overridden procedure", proc
->name
, &where
);
5441 /* If the overridden binding is NOPASS, the overriding one must also be
5443 if (old
->n
.tb
->nopass
&& !proc
->n
.tb
->nopass
)
5445 gfc_error ("%qs at %L overrides a NOPASS binding and must also be"
5446 " NOPASS", proc
->name
, &where
);
5450 /* If the overridden binding is PASS(x), the overriding one must also be
5451 PASS and the passed-object dummy arguments must correspond. */
5452 if (!old
->n
.tb
->nopass
)
5454 if (proc
->n
.tb
->nopass
)
5456 gfc_error ("%qs at %L overrides a binding with PASS and must also be"
5457 " PASS", proc
->name
, &where
);
5461 if (proc_pass_arg
!= old_pass_arg
)
5463 gfc_error ("Passed-object dummy argument of %qs at %L must be at"
5464 " the same position as the passed-object dummy argument of"
5465 " the overridden procedure", proc
->name
, &where
);
5474 /* The following three functions check that the formal arguments
5475 of user defined derived type IO procedures are compliant with
5476 the requirements of the standard, see F03:9.5.3.7.2 (F08:9.6.4.8.3). */
5479 check_dtio_arg_TKR_intent (gfc_symbol
*fsym
, bool typebound
, bt type
,
5480 int kind
, int rank
, sym_intent intent
)
5482 if (fsym
->ts
.type
!= type
)
5484 gfc_error ("DTIO dummy argument at %L must be of type %s",
5485 &fsym
->declared_at
, gfc_basic_typename (type
));
5489 if (fsym
->ts
.type
!= BT_CLASS
&& fsym
->ts
.type
!= BT_DERIVED
5490 && fsym
->ts
.kind
!= kind
)
5491 gfc_error ("DTIO dummy argument at %L must be of KIND = %d",
5492 &fsym
->declared_at
, kind
);
5496 && (((type
== BT_CLASS
) && CLASS_DATA (fsym
)->attr
.dimension
)
5497 || ((type
!= BT_CLASS
) && fsym
->attr
.dimension
)))
5498 gfc_error ("DTIO dummy argument at %L must be a scalar",
5499 &fsym
->declared_at
);
5501 && (fsym
->as
== NULL
|| fsym
->as
->type
!= AS_ASSUMED_SHAPE
))
5502 gfc_error ("DTIO dummy argument at %L must be an "
5503 "ASSUMED SHAPE ARRAY", &fsym
->declared_at
);
5505 if (type
== BT_CHARACTER
&& fsym
->ts
.u
.cl
->length
!= NULL
)
5506 gfc_error ("DTIO character argument at %L must have assumed length",
5507 &fsym
->declared_at
);
5509 if (fsym
->attr
.intent
!= intent
)
5510 gfc_error ("DTIO dummy argument at %L must have INTENT %s",
5511 &fsym
->declared_at
, gfc_code2string (intents
, (int)intent
));
5517 check_dtio_interface1 (gfc_symbol
*derived
, gfc_symtree
*tb_io_st
,
5518 bool typebound
, bool formatted
, int code
)
5520 gfc_symbol
*dtio_sub
, *generic_proc
, *fsym
;
5521 gfc_typebound_proc
*tb_io_proc
, *specific_proc
;
5522 gfc_interface
*intr
;
5523 gfc_formal_arglist
*formal
;
5526 bool read
= ((dtio_codes
)code
== DTIO_RF
)
5527 || ((dtio_codes
)code
== DTIO_RUF
);
5535 /* Typebound DTIO binding. */
5536 tb_io_proc
= tb_io_st
->n
.tb
;
5537 if (tb_io_proc
== NULL
)
5540 gcc_assert (tb_io_proc
->is_generic
);
5542 specific_proc
= tb_io_proc
->u
.generic
->specific
;
5543 if (specific_proc
== NULL
|| specific_proc
->is_generic
)
5546 dtio_sub
= specific_proc
->u
.specific
->n
.sym
;
5550 generic_proc
= tb_io_st
->n
.sym
;
5551 if (generic_proc
== NULL
|| generic_proc
->generic
== NULL
)
5554 for (intr
= tb_io_st
->n
.sym
->generic
; intr
; intr
= intr
->next
)
5556 if (intr
->sym
&& intr
->sym
->formal
&& intr
->sym
->formal
->sym
5557 && ((intr
->sym
->formal
->sym
->ts
.type
== BT_CLASS
5558 && CLASS_DATA (intr
->sym
->formal
->sym
)->ts
.u
.derived
5560 || (intr
->sym
->formal
->sym
->ts
.type
== BT_DERIVED
5561 && intr
->sym
->formal
->sym
->ts
.u
.derived
== derived
)))
5563 dtio_sub
= intr
->sym
;
5566 else if (intr
->sym
&& intr
->sym
->formal
&& !intr
->sym
->formal
->sym
)
5568 gfc_error ("Alternate return at %L is not permitted in a DTIO "
5569 "procedure", &intr
->sym
->declared_at
);
5574 if (dtio_sub
== NULL
)
5578 gcc_assert (dtio_sub
);
5579 if (!dtio_sub
->attr
.subroutine
)
5580 gfc_error ("DTIO procedure %qs at %L must be a subroutine",
5581 dtio_sub
->name
, &dtio_sub
->declared_at
);
5583 if (!dtio_sub
->resolve_symbol_called
)
5584 gfc_resolve_formal_arglist (dtio_sub
);
5587 for (formal
= dtio_sub
->formal
; formal
; formal
= formal
->next
)
5590 if (arg_num
< (formatted
? 6 : 4))
5592 gfc_error ("Too few dummy arguments in DTIO procedure %qs at %L",
5593 dtio_sub
->name
, &dtio_sub
->declared_at
);
5597 if (arg_num
> (formatted
? 6 : 4))
5599 gfc_error ("Too many dummy arguments in DTIO procedure %qs at %L",
5600 dtio_sub
->name
, &dtio_sub
->declared_at
);
5604 /* Now go through the formal arglist. */
5606 for (formal
= dtio_sub
->formal
; formal
; formal
= formal
->next
, arg_num
++)
5608 if (!formatted
&& arg_num
== 3)
5614 gfc_error ("Alternate return at %L is not permitted in a DTIO "
5615 "procedure", &dtio_sub
->declared_at
);
5622 type
= derived
->attr
.sequence
|| derived
->attr
.is_bind_c
?
5623 BT_DERIVED
: BT_CLASS
;
5625 intent
= read
? INTENT_INOUT
: INTENT_IN
;
5626 check_dtio_arg_TKR_intent (fsym
, typebound
, type
, kind
,
5632 kind
= gfc_default_integer_kind
;
5634 check_dtio_arg_TKR_intent (fsym
, typebound
, type
, kind
,
5637 case(3): /* IOTYPE */
5638 type
= BT_CHARACTER
;
5639 kind
= gfc_default_character_kind
;
5641 check_dtio_arg_TKR_intent (fsym
, typebound
, type
, kind
,
5644 case(4): /* VLIST */
5646 kind
= gfc_default_integer_kind
;
5648 check_dtio_arg_TKR_intent (fsym
, typebound
, type
, kind
,
5651 case(5): /* IOSTAT */
5653 kind
= gfc_default_integer_kind
;
5654 intent
= INTENT_OUT
;
5655 check_dtio_arg_TKR_intent (fsym
, typebound
, type
, kind
,
5658 case(6): /* IOMSG */
5659 type
= BT_CHARACTER
;
5660 kind
= gfc_default_character_kind
;
5661 intent
= INTENT_INOUT
;
5662 check_dtio_arg_TKR_intent (fsym
, typebound
, type
, kind
,
5669 derived
->attr
.has_dtio_procs
= 1;
5674 gfc_check_dtio_interfaces (gfc_symbol
*derived
)
5676 gfc_symtree
*tb_io_st
;
5681 if (derived
->attr
.is_class
== 1 || derived
->attr
.vtype
== 1)
5684 /* Check typebound DTIO bindings. */
5685 for (code
= 0; code
< 4; code
++)
5687 formatted
= ((dtio_codes
)code
== DTIO_RF
)
5688 || ((dtio_codes
)code
== DTIO_WF
);
5690 tb_io_st
= gfc_find_typebound_proc (derived
, &t
,
5691 gfc_code2string (dtio_procs
, code
),
5692 true, &derived
->declared_at
);
5693 if (tb_io_st
!= NULL
)
5694 check_dtio_interface1 (derived
, tb_io_st
, true, formatted
, code
);
5697 /* Check generic DTIO interfaces. */
5698 for (code
= 0; code
< 4; code
++)
5700 formatted
= ((dtio_codes
)code
== DTIO_RF
)
5701 || ((dtio_codes
)code
== DTIO_WF
);
5703 tb_io_st
= gfc_find_symtree (derived
->ns
->sym_root
,
5704 gfc_code2string (dtio_procs
, code
));
5705 if (tb_io_st
!= NULL
)
5706 check_dtio_interface1 (derived
, tb_io_st
, false, formatted
, code
);
5712 gfc_find_typebound_dtio_proc (gfc_symbol
*derived
, bool write
, bool formatted
)
5714 gfc_symtree
*tb_io_st
= NULL
;
5717 if (!derived
|| !derived
->resolve_symbol_called
5718 || derived
->attr
.flavor
!= FL_DERIVED
)
5721 /* Try to find a typebound DTIO binding. */
5722 if (formatted
== true)
5725 tb_io_st
= gfc_find_typebound_proc (derived
, &t
,
5726 gfc_code2string (dtio_procs
,
5729 &derived
->declared_at
);
5731 tb_io_st
= gfc_find_typebound_proc (derived
, &t
,
5732 gfc_code2string (dtio_procs
,
5735 &derived
->declared_at
);
5740 tb_io_st
= gfc_find_typebound_proc (derived
, &t
,
5741 gfc_code2string (dtio_procs
,
5744 &derived
->declared_at
);
5746 tb_io_st
= gfc_find_typebound_proc (derived
, &t
,
5747 gfc_code2string (dtio_procs
,
5750 &derived
->declared_at
);
5757 gfc_find_specific_dtio_proc (gfc_symbol
*derived
, bool write
, bool formatted
)
5759 gfc_symtree
*tb_io_st
= NULL
;
5760 gfc_symbol
*dtio_sub
= NULL
;
5761 gfc_symbol
*extended
;
5762 gfc_typebound_proc
*tb_io_proc
, *specific_proc
;
5764 tb_io_st
= gfc_find_typebound_dtio_proc (derived
, write
, formatted
);
5766 if (tb_io_st
!= NULL
)
5768 const char *genname
;
5771 tb_io_proc
= tb_io_st
->n
.tb
;
5772 gcc_assert (tb_io_proc
!= NULL
);
5773 gcc_assert (tb_io_proc
->is_generic
);
5774 gcc_assert (tb_io_proc
->u
.generic
->next
== NULL
);
5776 specific_proc
= tb_io_proc
->u
.generic
->specific
;
5777 gcc_assert (!specific_proc
->is_generic
);
5779 /* Go back and make sure that we have the right specific procedure.
5780 Here we most likely have a procedure from the parent type, which
5781 can be overridden in extensions. */
5782 genname
= tb_io_proc
->u
.generic
->specific_st
->name
;
5783 st
= gfc_find_typebound_proc (derived
, NULL
, genname
,
5784 true, &tb_io_proc
->where
);
5786 dtio_sub
= st
->n
.tb
->u
.specific
->n
.sym
;
5788 dtio_sub
= specific_proc
->u
.specific
->n
.sym
;
5793 /* If there is not a typebound binding, look for a generic
5795 for (extended
= derived
; extended
;
5796 extended
= gfc_get_derived_super_type (extended
))
5798 if (extended
== NULL
|| extended
->ns
== NULL
5799 || extended
->attr
.flavor
== FL_UNKNOWN
)
5802 if (formatted
== true)
5805 tb_io_st
= gfc_find_symtree (extended
->ns
->sym_root
,
5806 gfc_code2string (dtio_procs
,
5809 tb_io_st
= gfc_find_symtree (extended
->ns
->sym_root
,
5810 gfc_code2string (dtio_procs
,
5816 tb_io_st
= gfc_find_symtree (extended
->ns
->sym_root
,
5817 gfc_code2string (dtio_procs
,
5820 tb_io_st
= gfc_find_symtree (extended
->ns
->sym_root
,
5821 gfc_code2string (dtio_procs
,
5825 if (tb_io_st
!= NULL
5827 && tb_io_st
->n
.sym
->generic
)
5829 for (gfc_interface
*intr
= tb_io_st
->n
.sym
->generic
;
5830 intr
&& intr
->sym
; intr
= intr
->next
)
5832 if (intr
->sym
->formal
)
5834 gfc_symbol
*fsym
= intr
->sym
->formal
->sym
;
5835 if ((fsym
->ts
.type
== BT_CLASS
5836 && CLASS_DATA (fsym
)->ts
.u
.derived
== extended
)
5837 || (fsym
->ts
.type
== BT_DERIVED
5838 && fsym
->ts
.u
.derived
== extended
))
5840 dtio_sub
= intr
->sym
;
5850 && dtio_sub
->formal
->sym
->ts
.type
== BT_CLASS
5851 && derived
!= CLASS_DATA (dtio_sub
->formal
->sym
)->ts
.u
.derived
)
5852 gfc_find_derived_vtab (derived
);
5857 /* Helper function - if we do not find an interface for a procedure,
5858 construct it from the actual arglist. Luckily, this can only
5859 happen for call by reference, so the information we actually need
5860 to provide (and which would be impossible to guess from the call
5861 itself) is not actually needed. */
5864 gfc_get_formal_from_actual_arglist (gfc_symbol
*sym
,
5865 gfc_actual_arglist
*actual_args
)
5867 gfc_actual_arglist
*a
;
5868 gfc_formal_arglist
**f
;
5870 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
5873 /* Do not infer the formal from actual arguments if we are dealing with
5876 if (sym
->ts
.type
== BT_CLASS
)
5880 for (a
= actual_args
; a
!= NULL
; a
= a
->next
)
5882 (*f
) = gfc_get_formal_arglist ();
5885 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "_formal_%d", var_num
++);
5886 gfc_get_symbol (name
, gfc_current_ns
, &s
);
5887 if (a
->expr
->ts
.type
== BT_PROCEDURE
)
5889 gfc_symbol
*asym
= a
->expr
->symtree
->n
.sym
;
5890 s
->attr
.flavor
= FL_PROCEDURE
;
5891 if (asym
->attr
.function
)
5893 s
->attr
.function
= 1;
5896 s
->attr
.subroutine
= asym
->attr
.subroutine
;
5900 s
->ts
= a
->expr
->ts
;
5902 if (s
->ts
.type
== BT_CHARACTER
)
5903 s
->ts
.u
.cl
= gfc_get_charlen ();
5907 s
->ts
.is_c_interop
= 0;
5908 s
->attr
.flavor
= FL_VARIABLE
;
5909 if (a
->expr
->rank
> 0)
5911 s
->attr
.dimension
= 1;
5912 s
->as
= gfc_get_array_spec ();
5914 s
->as
->lower
[0] = gfc_get_int_expr (gfc_index_integer_kind
,
5915 &a
->expr
->where
, 1);
5916 s
->as
->upper
[0] = NULL
;
5917 s
->as
->type
= AS_ASSUMED_SIZE
;
5920 s
->maybe_array
= maybe_dummy_array_arg (a
->expr
);
5923 s
->attr
.artificial
= 1;
5924 s
->declared_at
= a
->expr
->where
;
5925 s
->attr
.intent
= INTENT_UNKNOWN
;
5927 gfc_commit_symbol (s
);
5929 else /* If a->expr is NULL, this is an alternate rerturn. */
5939 gfc_dummy_arg_get_name (gfc_dummy_arg
& dummy_arg
)
5941 switch (dummy_arg
.intrinsicness
)
5943 case GFC_INTRINSIC_DUMMY_ARG
:
5944 return dummy_arg
.u
.intrinsic
->name
;
5946 case GFC_NON_INTRINSIC_DUMMY_ARG
:
5947 return dummy_arg
.u
.non_intrinsic
->sym
->name
;
5955 const gfc_typespec
&
5956 gfc_dummy_arg_get_typespec (gfc_dummy_arg
& dummy_arg
)
5958 switch (dummy_arg
.intrinsicness
)
5960 case GFC_INTRINSIC_DUMMY_ARG
:
5961 return dummy_arg
.u
.intrinsic
->ts
;
5963 case GFC_NON_INTRINSIC_DUMMY_ARG
:
5964 return dummy_arg
.u
.non_intrinsic
->sym
->ts
;
5973 gfc_dummy_arg_is_optional (gfc_dummy_arg
& dummy_arg
)
5975 switch (dummy_arg
.intrinsicness
)
5977 case GFC_INTRINSIC_DUMMY_ARG
:
5978 return dummy_arg
.u
.intrinsic
->optional
;
5980 case GFC_NON_INTRINSIC_DUMMY_ARG
:
5981 return dummy_arg
.u
.non_intrinsic
->sym
->attr
.optional
;