2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught & Katherine Holcomb
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24 /* These functions check to see if an argument list is compatible with
25 a particular intrinsic function or subroutine. Presence of
26 required arguments has already been established, the argument list
27 has been sorted into the right order and has NULL arguments in the
28 correct places for missing optional arguments. */
34 #include "intrinsic.h"
37 /* Check the type of an expression. */
40 type_check (gfc_expr *e, int n, bt type)
42 if (e->ts.type == type)
45 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
46 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where,
47 gfc_basic_typename (type));
53 /* Check that the expression is a numeric type. */
56 numeric_check (gfc_expr *e, int n)
58 if (gfc_numeric_ts (&e->ts))
61 /* If the expression has not got a type, check if its namespace can
62 offer a default type. */
63 if ((e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_VARIABLE)
64 && e->symtree->n.sym->ts.type == BT_UNKNOWN
65 && gfc_set_default_type (e->symtree->n.sym, 0,
66 e->symtree->n.sym->ns) == SUCCESS
67 && gfc_numeric_ts (&e->symtree->n.sym->ts))
69 e->ts = e->symtree->n.sym->ts;
73 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
74 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
80 /* Check that an expression is integer or real. */
83 int_or_real_check (gfc_expr *e, int n)
85 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
87 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
88 "or REAL", gfc_current_intrinsic_arg[n],
89 gfc_current_intrinsic, &e->where);
97 /* Check that an expression is real or complex. */
100 real_or_complex_check (gfc_expr *e, int n)
102 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
104 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
105 "or COMPLEX", gfc_current_intrinsic_arg[n],
106 gfc_current_intrinsic, &e->where);
114 /* Check that the expression is an optional constant integer
115 and that it specifies a valid kind for that type. */
118 kind_check (gfc_expr *k, int n, bt type)
125 if (type_check (k, n, BT_INTEGER) == FAILURE)
128 if (k->expr_type != EXPR_CONSTANT)
130 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
131 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
136 if (gfc_extract_int (k, &kind) != NULL
137 || gfc_validate_kind (type, kind, true) < 0)
139 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
148 /* Make sure the expression is a double precision real. */
151 double_check (gfc_expr *d, int n)
153 if (type_check (d, n, BT_REAL) == FAILURE)
156 if (d->ts.kind != gfc_default_double_kind)
158 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
159 "precision", gfc_current_intrinsic_arg[n],
160 gfc_current_intrinsic, &d->where);
168 /* Make sure the expression is a logical array. */
171 logical_array_check (gfc_expr *array, int n)
173 if (array->ts.type != BT_LOGICAL || array->rank == 0)
175 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
176 "array", gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
185 /* Make sure an expression is an array. */
188 array_check (gfc_expr *e, int n)
193 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
194 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
200 /* Make sure an expression is a scalar. */
203 scalar_check (gfc_expr *e, int n)
208 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
209 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
215 /* Make sure two expressions have the same type. */
218 same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
220 if (gfc_compare_types (&e->ts, &f->ts))
223 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
224 "and kind as '%s'", gfc_current_intrinsic_arg[m],
225 gfc_current_intrinsic, &f->where, gfc_current_intrinsic_arg[n]);
231 /* Make sure that an expression has a certain (nonzero) rank. */
234 rank_check (gfc_expr *e, int n, int rank)
239 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
240 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
247 /* Make sure a variable expression is not an optional dummy argument. */
250 nonoptional_check (gfc_expr *e, int n)
252 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
254 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
255 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
259 /* TODO: Recursive check on nonoptional variables? */
265 /* Check that an expression has a particular kind. */
268 kind_value_check (gfc_expr *e, int n, int k)
273 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
274 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
281 /* Make sure an expression is a variable. */
284 variable_check (gfc_expr *e, int n)
286 if ((e->expr_type == EXPR_VARIABLE
287 && e->symtree->n.sym->attr.flavor != FL_PARAMETER)
288 || (e->expr_type == EXPR_FUNCTION
289 && e->symtree->n.sym->result == e->symtree->n.sym))
292 if (e->expr_type == EXPR_VARIABLE
293 && e->symtree->n.sym->attr.intent == INTENT_IN)
295 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
296 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
301 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
302 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
308 /* Check the common DIM parameter for correctness. */
311 dim_check (gfc_expr *dim, int n, int optional)
313 if (optional && dim == NULL)
318 gfc_error ("Missing DIM parameter in intrinsic '%s' at %L",
319 gfc_current_intrinsic, gfc_current_intrinsic_where);
323 if (type_check (dim, n, BT_INTEGER) == FAILURE)
326 if (scalar_check (dim, n) == FAILURE)
329 if (nonoptional_check (dim, n) == FAILURE)
336 /* If a DIM parameter is a constant, make sure that it is greater than
337 zero and less than or equal to the rank of the given array. If
338 allow_assumed is zero then dim must be less than the rank of the array
339 for assumed size arrays. */
342 dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
347 if (dim->expr_type != EXPR_CONSTANT || array->expr_type != EXPR_VARIABLE)
350 ar = gfc_find_array_ref (array);
352 if (ar->as->type == AS_ASSUMED_SIZE
354 && ar->type != AR_ELEMENT
355 && ar->type != AR_SECTION)
358 if (mpz_cmp_ui (dim->value.integer, 1) < 0
359 || mpz_cmp_ui (dim->value.integer, rank) > 0)
361 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
362 "dimension index", gfc_current_intrinsic, &dim->where);
371 /* Compare the size of a along dimension ai with the size of b along
372 dimension bi, returning 0 if they are known not to be identical,
373 and 1 if they are identical, or if this cannot be determined. */
376 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
378 mpz_t a_size, b_size;
381 gcc_assert (a->rank > ai);
382 gcc_assert (b->rank > bi);
386 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
388 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
390 if (mpz_cmp (a_size, b_size) != 0)
401 /* Error return for transformational intrinsics not allowed in
402 initialization expressions. */
405 non_init_transformational (void)
407 gfc_error ("transformational intrinsic '%s' at %L is not permitted "
408 "in an initialization expression", gfc_current_intrinsic,
409 gfc_current_intrinsic_where);
413 /***** Check functions *****/
415 /* Check subroutine suitable for intrinsics taking a real argument and
416 a kind argument for the result. */
419 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
421 if (type_check (a, 0, BT_REAL) == FAILURE)
423 if (kind_check (kind, 1, type) == FAILURE)
430 /* Check subroutine suitable for ceiling, floor and nint. */
433 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
435 return check_a_kind (a, kind, BT_INTEGER);
439 /* Check subroutine suitable for aint, anint. */
442 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
444 return check_a_kind (a, kind, BT_REAL);
449 gfc_check_abs (gfc_expr *a)
451 if (numeric_check (a, 0) == FAILURE)
459 gfc_check_achar (gfc_expr *a)
461 if (type_check (a, 0, BT_INTEGER) == FAILURE)
469 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
471 if (type_check (name, 0, BT_CHARACTER) == FAILURE
472 || scalar_check (name, 0) == FAILURE)
475 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
476 || scalar_check (mode, 1) == FAILURE)
484 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
486 if (logical_array_check (mask, 0) == FAILURE)
489 if (dim_check (dim, 1, 1) == FAILURE)
493 return non_init_transformational ();
500 gfc_check_allocated (gfc_expr *array)
502 symbol_attribute attr;
504 if (variable_check (array, 0) == FAILURE)
507 if (array_check (array, 0) == FAILURE)
510 attr = gfc_variable_attr (array, NULL);
511 if (!attr.allocatable)
513 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
514 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
523 /* Common check function where the first argument must be real or
524 integer and the second argument must be the same as the first. */
527 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
529 if (int_or_real_check (a, 0) == FAILURE)
532 if (a->ts.type != p->ts.type)
534 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
535 "have the same type", gfc_current_intrinsic_arg[0],
536 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
541 if (a->ts.kind != p->ts.kind)
543 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
544 &p->where) == FAILURE)
553 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
555 symbol_attribute attr;
560 where = &pointer->where;
562 if (pointer->expr_type == EXPR_VARIABLE)
563 attr = gfc_variable_attr (pointer, NULL);
564 else if (pointer->expr_type == EXPR_FUNCTION)
565 attr = pointer->symtree->n.sym->attr;
566 else if (pointer->expr_type == EXPR_NULL)
569 gcc_assert (0); /* Pointer must be a variable or a function. */
573 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
574 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
579 /* Target argument is optional. */
583 where = &target->where;
584 if (target->expr_type == EXPR_NULL)
587 if (target->expr_type == EXPR_VARIABLE)
588 attr = gfc_variable_attr (target, NULL);
589 else if (target->expr_type == EXPR_FUNCTION)
590 attr = target->symtree->n.sym->attr;
593 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
594 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg[1],
595 gfc_current_intrinsic, &target->where);
599 if (!attr.pointer && !attr.target)
601 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
602 "or a TARGET", gfc_current_intrinsic_arg[1],
603 gfc_current_intrinsic, &target->where);
608 if (same_type_check (pointer, 0, target, 1) == FAILURE)
610 if (rank_check (target, 0, pointer->rank) == FAILURE)
612 if (target->rank > 0)
614 for (i = 0; i < target->rank; i++)
615 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
617 gfc_error ("Array section with a vector subscript at %L shall not "
618 "be the target of a pointer",
628 gfc_error ("NULL pointer at %L is not permitted as actual argument "
629 "of '%s' intrinsic function", where, gfc_current_intrinsic);
636 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
638 if (type_check (y, 0, BT_REAL) == FAILURE)
640 if (same_type_check (y, 0, x, 1) == FAILURE)
647 /* BESJN and BESYN functions. */
650 gfc_check_besn (gfc_expr *n, gfc_expr *x)
652 if (type_check (n, 0, BT_INTEGER) == FAILURE)
655 if (type_check (x, 1, BT_REAL) == FAILURE)
663 gfc_check_btest (gfc_expr *i, gfc_expr *pos)
665 if (type_check (i, 0, BT_INTEGER) == FAILURE)
667 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
675 gfc_check_char (gfc_expr *i, gfc_expr *kind)
677 if (type_check (i, 0, BT_INTEGER) == FAILURE)
679 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
687 gfc_check_chdir (gfc_expr *dir)
689 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
697 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
699 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
705 if (type_check (status, 1, BT_INTEGER) == FAILURE)
708 if (scalar_check (status, 1) == FAILURE)
716 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
718 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
721 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
729 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
731 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
734 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
740 if (type_check (status, 2, BT_INTEGER) == FAILURE)
743 if (scalar_check (status, 2) == FAILURE)
751 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
753 if (numeric_check (x, 0) == FAILURE)
758 if (numeric_check (y, 1) == FAILURE)
761 if (x->ts.type == BT_COMPLEX)
763 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
764 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
765 gfc_current_intrinsic, &y->where);
770 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
778 gfc_check_complex (gfc_expr *x, gfc_expr *y)
780 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
782 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
783 "or REAL", gfc_current_intrinsic_arg[0],
784 gfc_current_intrinsic, &x->where);
787 if (scalar_check (x, 0) == FAILURE)
790 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
792 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
793 "or REAL", gfc_current_intrinsic_arg[1],
794 gfc_current_intrinsic, &y->where);
797 if (scalar_check (y, 1) == FAILURE)
805 gfc_check_count (gfc_expr *mask, gfc_expr *dim)
807 if (logical_array_check (mask, 0) == FAILURE)
809 if (dim_check (dim, 1, 1) == FAILURE)
813 return non_init_transformational ();
820 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
822 if (array_check (array, 0) == FAILURE)
825 if (array->rank == 1)
827 if (scalar_check (shift, 1) == FAILURE)
832 /* TODO: more requirements on shift parameter. */
835 if (dim_check (dim, 2, 1) == FAILURE)
839 return non_init_transformational ();
846 gfc_check_ctime (gfc_expr *time)
848 if (scalar_check (time, 0) == FAILURE)
851 if (type_check (time, 0, BT_INTEGER) == FAILURE)
859 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
861 if (numeric_check (x, 0) == FAILURE)
866 if (numeric_check (y, 1) == FAILURE)
869 if (x->ts.type == BT_COMPLEX)
871 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
872 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
873 gfc_current_intrinsic, &y->where);
883 gfc_check_dble (gfc_expr *x)
885 if (numeric_check (x, 0) == FAILURE)
893 gfc_check_digits (gfc_expr *x)
895 if (int_or_real_check (x, 0) == FAILURE)
903 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
905 switch (vector_a->ts.type)
908 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
915 if (numeric_check (vector_b, 1) == FAILURE)
920 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
921 "or LOGICAL", gfc_current_intrinsic_arg[0],
922 gfc_current_intrinsic, &vector_a->where);
926 if (rank_check (vector_a, 0, 1) == FAILURE)
929 if (rank_check (vector_b, 1, 1) == FAILURE)
932 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
934 gfc_error ("different shape for arguments '%s' and '%s' at %L for "
935 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0],
936 gfc_current_intrinsic_arg[1], &vector_a->where);
941 return non_init_transformational ();
948 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
951 if (array_check (array, 0) == FAILURE)
954 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
957 if (array->rank == 1)
959 if (scalar_check (shift, 2) == FAILURE)
964 /* TODO: more weird restrictions on shift. */
967 if (boundary != NULL)
969 if (same_type_check (array, 0, boundary, 2) == FAILURE)
972 /* TODO: more restrictions on boundary. */
975 if (dim_check (dim, 1, 1) == FAILURE)
979 return non_init_transformational ();
985 /* A single complex argument. */
988 gfc_check_fn_c (gfc_expr *a)
990 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
997 /* A single real argument. */
1000 gfc_check_fn_r (gfc_expr *a)
1002 if (type_check (a, 0, BT_REAL) == FAILURE)
1009 /* A single real or complex argument. */
1012 gfc_check_fn_rc (gfc_expr *a)
1014 if (real_or_complex_check (a, 0) == FAILURE)
1022 gfc_check_fnum (gfc_expr *unit)
1024 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1027 if (scalar_check (unit, 0) == FAILURE)
1035 gfc_check_huge (gfc_expr *x)
1037 if (int_or_real_check (x, 0) == FAILURE)
1044 /* Check that the single argument is an integer. */
1047 gfc_check_i (gfc_expr *i)
1049 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1057 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1059 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1062 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1065 if (i->ts.kind != j->ts.kind)
1067 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1068 &i->where) == FAILURE)
1077 gfc_check_ibclr (gfc_expr *i, gfc_expr *pos)
1079 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1082 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1090 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1092 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1095 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1098 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1106 gfc_check_ibset (gfc_expr *i, gfc_expr *pos)
1108 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1111 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1119 gfc_check_ichar_iachar (gfc_expr *c)
1123 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1126 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1132 /* Substring references don't have the charlength set. */
1134 while (ref && ref->type != REF_SUBSTRING)
1137 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1141 /* Check that the argument is length one. Non-constant lengths
1142 can't be checked here, so assume they are ok. */
1143 if (c->ts.cl && c->ts.cl->length)
1145 /* If we already have a length for this expression then use it. */
1146 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
1148 i = mpz_get_si (c->ts.cl->length->value.integer);
1155 start = ref->u.ss.start;
1156 end = ref->u.ss.end;
1159 if (end == NULL || end->expr_type != EXPR_CONSTANT
1160 || start->expr_type != EXPR_CONSTANT)
1163 i = mpz_get_si (end->value.integer) + 1
1164 - mpz_get_si (start->value.integer);
1172 gfc_error ("Argument of %s at %L must be of length one",
1173 gfc_current_intrinsic, &c->where);
1182 gfc_check_idnint (gfc_expr *a)
1184 if (double_check (a, 0) == FAILURE)
1192 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1194 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1197 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1200 if (i->ts.kind != j->ts.kind)
1202 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1203 &i->where) == FAILURE)
1212 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back)
1214 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1215 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1219 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1222 if (string->ts.kind != substring->ts.kind)
1224 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1225 "kind as '%s'", gfc_current_intrinsic_arg[1],
1226 gfc_current_intrinsic, &substring->where,
1227 gfc_current_intrinsic_arg[0]);
1236 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1238 if (numeric_check (x, 0) == FAILURE)
1243 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
1246 if (scalar_check (kind, 1) == FAILURE)
1255 gfc_check_intconv (gfc_expr *x)
1257 if (numeric_check (x, 0) == FAILURE)
1265 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1267 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1270 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1273 if (i->ts.kind != j->ts.kind)
1275 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1276 &i->where) == FAILURE)
1285 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1287 if (type_check (i, 0, BT_INTEGER) == FAILURE
1288 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1296 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1298 if (type_check (i, 0, BT_INTEGER) == FAILURE
1299 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1302 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1310 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1312 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1315 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1323 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1325 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1328 if (scalar_check (pid, 0) == FAILURE)
1331 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1334 if (scalar_check (sig, 1) == FAILURE)
1340 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1343 if (scalar_check (status, 2) == FAILURE)
1351 gfc_check_kind (gfc_expr *x)
1353 if (x->ts.type == BT_DERIVED)
1355 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1356 "non-derived type", gfc_current_intrinsic_arg[0],
1357 gfc_current_intrinsic, &x->where);
1366 gfc_check_lbound (gfc_expr *array, gfc_expr *dim)
1368 if (array_check (array, 0) == FAILURE)
1373 if (dim_check (dim, 1, 1) == FAILURE)
1376 if (dim_rank_check (dim, array, 1) == FAILURE)
1384 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
1386 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1389 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1397 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1399 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1402 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1408 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1411 if (scalar_check (status, 2) == FAILURE)
1419 gfc_check_loc (gfc_expr *expr)
1421 return variable_check (expr, 0);
1426 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
1428 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1431 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1439 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1441 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1444 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1450 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1453 if (scalar_check (status, 2) == FAILURE)
1461 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
1463 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1465 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1472 /* Min/max family. */
1475 min_max_args (gfc_actual_arglist *arg)
1477 if (arg == NULL || arg->next == NULL)
1479 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1480 gfc_current_intrinsic, gfc_current_intrinsic_where);
1489 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
1491 gfc_actual_arglist *arg, *tmp;
1496 if (min_max_args (arglist) == FAILURE)
1499 for (arg = arglist, n=1; arg; arg = arg->next, n++)
1502 if (x->ts.type != type || x->ts.kind != kind)
1504 if (x->ts.type == type)
1506 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
1507 "kinds at %L", &x->where) == FAILURE)
1512 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1513 "%s(%d)", n, gfc_current_intrinsic, &x->where,
1514 gfc_basic_typename (type), kind);
1519 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
1522 snprintf (buffer, 80, "arguments 'a%d' and 'a%d' for intrinsic '%s'",
1523 m, n, gfc_current_intrinsic);
1524 if (gfc_check_conformance (buffer, tmp->expr, x) == FAILURE)
1534 gfc_check_min_max (gfc_actual_arglist *arg)
1538 if (min_max_args (arg) == FAILURE)
1543 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1545 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER "
1546 "or REAL", gfc_current_intrinsic, &x->where);
1550 return check_rest (x->ts.type, x->ts.kind, arg);
1555 gfc_check_min_max_integer (gfc_actual_arglist *arg)
1557 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1562 gfc_check_min_max_real (gfc_actual_arglist *arg)
1564 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1569 gfc_check_min_max_double (gfc_actual_arglist *arg)
1571 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1575 /* End of min/max family. */
1578 gfc_check_malloc (gfc_expr *size)
1580 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1583 if (scalar_check (size, 0) == FAILURE)
1591 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
1593 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1595 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1596 "or LOGICAL", gfc_current_intrinsic_arg[0],
1597 gfc_current_intrinsic, &matrix_a->where);
1601 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1603 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1604 "or LOGICAL", gfc_current_intrinsic_arg[1],
1605 gfc_current_intrinsic, &matrix_b->where);
1609 switch (matrix_a->rank)
1612 if (rank_check (matrix_b, 1, 2) == FAILURE)
1614 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
1615 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
1617 gfc_error ("different shape on dimension 1 for arguments '%s' "
1618 "and '%s' at %L for intrinsic matmul",
1619 gfc_current_intrinsic_arg[0],
1620 gfc_current_intrinsic_arg[1], &matrix_a->where);
1626 if (matrix_b->rank != 2)
1628 if (rank_check (matrix_b, 1, 1) == FAILURE)
1631 /* matrix_b has rank 1 or 2 here. Common check for the cases
1632 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
1633 - matrix_a has shape (n,m) and matrix_b has shape (m). */
1634 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
1636 gfc_error ("different shape on dimension 2 for argument '%s' and "
1637 "dimension 1 for argument '%s' at %L for intrinsic "
1638 "matmul", gfc_current_intrinsic_arg[0],
1639 gfc_current_intrinsic_arg[1], &matrix_a->where);
1645 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1646 "1 or 2", gfc_current_intrinsic_arg[0],
1647 gfc_current_intrinsic, &matrix_a->where);
1652 return non_init_transformational ();
1658 /* Whoever came up with this interface was probably on something.
1659 The possibilities for the occupation of the second and third
1666 NULL MASK minloc(array, mask=m)
1669 I.e. in the case of minloc(array,mask), mask will be in the second
1670 position of the argument list and we'll have to fix that up. */
1673 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
1675 gfc_expr *a, *m, *d;
1678 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
1682 m = ap->next->next->expr;
1684 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1685 && ap->next->name == NULL)
1689 ap->next->expr = NULL;
1690 ap->next->next->expr = m;
1693 if (dim_check (d, 1, 1) == FAILURE)
1696 if (d && dim_rank_check (d, a, 0) == FAILURE)
1699 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1705 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1706 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1707 gfc_current_intrinsic);
1708 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1713 return non_init_transformational ();
1719 /* Similar to minloc/maxloc, the argument list might need to be
1720 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1721 difference is that MINLOC/MAXLOC take an additional KIND argument.
1722 The possibilities are:
1728 NULL MASK minval(array, mask=m)
1731 I.e. in the case of minval(array,mask), mask will be in the second
1732 position of the argument list and we'll have to fix that up. */
1735 check_reduction (gfc_actual_arglist *ap)
1737 gfc_expr *a, *m, *d;
1741 m = ap->next->next->expr;
1743 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1744 && ap->next->name == NULL)
1748 ap->next->expr = NULL;
1749 ap->next->next->expr = m;
1752 if (dim_check (d, 1, 1) == FAILURE)
1755 if (d && dim_rank_check (d, a, 0) == FAILURE)
1758 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1764 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1765 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1766 gfc_current_intrinsic);
1767 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1776 gfc_check_minval_maxval (gfc_actual_arglist *ap)
1778 if (int_or_real_check (ap->expr, 0) == FAILURE
1779 || array_check (ap->expr, 0) == FAILURE)
1783 return non_init_transformational ();
1785 return check_reduction (ap);
1790 gfc_check_product_sum (gfc_actual_arglist *ap)
1792 if (numeric_check (ap->expr, 0) == FAILURE
1793 || array_check (ap->expr, 0) == FAILURE)
1797 return non_init_transformational ();
1799 return check_reduction (ap);
1804 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
1806 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
1809 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
1816 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
1818 symbol_attribute attr;
1820 if (variable_check (from, 0) == FAILURE)
1823 if (array_check (from, 0) == FAILURE)
1826 attr = gfc_variable_attr (from, NULL);
1827 if (!attr.allocatable)
1829 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1830 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1835 if (variable_check (to, 0) == FAILURE)
1838 if (array_check (to, 0) == FAILURE)
1841 attr = gfc_variable_attr (to, NULL);
1842 if (!attr.allocatable)
1844 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1845 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1850 if (same_type_check (from, 0, to, 1) == FAILURE)
1853 if (to->rank != from->rank)
1855 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1856 "have the same rank %d/%d", gfc_current_intrinsic_arg[0],
1857 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1858 &to->where, from->rank, to->rank);
1862 if (to->ts.kind != from->ts.kind)
1864 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1865 "be of the same kind %d/%d", gfc_current_intrinsic_arg[0],
1866 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1867 &to->where, from->ts.kind, to->ts.kind);
1876 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
1878 if (type_check (x, 0, BT_REAL) == FAILURE)
1881 if (type_check (s, 1, BT_REAL) == FAILURE)
1889 gfc_check_new_line (gfc_expr *a)
1891 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1899 gfc_check_null (gfc_expr *mold)
1901 symbol_attribute attr;
1906 if (variable_check (mold, 0) == FAILURE)
1909 attr = gfc_variable_attr (mold, NULL);
1913 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
1914 gfc_current_intrinsic_arg[0],
1915 gfc_current_intrinsic, &mold->where);
1924 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
1928 if (array_check (array, 0) == FAILURE)
1931 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1934 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1935 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1936 gfc_current_intrinsic);
1937 if (gfc_check_conformance (buffer, array, mask) == FAILURE)
1942 if (same_type_check (array, 0, vector, 2) == FAILURE)
1945 if (rank_check (vector, 2, 1) == FAILURE)
1948 /* TODO: More constraints here. */
1952 return non_init_transformational ();
1959 gfc_check_precision (gfc_expr *x)
1961 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
1963 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
1964 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
1965 gfc_current_intrinsic, &x->where);
1974 gfc_check_present (gfc_expr *a)
1978 if (variable_check (a, 0) == FAILURE)
1981 sym = a->symtree->n.sym;
1982 if (!sym->attr.dummy)
1984 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
1985 "dummy variable", gfc_current_intrinsic_arg[0],
1986 gfc_current_intrinsic, &a->where);
1990 if (!sym->attr.optional)
1992 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
1993 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
1994 gfc_current_intrinsic, &a->where);
1998 /* 13.14.82 PRESENT(A)
2000 Argument. A shall be the name of an optional dummy argument that is
2001 accessible in the subprogram in which the PRESENT function reference
2005 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2006 && a->ref->u.ar.type == AR_FULL))
2008 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2009 "subobject of '%s'", gfc_current_intrinsic_arg[0],
2010 gfc_current_intrinsic, &a->where, sym->name);
2019 gfc_check_radix (gfc_expr *x)
2021 if (int_or_real_check (x, 0) == FAILURE)
2029 gfc_check_range (gfc_expr *x)
2031 if (numeric_check (x, 0) == FAILURE)
2038 /* real, float, sngl. */
2040 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2042 if (numeric_check (a, 0) == FAILURE)
2045 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2053 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2055 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2058 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2066 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2068 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2071 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2077 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2080 if (scalar_check (status, 2) == FAILURE)
2088 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2090 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2093 if (scalar_check (x, 0) == FAILURE)
2096 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2099 if (scalar_check (y, 1) == FAILURE)
2107 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2108 gfc_expr *pad, gfc_expr *order)
2114 if (array_check (source, 0) == FAILURE)
2117 if (rank_check (shape, 1, 1) == FAILURE)
2120 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2123 if (gfc_array_size (shape, &size) != SUCCESS)
2125 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2126 "array of constant size", &shape->where);
2130 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
2135 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2136 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2142 if (same_type_check (source, 0, pad, 2) == FAILURE)
2144 if (array_check (pad, 2) == FAILURE)
2148 if (order != NULL && array_check (order, 3) == FAILURE)
2151 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2152 && gfc_is_constant_expr (shape)
2153 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2154 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2156 /* Check the match in size between source and destination. */
2157 if (gfc_array_size (source, &nelems) == SUCCESS)
2162 c = shape->value.constructor;
2163 mpz_init_set_ui (size, 1);
2164 for (; c; c = c->next)
2165 mpz_mul (size, size, c->expr->value.integer);
2167 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2173 gfc_error ("Without padding, there are not enough elements "
2174 "in the intrinsic RESHAPE source at %L to match "
2175 "the shape", &source->where);
2186 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2188 if (type_check (x, 0, BT_REAL) == FAILURE)
2191 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2199 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2201 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2204 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2207 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2210 if (same_type_check (x, 0, y, 1) == FAILURE)
2218 gfc_check_secnds (gfc_expr *r)
2220 if (type_check (r, 0, BT_REAL) == FAILURE)
2223 if (kind_value_check (r, 0, 4) == FAILURE)
2226 if (scalar_check (r, 0) == FAILURE)
2234 gfc_check_selected_int_kind (gfc_expr *r)
2236 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2239 if (scalar_check (r, 0) == FAILURE)
2247 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r)
2249 if (p == NULL && r == NULL)
2251 gfc_error ("Missing arguments to %s intrinsic at %L",
2252 gfc_current_intrinsic, gfc_current_intrinsic_where);
2257 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
2260 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
2268 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
2270 if (type_check (x, 0, BT_REAL) == FAILURE)
2273 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2281 gfc_check_shape (gfc_expr *source)
2285 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2288 ar = gfc_find_array_ref (source);
2290 if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
2292 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2293 "an assumed size array", &source->where);
2302 gfc_check_sign (gfc_expr *a, gfc_expr *b)
2304 if (int_or_real_check (a, 0) == FAILURE)
2307 if (same_type_check (a, 0, b, 1) == FAILURE)
2315 gfc_check_size (gfc_expr *array, gfc_expr *dim)
2317 if (array_check (array, 0) == FAILURE)
2322 if (type_check (dim, 1, BT_INTEGER) == FAILURE)
2325 if (kind_value_check (dim, 1, gfc_default_integer_kind) == FAILURE)
2328 if (dim_rank_check (dim, array, 0) == FAILURE)
2337 gfc_check_sizeof (gfc_expr *arg __attribute__((unused)))
2344 gfc_check_sleep_sub (gfc_expr *seconds)
2346 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2349 if (scalar_check (seconds, 0) == FAILURE)
2357 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
2359 if (source->rank >= GFC_MAX_DIMENSIONS)
2361 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2362 "than rank %d", gfc_current_intrinsic_arg[0],
2363 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2368 if (dim_check (dim, 1, 0) == FAILURE)
2371 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2374 if (scalar_check (ncopies, 2) == FAILURE)
2378 return non_init_transformational ();
2384 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2388 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
2390 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2393 if (scalar_check (unit, 0) == FAILURE)
2396 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2402 if (type_check (status, 2, BT_INTEGER) == FAILURE
2403 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2404 || scalar_check (status, 2) == FAILURE)
2412 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
2414 return gfc_check_fgetputc_sub (unit, c, NULL);
2419 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
2421 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2427 if (type_check (status, 1, BT_INTEGER) == FAILURE
2428 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2429 || scalar_check (status, 1) == FAILURE)
2437 gfc_check_fgetput (gfc_expr *c)
2439 return gfc_check_fgetput_sub (c, NULL);
2444 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
2446 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2449 if (scalar_check (unit, 0) == FAILURE)
2452 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2455 if (scalar_check (offset, 1) == FAILURE)
2458 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
2461 if (scalar_check (whence, 2) == FAILURE)
2467 if (type_check (status, 3, BT_INTEGER) == FAILURE)
2470 if (kind_value_check (status, 3, 4) == FAILURE)
2473 if (scalar_check (status, 3) == FAILURE)
2482 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
2484 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2487 if (scalar_check (unit, 0) == FAILURE)
2490 if (type_check (array, 1, BT_INTEGER) == FAILURE
2491 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2494 if (array_check (array, 1) == FAILURE)
2502 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
2504 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2507 if (scalar_check (unit, 0) == FAILURE)
2510 if (type_check (array, 1, BT_INTEGER) == FAILURE
2511 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2514 if (array_check (array, 1) == FAILURE)
2520 if (type_check (status, 2, BT_INTEGER) == FAILURE
2521 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2524 if (scalar_check (status, 2) == FAILURE)
2532 gfc_check_ftell (gfc_expr *unit)
2534 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2537 if (scalar_check (unit, 0) == FAILURE)
2545 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
2547 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2550 if (scalar_check (unit, 0) == FAILURE)
2553 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2556 if (scalar_check (offset, 1) == FAILURE)
2564 gfc_check_stat (gfc_expr *name, gfc_expr *array)
2566 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2569 if (type_check (array, 1, BT_INTEGER) == FAILURE
2570 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2573 if (array_check (array, 1) == FAILURE)
2581 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
2583 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2586 if (type_check (array, 1, BT_INTEGER) == FAILURE
2587 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2590 if (array_check (array, 1) == FAILURE)
2596 if (type_check (status, 2, BT_INTEGER) == FAILURE
2597 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2600 if (scalar_check (status, 2) == FAILURE)
2608 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
2609 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
2611 if (mold->ts.type == BT_HOLLERITH)
2613 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
2614 &mold->where, gfc_basic_typename (BT_HOLLERITH));
2620 if (type_check (size, 2, BT_INTEGER) == FAILURE)
2623 if (scalar_check (size, 2) == FAILURE)
2626 if (nonoptional_check (size, 2) == FAILURE)
2635 gfc_check_transpose (gfc_expr *matrix)
2637 if (rank_check (matrix, 0, 2) == FAILURE)
2641 return non_init_transformational ();
2648 gfc_check_ubound (gfc_expr *array, gfc_expr *dim)
2650 if (array_check (array, 0) == FAILURE)
2655 if (dim_check (dim, 1, 1) == FAILURE)
2658 if (dim_rank_check (dim, array, 0) == FAILURE)
2667 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
2669 if (rank_check (vector, 0, 1) == FAILURE)
2672 if (array_check (mask, 1) == FAILURE)
2675 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2678 if (same_type_check (vector, 0, field, 2) == FAILURE)
2682 return non_init_transformational ();
2689 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2691 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2694 if (same_type_check (x, 0, y, 1) == FAILURE)
2697 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2705 gfc_check_trim (gfc_expr *x)
2707 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2710 if (scalar_check (x, 0) == FAILURE)
2718 gfc_check_ttynam (gfc_expr *unit)
2720 if (scalar_check (unit, 0) == FAILURE)
2723 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2730 /* Common check function for the half a dozen intrinsics that have a
2731 single real argument. */
2734 gfc_check_x (gfc_expr *x)
2736 if (type_check (x, 0, BT_REAL) == FAILURE)
2743 /************* Check functions for intrinsic subroutines *************/
2746 gfc_check_cpu_time (gfc_expr *time)
2748 if (scalar_check (time, 0) == FAILURE)
2751 if (type_check (time, 0, BT_REAL) == FAILURE)
2754 if (variable_check (time, 0) == FAILURE)
2762 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
2763 gfc_expr *zone, gfc_expr *values)
2767 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2769 if (scalar_check (date, 0) == FAILURE)
2771 if (variable_check (date, 0) == FAILURE)
2777 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
2779 if (scalar_check (time, 1) == FAILURE)
2781 if (variable_check (time, 1) == FAILURE)
2787 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
2789 if (scalar_check (zone, 2) == FAILURE)
2791 if (variable_check (zone, 2) == FAILURE)
2797 if (type_check (values, 3, BT_INTEGER) == FAILURE)
2799 if (array_check (values, 3) == FAILURE)
2801 if (rank_check (values, 3, 1) == FAILURE)
2803 if (variable_check (values, 3) == FAILURE)
2812 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
2813 gfc_expr *to, gfc_expr *topos)
2815 if (type_check (from, 0, BT_INTEGER) == FAILURE)
2818 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
2821 if (type_check (len, 2, BT_INTEGER) == FAILURE)
2824 if (same_type_check (from, 0, to, 3) == FAILURE)
2827 if (variable_check (to, 3) == FAILURE)
2830 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
2838 gfc_check_random_number (gfc_expr *harvest)
2840 if (type_check (harvest, 0, BT_REAL) == FAILURE)
2843 if (variable_check (harvest, 0) == FAILURE)
2851 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
2855 if (scalar_check (size, 0) == FAILURE)
2858 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2861 if (variable_check (size, 0) == FAILURE)
2864 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
2872 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2875 if (array_check (put, 1) == FAILURE)
2878 if (rank_check (put, 1, 1) == FAILURE)
2881 if (type_check (put, 1, BT_INTEGER) == FAILURE)
2884 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
2891 if (size != NULL || put != NULL)
2892 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2895 if (array_check (get, 2) == FAILURE)
2898 if (rank_check (get, 2, 1) == FAILURE)
2901 if (type_check (get, 2, BT_INTEGER) == FAILURE)
2904 if (variable_check (get, 2) == FAILURE)
2907 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
2916 gfc_check_second_sub (gfc_expr *time)
2918 if (scalar_check (time, 0) == FAILURE)
2921 if (type_check (time, 0, BT_REAL) == FAILURE)
2924 if (kind_value_check(time, 0, 4) == FAILURE)
2931 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2932 count, count_rate, and count_max are all optional arguments */
2935 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
2936 gfc_expr *count_max)
2940 if (scalar_check (count, 0) == FAILURE)
2943 if (type_check (count, 0, BT_INTEGER) == FAILURE)
2946 if (variable_check (count, 0) == FAILURE)
2950 if (count_rate != NULL)
2952 if (scalar_check (count_rate, 1) == FAILURE)
2955 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
2958 if (variable_check (count_rate, 1) == FAILURE)
2962 && same_type_check (count, 0, count_rate, 1) == FAILURE)
2967 if (count_max != NULL)
2969 if (scalar_check (count_max, 2) == FAILURE)
2972 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
2975 if (variable_check (count_max, 2) == FAILURE)
2979 && same_type_check (count, 0, count_max, 2) == FAILURE)
2982 if (count_rate != NULL
2983 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
2992 gfc_check_irand (gfc_expr *x)
2997 if (scalar_check (x, 0) == FAILURE)
3000 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3003 if (kind_value_check(x, 0, 4) == FAILURE)
3011 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
3013 if (scalar_check (seconds, 0) == FAILURE)
3016 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3019 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3021 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3022 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3023 gfc_current_intrinsic, &handler->where);
3027 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3033 if (scalar_check (status, 2) == FAILURE)
3036 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3039 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3047 gfc_check_rand (gfc_expr *x)
3052 if (scalar_check (x, 0) == FAILURE)
3055 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3058 if (kind_value_check(x, 0, 4) == FAILURE)
3066 gfc_check_srand (gfc_expr *x)
3068 if (scalar_check (x, 0) == FAILURE)
3071 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3074 if (kind_value_check(x, 0, 4) == FAILURE)
3082 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
3084 if (scalar_check (time, 0) == FAILURE)
3087 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3090 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
3098 gfc_check_etime (gfc_expr *x)
3100 if (array_check (x, 0) == FAILURE)
3103 if (rank_check (x, 0, 1) == FAILURE)
3106 if (variable_check (x, 0) == FAILURE)
3109 if (type_check (x, 0, BT_REAL) == FAILURE)
3112 if (kind_value_check(x, 0, 4) == FAILURE)
3120 gfc_check_etime_sub (gfc_expr *values, gfc_expr *time)
3122 if (array_check (values, 0) == FAILURE)
3125 if (rank_check (values, 0, 1) == FAILURE)
3128 if (variable_check (values, 0) == FAILURE)
3131 if (type_check (values, 0, BT_REAL) == FAILURE)
3134 if (kind_value_check(values, 0, 4) == FAILURE)
3137 if (scalar_check (time, 1) == FAILURE)
3140 if (type_check (time, 1, BT_REAL) == FAILURE)
3143 if (kind_value_check(time, 1, 4) == FAILURE)
3151 gfc_check_fdate_sub (gfc_expr *date)
3153 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3161 gfc_check_gerror (gfc_expr *msg)
3163 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3171 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
3173 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
3179 if (scalar_check (status, 1) == FAILURE)
3182 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3190 gfc_check_getlog (gfc_expr *msg)
3192 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3200 gfc_check_exit (gfc_expr *status)
3205 if (type_check (status, 0, BT_INTEGER) == FAILURE)
3208 if (scalar_check (status, 0) == FAILURE)
3216 gfc_check_flush (gfc_expr *unit)
3221 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3224 if (scalar_check (unit, 0) == FAILURE)
3232 gfc_check_free (gfc_expr *i)
3234 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3237 if (scalar_check (i, 0) == FAILURE)
3245 gfc_check_hostnm (gfc_expr *name)
3247 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3255 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
3257 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3263 if (scalar_check (status, 1) == FAILURE)
3266 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3274 gfc_check_itime_idate (gfc_expr *values)
3276 if (array_check (values, 0) == FAILURE)
3279 if (rank_check (values, 0, 1) == FAILURE)
3282 if (variable_check (values, 0) == FAILURE)
3285 if (type_check (values, 0, BT_INTEGER) == FAILURE)
3288 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
3296 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
3298 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3301 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
3304 if (scalar_check (time, 0) == FAILURE)
3307 if (array_check (values, 1) == FAILURE)
3310 if (rank_check (values, 1, 1) == FAILURE)
3313 if (variable_check (values, 1) == FAILURE)
3316 if (type_check (values, 1, BT_INTEGER) == FAILURE)
3319 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
3327 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
3329 if (scalar_check (unit, 0) == FAILURE)
3332 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3335 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
3343 gfc_check_isatty (gfc_expr *unit)
3348 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3351 if (scalar_check (unit, 0) == FAILURE)
3359 gfc_check_perror (gfc_expr *string)
3361 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
3369 gfc_check_umask (gfc_expr *mask)
3371 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3374 if (scalar_check (mask, 0) == FAILURE)
3382 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
3384 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3387 if (scalar_check (mask, 0) == FAILURE)
3393 if (scalar_check (old, 1) == FAILURE)
3396 if (type_check (old, 1, BT_INTEGER) == FAILURE)
3404 gfc_check_unlink (gfc_expr *name)
3406 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3414 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
3416 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3422 if (scalar_check (status, 1) == FAILURE)
3425 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3433 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
3435 if (scalar_check (number, 0) == FAILURE)
3438 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3441 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3443 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3444 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3445 gfc_current_intrinsic, &handler->where);
3449 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3457 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
3459 if (scalar_check (number, 0) == FAILURE)
3462 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3465 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3467 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3468 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3469 gfc_current_intrinsic, &handler->where);
3473 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3479 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3482 if (scalar_check (status, 2) == FAILURE)
3490 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
3492 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
3495 if (scalar_check (status, 1) == FAILURE)
3498 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3501 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
3508 /* This is used for the GNU intrinsics AND, OR and XOR. */
3510 gfc_check_and (gfc_expr *i, gfc_expr *j)
3512 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
3514 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3515 "or LOGICAL", gfc_current_intrinsic_arg[0],
3516 gfc_current_intrinsic, &i->where);
3520 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
3522 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3523 "or LOGICAL", gfc_current_intrinsic_arg[1],
3524 gfc_current_intrinsic, &j->where);
3528 if (i->ts.type != j->ts.type)
3530 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
3531 "have the same type", gfc_current_intrinsic_arg[0],
3532 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3537 if (scalar_check (i, 0) == FAILURE)
3540 if (scalar_check (j, 1) == FAILURE)