2 Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Katherine Holcomb
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 /* These functions check to see if an argument list is compatible with
24 a particular intrinsic function or subroutine. Presence of
25 required arguments has already been established, the argument list
26 has been sorted into the right order and has NULL arguments in the
27 correct places for missing optional arguments. */
33 #include "intrinsic.h"
36 /* Check the type of an expression. */
39 type_check (gfc_expr * e, int n, bt type)
41 if (e->ts.type == type)
44 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
45 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where,
46 gfc_basic_typename (type));
52 /* Check that the expression is a numeric type. */
55 numeric_check (gfc_expr * e, int n)
57 if (gfc_numeric_ts (&e->ts))
60 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
61 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
67 /* Check that an expression is integer or real. */
70 int_or_real_check (gfc_expr * e, int n)
72 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
75 "'%s' argument of '%s' intrinsic at %L must be INTEGER or REAL",
76 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
84 /* Check that an expression is real or complex. */
87 real_or_complex_check (gfc_expr * e, int n)
89 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
92 "'%s' argument of '%s' intrinsic at %L must be REAL or COMPLEX",
93 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
101 /* Check that the expression is an optional constant integer
102 and that it specifies a valid kind for that type. */
105 kind_check (gfc_expr * k, int n, bt type)
112 if (type_check (k, n, BT_INTEGER) == FAILURE)
115 if (k->expr_type != EXPR_CONSTANT)
118 "'%s' argument of '%s' intrinsic at %L must be a constant",
119 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &k->where);
123 if (gfc_extract_int (k, &kind) != NULL
124 || gfc_validate_kind (type, kind, true) < 0)
126 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
135 /* Make sure the expression is a double precision real. */
138 double_check (gfc_expr * d, int n)
140 if (type_check (d, n, BT_REAL) == FAILURE)
143 if (d->ts.kind != gfc_default_double_kind)
146 "'%s' argument of '%s' intrinsic at %L must be double precision",
147 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &d->where);
155 /* Make sure the expression is a logical array. */
158 logical_array_check (gfc_expr * array, int n)
160 if (array->ts.type != BT_LOGICAL || array->rank == 0)
163 "'%s' argument of '%s' intrinsic at %L must be a logical array",
164 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &array->where);
172 /* Make sure an expression is an array. */
175 array_check (gfc_expr * e, int n)
180 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
181 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
187 /* Make sure an expression is a scalar. */
190 scalar_check (gfc_expr * e, int n)
195 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
196 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
202 /* Make sure two expression have the same type. */
205 same_type_check (gfc_expr * e, int n, gfc_expr * f, int m)
207 if (gfc_compare_types (&e->ts, &f->ts))
210 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
211 "and kind as '%s'", gfc_current_intrinsic_arg[m],
212 gfc_current_intrinsic, &f->where, gfc_current_intrinsic_arg[n]);
217 /* Make sure that an expression has a certain (nonzero) rank. */
220 rank_check (gfc_expr * e, int n, int rank)
225 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
226 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
232 /* Make sure a variable expression is not an optional dummy argument. */
235 nonoptional_check (gfc_expr * e, int n)
237 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
239 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
240 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
245 /* TODO: Recursive check on nonoptional variables? */
251 /* Check that an expression has a particular kind. */
254 kind_value_check (gfc_expr * e, int n, int k)
259 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
260 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
266 /* Make sure an expression is a variable. */
269 variable_check (gfc_expr * e, int n)
271 if ((e->expr_type == EXPR_VARIABLE
272 && e->symtree->n.sym->attr.flavor != FL_PARAMETER)
273 || (e->expr_type == EXPR_FUNCTION
274 && e->symtree->n.sym->result == e->symtree->n.sym))
277 if (e->expr_type == EXPR_VARIABLE
278 && e->symtree->n.sym->attr.intent == INTENT_IN)
280 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
281 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
286 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
287 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
293 /* Check the common DIM parameter for correctness. */
296 dim_check (gfc_expr * dim, int n, int optional)
298 if (optional && dim == NULL)
303 gfc_error ("Missing DIM parameter in intrinsic '%s' at %L",
304 gfc_current_intrinsic, gfc_current_intrinsic_where);
308 if (type_check (dim, n, BT_INTEGER) == FAILURE)
311 if (scalar_check (dim, n) == FAILURE)
314 if (nonoptional_check (dim, n) == FAILURE)
321 /* If a DIM parameter is a constant, make sure that it is greater than
322 zero and less than or equal to the rank of the given array. If
323 allow_assumed is zero then dim must be less than the rank of the array
324 for assumed size arrays. */
327 dim_rank_check (gfc_expr * dim, gfc_expr * array, int allow_assumed)
332 if (dim->expr_type != EXPR_CONSTANT || array->expr_type != EXPR_VARIABLE)
335 ar = gfc_find_array_ref (array);
337 if (ar->as->type == AS_ASSUMED_SIZE && !allow_assumed)
340 if (mpz_cmp_ui (dim->value.integer, 1) < 0
341 || mpz_cmp_ui (dim->value.integer, rank) > 0)
343 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
344 "dimension index", gfc_current_intrinsic, &dim->where);
352 /* Compare the size of a along dimension ai with the size of b along
353 dimension bi, returning 0 if they are known not to be identical,
354 and 1 if they are identical, or if this cannot be determined. */
357 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
359 mpz_t a_size, b_size;
362 gcc_assert (a->rank > ai);
363 gcc_assert (b->rank > bi);
367 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
369 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
371 if (mpz_cmp (a_size, b_size) != 0)
381 /* Error return for transformational intrinsics not allowed in
382 initialization expressions. */
385 non_init_transformational (void)
387 gfc_error ("transformational intrinsic '%s' at %L is not permitted "
388 "in an initialization expression", gfc_current_intrinsic,
389 gfc_current_intrinsic_where);
393 /***** Check functions *****/
395 /* Check subroutine suitable for intrinsics taking a real argument and
396 a kind argument for the result. */
399 check_a_kind (gfc_expr * a, gfc_expr * kind, bt type)
401 if (type_check (a, 0, BT_REAL) == FAILURE)
403 if (kind_check (kind, 1, type) == FAILURE)
409 /* Check subroutine suitable for ceiling, floor and nint. */
412 gfc_check_a_ikind (gfc_expr * a, gfc_expr * kind)
414 return check_a_kind (a, kind, BT_INTEGER);
417 /* Check subroutine suitable for aint, anint. */
420 gfc_check_a_xkind (gfc_expr * a, gfc_expr * kind)
422 return check_a_kind (a, kind, BT_REAL);
426 gfc_check_abs (gfc_expr * a)
428 if (numeric_check (a, 0) == FAILURE)
435 gfc_check_achar (gfc_expr * a)
438 if (type_check (a, 0, BT_INTEGER) == FAILURE)
446 gfc_check_access_func (gfc_expr * name, gfc_expr * mode)
448 if (type_check (name, 0, BT_CHARACTER) == FAILURE
449 || scalar_check (name, 0) == FAILURE)
453 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
454 || scalar_check (mode, 1) == FAILURE)
462 gfc_check_all_any (gfc_expr * mask, gfc_expr * dim)
464 if (logical_array_check (mask, 0) == FAILURE)
467 if (dim_check (dim, 1, 1) == FAILURE)
471 return non_init_transformational ();
478 gfc_check_allocated (gfc_expr * array)
480 symbol_attribute attr;
482 if (variable_check (array, 0) == FAILURE)
485 if (array_check (array, 0) == FAILURE)
488 attr = gfc_variable_attr (array, NULL);
489 if (!attr.allocatable)
491 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
492 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
501 /* Common check function where the first argument must be real or
502 integer and the second argument must be the same as the first. */
505 gfc_check_a_p (gfc_expr * a, gfc_expr * p)
507 if (int_or_real_check (a, 0) == FAILURE)
510 if (a->ts.type != p->ts.type)
512 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
513 "have the same type", gfc_current_intrinsic_arg[0],
514 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
519 if (a->ts.kind != p->ts.kind)
521 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
522 &p->where) == FAILURE)
531 gfc_check_associated (gfc_expr * pointer, gfc_expr * target)
533 symbol_attribute attr;
538 where = &pointer->where;
540 if (pointer->expr_type == EXPR_VARIABLE)
541 attr = gfc_variable_attr (pointer, NULL);
542 else if (pointer->expr_type == EXPR_FUNCTION)
543 attr = pointer->symtree->n.sym->attr;
544 else if (pointer->expr_type == EXPR_NULL)
547 gcc_assert (0); /* Pointer must be a variable or a function. */
551 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
552 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
557 /* Target argument is optional. */
561 where = &target->where;
562 if (target->expr_type == EXPR_NULL)
565 if (target->expr_type == EXPR_VARIABLE)
566 attr = gfc_variable_attr (target, NULL);
567 else if (target->expr_type == EXPR_FUNCTION)
568 attr = target->symtree->n.sym->attr;
571 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
572 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg[1],
573 gfc_current_intrinsic, &target->where);
577 if (!attr.pointer && !attr.target)
579 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
580 "or a TARGET", gfc_current_intrinsic_arg[1],
581 gfc_current_intrinsic, &target->where);
586 if (same_type_check (pointer, 0, target, 1) == FAILURE)
588 if (rank_check (target, 0, pointer->rank) == FAILURE)
590 if (target->rank > 0)
592 for (i = 0; i < target->rank; i++)
593 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
595 gfc_error ("Array section with a vector subscript at %L shall not "
596 "be the target of a pointer",
606 gfc_error ("NULL pointer at %L is not permitted as actual argument "
607 "of '%s' intrinsic function", where, gfc_current_intrinsic);
614 gfc_check_atan2 (gfc_expr * y, gfc_expr * x)
616 if (type_check (y, 0, BT_REAL) == FAILURE)
618 if (same_type_check (y, 0, x, 1) == FAILURE)
625 /* BESJN and BESYN functions. */
628 gfc_check_besn (gfc_expr * n, gfc_expr * x)
630 if (scalar_check (n, 0) == FAILURE)
633 if (type_check (n, 0, BT_INTEGER) == FAILURE)
636 if (scalar_check (x, 1) == FAILURE)
639 if (type_check (x, 1, BT_REAL) == FAILURE)
647 gfc_check_btest (gfc_expr * i, gfc_expr * pos)
649 if (type_check (i, 0, BT_INTEGER) == FAILURE)
651 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
659 gfc_check_char (gfc_expr * i, gfc_expr * kind)
661 if (type_check (i, 0, BT_INTEGER) == FAILURE)
663 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
671 gfc_check_chdir (gfc_expr * dir)
673 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
681 gfc_check_chdir_sub (gfc_expr * dir, gfc_expr * status)
683 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
689 if (type_check (status, 1, BT_INTEGER) == FAILURE)
692 if (scalar_check (status, 1) == FAILURE)
700 gfc_check_chmod (gfc_expr * name, gfc_expr * mode)
702 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
705 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
713 gfc_check_chmod_sub (gfc_expr * name, gfc_expr * mode, gfc_expr * status)
715 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
718 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
724 if (type_check (status, 2, BT_INTEGER) == FAILURE)
727 if (scalar_check (status, 2) == FAILURE)
735 gfc_check_cmplx (gfc_expr * x, gfc_expr * y, gfc_expr * kind)
737 if (numeric_check (x, 0) == FAILURE)
742 if (numeric_check (y, 1) == FAILURE)
745 if (x->ts.type == BT_COMPLEX)
747 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
748 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
749 gfc_current_intrinsic, &y->where);
754 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
762 gfc_check_complex (gfc_expr * x, gfc_expr * y)
764 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
767 "'%s' argument of '%s' intrinsic at %L must be INTEGER or REAL",
768 gfc_current_intrinsic_arg[0], gfc_current_intrinsic, &x->where);
771 if (scalar_check (x, 0) == FAILURE)
774 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
777 "'%s' argument of '%s' intrinsic at %L must be INTEGER or REAL",
778 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &y->where);
781 if (scalar_check (y, 1) == FAILURE)
789 gfc_check_count (gfc_expr * mask, gfc_expr * dim)
791 if (logical_array_check (mask, 0) == FAILURE)
793 if (dim_check (dim, 1, 1) == FAILURE)
797 return non_init_transformational ();
804 gfc_check_cshift (gfc_expr * array, gfc_expr * shift, gfc_expr * dim)
806 if (array_check (array, 0) == FAILURE)
809 if (array->rank == 1)
811 if (scalar_check (shift, 1) == FAILURE)
816 /* TODO: more requirements on shift parameter. */
819 if (dim_check (dim, 2, 1) == FAILURE)
823 return non_init_transformational ();
830 gfc_check_ctime (gfc_expr * time)
832 if (scalar_check (time, 0) == FAILURE)
835 if (type_check (time, 0, BT_INTEGER) == FAILURE)
843 gfc_check_dcmplx (gfc_expr * x, gfc_expr * y)
845 if (numeric_check (x, 0) == FAILURE)
850 if (numeric_check (y, 1) == FAILURE)
853 if (x->ts.type == BT_COMPLEX)
855 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
856 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
857 gfc_current_intrinsic, &y->where);
867 gfc_check_dble (gfc_expr * x)
869 if (numeric_check (x, 0) == FAILURE)
877 gfc_check_digits (gfc_expr * x)
879 if (int_or_real_check (x, 0) == FAILURE)
887 gfc_check_dot_product (gfc_expr * vector_a, gfc_expr * vector_b)
889 switch (vector_a->ts.type)
892 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
899 if (numeric_check (vector_b, 1) == FAILURE)
904 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
905 "or LOGICAL", gfc_current_intrinsic_arg[0],
906 gfc_current_intrinsic, &vector_a->where);
910 if (rank_check (vector_a, 0, 1) == FAILURE)
913 if (rank_check (vector_b, 1, 1) == FAILURE)
916 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
918 gfc_error ("different shape for arguments '%s' and '%s' "
919 "at %L for intrinsic 'dot_product'",
920 gfc_current_intrinsic_arg[0],
921 gfc_current_intrinsic_arg[1],
927 return non_init_transformational ();
934 gfc_check_eoshift (gfc_expr * array, gfc_expr * shift, gfc_expr * boundary,
937 if (array_check (array, 0) == FAILURE)
940 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
943 if (array->rank == 1)
945 if (scalar_check (shift, 2) == FAILURE)
950 /* TODO: more weird restrictions on shift. */
953 if (boundary != NULL)
955 if (same_type_check (array, 0, boundary, 2) == FAILURE)
958 /* TODO: more restrictions on boundary. */
961 if (dim_check (dim, 1, 1) == FAILURE)
965 return non_init_transformational ();
971 /* A single complex argument. */
974 gfc_check_fn_c (gfc_expr * a)
976 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
983 /* A single real argument. */
986 gfc_check_fn_r (gfc_expr * a)
988 if (type_check (a, 0, BT_REAL) == FAILURE)
995 /* A single real or complex argument. */
998 gfc_check_fn_rc (gfc_expr * a)
1000 if (real_or_complex_check (a, 0) == FAILURE)
1008 gfc_check_fnum (gfc_expr * unit)
1010 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1013 if (scalar_check (unit, 0) == FAILURE)
1020 /* This is used for the g77 one-argument Bessel functions, and the
1024 gfc_check_g77_math1 (gfc_expr * x)
1026 if (scalar_check (x, 0) == FAILURE)
1029 if (type_check (x, 0, BT_REAL) == FAILURE)
1037 gfc_check_huge (gfc_expr * x)
1039 if (int_or_real_check (x, 0) == FAILURE)
1046 /* Check that the single argument is an integer. */
1049 gfc_check_i (gfc_expr * i)
1051 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1059 gfc_check_iand (gfc_expr * i, gfc_expr * j)
1061 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1064 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1067 if (i->ts.kind != j->ts.kind)
1069 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1070 &i->where) == FAILURE)
1079 gfc_check_ibclr (gfc_expr * i, gfc_expr * pos)
1081 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1084 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1092 gfc_check_ibits (gfc_expr * i, gfc_expr * pos, gfc_expr * len)
1094 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1097 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1100 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1108 gfc_check_ibset (gfc_expr * i, gfc_expr * pos)
1110 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1113 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1121 gfc_check_ichar_iachar (gfc_expr * c)
1125 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1128 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1134 /* Substring references don't have the charlength set. */
1136 while (ref && ref->type != REF_SUBSTRING)
1139 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1143 /* Check that the argument is length one. Non-constant lengths
1144 can't be checked here, so assume they are ok. */
1145 if (c->ts.cl && c->ts.cl->length)
1147 /* If we already have a length for this expression then use it. */
1148 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
1150 i = mpz_get_si (c->ts.cl->length->value.integer);
1157 start = ref->u.ss.start;
1158 end = ref->u.ss.end;
1161 if (end == NULL || end->expr_type != EXPR_CONSTANT
1162 || start->expr_type != EXPR_CONSTANT)
1165 i = mpz_get_si (end->value.integer) + 1
1166 - mpz_get_si (start->value.integer);
1174 gfc_error ("Argument of %s at %L must be of length one",
1175 gfc_current_intrinsic, &c->where);
1184 gfc_check_idnint (gfc_expr * a)
1186 if (double_check (a, 0) == FAILURE)
1194 gfc_check_ieor (gfc_expr * i, gfc_expr * j)
1196 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1199 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1202 if (i->ts.kind != j->ts.kind)
1204 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1205 &i->where) == FAILURE)
1214 gfc_check_index (gfc_expr * string, gfc_expr * substring, gfc_expr * back)
1216 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1217 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1221 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1224 if (string->ts.kind != substring->ts.kind)
1226 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1227 "kind as '%s'", gfc_current_intrinsic_arg[1],
1228 gfc_current_intrinsic, &substring->where,
1229 gfc_current_intrinsic_arg[0]);
1238 gfc_check_int (gfc_expr * x, gfc_expr * kind)
1240 if (numeric_check (x, 0) == FAILURE)
1245 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
1248 if (scalar_check (kind, 1) == FAILURE)
1257 gfc_check_intconv (gfc_expr * x)
1259 if (numeric_check (x, 0) == FAILURE)
1267 gfc_check_ior (gfc_expr * i, gfc_expr * j)
1269 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1272 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1275 if (i->ts.kind != j->ts.kind)
1277 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1278 &i->where) == FAILURE)
1287 gfc_check_ishft (gfc_expr * i, gfc_expr * shift)
1289 if (type_check (i, 0, BT_INTEGER) == FAILURE
1290 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1298 gfc_check_ishftc (gfc_expr * i, gfc_expr * shift, gfc_expr * size)
1300 if (type_check (i, 0, BT_INTEGER) == FAILURE
1301 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1304 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1312 gfc_check_kill (gfc_expr * pid, gfc_expr * sig)
1314 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1317 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1325 gfc_check_kill_sub (gfc_expr * pid, gfc_expr * sig, gfc_expr * status)
1327 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1330 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1336 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1339 if (scalar_check (status, 2) == FAILURE)
1347 gfc_check_kind (gfc_expr * x)
1349 if (x->ts.type == BT_DERIVED)
1351 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1352 "non-derived type", gfc_current_intrinsic_arg[0],
1353 gfc_current_intrinsic, &x->where);
1362 gfc_check_lbound (gfc_expr * array, gfc_expr * dim)
1364 if (array_check (array, 0) == FAILURE)
1369 if (dim_check (dim, 1, 1) == FAILURE)
1372 if (dim_rank_check (dim, array, 1) == FAILURE)
1380 gfc_check_link (gfc_expr * path1, gfc_expr * path2)
1382 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1385 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1393 gfc_check_link_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
1395 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1398 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1404 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1407 if (scalar_check (status, 2) == FAILURE)
1414 gfc_check_loc (gfc_expr *expr)
1416 return variable_check (expr, 0);
1421 gfc_check_symlnk (gfc_expr * path1, gfc_expr * path2)
1423 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1426 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1434 gfc_check_symlnk_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
1436 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1439 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1445 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1448 if (scalar_check (status, 2) == FAILURE)
1456 gfc_check_logical (gfc_expr * a, gfc_expr * kind)
1458 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1460 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1467 /* Min/max family. */
1470 min_max_args (gfc_actual_arglist * arg)
1472 if (arg == NULL || arg->next == NULL)
1474 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1475 gfc_current_intrinsic, gfc_current_intrinsic_where);
1484 check_rest (bt type, int kind, gfc_actual_arglist * arg)
1489 if (min_max_args (arg) == FAILURE)
1494 for (; arg; arg = arg->next, n++)
1497 if (x->ts.type != type || x->ts.kind != kind)
1499 if (x->ts.type == type)
1501 if (gfc_notify_std (GFC_STD_GNU,
1502 "Extension: Different type kinds at %L", &x->where)
1508 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be %s(%d)",
1509 n, gfc_current_intrinsic, &x->where,
1510 gfc_basic_typename (type), kind);
1521 gfc_check_min_max (gfc_actual_arglist * arg)
1525 if (min_max_args (arg) == FAILURE)
1530 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1533 ("'a1' argument of '%s' intrinsic at %L must be INTEGER or REAL",
1534 gfc_current_intrinsic, &x->where);
1538 return check_rest (x->ts.type, x->ts.kind, arg);
1543 gfc_check_min_max_integer (gfc_actual_arglist * arg)
1545 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1550 gfc_check_min_max_real (gfc_actual_arglist * arg)
1552 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1557 gfc_check_min_max_double (gfc_actual_arglist * arg)
1559 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1562 /* End of min/max family. */
1565 gfc_check_malloc (gfc_expr * size)
1567 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1570 if (scalar_check (size, 0) == FAILURE)
1578 gfc_check_matmul (gfc_expr * matrix_a, gfc_expr * matrix_b)
1580 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1582 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1583 "or LOGICAL", gfc_current_intrinsic_arg[0],
1584 gfc_current_intrinsic, &matrix_a->where);
1588 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1590 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1591 "or LOGICAL", gfc_current_intrinsic_arg[1],
1592 gfc_current_intrinsic, &matrix_b->where);
1596 switch (matrix_a->rank)
1599 if (rank_check (matrix_b, 1, 2) == FAILURE)
1601 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
1602 if (! identical_dimen_shape (matrix_a, 0, matrix_b, 0))
1604 gfc_error ("different shape on dimension 1 for arguments '%s' "
1605 "and '%s' at %L for intrinsic matmul",
1606 gfc_current_intrinsic_arg[0],
1607 gfc_current_intrinsic_arg[1],
1614 if (matrix_b->rank != 2)
1616 if (rank_check (matrix_b, 1, 1) == FAILURE)
1619 /* matrix_b has rank 1 or 2 here. Common check for the cases
1620 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
1621 - matrix_a has shape (n,m) and matrix_b has shape (m). */
1622 if (! identical_dimen_shape (matrix_a, 1, matrix_b, 0))
1624 gfc_error ("different shape on dimension 2 for argument '%s' and "
1625 "dimension 1 for argument '%s' at %L for intrinsic "
1626 "matmul", gfc_current_intrinsic_arg[0],
1627 gfc_current_intrinsic_arg[1], &matrix_a->where);
1633 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1634 "1 or 2", gfc_current_intrinsic_arg[0],
1635 gfc_current_intrinsic, &matrix_a->where);
1640 return non_init_transformational ();
1646 /* Whoever came up with this interface was probably on something.
1647 The possibilities for the occupation of the second and third
1654 NULL MASK minloc(array, mask=m)
1657 I.e. in the case of minloc(array,mask), mask will be in the second
1658 position of the argument list and we'll have to fix that up. */
1661 gfc_check_minloc_maxloc (gfc_actual_arglist * ap)
1663 gfc_expr *a, *m, *d;
1666 if (int_or_real_check (a, 0) == FAILURE
1667 || array_check (a, 0) == FAILURE)
1671 m = ap->next->next->expr;
1673 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1674 && ap->next->name == NULL)
1679 ap->next->expr = NULL;
1680 ap->next->next->expr = m;
1683 if (dim_check (d, 1, 1) == FAILURE)
1686 if (d && dim_rank_check (d, a, 0) == FAILURE)
1689 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1695 snprintf(buffer, sizeof(buffer), "arguments '%s' and '%s' for intrinsic %s",
1696 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1697 gfc_current_intrinsic);
1698 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1703 return non_init_transformational ();
1709 /* Similar to minloc/maxloc, the argument list might need to be
1710 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1711 difference is that MINLOC/MAXLOC take an additional KIND argument.
1712 The possibilities are:
1718 NULL MASK minval(array, mask=m)
1721 I.e. in the case of minval(array,mask), mask will be in the second
1722 position of the argument list and we'll have to fix that up. */
1725 check_reduction (gfc_actual_arglist * ap)
1727 gfc_expr *a, *m, *d;
1731 m = ap->next->next->expr;
1733 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1734 && ap->next->name == NULL)
1739 ap->next->expr = NULL;
1740 ap->next->next->expr = m;
1743 if (dim_check (d, 1, 1) == FAILURE)
1746 if (d && dim_rank_check (d, a, 0) == FAILURE)
1749 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1755 snprintf(buffer, sizeof(buffer), "arguments '%s' and '%s' for intrinsic %s",
1756 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1757 gfc_current_intrinsic);
1758 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1767 gfc_check_minval_maxval (gfc_actual_arglist * ap)
1769 if (int_or_real_check (ap->expr, 0) == FAILURE
1770 || array_check (ap->expr, 0) == FAILURE)
1774 return non_init_transformational ();
1776 return check_reduction (ap);
1781 gfc_check_product_sum (gfc_actual_arglist * ap)
1783 if (numeric_check (ap->expr, 0) == FAILURE
1784 || array_check (ap->expr, 0) == FAILURE)
1788 return non_init_transformational ();
1790 return check_reduction (ap);
1795 gfc_check_merge (gfc_expr * tsource, gfc_expr * fsource, gfc_expr * mask)
1799 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
1802 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
1805 snprintf(buffer, sizeof(buffer), "arguments '%s' and '%s' for intrinsic '%s'",
1806 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1807 gfc_current_intrinsic);
1808 if (gfc_check_conformance (buffer, tsource, fsource) == FAILURE)
1811 snprintf(buffer, sizeof(buffer), "arguments '%s' and '%s' for intrinsic '%s'",
1812 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1813 gfc_current_intrinsic);
1814 if (gfc_check_conformance (buffer, tsource, mask) == FAILURE)
1821 gfc_check_move_alloc (gfc_expr * from, gfc_expr * to)
1823 symbol_attribute attr;
1825 if (variable_check (from, 0) == FAILURE)
1828 if (array_check (from, 0) == FAILURE)
1831 attr = gfc_variable_attr (from, NULL);
1832 if (!attr.allocatable)
1834 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1835 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1840 if (variable_check (to, 0) == FAILURE)
1843 if (array_check (to, 0) == FAILURE)
1846 attr = gfc_variable_attr (to, NULL);
1847 if (!attr.allocatable)
1849 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1850 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1855 if (same_type_check (from, 0, to, 1) == FAILURE)
1858 if (to->rank != from->rank)
1860 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1861 "have the same rank %d/%d", gfc_current_intrinsic_arg[0],
1862 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1863 &to->where, from->rank, to->rank);
1867 if (to->ts.kind != from->ts.kind)
1869 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1870 "be of the same kind %d/%d", gfc_current_intrinsic_arg[0],
1871 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1872 &to->where, from->ts.kind, to->ts.kind);
1880 gfc_check_nearest (gfc_expr * x, gfc_expr * s)
1882 if (type_check (x, 0, BT_REAL) == FAILURE)
1885 if (type_check (s, 1, BT_REAL) == FAILURE)
1892 gfc_check_new_line (gfc_expr * a)
1894 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1901 gfc_check_null (gfc_expr * mold)
1903 symbol_attribute attr;
1908 if (variable_check (mold, 0) == FAILURE)
1911 attr = gfc_variable_attr (mold, NULL);
1915 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
1916 gfc_current_intrinsic_arg[0],
1917 gfc_current_intrinsic, &mold->where);
1926 gfc_check_pack (gfc_expr * array, gfc_expr * mask, gfc_expr * vector)
1930 if (array_check (array, 0) == FAILURE)
1933 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1936 snprintf(buffer, sizeof(buffer), "arguments '%s' and '%s' for intrinsic '%s'",
1937 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1938 gfc_current_intrinsic);
1939 if (gfc_check_conformance (buffer, array, mask) == FAILURE)
1944 if (same_type_check (array, 0, vector, 2) == FAILURE)
1947 if (rank_check (vector, 2, 1) == FAILURE)
1950 /* TODO: More constraints here. */
1954 return non_init_transformational ();
1961 gfc_check_precision (gfc_expr * x)
1963 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
1965 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
1966 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
1967 gfc_current_intrinsic, &x->where);
1976 gfc_check_present (gfc_expr * a)
1980 if (variable_check (a, 0) == FAILURE)
1983 sym = a->symtree->n.sym;
1984 if (!sym->attr.dummy)
1986 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
1987 "dummy variable", gfc_current_intrinsic_arg[0],
1988 gfc_current_intrinsic, &a->where);
1992 if (!sym->attr.optional)
1994 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
1995 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
1996 gfc_current_intrinsic, &a->where);
2000 /* 13.14.82 PRESENT(A)
2002 Argument. A shall be the name of an optional dummy argument that is accessible
2003 in the subprogram in which the PRESENT function reference appears... */
2006 && !(a->ref->next == NULL
2007 && a->ref->type == REF_ARRAY
2008 && a->ref->u.ar.type == AR_FULL))
2010 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a sub-"
2011 "object of '%s'", gfc_current_intrinsic_arg[0],
2012 gfc_current_intrinsic, &a->where, sym->name);
2021 gfc_check_radix (gfc_expr * x)
2023 if (int_or_real_check (x, 0) == FAILURE)
2031 gfc_check_range (gfc_expr * x)
2033 if (numeric_check (x, 0) == FAILURE)
2040 /* real, float, sngl. */
2042 gfc_check_real (gfc_expr * a, gfc_expr * kind)
2044 if (numeric_check (a, 0) == FAILURE)
2047 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2055 gfc_check_rename (gfc_expr * path1, gfc_expr * path2)
2057 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2060 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2068 gfc_check_rename_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
2070 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2073 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2079 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2082 if (scalar_check (status, 2) == FAILURE)
2090 gfc_check_repeat (gfc_expr * x, gfc_expr * y)
2092 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2095 if (scalar_check (x, 0) == FAILURE)
2098 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2101 if (scalar_check (y, 1) == FAILURE)
2109 gfc_check_reshape (gfc_expr * source, gfc_expr * shape,
2110 gfc_expr * pad, gfc_expr * order)
2115 if (array_check (source, 0) == FAILURE)
2118 if (rank_check (shape, 1, 1) == FAILURE)
2121 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2124 if (gfc_array_size (shape, &size) != SUCCESS)
2126 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2127 "array of constant size", &shape->where);
2131 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
2136 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2137 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2143 if (same_type_check (source, 0, pad, 2) == FAILURE)
2145 if (array_check (pad, 2) == FAILURE)
2149 if (order != NULL && array_check (order, 3) == FAILURE)
2157 gfc_check_scale (gfc_expr * x, gfc_expr * i)
2159 if (type_check (x, 0, BT_REAL) == FAILURE)
2162 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2170 gfc_check_scan (gfc_expr * x, gfc_expr * y, gfc_expr * z)
2172 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2175 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2178 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2181 if (same_type_check (x, 0, y, 1) == FAILURE)
2189 gfc_check_secnds (gfc_expr * r)
2192 if (type_check (r, 0, BT_REAL) == FAILURE)
2195 if (kind_value_check (r, 0, 4) == FAILURE)
2198 if (scalar_check (r, 0) == FAILURE)
2206 gfc_check_selected_int_kind (gfc_expr * r)
2209 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2212 if (scalar_check (r, 0) == FAILURE)
2220 gfc_check_selected_real_kind (gfc_expr * p, gfc_expr * r)
2222 if (p == NULL && r == NULL)
2224 gfc_error ("Missing arguments to %s intrinsic at %L",
2225 gfc_current_intrinsic, gfc_current_intrinsic_where);
2230 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
2233 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
2241 gfc_check_set_exponent (gfc_expr * x, gfc_expr * i)
2243 if (type_check (x, 0, BT_REAL) == FAILURE)
2246 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2254 gfc_check_shape (gfc_expr * source)
2258 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2261 ar = gfc_find_array_ref (source);
2263 if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
2265 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2266 "an assumed size array", &source->where);
2275 gfc_check_sign (gfc_expr * a, gfc_expr * b)
2277 if (int_or_real_check (a, 0) == FAILURE)
2280 if (same_type_check (a, 0, b, 1) == FAILURE)
2288 gfc_check_size (gfc_expr * array, gfc_expr * dim)
2290 if (array_check (array, 0) == FAILURE)
2295 if (type_check (dim, 1, BT_INTEGER) == FAILURE)
2298 if (kind_value_check (dim, 1, gfc_default_integer_kind) == FAILURE)
2301 if (dim_rank_check (dim, array, 0) == FAILURE)
2310 gfc_check_sleep_sub (gfc_expr * seconds)
2312 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2315 if (scalar_check (seconds, 0) == FAILURE)
2323 gfc_check_spread (gfc_expr * source, gfc_expr * dim, gfc_expr * ncopies)
2325 if (source->rank >= GFC_MAX_DIMENSIONS)
2327 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2328 "than rank %d", gfc_current_intrinsic_arg[0],
2329 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2334 if (dim_check (dim, 1, 0) == FAILURE)
2337 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2340 if (scalar_check (ncopies, 2) == FAILURE)
2344 return non_init_transformational ();
2350 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2353 gfc_check_fgetputc_sub (gfc_expr * unit, gfc_expr * c, gfc_expr * status)
2355 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2358 if (scalar_check (unit, 0) == FAILURE)
2361 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2367 if (type_check (status, 2, BT_INTEGER) == FAILURE
2368 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2369 || scalar_check (status, 2) == FAILURE)
2377 gfc_check_fgetputc (gfc_expr * unit, gfc_expr * c)
2379 return gfc_check_fgetputc_sub (unit, c, NULL);
2384 gfc_check_fgetput_sub (gfc_expr * c, gfc_expr * status)
2386 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2392 if (type_check (status, 1, BT_INTEGER) == FAILURE
2393 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2394 || scalar_check (status, 1) == FAILURE)
2402 gfc_check_fgetput (gfc_expr * c)
2404 return gfc_check_fgetput_sub (c, NULL);
2409 gfc_check_fstat (gfc_expr * unit, gfc_expr * array)
2411 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2414 if (scalar_check (unit, 0) == FAILURE)
2417 if (type_check (array, 1, BT_INTEGER) == FAILURE
2418 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2421 if (array_check (array, 1) == FAILURE)
2429 gfc_check_fstat_sub (gfc_expr * unit, gfc_expr * array, gfc_expr * status)
2431 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2434 if (scalar_check (unit, 0) == FAILURE)
2437 if (type_check (array, 1, BT_INTEGER) == FAILURE
2438 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2441 if (array_check (array, 1) == FAILURE)
2447 if (type_check (status, 2, BT_INTEGER) == FAILURE
2448 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2451 if (scalar_check (status, 2) == FAILURE)
2459 gfc_check_ftell (gfc_expr * unit)
2461 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2464 if (scalar_check (unit, 0) == FAILURE)
2472 gfc_check_ftell_sub (gfc_expr * unit, gfc_expr * offset)
2474 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2477 if (scalar_check (unit, 0) == FAILURE)
2480 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2483 if (scalar_check (offset, 1) == FAILURE)
2491 gfc_check_stat (gfc_expr * name, gfc_expr * array)
2493 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2496 if (type_check (array, 1, BT_INTEGER) == FAILURE
2497 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2500 if (array_check (array, 1) == FAILURE)
2508 gfc_check_stat_sub (gfc_expr * name, gfc_expr * array, gfc_expr * status)
2510 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2513 if (type_check (array, 1, BT_INTEGER) == FAILURE
2514 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2517 if (array_check (array, 1) == FAILURE)
2523 if (type_check (status, 2, BT_INTEGER) == FAILURE
2524 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2527 if (scalar_check (status, 2) == FAILURE)
2535 gfc_check_transfer (gfc_expr * source ATTRIBUTE_UNUSED,
2536 gfc_expr * mold ATTRIBUTE_UNUSED,
2541 if (type_check (size, 2, BT_INTEGER) == FAILURE)
2544 if (scalar_check (size, 2) == FAILURE)
2547 if (nonoptional_check (size, 2) == FAILURE)
2556 gfc_check_transpose (gfc_expr * matrix)
2558 if (rank_check (matrix, 0, 2) == FAILURE)
2562 return non_init_transformational ();
2569 gfc_check_ubound (gfc_expr * array, gfc_expr * dim)
2571 if (array_check (array, 0) == FAILURE)
2576 if (dim_check (dim, 1, 1) == FAILURE)
2579 if (dim_rank_check (dim, array, 0) == FAILURE)
2588 gfc_check_unpack (gfc_expr * vector, gfc_expr * mask, gfc_expr * field)
2590 if (rank_check (vector, 0, 1) == FAILURE)
2593 if (array_check (mask, 1) == FAILURE)
2596 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2599 if (same_type_check (vector, 0, field, 2) == FAILURE)
2603 return non_init_transformational ();
2610 gfc_check_verify (gfc_expr * x, gfc_expr * y, gfc_expr * z)
2612 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2615 if (same_type_check (x, 0, y, 1) == FAILURE)
2618 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2626 gfc_check_trim (gfc_expr * x)
2628 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2631 if (scalar_check (x, 0) == FAILURE)
2639 gfc_check_ttynam (gfc_expr * unit)
2641 if (scalar_check (unit, 0) == FAILURE)
2644 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2651 /* Common check function for the half a dozen intrinsics that have a
2652 single real argument. */
2655 gfc_check_x (gfc_expr * x)
2657 if (type_check (x, 0, BT_REAL) == FAILURE)
2664 /************* Check functions for intrinsic subroutines *************/
2667 gfc_check_cpu_time (gfc_expr * time)
2669 if (scalar_check (time, 0) == FAILURE)
2672 if (type_check (time, 0, BT_REAL) == FAILURE)
2675 if (variable_check (time, 0) == FAILURE)
2683 gfc_check_date_and_time (gfc_expr * date, gfc_expr * time,
2684 gfc_expr * zone, gfc_expr * values)
2688 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2690 if (scalar_check (date, 0) == FAILURE)
2692 if (variable_check (date, 0) == FAILURE)
2698 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
2700 if (scalar_check (time, 1) == FAILURE)
2702 if (variable_check (time, 1) == FAILURE)
2708 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
2710 if (scalar_check (zone, 2) == FAILURE)
2712 if (variable_check (zone, 2) == FAILURE)
2718 if (type_check (values, 3, BT_INTEGER) == FAILURE)
2720 if (array_check (values, 3) == FAILURE)
2722 if (rank_check (values, 3, 1) == FAILURE)
2724 if (variable_check (values, 3) == FAILURE)
2733 gfc_check_mvbits (gfc_expr * from, gfc_expr * frompos, gfc_expr * len,
2734 gfc_expr * to, gfc_expr * topos)
2736 if (type_check (from, 0, BT_INTEGER) == FAILURE)
2739 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
2742 if (type_check (len, 2, BT_INTEGER) == FAILURE)
2745 if (same_type_check (from, 0, to, 3) == FAILURE)
2748 if (variable_check (to, 3) == FAILURE)
2751 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
2759 gfc_check_random_number (gfc_expr * harvest)
2761 if (type_check (harvest, 0, BT_REAL) == FAILURE)
2764 if (variable_check (harvest, 0) == FAILURE)
2772 gfc_check_random_seed (gfc_expr * size, gfc_expr * put, gfc_expr * get)
2776 if (scalar_check (size, 0) == FAILURE)
2779 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2782 if (variable_check (size, 0) == FAILURE)
2785 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
2793 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2796 if (array_check (put, 1) == FAILURE)
2799 if (rank_check (put, 1, 1) == FAILURE)
2802 if (type_check (put, 1, BT_INTEGER) == FAILURE)
2805 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
2812 if (size != NULL || put != NULL)
2813 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2816 if (array_check (get, 2) == FAILURE)
2819 if (rank_check (get, 2, 1) == FAILURE)
2822 if (type_check (get, 2, BT_INTEGER) == FAILURE)
2825 if (variable_check (get, 2) == FAILURE)
2828 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
2836 gfc_check_second_sub (gfc_expr * time)
2838 if (scalar_check (time, 0) == FAILURE)
2841 if (type_check (time, 0, BT_REAL) == FAILURE)
2844 if (kind_value_check(time, 0, 4) == FAILURE)
2851 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2852 count, count_rate, and count_max are all optional arguments */
2855 gfc_check_system_clock (gfc_expr * count, gfc_expr * count_rate,
2856 gfc_expr * count_max)
2860 if (scalar_check (count, 0) == FAILURE)
2863 if (type_check (count, 0, BT_INTEGER) == FAILURE)
2866 if (variable_check (count, 0) == FAILURE)
2870 if (count_rate != NULL)
2872 if (scalar_check (count_rate, 1) == FAILURE)
2875 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
2878 if (variable_check (count_rate, 1) == FAILURE)
2882 && same_type_check (count, 0, count_rate, 1) == FAILURE)
2887 if (count_max != NULL)
2889 if (scalar_check (count_max, 2) == FAILURE)
2892 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
2895 if (variable_check (count_max, 2) == FAILURE)
2899 && same_type_check (count, 0, count_max, 2) == FAILURE)
2902 if (count_rate != NULL
2903 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
2911 gfc_check_irand (gfc_expr * x)
2916 if (scalar_check (x, 0) == FAILURE)
2919 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2922 if (kind_value_check(x, 0, 4) == FAILURE)
2930 gfc_check_alarm_sub (gfc_expr * seconds, gfc_expr * handler, gfc_expr * status)
2932 if (scalar_check (seconds, 0) == FAILURE)
2935 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2938 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
2941 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
2942 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
2946 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
2952 if (scalar_check (status, 2) == FAILURE)
2955 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2963 gfc_check_rand (gfc_expr * x)
2968 if (scalar_check (x, 0) == FAILURE)
2971 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2974 if (kind_value_check(x, 0, 4) == FAILURE)
2981 gfc_check_srand (gfc_expr * x)
2983 if (scalar_check (x, 0) == FAILURE)
2986 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2989 if (kind_value_check(x, 0, 4) == FAILURE)
2996 gfc_check_ctime_sub (gfc_expr * time, gfc_expr * result)
2998 if (scalar_check (time, 0) == FAILURE)
3001 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3004 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
3011 gfc_check_etime (gfc_expr * x)
3013 if (array_check (x, 0) == FAILURE)
3016 if (rank_check (x, 0, 1) == FAILURE)
3019 if (variable_check (x, 0) == FAILURE)
3022 if (type_check (x, 0, BT_REAL) == FAILURE)
3025 if (kind_value_check(x, 0, 4) == FAILURE)
3032 gfc_check_etime_sub (gfc_expr * values, gfc_expr * time)
3034 if (array_check (values, 0) == FAILURE)
3037 if (rank_check (values, 0, 1) == FAILURE)
3040 if (variable_check (values, 0) == FAILURE)
3043 if (type_check (values, 0, BT_REAL) == FAILURE)
3046 if (kind_value_check(values, 0, 4) == FAILURE)
3049 if (scalar_check (time, 1) == FAILURE)
3052 if (type_check (time, 1, BT_REAL) == FAILURE)
3055 if (kind_value_check(time, 1, 4) == FAILURE)
3063 gfc_check_fdate_sub (gfc_expr * date)
3065 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3073 gfc_check_gerror (gfc_expr * msg)
3075 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3083 gfc_check_getcwd_sub (gfc_expr * cwd, gfc_expr * status)
3085 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
3091 if (scalar_check (status, 1) == FAILURE)
3094 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3102 gfc_check_getlog (gfc_expr * msg)
3104 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3112 gfc_check_exit (gfc_expr * status)
3117 if (type_check (status, 0, BT_INTEGER) == FAILURE)
3120 if (scalar_check (status, 0) == FAILURE)
3128 gfc_check_flush (gfc_expr * unit)
3133 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3136 if (scalar_check (unit, 0) == FAILURE)
3144 gfc_check_free (gfc_expr * i)
3146 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3149 if (scalar_check (i, 0) == FAILURE)
3157 gfc_check_hostnm (gfc_expr * name)
3159 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3167 gfc_check_hostnm_sub (gfc_expr * name, gfc_expr * status)
3169 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3175 if (scalar_check (status, 1) == FAILURE)
3178 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3186 gfc_check_itime_idate (gfc_expr * values)
3188 if (array_check (values, 0) == FAILURE)
3191 if (rank_check (values, 0, 1) == FAILURE)
3194 if (variable_check (values, 0) == FAILURE)
3197 if (type_check (values, 0, BT_INTEGER) == FAILURE)
3200 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
3208 gfc_check_ltime_gmtime (gfc_expr * time, gfc_expr * values)
3210 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3213 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
3216 if (scalar_check (time, 0) == FAILURE)
3219 if (array_check (values, 1) == FAILURE)
3222 if (rank_check (values, 1, 1) == FAILURE)
3225 if (variable_check (values, 1) == FAILURE)
3228 if (type_check (values, 1, BT_INTEGER) == FAILURE)
3231 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
3239 gfc_check_ttynam_sub (gfc_expr * unit, gfc_expr * name)
3241 if (scalar_check (unit, 0) == FAILURE)
3244 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3247 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
3255 gfc_check_isatty (gfc_expr * unit)
3260 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3263 if (scalar_check (unit, 0) == FAILURE)
3271 gfc_check_perror (gfc_expr * string)
3273 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
3281 gfc_check_umask (gfc_expr * mask)
3283 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3286 if (scalar_check (mask, 0) == FAILURE)
3294 gfc_check_umask_sub (gfc_expr * mask, gfc_expr * old)
3296 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3299 if (scalar_check (mask, 0) == FAILURE)
3305 if (scalar_check (old, 1) == FAILURE)
3308 if (type_check (old, 1, BT_INTEGER) == FAILURE)
3316 gfc_check_unlink (gfc_expr * name)
3318 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3326 gfc_check_unlink_sub (gfc_expr * name, gfc_expr * status)
3328 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3334 if (scalar_check (status, 1) == FAILURE)
3337 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3345 gfc_check_signal (gfc_expr * number, gfc_expr * handler)
3347 if (scalar_check (number, 0) == FAILURE)
3350 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3353 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3356 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
3357 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
3361 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3369 gfc_check_signal_sub (gfc_expr * number, gfc_expr * handler, gfc_expr * status)
3371 if (scalar_check (number, 0) == FAILURE)
3374 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3377 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3380 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
3381 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
3385 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3391 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3394 if (scalar_check (status, 2) == FAILURE)
3402 gfc_check_system_sub (gfc_expr * cmd, gfc_expr * status)
3404 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
3407 if (scalar_check (status, 1) == FAILURE)
3410 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3413 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
3420 /* This is used for the GNU intrinsics AND, OR and XOR. */
3422 gfc_check_and (gfc_expr * i, gfc_expr * j)
3424 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
3427 "'%s' argument of '%s' intrinsic at %L must be INTEGER or LOGICAL",
3428 gfc_current_intrinsic_arg[0], gfc_current_intrinsic, &i->where);
3432 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
3435 "'%s' argument of '%s' intrinsic at %L must be INTEGER or LOGICAL",
3436 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &j->where);
3440 if (i->ts.type != j->ts.type)
3442 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
3443 "have the same type", gfc_current_intrinsic_arg[0],
3444 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3449 if (scalar_check (i, 0) == FAILURE)
3452 if (scalar_check (j, 1) == FAILURE)