Branch data Line data Source code
1 : : /* Deal with interfaces.
2 : : Copyright (C) 2000-2025 Free Software Foundation, Inc.
3 : : Contributed by Andy Vaught
4 : :
5 : : This file is part of GCC.
6 : :
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
10 : : version.
11 : :
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
15 : : for more details.
16 : :
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/>. */
20 : :
21 : :
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.
27 : :
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.
32 : :
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
35 : : own head pointer.
36 : :
37 : : Nameless interfaces:
38 : : Nameless interfaces create symbols with explicit interfaces within
39 : : the current namespace. They are otherwise unlinked.
40 : :
41 : : Generic interfaces:
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.
46 : :
47 : : User operators:
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.
51 : :
52 : : Extended intrinsics and assignment:
53 : : The head of these interface lists are stored in the containing namespace.
54 : :
55 : : Implicit interfaces:
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.
59 : :
60 : :
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. */
65 : :
66 : : #include "config.h"
67 : : #include "system.h"
68 : : #include "coretypes.h"
69 : : #include "options.h"
70 : : #include "gfortran.h"
71 : : #include "match.h"
72 : : #include "arith.h"
73 : :
74 : : /* The current_interface structure holds information about the
75 : : interface currently being parsed. This structure is saved and
76 : : restored during recursive interfaces. */
77 : :
78 : : gfc_interface_info current_interface;
79 : :
80 : :
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
84 : : with INTR. */
85 : :
86 : : static void
87 : 20475075 : free_interface_elements_until (gfc_interface *intr, gfc_interface *end)
88 : : {
89 : 20475075 : gfc_interface *next;
90 : :
91 : 20659644 : for (; intr != end; intr = next)
92 : : {
93 : 184569 : next = intr->next;
94 : 184569 : free (intr);
95 : : }
96 : 0 : }
97 : :
98 : :
99 : : /* Free a singly linked list of gfc_interface structures. */
100 : :
101 : : void
102 : 19833618 : gfc_free_interface (gfc_interface *intr)
103 : : {
104 : 19833618 : free_interface_elements_until (intr, nullptr);
105 : 19833618 : }
106 : :
107 : :
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. */
112 : :
113 : : void
114 : 8631117 : gfc_drop_interface_elements_before (gfc_interface **ifc_ptr,
115 : : gfc_interface *tail)
116 : : {
117 : 8631117 : if (ifc_ptr == nullptr)
118 : : return;
119 : :
120 : 641457 : free_interface_elements_until (*ifc_ptr, tail);
121 : 641457 : *ifc_ptr = tail;
122 : : }
123 : :
124 : :
125 : : /* Change the operators unary plus and minus into binary plus and
126 : : minus respectively, leaving the rest unchanged. */
127 : :
128 : : static gfc_intrinsic_op
129 : 2816 : fold_unary_intrinsic (gfc_intrinsic_op op)
130 : : {
131 : 0 : switch (op)
132 : : {
133 : 0 : case INTRINSIC_UPLUS:
134 : 0 : op = INTRINSIC_PLUS;
135 : 0 : break;
136 : 56 : case INTRINSIC_UMINUS:
137 : 56 : op = INTRINSIC_MINUS;
138 : 0 : break;
139 : : default:
140 : : break;
141 : : }
142 : :
143 : 2802 : return op;
144 : : }
145 : :
146 : :
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. */
150 : :
151 : : static gfc_intrinsic_op
152 : 390 : dtio_op (char* mode)
153 : : {
154 : 390 : if (strcmp (mode, "formatted") == 0)
155 : : return INTRINSIC_FORMATTED;
156 : 84 : if (strcmp (mode, "unformatted") == 0)
157 : 84 : return INTRINSIC_UNFORMATTED;
158 : : return INTRINSIC_NONE;
159 : : }
160 : :
161 : :
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. */
165 : :
166 : : match
167 : 26557 : gfc_match_generic_spec (interface_type *type,
168 : : char *name,
169 : : gfc_intrinsic_op *op)
170 : : {
171 : 26557 : char buffer[GFC_MAX_SYMBOL_LEN + 1];
172 : 26557 : match m;
173 : 26557 : gfc_intrinsic_op i;
174 : :
175 : 26557 : if (gfc_match (" assignment ( = )") == MATCH_YES)
176 : : {
177 : 497 : *type = INTERFACE_INTRINSIC_OP;
178 : 497 : *op = INTRINSIC_ASSIGN;
179 : 497 : return MATCH_YES;
180 : : }
181 : :
182 : 26060 : if (gfc_match (" operator ( %o )", &i) == MATCH_YES)
183 : : { /* Operator i/f */
184 : 747 : *type = INTERFACE_INTRINSIC_OP;
185 : 747 : *op = fold_unary_intrinsic (i);
186 : 747 : return MATCH_YES;
187 : : }
188 : :
189 : 25313 : *op = INTRINSIC_NONE;
190 : 25313 : if (gfc_match (" operator ( ") == MATCH_YES)
191 : : {
192 : 316 : m = gfc_match_defined_op_name (buffer, 1);
193 : 316 : if (m == MATCH_NO)
194 : 0 : goto syntax;
195 : 316 : if (m != MATCH_YES)
196 : : return MATCH_ERROR;
197 : :
198 : 316 : m = gfc_match_char (')');
199 : 316 : if (m == MATCH_NO)
200 : 0 : goto syntax;
201 : 316 : if (m != MATCH_YES)
202 : : return MATCH_ERROR;
203 : :
204 : 316 : strcpy (name, buffer);
205 : 316 : *type = INTERFACE_USER_OP;
206 : 316 : return MATCH_YES;
207 : : }
208 : :
209 : 24997 : if (gfc_match (" read ( %n )", buffer) == MATCH_YES)
210 : : {
211 : 154 : *op = dtio_op (buffer);
212 : 154 : if (*op == INTRINSIC_FORMATTED)
213 : : {
214 : 111 : strcpy (name, gfc_code2string (dtio_procs, DTIO_RF));
215 : 111 : *type = INTERFACE_DTIO;
216 : : }
217 : 154 : if (*op == INTRINSIC_UNFORMATTED)
218 : : {
219 : 43 : strcpy (name, gfc_code2string (dtio_procs, DTIO_RUF));
220 : 43 : *type = INTERFACE_DTIO;
221 : : }
222 : 154 : if (*op != INTRINSIC_NONE)
223 : : return MATCH_YES;
224 : : }
225 : :
226 : 24843 : if (gfc_match (" write ( %n )", buffer) == MATCH_YES)
227 : : {
228 : 236 : *op = dtio_op (buffer);
229 : 236 : if (*op == INTRINSIC_FORMATTED)
230 : : {
231 : 195 : strcpy (name, gfc_code2string (dtio_procs, DTIO_WF));
232 : 195 : *type = INTERFACE_DTIO;
233 : : }
234 : 236 : if (*op == INTRINSIC_UNFORMATTED)
235 : : {
236 : 41 : strcpy (name, gfc_code2string (dtio_procs, DTIO_WUF));
237 : 41 : *type = INTERFACE_DTIO;
238 : : }
239 : 236 : if (*op != INTRINSIC_NONE)
240 : : return MATCH_YES;
241 : : }
242 : :
243 : 24607 : if (gfc_match_name (buffer) == MATCH_YES)
244 : : {
245 : 19812 : strcpy (name, buffer);
246 : 19812 : *type = INTERFACE_GENERIC;
247 : 19812 : return MATCH_YES;
248 : : }
249 : :
250 : 4795 : *type = INTERFACE_NAMELESS;
251 : 4795 : return MATCH_YES;
252 : :
253 : 0 : syntax:
254 : 0 : gfc_error ("Syntax error in generic specification at %C");
255 : 0 : return MATCH_ERROR;
256 : : }
257 : :
258 : :
259 : : /* Match one of the five F95 forms of an interface statement. The
260 : : matcher for the abstract interface follows. */
261 : :
262 : : match
263 : 9365 : gfc_match_interface (void)
264 : : {
265 : 9365 : char name[GFC_MAX_SYMBOL_LEN + 1];
266 : 9365 : interface_type type;
267 : 9365 : gfc_symbol *sym;
268 : 9365 : gfc_intrinsic_op op;
269 : 9365 : match m;
270 : :
271 : 9365 : m = gfc_match_space ();
272 : :
273 : 9365 : if (gfc_match_generic_spec (&type, name, &op) == MATCH_ERROR)
274 : : return MATCH_ERROR;
275 : :
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 : 9365 : if (gfc_match_eos () != MATCH_YES
279 : 9365 : || (type != INTERFACE_NAMELESS && m != MATCH_YES))
280 : : {
281 : 0 : gfc_error ("Syntax error: Trailing garbage in INTERFACE statement "
282 : : "at %C");
283 : 0 : return MATCH_ERROR;
284 : : }
285 : :
286 : 9365 : current_interface.type = type;
287 : :
288 : 9365 : switch (type)
289 : : {
290 : 3887 : case INTERFACE_DTIO:
291 : 3887 : case INTERFACE_GENERIC:
292 : 3887 : if (gfc_get_symbol (name, NULL, &sym))
293 : : return MATCH_ERROR;
294 : :
295 : 3887 : if (!sym->attr.generic
296 : 3887 : && !gfc_add_generic (&sym->attr, sym->name, NULL))
297 : : return MATCH_ERROR;
298 : :
299 : 3886 : if (sym->attr.dummy)
300 : : {
301 : 0 : gfc_error ("Dummy procedure %qs at %C cannot have a "
302 : : "generic interface", sym->name);
303 : 0 : return MATCH_ERROR;
304 : : }
305 : :
306 : 3886 : current_interface.sym = gfc_new_block = sym;
307 : 3886 : break;
308 : :
309 : 155 : case INTERFACE_USER_OP:
310 : 155 : current_interface.uop = gfc_get_uop (name);
311 : 155 : break;
312 : :
313 : 530 : case INTERFACE_INTRINSIC_OP:
314 : 530 : current_interface.op = op;
315 : 530 : break;
316 : :
317 : : case INTERFACE_NAMELESS:
318 : : case INTERFACE_ABSTRACT:
319 : : break;
320 : : }
321 : :
322 : : return MATCH_YES;
323 : : }
324 : :
325 : :
326 : :
327 : : /* Match a F2003 abstract interface. */
328 : :
329 : : match
330 : 445 : gfc_match_abstract_interface (void)
331 : : {
332 : 445 : match m;
333 : :
334 : 445 : if (!gfc_notify_std (GFC_STD_F2003, "ABSTRACT INTERFACE at %C"))
335 : : return MATCH_ERROR;
336 : :
337 : 444 : m = gfc_match_eos ();
338 : :
339 : 444 : if (m != MATCH_YES)
340 : : {
341 : 1 : gfc_error ("Syntax error in ABSTRACT INTERFACE statement at %C");
342 : 1 : return MATCH_ERROR;
343 : : }
344 : :
345 : 443 : current_interface.type = INTERFACE_ABSTRACT;
346 : :
347 : 443 : return m;
348 : : }
349 : :
350 : :
351 : : /* Match the different sort of generic-specs that can be present after
352 : : the END INTERFACE itself. */
353 : :
354 : : match
355 : 562 : gfc_match_end_interface (void)
356 : : {
357 : 562 : char name[GFC_MAX_SYMBOL_LEN + 1];
358 : 562 : interface_type type;
359 : 562 : gfc_intrinsic_op op;
360 : 562 : match m;
361 : :
362 : 562 : m = gfc_match_space ();
363 : :
364 : 562 : if (gfc_match_generic_spec (&type, name, &op) == MATCH_ERROR)
365 : : return MATCH_ERROR;
366 : :
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 : 562 : if (gfc_match_eos () != MATCH_YES
370 : 562 : || (type != INTERFACE_NAMELESS && m != MATCH_YES))
371 : : {
372 : 0 : gfc_error ("Syntax error: Trailing garbage in END INTERFACE "
373 : : "statement at %C");
374 : 0 : return MATCH_ERROR;
375 : : }
376 : :
377 : 562 : m = MATCH_YES;
378 : :
379 : 562 : switch (current_interface.type)
380 : : {
381 : 0 : case INTERFACE_NAMELESS:
382 : 0 : case INTERFACE_ABSTRACT:
383 : 0 : if (type != INTERFACE_NAMELESS)
384 : : {
385 : 0 : gfc_error ("Expected a nameless interface at %C");
386 : 0 : m = MATCH_ERROR;
387 : : }
388 : :
389 : : break;
390 : :
391 : 137 : case INTERFACE_INTRINSIC_OP:
392 : 137 : if (type != current_interface.type || op != current_interface.op)
393 : : {
394 : :
395 : 14 : if (current_interface.op == INTRINSIC_ASSIGN)
396 : : {
397 : 0 : m = MATCH_ERROR;
398 : 0 : gfc_error ("Expected %<END INTERFACE ASSIGNMENT (=)%> at %C");
399 : : }
400 : : else
401 : : {
402 : 14 : const char *s1, *s2;
403 : 14 : s1 = gfc_op2string (current_interface.op);
404 : 14 : s2 = gfc_op2string (op);
405 : :
406 : : /* The following if-statements are used to enforce C1202
407 : : from F2003. */
408 : 14 : if ((strcmp(s1, "==") == 0 && strcmp (s2, ".eq.") == 0)
409 : 13 : || (strcmp(s1, ".eq.") == 0 && strcmp (s2, "==") == 0))
410 : : break;
411 : 12 : if ((strcmp(s1, "/=") == 0 && strcmp (s2, ".ne.") == 0)
412 : 11 : || (strcmp(s1, ".ne.") == 0 && strcmp (s2, "/=") == 0))
413 : : break;
414 : 10 : if ((strcmp(s1, "<=") == 0 && strcmp (s2, ".le.") == 0)
415 : 9 : || (strcmp(s1, ".le.") == 0 && strcmp (s2, "<=") == 0))
416 : : break;
417 : 8 : if ((strcmp(s1, "<") == 0 && strcmp (s2, ".lt.") == 0)
418 : 7 : || (strcmp(s1, ".lt.") == 0 && strcmp (s2, "<") == 0))
419 : : break;
420 : 6 : if ((strcmp(s1, ">=") == 0 && strcmp (s2, ".ge.") == 0)
421 : 5 : || (strcmp(s1, ".ge.") == 0 && strcmp (s2, ">=") == 0))
422 : : break;
423 : 4 : if ((strcmp(s1, ">") == 0 && strcmp (s2, ".gt.") == 0)
424 : 3 : || (strcmp(s1, ".gt.") == 0 && strcmp (s2, ">") == 0))
425 : : break;
426 : :
427 : 2 : m = MATCH_ERROR;
428 : 2 : if (strcmp(s2, "none") == 0)
429 : 1 : gfc_error ("Expecting %<END INTERFACE OPERATOR (%s)%> "
430 : : "at %C", s1);
431 : : else
432 : 1 : gfc_error ("Expecting %<END INTERFACE OPERATOR (%s)%> at %C, "
433 : : "but got %qs", s1, s2);
434 : : }
435 : :
436 : : }
437 : :
438 : : break;
439 : :
440 : 14 : case INTERFACE_USER_OP:
441 : : /* Comparing the symbol node names is OK because only use-associated
442 : : symbols can be renamed. */
443 : 14 : if (type != current_interface.type
444 : 14 : || strcmp (current_interface.uop->name, name) != 0)
445 : : {
446 : 0 : gfc_error ("Expecting %<END INTERFACE OPERATOR (.%s.)%> at %C",
447 : 0 : current_interface.uop->name);
448 : 0 : m = MATCH_ERROR;
449 : : }
450 : :
451 : : break;
452 : :
453 : 411 : case INTERFACE_DTIO:
454 : 411 : case INTERFACE_GENERIC:
455 : 411 : if (type != current_interface.type
456 : 411 : || strcmp (current_interface.sym->name, name) != 0)
457 : : {
458 : 0 : gfc_error ("Expecting %<END INTERFACE %s%> at %C",
459 : 0 : current_interface.sym->name);
460 : 0 : m = MATCH_ERROR;
461 : : }
462 : :
463 : : break;
464 : : }
465 : :
466 : : return m;
467 : : }
468 : :
469 : :
470 : : /* Return whether the component was defined anonymously. */
471 : :
472 : : static bool
473 : 10169 : is_anonymous_component (gfc_component *cmp)
474 : : {
475 : : /* Only UNION and MAP components are anonymous. In the case of a MAP,
476 : : the derived type symbol is FL_STRUCT and the component name looks like mM*.
477 : : This is the only case in which the second character of a component name is
478 : : uppercase. */
479 : 10169 : return cmp->ts.type == BT_UNION
480 : 10169 : || (cmp->ts.type == BT_DERIVED
481 : 3668 : && cmp->ts.u.derived->attr.flavor == FL_STRUCT
482 : 72 : && cmp->name[0] && cmp->name[1] && ISUPPER (cmp->name[1]));
483 : : }
484 : :
485 : :
486 : : /* Return whether the derived type was defined anonymously. */
487 : :
488 : : static bool
489 : 567903 : is_anonymous_dt (gfc_symbol *derived)
490 : : {
491 : : /* UNION and MAP types are always anonymous. Otherwise, only nested STRUCTURE
492 : : types can be anonymous. For anonymous MAP/STRUCTURE, we have FL_STRUCT
493 : : and the type name looks like XX*. This is the only case in which the
494 : : second character of a type name is uppercase. */
495 : 567903 : return derived->attr.flavor == FL_UNION
496 : 567903 : || (derived->attr.flavor == FL_STRUCT
497 : 3345 : && derived->name[0] && derived->name[1] && ISUPPER (derived->name[1]));
498 : : }
499 : :
500 : :
501 : : /* Compare components according to 4.4.2 of the Fortran standard. */
502 : :
503 : : static bool
504 : 5248 : compare_components (gfc_component *cmp1, gfc_component *cmp2,
505 : : gfc_symbol *derived1, gfc_symbol *derived2)
506 : : {
507 : : /* Compare names, but not for anonymous components such as UNION or MAP. */
508 : 4921 : if (!is_anonymous_component (cmp1) && !is_anonymous_component (cmp2)
509 : 9884 : && strcmp (cmp1->name, cmp2->name) != 0)
510 : : return false;
511 : :
512 : 4385 : if (cmp1->attr.access != cmp2->attr.access)
513 : : return false;
514 : :
515 : 4384 : if (cmp1->attr.pointer != cmp2->attr.pointer)
516 : : return false;
517 : :
518 : 4384 : if (cmp1->attr.dimension != cmp2->attr.dimension)
519 : : return false;
520 : :
521 : 4250 : if (cmp1->attr.codimension != cmp2->attr.codimension)
522 : : return false;
523 : :
524 : 4250 : if (cmp1->attr.allocatable != cmp2->attr.allocatable)
525 : : return false;
526 : :
527 : 4250 : if (cmp1->attr.dimension && gfc_compare_array_spec (cmp1->as, cmp2->as) == 0)
528 : : return false;
529 : :
530 : 3846 : if (cmp1->attr.codimension
531 : 3846 : && gfc_compare_array_spec (cmp1->as, cmp2->as) == 0)
532 : : return false;
533 : :
534 : 3846 : if (cmp1->ts.type == BT_CHARACTER && cmp2->ts.type == BT_CHARACTER)
535 : : {
536 : 75 : gfc_charlen *l1 = cmp1->ts.u.cl;
537 : 75 : gfc_charlen *l2 = cmp2->ts.u.cl;
538 : 75 : if (l1 && l2 && l1->length && l2->length
539 : 75 : && l1->length->expr_type == EXPR_CONSTANT
540 : 75 : && l2->length->expr_type == EXPR_CONSTANT
541 : 150 : && gfc_dep_compare_expr (l1->length, l2->length) != 0)
542 : : return false;
543 : : }
544 : :
545 : : /* Make sure that link lists do not put this function into an
546 : : endless recursive loop! */
547 : 1435 : if (!(cmp1->ts.type == BT_DERIVED && derived1 == cmp1->ts.u.derived)
548 : 3660 : && !(cmp2->ts.type == BT_DERIVED && derived2 == cmp2->ts.u.derived)
549 : 7501 : && !gfc_compare_types (&cmp1->ts, &cmp2->ts))
550 : : return false;
551 : :
552 : 3423 : else if ( (cmp1->ts.type == BT_DERIVED && derived1 == cmp1->ts.u.derived)
553 : 181 : && !(cmp2->ts.type == BT_DERIVED && derived2 == cmp2->ts.u.derived))
554 : : return false;
555 : :
556 : 3423 : else if (!(cmp1->ts.type == BT_DERIVED && derived1 == cmp1->ts.u.derived)
557 : 3242 : && (cmp2->ts.type == BT_DERIVED && derived2 == cmp2->ts.u.derived))
558 : : return false;
559 : :
560 : : return true;
561 : : }
562 : :
563 : :
564 : : /* Compare two union types by comparing the components of their maps.
565 : : Because unions and maps are anonymous their types get special internal
566 : : names; therefore the usual derived type comparison will fail on them.
567 : :
568 : : Returns nonzero if equal, as with gfc_compare_derived_types. Also as with
569 : : gfc_compare_derived_types, 'equal' is closer to meaning 'duplicate
570 : : definitions' than 'equivalent structure'. */
571 : :
572 : : static bool
573 : 793 : compare_union_types (gfc_symbol *un1, gfc_symbol *un2)
574 : : {
575 : 793 : gfc_component *map1, *map2, *cmp1, *cmp2;
576 : 793 : gfc_symbol *map1_t, *map2_t;
577 : :
578 : 793 : if (un1->attr.flavor != FL_UNION || un2->attr.flavor != FL_UNION)
579 : : return false;
580 : :
581 : 148 : if (un1->attr.zero_comp != un2->attr.zero_comp)
582 : : return false;
583 : :
584 : 148 : if (un1->attr.zero_comp)
585 : : return true;
586 : :
587 : 146 : map1 = un1->components;
588 : 146 : map2 = un2->components;
589 : :
590 : : /* In terms of 'equality' here we are worried about types which are
591 : : declared the same in two places, not types that represent equivalent
592 : : structures. (This is common because of FORTRAN's weird scoping rules.)
593 : : Though two unions with their maps in different orders could be equivalent,
594 : : we will say they are not equal for the purposes of this test; therefore
595 : : we compare the maps sequentially. */
596 : 229 : for (;;)
597 : : {
598 : 229 : map1_t = map1->ts.u.derived;
599 : 229 : map2_t = map2->ts.u.derived;
600 : :
601 : 229 : cmp1 = map1_t->components;
602 : 229 : cmp2 = map2_t->components;
603 : :
604 : : /* Protect against null components. */
605 : 229 : if (map1_t->attr.zero_comp != map2_t->attr.zero_comp)
606 : : return false;
607 : :
608 : 229 : if (map1_t->attr.zero_comp)
609 : : return true;
610 : :
611 : 609 : for (;;)
612 : : {
613 : : /* No two fields will ever point to the same map type unless they are
614 : : the same component, because one map field is created with its type
615 : : declaration. Therefore don't worry about recursion here. */
616 : : /* TODO: worry about recursion into parent types of the unions? */
617 : 609 : if (!compare_components (cmp1, cmp2, map1_t, map2_t))
618 : : return false;
619 : :
620 : 603 : cmp1 = cmp1->next;
621 : 603 : cmp2 = cmp2->next;
622 : :
623 : 603 : if (cmp1 == NULL && cmp2 == NULL)
624 : : break;
625 : 384 : if (cmp1 == NULL || cmp2 == NULL)
626 : : return false;
627 : : }
628 : :
629 : 219 : map1 = map1->next;
630 : 219 : map2 = map2->next;
631 : :
632 : 219 : if (map1 == NULL && map2 == NULL)
633 : : break;
634 : 83 : if (map1 == NULL || map2 == NULL)
635 : : return false;
636 : : }
637 : :
638 : : return true;
639 : : }
640 : :
641 : :
642 : :
643 : : /* Compare two derived types using the criteria in 4.4.2 of the standard,
644 : : recursing through gfc_compare_types for the components. */
645 : :
646 : : bool
647 : 581828 : gfc_compare_derived_types (gfc_symbol *derived1, gfc_symbol *derived2)
648 : : {
649 : 581828 : gfc_component *cmp1, *cmp2;
650 : :
651 : 581828 : if (derived1 == derived2)
652 : : return true;
653 : :
654 : 309060 : if (!derived1 || !derived2)
655 : 0 : gfc_internal_error ("gfc_compare_derived_types: invalid derived type");
656 : :
657 : 309060 : if (derived1->attr.unlimited_polymorphic
658 : 187 : && derived2->attr.unlimited_polymorphic)
659 : : return true;
660 : :
661 : 308887 : if (derived1->attr.unlimited_polymorphic
662 : 308887 : != derived2->attr.unlimited_polymorphic)
663 : : return false;
664 : :
665 : : /* Compare UNION types specially. */
666 : 308798 : if (derived1->attr.flavor == FL_UNION || derived2->attr.flavor == FL_UNION)
667 : 645 : return compare_union_types (derived1, derived2);
668 : :
669 : : /* Special case for comparing derived types across namespaces. If the
670 : : true names and module names are the same and the module name is
671 : : nonnull, then they are equal. */
672 : 308153 : if (strcmp (derived1->name, derived2->name) == 0
673 : 26496 : && derived1->module != NULL && derived2->module != NULL
674 : 24097 : && strcmp (derived1->module, derived2->module) == 0)
675 : : return true;
676 : :
677 : : /* Compare type via the rules of the standard. Both types must have the
678 : : SEQUENCE or BIND(C) attribute to be equal. We also compare types
679 : : recursively if they are class descriptors types or virtual tables types.
680 : : STRUCTUREs are special because they can be anonymous; therefore two
681 : : structures with different names may be equal. */
682 : :
683 : : /* Compare names, but not for anonymous types such as UNION or MAP. */
684 : 283387 : if (!is_anonymous_dt (derived1) && !is_anonymous_dt (derived2)
685 : 567548 : && strcmp (derived1->name, derived2->name) != 0)
686 : : return false;
687 : :
688 : 4343 : if (derived1->component_access == ACCESS_PRIVATE
689 : 4342 : || derived2->component_access == ACCESS_PRIVATE)
690 : : return false;
691 : :
692 : 4342 : if (!(derived1->attr.sequence && derived2->attr.sequence)
693 : 2583 : && !(derived1->attr.is_bind_c && derived2->attr.is_bind_c)
694 : 2572 : && !(derived1->attr.is_class && derived2->attr.is_class)
695 : 1667 : && !(derived1->attr.vtype && derived2->attr.vtype)
696 : 1475 : && !(derived1->attr.pdt_type && derived2->attr.pdt_type))
697 : : return false;
698 : :
699 : : /* Protect against null components. */
700 : 2867 : if (derived1->attr.zero_comp != derived2->attr.zero_comp)
701 : : return false;
702 : :
703 : 2858 : if (derived1->attr.zero_comp)
704 : : return true;
705 : :
706 : 2858 : cmp1 = derived1->components;
707 : 2858 : cmp2 = derived2->components;
708 : :
709 : : /* Since subtypes of SEQUENCE types must be SEQUENCE types as well, a
710 : : simple test can speed things up. Otherwise, lots of things have to
711 : : match. */
712 : 4639 : for (;;)
713 : : {
714 : 4639 : if (!compare_components (cmp1, cmp2, derived1, derived2))
715 : : return false;
716 : :
717 : 2820 : cmp1 = cmp1->next;
718 : 2820 : cmp2 = cmp2->next;
719 : :
720 : 2820 : if (cmp1 == NULL && cmp2 == NULL)
721 : : break;
722 : 1787 : if (cmp1 == NULL || cmp2 == NULL)
723 : : return false;
724 : : }
725 : :
726 : : return true;
727 : : }
728 : :
729 : :
730 : : /* Compare two typespecs, recursively if necessary. */
731 : :
732 : : bool
733 : 7210070 : gfc_compare_types (gfc_typespec *ts1, gfc_typespec *ts2)
734 : : {
735 : : /* See if one of the typespecs is a BT_VOID, which is what is being used
736 : : to allow the funcs like c_f_pointer to accept any pointer type.
737 : : TODO: Possibly should narrow this to just the one typespec coming in
738 : : that is for the formal arg, but oh well. */
739 : 7210070 : if (ts1->type == BT_VOID || ts2->type == BT_VOID)
740 : : return true;
741 : :
742 : : /* Special case for our C interop types. FIXME: There should be a
743 : : better way of doing this. When ISO C binding is cleared up,
744 : : this can probably be removed. See PR 57048. */
745 : :
746 : 7210046 : if ((ts1->type == BT_INTEGER
747 : 1836572 : && ts2->type == BT_DERIVED
748 : 5253 : && ts1->f90_type == BT_VOID
749 : 86 : && ts2->u.derived->from_intmod == INTMOD_ISO_C_BINDING
750 : 86 : && ts1->u.derived
751 : 86 : && strcmp (ts1->u.derived->name, ts2->u.derived->name) == 0)
752 : 7209961 : || (ts2->type == BT_INTEGER
753 : 1937452 : && ts1->type == BT_DERIVED
754 : 4838 : && ts2->f90_type == BT_VOID
755 : 84 : && ts1->u.derived->from_intmod == INTMOD_ISO_C_BINDING
756 : 84 : && ts2->u.derived
757 : 84 : && strcmp (ts1->u.derived->name, ts2->u.derived->name) == 0))
758 : : return true;
759 : :
760 : : /* The _data component is not always present, therefore check for its
761 : : presence before assuming, that its derived->attr is available.
762 : : When the _data component is not present, then nevertheless the
763 : : unlimited_polymorphic flag may be set in the derived type's attr. */
764 : 7209877 : if (ts1->type == BT_CLASS && ts1->u.derived->components
765 : 28999 : && ((ts1->u.derived->attr.is_class
766 : 28992 : && ts1->u.derived->components->ts.u.derived->attr
767 : 28992 : .unlimited_polymorphic)
768 : 23873 : || ts1->u.derived->attr.unlimited_polymorphic))
769 : : return true;
770 : :
771 : : /* F2003: C717 */
772 : 7204751 : if (ts2->type == BT_CLASS && ts1->type == BT_DERIVED
773 : 935 : && ts2->u.derived->components
774 : 934 : && ((ts2->u.derived->attr.is_class
775 : 932 : && ts2->u.derived->components->ts.u.derived->attr
776 : 932 : .unlimited_polymorphic)
777 : 893 : || ts2->u.derived->attr.unlimited_polymorphic)
778 : 41 : && (ts1->u.derived->attr.sequence || ts1->u.derived->attr.is_bind_c))
779 : : return true;
780 : :
781 : 7204725 : if (ts1->type != ts2->type
782 : 998057 : && ((ts1->type != BT_DERIVED && ts1->type != BT_CLASS)
783 : 70259 : || (ts2->type != BT_DERIVED && ts2->type != BT_CLASS)))
784 : : return false;
785 : :
786 : 6214531 : if (ts1->type == BT_UNION)
787 : 148 : return compare_union_types (ts1->u.derived, ts2->u.derived);
788 : :
789 : 6214383 : if (ts1->type != BT_DERIVED && ts1->type != BT_CLASS)
790 : 5958292 : return (ts1->kind == ts2->kind);
791 : :
792 : : /* Compare derived types. */
793 : 256091 : return gfc_type_compatible (ts1, ts2);
794 : : }
795 : :
796 : :
797 : : static bool
798 : 5125903 : compare_type (gfc_symbol *s1, gfc_symbol *s2)
799 : : {
800 : 5125903 : if (s2->attr.ext_attr & (1 << EXT_ATTR_NO_ARG_CHECK))
801 : : return true;
802 : :
803 : 4975535 : return gfc_compare_types (&s1->ts, &s2->ts) || s2->ts.type == BT_ASSUMED;
804 : : }
805 : :
806 : :
807 : : static bool
808 : 261719 : compare_type_characteristics (gfc_symbol *s1, gfc_symbol *s2)
809 : : {
810 : : /* TYPE and CLASS of the same declared type are type compatible,
811 : : but have different characteristics. */
812 : 261719 : if ((s1->ts.type == BT_CLASS && s2->ts.type == BT_DERIVED)
813 : 261711 : || (s1->ts.type == BT_DERIVED && s2->ts.type == BT_CLASS))
814 : : return false;
815 : :
816 : 261710 : return compare_type (s1, s2);
817 : : }
818 : :
819 : :
820 : : static bool
821 : 822847 : compare_rank (gfc_symbol *s1, gfc_symbol *s2)
822 : : {
823 : 822847 : gfc_array_spec *as1, *as2;
824 : 822847 : int r1, r2;
825 : :
826 : 822847 : if (s2->attr.ext_attr & (1 << EXT_ATTR_NO_ARG_CHECK))
827 : : return true;
828 : :
829 : 668439 : as1 = (s1->ts.type == BT_CLASS
830 : 4668 : && !s1->ts.u.derived->attr.unlimited_polymorphic)
831 : 677771 : ? CLASS_DATA (s1)->as : s1->as;
832 : 668457 : as2 = (s2->ts.type == BT_CLASS
833 : 4650 : && !s2->ts.u.derived->attr.unlimited_polymorphic)
834 : 677753 : ? CLASS_DATA (s2)->as : s2->as;
835 : :
836 : 673105 : r1 = as1 ? as1->rank : 0;
837 : 673105 : r2 = as2 ? as2->rank : 0;
838 : :
839 : 673105 : if (r1 != r2 && (!as2 || as2->type != AS_ASSUMED_RANK))
840 : 3678 : return false; /* Ranks differ. */
841 : :
842 : : return true;
843 : : }
844 : :
845 : :
846 : : /* Given two symbols that are formal arguments, compare their ranks
847 : : and types. Returns true if they have the same rank and type,
848 : : false otherwise. */
849 : :
850 : : static bool
851 : 4861153 : compare_type_rank (gfc_symbol *s1, gfc_symbol *s2)
852 : : {
853 : 4861153 : return compare_type (s1, s2) && compare_rank (s1, s2);
854 : : }
855 : :
856 : :
857 : : /* Given two symbols that are formal arguments, compare their types
858 : : and rank and their formal interfaces if they are both dummy
859 : : procedures. Returns true if the same, false if different. */
860 : :
861 : : static bool
862 : 4756458 : compare_type_rank_if (gfc_symbol *s1, gfc_symbol *s2)
863 : : {
864 : 4756458 : if (s1 == NULL || s2 == NULL)
865 : 120 : return (s1 == s2);
866 : :
867 : 4756338 : if (s1 == s2)
868 : : return true;
869 : :
870 : 4756338 : if (s1->attr.flavor != FL_PROCEDURE && s2->attr.flavor != FL_PROCEDURE)
871 : 4756264 : return compare_type_rank (s1, s2);
872 : :
873 : 74 : if (s1->attr.flavor != FL_PROCEDURE || s2->attr.flavor != FL_PROCEDURE)
874 : : return false;
875 : :
876 : : /* At this point, both symbols are procedures. It can happen that
877 : : external procedures are compared, where one is identified by usage
878 : : to be a function or subroutine but the other is not. Check TKR
879 : : nonetheless for these cases. */
880 : 6 : if (s1->attr.function == 0 && s1->attr.subroutine == 0)
881 : 2 : return s1->attr.external ? compare_type_rank (s1, s2) : false;
882 : :
883 : 4 : if (s2->attr.function == 0 && s2->attr.subroutine == 0)
884 : 0 : return s2->attr.external ? compare_type_rank (s1, s2) : false;
885 : :
886 : : /* Now the type of procedure has been identified. */
887 : 4 : if (s1->attr.function != s2->attr.function
888 : 4 : || s1->attr.subroutine != s2->attr.subroutine)
889 : : return false;
890 : :
891 : 4 : if (s1->attr.function && !compare_type_rank (s1, s2))
892 : : return false;
893 : :
894 : : /* Originally, gfortran recursed here to check the interfaces of passed
895 : : procedures. This is explicitly not required by the standard. */
896 : : return true;
897 : : }
898 : :
899 : :
900 : : /* Given a formal argument list and a keyword name, search the list
901 : : for that keyword. Returns the correct symbol node if found, NULL
902 : : if not found. */
903 : :
904 : : static gfc_symbol *
905 : 30976 : find_keyword_arg (const char *name, gfc_formal_arglist *f)
906 : : {
907 : 42882 : for (; f; f = f->next)
908 : 42882 : if (strcmp (f->sym->name, name) == 0)
909 : : return f->sym;
910 : :
911 : : return NULL;
912 : : }
913 : :
914 : :
915 : : /******** Interface checking subroutines **********/
916 : :
917 : :
918 : : /* Given an operator interface and the operator, make sure that all
919 : : interfaces for that operator are legal. */
920 : :
921 : : bool
922 : 3408 : gfc_check_operator_interface (gfc_symbol *sym, gfc_intrinsic_op op,
923 : : locus opwhere)
924 : : {
925 : 3408 : gfc_formal_arglist *formal;
926 : 3408 : sym_intent i1, i2;
927 : 3408 : bt t1, t2;
928 : 3408 : int args, r1, r2, k1, k2;
929 : :
930 : 3408 : gcc_assert (sym);
931 : :
932 : 3408 : args = 0;
933 : 3408 : t1 = t2 = BT_UNKNOWN;
934 : 3408 : i1 = i2 = INTENT_UNKNOWN;
935 : 3408 : r1 = r2 = -1;
936 : 3408 : k1 = k2 = -1;
937 : :
938 : 10192 : for (formal = gfc_sym_get_dummy_args (sym); formal; formal = formal->next)
939 : : {
940 : 6785 : gfc_symbol *fsym = formal->sym;
941 : 6785 : if (fsym == NULL)
942 : : {
943 : 1 : gfc_error ("Alternate return cannot appear in operator "
944 : : "interface at %L", &sym->declared_at);
945 : 1 : return false;
946 : : }
947 : 6784 : if (args == 0)
948 : : {
949 : 3408 : t1 = fsym->ts.type;
950 : 3408 : i1 = fsym->attr.intent;
951 : 3408 : r1 = (fsym->as != NULL) ? fsym->as->rank : 0;
952 : 3408 : k1 = fsym->ts.kind;
953 : : }
954 : 6784 : if (args == 1)
955 : : {
956 : 3376 : t2 = fsym->ts.type;
957 : 3376 : i2 = fsym->attr.intent;
958 : 3376 : r2 = (fsym->as != NULL) ? fsym->as->rank : 0;
959 : 3376 : k2 = fsym->ts.kind;
960 : : }
961 : 6784 : args++;
962 : : }
963 : :
964 : : /* Only +, - and .not. can be unary operators.
965 : : .not. cannot be a binary operator. */
966 : 3407 : if (args == 0 || args > 2 || (args == 1 && op != INTRINSIC_PLUS
967 : 30 : && op != INTRINSIC_MINUS
968 : 30 : && op != INTRINSIC_NOT)
969 : 3406 : || (args == 2 && op == INTRINSIC_NOT))
970 : : {
971 : 1 : if (op == INTRINSIC_ASSIGN)
972 : 0 : gfc_error ("Assignment operator interface at %L must have "
973 : : "two arguments", &sym->declared_at);
974 : : else
975 : 1 : gfc_error ("Operator interface at %L has the wrong number of arguments",
976 : : &sym->declared_at);
977 : 1 : return false;
978 : : }
979 : :
980 : : /* Check that intrinsics are mapped to functions, except
981 : : INTRINSIC_ASSIGN which should map to a subroutine. */
982 : 3406 : if (op == INTRINSIC_ASSIGN)
983 : : {
984 : 1245 : gfc_formal_arglist *dummy_args;
985 : :
986 : 1245 : if (!sym->attr.subroutine)
987 : : {
988 : 1 : gfc_error ("Assignment operator interface at %L must be "
989 : : "a SUBROUTINE", &sym->declared_at);
990 : 1 : return false;
991 : : }
992 : :
993 : : /* Allowed are (per F2003, 12.3.2.1.2 Defined assignments):
994 : : - First argument an array with different rank than second,
995 : : - First argument is a scalar and second an array,
996 : : - Types and kinds do not conform, or
997 : : - First argument is of derived type. */
998 : 1244 : dummy_args = gfc_sym_get_dummy_args (sym);
999 : 1244 : if (dummy_args->sym->ts.type != BT_DERIVED
1000 : 1015 : && dummy_args->sym->ts.type != BT_CLASS
1001 : 94 : && (r2 == 0 || r1 == r2)
1002 : 1333 : && (dummy_args->sym->ts.type == dummy_args->next->sym->ts.type
1003 : 84 : || (gfc_numeric_ts (&dummy_args->sym->ts)
1004 : 50 : && gfc_numeric_ts (&dummy_args->next->sym->ts))))
1005 : : {
1006 : 5 : gfc_error ("Assignment operator interface at %L must not redefine "
1007 : : "an INTRINSIC type assignment", &sym->declared_at);
1008 : 5 : return false;
1009 : : }
1010 : : }
1011 : : else
1012 : : {
1013 : 2161 : if (!sym->attr.function)
1014 : : {
1015 : 1 : gfc_error ("Intrinsic operator interface at %L must be a FUNCTION",
1016 : : &sym->declared_at);
1017 : 1 : return false;
1018 : : }
1019 : : }
1020 : :
1021 : : /* Check intents on operator interfaces. */
1022 : 3399 : if (op == INTRINSIC_ASSIGN)
1023 : : {
1024 : 1239 : if (i1 != INTENT_OUT && i1 != INTENT_INOUT)
1025 : : {
1026 : 0 : gfc_error ("First argument of defined assignment at %L must be "
1027 : : "INTENT(OUT) or INTENT(INOUT)", &sym->declared_at);
1028 : 0 : return false;
1029 : : }
1030 : :
1031 : 1239 : if (i2 != INTENT_IN)
1032 : : {
1033 : 0 : gfc_error ("Second argument of defined assignment at %L must be "
1034 : : "INTENT(IN)", &sym->declared_at);
1035 : 0 : return false;
1036 : : }
1037 : : }
1038 : : else
1039 : : {
1040 : 2160 : if (i1 != INTENT_IN)
1041 : : {
1042 : 0 : gfc_error ("First argument of operator interface at %L must be "
1043 : : "INTENT(IN)", &sym->declared_at);
1044 : 0 : return false;
1045 : : }
1046 : :
1047 : 2160 : if (args == 2 && i2 != INTENT_IN)
1048 : : {
1049 : 0 : gfc_error ("Second argument of operator interface at %L must be "
1050 : : "INTENT(IN)", &sym->declared_at);
1051 : 0 : return false;
1052 : : }
1053 : : }
1054 : :
1055 : : /* From now on, all we have to do is check that the operator definition
1056 : : doesn't conflict with an intrinsic operator. The rules for this
1057 : : game are defined in 7.1.2 and 7.1.3 of both F95 and F2003 standards,
1058 : : as well as 12.3.2.1.1 of Fortran 2003:
1059 : :
1060 : : "If the operator is an intrinsic-operator (R310), the number of
1061 : : function arguments shall be consistent with the intrinsic uses of
1062 : : that operator, and the types, kind type parameters, or ranks of the
1063 : : dummy arguments shall differ from those required for the intrinsic
1064 : : operation (7.1.2)." */
1065 : :
1066 : : #define IS_NUMERIC_TYPE(t) \
1067 : : ((t) == BT_INTEGER || (t) == BT_REAL || (t) == BT_COMPLEX)
1068 : :
1069 : : /* Unary ops are easy, do them first. */
1070 : 3399 : if (op == INTRINSIC_NOT)
1071 : : {
1072 : 5 : if (t1 == BT_LOGICAL)
1073 : 0 : goto bad_repl;
1074 : : else
1075 : : return true;
1076 : : }
1077 : :
1078 : 3394 : if (args == 1 && (op == INTRINSIC_PLUS || op == INTRINSIC_MINUS))
1079 : : {
1080 : 25 : if (IS_NUMERIC_TYPE (t1))
1081 : 0 : goto bad_repl;
1082 : : else
1083 : : return true;
1084 : : }
1085 : :
1086 : : /* Character intrinsic operators have same character kind, thus
1087 : : operator definitions with operands of different character kinds
1088 : : are always safe. */
1089 : 3369 : if (t1 == BT_CHARACTER && t2 == BT_CHARACTER && k1 != k2)
1090 : : return true;
1091 : :
1092 : : /* Intrinsic operators always perform on arguments of same rank,
1093 : : so different ranks is also always safe. (rank == 0) is an exception
1094 : : to that, because all intrinsic operators are elemental. */
1095 : 3369 : if (r1 != r2 && r1 != 0 && r2 != 0)
1096 : : return true;
1097 : :
1098 : 3303 : switch (op)
1099 : : {
1100 : 995 : case INTRINSIC_EQ:
1101 : 995 : case INTRINSIC_EQ_OS:
1102 : 995 : case INTRINSIC_NE:
1103 : 995 : case INTRINSIC_NE_OS:
1104 : 995 : if (t1 == BT_CHARACTER && t2 == BT_CHARACTER)
1105 : 0 : goto bad_repl;
1106 : : /* Fall through. */
1107 : :
1108 : 1697 : case INTRINSIC_PLUS:
1109 : 1697 : case INTRINSIC_MINUS:
1110 : 1697 : case INTRINSIC_TIMES:
1111 : 1697 : case INTRINSIC_DIVIDE:
1112 : 1697 : case INTRINSIC_POWER:
1113 : 1697 : if (IS_NUMERIC_TYPE (t1) && IS_NUMERIC_TYPE (t2))
1114 : 1 : goto bad_repl;
1115 : : break;
1116 : :
1117 : 278 : case INTRINSIC_GT:
1118 : 278 : case INTRINSIC_GT_OS:
1119 : 278 : case INTRINSIC_GE:
1120 : 278 : case INTRINSIC_GE_OS:
1121 : 278 : case INTRINSIC_LT:
1122 : 278 : case INTRINSIC_LT_OS:
1123 : 278 : case INTRINSIC_LE:
1124 : 278 : case INTRINSIC_LE_OS:
1125 : 278 : if (t1 == BT_CHARACTER && t2 == BT_CHARACTER)
1126 : 1 : goto bad_repl;
1127 : 277 : if ((t1 == BT_INTEGER || t1 == BT_REAL)
1128 : 0 : && (t2 == BT_INTEGER || t2 == BT_REAL))
1129 : 0 : goto bad_repl;
1130 : : break;
1131 : :
1132 : 36 : case INTRINSIC_CONCAT:
1133 : 36 : if (t1 == BT_CHARACTER && t2 == BT_CHARACTER)
1134 : 0 : goto bad_repl;
1135 : : break;
1136 : :
1137 : 56 : case INTRINSIC_AND:
1138 : 56 : case INTRINSIC_OR:
1139 : 56 : case INTRINSIC_EQV:
1140 : 56 : case INTRINSIC_NEQV:
1141 : 56 : if (t1 == BT_LOGICAL && t2 == BT_LOGICAL)
1142 : 0 : goto bad_repl;
1143 : : break;
1144 : :
1145 : : default:
1146 : : break;
1147 : : }
1148 : :
1149 : : return true;
1150 : :
1151 : : #undef IS_NUMERIC_TYPE
1152 : :
1153 : 2 : bad_repl:
1154 : 2 : gfc_error ("Operator interface at %L conflicts with intrinsic interface",
1155 : : &opwhere);
1156 : 2 : return false;
1157 : : }
1158 : :
1159 : :
1160 : : /* Given a pair of formal argument lists, we see if the two lists can
1161 : : be distinguished by counting the number of nonoptional arguments of
1162 : : a given type/rank in f1 and seeing if there are less then that
1163 : : number of those arguments in f2 (including optional arguments).
1164 : : Since this test is asymmetric, it has to be called twice to make it
1165 : : symmetric. Returns nonzero if the argument lists are incompatible
1166 : : by this test. This subroutine implements rule 1 of section F03:16.2.3.
1167 : : 'p1' and 'p2' are the PASS arguments of both procedures (if applicable). */
1168 : :
1169 : : static bool
1170 : 876379 : count_types_test (gfc_formal_arglist *f1, gfc_formal_arglist *f2,
1171 : : const char *p1, const char *p2)
1172 : : {
1173 : 876379 : int ac1, ac2, i, j, k, n1;
1174 : 876379 : gfc_formal_arglist *f;
1175 : :
1176 : 876379 : typedef struct
1177 : : {
1178 : : int flag;
1179 : : gfc_symbol *sym;
1180 : : }
1181 : : arginfo;
1182 : :
1183 : 876379 : arginfo *arg;
1184 : :
1185 : 876379 : n1 = 0;
1186 : :
1187 : 2470755 : for (f = f1; f; f = f->next)
1188 : 1594376 : n1++;
1189 : :
1190 : : /* Build an array of integers that gives the same integer to
1191 : : arguments of the same type/rank. */
1192 : 876379 : arg = XCNEWVEC (arginfo, n1);
1193 : :
1194 : 876379 : f = f1;
1195 : 3347134 : for (i = 0; i < n1; i++, f = f->next)
1196 : : {
1197 : 1594376 : arg[i].flag = -1;
1198 : 1594376 : arg[i].sym = f->sym;
1199 : : }
1200 : :
1201 : : k = 0;
1202 : :
1203 : 2470755 : for (i = 0; i < n1; i++)
1204 : : {
1205 : 1594376 : if (arg[i].flag != -1)
1206 : 250626 : continue;
1207 : :
1208 : 1343750 : if (arg[i].sym && (arg[i].sym->attr.optional
1209 : 1343561 : || (p1 && strcmp (arg[i].sym->name, p1) == 0)))
1210 : 401 : continue; /* Skip OPTIONAL and PASS arguments. */
1211 : :
1212 : 1343349 : arg[i].flag = k;
1213 : :
1214 : : /* Find other non-optional, non-pass arguments of the same type/rank. */
1215 : 2078208 : for (j = i + 1; j < n1; j++)
1216 : 734859 : if ((arg[j].sym == NULL
1217 : 734827 : || !(arg[j].sym->attr.optional
1218 : 152 : || (p1 && strcmp (arg[j].sym->name, p1) == 0)))
1219 : 1469364 : && (compare_type_rank_if (arg[i].sym, arg[j].sym)
1220 : 550315 : || compare_type_rank_if (arg[j].sym, arg[i].sym)))
1221 : 250626 : arg[j].flag = k;
1222 : :
1223 : 1343349 : k++;
1224 : : }
1225 : :
1226 : : /* Now loop over each distinct type found in f1. */
1227 : : k = 0;
1228 : 1173315 : bool rc = false;
1229 : :
1230 : 1173315 : for (i = 0; i < n1; i++)
1231 : : {
1232 : 1079939 : if (arg[i].flag != k)
1233 : 35328 : continue;
1234 : :
1235 : 1044611 : ac1 = 1;
1236 : 1779209 : for (j = i + 1; j < n1; j++)
1237 : 734598 : if (arg[j].flag == k)
1238 : 250605 : ac1++;
1239 : :
1240 : : /* Count the number of non-pass arguments in f2 with that type,
1241 : : including those that are optional. */
1242 : : ac2 = 0;
1243 : :
1244 : 2954051 : for (f = f2; f; f = f->next)
1245 : 439 : if ((!p2 || strcmp (f->sym->name, p2) != 0)
1246 : 1909667 : && (compare_type_rank_if (arg[i].sym, f->sym)
1247 : 1562378 : || compare_type_rank_if (f->sym, arg[i].sym)))
1248 : 401402 : ac2++;
1249 : :
1250 : 1044611 : if (ac1 > ac2)
1251 : : {
1252 : : rc = true;
1253 : : break;
1254 : : }
1255 : :
1256 : 261608 : k++;
1257 : : }
1258 : :
1259 : 876379 : free (arg);
1260 : :
1261 : 876379 : return rc;
1262 : : }
1263 : :
1264 : :
1265 : : /* Returns true if two dummy arguments are distinguishable due to their POINTER
1266 : : and ALLOCATABLE attributes according to F2018 section 15.4.3.4.5 (3).
1267 : : The function is asymmetric wrt to the arguments s1 and s2 and should always
1268 : : be called twice (with flipped arguments in the second call). */
1269 : :
1270 : : static bool
1271 : 24617 : compare_ptr_alloc(gfc_symbol *s1, gfc_symbol *s2)
1272 : : {
1273 : : /* Is s1 allocatable? */
1274 : 24617 : const bool a1 = s1->ts.type == BT_CLASS ?
1275 : 24617 : CLASS_DATA(s1)->attr.allocatable : s1->attr.allocatable;
1276 : : /* Is s2 a pointer? */
1277 : 24617 : const bool p2 = s2->ts.type == BT_CLASS ?
1278 : 24617 : CLASS_DATA(s2)->attr.class_pointer : s2->attr.pointer;
1279 : 24617 : return a1 && p2 && (s2->attr.intent != INTENT_IN);
1280 : : }
1281 : :
1282 : :
1283 : : /* Perform the correspondence test in rule (3) of F08:C1215.
1284 : : Returns zero if no argument is found that satisfies this rule,
1285 : : nonzero otherwise. 'p1' and 'p2' are the PASS arguments of both procedures
1286 : : (if applicable).
1287 : :
1288 : : This test is also not symmetric in f1 and f2 and must be called
1289 : : twice. This test finds problems caused by sorting the actual
1290 : : argument list with keywords. For example:
1291 : :
1292 : : INTERFACE FOO
1293 : : SUBROUTINE F1(A, B)
1294 : : INTEGER :: A ; REAL :: B
1295 : : END SUBROUTINE F1
1296 : :
1297 : : SUBROUTINE F2(B, A)
1298 : : INTEGER :: A ; REAL :: B
1299 : : END SUBROUTINE F1
1300 : : END INTERFACE FOO
1301 : :
1302 : : At this point, 'CALL FOO(A=1, B=1.0)' is ambiguous. */
1303 : :
1304 : : static bool
1305 : 31026 : generic_correspondence (gfc_formal_arglist *f1, gfc_formal_arglist *f2,
1306 : : const char *p1, const char *p2)
1307 : : {
1308 : 31026 : gfc_formal_arglist *f2_save, *g;
1309 : 31026 : gfc_symbol *sym;
1310 : :
1311 : 31026 : f2_save = f2;
1312 : :
1313 : 43000 : while (f1)
1314 : : {
1315 : 42950 : if (!f1->sym || f1->sym->attr.optional)
1316 : 4 : goto next;
1317 : :
1318 : 42946 : if (p1 && strcmp (f1->sym->name, p1) == 0)
1319 : 7 : f1 = f1->next;
1320 : 42946 : if (f2 && p2 && strcmp (f2->sym->name, p2) == 0)
1321 : 5 : f2 = f2->next;
1322 : :
1323 : 42942 : if (f2 != NULL && (compare_type_rank (f1->sym, f2->sym)
1324 : 30967 : || compare_type_rank (f2->sym, f1->sym))
1325 : 54924 : && !((gfc_option.allow_std & GFC_STD_F2008)
1326 : 11978 : && (compare_ptr_alloc(f1->sym, f2->sym)
1327 : 11971 : || compare_ptr_alloc(f2->sym, f1->sym))))
1328 : 11966 : goto next;
1329 : :
1330 : : /* Now search for a disambiguating keyword argument starting at
1331 : : the current non-match. */
1332 : 30980 : for (g = f1; g; g = g->next)
1333 : : {
1334 : 30976 : if (g->sym->attr.optional || (p1 && strcmp (g->sym->name, p1) == 0))
1335 : 0 : continue;
1336 : :
1337 : 30976 : sym = find_keyword_arg (g->sym->name, f2_save);
1338 : 30976 : if (sym == NULL || !compare_type_rank (g->sym, sym)
1339 : 30990 : || ((gfc_option.allow_std & GFC_STD_F2008)
1340 : 14 : && (compare_ptr_alloc(sym, g->sym)
1341 : 7 : || compare_ptr_alloc(g->sym, sym))))
1342 : 30976 : return true;
1343 : : }
1344 : :
1345 : 11974 : next:
1346 : 11974 : if (f1 != NULL)
1347 : 11970 : f1 = f1->next;
1348 : 11974 : if (f2 != NULL)
1349 : 11970 : f2 = f2->next;
1350 : : }
1351 : :
1352 : : return false;
1353 : : }
1354 : :
1355 : :
1356 : : static int
1357 : 470589 : symbol_rank (gfc_symbol *sym)
1358 : : {
1359 : 470589 : gfc_array_spec *as = NULL;
1360 : :
1361 : 470589 : if (sym->ts.type == BT_CLASS && CLASS_DATA (sym))
1362 : 13130 : as = CLASS_DATA (sym)->as;
1363 : : else
1364 : 457459 : as = sym->as;
1365 : :
1366 : 470589 : return as ? as->rank : 0;
1367 : : }
1368 : :
1369 : :
1370 : : /* Check if the characteristics of two dummy arguments match,
1371 : : cf. F08:12.3.2. */
1372 : :
1373 : : bool
1374 : 108031 : gfc_check_dummy_characteristics (gfc_symbol *s1, gfc_symbol *s2,
1375 : : bool type_must_agree, char *errmsg,
1376 : : int err_len)
1377 : : {
1378 : 108031 : if (s1 == NULL || s2 == NULL)
1379 : 27 : return s1 == s2 ? true : false;
1380 : :
1381 : 108004 : if (s1->attr.proc == PROC_ST_FUNCTION || s2->attr.proc == PROC_ST_FUNCTION)
1382 : : {
1383 : 1 : strncpy (errmsg, "Statement function", err_len);
1384 : 1 : return false;
1385 : : }
1386 : :
1387 : : /* Check type and rank. */
1388 : 108003 : if (type_must_agree)
1389 : : {
1390 : 106842 : if (!compare_type_characteristics (s1, s2)
1391 : 106842 : || !compare_type_characteristics (s2, s1))
1392 : : {
1393 : 24 : snprintf (errmsg, err_len, "Type mismatch in argument '%s' (%s/%s)",
1394 : : s1->name, gfc_dummy_typename (&s1->ts),
1395 : : gfc_dummy_typename (&s2->ts));
1396 : 24 : return false;
1397 : : }
1398 : 106818 : if (!compare_rank (s1, s2))
1399 : : {
1400 : 3 : snprintf (errmsg, err_len, "Rank mismatch in argument '%s' (%i/%i)",
1401 : : s1->name, symbol_rank (s1), symbol_rank (s2));
1402 : 3 : return false;
1403 : : }
1404 : : }
1405 : :
1406 : : /* A lot of information is missing for artificially generated
1407 : : formal arguments, let's not look into that. */
1408 : :
1409 : 107976 : if (!s1->attr.artificial && !s2->attr.artificial)
1410 : : {
1411 : : /* Check INTENT. */
1412 : 85423 : if (s1->attr.intent != s2->attr.intent)
1413 : : {
1414 : 5 : snprintf (errmsg, err_len, "INTENT mismatch in argument '%s'",
1415 : : s1->name);
1416 : 5 : return false;
1417 : : }
1418 : :
1419 : : /* Check OPTIONAL attribute. */
1420 : 85418 : if (s1->attr.optional != s2->attr.optional)
1421 : : {
1422 : 1 : snprintf (errmsg, err_len, "OPTIONAL mismatch in argument '%s'",
1423 : : s1->name);
1424 : 1 : return false;
1425 : : }
1426 : :
1427 : : /* Check ALLOCATABLE attribute. */
1428 : 85417 : if (s1->attr.allocatable != s2->attr.allocatable)
1429 : : {
1430 : 0 : snprintf (errmsg, err_len, "ALLOCATABLE mismatch in argument '%s'",
1431 : : s1->name);
1432 : 0 : return false;
1433 : : }
1434 : :
1435 : : /* Check POINTER attribute. */
1436 : 85417 : if (s1->attr.pointer != s2->attr.pointer)
1437 : : {
1438 : 0 : snprintf (errmsg, err_len, "POINTER mismatch in argument '%s'",
1439 : : s1->name);
1440 : 0 : return false;
1441 : : }
1442 : :
1443 : : /* Check TARGET attribute. */
1444 : 85417 : if (s1->attr.target != s2->attr.target)
1445 : : {
1446 : 0 : snprintf (errmsg, err_len, "TARGET mismatch in argument '%s'",
1447 : : s1->name);
1448 : 0 : return false;
1449 : : }
1450 : :
1451 : : /* Check ASYNCHRONOUS attribute. */
1452 : 85417 : if (s1->attr.asynchronous != s2->attr.asynchronous)
1453 : : {
1454 : 1 : snprintf (errmsg, err_len, "ASYNCHRONOUS mismatch in argument '%s'",
1455 : : s1->name);
1456 : 1 : return false;
1457 : : }
1458 : :
1459 : : /* Check CONTIGUOUS attribute. */
1460 : 85416 : if (s1->attr.contiguous != s2->attr.contiguous)
1461 : : {
1462 : 1 : snprintf (errmsg, err_len, "CONTIGUOUS mismatch in argument '%s'",
1463 : : s1->name);
1464 : 1 : return false;
1465 : : }
1466 : :
1467 : : /* Check VALUE attribute. */
1468 : 85415 : if (s1->attr.value != s2->attr.value)
1469 : : {
1470 : 1 : snprintf (errmsg, err_len, "VALUE mismatch in argument '%s'",
1471 : : s1->name);
1472 : 1 : return false;
1473 : : }
1474 : :
1475 : : /* Check VOLATILE attribute. */
1476 : 85414 : if (s1->attr.volatile_ != s2->attr.volatile_)
1477 : : {
1478 : 1 : snprintf (errmsg, err_len, "VOLATILE mismatch in argument '%s'",
1479 : : s1->name);
1480 : 1 : return false;
1481 : : }
1482 : : }
1483 : :
1484 : : /* Check interface of dummy procedures. */
1485 : 107966 : if (s1->attr.flavor == FL_PROCEDURE)
1486 : : {
1487 : 120 : char err[200];
1488 : 120 : if (!gfc_compare_interfaces (s1, s2, s2->name, 0, 1, err, sizeof(err),
1489 : : NULL, NULL))
1490 : : {
1491 : 1 : snprintf (errmsg, err_len, "Interface mismatch in dummy procedure "
1492 : : "'%s': %s", s1->name, err);
1493 : 1 : return false;
1494 : : }
1495 : : }
1496 : :
1497 : : /* Check string length. */
1498 : 107965 : if (s1->ts.type == BT_CHARACTER
1499 : 2779 : && s1->ts.u.cl && s1->ts.u.cl->length
1500 : 883 : && s2->ts.u.cl && s2->ts.u.cl->length)
1501 : : {
1502 : 883 : int compval = gfc_dep_compare_expr (s1->ts.u.cl->length,
1503 : : s2->ts.u.cl->length);
1504 : 883 : switch (compval)
1505 : : {
1506 : 0 : case -1:
1507 : 0 : case 1:
1508 : 0 : case -3:
1509 : 0 : snprintf (errmsg, err_len, "Character length mismatch "
1510 : : "in argument '%s'", s1->name);
1511 : 0 : return false;
1512 : :
1513 : : case -2:
1514 : : /* FIXME: Implement a warning for this case.
1515 : : gfc_warning (0, "Possible character length mismatch in argument %qs",
1516 : : s1->name);*/
1517 : : break;
1518 : :
1519 : : case 0:
1520 : : break;
1521 : :
1522 : 0 : default:
1523 : 0 : gfc_internal_error ("check_dummy_characteristics: Unexpected result "
1524 : : "%i of gfc_dep_compare_expr", compval);
1525 : : break;
1526 : : }
1527 : : }
1528 : :
1529 : : /* Check array shape. */
1530 : 107965 : if (s1->as && s2->as)
1531 : : {
1532 : 17009 : int i, compval;
1533 : 17009 : gfc_expr *shape1, *shape2;
1534 : :
1535 : : /* Sometimes the ambiguity between deferred shape and assumed shape
1536 : : does not get resolved in module procedures, where the only explicit
1537 : : declaration of the dummy is in the interface. */
1538 : 17009 : if (s1->ns->proc_name && s1->ns->proc_name->attr.module_procedure
1539 : 109 : && s1->as->type == AS_ASSUMED_SHAPE
1540 : 65 : && s2->as->type == AS_DEFERRED)
1541 : : {
1542 : 7 : s2->as->type = AS_ASSUMED_SHAPE;
1543 : 14 : for (i = 0; i < s2->as->rank; i++)
1544 : 7 : if (s1->as->lower[i] != NULL)
1545 : 7 : s2->as->lower[i] = gfc_copy_expr (s1->as->lower[i]);
1546 : : }
1547 : :
1548 : 17009 : if (s1->as->type != s2->as->type)
1549 : : {
1550 : 3 : snprintf (errmsg, err_len, "Shape mismatch in argument '%s'",
1551 : : s1->name);
1552 : 3 : return false;
1553 : : }
1554 : :
1555 : 17006 : if (s1->as->corank != s2->as->corank)
1556 : : {
1557 : 1 : snprintf (errmsg, err_len, "Corank mismatch in argument '%s' (%i/%i)",
1558 : : s1->name, s1->as->corank, s2->as->corank);
1559 : 1 : return false;
1560 : : }
1561 : :
1562 : 17005 : if (s1->as->type == AS_EXPLICIT)
1563 : 1266 : for (i = 0; i < s1->as->rank + MAX (0, s1->as->corank-1); i++)
1564 : : {
1565 : 783 : shape1 = gfc_subtract (gfc_copy_expr (s1->as->upper[i]),
1566 : 783 : gfc_copy_expr (s1->as->lower[i]));
1567 : 783 : shape2 = gfc_subtract (gfc_copy_expr (s2->as->upper[i]),
1568 : 783 : gfc_copy_expr (s2->as->lower[i]));
1569 : 783 : compval = gfc_dep_compare_expr (shape1, shape2);
1570 : 783 : gfc_free_expr (shape1);
1571 : 783 : gfc_free_expr (shape2);
1572 : 783 : switch (compval)
1573 : : {
1574 : 2 : case -1:
1575 : 2 : case 1:
1576 : 2 : case -3:
1577 : 2 : if (i < s1->as->rank)
1578 : 2 : snprintf (errmsg, err_len, "Shape mismatch in dimension %i of"
1579 : : " argument '%s'", i + 1, s1->name);
1580 : : else
1581 : 0 : snprintf (errmsg, err_len, "Shape mismatch in codimension %i "
1582 : 0 : "of argument '%s'", i - s1->as->rank + 1, s1->name);
1583 : 2 : return false;
1584 : :
1585 : : case -2:
1586 : : /* FIXME: Implement a warning for this case.
1587 : : gfc_warning (0, "Possible shape mismatch in argument %qs",
1588 : : s1->name);*/
1589 : : break;
1590 : :
1591 : : case 0:
1592 : : break;
1593 : :
1594 : 0 : default:
1595 : 0 : gfc_internal_error ("check_dummy_characteristics: Unexpected "
1596 : : "result %i of gfc_dep_compare_expr",
1597 : : compval);
1598 : 781 : break;
1599 : : }
1600 : : }
1601 : : }
1602 : :
1603 : : return true;
1604 : : }
1605 : :
1606 : :
1607 : : /* Check if the characteristics of two function results match,
1608 : : cf. F08:12.3.3. */
1609 : :
1610 : : bool
1611 : 48295 : gfc_check_result_characteristics (gfc_symbol *s1, gfc_symbol *s2,
1612 : : char *errmsg, int err_len)
1613 : : {
1614 : 48295 : gfc_symbol *r1, *r2;
1615 : :
1616 : 48295 : if (s1->ts.interface && s1->ts.interface->result)
1617 : : r1 = s1->ts.interface->result;
1618 : : else
1619 : 47990 : r1 = s1->result ? s1->result : s1;
1620 : :
1621 : 48295 : if (s2->ts.interface && s2->ts.interface->result)
1622 : : r2 = s2->ts.interface->result;
1623 : : else
1624 : 47992 : r2 = s2->result ? s2->result : s2;
1625 : :
1626 : 48295 : if (r1->ts.type == BT_UNKNOWN)
1627 : : return true;
1628 : :
1629 : : /* Check type and rank. */
1630 : 48057 : if (!compare_type_characteristics (r1, r2))
1631 : : {
1632 : 22 : snprintf (errmsg, err_len, "Type mismatch in function result (%s/%s)",
1633 : : gfc_typename (&r1->ts), gfc_typename (&r2->ts));
1634 : 22 : return false;
1635 : : }
1636 : 48035 : if (!compare_rank (r1, r2))
1637 : : {
1638 : 5 : snprintf (errmsg, err_len, "Rank mismatch in function result (%i/%i)",
1639 : : symbol_rank (r1), symbol_rank (r2));
1640 : 5 : return false;
1641 : : }
1642 : :
1643 : : /* Check ALLOCATABLE attribute. */
1644 : 48030 : if (r1->attr.allocatable != r2->attr.allocatable)
1645 : : {
1646 : 2 : snprintf (errmsg, err_len, "ALLOCATABLE attribute mismatch in "
1647 : : "function result");
1648 : 2 : return false;
1649 : : }
1650 : :
1651 : : /* Check POINTER attribute. */
1652 : 48028 : if (r1->attr.pointer != r2->attr.pointer)
1653 : : {
1654 : 2 : snprintf (errmsg, err_len, "POINTER attribute mismatch in "
1655 : : "function result");
1656 : 2 : return false;
1657 : : }
1658 : :
1659 : : /* Check CONTIGUOUS attribute. */
1660 : 48026 : if (r1->attr.contiguous != r2->attr.contiguous)
1661 : : {
1662 : 1 : snprintf (errmsg, err_len, "CONTIGUOUS attribute mismatch in "
1663 : : "function result");
1664 : 1 : return false;
1665 : : }
1666 : :
1667 : : /* Check PROCEDURE POINTER attribute. */
1668 : 48025 : if (r1 != s1 && r1->attr.proc_pointer != r2->attr.proc_pointer)
1669 : : {
1670 : 3 : snprintf (errmsg, err_len, "PROCEDURE POINTER mismatch in "
1671 : : "function result");
1672 : 3 : return false;
1673 : : }
1674 : :
1675 : : /* Check string length. */
1676 : 48022 : if (r1->ts.type == BT_CHARACTER && r1->ts.u.cl && r2->ts.u.cl)
1677 : : {
1678 : 1631 : if (r1->ts.deferred != r2->ts.deferred)
1679 : : {
1680 : 0 : snprintf (errmsg, err_len, "Character length mismatch "
1681 : : "in function result");
1682 : 0 : return false;
1683 : : }
1684 : :
1685 : 1631 : if (r1->ts.u.cl->length && r2->ts.u.cl->length)
1686 : : {
1687 : 1071 : int compval = gfc_dep_compare_expr (r1->ts.u.cl->length,
1688 : : r2->ts.u.cl->length);
1689 : 1071 : switch (compval)
1690 : : {
1691 : 3 : case -1:
1692 : 3 : case 1:
1693 : 3 : case -3:
1694 : 3 : snprintf (errmsg, err_len, "Character length mismatch "
1695 : : "in function result");
1696 : 3 : return false;
1697 : :
1698 : 75 : case -2:
1699 : 75 : if (r1->ts.u.cl->length->expr_type == EXPR_CONSTANT)
1700 : : {
1701 : 0 : snprintf (errmsg, err_len,
1702 : : "Function declared with a non-constant character "
1703 : : "length referenced with a constant length");
1704 : 0 : return false;
1705 : : }
1706 : 75 : else if (r2->ts.u.cl->length->expr_type == EXPR_CONSTANT)
1707 : : {
1708 : 3 : snprintf (errmsg, err_len,
1709 : : "Function declared with a constant character "
1710 : : "length referenced with a non-constant length");
1711 : 3 : return false;
1712 : : }
1713 : : /* Warn if length expression types are different, except for
1714 : : possibly false positives where complex expressions might have
1715 : : been used. */
1716 : 72 : else if ((r1->ts.u.cl->length->expr_type
1717 : : != r2->ts.u.cl->length->expr_type)
1718 : 4 : && (r1->ts.u.cl->length->expr_type != EXPR_OP
1719 : 2 : || r2->ts.u.cl->length->expr_type != EXPR_OP))
1720 : 4 : gfc_warning (0, "Possible character length mismatch in "
1721 : : "function result between %L and %L",
1722 : : &r1->declared_at, &r2->declared_at);
1723 : : break;
1724 : :
1725 : : case 0:
1726 : : break;
1727 : :
1728 : 0 : default:
1729 : 0 : gfc_internal_error ("check_result_characteristics (1): Unexpected "
1730 : : "result %i of gfc_dep_compare_expr", compval);
1731 : : break;
1732 : : }
1733 : : }
1734 : : }
1735 : :
1736 : : /* Check array shape. */
1737 : 48016 : if (!r1->attr.allocatable && !r1->attr.pointer && r1->as && r2->as)
1738 : : {
1739 : 989 : int i, compval;
1740 : 989 : gfc_expr *shape1, *shape2;
1741 : :
1742 : 989 : if (r1->as->type != r2->as->type)
1743 : : {
1744 : 0 : snprintf (errmsg, err_len, "Shape mismatch in function result");
1745 : 0 : return false;
1746 : : }
1747 : :
1748 : 989 : if (r1->as->type == AS_EXPLICIT)
1749 : 2493 : for (i = 0; i < r1->as->rank + r1->as->corank; i++)
1750 : : {
1751 : 1505 : shape1 = gfc_subtract (gfc_copy_expr (r1->as->upper[i]),
1752 : 1505 : gfc_copy_expr (r1->as->lower[i]));
1753 : 1505 : shape2 = gfc_subtract (gfc_copy_expr (r2->as->upper[i]),
1754 : 1505 : gfc_copy_expr (r2->as->lower[i]));
1755 : 1505 : compval = gfc_dep_compare_expr (shape1, shape2);
1756 : 1505 : gfc_free_expr (shape1);
1757 : 1505 : gfc_free_expr (shape2);
1758 : 1505 : switch (compval)
1759 : : {
1760 : 1 : case -1:
1761 : 1 : case 1:
1762 : 1 : case -3:
1763 : 1 : snprintf (errmsg, err_len, "Shape mismatch in dimension %i of "
1764 : : "function result", i + 1);
1765 : 1 : return false;
1766 : :
1767 : : case -2:
1768 : : /* FIXME: Implement a warning for this case.
1769 : : gfc_warning (0, "Possible shape mismatch in return value");*/
1770 : : break;
1771 : :
1772 : : case 0:
1773 : : break;
1774 : :
1775 : 0 : default:
1776 : 0 : gfc_internal_error ("check_result_characteristics (2): "
1777 : : "Unexpected result %i of "
1778 : : "gfc_dep_compare_expr", compval);
1779 : 1504 : break;
1780 : : }
1781 : : }
1782 : : }
1783 : :
1784 : : return true;
1785 : : }
1786 : :
1787 : :
1788 : : /* 'Compare' two formal interfaces associated with a pair of symbols.
1789 : : We return true if there exists an actual argument list that
1790 : : would be ambiguous between the two interfaces, zero otherwise.
1791 : : 'strict_flag' specifies whether all the characteristics are
1792 : : required to match, which is not the case for ambiguity checks.
1793 : : 'p1' and 'p2' are the PASS arguments of both procedures (if applicable). */
1794 : :
1795 : : bool
1796 : 870090 : gfc_compare_interfaces (gfc_symbol *s1, gfc_symbol *s2, const char *name2,
1797 : : int generic_flag, int strict_flag,
1798 : : char *errmsg, int err_len,
1799 : : const char *p1, const char *p2,
1800 : : bool *bad_result_characteristics)
1801 : : {
1802 : 870090 : gfc_formal_arglist *f1, *f2;
1803 : :
1804 : 870090 : gcc_assert (name2 != NULL);
1805 : :
1806 : 870090 : if (bad_result_characteristics)
1807 : 14790 : *bad_result_characteristics = false;
1808 : :
1809 : 870090 : if (s1->attr.function && (s2->attr.subroutine
1810 : 788508 : || (!s2->attr.function && s2->ts.type == BT_UNKNOWN
1811 : 5 : && gfc_get_default_type (name2, s2->ns)->type == BT_UNKNOWN)))
1812 : : {
1813 : 3 : if (errmsg != NULL)
1814 : 3 : snprintf (errmsg, err_len, "'%s' is not a function", name2);
1815 : 3 : return false;
1816 : : }
1817 : :
1818 : 870087 : if (s1->attr.subroutine && s2->attr.function)
1819 : : {
1820 : 6 : if (errmsg != NULL)
1821 : 6 : snprintf (errmsg, err_len, "'%s' is not a subroutine", name2);
1822 : 6 : return false;
1823 : : }
1824 : :
1825 : 870081 : if (s2->attr.subroutine && s1->attr.flavor == FL_VARIABLE)
1826 : : {
1827 : 2 : if (errmsg != NULL)
1828 : 2 : snprintf (errmsg, err_len, "subroutine proc pointer '%s' passed "
1829 : : "to dummy variable '%s'", name2, s1->name);
1830 : 2 : return false;
1831 : : }
1832 : :
1833 : : /* Do strict checks on all characteristics
1834 : : (for dummy procedures and procedure pointer assignments). */
1835 : 870079 : if (!generic_flag && strict_flag)
1836 : : {
1837 : 53340 : if (s1->attr.function && s2->attr.function)
1838 : : {
1839 : : /* If both are functions, check result characteristics. */
1840 : 23648 : if (!gfc_check_result_characteristics (s1, s2, errmsg, err_len)
1841 : 23648 : || !gfc_check_result_characteristics (s2, s1, errmsg, err_len))
1842 : : {
1843 : 31 : if (bad_result_characteristics)
1844 : 6 : *bad_result_characteristics = true;
1845 : 31 : return false;
1846 : : }
1847 : : }
1848 : :
1849 : 53309 : if (s1->attr.pure && !s2->attr.pure)
1850 : : {
1851 : 2 : snprintf (errmsg, err_len, "Mismatch in PURE attribute");
1852 : 2 : return false;
1853 : : }
1854 : 53307 : if (s1->attr.elemental && !s2->attr.elemental)
1855 : : {
1856 : 0 : snprintf (errmsg, err_len, "Mismatch in ELEMENTAL attribute");
1857 : 0 : return false;
1858 : : }
1859 : : }
1860 : :
1861 : 870046 : if (s1->attr.if_source == IFSRC_UNKNOWN
1862 : 854530 : || s2->attr.if_source == IFSRC_UNKNOWN)
1863 : : return true;
1864 : :
1865 : 854454 : f1 = gfc_sym_get_dummy_args (s1);
1866 : 854454 : f2 = gfc_sym_get_dummy_args (s2);
1867 : :
1868 : : /* Special case: No arguments. */
1869 : 854454 : if (f1 == NULL && f2 == NULL)
1870 : : return true;
1871 : :
1872 : 852676 : if (generic_flag)
1873 : : {
1874 : 814007 : if (count_types_test (f1, f2, p1, p2)
1875 : 814007 : || count_types_test (f2, f1, p2, p1))
1876 : 783003 : return false;
1877 : :
1878 : : /* Special case: alternate returns. If both f1->sym and f2->sym are
1879 : : NULL, then the leading formal arguments are alternate returns.
1880 : : The previous conditional should catch argument lists with
1881 : : different number of argument. */
1882 : 31004 : if (f1 && f1->sym == NULL && f2 && f2->sym == NULL)
1883 : : return true;
1884 : :
1885 : 31001 : if (generic_correspondence (f1, f2, p1, p2)
1886 : 31001 : || generic_correspondence (f2, f1, p2, p1))
1887 : 30976 : return false;
1888 : : }
1889 : : else
1890 : : /* Perform the abbreviated correspondence test for operators (the
1891 : : arguments cannot be optional and are always ordered correctly).
1892 : : This is also done when comparing interfaces for dummy procedures and in
1893 : : procedure pointer assignments. */
1894 : :
1895 : 144631 : for (; f1 || f2; f1 = f1->next, f2 = f2->next)
1896 : : {
1897 : : /* Check existence. */
1898 : 108727 : if (f1 == NULL || f2 == NULL)
1899 : : {
1900 : 10 : if (errmsg != NULL)
1901 : 6 : snprintf (errmsg, err_len, "'%s' has the wrong number of "
1902 : : "arguments", name2);
1903 : 10 : return false;
1904 : : }
1905 : :
1906 : 108717 : if (strict_flag)
1907 : : {
1908 : : /* Check all characteristics. */
1909 : 105677 : if (!gfc_check_dummy_characteristics (f1->sym, f2->sym, true,
1910 : : errmsg, err_len))
1911 : : return false;
1912 : : }
1913 : : else
1914 : : {
1915 : : /* Operators: Only check type and rank of arguments. */
1916 : 3040 : if (!compare_type (f2->sym, f1->sym))
1917 : : {
1918 : 2712 : if (errmsg != NULL)
1919 : 0 : snprintf (errmsg, err_len, "Type mismatch in argument '%s' "
1920 : 0 : "(%s/%s)", f1->sym->name,
1921 : 0 : gfc_typename (&f1->sym->ts),
1922 : 0 : gfc_typename (&f2->sym->ts));
1923 : 2712 : return false;
1924 : : }
1925 : 328 : if (!compare_rank (f2->sym, f1->sym))
1926 : : {
1927 : 4 : if (errmsg != NULL)
1928 : 0 : snprintf (errmsg, err_len, "Rank mismatch in argument "
1929 : : "'%s' (%i/%i)", f1->sym->name,
1930 : : symbol_rank (f1->sym), symbol_rank (f2->sym));
1931 : 4 : return false;
1932 : : }
1933 : 324 : if ((gfc_option.allow_std & GFC_STD_F2008)
1934 : 324 : && (compare_ptr_alloc(f1->sym, f2->sym)
1935 : 323 : || compare_ptr_alloc(f2->sym, f1->sym)))
1936 : : {
1937 : 2 : if (errmsg != NULL)
1938 : 0 : snprintf (errmsg, err_len, "Mismatching POINTER/ALLOCATABLE "
1939 : : "attribute in argument '%s' ", f1->sym->name);
1940 : 2 : return false;
1941 : : }
1942 : : }
1943 : : }
1944 : :
1945 : : return true;
1946 : : }
1947 : :
1948 : :
1949 : : /* Given a pointer to an interface pointer, remove duplicate
1950 : : interfaces and make sure that all symbols are either functions
1951 : : or subroutines, and all of the same kind. Returns true if
1952 : : something goes wrong. */
1953 : :
1954 : : static bool
1955 : 8970157 : check_interface0 (gfc_interface *p, const char *interface_name)
1956 : : {
1957 : 8970157 : gfc_interface *psave, *q, *qlast;
1958 : :
1959 : 8970157 : psave = p;
1960 : 9159739 : for (; p; p = p->next)
1961 : : {
1962 : : /* Make sure all symbols in the interface have been defined as
1963 : : functions or subroutines. */
1964 : 189596 : if (((!p->sym->attr.function && !p->sym->attr.subroutine)
1965 : 155297 : || !p->sym->attr.if_source)
1966 : 34302 : && !gfc_fl_struct (p->sym->attr.flavor))
1967 : : {
1968 : 11 : const char *guessed
1969 : 11 : = gfc_lookup_function_fuzzy (p->sym->name, p->sym->ns->sym_root);
1970 : :
1971 : 11 : if (p->sym->attr.external)
1972 : 5 : if (guessed)
1973 : 5 : gfc_error ("Procedure %qs in %s at %L has no explicit interface"
1974 : : "; did you mean %qs?",
1975 : : p->sym->name, interface_name, &p->sym->declared_at,
1976 : : guessed);
1977 : : else
1978 : 0 : gfc_error ("Procedure %qs in %s at %L has no explicit interface",
1979 : : p->sym->name, interface_name, &p->sym->declared_at);
1980 : : else
1981 : 6 : if (guessed)
1982 : 3 : gfc_error ("Procedure %qs in %s at %L is neither function nor "
1983 : : "subroutine; did you mean %qs?", p->sym->name,
1984 : : interface_name, &p->sym->declared_at, guessed);
1985 : : else
1986 : 3 : gfc_error ("Procedure %qs in %s at %L is neither function nor "
1987 : : "subroutine", p->sym->name, interface_name,
1988 : : &p->sym->declared_at);
1989 : 11 : return true;
1990 : : }
1991 : :
1992 : : /* Verify that procedures are either all SUBROUTINEs or all FUNCTIONs. */
1993 : 189585 : if ((psave->sym->attr.function && !p->sym->attr.function
1994 : 193 : && !gfc_fl_struct (p->sym->attr.flavor))
1995 : 189584 : || (psave->sym->attr.subroutine && !p->sym->attr.subroutine))
1996 : : {
1997 : 2 : if (!gfc_fl_struct (p->sym->attr.flavor))
1998 : 2 : gfc_error ("In %s at %L procedures must be either all SUBROUTINEs"
1999 : : " or all FUNCTIONs", interface_name,
2000 : : &p->sym->declared_at);
2001 : 0 : else if (p->sym->attr.flavor == FL_DERIVED)
2002 : 0 : gfc_error ("In %s at %L procedures must be all FUNCTIONs as the "
2003 : : "generic name is also the name of a derived type",
2004 : : interface_name, &p->sym->declared_at);
2005 : 2 : return true;
2006 : : }
2007 : :
2008 : : /* F2003, C1207. F2008, C1207. */
2009 : 189583 : if (p->sym->attr.proc == PROC_INTERNAL
2010 : 189583 : && !gfc_notify_std (GFC_STD_F2008, "Internal procedure "
2011 : : "%qs in %s at %L", p->sym->name,
2012 : : interface_name, &p->sym->declared_at))
2013 : : return true;
2014 : : }
2015 : : p = psave;
2016 : :
2017 : : /* Remove duplicate interfaces in this interface list. */
2018 : 9154725 : for (; p; p = p->next)
2019 : : {
2020 : 184582 : qlast = p;
2021 : :
2022 : 609496 : for (q = p->next; q;)
2023 : : {
2024 : 424914 : if (p->sym != q->sym)
2025 : : {
2026 : 419917 : qlast = q;
2027 : 419917 : q = q->next;
2028 : : }
2029 : : else
2030 : : {
2031 : : /* Duplicate interface. */
2032 : 4997 : qlast->next = q->next;
2033 : 4997 : free (q);
2034 : 4997 : q = qlast->next;
2035 : : }
2036 : : }
2037 : : }
2038 : :
2039 : : return false;
2040 : : }
2041 : :
2042 : :
2043 : : /* Check lists of interfaces to make sure that no two interfaces are
2044 : : ambiguous. Duplicate interfaces (from the same symbol) are OK here. */
2045 : :
2046 : : static bool
2047 : 16185988 : check_interface1 (gfc_interface *p, gfc_interface *q0,
2048 : : int generic_flag, const char *interface_name,
2049 : : bool referenced)
2050 : : {
2051 : 16185988 : gfc_interface *q;
2052 : 16373730 : for (; p; p = p->next)
2053 : 1189181 : for (q = q0; q; q = q->next)
2054 : : {
2055 : 1001439 : if (p->sym == q->sym)
2056 : 184544 : continue; /* Duplicates OK here. */
2057 : :
2058 : 816895 : if (p->sym->name == q->sym->name && p->sym->module == q->sym->module)
2059 : 100 : continue;
2060 : :
2061 : 816795 : if (!gfc_fl_struct (p->sym->attr.flavor)
2062 : 816576 : && !gfc_fl_struct (q->sym->attr.flavor)
2063 : 816361 : && gfc_compare_interfaces (p->sym, q->sym, q->sym->name,
2064 : : generic_flag, 0, NULL, 0, NULL, NULL))
2065 : : {
2066 : 30 : if (referenced)
2067 : 27 : gfc_error ("Ambiguous interfaces in %s for %qs at %L "
2068 : : "and %qs at %L", interface_name,
2069 : 27 : q->sym->name, &q->sym->declared_at,
2070 : 27 : p->sym->name, &p->sym->declared_at);
2071 : 3 : else if (!p->sym->attr.use_assoc && q->sym->attr.use_assoc)
2072 : 1 : gfc_warning (0, "Ambiguous interfaces in %s for %qs at %L "
2073 : : "and %qs at %L", interface_name,
2074 : : q->sym->name, &q->sym->declared_at,
2075 : : p->sym->name, &p->sym->declared_at);
2076 : : else
2077 : 2 : gfc_warning (0, "Although not referenced, %qs has ambiguous "
2078 : : "interfaces at %L", interface_name, &p->where);
2079 : 30 : return true;
2080 : : }
2081 : : }
2082 : : return false;
2083 : : }
2084 : :
2085 : :
2086 : : /* Check the generic and operator interfaces of symbols to make sure
2087 : : that none of the interfaces conflict. The check has to be done
2088 : : after all of the symbols are actually loaded. */
2089 : :
2090 : : static void
2091 : 1769614 : check_sym_interfaces (gfc_symbol *sym)
2092 : : {
2093 : : /* Provide sufficient space to hold "generic interface 'symbol.symbol'". */
2094 : 1769614 : char interface_name[2*GFC_MAX_SYMBOL_LEN+2 + sizeof("generic interface ''")];
2095 : 1769614 : gfc_interface *p;
2096 : :
2097 : 1769614 : if (sym->ns != gfc_current_ns)
2098 : 56938 : return;
2099 : :
2100 : 1712693 : if (sym->generic != NULL)
2101 : : {
2102 : 74520 : size_t len = strlen (sym->name) + sizeof("generic interface ''");
2103 : 74520 : gcc_assert (len < sizeof (interface_name));
2104 : 74520 : sprintf (interface_name, "generic interface '%s'", sym->name);
2105 : 74520 : if (check_interface0 (sym->generic, interface_name))
2106 : : return;
2107 : :
2108 : 255320 : for (p = sym->generic; p; p = p->next)
2109 : : {
2110 : 180817 : if (p->sym->attr.mod_proc
2111 : 1044 : && !p->sym->attr.module_procedure
2112 : 1038 : && (p->sym->attr.if_source != IFSRC_DECL
2113 : 1034 : || p->sym->attr.procedure))
2114 : : {
2115 : 4 : gfc_error ("%qs at %L is not a module procedure",
2116 : : p->sym->name, &p->where);
2117 : 4 : return;
2118 : : }
2119 : : }
2120 : :
2121 : : /* Originally, this test was applied to host interfaces too;
2122 : : this is incorrect since host associated symbols, from any
2123 : : source, cannot be ambiguous with local symbols. */
2124 : 74503 : check_interface1 (sym->generic, sym->generic, 1, interface_name,
2125 : 74503 : sym->attr.referenced || !sym->attr.use_assoc);
2126 : : }
2127 : : }
2128 : :
2129 : :
2130 : : static void
2131 : 333 : check_uop_interfaces (gfc_user_op *uop)
2132 : : {
2133 : 333 : char interface_name[GFC_MAX_SYMBOL_LEN + sizeof("operator interface ''")];
2134 : 333 : gfc_user_op *uop2;
2135 : 333 : gfc_namespace *ns;
2136 : :
2137 : 333 : sprintf (interface_name, "operator interface '%s'", uop->name);
2138 : 333 : if (check_interface0 (uop->op, interface_name))
2139 : 1 : return;
2140 : :
2141 : 674 : for (ns = gfc_current_ns; ns; ns = ns->parent)
2142 : : {
2143 : 342 : uop2 = gfc_find_uop (uop->name, ns);
2144 : 342 : if (uop2 == NULL)
2145 : 10 : continue;
2146 : :
2147 : 332 : check_interface1 (uop->op, uop2->op, 0,
2148 : : interface_name, true);
2149 : : }
2150 : : }
2151 : :
2152 : : /* Given an intrinsic op, return an equivalent op if one exists,
2153 : : or INTRINSIC_NONE otherwise. */
2154 : :
2155 : : gfc_intrinsic_op
2156 : 11153942 : gfc_equivalent_op (gfc_intrinsic_op op)
2157 : : {
2158 : 11153942 : switch(op)
2159 : : {
2160 : : case INTRINSIC_EQ:
2161 : : return INTRINSIC_EQ_OS;
2162 : :
2163 : : case INTRINSIC_EQ_OS:
2164 : : return INTRINSIC_EQ;
2165 : :
2166 : : case INTRINSIC_NE:
2167 : : return INTRINSIC_NE_OS;
2168 : :
2169 : : case INTRINSIC_NE_OS:
2170 : : return INTRINSIC_NE;
2171 : :
2172 : : case INTRINSIC_GT:
2173 : : return INTRINSIC_GT_OS;
2174 : :
2175 : : case INTRINSIC_GT_OS:
2176 : : return INTRINSIC_GT;
2177 : :
2178 : : case INTRINSIC_GE:
2179 : : return INTRINSIC_GE_OS;
2180 : :
2181 : : case INTRINSIC_GE_OS:
2182 : : return INTRINSIC_GE;
2183 : :
2184 : : case INTRINSIC_LT:
2185 : : return INTRINSIC_LT_OS;
2186 : :
2187 : : case INTRINSIC_LT_OS:
2188 : : return INTRINSIC_LT;
2189 : :
2190 : : case INTRINSIC_LE:
2191 : : return INTRINSIC_LE_OS;
2192 : :
2193 : : case INTRINSIC_LE_OS:
2194 : : return INTRINSIC_LE;
2195 : :
2196 : : default:
2197 : : return INTRINSIC_NONE;
2198 : : }
2199 : : }
2200 : :
2201 : : /* For the namespace, check generic, user operator and intrinsic
2202 : : operator interfaces for consistency and to remove duplicate
2203 : : interfaces. We traverse the whole namespace, counting on the fact
2204 : : that most symbols will not have generic or operator interfaces. */
2205 : :
2206 : : void
2207 : 329458 : gfc_check_interfaces (gfc_namespace *ns)
2208 : : {
2209 : 329458 : gfc_namespace *old_ns, *ns2;
2210 : 329458 : char interface_name[GFC_MAX_SYMBOL_LEN + sizeof("intrinsic '' operator")];
2211 : 329458 : int i;
2212 : :
2213 : 329458 : old_ns = gfc_current_ns;
2214 : 329458 : gfc_current_ns = ns;
2215 : :
2216 : 329458 : gfc_traverse_ns (ns, check_sym_interfaces);
2217 : :
2218 : 329458 : gfc_traverse_user_op (ns, check_uop_interfaces);
2219 : :
2220 : 9554214 : for (i = GFC_INTRINSIC_BEGIN; i != GFC_INTRINSIC_END; i++)
2221 : : {
2222 : 9224759 : if (i == INTRINSIC_USER)
2223 : 329455 : continue;
2224 : :
2225 : 8895304 : if (i == INTRINSIC_ASSIGN)
2226 : 329455 : strcpy (interface_name, "intrinsic assignment operator");
2227 : : else
2228 : 8565849 : sprintf (interface_name, "intrinsic '%s' operator",
2229 : : gfc_op2string ((gfc_intrinsic_op) i));
2230 : :
2231 : 8895304 : if (check_interface0 (ns->op[i], interface_name))
2232 : 0 : continue;
2233 : :
2234 : 8895304 : if (ns->op[i])
2235 : 2378 : gfc_check_operator_interface (ns->op[i]->sym, (gfc_intrinsic_op) i,
2236 : : ns->op[i]->where);
2237 : :
2238 : 20049182 : for (ns2 = ns; ns2; ns2 = ns2->parent)
2239 : : {
2240 : 11153881 : gfc_intrinsic_op other_op;
2241 : :
2242 : 11153881 : if (check_interface1 (ns->op[i], ns2->op[i], 0,
2243 : : interface_name, true))
2244 : 3 : goto done;
2245 : :
2246 : : /* i should be gfc_intrinsic_op, but has to be int with this cast
2247 : : here for stupid C++ compatibility rules. */
2248 : 11153878 : other_op = gfc_equivalent_op ((gfc_intrinsic_op) i);
2249 : 11153878 : if (other_op != INTRINSIC_NONE
2250 : 11153878 : && check_interface1 (ns->op[i], ns2->op[other_op],
2251 : : 0, interface_name, true))
2252 : 0 : goto done;
2253 : : }
2254 : : }
2255 : :
2256 : 329455 : done:
2257 : 329458 : gfc_current_ns = old_ns;
2258 : 329458 : }
2259 : :
2260 : :
2261 : : /* Given a symbol of a formal argument list and an expression, if the
2262 : : formal argument is allocatable, check that the actual argument is
2263 : : allocatable. Returns true if compatible, zero if not compatible. */
2264 : :
2265 : : static bool
2266 : 250728 : compare_allocatable (gfc_symbol *formal, gfc_expr *actual)
2267 : : {
2268 : 250728 : if (formal->attr.allocatable
2269 : 247739 : || (formal->ts.type == BT_CLASS && CLASS_DATA (formal)->attr.allocatable))
2270 : : {
2271 : 3849 : symbol_attribute attr = gfc_expr_attr (actual);
2272 : 3849 : if (actual->ts.type == BT_CLASS && !attr.class_ok)
2273 : 23 : return true;
2274 : 3835 : else if (!attr.allocatable)
2275 : : return false;
2276 : : }
2277 : :
2278 : : return true;
2279 : : }
2280 : :
2281 : :
2282 : : /* Given a symbol of a formal argument list and an expression, if the
2283 : : formal argument is a pointer, see if the actual argument is a
2284 : : pointer. Returns nonzero if compatible, zero if not compatible. */
2285 : :
2286 : : static int
2287 : 250749 : compare_pointer (gfc_symbol *formal, gfc_expr *actual)
2288 : : {
2289 : 250749 : symbol_attribute attr;
2290 : :
2291 : 250749 : if (formal->attr.pointer
2292 : 246015 : || (formal->ts.type == BT_CLASS && CLASS_DATA (formal)
2293 : 13122 : && CLASS_DATA (formal)->attr.class_pointer))
2294 : : {
2295 : 5626 : attr = gfc_expr_attr (actual);
2296 : :
2297 : : /* Fortran 2008 allows non-pointer actual arguments. */
2298 : 5626 : if (!attr.pointer && attr.target && formal->attr.intent == INTENT_IN)
2299 : : return 2;
2300 : :
2301 : 5247 : if (!attr.pointer)
2302 : : return 0;
2303 : : }
2304 : :
2305 : : return 1;
2306 : : }
2307 : :
2308 : :
2309 : : /* Emit clear error messages for rank mismatch. */
2310 : :
2311 : : static void
2312 : 153 : argument_rank_mismatch (const char *name, locus *where,
2313 : : int rank1, int rank2, locus *where_formal)
2314 : : {
2315 : :
2316 : : /* TS 29113, C407b. */
2317 : 153 : if (where_formal == NULL)
2318 : : {
2319 : 143 : if (rank2 == -1)
2320 : 10 : gfc_error ("The assumed-rank array at %L requires that the dummy "
2321 : : "argument %qs has assumed-rank", where, name);
2322 : 133 : else if (rank1 == 0)
2323 : 22 : gfc_error_opt (0, "Rank mismatch in argument %qs "
2324 : : "at %L (scalar and rank-%d)", name, where, rank2);
2325 : 111 : else if (rank2 == 0)
2326 : 104 : gfc_error_opt (0, "Rank mismatch in argument %qs "
2327 : : "at %L (rank-%d and scalar)", name, where, rank1);
2328 : : else
2329 : 7 : gfc_error_opt (0, "Rank mismatch in argument %qs "
2330 : : "at %L (rank-%d and rank-%d)", name, where, rank1,
2331 : : rank2);
2332 : : }
2333 : : else
2334 : : {
2335 : 10 : if (rank2 == -1)
2336 : : /* This is an assumed rank-actual passed to a function without
2337 : : an explicit interface, which is already diagnosed in
2338 : : gfc_procedure_use. */
2339 : : return;
2340 : 8 : if (rank1 == 0)
2341 : 6 : gfc_error_opt (0, "Rank mismatch between actual argument at %L "
2342 : : "and actual argument at %L (scalar and rank-%d)",
2343 : : where, where_formal, rank2);
2344 : 2 : else if (rank2 == 0)
2345 : 2 : gfc_error_opt (0, "Rank mismatch between actual argument at %L "
2346 : : "and actual argument at %L (rank-%d and scalar)",
2347 : : where, where_formal, rank1);
2348 : : else
2349 : 0 : gfc_error_opt (0, "Rank mismatch between actual argument at %L "
2350 : : "and actual argument at %L (rank-%d and rank-%d)", where,
2351 : : where_formal, rank1, rank2);
2352 : : }
2353 : : }
2354 : :
2355 : :
2356 : : /* Under certain conditions, a scalar actual argument can be passed
2357 : : to an array dummy argument - see F2018, 15.5.2.4, paragraph 14.
2358 : : This function returns true for these conditions so that an error
2359 : : or warning for this can be suppressed later. Always return false
2360 : : for expressions with rank > 0. */
2361 : :
2362 : : bool
2363 : 3056 : maybe_dummy_array_arg (gfc_expr *e)
2364 : : {
2365 : 3056 : gfc_symbol *s;
2366 : 3056 : gfc_ref *ref;
2367 : 3056 : bool array_pointer = false;
2368 : 3056 : bool assumed_shape = false;
2369 : 3056 : bool scalar_ref = true;
2370 : :
2371 : 3056 : if (e->rank > 0)
2372 : : return false;
2373 : :
2374 : 3050 : if (e->ts.type == BT_CHARACTER && e->ts.kind == 1)
2375 : : return true;
2376 : :
2377 : : /* If this comes from a constructor, it has been an array element
2378 : : originally. */
2379 : :
2380 : 2906 : if (e->expr_type == EXPR_CONSTANT)
2381 : 685 : return e->from_constructor;
2382 : :
2383 : 2221 : if (e->expr_type != EXPR_VARIABLE)
2384 : : return false;
2385 : :
2386 : 2117 : s = e->symtree->n.sym;
2387 : :
2388 : 2117 : if (s->attr.dimension)
2389 : : {
2390 : 233 : scalar_ref = false;
2391 : 233 : array_pointer = s->attr.pointer;
2392 : : }
2393 : :
2394 : 2117 : if (s->as && s->as->type == AS_ASSUMED_SHAPE)
2395 : 2117 : assumed_shape = true;
2396 : :
2397 : 2379 : for (ref=e->ref; ref; ref=ref->next)
2398 : : {
2399 : 262 : if (ref->type == REF_COMPONENT)
2400 : : {
2401 : 20 : symbol_attribute *attr;
2402 : 20 : attr = &ref->u.c.component->attr;
2403 : 20 : if (attr->dimension)
2404 : : {
2405 : 2 : array_pointer = attr->pointer;
2406 : 2 : assumed_shape = false;
2407 : 2 : scalar_ref = false;
2408 : : }
2409 : : else
2410 : : scalar_ref = true;
2411 : : }
2412 : : }
2413 : :
2414 : 2117 : return !(scalar_ref || array_pointer || assumed_shape);
2415 : : }
2416 : :
2417 : : /* Given a symbol of a formal argument list and an expression, see if
2418 : : the two are compatible as arguments. Returns true if
2419 : : compatible, false if not compatible. */
2420 : :
2421 : : static bool
2422 : 354319 : compare_parameter (gfc_symbol *formal, gfc_expr *actual,
2423 : : int ranks_must_agree, int is_elemental, locus *where)
2424 : : {
2425 : 354319 : gfc_ref *ref;
2426 : 354319 : bool rank_check, is_pointer;
2427 : 354319 : char err[200];
2428 : 354319 : gfc_component *ppc;
2429 : 354319 : bool codimension = false;
2430 : 354319 : gfc_array_spec *formal_as;
2431 : 354319 : const char *actual_name;
2432 : :
2433 : : /* If the formal arg has type BT_VOID, it's to one of the iso_c_binding
2434 : : procs c_f_pointer or c_f_procpointer, and we need to accept most
2435 : : pointers the user could give us. This should allow that. */
2436 : 354319 : if (formal->ts.type == BT_VOID)
2437 : : return true;
2438 : :
2439 : 354319 : if (formal->ts.type == BT_DERIVED
2440 : 29015 : && formal->ts.u.derived && formal->ts.u.derived->ts.is_iso_c
2441 : 4325 : && actual->ts.type == BT_DERIVED
2442 : 4317 : && actual->ts.u.derived && actual->ts.u.derived->ts.is_iso_c)
2443 : : {
2444 : 4317 : if (formal->ts.u.derived->intmod_sym_id
2445 : 4317 : != actual->ts.u.derived->intmod_sym_id)
2446 : : return false;
2447 : :
2448 : 4227 : if (ranks_must_agree
2449 : 115 : && symbol_rank (formal) != actual->rank
2450 : 4287 : && symbol_rank (formal) != -1)
2451 : : {
2452 : 42 : if (where)
2453 : 0 : argument_rank_mismatch (formal->name, &actual->where,
2454 : : symbol_rank (formal), actual->rank,
2455 : : NULL);
2456 : 42 : return false;
2457 : : }
2458 : : return true;
2459 : : }
2460 : :
2461 : 350002 : if (formal->ts.type == BT_CLASS && actual->ts.type == BT_DERIVED)
2462 : : /* Make sure the vtab symbol is present when
2463 : : the module variables are generated. */
2464 : 6421 : gfc_find_derived_vtab (actual->ts.u.derived);
2465 : :
2466 : 350002 : if (actual->ts.type == BT_PROCEDURE)
2467 : : {
2468 : 1916 : gfc_symbol *act_sym = actual->symtree->n.sym;
2469 : :
2470 : 1916 : if (formal->attr.flavor != FL_PROCEDURE && !act_sym->ts.interface)
2471 : : {
2472 : 5 : if (where)
2473 : 3 : gfc_error ("Invalid procedure argument at %L", &actual->where);
2474 : 5 : return false;
2475 : : }
2476 : 1911 : else if (act_sym->ts.interface
2477 : 1911 : && !gfc_compare_interfaces (formal, act_sym->ts.interface,
2478 : : act_sym->name, 0, 1, err,
2479 : : sizeof(err),NULL, NULL))
2480 : : {
2481 : 1 : if (where)
2482 : : {
2483 : : /* Artificially generated symbol names would only confuse. */
2484 : 1 : if (formal->attr.artificial)
2485 : 0 : gfc_error_opt (0, "Interface mismatch in dummy procedure "
2486 : : "at %L conflicts with %L: %s", &actual->where,
2487 : : &formal->declared_at, err);
2488 : : else
2489 : 1 : gfc_error_opt (0, "Interface mismatch in dummy procedure %qs "
2490 : : "at %L: %s", formal->name, &actual->where, err);
2491 : : }
2492 : 1 : return false;
2493 : : }
2494 : :
2495 : 1910 : if (!gfc_compare_interfaces (formal, act_sym, act_sym->name, 0, 1, err,
2496 : : sizeof(err), NULL, NULL))
2497 : : {
2498 : 36 : if (where)
2499 : : {
2500 : 36 : if (formal->attr.artificial)
2501 : 1 : gfc_error_opt (0, "Interface mismatch in dummy procedure "
2502 : : "at %L conflicts with %L: %s", &actual->where,
2503 : : &formal->declared_at, err);
2504 : : else
2505 : 35 : gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at "
2506 : : "%L: %s", formal->name, &actual->where, err);
2507 : :
2508 : : }
2509 : 36 : return false;
2510 : : }
2511 : :
2512 : : /* The actual symbol may disagree with a global symbol. If so, issue an
2513 : : error, but only if no previous error has been reported on the formal
2514 : : argument. */
2515 : 1874 : actual_name = act_sym->name;
2516 : 1874 : if (!formal->error && actual_name)
2517 : : {
2518 : 1874 : gfc_gsymbol *gsym;
2519 : 1874 : gsym = gfc_find_gsymbol (gfc_gsym_root, actual_name);
2520 : 1874 : if (gsym != NULL)
2521 : : {
2522 : 142 : if (gsym->type == GSYM_SUBROUTINE && formal->attr.function)
2523 : : {
2524 : 1 : gfc_error ("Passing global subroutine %qs declared at %L "
2525 : : "as function at %L", actual_name, &gsym->where,
2526 : : &actual->where);
2527 : 1 : return false;
2528 : : }
2529 : 141 : if (gsym->type == GSYM_FUNCTION && formal->attr.subroutine)
2530 : : {
2531 : 1 : gfc_error ("Passing global function %qs declared at %L "
2532 : : "as subroutine at %L", actual_name, &gsym->where,
2533 : : &actual->where);
2534 : 1 : return false;
2535 : : }
2536 : 140 : if (gsym->type == GSYM_FUNCTION)
2537 : : {
2538 : 61 : gfc_symbol *global_asym;
2539 : 61 : gfc_find_symbol (actual_name, gsym->ns, 0, &global_asym);
2540 : 61 : if (global_asym != NULL)
2541 : : {
2542 : 61 : if (formal->attr.subroutine)
2543 : : {
2544 : 0 : gfc_error ("Mismatch between subroutine and "
2545 : : "function at %L", &actual->where);
2546 : 1 : return false;
2547 : : }
2548 : 61 : else if (formal->attr.function)
2549 : : {
2550 : 60 : gfc_typespec ts;
2551 : :
2552 : 60 : if (global_asym->result)
2553 : 59 : ts = global_asym->result->ts;
2554 : : else
2555 : 1 : ts = global_asym->ts;
2556 : :
2557 : 60 : if (!gfc_compare_types (&ts,
2558 : : &formal->ts))
2559 : : {
2560 : 2 : gfc_error ("Type mismatch at %L passing global "
2561 : : "function %qs declared at %L (%s/%s)",
2562 : : &actual->where, actual_name,
2563 : : &gsym->where,
2564 : 1 : gfc_typename (&global_asym->ts),
2565 : : gfc_dummy_typename (&formal->ts));
2566 : 1 : return false;
2567 : : }
2568 : : }
2569 : : else
2570 : : {
2571 : : /* The global symbol is a function. Set the formal
2572 : : argument acordingly. */
2573 : 1 : formal->attr.function = 1;
2574 : 1 : formal->ts = global_asym->ts;
2575 : : }
2576 : : }
2577 : : }
2578 : : }
2579 : : }
2580 : :
2581 : 1871 : if (formal->attr.function && !act_sym->attr.function)
2582 : : {
2583 : 5 : gfc_add_function (&act_sym->attr, act_sym->name,
2584 : : &act_sym->declared_at);
2585 : 5 : if (act_sym->ts.type == BT_UNKNOWN
2586 : 5 : && !gfc_set_default_type (act_sym, 1, act_sym->ns))
2587 : : return false;
2588 : : }
2589 : 1866 : else if (formal->attr.subroutine && !act_sym->attr.subroutine)
2590 : 50 : gfc_add_subroutine (&act_sym->attr, act_sym->name,
2591 : : &act_sym->declared_at);
2592 : :
2593 : 1871 : return true;
2594 : : }
2595 : 348086 : ppc = gfc_get_proc_ptr_comp (actual);
2596 : 348086 : if (ppc && ppc->ts.interface)
2597 : : {
2598 : 495 : if (!gfc_compare_interfaces (formal, ppc->ts.interface, ppc->name, 0, 1,
2599 : : err, sizeof(err), NULL, NULL))
2600 : : {
2601 : 2 : if (where)
2602 : 2 : gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at %L:"
2603 : : " %s", formal->name, &actual->where, err);
2604 : 2 : return false;
2605 : : }
2606 : : }
2607 : :
2608 : : /* F2008, C1241. */
2609 : 5249 : if (formal->attr.pointer && formal->attr.contiguous
2610 : 348113 : && !gfc_is_simply_contiguous (actual, true, false))
2611 : : {
2612 : 4 : if (where)
2613 : 4 : gfc_error ("Actual argument to contiguous pointer dummy %qs at %L "
2614 : : "must be simply contiguous", formal->name, &actual->where);
2615 : 4 : return false;
2616 : : }
2617 : :
2618 : 348080 : symbol_attribute actual_attr = gfc_expr_attr (actual);
2619 : 348080 : if (actual->ts.type == BT_CLASS && !actual_attr.class_ok)
2620 : : return true;
2621 : :
2622 : 807 : if ((actual->expr_type != EXPR_NULL || actual->ts.type != BT_UNKNOWN)
2623 : 347777 : && actual->ts.type != BT_HOLLERITH
2624 : 347758 : && formal->ts.type != BT_ASSUMED
2625 : 344394 : && !(formal->attr.ext_attr & (1 << EXT_ATTR_NO_ARG_CHECK))
2626 : 344394 : && !gfc_compare_types (&formal->ts, &actual->ts)
2627 : 450225 : && !(formal->ts.type == BT_DERIVED && actual->ts.type == BT_CLASS
2628 : 2 : && gfc_compare_derived_types (formal->ts.u.derived,
2629 : 2 : CLASS_DATA (actual)->ts.u.derived)))
2630 : : {
2631 : 102188 : if (where)
2632 : : {
2633 : 68 : if (formal->attr.artificial)
2634 : : {
2635 : 19 : if (!flag_allow_argument_mismatch || !formal->error)
2636 : 14 : gfc_error_opt (0, "Type mismatch between actual argument at %L "
2637 : : "and actual argument at %L (%s/%s).",
2638 : : &actual->where,
2639 : : &formal->declared_at,
2640 : : gfc_typename (actual),
2641 : : gfc_dummy_typename (&formal->ts));
2642 : :
2643 : 19 : formal->error = 1;
2644 : : }
2645 : : else
2646 : 49 : gfc_error_opt (0, "Type mismatch in argument %qs at %L; passed %s "
2647 : : "to %s", formal->name, where, gfc_typename (actual),
2648 : : gfc_dummy_typename (&formal->ts));
2649 : : }
2650 : 102188 : return false;
2651 : : }
2652 : :
2653 : 245847 : if (actual->ts.type == BT_ASSUMED && formal->ts.type != BT_ASSUMED)
2654 : : {
2655 : 3 : if (where)
2656 : 1 : gfc_error ("Assumed-type actual argument at %L requires that dummy "
2657 : : "argument %qs is of assumed type", &actual->where,
2658 : : formal->name);
2659 : 3 : return false;
2660 : : }
2661 : :
2662 : : /* TS29113 C407c; F2018 C711. */
2663 : 245844 : if (actual->ts.type == BT_ASSUMED
2664 : 302 : && symbol_rank (formal) == -1
2665 : 27 : && actual->rank != -1
2666 : 245851 : && !(actual->symtree->n.sym->as
2667 : 5 : && actual->symtree->n.sym->as->type == AS_ASSUMED_SHAPE))
2668 : : {
2669 : 4 : if (where)
2670 : 4 : gfc_error ("Assumed-type actual argument at %L corresponding to "
2671 : : "assumed-rank dummy argument %qs must be "
2672 : : "assumed-shape or assumed-rank",
2673 : : &actual->where, formal->name);
2674 : 4 : return false;
2675 : : }
2676 : :
2677 : : /* F2008, 12.5.2.5; IR F08/0073. */
2678 : 245840 : if (formal->ts.type == BT_CLASS && formal->attr.class_ok
2679 : 13128 : && actual->expr_type != EXPR_NULL
2680 : 13128 : && ((CLASS_DATA (formal)->attr.class_pointer
2681 : 869 : && formal->attr.intent != INTENT_IN)
2682 : 12876 : || CLASS_DATA (formal)->attr.allocatable))
2683 : : {
2684 : 1100 : if (actual->ts.type != BT_CLASS)
2685 : : {
2686 : 2 : if (where)
2687 : 2 : gfc_error ("Actual argument to %qs at %L must be polymorphic",
2688 : : formal->name, &actual->where);
2689 : 2 : return false;
2690 : : }
2691 : :
2692 : 1098 : if ((!UNLIMITED_POLY (formal) || !UNLIMITED_POLY(actual))
2693 : 755 : && !gfc_compare_derived_types (CLASS_DATA (actual)->ts.u.derived,
2694 : 755 : CLASS_DATA (formal)->ts.u.derived))
2695 : : {
2696 : 1 : if (where)
2697 : 1 : gfc_error ("Actual argument to %qs at %L must have the same "
2698 : : "declared type", formal->name, &actual->where);
2699 : 1 : return false;
2700 : : }
2701 : : }
2702 : :
2703 : : /* F08: 12.5.2.5 Allocatable and pointer dummy variables. However, this
2704 : : is necessary also for F03, so retain error for both.
2705 : : NOTE: Other type/kind errors pre-empt this error. Since they are F03
2706 : : compatible, no attempt has been made to channel to this one. */
2707 : 245837 : if (UNLIMITED_POLY (formal) && !UNLIMITED_POLY (actual)
2708 : 1586 : && (CLASS_DATA (formal)->attr.allocatable
2709 : 1586 : ||CLASS_DATA (formal)->attr.class_pointer))
2710 : : {
2711 : 0 : if (where)
2712 : 0 : gfc_error ("Actual argument to %qs at %L must be unlimited "
2713 : : "polymorphic since the formal argument is a "
2714 : : "pointer or allocatable unlimited polymorphic "
2715 : : "entity [F2008: 12.5.2.5]", formal->name,
2716 : : &actual->where);
2717 : 0 : return false;
2718 : : }
2719 : :
2720 : 245837 : if (formal->ts.type == BT_CLASS && formal->attr.class_ok)
2721 : 13125 : codimension = CLASS_DATA (formal)->attr.codimension;
2722 : : else
2723 : 232712 : codimension = formal->attr.codimension;
2724 : :
2725 : 245837 : if (codimension && !gfc_is_coarray (actual))
2726 : : {
2727 : 4 : if (where)
2728 : 4 : gfc_error ("Actual argument to %qs at %L must be a coarray",
2729 : : formal->name, &actual->where);
2730 : 4 : return false;
2731 : : }
2732 : :
2733 : 232709 : formal_as = (formal->ts.type == BT_CLASS
2734 : 245833 : ? CLASS_DATA (formal)->as : formal->as);
2735 : :
2736 : 245833 : if (codimension && formal->attr.allocatable)
2737 : : {
2738 : 23 : gfc_ref *last = NULL;
2739 : :
2740 : 46 : for (ref = actual->ref; ref; ref = ref->next)
2741 : 23 : if (ref->type == REF_COMPONENT)
2742 : 0 : last = ref;
2743 : :
2744 : : /* F2008, 12.5.2.6. */
2745 : 23 : if ((last && last->u.c.component->as->corank != formal->as->corank)
2746 : : || (!last
2747 : 23 : && actual->symtree->n.sym->as->corank != formal->as->corank))
2748 : : {
2749 : 1 : if (where)
2750 : 1 : gfc_error ("Corank mismatch in argument %qs at %L (%d and %d)",
2751 : 1 : formal->name, &actual->where, formal->as->corank,
2752 : 0 : last ? last->u.c.component->as->corank
2753 : 1 : : actual->symtree->n.sym->as->corank);
2754 : 1 : return false;
2755 : : }
2756 : : }
2757 : :
2758 : 366 : if (codimension)
2759 : : {
2760 : : /* F2008, 12.5.2.8 + Corrig 2 (IR F08/0048). */
2761 : : /* F2018, 12.5.2.8. */
2762 : 366 : if (formal->attr.dimension
2763 : 133 : && (formal->attr.contiguous || formal->as->type != AS_ASSUMED_SHAPE)
2764 : 91 : && actual_attr.dimension
2765 : 456 : && !gfc_is_simply_contiguous (actual, true, true))
2766 : : {
2767 : 2 : if (where)
2768 : 2 : gfc_error ("Actual argument to %qs at %L must be simply "
2769 : : "contiguous or an element of such an array",
2770 : : formal->name, &actual->where);
2771 : 2 : return false;
2772 : : }
2773 : :
2774 : : /* F2008, C1303 and C1304. */
2775 : 364 : if (formal->attr.intent != INTENT_INOUT
2776 : 356 : && (((formal->ts.type == BT_DERIVED || formal->ts.type == BT_CLASS)
2777 : 191 : && formal->ts.u.derived->from_intmod == INTMOD_ISO_FORTRAN_ENV
2778 : 1 : && formal->ts.u.derived->intmod_sym_id == ISOFORTRAN_LOCK_TYPE)
2779 : 355 : || formal->attr.lock_comp))
2780 : :
2781 : : {
2782 : 1 : if (where)
2783 : 1 : gfc_error ("Actual argument to non-INTENT(INOUT) dummy %qs at %L, "
2784 : : "which is LOCK_TYPE or has a LOCK_TYPE component",
2785 : : formal->name, &actual->where);
2786 : 1 : return false;
2787 : : }
2788 : :
2789 : : /* TS18508, C702/C703. */
2790 : 363 : if (formal->attr.intent != INTENT_INOUT
2791 : 355 : && (((formal->ts.type == BT_DERIVED || formal->ts.type == BT_CLASS)
2792 : 190 : && formal->ts.u.derived->from_intmod == INTMOD_ISO_FORTRAN_ENV
2793 : 0 : && formal->ts.u.derived->intmod_sym_id == ISOFORTRAN_EVENT_TYPE)
2794 : 355 : || formal->attr.event_comp))
2795 : :
2796 : : {
2797 : 0 : if (where)
2798 : 0 : gfc_error ("Actual argument to non-INTENT(INOUT) dummy %qs at %L, "
2799 : : "which is EVENT_TYPE or has a EVENT_TYPE component",
2800 : : formal->name, &actual->where);
2801 : 0 : return false;
2802 : : }
2803 : : }
2804 : :
2805 : : /* F2008, C1239/C1240. */
2806 : 245829 : if (actual->expr_type == EXPR_VARIABLE
2807 : 100630 : && (actual->symtree->n.sym->attr.asynchronous
2808 : 100593 : || actual->symtree->n.sym->attr.volatile_)
2809 : 3284 : && (formal->attr.asynchronous || formal->attr.volatile_)
2810 : 75 : && actual->rank && formal->as
2811 : 70 : && !gfc_is_simply_contiguous (actual, true, false)
2812 : 245877 : && ((formal->as->type != AS_ASSUMED_SHAPE
2813 : 19 : && formal->as->type != AS_ASSUMED_RANK && !formal->attr.pointer)
2814 : 37 : || formal->attr.contiguous))
2815 : : {
2816 : 22 : if (where)
2817 : 22 : gfc_error ("Dummy argument %qs has to be a pointer, assumed-shape or "
2818 : : "assumed-rank array without CONTIGUOUS attribute - as actual"
2819 : : " argument at %L is not simply contiguous and both are "
2820 : : "ASYNCHRONOUS or VOLATILE", formal->name, &actual->where);
2821 : 22 : return false;
2822 : : }
2823 : :
2824 : 245807 : if (formal->attr.allocatable && !codimension
2825 : 3077 : && actual_attr.codimension)
2826 : : {
2827 : 5 : if (formal->attr.intent == INTENT_OUT)
2828 : : {
2829 : 1 : if (where)
2830 : 1 : gfc_error ("Passing coarray at %L to allocatable, noncoarray, "
2831 : : "INTENT(OUT) dummy argument %qs", &actual->where,
2832 : : formal->name);
2833 : 1 : return false;
2834 : : }
2835 : 4 : else if (warn_surprising && where && formal->attr.intent != INTENT_IN)
2836 : 1 : gfc_warning (OPT_Wsurprising,
2837 : : "Passing coarray at %L to allocatable, noncoarray dummy "
2838 : : "argument %qs, which is invalid if the allocation status"
2839 : : " is modified", &actual->where, formal->name);
2840 : : }
2841 : :
2842 : : /* If the rank is the same or the formal argument has assumed-rank. */
2843 : 245806 : if (symbol_rank (formal) == actual->rank || symbol_rank (formal) == -1)
2844 : : return true;
2845 : :
2846 : 1810 : rank_check = where != NULL && !is_elemental && formal_as
2847 : 1777 : && (formal_as->type == AS_ASSUMED_SHAPE
2848 : 1777 : || formal_as->type == AS_DEFERRED)
2849 : 7502 : && !(actual->expr_type == EXPR_NULL
2850 : 86 : && actual->ts.type == BT_UNKNOWN);
2851 : :
2852 : : /* Skip rank checks for NO_ARG_CHECK. */
2853 : 7351 : if (formal->attr.ext_attr & (1 << EXT_ATTR_NO_ARG_CHECK))
2854 : : return true;
2855 : :
2856 : : /* Scalar & coindexed, see: F2008, Section 12.5.2.4. */
2857 : 7029 : if (rank_check || ranks_must_agree
2858 : 6871 : || (formal->attr.pointer && actual->expr_type != EXPR_NULL)
2859 : 6871 : || (actual->rank != 0
2860 : 6080 : && !(is_elemental || formal->attr.dimension
2861 : 118 : || (formal->ts.type == BT_CLASS
2862 : 85 : && CLASS_DATA (formal)->attr.dimension)))
2863 : 6838 : || (actual->rank == 0
2864 : 791 : && ((formal->ts.type == BT_CLASS
2865 : 1 : && CLASS_DATA (formal)->as->type == AS_ASSUMED_SHAPE)
2866 : 791 : || (formal->ts.type != BT_CLASS
2867 : 790 : && formal->as->type == AS_ASSUMED_SHAPE))
2868 : 13 : && actual->expr_type != EXPR_NULL)
2869 : 6838 : || (actual->rank == 0
2870 : 791 : && (formal->attr.dimension
2871 : 1 : || (formal->ts.type == BT_CLASS
2872 : 1 : && CLASS_DATA (formal)->attr.dimension))
2873 : 791 : && gfc_is_coindexed (actual))
2874 : : /* Assumed-rank actual argument; F2018 C838. */
2875 : 13864 : || actual->rank == -1)
2876 : : {
2877 : 199 : if (where
2878 : 199 : && (!formal->attr.artificial || (!formal->maybe_array
2879 : 8 : && !maybe_dummy_array_arg (actual))))
2880 : : {
2881 : 104 : locus *where_formal;
2882 : 104 : if (formal->attr.artificial)
2883 : 8 : where_formal = &formal->declared_at;
2884 : : else
2885 : : where_formal = NULL;
2886 : :
2887 : 104 : argument_rank_mismatch (formal->name, &actual->where,
2888 : : symbol_rank (formal), actual->rank,
2889 : : where_formal);
2890 : : }
2891 : 199 : return false;
2892 : : }
2893 : 6830 : else if (actual->rank != 0
2894 : 6042 : && (is_elemental || formal->attr.dimension
2895 : 85 : || (formal->ts.type == BT_CLASS
2896 : 85 : && CLASS_DATA (formal)->attr.dimension)))
2897 : : return true;
2898 : :
2899 : : /* At this point, we are considering a scalar passed to an array. This
2900 : : is valid (cf. F95 12.4.1.1, F2003 12.4.1.2, and F2008 12.5.2.4),
2901 : : - if the actual argument is (a substring of) an element of a
2902 : : non-assumed-shape/non-pointer/non-polymorphic array; or
2903 : : - (F2003) if the actual argument is of type character of default/c_char
2904 : : kind.
2905 : : - (F2018) if the dummy argument is type(*). */
2906 : :
2907 : 1576 : is_pointer = actual->expr_type == EXPR_VARIABLE
2908 : 788 : ? actual->symtree->n.sym->attr.pointer : false;
2909 : :
2910 : 811 : for (ref = actual->ref; ref; ref = ref->next)
2911 : : {
2912 : 439 : if (ref->type == REF_COMPONENT)
2913 : 12 : is_pointer = ref->u.c.component->attr.pointer;
2914 : 427 : else if (ref->type == REF_ARRAY && ref->u.ar.type == AR_ELEMENT
2915 : 420 : && ref->u.ar.dimen > 0
2916 : 417 : && (!ref->next
2917 : 9 : || (ref->next->type == REF_SUBSTRING && !ref->next->next)))
2918 : : break;
2919 : : }
2920 : :
2921 : 788 : if (actual->ts.type == BT_CLASS && actual->expr_type != EXPR_NULL)
2922 : : {
2923 : 0 : if (where)
2924 : 0 : gfc_error ("Polymorphic scalar passed to array dummy argument %qs "
2925 : : "at %L", formal->name, &actual->where);
2926 : 0 : return false;
2927 : : }
2928 : :
2929 : 788 : if (actual->expr_type != EXPR_NULL && ref && actual->ts.type != BT_CHARACTER
2930 : 367 : && (is_pointer || ref->u.ar.as->type == AS_ASSUMED_SHAPE))
2931 : : {
2932 : 10 : if (where)
2933 : : {
2934 : 10 : if (formal->attr.artificial)
2935 : 3 : gfc_error ("Element of assumed-shape or pointer array "
2936 : : "as actual argument at %L cannot correspond to "
2937 : : "actual argument at %L",
2938 : : &actual->where, &formal->declared_at);
2939 : : else
2940 : 7 : gfc_error ("Element of assumed-shape or pointer "
2941 : : "array passed to array dummy argument %qs at %L",
2942 : : formal->name, &actual->where);
2943 : : }
2944 : 10 : return false;
2945 : : }
2946 : :
2947 : 778 : if (actual->ts.type == BT_CHARACTER && actual->expr_type != EXPR_NULL
2948 : 280 : && (!ref || is_pointer || ref->u.ar.as->type == AS_ASSUMED_SHAPE))
2949 : : {
2950 : 263 : if (formal->ts.kind != 1 && (gfc_option.allow_std & GFC_STD_GNU) == 0)
2951 : : {
2952 : 0 : if (where)
2953 : 0 : gfc_error ("Extension: Scalar non-default-kind, non-C_CHAR-kind "
2954 : : "CHARACTER actual argument with array dummy argument "
2955 : : "%qs at %L", formal->name, &actual->where);
2956 : 0 : return false;
2957 : : }
2958 : :
2959 : 263 : if (where && (gfc_option.allow_std & GFC_STD_F2003) == 0)
2960 : : {
2961 : 50 : gfc_error ("Fortran 2003: Scalar CHARACTER actual argument with "
2962 : : "array dummy argument %qs at %L",
2963 : : formal->name, &actual->where);
2964 : 50 : return false;
2965 : : }
2966 : : else
2967 : 213 : return ((gfc_option.allow_std & GFC_STD_F2003) != 0);
2968 : : }
2969 : :
2970 : 498 : if (ref == NULL && actual->expr_type != EXPR_NULL)
2971 : : {
2972 : 53 : if (actual->rank == 0
2973 : 53 : && formal->ts.type == BT_ASSUMED
2974 : 3 : && formal->as
2975 : 3 : && formal->as->type == AS_ASSUMED_SIZE)
2976 : : /* This is new in F2018, type(*) is new in TS29113, but gfortran does
2977 : : not differentiate. Thus, if type(*) exists, it is valid;
2978 : : otherwise, type(*) is already rejected. */
2979 : : return true;
2980 : 50 : if (where
2981 : 50 : && (!formal->attr.artificial || (!formal->maybe_array
2982 : 3 : && !maybe_dummy_array_arg (actual))))
2983 : : {
2984 : 49 : locus *where_formal;
2985 : 49 : if (formal->attr.artificial)
2986 : 2 : where_formal = &formal->declared_at;
2987 : : else
2988 : : where_formal = NULL;
2989 : :
2990 : 49 : argument_rank_mismatch (formal->name, &actual->where,
2991 : : symbol_rank (formal), actual->rank,
2992 : : where_formal);
2993 : : }
2994 : 50 : return false;
2995 : : }
2996 : :
2997 : : return true;
2998 : : }
2999 : :
3000 : :
3001 : : /* Returns the storage size of a symbol (formal argument) or
3002 : : zero if it cannot be determined. */
3003 : :
3004 : : static unsigned long
3005 : 238193 : get_sym_storage_size (gfc_symbol *sym)
3006 : : {
3007 : 238193 : int i;
3008 : 238193 : unsigned long strlen, elements;
3009 : :
3010 : 238193 : if (sym->ts.type == BT_CHARACTER)
3011 : : {
3012 : 33266 : if (sym->ts.u.cl && sym->ts.u.cl->length
3013 : 6988 : && sym->ts.u.cl->length->expr_type == EXPR_CONSTANT
3014 : 6001 : && sym->ts.u.cl->length->ts.type == BT_INTEGER)
3015 : 5999 : strlen = mpz_get_ui (sym->ts.u.cl->length->value.integer);
3016 : : else
3017 : : return 0;
3018 : : }
3019 : : else
3020 : : strlen = 1;
3021 : :
3022 : 210926 : if (symbol_rank (sym) == 0)
3023 : : return strlen;
3024 : :
3025 : 32018 : elements = 1;
3026 : 32018 : if (sym->as->type != AS_EXPLICIT)
3027 : : return 0;
3028 : 14609 : for (i = 0; i < sym->as->rank; i++)
3029 : : {
3030 : 9633 : if (sym->as->upper[i]->expr_type != EXPR_CONSTANT
3031 : 6472 : || sym->as->lower[i]->expr_type != EXPR_CONSTANT
3032 : 6472 : || sym->as->upper[i]->ts.type != BT_INTEGER
3033 : 6471 : || sym->as->lower[i]->ts.type != BT_INTEGER)
3034 : : return 0;
3035 : :
3036 : 6469 : elements *= mpz_get_si (sym->as->upper[i]->value.integer)
3037 : 6469 : - mpz_get_si (sym->as->lower[i]->value.integer) + 1L;
3038 : : }
3039 : :
3040 : 4976 : return strlen*elements;
3041 : : }
3042 : :
3043 : :
3044 : : /* Returns the storage size of an expression (actual argument) or
3045 : : zero if it cannot be determined. For an array element, it returns
3046 : : the remaining size as the element sequence consists of all storage
3047 : : units of the actual argument up to the end of the array. */
3048 : :
3049 : : static unsigned long
3050 : 238193 : get_expr_storage_size (gfc_expr *e)
3051 : : {
3052 : 238193 : int i;
3053 : 238193 : long int strlen, elements;
3054 : 238193 : long int substrlen = 0;
3055 : 238193 : bool is_str_storage = false;
3056 : 238193 : gfc_ref *ref;
3057 : :
3058 : 238193 : if (e == NULL)
3059 : : return 0;
3060 : :
3061 : 238193 : if (e->ts.type == BT_CHARACTER)
3062 : : {
3063 : 33661 : if (e->ts.u.cl && e->ts.u.cl->length
3064 : 11365 : && e->ts.u.cl->length->expr_type == EXPR_CONSTANT
3065 : 10556 : && e->ts.u.cl->length->ts.type == BT_INTEGER)
3066 : 10555 : strlen = mpz_get_si (e->ts.u.cl->length->value.integer);
3067 : 23106 : else if (e->expr_type == EXPR_CONSTANT
3068 : 19452 : && (e->ts.u.cl == NULL || e->ts.u.cl->length == NULL))
3069 : 19452 : strlen = e->value.character.length;
3070 : : else
3071 : : return 0;
3072 : : }
3073 : : else
3074 : : strlen = 1; /* Length per element. */
3075 : :
3076 : 234539 : if (e->rank == 0 && !e->ref)
3077 : 191342 : return strlen;
3078 : :
3079 : 43197 : elements = 1;
3080 : 43197 : if (!e->ref)
3081 : : {
3082 : 6237 : if (!e->shape)
3083 : : return 0;
3084 : 11281 : for (i = 0; i < e->rank; i++)
3085 : 6095 : elements *= mpz_get_si (e->shape[i]);
3086 : 5186 : return elements*strlen;
3087 : : }
3088 : :
3089 : 60409 : for (ref = e->ref; ref; ref = ref->next)
3090 : : {
3091 : 38202 : if (ref->type == REF_SUBSTRING && ref->u.ss.start
3092 : 64 : && ref->u.ss.start->expr_type == EXPR_CONSTANT)
3093 : : {
3094 : 58 : if (is_str_storage)
3095 : : {
3096 : : /* The string length is the substring length.
3097 : : Set now to full string length. */
3098 : 5 : if (!ref->u.ss.length || !ref->u.ss.length->length
3099 : 4 : || ref->u.ss.length->length->expr_type != EXPR_CONSTANT)
3100 : : return 0;
3101 : :
3102 : 4 : strlen = mpz_get_ui (ref->u.ss.length->length->value.integer);
3103 : : }
3104 : 57 : substrlen = strlen - mpz_get_ui (ref->u.ss.start->value.integer) + 1;
3105 : 57 : continue;
3106 : : }
3107 : :
3108 : 38144 : if (ref->type == REF_ARRAY && ref->u.ar.type == AR_SECTION)
3109 : 10748 : for (i = 0; i < ref->u.ar.dimen; i++)
3110 : : {
3111 : 6563 : long int start, end, stride;
3112 : 6563 : stride = 1;
3113 : :
3114 : 6563 : if (ref->u.ar.stride[i])
3115 : : {
3116 : 2586 : if (ref->u.ar.stride[i]->expr_type == EXPR_CONSTANT
3117 : 2423 : && ref->u.ar.stride[i]->ts.type == BT_INTEGER)
3118 : 2423 : stride = mpz_get_si (ref->u.ar.stride[i]->value.integer);
3119 : : else
3120 : : return 0;
3121 : : }
3122 : :
3123 : 6400 : if (ref->u.ar.start[i])
3124 : : {
3125 : 3526 : if (ref->u.ar.start[i]->expr_type == EXPR_CONSTANT
3126 : 3311 : && ref->u.ar.start[i]->ts.type == BT_INTEGER)
3127 : 3311 : start = mpz_get_si (ref->u.ar.start[i]->value.integer);
3128 : : else
3129 : : return 0;
3130 : : }
3131 : 2874 : else if (ref->u.ar.as->lower[i]
3132 : 2584 : && ref->u.ar.as->lower[i]->expr_type == EXPR_CONSTANT
3133 : 2584 : && ref->u.ar.as->lower[i]->ts.type == BT_INTEGER)
3134 : 2584 : start = mpz_get_si (ref->u.ar.as->lower[i]->value.integer);
3135 : : else
3136 : : return 0;
3137 : :
3138 : 5895 : if (ref->u.ar.end[i])
3139 : : {
3140 : 4608 : if (ref->u.ar.end[i]->expr_type == EXPR_CONSTANT
3141 : 4489 : && ref->u.ar.end[i]->ts.type == BT_INTEGER)
3142 : 4489 : end = mpz_get_si (ref->u.ar.end[i]->value.integer);
3143 : : else
3144 : : return 0;
3145 : : }
3146 : 1287 : else if (ref->u.ar.as->upper[i]
3147 : 1039 : && ref->u.ar.as->upper[i]->expr_type == EXPR_CONSTANT
3148 : 1005 : && ref->u.ar.as->upper[i]->ts.type == BT_INTEGER)
3149 : 1004 : end = mpz_get_si (ref->u.ar.as->upper[i]->value.integer);
3150 : : else
3151 : : return 0;
3152 : :
3153 : 5493 : elements *= (end - start)/stride + 1L;
3154 : : }
3155 : 32889 : else if (ref->type == REF_ARRAY && ref->u.ar.type == AR_FULL)
3156 : 47843 : for (i = 0; i < ref->u.ar.as->rank; i++)
3157 : : {
3158 : 32339 : if (ref->u.ar.as->lower[i] && ref->u.ar.as->upper[i]
3159 : 22708 : && ref->u.ar.as->lower[i]->expr_type == EXPR_CONSTANT
3160 : 22659 : && ref->u.ar.as->lower[i]->ts.type == BT_INTEGER
3161 : 22659 : && ref->u.ar.as->upper[i]->expr_type == EXPR_CONSTANT
3162 : 21045 : && ref->u.ar.as->upper[i]->ts.type == BT_INTEGER)
3163 : 21045 : elements *= mpz_get_si (ref->u.ar.as->upper[i]->value.integer)
3164 : 21045 : - mpz_get_si (ref->u.ar.as->lower[i]->value.integer)
3165 : 21045 : + 1L;
3166 : : else
3167 : : return 0;
3168 : : }
3169 : 6091 : else if (ref->type == REF_ARRAY && ref->u.ar.type == AR_ELEMENT
3170 : 3996 : && e->expr_type == EXPR_VARIABLE)
3171 : : {
3172 : 3996 : if (ref->u.ar.as->type == AS_ASSUMED_SHAPE
3173 : 3827 : || e->symtree->n.sym->attr.pointer)
3174 : : {
3175 : 210 : elements = 1;
3176 : 210 : continue;
3177 : : }
3178 : :
3179 : : /* Determine the number of remaining elements in the element
3180 : : sequence for array element designators. */
3181 : 3786 : is_str_storage = true;
3182 : 5298 : for (i = ref->u.ar.dimen - 1; i >= 0; i--)
3183 : : {
3184 : 3899 : if (ref->u.ar.start[i] == NULL
3185 : 3899 : || ref->u.ar.start[i]->expr_type != EXPR_CONSTANT
3186 : 2110 : || ref->u.ar.as->upper[i] == NULL
3187 : 1539 : || ref->u.ar.as->lower[i] == NULL
3188 : 1539 : || ref->u.ar.as->upper[i]->expr_type != EXPR_CONSTANT
3189 : 1512 : || ref->u.ar.as->lower[i]->expr_type != EXPR_CONSTANT
3190 : 1512 : || ref->u.ar.as->upper[i]->ts.type != BT_INTEGER
3191 : 1512 : || ref->u.ar.as->lower[i]->ts.type != BT_INTEGER)
3192 : : return 0;
3193 : :
3194 : 1512 : elements
3195 : 1512 : = elements
3196 : 1512 : * (mpz_get_si (ref->u.ar.as->upper[i]->value.integer)
3197 : 1512 : - mpz_get_si (ref->u.ar.as->lower[i]->value.integer)
3198 : 1512 : + 1L)
3199 : 1512 : - (mpz_get_si (ref->u.ar.start[i]->value.integer)
3200 : 1512 : - mpz_get_si (ref->u.ar.as->lower[i]->value.integer));
3201 : : }
3202 : : }
3203 : 2095 : else if (ref->type == REF_COMPONENT && ref->u.c.component->attr.function
3204 : 90 : && ref->u.c.component->attr.proc_pointer
3205 : 90 : && ref->u.c.component->attr.dimension)
3206 : : {
3207 : : /* Array-valued procedure-pointer components. */
3208 : 8 : gfc_array_spec *as = ref->u.c.component->as;
3209 : 15 : for (i = 0; i < as->rank; i++)
3210 : : {
3211 : 8 : if (!as->upper[i] || !as->lower[i]
3212 : 8 : || as->upper[i]->expr_type != EXPR_CONSTANT
3213 : 7 : || as->lower[i]->expr_type != EXPR_CONSTANT
3214 : 7 : || as->upper[i]->ts.type != BT_INTEGER
3215 : 7 : || as->lower[i]->ts.type != BT_INTEGER)
3216 : : return 0;
3217 : :
3218 : 7 : elements = elements
3219 : 7 : * (mpz_get_si (as->upper[i]->value.integer)
3220 : 7 : - mpz_get_si (as->lower[i]->value.integer) + 1L);
3221 : : }
3222 : : }
3223 : : }
3224 : :
3225 : 22207 : if (substrlen)
3226 : 51 : return (is_str_storage) ? substrlen + (elements-1)*strlen
3227 : 51 : : elements*strlen;
3228 : : else
3229 : 22156 : return elements*strlen;
3230 : : }
3231 : :
3232 : :
3233 : : /* Given an expression, check whether it is an array section
3234 : : which has a vector subscript. */
3235 : :
3236 : : bool
3237 : 16790 : gfc_has_vector_subscript (gfc_expr *e)
3238 : : {
3239 : 16790 : int i;
3240 : 16790 : gfc_ref *ref;
3241 : :
3242 : 16790 : if (e == NULL || e->rank == 0 || e->expr_type != EXPR_VARIABLE)
3243 : : return false;
3244 : :
3245 : 16312 : for (ref = e->ref; ref; ref = ref->next)
3246 : 9255 : if (ref->type == REF_ARRAY && ref->u.ar.type == AR_SECTION)
3247 : 2669 : for (i = 0; i < ref->u.ar.dimen; i++)
3248 : 1754 : if (ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
3249 : : return true;
3250 : :
3251 : : return false;
3252 : : }
3253 : :
3254 : :
3255 : : static bool
3256 : 27 : is_procptr_result (gfc_expr *expr)
3257 : : {
3258 : 27 : gfc_component *c = gfc_get_proc_ptr_comp (expr);
3259 : 27 : if (c)
3260 : 2 : return (c->ts.interface && (c->ts.interface->attr.proc_pointer == 1));
3261 : : else
3262 : 26 : return ((expr->symtree->n.sym->result != expr->symtree->n.sym)
3263 : 28 : && (expr->symtree->n.sym->result->attr.proc_pointer == 1));
3264 : : }
3265 : :
3266 : :
3267 : : /* Recursively append candidate argument ARG to CANDIDATES. Store the
3268 : : number of total candidates in CANDIDATES_LEN. */
3269 : :
3270 : : static void
3271 : 1 : lookup_arg_fuzzy_find_candidates (gfc_formal_arglist *arg,
3272 : : char **&candidates,
3273 : : size_t &candidates_len)
3274 : : {
3275 : 2 : for (gfc_formal_arglist *p = arg; p && p->sym; p = p->next)
3276 : 1 : vec_push (candidates, candidates_len, p->sym->name);
3277 : 1 : }
3278 : :
3279 : :
3280 : : /* Lookup argument ARG fuzzily, taking names in ARGUMENTS into account. */
3281 : :
3282 : : static const char*
3283 : 1 : lookup_arg_fuzzy (const char *arg, gfc_formal_arglist *arguments)
3284 : : {
3285 : 1 : char **candidates = NULL;
3286 : 1 : size_t candidates_len = 0;
3287 : 1 : lookup_arg_fuzzy_find_candidates (arguments, candidates, candidates_len);
3288 : 1 : return gfc_closest_fuzzy_match (arg, candidates);
3289 : : }
3290 : :
3291 : :
3292 : : static gfc_dummy_arg *
3293 : 359901 : get_nonintrinsic_dummy_arg (gfc_formal_arglist *formal)
3294 : : {
3295 : 0 : gfc_dummy_arg * const dummy_arg = gfc_get_dummy_arg ();
3296 : :
3297 : 359901 : dummy_arg->intrinsicness = GFC_NON_INTRINSIC_DUMMY_ARG;
3298 : 359901 : dummy_arg->u.non_intrinsic = formal;
3299 : :
3300 : 359901 : return dummy_arg;
3301 : : }
3302 : :
3303 : :
3304 : : /* Given formal and actual argument lists, see if they are compatible.
3305 : : If they are compatible, the actual argument list is sorted to
3306 : : correspond with the formal list, and elements for missing optional
3307 : : arguments are inserted. If WHERE pointer is nonnull, then we issue
3308 : : errors when things don't match instead of just returning the status
3309 : : code. */
3310 : :
3311 : : bool
3312 : 189735 : gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal,
3313 : : int ranks_must_agree, int is_elemental,
3314 : : bool in_statement_function, locus *where)
3315 : : {
3316 : 189735 : gfc_actual_arglist **new_arg, *a, *actual;
3317 : 189735 : gfc_formal_arglist *f;
3318 : 189735 : int i, n, na;
3319 : 189735 : unsigned long actual_size, formal_size;
3320 : 189735 : bool full_array = false;
3321 : 189735 : gfc_array_ref *actual_arr_ref;
3322 : 189735 : gfc_array_spec *fas, *aas;
3323 : 189735 : bool pointer_dummy, pointer_arg, allocatable_arg;
3324 : 189735 : bool procptr_dummy, optional_dummy, allocatable_dummy;
3325 : :
3326 : 189735 : bool ok = true;
3327 : :
3328 : 189735 : actual = *ap;
3329 : :
3330 : 189735 : if (actual == NULL && formal == NULL)
3331 : : return true;
3332 : :
3333 : : n = 0;
3334 : 533137 : for (f = formal; f; f = f->next)
3335 : 360276 : n++;
3336 : :
3337 : 172861 : new_arg = XALLOCAVEC (gfc_actual_arglist *, n);
3338 : :
3339 : 533137 : for (i = 0; i < n; i++)
3340 : 360276 : new_arg[i] = NULL;
3341 : :
3342 : : na = 0;
3343 : : f = formal;
3344 : : i = 0;
3345 : :
3346 : 527403 : for (a = actual; a; a = a->next, f = f->next)
3347 : : {
3348 : 355693 : if (a->name != NULL && in_statement_function)
3349 : : {
3350 : 1 : gfc_error ("Keyword argument %qs at %L is invalid in "
3351 : 1 : "a statement function", a->name, &a->expr->where);
3352 : 1 : return false;
3353 : : }
3354 : :
3355 : : /* Look for keywords but ignore g77 extensions like %VAL. */
3356 : 355692 : if (a->name != NULL && a->name[0] != '%')
3357 : : {
3358 : : i = 0;
3359 : 12126 : for (f = formal; f; f = f->next, i++)
3360 : : {
3361 : 12110 : if (f->sym == NULL)
3362 : 0 : continue;
3363 : 12110 : if (strcmp (f->sym->name, a->name) == 0)
3364 : : break;
3365 : : }
3366 : :
3367 : 3498 : if (f == NULL)
3368 : : {
3369 : 16 : if (where)
3370 : : {
3371 : 1 : const char *guessed = lookup_arg_fuzzy (a->name, formal);
3372 : 1 : if (guessed)
3373 : 1 : gfc_error ("Keyword argument %qs at %L is not in "
3374 : : "the procedure; did you mean %qs?",
3375 : 1 : a->name, &a->expr->where, guessed);
3376 : : else
3377 : 0 : gfc_error ("Keyword argument %qs at %L is not in "
3378 : 0 : "the procedure", a->name, &a->expr->where);
3379 : : }
3380 : 16 : return false;
3381 : : }
3382 : :
3383 : 3498 : if (new_arg[i] != NULL)
3384 : : {
3385 : 0 : if (where)
3386 : 0 : gfc_error ("Keyword argument %qs at %L is already associated "
3387 : : "with another actual argument", a->name,
3388 : 0 : &a->expr->where);
3389 : 0 : return false;
3390 : : }
3391 : : }
3392 : :
3393 : 355676 : if (f == NULL)
3394 : : {
3395 : 1126 : if (where)
3396 : 8 : gfc_error ("More actual than formal arguments in procedure "
3397 : : "call at %L", where);
3398 : 1126 : return false;
3399 : : }
3400 : :
3401 : 354550 : if (f->sym == NULL && a->expr == NULL)
3402 : 210 : goto match;
3403 : :
3404 : 354340 : if (f->sym == NULL)
3405 : : {
3406 : : /* These errors have to be issued, otherwise an ICE can occur.
3407 : : See PR 78865. */
3408 : 6 : if (where)
3409 : 6 : gfc_error_now ("Missing alternate return specifier in subroutine "
3410 : : "call at %L", where);
3411 : 6 : return false;
3412 : : }
3413 : : else
3414 : : {
3415 : 354334 : if (a->associated_dummy)
3416 : 120391 : free (a->associated_dummy);
3417 : 354334 : a->associated_dummy = get_nonintrinsic_dummy_arg (f);
3418 : : }
3419 : :
3420 : 354334 : if (a->expr == NULL)
3421 : : {
3422 : 8 : if (f->sym->attr.optional)
3423 : 6 : continue;
3424 : : else
3425 : : {
3426 : 2 : if (where)
3427 : 1 : gfc_error_now ("Unexpected alternate return specifier in "
3428 : : "subroutine call at %L", where);
3429 : 2 : return false;
3430 : : }
3431 : : }
3432 : :
3433 : : /* Make sure that intrinsic vtables exist for calls to unlimited
3434 : : polymorphic formal arguments. */
3435 : 354326 : if (UNLIMITED_POLY (f->sym)
3436 : 2711 : && a->expr->ts.type != BT_DERIVED
3437 : : && a->expr->ts.type != BT_CLASS
3438 : : && a->expr->ts.type != BT_ASSUMED)
3439 : 911 : gfc_find_vtab (&a->expr->ts);
3440 : :
3441 : : /* Interp J3/22-146:
3442 : : "If the context of the reference to NULL is an <actual argument>
3443 : : corresponding to an <assumed-rank> dummy argument, MOLD shall be
3444 : : present." */
3445 : 354326 : if (a->expr->expr_type == EXPR_NULL
3446 : 826 : && a->expr->ts.type == BT_UNKNOWN
3447 : 264 : && f->sym->as
3448 : 97 : && f->sym->as->type == AS_ASSUMED_RANK)
3449 : : {
3450 : 1 : gfc_error ("Intrinsic %<NULL()%> without %<MOLD%> argument at %L "
3451 : : "passed to assumed-rank dummy %qs",
3452 : : &a->expr->where, f->sym->name);
3453 : 1 : ok = false;
3454 : 1 : goto match;
3455 : : }
3456 : :
3457 : 354325 : if (warn_surprising
3458 : 1204 : && a->expr->expr_type == EXPR_VARIABLE
3459 : 591 : && a->expr->symtree->n.sym->as
3460 : 239 : && a->expr->symtree->n.sym->as->type == AS_ASSUMED_SIZE
3461 : 137 : && f->sym->as
3462 : 137 : && f->sym->as->type == AS_ASSUMED_RANK)
3463 : 1 : gfc_warning (0, "The assumed-size dummy %qs is being passed at %L to "
3464 : : "an assumed-rank dummy %qs", a->expr->symtree->name,
3465 : : &a->expr->where, f->sym->name);
3466 : :
3467 : 354325 : if (a->expr->expr_type == EXPR_NULL
3468 : 825 : && a->expr->ts.type == BT_UNKNOWN
3469 : 263 : && f->sym->ts.type == BT_CHARACTER
3470 : 83 : && !f->sym->ts.deferred
3471 : 46 : && f->sym->ts.u.cl
3472 : 46 : && f->sym->ts.u.cl->length == NULL)
3473 : : {
3474 : 1 : gfc_error ("Intrinsic %<NULL()%> without %<MOLD%> argument at %L "
3475 : : "passed to assumed-length dummy %qs",
3476 : : &a->expr->where, f->sym->name);
3477 : 1 : ok = false;
3478 : 1 : goto match;
3479 : : }
3480 : :
3481 : : /* Allow passing of NULL() as disassociated pointer, procedure
3482 : : pointer, or unallocated allocatable (F2008+) to a respective dummy
3483 : : argument. */
3484 : 708648 : pointer_dummy = ((f->sym->ts.type != BT_CLASS
3485 : 340595 : && f->sym->attr.pointer)
3486 : 689626 : || (f->sym->ts.type == BT_CLASS
3487 : 13729 : && CLASS_DATA (f->sym)->attr.class_pointer));
3488 : :
3489 : 708648 : procptr_dummy = ((f->sym->ts.type != BT_CLASS
3490 : 340595 : && f->sym->attr.proc_pointer)
3491 : 694751 : || (f->sym->ts.type == BT_CLASS
3492 : 13729 : && CLASS_DATA (f->sym)->attr.proc_pointer));
3493 : :
3494 : 354324 : optional_dummy = f->sym->attr.optional;
3495 : :
3496 : 708648 : allocatable_dummy = ((f->sym->ts.type != BT_CLASS
3497 : 340595 : && f->sym->attr.allocatable)
3498 : 691805 : || (f->sym->ts.type == BT_CLASS
3499 : 13729 : && CLASS_DATA (f->sym)->attr.allocatable));
3500 : :
3501 : 354324 : if (a->expr->expr_type == EXPR_NULL
3502 : : && !pointer_dummy
3503 : 824 : && !procptr_dummy
3504 : 338 : && !(optional_dummy
3505 : 287 : && (gfc_option.allow_std & GFC_STD_F2008) != 0)
3506 : 54 : && !(allocatable_dummy
3507 : 50 : && (gfc_option.allow_std & GFC_STD_F2008) != 0))
3508 : : {
3509 : 5 : if (where
3510 : 4 : && (!f->sym->attr.optional
3511 : 2 : || (f->sym->ts.type != BT_CLASS && f->sym->attr.allocatable)
3512 : 1 : || (f->sym->ts.type == BT_CLASS
3513 : 0 : && CLASS_DATA (f->sym)->attr.allocatable)))
3514 : 3 : gfc_error ("Unexpected NULL() intrinsic at %L to dummy %qs",
3515 : : where, f->sym->name);
3516 : 1 : else if (where)
3517 : 1 : gfc_error ("Fortran 2008: Null pointer at %L to non-pointer "
3518 : : "dummy %qs", where, f->sym->name);
3519 : 5 : ok = false;
3520 : 5 : goto match;
3521 : : }
3522 : :
3523 : 354319 : if (!compare_parameter (f->sym, a->expr, ranks_must_agree,
3524 : : is_elemental, where))
3525 : : {
3526 : 102721 : ok = false;
3527 : 102721 : goto match;
3528 : : }
3529 : :
3530 : : /* TS 29113, 6.3p2; F2018 15.5.2.4. */
3531 : 251598 : if (f->sym->ts.type == BT_ASSUMED
3532 : 3370 : && (a->expr->ts.type == BT_DERIVED
3533 : 2926 : || (a->expr->ts.type == BT_CLASS && CLASS_DATA (a->expr))))
3534 : : {
3535 : 651 : gfc_symbol *derived = (a->expr->ts.type == BT_DERIVED
3536 : : ? a->expr->ts.u.derived
3537 : 207 : : CLASS_DATA (a->expr)->ts.u.derived);
3538 : 651 : gfc_namespace *f2k_derived = derived->f2k_derived;
3539 : 651 : if (derived->attr.pdt_type
3540 : 650 : || (f2k_derived
3541 : 585 : && (f2k_derived->finalizers || f2k_derived->tb_sym_root)))
3542 : : {
3543 : 5 : gfc_error ("Actual argument at %L to assumed-type dummy "
3544 : : "has type parameters or is of "
3545 : : "derived type with type-bound or FINAL procedures",
3546 : : &a->expr->where);
3547 : 5 : ok = false;
3548 : 5 : goto match;
3549 : : }
3550 : : }
3551 : :
3552 : 251593 : if (UNLIMITED_POLY (a->expr)
3553 : 1099 : && !(f->sym->ts.type == BT_ASSUMED || UNLIMITED_POLY (f->sym)))
3554 : : {
3555 : 1 : gfc_error ("Unlimited polymorphic actual argument at %L is not "
3556 : : "matched with either an unlimited polymorphic or "
3557 : : "assumed type dummy argument", &a->expr->where);
3558 : 1 : ok = false;
3559 : 1 : goto match;
3560 : : }
3561 : :
3562 : : /* Special case for character arguments. For allocatable, pointer
3563 : : and assumed-shape dummies, the string length needs to match
3564 : : exactly. */
3565 : 251592 : if (a->expr->ts.type == BT_CHARACTER
3566 : 33846 : && a->expr->ts.u.cl && a->expr->ts.u.cl->length
3567 : 11497 : && a->expr->ts.u.cl->length->expr_type == EXPR_CONSTANT
3568 : 10688 : && a->expr->ts.u.cl->length->ts.type == BT_INTEGER
3569 : 10687 : && f->sym->ts.type == BT_CHARACTER && f->sym->ts.u.cl
3570 : 10356 : && f->sym->ts.u.cl->length
3571 : 5463 : && f->sym->ts.u.cl->length->expr_type == EXPR_CONSTANT
3572 : 4610 : && f->sym->ts.u.cl->length->ts.type == BT_INTEGER
3573 : 4608 : && (f->sym->attr.pointer || f->sym->attr.allocatable
3574 : 4204 : || (f->sym->as && f->sym->as->type == AS_ASSUMED_SHAPE))
3575 : 1000 : && (mpz_cmp (a->expr->ts.u.cl->length->value.integer,
3576 : 1000 : f->sym->ts.u.cl->length->value.integer) != 0))
3577 : : {
3578 : 6 : if (where && (f->sym->attr.pointer || f->sym->attr.allocatable))
3579 : 5 : gfc_warning (0, "Character length mismatch (%ld/%ld) between actual "
3580 : : "argument and pointer or allocatable dummy argument "
3581 : : "%qs at %L",
3582 : : mpz_get_si (a->expr->ts.u.cl->length->value.integer),
3583 : : mpz_get_si (f->sym->ts.u.cl->length->value.integer),
3584 : : f->sym->name, &a->expr->where);
3585 : 1 : else if (where)
3586 : 1 : gfc_warning (0, "Character length mismatch (%ld/%ld) between actual "
3587 : : "argument and assumed-shape dummy argument %qs "
3588 : : "at %L",
3589 : : mpz_get_si (a->expr->ts.u.cl->length->value.integer),
3590 : : mpz_get_si (f->sym->ts.u.cl->length->value.integer),
3591 : : f->sym->name, &a->expr->where);
3592 : 6 : ok = false;
3593 : 6 : goto match;
3594 : : }
3595 : :
3596 : 251586 : if ((f->sym->attr.pointer || f->sym->attr.allocatable)
3597 : 8251 : && f->sym->ts.deferred != a->expr->ts.deferred
3598 : 38 : && a->expr->ts.type == BT_CHARACTER)
3599 : : {
3600 : 1 : if (where)
3601 : 1 : gfc_error ("Actual argument at %L to allocatable or "
3602 : : "pointer dummy argument %qs must have a deferred "
3603 : : "length type parameter if and only if the dummy has one",
3604 : : &a->expr->where, f->sym->name);
3605 : 1 : ok = false;
3606 : 1 : goto match;
3607 : : }
3608 : :
3609 : 251585 : if (f->sym->ts.type == BT_CLASS)
3610 : 13135 : goto skip_size_check;
3611 : :
3612 : : /* Skip size check for NULL() actual without MOLD argument. */
3613 : 238450 : if (a->expr->expr_type == EXPR_NULL && a->expr->ts.type == BT_UNKNOWN)
3614 : 257 : goto skip_size_check;
3615 : :
3616 : 238193 : actual_size = get_expr_storage_size (a->expr);
3617 : 238193 : formal_size = get_sym_storage_size (f->sym);
3618 : 238193 : if (actual_size != 0 && actual_size < formal_size
3619 : 88 : && a->expr->ts.type != BT_PROCEDURE
3620 : 82 : && f->sym->attr.flavor != FL_PROCEDURE)
3621 : : {
3622 : 82 : if (a->expr->ts.type == BT_CHARACTER && !f->sym->as && where)
3623 : : {
3624 : 38 : gfc_warning (0, "Character length of actual argument shorter "
3625 : : "than of dummy argument %qs (%lu/%lu) at %L",
3626 : : f->sym->name, actual_size, formal_size,
3627 : : &a->expr->where);
3628 : 38 : goto skip_size_check;
3629 : : }
3630 : 44 : else if (where)
3631 : : {
3632 : : /* Emit a warning for -std=legacy and an error otherwise. */
3633 : 44 : if (gfc_option.warn_std == 0)
3634 : 0 : gfc_warning (0, "Actual argument contains too few "
3635 : : "elements for dummy argument %qs (%lu/%lu) "
3636 : : "at %L", f->sym->name, actual_size,
3637 : : formal_size, &a->expr->where);
3638 : : else
3639 : 44 : gfc_error_now ("Actual argument contains too few "
3640 : : "elements for dummy argument %qs (%lu/%lu) "
3641 : : "at %L", f->sym->name, actual_size,
3642 : : formal_size, &a->expr->where);
3643 : : }
3644 : 44 : ok = false;
3645 : 44 : goto match;
3646 : : }
3647 : :
3648 : 238111 : skip_size_check:
3649 : :
3650 : : /* Satisfy either: F03:12.4.1.3 by ensuring that a procedure pointer
3651 : : actual argument is provided for a procedure pointer formal argument;
3652 : : or: F08:12.5.2.9 (F18:15.5.2.10) by ensuring that the effective
3653 : : argument shall be an external, internal, module, or dummy procedure.
3654 : : The interfaces are checked elsewhere. */
3655 : 251541 : if (f->sym->attr.proc_pointer
3656 : 251541 : && !((a->expr->expr_type == EXPR_VARIABLE
3657 : 158 : && (a->expr->symtree->n.sym->attr.proc_pointer
3658 : 25 : || gfc_is_proc_ptr_comp (a->expr)))
3659 : 10 : || (a->expr->ts.type == BT_PROCEDURE
3660 : 4 : && f->sym->ts.interface)
3661 : 6 : || (a->expr->expr_type == EXPR_FUNCTION
3662 : 6 : && is_procptr_result (a->expr))))
3663 : : {
3664 : 0 : if (where)
3665 : 0 : gfc_error ("Expected a procedure pointer for argument %qs at %L",
3666 : 0 : f->sym->name, &a->expr->where);
3667 : 0 : ok = false;
3668 : 0 : goto match;
3669 : : }
3670 : :
3671 : : /* Satisfy F03:12.4.1.3 by ensuring that a procedure actual argument is
3672 : : provided for a procedure formal argument. */
3673 : 251541 : if (f->sym->attr.flavor == FL_PROCEDURE
3674 : 251541 : && !((a->expr->expr_type == EXPR_VARIABLE
3675 : 1903 : && (a->expr->symtree->n.sym->attr.flavor == FL_PROCEDURE
3676 : 32 : || a->expr->symtree->n.sym->attr.proc_pointer
3677 : 32 : || gfc_is_proc_ptr_comp (a->expr)))
3678 : 30 : || (a->expr->expr_type == EXPR_FUNCTION
3679 : 21 : && is_procptr_result (a->expr))))
3680 : : {
3681 : 12 : if (where)
3682 : 6 : gfc_error ("Expected a procedure for argument %qs at %L",
3683 : 6 : f->sym->name, &a->expr->where);
3684 : 12 : ok = false;
3685 : 12 : goto match;
3686 : : }
3687 : :
3688 : : /* Class array variables and expressions store array info in a
3689 : : different place from non-class objects; consolidate the logic
3690 : : to access it here instead of repeating it below. Note that
3691 : : pointer_arg and allocatable_arg are not fully general and are
3692 : : only used in a specific situation below with an assumed-rank
3693 : : argument. */
3694 : 251529 : if (f->sym->ts.type == BT_CLASS && CLASS_DATA (f->sym))
3695 : : {
3696 : 13135 : gfc_component *classdata = CLASS_DATA (f->sym);
3697 : 13135 : fas = classdata->as;
3698 : 13135 : pointer_dummy = classdata->attr.class_pointer;
3699 : 13135 : }
3700 : : else
3701 : : {
3702 : 238394 : fas = f->sym->as;
3703 : 238394 : pointer_dummy = f->sym->attr.pointer;
3704 : : }
3705 : :
3706 : 251529 : if (a->expr->expr_type != EXPR_VARIABLE
3707 : 146709 : && !(a->expr->expr_type == EXPR_NULL
3708 : 758 : && a->expr->ts.type != BT_UNKNOWN))
3709 : : {
3710 : : aas = NULL;
3711 : : pointer_arg = false;
3712 : : allocatable_arg = false;
3713 : : }
3714 : 105321 : else if (a->expr->ts.type == BT_CLASS
3715 : 6457 : && a->expr->symtree->n.sym
3716 : 6457 : && CLASS_DATA (a->expr->symtree->n.sym))
3717 : : {
3718 : 6454 : gfc_component *classdata = CLASS_DATA (a->expr->symtree->n.sym);
3719 : 6454 : aas = classdata->as;
3720 : 6454 : pointer_arg = classdata->attr.class_pointer;
3721 : 6454 : allocatable_arg = classdata->attr.allocatable;
3722 : 6454 : }
3723 : : else
3724 : : {
3725 : 98867 : aas = a->expr->symtree->n.sym->as;
3726 : 98867 : pointer_arg = a->expr->symtree->n.sym->attr.pointer;
3727 : 98867 : allocatable_arg = a->expr->symtree->n.sym->attr.allocatable;
3728 : : }
3729 : :
3730 : : /* F2018:9.5.2(2) permits assumed-size whole array expressions as
3731 : : actual arguments only if the shape is not required; thus it
3732 : : cannot be passed to an assumed-shape array dummy.
3733 : : F2018:15.5.2.(2) permits passing a nonpointer actual to an
3734 : : intent(in) pointer dummy argument and this is accepted by
3735 : : the compare_pointer check below, but this also requires shape
3736 : : information.
3737 : : There's more discussion of this in PR94110. */
3738 : 251529 : if (fas
3739 : 41803 : && (fas->type == AS_ASSUMED_SHAPE
3740 : 41803 : || fas->type == AS_DEFERRED
3741 : 21587 : || (fas->type == AS_ASSUMED_RANK && pointer_dummy))
3742 : 21278 : && aas
3743 : 16864 : && aas->type == AS_ASSUMED_SIZE
3744 : 14 : && (a->expr->ref == NULL
3745 : 14 : || (a->expr->ref->type == REF_ARRAY
3746 : 14 : && a->expr->ref->u.ar.type == AR_FULL)))
3747 : : {
3748 : 10 : if (where)
3749 : 10 : gfc_error ("Actual argument for %qs cannot be an assumed-size"
3750 : : " array at %L", f->sym->name, where);
3751 : 10 : ok = false;
3752 : 10 : goto match;
3753 : : }
3754 : :
3755 : : /* Diagnose F2018 C839 (TS29113 C535c). Here the problem is
3756 : : passing an assumed-size array to an INTENT(OUT) assumed-rank
3757 : : dummy when it doesn't have the size information needed to run
3758 : : initializers and finalizers. */
3759 : 251519 : if (f->sym->attr.intent == INTENT_OUT
3760 : 6529 : && fas
3761 : 1206 : && fas->type == AS_ASSUMED_RANK
3762 : 276 : && aas
3763 : 223 : && ((aas->type == AS_ASSUMED_SIZE
3764 : 61 : && (a->expr->ref == NULL
3765 : 61 : || (a->expr->ref->type == REF_ARRAY
3766 : 61 : && a->expr->ref->u.ar.type == AR_FULL)))
3767 : 173 : || (aas->type == AS_ASSUMED_RANK
3768 : : && !pointer_arg
3769 : 34 : && !allocatable_arg))
3770 : 251587 : && (a->expr->ts.type == BT_CLASS
3771 : 62 : || (a->expr->ts.type == BT_DERIVED
3772 : 16 : && (gfc_is_finalizable (a->expr->ts.u.derived, NULL)
3773 : 14 : || gfc_has_ultimate_allocatable (a->expr)
3774 : 12 : || gfc_has_default_initializer
3775 : 12 : (a->expr->ts.u.derived)))))
3776 : : {
3777 : 12 : if (where)
3778 : 12 : gfc_error ("Actual argument to assumed-rank INTENT(OUT) "
3779 : : "dummy %qs at %L cannot be of unknown size",
3780 : 12 : f->sym->name, where);
3781 : 12 : ok = false;
3782 : 12 : goto match;
3783 : : }
3784 : :
3785 : 251507 : if (a->expr->expr_type != EXPR_NULL)
3786 : : {
3787 : 250749 : int cmp = compare_pointer (f->sym, a->expr);
3788 : 250749 : bool pre2008 = ((gfc_option.allow_std & GFC_STD_F2008) == 0);
3789 : :
3790 : 250749 : if (pre2008 && cmp == 0)
3791 : : {
3792 : 1 : if (where)
3793 : 1 : gfc_error ("Actual argument for %qs at %L must be a pointer",
3794 : 1 : f->sym->name, &a->expr->where);
3795 : 1 : ok = false;
3796 : 1 : goto match;
3797 : : }
3798 : :
3799 : 250748 : if (pre2008 && cmp == 2)
3800 : : {
3801 : 3 : if (where)
3802 : 3 : gfc_error ("Fortran 2008: Non-pointer actual argument at %L to "
3803 : 3 : "pointer dummy %qs", &a->expr->where, f->sym->name);
3804 : 3 : ok = false;
3805 : 3 : goto match;
3806 : : }
3807 : :
3808 : 250745 : if (!pre2008 && cmp == 0)
3809 : : {
3810 : 11 : if (where)
3811 : 5 : gfc_error ("Actual argument for %qs at %L must be a pointer "
3812 : : "or a valid target for the dummy pointer in a "
3813 : : "pointer assignment statement",
3814 : 5 : f->sym->name, &a->expr->where);
3815 : 11 : ok = false;
3816 : 11 : goto match;
3817 : : }
3818 : : }
3819 : :
3820 : :
3821 : : /* Fortran 2008, C1242. */
3822 : 251492 : if (f->sym->attr.pointer && gfc_is_coindexed (a->expr))
3823 : : {
3824 : 2 : if (where)
3825 : 2 : gfc_error ("Coindexed actual argument at %L to pointer "
3826 : : "dummy %qs",
3827 : 2 : &a->expr->where, f->sym->name);
3828 : 2 : ok = false;
3829 : 2 : goto match;
3830 : : }
3831 : :
3832 : : /* Fortran 2008, 12.5.2.5 (no constraint). */
3833 : 251490 : if (a->expr->expr_type == EXPR_VARIABLE
3834 : 104782 : && f->sym->attr.intent != INTENT_IN
3835 : 60519 : && f->sym->attr.allocatable
3836 : 254296 : && gfc_is_coindexed (a->expr))
3837 : : {
3838 : 1 : if (where)
3839 : 1 : gfc_error ("Coindexed actual argument at %L to allocatable "
3840 : : "dummy %qs requires INTENT(IN)",
3841 : 1 : &a->expr->where, f->sym->name);
3842 : 1 : ok = false;
3843 : 1 : goto match;
3844 : : }
3845 : :
3846 : : /* Fortran 2008, C1237. */
3847 : 251489 : if (a->expr->expr_type == EXPR_VARIABLE
3848 : 104781 : && (f->sym->attr.asynchronous || f->sym->attr.volatile_)
3849 : 65 : && gfc_is_coindexed (a->expr)
3850 : 251491 : && (a->expr->symtree->n.sym->attr.volatile_
3851 : 1 : || a->expr->symtree->n.sym->attr.asynchronous))
3852 : : {
3853 : 2 : if (where)
3854 : 2 : gfc_error ("Coindexed ASYNCHRONOUS or VOLATILE actual argument at "
3855 : : "%L requires that dummy %qs has neither "
3856 : : "ASYNCHRONOUS nor VOLATILE", &a->expr->where,
3857 : 2 : f->sym->name);
3858 : 2 : ok = false;
3859 : 2 : goto match;
3860 : : }
3861 : :
3862 : : /* Fortran 2008, 12.5.2.4 (no constraint). */
3863 : 251487 : if (a->expr->expr_type == EXPR_VARIABLE
3864 : 104779 : && f->sym->attr.intent != INTENT_IN && !f->sym->attr.value
3865 : 56124 : && gfc_is_coindexed (a->expr)
3866 : 251498 : && gfc_has_ultimate_allocatable (a->expr))
3867 : : {
3868 : 1 : if (where)
3869 : 1 : gfc_error ("Coindexed actual argument at %L with allocatable "
3870 : : "ultimate component to dummy %qs requires either VALUE "
3871 : 1 : "or INTENT(IN)", &a->expr->where, f->sym->name);
3872 : 1 : ok = false;
3873 : 1 : goto match;
3874 : : }
3875 : :
3876 : 251486 : if (f->sym->ts.type == BT_CLASS
3877 : 13127 : && CLASS_DATA (f->sym)->attr.allocatable
3878 : 860 : && gfc_is_class_array_ref (a->expr, &full_array)
3879 : 251930 : && !full_array)
3880 : : {
3881 : 0 : if (where)
3882 : 0 : gfc_error ("Actual CLASS array argument for %qs must be a full "
3883 : 0 : "array at %L", f->sym->name, &a->expr->where);
3884 : 0 : ok = false;
3885 : 0 : goto match;
3886 : : }
3887 : :
3888 : :
3889 : 251486 : if (a->expr->expr_type != EXPR_NULL
3890 : 251486 : && !compare_allocatable (f->sym, a->expr))
3891 : : {
3892 : 9 : if (where)
3893 : 9 : gfc_error ("Actual argument for %qs must be ALLOCATABLE at %L",
3894 : 9 : f->sym->name, &a->expr->where);
3895 : 9 : ok = false;
3896 : 9 : goto match;
3897 : : }
3898 : :
3899 : 251477 : if (a->expr->expr_type == EXPR_FUNCTION
3900 : 14886 : && a->expr->value.function.esym
3901 : 4941 : && f->sym->attr.allocatable)
3902 : : {
3903 : 4 : if (where)
3904 : 4 : gfc_error ("Actual argument for %qs at %L is a function result "
3905 : : "and the dummy argument is ALLOCATABLE",
3906 : : f->sym->name, &a->expr->where);
3907 : 4 : ok = false;
3908 : 4 : goto match;
3909 : : }
3910 : :
3911 : : /* Check intent = OUT/INOUT for definable actual argument. */
3912 : 251473 : if (!in_statement_function
3913 : 250998 : && (f->sym->attr.intent == INTENT_OUT
3914 : 244483 : || f->sym->attr.intent == INTENT_INOUT))
3915 : : {
3916 : 10259 : const char* context = (where
3917 : 10259 : ? _("actual argument to INTENT = OUT/INOUT")
3918 : : : NULL);
3919 : :
3920 : 2570 : if (((f->sym->ts.type == BT_CLASS && f->sym->attr.class_ok
3921 : 2570 : && CLASS_DATA (f->sym)->attr.class_pointer)
3922 : 10239 : || (f->sym->ts.type != BT_CLASS && f->sym->attr.pointer))
3923 : 10449 : && !gfc_check_vardef_context (a->expr, true, false, false, context))
3924 : : {
3925 : 6 : ok = false;
3926 : 6 : goto match;
3927 : : }
3928 : 10253 : if (!gfc_check_vardef_context (a->expr, false, false, false, context))
3929 : : {
3930 : 21 : ok = false;
3931 : 21 : goto match;
3932 : : }
3933 : : }
3934 : :
3935 : 251446 : if ((f->sym->attr.intent == INTENT_OUT
3936 : 244939 : || f->sym->attr.intent == INTENT_INOUT
3937 : 241212 : || f->sym->attr.volatile_
3938 : 241176 : || f->sym->attr.asynchronous)
3939 : 255237 : && gfc_has_vector_subscript (a->expr))
3940 : : {
3941 : 3 : if (where)
3942 : 3 : gfc_error ("Array-section actual argument with vector "
3943 : : "subscripts at %L is incompatible with INTENT(OUT), "
3944 : : "INTENT(INOUT), VOLATILE or ASYNCHRONOUS attribute "
3945 : : "of the dummy argument %qs",
3946 : 3 : &a->expr->where, f->sym->name);
3947 : 3 : ok = false;
3948 : 3 : goto match;
3949 : : }
3950 : :
3951 : : /* C1232 (R1221) For an actual argument which is an array section or
3952 : : an assumed-shape array, the dummy argument shall be an assumed-
3953 : : shape array, if the dummy argument has the VOLATILE attribute. */
3954 : :
3955 : 251443 : if (f->sym->attr.volatile_
3956 : 37 : && a->expr->expr_type == EXPR_VARIABLE
3957 : 34 : && a->expr->symtree->n.sym->as
3958 : 29 : && a->expr->symtree->n.sym->as->type == AS_ASSUMED_SHAPE
3959 : 2 : && !(fas && fas->type == AS_ASSUMED_SHAPE))
3960 : : {
3961 : 1 : if (where)
3962 : 1 : gfc_error ("Assumed-shape actual argument at %L is "
3963 : : "incompatible with the non-assumed-shape "
3964 : : "dummy argument %qs due to VOLATILE attribute",
3965 : : &a->expr->where,f->sym->name);
3966 : 1 : ok = false;
3967 : 1 : goto match;
3968 : : }
3969 : :
3970 : : /* Find the last array_ref. */
3971 : 251442 : actual_arr_ref = NULL;
3972 : 251442 : if (a->expr->ref)
3973 : 44326 : actual_arr_ref = gfc_find_array_ref (a->expr, true);
3974 : :
3975 : 251442 : if (f->sym->attr.volatile_
3976 : 36 : && actual_arr_ref && actual_arr_ref->type == AR_SECTION
3977 : 5 : && !(fas && fas->type == AS_ASSUMED_SHAPE))
3978 : : {
3979 : 1 : if (where)
3980 : 1 : gfc_error ("Array-section actual argument at %L is "
3981 : : "incompatible with the non-assumed-shape "
3982 : : "dummy argument %qs due to VOLATILE attribute",
3983 : 1 : &a->expr->where, f->sym->name);
3984 : 1 : ok = false;
3985 : 1 : goto match;
3986 : : }
3987 : :
3988 : : /* C1233 (R1221) For an actual argument which is a pointer array, the
3989 : : dummy argument shall be an assumed-shape or pointer array, if the
3990 : : dummy argument has the VOLATILE attribute. */
3991 : :
3992 : 251441 : if (f->sym->attr.volatile_
3993 : 35 : && a->expr->expr_type == EXPR_VARIABLE
3994 : 32 : && a->expr->symtree->n.sym->attr.pointer
3995 : 17 : && a->expr->symtree->n.sym->as
3996 : 17 : && !(fas
3997 : 17 : && (fas->type == AS_ASSUMED_SHAPE
3998 : 6 : || f->sym->attr.pointer)))
3999 : : {
4000 : 3 : if (where)
4001 : 2 : gfc_error ("Pointer-array actual argument at %L requires "
4002 : : "an assumed-shape or pointer-array dummy "
4003 : : "argument %qs due to VOLATILE attribute",
4004 : : &a->expr->where,f->sym->name);
4005 : 3 : ok = false;
4006 : 3 : goto match;
4007 : : }
4008 : :
4009 : 251438 : match:
4010 : 354536 : if (a == actual)
4011 : 171526 : na = i;
4012 : :
4013 : 354536 : new_arg[i++] = a;
4014 : : }
4015 : :
4016 : : /* Give up now if we saw any bad argument. */
4017 : 171710 : if (!ok)
4018 : : return false;
4019 : :
4020 : : /* Make sure missing actual arguments are optional. */
4021 : : i = 0;
4022 : 348191 : for (f = formal; f; f = f->next, i++)
4023 : : {
4024 : 240709 : if (new_arg[i] != NULL)
4025 : 235060 : continue;
4026 : 5649 : if (f->sym == NULL)
4027 : : {
4028 : 1 : if (where)
4029 : 1 : gfc_error ("Missing alternate return spec in subroutine call "
4030 : : "at %L", where);
4031 : 1 : return false;
4032 : : }
4033 : : /* For CLASS, the optional attribute might be set at either location. */
4034 : 5648 : if (((f->sym->ts.type != BT_CLASS || !CLASS_DATA (f->sym)->attr.optional)
4035 : 5648 : && !f->sym->attr.optional)
4036 : 5568 : || (in_statement_function
4037 : 1 : && (f->sym->attr.optional
4038 : 0 : || (f->sym->ts.type == BT_CLASS
4039 : 0 : && CLASS_DATA (f->sym)->attr.optional))))
4040 : : {
4041 : 81 : if (where)
4042 : 4 : gfc_error ("Missing actual argument for argument %qs at %L",
4043 : : f->sym->name, where);
4044 : 81 : return false;
4045 : : }
4046 : : }
4047 : :
4048 : : /* We should have handled the cases where the formal arglist is null
4049 : : already. */
4050 : 107482 : gcc_assert (n > 0);
4051 : :
4052 : : /* The argument lists are compatible. We now relink a new actual
4053 : : argument list with null arguments in the right places. The head
4054 : : of the list remains the head. */
4055 : 348042 : for (f = formal, i = 0; f; f = f->next, i++)
4056 : 240560 : if (new_arg[i] == NULL)
4057 : : {
4058 : 5567 : new_arg[i] = gfc_get_actual_arglist ();
4059 : 5567 : new_arg[i]->associated_dummy = get_nonintrinsic_dummy_arg (f);
4060 : : }
4061 : :
4062 : 107482 : if (na != 0)
4063 : : {
4064 : 385 : std::swap (*new_arg[0], *actual);
4065 : 385 : std::swap (new_arg[0], new_arg[na]);
4066 : : }
4067 : :
4068 : 240560 : for (i = 0; i < n - 1; i++)
4069 : 133078 : new_arg[i]->next = new_arg[i + 1];
4070 : :
4071 : 107482 : new_arg[i]->next = NULL;
4072 : :
4073 : 107482 : if (*ap == NULL && n > 0)
4074 : 789 : *ap = new_arg[0];
4075 : :
4076 : : return true;
4077 : : }
4078 : :
4079 : :
4080 : : typedef struct
4081 : : {
4082 : : gfc_formal_arglist *f;
4083 : : gfc_actual_arglist *a;
4084 : : }
4085 : : argpair;
4086 : :
4087 : : /* qsort comparison function for argument pairs, with the following
4088 : : order:
4089 : : - p->a->expr == NULL
4090 : : - p->a->expr->expr_type != EXPR_VARIABLE
4091 : : - by gfc_symbol pointer value (larger first). */
4092 : :
4093 : : static int
4094 : 2105 : pair_cmp (const void *p1, const void *p2)
4095 : : {
4096 : 2105 : const gfc_actual_arglist *a1, *a2;
4097 : :
4098 : : /* *p1 and *p2 are elements of the to-be-sorted array. */
4099 : 2105 : a1 = ((const argpair *) p1)->a;
4100 : 2105 : a2 = ((const argpair *) p2)->a;
4101 : 2105 : if (!a1->expr)
4102 : : {
4103 : 23 : if (!a2->expr)
4104 : : return 0;
4105 : 23 : return -1;
4106 : : }
4107 : 2082 : if (!a2->expr)
4108 : : return 1;
4109 : 2073 : if (a1->expr->expr_type != EXPR_VARIABLE)
4110 : : {
4111 : 1466 : if (a2->expr->expr_type != EXPR_VARIABLE)
4112 : : return 0;
4113 : 990 : return -1;
4114 : : }
4115 : 607 : if (a2->expr->expr_type != EXPR_VARIABLE)
4116 : : return 1;
4117 : 195 : if (a1->expr->symtree->n.sym > a2->expr->symtree->n.sym)
4118 : : return -1;
4119 : 72 : return a1->expr->symtree->n.sym < a2->expr->symtree->n.sym;
4120 : : }
4121 : :
4122 : :
4123 : : /* Given two expressions from some actual arguments, test whether they
4124 : : refer to the same expression. The analysis is conservative.
4125 : : Returning false will produce no warning. */
4126 : :
4127 : : static bool
4128 : 43 : compare_actual_expr (gfc_expr *e1, gfc_expr *e2)
4129 : : {
4130 : 43 : const gfc_ref *r1, *r2;
4131 : :
4132 : 43 : if (!e1 || !e2
4133 : 43 : || e1->expr_type != EXPR_VARIABLE
4134 : 43 : || e2->expr_type != EXPR_VARIABLE
4135 : 43 : || e1->symtree->n.sym != e2->symtree->n.sym)
4136 : : return false;
4137 : :
4138 : : /* TODO: improve comparison, see expr.cc:show_ref(). */
4139 : 4 : for (r1 = e1->ref, r2 = e2->ref; r1 && r2; r1 = r1->next, r2 = r2->next)
4140 : : {
4141 : 1 : if (r1->type != r2->type)
4142 : : return false;
4143 : 1 : switch (r1->type)
4144 : : {
4145 : 0 : case REF_ARRAY:
4146 : 0 : if (r1->u.ar.type != r2->u.ar.type)
4147 : : return false;
4148 : : /* TODO: At the moment, consider only full arrays;
4149 : : we could do better. */
4150 : 0 : if (r1->u.ar.type != AR_FULL || r2->u.ar.type != AR_FULL)
4151 : : return false;
4152 : : break;
4153 : :
4154 : 0 : case REF_COMPONENT:
4155 : 0 : if (r1->u.c.component != r2->u.c.component)
4156 : : return false;
4157 : : break;
4158 : :
4159 : : case REF_SUBSTRING:
4160 : : return false;
4161 : :
4162 : 1 : case REF_INQUIRY:
4163 : 1 : if (e1->symtree->n.sym->ts.type == BT_COMPLEX
4164 : 1 : && e1->ts.type == BT_REAL && e2->ts.type == BT_REAL
4165 : 1 : && r1->u.i != r2->u.i)
4166 : : return false;
4167 : : break;
4168 : :
4169 : 0 : default:
4170 : 0 : gfc_internal_error ("compare_actual_expr(): Bad component code");
4171 : : }
4172 : : }
4173 : 3 : if (!r1 && !r2)
4174 : : return true;
4175 : : return false;
4176 : : }
4177 : :
4178 : :
4179 : : /* Given formal and actual argument lists that correspond to one
4180 : : another, check that identical actual arguments aren't not
4181 : : associated with some incompatible INTENTs. */
4182 : :
4183 : : static bool
4184 : 686 : check_some_aliasing (gfc_formal_arglist *f, gfc_actual_arglist *a)
4185 : : {
4186 : 686 : sym_intent f1_intent, f2_intent;
4187 : 686 : gfc_formal_arglist *f1;
4188 : 686 : gfc_actual_arglist *a1;
4189 : 686 : size_t n, i, j;
4190 : 686 : argpair *p;
4191 : 686 : bool t = true;
4192 : :
4193 : 686 : n = 0;
4194 : 686 : for (f1 = f, a1 = a;; f1 = f1->next, a1 = a1->next)
4195 : : {
4196 : 1808 : if (f1 == NULL && a1 == NULL)
4197 : : break;
4198 : 1122 : if (f1 == NULL || a1 == NULL)
4199 : 0 : gfc_internal_error ("check_some_aliasing(): List mismatch");
4200 : 1122 : n++;
4201 : : }
4202 : 686 : if (n == 0)
4203 : : return t;
4204 : 628 : p = XALLOCAVEC (argpair, n);
4205 : :
4206 : 1750 : for (i = 0, f1 = f, a1 = a; i < n; i++, f1 = f1->next, a1 = a1->next)
4207 : : {
4208 : 1122 : p[i].f = f1;
4209 : 1122 : p[i].a = a1;
4210 : : }
4211 : :
4212 : 628 : qsort (p, n, sizeof (argpair), pair_cmp);
4213 : :
4214 : 2378 : for (i = 0; i < n; i++)
4215 : : {
4216 : 1122 : if (!p[i].a->expr
4217 : 1117 : || p[i].a->expr->expr_type != EXPR_VARIABLE
4218 : 543 : || p[i].a->expr->ts.type == BT_PROCEDURE)
4219 : 580 : continue;
4220 : 542 : f1_intent = p[i].f->sym->attr.intent;
4221 : 545 : for (j = i + 1; j < n; j++)
4222 : : {
4223 : : /* Expected order after the sort. */
4224 : 43 : if (!p[j].a->expr || p[j].a->expr->expr_type != EXPR_VARIABLE)
4225 : 0 : gfc_internal_error ("check_some_aliasing(): corrupted data");
4226 : :
4227 : : /* Are the expression the same? */
4228 : 43 : if (!compare_actual_expr (p[i].a->expr, p[j].a->expr))
4229 : : break;
4230 : 3 : f2_intent = p[j].f->sym->attr.intent;
4231 : 3 : if ((f1_intent == INTENT_IN && f2_intent == INTENT_OUT)
4232 : 2 : || (f1_intent == INTENT_OUT && f2_intent == INTENT_IN)
4233 : 1 : || (f1_intent == INTENT_OUT && f2_intent == INTENT_OUT))
4234 : : {
4235 : 3 : gfc_warning (0, "Same actual argument associated with INTENT(%s) "
4236 : : "argument %qs and INTENT(%s) argument %qs at %L",
4237 : 3 : gfc_intent_string (f1_intent), p[i].f->sym->name,
4238 : : gfc_intent_string (f2_intent), p[j].f->sym->name,
4239 : : &p[i].a->expr->where);
4240 : 3 : t = false;
4241 : : }
4242 : : }
4243 : : }
4244 : :
4245 : : return t;
4246 : : }
4247 : :
4248 : :
4249 : : /* Given formal and actual argument lists that correspond to one
4250 : : another, check that they are compatible in the sense that intents
4251 : : are not mismatched. */
4252 : :
4253 : : static bool
4254 : 110046 : check_intents (gfc_formal_arglist *f, gfc_actual_arglist *a)
4255 : : {
4256 : 322995 : sym_intent f_intent;
4257 : :
4258 : 535944 : for (;; f = f->next, a = a->next)
4259 : : {
4260 : 322995 : gfc_expr *expr;
4261 : :
4262 : 322995 : if (f == NULL && a == NULL)
4263 : : break;
4264 : 212953 : if (f == NULL || a == NULL)
4265 : 0 : gfc_internal_error ("check_intents(): List mismatch");
4266 : :
4267 : 212953 : if (a->expr && a->expr->expr_type == EXPR_FUNCTION
4268 : 12439 : && a->expr->value.function.isym
4269 : 7471 : && a->expr->value.function.isym->id == GFC_ISYM_CAF_GET)
4270 : 0 : expr = a->expr->value.function.actual->expr;
4271 : : else
4272 : : expr = a->expr;
4273 : :
4274 : 212953 : if (expr == NULL || expr->expr_type != EXPR_VARIABLE)
4275 : 124178 : continue;
4276 : :
4277 : 88775 : f_intent = f->sym->attr.intent;
4278 : :
4279 : 88775 : if (gfc_pure (NULL) && gfc_impure_variable (expr->symtree->n.sym))
4280 : : {
4281 : 404 : if ((f->sym->ts.type == BT_CLASS && f->sym->attr.class_ok
4282 : 10 : && CLASS_DATA (f->sym)->attr.class_pointer)
4283 : 403 : || (f->sym->ts.type != BT_CLASS && f->sym->attr.pointer))
4284 : : {
4285 : 2 : gfc_error ("Procedure argument at %L is local to a PURE "
4286 : : "procedure and has the POINTER attribute",
4287 : : &expr->where);
4288 : 2 : return false;
4289 : : }
4290 : : }
4291 : :
4292 : : /* Fortran 2008, C1283. */
4293 : 88773 : if (gfc_pure (NULL) && gfc_is_coindexed (expr))
4294 : : {
4295 : 1 : if (f_intent == INTENT_INOUT || f_intent == INTENT_OUT)
4296 : : {
4297 : 1 : gfc_error ("Coindexed actual argument at %L in PURE procedure "
4298 : : "is passed to an INTENT(%s) argument",
4299 : : &expr->where, gfc_intent_string (f_intent));
4300 : 1 : return false;
4301 : : }
4302 : :
4303 : 0 : if ((f->sym->ts.type == BT_CLASS && f->sym->attr.class_ok
4304 : 0 : && CLASS_DATA (f->sym)->attr.class_pointer)
4305 : 0 : || (f->sym->ts.type != BT_CLASS && f->sym->attr.pointer))
4306 : : {
4307 : 0 : gfc_error ("Coindexed actual argument at %L in PURE procedure "
4308 : : "is passed to a POINTER dummy argument",
4309 : : &expr->where);
4310 : 0 : return false;
4311 : : }
4312 : : }
4313 : :
4314 : : /* F2008, Section 12.5.2.4. */
4315 : 6322 : if (expr->ts.type == BT_CLASS && f->sym->ts.type == BT_CLASS
4316 : 94394 : && gfc_is_coindexed (expr))
4317 : : {
4318 : 1 : gfc_error ("Coindexed polymorphic actual argument at %L is passed "
4319 : : "polymorphic dummy argument %qs",
4320 : 1 : &expr->where, f->sym->name);
4321 : 1 : return false;
4322 : : }
4323 : 212949 : }
4324 : :
4325 : : return true;
4326 : : }
4327 : :
4328 : :
4329 : : /* Check how a procedure is used against its interface. If all goes
4330 : : well, the actual argument list will also end up being properly
4331 : : sorted. */
4332 : :
4333 : : bool
4334 : 101624 : gfc_procedure_use (gfc_symbol *sym, gfc_actual_arglist **ap, locus *where)
4335 : : {
4336 : 101624 : gfc_actual_arglist *a;
4337 : 101624 : gfc_formal_arglist *dummy_args;
4338 : 101624 : bool implicit = false;
4339 : :
4340 : : /* Warn about calls with an implicit interface. Special case
4341 : : for calling a ISO_C_BINDING because c_loc and c_funloc
4342 : : are pseudo-unknown. Additionally, warn about procedures not
4343 : : explicitly declared at all if requested. */
4344 : 101624 : if (sym->attr.if_source == IFSRC_UNKNOWN && !sym->attr.is_iso_c)
4345 : : {
4346 : 16312 : bool has_implicit_none_export = false;
4347 : 16312 : implicit = true;
4348 : 16312 : if (sym->attr.proc == PROC_UNKNOWN)
4349 : 23067 : for (gfc_namespace *ns = sym->ns; ns; ns = ns->parent)
4350 : 11624 : if (ns->has_implicit_none_export)
4351 : : {
4352 : : has_implicit_none_export = true;
4353 : : break;
4354 : : }
4355 : 11447 : if (has_implicit_none_export)
4356 : : {
4357 : 4 : const char *guessed
4358 : 4 : = gfc_lookup_function_fuzzy (sym->name, sym->ns->sym_root);
4359 : 4 : if (guessed)
4360 : 1 : gfc_error ("Procedure %qs called at %L is not explicitly declared"
4361 : : "; did you mean %qs?",
4362 : : sym->name, where, guessed);
4363 : : else
4364 : 3 : gfc_error ("Procedure %qs called at %L is not explicitly declared",
4365 : : sym->name, where);
4366 : 4 : return false;
4367 : : }
4368 : 16308 : if (warn_implicit_interface)
4369 : 0 : gfc_warning (OPT_Wimplicit_interface,
4370 : : "Procedure %qs called with an implicit interface at %L",
4371 : : sym->name, where);
4372 : 16308 : else if (warn_implicit_procedure && sym->attr.proc == PROC_UNKNOWN)
4373 : 1 : gfc_warning (OPT_Wimplicit_procedure,
4374 : : "Procedure %qs called at %L is not explicitly declared",
4375 : : sym->name, where);
4376 : 16308 : gfc_find_proc_namespace (sym->ns)->implicit_interface_calls = 1;
4377 : : }
4378 : :
4379 : 101620 : if (sym->attr.if_source == IFSRC_UNKNOWN)
4380 : : {
4381 : 16308 : if (sym->attr.pointer)
4382 : : {
4383 : 1 : gfc_error ("The pointer object %qs at %L must have an explicit "
4384 : : "function interface or be declared as array",
4385 : : sym->name, where);
4386 : 1 : return false;
4387 : : }
4388 : :
4389 : 16307 : if (sym->attr.allocatable && !sym->attr.external)
4390 : : {
4391 : 1 : gfc_error ("The allocatable object %qs at %L must have an explicit "
4392 : : "function interface or be declared as array",
4393 : : sym->name, where);
4394 : 1 : return false;
4395 : : }
4396 : :
4397 : 16306 : if (sym->attr.allocatable)
4398 : : {
4399 : 1 : gfc_error ("Allocatable function %qs at %L must have an explicit "
4400 : : "function interface", sym->name, where);
4401 : 1 : return false;
4402 : : }
4403 : :
4404 : 46720 : for (a = *ap; a; a = a->next)
4405 : : {
4406 : 30430 : if (a->expr && a->expr->error)
4407 : : return false;
4408 : :
4409 : : /* F2018, 15.4.2.2 Explicit interface is required for a
4410 : : polymorphic dummy argument, so there is no way to
4411 : : legally have a class appear in an argument with an
4412 : : implicit interface. */
4413 : :
4414 : 30430 : if (implicit && a->expr && a->expr->ts.type == BT_CLASS)
4415 : : {
4416 : 3 : gfc_error ("Explicit interface required for polymorphic "
4417 : : "argument at %L",&a->expr->where);
4418 : 3 : a->expr->error = 1;
4419 : 3 : break;
4420 : : }
4421 : :
4422 : : /* Skip g77 keyword extensions like %VAL, %REF, %LOC. */
4423 : 30427 : if (a->name != NULL && a->name[0] != '%')
4424 : : {
4425 : 2 : gfc_error ("Keyword argument requires explicit interface "
4426 : : "for procedure %qs at %L", sym->name, &a->expr->where);
4427 : 2 : break;
4428 : : }
4429 : :
4430 : : /* TS 29113, 6.2. */
4431 : 30425 : if (a->expr && a->expr->ts.type == BT_ASSUMED
4432 : 3 : && sym->intmod_sym_id != ISOCBINDING_LOC)
4433 : : {
4434 : 3 : gfc_error ("Assumed-type argument %s at %L requires an explicit "
4435 : 3 : "interface", a->expr->symtree->n.sym->name,
4436 : : &a->expr->where);
4437 : 3 : a->expr->error = 1;
4438 : 3 : break;
4439 : : }
4440 : :
4441 : : /* F2008, C1303 and C1304. */
4442 : 30422 : if (a->expr
4443 : 30247 : && (a->expr->ts.type == BT_DERIVED || a->expr->ts.type == BT_CLASS)
4444 : 67 : && a->expr->ts.u.derived
4445 : 30487 : && ((a->expr->ts.u.derived->from_intmod == INTMOD_ISO_FORTRAN_ENV
4446 : 1 : && a->expr->ts.u.derived->intmod_sym_id == ISOFORTRAN_LOCK_TYPE)
4447 : 64 : || gfc_expr_attr (a->expr).lock_comp))
4448 : : {
4449 : 1 : gfc_error ("Actual argument of LOCK_TYPE or with LOCK_TYPE "
4450 : : "component at %L requires an explicit interface for "
4451 : 1 : "procedure %qs", &a->expr->where, sym->name);
4452 : 1 : a->expr->error = 1;
4453 : 1 : break;
4454 : : }
4455 : :
4456 : 30421 : if (a->expr
4457 : 30246 : && (a->expr->ts.type == BT_DERIVED || a->expr->ts.type == BT_CLASS)
4458 : 66 : && a->expr->ts.u.derived
4459 : 30485 : && ((a->expr->ts.u.derived->from_intmod == INTMOD_ISO_FORTRAN_ENV
4460 : 0 : && a->expr->ts.u.derived->intmod_sym_id
4461 : : == ISOFORTRAN_EVENT_TYPE)
4462 : 64 : || gfc_expr_attr (a->expr).event_comp))
4463 : : {
4464 : 0 : gfc_error ("Actual argument of EVENT_TYPE or with EVENT_TYPE "
4465 : : "component at %L requires an explicit interface for "
4466 : 0 : "procedure %qs", &a->expr->where, sym->name);
4467 : 0 : a->expr->error = 1;
4468 : 0 : break;
4469 : : }
4470 : :
4471 : 30421 : if (a->expr && a->expr->expr_type == EXPR_NULL
4472 : 2 : && a->expr->ts.type == BT_UNKNOWN)
4473 : : {
4474 : 1 : gfc_error ("MOLD argument to NULL required at %L",
4475 : : &a->expr->where);
4476 : 1 : a->expr->error = 1;
4477 : 1 : return false;
4478 : : }
4479 : :
4480 : 30420 : if (a->expr && a->expr->expr_type == EXPR_NULL)
4481 : : {
4482 : 1 : gfc_error ("Passing intrinsic NULL as actual argument at %L "
4483 : : "requires an explicit interface", &a->expr->where);
4484 : 1 : a->expr->error = 1;
4485 : 1 : return false;
4486 : : }
4487 : :
4488 : : /* TS 29113, C407b. */
4489 : 30244 : if (a->expr && a->expr->expr_type == EXPR_VARIABLE
4490 : 43690 : && symbol_rank (a->expr->symtree->n.sym) == -1)
4491 : : {
4492 : 4 : gfc_error ("Assumed-rank argument requires an explicit interface "
4493 : : "at %L", &a->expr->where);
4494 : 4 : a->expr->error = 1;
4495 : 4 : return false;
4496 : : }
4497 : : }
4498 : :
4499 : 16299 : return true;
4500 : : }
4501 : :
4502 : 85312 : dummy_args = gfc_sym_get_dummy_args (sym);
4503 : :
4504 : : /* For a statement function, check that types and type parameters of actual
4505 : : arguments and dummy arguments match. */
4506 : 85312 : if (!gfc_compare_actual_formal (ap, dummy_args, 0, sym->attr.elemental,
4507 : 85312 : sym->attr.proc == PROC_ST_FUNCTION, where))
4508 : : return false;
4509 : :
4510 : 84902 : if (!check_intents (dummy_args, *ap))
4511 : : return false;
4512 : :
4513 : 84898 : if (warn_aliasing)
4514 : 674 : check_some_aliasing (dummy_args, *ap);
4515 : :
4516 : : return true;
4517 : : }
4518 : :
4519 : :
4520 : : /* Check how a procedure pointer component is used against its interface.
4521 : : If all goes well, the actual argument list will also end up being properly
4522 : : sorted. Completely analogous to gfc_procedure_use. */
4523 : :
4524 : : void
4525 : 394 : gfc_ppc_use (gfc_component *comp, gfc_actual_arglist **ap, locus *where)
4526 : : {
4527 : : /* Warn about calls with an implicit interface. Special case
4528 : : for calling a ISO_C_BINDING because c_loc and c_funloc
4529 : : are pseudo-unknown. */
4530 : 394 : if (warn_implicit_interface
4531 : 0 : && comp->attr.if_source == IFSRC_UNKNOWN
4532 : 0 : && !comp->attr.is_iso_c)
4533 : 0 : gfc_warning (OPT_Wimplicit_interface,
4534 : : "Procedure pointer component %qs called with an implicit "
4535 : : "interface at %L", comp->name, where);
4536 : :
4537 : 394 : if (comp->attr.if_source == IFSRC_UNKNOWN)
4538 : : {
4539 : 47 : gfc_actual_arglist *a;
4540 : 74 : for (a = *ap; a; a = a->next)
4541 : : {
4542 : : /* Skip g77 keyword extensions like %VAL, %REF, %LOC. */
4543 : 27 : if (a->name != NULL && a->name[0] != '%')
4544 : : {
4545 : 0 : gfc_error ("Keyword argument requires explicit interface "
4546 : : "for procedure pointer component %qs at %L",
4547 : 0 : comp->name, &a->expr->where);
4548 : 0 : break;
4549 : : }
4550 : : }
4551 : :
4552 : 47 : return;
4553 : : }
4554 : :
4555 : 347 : if (!gfc_compare_actual_formal (ap, comp->ts.interface->formal, 0,
4556 : 347 : comp->attr.elemental, false, where))
4557 : : return;
4558 : :
4559 : 347 : check_intents (comp->ts.interface->formal, *ap);
4560 : 347 : if (warn_aliasing)
4561 : 0 : check_some_aliasing (comp->ts.interface->formal, *ap);
4562 : : }
4563 : :
4564 : :
4565 : : /* Try if an actual argument list matches the formal list of a symbol,
4566 : : respecting the symbol's attributes like ELEMENTAL. This is used for
4567 : : GENERIC resolution. */
4568 : :
4569 : : bool
4570 : 89692 : gfc_arglist_matches_symbol (gfc_actual_arglist** args, gfc_symbol* sym)
4571 : : {
4572 : 89692 : gfc_formal_arglist *dummy_args;
4573 : 89692 : bool r;
4574 : :
4575 : 89692 : if (sym->attr.flavor != FL_PROCEDURE)
4576 : : return false;
4577 : :
4578 : 89690 : dummy_args = gfc_sym_get_dummy_args (sym);
4579 : :
4580 : 89690 : r = !sym->attr.elemental;
4581 : 89690 : if (gfc_compare_actual_formal (args, dummy_args, r, !r, false, NULL))
4582 : : {
4583 : 24797 : check_intents (dummy_args, *args);
4584 : 24797 : if (warn_aliasing)
4585 : 12 : check_some_aliasing (dummy_args, *args);
4586 : 24797 : return true;
4587 : : }
4588 : :
4589 : : return false;
4590 : : }
4591 : :
4592 : :
4593 : : /* Given an interface pointer and an actual argument list, search for
4594 : : a formal argument list that matches the actual. If found, returns
4595 : : a pointer to the symbol of the correct interface. Returns NULL if
4596 : : not found. */
4597 : :
4598 : : gfc_symbol *
4599 : 42557 : gfc_search_interface (gfc_interface *intr, int sub_flag,
4600 : : gfc_actual_arglist **ap)
4601 : : {
4602 : 42557 : gfc_symbol *elem_sym = NULL;
4603 : 42557 : gfc_symbol *null_sym = NULL;
4604 : 42557 : locus null_expr_loc;
4605 : 42557 : gfc_actual_arglist *a;
4606 : 42557 : bool has_null_arg = false;
4607 : :
4608 : 118332 : for (a = *ap; a; a = a->next)
4609 : 75904 : if (a->expr && a->expr->expr_type == EXPR_NULL
4610 : 175 : && a->expr->ts.type == BT_UNKNOWN)
4611 : : {
4612 : 129 : has_null_arg = true;
4613 : 129 : null_expr_loc = a->expr->where;
4614 : 129 : break;
4615 : : }
4616 : :
4617 : 126270 : for (; intr; intr = intr->next)
4618 : : {
4619 : 93777 : if (gfc_fl_struct (intr->sym->attr.flavor))
4620 : 5961 : continue;
4621 : 87816 : if (sub_flag && intr->sym->attr.function)
4622 : 0 : continue;
4623 : 83328 : if (!sub_flag && intr->sym->attr.subroutine)
4624 : 0 : continue;
4625 : :
4626 : 87816 : if (gfc_arglist_matches_symbol (ap, intr->sym))
4627 : : {
4628 : 23679 : if (has_null_arg && null_sym)
4629 : : {
4630 : 2 : gfc_error ("MOLD= required in NULL() argument at %L: Ambiguity "
4631 : : "between specific functions %s and %s",
4632 : 2 : &null_expr_loc, null_sym->name, intr->sym->name);
4633 : 2 : return NULL;
4634 : : }
4635 : 23677 : else if (has_null_arg)
4636 : : {
4637 : 4 : null_sym = intr->sym;
4638 : 4 : continue;
4639 : : }
4640 : :
4641 : : /* Satisfy 12.4.4.1 such that an elemental match has lower
4642 : : weight than a non-elemental match. */
4643 : 23673 : if (intr->sym->attr.elemental)
4644 : : {
4645 : 13611 : elem_sym = intr->sym;
4646 : 13611 : continue;
4647 : : }
4648 : : return intr->sym;
4649 : : }
4650 : : }
4651 : :
4652 : 32493 : if (null_sym)
4653 : 2 : return null_sym;
4654 : :
4655 : : return elem_sym ? elem_sym : NULL;
4656 : : }
4657 : :
4658 : :
4659 : : /* Do a brute force recursive search for a symbol. */
4660 : :
4661 : : static gfc_symtree *
4662 : 70351 : find_symtree0 (gfc_symtree *root, gfc_symbol *sym)
4663 : : {
4664 : 137313 : gfc_symtree * st;
4665 : :
4666 : 137313 : if (root->n.sym == sym)
4667 : : return root;
4668 : :
4669 : 136325 : st = NULL;
4670 : 136325 : if (root->left)
4671 : 69311 : st = find_symtree0 (root->left, sym);
4672 : 136325 : if (root->right && ! st)
4673 : : st = find_symtree0 (root->right, sym);
4674 : : return st;
4675 : : }
4676 : :
4677 : :
4678 : : /* Find a symtree for a symbol. */
4679 : :
4680 : : gfc_symtree *
4681 : 4270 : gfc_find_sym_in_symtree (gfc_symbol *sym)
4682 : : {
4683 : 4270 : gfc_symtree *st;
4684 : 4270 : gfc_namespace *ns;
4685 : :
4686 : : /* First try to find it by name. */
4687 : 4270 : gfc_find_sym_tree (sym->name, gfc_current_ns, 1, &st);
4688 : 4270 : if (st && st->n.sym == sym)
4689 : : return st;
4690 : :
4691 : : /* If it's been renamed, resort to a brute-force search. */
4692 : : /* TODO: avoid having to do this search. If the symbol doesn't exist
4693 : : in the symtree for the current namespace, it should probably be added. */
4694 : 1040 : for (ns = gfc_current_ns; ns; ns = ns->parent)
4695 : : {
4696 : 1040 : st = find_symtree0 (ns->sym_root, sym);
4697 : 1040 : if (st)
4698 : : return st;
4699 : : }
4700 : 0 : gfc_internal_error ("Unable to find symbol %qs", sym->name);
4701 : : /* Not reached. */
4702 : : }
4703 : :
4704 : :
4705 : : /* See if the arglist to an operator-call contains a derived-type argument
4706 : : with a matching type-bound operator. If so, return the matching specific
4707 : : procedure defined as operator-target as well as the base-object to use
4708 : : (which is the found derived-type argument with operator). The generic
4709 : : name, if any, is transmitted to the final expression via 'gname'. */
4710 : :
4711 : : static gfc_typebound_proc*
4712 : 12488 : matching_typebound_op (gfc_expr** tb_base,
4713 : : gfc_actual_arglist* args,
4714 : : gfc_intrinsic_op op, const char* uop,
4715 : : const char ** gname)
4716 : : {
4717 : 12488 : gfc_actual_arglist* base;
4718 : :
4719 : 35886 : for (base = args; base; base = base->next)
4720 : 24145 : if (base->expr->ts.type == BT_DERIVED || base->expr->ts.type == BT_CLASS)
4721 : : {
4722 : : gfc_typebound_proc* tb;
4723 : : gfc_symbol* derived;
4724 : : bool result;
4725 : :
4726 : 20350 : while (base->expr->expr_type == EXPR_OP
4727 : 20350 : && base->expr->value.op.op == INTRINSIC_PARENTHESES)
4728 : 84 : base->expr = base->expr->value.op.op1;
4729 : :
4730 : 20266 : if (base->expr->ts.type == BT_CLASS)
4731 : : {
4732 : 1738 : if (!base->expr->ts.u.derived || CLASS_DATA (base->expr) == NULL
4733 : 3473 : || !gfc_expr_attr (base->expr).class_ok)
4734 : 87 : continue;
4735 : 1652 : derived = CLASS_DATA (base->expr)->ts.u.derived;
4736 : : }
4737 : : else
4738 : 18527 : derived = base->expr->ts.u.derived;
4739 : :
4740 : 20179 : if (op == INTRINSIC_USER)
4741 : : {
4742 : 178 : gfc_symtree* tb_uop;
4743 : :
4744 : 178 : gcc_assert (uop);
4745 : 178 : tb_uop = gfc_find_typebound_user_op (derived, &result, uop,
4746 : : false, NULL);
4747 : :
4748 : 178 : if (tb_uop)
4749 : 40 : tb = tb_uop->n.tb;
4750 : : else
4751 : : tb = NULL;
4752 : : }
4753 : : else
4754 : 20001 : tb = gfc_find_typebound_intrinsic_op (derived, &result, op,
4755 : : false, NULL);
4756 : :
4757 : : /* This means we hit a PRIVATE operator which is use-associated and
4758 : : should thus not be seen. */
4759 : 20179 : if (!result)
4760 : 19282 : tb = NULL;
4761 : :
4762 : : /* Look through the super-type hierarchy for a matching specific
4763 : : binding. */
4764 : 20329 : for (; tb; tb = tb->overridden)
4765 : : {
4766 : 897 : gfc_tbp_generic* g;
4767 : :
4768 : 897 : gcc_assert (tb->is_generic);
4769 : 1467 : for (g = tb->u.generic; g; g = g->next)
4770 : : {
4771 : 1317 : gfc_symbol* target;
4772 : 1317 : gfc_actual_arglist* argcopy;
4773 : 1317 : bool matches;
4774 : :
4775 : 1317 : gcc_assert (g->specific);
4776 : 1317 : if (g->specific->error)
4777 : 0 : continue;
4778 : :
4779 : 1317 : target = g->specific->u.specific->n.sym;
4780 : :
4781 : : /* Check if this arglist matches the formal. */
4782 : 1317 : argcopy = gfc_copy_actual_arglist (args);
4783 : 1317 : matches = gfc_arglist_matches_symbol (&argcopy, target);
4784 : 1317 : gfc_free_actual_arglist (argcopy);
4785 : :
4786 : : /* Return if we found a match. */
4787 : 1317 : if (matches)
4788 : : {
4789 : 747 : *tb_base = base->expr;
4790 : 747 : *gname = g->specific_st->name;
4791 : 747 : return g->specific;
4792 : : }
4793 : : }
4794 : : }
4795 : : }
4796 : :
4797 : : return NULL;
4798 : : }
4799 : :
4800 : :
4801 : : /* For the 'actual arglist' of an operator call and a specific typebound
4802 : : procedure that has been found the target of a type-bound operator, build the
4803 : : appropriate EXPR_COMPCALL and resolve it. We take this indirection over
4804 : : type-bound procedures rather than resolving type-bound operators 'directly'
4805 : : so that we can reuse the existing logic. */
4806 : :
4807 : : static void
4808 : 747 : build_compcall_for_operator (gfc_expr* e, gfc_actual_arglist* actual,
4809 : : gfc_expr* base, gfc_typebound_proc* target,
4810 : : const char *gname)
4811 : : {
4812 : 747 : e->expr_type = EXPR_COMPCALL;
4813 : 747 : e->value.compcall.tbp = target;
4814 : 747 : e->value.compcall.name = gname ? gname : "$op";
4815 : 747 : e->value.compcall.actual = actual;
4816 : 747 : e->value.compcall.base_object = base;
4817 : 747 : e->value.compcall.ignore_pass = 1;
4818 : 747 : e->value.compcall.assign = 0;
4819 : 747 : if (e->ts.type == BT_UNKNOWN
4820 : 747 : && target->function)
4821 : : {
4822 : 331 : if (target->is_generic)
4823 : 0 : e->ts = target->u.generic->specific->u.specific->n.sym->ts;
4824 : : else
4825 : 331 : e->ts = target->u.specific->n.sym->ts;
4826 : : }
4827 : 747 : }
4828 : :
4829 : :
4830 : : /* This subroutine is called when an expression is being resolved.
4831 : : The expression node in question is either a user defined operator
4832 : : or an intrinsic operator with arguments that aren't compatible
4833 : : with the operator. This subroutine builds an actual argument list
4834 : : corresponding to the operands, then searches for a compatible
4835 : : interface. If one is found, the expression node is replaced with
4836 : : the appropriate function call. We use the 'match' enum to specify
4837 : : whether a replacement has been made or not, or if an error occurred. */
4838 : :
4839 : : match
4840 : 2069 : gfc_extend_expr (gfc_expr *e)
4841 : : {
4842 : 2069 : gfc_actual_arglist *actual;
4843 : 2069 : gfc_symbol *sym;
4844 : 2069 : gfc_namespace *ns;
4845 : 2069 : gfc_user_op *uop;
4846 : 2069 : gfc_intrinsic_op i;
4847 : 2069 : const char *gname;
4848 : 2069 : gfc_typebound_proc* tbo;
4849 : 2069 : gfc_expr* tb_base;
4850 : :
4851 : 2069 : sym = NULL;
4852 : :
4853 : 2069 : actual = gfc_get_actual_arglist ();
4854 : 2069 : actual->expr = e->value.op.op1;
4855 : :
4856 : 2069 : gname = NULL;
4857 : :
4858 : 2069 : if (e->value.op.op2 != NULL)
4859 : : {
4860 : 1907 : actual->next = gfc_get_actual_arglist ();
4861 : 1907 : actual->next->expr = e->value.op.op2;
4862 : : }
4863 : :
4864 : 2069 : i = fold_unary_intrinsic (e->value.op.op);
4865 : :
4866 : : /* See if we find a matching type-bound operator. */
4867 : 2055 : if (i == INTRINSIC_USER)
4868 : 232 : tbo = matching_typebound_op (&tb_base, actual,
4869 : 232 : i, e->value.op.uop->name, &gname);
4870 : : else
4871 : 1837 : switch (i)
4872 : : {
4873 : : #define CHECK_OS_COMPARISON(comp) \
4874 : : case INTRINSIC_##comp: \
4875 : : case INTRINSIC_##comp##_OS: \
4876 : : tbo = matching_typebound_op (&tb_base, actual, \
4877 : : INTRINSIC_##comp, NULL, &gname); \
4878 : : if (!tbo) \
4879 : : tbo = matching_typebound_op (&tb_base, actual, \
4880 : : INTRINSIC_##comp##_OS, NULL, &gname); \
4881 : : break;
4882 : 189 : CHECK_OS_COMPARISON(EQ)
4883 : 828 : CHECK_OS_COMPARISON(NE)
4884 : 41 : CHECK_OS_COMPARISON(GT)
4885 : 40 : CHECK_OS_COMPARISON(GE)
4886 : 78 : CHECK_OS_COMPARISON(LT)
4887 : 40 : CHECK_OS_COMPARISON(LE)
4888 : : #undef CHECK_OS_COMPARISON
4889 : :
4890 : 621 : default:
4891 : 621 : tbo = matching_typebound_op (&tb_base, actual, i, NULL, &gname);
4892 : 621 : break;
4893 : : }
4894 : :
4895 : : /* If there is a matching typebound-operator, replace the expression with
4896 : : a call to it and succeed. */
4897 : 2069 : if (tbo)
4898 : : {
4899 : 331 : gcc_assert (tb_base);
4900 : 331 : build_compcall_for_operator (e, actual, tb_base, tbo, gname);
4901 : :
4902 : 331 : if (!gfc_resolve_expr (e))
4903 : : return MATCH_ERROR;
4904 : : else
4905 : : return MATCH_YES;
4906 : : }
4907 : :
4908 : 1738 : if (i == INTRINSIC_USER)
4909 : : {
4910 : 202 : for (ns = gfc_current_ns; ns; ns = ns->parent)
4911 : : {
4912 : 193 : uop = gfc_find_uop (e->value.op.uop->name, ns);
4913 : 193 : if (uop == NULL)
4914 : 0 : continue;
4915 : :
4916 : 193 : sym = gfc_search_interface (uop->op, 0, &actual);
4917 : 193 : if (sym != NULL)
4918 : : break;
4919 : : }
4920 : : }
4921 : : else
4922 : : {
4923 : 1813 : for (ns = gfc_current_ns; ns; ns = ns->parent)
4924 : : {
4925 : : /* Due to the distinction between '==' and '.eq.' and friends, one has
4926 : : to check if either is defined. */
4927 : 1614 : switch (i)
4928 : : {
4929 : : #define CHECK_OS_COMPARISON(comp) \
4930 : : case INTRINSIC_##comp: \
4931 : : case INTRINSIC_##comp##_OS: \
4932 : : sym = gfc_search_interface (ns->op[INTRINSIC_##comp], 0, &actual); \
4933 : : if (!sym) \
4934 : : sym = gfc_search_interface (ns->op[INTRINSIC_##comp##_OS], 0, &actual); \
4935 : : break;
4936 : 196 : CHECK_OS_COMPARISON(EQ)
4937 : 872 : CHECK_OS_COMPARISON(NE)
4938 : 41 : CHECK_OS_COMPARISON(GT)
4939 : 40 : CHECK_OS_COMPARISON(GE)
4940 : 65 : CHECK_OS_COMPARISON(LT)
4941 : 40 : CHECK_OS_COMPARISON(LE)
4942 : : #undef CHECK_OS_COMPARISON
4943 : :
4944 : 360 : default:
4945 : 360 : sym = gfc_search_interface (ns->op[i], 0, &actual);
4946 : : }
4947 : :
4948 : 1380 : if (sym != NULL)
4949 : : break;
4950 : : }
4951 : :
4952 : : /* F2018(15.4.3.4.2) requires that the use of unlimited polymorphic
4953 : : formal arguments does not override the intrinsic uses. */
4954 : 1545 : gfc_push_suppress_errors ();
4955 : 1545 : if (sym
4956 : 1346 : && (UNLIMITED_POLY (sym->formal->sym)
4957 : 1336 : || (sym->formal->next
4958 : 1310 : && UNLIMITED_POLY (sym->formal->next->sym)))
4959 : 1555 : && !gfc_check_operator_interface (sym, e->value.op.op, e->where))
4960 : 0 : sym = NULL;
4961 : 1545 : gfc_pop_suppress_errors ();
4962 : : }
4963 : :
4964 : : /* TODO: Do an ambiguity-check and error if multiple matching interfaces are
4965 : : found rather than just taking the first one and not checking further. */
4966 : :
4967 : 1738 : if (sym == NULL)
4968 : : {
4969 : : /* Don't use gfc_free_actual_arglist(). */
4970 : 208 : free (actual->next);
4971 : 208 : free (actual);
4972 : 208 : return MATCH_NO;
4973 : : }
4974 : :
4975 : : /* Change the expression node to a function call. */
4976 : 1530 : e->expr_type = EXPR_FUNCTION;
4977 : 1530 : e->symtree = gfc_find_sym_in_symtree (sym);
4978 : 1530 : e->value.function.actual = actual;
4979 : 1530 : e->value.function.esym = NULL;
4980 : 1530 : e->value.function.isym = NULL;
4981 : 1530 : e->value.function.name = NULL;
4982 : 1530 : e->user_operator = 1;
4983 : :
4984 : 1530 : if (!gfc_resolve_expr (e))
4985 : : return MATCH_ERROR;
4986 : :
4987 : : return MATCH_YES;
4988 : : }
4989 : :
4990 : :
4991 : : /* Tries to replace an assignment code node with a subroutine call to the
4992 : : subroutine associated with the assignment operator. Return true if the node
4993 : : was replaced. On false, no error is generated. */
4994 : :
4995 : : bool
4996 : 278988 : gfc_extend_assign (gfc_code *c, gfc_namespace *ns)
4997 : : {
4998 : 278988 : gfc_actual_arglist *actual;
4999 : 278988 : gfc_expr *lhs, *rhs, *tb_base;
5000 : 278988 : gfc_symbol *sym = NULL;
5001 : 278988 : const char *gname = NULL;
5002 : 278988 : gfc_typebound_proc* tbo;
5003 : :
5004 : 278988 : lhs = c->expr1;
5005 : 278988 : rhs = c->expr2;
5006 : :
5007 : : /* Don't allow an intrinsic assignment with a BOZ rhs to be replaced. */
5008 : 278988 : if (c->op == EXEC_ASSIGN
5009 : 278988 : && c->expr1->expr_type == EXPR_VARIABLE
5010 : 278988 : && c->expr2->expr_type == EXPR_CONSTANT && c->expr2->ts.type == BT_BOZ)
5011 : : return false;
5012 : :
5013 : : /* Don't allow an intrinsic assignment to be replaced. */
5014 : 271863 : if (lhs->ts.type != BT_DERIVED && lhs->ts.type != BT_CLASS
5015 : 270892 : && (rhs->rank == 0 || rhs->rank == lhs->rank)
5016 : 549853 : && (lhs->ts.type == rhs->ts.type
5017 : 6702 : || (gfc_numeric_ts (&lhs->ts) && gfc_numeric_ts (&rhs->ts))))
5018 : 269782 : return false;
5019 : :
5020 : 9203 : actual = gfc_get_actual_arglist ();
5021 : 9203 : actual->expr = lhs;
5022 : :
5023 : 9203 : actual->next = gfc_get_actual_arglist ();
5024 : 9203 : actual->next->expr = rhs;
5025 : :
5026 : : /* TODO: Ambiguity-check, see above for gfc_extend_expr. */
5027 : :
5028 : : /* See if we find a matching type-bound assignment. */
5029 : 9203 : tbo = matching_typebound_op (&tb_base, actual, INTRINSIC_ASSIGN,
5030 : : NULL, &gname);
5031 : :
5032 : 9203 : if (tbo)
5033 : : {
5034 : : /* Success: Replace the expression with a type-bound call. */
5035 : 416 : gcc_assert (tb_base);
5036 : 416 : c->expr1 = gfc_get_expr ();
5037 : 416 : build_compcall_for_operator (c->expr1, actual, tb_base, tbo, gname);
5038 : 416 : c->expr1->value.compcall.assign = 1;
5039 : 416 : c->expr1->where = c->loc;
5040 : 416 : c->expr2 = NULL;
5041 : 416 : c->op = EXEC_COMPCALL;
5042 : 416 : return true;
5043 : : }
5044 : :
5045 : : /* See if we find an 'ordinary' (non-typebound) assignment procedure. */
5046 : 20377 : for (; ns; ns = ns->parent)
5047 : : {
5048 : 11926 : sym = gfc_search_interface (ns->op[INTRINSIC_ASSIGN], 1, &actual);
5049 : 11926 : if (sym != NULL)
5050 : : break;
5051 : : }
5052 : :
5053 : 8787 : if (sym)
5054 : : {
5055 : : /* Success: Replace the assignment with the call. */
5056 : 336 : c->op = EXEC_ASSIGN_CALL;
5057 : 336 : c->symtree = gfc_find_sym_in_symtree (sym);
5058 : 336 : c->expr1 = NULL;
5059 : 336 : c->expr2 = NULL;
5060 : 336 : c->ext.actual = actual;
5061 : 336 : return true;
5062 : : }
5063 : :
5064 : : /* Failure: No assignment procedure found. */
5065 : 8451 : free (actual->next);
5066 : 8451 : free (actual);
5067 : 8451 : return false;
5068 : : }
5069 : :
5070 : :
5071 : : /* Make sure that the interface just parsed is not already present in
5072 : : the given interface list. Ambiguity isn't checked yet since module
5073 : : procedures can be present without interfaces. */
5074 : :
5075 : : bool
5076 : 9356 : gfc_check_new_interface (gfc_interface *base, gfc_symbol *new_sym, locus loc)
5077 : : {
5078 : 9356 : gfc_interface *ip;
5079 : :
5080 : 18412 : for (ip = base; ip; ip = ip->next)
5081 : : {
5082 : 9063 : if (ip->sym == new_sym)
5083 : : {
5084 : 7 : gfc_error ("Entity %qs at %L is already present in the interface",
5085 : : new_sym->name, &loc);
5086 : 7 : return false;
5087 : : }
5088 : : }
5089 : :
5090 : : return true;
5091 : : }
5092 : :
5093 : :
5094 : : /* Add a symbol to the current interface. */
5095 : :
5096 : : bool
5097 : 16947 : gfc_add_interface (gfc_symbol *new_sym)
5098 : : {
5099 : 16947 : gfc_interface **head, *intr;
5100 : 16947 : gfc_namespace *ns;
5101 : 16947 : gfc_symbol *sym;
5102 : :
5103 : 16947 : switch (current_interface.type)
5104 : : {
5105 : : case INTERFACE_NAMELESS:
5106 : : case INTERFACE_ABSTRACT:
5107 : : return true;
5108 : :
5109 : 621 : case INTERFACE_INTRINSIC_OP:
5110 : 1245 : for (ns = current_interface.ns; ns; ns = ns->parent)
5111 : 627 : switch (current_interface.op)
5112 : : {
5113 : 75 : case INTRINSIC_EQ:
5114 : 75 : case INTRINSIC_EQ_OS:
5115 : 75 : if (!gfc_check_new_interface (ns->op[INTRINSIC_EQ], new_sym,
5116 : : gfc_current_locus)
5117 : 75 : || !gfc_check_new_interface (ns->op[INTRINSIC_EQ_OS],
5118 : : new_sym, gfc_current_locus))
5119 : 2 : return false;
5120 : : break;
5121 : :
5122 : 44 : case INTRINSIC_NE:
5123 : 44 : case INTRINSIC_NE_OS:
5124 : 44 : if (!gfc_check_new_interface (ns->op[INTRINSIC_NE], new_sym,
5125 : : gfc_current_locus)
5126 : 44 : || !gfc_check_new_interface (ns->op[INTRINSIC_NE_OS],
5127 : : new_sym, gfc_current_locus))
5128 : 0 : return false;
5129 : : break;
5130 : :
5131 : 19 : case INTRINSIC_GT:
5132 : 19 : case INTRINSIC_GT_OS:
5133 : 19 : if (!gfc_check_new_interface (ns->op[INTRINSIC_GT],
5134 : : new_sym, gfc_current_locus)
5135 : 19 : || !gfc_check_new_interface (ns->op[INTRINSIC_GT_OS],
5136 : : new_sym, gfc_current_locus))
5137 : 0 : return false;
5138 : : break;
5139 : :
5140 : 17 : case INTRINSIC_GE:
5141 : 17 : case INTRINSIC_GE_OS:
5142 : 17 : if (!gfc_check_new_interface (ns->op[INTRINSIC_GE],
5143 : : new_sym, gfc_current_locus)
5144 : 17 : || !gfc_check_new_interface (ns->op[INTRINSIC_GE_OS],
5145 : : new_sym, gfc_current_locus))
5146 : 0 : return false;
5147 : : break;
5148 : :
5149 : 29 : case INTRINSIC_LT:
5150 : 29 : case INTRINSIC_LT_OS:
5151 : 29 : if (!gfc_check_new_interface (ns->op[INTRINSIC_LT],
5152 : : new_sym, gfc_current_locus)
5153 : 29 : || !gfc_check_new_interface (ns->op[INTRINSIC_LT_OS],
5154 : : new_sym, gfc_current_locus))
5155 : 0 : return false;
5156 : : break;
5157 : :
5158 : 17 : case INTRINSIC_LE:
5159 : 17 : case INTRINSIC_LE_OS:
5160 : 17 : if (!gfc_check_new_interface (ns->op[INTRINSIC_LE],
5161 : : new_sym, gfc_current_locus)
5162 : 17 : || !gfc_check_new_interface (ns->op[INTRINSIC_LE_OS],
5163 : : new_sym, gfc_current_locus))
5164 : 0 : return false;
5165 : : break;
5166 : :
5167 : 426 : default:
5168 : 426 : if (!gfc_check_new_interface (ns->op[current_interface.op],
5169 : : new_sym, gfc_current_locus))
5170 : : return false;
5171 : : }
5172 : :
5173 : 618 : head = ¤t_interface.ns->op[current_interface.op];
5174 : 618 : break;
5175 : :
5176 : 8020 : case INTERFACE_GENERIC:
5177 : 8020 : case INTERFACE_DTIO:
5178 : 16049 : for (ns = current_interface.ns; ns; ns = ns->parent)
5179 : : {
5180 : 8030 : gfc_find_symbol (current_interface.sym->name, ns, 0, &sym);
5181 : 8030 : if (sym == NULL)
5182 : 10 : continue;
5183 : :
5184 : 8020 : if (!gfc_check_new_interface (sym->generic,
5185 : : new_sym, gfc_current_locus))
5186 : : return false;
5187 : : }
5188 : :
5189 : 8019 : head = ¤t_interface.sym->generic;
5190 : 8019 : break;
5191 : :
5192 : 168 : case INTERFACE_USER_OP:
5193 : 168 : if (!gfc_check_new_interface (current_interface.uop->op,
5194 : : new_sym, gfc_current_locus))
5195 : : return false;
5196 : :
5197 : 167 : head = ¤t_interface.uop->op;
5198 : 167 : break;
5199 : :
5200 : 0 : default:
5201 : 0 : gfc_internal_error ("gfc_add_interface(): Bad interface type");
5202 : : }
5203 : :
5204 : 8804 : intr = gfc_get_interface ();
5205 : 8804 : intr->sym = new_sym;
5206 : 8804 : intr->where = gfc_current_locus;
5207 : :
5208 : 8804 : intr->next = *head;
5209 : 8804 : *head = intr;
5210 : :
5211 : 8804 : return true;
5212 : : }
5213 : :
5214 : :
5215 : : gfc_interface *&
5216 : 85373 : gfc_current_interface_head (void)
5217 : : {
5218 : 85373 : switch (current_interface.type)
5219 : : {
5220 : 10312 : case INTERFACE_INTRINSIC_OP:
5221 : 10312 : return current_interface.ns->op[current_interface.op];
5222 : :
5223 : 72210 : case INTERFACE_GENERIC:
5224 : 72210 : case INTERFACE_DTIO:
5225 : 72210 : return current_interface.sym->generic;
5226 : :
5227 : 2851 : case INTERFACE_USER_OP:
5228 : 2851 : return current_interface.uop->op;
5229 : :
5230 : 0 : default:
5231 : 0 : gcc_unreachable ();
5232 : : }
5233 : : }
5234 : :
5235 : :
5236 : : void
5237 : 3 : gfc_set_current_interface_head (gfc_interface *i)
5238 : : {
5239 : 3 : switch (current_interface.type)
5240 : : {
5241 : 0 : case INTERFACE_INTRINSIC_OP:
5242 : 0 : current_interface.ns->op[current_interface.op] = i;
5243 : 0 : break;
5244 : :
5245 : 3 : case INTERFACE_GENERIC:
5246 : 3 : case INTERFACE_DTIO:
5247 : 3 : current_interface.sym->generic = i;
5248 : 3 : break;
5249 : :
5250 : 0 : case INTERFACE_USER_OP:
5251 : 0 : current_interface.uop->op = i;
5252 : 0 : break;
5253 : :
5254 : 0 : default:
5255 : 0 : gcc_unreachable ();
5256 : : }
5257 : 3 : }
5258 : :
5259 : :
5260 : : /* Gets rid of a formal argument list. We do not free symbols.
5261 : : Symbols are freed when a namespace is freed. */
5262 : :
5263 : : void
5264 : 5983169 : gfc_free_formal_arglist (gfc_formal_arglist *p)
5265 : : {
5266 : 5983169 : gfc_formal_arglist *q;
5267 : :
5268 : 6672843 : for (; p; p = q)
5269 : : {
5270 : 689674 : q = p->next;
5271 : 689674 : free (p);
5272 : : }
5273 : 5983169 : }
5274 : :
5275 : :
5276 : : /* Check that it is ok for the type-bound procedure 'proc' to override the
5277 : : procedure 'old', cf. F08:4.5.7.3. */
5278 : :
5279 : : bool
5280 : 1210 : gfc_check_typebound_override (gfc_symtree* proc, gfc_symtree* old)
5281 : : {
5282 : 1210 : locus where;
5283 : 1210 : gfc_symbol *proc_target, *old_target;
5284 : 1210 : unsigned proc_pass_arg, old_pass_arg, argpos;
5285 : 1210 : gfc_formal_arglist *proc_formal, *old_formal;
5286 : 1210 : bool check_type;
5287 : 1210 : char err[200];
5288 : :
5289 : : /* This procedure should only be called for non-GENERIC proc. */
5290 : 1210 : gcc_assert (!proc->n.tb->is_generic);
5291 : :
5292 : : /* If the overwritten procedure is GENERIC, this is an error. */
5293 : 1210 : if (old->n.tb->is_generic)
5294 : : {
5295 : 1 : gfc_error ("Cannot overwrite GENERIC %qs at %L",
5296 : : old->name, &proc->n.tb->where);
5297 : 1 : return false;
5298 : : }
5299 : :
5300 : 1209 : where = proc->n.tb->where;
5301 : 1209 : proc_target = proc->n.tb->u.specific->n.sym;
5302 : 1209 : old_target = old->n.tb->u.specific->n.sym;
5303 : :
5304 : : /* Check that overridden binding is not NON_OVERRIDABLE. */
5305 : 1209 : if (old->n.tb->non_overridable)
5306 : : {
5307 : 1 : gfc_error ("%qs at %L overrides a procedure binding declared"
5308 : : " NON_OVERRIDABLE", proc->name, &where);
5309 : 1 : return false;
5310 : : }
5311 : :
5312 : : /* It's an error to override a non-DEFERRED procedure with a DEFERRED one. */
5313 : 1208 : if (!old->n.tb->deferred && proc->n.tb->deferred)
5314 : : {
5315 : 1 : gfc_error ("%qs at %L must not be DEFERRED as it overrides a"
5316 : : " non-DEFERRED binding", proc->name, &where);
5317 : 1 : return false;
5318 : : }
5319 : :
5320 : : /* If the overridden binding is PURE, the overriding must be, too. */
5321 : 1207 : if (old_target->attr.pure && !proc_target->attr.pure)
5322 : : {
5323 : 2 : gfc_error ("%qs at %L overrides a PURE procedure and must also be PURE",
5324 : : proc->name, &where);
5325 : 2 : return false;
5326 : : }
5327 : :
5328 : : /* If the overridden binding is ELEMENTAL, the overriding must be, too. If it
5329 : : is not, the overriding must not be either. */
5330 : 1205 : if (old_target->attr.elemental && !proc_target->attr.elemental)
5331 : : {
5332 : 0 : gfc_error ("%qs at %L overrides an ELEMENTAL procedure and must also be"
5333 : : " ELEMENTAL", proc->name, &where);
5334 : 0 : return false;
5335 : : }
5336 : 1205 : if (!old_target->attr.elemental && proc_target->attr.elemental)
5337 : : {
5338 : 1 : gfc_error ("%qs at %L overrides a non-ELEMENTAL procedure and must not"
5339 : : " be ELEMENTAL, either", proc->name, &where);
5340 : 1 : return false;
5341 : : }
5342 : :
5343 : : /* If the overridden binding is a SUBROUTINE, the overriding must also be a
5344 : : SUBROUTINE. */
5345 : 1204 : if (old_target->attr.subroutine && !proc_target->attr.subroutine)
5346 : : {
5347 : 1 : gfc_error ("%qs at %L overrides a SUBROUTINE and must also be a"
5348 : : " SUBROUTINE", proc->name, &where);
5349 : 1 : return false;
5350 : : }
5351 : :
5352 : : /* If the overridden binding is a FUNCTION, the overriding must also be a
5353 : : FUNCTION and have the same characteristics. */
5354 : 1203 : if (old_target->attr.function)
5355 : : {
5356 : 654 : if (!proc_target->attr.function)
5357 : : {
5358 : 1 : gfc_error ("%qs at %L overrides a FUNCTION and must also be a"
5359 : : " FUNCTION", proc->name, &where);
5360 : 1 : return false;
5361 : : }
5362 : :
5363 : 653 : if (!gfc_check_result_characteristics (proc_target, old_target,
5364 : : err, sizeof(err)))
5365 : : {
5366 : 6 : gfc_error ("Result mismatch for the overriding procedure "
5367 : : "%qs at %L: %s", proc->name, &where, err);
5368 : 6 : return false;
5369 : : }
5370 : : }
5371 : :
5372 : : /* If the overridden binding is PUBLIC, the overriding one must not be
5373 : : PRIVATE. */
5374 : 1196 : if (old->n.tb->access == ACCESS_PUBLIC
5375 : 1171 : && proc->n.tb->access == ACCESS_PRIVATE)
5376 : : {
5377 : 1 : gfc_error ("%qs at %L overrides a PUBLIC procedure and must not be"
5378 : : " PRIVATE", proc->name, &where);
5379 : 1 : return false;
5380 : : }
5381 : :
5382 : : /* Compare the formal argument lists of both procedures. This is also abused
5383 : : to find the position of the passed-object dummy arguments of both
5384 : : bindings as at least the overridden one might not yet be resolved and we
5385 : : need those positions in the check below. */
5386 : 1195 : proc_pass_arg = old_pass_arg = 0;
5387 : 1195 : if (!proc->n.tb->nopass && !proc->n.tb->pass_arg)
5388 : 1195 : proc_pass_arg = 1;
5389 : 1195 : if (!old->n.tb->nopass && !old->n.tb->pass_arg)
5390 : 1195 : old_pass_arg = 1;
5391 : 1195 : argpos = 1;
5392 : 1195 : proc_formal = gfc_sym_get_dummy_args (proc_target);
5393 : 1195 : old_formal = gfc_sym_get_dummy_args (old_target);
5394 : 4317 : for ( ; proc_formal && old_formal;
5395 : 1927 : proc_formal = proc_formal->next, old_formal = old_formal->next)
5396 : : {
5397 : 1934 : if (proc->n.tb->pass_arg
5398 : 491 : && !strcmp (proc->n.tb->pass_arg, proc_formal->sym->name))
5399 : 1934 : proc_pass_arg = argpos;
5400 : 1934 : if (old->n.tb->pass_arg
5401 : 493 : && !strcmp (old->n.tb->pass_arg, old_formal->sym->name))
5402 : 1934 : old_pass_arg = argpos;
5403 : :
5404 : : /* Check that the names correspond. */
5405 : 1934 : if (strcmp (proc_formal->sym->name, old_formal->sym->name))
5406 : : {
5407 : 1 : gfc_error ("Dummy argument %qs of %qs at %L should be named %qs as"
5408 : : " to match the corresponding argument of the overridden"
5409 : : " procedure", proc_formal->sym->name, proc->name, &where,
5410 : : old_formal->sym->name);
5411 : 1 : return false;
5412 : : }
5413 : :
5414 : 1933 : check_type = proc_pass_arg != argpos && old_pass_arg != argpos;
5415 : 1933 : if (!gfc_check_dummy_characteristics (proc_formal->sym, old_formal->sym,
5416 : : check_type, err, sizeof(err)))
5417 : : {
5418 : 6 : gfc_error_opt (0, "Argument mismatch for the overriding procedure "
5419 : : "%qs at %L: %s", proc->name, &where, err);
5420 : 6 : return false;
5421 : : }
5422 : :
5423 : 1927 : ++argpos;
5424 : : }
5425 : 1188 : if (proc_formal || old_formal)
5426 : : {
5427 : 1 : gfc_error ("%qs at %L must have the same number of formal arguments as"
5428 : : " the overridden procedure", proc->name, &where);
5429 : 1 : return false;
5430 : : }
5431 : :
5432 : : /* If the overridden binding is NOPASS, the overriding one must also be
5433 : : NOPASS. */
5434 : 1187 : if (old->n.tb->nopass && !proc->n.tb->nopass)
5435 : : {
5436 : 1 : gfc_error ("%qs at %L overrides a NOPASS binding and must also be"
5437 : : " NOPASS", proc->name, &where);
5438 : 1 : return false;
5439 : : }
5440 : :
5441 : : /* If the overridden binding is PASS(x), the overriding one must also be
5442 : : PASS and the passed-object dummy arguments must correspond. */
5443 : 1186 : if (!old->n.tb->nopass)
5444 : : {
5445 : 1152 : if (proc->n.tb->nopass)
5446 : : {
5447 : 1 : gfc_error ("%qs at %L overrides a binding with PASS and must also be"
5448 : : " PASS", proc->name, &where);
5449 : 1 : return false;
5450 : : }
5451 : :
5452 : 1151 : if (proc_pass_arg != old_pass_arg)
5453 : : {
5454 : 1 : gfc_error ("Passed-object dummy argument of %qs at %L must be at"
5455 : : " the same position as the passed-object dummy argument of"
5456 : : " the overridden procedure", proc->name, &where);
5457 : 1 : return false;
5458 : : }
5459 : : }
5460 : :
5461 : : return true;
5462 : : }
5463 : :
5464 : :
5465 : : /* The following three functions check that the formal arguments
5466 : : of user defined derived type IO procedures are compliant with
5467 : : the requirements of the standard, see F03:9.5.3.7.2 (F08:9.6.4.8.3). */
5468 : :
5469 : : static void
5470 : 4380 : check_dtio_arg_TKR_intent (gfc_symbol *fsym, bool typebound, bt type,
5471 : : int kind, int rank, sym_intent intent)
5472 : : {
5473 : 4380 : if (fsym->ts.type != type)
5474 : : {
5475 : 3 : gfc_error ("DTIO dummy argument at %L must be of type %s",
5476 : : &fsym->declared_at, gfc_basic_typename (type));
5477 : 3 : return;
5478 : : }
5479 : :
5480 : 4377 : if (fsym->ts.type != BT_CLASS && fsym->ts.type != BT_DERIVED
5481 : 3607 : && fsym->ts.kind != kind)
5482 : 1 : gfc_error ("DTIO dummy argument at %L must be of KIND = %d",
5483 : : &fsym->declared_at, kind);
5484 : :
5485 : 4377 : if (!typebound
5486 : 4377 : && rank == 0
5487 : 998 : && (((type == BT_CLASS) && CLASS_DATA (fsym)->attr.dimension)
5488 : 830 : || ((type != BT_CLASS) && fsym->attr.dimension)))
5489 : 0 : gfc_error ("DTIO dummy argument at %L must be a scalar",
5490 : : &fsym->declared_at);
5491 : 4377 : else if (rank == 1
5492 : 645 : && (fsym->as == NULL || fsym->as->type != AS_ASSUMED_SHAPE))
5493 : 1 : gfc_error ("DTIO dummy argument at %L must be an "
5494 : : "ASSUMED SHAPE ARRAY", &fsym->declared_at);
5495 : :
5496 : 4377 : if (type == BT_CHARACTER && fsym->ts.u.cl->length != NULL)
5497 : 1 : gfc_error ("DTIO character argument at %L must have assumed length",
5498 : : &fsym->declared_at);
5499 : :
5500 : 4377 : if (fsym->attr.intent != intent)
5501 : 1 : gfc_error ("DTIO dummy argument at %L must have INTENT %s",
5502 : : &fsym->declared_at, gfc_code2string (intents, (int)intent));
5503 : : return;
5504 : : }
5505 : :
5506 : :
5507 : : static void
5508 : 857 : check_dtio_interface1 (gfc_symbol *derived, gfc_symtree *tb_io_st,
5509 : : bool typebound, bool formatted, int code)
5510 : : {
5511 : 857 : gfc_symbol *dtio_sub, *generic_proc, *fsym;
5512 : 857 : gfc_typebound_proc *tb_io_proc, *specific_proc;
5513 : 857 : gfc_interface *intr;
5514 : 857 : gfc_formal_arglist *formal;
5515 : 857 : int arg_num;
5516 : :
5517 : 857 : bool read = ((dtio_codes)code == DTIO_RF)
5518 : 857 : || ((dtio_codes)code == DTIO_RUF);
5519 : 857 : bt type;
5520 : 857 : sym_intent intent;
5521 : 857 : int kind;
5522 : :
5523 : 857 : dtio_sub = NULL;
5524 : 857 : if (typebound)
5525 : : {
5526 : : /* Typebound DTIO binding. */
5527 : 557 : tb_io_proc = tb_io_st->n.tb;
5528 : 557 : if (tb_io_proc == NULL)
5529 : : return;
5530 : :
5531 : 557 : gcc_assert (tb_io_proc->is_generic);
5532 : :
5533 : 557 : specific_proc = tb_io_proc->u.generic->specific;
5534 : 557 : if (specific_proc == NULL || specific_proc->is_generic)
5535 : : return;
5536 : :
5537 : 557 : dtio_sub = specific_proc->u.specific->n.sym;
5538 : : }
5539 : : else
5540 : : {
5541 : 300 : generic_proc = tb_io_st->n.sym;
5542 : 300 : if (generic_proc == NULL || generic_proc->generic == NULL)
5543 : : return;
5544 : :
5545 : 377 : for (intr = tb_io_st->n.sym->generic; intr; intr = intr->next)
5546 : : {
5547 : 304 : if (intr->sym && intr->sym->formal && intr->sym->formal->sym
5548 : 300 : && ((intr->sym->formal->sym->ts.type == BT_CLASS
5549 : 201 : && CLASS_DATA (intr->sym->formal->sym)->ts.u.derived
5550 : : == derived)
5551 : 127 : || (intr->sym->formal->sym->ts.type == BT_DERIVED
5552 : 99 : && intr->sym->formal->sym->ts.u.derived == derived)))
5553 : : {
5554 : : dtio_sub = intr->sym;
5555 : : break;
5556 : : }
5557 : 80 : else if (intr->sym && intr->sym->formal && !intr->sym->formal->sym)
5558 : : {
5559 : 1 : gfc_error ("Alternate return at %L is not permitted in a DTIO "
5560 : : "procedure", &intr->sym->declared_at);
5561 : 1 : return;
5562 : : }
5563 : : }
5564 : :
5565 : 297 : if (dtio_sub == NULL)
5566 : : return;
5567 : : }
5568 : :
5569 : 557 : gcc_assert (dtio_sub);
5570 : 781 : if (!dtio_sub->attr.subroutine)
5571 : 0 : gfc_error ("DTIO procedure %qs at %L must be a subroutine",
5572 : : dtio_sub->name, &dtio_sub->declared_at);
5573 : :
5574 : 781 : if (!dtio_sub->resolve_symbol_called)
5575 : 1 : gfc_resolve_formal_arglist (dtio_sub);
5576 : :
5577 : 781 : arg_num = 0;
5578 : 5192 : for (formal = dtio_sub->formal; formal; formal = formal->next)
5579 : 4411 : arg_num++;
5580 : :
5581 : 912 : if (arg_num < (formatted ? 6 : 4))
5582 : : {
5583 : 5 : gfc_error ("Too few dummy arguments in DTIO procedure %qs at %L",
5584 : : dtio_sub->name, &dtio_sub->declared_at);
5585 : 5 : return;
5586 : : }
5587 : :
5588 : 776 : if (arg_num > (formatted ? 6 : 4))
5589 : : {
5590 : 3 : gfc_error ("Too many dummy arguments in DTIO procedure %qs at %L",
5591 : : dtio_sub->name, &dtio_sub->declared_at);
5592 : 3 : return;
5593 : : }
5594 : :
5595 : : /* Now go through the formal arglist. */
5596 : : arg_num = 1;
5597 : 5153 : for (formal = dtio_sub->formal; formal; formal = formal->next, arg_num++)
5598 : : {
5599 : 4381 : if (!formatted && arg_num == 3)
5600 : 128 : arg_num = 5;
5601 : 4381 : fsym = formal->sym;
5602 : :
5603 : 4381 : if (fsym == NULL)
5604 : : {
5605 : 1 : gfc_error ("Alternate return at %L is not permitted in a DTIO "
5606 : : "procedure", &dtio_sub->declared_at);
5607 : 1 : return;
5608 : : }
5609 : :
5610 : 4380 : switch (arg_num)
5611 : : {
5612 : 773 : case(1): /* DTV */
5613 : 773 : type = derived->attr.sequence || derived->attr.is_bind_c ?
5614 : : BT_DERIVED : BT_CLASS;
5615 : 773 : kind = 0;
5616 : 773 : intent = read ? INTENT_INOUT : INTENT_IN;
5617 : 773 : check_dtio_arg_TKR_intent (fsym, typebound, type, kind,
5618 : : 0, intent);
5619 : 773 : break;
5620 : :
5621 : 773 : case(2): /* UNIT */
5622 : 773 : type = BT_INTEGER;
5623 : 773 : kind = gfc_default_integer_kind;
5624 : 773 : intent = INTENT_IN;
5625 : 773 : check_dtio_arg_TKR_intent (fsym, typebound, type, kind,
5626 : : 0, intent);
5627 : 773 : break;
5628 : 645 : case(3): /* IOTYPE */
5629 : 645 : type = BT_CHARACTER;
5630 : 645 : kind = gfc_default_character_kind;
5631 : 645 : intent = INTENT_IN;
5632 : 645 : check_dtio_arg_TKR_intent (fsym, typebound, type, kind,
5633 : : 0, intent);
5634 : 645 : break;
5635 : 645 : case(4): /* VLIST */
5636 : 645 : type = BT_INTEGER;
5637 : 645 : kind = gfc_default_integer_kind;
5638 : 645 : intent = INTENT_IN;
5639 : 645 : check_dtio_arg_TKR_intent (fsym, typebound, type, kind,
5640 : : 1, intent);
5641 : 645 : break;
5642 : 772 : case(5): /* IOSTAT */
5643 : 772 : type = BT_INTEGER;
5644 : 772 : kind = gfc_default_integer_kind;
5645 : 772 : intent = INTENT_OUT;
5646 : 772 : check_dtio_arg_TKR_intent (fsym, typebound, type, kind,
5647 : : 0, intent);
5648 : 772 : break;
5649 : 772 : case(6): /* IOMSG */
5650 : 772 : type = BT_CHARACTER;
5651 : 772 : kind = gfc_default_character_kind;
5652 : 772 : intent = INTENT_INOUT;
5653 : 772 : check_dtio_arg_TKR_intent (fsym, typebound, type, kind,
5654 : : 0, intent);
5655 : 772 : break;
5656 : 0 : default:
5657 : 0 : gcc_unreachable ();
5658 : : }
5659 : : }
5660 : 772 : derived->attr.has_dtio_procs = 1;
5661 : 772 : return;
5662 : : }
5663 : :
5664 : : void
5665 : 87429 : gfc_check_dtio_interfaces (gfc_symbol *derived)
5666 : : {
5667 : 87429 : gfc_symtree *tb_io_st;
5668 : 87429 : bool t = false;
5669 : 87429 : int code;
5670 : 87429 : bool formatted;
5671 : :
5672 : 87429 : if (derived->attr.is_class == 1 || derived->attr.vtype == 1)
5673 : 34371 : return;
5674 : :
5675 : : /* Check typebound DTIO bindings. */
5676 : 265290 : for (code = 0; code < 4; code++)
5677 : : {
5678 : 212232 : formatted = ((dtio_codes)code == DTIO_RF)
5679 : : || ((dtio_codes)code == DTIO_WF);
5680 : :
5681 : 212232 : tb_io_st = gfc_find_typebound_proc (derived, &t,
5682 : : gfc_code2string (dtio_procs, code),
5683 : : true, &derived->declared_at);
5684 : 212232 : if (tb_io_st != NULL)
5685 : 557 : check_dtio_interface1 (derived, tb_io_st, true, formatted, code);
5686 : : }
5687 : :
5688 : : /* Check generic DTIO interfaces. */
5689 : 265290 : for (code = 0; code < 4; code++)
5690 : : {
5691 : 212232 : formatted = ((dtio_codes)code == DTIO_RF)
5692 : : || ((dtio_codes)code == DTIO_WF);
5693 : :
5694 : 212232 : tb_io_st = gfc_find_symtree (derived->ns->sym_root,
5695 : : gfc_code2string (dtio_procs, code));
5696 : 212232 : if (tb_io_st != NULL)
5697 : 300 : check_dtio_interface1 (derived, tb_io_st, false, formatted, code);
5698 : : }
5699 : : }
5700 : :
5701 : :
5702 : : gfc_symtree*
5703 : 4265 : gfc_find_typebound_dtio_proc (gfc_symbol *derived, bool write, bool formatted)
5704 : : {
5705 : 4265 : gfc_symtree *tb_io_st = NULL;
5706 : 4265 : bool t = false;
5707 : :
5708 : 4265 : if (!derived || !derived->resolve_symbol_called
5709 : 4265 : || derived->attr.flavor != FL_DERIVED)
5710 : : return NULL;
5711 : :
5712 : : /* Try to find a typebound DTIO binding. */
5713 : 4259 : if (formatted == true)
5714 : : {
5715 : 4014 : if (write == true)
5716 : 1899 : tb_io_st = gfc_find_typebound_proc (derived, &t,
5717 : : gfc_code2string (dtio_procs,
5718 : : DTIO_WF),
5719 : : true,
5720 : : &derived->declared_at);
5721 : : else
5722 : 2115 : tb_io_st = gfc_find_typebound_proc (derived, &t,
5723 : : gfc_code2string (dtio_procs,
5724 : : DTIO_RF),
5725 : : true,
5726 : : &derived->declared_at);
5727 : : }
5728 : : else
5729 : : {
5730 : 245 : if (write == true)
5731 : 109 : tb_io_st = gfc_find_typebound_proc (derived, &t,
5732 : : gfc_code2string (dtio_procs,
5733 : : DTIO_WUF),
5734 : : true,
5735 : : &derived->declared_at);
5736 : : else
5737 : 136 : tb_io_st = gfc_find_typebound_proc (derived, &t,
5738 : : gfc_code2string (dtio_procs,
5739 : : DTIO_RUF),
5740 : : true,
5741 : : &derived->declared_at);
5742 : : }
5743 : : return tb_io_st;
5744 : : }
5745 : :
5746 : :
5747 : : gfc_symbol *
5748 : 2848 : gfc_find_specific_dtio_proc (gfc_symbol *derived, bool write, bool formatted)
5749 : : {
5750 : 2848 : gfc_symtree *tb_io_st = NULL;
5751 : 2848 : gfc_symbol *dtio_sub = NULL;
5752 : 2848 : gfc_symbol *extended;
5753 : 2848 : gfc_typebound_proc *tb_io_proc, *specific_proc;
5754 : :
5755 : 2848 : tb_io_st = gfc_find_typebound_dtio_proc (derived, write, formatted);
5756 : :
5757 : 2848 : if (tb_io_st != NULL)
5758 : : {
5759 : 858 : const char *genname;
5760 : 858 : gfc_symtree *st;
5761 : :
5762 : 858 : tb_io_proc = tb_io_st->n.tb;
5763 : 858 : gcc_assert (tb_io_proc != NULL);
5764 : 858 : gcc_assert (tb_io_proc->is_generic);
5765 : 858 : gcc_assert (tb_io_proc->u.generic->next == NULL);
5766 : :
5767 : 858 : specific_proc = tb_io_proc->u.generic->specific;
5768 : 858 : gcc_assert (!specific_proc->is_generic);
5769 : :
5770 : : /* Go back and make sure that we have the right specific procedure.
5771 : : Here we most likely have a procedure from the parent type, which
5772 : : can be overridden in extensions. */
5773 : 858 : genname = tb_io_proc->u.generic->specific_st->name;
5774 : 858 : st = gfc_find_typebound_proc (derived, NULL, genname,
5775 : : true, &tb_io_proc->where);
5776 : 858 : if (st)
5777 : 858 : dtio_sub = st->n.tb->u.specific->n.sym;
5778 : : else
5779 : 0 : dtio_sub = specific_proc->u.specific->n.sym;
5780 : :
5781 : 858 : goto finish;
5782 : : }
5783 : :
5784 : : /* If there is not a typebound binding, look for a generic
5785 : : DTIO interface. */
5786 : 4059 : for (extended = derived; extended;
5787 : 2069 : extended = gfc_get_derived_super_type (extended))
5788 : : {
5789 : 2069 : if (extended == NULL || extended->ns == NULL
5790 : 2069 : || extended->attr.flavor == FL_UNKNOWN)
5791 : : return NULL;
5792 : :
5793 : 2069 : if (formatted == true)
5794 : : {
5795 : 1982 : if (write == true)
5796 : 907 : tb_io_st = gfc_find_symtree (extended->ns->sym_root,
5797 : : gfc_code2string (dtio_procs,
5798 : : DTIO_WF));
5799 : : else
5800 : 1075 : tb_io_st = gfc_find_symtree (extended->ns->sym_root,
5801 : : gfc_code2string (dtio_procs,
5802 : : DTIO_RF));
5803 : : }
5804 : : else
5805 : : {
5806 : 87 : if (write == true)
5807 : 37 : tb_io_st = gfc_find_symtree (extended->ns->sym_root,
5808 : : gfc_code2string (dtio_procs,
5809 : : DTIO_WUF));
5810 : : else
5811 : 50 : tb_io_st = gfc_find_symtree (extended->ns->sym_root,
5812 : : gfc_code2string (dtio_procs,
5813 : : DTIO_RUF));
5814 : : }
5815 : :
5816 : 2069 : if (tb_io_st != NULL
5817 : 221 : && tb_io_st->n.sym
5818 : 221 : && tb_io_st->n.sym->generic)
5819 : : {
5820 : 26 : for (gfc_interface *intr = tb_io_st->n.sym->generic;
5821 : 247 : intr && intr->sym; intr = intr->next)
5822 : : {
5823 : 225 : if (intr->sym->formal)
5824 : : {
5825 : 220 : gfc_symbol *fsym = intr->sym->formal->sym;
5826 : 220 : if ((fsym->ts.type == BT_CLASS
5827 : 170 : && CLASS_DATA (fsym)->ts.u.derived == extended)
5828 : 71 : || (fsym->ts.type == BT_DERIVED
5829 : 50 : && fsym->ts.u.derived == extended))
5830 : : {
5831 : : dtio_sub = intr->sym;
5832 : : break;
5833 : : }
5834 : : }
5835 : : }
5836 : : }
5837 : : }
5838 : :
5839 : 1990 : finish:
5840 : 2848 : if (dtio_sub
5841 : 1057 : && dtio_sub->formal->sym->ts.type == BT_CLASS
5842 : 1007 : && derived != CLASS_DATA (dtio_sub->formal->sym)->ts.u.derived)
5843 : 97 : gfc_find_derived_vtab (derived);
5844 : :
5845 : : return dtio_sub;
5846 : : }
5847 : :
5848 : : /* Helper function - if we do not find an interface for a procedure,
5849 : : construct it from the actual arglist. Luckily, this can only
5850 : : happen for call by reference, so the information we actually need
5851 : : to provide (and which would be impossible to guess from the call
5852 : : itself) is not actually needed. */
5853 : :
5854 : : void
5855 : 1984 : gfc_get_formal_from_actual_arglist (gfc_symbol *sym,
5856 : : gfc_actual_arglist *actual_args)
5857 : : {
5858 : 1984 : gfc_actual_arglist *a;
5859 : 1984 : gfc_formal_arglist **f;
5860 : 1984 : gfc_symbol *s;
5861 : 1984 : char name[GFC_MAX_SYMBOL_LEN + 1];
5862 : 1984 : static int var_num;
5863 : :
5864 : : /* Do not infer the formal from actual arguments if we are dealing with
5865 : : classes. */
5866 : :
5867 : 1984 : if (sym->ts.type == BT_CLASS)
5868 : 1 : return;
5869 : :
5870 : 1983 : f = &sym->formal;
5871 : 5952 : for (a = actual_args; a != NULL; a = a->next)
5872 : : {
5873 : 3969 : (*f) = gfc_get_formal_arglist ();
5874 : 3969 : if (a->expr)
5875 : : {
5876 : 3961 : snprintf (name, GFC_MAX_SYMBOL_LEN, "_formal_%d", var_num ++);
5877 : 3961 : gfc_get_symbol (name, gfc_current_ns, &s);
5878 : 3961 : if (a->expr->ts.type == BT_PROCEDURE)
5879 : : {
5880 : 44 : gfc_symbol *asym = a->expr->symtree->n.sym;
5881 : 44 : s->attr.flavor = FL_PROCEDURE;
5882 : 44 : if (asym->attr.function)
5883 : : {
5884 : 24 : s->attr.function = 1;
5885 : 24 : s->ts = asym->ts;
5886 : : }
5887 : 44 : s->attr.subroutine = asym->attr.subroutine;
5888 : : }
5889 : : else
5890 : : {
5891 : 3917 : s->ts = a->expr->ts;
5892 : :
5893 : 3917 : if (s->ts.type == BT_CHARACTER)
5894 : 176 : s->ts.u.cl = gfc_get_charlen ();
5895 : :
5896 : 3917 : s->ts.deferred = 0;
5897 : 3917 : s->ts.is_iso_c = 0;
5898 : 3917 : s->ts.is_c_interop = 0;
5899 : 3917 : s->attr.flavor = FL_VARIABLE;
5900 : 3917 : if (a->expr->rank > 0)
5901 : : {
5902 : 872 : s->attr.dimension = 1;
5903 : 872 : s->as = gfc_get_array_spec ();
5904 : 872 : s->as->rank = 1;
5905 : 1744 : s->as->lower[0] = gfc_get_int_expr (gfc_index_integer_kind,
5906 : 872 : &a->expr->where, 1);
5907 : 872 : s->as->upper[0] = NULL;
5908 : 872 : s->as->type = AS_ASSUMED_SIZE;
5909 : : }
5910 : : else
5911 : 3045 : s->maybe_array = maybe_dummy_array_arg (a->expr);
5912 : : }
5913 : 3961 : s->attr.dummy = 1;
5914 : 3961 : s->attr.artificial = 1;
5915 : 3961 : s->declared_at = a->expr->where;
5916 : 3961 : s->attr.intent = INTENT_UNKNOWN;
5917 : 3961 : (*f)->sym = s;
5918 : 3961 : gfc_commit_symbol (s);
5919 : : }
5920 : : else /* If a->expr is NULL, this is an alternate rerturn. */
5921 : 8 : (*f)->sym = NULL;
5922 : :
5923 : 3969 : f = &((*f)->next);
5924 : : }
5925 : :
5926 : : }
5927 : :
5928 : :
5929 : : const char *
5930 : 241 : gfc_dummy_arg_get_name (gfc_dummy_arg & dummy_arg)
5931 : : {
5932 : 241 : switch (dummy_arg.intrinsicness)
5933 : : {
5934 : 241 : case GFC_INTRINSIC_DUMMY_ARG:
5935 : 241 : return dummy_arg.u.intrinsic->name;
5936 : :
5937 : 0 : case GFC_NON_INTRINSIC_DUMMY_ARG:
5938 : 0 : return dummy_arg.u.non_intrinsic->sym->name;
5939 : :
5940 : 0 : default:
5941 : 0 : gcc_unreachable ();
5942 : : }
5943 : : }
5944 : :
5945 : :
5946 : : const gfc_typespec &
5947 : 2458 : gfc_dummy_arg_get_typespec (gfc_dummy_arg & dummy_arg)
5948 : : {
5949 : 2458 : switch (dummy_arg.intrinsicness)
5950 : : {
5951 : 1352 : case GFC_INTRINSIC_DUMMY_ARG:
5952 : 1352 : return dummy_arg.u.intrinsic->ts;
5953 : :
5954 : 1106 : case GFC_NON_INTRINSIC_DUMMY_ARG:
5955 : 1106 : return dummy_arg.u.non_intrinsic->sym->ts;
5956 : :
5957 : 0 : default:
5958 : 0 : gcc_unreachable ();
5959 : : }
5960 : : }
5961 : :
5962 : :
5963 : : bool
5964 : 25718 : gfc_dummy_arg_is_optional (gfc_dummy_arg & dummy_arg)
5965 : : {
5966 : 25718 : switch (dummy_arg.intrinsicness)
5967 : : {
5968 : 12244 : case GFC_INTRINSIC_DUMMY_ARG:
5969 : 12244 : return dummy_arg.u.intrinsic->optional;
5970 : :
5971 : 13474 : case GFC_NON_INTRINSIC_DUMMY_ARG:
5972 : 13474 : return dummy_arg.u.non_intrinsic->sym->attr.optional;
5973 : :
5974 : 0 : default:
5975 : 0 : gcc_unreachable ();
5976 : : }
5977 : : }
|