2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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"
34 #include "constructor.h"
37 /* Make sure an expression is a scalar. */
40 scalar_check (gfc_expr *e, int n)
45 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
46 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
52 /* Check the type of an expression. */
55 type_check (gfc_expr *e, int n, bt type)
57 if (e->ts.type == type)
60 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
61 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where,
62 gfc_basic_typename (type));
68 /* Check that the expression is a numeric type. */
71 numeric_check (gfc_expr *e, int n)
73 if (gfc_numeric_ts (&e->ts))
76 /* If the expression has not got a type, check if its namespace can
77 offer a default type. */
78 if ((e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_VARIABLE)
79 && e->symtree->n.sym->ts.type == BT_UNKNOWN
80 && gfc_set_default_type (e->symtree->n.sym, 0,
81 e->symtree->n.sym->ns) == SUCCESS
82 && gfc_numeric_ts (&e->symtree->n.sym->ts))
84 e->ts = e->symtree->n.sym->ts;
88 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
89 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
95 /* Check that an expression is integer or real. */
98 int_or_real_check (gfc_expr *e, int n)
100 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
102 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
103 "or REAL", gfc_current_intrinsic_arg[n],
104 gfc_current_intrinsic, &e->where);
112 /* Check that an expression is real or complex. */
115 real_or_complex_check (gfc_expr *e, int n)
117 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
119 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
120 "or COMPLEX", gfc_current_intrinsic_arg[n],
121 gfc_current_intrinsic, &e->where);
129 /* Check that the expression is an optional constant integer
130 and that it specifies a valid kind for that type. */
133 kind_check (gfc_expr *k, int n, bt type)
140 if (type_check (k, n, BT_INTEGER) == FAILURE)
143 if (scalar_check (k, n) == FAILURE)
146 if (k->expr_type != EXPR_CONSTANT)
148 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
149 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
154 if (gfc_extract_int (k, &kind) != NULL
155 || gfc_validate_kind (type, kind, true) < 0)
157 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
166 /* Make sure the expression is a double precision real. */
169 double_check (gfc_expr *d, int n)
171 if (type_check (d, n, BT_REAL) == FAILURE)
174 if (d->ts.kind != gfc_default_double_kind)
176 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
177 "precision", gfc_current_intrinsic_arg[n],
178 gfc_current_intrinsic, &d->where);
186 /* Check whether an expression is a coarray (without array designator). */
189 is_coarray (gfc_expr *e)
191 bool coarray = false;
194 if (e->expr_type != EXPR_VARIABLE)
197 coarray = e->symtree->n.sym->attr.codimension;
199 for (ref = e->ref; ref; ref = ref->next)
201 if (ref->type == REF_COMPONENT)
202 coarray = ref->u.c.component->attr.codimension;
203 else if (ref->type != REF_ARRAY || ref->u.ar.dimen != 0
204 || ref->u.ar.codimen != 0)
212 /* Make sure the expression is a logical array. */
215 logical_array_check (gfc_expr *array, int n)
217 if (array->ts.type != BT_LOGICAL || array->rank == 0)
219 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
220 "array", gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
229 /* Make sure an expression is an array. */
232 array_check (gfc_expr *e, int n)
237 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
238 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
244 /* If expr is a constant, then check to ensure that it is greater than
248 nonnegative_check (const char *arg, gfc_expr *expr)
252 if (expr->expr_type == EXPR_CONSTANT)
254 gfc_extract_int (expr, &i);
257 gfc_error ("'%s' at %L must be nonnegative", arg, &expr->where);
266 /* If expr2 is constant, then check that the value is less than
270 less_than_bitsize1 (const char *arg1, gfc_expr *expr1, const char *arg2,
275 if (expr2->expr_type == EXPR_CONSTANT)
277 gfc_extract_int (expr2, &i2);
278 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
279 if (i2 >= gfc_integer_kinds[i3].bit_size)
281 gfc_error ("'%s' at %L must be less than BIT_SIZE('%s')",
282 arg2, &expr2->where, arg1);
291 /* If expr2 and expr3 are constants, then check that the value is less than
292 or equal to bit_size(expr1). */
295 less_than_bitsize2 (const char *arg1, gfc_expr *expr1, const char *arg2,
296 gfc_expr *expr2, const char *arg3, gfc_expr *expr3)
300 if (expr2->expr_type == EXPR_CONSTANT && expr3->expr_type == EXPR_CONSTANT)
302 gfc_extract_int (expr2, &i2);
303 gfc_extract_int (expr3, &i3);
305 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
306 if (i2 > gfc_integer_kinds[i3].bit_size)
308 gfc_error ("'%s + %s' at %L must be less than or equal "
310 arg2, arg3, &expr2->where, arg1);
318 /* Make sure two expressions have the same type. */
321 same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
323 if (gfc_compare_types (&e->ts, &f->ts))
326 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
327 "and kind as '%s'", gfc_current_intrinsic_arg[m],
328 gfc_current_intrinsic, &f->where, gfc_current_intrinsic_arg[n]);
334 /* Make sure that an expression has a certain (nonzero) rank. */
337 rank_check (gfc_expr *e, int n, int rank)
342 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
343 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
350 /* Make sure a variable expression is not an optional dummy argument. */
353 nonoptional_check (gfc_expr *e, int n)
355 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
357 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
358 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
362 /* TODO: Recursive check on nonoptional variables? */
368 /* Check that an expression has a particular kind. */
371 kind_value_check (gfc_expr *e, int n, int k)
376 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
377 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
384 /* Make sure an expression is a variable. */
387 variable_check (gfc_expr *e, int n)
389 if ((e->expr_type == EXPR_VARIABLE
390 && e->symtree->n.sym->attr.flavor != FL_PARAMETER)
391 || (e->expr_type == EXPR_FUNCTION
392 && e->symtree->n.sym->result == e->symtree->n.sym))
395 if (e->expr_type == EXPR_VARIABLE
396 && e->symtree->n.sym->attr.intent == INTENT_IN)
398 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
399 gfc_current_intrinsic_arg[n], gfc_current_intrinsic,
404 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
405 gfc_current_intrinsic_arg[n], gfc_current_intrinsic, &e->where);
411 /* Check the common DIM parameter for correctness. */
414 dim_check (gfc_expr *dim, int n, bool optional)
419 if (type_check (dim, n, BT_INTEGER) == FAILURE)
422 if (scalar_check (dim, n) == FAILURE)
425 if (!optional && nonoptional_check (dim, n) == FAILURE)
432 /* If a coarray DIM parameter is a constant, make sure that it is greater than
433 zero and less than or equal to the corank of the given array. */
436 dim_corank_check (gfc_expr *dim, gfc_expr *array)
441 gcc_assert (array->expr_type == EXPR_VARIABLE);
443 if (dim->expr_type != EXPR_CONSTANT)
446 ar = gfc_find_array_ref (array);
447 corank = ar->as->corank;
449 if (mpz_cmp_ui (dim->value.integer, 1) < 0
450 || mpz_cmp_ui (dim->value.integer, corank) > 0)
452 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
453 "codimension index", gfc_current_intrinsic, &dim->where);
462 /* If a DIM parameter is a constant, make sure that it is greater than
463 zero and less than or equal to the rank of the given array. If
464 allow_assumed is zero then dim must be less than the rank of the array
465 for assumed size arrays. */
468 dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
476 if (dim->expr_type != EXPR_CONSTANT
477 || (array->expr_type != EXPR_VARIABLE
478 && array->expr_type != EXPR_ARRAY))
482 if (array->expr_type == EXPR_VARIABLE)
484 ar = gfc_find_array_ref (array);
485 if (ar->as->type == AS_ASSUMED_SIZE
487 && ar->type != AR_ELEMENT
488 && ar->type != AR_SECTION)
492 if (mpz_cmp_ui (dim->value.integer, 1) < 0
493 || mpz_cmp_ui (dim->value.integer, rank) > 0)
495 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
496 "dimension index", gfc_current_intrinsic, &dim->where);
505 /* Compare the size of a along dimension ai with the size of b along
506 dimension bi, returning 0 if they are known not to be identical,
507 and 1 if they are identical, or if this cannot be determined. */
510 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
512 mpz_t a_size, b_size;
515 gcc_assert (a->rank > ai);
516 gcc_assert (b->rank > bi);
520 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
522 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
524 if (mpz_cmp (a_size, b_size) != 0)
535 /* Check whether two character expressions have the same length;
536 returns SUCCESS if they have or if the length cannot be determined. */
539 gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
544 if (a->ts.u.cl && a->ts.u.cl->length
545 && a->ts.u.cl->length->expr_type == EXPR_CONSTANT)
546 len_a = mpz_get_si (a->ts.u.cl->length->value.integer);
547 else if (a->expr_type == EXPR_CONSTANT
548 && (a->ts.u.cl == NULL || a->ts.u.cl->length == NULL))
549 len_a = a->value.character.length;
553 if (b->ts.u.cl && b->ts.u.cl->length
554 && b->ts.u.cl->length->expr_type == EXPR_CONSTANT)
555 len_b = mpz_get_si (b->ts.u.cl->length->value.integer);
556 else if (b->expr_type == EXPR_CONSTANT
557 && (b->ts.u.cl == NULL || b->ts.u.cl->length == NULL))
558 len_b = b->value.character.length;
565 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
566 len_a, len_b, name, &a->where);
571 /***** Check functions *****/
573 /* Check subroutine suitable for intrinsics taking a real argument and
574 a kind argument for the result. */
577 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
579 if (type_check (a, 0, BT_REAL) == FAILURE)
581 if (kind_check (kind, 1, type) == FAILURE)
588 /* Check subroutine suitable for ceiling, floor and nint. */
591 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
593 return check_a_kind (a, kind, BT_INTEGER);
597 /* Check subroutine suitable for aint, anint. */
600 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
602 return check_a_kind (a, kind, BT_REAL);
607 gfc_check_abs (gfc_expr *a)
609 if (numeric_check (a, 0) == FAILURE)
617 gfc_check_achar (gfc_expr *a, gfc_expr *kind)
619 if (type_check (a, 0, BT_INTEGER) == FAILURE)
621 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
629 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
631 if (type_check (name, 0, BT_CHARACTER) == FAILURE
632 || scalar_check (name, 0) == FAILURE)
634 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
637 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
638 || scalar_check (mode, 1) == FAILURE)
640 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
648 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
650 if (logical_array_check (mask, 0) == FAILURE)
653 if (dim_check (dim, 1, false) == FAILURE)
656 if (dim_rank_check (dim, mask, 0) == FAILURE)
664 gfc_check_allocated (gfc_expr *array)
666 symbol_attribute attr;
668 if (variable_check (array, 0) == FAILURE)
671 attr = gfc_variable_attr (array, NULL);
672 if (!attr.allocatable)
674 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
675 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
684 /* Common check function where the first argument must be real or
685 integer and the second argument must be the same as the first. */
688 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
690 if (int_or_real_check (a, 0) == FAILURE)
693 if (a->ts.type != p->ts.type)
695 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
696 "have the same type", gfc_current_intrinsic_arg[0],
697 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
702 if (a->ts.kind != p->ts.kind)
704 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
705 &p->where) == FAILURE)
714 gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
716 if (double_check (x, 0) == FAILURE || double_check (y, 1) == FAILURE)
724 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
726 symbol_attribute attr1, attr2;
731 where = &pointer->where;
733 if (pointer->expr_type == EXPR_VARIABLE || pointer->expr_type == EXPR_FUNCTION)
734 attr1 = gfc_expr_attr (pointer);
735 else if (pointer->expr_type == EXPR_NULL)
738 gcc_assert (0); /* Pointer must be a variable or a function. */
740 if (!attr1.pointer && !attr1.proc_pointer)
742 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
743 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
748 /* Target argument is optional. */
752 where = &target->where;
753 if (target->expr_type == EXPR_NULL)
756 if (target->expr_type == EXPR_VARIABLE || target->expr_type == EXPR_FUNCTION)
757 attr2 = gfc_expr_attr (target);
760 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
761 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg[1],
762 gfc_current_intrinsic, &target->where);
766 if (attr1.pointer && !attr2.pointer && !attr2.target)
768 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
769 "or a TARGET", gfc_current_intrinsic_arg[1],
770 gfc_current_intrinsic, &target->where);
775 if (same_type_check (pointer, 0, target, 1) == FAILURE)
777 if (rank_check (target, 0, pointer->rank) == FAILURE)
779 if (target->rank > 0)
781 for (i = 0; i < target->rank; i++)
782 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
784 gfc_error ("Array section with a vector subscript at %L shall not "
785 "be the target of a pointer",
795 gfc_error ("NULL pointer at %L is not permitted as actual argument "
796 "of '%s' intrinsic function", where, gfc_current_intrinsic);
803 gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
805 /* gfc_notify_std would be a wast of time as the return value
806 is seemingly used only for the generic resolution. The error
807 will be: Too many arguments. */
808 if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
811 return gfc_check_atan2 (y, x);
816 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
818 if (type_check (y, 0, BT_REAL) == FAILURE)
820 if (same_type_check (y, 0, x, 1) == FAILURE)
827 /* BESJN and BESYN functions. */
830 gfc_check_besn (gfc_expr *n, gfc_expr *x)
832 if (type_check (n, 0, BT_INTEGER) == FAILURE)
835 if (type_check (x, 1, BT_REAL) == FAILURE)
843 gfc_check_bitfcn (gfc_expr *i, gfc_expr *pos)
845 if (type_check (i, 0, BT_INTEGER) == FAILURE)
848 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
851 if (nonnegative_check ("pos", pos) == FAILURE)
854 if (less_than_bitsize1 ("i", i, "pos", pos) == FAILURE)
862 gfc_check_char (gfc_expr *i, gfc_expr *kind)
864 if (type_check (i, 0, BT_INTEGER) == FAILURE)
866 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
874 gfc_check_chdir (gfc_expr *dir)
876 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
878 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
886 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
888 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
890 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
896 if (type_check (status, 1, BT_INTEGER) == FAILURE)
898 if (scalar_check (status, 1) == FAILURE)
906 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
908 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
910 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
913 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
915 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
923 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
925 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
927 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
930 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
932 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
938 if (type_check (status, 2, BT_INTEGER) == FAILURE)
941 if (scalar_check (status, 2) == FAILURE)
949 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
951 if (numeric_check (x, 0) == FAILURE)
956 if (numeric_check (y, 1) == FAILURE)
959 if (x->ts.type == BT_COMPLEX)
961 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
962 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
963 gfc_current_intrinsic, &y->where);
967 if (y->ts.type == BT_COMPLEX)
969 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
970 "of either REAL or INTEGER", gfc_current_intrinsic_arg[1],
971 gfc_current_intrinsic, &y->where);
977 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
985 gfc_check_complex (gfc_expr *x, gfc_expr *y)
987 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
989 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
990 "or REAL", gfc_current_intrinsic_arg[0],
991 gfc_current_intrinsic, &x->where);
994 if (scalar_check (x, 0) == FAILURE)
997 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
999 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
1000 "or REAL", gfc_current_intrinsic_arg[1],
1001 gfc_current_intrinsic, &y->where);
1004 if (scalar_check (y, 1) == FAILURE)
1012 gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
1014 if (logical_array_check (mask, 0) == FAILURE)
1016 if (dim_check (dim, 1, false) == FAILURE)
1018 if (dim_rank_check (dim, mask, 0) == FAILURE)
1020 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1022 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1023 "with KIND argument at %L",
1024 gfc_current_intrinsic, &kind->where) == FAILURE)
1032 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
1034 if (array_check (array, 0) == FAILURE)
1037 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1040 if (dim_check (dim, 2, true) == FAILURE)
1043 if (dim_rank_check (dim, array, false) == FAILURE)
1046 if (array->rank == 1 || shift->rank == 0)
1048 if (scalar_check (shift, 1) == FAILURE)
1051 else if (shift->rank == array->rank - 1)
1056 else if (dim->expr_type == EXPR_CONSTANT)
1057 gfc_extract_int (dim, &d);
1064 for (i = 0, j = 0; i < array->rank; i++)
1067 if (!identical_dimen_shape (array, i, shift, j))
1069 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1070 "invalid shape in dimension %d (%ld/%ld)",
1071 gfc_current_intrinsic_arg[1],
1072 gfc_current_intrinsic, &shift->where, i + 1,
1073 mpz_get_si (array->shape[i]),
1074 mpz_get_si (shift->shape[j]));
1084 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1085 "%d or be a scalar", gfc_current_intrinsic_arg[1],
1086 gfc_current_intrinsic, &shift->where, array->rank - 1);
1095 gfc_check_ctime (gfc_expr *time)
1097 if (scalar_check (time, 0) == FAILURE)
1100 if (type_check (time, 0, BT_INTEGER) == FAILURE)
1107 gfc_try gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
1109 if (double_check (y, 0) == FAILURE || double_check (x, 1) == FAILURE)
1116 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
1118 if (numeric_check (x, 0) == FAILURE)
1123 if (numeric_check (y, 1) == FAILURE)
1126 if (x->ts.type == BT_COMPLEX)
1128 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1129 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
1130 gfc_current_intrinsic, &y->where);
1134 if (y->ts.type == BT_COMPLEX)
1136 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1137 "of either REAL or INTEGER", gfc_current_intrinsic_arg[1],
1138 gfc_current_intrinsic, &y->where);
1148 gfc_check_dble (gfc_expr *x)
1150 if (numeric_check (x, 0) == FAILURE)
1158 gfc_check_digits (gfc_expr *x)
1160 if (int_or_real_check (x, 0) == FAILURE)
1168 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
1170 switch (vector_a->ts.type)
1173 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
1180 if (numeric_check (vector_b, 1) == FAILURE)
1185 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1186 "or LOGICAL", gfc_current_intrinsic_arg[0],
1187 gfc_current_intrinsic, &vector_a->where);
1191 if (rank_check (vector_a, 0, 1) == FAILURE)
1194 if (rank_check (vector_b, 1, 1) == FAILURE)
1197 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
1199 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1200 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0],
1201 gfc_current_intrinsic_arg[1], &vector_a->where);
1210 gfc_check_dprod (gfc_expr *x, gfc_expr *y)
1212 if (type_check (x, 0, BT_REAL) == FAILURE
1213 || type_check (y, 1, BT_REAL) == FAILURE)
1216 if (x->ts.kind != gfc_default_real_kind)
1218 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1219 "real", gfc_current_intrinsic_arg[0],
1220 gfc_current_intrinsic, &x->where);
1224 if (y->ts.kind != gfc_default_real_kind)
1226 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1227 "real", gfc_current_intrinsic_arg[1],
1228 gfc_current_intrinsic, &y->where);
1237 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
1240 if (array_check (array, 0) == FAILURE)
1243 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1246 if (dim_check (dim, 3, true) == FAILURE)
1249 if (dim_rank_check (dim, array, false) == FAILURE)
1252 if (array->rank == 1 || shift->rank == 0)
1254 if (scalar_check (shift, 1) == FAILURE)
1257 else if (shift->rank == array->rank - 1)
1262 else if (dim->expr_type == EXPR_CONSTANT)
1263 gfc_extract_int (dim, &d);
1270 for (i = 0, j = 0; i < array->rank; i++)
1273 if (!identical_dimen_shape (array, i, shift, j))
1275 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1276 "invalid shape in dimension %d (%ld/%ld)",
1277 gfc_current_intrinsic_arg[1],
1278 gfc_current_intrinsic, &shift->where, i + 1,
1279 mpz_get_si (array->shape[i]),
1280 mpz_get_si (shift->shape[j]));
1290 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1291 "%d or be a scalar", gfc_current_intrinsic_arg[1],
1292 gfc_current_intrinsic, &shift->where, array->rank - 1);
1296 if (boundary != NULL)
1298 if (same_type_check (array, 0, boundary, 2) == FAILURE)
1301 if (array->rank == 1 || boundary->rank == 0)
1303 if (scalar_check (boundary, 2) == FAILURE)
1306 else if (boundary->rank == array->rank - 1)
1308 if (gfc_check_conformance (shift, boundary,
1309 "arguments '%s' and '%s' for "
1311 gfc_current_intrinsic_arg[1],
1312 gfc_current_intrinsic_arg[2],
1313 gfc_current_intrinsic ) == FAILURE)
1318 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1319 "rank %d or be a scalar", gfc_current_intrinsic_arg[1],
1320 gfc_current_intrinsic, &shift->where, array->rank - 1);
1329 gfc_check_float (gfc_expr *a)
1331 if (type_check (a, 0, BT_INTEGER) == FAILURE)
1334 if ((a->ts.kind != gfc_default_integer_kind)
1335 && gfc_notify_std (GFC_STD_GNU, "GNU extension: non-default INTEGER"
1336 "kind argument to %s intrinsic at %L",
1337 gfc_current_intrinsic, &a->where) == FAILURE )
1343 /* A single complex argument. */
1346 gfc_check_fn_c (gfc_expr *a)
1348 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
1354 /* A single real argument. */
1357 gfc_check_fn_r (gfc_expr *a)
1359 if (type_check (a, 0, BT_REAL) == FAILURE)
1365 /* A single double argument. */
1368 gfc_check_fn_d (gfc_expr *a)
1370 if (double_check (a, 0) == FAILURE)
1376 /* A single real or complex argument. */
1379 gfc_check_fn_rc (gfc_expr *a)
1381 if (real_or_complex_check (a, 0) == FAILURE)
1389 gfc_check_fn_rc2008 (gfc_expr *a)
1391 if (real_or_complex_check (a, 0) == FAILURE)
1394 if (a->ts.type == BT_COMPLEX
1395 && gfc_notify_std (GFC_STD_F2008, "Fortran 2008: COMPLEX argument '%s' "
1396 "argument of '%s' intrinsic at %L",
1397 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1398 &a->where) == FAILURE)
1406 gfc_check_fnum (gfc_expr *unit)
1408 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1411 if (scalar_check (unit, 0) == FAILURE)
1419 gfc_check_huge (gfc_expr *x)
1421 if (int_or_real_check (x, 0) == FAILURE)
1429 gfc_check_hypot (gfc_expr *x, gfc_expr *y)
1431 if (type_check (x, 0, BT_REAL) == FAILURE)
1433 if (same_type_check (x, 0, y, 1) == FAILURE)
1440 /* Check that the single argument is an integer. */
1443 gfc_check_i (gfc_expr *i)
1445 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1453 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1455 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1458 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1461 if (i->ts.kind != j->ts.kind)
1463 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1464 &i->where) == FAILURE)
1473 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1475 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1478 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1481 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1484 if (nonnegative_check ("pos", pos) == FAILURE)
1487 if (nonnegative_check ("len", len) == FAILURE)
1490 if (less_than_bitsize2 ("i", i, "pos", pos, "len", len) == FAILURE)
1498 gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
1502 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1505 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1508 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1509 "with KIND argument at %L",
1510 gfc_current_intrinsic, &kind->where) == FAILURE)
1513 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1519 /* Substring references don't have the charlength set. */
1521 while (ref && ref->type != REF_SUBSTRING)
1524 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1528 /* Check that the argument is length one. Non-constant lengths
1529 can't be checked here, so assume they are ok. */
1530 if (c->ts.u.cl && c->ts.u.cl->length)
1532 /* If we already have a length for this expression then use it. */
1533 if (c->ts.u.cl->length->expr_type != EXPR_CONSTANT)
1535 i = mpz_get_si (c->ts.u.cl->length->value.integer);
1542 start = ref->u.ss.start;
1543 end = ref->u.ss.end;
1546 if (end == NULL || end->expr_type != EXPR_CONSTANT
1547 || start->expr_type != EXPR_CONSTANT)
1550 i = mpz_get_si (end->value.integer) + 1
1551 - mpz_get_si (start->value.integer);
1559 gfc_error ("Argument of %s at %L must be of length one",
1560 gfc_current_intrinsic, &c->where);
1569 gfc_check_idnint (gfc_expr *a)
1571 if (double_check (a, 0) == FAILURE)
1579 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1581 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1584 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1587 if (i->ts.kind != j->ts.kind)
1589 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1590 &i->where) == FAILURE)
1599 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back,
1602 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1603 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1606 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1609 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
1611 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1612 "with KIND argument at %L",
1613 gfc_current_intrinsic, &kind->where) == FAILURE)
1616 if (string->ts.kind != substring->ts.kind)
1618 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1619 "kind as '%s'", gfc_current_intrinsic_arg[1],
1620 gfc_current_intrinsic, &substring->where,
1621 gfc_current_intrinsic_arg[0]);
1630 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1632 if (numeric_check (x, 0) == FAILURE)
1635 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1643 gfc_check_intconv (gfc_expr *x)
1645 if (numeric_check (x, 0) == FAILURE)
1653 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1655 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1658 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1661 if (i->ts.kind != j->ts.kind)
1663 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1664 &i->where) == FAILURE)
1673 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1675 if (type_check (i, 0, BT_INTEGER) == FAILURE
1676 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1684 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1686 if (type_check (i, 0, BT_INTEGER) == FAILURE
1687 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1690 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1698 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1700 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1703 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1711 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1713 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1716 if (scalar_check (pid, 0) == FAILURE)
1719 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1722 if (scalar_check (sig, 1) == FAILURE)
1728 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1731 if (scalar_check (status, 2) == FAILURE)
1739 gfc_check_kind (gfc_expr *x)
1741 if (x->ts.type == BT_DERIVED)
1743 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1744 "non-derived type", gfc_current_intrinsic_arg[0],
1745 gfc_current_intrinsic, &x->where);
1754 gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1756 if (array_check (array, 0) == FAILURE)
1759 if (dim_check (dim, 1, false) == FAILURE)
1762 if (dim_rank_check (dim, array, 1) == FAILURE)
1765 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1767 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1768 "with KIND argument at %L",
1769 gfc_current_intrinsic, &kind->where) == FAILURE)
1777 gfc_check_lcobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
1779 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
1781 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
1785 if (!is_coarray (coarray))
1787 gfc_error ("Expected coarray variable as '%s' argument to the LCOBOUND "
1788 "intrinsic at %L", gfc_current_intrinsic_arg[0], &coarray->where);
1794 if (dim_check (dim, 1, false) == FAILURE)
1797 if (dim_corank_check (dim, coarray) == FAILURE)
1801 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1809 gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
1811 if (type_check (s, 0, BT_CHARACTER) == FAILURE)
1814 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1816 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1817 "with KIND argument at %L",
1818 gfc_current_intrinsic, &kind->where) == FAILURE)
1826 gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
1828 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1830 if (kind_value_check (a, 0, gfc_default_character_kind) == FAILURE)
1833 if (type_check (b, 1, BT_CHARACTER) == FAILURE)
1835 if (kind_value_check (b, 1, gfc_default_character_kind) == FAILURE)
1843 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
1845 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1847 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1850 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1852 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1860 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1862 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1864 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1867 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1869 if (kind_value_check (path2, 0, gfc_default_character_kind) == FAILURE)
1875 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1878 if (scalar_check (status, 2) == FAILURE)
1886 gfc_check_loc (gfc_expr *expr)
1888 return variable_check (expr, 0);
1893 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
1895 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1897 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1900 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1902 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1910 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1912 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1914 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1917 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1919 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1925 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1928 if (scalar_check (status, 2) == FAILURE)
1936 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
1938 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1940 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1947 /* Min/max family. */
1950 min_max_args (gfc_actual_arglist *arg)
1952 if (arg == NULL || arg->next == NULL)
1954 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1955 gfc_current_intrinsic, gfc_current_intrinsic_where);
1964 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
1966 gfc_actual_arglist *arg, *tmp;
1971 if (min_max_args (arglist) == FAILURE)
1974 for (arg = arglist, n=1; arg; arg = arg->next, n++)
1977 if (x->ts.type != type || x->ts.kind != kind)
1979 if (x->ts.type == type)
1981 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
1982 "kinds at %L", &x->where) == FAILURE)
1987 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1988 "%s(%d)", n, gfc_current_intrinsic, &x->where,
1989 gfc_basic_typename (type), kind);
1994 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
1995 if (gfc_check_conformance (tmp->expr, x,
1996 "arguments 'a%d' and 'a%d' for "
1997 "intrinsic '%s'", m, n,
1998 gfc_current_intrinsic) == FAILURE)
2007 gfc_check_min_max (gfc_actual_arglist *arg)
2011 if (min_max_args (arg) == FAILURE)
2016 if (x->ts.type == BT_CHARACTER)
2018 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2019 "with CHARACTER argument at %L",
2020 gfc_current_intrinsic, &x->where) == FAILURE)
2023 else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
2025 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
2026 "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
2030 return check_rest (x->ts.type, x->ts.kind, arg);
2035 gfc_check_min_max_integer (gfc_actual_arglist *arg)
2037 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
2042 gfc_check_min_max_real (gfc_actual_arglist *arg)
2044 return check_rest (BT_REAL, gfc_default_real_kind, arg);
2049 gfc_check_min_max_double (gfc_actual_arglist *arg)
2051 return check_rest (BT_REAL, gfc_default_double_kind, arg);
2055 /* End of min/max family. */
2058 gfc_check_malloc (gfc_expr *size)
2060 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2063 if (scalar_check (size, 0) == FAILURE)
2071 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
2073 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
2075 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2076 "or LOGICAL", gfc_current_intrinsic_arg[0],
2077 gfc_current_intrinsic, &matrix_a->where);
2081 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
2083 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2084 "or LOGICAL", gfc_current_intrinsic_arg[1],
2085 gfc_current_intrinsic, &matrix_b->where);
2089 if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
2090 || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
2092 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2093 gfc_current_intrinsic, &matrix_a->where,
2094 gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
2098 switch (matrix_a->rank)
2101 if (rank_check (matrix_b, 1, 2) == FAILURE)
2103 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2104 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
2106 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2107 "and '%s' at %L for intrinsic matmul",
2108 gfc_current_intrinsic_arg[0],
2109 gfc_current_intrinsic_arg[1], &matrix_a->where);
2115 if (matrix_b->rank != 2)
2117 if (rank_check (matrix_b, 1, 1) == FAILURE)
2120 /* matrix_b has rank 1 or 2 here. Common check for the cases
2121 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2122 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2123 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
2125 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2126 "dimension 1 for argument '%s' at %L for intrinsic "
2127 "matmul", gfc_current_intrinsic_arg[0],
2128 gfc_current_intrinsic_arg[1], &matrix_a->where);
2134 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2135 "1 or 2", gfc_current_intrinsic_arg[0],
2136 gfc_current_intrinsic, &matrix_a->where);
2144 /* Whoever came up with this interface was probably on something.
2145 The possibilities for the occupation of the second and third
2152 NULL MASK minloc(array, mask=m)
2155 I.e. in the case of minloc(array,mask), mask will be in the second
2156 position of the argument list and we'll have to fix that up. */
2159 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
2161 gfc_expr *a, *m, *d;
2164 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
2168 m = ap->next->next->expr;
2170 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2171 && ap->next->name == NULL)
2175 ap->next->expr = NULL;
2176 ap->next->next->expr = m;
2179 if (dim_check (d, 1, false) == FAILURE)
2182 if (dim_rank_check (d, a, 0) == FAILURE)
2185 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2189 && gfc_check_conformance (a, m,
2190 "arguments '%s' and '%s' for intrinsic %s",
2191 gfc_current_intrinsic_arg[0],
2192 gfc_current_intrinsic_arg[2],
2193 gfc_current_intrinsic ) == FAILURE)
2200 /* Similar to minloc/maxloc, the argument list might need to be
2201 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2202 difference is that MINLOC/MAXLOC take an additional KIND argument.
2203 The possibilities are:
2209 NULL MASK minval(array, mask=m)
2212 I.e. in the case of minval(array,mask), mask will be in the second
2213 position of the argument list and we'll have to fix that up. */
2216 check_reduction (gfc_actual_arglist *ap)
2218 gfc_expr *a, *m, *d;
2222 m = ap->next->next->expr;
2224 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2225 && ap->next->name == NULL)
2229 ap->next->expr = NULL;
2230 ap->next->next->expr = m;
2233 if (dim_check (d, 1, false) == FAILURE)
2236 if (dim_rank_check (d, a, 0) == FAILURE)
2239 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2243 && gfc_check_conformance (a, m,
2244 "arguments '%s' and '%s' for intrinsic %s",
2245 gfc_current_intrinsic_arg[0],
2246 gfc_current_intrinsic_arg[2],
2247 gfc_current_intrinsic) == FAILURE)
2255 gfc_check_minval_maxval (gfc_actual_arglist *ap)
2257 if (int_or_real_check (ap->expr, 0) == FAILURE
2258 || array_check (ap->expr, 0) == FAILURE)
2261 return check_reduction (ap);
2266 gfc_check_product_sum (gfc_actual_arglist *ap)
2268 if (numeric_check (ap->expr, 0) == FAILURE
2269 || array_check (ap->expr, 0) == FAILURE)
2272 return check_reduction (ap);
2277 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
2279 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
2282 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
2285 if (tsource->ts.type == BT_CHARACTER)
2286 return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
2293 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
2295 symbol_attribute attr;
2297 if (variable_check (from, 0) == FAILURE)
2300 attr = gfc_variable_attr (from, NULL);
2301 if (!attr.allocatable)
2303 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2304 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
2309 if (variable_check (to, 0) == FAILURE)
2312 attr = gfc_variable_attr (to, NULL);
2313 if (!attr.allocatable)
2315 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2316 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
2321 if (same_type_check (to, 1, from, 0) == FAILURE)
2324 if (to->rank != from->rank)
2326 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2327 "have the same rank %d/%d", gfc_current_intrinsic_arg[0],
2328 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
2329 &to->where, from->rank, to->rank);
2333 if (to->ts.kind != from->ts.kind)
2335 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2336 "be of the same kind %d/%d", gfc_current_intrinsic_arg[0],
2337 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
2338 &to->where, from->ts.kind, to->ts.kind);
2347 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
2349 if (type_check (x, 0, BT_REAL) == FAILURE)
2352 if (type_check (s, 1, BT_REAL) == FAILURE)
2360 gfc_check_new_line (gfc_expr *a)
2362 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2370 gfc_check_null (gfc_expr *mold)
2372 symbol_attribute attr;
2377 if (variable_check (mold, 0) == FAILURE)
2380 attr = gfc_variable_attr (mold, NULL);
2382 if (!attr.pointer && !attr.proc_pointer)
2384 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
2385 gfc_current_intrinsic_arg[0],
2386 gfc_current_intrinsic, &mold->where);
2395 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
2397 if (array_check (array, 0) == FAILURE)
2400 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2403 if (gfc_check_conformance (array, mask,
2404 "arguments '%s' and '%s' for intrinsic '%s'",
2405 gfc_current_intrinsic_arg[0],
2406 gfc_current_intrinsic_arg[1],
2407 gfc_current_intrinsic) == FAILURE)
2412 mpz_t array_size, vector_size;
2413 bool have_array_size, have_vector_size;
2415 if (same_type_check (array, 0, vector, 2) == FAILURE)
2418 if (rank_check (vector, 2, 1) == FAILURE)
2421 /* VECTOR requires at least as many elements as MASK
2422 has .TRUE. values. */
2423 have_array_size = gfc_array_size (array, &array_size) == SUCCESS;
2424 have_vector_size = gfc_array_size (vector, &vector_size) == SUCCESS;
2426 if (have_vector_size
2427 && (mask->expr_type == EXPR_ARRAY
2428 || (mask->expr_type == EXPR_CONSTANT
2429 && have_array_size)))
2431 int mask_true_values = 0;
2433 if (mask->expr_type == EXPR_ARRAY)
2435 gfc_constructor *mask_ctor;
2436 mask_ctor = gfc_constructor_first (mask->value.constructor);
2439 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
2441 mask_true_values = 0;
2445 if (mask_ctor->expr->value.logical)
2448 mask_ctor = gfc_constructor_next (mask_ctor);
2451 else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
2452 mask_true_values = mpz_get_si (array_size);
2454 if (mpz_get_si (vector_size) < mask_true_values)
2456 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2457 "provide at least as many elements as there "
2458 "are .TRUE. values in '%s' (%ld/%d)",
2459 gfc_current_intrinsic_arg[2],gfc_current_intrinsic,
2460 &vector->where, gfc_current_intrinsic_arg[1],
2461 mpz_get_si (vector_size), mask_true_values);
2466 if (have_array_size)
2467 mpz_clear (array_size);
2468 if (have_vector_size)
2469 mpz_clear (vector_size);
2477 gfc_check_precision (gfc_expr *x)
2479 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
2481 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
2482 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
2483 gfc_current_intrinsic, &x->where);
2492 gfc_check_present (gfc_expr *a)
2496 if (variable_check (a, 0) == FAILURE)
2499 sym = a->symtree->n.sym;
2500 if (!sym->attr.dummy)
2502 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2503 "dummy variable", gfc_current_intrinsic_arg[0],
2504 gfc_current_intrinsic, &a->where);
2508 if (!sym->attr.optional)
2510 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2511 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
2512 gfc_current_intrinsic, &a->where);
2516 /* 13.14.82 PRESENT(A)
2518 Argument. A shall be the name of an optional dummy argument that is
2519 accessible in the subprogram in which the PRESENT function reference
2523 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2524 && a->ref->u.ar.type == AR_FULL))
2526 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2527 "subobject of '%s'", gfc_current_intrinsic_arg[0],
2528 gfc_current_intrinsic, &a->where, sym->name);
2537 gfc_check_radix (gfc_expr *x)
2539 if (int_or_real_check (x, 0) == FAILURE)
2547 gfc_check_range (gfc_expr *x)
2549 if (numeric_check (x, 0) == FAILURE)
2556 /* real, float, sngl. */
2558 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2560 if (numeric_check (a, 0) == FAILURE)
2563 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2571 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2573 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2575 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2578 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2580 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2588 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2590 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2592 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2595 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2597 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2603 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2606 if (scalar_check (status, 2) == FAILURE)
2614 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2616 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2619 if (scalar_check (x, 0) == FAILURE)
2622 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2625 if (scalar_check (y, 1) == FAILURE)
2633 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2634 gfc_expr *pad, gfc_expr *order)
2640 if (array_check (source, 0) == FAILURE)
2643 if (rank_check (shape, 1, 1) == FAILURE)
2646 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2649 if (gfc_array_size (shape, &size) != SUCCESS)
2651 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2652 "array of constant size", &shape->where);
2656 shape_size = mpz_get_ui (size);
2659 if (shape_size <= 0)
2661 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
2662 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
2666 else if (shape_size > GFC_MAX_DIMENSIONS)
2668 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2669 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2672 else if (shape->expr_type == EXPR_ARRAY)
2676 for (i = 0; i < shape_size; ++i)
2678 e = gfc_constructor_lookup_expr (shape->value.constructor, i);
2679 if (e->expr_type != EXPR_CONSTANT)
2682 gfc_extract_int (e, &extent);
2685 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2686 "negative element (%d)", gfc_current_intrinsic_arg[1],
2687 gfc_current_intrinsic, &e->where, extent);
2695 if (same_type_check (source, 0, pad, 2) == FAILURE)
2698 if (array_check (pad, 2) == FAILURE)
2704 if (array_check (order, 3) == FAILURE)
2707 if (type_check (order, 3, BT_INTEGER) == FAILURE)
2710 if (order->expr_type == EXPR_ARRAY)
2712 int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
2715 for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
2718 gfc_array_size (order, &size);
2719 order_size = mpz_get_ui (size);
2722 if (order_size != shape_size)
2724 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2725 "has wrong number of elements (%d/%d)",
2726 gfc_current_intrinsic_arg[3],
2727 gfc_current_intrinsic, &order->where,
2728 order_size, shape_size);
2732 for (i = 1; i <= order_size; ++i)
2734 e = gfc_constructor_lookup_expr (order->value.constructor, i-1);
2735 if (e->expr_type != EXPR_CONSTANT)
2738 gfc_extract_int (e, &dim);
2740 if (dim < 1 || dim > order_size)
2742 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2743 "has out-of-range dimension (%d)",
2744 gfc_current_intrinsic_arg[3],
2745 gfc_current_intrinsic, &e->where, dim);
2749 if (perm[dim-1] != 0)
2751 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2752 "invalid permutation of dimensions (dimension "
2753 "'%d' duplicated)", gfc_current_intrinsic_arg[3],
2754 gfc_current_intrinsic, &e->where, dim);
2763 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2764 && gfc_is_constant_expr (shape)
2765 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2766 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2768 /* Check the match in size between source and destination. */
2769 if (gfc_array_size (source, &nelems) == SUCCESS)
2775 mpz_init_set_ui (size, 1);
2776 for (c = gfc_constructor_first (shape->value.constructor);
2777 c; c = gfc_constructor_next (c))
2778 mpz_mul (size, size, c->expr->value.integer);
2780 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2786 gfc_error ("Without padding, there are not enough elements "
2787 "in the intrinsic RESHAPE source at %L to match "
2788 "the shape", &source->where);
2799 gfc_check_same_type_as (gfc_expr *a, gfc_expr *b)
2802 if (a->ts.type != BT_DERIVED && a->ts.type != BT_CLASS)
2804 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2805 "must be of a derived type", gfc_current_intrinsic_arg[0],
2806 gfc_current_intrinsic, &a->where);
2810 if (!gfc_type_is_extensible (a->ts.u.derived))
2812 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2813 "must be of an extensible type", gfc_current_intrinsic_arg[0],
2814 gfc_current_intrinsic, &a->where);
2818 if (b->ts.type != BT_DERIVED && b->ts.type != BT_CLASS)
2820 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2821 "must be of a derived type", gfc_current_intrinsic_arg[1],
2822 gfc_current_intrinsic, &b->where);
2826 if (!gfc_type_is_extensible (b->ts.u.derived))
2828 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2829 "must be of an extensible type", gfc_current_intrinsic_arg[1],
2830 gfc_current_intrinsic, &b->where);
2839 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2841 if (type_check (x, 0, BT_REAL) == FAILURE)
2844 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2852 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
2854 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2857 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2860 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2863 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
2865 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2866 "with KIND argument at %L",
2867 gfc_current_intrinsic, &kind->where) == FAILURE)
2870 if (same_type_check (x, 0, y, 1) == FAILURE)
2878 gfc_check_secnds (gfc_expr *r)
2880 if (type_check (r, 0, BT_REAL) == FAILURE)
2883 if (kind_value_check (r, 0, 4) == FAILURE)
2886 if (scalar_check (r, 0) == FAILURE)
2894 gfc_check_selected_char_kind (gfc_expr *name)
2896 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2899 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
2902 if (scalar_check (name, 0) == FAILURE)
2910 gfc_check_selected_int_kind (gfc_expr *r)
2912 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2915 if (scalar_check (r, 0) == FAILURE)
2923 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r)
2925 if (p == NULL && r == NULL)
2927 gfc_error ("Missing arguments to %s intrinsic at %L",
2928 gfc_current_intrinsic, gfc_current_intrinsic_where);
2935 if (type_check (p, 0, BT_INTEGER) == FAILURE)
2938 if (scalar_check (p, 0) == FAILURE)
2944 if (type_check (r, 1, BT_INTEGER) == FAILURE)
2947 if (scalar_check (r, 1) == FAILURE)
2956 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
2958 if (type_check (x, 0, BT_REAL) == FAILURE)
2961 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2969 gfc_check_shape (gfc_expr *source)
2973 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2976 ar = gfc_find_array_ref (source);
2978 if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
2980 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2981 "an assumed size array", &source->where);
2990 gfc_check_sign (gfc_expr *a, gfc_expr *b)
2992 if (int_or_real_check (a, 0) == FAILURE)
2995 if (same_type_check (a, 0, b, 1) == FAILURE)
3003 gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3005 if (array_check (array, 0) == FAILURE)
3008 if (dim_check (dim, 1, true) == FAILURE)
3011 if (dim_rank_check (dim, array, 0) == FAILURE)
3014 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3016 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3017 "with KIND argument at %L",
3018 gfc_current_intrinsic, &kind->where) == FAILURE)
3027 gfc_check_sizeof (gfc_expr *arg ATTRIBUTE_UNUSED)
3034 gfc_check_sleep_sub (gfc_expr *seconds)
3036 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3039 if (scalar_check (seconds, 0) == FAILURE)
3046 gfc_check_sngl (gfc_expr *a)
3048 if (type_check (a, 0, BT_REAL) == FAILURE)
3051 if ((a->ts.kind != gfc_default_double_kind)
3052 && gfc_notify_std (GFC_STD_GNU, "GNU extension: non double precision"
3053 "REAL argument to %s intrinsic at %L",
3054 gfc_current_intrinsic, &a->where) == FAILURE)
3061 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
3063 if (source->rank >= GFC_MAX_DIMENSIONS)
3065 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
3066 "than rank %d", gfc_current_intrinsic_arg[0],
3067 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
3075 if (dim_check (dim, 1, false) == FAILURE)
3078 /* dim_rank_check() does not apply here. */
3080 && dim->expr_type == EXPR_CONSTANT
3081 && (mpz_cmp_ui (dim->value.integer, 1) < 0
3082 || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0))
3084 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
3085 "dimension index", gfc_current_intrinsic_arg[1],
3086 gfc_current_intrinsic, &dim->where);
3090 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
3093 if (scalar_check (ncopies, 2) == FAILURE)
3100 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3104 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
3106 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3109 if (scalar_check (unit, 0) == FAILURE)
3112 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
3114 if (kind_value_check (c, 1, gfc_default_character_kind) == FAILURE)
3120 if (type_check (status, 2, BT_INTEGER) == FAILURE
3121 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
3122 || scalar_check (status, 2) == FAILURE)
3130 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
3132 return gfc_check_fgetputc_sub (unit, c, NULL);
3137 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
3139 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
3141 if (kind_value_check (c, 0, gfc_default_character_kind) == FAILURE)
3147 if (type_check (status, 1, BT_INTEGER) == FAILURE
3148 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
3149 || scalar_check (status, 1) == FAILURE)
3157 gfc_check_fgetput (gfc_expr *c)
3159 return gfc_check_fgetput_sub (c, NULL);
3164 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
3166 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3169 if (scalar_check (unit, 0) == FAILURE)
3172 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3175 if (scalar_check (offset, 1) == FAILURE)
3178 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
3181 if (scalar_check (whence, 2) == FAILURE)
3187 if (type_check (status, 3, BT_INTEGER) == FAILURE)
3190 if (kind_value_check (status, 3, 4) == FAILURE)
3193 if (scalar_check (status, 3) == FAILURE)
3202 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
3204 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3207 if (scalar_check (unit, 0) == FAILURE)
3210 if (type_check (array, 1, BT_INTEGER) == FAILURE
3211 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
3214 if (array_check (array, 1) == FAILURE)
3222 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
3224 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3227 if (scalar_check (unit, 0) == FAILURE)
3230 if (type_check (array, 1, BT_INTEGER) == FAILURE
3231 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3234 if (array_check (array, 1) == FAILURE)
3240 if (type_check (status, 2, BT_INTEGER) == FAILURE
3241 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3244 if (scalar_check (status, 2) == FAILURE)
3252 gfc_check_ftell (gfc_expr *unit)
3254 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3257 if (scalar_check (unit, 0) == FAILURE)
3265 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
3267 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3270 if (scalar_check (unit, 0) == FAILURE)
3273 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3276 if (scalar_check (offset, 1) == FAILURE)
3284 gfc_check_stat (gfc_expr *name, gfc_expr *array)
3286 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3288 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3291 if (type_check (array, 1, BT_INTEGER) == FAILURE
3292 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3295 if (array_check (array, 1) == FAILURE)
3303 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
3305 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3307 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3310 if (type_check (array, 1, BT_INTEGER) == FAILURE
3311 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3314 if (array_check (array, 1) == FAILURE)
3320 if (type_check (status, 2, BT_INTEGER) == FAILURE
3321 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3324 if (scalar_check (status, 2) == FAILURE)
3332 gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub)
3334 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3336 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3340 if (!is_coarray (coarray))
3342 gfc_error ("Expected coarray variable as '%s' argument to IMAGE_INDEX "
3343 "intrinsic at %L", gfc_current_intrinsic_arg[0], &coarray->where);
3349 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3350 gfc_current_intrinsic_arg[1], &sub->where);
3359 gfc_check_this_image (gfc_expr *coarray, gfc_expr *dim)
3361 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3363 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3367 if (dim != NULL && coarray == NULL)
3369 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3370 "intrinsic at %L", &dim->where);
3374 if (coarray == NULL)
3377 if (!is_coarray (coarray))
3379 gfc_error ("Expected coarray variable as '%s' argument to THIS_IMAGE "
3380 "intrinsic at %L", gfc_current_intrinsic_arg[0], &coarray->where);
3386 if (dim_check (dim, 1, false) == FAILURE)
3389 if (dim_corank_check (dim, coarray) == FAILURE)
3398 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
3399 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
3401 if (mold->ts.type == BT_HOLLERITH)
3403 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3404 &mold->where, gfc_basic_typename (BT_HOLLERITH));
3410 if (type_check (size, 2, BT_INTEGER) == FAILURE)
3413 if (scalar_check (size, 2) == FAILURE)
3416 if (nonoptional_check (size, 2) == FAILURE)
3425 gfc_check_transpose (gfc_expr *matrix)
3427 if (rank_check (matrix, 0, 2) == FAILURE)
3435 gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3437 if (array_check (array, 0) == FAILURE)
3440 if (dim_check (dim, 1, false) == FAILURE)
3443 if (dim_rank_check (dim, array, 0) == FAILURE)
3446 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3448 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3449 "with KIND argument at %L",
3450 gfc_current_intrinsic, &kind->where) == FAILURE)
3458 gfc_check_ucobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
3460 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3462 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3466 if (!is_coarray (coarray))
3468 gfc_error ("Expected coarray variable as '%s' argument to the UCOBOUND "
3469 "intrinsic at %L", gfc_current_intrinsic_arg[0], &coarray->where);
3475 if (dim_check (dim, 1, false) == FAILURE)
3478 if (dim_corank_check (dim, coarray) == FAILURE)
3482 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3490 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
3494 if (rank_check (vector, 0, 1) == FAILURE)
3497 if (array_check (mask, 1) == FAILURE)
3500 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
3503 if (same_type_check (vector, 0, field, 2) == FAILURE)
3506 if (mask->expr_type == EXPR_ARRAY
3507 && gfc_array_size (vector, &vector_size) == SUCCESS)
3509 int mask_true_count = 0;
3510 gfc_constructor *mask_ctor;
3511 mask_ctor = gfc_constructor_first (mask->value.constructor);
3514 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
3516 mask_true_count = 0;
3520 if (mask_ctor->expr->value.logical)
3523 mask_ctor = gfc_constructor_next (mask_ctor);
3526 if (mpz_get_si (vector_size) < mask_true_count)
3528 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
3529 "provide at least as many elements as there "
3530 "are .TRUE. values in '%s' (%ld/%d)",
3531 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
3532 &vector->where, gfc_current_intrinsic_arg[1],
3533 mpz_get_si (vector_size), mask_true_count);
3537 mpz_clear (vector_size);
3540 if (mask->rank != field->rank && field->rank != 0)
3542 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
3543 "the same rank as '%s' or be a scalar",
3544 gfc_current_intrinsic_arg[2], gfc_current_intrinsic,
3545 &field->where, gfc_current_intrinsic_arg[1]);
3549 if (mask->rank == field->rank)
3552 for (i = 0; i < field->rank; i++)
3553 if (! identical_dimen_shape (mask, i, field, i))
3555 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
3556 "must have identical shape.",
3557 gfc_current_intrinsic_arg[2],
3558 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3568 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
3570 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3573 if (same_type_check (x, 0, y, 1) == FAILURE)
3576 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
3579 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
3581 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3582 "with KIND argument at %L",
3583 gfc_current_intrinsic, &kind->where) == FAILURE)
3591 gfc_check_trim (gfc_expr *x)
3593 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3596 if (scalar_check (x, 0) == FAILURE)
3604 gfc_check_ttynam (gfc_expr *unit)
3606 if (scalar_check (unit, 0) == FAILURE)
3609 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3616 /* Common check function for the half a dozen intrinsics that have a
3617 single real argument. */
3620 gfc_check_x (gfc_expr *x)
3622 if (type_check (x, 0, BT_REAL) == FAILURE)
3629 /************* Check functions for intrinsic subroutines *************/
3632 gfc_check_cpu_time (gfc_expr *time)
3634 if (scalar_check (time, 0) == FAILURE)
3637 if (type_check (time, 0, BT_REAL) == FAILURE)
3640 if (variable_check (time, 0) == FAILURE)
3648 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
3649 gfc_expr *zone, gfc_expr *values)
3653 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3655 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
3657 if (scalar_check (date, 0) == FAILURE)
3659 if (variable_check (date, 0) == FAILURE)
3665 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
3667 if (kind_value_check (time, 1, gfc_default_character_kind) == FAILURE)
3669 if (scalar_check (time, 1) == FAILURE)
3671 if (variable_check (time, 1) == FAILURE)
3677 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
3679 if (kind_value_check (zone, 2, gfc_default_character_kind) == FAILURE)
3681 if (scalar_check (zone, 2) == FAILURE)
3683 if (variable_check (zone, 2) == FAILURE)
3689 if (type_check (values, 3, BT_INTEGER) == FAILURE)
3691 if (array_check (values, 3) == FAILURE)
3693 if (rank_check (values, 3, 1) == FAILURE)
3695 if (variable_check (values, 3) == FAILURE)
3704 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
3705 gfc_expr *to, gfc_expr *topos)
3707 if (type_check (from, 0, BT_INTEGER) == FAILURE)
3710 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
3713 if (type_check (len, 2, BT_INTEGER) == FAILURE)
3716 if (same_type_check (from, 0, to, 3) == FAILURE)
3719 if (variable_check (to, 3) == FAILURE)
3722 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
3725 if (nonnegative_check ("frompos", frompos) == FAILURE)
3728 if (nonnegative_check ("topos", topos) == FAILURE)
3731 if (nonnegative_check ("len", len) == FAILURE)
3734 if (less_than_bitsize2 ("from", from, "frompos", frompos, "len", len)
3738 if (less_than_bitsize2 ("to", to, "topos", topos, "len", len) == FAILURE)
3746 gfc_check_random_number (gfc_expr *harvest)
3748 if (type_check (harvest, 0, BT_REAL) == FAILURE)
3751 if (variable_check (harvest, 0) == FAILURE)
3759 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
3761 unsigned int nargs = 0, kiss_size;
3762 locus *where = NULL;
3763 mpz_t put_size, get_size;
3764 bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
3766 have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
3768 /* Keep the number of bytes in sync with kiss_size in
3769 libgfortran/intrinsics/random.c. */
3770 kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind;
3774 if (size->expr_type != EXPR_VARIABLE
3775 || !size->symtree->n.sym->attr.optional)
3778 if (scalar_check (size, 0) == FAILURE)
3781 if (type_check (size, 0, BT_INTEGER) == FAILURE)
3784 if (variable_check (size, 0) == FAILURE)
3787 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
3793 if (put->expr_type != EXPR_VARIABLE
3794 || !put->symtree->n.sym->attr.optional)
3797 where = &put->where;
3800 if (array_check (put, 1) == FAILURE)
3803 if (rank_check (put, 1, 1) == FAILURE)
3806 if (type_check (put, 1, BT_INTEGER) == FAILURE)
3809 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
3812 if (gfc_array_size (put, &put_size) == SUCCESS
3813 && mpz_get_ui (put_size) < kiss_size)
3814 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3815 "too small (%i/%i)",
3816 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, where,
3817 (int) mpz_get_ui (put_size), kiss_size);
3822 if (get->expr_type != EXPR_VARIABLE
3823 || !get->symtree->n.sym->attr.optional)
3826 where = &get->where;
3829 if (array_check (get, 2) == FAILURE)
3832 if (rank_check (get, 2, 1) == FAILURE)
3835 if (type_check (get, 2, BT_INTEGER) == FAILURE)
3838 if (variable_check (get, 2) == FAILURE)
3841 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
3844 if (gfc_array_size (get, &get_size) == SUCCESS
3845 && mpz_get_ui (get_size) < kiss_size)
3846 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3847 "too small (%i/%i)",
3848 gfc_current_intrinsic_arg[2], gfc_current_intrinsic, where,
3849 (int) mpz_get_ui (get_size), kiss_size);
3852 /* RANDOM_SEED may not have more than one non-optional argument. */
3854 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
3861 gfc_check_second_sub (gfc_expr *time)
3863 if (scalar_check (time, 0) == FAILURE)
3866 if (type_check (time, 0, BT_REAL) == FAILURE)
3869 if (kind_value_check(time, 0, 4) == FAILURE)
3876 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
3877 count, count_rate, and count_max are all optional arguments */
3880 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
3881 gfc_expr *count_max)
3885 if (scalar_check (count, 0) == FAILURE)
3888 if (type_check (count, 0, BT_INTEGER) == FAILURE)
3891 if (variable_check (count, 0) == FAILURE)
3895 if (count_rate != NULL)
3897 if (scalar_check (count_rate, 1) == FAILURE)
3900 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
3903 if (variable_check (count_rate, 1) == FAILURE)
3907 && same_type_check (count, 0, count_rate, 1) == FAILURE)
3912 if (count_max != NULL)
3914 if (scalar_check (count_max, 2) == FAILURE)
3917 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
3920 if (variable_check (count_max, 2) == FAILURE)
3924 && same_type_check (count, 0, count_max, 2) == FAILURE)
3927 if (count_rate != NULL
3928 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
3937 gfc_check_irand (gfc_expr *x)
3942 if (scalar_check (x, 0) == FAILURE)
3945 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3948 if (kind_value_check(x, 0, 4) == FAILURE)
3956 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
3958 if (scalar_check (seconds, 0) == FAILURE)
3961 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3964 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3966 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3967 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3968 gfc_current_intrinsic, &handler->where);
3972 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3978 if (scalar_check (status, 2) == FAILURE)
3981 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3984 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3992 gfc_check_rand (gfc_expr *x)
3997 if (scalar_check (x, 0) == FAILURE)
4000 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4003 if (kind_value_check(x, 0, 4) == FAILURE)
4011 gfc_check_srand (gfc_expr *x)
4013 if (scalar_check (x, 0) == FAILURE)
4016 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4019 if (kind_value_check(x, 0, 4) == FAILURE)
4027 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
4029 if (scalar_check (time, 0) == FAILURE)
4031 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4034 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
4036 if (kind_value_check (result, 1, gfc_default_character_kind) == FAILURE)
4044 gfc_check_dtime_etime (gfc_expr *x)
4046 if (array_check (x, 0) == FAILURE)
4049 if (rank_check (x, 0, 1) == FAILURE)
4052 if (variable_check (x, 0) == FAILURE)
4055 if (type_check (x, 0, BT_REAL) == FAILURE)
4058 if (kind_value_check(x, 0, 4) == FAILURE)
4066 gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
4068 if (array_check (values, 0) == FAILURE)
4071 if (rank_check (values, 0, 1) == FAILURE)
4074 if (variable_check (values, 0) == FAILURE)
4077 if (type_check (values, 0, BT_REAL) == FAILURE)
4080 if (kind_value_check(values, 0, 4) == FAILURE)
4083 if (scalar_check (time, 1) == FAILURE)
4086 if (type_check (time, 1, BT_REAL) == FAILURE)
4089 if (kind_value_check(time, 1, 4) == FAILURE)
4097 gfc_check_fdate_sub (gfc_expr *date)
4099 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
4101 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
4109 gfc_check_gerror (gfc_expr *msg)
4111 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4113 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4121 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
4123 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
4125 if (kind_value_check (cwd, 0, gfc_default_character_kind) == FAILURE)
4131 if (scalar_check (status, 1) == FAILURE)
4134 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4142 gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
4144 if (type_check (pos, 0, BT_INTEGER) == FAILURE)
4147 if (pos->ts.kind > gfc_default_integer_kind)
4149 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4150 "not wider than the default kind (%d)",
4151 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
4152 &pos->where, gfc_default_integer_kind);
4156 if (type_check (value, 1, BT_CHARACTER) == FAILURE)
4158 if (kind_value_check (value, 1, gfc_default_character_kind) == FAILURE)
4166 gfc_check_getlog (gfc_expr *msg)
4168 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4170 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4178 gfc_check_exit (gfc_expr *status)
4183 if (type_check (status, 0, BT_INTEGER) == FAILURE)
4186 if (scalar_check (status, 0) == FAILURE)
4194 gfc_check_flush (gfc_expr *unit)
4199 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4202 if (scalar_check (unit, 0) == FAILURE)
4210 gfc_check_free (gfc_expr *i)
4212 if (type_check (i, 0, BT_INTEGER) == FAILURE)
4215 if (scalar_check (i, 0) == FAILURE)
4223 gfc_check_hostnm (gfc_expr *name)
4225 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4227 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4235 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
4237 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4239 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4245 if (scalar_check (status, 1) == FAILURE)
4248 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4256 gfc_check_itime_idate (gfc_expr *values)
4258 if (array_check (values, 0) == FAILURE)
4261 if (rank_check (values, 0, 1) == FAILURE)
4264 if (variable_check (values, 0) == FAILURE)
4267 if (type_check (values, 0, BT_INTEGER) == FAILURE)
4270 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
4278 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
4280 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4283 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
4286 if (scalar_check (time, 0) == FAILURE)
4289 if (array_check (values, 1) == FAILURE)
4292 if (rank_check (values, 1, 1) == FAILURE)
4295 if (variable_check (values, 1) == FAILURE)
4298 if (type_check (values, 1, BT_INTEGER) == FAILURE)
4301 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
4309 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
4311 if (scalar_check (unit, 0) == FAILURE)
4314 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4317 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
4319 if (kind_value_check (name, 1, gfc_default_character_kind) == FAILURE)
4327 gfc_check_isatty (gfc_expr *unit)
4332 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4335 if (scalar_check (unit, 0) == FAILURE)
4343 gfc_check_isnan (gfc_expr *x)
4345 if (type_check (x, 0, BT_REAL) == FAILURE)
4353 gfc_check_perror (gfc_expr *string)
4355 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
4357 if (kind_value_check (string, 0, gfc_default_character_kind) == FAILURE)
4365 gfc_check_umask (gfc_expr *mask)
4367 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4370 if (scalar_check (mask, 0) == FAILURE)
4378 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
4380 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4383 if (scalar_check (mask, 0) == FAILURE)
4389 if (scalar_check (old, 1) == FAILURE)
4392 if (type_check (old, 1, BT_INTEGER) == FAILURE)
4400 gfc_check_unlink (gfc_expr *name)
4402 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4404 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4412 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
4414 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4416 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4422 if (scalar_check (status, 1) == FAILURE)
4425 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4433 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
4435 if (scalar_check (number, 0) == FAILURE)
4438 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4441 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
4443 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4444 "or PROCEDURE", gfc_current_intrinsic_arg[1],
4445 gfc_current_intrinsic, &handler->where);
4449 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4457 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
4459 if (scalar_check (number, 0) == FAILURE)
4462 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4465 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
4467 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4468 "or PROCEDURE", gfc_current_intrinsic_arg[1],
4469 gfc_current_intrinsic, &handler->where);
4473 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4479 if (type_check (status, 2, BT_INTEGER) == FAILURE)
4482 if (scalar_check (status, 2) == FAILURE)
4490 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
4492 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
4494 if (kind_value_check (cmd, 0, gfc_default_character_kind) == FAILURE)
4497 if (scalar_check (status, 1) == FAILURE)
4500 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4503 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
4510 /* This is used for the GNU intrinsics AND, OR and XOR. */
4512 gfc_check_and (gfc_expr *i, gfc_expr *j)
4514 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
4516 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4517 "or LOGICAL", gfc_current_intrinsic_arg[0],
4518 gfc_current_intrinsic, &i->where);
4522 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
4524 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4525 "or LOGICAL", gfc_current_intrinsic_arg[1],
4526 gfc_current_intrinsic, &j->where);
4530 if (i->ts.type != j->ts.type)
4532 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
4533 "have the same type", gfc_current_intrinsic_arg[0],
4534 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
4539 if (scalar_check (i, 0) == FAILURE)
4542 if (scalar_check (j, 1) == FAILURE)