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_all_any (gfc_expr * mask, gfc_expr * dim)
448 if (logical_array_check (mask, 0) == FAILURE)
451 if (dim_check (dim, 1, 1) == FAILURE)
455 return non_init_transformational ();
462 gfc_check_allocated (gfc_expr * array)
464 if (variable_check (array, 0) == FAILURE)
467 if (array_check (array, 0) == FAILURE)
470 if (!array->symtree->n.sym->attr.allocatable)
472 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
473 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
482 /* Common check function where the first argument must be real or
483 integer and the second argument must be the same as the first. */
486 gfc_check_a_p (gfc_expr * a, gfc_expr * p)
488 if (int_or_real_check (a, 0) == FAILURE)
491 if (a->ts.type != p->ts.type)
493 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
494 "have the same type", gfc_current_intrinsic_arg[0],
495 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
500 if (a->ts.kind != p->ts.kind)
502 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
503 &p->where) == FAILURE)
512 gfc_check_associated (gfc_expr * pointer, gfc_expr * target)
514 symbol_attribute attr;
519 where = &pointer->where;
521 if (pointer->expr_type == EXPR_VARIABLE)
522 attr = gfc_variable_attr (pointer, NULL);
523 else if (pointer->expr_type == EXPR_FUNCTION)
524 attr = pointer->symtree->n.sym->attr;
525 else if (pointer->expr_type == EXPR_NULL)
528 gcc_assert (0); /* Pointer must be a variable or a function. */
532 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
533 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
538 /* Target argument is optional. */
542 where = &target->where;
543 if (target->expr_type == EXPR_NULL)
546 if (target->expr_type == EXPR_VARIABLE)
547 attr = gfc_variable_attr (target, NULL);
548 else if (target->expr_type == EXPR_FUNCTION)
549 attr = target->symtree->n.sym->attr;
552 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
553 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg[1],
554 gfc_current_intrinsic, &target->where);
558 if (!attr.pointer && !attr.target)
560 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
561 "or a TARGET", gfc_current_intrinsic_arg[1],
562 gfc_current_intrinsic, &target->where);
567 if (same_type_check (pointer, 0, target, 1) == FAILURE)
569 if (rank_check (target, 0, pointer->rank) == FAILURE)
571 if (target->rank > 0)
573 for (i = 0; i < target->rank; i++)
574 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
576 gfc_error ("Array section with a vector subscript at %L shall not "
577 "be the target of a pointer",
587 gfc_error ("NULL pointer at %L is not permitted as actual argument "
588 "of '%s' intrinsic function", where, gfc_current_intrinsic);
595 gfc_check_atan2 (gfc_expr * y, gfc_expr * x)
597 if (type_check (y, 0, BT_REAL) == FAILURE)
599 if (same_type_check (y, 0, x, 1) == FAILURE)
606 /* BESJN and BESYN functions. */
609 gfc_check_besn (gfc_expr * n, gfc_expr * x)
611 if (scalar_check (n, 0) == FAILURE)
614 if (type_check (n, 0, BT_INTEGER) == FAILURE)
617 if (scalar_check (x, 1) == FAILURE)
620 if (type_check (x, 1, BT_REAL) == FAILURE)
628 gfc_check_btest (gfc_expr * i, gfc_expr * pos)
630 if (type_check (i, 0, BT_INTEGER) == FAILURE)
632 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
640 gfc_check_char (gfc_expr * i, gfc_expr * kind)
642 if (type_check (i, 0, BT_INTEGER) == FAILURE)
644 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
652 gfc_check_chdir (gfc_expr * dir)
654 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
662 gfc_check_chdir_sub (gfc_expr * dir, gfc_expr * status)
664 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
670 if (type_check (status, 1, BT_INTEGER) == FAILURE)
673 if (scalar_check (status, 1) == FAILURE)
681 gfc_check_cmplx (gfc_expr * x, gfc_expr * y, gfc_expr * kind)
683 if (numeric_check (x, 0) == FAILURE)
688 if (numeric_check (y, 1) == FAILURE)
691 if (x->ts.type == BT_COMPLEX)
693 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
694 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
695 gfc_current_intrinsic, &y->where);
700 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
708 gfc_check_complex (gfc_expr * x, gfc_expr * y)
710 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
713 "'%s' argument of '%s' intrinsic at %L must be INTEGER or REAL",
714 gfc_current_intrinsic_arg[0], gfc_current_intrinsic, &x->where);
717 if (scalar_check (x, 0) == FAILURE)
720 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
723 "'%s' argument of '%s' intrinsic at %L must be INTEGER or REAL",
724 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &y->where);
727 if (scalar_check (y, 1) == FAILURE)
735 gfc_check_count (gfc_expr * mask, gfc_expr * dim)
737 if (logical_array_check (mask, 0) == FAILURE)
739 if (dim_check (dim, 1, 1) == FAILURE)
743 return non_init_transformational ();
750 gfc_check_cshift (gfc_expr * array, gfc_expr * shift, gfc_expr * dim)
752 if (array_check (array, 0) == FAILURE)
755 if (array->rank == 1)
757 if (scalar_check (shift, 1) == FAILURE)
762 /* TODO: more requirements on shift parameter. */
765 if (dim_check (dim, 2, 1) == FAILURE)
769 return non_init_transformational ();
776 gfc_check_ctime (gfc_expr * time)
778 if (scalar_check (time, 0) == FAILURE)
781 if (type_check (time, 0, BT_INTEGER) == FAILURE)
789 gfc_check_dcmplx (gfc_expr * x, gfc_expr * y)
791 if (numeric_check (x, 0) == FAILURE)
796 if (numeric_check (y, 1) == FAILURE)
799 if (x->ts.type == BT_COMPLEX)
801 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
802 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
803 gfc_current_intrinsic, &y->where);
813 gfc_check_dble (gfc_expr * x)
815 if (numeric_check (x, 0) == FAILURE)
823 gfc_check_digits (gfc_expr * x)
825 if (int_or_real_check (x, 0) == FAILURE)
833 gfc_check_dot_product (gfc_expr * vector_a, gfc_expr * vector_b)
835 switch (vector_a->ts.type)
838 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
845 if (numeric_check (vector_b, 1) == FAILURE)
850 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
851 "or LOGICAL", gfc_current_intrinsic_arg[0],
852 gfc_current_intrinsic, &vector_a->where);
856 if (rank_check (vector_a, 0, 1) == FAILURE)
859 if (rank_check (vector_b, 1, 1) == FAILURE)
862 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
864 gfc_error ("different shape for arguments '%s' and '%s' "
865 "at %L for intrinsic 'dot_product'",
866 gfc_current_intrinsic_arg[0],
867 gfc_current_intrinsic_arg[1],
873 return non_init_transformational ();
880 gfc_check_eoshift (gfc_expr * array, gfc_expr * shift, gfc_expr * boundary,
883 if (array_check (array, 0) == FAILURE)
886 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
889 if (array->rank == 1)
891 if (scalar_check (shift, 2) == FAILURE)
896 /* TODO: more weird restrictions on shift. */
899 if (boundary != NULL)
901 if (same_type_check (array, 0, boundary, 2) == FAILURE)
904 /* TODO: more restrictions on boundary. */
907 if (dim_check (dim, 1, 1) == FAILURE)
911 return non_init_transformational ();
917 /* A single complex argument. */
920 gfc_check_fn_c (gfc_expr * a)
922 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
929 /* A single real argument. */
932 gfc_check_fn_r (gfc_expr * a)
934 if (type_check (a, 0, BT_REAL) == FAILURE)
941 /* A single real or complex argument. */
944 gfc_check_fn_rc (gfc_expr * a)
946 if (real_or_complex_check (a, 0) == FAILURE)
954 gfc_check_fnum (gfc_expr * unit)
956 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
959 if (scalar_check (unit, 0) == FAILURE)
966 /* This is used for the g77 one-argument Bessel functions, and the
970 gfc_check_g77_math1 (gfc_expr * x)
972 if (scalar_check (x, 0) == FAILURE)
975 if (type_check (x, 0, BT_REAL) == FAILURE)
983 gfc_check_huge (gfc_expr * x)
985 if (int_or_real_check (x, 0) == FAILURE)
992 /* Check that the single argument is an integer. */
995 gfc_check_i (gfc_expr * i)
997 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1005 gfc_check_iand (gfc_expr * i, gfc_expr * j)
1007 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1010 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1013 if (i->ts.kind != j->ts.kind)
1015 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1016 &i->where) == FAILURE)
1025 gfc_check_ibclr (gfc_expr * i, gfc_expr * pos)
1027 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1030 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1038 gfc_check_ibits (gfc_expr * i, gfc_expr * pos, gfc_expr * len)
1040 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1043 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1046 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1054 gfc_check_ibset (gfc_expr * i, gfc_expr * pos)
1056 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1059 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1067 gfc_check_ichar_iachar (gfc_expr * c)
1071 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1074 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1080 /* Substring references don't have the charlength set. */
1082 while (ref && ref->type != REF_SUBSTRING)
1085 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1089 /* Check that the argument is length one. Non-constant lengths
1090 can't be checked here, so assume they are ok. */
1091 if (c->ts.cl && c->ts.cl->length)
1093 /* If we already have a length for this expression then use it. */
1094 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
1096 i = mpz_get_si (c->ts.cl->length->value.integer);
1103 start = ref->u.ss.start;
1104 end = ref->u.ss.end;
1107 if (end == NULL || end->expr_type != EXPR_CONSTANT
1108 || start->expr_type != EXPR_CONSTANT)
1111 i = mpz_get_si (end->value.integer) + 1
1112 - mpz_get_si (start->value.integer);
1120 gfc_error ("Argument of %s at %L must be of length one",
1121 gfc_current_intrinsic, &c->where);
1130 gfc_check_idnint (gfc_expr * a)
1132 if (double_check (a, 0) == FAILURE)
1140 gfc_check_ieor (gfc_expr * i, gfc_expr * j)
1142 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1145 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1148 if (i->ts.kind != j->ts.kind)
1150 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1151 &i->where) == FAILURE)
1160 gfc_check_index (gfc_expr * string, gfc_expr * substring, gfc_expr * back)
1162 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1163 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1167 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1170 if (string->ts.kind != substring->ts.kind)
1172 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1173 "kind as '%s'", gfc_current_intrinsic_arg[1],
1174 gfc_current_intrinsic, &substring->where,
1175 gfc_current_intrinsic_arg[0]);
1184 gfc_check_int (gfc_expr * x, gfc_expr * kind)
1186 if (numeric_check (x, 0) == FAILURE)
1191 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
1194 if (scalar_check (kind, 1) == FAILURE)
1203 gfc_check_ior (gfc_expr * i, gfc_expr * j)
1205 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1208 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1211 if (i->ts.kind != j->ts.kind)
1213 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1214 &i->where) == FAILURE)
1223 gfc_check_ishft (gfc_expr * i, gfc_expr * shift)
1225 if (type_check (i, 0, BT_INTEGER) == FAILURE
1226 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1234 gfc_check_ishftc (gfc_expr * i, gfc_expr * shift, gfc_expr * size)
1236 if (type_check (i, 0, BT_INTEGER) == FAILURE
1237 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1240 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1248 gfc_check_kill (gfc_expr * pid, gfc_expr * sig)
1250 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1253 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1261 gfc_check_kill_sub (gfc_expr * pid, gfc_expr * sig, gfc_expr * status)
1263 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1266 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1272 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1275 if (scalar_check (status, 2) == FAILURE)
1283 gfc_check_kind (gfc_expr * x)
1285 if (x->ts.type == BT_DERIVED)
1287 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1288 "non-derived type", gfc_current_intrinsic_arg[0],
1289 gfc_current_intrinsic, &x->where);
1298 gfc_check_lbound (gfc_expr * array, gfc_expr * dim)
1300 if (array_check (array, 0) == FAILURE)
1305 if (dim_check (dim, 1, 1) == FAILURE)
1308 if (dim_rank_check (dim, array, 1) == FAILURE)
1316 gfc_check_link (gfc_expr * path1, gfc_expr * path2)
1318 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1321 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1329 gfc_check_link_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
1331 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1334 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1340 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1343 if (scalar_check (status, 2) == FAILURE)
1350 gfc_check_loc (gfc_expr *expr)
1352 return variable_check (expr, 0);
1357 gfc_check_symlnk (gfc_expr * path1, gfc_expr * path2)
1359 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1362 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1370 gfc_check_symlnk_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
1372 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1375 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1381 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1384 if (scalar_check (status, 2) == FAILURE)
1392 gfc_check_logical (gfc_expr * a, gfc_expr * kind)
1394 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1396 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1403 /* Min/max family. */
1406 min_max_args (gfc_actual_arglist * arg)
1408 if (arg == NULL || arg->next == NULL)
1410 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1411 gfc_current_intrinsic, gfc_current_intrinsic_where);
1420 check_rest (bt type, int kind, gfc_actual_arglist * arg)
1425 if (min_max_args (arg) == FAILURE)
1430 for (; arg; arg = arg->next, n++)
1433 if (x->ts.type != type || x->ts.kind != kind)
1435 if (x->ts.type == type)
1437 if (gfc_notify_std (GFC_STD_GNU,
1438 "Extension: Different type kinds at %L", &x->where)
1444 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be %s(%d)",
1445 n, gfc_current_intrinsic, &x->where,
1446 gfc_basic_typename (type), kind);
1457 gfc_check_min_max (gfc_actual_arglist * arg)
1461 if (min_max_args (arg) == FAILURE)
1466 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1469 ("'a1' argument of '%s' intrinsic at %L must be INTEGER or REAL",
1470 gfc_current_intrinsic, &x->where);
1474 return check_rest (x->ts.type, x->ts.kind, arg);
1479 gfc_check_min_max_integer (gfc_actual_arglist * arg)
1481 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1486 gfc_check_min_max_real (gfc_actual_arglist * arg)
1488 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1493 gfc_check_min_max_double (gfc_actual_arglist * arg)
1495 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1498 /* End of min/max family. */
1501 gfc_check_malloc (gfc_expr * size)
1503 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1506 if (scalar_check (size, 0) == FAILURE)
1514 gfc_check_matmul (gfc_expr * matrix_a, gfc_expr * matrix_b)
1516 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1518 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1519 "or LOGICAL", gfc_current_intrinsic_arg[0],
1520 gfc_current_intrinsic, &matrix_a->where);
1524 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1526 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1527 "or LOGICAL", gfc_current_intrinsic_arg[1],
1528 gfc_current_intrinsic, &matrix_b->where);
1532 switch (matrix_a->rank)
1535 if (rank_check (matrix_b, 1, 2) == FAILURE)
1537 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
1538 if (! identical_dimen_shape (matrix_a, 0, matrix_b, 0))
1540 gfc_error ("different shape on dimension 1 for arguments '%s' "
1541 "and '%s' at %L for intrinsic matmul",
1542 gfc_current_intrinsic_arg[0],
1543 gfc_current_intrinsic_arg[1],
1550 if (matrix_b->rank != 2)
1552 if (rank_check (matrix_b, 1, 1) == FAILURE)
1555 /* matrix_b has rank 1 or 2 here. Common check for the cases
1556 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
1557 - matrix_a has shape (n,m) and matrix_b has shape (m). */
1558 if (! identical_dimen_shape (matrix_a, 1, matrix_b, 0))
1560 gfc_error ("different shape on dimension 2 for argument '%s' and "
1561 "dimension 1 for argument '%s' at %L for intrinsic "
1562 "matmul", gfc_current_intrinsic_arg[0],
1563 gfc_current_intrinsic_arg[1], &matrix_a->where);
1569 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1570 "1 or 2", gfc_current_intrinsic_arg[0],
1571 gfc_current_intrinsic, &matrix_a->where);
1576 return non_init_transformational ();
1582 /* Whoever came up with this interface was probably on something.
1583 The possibilities for the occupation of the second and third
1590 NULL MASK minloc(array, mask=m)
1593 I.e. in the case of minloc(array,mask), mask will be in the second
1594 position of the argument list and we'll have to fix that up. */
1597 gfc_check_minloc_maxloc (gfc_actual_arglist * ap)
1599 gfc_expr *a, *m, *d;
1602 if (int_or_real_check (a, 0) == FAILURE
1603 || array_check (a, 0) == FAILURE)
1607 m = ap->next->next->expr;
1609 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1610 && ap->next->name == NULL)
1615 ap->next->expr = NULL;
1616 ap->next->next->expr = m;
1619 if (dim_check (d, 1, 1) == FAILURE)
1622 if (d && dim_rank_check (d, a, 0) == FAILURE)
1625 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1631 snprintf(buffer, sizeof(buffer), "arguments '%s' and '%s' for intrinsic %s",
1632 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1633 gfc_current_intrinsic);
1634 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1639 return non_init_transformational ();
1645 /* Similar to minloc/maxloc, the argument list might need to be
1646 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1647 difference is that MINLOC/MAXLOC take an additional KIND argument.
1648 The possibilities are:
1654 NULL MASK minval(array, mask=m)
1657 I.e. in the case of minval(array,mask), mask will be in the second
1658 position of the argument list and we'll have to fix that up. */
1661 check_reduction (gfc_actual_arglist * ap)
1663 gfc_expr *a, *m, *d;
1667 m = ap->next->next->expr;
1669 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1670 && ap->next->name == NULL)
1675 ap->next->expr = NULL;
1676 ap->next->next->expr = m;
1679 if (dim_check (d, 1, 1) == FAILURE)
1682 if (d && dim_rank_check (d, a, 0) == FAILURE)
1685 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1691 snprintf(buffer, sizeof(buffer), "arguments '%s' and '%s' for intrinsic %s",
1692 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1693 gfc_current_intrinsic);
1694 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1703 gfc_check_minval_maxval (gfc_actual_arglist * ap)
1705 if (int_or_real_check (ap->expr, 0) == FAILURE
1706 || array_check (ap->expr, 0) == FAILURE)
1710 return non_init_transformational ();
1712 return check_reduction (ap);
1717 gfc_check_product_sum (gfc_actual_arglist * ap)
1719 if (numeric_check (ap->expr, 0) == FAILURE
1720 || array_check (ap->expr, 0) == FAILURE)
1724 return non_init_transformational ();
1726 return check_reduction (ap);
1731 gfc_check_merge (gfc_expr * tsource, gfc_expr * fsource, gfc_expr * mask)
1735 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
1738 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
1741 snprintf(buffer, sizeof(buffer), "arguments '%s' and '%s' for intrinsic '%s'",
1742 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1743 gfc_current_intrinsic);
1744 if (gfc_check_conformance (buffer, tsource, fsource) == FAILURE)
1747 snprintf(buffer, sizeof(buffer), "arguments '%s' and '%s' for intrinsic '%s'",
1748 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1749 gfc_current_intrinsic);
1750 if (gfc_check_conformance (buffer, tsource, mask) == FAILURE)
1758 gfc_check_nearest (gfc_expr * x, gfc_expr * s)
1760 if (type_check (x, 0, BT_REAL) == FAILURE)
1763 if (type_check (s, 1, BT_REAL) == FAILURE)
1771 gfc_check_null (gfc_expr * mold)
1773 symbol_attribute attr;
1778 if (variable_check (mold, 0) == FAILURE)
1781 attr = gfc_variable_attr (mold, NULL);
1785 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
1786 gfc_current_intrinsic_arg[0],
1787 gfc_current_intrinsic, &mold->where);
1796 gfc_check_pack (gfc_expr * array, gfc_expr * mask, gfc_expr * vector)
1800 if (array_check (array, 0) == FAILURE)
1803 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1806 snprintf(buffer, sizeof(buffer), "arguments '%s' and '%s' for intrinsic '%s'",
1807 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1808 gfc_current_intrinsic);
1809 if (gfc_check_conformance (buffer, array, mask) == FAILURE)
1814 if (same_type_check (array, 0, vector, 2) == FAILURE)
1817 if (rank_check (vector, 2, 1) == FAILURE)
1820 /* TODO: More constraints here. */
1824 return non_init_transformational ();
1831 gfc_check_precision (gfc_expr * x)
1833 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
1835 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
1836 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
1837 gfc_current_intrinsic, &x->where);
1846 gfc_check_present (gfc_expr * a)
1850 if (variable_check (a, 0) == FAILURE)
1853 sym = a->symtree->n.sym;
1854 if (!sym->attr.dummy)
1856 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
1857 "dummy variable", gfc_current_intrinsic_arg[0],
1858 gfc_current_intrinsic, &a->where);
1862 if (!sym->attr.optional)
1864 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
1865 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
1866 gfc_current_intrinsic, &a->where);
1870 /* 13.14.82 PRESENT(A)
1872 Argument. A shall be the name of an optional dummy argument that is accessible
1873 in the subprogram in which the PRESENT function reference appears... */
1876 && !(a->ref->next == NULL
1877 && a->ref->type == REF_ARRAY
1878 && a->ref->u.ar.type == AR_FULL))
1880 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a sub-"
1881 "object of '%s'", gfc_current_intrinsic_arg[0],
1882 gfc_current_intrinsic, &a->where, sym->name);
1891 gfc_check_radix (gfc_expr * x)
1893 if (int_or_real_check (x, 0) == FAILURE)
1901 gfc_check_range (gfc_expr * x)
1903 if (numeric_check (x, 0) == FAILURE)
1910 /* real, float, sngl. */
1912 gfc_check_real (gfc_expr * a, gfc_expr * kind)
1914 if (numeric_check (a, 0) == FAILURE)
1917 if (kind_check (kind, 1, BT_REAL) == FAILURE)
1925 gfc_check_rename (gfc_expr * path1, gfc_expr * path2)
1927 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1930 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1938 gfc_check_rename_sub (gfc_expr * path1, gfc_expr * path2, gfc_expr * status)
1940 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1943 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1949 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1952 if (scalar_check (status, 2) == FAILURE)
1960 gfc_check_repeat (gfc_expr * x, gfc_expr * y)
1962 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
1965 if (scalar_check (x, 0) == FAILURE)
1968 if (type_check (y, 0, BT_INTEGER) == FAILURE)
1971 if (scalar_check (y, 1) == FAILURE)
1979 gfc_check_reshape (gfc_expr * source, gfc_expr * shape,
1980 gfc_expr * pad, gfc_expr * order)
1985 if (array_check (source, 0) == FAILURE)
1988 if (rank_check (shape, 1, 1) == FAILURE)
1991 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
1994 if (gfc_array_size (shape, &size) != SUCCESS)
1996 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
1997 "array of constant size", &shape->where);
2001 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
2006 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2007 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2013 if (same_type_check (source, 0, pad, 2) == FAILURE)
2015 if (array_check (pad, 2) == FAILURE)
2019 if (order != NULL && array_check (order, 3) == FAILURE)
2027 gfc_check_scale (gfc_expr * x, gfc_expr * i)
2029 if (type_check (x, 0, BT_REAL) == FAILURE)
2032 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2040 gfc_check_scan (gfc_expr * x, gfc_expr * y, gfc_expr * z)
2042 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2045 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2048 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2051 if (same_type_check (x, 0, y, 1) == FAILURE)
2059 gfc_check_secnds (gfc_expr * r)
2062 if (type_check (r, 0, BT_REAL) == FAILURE)
2065 if (kind_value_check (r, 0, 4) == FAILURE)
2068 if (scalar_check (r, 0) == FAILURE)
2076 gfc_check_selected_int_kind (gfc_expr * r)
2079 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2082 if (scalar_check (r, 0) == FAILURE)
2090 gfc_check_selected_real_kind (gfc_expr * p, gfc_expr * r)
2092 if (p == NULL && r == NULL)
2094 gfc_error ("Missing arguments to %s intrinsic at %L",
2095 gfc_current_intrinsic, gfc_current_intrinsic_where);
2100 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
2103 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
2111 gfc_check_set_exponent (gfc_expr * x, gfc_expr * i)
2113 if (type_check (x, 0, BT_REAL) == FAILURE)
2116 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2124 gfc_check_shape (gfc_expr * source)
2128 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2131 ar = gfc_find_array_ref (source);
2133 if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
2135 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2136 "an assumed size array", &source->where);
2145 gfc_check_sign (gfc_expr * a, gfc_expr * b)
2147 if (int_or_real_check (a, 0) == FAILURE)
2150 if (same_type_check (a, 0, b, 1) == FAILURE)
2158 gfc_check_size (gfc_expr * array, gfc_expr * dim)
2160 if (array_check (array, 0) == FAILURE)
2165 if (type_check (dim, 1, BT_INTEGER) == FAILURE)
2168 if (kind_value_check (dim, 1, gfc_default_integer_kind) == FAILURE)
2171 if (dim_rank_check (dim, array, 0) == FAILURE)
2180 gfc_check_sleep_sub (gfc_expr * seconds)
2182 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2185 if (scalar_check (seconds, 0) == FAILURE)
2193 gfc_check_spread (gfc_expr * source, gfc_expr * dim, gfc_expr * ncopies)
2195 if (source->rank >= GFC_MAX_DIMENSIONS)
2197 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2198 "than rank %d", gfc_current_intrinsic_arg[0],
2199 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2204 if (dim_check (dim, 1, 0) == FAILURE)
2207 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2210 if (scalar_check (ncopies, 2) == FAILURE)
2214 return non_init_transformational ();
2220 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2223 gfc_check_fgetputc_sub (gfc_expr * unit, gfc_expr * c, gfc_expr * status)
2225 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2228 if (scalar_check (unit, 0) == FAILURE)
2231 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2237 if (type_check (status, 2, BT_INTEGER) == FAILURE
2238 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2239 || scalar_check (status, 2) == FAILURE)
2247 gfc_check_fgetputc (gfc_expr * unit, gfc_expr * c)
2249 return gfc_check_fgetputc_sub (unit, c, NULL);
2254 gfc_check_fgetput_sub (gfc_expr * c, gfc_expr * status)
2256 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2262 if (type_check (status, 1, BT_INTEGER) == FAILURE
2263 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2264 || scalar_check (status, 1) == FAILURE)
2272 gfc_check_fgetput (gfc_expr * c)
2274 return gfc_check_fgetput_sub (c, NULL);
2279 gfc_check_fstat (gfc_expr * unit, gfc_expr * array)
2281 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2284 if (scalar_check (unit, 0) == FAILURE)
2287 if (type_check (array, 1, BT_INTEGER) == FAILURE
2288 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2291 if (array_check (array, 1) == FAILURE)
2299 gfc_check_fstat_sub (gfc_expr * unit, gfc_expr * array, gfc_expr * status)
2301 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2304 if (scalar_check (unit, 0) == FAILURE)
2307 if (type_check (array, 1, BT_INTEGER) == FAILURE
2308 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2311 if (array_check (array, 1) == FAILURE)
2317 if (type_check (status, 2, BT_INTEGER) == FAILURE
2318 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2321 if (scalar_check (status, 2) == FAILURE)
2329 gfc_check_ftell (gfc_expr * unit)
2331 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2334 if (scalar_check (unit, 0) == FAILURE)
2342 gfc_check_ftell_sub (gfc_expr * unit, gfc_expr * offset)
2344 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2347 if (scalar_check (unit, 0) == FAILURE)
2350 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2353 if (scalar_check (offset, 1) == FAILURE)
2361 gfc_check_stat (gfc_expr * name, gfc_expr * array)
2363 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2366 if (type_check (array, 1, BT_INTEGER) == FAILURE
2367 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2370 if (array_check (array, 1) == FAILURE)
2378 gfc_check_stat_sub (gfc_expr * name, gfc_expr * array, gfc_expr * status)
2380 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2383 if (type_check (array, 1, BT_INTEGER) == FAILURE
2384 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2387 if (array_check (array, 1) == FAILURE)
2393 if (type_check (status, 2, BT_INTEGER) == FAILURE
2394 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2397 if (scalar_check (status, 2) == FAILURE)
2405 gfc_check_transfer (gfc_expr * source ATTRIBUTE_UNUSED,
2406 gfc_expr * mold ATTRIBUTE_UNUSED,
2411 if (type_check (size, 2, BT_INTEGER) == FAILURE)
2414 if (scalar_check (size, 2) == FAILURE)
2417 if (nonoptional_check (size, 2) == FAILURE)
2426 gfc_check_transpose (gfc_expr * matrix)
2428 if (rank_check (matrix, 0, 2) == FAILURE)
2432 return non_init_transformational ();
2439 gfc_check_ubound (gfc_expr * array, gfc_expr * dim)
2441 if (array_check (array, 0) == FAILURE)
2446 if (dim_check (dim, 1, 1) == FAILURE)
2449 if (dim_rank_check (dim, array, 0) == FAILURE)
2458 gfc_check_unpack (gfc_expr * vector, gfc_expr * mask, gfc_expr * field)
2460 if (rank_check (vector, 0, 1) == FAILURE)
2463 if (array_check (mask, 1) == FAILURE)
2466 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2469 if (same_type_check (vector, 0, field, 2) == FAILURE)
2473 return non_init_transformational ();
2480 gfc_check_verify (gfc_expr * x, gfc_expr * y, gfc_expr * z)
2482 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2485 if (same_type_check (x, 0, y, 1) == FAILURE)
2488 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2496 gfc_check_trim (gfc_expr * x)
2498 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2501 if (scalar_check (x, 0) == FAILURE)
2509 gfc_check_ttynam (gfc_expr * unit)
2511 if (scalar_check (unit, 0) == FAILURE)
2514 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2521 /* Common check function for the half a dozen intrinsics that have a
2522 single real argument. */
2525 gfc_check_x (gfc_expr * x)
2527 if (type_check (x, 0, BT_REAL) == FAILURE)
2534 /************* Check functions for intrinsic subroutines *************/
2537 gfc_check_cpu_time (gfc_expr * time)
2539 if (scalar_check (time, 0) == FAILURE)
2542 if (type_check (time, 0, BT_REAL) == FAILURE)
2545 if (variable_check (time, 0) == FAILURE)
2553 gfc_check_date_and_time (gfc_expr * date, gfc_expr * time,
2554 gfc_expr * zone, gfc_expr * values)
2558 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2560 if (scalar_check (date, 0) == FAILURE)
2562 if (variable_check (date, 0) == FAILURE)
2568 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
2570 if (scalar_check (time, 1) == FAILURE)
2572 if (variable_check (time, 1) == FAILURE)
2578 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
2580 if (scalar_check (zone, 2) == FAILURE)
2582 if (variable_check (zone, 2) == FAILURE)
2588 if (type_check (values, 3, BT_INTEGER) == FAILURE)
2590 if (array_check (values, 3) == FAILURE)
2592 if (rank_check (values, 3, 1) == FAILURE)
2594 if (variable_check (values, 3) == FAILURE)
2603 gfc_check_mvbits (gfc_expr * from, gfc_expr * frompos, gfc_expr * len,
2604 gfc_expr * to, gfc_expr * topos)
2606 if (type_check (from, 0, BT_INTEGER) == FAILURE)
2609 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
2612 if (type_check (len, 2, BT_INTEGER) == FAILURE)
2615 if (same_type_check (from, 0, to, 3) == FAILURE)
2618 if (variable_check (to, 3) == FAILURE)
2621 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
2629 gfc_check_random_number (gfc_expr * harvest)
2631 if (type_check (harvest, 0, BT_REAL) == FAILURE)
2634 if (variable_check (harvest, 0) == FAILURE)
2642 gfc_check_random_seed (gfc_expr * size, gfc_expr * put, gfc_expr * get)
2646 if (scalar_check (size, 0) == FAILURE)
2649 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2652 if (variable_check (size, 0) == FAILURE)
2655 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
2663 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2666 if (array_check (put, 1) == FAILURE)
2669 if (rank_check (put, 1, 1) == FAILURE)
2672 if (type_check (put, 1, BT_INTEGER) == FAILURE)
2675 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
2682 if (size != NULL || put != NULL)
2683 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2686 if (array_check (get, 2) == FAILURE)
2689 if (rank_check (get, 2, 1) == FAILURE)
2692 if (type_check (get, 2, BT_INTEGER) == FAILURE)
2695 if (variable_check (get, 2) == FAILURE)
2698 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
2706 gfc_check_second_sub (gfc_expr * time)
2708 if (scalar_check (time, 0) == FAILURE)
2711 if (type_check (time, 0, BT_REAL) == FAILURE)
2714 if (kind_value_check(time, 0, 4) == FAILURE)
2721 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2722 count, count_rate, and count_max are all optional arguments */
2725 gfc_check_system_clock (gfc_expr * count, gfc_expr * count_rate,
2726 gfc_expr * count_max)
2730 if (scalar_check (count, 0) == FAILURE)
2733 if (type_check (count, 0, BT_INTEGER) == FAILURE)
2736 if (variable_check (count, 0) == FAILURE)
2740 if (count_rate != NULL)
2742 if (scalar_check (count_rate, 1) == FAILURE)
2745 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
2748 if (variable_check (count_rate, 1) == FAILURE)
2752 && same_type_check (count, 0, count_rate, 1) == FAILURE)
2757 if (count_max != NULL)
2759 if (scalar_check (count_max, 2) == FAILURE)
2762 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
2765 if (variable_check (count_max, 2) == FAILURE)
2769 && same_type_check (count, 0, count_max, 2) == FAILURE)
2772 if (count_rate != NULL
2773 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
2781 gfc_check_irand (gfc_expr * x)
2786 if (scalar_check (x, 0) == FAILURE)
2789 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2792 if (kind_value_check(x, 0, 4) == FAILURE)
2800 gfc_check_alarm_sub (gfc_expr * seconds, gfc_expr * handler, gfc_expr * status)
2802 if (scalar_check (seconds, 0) == FAILURE)
2805 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2808 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
2811 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
2812 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
2816 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
2822 if (scalar_check (status, 2) == FAILURE)
2825 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2833 gfc_check_rand (gfc_expr * x)
2838 if (scalar_check (x, 0) == FAILURE)
2841 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2844 if (kind_value_check(x, 0, 4) == FAILURE)
2851 gfc_check_srand (gfc_expr * x)
2853 if (scalar_check (x, 0) == FAILURE)
2856 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2859 if (kind_value_check(x, 0, 4) == FAILURE)
2866 gfc_check_ctime_sub (gfc_expr * time, gfc_expr * result)
2868 if (scalar_check (time, 0) == FAILURE)
2871 if (type_check (time, 0, BT_INTEGER) == FAILURE)
2874 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
2881 gfc_check_etime (gfc_expr * x)
2883 if (array_check (x, 0) == FAILURE)
2886 if (rank_check (x, 0, 1) == FAILURE)
2889 if (variable_check (x, 0) == FAILURE)
2892 if (type_check (x, 0, BT_REAL) == FAILURE)
2895 if (kind_value_check(x, 0, 4) == FAILURE)
2902 gfc_check_etime_sub (gfc_expr * values, gfc_expr * time)
2904 if (array_check (values, 0) == FAILURE)
2907 if (rank_check (values, 0, 1) == FAILURE)
2910 if (variable_check (values, 0) == FAILURE)
2913 if (type_check (values, 0, BT_REAL) == FAILURE)
2916 if (kind_value_check(values, 0, 4) == FAILURE)
2919 if (scalar_check (time, 1) == FAILURE)
2922 if (type_check (time, 1, BT_REAL) == FAILURE)
2925 if (kind_value_check(time, 1, 4) == FAILURE)
2933 gfc_check_fdate_sub (gfc_expr * date)
2935 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2943 gfc_check_gerror (gfc_expr * msg)
2945 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
2953 gfc_check_getcwd_sub (gfc_expr * cwd, gfc_expr * status)
2955 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
2961 if (scalar_check (status, 1) == FAILURE)
2964 if (type_check (status, 1, BT_INTEGER) == FAILURE)
2972 gfc_check_getlog (gfc_expr * msg)
2974 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
2982 gfc_check_exit (gfc_expr * status)
2987 if (type_check (status, 0, BT_INTEGER) == FAILURE)
2990 if (scalar_check (status, 0) == FAILURE)
2998 gfc_check_flush (gfc_expr * unit)
3003 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3006 if (scalar_check (unit, 0) == FAILURE)
3014 gfc_check_free (gfc_expr * i)
3016 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3019 if (scalar_check (i, 0) == FAILURE)
3027 gfc_check_hostnm (gfc_expr * name)
3029 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3037 gfc_check_hostnm_sub (gfc_expr * name, gfc_expr * status)
3039 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3045 if (scalar_check (status, 1) == FAILURE)
3048 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3056 gfc_check_itime_idate (gfc_expr * values)
3058 if (array_check (values, 0) == FAILURE)
3061 if (rank_check (values, 0, 1) == FAILURE)
3064 if (variable_check (values, 0) == FAILURE)
3067 if (type_check (values, 0, BT_INTEGER) == FAILURE)
3070 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
3078 gfc_check_ttynam_sub (gfc_expr * unit, gfc_expr * name)
3080 if (scalar_check (unit, 0) == FAILURE)
3083 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3086 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
3094 gfc_check_isatty (gfc_expr * unit)
3099 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3102 if (scalar_check (unit, 0) == FAILURE)
3110 gfc_check_perror (gfc_expr * string)
3112 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
3120 gfc_check_umask (gfc_expr * mask)
3122 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3125 if (scalar_check (mask, 0) == FAILURE)
3133 gfc_check_umask_sub (gfc_expr * mask, gfc_expr * old)
3135 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3138 if (scalar_check (mask, 0) == FAILURE)
3144 if (scalar_check (old, 1) == FAILURE)
3147 if (type_check (old, 1, BT_INTEGER) == FAILURE)
3155 gfc_check_unlink (gfc_expr * name)
3157 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3165 gfc_check_unlink_sub (gfc_expr * name, gfc_expr * status)
3167 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3173 if (scalar_check (status, 1) == FAILURE)
3176 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3184 gfc_check_signal (gfc_expr * number, gfc_expr * handler)
3186 if (scalar_check (number, 0) == FAILURE)
3189 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3192 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3195 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
3196 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
3200 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3208 gfc_check_signal_sub (gfc_expr * number, gfc_expr * handler, gfc_expr * status)
3210 if (scalar_check (number, 0) == FAILURE)
3213 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3216 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3219 "'%s' argument of '%s' intrinsic at %L must be INTEGER or PROCEDURE",
3220 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &handler->where);
3224 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3230 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3233 if (scalar_check (status, 2) == FAILURE)
3241 gfc_check_system_sub (gfc_expr * cmd, gfc_expr * status)
3243 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
3246 if (scalar_check (status, 1) == FAILURE)
3249 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3252 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
3259 /* This is used for the GNU intrinsics AND, OR and XOR. */
3261 gfc_check_and (gfc_expr * i, gfc_expr * j)
3263 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
3266 "'%s' argument of '%s' intrinsic at %L must be INTEGER or LOGICAL",
3267 gfc_current_intrinsic_arg[0], gfc_current_intrinsic, &i->where);
3271 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
3274 "'%s' argument of '%s' intrinsic at %L must be INTEGER or LOGICAL",
3275 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, &j->where);
3279 if (i->ts.type != j->ts.type)
3281 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
3282 "have the same type", gfc_current_intrinsic_arg[0],
3283 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3288 if (scalar_check (i, 0) == FAILURE)
3291 if (scalar_check (j, 1) == FAILURE)