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 /***** Check functions *****/
403 /* Check subroutine suitable for intrinsics taking a real argument and
404 a kind argument for the result. */
407 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
409 if (type_check (a, 0, BT_REAL) == FAILURE)
411 if (kind_check (kind, 1, type) == FAILURE)
418 /* Check subroutine suitable for ceiling, floor and nint. */
421 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
423 return check_a_kind (a, kind, BT_INTEGER);
427 /* Check subroutine suitable for aint, anint. */
430 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
432 return check_a_kind (a, kind, BT_REAL);
437 gfc_check_abs (gfc_expr *a)
439 if (numeric_check (a, 0) == FAILURE)
447 gfc_check_achar (gfc_expr *a)
449 if (type_check (a, 0, BT_INTEGER) == FAILURE)
457 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
459 if (type_check (name, 0, BT_CHARACTER) == FAILURE
460 || scalar_check (name, 0) == FAILURE)
463 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
464 || scalar_check (mode, 1) == FAILURE)
472 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
474 if (logical_array_check (mask, 0) == FAILURE)
477 if (dim_check (dim, 1, 1) == FAILURE)
485 gfc_check_allocated (gfc_expr *array)
487 symbol_attribute attr;
489 if (variable_check (array, 0) == FAILURE)
492 if (array_check (array, 0) == FAILURE)
495 attr = gfc_variable_attr (array, NULL);
496 if (!attr.allocatable)
498 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
499 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
508 /* Common check function where the first argument must be real or
509 integer and the second argument must be the same as the first. */
512 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
514 if (int_or_real_check (a, 0) == FAILURE)
517 if (a->ts.type != p->ts.type)
519 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
520 "have the same type", gfc_current_intrinsic_arg[0],
521 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
526 if (a->ts.kind != p->ts.kind)
528 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
529 &p->where) == FAILURE)
538 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
540 symbol_attribute attr;
545 where = &pointer->where;
547 if (pointer->expr_type == EXPR_VARIABLE)
548 attr = gfc_variable_attr (pointer, NULL);
549 else if (pointer->expr_type == EXPR_FUNCTION)
550 attr = pointer->symtree->n.sym->attr;
551 else if (pointer->expr_type == EXPR_NULL)
554 gcc_assert (0); /* Pointer must be a variable or a function. */
558 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
559 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
564 /* Target argument is optional. */
568 where = &target->where;
569 if (target->expr_type == EXPR_NULL)
572 if (target->expr_type == EXPR_VARIABLE)
573 attr = gfc_variable_attr (target, NULL);
574 else if (target->expr_type == EXPR_FUNCTION)
575 attr = target->symtree->n.sym->attr;
578 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
579 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg[1],
580 gfc_current_intrinsic, &target->where);
584 if (!attr.pointer && !attr.target)
586 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
587 "or a TARGET", gfc_current_intrinsic_arg[1],
588 gfc_current_intrinsic, &target->where);
593 if (same_type_check (pointer, 0, target, 1) == FAILURE)
595 if (rank_check (target, 0, pointer->rank) == FAILURE)
597 if (target->rank > 0)
599 for (i = 0; i < target->rank; i++)
600 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
602 gfc_error ("Array section with a vector subscript at %L shall not "
603 "be the target of a pointer",
613 gfc_error ("NULL pointer at %L is not permitted as actual argument "
614 "of '%s' intrinsic function", where, gfc_current_intrinsic);
621 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
623 if (type_check (y, 0, BT_REAL) == FAILURE)
625 if (same_type_check (y, 0, x, 1) == FAILURE)
632 /* BESJN and BESYN functions. */
635 gfc_check_besn (gfc_expr *n, gfc_expr *x)
637 if (type_check (n, 0, BT_INTEGER) == FAILURE)
640 if (type_check (x, 1, BT_REAL) == FAILURE)
648 gfc_check_btest (gfc_expr *i, gfc_expr *pos)
650 if (type_check (i, 0, BT_INTEGER) == FAILURE)
652 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
660 gfc_check_char (gfc_expr *i, gfc_expr *kind)
662 if (type_check (i, 0, BT_INTEGER) == FAILURE)
664 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
672 gfc_check_chdir (gfc_expr *dir)
674 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
682 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
684 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
690 if (type_check (status, 1, BT_INTEGER) == FAILURE)
693 if (scalar_check (status, 1) == FAILURE)
701 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
703 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
706 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
714 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
716 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
719 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
725 if (type_check (status, 2, BT_INTEGER) == FAILURE)
728 if (scalar_check (status, 2) == FAILURE)
736 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
738 if (numeric_check (x, 0) == FAILURE)
743 if (numeric_check (y, 1) == FAILURE)
746 if (x->ts.type == BT_COMPLEX)
748 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
749 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
750 gfc_current_intrinsic, &y->where);
755 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
763 gfc_check_complex (gfc_expr *x, gfc_expr *y)
765 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
767 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
768 "or REAL", gfc_current_intrinsic_arg[0],
769 gfc_current_intrinsic, &x->where);
772 if (scalar_check (x, 0) == FAILURE)
775 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
777 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
778 "or REAL", gfc_current_intrinsic_arg[1],
779 gfc_current_intrinsic, &y->where);
782 if (scalar_check (y, 1) == FAILURE)
790 gfc_check_count (gfc_expr *mask, gfc_expr *dim)
792 if (logical_array_check (mask, 0) == FAILURE)
794 if (dim_check (dim, 1, 1) == FAILURE)
802 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
804 if (array_check (array, 0) == FAILURE)
807 if (array->rank == 1)
809 if (scalar_check (shift, 1) == FAILURE)
814 /* TODO: more requirements on shift parameter. */
817 if (dim_check (dim, 2, 1) == FAILURE)
825 gfc_check_ctime (gfc_expr *time)
827 if (scalar_check (time, 0) == FAILURE)
830 if (type_check (time, 0, BT_INTEGER) == FAILURE)
838 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
840 if (numeric_check (x, 0) == FAILURE)
845 if (numeric_check (y, 1) == FAILURE)
848 if (x->ts.type == BT_COMPLEX)
850 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
851 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
852 gfc_current_intrinsic, &y->where);
862 gfc_check_dble (gfc_expr *x)
864 if (numeric_check (x, 0) == FAILURE)
872 gfc_check_digits (gfc_expr *x)
874 if (int_or_real_check (x, 0) == FAILURE)
882 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
884 switch (vector_a->ts.type)
887 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
894 if (numeric_check (vector_b, 1) == FAILURE)
899 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
900 "or LOGICAL", gfc_current_intrinsic_arg[0],
901 gfc_current_intrinsic, &vector_a->where);
905 if (rank_check (vector_a, 0, 1) == FAILURE)
908 if (rank_check (vector_b, 1, 1) == FAILURE)
911 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
913 gfc_error ("different shape for arguments '%s' and '%s' at %L for "
914 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0],
915 gfc_current_intrinsic_arg[1], &vector_a->where);
924 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
927 if (array_check (array, 0) == FAILURE)
930 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
933 if (array->rank == 1)
935 if (scalar_check (shift, 2) == FAILURE)
940 /* TODO: more weird restrictions on shift. */
943 if (boundary != NULL)
945 if (same_type_check (array, 0, boundary, 2) == FAILURE)
948 /* TODO: more restrictions on boundary. */
951 if (dim_check (dim, 1, 1) == FAILURE)
958 /* A single complex argument. */
961 gfc_check_fn_c (gfc_expr *a)
963 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
970 /* A single real argument. */
973 gfc_check_fn_r (gfc_expr *a)
975 if (type_check (a, 0, BT_REAL) == FAILURE)
982 /* A single real or complex argument. */
985 gfc_check_fn_rc (gfc_expr *a)
987 if (real_or_complex_check (a, 0) == FAILURE)
995 gfc_check_fnum (gfc_expr *unit)
997 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1000 if (scalar_check (unit, 0) == FAILURE)
1008 gfc_check_huge (gfc_expr *x)
1010 if (int_or_real_check (x, 0) == FAILURE)
1017 /* Check that the single argument is an integer. */
1020 gfc_check_i (gfc_expr *i)
1022 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1030 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1032 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1035 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1038 if (i->ts.kind != j->ts.kind)
1040 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1041 &i->where) == FAILURE)
1050 gfc_check_ibclr (gfc_expr *i, gfc_expr *pos)
1052 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1055 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1063 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1065 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1068 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1071 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1079 gfc_check_ibset (gfc_expr *i, gfc_expr *pos)
1081 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1084 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1092 gfc_check_ichar_iachar (gfc_expr *c)
1096 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1099 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1105 /* Substring references don't have the charlength set. */
1107 while (ref && ref->type != REF_SUBSTRING)
1110 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1114 /* Check that the argument is length one. Non-constant lengths
1115 can't be checked here, so assume they are ok. */
1116 if (c->ts.cl && c->ts.cl->length)
1118 /* If we already have a length for this expression then use it. */
1119 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
1121 i = mpz_get_si (c->ts.cl->length->value.integer);
1128 start = ref->u.ss.start;
1129 end = ref->u.ss.end;
1132 if (end == NULL || end->expr_type != EXPR_CONSTANT
1133 || start->expr_type != EXPR_CONSTANT)
1136 i = mpz_get_si (end->value.integer) + 1
1137 - mpz_get_si (start->value.integer);
1145 gfc_error ("Argument of %s at %L must be of length one",
1146 gfc_current_intrinsic, &c->where);
1155 gfc_check_idnint (gfc_expr *a)
1157 if (double_check (a, 0) == FAILURE)
1165 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1167 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1170 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1173 if (i->ts.kind != j->ts.kind)
1175 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1176 &i->where) == FAILURE)
1185 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back)
1187 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1188 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1192 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1195 if (string->ts.kind != substring->ts.kind)
1197 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1198 "kind as '%s'", gfc_current_intrinsic_arg[1],
1199 gfc_current_intrinsic, &substring->where,
1200 gfc_current_intrinsic_arg[0]);
1209 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1211 if (numeric_check (x, 0) == FAILURE)
1216 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
1219 if (scalar_check (kind, 1) == FAILURE)
1228 gfc_check_intconv (gfc_expr *x)
1230 if (numeric_check (x, 0) == FAILURE)
1238 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1240 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1243 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1246 if (i->ts.kind != j->ts.kind)
1248 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1249 &i->where) == FAILURE)
1258 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1260 if (type_check (i, 0, BT_INTEGER) == FAILURE
1261 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1269 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1271 if (type_check (i, 0, BT_INTEGER) == FAILURE
1272 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1275 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1283 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1285 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1288 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1296 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1298 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1301 if (scalar_check (pid, 0) == FAILURE)
1304 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1307 if (scalar_check (sig, 1) == FAILURE)
1313 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1316 if (scalar_check (status, 2) == FAILURE)
1324 gfc_check_kind (gfc_expr *x)
1326 if (x->ts.type == BT_DERIVED)
1328 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1329 "non-derived type", gfc_current_intrinsic_arg[0],
1330 gfc_current_intrinsic, &x->where);
1339 gfc_check_lbound (gfc_expr *array, gfc_expr *dim)
1341 if (array_check (array, 0) == FAILURE)
1346 if (dim_check (dim, 1, 1) == FAILURE)
1349 if (dim_rank_check (dim, array, 1) == FAILURE)
1357 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
1359 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1362 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1370 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1372 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1375 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1381 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1384 if (scalar_check (status, 2) == FAILURE)
1392 gfc_check_loc (gfc_expr *expr)
1394 return variable_check (expr, 0);
1399 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
1401 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1404 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1412 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1414 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1417 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1423 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1426 if (scalar_check (status, 2) == FAILURE)
1434 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
1436 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1438 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1445 /* Min/max family. */
1448 min_max_args (gfc_actual_arglist *arg)
1450 if (arg == NULL || arg->next == NULL)
1452 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1453 gfc_current_intrinsic, gfc_current_intrinsic_where);
1462 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
1464 gfc_actual_arglist *arg, *tmp;
1469 if (min_max_args (arglist) == FAILURE)
1472 for (arg = arglist, n=1; arg; arg = arg->next, n++)
1475 if (x->ts.type != type || x->ts.kind != kind)
1477 if (x->ts.type == type)
1479 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
1480 "kinds at %L", &x->where) == FAILURE)
1485 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1486 "%s(%d)", n, gfc_current_intrinsic, &x->where,
1487 gfc_basic_typename (type), kind);
1492 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
1495 snprintf (buffer, 80, "arguments 'a%d' and 'a%d' for intrinsic '%s'",
1496 m, n, gfc_current_intrinsic);
1497 if (gfc_check_conformance (buffer, tmp->expr, x) == FAILURE)
1507 gfc_check_min_max (gfc_actual_arglist *arg)
1511 if (min_max_args (arg) == FAILURE)
1516 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1518 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER "
1519 "or REAL", gfc_current_intrinsic, &x->where);
1523 return check_rest (x->ts.type, x->ts.kind, arg);
1528 gfc_check_min_max_integer (gfc_actual_arglist *arg)
1530 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1535 gfc_check_min_max_real (gfc_actual_arglist *arg)
1537 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1542 gfc_check_min_max_double (gfc_actual_arglist *arg)
1544 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1548 /* End of min/max family. */
1551 gfc_check_malloc (gfc_expr *size)
1553 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1556 if (scalar_check (size, 0) == FAILURE)
1564 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
1566 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1568 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1569 "or LOGICAL", gfc_current_intrinsic_arg[0],
1570 gfc_current_intrinsic, &matrix_a->where);
1574 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1576 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1577 "or LOGICAL", gfc_current_intrinsic_arg[1],
1578 gfc_current_intrinsic, &matrix_b->where);
1582 switch (matrix_a->rank)
1585 if (rank_check (matrix_b, 1, 2) == FAILURE)
1587 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
1588 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
1590 gfc_error ("different shape on dimension 1 for arguments '%s' "
1591 "and '%s' at %L for intrinsic matmul",
1592 gfc_current_intrinsic_arg[0],
1593 gfc_current_intrinsic_arg[1], &matrix_a->where);
1599 if (matrix_b->rank != 2)
1601 if (rank_check (matrix_b, 1, 1) == FAILURE)
1604 /* matrix_b has rank 1 or 2 here. Common check for the cases
1605 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
1606 - matrix_a has shape (n,m) and matrix_b has shape (m). */
1607 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
1609 gfc_error ("different shape on dimension 2 for argument '%s' and "
1610 "dimension 1 for argument '%s' at %L for intrinsic "
1611 "matmul", gfc_current_intrinsic_arg[0],
1612 gfc_current_intrinsic_arg[1], &matrix_a->where);
1618 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1619 "1 or 2", gfc_current_intrinsic_arg[0],
1620 gfc_current_intrinsic, &matrix_a->where);
1628 /* Whoever came up with this interface was probably on something.
1629 The possibilities for the occupation of the second and third
1636 NULL MASK minloc(array, mask=m)
1639 I.e. in the case of minloc(array,mask), mask will be in the second
1640 position of the argument list and we'll have to fix that up. */
1643 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
1645 gfc_expr *a, *m, *d;
1648 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
1652 m = ap->next->next->expr;
1654 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1655 && ap->next->name == NULL)
1659 ap->next->expr = NULL;
1660 ap->next->next->expr = m;
1663 if (dim_check (d, 1, 1) == FAILURE)
1666 if (d && dim_rank_check (d, a, 0) == FAILURE)
1669 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1675 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1676 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1677 gfc_current_intrinsic);
1678 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1686 /* Similar to minloc/maxloc, the argument list might need to be
1687 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1688 difference is that MINLOC/MAXLOC take an additional KIND argument.
1689 The possibilities are:
1695 NULL MASK minval(array, mask=m)
1698 I.e. in the case of minval(array,mask), mask will be in the second
1699 position of the argument list and we'll have to fix that up. */
1702 check_reduction (gfc_actual_arglist *ap)
1704 gfc_expr *a, *m, *d;
1708 m = ap->next->next->expr;
1710 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1711 && ap->next->name == NULL)
1715 ap->next->expr = NULL;
1716 ap->next->next->expr = m;
1719 if (dim_check (d, 1, 1) == FAILURE)
1722 if (d && dim_rank_check (d, a, 0) == FAILURE)
1725 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1731 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1732 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1733 gfc_current_intrinsic);
1734 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1743 gfc_check_minval_maxval (gfc_actual_arglist *ap)
1745 if (int_or_real_check (ap->expr, 0) == FAILURE
1746 || array_check (ap->expr, 0) == FAILURE)
1749 return check_reduction (ap);
1754 gfc_check_product_sum (gfc_actual_arglist *ap)
1756 if (numeric_check (ap->expr, 0) == FAILURE
1757 || array_check (ap->expr, 0) == FAILURE)
1760 return check_reduction (ap);
1765 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
1767 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
1770 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
1777 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
1779 symbol_attribute attr;
1781 if (variable_check (from, 0) == FAILURE)
1784 if (array_check (from, 0) == FAILURE)
1787 attr = gfc_variable_attr (from, NULL);
1788 if (!attr.allocatable)
1790 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1791 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1796 if (variable_check (to, 0) == FAILURE)
1799 if (array_check (to, 0) == FAILURE)
1802 attr = gfc_variable_attr (to, NULL);
1803 if (!attr.allocatable)
1805 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1806 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1811 if (same_type_check (from, 0, to, 1) == FAILURE)
1814 if (to->rank != from->rank)
1816 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1817 "have the same rank %d/%d", gfc_current_intrinsic_arg[0],
1818 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1819 &to->where, from->rank, to->rank);
1823 if (to->ts.kind != from->ts.kind)
1825 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1826 "be of the same kind %d/%d", gfc_current_intrinsic_arg[0],
1827 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1828 &to->where, from->ts.kind, to->ts.kind);
1837 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
1839 if (type_check (x, 0, BT_REAL) == FAILURE)
1842 if (type_check (s, 1, BT_REAL) == FAILURE)
1850 gfc_check_new_line (gfc_expr *a)
1852 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1860 gfc_check_null (gfc_expr *mold)
1862 symbol_attribute attr;
1867 if (variable_check (mold, 0) == FAILURE)
1870 attr = gfc_variable_attr (mold, NULL);
1874 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
1875 gfc_current_intrinsic_arg[0],
1876 gfc_current_intrinsic, &mold->where);
1885 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
1889 if (array_check (array, 0) == FAILURE)
1892 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1895 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1896 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1897 gfc_current_intrinsic);
1898 if (gfc_check_conformance (buffer, array, mask) == FAILURE)
1903 if (same_type_check (array, 0, vector, 2) == FAILURE)
1906 if (rank_check (vector, 2, 1) == FAILURE)
1909 /* TODO: More constraints here. */
1917 gfc_check_precision (gfc_expr *x)
1919 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
1921 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
1922 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
1923 gfc_current_intrinsic, &x->where);
1932 gfc_check_present (gfc_expr *a)
1936 if (variable_check (a, 0) == FAILURE)
1939 sym = a->symtree->n.sym;
1940 if (!sym->attr.dummy)
1942 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
1943 "dummy variable", gfc_current_intrinsic_arg[0],
1944 gfc_current_intrinsic, &a->where);
1948 if (!sym->attr.optional)
1950 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
1951 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
1952 gfc_current_intrinsic, &a->where);
1956 /* 13.14.82 PRESENT(A)
1958 Argument. A shall be the name of an optional dummy argument that is
1959 accessible in the subprogram in which the PRESENT function reference
1963 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
1964 && a->ref->u.ar.type == AR_FULL))
1966 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
1967 "subobject of '%s'", gfc_current_intrinsic_arg[0],
1968 gfc_current_intrinsic, &a->where, sym->name);
1977 gfc_check_radix (gfc_expr *x)
1979 if (int_or_real_check (x, 0) == FAILURE)
1987 gfc_check_range (gfc_expr *x)
1989 if (numeric_check (x, 0) == FAILURE)
1996 /* real, float, sngl. */
1998 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2000 if (numeric_check (a, 0) == FAILURE)
2003 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2011 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2013 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2016 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2024 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2026 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2029 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2035 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2038 if (scalar_check (status, 2) == FAILURE)
2046 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2048 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2051 if (scalar_check (x, 0) == FAILURE)
2054 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2057 if (scalar_check (y, 1) == FAILURE)
2065 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2066 gfc_expr *pad, gfc_expr *order)
2072 if (array_check (source, 0) == FAILURE)
2075 if (rank_check (shape, 1, 1) == FAILURE)
2078 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2081 if (gfc_array_size (shape, &size) != SUCCESS)
2083 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2084 "array of constant size", &shape->where);
2088 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
2093 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2094 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2100 if (same_type_check (source, 0, pad, 2) == FAILURE)
2102 if (array_check (pad, 2) == FAILURE)
2106 if (order != NULL && array_check (order, 3) == FAILURE)
2109 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2110 && gfc_is_constant_expr (shape)
2111 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2112 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2114 /* Check the match in size between source and destination. */
2115 if (gfc_array_size (source, &nelems) == SUCCESS)
2120 c = shape->value.constructor;
2121 mpz_init_set_ui (size, 1);
2122 for (; c; c = c->next)
2123 mpz_mul (size, size, c->expr->value.integer);
2125 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2131 gfc_error ("Without padding, there are not enough elements "
2132 "in the intrinsic RESHAPE source at %L to match "
2133 "the shape", &source->where);
2144 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2146 if (type_check (x, 0, BT_REAL) == FAILURE)
2149 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2157 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2159 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2162 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2165 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2168 if (same_type_check (x, 0, y, 1) == FAILURE)
2176 gfc_check_secnds (gfc_expr *r)
2178 if (type_check (r, 0, BT_REAL) == FAILURE)
2181 if (kind_value_check (r, 0, 4) == FAILURE)
2184 if (scalar_check (r, 0) == FAILURE)
2192 gfc_check_selected_int_kind (gfc_expr *r)
2194 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2197 if (scalar_check (r, 0) == FAILURE)
2205 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r)
2207 if (p == NULL && r == NULL)
2209 gfc_error ("Missing arguments to %s intrinsic at %L",
2210 gfc_current_intrinsic, gfc_current_intrinsic_where);
2215 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
2218 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
2226 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
2228 if (type_check (x, 0, BT_REAL) == FAILURE)
2231 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2239 gfc_check_shape (gfc_expr *source)
2243 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2246 ar = gfc_find_array_ref (source);
2248 if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
2250 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2251 "an assumed size array", &source->where);
2260 gfc_check_sign (gfc_expr *a, gfc_expr *b)
2262 if (int_or_real_check (a, 0) == FAILURE)
2265 if (same_type_check (a, 0, b, 1) == FAILURE)
2273 gfc_check_size (gfc_expr *array, gfc_expr *dim)
2275 if (array_check (array, 0) == FAILURE)
2280 if (type_check (dim, 1, BT_INTEGER) == FAILURE)
2283 if (kind_value_check (dim, 1, gfc_default_integer_kind) == FAILURE)
2286 if (dim_rank_check (dim, array, 0) == FAILURE)
2295 gfc_check_sizeof (gfc_expr *arg __attribute__((unused)))
2302 gfc_check_sleep_sub (gfc_expr *seconds)
2304 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2307 if (scalar_check (seconds, 0) == FAILURE)
2315 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
2317 if (source->rank >= GFC_MAX_DIMENSIONS)
2319 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2320 "than rank %d", gfc_current_intrinsic_arg[0],
2321 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2326 if (dim_check (dim, 1, 0) == FAILURE)
2329 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2332 if (scalar_check (ncopies, 2) == FAILURE)
2339 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2343 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
2345 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2348 if (scalar_check (unit, 0) == FAILURE)
2351 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2357 if (type_check (status, 2, BT_INTEGER) == FAILURE
2358 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2359 || scalar_check (status, 2) == FAILURE)
2367 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
2369 return gfc_check_fgetputc_sub (unit, c, NULL);
2374 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
2376 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2382 if (type_check (status, 1, BT_INTEGER) == FAILURE
2383 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2384 || scalar_check (status, 1) == FAILURE)
2392 gfc_check_fgetput (gfc_expr *c)
2394 return gfc_check_fgetput_sub (c, NULL);
2399 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
2401 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2404 if (scalar_check (unit, 0) == FAILURE)
2407 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2410 if (scalar_check (offset, 1) == FAILURE)
2413 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
2416 if (scalar_check (whence, 2) == FAILURE)
2422 if (type_check (status, 3, BT_INTEGER) == FAILURE)
2425 if (kind_value_check (status, 3, 4) == FAILURE)
2428 if (scalar_check (status, 3) == FAILURE)
2437 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
2439 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2442 if (scalar_check (unit, 0) == FAILURE)
2445 if (type_check (array, 1, BT_INTEGER) == FAILURE
2446 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2449 if (array_check (array, 1) == FAILURE)
2457 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
2459 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2462 if (scalar_check (unit, 0) == FAILURE)
2465 if (type_check (array, 1, BT_INTEGER) == FAILURE
2466 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2469 if (array_check (array, 1) == FAILURE)
2475 if (type_check (status, 2, BT_INTEGER) == FAILURE
2476 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2479 if (scalar_check (status, 2) == FAILURE)
2487 gfc_check_ftell (gfc_expr *unit)
2489 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2492 if (scalar_check (unit, 0) == FAILURE)
2500 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
2502 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2505 if (scalar_check (unit, 0) == FAILURE)
2508 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2511 if (scalar_check (offset, 1) == FAILURE)
2519 gfc_check_stat (gfc_expr *name, gfc_expr *array)
2521 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2524 if (type_check (array, 1, BT_INTEGER) == FAILURE
2525 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2528 if (array_check (array, 1) == FAILURE)
2536 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
2538 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2541 if (type_check (array, 1, BT_INTEGER) == FAILURE
2542 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2545 if (array_check (array, 1) == FAILURE)
2551 if (type_check (status, 2, BT_INTEGER) == FAILURE
2552 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2555 if (scalar_check (status, 2) == FAILURE)
2563 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
2564 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
2566 if (mold->ts.type == BT_HOLLERITH)
2568 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
2569 &mold->where, gfc_basic_typename (BT_HOLLERITH));
2575 if (type_check (size, 2, BT_INTEGER) == FAILURE)
2578 if (scalar_check (size, 2) == FAILURE)
2581 if (nonoptional_check (size, 2) == FAILURE)
2590 gfc_check_transpose (gfc_expr *matrix)
2592 if (rank_check (matrix, 0, 2) == FAILURE)
2600 gfc_check_ubound (gfc_expr *array, gfc_expr *dim)
2602 if (array_check (array, 0) == FAILURE)
2607 if (dim_check (dim, 1, 1) == FAILURE)
2610 if (dim_rank_check (dim, array, 0) == FAILURE)
2619 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
2621 if (rank_check (vector, 0, 1) == FAILURE)
2624 if (array_check (mask, 1) == FAILURE)
2627 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2630 if (same_type_check (vector, 0, field, 2) == FAILURE)
2638 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2640 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2643 if (same_type_check (x, 0, y, 1) == FAILURE)
2646 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2654 gfc_check_trim (gfc_expr *x)
2656 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2659 if (scalar_check (x, 0) == FAILURE)
2667 gfc_check_ttynam (gfc_expr *unit)
2669 if (scalar_check (unit, 0) == FAILURE)
2672 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2679 /* Common check function for the half a dozen intrinsics that have a
2680 single real argument. */
2683 gfc_check_x (gfc_expr *x)
2685 if (type_check (x, 0, BT_REAL) == FAILURE)
2692 /************* Check functions for intrinsic subroutines *************/
2695 gfc_check_cpu_time (gfc_expr *time)
2697 if (scalar_check (time, 0) == FAILURE)
2700 if (type_check (time, 0, BT_REAL) == FAILURE)
2703 if (variable_check (time, 0) == FAILURE)
2711 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
2712 gfc_expr *zone, gfc_expr *values)
2716 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2718 if (scalar_check (date, 0) == FAILURE)
2720 if (variable_check (date, 0) == FAILURE)
2726 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
2728 if (scalar_check (time, 1) == FAILURE)
2730 if (variable_check (time, 1) == FAILURE)
2736 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
2738 if (scalar_check (zone, 2) == FAILURE)
2740 if (variable_check (zone, 2) == FAILURE)
2746 if (type_check (values, 3, BT_INTEGER) == FAILURE)
2748 if (array_check (values, 3) == FAILURE)
2750 if (rank_check (values, 3, 1) == FAILURE)
2752 if (variable_check (values, 3) == FAILURE)
2761 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
2762 gfc_expr *to, gfc_expr *topos)
2764 if (type_check (from, 0, BT_INTEGER) == FAILURE)
2767 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
2770 if (type_check (len, 2, BT_INTEGER) == FAILURE)
2773 if (same_type_check (from, 0, to, 3) == FAILURE)
2776 if (variable_check (to, 3) == FAILURE)
2779 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
2787 gfc_check_random_number (gfc_expr *harvest)
2789 if (type_check (harvest, 0, BT_REAL) == FAILURE)
2792 if (variable_check (harvest, 0) == FAILURE)
2800 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
2804 if (scalar_check (size, 0) == FAILURE)
2807 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2810 if (variable_check (size, 0) == FAILURE)
2813 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
2821 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2824 if (array_check (put, 1) == FAILURE)
2827 if (rank_check (put, 1, 1) == FAILURE)
2830 if (type_check (put, 1, BT_INTEGER) == FAILURE)
2833 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
2840 if (size != NULL || put != NULL)
2841 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2844 if (array_check (get, 2) == FAILURE)
2847 if (rank_check (get, 2, 1) == FAILURE)
2850 if (type_check (get, 2, BT_INTEGER) == FAILURE)
2853 if (variable_check (get, 2) == FAILURE)
2856 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
2865 gfc_check_second_sub (gfc_expr *time)
2867 if (scalar_check (time, 0) == FAILURE)
2870 if (type_check (time, 0, BT_REAL) == FAILURE)
2873 if (kind_value_check(time, 0, 4) == FAILURE)
2880 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2881 count, count_rate, and count_max are all optional arguments */
2884 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
2885 gfc_expr *count_max)
2889 if (scalar_check (count, 0) == FAILURE)
2892 if (type_check (count, 0, BT_INTEGER) == FAILURE)
2895 if (variable_check (count, 0) == FAILURE)
2899 if (count_rate != NULL)
2901 if (scalar_check (count_rate, 1) == FAILURE)
2904 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
2907 if (variable_check (count_rate, 1) == FAILURE)
2911 && same_type_check (count, 0, count_rate, 1) == FAILURE)
2916 if (count_max != NULL)
2918 if (scalar_check (count_max, 2) == FAILURE)
2921 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
2924 if (variable_check (count_max, 2) == FAILURE)
2928 && same_type_check (count, 0, count_max, 2) == FAILURE)
2931 if (count_rate != NULL
2932 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
2941 gfc_check_irand (gfc_expr *x)
2946 if (scalar_check (x, 0) == FAILURE)
2949 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2952 if (kind_value_check(x, 0, 4) == FAILURE)
2960 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
2962 if (scalar_check (seconds, 0) == FAILURE)
2965 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2968 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
2970 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
2971 "or PROCEDURE", gfc_current_intrinsic_arg[1],
2972 gfc_current_intrinsic, &handler->where);
2976 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
2982 if (scalar_check (status, 2) == FAILURE)
2985 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2988 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2996 gfc_check_rand (gfc_expr *x)
3001 if (scalar_check (x, 0) == FAILURE)
3004 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3007 if (kind_value_check(x, 0, 4) == FAILURE)
3015 gfc_check_srand (gfc_expr *x)
3017 if (scalar_check (x, 0) == FAILURE)
3020 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3023 if (kind_value_check(x, 0, 4) == FAILURE)
3031 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
3033 if (scalar_check (time, 0) == FAILURE)
3036 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3039 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
3047 gfc_check_etime (gfc_expr *x)
3049 if (array_check (x, 0) == FAILURE)
3052 if (rank_check (x, 0, 1) == FAILURE)
3055 if (variable_check (x, 0) == FAILURE)
3058 if (type_check (x, 0, BT_REAL) == FAILURE)
3061 if (kind_value_check(x, 0, 4) == FAILURE)
3069 gfc_check_etime_sub (gfc_expr *values, gfc_expr *time)
3071 if (array_check (values, 0) == FAILURE)
3074 if (rank_check (values, 0, 1) == FAILURE)
3077 if (variable_check (values, 0) == FAILURE)
3080 if (type_check (values, 0, BT_REAL) == FAILURE)
3083 if (kind_value_check(values, 0, 4) == FAILURE)
3086 if (scalar_check (time, 1) == FAILURE)
3089 if (type_check (time, 1, BT_REAL) == FAILURE)
3092 if (kind_value_check(time, 1, 4) == FAILURE)
3100 gfc_check_fdate_sub (gfc_expr *date)
3102 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3110 gfc_check_gerror (gfc_expr *msg)
3112 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3120 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
3122 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
3128 if (scalar_check (status, 1) == FAILURE)
3131 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3139 gfc_check_getlog (gfc_expr *msg)
3141 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3149 gfc_check_exit (gfc_expr *status)
3154 if (type_check (status, 0, BT_INTEGER) == FAILURE)
3157 if (scalar_check (status, 0) == FAILURE)
3165 gfc_check_flush (gfc_expr *unit)
3170 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3173 if (scalar_check (unit, 0) == FAILURE)
3181 gfc_check_free (gfc_expr *i)
3183 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3186 if (scalar_check (i, 0) == FAILURE)
3194 gfc_check_hostnm (gfc_expr *name)
3196 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3204 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
3206 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3212 if (scalar_check (status, 1) == FAILURE)
3215 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3223 gfc_check_itime_idate (gfc_expr *values)
3225 if (array_check (values, 0) == FAILURE)
3228 if (rank_check (values, 0, 1) == FAILURE)
3231 if (variable_check (values, 0) == FAILURE)
3234 if (type_check (values, 0, BT_INTEGER) == FAILURE)
3237 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
3245 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
3247 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3250 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
3253 if (scalar_check (time, 0) == FAILURE)
3256 if (array_check (values, 1) == FAILURE)
3259 if (rank_check (values, 1, 1) == FAILURE)
3262 if (variable_check (values, 1) == FAILURE)
3265 if (type_check (values, 1, BT_INTEGER) == FAILURE)
3268 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
3276 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
3278 if (scalar_check (unit, 0) == FAILURE)
3281 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3284 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
3292 gfc_check_isatty (gfc_expr *unit)
3297 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3300 if (scalar_check (unit, 0) == FAILURE)
3308 gfc_check_perror (gfc_expr *string)
3310 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
3318 gfc_check_umask (gfc_expr *mask)
3320 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3323 if (scalar_check (mask, 0) == FAILURE)
3331 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
3333 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3336 if (scalar_check (mask, 0) == FAILURE)
3342 if (scalar_check (old, 1) == FAILURE)
3345 if (type_check (old, 1, BT_INTEGER) == FAILURE)
3353 gfc_check_unlink (gfc_expr *name)
3355 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3363 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
3365 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3371 if (scalar_check (status, 1) == FAILURE)
3374 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3382 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
3384 if (scalar_check (number, 0) == FAILURE)
3387 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3390 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3392 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3393 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3394 gfc_current_intrinsic, &handler->where);
3398 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3406 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
3408 if (scalar_check (number, 0) == FAILURE)
3411 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3414 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3416 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3417 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3418 gfc_current_intrinsic, &handler->where);
3422 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3428 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3431 if (scalar_check (status, 2) == FAILURE)
3439 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
3441 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
3444 if (scalar_check (status, 1) == FAILURE)
3447 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3450 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
3457 /* This is used for the GNU intrinsics AND, OR and XOR. */
3459 gfc_check_and (gfc_expr *i, gfc_expr *j)
3461 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
3463 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3464 "or LOGICAL", gfc_current_intrinsic_arg[0],
3465 gfc_current_intrinsic, &i->where);
3469 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
3471 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3472 "or LOGICAL", gfc_current_intrinsic_arg[1],
3473 gfc_current_intrinsic, &j->where);
3477 if (i->ts.type != j->ts.type)
3479 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
3480 "have the same type", gfc_current_intrinsic_arg[0],
3481 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3486 if (scalar_check (i, 0) == FAILURE)
3489 if (scalar_check (j, 1) == FAILURE)