2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
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)
345 if (dim->expr_type != EXPR_CONSTANT
346 || (array->expr_type != EXPR_VARIABLE
347 && array->expr_type != EXPR_ARRAY))
351 if (array->expr_type == EXPR_VARIABLE)
353 ar = gfc_find_array_ref (array);
354 if (ar->as->type == AS_ASSUMED_SIZE
356 && ar->type != AR_ELEMENT
357 && ar->type != AR_SECTION)
361 if (mpz_cmp_ui (dim->value.integer, 1) < 0
362 || mpz_cmp_ui (dim->value.integer, rank) > 0)
364 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
365 "dimension index", gfc_current_intrinsic, &dim->where);
374 /* Compare the size of a along dimension ai with the size of b along
375 dimension bi, returning 0 if they are known not to be identical,
376 and 1 if they are identical, or if this cannot be determined. */
379 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
381 mpz_t a_size, b_size;
384 gcc_assert (a->rank > ai);
385 gcc_assert (b->rank > bi);
389 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
391 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
393 if (mpz_cmp (a_size, b_size) != 0)
404 /* Check whether two character expressions have the same length;
405 returns SUCCESS if they have or if the length cannot be determined. */
408 gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
413 if (a->ts.u.cl && a->ts.u.cl->length
414 && a->ts.u.cl->length->expr_type == EXPR_CONSTANT)
415 len_a = mpz_get_si (a->ts.u.cl->length->value.integer);
416 else if (a->expr_type == EXPR_CONSTANT
417 && (a->ts.u.cl == NULL || a->ts.u.cl->length == NULL))
418 len_a = a->value.character.length;
422 if (b->ts.u.cl && b->ts.u.cl->length
423 && b->ts.u.cl->length->expr_type == EXPR_CONSTANT)
424 len_b = mpz_get_si (b->ts.u.cl->length->value.integer);
425 else if (b->expr_type == EXPR_CONSTANT
426 && (b->ts.u.cl == NULL || b->ts.u.cl->length == NULL))
427 len_b = b->value.character.length;
434 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
435 len_a, len_b, name, &a->where);
440 /***** Check functions *****/
442 /* Check subroutine suitable for intrinsics taking a real argument and
443 a kind argument for the result. */
446 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
448 if (type_check (a, 0, BT_REAL) == FAILURE)
450 if (kind_check (kind, 1, type) == FAILURE)
457 /* Check subroutine suitable for ceiling, floor and nint. */
460 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
462 return check_a_kind (a, kind, BT_INTEGER);
466 /* Check subroutine suitable for aint, anint. */
469 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
471 return check_a_kind (a, kind, BT_REAL);
476 gfc_check_abs (gfc_expr *a)
478 if (numeric_check (a, 0) == FAILURE)
486 gfc_check_achar (gfc_expr *a, gfc_expr *kind)
488 if (type_check (a, 0, BT_INTEGER) == FAILURE)
490 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
498 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
500 if (type_check (name, 0, BT_CHARACTER) == FAILURE
501 || scalar_check (name, 0) == FAILURE)
503 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
506 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
507 || scalar_check (mode, 1) == FAILURE)
509 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
517 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
519 if (logical_array_check (mask, 0) == FAILURE)
522 if (dim_check (dim, 1, false) == FAILURE)
525 if (dim_rank_check (dim, mask, 0) == FAILURE)
533 gfc_check_allocated (gfc_expr *array)
535 symbol_attribute attr;
537 if (variable_check (array, 0) == FAILURE)
540 attr = gfc_variable_attr (array, NULL);
541 if (!attr.allocatable)
543 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
544 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
549 if (array_check (array, 0) == FAILURE)
556 /* Common check function where the first argument must be real or
557 integer and the second argument must be the same as the first. */
560 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
562 if (int_or_real_check (a, 0) == FAILURE)
565 if (a->ts.type != p->ts.type)
567 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
568 "have the same type", gfc_current_intrinsic_arg[0],
569 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
574 if (a->ts.kind != p->ts.kind)
576 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
577 &p->where) == FAILURE)
586 gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
588 if (double_check (x, 0) == FAILURE || double_check (y, 1) == FAILURE)
596 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
598 symbol_attribute attr1, attr2;
603 where = &pointer->where;
605 if (pointer->expr_type == EXPR_VARIABLE)
606 attr1 = gfc_variable_attr (pointer, NULL);
607 else if (pointer->expr_type == EXPR_FUNCTION)
608 attr1 = pointer->symtree->n.sym->attr;
609 else if (pointer->expr_type == EXPR_NULL)
612 gcc_assert (0); /* Pointer must be a variable or a function. */
614 if (!attr1.pointer && !attr1.proc_pointer)
616 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
617 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
622 /* Target argument is optional. */
626 where = &target->where;
627 if (target->expr_type == EXPR_NULL)
630 if (target->expr_type == EXPR_VARIABLE)
631 attr2 = gfc_variable_attr (target, NULL);
632 else if (target->expr_type == EXPR_FUNCTION)
633 attr2 = target->symtree->n.sym->attr;
636 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
637 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg[1],
638 gfc_current_intrinsic, &target->where);
642 if (attr1.pointer && !attr2.pointer && !attr2.target)
644 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
645 "or a TARGET", gfc_current_intrinsic_arg[1],
646 gfc_current_intrinsic, &target->where);
651 if (same_type_check (pointer, 0, target, 1) == FAILURE)
653 if (rank_check (target, 0, pointer->rank) == FAILURE)
655 if (target->rank > 0)
657 for (i = 0; i < target->rank; i++)
658 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
660 gfc_error ("Array section with a vector subscript at %L shall not "
661 "be the target of a pointer",
671 gfc_error ("NULL pointer at %L is not permitted as actual argument "
672 "of '%s' intrinsic function", where, gfc_current_intrinsic);
679 gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
681 /* gfc_notify_std would be a wast of time as the return value
682 is seemingly used only for the generic resolution. The error
683 will be: Too many arguments. */
684 if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
687 return gfc_check_atan2 (y, x);
692 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
694 if (type_check (y, 0, BT_REAL) == FAILURE)
696 if (same_type_check (y, 0, x, 1) == FAILURE)
703 /* BESJN and BESYN functions. */
706 gfc_check_besn (gfc_expr *n, gfc_expr *x)
708 if (type_check (n, 0, BT_INTEGER) == FAILURE)
711 if (type_check (x, 1, BT_REAL) == FAILURE)
719 gfc_check_btest (gfc_expr *i, gfc_expr *pos)
721 if (type_check (i, 0, BT_INTEGER) == FAILURE)
723 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
731 gfc_check_char (gfc_expr *i, gfc_expr *kind)
733 if (type_check (i, 0, BT_INTEGER) == FAILURE)
735 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
743 gfc_check_chdir (gfc_expr *dir)
745 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
747 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
755 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
757 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
759 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
765 if (type_check (status, 1, BT_INTEGER) == FAILURE)
767 if (scalar_check (status, 1) == FAILURE)
775 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
777 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
779 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
782 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
784 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
792 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
794 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
796 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
799 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
801 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
807 if (type_check (status, 2, BT_INTEGER) == FAILURE)
810 if (scalar_check (status, 2) == FAILURE)
818 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
820 if (numeric_check (x, 0) == FAILURE)
825 if (numeric_check (y, 1) == FAILURE)
828 if (x->ts.type == BT_COMPLEX)
830 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
831 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
832 gfc_current_intrinsic, &y->where);
836 if (y->ts.type == BT_COMPLEX)
838 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
839 "of either REAL or INTEGER", gfc_current_intrinsic_arg[1],
840 gfc_current_intrinsic, &y->where);
846 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
854 gfc_check_complex (gfc_expr *x, gfc_expr *y)
856 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
858 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
859 "or REAL", gfc_current_intrinsic_arg[0],
860 gfc_current_intrinsic, &x->where);
863 if (scalar_check (x, 0) == FAILURE)
866 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
868 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
869 "or REAL", gfc_current_intrinsic_arg[1],
870 gfc_current_intrinsic, &y->where);
873 if (scalar_check (y, 1) == FAILURE)
881 gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
883 if (logical_array_check (mask, 0) == FAILURE)
885 if (dim_check (dim, 1, false) == FAILURE)
887 if (dim_rank_check (dim, mask, 0) == FAILURE)
889 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
891 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
892 "with KIND argument at %L",
893 gfc_current_intrinsic, &kind->where) == FAILURE)
901 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
903 if (array_check (array, 0) == FAILURE)
906 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
909 if (dim_check (dim, 2, true) == FAILURE)
912 if (dim_rank_check (dim, array, false) == FAILURE)
915 if (array->rank == 1 || shift->rank == 0)
917 if (scalar_check (shift, 1) == FAILURE)
920 else if (shift->rank == array->rank - 1)
925 else if (dim->expr_type == EXPR_CONSTANT)
926 gfc_extract_int (dim, &d);
933 for (i = 0, j = 0; i < array->rank; i++)
936 if (!identical_dimen_shape (array, i, shift, j))
938 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
939 "invalid shape in dimension %d (%ld/%ld)",
940 gfc_current_intrinsic_arg[1],
941 gfc_current_intrinsic, &shift->where, i + 1,
942 mpz_get_si (array->shape[i]),
943 mpz_get_si (shift->shape[j]));
953 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
954 "%d or be a scalar", gfc_current_intrinsic_arg[1],
955 gfc_current_intrinsic, &shift->where, array->rank - 1);
964 gfc_check_ctime (gfc_expr *time)
966 if (scalar_check (time, 0) == FAILURE)
969 if (type_check (time, 0, BT_INTEGER) == FAILURE)
976 gfc_try gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
978 if (double_check (y, 0) == FAILURE || double_check (x, 1) == FAILURE)
985 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
987 if (numeric_check (x, 0) == FAILURE)
992 if (numeric_check (y, 1) == FAILURE)
995 if (x->ts.type == BT_COMPLEX)
997 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
998 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
999 gfc_current_intrinsic, &y->where);
1003 if (y->ts.type == BT_COMPLEX)
1005 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1006 "of either REAL or INTEGER", gfc_current_intrinsic_arg[1],
1007 gfc_current_intrinsic, &y->where);
1017 gfc_check_dble (gfc_expr *x)
1019 if (numeric_check (x, 0) == FAILURE)
1027 gfc_check_digits (gfc_expr *x)
1029 if (int_or_real_check (x, 0) == FAILURE)
1037 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
1039 switch (vector_a->ts.type)
1042 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
1049 if (numeric_check (vector_b, 1) == FAILURE)
1054 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1055 "or LOGICAL", gfc_current_intrinsic_arg[0],
1056 gfc_current_intrinsic, &vector_a->where);
1060 if (rank_check (vector_a, 0, 1) == FAILURE)
1063 if (rank_check (vector_b, 1, 1) == FAILURE)
1066 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
1068 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1069 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0],
1070 gfc_current_intrinsic_arg[1], &vector_a->where);
1079 gfc_check_dprod (gfc_expr *x, gfc_expr *y)
1081 if (type_check (x, 0, BT_REAL) == FAILURE
1082 || type_check (y, 1, BT_REAL) == FAILURE)
1085 if (x->ts.kind != gfc_default_real_kind)
1087 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1088 "real", gfc_current_intrinsic_arg[0],
1089 gfc_current_intrinsic, &x->where);
1093 if (y->ts.kind != gfc_default_real_kind)
1095 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1096 "real", gfc_current_intrinsic_arg[1],
1097 gfc_current_intrinsic, &y->where);
1106 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
1109 if (array_check (array, 0) == FAILURE)
1112 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1115 if (dim_check (dim, 3, true) == FAILURE)
1118 if (dim_rank_check (dim, array, false) == FAILURE)
1121 if (array->rank == 1 || shift->rank == 0)
1123 if (scalar_check (shift, 1) == FAILURE)
1126 else if (shift->rank == array->rank - 1)
1131 else if (dim->expr_type == EXPR_CONSTANT)
1132 gfc_extract_int (dim, &d);
1139 for (i = 0, j = 0; i < array->rank; i++)
1142 if (!identical_dimen_shape (array, i, shift, j))
1144 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1145 "invalid shape in dimension %d (%ld/%ld)",
1146 gfc_current_intrinsic_arg[1],
1147 gfc_current_intrinsic, &shift->where, i + 1,
1148 mpz_get_si (array->shape[i]),
1149 mpz_get_si (shift->shape[j]));
1159 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1160 "%d or be a scalar", gfc_current_intrinsic_arg[1],
1161 gfc_current_intrinsic, &shift->where, array->rank - 1);
1165 if (boundary != NULL)
1167 if (same_type_check (array, 0, boundary, 2) == FAILURE)
1170 if (array->rank == 1 || boundary->rank == 0)
1172 if (scalar_check (boundary, 2) == FAILURE)
1175 else if (boundary->rank == array->rank - 1)
1177 if (gfc_check_conformance (shift, boundary,
1178 "arguments '%s' and '%s' for "
1180 gfc_current_intrinsic_arg[1],
1181 gfc_current_intrinsic_arg[2],
1182 gfc_current_intrinsic ) == FAILURE)
1187 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1188 "rank %d or be a scalar", gfc_current_intrinsic_arg[1],
1189 gfc_current_intrinsic, &shift->where, array->rank - 1);
1198 /* A single complex argument. */
1201 gfc_check_fn_c (gfc_expr *a)
1203 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
1210 /* A single real argument. */
1213 gfc_check_fn_r (gfc_expr *a)
1215 if (type_check (a, 0, BT_REAL) == FAILURE)
1221 /* A single double argument. */
1224 gfc_check_fn_d (gfc_expr *a)
1226 if (double_check (a, 0) == FAILURE)
1232 /* A single real or complex argument. */
1235 gfc_check_fn_rc (gfc_expr *a)
1237 if (real_or_complex_check (a, 0) == FAILURE)
1245 gfc_check_fn_rc2008 (gfc_expr *a)
1247 if (real_or_complex_check (a, 0) == FAILURE)
1250 if (a->ts.type == BT_COMPLEX
1251 && gfc_notify_std (GFC_STD_F2008, "Fortran 2008: COMPLEX argument '%s' "
1252 "argument of '%s' intrinsic at %L",
1253 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
1254 &a->where) == FAILURE)
1262 gfc_check_fnum (gfc_expr *unit)
1264 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1267 if (scalar_check (unit, 0) == FAILURE)
1275 gfc_check_huge (gfc_expr *x)
1277 if (int_or_real_check (x, 0) == FAILURE)
1285 gfc_check_hypot (gfc_expr *x, gfc_expr *y)
1287 if (type_check (x, 0, BT_REAL) == FAILURE)
1289 if (same_type_check (x, 0, y, 1) == FAILURE)
1296 /* Check that the single argument is an integer. */
1299 gfc_check_i (gfc_expr *i)
1301 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1309 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1311 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1314 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1317 if (i->ts.kind != j->ts.kind)
1319 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1320 &i->where) == FAILURE)
1329 gfc_check_ibclr (gfc_expr *i, gfc_expr *pos)
1331 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1334 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1342 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1344 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1347 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1350 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1358 gfc_check_ibset (gfc_expr *i, gfc_expr *pos)
1360 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1363 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1371 gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
1375 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1378 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1381 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1382 "with KIND argument at %L",
1383 gfc_current_intrinsic, &kind->where) == FAILURE)
1386 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1392 /* Substring references don't have the charlength set. */
1394 while (ref && ref->type != REF_SUBSTRING)
1397 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1401 /* Check that the argument is length one. Non-constant lengths
1402 can't be checked here, so assume they are ok. */
1403 if (c->ts.u.cl && c->ts.u.cl->length)
1405 /* If we already have a length for this expression then use it. */
1406 if (c->ts.u.cl->length->expr_type != EXPR_CONSTANT)
1408 i = mpz_get_si (c->ts.u.cl->length->value.integer);
1415 start = ref->u.ss.start;
1416 end = ref->u.ss.end;
1419 if (end == NULL || end->expr_type != EXPR_CONSTANT
1420 || start->expr_type != EXPR_CONSTANT)
1423 i = mpz_get_si (end->value.integer) + 1
1424 - mpz_get_si (start->value.integer);
1432 gfc_error ("Argument of %s at %L must be of length one",
1433 gfc_current_intrinsic, &c->where);
1442 gfc_check_idnint (gfc_expr *a)
1444 if (double_check (a, 0) == FAILURE)
1452 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1454 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1457 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1460 if (i->ts.kind != j->ts.kind)
1462 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1463 &i->where) == FAILURE)
1472 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back,
1475 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1476 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1479 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1482 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
1484 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1485 "with KIND argument at %L",
1486 gfc_current_intrinsic, &kind->where) == FAILURE)
1489 if (string->ts.kind != substring->ts.kind)
1491 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1492 "kind as '%s'", gfc_current_intrinsic_arg[1],
1493 gfc_current_intrinsic, &substring->where,
1494 gfc_current_intrinsic_arg[0]);
1503 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1505 if (numeric_check (x, 0) == FAILURE)
1508 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1516 gfc_check_intconv (gfc_expr *x)
1518 if (numeric_check (x, 0) == FAILURE)
1526 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1528 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1531 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1534 if (i->ts.kind != j->ts.kind)
1536 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1537 &i->where) == FAILURE)
1546 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1548 if (type_check (i, 0, BT_INTEGER) == FAILURE
1549 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1557 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1559 if (type_check (i, 0, BT_INTEGER) == FAILURE
1560 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1563 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1571 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1573 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1576 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1584 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1586 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1589 if (scalar_check (pid, 0) == FAILURE)
1592 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1595 if (scalar_check (sig, 1) == FAILURE)
1601 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1604 if (scalar_check (status, 2) == FAILURE)
1612 gfc_check_kind (gfc_expr *x)
1614 if (x->ts.type == BT_DERIVED)
1616 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1617 "non-derived type", gfc_current_intrinsic_arg[0],
1618 gfc_current_intrinsic, &x->where);
1627 gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1629 if (array_check (array, 0) == FAILURE)
1632 if (dim_check (dim, 1, false) == FAILURE)
1635 if (dim_rank_check (dim, array, 1) == FAILURE)
1638 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1640 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1641 "with KIND argument at %L",
1642 gfc_current_intrinsic, &kind->where) == FAILURE)
1650 gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
1652 if (type_check (s, 0, BT_CHARACTER) == FAILURE)
1655 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1657 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1658 "with KIND argument at %L",
1659 gfc_current_intrinsic, &kind->where) == FAILURE)
1667 gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
1669 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1671 if (kind_value_check (a, 0, gfc_default_character_kind) == FAILURE)
1674 if (type_check (b, 1, BT_CHARACTER) == FAILURE)
1676 if (kind_value_check (b, 1, gfc_default_character_kind) == FAILURE)
1684 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
1686 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1688 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1691 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1693 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1701 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1703 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1705 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1708 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1710 if (kind_value_check (path2, 0, gfc_default_character_kind) == FAILURE)
1716 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1719 if (scalar_check (status, 2) == FAILURE)
1727 gfc_check_loc (gfc_expr *expr)
1729 return variable_check (expr, 0);
1734 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
1736 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1738 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1741 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1743 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1751 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1753 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1755 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1758 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1760 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1766 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1769 if (scalar_check (status, 2) == FAILURE)
1777 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
1779 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1781 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1788 /* Min/max family. */
1791 min_max_args (gfc_actual_arglist *arg)
1793 if (arg == NULL || arg->next == NULL)
1795 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1796 gfc_current_intrinsic, gfc_current_intrinsic_where);
1805 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
1807 gfc_actual_arglist *arg, *tmp;
1812 if (min_max_args (arglist) == FAILURE)
1815 for (arg = arglist, n=1; arg; arg = arg->next, n++)
1818 if (x->ts.type != type || x->ts.kind != kind)
1820 if (x->ts.type == type)
1822 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
1823 "kinds at %L", &x->where) == FAILURE)
1828 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1829 "%s(%d)", n, gfc_current_intrinsic, &x->where,
1830 gfc_basic_typename (type), kind);
1835 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
1836 if (gfc_check_conformance (tmp->expr, x,
1837 "arguments 'a%d' and 'a%d' for "
1838 "intrinsic '%s'", m, n,
1839 gfc_current_intrinsic) == FAILURE)
1848 gfc_check_min_max (gfc_actual_arglist *arg)
1852 if (min_max_args (arg) == FAILURE)
1857 if (x->ts.type == BT_CHARACTER)
1859 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1860 "with CHARACTER argument at %L",
1861 gfc_current_intrinsic, &x->where) == FAILURE)
1864 else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1866 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
1867 "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
1871 return check_rest (x->ts.type, x->ts.kind, arg);
1876 gfc_check_min_max_integer (gfc_actual_arglist *arg)
1878 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1883 gfc_check_min_max_real (gfc_actual_arglist *arg)
1885 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1890 gfc_check_min_max_double (gfc_actual_arglist *arg)
1892 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1896 /* End of min/max family. */
1899 gfc_check_malloc (gfc_expr *size)
1901 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1904 if (scalar_check (size, 0) == FAILURE)
1912 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
1914 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1916 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1917 "or LOGICAL", gfc_current_intrinsic_arg[0],
1918 gfc_current_intrinsic, &matrix_a->where);
1922 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1924 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1925 "or LOGICAL", gfc_current_intrinsic_arg[1],
1926 gfc_current_intrinsic, &matrix_b->where);
1930 if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
1931 || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
1933 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
1934 gfc_current_intrinsic, &matrix_a->where,
1935 gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
1939 switch (matrix_a->rank)
1942 if (rank_check (matrix_b, 1, 2) == FAILURE)
1944 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
1945 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
1947 gfc_error ("Different shape on dimension 1 for arguments '%s' "
1948 "and '%s' at %L for intrinsic matmul",
1949 gfc_current_intrinsic_arg[0],
1950 gfc_current_intrinsic_arg[1], &matrix_a->where);
1956 if (matrix_b->rank != 2)
1958 if (rank_check (matrix_b, 1, 1) == FAILURE)
1961 /* matrix_b has rank 1 or 2 here. Common check for the cases
1962 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
1963 - matrix_a has shape (n,m) and matrix_b has shape (m). */
1964 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
1966 gfc_error ("Different shape on dimension 2 for argument '%s' and "
1967 "dimension 1 for argument '%s' at %L for intrinsic "
1968 "matmul", gfc_current_intrinsic_arg[0],
1969 gfc_current_intrinsic_arg[1], &matrix_a->where);
1975 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1976 "1 or 2", gfc_current_intrinsic_arg[0],
1977 gfc_current_intrinsic, &matrix_a->where);
1985 /* Whoever came up with this interface was probably on something.
1986 The possibilities for the occupation of the second and third
1993 NULL MASK minloc(array, mask=m)
1996 I.e. in the case of minloc(array,mask), mask will be in the second
1997 position of the argument list and we'll have to fix that up. */
2000 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
2002 gfc_expr *a, *m, *d;
2005 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
2009 m = ap->next->next->expr;
2011 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2012 && ap->next->name == NULL)
2016 ap->next->expr = NULL;
2017 ap->next->next->expr = m;
2020 if (dim_check (d, 1, false) == FAILURE)
2023 if (dim_rank_check (d, a, 0) == FAILURE)
2026 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2030 && gfc_check_conformance (a, m,
2031 "arguments '%s' and '%s' for intrinsic %s",
2032 gfc_current_intrinsic_arg[0],
2033 gfc_current_intrinsic_arg[2],
2034 gfc_current_intrinsic ) == FAILURE)
2041 /* Similar to minloc/maxloc, the argument list might need to be
2042 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2043 difference is that MINLOC/MAXLOC take an additional KIND argument.
2044 The possibilities are:
2050 NULL MASK minval(array, mask=m)
2053 I.e. in the case of minval(array,mask), mask will be in the second
2054 position of the argument list and we'll have to fix that up. */
2057 check_reduction (gfc_actual_arglist *ap)
2059 gfc_expr *a, *m, *d;
2063 m = ap->next->next->expr;
2065 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2066 && ap->next->name == NULL)
2070 ap->next->expr = NULL;
2071 ap->next->next->expr = m;
2074 if (dim_check (d, 1, false) == FAILURE)
2077 if (dim_rank_check (d, a, 0) == FAILURE)
2080 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2084 && gfc_check_conformance (a, m,
2085 "arguments '%s' and '%s' for intrinsic %s",
2086 gfc_current_intrinsic_arg[0],
2087 gfc_current_intrinsic_arg[2],
2088 gfc_current_intrinsic) == FAILURE)
2096 gfc_check_minval_maxval (gfc_actual_arglist *ap)
2098 if (int_or_real_check (ap->expr, 0) == FAILURE
2099 || array_check (ap->expr, 0) == FAILURE)
2102 return check_reduction (ap);
2107 gfc_check_product_sum (gfc_actual_arglist *ap)
2109 if (numeric_check (ap->expr, 0) == FAILURE
2110 || array_check (ap->expr, 0) == FAILURE)
2113 return check_reduction (ap);
2118 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
2120 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
2123 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
2126 if (tsource->ts.type == BT_CHARACTER)
2127 return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
2134 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
2136 symbol_attribute attr;
2138 if (variable_check (from, 0) == FAILURE)
2141 if (array_check (from, 0) == FAILURE)
2144 attr = gfc_variable_attr (from, NULL);
2145 if (!attr.allocatable)
2147 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2148 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
2153 if (variable_check (to, 0) == FAILURE)
2156 if (array_check (to, 0) == FAILURE)
2159 attr = gfc_variable_attr (to, NULL);
2160 if (!attr.allocatable)
2162 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2163 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
2168 if (same_type_check (from, 0, to, 1) == FAILURE)
2171 if (to->rank != from->rank)
2173 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2174 "have the same rank %d/%d", gfc_current_intrinsic_arg[0],
2175 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
2176 &to->where, from->rank, to->rank);
2180 if (to->ts.kind != from->ts.kind)
2182 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2183 "be of the same kind %d/%d", gfc_current_intrinsic_arg[0],
2184 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
2185 &to->where, from->ts.kind, to->ts.kind);
2194 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
2196 if (type_check (x, 0, BT_REAL) == FAILURE)
2199 if (type_check (s, 1, BT_REAL) == FAILURE)
2207 gfc_check_new_line (gfc_expr *a)
2209 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2217 gfc_check_null (gfc_expr *mold)
2219 symbol_attribute attr;
2224 if (variable_check (mold, 0) == FAILURE)
2227 attr = gfc_variable_attr (mold, NULL);
2229 if (!attr.pointer && !attr.proc_pointer)
2231 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
2232 gfc_current_intrinsic_arg[0],
2233 gfc_current_intrinsic, &mold->where);
2242 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
2244 if (array_check (array, 0) == FAILURE)
2247 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2250 if (gfc_check_conformance (array, mask,
2251 "arguments '%s' and '%s' for intrinsic '%s'",
2252 gfc_current_intrinsic_arg[0],
2253 gfc_current_intrinsic_arg[1],
2254 gfc_current_intrinsic) == FAILURE)
2259 mpz_t array_size, vector_size;
2260 bool have_array_size, have_vector_size;
2262 if (same_type_check (array, 0, vector, 2) == FAILURE)
2265 if (rank_check (vector, 2, 1) == FAILURE)
2268 /* VECTOR requires at least as many elements as MASK
2269 has .TRUE. values. */
2270 have_array_size = gfc_array_size (array, &array_size) == SUCCESS;
2271 have_vector_size = gfc_array_size (vector, &vector_size) == SUCCESS;
2273 if (have_vector_size
2274 && (mask->expr_type == EXPR_ARRAY
2275 || (mask->expr_type == EXPR_CONSTANT
2276 && have_array_size)))
2278 int mask_true_values = 0;
2280 if (mask->expr_type == EXPR_ARRAY)
2282 gfc_constructor *mask_ctor = mask->value.constructor;
2285 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
2287 mask_true_values = 0;
2291 if (mask_ctor->expr->value.logical)
2294 mask_ctor = mask_ctor->next;
2297 else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
2298 mask_true_values = mpz_get_si (array_size);
2300 if (mpz_get_si (vector_size) < mask_true_values)
2302 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2303 "provide at least as many elements as there "
2304 "are .TRUE. values in '%s' (%ld/%d)",
2305 gfc_current_intrinsic_arg[2],gfc_current_intrinsic,
2306 &vector->where, gfc_current_intrinsic_arg[1],
2307 mpz_get_si (vector_size), mask_true_values);
2312 if (have_array_size)
2313 mpz_clear (array_size);
2314 if (have_vector_size)
2315 mpz_clear (vector_size);
2323 gfc_check_precision (gfc_expr *x)
2325 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
2327 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
2328 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
2329 gfc_current_intrinsic, &x->where);
2338 gfc_check_present (gfc_expr *a)
2342 if (variable_check (a, 0) == FAILURE)
2345 sym = a->symtree->n.sym;
2346 if (!sym->attr.dummy)
2348 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2349 "dummy variable", gfc_current_intrinsic_arg[0],
2350 gfc_current_intrinsic, &a->where);
2354 if (!sym->attr.optional)
2356 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2357 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
2358 gfc_current_intrinsic, &a->where);
2362 /* 13.14.82 PRESENT(A)
2364 Argument. A shall be the name of an optional dummy argument that is
2365 accessible in the subprogram in which the PRESENT function reference
2369 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2370 && a->ref->u.ar.type == AR_FULL))
2372 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2373 "subobject of '%s'", gfc_current_intrinsic_arg[0],
2374 gfc_current_intrinsic, &a->where, sym->name);
2383 gfc_check_radix (gfc_expr *x)
2385 if (int_or_real_check (x, 0) == FAILURE)
2393 gfc_check_range (gfc_expr *x)
2395 if (numeric_check (x, 0) == FAILURE)
2402 /* real, float, sngl. */
2404 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2406 if (numeric_check (a, 0) == FAILURE)
2409 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2417 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2419 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2421 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2424 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2426 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2434 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2436 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2438 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2441 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2443 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2449 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2452 if (scalar_check (status, 2) == FAILURE)
2460 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2462 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2465 if (scalar_check (x, 0) == FAILURE)
2468 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2471 if (scalar_check (y, 1) == FAILURE)
2479 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2480 gfc_expr *pad, gfc_expr *order)
2486 if (array_check (source, 0) == FAILURE)
2489 if (rank_check (shape, 1, 1) == FAILURE)
2492 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2495 if (gfc_array_size (shape, &size) != SUCCESS)
2497 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2498 "array of constant size", &shape->where);
2502 shape_size = mpz_get_ui (size);
2505 if (shape_size <= 0)
2507 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
2508 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
2512 else if (shape_size > GFC_MAX_DIMENSIONS)
2514 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2515 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2518 else if (shape->expr_type == EXPR_ARRAY)
2522 for (i = 0; i < shape_size; ++i)
2524 e = gfc_get_array_element (shape, i);
2525 if (e->expr_type != EXPR_CONSTANT)
2531 gfc_extract_int (e, &extent);
2534 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2535 "negative element (%d)", gfc_current_intrinsic_arg[1],
2536 gfc_current_intrinsic, &e->where, extent);
2546 if (same_type_check (source, 0, pad, 2) == FAILURE)
2549 if (array_check (pad, 2) == FAILURE)
2555 if (array_check (order, 3) == FAILURE)
2558 if (type_check (order, 3, BT_INTEGER) == FAILURE)
2561 if (order->expr_type == EXPR_ARRAY)
2563 int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
2566 for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
2569 gfc_array_size (order, &size);
2570 order_size = mpz_get_ui (size);
2573 if (order_size != shape_size)
2575 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2576 "has wrong number of elements (%d/%d)",
2577 gfc_current_intrinsic_arg[3],
2578 gfc_current_intrinsic, &order->where,
2579 order_size, shape_size);
2583 for (i = 1; i <= order_size; ++i)
2585 e = gfc_get_array_element (order, i-1);
2586 if (e->expr_type != EXPR_CONSTANT)
2592 gfc_extract_int (e, &dim);
2594 if (dim < 1 || dim > order_size)
2596 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2597 "has out-of-range dimension (%d)",
2598 gfc_current_intrinsic_arg[3],
2599 gfc_current_intrinsic, &e->where, dim);
2603 if (perm[dim-1] != 0)
2605 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2606 "invalid permutation of dimensions (dimension "
2607 "'%d' duplicated)", gfc_current_intrinsic_arg[3],
2608 gfc_current_intrinsic, &e->where, dim);
2618 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2619 && gfc_is_constant_expr (shape)
2620 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2621 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2623 /* Check the match in size between source and destination. */
2624 if (gfc_array_size (source, &nelems) == SUCCESS)
2629 c = shape->value.constructor;
2630 mpz_init_set_ui (size, 1);
2631 for (; c; c = c->next)
2632 mpz_mul (size, size, c->expr->value.integer);
2634 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2640 gfc_error ("Without padding, there are not enough elements "
2641 "in the intrinsic RESHAPE source at %L to match "
2642 "the shape", &source->where);
2653 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2655 if (type_check (x, 0, BT_REAL) == FAILURE)
2658 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2666 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
2668 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2671 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2674 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2677 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
2679 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2680 "with KIND argument at %L",
2681 gfc_current_intrinsic, &kind->where) == FAILURE)
2684 if (same_type_check (x, 0, y, 1) == FAILURE)
2692 gfc_check_secnds (gfc_expr *r)
2694 if (type_check (r, 0, BT_REAL) == FAILURE)
2697 if (kind_value_check (r, 0, 4) == FAILURE)
2700 if (scalar_check (r, 0) == FAILURE)
2708 gfc_check_selected_char_kind (gfc_expr *name)
2710 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2713 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
2716 if (scalar_check (name, 0) == FAILURE)
2724 gfc_check_selected_int_kind (gfc_expr *r)
2726 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2729 if (scalar_check (r, 0) == FAILURE)
2737 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r)
2739 if (p == NULL && r == NULL)
2741 gfc_error ("Missing arguments to %s intrinsic at %L",
2742 gfc_current_intrinsic, gfc_current_intrinsic_where);
2747 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
2750 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
2758 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
2760 if (type_check (x, 0, BT_REAL) == FAILURE)
2763 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2771 gfc_check_shape (gfc_expr *source)
2775 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2778 ar = gfc_find_array_ref (source);
2780 if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
2782 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2783 "an assumed size array", &source->where);
2792 gfc_check_sign (gfc_expr *a, gfc_expr *b)
2794 if (int_or_real_check (a, 0) == FAILURE)
2797 if (same_type_check (a, 0, b, 1) == FAILURE)
2805 gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2807 if (array_check (array, 0) == FAILURE)
2810 if (dim_check (dim, 1, true) == FAILURE)
2813 if (dim_rank_check (dim, array, 0) == FAILURE)
2816 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
2818 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2819 "with KIND argument at %L",
2820 gfc_current_intrinsic, &kind->where) == FAILURE)
2829 gfc_check_sizeof (gfc_expr *arg ATTRIBUTE_UNUSED)
2836 gfc_check_sleep_sub (gfc_expr *seconds)
2838 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2841 if (scalar_check (seconds, 0) == FAILURE)
2849 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
2851 if (source->rank >= GFC_MAX_DIMENSIONS)
2853 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2854 "than rank %d", gfc_current_intrinsic_arg[0],
2855 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2863 if (dim_check (dim, 1, false) == FAILURE)
2866 /* dim_rank_check() does not apply here. */
2868 && dim->expr_type == EXPR_CONSTANT
2869 && (mpz_cmp_ui (dim->value.integer, 1) < 0
2870 || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0))
2872 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
2873 "dimension index", gfc_current_intrinsic_arg[1],
2874 gfc_current_intrinsic, &dim->where);
2878 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2881 if (scalar_check (ncopies, 2) == FAILURE)
2888 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2892 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
2894 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2897 if (scalar_check (unit, 0) == FAILURE)
2900 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2902 if (kind_value_check (c, 1, gfc_default_character_kind) == FAILURE)
2908 if (type_check (status, 2, BT_INTEGER) == FAILURE
2909 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2910 || scalar_check (status, 2) == FAILURE)
2918 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
2920 return gfc_check_fgetputc_sub (unit, c, NULL);
2925 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
2927 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2929 if (kind_value_check (c, 0, gfc_default_character_kind) == FAILURE)
2935 if (type_check (status, 1, BT_INTEGER) == FAILURE
2936 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2937 || scalar_check (status, 1) == FAILURE)
2945 gfc_check_fgetput (gfc_expr *c)
2947 return gfc_check_fgetput_sub (c, NULL);
2952 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
2954 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2957 if (scalar_check (unit, 0) == FAILURE)
2960 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2963 if (scalar_check (offset, 1) == FAILURE)
2966 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
2969 if (scalar_check (whence, 2) == FAILURE)
2975 if (type_check (status, 3, BT_INTEGER) == FAILURE)
2978 if (kind_value_check (status, 3, 4) == FAILURE)
2981 if (scalar_check (status, 3) == FAILURE)
2990 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
2992 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2995 if (scalar_check (unit, 0) == FAILURE)
2998 if (type_check (array, 1, BT_INTEGER) == FAILURE
2999 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
3002 if (array_check (array, 1) == FAILURE)
3010 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
3012 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3015 if (scalar_check (unit, 0) == FAILURE)
3018 if (type_check (array, 1, BT_INTEGER) == FAILURE
3019 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3022 if (array_check (array, 1) == FAILURE)
3028 if (type_check (status, 2, BT_INTEGER) == FAILURE
3029 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3032 if (scalar_check (status, 2) == FAILURE)
3040 gfc_check_ftell (gfc_expr *unit)
3042 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3045 if (scalar_check (unit, 0) == FAILURE)
3053 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
3055 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3058 if (scalar_check (unit, 0) == FAILURE)
3061 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3064 if (scalar_check (offset, 1) == FAILURE)
3072 gfc_check_stat (gfc_expr *name, gfc_expr *array)
3074 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3076 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3079 if (type_check (array, 1, BT_INTEGER) == FAILURE
3080 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3083 if (array_check (array, 1) == FAILURE)
3091 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
3093 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3095 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3098 if (type_check (array, 1, BT_INTEGER) == FAILURE
3099 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3102 if (array_check (array, 1) == FAILURE)
3108 if (type_check (status, 2, BT_INTEGER) == FAILURE
3109 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3112 if (scalar_check (status, 2) == FAILURE)
3120 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
3121 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
3123 if (mold->ts.type == BT_HOLLERITH)
3125 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3126 &mold->where, gfc_basic_typename (BT_HOLLERITH));
3132 if (type_check (size, 2, BT_INTEGER) == FAILURE)
3135 if (scalar_check (size, 2) == FAILURE)
3138 if (nonoptional_check (size, 2) == FAILURE)
3147 gfc_check_transpose (gfc_expr *matrix)
3149 if (rank_check (matrix, 0, 2) == FAILURE)
3157 gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3159 if (array_check (array, 0) == FAILURE)
3162 if (dim_check (dim, 1, false) == FAILURE)
3165 if (dim_rank_check (dim, array, 0) == FAILURE)
3168 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3170 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3171 "with KIND argument at %L",
3172 gfc_current_intrinsic, &kind->where) == FAILURE)
3180 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
3184 if (rank_check (vector, 0, 1) == FAILURE)
3187 if (array_check (mask, 1) == FAILURE)
3190 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
3193 if (same_type_check (vector, 0, field, 2) == FAILURE)
3196 if (mask->expr_type == EXPR_ARRAY
3197 && gfc_array_size (vector, &vector_size) == SUCCESS)
3199 int mask_true_count = 0;
3200 gfc_constructor *mask_ctor = mask->value.constructor;
3203 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
3205 mask_true_count = 0;
3209 if (mask_ctor->expr->value.logical)
3212 mask_ctor = mask_ctor->next;
3215 if (mpz_get_si (vector_size) < mask_true_count)
3217 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
3218 "provide at least as many elements as there "
3219 "are .TRUE. values in '%s' (%ld/%d)",
3220 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
3221 &vector->where, gfc_current_intrinsic_arg[1],
3222 mpz_get_si (vector_size), mask_true_count);
3226 mpz_clear (vector_size);
3229 if (mask->rank != field->rank && field->rank != 0)
3231 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
3232 "the same rank as '%s' or be a scalar",
3233 gfc_current_intrinsic_arg[2], gfc_current_intrinsic,
3234 &field->where, gfc_current_intrinsic_arg[1]);
3238 if (mask->rank == field->rank)
3241 for (i = 0; i < field->rank; i++)
3242 if (! identical_dimen_shape (mask, i, field, i))
3244 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
3245 "must have identical shape.",
3246 gfc_current_intrinsic_arg[2],
3247 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
3257 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
3259 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3262 if (same_type_check (x, 0, y, 1) == FAILURE)
3265 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
3268 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
3270 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3271 "with KIND argument at %L",
3272 gfc_current_intrinsic, &kind->where) == FAILURE)
3280 gfc_check_trim (gfc_expr *x)
3282 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3285 if (scalar_check (x, 0) == FAILURE)
3293 gfc_check_ttynam (gfc_expr *unit)
3295 if (scalar_check (unit, 0) == FAILURE)
3298 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3305 /* Common check function for the half a dozen intrinsics that have a
3306 single real argument. */
3309 gfc_check_x (gfc_expr *x)
3311 if (type_check (x, 0, BT_REAL) == FAILURE)
3318 /************* Check functions for intrinsic subroutines *************/
3321 gfc_check_cpu_time (gfc_expr *time)
3323 if (scalar_check (time, 0) == FAILURE)
3326 if (type_check (time, 0, BT_REAL) == FAILURE)
3329 if (variable_check (time, 0) == FAILURE)
3337 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
3338 gfc_expr *zone, gfc_expr *values)
3342 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3344 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
3346 if (scalar_check (date, 0) == FAILURE)
3348 if (variable_check (date, 0) == FAILURE)
3354 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
3356 if (kind_value_check (time, 1, gfc_default_character_kind) == FAILURE)
3358 if (scalar_check (time, 1) == FAILURE)
3360 if (variable_check (time, 1) == FAILURE)
3366 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
3368 if (kind_value_check (zone, 2, gfc_default_character_kind) == FAILURE)
3370 if (scalar_check (zone, 2) == FAILURE)
3372 if (variable_check (zone, 2) == FAILURE)
3378 if (type_check (values, 3, BT_INTEGER) == FAILURE)
3380 if (array_check (values, 3) == FAILURE)
3382 if (rank_check (values, 3, 1) == FAILURE)
3384 if (variable_check (values, 3) == FAILURE)
3393 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
3394 gfc_expr *to, gfc_expr *topos)
3396 if (type_check (from, 0, BT_INTEGER) == FAILURE)
3399 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
3402 if (type_check (len, 2, BT_INTEGER) == FAILURE)
3405 if (same_type_check (from, 0, to, 3) == FAILURE)
3408 if (variable_check (to, 3) == FAILURE)
3411 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
3419 gfc_check_random_number (gfc_expr *harvest)
3421 if (type_check (harvest, 0, BT_REAL) == FAILURE)
3424 if (variable_check (harvest, 0) == FAILURE)
3432 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
3434 unsigned int nargs = 0, kiss_size;
3435 locus *where = NULL;
3436 mpz_t put_size, get_size;
3437 bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
3439 have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
3441 /* Keep the number of bytes in sync with kiss_size in
3442 libgfortran/intrinsics/random.c. */
3443 kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind;
3447 if (size->expr_type != EXPR_VARIABLE
3448 || !size->symtree->n.sym->attr.optional)
3451 if (scalar_check (size, 0) == FAILURE)
3454 if (type_check (size, 0, BT_INTEGER) == FAILURE)
3457 if (variable_check (size, 0) == FAILURE)
3460 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
3466 if (put->expr_type != EXPR_VARIABLE
3467 || !put->symtree->n.sym->attr.optional)
3470 where = &put->where;
3473 if (array_check (put, 1) == FAILURE)
3476 if (rank_check (put, 1, 1) == FAILURE)
3479 if (type_check (put, 1, BT_INTEGER) == FAILURE)
3482 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
3485 if (gfc_array_size (put, &put_size) == SUCCESS
3486 && mpz_get_ui (put_size) < kiss_size)
3487 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3488 "too small (%i/%i)",
3489 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, where,
3490 (int) mpz_get_ui (put_size), kiss_size);
3495 if (get->expr_type != EXPR_VARIABLE
3496 || !get->symtree->n.sym->attr.optional)
3499 where = &get->where;
3502 if (array_check (get, 2) == FAILURE)
3505 if (rank_check (get, 2, 1) == FAILURE)
3508 if (type_check (get, 2, BT_INTEGER) == FAILURE)
3511 if (variable_check (get, 2) == FAILURE)
3514 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
3517 if (gfc_array_size (get, &get_size) == SUCCESS
3518 && mpz_get_ui (get_size) < kiss_size)
3519 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3520 "too small (%i/%i)",
3521 gfc_current_intrinsic_arg[2], gfc_current_intrinsic, where,
3522 (int) mpz_get_ui (get_size), kiss_size);
3525 /* RANDOM_SEED may not have more than one non-optional argument. */
3527 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
3534 gfc_check_second_sub (gfc_expr *time)
3536 if (scalar_check (time, 0) == FAILURE)
3539 if (type_check (time, 0, BT_REAL) == FAILURE)
3542 if (kind_value_check(time, 0, 4) == FAILURE)
3549 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
3550 count, count_rate, and count_max are all optional arguments */
3553 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
3554 gfc_expr *count_max)
3558 if (scalar_check (count, 0) == FAILURE)
3561 if (type_check (count, 0, BT_INTEGER) == FAILURE)
3564 if (variable_check (count, 0) == FAILURE)
3568 if (count_rate != NULL)
3570 if (scalar_check (count_rate, 1) == FAILURE)
3573 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
3576 if (variable_check (count_rate, 1) == FAILURE)
3580 && same_type_check (count, 0, count_rate, 1) == FAILURE)
3585 if (count_max != NULL)
3587 if (scalar_check (count_max, 2) == FAILURE)
3590 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
3593 if (variable_check (count_max, 2) == FAILURE)
3597 && same_type_check (count, 0, count_max, 2) == FAILURE)
3600 if (count_rate != NULL
3601 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
3610 gfc_check_irand (gfc_expr *x)
3615 if (scalar_check (x, 0) == FAILURE)
3618 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3621 if (kind_value_check(x, 0, 4) == FAILURE)
3629 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
3631 if (scalar_check (seconds, 0) == FAILURE)
3634 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3637 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3639 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3640 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3641 gfc_current_intrinsic, &handler->where);
3645 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3651 if (scalar_check (status, 2) == FAILURE)
3654 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3657 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3665 gfc_check_rand (gfc_expr *x)
3670 if (scalar_check (x, 0) == FAILURE)
3673 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3676 if (kind_value_check(x, 0, 4) == FAILURE)
3684 gfc_check_srand (gfc_expr *x)
3686 if (scalar_check (x, 0) == FAILURE)
3689 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3692 if (kind_value_check(x, 0, 4) == FAILURE)
3700 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
3702 if (scalar_check (time, 0) == FAILURE)
3704 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3707 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
3709 if (kind_value_check (result, 1, gfc_default_character_kind) == FAILURE)
3717 gfc_check_dtime_etime (gfc_expr *x)
3719 if (array_check (x, 0) == FAILURE)
3722 if (rank_check (x, 0, 1) == FAILURE)
3725 if (variable_check (x, 0) == FAILURE)
3728 if (type_check (x, 0, BT_REAL) == FAILURE)
3731 if (kind_value_check(x, 0, 4) == FAILURE)
3739 gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
3741 if (array_check (values, 0) == FAILURE)
3744 if (rank_check (values, 0, 1) == FAILURE)
3747 if (variable_check (values, 0) == FAILURE)
3750 if (type_check (values, 0, BT_REAL) == FAILURE)
3753 if (kind_value_check(values, 0, 4) == FAILURE)
3756 if (scalar_check (time, 1) == FAILURE)
3759 if (type_check (time, 1, BT_REAL) == FAILURE)
3762 if (kind_value_check(time, 1, 4) == FAILURE)
3770 gfc_check_fdate_sub (gfc_expr *date)
3772 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3774 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
3782 gfc_check_gerror (gfc_expr *msg)
3784 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3786 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
3794 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
3796 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
3798 if (kind_value_check (cwd, 0, gfc_default_character_kind) == FAILURE)
3804 if (scalar_check (status, 1) == FAILURE)
3807 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3815 gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
3817 if (type_check (pos, 0, BT_INTEGER) == FAILURE)
3820 if (pos->ts.kind > gfc_default_integer_kind)
3822 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
3823 "not wider than the default kind (%d)",
3824 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
3825 &pos->where, gfc_default_integer_kind);
3829 if (type_check (value, 1, BT_CHARACTER) == FAILURE)
3831 if (kind_value_check (value, 1, gfc_default_character_kind) == FAILURE)
3839 gfc_check_getlog (gfc_expr *msg)
3841 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3843 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
3851 gfc_check_exit (gfc_expr *status)
3856 if (type_check (status, 0, BT_INTEGER) == FAILURE)
3859 if (scalar_check (status, 0) == FAILURE)
3867 gfc_check_flush (gfc_expr *unit)
3872 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3875 if (scalar_check (unit, 0) == FAILURE)
3883 gfc_check_free (gfc_expr *i)
3885 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3888 if (scalar_check (i, 0) == FAILURE)
3896 gfc_check_hostnm (gfc_expr *name)
3898 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3900 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3908 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
3910 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3912 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3918 if (scalar_check (status, 1) == FAILURE)
3921 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3929 gfc_check_itime_idate (gfc_expr *values)
3931 if (array_check (values, 0) == FAILURE)
3934 if (rank_check (values, 0, 1) == FAILURE)
3937 if (variable_check (values, 0) == FAILURE)
3940 if (type_check (values, 0, BT_INTEGER) == FAILURE)
3943 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
3951 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
3953 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3956 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
3959 if (scalar_check (time, 0) == FAILURE)
3962 if (array_check (values, 1) == FAILURE)
3965 if (rank_check (values, 1, 1) == FAILURE)
3968 if (variable_check (values, 1) == FAILURE)
3971 if (type_check (values, 1, BT_INTEGER) == FAILURE)
3974 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
3982 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
3984 if (scalar_check (unit, 0) == FAILURE)
3987 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3990 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
3992 if (kind_value_check (name, 1, gfc_default_character_kind) == FAILURE)
4000 gfc_check_isatty (gfc_expr *unit)
4005 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4008 if (scalar_check (unit, 0) == FAILURE)
4016 gfc_check_isnan (gfc_expr *x)
4018 if (type_check (x, 0, BT_REAL) == FAILURE)
4026 gfc_check_perror (gfc_expr *string)
4028 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
4030 if (kind_value_check (string, 0, gfc_default_character_kind) == FAILURE)
4038 gfc_check_umask (gfc_expr *mask)
4040 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4043 if (scalar_check (mask, 0) == FAILURE)
4051 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
4053 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4056 if (scalar_check (mask, 0) == FAILURE)
4062 if (scalar_check (old, 1) == FAILURE)
4065 if (type_check (old, 1, BT_INTEGER) == FAILURE)
4073 gfc_check_unlink (gfc_expr *name)
4075 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4077 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4085 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
4087 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4089 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4095 if (scalar_check (status, 1) == FAILURE)
4098 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4106 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
4108 if (scalar_check (number, 0) == FAILURE)
4111 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4114 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
4116 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4117 "or PROCEDURE", gfc_current_intrinsic_arg[1],
4118 gfc_current_intrinsic, &handler->where);
4122 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4130 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
4132 if (scalar_check (number, 0) == FAILURE)
4135 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4138 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
4140 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4141 "or PROCEDURE", gfc_current_intrinsic_arg[1],
4142 gfc_current_intrinsic, &handler->where);
4146 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4152 if (type_check (status, 2, BT_INTEGER) == FAILURE)
4155 if (scalar_check (status, 2) == FAILURE)
4163 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
4165 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
4167 if (kind_value_check (cmd, 0, gfc_default_character_kind) == FAILURE)
4170 if (scalar_check (status, 1) == FAILURE)
4173 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4176 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
4183 /* This is used for the GNU intrinsics AND, OR and XOR. */
4185 gfc_check_and (gfc_expr *i, gfc_expr *j)
4187 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
4189 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4190 "or LOGICAL", gfc_current_intrinsic_arg[0],
4191 gfc_current_intrinsic, &i->where);
4195 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
4197 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4198 "or LOGICAL", gfc_current_intrinsic_arg[1],
4199 gfc_current_intrinsic, &j->where);
4203 if (i->ts.type != j->ts.type)
4205 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
4206 "have the same type", gfc_current_intrinsic_arg[0],
4207 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
4212 if (scalar_check (i, 0) == FAILURE)
4215 if (scalar_check (j, 1) == FAILURE)