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 (scalar_check (n, 0) == FAILURE)
655 if (type_check (n, 0, BT_INTEGER) == FAILURE)
658 if (scalar_check (x, 1) == FAILURE)
661 if (type_check (x, 1, BT_REAL) == FAILURE)
669 gfc_check_btest (gfc_expr *i, gfc_expr *pos)
671 if (type_check (i, 0, BT_INTEGER) == FAILURE)
673 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
681 gfc_check_char (gfc_expr *i, gfc_expr *kind)
683 if (type_check (i, 0, BT_INTEGER) == FAILURE)
685 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
693 gfc_check_chdir (gfc_expr *dir)
695 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
703 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
705 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
711 if (type_check (status, 1, BT_INTEGER) == FAILURE)
714 if (scalar_check (status, 1) == FAILURE)
722 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
724 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
727 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
735 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
737 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
740 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
746 if (type_check (status, 2, BT_INTEGER) == FAILURE)
749 if (scalar_check (status, 2) == FAILURE)
757 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
759 if (numeric_check (x, 0) == FAILURE)
764 if (numeric_check (y, 1) == FAILURE)
767 if (x->ts.type == BT_COMPLEX)
769 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
770 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
771 gfc_current_intrinsic, &y->where);
776 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
784 gfc_check_complex (gfc_expr *x, gfc_expr *y)
786 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
788 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
789 "or REAL", gfc_current_intrinsic_arg[0],
790 gfc_current_intrinsic, &x->where);
793 if (scalar_check (x, 0) == FAILURE)
796 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
798 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
799 "or REAL", gfc_current_intrinsic_arg[1],
800 gfc_current_intrinsic, &y->where);
803 if (scalar_check (y, 1) == FAILURE)
811 gfc_check_count (gfc_expr *mask, gfc_expr *dim)
813 if (logical_array_check (mask, 0) == FAILURE)
815 if (dim_check (dim, 1, 1) == FAILURE)
819 return non_init_transformational ();
826 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
828 if (array_check (array, 0) == FAILURE)
831 if (array->rank == 1)
833 if (scalar_check (shift, 1) == FAILURE)
838 /* TODO: more requirements on shift parameter. */
841 if (dim_check (dim, 2, 1) == FAILURE)
845 return non_init_transformational ();
852 gfc_check_ctime (gfc_expr *time)
854 if (scalar_check (time, 0) == FAILURE)
857 if (type_check (time, 0, BT_INTEGER) == FAILURE)
865 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
867 if (numeric_check (x, 0) == FAILURE)
872 if (numeric_check (y, 1) == FAILURE)
875 if (x->ts.type == BT_COMPLEX)
877 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
878 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
879 gfc_current_intrinsic, &y->where);
889 gfc_check_dble (gfc_expr *x)
891 if (numeric_check (x, 0) == FAILURE)
899 gfc_check_digits (gfc_expr *x)
901 if (int_or_real_check (x, 0) == FAILURE)
909 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
911 switch (vector_a->ts.type)
914 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
921 if (numeric_check (vector_b, 1) == FAILURE)
926 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
927 "or LOGICAL", gfc_current_intrinsic_arg[0],
928 gfc_current_intrinsic, &vector_a->where);
932 if (rank_check (vector_a, 0, 1) == FAILURE)
935 if (rank_check (vector_b, 1, 1) == FAILURE)
938 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
940 gfc_error ("different shape for arguments '%s' and '%s' at %L for "
941 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0],
942 gfc_current_intrinsic_arg[1], &vector_a->where);
947 return non_init_transformational ();
954 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
957 if (array_check (array, 0) == FAILURE)
960 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
963 if (array->rank == 1)
965 if (scalar_check (shift, 2) == FAILURE)
970 /* TODO: more weird restrictions on shift. */
973 if (boundary != NULL)
975 if (same_type_check (array, 0, boundary, 2) == FAILURE)
978 /* TODO: more restrictions on boundary. */
981 if (dim_check (dim, 1, 1) == FAILURE)
985 return non_init_transformational ();
991 /* A single complex argument. */
994 gfc_check_fn_c (gfc_expr *a)
996 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
1003 /* A single real argument. */
1006 gfc_check_fn_r (gfc_expr *a)
1008 if (type_check (a, 0, BT_REAL) == FAILURE)
1015 /* A single real or complex argument. */
1018 gfc_check_fn_rc (gfc_expr *a)
1020 if (real_or_complex_check (a, 0) == FAILURE)
1028 gfc_check_fnum (gfc_expr *unit)
1030 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1033 if (scalar_check (unit, 0) == FAILURE)
1040 /* This is used for the g77 one-argument Bessel functions, and the
1044 gfc_check_g77_math1 (gfc_expr *x)
1046 if (scalar_check (x, 0) == FAILURE)
1049 if (type_check (x, 0, BT_REAL) == FAILURE)
1057 gfc_check_huge (gfc_expr *x)
1059 if (int_or_real_check (x, 0) == FAILURE)
1066 /* Check that the single argument is an integer. */
1069 gfc_check_i (gfc_expr *i)
1071 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1079 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1081 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1084 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1087 if (i->ts.kind != j->ts.kind)
1089 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1090 &i->where) == FAILURE)
1099 gfc_check_ibclr (gfc_expr *i, gfc_expr *pos)
1101 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1104 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1112 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1114 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1117 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1120 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1128 gfc_check_ibset (gfc_expr *i, gfc_expr *pos)
1130 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1133 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1141 gfc_check_ichar_iachar (gfc_expr *c)
1145 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1148 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1154 /* Substring references don't have the charlength set. */
1156 while (ref && ref->type != REF_SUBSTRING)
1159 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1163 /* Check that the argument is length one. Non-constant lengths
1164 can't be checked here, so assume they are ok. */
1165 if (c->ts.cl && c->ts.cl->length)
1167 /* If we already have a length for this expression then use it. */
1168 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
1170 i = mpz_get_si (c->ts.cl->length->value.integer);
1177 start = ref->u.ss.start;
1178 end = ref->u.ss.end;
1181 if (end == NULL || end->expr_type != EXPR_CONSTANT
1182 || start->expr_type != EXPR_CONSTANT)
1185 i = mpz_get_si (end->value.integer) + 1
1186 - mpz_get_si (start->value.integer);
1194 gfc_error ("Argument of %s at %L must be of length one",
1195 gfc_current_intrinsic, &c->where);
1204 gfc_check_idnint (gfc_expr *a)
1206 if (double_check (a, 0) == FAILURE)
1214 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1216 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1219 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1222 if (i->ts.kind != j->ts.kind)
1224 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1225 &i->where) == FAILURE)
1234 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back)
1236 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1237 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1241 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1244 if (string->ts.kind != substring->ts.kind)
1246 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1247 "kind as '%s'", gfc_current_intrinsic_arg[1],
1248 gfc_current_intrinsic, &substring->where,
1249 gfc_current_intrinsic_arg[0]);
1258 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1260 if (numeric_check (x, 0) == FAILURE)
1265 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
1268 if (scalar_check (kind, 1) == FAILURE)
1277 gfc_check_intconv (gfc_expr *x)
1279 if (numeric_check (x, 0) == FAILURE)
1287 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1289 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1292 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1295 if (i->ts.kind != j->ts.kind)
1297 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1298 &i->where) == FAILURE)
1307 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1309 if (type_check (i, 0, BT_INTEGER) == FAILURE
1310 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1318 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1320 if (type_check (i, 0, BT_INTEGER) == FAILURE
1321 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1324 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1332 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1334 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1337 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1345 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1347 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1350 if (scalar_check (pid, 0) == FAILURE)
1353 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1356 if (scalar_check (sig, 1) == FAILURE)
1362 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1365 if (scalar_check (status, 2) == FAILURE)
1373 gfc_check_kind (gfc_expr *x)
1375 if (x->ts.type == BT_DERIVED)
1377 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1378 "non-derived type", gfc_current_intrinsic_arg[0],
1379 gfc_current_intrinsic, &x->where);
1388 gfc_check_lbound (gfc_expr *array, gfc_expr *dim)
1390 if (array_check (array, 0) == FAILURE)
1395 if (dim_check (dim, 1, 1) == FAILURE)
1398 if (dim_rank_check (dim, array, 1) == FAILURE)
1406 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
1408 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1411 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1419 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1421 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1424 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1430 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1433 if (scalar_check (status, 2) == FAILURE)
1441 gfc_check_loc (gfc_expr *expr)
1443 return variable_check (expr, 0);
1448 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
1450 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1453 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1461 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1463 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1466 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1472 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1475 if (scalar_check (status, 2) == FAILURE)
1483 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
1485 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1487 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1494 /* Min/max family. */
1497 min_max_args (gfc_actual_arglist *arg)
1499 if (arg == NULL || arg->next == NULL)
1501 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1502 gfc_current_intrinsic, gfc_current_intrinsic_where);
1511 check_rest (bt type, int kind, gfc_actual_arglist *arg)
1516 if (min_max_args (arg) == FAILURE)
1521 for (; arg; arg = arg->next, n++)
1524 if (x->ts.type != type || x->ts.kind != kind)
1526 if (x->ts.type == type)
1528 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
1529 "kinds at %L", &x->where) == FAILURE)
1534 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1535 "%s(%d)", n, gfc_current_intrinsic, &x->where,
1536 gfc_basic_typename (type), kind);
1547 gfc_check_min_max (gfc_actual_arglist *arg)
1551 if (min_max_args (arg) == FAILURE)
1556 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1558 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER "
1559 "or REAL", gfc_current_intrinsic, &x->where);
1563 return check_rest (x->ts.type, x->ts.kind, arg);
1568 gfc_check_min_max_integer (gfc_actual_arglist *arg)
1570 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1575 gfc_check_min_max_real (gfc_actual_arglist *arg)
1577 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1582 gfc_check_min_max_double (gfc_actual_arglist *arg)
1584 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1588 /* End of min/max family. */
1591 gfc_check_malloc (gfc_expr *size)
1593 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1596 if (scalar_check (size, 0) == FAILURE)
1604 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
1606 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1608 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1609 "or LOGICAL", gfc_current_intrinsic_arg[0],
1610 gfc_current_intrinsic, &matrix_a->where);
1614 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1616 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1617 "or LOGICAL", gfc_current_intrinsic_arg[1],
1618 gfc_current_intrinsic, &matrix_b->where);
1622 switch (matrix_a->rank)
1625 if (rank_check (matrix_b, 1, 2) == FAILURE)
1627 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
1628 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
1630 gfc_error ("different shape on dimension 1 for arguments '%s' "
1631 "and '%s' at %L for intrinsic matmul",
1632 gfc_current_intrinsic_arg[0],
1633 gfc_current_intrinsic_arg[1], &matrix_a->where);
1639 if (matrix_b->rank != 2)
1641 if (rank_check (matrix_b, 1, 1) == FAILURE)
1644 /* matrix_b has rank 1 or 2 here. Common check for the cases
1645 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
1646 - matrix_a has shape (n,m) and matrix_b has shape (m). */
1647 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
1649 gfc_error ("different shape on dimension 2 for argument '%s' and "
1650 "dimension 1 for argument '%s' at %L for intrinsic "
1651 "matmul", gfc_current_intrinsic_arg[0],
1652 gfc_current_intrinsic_arg[1], &matrix_a->where);
1658 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1659 "1 or 2", gfc_current_intrinsic_arg[0],
1660 gfc_current_intrinsic, &matrix_a->where);
1665 return non_init_transformational ();
1671 /* Whoever came up with this interface was probably on something.
1672 The possibilities for the occupation of the second and third
1679 NULL MASK minloc(array, mask=m)
1682 I.e. in the case of minloc(array,mask), mask will be in the second
1683 position of the argument list and we'll have to fix that up. */
1686 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
1688 gfc_expr *a, *m, *d;
1691 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
1695 m = ap->next->next->expr;
1697 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1698 && ap->next->name == NULL)
1702 ap->next->expr = NULL;
1703 ap->next->next->expr = m;
1706 if (dim_check (d, 1, 1) == FAILURE)
1709 if (d && dim_rank_check (d, a, 0) == FAILURE)
1712 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1718 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1719 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1720 gfc_current_intrinsic);
1721 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1726 return non_init_transformational ();
1732 /* Similar to minloc/maxloc, the argument list might need to be
1733 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1734 difference is that MINLOC/MAXLOC take an additional KIND argument.
1735 The possibilities are:
1741 NULL MASK minval(array, mask=m)
1744 I.e. in the case of minval(array,mask), mask will be in the second
1745 position of the argument list and we'll have to fix that up. */
1748 check_reduction (gfc_actual_arglist *ap)
1750 gfc_expr *a, *m, *d;
1754 m = ap->next->next->expr;
1756 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1757 && ap->next->name == NULL)
1761 ap->next->expr = NULL;
1762 ap->next->next->expr = m;
1765 if (dim_check (d, 1, 1) == FAILURE)
1768 if (d && dim_rank_check (d, a, 0) == FAILURE)
1771 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1777 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1778 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1779 gfc_current_intrinsic);
1780 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1789 gfc_check_minval_maxval (gfc_actual_arglist *ap)
1791 if (int_or_real_check (ap->expr, 0) == FAILURE
1792 || array_check (ap->expr, 0) == FAILURE)
1796 return non_init_transformational ();
1798 return check_reduction (ap);
1803 gfc_check_product_sum (gfc_actual_arglist *ap)
1805 if (numeric_check (ap->expr, 0) == FAILURE
1806 || array_check (ap->expr, 0) == FAILURE)
1810 return non_init_transformational ();
1812 return check_reduction (ap);
1817 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
1821 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
1824 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
1827 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1828 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1829 gfc_current_intrinsic);
1830 if (gfc_check_conformance (buffer, tsource, fsource) == FAILURE)
1833 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1834 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1835 gfc_current_intrinsic);
1836 if (gfc_check_conformance (buffer, tsource, mask) == FAILURE)
1843 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
1845 symbol_attribute attr;
1847 if (variable_check (from, 0) == FAILURE)
1850 if (array_check (from, 0) == FAILURE)
1853 attr = gfc_variable_attr (from, NULL);
1854 if (!attr.allocatable)
1856 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1857 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1862 if (variable_check (to, 0) == FAILURE)
1865 if (array_check (to, 0) == FAILURE)
1868 attr = gfc_variable_attr (to, NULL);
1869 if (!attr.allocatable)
1871 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1872 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1877 if (same_type_check (from, 0, to, 1) == FAILURE)
1880 if (to->rank != from->rank)
1882 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1883 "have the same rank %d/%d", gfc_current_intrinsic_arg[0],
1884 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1885 &to->where, from->rank, to->rank);
1889 if (to->ts.kind != from->ts.kind)
1891 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1892 "be of the same kind %d/%d", gfc_current_intrinsic_arg[0],
1893 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1894 &to->where, from->ts.kind, to->ts.kind);
1903 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
1905 if (type_check (x, 0, BT_REAL) == FAILURE)
1908 if (type_check (s, 1, BT_REAL) == FAILURE)
1916 gfc_check_new_line (gfc_expr *a)
1918 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1926 gfc_check_null (gfc_expr *mold)
1928 symbol_attribute attr;
1933 if (variable_check (mold, 0) == FAILURE)
1936 attr = gfc_variable_attr (mold, NULL);
1940 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
1941 gfc_current_intrinsic_arg[0],
1942 gfc_current_intrinsic, &mold->where);
1951 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
1955 if (array_check (array, 0) == FAILURE)
1958 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1961 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1962 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1963 gfc_current_intrinsic);
1964 if (gfc_check_conformance (buffer, array, mask) == FAILURE)
1969 if (same_type_check (array, 0, vector, 2) == FAILURE)
1972 if (rank_check (vector, 2, 1) == FAILURE)
1975 /* TODO: More constraints here. */
1979 return non_init_transformational ();
1986 gfc_check_precision (gfc_expr *x)
1988 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
1990 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
1991 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
1992 gfc_current_intrinsic, &x->where);
2001 gfc_check_present (gfc_expr *a)
2005 if (variable_check (a, 0) == FAILURE)
2008 sym = a->symtree->n.sym;
2009 if (!sym->attr.dummy)
2011 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2012 "dummy variable", gfc_current_intrinsic_arg[0],
2013 gfc_current_intrinsic, &a->where);
2017 if (!sym->attr.optional)
2019 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2020 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
2021 gfc_current_intrinsic, &a->where);
2025 /* 13.14.82 PRESENT(A)
2027 Argument. A shall be the name of an optional dummy argument that is
2028 accessible in the subprogram in which the PRESENT function reference
2032 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2033 && a->ref->u.ar.type == AR_FULL))
2035 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2036 "subobject of '%s'", gfc_current_intrinsic_arg[0],
2037 gfc_current_intrinsic, &a->where, sym->name);
2046 gfc_check_radix (gfc_expr *x)
2048 if (int_or_real_check (x, 0) == FAILURE)
2056 gfc_check_range (gfc_expr *x)
2058 if (numeric_check (x, 0) == FAILURE)
2065 /* real, float, sngl. */
2067 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2069 if (numeric_check (a, 0) == FAILURE)
2072 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2080 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2082 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2085 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2093 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2095 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2098 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2104 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2107 if (scalar_check (status, 2) == FAILURE)
2115 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2117 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2120 if (scalar_check (x, 0) == FAILURE)
2123 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2126 if (scalar_check (y, 1) == FAILURE)
2134 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2135 gfc_expr *pad, gfc_expr *order)
2141 if (array_check (source, 0) == FAILURE)
2144 if (rank_check (shape, 1, 1) == FAILURE)
2147 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2150 if (gfc_array_size (shape, &size) != SUCCESS)
2152 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2153 "array of constant size", &shape->where);
2157 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
2162 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2163 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2169 if (same_type_check (source, 0, pad, 2) == FAILURE)
2171 if (array_check (pad, 2) == FAILURE)
2175 if (order != NULL && array_check (order, 3) == FAILURE)
2178 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2179 && gfc_is_constant_expr (shape)
2180 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2181 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2183 /* Check the match in size between source and destination. */
2184 if (gfc_array_size (source, &nelems) == SUCCESS)
2189 c = shape->value.constructor;
2190 mpz_init_set_ui (size, 1);
2191 for (; c; c = c->next)
2192 mpz_mul (size, size, c->expr->value.integer);
2194 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2200 gfc_error ("Without padding, there are not enough elements "
2201 "in the intrinsic RESHAPE source at %L to match "
2202 "the shape", &source->where);
2213 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2215 if (type_check (x, 0, BT_REAL) == FAILURE)
2218 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2226 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2228 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2231 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2234 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2237 if (same_type_check (x, 0, y, 1) == FAILURE)
2245 gfc_check_secnds (gfc_expr *r)
2247 if (type_check (r, 0, BT_REAL) == FAILURE)
2250 if (kind_value_check (r, 0, 4) == FAILURE)
2253 if (scalar_check (r, 0) == FAILURE)
2261 gfc_check_selected_int_kind (gfc_expr *r)
2263 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2266 if (scalar_check (r, 0) == FAILURE)
2274 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r)
2276 if (p == NULL && r == NULL)
2278 gfc_error ("Missing arguments to %s intrinsic at %L",
2279 gfc_current_intrinsic, gfc_current_intrinsic_where);
2284 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
2287 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
2295 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
2297 if (type_check (x, 0, BT_REAL) == FAILURE)
2300 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2308 gfc_check_shape (gfc_expr *source)
2312 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2315 ar = gfc_find_array_ref (source);
2317 if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
2319 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2320 "an assumed size array", &source->where);
2329 gfc_check_sign (gfc_expr *a, gfc_expr *b)
2331 if (int_or_real_check (a, 0) == FAILURE)
2334 if (same_type_check (a, 0, b, 1) == FAILURE)
2342 gfc_check_size (gfc_expr *array, gfc_expr *dim)
2344 if (array_check (array, 0) == FAILURE)
2349 if (type_check (dim, 1, BT_INTEGER) == FAILURE)
2352 if (kind_value_check (dim, 1, gfc_default_integer_kind) == FAILURE)
2355 if (dim_rank_check (dim, array, 0) == FAILURE)
2364 gfc_check_sleep_sub (gfc_expr *seconds)
2366 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2369 if (scalar_check (seconds, 0) == FAILURE)
2377 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
2379 if (source->rank >= GFC_MAX_DIMENSIONS)
2381 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2382 "than rank %d", gfc_current_intrinsic_arg[0],
2383 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2388 if (dim_check (dim, 1, 0) == FAILURE)
2391 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2394 if (scalar_check (ncopies, 2) == FAILURE)
2398 return non_init_transformational ();
2404 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2408 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
2410 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2413 if (scalar_check (unit, 0) == FAILURE)
2416 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2422 if (type_check (status, 2, BT_INTEGER) == FAILURE
2423 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2424 || scalar_check (status, 2) == FAILURE)
2432 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
2434 return gfc_check_fgetputc_sub (unit, c, NULL);
2439 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
2441 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2447 if (type_check (status, 1, BT_INTEGER) == FAILURE
2448 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2449 || scalar_check (status, 1) == FAILURE)
2457 gfc_check_fgetput (gfc_expr *c)
2459 return gfc_check_fgetput_sub (c, NULL);
2464 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
2466 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2469 if (scalar_check (unit, 0) == FAILURE)
2472 if (type_check (array, 1, BT_INTEGER) == FAILURE
2473 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2476 if (array_check (array, 1) == FAILURE)
2484 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
2486 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2489 if (scalar_check (unit, 0) == FAILURE)
2492 if (type_check (array, 1, BT_INTEGER) == FAILURE
2493 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2496 if (array_check (array, 1) == FAILURE)
2502 if (type_check (status, 2, BT_INTEGER) == FAILURE
2503 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2506 if (scalar_check (status, 2) == FAILURE)
2514 gfc_check_ftell (gfc_expr *unit)
2516 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2519 if (scalar_check (unit, 0) == FAILURE)
2527 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
2529 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2532 if (scalar_check (unit, 0) == FAILURE)
2535 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2538 if (scalar_check (offset, 1) == FAILURE)
2546 gfc_check_stat (gfc_expr *name, gfc_expr *array)
2548 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2551 if (type_check (array, 1, BT_INTEGER) == FAILURE
2552 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2555 if (array_check (array, 1) == FAILURE)
2563 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
2565 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2568 if (type_check (array, 1, BT_INTEGER) == FAILURE
2569 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2572 if (array_check (array, 1) == FAILURE)
2578 if (type_check (status, 2, BT_INTEGER) == FAILURE
2579 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2582 if (scalar_check (status, 2) == FAILURE)
2590 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
2591 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
2595 if (type_check (size, 2, BT_INTEGER) == FAILURE)
2598 if (scalar_check (size, 2) == FAILURE)
2601 if (nonoptional_check (size, 2) == FAILURE)
2610 gfc_check_transpose (gfc_expr *matrix)
2612 if (rank_check (matrix, 0, 2) == FAILURE)
2616 return non_init_transformational ();
2623 gfc_check_ubound (gfc_expr *array, gfc_expr *dim)
2625 if (array_check (array, 0) == FAILURE)
2630 if (dim_check (dim, 1, 1) == FAILURE)
2633 if (dim_rank_check (dim, array, 0) == FAILURE)
2642 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
2644 if (rank_check (vector, 0, 1) == FAILURE)
2647 if (array_check (mask, 1) == FAILURE)
2650 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2653 if (same_type_check (vector, 0, field, 2) == FAILURE)
2657 return non_init_transformational ();
2664 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2666 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2669 if (same_type_check (x, 0, y, 1) == FAILURE)
2672 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2680 gfc_check_trim (gfc_expr *x)
2682 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2685 if (scalar_check (x, 0) == FAILURE)
2693 gfc_check_ttynam (gfc_expr *unit)
2695 if (scalar_check (unit, 0) == FAILURE)
2698 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2705 /* Common check function for the half a dozen intrinsics that have a
2706 single real argument. */
2709 gfc_check_x (gfc_expr *x)
2711 if (type_check (x, 0, BT_REAL) == FAILURE)
2718 /************* Check functions for intrinsic subroutines *************/
2721 gfc_check_cpu_time (gfc_expr *time)
2723 if (scalar_check (time, 0) == FAILURE)
2726 if (type_check (time, 0, BT_REAL) == FAILURE)
2729 if (variable_check (time, 0) == FAILURE)
2737 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
2738 gfc_expr *zone, gfc_expr *values)
2742 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2744 if (scalar_check (date, 0) == FAILURE)
2746 if (variable_check (date, 0) == FAILURE)
2752 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
2754 if (scalar_check (time, 1) == FAILURE)
2756 if (variable_check (time, 1) == FAILURE)
2762 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
2764 if (scalar_check (zone, 2) == FAILURE)
2766 if (variable_check (zone, 2) == FAILURE)
2772 if (type_check (values, 3, BT_INTEGER) == FAILURE)
2774 if (array_check (values, 3) == FAILURE)
2776 if (rank_check (values, 3, 1) == FAILURE)
2778 if (variable_check (values, 3) == FAILURE)
2787 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
2788 gfc_expr *to, gfc_expr *topos)
2790 if (type_check (from, 0, BT_INTEGER) == FAILURE)
2793 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
2796 if (type_check (len, 2, BT_INTEGER) == FAILURE)
2799 if (same_type_check (from, 0, to, 3) == FAILURE)
2802 if (variable_check (to, 3) == FAILURE)
2805 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
2813 gfc_check_random_number (gfc_expr *harvest)
2815 if (type_check (harvest, 0, BT_REAL) == FAILURE)
2818 if (variable_check (harvest, 0) == FAILURE)
2826 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
2830 if (scalar_check (size, 0) == FAILURE)
2833 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2836 if (variable_check (size, 0) == FAILURE)
2839 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
2847 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2850 if (array_check (put, 1) == FAILURE)
2853 if (rank_check (put, 1, 1) == FAILURE)
2856 if (type_check (put, 1, BT_INTEGER) == FAILURE)
2859 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
2866 if (size != NULL || put != NULL)
2867 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2870 if (array_check (get, 2) == FAILURE)
2873 if (rank_check (get, 2, 1) == FAILURE)
2876 if (type_check (get, 2, BT_INTEGER) == FAILURE)
2879 if (variable_check (get, 2) == FAILURE)
2882 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
2891 gfc_check_second_sub (gfc_expr *time)
2893 if (scalar_check (time, 0) == FAILURE)
2896 if (type_check (time, 0, BT_REAL) == FAILURE)
2899 if (kind_value_check(time, 0, 4) == FAILURE)
2906 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2907 count, count_rate, and count_max are all optional arguments */
2910 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
2911 gfc_expr *count_max)
2915 if (scalar_check (count, 0) == FAILURE)
2918 if (type_check (count, 0, BT_INTEGER) == FAILURE)
2921 if (variable_check (count, 0) == FAILURE)
2925 if (count_rate != NULL)
2927 if (scalar_check (count_rate, 1) == FAILURE)
2930 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
2933 if (variable_check (count_rate, 1) == FAILURE)
2937 && same_type_check (count, 0, count_rate, 1) == FAILURE)
2942 if (count_max != NULL)
2944 if (scalar_check (count_max, 2) == FAILURE)
2947 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
2950 if (variable_check (count_max, 2) == FAILURE)
2954 && same_type_check (count, 0, count_max, 2) == FAILURE)
2957 if (count_rate != NULL
2958 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
2967 gfc_check_irand (gfc_expr *x)
2972 if (scalar_check (x, 0) == FAILURE)
2975 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2978 if (kind_value_check(x, 0, 4) == FAILURE)
2986 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
2988 if (scalar_check (seconds, 0) == FAILURE)
2991 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2994 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
2996 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
2997 "or PROCEDURE", gfc_current_intrinsic_arg[1],
2998 gfc_current_intrinsic, &handler->where);
3002 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3008 if (scalar_check (status, 2) == FAILURE)
3011 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3014 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3022 gfc_check_rand (gfc_expr *x)
3027 if (scalar_check (x, 0) == FAILURE)
3030 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3033 if (kind_value_check(x, 0, 4) == FAILURE)
3041 gfc_check_srand (gfc_expr *x)
3043 if (scalar_check (x, 0) == FAILURE)
3046 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3049 if (kind_value_check(x, 0, 4) == FAILURE)
3057 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
3059 if (scalar_check (time, 0) == FAILURE)
3062 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3065 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
3073 gfc_check_etime (gfc_expr *x)
3075 if (array_check (x, 0) == FAILURE)
3078 if (rank_check (x, 0, 1) == FAILURE)
3081 if (variable_check (x, 0) == FAILURE)
3084 if (type_check (x, 0, BT_REAL) == FAILURE)
3087 if (kind_value_check(x, 0, 4) == FAILURE)
3095 gfc_check_etime_sub (gfc_expr *values, gfc_expr *time)
3097 if (array_check (values, 0) == FAILURE)
3100 if (rank_check (values, 0, 1) == FAILURE)
3103 if (variable_check (values, 0) == FAILURE)
3106 if (type_check (values, 0, BT_REAL) == FAILURE)
3109 if (kind_value_check(values, 0, 4) == FAILURE)
3112 if (scalar_check (time, 1) == FAILURE)
3115 if (type_check (time, 1, BT_REAL) == FAILURE)
3118 if (kind_value_check(time, 1, 4) == FAILURE)
3126 gfc_check_fdate_sub (gfc_expr *date)
3128 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3136 gfc_check_gerror (gfc_expr *msg)
3138 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3146 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
3148 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
3154 if (scalar_check (status, 1) == FAILURE)
3157 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3165 gfc_check_getlog (gfc_expr *msg)
3167 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3175 gfc_check_exit (gfc_expr *status)
3180 if (type_check (status, 0, BT_INTEGER) == FAILURE)
3183 if (scalar_check (status, 0) == FAILURE)
3191 gfc_check_flush (gfc_expr *unit)
3196 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3199 if (scalar_check (unit, 0) == FAILURE)
3207 gfc_check_free (gfc_expr *i)
3209 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3212 if (scalar_check (i, 0) == FAILURE)
3220 gfc_check_hostnm (gfc_expr *name)
3222 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3230 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
3232 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3238 if (scalar_check (status, 1) == FAILURE)
3241 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3249 gfc_check_itime_idate (gfc_expr *values)
3251 if (array_check (values, 0) == FAILURE)
3254 if (rank_check (values, 0, 1) == FAILURE)
3257 if (variable_check (values, 0) == FAILURE)
3260 if (type_check (values, 0, BT_INTEGER) == FAILURE)
3263 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
3271 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
3273 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3276 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
3279 if (scalar_check (time, 0) == FAILURE)
3282 if (array_check (values, 1) == FAILURE)
3285 if (rank_check (values, 1, 1) == FAILURE)
3288 if (variable_check (values, 1) == FAILURE)
3291 if (type_check (values, 1, BT_INTEGER) == FAILURE)
3294 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
3302 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
3304 if (scalar_check (unit, 0) == FAILURE)
3307 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3310 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
3318 gfc_check_isatty (gfc_expr *unit)
3323 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3326 if (scalar_check (unit, 0) == FAILURE)
3334 gfc_check_perror (gfc_expr *string)
3336 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
3344 gfc_check_umask (gfc_expr *mask)
3346 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3349 if (scalar_check (mask, 0) == FAILURE)
3357 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
3359 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3362 if (scalar_check (mask, 0) == FAILURE)
3368 if (scalar_check (old, 1) == FAILURE)
3371 if (type_check (old, 1, BT_INTEGER) == FAILURE)
3379 gfc_check_unlink (gfc_expr *name)
3381 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3389 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
3391 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3397 if (scalar_check (status, 1) == FAILURE)
3400 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3408 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
3410 if (scalar_check (number, 0) == FAILURE)
3413 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3416 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3418 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3419 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3420 gfc_current_intrinsic, &handler->where);
3424 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3432 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
3434 if (scalar_check (number, 0) == FAILURE)
3437 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3440 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3442 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3443 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3444 gfc_current_intrinsic, &handler->where);
3448 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3454 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3457 if (scalar_check (status, 2) == FAILURE)
3465 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
3467 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
3470 if (scalar_check (status, 1) == FAILURE)
3473 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3476 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
3483 /* This is used for the GNU intrinsics AND, OR and XOR. */
3485 gfc_check_and (gfc_expr *i, gfc_expr *j)
3487 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
3489 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3490 "or LOGICAL", gfc_current_intrinsic_arg[0],
3491 gfc_current_intrinsic, &i->where);
3495 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
3497 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3498 "or LOGICAL", gfc_current_intrinsic_arg[1],
3499 gfc_current_intrinsic, &j->where);
3503 if (i->ts.type != j->ts.type)
3505 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
3506 "have the same type", gfc_current_intrinsic_arg[0],
3507 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3512 if (scalar_check (i, 0) == FAILURE)
3515 if (scalar_check (j, 1) == FAILURE)