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 (type_check (x, 1, BT_REAL) == FAILURE)
666 gfc_check_btest (gfc_expr *i, gfc_expr *pos)
668 if (type_check (i, 0, BT_INTEGER) == FAILURE)
670 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
678 gfc_check_char (gfc_expr *i, gfc_expr *kind)
680 if (type_check (i, 0, BT_INTEGER) == FAILURE)
682 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
690 gfc_check_chdir (gfc_expr *dir)
692 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
700 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
702 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
708 if (type_check (status, 1, BT_INTEGER) == FAILURE)
711 if (scalar_check (status, 1) == FAILURE)
719 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
721 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
724 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
732 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
734 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
737 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
743 if (type_check (status, 2, BT_INTEGER) == FAILURE)
746 if (scalar_check (status, 2) == FAILURE)
754 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
756 if (numeric_check (x, 0) == FAILURE)
761 if (numeric_check (y, 1) == FAILURE)
764 if (x->ts.type == BT_COMPLEX)
766 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
767 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
768 gfc_current_intrinsic, &y->where);
773 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
781 gfc_check_complex (gfc_expr *x, gfc_expr *y)
783 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
785 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
786 "or REAL", gfc_current_intrinsic_arg[0],
787 gfc_current_intrinsic, &x->where);
790 if (scalar_check (x, 0) == FAILURE)
793 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
795 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
796 "or REAL", gfc_current_intrinsic_arg[1],
797 gfc_current_intrinsic, &y->where);
800 if (scalar_check (y, 1) == FAILURE)
808 gfc_check_count (gfc_expr *mask, gfc_expr *dim)
810 if (logical_array_check (mask, 0) == FAILURE)
812 if (dim_check (dim, 1, 1) == FAILURE)
816 return non_init_transformational ();
823 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
825 if (array_check (array, 0) == FAILURE)
828 if (array->rank == 1)
830 if (scalar_check (shift, 1) == FAILURE)
835 /* TODO: more requirements on shift parameter. */
838 if (dim_check (dim, 2, 1) == FAILURE)
842 return non_init_transformational ();
849 gfc_check_ctime (gfc_expr *time)
851 if (scalar_check (time, 0) == FAILURE)
854 if (type_check (time, 0, BT_INTEGER) == FAILURE)
862 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
864 if (numeric_check (x, 0) == FAILURE)
869 if (numeric_check (y, 1) == FAILURE)
872 if (x->ts.type == BT_COMPLEX)
874 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
875 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
876 gfc_current_intrinsic, &y->where);
886 gfc_check_dble (gfc_expr *x)
888 if (numeric_check (x, 0) == FAILURE)
896 gfc_check_digits (gfc_expr *x)
898 if (int_or_real_check (x, 0) == FAILURE)
906 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
908 switch (vector_a->ts.type)
911 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
918 if (numeric_check (vector_b, 1) == FAILURE)
923 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
924 "or LOGICAL", gfc_current_intrinsic_arg[0],
925 gfc_current_intrinsic, &vector_a->where);
929 if (rank_check (vector_a, 0, 1) == FAILURE)
932 if (rank_check (vector_b, 1, 1) == FAILURE)
935 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
937 gfc_error ("different shape for arguments '%s' and '%s' at %L for "
938 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0],
939 gfc_current_intrinsic_arg[1], &vector_a->where);
944 return non_init_transformational ();
951 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
954 if (array_check (array, 0) == FAILURE)
957 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
960 if (array->rank == 1)
962 if (scalar_check (shift, 2) == FAILURE)
967 /* TODO: more weird restrictions on shift. */
970 if (boundary != NULL)
972 if (same_type_check (array, 0, boundary, 2) == FAILURE)
975 /* TODO: more restrictions on boundary. */
978 if (dim_check (dim, 1, 1) == FAILURE)
982 return non_init_transformational ();
988 /* A single complex argument. */
991 gfc_check_fn_c (gfc_expr *a)
993 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
1000 /* A single real argument. */
1003 gfc_check_fn_r (gfc_expr *a)
1005 if (type_check (a, 0, BT_REAL) == FAILURE)
1012 /* A single real or complex argument. */
1015 gfc_check_fn_rc (gfc_expr *a)
1017 if (real_or_complex_check (a, 0) == FAILURE)
1025 gfc_check_fnum (gfc_expr *unit)
1027 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1030 if (scalar_check (unit, 0) == FAILURE)
1038 gfc_check_huge (gfc_expr *x)
1040 if (int_or_real_check (x, 0) == FAILURE)
1047 /* Check that the single argument is an integer. */
1050 gfc_check_i (gfc_expr *i)
1052 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1060 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1062 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1065 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1068 if (i->ts.kind != j->ts.kind)
1070 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1071 &i->where) == FAILURE)
1080 gfc_check_ibclr (gfc_expr *i, gfc_expr *pos)
1082 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1085 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1093 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1095 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1098 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1101 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1109 gfc_check_ibset (gfc_expr *i, gfc_expr *pos)
1111 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1114 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1122 gfc_check_ichar_iachar (gfc_expr *c)
1126 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1129 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1135 /* Substring references don't have the charlength set. */
1137 while (ref && ref->type != REF_SUBSTRING)
1140 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1144 /* Check that the argument is length one. Non-constant lengths
1145 can't be checked here, so assume they are ok. */
1146 if (c->ts.cl && c->ts.cl->length)
1148 /* If we already have a length for this expression then use it. */
1149 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
1151 i = mpz_get_si (c->ts.cl->length->value.integer);
1158 start = ref->u.ss.start;
1159 end = ref->u.ss.end;
1162 if (end == NULL || end->expr_type != EXPR_CONSTANT
1163 || start->expr_type != EXPR_CONSTANT)
1166 i = mpz_get_si (end->value.integer) + 1
1167 - mpz_get_si (start->value.integer);
1175 gfc_error ("Argument of %s at %L must be of length one",
1176 gfc_current_intrinsic, &c->where);
1185 gfc_check_idnint (gfc_expr *a)
1187 if (double_check (a, 0) == FAILURE)
1195 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1197 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1200 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1203 if (i->ts.kind != j->ts.kind)
1205 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1206 &i->where) == FAILURE)
1215 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back)
1217 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1218 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1222 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1225 if (string->ts.kind != substring->ts.kind)
1227 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1228 "kind as '%s'", gfc_current_intrinsic_arg[1],
1229 gfc_current_intrinsic, &substring->where,
1230 gfc_current_intrinsic_arg[0]);
1239 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1241 if (numeric_check (x, 0) == FAILURE)
1246 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
1249 if (scalar_check (kind, 1) == FAILURE)
1258 gfc_check_intconv (gfc_expr *x)
1260 if (numeric_check (x, 0) == FAILURE)
1268 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1270 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1273 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1276 if (i->ts.kind != j->ts.kind)
1278 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1279 &i->where) == FAILURE)
1288 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1290 if (type_check (i, 0, BT_INTEGER) == FAILURE
1291 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1299 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1301 if (type_check (i, 0, BT_INTEGER) == FAILURE
1302 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1305 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1313 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1315 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1318 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1326 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1328 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1331 if (scalar_check (pid, 0) == FAILURE)
1334 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1337 if (scalar_check (sig, 1) == FAILURE)
1343 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1346 if (scalar_check (status, 2) == FAILURE)
1354 gfc_check_kind (gfc_expr *x)
1356 if (x->ts.type == BT_DERIVED)
1358 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1359 "non-derived type", gfc_current_intrinsic_arg[0],
1360 gfc_current_intrinsic, &x->where);
1369 gfc_check_lbound (gfc_expr *array, gfc_expr *dim)
1371 if (array_check (array, 0) == FAILURE)
1376 if (dim_check (dim, 1, 1) == FAILURE)
1379 if (dim_rank_check (dim, array, 1) == FAILURE)
1387 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
1389 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1392 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1400 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1402 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1405 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1411 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1414 if (scalar_check (status, 2) == FAILURE)
1422 gfc_check_loc (gfc_expr *expr)
1424 return variable_check (expr, 0);
1429 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
1431 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1434 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1442 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1444 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1447 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1453 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1456 if (scalar_check (status, 2) == FAILURE)
1464 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
1466 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1468 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1475 /* Min/max family. */
1478 min_max_args (gfc_actual_arglist *arg)
1480 if (arg == NULL || arg->next == NULL)
1482 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1483 gfc_current_intrinsic, gfc_current_intrinsic_where);
1492 check_rest (bt type, int kind, gfc_actual_arglist *arg)
1497 if (min_max_args (arg) == FAILURE)
1502 for (; arg; arg = arg->next, n++)
1505 if (x->ts.type != type || x->ts.kind != kind)
1507 if (x->ts.type == type)
1509 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
1510 "kinds at %L", &x->where) == FAILURE)
1515 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1516 "%s(%d)", n, gfc_current_intrinsic, &x->where,
1517 gfc_basic_typename (type), kind);
1528 gfc_check_min_max (gfc_actual_arglist *arg)
1532 if (min_max_args (arg) == FAILURE)
1537 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1539 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER "
1540 "or REAL", gfc_current_intrinsic, &x->where);
1544 return check_rest (x->ts.type, x->ts.kind, arg);
1549 gfc_check_min_max_integer (gfc_actual_arglist *arg)
1551 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1556 gfc_check_min_max_real (gfc_actual_arglist *arg)
1558 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1563 gfc_check_min_max_double (gfc_actual_arglist *arg)
1565 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1569 /* End of min/max family. */
1572 gfc_check_malloc (gfc_expr *size)
1574 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1577 if (scalar_check (size, 0) == FAILURE)
1585 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
1587 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1589 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1590 "or LOGICAL", gfc_current_intrinsic_arg[0],
1591 gfc_current_intrinsic, &matrix_a->where);
1595 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1597 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1598 "or LOGICAL", gfc_current_intrinsic_arg[1],
1599 gfc_current_intrinsic, &matrix_b->where);
1603 switch (matrix_a->rank)
1606 if (rank_check (matrix_b, 1, 2) == FAILURE)
1608 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
1609 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
1611 gfc_error ("different shape on dimension 1 for arguments '%s' "
1612 "and '%s' at %L for intrinsic matmul",
1613 gfc_current_intrinsic_arg[0],
1614 gfc_current_intrinsic_arg[1], &matrix_a->where);
1620 if (matrix_b->rank != 2)
1622 if (rank_check (matrix_b, 1, 1) == FAILURE)
1625 /* matrix_b has rank 1 or 2 here. Common check for the cases
1626 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
1627 - matrix_a has shape (n,m) and matrix_b has shape (m). */
1628 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
1630 gfc_error ("different shape on dimension 2 for argument '%s' and "
1631 "dimension 1 for argument '%s' at %L for intrinsic "
1632 "matmul", gfc_current_intrinsic_arg[0],
1633 gfc_current_intrinsic_arg[1], &matrix_a->where);
1639 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1640 "1 or 2", gfc_current_intrinsic_arg[0],
1641 gfc_current_intrinsic, &matrix_a->where);
1646 return non_init_transformational ();
1652 /* Whoever came up with this interface was probably on something.
1653 The possibilities for the occupation of the second and third
1660 NULL MASK minloc(array, mask=m)
1663 I.e. in the case of minloc(array,mask), mask will be in the second
1664 position of the argument list and we'll have to fix that up. */
1667 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
1669 gfc_expr *a, *m, *d;
1672 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
1676 m = ap->next->next->expr;
1678 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1679 && ap->next->name == NULL)
1683 ap->next->expr = NULL;
1684 ap->next->next->expr = m;
1687 if (dim_check (d, 1, 1) == FAILURE)
1690 if (d && dim_rank_check (d, a, 0) == FAILURE)
1693 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1699 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1700 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1701 gfc_current_intrinsic);
1702 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1707 return non_init_transformational ();
1713 /* Similar to minloc/maxloc, the argument list might need to be
1714 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1715 difference is that MINLOC/MAXLOC take an additional KIND argument.
1716 The possibilities are:
1722 NULL MASK minval(array, mask=m)
1725 I.e. in the case of minval(array,mask), mask will be in the second
1726 position of the argument list and we'll have to fix that up. */
1729 check_reduction (gfc_actual_arglist *ap)
1731 gfc_expr *a, *m, *d;
1735 m = ap->next->next->expr;
1737 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1738 && ap->next->name == NULL)
1742 ap->next->expr = NULL;
1743 ap->next->next->expr = m;
1746 if (dim_check (d, 1, 1) == FAILURE)
1749 if (d && dim_rank_check (d, a, 0) == FAILURE)
1752 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1758 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1759 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1760 gfc_current_intrinsic);
1761 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1770 gfc_check_minval_maxval (gfc_actual_arglist *ap)
1772 if (int_or_real_check (ap->expr, 0) == FAILURE
1773 || array_check (ap->expr, 0) == FAILURE)
1777 return non_init_transformational ();
1779 return check_reduction (ap);
1784 gfc_check_product_sum (gfc_actual_arglist *ap)
1786 if (numeric_check (ap->expr, 0) == FAILURE
1787 || array_check (ap->expr, 0) == FAILURE)
1791 return non_init_transformational ();
1793 return check_reduction (ap);
1798 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
1802 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
1805 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
1808 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1809 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1810 gfc_current_intrinsic);
1811 if (gfc_check_conformance (buffer, tsource, fsource) == FAILURE)
1814 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1815 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1816 gfc_current_intrinsic);
1817 if (gfc_check_conformance (buffer, tsource, mask) == FAILURE)
1824 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
1826 symbol_attribute attr;
1828 if (variable_check (from, 0) == FAILURE)
1831 if (array_check (from, 0) == FAILURE)
1834 attr = gfc_variable_attr (from, NULL);
1835 if (!attr.allocatable)
1837 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1838 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1843 if (variable_check (to, 0) == FAILURE)
1846 if (array_check (to, 0) == FAILURE)
1849 attr = gfc_variable_attr (to, NULL);
1850 if (!attr.allocatable)
1852 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1853 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1858 if (same_type_check (from, 0, to, 1) == FAILURE)
1861 if (to->rank != from->rank)
1863 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1864 "have the same rank %d/%d", gfc_current_intrinsic_arg[0],
1865 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1866 &to->where, from->rank, to->rank);
1870 if (to->ts.kind != from->ts.kind)
1872 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1873 "be of the same kind %d/%d", gfc_current_intrinsic_arg[0],
1874 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1875 &to->where, from->ts.kind, to->ts.kind);
1884 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
1886 if (type_check (x, 0, BT_REAL) == FAILURE)
1889 if (type_check (s, 1, BT_REAL) == FAILURE)
1897 gfc_check_new_line (gfc_expr *a)
1899 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1907 gfc_check_null (gfc_expr *mold)
1909 symbol_attribute attr;
1914 if (variable_check (mold, 0) == FAILURE)
1917 attr = gfc_variable_attr (mold, NULL);
1921 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
1922 gfc_current_intrinsic_arg[0],
1923 gfc_current_intrinsic, &mold->where);
1932 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
1936 if (array_check (array, 0) == FAILURE)
1939 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1942 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1943 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1944 gfc_current_intrinsic);
1945 if (gfc_check_conformance (buffer, array, mask) == FAILURE)
1950 if (same_type_check (array, 0, vector, 2) == FAILURE)
1953 if (rank_check (vector, 2, 1) == FAILURE)
1956 /* TODO: More constraints here. */
1960 return non_init_transformational ();
1967 gfc_check_precision (gfc_expr *x)
1969 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
1971 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
1972 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
1973 gfc_current_intrinsic, &x->where);
1982 gfc_check_present (gfc_expr *a)
1986 if (variable_check (a, 0) == FAILURE)
1989 sym = a->symtree->n.sym;
1990 if (!sym->attr.dummy)
1992 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
1993 "dummy variable", gfc_current_intrinsic_arg[0],
1994 gfc_current_intrinsic, &a->where);
1998 if (!sym->attr.optional)
2000 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2001 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
2002 gfc_current_intrinsic, &a->where);
2006 /* 13.14.82 PRESENT(A)
2008 Argument. A shall be the name of an optional dummy argument that is
2009 accessible in the subprogram in which the PRESENT function reference
2013 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2014 && a->ref->u.ar.type == AR_FULL))
2016 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2017 "subobject of '%s'", gfc_current_intrinsic_arg[0],
2018 gfc_current_intrinsic, &a->where, sym->name);
2027 gfc_check_radix (gfc_expr *x)
2029 if (int_or_real_check (x, 0) == FAILURE)
2037 gfc_check_range (gfc_expr *x)
2039 if (numeric_check (x, 0) == FAILURE)
2046 /* real, float, sngl. */
2048 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2050 if (numeric_check (a, 0) == FAILURE)
2053 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2061 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2063 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2066 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2074 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2076 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2079 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2085 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2088 if (scalar_check (status, 2) == FAILURE)
2096 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2098 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2101 if (scalar_check (x, 0) == FAILURE)
2104 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2107 if (scalar_check (y, 1) == FAILURE)
2115 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2116 gfc_expr *pad, gfc_expr *order)
2122 if (array_check (source, 0) == FAILURE)
2125 if (rank_check (shape, 1, 1) == FAILURE)
2128 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2131 if (gfc_array_size (shape, &size) != SUCCESS)
2133 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2134 "array of constant size", &shape->where);
2138 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
2143 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2144 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2150 if (same_type_check (source, 0, pad, 2) == FAILURE)
2152 if (array_check (pad, 2) == FAILURE)
2156 if (order != NULL && array_check (order, 3) == FAILURE)
2159 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2160 && gfc_is_constant_expr (shape)
2161 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2162 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2164 /* Check the match in size between source and destination. */
2165 if (gfc_array_size (source, &nelems) == SUCCESS)
2170 c = shape->value.constructor;
2171 mpz_init_set_ui (size, 1);
2172 for (; c; c = c->next)
2173 mpz_mul (size, size, c->expr->value.integer);
2175 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2181 gfc_error ("Without padding, there are not enough elements "
2182 "in the intrinsic RESHAPE source at %L to match "
2183 "the shape", &source->where);
2194 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2196 if (type_check (x, 0, BT_REAL) == FAILURE)
2199 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2207 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2209 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2212 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2215 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2218 if (same_type_check (x, 0, y, 1) == FAILURE)
2226 gfc_check_secnds (gfc_expr *r)
2228 if (type_check (r, 0, BT_REAL) == FAILURE)
2231 if (kind_value_check (r, 0, 4) == FAILURE)
2234 if (scalar_check (r, 0) == FAILURE)
2242 gfc_check_selected_int_kind (gfc_expr *r)
2244 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2247 if (scalar_check (r, 0) == FAILURE)
2255 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r)
2257 if (p == NULL && r == NULL)
2259 gfc_error ("Missing arguments to %s intrinsic at %L",
2260 gfc_current_intrinsic, gfc_current_intrinsic_where);
2265 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
2268 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
2276 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
2278 if (type_check (x, 0, BT_REAL) == FAILURE)
2281 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2289 gfc_check_shape (gfc_expr *source)
2293 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2296 ar = gfc_find_array_ref (source);
2298 if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
2300 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2301 "an assumed size array", &source->where);
2310 gfc_check_sign (gfc_expr *a, gfc_expr *b)
2312 if (int_or_real_check (a, 0) == FAILURE)
2315 if (same_type_check (a, 0, b, 1) == FAILURE)
2323 gfc_check_size (gfc_expr *array, gfc_expr *dim)
2325 if (array_check (array, 0) == FAILURE)
2330 if (type_check (dim, 1, BT_INTEGER) == FAILURE)
2333 if (kind_value_check (dim, 1, gfc_default_integer_kind) == FAILURE)
2336 if (dim_rank_check (dim, array, 0) == FAILURE)
2345 gfc_check_sleep_sub (gfc_expr *seconds)
2347 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2350 if (scalar_check (seconds, 0) == FAILURE)
2358 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
2360 if (source->rank >= GFC_MAX_DIMENSIONS)
2362 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2363 "than rank %d", gfc_current_intrinsic_arg[0],
2364 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2369 if (dim_check (dim, 1, 0) == FAILURE)
2372 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2375 if (scalar_check (ncopies, 2) == FAILURE)
2379 return non_init_transformational ();
2385 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2389 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
2391 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2394 if (scalar_check (unit, 0) == FAILURE)
2397 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2403 if (type_check (status, 2, BT_INTEGER) == FAILURE
2404 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2405 || scalar_check (status, 2) == FAILURE)
2413 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
2415 return gfc_check_fgetputc_sub (unit, c, NULL);
2420 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
2422 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2428 if (type_check (status, 1, BT_INTEGER) == FAILURE
2429 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2430 || scalar_check (status, 1) == FAILURE)
2438 gfc_check_fgetput (gfc_expr *c)
2440 return gfc_check_fgetput_sub (c, NULL);
2445 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
2447 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2450 if (scalar_check (unit, 0) == FAILURE)
2453 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2456 if (scalar_check (offset, 1) == FAILURE)
2459 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
2462 if (scalar_check (whence, 2) == FAILURE)
2468 if (type_check (status, 3, BT_INTEGER) == FAILURE)
2471 if (kind_value_check (status, 3, 4) == FAILURE)
2474 if (scalar_check (status, 3) == FAILURE)
2483 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
2485 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2488 if (scalar_check (unit, 0) == FAILURE)
2491 if (type_check (array, 1, BT_INTEGER) == FAILURE
2492 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2495 if (array_check (array, 1) == FAILURE)
2503 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
2505 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2508 if (scalar_check (unit, 0) == FAILURE)
2511 if (type_check (array, 1, BT_INTEGER) == FAILURE
2512 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2515 if (array_check (array, 1) == FAILURE)
2521 if (type_check (status, 2, BT_INTEGER) == FAILURE
2522 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2525 if (scalar_check (status, 2) == FAILURE)
2533 gfc_check_ftell (gfc_expr *unit)
2535 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2538 if (scalar_check (unit, 0) == FAILURE)
2546 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
2548 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2551 if (scalar_check (unit, 0) == FAILURE)
2554 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2557 if (scalar_check (offset, 1) == FAILURE)
2565 gfc_check_stat (gfc_expr *name, gfc_expr *array)
2567 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2570 if (type_check (array, 1, BT_INTEGER) == FAILURE
2571 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2574 if (array_check (array, 1) == FAILURE)
2582 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
2584 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2587 if (type_check (array, 1, BT_INTEGER) == FAILURE
2588 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2591 if (array_check (array, 1) == FAILURE)
2597 if (type_check (status, 2, BT_INTEGER) == FAILURE
2598 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2601 if (scalar_check (status, 2) == FAILURE)
2609 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
2610 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
2614 if (type_check (size, 2, BT_INTEGER) == FAILURE)
2617 if (scalar_check (size, 2) == FAILURE)
2620 if (nonoptional_check (size, 2) == FAILURE)
2629 gfc_check_transpose (gfc_expr *matrix)
2631 if (rank_check (matrix, 0, 2) == FAILURE)
2635 return non_init_transformational ();
2642 gfc_check_ubound (gfc_expr *array, gfc_expr *dim)
2644 if (array_check (array, 0) == FAILURE)
2649 if (dim_check (dim, 1, 1) == FAILURE)
2652 if (dim_rank_check (dim, array, 0) == FAILURE)
2661 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
2663 if (rank_check (vector, 0, 1) == FAILURE)
2666 if (array_check (mask, 1) == FAILURE)
2669 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2672 if (same_type_check (vector, 0, field, 2) == FAILURE)
2676 return non_init_transformational ();
2683 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2685 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2688 if (same_type_check (x, 0, y, 1) == FAILURE)
2691 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2699 gfc_check_trim (gfc_expr *x)
2701 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2704 if (scalar_check (x, 0) == FAILURE)
2712 gfc_check_ttynam (gfc_expr *unit)
2714 if (scalar_check (unit, 0) == FAILURE)
2717 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2724 /* Common check function for the half a dozen intrinsics that have a
2725 single real argument. */
2728 gfc_check_x (gfc_expr *x)
2730 if (type_check (x, 0, BT_REAL) == FAILURE)
2737 /************* Check functions for intrinsic subroutines *************/
2740 gfc_check_cpu_time (gfc_expr *time)
2742 if (scalar_check (time, 0) == FAILURE)
2745 if (type_check (time, 0, BT_REAL) == FAILURE)
2748 if (variable_check (time, 0) == FAILURE)
2756 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
2757 gfc_expr *zone, gfc_expr *values)
2761 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2763 if (scalar_check (date, 0) == FAILURE)
2765 if (variable_check (date, 0) == FAILURE)
2771 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
2773 if (scalar_check (time, 1) == FAILURE)
2775 if (variable_check (time, 1) == FAILURE)
2781 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
2783 if (scalar_check (zone, 2) == FAILURE)
2785 if (variable_check (zone, 2) == FAILURE)
2791 if (type_check (values, 3, BT_INTEGER) == FAILURE)
2793 if (array_check (values, 3) == FAILURE)
2795 if (rank_check (values, 3, 1) == FAILURE)
2797 if (variable_check (values, 3) == FAILURE)
2806 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
2807 gfc_expr *to, gfc_expr *topos)
2809 if (type_check (from, 0, BT_INTEGER) == FAILURE)
2812 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
2815 if (type_check (len, 2, BT_INTEGER) == FAILURE)
2818 if (same_type_check (from, 0, to, 3) == FAILURE)
2821 if (variable_check (to, 3) == FAILURE)
2824 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
2832 gfc_check_random_number (gfc_expr *harvest)
2834 if (type_check (harvest, 0, BT_REAL) == FAILURE)
2837 if (variable_check (harvest, 0) == FAILURE)
2845 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
2849 if (scalar_check (size, 0) == FAILURE)
2852 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2855 if (variable_check (size, 0) == FAILURE)
2858 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
2866 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2869 if (array_check (put, 1) == FAILURE)
2872 if (rank_check (put, 1, 1) == FAILURE)
2875 if (type_check (put, 1, BT_INTEGER) == FAILURE)
2878 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
2885 if (size != NULL || put != NULL)
2886 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2889 if (array_check (get, 2) == FAILURE)
2892 if (rank_check (get, 2, 1) == FAILURE)
2895 if (type_check (get, 2, BT_INTEGER) == FAILURE)
2898 if (variable_check (get, 2) == FAILURE)
2901 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
2910 gfc_check_second_sub (gfc_expr *time)
2912 if (scalar_check (time, 0) == FAILURE)
2915 if (type_check (time, 0, BT_REAL) == FAILURE)
2918 if (kind_value_check(time, 0, 4) == FAILURE)
2925 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2926 count, count_rate, and count_max are all optional arguments */
2929 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
2930 gfc_expr *count_max)
2934 if (scalar_check (count, 0) == FAILURE)
2937 if (type_check (count, 0, BT_INTEGER) == FAILURE)
2940 if (variable_check (count, 0) == FAILURE)
2944 if (count_rate != NULL)
2946 if (scalar_check (count_rate, 1) == FAILURE)
2949 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
2952 if (variable_check (count_rate, 1) == FAILURE)
2956 && same_type_check (count, 0, count_rate, 1) == FAILURE)
2961 if (count_max != NULL)
2963 if (scalar_check (count_max, 2) == FAILURE)
2966 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
2969 if (variable_check (count_max, 2) == FAILURE)
2973 && same_type_check (count, 0, count_max, 2) == FAILURE)
2976 if (count_rate != NULL
2977 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
2986 gfc_check_irand (gfc_expr *x)
2991 if (scalar_check (x, 0) == FAILURE)
2994 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2997 if (kind_value_check(x, 0, 4) == FAILURE)
3005 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
3007 if (scalar_check (seconds, 0) == FAILURE)
3010 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3013 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3015 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3016 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3017 gfc_current_intrinsic, &handler->where);
3021 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3027 if (scalar_check (status, 2) == FAILURE)
3030 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3033 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3041 gfc_check_rand (gfc_expr *x)
3046 if (scalar_check (x, 0) == FAILURE)
3049 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3052 if (kind_value_check(x, 0, 4) == FAILURE)
3060 gfc_check_srand (gfc_expr *x)
3062 if (scalar_check (x, 0) == FAILURE)
3065 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3068 if (kind_value_check(x, 0, 4) == FAILURE)
3076 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
3078 if (scalar_check (time, 0) == FAILURE)
3081 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3084 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
3092 gfc_check_etime (gfc_expr *x)
3094 if (array_check (x, 0) == FAILURE)
3097 if (rank_check (x, 0, 1) == FAILURE)
3100 if (variable_check (x, 0) == FAILURE)
3103 if (type_check (x, 0, BT_REAL) == FAILURE)
3106 if (kind_value_check(x, 0, 4) == FAILURE)
3114 gfc_check_etime_sub (gfc_expr *values, gfc_expr *time)
3116 if (array_check (values, 0) == FAILURE)
3119 if (rank_check (values, 0, 1) == FAILURE)
3122 if (variable_check (values, 0) == FAILURE)
3125 if (type_check (values, 0, BT_REAL) == FAILURE)
3128 if (kind_value_check(values, 0, 4) == FAILURE)
3131 if (scalar_check (time, 1) == FAILURE)
3134 if (type_check (time, 1, BT_REAL) == FAILURE)
3137 if (kind_value_check(time, 1, 4) == FAILURE)
3145 gfc_check_fdate_sub (gfc_expr *date)
3147 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3155 gfc_check_gerror (gfc_expr *msg)
3157 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3165 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
3167 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
3173 if (scalar_check (status, 1) == FAILURE)
3176 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3184 gfc_check_getlog (gfc_expr *msg)
3186 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3194 gfc_check_exit (gfc_expr *status)
3199 if (type_check (status, 0, BT_INTEGER) == FAILURE)
3202 if (scalar_check (status, 0) == FAILURE)
3210 gfc_check_flush (gfc_expr *unit)
3215 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3218 if (scalar_check (unit, 0) == FAILURE)
3226 gfc_check_free (gfc_expr *i)
3228 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3231 if (scalar_check (i, 0) == FAILURE)
3239 gfc_check_hostnm (gfc_expr *name)
3241 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3249 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
3251 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3257 if (scalar_check (status, 1) == FAILURE)
3260 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3268 gfc_check_itime_idate (gfc_expr *values)
3270 if (array_check (values, 0) == FAILURE)
3273 if (rank_check (values, 0, 1) == FAILURE)
3276 if (variable_check (values, 0) == FAILURE)
3279 if (type_check (values, 0, BT_INTEGER) == FAILURE)
3282 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
3290 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
3292 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3295 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
3298 if (scalar_check (time, 0) == FAILURE)
3301 if (array_check (values, 1) == FAILURE)
3304 if (rank_check (values, 1, 1) == FAILURE)
3307 if (variable_check (values, 1) == FAILURE)
3310 if (type_check (values, 1, BT_INTEGER) == FAILURE)
3313 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
3321 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
3323 if (scalar_check (unit, 0) == FAILURE)
3326 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3329 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
3337 gfc_check_isatty (gfc_expr *unit)
3342 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3345 if (scalar_check (unit, 0) == FAILURE)
3353 gfc_check_perror (gfc_expr *string)
3355 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
3363 gfc_check_umask (gfc_expr *mask)
3365 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3368 if (scalar_check (mask, 0) == FAILURE)
3376 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
3378 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3381 if (scalar_check (mask, 0) == FAILURE)
3387 if (scalar_check (old, 1) == FAILURE)
3390 if (type_check (old, 1, BT_INTEGER) == FAILURE)
3398 gfc_check_unlink (gfc_expr *name)
3400 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3408 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
3410 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3416 if (scalar_check (status, 1) == FAILURE)
3419 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3427 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
3429 if (scalar_check (number, 0) == FAILURE)
3432 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3435 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3437 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3438 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3439 gfc_current_intrinsic, &handler->where);
3443 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3451 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
3453 if (scalar_check (number, 0) == FAILURE)
3456 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3459 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3461 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3462 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3463 gfc_current_intrinsic, &handler->where);
3467 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3473 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3476 if (scalar_check (status, 2) == FAILURE)
3484 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
3486 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
3489 if (scalar_check (status, 1) == FAILURE)
3492 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3495 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
3502 /* This is used for the GNU intrinsics AND, OR and XOR. */
3504 gfc_check_and (gfc_expr *i, gfc_expr *j)
3506 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
3508 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3509 "or LOGICAL", gfc_current_intrinsic_arg[0],
3510 gfc_current_intrinsic, &i->where);
3514 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
3516 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3517 "or LOGICAL", gfc_current_intrinsic_arg[1],
3518 gfc_current_intrinsic, &j->where);
3522 if (i->ts.type != j->ts.type)
3524 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
3525 "have the same type", gfc_current_intrinsic_arg[0],
3526 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3531 if (scalar_check (i, 0) == FAILURE)
3534 if (scalar_check (j, 1) == FAILURE)