]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/check.c
Update copyright years.
[thirdparty/gcc.git] / gcc / fortran / check.c
1 /* Check functions
2 Copyright (C) 2002-2017 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Katherine Holcomb
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21
22 /* These functions check to see if an argument list is compatible with
23 a particular intrinsic function or subroutine. Presence of
24 required arguments has already been established, the argument list
25 has been sorted into the right order and has NULL arguments in the
26 correct places for missing optional arguments. */
27
28 #include "config.h"
29 #include "system.h"
30 #include "coretypes.h"
31 #include "options.h"
32 #include "gfortran.h"
33 #include "intrinsic.h"
34 #include "constructor.h"
35 #include "target-memory.h"
36
37
38 /* Make sure an expression is a scalar. */
39
40 static bool
41 scalar_check (gfc_expr *e, int n)
42 {
43 if (e->rank == 0)
44 return true;
45
46 gfc_error ("%qs argument of %qs intrinsic at %L must be a scalar",
47 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
48 &e->where);
49
50 return false;
51 }
52
53
54 /* Check the type of an expression. */
55
56 static bool
57 type_check (gfc_expr *e, int n, bt type)
58 {
59 if (e->ts.type == type)
60 return true;
61
62 gfc_error ("%qs argument of %qs intrinsic at %L must be %s",
63 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
64 &e->where, gfc_basic_typename (type));
65
66 return false;
67 }
68
69
70 /* Check that the expression is a numeric type. */
71
72 static bool
73 numeric_check (gfc_expr *e, int n)
74 {
75 /* Users sometime use a subroutine designator as an actual argument to
76 an intrinsic subprogram that expects an argument with a numeric type. */
77 if (e->symtree && e->symtree->n.sym->attr.subroutine)
78 goto error;
79
80 if (gfc_numeric_ts (&e->ts))
81 return true;
82
83 /* If the expression has not got a type, check if its namespace can
84 offer a default type. */
85 if ((e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_FUNCTION)
86 && e->symtree->n.sym->ts.type == BT_UNKNOWN
87 && gfc_set_default_type (e->symtree->n.sym, 0, e->symtree->n.sym->ns)
88 && gfc_numeric_ts (&e->symtree->n.sym->ts))
89 {
90 e->ts = e->symtree->n.sym->ts;
91 return true;
92 }
93
94 error:
95
96 gfc_error ("%qs argument of %qs intrinsic at %L must have a numeric type",
97 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
98 &e->where);
99
100 return false;
101 }
102
103
104 /* Check that an expression is integer or real. */
105
106 static bool
107 int_or_real_check (gfc_expr *e, int n)
108 {
109 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
110 {
111 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
112 "or REAL", gfc_current_intrinsic_arg[n]->name,
113 gfc_current_intrinsic, &e->where);
114 return false;
115 }
116
117 return true;
118 }
119
120
121 /* Check that an expression is real or complex. */
122
123 static bool
124 real_or_complex_check (gfc_expr *e, int n)
125 {
126 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
127 {
128 gfc_error ("%qs argument of %qs intrinsic at %L must be REAL "
129 "or COMPLEX", gfc_current_intrinsic_arg[n]->name,
130 gfc_current_intrinsic, &e->where);
131 return false;
132 }
133
134 return true;
135 }
136
137
138 /* Check that an expression is INTEGER or PROCEDURE. */
139
140 static bool
141 int_or_proc_check (gfc_expr *e, int n)
142 {
143 if (e->ts.type != BT_INTEGER && e->ts.type != BT_PROCEDURE)
144 {
145 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
146 "or PROCEDURE", gfc_current_intrinsic_arg[n]->name,
147 gfc_current_intrinsic, &e->where);
148 return false;
149 }
150
151 return true;
152 }
153
154
155 /* Check that the expression is an optional constant integer
156 and that it specifies a valid kind for that type. */
157
158 static bool
159 kind_check (gfc_expr *k, int n, bt type)
160 {
161 int kind;
162
163 if (k == NULL)
164 return true;
165
166 if (!type_check (k, n, BT_INTEGER))
167 return false;
168
169 if (!scalar_check (k, n))
170 return false;
171
172 if (!gfc_check_init_expr (k))
173 {
174 gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
175 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
176 &k->where);
177 return false;
178 }
179
180 if (gfc_extract_int (k, &kind) != NULL
181 || gfc_validate_kind (type, kind, true) < 0)
182 {
183 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
184 &k->where);
185 return false;
186 }
187
188 return true;
189 }
190
191
192 /* Make sure the expression is a double precision real. */
193
194 static bool
195 double_check (gfc_expr *d, int n)
196 {
197 if (!type_check (d, n, BT_REAL))
198 return false;
199
200 if (d->ts.kind != gfc_default_double_kind)
201 {
202 gfc_error ("%qs argument of %qs intrinsic at %L must be double "
203 "precision", gfc_current_intrinsic_arg[n]->name,
204 gfc_current_intrinsic, &d->where);
205 return false;
206 }
207
208 return true;
209 }
210
211
212 static bool
213 coarray_check (gfc_expr *e, int n)
214 {
215 if (e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok
216 && CLASS_DATA (e)->attr.codimension
217 && CLASS_DATA (e)->as->corank)
218 {
219 gfc_add_class_array_ref (e);
220 return true;
221 }
222
223 if (!gfc_is_coarray (e))
224 {
225 gfc_error ("Expected coarray variable as %qs argument to the %s "
226 "intrinsic at %L", gfc_current_intrinsic_arg[n]->name,
227 gfc_current_intrinsic, &e->where);
228 return false;
229 }
230
231 return true;
232 }
233
234
235 /* Make sure the expression is a logical array. */
236
237 static bool
238 logical_array_check (gfc_expr *array, int n)
239 {
240 if (array->ts.type != BT_LOGICAL || array->rank == 0)
241 {
242 gfc_error ("%qs argument of %qs intrinsic at %L must be a logical "
243 "array", gfc_current_intrinsic_arg[n]->name,
244 gfc_current_intrinsic, &array->where);
245 return false;
246 }
247
248 return true;
249 }
250
251
252 /* Make sure an expression is an array. */
253
254 static bool
255 array_check (gfc_expr *e, int n)
256 {
257 if (e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok
258 && CLASS_DATA (e)->attr.dimension
259 && CLASS_DATA (e)->as->rank)
260 {
261 gfc_add_class_array_ref (e);
262 return true;
263 }
264
265 if (e->rank != 0 && e->ts.type != BT_PROCEDURE)
266 return true;
267
268 gfc_error ("%qs argument of %qs intrinsic at %L must be an array",
269 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
270 &e->where);
271
272 return false;
273 }
274
275
276 /* If expr is a constant, then check to ensure that it is greater than
277 of equal to zero. */
278
279 static bool
280 nonnegative_check (const char *arg, gfc_expr *expr)
281 {
282 int i;
283
284 if (expr->expr_type == EXPR_CONSTANT)
285 {
286 gfc_extract_int (expr, &i);
287 if (i < 0)
288 {
289 gfc_error ("%qs at %L must be nonnegative", arg, &expr->where);
290 return false;
291 }
292 }
293
294 return true;
295 }
296
297
298 /* If expr2 is constant, then check that the value is less than
299 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
300
301 static bool
302 less_than_bitsize1 (const char *arg1, gfc_expr *expr1, const char *arg2,
303 gfc_expr *expr2, bool or_equal)
304 {
305 int i2, i3;
306
307 if (expr2->expr_type == EXPR_CONSTANT)
308 {
309 gfc_extract_int (expr2, &i2);
310 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
311
312 /* For ISHFT[C], check that |shift| <= bit_size(i). */
313 if (arg2 == NULL)
314 {
315 if (i2 < 0)
316 i2 = -i2;
317
318 if (i2 > gfc_integer_kinds[i3].bit_size)
319 {
320 gfc_error ("The absolute value of SHIFT at %L must be less "
321 "than or equal to BIT_SIZE(%qs)",
322 &expr2->where, arg1);
323 return false;
324 }
325 }
326
327 if (or_equal)
328 {
329 if (i2 > gfc_integer_kinds[i3].bit_size)
330 {
331 gfc_error ("%qs at %L must be less than "
332 "or equal to BIT_SIZE(%qs)",
333 arg2, &expr2->where, arg1);
334 return false;
335 }
336 }
337 else
338 {
339 if (i2 >= gfc_integer_kinds[i3].bit_size)
340 {
341 gfc_error ("%qs at %L must be less than BIT_SIZE(%qs)",
342 arg2, &expr2->where, arg1);
343 return false;
344 }
345 }
346 }
347
348 return true;
349 }
350
351
352 /* If expr is constant, then check that the value is less than or equal
353 to the bit_size of the kind k. */
354
355 static bool
356 less_than_bitsizekind (const char *arg, gfc_expr *expr, int k)
357 {
358 int i, val;
359
360 if (expr->expr_type != EXPR_CONSTANT)
361 return true;
362
363 i = gfc_validate_kind (BT_INTEGER, k, false);
364 gfc_extract_int (expr, &val);
365
366 if (val > gfc_integer_kinds[i].bit_size)
367 {
368 gfc_error ("%qs at %L must be less than or equal to the BIT_SIZE of "
369 "INTEGER(KIND=%d)", arg, &expr->where, k);
370 return false;
371 }
372
373 return true;
374 }
375
376
377 /* If expr2 and expr3 are constants, then check that the value is less than
378 or equal to bit_size(expr1). */
379
380 static bool
381 less_than_bitsize2 (const char *arg1, gfc_expr *expr1, const char *arg2,
382 gfc_expr *expr2, const char *arg3, gfc_expr *expr3)
383 {
384 int i2, i3;
385
386 if (expr2->expr_type == EXPR_CONSTANT && expr3->expr_type == EXPR_CONSTANT)
387 {
388 gfc_extract_int (expr2, &i2);
389 gfc_extract_int (expr3, &i3);
390 i2 += i3;
391 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
392 if (i2 > gfc_integer_kinds[i3].bit_size)
393 {
394 gfc_error ("%<%s + %s%> at %L must be less than or equal "
395 "to BIT_SIZE(%qs)",
396 arg2, arg3, &expr2->where, arg1);
397 return false;
398 }
399 }
400
401 return true;
402 }
403
404 /* Make sure two expressions have the same type. */
405
406 static bool
407 same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
408 {
409 gfc_typespec *ets = &e->ts;
410 gfc_typespec *fts = &f->ts;
411
412 if (e->ts.type == BT_PROCEDURE && e->symtree->n.sym)
413 ets = &e->symtree->n.sym->ts;
414 if (f->ts.type == BT_PROCEDURE && f->symtree->n.sym)
415 fts = &f->symtree->n.sym->ts;
416
417 if (gfc_compare_types (ets, fts))
418 return true;
419
420 gfc_error ("%qs argument of %qs intrinsic at %L must be the same type "
421 "and kind as %qs", gfc_current_intrinsic_arg[m]->name,
422 gfc_current_intrinsic, &f->where,
423 gfc_current_intrinsic_arg[n]->name);
424
425 return false;
426 }
427
428
429 /* Make sure that an expression has a certain (nonzero) rank. */
430
431 static bool
432 rank_check (gfc_expr *e, int n, int rank)
433 {
434 if (e->rank == rank)
435 return true;
436
437 gfc_error ("%qs argument of %qs intrinsic at %L must be of rank %d",
438 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
439 &e->where, rank);
440
441 return false;
442 }
443
444
445 /* Make sure a variable expression is not an optional dummy argument. */
446
447 static bool
448 nonoptional_check (gfc_expr *e, int n)
449 {
450 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
451 {
452 gfc_error ("%qs argument of %qs intrinsic at %L must not be OPTIONAL",
453 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
454 &e->where);
455 }
456
457 /* TODO: Recursive check on nonoptional variables? */
458
459 return true;
460 }
461
462
463 /* Check for ALLOCATABLE attribute. */
464
465 static bool
466 allocatable_check (gfc_expr *e, int n)
467 {
468 symbol_attribute attr;
469
470 attr = gfc_variable_attr (e, NULL);
471 if (!attr.allocatable || attr.associate_var)
472 {
473 gfc_error ("%qs argument of %qs intrinsic at %L must be ALLOCATABLE",
474 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
475 &e->where);
476 return false;
477 }
478
479 return true;
480 }
481
482
483 /* Check that an expression has a particular kind. */
484
485 static bool
486 kind_value_check (gfc_expr *e, int n, int k)
487 {
488 if (e->ts.kind == k)
489 return true;
490
491 gfc_error ("%qs argument of %qs intrinsic at %L must be of kind %d",
492 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
493 &e->where, k);
494
495 return false;
496 }
497
498
499 /* Make sure an expression is a variable. */
500
501 static bool
502 variable_check (gfc_expr *e, int n, bool allow_proc)
503 {
504 if (e->expr_type == EXPR_VARIABLE
505 && e->symtree->n.sym->attr.intent == INTENT_IN
506 && (gfc_current_intrinsic_arg[n]->intent == INTENT_OUT
507 || gfc_current_intrinsic_arg[n]->intent == INTENT_INOUT))
508 {
509 gfc_ref *ref;
510 bool pointer = e->symtree->n.sym->ts.type == BT_CLASS
511 && CLASS_DATA (e->symtree->n.sym)
512 ? CLASS_DATA (e->symtree->n.sym)->attr.class_pointer
513 : e->symtree->n.sym->attr.pointer;
514
515 for (ref = e->ref; ref; ref = ref->next)
516 {
517 if (pointer && ref->type == REF_COMPONENT)
518 break;
519 if (ref->type == REF_COMPONENT
520 && ((ref->u.c.component->ts.type == BT_CLASS
521 && CLASS_DATA (ref->u.c.component)->attr.class_pointer)
522 || (ref->u.c.component->ts.type != BT_CLASS
523 && ref->u.c.component->attr.pointer)))
524 break;
525 }
526
527 if (!ref)
528 {
529 gfc_error ("%qs argument of %qs intrinsic at %L cannot be "
530 "INTENT(IN)", gfc_current_intrinsic_arg[n]->name,
531 gfc_current_intrinsic, &e->where);
532 return false;
533 }
534 }
535
536 if (e->expr_type == EXPR_VARIABLE
537 && e->symtree->n.sym->attr.flavor != FL_PARAMETER
538 && (allow_proc || !e->symtree->n.sym->attr.function))
539 return true;
540
541 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.function
542 && e->symtree->n.sym == e->symtree->n.sym->result)
543 {
544 gfc_namespace *ns;
545 for (ns = gfc_current_ns; ns; ns = ns->parent)
546 if (ns->proc_name == e->symtree->n.sym)
547 return true;
548 }
549
550 gfc_error ("%qs argument of %qs intrinsic at %L must be a variable",
551 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, &e->where);
552
553 return false;
554 }
555
556
557 /* Check the common DIM parameter for correctness. */
558
559 static bool
560 dim_check (gfc_expr *dim, int n, bool optional)
561 {
562 if (dim == NULL)
563 return true;
564
565 if (!type_check (dim, n, BT_INTEGER))
566 return false;
567
568 if (!scalar_check (dim, n))
569 return false;
570
571 if (!optional && !nonoptional_check (dim, n))
572 return false;
573
574 return true;
575 }
576
577
578 /* If a coarray DIM parameter is a constant, make sure that it is greater than
579 zero and less than or equal to the corank of the given array. */
580
581 static bool
582 dim_corank_check (gfc_expr *dim, gfc_expr *array)
583 {
584 int corank;
585
586 gcc_assert (array->expr_type == EXPR_VARIABLE);
587
588 if (dim->expr_type != EXPR_CONSTANT)
589 return true;
590
591 if (array->ts.type == BT_CLASS)
592 return true;
593
594 corank = gfc_get_corank (array);
595
596 if (mpz_cmp_ui (dim->value.integer, 1) < 0
597 || mpz_cmp_ui (dim->value.integer, corank) > 0)
598 {
599 gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
600 "codimension index", gfc_current_intrinsic, &dim->where);
601
602 return false;
603 }
604
605 return true;
606 }
607
608
609 /* If a DIM parameter is a constant, make sure that it is greater than
610 zero and less than or equal to the rank of the given array. If
611 allow_assumed is zero then dim must be less than the rank of the array
612 for assumed size arrays. */
613
614 static bool
615 dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
616 {
617 gfc_array_ref *ar;
618 int rank;
619
620 if (dim == NULL)
621 return true;
622
623 if (dim->expr_type != EXPR_CONSTANT)
624 return true;
625
626 if (array->expr_type == EXPR_FUNCTION && array->value.function.isym
627 && array->value.function.isym->id == GFC_ISYM_SPREAD)
628 rank = array->rank + 1;
629 else
630 rank = array->rank;
631
632 /* Assumed-rank array. */
633 if (rank == -1)
634 rank = GFC_MAX_DIMENSIONS;
635
636 if (array->expr_type == EXPR_VARIABLE)
637 {
638 ar = gfc_find_array_ref (array);
639 if (ar->as->type == AS_ASSUMED_SIZE
640 && !allow_assumed
641 && ar->type != AR_ELEMENT
642 && ar->type != AR_SECTION)
643 rank--;
644 }
645
646 if (mpz_cmp_ui (dim->value.integer, 1) < 0
647 || mpz_cmp_ui (dim->value.integer, rank) > 0)
648 {
649 gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
650 "dimension index", gfc_current_intrinsic, &dim->where);
651
652 return false;
653 }
654
655 return true;
656 }
657
658
659 /* Compare the size of a along dimension ai with the size of b along
660 dimension bi, returning 0 if they are known not to be identical,
661 and 1 if they are identical, or if this cannot be determined. */
662
663 static int
664 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
665 {
666 mpz_t a_size, b_size;
667 int ret;
668
669 gcc_assert (a->rank > ai);
670 gcc_assert (b->rank > bi);
671
672 ret = 1;
673
674 if (gfc_array_dimen_size (a, ai, &a_size))
675 {
676 if (gfc_array_dimen_size (b, bi, &b_size))
677 {
678 if (mpz_cmp (a_size, b_size) != 0)
679 ret = 0;
680
681 mpz_clear (b_size);
682 }
683 mpz_clear (a_size);
684 }
685 return ret;
686 }
687
688 /* Calculate the length of a character variable, including substrings.
689 Strip away parentheses if necessary. Return -1 if no length could
690 be determined. */
691
692 static long
693 gfc_var_strlen (const gfc_expr *a)
694 {
695 gfc_ref *ra;
696
697 while (a->expr_type == EXPR_OP && a->value.op.op == INTRINSIC_PARENTHESES)
698 a = a->value.op.op1;
699
700 for (ra = a->ref; ra != NULL && ra->type != REF_SUBSTRING; ra = ra->next)
701 ;
702
703 if (ra)
704 {
705 long start_a, end_a;
706
707 if (!ra->u.ss.end)
708 return -1;
709
710 if ((!ra->u.ss.start || ra->u.ss.start->expr_type == EXPR_CONSTANT)
711 && ra->u.ss.end->expr_type == EXPR_CONSTANT)
712 {
713 start_a = ra->u.ss.start ? mpz_get_si (ra->u.ss.start->value.integer)
714 : 1;
715 end_a = mpz_get_si (ra->u.ss.end->value.integer);
716 return (end_a < start_a) ? 0 : end_a - start_a + 1;
717 }
718 else if (ra->u.ss.start
719 && gfc_dep_compare_expr (ra->u.ss.start, ra->u.ss.end) == 0)
720 return 1;
721 else
722 return -1;
723 }
724
725 if (a->ts.u.cl && a->ts.u.cl->length
726 && a->ts.u.cl->length->expr_type == EXPR_CONSTANT)
727 return mpz_get_si (a->ts.u.cl->length->value.integer);
728 else if (a->expr_type == EXPR_CONSTANT
729 && (a->ts.u.cl == NULL || a->ts.u.cl->length == NULL))
730 return a->value.character.length;
731 else
732 return -1;
733
734 }
735
736 /* Check whether two character expressions have the same length;
737 returns true if they have or if the length cannot be determined,
738 otherwise return false and raise a gfc_error. */
739
740 bool
741 gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
742 {
743 long len_a, len_b;
744
745 len_a = gfc_var_strlen(a);
746 len_b = gfc_var_strlen(b);
747
748 if (len_a == -1 || len_b == -1 || len_a == len_b)
749 return true;
750 else
751 {
752 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
753 len_a, len_b, name, &a->where);
754 return false;
755 }
756 }
757
758
759 /***** Check functions *****/
760
761 /* Check subroutine suitable for intrinsics taking a real argument and
762 a kind argument for the result. */
763
764 static bool
765 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
766 {
767 if (!type_check (a, 0, BT_REAL))
768 return false;
769 if (!kind_check (kind, 1, type))
770 return false;
771
772 return true;
773 }
774
775
776 /* Check subroutine suitable for ceiling, floor and nint. */
777
778 bool
779 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
780 {
781 return check_a_kind (a, kind, BT_INTEGER);
782 }
783
784
785 /* Check subroutine suitable for aint, anint. */
786
787 bool
788 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
789 {
790 return check_a_kind (a, kind, BT_REAL);
791 }
792
793
794 bool
795 gfc_check_abs (gfc_expr *a)
796 {
797 if (!numeric_check (a, 0))
798 return false;
799
800 return true;
801 }
802
803
804 bool
805 gfc_check_achar (gfc_expr *a, gfc_expr *kind)
806 {
807 if (!type_check (a, 0, BT_INTEGER))
808 return false;
809 if (!kind_check (kind, 1, BT_CHARACTER))
810 return false;
811
812 return true;
813 }
814
815
816 bool
817 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
818 {
819 if (!type_check (name, 0, BT_CHARACTER)
820 || !scalar_check (name, 0))
821 return false;
822 if (!kind_value_check (name, 0, gfc_default_character_kind))
823 return false;
824
825 if (!type_check (mode, 1, BT_CHARACTER)
826 || !scalar_check (mode, 1))
827 return false;
828 if (!kind_value_check (mode, 1, gfc_default_character_kind))
829 return false;
830
831 return true;
832 }
833
834
835 bool
836 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
837 {
838 if (!logical_array_check (mask, 0))
839 return false;
840
841 if (!dim_check (dim, 1, false))
842 return false;
843
844 if (!dim_rank_check (dim, mask, 0))
845 return false;
846
847 return true;
848 }
849
850
851 bool
852 gfc_check_allocated (gfc_expr *array)
853 {
854 /* Tests on allocated components of coarrays need to detour the check to
855 argument of the _caf_get. */
856 if (flag_coarray == GFC_FCOARRAY_LIB && array->expr_type == EXPR_FUNCTION
857 && array->value.function.isym
858 && array->value.function.isym->id == GFC_ISYM_CAF_GET)
859 {
860 array = array->value.function.actual->expr;
861 if (!array->ref)
862 return false;
863 }
864
865 if (!variable_check (array, 0, false))
866 return false;
867 if (!allocatable_check (array, 0))
868 return false;
869
870 return true;
871 }
872
873
874 /* Common check function where the first argument must be real or
875 integer and the second argument must be the same as the first. */
876
877 bool
878 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
879 {
880 if (!int_or_real_check (a, 0))
881 return false;
882
883 if (a->ts.type != p->ts.type)
884 {
885 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
886 "have the same type", gfc_current_intrinsic_arg[0]->name,
887 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
888 &p->where);
889 return false;
890 }
891
892 if (a->ts.kind != p->ts.kind)
893 {
894 if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
895 &p->where))
896 return false;
897 }
898
899 return true;
900 }
901
902
903 bool
904 gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
905 {
906 if (!double_check (x, 0) || !double_check (y, 1))
907 return false;
908
909 return true;
910 }
911
912
913 bool
914 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
915 {
916 symbol_attribute attr1, attr2;
917 int i;
918 bool t;
919 locus *where;
920
921 where = &pointer->where;
922
923 if (pointer->expr_type == EXPR_NULL)
924 goto null_arg;
925
926 attr1 = gfc_expr_attr (pointer);
927
928 if (!attr1.pointer && !attr1.proc_pointer)
929 {
930 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER",
931 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
932 &pointer->where);
933 return false;
934 }
935
936 /* F2008, C1242. */
937 if (attr1.pointer && gfc_is_coindexed (pointer))
938 {
939 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
940 "coindexed", gfc_current_intrinsic_arg[0]->name,
941 gfc_current_intrinsic, &pointer->where);
942 return false;
943 }
944
945 /* Target argument is optional. */
946 if (target == NULL)
947 return true;
948
949 where = &target->where;
950 if (target->expr_type == EXPR_NULL)
951 goto null_arg;
952
953 if (target->expr_type == EXPR_VARIABLE || target->expr_type == EXPR_FUNCTION)
954 attr2 = gfc_expr_attr (target);
955 else
956 {
957 gfc_error ("%qs argument of %qs intrinsic at %L must be a pointer "
958 "or target VARIABLE or FUNCTION",
959 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
960 &target->where);
961 return false;
962 }
963
964 if (attr1.pointer && !attr2.pointer && !attr2.target)
965 {
966 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER "
967 "or a TARGET", gfc_current_intrinsic_arg[1]->name,
968 gfc_current_intrinsic, &target->where);
969 return false;
970 }
971
972 /* F2008, C1242. */
973 if (attr1.pointer && gfc_is_coindexed (target))
974 {
975 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
976 "coindexed", gfc_current_intrinsic_arg[1]->name,
977 gfc_current_intrinsic, &target->where);
978 return false;
979 }
980
981 t = true;
982 if (!same_type_check (pointer, 0, target, 1))
983 t = false;
984 if (!rank_check (target, 0, pointer->rank))
985 t = false;
986 if (target->rank > 0)
987 {
988 for (i = 0; i < target->rank; i++)
989 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
990 {
991 gfc_error ("Array section with a vector subscript at %L shall not "
992 "be the target of a pointer",
993 &target->where);
994 t = false;
995 break;
996 }
997 }
998 return t;
999
1000 null_arg:
1001
1002 gfc_error ("NULL pointer at %L is not permitted as actual argument "
1003 "of %qs intrinsic function", where, gfc_current_intrinsic);
1004 return false;
1005
1006 }
1007
1008
1009 bool
1010 gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
1011 {
1012 /* gfc_notify_std would be a waste of time as the return value
1013 is seemingly used only for the generic resolution. The error
1014 will be: Too many arguments. */
1015 if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
1016 return false;
1017
1018 return gfc_check_atan2 (y, x);
1019 }
1020
1021
1022 bool
1023 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
1024 {
1025 if (!type_check (y, 0, BT_REAL))
1026 return false;
1027 if (!same_type_check (y, 0, x, 1))
1028 return false;
1029
1030 return true;
1031 }
1032
1033
1034 static bool
1035 gfc_check_atomic (gfc_expr *atom, int atom_no, gfc_expr *value, int val_no,
1036 gfc_expr *stat, int stat_no)
1037 {
1038 if (!scalar_check (atom, atom_no) || !scalar_check (value, val_no))
1039 return false;
1040
1041 if (!(atom->ts.type == BT_INTEGER && atom->ts.kind == gfc_atomic_int_kind)
1042 && !(atom->ts.type == BT_LOGICAL
1043 && atom->ts.kind == gfc_atomic_logical_kind))
1044 {
1045 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1046 "integer of ATOMIC_INT_KIND or a logical of "
1047 "ATOMIC_LOGICAL_KIND", &atom->where, gfc_current_intrinsic);
1048 return false;
1049 }
1050
1051 if (!gfc_is_coarray (atom) && !gfc_is_coindexed (atom))
1052 {
1053 gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
1054 "coarray or coindexed", &atom->where, gfc_current_intrinsic);
1055 return false;
1056 }
1057
1058 if (atom->ts.type != value->ts.type)
1059 {
1060 gfc_error ("%qs argument of %qs intrinsic at %L shall have the same "
1061 "type as %qs at %L", gfc_current_intrinsic_arg[val_no]->name,
1062 gfc_current_intrinsic, &value->where,
1063 gfc_current_intrinsic_arg[atom_no]->name, &atom->where);
1064 return false;
1065 }
1066
1067 if (stat != NULL)
1068 {
1069 if (!type_check (stat, stat_no, BT_INTEGER))
1070 return false;
1071 if (!scalar_check (stat, stat_no))
1072 return false;
1073 if (!variable_check (stat, stat_no, false))
1074 return false;
1075 if (!kind_value_check (stat, stat_no, gfc_default_integer_kind))
1076 return false;
1077
1078 if (!gfc_notify_std (GFC_STD_F2008_TS, "STAT= argument to %s at %L",
1079 gfc_current_intrinsic, &stat->where))
1080 return false;
1081 }
1082
1083 return true;
1084 }
1085
1086
1087 bool
1088 gfc_check_atomic_def (gfc_expr *atom, gfc_expr *value, gfc_expr *stat)
1089 {
1090 if (atom->expr_type == EXPR_FUNCTION
1091 && atom->value.function.isym
1092 && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1093 atom = atom->value.function.actual->expr;
1094
1095 if (!gfc_check_vardef_context (atom, false, false, false, NULL))
1096 {
1097 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1098 "definable", gfc_current_intrinsic, &atom->where);
1099 return false;
1100 }
1101
1102 return gfc_check_atomic (atom, 0, value, 1, stat, 2);
1103 }
1104
1105
1106 bool
1107 gfc_check_atomic_op (gfc_expr *atom, gfc_expr *value, gfc_expr *stat)
1108 {
1109 if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind)
1110 {
1111 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1112 "integer of ATOMIC_INT_KIND", &atom->where,
1113 gfc_current_intrinsic);
1114 return false;
1115 }
1116
1117 return gfc_check_atomic_def (atom, value, stat);
1118 }
1119
1120
1121 bool
1122 gfc_check_atomic_ref (gfc_expr *value, gfc_expr *atom, gfc_expr *stat)
1123 {
1124 if (atom->expr_type == EXPR_FUNCTION
1125 && atom->value.function.isym
1126 && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1127 atom = atom->value.function.actual->expr;
1128
1129 if (!gfc_check_vardef_context (value, false, false, false, NULL))
1130 {
1131 gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1132 "definable", gfc_current_intrinsic, &value->where);
1133 return false;
1134 }
1135
1136 return gfc_check_atomic (atom, 1, value, 0, stat, 2);
1137 }
1138
1139
1140 bool
1141 gfc_check_atomic_cas (gfc_expr *atom, gfc_expr *old, gfc_expr *compare,
1142 gfc_expr *new_val, gfc_expr *stat)
1143 {
1144 if (atom->expr_type == EXPR_FUNCTION
1145 && atom->value.function.isym
1146 && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1147 atom = atom->value.function.actual->expr;
1148
1149 if (!gfc_check_atomic (atom, 0, new_val, 3, stat, 4))
1150 return false;
1151
1152 if (!scalar_check (old, 1) || !scalar_check (compare, 2))
1153 return false;
1154
1155 if (!same_type_check (atom, 0, old, 1))
1156 return false;
1157
1158 if (!same_type_check (atom, 0, compare, 2))
1159 return false;
1160
1161 if (!gfc_check_vardef_context (atom, false, false, false, NULL))
1162 {
1163 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1164 "definable", gfc_current_intrinsic, &atom->where);
1165 return false;
1166 }
1167
1168 if (!gfc_check_vardef_context (old, false, false, false, NULL))
1169 {
1170 gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1171 "definable", gfc_current_intrinsic, &old->where);
1172 return false;
1173 }
1174
1175 return true;
1176 }
1177
1178 bool
1179 gfc_check_event_query (gfc_expr *event, gfc_expr *count, gfc_expr *stat)
1180 {
1181 if (event->ts.type != BT_DERIVED
1182 || event->ts.u.derived->from_intmod != INTMOD_ISO_FORTRAN_ENV
1183 || event->ts.u.derived->intmod_sym_id != ISOFORTRAN_EVENT_TYPE)
1184 {
1185 gfc_error ("EVENT argument at %L to the intrinsic EVENT_QUERY "
1186 "shall be of type EVENT_TYPE", &event->where);
1187 return false;
1188 }
1189
1190 if (!scalar_check (event, 0))
1191 return false;
1192
1193 if (!gfc_check_vardef_context (count, false, false, false, NULL))
1194 {
1195 gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1196 "shall be definable", &count->where);
1197 return false;
1198 }
1199
1200 if (!type_check (count, 1, BT_INTEGER))
1201 return false;
1202
1203 int i = gfc_validate_kind (BT_INTEGER, count->ts.kind, false);
1204 int j = gfc_validate_kind (BT_INTEGER, gfc_default_integer_kind, false);
1205
1206 if (gfc_integer_kinds[i].range < gfc_integer_kinds[j].range)
1207 {
1208 gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1209 "shall have at least the range of the default integer",
1210 &count->where);
1211 return false;
1212 }
1213
1214 if (stat != NULL)
1215 {
1216 if (!type_check (stat, 2, BT_INTEGER))
1217 return false;
1218 if (!scalar_check (stat, 2))
1219 return false;
1220 if (!variable_check (stat, 2, false))
1221 return false;
1222
1223 if (!gfc_notify_std (GFC_STD_F2008_TS, "STAT= argument to %s at %L",
1224 gfc_current_intrinsic, &stat->where))
1225 return false;
1226 }
1227
1228 return true;
1229 }
1230
1231
1232 bool
1233 gfc_check_atomic_fetch_op (gfc_expr *atom, gfc_expr *value, gfc_expr *old,
1234 gfc_expr *stat)
1235 {
1236 if (atom->expr_type == EXPR_FUNCTION
1237 && atom->value.function.isym
1238 && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1239 atom = atom->value.function.actual->expr;
1240
1241 if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind)
1242 {
1243 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1244 "integer of ATOMIC_INT_KIND", &atom->where,
1245 gfc_current_intrinsic);
1246 return false;
1247 }
1248
1249 if (!gfc_check_atomic (atom, 0, value, 1, stat, 3))
1250 return false;
1251
1252 if (!scalar_check (old, 2))
1253 return false;
1254
1255 if (!same_type_check (atom, 0, old, 2))
1256 return false;
1257
1258 if (!gfc_check_vardef_context (atom, false, false, false, NULL))
1259 {
1260 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1261 "definable", gfc_current_intrinsic, &atom->where);
1262 return false;
1263 }
1264
1265 if (!gfc_check_vardef_context (old, false, false, false, NULL))
1266 {
1267 gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1268 "definable", gfc_current_intrinsic, &old->where);
1269 return false;
1270 }
1271
1272 return true;
1273 }
1274
1275
1276 /* BESJN and BESYN functions. */
1277
1278 bool
1279 gfc_check_besn (gfc_expr *n, gfc_expr *x)
1280 {
1281 if (!type_check (n, 0, BT_INTEGER))
1282 return false;
1283 if (n->expr_type == EXPR_CONSTANT)
1284 {
1285 int i;
1286 gfc_extract_int (n, &i);
1287 if (i < 0 && !gfc_notify_std (GFC_STD_GNU, "Negative argument "
1288 "N at %L", &n->where))
1289 return false;
1290 }
1291
1292 if (!type_check (x, 1, BT_REAL))
1293 return false;
1294
1295 return true;
1296 }
1297
1298
1299 /* Transformational version of the Bessel JN and YN functions. */
1300
1301 bool
1302 gfc_check_bessel_n2 (gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
1303 {
1304 if (!type_check (n1, 0, BT_INTEGER))
1305 return false;
1306 if (!scalar_check (n1, 0))
1307 return false;
1308 if (!nonnegative_check ("N1", n1))
1309 return false;
1310
1311 if (!type_check (n2, 1, BT_INTEGER))
1312 return false;
1313 if (!scalar_check (n2, 1))
1314 return false;
1315 if (!nonnegative_check ("N2", n2))
1316 return false;
1317
1318 if (!type_check (x, 2, BT_REAL))
1319 return false;
1320 if (!scalar_check (x, 2))
1321 return false;
1322
1323 return true;
1324 }
1325
1326
1327 bool
1328 gfc_check_bge_bgt_ble_blt (gfc_expr *i, gfc_expr *j)
1329 {
1330 if (!type_check (i, 0, BT_INTEGER))
1331 return false;
1332
1333 if (!type_check (j, 1, BT_INTEGER))
1334 return false;
1335
1336 return true;
1337 }
1338
1339
1340 bool
1341 gfc_check_bitfcn (gfc_expr *i, gfc_expr *pos)
1342 {
1343 if (!type_check (i, 0, BT_INTEGER))
1344 return false;
1345
1346 if (!type_check (pos, 1, BT_INTEGER))
1347 return false;
1348
1349 if (!nonnegative_check ("pos", pos))
1350 return false;
1351
1352 if (!less_than_bitsize1 ("i", i, "pos", pos, false))
1353 return false;
1354
1355 return true;
1356 }
1357
1358
1359 bool
1360 gfc_check_char (gfc_expr *i, gfc_expr *kind)
1361 {
1362 if (!type_check (i, 0, BT_INTEGER))
1363 return false;
1364 if (!kind_check (kind, 1, BT_CHARACTER))
1365 return false;
1366
1367 return true;
1368 }
1369
1370
1371 bool
1372 gfc_check_chdir (gfc_expr *dir)
1373 {
1374 if (!type_check (dir, 0, BT_CHARACTER))
1375 return false;
1376 if (!kind_value_check (dir, 0, gfc_default_character_kind))
1377 return false;
1378
1379 return true;
1380 }
1381
1382
1383 bool
1384 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
1385 {
1386 if (!type_check (dir, 0, BT_CHARACTER))
1387 return false;
1388 if (!kind_value_check (dir, 0, gfc_default_character_kind))
1389 return false;
1390
1391 if (status == NULL)
1392 return true;
1393
1394 if (!type_check (status, 1, BT_INTEGER))
1395 return false;
1396 if (!scalar_check (status, 1))
1397 return false;
1398
1399 return true;
1400 }
1401
1402
1403 bool
1404 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
1405 {
1406 if (!type_check (name, 0, BT_CHARACTER))
1407 return false;
1408 if (!kind_value_check (name, 0, gfc_default_character_kind))
1409 return false;
1410
1411 if (!type_check (mode, 1, BT_CHARACTER))
1412 return false;
1413 if (!kind_value_check (mode, 1, gfc_default_character_kind))
1414 return false;
1415
1416 return true;
1417 }
1418
1419
1420 bool
1421 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
1422 {
1423 if (!type_check (name, 0, BT_CHARACTER))
1424 return false;
1425 if (!kind_value_check (name, 0, gfc_default_character_kind))
1426 return false;
1427
1428 if (!type_check (mode, 1, BT_CHARACTER))
1429 return false;
1430 if (!kind_value_check (mode, 1, gfc_default_character_kind))
1431 return false;
1432
1433 if (status == NULL)
1434 return true;
1435
1436 if (!type_check (status, 2, BT_INTEGER))
1437 return false;
1438
1439 if (!scalar_check (status, 2))
1440 return false;
1441
1442 return true;
1443 }
1444
1445
1446 bool
1447 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
1448 {
1449 if (!numeric_check (x, 0))
1450 return false;
1451
1452 if (y != NULL)
1453 {
1454 if (!numeric_check (y, 1))
1455 return false;
1456
1457 if (x->ts.type == BT_COMPLEX)
1458 {
1459 gfc_error ("%qs argument of %qs intrinsic at %L must not be "
1460 "present if %<x%> is COMPLEX",
1461 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1462 &y->where);
1463 return false;
1464 }
1465
1466 if (y->ts.type == BT_COMPLEX)
1467 {
1468 gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
1469 "of either REAL or INTEGER",
1470 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1471 &y->where);
1472 return false;
1473 }
1474
1475 }
1476
1477 if (!kind_check (kind, 2, BT_COMPLEX))
1478 return false;
1479
1480 if (!kind && warn_conversion
1481 && x->ts.type == BT_REAL && x->ts.kind > gfc_default_real_kind)
1482 gfc_warning_now (OPT_Wconversion, "Conversion from %s to default-kind "
1483 "COMPLEX(%d) at %L might lose precision, consider using "
1484 "the KIND argument", gfc_typename (&x->ts),
1485 gfc_default_real_kind, &x->where);
1486 else if (y && !kind && warn_conversion
1487 && y->ts.type == BT_REAL && y->ts.kind > gfc_default_real_kind)
1488 gfc_warning_now (OPT_Wconversion, "Conversion from %s to default-kind "
1489 "COMPLEX(%d) at %L might lose precision, consider using "
1490 "the KIND argument", gfc_typename (&y->ts),
1491 gfc_default_real_kind, &y->where);
1492 return true;
1493 }
1494
1495
1496 static bool
1497 check_co_collective (gfc_expr *a, gfc_expr *image_idx, gfc_expr *stat,
1498 gfc_expr *errmsg, bool co_reduce)
1499 {
1500 if (!variable_check (a, 0, false))
1501 return false;
1502
1503 if (!gfc_check_vardef_context (a, false, false, false, "argument 'A' with "
1504 "INTENT(INOUT)"))
1505 return false;
1506
1507 /* Fortran 2008, 12.5.2.4, paragraph 18. */
1508 if (gfc_has_vector_subscript (a))
1509 {
1510 gfc_error ("Argument %<A%> with INTENT(INOUT) at %L of the intrinsic "
1511 "subroutine %s shall not have a vector subscript",
1512 &a->where, gfc_current_intrinsic);
1513 return false;
1514 }
1515
1516 if (gfc_is_coindexed (a))
1517 {
1518 gfc_error ("The A argument at %L to the intrinsic %s shall not be "
1519 "coindexed", &a->where, gfc_current_intrinsic);
1520 return false;
1521 }
1522
1523 if (image_idx != NULL)
1524 {
1525 if (!type_check (image_idx, co_reduce ? 2 : 1, BT_INTEGER))
1526 return false;
1527 if (!scalar_check (image_idx, co_reduce ? 2 : 1))
1528 return false;
1529 }
1530
1531 if (stat != NULL)
1532 {
1533 if (!type_check (stat, co_reduce ? 3 : 2, BT_INTEGER))
1534 return false;
1535 if (!scalar_check (stat, co_reduce ? 3 : 2))
1536 return false;
1537 if (!variable_check (stat, co_reduce ? 3 : 2, false))
1538 return false;
1539 if (stat->ts.kind != 4)
1540 {
1541 gfc_error ("The stat= argument at %L must be a kind=4 integer "
1542 "variable", &stat->where);
1543 return false;
1544 }
1545 }
1546
1547 if (errmsg != NULL)
1548 {
1549 if (!type_check (errmsg, co_reduce ? 4 : 3, BT_CHARACTER))
1550 return false;
1551 if (!scalar_check (errmsg, co_reduce ? 4 : 3))
1552 return false;
1553 if (!variable_check (errmsg, co_reduce ? 4 : 3, false))
1554 return false;
1555 if (errmsg->ts.kind != 1)
1556 {
1557 gfc_error ("The errmsg= argument at %L must be a default-kind "
1558 "character variable", &errmsg->where);
1559 return false;
1560 }
1561 }
1562
1563 if (flag_coarray == GFC_FCOARRAY_NONE)
1564 {
1565 gfc_fatal_error ("Coarrays disabled at %L, use %<-fcoarray=%> to enable",
1566 &a->where);
1567 return false;
1568 }
1569
1570 return true;
1571 }
1572
1573
1574 bool
1575 gfc_check_co_broadcast (gfc_expr *a, gfc_expr *source_image, gfc_expr *stat,
1576 gfc_expr *errmsg)
1577 {
1578 if (a->ts.type == BT_CLASS || gfc_expr_attr (a).alloc_comp)
1579 {
1580 gfc_error ("Support for the A argument at %L which is polymorphic A "
1581 "argument or has allocatable components is not yet "
1582 "implemented", &a->where);
1583 return false;
1584 }
1585 return check_co_collective (a, source_image, stat, errmsg, false);
1586 }
1587
1588
1589 bool
1590 gfc_check_co_reduce (gfc_expr *a, gfc_expr *op, gfc_expr *result_image,
1591 gfc_expr *stat, gfc_expr *errmsg)
1592 {
1593 symbol_attribute attr;
1594 gfc_formal_arglist *formal;
1595 gfc_symbol *sym;
1596
1597 if (a->ts.type == BT_CLASS)
1598 {
1599 gfc_error ("The A argument at %L of CO_REDUCE shall not be polymorphic",
1600 &a->where);
1601 return false;
1602 }
1603
1604 if (gfc_expr_attr (a).alloc_comp)
1605 {
1606 gfc_error ("Support for the A argument at %L with allocatable components"
1607 " is not yet implemented", &a->where);
1608 return false;
1609 }
1610
1611 if (!check_co_collective (a, result_image, stat, errmsg, true))
1612 return false;
1613
1614 if (!gfc_resolve_expr (op))
1615 return false;
1616
1617 attr = gfc_expr_attr (op);
1618 if (!attr.pure || !attr.function)
1619 {
1620 gfc_error ("OPERATOR argument at %L must be a PURE function",
1621 &op->where);
1622 return false;
1623 }
1624
1625 if (attr.intrinsic)
1626 {
1627 /* None of the intrinsics fulfills the criteria of taking two arguments,
1628 returning the same type and kind as the arguments and being permitted
1629 as actual argument. */
1630 gfc_error ("Intrinsic function %s at %L is not permitted for CO_REDUCE",
1631 op->symtree->n.sym->name, &op->where);
1632 return false;
1633 }
1634
1635 if (gfc_is_proc_ptr_comp (op))
1636 {
1637 gfc_component *comp = gfc_get_proc_ptr_comp (op);
1638 sym = comp->ts.interface;
1639 }
1640 else
1641 sym = op->symtree->n.sym;
1642
1643 formal = sym->formal;
1644
1645 if (!formal || !formal->next || formal->next->next)
1646 {
1647 gfc_error ("The function passed as OPERATOR at %L shall have two "
1648 "arguments", &op->where);
1649 return false;
1650 }
1651
1652 if (sym->result->ts.type == BT_UNKNOWN)
1653 gfc_set_default_type (sym->result, 0, NULL);
1654
1655 if (!gfc_compare_types (&a->ts, &sym->result->ts))
1656 {
1657 gfc_error ("A argument at %L has type %s but the function passed as "
1658 "OPERATOR at %L returns %s",
1659 &a->where, gfc_typename (&a->ts), &op->where,
1660 gfc_typename (&sym->result->ts));
1661 return false;
1662 }
1663 if (!gfc_compare_types (&a->ts, &formal->sym->ts)
1664 || !gfc_compare_types (&a->ts, &formal->next->sym->ts))
1665 {
1666 gfc_error ("The function passed as OPERATOR at %L has arguments of type "
1667 "%s and %s but shall have type %s", &op->where,
1668 gfc_typename (&formal->sym->ts),
1669 gfc_typename (&formal->next->sym->ts), gfc_typename (&a->ts));
1670 return false;
1671 }
1672 if (op->rank || attr.allocatable || attr.pointer || formal->sym->as
1673 || formal->next->sym->as || formal->sym->attr.allocatable
1674 || formal->next->sym->attr.allocatable || formal->sym->attr.pointer
1675 || formal->next->sym->attr.pointer)
1676 {
1677 gfc_error ("The function passed as OPERATOR at %L shall have scalar "
1678 "nonallocatable nonpointer arguments and return a "
1679 "nonallocatable nonpointer scalar", &op->where);
1680 return false;
1681 }
1682
1683 if (formal->sym->attr.value != formal->next->sym->attr.value)
1684 {
1685 gfc_error ("The function passed as OPERATOR at %L shall have the VALUE "
1686 "attribute either for none or both arguments", &op->where);
1687 return false;
1688 }
1689
1690 if (formal->sym->attr.target != formal->next->sym->attr.target)
1691 {
1692 gfc_error ("The function passed as OPERATOR at %L shall have the TARGET "
1693 "attribute either for none or both arguments", &op->where);
1694 return false;
1695 }
1696
1697 if (formal->sym->attr.asynchronous != formal->next->sym->attr.asynchronous)
1698 {
1699 gfc_error ("The function passed as OPERATOR at %L shall have the "
1700 "ASYNCHRONOUS attribute either for none or both arguments",
1701 &op->where);
1702 return false;
1703 }
1704
1705 if (formal->sym->attr.optional || formal->next->sym->attr.optional)
1706 {
1707 gfc_error ("The function passed as OPERATOR at %L shall not have the "
1708 "OPTIONAL attribute for either of the arguments", &op->where);
1709 return false;
1710 }
1711
1712 if (a->ts.type == BT_CHARACTER)
1713 {
1714 gfc_charlen *cl;
1715 unsigned long actual_size, formal_size1, formal_size2, result_size;
1716
1717 cl = a->ts.u.cl;
1718 actual_size = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
1719 ? mpz_get_ui (cl->length->value.integer) : 0;
1720
1721 cl = formal->sym->ts.u.cl;
1722 formal_size1 = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
1723 ? mpz_get_ui (cl->length->value.integer) : 0;
1724
1725 cl = formal->next->sym->ts.u.cl;
1726 formal_size2 = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
1727 ? mpz_get_ui (cl->length->value.integer) : 0;
1728
1729 cl = sym->ts.u.cl;
1730 result_size = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
1731 ? mpz_get_ui (cl->length->value.integer) : 0;
1732
1733 if (actual_size
1734 && ((formal_size1 && actual_size != formal_size1)
1735 || (formal_size2 && actual_size != formal_size2)))
1736 {
1737 gfc_error ("The character length of the A argument at %L and of the "
1738 "arguments of the OPERATOR at %L shall be the same",
1739 &a->where, &op->where);
1740 return false;
1741 }
1742 if (actual_size && result_size && actual_size != result_size)
1743 {
1744 gfc_error ("The character length of the A argument at %L and of the "
1745 "function result of the OPERATOR at %L shall be the same",
1746 &a->where, &op->where);
1747 return false;
1748 }
1749 }
1750
1751 return true;
1752 }
1753
1754
1755 bool
1756 gfc_check_co_minmax (gfc_expr *a, gfc_expr *result_image, gfc_expr *stat,
1757 gfc_expr *errmsg)
1758 {
1759 if (a->ts.type != BT_INTEGER && a->ts.type != BT_REAL
1760 && a->ts.type != BT_CHARACTER)
1761 {
1762 gfc_error ("%qs argument of %qs intrinsic at %L shall be of type "
1763 "integer, real or character",
1764 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
1765 &a->where);
1766 return false;
1767 }
1768 return check_co_collective (a, result_image, stat, errmsg, false);
1769 }
1770
1771
1772 bool
1773 gfc_check_co_sum (gfc_expr *a, gfc_expr *result_image, gfc_expr *stat,
1774 gfc_expr *errmsg)
1775 {
1776 if (!numeric_check (a, 0))
1777 return false;
1778 return check_co_collective (a, result_image, stat, errmsg, false);
1779 }
1780
1781
1782 bool
1783 gfc_check_complex (gfc_expr *x, gfc_expr *y)
1784 {
1785 if (!int_or_real_check (x, 0))
1786 return false;
1787 if (!scalar_check (x, 0))
1788 return false;
1789
1790 if (!int_or_real_check (y, 1))
1791 return false;
1792 if (!scalar_check (y, 1))
1793 return false;
1794
1795 return true;
1796 }
1797
1798
1799 bool
1800 gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
1801 {
1802 if (!logical_array_check (mask, 0))
1803 return false;
1804 if (!dim_check (dim, 1, false))
1805 return false;
1806 if (!dim_rank_check (dim, mask, 0))
1807 return false;
1808 if (!kind_check (kind, 2, BT_INTEGER))
1809 return false;
1810 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
1811 "with KIND argument at %L",
1812 gfc_current_intrinsic, &kind->where))
1813 return false;
1814
1815 return true;
1816 }
1817
1818
1819 bool
1820 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
1821 {
1822 if (!array_check (array, 0))
1823 return false;
1824
1825 if (!type_check (shift, 1, BT_INTEGER))
1826 return false;
1827
1828 if (!dim_check (dim, 2, true))
1829 return false;
1830
1831 if (!dim_rank_check (dim, array, false))
1832 return false;
1833
1834 if (array->rank == 1 || shift->rank == 0)
1835 {
1836 if (!scalar_check (shift, 1))
1837 return false;
1838 }
1839 else if (shift->rank == array->rank - 1)
1840 {
1841 int d;
1842 if (!dim)
1843 d = 1;
1844 else if (dim->expr_type == EXPR_CONSTANT)
1845 gfc_extract_int (dim, &d);
1846 else
1847 d = -1;
1848
1849 if (d > 0)
1850 {
1851 int i, j;
1852 for (i = 0, j = 0; i < array->rank; i++)
1853 if (i != d - 1)
1854 {
1855 if (!identical_dimen_shape (array, i, shift, j))
1856 {
1857 gfc_error ("%qs argument of %qs intrinsic at %L has "
1858 "invalid shape in dimension %d (%ld/%ld)",
1859 gfc_current_intrinsic_arg[1]->name,
1860 gfc_current_intrinsic, &shift->where, i + 1,
1861 mpz_get_si (array->shape[i]),
1862 mpz_get_si (shift->shape[j]));
1863 return false;
1864 }
1865
1866 j += 1;
1867 }
1868 }
1869 }
1870 else
1871 {
1872 gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
1873 "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
1874 gfc_current_intrinsic, &shift->where, array->rank - 1);
1875 return false;
1876 }
1877
1878 return true;
1879 }
1880
1881
1882 bool
1883 gfc_check_ctime (gfc_expr *time)
1884 {
1885 if (!scalar_check (time, 0))
1886 return false;
1887
1888 if (!type_check (time, 0, BT_INTEGER))
1889 return false;
1890
1891 return true;
1892 }
1893
1894
1895 bool gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
1896 {
1897 if (!double_check (y, 0) || !double_check (x, 1))
1898 return false;
1899
1900 return true;
1901 }
1902
1903 bool
1904 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
1905 {
1906 if (!numeric_check (x, 0))
1907 return false;
1908
1909 if (y != NULL)
1910 {
1911 if (!numeric_check (y, 1))
1912 return false;
1913
1914 if (x->ts.type == BT_COMPLEX)
1915 {
1916 gfc_error ("%qs argument of %qs intrinsic at %L must not be "
1917 "present if %<x%> is COMPLEX",
1918 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1919 &y->where);
1920 return false;
1921 }
1922
1923 if (y->ts.type == BT_COMPLEX)
1924 {
1925 gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
1926 "of either REAL or INTEGER",
1927 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1928 &y->where);
1929 return false;
1930 }
1931 }
1932
1933 return true;
1934 }
1935
1936
1937 bool
1938 gfc_check_dble (gfc_expr *x)
1939 {
1940 if (!numeric_check (x, 0))
1941 return false;
1942
1943 return true;
1944 }
1945
1946
1947 bool
1948 gfc_check_digits (gfc_expr *x)
1949 {
1950 if (!int_or_real_check (x, 0))
1951 return false;
1952
1953 return true;
1954 }
1955
1956
1957 bool
1958 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
1959 {
1960 switch (vector_a->ts.type)
1961 {
1962 case BT_LOGICAL:
1963 if (!type_check (vector_b, 1, BT_LOGICAL))
1964 return false;
1965 break;
1966
1967 case BT_INTEGER:
1968 case BT_REAL:
1969 case BT_COMPLEX:
1970 if (!numeric_check (vector_b, 1))
1971 return false;
1972 break;
1973
1974 default:
1975 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
1976 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
1977 gfc_current_intrinsic, &vector_a->where);
1978 return false;
1979 }
1980
1981 if (!rank_check (vector_a, 0, 1))
1982 return false;
1983
1984 if (!rank_check (vector_b, 1, 1))
1985 return false;
1986
1987 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
1988 {
1989 gfc_error ("Different shape for arguments %qs and %qs at %L for "
1990 "intrinsic %<dot_product%>",
1991 gfc_current_intrinsic_arg[0]->name,
1992 gfc_current_intrinsic_arg[1]->name, &vector_a->where);
1993 return false;
1994 }
1995
1996 return true;
1997 }
1998
1999
2000 bool
2001 gfc_check_dprod (gfc_expr *x, gfc_expr *y)
2002 {
2003 if (!type_check (x, 0, BT_REAL)
2004 || !type_check (y, 1, BT_REAL))
2005 return false;
2006
2007 if (x->ts.kind != gfc_default_real_kind)
2008 {
2009 gfc_error ("%qs argument of %qs intrinsic at %L must be default "
2010 "real", gfc_current_intrinsic_arg[0]->name,
2011 gfc_current_intrinsic, &x->where);
2012 return false;
2013 }
2014
2015 if (y->ts.kind != gfc_default_real_kind)
2016 {
2017 gfc_error ("%qs argument of %qs intrinsic at %L must be default "
2018 "real", gfc_current_intrinsic_arg[1]->name,
2019 gfc_current_intrinsic, &y->where);
2020 return false;
2021 }
2022
2023 return true;
2024 }
2025
2026
2027 bool
2028 gfc_check_dshift (gfc_expr *i, gfc_expr *j, gfc_expr *shift)
2029 {
2030 if (!type_check (i, 0, BT_INTEGER))
2031 return false;
2032
2033 if (!type_check (j, 1, BT_INTEGER))
2034 return false;
2035
2036 if (i->is_boz && j->is_boz)
2037 {
2038 gfc_error ("%<I%> at %L and %<J%>' at %L cannot both be BOZ literal "
2039 "constants", &i->where, &j->where);
2040 return false;
2041 }
2042
2043 if (!i->is_boz && !j->is_boz && !same_type_check (i, 0, j, 1))
2044 return false;
2045
2046 if (!type_check (shift, 2, BT_INTEGER))
2047 return false;
2048
2049 if (!nonnegative_check ("SHIFT", shift))
2050 return false;
2051
2052 if (i->is_boz)
2053 {
2054 if (!less_than_bitsize1 ("J", j, "SHIFT", shift, true))
2055 return false;
2056 i->ts.kind = j->ts.kind;
2057 }
2058 else
2059 {
2060 if (!less_than_bitsize1 ("I", i, "SHIFT", shift, true))
2061 return false;
2062 j->ts.kind = i->ts.kind;
2063 }
2064
2065 return true;
2066 }
2067
2068
2069 bool
2070 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
2071 gfc_expr *dim)
2072 {
2073 if (!array_check (array, 0))
2074 return false;
2075
2076 if (!type_check (shift, 1, BT_INTEGER))
2077 return false;
2078
2079 if (!dim_check (dim, 3, true))
2080 return false;
2081
2082 if (!dim_rank_check (dim, array, false))
2083 return false;
2084
2085 if (array->rank == 1 || shift->rank == 0)
2086 {
2087 if (!scalar_check (shift, 1))
2088 return false;
2089 }
2090 else if (shift->rank == array->rank - 1)
2091 {
2092 int d;
2093 if (!dim)
2094 d = 1;
2095 else if (dim->expr_type == EXPR_CONSTANT)
2096 gfc_extract_int (dim, &d);
2097 else
2098 d = -1;
2099
2100 if (d > 0)
2101 {
2102 int i, j;
2103 for (i = 0, j = 0; i < array->rank; i++)
2104 if (i != d - 1)
2105 {
2106 if (!identical_dimen_shape (array, i, shift, j))
2107 {
2108 gfc_error ("%qs argument of %qs intrinsic at %L has "
2109 "invalid shape in dimension %d (%ld/%ld)",
2110 gfc_current_intrinsic_arg[1]->name,
2111 gfc_current_intrinsic, &shift->where, i + 1,
2112 mpz_get_si (array->shape[i]),
2113 mpz_get_si (shift->shape[j]));
2114 return false;
2115 }
2116
2117 j += 1;
2118 }
2119 }
2120 }
2121 else
2122 {
2123 gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
2124 "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
2125 gfc_current_intrinsic, &shift->where, array->rank - 1);
2126 return false;
2127 }
2128
2129 if (boundary != NULL)
2130 {
2131 if (!same_type_check (array, 0, boundary, 2))
2132 return false;
2133
2134 if (array->rank == 1 || boundary->rank == 0)
2135 {
2136 if (!scalar_check (boundary, 2))
2137 return false;
2138 }
2139 else if (boundary->rank == array->rank - 1)
2140 {
2141 if (!gfc_check_conformance (shift, boundary,
2142 "arguments '%s' and '%s' for "
2143 "intrinsic %s",
2144 gfc_current_intrinsic_arg[1]->name,
2145 gfc_current_intrinsic_arg[2]->name,
2146 gfc_current_intrinsic))
2147 return false;
2148 }
2149 else
2150 {
2151 gfc_error ("%qs argument of intrinsic %qs at %L of must have "
2152 "rank %d or be a scalar",
2153 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2154 &shift->where, array->rank - 1);
2155 return false;
2156 }
2157 }
2158
2159 return true;
2160 }
2161
2162 bool
2163 gfc_check_float (gfc_expr *a)
2164 {
2165 if (!type_check (a, 0, BT_INTEGER))
2166 return false;
2167
2168 if ((a->ts.kind != gfc_default_integer_kind)
2169 && !gfc_notify_std (GFC_STD_GNU, "non-default INTEGER "
2170 "kind argument to %s intrinsic at %L",
2171 gfc_current_intrinsic, &a->where))
2172 return false;
2173
2174 return true;
2175 }
2176
2177 /* A single complex argument. */
2178
2179 bool
2180 gfc_check_fn_c (gfc_expr *a)
2181 {
2182 if (!type_check (a, 0, BT_COMPLEX))
2183 return false;
2184
2185 return true;
2186 }
2187
2188 /* A single real argument. */
2189
2190 bool
2191 gfc_check_fn_r (gfc_expr *a)
2192 {
2193 if (!type_check (a, 0, BT_REAL))
2194 return false;
2195
2196 return true;
2197 }
2198
2199 /* A single double argument. */
2200
2201 bool
2202 gfc_check_fn_d (gfc_expr *a)
2203 {
2204 if (!double_check (a, 0))
2205 return false;
2206
2207 return true;
2208 }
2209
2210 /* A single real or complex argument. */
2211
2212 bool
2213 gfc_check_fn_rc (gfc_expr *a)
2214 {
2215 if (!real_or_complex_check (a, 0))
2216 return false;
2217
2218 return true;
2219 }
2220
2221
2222 bool
2223 gfc_check_fn_rc2008 (gfc_expr *a)
2224 {
2225 if (!real_or_complex_check (a, 0))
2226 return false;
2227
2228 if (a->ts.type == BT_COMPLEX
2229 && !gfc_notify_std (GFC_STD_F2008, "COMPLEX argument %qs "
2230 "of %qs intrinsic at %L",
2231 gfc_current_intrinsic_arg[0]->name,
2232 gfc_current_intrinsic, &a->where))
2233 return false;
2234
2235 return true;
2236 }
2237
2238
2239 bool
2240 gfc_check_fnum (gfc_expr *unit)
2241 {
2242 if (!type_check (unit, 0, BT_INTEGER))
2243 return false;
2244
2245 if (!scalar_check (unit, 0))
2246 return false;
2247
2248 return true;
2249 }
2250
2251
2252 bool
2253 gfc_check_huge (gfc_expr *x)
2254 {
2255 if (!int_or_real_check (x, 0))
2256 return false;
2257
2258 return true;
2259 }
2260
2261
2262 bool
2263 gfc_check_hypot (gfc_expr *x, gfc_expr *y)
2264 {
2265 if (!type_check (x, 0, BT_REAL))
2266 return false;
2267 if (!same_type_check (x, 0, y, 1))
2268 return false;
2269
2270 return true;
2271 }
2272
2273
2274 /* Check that the single argument is an integer. */
2275
2276 bool
2277 gfc_check_i (gfc_expr *i)
2278 {
2279 if (!type_check (i, 0, BT_INTEGER))
2280 return false;
2281
2282 return true;
2283 }
2284
2285
2286 bool
2287 gfc_check_iand (gfc_expr *i, gfc_expr *j)
2288 {
2289 if (!type_check (i, 0, BT_INTEGER))
2290 return false;
2291
2292 if (!type_check (j, 1, BT_INTEGER))
2293 return false;
2294
2295 if (i->ts.kind != j->ts.kind)
2296 {
2297 if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
2298 &i->where))
2299 return false;
2300 }
2301
2302 return true;
2303 }
2304
2305
2306 bool
2307 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
2308 {
2309 if (!type_check (i, 0, BT_INTEGER))
2310 return false;
2311
2312 if (!type_check (pos, 1, BT_INTEGER))
2313 return false;
2314
2315 if (!type_check (len, 2, BT_INTEGER))
2316 return false;
2317
2318 if (!nonnegative_check ("pos", pos))
2319 return false;
2320
2321 if (!nonnegative_check ("len", len))
2322 return false;
2323
2324 if (!less_than_bitsize2 ("i", i, "pos", pos, "len", len))
2325 return false;
2326
2327 return true;
2328 }
2329
2330
2331 bool
2332 gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
2333 {
2334 int i;
2335
2336 if (!type_check (c, 0, BT_CHARACTER))
2337 return false;
2338
2339 if (!kind_check (kind, 1, BT_INTEGER))
2340 return false;
2341
2342 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
2343 "with KIND argument at %L",
2344 gfc_current_intrinsic, &kind->where))
2345 return false;
2346
2347 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
2348 {
2349 gfc_expr *start;
2350 gfc_expr *end;
2351 gfc_ref *ref;
2352
2353 /* Substring references don't have the charlength set. */
2354 ref = c->ref;
2355 while (ref && ref->type != REF_SUBSTRING)
2356 ref = ref->next;
2357
2358 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
2359
2360 if (!ref)
2361 {
2362 /* Check that the argument is length one. Non-constant lengths
2363 can't be checked here, so assume they are ok. */
2364 if (c->ts.u.cl && c->ts.u.cl->length)
2365 {
2366 /* If we already have a length for this expression then use it. */
2367 if (c->ts.u.cl->length->expr_type != EXPR_CONSTANT)
2368 return true;
2369 i = mpz_get_si (c->ts.u.cl->length->value.integer);
2370 }
2371 else
2372 return true;
2373 }
2374 else
2375 {
2376 start = ref->u.ss.start;
2377 end = ref->u.ss.end;
2378
2379 gcc_assert (start);
2380 if (end == NULL || end->expr_type != EXPR_CONSTANT
2381 || start->expr_type != EXPR_CONSTANT)
2382 return true;
2383
2384 i = mpz_get_si (end->value.integer) + 1
2385 - mpz_get_si (start->value.integer);
2386 }
2387 }
2388 else
2389 return true;
2390
2391 if (i != 1)
2392 {
2393 gfc_error ("Argument of %s at %L must be of length one",
2394 gfc_current_intrinsic, &c->where);
2395 return false;
2396 }
2397
2398 return true;
2399 }
2400
2401
2402 bool
2403 gfc_check_idnint (gfc_expr *a)
2404 {
2405 if (!double_check (a, 0))
2406 return false;
2407
2408 return true;
2409 }
2410
2411
2412 bool
2413 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
2414 {
2415 if (!type_check (i, 0, BT_INTEGER))
2416 return false;
2417
2418 if (!type_check (j, 1, BT_INTEGER))
2419 return false;
2420
2421 if (i->ts.kind != j->ts.kind)
2422 {
2423 if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
2424 &i->where))
2425 return false;
2426 }
2427
2428 return true;
2429 }
2430
2431
2432 bool
2433 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back,
2434 gfc_expr *kind)
2435 {
2436 if (!type_check (string, 0, BT_CHARACTER)
2437 || !type_check (substring, 1, BT_CHARACTER))
2438 return false;
2439
2440 if (back != NULL && !type_check (back, 2, BT_LOGICAL))
2441 return false;
2442
2443 if (!kind_check (kind, 3, BT_INTEGER))
2444 return false;
2445 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
2446 "with KIND argument at %L",
2447 gfc_current_intrinsic, &kind->where))
2448 return false;
2449
2450 if (string->ts.kind != substring->ts.kind)
2451 {
2452 gfc_error ("%qs argument of %qs intrinsic at %L must be the same "
2453 "kind as %qs", gfc_current_intrinsic_arg[1]->name,
2454 gfc_current_intrinsic, &substring->where,
2455 gfc_current_intrinsic_arg[0]->name);
2456 return false;
2457 }
2458
2459 return true;
2460 }
2461
2462
2463 bool
2464 gfc_check_int (gfc_expr *x, gfc_expr *kind)
2465 {
2466 if (!numeric_check (x, 0))
2467 return false;
2468
2469 if (!kind_check (kind, 1, BT_INTEGER))
2470 return false;
2471
2472 return true;
2473 }
2474
2475
2476 bool
2477 gfc_check_intconv (gfc_expr *x)
2478 {
2479 if (!numeric_check (x, 0))
2480 return false;
2481
2482 return true;
2483 }
2484
2485
2486 bool
2487 gfc_check_ior (gfc_expr *i, gfc_expr *j)
2488 {
2489 if (!type_check (i, 0, BT_INTEGER))
2490 return false;
2491
2492 if (!type_check (j, 1, BT_INTEGER))
2493 return false;
2494
2495 if (i->ts.kind != j->ts.kind)
2496 {
2497 if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
2498 &i->where))
2499 return false;
2500 }
2501
2502 return true;
2503 }
2504
2505
2506 bool
2507 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
2508 {
2509 if (!type_check (i, 0, BT_INTEGER)
2510 || !type_check (shift, 1, BT_INTEGER))
2511 return false;
2512
2513 if (!less_than_bitsize1 ("I", i, NULL, shift, true))
2514 return false;
2515
2516 return true;
2517 }
2518
2519
2520 bool
2521 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
2522 {
2523 if (!type_check (i, 0, BT_INTEGER)
2524 || !type_check (shift, 1, BT_INTEGER))
2525 return false;
2526
2527 if (size != NULL)
2528 {
2529 int i2, i3;
2530
2531 if (!type_check (size, 2, BT_INTEGER))
2532 return false;
2533
2534 if (!less_than_bitsize1 ("I", i, "SIZE", size, true))
2535 return false;
2536
2537 if (size->expr_type == EXPR_CONSTANT)
2538 {
2539 gfc_extract_int (size, &i3);
2540 if (i3 <= 0)
2541 {
2542 gfc_error ("SIZE at %L must be positive", &size->where);
2543 return false;
2544 }
2545
2546 if (shift->expr_type == EXPR_CONSTANT)
2547 {
2548 gfc_extract_int (shift, &i2);
2549 if (i2 < 0)
2550 i2 = -i2;
2551
2552 if (i2 > i3)
2553 {
2554 gfc_error ("The absolute value of SHIFT at %L must be less "
2555 "than or equal to SIZE at %L", &shift->where,
2556 &size->where);
2557 return false;
2558 }
2559 }
2560 }
2561 }
2562 else if (!less_than_bitsize1 ("I", i, NULL, shift, true))
2563 return false;
2564
2565 return true;
2566 }
2567
2568
2569 bool
2570 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
2571 {
2572 if (!type_check (pid, 0, BT_INTEGER))
2573 return false;
2574
2575 if (!type_check (sig, 1, BT_INTEGER))
2576 return false;
2577
2578 return true;
2579 }
2580
2581
2582 bool
2583 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
2584 {
2585 if (!type_check (pid, 0, BT_INTEGER))
2586 return false;
2587
2588 if (!scalar_check (pid, 0))
2589 return false;
2590
2591 if (!type_check (sig, 1, BT_INTEGER))
2592 return false;
2593
2594 if (!scalar_check (sig, 1))
2595 return false;
2596
2597 if (status == NULL)
2598 return true;
2599
2600 if (!type_check (status, 2, BT_INTEGER))
2601 return false;
2602
2603 if (!scalar_check (status, 2))
2604 return false;
2605
2606 return true;
2607 }
2608
2609
2610 bool
2611 gfc_check_kind (gfc_expr *x)
2612 {
2613 if (gfc_bt_struct (x->ts.type) || x->ts.type == BT_CLASS)
2614 {
2615 gfc_error ("%qs argument of %qs intrinsic at %L must be of "
2616 "intrinsic type", gfc_current_intrinsic_arg[0]->name,
2617 gfc_current_intrinsic, &x->where);
2618 return false;
2619 }
2620 if (x->ts.type == BT_PROCEDURE)
2621 {
2622 gfc_error ("%qs argument of %qs intrinsic at %L must be a data entity",
2623 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2624 &x->where);
2625 return false;
2626 }
2627
2628 return true;
2629 }
2630
2631
2632 bool
2633 gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2634 {
2635 if (!array_check (array, 0))
2636 return false;
2637
2638 if (!dim_check (dim, 1, false))
2639 return false;
2640
2641 if (!dim_rank_check (dim, array, 1))
2642 return false;
2643
2644 if (!kind_check (kind, 2, BT_INTEGER))
2645 return false;
2646 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
2647 "with KIND argument at %L",
2648 gfc_current_intrinsic, &kind->where))
2649 return false;
2650
2651 return true;
2652 }
2653
2654
2655 bool
2656 gfc_check_lcobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
2657 {
2658 if (flag_coarray == GFC_FCOARRAY_NONE)
2659 {
2660 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
2661 return false;
2662 }
2663
2664 if (!coarray_check (coarray, 0))
2665 return false;
2666
2667 if (dim != NULL)
2668 {
2669 if (!dim_check (dim, 1, false))
2670 return false;
2671
2672 if (!dim_corank_check (dim, coarray))
2673 return false;
2674 }
2675
2676 if (!kind_check (kind, 2, BT_INTEGER))
2677 return false;
2678
2679 return true;
2680 }
2681
2682
2683 bool
2684 gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
2685 {
2686 if (!type_check (s, 0, BT_CHARACTER))
2687 return false;
2688
2689 if (!kind_check (kind, 1, BT_INTEGER))
2690 return false;
2691 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
2692 "with KIND argument at %L",
2693 gfc_current_intrinsic, &kind->where))
2694 return false;
2695
2696 return true;
2697 }
2698
2699
2700 bool
2701 gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
2702 {
2703 if (!type_check (a, 0, BT_CHARACTER))
2704 return false;
2705 if (!kind_value_check (a, 0, gfc_default_character_kind))
2706 return false;
2707
2708 if (!type_check (b, 1, BT_CHARACTER))
2709 return false;
2710 if (!kind_value_check (b, 1, gfc_default_character_kind))
2711 return false;
2712
2713 return true;
2714 }
2715
2716
2717 bool
2718 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
2719 {
2720 if (!type_check (path1, 0, BT_CHARACTER))
2721 return false;
2722 if (!kind_value_check (path1, 0, gfc_default_character_kind))
2723 return false;
2724
2725 if (!type_check (path2, 1, BT_CHARACTER))
2726 return false;
2727 if (!kind_value_check (path2, 1, gfc_default_character_kind))
2728 return false;
2729
2730 return true;
2731 }
2732
2733
2734 bool
2735 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2736 {
2737 if (!type_check (path1, 0, BT_CHARACTER))
2738 return false;
2739 if (!kind_value_check (path1, 0, gfc_default_character_kind))
2740 return false;
2741
2742 if (!type_check (path2, 1, BT_CHARACTER))
2743 return false;
2744 if (!kind_value_check (path2, 0, gfc_default_character_kind))
2745 return false;
2746
2747 if (status == NULL)
2748 return true;
2749
2750 if (!type_check (status, 2, BT_INTEGER))
2751 return false;
2752
2753 if (!scalar_check (status, 2))
2754 return false;
2755
2756 return true;
2757 }
2758
2759
2760 bool
2761 gfc_check_loc (gfc_expr *expr)
2762 {
2763 return variable_check (expr, 0, true);
2764 }
2765
2766
2767 bool
2768 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
2769 {
2770 if (!type_check (path1, 0, BT_CHARACTER))
2771 return false;
2772 if (!kind_value_check (path1, 0, gfc_default_character_kind))
2773 return false;
2774
2775 if (!type_check (path2, 1, BT_CHARACTER))
2776 return false;
2777 if (!kind_value_check (path2, 1, gfc_default_character_kind))
2778 return false;
2779
2780 return true;
2781 }
2782
2783
2784 bool
2785 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2786 {
2787 if (!type_check (path1, 0, BT_CHARACTER))
2788 return false;
2789 if (!kind_value_check (path1, 0, gfc_default_character_kind))
2790 return false;
2791
2792 if (!type_check (path2, 1, BT_CHARACTER))
2793 return false;
2794 if (!kind_value_check (path2, 1, gfc_default_character_kind))
2795 return false;
2796
2797 if (status == NULL)
2798 return true;
2799
2800 if (!type_check (status, 2, BT_INTEGER))
2801 return false;
2802
2803 if (!scalar_check (status, 2))
2804 return false;
2805
2806 return true;
2807 }
2808
2809
2810 bool
2811 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
2812 {
2813 if (!type_check (a, 0, BT_LOGICAL))
2814 return false;
2815 if (!kind_check (kind, 1, BT_LOGICAL))
2816 return false;
2817
2818 return true;
2819 }
2820
2821
2822 /* Min/max family. */
2823
2824 static bool
2825 min_max_args (gfc_actual_arglist *args)
2826 {
2827 gfc_actual_arglist *arg;
2828 int i, j, nargs, *nlabels, nlabelless;
2829 bool a1 = false, a2 = false;
2830
2831 if (args == NULL || args->next == NULL)
2832 {
2833 gfc_error ("Intrinsic %qs at %L must have at least two arguments",
2834 gfc_current_intrinsic, gfc_current_intrinsic_where);
2835 return false;
2836 }
2837
2838 if (!args->name)
2839 a1 = true;
2840
2841 if (!args->next->name)
2842 a2 = true;
2843
2844 nargs = 0;
2845 for (arg = args; arg; arg = arg->next)
2846 if (arg->name)
2847 nargs++;
2848
2849 if (nargs == 0)
2850 return true;
2851
2852 /* Note: Having a keywordless argument after an "arg=" is checked before. */
2853 nlabelless = 0;
2854 nlabels = XALLOCAVEC (int, nargs);
2855 for (arg = args, i = 0; arg; arg = arg->next, i++)
2856 if (arg->name)
2857 {
2858 int n;
2859 char *endp;
2860
2861 if (arg->name[0] != 'a' || arg->name[1] < '1' || arg->name[1] > '9')
2862 goto unknown;
2863 n = strtol (&arg->name[1], &endp, 10);
2864 if (endp[0] != '\0')
2865 goto unknown;
2866 if (n <= 0)
2867 goto unknown;
2868 if (n <= nlabelless)
2869 goto duplicate;
2870 nlabels[i] = n;
2871 if (n == 1)
2872 a1 = true;
2873 if (n == 2)
2874 a2 = true;
2875 }
2876 else
2877 nlabelless++;
2878
2879 if (!a1 || !a2)
2880 {
2881 gfc_error ("Missing %qs argument to the %s intrinsic at %L",
2882 !a1 ? "a1" : "a2", gfc_current_intrinsic,
2883 gfc_current_intrinsic_where);
2884 return false;
2885 }
2886
2887 /* Check for duplicates. */
2888 for (i = 0; i < nargs; i++)
2889 for (j = i + 1; j < nargs; j++)
2890 if (nlabels[i] == nlabels[j])
2891 goto duplicate;
2892
2893 return true;
2894
2895 duplicate:
2896 gfc_error ("Duplicate argument %qs at %L to intrinsic %s", arg->name,
2897 &arg->expr->where, gfc_current_intrinsic);
2898 return false;
2899
2900 unknown:
2901 gfc_error ("Unknown argument %qs at %L to intrinsic %s", arg->name,
2902 &arg->expr->where, gfc_current_intrinsic);
2903 return false;
2904 }
2905
2906
2907 static bool
2908 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
2909 {
2910 gfc_actual_arglist *arg, *tmp;
2911 gfc_expr *x;
2912 int m, n;
2913
2914 if (!min_max_args (arglist))
2915 return false;
2916
2917 for (arg = arglist, n=1; arg; arg = arg->next, n++)
2918 {
2919 x = arg->expr;
2920 if (x->ts.type != type || x->ts.kind != kind)
2921 {
2922 if (x->ts.type == type)
2923 {
2924 if (!gfc_notify_std (GFC_STD_GNU, "Different type "
2925 "kinds at %L", &x->where))
2926 return false;
2927 }
2928 else
2929 {
2930 gfc_error ("%<a%d%> argument of %qs intrinsic at %L must be "
2931 "%s(%d)", n, gfc_current_intrinsic, &x->where,
2932 gfc_basic_typename (type), kind);
2933 return false;
2934 }
2935 }
2936
2937 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
2938 if (!gfc_check_conformance (tmp->expr, x,
2939 "arguments 'a%d' and 'a%d' for "
2940 "intrinsic '%s'", m, n,
2941 gfc_current_intrinsic))
2942 return false;
2943 }
2944
2945 return true;
2946 }
2947
2948
2949 bool
2950 gfc_check_min_max (gfc_actual_arglist *arg)
2951 {
2952 gfc_expr *x;
2953
2954 if (!min_max_args (arg))
2955 return false;
2956
2957 x = arg->expr;
2958
2959 if (x->ts.type == BT_CHARACTER)
2960 {
2961 if (!gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
2962 "with CHARACTER argument at %L",
2963 gfc_current_intrinsic, &x->where))
2964 return false;
2965 }
2966 else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
2967 {
2968 gfc_error ("%<a1%> argument of %qs intrinsic at %L must be INTEGER, "
2969 "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
2970 return false;
2971 }
2972
2973 return check_rest (x->ts.type, x->ts.kind, arg);
2974 }
2975
2976
2977 bool
2978 gfc_check_min_max_integer (gfc_actual_arglist *arg)
2979 {
2980 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
2981 }
2982
2983
2984 bool
2985 gfc_check_min_max_real (gfc_actual_arglist *arg)
2986 {
2987 return check_rest (BT_REAL, gfc_default_real_kind, arg);
2988 }
2989
2990
2991 bool
2992 gfc_check_min_max_double (gfc_actual_arglist *arg)
2993 {
2994 return check_rest (BT_REAL, gfc_default_double_kind, arg);
2995 }
2996
2997
2998 /* End of min/max family. */
2999
3000 bool
3001 gfc_check_malloc (gfc_expr *size)
3002 {
3003 if (!type_check (size, 0, BT_INTEGER))
3004 return false;
3005
3006 if (!scalar_check (size, 0))
3007 return false;
3008
3009 return true;
3010 }
3011
3012
3013 bool
3014 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
3015 {
3016 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
3017 {
3018 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3019 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
3020 gfc_current_intrinsic, &matrix_a->where);
3021 return false;
3022 }
3023
3024 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
3025 {
3026 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3027 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
3028 gfc_current_intrinsic, &matrix_b->where);
3029 return false;
3030 }
3031
3032 if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
3033 || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
3034 {
3035 gfc_error ("Argument types of %qs intrinsic at %L must match (%s/%s)",
3036 gfc_current_intrinsic, &matrix_a->where,
3037 gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
3038 return false;
3039 }
3040
3041 switch (matrix_a->rank)
3042 {
3043 case 1:
3044 if (!rank_check (matrix_b, 1, 2))
3045 return false;
3046 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
3047 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
3048 {
3049 gfc_error ("Different shape on dimension 1 for arguments %qs "
3050 "and %qs at %L for intrinsic matmul",
3051 gfc_current_intrinsic_arg[0]->name,
3052 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
3053 return false;
3054 }
3055 break;
3056
3057 case 2:
3058 if (matrix_b->rank != 2)
3059 {
3060 if (!rank_check (matrix_b, 1, 1))
3061 return false;
3062 }
3063 /* matrix_b has rank 1 or 2 here. Common check for the cases
3064 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
3065 - matrix_a has shape (n,m) and matrix_b has shape (m). */
3066 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
3067 {
3068 gfc_error ("Different shape on dimension 2 for argument %qs and "
3069 "dimension 1 for argument %qs at %L for intrinsic "
3070 "matmul", gfc_current_intrinsic_arg[0]->name,
3071 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
3072 return false;
3073 }
3074 break;
3075
3076 default:
3077 gfc_error ("%qs argument of %qs intrinsic at %L must be of rank "
3078 "1 or 2", gfc_current_intrinsic_arg[0]->name,
3079 gfc_current_intrinsic, &matrix_a->where);
3080 return false;
3081 }
3082
3083 return true;
3084 }
3085
3086
3087 /* Whoever came up with this interface was probably on something.
3088 The possibilities for the occupation of the second and third
3089 parameters are:
3090
3091 Arg #2 Arg #3
3092 NULL NULL
3093 DIM NULL
3094 MASK NULL
3095 NULL MASK minloc(array, mask=m)
3096 DIM MASK
3097
3098 I.e. in the case of minloc(array,mask), mask will be in the second
3099 position of the argument list and we'll have to fix that up. */
3100
3101 bool
3102 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
3103 {
3104 gfc_expr *a, *m, *d;
3105
3106 a = ap->expr;
3107 if (!int_or_real_check (a, 0) || !array_check (a, 0))
3108 return false;
3109
3110 d = ap->next->expr;
3111 m = ap->next->next->expr;
3112
3113 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
3114 && ap->next->name == NULL)
3115 {
3116 m = d;
3117 d = NULL;
3118 ap->next->expr = NULL;
3119 ap->next->next->expr = m;
3120 }
3121
3122 if (!dim_check (d, 1, false))
3123 return false;
3124
3125 if (!dim_rank_check (d, a, 0))
3126 return false;
3127
3128 if (m != NULL && !type_check (m, 2, BT_LOGICAL))
3129 return false;
3130
3131 if (m != NULL
3132 && !gfc_check_conformance (a, m,
3133 "arguments '%s' and '%s' for intrinsic %s",
3134 gfc_current_intrinsic_arg[0]->name,
3135 gfc_current_intrinsic_arg[2]->name,
3136 gfc_current_intrinsic))
3137 return false;
3138
3139 return true;
3140 }
3141
3142
3143 /* Similar to minloc/maxloc, the argument list might need to be
3144 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
3145 difference is that MINLOC/MAXLOC take an additional KIND argument.
3146 The possibilities are:
3147
3148 Arg #2 Arg #3
3149 NULL NULL
3150 DIM NULL
3151 MASK NULL
3152 NULL MASK minval(array, mask=m)
3153 DIM MASK
3154
3155 I.e. in the case of minval(array,mask), mask will be in the second
3156 position of the argument list and we'll have to fix that up. */
3157
3158 static bool
3159 check_reduction (gfc_actual_arglist *ap)
3160 {
3161 gfc_expr *a, *m, *d;
3162
3163 a = ap->expr;
3164 d = ap->next->expr;
3165 m = ap->next->next->expr;
3166
3167 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
3168 && ap->next->name == NULL)
3169 {
3170 m = d;
3171 d = NULL;
3172 ap->next->expr = NULL;
3173 ap->next->next->expr = m;
3174 }
3175
3176 if (!dim_check (d, 1, false))
3177 return false;
3178
3179 if (!dim_rank_check (d, a, 0))
3180 return false;
3181
3182 if (m != NULL && !type_check (m, 2, BT_LOGICAL))
3183 return false;
3184
3185 if (m != NULL
3186 && !gfc_check_conformance (a, m,
3187 "arguments '%s' and '%s' for intrinsic %s",
3188 gfc_current_intrinsic_arg[0]->name,
3189 gfc_current_intrinsic_arg[2]->name,
3190 gfc_current_intrinsic))
3191 return false;
3192
3193 return true;
3194 }
3195
3196
3197 bool
3198 gfc_check_minval_maxval (gfc_actual_arglist *ap)
3199 {
3200 if (!int_or_real_check (ap->expr, 0)
3201 || !array_check (ap->expr, 0))
3202 return false;
3203
3204 return check_reduction (ap);
3205 }
3206
3207
3208 bool
3209 gfc_check_product_sum (gfc_actual_arglist *ap)
3210 {
3211 if (!numeric_check (ap->expr, 0)
3212 || !array_check (ap->expr, 0))
3213 return false;
3214
3215 return check_reduction (ap);
3216 }
3217
3218
3219 /* For IANY, IALL and IPARITY. */
3220
3221 bool
3222 gfc_check_mask (gfc_expr *i, gfc_expr *kind)
3223 {
3224 int k;
3225
3226 if (!type_check (i, 0, BT_INTEGER))
3227 return false;
3228
3229 if (!nonnegative_check ("I", i))
3230 return false;
3231
3232 if (!kind_check (kind, 1, BT_INTEGER))
3233 return false;
3234
3235 if (kind)
3236 gfc_extract_int (kind, &k);
3237 else
3238 k = gfc_default_integer_kind;
3239
3240 if (!less_than_bitsizekind ("I", i, k))
3241 return false;
3242
3243 return true;
3244 }
3245
3246
3247 bool
3248 gfc_check_transf_bit_intrins (gfc_actual_arglist *ap)
3249 {
3250 if (ap->expr->ts.type != BT_INTEGER)
3251 {
3252 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER",
3253 gfc_current_intrinsic_arg[0]->name,
3254 gfc_current_intrinsic, &ap->expr->where);
3255 return false;
3256 }
3257
3258 if (!array_check (ap->expr, 0))
3259 return false;
3260
3261 return check_reduction (ap);
3262 }
3263
3264
3265 bool
3266 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
3267 {
3268 if (!same_type_check (tsource, 0, fsource, 1))
3269 return false;
3270
3271 if (!type_check (mask, 2, BT_LOGICAL))
3272 return false;
3273
3274 if (tsource->ts.type == BT_CHARACTER)
3275 return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
3276
3277 return true;
3278 }
3279
3280
3281 bool
3282 gfc_check_merge_bits (gfc_expr *i, gfc_expr *j, gfc_expr *mask)
3283 {
3284 if (!type_check (i, 0, BT_INTEGER))
3285 return false;
3286
3287 if (!type_check (j, 1, BT_INTEGER))
3288 return false;
3289
3290 if (!type_check (mask, 2, BT_INTEGER))
3291 return false;
3292
3293 if (!same_type_check (i, 0, j, 1))
3294 return false;
3295
3296 if (!same_type_check (i, 0, mask, 2))
3297 return false;
3298
3299 return true;
3300 }
3301
3302
3303 bool
3304 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
3305 {
3306 if (!variable_check (from, 0, false))
3307 return false;
3308 if (!allocatable_check (from, 0))
3309 return false;
3310 if (gfc_is_coindexed (from))
3311 {
3312 gfc_error ("The FROM argument to MOVE_ALLOC at %L shall not be "
3313 "coindexed", &from->where);
3314 return false;
3315 }
3316
3317 if (!variable_check (to, 1, false))
3318 return false;
3319 if (!allocatable_check (to, 1))
3320 return false;
3321 if (gfc_is_coindexed (to))
3322 {
3323 gfc_error ("The TO argument to MOVE_ALLOC at %L shall not be "
3324 "coindexed", &to->where);
3325 return false;
3326 }
3327
3328 if (from->ts.type == BT_CLASS && to->ts.type == BT_DERIVED)
3329 {
3330 gfc_error ("The TO arguments in MOVE_ALLOC at %L must be "
3331 "polymorphic if FROM is polymorphic",
3332 &to->where);
3333 return false;
3334 }
3335
3336 if (!same_type_check (to, 1, from, 0))
3337 return false;
3338
3339 if (to->rank != from->rank)
3340 {
3341 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
3342 "must have the same rank %d/%d", &to->where, from->rank,
3343 to->rank);
3344 return false;
3345 }
3346
3347 /* IR F08/0040; cf. 12-006A. */
3348 if (gfc_get_corank (to) != gfc_get_corank (from))
3349 {
3350 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
3351 "must have the same corank %d/%d", &to->where,
3352 gfc_get_corank (from), gfc_get_corank (to));
3353 return false;
3354 }
3355
3356 /* This is based losely on F2003 12.4.1.7. It is intended to prevent
3357 the likes of to = sym->cmp1->cmp2 and from = sym->cmp1, where cmp1
3358 and cmp2 are allocatable. After the allocation is transferred,
3359 the 'to' chain is broken by the nullification of the 'from'. A bit
3360 of reflection reveals that this can only occur for derived types
3361 with recursive allocatable components. */
3362 if (to->expr_type == EXPR_VARIABLE && from->expr_type == EXPR_VARIABLE
3363 && !strcmp (to->symtree->n.sym->name, from->symtree->n.sym->name))
3364 {
3365 gfc_ref *to_ref, *from_ref;
3366 to_ref = to->ref;
3367 from_ref = from->ref;
3368 bool aliasing = true;
3369
3370 for (; from_ref && to_ref;
3371 from_ref = from_ref->next, to_ref = to_ref->next)
3372 {
3373 if (to_ref->type != from->ref->type)
3374 aliasing = false;
3375 else if (to_ref->type == REF_ARRAY
3376 && to_ref->u.ar.type != AR_FULL
3377 && from_ref->u.ar.type != AR_FULL)
3378 /* Play safe; assume sections and elements are different. */
3379 aliasing = false;
3380 else if (to_ref->type == REF_COMPONENT
3381 && to_ref->u.c.component != from_ref->u.c.component)
3382 aliasing = false;
3383
3384 if (!aliasing)
3385 break;
3386 }
3387
3388 if (aliasing)
3389 {
3390 gfc_error ("The FROM and TO arguments at %L violate aliasing "
3391 "restrictions (F2003 12.4.1.7)", &to->where);
3392 return false;
3393 }
3394 }
3395
3396 /* CLASS arguments: Make sure the vtab of from is present. */
3397 if (to->ts.type == BT_CLASS && !UNLIMITED_POLY (from))
3398 gfc_find_vtab (&from->ts);
3399
3400 return true;
3401 }
3402
3403
3404 bool
3405 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
3406 {
3407 if (!type_check (x, 0, BT_REAL))
3408 return false;
3409
3410 if (!type_check (s, 1, BT_REAL))
3411 return false;
3412
3413 if (s->expr_type == EXPR_CONSTANT)
3414 {
3415 if (mpfr_sgn (s->value.real) == 0)
3416 {
3417 gfc_error ("Argument %<S%> of NEAREST at %L shall not be zero",
3418 &s->where);
3419 return false;
3420 }
3421 }
3422
3423 return true;
3424 }
3425
3426
3427 bool
3428 gfc_check_new_line (gfc_expr *a)
3429 {
3430 if (!type_check (a, 0, BT_CHARACTER))
3431 return false;
3432
3433 return true;
3434 }
3435
3436
3437 bool
3438 gfc_check_norm2 (gfc_expr *array, gfc_expr *dim)
3439 {
3440 if (!type_check (array, 0, BT_REAL))
3441 return false;
3442
3443 if (!array_check (array, 0))
3444 return false;
3445
3446 if (!dim_rank_check (dim, array, false))
3447 return false;
3448
3449 return true;
3450 }
3451
3452 bool
3453 gfc_check_null (gfc_expr *mold)
3454 {
3455 symbol_attribute attr;
3456
3457 if (mold == NULL)
3458 return true;
3459
3460 if (!variable_check (mold, 0, true))
3461 return false;
3462
3463 attr = gfc_variable_attr (mold, NULL);
3464
3465 if (!attr.pointer && !attr.proc_pointer && !attr.allocatable)
3466 {
3467 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER, "
3468 "ALLOCATABLE or procedure pointer",
3469 gfc_current_intrinsic_arg[0]->name,
3470 gfc_current_intrinsic, &mold->where);
3471 return false;
3472 }
3473
3474 if (attr.allocatable
3475 && !gfc_notify_std (GFC_STD_F2003, "NULL intrinsic with "
3476 "allocatable MOLD at %L", &mold->where))
3477 return false;
3478
3479 /* F2008, C1242. */
3480 if (gfc_is_coindexed (mold))
3481 {
3482 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
3483 "coindexed", gfc_current_intrinsic_arg[0]->name,
3484 gfc_current_intrinsic, &mold->where);
3485 return false;
3486 }
3487
3488 return true;
3489 }
3490
3491
3492 bool
3493 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
3494 {
3495 if (!array_check (array, 0))
3496 return false;
3497
3498 if (!type_check (mask, 1, BT_LOGICAL))
3499 return false;
3500
3501 if (!gfc_check_conformance (array, mask,
3502 "arguments '%s' and '%s' for intrinsic '%s'",
3503 gfc_current_intrinsic_arg[0]->name,
3504 gfc_current_intrinsic_arg[1]->name,
3505 gfc_current_intrinsic))
3506 return false;
3507
3508 if (vector != NULL)
3509 {
3510 mpz_t array_size, vector_size;
3511 bool have_array_size, have_vector_size;
3512
3513 if (!same_type_check (array, 0, vector, 2))
3514 return false;
3515
3516 if (!rank_check (vector, 2, 1))
3517 return false;
3518
3519 /* VECTOR requires at least as many elements as MASK
3520 has .TRUE. values. */
3521 have_array_size = gfc_array_size(array, &array_size);
3522 have_vector_size = gfc_array_size(vector, &vector_size);
3523
3524 if (have_vector_size
3525 && (mask->expr_type == EXPR_ARRAY
3526 || (mask->expr_type == EXPR_CONSTANT
3527 && have_array_size)))
3528 {
3529 int mask_true_values = 0;
3530
3531 if (mask->expr_type == EXPR_ARRAY)
3532 {
3533 gfc_constructor *mask_ctor;
3534 mask_ctor = gfc_constructor_first (mask->value.constructor);
3535 while (mask_ctor)
3536 {
3537 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
3538 {
3539 mask_true_values = 0;
3540 break;
3541 }
3542
3543 if (mask_ctor->expr->value.logical)
3544 mask_true_values++;
3545
3546 mask_ctor = gfc_constructor_next (mask_ctor);
3547 }
3548 }
3549 else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
3550 mask_true_values = mpz_get_si (array_size);
3551
3552 if (mpz_get_si (vector_size) < mask_true_values)
3553 {
3554 gfc_error ("%qs argument of %qs intrinsic at %L must "
3555 "provide at least as many elements as there "
3556 "are .TRUE. values in %qs (%ld/%d)",
3557 gfc_current_intrinsic_arg[2]->name,
3558 gfc_current_intrinsic, &vector->where,
3559 gfc_current_intrinsic_arg[1]->name,
3560 mpz_get_si (vector_size), mask_true_values);
3561 return false;
3562 }
3563 }
3564
3565 if (have_array_size)
3566 mpz_clear (array_size);
3567 if (have_vector_size)
3568 mpz_clear (vector_size);
3569 }
3570
3571 return true;
3572 }
3573
3574
3575 bool
3576 gfc_check_parity (gfc_expr *mask, gfc_expr *dim)
3577 {
3578 if (!type_check (mask, 0, BT_LOGICAL))
3579 return false;
3580
3581 if (!array_check (mask, 0))
3582 return false;
3583
3584 if (!dim_rank_check (dim, mask, false))
3585 return false;
3586
3587 return true;
3588 }
3589
3590
3591 bool
3592 gfc_check_precision (gfc_expr *x)
3593 {
3594 if (!real_or_complex_check (x, 0))
3595 return false;
3596
3597 return true;
3598 }
3599
3600
3601 bool
3602 gfc_check_present (gfc_expr *a)
3603 {
3604 gfc_symbol *sym;
3605
3606 if (!variable_check (a, 0, true))
3607 return false;
3608
3609 sym = a->symtree->n.sym;
3610 if (!sym->attr.dummy)
3611 {
3612 gfc_error ("%qs argument of %qs intrinsic at %L must be of a "
3613 "dummy variable", gfc_current_intrinsic_arg[0]->name,
3614 gfc_current_intrinsic, &a->where);
3615 return false;
3616 }
3617
3618 if (!sym->attr.optional)
3619 {
3620 gfc_error ("%qs argument of %qs intrinsic at %L must be of "
3621 "an OPTIONAL dummy variable",
3622 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3623 &a->where);
3624 return false;
3625 }
3626
3627 /* 13.14.82 PRESENT(A)
3628 ......
3629 Argument. A shall be the name of an optional dummy argument that is
3630 accessible in the subprogram in which the PRESENT function reference
3631 appears... */
3632
3633 if (a->ref != NULL
3634 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
3635 && (a->ref->u.ar.type == AR_FULL
3636 || (a->ref->u.ar.type == AR_ELEMENT
3637 && a->ref->u.ar.as->rank == 0))))
3638 {
3639 gfc_error ("%qs argument of %qs intrinsic at %L must not be a "
3640 "subobject of %qs", gfc_current_intrinsic_arg[0]->name,
3641 gfc_current_intrinsic, &a->where, sym->name);
3642 return false;
3643 }
3644
3645 return true;
3646 }
3647
3648
3649 bool
3650 gfc_check_radix (gfc_expr *x)
3651 {
3652 if (!int_or_real_check (x, 0))
3653 return false;
3654
3655 return true;
3656 }
3657
3658
3659 bool
3660 gfc_check_range (gfc_expr *x)
3661 {
3662 if (!numeric_check (x, 0))
3663 return false;
3664
3665 return true;
3666 }
3667
3668
3669 bool
3670 gfc_check_rank (gfc_expr *a)
3671 {
3672 /* Any data object is allowed; a "data object" is a "constant (4.1.3),
3673 variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
3674
3675 bool is_variable = true;
3676
3677 /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
3678 if (a->expr_type == EXPR_FUNCTION)
3679 is_variable = a->value.function.esym
3680 ? a->value.function.esym->result->attr.pointer
3681 : a->symtree->n.sym->result->attr.pointer;
3682
3683 if (a->expr_type == EXPR_OP || a->expr_type == EXPR_NULL
3684 || a->expr_type == EXPR_COMPCALL|| a->expr_type == EXPR_PPC
3685 || !is_variable)
3686 {
3687 gfc_error ("The argument of the RANK intrinsic at %L must be a data "
3688 "object", &a->where);
3689 return false;
3690 }
3691
3692 return true;
3693 }
3694
3695
3696 /* real, float, sngl. */
3697 bool
3698 gfc_check_real (gfc_expr *a, gfc_expr *kind)
3699 {
3700 if (!numeric_check (a, 0))
3701 return false;
3702
3703 if (!kind_check (kind, 1, BT_REAL))
3704 return false;
3705
3706 return true;
3707 }
3708
3709
3710 bool
3711 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
3712 {
3713 if (!type_check (path1, 0, BT_CHARACTER))
3714 return false;
3715 if (!kind_value_check (path1, 0, gfc_default_character_kind))
3716 return false;
3717
3718 if (!type_check (path2, 1, BT_CHARACTER))
3719 return false;
3720 if (!kind_value_check (path2, 1, gfc_default_character_kind))
3721 return false;
3722
3723 return true;
3724 }
3725
3726
3727 bool
3728 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
3729 {
3730 if (!type_check (path1, 0, BT_CHARACTER))
3731 return false;
3732 if (!kind_value_check (path1, 0, gfc_default_character_kind))
3733 return false;
3734
3735 if (!type_check (path2, 1, BT_CHARACTER))
3736 return false;
3737 if (!kind_value_check (path2, 1, gfc_default_character_kind))
3738 return false;
3739
3740 if (status == NULL)
3741 return true;
3742
3743 if (!type_check (status, 2, BT_INTEGER))
3744 return false;
3745
3746 if (!scalar_check (status, 2))
3747 return false;
3748
3749 return true;
3750 }
3751
3752
3753 bool
3754 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
3755 {
3756 if (!type_check (x, 0, BT_CHARACTER))
3757 return false;
3758
3759 if (!scalar_check (x, 0))
3760 return false;
3761
3762 if (!type_check (y, 0, BT_INTEGER))
3763 return false;
3764
3765 if (!scalar_check (y, 1))
3766 return false;
3767
3768 return true;
3769 }
3770
3771
3772 bool
3773 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
3774 gfc_expr *pad, gfc_expr *order)
3775 {
3776 mpz_t size;
3777 mpz_t nelems;
3778 int shape_size;
3779
3780 if (!array_check (source, 0))
3781 return false;
3782
3783 if (!rank_check (shape, 1, 1))
3784 return false;
3785
3786 if (!type_check (shape, 1, BT_INTEGER))
3787 return false;
3788
3789 if (!gfc_array_size (shape, &size))
3790 {
3791 gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L must be an "
3792 "array of constant size", &shape->where);
3793 return false;
3794 }
3795
3796 shape_size = mpz_get_ui (size);
3797 mpz_clear (size);
3798
3799 if (shape_size <= 0)
3800 {
3801 gfc_error ("%qs argument of %qs intrinsic at %L is empty",
3802 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3803 &shape->where);
3804 return false;
3805 }
3806 else if (shape_size > GFC_MAX_DIMENSIONS)
3807 {
3808 gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L has more "
3809 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
3810 return false;
3811 }
3812 else if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape))
3813 {
3814 gfc_expr *e;
3815 int i, extent;
3816 for (i = 0; i < shape_size; ++i)
3817 {
3818 e = gfc_constructor_lookup_expr (shape->value.constructor, i);
3819 if (e->expr_type != EXPR_CONSTANT)
3820 continue;
3821
3822 gfc_extract_int (e, &extent);
3823 if (extent < 0)
3824 {
3825 gfc_error ("%qs argument of %qs intrinsic at %L has "
3826 "negative element (%d)",
3827 gfc_current_intrinsic_arg[1]->name,
3828 gfc_current_intrinsic, &e->where, extent);
3829 return false;
3830 }
3831 }
3832 }
3833 else if (shape->expr_type == EXPR_VARIABLE && shape->ref
3834 && shape->ref->u.ar.type == AR_FULL && shape->ref->u.ar.dimen == 1
3835 && shape->ref->u.ar.as
3836 && shape->ref->u.ar.as->lower[0]->expr_type == EXPR_CONSTANT
3837 && shape->ref->u.ar.as->lower[0]->ts.type == BT_INTEGER
3838 && shape->ref->u.ar.as->upper[0]->expr_type == EXPR_CONSTANT
3839 && shape->ref->u.ar.as->upper[0]->ts.type == BT_INTEGER
3840 && shape->symtree->n.sym->attr.flavor == FL_PARAMETER)
3841 {
3842 int i, extent;
3843 gfc_expr *e, *v;
3844
3845 v = shape->symtree->n.sym->value;
3846
3847 for (i = 0; i < shape_size; i++)
3848 {
3849 e = gfc_constructor_lookup_expr (v->value.constructor, i);
3850 if (e == NULL)
3851 break;
3852
3853 gfc_extract_int (e, &extent);
3854
3855 if (extent < 0)
3856 {
3857 gfc_error ("Element %d of actual argument of RESHAPE at %L "
3858 "cannot be negative", i + 1, &shape->where);
3859 return false;
3860 }
3861 }
3862 }
3863
3864 if (pad != NULL)
3865 {
3866 if (!same_type_check (source, 0, pad, 2))
3867 return false;
3868
3869 if (!array_check (pad, 2))
3870 return false;
3871 }
3872
3873 if (order != NULL)
3874 {
3875 if (!array_check (order, 3))
3876 return false;
3877
3878 if (!type_check (order, 3, BT_INTEGER))
3879 return false;
3880
3881 if (order->expr_type == EXPR_ARRAY && gfc_is_constant_expr (order))
3882 {
3883 int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
3884 gfc_expr *e;
3885
3886 for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
3887 perm[i] = 0;
3888
3889 gfc_array_size (order, &size);
3890 order_size = mpz_get_ui (size);
3891 mpz_clear (size);
3892
3893 if (order_size != shape_size)
3894 {
3895 gfc_error ("%qs argument of %qs intrinsic at %L "
3896 "has wrong number of elements (%d/%d)",
3897 gfc_current_intrinsic_arg[3]->name,
3898 gfc_current_intrinsic, &order->where,
3899 order_size, shape_size);
3900 return false;
3901 }
3902
3903 for (i = 1; i <= order_size; ++i)
3904 {
3905 e = gfc_constructor_lookup_expr (order->value.constructor, i-1);
3906 if (e->expr_type != EXPR_CONSTANT)
3907 continue;
3908
3909 gfc_extract_int (e, &dim);
3910
3911 if (dim < 1 || dim > order_size)
3912 {
3913 gfc_error ("%qs argument of %qs intrinsic at %L "
3914 "has out-of-range dimension (%d)",
3915 gfc_current_intrinsic_arg[3]->name,
3916 gfc_current_intrinsic, &e->where, dim);
3917 return false;
3918 }
3919
3920 if (perm[dim-1] != 0)
3921 {
3922 gfc_error ("%qs argument of %qs intrinsic at %L has "
3923 "invalid permutation of dimensions (dimension "
3924 "%qd duplicated)",
3925 gfc_current_intrinsic_arg[3]->name,
3926 gfc_current_intrinsic, &e->where, dim);
3927 return false;
3928 }
3929
3930 perm[dim-1] = 1;
3931 }
3932 }
3933 }
3934
3935 if (pad == NULL && shape->expr_type == EXPR_ARRAY
3936 && gfc_is_constant_expr (shape)
3937 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
3938 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
3939 {
3940 /* Check the match in size between source and destination. */
3941 if (gfc_array_size (source, &nelems))
3942 {
3943 gfc_constructor *c;
3944 bool test;
3945
3946
3947 mpz_init_set_ui (size, 1);
3948 for (c = gfc_constructor_first (shape->value.constructor);
3949 c; c = gfc_constructor_next (c))
3950 mpz_mul (size, size, c->expr->value.integer);
3951
3952 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
3953 mpz_clear (nelems);
3954 mpz_clear (size);
3955
3956 if (test)
3957 {
3958 gfc_error ("Without padding, there are not enough elements "
3959 "in the intrinsic RESHAPE source at %L to match "
3960 "the shape", &source->where);
3961 return false;
3962 }
3963 }
3964 }
3965
3966 return true;
3967 }
3968
3969
3970 bool
3971 gfc_check_same_type_as (gfc_expr *a, gfc_expr *b)
3972 {
3973 if (a->ts.type != BT_DERIVED && a->ts.type != BT_CLASS)
3974 {
3975 gfc_error ("%qs argument of %qs intrinsic at %L "
3976 "cannot be of type %s",
3977 gfc_current_intrinsic_arg[0]->name,
3978 gfc_current_intrinsic,
3979 &a->where, gfc_typename (&a->ts));
3980 return false;
3981 }
3982
3983 if (!(gfc_type_is_extensible (a->ts.u.derived) || UNLIMITED_POLY (a)))
3984 {
3985 gfc_error ("%qs argument of %qs intrinsic at %L "
3986 "must be of an extensible type",
3987 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3988 &a->where);
3989 return false;
3990 }
3991
3992 if (b->ts.type != BT_DERIVED && b->ts.type != BT_CLASS)
3993 {
3994 gfc_error ("%qs argument of %qs intrinsic at %L "
3995 "cannot be of type %s",
3996 gfc_current_intrinsic_arg[0]->name,
3997 gfc_current_intrinsic,
3998 &b->where, gfc_typename (&b->ts));
3999 return false;
4000 }
4001
4002 if (!(gfc_type_is_extensible (b->ts.u.derived) || UNLIMITED_POLY (b)))
4003 {
4004 gfc_error ("%qs argument of %qs intrinsic at %L "
4005 "must be of an extensible type",
4006 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4007 &b->where);
4008 return false;
4009 }
4010
4011 return true;
4012 }
4013
4014
4015 bool
4016 gfc_check_scale (gfc_expr *x, gfc_expr *i)
4017 {
4018 if (!type_check (x, 0, BT_REAL))
4019 return false;
4020
4021 if (!type_check (i, 1, BT_INTEGER))
4022 return false;
4023
4024 return true;
4025 }
4026
4027
4028 bool
4029 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
4030 {
4031 if (!type_check (x, 0, BT_CHARACTER))
4032 return false;
4033
4034 if (!type_check (y, 1, BT_CHARACTER))
4035 return false;
4036
4037 if (z != NULL && !type_check (z, 2, BT_LOGICAL))
4038 return false;
4039
4040 if (!kind_check (kind, 3, BT_INTEGER))
4041 return false;
4042 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
4043 "with KIND argument at %L",
4044 gfc_current_intrinsic, &kind->where))
4045 return false;
4046
4047 if (!same_type_check (x, 0, y, 1))
4048 return false;
4049
4050 return true;
4051 }
4052
4053
4054 bool
4055 gfc_check_secnds (gfc_expr *r)
4056 {
4057 if (!type_check (r, 0, BT_REAL))
4058 return false;
4059
4060 if (!kind_value_check (r, 0, 4))
4061 return false;
4062
4063 if (!scalar_check (r, 0))
4064 return false;
4065
4066 return true;
4067 }
4068
4069
4070 bool
4071 gfc_check_selected_char_kind (gfc_expr *name)
4072 {
4073 if (!type_check (name, 0, BT_CHARACTER))
4074 return false;
4075
4076 if (!kind_value_check (name, 0, gfc_default_character_kind))
4077 return false;
4078
4079 if (!scalar_check (name, 0))
4080 return false;
4081
4082 return true;
4083 }
4084
4085
4086 bool
4087 gfc_check_selected_int_kind (gfc_expr *r)
4088 {
4089 if (!type_check (r, 0, BT_INTEGER))
4090 return false;
4091
4092 if (!scalar_check (r, 0))
4093 return false;
4094
4095 return true;
4096 }
4097
4098
4099 bool
4100 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r, gfc_expr *radix)
4101 {
4102 if (p == NULL && r == NULL
4103 && !gfc_notify_std (GFC_STD_F2008, "SELECTED_REAL_KIND with"
4104 " neither %<P%> nor %<R%> argument at %L",
4105 gfc_current_intrinsic_where))
4106 return false;
4107
4108 if (p)
4109 {
4110 if (!type_check (p, 0, BT_INTEGER))
4111 return false;
4112
4113 if (!scalar_check (p, 0))
4114 return false;
4115 }
4116
4117 if (r)
4118 {
4119 if (!type_check (r, 1, BT_INTEGER))
4120 return false;
4121
4122 if (!scalar_check (r, 1))
4123 return false;
4124 }
4125
4126 if (radix)
4127 {
4128 if (!type_check (radix, 1, BT_INTEGER))
4129 return false;
4130
4131 if (!scalar_check (radix, 1))
4132 return false;
4133
4134 if (!gfc_notify_std (GFC_STD_F2008, "%qs intrinsic with "
4135 "RADIX argument at %L", gfc_current_intrinsic,
4136 &radix->where))
4137 return false;
4138 }
4139
4140 return true;
4141 }
4142
4143
4144 bool
4145 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
4146 {
4147 if (!type_check (x, 0, BT_REAL))
4148 return false;
4149
4150 if (!type_check (i, 1, BT_INTEGER))
4151 return false;
4152
4153 return true;
4154 }
4155
4156
4157 bool
4158 gfc_check_shape (gfc_expr *source, gfc_expr *kind)
4159 {
4160 gfc_array_ref *ar;
4161
4162 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
4163 return true;
4164
4165 ar = gfc_find_array_ref (source);
4166
4167 if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
4168 {
4169 gfc_error ("%<source%> argument of %<shape%> intrinsic at %L must not be "
4170 "an assumed size array", &source->where);
4171 return false;
4172 }
4173
4174 if (!kind_check (kind, 1, BT_INTEGER))
4175 return false;
4176 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
4177 "with KIND argument at %L",
4178 gfc_current_intrinsic, &kind->where))
4179 return false;
4180
4181 return true;
4182 }
4183
4184
4185 bool
4186 gfc_check_shift (gfc_expr *i, gfc_expr *shift)
4187 {
4188 if (!type_check (i, 0, BT_INTEGER))
4189 return false;
4190
4191 if (!type_check (shift, 0, BT_INTEGER))
4192 return false;
4193
4194 if (!nonnegative_check ("SHIFT", shift))
4195 return false;
4196
4197 if (!less_than_bitsize1 ("I", i, "SHIFT", shift, true))
4198 return false;
4199
4200 return true;
4201 }
4202
4203
4204 bool
4205 gfc_check_sign (gfc_expr *a, gfc_expr *b)
4206 {
4207 if (!int_or_real_check (a, 0))
4208 return false;
4209
4210 if (!same_type_check (a, 0, b, 1))
4211 return false;
4212
4213 return true;
4214 }
4215
4216
4217 bool
4218 gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
4219 {
4220 if (!array_check (array, 0))
4221 return false;
4222
4223 if (!dim_check (dim, 1, true))
4224 return false;
4225
4226 if (!dim_rank_check (dim, array, 0))
4227 return false;
4228
4229 if (!kind_check (kind, 2, BT_INTEGER))
4230 return false;
4231 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
4232 "with KIND argument at %L",
4233 gfc_current_intrinsic, &kind->where))
4234 return false;
4235
4236
4237 return true;
4238 }
4239
4240
4241 bool
4242 gfc_check_sizeof (gfc_expr *arg)
4243 {
4244 if (arg->ts.type == BT_PROCEDURE)
4245 {
4246 gfc_error ("%qs argument of %qs intrinsic at %L shall not be a procedure",
4247 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4248 &arg->where);
4249 return false;
4250 }
4251
4252 /* TYPE(*) is acceptable if and only if it uses an array descriptor. */
4253 if (arg->ts.type == BT_ASSUMED
4254 && (arg->symtree->n.sym->as == NULL
4255 || (arg->symtree->n.sym->as->type != AS_ASSUMED_SHAPE
4256 && arg->symtree->n.sym->as->type != AS_DEFERRED
4257 && arg->symtree->n.sym->as->type != AS_ASSUMED_RANK)))
4258 {
4259 gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
4260 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4261 &arg->where);
4262 return false;
4263 }
4264
4265 if (arg->rank && arg->expr_type == EXPR_VARIABLE
4266 && arg->symtree->n.sym->as != NULL
4267 && arg->symtree->n.sym->as->type == AS_ASSUMED_SIZE && arg->ref
4268 && arg->ref->type == REF_ARRAY && arg->ref->u.ar.type == AR_FULL)
4269 {
4270 gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
4271 "assumed-size array", gfc_current_intrinsic_arg[0]->name,
4272 gfc_current_intrinsic, &arg->where);
4273 return false;
4274 }
4275
4276 return true;
4277 }
4278
4279
4280 /* Check whether an expression is interoperable. When returning false,
4281 msg is set to a string telling why the expression is not interoperable,
4282 otherwise, it is set to NULL. The msg string can be used in diagnostics.
4283 If c_loc is true, character with len > 1 are allowed (cf. Fortran
4284 2003corr5); additionally, assumed-shape/assumed-rank/deferred-shape
4285 arrays are permitted. And if c_f_ptr is true, deferred-shape arrays
4286 are permitted. */
4287
4288 static bool
4289 is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr)
4290 {
4291 *msg = NULL;
4292
4293 if (expr->ts.type == BT_CLASS)
4294 {
4295 *msg = "Expression is polymorphic";
4296 return false;
4297 }
4298
4299 if (expr->ts.type == BT_DERIVED && !expr->ts.u.derived->attr.is_bind_c
4300 && !expr->ts.u.derived->ts.is_iso_c)
4301 {
4302 *msg = "Expression is a noninteroperable derived type";
4303 return false;
4304 }
4305
4306 if (expr->ts.type == BT_PROCEDURE)
4307 {
4308 *msg = "Procedure unexpected as argument";
4309 return false;
4310 }
4311
4312 if (gfc_notification_std (GFC_STD_GNU) && expr->ts.type == BT_LOGICAL)
4313 {
4314 int i;
4315 for (i = 0; gfc_logical_kinds[i].kind; i++)
4316 if (gfc_logical_kinds[i].kind == expr->ts.kind)
4317 return true;
4318 *msg = "Extension to use a non-C_Bool-kind LOGICAL";
4319 return false;
4320 }
4321
4322 if (gfc_notification_std (GFC_STD_GNU) && expr->ts.type == BT_CHARACTER
4323 && expr->ts.kind != 1)
4324 {
4325 *msg = "Extension to use a non-C_CHAR-kind CHARACTER";
4326 return false;
4327 }
4328
4329 if (expr->ts.type == BT_CHARACTER) {
4330 if (expr->ts.deferred)
4331 {
4332 /* TS 29113 allows deferred-length strings as dummy arguments,
4333 but it is not an interoperable type. */
4334 *msg = "Expression shall not be a deferred-length string";
4335 return false;
4336 }
4337
4338 if (expr->ts.u.cl && expr->ts.u.cl->length
4339 && !gfc_simplify_expr (expr->ts.u.cl->length, 0))
4340 gfc_internal_error ("is_c_interoperable(): gfc_simplify_expr failed");
4341
4342 if (!c_loc && expr->ts.u.cl
4343 && (!expr->ts.u.cl->length
4344 || expr->ts.u.cl->length->expr_type != EXPR_CONSTANT
4345 || mpz_cmp_si (expr->ts.u.cl->length->value.integer, 1) != 0))
4346 {
4347 *msg = "Type shall have a character length of 1";
4348 return false;
4349 }
4350 }
4351
4352 /* Note: The following checks are about interoperatable variables, Fortran
4353 15.3.5/15.3.6. In intrinsics like C_LOC or in procedure interface, more
4354 is allowed, e.g. assumed-shape arrays with TS 29113. */
4355
4356 if (gfc_is_coarray (expr))
4357 {
4358 *msg = "Coarrays are not interoperable";
4359 return false;
4360 }
4361
4362 if (!c_loc && expr->rank > 0 && expr->expr_type != EXPR_ARRAY)
4363 {
4364 gfc_array_ref *ar = gfc_find_array_ref (expr);
4365 if (ar->type != AR_FULL)
4366 {
4367 *msg = "Only whole-arrays are interoperable";
4368 return false;
4369 }
4370 if (!c_f_ptr && ar->as->type != AS_EXPLICIT
4371 && ar->as->type != AS_ASSUMED_SIZE)
4372 {
4373 *msg = "Only explicit-size and assumed-size arrays are interoperable";
4374 return false;
4375 }
4376 }
4377
4378 return true;
4379 }
4380
4381
4382 bool
4383 gfc_check_c_sizeof (gfc_expr *arg)
4384 {
4385 const char *msg;
4386
4387 if (!is_c_interoperable (arg, &msg, false, false))
4388 {
4389 gfc_error ("%qs argument of %qs intrinsic at %L must be an "
4390 "interoperable data entity: %s",
4391 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4392 &arg->where, msg);
4393 return false;
4394 }
4395
4396 if (arg->ts.type == BT_ASSUMED)
4397 {
4398 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
4399 "TYPE(*)",
4400 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4401 &arg->where);
4402 return false;
4403 }
4404
4405 if (arg->rank && arg->expr_type == EXPR_VARIABLE
4406 && arg->symtree->n.sym->as != NULL
4407 && arg->symtree->n.sym->as->type == AS_ASSUMED_SIZE && arg->ref
4408 && arg->ref->type == REF_ARRAY && arg->ref->u.ar.type == AR_FULL)
4409 {
4410 gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
4411 "assumed-size array", gfc_current_intrinsic_arg[0]->name,
4412 gfc_current_intrinsic, &arg->where);
4413 return false;
4414 }
4415
4416 return true;
4417 }
4418
4419
4420 bool
4421 gfc_check_c_associated (gfc_expr *c_ptr_1, gfc_expr *c_ptr_2)
4422 {
4423 if (c_ptr_1->ts.type != BT_DERIVED
4424 || c_ptr_1->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
4425 || (c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR
4426 && c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR))
4427 {
4428 gfc_error ("Argument C_PTR_1 at %L to C_ASSOCIATED shall have the "
4429 "type TYPE(C_PTR) or TYPE(C_FUNPTR)", &c_ptr_1->where);
4430 return false;
4431 }
4432
4433 if (!scalar_check (c_ptr_1, 0))
4434 return false;
4435
4436 if (c_ptr_2
4437 && (c_ptr_2->ts.type != BT_DERIVED
4438 || c_ptr_2->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
4439 || (c_ptr_1->ts.u.derived->intmod_sym_id
4440 != c_ptr_2->ts.u.derived->intmod_sym_id)))
4441 {
4442 gfc_error ("Argument C_PTR_2 at %L to C_ASSOCIATED shall have the "
4443 "same type as C_PTR_1: %s instead of %s", &c_ptr_1->where,
4444 gfc_typename (&c_ptr_1->ts),
4445 gfc_typename (&c_ptr_2->ts));
4446 return false;
4447 }
4448
4449 if (c_ptr_2 && !scalar_check (c_ptr_2, 1))
4450 return false;
4451
4452 return true;
4453 }
4454
4455
4456 bool
4457 gfc_check_c_f_pointer (gfc_expr *cptr, gfc_expr *fptr, gfc_expr *shape)
4458 {
4459 symbol_attribute attr;
4460 const char *msg;
4461
4462 if (cptr->ts.type != BT_DERIVED
4463 || cptr->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
4464 || cptr->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR)
4465 {
4466 gfc_error ("Argument CPTR at %L to C_F_POINTER shall have the "
4467 "type TYPE(C_PTR)", &cptr->where);
4468 return false;
4469 }
4470
4471 if (!scalar_check (cptr, 0))
4472 return false;
4473
4474 attr = gfc_expr_attr (fptr);
4475
4476 if (!attr.pointer)
4477 {
4478 gfc_error ("Argument FPTR at %L to C_F_POINTER must be a pointer",
4479 &fptr->where);
4480 return false;
4481 }
4482
4483 if (fptr->ts.type == BT_CLASS)
4484 {
4485 gfc_error ("FPTR argument at %L to C_F_POINTER shall not be polymorphic",
4486 &fptr->where);
4487 return false;
4488 }
4489
4490 if (gfc_is_coindexed (fptr))
4491 {
4492 gfc_error ("Argument FPTR at %L to C_F_POINTER shall not be "
4493 "coindexed", &fptr->where);
4494 return false;
4495 }
4496
4497 if (fptr->rank == 0 && shape)
4498 {
4499 gfc_error ("Unexpected SHAPE argument at %L to C_F_POINTER with scalar "
4500 "FPTR", &fptr->where);
4501 return false;
4502 }
4503 else if (fptr->rank && !shape)
4504 {
4505 gfc_error ("Expected SHAPE argument to C_F_POINTER with array "
4506 "FPTR at %L", &fptr->where);
4507 return false;
4508 }
4509
4510 if (shape && !rank_check (shape, 2, 1))
4511 return false;
4512
4513 if (shape && !type_check (shape, 2, BT_INTEGER))
4514 return false;
4515
4516 if (shape)
4517 {
4518 mpz_t size;
4519 if (gfc_array_size (shape, &size))
4520 {
4521 if (mpz_cmp_ui (size, fptr->rank) != 0)
4522 {
4523 mpz_clear (size);
4524 gfc_error ("SHAPE argument at %L to C_F_POINTER must have the same "
4525 "size as the RANK of FPTR", &shape->where);
4526 return false;
4527 }
4528 mpz_clear (size);
4529 }
4530 }
4531
4532 if (fptr->ts.type == BT_CLASS)
4533 {
4534 gfc_error ("Polymorphic FPTR at %L to C_F_POINTER", &fptr->where);
4535 return false;
4536 }
4537
4538 if (!is_c_interoperable (fptr, &msg, false, true))
4539 return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable array FPTR "
4540 "at %L to C_F_POINTER: %s", &fptr->where, msg);
4541
4542 return true;
4543 }
4544
4545
4546 bool
4547 gfc_check_c_f_procpointer (gfc_expr *cptr, gfc_expr *fptr)
4548 {
4549 symbol_attribute attr;
4550
4551 if (cptr->ts.type != BT_DERIVED
4552 || cptr->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
4553 || cptr->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR)
4554 {
4555 gfc_error ("Argument CPTR at %L to C_F_PROCPOINTER shall have the "
4556 "type TYPE(C_FUNPTR)", &cptr->where);
4557 return false;
4558 }
4559
4560 if (!scalar_check (cptr, 0))
4561 return false;
4562
4563 attr = gfc_expr_attr (fptr);
4564
4565 if (!attr.proc_pointer)
4566 {
4567 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall be a procedure "
4568 "pointer", &fptr->where);
4569 return false;
4570 }
4571
4572 if (gfc_is_coindexed (fptr))
4573 {
4574 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall not be "
4575 "coindexed", &fptr->where);
4576 return false;
4577 }
4578
4579 if (!attr.is_bind_c)
4580 return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable procedure "
4581 "pointer at %L to C_F_PROCPOINTER", &fptr->where);
4582
4583 return true;
4584 }
4585
4586
4587 bool
4588 gfc_check_c_funloc (gfc_expr *x)
4589 {
4590 symbol_attribute attr;
4591
4592 if (gfc_is_coindexed (x))
4593 {
4594 gfc_error ("Argument X at %L to C_FUNLOC shall not be "
4595 "coindexed", &x->where);
4596 return false;
4597 }
4598
4599 attr = gfc_expr_attr (x);
4600
4601 if (attr.function && !attr.proc_pointer && x->expr_type == EXPR_VARIABLE
4602 && x->symtree->n.sym == x->symtree->n.sym->result)
4603 {
4604 gfc_namespace *ns = gfc_current_ns;
4605
4606 for (ns = gfc_current_ns; ns; ns = ns->parent)
4607 if (x->symtree->n.sym == ns->proc_name)
4608 {
4609 gfc_error ("Function result %qs at %L is invalid as X argument "
4610 "to C_FUNLOC", x->symtree->n.sym->name, &x->where);
4611 return false;
4612 }
4613 }
4614
4615 if (attr.flavor != FL_PROCEDURE)
4616 {
4617 gfc_error ("Argument X at %L to C_FUNLOC shall be a procedure "
4618 "or a procedure pointer", &x->where);
4619 return false;
4620 }
4621
4622 if (!attr.is_bind_c)
4623 return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable procedure "
4624 "at %L to C_FUNLOC", &x->where);
4625 return true;
4626 }
4627
4628
4629 bool
4630 gfc_check_c_loc (gfc_expr *x)
4631 {
4632 symbol_attribute attr;
4633 const char *msg;
4634
4635 if (gfc_is_coindexed (x))
4636 {
4637 gfc_error ("Argument X at %L to C_LOC shall not be coindexed", &x->where);
4638 return false;
4639 }
4640
4641 if (x->ts.type == BT_CLASS)
4642 {
4643 gfc_error ("X argument at %L to C_LOC shall not be polymorphic",
4644 &x->where);
4645 return false;
4646 }
4647
4648 attr = gfc_expr_attr (x);
4649
4650 if (!attr.pointer
4651 && (x->expr_type != EXPR_VARIABLE || !attr.target
4652 || attr.flavor == FL_PARAMETER))
4653 {
4654 gfc_error ("Argument X at %L to C_LOC shall have either "
4655 "the POINTER or the TARGET attribute", &x->where);
4656 return false;
4657 }
4658
4659 if (x->ts.type == BT_CHARACTER
4660 && gfc_var_strlen (x) == 0)
4661 {
4662 gfc_error ("Argument X at %L to C_LOC shall be not be a zero-sized "
4663 "string", &x->where);
4664 return false;
4665 }
4666
4667 if (!is_c_interoperable (x, &msg, true, false))
4668 {
4669 if (x->ts.type == BT_CLASS)
4670 {
4671 gfc_error ("Argument at %L to C_LOC shall not be polymorphic",
4672 &x->where);
4673 return false;
4674 }
4675
4676 if (x->rank
4677 && !gfc_notify_std (GFC_STD_F2008_TS,
4678 "Noninteroperable array at %L as"
4679 " argument to C_LOC: %s", &x->where, msg))
4680 return false;
4681 }
4682 else if (x->rank > 0 && gfc_notification_std (GFC_STD_F2008))
4683 {
4684 gfc_array_ref *ar = gfc_find_array_ref (x);
4685
4686 if (ar->as->type != AS_EXPLICIT && ar->as->type != AS_ASSUMED_SIZE
4687 && !attr.allocatable
4688 && !gfc_notify_std (GFC_STD_F2008,
4689 "Array of interoperable type at %L "
4690 "to C_LOC which is nonallocatable and neither "
4691 "assumed size nor explicit size", &x->where))
4692 return false;
4693 else if (ar->type != AR_FULL
4694 && !gfc_notify_std (GFC_STD_F2008, "Array section at %L "
4695 "to C_LOC", &x->where))
4696 return false;
4697 }
4698
4699 return true;
4700 }
4701
4702
4703 bool
4704 gfc_check_sleep_sub (gfc_expr *seconds)
4705 {
4706 if (!type_check (seconds, 0, BT_INTEGER))
4707 return false;
4708
4709 if (!scalar_check (seconds, 0))
4710 return false;
4711
4712 return true;
4713 }
4714
4715 bool
4716 gfc_check_sngl (gfc_expr *a)
4717 {
4718 if (!type_check (a, 0, BT_REAL))
4719 return false;
4720
4721 if ((a->ts.kind != gfc_default_double_kind)
4722 && !gfc_notify_std (GFC_STD_GNU, "non double precision "
4723 "REAL argument to %s intrinsic at %L",
4724 gfc_current_intrinsic, &a->where))
4725 return false;
4726
4727 return true;
4728 }
4729
4730 bool
4731 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
4732 {
4733 if (source->rank >= GFC_MAX_DIMENSIONS)
4734 {
4735 gfc_error ("%qs argument of %qs intrinsic at %L must be less "
4736 "than rank %d", gfc_current_intrinsic_arg[0]->name,
4737 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
4738
4739 return false;
4740 }
4741
4742 if (dim == NULL)
4743 return false;
4744
4745 if (!dim_check (dim, 1, false))
4746 return false;
4747
4748 /* dim_rank_check() does not apply here. */
4749 if (dim
4750 && dim->expr_type == EXPR_CONSTANT
4751 && (mpz_cmp_ui (dim->value.integer, 1) < 0
4752 || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0))
4753 {
4754 gfc_error ("%qs argument of %qs intrinsic at %L is not a valid "
4755 "dimension index", gfc_current_intrinsic_arg[1]->name,
4756 gfc_current_intrinsic, &dim->where);
4757 return false;
4758 }
4759
4760 if (!type_check (ncopies, 2, BT_INTEGER))
4761 return false;
4762
4763 if (!scalar_check (ncopies, 2))
4764 return false;
4765
4766 return true;
4767 }
4768
4769
4770 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
4771 functions). */
4772
4773 bool
4774 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
4775 {
4776 if (!type_check (unit, 0, BT_INTEGER))
4777 return false;
4778
4779 if (!scalar_check (unit, 0))
4780 return false;
4781
4782 if (!type_check (c, 1, BT_CHARACTER))
4783 return false;
4784 if (!kind_value_check (c, 1, gfc_default_character_kind))
4785 return false;
4786
4787 if (status == NULL)
4788 return true;
4789
4790 if (!type_check (status, 2, BT_INTEGER)
4791 || !kind_value_check (status, 2, gfc_default_integer_kind)
4792 || !scalar_check (status, 2))
4793 return false;
4794
4795 return true;
4796 }
4797
4798
4799 bool
4800 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
4801 {
4802 return gfc_check_fgetputc_sub (unit, c, NULL);
4803 }
4804
4805
4806 bool
4807 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
4808 {
4809 if (!type_check (c, 0, BT_CHARACTER))
4810 return false;
4811 if (!kind_value_check (c, 0, gfc_default_character_kind))
4812 return false;
4813
4814 if (status == NULL)
4815 return true;
4816
4817 if (!type_check (status, 1, BT_INTEGER)
4818 || !kind_value_check (status, 1, gfc_default_integer_kind)
4819 || !scalar_check (status, 1))
4820 return false;
4821
4822 return true;
4823 }
4824
4825
4826 bool
4827 gfc_check_fgetput (gfc_expr *c)
4828 {
4829 return gfc_check_fgetput_sub (c, NULL);
4830 }
4831
4832
4833 bool
4834 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
4835 {
4836 if (!type_check (unit, 0, BT_INTEGER))
4837 return false;
4838
4839 if (!scalar_check (unit, 0))
4840 return false;
4841
4842 if (!type_check (offset, 1, BT_INTEGER))
4843 return false;
4844
4845 if (!scalar_check (offset, 1))
4846 return false;
4847
4848 if (!type_check (whence, 2, BT_INTEGER))
4849 return false;
4850
4851 if (!scalar_check (whence, 2))
4852 return false;
4853
4854 if (status == NULL)
4855 return true;
4856
4857 if (!type_check (status, 3, BT_INTEGER))
4858 return false;
4859
4860 if (!kind_value_check (status, 3, 4))
4861 return false;
4862
4863 if (!scalar_check (status, 3))
4864 return false;
4865
4866 return true;
4867 }
4868
4869
4870
4871 bool
4872 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
4873 {
4874 if (!type_check (unit, 0, BT_INTEGER))
4875 return false;
4876
4877 if (!scalar_check (unit, 0))
4878 return false;
4879
4880 if (!type_check (array, 1, BT_INTEGER)
4881 || !kind_value_check (unit, 0, gfc_default_integer_kind))
4882 return false;
4883
4884 if (!array_check (array, 1))
4885 return false;
4886
4887 return true;
4888 }
4889
4890
4891 bool
4892 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
4893 {
4894 if (!type_check (unit, 0, BT_INTEGER))
4895 return false;
4896
4897 if (!scalar_check (unit, 0))
4898 return false;
4899
4900 if (!type_check (array, 1, BT_INTEGER)
4901 || !kind_value_check (array, 1, gfc_default_integer_kind))
4902 return false;
4903
4904 if (!array_check (array, 1))
4905 return false;
4906
4907 if (status == NULL)
4908 return true;
4909
4910 if (!type_check (status, 2, BT_INTEGER)
4911 || !kind_value_check (status, 2, gfc_default_integer_kind))
4912 return false;
4913
4914 if (!scalar_check (status, 2))
4915 return false;
4916
4917 return true;
4918 }
4919
4920
4921 bool
4922 gfc_check_ftell (gfc_expr *unit)
4923 {
4924 if (!type_check (unit, 0, BT_INTEGER))
4925 return false;
4926
4927 if (!scalar_check (unit, 0))
4928 return false;
4929
4930 return true;
4931 }
4932
4933
4934 bool
4935 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
4936 {
4937 if (!type_check (unit, 0, BT_INTEGER))
4938 return false;
4939
4940 if (!scalar_check (unit, 0))
4941 return false;
4942
4943 if (!type_check (offset, 1, BT_INTEGER))
4944 return false;
4945
4946 if (!scalar_check (offset, 1))
4947 return false;
4948
4949 return true;
4950 }
4951
4952
4953 bool
4954 gfc_check_stat (gfc_expr *name, gfc_expr *array)
4955 {
4956 if (!type_check (name, 0, BT_CHARACTER))
4957 return false;
4958 if (!kind_value_check (name, 0, gfc_default_character_kind))
4959 return false;
4960
4961 if (!type_check (array, 1, BT_INTEGER)
4962 || !kind_value_check (array, 1, gfc_default_integer_kind))
4963 return false;
4964
4965 if (!array_check (array, 1))
4966 return false;
4967
4968 return true;
4969 }
4970
4971
4972 bool
4973 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
4974 {
4975 if (!type_check (name, 0, BT_CHARACTER))
4976 return false;
4977 if (!kind_value_check (name, 0, gfc_default_character_kind))
4978 return false;
4979
4980 if (!type_check (array, 1, BT_INTEGER)
4981 || !kind_value_check (array, 1, gfc_default_integer_kind))
4982 return false;
4983
4984 if (!array_check (array, 1))
4985 return false;
4986
4987 if (status == NULL)
4988 return true;
4989
4990 if (!type_check (status, 2, BT_INTEGER)
4991 || !kind_value_check (array, 1, gfc_default_integer_kind))
4992 return false;
4993
4994 if (!scalar_check (status, 2))
4995 return false;
4996
4997 return true;
4998 }
4999
5000
5001 bool
5002 gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub)
5003 {
5004 mpz_t nelems;
5005
5006 if (flag_coarray == GFC_FCOARRAY_NONE)
5007 {
5008 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5009 return false;
5010 }
5011
5012 if (!coarray_check (coarray, 0))
5013 return false;
5014
5015 if (sub->rank != 1)
5016 {
5017 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
5018 gfc_current_intrinsic_arg[1]->name, &sub->where);
5019 return false;
5020 }
5021
5022 if (gfc_array_size (sub, &nelems))
5023 {
5024 int corank = gfc_get_corank (coarray);
5025
5026 if (mpz_cmp_ui (nelems, corank) != 0)
5027 {
5028 gfc_error ("The number of array elements of the SUB argument to "
5029 "IMAGE_INDEX at %L shall be %d (corank) not %d",
5030 &sub->where, corank, (int) mpz_get_si (nelems));
5031 mpz_clear (nelems);
5032 return false;
5033 }
5034 mpz_clear (nelems);
5035 }
5036
5037 return true;
5038 }
5039
5040
5041 bool
5042 gfc_check_num_images (gfc_expr *distance, gfc_expr *failed)
5043 {
5044 if (flag_coarray == GFC_FCOARRAY_NONE)
5045 {
5046 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5047 return false;
5048 }
5049
5050 if (distance)
5051 {
5052 if (!type_check (distance, 0, BT_INTEGER))
5053 return false;
5054
5055 if (!nonnegative_check ("DISTANCE", distance))
5056 return false;
5057
5058 if (!scalar_check (distance, 0))
5059 return false;
5060
5061 if (!gfc_notify_std (GFC_STD_F2008_TS, "DISTANCE= argument to "
5062 "NUM_IMAGES at %L", &distance->where))
5063 return false;
5064 }
5065
5066 if (failed)
5067 {
5068 if (!type_check (failed, 1, BT_LOGICAL))
5069 return false;
5070
5071 if (!scalar_check (failed, 1))
5072 return false;
5073
5074 if (!gfc_notify_std (GFC_STD_F2008_TS, "FAILED= argument to "
5075 "NUM_IMAGES at %L", &distance->where))
5076 return false;
5077 }
5078
5079 return true;
5080 }
5081
5082
5083 bool
5084 gfc_check_this_image (gfc_expr *coarray, gfc_expr *dim, gfc_expr *distance)
5085 {
5086 if (flag_coarray == GFC_FCOARRAY_NONE)
5087 {
5088 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5089 return false;
5090 }
5091
5092 if (coarray == NULL && dim == NULL && distance == NULL)
5093 return true;
5094
5095 if (dim != NULL && coarray == NULL)
5096 {
5097 gfc_error ("DIM argument without COARRAY argument not allowed for "
5098 "THIS_IMAGE intrinsic at %L", &dim->where);
5099 return false;
5100 }
5101
5102 if (distance && (coarray || dim))
5103 {
5104 gfc_error ("The DISTANCE argument may not be specified together with the "
5105 "COARRAY or DIM argument in intrinsic at %L",
5106 &distance->where);
5107 return false;
5108 }
5109
5110 /* Assume that we have "this_image (distance)". */
5111 if (coarray && !gfc_is_coarray (coarray) && coarray->ts.type == BT_INTEGER)
5112 {
5113 if (dim)
5114 {
5115 gfc_error ("Unexpected DIM argument with noncoarray argument at %L",
5116 &coarray->where);
5117 return false;
5118 }
5119 distance = coarray;
5120 }
5121
5122 if (distance)
5123 {
5124 if (!type_check (distance, 2, BT_INTEGER))
5125 return false;
5126
5127 if (!nonnegative_check ("DISTANCE", distance))
5128 return false;
5129
5130 if (!scalar_check (distance, 2))
5131 return false;
5132
5133 if (!gfc_notify_std (GFC_STD_F2008_TS, "DISTANCE= argument to "
5134 "THIS_IMAGE at %L", &distance->where))
5135 return false;
5136
5137 return true;
5138 }
5139
5140 if (!coarray_check (coarray, 0))
5141 return false;
5142
5143 if (dim != NULL)
5144 {
5145 if (!dim_check (dim, 1, false))
5146 return false;
5147
5148 if (!dim_corank_check (dim, coarray))
5149 return false;
5150 }
5151
5152 return true;
5153 }
5154
5155 /* Calculate the sizes for transfer, used by gfc_check_transfer and also
5156 by gfc_simplify_transfer. Return false if we cannot do so. */
5157
5158 bool
5159 gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size,
5160 size_t *source_size, size_t *result_size,
5161 size_t *result_length_p)
5162 {
5163 size_t result_elt_size;
5164
5165 if (source->expr_type == EXPR_FUNCTION)
5166 return false;
5167
5168 if (size && size->expr_type != EXPR_CONSTANT)
5169 return false;
5170
5171 /* Calculate the size of the source. */
5172 *source_size = gfc_target_expr_size (source);
5173 if (*source_size == 0)
5174 return false;
5175
5176 /* Determine the size of the element. */
5177 result_elt_size = gfc_element_size (mold);
5178 if (result_elt_size == 0)
5179 return false;
5180
5181 if (mold->expr_type == EXPR_ARRAY || mold->rank || size)
5182 {
5183 int result_length;
5184
5185 if (size)
5186 result_length = (size_t)mpz_get_ui (size->value.integer);
5187 else
5188 {
5189 result_length = *source_size / result_elt_size;
5190 if (result_length * result_elt_size < *source_size)
5191 result_length += 1;
5192 }
5193
5194 *result_size = result_length * result_elt_size;
5195 if (result_length_p)
5196 *result_length_p = result_length;
5197 }
5198 else
5199 *result_size = result_elt_size;
5200
5201 return true;
5202 }
5203
5204
5205 bool
5206 gfc_check_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size)
5207 {
5208 size_t source_size;
5209 size_t result_size;
5210
5211 if (mold->ts.type == BT_HOLLERITH)
5212 {
5213 gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L must not be"
5214 " %s", &mold->where, gfc_basic_typename (BT_HOLLERITH));
5215 return false;
5216 }
5217
5218 if (size != NULL)
5219 {
5220 if (!type_check (size, 2, BT_INTEGER))
5221 return false;
5222
5223 if (!scalar_check (size, 2))
5224 return false;
5225
5226 if (!nonoptional_check (size, 2))
5227 return false;
5228 }
5229
5230 if (!warn_surprising)
5231 return true;
5232
5233 /* If we can't calculate the sizes, we cannot check any more.
5234 Return true for that case. */
5235
5236 if (!gfc_calculate_transfer_sizes (source, mold, size, &source_size,
5237 &result_size, NULL))
5238 return true;
5239
5240 if (source_size < result_size)
5241 gfc_warning (OPT_Wsurprising,
5242 "Intrinsic TRANSFER at %L has partly undefined result: "
5243 "source size %ld < result size %ld", &source->where,
5244 (long) source_size, (long) result_size);
5245
5246 return true;
5247 }
5248
5249
5250 bool
5251 gfc_check_transpose (gfc_expr *matrix)
5252 {
5253 if (!rank_check (matrix, 0, 2))
5254 return false;
5255
5256 return true;
5257 }
5258
5259
5260 bool
5261 gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
5262 {
5263 if (!array_check (array, 0))
5264 return false;
5265
5266 if (!dim_check (dim, 1, false))
5267 return false;
5268
5269 if (!dim_rank_check (dim, array, 0))
5270 return false;
5271
5272 if (!kind_check (kind, 2, BT_INTEGER))
5273 return false;
5274 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
5275 "with KIND argument at %L",
5276 gfc_current_intrinsic, &kind->where))
5277 return false;
5278
5279 return true;
5280 }
5281
5282
5283 bool
5284 gfc_check_ucobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
5285 {
5286 if (flag_coarray == GFC_FCOARRAY_NONE)
5287 {
5288 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5289 return false;
5290 }
5291
5292 if (!coarray_check (coarray, 0))
5293 return false;
5294
5295 if (dim != NULL)
5296 {
5297 if (!dim_check (dim, 1, false))
5298 return false;
5299
5300 if (!dim_corank_check (dim, coarray))
5301 return false;
5302 }
5303
5304 if (!kind_check (kind, 2, BT_INTEGER))
5305 return false;
5306
5307 return true;
5308 }
5309
5310
5311 bool
5312 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
5313 {
5314 mpz_t vector_size;
5315
5316 if (!rank_check (vector, 0, 1))
5317 return false;
5318
5319 if (!array_check (mask, 1))
5320 return false;
5321
5322 if (!type_check (mask, 1, BT_LOGICAL))
5323 return false;
5324
5325 if (!same_type_check (vector, 0, field, 2))
5326 return false;
5327
5328 if (mask->expr_type == EXPR_ARRAY
5329 && gfc_array_size (vector, &vector_size))
5330 {
5331 int mask_true_count = 0;
5332 gfc_constructor *mask_ctor;
5333 mask_ctor = gfc_constructor_first (mask->value.constructor);
5334 while (mask_ctor)
5335 {
5336 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
5337 {
5338 mask_true_count = 0;
5339 break;
5340 }
5341
5342 if (mask_ctor->expr->value.logical)
5343 mask_true_count++;
5344
5345 mask_ctor = gfc_constructor_next (mask_ctor);
5346 }
5347
5348 if (mpz_get_si (vector_size) < mask_true_count)
5349 {
5350 gfc_error ("%qs argument of %qs intrinsic at %L must "
5351 "provide at least as many elements as there "
5352 "are .TRUE. values in %qs (%ld/%d)",
5353 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
5354 &vector->where, gfc_current_intrinsic_arg[1]->name,
5355 mpz_get_si (vector_size), mask_true_count);
5356 return false;
5357 }
5358
5359 mpz_clear (vector_size);
5360 }
5361
5362 if (mask->rank != field->rank && field->rank != 0)
5363 {
5364 gfc_error ("%qs argument of %qs intrinsic at %L must have "
5365 "the same rank as %qs or be a scalar",
5366 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
5367 &field->where, gfc_current_intrinsic_arg[1]->name);
5368 return false;
5369 }
5370
5371 if (mask->rank == field->rank)
5372 {
5373 int i;
5374 for (i = 0; i < field->rank; i++)
5375 if (! identical_dimen_shape (mask, i, field, i))
5376 {
5377 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L "
5378 "must have identical shape.",
5379 gfc_current_intrinsic_arg[2]->name,
5380 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
5381 &field->where);
5382 }
5383 }
5384
5385 return true;
5386 }
5387
5388
5389 bool
5390 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
5391 {
5392 if (!type_check (x, 0, BT_CHARACTER))
5393 return false;
5394
5395 if (!same_type_check (x, 0, y, 1))
5396 return false;
5397
5398 if (z != NULL && !type_check (z, 2, BT_LOGICAL))
5399 return false;
5400
5401 if (!kind_check (kind, 3, BT_INTEGER))
5402 return false;
5403 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
5404 "with KIND argument at %L",
5405 gfc_current_intrinsic, &kind->where))
5406 return false;
5407
5408 return true;
5409 }
5410
5411
5412 bool
5413 gfc_check_trim (gfc_expr *x)
5414 {
5415 if (!type_check (x, 0, BT_CHARACTER))
5416 return false;
5417
5418 if (!scalar_check (x, 0))
5419 return false;
5420
5421 return true;
5422 }
5423
5424
5425 bool
5426 gfc_check_ttynam (gfc_expr *unit)
5427 {
5428 if (!scalar_check (unit, 0))
5429 return false;
5430
5431 if (!type_check (unit, 0, BT_INTEGER))
5432 return false;
5433
5434 return true;
5435 }
5436
5437
5438 /* Common check function for the half a dozen intrinsics that have a
5439 single real argument. */
5440
5441 bool
5442 gfc_check_x (gfc_expr *x)
5443 {
5444 if (!type_check (x, 0, BT_REAL))
5445 return false;
5446
5447 return true;
5448 }
5449
5450
5451 /************* Check functions for intrinsic subroutines *************/
5452
5453 bool
5454 gfc_check_cpu_time (gfc_expr *time)
5455 {
5456 if (!scalar_check (time, 0))
5457 return false;
5458
5459 if (!type_check (time, 0, BT_REAL))
5460 return false;
5461
5462 if (!variable_check (time, 0, false))
5463 return false;
5464
5465 return true;
5466 }
5467
5468
5469 bool
5470 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
5471 gfc_expr *zone, gfc_expr *values)
5472 {
5473 if (date != NULL)
5474 {
5475 if (!type_check (date, 0, BT_CHARACTER))
5476 return false;
5477 if (!kind_value_check (date, 0, gfc_default_character_kind))
5478 return false;
5479 if (!scalar_check (date, 0))
5480 return false;
5481 if (!variable_check (date, 0, false))
5482 return false;
5483 }
5484
5485 if (time != NULL)
5486 {
5487 if (!type_check (time, 1, BT_CHARACTER))
5488 return false;
5489 if (!kind_value_check (time, 1, gfc_default_character_kind))
5490 return false;
5491 if (!scalar_check (time, 1))
5492 return false;
5493 if (!variable_check (time, 1, false))
5494 return false;
5495 }
5496
5497 if (zone != NULL)
5498 {
5499 if (!type_check (zone, 2, BT_CHARACTER))
5500 return false;
5501 if (!kind_value_check (zone, 2, gfc_default_character_kind))
5502 return false;
5503 if (!scalar_check (zone, 2))
5504 return false;
5505 if (!variable_check (zone, 2, false))
5506 return false;
5507 }
5508
5509 if (values != NULL)
5510 {
5511 if (!type_check (values, 3, BT_INTEGER))
5512 return false;
5513 if (!array_check (values, 3))
5514 return false;
5515 if (!rank_check (values, 3, 1))
5516 return false;
5517 if (!variable_check (values, 3, false))
5518 return false;
5519 }
5520
5521 return true;
5522 }
5523
5524
5525 bool
5526 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
5527 gfc_expr *to, gfc_expr *topos)
5528 {
5529 if (!type_check (from, 0, BT_INTEGER))
5530 return false;
5531
5532 if (!type_check (frompos, 1, BT_INTEGER))
5533 return false;
5534
5535 if (!type_check (len, 2, BT_INTEGER))
5536 return false;
5537
5538 if (!same_type_check (from, 0, to, 3))
5539 return false;
5540
5541 if (!variable_check (to, 3, false))
5542 return false;
5543
5544 if (!type_check (topos, 4, BT_INTEGER))
5545 return false;
5546
5547 if (!nonnegative_check ("frompos", frompos))
5548 return false;
5549
5550 if (!nonnegative_check ("topos", topos))
5551 return false;
5552
5553 if (!nonnegative_check ("len", len))
5554 return false;
5555
5556 if (!less_than_bitsize2 ("from", from, "frompos", frompos, "len", len))
5557 return false;
5558
5559 if (!less_than_bitsize2 ("to", to, "topos", topos, "len", len))
5560 return false;
5561
5562 return true;
5563 }
5564
5565
5566 bool
5567 gfc_check_random_number (gfc_expr *harvest)
5568 {
5569 if (!type_check (harvest, 0, BT_REAL))
5570 return false;
5571
5572 if (!variable_check (harvest, 0, false))
5573 return false;
5574
5575 return true;
5576 }
5577
5578
5579 bool
5580 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
5581 {
5582 unsigned int nargs = 0, seed_size;
5583 locus *where = NULL;
5584 mpz_t put_size, get_size;
5585
5586 /* Keep the number of bytes in sync with master_state in
5587 libgfortran/intrinsics/random.c. +1 due to the integer p which is
5588 part of the state too. */
5589 seed_size = 128 / gfc_default_integer_kind + 1;
5590
5591 if (size != NULL)
5592 {
5593 if (size->expr_type != EXPR_VARIABLE
5594 || !size->symtree->n.sym->attr.optional)
5595 nargs++;
5596
5597 if (!scalar_check (size, 0))
5598 return false;
5599
5600 if (!type_check (size, 0, BT_INTEGER))
5601 return false;
5602
5603 if (!variable_check (size, 0, false))
5604 return false;
5605
5606 if (!kind_value_check (size, 0, gfc_default_integer_kind))
5607 return false;
5608 }
5609
5610 if (put != NULL)
5611 {
5612 if (put->expr_type != EXPR_VARIABLE
5613 || !put->symtree->n.sym->attr.optional)
5614 {
5615 nargs++;
5616 where = &put->where;
5617 }
5618
5619 if (!array_check (put, 1))
5620 return false;
5621
5622 if (!rank_check (put, 1, 1))
5623 return false;
5624
5625 if (!type_check (put, 1, BT_INTEGER))
5626 return false;
5627
5628 if (!kind_value_check (put, 1, gfc_default_integer_kind))
5629 return false;
5630
5631 if (gfc_array_size (put, &put_size)
5632 && mpz_get_ui (put_size) < seed_size)
5633 gfc_error ("Size of %qs argument of %qs intrinsic at %L "
5634 "too small (%i/%i)",
5635 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
5636 where, (int) mpz_get_ui (put_size), seed_size);
5637 }
5638
5639 if (get != NULL)
5640 {
5641 if (get->expr_type != EXPR_VARIABLE
5642 || !get->symtree->n.sym->attr.optional)
5643 {
5644 nargs++;
5645 where = &get->where;
5646 }
5647
5648 if (!array_check (get, 2))
5649 return false;
5650
5651 if (!rank_check (get, 2, 1))
5652 return false;
5653
5654 if (!type_check (get, 2, BT_INTEGER))
5655 return false;
5656
5657 if (!variable_check (get, 2, false))
5658 return false;
5659
5660 if (!kind_value_check (get, 2, gfc_default_integer_kind))
5661 return false;
5662
5663 if (gfc_array_size (get, &get_size)
5664 && mpz_get_ui (get_size) < seed_size)
5665 gfc_error ("Size of %qs argument of %qs intrinsic at %L "
5666 "too small (%i/%i)",
5667 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
5668 where, (int) mpz_get_ui (get_size), seed_size);
5669 }
5670
5671 /* RANDOM_SEED may not have more than one non-optional argument. */
5672 if (nargs > 1)
5673 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
5674
5675 return true;
5676 }
5677
5678 bool
5679 gfc_check_fe_runtime_error (gfc_actual_arglist *a)
5680 {
5681 gfc_expr *e;
5682 int len, i;
5683 int num_percent, nargs;
5684
5685 e = a->expr;
5686 if (e->expr_type != EXPR_CONSTANT)
5687 return true;
5688
5689 len = e->value.character.length;
5690 if (e->value.character.string[len-1] != '\0')
5691 gfc_internal_error ("fe_runtime_error string must be null terminated");
5692
5693 num_percent = 0;
5694 for (i=0; i<len-1; i++)
5695 if (e->value.character.string[i] == '%')
5696 num_percent ++;
5697
5698 nargs = 0;
5699 for (; a; a = a->next)
5700 nargs ++;
5701
5702 if (nargs -1 != num_percent)
5703 gfc_internal_error ("fe_runtime_error: Wrong number of arguments (%d instead of %d)",
5704 nargs, num_percent++);
5705
5706 return true;
5707 }
5708
5709 bool
5710 gfc_check_second_sub (gfc_expr *time)
5711 {
5712 if (!scalar_check (time, 0))
5713 return false;
5714
5715 if (!type_check (time, 0, BT_REAL))
5716 return false;
5717
5718 if (!kind_value_check (time, 0, 4))
5719 return false;
5720
5721 return true;
5722 }
5723
5724
5725 /* COUNT and COUNT_MAX of SYSTEM_CLOCK are scalar, default-kind integer
5726 variables in Fortran 95. In Fortran 2003 and later, they can be of any
5727 kind, and COUNT_RATE can be of type real. Note, count, count_rate, and
5728 count_max are all optional arguments */
5729
5730 bool
5731 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
5732 gfc_expr *count_max)
5733 {
5734 if (count != NULL)
5735 {
5736 if (!scalar_check (count, 0))
5737 return false;
5738
5739 if (!type_check (count, 0, BT_INTEGER))
5740 return false;
5741
5742 if (count->ts.kind != gfc_default_integer_kind
5743 && !gfc_notify_std (GFC_STD_F2003, "COUNT argument to "
5744 "SYSTEM_CLOCK at %L has non-default kind",
5745 &count->where))
5746 return false;
5747
5748 if (!variable_check (count, 0, false))
5749 return false;
5750 }
5751
5752 if (count_rate != NULL)
5753 {
5754 if (!scalar_check (count_rate, 1))
5755 return false;
5756
5757 if (!variable_check (count_rate, 1, false))
5758 return false;
5759
5760 if (count_rate->ts.type == BT_REAL)
5761 {
5762 if (!gfc_notify_std (GFC_STD_F2003, "Real COUNT_RATE argument to "
5763 "SYSTEM_CLOCK at %L", &count_rate->where))
5764 return false;
5765 }
5766 else
5767 {
5768 if (!type_check (count_rate, 1, BT_INTEGER))
5769 return false;
5770
5771 if (count_rate->ts.kind != gfc_default_integer_kind
5772 && !gfc_notify_std (GFC_STD_F2003, "COUNT_RATE argument to "
5773 "SYSTEM_CLOCK at %L has non-default kind",
5774 &count_rate->where))
5775 return false;
5776 }
5777
5778 }
5779
5780 if (count_max != NULL)
5781 {
5782 if (!scalar_check (count_max, 2))
5783 return false;
5784
5785 if (!type_check (count_max, 2, BT_INTEGER))
5786 return false;
5787
5788 if (count_max->ts.kind != gfc_default_integer_kind
5789 && !gfc_notify_std (GFC_STD_F2003, "COUNT_MAX argument to "
5790 "SYSTEM_CLOCK at %L has non-default kind",
5791 &count_max->where))
5792 return false;
5793
5794 if (!variable_check (count_max, 2, false))
5795 return false;
5796 }
5797
5798 return true;
5799 }
5800
5801
5802 bool
5803 gfc_check_irand (gfc_expr *x)
5804 {
5805 if (x == NULL)
5806 return true;
5807
5808 if (!scalar_check (x, 0))
5809 return false;
5810
5811 if (!type_check (x, 0, BT_INTEGER))
5812 return false;
5813
5814 if (!kind_value_check (x, 0, 4))
5815 return false;
5816
5817 return true;
5818 }
5819
5820
5821 bool
5822 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
5823 {
5824 if (!scalar_check (seconds, 0))
5825 return false;
5826 if (!type_check (seconds, 0, BT_INTEGER))
5827 return false;
5828
5829 if (!int_or_proc_check (handler, 1))
5830 return false;
5831 if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
5832 return false;
5833
5834 if (status == NULL)
5835 return true;
5836
5837 if (!scalar_check (status, 2))
5838 return false;
5839 if (!type_check (status, 2, BT_INTEGER))
5840 return false;
5841 if (!kind_value_check (status, 2, gfc_default_integer_kind))
5842 return false;
5843
5844 return true;
5845 }
5846
5847
5848 bool
5849 gfc_check_rand (gfc_expr *x)
5850 {
5851 if (x == NULL)
5852 return true;
5853
5854 if (!scalar_check (x, 0))
5855 return false;
5856
5857 if (!type_check (x, 0, BT_INTEGER))
5858 return false;
5859
5860 if (!kind_value_check (x, 0, 4))
5861 return false;
5862
5863 return true;
5864 }
5865
5866
5867 bool
5868 gfc_check_srand (gfc_expr *x)
5869 {
5870 if (!scalar_check (x, 0))
5871 return false;
5872
5873 if (!type_check (x, 0, BT_INTEGER))
5874 return false;
5875
5876 if (!kind_value_check (x, 0, 4))
5877 return false;
5878
5879 return true;
5880 }
5881
5882
5883 bool
5884 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
5885 {
5886 if (!scalar_check (time, 0))
5887 return false;
5888 if (!type_check (time, 0, BT_INTEGER))
5889 return false;
5890
5891 if (!type_check (result, 1, BT_CHARACTER))
5892 return false;
5893 if (!kind_value_check (result, 1, gfc_default_character_kind))
5894 return false;
5895
5896 return true;
5897 }
5898
5899
5900 bool
5901 gfc_check_dtime_etime (gfc_expr *x)
5902 {
5903 if (!array_check (x, 0))
5904 return false;
5905
5906 if (!rank_check (x, 0, 1))
5907 return false;
5908
5909 if (!variable_check (x, 0, false))
5910 return false;
5911
5912 if (!type_check (x, 0, BT_REAL))
5913 return false;
5914
5915 if (!kind_value_check (x, 0, 4))
5916 return false;
5917
5918 return true;
5919 }
5920
5921
5922 bool
5923 gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
5924 {
5925 if (!array_check (values, 0))
5926 return false;
5927
5928 if (!rank_check (values, 0, 1))
5929 return false;
5930
5931 if (!variable_check (values, 0, false))
5932 return false;
5933
5934 if (!type_check (values, 0, BT_REAL))
5935 return false;
5936
5937 if (!kind_value_check (values, 0, 4))
5938 return false;
5939
5940 if (!scalar_check (time, 1))
5941 return false;
5942
5943 if (!type_check (time, 1, BT_REAL))
5944 return false;
5945
5946 if (!kind_value_check (time, 1, 4))
5947 return false;
5948
5949 return true;
5950 }
5951
5952
5953 bool
5954 gfc_check_fdate_sub (gfc_expr *date)
5955 {
5956 if (!type_check (date, 0, BT_CHARACTER))
5957 return false;
5958 if (!kind_value_check (date, 0, gfc_default_character_kind))
5959 return false;
5960
5961 return true;
5962 }
5963
5964
5965 bool
5966 gfc_check_gerror (gfc_expr *msg)
5967 {
5968 if (!type_check (msg, 0, BT_CHARACTER))
5969 return false;
5970 if (!kind_value_check (msg, 0, gfc_default_character_kind))
5971 return false;
5972
5973 return true;
5974 }
5975
5976
5977 bool
5978 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
5979 {
5980 if (!type_check (cwd, 0, BT_CHARACTER))
5981 return false;
5982 if (!kind_value_check (cwd, 0, gfc_default_character_kind))
5983 return false;
5984
5985 if (status == NULL)
5986 return true;
5987
5988 if (!scalar_check (status, 1))
5989 return false;
5990
5991 if (!type_check (status, 1, BT_INTEGER))
5992 return false;
5993
5994 return true;
5995 }
5996
5997
5998 bool
5999 gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
6000 {
6001 if (!type_check (pos, 0, BT_INTEGER))
6002 return false;
6003
6004 if (pos->ts.kind > gfc_default_integer_kind)
6005 {
6006 gfc_error ("%qs argument of %qs intrinsic at %L must be of a kind "
6007 "not wider than the default kind (%d)",
6008 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
6009 &pos->where, gfc_default_integer_kind);
6010 return false;
6011 }
6012
6013 if (!type_check (value, 1, BT_CHARACTER))
6014 return false;
6015 if (!kind_value_check (value, 1, gfc_default_character_kind))
6016 return false;
6017
6018 return true;
6019 }
6020
6021
6022 bool
6023 gfc_check_getlog (gfc_expr *msg)
6024 {
6025 if (!type_check (msg, 0, BT_CHARACTER))
6026 return false;
6027 if (!kind_value_check (msg, 0, gfc_default_character_kind))
6028 return false;
6029
6030 return true;
6031 }
6032
6033
6034 bool
6035 gfc_check_exit (gfc_expr *status)
6036 {
6037 if (status == NULL)
6038 return true;
6039
6040 if (!type_check (status, 0, BT_INTEGER))
6041 return false;
6042
6043 if (!scalar_check (status, 0))
6044 return false;
6045
6046 return true;
6047 }
6048
6049
6050 bool
6051 gfc_check_flush (gfc_expr *unit)
6052 {
6053 if (unit == NULL)
6054 return true;
6055
6056 if (!type_check (unit, 0, BT_INTEGER))
6057 return false;
6058
6059 if (!scalar_check (unit, 0))
6060 return false;
6061
6062 return true;
6063 }
6064
6065
6066 bool
6067 gfc_check_free (gfc_expr *i)
6068 {
6069 if (!type_check (i, 0, BT_INTEGER))
6070 return false;
6071
6072 if (!scalar_check (i, 0))
6073 return false;
6074
6075 return true;
6076 }
6077
6078
6079 bool
6080 gfc_check_hostnm (gfc_expr *name)
6081 {
6082 if (!type_check (name, 0, BT_CHARACTER))
6083 return false;
6084 if (!kind_value_check (name, 0, gfc_default_character_kind))
6085 return false;
6086
6087 return true;
6088 }
6089
6090
6091 bool
6092 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
6093 {
6094 if (!type_check (name, 0, BT_CHARACTER))
6095 return false;
6096 if (!kind_value_check (name, 0, gfc_default_character_kind))
6097 return false;
6098
6099 if (status == NULL)
6100 return true;
6101
6102 if (!scalar_check (status, 1))
6103 return false;
6104
6105 if (!type_check (status, 1, BT_INTEGER))
6106 return false;
6107
6108 return true;
6109 }
6110
6111
6112 bool
6113 gfc_check_itime_idate (gfc_expr *values)
6114 {
6115 if (!array_check (values, 0))
6116 return false;
6117
6118 if (!rank_check (values, 0, 1))
6119 return false;
6120
6121 if (!variable_check (values, 0, false))
6122 return false;
6123
6124 if (!type_check (values, 0, BT_INTEGER))
6125 return false;
6126
6127 if (!kind_value_check (values, 0, gfc_default_integer_kind))
6128 return false;
6129
6130 return true;
6131 }
6132
6133
6134 bool
6135 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
6136 {
6137 if (!type_check (time, 0, BT_INTEGER))
6138 return false;
6139
6140 if (!kind_value_check (time, 0, gfc_default_integer_kind))
6141 return false;
6142
6143 if (!scalar_check (time, 0))
6144 return false;
6145
6146 if (!array_check (values, 1))
6147 return false;
6148
6149 if (!rank_check (values, 1, 1))
6150 return false;
6151
6152 if (!variable_check (values, 1, false))
6153 return false;
6154
6155 if (!type_check (values, 1, BT_INTEGER))
6156 return false;
6157
6158 if (!kind_value_check (values, 1, gfc_default_integer_kind))
6159 return false;
6160
6161 return true;
6162 }
6163
6164
6165 bool
6166 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
6167 {
6168 if (!scalar_check (unit, 0))
6169 return false;
6170
6171 if (!type_check (unit, 0, BT_INTEGER))
6172 return false;
6173
6174 if (!type_check (name, 1, BT_CHARACTER))
6175 return false;
6176 if (!kind_value_check (name, 1, gfc_default_character_kind))
6177 return false;
6178
6179 return true;
6180 }
6181
6182
6183 bool
6184 gfc_check_isatty (gfc_expr *unit)
6185 {
6186 if (unit == NULL)
6187 return false;
6188
6189 if (!type_check (unit, 0, BT_INTEGER))
6190 return false;
6191
6192 if (!scalar_check (unit, 0))
6193 return false;
6194
6195 return true;
6196 }
6197
6198
6199 bool
6200 gfc_check_isnan (gfc_expr *x)
6201 {
6202 if (!type_check (x, 0, BT_REAL))
6203 return false;
6204
6205 return true;
6206 }
6207
6208
6209 bool
6210 gfc_check_perror (gfc_expr *string)
6211 {
6212 if (!type_check (string, 0, BT_CHARACTER))
6213 return false;
6214 if (!kind_value_check (string, 0, gfc_default_character_kind))
6215 return false;
6216
6217 return true;
6218 }
6219
6220
6221 bool
6222 gfc_check_umask (gfc_expr *mask)
6223 {
6224 if (!type_check (mask, 0, BT_INTEGER))
6225 return false;
6226
6227 if (!scalar_check (mask, 0))
6228 return false;
6229
6230 return true;
6231 }
6232
6233
6234 bool
6235 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
6236 {
6237 if (!type_check (mask, 0, BT_INTEGER))
6238 return false;
6239
6240 if (!scalar_check (mask, 0))
6241 return false;
6242
6243 if (old == NULL)
6244 return true;
6245
6246 if (!scalar_check (old, 1))
6247 return false;
6248
6249 if (!type_check (old, 1, BT_INTEGER))
6250 return false;
6251
6252 return true;
6253 }
6254
6255
6256 bool
6257 gfc_check_unlink (gfc_expr *name)
6258 {
6259 if (!type_check (name, 0, BT_CHARACTER))
6260 return false;
6261 if (!kind_value_check (name, 0, gfc_default_character_kind))
6262 return false;
6263
6264 return true;
6265 }
6266
6267
6268 bool
6269 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
6270 {
6271 if (!type_check (name, 0, BT_CHARACTER))
6272 return false;
6273 if (!kind_value_check (name, 0, gfc_default_character_kind))
6274 return false;
6275
6276 if (status == NULL)
6277 return true;
6278
6279 if (!scalar_check (status, 1))
6280 return false;
6281
6282 if (!type_check (status, 1, BT_INTEGER))
6283 return false;
6284
6285 return true;
6286 }
6287
6288
6289 bool
6290 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
6291 {
6292 if (!scalar_check (number, 0))
6293 return false;
6294 if (!type_check (number, 0, BT_INTEGER))
6295 return false;
6296
6297 if (!int_or_proc_check (handler, 1))
6298 return false;
6299 if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
6300 return false;
6301
6302 return true;
6303 }
6304
6305
6306 bool
6307 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
6308 {
6309 if (!scalar_check (number, 0))
6310 return false;
6311 if (!type_check (number, 0, BT_INTEGER))
6312 return false;
6313
6314 if (!int_or_proc_check (handler, 1))
6315 return false;
6316 if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
6317 return false;
6318
6319 if (status == NULL)
6320 return true;
6321
6322 if (!type_check (status, 2, BT_INTEGER))
6323 return false;
6324 if (!scalar_check (status, 2))
6325 return false;
6326
6327 return true;
6328 }
6329
6330
6331 bool
6332 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
6333 {
6334 if (!type_check (cmd, 0, BT_CHARACTER))
6335 return false;
6336 if (!kind_value_check (cmd, 0, gfc_default_character_kind))
6337 return false;
6338
6339 if (!scalar_check (status, 1))
6340 return false;
6341
6342 if (!type_check (status, 1, BT_INTEGER))
6343 return false;
6344
6345 if (!kind_value_check (status, 1, gfc_default_integer_kind))
6346 return false;
6347
6348 return true;
6349 }
6350
6351
6352 /* This is used for the GNU intrinsics AND, OR and XOR. */
6353 bool
6354 gfc_check_and (gfc_expr *i, gfc_expr *j)
6355 {
6356 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
6357 {
6358 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
6359 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
6360 gfc_current_intrinsic, &i->where);
6361 return false;
6362 }
6363
6364 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
6365 {
6366 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
6367 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
6368 gfc_current_intrinsic, &j->where);
6369 return false;
6370 }
6371
6372 if (i->ts.type != j->ts.type)
6373 {
6374 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
6375 "have the same type", gfc_current_intrinsic_arg[0]->name,
6376 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
6377 &j->where);
6378 return false;
6379 }
6380
6381 if (!scalar_check (i, 0))
6382 return false;
6383
6384 if (!scalar_check (j, 1))
6385 return false;
6386
6387 return true;
6388 }
6389
6390
6391 bool
6392 gfc_check_storage_size (gfc_expr *a, gfc_expr *kind)
6393 {
6394
6395 if (a->expr_type == EXPR_NULL)
6396 {
6397 gfc_error ("Intrinsic function NULL at %L cannot be an actual "
6398 "argument to STORAGE_SIZE, because it returns a "
6399 "disassociated pointer", &a->where);
6400 return false;
6401 }
6402
6403 if (a->ts.type == BT_ASSUMED)
6404 {
6405 gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
6406 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
6407 &a->where);
6408 return false;
6409 }
6410
6411 if (a->ts.type == BT_PROCEDURE)
6412 {
6413 gfc_error ("%qs argument of %qs intrinsic at %L shall not be a "
6414 "procedure", gfc_current_intrinsic_arg[0]->name,
6415 gfc_current_intrinsic, &a->where);
6416 return false;
6417 }
6418
6419 if (kind == NULL)
6420 return true;
6421
6422 if (!type_check (kind, 1, BT_INTEGER))
6423 return false;
6424
6425 if (!scalar_check (kind, 1))
6426 return false;
6427
6428 if (kind->expr_type != EXPR_CONSTANT)
6429 {
6430 gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
6431 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
6432 &kind->where);
6433 return false;
6434 }
6435
6436 return true;
6437 }