File: | build/gcc/fortran/resolve.cc |
Warning: | line 3910, column 3 Value stored to 'isym' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* Perform type resolution on the various structures. |
2 | Copyright (C) 2001-2023 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 | #include "config.h" |
22 | #include "system.h" |
23 | #include "coretypes.h" |
24 | #include "options.h" |
25 | #include "bitmap.h" |
26 | #include "gfortran.h" |
27 | #include "arith.h" /* For gfc_compare_expr(). */ |
28 | #include "dependency.h" |
29 | #include "data.h" |
30 | #include "target-memory.h" /* for gfc_simplify_transfer */ |
31 | #include "constructor.h" |
32 | |
33 | /* Types used in equivalence statements. */ |
34 | |
35 | enum seq_type |
36 | { |
37 | SEQ_NONDEFAULT, SEQ_NUMERIC, SEQ_CHARACTER, SEQ_MIXED |
38 | }; |
39 | |
40 | /* Stack to keep track of the nesting of blocks as we move through the |
41 | code. See resolve_branch() and gfc_resolve_code(). */ |
42 | |
43 | typedef struct code_stack |
44 | { |
45 | struct gfc_code *head, *current; |
46 | struct code_stack *prev; |
47 | |
48 | /* This bitmap keeps track of the targets valid for a branch from |
49 | inside this block except for END {IF|SELECT}s of enclosing |
50 | blocks. */ |
51 | bitmap reachable_labels; |
52 | } |
53 | code_stack; |
54 | |
55 | static code_stack *cs_base = NULL__null; |
56 | |
57 | |
58 | /* Nonzero if we're inside a FORALL or DO CONCURRENT block. */ |
59 | |
60 | static int forall_flag; |
61 | int gfc_do_concurrent_flag; |
62 | |
63 | /* True when we are resolving an expression that is an actual argument to |
64 | a procedure. */ |
65 | static bool actual_arg = false; |
66 | /* True when we are resolving an expression that is the first actual argument |
67 | to a procedure. */ |
68 | static bool first_actual_arg = false; |
69 | |
70 | |
71 | /* Nonzero if we're inside a OpenMP WORKSHARE or PARALLEL WORKSHARE block. */ |
72 | |
73 | static int omp_workshare_flag; |
74 | |
75 | /* True if we are processing a formal arglist. The corresponding function |
76 | resets the flag each time that it is read. */ |
77 | static bool formal_arg_flag = false; |
78 | |
79 | /* True if we are resolving a specification expression. */ |
80 | static bool specification_expr = false; |
81 | |
82 | /* The id of the last entry seen. */ |
83 | static int current_entry_id; |
84 | |
85 | /* We use bitmaps to determine if a branch target is valid. */ |
86 | static bitmap_obstack labels_obstack; |
87 | |
88 | /* True when simplifying a EXPR_VARIABLE argument to an inquiry function. */ |
89 | static bool inquiry_argument = false; |
90 | |
91 | |
92 | bool |
93 | gfc_is_formal_arg (void) |
94 | { |
95 | return formal_arg_flag; |
96 | } |
97 | |
98 | /* Is the symbol host associated? */ |
99 | static bool |
100 | is_sym_host_assoc (gfc_symbol *sym, gfc_namespace *ns) |
101 | { |
102 | for (ns = ns->parent; ns; ns = ns->parent) |
103 | { |
104 | if (sym->ns == ns) |
105 | return true; |
106 | } |
107 | |
108 | return false; |
109 | } |
110 | |
111 | /* Ensure a typespec used is valid; for instance, TYPE(t) is invalid if t is |
112 | an ABSTRACT derived-type. If where is not NULL, an error message with that |
113 | locus is printed, optionally using name. */ |
114 | |
115 | static bool |
116 | resolve_typespec_used (gfc_typespec* ts, locus* where, const char* name) |
117 | { |
118 | if (ts->type == BT_DERIVED && ts->u.derived->attr.abstract) |
119 | { |
120 | if (where) |
121 | { |
122 | if (name) |
123 | gfc_error ("%qs at %L is of the ABSTRACT type %qs", |
124 | name, where, ts->u.derived->name); |
125 | else |
126 | gfc_error ("ABSTRACT type %qs used at %L", |
127 | ts->u.derived->name, where); |
128 | } |
129 | |
130 | return false; |
131 | } |
132 | |
133 | return true; |
134 | } |
135 | |
136 | |
137 | static bool |
138 | check_proc_interface (gfc_symbol *ifc, locus *where) |
139 | { |
140 | /* Several checks for F08:C1216. */ |
141 | if (ifc->attr.procedure) |
142 | { |
143 | gfc_error ("Interface %qs at %L is declared " |
144 | "in a later PROCEDURE statement", ifc->name, where); |
145 | return false; |
146 | } |
147 | if (ifc->generic) |
148 | { |
149 | /* For generic interfaces, check if there is |
150 | a specific procedure with the same name. */ |
151 | gfc_interface *gen = ifc->generic; |
152 | while (gen && strcmp (gen->sym->name, ifc->name) != 0) |
153 | gen = gen->next; |
154 | if (!gen) |
155 | { |
156 | gfc_error ("Interface %qs at %L may not be generic", |
157 | ifc->name, where); |
158 | return false; |
159 | } |
160 | } |
161 | if (ifc->attr.proc == PROC_ST_FUNCTION) |
162 | { |
163 | gfc_error ("Interface %qs at %L may not be a statement function", |
164 | ifc->name, where); |
165 | return false; |
166 | } |
167 | if (gfc_is_intrinsic (ifc, 0, ifc->declared_at) |
168 | || gfc_is_intrinsic (ifc, 1, ifc->declared_at)) |
169 | ifc->attr.intrinsic = 1; |
170 | if (ifc->attr.intrinsic && !gfc_intrinsic_actual_ok (ifc->name, 0)) |
171 | { |
172 | gfc_error ("Intrinsic procedure %qs not allowed in " |
173 | "PROCEDURE statement at %L", ifc->name, where); |
174 | return false; |
175 | } |
176 | if (!ifc->attr.if_source && !ifc->attr.intrinsic && ifc->name[0] != '\0') |
177 | { |
178 | gfc_error ("Interface %qs at %L must be explicit", ifc->name, where); |
179 | return false; |
180 | } |
181 | return true; |
182 | } |
183 | |
184 | |
185 | static void resolve_symbol (gfc_symbol *sym); |
186 | |
187 | |
188 | /* Resolve the interface for a PROCEDURE declaration or procedure pointer. */ |
189 | |
190 | static bool |
191 | resolve_procedure_interface (gfc_symbol *sym) |
192 | { |
193 | gfc_symbol *ifc = sym->ts.interface; |
194 | |
195 | if (!ifc) |
196 | return true; |
197 | |
198 | if (ifc == sym) |
199 | { |
200 | gfc_error ("PROCEDURE %qs at %L may not be used as its own interface", |
201 | sym->name, &sym->declared_at); |
202 | return false; |
203 | } |
204 | if (!check_proc_interface (ifc, &sym->declared_at)) |
205 | return false; |
206 | |
207 | if (ifc->attr.if_source || ifc->attr.intrinsic) |
208 | { |
209 | /* Resolve interface and copy attributes. */ |
210 | resolve_symbol (ifc); |
211 | if (ifc->attr.intrinsic) |
212 | gfc_resolve_intrinsic (ifc, &ifc->declared_at); |
213 | |
214 | if (ifc->result) |
215 | { |
216 | sym->ts = ifc->result->ts; |
217 | sym->attr.allocatable = ifc->result->attr.allocatable; |
218 | sym->attr.pointer = ifc->result->attr.pointer; |
219 | sym->attr.dimension = ifc->result->attr.dimension; |
220 | sym->attr.class_ok = ifc->result->attr.class_ok; |
221 | sym->as = gfc_copy_array_spec (ifc->result->as); |
222 | sym->result = sym; |
223 | } |
224 | else |
225 | { |
226 | sym->ts = ifc->ts; |
227 | sym->attr.allocatable = ifc->attr.allocatable; |
228 | sym->attr.pointer = ifc->attr.pointer; |
229 | sym->attr.dimension = ifc->attr.dimension; |
230 | sym->attr.class_ok = ifc->attr.class_ok; |
231 | sym->as = gfc_copy_array_spec (ifc->as); |
232 | } |
233 | sym->ts.interface = ifc; |
234 | sym->attr.function = ifc->attr.function; |
235 | sym->attr.subroutine = ifc->attr.subroutine; |
236 | |
237 | sym->attr.pure = ifc->attr.pure; |
238 | sym->attr.elemental = ifc->attr.elemental; |
239 | sym->attr.contiguous = ifc->attr.contiguous; |
240 | sym->attr.recursive = ifc->attr.recursive; |
241 | sym->attr.always_explicit = ifc->attr.always_explicit; |
242 | sym->attr.ext_attr |= ifc->attr.ext_attr; |
243 | sym->attr.is_bind_c = ifc->attr.is_bind_c; |
244 | /* Copy char length. */ |
245 | if (ifc->ts.type == BT_CHARACTER && ifc->ts.u.cl) |
246 | { |
247 | sym->ts.u.cl = gfc_new_charlen (sym->ns, ifc->ts.u.cl); |
248 | if (sym->ts.u.cl->length && !sym->ts.u.cl->resolved |
249 | && !gfc_resolve_expr (sym->ts.u.cl->length)) |
250 | return false; |
251 | } |
252 | } |
253 | |
254 | return true; |
255 | } |
256 | |
257 | |
258 | /* Resolve types of formal argument lists. These have to be done early so that |
259 | the formal argument lists of module procedures can be copied to the |
260 | containing module before the individual procedures are resolved |
261 | individually. We also resolve argument lists of procedures in interface |
262 | blocks because they are self-contained scoping units. |
263 | |
264 | Since a dummy argument cannot be a non-dummy procedure, the only |
265 | resort left for untyped names are the IMPLICIT types. */ |
266 | |
267 | void |
268 | gfc_resolve_formal_arglist (gfc_symbol *proc) |
269 | { |
270 | gfc_formal_arglist *f; |
271 | gfc_symbol *sym; |
272 | bool saved_specification_expr; |
273 | int i; |
274 | |
275 | if (proc->result != NULL__null) |
276 | sym = proc->result; |
277 | else |
278 | sym = proc; |
279 | |
280 | if (gfc_elemental (proc) |
281 | || sym->attr.pointer || sym->attr.allocatable |
282 | || (sym->as && sym->as->rank != 0)) |
283 | { |
284 | proc->attr.always_explicit = 1; |
285 | sym->attr.always_explicit = 1; |
286 | } |
287 | |
288 | formal_arg_flag = true; |
289 | |
290 | for (f = proc->formal; f; f = f->next) |
291 | { |
292 | gfc_array_spec *as; |
293 | |
294 | sym = f->sym; |
295 | |
296 | if (sym == NULL__null) |
297 | { |
298 | /* Alternate return placeholder. */ |
299 | if (gfc_elemental (proc)) |
300 | gfc_error ("Alternate return specifier in elemental subroutine " |
301 | "%qs at %L is not allowed", proc->name, |
302 | &proc->declared_at); |
303 | if (proc->attr.function) |
304 | gfc_error ("Alternate return specifier in function " |
305 | "%qs at %L is not allowed", proc->name, |
306 | &proc->declared_at); |
307 | continue; |
308 | } |
309 | else if (sym->attr.procedure && sym->attr.if_source != IFSRC_DECL |
310 | && !resolve_procedure_interface (sym)) |
311 | return; |
312 | |
313 | if (strcmp (proc->name, sym->name) == 0) |
314 | { |
315 | gfc_error ("Self-referential argument " |
316 | "%qs at %L is not allowed", sym->name, |
317 | &proc->declared_at); |
318 | return; |
319 | } |
320 | |
321 | if (sym->attr.if_source != IFSRC_UNKNOWN) |
322 | gfc_resolve_formal_arglist (sym); |
323 | |
324 | if (sym->attr.subroutine || sym->attr.external) |
325 | { |
326 | if (sym->attr.flavor == FL_UNKNOWN) |
327 | gfc_add_flavor (&sym->attr, FL_PROCEDURE, sym->name, &sym->declared_at); |
328 | } |
329 | else |
330 | { |
331 | if (sym->ts.type == BT_UNKNOWN && !proc->attr.intrinsic |
332 | && (!sym->attr.function || sym->result == sym)) |
333 | gfc_set_default_type (sym, 1, sym->ns); |
334 | } |
335 | |
336 | as = sym->ts.type == BT_CLASS && sym->attr.class_ok |
337 | ? CLASS_DATA (sym)sym->ts.u.derived->components->as : sym->as; |
338 | |
339 | saved_specification_expr = specification_expr; |
340 | specification_expr = true; |
341 | gfc_resolve_array_spec (as, 0); |
342 | specification_expr = saved_specification_expr; |
343 | |
344 | /* We can't tell if an array with dimension (:) is assumed or deferred |
345 | shape until we know if it has the pointer or allocatable attributes. |
346 | */ |
347 | if (as && as->rank > 0 && as->type == AS_DEFERRED |
348 | && ((sym->ts.type != BT_CLASS |
349 | && !(sym->attr.pointer || sym->attr.allocatable)) |
350 | || (sym->ts.type == BT_CLASS |
351 | && !(CLASS_DATA (sym)sym->ts.u.derived->components->attr.class_pointer |
352 | || CLASS_DATA (sym)sym->ts.u.derived->components->attr.allocatable))) |
353 | && sym->attr.flavor != FL_PROCEDURE) |
354 | { |
355 | as->type = AS_ASSUMED_SHAPE; |
356 | for (i = 0; i < as->rank; i++) |
357 | as->lower[i] = gfc_get_int_expr (gfc_default_integer_kind, NULL__null, 1); |
358 | } |
359 | |
360 | if ((as && as->rank > 0 && as->type == AS_ASSUMED_SHAPE) |
361 | || (as && as->type == AS_ASSUMED_RANK) |
362 | || sym->attr.pointer || sym->attr.allocatable || sym->attr.target |
363 | || (sym->ts.type == BT_CLASS && sym->attr.class_ok |
364 | && (CLASS_DATA (sym)sym->ts.u.derived->components->attr.class_pointer |
365 | || CLASS_DATA (sym)sym->ts.u.derived->components->attr.allocatable |
366 | || CLASS_DATA (sym)sym->ts.u.derived->components->attr.target)) |
367 | || sym->attr.optional) |
368 | { |
369 | proc->attr.always_explicit = 1; |
370 | if (proc->result) |
371 | proc->result->attr.always_explicit = 1; |
372 | } |
373 | |
374 | /* If the flavor is unknown at this point, it has to be a variable. |
375 | A procedure specification would have already set the type. */ |
376 | |
377 | if (sym->attr.flavor == FL_UNKNOWN) |
378 | gfc_add_flavor (&sym->attr, FL_VARIABLE, sym->name, &sym->declared_at); |
379 | |
380 | if (gfc_pure (proc)) |
381 | { |
382 | if (sym->attr.flavor == FL_PROCEDURE) |
383 | { |
384 | /* F08:C1279. */ |
385 | if (!gfc_pure (sym)) |
386 | { |
387 | gfc_error ("Dummy procedure %qs of PURE procedure at %L must " |
388 | "also be PURE", sym->name, &sym->declared_at); |
389 | continue; |
390 | } |
391 | } |
392 | else if (!sym->attr.pointer) |
393 | { |
394 | if (proc->attr.function && sym->attr.intent != INTENT_IN) |
395 | { |
396 | if (sym->attr.value) |
397 | gfc_notify_std (GFC_STD_F2008(1<<7), "Argument %qs" |
398 | " of pure function %qs at %L with VALUE " |
399 | "attribute but without INTENT(IN)", |
400 | sym->name, proc->name, &sym->declared_at); |
401 | else |
402 | gfc_error ("Argument %qs of pure function %qs at %L must " |
403 | "be INTENT(IN) or VALUE", sym->name, proc->name, |
404 | &sym->declared_at); |
405 | } |
406 | |
407 | if (proc->attr.subroutine && sym->attr.intent == INTENT_UNKNOWN) |
408 | { |
409 | if (sym->attr.value) |
410 | gfc_notify_std (GFC_STD_F2008(1<<7), "Argument %qs" |
411 | " of pure subroutine %qs at %L with VALUE " |
412 | "attribute but without INTENT", sym->name, |
413 | proc->name, &sym->declared_at); |
414 | else |
415 | gfc_error ("Argument %qs of pure subroutine %qs at %L " |
416 | "must have its INTENT specified or have the " |
417 | "VALUE attribute", sym->name, proc->name, |
418 | &sym->declared_at); |
419 | } |
420 | } |
421 | |
422 | /* F08:C1278a. */ |
423 | if (sym->ts.type == BT_CLASS && sym->attr.intent == INTENT_OUT) |
424 | { |
425 | gfc_error ("INTENT(OUT) argument %qs of pure procedure %qs at %L" |
426 | " may not be polymorphic", sym->name, proc->name, |
427 | &sym->declared_at); |
428 | continue; |
429 | } |
430 | } |
431 | |
432 | if (proc->attr.implicit_pure) |
433 | { |
434 | if (sym->attr.flavor == FL_PROCEDURE) |
435 | { |
436 | if (!gfc_pure (sym)) |
437 | proc->attr.implicit_pure = 0; |
438 | } |
439 | else if (!sym->attr.pointer) |
440 | { |
441 | if (proc->attr.function && sym->attr.intent != INTENT_IN |
442 | && !sym->value) |
443 | proc->attr.implicit_pure = 0; |
444 | |
445 | if (proc->attr.subroutine && sym->attr.intent == INTENT_UNKNOWN |
446 | && !sym->value) |
447 | proc->attr.implicit_pure = 0; |
448 | } |
449 | } |
450 | |
451 | if (gfc_elemental (proc)) |
452 | { |
453 | /* F08:C1289. */ |
454 | if (sym->attr.codimension |
455 | || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)sym->ts.u.derived->components |
456 | && CLASS_DATA (sym)sym->ts.u.derived->components->attr.codimension)) |
457 | { |
458 | gfc_error ("Coarray dummy argument %qs at %L to elemental " |
459 | "procedure", sym->name, &sym->declared_at); |
460 | continue; |
461 | } |
462 | |
463 | if (sym->as || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)sym->ts.u.derived->components |
464 | && CLASS_DATA (sym)sym->ts.u.derived->components->as)) |
465 | { |
466 | gfc_error ("Argument %qs of elemental procedure at %L must " |
467 | "be scalar", sym->name, &sym->declared_at); |
468 | continue; |
469 | } |
470 | |
471 | if (sym->attr.allocatable |
472 | || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)sym->ts.u.derived->components |
473 | && CLASS_DATA (sym)sym->ts.u.derived->components->attr.allocatable)) |
474 | { |
475 | gfc_error ("Argument %qs of elemental procedure at %L cannot " |
476 | "have the ALLOCATABLE attribute", sym->name, |
477 | &sym->declared_at); |
478 | continue; |
479 | } |
480 | |
481 | if (sym->attr.pointer |
482 | || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)sym->ts.u.derived->components |
483 | && CLASS_DATA (sym)sym->ts.u.derived->components->attr.class_pointer)) |
484 | { |
485 | gfc_error ("Argument %qs of elemental procedure at %L cannot " |
486 | "have the POINTER attribute", sym->name, |
487 | &sym->declared_at); |
488 | continue; |
489 | } |
490 | |
491 | if (sym->attr.flavor == FL_PROCEDURE) |
492 | { |
493 | gfc_error ("Dummy procedure %qs not allowed in elemental " |
494 | "procedure %qs at %L", sym->name, proc->name, |
495 | &sym->declared_at); |
496 | continue; |
497 | } |
498 | |
499 | /* Fortran 2008 Corrigendum 1, C1290a. */ |
500 | if (sym->attr.intent == INTENT_UNKNOWN && !sym->attr.value) |
501 | { |
502 | gfc_error ("Argument %qs of elemental procedure %qs at %L must " |
503 | "have its INTENT specified or have the VALUE " |
504 | "attribute", sym->name, proc->name, |
505 | &sym->declared_at); |
506 | continue; |
507 | } |
508 | } |
509 | |
510 | /* Each dummy shall be specified to be scalar. */ |
511 | if (proc->attr.proc == PROC_ST_FUNCTION) |
512 | { |
513 | if (sym->as != NULL__null) |
514 | { |
515 | /* F03:C1263 (R1238) The function-name and each dummy-arg-name |
516 | shall be specified, explicitly or implicitly, to be scalar. */ |
517 | gfc_error ("Argument %qs of statement function %qs at %L " |
518 | "must be scalar", sym->name, proc->name, |
519 | &proc->declared_at); |
520 | continue; |
521 | } |
522 | |
523 | if (sym->ts.type == BT_CHARACTER) |
524 | { |
525 | gfc_charlen *cl = sym->ts.u.cl; |
526 | if (!cl || !cl->length || cl->length->expr_type != EXPR_CONSTANT) |
527 | { |
528 | gfc_error ("Character-valued argument %qs of statement " |
529 | "function at %L must have constant length", |
530 | sym->name, &sym->declared_at); |
531 | continue; |
532 | } |
533 | } |
534 | } |
535 | } |
536 | formal_arg_flag = false; |
537 | } |
538 | |
539 | |
540 | /* Work function called when searching for symbols that have argument lists |
541 | associated with them. */ |
542 | |
543 | static void |
544 | find_arglists (gfc_symbol *sym) |
545 | { |
546 | if (sym->attr.if_source == IFSRC_UNKNOWN || sym->ns != gfc_current_ns |
547 | || gfc_fl_struct (sym->attr.flavor)((sym->attr.flavor) == FL_DERIVED || (sym->attr.flavor) == FL_UNION || (sym->attr.flavor) == FL_STRUCT) || sym->attr.intrinsic) |
548 | return; |
549 | |
550 | gfc_resolve_formal_arglist (sym); |
551 | } |
552 | |
553 | |
554 | /* Given a namespace, resolve all formal argument lists within the namespace. |
555 | */ |
556 | |
557 | static void |
558 | resolve_formal_arglists (gfc_namespace *ns) |
559 | { |
560 | if (ns == NULL__null) |
561 | return; |
562 | |
563 | gfc_traverse_ns (ns, find_arglists); |
564 | } |
565 | |
566 | |
567 | static void |
568 | resolve_contained_fntype (gfc_symbol *sym, gfc_namespace *ns) |
569 | { |
570 | bool t; |
571 | |
572 | if (sym && sym->attr.flavor == FL_PROCEDURE |
573 | && sym->ns->parent |
574 | && sym->ns->parent->proc_name |
575 | && sym->ns->parent->proc_name->attr.flavor == FL_PROCEDURE |
576 | && !strcmp (sym->name, sym->ns->parent->proc_name->name)) |
577 | gfc_error ("Contained procedure %qs at %L has the same name as its " |
578 | "encompassing procedure", sym->name, &sym->declared_at); |
579 | |
580 | /* If this namespace is not a function or an entry master function, |
581 | ignore it. */ |
582 | if (! sym || !(sym->attr.function || sym->attr.flavor == FL_VARIABLE) |
583 | || sym->attr.entry_master) |
584 | return; |
585 | |
586 | if (!sym->result) |
587 | return; |
588 | |
589 | /* Try to find out of what the return type is. */ |
590 | if (sym->result->ts.type == BT_UNKNOWN && sym->result->ts.interface == NULL__null) |
591 | { |
592 | t = gfc_set_default_type (sym->result, 0, ns); |
593 | |
594 | if (!t && !sym->result->attr.untyped) |
595 | { |
596 | if (sym->result == sym) |
597 | gfc_error ("Contained function %qs at %L has no IMPLICIT type", |
598 | sym->name, &sym->declared_at); |
599 | else if (!sym->result->attr.proc_pointer) |
600 | gfc_error ("Result %qs of contained function %qs at %L has " |
601 | "no IMPLICIT type", sym->result->name, sym->name, |
602 | &sym->result->declared_at); |
603 | sym->result->attr.untyped = 1; |
604 | } |
605 | } |
606 | |
607 | /* Fortran 2008 Draft Standard, page 535, C418, on type-param-value |
608 | type, lists the only ways a character length value of * can be used: |
609 | dummy arguments of procedures, named constants, function results and |
610 | in allocate statements if the allocate_object is an assumed length dummy |
611 | in external functions. Internal function results and results of module |
612 | procedures are not on this list, ergo, not permitted. */ |
613 | |
614 | if (sym->result->ts.type == BT_CHARACTER) |
615 | { |
616 | gfc_charlen *cl = sym->result->ts.u.cl; |
617 | if ((!cl || !cl->length) && !sym->result->ts.deferred) |
618 | { |
619 | /* See if this is a module-procedure and adapt error message |
620 | accordingly. */ |
621 | bool module_proc; |
622 | gcc_assert (ns->parent && ns->parent->proc_name)((void)(!(ns->parent && ns->parent->proc_name ) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 622, __FUNCTION__), 0 : 0)); |
623 | module_proc = (ns->parent->proc_name->attr.flavor == FL_MODULE); |
624 | |
625 | gfc_error (module_proc |
626 | ? G_("Character-valued module procedure %qs at %L""Character-valued module procedure %qs at %L" " must not be assumed length" |
627 | " must not be assumed length")"Character-valued module procedure %qs at %L" " must not be assumed length" |
628 | : G_("Character-valued internal function %qs at %L""Character-valued internal function %qs at %L" " must not be assumed length" |
629 | " must not be assumed length")"Character-valued internal function %qs at %L" " must not be assumed length", |
630 | sym->name, &sym->declared_at); |
631 | } |
632 | } |
633 | } |
634 | |
635 | |
636 | /* Add NEW_ARGS to the formal argument list of PROC, taking care not to |
637 | introduce duplicates. */ |
638 | |
639 | static void |
640 | merge_argument_lists (gfc_symbol *proc, gfc_formal_arglist *new_args) |
641 | { |
642 | gfc_formal_arglist *f, *new_arglist; |
643 | gfc_symbol *new_sym; |
644 | |
645 | for (; new_args != NULL__null; new_args = new_args->next) |
646 | { |
647 | new_sym = new_args->sym; |
648 | /* See if this arg is already in the formal argument list. */ |
649 | for (f = proc->formal; f; f = f->next) |
650 | { |
651 | if (new_sym == f->sym) |
652 | break; |
653 | } |
654 | |
655 | if (f) |
656 | continue; |
657 | |
658 | /* Add a new argument. Argument order is not important. */ |
659 | new_arglist = gfc_get_formal_arglist ()((gfc_formal_arglist *) xcalloc (1, sizeof (gfc_formal_arglist ))); |
660 | new_arglist->sym = new_sym; |
661 | new_arglist->next = proc->formal; |
662 | proc->formal = new_arglist; |
663 | } |
664 | } |
665 | |
666 | |
667 | /* Flag the arguments that are not present in all entries. */ |
668 | |
669 | static void |
670 | check_argument_lists (gfc_symbol *proc, gfc_formal_arglist *new_args) |
671 | { |
672 | gfc_formal_arglist *f, *head; |
673 | head = new_args; |
674 | |
675 | for (f = proc->formal; f; f = f->next) |
676 | { |
677 | if (f->sym == NULL__null) |
678 | continue; |
679 | |
680 | for (new_args = head; new_args; new_args = new_args->next) |
681 | { |
682 | if (new_args->sym == f->sym) |
683 | break; |
684 | } |
685 | |
686 | if (new_args) |
687 | continue; |
688 | |
689 | f->sym->attr.not_always_present = 1; |
690 | } |
691 | } |
692 | |
693 | |
694 | /* Resolve alternate entry points. If a symbol has multiple entry points we |
695 | create a new master symbol for the main routine, and turn the existing |
696 | symbol into an entry point. */ |
697 | |
698 | static void |
699 | resolve_entries (gfc_namespace *ns) |
700 | { |
701 | gfc_namespace *old_ns; |
702 | gfc_code *c; |
703 | gfc_symbol *proc; |
704 | gfc_entry_list *el; |
705 | char name[GFC_MAX_SYMBOL_LEN63 + 1]; |
706 | static int master_count = 0; |
707 | |
708 | if (ns->proc_name == NULL__null) |
709 | return; |
710 | |
711 | /* No need to do anything if this procedure doesn't have alternate entry |
712 | points. */ |
713 | if (!ns->entries) |
714 | return; |
715 | |
716 | /* We may already have resolved alternate entry points. */ |
717 | if (ns->proc_name->attr.entry_master) |
718 | return; |
719 | |
720 | /* If this isn't a procedure something has gone horribly wrong. */ |
721 | gcc_assert (ns->proc_name->attr.flavor == FL_PROCEDURE)((void)(!(ns->proc_name->attr.flavor == FL_PROCEDURE) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 721, __FUNCTION__), 0 : 0)); |
722 | |
723 | /* Remember the current namespace. */ |
724 | old_ns = gfc_current_ns; |
725 | |
726 | gfc_current_ns = ns; |
727 | |
728 | /* Add the main entry point to the list of entry points. */ |
729 | el = gfc_get_entry_list ()((gfc_entry_list *) xcalloc (1, sizeof (gfc_entry_list))); |
730 | el->sym = ns->proc_name; |
731 | el->id = 0; |
732 | el->next = ns->entries; |
733 | ns->entries = el; |
734 | ns->proc_name->attr.entry = 1; |
735 | |
736 | /* If it is a module function, it needs to be in the right namespace |
737 | so that gfc_get_fake_result_decl can gather up the results. The |
738 | need for this arose in get_proc_name, where these beasts were |
739 | left in their own namespace, to keep prior references linked to |
740 | the entry declaration.*/ |
741 | if (ns->proc_name->attr.function |
742 | && ns->parent && ns->parent->proc_name->attr.flavor == FL_MODULE) |
743 | el->sym->ns = ns; |
744 | |
745 | /* Do the same for entries where the master is not a module |
746 | procedure. These are retained in the module namespace because |
747 | of the module procedure declaration. */ |
748 | for (el = el->next; el; el = el->next) |
749 | if (el->sym->ns->proc_name->attr.flavor == FL_MODULE |
750 | && el->sym->attr.mod_proc) |
751 | el->sym->ns = ns; |
752 | el = ns->entries; |
753 | |
754 | /* Add an entry statement for it. */ |
755 | c = gfc_get_code (EXEC_ENTRY); |
756 | c->ext.entry = el; |
757 | c->next = ns->code; |
758 | ns->code = c; |
759 | |
760 | /* Create a new symbol for the master function. */ |
761 | /* Give the internal function a unique name (within this file). |
762 | Also include the function name so the user has some hope of figuring |
763 | out what is going on. */ |
764 | snprintf (name, GFC_MAX_SYMBOL_LEN63, "master.%d.%s", |
765 | master_count++, ns->proc_name->name); |
766 | gfc_get_ha_symbol (name, &proc); |
767 | gcc_assert (proc != NULL)((void)(!(proc != __null) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 767, __FUNCTION__), 0 : 0)); |
768 | |
769 | gfc_add_procedure (&proc->attr, PROC_INTERNAL, proc->name, NULL__null); |
770 | if (ns->proc_name->attr.subroutine) |
771 | gfc_add_subroutine (&proc->attr, proc->name, NULL__null); |
772 | else |
773 | { |
774 | gfc_symbol *sym; |
775 | gfc_typespec *ts, *fts; |
776 | gfc_array_spec *as, *fas; |
777 | gfc_add_function (&proc->attr, proc->name, NULL__null); |
778 | proc->result = proc; |
779 | fas = ns->entries->sym->as; |
780 | fas = fas ? fas : ns->entries->sym->result->as; |
781 | fts = &ns->entries->sym->result->ts; |
782 | if (fts->type == BT_UNKNOWN) |
783 | fts = gfc_get_default_type (ns->entries->sym->result->name, NULL__null); |
784 | for (el = ns->entries->next; el; el = el->next) |
785 | { |
786 | ts = &el->sym->result->ts; |
787 | as = el->sym->as; |
788 | as = as ? as : el->sym->result->as; |
789 | if (ts->type == BT_UNKNOWN) |
790 | ts = gfc_get_default_type (el->sym->result->name, NULL__null); |
791 | |
792 | if (! gfc_compare_types (ts, fts) |
793 | || (el->sym->result->attr.dimension |
794 | != ns->entries->sym->result->attr.dimension) |
795 | || (el->sym->result->attr.pointer |
796 | != ns->entries->sym->result->attr.pointer)) |
797 | break; |
798 | else if (as && fas && ns->entries->sym->result != el->sym->result |
799 | && gfc_compare_array_spec (as, fas) == 0) |
800 | gfc_error ("Function %s at %L has entries with mismatched " |
801 | "array specifications", ns->entries->sym->name, |
802 | &ns->entries->sym->declared_at); |
803 | /* The characteristics need to match and thus both need to have |
804 | the same string length, i.e. both len=*, or both len=4. |
805 | Having both len=<variable> is also possible, but difficult to |
806 | check at compile time. */ |
807 | else if (ts->type == BT_CHARACTER |
808 | && (el->sym->result->attr.allocatable |
809 | != ns->entries->sym->result->attr.allocatable)) |
810 | { |
811 | gfc_error ("Function %s at %L has entry %s with mismatched " |
812 | "characteristics", ns->entries->sym->name, |
813 | &ns->entries->sym->declared_at, el->sym->name); |
814 | goto cleanup; |
815 | } |
816 | else if (ts->type == BT_CHARACTER && ts->u.cl && fts->u.cl |
817 | && (((ts->u.cl->length && !fts->u.cl->length) |
818 | ||(!ts->u.cl->length && fts->u.cl->length)) |
819 | || (ts->u.cl->length |
820 | && ts->u.cl->length->expr_type |
821 | != fts->u.cl->length->expr_type) |
822 | || (ts->u.cl->length |
823 | && ts->u.cl->length->expr_type == EXPR_CONSTANT |
824 | && mpz_cmp__gmpz_cmp (ts->u.cl->length->value.integer, |
825 | fts->u.cl->length->value.integer) != 0))) |
826 | gfc_notify_std (GFC_STD_GNU(1<<5), "Function %s at %L with " |
827 | "entries returning variables of different " |
828 | "string lengths", ns->entries->sym->name, |
829 | &ns->entries->sym->declared_at); |
830 | } |
831 | |
832 | if (el == NULL__null) |
833 | { |
834 | sym = ns->entries->sym->result; |
835 | /* All result types the same. */ |
836 | proc->ts = *fts; |
837 | if (sym->attr.dimension) |
838 | gfc_set_array_spec (proc, gfc_copy_array_spec (sym->as), NULL__null); |
839 | if (sym->attr.pointer) |
840 | gfc_add_pointer (&proc->attr, NULL__null); |
841 | } |
842 | else |
843 | { |
844 | /* Otherwise the result will be passed through a union by |
845 | reference. */ |
846 | proc->attr.mixed_entry_master = 1; |
847 | for (el = ns->entries; el; el = el->next) |
848 | { |
849 | sym = el->sym->result; |
850 | if (sym->attr.dimension) |
851 | { |
852 | if (el == ns->entries) |
853 | gfc_error ("FUNCTION result %s cannot be an array in " |
854 | "FUNCTION %s at %L", sym->name, |
855 | ns->entries->sym->name, &sym->declared_at); |
856 | else |
857 | gfc_error ("ENTRY result %s cannot be an array in " |
858 | "FUNCTION %s at %L", sym->name, |
859 | ns->entries->sym->name, &sym->declared_at); |
860 | } |
861 | else if (sym->attr.pointer) |
862 | { |
863 | if (el == ns->entries) |
864 | gfc_error ("FUNCTION result %s cannot be a POINTER in " |
865 | "FUNCTION %s at %L", sym->name, |
866 | ns->entries->sym->name, &sym->declared_at); |
867 | else |
868 | gfc_error ("ENTRY result %s cannot be a POINTER in " |
869 | "FUNCTION %s at %L", sym->name, |
870 | ns->entries->sym->name, &sym->declared_at); |
871 | } |
872 | else |
873 | { |
874 | ts = &sym->ts; |
875 | if (ts->type == BT_UNKNOWN) |
876 | ts = gfc_get_default_type (sym->name, NULL__null); |
877 | switch (ts->type) |
878 | { |
879 | case BT_INTEGER: |
880 | if (ts->kind == gfc_default_integer_kind) |
881 | sym = NULL__null; |
882 | break; |
883 | case BT_REAL: |
884 | if (ts->kind == gfc_default_real_kind |
885 | || ts->kind == gfc_default_double_kind) |
886 | sym = NULL__null; |
887 | break; |
888 | case BT_COMPLEX: |
889 | if (ts->kind == gfc_default_complex_kind) |
890 | sym = NULL__null; |
891 | break; |
892 | case BT_LOGICAL: |
893 | if (ts->kind == gfc_default_logical_kind) |
894 | sym = NULL__null; |
895 | break; |
896 | case BT_UNKNOWN: |
897 | /* We will issue error elsewhere. */ |
898 | sym = NULL__null; |
899 | break; |
900 | default: |
901 | break; |
902 | } |
903 | if (sym) |
904 | { |
905 | if (el == ns->entries) |
906 | gfc_error ("FUNCTION result %s cannot be of type %s " |
907 | "in FUNCTION %s at %L", sym->name, |
908 | gfc_typename (ts), ns->entries->sym->name, |
909 | &sym->declared_at); |
910 | else |
911 | gfc_error ("ENTRY result %s cannot be of type %s " |
912 | "in FUNCTION %s at %L", sym->name, |
913 | gfc_typename (ts), ns->entries->sym->name, |
914 | &sym->declared_at); |
915 | } |
916 | } |
917 | } |
918 | } |
919 | } |
920 | |
921 | cleanup: |
922 | proc->attr.access = ACCESS_PRIVATE; |
923 | proc->attr.entry_master = 1; |
924 | |
925 | /* Merge all the entry point arguments. */ |
926 | for (el = ns->entries; el; el = el->next) |
927 | merge_argument_lists (proc, el->sym->formal); |
928 | |
929 | /* Check the master formal arguments for any that are not |
930 | present in all entry points. */ |
931 | for (el = ns->entries; el; el = el->next) |
932 | check_argument_lists (proc, el->sym->formal); |
933 | |
934 | /* Use the master function for the function body. */ |
935 | ns->proc_name = proc; |
936 | |
937 | /* Finalize the new symbols. */ |
938 | gfc_commit_symbols (); |
939 | |
940 | /* Restore the original namespace. */ |
941 | gfc_current_ns = old_ns; |
942 | } |
943 | |
944 | |
945 | /* Resolve common variables. */ |
946 | static void |
947 | resolve_common_vars (gfc_common_head *common_block, bool named_common) |
948 | { |
949 | gfc_symbol *csym = common_block->head; |
950 | gfc_gsymbol *gsym; |
951 | |
952 | for (; csym; csym = csym->common_next) |
953 | { |
954 | gsym = gfc_find_gsymbol (gfc_gsym_root, csym->name); |
955 | if (gsym && (gsym->type == GSYM_MODULE || gsym->type == GSYM_PROGRAM)) |
956 | { |
957 | if (csym->common_block) |
958 | gfc_error_now ("Global entity %qs at %L cannot appear in a " |
959 | "COMMON block at %L", gsym->name, |
960 | &gsym->where, &csym->common_block->where); |
961 | else |
962 | gfc_error_now ("Global entity %qs at %L cannot appear in a " |
963 | "COMMON block", gsym->name, &gsym->where); |
964 | } |
965 | |
966 | /* gfc_add_in_common may have been called before, but the reported errors |
967 | have been ignored to continue parsing. |
968 | We do the checks again here. */ |
969 | if (!csym->attr.use_assoc) |
970 | { |
971 | gfc_add_in_common (&csym->attr, csym->name, &common_block->where); |
972 | gfc_notify_std (GFC_STD_F2018_OBS(1<<10), "COMMON block at %L", |
973 | &common_block->where); |
974 | } |
975 | |
976 | if (csym->value || csym->attr.data) |
977 | { |
978 | if (!csym->ns->is_block_data) |
979 | gfc_notify_std (GFC_STD_GNU(1<<5), "Variable %qs at %L is in COMMON " |
980 | "but only in BLOCK DATA initialization is " |
981 | "allowed", csym->name, &csym->declared_at); |
982 | else if (!named_common) |
983 | gfc_notify_std (GFC_STD_GNU(1<<5), "Initialized variable %qs at %L is " |
984 | "in a blank COMMON but initialization is only " |
985 | "allowed in named common blocks", csym->name, |
986 | &csym->declared_at); |
987 | } |
988 | |
989 | if (UNLIMITED_POLY (csym)(csym != __null && csym->ts.type == BT_CLASS && csym->ts.u.derived->components && csym->ts. u.derived->components->ts.u.derived && csym-> ts.u.derived->components->ts.u.derived->attr.unlimited_polymorphic )) |
990 | gfc_error_now ("%qs at %L cannot appear in COMMON " |
991 | "[F2008:C5100]", csym->name, &csym->declared_at); |
992 | |
993 | if (csym->ts.type != BT_DERIVED) |
994 | continue; |
995 | |
996 | if (!(csym->ts.u.derived->attr.sequence |
997 | || csym->ts.u.derived->attr.is_bind_c)) |
998 | gfc_error_now ("Derived type variable %qs in COMMON at %L " |
999 | "has neither the SEQUENCE nor the BIND(C) " |
1000 | "attribute", csym->name, &csym->declared_at); |
1001 | if (csym->ts.u.derived->attr.alloc_comp) |
1002 | gfc_error_now ("Derived type variable %qs in COMMON at %L " |
1003 | "has an ultimate component that is " |
1004 | "allocatable", csym->name, &csym->declared_at); |
1005 | if (gfc_has_default_initializer (csym->ts.u.derived)) |
1006 | gfc_error_now ("Derived type variable %qs in COMMON at %L " |
1007 | "may not have default initializer", csym->name, |
1008 | &csym->declared_at); |
1009 | |
1010 | if (csym->attr.flavor == FL_UNKNOWN && !csym->attr.proc_pointer) |
1011 | gfc_add_flavor (&csym->attr, FL_VARIABLE, csym->name, &csym->declared_at); |
1012 | } |
1013 | } |
1014 | |
1015 | /* Resolve common blocks. */ |
1016 | static void |
1017 | resolve_common_blocks (gfc_symtree *common_root) |
1018 | { |
1019 | gfc_symbol *sym; |
1020 | gfc_gsymbol * gsym; |
1021 | |
1022 | if (common_root == NULL__null) |
1023 | return; |
1024 | |
1025 | if (common_root->left) |
1026 | resolve_common_blocks (common_root->left); |
1027 | if (common_root->right) |
1028 | resolve_common_blocks (common_root->right); |
1029 | |
1030 | resolve_common_vars (common_root->n.common, true); |
1031 | |
1032 | /* The common name is a global name - in Fortran 2003 also if it has a |
1033 | C binding name, since Fortran 2008 only the C binding name is a global |
1034 | identifier. */ |
1035 | if (!common_root->n.common->binding_label |
1036 | || gfc_notification_std (GFC_STD_F2008(1<<7))) |
1037 | { |
1038 | gsym = gfc_find_gsymbol (gfc_gsym_root, |
1039 | common_root->n.common->name); |
1040 | |
1041 | if (gsym && gfc_notification_std (GFC_STD_F2008(1<<7)) |
1042 | && gsym->type == GSYM_COMMON |
1043 | && ((common_root->n.common->binding_label |
1044 | && (!gsym->binding_label |
1045 | || strcmp (common_root->n.common->binding_label, |
1046 | gsym->binding_label) != 0)) |
1047 | || (!common_root->n.common->binding_label |
1048 | && gsym->binding_label))) |
1049 | { |
1050 | gfc_error ("In Fortran 2003 COMMON %qs block at %L is a global " |
1051 | "identifier and must thus have the same binding name " |
1052 | "as the same-named COMMON block at %L: %s vs %s", |
1053 | common_root->n.common->name, &common_root->n.common->where, |
1054 | &gsym->where, |
1055 | common_root->n.common->binding_label |
1056 | ? common_root->n.common->binding_label : "(blank)", |
1057 | gsym->binding_label ? gsym->binding_label : "(blank)"); |
1058 | return; |
1059 | } |
1060 | |
1061 | if (gsym && gsym->type != GSYM_COMMON |
1062 | && !common_root->n.common->binding_label) |
1063 | { |
1064 | gfc_error ("COMMON block %qs at %L uses the same global identifier " |
1065 | "as entity at %L", |
1066 | common_root->n.common->name, &common_root->n.common->where, |
1067 | &gsym->where); |
1068 | return; |
1069 | } |
1070 | if (gsym && gsym->type != GSYM_COMMON) |
1071 | { |
1072 | gfc_error ("Fortran 2008: COMMON block %qs with binding label at " |
1073 | "%L sharing the identifier with global non-COMMON-block " |
1074 | "entity at %L", common_root->n.common->name, |
1075 | &common_root->n.common->where, &gsym->where); |
1076 | return; |
1077 | } |
1078 | if (!gsym) |
1079 | { |
1080 | gsym = gfc_get_gsymbol (common_root->n.common->name, false); |
1081 | gsym->type = GSYM_COMMON; |
1082 | gsym->where = common_root->n.common->where; |
1083 | gsym->defined = 1; |
1084 | } |
1085 | gsym->used = 1; |
1086 | } |
1087 | |
1088 | if (common_root->n.common->binding_label) |
1089 | { |
1090 | gsym = gfc_find_gsymbol (gfc_gsym_root, |
1091 | common_root->n.common->binding_label); |
1092 | if (gsym && gsym->type != GSYM_COMMON) |
1093 | { |
1094 | gfc_error ("COMMON block at %L with binding label %qs uses the same " |
1095 | "global identifier as entity at %L", |
1096 | &common_root->n.common->where, |
1097 | common_root->n.common->binding_label, &gsym->where); |
1098 | return; |
1099 | } |
1100 | if (!gsym) |
1101 | { |
1102 | gsym = gfc_get_gsymbol (common_root->n.common->binding_label, true); |
1103 | gsym->type = GSYM_COMMON; |
1104 | gsym->where = common_root->n.common->where; |
1105 | gsym->defined = 1; |
1106 | } |
1107 | gsym->used = 1; |
1108 | } |
1109 | |
1110 | gfc_find_symbol (common_root->name, gfc_current_ns, 0, &sym); |
1111 | if (sym == NULL__null) |
1112 | return; |
1113 | |
1114 | if (sym->attr.flavor == FL_PARAMETER) |
1115 | gfc_error ("COMMON block %qs at %L is used as PARAMETER at %L", |
1116 | sym->name, &common_root->n.common->where, &sym->declared_at); |
1117 | |
1118 | if (sym->attr.external) |
1119 | gfc_error ("COMMON block %qs at %L cannot have the EXTERNAL attribute", |
1120 | sym->name, &common_root->n.common->where); |
1121 | |
1122 | if (sym->attr.intrinsic) |
1123 | gfc_error ("COMMON block %qs at %L is also an intrinsic procedure", |
1124 | sym->name, &common_root->n.common->where); |
1125 | else if (sym->attr.result |
1126 | || gfc_is_function_return_value (sym, gfc_current_ns)) |
1127 | gfc_notify_std (GFC_STD_F2003(1<<4), "COMMON block %qs at %L " |
1128 | "that is also a function result", sym->name, |
1129 | &common_root->n.common->where); |
1130 | else if (sym->attr.flavor == FL_PROCEDURE && sym->attr.proc != PROC_INTERNAL |
1131 | && sym->attr.proc != PROC_ST_FUNCTION) |
1132 | gfc_notify_std (GFC_STD_F2003(1<<4), "COMMON block %qs at %L " |
1133 | "that is also a global procedure", sym->name, |
1134 | &common_root->n.common->where); |
1135 | } |
1136 | |
1137 | |
1138 | /* Resolve contained function types. Because contained functions can call one |
1139 | another, they have to be worked out before any of the contained procedures |
1140 | can be resolved. |
1141 | |
1142 | The good news is that if a function doesn't already have a type, the only |
1143 | way it can get one is through an IMPLICIT type or a RESULT variable, because |
1144 | by definition contained functions are contained namespace they're contained |
1145 | in, not in a sibling or parent namespace. */ |
1146 | |
1147 | static void |
1148 | resolve_contained_functions (gfc_namespace *ns) |
1149 | { |
1150 | gfc_namespace *child; |
1151 | gfc_entry_list *el; |
1152 | |
1153 | resolve_formal_arglists (ns); |
1154 | |
1155 | for (child = ns->contained; child; child = child->sibling) |
1156 | { |
1157 | /* Resolve alternate entry points first. */ |
1158 | resolve_entries (child); |
1159 | |
1160 | /* Then check function return types. */ |
1161 | resolve_contained_fntype (child->proc_name, child); |
1162 | for (el = child->entries; el; el = el->next) |
1163 | resolve_contained_fntype (el->sym, child); |
1164 | } |
1165 | } |
1166 | |
1167 | |
1168 | |
1169 | /* A Parameterized Derived Type constructor must contain values for |
1170 | the PDT KIND parameters or they must have a default initializer. |
1171 | Go through the constructor picking out the KIND expressions, |
1172 | storing them in 'param_list' and then call gfc_get_pdt_instance |
1173 | to obtain the PDT instance. */ |
1174 | |
1175 | static gfc_actual_arglist *param_list, *param_tail, *param; |
1176 | |
1177 | static bool |
1178 | get_pdt_spec_expr (gfc_component *c, gfc_expr *expr) |
1179 | { |
1180 | param = gfc_get_actual_arglist ()((gfc_actual_arglist *) xcalloc (1, sizeof (gfc_actual_arglist ))); |
1181 | if (!param_list) |
1182 | param_list = param_tail = param; |
1183 | else |
1184 | { |
1185 | param_tail->next = param; |
1186 | param_tail = param_tail->next; |
1187 | } |
1188 | |
1189 | param_tail->name = c->name; |
1190 | if (expr) |
1191 | param_tail->expr = gfc_copy_expr (expr); |
1192 | else if (c->initializer) |
1193 | param_tail->expr = gfc_copy_expr (c->initializer); |
1194 | else |
1195 | { |
1196 | param_tail->spec_type = SPEC_ASSUMED; |
1197 | if (c->attr.pdt_kind) |
1198 | { |
1199 | gfc_error ("The KIND parameter %qs in the PDT constructor " |
1200 | "at %C has no value", param->name); |
1201 | return false; |
1202 | } |
1203 | } |
1204 | |
1205 | return true; |
1206 | } |
1207 | |
1208 | static bool |
1209 | get_pdt_constructor (gfc_expr *expr, gfc_constructor **constr, |
1210 | gfc_symbol *derived) |
1211 | { |
1212 | gfc_constructor *cons = NULL__null; |
1213 | gfc_component *comp; |
1214 | bool t = true; |
1215 | |
1216 | if (expr && expr->expr_type == EXPR_STRUCTURE) |
1217 | cons = gfc_constructor_first (expr->value.constructor); |
1218 | else if (constr) |
1219 | cons = *constr; |
1220 | gcc_assert (cons)((void)(!(cons) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 1220, __FUNCTION__), 0 : 0)); |
1221 | |
1222 | comp = derived->components; |
1223 | |
1224 | for (; comp && cons; comp = comp->next, cons = gfc_constructor_next (cons)) |
1225 | { |
1226 | if (cons->expr |
1227 | && cons->expr->expr_type == EXPR_STRUCTURE |
1228 | && comp->ts.type == BT_DERIVED) |
1229 | { |
1230 | t = get_pdt_constructor (cons->expr, NULL__null, comp->ts.u.derived); |
1231 | if (!t) |
1232 | return t; |
1233 | } |
1234 | else if (comp->ts.type == BT_DERIVED) |
1235 | { |
1236 | t = get_pdt_constructor (NULL__null, &cons, comp->ts.u.derived); |
1237 | if (!t) |
1238 | return t; |
1239 | } |
1240 | else if ((comp->attr.pdt_kind || comp->attr.pdt_len) |
1241 | && derived->attr.pdt_template) |
1242 | { |
1243 | t = get_pdt_spec_expr (comp, cons->expr); |
1244 | if (!t) |
1245 | return t; |
1246 | } |
1247 | } |
1248 | return t; |
1249 | } |
1250 | |
1251 | |
1252 | static bool resolve_fl_derived0 (gfc_symbol *sym); |
1253 | static bool resolve_fl_struct (gfc_symbol *sym); |
1254 | |
1255 | |
1256 | /* Resolve all of the elements of a structure constructor and make sure that |
1257 | the types are correct. The 'init' flag indicates that the given |
1258 | constructor is an initializer. */ |
1259 | |
1260 | static bool |
1261 | resolve_structure_cons (gfc_expr *expr, int init) |
1262 | { |
1263 | gfc_constructor *cons; |
1264 | gfc_component *comp; |
1265 | bool t; |
1266 | symbol_attribute a; |
1267 | |
1268 | t = true; |
1269 | |
1270 | if (expr->ts.type == BT_DERIVED || expr->ts.type == BT_UNION) |
1271 | { |
1272 | if (expr->ts.u.derived->attr.flavor == FL_DERIVED) |
1273 | resolve_fl_derived0 (expr->ts.u.derived); |
1274 | else |
1275 | resolve_fl_struct (expr->ts.u.derived); |
1276 | |
1277 | /* If this is a Parameterized Derived Type template, find the |
1278 | instance corresponding to the PDT kind parameters. */ |
1279 | if (expr->ts.u.derived->attr.pdt_template) |
1280 | { |
1281 | param_list = NULL__null; |
1282 | t = get_pdt_constructor (expr, NULL__null, expr->ts.u.derived); |
1283 | if (!t) |
1284 | return t; |
1285 | gfc_get_pdt_instance (param_list, &expr->ts.u.derived, NULL__null); |
1286 | |
1287 | expr->param_list = gfc_copy_actual_arglist (param_list); |
1288 | |
1289 | if (param_list) |
1290 | gfc_free_actual_arglist (param_list); |
1291 | |
1292 | if (!expr->ts.u.derived->attr.pdt_type) |
1293 | return false; |
1294 | } |
1295 | } |
1296 | |
1297 | /* A constructor may have references if it is the result of substituting a |
1298 | parameter variable. In this case we just pull out the component we |
1299 | want. */ |
1300 | if (expr->ref) |
1301 | comp = expr->ref->u.c.sym->components; |
1302 | else if ((expr->ts.type == BT_DERIVED || expr->ts.type == BT_CLASS |
1303 | || expr->ts.type == BT_UNION) |
1304 | && expr->ts.u.derived) |
1305 | comp = expr->ts.u.derived->components; |
1306 | else |
1307 | return false; |
1308 | |
1309 | cons = gfc_constructor_first (expr->value.constructor); |
1310 | |
1311 | for (; comp && cons; comp = comp->next, cons = gfc_constructor_next (cons)) |
1312 | { |
1313 | int rank; |
1314 | |
1315 | if (!cons->expr) |
1316 | continue; |
1317 | |
1318 | /* Unions use an EXPR_NULL contrived expression to tell the translation |
1319 | phase to generate an initializer of the appropriate length. |
1320 | Ignore it here. */ |
1321 | if (cons->expr->ts.type == BT_UNION && cons->expr->expr_type == EXPR_NULL) |
1322 | continue; |
1323 | |
1324 | if (!gfc_resolve_expr (cons->expr)) |
1325 | { |
1326 | t = false; |
1327 | continue; |
1328 | } |
1329 | |
1330 | rank = comp->as ? comp->as->rank : 0; |
1331 | if (comp->ts.type == BT_CLASS |
1332 | && !comp->ts.u.derived->attr.unlimited_polymorphic |
1333 | && CLASS_DATA (comp)comp->ts.u.derived->components->as) |
1334 | rank = CLASS_DATA (comp)comp->ts.u.derived->components->as->rank; |
1335 | |
1336 | if (cons->expr->expr_type != EXPR_NULL && rank != cons->expr->rank |
1337 | && (comp->attr.allocatable || cons->expr->rank)) |
1338 | { |
1339 | gfc_error ("The rank of the element in the structure " |
1340 | "constructor at %L does not match that of the " |
1341 | "component (%d/%d)", &cons->expr->where, |
1342 | cons->expr->rank, rank); |
1343 | t = false; |
1344 | } |
1345 | |
1346 | /* If we don't have the right type, try to convert it. */ |
1347 | |
1348 | if (!comp->attr.proc_pointer && |
1349 | !gfc_compare_types (&cons->expr->ts, &comp->ts)) |
1350 | { |
1351 | if (strcmp (comp->name, "_extends") == 0) |
1352 | { |
1353 | /* Can afford to be brutal with the _extends initializer. |
1354 | The derived type can get lost because it is PRIVATE |
1355 | but it is not usage constrained by the standard. */ |
1356 | cons->expr->ts = comp->ts; |
1357 | } |
1358 | else if (comp->attr.pointer && cons->expr->ts.type != BT_UNKNOWN) |
1359 | { |
1360 | gfc_error ("The element in the structure constructor at %L, " |
1361 | "for pointer component %qs, is %s but should be %s", |
1362 | &cons->expr->where, comp->name, |
1363 | gfc_basic_typename (cons->expr->ts.type), |
1364 | gfc_basic_typename (comp->ts.type)); |
1365 | t = false; |
1366 | } |
1367 | else |
1368 | { |
1369 | bool t2 = gfc_convert_type (cons->expr, &comp->ts, 1); |
1370 | if (t) |
1371 | t = t2; |
1372 | } |
1373 | } |
1374 | |
1375 | /* For strings, the length of the constructor should be the same as |
1376 | the one of the structure, ensure this if the lengths are known at |
1377 | compile time and when we are dealing with PARAMETER or structure |
1378 | constructors. */ |
1379 | if (cons->expr->ts.type == BT_CHARACTER && comp->ts.u.cl |
1380 | && comp->ts.u.cl->length |
1381 | && comp->ts.u.cl->length->expr_type == EXPR_CONSTANT |
1382 | && cons->expr->ts.u.cl && cons->expr->ts.u.cl->length |
1383 | && cons->expr->ts.u.cl->length->expr_type == EXPR_CONSTANT |
1384 | && mpz_cmp__gmpz_cmp (cons->expr->ts.u.cl->length->value.integer, |
1385 | comp->ts.u.cl->length->value.integer) != 0) |
1386 | { |
1387 | if (comp->attr.pointer) |
1388 | { |
1389 | HOST_WIDE_INTlong la, lb; |
1390 | la = gfc_mpz_get_hwi (comp->ts.u.cl->length->value.integer); |
1391 | lb = gfc_mpz_get_hwi (cons->expr->ts.u.cl->length->value.integer); |
1392 | gfc_error ("Unequal character lengths (%wd/%wd) for pointer " |
1393 | "component %qs in constructor at %L", |
1394 | la, lb, comp->name, &cons->expr->where); |
1395 | t = false; |
1396 | } |
1397 | |
1398 | if (cons->expr->expr_type == EXPR_VARIABLE |
1399 | && cons->expr->rank != 0 |
1400 | && cons->expr->symtree->n.sym->attr.flavor == FL_PARAMETER) |
1401 | { |
1402 | /* Wrap the parameter in an array constructor (EXPR_ARRAY) |
1403 | to make use of the gfc_resolve_character_array_constructor |
1404 | machinery. The expression is later simplified away to |
1405 | an array of string literals. */ |
1406 | gfc_expr *para = cons->expr; |
1407 | cons->expr = gfc_get_expr (); |
1408 | cons->expr->ts = para->ts; |
1409 | cons->expr->where = para->where; |
1410 | cons->expr->expr_type = EXPR_ARRAY; |
1411 | cons->expr->rank = para->rank; |
1412 | cons->expr->shape = gfc_copy_shape (para->shape, para->rank); |
1413 | gfc_constructor_append_expr (&cons->expr->value.constructor, |
1414 | para, &cons->expr->where); |
1415 | } |
1416 | |
1417 | if (cons->expr->expr_type == EXPR_ARRAY) |
1418 | { |
1419 | /* Rely on the cleanup of the namespace to deal correctly with |
1420 | the old charlen. (There was a block here that attempted to |
1421 | remove the charlen but broke the chain in so doing.) */ |
1422 | cons->expr->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL__null); |
1423 | cons->expr->ts.u.cl->length_from_typespec = true; |
1424 | cons->expr->ts.u.cl->length = gfc_copy_expr (comp->ts.u.cl->length); |
1425 | gfc_resolve_character_array_constructor (cons->expr); |
1426 | } |
1427 | } |
1428 | |
1429 | if (cons->expr->expr_type == EXPR_NULL |
1430 | && !(comp->attr.pointer || comp->attr.allocatable |
1431 | || comp->attr.proc_pointer || comp->ts.f90_type == BT_VOID |
1432 | || (comp->ts.type == BT_CLASS |
1433 | && (CLASS_DATA (comp)comp->ts.u.derived->components->attr.class_pointer |
1434 | || CLASS_DATA (comp)comp->ts.u.derived->components->attr.allocatable)))) |
1435 | { |
1436 | t = false; |
1437 | gfc_error ("The NULL in the structure constructor at %L is " |
1438 | "being applied to component %qs, which is neither " |
1439 | "a POINTER nor ALLOCATABLE", &cons->expr->where, |
1440 | comp->name); |
1441 | } |
1442 | |
1443 | if (comp->attr.proc_pointer && comp->ts.interface) |
1444 | { |
1445 | /* Check procedure pointer interface. */ |
1446 | gfc_symbol *s2 = NULL__null; |
1447 | gfc_component *c2; |
1448 | const char *name; |
1449 | char err[200]; |
1450 | |
1451 | c2 = gfc_get_proc_ptr_comp (cons->expr); |
1452 | if (c2) |
1453 | { |
1454 | s2 = c2->ts.interface; |
1455 | name = c2->name; |
1456 | } |
1457 | else if (cons->expr->expr_type == EXPR_FUNCTION) |
1458 | { |
1459 | s2 = cons->expr->symtree->n.sym->result; |
1460 | name = cons->expr->symtree->n.sym->result->name; |
1461 | } |
1462 | else if (cons->expr->expr_type != EXPR_NULL) |
1463 | { |
1464 | s2 = cons->expr->symtree->n.sym; |
1465 | name = cons->expr->symtree->n.sym->name; |
1466 | } |
1467 | |
1468 | if (s2 && !gfc_compare_interfaces (comp->ts.interface, s2, name, 0, 1, |
1469 | err, sizeof (err), NULL__null, NULL__null)) |
1470 | { |
1471 | gfc_error_opt (0, "Interface mismatch for procedure-pointer " |
1472 | "component %qs in structure constructor at %L:" |
1473 | " %s", comp->name, &cons->expr->where, err); |
1474 | return false; |
1475 | } |
1476 | } |
1477 | |
1478 | /* Validate shape, except for dynamic or PDT arrays. */ |
1479 | if (cons->expr->expr_type == EXPR_ARRAY && rank == cons->expr->rank |
1480 | && comp->as && !comp->attr.allocatable && !comp->attr.pointer |
1481 | && !comp->attr.pdt_array) |
1482 | { |
1483 | mpz_t len; |
1484 | mpz_init__gmpz_init (len); |
1485 | for (int n = 0; n < rank; n++) |
1486 | { |
1487 | if (comp->as->upper[n]->expr_type != EXPR_CONSTANT |
1488 | || comp->as->lower[n]->expr_type != EXPR_CONSTANT) |
1489 | { |
1490 | gfc_error ("Bad array spec of component %qs referenced in " |
1491 | "structure constructor at %L", |
1492 | comp->name, &cons->expr->where); |
1493 | t = false; |
1494 | break; |
1495 | }; |
1496 | if (cons->expr->shape == NULL__null) |
1497 | continue; |
1498 | mpz_set_ui__gmpz_set_ui (len, 1); |
1499 | mpz_add__gmpz_add (len, len, comp->as->upper[n]->value.integer); |
1500 | mpz_sub__gmpz_sub (len, len, comp->as->lower[n]->value.integer); |
1501 | if (mpz_cmp__gmpz_cmp (cons->expr->shape[n], len) != 0) |
1502 | { |
1503 | gfc_error ("The shape of component %qs in the structure " |
1504 | "constructor at %L differs from the shape of the " |
1505 | "declared component for dimension %d (%ld/%ld)", |
1506 | comp->name, &cons->expr->where, n+1, |
1507 | mpz_get_si__gmpz_get_si (cons->expr->shape[n]), |
1508 | mpz_get_si__gmpz_get_si (len)); |
1509 | t = false; |
1510 | } |
1511 | } |
1512 | mpz_clear__gmpz_clear (len); |
1513 | } |
1514 | |
1515 | if (!comp->attr.pointer || comp->attr.proc_pointer |
1516 | || cons->expr->expr_type == EXPR_NULL) |
1517 | continue; |
1518 | |
1519 | a = gfc_expr_attr (cons->expr); |
1520 | |
1521 | if (!a.pointer && !a.target) |
1522 | { |
1523 | t = false; |
1524 | gfc_error ("The element in the structure constructor at %L, " |
1525 | "for pointer component %qs should be a POINTER or " |
1526 | "a TARGET", &cons->expr->where, comp->name); |
1527 | } |
1528 | |
1529 | if (init) |
1530 | { |
1531 | /* F08:C461. Additional checks for pointer initialization. */ |
1532 | if (a.allocatable) |
1533 | { |
1534 | t = false; |
1535 | gfc_error ("Pointer initialization target at %L " |
1536 | "must not be ALLOCATABLE", &cons->expr->where); |
1537 | } |
1538 | if (!a.save) |
1539 | { |
1540 | t = false; |
1541 | gfc_error ("Pointer initialization target at %L " |
1542 | "must have the SAVE attribute", &cons->expr->where); |
1543 | } |
1544 | } |
1545 | |
1546 | /* F2003, C1272 (3). */ |
1547 | bool impure = cons->expr->expr_type == EXPR_VARIABLE |
1548 | && (gfc_impure_variable (cons->expr->symtree->n.sym) |
1549 | || gfc_is_coindexed (cons->expr)); |
1550 | if (impure && gfc_pure (NULL__null)) |
1551 | { |
1552 | t = false; |
1553 | gfc_error ("Invalid expression in the structure constructor for " |
1554 | "pointer component %qs at %L in PURE procedure", |
1555 | comp->name, &cons->expr->where); |
1556 | } |
1557 | |
1558 | if (impure) |
1559 | gfc_unset_implicit_pure (NULL__null); |
1560 | } |
1561 | |
1562 | return t; |
1563 | } |
1564 | |
1565 | |
1566 | /****************** Expression name resolution ******************/ |
1567 | |
1568 | /* Returns 0 if a symbol was not declared with a type or |
1569 | attribute declaration statement, nonzero otherwise. */ |
1570 | |
1571 | static int |
1572 | was_declared (gfc_symbol *sym) |
1573 | { |
1574 | symbol_attribute a; |
1575 | |
1576 | a = sym->attr; |
1577 | |
1578 | if (!a.implicit_type && sym->ts.type != BT_UNKNOWN) |
1579 | return 1; |
1580 | |
1581 | if (a.allocatable || a.dimension || a.dummy || a.external || a.intrinsic |
1582 | || a.optional || a.pointer || a.save || a.target || a.volatile_ |
1583 | || a.value || a.access != ACCESS_UNKNOWN || a.intent != INTENT_UNKNOWN |
1584 | || a.asynchronous || a.codimension) |
1585 | return 1; |
1586 | |
1587 | return 0; |
1588 | } |
1589 | |
1590 | |
1591 | /* Determine if a symbol is generic or not. */ |
1592 | |
1593 | static int |
1594 | generic_sym (gfc_symbol *sym) |
1595 | { |
1596 | gfc_symbol *s; |
1597 | |
1598 | if (sym->attr.generic || |
1599 | (sym->attr.intrinsic && gfc_generic_intrinsic (sym->name))) |
1600 | return 1; |
1601 | |
1602 | if (was_declared (sym) || sym->ns->parent == NULL__null) |
1603 | return 0; |
1604 | |
1605 | gfc_find_symbol (sym->name, sym->ns->parent, 1, &s); |
1606 | |
1607 | if (s != NULL__null) |
1608 | { |
1609 | if (s == sym) |
1610 | return 0; |
1611 | else |
1612 | return generic_sym (s); |
1613 | } |
1614 | |
1615 | return 0; |
1616 | } |
1617 | |
1618 | |
1619 | /* Determine if a symbol is specific or not. */ |
1620 | |
1621 | static int |
1622 | specific_sym (gfc_symbol *sym) |
1623 | { |
1624 | gfc_symbol *s; |
1625 | |
1626 | if (sym->attr.if_source == IFSRC_IFBODY |
1627 | || sym->attr.proc == PROC_MODULE |
1628 | || sym->attr.proc == PROC_INTERNAL |
1629 | || sym->attr.proc == PROC_ST_FUNCTION |
1630 | || (sym->attr.intrinsic && gfc_specific_intrinsic (sym->name)) |
1631 | || sym->attr.external) |
1632 | return 1; |
1633 | |
1634 | if (was_declared (sym) || sym->ns->parent == NULL__null) |
1635 | return 0; |
1636 | |
1637 | gfc_find_symbol (sym->name, sym->ns->parent, 1, &s); |
1638 | |
1639 | return (s == NULL__null) ? 0 : specific_sym (s); |
1640 | } |
1641 | |
1642 | |
1643 | /* Figure out if the procedure is specific, generic or unknown. */ |
1644 | |
1645 | enum proc_type |
1646 | { PTYPE_GENERIC = 1, PTYPE_SPECIFIC, PTYPE_UNKNOWN }; |
1647 | |
1648 | static proc_type |
1649 | procedure_kind (gfc_symbol *sym) |
1650 | { |
1651 | if (generic_sym (sym)) |
1652 | return PTYPE_GENERIC; |
1653 | |
1654 | if (specific_sym (sym)) |
1655 | return PTYPE_SPECIFIC; |
1656 | |
1657 | return PTYPE_UNKNOWN; |
1658 | } |
1659 | |
1660 | /* Check references to assumed size arrays. The flag need_full_assumed_size |
1661 | is nonzero when matching actual arguments. */ |
1662 | |
1663 | static int need_full_assumed_size = 0; |
1664 | |
1665 | static bool |
1666 | check_assumed_size_reference (gfc_symbol *sym, gfc_expr *e) |
1667 | { |
1668 | if (need_full_assumed_size || !(sym->as && sym->as->type == AS_ASSUMED_SIZE)) |
1669 | return false; |
1670 | |
1671 | /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong. |
1672 | What should it be? */ |
1673 | if (e->ref |
1674 | && e->ref->u.ar.as |
1675 | && (e->ref->u.ar.end[e->ref->u.ar.as->rank - 1] == NULL__null) |
1676 | && (e->ref->u.ar.as->type == AS_ASSUMED_SIZE) |
1677 | && (e->ref->u.ar.type == AR_FULL)) |
1678 | { |
1679 | gfc_error ("The upper bound in the last dimension must " |
1680 | "appear in the reference to the assumed size " |
1681 | "array %qs at %L", sym->name, &e->where); |
1682 | return true; |
1683 | } |
1684 | return false; |
1685 | } |
1686 | |
1687 | |
1688 | /* Look for bad assumed size array references in argument expressions |
1689 | of elemental and array valued intrinsic procedures. Since this is |
1690 | called from procedure resolution functions, it only recurses at |
1691 | operators. */ |
1692 | |
1693 | static bool |
1694 | resolve_assumed_size_actual (gfc_expr *e) |
1695 | { |
1696 | if (e == NULL__null) |
1697 | return false; |
1698 | |
1699 | switch (e->expr_type) |
1700 | { |
1701 | case EXPR_VARIABLE: |
1702 | if (e->symtree && check_assumed_size_reference (e->symtree->n.sym, e)) |
1703 | return true; |
1704 | break; |
1705 | |
1706 | case EXPR_OP: |
1707 | if (resolve_assumed_size_actual (e->value.op.op1) |
1708 | || resolve_assumed_size_actual (e->value.op.op2)) |
1709 | return true; |
1710 | break; |
1711 | |
1712 | default: |
1713 | break; |
1714 | } |
1715 | return false; |
1716 | } |
1717 | |
1718 | |
1719 | /* Check a generic procedure, passed as an actual argument, to see if |
1720 | there is a matching specific name. If none, it is an error, and if |
1721 | more than one, the reference is ambiguous. */ |
1722 | static int |
1723 | count_specific_procs (gfc_expr *e) |
1724 | { |
1725 | int n; |
1726 | gfc_interface *p; |
1727 | gfc_symbol *sym; |
1728 | |
1729 | n = 0; |
1730 | sym = e->symtree->n.sym; |
1731 | |
1732 | for (p = sym->generic; p; p = p->next) |
1733 | if (strcmp (sym->name, p->sym->name) == 0) |
1734 | { |
1735 | e->symtree = gfc_find_symtree (p->sym->ns->sym_root, |
1736 | sym->name); |
1737 | n++; |
1738 | } |
1739 | |
1740 | if (n > 1) |
1741 | gfc_error ("%qs at %L is ambiguous", e->symtree->n.sym->name, |
1742 | &e->where); |
1743 | |
1744 | if (n == 0) |
1745 | gfc_error ("GENERIC procedure %qs is not allowed as an actual " |
1746 | "argument at %L", sym->name, &e->where); |
1747 | |
1748 | return n; |
1749 | } |
1750 | |
1751 | |
1752 | /* See if a call to sym could possibly be a not allowed RECURSION because of |
1753 | a missing RECURSIVE declaration. This means that either sym is the current |
1754 | context itself, or sym is the parent of a contained procedure calling its |
1755 | non-RECURSIVE containing procedure. |
1756 | This also works if sym is an ENTRY. */ |
1757 | |
1758 | static bool |
1759 | is_illegal_recursion (gfc_symbol* sym, gfc_namespace* context) |
1760 | { |
1761 | gfc_symbol* proc_sym; |
1762 | gfc_symbol* context_proc; |
1763 | gfc_namespace* real_context; |
1764 | |
1765 | if (sym->attr.flavor == FL_PROGRAM |
1766 | || gfc_fl_struct (sym->attr.flavor)((sym->attr.flavor) == FL_DERIVED || (sym->attr.flavor) == FL_UNION || (sym->attr.flavor) == FL_STRUCT)) |
1767 | return false; |
1768 | |
1769 | /* If we've got an ENTRY, find real procedure. */ |
1770 | if (sym->attr.entry && sym->ns->entries) |
1771 | proc_sym = sym->ns->entries->sym; |
1772 | else |
1773 | proc_sym = sym; |
1774 | |
1775 | /* If sym is RECURSIVE, all is well of course. */ |
1776 | if (proc_sym->attr.recursive || flag_recursiveglobal_options.x_flag_recursive) |
1777 | return false; |
1778 | |
1779 | /* Find the context procedure's "real" symbol if it has entries. |
1780 | We look for a procedure symbol, so recurse on the parents if we don't |
1781 | find one (like in case of a BLOCK construct). */ |
1782 | for (real_context = context; ; real_context = real_context->parent) |
1783 | { |
1784 | /* We should find something, eventually! */ |
1785 | gcc_assert (real_context)((void)(!(real_context) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 1785, __FUNCTION__), 0 : 0)); |
1786 | |
1787 | context_proc = (real_context->entries ? real_context->entries->sym |
1788 | : real_context->proc_name); |
1789 | |
1790 | /* In some special cases, there may not be a proc_name, like for this |
1791 | invalid code: |
1792 | real(bad_kind()) function foo () ... |
1793 | when checking the call to bad_kind (). |
1794 | In these cases, we simply return here and assume that the |
1795 | call is ok. */ |
1796 | if (!context_proc) |
1797 | return false; |
1798 | |
1799 | if (context_proc->attr.flavor != FL_LABEL) |
1800 | break; |
1801 | } |
1802 | |
1803 | /* A call from sym's body to itself is recursion, of course. */ |
1804 | if (context_proc == proc_sym) |
1805 | return true; |
1806 | |
1807 | /* The same is true if context is a contained procedure and sym the |
1808 | containing one. */ |
1809 | if (context_proc->attr.contained) |
1810 | { |
1811 | gfc_symbol* parent_proc; |
1812 | |
1813 | gcc_assert (context->parent)((void)(!(context->parent) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 1813, __FUNCTION__), 0 : 0)); |
1814 | parent_proc = (context->parent->entries ? context->parent->entries->sym |
1815 | : context->parent->proc_name); |
1816 | |
1817 | if (parent_proc == proc_sym) |
1818 | return true; |
1819 | } |
1820 | |
1821 | return false; |
1822 | } |
1823 | |
1824 | |
1825 | /* Resolve an intrinsic procedure: Set its function/subroutine attribute, |
1826 | its typespec and formal argument list. */ |
1827 | |
1828 | bool |
1829 | gfc_resolve_intrinsic (gfc_symbol *sym, locus *loc) |
1830 | { |
1831 | gfc_intrinsic_sym* isym = NULL__null; |
1832 | const char* symstd; |
1833 | |
1834 | if (sym->resolve_symbol_called >= 2) |
1835 | return true; |
1836 | |
1837 | sym->resolve_symbol_called = 2; |
1838 | |
1839 | /* Already resolved. */ |
1840 | if (sym->from_intmod && sym->ts.type != BT_UNKNOWN) |
1841 | return true; |
1842 | |
1843 | /* We already know this one is an intrinsic, so we don't call |
1844 | gfc_is_intrinsic for full checking but rather use gfc_find_function and |
1845 | gfc_find_subroutine directly to check whether it is a function or |
1846 | subroutine. */ |
1847 | |
1848 | if (sym->intmod_sym_id && sym->attr.subroutine) |
1849 | { |
1850 | gfc_isym_id id = gfc_isym_id_by_intmod_sym (sym); |
1851 | isym = gfc_intrinsic_subroutine_by_id (id); |
1852 | } |
1853 | else if (sym->intmod_sym_id) |
1854 | { |
1855 | gfc_isym_id id = gfc_isym_id_by_intmod_sym (sym); |
1856 | isym = gfc_intrinsic_function_by_id (id); |
1857 | } |
1858 | else if (!sym->attr.subroutine) |
1859 | isym = gfc_find_function (sym->name); |
1860 | |
1861 | if (isym && !sym->attr.subroutine) |
1862 | { |
1863 | if (sym->ts.type != BT_UNKNOWN && warn_surprisingglobal_options.x_warn_surprising |
1864 | && !sym->attr.implicit_type) |
1865 | gfc_warning (OPT_Wsurprising, |
1866 | "Type specified for intrinsic function %qs at %L is" |
1867 | " ignored", sym->name, &sym->declared_at); |
1868 | |
1869 | if (!sym->attr.function && |
1870 | !gfc_add_function(&sym->attr, sym->name, loc)) |
1871 | return false; |
1872 | |
1873 | sym->ts = isym->ts; |
1874 | } |
1875 | else if (isym || (isym = gfc_find_subroutine (sym->name))) |
1876 | { |
1877 | if (sym->ts.type != BT_UNKNOWN && !sym->attr.implicit_type) |
1878 | { |
1879 | gfc_error ("Intrinsic subroutine %qs at %L shall not have a type" |
1880 | " specifier", sym->name, &sym->declared_at); |
1881 | return false; |
1882 | } |
1883 | |
1884 | if (!sym->attr.subroutine && |
1885 | !gfc_add_subroutine(&sym->attr, sym->name, loc)) |
1886 | return false; |
1887 | } |
1888 | else |
1889 | { |
1890 | gfc_error ("%qs declared INTRINSIC at %L does not exist", sym->name, |
1891 | &sym->declared_at); |
1892 | return false; |
1893 | } |
1894 | |
1895 | gfc_copy_formal_args_intr (sym, isym, NULL__null); |
1896 | |
1897 | sym->attr.pure = isym->pure; |
1898 | sym->attr.elemental = isym->elemental; |
1899 | |
1900 | /* Check it is actually available in the standard settings. */ |
1901 | if (!gfc_check_intrinsic_standard (isym, &symstd, false, sym->declared_at)) |
1902 | { |
1903 | gfc_error ("The intrinsic %qs declared INTRINSIC at %L is not " |
1904 | "available in the current standard settings but %s. Use " |
1905 | "an appropriate %<-std=*%> option or enable " |
1906 | "%<-fall-intrinsics%> in order to use it.", |
1907 | sym->name, &sym->declared_at, symstd); |
1908 | return false; |
1909 | } |
1910 | |
1911 | return true; |
1912 | } |
1913 | |
1914 | |
1915 | /* Resolve a procedure expression, like passing it to a called procedure or as |
1916 | RHS for a procedure pointer assignment. */ |
1917 | |
1918 | static bool |
1919 | resolve_procedure_expression (gfc_expr* expr) |
1920 | { |
1921 | gfc_symbol* sym; |
1922 | |
1923 | if (expr->expr_type != EXPR_VARIABLE) |
1924 | return true; |
1925 | gcc_assert (expr->symtree)((void)(!(expr->symtree) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 1925, __FUNCTION__), 0 : 0)); |
1926 | |
1927 | sym = expr->symtree->n.sym; |
1928 | |
1929 | if (sym->attr.intrinsic) |
1930 | gfc_resolve_intrinsic (sym, &expr->where); |
1931 | |
1932 | if (sym->attr.flavor != FL_PROCEDURE |
1933 | || (sym->attr.function && sym->result == sym)) |
1934 | return true; |
1935 | |
1936 | /* A non-RECURSIVE procedure that is used as procedure expression within its |
1937 | own body is in danger of being called recursively. */ |
1938 | if (is_illegal_recursion (sym, gfc_current_ns)) |
1939 | gfc_warning (0, "Non-RECURSIVE procedure %qs at %L is possibly calling" |
1940 | " itself recursively. Declare it RECURSIVE or use" |
1941 | " %<-frecursive%>", sym->name, &expr->where); |
1942 | |
1943 | return true; |
1944 | } |
1945 | |
1946 | |
1947 | /* Check that name is not a derived type. */ |
1948 | |
1949 | static bool |
1950 | is_dt_name (const char *name) |
1951 | { |
1952 | gfc_symbol *dt_list, *dt_first; |
1953 | |
1954 | dt_list = dt_first = gfc_derived_types; |
1955 | for (; dt_list; dt_list = dt_list->dt_next) |
1956 | { |
1957 | if (strcmp(dt_list->name, name) == 0) |
1958 | return true; |
1959 | if (dt_first == dt_list->dt_next) |
1960 | break; |
1961 | } |
1962 | return false; |
1963 | } |
1964 | |
1965 | |
1966 | /* Resolve an actual argument list. Most of the time, this is just |
1967 | resolving the expressions in the list. |
1968 | The exception is that we sometimes have to decide whether arguments |
1969 | that look like procedure arguments are really simple variable |
1970 | references. */ |
1971 | |
1972 | static bool |
1973 | resolve_actual_arglist (gfc_actual_arglist *arg, procedure_type ptype, |
1974 | bool no_formal_args) |
1975 | { |
1976 | gfc_symbol *sym; |
1977 | gfc_symtree *parent_st; |
1978 | gfc_expr *e; |
1979 | gfc_component *comp; |
1980 | int save_need_full_assumed_size; |
1981 | bool return_value = false; |
1982 | bool actual_arg_sav = actual_arg, first_actual_arg_sav = first_actual_arg; |
1983 | |
1984 | actual_arg = true; |
1985 | first_actual_arg = true; |
1986 | |
1987 | for (; arg; arg = arg->next) |
1988 | { |
1989 | e = arg->expr; |
1990 | if (e == NULL__null) |
1991 | { |
1992 | /* Check the label is a valid branching target. */ |
1993 | if (arg->label) |
1994 | { |
1995 | if (arg->label->defined == ST_LABEL_UNKNOWN) |
1996 | { |
1997 | gfc_error ("Label %d referenced at %L is never defined", |
1998 | arg->label->value, &arg->label->where); |
1999 | goto cleanup; |
2000 | } |
2001 | } |
2002 | first_actual_arg = false; |
2003 | continue; |
2004 | } |
2005 | |
2006 | if (e->expr_type == EXPR_VARIABLE |
2007 | && e->symtree->n.sym->attr.generic |
2008 | && no_formal_args |
2009 | && count_specific_procs (e) != 1) |
2010 | goto cleanup; |
2011 | |
2012 | if (e->ts.type != BT_PROCEDURE) |
2013 | { |
2014 | save_need_full_assumed_size = need_full_assumed_size; |
2015 | if (e->expr_type != EXPR_VARIABLE) |
2016 | need_full_assumed_size = 0; |
2017 | if (!gfc_resolve_expr (e)) |
2018 | goto cleanup; |
2019 | need_full_assumed_size = save_need_full_assumed_size; |
2020 | goto argument_list; |
2021 | } |
2022 | |
2023 | /* See if the expression node should really be a variable reference. */ |
2024 | |
2025 | sym = e->symtree->n.sym; |
2026 | |
2027 | if (sym->attr.flavor == FL_PROCEDURE && is_dt_name (sym->name)) |
2028 | { |
2029 | gfc_error ("Derived type %qs is used as an actual " |
2030 | "argument at %L", sym->name, &e->where); |
2031 | goto cleanup; |
2032 | } |
2033 | |
2034 | if (sym->attr.flavor == FL_PROCEDURE |
2035 | || sym->attr.intrinsic |
2036 | || sym->attr.external) |
2037 | { |
2038 | int actual_ok; |
2039 | |
2040 | /* If a procedure is not already determined to be something else |
2041 | check if it is intrinsic. */ |
2042 | if (gfc_is_intrinsic (sym, sym->attr.subroutine, e->where)) |
2043 | sym->attr.intrinsic = 1; |
2044 | |
2045 | if (sym->attr.proc == PROC_ST_FUNCTION) |
2046 | { |
2047 | gfc_error ("Statement function %qs at %L is not allowed as an " |
2048 | "actual argument", sym->name, &e->where); |
2049 | } |
2050 | |
2051 | actual_ok = gfc_intrinsic_actual_ok (sym->name, |
2052 | sym->attr.subroutine); |
2053 | if (sym->attr.intrinsic && actual_ok == 0) |
2054 | { |
2055 | gfc_error ("Intrinsic %qs at %L is not allowed as an " |
2056 | "actual argument", sym->name, &e->where); |
2057 | } |
2058 | |
2059 | if (sym->attr.contained && !sym->attr.use_assoc |
2060 | && sym->ns->proc_name->attr.flavor != FL_MODULE) |
2061 | { |
2062 | if (!gfc_notify_std (GFC_STD_F2008(1<<7), "Internal procedure %qs is" |
2063 | " used as actual argument at %L", |
2064 | sym->name, &e->where)) |
2065 | goto cleanup; |
2066 | } |
2067 | |
2068 | if (sym->attr.elemental && !sym->attr.intrinsic) |
2069 | { |
2070 | gfc_error ("ELEMENTAL non-INTRINSIC procedure %qs is not " |
2071 | "allowed as an actual argument at %L", sym->name, |
2072 | &e->where); |
2073 | } |
2074 | |
2075 | /* Check if a generic interface has a specific procedure |
2076 | with the same name before emitting an error. */ |
2077 | if (sym->attr.generic && count_specific_procs (e) != 1) |
2078 | goto cleanup; |
2079 | |
2080 | /* Just in case a specific was found for the expression. */ |
2081 | sym = e->symtree->n.sym; |
2082 | |
2083 | /* If the symbol is the function that names the current (or |
2084 | parent) scope, then we really have a variable reference. */ |
2085 | |
2086 | if (gfc_is_function_return_value (sym, sym->ns)) |
2087 | goto got_variable; |
2088 | |
2089 | /* If all else fails, see if we have a specific intrinsic. */ |
2090 | if (sym->ts.type == BT_UNKNOWN && sym->attr.intrinsic) |
2091 | { |
2092 | gfc_intrinsic_sym *isym; |
2093 | |
2094 | isym = gfc_find_function (sym->name); |
2095 | if (isym == NULL__null || !isym->specific) |
2096 | { |
2097 | gfc_error ("Unable to find a specific INTRINSIC procedure " |
2098 | "for the reference %qs at %L", sym->name, |
2099 | &e->where); |
2100 | goto cleanup; |
2101 | } |
2102 | sym->ts = isym->ts; |
2103 | sym->attr.intrinsic = 1; |
2104 | sym->attr.function = 1; |
2105 | } |
2106 | |
2107 | if (!gfc_resolve_expr (e)) |
2108 | goto cleanup; |
2109 | goto argument_list; |
2110 | } |
2111 | |
2112 | /* See if the name is a module procedure in a parent unit. */ |
2113 | |
2114 | if (was_declared (sym) || sym->ns->parent == NULL__null) |
2115 | goto got_variable; |
2116 | |
2117 | if (gfc_find_sym_tree (sym->name, sym->ns->parent, 1, &parent_st)) |
2118 | { |
2119 | gfc_error ("Symbol %qs at %L is ambiguous", sym->name, &e->where); |
2120 | goto cleanup; |
2121 | } |
2122 | |
2123 | if (parent_st == NULL__null) |
2124 | goto got_variable; |
2125 | |
2126 | sym = parent_st->n.sym; |
2127 | e->symtree = parent_st; /* Point to the right thing. */ |
2128 | |
2129 | if (sym->attr.flavor == FL_PROCEDURE |
2130 | || sym->attr.intrinsic |
2131 | || sym->attr.external) |
2132 | { |
2133 | if (!gfc_resolve_expr (e)) |
2134 | goto cleanup; |
2135 | goto argument_list; |
2136 | } |
2137 | |
2138 | got_variable: |
2139 | e->expr_type = EXPR_VARIABLE; |
2140 | e->ts = sym->ts; |
2141 | if ((sym->as != NULL__null && sym->ts.type != BT_CLASS) |
2142 | || (sym->ts.type == BT_CLASS && sym->attr.class_ok |
2143 | && CLASS_DATA (sym)sym->ts.u.derived->components->as)) |
2144 | { |
2145 | e->rank = sym->ts.type == BT_CLASS |
2146 | ? CLASS_DATA (sym)sym->ts.u.derived->components->as->rank : sym->as->rank; |
2147 | e->ref = gfc_get_ref ()((gfc_ref *) xcalloc (1, sizeof (gfc_ref))); |
2148 | e->ref->type = REF_ARRAY; |
2149 | e->ref->u.ar.type = AR_FULL; |
2150 | e->ref->u.ar.as = sym->ts.type == BT_CLASS |
2151 | ? CLASS_DATA (sym)sym->ts.u.derived->components->as : sym->as; |
2152 | } |
2153 | |
2154 | /* Expressions are assigned a default ts.type of BT_PROCEDURE in |
2155 | primary.cc (match_actual_arg). If above code determines that it |
2156 | is a variable instead, it needs to be resolved as it was not |
2157 | done at the beginning of this function. */ |
2158 | save_need_full_assumed_size = need_full_assumed_size; |
2159 | if (e->expr_type != EXPR_VARIABLE) |
2160 | need_full_assumed_size = 0; |
2161 | if (!gfc_resolve_expr (e)) |
2162 | goto cleanup; |
2163 | need_full_assumed_size = save_need_full_assumed_size; |
2164 | |
2165 | argument_list: |
2166 | /* Check argument list functions %VAL, %LOC and %REF. There is |
2167 | nothing to do for %REF. */ |
2168 | if (arg->name && arg->name[0] == '%') |
2169 | { |
2170 | if (strcmp ("%VAL", arg->name) == 0) |
2171 | { |
2172 | if (e->ts.type == BT_CHARACTER || e->ts.type == BT_DERIVED) |
2173 | { |
2174 | gfc_error ("By-value argument at %L is not of numeric " |
2175 | "type", &e->where); |
2176 | goto cleanup; |
2177 | } |
2178 | |
2179 | if (e->rank) |
2180 | { |
2181 | gfc_error ("By-value argument at %L cannot be an array or " |
2182 | "an array section", &e->where); |
2183 | goto cleanup; |
2184 | } |
2185 | |
2186 | /* Intrinsics are still PROC_UNKNOWN here. However, |
2187 | since same file external procedures are not resolvable |
2188 | in gfortran, it is a good deal easier to leave them to |
2189 | intrinsic.cc. */ |
2190 | if (ptype != PROC_UNKNOWN |
2191 | && ptype != PROC_DUMMY |
2192 | && ptype != PROC_EXTERNAL |
2193 | && ptype != PROC_MODULE) |
2194 | { |
2195 | gfc_error ("By-value argument at %L is not allowed " |
2196 | "in this context", &e->where); |
2197 | goto cleanup; |
2198 | } |
2199 | } |
2200 | |
2201 | /* Statement functions have already been excluded above. */ |
2202 | else if (strcmp ("%LOC", arg->name) == 0 |
2203 | && e->ts.type == BT_PROCEDURE) |
2204 | { |
2205 | if (e->symtree->n.sym->attr.proc == PROC_INTERNAL) |
2206 | { |
2207 | gfc_error ("Passing internal procedure at %L by location " |
2208 | "not allowed", &e->where); |
2209 | goto cleanup; |
2210 | } |
2211 | } |
2212 | } |
2213 | |
2214 | comp = gfc_get_proc_ptr_comp(e); |
2215 | if (e->expr_type == EXPR_VARIABLE |
2216 | && comp && comp->attr.elemental) |
2217 | { |
2218 | gfc_error ("ELEMENTAL procedure pointer component %qs is not " |
2219 | "allowed as an actual argument at %L", comp->name, |
2220 | &e->where); |
2221 | } |
2222 | |
2223 | /* Fortran 2008, C1237. */ |
2224 | if (e->expr_type == EXPR_VARIABLE && gfc_is_coindexed (e) |
2225 | && gfc_has_ultimate_pointer (e)) |
2226 | { |
2227 | gfc_error ("Coindexed actual argument at %L with ultimate pointer " |
2228 | "component", &e->where); |
2229 | goto cleanup; |
2230 | } |
2231 | |
2232 | first_actual_arg = false; |
2233 | } |
2234 | |
2235 | return_value = true; |
2236 | |
2237 | cleanup: |
2238 | actual_arg = actual_arg_sav; |
2239 | first_actual_arg = first_actual_arg_sav; |
2240 | |
2241 | return return_value; |
2242 | } |
2243 | |
2244 | |
2245 | /* Do the checks of the actual argument list that are specific to elemental |
2246 | procedures. If called with c == NULL, we have a function, otherwise if |
2247 | expr == NULL, we have a subroutine. */ |
2248 | |
2249 | static bool |
2250 | resolve_elemental_actual (gfc_expr *expr, gfc_code *c) |
2251 | { |
2252 | gfc_actual_arglist *arg0; |
2253 | gfc_actual_arglist *arg; |
2254 | gfc_symbol *esym = NULL__null; |
2255 | gfc_intrinsic_sym *isym = NULL__null; |
2256 | gfc_expr *e = NULL__null; |
2257 | gfc_intrinsic_arg *iformal = NULL__null; |
2258 | gfc_formal_arglist *eformal = NULL__null; |
2259 | bool formal_optional = false; |
2260 | bool set_by_optional = false; |
2261 | int i; |
2262 | int rank = 0; |
2263 | |
2264 | /* Is this an elemental procedure? */ |
2265 | if (expr && expr->value.function.actual != NULL__null) |
2266 | { |
2267 | if (expr->value.function.esym != NULL__null |
2268 | && expr->value.function.esym->attr.elemental) |
2269 | { |
2270 | arg0 = expr->value.function.actual; |
2271 | esym = expr->value.function.esym; |
2272 | } |
2273 | else if (expr->value.function.isym != NULL__null |
2274 | && expr->value.function.isym->elemental) |
2275 | { |
2276 | arg0 = expr->value.function.actual; |
2277 | isym = expr->value.function.isym; |
2278 | } |
2279 | else |
2280 | return true; |
2281 | } |
2282 | else if (c && c->ext.actual != NULL__null) |
2283 | { |
2284 | arg0 = c->ext.actual; |
2285 | |
2286 | if (c->resolved_sym) |
2287 | esym = c->resolved_sym; |
2288 | else |
2289 | esym = c->symtree->n.sym; |
2290 | gcc_assert (esym)((void)(!(esym) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 2290, __FUNCTION__), 0 : 0)); |
2291 | |
2292 | if (!esym->attr.elemental) |
2293 | return true; |
2294 | } |
2295 | else |
2296 | return true; |
2297 | |
2298 | /* The rank of an elemental is the rank of its array argument(s). */ |
2299 | for (arg = arg0; arg; arg = arg->next) |
2300 | { |
2301 | if (arg->expr != NULL__null && arg->expr->rank != 0) |
2302 | { |
2303 | rank = arg->expr->rank; |
2304 | if (arg->expr->expr_type == EXPR_VARIABLE |
2305 | && arg->expr->symtree->n.sym->attr.optional) |
2306 | set_by_optional = true; |
2307 | |
2308 | /* Function specific; set the result rank and shape. */ |
2309 | if (expr) |
2310 | { |
2311 | expr->rank = rank; |
2312 | if (!expr->shape && arg->expr->shape) |
2313 | { |
2314 | expr->shape = gfc_get_shape (rank)(((mpz_t *) xcalloc (((rank)), sizeof (mpz_t)))); |
2315 | for (i = 0; i < rank; i++) |
2316 | mpz_init_set__gmpz_init_set (expr->shape[i], arg->expr->shape[i]); |
2317 | } |
2318 | } |
2319 | break; |
2320 | } |
2321 | } |
2322 | |
2323 | /* If it is an array, it shall not be supplied as an actual argument |
2324 | to an elemental procedure unless an array of the same rank is supplied |
2325 | as an actual argument corresponding to a nonoptional dummy argument of |
2326 | that elemental procedure(12.4.1.5). */ |
2327 | formal_optional = false; |
2328 | if (isym) |
2329 | iformal = isym->formal; |
2330 | else |
2331 | eformal = esym->formal; |
2332 | |
2333 | for (arg = arg0; arg; arg = arg->next) |
2334 | { |
2335 | if (eformal) |
2336 | { |
2337 | if (eformal->sym && eformal->sym->attr.optional) |
2338 | formal_optional = true; |
2339 | eformal = eformal->next; |
2340 | } |
2341 | else if (isym && iformal) |
2342 | { |
2343 | if (iformal->optional) |
2344 | formal_optional = true; |
2345 | iformal = iformal->next; |
2346 | } |
2347 | else if (isym) |
2348 | formal_optional = true; |
2349 | |
2350 | if (pedanticglobal_options.x_pedantic && arg->expr != NULL__null |
2351 | && arg->expr->expr_type == EXPR_VARIABLE |
2352 | && arg->expr->symtree->n.sym->attr.optional |
2353 | && formal_optional |
2354 | && arg->expr->rank |
2355 | && (set_by_optional || arg->expr->rank != rank) |
2356 | && !(isym && isym->id == GFC_ISYM_CONVERSION)) |
2357 | { |
2358 | bool t = false; |
2359 | gfc_actual_arglist *a; |
2360 | |
2361 | /* Scan the argument list for a non-optional argument with the |
2362 | same rank as arg. */ |
2363 | for (a = arg0; a; a = a->next) |
2364 | if (a != arg |
2365 | && a->expr->rank == arg->expr->rank |
2366 | && !a->expr->symtree->n.sym->attr.optional) |
2367 | { |
2368 | t = true; |
2369 | break; |
2370 | } |
2371 | |
2372 | if (!t) |
2373 | gfc_warning (OPT_Wpedantic, |
2374 | "%qs at %L is an array and OPTIONAL; If it is not " |
2375 | "present, then it cannot be the actual argument of " |
2376 | "an ELEMENTAL procedure unless there is a non-optional" |
2377 | " argument with the same rank " |
2378 | "(Fortran 2018, 15.5.2.12)", |
2379 | arg->expr->symtree->n.sym->name, &arg->expr->where); |
2380 | } |
2381 | } |
2382 | |
2383 | for (arg = arg0; arg; arg = arg->next) |
2384 | { |
2385 | if (arg->expr == NULL__null || arg->expr->rank == 0) |
2386 | continue; |
2387 | |
2388 | /* Being elemental, the last upper bound of an assumed size array |
2389 | argument must be present. */ |
2390 | if (resolve_assumed_size_actual (arg->expr)) |
2391 | return false; |
2392 | |
2393 | /* Elemental procedure's array actual arguments must conform. */ |
2394 | if (e != NULL__null) |
2395 | { |
2396 | if (!gfc_check_conformance (arg->expr, e, _("elemental procedure")gettext ("elemental procedure"))) |
2397 | return false; |
2398 | } |
2399 | else |
2400 | e = arg->expr; |
2401 | } |
2402 | |
2403 | /* INTENT(OUT) is only allowed for subroutines; if any actual argument |
2404 | is an array, the intent inout/out variable needs to be also an array. */ |
2405 | if (rank > 0 && esym && expr == NULL__null) |
2406 | for (eformal = esym->formal, arg = arg0; arg && eformal; |
2407 | arg = arg->next, eformal = eformal->next) |
2408 | if (eformal->sym |
2409 | && (eformal->sym->attr.intent == INTENT_OUT |
2410 | || eformal->sym->attr.intent == INTENT_INOUT) |
2411 | && arg->expr && arg->expr->rank == 0) |
2412 | { |
2413 | gfc_error ("Actual argument at %L for INTENT(%s) dummy %qs of " |
2414 | "ELEMENTAL subroutine %qs is a scalar, but another " |
2415 | "actual argument is an array", &arg->expr->where, |
2416 | (eformal->sym->attr.intent == INTENT_OUT) ? "OUT" |
2417 | : "INOUT", eformal->sym->name, esym->name); |
2418 | return false; |
2419 | } |
2420 | return true; |
2421 | } |
2422 | |
2423 | |
2424 | /* This function does the checking of references to global procedures |
2425 | as defined in sections 18.1 and 14.1, respectively, of the Fortran |
2426 | 77 and 95 standards. It checks for a gsymbol for the name, making |
2427 | one if it does not already exist. If it already exists, then the |
2428 | reference being resolved must correspond to the type of gsymbol. |
2429 | Otherwise, the new symbol is equipped with the attributes of the |
2430 | reference. The corresponding code that is called in creating |
2431 | global entities is parse.cc. |
2432 | |
2433 | In addition, for all but -std=legacy, the gsymbols are used to |
2434 | check the interfaces of external procedures from the same file. |
2435 | The namespace of the gsymbol is resolved and then, once this is |
2436 | done the interface is checked. */ |
2437 | |
2438 | |
2439 | static bool |
2440 | not_in_recursive (gfc_symbol *sym, gfc_namespace *gsym_ns) |
2441 | { |
2442 | if (!gsym_ns->proc_name->attr.recursive) |
2443 | return true; |
2444 | |
2445 | if (sym->ns == gsym_ns) |
2446 | return false; |
2447 | |
2448 | if (sym->ns->parent && sym->ns->parent == gsym_ns) |
2449 | return false; |
2450 | |
2451 | return true; |
2452 | } |
2453 | |
2454 | static bool |
2455 | not_entry_self_reference (gfc_symbol *sym, gfc_namespace *gsym_ns) |
2456 | { |
2457 | if (gsym_ns->entries) |
2458 | { |
2459 | gfc_entry_list *entry = gsym_ns->entries; |
2460 | |
2461 | for (; entry; entry = entry->next) |
2462 | { |
2463 | if (strcmp (sym->name, entry->sym->name) == 0) |
2464 | { |
2465 | if (strcmp (gsym_ns->proc_name->name, |
2466 | sym->ns->proc_name->name) == 0) |
2467 | return false; |
2468 | |
2469 | if (sym->ns->parent |
2470 | && strcmp (gsym_ns->proc_name->name, |
2471 | sym->ns->parent->proc_name->name) == 0) |
2472 | return false; |
2473 | } |
2474 | } |
2475 | } |
2476 | return true; |
2477 | } |
2478 | |
2479 | |
2480 | /* Check for the requirement of an explicit interface. F08:12.4.2.2. */ |
2481 | |
2482 | bool |
2483 | gfc_explicit_interface_required (gfc_symbol *sym, char *errmsg, int err_len) |
2484 | { |
2485 | gfc_formal_arglist *arg = gfc_sym_get_dummy_args (sym); |
2486 | |
2487 | for ( ; arg; arg = arg->next) |
2488 | { |
2489 | if (!arg->sym) |
2490 | continue; |
2491 | |
2492 | if (arg->sym->attr.allocatable) /* (2a) */ |
2493 | { |
2494 | strncpy (errmsg, _("allocatable argument")gettext ("allocatable argument"), err_len); |
2495 | return true; |
2496 | } |
2497 | else if (arg->sym->attr.asynchronous) |
2498 | { |
2499 | strncpy (errmsg, _("asynchronous argument")gettext ("asynchronous argument"), err_len); |
2500 | return true; |
2501 | } |
2502 | else if (arg->sym->attr.optional) |
2503 | { |
2504 | strncpy (errmsg, _("optional argument")gettext ("optional argument"), err_len); |
2505 | return true; |
2506 | } |
2507 | else if (arg->sym->attr.pointer) |
2508 | { |
2509 | strncpy (errmsg, _("pointer argument")gettext ("pointer argument"), err_len); |
2510 | return true; |
2511 | } |
2512 | else if (arg->sym->attr.target) |
2513 | { |
2514 | strncpy (errmsg, _("target argument")gettext ("target argument"), err_len); |
2515 | return true; |
2516 | } |
2517 | else if (arg->sym->attr.value) |
2518 | { |
2519 | strncpy (errmsg, _("value argument")gettext ("value argument"), err_len); |
2520 | return true; |
2521 | } |
2522 | else if (arg->sym->attr.volatile_) |
2523 | { |
2524 | strncpy (errmsg, _("volatile argument")gettext ("volatile argument"), err_len); |
2525 | return true; |
2526 | } |
2527 | else if (arg->sym->as && arg->sym->as->type == AS_ASSUMED_SHAPE) /* (2b) */ |
2528 | { |
2529 | strncpy (errmsg, _("assumed-shape argument")gettext ("assumed-shape argument"), err_len); |
2530 | return true; |
2531 | } |
2532 | else if (arg->sym->as && arg->sym->as->type == AS_ASSUMED_RANK) /* TS 29113, 6.2. */ |
2533 | { |
2534 | strncpy (errmsg, _("assumed-rank argument")gettext ("assumed-rank argument"), err_len); |
2535 | return true; |
2536 | } |
2537 | else if (arg->sym->attr.codimension) /* (2c) */ |
2538 | { |
2539 | strncpy (errmsg, _("coarray argument")gettext ("coarray argument"), err_len); |
2540 | return true; |
2541 | } |
2542 | else if (false) /* (2d) TODO: parametrized derived type */ |
2543 | { |
2544 | strncpy (errmsg, _("parametrized derived type argument")gettext ("parametrized derived type argument"), err_len); |
2545 | return true; |
2546 | } |
2547 | else if (arg->sym->ts.type == BT_CLASS) /* (2e) */ |
2548 | { |
2549 | strncpy (errmsg, _("polymorphic argument")gettext ("polymorphic argument"), err_len); |
2550 | return true; |
2551 | } |
2552 | else if (arg->sym->attr.ext_attr & (1 << EXT_ATTR_NO_ARG_CHECK)) |
2553 | { |
2554 | strncpy (errmsg, _("NO_ARG_CHECK attribute")gettext ("NO_ARG_CHECK attribute"), err_len); |
2555 | return true; |
2556 | } |
2557 | else if (arg->sym->ts.type == BT_ASSUMED) |
2558 | { |
2559 | /* As assumed-type is unlimited polymorphic (cf. above). |
2560 | See also TS 29113, Note 6.1. */ |
2561 | strncpy (errmsg, _("assumed-type argument")gettext ("assumed-type argument"), err_len); |
2562 | return true; |
2563 | } |
2564 | } |
2565 | |
2566 | if (sym->attr.function) |
2567 | { |
2568 | gfc_symbol *res = sym->result ? sym->result : sym; |
2569 | |
2570 | if (res->attr.dimension) /* (3a) */ |
2571 | { |
2572 | strncpy (errmsg, _("array result")gettext ("array result"), err_len); |
2573 | return true; |
2574 | } |
2575 | else if (res->attr.pointer || res->attr.allocatable) /* (3b) */ |
2576 | { |
2577 | strncpy (errmsg, _("pointer or allocatable result")gettext ("pointer or allocatable result"), err_len); |
2578 | return true; |
2579 | } |
2580 | else if (res->ts.type == BT_CHARACTER && res->ts.u.cl |
2581 | && res->ts.u.cl->length |
2582 | && res->ts.u.cl->length->expr_type != EXPR_CONSTANT) /* (3c) */ |
2583 | { |
2584 | strncpy (errmsg, _("result with non-constant character length")gettext ("result with non-constant character length"), err_len); |
2585 | return true; |
2586 | } |
2587 | } |
2588 | |
2589 | if (sym->attr.elemental && !sym->attr.intrinsic) /* (4) */ |
2590 | { |
2591 | strncpy (errmsg, _("elemental procedure")gettext ("elemental procedure"), err_len); |
2592 | return true; |
2593 | } |
2594 | else if (sym->attr.is_bind_c) /* (5) */ |
2595 | { |
2596 | strncpy (errmsg, _("bind(c) procedure")gettext ("bind(c) procedure"), err_len); |
2597 | return true; |
2598 | } |
2599 | |
2600 | return false; |
2601 | } |
2602 | |
2603 | |
2604 | static void |
2605 | resolve_global_procedure (gfc_symbol *sym, locus *where, int sub) |
2606 | { |
2607 | gfc_gsymbol * gsym; |
2608 | gfc_namespace *ns; |
2609 | enum gfc_symbol_type type; |
2610 | char reason[200]; |
2611 | |
2612 | type = sub ? GSYM_SUBROUTINE : GSYM_FUNCTION; |
2613 | |
2614 | gsym = gfc_get_gsymbol (sym->binding_label ? sym->binding_label : sym->name, |
2615 | sym->binding_label != NULL__null); |
2616 | |
2617 | if ((gsym->type != GSYM_UNKNOWN && gsym->type != type)) |
2618 | gfc_global_used (gsym, where); |
2619 | |
2620 | if ((sym->attr.if_source == IFSRC_UNKNOWN |
2621 | || sym->attr.if_source == IFSRC_IFBODY) |
2622 | && gsym->type != GSYM_UNKNOWN |
2623 | && !gsym->binding_label |
2624 | && gsym->ns |
2625 | && gsym->ns->proc_name |
2626 | && not_in_recursive (sym, gsym->ns) |
2627 | && not_entry_self_reference (sym, gsym->ns)) |
2628 | { |
2629 | gfc_symbol *def_sym; |
2630 | def_sym = gsym->ns->proc_name; |
2631 | |
2632 | if (gsym->ns->resolved != -1) |
2633 | { |
2634 | |
2635 | /* Resolve the gsymbol namespace if needed. */ |
2636 | if (!gsym->ns->resolved) |
2637 | { |
2638 | gfc_symbol *old_dt_list; |
2639 | |
2640 | /* Stash away derived types so that the backend_decls |
2641 | do not get mixed up. */ |
2642 | old_dt_list = gfc_derived_types; |
2643 | gfc_derived_types = NULL__null; |
2644 | |
2645 | gfc_resolve (gsym->ns); |
2646 | |
2647 | /* Store the new derived types with the global namespace. */ |
2648 | if (gfc_derived_types) |
2649 | gsym->ns->derived_types = gfc_derived_types; |
2650 | |
2651 | /* Restore the derived types of this namespace. */ |
2652 | gfc_derived_types = old_dt_list; |
2653 | } |
2654 | |
2655 | /* Make sure that translation for the gsymbol occurs before |
2656 | the procedure currently being resolved. */ |
2657 | ns = gfc_global_ns_list; |
2658 | for (; ns && ns != gsym->ns; ns = ns->sibling) |
2659 | { |
2660 | if (ns->sibling == gsym->ns) |
2661 | { |
2662 | ns->sibling = gsym->ns->sibling; |
2663 | gsym->ns->sibling = gfc_global_ns_list; |
2664 | gfc_global_ns_list = gsym->ns; |
2665 | break; |
2666 | } |
2667 | } |
2668 | |
2669 | /* This can happen if a binding name has been specified. */ |
2670 | if (gsym->binding_label && gsym->sym_name != def_sym->name) |
2671 | gfc_find_symbol (gsym->sym_name, gsym->ns, 0, &def_sym); |
2672 | |
2673 | if (def_sym->attr.entry_master || def_sym->attr.entry) |
2674 | { |
2675 | gfc_entry_list *entry; |
2676 | for (entry = gsym->ns->entries; entry; entry = entry->next) |
2677 | if (strcmp (entry->sym->name, sym->name) == 0) |
2678 | { |
2679 | def_sym = entry->sym; |
2680 | break; |
2681 | } |
2682 | } |
2683 | } |
2684 | |
2685 | if (sym->attr.function && !gfc_compare_types (&sym->ts, &def_sym->ts)) |
2686 | { |
2687 | gfc_error ("Return type mismatch of function %qs at %L (%s/%s)", |
2688 | sym->name, &sym->declared_at, gfc_typename (&sym->ts), |
2689 | gfc_typename (&def_sym->ts)); |
2690 | goto done; |
2691 | } |
2692 | |
2693 | if (sym->attr.if_source == IFSRC_UNKNOWN |
2694 | && gfc_explicit_interface_required (def_sym, reason, sizeof(reason))) |
2695 | { |
2696 | gfc_error ("Explicit interface required for %qs at %L: %s", |
2697 | sym->name, &sym->declared_at, reason); |
2698 | goto done; |
2699 | } |
2700 | |
2701 | bool bad_result_characteristics; |
2702 | if (!gfc_compare_interfaces (sym, def_sym, sym->name, 0, 1, |
2703 | reason, sizeof(reason), NULL__null, NULL__null, |
2704 | &bad_result_characteristics)) |
2705 | { |
2706 | /* Turn erros into warnings with -std=gnu and -std=legacy, |
2707 | unless a function returns a wrong type, which can lead |
2708 | to all kinds of ICEs and wrong code. */ |
2709 | |
2710 | if (!pedanticglobal_options.x_pedantic && (gfc_option.allow_std & GFC_STD_GNU(1<<5)) |
2711 | && !bad_result_characteristics) |
2712 | gfc_errors_to_warnings (true); |
2713 | |
2714 | gfc_error ("Interface mismatch in global procedure %qs at %L: %s", |
2715 | sym->name, &sym->declared_at, reason); |
2716 | sym->error = 1; |
2717 | gfc_errors_to_warnings (false); |
2718 | goto done; |
2719 | } |
2720 | } |
2721 | |
2722 | done: |
2723 | |
2724 | if (gsym->type == GSYM_UNKNOWN) |
2725 | { |
2726 | gsym->type = type; |
2727 | gsym->where = *where; |
2728 | } |
2729 | |
2730 | gsym->used = 1; |
2731 | } |
2732 | |
2733 | |
2734 | /************* Function resolution *************/ |
2735 | |
2736 | /* Resolve a function call known to be generic. |
2737 | Section 14.1.2.4.1. */ |
2738 | |
2739 | static match |
2740 | resolve_generic_f0 (gfc_expr *expr, gfc_symbol *sym) |
2741 | { |
2742 | gfc_symbol *s; |
2743 | |
2744 | if (sym->attr.generic) |
2745 | { |
2746 | s = gfc_search_interface (sym->generic, 0, &expr->value.function.actual); |
2747 | if (s != NULL__null) |
2748 | { |
2749 | expr->value.function.name = s->name; |
2750 | expr->value.function.esym = s; |
2751 | |
2752 | if (s->ts.type != BT_UNKNOWN) |
2753 | expr->ts = s->ts; |
2754 | else if (s->result != NULL__null && s->result->ts.type != BT_UNKNOWN) |
2755 | expr->ts = s->result->ts; |
2756 | |
2757 | if (s->as != NULL__null) |
2758 | expr->rank = s->as->rank; |
2759 | else if (s->result != NULL__null && s->result->as != NULL__null) |
2760 | expr->rank = s->result->as->rank; |
2761 | |
2762 | gfc_set_sym_referenced (expr->value.function.esym); |
2763 | |
2764 | return MATCH_YES; |
2765 | } |
2766 | |
2767 | /* TODO: Need to search for elemental references in generic |
2768 | interface. */ |
2769 | } |
2770 | |
2771 | if (sym->attr.intrinsic) |
2772 | return gfc_intrinsic_func_interface (expr, 0); |
2773 | |
2774 | return MATCH_NO; |
2775 | } |
2776 | |
2777 | |
2778 | static bool |
2779 | resolve_generic_f (gfc_expr *expr) |
2780 | { |
2781 | gfc_symbol *sym; |
2782 | match m; |
2783 | gfc_interface *intr = NULL__null; |
2784 | |
2785 | sym = expr->symtree->n.sym; |
2786 | |
2787 | for (;;) |
2788 | { |
2789 | m = resolve_generic_f0 (expr, sym); |
2790 | if (m == MATCH_YES) |
2791 | return true; |
2792 | else if (m == MATCH_ERROR) |
2793 | return false; |
2794 | |
2795 | generic: |
2796 | if (!intr) |
2797 | for (intr = sym->generic; intr; intr = intr->next) |
2798 | if (gfc_fl_struct (intr->sym->attr.flavor)((intr->sym->attr.flavor) == FL_DERIVED || (intr->sym ->attr.flavor) == FL_UNION || (intr->sym->attr.flavor ) == FL_STRUCT)) |
2799 | break; |
2800 | |
2801 | if (sym->ns->parent == NULL__null) |
2802 | break; |
2803 | gfc_find_symbol (sym->name, sym->ns->parent, 1, &sym); |
2804 | |
2805 | if (sym == NULL__null) |
2806 | break; |
2807 | if (!generic_sym (sym)) |
2808 | goto generic; |
2809 | } |
2810 | |
2811 | /* Last ditch attempt. See if the reference is to an intrinsic |
2812 | that possesses a matching interface. 14.1.2.4 */ |
2813 | if (sym && !intr && !gfc_is_intrinsic (sym, 0, expr->where)) |
2814 | { |
2815 | if (gfc_init_expr_flag) |
2816 | gfc_error ("Function %qs in initialization expression at %L " |
2817 | "must be an intrinsic function", |
2818 | expr->symtree->n.sym->name, &expr->where); |
2819 | else |
2820 | gfc_error ("There is no specific function for the generic %qs " |
2821 | "at %L", expr->symtree->n.sym->name, &expr->where); |
2822 | return false; |
2823 | } |
2824 | |
2825 | if (intr) |
2826 | { |
2827 | if (!gfc_convert_to_structure_constructor (expr, intr->sym, NULL__null, |
2828 | NULL__null, false)) |
2829 | return false; |
2830 | if (!gfc_use_derived (expr->ts.u.derived)) |
2831 | return false; |
2832 | return resolve_structure_cons (expr, 0); |
2833 | } |
2834 | |
2835 | m = gfc_intrinsic_func_interface (expr, 0); |
2836 | if (m == MATCH_YES) |
2837 | return true; |
2838 | |
2839 | if (m == MATCH_NO) |
2840 | gfc_error ("Generic function %qs at %L is not consistent with a " |
2841 | "specific intrinsic interface", expr->symtree->n.sym->name, |
2842 | &expr->where); |
2843 | |
2844 | return false; |
2845 | } |
2846 | |
2847 | |
2848 | /* Resolve a function call known to be specific. */ |
2849 | |
2850 | static match |
2851 | resolve_specific_f0 (gfc_symbol *sym, gfc_expr *expr) |
2852 | { |
2853 | match m; |
2854 | |
2855 | if (sym->attr.external || sym->attr.if_source == IFSRC_IFBODY) |
2856 | { |
2857 | if (sym->attr.dummy) |
2858 | { |
2859 | sym->attr.proc = PROC_DUMMY; |
2860 | goto found; |
2861 | } |
2862 | |
2863 | sym->attr.proc = PROC_EXTERNAL; |
2864 | goto found; |
2865 | } |
2866 | |
2867 | if (sym->attr.proc == PROC_MODULE |
2868 | || sym->attr.proc == PROC_ST_FUNCTION |
2869 | || sym->attr.proc == PROC_INTERNAL) |
2870 | goto found; |
2871 | |
2872 | if (sym->attr.intrinsic) |
2873 | { |
2874 | m = gfc_intrinsic_func_interface (expr, 1); |
2875 | if (m == MATCH_YES) |
2876 | return MATCH_YES; |
2877 | if (m == MATCH_NO) |
2878 | gfc_error ("Function %qs at %L is INTRINSIC but is not compatible " |
2879 | "with an intrinsic", sym->name, &expr->where); |
2880 | |
2881 | return MATCH_ERROR; |
2882 | } |
2883 | |
2884 | return MATCH_NO; |
2885 | |
2886 | found: |
2887 | gfc_procedure_use (sym, &expr->value.function.actual, &expr->where); |
2888 | |
2889 | if (sym->result) |
2890 | expr->ts = sym->result->ts; |
2891 | else |
2892 | expr->ts = sym->ts; |
2893 | expr->value.function.name = sym->name; |
2894 | expr->value.function.esym = sym; |
2895 | /* Prevent crash when sym->ts.u.derived->components is not set due to previous |
2896 | error(s). */ |
2897 | if (sym->ts.type == BT_CLASS && !CLASS_DATA (sym)sym->ts.u.derived->components) |
2898 | return MATCH_ERROR; |
2899 | if (sym->ts.type == BT_CLASS && CLASS_DATA (sym)sym->ts.u.derived->components->as) |
2900 | expr->rank = CLASS_DATA (sym)sym->ts.u.derived->components->as->rank; |
2901 | else if (sym->as != NULL__null) |
2902 | expr->rank = sym->as->rank; |
2903 | |
2904 | return MATCH_YES; |
2905 | } |
2906 | |
2907 | |
2908 | static bool |
2909 | resolve_specific_f (gfc_expr *expr) |
2910 | { |
2911 | gfc_symbol *sym; |
2912 | match m; |
2913 | |
2914 | sym = expr->symtree->n.sym; |
2915 | |
2916 | for (;;) |
2917 | { |
2918 | m = resolve_specific_f0 (sym, expr); |
2919 | if (m == MATCH_YES) |
2920 | return true; |
2921 | if (m == MATCH_ERROR) |
2922 | return false; |
2923 | |
2924 | if (sym->ns->parent == NULL__null) |
2925 | break; |
2926 | |
2927 | gfc_find_symbol (sym->name, sym->ns->parent, 1, &sym); |
2928 | |
2929 | if (sym == NULL__null) |
2930 | break; |
2931 | } |
2932 | |
2933 | gfc_error ("Unable to resolve the specific function %qs at %L", |
2934 | expr->symtree->n.sym->name, &expr->where); |
2935 | |
2936 | return true; |
2937 | } |
2938 | |
2939 | /* Recursively append candidate SYM to CANDIDATES. Store the number of |
2940 | candidates in CANDIDATES_LEN. */ |
2941 | |
2942 | static void |
2943 | lookup_function_fuzzy_find_candidates (gfc_symtree *sym, |
2944 | char **&candidates, |
2945 | size_t &candidates_len) |
2946 | { |
2947 | gfc_symtree *p; |
2948 | |
2949 | if (sym == NULL__null) |
2950 | return; |
2951 | if ((sym->n.sym->ts.type != BT_UNKNOWN || sym->n.sym->attr.external) |
2952 | && sym->n.sym->attr.flavor == FL_PROCEDURE) |
2953 | vec_push (candidates, candidates_len, sym->name); |
2954 | |
2955 | p = sym->left; |
2956 | if (p) |
2957 | lookup_function_fuzzy_find_candidates (p, candidates, candidates_len); |
2958 | |
2959 | p = sym->right; |
2960 | if (p) |
2961 | lookup_function_fuzzy_find_candidates (p, candidates, candidates_len); |
2962 | } |
2963 | |
2964 | |
2965 | /* Lookup function FN fuzzily, taking names in SYMROOT into account. */ |
2966 | |
2967 | const char* |
2968 | gfc_lookup_function_fuzzy (const char *fn, gfc_symtree *symroot) |
2969 | { |
2970 | char **candidates = NULL__null; |
2971 | size_t candidates_len = 0; |
2972 | lookup_function_fuzzy_find_candidates (symroot, candidates, candidates_len); |
2973 | return gfc_closest_fuzzy_match (fn, candidates); |
2974 | } |
2975 | |
2976 | |
2977 | /* Resolve a procedure call not known to be generic nor specific. */ |
2978 | |
2979 | static bool |
2980 | resolve_unknown_f (gfc_expr *expr) |
2981 | { |
2982 | gfc_symbol *sym; |
2983 | gfc_typespec *ts; |
2984 | |
2985 | sym = expr->symtree->n.sym; |
2986 | |
2987 | if (sym->attr.dummy) |
2988 | { |
2989 | sym->attr.proc = PROC_DUMMY; |
2990 | expr->value.function.name = sym->name; |
2991 | goto set_type; |
2992 | } |
2993 | |
2994 | /* See if we have an intrinsic function reference. */ |
2995 | |
2996 | if (gfc_is_intrinsic (sym, 0, expr->where)) |
2997 | { |
2998 | if (gfc_intrinsic_func_interface (expr, 1) == MATCH_YES) |
2999 | return true; |
3000 | return false; |
3001 | } |
3002 | |
3003 | /* IMPLICIT NONE (external) procedures require an explicit EXTERNAL attr. */ |
3004 | /* Intrinsics were handled above, only non-intrinsics left here. */ |
3005 | if (sym->attr.flavor == FL_PROCEDURE |
3006 | && sym->attr.implicit_type |
3007 | && sym->ns |
3008 | && sym->ns->has_implicit_none_export) |
3009 | { |
3010 | gfc_error ("Missing explicit declaration with EXTERNAL attribute " |
3011 | "for symbol %qs at %L", sym->name, &sym->declared_at); |
3012 | sym->error = 1; |
3013 | return false; |
3014 | } |
3015 | |
3016 | /* The reference is to an external name. */ |
3017 | |
3018 | sym->attr.proc = PROC_EXTERNAL; |
3019 | expr->value.function.name = sym->name; |
3020 | expr->value.function.esym = expr->symtree->n.sym; |
3021 | |
3022 | if (sym->as != NULL__null) |
3023 | expr->rank = sym->as->rank; |
3024 | |
3025 | /* Type of the expression is either the type of the symbol or the |
3026 | default type of the symbol. */ |
3027 | |
3028 | set_type: |
3029 | gfc_procedure_use (sym, &expr->value.function.actual, &expr->where); |
3030 | |
3031 | if (sym->ts.type != BT_UNKNOWN) |
3032 | expr->ts = sym->ts; |
3033 | else |
3034 | { |
3035 | ts = gfc_get_default_type (sym->name, sym->ns); |
3036 | |
3037 | if (ts->type == BT_UNKNOWN) |
3038 | { |
3039 | const char *guessed |
3040 | = gfc_lookup_function_fuzzy (sym->name, sym->ns->sym_root); |
3041 | if (guessed) |
3042 | gfc_error ("Function %qs at %L has no IMPLICIT type" |
3043 | "; did you mean %qs?", |
3044 | sym->name, &expr->where, guessed); |
3045 | else |
3046 | gfc_error ("Function %qs at %L has no IMPLICIT type", |
3047 | sym->name, &expr->where); |
3048 | return false; |
3049 | } |
3050 | else |
3051 | expr->ts = *ts; |
3052 | } |
3053 | |
3054 | return true; |
3055 | } |
3056 | |
3057 | |
3058 | /* Return true, if the symbol is an external procedure. */ |
3059 | static bool |
3060 | is_external_proc (gfc_symbol *sym) |
3061 | { |
3062 | if (!sym->attr.dummy && !sym->attr.contained |
3063 | && !gfc_is_intrinsic (sym, sym->attr.subroutine, sym->declared_at) |
3064 | && sym->attr.proc != PROC_ST_FUNCTION |
3065 | && !sym->attr.proc_pointer |
3066 | && !sym->attr.use_assoc |
3067 | && sym->name) |
3068 | return true; |
3069 | |
3070 | return false; |
3071 | } |
3072 | |
3073 | |
3074 | /* Figure out if a function reference is pure or not. Also set the name |
3075 | of the function for a potential error message. Return nonzero if the |
3076 | function is PURE, zero if not. */ |
3077 | static int |
3078 | pure_stmt_function (gfc_expr *, gfc_symbol *); |
3079 | |
3080 | int |
3081 | gfc_pure_function (gfc_expr *e, const char **name) |
3082 | { |
3083 | int pure; |
3084 | gfc_component *comp; |
3085 | |
3086 | *name = NULL__null; |
3087 | |
3088 | if (e->symtree != NULL__null |
3089 | && e->symtree->n.sym != NULL__null |
3090 | && e->symtree->n.sym->attr.proc == PROC_ST_FUNCTION) |
3091 | return pure_stmt_function (e, e->symtree->n.sym); |
3092 | |
3093 | comp = gfc_get_proc_ptr_comp (e); |
3094 | if (comp) |
3095 | { |
3096 | pure = gfc_pure (comp->ts.interface); |
3097 | *name = comp->name; |
3098 | } |
3099 | else if (e->value.function.esym) |
3100 | { |
3101 | pure = gfc_pure (e->value.function.esym); |
3102 | *name = e->value.function.esym->name; |
3103 | } |
3104 | else if (e->value.function.isym) |
3105 | { |
3106 | pure = e->value.function.isym->pure |
3107 | || e->value.function.isym->elemental; |
3108 | *name = e->value.function.isym->name; |
3109 | } |
3110 | else |
3111 | { |
3112 | /* Implicit functions are not pure. */ |
3113 | pure = 0; |
3114 | *name = e->value.function.name; |
3115 | } |
3116 | |
3117 | return pure; |
3118 | } |
3119 | |
3120 | |
3121 | /* Check if the expression is a reference to an implicitly pure function. */ |
3122 | |
3123 | int |
3124 | gfc_implicit_pure_function (gfc_expr *e) |
3125 | { |
3126 | gfc_component *comp = gfc_get_proc_ptr_comp (e); |
3127 | if (comp) |
3128 | return gfc_implicit_pure (comp->ts.interface); |
3129 | else if (e->value.function.esym) |
3130 | return gfc_implicit_pure (e->value.function.esym); |
3131 | else |
3132 | return 0; |
3133 | } |
3134 | |
3135 | |
3136 | static bool |
3137 | impure_stmt_fcn (gfc_expr *e, gfc_symbol *sym, |
3138 | int *f ATTRIBUTE_UNUSED__attribute__ ((__unused__))) |
3139 | { |
3140 | const char *name; |
3141 | |
3142 | /* Don't bother recursing into other statement functions |
3143 | since they will be checked individually for purity. */ |
3144 | if (e->expr_type != EXPR_FUNCTION |
3145 | || !e->symtree |
3146 | || e->symtree->n.sym == sym |
3147 | || e->symtree->n.sym->attr.proc == PROC_ST_FUNCTION) |
3148 | return false; |
3149 | |
3150 | return gfc_pure_function (e, &name) ? false : true; |
3151 | } |
3152 | |
3153 | |
3154 | static int |
3155 | pure_stmt_function (gfc_expr *e, gfc_symbol *sym) |
3156 | { |
3157 | return gfc_traverse_expr (e, sym, impure_stmt_fcn, 0) ? 0 : 1; |
3158 | } |
3159 | |
3160 | |
3161 | /* Check if an impure function is allowed in the current context. */ |
3162 | |
3163 | static bool check_pure_function (gfc_expr *e) |
3164 | { |
3165 | const char *name = NULL__null; |
3166 | if (!gfc_pure_function (e, &name) && name) |
3167 | { |
3168 | if (forall_flag) |
3169 | { |
3170 | gfc_error ("Reference to impure function %qs at %L inside a " |
3171 | "FORALL %s", name, &e->where, |
3172 | forall_flag == 2 ? "mask" : "block"); |
3173 | return false; |
3174 | } |
3175 | else if (gfc_do_concurrent_flag) |
3176 | { |
3177 | gfc_error ("Reference to impure function %qs at %L inside a " |
3178 | "DO CONCURRENT %s", name, &e->where, |
3179 | gfc_do_concurrent_flag == 2 ? "mask" : "block"); |
3180 | return false; |
3181 | } |
3182 | else if (gfc_pure (NULL__null)) |
3183 | { |
3184 | gfc_error ("Reference to impure function %qs at %L " |
3185 | "within a PURE procedure", name, &e->where); |
3186 | return false; |
3187 | } |
3188 | if (!gfc_implicit_pure_function (e)) |
3189 | gfc_unset_implicit_pure (NULL__null); |
3190 | } |
3191 | return true; |
3192 | } |
3193 | |
3194 | |
3195 | /* Update current procedure's array_outer_dependency flag, considering |
3196 | a call to procedure SYM. */ |
3197 | |
3198 | static void |
3199 | update_current_proc_array_outer_dependency (gfc_symbol *sym) |
3200 | { |
3201 | /* Check to see if this is a sibling function that has not yet |
3202 | been resolved. */ |
3203 | gfc_namespace *sibling = gfc_current_ns->sibling; |
3204 | for (; sibling; sibling = sibling->sibling) |
3205 | { |
3206 | if (sibling->proc_name == sym) |
3207 | { |
3208 | gfc_resolve (sibling); |
3209 | break; |
3210 | } |
3211 | } |
3212 | |
3213 | /* If SYM has references to outer arrays, so has the procedure calling |
3214 | SYM. If SYM is a procedure pointer, we can assume the worst. */ |
3215 | if ((sym->attr.array_outer_dependency || sym->attr.proc_pointer) |
3216 | && gfc_current_ns->proc_name) |
3217 | gfc_current_ns->proc_name->attr.array_outer_dependency = 1; |
3218 | } |
3219 | |
3220 | |
3221 | /* Resolve a function call, which means resolving the arguments, then figuring |
3222 | out which entity the name refers to. */ |
3223 | |
3224 | static bool |
3225 | resolve_function (gfc_expr *expr) |
3226 | { |
3227 | gfc_actual_arglist *arg; |
3228 | gfc_symbol *sym; |
3229 | bool t; |
3230 | int temp; |
3231 | procedure_type p = PROC_INTRINSIC; |
3232 | bool no_formal_args; |
3233 | |
3234 | sym = NULL__null; |
3235 | if (expr->symtree) |
3236 | sym = expr->symtree->n.sym; |
3237 | |
3238 | /* If this is a procedure pointer component, it has already been resolved. */ |
3239 | if (gfc_is_proc_ptr_comp (expr)) |
3240 | return true; |
3241 | |
3242 | /* Avoid re-resolving the arguments of caf_get, which can lead to inserting |
3243 | another caf_get. */ |
3244 | if (sym && sym->attr.intrinsic |
3245 | && (sym->intmod_sym_id == GFC_ISYM_CAF_GET |
3246 | || sym->intmod_sym_id == GFC_ISYM_CAF_SEND)) |
3247 | return true; |
3248 | |
3249 | if (expr->ref) |
3250 | { |
3251 | gfc_error ("Unexpected junk after %qs at %L", expr->symtree->n.sym->name, |
3252 | &expr->where); |
3253 | return false; |
3254 | } |
3255 | |
3256 | if (sym && sym->attr.intrinsic |
3257 | && !gfc_resolve_intrinsic (sym, &expr->where)) |
3258 | return false; |
3259 | |
3260 | if (sym && (sym->attr.flavor == FL_VARIABLE || sym->attr.subroutine)) |
3261 | { |
3262 | gfc_error ("%qs at %L is not a function", sym->name, &expr->where); |
3263 | return false; |
3264 | } |
3265 | |
3266 | /* If this is a deferred TBP with an abstract interface (which may |
3267 | of course be referenced), expr->value.function.esym will be set. */ |
3268 | if (sym && sym->attr.abstract && !expr->value.function.esym) |
3269 | { |
3270 | gfc_error ("ABSTRACT INTERFACE %qs must not be referenced at %L", |
3271 | sym->name, &expr->where); |
3272 | return false; |
3273 | } |
3274 | |
3275 | /* If this is a deferred TBP with an abstract interface, its result |
3276 | cannot be an assumed length character (F2003: C418). */ |
3277 | if (sym && sym->attr.abstract && sym->attr.function |
3278 | && sym->result->ts.u.cl |
3279 | && sym->result->ts.u.cl->length == NULL__null |
3280 | && !sym->result->ts.deferred) |
3281 | { |
3282 | gfc_error ("ABSTRACT INTERFACE %qs at %L must not have an assumed " |
3283 | "character length result (F2008: C418)", sym->name, |
3284 | &sym->declared_at); |
3285 | return false; |
3286 | } |
3287 | |
3288 | /* Switch off assumed size checking and do this again for certain kinds |
3289 | of procedure, once the procedure itself is resolved. */ |
3290 | need_full_assumed_size++; |
3291 | |
3292 | if (expr->symtree && expr->symtree->n.sym) |
3293 | p = expr->symtree->n.sym->attr.proc; |
3294 | |
3295 | if (expr->value.function.isym && expr->value.function.isym->inquiry) |
3296 | inquiry_argument = true; |
3297 | no_formal_args = sym && is_external_proc (sym) |
3298 | && gfc_sym_get_dummy_args (sym) == NULL__null; |
3299 | |
3300 | if (!resolve_actual_arglist (expr->value.function.actual, |
3301 | p, no_formal_args)) |
3302 | { |
3303 | inquiry_argument = false; |
3304 | return false; |
3305 | } |
3306 | |
3307 | inquiry_argument = false; |
3308 | |
3309 | /* Resume assumed_size checking. */ |
3310 | need_full_assumed_size--; |
3311 | |
3312 | /* If the procedure is external, check for usage. */ |
3313 | if (sym && is_external_proc (sym)) |
3314 | resolve_global_procedure (sym, &expr->where, 0); |
3315 | |
3316 | if (sym && sym->ts.type == BT_CHARACTER |
3317 | && sym->ts.u.cl |
3318 | && sym->ts.u.cl->length == NULL__null |
3319 | && !sym->attr.dummy |
3320 | && !sym->ts.deferred |
3321 | && expr->value.function.esym == NULL__null |
3322 | && !sym->attr.contained) |
3323 | { |
3324 | /* Internal procedures are taken care of in resolve_contained_fntype. */ |
3325 | gfc_error ("Function %qs is declared CHARACTER(*) and cannot " |
3326 | "be used at %L since it is not a dummy argument", |
3327 | sym->name, &expr->where); |
3328 | return false; |
3329 | } |
3330 | |
3331 | /* See if function is already resolved. */ |
3332 | |
3333 | if (expr->value.function.name != NULL__null |
3334 | || expr->value.function.isym != NULL__null) |
3335 | { |
3336 | if (expr->ts.type == BT_UNKNOWN) |
3337 | expr->ts = sym->ts; |
3338 | t = true; |
3339 | } |
3340 | else |
3341 | { |
3342 | /* Apply the rules of section 14.1.2. */ |
3343 | |
3344 | switch (procedure_kind (sym)) |
3345 | { |
3346 | case PTYPE_GENERIC: |
3347 | t = resolve_generic_f (expr); |
3348 | break; |
3349 | |
3350 | case PTYPE_SPECIFIC: |
3351 | t = resolve_specific_f (expr); |
3352 | break; |
3353 | |
3354 | case PTYPE_UNKNOWN: |
3355 | t = resolve_unknown_f (expr); |
3356 | break; |
3357 | |
3358 | default: |
3359 | gfc_internal_error ("resolve_function(): bad function type"); |
3360 | } |
3361 | } |
3362 | |
3363 | /* If the expression is still a function (it might have simplified), |
3364 | then we check to see if we are calling an elemental function. */ |
3365 | |
3366 | if (expr->expr_type != EXPR_FUNCTION) |
3367 | return t; |
3368 | |
3369 | /* Walk the argument list looking for invalid BOZ. */ |
3370 | for (arg = expr->value.function.actual; arg; arg = arg->next) |
3371 | if (arg->expr && arg->expr->ts.type == BT_BOZ) |
3372 | { |
3373 | gfc_error ("A BOZ literal constant at %L cannot appear as an " |
3374 | "actual argument in a function reference", |
3375 | &arg->expr->where); |
3376 | return false; |
3377 | } |
3378 | |
3379 | temp = need_full_assumed_size; |
3380 | need_full_assumed_size = 0; |
3381 | |
3382 | if (!resolve_elemental_actual (expr, NULL__null)) |
3383 | return false; |
3384 | |
3385 | if (omp_workshare_flag |
3386 | && expr->value.function.esym |
3387 | && ! gfc_elemental (expr->value.function.esym)) |
3388 | { |
3389 | gfc_error ("User defined non-ELEMENTAL function %qs at %L not allowed " |
3390 | "in WORKSHARE construct", expr->value.function.esym->name, |
3391 | &expr->where); |
3392 | t = false; |
3393 | } |
3394 | |
3395 | #define GENERIC_ID expr->value.function.isym->id |
3396 | else if (expr->value.function.actual != NULL__null |
3397 | && expr->value.function.isym != NULL__null |
3398 | && GENERIC_ID != GFC_ISYM_LBOUND |
3399 | && GENERIC_ID != GFC_ISYM_LCOBOUND |
3400 | && GENERIC_ID != GFC_ISYM_UCOBOUND |
3401 | && GENERIC_ID != GFC_ISYM_LEN |
3402 | && GENERIC_ID != GFC_ISYM_LOC |
3403 | && GENERIC_ID != GFC_ISYM_C_LOC |
3404 | && GENERIC_ID != GFC_ISYM_PRESENT) |
3405 | { |
3406 | /* Array intrinsics must also have the last upper bound of an |
3407 | assumed size array argument. UBOUND and SIZE have to be |
3408 | excluded from the check if the second argument is anything |
3409 | than a constant. */ |
3410 | |
3411 | for (arg = expr->value.function.actual; arg; arg = arg->next) |
3412 | { |
3413 | if ((GENERIC_ID == GFC_ISYM_UBOUND || GENERIC_ID == GFC_ISYM_SIZE) |
3414 | && arg == expr->value.function.actual |
3415 | && arg->next != NULL__null && arg->next->expr) |
3416 | { |
3417 | if (arg->next->expr->expr_type != EXPR_CONSTANT) |
3418 | break; |
3419 | |
3420 | if (arg->next->name && strcmp (arg->next->name, "kind") == 0) |
3421 | break; |
3422 | |
3423 | if ((int)mpz_get_si__gmpz_get_si (arg->next->expr->value.integer) |
3424 | < arg->expr->rank) |
3425 | break; |
3426 | } |
3427 | |
3428 | if (arg->expr != NULL__null |
3429 | && arg->expr->rank > 0 |
3430 | && resolve_assumed_size_actual (arg->expr)) |
3431 | return false; |
3432 | } |
3433 | } |
3434 | #undef GENERIC_ID |
3435 | |
3436 | need_full_assumed_size = temp; |
3437 | |
3438 | if (!check_pure_function(expr)) |
3439 | t = false; |
3440 | |
3441 | /* Functions without the RECURSIVE attribution are not allowed to |
3442 | * call themselves. */ |
3443 | if (expr->value.function.esym && !expr->value.function.esym->attr.recursive) |
3444 | { |
3445 | gfc_symbol *esym; |
3446 | esym = expr->value.function.esym; |
3447 | |
3448 | if (is_illegal_recursion (esym, gfc_current_ns)) |
3449 | { |
3450 | if (esym->attr.entry && esym->ns->entries) |
3451 | gfc_error ("ENTRY %qs at %L cannot be called recursively, as" |
3452 | " function %qs is not RECURSIVE", |
3453 | esym->name, &expr->where, esym->ns->entries->sym->name); |
3454 | else |
3455 | gfc_error ("Function %qs at %L cannot be called recursively, as it" |
3456 | " is not RECURSIVE", esym->name, &expr->where); |
3457 | |
3458 | t = false; |
3459 | } |
3460 | } |
3461 | |
3462 | /* Character lengths of use associated functions may contains references to |
3463 | symbols not referenced from the current program unit otherwise. Make sure |
3464 | those symbols are marked as referenced. */ |
3465 | |
3466 | if (expr->ts.type == BT_CHARACTER && expr->value.function.esym |
3467 | && expr->value.function.esym->attr.use_assoc) |
3468 | { |
3469 | gfc_expr_set_symbols_referenced (expr->ts.u.cl->length); |
3470 | } |
3471 | |
3472 | /* Make sure that the expression has a typespec that works. */ |
3473 | if (expr->ts.type == BT_UNKNOWN) |
3474 | { |
3475 | if (expr->symtree->n.sym->result |
3476 | && expr->symtree->n.sym->result->ts.type != BT_UNKNOWN |
3477 | && !expr->symtree->n.sym->result->attr.proc_pointer) |
3478 | expr->ts = expr->symtree->n.sym->result->ts; |
3479 | } |
3480 | |
3481 | /* These derived types with an incomplete namespace, arising from use |
3482 | association, cause gfc_get_derived_vtab to segfault. If the function |
3483 | namespace does not suffice, something is badly wrong. */ |
3484 | if (expr->ts.type == BT_DERIVED |
3485 | && !expr->ts.u.derived->ns->proc_name) |
3486 | { |
3487 | gfc_symbol *der; |
3488 | gfc_find_symbol (expr->ts.u.derived->name, expr->symtree->n.sym->ns, 1, &der); |
3489 | if (der) |
3490 | { |
3491 | expr->ts.u.derived->refs--; |
3492 | expr->ts.u.derived = der; |
3493 | der->refs++; |
3494 | } |
3495 | else |
3496 | expr->ts.u.derived->ns = expr->symtree->n.sym->ns; |
3497 | } |
3498 | |
3499 | if (!expr->ref && !expr->value.function.isym) |
3500 | { |
3501 | if (expr->value.function.esym) |
3502 | update_current_proc_array_outer_dependency (expr->value.function.esym); |
3503 | else |
3504 | update_current_proc_array_outer_dependency (sym); |
3505 | } |
3506 | else if (expr->ref) |
3507 | /* typebound procedure: Assume the worst. */ |
3508 | gfc_current_ns->proc_name->attr.array_outer_dependency = 1; |
3509 | |
3510 | if (expr->value.function.esym |
3511 | && expr->value.function.esym->attr.ext_attr & (1 << EXT_ATTR_DEPRECATED)) |
3512 | gfc_warning (OPT_Wdeprecated_declarations, |
3513 | "Using function %qs at %L is deprecated", |
3514 | sym->name, &expr->where); |
3515 | return t; |
3516 | } |
3517 | |
3518 | |
3519 | /************* Subroutine resolution *************/ |
3520 | |
3521 | static bool |
3522 | pure_subroutine (gfc_symbol *sym, const char *name, locus *loc) |
3523 | { |
3524 | if (gfc_pure (sym)) |
3525 | return true; |
3526 | |
3527 | if (forall_flag) |
3528 | { |
3529 | gfc_error ("Subroutine call to %qs in FORALL block at %L is not PURE", |
3530 | name, loc); |
3531 | return false; |
3532 | } |
3533 | else if (gfc_do_concurrent_flag) |
3534 | { |
3535 | gfc_error ("Subroutine call to %qs in DO CONCURRENT block at %L is not " |
3536 | "PURE", name, loc); |
3537 | return false; |
3538 | } |
3539 | else if (gfc_pure (NULL__null)) |
3540 | { |
3541 | gfc_error ("Subroutine call to %qs at %L is not PURE", name, loc); |
3542 | return false; |
3543 | } |
3544 | |
3545 | gfc_unset_implicit_pure (NULL__null); |
3546 | return true; |
3547 | } |
3548 | |
3549 | |
3550 | static match |
3551 | resolve_generic_s0 (gfc_code *c, gfc_symbol *sym) |
3552 | { |
3553 | gfc_symbol *s; |
3554 | |
3555 | if (sym->attr.generic) |
3556 | { |
3557 | s = gfc_search_interface (sym->generic, 1, &c->ext.actual); |
3558 | if (s != NULL__null) |
3559 | { |
3560 | c->resolved_sym = s; |
3561 | if (!pure_subroutine (s, s->name, &c->loc)) |
3562 | return MATCH_ERROR; |
3563 | return MATCH_YES; |
3564 | } |
3565 | |
3566 | /* TODO: Need to search for elemental references in generic interface. */ |
3567 | } |
3568 | |
3569 | if (sym->attr.intrinsic) |
3570 | return gfc_intrinsic_sub_interface (c, 0); |
3571 | |
3572 | return MATCH_NO; |
3573 | } |
3574 | |
3575 | |
3576 | static bool |
3577 | resolve_generic_s (gfc_code *c) |
3578 | { |
3579 | gfc_symbol *sym; |
3580 | match m; |
3581 | |
3582 | sym = c->symtree->n.sym; |
3583 | |
3584 | for (;;) |
3585 | { |
3586 | m = resolve_generic_s0 (c, sym); |
3587 | if (m == MATCH_YES) |
3588 | return true; |
3589 | else if (m == MATCH_ERROR) |
3590 | return false; |
3591 | |
3592 | generic: |
3593 | if (sym->ns->parent == NULL__null) |
3594 | break; |
3595 | gfc_find_symbol (sym->name, sym->ns->parent, 1, &sym); |
3596 | |
3597 | if (sym == NULL__null) |
3598 | break; |
3599 | if (!generic_sym (sym)) |
3600 | goto generic; |
3601 | } |
3602 | |
3603 | /* Last ditch attempt. See if the reference is to an intrinsic |
3604 | that possesses a matching interface. 14.1.2.4 */ |
3605 | sym = c->symtree->n.sym; |
3606 | |
3607 | if (!gfc_is_intrinsic (sym, 1, c->loc)) |
3608 | { |
3609 | gfc_error ("There is no specific subroutine for the generic %qs at %L", |
3610 | sym->name, &c->loc); |
3611 | return false; |
3612 | } |
3613 | |
3614 | m = gfc_intrinsic_sub_interface (c, 0); |
3615 | if (m == MATCH_YES) |
3616 | return true; |
3617 | if (m == MATCH_NO) |
3618 | gfc_error ("Generic subroutine %qs at %L is not consistent with an " |
3619 | "intrinsic subroutine interface", sym->name, &c->loc); |
3620 | |
3621 | return false; |
3622 | } |
3623 | |
3624 | |
3625 | /* Resolve a subroutine call known to be specific. */ |
3626 | |
3627 | static match |
3628 | resolve_specific_s0 (gfc_code *c, gfc_symbol *sym) |
3629 | { |
3630 | match m; |
3631 | |
3632 | if (sym->attr.external || sym->attr.if_source == IFSRC_IFBODY) |
3633 | { |
3634 | if (sym->attr.dummy) |
3635 | { |
3636 | sym->attr.proc = PROC_DUMMY; |
3637 | goto found; |
3638 | } |
3639 | |
3640 | sym->attr.proc = PROC_EXTERNAL; |
3641 | goto found; |
3642 | } |
3643 | |
3644 | if (sym->attr.proc == PROC_MODULE || sym->attr.proc == PROC_INTERNAL) |
3645 | goto found; |
3646 | |
3647 | if (sym->attr.intrinsic) |
3648 | { |
3649 | m = gfc_intrinsic_sub_interface (c, 1); |
3650 | if (m == MATCH_YES) |
3651 | return MATCH_YES; |
3652 | if (m == MATCH_NO) |
3653 | gfc_error ("Subroutine %qs at %L is INTRINSIC but is not compatible " |
3654 | "with an intrinsic", sym->name, &c->loc); |
3655 | |
3656 | return MATCH_ERROR; |
3657 | } |
3658 | |
3659 | return MATCH_NO; |
3660 | |
3661 | found: |
3662 | gfc_procedure_use (sym, &c->ext.actual, &c->loc); |
3663 | |
3664 | c->resolved_sym = sym; |
3665 | if (!pure_subroutine (sym, sym->name, &c->loc)) |
3666 | return MATCH_ERROR; |
3667 | |
3668 | return MATCH_YES; |
3669 | } |
3670 | |
3671 | |
3672 | static bool |
3673 | resolve_specific_s (gfc_code *c) |
3674 | { |
3675 | gfc_symbol *sym; |
3676 | match m; |
3677 | |
3678 | sym = c->symtree->n.sym; |
3679 | |
3680 | for (;;) |
3681 | { |
3682 | m = resolve_specific_s0 (c, sym); |
3683 | if (m == MATCH_YES) |
3684 | return true; |
3685 | if (m == MATCH_ERROR) |
3686 | return false; |
3687 | |
3688 | if (sym->ns->parent == NULL__null) |
3689 | break; |
3690 | |
3691 | gfc_find_symbol (sym->name, sym->ns->parent, 1, &sym); |
3692 | |
3693 | if (sym == NULL__null) |
3694 | break; |
3695 | } |
3696 | |
3697 | sym = c->symtree->n.sym; |
3698 | gfc_error ("Unable to resolve the specific subroutine %qs at %L", |
3699 | sym->name, &c->loc); |
3700 | |
3701 | return false; |
3702 | } |
3703 | |
3704 | |
3705 | /* Resolve a subroutine call not known to be generic nor specific. */ |
3706 | |
3707 | static bool |
3708 | resolve_unknown_s (gfc_code *c) |
3709 | { |
3710 | gfc_symbol *sym; |
3711 | |
3712 | sym = c->symtree->n.sym; |
3713 | |
3714 | if (sym->attr.dummy) |
3715 | { |
3716 | sym->attr.proc = PROC_DUMMY; |
3717 | goto found; |
3718 | } |
3719 | |
3720 | /* See if we have an intrinsic function reference. */ |
3721 | |
3722 | if (gfc_is_intrinsic (sym, 1, c->loc)) |
3723 | { |
3724 | if (gfc_intrinsic_sub_interface (c, 1) == MATCH_YES) |
3725 | return true; |
3726 | return false; |
3727 | } |
3728 | |
3729 | /* The reference is to an external name. */ |
3730 | |
3731 | found: |
3732 | gfc_procedure_use (sym, &c->ext.actual, &c->loc); |
3733 | |
3734 | c->resolved_sym = sym; |
3735 | |
3736 | return pure_subroutine (sym, sym->name, &c->loc); |
3737 | } |
3738 | |
3739 | |
3740 | /* Resolve a subroutine call. Although it was tempting to use the same code |
3741 | for functions, subroutines and functions are stored differently and this |
3742 | makes things awkward. */ |
3743 | |
3744 | static bool |
3745 | resolve_call (gfc_code *c) |
3746 | { |
3747 | bool t; |
3748 | procedure_type ptype = PROC_INTRINSIC; |
3749 | gfc_symbol *csym, *sym; |
3750 | bool no_formal_args; |
3751 | |
3752 | csym = c->symtree ? c->symtree->n.sym : NULL__null; |
3753 | |
3754 | if (csym && csym->ts.type != BT_UNKNOWN) |
3755 | { |
3756 | gfc_error ("%qs at %L has a type, which is not consistent with " |
3757 | "the CALL at %L", csym->name, &csym->declared_at, &c->loc); |
3758 | return false; |
3759 | } |
3760 | |
3761 | if (csym && gfc_current_ns->parent && csym->ns != gfc_current_ns) |
3762 | { |
3763 | gfc_symtree *st; |
3764 | gfc_find_sym_tree (c->symtree->name, gfc_current_ns, 1, &st); |
3765 | sym = st ? st->n.sym : NULL__null; |
3766 | if (sym && csym != sym |
3767 | && sym->ns == gfc_current_ns |
3768 | && sym->attr.flavor == FL_PROCEDURE |
3769 | && sym->attr.contained) |
3770 | { |
3771 | sym->refs++; |
3772 | if (csym->attr.generic) |
3773 | c->symtree->n.sym = sym; |
3774 | else |
3775 | c->symtree = st; |
3776 | csym = c->symtree->n.sym; |
3777 | } |
3778 | } |
3779 | |
3780 | /* If this ia a deferred TBP, c->expr1 will be set. */ |
3781 | if (!c->expr1 && csym) |
3782 | { |
3783 | if (csym->attr.abstract) |
3784 | { |
3785 | gfc_error ("ABSTRACT INTERFACE %qs must not be referenced at %L", |
3786 | csym->name, &c->loc); |
3787 | return false; |
3788 | } |
3789 | |
3790 | /* Subroutines without the RECURSIVE attribution are not allowed to |
3791 | call themselves. */ |
3792 | if (is_illegal_recursion (csym, gfc_current_ns)) |
3793 | { |
3794 | if (csym->attr.entry && csym->ns->entries) |
3795 | gfc_error ("ENTRY %qs at %L cannot be called recursively, " |
3796 | "as subroutine %qs is not RECURSIVE", |
3797 | csym->name, &c->loc, csym->ns->entries->sym->name); |
3798 | else |
3799 | gfc_error ("SUBROUTINE %qs at %L cannot be called recursively, " |
3800 | "as it is not RECURSIVE", csym->name, &c->loc); |
3801 | |
3802 | t = false; |
3803 | } |
3804 | } |
3805 | |
3806 | /* Switch off assumed size checking and do this again for certain kinds |
3807 | of procedure, once the procedure itself is resolved. */ |
3808 | need_full_assumed_size++; |
3809 | |
3810 | if (csym) |
3811 | ptype = csym->attr.proc; |
3812 | |
3813 | no_formal_args = csym && is_external_proc (csym) |
3814 | && gfc_sym_get_dummy_args (csym) == NULL__null; |
3815 | if (!resolve_actual_arglist (c->ext.actual, ptype, no_formal_args)) |
3816 | return false; |
3817 | |
3818 | /* Resume assumed_size checking. */ |
3819 | need_full_assumed_size--; |
3820 | |
3821 | /* If external, check for usage. */ |
3822 | if (csym && is_external_proc (csym)) |
3823 | resolve_global_procedure (csym, &c->loc, 1); |
3824 | |
3825 | t = true; |
3826 | if (c->resolved_sym == NULL__null) |
3827 | { |
3828 | c->resolved_isym = NULL__null; |
3829 | switch (procedure_kind (csym)) |
3830 | { |
3831 | case PTYPE_GENERIC: |
3832 | t = resolve_generic_s (c); |
3833 | break; |
3834 | |
3835 | case PTYPE_SPECIFIC: |
3836 | t = resolve_specific_s (c); |
3837 | break; |
3838 | |
3839 | case PTYPE_UNKNOWN: |
3840 | t = resolve_unknown_s (c); |
3841 | break; |
3842 | |
3843 | default: |
3844 | gfc_internal_error ("resolve_subroutine(): bad function type"); |
3845 | } |
3846 | } |
3847 | |
3848 | /* Some checks of elemental subroutine actual arguments. */ |
3849 | if (!resolve_elemental_actual (NULL__null, c)) |
3850 | return false; |
3851 | |
3852 | if (!c->expr1) |
3853 | update_current_proc_array_outer_dependency (csym); |
3854 | else |
3855 | /* Typebound procedure: Assume the worst. */ |
3856 | gfc_current_ns->proc_name->attr.array_outer_dependency = 1; |
3857 | |
3858 | if (c->resolved_sym |
3859 | && c->resolved_sym->attr.ext_attr & (1 << EXT_ATTR_DEPRECATED)) |
3860 | gfc_warning (OPT_Wdeprecated_declarations, |
3861 | "Using subroutine %qs at %L is deprecated", |
3862 | c->resolved_sym->name, &c->loc); |
3863 | |
3864 | return t; |
3865 | } |
3866 | |
3867 | |
3868 | /* Compare the shapes of two arrays that have non-NULL shapes. If both |
3869 | op1->shape and op2->shape are non-NULL return true if their shapes |
3870 | match. If both op1->shape and op2->shape are non-NULL return false |
3871 | if their shapes do not match. If either op1->shape or op2->shape is |
3872 | NULL, return true. */ |
3873 | |
3874 | static bool |
3875 | compare_shapes (gfc_expr *op1, gfc_expr *op2) |
3876 | { |
3877 | bool t; |
3878 | int i; |
3879 | |
3880 | t = true; |
3881 | |
3882 | if (op1->shape != NULL__null && op2->shape != NULL__null) |
3883 | { |
3884 | for (i = 0; i < op1->rank; i++) |
3885 | { |
3886 | if (mpz_cmp__gmpz_cmp (op1->shape[i], op2->shape[i]) != 0) |
3887 | { |
3888 | gfc_error ("Shapes for operands at %L and %L are not conformable", |
3889 | &op1->where, &op2->where); |
3890 | t = false; |
3891 | break; |
3892 | } |
3893 | } |
3894 | } |
3895 | |
3896 | return t; |
3897 | } |
3898 | |
3899 | /* Convert a logical operator to the corresponding bitwise intrinsic call. |
3900 | For example A .AND. B becomes IAND(A, B). */ |
3901 | static gfc_expr * |
3902 | logical_to_bitwise (gfc_expr *e) |
3903 | { |
3904 | gfc_expr *tmp, *op1, *op2; |
3905 | gfc_isym_id isym; |
3906 | gfc_actual_arglist *args = NULL__null; |
3907 | |
3908 | gcc_assert (e->expr_type == EXPR_OP)((void)(!(e->expr_type == EXPR_OP) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 3908, __FUNCTION__), 0 : 0)); |
3909 | |
3910 | isym = GFC_ISYM_NONE; |
Value stored to 'isym' is never read | |
3911 | op1 = e->value.op.op1; |
3912 | op2 = e->value.op.op2; |
3913 | |
3914 | switch (e->value.op.op) |
3915 | { |
3916 | case INTRINSIC_NOT: |
3917 | isym = GFC_ISYM_NOT; |
3918 | break; |
3919 | case INTRINSIC_AND: |
3920 | isym = GFC_ISYM_IAND; |
3921 | break; |
3922 | case INTRINSIC_OR: |
3923 | isym = GFC_ISYM_IOR; |
3924 | break; |
3925 | case INTRINSIC_NEQV: |
3926 | isym = GFC_ISYM_IEOR; |
3927 | break; |
3928 | case INTRINSIC_EQV: |
3929 | /* "Bitwise eqv" is just the complement of NEQV === IEOR. |
3930 | Change the old expression to NEQV, which will get replaced by IEOR, |
3931 | and wrap it in NOT. */ |
3932 | tmp = gfc_copy_expr (e); |
3933 | tmp->value.op.op = INTRINSIC_NEQV; |
3934 | tmp = logical_to_bitwise (tmp); |
3935 | isym = GFC_ISYM_NOT; |
3936 | op1 = tmp; |
3937 | op2 = NULL__null; |
3938 | break; |
3939 | default: |
3940 | gfc_internal_error ("logical_to_bitwise(): Bad intrinsic"); |
3941 | } |
3942 | |
3943 | /* Inherit the original operation's operands as arguments. */ |
3944 | args = gfc_get_actual_arglist ()((gfc_actual_arglist *) xcalloc (1, sizeof (gfc_actual_arglist ))); |
3945 | args->expr = op1; |
3946 | if (op2) |
3947 | { |
3948 | args->next = gfc_get_actual_arglist ()((gfc_actual_arglist *) xcalloc (1, sizeof (gfc_actual_arglist ))); |
3949 | args->next->expr = op2; |
3950 | } |
3951 | |
3952 | /* Convert the expression to a function call. */ |
3953 | e->expr_type = EXPR_FUNCTION; |
3954 | e->value.function.actual = args; |
3955 | e->value.function.isym = gfc_intrinsic_function_by_id (isym); |
3956 | e->value.function.name = e->value.function.isym->name; |
3957 | e->value.function.esym = NULL__null; |
3958 | |
3959 | /* Make up a pre-resolved function call symtree if we need to. */ |
3960 | if (!e->symtree || !e->symtree->n.sym) |
3961 | { |
3962 | gfc_symbol *sym; |
3963 | gfc_get_ha_sym_tree (e->value.function.isym->name, &e->symtree); |
3964 | sym = e->symtree->n.sym; |
3965 | sym->result = sym; |
3966 | sym->attr.flavor = FL_PROCEDURE; |
3967 | sym->attr.function = 1; |
3968 | sym->attr.elemental = 1; |
3969 | sym->attr.pure = 1; |
3970 | sym->attr.referenced = 1; |
3971 | gfc_intrinsic_symbol (sym)sym->module = gfc_get_string ("(intrinsic)"); |
3972 | gfc_commit_symbol (sym); |
3973 | } |
3974 | |
3975 | args->name = e->value.function.isym->formal->name; |
3976 | if (e->value.function.isym->formal->next) |
3977 | args->next->name = e->value.function.isym->formal->next->name; |
3978 | |
3979 | return e; |
3980 | } |
3981 | |
3982 | /* Recursively append candidate UOP to CANDIDATES. Store the number of |
3983 | candidates in CANDIDATES_LEN. */ |
3984 | static void |
3985 | lookup_uop_fuzzy_find_candidates (gfc_symtree *uop, |
3986 | char **&candidates, |
3987 | size_t &candidates_len) |
3988 | { |
3989 | gfc_symtree *p; |
3990 | |
3991 | if (uop == NULL__null) |
3992 | return; |
3993 | |
3994 | /* Not sure how to properly filter here. Use all for a start. |
3995 | n.uop.op is NULL for empty interface operators (is that legal?) disregard |
3996 | these as i suppose they don't make terribly sense. */ |
3997 | |
3998 | if (uop->n.uop->op != NULL__null) |
3999 | vec_push (candidates, candidates_len, uop->name); |
4000 | |
4001 | p = uop->left; |
4002 | if (p) |
4003 | lookup_uop_fuzzy_find_candidates (p, candidates, candidates_len); |
4004 | |
4005 | p = uop->right; |
4006 | if (p) |
4007 | lookup_uop_fuzzy_find_candidates (p, candidates, candidates_len); |
4008 | } |
4009 | |
4010 | /* Lookup user-operator OP fuzzily, taking names in UOP into account. */ |
4011 | |
4012 | static const char* |
4013 | lookup_uop_fuzzy (const char *op, gfc_symtree *uop) |
4014 | { |
4015 | char **candidates = NULL__null; |
4016 | size_t candidates_len = 0; |
4017 | lookup_uop_fuzzy_find_candidates (uop, candidates, candidates_len); |
4018 | return gfc_closest_fuzzy_match (op, candidates); |
4019 | } |
4020 | |
4021 | |
4022 | /* Callback finding an impure function as an operand to an .and. or |
4023 | .or. expression. Remember the last function warned about to |
4024 | avoid double warnings when recursing. */ |
4025 | |
4026 | static int |
4027 | impure_function_callback (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
4028 | void *data) |
4029 | { |
4030 | gfc_expr *f = *e; |
4031 | const char *name; |
4032 | static gfc_expr *last = NULL__null; |
4033 | bool *found = (bool *) data; |
4034 | |
4035 | if (f->expr_type == EXPR_FUNCTION) |
4036 | { |
4037 | *found = 1; |
4038 | if (f != last && !gfc_pure_function (f, &name) |
4039 | && !gfc_implicit_pure_function (f)) |
4040 | { |
4041 | if (name) |
4042 | gfc_warning (OPT_Wfunction_elimination, |
4043 | "Impure function %qs at %L might not be evaluated", |
4044 | name, &f->where); |
4045 | else |
4046 | gfc_warning (OPT_Wfunction_elimination, |
4047 | "Impure function at %L might not be evaluated", |
4048 | &f->where); |
4049 | } |
4050 | last = f; |
4051 | } |
4052 | |
4053 | return 0; |
4054 | } |
4055 | |
4056 | /* Return true if TYPE is character based, false otherwise. */ |
4057 | |
4058 | static int |
4059 | is_character_based (bt type) |
4060 | { |
4061 | return type == BT_CHARACTER || type == BT_HOLLERITH; |
4062 | } |
4063 | |
4064 | |
4065 | /* If expression is a hollerith, convert it to character and issue a warning |
4066 | for the conversion. */ |
4067 | |
4068 | static void |
4069 | convert_hollerith_to_character (gfc_expr *e) |
4070 | { |
4071 | if (e->ts.type == BT_HOLLERITH) |
4072 | { |
4073 | gfc_typespec t; |
4074 | gfc_clear_ts (&t); |
4075 | t.type = BT_CHARACTER; |
4076 | t.kind = e->ts.kind; |
4077 | gfc_convert_type_warn (e, &t, 2, 1); |
4078 | } |
4079 | } |
4080 | |
4081 | /* Convert to numeric and issue a warning for the conversion. */ |
4082 | |
4083 | static void |
4084 | convert_to_numeric (gfc_expr *a, gfc_expr *b) |
4085 | { |
4086 | gfc_typespec t; |
4087 | gfc_clear_ts (&t); |
4088 | t.type = b->ts.type; |
4089 | t.kind = b->ts.kind; |
4090 | gfc_convert_type_warn (a, &t, 2, 1); |
4091 | } |
4092 | |
4093 | /* Resolve an operator expression node. This can involve replacing the |
4094 | operation with a user defined function call. */ |
4095 | |
4096 | static bool |
4097 | resolve_operator (gfc_expr *e) |
4098 | { |
4099 | gfc_expr *op1, *op2; |
4100 | /* One error uses 3 names; additional space for wording (also via gettext). */ |
4101 | char msg[3*GFC_MAX_SYMBOL_LEN63 + 1 + 50]; |
4102 | bool dual_locus_error; |
4103 | bool t = true; |
4104 | |
4105 | /* Resolve all subnodes-- give them types. */ |
4106 | |
4107 | switch (e->value.op.op) |
4108 | { |
4109 | default: |
4110 | if (!gfc_resolve_expr (e->value.op.op2)) |
4111 | t = false; |
4112 | |
4113 | /* Fall through. */ |
4114 | |
4115 | case INTRINSIC_NOT: |
4116 | case INTRINSIC_UPLUS: |
4117 | case INTRINSIC_UMINUS: |
4118 | case INTRINSIC_PARENTHESES: |
4119 | if (!gfc_resolve_expr (e->value.op.op1)) |
4120 | return false; |
4121 | if (e->value.op.op1 |
4122 | && e->value.op.op1->ts.type == BT_BOZ && !e->value.op.op2) |
4123 | { |
4124 | gfc_error ("BOZ literal constant at %L cannot be an operand of " |
4125 | "unary operator %qs", &e->value.op.op1->where, |
4126 | gfc_op2string (e->value.op.op)); |
4127 | return false; |
4128 | } |
4129 | break; |
4130 | } |
4131 | |
4132 | /* Typecheck the new node. */ |
4133 | |
4134 | op1 = e->value.op.op1; |
4135 | op2 = e->value.op.op2; |
4136 | if (op1 == NULL__null && op2 == NULL__null) |
4137 | return false; |
4138 | /* Error out if op2 did not resolve. We already diagnosed op1. */ |
4139 | if (t == false) |
4140 | return false; |
4141 | |
4142 | dual_locus_error = false; |
4143 | |
4144 | /* op1 and op2 cannot both be BOZ. */ |
4145 | if (op1 && op1->ts.type == BT_BOZ |
4146 | && op2 && op2->ts.type == BT_BOZ) |
4147 | { |
4148 | gfc_error ("Operands at %L and %L cannot appear as operands of " |
4149 | "binary operator %qs", &op1->where, &op2->where, |
4150 | gfc_op2string (e->value.op.op)); |
4151 | return false; |
4152 | } |
4153 | |
4154 | if ((op1 && op1->expr_type == EXPR_NULL) |
4155 | || (op2 && op2->expr_type == EXPR_NULL)) |
4156 | { |
4157 | snprintf (msg, sizeof (msg), |
4158 | _("Invalid context for NULL() pointer at %%L")gettext ("Invalid context for NULL() pointer at %%L")); |
4159 | goto bad_op; |
4160 | } |
4161 | |
4162 | switch (e->value.op.op) |
4163 | { |
4164 | case INTRINSIC_UPLUS: |
4165 | case INTRINSIC_UMINUS: |
4166 | if (op1->ts.type == BT_INTEGER |
4167 | || op1->ts.type == BT_REAL |
4168 | || op1->ts.type == BT_COMPLEX) |
4169 | { |
4170 | e->ts = op1->ts; |
4171 | break; |
4172 | } |
4173 | |
4174 | snprintf (msg, sizeof (msg), |
4175 | _("Operand of unary numeric operator %%<%s%%> at %%L is %s")gettext ("Operand of unary numeric operator %%<%s%%> at %%L is %s" ), |
4176 | gfc_op2string (e->value.op.op), gfc_typename (e)); |
4177 | goto bad_op; |
4178 | |
4179 | case INTRINSIC_PLUS: |
4180 | case INTRINSIC_MINUS: |
4181 | case INTRINSIC_TIMES: |
4182 | case INTRINSIC_DIVIDE: |
4183 | case INTRINSIC_POWER: |
4184 | if (gfc_numeric_ts (&op1->ts) && gfc_numeric_ts (&op2->ts)) |
4185 | { |
4186 | gfc_type_convert_binary (e, 1); |
4187 | break; |
4188 | } |
4189 | |
4190 | if (op1->ts.type == BT_DERIVED || op2->ts.type == BT_DERIVED) |
4191 | snprintf (msg, sizeof (msg), |
4192 | _("Unexpected derived-type entities in binary intrinsic "gettext ("Unexpected derived-type entities in binary intrinsic " "numeric operator %%<%s%%> at %%L") |
4193 | "numeric operator %%<%s%%> at %%L")gettext ("Unexpected derived-type entities in binary intrinsic " "numeric operator %%<%s%%> at %%L"), |
4194 | gfc_op2string (e->value.op.op)); |
4195 | else |
4196 | snprintf (msg, sizeof(msg), |
4197 | _("Operands of binary numeric operator %%<%s%%> at %%L are %s/%s")gettext ("Operands of binary numeric operator %%<%s%%> at %%L are %s/%s" ), |
4198 | gfc_op2string (e->value.op.op), gfc_typename (op1), |
4199 | gfc_typename (op2)); |
4200 | goto bad_op; |
4201 | |
4202 | case INTRINSIC_CONCAT: |
4203 | if (op1->ts.type == BT_CHARACTER && op2->ts.type == BT_CHARACTER |
4204 | && op1->ts.kind == op2->ts.kind) |
4205 | { |
4206 | e->ts.type = BT_CHARACTER; |
4207 | e->ts.kind = op1->ts.kind; |
4208 | break; |
4209 | } |
4210 | |
4211 | snprintf (msg, sizeof (msg), |
4212 | _("Operands of string concatenation operator at %%L are %s/%s")gettext ("Operands of string concatenation operator at %%L are %s/%s" ), |
4213 | gfc_typename (op1), gfc_typename (op2)); |
4214 | goto bad_op; |
4215 | |
4216 | case INTRINSIC_AND: |
4217 | case INTRINSIC_OR: |
4218 | case INTRINSIC_EQV: |
4219 | case INTRINSIC_NEQV: |
4220 | if (op1->ts.type == BT_LOGICAL && op2->ts.type == BT_LOGICAL) |
4221 | { |
4222 | e->ts.type = BT_LOGICAL; |
4223 | e->ts.kind = gfc_kind_max (op1, op2); |
4224 | if (op1->ts.kind < e->ts.kind) |
4225 | gfc_convert_type (op1, &e->ts, 2); |
4226 | else if (op2->ts.kind < e->ts.kind) |
4227 | gfc_convert_type (op2, &e->ts, 2); |
4228 | |
4229 | if (flag_frontend_optimizeglobal_options.x_flag_frontend_optimize && |
4230 | (e->value.op.op == INTRINSIC_AND || e->value.op.op == INTRINSIC_OR)) |
4231 | { |
4232 | /* Warn about short-circuiting |
4233 | with impure function as second operand. */ |
4234 | bool op2_f = false; |
4235 | gfc_expr_walker (&op2, impure_function_callback, &op2_f); |
4236 | } |
4237 | break; |
4238 | } |
4239 | |
4240 | /* Logical ops on integers become bitwise ops with -fdec. */ |
4241 | else if (flag_decglobal_options.x_flag_dec |
4242 | && (op1->ts.type == BT_INTEGER || op2->ts.type == BT_INTEGER)) |
4243 | { |
4244 | e->ts.type = BT_INTEGER; |
4245 | e->ts.kind = gfc_kind_max (op1, op2); |
4246 | if (op1->ts.type != e->ts.type || op1->ts.kind != e->ts.kind) |
4247 | gfc_convert_type (op1, &e->ts, 1); |
4248 | if (op2->ts.type != e->ts.type || op2->ts.kind != e->ts.kind) |
4249 | gfc_convert_type (op2, &e->ts, 1); |
4250 | e = logical_to_bitwise (e); |
4251 | goto simplify_op; |
4252 | } |
4253 | |
4254 | snprintf (msg, sizeof (msg), |
4255 | _("Operands of logical operator %%<%s%%> at %%L are %s/%s")gettext ("Operands of logical operator %%<%s%%> at %%L are %s/%s" ), |
4256 | gfc_op2string (e->value.op.op), gfc_typename (op1), |
4257 | gfc_typename (op2)); |
4258 | |
4259 | goto bad_op; |
4260 | |
4261 | case INTRINSIC_NOT: |
4262 | /* Logical ops on integers become bitwise ops with -fdec. */ |
4263 | if (flag_decglobal_options.x_flag_dec && op1->ts.type == BT_INTEGER) |
4264 | { |
4265 | e->ts.type = BT_INTEGER; |
4266 | e->ts.kind = op1->ts.kind; |
4267 | e = logical_to_bitwise (e); |
4268 | goto simplify_op; |
4269 | } |
4270 | |
4271 | if (op1->ts.type == BT_LOGICAL) |
4272 | { |
4273 | e->ts.type = BT_LOGICAL; |
4274 | e->ts.kind = op1->ts.kind; |
4275 | break; |
4276 | } |
4277 | |
4278 | snprintf (msg, sizeof (msg), _("Operand of .not. operator at %%L is %s")gettext ("Operand of .not. operator at %%L is %s"), |
4279 | gfc_typename (op1)); |
4280 | goto bad_op; |
4281 | |
4282 | case INTRINSIC_GT: |
4283 | case INTRINSIC_GT_OS: |
4284 | case INTRINSIC_GE: |
4285 | case INTRINSIC_GE_OS: |
4286 | case INTRINSIC_LT: |
4287 | case INTRINSIC_LT_OS: |
4288 | case INTRINSIC_LE: |
4289 | case INTRINSIC_LE_OS: |
4290 | if (op1->ts.type == BT_COMPLEX || op2->ts.type == BT_COMPLEX) |
4291 | { |
4292 | strcpy (msg, _("COMPLEX quantities cannot be compared at %L")gettext ("COMPLEX quantities cannot be compared at %L")); |
4293 | goto bad_op; |
4294 | } |
4295 | |
4296 | /* Fall through. */ |
4297 | |
4298 | case INTRINSIC_EQ: |
4299 | case INTRINSIC_EQ_OS: |
4300 | case INTRINSIC_NE: |
4301 | case INTRINSIC_NE_OS: |
4302 | |
4303 | if (flag_decglobal_options.x_flag_dec |
4304 | && is_character_based (op1->ts.type) |
4305 | && is_character_based (op2->ts.type)) |
4306 | { |
4307 | convert_hollerith_to_character (op1); |
4308 | convert_hollerith_to_character (op2); |
4309 | } |
4310 | |
4311 | if (op1->ts.type == BT_CHARACTER && op2->ts.type == BT_CHARACTER |
4312 | && op1->ts.kind == op2->ts.kind) |
4313 | { |
4314 | e->ts.type = BT_LOGICAL; |
4315 | e->ts.kind = gfc_default_logical_kind; |
4316 | break; |
4317 | } |
4318 | |
4319 | /* If op1 is BOZ, then op2 is not!. Try to convert to type of op2. */ |
4320 | if (op1->ts.type == BT_BOZ) |
4321 | { |
4322 | if (gfc_invalid_boz (G_("BOZ literal constant near %L cannot appear ""BOZ literal constant near %L cannot appear " "as an operand of a relational operator" |
4323 | "as an operand of a relational operator")"BOZ literal constant near %L cannot appear " "as an operand of a relational operator", |
4324 | &op1->where)) |
4325 | return false; |
4326 | |
4327 | if (op2->ts.type == BT_INTEGER && !gfc_boz2int (op1, op2->ts.kind)) |
4328 | return false; |
4329 | |
4330 | if (op2->ts.type == BT_REAL && !gfc_boz2real (op1, op2->ts.kind)) |
4331 | return false; |
4332 | } |
4333 | |
4334 | /* If op2 is BOZ, then op1 is not!. Try to convert to type of op2. */ |
4335 | if (op2->ts.type == BT_BOZ) |
4336 | { |
4337 | if (gfc_invalid_boz (G_("BOZ literal constant near %L cannot appear""BOZ literal constant near %L cannot appear" " as an operand of a relational operator" |
4338 | " as an operand of a relational operator")"BOZ literal constant near %L cannot appear" " as an operand of a relational operator", |
4339 | &op2->where)) |
4340 | return false; |
4341 | |
4342 | if (op1->ts.type == BT_INTEGER && !gfc_boz2int (op2, op1->ts.kind)) |
4343 | return false; |
4344 | |
4345 | if (op1->ts.type == BT_REAL && !gfc_boz2real (op2, op1->ts.kind)) |
4346 | return false; |
4347 | } |
4348 | if (flag_decglobal_options.x_flag_dec |
4349 | && op1->ts.type == BT_HOLLERITH && gfc_numeric_ts (&op2->ts)) |
4350 | convert_to_numeric (op1, op2); |
4351 | |
4352 | if (flag_decglobal_options.x_flag_dec |
4353 | && gfc_numeric_ts (&op1->ts) && op2->ts.type == BT_HOLLERITH) |
4354 | convert_to_numeric (op2, op1); |
4355 | |
4356 | if (gfc_numeric_ts (&op1->ts) && gfc_numeric_ts (&op2->ts)) |
4357 | { |
4358 | gfc_type_convert_binary (e, 1); |
4359 | |
4360 | e->ts.type = BT_LOGICAL; |
4361 | e->ts.kind = gfc_default_logical_kind; |
4362 | |
4363 | if (warn_compare_realsglobal_options.x_warn_compare_reals) |
4364 | { |
4365 | gfc_intrinsic_op op = e->value.op.op; |
4366 | |
4367 | /* Type conversion has made sure that the types of op1 and op2 |
4368 | agree, so it is only necessary to check the first one. */ |
4369 | if ((op1->ts.type == BT_REAL || op1->ts.type == BT_COMPLEX) |
4370 | && (op == INTRINSIC_EQ || op == INTRINSIC_EQ_OS |
4371 | || op == INTRINSIC_NE || op == INTRINSIC_NE_OS)) |
4372 | { |
4373 | const char *msg; |
4374 | |
4375 | if (op == INTRINSIC_EQ || op == INTRINSIC_EQ_OS) |
4376 | msg = G_("Equality comparison for %s at %L")"Equality comparison for %s at %L"; |
4377 | else |
4378 | msg = G_("Inequality comparison for %s at %L")"Inequality comparison for %s at %L"; |
4379 | |
4380 | gfc_warning (OPT_Wcompare_reals, msg, |
4381 | gfc_typename (op1), &op1->where); |
4382 | } |
4383 | } |
4384 | |
4385 | break; |
4386 | } |
4387 | |
4388 | if (op1->ts.type == BT_LOGICAL && op2->ts.type == BT_LOGICAL) |
4389 | snprintf (msg, sizeof (msg), |
4390 | _("Logicals at %%L must be compared with %s instead of %s")gettext ("Logicals at %%L must be compared with %s instead of %s" ), |
4391 | (e->value.op.op == INTRINSIC_EQ |
4392 | || e->value.op.op == INTRINSIC_EQ_OS) |
4393 | ? ".eqv." : ".neqv.", gfc_op2string (e->value.op.op)); |
4394 | else |
4395 | snprintf (msg, sizeof (msg), |
4396 | _("Operands of comparison operator %%<%s%%> at %%L are %s/%s")gettext ("Operands of comparison operator %%<%s%%> at %%L are %s/%s" ), |
4397 | gfc_op2string (e->value.op.op), gfc_typename (op1), |
4398 | gfc_typename (op2)); |
4399 | |
4400 | goto bad_op; |
4401 | |
4402 | case INTRINSIC_USER: |
4403 | if (e->value.op.uop->op == NULL__null) |
4404 | { |
4405 | const char *name = e->value.op.uop->name; |
4406 | const char *guessed; |
4407 | guessed = lookup_uop_fuzzy (name, e->value.op.uop->ns->uop_root); |
4408 | if (guessed) |
4409 | snprintf (msg, sizeof (msg), |
4410 | _("Unknown operator %%<%s%%> at %%L; did you mean "gettext ("Unknown operator %%<%s%%> at %%L; did you mean " "%%<%s%%>?") |
4411 | "%%<%s%%>?")gettext ("Unknown operator %%<%s%%> at %%L; did you mean " "%%<%s%%>?"), name, guessed); |
4412 | else |
4413 | snprintf (msg, sizeof (msg), _("Unknown operator %%<%s%%> at %%L")gettext ("Unknown operator %%<%s%%> at %%L"), |
4414 | name); |
4415 | } |
4416 | else if (op2 == NULL__null) |
4417 | snprintf (msg, sizeof (msg), |
4418 | _("Operand of user operator %%<%s%%> at %%L is %s")gettext ("Operand of user operator %%<%s%%> at %%L is %s" ), |
4419 | e->value.op.uop->name, gfc_typename (op1)); |
4420 | else |
4421 | { |
4422 | snprintf (msg, sizeof (msg), |
4423 | _("Operands of user operator %%<%s%%> at %%L are %s/%s")gettext ("Operands of user operator %%<%s%%> at %%L are %s/%s" ), |
4424 | e->value.op.uop->name, gfc_typename (op1), |
4425 | gfc_typename (op2)); |
4426 | e->value.op.uop->op->sym->attr.referenced = 1; |
4427 | } |
4428 | |
4429 | goto bad_op; |
4430 | |
4431 | case INTRINSIC_PARENTHESES: |
4432 | e->ts = op1->ts; |
4433 | if (e->ts.type == BT_CHARACTER) |
4434 | e->ts.u.cl = op1->ts.u.cl; |
4435 | break; |
4436 | |
4437 | default: |
4438 | gfc_internal_error ("resolve_operator(): Bad intrinsic"); |
4439 | } |
4440 | |
4441 | /* Deal with arrayness of an operand through an operator. */ |
4442 | |
4443 | switch (e->value.op.op) |
4444 | { |
4445 | case INTRINSIC_PLUS: |
4446 | case INTRINSIC_MINUS: |
4447 | case INTRINSIC_TIMES: |
4448 | case INTRINSIC_DIVIDE: |
4449 | case INTRINSIC_POWER: |
4450 | case INTRINSIC_CONCAT: |
4451 | case INTRINSIC_AND: |
4452 | case INTRINSIC_OR: |
4453 | case INTRINSIC_EQV: |
4454 | case INTRINSIC_NEQV: |
4455 | case INTRINSIC_EQ: |
4456 | case INTRINSIC_EQ_OS: |
4457 | case INTRINSIC_NE: |
4458 | case INTRINSIC_NE_OS: |
4459 | case INTRINSIC_GT: |
4460 | case INTRINSIC_GT_OS: |
4461 | case INTRINSIC_GE: |
4462 | case INTRINSIC_GE_OS: |
4463 | case INTRINSIC_LT: |
4464 | case INTRINSIC_LT_OS: |
4465 | case INTRINSIC_LE: |
4466 | case INTRINSIC_LE_OS: |
4467 | |
4468 | if (op1->rank == 0 && op2->rank == 0) |
4469 | e->rank = 0; |
4470 | |
4471 | if (op1->rank == 0 && op2->rank != 0) |
4472 | { |
4473 | e->rank = op2->rank; |
4474 | |
4475 | if (e->shape == NULL__null) |
4476 | e->shape = gfc_copy_shape (op2->shape, op2->rank); |
4477 | } |
4478 | |
4479 | if (op1->rank != 0 && op2->rank == 0) |
4480 | { |
4481 | e->rank = op1->rank; |
4482 | |
4483 | if (e->shape == NULL__null) |
4484 | e->shape = gfc_copy_shape (op1->shape, op1->rank); |
4485 | } |
4486 | |
4487 | if (op1->rank != 0 && op2->rank != 0) |
4488 | { |
4489 | if (op1->rank == op2->rank) |
4490 | { |
4491 | e->rank = op1->rank; |
4492 | if (e->shape == NULL__null) |
4493 | { |
4494 | t = compare_shapes (op1, op2); |
4495 | if (!t) |
4496 | e->shape = NULL__null; |
4497 | else |
4498 | e->shape = gfc_copy_shape (op1->shape, op1->rank); |
4499 | } |
4500 | } |
4501 | else |
4502 | { |
4503 | /* Allow higher level expressions to work. */ |
4504 | e->rank = 0; |
4505 | |
4506 | /* Try user-defined operators, and otherwise throw an error. */ |
4507 | dual_locus_error = true; |
4508 | snprintf (msg, sizeof (msg), |
4509 | _("Inconsistent ranks for operator at %%L and %%L")gettext ("Inconsistent ranks for operator at %%L and %%L")); |
4510 | goto bad_op; |
4511 | } |
4512 | } |
4513 | |
4514 | break; |
4515 | |
4516 | case INTRINSIC_PARENTHESES: |
4517 | case INTRINSIC_NOT: |
4518 | case INTRINSIC_UPLUS: |
4519 | case INTRINSIC_UMINUS: |
4520 | /* Simply copy arrayness attribute */ |
4521 | e->rank = op1->rank; |
4522 | |
4523 | if (e->shape == NULL__null) |
4524 | e->shape = gfc_copy_shape (op1->shape, op1->rank); |
4525 | |
4526 | break; |
4527 | |
4528 | default: |
4529 | break; |
4530 | } |
4531 | |
4532 | simplify_op: |
4533 | |
4534 | /* Attempt to simplify the expression. */ |
4535 | if (t) |
4536 | { |
4537 | t = gfc_simplify_expr (e, 0); |
4538 | /* Some calls do not succeed in simplification and return false |
4539 | even though there is no error; e.g. variable references to |
4540 | PARAMETER arrays. */ |
4541 | if (!gfc_is_constant_expr (e)) |
4542 | t = true; |
4543 | } |
4544 | return t; |
4545 | |
4546 | bad_op: |
4547 | |
4548 | { |
4549 | match m = gfc_extend_expr (e); |
4550 | if (m == MATCH_YES) |
4551 | return true; |
4552 | if (m == MATCH_ERROR) |
4553 | return false; |
4554 | } |
4555 | |
4556 | if (dual_locus_error) |
4557 | gfc_error (msg, &op1->where, &op2->where); |
4558 | else |
4559 | gfc_error (msg, &e->where); |
4560 | |
4561 | return false; |
4562 | } |
4563 | |
4564 | |
4565 | /************** Array resolution subroutines **************/ |
4566 | |
4567 | enum compare_result |
4568 | { CMP_LT, CMP_EQ, CMP_GT, CMP_UNKNOWN }; |
4569 | |
4570 | /* Compare two integer expressions. */ |
4571 | |
4572 | static compare_result |
4573 | compare_bound (gfc_expr *a, gfc_expr *b) |
4574 | { |
4575 | int i; |
4576 | |
4577 | if (a == NULL__null || a->expr_type != EXPR_CONSTANT |
4578 | || b == NULL__null || b->expr_type != EXPR_CONSTANT) |
4579 | return CMP_UNKNOWN; |
4580 | |
4581 | /* If either of the types isn't INTEGER, we must have |
4582 | raised an error earlier. */ |
4583 | |
4584 | if (a->ts.type != BT_INTEGER || b->ts.type != BT_INTEGER) |
4585 | return CMP_UNKNOWN; |
4586 | |
4587 | i = mpz_cmp__gmpz_cmp (a->value.integer, b->value.integer); |
4588 | |
4589 | if (i < 0) |
4590 | return CMP_LT; |
4591 | if (i > 0) |
4592 | return CMP_GT; |
4593 | return CMP_EQ; |
4594 | } |
4595 | |
4596 | |
4597 | /* Compare an integer expression with an integer. */ |
4598 | |
4599 | static compare_result |
4600 | compare_bound_int (gfc_expr *a, int b) |
4601 | { |
4602 | int i; |
4603 | |
4604 | if (a == NULL__null |
4605 | || a->expr_type != EXPR_CONSTANT |
4606 | || a->ts.type != BT_INTEGER) |
4607 | return CMP_UNKNOWN; |
4608 | |
4609 | i = mpz_cmp_si (a->value.integer, b)(__builtin_constant_p ((b) >= 0) && (b) >= 0 ? ( __builtin_constant_p ((static_cast<unsigned long> (b))) && ((static_cast<unsigned long> (b))) == 0 ? ( (a->value.integer)->_mp_size < 0 ? -1 : (a->value .integer)->_mp_size > 0) : __gmpz_cmp_ui (a->value.integer ,(static_cast<unsigned long> (b)))) : __gmpz_cmp_si (a-> value.integer,b)); |
4610 | |
4611 | if (i < 0) |
4612 | return CMP_LT; |
4613 | if (i > 0) |
4614 | return CMP_GT; |
4615 | return CMP_EQ; |
4616 | } |
4617 | |
4618 | |
4619 | /* Compare an integer expression with a mpz_t. */ |
4620 | |
4621 | static compare_result |
4622 | compare_bound_mpz_t (gfc_expr *a, mpz_t b) |
4623 | { |
4624 | int i; |
4625 | |
4626 | if (a == NULL__null |
4627 | || a->expr_type != EXPR_CONSTANT |
4628 | || a->ts.type != BT_INTEGER) |
4629 | return CMP_UNKNOWN; |
4630 | |
4631 | i = mpz_cmp__gmpz_cmp (a->value.integer, b); |
4632 | |
4633 | if (i < 0) |
4634 | return CMP_LT; |
4635 | if (i > 0) |
4636 | return CMP_GT; |
4637 | return CMP_EQ; |
4638 | } |
4639 | |
4640 | |
4641 | /* Compute the last value of a sequence given by a triplet. |
4642 | Return 0 if it wasn't able to compute the last value, or if the |
4643 | sequence if empty, and 1 otherwise. */ |
4644 | |
4645 | static int |
4646 | compute_last_value_for_triplet (gfc_expr *start, gfc_expr *end, |
4647 | gfc_expr *stride, mpz_t last) |
4648 | { |
4649 | mpz_t rem; |
4650 | |
4651 | if (start == NULL__null || start->expr_type != EXPR_CONSTANT |
4652 | || end == NULL__null || end->expr_type != EXPR_CONSTANT |
4653 | || (stride != NULL__null && stride->expr_type != EXPR_CONSTANT)) |
4654 | return 0; |
4655 | |
4656 | if (start->ts.type != BT_INTEGER || end->ts.type != BT_INTEGER |
4657 | || (stride != NULL__null && stride->ts.type != BT_INTEGER)) |
4658 | return 0; |
4659 | |
4660 | if (stride == NULL__null || compare_bound_int (stride, 1) == CMP_EQ) |
4661 | { |
4662 | if (compare_bound (start, end) == CMP_GT) |
4663 | return 0; |
4664 | mpz_set__gmpz_set (last, end->value.integer); |
4665 | return 1; |
4666 | } |
4667 | |
4668 | if (compare_bound_int (stride, 0) == CMP_GT) |
4669 | { |
4670 | /* Stride is positive */ |
4671 | if (mpz_cmp__gmpz_cmp (start->value.integer, end->value.integer) > 0) |
4672 | return 0; |
4673 | } |
4674 | else |
4675 | { |
4676 | /* Stride is negative */ |
4677 | if (mpz_cmp__gmpz_cmp (start->value.integer, end->value.integer) < 0) |
4678 | return 0; |
4679 | } |
4680 | |
4681 | mpz_init__gmpz_init (rem); |
4682 | mpz_sub__gmpz_sub (rem, end->value.integer, start->value.integer); |
4683 | mpz_tdiv_r__gmpz_tdiv_r (rem, rem, stride->value.integer); |
4684 | mpz_sub__gmpz_sub (last, end->value.integer, rem); |
4685 | mpz_clear__gmpz_clear (rem); |
4686 | |
4687 | return 1; |
4688 | } |
4689 | |
4690 | |
4691 | /* Compare a single dimension of an array reference to the array |
4692 | specification. */ |
4693 | |
4694 | static bool |
4695 | check_dimension (int i, gfc_array_ref *ar, gfc_array_spec *as) |
4696 | { |
4697 | mpz_t last_value; |
4698 | |
4699 | if (ar->dimen_type[i] == DIMEN_STAR) |
4700 | { |
4701 | gcc_assert (ar->stride[i] == NULL)((void)(!(ar->stride[i] == __null) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 4701, __FUNCTION__), 0 : 0)); |
4702 | /* This implies [*] as [*:] and [*:3] are not possible. */ |
4703 | if (ar->start[i] == NULL__null) |
4704 | { |
4705 | gcc_assert (ar->end[i] == NULL)((void)(!(ar->end[i] == __null) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 4705, __FUNCTION__), 0 : 0)); |
4706 | return true; |
4707 | } |
4708 | } |
4709 | |
4710 | /* Given start, end and stride values, calculate the minimum and |
4711 | maximum referenced indexes. */ |
4712 | |
4713 | switch (ar->dimen_type[i]) |
4714 | { |
4715 | case DIMEN_VECTOR: |
4716 | case DIMEN_THIS_IMAGE: |
4717 | break; |
4718 | |
4719 | case DIMEN_STAR: |
4720 | case DIMEN_ELEMENT: |
4721 | if (compare_bound (ar->start[i], as->lower[i]) == CMP_LT) |
4722 | { |
4723 | if (i < as->rank) |
4724 | gfc_warning (0, "Array reference at %L is out of bounds " |
4725 | "(%ld < %ld) in dimension %d", &ar->c_where[i], |
4726 | mpz_get_si__gmpz_get_si (ar->start[i]->value.integer), |
4727 | mpz_get_si__gmpz_get_si (as->lower[i]->value.integer), i+1); |
4728 | else |
4729 | gfc_warning (0, "Array reference at %L is out of bounds " |
4730 | "(%ld < %ld) in codimension %d", &ar->c_where[i], |
4731 | mpz_get_si__gmpz_get_si (ar->start[i]->value.integer), |
4732 | mpz_get_si__gmpz_get_si (as->lower[i]->value.integer), |
4733 | i + 1 - as->rank); |
4734 | return true; |
4735 | } |
4736 | if (compare_bound (ar->start[i], as->upper[i]) == CMP_GT) |
4737 | { |
4738 | if (i < as->rank) |
4739 | gfc_warning (0, "Array reference at %L is out of bounds " |
4740 | "(%ld > %ld) in dimension %d", &ar->c_where[i], |
4741 | mpz_get_si__gmpz_get_si (ar->start[i]->value.integer), |
4742 | mpz_get_si__gmpz_get_si (as->upper[i]->value.integer), i+1); |
4743 | else |
4744 | gfc_warning (0, "Array reference at %L is out of bounds " |
4745 | "(%ld > %ld) in codimension %d", &ar->c_where[i], |
4746 | mpz_get_si__gmpz_get_si (ar->start[i]->value.integer), |
4747 | mpz_get_si__gmpz_get_si (as->upper[i]->value.integer), |
4748 | i + 1 - as->rank); |
4749 | return true; |
4750 | } |
4751 | |
4752 | break; |
4753 | |
4754 | case DIMEN_RANGE: |
4755 | { |
4756 | #define AR_START (ar->start[i] ? ar->start[i] : as->lower[i]) |
4757 | #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i]) |
4758 | |
4759 | compare_result comp_start_end = compare_bound (AR_START, AR_END); |
4760 | compare_result comp_stride_zero = compare_bound_int (ar->stride[i], 0); |
4761 | |
4762 | /* Check for zero stride, which is not allowed. */ |
4763 | if (comp_stride_zero == CMP_EQ) |
4764 | { |
4765 | gfc_error ("Illegal stride of zero at %L", &ar->c_where[i]); |
4766 | return false; |
4767 | } |
4768 | |
4769 | /* if start == end || (stride > 0 && start < end) |
4770 | || (stride < 0 && start > end), |
4771 | then the array section contains at least one element. In this |
4772 | case, there is an out-of-bounds access if |
4773 | (start < lower || start > upper). */ |
4774 | if (comp_start_end == CMP_EQ |
4775 | || ((comp_stride_zero == CMP_GT || ar->stride[i] == NULL__null) |
4776 | && comp_start_end == CMP_LT) |
4777 | || (comp_stride_zero == CMP_LT |
4778 | && comp_start_end == CMP_GT)) |
4779 | { |
4780 | if (compare_bound (AR_START, as->lower[i]) == CMP_LT) |
4781 | { |
4782 | gfc_warning (0, "Lower array reference at %L is out of bounds " |
4783 | "(%ld < %ld) in dimension %d", &ar->c_where[i], |
4784 | mpz_get_si__gmpz_get_si (AR_START->value.integer), |
4785 | mpz_get_si__gmpz_get_si (as->lower[i]->value.integer), i+1); |
4786 | return true; |
4787 | } |
4788 | if (compare_bound (AR_START, as->upper[i]) == CMP_GT) |
4789 | { |
4790 | gfc_warning (0, "Lower array reference at %L is out of bounds " |
4791 | "(%ld > %ld) in dimension %d", &ar->c_where[i], |
4792 | mpz_get_si__gmpz_get_si (AR_START->value.integer), |
4793 | mpz_get_si__gmpz_get_si (as->upper[i]->value.integer), i+1); |
4794 | return true; |
4795 | } |
4796 | } |
4797 | |
4798 | /* If we can compute the highest index of the array section, |
4799 | then it also has to be between lower and upper. */ |
4800 | mpz_init__gmpz_init (last_value); |
4801 | if (compute_last_value_for_triplet (AR_START, AR_END, ar->stride[i], |
4802 | last_value)) |
4803 | { |
4804 | if (compare_bound_mpz_t (as->lower[i], last_value) == CMP_GT) |
4805 | { |
4806 | gfc_warning (0, "Upper array reference at %L is out of bounds " |
4807 | "(%ld < %ld) in dimension %d", &ar->c_where[i], |
4808 | mpz_get_si__gmpz_get_si (last_value), |
4809 | mpz_get_si__gmpz_get_si (as->lower[i]->value.integer), i+1); |
4810 | mpz_clear__gmpz_clear (last_value); |
4811 | return true; |
4812 | } |
4813 | if (compare_bound_mpz_t (as->upper[i], last_value) == CMP_LT) |
4814 | { |
4815 | gfc_warning (0, "Upper array reference at %L is out of bounds " |
4816 | "(%ld > %ld) in dimension %d", &ar->c_where[i], |
4817 | mpz_get_si__gmpz_get_si (last_value), |
4818 | mpz_get_si__gmpz_get_si (as->upper[i]->value.integer), i+1); |
4819 | mpz_clear__gmpz_clear (last_value); |
4820 | return true; |
4821 | } |
4822 | } |
4823 | mpz_clear__gmpz_clear (last_value); |
4824 | |
4825 | #undef AR_START |
4826 | #undef AR_END |
4827 | } |
4828 | break; |
4829 | |
4830 | default: |
4831 | gfc_internal_error ("check_dimension(): Bad array reference"); |
4832 | } |
4833 | |
4834 | return true; |
4835 | } |
4836 | |
4837 | |
4838 | /* Compare an array reference with an array specification. */ |
4839 | |
4840 | static bool |
4841 | compare_spec_to_ref (gfc_array_ref *ar) |
4842 | { |
4843 | gfc_array_spec *as; |
4844 | int i; |
4845 | |
4846 | as = ar->as; |
4847 | i = as->rank - 1; |
4848 | /* TODO: Full array sections are only allowed as actual parameters. */ |
4849 | if (as->type == AS_ASSUMED_SIZE |
4850 | && (/*ar->type == AR_FULL |
4851 | ||*/ (ar->type == AR_SECTION |
4852 | && ar->dimen_type[i] == DIMEN_RANGE && ar->end[i] == NULL__null))) |
4853 | { |
4854 | gfc_error ("Rightmost upper bound of assumed size array section " |
4855 | "not specified at %L", &ar->where); |
4856 | return false; |
4857 | } |
4858 | |
4859 | if (ar->type == AR_FULL) |
4860 | return true; |
4861 | |
4862 | if (as->rank != ar->dimen) |
4863 | { |
4864 | gfc_error ("Rank mismatch in array reference at %L (%d/%d)", |
4865 | &ar->where, ar->dimen, as->rank); |
4866 | return false; |
4867 | } |
4868 | |
4869 | /* ar->codimen == 0 is a local array. */ |
4870 | if (as->corank != ar->codimen && ar->codimen != 0) |
4871 | { |
4872 | gfc_error ("Coindex rank mismatch in array reference at %L (%d/%d)", |
4873 | &ar->where, ar->codimen, as->corank); |
4874 | return false; |
4875 | } |
4876 | |
4877 | for (i = 0; i < as->rank; i++) |
4878 | if (!check_dimension (i, ar, as)) |
4879 | return false; |
4880 | |
4881 | /* Local access has no coarray spec. */ |
4882 | if (ar->codimen != 0) |
4883 | for (i = as->rank; i < as->rank + as->corank; i++) |
4884 | { |
4885 | if (ar->dimen_type[i] != DIMEN_ELEMENT && !ar->in_allocate |
4886 | && ar->dimen_type[i] != DIMEN_THIS_IMAGE) |
4887 | { |
4888 | gfc_error ("Coindex of codimension %d must be a scalar at %L", |
4889 | i + 1 - as->rank, &ar->where); |
4890 | return false; |
4891 | } |
4892 | if (!check_dimension (i, ar, as)) |
4893 | return false; |
4894 | } |
4895 | |
4896 | return true; |
4897 | } |
4898 | |
4899 | |
4900 | /* Resolve one part of an array index. */ |
4901 | |
4902 | static bool |
4903 | gfc_resolve_index_1 (gfc_expr *index, int check_scalar, |
4904 | int force_index_integer_kind) |
4905 | { |
4906 | gfc_typespec ts; |
4907 | |
4908 | if (index == NULL__null) |
4909 | return true; |
4910 | |
4911 | if (!gfc_resolve_expr (index)) |
4912 | return false; |
4913 | |
4914 | if (check_scalar && index->rank != 0) |
4915 | { |
4916 | gfc_error ("Array index at %L must be scalar", &index->where); |
4917 | return false; |
4918 | } |
4919 | |
4920 | if (index->ts.type != BT_INTEGER && index->ts.type != BT_REAL) |
4921 | { |
4922 | gfc_error ("Array index at %L must be of INTEGER type, found %s", |
4923 | &index->where, gfc_basic_typename (index->ts.type)); |
4924 | return false; |
4925 | } |
4926 | |
4927 | if (index->ts.type == BT_REAL) |
4928 | if (!gfc_notify_std (GFC_STD_LEGACY(1<<6), "REAL array index at %L", |
4929 | &index->where)) |
4930 | return false; |
4931 | |
4932 | if ((index->ts.kind != gfc_index_integer_kind |
4933 | && force_index_integer_kind) |
4934 | || index->ts.type != BT_INTEGER) |
4935 | { |
4936 | gfc_clear_ts (&ts); |
4937 | ts.type = BT_INTEGER; |
4938 | ts.kind = gfc_index_integer_kind; |
4939 | |
4940 | gfc_convert_type_warn (index, &ts, 2, 0); |
4941 | } |
4942 | |
4943 | return true; |
4944 | } |
4945 | |
4946 | /* Resolve one part of an array index. */ |
4947 | |
4948 | bool |
4949 | gfc_resolve_index (gfc_expr *index, int check_scalar) |
4950 | { |
4951 | return gfc_resolve_index_1 (index, check_scalar, 1); |
4952 | } |
4953 | |
4954 | /* Resolve a dim argument to an intrinsic function. */ |
4955 | |
4956 | bool |
4957 | gfc_resolve_dim_arg (gfc_expr *dim) |
4958 | { |
4959 | if (dim == NULL__null) |
4960 | return true; |
4961 | |
4962 | if (!gfc_resolve_expr (dim)) |
4963 | return false; |
4964 | |
4965 | if (dim->rank != 0) |
4966 | { |
4967 | gfc_error ("Argument dim at %L must be scalar", &dim->where); |
4968 | return false; |
4969 | |
4970 | } |
4971 | |
4972 | if (dim->ts.type != BT_INTEGER) |
4973 | { |
4974 | gfc_error ("Argument dim at %L must be of INTEGER type", &dim->where); |
4975 | return false; |
4976 | } |
4977 | |
4978 | if (dim->ts.kind != gfc_index_integer_kind) |
4979 | { |
4980 | gfc_typespec ts; |
4981 | |
4982 | gfc_clear_ts (&ts); |
4983 | ts.type = BT_INTEGER; |
4984 | ts.kind = gfc_index_integer_kind; |
4985 | |
4986 | gfc_convert_type_warn (dim, &ts, 2, 0); |
4987 | } |
4988 | |
4989 | return true; |
4990 | } |
4991 | |
4992 | /* Given an expression that contains array references, update those array |
4993 | references to point to the right array specifications. While this is |
4994 | filled in during matching, this information is difficult to save and load |
4995 | in a module, so we take care of it here. |
4996 | |
4997 | The idea here is that the original array reference comes from the |
4998 | base symbol. We traverse the list of reference structures, setting |
4999 | the stored reference to references. Component references can |
5000 | provide an additional array specification. */ |
5001 | static void |
5002 | resolve_assoc_var (gfc_symbol* sym, bool resolve_target); |
5003 | |
5004 | static bool |
5005 | find_array_spec (gfc_expr *e) |
5006 | { |
5007 | gfc_array_spec *as; |
5008 | gfc_component *c; |
5009 | gfc_ref *ref; |
5010 | bool class_as = false; |
5011 | |
5012 | if (e->symtree->n.sym->assoc) |
5013 | { |
5014 | if (e->symtree->n.sym->assoc->target) |
5015 | gfc_resolve_expr (e->symtree->n.sym->assoc->target); |
5016 | resolve_assoc_var (e->symtree->n.sym, false); |
5017 | } |
5018 | |
5019 | if (e->symtree->n.sym->ts.type == BT_CLASS) |
5020 | { |
5021 | as = CLASS_DATA (e->symtree->n.sym)e->symtree->n.sym->ts.u.derived->components->as; |
5022 | class_as = true; |
5023 | } |
5024 | else |
5025 | as = e->symtree->n.sym->as; |
5026 | |
5027 | for (ref = e->ref; ref; ref = ref->next) |
5028 | switch (ref->type) |
5029 | { |
5030 | case REF_ARRAY: |
5031 | if (as == NULL__null) |
5032 | { |
5033 | locus loc = ref->u.ar.where.lb ? ref->u.ar.where : e->where; |
5034 | gfc_error ("Invalid array reference of a non-array entity at %L", |
5035 | &loc); |
5036 | return false; |
5037 | } |
5038 | |
5039 | ref->u.ar.as = as; |
5040 | as = NULL__null; |
5041 | break; |
5042 | |
5043 | case REF_COMPONENT: |
5044 | c = ref->u.c.component; |
5045 | if (c->attr.dimension) |
5046 | { |
5047 | if (as != NULL__null && !(class_as && as == c->as)) |
5048 | gfc_internal_error ("find_array_spec(): unused as(1)"); |
5049 | as = c->as; |
5050 | } |
5051 | |
5052 | break; |
5053 | |
5054 | case REF_SUBSTRING: |
5055 | case REF_INQUIRY: |
5056 | break; |
5057 | } |
5058 | |
5059 | if (as != NULL__null) |
5060 | gfc_internal_error ("find_array_spec(): unused as(2)"); |
5061 | |
5062 | return true; |
5063 | } |
5064 | |
5065 | |
5066 | /* Resolve an array reference. */ |
5067 | |
5068 | static bool |
5069 | resolve_array_ref (gfc_array_ref *ar) |
5070 | { |
5071 | int i, check_scalar; |
5072 | gfc_expr *e; |
5073 | |
5074 | for (i = 0; i < ar->dimen + ar->codimen; i++) |
5075 | { |
5076 | check_scalar = ar->dimen_type[i] == DIMEN_RANGE; |
5077 | |
5078 | /* Do not force gfc_index_integer_kind for the start. We can |
5079 | do fine with any integer kind. This avoids temporary arrays |
5080 | created for indexing with a vector. */ |
5081 | if (!gfc_resolve_index_1 (ar->start[i], check_scalar, 0)) |
5082 | return false; |
5083 | if (!gfc_resolve_index (ar->end[i], check_scalar)) |
5084 | return false; |
5085 | if (!gfc_resolve_index (ar->stride[i], check_scalar)) |
5086 | return false; |
5087 | |
5088 | e = ar->start[i]; |
5089 | |
5090 | if (ar->dimen_type[i] == DIMEN_UNKNOWN) |
5091 | switch (e->rank) |
5092 | { |
5093 | case 0: |
5094 | ar->dimen_type[i] = DIMEN_ELEMENT; |
5095 | break; |
5096 | |
5097 | case 1: |
5098 | ar->dimen_type[i] = DIMEN_VECTOR; |
5099 | if (e->expr_type == EXPR_VARIABLE |
5100 | && e->symtree->n.sym->ts.type == BT_DERIVED) |
5101 | ar->start[i] = gfc_get_parentheses (e); |
5102 | break; |
5103 | |
5104 | default: |
5105 | gfc_error ("Array index at %L is an array of rank %d", |
5106 | &ar->c_where[i], e->rank); |
5107 | return false; |
5108 | } |
5109 | |
5110 | /* Fill in the upper bound, which may be lower than the |
5111 | specified one for something like a(2:10:5), which is |
5112 | identical to a(2:7:5). Only relevant for strides not equal |
5113 | to one. Don't try a division by zero. */ |
5114 | if (ar->dimen_type[i] == DIMEN_RANGE |
5115 | && ar->stride[i] != NULL__null && ar->stride[i]->expr_type == EXPR_CONSTANT |
5116 | && mpz_cmp_si (ar->stride[i]->value.integer, 1L)(__builtin_constant_p ((1L) >= 0) && (1L) >= 0 ? (__builtin_constant_p ((static_cast<unsigned long> (1L ))) && ((static_cast<unsigned long> (1L))) == 0 ? ((ar->stride[i]->value.integer)->_mp_size < 0 ? -1 : (ar->stride[i]->value.integer)->_mp_size > 0 ) : __gmpz_cmp_ui (ar->stride[i]->value.integer,(static_cast <unsigned long> (1L)))) : __gmpz_cmp_si (ar->stride[ i]->value.integer,1L)) != 0 |
5117 | && mpz_cmp_si (ar->stride[i]->value.integer, 0L)(__builtin_constant_p ((0L) >= 0) && (0L) >= 0 ? (__builtin_constant_p ((static_cast<unsigned long> (0L ))) && ((static_cast<unsigned long> (0L))) == 0 ? ((ar->stride[i]->value.integer)->_mp_size < 0 ? -1 : (ar->stride[i]->value.integer)->_mp_size > 0 ) : __gmpz_cmp_ui (ar->stride[i]->value.integer,(static_cast <unsigned long> (0L)))) : __gmpz_cmp_si (ar->stride[ i]->value.integer,0L)) != 0) |
5118 | { |
5119 | mpz_t size, end; |
5120 | |
5121 | if (gfc_ref_dimen_size (ar, i, &size, &end)) |
5122 | { |
5123 | if (ar->end[i] == NULL__null) |
5124 | { |
5125 | ar->end[i] = |
5126 | gfc_get_constant_expr (BT_INTEGER, gfc_index_integer_kind, |
5127 | &ar->where); |
5128 | mpz_set__gmpz_set (ar->end[i]->value.integer, end); |
5129 | } |
5130 | else if (ar->end[i]->ts.type == BT_INTEGER |
5131 | && ar->end[i]->expr_type == EXPR_CONSTANT) |
5132 | { |
5133 | mpz_set__gmpz_set (ar->end[i]->value.integer, end); |
5134 | } |
5135 | else |
5136 | gcc_unreachable ()(fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 5136, __FUNCTION__)); |
5137 | |
5138 | mpz_clear__gmpz_clear (size); |
5139 | mpz_clear__gmpz_clear (end); |
5140 | } |
5141 | } |
5142 | } |
5143 | |
5144 | if (ar->type == AR_FULL) |
5145 | { |
5146 | if (ar->as->rank == 0) |
5147 | ar->type = AR_ELEMENT; |
5148 | |
5149 | /* Make sure array is the same as array(:,:), this way |
5150 | we don't need to special case all the time. */ |
5151 | ar->dimen = ar->as->rank; |
5152 | for (i = 0; i < ar->dimen; i++) |
5153 | { |
5154 | ar->dimen_type[i] = DIMEN_RANGE; |
5155 | |
5156 | gcc_assert (ar->start[i] == NULL)((void)(!(ar->start[i] == __null) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 5156, __FUNCTION__), 0 : 0)); |
5157 | gcc_assert (ar->end[i] == NULL)((void)(!(ar->end[i] == __null) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 5157, __FUNCTION__), 0 : 0)); |
5158 | gcc_assert (ar->stride[i] == NULL)((void)(!(ar->stride[i] == __null) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 5158, __FUNCTION__), 0 : 0)); |
5159 | } |
5160 | } |
5161 | |
5162 | /* If the reference type is unknown, figure out what kind it is. */ |
5163 | |
5164 | if (ar->type == AR_UNKNOWN) |
5165 | { |
5166 | ar->type = AR_ELEMENT; |
5167 | for (i = 0; i < ar->dimen; i++) |
5168 | if (ar->dimen_type[i] == DIMEN_RANGE |
5169 | || ar->dimen_type[i] == DIMEN_VECTOR) |
5170 | { |
5171 | ar->type = AR_SECTION; |
5172 | break; |
5173 | } |
5174 | } |
5175 | |
5176 | if (!ar->as->cray_pointee && !compare_spec_to_ref (ar)) |
5177 | return false; |
5178 | |
5179 | if (ar->as->corank && ar->codimen == 0) |
5180 | { |
5181 | int n; |
5182 | ar->codimen = ar->as->corank; |
5183 | for (n = ar->dimen; n < ar->dimen + ar->codimen; n++) |
5184 | ar->dimen_type[n] = DIMEN_THIS_IMAGE; |
5185 | } |
5186 | |
5187 | return true; |
5188 | } |
5189 | |
5190 | |
5191 | bool |
5192 | gfc_resolve_substring (gfc_ref *ref, bool *equal_length) |
5193 | { |
5194 | int k = gfc_validate_kind (BT_INTEGER, gfc_charlen_int_kind, false); |
5195 | |
5196 | if (ref->u.ss.start != NULL__null) |
5197 | { |
5198 | if (!gfc_resolve_expr (ref->u.ss.start)) |
5199 | return false; |
5200 | |
5201 | if (ref->u.ss.start->ts.type != BT_INTEGER) |
5202 | { |
5203 | gfc_error ("Substring start index at %L must be of type INTEGER", |
5204 | &ref->u.ss.start->where); |
5205 | return false; |
5206 | } |
5207 | |
5208 | if (ref->u.ss.start->rank != 0) |
5209 | { |
5210 | gfc_error ("Substring start index at %L must be scalar", |
5211 | &ref->u.ss.start->where); |
5212 | return false; |
5213 | } |
5214 | |
5215 | if (compare_bound_int (ref->u.ss.start, 1) == CMP_LT |
5216 | && (compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_EQ |
5217 | || compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_GT)) |
5218 | { |
5219 | gfc_error ("Substring start index at %L is less than one", |
5220 | &ref->u.ss.start->where); |
5221 | return false; |
5222 | } |
5223 | } |
5224 | |
5225 | if (ref->u.ss.end != NULL__null) |
5226 | { |
5227 | if (!gfc_resolve_expr (ref->u.ss.end)) |
5228 | return false; |
5229 | |
5230 | if (ref->u.ss.end->ts.type != BT_INTEGER) |
5231 | { |
5232 | gfc_error ("Substring end index at %L must be of type INTEGER", |
5233 | &ref->u.ss.end->where); |
5234 | return false; |
5235 | } |
5236 | |
5237 | if (ref->u.ss.end->rank != 0) |
5238 | { |
5239 | gfc_error ("Substring end index at %L must be scalar", |
5240 | &ref->u.ss.end->where); |
5241 | return false; |
5242 | } |
5243 | |
5244 | if (ref->u.ss.length != NULL__null |
5245 | && compare_bound (ref->u.ss.end, ref->u.ss.length->length) == CMP_GT |
5246 | && (compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_EQ |
5247 | || compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_GT)) |
5248 | { |
5249 | gfc_error ("Substring end index at %L exceeds the string length", |
5250 | &ref->u.ss.start->where); |
5251 | return false; |
5252 | } |
5253 | |
5254 | if (compare_bound_mpz_t (ref->u.ss.end, |
5255 | gfc_integer_kinds[k].huge) == CMP_GT |
5256 | && (compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_EQ |
5257 | || compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_GT)) |
5258 | { |
5259 | gfc_error ("Substring end index at %L is too large", |
5260 | &ref->u.ss.end->where); |
5261 | return false; |
5262 | } |
5263 | /* If the substring has the same length as the original |
5264 | variable, the reference itself can be deleted. */ |
5265 | |
5266 | if (ref->u.ss.length != NULL__null |
5267 | && compare_bound (ref->u.ss.end, ref->u.ss.length->length) == CMP_EQ |
5268 | && compare_bound_int (ref->u.ss.start, 1) == CMP_EQ) |
5269 | *equal_length = true; |
5270 | } |
5271 | |
5272 | return true; |
5273 | } |
5274 | |
5275 | |
5276 | /* This function supplies missing substring charlens. */ |
5277 | |
5278 | void |
5279 | gfc_resolve_substring_charlen (gfc_expr *e) |
5280 | { |
5281 | gfc_ref *char_ref; |
5282 | gfc_expr *start, *end; |
5283 | gfc_typespec *ts = NULL__null; |
5284 | mpz_t diff; |
5285 | |
5286 | for (char_ref = e->ref; char_ref; char_ref = char_ref->next) |
5287 | { |
5288 | if (char_ref->type == REF_SUBSTRING || char_ref->type == REF_INQUIRY) |
5289 | break; |
5290 | if (char_ref->type == REF_COMPONENT) |
5291 | ts = &char_ref->u.c.component->ts; |
5292 | } |
5293 | |
5294 | if (!char_ref || char_ref->type == REF_INQUIRY) |
5295 | return; |
5296 | |
5297 | gcc_assert (char_ref->next == NULL)((void)(!(char_ref->next == __null) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 5297, __FUNCTION__), 0 : 0)); |
5298 | |
5299 | if (e->ts.u.cl) |
5300 | { |
5301 | if (e->ts.u.cl->length) |
5302 | gfc_free_expr (e->ts.u.cl->length); |
5303 | else if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.dummy) |
5304 | return; |
5305 | } |
5306 | |
5307 | if (!e->ts.u.cl) |
5308 | e->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL__null); |
5309 | |
5310 | if (char_ref->u.ss.start) |
5311 | start = gfc_copy_expr (char_ref->u.ss.start); |
5312 | else |
5313 | start = gfc_get_int_expr (gfc_charlen_int_kind, NULL__null, 1); |
5314 | |
5315 | if (char_ref->u.ss.end) |
5316 | end = gfc_copy_expr (char_ref->u.ss.end); |
5317 | else if (e->expr_type == EXPR_VARIABLE) |
5318 | { |
5319 | if (!ts) |
5320 | ts = &e->symtree->n.sym->ts; |
5321 | end = gfc_copy_expr (ts->u.cl->length); |
5322 | } |
5323 | else |
5324 | end = NULL__null; |
5325 | |
5326 | if (!start || !end) |
5327 | { |
5328 | gfc_free_expr (start); |
5329 | gfc_free_expr (end); |
5330 | return; |
5331 | } |
5332 | |
5333 | /* Length = (end - start + 1). |
5334 | Check first whether it has a constant length. */ |
5335 | if (gfc_dep_difference (end, start, &diff)) |
5336 | { |
5337 | gfc_expr *len = gfc_get_constant_expr (BT_INTEGER, gfc_charlen_int_kind, |
5338 | &e->where); |
5339 | |
5340 | mpz_add_ui__gmpz_add_ui (len->value.integer, diff, 1); |
5341 | mpz_clear__gmpz_clear (diff); |
5342 | e->ts.u.cl->length = len; |
5343 | /* The check for length < 0 is handled below */ |
5344 | } |
5345 | else |
5346 | { |
5347 | e->ts.u.cl->length = gfc_subtract (end, start); |
5348 | e->ts.u.cl->length = gfc_add (e->ts.u.cl->length, |
5349 | gfc_get_int_expr (gfc_charlen_int_kind, |
5350 | NULL__null, 1)); |
5351 | } |
5352 | |
5353 | /* F2008, 6.4.1: Both the starting point and the ending point shall |
5354 | be within the range 1, 2, ..., n unless the starting point exceeds |
5355 | the ending point, in which case the substring has length zero. */ |
5356 | |
5357 | if (mpz_cmp_si (e->ts.u.cl->length->value.integer, 0)(__builtin_constant_p ((0) >= 0) && (0) >= 0 ? ( __builtin_constant_p ((static_cast<unsigned long> (0))) && ((static_cast<unsigned long> (0))) == 0 ? ( (e->ts.u.cl->length->value.integer)->_mp_size < 0 ? -1 : (e->ts.u.cl->length->value.integer)->_mp_size > 0) : __gmpz_cmp_ui (e->ts.u.cl->length->value. integer,(static_cast<unsigned long> (0)))) : __gmpz_cmp_si (e->ts.u.cl->length->value.integer,0)) < 0) |
5358 | mpz_set_si__gmpz_set_si (e->ts.u.cl->length->value.integer, 0); |
5359 | |
5360 | e->ts.u.cl->length->ts.type = BT_INTEGER; |
5361 | e->ts.u.cl->length->ts.kind = gfc_charlen_int_kind; |
5362 | |
5363 | /* Make sure that the length is simplified. */ |
5364 | gfc_simplify_expr (e->ts.u.cl->length, 1); |
5365 | gfc_resolve_expr (e->ts.u.cl->length); |
5366 | } |
5367 | |
5368 | |
5369 | /* Resolve subtype references. */ |
5370 | |
5371 | bool |
5372 | gfc_resolve_ref (gfc_expr *expr) |
5373 | { |
5374 | int current_part_dimension, n_components, seen_part_dimension, dim; |
5375 | gfc_ref *ref, **prev, *array_ref; |
5376 | bool equal_length; |
5377 | |
5378 | for (ref = expr->ref; ref; ref = ref->next) |
5379 | if (ref->type == REF_ARRAY && ref->u.ar.as == NULL__null) |
5380 | { |
5381 | if (!find_array_spec (expr)) |
5382 | return false; |
5383 | break; |
5384 | } |
5385 | |
5386 | for (prev = &expr->ref; *prev != NULL__null; |
5387 | prev = *prev == NULL__null ? prev : &(*prev)->next) |
5388 | switch ((*prev)->type) |
5389 | { |
5390 | case REF_ARRAY: |
5391 | if (!resolve_array_ref (&(*prev)->u.ar)) |
5392 | return false; |
5393 | break; |
5394 | |
5395 | case REF_COMPONENT: |
5396 | case REF_INQUIRY: |
5397 | break; |
5398 | |
5399 | case REF_SUBSTRING: |
5400 | equal_length = false; |
5401 | if (!gfc_resolve_substring (*prev, &equal_length)) |
5402 | return false; |
5403 | |
5404 | if (expr->expr_type != EXPR_SUBSTRING && equal_length) |
5405 | { |
5406 | /* Remove the reference and move the charlen, if any. */ |
5407 | ref = *prev; |
5408 | *prev = ref->next; |
5409 | ref->next = NULL__null; |
5410 | expr->ts.u.cl = ref->u.ss.length; |
5411 | ref->u.ss.length = NULL__null; |
5412 | gfc_free_ref_list (ref); |
5413 | } |
5414 | break; |
5415 | } |
5416 | |
5417 | /* Check constraints on part references. */ |
5418 | |
5419 | current_part_dimension = 0; |
5420 | seen_part_dimension = 0; |
5421 | n_components = 0; |
5422 | array_ref = NULL__null; |
5423 | |
5424 | for (ref = expr->ref; ref; ref = ref->next) |
5425 | { |
5426 | switch (ref->type) |
5427 | { |
5428 | case REF_ARRAY: |
5429 | array_ref = ref; |
5430 | switch (ref->u.ar.type) |
5431 | { |
5432 | case AR_FULL: |
5433 | /* Coarray scalar. */ |
5434 | if (ref->u.ar.as->rank == 0) |
5435 | { |
5436 | current_part_dimension = 0; |
5437 | break; |
5438 | } |
5439 | /* Fall through. */ |
5440 | case AR_SECTION: |
5441 | current_part_dimension = 1; |
5442 | break; |
5443 | |
5444 | case AR_ELEMENT: |
5445 | array_ref = NULL__null; |
5446 | current_part_dimension = 0; |
5447 | break; |
5448 | |
5449 | case AR_UNKNOWN: |
5450 | gfc_internal_error ("resolve_ref(): Bad array reference"); |
5451 | } |
5452 | |
5453 | break; |
5454 | |
5455 | case REF_COMPONENT: |
5456 | if (current_part_dimension || seen_part_dimension) |
5457 | { |
5458 | /* F03:C614. */ |
5459 | if (ref->u.c.component->attr.pointer |
5460 | || ref->u.c.component->attr.proc_pointer |
5461 | || (ref->u.c.component->ts.type == BT_CLASS |
5462 | && CLASS_DATA (ref->u.c.component)ref->u.c.component->ts.u.derived->components->attr.pointer)) |
5463 | { |
5464 | gfc_error ("Component to the right of a part reference " |
5465 | "with nonzero rank must not have the POINTER " |
5466 | "attribute at %L", &expr->where); |
5467 | return false; |
5468 | } |
5469 | else if (ref->u.c.component->attr.allocatable |
5470 | || (ref->u.c.component->ts.type == BT_CLASS |
5471 | && CLASS_DATA (ref->u.c.component)ref->u.c.component->ts.u.derived->components->attr.allocatable)) |
5472 | |
5473 | { |
5474 | gfc_error ("Component to the right of a part reference " |
5475 | "with nonzero rank must not have the ALLOCATABLE " |
5476 | "attribute at %L", &expr->where); |
5477 | return false; |
5478 | } |
5479 | } |
5480 | |
5481 | n_components++; |
5482 | break; |
5483 | |
5484 | case REF_SUBSTRING: |
5485 | break; |
5486 | |
5487 | case REF_INQUIRY: |
5488 | /* Implement requirement in note 9.7 of F2018 that the result of the |
5489 | LEN inquiry be a scalar. */ |
5490 | if (ref->u.i == INQUIRY_LEN && array_ref && expr->ts.deferred) |
5491 | { |
5492 | array_ref->u.ar.type = AR_ELEMENT; |
5493 | expr->rank = 0; |
5494 | /* INQUIRY_LEN is not evaluated from the rest of the expr |
5495 | but directly from the string length. This means that setting |
5496 | the array indices to one does not matter but might trigger |
5497 | a runtime bounds error. Suppress the check. */ |
5498 | expr->no_bounds_check = 1; |
5499 | for (dim = 0; dim < array_ref->u.ar.dimen; dim++) |
5500 | { |
5501 | array_ref->u.ar.dimen_type[dim] = DIMEN_ELEMENT; |
5502 | if (array_ref->u.ar.start[dim]) |
5503 | gfc_free_expr (array_ref->u.ar.start[dim]); |
5504 | array_ref->u.ar.start[dim] |
5505 | = gfc_get_int_expr (gfc_default_integer_kind, NULL__null, 1); |
5506 | if (array_ref->u.ar.end[dim]) |
5507 | gfc_free_expr (array_ref->u.ar.end[dim]); |
5508 | if (array_ref->u.ar.stride[dim]) |
5509 | gfc_free_expr (array_ref->u.ar.stride[dim]); |
5510 | } |
5511 | } |
5512 | break; |
5513 | } |
5514 | |
5515 | if (((ref->type == REF_COMPONENT && n_components > 1) |
5516 | || ref->next == NULL__null) |
5517 | && current_part_dimension |
5518 | && seen_part_dimension) |
5519 | { |
5520 | gfc_error ("Two or more part references with nonzero rank must " |
5521 | "not be specified at %L", &expr->where); |
5522 | return false; |
5523 | } |
5524 | |
5525 | if (ref->type == REF_COMPONENT) |
5526 | { |
5527 | if (current_part_dimension) |
5528 | seen_part_dimension = 1; |
5529 | |
5530 | /* reset to make sure */ |
5531 | current_part_dimension = 0; |
5532 | } |
5533 | } |
5534 | |
5535 | return true; |
5536 | } |
5537 | |
5538 | |
5539 | /* Given an expression, determine its shape. This is easier than it sounds. |
5540 | Leaves the shape array NULL if it is not possible to determine the shape. */ |
5541 | |
5542 | static void |
5543 | expression_shape (gfc_expr *e) |
5544 | { |
5545 | mpz_t array[GFC_MAX_DIMENSIONS15]; |
5546 | int i; |
5547 | |
5548 | if (e->rank <= 0 || e->shape != NULL__null) |
5549 | return; |
5550 | |
5551 | for (i = 0; i < e->rank; i++) |
5552 | if (!gfc_array_dimen_size (e, i, &array[i])) |
5553 | goto fail; |
5554 | |
5555 | e->shape = gfc_get_shape (e->rank)(((mpz_t *) xcalloc (((e->rank)), sizeof (mpz_t)))); |
5556 | |
5557 | memcpy (e->shape, array, e->rank * sizeof (mpz_t)); |
5558 | |
5559 | return; |
5560 | |
5561 | fail: |
5562 | for (i--; i >= 0; i--) |
5563 | mpz_clear__gmpz_clear (array[i]); |
5564 | } |
5565 | |
5566 | |
5567 | /* Given a variable expression node, compute the rank of the expression by |
5568 | examining the base symbol and any reference structures it may have. */ |
5569 | |
5570 | void |
5571 | gfc_expression_rank (gfc_expr *e) |
5572 | { |
5573 | gfc_ref *ref; |
5574 | int i, rank; |
5575 | |
5576 | /* Just to make sure, because EXPR_COMPCALL's also have an e->ref and that |
5577 | could lead to serious confusion... */ |
5578 | gcc_assert (e->expr_type != EXPR_COMPCALL)((void)(!(e->expr_type != EXPR_COMPCALL) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 5578, __FUNCTION__), 0 : 0)); |
5579 | |
5580 | if (e->ref == NULL__null) |
5581 | { |
5582 | if (e->expr_type == EXPR_ARRAY) |
5583 | goto done; |
5584 | /* Constructors can have a rank different from one via RESHAPE(). */ |
5585 | |
5586 | e->rank = ((e->symtree == NULL__null || e->symtree->n.sym->as == NULL__null) |
5587 | ? 0 : e->symtree->n.sym->as->rank); |
5588 | goto done; |
5589 | } |
5590 | |
5591 | rank = 0; |
5592 | |
5593 | for (ref = e->ref; ref; ref = ref->next) |
5594 | { |
5595 | if (ref->type == REF_COMPONENT && ref->u.c.component->attr.proc_pointer |
5596 | && ref->u.c.component->attr.function && !ref->next) |
5597 | rank = ref->u.c.component->as ? ref->u.c.component->as->rank : 0; |
5598 | |
5599 | if (ref->type != REF_ARRAY) |
5600 | continue; |
5601 | |
5602 | if (ref->u.ar.type == AR_FULL) |
5603 | { |
5604 | rank = ref->u.ar.as->rank; |
5605 | break; |
5606 | } |
5607 | |
5608 | if (ref->u.ar.type == AR_SECTION) |
5609 | { |
5610 | /* Figure out the rank of the section. */ |
5611 | if (rank != 0) |
5612 | gfc_internal_error ("gfc_expression_rank(): Two array specs"); |
5613 | |
5614 | for (i = 0; i < ref->u.ar.dimen; i++) |
5615 | if (ref->u.ar.dimen_type[i] == DIMEN_RANGE |
5616 | || ref->u.ar.dimen_type[i] == DIMEN_VECTOR) |
5617 | rank++; |
5618 | |
5619 | break; |
5620 | } |
5621 | } |
5622 | |
5623 | e->rank = rank; |
5624 | |
5625 | done: |
5626 | expression_shape (e); |
5627 | } |
5628 | |
5629 | |
5630 | static void |
5631 | add_caf_get_intrinsic (gfc_expr *e) |
5632 | { |
5633 | gfc_expr *wrapper, *tmp_expr; |
5634 | gfc_ref *ref; |
5635 | int n; |
5636 | |
5637 | for (ref = e->ref; ref; ref = ref->next) |
5638 | if (ref->type == REF_ARRAY && ref->u.ar.codimen > 0) |
5639 | break; |
5640 | if (ref == NULL__null) |
5641 | return; |
5642 | |
5643 | for (n = ref->u.ar.dimen; n < ref->u.ar.dimen + ref->u.ar.codimen; n++) |
5644 | if (ref->u.ar.dimen_type[n] != DIMEN_ELEMENT) |
5645 | return; |
5646 | |
5647 | tmp_expr = XCNEW (gfc_expr)((gfc_expr *) xcalloc (1, sizeof (gfc_expr))); |
5648 | *tmp_expr = *e; |
5649 | wrapper = gfc_build_intrinsic_call (gfc_current_ns, GFC_ISYM_CAF_GET, |
5650 | "caf_get", tmp_expr->where, 1, tmp_expr); |
5651 | wrapper->ts = e->ts; |
5652 | wrapper->rank = e->rank; |
5653 | if (e->rank) |
5654 | wrapper->shape = gfc_copy_shape (e->shape, e->rank); |
5655 | *e = *wrapper; |
5656 | free (wrapper); |
5657 | } |
5658 | |
5659 | |
5660 | static void |
5661 | remove_caf_get_intrinsic (gfc_expr *e) |
5662 | { |
5663 | gcc_assert (e->expr_type == EXPR_FUNCTION && e->value.function.isym((void)(!(e->expr_type == EXPR_FUNCTION && e->value .function.isym && e->value.function.isym->id == GFC_ISYM_CAF_GET) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 5664, __FUNCTION__), 0 : 0)) |
5664 | && e->value.function.isym->id == GFC_ISYM_CAF_GET)((void)(!(e->expr_type == EXPR_FUNCTION && e->value .function.isym && e->value.function.isym->id == GFC_ISYM_CAF_GET) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 5664, __FUNCTION__), 0 : 0)); |
5665 | gfc_expr *e2 = e->value.function.actual->expr; |
5666 | e->value.function.actual->expr = NULL__null; |
5667 | gfc_free_actual_arglist (e->value.function.actual); |
5668 | gfc_free_shape (&e->shape, e->rank); |
5669 | *e = *e2; |
5670 | free (e2); |
5671 | } |
5672 | |
5673 | |
5674 | /* Resolve a variable expression. */ |
5675 | |
5676 | static bool |
5677 | resolve_variable (gfc_expr *e) |
5678 | { |
5679 | gfc_symbol *sym; |
5680 | bool t; |
5681 | |
5682 | t = true; |
5683 | |
5684 | if (e->symtree == NULL__null) |
5685 | return false; |
5686 | sym = e->symtree->n.sym; |
5687 | |
5688 | /* Use same check as for TYPE(*) below; this check has to be before TYPE(*) |
5689 | as ts.type is set to BT_ASSUMED in resolve_symbol. */ |
5690 | if (sym->attr.ext_attr & (1 << EXT_ATTR_NO_ARG_CHECK)) |
5691 | { |
5692 | if (!actual_arg || inquiry_argument) |
5693 | { |
5694 | gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute may only " |
5695 | "be used as actual argument", sym->name, &e->where); |
5696 | return false; |
5697 | } |
5698 | } |
5699 | /* TS 29113, 407b. */ |
5700 | else if (e->ts.type == BT_ASSUMED) |
5701 | { |
5702 | if (!actual_arg) |
5703 | { |
5704 | gfc_error ("Assumed-type variable %s at %L may only be used " |
5705 | "as actual argument", sym->name, &e->where); |
5706 | return false; |
5707 | } |
5708 | else if (inquiry_argument && !first_actual_arg) |
5709 | { |
5710 | /* FIXME: It doesn't work reliably as inquiry_argument is not set |
5711 | for all inquiry functions in resolve_function; the reason is |
5712 | that the function-name resolution happens too late in that |
5713 | function. */ |
5714 | gfc_error ("Assumed-type variable %s at %L as actual argument to " |
5715 | "an inquiry function shall be the first argument", |
5716 | sym->name, &e->where); |
5717 | return false; |
5718 | } |
5719 | } |
5720 | /* TS 29113, C535b. */ |
5721 | else if (((sym->ts.type == BT_CLASS && sym->attr.class_ok |
5722 | && sym->ts.u.derived && CLASS_DATA (sym)sym->ts.u.derived->components |
5723 | && CLASS_DATA (sym)sym->ts.u.derived->components->as |
5724 | && CLASS_DATA (sym)sym->ts.u.derived->components->as->type == AS_ASSUMED_RANK) |
5725 | || (sym->ts.type != BT_CLASS && sym->as |
5726 | && sym->as->type == AS_ASSUMED_RANK)) |
5727 | && !sym->attr.select_rank_temporary) |
5728 | { |
5729 | if (!actual_arg |
5730 | && !(cs_base && cs_base->current |
5731 | && cs_base->current->op == EXEC_SELECT_RANK)) |
5732 | { |
5733 | gfc_error ("Assumed-rank variable %s at %L may only be used as " |
5734 | "actual argument", sym->name, &e->where); |
5735 | return false; |
5736 | } |
5737 | else if (inquiry_argument && !first_actual_arg) |
5738 | { |
5739 | /* FIXME: It doesn't work reliably as inquiry_argument is not set |
5740 | for all inquiry functions in resolve_function; the reason is |
5741 | that the function-name resolution happens too late in that |
5742 | function. */ |
5743 | gfc_error ("Assumed-rank variable %s at %L as actual argument " |
5744 | "to an inquiry function shall be the first argument", |
5745 | sym->name, &e->where); |
5746 | return false; |
5747 | } |
5748 | } |
5749 | |
5750 | if ((sym->attr.ext_attr & (1 << EXT_ATTR_NO_ARG_CHECK)) && e->ref |
5751 | && !(e->ref->type == REF_ARRAY && e->ref->u.ar.type == AR_FULL |
5752 | && e->ref->next == NULL__null)) |
5753 | { |
5754 | gfc_error ("Variable %s at %L with NO_ARG_CHECK attribute shall not have " |
5755 | "a subobject reference", sym->name, &e->ref->u.ar.where); |
5756 | return false; |
5757 | } |
5758 | /* TS 29113, 407b. */ |
5759 | else if (e->ts.type == BT_ASSUMED && e->ref |
5760 | && !(e->ref->type == REF_ARRAY && e->ref->u.ar.type == AR_FULL |
5761 | && e->ref->next == NULL__null)) |
5762 | { |
5763 | gfc_error ("Assumed-type variable %s at %L shall not have a subobject " |
5764 | "reference", sym->name, &e->ref->u.ar.where); |
5765 | return false; |
5766 | } |
5767 | |
5768 | /* TS 29113, C535b. */ |
5769 | if (((sym->ts.type == BT_CLASS && sym->attr.class_ok |
5770 | && sym->ts.u.derived && CLASS_DATA (sym)sym->ts.u.derived->components |
5771 | && CLASS_DATA (sym)sym->ts.u.derived->components->as |
5772 | && CLASS_DATA (sym)sym->ts.u.derived->components->as->type == AS_ASSUMED_RANK) |
5773 | || (sym->ts.type != BT_CLASS && sym->as |
5774 | && sym->as->type == AS_ASSUMED_RANK)) |
5775 | && e->ref |
5776 | && !(e->ref->type == REF_ARRAY && e->ref->u.ar.type == AR_FULL |
5777 | && e->ref->next == NULL__null)) |
5778 | { |
5779 | gfc_error ("Assumed-rank variable %s at %L shall not have a subobject " |
5780 | "reference", sym->name, &e->ref->u.ar.where); |
5781 | return false; |
5782 | } |
5783 | |
5784 | /* For variables that are used in an associate (target => object) where |
5785 | the object's basetype is array valued while the target is scalar, |
5786 | the ts' type of the component refs is still array valued, which |
5787 | can't be translated that way. */ |
5788 | if (sym->assoc && e->rank == 0 && e->ref && sym->ts.type == BT_CLASS |
5789 | && sym->assoc->target && sym->assoc->target->ts.type == BT_CLASS |
5790 | && sym->assoc->target->ts.u.derived |
5791 | && CLASS_DATA (sym->assoc->target)sym->assoc->target->ts.u.derived->components |
5792 | && CLASS_DATA (sym->assoc->target)sym->assoc->target->ts.u.derived->components->as) |
5793 | { |
5794 | gfc_ref *ref = e->ref; |
5795 | while (ref) |
5796 | { |
5797 | switch (ref->type) |
5798 | { |
5799 | case REF_COMPONENT: |
5800 | ref->u.c.sym = sym->ts.u.derived; |
5801 | /* Stop the loop. */ |
5802 | ref = NULL__null; |
5803 | break; |
5804 | default: |
5805 | ref = ref->next; |
5806 | break; |
5807 | } |
5808 | } |
5809 | } |
5810 | |
5811 | /* If this is an associate-name, it may be parsed with an array reference |
5812 | in error even though the target is scalar. Fail directly in this case. |
5813 | TODO Understand why class scalar expressions must be excluded. */ |
5814 | if (sym->assoc && !(sym->ts.type == BT_CLASS && e->rank == 0)) |
5815 | { |
5816 | if (sym->ts.type == BT_CLASS) |
5817 | gfc_fix_class_refs (e); |
5818 | if (!sym->attr.dimension && e->ref && e->ref->type == REF_ARRAY) |
5819 | return false; |
5820 | else if (sym->attr.dimension && (!e->ref || e->ref->type != REF_ARRAY)) |
5821 | { |
5822 | /* This can happen because the parser did not detect that the |
5823 | associate name is an array and the expression had no array |
5824 | part_ref. */ |
5825 | gfc_ref *ref = gfc_get_ref ()((gfc_ref *) xcalloc (1, sizeof (gfc_ref))); |
5826 | ref->type = REF_ARRAY; |
5827 | ref->u.ar.type = AR_FULL; |
5828 | if (sym->as) |
5829 | { |
5830 | ref->u.ar.as = sym->as; |
5831 | ref->u.ar.dimen = sym->as->rank; |
5832 | } |
5833 | ref->next = e->ref; |
5834 | e->ref = ref; |
5835 | |
5836 | } |
5837 | } |
5838 | |
5839 | if (sym->ts.type == BT_DERIVED && sym->ts.u.derived->attr.generic) |
5840 | sym->ts.u.derived = gfc_find_dt_in_generic (sym->ts.u.derived); |
5841 | |
5842 | /* On the other hand, the parser may not have known this is an array; |
5843 | in this case, we have to add a FULL reference. */ |
5844 | if (sym->assoc && sym->attr.dimension && !e->ref) |
5845 | { |
5846 | e->ref = gfc_get_ref ()((gfc_ref *) xcalloc (1, sizeof (gfc_ref))); |
5847 | e->ref->type = REF_ARRAY; |
5848 | e->ref->u.ar.type = AR_FULL; |
5849 | e->ref->u.ar.dimen = 0; |
5850 | } |
5851 | |
5852 | /* Like above, but for class types, where the checking whether an array |
5853 | ref is present is more complicated. Furthermore make sure not to add |
5854 | the full array ref to _vptr or _len refs. */ |
5855 | if (sym->assoc && sym->ts.type == BT_CLASS && sym->ts.u.derived |
5856 | && CLASS_DATA (sym)sym->ts.u.derived->components |
5857 | && CLASS_DATA (sym)sym->ts.u.derived->components->attr.dimension |
5858 | && (e->ts.type != BT_DERIVED || !e->ts.u.derived->attr.vtype)) |
5859 | { |
5860 | gfc_ref *ref, *newref; |
5861 | |
5862 | newref = gfc_get_ref ()((gfc_ref *) xcalloc (1, sizeof (gfc_ref))); |
5863 | newref->type = REF_ARRAY; |
5864 | newref->u.ar.type = AR_FULL; |
5865 | newref->u.ar.dimen = 0; |
5866 | /* Because this is an associate var and the first ref either is a ref to |
5867 | the _data component or not, no traversal of the ref chain is |
5868 | needed. The array ref needs to be inserted after the _data ref, |
5869 | or when that is not present, which may happend for polymorphic |
5870 | types, then at the first position. */ |
5871 | ref = e->ref; |
5872 | if (!ref) |
5873 | e->ref = newref; |
5874 | else if (ref->type == REF_COMPONENT |
5875 | && strcmp ("_data", ref->u.c.component->name) == 0) |
5876 | { |
5877 | if (!ref->next || ref->next->type != REF_ARRAY) |
5878 | { |
5879 | newref->next = ref->next; |
5880 | ref->next = newref; |
5881 | } |
5882 | else |
5883 | /* Array ref present already. */ |
5884 | gfc_free_ref_list (newref); |
5885 | } |
5886 | else if (ref->type == REF_ARRAY) |
5887 | /* Array ref present already. */ |
5888 | gfc_free_ref_list (newref); |
5889 | else |
5890 | { |
5891 | newref->next = ref; |
5892 | e->ref = newref; |
5893 | } |
5894 | } |
5895 | |
5896 | if (e->ref && !gfc_resolve_ref (e)) |
5897 | return false; |
5898 | |
5899 | if (sym->attr.flavor == FL_PROCEDURE |
5900 | && (!sym->attr.function |
5901 | || (sym->attr.function && sym->result |
5902 | && sym->result->attr.proc_pointer |
5903 | && !sym->result->attr.function))) |
5904 | { |
5905 | e->ts.type = BT_PROCEDURE; |
5906 | goto resolve_procedure; |
5907 | } |
5908 | |
5909 | if (sym->ts.type != BT_UNKNOWN) |
5910 | gfc_variable_attr (e, &e->ts); |
5911 | else if (sym->attr.flavor == FL_PROCEDURE |
5912 | && sym->attr.function && sym->result |
5913 | && sym->result->ts.type != BT_UNKNOWN |
5914 | && sym->result->attr.proc_pointer) |
5915 | e->ts = sym->result->ts; |
5916 | else |
5917 | { |
5918 | /* Must be a simple variable reference. */ |
5919 | if (!gfc_set_default_type (sym, 1, sym->ns)) |
5920 | return false; |
5921 | e->ts = sym->ts; |
5922 | } |
5923 | |
5924 | if (check_assumed_size_reference (sym, e)) |
5925 | return false; |
5926 | |
5927 | /* Deal with forward references to entries during gfc_resolve_code, to |
5928 | satisfy, at least partially, 12.5.2.5. */ |
5929 | if (gfc_current_ns->entries |
5930 | && current_entry_id == sym->entry_id |
5931 | && cs_base |
5932 | && cs_base->current |
5933 | && cs_base->current->op != EXEC_ENTRY) |
5934 | { |
5935 | gfc_entry_list *entry; |
5936 | gfc_formal_arglist *formal; |
5937 | int n; |
5938 | bool seen, saved_specification_expr; |
5939 | |
5940 | /* If the symbol is a dummy... */ |
5941 | if (sym->attr.dummy && sym->ns == gfc_current_ns) |
5942 | { |
5943 | entry = gfc_current_ns->entries; |
5944 | seen = false; |
5945 | |
5946 | /* ...test if the symbol is a parameter of previous entries. */ |
5947 | for (; entry && entry->id <= current_entry_id; entry = entry->next) |
5948 | for (formal = entry->sym->formal; formal; formal = formal->next) |
5949 | { |
5950 | if (formal->sym && sym->name == formal->sym->name) |
5951 | { |
5952 | seen = true; |
5953 | break; |
5954 | } |
5955 | } |
5956 | |
5957 | /* If it has not been seen as a dummy, this is an error. */ |
5958 | if (!seen) |
5959 | { |
5960 | if (specification_expr) |
5961 | gfc_error ("Variable %qs, used in a specification expression" |
5962 | ", is referenced at %L before the ENTRY statement " |
5963 | "in which it is a parameter", |
5964 | sym->name, &cs_base->current->loc); |
5965 | else |
5966 | gfc_error ("Variable %qs is used at %L before the ENTRY " |
5967 | "statement in which it is a parameter", |
5968 | sym->name, &cs_base->current->loc); |
5969 | t = false; |
5970 | } |
5971 | } |
5972 | |
5973 | /* Now do the same check on the specification expressions. */ |
5974 | saved_specification_expr = specification_expr; |
5975 | specification_expr = true; |
5976 | if (sym->ts.type == BT_CHARACTER |
5977 | && !gfc_resolve_expr (sym->ts.u.cl->length)) |
5978 | t = false; |
5979 | |
5980 | if (sym->as) |
5981 | for (n = 0; n < sym->as->rank; n++) |
5982 | { |
5983 | if (!gfc_resolve_expr (sym->as->lower[n])) |
5984 | t = false; |
5985 | if (!gfc_resolve_expr (sym->as->upper[n])) |
5986 | t = false; |
5987 | } |
5988 | specification_expr = saved_specification_expr; |
5989 | |
5990 | if (t) |
5991 | /* Update the symbol's entry level. */ |
5992 | sym->entry_id = current_entry_id + 1; |
5993 | } |
5994 | |
5995 | /* If a symbol has been host_associated mark it. This is used latter, |
5996 | to identify if aliasing is possible via host association. */ |
5997 | if (sym->attr.flavor == FL_VARIABLE |
5998 | && gfc_current_ns->parent |
5999 | && (gfc_current_ns->parent == sym->ns |
6000 | || (gfc_current_ns->parent->parent |
6001 | && gfc_current_ns->parent->parent == sym->ns))) |
6002 | sym->attr.host_assoc = 1; |
6003 | |
6004 | if (gfc_current_ns->proc_name |
6005 | && sym->attr.dimension |
6006 | && (sym->ns != gfc_current_ns |
6007 | || sym->attr.use_assoc |
6008 | || sym->attr.in_common)) |
6009 | gfc_current_ns->proc_name->attr.array_outer_dependency = 1; |
6010 | |
6011 | resolve_procedure: |
6012 | if (t && !resolve_procedure_expression (e)) |
6013 | t = false; |
6014 | |
6015 | /* F2008, C617 and C1229. */ |
6016 | if (!inquiry_argument && (e->ts.type == BT_CLASS || e->ts.type == BT_DERIVED) |
6017 | && gfc_is_coindexed (e)) |
6018 | { |
6019 | gfc_ref *ref, *ref2 = NULL__null; |
6020 | |
6021 | for (ref = e->ref; ref; ref = ref->next) |
6022 | { |
6023 | if (ref->type == REF_COMPONENT) |
6024 | ref2 = ref; |
6025 | if (ref->type == REF_ARRAY && ref->u.ar.codimen > 0) |
6026 | break; |
6027 | } |
6028 | |
6029 | for ( ; ref; ref = ref->next) |
6030 | if (ref->type == REF_COMPONENT) |
6031 | break; |
6032 | |
6033 | /* Expression itself is not coindexed object. */ |
6034 | if (ref && e->ts.type == BT_CLASS) |
6035 | { |
6036 | gfc_error ("Polymorphic subobject of coindexed object at %L", |
6037 | &e->where); |
6038 | t = false; |
6039 | } |
6040 | |
6041 | /* Expression itself is coindexed object. */ |
6042 | if (ref == NULL__null) |
6043 | { |
6044 | gfc_component *c; |
6045 | c = ref2 ? ref2->u.c.component : e->symtree->n.sym->components; |
6046 | for ( ; c; c = c->next) |
6047 | if (c->attr.allocatable && c->ts.type == BT_CLASS) |
6048 | { |
6049 | gfc_error ("Coindexed object with polymorphic allocatable " |
6050 | "subcomponent at %L", &e->where); |
6051 | t = false; |
6052 | break; |
6053 | } |
6054 | } |
6055 | } |
6056 | |
6057 | if (t) |
6058 | gfc_expression_rank (e); |
6059 | |
6060 | if (t && flag_coarrayglobal_options.x_flag_coarray == GFC_FCOARRAY_LIB && gfc_is_coindexed (e)) |
6061 | add_caf_get_intrinsic (e); |
6062 | |
6063 | if (sym->attr.ext_attr & (1 << EXT_ATTR_DEPRECATED) && sym != sym->result) |
6064 | gfc_warning (OPT_Wdeprecated_declarations, |
6065 | "Using variable %qs at %L is deprecated", |
6066 | sym->name, &e->where); |
6067 | /* Simplify cases where access to a parameter array results in a |
6068 | single constant. Suppress errors since those will have been |
6069 | issued before, as warnings. */ |
6070 | if (e->rank == 0 && sym->as && sym->attr.flavor == FL_PARAMETER) |
6071 | { |
6072 | gfc_push_suppress_errors (); |
6073 | gfc_simplify_expr (e, 1); |
6074 | gfc_pop_suppress_errors (); |
6075 | } |
6076 | |
6077 | return t; |
6078 | } |
6079 | |
6080 | |
6081 | /* Checks to see that the correct symbol has been host associated. |
6082 | The only situations where this arises are: |
6083 | (i) That in which a twice contained function is parsed after |
6084 | the host association is made. On detecting this, change |
6085 | the symbol in the expression and convert the array reference |
6086 | into an actual arglist if the old symbol is a variable; or |
6087 | (ii) That in which an external function is typed but not declared |
6088 | explcitly to be external. Here, the old symbol is changed |
6089 | from a variable to an external function. */ |
6090 | static bool |
6091 | check_host_association (gfc_expr *e) |
6092 | { |
6093 | gfc_symbol *sym, *old_sym; |
6094 | gfc_symtree *st; |
6095 | int n; |
6096 | gfc_ref *ref; |
6097 | gfc_actual_arglist *arg, *tail = NULL__null; |
6098 | bool retval = e->expr_type == EXPR_FUNCTION; |
6099 | |
6100 | /* If the expression is the result of substitution in |
6101 | interface.cc(gfc_extend_expr) because there is no way in |
6102 | which the host association can be wrong. */ |
6103 | if (e->symtree == NULL__null |
6104 | || e->symtree->n.sym == NULL__null |
6105 | || e->user_operator) |
6106 | return retval; |
6107 | |
6108 | old_sym = e->symtree->n.sym; |
6109 | |
6110 | if (gfc_current_ns->parent |
6111 | && old_sym->ns != gfc_current_ns) |
6112 | { |
6113 | /* Use the 'USE' name so that renamed module symbols are |
6114 | correctly handled. */ |
6115 | gfc_find_symbol (e->symtree->name, gfc_current_ns, 1, &sym); |
6116 | |
6117 | if (sym && old_sym != sym |
6118 | && sym->attr.flavor == FL_PROCEDURE |
6119 | && sym->attr.contained) |
6120 | { |
6121 | /* Clear the shape, since it might not be valid. */ |
6122 | gfc_free_shape (&e->shape, e->rank); |
6123 | |
6124 | /* Give the expression the right symtree! */ |
6125 | gfc_find_sym_tree (e->symtree->name, NULL__null, 1, &st); |
6126 | gcc_assert (st != NULL)((void)(!(st != __null) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 6126, __FUNCTION__), 0 : 0)); |
6127 | |
6128 | if (old_sym->attr.flavor == FL_PROCEDURE |
6129 | || e->expr_type == EXPR_FUNCTION) |
6130 | { |
6131 | /* Original was function so point to the new symbol, since |
6132 | the actual argument list is already attached to the |
6133 | expression. */ |
6134 | e->value.function.esym = NULL__null; |
6135 | e->symtree = st; |
6136 | } |
6137 | else |
6138 | { |
6139 | /* Original was variable so convert array references into |
6140 | an actual arglist. This does not need any checking now |
6141 | since resolve_function will take care of it. */ |
6142 | e->value.function.actual = NULL__null; |
6143 | e->expr_type = EXPR_FUNCTION; |
6144 | e->symtree = st; |
6145 | |
6146 | /* Ambiguity will not arise if the array reference is not |
6147 | the last reference. */ |
6148 | for (ref = e->ref; ref; ref = ref->next) |
6149 | if (ref->type == REF_ARRAY && ref->next == NULL__null) |
6150 | break; |
6151 | |
6152 | if ((ref == NULL__null || ref->type != REF_ARRAY) |
6153 | && sym->attr.proc == PROC_INTERNAL) |
6154 | { |
6155 | gfc_error ("%qs at %L is host associated at %L into " |
6156 | "a contained procedure with an internal " |
6157 | "procedure of the same name", sym->name, |
6158 | &old_sym->declared_at, &e->where); |
6159 | return false; |
6160 | } |
6161 | |
6162 | if (ref == NULL__null) |
6163 | return false; |
6164 | |
6165 | gcc_assert (ref->type == REF_ARRAY)((void)(!(ref->type == REF_ARRAY) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 6165, __FUNCTION__), 0 : 0)); |
6166 | |
6167 | /* Grab the start expressions from the array ref and |
6168 | copy them into actual arguments. */ |
6169 | for (n = 0; n < ref->u.ar.dimen; n++) |
6170 | { |
6171 | arg = gfc_get_actual_arglist ()((gfc_actual_arglist *) xcalloc (1, sizeof (gfc_actual_arglist ))); |
6172 | arg->expr = gfc_copy_expr (ref->u.ar.start[n]); |
6173 | if (e->value.function.actual == NULL__null) |
6174 | tail = e->value.function.actual = arg; |
6175 | else |
6176 | { |
6177 | tail->next = arg; |
6178 | tail = arg; |
6179 | } |
6180 | } |
6181 | |
6182 | /* Dump the reference list and set the rank. */ |
6183 | gfc_free_ref_list (e->ref); |
6184 | e->ref = NULL__null; |
6185 | e->rank = sym->as ? sym->as->rank : 0; |
6186 | } |
6187 | |
6188 | gfc_resolve_expr (e); |
6189 | sym->refs++; |
6190 | } |
6191 | /* This case corresponds to a call, from a block or a contained |
6192 | procedure, to an external function, which has not been declared |
6193 | as being external in the main program but has been typed. */ |
6194 | else if (sym && old_sym != sym |
6195 | && !e->ref |
6196 | && sym->ts.type == BT_UNKNOWN |
6197 | && old_sym->ts.type != BT_UNKNOWN |
6198 | && sym->attr.flavor == FL_PROCEDURE |
6199 | && old_sym->attr.flavor == FL_VARIABLE |
6200 | && sym->ns->parent == old_sym->ns |
6201 | && sym->ns->proc_name |
6202 | && sym->ns->proc_name->attr.proc != PROC_MODULE |
6203 | && (sym->ns->proc_name->attr.flavor == FL_LABEL |
6204 | || sym->ns->proc_name->attr.flavor == FL_PROCEDURE)) |
6205 | { |
6206 | old_sym->attr.flavor = FL_PROCEDURE; |
6207 | old_sym->attr.external = 1; |
6208 | old_sym->attr.function = 1; |
6209 | old_sym->result = old_sym; |
6210 | gfc_resolve_expr (e); |
6211 | } |
6212 | } |
6213 | /* This might have changed! */ |
6214 | return e->expr_type == EXPR_FUNCTION; |
6215 | } |
6216 | |
6217 | |
6218 | static void |
6219 | gfc_resolve_character_operator (gfc_expr *e) |
6220 | { |
6221 | gfc_expr *op1 = e->value.op.op1; |
6222 | gfc_expr *op2 = e->value.op.op2; |
6223 | gfc_expr *e1 = NULL__null; |
6224 | gfc_expr *e2 = NULL__null; |
6225 | |
6226 | gcc_assert (e->value.op.op == INTRINSIC_CONCAT)((void)(!(e->value.op.op == INTRINSIC_CONCAT) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 6226, __FUNCTION__), 0 : 0)); |
6227 | |
6228 | if (op1->ts.u.cl && op1->ts.u.cl->length) |
6229 | e1 = gfc_copy_expr (op1->ts.u.cl->length); |
6230 | else if (op1->expr_type == EXPR_CONSTANT) |
6231 | e1 = gfc_get_int_expr (gfc_charlen_int_kind, NULL__null, |
6232 | op1->value.character.length); |
6233 | |
6234 | if (op2->ts.u.cl && op2->ts.u.cl->length) |
6235 | e2 = gfc_copy_expr (op2->ts.u.cl->length); |
6236 | else if (op2->expr_type == EXPR_CONSTANT) |
6237 | e2 = gfc_get_int_expr (gfc_charlen_int_kind, NULL__null, |
6238 | op2->value.character.length); |
6239 | |
6240 | e->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL__null); |
6241 | |
6242 | if (!e1 || !e2) |
6243 | { |
6244 | gfc_free_expr (e1); |
6245 | gfc_free_expr (e2); |
6246 | |
6247 | return; |
6248 | } |
6249 | |
6250 | e->ts.u.cl->length = gfc_add (e1, e2); |
6251 | e->ts.u.cl->length->ts.type = BT_INTEGER; |
6252 | e->ts.u.cl->length->ts.kind = gfc_charlen_int_kind; |
6253 | gfc_simplify_expr (e->ts.u.cl->length, 0); |
6254 | gfc_resolve_expr (e->ts.u.cl->length); |
6255 | |
6256 | return; |
6257 | } |
6258 | |
6259 | |
6260 | /* Ensure that an character expression has a charlen and, if possible, a |
6261 | length expression. */ |
6262 | |
6263 | static void |
6264 | fixup_charlen (gfc_expr *e) |
6265 | { |
6266 | /* The cases fall through so that changes in expression type and the need |
6267 | for multiple fixes are picked up. In all circumstances, a charlen should |
6268 | be available for the middle end to hang a backend_decl on. */ |
6269 | switch (e->expr_type) |
6270 | { |
6271 | case EXPR_OP: |
6272 | gfc_resolve_character_operator (e); |
6273 | /* FALLTHRU */ |
6274 | |
6275 | case EXPR_ARRAY: |
6276 | if (e->expr_type == EXPR_ARRAY) |
6277 | gfc_resolve_character_array_constructor (e); |
6278 | /* FALLTHRU */ |
6279 | |
6280 | case EXPR_SUBSTRING: |
6281 | if (!e->ts.u.cl && e->ref) |
6282 | gfc_resolve_substring_charlen (e); |
6283 | /* FALLTHRU */ |
6284 | |
6285 | default: |
6286 | if (!e->ts.u.cl) |
6287 | e->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL__null); |
6288 | |
6289 | break; |
6290 | } |
6291 | } |
6292 | |
6293 | |
6294 | /* Update an actual argument to include the passed-object for type-bound |
6295 | procedures at the right position. */ |
6296 | |
6297 | static gfc_actual_arglist* |
6298 | update_arglist_pass (gfc_actual_arglist* lst, gfc_expr* po, unsigned argpos, |
6299 | const char *name) |
6300 | { |
6301 | gcc_assert (argpos > 0)((void)(!(argpos > 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 6301, __FUNCTION__), 0 : 0)); |
6302 | |
6303 | if (argpos == 1) |
6304 | { |
6305 | gfc_actual_arglist* result; |
6306 | |
6307 | result = gfc_get_actual_arglist ()((gfc_actual_arglist *) xcalloc (1, sizeof (gfc_actual_arglist ))); |
6308 | result->expr = po; |
6309 | result->next = lst; |
6310 | if (name) |
6311 | result->name = name; |
6312 | |
6313 | return result; |
6314 | } |
6315 | |
6316 | if (lst) |
6317 | lst->next = update_arglist_pass (lst->next, po, argpos - 1, name); |
6318 | else |
6319 | lst = update_arglist_pass (NULL__null, po, argpos - 1, name); |
6320 | return lst; |
6321 | } |
6322 | |
6323 | |
6324 | /* Extract the passed-object from an EXPR_COMPCALL (a copy of it). */ |
6325 | |
6326 | static gfc_expr* |
6327 | extract_compcall_passed_object (gfc_expr* e) |
6328 | { |
6329 | gfc_expr* po; |
6330 | |
6331 | if (e->expr_type == EXPR_UNKNOWN) |
6332 | { |
6333 | gfc_error ("Error in typebound call at %L", |
6334 | &e->where); |
6335 | return NULL__null; |
6336 | } |
6337 | |
6338 | gcc_assert (e->expr_type == EXPR_COMPCALL)((void)(!(e->expr_type == EXPR_COMPCALL) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 6338, __FUNCTION__), 0 : 0)); |
6339 | |
6340 | if (e->value.compcall.base_object) |
6341 | po = gfc_copy_expr (e->value.compcall.base_object); |
6342 | else |
6343 | { |
6344 | po = gfc_get_expr (); |
6345 | po->expr_type = EXPR_VARIABLE; |
6346 | po->symtree = e->symtree; |
6347 | po->ref = gfc_copy_ref (e->ref); |
6348 | po->where = e->where; |
6349 | } |
6350 | |
6351 | if (!gfc_resolve_expr (po)) |
6352 | return NULL__null; |
6353 | |
6354 | return po; |
6355 | } |
6356 | |
6357 | |
6358 | /* Update the arglist of an EXPR_COMPCALL expression to include the |
6359 | passed-object. */ |
6360 | |
6361 | static bool |
6362 | update_compcall_arglist (gfc_expr* e) |
6363 | { |
6364 | gfc_expr* po; |
6365 | gfc_typebound_proc* tbp; |
6366 | |
6367 | tbp = e->value.compcall.tbp; |
6368 | |
6369 | if (tbp->error) |
6370 | return false; |
6371 | |
6372 | po = extract_compcall_passed_object (e); |
6373 | if (!po) |
6374 | return false; |
6375 | |
6376 | if (tbp->nopass || e->value.compcall.ignore_pass) |
6377 | { |
6378 | gfc_free_expr (po); |
6379 | return true; |
6380 | } |
6381 | |
6382 | if (tbp->pass_arg_num <= 0) |
6383 | return false; |
6384 | |
6385 | e->value.compcall.actual = update_arglist_pass (e->value.compcall.actual, po, |
6386 | tbp->pass_arg_num, |
6387 | tbp->pass_arg); |
6388 | |
6389 | return true; |
6390 | } |
6391 | |
6392 | |
6393 | /* Extract the passed object from a PPC call (a copy of it). */ |
6394 | |
6395 | static gfc_expr* |
6396 | extract_ppc_passed_object (gfc_expr *e) |
6397 | { |
6398 | gfc_expr *po; |
6399 | gfc_ref **ref; |
6400 | |
6401 | po = gfc_get_expr (); |
6402 | po->expr_type = EXPR_VARIABLE; |
6403 | po->symtree = e->symtree; |
6404 | po->ref = gfc_copy_ref (e->ref); |
6405 | po->where = e->where; |
6406 | |
6407 | /* Remove PPC reference. */ |
6408 | ref = &po->ref; |
6409 | while ((*ref)->next) |
6410 | ref = &(*ref)->next; |
6411 | gfc_free_ref_list (*ref); |
6412 | *ref = NULL__null; |
6413 | |
6414 | if (!gfc_resolve_expr (po)) |
6415 | return NULL__null; |
6416 | |
6417 | return po; |
6418 | } |
6419 | |
6420 | |
6421 | /* Update the actual arglist of a procedure pointer component to include the |
6422 | passed-object. */ |
6423 | |
6424 | static bool |
6425 | update_ppc_arglist (gfc_expr* e) |
6426 | { |
6427 | gfc_expr* po; |
6428 | gfc_component *ppc; |
6429 | gfc_typebound_proc* tb; |
6430 | |
6431 | ppc = gfc_get_proc_ptr_comp (e); |
6432 | if (!ppc) |
6433 | return false; |
6434 | |
6435 | tb = ppc->tb; |
6436 | |
6437 | if (tb->error) |
6438 | return false; |
6439 | else if (tb->nopass) |
6440 | return true; |
6441 | |
6442 | po = extract_ppc_passed_object (e); |
6443 | if (!po) |
6444 | return false; |
6445 | |
6446 | /* F08:R739. */ |
6447 | if (po->rank != 0) |
6448 | { |
6449 | gfc_error ("Passed-object at %L must be scalar", &e->where); |
6450 | return false; |
6451 | } |
6452 | |
6453 | /* F08:C611. */ |
6454 | if (po->ts.type == BT_DERIVED && po->ts.u.derived->attr.abstract) |
6455 | { |
6456 | gfc_error ("Base object for procedure-pointer component call at %L is of" |
6457 | " ABSTRACT type %qs", &e->where, po->ts.u.derived->name); |
6458 | return false; |
6459 | } |
6460 | |
6461 | gcc_assert (tb->pass_arg_num > 0)((void)(!(tb->pass_arg_num > 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/fortran/resolve.cc" , 6461, __FUNCTION__), 0 : 0)); |
6462 | e->value.compcall.actual = update_arglist_pass (e->value.compcall.actual, po, |
6463 | tb->pass_arg_num, |
6464 | tb->pass_arg); |
6465 | |
6466 | return true; |
6467 | } |
6468 | |
6469 | |
6470 | /* Check that the object a TBP is called on is valid, i.e. it must not be |
6471 | of ABSTRACT type (as in subobject%abstract_parent%tbp()). */ |
6472 | |
6473 | static bool |
6474 | check_typebound_baseobject (gfc_expr* e) |
6475 | { |
6476 | gfc_expr* base; |
6477 | bool return_value = false; |
6478 | |
6479 | base = extract_compcall_passed_object (e); |
6480 |