Fix memory leak in tree-vect-slp.c
[official-gcc.git] / gcc / fortran / check.c
blobd26e45ec406d6c595188569aa19748fa36eb9742
1 /* Check functions
2 Copyright (C) 2002-2016 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Katherine Holcomb
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 /* 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. */
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"
38 /* Make sure an expression is a scalar. */
40 static bool
41 scalar_check (gfc_expr *e, int n)
43 if (e->rank == 0)
44 return true;
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);
50 return false;
54 /* Check the type of an expression. */
56 static bool
57 type_check (gfc_expr *e, int n, bt type)
59 if (e->ts.type == type)
60 return true;
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));
66 return false;
70 /* Check that the expression is a numeric type. */
72 static bool
73 numeric_check (gfc_expr *e, int n)
75 if (gfc_numeric_ts (&e->ts))
76 return true;
78 /* If the expression has not got a type, check if its namespace can
79 offer a default type. */
80 if ((e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_FUNCTION)
81 && e->symtree->n.sym->ts.type == BT_UNKNOWN
82 && gfc_set_default_type (e->symtree->n.sym, 0, e->symtree->n.sym->ns)
83 && gfc_numeric_ts (&e->symtree->n.sym->ts))
85 e->ts = e->symtree->n.sym->ts;
86 return true;
89 gfc_error ("%qs argument of %qs intrinsic at %L must be a numeric type",
90 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
91 &e->where);
93 return false;
97 /* Check that an expression is integer or real. */
99 static bool
100 int_or_real_check (gfc_expr *e, int n)
102 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
104 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
105 "or REAL", gfc_current_intrinsic_arg[n]->name,
106 gfc_current_intrinsic, &e->where);
107 return false;
110 return true;
114 /* Check that an expression is real or complex. */
116 static bool
117 real_or_complex_check (gfc_expr *e, int n)
119 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
121 gfc_error ("%qs argument of %qs intrinsic at %L must be REAL "
122 "or COMPLEX", gfc_current_intrinsic_arg[n]->name,
123 gfc_current_intrinsic, &e->where);
124 return false;
127 return true;
131 /* Check that an expression is INTEGER or PROCEDURE. */
133 static bool
134 int_or_proc_check (gfc_expr *e, int n)
136 if (e->ts.type != BT_INTEGER && e->ts.type != BT_PROCEDURE)
138 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
139 "or PROCEDURE", gfc_current_intrinsic_arg[n]->name,
140 gfc_current_intrinsic, &e->where);
141 return false;
144 return true;
148 /* Check that the expression is an optional constant integer
149 and that it specifies a valid kind for that type. */
151 static bool
152 kind_check (gfc_expr *k, int n, bt type)
154 int kind;
156 if (k == NULL)
157 return true;
159 if (!type_check (k, n, BT_INTEGER))
160 return false;
162 if (!scalar_check (k, n))
163 return false;
165 if (!gfc_check_init_expr (k))
167 gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
168 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
169 &k->where);
170 return false;
173 if (gfc_extract_int (k, &kind) != NULL
174 || gfc_validate_kind (type, kind, true) < 0)
176 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
177 &k->where);
178 return false;
181 return true;
185 /* Make sure the expression is a double precision real. */
187 static bool
188 double_check (gfc_expr *d, int n)
190 if (!type_check (d, n, BT_REAL))
191 return false;
193 if (d->ts.kind != gfc_default_double_kind)
195 gfc_error ("%qs argument of %qs intrinsic at %L must be double "
196 "precision", gfc_current_intrinsic_arg[n]->name,
197 gfc_current_intrinsic, &d->where);
198 return false;
201 return true;
205 static bool
206 coarray_check (gfc_expr *e, int n)
208 if (e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok
209 && CLASS_DATA (e)->attr.codimension
210 && CLASS_DATA (e)->as->corank)
212 gfc_add_class_array_ref (e);
213 return true;
216 if (!gfc_is_coarray (e))
218 gfc_error ("Expected coarray variable as %qs argument to the %s "
219 "intrinsic at %L", gfc_current_intrinsic_arg[n]->name,
220 gfc_current_intrinsic, &e->where);
221 return false;
224 return true;
228 /* Make sure the expression is a logical array. */
230 static bool
231 logical_array_check (gfc_expr *array, int n)
233 if (array->ts.type != BT_LOGICAL || array->rank == 0)
235 gfc_error ("%qs argument of %qs intrinsic at %L must be a logical "
236 "array", gfc_current_intrinsic_arg[n]->name,
237 gfc_current_intrinsic, &array->where);
238 return false;
241 return true;
245 /* Make sure an expression is an array. */
247 static bool
248 array_check (gfc_expr *e, int n)
250 if (e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok
251 && CLASS_DATA (e)->attr.dimension
252 && CLASS_DATA (e)->as->rank)
254 gfc_add_class_array_ref (e);
255 return true;
258 if (e->rank != 0 && e->ts.type != BT_PROCEDURE)
259 return true;
261 gfc_error ("%qs argument of %qs intrinsic at %L must be an array",
262 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
263 &e->where);
265 return false;
269 /* If expr is a constant, then check to ensure that it is greater than
270 of equal to zero. */
272 static bool
273 nonnegative_check (const char *arg, gfc_expr *expr)
275 int i;
277 if (expr->expr_type == EXPR_CONSTANT)
279 gfc_extract_int (expr, &i);
280 if (i < 0)
282 gfc_error ("%qs at %L must be nonnegative", arg, &expr->where);
283 return false;
287 return true;
291 /* If expr2 is constant, then check that the value is less than
292 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
294 static bool
295 less_than_bitsize1 (const char *arg1, gfc_expr *expr1, const char *arg2,
296 gfc_expr *expr2, bool or_equal)
298 int i2, i3;
300 if (expr2->expr_type == EXPR_CONSTANT)
302 gfc_extract_int (expr2, &i2);
303 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
305 /* For ISHFT[C], check that |shift| <= bit_size(i). */
306 if (arg2 == NULL)
308 if (i2 < 0)
309 i2 = -i2;
311 if (i2 > gfc_integer_kinds[i3].bit_size)
313 gfc_error ("The absolute value of SHIFT at %L must be less "
314 "than or equal to BIT_SIZE(%qs)",
315 &expr2->where, arg1);
316 return false;
320 if (or_equal)
322 if (i2 > gfc_integer_kinds[i3].bit_size)
324 gfc_error ("%qs at %L must be less than "
325 "or equal to BIT_SIZE(%qs)",
326 arg2, &expr2->where, arg1);
327 return false;
330 else
332 if (i2 >= gfc_integer_kinds[i3].bit_size)
334 gfc_error ("%qs at %L must be less than BIT_SIZE(%qs)",
335 arg2, &expr2->where, arg1);
336 return false;
341 return true;
345 /* If expr is constant, then check that the value is less than or equal
346 to the bit_size of the kind k. */
348 static bool
349 less_than_bitsizekind (const char *arg, gfc_expr *expr, int k)
351 int i, val;
353 if (expr->expr_type != EXPR_CONSTANT)
354 return true;
356 i = gfc_validate_kind (BT_INTEGER, k, false);
357 gfc_extract_int (expr, &val);
359 if (val > gfc_integer_kinds[i].bit_size)
361 gfc_error ("%qs at %L must be less than or equal to the BIT_SIZE of "
362 "INTEGER(KIND=%d)", arg, &expr->where, k);
363 return false;
366 return true;
370 /* If expr2 and expr3 are constants, then check that the value is less than
371 or equal to bit_size(expr1). */
373 static bool
374 less_than_bitsize2 (const char *arg1, gfc_expr *expr1, const char *arg2,
375 gfc_expr *expr2, const char *arg3, gfc_expr *expr3)
377 int i2, i3;
379 if (expr2->expr_type == EXPR_CONSTANT && expr3->expr_type == EXPR_CONSTANT)
381 gfc_extract_int (expr2, &i2);
382 gfc_extract_int (expr3, &i3);
383 i2 += i3;
384 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
385 if (i2 > gfc_integer_kinds[i3].bit_size)
387 gfc_error ("%<%s + %s%> at %L must be less than or equal "
388 "to BIT_SIZE(%qs)",
389 arg2, arg3, &expr2->where, arg1);
390 return false;
394 return true;
397 /* Make sure two expressions have the same type. */
399 static bool
400 same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
402 gfc_typespec *ets = &e->ts;
403 gfc_typespec *fts = &f->ts;
405 if (e->ts.type == BT_PROCEDURE && e->symtree->n.sym)
406 ets = &e->symtree->n.sym->ts;
407 if (f->ts.type == BT_PROCEDURE && f->symtree->n.sym)
408 fts = &f->symtree->n.sym->ts;
410 if (gfc_compare_types (ets, fts))
411 return true;
413 gfc_error ("%qs argument of %qs intrinsic at %L must be the same type "
414 "and kind as %qs", gfc_current_intrinsic_arg[m]->name,
415 gfc_current_intrinsic, &f->where,
416 gfc_current_intrinsic_arg[n]->name);
418 return false;
422 /* Make sure that an expression has a certain (nonzero) rank. */
424 static bool
425 rank_check (gfc_expr *e, int n, int rank)
427 if (e->rank == rank)
428 return true;
430 gfc_error ("%qs argument of %qs intrinsic at %L must be of rank %d",
431 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
432 &e->where, rank);
434 return false;
438 /* Make sure a variable expression is not an optional dummy argument. */
440 static bool
441 nonoptional_check (gfc_expr *e, int n)
443 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
445 gfc_error ("%qs argument of %qs intrinsic at %L must not be OPTIONAL",
446 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
447 &e->where);
450 /* TODO: Recursive check on nonoptional variables? */
452 return true;
456 /* Check for ALLOCATABLE attribute. */
458 static bool
459 allocatable_check (gfc_expr *e, int n)
461 symbol_attribute attr;
463 attr = gfc_variable_attr (e, NULL);
464 if (!attr.allocatable || attr.associate_var)
466 gfc_error ("%qs argument of %qs intrinsic at %L must be ALLOCATABLE",
467 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
468 &e->where);
469 return false;
472 return true;
476 /* Check that an expression has a particular kind. */
478 static bool
479 kind_value_check (gfc_expr *e, int n, int k)
481 if (e->ts.kind == k)
482 return true;
484 gfc_error ("%qs argument of %qs intrinsic at %L must be of kind %d",
485 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
486 &e->where, k);
488 return false;
492 /* Make sure an expression is a variable. */
494 static bool
495 variable_check (gfc_expr *e, int n, bool allow_proc)
497 if (e->expr_type == EXPR_VARIABLE
498 && e->symtree->n.sym->attr.intent == INTENT_IN
499 && (gfc_current_intrinsic_arg[n]->intent == INTENT_OUT
500 || gfc_current_intrinsic_arg[n]->intent == INTENT_INOUT))
502 gfc_ref *ref;
503 bool pointer = e->symtree->n.sym->ts.type == BT_CLASS
504 && CLASS_DATA (e->symtree->n.sym)
505 ? CLASS_DATA (e->symtree->n.sym)->attr.class_pointer
506 : e->symtree->n.sym->attr.pointer;
508 for (ref = e->ref; ref; ref = ref->next)
510 if (pointer && ref->type == REF_COMPONENT)
511 break;
512 if (ref->type == REF_COMPONENT
513 && ((ref->u.c.component->ts.type == BT_CLASS
514 && CLASS_DATA (ref->u.c.component)->attr.class_pointer)
515 || (ref->u.c.component->ts.type != BT_CLASS
516 && ref->u.c.component->attr.pointer)))
517 break;
520 if (!ref)
522 gfc_error ("%qs argument of %qs intrinsic at %L cannot be "
523 "INTENT(IN)", gfc_current_intrinsic_arg[n]->name,
524 gfc_current_intrinsic, &e->where);
525 return false;
529 if (e->expr_type == EXPR_VARIABLE
530 && e->symtree->n.sym->attr.flavor != FL_PARAMETER
531 && (allow_proc || !e->symtree->n.sym->attr.function))
532 return true;
534 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.function
535 && e->symtree->n.sym == e->symtree->n.sym->result)
537 gfc_namespace *ns;
538 for (ns = gfc_current_ns; ns; ns = ns->parent)
539 if (ns->proc_name == e->symtree->n.sym)
540 return true;
543 gfc_error ("%qs argument of %qs intrinsic at %L must be a variable",
544 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, &e->where);
546 return false;
550 /* Check the common DIM parameter for correctness. */
552 static bool
553 dim_check (gfc_expr *dim, int n, bool optional)
555 if (dim == NULL)
556 return true;
558 if (!type_check (dim, n, BT_INTEGER))
559 return false;
561 if (!scalar_check (dim, n))
562 return false;
564 if (!optional && !nonoptional_check (dim, n))
565 return false;
567 return true;
571 /* If a coarray DIM parameter is a constant, make sure that it is greater than
572 zero and less than or equal to the corank of the given array. */
574 static bool
575 dim_corank_check (gfc_expr *dim, gfc_expr *array)
577 int corank;
579 gcc_assert (array->expr_type == EXPR_VARIABLE);
581 if (dim->expr_type != EXPR_CONSTANT)
582 return true;
584 if (array->ts.type == BT_CLASS)
585 return true;
587 corank = gfc_get_corank (array);
589 if (mpz_cmp_ui (dim->value.integer, 1) < 0
590 || mpz_cmp_ui (dim->value.integer, corank) > 0)
592 gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
593 "codimension index", gfc_current_intrinsic, &dim->where);
595 return false;
598 return true;
602 /* If a DIM parameter is a constant, make sure that it is greater than
603 zero and less than or equal to the rank of the given array. If
604 allow_assumed is zero then dim must be less than the rank of the array
605 for assumed size arrays. */
607 static bool
608 dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
610 gfc_array_ref *ar;
611 int rank;
613 if (dim == NULL)
614 return true;
616 if (dim->expr_type != EXPR_CONSTANT)
617 return true;
619 if (array->expr_type == EXPR_FUNCTION && array->value.function.isym
620 && array->value.function.isym->id == GFC_ISYM_SPREAD)
621 rank = array->rank + 1;
622 else
623 rank = array->rank;
625 /* Assumed-rank array. */
626 if (rank == -1)
627 rank = GFC_MAX_DIMENSIONS;
629 if (array->expr_type == EXPR_VARIABLE)
631 ar = gfc_find_array_ref (array);
632 if (ar->as->type == AS_ASSUMED_SIZE
633 && !allow_assumed
634 && ar->type != AR_ELEMENT
635 && ar->type != AR_SECTION)
636 rank--;
639 if (mpz_cmp_ui (dim->value.integer, 1) < 0
640 || mpz_cmp_ui (dim->value.integer, rank) > 0)
642 gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
643 "dimension index", gfc_current_intrinsic, &dim->where);
645 return false;
648 return true;
652 /* Compare the size of a along dimension ai with the size of b along
653 dimension bi, returning 0 if they are known not to be identical,
654 and 1 if they are identical, or if this cannot be determined. */
656 static int
657 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
659 mpz_t a_size, b_size;
660 int ret;
662 gcc_assert (a->rank > ai);
663 gcc_assert (b->rank > bi);
665 ret = 1;
667 if (gfc_array_dimen_size (a, ai, &a_size))
669 if (gfc_array_dimen_size (b, bi, &b_size))
671 if (mpz_cmp (a_size, b_size) != 0)
672 ret = 0;
674 mpz_clear (b_size);
676 mpz_clear (a_size);
678 return ret;
681 /* Calculate the length of a character variable, including substrings.
682 Strip away parentheses if necessary. Return -1 if no length could
683 be determined. */
685 static long
686 gfc_var_strlen (const gfc_expr *a)
688 gfc_ref *ra;
690 while (a->expr_type == EXPR_OP && a->value.op.op == INTRINSIC_PARENTHESES)
691 a = a->value.op.op1;
693 for (ra = a->ref; ra != NULL && ra->type != REF_SUBSTRING; ra = ra->next)
696 if (ra)
698 long start_a, end_a;
700 if (!ra->u.ss.end)
701 return -1;
703 if ((!ra->u.ss.start || ra->u.ss.start->expr_type == EXPR_CONSTANT)
704 && ra->u.ss.end->expr_type == EXPR_CONSTANT)
706 start_a = ra->u.ss.start ? mpz_get_si (ra->u.ss.start->value.integer)
707 : 1;
708 end_a = mpz_get_si (ra->u.ss.end->value.integer);
709 return (end_a < start_a) ? 0 : end_a - start_a + 1;
711 else if (ra->u.ss.start
712 && gfc_dep_compare_expr (ra->u.ss.start, ra->u.ss.end) == 0)
713 return 1;
714 else
715 return -1;
718 if (a->ts.u.cl && a->ts.u.cl->length
719 && a->ts.u.cl->length->expr_type == EXPR_CONSTANT)
720 return mpz_get_si (a->ts.u.cl->length->value.integer);
721 else if (a->expr_type == EXPR_CONSTANT
722 && (a->ts.u.cl == NULL || a->ts.u.cl->length == NULL))
723 return a->value.character.length;
724 else
725 return -1;
729 /* Check whether two character expressions have the same length;
730 returns true if they have or if the length cannot be determined,
731 otherwise return false and raise a gfc_error. */
733 bool
734 gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
736 long len_a, len_b;
738 len_a = gfc_var_strlen(a);
739 len_b = gfc_var_strlen(b);
741 if (len_a == -1 || len_b == -1 || len_a == len_b)
742 return true;
743 else
745 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
746 len_a, len_b, name, &a->where);
747 return false;
752 /***** Check functions *****/
754 /* Check subroutine suitable for intrinsics taking a real argument and
755 a kind argument for the result. */
757 static bool
758 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
760 if (!type_check (a, 0, BT_REAL))
761 return false;
762 if (!kind_check (kind, 1, type))
763 return false;
765 return true;
769 /* Check subroutine suitable for ceiling, floor and nint. */
771 bool
772 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
774 return check_a_kind (a, kind, BT_INTEGER);
778 /* Check subroutine suitable for aint, anint. */
780 bool
781 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
783 return check_a_kind (a, kind, BT_REAL);
787 bool
788 gfc_check_abs (gfc_expr *a)
790 if (!numeric_check (a, 0))
791 return false;
793 return true;
797 bool
798 gfc_check_achar (gfc_expr *a, gfc_expr *kind)
800 if (!type_check (a, 0, BT_INTEGER))
801 return false;
802 if (!kind_check (kind, 1, BT_CHARACTER))
803 return false;
805 return true;
809 bool
810 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
812 if (!type_check (name, 0, BT_CHARACTER)
813 || !scalar_check (name, 0))
814 return false;
815 if (!kind_value_check (name, 0, gfc_default_character_kind))
816 return false;
818 if (!type_check (mode, 1, BT_CHARACTER)
819 || !scalar_check (mode, 1))
820 return false;
821 if (!kind_value_check (mode, 1, gfc_default_character_kind))
822 return false;
824 return true;
828 bool
829 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
831 if (!logical_array_check (mask, 0))
832 return false;
834 if (!dim_check (dim, 1, false))
835 return false;
837 if (!dim_rank_check (dim, mask, 0))
838 return false;
840 return true;
844 bool
845 gfc_check_allocated (gfc_expr *array)
847 if (!variable_check (array, 0, false))
848 return false;
849 if (!allocatable_check (array, 0))
850 return false;
852 return true;
856 /* Common check function where the first argument must be real or
857 integer and the second argument must be the same as the first. */
859 bool
860 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
862 if (!int_or_real_check (a, 0))
863 return false;
865 if (a->ts.type != p->ts.type)
867 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
868 "have the same type", gfc_current_intrinsic_arg[0]->name,
869 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
870 &p->where);
871 return false;
874 if (a->ts.kind != p->ts.kind)
876 if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
877 &p->where))
878 return false;
881 return true;
885 bool
886 gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
888 if (!double_check (x, 0) || !double_check (y, 1))
889 return false;
891 return true;
895 bool
896 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
898 symbol_attribute attr1, attr2;
899 int i;
900 bool t;
901 locus *where;
903 where = &pointer->where;
905 if (pointer->expr_type == EXPR_NULL)
906 goto null_arg;
908 attr1 = gfc_expr_attr (pointer);
910 if (!attr1.pointer && !attr1.proc_pointer)
912 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER",
913 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
914 &pointer->where);
915 return false;
918 /* F2008, C1242. */
919 if (attr1.pointer && gfc_is_coindexed (pointer))
921 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
922 "coindexed", gfc_current_intrinsic_arg[0]->name,
923 gfc_current_intrinsic, &pointer->where);
924 return false;
927 /* Target argument is optional. */
928 if (target == NULL)
929 return true;
931 where = &target->where;
932 if (target->expr_type == EXPR_NULL)
933 goto null_arg;
935 if (target->expr_type == EXPR_VARIABLE || target->expr_type == EXPR_FUNCTION)
936 attr2 = gfc_expr_attr (target);
937 else
939 gfc_error ("%qs argument of %qs intrinsic at %L must be a pointer "
940 "or target VARIABLE or FUNCTION",
941 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
942 &target->where);
943 return false;
946 if (attr1.pointer && !attr2.pointer && !attr2.target)
948 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER "
949 "or a TARGET", gfc_current_intrinsic_arg[1]->name,
950 gfc_current_intrinsic, &target->where);
951 return false;
954 /* F2008, C1242. */
955 if (attr1.pointer && gfc_is_coindexed (target))
957 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
958 "coindexed", gfc_current_intrinsic_arg[1]->name,
959 gfc_current_intrinsic, &target->where);
960 return false;
963 t = true;
964 if (!same_type_check (pointer, 0, target, 1))
965 t = false;
966 if (!rank_check (target, 0, pointer->rank))
967 t = false;
968 if (target->rank > 0)
970 for (i = 0; i < target->rank; i++)
971 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
973 gfc_error ("Array section with a vector subscript at %L shall not "
974 "be the target of a pointer",
975 &target->where);
976 t = false;
977 break;
980 return t;
982 null_arg:
984 gfc_error ("NULL pointer at %L is not permitted as actual argument "
985 "of %qs intrinsic function", where, gfc_current_intrinsic);
986 return false;
991 bool
992 gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
994 /* gfc_notify_std would be a waste of time as the return value
995 is seemingly used only for the generic resolution. The error
996 will be: Too many arguments. */
997 if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
998 return false;
1000 return gfc_check_atan2 (y, x);
1004 bool
1005 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
1007 if (!type_check (y, 0, BT_REAL))
1008 return false;
1009 if (!same_type_check (y, 0, x, 1))
1010 return false;
1012 return true;
1016 static bool
1017 gfc_check_atomic (gfc_expr *atom, int atom_no, gfc_expr *value, int val_no,
1018 gfc_expr *stat, int stat_no)
1020 if (!scalar_check (atom, atom_no) || !scalar_check (value, val_no))
1021 return false;
1023 if (!(atom->ts.type == BT_INTEGER && atom->ts.kind == gfc_atomic_int_kind)
1024 && !(atom->ts.type == BT_LOGICAL
1025 && atom->ts.kind == gfc_atomic_logical_kind))
1027 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1028 "integer of ATOMIC_INT_KIND or a logical of "
1029 "ATOMIC_LOGICAL_KIND", &atom->where, gfc_current_intrinsic);
1030 return false;
1033 if (!gfc_is_coarray (atom) && !gfc_is_coindexed (atom))
1035 gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
1036 "coarray or coindexed", &atom->where, gfc_current_intrinsic);
1037 return false;
1040 if (atom->ts.type != value->ts.type)
1042 gfc_error ("%qs argument of %qs intrinsic at %L shall have the same "
1043 "type as %qs at %L", gfc_current_intrinsic_arg[val_no]->name,
1044 gfc_current_intrinsic, &value->where,
1045 gfc_current_intrinsic_arg[atom_no]->name, &atom->where);
1046 return false;
1049 if (stat != NULL)
1051 if (!type_check (stat, stat_no, BT_INTEGER))
1052 return false;
1053 if (!scalar_check (stat, stat_no))
1054 return false;
1055 if (!variable_check (stat, stat_no, false))
1056 return false;
1057 if (!kind_value_check (stat, stat_no, gfc_default_integer_kind))
1058 return false;
1060 if (!gfc_notify_std (GFC_STD_F2008_TS, "STAT= argument to %s at %L",
1061 gfc_current_intrinsic, &stat->where))
1062 return false;
1065 return true;
1069 bool
1070 gfc_check_atomic_def (gfc_expr *atom, gfc_expr *value, gfc_expr *stat)
1072 if (atom->expr_type == EXPR_FUNCTION
1073 && atom->value.function.isym
1074 && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1075 atom = atom->value.function.actual->expr;
1077 if (!gfc_check_vardef_context (atom, false, false, false, NULL))
1079 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1080 "definable", gfc_current_intrinsic, &atom->where);
1081 return false;
1084 return gfc_check_atomic (atom, 0, value, 1, stat, 2);
1088 bool
1089 gfc_check_atomic_op (gfc_expr *atom, gfc_expr *value, gfc_expr *stat)
1091 if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind)
1093 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1094 "integer of ATOMIC_INT_KIND", &atom->where,
1095 gfc_current_intrinsic);
1096 return false;
1099 return gfc_check_atomic_def (atom, value, stat);
1103 bool
1104 gfc_check_atomic_ref (gfc_expr *value, gfc_expr *atom, gfc_expr *stat)
1106 if (atom->expr_type == EXPR_FUNCTION
1107 && atom->value.function.isym
1108 && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1109 atom = atom->value.function.actual->expr;
1111 if (!gfc_check_vardef_context (value, false, false, false, NULL))
1113 gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1114 "definable", gfc_current_intrinsic, &value->where);
1115 return false;
1118 return gfc_check_atomic (atom, 1, value, 0, stat, 2);
1122 bool
1123 gfc_check_atomic_cas (gfc_expr *atom, gfc_expr *old, gfc_expr *compare,
1124 gfc_expr *new_val, gfc_expr *stat)
1126 if (atom->expr_type == EXPR_FUNCTION
1127 && atom->value.function.isym
1128 && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1129 atom = atom->value.function.actual->expr;
1131 if (!gfc_check_atomic (atom, 0, new_val, 3, stat, 4))
1132 return false;
1134 if (!scalar_check (old, 1) || !scalar_check (compare, 2))
1135 return false;
1137 if (!same_type_check (atom, 0, old, 1))
1138 return false;
1140 if (!same_type_check (atom, 0, compare, 2))
1141 return false;
1143 if (!gfc_check_vardef_context (atom, false, false, false, NULL))
1145 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1146 "definable", gfc_current_intrinsic, &atom->where);
1147 return false;
1150 if (!gfc_check_vardef_context (old, false, false, false, NULL))
1152 gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1153 "definable", gfc_current_intrinsic, &old->where);
1154 return false;
1157 return true;
1160 bool
1161 gfc_check_event_query (gfc_expr *event, gfc_expr *count, gfc_expr *stat)
1163 if (event->ts.type != BT_DERIVED
1164 || event->ts.u.derived->from_intmod != INTMOD_ISO_FORTRAN_ENV
1165 || event->ts.u.derived->intmod_sym_id != ISOFORTRAN_EVENT_TYPE)
1167 gfc_error ("EVENT argument at %L to the intrinsic EVENT_QUERY "
1168 "shall be of type EVENT_TYPE", &event->where);
1169 return false;
1172 if (!scalar_check (event, 0))
1173 return false;
1175 if (!gfc_check_vardef_context (count, false, false, false, NULL))
1177 gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1178 "shall be definable", &count->where);
1179 return false;
1182 if (!type_check (count, 1, BT_INTEGER))
1183 return false;
1185 int i = gfc_validate_kind (BT_INTEGER, count->ts.kind, false);
1186 int j = gfc_validate_kind (BT_INTEGER, gfc_default_integer_kind, false);
1188 if (gfc_integer_kinds[i].range < gfc_integer_kinds[j].range)
1190 gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1191 "shall have at least the range of the default integer",
1192 &count->where);
1193 return false;
1196 if (stat != NULL)
1198 if (!type_check (stat, 2, BT_INTEGER))
1199 return false;
1200 if (!scalar_check (stat, 2))
1201 return false;
1202 if (!variable_check (stat, 2, false))
1203 return false;
1205 if (!gfc_notify_std (GFC_STD_F2008_TS, "STAT= argument to %s at %L",
1206 gfc_current_intrinsic, &stat->where))
1207 return false;
1210 return true;
1214 bool
1215 gfc_check_atomic_fetch_op (gfc_expr *atom, gfc_expr *value, gfc_expr *old,
1216 gfc_expr *stat)
1218 if (atom->expr_type == EXPR_FUNCTION
1219 && atom->value.function.isym
1220 && atom->value.function.isym->id == GFC_ISYM_CAF_GET)
1221 atom = atom->value.function.actual->expr;
1223 if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind)
1225 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1226 "integer of ATOMIC_INT_KIND", &atom->where,
1227 gfc_current_intrinsic);
1228 return false;
1231 if (!gfc_check_atomic (atom, 0, value, 1, stat, 3))
1232 return false;
1234 if (!scalar_check (old, 2))
1235 return false;
1237 if (!same_type_check (atom, 0, old, 2))
1238 return false;
1240 if (!gfc_check_vardef_context (atom, false, false, false, NULL))
1242 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1243 "definable", gfc_current_intrinsic, &atom->where);
1244 return false;
1247 if (!gfc_check_vardef_context (old, false, false, false, NULL))
1249 gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1250 "definable", gfc_current_intrinsic, &old->where);
1251 return false;
1254 return true;
1258 /* BESJN and BESYN functions. */
1260 bool
1261 gfc_check_besn (gfc_expr *n, gfc_expr *x)
1263 if (!type_check (n, 0, BT_INTEGER))
1264 return false;
1265 if (n->expr_type == EXPR_CONSTANT)
1267 int i;
1268 gfc_extract_int (n, &i);
1269 if (i < 0 && !gfc_notify_std (GFC_STD_GNU, "Negative argument "
1270 "N at %L", &n->where))
1271 return false;
1274 if (!type_check (x, 1, BT_REAL))
1275 return false;
1277 return true;
1281 /* Transformational version of the Bessel JN and YN functions. */
1283 bool
1284 gfc_check_bessel_n2 (gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
1286 if (!type_check (n1, 0, BT_INTEGER))
1287 return false;
1288 if (!scalar_check (n1, 0))
1289 return false;
1290 if (!nonnegative_check ("N1", n1))
1291 return false;
1293 if (!type_check (n2, 1, BT_INTEGER))
1294 return false;
1295 if (!scalar_check (n2, 1))
1296 return false;
1297 if (!nonnegative_check ("N2", n2))
1298 return false;
1300 if (!type_check (x, 2, BT_REAL))
1301 return false;
1302 if (!scalar_check (x, 2))
1303 return false;
1305 return true;
1309 bool
1310 gfc_check_bge_bgt_ble_blt (gfc_expr *i, gfc_expr *j)
1312 if (!type_check (i, 0, BT_INTEGER))
1313 return false;
1315 if (!type_check (j, 1, BT_INTEGER))
1316 return false;
1318 return true;
1322 bool
1323 gfc_check_bitfcn (gfc_expr *i, gfc_expr *pos)
1325 if (!type_check (i, 0, BT_INTEGER))
1326 return false;
1328 if (!type_check (pos, 1, BT_INTEGER))
1329 return false;
1331 if (!nonnegative_check ("pos", pos))
1332 return false;
1334 if (!less_than_bitsize1 ("i", i, "pos", pos, false))
1335 return false;
1337 return true;
1341 bool
1342 gfc_check_char (gfc_expr *i, gfc_expr *kind)
1344 if (!type_check (i, 0, BT_INTEGER))
1345 return false;
1346 if (!kind_check (kind, 1, BT_CHARACTER))
1347 return false;
1349 return true;
1353 bool
1354 gfc_check_chdir (gfc_expr *dir)
1356 if (!type_check (dir, 0, BT_CHARACTER))
1357 return false;
1358 if (!kind_value_check (dir, 0, gfc_default_character_kind))
1359 return false;
1361 return true;
1365 bool
1366 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
1368 if (!type_check (dir, 0, BT_CHARACTER))
1369 return false;
1370 if (!kind_value_check (dir, 0, gfc_default_character_kind))
1371 return false;
1373 if (status == NULL)
1374 return true;
1376 if (!type_check (status, 1, BT_INTEGER))
1377 return false;
1378 if (!scalar_check (status, 1))
1379 return false;
1381 return true;
1385 bool
1386 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
1388 if (!type_check (name, 0, BT_CHARACTER))
1389 return false;
1390 if (!kind_value_check (name, 0, gfc_default_character_kind))
1391 return false;
1393 if (!type_check (mode, 1, BT_CHARACTER))
1394 return false;
1395 if (!kind_value_check (mode, 1, gfc_default_character_kind))
1396 return false;
1398 return true;
1402 bool
1403 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
1405 if (!type_check (name, 0, BT_CHARACTER))
1406 return false;
1407 if (!kind_value_check (name, 0, gfc_default_character_kind))
1408 return false;
1410 if (!type_check (mode, 1, BT_CHARACTER))
1411 return false;
1412 if (!kind_value_check (mode, 1, gfc_default_character_kind))
1413 return false;
1415 if (status == NULL)
1416 return true;
1418 if (!type_check (status, 2, BT_INTEGER))
1419 return false;
1421 if (!scalar_check (status, 2))
1422 return false;
1424 return true;
1428 bool
1429 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
1431 if (!numeric_check (x, 0))
1432 return false;
1434 if (y != NULL)
1436 if (!numeric_check (y, 1))
1437 return false;
1439 if (x->ts.type == BT_COMPLEX)
1441 gfc_error ("%qs argument of %qs intrinsic at %L must not be "
1442 "present if %<x%> is COMPLEX",
1443 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1444 &y->where);
1445 return false;
1448 if (y->ts.type == BT_COMPLEX)
1450 gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
1451 "of either REAL or INTEGER",
1452 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1453 &y->where);
1454 return false;
1459 if (!kind_check (kind, 2, BT_COMPLEX))
1460 return false;
1462 if (!kind && warn_conversion
1463 && x->ts.type == BT_REAL && x->ts.kind > gfc_default_real_kind)
1464 gfc_warning_now (OPT_Wconversion, "Conversion from %s to default-kind "
1465 "COMPLEX(%d) at %L might lose precision, consider using "
1466 "the KIND argument", gfc_typename (&x->ts),
1467 gfc_default_real_kind, &x->where);
1468 else if (y && !kind && warn_conversion
1469 && y->ts.type == BT_REAL && y->ts.kind > gfc_default_real_kind)
1470 gfc_warning_now (OPT_Wconversion, "Conversion from %s to default-kind "
1471 "COMPLEX(%d) at %L might lose precision, consider using "
1472 "the KIND argument", gfc_typename (&y->ts),
1473 gfc_default_real_kind, &y->where);
1474 return true;
1478 static bool
1479 check_co_collective (gfc_expr *a, gfc_expr *image_idx, gfc_expr *stat,
1480 gfc_expr *errmsg, bool co_reduce)
1482 if (!variable_check (a, 0, false))
1483 return false;
1485 if (!gfc_check_vardef_context (a, false, false, false, "argument 'A' with "
1486 "INTENT(INOUT)"))
1487 return false;
1489 /* Fortran 2008, 12.5.2.4, paragraph 18. */
1490 if (gfc_has_vector_subscript (a))
1492 gfc_error ("Argument %<A%> with INTENT(INOUT) at %L of the intrinsic "
1493 "subroutine %s shall not have a vector subscript",
1494 &a->where, gfc_current_intrinsic);
1495 return false;
1498 if (gfc_is_coindexed (a))
1500 gfc_error ("The A argument at %L to the intrinsic %s shall not be "
1501 "coindexed", &a->where, gfc_current_intrinsic);
1502 return false;
1505 if (image_idx != NULL)
1507 if (!type_check (image_idx, co_reduce ? 2 : 1, BT_INTEGER))
1508 return false;
1509 if (!scalar_check (image_idx, co_reduce ? 2 : 1))
1510 return false;
1513 if (stat != NULL)
1515 if (!type_check (stat, co_reduce ? 3 : 2, BT_INTEGER))
1516 return false;
1517 if (!scalar_check (stat, co_reduce ? 3 : 2))
1518 return false;
1519 if (!variable_check (stat, co_reduce ? 3 : 2, false))
1520 return false;
1521 if (stat->ts.kind != 4)
1523 gfc_error ("The stat= argument at %L must be a kind=4 integer "
1524 "variable", &stat->where);
1525 return false;
1529 if (errmsg != NULL)
1531 if (!type_check (errmsg, co_reduce ? 4 : 3, BT_CHARACTER))
1532 return false;
1533 if (!scalar_check (errmsg, co_reduce ? 4 : 3))
1534 return false;
1535 if (!variable_check (errmsg, co_reduce ? 4 : 3, false))
1536 return false;
1537 if (errmsg->ts.kind != 1)
1539 gfc_error ("The errmsg= argument at %L must be a default-kind "
1540 "character variable", &errmsg->where);
1541 return false;
1545 if (flag_coarray == GFC_FCOARRAY_NONE)
1547 gfc_fatal_error ("Coarrays disabled at %L, use %<-fcoarray=%> to enable",
1548 &a->where);
1549 return false;
1552 return true;
1556 bool
1557 gfc_check_co_broadcast (gfc_expr *a, gfc_expr *source_image, gfc_expr *stat,
1558 gfc_expr *errmsg)
1560 if (a->ts.type == BT_CLASS || gfc_expr_attr (a).alloc_comp)
1562 gfc_error ("Support for the A argument at %L which is polymorphic A "
1563 "argument or has allocatable components is not yet "
1564 "implemented", &a->where);
1565 return false;
1567 return check_co_collective (a, source_image, stat, errmsg, false);
1571 bool
1572 gfc_check_co_reduce (gfc_expr *a, gfc_expr *op, gfc_expr *result_image,
1573 gfc_expr *stat, gfc_expr *errmsg)
1575 symbol_attribute attr;
1576 gfc_formal_arglist *formal;
1577 gfc_symbol *sym;
1579 if (a->ts.type == BT_CLASS)
1581 gfc_error ("The A argument at %L of CO_REDUCE shall not be polymorphic",
1582 &a->where);
1583 return false;
1586 if (gfc_expr_attr (a).alloc_comp)
1588 gfc_error ("Support for the A argument at %L with allocatable components"
1589 " is not yet implemented", &a->where);
1590 return false;
1593 if (!check_co_collective (a, result_image, stat, errmsg, true))
1594 return false;
1596 if (!gfc_resolve_expr (op))
1597 return false;
1599 attr = gfc_expr_attr (op);
1600 if (!attr.pure || !attr.function)
1602 gfc_error ("OPERATOR argument at %L must be a PURE function",
1603 &op->where);
1604 return false;
1607 if (attr.intrinsic)
1609 /* None of the intrinsics fulfills the criteria of taking two arguments,
1610 returning the same type and kind as the arguments and being permitted
1611 as actual argument. */
1612 gfc_error ("Intrinsic function %s at %L is not permitted for CO_REDUCE",
1613 op->symtree->n.sym->name, &op->where);
1614 return false;
1617 if (gfc_is_proc_ptr_comp (op))
1619 gfc_component *comp = gfc_get_proc_ptr_comp (op);
1620 sym = comp->ts.interface;
1622 else
1623 sym = op->symtree->n.sym;
1625 formal = sym->formal;
1627 if (!formal || !formal->next || formal->next->next)
1629 gfc_error ("The function passed as OPERATOR at %L shall have two "
1630 "arguments", &op->where);
1631 return false;
1634 if (sym->result->ts.type == BT_UNKNOWN)
1635 gfc_set_default_type (sym->result, 0, NULL);
1637 if (!gfc_compare_types (&a->ts, &sym->result->ts))
1639 gfc_error ("A argument at %L has type %s but the function passed as "
1640 "OPERATOR at %L returns %s",
1641 &a->where, gfc_typename (&a->ts), &op->where,
1642 gfc_typename (&sym->result->ts));
1643 return false;
1645 if (!gfc_compare_types (&a->ts, &formal->sym->ts)
1646 || !gfc_compare_types (&a->ts, &formal->next->sym->ts))
1648 gfc_error ("The function passed as OPERATOR at %L has arguments of type "
1649 "%s and %s but shall have type %s", &op->where,
1650 gfc_typename (&formal->sym->ts),
1651 gfc_typename (&formal->next->sym->ts), gfc_typename (&a->ts));
1652 return false;
1654 if (op->rank || attr.allocatable || attr.pointer || formal->sym->as
1655 || formal->next->sym->as || formal->sym->attr.allocatable
1656 || formal->next->sym->attr.allocatable || formal->sym->attr.pointer
1657 || formal->next->sym->attr.pointer)
1659 gfc_error ("The function passed as OPERATOR at %L shall have scalar "
1660 "nonallocatable nonpointer arguments and return a "
1661 "nonallocatable nonpointer scalar", &op->where);
1662 return false;
1665 if (formal->sym->attr.value != formal->next->sym->attr.value)
1667 gfc_error ("The function passed as OPERATOR at %L shall have the VALUE "
1668 "attribute either for none or both arguments", &op->where);
1669 return false;
1672 if (formal->sym->attr.target != formal->next->sym->attr.target)
1674 gfc_error ("The function passed as OPERATOR at %L shall have the TARGET "
1675 "attribute either for none or both arguments", &op->where);
1676 return false;
1679 if (formal->sym->attr.asynchronous != formal->next->sym->attr.asynchronous)
1681 gfc_error ("The function passed as OPERATOR at %L shall have the "
1682 "ASYNCHRONOUS attribute either for none or both arguments",
1683 &op->where);
1684 return false;
1687 if (formal->sym->attr.optional || formal->next->sym->attr.optional)
1689 gfc_error ("The function passed as OPERATOR at %L shall not have the "
1690 "OPTIONAL attribute for either of the arguments", &op->where);
1691 return false;
1694 if (a->ts.type == BT_CHARACTER)
1696 gfc_charlen *cl;
1697 unsigned long actual_size, formal_size1, formal_size2, result_size;
1699 cl = a->ts.u.cl;
1700 actual_size = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
1701 ? mpz_get_ui (cl->length->value.integer) : 0;
1703 cl = formal->sym->ts.u.cl;
1704 formal_size1 = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
1705 ? mpz_get_ui (cl->length->value.integer) : 0;
1707 cl = formal->next->sym->ts.u.cl;
1708 formal_size2 = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
1709 ? mpz_get_ui (cl->length->value.integer) : 0;
1711 cl = sym->ts.u.cl;
1712 result_size = cl && cl->length && cl->length->expr_type == EXPR_CONSTANT
1713 ? mpz_get_ui (cl->length->value.integer) : 0;
1715 if (actual_size
1716 && ((formal_size1 && actual_size != formal_size1)
1717 || (formal_size2 && actual_size != formal_size2)))
1719 gfc_error ("The character length of the A argument at %L and of the "
1720 "arguments of the OPERATOR at %L shall be the same",
1721 &a->where, &op->where);
1722 return false;
1724 if (actual_size && result_size && actual_size != result_size)
1726 gfc_error ("The character length of the A argument at %L and of the "
1727 "function result of the OPERATOR at %L shall be the same",
1728 &a->where, &op->where);
1729 return false;
1733 return true;
1737 bool
1738 gfc_check_co_minmax (gfc_expr *a, gfc_expr *result_image, gfc_expr *stat,
1739 gfc_expr *errmsg)
1741 if (a->ts.type != BT_INTEGER && a->ts.type != BT_REAL
1742 && a->ts.type != BT_CHARACTER)
1744 gfc_error ("%qs argument of %qs intrinsic at %L shall be of type "
1745 "integer, real or character",
1746 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
1747 &a->where);
1748 return false;
1750 return check_co_collective (a, result_image, stat, errmsg, false);
1754 bool
1755 gfc_check_co_sum (gfc_expr *a, gfc_expr *result_image, gfc_expr *stat,
1756 gfc_expr *errmsg)
1758 if (!numeric_check (a, 0))
1759 return false;
1760 return check_co_collective (a, result_image, stat, errmsg, false);
1764 bool
1765 gfc_check_complex (gfc_expr *x, gfc_expr *y)
1767 if (!int_or_real_check (x, 0))
1768 return false;
1769 if (!scalar_check (x, 0))
1770 return false;
1772 if (!int_or_real_check (y, 1))
1773 return false;
1774 if (!scalar_check (y, 1))
1775 return false;
1777 return true;
1781 bool
1782 gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
1784 if (!logical_array_check (mask, 0))
1785 return false;
1786 if (!dim_check (dim, 1, false))
1787 return false;
1788 if (!dim_rank_check (dim, mask, 0))
1789 return false;
1790 if (!kind_check (kind, 2, BT_INTEGER))
1791 return false;
1792 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
1793 "with KIND argument at %L",
1794 gfc_current_intrinsic, &kind->where))
1795 return false;
1797 return true;
1801 bool
1802 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
1804 if (!array_check (array, 0))
1805 return false;
1807 if (!type_check (shift, 1, BT_INTEGER))
1808 return false;
1810 if (!dim_check (dim, 2, true))
1811 return false;
1813 if (!dim_rank_check (dim, array, false))
1814 return false;
1816 if (array->rank == 1 || shift->rank == 0)
1818 if (!scalar_check (shift, 1))
1819 return false;
1821 else if (shift->rank == array->rank - 1)
1823 int d;
1824 if (!dim)
1825 d = 1;
1826 else if (dim->expr_type == EXPR_CONSTANT)
1827 gfc_extract_int (dim, &d);
1828 else
1829 d = -1;
1831 if (d > 0)
1833 int i, j;
1834 for (i = 0, j = 0; i < array->rank; i++)
1835 if (i != d - 1)
1837 if (!identical_dimen_shape (array, i, shift, j))
1839 gfc_error ("%qs argument of %qs intrinsic at %L has "
1840 "invalid shape in dimension %d (%ld/%ld)",
1841 gfc_current_intrinsic_arg[1]->name,
1842 gfc_current_intrinsic, &shift->where, i + 1,
1843 mpz_get_si (array->shape[i]),
1844 mpz_get_si (shift->shape[j]));
1845 return false;
1848 j += 1;
1852 else
1854 gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
1855 "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
1856 gfc_current_intrinsic, &shift->where, array->rank - 1);
1857 return false;
1860 return true;
1864 bool
1865 gfc_check_ctime (gfc_expr *time)
1867 if (!scalar_check (time, 0))
1868 return false;
1870 if (!type_check (time, 0, BT_INTEGER))
1871 return false;
1873 return true;
1877 bool gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
1879 if (!double_check (y, 0) || !double_check (x, 1))
1880 return false;
1882 return true;
1885 bool
1886 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
1888 if (!numeric_check (x, 0))
1889 return false;
1891 if (y != NULL)
1893 if (!numeric_check (y, 1))
1894 return false;
1896 if (x->ts.type == BT_COMPLEX)
1898 gfc_error ("%qs argument of %qs intrinsic at %L must not be "
1899 "present if %<x%> is COMPLEX",
1900 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1901 &y->where);
1902 return false;
1905 if (y->ts.type == BT_COMPLEX)
1907 gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
1908 "of either REAL or INTEGER",
1909 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1910 &y->where);
1911 return false;
1915 return true;
1919 bool
1920 gfc_check_dble (gfc_expr *x)
1922 if (!numeric_check (x, 0))
1923 return false;
1925 return true;
1929 bool
1930 gfc_check_digits (gfc_expr *x)
1932 if (!int_or_real_check (x, 0))
1933 return false;
1935 return true;
1939 bool
1940 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
1942 switch (vector_a->ts.type)
1944 case BT_LOGICAL:
1945 if (!type_check (vector_b, 1, BT_LOGICAL))
1946 return false;
1947 break;
1949 case BT_INTEGER:
1950 case BT_REAL:
1951 case BT_COMPLEX:
1952 if (!numeric_check (vector_b, 1))
1953 return false;
1954 break;
1956 default:
1957 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
1958 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
1959 gfc_current_intrinsic, &vector_a->where);
1960 return false;
1963 if (!rank_check (vector_a, 0, 1))
1964 return false;
1966 if (!rank_check (vector_b, 1, 1))
1967 return false;
1969 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
1971 gfc_error ("Different shape for arguments %qs and %qs at %L for "
1972 "intrinsic %<dot_product%>",
1973 gfc_current_intrinsic_arg[0]->name,
1974 gfc_current_intrinsic_arg[1]->name, &vector_a->where);
1975 return false;
1978 return true;
1982 bool
1983 gfc_check_dprod (gfc_expr *x, gfc_expr *y)
1985 if (!type_check (x, 0, BT_REAL)
1986 || !type_check (y, 1, BT_REAL))
1987 return false;
1989 if (x->ts.kind != gfc_default_real_kind)
1991 gfc_error ("%qs argument of %qs intrinsic at %L must be default "
1992 "real", gfc_current_intrinsic_arg[0]->name,
1993 gfc_current_intrinsic, &x->where);
1994 return false;
1997 if (y->ts.kind != gfc_default_real_kind)
1999 gfc_error ("%qs argument of %qs intrinsic at %L must be default "
2000 "real", gfc_current_intrinsic_arg[1]->name,
2001 gfc_current_intrinsic, &y->where);
2002 return false;
2005 return true;
2009 bool
2010 gfc_check_dshift (gfc_expr *i, gfc_expr *j, gfc_expr *shift)
2012 if (!type_check (i, 0, BT_INTEGER))
2013 return false;
2015 if (!type_check (j, 1, BT_INTEGER))
2016 return false;
2018 if (i->is_boz && j->is_boz)
2020 gfc_error ("%<I%> at %L and %<J%>' at %L cannot both be BOZ literal "
2021 "constants", &i->where, &j->where);
2022 return false;
2025 if (!i->is_boz && !j->is_boz && !same_type_check (i, 0, j, 1))
2026 return false;
2028 if (!type_check (shift, 2, BT_INTEGER))
2029 return false;
2031 if (!nonnegative_check ("SHIFT", shift))
2032 return false;
2034 if (i->is_boz)
2036 if (!less_than_bitsize1 ("J", j, "SHIFT", shift, true))
2037 return false;
2038 i->ts.kind = j->ts.kind;
2040 else
2042 if (!less_than_bitsize1 ("I", i, "SHIFT", shift, true))
2043 return false;
2044 j->ts.kind = i->ts.kind;
2047 return true;
2051 bool
2052 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
2053 gfc_expr *dim)
2055 if (!array_check (array, 0))
2056 return false;
2058 if (!type_check (shift, 1, BT_INTEGER))
2059 return false;
2061 if (!dim_check (dim, 3, true))
2062 return false;
2064 if (!dim_rank_check (dim, array, false))
2065 return false;
2067 if (array->rank == 1 || shift->rank == 0)
2069 if (!scalar_check (shift, 1))
2070 return false;
2072 else if (shift->rank == array->rank - 1)
2074 int d;
2075 if (!dim)
2076 d = 1;
2077 else if (dim->expr_type == EXPR_CONSTANT)
2078 gfc_extract_int (dim, &d);
2079 else
2080 d = -1;
2082 if (d > 0)
2084 int i, j;
2085 for (i = 0, j = 0; i < array->rank; i++)
2086 if (i != d - 1)
2088 if (!identical_dimen_shape (array, i, shift, j))
2090 gfc_error ("%qs argument of %qs intrinsic at %L has "
2091 "invalid shape in dimension %d (%ld/%ld)",
2092 gfc_current_intrinsic_arg[1]->name,
2093 gfc_current_intrinsic, &shift->where, i + 1,
2094 mpz_get_si (array->shape[i]),
2095 mpz_get_si (shift->shape[j]));
2096 return false;
2099 j += 1;
2103 else
2105 gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
2106 "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
2107 gfc_current_intrinsic, &shift->where, array->rank - 1);
2108 return false;
2111 if (boundary != NULL)
2113 if (!same_type_check (array, 0, boundary, 2))
2114 return false;
2116 if (array->rank == 1 || boundary->rank == 0)
2118 if (!scalar_check (boundary, 2))
2119 return false;
2121 else if (boundary->rank == array->rank - 1)
2123 if (!gfc_check_conformance (shift, boundary,
2124 "arguments '%s' and '%s' for "
2125 "intrinsic %s",
2126 gfc_current_intrinsic_arg[1]->name,
2127 gfc_current_intrinsic_arg[2]->name,
2128 gfc_current_intrinsic))
2129 return false;
2131 else
2133 gfc_error ("%qs argument of intrinsic %qs at %L of must have "
2134 "rank %d or be a scalar",
2135 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2136 &shift->where, array->rank - 1);
2137 return false;
2141 return true;
2144 bool
2145 gfc_check_float (gfc_expr *a)
2147 if (!type_check (a, 0, BT_INTEGER))
2148 return false;
2150 if ((a->ts.kind != gfc_default_integer_kind)
2151 && !gfc_notify_std (GFC_STD_GNU, "non-default INTEGER "
2152 "kind argument to %s intrinsic at %L",
2153 gfc_current_intrinsic, &a->where))
2154 return false;
2156 return true;
2159 /* A single complex argument. */
2161 bool
2162 gfc_check_fn_c (gfc_expr *a)
2164 if (!type_check (a, 0, BT_COMPLEX))
2165 return false;
2167 return true;
2170 /* A single real argument. */
2172 bool
2173 gfc_check_fn_r (gfc_expr *a)
2175 if (!type_check (a, 0, BT_REAL))
2176 return false;
2178 return true;
2181 /* A single double argument. */
2183 bool
2184 gfc_check_fn_d (gfc_expr *a)
2186 if (!double_check (a, 0))
2187 return false;
2189 return true;
2192 /* A single real or complex argument. */
2194 bool
2195 gfc_check_fn_rc (gfc_expr *a)
2197 if (!real_or_complex_check (a, 0))
2198 return false;
2200 return true;
2204 bool
2205 gfc_check_fn_rc2008 (gfc_expr *a)
2207 if (!real_or_complex_check (a, 0))
2208 return false;
2210 if (a->ts.type == BT_COMPLEX
2211 && !gfc_notify_std (GFC_STD_F2008, "COMPLEX argument %qs "
2212 "of %qs intrinsic at %L",
2213 gfc_current_intrinsic_arg[0]->name,
2214 gfc_current_intrinsic, &a->where))
2215 return false;
2217 return true;
2221 bool
2222 gfc_check_fnum (gfc_expr *unit)
2224 if (!type_check (unit, 0, BT_INTEGER))
2225 return false;
2227 if (!scalar_check (unit, 0))
2228 return false;
2230 return true;
2234 bool
2235 gfc_check_huge (gfc_expr *x)
2237 if (!int_or_real_check (x, 0))
2238 return false;
2240 return true;
2244 bool
2245 gfc_check_hypot (gfc_expr *x, gfc_expr *y)
2247 if (!type_check (x, 0, BT_REAL))
2248 return false;
2249 if (!same_type_check (x, 0, y, 1))
2250 return false;
2252 return true;
2256 /* Check that the single argument is an integer. */
2258 bool
2259 gfc_check_i (gfc_expr *i)
2261 if (!type_check (i, 0, BT_INTEGER))
2262 return false;
2264 return true;
2268 bool
2269 gfc_check_iand (gfc_expr *i, gfc_expr *j)
2271 if (!type_check (i, 0, BT_INTEGER))
2272 return false;
2274 if (!type_check (j, 1, BT_INTEGER))
2275 return false;
2277 if (i->ts.kind != j->ts.kind)
2279 if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
2280 &i->where))
2281 return false;
2284 return true;
2288 bool
2289 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
2291 if (!type_check (i, 0, BT_INTEGER))
2292 return false;
2294 if (!type_check (pos, 1, BT_INTEGER))
2295 return false;
2297 if (!type_check (len, 2, BT_INTEGER))
2298 return false;
2300 if (!nonnegative_check ("pos", pos))
2301 return false;
2303 if (!nonnegative_check ("len", len))
2304 return false;
2306 if (!less_than_bitsize2 ("i", i, "pos", pos, "len", len))
2307 return false;
2309 return true;
2313 bool
2314 gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
2316 int i;
2318 if (!type_check (c, 0, BT_CHARACTER))
2319 return false;
2321 if (!kind_check (kind, 1, BT_INTEGER))
2322 return false;
2324 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
2325 "with KIND argument at %L",
2326 gfc_current_intrinsic, &kind->where))
2327 return false;
2329 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
2331 gfc_expr *start;
2332 gfc_expr *end;
2333 gfc_ref *ref;
2335 /* Substring references don't have the charlength set. */
2336 ref = c->ref;
2337 while (ref && ref->type != REF_SUBSTRING)
2338 ref = ref->next;
2340 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
2342 if (!ref)
2344 /* Check that the argument is length one. Non-constant lengths
2345 can't be checked here, so assume they are ok. */
2346 if (c->ts.u.cl && c->ts.u.cl->length)
2348 /* If we already have a length for this expression then use it. */
2349 if (c->ts.u.cl->length->expr_type != EXPR_CONSTANT)
2350 return true;
2351 i = mpz_get_si (c->ts.u.cl->length->value.integer);
2353 else
2354 return true;
2356 else
2358 start = ref->u.ss.start;
2359 end = ref->u.ss.end;
2361 gcc_assert (start);
2362 if (end == NULL || end->expr_type != EXPR_CONSTANT
2363 || start->expr_type != EXPR_CONSTANT)
2364 return true;
2366 i = mpz_get_si (end->value.integer) + 1
2367 - mpz_get_si (start->value.integer);
2370 else
2371 return true;
2373 if (i != 1)
2375 gfc_error ("Argument of %s at %L must be of length one",
2376 gfc_current_intrinsic, &c->where);
2377 return false;
2380 return true;
2384 bool
2385 gfc_check_idnint (gfc_expr *a)
2387 if (!double_check (a, 0))
2388 return false;
2390 return true;
2394 bool
2395 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
2397 if (!type_check (i, 0, BT_INTEGER))
2398 return false;
2400 if (!type_check (j, 1, BT_INTEGER))
2401 return false;
2403 if (i->ts.kind != j->ts.kind)
2405 if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
2406 &i->where))
2407 return false;
2410 return true;
2414 bool
2415 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back,
2416 gfc_expr *kind)
2418 if (!type_check (string, 0, BT_CHARACTER)
2419 || !type_check (substring, 1, BT_CHARACTER))
2420 return false;
2422 if (back != NULL && !type_check (back, 2, BT_LOGICAL))
2423 return false;
2425 if (!kind_check (kind, 3, BT_INTEGER))
2426 return false;
2427 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
2428 "with KIND argument at %L",
2429 gfc_current_intrinsic, &kind->where))
2430 return false;
2432 if (string->ts.kind != substring->ts.kind)
2434 gfc_error ("%qs argument of %qs intrinsic at %L must be the same "
2435 "kind as %qs", gfc_current_intrinsic_arg[1]->name,
2436 gfc_current_intrinsic, &substring->where,
2437 gfc_current_intrinsic_arg[0]->name);
2438 return false;
2441 return true;
2445 bool
2446 gfc_check_int (gfc_expr *x, gfc_expr *kind)
2448 if (!numeric_check (x, 0))
2449 return false;
2451 if (!kind_check (kind, 1, BT_INTEGER))
2452 return false;
2454 return true;
2458 bool
2459 gfc_check_intconv (gfc_expr *x)
2461 if (!numeric_check (x, 0))
2462 return false;
2464 return true;
2468 bool
2469 gfc_check_ior (gfc_expr *i, gfc_expr *j)
2471 if (!type_check (i, 0, BT_INTEGER))
2472 return false;
2474 if (!type_check (j, 1, BT_INTEGER))
2475 return false;
2477 if (i->ts.kind != j->ts.kind)
2479 if (!gfc_notify_std (GFC_STD_GNU, "Different type kinds at %L",
2480 &i->where))
2481 return false;
2484 return true;
2488 bool
2489 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
2491 if (!type_check (i, 0, BT_INTEGER)
2492 || !type_check (shift, 1, BT_INTEGER))
2493 return false;
2495 if (!less_than_bitsize1 ("I", i, NULL, shift, true))
2496 return false;
2498 return true;
2502 bool
2503 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
2505 if (!type_check (i, 0, BT_INTEGER)
2506 || !type_check (shift, 1, BT_INTEGER))
2507 return false;
2509 if (size != NULL)
2511 int i2, i3;
2513 if (!type_check (size, 2, BT_INTEGER))
2514 return false;
2516 if (!less_than_bitsize1 ("I", i, "SIZE", size, true))
2517 return false;
2519 if (size->expr_type == EXPR_CONSTANT)
2521 gfc_extract_int (size, &i3);
2522 if (i3 <= 0)
2524 gfc_error ("SIZE at %L must be positive", &size->where);
2525 return false;
2528 if (shift->expr_type == EXPR_CONSTANT)
2530 gfc_extract_int (shift, &i2);
2531 if (i2 < 0)
2532 i2 = -i2;
2534 if (i2 > i3)
2536 gfc_error ("The absolute value of SHIFT at %L must be less "
2537 "than or equal to SIZE at %L", &shift->where,
2538 &size->where);
2539 return false;
2544 else if (!less_than_bitsize1 ("I", i, NULL, shift, true))
2545 return false;
2547 return true;
2551 bool
2552 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
2554 if (!type_check (pid, 0, BT_INTEGER))
2555 return false;
2557 if (!type_check (sig, 1, BT_INTEGER))
2558 return false;
2560 return true;
2564 bool
2565 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
2567 if (!type_check (pid, 0, BT_INTEGER))
2568 return false;
2570 if (!scalar_check (pid, 0))
2571 return false;
2573 if (!type_check (sig, 1, BT_INTEGER))
2574 return false;
2576 if (!scalar_check (sig, 1))
2577 return false;
2579 if (status == NULL)
2580 return true;
2582 if (!type_check (status, 2, BT_INTEGER))
2583 return false;
2585 if (!scalar_check (status, 2))
2586 return false;
2588 return true;
2592 bool
2593 gfc_check_kind (gfc_expr *x)
2595 if (gfc_bt_struct (x->ts.type) || x->ts.type == BT_CLASS)
2597 gfc_error ("%qs argument of %qs intrinsic at %L must be of "
2598 "intrinsic type", gfc_current_intrinsic_arg[0]->name,
2599 gfc_current_intrinsic, &x->where);
2600 return false;
2602 if (x->ts.type == BT_PROCEDURE)
2604 gfc_error ("%qs argument of %qs intrinsic at %L must be a data entity",
2605 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2606 &x->where);
2607 return false;
2610 return true;
2614 bool
2615 gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2617 if (!array_check (array, 0))
2618 return false;
2620 if (!dim_check (dim, 1, false))
2621 return false;
2623 if (!dim_rank_check (dim, array, 1))
2624 return false;
2626 if (!kind_check (kind, 2, BT_INTEGER))
2627 return false;
2628 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
2629 "with KIND argument at %L",
2630 gfc_current_intrinsic, &kind->where))
2631 return false;
2633 return true;
2637 bool
2638 gfc_check_lcobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
2640 if (flag_coarray == GFC_FCOARRAY_NONE)
2642 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
2643 return false;
2646 if (!coarray_check (coarray, 0))
2647 return false;
2649 if (dim != NULL)
2651 if (!dim_check (dim, 1, false))
2652 return false;
2654 if (!dim_corank_check (dim, coarray))
2655 return false;
2658 if (!kind_check (kind, 2, BT_INTEGER))
2659 return false;
2661 return true;
2665 bool
2666 gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
2668 if (!type_check (s, 0, BT_CHARACTER))
2669 return false;
2671 if (!kind_check (kind, 1, BT_INTEGER))
2672 return false;
2673 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
2674 "with KIND argument at %L",
2675 gfc_current_intrinsic, &kind->where))
2676 return false;
2678 return true;
2682 bool
2683 gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
2685 if (!type_check (a, 0, BT_CHARACTER))
2686 return false;
2687 if (!kind_value_check (a, 0, gfc_default_character_kind))
2688 return false;
2690 if (!type_check (b, 1, BT_CHARACTER))
2691 return false;
2692 if (!kind_value_check (b, 1, gfc_default_character_kind))
2693 return false;
2695 return true;
2699 bool
2700 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
2702 if (!type_check (path1, 0, BT_CHARACTER))
2703 return false;
2704 if (!kind_value_check (path1, 0, gfc_default_character_kind))
2705 return false;
2707 if (!type_check (path2, 1, BT_CHARACTER))
2708 return false;
2709 if (!kind_value_check (path2, 1, gfc_default_character_kind))
2710 return false;
2712 return true;
2716 bool
2717 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2719 if (!type_check (path1, 0, BT_CHARACTER))
2720 return false;
2721 if (!kind_value_check (path1, 0, gfc_default_character_kind))
2722 return false;
2724 if (!type_check (path2, 1, BT_CHARACTER))
2725 return false;
2726 if (!kind_value_check (path2, 0, gfc_default_character_kind))
2727 return false;
2729 if (status == NULL)
2730 return true;
2732 if (!type_check (status, 2, BT_INTEGER))
2733 return false;
2735 if (!scalar_check (status, 2))
2736 return false;
2738 return true;
2742 bool
2743 gfc_check_loc (gfc_expr *expr)
2745 return variable_check (expr, 0, true);
2749 bool
2750 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
2752 if (!type_check (path1, 0, BT_CHARACTER))
2753 return false;
2754 if (!kind_value_check (path1, 0, gfc_default_character_kind))
2755 return false;
2757 if (!type_check (path2, 1, BT_CHARACTER))
2758 return false;
2759 if (!kind_value_check (path2, 1, gfc_default_character_kind))
2760 return false;
2762 return true;
2766 bool
2767 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2769 if (!type_check (path1, 0, BT_CHARACTER))
2770 return false;
2771 if (!kind_value_check (path1, 0, gfc_default_character_kind))
2772 return false;
2774 if (!type_check (path2, 1, BT_CHARACTER))
2775 return false;
2776 if (!kind_value_check (path2, 1, gfc_default_character_kind))
2777 return false;
2779 if (status == NULL)
2780 return true;
2782 if (!type_check (status, 2, BT_INTEGER))
2783 return false;
2785 if (!scalar_check (status, 2))
2786 return false;
2788 return true;
2792 bool
2793 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
2795 if (!type_check (a, 0, BT_LOGICAL))
2796 return false;
2797 if (!kind_check (kind, 1, BT_LOGICAL))
2798 return false;
2800 return true;
2804 /* Min/max family. */
2806 static bool
2807 min_max_args (gfc_actual_arglist *args)
2809 gfc_actual_arglist *arg;
2810 int i, j, nargs, *nlabels, nlabelless;
2811 bool a1 = false, a2 = false;
2813 if (args == NULL || args->next == NULL)
2815 gfc_error ("Intrinsic %qs at %L must have at least two arguments",
2816 gfc_current_intrinsic, gfc_current_intrinsic_where);
2817 return false;
2820 if (!args->name)
2821 a1 = true;
2823 if (!args->next->name)
2824 a2 = true;
2826 nargs = 0;
2827 for (arg = args; arg; arg = arg->next)
2828 if (arg->name)
2829 nargs++;
2831 if (nargs == 0)
2832 return true;
2834 /* Note: Having a keywordless argument after an "arg=" is checked before. */
2835 nlabelless = 0;
2836 nlabels = XALLOCAVEC (int, nargs);
2837 for (arg = args, i = 0; arg; arg = arg->next, i++)
2838 if (arg->name)
2840 int n;
2841 char *endp;
2843 if (arg->name[0] != 'a' || arg->name[1] < '1' || arg->name[1] > '9')
2844 goto unknown;
2845 n = strtol (&arg->name[1], &endp, 10);
2846 if (endp[0] != '\0')
2847 goto unknown;
2848 if (n <= 0)
2849 goto unknown;
2850 if (n <= nlabelless)
2851 goto duplicate;
2852 nlabels[i] = n;
2853 if (n == 1)
2854 a1 = true;
2855 if (n == 2)
2856 a2 = true;
2858 else
2859 nlabelless++;
2861 if (!a1 || !a2)
2863 gfc_error ("Missing %qs argument to the %s intrinsic at %L",
2864 !a1 ? "a1" : "a2", gfc_current_intrinsic,
2865 gfc_current_intrinsic_where);
2866 return false;
2869 /* Check for duplicates. */
2870 for (i = 0; i < nargs; i++)
2871 for (j = i + 1; j < nargs; j++)
2872 if (nlabels[i] == nlabels[j])
2873 goto duplicate;
2875 return true;
2877 duplicate:
2878 gfc_error ("Duplicate argument %qs at %L to intrinsic %s", arg->name,
2879 &arg->expr->where, gfc_current_intrinsic);
2880 return false;
2882 unknown:
2883 gfc_error ("Unknown argument %qs at %L to intrinsic %s", arg->name,
2884 &arg->expr->where, gfc_current_intrinsic);
2885 return false;
2889 static bool
2890 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
2892 gfc_actual_arglist *arg, *tmp;
2893 gfc_expr *x;
2894 int m, n;
2896 if (!min_max_args (arglist))
2897 return false;
2899 for (arg = arglist, n=1; arg; arg = arg->next, n++)
2901 x = arg->expr;
2902 if (x->ts.type != type || x->ts.kind != kind)
2904 if (x->ts.type == type)
2906 if (!gfc_notify_std (GFC_STD_GNU, "Different type "
2907 "kinds at %L", &x->where))
2908 return false;
2910 else
2912 gfc_error ("%<a%d%> argument of %qs intrinsic at %L must be "
2913 "%s(%d)", n, gfc_current_intrinsic, &x->where,
2914 gfc_basic_typename (type), kind);
2915 return false;
2919 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
2920 if (!gfc_check_conformance (tmp->expr, x,
2921 "arguments 'a%d' and 'a%d' for "
2922 "intrinsic '%s'", m, n,
2923 gfc_current_intrinsic))
2924 return false;
2927 return true;
2931 bool
2932 gfc_check_min_max (gfc_actual_arglist *arg)
2934 gfc_expr *x;
2936 if (!min_max_args (arg))
2937 return false;
2939 x = arg->expr;
2941 if (x->ts.type == BT_CHARACTER)
2943 if (!gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
2944 "with CHARACTER argument at %L",
2945 gfc_current_intrinsic, &x->where))
2946 return false;
2948 else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
2950 gfc_error ("%<a1%> argument of %qs intrinsic at %L must be INTEGER, "
2951 "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
2952 return false;
2955 return check_rest (x->ts.type, x->ts.kind, arg);
2959 bool
2960 gfc_check_min_max_integer (gfc_actual_arglist *arg)
2962 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
2966 bool
2967 gfc_check_min_max_real (gfc_actual_arglist *arg)
2969 return check_rest (BT_REAL, gfc_default_real_kind, arg);
2973 bool
2974 gfc_check_min_max_double (gfc_actual_arglist *arg)
2976 return check_rest (BT_REAL, gfc_default_double_kind, arg);
2980 /* End of min/max family. */
2982 bool
2983 gfc_check_malloc (gfc_expr *size)
2985 if (!type_check (size, 0, BT_INTEGER))
2986 return false;
2988 if (!scalar_check (size, 0))
2989 return false;
2991 return true;
2995 bool
2996 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
2998 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
3000 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3001 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
3002 gfc_current_intrinsic, &matrix_a->where);
3003 return false;
3006 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
3008 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3009 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
3010 gfc_current_intrinsic, &matrix_b->where);
3011 return false;
3014 if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
3015 || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
3017 gfc_error ("Argument types of %qs intrinsic at %L must match (%s/%s)",
3018 gfc_current_intrinsic, &matrix_a->where,
3019 gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
3020 return false;
3023 switch (matrix_a->rank)
3025 case 1:
3026 if (!rank_check (matrix_b, 1, 2))
3027 return false;
3028 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
3029 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
3031 gfc_error ("Different shape on dimension 1 for arguments %qs "
3032 "and %qs at %L for intrinsic matmul",
3033 gfc_current_intrinsic_arg[0]->name,
3034 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
3035 return false;
3037 break;
3039 case 2:
3040 if (matrix_b->rank != 2)
3042 if (!rank_check (matrix_b, 1, 1))
3043 return false;
3045 /* matrix_b has rank 1 or 2 here. Common check for the cases
3046 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
3047 - matrix_a has shape (n,m) and matrix_b has shape (m). */
3048 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
3050 gfc_error ("Different shape on dimension 2 for argument %qs and "
3051 "dimension 1 for argument %qs at %L for intrinsic "
3052 "matmul", gfc_current_intrinsic_arg[0]->name,
3053 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
3054 return false;
3056 break;
3058 default:
3059 gfc_error ("%qs argument of %qs intrinsic at %L must be of rank "
3060 "1 or 2", gfc_current_intrinsic_arg[0]->name,
3061 gfc_current_intrinsic, &matrix_a->where);
3062 return false;
3065 return true;
3069 /* Whoever came up with this interface was probably on something.
3070 The possibilities for the occupation of the second and third
3071 parameters are:
3073 Arg #2 Arg #3
3074 NULL NULL
3075 DIM NULL
3076 MASK NULL
3077 NULL MASK minloc(array, mask=m)
3078 DIM MASK
3080 I.e. in the case of minloc(array,mask), mask will be in the second
3081 position of the argument list and we'll have to fix that up. */
3083 bool
3084 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
3086 gfc_expr *a, *m, *d;
3088 a = ap->expr;
3089 if (!int_or_real_check (a, 0) || !array_check (a, 0))
3090 return false;
3092 d = ap->next->expr;
3093 m = ap->next->next->expr;
3095 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
3096 && ap->next->name == NULL)
3098 m = d;
3099 d = NULL;
3100 ap->next->expr = NULL;
3101 ap->next->next->expr = m;
3104 if (!dim_check (d, 1, false))
3105 return false;
3107 if (!dim_rank_check (d, a, 0))
3108 return false;
3110 if (m != NULL && !type_check (m, 2, BT_LOGICAL))
3111 return false;
3113 if (m != NULL
3114 && !gfc_check_conformance (a, m,
3115 "arguments '%s' and '%s' for intrinsic %s",
3116 gfc_current_intrinsic_arg[0]->name,
3117 gfc_current_intrinsic_arg[2]->name,
3118 gfc_current_intrinsic))
3119 return false;
3121 return true;
3125 /* Similar to minloc/maxloc, the argument list might need to be
3126 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
3127 difference is that MINLOC/MAXLOC take an additional KIND argument.
3128 The possibilities are:
3130 Arg #2 Arg #3
3131 NULL NULL
3132 DIM NULL
3133 MASK NULL
3134 NULL MASK minval(array, mask=m)
3135 DIM MASK
3137 I.e. in the case of minval(array,mask), mask will be in the second
3138 position of the argument list and we'll have to fix that up. */
3140 static bool
3141 check_reduction (gfc_actual_arglist *ap)
3143 gfc_expr *a, *m, *d;
3145 a = ap->expr;
3146 d = ap->next->expr;
3147 m = ap->next->next->expr;
3149 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
3150 && ap->next->name == NULL)
3152 m = d;
3153 d = NULL;
3154 ap->next->expr = NULL;
3155 ap->next->next->expr = m;
3158 if (!dim_check (d, 1, false))
3159 return false;
3161 if (!dim_rank_check (d, a, 0))
3162 return false;
3164 if (m != NULL && !type_check (m, 2, BT_LOGICAL))
3165 return false;
3167 if (m != NULL
3168 && !gfc_check_conformance (a, m,
3169 "arguments '%s' and '%s' for intrinsic %s",
3170 gfc_current_intrinsic_arg[0]->name,
3171 gfc_current_intrinsic_arg[2]->name,
3172 gfc_current_intrinsic))
3173 return false;
3175 return true;
3179 bool
3180 gfc_check_minval_maxval (gfc_actual_arglist *ap)
3182 if (!int_or_real_check (ap->expr, 0)
3183 || !array_check (ap->expr, 0))
3184 return false;
3186 return check_reduction (ap);
3190 bool
3191 gfc_check_product_sum (gfc_actual_arglist *ap)
3193 if (!numeric_check (ap->expr, 0)
3194 || !array_check (ap->expr, 0))
3195 return false;
3197 return check_reduction (ap);
3201 /* For IANY, IALL and IPARITY. */
3203 bool
3204 gfc_check_mask (gfc_expr *i, gfc_expr *kind)
3206 int k;
3208 if (!type_check (i, 0, BT_INTEGER))
3209 return false;
3211 if (!nonnegative_check ("I", i))
3212 return false;
3214 if (!kind_check (kind, 1, BT_INTEGER))
3215 return false;
3217 if (kind)
3218 gfc_extract_int (kind, &k);
3219 else
3220 k = gfc_default_integer_kind;
3222 if (!less_than_bitsizekind ("I", i, k))
3223 return false;
3225 return true;
3229 bool
3230 gfc_check_transf_bit_intrins (gfc_actual_arglist *ap)
3232 if (ap->expr->ts.type != BT_INTEGER)
3234 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER",
3235 gfc_current_intrinsic_arg[0]->name,
3236 gfc_current_intrinsic, &ap->expr->where);
3237 return false;
3240 if (!array_check (ap->expr, 0))
3241 return false;
3243 return check_reduction (ap);
3247 bool
3248 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
3250 if (!same_type_check (tsource, 0, fsource, 1))
3251 return false;
3253 if (!type_check (mask, 2, BT_LOGICAL))
3254 return false;
3256 if (tsource->ts.type == BT_CHARACTER)
3257 return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
3259 return true;
3263 bool
3264 gfc_check_merge_bits (gfc_expr *i, gfc_expr *j, gfc_expr *mask)
3266 if (!type_check (i, 0, BT_INTEGER))
3267 return false;
3269 if (!type_check (j, 1, BT_INTEGER))
3270 return false;
3272 if (!type_check (mask, 2, BT_INTEGER))
3273 return false;
3275 if (!same_type_check (i, 0, j, 1))
3276 return false;
3278 if (!same_type_check (i, 0, mask, 2))
3279 return false;
3281 return true;
3285 bool
3286 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
3288 if (!variable_check (from, 0, false))
3289 return false;
3290 if (!allocatable_check (from, 0))
3291 return false;
3292 if (gfc_is_coindexed (from))
3294 gfc_error ("The FROM argument to MOVE_ALLOC at %L shall not be "
3295 "coindexed", &from->where);
3296 return false;
3299 if (!variable_check (to, 1, false))
3300 return false;
3301 if (!allocatable_check (to, 1))
3302 return false;
3303 if (gfc_is_coindexed (to))
3305 gfc_error ("The TO argument to MOVE_ALLOC at %L shall not be "
3306 "coindexed", &to->where);
3307 return false;
3310 if (from->ts.type == BT_CLASS && to->ts.type == BT_DERIVED)
3312 gfc_error ("The TO arguments in MOVE_ALLOC at %L must be "
3313 "polymorphic if FROM is polymorphic",
3314 &to->where);
3315 return false;
3318 if (!same_type_check (to, 1, from, 0))
3319 return false;
3321 if (to->rank != from->rank)
3323 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
3324 "must have the same rank %d/%d", &to->where, from->rank,
3325 to->rank);
3326 return false;
3329 /* IR F08/0040; cf. 12-006A. */
3330 if (gfc_get_corank (to) != gfc_get_corank (from))
3332 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
3333 "must have the same corank %d/%d", &to->where,
3334 gfc_get_corank (from), gfc_get_corank (to));
3335 return false;
3338 /* CLASS arguments: Make sure the vtab of from is present. */
3339 if (to->ts.type == BT_CLASS && !UNLIMITED_POLY (from))
3340 gfc_find_vtab (&from->ts);
3342 return true;
3346 bool
3347 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
3349 if (!type_check (x, 0, BT_REAL))
3350 return false;
3352 if (!type_check (s, 1, BT_REAL))
3353 return false;
3355 if (s->expr_type == EXPR_CONSTANT)
3357 if (mpfr_sgn (s->value.real) == 0)
3359 gfc_error ("Argument %<S%> of NEAREST at %L shall not be zero",
3360 &s->where);
3361 return false;
3365 return true;
3369 bool
3370 gfc_check_new_line (gfc_expr *a)
3372 if (!type_check (a, 0, BT_CHARACTER))
3373 return false;
3375 return true;
3379 bool
3380 gfc_check_norm2 (gfc_expr *array, gfc_expr *dim)
3382 if (!type_check (array, 0, BT_REAL))
3383 return false;
3385 if (!array_check (array, 0))
3386 return false;
3388 if (!dim_rank_check (dim, array, false))
3389 return false;
3391 return true;
3394 bool
3395 gfc_check_null (gfc_expr *mold)
3397 symbol_attribute attr;
3399 if (mold == NULL)
3400 return true;
3402 if (!variable_check (mold, 0, true))
3403 return false;
3405 attr = gfc_variable_attr (mold, NULL);
3407 if (!attr.pointer && !attr.proc_pointer && !attr.allocatable)
3409 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER, "
3410 "ALLOCATABLE or procedure pointer",
3411 gfc_current_intrinsic_arg[0]->name,
3412 gfc_current_intrinsic, &mold->where);
3413 return false;
3416 if (attr.allocatable
3417 && !gfc_notify_std (GFC_STD_F2003, "NULL intrinsic with "
3418 "allocatable MOLD at %L", &mold->where))
3419 return false;
3421 /* F2008, C1242. */
3422 if (gfc_is_coindexed (mold))
3424 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
3425 "coindexed", gfc_current_intrinsic_arg[0]->name,
3426 gfc_current_intrinsic, &mold->where);
3427 return false;
3430 return true;
3434 bool
3435 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
3437 if (!array_check (array, 0))
3438 return false;
3440 if (!type_check (mask, 1, BT_LOGICAL))
3441 return false;
3443 if (!gfc_check_conformance (array, mask,
3444 "arguments '%s' and '%s' for intrinsic '%s'",
3445 gfc_current_intrinsic_arg[0]->name,
3446 gfc_current_intrinsic_arg[1]->name,
3447 gfc_current_intrinsic))
3448 return false;
3450 if (vector != NULL)
3452 mpz_t array_size, vector_size;
3453 bool have_array_size, have_vector_size;
3455 if (!same_type_check (array, 0, vector, 2))
3456 return false;
3458 if (!rank_check (vector, 2, 1))
3459 return false;
3461 /* VECTOR requires at least as many elements as MASK
3462 has .TRUE. values. */
3463 have_array_size = gfc_array_size(array, &array_size);
3464 have_vector_size = gfc_array_size(vector, &vector_size);
3466 if (have_vector_size
3467 && (mask->expr_type == EXPR_ARRAY
3468 || (mask->expr_type == EXPR_CONSTANT
3469 && have_array_size)))
3471 int mask_true_values = 0;
3473 if (mask->expr_type == EXPR_ARRAY)
3475 gfc_constructor *mask_ctor;
3476 mask_ctor = gfc_constructor_first (mask->value.constructor);
3477 while (mask_ctor)
3479 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
3481 mask_true_values = 0;
3482 break;
3485 if (mask_ctor->expr->value.logical)
3486 mask_true_values++;
3488 mask_ctor = gfc_constructor_next (mask_ctor);
3491 else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
3492 mask_true_values = mpz_get_si (array_size);
3494 if (mpz_get_si (vector_size) < mask_true_values)
3496 gfc_error ("%qs argument of %qs intrinsic at %L must "
3497 "provide at least as many elements as there "
3498 "are .TRUE. values in %qs (%ld/%d)",
3499 gfc_current_intrinsic_arg[2]->name,
3500 gfc_current_intrinsic, &vector->where,
3501 gfc_current_intrinsic_arg[1]->name,
3502 mpz_get_si (vector_size), mask_true_values);
3503 return false;
3507 if (have_array_size)
3508 mpz_clear (array_size);
3509 if (have_vector_size)
3510 mpz_clear (vector_size);
3513 return true;
3517 bool
3518 gfc_check_parity (gfc_expr *mask, gfc_expr *dim)
3520 if (!type_check (mask, 0, BT_LOGICAL))
3521 return false;
3523 if (!array_check (mask, 0))
3524 return false;
3526 if (!dim_rank_check (dim, mask, false))
3527 return false;
3529 return true;
3533 bool
3534 gfc_check_precision (gfc_expr *x)
3536 if (!real_or_complex_check (x, 0))
3537 return false;
3539 return true;
3543 bool
3544 gfc_check_present (gfc_expr *a)
3546 gfc_symbol *sym;
3548 if (!variable_check (a, 0, true))
3549 return false;
3551 sym = a->symtree->n.sym;
3552 if (!sym->attr.dummy)
3554 gfc_error ("%qs argument of %qs intrinsic at %L must be of a "
3555 "dummy variable", gfc_current_intrinsic_arg[0]->name,
3556 gfc_current_intrinsic, &a->where);
3557 return false;
3560 if (!sym->attr.optional)
3562 gfc_error ("%qs argument of %qs intrinsic at %L must be of "
3563 "an OPTIONAL dummy variable",
3564 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3565 &a->where);
3566 return false;
3569 /* 13.14.82 PRESENT(A)
3570 ......
3571 Argument. A shall be the name of an optional dummy argument that is
3572 accessible in the subprogram in which the PRESENT function reference
3573 appears... */
3575 if (a->ref != NULL
3576 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
3577 && (a->ref->u.ar.type == AR_FULL
3578 || (a->ref->u.ar.type == AR_ELEMENT
3579 && a->ref->u.ar.as->rank == 0))))
3581 gfc_error ("%qs argument of %qs intrinsic at %L must not be a "
3582 "subobject of %qs", gfc_current_intrinsic_arg[0]->name,
3583 gfc_current_intrinsic, &a->where, sym->name);
3584 return false;
3587 return true;
3591 bool
3592 gfc_check_radix (gfc_expr *x)
3594 if (!int_or_real_check (x, 0))
3595 return false;
3597 return true;
3601 bool
3602 gfc_check_range (gfc_expr *x)
3604 if (!numeric_check (x, 0))
3605 return false;
3607 return true;
3611 bool
3612 gfc_check_rank (gfc_expr *a ATTRIBUTE_UNUSED)
3614 /* Any data object is allowed; a "data object" is a "constant (4.1.3),
3615 variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
3617 bool is_variable = true;
3619 /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
3620 if (a->expr_type == EXPR_FUNCTION)
3621 is_variable = a->value.function.esym
3622 ? a->value.function.esym->result->attr.pointer
3623 : a->symtree->n.sym->result->attr.pointer;
3625 if (a->expr_type == EXPR_OP || a->expr_type == EXPR_NULL
3626 || a->expr_type == EXPR_COMPCALL|| a->expr_type == EXPR_PPC
3627 || !is_variable)
3629 gfc_error ("The argument of the RANK intrinsic at %L must be a data "
3630 "object", &a->where);
3631 return false;
3634 return true;
3638 /* real, float, sngl. */
3639 bool
3640 gfc_check_real (gfc_expr *a, gfc_expr *kind)
3642 if (!numeric_check (a, 0))
3643 return false;
3645 if (!kind_check (kind, 1, BT_REAL))
3646 return false;
3648 return true;
3652 bool
3653 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
3655 if (!type_check (path1, 0, BT_CHARACTER))
3656 return false;
3657 if (!kind_value_check (path1, 0, gfc_default_character_kind))
3658 return false;
3660 if (!type_check (path2, 1, BT_CHARACTER))
3661 return false;
3662 if (!kind_value_check (path2, 1, gfc_default_character_kind))
3663 return false;
3665 return true;
3669 bool
3670 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
3672 if (!type_check (path1, 0, BT_CHARACTER))
3673 return false;
3674 if (!kind_value_check (path1, 0, gfc_default_character_kind))
3675 return false;
3677 if (!type_check (path2, 1, BT_CHARACTER))
3678 return false;
3679 if (!kind_value_check (path2, 1, gfc_default_character_kind))
3680 return false;
3682 if (status == NULL)
3683 return true;
3685 if (!type_check (status, 2, BT_INTEGER))
3686 return false;
3688 if (!scalar_check (status, 2))
3689 return false;
3691 return true;
3695 bool
3696 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
3698 if (!type_check (x, 0, BT_CHARACTER))
3699 return false;
3701 if (!scalar_check (x, 0))
3702 return false;
3704 if (!type_check (y, 0, BT_INTEGER))
3705 return false;
3707 if (!scalar_check (y, 1))
3708 return false;
3710 return true;
3714 bool
3715 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
3716 gfc_expr *pad, gfc_expr *order)
3718 mpz_t size;
3719 mpz_t nelems;
3720 int shape_size;
3722 if (!array_check (source, 0))
3723 return false;
3725 if (!rank_check (shape, 1, 1))
3726 return false;
3728 if (!type_check (shape, 1, BT_INTEGER))
3729 return false;
3731 if (!gfc_array_size (shape, &size))
3733 gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L must be an "
3734 "array of constant size", &shape->where);
3735 return false;
3738 shape_size = mpz_get_ui (size);
3739 mpz_clear (size);
3741 if (shape_size <= 0)
3743 gfc_error ("%qs argument of %qs intrinsic at %L is empty",
3744 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3745 &shape->where);
3746 return false;
3748 else if (shape_size > GFC_MAX_DIMENSIONS)
3750 gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L has more "
3751 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
3752 return false;
3754 else if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape))
3756 gfc_expr *e;
3757 int i, extent;
3758 for (i = 0; i < shape_size; ++i)
3760 e = gfc_constructor_lookup_expr (shape->value.constructor, i);
3761 if (e->expr_type != EXPR_CONSTANT)
3762 continue;
3764 gfc_extract_int (e, &extent);
3765 if (extent < 0)
3767 gfc_error ("%qs argument of %qs intrinsic at %L has "
3768 "negative element (%d)",
3769 gfc_current_intrinsic_arg[1]->name,
3770 gfc_current_intrinsic, &e->where, extent);
3771 return false;
3775 else if (shape->expr_type == EXPR_VARIABLE && shape->ref
3776 && shape->ref->u.ar.type == AR_FULL && shape->ref->u.ar.dimen == 1
3777 && shape->ref->u.ar.as
3778 && shape->ref->u.ar.as->lower[0]->expr_type == EXPR_CONSTANT
3779 && shape->ref->u.ar.as->lower[0]->ts.type == BT_INTEGER
3780 && shape->ref->u.ar.as->upper[0]->expr_type == EXPR_CONSTANT
3781 && shape->ref->u.ar.as->upper[0]->ts.type == BT_INTEGER
3782 && shape->symtree->n.sym->attr.flavor == FL_PARAMETER)
3784 int i, extent;
3785 gfc_expr *e, *v;
3787 v = shape->symtree->n.sym->value;
3789 for (i = 0; i < shape_size; i++)
3791 e = gfc_constructor_lookup_expr (v->value.constructor, i);
3792 if (e == NULL)
3793 break;
3795 gfc_extract_int (e, &extent);
3797 if (extent < 0)
3799 gfc_error ("Element %d of actual argument of RESHAPE at %L "
3800 "cannot be negative", i + 1, &shape->where);
3801 return false;
3806 if (pad != NULL)
3808 if (!same_type_check (source, 0, pad, 2))
3809 return false;
3811 if (!array_check (pad, 2))
3812 return false;
3815 if (order != NULL)
3817 if (!array_check (order, 3))
3818 return false;
3820 if (!type_check (order, 3, BT_INTEGER))
3821 return false;
3823 if (order->expr_type == EXPR_ARRAY)
3825 int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
3826 gfc_expr *e;
3828 for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
3829 perm[i] = 0;
3831 gfc_array_size (order, &size);
3832 order_size = mpz_get_ui (size);
3833 mpz_clear (size);
3835 if (order_size != shape_size)
3837 gfc_error ("%qs argument of %qs intrinsic at %L "
3838 "has wrong number of elements (%d/%d)",
3839 gfc_current_intrinsic_arg[3]->name,
3840 gfc_current_intrinsic, &order->where,
3841 order_size, shape_size);
3842 return false;
3845 for (i = 1; i <= order_size; ++i)
3847 e = gfc_constructor_lookup_expr (order->value.constructor, i-1);
3848 if (e->expr_type != EXPR_CONSTANT)
3849 continue;
3851 gfc_extract_int (e, &dim);
3853 if (dim < 1 || dim > order_size)
3855 gfc_error ("%qs argument of %qs intrinsic at %L "
3856 "has out-of-range dimension (%d)",
3857 gfc_current_intrinsic_arg[3]->name,
3858 gfc_current_intrinsic, &e->where, dim);
3859 return false;
3862 if (perm[dim-1] != 0)
3864 gfc_error ("%qs argument of %qs intrinsic at %L has "
3865 "invalid permutation of dimensions (dimension "
3866 "%qd duplicated)",
3867 gfc_current_intrinsic_arg[3]->name,
3868 gfc_current_intrinsic, &e->where, dim);
3869 return false;
3872 perm[dim-1] = 1;
3877 if (pad == NULL && shape->expr_type == EXPR_ARRAY
3878 && gfc_is_constant_expr (shape)
3879 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
3880 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
3882 /* Check the match in size between source and destination. */
3883 if (gfc_array_size (source, &nelems))
3885 gfc_constructor *c;
3886 bool test;
3889 mpz_init_set_ui (size, 1);
3890 for (c = gfc_constructor_first (shape->value.constructor);
3891 c; c = gfc_constructor_next (c))
3892 mpz_mul (size, size, c->expr->value.integer);
3894 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
3895 mpz_clear (nelems);
3896 mpz_clear (size);
3898 if (test)
3900 gfc_error ("Without padding, there are not enough elements "
3901 "in the intrinsic RESHAPE source at %L to match "
3902 "the shape", &source->where);
3903 return false;
3908 return true;
3912 bool
3913 gfc_check_same_type_as (gfc_expr *a, gfc_expr *b)
3915 if (a->ts.type != BT_DERIVED && a->ts.type != BT_CLASS)
3917 gfc_error ("%qs argument of %qs intrinsic at %L "
3918 "cannot be of type %s",
3919 gfc_current_intrinsic_arg[0]->name,
3920 gfc_current_intrinsic,
3921 &a->where, gfc_typename (&a->ts));
3922 return false;
3925 if (!(gfc_type_is_extensible (a->ts.u.derived) || UNLIMITED_POLY (a)))
3927 gfc_error ("%qs argument of %qs intrinsic at %L "
3928 "must be of an extensible type",
3929 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3930 &a->where);
3931 return false;
3934 if (b->ts.type != BT_DERIVED && b->ts.type != BT_CLASS)
3936 gfc_error ("%qs argument of %qs intrinsic at %L "
3937 "cannot be of type %s",
3938 gfc_current_intrinsic_arg[0]->name,
3939 gfc_current_intrinsic,
3940 &b->where, gfc_typename (&b->ts));
3941 return false;
3944 if (!(gfc_type_is_extensible (b->ts.u.derived) || UNLIMITED_POLY (b)))
3946 gfc_error ("%qs argument of %qs intrinsic at %L "
3947 "must be of an extensible type",
3948 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3949 &b->where);
3950 return false;
3953 return true;
3957 bool
3958 gfc_check_scale (gfc_expr *x, gfc_expr *i)
3960 if (!type_check (x, 0, BT_REAL))
3961 return false;
3963 if (!type_check (i, 1, BT_INTEGER))
3964 return false;
3966 return true;
3970 bool
3971 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
3973 if (!type_check (x, 0, BT_CHARACTER))
3974 return false;
3976 if (!type_check (y, 1, BT_CHARACTER))
3977 return false;
3979 if (z != NULL && !type_check (z, 2, BT_LOGICAL))
3980 return false;
3982 if (!kind_check (kind, 3, BT_INTEGER))
3983 return false;
3984 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
3985 "with KIND argument at %L",
3986 gfc_current_intrinsic, &kind->where))
3987 return false;
3989 if (!same_type_check (x, 0, y, 1))
3990 return false;
3992 return true;
3996 bool
3997 gfc_check_secnds (gfc_expr *r)
3999 if (!type_check (r, 0, BT_REAL))
4000 return false;
4002 if (!kind_value_check (r, 0, 4))
4003 return false;
4005 if (!scalar_check (r, 0))
4006 return false;
4008 return true;
4012 bool
4013 gfc_check_selected_char_kind (gfc_expr *name)
4015 if (!type_check (name, 0, BT_CHARACTER))
4016 return false;
4018 if (!kind_value_check (name, 0, gfc_default_character_kind))
4019 return false;
4021 if (!scalar_check (name, 0))
4022 return false;
4024 return true;
4028 bool
4029 gfc_check_selected_int_kind (gfc_expr *r)
4031 if (!type_check (r, 0, BT_INTEGER))
4032 return false;
4034 if (!scalar_check (r, 0))
4035 return false;
4037 return true;
4041 bool
4042 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r, gfc_expr *radix)
4044 if (p == NULL && r == NULL
4045 && !gfc_notify_std (GFC_STD_F2008, "SELECTED_REAL_KIND with"
4046 " neither %<P%> nor %<R%> argument at %L",
4047 gfc_current_intrinsic_where))
4048 return false;
4050 if (p)
4052 if (!type_check (p, 0, BT_INTEGER))
4053 return false;
4055 if (!scalar_check (p, 0))
4056 return false;
4059 if (r)
4061 if (!type_check (r, 1, BT_INTEGER))
4062 return false;
4064 if (!scalar_check (r, 1))
4065 return false;
4068 if (radix)
4070 if (!type_check (radix, 1, BT_INTEGER))
4071 return false;
4073 if (!scalar_check (radix, 1))
4074 return false;
4076 if (!gfc_notify_std (GFC_STD_F2008, "%qs intrinsic with "
4077 "RADIX argument at %L", gfc_current_intrinsic,
4078 &radix->where))
4079 return false;
4082 return true;
4086 bool
4087 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
4089 if (!type_check (x, 0, BT_REAL))
4090 return false;
4092 if (!type_check (i, 1, BT_INTEGER))
4093 return false;
4095 return true;
4099 bool
4100 gfc_check_shape (gfc_expr *source, gfc_expr *kind)
4102 gfc_array_ref *ar;
4104 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
4105 return true;
4107 ar = gfc_find_array_ref (source);
4109 if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
4111 gfc_error ("%<source%> argument of %<shape%> intrinsic at %L must not be "
4112 "an assumed size array", &source->where);
4113 return false;
4116 if (!kind_check (kind, 1, BT_INTEGER))
4117 return false;
4118 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
4119 "with KIND argument at %L",
4120 gfc_current_intrinsic, &kind->where))
4121 return false;
4123 return true;
4127 bool
4128 gfc_check_shift (gfc_expr *i, gfc_expr *shift)
4130 if (!type_check (i, 0, BT_INTEGER))
4131 return false;
4133 if (!type_check (shift, 0, BT_INTEGER))
4134 return false;
4136 if (!nonnegative_check ("SHIFT", shift))
4137 return false;
4139 if (!less_than_bitsize1 ("I", i, "SHIFT", shift, true))
4140 return false;
4142 return true;
4146 bool
4147 gfc_check_sign (gfc_expr *a, gfc_expr *b)
4149 if (!int_or_real_check (a, 0))
4150 return false;
4152 if (!same_type_check (a, 0, b, 1))
4153 return false;
4155 return true;
4159 bool
4160 gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
4162 if (!array_check (array, 0))
4163 return false;
4165 if (!dim_check (dim, 1, true))
4166 return false;
4168 if (!dim_rank_check (dim, array, 0))
4169 return false;
4171 if (!kind_check (kind, 2, BT_INTEGER))
4172 return false;
4173 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
4174 "with KIND argument at %L",
4175 gfc_current_intrinsic, &kind->where))
4176 return false;
4179 return true;
4183 bool
4184 gfc_check_sizeof (gfc_expr *arg)
4186 if (arg->ts.type == BT_PROCEDURE)
4188 gfc_error ("%qs argument of %qs intrinsic at %L shall not be a procedure",
4189 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4190 &arg->where);
4191 return false;
4194 /* TYPE(*) is acceptable if and only if it uses an array descriptor. */
4195 if (arg->ts.type == BT_ASSUMED
4196 && (arg->symtree->n.sym->as == NULL
4197 || (arg->symtree->n.sym->as->type != AS_ASSUMED_SHAPE
4198 && arg->symtree->n.sym->as->type != AS_DEFERRED
4199 && arg->symtree->n.sym->as->type != AS_ASSUMED_RANK)))
4201 gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
4202 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4203 &arg->where);
4204 return false;
4207 if (arg->rank && arg->expr_type == EXPR_VARIABLE
4208 && arg->symtree->n.sym->as != NULL
4209 && arg->symtree->n.sym->as->type == AS_ASSUMED_SIZE && arg->ref
4210 && arg->ref->type == REF_ARRAY && arg->ref->u.ar.type == AR_FULL)
4212 gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
4213 "assumed-size array", gfc_current_intrinsic_arg[0]->name,
4214 gfc_current_intrinsic, &arg->where);
4215 return false;
4218 return true;
4222 /* Check whether an expression is interoperable. When returning false,
4223 msg is set to a string telling why the expression is not interoperable,
4224 otherwise, it is set to NULL. The msg string can be used in diagnostics.
4225 If c_loc is true, character with len > 1 are allowed (cf. Fortran
4226 2003corr5); additionally, assumed-shape/assumed-rank/deferred-shape
4227 arrays are permitted. And if c_f_ptr is true, deferred-shape arrays
4228 are permitted. */
4230 static bool
4231 is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr)
4233 *msg = NULL;
4235 if (expr->ts.type == BT_CLASS)
4237 *msg = "Expression is polymorphic";
4238 return false;
4241 if (expr->ts.type == BT_DERIVED && !expr->ts.u.derived->attr.is_bind_c
4242 && !expr->ts.u.derived->ts.is_iso_c)
4244 *msg = "Expression is a noninteroperable derived type";
4245 return false;
4248 if (expr->ts.type == BT_PROCEDURE)
4250 *msg = "Procedure unexpected as argument";
4251 return false;
4254 if (gfc_notification_std (GFC_STD_GNU) && expr->ts.type == BT_LOGICAL)
4256 int i;
4257 for (i = 0; gfc_logical_kinds[i].kind; i++)
4258 if (gfc_logical_kinds[i].kind == expr->ts.kind)
4259 return true;
4260 *msg = "Extension to use a non-C_Bool-kind LOGICAL";
4261 return false;
4264 if (gfc_notification_std (GFC_STD_GNU) && expr->ts.type == BT_CHARACTER
4265 && expr->ts.kind != 1)
4267 *msg = "Extension to use a non-C_CHAR-kind CHARACTER";
4268 return false;
4271 if (expr->ts.type == BT_CHARACTER) {
4272 if (expr->ts.deferred)
4274 /* TS 29113 allows deferred-length strings as dummy arguments,
4275 but it is not an interoperable type. */
4276 *msg = "Expression shall not be a deferred-length string";
4277 return false;
4280 if (expr->ts.u.cl && expr->ts.u.cl->length
4281 && !gfc_simplify_expr (expr, 0))
4282 gfc_internal_error ("is_c_interoperable(): gfc_simplify_expr failed");
4284 if (!c_loc && expr->ts.u.cl
4285 && (!expr->ts.u.cl->length
4286 || expr->ts.u.cl->length->expr_type != EXPR_CONSTANT
4287 || mpz_cmp_si (expr->ts.u.cl->length->value.integer, 1) != 0))
4289 *msg = "Type shall have a character length of 1";
4290 return false;
4294 /* Note: The following checks are about interoperatable variables, Fortran
4295 15.3.5/15.3.6. In intrinsics like C_LOC or in procedure interface, more
4296 is allowed, e.g. assumed-shape arrays with TS 29113. */
4298 if (gfc_is_coarray (expr))
4300 *msg = "Coarrays are not interoperable";
4301 return false;
4304 if (!c_loc && expr->rank > 0 && expr->expr_type != EXPR_ARRAY)
4306 gfc_array_ref *ar = gfc_find_array_ref (expr);
4307 if (ar->type != AR_FULL)
4309 *msg = "Only whole-arrays are interoperable";
4310 return false;
4312 if (!c_f_ptr && ar->as->type != AS_EXPLICIT
4313 && ar->as->type != AS_ASSUMED_SIZE)
4315 *msg = "Only explicit-size and assumed-size arrays are interoperable";
4316 return false;
4320 return true;
4324 bool
4325 gfc_check_c_sizeof (gfc_expr *arg)
4327 const char *msg;
4329 if (!is_c_interoperable (arg, &msg, false, false))
4331 gfc_error ("%qs argument of %qs intrinsic at %L must be an "
4332 "interoperable data entity: %s",
4333 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4334 &arg->where, msg);
4335 return false;
4338 if (arg->ts.type == BT_ASSUMED)
4340 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
4341 "TYPE(*)",
4342 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4343 &arg->where);
4344 return false;
4347 if (arg->rank && arg->expr_type == EXPR_VARIABLE
4348 && arg->symtree->n.sym->as != NULL
4349 && arg->symtree->n.sym->as->type == AS_ASSUMED_SIZE && arg->ref
4350 && arg->ref->type == REF_ARRAY && arg->ref->u.ar.type == AR_FULL)
4352 gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
4353 "assumed-size array", gfc_current_intrinsic_arg[0]->name,
4354 gfc_current_intrinsic, &arg->where);
4355 return false;
4358 return true;
4362 bool
4363 gfc_check_c_associated (gfc_expr *c_ptr_1, gfc_expr *c_ptr_2)
4365 if (c_ptr_1->ts.type != BT_DERIVED
4366 || c_ptr_1->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
4367 || (c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR
4368 && c_ptr_1->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR))
4370 gfc_error ("Argument C_PTR_1 at %L to C_ASSOCIATED shall have the "
4371 "type TYPE(C_PTR) or TYPE(C_FUNPTR)", &c_ptr_1->where);
4372 return false;
4375 if (!scalar_check (c_ptr_1, 0))
4376 return false;
4378 if (c_ptr_2
4379 && (c_ptr_2->ts.type != BT_DERIVED
4380 || c_ptr_2->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
4381 || (c_ptr_1->ts.u.derived->intmod_sym_id
4382 != c_ptr_2->ts.u.derived->intmod_sym_id)))
4384 gfc_error ("Argument C_PTR_2 at %L to C_ASSOCIATED shall have the "
4385 "same type as C_PTR_1: %s instead of %s", &c_ptr_1->where,
4386 gfc_typename (&c_ptr_1->ts),
4387 gfc_typename (&c_ptr_2->ts));
4388 return false;
4391 if (c_ptr_2 && !scalar_check (c_ptr_2, 1))
4392 return false;
4394 return true;
4398 bool
4399 gfc_check_c_f_pointer (gfc_expr *cptr, gfc_expr *fptr, gfc_expr *shape)
4401 symbol_attribute attr;
4402 const char *msg;
4404 if (cptr->ts.type != BT_DERIVED
4405 || cptr->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
4406 || cptr->ts.u.derived->intmod_sym_id != ISOCBINDING_PTR)
4408 gfc_error ("Argument CPTR at %L to C_F_POINTER shall have the "
4409 "type TYPE(C_PTR)", &cptr->where);
4410 return false;
4413 if (!scalar_check (cptr, 0))
4414 return false;
4416 attr = gfc_expr_attr (fptr);
4418 if (!attr.pointer)
4420 gfc_error ("Argument FPTR at %L to C_F_POINTER must be a pointer",
4421 &fptr->where);
4422 return false;
4425 if (fptr->ts.type == BT_CLASS)
4427 gfc_error ("FPTR argument at %L to C_F_POINTER shall not be polymorphic",
4428 &fptr->where);
4429 return false;
4432 if (gfc_is_coindexed (fptr))
4434 gfc_error ("Argument FPTR at %L to C_F_POINTER shall not be "
4435 "coindexed", &fptr->where);
4436 return false;
4439 if (fptr->rank == 0 && shape)
4441 gfc_error ("Unexpected SHAPE argument at %L to C_F_POINTER with scalar "
4442 "FPTR", &fptr->where);
4443 return false;
4445 else if (fptr->rank && !shape)
4447 gfc_error ("Expected SHAPE argument to C_F_POINTER with array "
4448 "FPTR at %L", &fptr->where);
4449 return false;
4452 if (shape && !rank_check (shape, 2, 1))
4453 return false;
4455 if (shape && !type_check (shape, 2, BT_INTEGER))
4456 return false;
4458 if (shape)
4460 mpz_t size;
4461 if (gfc_array_size (shape, &size))
4463 if (mpz_cmp_ui (size, fptr->rank) != 0)
4465 mpz_clear (size);
4466 gfc_error ("SHAPE argument at %L to C_F_POINTER must have the same "
4467 "size as the RANK of FPTR", &shape->where);
4468 return false;
4470 mpz_clear (size);
4474 if (fptr->ts.type == BT_CLASS)
4476 gfc_error ("Polymorphic FPTR at %L to C_F_POINTER", &fptr->where);
4477 return false;
4480 if (!is_c_interoperable (fptr, &msg, false, true))
4481 return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable array FPTR "
4482 "at %L to C_F_POINTER: %s", &fptr->where, msg);
4484 return true;
4488 bool
4489 gfc_check_c_f_procpointer (gfc_expr *cptr, gfc_expr *fptr)
4491 symbol_attribute attr;
4493 if (cptr->ts.type != BT_DERIVED
4494 || cptr->ts.u.derived->from_intmod != INTMOD_ISO_C_BINDING
4495 || cptr->ts.u.derived->intmod_sym_id != ISOCBINDING_FUNPTR)
4497 gfc_error ("Argument CPTR at %L to C_F_PROCPOINTER shall have the "
4498 "type TYPE(C_FUNPTR)", &cptr->where);
4499 return false;
4502 if (!scalar_check (cptr, 0))
4503 return false;
4505 attr = gfc_expr_attr (fptr);
4507 if (!attr.proc_pointer)
4509 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall be a procedure "
4510 "pointer", &fptr->where);
4511 return false;
4514 if (gfc_is_coindexed (fptr))
4516 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall not be "
4517 "coindexed", &fptr->where);
4518 return false;
4521 if (!attr.is_bind_c)
4522 return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable procedure "
4523 "pointer at %L to C_F_PROCPOINTER", &fptr->where);
4525 return true;
4529 bool
4530 gfc_check_c_funloc (gfc_expr *x)
4532 symbol_attribute attr;
4534 if (gfc_is_coindexed (x))
4536 gfc_error ("Argument X at %L to C_FUNLOC shall not be "
4537 "coindexed", &x->where);
4538 return false;
4541 attr = gfc_expr_attr (x);
4543 if (attr.function && !attr.proc_pointer && x->expr_type == EXPR_VARIABLE
4544 && x->symtree->n.sym == x->symtree->n.sym->result)
4546 gfc_namespace *ns = gfc_current_ns;
4548 for (ns = gfc_current_ns; ns; ns = ns->parent)
4549 if (x->symtree->n.sym == ns->proc_name)
4551 gfc_error ("Function result %qs at %L is invalid as X argument "
4552 "to C_FUNLOC", x->symtree->n.sym->name, &x->where);
4553 return false;
4557 if (attr.flavor != FL_PROCEDURE)
4559 gfc_error ("Argument X at %L to C_FUNLOC shall be a procedure "
4560 "or a procedure pointer", &x->where);
4561 return false;
4564 if (!attr.is_bind_c)
4565 return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable procedure "
4566 "at %L to C_FUNLOC", &x->where);
4567 return true;
4571 bool
4572 gfc_check_c_loc (gfc_expr *x)
4574 symbol_attribute attr;
4575 const char *msg;
4577 if (gfc_is_coindexed (x))
4579 gfc_error ("Argument X at %L to C_LOC shall not be coindexed", &x->where);
4580 return false;
4583 if (x->ts.type == BT_CLASS)
4585 gfc_error ("X argument at %L to C_LOC shall not be polymorphic",
4586 &x->where);
4587 return false;
4590 attr = gfc_expr_attr (x);
4592 if (!attr.pointer
4593 && (x->expr_type != EXPR_VARIABLE || !attr.target
4594 || attr.flavor == FL_PARAMETER))
4596 gfc_error ("Argument X at %L to C_LOC shall have either "
4597 "the POINTER or the TARGET attribute", &x->where);
4598 return false;
4601 if (x->ts.type == BT_CHARACTER
4602 && gfc_var_strlen (x) == 0)
4604 gfc_error ("Argument X at %L to C_LOC shall be not be a zero-sized "
4605 "string", &x->where);
4606 return false;
4609 if (!is_c_interoperable (x, &msg, true, false))
4611 if (x->ts.type == BT_CLASS)
4613 gfc_error ("Argument at %L to C_LOC shall not be polymorphic",
4614 &x->where);
4615 return false;
4618 if (x->rank
4619 && !gfc_notify_std (GFC_STD_F2008_TS,
4620 "Noninteroperable array at %L as"
4621 " argument to C_LOC: %s", &x->where, msg))
4622 return false;
4624 else if (x->rank > 0 && gfc_notification_std (GFC_STD_F2008))
4626 gfc_array_ref *ar = gfc_find_array_ref (x);
4628 if (ar->as->type != AS_EXPLICIT && ar->as->type != AS_ASSUMED_SIZE
4629 && !attr.allocatable
4630 && !gfc_notify_std (GFC_STD_F2008,
4631 "Array of interoperable type at %L "
4632 "to C_LOC which is nonallocatable and neither "
4633 "assumed size nor explicit size", &x->where))
4634 return false;
4635 else if (ar->type != AR_FULL
4636 && !gfc_notify_std (GFC_STD_F2008, "Array section at %L "
4637 "to C_LOC", &x->where))
4638 return false;
4641 return true;
4645 bool
4646 gfc_check_sleep_sub (gfc_expr *seconds)
4648 if (!type_check (seconds, 0, BT_INTEGER))
4649 return false;
4651 if (!scalar_check (seconds, 0))
4652 return false;
4654 return true;
4657 bool
4658 gfc_check_sngl (gfc_expr *a)
4660 if (!type_check (a, 0, BT_REAL))
4661 return false;
4663 if ((a->ts.kind != gfc_default_double_kind)
4664 && !gfc_notify_std (GFC_STD_GNU, "non double precision "
4665 "REAL argument to %s intrinsic at %L",
4666 gfc_current_intrinsic, &a->where))
4667 return false;
4669 return true;
4672 bool
4673 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
4675 if (source->rank >= GFC_MAX_DIMENSIONS)
4677 gfc_error ("%qs argument of %qs intrinsic at %L must be less "
4678 "than rank %d", gfc_current_intrinsic_arg[0]->name,
4679 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
4681 return false;
4684 if (dim == NULL)
4685 return false;
4687 if (!dim_check (dim, 1, false))
4688 return false;
4690 /* dim_rank_check() does not apply here. */
4691 if (dim
4692 && dim->expr_type == EXPR_CONSTANT
4693 && (mpz_cmp_ui (dim->value.integer, 1) < 0
4694 || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0))
4696 gfc_error ("%qs argument of %qs intrinsic at %L is not a valid "
4697 "dimension index", gfc_current_intrinsic_arg[1]->name,
4698 gfc_current_intrinsic, &dim->where);
4699 return false;
4702 if (!type_check (ncopies, 2, BT_INTEGER))
4703 return false;
4705 if (!scalar_check (ncopies, 2))
4706 return false;
4708 return true;
4712 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
4713 functions). */
4715 bool
4716 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
4718 if (!type_check (unit, 0, BT_INTEGER))
4719 return false;
4721 if (!scalar_check (unit, 0))
4722 return false;
4724 if (!type_check (c, 1, BT_CHARACTER))
4725 return false;
4726 if (!kind_value_check (c, 1, gfc_default_character_kind))
4727 return false;
4729 if (status == NULL)
4730 return true;
4732 if (!type_check (status, 2, BT_INTEGER)
4733 || !kind_value_check (status, 2, gfc_default_integer_kind)
4734 || !scalar_check (status, 2))
4735 return false;
4737 return true;
4741 bool
4742 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
4744 return gfc_check_fgetputc_sub (unit, c, NULL);
4748 bool
4749 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
4751 if (!type_check (c, 0, BT_CHARACTER))
4752 return false;
4753 if (!kind_value_check (c, 0, gfc_default_character_kind))
4754 return false;
4756 if (status == NULL)
4757 return true;
4759 if (!type_check (status, 1, BT_INTEGER)
4760 || !kind_value_check (status, 1, gfc_default_integer_kind)
4761 || !scalar_check (status, 1))
4762 return false;
4764 return true;
4768 bool
4769 gfc_check_fgetput (gfc_expr *c)
4771 return gfc_check_fgetput_sub (c, NULL);
4775 bool
4776 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
4778 if (!type_check (unit, 0, BT_INTEGER))
4779 return false;
4781 if (!scalar_check (unit, 0))
4782 return false;
4784 if (!type_check (offset, 1, BT_INTEGER))
4785 return false;
4787 if (!scalar_check (offset, 1))
4788 return false;
4790 if (!type_check (whence, 2, BT_INTEGER))
4791 return false;
4793 if (!scalar_check (whence, 2))
4794 return false;
4796 if (status == NULL)
4797 return true;
4799 if (!type_check (status, 3, BT_INTEGER))
4800 return false;
4802 if (!kind_value_check (status, 3, 4))
4803 return false;
4805 if (!scalar_check (status, 3))
4806 return false;
4808 return true;
4813 bool
4814 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
4816 if (!type_check (unit, 0, BT_INTEGER))
4817 return false;
4819 if (!scalar_check (unit, 0))
4820 return false;
4822 if (!type_check (array, 1, BT_INTEGER)
4823 || !kind_value_check (unit, 0, gfc_default_integer_kind))
4824 return false;
4826 if (!array_check (array, 1))
4827 return false;
4829 return true;
4833 bool
4834 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
4836 if (!type_check (unit, 0, BT_INTEGER))
4837 return false;
4839 if (!scalar_check (unit, 0))
4840 return false;
4842 if (!type_check (array, 1, BT_INTEGER)
4843 || !kind_value_check (array, 1, gfc_default_integer_kind))
4844 return false;
4846 if (!array_check (array, 1))
4847 return false;
4849 if (status == NULL)
4850 return true;
4852 if (!type_check (status, 2, BT_INTEGER)
4853 || !kind_value_check (status, 2, gfc_default_integer_kind))
4854 return false;
4856 if (!scalar_check (status, 2))
4857 return false;
4859 return true;
4863 bool
4864 gfc_check_ftell (gfc_expr *unit)
4866 if (!type_check (unit, 0, BT_INTEGER))
4867 return false;
4869 if (!scalar_check (unit, 0))
4870 return false;
4872 return true;
4876 bool
4877 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
4879 if (!type_check (unit, 0, BT_INTEGER))
4880 return false;
4882 if (!scalar_check (unit, 0))
4883 return false;
4885 if (!type_check (offset, 1, BT_INTEGER))
4886 return false;
4888 if (!scalar_check (offset, 1))
4889 return false;
4891 return true;
4895 bool
4896 gfc_check_stat (gfc_expr *name, gfc_expr *array)
4898 if (!type_check (name, 0, BT_CHARACTER))
4899 return false;
4900 if (!kind_value_check (name, 0, gfc_default_character_kind))
4901 return false;
4903 if (!type_check (array, 1, BT_INTEGER)
4904 || !kind_value_check (array, 1, gfc_default_integer_kind))
4905 return false;
4907 if (!array_check (array, 1))
4908 return false;
4910 return true;
4914 bool
4915 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
4917 if (!type_check (name, 0, BT_CHARACTER))
4918 return false;
4919 if (!kind_value_check (name, 0, gfc_default_character_kind))
4920 return false;
4922 if (!type_check (array, 1, BT_INTEGER)
4923 || !kind_value_check (array, 1, gfc_default_integer_kind))
4924 return false;
4926 if (!array_check (array, 1))
4927 return false;
4929 if (status == NULL)
4930 return true;
4932 if (!type_check (status, 2, BT_INTEGER)
4933 || !kind_value_check (array, 1, gfc_default_integer_kind))
4934 return false;
4936 if (!scalar_check (status, 2))
4937 return false;
4939 return true;
4943 bool
4944 gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub)
4946 mpz_t nelems;
4948 if (flag_coarray == GFC_FCOARRAY_NONE)
4950 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
4951 return false;
4954 if (!coarray_check (coarray, 0))
4955 return false;
4957 if (sub->rank != 1)
4959 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
4960 gfc_current_intrinsic_arg[1]->name, &sub->where);
4961 return false;
4964 if (gfc_array_size (sub, &nelems))
4966 int corank = gfc_get_corank (coarray);
4968 if (mpz_cmp_ui (nelems, corank) != 0)
4970 gfc_error ("The number of array elements of the SUB argument to "
4971 "IMAGE_INDEX at %L shall be %d (corank) not %d",
4972 &sub->where, corank, (int) mpz_get_si (nelems));
4973 mpz_clear (nelems);
4974 return false;
4976 mpz_clear (nelems);
4979 return true;
4983 bool
4984 gfc_check_num_images (gfc_expr *distance, gfc_expr *failed)
4986 if (flag_coarray == GFC_FCOARRAY_NONE)
4988 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
4989 return false;
4992 if (distance)
4994 if (!type_check (distance, 0, BT_INTEGER))
4995 return false;
4997 if (!nonnegative_check ("DISTANCE", distance))
4998 return false;
5000 if (!scalar_check (distance, 0))
5001 return false;
5003 if (!gfc_notify_std (GFC_STD_F2008_TS, "DISTANCE= argument to "
5004 "NUM_IMAGES at %L", &distance->where))
5005 return false;
5008 if (failed)
5010 if (!type_check (failed, 1, BT_LOGICAL))
5011 return false;
5013 if (!scalar_check (failed, 1))
5014 return false;
5016 if (!gfc_notify_std (GFC_STD_F2008_TS, "FAILED= argument to "
5017 "NUM_IMAGES at %L", &distance->where))
5018 return false;
5021 return true;
5025 bool
5026 gfc_check_this_image (gfc_expr *coarray, gfc_expr *dim, gfc_expr *distance)
5028 if (flag_coarray == GFC_FCOARRAY_NONE)
5030 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5031 return false;
5034 if (coarray == NULL && dim == NULL && distance == NULL)
5035 return true;
5037 if (dim != NULL && coarray == NULL)
5039 gfc_error ("DIM argument without COARRAY argument not allowed for "
5040 "THIS_IMAGE intrinsic at %L", &dim->where);
5041 return false;
5044 if (distance && (coarray || dim))
5046 gfc_error ("The DISTANCE argument may not be specified together with the "
5047 "COARRAY or DIM argument in intrinsic at %L",
5048 &distance->where);
5049 return false;
5052 /* Assume that we have "this_image (distance)". */
5053 if (coarray && !gfc_is_coarray (coarray) && coarray->ts.type == BT_INTEGER)
5055 if (dim)
5057 gfc_error ("Unexpected DIM argument with noncoarray argument at %L",
5058 &coarray->where);
5059 return false;
5061 distance = coarray;
5064 if (distance)
5066 if (!type_check (distance, 2, BT_INTEGER))
5067 return false;
5069 if (!nonnegative_check ("DISTANCE", distance))
5070 return false;
5072 if (!scalar_check (distance, 2))
5073 return false;
5075 if (!gfc_notify_std (GFC_STD_F2008_TS, "DISTANCE= argument to "
5076 "THIS_IMAGE at %L", &distance->where))
5077 return false;
5079 return true;
5082 if (!coarray_check (coarray, 0))
5083 return false;
5085 if (dim != NULL)
5087 if (!dim_check (dim, 1, false))
5088 return false;
5090 if (!dim_corank_check (dim, coarray))
5091 return false;
5094 return true;
5097 /* Calculate the sizes for transfer, used by gfc_check_transfer and also
5098 by gfc_simplify_transfer. Return false if we cannot do so. */
5100 bool
5101 gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size,
5102 size_t *source_size, size_t *result_size,
5103 size_t *result_length_p)
5105 size_t result_elt_size;
5107 if (source->expr_type == EXPR_FUNCTION)
5108 return false;
5110 if (size && size->expr_type != EXPR_CONSTANT)
5111 return false;
5113 /* Calculate the size of the source. */
5114 *source_size = gfc_target_expr_size (source);
5115 if (*source_size == 0)
5116 return false;
5118 /* Determine the size of the element. */
5119 result_elt_size = gfc_element_size (mold);
5120 if (result_elt_size == 0)
5121 return false;
5123 if (mold->expr_type == EXPR_ARRAY || mold->rank || size)
5125 int result_length;
5127 if (size)
5128 result_length = (size_t)mpz_get_ui (size->value.integer);
5129 else
5131 result_length = *source_size / result_elt_size;
5132 if (result_length * result_elt_size < *source_size)
5133 result_length += 1;
5136 *result_size = result_length * result_elt_size;
5137 if (result_length_p)
5138 *result_length_p = result_length;
5140 else
5141 *result_size = result_elt_size;
5143 return true;
5147 bool
5148 gfc_check_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size)
5150 size_t source_size;
5151 size_t result_size;
5153 if (mold->ts.type == BT_HOLLERITH)
5155 gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L must not be"
5156 " %s", &mold->where, gfc_basic_typename (BT_HOLLERITH));
5157 return false;
5160 if (size != NULL)
5162 if (!type_check (size, 2, BT_INTEGER))
5163 return false;
5165 if (!scalar_check (size, 2))
5166 return false;
5168 if (!nonoptional_check (size, 2))
5169 return false;
5172 if (!warn_surprising)
5173 return true;
5175 /* If we can't calculate the sizes, we cannot check any more.
5176 Return true for that case. */
5178 if (!gfc_calculate_transfer_sizes (source, mold, size, &source_size,
5179 &result_size, NULL))
5180 return true;
5182 if (source_size < result_size)
5183 gfc_warning (0, "Intrinsic TRANSFER at %L has partly undefined result: "
5184 "source size %ld < result size %ld", &source->where,
5185 (long) source_size, (long) result_size);
5187 return true;
5191 bool
5192 gfc_check_transpose (gfc_expr *matrix)
5194 if (!rank_check (matrix, 0, 2))
5195 return false;
5197 return true;
5201 bool
5202 gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
5204 if (!array_check (array, 0))
5205 return false;
5207 if (!dim_check (dim, 1, false))
5208 return false;
5210 if (!dim_rank_check (dim, array, 0))
5211 return false;
5213 if (!kind_check (kind, 2, BT_INTEGER))
5214 return false;
5215 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
5216 "with KIND argument at %L",
5217 gfc_current_intrinsic, &kind->where))
5218 return false;
5220 return true;
5224 bool
5225 gfc_check_ucobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
5227 if (flag_coarray == GFC_FCOARRAY_NONE)
5229 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5230 return false;
5233 if (!coarray_check (coarray, 0))
5234 return false;
5236 if (dim != NULL)
5238 if (!dim_check (dim, 1, false))
5239 return false;
5241 if (!dim_corank_check (dim, coarray))
5242 return false;
5245 if (!kind_check (kind, 2, BT_INTEGER))
5246 return false;
5248 return true;
5252 bool
5253 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
5255 mpz_t vector_size;
5257 if (!rank_check (vector, 0, 1))
5258 return false;
5260 if (!array_check (mask, 1))
5261 return false;
5263 if (!type_check (mask, 1, BT_LOGICAL))
5264 return false;
5266 if (!same_type_check (vector, 0, field, 2))
5267 return false;
5269 if (mask->expr_type == EXPR_ARRAY
5270 && gfc_array_size (vector, &vector_size))
5272 int mask_true_count = 0;
5273 gfc_constructor *mask_ctor;
5274 mask_ctor = gfc_constructor_first (mask->value.constructor);
5275 while (mask_ctor)
5277 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
5279 mask_true_count = 0;
5280 break;
5283 if (mask_ctor->expr->value.logical)
5284 mask_true_count++;
5286 mask_ctor = gfc_constructor_next (mask_ctor);
5289 if (mpz_get_si (vector_size) < mask_true_count)
5291 gfc_error ("%qs argument of %qs intrinsic at %L must "
5292 "provide at least as many elements as there "
5293 "are .TRUE. values in %qs (%ld/%d)",
5294 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
5295 &vector->where, gfc_current_intrinsic_arg[1]->name,
5296 mpz_get_si (vector_size), mask_true_count);
5297 return false;
5300 mpz_clear (vector_size);
5303 if (mask->rank != field->rank && field->rank != 0)
5305 gfc_error ("%qs argument of %qs intrinsic at %L must have "
5306 "the same rank as %qs or be a scalar",
5307 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
5308 &field->where, gfc_current_intrinsic_arg[1]->name);
5309 return false;
5312 if (mask->rank == field->rank)
5314 int i;
5315 for (i = 0; i < field->rank; i++)
5316 if (! identical_dimen_shape (mask, i, field, i))
5318 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L "
5319 "must have identical shape.",
5320 gfc_current_intrinsic_arg[2]->name,
5321 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
5322 &field->where);
5326 return true;
5330 bool
5331 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
5333 if (!type_check (x, 0, BT_CHARACTER))
5334 return false;
5336 if (!same_type_check (x, 0, y, 1))
5337 return false;
5339 if (z != NULL && !type_check (z, 2, BT_LOGICAL))
5340 return false;
5342 if (!kind_check (kind, 3, BT_INTEGER))
5343 return false;
5344 if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
5345 "with KIND argument at %L",
5346 gfc_current_intrinsic, &kind->where))
5347 return false;
5349 return true;
5353 bool
5354 gfc_check_trim (gfc_expr *x)
5356 if (!type_check (x, 0, BT_CHARACTER))
5357 return false;
5359 if (!scalar_check (x, 0))
5360 return false;
5362 return true;
5366 bool
5367 gfc_check_ttynam (gfc_expr *unit)
5369 if (!scalar_check (unit, 0))
5370 return false;
5372 if (!type_check (unit, 0, BT_INTEGER))
5373 return false;
5375 return true;
5379 /* Common check function for the half a dozen intrinsics that have a
5380 single real argument. */
5382 bool
5383 gfc_check_x (gfc_expr *x)
5385 if (!type_check (x, 0, BT_REAL))
5386 return false;
5388 return true;
5392 /************* Check functions for intrinsic subroutines *************/
5394 bool
5395 gfc_check_cpu_time (gfc_expr *time)
5397 if (!scalar_check (time, 0))
5398 return false;
5400 if (!type_check (time, 0, BT_REAL))
5401 return false;
5403 if (!variable_check (time, 0, false))
5404 return false;
5406 return true;
5410 bool
5411 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
5412 gfc_expr *zone, gfc_expr *values)
5414 if (date != NULL)
5416 if (!type_check (date, 0, BT_CHARACTER))
5417 return false;
5418 if (!kind_value_check (date, 0, gfc_default_character_kind))
5419 return false;
5420 if (!scalar_check (date, 0))
5421 return false;
5422 if (!variable_check (date, 0, false))
5423 return false;
5426 if (time != NULL)
5428 if (!type_check (time, 1, BT_CHARACTER))
5429 return false;
5430 if (!kind_value_check (time, 1, gfc_default_character_kind))
5431 return false;
5432 if (!scalar_check (time, 1))
5433 return false;
5434 if (!variable_check (time, 1, false))
5435 return false;
5438 if (zone != NULL)
5440 if (!type_check (zone, 2, BT_CHARACTER))
5441 return false;
5442 if (!kind_value_check (zone, 2, gfc_default_character_kind))
5443 return false;
5444 if (!scalar_check (zone, 2))
5445 return false;
5446 if (!variable_check (zone, 2, false))
5447 return false;
5450 if (values != NULL)
5452 if (!type_check (values, 3, BT_INTEGER))
5453 return false;
5454 if (!array_check (values, 3))
5455 return false;
5456 if (!rank_check (values, 3, 1))
5457 return false;
5458 if (!variable_check (values, 3, false))
5459 return false;
5462 return true;
5466 bool
5467 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
5468 gfc_expr *to, gfc_expr *topos)
5470 if (!type_check (from, 0, BT_INTEGER))
5471 return false;
5473 if (!type_check (frompos, 1, BT_INTEGER))
5474 return false;
5476 if (!type_check (len, 2, BT_INTEGER))
5477 return false;
5479 if (!same_type_check (from, 0, to, 3))
5480 return false;
5482 if (!variable_check (to, 3, false))
5483 return false;
5485 if (!type_check (topos, 4, BT_INTEGER))
5486 return false;
5488 if (!nonnegative_check ("frompos", frompos))
5489 return false;
5491 if (!nonnegative_check ("topos", topos))
5492 return false;
5494 if (!nonnegative_check ("len", len))
5495 return false;
5497 if (!less_than_bitsize2 ("from", from, "frompos", frompos, "len", len))
5498 return false;
5500 if (!less_than_bitsize2 ("to", to, "topos", topos, "len", len))
5501 return false;
5503 return true;
5507 bool
5508 gfc_check_random_number (gfc_expr *harvest)
5510 if (!type_check (harvest, 0, BT_REAL))
5511 return false;
5513 if (!variable_check (harvest, 0, false))
5514 return false;
5516 return true;
5520 bool
5521 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
5523 unsigned int nargs = 0, kiss_size;
5524 locus *where = NULL;
5525 mpz_t put_size, get_size;
5526 bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
5528 have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
5530 /* Keep the number of bytes in sync with kiss_size in
5531 libgfortran/intrinsics/random.c. */
5532 kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind;
5534 if (size != NULL)
5536 if (size->expr_type != EXPR_VARIABLE
5537 || !size->symtree->n.sym->attr.optional)
5538 nargs++;
5540 if (!scalar_check (size, 0))
5541 return false;
5543 if (!type_check (size, 0, BT_INTEGER))
5544 return false;
5546 if (!variable_check (size, 0, false))
5547 return false;
5549 if (!kind_value_check (size, 0, gfc_default_integer_kind))
5550 return false;
5553 if (put != NULL)
5555 if (put->expr_type != EXPR_VARIABLE
5556 || !put->symtree->n.sym->attr.optional)
5558 nargs++;
5559 where = &put->where;
5562 if (!array_check (put, 1))
5563 return false;
5565 if (!rank_check (put, 1, 1))
5566 return false;
5568 if (!type_check (put, 1, BT_INTEGER))
5569 return false;
5571 if (!kind_value_check (put, 1, gfc_default_integer_kind))
5572 return false;
5574 if (gfc_array_size (put, &put_size)
5575 && mpz_get_ui (put_size) < kiss_size)
5576 gfc_error ("Size of %qs argument of %qs intrinsic at %L "
5577 "too small (%i/%i)",
5578 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
5579 where, (int) mpz_get_ui (put_size), kiss_size);
5582 if (get != NULL)
5584 if (get->expr_type != EXPR_VARIABLE
5585 || !get->symtree->n.sym->attr.optional)
5587 nargs++;
5588 where = &get->where;
5591 if (!array_check (get, 2))
5592 return false;
5594 if (!rank_check (get, 2, 1))
5595 return false;
5597 if (!type_check (get, 2, BT_INTEGER))
5598 return false;
5600 if (!variable_check (get, 2, false))
5601 return false;
5603 if (!kind_value_check (get, 2, gfc_default_integer_kind))
5604 return false;
5606 if (gfc_array_size (get, &get_size)
5607 && mpz_get_ui (get_size) < kiss_size)
5608 gfc_error ("Size of %qs argument of %qs intrinsic at %L "
5609 "too small (%i/%i)",
5610 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
5611 where, (int) mpz_get_ui (get_size), kiss_size);
5614 /* RANDOM_SEED may not have more than one non-optional argument. */
5615 if (nargs > 1)
5616 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
5618 return true;
5621 bool
5622 gfc_check_fe_runtime_error (gfc_actual_arglist *a)
5624 gfc_expr *e;
5625 int len, i;
5626 int num_percent, nargs;
5628 e = a->expr;
5629 if (e->expr_type != EXPR_CONSTANT)
5630 return true;
5632 len = e->value.character.length;
5633 if (e->value.character.string[len-1] != '\0')
5634 gfc_internal_error ("fe_runtime_error string must be null terminated");
5636 num_percent = 0;
5637 for (i=0; i<len-1; i++)
5638 if (e->value.character.string[i] == '%')
5639 num_percent ++;
5641 nargs = 0;
5642 for (; a; a = a->next)
5643 nargs ++;
5645 if (nargs -1 != num_percent)
5646 gfc_internal_error ("fe_runtime_error: Wrong number of arguments (%d instead of %d)",
5647 nargs, num_percent++);
5649 return true;
5652 bool
5653 gfc_check_second_sub (gfc_expr *time)
5655 if (!scalar_check (time, 0))
5656 return false;
5658 if (!type_check (time, 0, BT_REAL))
5659 return false;
5661 if (!kind_value_check (time, 0, 4))
5662 return false;
5664 return true;
5668 /* COUNT and COUNT_MAX of SYSTEM_CLOCK are scalar, default-kind integer
5669 variables in Fortran 95. In Fortran 2003 and later, they can be of any
5670 kind, and COUNT_RATE can be of type real. Note, count, count_rate, and
5671 count_max are all optional arguments */
5673 bool
5674 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
5675 gfc_expr *count_max)
5677 if (count != NULL)
5679 if (!scalar_check (count, 0))
5680 return false;
5682 if (!type_check (count, 0, BT_INTEGER))
5683 return false;
5685 if (count->ts.kind != gfc_default_integer_kind
5686 && !gfc_notify_std (GFC_STD_F2003, "COUNT argument to "
5687 "SYSTEM_CLOCK at %L has non-default kind",
5688 &count->where))
5689 return false;
5691 if (!variable_check (count, 0, false))
5692 return false;
5695 if (count_rate != NULL)
5697 if (!scalar_check (count_rate, 1))
5698 return false;
5700 if (!variable_check (count_rate, 1, false))
5701 return false;
5703 if (count_rate->ts.type == BT_REAL)
5705 if (!gfc_notify_std (GFC_STD_F2003, "Real COUNT_RATE argument to "
5706 "SYSTEM_CLOCK at %L", &count_rate->where))
5707 return false;
5709 else
5711 if (!type_check (count_rate, 1, BT_INTEGER))
5712 return false;
5714 if (count_rate->ts.kind != gfc_default_integer_kind
5715 && !gfc_notify_std (GFC_STD_F2003, "COUNT_RATE argument to "
5716 "SYSTEM_CLOCK at %L has non-default kind",
5717 &count_rate->where))
5718 return false;
5723 if (count_max != NULL)
5725 if (!scalar_check (count_max, 2))
5726 return false;
5728 if (!type_check (count_max, 2, BT_INTEGER))
5729 return false;
5731 if (count_max->ts.kind != gfc_default_integer_kind
5732 && !gfc_notify_std (GFC_STD_F2003, "COUNT_MAX argument to "
5733 "SYSTEM_CLOCK at %L has non-default kind",
5734 &count_max->where))
5735 return false;
5737 if (!variable_check (count_max, 2, false))
5738 return false;
5741 return true;
5745 bool
5746 gfc_check_irand (gfc_expr *x)
5748 if (x == NULL)
5749 return true;
5751 if (!scalar_check (x, 0))
5752 return false;
5754 if (!type_check (x, 0, BT_INTEGER))
5755 return false;
5757 if (!kind_value_check (x, 0, 4))
5758 return false;
5760 return true;
5764 bool
5765 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
5767 if (!scalar_check (seconds, 0))
5768 return false;
5769 if (!type_check (seconds, 0, BT_INTEGER))
5770 return false;
5772 if (!int_or_proc_check (handler, 1))
5773 return false;
5774 if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
5775 return false;
5777 if (status == NULL)
5778 return true;
5780 if (!scalar_check (status, 2))
5781 return false;
5782 if (!type_check (status, 2, BT_INTEGER))
5783 return false;
5784 if (!kind_value_check (status, 2, gfc_default_integer_kind))
5785 return false;
5787 return true;
5791 bool
5792 gfc_check_rand (gfc_expr *x)
5794 if (x == NULL)
5795 return true;
5797 if (!scalar_check (x, 0))
5798 return false;
5800 if (!type_check (x, 0, BT_INTEGER))
5801 return false;
5803 if (!kind_value_check (x, 0, 4))
5804 return false;
5806 return true;
5810 bool
5811 gfc_check_srand (gfc_expr *x)
5813 if (!scalar_check (x, 0))
5814 return false;
5816 if (!type_check (x, 0, BT_INTEGER))
5817 return false;
5819 if (!kind_value_check (x, 0, 4))
5820 return false;
5822 return true;
5826 bool
5827 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
5829 if (!scalar_check (time, 0))
5830 return false;
5831 if (!type_check (time, 0, BT_INTEGER))
5832 return false;
5834 if (!type_check (result, 1, BT_CHARACTER))
5835 return false;
5836 if (!kind_value_check (result, 1, gfc_default_character_kind))
5837 return false;
5839 return true;
5843 bool
5844 gfc_check_dtime_etime (gfc_expr *x)
5846 if (!array_check (x, 0))
5847 return false;
5849 if (!rank_check (x, 0, 1))
5850 return false;
5852 if (!variable_check (x, 0, false))
5853 return false;
5855 if (!type_check (x, 0, BT_REAL))
5856 return false;
5858 if (!kind_value_check (x, 0, 4))
5859 return false;
5861 return true;
5865 bool
5866 gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
5868 if (!array_check (values, 0))
5869 return false;
5871 if (!rank_check (values, 0, 1))
5872 return false;
5874 if (!variable_check (values, 0, false))
5875 return false;
5877 if (!type_check (values, 0, BT_REAL))
5878 return false;
5880 if (!kind_value_check (values, 0, 4))
5881 return false;
5883 if (!scalar_check (time, 1))
5884 return false;
5886 if (!type_check (time, 1, BT_REAL))
5887 return false;
5889 if (!kind_value_check (time, 1, 4))
5890 return false;
5892 return true;
5896 bool
5897 gfc_check_fdate_sub (gfc_expr *date)
5899 if (!type_check (date, 0, BT_CHARACTER))
5900 return false;
5901 if (!kind_value_check (date, 0, gfc_default_character_kind))
5902 return false;
5904 return true;
5908 bool
5909 gfc_check_gerror (gfc_expr *msg)
5911 if (!type_check (msg, 0, BT_CHARACTER))
5912 return false;
5913 if (!kind_value_check (msg, 0, gfc_default_character_kind))
5914 return false;
5916 return true;
5920 bool
5921 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
5923 if (!type_check (cwd, 0, BT_CHARACTER))
5924 return false;
5925 if (!kind_value_check (cwd, 0, gfc_default_character_kind))
5926 return false;
5928 if (status == NULL)
5929 return true;
5931 if (!scalar_check (status, 1))
5932 return false;
5934 if (!type_check (status, 1, BT_INTEGER))
5935 return false;
5937 return true;
5941 bool
5942 gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
5944 if (!type_check (pos, 0, BT_INTEGER))
5945 return false;
5947 if (pos->ts.kind > gfc_default_integer_kind)
5949 gfc_error ("%qs argument of %qs intrinsic at %L must be of a kind "
5950 "not wider than the default kind (%d)",
5951 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
5952 &pos->where, gfc_default_integer_kind);
5953 return false;
5956 if (!type_check (value, 1, BT_CHARACTER))
5957 return false;
5958 if (!kind_value_check (value, 1, gfc_default_character_kind))
5959 return false;
5961 return true;
5965 bool
5966 gfc_check_getlog (gfc_expr *msg)
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;
5973 return true;
5977 bool
5978 gfc_check_exit (gfc_expr *status)
5980 if (status == NULL)
5981 return true;
5983 if (!type_check (status, 0, BT_INTEGER))
5984 return false;
5986 if (!scalar_check (status, 0))
5987 return false;
5989 return true;
5993 bool
5994 gfc_check_flush (gfc_expr *unit)
5996 if (unit == NULL)
5997 return true;
5999 if (!type_check (unit, 0, BT_INTEGER))
6000 return false;
6002 if (!scalar_check (unit, 0))
6003 return false;
6005 return true;
6009 bool
6010 gfc_check_free (gfc_expr *i)
6012 if (!type_check (i, 0, BT_INTEGER))
6013 return false;
6015 if (!scalar_check (i, 0))
6016 return false;
6018 return true;
6022 bool
6023 gfc_check_hostnm (gfc_expr *name)
6025 if (!type_check (name, 0, BT_CHARACTER))
6026 return false;
6027 if (!kind_value_check (name, 0, gfc_default_character_kind))
6028 return false;
6030 return true;
6034 bool
6035 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
6037 if (!type_check (name, 0, BT_CHARACTER))
6038 return false;
6039 if (!kind_value_check (name, 0, gfc_default_character_kind))
6040 return false;
6042 if (status == NULL)
6043 return true;
6045 if (!scalar_check (status, 1))
6046 return false;
6048 if (!type_check (status, 1, BT_INTEGER))
6049 return false;
6051 return true;
6055 bool
6056 gfc_check_itime_idate (gfc_expr *values)
6058 if (!array_check (values, 0))
6059 return false;
6061 if (!rank_check (values, 0, 1))
6062 return false;
6064 if (!variable_check (values, 0, false))
6065 return false;
6067 if (!type_check (values, 0, BT_INTEGER))
6068 return false;
6070 if (!kind_value_check (values, 0, gfc_default_integer_kind))
6071 return false;
6073 return true;
6077 bool
6078 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
6080 if (!type_check (time, 0, BT_INTEGER))
6081 return false;
6083 if (!kind_value_check (time, 0, gfc_default_integer_kind))
6084 return false;
6086 if (!scalar_check (time, 0))
6087 return false;
6089 if (!array_check (values, 1))
6090 return false;
6092 if (!rank_check (values, 1, 1))
6093 return false;
6095 if (!variable_check (values, 1, false))
6096 return false;
6098 if (!type_check (values, 1, BT_INTEGER))
6099 return false;
6101 if (!kind_value_check (values, 1, gfc_default_integer_kind))
6102 return false;
6104 return true;
6108 bool
6109 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
6111 if (!scalar_check (unit, 0))
6112 return false;
6114 if (!type_check (unit, 0, BT_INTEGER))
6115 return false;
6117 if (!type_check (name, 1, BT_CHARACTER))
6118 return false;
6119 if (!kind_value_check (name, 1, gfc_default_character_kind))
6120 return false;
6122 return true;
6126 bool
6127 gfc_check_isatty (gfc_expr *unit)
6129 if (unit == NULL)
6130 return false;
6132 if (!type_check (unit, 0, BT_INTEGER))
6133 return false;
6135 if (!scalar_check (unit, 0))
6136 return false;
6138 return true;
6142 bool
6143 gfc_check_isnan (gfc_expr *x)
6145 if (!type_check (x, 0, BT_REAL))
6146 return false;
6148 return true;
6152 bool
6153 gfc_check_perror (gfc_expr *string)
6155 if (!type_check (string, 0, BT_CHARACTER))
6156 return false;
6157 if (!kind_value_check (string, 0, gfc_default_character_kind))
6158 return false;
6160 return true;
6164 bool
6165 gfc_check_umask (gfc_expr *mask)
6167 if (!type_check (mask, 0, BT_INTEGER))
6168 return false;
6170 if (!scalar_check (mask, 0))
6171 return false;
6173 return true;
6177 bool
6178 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
6180 if (!type_check (mask, 0, BT_INTEGER))
6181 return false;
6183 if (!scalar_check (mask, 0))
6184 return false;
6186 if (old == NULL)
6187 return true;
6189 if (!scalar_check (old, 1))
6190 return false;
6192 if (!type_check (old, 1, BT_INTEGER))
6193 return false;
6195 return true;
6199 bool
6200 gfc_check_unlink (gfc_expr *name)
6202 if (!type_check (name, 0, BT_CHARACTER))
6203 return false;
6204 if (!kind_value_check (name, 0, gfc_default_character_kind))
6205 return false;
6207 return true;
6211 bool
6212 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
6214 if (!type_check (name, 0, BT_CHARACTER))
6215 return false;
6216 if (!kind_value_check (name, 0, gfc_default_character_kind))
6217 return false;
6219 if (status == NULL)
6220 return true;
6222 if (!scalar_check (status, 1))
6223 return false;
6225 if (!type_check (status, 1, BT_INTEGER))
6226 return false;
6228 return true;
6232 bool
6233 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
6235 if (!scalar_check (number, 0))
6236 return false;
6237 if (!type_check (number, 0, BT_INTEGER))
6238 return false;
6240 if (!int_or_proc_check (handler, 1))
6241 return false;
6242 if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
6243 return false;
6245 return true;
6249 bool
6250 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
6252 if (!scalar_check (number, 0))
6253 return false;
6254 if (!type_check (number, 0, BT_INTEGER))
6255 return false;
6257 if (!int_or_proc_check (handler, 1))
6258 return false;
6259 if (handler->ts.type == BT_INTEGER && !scalar_check (handler, 1))
6260 return false;
6262 if (status == NULL)
6263 return true;
6265 if (!type_check (status, 2, BT_INTEGER))
6266 return false;
6267 if (!scalar_check (status, 2))
6268 return false;
6270 return true;
6274 bool
6275 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
6277 if (!type_check (cmd, 0, BT_CHARACTER))
6278 return false;
6279 if (!kind_value_check (cmd, 0, gfc_default_character_kind))
6280 return false;
6282 if (!scalar_check (status, 1))
6283 return false;
6285 if (!type_check (status, 1, BT_INTEGER))
6286 return false;
6288 if (!kind_value_check (status, 1, gfc_default_integer_kind))
6289 return false;
6291 return true;
6295 /* This is used for the GNU intrinsics AND, OR and XOR. */
6296 bool
6297 gfc_check_and (gfc_expr *i, gfc_expr *j)
6299 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
6301 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
6302 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
6303 gfc_current_intrinsic, &i->where);
6304 return false;
6307 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
6309 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
6310 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
6311 gfc_current_intrinsic, &j->where);
6312 return false;
6315 if (i->ts.type != j->ts.type)
6317 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
6318 "have the same type", gfc_current_intrinsic_arg[0]->name,
6319 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
6320 &j->where);
6321 return false;
6324 if (!scalar_check (i, 0))
6325 return false;
6327 if (!scalar_check (j, 1))
6328 return false;
6330 return true;
6334 bool
6335 gfc_check_storage_size (gfc_expr *a, gfc_expr *kind)
6338 if (a->expr_type == EXPR_NULL)
6340 gfc_error ("Intrinsic function NULL at %L cannot be an actual "
6341 "argument to STORAGE_SIZE, because it returns a "
6342 "disassociated pointer", &a->where);
6343 return false;
6346 if (a->ts.type == BT_ASSUMED)
6348 gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
6349 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
6350 &a->where);
6351 return false;
6354 if (a->ts.type == BT_PROCEDURE)
6356 gfc_error ("%qs argument of %qs intrinsic at %L shall not be a "
6357 "procedure", gfc_current_intrinsic_arg[0]->name,
6358 gfc_current_intrinsic, &a->where);
6359 return false;
6362 if (kind == NULL)
6363 return true;
6365 if (!type_check (kind, 1, BT_INTEGER))
6366 return false;
6368 if (!scalar_check (kind, 1))
6369 return false;
6371 if (kind->expr_type != EXPR_CONSTANT)
6373 gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
6374 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
6375 &kind->where);
6376 return false;
6379 return true;