2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
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 /* Make sure an expression is a scalar. */
39 scalar_check (gfc_expr *e, int n)
44 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
45 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
51 /* Check the type of an expression. */
54 type_check (gfc_expr *e, int n, bt type)
56 if (e->ts.type == type)
59 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
60 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where,
61 gfc_basic_typename (type));
67 /* Check that the expression is a numeric type. */
70 numeric_check (gfc_expr *e, int n)
72 if (gfc_numeric_ts (&e->ts))
75 /* If the expression has not got a type, check if its namespace can
76 offer a default type. */
77 if ((e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_VARIABLE)
78 && e->symtree->n.sym->ts.type == BT_UNKNOWN
79 && gfc_set_default_type (e->symtree->n.sym, 0,
80 e->symtree->n.sym->ns) == SUCCESS
81 && gfc_numeric_ts (&e->symtree->n.sym->ts))
83 e->ts = e->symtree->n.sym->ts;
87 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
88 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
94 /* Check that an expression is integer or real. */
97 int_or_real_check (gfc_expr *e, int n)
99 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
101 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
102 "or REAL", gfc_current_intrinsic_arg[n],
103 gfc_current_intrinsic, &e->where);
111 /* Check that an expression is real or complex. */
114 real_or_complex_check (gfc_expr *e, int n)
116 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
118 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
119 "or COMPLEX", gfc_current_intrinsic_arg[n],
120 gfc_current_intrinsic, &e->where);
128 /* Check that the expression is an optional constant integer
129 and that it specifies a valid kind for that type. */
132 kind_check (gfc_expr *k, int n, bt type)
139 if (type_check (k, n, BT_INTEGER) == FAILURE)
142 if (scalar_check (k, n) == FAILURE)
145 if (k->expr_type != EXPR_CONSTANT)
147 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
148 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
153 if (gfc_extract_int (k, &kind) != NULL
154 || gfc_validate_kind (type, kind, true) < 0)
156 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
165 /* Make sure the expression is a double precision real. */
168 double_check (gfc_expr *d, int n)
170 if (type_check (d, n, BT_REAL) == FAILURE)
173 if (d->ts.kind != gfc_default_double_kind)
175 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
176 "precision", gfc_current_intrinsic_arg[n],
177 gfc_current_intrinsic, &d->where);
185 /* Make sure the expression is a logical array. */
188 logical_array_check (gfc_expr *array, int n)
190 if (array->ts.type != BT_LOGICAL || array->rank == 0)
192 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
193 "array", gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
202 /* Make sure an expression is an array. */
205 array_check (gfc_expr *e, int n)
210 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
211 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
217 /* Make sure two expressions have the same type. */
220 same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
222 if (gfc_compare_types (&e->ts, &f->ts))
225 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
226 "and kind as '%s'", gfc_current_intrinsic_arg[m],
227 gfc_current_intrinsic, &f->where, gfc_current_intrinsic_arg[n]);
233 /* Make sure that an expression has a certain (nonzero) rank. */
236 rank_check (gfc_expr *e, int n, int rank)
241 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
242 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
249 /* Make sure a variable expression is not an optional dummy argument. */
252 nonoptional_check (gfc_expr *e, int n)
254 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
256 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
257 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
261 /* TODO: Recursive check on nonoptional variables? */
267 /* Check that an expression has a particular kind. */
270 kind_value_check (gfc_expr *e, int n, int k)
275 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
276 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
283 /* Make sure an expression is a variable. */
286 variable_check (gfc_expr *e, int n)
288 if ((e->expr_type == EXPR_VARIABLE
289 && e->symtree->n.sym->attr.flavor != FL_PARAMETER)
290 || (e->expr_type == EXPR_FUNCTION
291 && e->symtree->n.sym->result == e->symtree->n.sym))
294 if (e->expr_type == EXPR_VARIABLE
295 && e->symtree->n.sym->attr.intent == INTENT_IN)
297 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
298 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
303 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
304 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
310 /* Check the common DIM parameter for correctness. */
313 dim_check (gfc_expr *dim, int n, bool optional)
318 if (type_check (dim, n, BT_INTEGER) == FAILURE)
321 if (scalar_check (dim, n) == FAILURE)
324 if (!optional && nonoptional_check (dim, n) == FAILURE)
331 /* If a DIM parameter is a constant, make sure that it is greater than
332 zero and less than or equal to the rank of the given array. If
333 allow_assumed is zero then dim must be less than the rank of the array
334 for assumed size arrays. */
337 dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
342 if (dim->expr_type != EXPR_CONSTANT || array->expr_type != EXPR_VARIABLE)
345 ar = gfc_find_array_ref (array);
347 if (ar->as->type == AS_ASSUMED_SIZE
349 && ar->type != AR_ELEMENT
350 && ar->type != AR_SECTION)
353 if (mpz_cmp_ui (dim->value.integer, 1) < 0
354 || mpz_cmp_ui (dim->value.integer, rank) > 0)
356 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
357 "dimension index", gfc_current_intrinsic, &dim->where);
366 /* Compare the size of a along dimension ai with the size of b along
367 dimension bi, returning 0 if they are known not to be identical,
368 and 1 if they are identical, or if this cannot be determined. */
371 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
373 mpz_t a_size, b_size;
376 gcc_assert (a->rank > ai);
377 gcc_assert (b->rank > bi);
381 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
383 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
385 if (mpz_cmp (a_size, b_size) != 0)
396 /* Check whether two character expressions have the same length;
397 returns SUCCESS if they have or if the length cannot be determined. */
400 check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
405 if (a->ts.cl && a->ts.cl->length
406 && a->ts.cl->length->expr_type == EXPR_CONSTANT)
407 len_a = mpz_get_si (a->ts.cl->length->value.integer);
408 else if (a->expr_type == EXPR_CONSTANT
409 && (a->ts.cl == NULL || a->ts.cl->length == NULL))
410 len_a = a->value.character.length;
414 if (b->ts.cl && b->ts.cl->length
415 && b->ts.cl->length->expr_type == EXPR_CONSTANT)
416 len_b = mpz_get_si (b->ts.cl->length->value.integer);
417 else if (b->expr_type == EXPR_CONSTANT
418 && (b->ts.cl == NULL || b->ts.cl->length == NULL))
419 len_b = b->value.character.length;
426 gfc_error ("Unequal character lengths (%ld and %ld) in %s intrinsic "
427 "at %L", len_a, len_b, name, &a->where);
432 /***** Check functions *****/
434 /* Check subroutine suitable for intrinsics taking a real argument and
435 a kind argument for the result. */
438 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
440 if (type_check (a, 0, BT_REAL) == FAILURE)
442 if (kind_check (kind, 1, type) == FAILURE)
449 /* Check subroutine suitable for ceiling, floor and nint. */
452 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
454 return check_a_kind (a, kind, BT_INTEGER);
458 /* Check subroutine suitable for aint, anint. */
461 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
463 return check_a_kind (a, kind, BT_REAL);
468 gfc_check_abs (gfc_expr *a)
470 if (numeric_check (a, 0) == FAILURE)
478 gfc_check_achar (gfc_expr *a, gfc_expr *kind)
480 if (type_check (a, 0, BT_INTEGER) == FAILURE)
482 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
490 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
492 if (type_check (name, 0, BT_CHARACTER) == FAILURE
493 || scalar_check (name, 0) == FAILURE)
495 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
498 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
499 || scalar_check (mode, 1) == FAILURE)
501 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
509 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
511 if (logical_array_check (mask, 0) == FAILURE)
514 if (dim_check (dim, 1, false) == FAILURE)
522 gfc_check_allocated (gfc_expr *array)
524 symbol_attribute attr;
526 if (variable_check (array, 0) == FAILURE)
529 attr = gfc_variable_attr (array, NULL);
530 if (!attr.allocatable)
532 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
533 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
538 if (array_check (array, 0) == FAILURE)
545 /* Common check function where the first argument must be real or
546 integer and the second argument must be the same as the first. */
549 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
551 if (int_or_real_check (a, 0) == FAILURE)
554 if (a->ts.type != p->ts.type)
556 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
557 "have the same type", gfc_current_intrinsic_arg[0],
558 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
563 if (a->ts.kind != p->ts.kind)
565 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
566 &p->where) == FAILURE)
575 gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
577 if (double_check (x, 0) == FAILURE || double_check (y, 1) == FAILURE)
585 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
587 symbol_attribute attr1, attr2;
592 where = &pointer->where;
594 if (pointer->expr_type == EXPR_VARIABLE)
595 attr1 = gfc_variable_attr (pointer, NULL);
596 else if (pointer->expr_type == EXPR_FUNCTION)
597 attr1 = pointer->symtree->n.sym->attr;
598 else if (pointer->expr_type == EXPR_NULL)
601 gcc_assert (0); /* Pointer must be a variable or a function. */
603 if (!attr1.pointer && !attr1.proc_pointer)
605 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
606 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
611 /* Target argument is optional. */
615 where = &target->where;
616 if (target->expr_type == EXPR_NULL)
619 if (target->expr_type == EXPR_VARIABLE)
620 attr2 = gfc_variable_attr (target, NULL);
621 else if (target->expr_type == EXPR_FUNCTION)
622 attr2 = target->symtree->n.sym->attr;
625 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
626 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg[1],
627 gfc_current_intrinsic, &target->where);
631 if (attr1.pointer && !attr2.pointer && !attr2.target)
633 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
634 "or a TARGET", gfc_current_intrinsic_arg[1],
635 gfc_current_intrinsic, &target->where);
640 if (same_type_check (pointer, 0, target, 1) == FAILURE)
642 if (rank_check (target, 0, pointer->rank) == FAILURE)
644 if (target->rank > 0)
646 for (i = 0; i < target->rank; i++)
647 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
649 gfc_error ("Array section with a vector subscript at %L shall not "
650 "be the target of a pointer",
660 gfc_error ("NULL pointer at %L is not permitted as actual argument "
661 "of '%s' intrinsic function", where, gfc_current_intrinsic);
668 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
670 if (type_check (y, 0, BT_REAL) == FAILURE)
672 if (same_type_check (y, 0, x, 1) == FAILURE)
679 /* BESJN and BESYN functions. */
682 gfc_check_besn (gfc_expr *n, gfc_expr *x)
684 if (type_check (n, 0, BT_INTEGER) == FAILURE)
687 if (type_check (x, 1, BT_REAL) == FAILURE)
695 gfc_check_btest (gfc_expr *i, gfc_expr *pos)
697 if (type_check (i, 0, BT_INTEGER) == FAILURE)
699 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
707 gfc_check_char (gfc_expr *i, gfc_expr *kind)
709 if (type_check (i, 0, BT_INTEGER) == FAILURE)
711 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
719 gfc_check_chdir (gfc_expr *dir)
721 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
723 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
731 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
733 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
735 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
741 if (type_check (status, 1, BT_INTEGER) == FAILURE)
743 if (scalar_check (status, 1) == FAILURE)
751 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
753 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
755 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
758 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
760 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
768 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
770 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
772 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
775 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
777 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
783 if (type_check (status, 2, BT_INTEGER) == FAILURE)
786 if (scalar_check (status, 2) == FAILURE)
794 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
796 if (numeric_check (x, 0) == FAILURE)
801 if (numeric_check (y, 1) == FAILURE)
804 if (x->ts.type == BT_COMPLEX)
806 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
807 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
808 gfc_current_intrinsic, &y->where);
813 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
821 gfc_check_complex (gfc_expr *x, gfc_expr *y)
823 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
825 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
826 "or REAL", gfc_current_intrinsic_arg[0],
827 gfc_current_intrinsic, &x->where);
830 if (scalar_check (x, 0) == FAILURE)
833 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
835 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
836 "or REAL", gfc_current_intrinsic_arg[1],
837 gfc_current_intrinsic, &y->where);
840 if (scalar_check (y, 1) == FAILURE)
848 gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
850 if (logical_array_check (mask, 0) == FAILURE)
852 if (dim_check (dim, 1, false) == FAILURE)
854 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
856 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
857 "with KIND argument at %L",
858 gfc_current_intrinsic, &kind->where) == FAILURE)
866 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
868 if (array_check (array, 0) == FAILURE)
871 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
874 if (array->rank == 1)
876 if (scalar_check (shift, 1) == FAILURE)
879 else if (shift->rank != array->rank - 1 && shift->rank != 0)
881 gfc_error ("SHIFT argument at %L of CSHIFT must have rank %d or be a "
882 "scalar", &shift->where, array->rank - 1);
886 /* TODO: Add shape conformance check between array (w/o dimension dim)
889 if (dim_check (dim, 2, true) == FAILURE)
897 gfc_check_ctime (gfc_expr *time)
899 if (scalar_check (time, 0) == FAILURE)
902 if (type_check (time, 0, BT_INTEGER) == FAILURE)
909 gfc_try gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
911 if (double_check (y, 0) == FAILURE || double_check (x, 1) == FAILURE)
918 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
920 if (numeric_check (x, 0) == FAILURE)
925 if (numeric_check (y, 1) == FAILURE)
928 if (x->ts.type == BT_COMPLEX)
930 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
931 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
932 gfc_current_intrinsic, &y->where);
942 gfc_check_dble (gfc_expr *x)
944 if (numeric_check (x, 0) == FAILURE)
952 gfc_check_digits (gfc_expr *x)
954 if (int_or_real_check (x, 0) == FAILURE)
962 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
964 switch (vector_a->ts.type)
967 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
974 if (numeric_check (vector_b, 1) == FAILURE)
979 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
980 "or LOGICAL", gfc_current_intrinsic_arg[0],
981 gfc_current_intrinsic, &vector_a->where);
985 if (rank_check (vector_a, 0, 1) == FAILURE)
988 if (rank_check (vector_b, 1, 1) == FAILURE)
991 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
993 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
994 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0],
995 gfc_current_intrinsic_arg[1], &vector_a->where);
1004 gfc_check_dprod (gfc_expr *x, gfc_expr *y)
1006 if (type_check (x, 0, BT_REAL) == FAILURE
1007 || type_check (y, 1, BT_REAL) == FAILURE)
1010 if (x->ts.kind != gfc_default_real_kind)
1012 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1013 "real", gfc_current_intrinsic_arg[0],
1014 gfc_current_intrinsic, &x->where);
1018 if (y->ts.kind != gfc_default_real_kind)
1020 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1021 "real", gfc_current_intrinsic_arg[1],
1022 gfc_current_intrinsic, &y->where);
1031 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
1034 if (array_check (array, 0) == FAILURE)
1037 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1040 if (array->rank == 1)
1042 if (scalar_check (shift, 2) == FAILURE)
1045 else if (shift->rank != array->rank - 1 && shift->rank != 0)
1047 gfc_error ("SHIFT argument at %L of EOSHIFT must have rank %d or be a "
1048 "scalar", &shift->where, array->rank - 1);
1052 /* TODO: Add shape conformance check between array (w/o dimension dim)
1055 if (boundary != NULL)
1057 if (same_type_check (array, 0, boundary, 2) == FAILURE)
1060 if (array->rank == 1)
1062 if (scalar_check (boundary, 2) == FAILURE)
1065 else if (boundary->rank != array->rank - 1 && boundary->rank != 0)
1067 gfc_error ("BOUNDARY argument at %L of EOSHIFT must have rank %d or be "
1068 "a scalar", &boundary->where, array->rank - 1);
1072 if (shift->rank == boundary->rank)
1075 for (i = 0; i < shift->rank; i++)
1076 if (! identical_dimen_shape (shift, i, boundary, i))
1078 gfc_error ("Different shape in dimension %d for SHIFT and "
1079 "BOUNDARY arguments of EOSHIFT at %L", shift->rank,
1086 if (dim_check (dim, 4, true) == FAILURE)
1093 /* A single complex argument. */
1096 gfc_check_fn_c (gfc_expr *a)
1098 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
1105 /* A single real argument. */
1108 gfc_check_fn_r (gfc_expr *a)
1110 if (type_check (a, 0, BT_REAL) == FAILURE)
1116 /* A single double argument. */
1119 gfc_check_fn_d (gfc_expr *a)
1121 if (double_check (a, 0) == FAILURE)
1127 /* A single real or complex argument. */
1130 gfc_check_fn_rc (gfc_expr *a)
1132 if (real_or_complex_check (a, 0) == FAILURE)
1140 gfc_check_fnum (gfc_expr *unit)
1142 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1145 if (scalar_check (unit, 0) == FAILURE)
1153 gfc_check_huge (gfc_expr *x)
1155 if (int_or_real_check (x, 0) == FAILURE)
1163 gfc_check_hypot (gfc_expr *x, gfc_expr *y)
1165 if (type_check (x, 0, BT_REAL) == FAILURE)
1167 if (same_type_check (x, 0, y, 1) == FAILURE)
1174 /* Check that the single argument is an integer. */
1177 gfc_check_i (gfc_expr *i)
1179 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1187 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1189 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1192 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1195 if (i->ts.kind != j->ts.kind)
1197 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1198 &i->where) == FAILURE)
1207 gfc_check_ibclr (gfc_expr *i, gfc_expr *pos)
1209 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1212 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1220 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1222 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1225 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1228 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1236 gfc_check_ibset (gfc_expr *i, gfc_expr *pos)
1238 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1241 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1249 gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
1253 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1256 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1259 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1260 "with KIND argument at %L",
1261 gfc_current_intrinsic, &kind->where) == FAILURE)
1264 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1270 /* Substring references don't have the charlength set. */
1272 while (ref && ref->type != REF_SUBSTRING)
1275 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1279 /* Check that the argument is length one. Non-constant lengths
1280 can't be checked here, so assume they are ok. */
1281 if (c->ts.cl && c->ts.cl->length)
1283 /* If we already have a length for this expression then use it. */
1284 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
1286 i = mpz_get_si (c->ts.cl->length->value.integer);
1293 start = ref->u.ss.start;
1294 end = ref->u.ss.end;
1297 if (end == NULL || end->expr_type != EXPR_CONSTANT
1298 || start->expr_type != EXPR_CONSTANT)
1301 i = mpz_get_si (end->value.integer) + 1
1302 - mpz_get_si (start->value.integer);
1310 gfc_error ("Argument of %s at %L must be of length one",
1311 gfc_current_intrinsic, &c->where);
1320 gfc_check_idnint (gfc_expr *a)
1322 if (double_check (a, 0) == FAILURE)
1330 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1332 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1335 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1338 if (i->ts.kind != j->ts.kind)
1340 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1341 &i->where) == FAILURE)
1350 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back,
1353 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1354 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1357 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1360 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
1362 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1363 "with KIND argument at %L",
1364 gfc_current_intrinsic, &kind->where) == FAILURE)
1367 if (string->ts.kind != substring->ts.kind)
1369 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1370 "kind as '%s'", gfc_current_intrinsic_arg[1],
1371 gfc_current_intrinsic, &substring->where,
1372 gfc_current_intrinsic_arg[0]);
1381 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1383 if (numeric_check (x, 0) == FAILURE)
1386 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1394 gfc_check_intconv (gfc_expr *x)
1396 if (numeric_check (x, 0) == FAILURE)
1404 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1406 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1409 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1412 if (i->ts.kind != j->ts.kind)
1414 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1415 &i->where) == FAILURE)
1424 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1426 if (type_check (i, 0, BT_INTEGER) == FAILURE
1427 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1435 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1437 if (type_check (i, 0, BT_INTEGER) == FAILURE
1438 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1441 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1449 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1451 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1454 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1462 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1464 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1467 if (scalar_check (pid, 0) == FAILURE)
1470 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1473 if (scalar_check (sig, 1) == FAILURE)
1479 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1482 if (scalar_check (status, 2) == FAILURE)
1490 gfc_check_kind (gfc_expr *x)
1492 if (x->ts.type == BT_DERIVED)
1494 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1495 "non-derived type", gfc_current_intrinsic_arg[0],
1496 gfc_current_intrinsic, &x->where);
1505 gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1507 if (array_check (array, 0) == FAILURE)
1512 if (dim_check (dim, 1, false) == FAILURE)
1515 if (dim_rank_check (dim, array, 1) == FAILURE)
1519 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1521 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1522 "with KIND argument at %L",
1523 gfc_current_intrinsic, &kind->where) == FAILURE)
1531 gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
1533 if (type_check (s, 0, BT_CHARACTER) == FAILURE)
1536 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1538 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1539 "with KIND argument at %L",
1540 gfc_current_intrinsic, &kind->where) == FAILURE)
1548 gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
1550 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1552 if (kind_value_check (a, 0, gfc_default_character_kind) == FAILURE)
1555 if (type_check (b, 1, BT_CHARACTER) == FAILURE)
1557 if (kind_value_check (b, 1, gfc_default_character_kind) == FAILURE)
1565 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
1567 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1569 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1572 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1574 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1582 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1584 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1586 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1589 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1591 if (kind_value_check (path2, 0, gfc_default_character_kind) == FAILURE)
1597 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1600 if (scalar_check (status, 2) == FAILURE)
1608 gfc_check_loc (gfc_expr *expr)
1610 return variable_check (expr, 0);
1615 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
1617 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1619 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1622 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1624 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1632 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1634 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1636 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1639 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1641 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1647 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1650 if (scalar_check (status, 2) == FAILURE)
1658 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
1660 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1662 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1669 /* Min/max family. */
1672 min_max_args (gfc_actual_arglist *arg)
1674 if (arg == NULL || arg->next == NULL)
1676 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1677 gfc_current_intrinsic, gfc_current_intrinsic_where);
1686 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
1688 gfc_actual_arglist *arg, *tmp;
1693 if (min_max_args (arglist) == FAILURE)
1696 for (arg = arglist, n=1; arg; arg = arg->next, n++)
1699 if (x->ts.type != type || x->ts.kind != kind)
1701 if (x->ts.type == type)
1703 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
1704 "kinds at %L", &x->where) == FAILURE)
1709 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1710 "%s(%d)", n, gfc_current_intrinsic, &x->where,
1711 gfc_basic_typename (type), kind);
1716 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
1719 snprintf (buffer, 80, "arguments 'a%d' and 'a%d' for intrinsic '%s'",
1720 m, n, gfc_current_intrinsic);
1721 if (gfc_check_conformance (buffer, tmp->expr, x) == FAILURE)
1731 gfc_check_min_max (gfc_actual_arglist *arg)
1735 if (min_max_args (arg) == FAILURE)
1740 if (x->ts.type == BT_CHARACTER)
1742 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1743 "with CHARACTER argument at %L",
1744 gfc_current_intrinsic, &x->where) == FAILURE)
1747 else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1749 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
1750 "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
1754 return check_rest (x->ts.type, x->ts.kind, arg);
1759 gfc_check_min_max_integer (gfc_actual_arglist *arg)
1761 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1766 gfc_check_min_max_real (gfc_actual_arglist *arg)
1768 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1773 gfc_check_min_max_double (gfc_actual_arglist *arg)
1775 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1779 /* End of min/max family. */
1782 gfc_check_malloc (gfc_expr *size)
1784 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1787 if (scalar_check (size, 0) == FAILURE)
1795 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
1797 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1799 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1800 "or LOGICAL", gfc_current_intrinsic_arg[0],
1801 gfc_current_intrinsic, &matrix_a->where);
1805 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1807 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1808 "or LOGICAL", gfc_current_intrinsic_arg[1],
1809 gfc_current_intrinsic, &matrix_b->where);
1813 if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
1814 || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
1816 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
1817 gfc_current_intrinsic, &matrix_a->where,
1818 gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
1822 switch (matrix_a->rank)
1825 if (rank_check (matrix_b, 1, 2) == FAILURE)
1827 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
1828 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
1830 gfc_error ("Different shape on dimension 1 for arguments '%s' "
1831 "and '%s' at %L for intrinsic matmul",
1832 gfc_current_intrinsic_arg[0],
1833 gfc_current_intrinsic_arg[1], &matrix_a->where);
1839 if (matrix_b->rank != 2)
1841 if (rank_check (matrix_b, 1, 1) == FAILURE)
1844 /* matrix_b has rank 1 or 2 here. Common check for the cases
1845 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
1846 - matrix_a has shape (n,m) and matrix_b has shape (m). */
1847 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
1849 gfc_error ("Different shape on dimension 2 for argument '%s' and "
1850 "dimension 1 for argument '%s' at %L for intrinsic "
1851 "matmul", gfc_current_intrinsic_arg[0],
1852 gfc_current_intrinsic_arg[1], &matrix_a->where);
1858 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1859 "1 or 2", gfc_current_intrinsic_arg[0],
1860 gfc_current_intrinsic, &matrix_a->where);
1868 /* Whoever came up with this interface was probably on something.
1869 The possibilities for the occupation of the second and third
1876 NULL MASK minloc(array, mask=m)
1879 I.e. in the case of minloc(array,mask), mask will be in the second
1880 position of the argument list and we'll have to fix that up. */
1883 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
1885 gfc_expr *a, *m, *d;
1888 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
1892 m = ap->next->next->expr;
1894 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1895 && ap->next->name == NULL)
1899 ap->next->expr = NULL;
1900 ap->next->next->expr = m;
1903 if (d && dim_check (d, 1, false) == FAILURE)
1906 if (d && dim_rank_check (d, a, 0) == FAILURE)
1909 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1915 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1916 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1917 gfc_current_intrinsic);
1918 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1926 /* Similar to minloc/maxloc, the argument list might need to be
1927 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1928 difference is that MINLOC/MAXLOC take an additional KIND argument.
1929 The possibilities are:
1935 NULL MASK minval(array, mask=m)
1938 I.e. in the case of minval(array,mask), mask will be in the second
1939 position of the argument list and we'll have to fix that up. */
1942 check_reduction (gfc_actual_arglist *ap)
1944 gfc_expr *a, *m, *d;
1948 m = ap->next->next->expr;
1950 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1951 && ap->next->name == NULL)
1955 ap->next->expr = NULL;
1956 ap->next->next->expr = m;
1959 if (d && dim_check (d, 1, false) == FAILURE)
1962 if (d && dim_rank_check (d, a, 0) == FAILURE)
1965 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1971 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1972 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1973 gfc_current_intrinsic);
1974 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1983 gfc_check_minval_maxval (gfc_actual_arglist *ap)
1985 if (int_or_real_check (ap->expr, 0) == FAILURE
1986 || array_check (ap->expr, 0) == FAILURE)
1989 return check_reduction (ap);
1994 gfc_check_product_sum (gfc_actual_arglist *ap)
1996 if (numeric_check (ap->expr, 0) == FAILURE
1997 || array_check (ap->expr, 0) == FAILURE)
2000 return check_reduction (ap);
2005 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
2007 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
2010 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
2013 if (tsource->ts.type == BT_CHARACTER)
2014 return check_same_strlen (tsource, fsource, "MERGE");
2021 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
2023 symbol_attribute attr;
2025 if (variable_check (from, 0) == FAILURE)
2028 if (array_check (from, 0) == FAILURE)
2031 attr = gfc_variable_attr (from, NULL);
2032 if (!attr.allocatable)
2034 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2035 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
2040 if (variable_check (to, 0) == FAILURE)
2043 if (array_check (to, 0) == FAILURE)
2046 attr = gfc_variable_attr (to, NULL);
2047 if (!attr.allocatable)
2049 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2050 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
2055 if (same_type_check (from, 0, to, 1) == FAILURE)
2058 if (to->rank != from->rank)
2060 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2061 "have the same rank %d/%d", gfc_current_intrinsic_arg[0],
2062 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
2063 &to->where, from->rank, to->rank);
2067 if (to->ts.kind != from->ts.kind)
2069 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2070 "be of the same kind %d/%d", gfc_current_intrinsic_arg[0],
2071 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
2072 &to->where, from->ts.kind, to->ts.kind);
2081 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
2083 if (type_check (x, 0, BT_REAL) == FAILURE)
2086 if (type_check (s, 1, BT_REAL) == FAILURE)
2094 gfc_check_new_line (gfc_expr *a)
2096 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2104 gfc_check_null (gfc_expr *mold)
2106 symbol_attribute attr;
2111 if (variable_check (mold, 0) == FAILURE)
2114 attr = gfc_variable_attr (mold, NULL);
2116 if (!attr.pointer && !attr.proc_pointer)
2118 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
2119 gfc_current_intrinsic_arg[0],
2120 gfc_current_intrinsic, &mold->where);
2129 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
2133 if (array_check (array, 0) == FAILURE)
2136 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2139 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
2140 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
2141 gfc_current_intrinsic);
2142 if (gfc_check_conformance (buffer, array, mask) == FAILURE)
2147 if (same_type_check (array, 0, vector, 2) == FAILURE)
2150 if (rank_check (vector, 2, 1) == FAILURE)
2153 /* TODO: More constraints here. */
2161 gfc_check_precision (gfc_expr *x)
2163 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
2165 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
2166 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
2167 gfc_current_intrinsic, &x->where);
2176 gfc_check_present (gfc_expr *a)
2180 if (variable_check (a, 0) == FAILURE)
2183 sym = a->symtree->n.sym;
2184 if (!sym->attr.dummy)
2186 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2187 "dummy variable", gfc_current_intrinsic_arg[0],
2188 gfc_current_intrinsic, &a->where);
2192 if (!sym->attr.optional)
2194 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2195 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
2196 gfc_current_intrinsic, &a->where);
2200 /* 13.14.82 PRESENT(A)
2202 Argument. A shall be the name of an optional dummy argument that is
2203 accessible in the subprogram in which the PRESENT function reference
2207 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2208 && a->ref->u.ar.type == AR_FULL))
2210 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2211 "subobject of '%s'", gfc_current_intrinsic_arg[0],
2212 gfc_current_intrinsic, &a->where, sym->name);
2221 gfc_check_radix (gfc_expr *x)
2223 if (int_or_real_check (x, 0) == FAILURE)
2231 gfc_check_range (gfc_expr *x)
2233 if (numeric_check (x, 0) == FAILURE)
2240 /* real, float, sngl. */
2242 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2244 if (numeric_check (a, 0) == FAILURE)
2247 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2255 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2257 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2259 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2262 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2264 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2272 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2274 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2276 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2279 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2281 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2287 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2290 if (scalar_check (status, 2) == FAILURE)
2298 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2300 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2303 if (scalar_check (x, 0) == FAILURE)
2306 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2309 if (scalar_check (y, 1) == FAILURE)
2317 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2318 gfc_expr *pad, gfc_expr *order)
2324 if (array_check (source, 0) == FAILURE)
2327 if (rank_check (shape, 1, 1) == FAILURE)
2330 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2333 if (gfc_array_size (shape, &size) != SUCCESS)
2335 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2336 "array of constant size", &shape->where);
2340 m = mpz_cmp_ui (size, GFC_MAX_DIMENSIONS);
2345 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2346 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2352 if (same_type_check (source, 0, pad, 2) == FAILURE)
2354 if (array_check (pad, 2) == FAILURE)
2358 if (order != NULL && array_check (order, 3) == FAILURE)
2361 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2362 && gfc_is_constant_expr (shape)
2363 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2364 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2366 /* Check the match in size between source and destination. */
2367 if (gfc_array_size (source, &nelems) == SUCCESS)
2372 c = shape->value.constructor;
2373 mpz_init_set_ui (size, 1);
2374 for (; c; c = c->next)
2375 mpz_mul (size, size, c->expr->value.integer);
2377 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2383 gfc_error ("Without padding, there are not enough elements "
2384 "in the intrinsic RESHAPE source at %L to match "
2385 "the shape", &source->where);
2396 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2398 if (type_check (x, 0, BT_REAL) == FAILURE)
2401 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2409 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
2411 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2414 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2417 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2420 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
2422 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2423 "with KIND argument at %L",
2424 gfc_current_intrinsic, &kind->where) == FAILURE)
2427 if (same_type_check (x, 0, y, 1) == FAILURE)
2435 gfc_check_secnds (gfc_expr *r)
2437 if (type_check (r, 0, BT_REAL) == FAILURE)
2440 if (kind_value_check (r, 0, 4) == FAILURE)
2443 if (scalar_check (r, 0) == FAILURE)
2451 gfc_check_selected_char_kind (gfc_expr *name)
2453 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2456 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
2459 if (scalar_check (name, 0) == FAILURE)
2467 gfc_check_selected_int_kind (gfc_expr *r)
2469 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2472 if (scalar_check (r, 0) == FAILURE)
2480 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r)
2482 if (p == NULL && r == NULL)
2484 gfc_error ("Missing arguments to %s intrinsic at %L",
2485 gfc_current_intrinsic, gfc_current_intrinsic_where);
2490 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
2493 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
2501 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
2503 if (type_check (x, 0, BT_REAL) == FAILURE)
2506 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2514 gfc_check_shape (gfc_expr *source)
2518 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2521 ar = gfc_find_array_ref (source);
2523 if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
2525 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2526 "an assumed size array", &source->where);
2535 gfc_check_sign (gfc_expr *a, gfc_expr *b)
2537 if (int_or_real_check (a, 0) == FAILURE)
2540 if (same_type_check (a, 0, b, 1) == FAILURE)
2548 gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2550 if (array_check (array, 0) == FAILURE)
2555 if (dim_check (dim, 1, true) == FAILURE)
2558 if (dim_rank_check (dim, array, 0) == FAILURE)
2562 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
2564 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2565 "with KIND argument at %L",
2566 gfc_current_intrinsic, &kind->where) == FAILURE)
2575 gfc_check_sizeof (gfc_expr *arg ATTRIBUTE_UNUSED)
2582 gfc_check_sleep_sub (gfc_expr *seconds)
2584 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2587 if (scalar_check (seconds, 0) == FAILURE)
2595 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
2597 if (source->rank >= GFC_MAX_DIMENSIONS)
2599 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2600 "than rank %d", gfc_current_intrinsic_arg[0],
2601 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2609 if (dim_check (dim, 1, false) == FAILURE)
2612 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2615 if (scalar_check (ncopies, 2) == FAILURE)
2622 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2626 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
2628 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2631 if (scalar_check (unit, 0) == FAILURE)
2634 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2636 if (kind_value_check (c, 1, gfc_default_character_kind) == FAILURE)
2642 if (type_check (status, 2, BT_INTEGER) == FAILURE
2643 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2644 || scalar_check (status, 2) == FAILURE)
2652 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
2654 return gfc_check_fgetputc_sub (unit, c, NULL);
2659 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
2661 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2663 if (kind_value_check (c, 0, gfc_default_character_kind) == FAILURE)
2669 if (type_check (status, 1, BT_INTEGER) == FAILURE
2670 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2671 || scalar_check (status, 1) == FAILURE)
2679 gfc_check_fgetput (gfc_expr *c)
2681 return gfc_check_fgetput_sub (c, NULL);
2686 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
2688 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2691 if (scalar_check (unit, 0) == FAILURE)
2694 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2697 if (scalar_check (offset, 1) == FAILURE)
2700 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
2703 if (scalar_check (whence, 2) == FAILURE)
2709 if (type_check (status, 3, BT_INTEGER) == FAILURE)
2712 if (kind_value_check (status, 3, 4) == FAILURE)
2715 if (scalar_check (status, 3) == FAILURE)
2724 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
2726 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2729 if (scalar_check (unit, 0) == FAILURE)
2732 if (type_check (array, 1, BT_INTEGER) == FAILURE
2733 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2736 if (array_check (array, 1) == FAILURE)
2744 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
2746 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2749 if (scalar_check (unit, 0) == FAILURE)
2752 if (type_check (array, 1, BT_INTEGER) == FAILURE
2753 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2756 if (array_check (array, 1) == FAILURE)
2762 if (type_check (status, 2, BT_INTEGER) == FAILURE
2763 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2766 if (scalar_check (status, 2) == FAILURE)
2774 gfc_check_ftell (gfc_expr *unit)
2776 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2779 if (scalar_check (unit, 0) == FAILURE)
2787 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
2789 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2792 if (scalar_check (unit, 0) == FAILURE)
2795 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2798 if (scalar_check (offset, 1) == FAILURE)
2806 gfc_check_stat (gfc_expr *name, gfc_expr *array)
2808 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2810 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
2813 if (type_check (array, 1, BT_INTEGER) == FAILURE
2814 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2817 if (array_check (array, 1) == FAILURE)
2825 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
2827 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2829 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
2832 if (type_check (array, 1, BT_INTEGER) == FAILURE
2833 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2836 if (array_check (array, 1) == FAILURE)
2842 if (type_check (status, 2, BT_INTEGER) == FAILURE
2843 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2846 if (scalar_check (status, 2) == FAILURE)
2854 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
2855 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
2857 if (mold->ts.type == BT_HOLLERITH)
2859 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
2860 &mold->where, gfc_basic_typename (BT_HOLLERITH));
2866 if (type_check (size, 2, BT_INTEGER) == FAILURE)
2869 if (scalar_check (size, 2) == FAILURE)
2872 if (nonoptional_check (size, 2) == FAILURE)
2881 gfc_check_transpose (gfc_expr *matrix)
2883 if (rank_check (matrix, 0, 2) == FAILURE)
2891 gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2893 if (array_check (array, 0) == FAILURE)
2898 if (dim_check (dim, 1, false) == FAILURE)
2901 if (dim_rank_check (dim, array, 0) == FAILURE)
2905 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
2907 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2908 "with KIND argument at %L",
2909 gfc_current_intrinsic, &kind->where) == FAILURE)
2917 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
2919 if (rank_check (vector, 0, 1) == FAILURE)
2922 if (array_check (mask, 1) == FAILURE)
2925 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2928 if (same_type_check (vector, 0, field, 2) == FAILURE)
2931 if (mask->rank != field->rank && field->rank != 0)
2933 gfc_error ("FIELD argument at %L of UNPACK must have the same rank as "
2934 "MASK or be a scalar", &field->where);
2938 if (mask->rank == field->rank)
2941 for (i = 0; i < field->rank; i++)
2942 if (! identical_dimen_shape (mask, i, field, i))
2944 gfc_error ("Different shape in dimension %d for MASK and FIELD "
2945 "arguments of UNPACK at %L", mask->rank, &field->where);
2955 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
2957 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2960 if (same_type_check (x, 0, y, 1) == FAILURE)
2963 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2966 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
2968 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2969 "with KIND argument at %L",
2970 gfc_current_intrinsic, &kind->where) == FAILURE)
2978 gfc_check_trim (gfc_expr *x)
2980 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2983 if (scalar_check (x, 0) == FAILURE)
2991 gfc_check_ttynam (gfc_expr *unit)
2993 if (scalar_check (unit, 0) == FAILURE)
2996 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3003 /* Common check function for the half a dozen intrinsics that have a
3004 single real argument. */
3007 gfc_check_x (gfc_expr *x)
3009 if (type_check (x, 0, BT_REAL) == FAILURE)
3016 /************* Check functions for intrinsic subroutines *************/
3019 gfc_check_cpu_time (gfc_expr *time)
3021 if (scalar_check (time, 0) == FAILURE)
3024 if (type_check (time, 0, BT_REAL) == FAILURE)
3027 if (variable_check (time, 0) == FAILURE)
3035 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
3036 gfc_expr *zone, gfc_expr *values)
3040 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3042 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
3044 if (scalar_check (date, 0) == FAILURE)
3046 if (variable_check (date, 0) == FAILURE)
3052 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
3054 if (kind_value_check (time, 1, gfc_default_character_kind) == FAILURE)
3056 if (scalar_check (time, 1) == FAILURE)
3058 if (variable_check (time, 1) == FAILURE)
3064 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
3066 if (kind_value_check (zone, 2, gfc_default_character_kind) == FAILURE)
3068 if (scalar_check (zone, 2) == FAILURE)
3070 if (variable_check (zone, 2) == FAILURE)
3076 if (type_check (values, 3, BT_INTEGER) == FAILURE)
3078 if (array_check (values, 3) == FAILURE)
3080 if (rank_check (values, 3, 1) == FAILURE)
3082 if (variable_check (values, 3) == FAILURE)
3091 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
3092 gfc_expr *to, gfc_expr *topos)
3094 if (type_check (from, 0, BT_INTEGER) == FAILURE)
3097 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
3100 if (type_check (len, 2, BT_INTEGER) == FAILURE)
3103 if (same_type_check (from, 0, to, 3) == FAILURE)
3106 if (variable_check (to, 3) == FAILURE)
3109 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
3117 gfc_check_random_number (gfc_expr *harvest)
3119 if (type_check (harvest, 0, BT_REAL) == FAILURE)
3122 if (variable_check (harvest, 0) == FAILURE)
3130 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
3132 unsigned int nargs = 0, kiss_size;
3133 locus *where = NULL;
3135 bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
3137 have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
3139 /* Keep these values in sync with kiss_size in libgfortran/random.c. */
3140 kiss_size = have_gfc_real_16 ? 12 : 8;
3144 if (size->expr_type != EXPR_VARIABLE
3145 || !size->symtree->n.sym->attr.optional)
3148 if (scalar_check (size, 0) == FAILURE)
3151 if (type_check (size, 0, BT_INTEGER) == FAILURE)
3154 if (variable_check (size, 0) == FAILURE)
3157 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
3163 if (put->expr_type != EXPR_VARIABLE
3164 || !put->symtree->n.sym->attr.optional)
3167 where = &put->where;
3170 if (array_check (put, 1) == FAILURE)
3173 if (rank_check (put, 1, 1) == FAILURE)
3176 if (type_check (put, 1, BT_INTEGER) == FAILURE)
3179 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
3182 if (gfc_array_size (put, &put_size) == SUCCESS
3183 && mpz_get_ui (put_size) < kiss_size)
3184 gfc_error ("Array PUT of intrinsic %s is too small (%i/%i) at %L",
3185 gfc_current_intrinsic, (int) mpz_get_ui (put_size),
3191 if (get->expr_type != EXPR_VARIABLE
3192 || !get->symtree->n.sym->attr.optional)
3195 where = &get->where;
3198 if (array_check (get, 2) == FAILURE)
3201 if (rank_check (get, 2, 1) == FAILURE)
3204 if (type_check (get, 2, BT_INTEGER) == FAILURE)
3207 if (variable_check (get, 2) == FAILURE)
3210 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
3214 /* RANDOM_SEED may not have more than one non-optional argument. */
3216 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
3223 gfc_check_second_sub (gfc_expr *time)
3225 if (scalar_check (time, 0) == FAILURE)
3228 if (type_check (time, 0, BT_REAL) == FAILURE)
3231 if (kind_value_check(time, 0, 4) == FAILURE)
3238 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
3239 count, count_rate, and count_max are all optional arguments */
3242 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
3243 gfc_expr *count_max)
3247 if (scalar_check (count, 0) == FAILURE)
3250 if (type_check (count, 0, BT_INTEGER) == FAILURE)
3253 if (variable_check (count, 0) == FAILURE)
3257 if (count_rate != NULL)
3259 if (scalar_check (count_rate, 1) == FAILURE)
3262 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
3265 if (variable_check (count_rate, 1) == FAILURE)
3269 && same_type_check (count, 0, count_rate, 1) == FAILURE)
3274 if (count_max != NULL)
3276 if (scalar_check (count_max, 2) == FAILURE)
3279 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
3282 if (variable_check (count_max, 2) == FAILURE)
3286 && same_type_check (count, 0, count_max, 2) == FAILURE)
3289 if (count_rate != NULL
3290 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
3299 gfc_check_irand (gfc_expr *x)
3304 if (scalar_check (x, 0) == FAILURE)
3307 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3310 if (kind_value_check(x, 0, 4) == FAILURE)
3318 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
3320 if (scalar_check (seconds, 0) == FAILURE)
3323 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3326 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3328 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3329 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3330 gfc_current_intrinsic, &handler->where);
3334 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3340 if (scalar_check (status, 2) == FAILURE)
3343 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3346 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3354 gfc_check_rand (gfc_expr *x)
3359 if (scalar_check (x, 0) == FAILURE)
3362 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3365 if (kind_value_check(x, 0, 4) == FAILURE)
3373 gfc_check_srand (gfc_expr *x)
3375 if (scalar_check (x, 0) == FAILURE)
3378 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3381 if (kind_value_check(x, 0, 4) == FAILURE)
3389 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
3391 if (scalar_check (time, 0) == FAILURE)
3393 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3396 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
3398 if (kind_value_check (result, 1, gfc_default_character_kind) == FAILURE)
3406 gfc_check_dtime_etime (gfc_expr *x)
3408 if (array_check (x, 0) == FAILURE)
3411 if (rank_check (x, 0, 1) == FAILURE)
3414 if (variable_check (x, 0) == FAILURE)
3417 if (type_check (x, 0, BT_REAL) == FAILURE)
3420 if (kind_value_check(x, 0, 4) == FAILURE)
3428 gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
3430 if (array_check (values, 0) == FAILURE)
3433 if (rank_check (values, 0, 1) == FAILURE)
3436 if (variable_check (values, 0) == FAILURE)
3439 if (type_check (values, 0, BT_REAL) == FAILURE)
3442 if (kind_value_check(values, 0, 4) == FAILURE)
3445 if (scalar_check (time, 1) == FAILURE)
3448 if (type_check (time, 1, BT_REAL) == FAILURE)
3451 if (kind_value_check(time, 1, 4) == FAILURE)
3459 gfc_check_fdate_sub (gfc_expr *date)
3461 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3463 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
3471 gfc_check_gerror (gfc_expr *msg)
3473 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3475 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
3483 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
3485 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
3487 if (kind_value_check (cwd, 0, gfc_default_character_kind) == FAILURE)
3493 if (scalar_check (status, 1) == FAILURE)
3496 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3504 gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
3506 if (type_check (pos, 0, BT_INTEGER) == FAILURE)
3509 if (pos->ts.kind > gfc_default_integer_kind)
3511 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
3512 "not wider than the default kind (%d)",
3513 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
3514 &pos->where, gfc_default_integer_kind);
3518 if (type_check (value, 1, BT_CHARACTER) == FAILURE)
3520 if (kind_value_check (value, 1, gfc_default_character_kind) == FAILURE)
3528 gfc_check_getlog (gfc_expr *msg)
3530 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3532 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
3540 gfc_check_exit (gfc_expr *status)
3545 if (type_check (status, 0, BT_INTEGER) == FAILURE)
3548 if (scalar_check (status, 0) == FAILURE)
3556 gfc_check_flush (gfc_expr *unit)
3561 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3564 if (scalar_check (unit, 0) == FAILURE)
3572 gfc_check_free (gfc_expr *i)
3574 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3577 if (scalar_check (i, 0) == FAILURE)
3585 gfc_check_hostnm (gfc_expr *name)
3587 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3589 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3597 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
3599 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3601 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3607 if (scalar_check (status, 1) == FAILURE)
3610 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3618 gfc_check_itime_idate (gfc_expr *values)
3620 if (array_check (values, 0) == FAILURE)
3623 if (rank_check (values, 0, 1) == FAILURE)
3626 if (variable_check (values, 0) == FAILURE)
3629 if (type_check (values, 0, BT_INTEGER) == FAILURE)
3632 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
3640 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
3642 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3645 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
3648 if (scalar_check (time, 0) == FAILURE)
3651 if (array_check (values, 1) == FAILURE)
3654 if (rank_check (values, 1, 1) == FAILURE)
3657 if (variable_check (values, 1) == FAILURE)
3660 if (type_check (values, 1, BT_INTEGER) == FAILURE)
3663 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
3671 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
3673 if (scalar_check (unit, 0) == FAILURE)
3676 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3679 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
3681 if (kind_value_check (name, 1, gfc_default_character_kind) == FAILURE)
3689 gfc_check_isatty (gfc_expr *unit)
3694 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3697 if (scalar_check (unit, 0) == FAILURE)
3705 gfc_check_isnan (gfc_expr *x)
3707 if (type_check (x, 0, BT_REAL) == FAILURE)
3715 gfc_check_perror (gfc_expr *string)
3717 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
3719 if (kind_value_check (string, 0, gfc_default_character_kind) == FAILURE)
3727 gfc_check_umask (gfc_expr *mask)
3729 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3732 if (scalar_check (mask, 0) == FAILURE)
3740 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
3742 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3745 if (scalar_check (mask, 0) == FAILURE)
3751 if (scalar_check (old, 1) == FAILURE)
3754 if (type_check (old, 1, BT_INTEGER) == FAILURE)
3762 gfc_check_unlink (gfc_expr *name)
3764 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3766 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3774 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
3776 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3778 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3784 if (scalar_check (status, 1) == FAILURE)
3787 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3795 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
3797 if (scalar_check (number, 0) == FAILURE)
3800 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3803 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3805 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3806 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3807 gfc_current_intrinsic, &handler->where);
3811 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3819 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
3821 if (scalar_check (number, 0) == FAILURE)
3824 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3827 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3829 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3830 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3831 gfc_current_intrinsic, &handler->where);
3835 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3841 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3844 if (scalar_check (status, 2) == FAILURE)
3852 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
3854 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
3856 if (kind_value_check (cmd, 0, gfc_default_character_kind) == FAILURE)
3859 if (scalar_check (status, 1) == FAILURE)
3862 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3865 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
3872 /* This is used for the GNU intrinsics AND, OR and XOR. */
3874 gfc_check_and (gfc_expr *i, gfc_expr *j)
3876 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
3878 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3879 "or LOGICAL", gfc_current_intrinsic_arg[0],
3880 gfc_current_intrinsic, &i->where);
3884 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
3886 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3887 "or LOGICAL", gfc_current_intrinsic_arg[1],
3888 gfc_current_intrinsic, &j->where);
3892 if (i->ts.type != j->ts.type)
3894 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
3895 "have the same type", gfc_current_intrinsic_arg[0],
3896 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3901 if (scalar_check (i, 0) == FAILURE)
3904 if (scalar_check (j, 1) == FAILURE)