2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught & Katherine Holcomb
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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 /* If the expression has not got a type, check if its namespace can
61 offer a default type. */
62 if ((e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_VARIABLE)
63 && e->symtree->n.sym->ts.type == BT_UNKNOWN
64 && gfc_set_default_type (e->symtree->n.sym, 0,
65 e->symtree->n.sym->ns) == SUCCESS
66 && gfc_numeric_ts (&e->symtree->n.sym->ts))
68 e->ts = e->symtree->n.sym->ts;
72 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
73 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
79 /* Check that an expression is integer or real. */
82 int_or_real_check (gfc_expr *e, int n)
84 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
86 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
87 "or REAL", gfc_current_intrinsic_arg[n],
88 gfc_current_intrinsic, &e->where);
96 /* Check that an expression is real or complex. */
99 real_or_complex_check (gfc_expr *e, int n)
101 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
103 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
104 "or COMPLEX", gfc_current_intrinsic_arg[n],
105 gfc_current_intrinsic, &e->where);
113 /* Check that the expression is an optional constant integer
114 and that it specifies a valid kind for that type. */
117 kind_check (gfc_expr *k, int n, bt type)
124 if (type_check (k, n, BT_INTEGER) == FAILURE)
127 if (k->expr_type != EXPR_CONSTANT)
129 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
130 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
135 if (gfc_extract_int (k, &kind) != NULL
136 || gfc_validate_kind (type, kind, true) < 0)
138 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
147 /* Make sure the expression is a double precision real. */
150 double_check (gfc_expr *d, int n)
152 if (type_check (d, n, BT_REAL) == FAILURE)
155 if (d->ts.kind != gfc_default_double_kind)
157 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
158 "precision", gfc_current_intrinsic_arg[n],
159 gfc_current_intrinsic, &d->where);
167 /* Make sure the expression is a logical array. */
170 logical_array_check (gfc_expr *array, int n)
172 if (array->ts.type != BT_LOGICAL || array->rank == 0)
174 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
175 "array", gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
184 /* Make sure an expression is an array. */
187 array_check (gfc_expr *e, int n)
192 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
193 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
199 /* Make sure an expression is a scalar. */
202 scalar_check (gfc_expr *e, int n)
207 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
208 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
214 /* Make sure two expressions have the same type. */
217 same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
219 if (gfc_compare_types (&e->ts, &f->ts))
222 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
223 "and kind as '%s'", gfc_current_intrinsic_arg[m],
224 gfc_current_intrinsic, &f->where, gfc_current_intrinsic_arg[n]);
230 /* Make sure that an expression has a certain (nonzero) rank. */
233 rank_check (gfc_expr *e, int n, int rank)
238 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
239 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
246 /* Make sure a variable expression is not an optional dummy argument. */
249 nonoptional_check (gfc_expr *e, int n)
251 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
253 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
254 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
258 /* TODO: Recursive check on nonoptional variables? */
264 /* Check that an expression has a particular kind. */
267 kind_value_check (gfc_expr *e, int n, int k)
272 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
273 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
280 /* Make sure an expression is a variable. */
283 variable_check (gfc_expr *e, int n)
285 if ((e->expr_type == EXPR_VARIABLE
286 && e->symtree->n.sym->attr.flavor != FL_PARAMETER)
287 || (e->expr_type == EXPR_FUNCTION
288 && e->symtree->n.sym->result == e->symtree->n.sym))
291 if (e->expr_type == EXPR_VARIABLE
292 && e->symtree->n.sym->attr.intent == INTENT_IN)
294 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
295 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
300 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
301 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
307 /* Check the common DIM parameter for correctness. */
310 dim_check (gfc_expr *dim, int n, int optional)
312 if (optional && dim == NULL)
317 gfc_error ("Missing DIM parameter in intrinsic '%s' at %L",
318 gfc_current_intrinsic, gfc_current_intrinsic_where);
322 if (type_check (dim, n, BT_INTEGER) == FAILURE)
325 if (scalar_check (dim, n) == FAILURE)
328 if (nonoptional_check (dim, n) == FAILURE)
335 /* If a DIM parameter is a constant, make sure that it is greater than
336 zero and less than or equal to the rank of the given array. If
337 allow_assumed is zero then dim must be less than the rank of the array
338 for assumed size arrays. */
341 dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
346 if (dim->expr_type != EXPR_CONSTANT || array->expr_type != EXPR_VARIABLE)
349 ar = gfc_find_array_ref (array);
351 if (ar->as->type == AS_ASSUMED_SIZE
353 && ar->type != AR_ELEMENT
354 && ar->type != AR_SECTION)
357 if (mpz_cmp_ui (dim->value.integer, 1) < 0
358 || mpz_cmp_ui (dim->value.integer, rank) > 0)
360 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
361 "dimension index", gfc_current_intrinsic, &dim->where);
370 /* Compare the size of a along dimension ai with the size of b along
371 dimension bi, returning 0 if they are known not to be identical,
372 and 1 if they are identical, or if this cannot be determined. */
375 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
377 mpz_t a_size, b_size;
380 gcc_assert (a->rank > ai);
381 gcc_assert (b->rank > bi);
385 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
387 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
389 if (mpz_cmp (a_size, b_size) != 0)
400 /***** Check functions *****/
402 /* Check subroutine suitable for intrinsics taking a real argument and
403 a kind argument for the result. */
406 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
408 if (type_check (a, 0, BT_REAL) == FAILURE)
410 if (kind_check (kind, 1, type) == FAILURE)
417 /* Check subroutine suitable for ceiling, floor and nint. */
420 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
422 return check_a_kind (a, kind, BT_INTEGER);
426 /* Check subroutine suitable for aint, anint. */
429 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
431 return check_a_kind (a, kind, BT_REAL);
436 gfc_check_abs (gfc_expr *a)
438 if (numeric_check (a, 0) == FAILURE)
446 gfc_check_achar (gfc_expr *a)
448 if (type_check (a, 0, BT_INTEGER) == FAILURE)
456 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
458 if (type_check (name, 0, BT_CHARACTER) == FAILURE
459 || scalar_check (name, 0) == FAILURE)
462 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
463 || scalar_check (mode, 1) == FAILURE)
471 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
473 if (logical_array_check (mask, 0) == FAILURE)
476 if (dim_check (dim, 1, 1) == FAILURE)
484 gfc_check_allocated (gfc_expr *array)
486 symbol_attribute attr;
488 if (variable_check (array, 0) == FAILURE)
491 attr = gfc_variable_attr (array, NULL);
492 if (!attr.allocatable)
494 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
495 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
500 if (array_check (array, 0) == FAILURE)
507 /* Common check function where the first argument must be real or
508 integer and the second argument must be the same as the first. */
511 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
513 if (int_or_real_check (a, 0) == FAILURE)
516 if (a->ts.type != p->ts.type)
518 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
519 "have the same type", gfc_current_intrinsic_arg[0],
520 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
525 if (a->ts.kind != p->ts.kind)
527 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
528 &p->where) == FAILURE)
537 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
539 symbol_attribute attr;
544 where = &pointer->where;
546 if (pointer->expr_type == EXPR_VARIABLE)
547 attr = gfc_variable_attr (pointer, NULL);
548 else if (pointer->expr_type == EXPR_FUNCTION)
549 attr = pointer->symtree->n.sym->attr;
550 else if (pointer->expr_type == EXPR_NULL)
553 gcc_assert (0); /* Pointer must be a variable or a function. */
557 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
558 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
563 /* Target argument is optional. */
567 where = &target->where;
568 if (target->expr_type == EXPR_NULL)
571 if (target->expr_type == EXPR_VARIABLE)
572 attr = gfc_variable_attr (target, NULL);
573 else if (target->expr_type == EXPR_FUNCTION)
574 attr = target->symtree->n.sym->attr;
577 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
578 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg[1],
579 gfc_current_intrinsic, &target->where);
583 if (!attr.pointer && !attr.target)
585 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
586 "or a TARGET", gfc_current_intrinsic_arg[1],
587 gfc_current_intrinsic, &target->where);
592 if (same_type_check (pointer, 0, target, 1) == FAILURE)
594 if (rank_check (target, 0, pointer->rank) == FAILURE)
596 if (target->rank > 0)
598 for (i = 0; i < target->rank; i++)
599 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
601 gfc_error ("Array section with a vector subscript at %L shall not "
602 "be the target of a pointer",
612 gfc_error ("NULL pointer at %L is not permitted as actual argument "
613 "of '%s' intrinsic function", where, gfc_current_intrinsic);
620 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
622 if (type_check (y, 0, BT_REAL) == FAILURE)
624 if (same_type_check (y, 0, x, 1) == FAILURE)
631 /* BESJN and BESYN functions. */
634 gfc_check_besn (gfc_expr *n, gfc_expr *x)
636 if (type_check (n, 0, BT_INTEGER) == 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)
766 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
767 "or REAL", gfc_current_intrinsic_arg[0],
768 gfc_current_intrinsic, &x->where);
771 if (scalar_check (x, 0) == FAILURE)
774 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
776 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
777 "or REAL", gfc_current_intrinsic_arg[1],
778 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)
801 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
803 if (array_check (array, 0) == FAILURE)
806 if (array->rank == 1)
808 if (scalar_check (shift, 1) == FAILURE)
813 /* TODO: more requirements on shift parameter. */
816 if (dim_check (dim, 2, 1) == FAILURE)
824 gfc_check_ctime (gfc_expr *time)
826 if (scalar_check (time, 0) == FAILURE)
829 if (type_check (time, 0, BT_INTEGER) == FAILURE)
837 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
839 if (numeric_check (x, 0) == FAILURE)
844 if (numeric_check (y, 1) == FAILURE)
847 if (x->ts.type == BT_COMPLEX)
849 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
850 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
851 gfc_current_intrinsic, &y->where);
861 gfc_check_dble (gfc_expr *x)
863 if (numeric_check (x, 0) == FAILURE)
871 gfc_check_digits (gfc_expr *x)
873 if (int_or_real_check (x, 0) == FAILURE)
881 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
883 switch (vector_a->ts.type)
886 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
893 if (numeric_check (vector_b, 1) == FAILURE)
898 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
899 "or LOGICAL", gfc_current_intrinsic_arg[0],
900 gfc_current_intrinsic, &vector_a->where);
904 if (rank_check (vector_a, 0, 1) == FAILURE)
907 if (rank_check (vector_b, 1, 1) == FAILURE)
910 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
912 gfc_error ("different shape for arguments '%s' and '%s' at %L for "
913 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0],
914 gfc_current_intrinsic_arg[1], &vector_a->where);
923 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
926 if (array_check (array, 0) == FAILURE)
929 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
932 if (array->rank == 1)
934 if (scalar_check (shift, 2) == FAILURE)
939 /* TODO: more weird restrictions on shift. */
942 if (boundary != NULL)
944 if (same_type_check (array, 0, boundary, 2) == FAILURE)
947 /* TODO: more restrictions on boundary. */
950 if (dim_check (dim, 1, 1) == FAILURE)
957 /* A single complex argument. */
960 gfc_check_fn_c (gfc_expr *a)
962 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
969 /* A single real argument. */
972 gfc_check_fn_r (gfc_expr *a)
974 if (type_check (a, 0, BT_REAL) == FAILURE)
981 /* A single real or complex argument. */
984 gfc_check_fn_rc (gfc_expr *a)
986 if (real_or_complex_check (a, 0) == FAILURE)
994 gfc_check_fnum (gfc_expr *unit)
996 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
999 if (scalar_check (unit, 0) == FAILURE)
1007 gfc_check_huge (gfc_expr *x)
1009 if (int_or_real_check (x, 0) == FAILURE)
1016 /* Check that the single argument is an integer. */
1019 gfc_check_i (gfc_expr *i)
1021 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1029 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1031 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1034 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1037 if (i->ts.kind != j->ts.kind)
1039 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1040 &i->where) == FAILURE)
1049 gfc_check_ibclr (gfc_expr *i, gfc_expr *pos)
1051 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1054 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1062 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1064 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1067 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1070 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1078 gfc_check_ibset (gfc_expr *i, gfc_expr *pos)
1080 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1083 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1091 gfc_check_ichar_iachar (gfc_expr *c)
1095 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1098 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1104 /* Substring references don't have the charlength set. */
1106 while (ref && ref->type != REF_SUBSTRING)
1109 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1113 /* Check that the argument is length one. Non-constant lengths
1114 can't be checked here, so assume they are ok. */
1115 if (c->ts.cl && c->ts.cl->length)
1117 /* If we already have a length for this expression then use it. */
1118 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
1120 i = mpz_get_si (c->ts.cl->length->value.integer);
1127 start = ref->u.ss.start;
1128 end = ref->u.ss.end;
1131 if (end == NULL || end->expr_type != EXPR_CONSTANT
1132 || start->expr_type != EXPR_CONSTANT)
1135 i = mpz_get_si (end->value.integer) + 1
1136 - mpz_get_si (start->value.integer);
1144 gfc_error ("Argument of %s at %L must be of length one",
1145 gfc_current_intrinsic, &c->where);
1154 gfc_check_idnint (gfc_expr *a)
1156 if (double_check (a, 0) == FAILURE)
1164 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1166 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1169 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1172 if (i->ts.kind != j->ts.kind)
1174 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1175 &i->where) == FAILURE)
1184 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back)
1186 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1187 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1191 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1194 if (string->ts.kind != substring->ts.kind)
1196 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1197 "kind as '%s'", gfc_current_intrinsic_arg[1],
1198 gfc_current_intrinsic, &substring->where,
1199 gfc_current_intrinsic_arg[0]);
1208 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1210 if (numeric_check (x, 0) == FAILURE)
1215 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
1218 if (scalar_check (kind, 1) == FAILURE)
1227 gfc_check_intconv (gfc_expr *x)
1229 if (numeric_check (x, 0) == FAILURE)
1237 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1239 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1242 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1245 if (i->ts.kind != j->ts.kind)
1247 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1248 &i->where) == FAILURE)
1257 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1259 if (type_check (i, 0, BT_INTEGER) == FAILURE
1260 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1268 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1270 if (type_check (i, 0, BT_INTEGER) == FAILURE
1271 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1274 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1282 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1284 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1287 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1295 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1297 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1300 if (scalar_check (pid, 0) == FAILURE)
1303 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1306 if (scalar_check (sig, 1) == FAILURE)
1312 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1315 if (scalar_check (status, 2) == FAILURE)
1323 gfc_check_kind (gfc_expr *x)
1325 if (x->ts.type == BT_DERIVED)
1327 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1328 "non-derived type", gfc_current_intrinsic_arg[0],
1329 gfc_current_intrinsic, &x->where);
1338 gfc_check_lbound (gfc_expr *array, gfc_expr *dim)
1340 if (array_check (array, 0) == FAILURE)
1345 if (dim_check (dim, 1, 1) == FAILURE)
1348 if (dim_rank_check (dim, array, 1) == FAILURE)
1356 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
1358 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1361 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1369 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1371 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1374 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1380 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1383 if (scalar_check (status, 2) == FAILURE)
1391 gfc_check_loc (gfc_expr *expr)
1393 return variable_check (expr, 0);
1398 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
1400 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1403 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1411 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1413 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1416 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1422 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1425 if (scalar_check (status, 2) == FAILURE)
1433 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
1435 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1437 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1444 /* Min/max family. */
1447 min_max_args (gfc_actual_arglist *arg)
1449 if (arg == NULL || arg->next == NULL)
1451 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1452 gfc_current_intrinsic, gfc_current_intrinsic_where);
1461 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
1463 gfc_actual_arglist *arg, *tmp;
1468 if (min_max_args (arglist) == FAILURE)
1471 for (arg = arglist, n=1; arg; arg = arg->next, n++)
1474 if (x->ts.type != type || x->ts.kind != kind)
1476 if (x->ts.type == type)
1478 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
1479 "kinds at %L", &x->where) == FAILURE)
1484 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1485 "%s(%d)", n, gfc_current_intrinsic, &x->where,
1486 gfc_basic_typename (type), kind);
1491 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
1494 snprintf (buffer, 80, "arguments 'a%d' and 'a%d' for intrinsic '%s'",
1495 m, n, gfc_current_intrinsic);
1496 if (gfc_check_conformance (buffer, tmp->expr, x) == FAILURE)
1506 gfc_check_min_max (gfc_actual_arglist *arg)
1510 if (min_max_args (arg) == FAILURE)
1515 if (x->ts.type == BT_CHARACTER)
1517 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1518 "with CHARACTER argument at %L",
1519 gfc_current_intrinsic, &x->where) == FAILURE)
1522 else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1524 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
1525 "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
1529 return check_rest (x->ts.type, x->ts.kind, arg);
1534 gfc_check_min_max_integer (gfc_actual_arglist *arg)
1536 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1541 gfc_check_min_max_real (gfc_actual_arglist *arg)
1543 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1548 gfc_check_min_max_double (gfc_actual_arglist *arg)
1550 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1554 /* End of min/max family. */
1557 gfc_check_malloc (gfc_expr *size)
1559 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1562 if (scalar_check (size, 0) == FAILURE)
1570 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
1572 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1574 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1575 "or LOGICAL", gfc_current_intrinsic_arg[0],
1576 gfc_current_intrinsic, &matrix_a->where);
1580 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1582 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1583 "or LOGICAL", gfc_current_intrinsic_arg[1],
1584 gfc_current_intrinsic, &matrix_b->where);
1588 switch (matrix_a->rank)
1591 if (rank_check (matrix_b, 1, 2) == FAILURE)
1593 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
1594 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
1596 gfc_error ("different shape on dimension 1 for arguments '%s' "
1597 "and '%s' at %L for intrinsic matmul",
1598 gfc_current_intrinsic_arg[0],
1599 gfc_current_intrinsic_arg[1], &matrix_a->where);
1605 if (matrix_b->rank != 2)
1607 if (rank_check (matrix_b, 1, 1) == FAILURE)
1610 /* matrix_b has rank 1 or 2 here. Common check for the cases
1611 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
1612 - matrix_a has shape (n,m) and matrix_b has shape (m). */
1613 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
1615 gfc_error ("different shape on dimension 2 for argument '%s' and "
1616 "dimension 1 for argument '%s' at %L for intrinsic "
1617 "matmul", gfc_current_intrinsic_arg[0],
1618 gfc_current_intrinsic_arg[1], &matrix_a->where);
1624 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1625 "1 or 2", gfc_current_intrinsic_arg[0],
1626 gfc_current_intrinsic, &matrix_a->where);
1634 /* Whoever came up with this interface was probably on something.
1635 The possibilities for the occupation of the second and third
1642 NULL MASK minloc(array, mask=m)
1645 I.e. in the case of minloc(array,mask), mask will be in the second
1646 position of the argument list and we'll have to fix that up. */
1649 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
1651 gfc_expr *a, *m, *d;
1654 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
1658 m = ap->next->next->expr;
1660 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1661 && ap->next->name == NULL)
1665 ap->next->expr = NULL;
1666 ap->next->next->expr = m;
1669 if (dim_check (d, 1, 1) == FAILURE)
1672 if (d && dim_rank_check (d, a, 0) == FAILURE)
1675 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1681 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1682 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1683 gfc_current_intrinsic);
1684 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1692 /* Similar to minloc/maxloc, the argument list might need to be
1693 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1694 difference is that MINLOC/MAXLOC take an additional KIND argument.
1695 The possibilities are:
1701 NULL MASK minval(array, mask=m)
1704 I.e. in the case of minval(array,mask), mask will be in the second
1705 position of the argument list and we'll have to fix that up. */
1708 check_reduction (gfc_actual_arglist *ap)
1710 gfc_expr *a, *m, *d;
1714 m = ap->next->next->expr;
1716 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1717 && ap->next->name == NULL)
1721 ap->next->expr = NULL;
1722 ap->next->next->expr = m;
1725 if (dim_check (d, 1, 1) == FAILURE)
1728 if (d && dim_rank_check (d, a, 0) == FAILURE)
1731 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1737 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1738 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1739 gfc_current_intrinsic);
1740 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1749 gfc_check_minval_maxval (gfc_actual_arglist *ap)
1751 if (int_or_real_check (ap->expr, 0) == FAILURE
1752 || array_check (ap->expr, 0) == FAILURE)
1755 return check_reduction (ap);
1760 gfc_check_product_sum (gfc_actual_arglist *ap)
1762 if (numeric_check (ap->expr, 0) == FAILURE
1763 || array_check (ap->expr, 0) == FAILURE)
1766 return check_reduction (ap);
1771 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
1773 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
1776 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
1783 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
1785 symbol_attribute attr;
1787 if (variable_check (from, 0) == FAILURE)
1790 if (array_check (from, 0) == FAILURE)
1793 attr = gfc_variable_attr (from, NULL);
1794 if (!attr.allocatable)
1796 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1797 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1802 if (variable_check (to, 0) == FAILURE)
1805 if (array_check (to, 0) == FAILURE)
1808 attr = gfc_variable_attr (to, NULL);
1809 if (!attr.allocatable)
1811 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
1812 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1817 if (same_type_check (from, 0, to, 1) == FAILURE)
1820 if (to->rank != from->rank)
1822 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1823 "have the same rank %d/%d", gfc_current_intrinsic_arg[0],
1824 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1825 &to->where, from->rank, to->rank);
1829 if (to->ts.kind != from->ts.kind)
1831 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
1832 "be of the same kind %d/%d", gfc_current_intrinsic_arg[0],
1833 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
1834 &to->where, from->ts.kind, to->ts.kind);
1843 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
1845 if (type_check (x, 0, BT_REAL) == FAILURE)
1848 if (type_check (s, 1, BT_REAL) == FAILURE)
1856 gfc_check_new_line (gfc_expr *a)
1858 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1866 gfc_check_null (gfc_expr *mold)
1868 symbol_attribute attr;
1873 if (variable_check (mold, 0) == FAILURE)
1876 attr = gfc_variable_attr (mold, NULL);
1880 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
1881 gfc_current_intrinsic_arg[0],
1882 gfc_current_intrinsic, &mold->where);
1891 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
1895 if (array_check (array, 0) == FAILURE)
1898 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
1901 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
1902 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
1903 gfc_current_intrinsic);
1904 if (gfc_check_conformance (buffer, array, mask) == FAILURE)
1909 if (same_type_check (array, 0, vector, 2) == FAILURE)
1912 if (rank_check (vector, 2, 1) == FAILURE)
1915 /* TODO: More constraints here. */
1923 gfc_check_precision (gfc_expr *x)
1925 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
1927 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
1928 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
1929 gfc_current_intrinsic, &x->where);
1938 gfc_check_present (gfc_expr *a)
1942 if (variable_check (a, 0) == FAILURE)
1945 sym = a->symtree->n.sym;
1946 if (!sym->attr.dummy)
1948 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
1949 "dummy variable", gfc_current_intrinsic_arg[0],
1950 gfc_current_intrinsic, &a->where);
1954 if (!sym->attr.optional)
1956 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
1957 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
1958 gfc_current_intrinsic, &a->where);
1962 /* 13.14.82 PRESENT(A)
1964 Argument. A shall be the name of an optional dummy argument that is
1965 accessible in the subprogram in which the PRESENT function reference
1969 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
1970 && a->ref->u.ar.type == AR_FULL))
1972 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
1973 "subobject of '%s'", gfc_current_intrinsic_arg[0],
1974 gfc_current_intrinsic, &a->where, sym->name);
1983 gfc_check_radix (gfc_expr *x)
1985 if (int_or_real_check (x, 0) == FAILURE)
1993 gfc_check_range (gfc_expr *x)
1995 if (numeric_check (x, 0) == FAILURE)
2002 /* real, float, sngl. */
2004 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2006 if (numeric_check (a, 0) == FAILURE)
2009 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2017 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2019 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2022 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2030 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2032 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2035 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2041 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2044 if (scalar_check (status, 2) == FAILURE)
2052 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2054 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2057 if (scalar_check (x, 0) == FAILURE)
2060 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2063 if (scalar_check (y, 1) == FAILURE)
2071 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2072 gfc_expr *pad, gfc_expr *order)
2078 if (array_check (source, 0) == FAILURE)
2081 if (rank_check (shape, 1, 1) == FAILURE)
2084 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2087 if (gfc_array_size (shape, &size) != SUCCESS)
2089 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2090 "array of constant size", &shape->where);
2094 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
2099 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2100 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2106 if (same_type_check (source, 0, pad, 2) == FAILURE)
2108 if (array_check (pad, 2) == FAILURE)
2112 if (order != NULL && array_check (order, 3) == FAILURE)
2115 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2116 && gfc_is_constant_expr (shape)
2117 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2118 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2120 /* Check the match in size between source and destination. */
2121 if (gfc_array_size (source, &nelems) == SUCCESS)
2126 c = shape->value.constructor;
2127 mpz_init_set_ui (size, 1);
2128 for (; c; c = c->next)
2129 mpz_mul (size, size, c->expr->value.integer);
2131 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2137 gfc_error ("Without padding, there are not enough elements "
2138 "in the intrinsic RESHAPE source at %L to match "
2139 "the shape", &source->where);
2150 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2152 if (type_check (x, 0, BT_REAL) == FAILURE)
2155 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2163 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2165 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2168 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2171 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2174 if (same_type_check (x, 0, y, 1) == FAILURE)
2182 gfc_check_secnds (gfc_expr *r)
2184 if (type_check (r, 0, BT_REAL) == FAILURE)
2187 if (kind_value_check (r, 0, 4) == FAILURE)
2190 if (scalar_check (r, 0) == FAILURE)
2198 gfc_check_selected_int_kind (gfc_expr *r)
2200 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2203 if (scalar_check (r, 0) == FAILURE)
2211 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r)
2213 if (p == NULL && r == NULL)
2215 gfc_error ("Missing arguments to %s intrinsic at %L",
2216 gfc_current_intrinsic, gfc_current_intrinsic_where);
2221 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
2224 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
2232 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
2234 if (type_check (x, 0, BT_REAL) == FAILURE)
2237 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2245 gfc_check_shape (gfc_expr *source)
2249 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2252 ar = gfc_find_array_ref (source);
2254 if (ar->as && ar->as->type == AS_ASSUMED_SIZE)
2256 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2257 "an assumed size array", &source->where);
2266 gfc_check_sign (gfc_expr *a, gfc_expr *b)
2268 if (int_or_real_check (a, 0) == FAILURE)
2271 if (same_type_check (a, 0, b, 1) == FAILURE)
2279 gfc_check_size (gfc_expr *array, gfc_expr *dim)
2281 if (array_check (array, 0) == FAILURE)
2286 if (type_check (dim, 1, BT_INTEGER) == FAILURE)
2289 if (kind_value_check (dim, 1, gfc_default_integer_kind) == FAILURE)
2292 if (dim_rank_check (dim, array, 0) == FAILURE)
2301 gfc_check_sizeof (gfc_expr *arg __attribute__((unused)))
2308 gfc_check_sleep_sub (gfc_expr *seconds)
2310 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2313 if (scalar_check (seconds, 0) == FAILURE)
2321 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
2323 if (source->rank >= GFC_MAX_DIMENSIONS)
2325 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2326 "than rank %d", gfc_current_intrinsic_arg[0],
2327 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2332 if (dim_check (dim, 1, 0) == FAILURE)
2335 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2338 if (scalar_check (ncopies, 2) == FAILURE)
2345 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2349 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
2351 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2354 if (scalar_check (unit, 0) == FAILURE)
2357 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2363 if (type_check (status, 2, BT_INTEGER) == FAILURE
2364 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2365 || scalar_check (status, 2) == FAILURE)
2373 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
2375 return gfc_check_fgetputc_sub (unit, c, NULL);
2380 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
2382 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2388 if (type_check (status, 1, BT_INTEGER) == FAILURE
2389 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2390 || scalar_check (status, 1) == FAILURE)
2398 gfc_check_fgetput (gfc_expr *c)
2400 return gfc_check_fgetput_sub (c, NULL);
2405 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
2407 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2410 if (scalar_check (unit, 0) == FAILURE)
2413 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2416 if (scalar_check (offset, 1) == FAILURE)
2419 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
2422 if (scalar_check (whence, 2) == FAILURE)
2428 if (type_check (status, 3, BT_INTEGER) == FAILURE)
2431 if (kind_value_check (status, 3, 4) == FAILURE)
2434 if (scalar_check (status, 3) == FAILURE)
2443 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
2445 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2448 if (scalar_check (unit, 0) == FAILURE)
2451 if (type_check (array, 1, BT_INTEGER) == FAILURE
2452 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2455 if (array_check (array, 1) == FAILURE)
2463 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
2465 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2468 if (scalar_check (unit, 0) == FAILURE)
2471 if (type_check (array, 1, BT_INTEGER) == FAILURE
2472 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2475 if (array_check (array, 1) == FAILURE)
2481 if (type_check (status, 2, BT_INTEGER) == FAILURE
2482 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2485 if (scalar_check (status, 2) == FAILURE)
2493 gfc_check_ftell (gfc_expr *unit)
2495 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2498 if (scalar_check (unit, 0) == FAILURE)
2506 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
2508 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2511 if (scalar_check (unit, 0) == FAILURE)
2514 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2517 if (scalar_check (offset, 1) == FAILURE)
2525 gfc_check_stat (gfc_expr *name, gfc_expr *array)
2527 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2530 if (type_check (array, 1, BT_INTEGER) == FAILURE
2531 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2534 if (array_check (array, 1) == FAILURE)
2542 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
2544 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2547 if (type_check (array, 1, BT_INTEGER) == FAILURE
2548 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2551 if (array_check (array, 1) == FAILURE)
2557 if (type_check (status, 2, BT_INTEGER) == FAILURE
2558 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2561 if (scalar_check (status, 2) == FAILURE)
2569 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
2570 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
2572 if (mold->ts.type == BT_HOLLERITH)
2574 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
2575 &mold->where, gfc_basic_typename (BT_HOLLERITH));
2581 if (type_check (size, 2, BT_INTEGER) == FAILURE)
2584 if (scalar_check (size, 2) == FAILURE)
2587 if (nonoptional_check (size, 2) == FAILURE)
2596 gfc_check_transpose (gfc_expr *matrix)
2598 if (rank_check (matrix, 0, 2) == FAILURE)
2606 gfc_check_ubound (gfc_expr *array, gfc_expr *dim)
2608 if (array_check (array, 0) == FAILURE)
2613 if (dim_check (dim, 1, 1) == FAILURE)
2616 if (dim_rank_check (dim, array, 0) == FAILURE)
2625 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
2627 if (rank_check (vector, 0, 1) == FAILURE)
2630 if (array_check (mask, 1) == FAILURE)
2633 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2636 if (same_type_check (vector, 0, field, 2) == FAILURE)
2644 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z)
2646 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2649 if (same_type_check (x, 0, y, 1) == FAILURE)
2652 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2660 gfc_check_trim (gfc_expr *x)
2662 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2665 if (scalar_check (x, 0) == FAILURE)
2673 gfc_check_ttynam (gfc_expr *unit)
2675 if (scalar_check (unit, 0) == FAILURE)
2678 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2685 /* Common check function for the half a dozen intrinsics that have a
2686 single real argument. */
2689 gfc_check_x (gfc_expr *x)
2691 if (type_check (x, 0, BT_REAL) == FAILURE)
2698 /************* Check functions for intrinsic subroutines *************/
2701 gfc_check_cpu_time (gfc_expr *time)
2703 if (scalar_check (time, 0) == FAILURE)
2706 if (type_check (time, 0, BT_REAL) == FAILURE)
2709 if (variable_check (time, 0) == FAILURE)
2717 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
2718 gfc_expr *zone, gfc_expr *values)
2722 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
2724 if (scalar_check (date, 0) == FAILURE)
2726 if (variable_check (date, 0) == FAILURE)
2732 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
2734 if (scalar_check (time, 1) == FAILURE)
2736 if (variable_check (time, 1) == FAILURE)
2742 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
2744 if (scalar_check (zone, 2) == FAILURE)
2746 if (variable_check (zone, 2) == FAILURE)
2752 if (type_check (values, 3, BT_INTEGER) == FAILURE)
2754 if (array_check (values, 3) == FAILURE)
2756 if (rank_check (values, 3, 1) == FAILURE)
2758 if (variable_check (values, 3) == FAILURE)
2767 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
2768 gfc_expr *to, gfc_expr *topos)
2770 if (type_check (from, 0, BT_INTEGER) == FAILURE)
2773 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
2776 if (type_check (len, 2, BT_INTEGER) == FAILURE)
2779 if (same_type_check (from, 0, to, 3) == FAILURE)
2782 if (variable_check (to, 3) == FAILURE)
2785 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
2793 gfc_check_random_number (gfc_expr *harvest)
2795 if (type_check (harvest, 0, BT_REAL) == FAILURE)
2798 if (variable_check (harvest, 0) == FAILURE)
2806 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
2810 if (scalar_check (size, 0) == FAILURE)
2813 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2816 if (variable_check (size, 0) == FAILURE)
2819 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
2827 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2830 if (array_check (put, 1) == FAILURE)
2833 if (rank_check (put, 1, 1) == FAILURE)
2836 if (type_check (put, 1, BT_INTEGER) == FAILURE)
2839 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
2846 if (size != NULL || put != NULL)
2847 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic,
2850 if (array_check (get, 2) == FAILURE)
2853 if (rank_check (get, 2, 1) == FAILURE)
2856 if (type_check (get, 2, BT_INTEGER) == FAILURE)
2859 if (variable_check (get, 2) == FAILURE)
2862 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
2871 gfc_check_second_sub (gfc_expr *time)
2873 if (scalar_check (time, 0) == FAILURE)
2876 if (type_check (time, 0, BT_REAL) == FAILURE)
2879 if (kind_value_check(time, 0, 4) == FAILURE)
2886 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
2887 count, count_rate, and count_max are all optional arguments */
2890 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
2891 gfc_expr *count_max)
2895 if (scalar_check (count, 0) == FAILURE)
2898 if (type_check (count, 0, BT_INTEGER) == FAILURE)
2901 if (variable_check (count, 0) == FAILURE)
2905 if (count_rate != NULL)
2907 if (scalar_check (count_rate, 1) == FAILURE)
2910 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
2913 if (variable_check (count_rate, 1) == FAILURE)
2917 && same_type_check (count, 0, count_rate, 1) == FAILURE)
2922 if (count_max != NULL)
2924 if (scalar_check (count_max, 2) == FAILURE)
2927 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
2930 if (variable_check (count_max, 2) == FAILURE)
2934 && same_type_check (count, 0, count_max, 2) == FAILURE)
2937 if (count_rate != NULL
2938 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
2947 gfc_check_irand (gfc_expr *x)
2952 if (scalar_check (x, 0) == FAILURE)
2955 if (type_check (x, 0, BT_INTEGER) == FAILURE)
2958 if (kind_value_check(x, 0, 4) == FAILURE)
2966 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
2968 if (scalar_check (seconds, 0) == FAILURE)
2971 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2974 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
2976 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
2977 "or PROCEDURE", gfc_current_intrinsic_arg[1],
2978 gfc_current_intrinsic, &handler->where);
2982 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
2988 if (scalar_check (status, 2) == FAILURE)
2991 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2994 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3002 gfc_check_rand (gfc_expr *x)
3007 if (scalar_check (x, 0) == FAILURE)
3010 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3013 if (kind_value_check(x, 0, 4) == FAILURE)
3021 gfc_check_srand (gfc_expr *x)
3023 if (scalar_check (x, 0) == FAILURE)
3026 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3029 if (kind_value_check(x, 0, 4) == FAILURE)
3037 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
3039 if (scalar_check (time, 0) == FAILURE)
3042 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3045 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
3053 gfc_check_etime (gfc_expr *x)
3055 if (array_check (x, 0) == FAILURE)
3058 if (rank_check (x, 0, 1) == FAILURE)
3061 if (variable_check (x, 0) == FAILURE)
3064 if (type_check (x, 0, BT_REAL) == FAILURE)
3067 if (kind_value_check(x, 0, 4) == FAILURE)
3075 gfc_check_etime_sub (gfc_expr *values, gfc_expr *time)
3077 if (array_check (values, 0) == FAILURE)
3080 if (rank_check (values, 0, 1) == FAILURE)
3083 if (variable_check (values, 0) == FAILURE)
3086 if (type_check (values, 0, BT_REAL) == FAILURE)
3089 if (kind_value_check(values, 0, 4) == FAILURE)
3092 if (scalar_check (time, 1) == FAILURE)
3095 if (type_check (time, 1, BT_REAL) == FAILURE)
3098 if (kind_value_check(time, 1, 4) == FAILURE)
3106 gfc_check_fdate_sub (gfc_expr *date)
3108 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3116 gfc_check_gerror (gfc_expr *msg)
3118 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3126 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
3128 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
3134 if (scalar_check (status, 1) == FAILURE)
3137 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3145 gfc_check_getlog (gfc_expr *msg)
3147 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3155 gfc_check_exit (gfc_expr *status)
3160 if (type_check (status, 0, BT_INTEGER) == FAILURE)
3163 if (scalar_check (status, 0) == FAILURE)
3171 gfc_check_flush (gfc_expr *unit)
3176 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3179 if (scalar_check (unit, 0) == FAILURE)
3187 gfc_check_free (gfc_expr *i)
3189 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3192 if (scalar_check (i, 0) == FAILURE)
3200 gfc_check_hostnm (gfc_expr *name)
3202 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3210 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
3212 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3218 if (scalar_check (status, 1) == FAILURE)
3221 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3229 gfc_check_itime_idate (gfc_expr *values)
3231 if (array_check (values, 0) == FAILURE)
3234 if (rank_check (values, 0, 1) == FAILURE)
3237 if (variable_check (values, 0) == FAILURE)
3240 if (type_check (values, 0, BT_INTEGER) == FAILURE)
3243 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
3251 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
3253 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3256 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
3259 if (scalar_check (time, 0) == FAILURE)
3262 if (array_check (values, 1) == FAILURE)
3265 if (rank_check (values, 1, 1) == FAILURE)
3268 if (variable_check (values, 1) == FAILURE)
3271 if (type_check (values, 1, BT_INTEGER) == FAILURE)
3274 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
3282 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
3284 if (scalar_check (unit, 0) == FAILURE)
3287 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3290 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
3298 gfc_check_isatty (gfc_expr *unit)
3303 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3306 if (scalar_check (unit, 0) == FAILURE)
3314 gfc_check_isnan (gfc_expr *x)
3316 if (type_check (x, 0, BT_REAL) == FAILURE)
3324 gfc_check_perror (gfc_expr *string)
3326 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
3334 gfc_check_umask (gfc_expr *mask)
3336 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3339 if (scalar_check (mask, 0) == FAILURE)
3347 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
3349 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3352 if (scalar_check (mask, 0) == FAILURE)
3358 if (scalar_check (old, 1) == FAILURE)
3361 if (type_check (old, 1, BT_INTEGER) == FAILURE)
3369 gfc_check_unlink (gfc_expr *name)
3371 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3379 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
3381 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3387 if (scalar_check (status, 1) == FAILURE)
3390 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3398 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
3400 if (scalar_check (number, 0) == FAILURE)
3403 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3406 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3408 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3409 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3410 gfc_current_intrinsic, &handler->where);
3414 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3422 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
3424 if (scalar_check (number, 0) == FAILURE)
3427 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3430 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3432 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3433 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3434 gfc_current_intrinsic, &handler->where);
3438 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3444 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3447 if (scalar_check (status, 2) == FAILURE)
3455 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
3457 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
3460 if (scalar_check (status, 1) == FAILURE)
3463 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3466 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
3473 /* This is used for the GNU intrinsics AND, OR and XOR. */
3475 gfc_check_and (gfc_expr *i, gfc_expr *j)
3477 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
3479 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3480 "or LOGICAL", gfc_current_intrinsic_arg[0],
3481 gfc_current_intrinsic, &i->where);
3485 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
3487 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3488 "or LOGICAL", gfc_current_intrinsic_arg[1],
3489 gfc_current_intrinsic, &j->where);
3493 if (i->ts.type != j->ts.type)
3495 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
3496 "have the same type", gfc_current_intrinsic_arg[0],
3497 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3502 if (scalar_check (i, 0) == FAILURE)
3505 if (scalar_check (j, 1) == FAILURE)