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