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)
342 if (dim->expr_type != EXPR_CONSTANT
343 || (array->expr_type != EXPR_VARIABLE
344 && array->expr_type != EXPR_ARRAY))
348 if (array->expr_type == EXPR_VARIABLE)
350 ar = gfc_find_array_ref (array);
351 if (ar->as->type == AS_ASSUMED_SIZE
353 && ar->type != AR_ELEMENT
354 && ar->type != AR_SECTION)
358 if (mpz_cmp_ui (dim->value.integer, 1) < 0
359 || mpz_cmp_ui (dim->value.integer, rank) > 0)
361 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
362 "dimension index", gfc_current_intrinsic, &dim->where);
371 /* Compare the size of a along dimension ai with the size of b along
372 dimension bi, returning 0 if they are known not to be identical,
373 and 1 if they are identical, or if this cannot be determined. */
376 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
378 mpz_t a_size, b_size;
381 gcc_assert (a->rank > ai);
382 gcc_assert (b->rank > bi);
386 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
388 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
390 if (mpz_cmp (a_size, b_size) != 0)
401 /* Check whether two character expressions have the same length;
402 returns SUCCESS if they have or if the length cannot be determined. */
405 gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
410 if (a->ts.cl && a->ts.cl->length
411 && a->ts.cl->length->expr_type == EXPR_CONSTANT)
412 len_a = mpz_get_si (a->ts.cl->length->value.integer);
413 else if (a->expr_type == EXPR_CONSTANT
414 && (a->ts.cl == NULL || a->ts.cl->length == NULL))
415 len_a = a->value.character.length;
419 if (b->ts.cl && b->ts.cl->length
420 && b->ts.cl->length->expr_type == EXPR_CONSTANT)
421 len_b = mpz_get_si (b->ts.cl->length->value.integer);
422 else if (b->expr_type == EXPR_CONSTANT
423 && (b->ts.cl == NULL || b->ts.cl->length == NULL))
424 len_b = b->value.character.length;
431 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
432 len_a, len_b, name, &a->where);
437 /***** Check functions *****/
439 /* Check subroutine suitable for intrinsics taking a real argument and
440 a kind argument for the result. */
443 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
445 if (type_check (a, 0, BT_REAL) == FAILURE)
447 if (kind_check (kind, 1, type) == FAILURE)
454 /* Check subroutine suitable for ceiling, floor and nint. */
457 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
459 return check_a_kind (a, kind, BT_INTEGER);
463 /* Check subroutine suitable for aint, anint. */
466 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
468 return check_a_kind (a, kind, BT_REAL);
473 gfc_check_abs (gfc_expr *a)
475 if (numeric_check (a, 0) == FAILURE)
483 gfc_check_achar (gfc_expr *a, gfc_expr *kind)
485 if (type_check (a, 0, BT_INTEGER) == FAILURE)
487 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
495 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
497 if (type_check (name, 0, BT_CHARACTER) == FAILURE
498 || scalar_check (name, 0) == FAILURE)
500 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
503 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
504 || scalar_check (mode, 1) == FAILURE)
506 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
514 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
516 if (logical_array_check (mask, 0) == FAILURE)
519 if (dim_check (dim, 1, false) == FAILURE)
527 gfc_check_allocated (gfc_expr *array)
529 symbol_attribute attr;
531 if (variable_check (array, 0) == FAILURE)
534 attr = gfc_variable_attr (array, NULL);
535 if (!attr.allocatable)
537 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
538 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
543 if (array_check (array, 0) == FAILURE)
550 /* Common check function where the first argument must be real or
551 integer and the second argument must be the same as the first. */
554 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
556 if (int_or_real_check (a, 0) == FAILURE)
559 if (a->ts.type != p->ts.type)
561 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
562 "have the same type", gfc_current_intrinsic_arg[0],
563 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
568 if (a->ts.kind != p->ts.kind)
570 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
571 &p->where) == FAILURE)
580 gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
582 if (double_check (x, 0) == FAILURE || double_check (y, 1) == FAILURE)
590 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
592 symbol_attribute attr1, attr2;
597 where = &pointer->where;
599 if (pointer->expr_type == EXPR_VARIABLE)
600 attr1 = gfc_variable_attr (pointer, NULL);
601 else if (pointer->expr_type == EXPR_FUNCTION)
602 attr1 = pointer->symtree->n.sym->attr;
603 else if (pointer->expr_type == EXPR_NULL)
606 gcc_assert (0); /* Pointer must be a variable or a function. */
608 if (!attr1.pointer && !attr1.proc_pointer)
610 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
611 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
616 /* Target argument is optional. */
620 where = &target->where;
621 if (target->expr_type == EXPR_NULL)
624 if (target->expr_type == EXPR_VARIABLE)
625 attr2 = gfc_variable_attr (target, NULL);
626 else if (target->expr_type == EXPR_FUNCTION)
627 attr2 = target->symtree->n.sym->attr;
630 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
631 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg[1],
632 gfc_current_intrinsic, &target->where);
636 if (attr1.pointer && !attr2.pointer && !attr2.target)
638 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
639 "or a TARGET", gfc_current_intrinsic_arg[1],
640 gfc_current_intrinsic, &target->where);
645 if (same_type_check (pointer, 0, target, 1) == FAILURE)
647 if (rank_check (target, 0, pointer->rank) == FAILURE)
649 if (target->rank > 0)
651 for (i = 0; i < target->rank; i++)
652 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
654 gfc_error ("Array section with a vector subscript at %L shall not "
655 "be the target of a pointer",
665 gfc_error ("NULL pointer at %L is not permitted as actual argument "
666 "of '%s' intrinsic function", where, gfc_current_intrinsic);
673 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
675 if (type_check (y, 0, BT_REAL) == FAILURE)
677 if (same_type_check (y, 0, x, 1) == FAILURE)
684 /* BESJN and BESYN functions. */
687 gfc_check_besn (gfc_expr *n, gfc_expr *x)
689 if (type_check (n, 0, BT_INTEGER) == FAILURE)
692 if (type_check (x, 1, BT_REAL) == FAILURE)
700 gfc_check_btest (gfc_expr *i, gfc_expr *pos)
702 if (type_check (i, 0, BT_INTEGER) == FAILURE)
704 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
712 gfc_check_char (gfc_expr *i, gfc_expr *kind)
714 if (type_check (i, 0, BT_INTEGER) == FAILURE)
716 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
724 gfc_check_chdir (gfc_expr *dir)
726 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
728 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
736 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
738 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
740 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
746 if (type_check (status, 1, BT_INTEGER) == FAILURE)
748 if (scalar_check (status, 1) == FAILURE)
756 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
758 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
760 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
763 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
765 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
773 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
775 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
777 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
780 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
782 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
788 if (type_check (status, 2, BT_INTEGER) == FAILURE)
791 if (scalar_check (status, 2) == FAILURE)
799 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
801 if (numeric_check (x, 0) == FAILURE)
806 if (numeric_check (y, 1) == FAILURE)
809 if (x->ts.type == BT_COMPLEX)
811 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
812 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
813 gfc_current_intrinsic, &y->where);
818 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
826 gfc_check_complex (gfc_expr *x, gfc_expr *y)
828 if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
830 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
831 "or REAL", gfc_current_intrinsic_arg[0],
832 gfc_current_intrinsic, &x->where);
835 if (scalar_check (x, 0) == FAILURE)
838 if (y->ts.type != BT_INTEGER && y->ts.type != BT_REAL)
840 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
841 "or REAL", gfc_current_intrinsic_arg[1],
842 gfc_current_intrinsic, &y->where);
845 if (scalar_check (y, 1) == FAILURE)
853 gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
855 if (logical_array_check (mask, 0) == FAILURE)
857 if (dim_check (dim, 1, false) == FAILURE)
859 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
861 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
862 "with KIND argument at %L",
863 gfc_current_intrinsic, &kind->where) == FAILURE)
871 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
873 if (array_check (array, 0) == FAILURE)
876 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
879 if (array->rank == 1)
881 if (scalar_check (shift, 1) == FAILURE)
884 else if (shift->rank != array->rank - 1 && shift->rank != 0)
886 gfc_error ("SHIFT argument at %L of CSHIFT must have rank %d or be a "
887 "scalar", &shift->where, array->rank - 1);
891 /* TODO: Add shape conformance check between array (w/o dimension dim)
894 if (dim_check (dim, 2, true) == FAILURE)
902 gfc_check_ctime (gfc_expr *time)
904 if (scalar_check (time, 0) == FAILURE)
907 if (type_check (time, 0, BT_INTEGER) == FAILURE)
914 gfc_try gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
916 if (double_check (y, 0) == FAILURE || double_check (x, 1) == FAILURE)
923 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
925 if (numeric_check (x, 0) == FAILURE)
930 if (numeric_check (y, 1) == FAILURE)
933 if (x->ts.type == BT_COMPLEX)
935 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
936 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg[1],
937 gfc_current_intrinsic, &y->where);
947 gfc_check_dble (gfc_expr *x)
949 if (numeric_check (x, 0) == FAILURE)
957 gfc_check_digits (gfc_expr *x)
959 if (int_or_real_check (x, 0) == FAILURE)
967 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
969 switch (vector_a->ts.type)
972 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
979 if (numeric_check (vector_b, 1) == FAILURE)
984 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
985 "or LOGICAL", gfc_current_intrinsic_arg[0],
986 gfc_current_intrinsic, &vector_a->where);
990 if (rank_check (vector_a, 0, 1) == FAILURE)
993 if (rank_check (vector_b, 1, 1) == FAILURE)
996 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
998 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
999 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0],
1000 gfc_current_intrinsic_arg[1], &vector_a->where);
1009 gfc_check_dprod (gfc_expr *x, gfc_expr *y)
1011 if (type_check (x, 0, BT_REAL) == FAILURE
1012 || type_check (y, 1, BT_REAL) == FAILURE)
1015 if (x->ts.kind != gfc_default_real_kind)
1017 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1018 "real", gfc_current_intrinsic_arg[0],
1019 gfc_current_intrinsic, &x->where);
1023 if (y->ts.kind != gfc_default_real_kind)
1025 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1026 "real", gfc_current_intrinsic_arg[1],
1027 gfc_current_intrinsic, &y->where);
1036 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
1039 if (array_check (array, 0) == FAILURE)
1042 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1045 if (array->rank == 1)
1047 if (scalar_check (shift, 2) == FAILURE)
1050 else if (shift->rank != array->rank - 1 && shift->rank != 0)
1052 gfc_error ("SHIFT argument at %L of EOSHIFT must have rank %d or be a "
1053 "scalar", &shift->where, array->rank - 1);
1057 /* TODO: Add shape conformance check between array (w/o dimension dim)
1060 if (boundary != NULL)
1062 if (same_type_check (array, 0, boundary, 2) == FAILURE)
1065 if (array->rank == 1)
1067 if (scalar_check (boundary, 2) == FAILURE)
1070 else if (boundary->rank != array->rank - 1 && boundary->rank != 0)
1072 gfc_error ("BOUNDARY argument at %L of EOSHIFT must have rank %d or be "
1073 "a scalar", &boundary->where, array->rank - 1);
1077 if (shift->rank == boundary->rank)
1080 for (i = 0; i < shift->rank; i++)
1081 if (! identical_dimen_shape (shift, i, boundary, i))
1083 gfc_error ("Different shape in dimension %d for SHIFT and "
1084 "BOUNDARY arguments of EOSHIFT at %L", shift->rank,
1091 if (dim_check (dim, 4, true) == FAILURE)
1098 /* A single complex argument. */
1101 gfc_check_fn_c (gfc_expr *a)
1103 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
1110 /* A single real argument. */
1113 gfc_check_fn_r (gfc_expr *a)
1115 if (type_check (a, 0, BT_REAL) == FAILURE)
1121 /* A single double argument. */
1124 gfc_check_fn_d (gfc_expr *a)
1126 if (double_check (a, 0) == FAILURE)
1132 /* A single real or complex argument. */
1135 gfc_check_fn_rc (gfc_expr *a)
1137 if (real_or_complex_check (a, 0) == FAILURE)
1145 gfc_check_fnum (gfc_expr *unit)
1147 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1150 if (scalar_check (unit, 0) == FAILURE)
1158 gfc_check_huge (gfc_expr *x)
1160 if (int_or_real_check (x, 0) == FAILURE)
1168 gfc_check_hypot (gfc_expr *x, gfc_expr *y)
1170 if (type_check (x, 0, BT_REAL) == FAILURE)
1172 if (same_type_check (x, 0, y, 1) == FAILURE)
1179 /* Check that the single argument is an integer. */
1182 gfc_check_i (gfc_expr *i)
1184 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1192 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1194 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1197 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1200 if (i->ts.kind != j->ts.kind)
1202 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1203 &i->where) == FAILURE)
1212 gfc_check_ibclr (gfc_expr *i, gfc_expr *pos)
1214 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1217 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1225 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1227 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1230 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1233 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1241 gfc_check_ibset (gfc_expr *i, gfc_expr *pos)
1243 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1246 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1254 gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
1258 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1261 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1264 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1265 "with KIND argument at %L",
1266 gfc_current_intrinsic, &kind->where) == FAILURE)
1269 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1275 /* Substring references don't have the charlength set. */
1277 while (ref && ref->type != REF_SUBSTRING)
1280 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1284 /* Check that the argument is length one. Non-constant lengths
1285 can't be checked here, so assume they are ok. */
1286 if (c->ts.cl && c->ts.cl->length)
1288 /* If we already have a length for this expression then use it. */
1289 if (c->ts.cl->length->expr_type != EXPR_CONSTANT)
1291 i = mpz_get_si (c->ts.cl->length->value.integer);
1298 start = ref->u.ss.start;
1299 end = ref->u.ss.end;
1302 if (end == NULL || end->expr_type != EXPR_CONSTANT
1303 || start->expr_type != EXPR_CONSTANT)
1306 i = mpz_get_si (end->value.integer) + 1
1307 - mpz_get_si (start->value.integer);
1315 gfc_error ("Argument of %s at %L must be of length one",
1316 gfc_current_intrinsic, &c->where);
1325 gfc_check_idnint (gfc_expr *a)
1327 if (double_check (a, 0) == FAILURE)
1335 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1337 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1340 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1343 if (i->ts.kind != j->ts.kind)
1345 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1346 &i->where) == FAILURE)
1355 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back,
1358 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1359 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1362 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1365 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
1367 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1368 "with KIND argument at %L",
1369 gfc_current_intrinsic, &kind->where) == FAILURE)
1372 if (string->ts.kind != substring->ts.kind)
1374 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1375 "kind as '%s'", gfc_current_intrinsic_arg[1],
1376 gfc_current_intrinsic, &substring->where,
1377 gfc_current_intrinsic_arg[0]);
1386 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1388 if (numeric_check (x, 0) == FAILURE)
1391 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1399 gfc_check_intconv (gfc_expr *x)
1401 if (numeric_check (x, 0) == FAILURE)
1409 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1411 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1414 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1417 if (i->ts.kind != j->ts.kind)
1419 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1420 &i->where) == FAILURE)
1429 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1431 if (type_check (i, 0, BT_INTEGER) == FAILURE
1432 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1440 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1442 if (type_check (i, 0, BT_INTEGER) == FAILURE
1443 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1446 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1454 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1456 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1459 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1467 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1469 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1472 if (scalar_check (pid, 0) == FAILURE)
1475 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1478 if (scalar_check (sig, 1) == FAILURE)
1484 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1487 if (scalar_check (status, 2) == FAILURE)
1495 gfc_check_kind (gfc_expr *x)
1497 if (x->ts.type == BT_DERIVED)
1499 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1500 "non-derived type", gfc_current_intrinsic_arg[0],
1501 gfc_current_intrinsic, &x->where);
1510 gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1512 if (array_check (array, 0) == FAILURE)
1517 if (dim_check (dim, 1, false) == FAILURE)
1520 if (dim_rank_check (dim, array, 1) == FAILURE)
1524 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1526 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1527 "with KIND argument at %L",
1528 gfc_current_intrinsic, &kind->where) == FAILURE)
1536 gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
1538 if (type_check (s, 0, BT_CHARACTER) == FAILURE)
1541 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1543 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1544 "with KIND argument at %L",
1545 gfc_current_intrinsic, &kind->where) == FAILURE)
1553 gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
1555 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1557 if (kind_value_check (a, 0, gfc_default_character_kind) == FAILURE)
1560 if (type_check (b, 1, BT_CHARACTER) == FAILURE)
1562 if (kind_value_check (b, 1, gfc_default_character_kind) == FAILURE)
1570 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
1572 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1574 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1577 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1579 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1587 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1589 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1591 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1594 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1596 if (kind_value_check (path2, 0, gfc_default_character_kind) == FAILURE)
1602 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1605 if (scalar_check (status, 2) == FAILURE)
1613 gfc_check_loc (gfc_expr *expr)
1615 return variable_check (expr, 0);
1620 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
1622 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1624 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1627 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1629 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1637 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1639 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1641 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1644 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1646 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1652 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1655 if (scalar_check (status, 2) == FAILURE)
1663 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
1665 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
1667 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
1674 /* Min/max family. */
1677 min_max_args (gfc_actual_arglist *arg)
1679 if (arg == NULL || arg->next == NULL)
1681 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1682 gfc_current_intrinsic, gfc_current_intrinsic_where);
1691 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
1693 gfc_actual_arglist *arg, *tmp;
1698 if (min_max_args (arglist) == FAILURE)
1701 for (arg = arglist, n=1; arg; arg = arg->next, n++)
1704 if (x->ts.type != type || x->ts.kind != kind)
1706 if (x->ts.type == type)
1708 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
1709 "kinds at %L", &x->where) == FAILURE)
1714 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1715 "%s(%d)", n, gfc_current_intrinsic, &x->where,
1716 gfc_basic_typename (type), kind);
1721 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
1724 snprintf (buffer, 80, "arguments 'a%d' and 'a%d' for intrinsic '%s'",
1725 m, n, gfc_current_intrinsic);
1726 if (gfc_check_conformance (buffer, tmp->expr, x) == FAILURE)
1736 gfc_check_min_max (gfc_actual_arglist *arg)
1740 if (min_max_args (arg) == FAILURE)
1745 if (x->ts.type == BT_CHARACTER)
1747 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1748 "with CHARACTER argument at %L",
1749 gfc_current_intrinsic, &x->where) == FAILURE)
1752 else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
1754 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
1755 "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
1759 return check_rest (x->ts.type, x->ts.kind, arg);
1764 gfc_check_min_max_integer (gfc_actual_arglist *arg)
1766 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
1771 gfc_check_min_max_real (gfc_actual_arglist *arg)
1773 return check_rest (BT_REAL, gfc_default_real_kind, arg);
1778 gfc_check_min_max_double (gfc_actual_arglist *arg)
1780 return check_rest (BT_REAL, gfc_default_double_kind, arg);
1784 /* End of min/max family. */
1787 gfc_check_malloc (gfc_expr *size)
1789 if (type_check (size, 0, BT_INTEGER) == FAILURE)
1792 if (scalar_check (size, 0) == FAILURE)
1800 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
1802 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
1804 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1805 "or LOGICAL", gfc_current_intrinsic_arg[0],
1806 gfc_current_intrinsic, &matrix_a->where);
1810 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
1812 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1813 "or LOGICAL", gfc_current_intrinsic_arg[1],
1814 gfc_current_intrinsic, &matrix_b->where);
1818 if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
1819 || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
1821 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
1822 gfc_current_intrinsic, &matrix_a->where,
1823 gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
1827 switch (matrix_a->rank)
1830 if (rank_check (matrix_b, 1, 2) == FAILURE)
1832 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
1833 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
1835 gfc_error ("Different shape on dimension 1 for arguments '%s' "
1836 "and '%s' at %L for intrinsic matmul",
1837 gfc_current_intrinsic_arg[0],
1838 gfc_current_intrinsic_arg[1], &matrix_a->where);
1844 if (matrix_b->rank != 2)
1846 if (rank_check (matrix_b, 1, 1) == FAILURE)
1849 /* matrix_b has rank 1 or 2 here. Common check for the cases
1850 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
1851 - matrix_a has shape (n,m) and matrix_b has shape (m). */
1852 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
1854 gfc_error ("Different shape on dimension 2 for argument '%s' and "
1855 "dimension 1 for argument '%s' at %L for intrinsic "
1856 "matmul", gfc_current_intrinsic_arg[0],
1857 gfc_current_intrinsic_arg[1], &matrix_a->where);
1863 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
1864 "1 or 2", gfc_current_intrinsic_arg[0],
1865 gfc_current_intrinsic, &matrix_a->where);
1873 /* Whoever came up with this interface was probably on something.
1874 The possibilities for the occupation of the second and third
1881 NULL MASK minloc(array, mask=m)
1884 I.e. in the case of minloc(array,mask), mask will be in the second
1885 position of the argument list and we'll have to fix that up. */
1888 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
1890 gfc_expr *a, *m, *d;
1893 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
1897 m = ap->next->next->expr;
1899 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1900 && ap->next->name == NULL)
1904 ap->next->expr = NULL;
1905 ap->next->next->expr = m;
1908 if (d && dim_check (d, 1, false) == FAILURE)
1911 if (d && dim_rank_check (d, a, 0) == FAILURE)
1914 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1920 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1921 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1922 gfc_current_intrinsic);
1923 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1931 /* Similar to minloc/maxloc, the argument list might need to be
1932 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
1933 difference is that MINLOC/MAXLOC take an additional KIND argument.
1934 The possibilities are:
1940 NULL MASK minval(array, mask=m)
1943 I.e. in the case of minval(array,mask), mask will be in the second
1944 position of the argument list and we'll have to fix that up. */
1947 check_reduction (gfc_actual_arglist *ap)
1949 gfc_expr *a, *m, *d;
1953 m = ap->next->next->expr;
1955 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
1956 && ap->next->name == NULL)
1960 ap->next->expr = NULL;
1961 ap->next->next->expr = m;
1964 if (d && dim_check (d, 1, false) == FAILURE)
1967 if (d && dim_rank_check (d, a, 0) == FAILURE)
1970 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
1976 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic %s",
1977 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[2],
1978 gfc_current_intrinsic);
1979 if (gfc_check_conformance (buffer, a, m) == FAILURE)
1988 gfc_check_minval_maxval (gfc_actual_arglist *ap)
1990 if (int_or_real_check (ap->expr, 0) == FAILURE
1991 || array_check (ap->expr, 0) == FAILURE)
1994 return check_reduction (ap);
1999 gfc_check_product_sum (gfc_actual_arglist *ap)
2001 if (numeric_check (ap->expr, 0) == FAILURE
2002 || array_check (ap->expr, 0) == FAILURE)
2005 return check_reduction (ap);
2010 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
2012 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
2015 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
2018 if (tsource->ts.type == BT_CHARACTER)
2019 return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
2026 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
2028 symbol_attribute attr;
2030 if (variable_check (from, 0) == FAILURE)
2033 if (array_check (from, 0) == FAILURE)
2036 attr = gfc_variable_attr (from, NULL);
2037 if (!attr.allocatable)
2039 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2040 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
2045 if (variable_check (to, 0) == FAILURE)
2048 if (array_check (to, 0) == FAILURE)
2051 attr = gfc_variable_attr (to, NULL);
2052 if (!attr.allocatable)
2054 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2055 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
2060 if (same_type_check (from, 0, to, 1) == FAILURE)
2063 if (to->rank != from->rank)
2065 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2066 "have the same rank %d/%d", gfc_current_intrinsic_arg[0],
2067 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
2068 &to->where, from->rank, to->rank);
2072 if (to->ts.kind != from->ts.kind)
2074 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2075 "be of the same kind %d/%d", gfc_current_intrinsic_arg[0],
2076 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
2077 &to->where, from->ts.kind, to->ts.kind);
2086 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
2088 if (type_check (x, 0, BT_REAL) == FAILURE)
2091 if (type_check (s, 1, BT_REAL) == FAILURE)
2099 gfc_check_new_line (gfc_expr *a)
2101 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2109 gfc_check_null (gfc_expr *mold)
2111 symbol_attribute attr;
2116 if (variable_check (mold, 0) == FAILURE)
2119 attr = gfc_variable_attr (mold, NULL);
2121 if (!attr.pointer && !attr.proc_pointer)
2123 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
2124 gfc_current_intrinsic_arg[0],
2125 gfc_current_intrinsic, &mold->where);
2134 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
2138 if (array_check (array, 0) == FAILURE)
2141 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2144 snprintf (buffer, 80, "arguments '%s' and '%s' for intrinsic '%s'",
2145 gfc_current_intrinsic_arg[0], gfc_current_intrinsic_arg[1],
2146 gfc_current_intrinsic);
2147 if (gfc_check_conformance (buffer, array, mask) == FAILURE)
2152 mpz_t array_size, vector_size;
2153 bool have_array_size, have_vector_size;
2155 if (same_type_check (array, 0, vector, 2) == FAILURE)
2158 if (rank_check (vector, 2, 1) == FAILURE)
2161 /* VECTOR requires at least as many elements as MASK
2162 has .TRUE. values. */
2163 have_array_size = gfc_array_size (array, &array_size) == SUCCESS;
2164 have_vector_size = gfc_array_size (vector, &vector_size) == SUCCESS;
2166 if (have_vector_size
2167 && (mask->expr_type == EXPR_ARRAY
2168 || (mask->expr_type == EXPR_CONSTANT
2169 && have_array_size)))
2171 int mask_true_values = 0;
2173 if (mask->expr_type == EXPR_ARRAY)
2175 gfc_constructor *mask_ctor = mask->value.constructor;
2178 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
2180 mask_true_values = 0;
2184 if (mask_ctor->expr->value.logical)
2187 mask_ctor = mask_ctor->next;
2190 else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
2191 mask_true_values = mpz_get_si (array_size);
2193 if (mpz_get_si (vector_size) < mask_true_values)
2195 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2196 "provide at least as many elements as there "
2197 "are .TRUE. values in '%s' (%ld/%d)",
2198 gfc_current_intrinsic_arg[2],gfc_current_intrinsic,
2199 &vector->where, gfc_current_intrinsic_arg[1],
2200 mpz_get_si (vector_size), mask_true_values);
2205 if (have_array_size)
2206 mpz_clear (array_size);
2207 if (have_vector_size)
2208 mpz_clear (vector_size);
2216 gfc_check_precision (gfc_expr *x)
2218 if (x->ts.type != BT_REAL && x->ts.type != BT_COMPLEX)
2220 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
2221 "REAL or COMPLEX", gfc_current_intrinsic_arg[0],
2222 gfc_current_intrinsic, &x->where);
2231 gfc_check_present (gfc_expr *a)
2235 if (variable_check (a, 0) == FAILURE)
2238 sym = a->symtree->n.sym;
2239 if (!sym->attr.dummy)
2241 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2242 "dummy variable", gfc_current_intrinsic_arg[0],
2243 gfc_current_intrinsic, &a->where);
2247 if (!sym->attr.optional)
2249 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2250 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg[0],
2251 gfc_current_intrinsic, &a->where);
2255 /* 13.14.82 PRESENT(A)
2257 Argument. A shall be the name of an optional dummy argument that is
2258 accessible in the subprogram in which the PRESENT function reference
2262 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2263 && a->ref->u.ar.type == AR_FULL))
2265 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2266 "subobject of '%s'", gfc_current_intrinsic_arg[0],
2267 gfc_current_intrinsic, &a->where, sym->name);
2276 gfc_check_radix (gfc_expr *x)
2278 if (int_or_real_check (x, 0) == FAILURE)
2286 gfc_check_range (gfc_expr *x)
2288 if (numeric_check (x, 0) == FAILURE)
2295 /* real, float, sngl. */
2297 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2299 if (numeric_check (a, 0) == FAILURE)
2302 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2310 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2312 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2314 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2317 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2319 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2327 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2329 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2331 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2334 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2336 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2342 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2345 if (scalar_check (status, 2) == FAILURE)
2353 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2355 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2358 if (scalar_check (x, 0) == FAILURE)
2361 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2364 if (scalar_check (y, 1) == FAILURE)
2372 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2373 gfc_expr *pad, gfc_expr *order)
2379 if (array_check (source, 0) == FAILURE)
2382 if (rank_check (shape, 1, 1) == FAILURE)
2385 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2388 if (gfc_array_size (shape, &size) != SUCCESS)
2390 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2391 "array of constant size", &shape->where);
2395 shape_size = mpz_get_ui (size);
2398 if (shape_size <= 0)
2400 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
2401 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
2405 else if (shape_size > GFC_MAX_DIMENSIONS)
2407 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2408 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2411 else if (shape->expr_type == EXPR_ARRAY)
2415 for (i = 0; i < shape_size; ++i)
2417 e = gfc_get_array_element (shape, i);
2418 if (e->expr_type != EXPR_CONSTANT)
2424 gfc_extract_int (e, &extent);
2427 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2428 "negative element (%d)", gfc_current_intrinsic_arg[1],
2429 gfc_current_intrinsic, &e->where, extent);
2439 if (same_type_check (source, 0, pad, 2) == FAILURE)
2442 if (array_check (pad, 2) == FAILURE)
2448 if (array_check (order, 3) == FAILURE)
2451 if (type_check (order, 3, BT_INTEGER) == FAILURE)
2454 if (order->expr_type == EXPR_ARRAY)
2456 int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
2459 for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
2462 gfc_array_size (order, &size);
2463 order_size = mpz_get_ui (size);
2466 if (order_size != shape_size)
2468 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2469 "has wrong number of elements (%d/%d)",
2470 gfc_current_intrinsic_arg[3],
2471 gfc_current_intrinsic, &order->where,
2472 order_size, shape_size);
2476 for (i = 1; i <= order_size; ++i)
2478 e = gfc_get_array_element (order, i-1);
2479 if (e->expr_type != EXPR_CONSTANT)
2485 gfc_extract_int (e, &dim);
2487 if (dim < 1 || dim > order_size)
2489 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2490 "has out-of-range dimension (%d)",
2491 gfc_current_intrinsic_arg[3],
2492 gfc_current_intrinsic, &e->where, dim);
2496 if (perm[dim-1] != 0)
2498 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2499 "invalid permutation of dimensions (dimension "
2500 "'%d' duplicated)", gfc_current_intrinsic_arg[3],
2501 gfc_current_intrinsic, &e->where, dim);
2511 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2512 && gfc_is_constant_expr (shape)
2513 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2514 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2516 /* Check the match in size between source and destination. */
2517 if (gfc_array_size (source, &nelems) == SUCCESS)
2522 c = shape->value.constructor;
2523 mpz_init_set_ui (size, 1);
2524 for (; c; c = c->next)
2525 mpz_mul (size, size, c->expr->value.integer);
2527 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2533 gfc_error ("Without padding, there are not enough elements "
2534 "in the intrinsic RESHAPE source at %L to match "
2535 "the shape", &source->where);
2546 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2548 if (type_check (x, 0, BT_REAL) == FAILURE)
2551 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2559 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
2561 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2564 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2567 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2570 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
2572 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2573 "with KIND argument at %L",
2574 gfc_current_intrinsic, &kind->where) == FAILURE)
2577 if (same_type_check (x, 0, y, 1) == FAILURE)
2585 gfc_check_secnds (gfc_expr *r)
2587 if (type_check (r, 0, BT_REAL) == FAILURE)
2590 if (kind_value_check (r, 0, 4) == FAILURE)
2593 if (scalar_check (r, 0) == FAILURE)
2601 gfc_check_selected_char_kind (gfc_expr *name)
2603 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2606 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
2609 if (scalar_check (name, 0) == FAILURE)
2617 gfc_check_selected_int_kind (gfc_expr *r)
2619 if (type_check (r, 0, BT_INTEGER) == FAILURE)
2622 if (scalar_check (r, 0) == FAILURE)
2630 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r)
2632 if (p == NULL && r == NULL)
2634 gfc_error ("Missing arguments to %s intrinsic at %L",
2635 gfc_current_intrinsic, gfc_current_intrinsic_where);
2640 if (p != NULL && type_check (p, 0, BT_INTEGER) == FAILURE)
2643 if (r != NULL && type_check (r, 1, BT_INTEGER) == FAILURE)
2651 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
2653 if (type_check (x, 0, BT_REAL) == FAILURE)
2656 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2664 gfc_check_shape (gfc_expr *source)
2668 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
2671 ar = gfc_find_array_ref (source);
2673 if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
2675 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2676 "an assumed size array", &source->where);
2685 gfc_check_sign (gfc_expr *a, gfc_expr *b)
2687 if (int_or_real_check (a, 0) == FAILURE)
2690 if (same_type_check (a, 0, b, 1) == FAILURE)
2698 gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2700 if (array_check (array, 0) == FAILURE)
2705 if (dim_check (dim, 1, true) == FAILURE)
2708 if (dim_rank_check (dim, array, 0) == FAILURE)
2712 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
2714 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2715 "with KIND argument at %L",
2716 gfc_current_intrinsic, &kind->where) == FAILURE)
2725 gfc_check_sizeof (gfc_expr *arg ATTRIBUTE_UNUSED)
2732 gfc_check_sleep_sub (gfc_expr *seconds)
2734 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
2737 if (scalar_check (seconds, 0) == FAILURE)
2745 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
2747 if (source->rank >= GFC_MAX_DIMENSIONS)
2749 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2750 "than rank %d", gfc_current_intrinsic_arg[0],
2751 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
2759 if (dim_check (dim, 1, false) == FAILURE)
2762 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
2765 if (scalar_check (ncopies, 2) == FAILURE)
2772 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
2776 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
2778 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2781 if (scalar_check (unit, 0) == FAILURE)
2784 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
2786 if (kind_value_check (c, 1, gfc_default_character_kind) == FAILURE)
2792 if (type_check (status, 2, BT_INTEGER) == FAILURE
2793 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
2794 || scalar_check (status, 2) == FAILURE)
2802 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
2804 return gfc_check_fgetputc_sub (unit, c, NULL);
2809 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
2811 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
2813 if (kind_value_check (c, 0, gfc_default_character_kind) == FAILURE)
2819 if (type_check (status, 1, BT_INTEGER) == FAILURE
2820 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
2821 || scalar_check (status, 1) == FAILURE)
2829 gfc_check_fgetput (gfc_expr *c)
2831 return gfc_check_fgetput_sub (c, NULL);
2836 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
2838 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2841 if (scalar_check (unit, 0) == FAILURE)
2844 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2847 if (scalar_check (offset, 1) == FAILURE)
2850 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
2853 if (scalar_check (whence, 2) == FAILURE)
2859 if (type_check (status, 3, BT_INTEGER) == FAILURE)
2862 if (kind_value_check (status, 3, 4) == FAILURE)
2865 if (scalar_check (status, 3) == FAILURE)
2874 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
2876 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2879 if (scalar_check (unit, 0) == FAILURE)
2882 if (type_check (array, 1, BT_INTEGER) == FAILURE
2883 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
2886 if (array_check (array, 1) == FAILURE)
2894 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
2896 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2899 if (scalar_check (unit, 0) == FAILURE)
2902 if (type_check (array, 1, BT_INTEGER) == FAILURE
2903 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2906 if (array_check (array, 1) == FAILURE)
2912 if (type_check (status, 2, BT_INTEGER) == FAILURE
2913 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
2916 if (scalar_check (status, 2) == FAILURE)
2924 gfc_check_ftell (gfc_expr *unit)
2926 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2929 if (scalar_check (unit, 0) == FAILURE)
2937 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
2939 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
2942 if (scalar_check (unit, 0) == FAILURE)
2945 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
2948 if (scalar_check (offset, 1) == FAILURE)
2956 gfc_check_stat (gfc_expr *name, gfc_expr *array)
2958 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2960 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
2963 if (type_check (array, 1, BT_INTEGER) == FAILURE
2964 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2967 if (array_check (array, 1) == FAILURE)
2975 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
2977 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2979 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
2982 if (type_check (array, 1, BT_INTEGER) == FAILURE
2983 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2986 if (array_check (array, 1) == FAILURE)
2992 if (type_check (status, 2, BT_INTEGER) == FAILURE
2993 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
2996 if (scalar_check (status, 2) == FAILURE)
3004 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
3005 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
3007 if (mold->ts.type == BT_HOLLERITH)
3009 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3010 &mold->where, gfc_basic_typename (BT_HOLLERITH));
3016 if (type_check (size, 2, BT_INTEGER) == FAILURE)
3019 if (scalar_check (size, 2) == FAILURE)
3022 if (nonoptional_check (size, 2) == FAILURE)
3031 gfc_check_transpose (gfc_expr *matrix)
3033 if (rank_check (matrix, 0, 2) == FAILURE)
3041 gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3043 if (array_check (array, 0) == FAILURE)
3048 if (dim_check (dim, 1, false) == FAILURE)
3051 if (dim_rank_check (dim, array, 0) == FAILURE)
3055 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3057 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3058 "with KIND argument at %L",
3059 gfc_current_intrinsic, &kind->where) == FAILURE)
3067 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
3069 if (rank_check (vector, 0, 1) == FAILURE)
3072 if (array_check (mask, 1) == FAILURE)
3075 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
3078 if (same_type_check (vector, 0, field, 2) == FAILURE)
3081 if (mask->rank != field->rank && field->rank != 0)
3083 gfc_error ("FIELD argument at %L of UNPACK must have the same rank as "
3084 "MASK or be a scalar", &field->where);
3088 if (mask->rank == field->rank)
3091 for (i = 0; i < field->rank; i++)
3092 if (! identical_dimen_shape (mask, i, field, i))
3094 gfc_error ("Different shape in dimension %d for MASK and FIELD "
3095 "arguments of UNPACK at %L", mask->rank, &field->where);
3105 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
3107 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3110 if (same_type_check (x, 0, y, 1) == FAILURE)
3113 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
3116 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
3118 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3119 "with KIND argument at %L",
3120 gfc_current_intrinsic, &kind->where) == FAILURE)
3128 gfc_check_trim (gfc_expr *x)
3130 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3133 if (scalar_check (x, 0) == FAILURE)
3141 gfc_check_ttynam (gfc_expr *unit)
3143 if (scalar_check (unit, 0) == FAILURE)
3146 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3153 /* Common check function for the half a dozen intrinsics that have a
3154 single real argument. */
3157 gfc_check_x (gfc_expr *x)
3159 if (type_check (x, 0, BT_REAL) == FAILURE)
3166 /************* Check functions for intrinsic subroutines *************/
3169 gfc_check_cpu_time (gfc_expr *time)
3171 if (scalar_check (time, 0) == FAILURE)
3174 if (type_check (time, 0, BT_REAL) == FAILURE)
3177 if (variable_check (time, 0) == FAILURE)
3185 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
3186 gfc_expr *zone, gfc_expr *values)
3190 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3192 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
3194 if (scalar_check (date, 0) == FAILURE)
3196 if (variable_check (date, 0) == FAILURE)
3202 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
3204 if (kind_value_check (time, 1, gfc_default_character_kind) == FAILURE)
3206 if (scalar_check (time, 1) == FAILURE)
3208 if (variable_check (time, 1) == FAILURE)
3214 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
3216 if (kind_value_check (zone, 2, gfc_default_character_kind) == FAILURE)
3218 if (scalar_check (zone, 2) == FAILURE)
3220 if (variable_check (zone, 2) == FAILURE)
3226 if (type_check (values, 3, BT_INTEGER) == FAILURE)
3228 if (array_check (values, 3) == FAILURE)
3230 if (rank_check (values, 3, 1) == FAILURE)
3232 if (variable_check (values, 3) == FAILURE)
3241 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
3242 gfc_expr *to, gfc_expr *topos)
3244 if (type_check (from, 0, BT_INTEGER) == FAILURE)
3247 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
3250 if (type_check (len, 2, BT_INTEGER) == FAILURE)
3253 if (same_type_check (from, 0, to, 3) == FAILURE)
3256 if (variable_check (to, 3) == FAILURE)
3259 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
3267 gfc_check_random_number (gfc_expr *harvest)
3269 if (type_check (harvest, 0, BT_REAL) == FAILURE)
3272 if (variable_check (harvest, 0) == FAILURE)
3280 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
3282 unsigned int nargs = 0, kiss_size;
3283 locus *where = NULL;
3284 mpz_t put_size, get_size;
3285 bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
3287 have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
3289 /* Keep the number of bytes in sync with kiss_size in
3290 libgfortran/intrinsics/random.c. */
3291 kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind;
3295 if (size->expr_type != EXPR_VARIABLE
3296 || !size->symtree->n.sym->attr.optional)
3299 if (scalar_check (size, 0) == FAILURE)
3302 if (type_check (size, 0, BT_INTEGER) == FAILURE)
3305 if (variable_check (size, 0) == FAILURE)
3308 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
3314 if (put->expr_type != EXPR_VARIABLE
3315 || !put->symtree->n.sym->attr.optional)
3318 where = &put->where;
3321 if (array_check (put, 1) == FAILURE)
3324 if (rank_check (put, 1, 1) == FAILURE)
3327 if (type_check (put, 1, BT_INTEGER) == FAILURE)
3330 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
3333 if (gfc_array_size (put, &put_size) == SUCCESS
3334 && mpz_get_ui (put_size) < kiss_size)
3335 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3336 "too small (%i/%i)",
3337 gfc_current_intrinsic_arg[1], gfc_current_intrinsic, where,
3338 (int) mpz_get_ui (put_size), kiss_size);
3343 if (get->expr_type != EXPR_VARIABLE
3344 || !get->symtree->n.sym->attr.optional)
3347 where = &get->where;
3350 if (array_check (get, 2) == FAILURE)
3353 if (rank_check (get, 2, 1) == FAILURE)
3356 if (type_check (get, 2, BT_INTEGER) == FAILURE)
3359 if (variable_check (get, 2) == FAILURE)
3362 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
3365 if (gfc_array_size (get, &get_size) == SUCCESS
3366 && mpz_get_ui (get_size) < kiss_size)
3367 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3368 "too small (%i/%i)",
3369 gfc_current_intrinsic_arg[2], gfc_current_intrinsic, where,
3370 (int) mpz_get_ui (get_size), kiss_size);
3373 /* RANDOM_SEED may not have more than one non-optional argument. */
3375 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
3382 gfc_check_second_sub (gfc_expr *time)
3384 if (scalar_check (time, 0) == FAILURE)
3387 if (type_check (time, 0, BT_REAL) == FAILURE)
3390 if (kind_value_check(time, 0, 4) == FAILURE)
3397 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
3398 count, count_rate, and count_max are all optional arguments */
3401 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
3402 gfc_expr *count_max)
3406 if (scalar_check (count, 0) == FAILURE)
3409 if (type_check (count, 0, BT_INTEGER) == FAILURE)
3412 if (variable_check (count, 0) == FAILURE)
3416 if (count_rate != NULL)
3418 if (scalar_check (count_rate, 1) == FAILURE)
3421 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
3424 if (variable_check (count_rate, 1) == FAILURE)
3428 && same_type_check (count, 0, count_rate, 1) == FAILURE)
3433 if (count_max != NULL)
3435 if (scalar_check (count_max, 2) == FAILURE)
3438 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
3441 if (variable_check (count_max, 2) == FAILURE)
3445 && same_type_check (count, 0, count_max, 2) == FAILURE)
3448 if (count_rate != NULL
3449 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
3458 gfc_check_irand (gfc_expr *x)
3463 if (scalar_check (x, 0) == FAILURE)
3466 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3469 if (kind_value_check(x, 0, 4) == FAILURE)
3477 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
3479 if (scalar_check (seconds, 0) == FAILURE)
3482 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3485 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3487 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3488 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3489 gfc_current_intrinsic, &handler->where);
3493 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3499 if (scalar_check (status, 2) == FAILURE)
3502 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3505 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3513 gfc_check_rand (gfc_expr *x)
3518 if (scalar_check (x, 0) == FAILURE)
3521 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3524 if (kind_value_check(x, 0, 4) == FAILURE)
3532 gfc_check_srand (gfc_expr *x)
3534 if (scalar_check (x, 0) == FAILURE)
3537 if (type_check (x, 0, BT_INTEGER) == FAILURE)
3540 if (kind_value_check(x, 0, 4) == FAILURE)
3548 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
3550 if (scalar_check (time, 0) == FAILURE)
3552 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3555 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
3557 if (kind_value_check (result, 1, gfc_default_character_kind) == FAILURE)
3565 gfc_check_dtime_etime (gfc_expr *x)
3567 if (array_check (x, 0) == FAILURE)
3570 if (rank_check (x, 0, 1) == FAILURE)
3573 if (variable_check (x, 0) == FAILURE)
3576 if (type_check (x, 0, BT_REAL) == FAILURE)
3579 if (kind_value_check(x, 0, 4) == FAILURE)
3587 gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
3589 if (array_check (values, 0) == FAILURE)
3592 if (rank_check (values, 0, 1) == FAILURE)
3595 if (variable_check (values, 0) == FAILURE)
3598 if (type_check (values, 0, BT_REAL) == FAILURE)
3601 if (kind_value_check(values, 0, 4) == FAILURE)
3604 if (scalar_check (time, 1) == FAILURE)
3607 if (type_check (time, 1, BT_REAL) == FAILURE)
3610 if (kind_value_check(time, 1, 4) == FAILURE)
3618 gfc_check_fdate_sub (gfc_expr *date)
3620 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3622 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
3630 gfc_check_gerror (gfc_expr *msg)
3632 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3634 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
3642 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
3644 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
3646 if (kind_value_check (cwd, 0, gfc_default_character_kind) == FAILURE)
3652 if (scalar_check (status, 1) == FAILURE)
3655 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3663 gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
3665 if (type_check (pos, 0, BT_INTEGER) == FAILURE)
3668 if (pos->ts.kind > gfc_default_integer_kind)
3670 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
3671 "not wider than the default kind (%d)",
3672 gfc_current_intrinsic_arg[0], gfc_current_intrinsic,
3673 &pos->where, gfc_default_integer_kind);
3677 if (type_check (value, 1, BT_CHARACTER) == FAILURE)
3679 if (kind_value_check (value, 1, gfc_default_character_kind) == FAILURE)
3687 gfc_check_getlog (gfc_expr *msg)
3689 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
3691 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
3699 gfc_check_exit (gfc_expr *status)
3704 if (type_check (status, 0, BT_INTEGER) == FAILURE)
3707 if (scalar_check (status, 0) == FAILURE)
3715 gfc_check_flush (gfc_expr *unit)
3720 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3723 if (scalar_check (unit, 0) == FAILURE)
3731 gfc_check_free (gfc_expr *i)
3733 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3736 if (scalar_check (i, 0) == FAILURE)
3744 gfc_check_hostnm (gfc_expr *name)
3746 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3748 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3756 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
3758 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3760 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3766 if (scalar_check (status, 1) == FAILURE)
3769 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3777 gfc_check_itime_idate (gfc_expr *values)
3779 if (array_check (values, 0) == FAILURE)
3782 if (rank_check (values, 0, 1) == FAILURE)
3785 if (variable_check (values, 0) == FAILURE)
3788 if (type_check (values, 0, BT_INTEGER) == FAILURE)
3791 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
3799 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
3801 if (type_check (time, 0, BT_INTEGER) == FAILURE)
3804 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
3807 if (scalar_check (time, 0) == FAILURE)
3810 if (array_check (values, 1) == FAILURE)
3813 if (rank_check (values, 1, 1) == FAILURE)
3816 if (variable_check (values, 1) == FAILURE)
3819 if (type_check (values, 1, BT_INTEGER) == FAILURE)
3822 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
3830 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
3832 if (scalar_check (unit, 0) == FAILURE)
3835 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3838 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
3840 if (kind_value_check (name, 1, gfc_default_character_kind) == FAILURE)
3848 gfc_check_isatty (gfc_expr *unit)
3853 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3856 if (scalar_check (unit, 0) == FAILURE)
3864 gfc_check_isnan (gfc_expr *x)
3866 if (type_check (x, 0, BT_REAL) == FAILURE)
3874 gfc_check_perror (gfc_expr *string)
3876 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
3878 if (kind_value_check (string, 0, gfc_default_character_kind) == FAILURE)
3886 gfc_check_umask (gfc_expr *mask)
3888 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3891 if (scalar_check (mask, 0) == FAILURE)
3899 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
3901 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
3904 if (scalar_check (mask, 0) == FAILURE)
3910 if (scalar_check (old, 1) == FAILURE)
3913 if (type_check (old, 1, BT_INTEGER) == FAILURE)
3921 gfc_check_unlink (gfc_expr *name)
3923 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3925 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3933 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
3935 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3937 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3943 if (scalar_check (status, 1) == FAILURE)
3946 if (type_check (status, 1, BT_INTEGER) == FAILURE)
3954 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
3956 if (scalar_check (number, 0) == FAILURE)
3959 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3962 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3964 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3965 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3966 gfc_current_intrinsic, &handler->where);
3970 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
3978 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
3980 if (scalar_check (number, 0) == FAILURE)
3983 if (type_check (number, 0, BT_INTEGER) == FAILURE)
3986 if (handler->ts.type != BT_INTEGER && handler->ts.type != BT_PROCEDURE)
3988 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3989 "or PROCEDURE", gfc_current_intrinsic_arg[1],
3990 gfc_current_intrinsic, &handler->where);
3994 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4000 if (type_check (status, 2, BT_INTEGER) == FAILURE)
4003 if (scalar_check (status, 2) == FAILURE)
4011 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
4013 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
4015 if (kind_value_check (cmd, 0, gfc_default_character_kind) == FAILURE)
4018 if (scalar_check (status, 1) == FAILURE)
4021 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4024 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
4031 /* This is used for the GNU intrinsics AND, OR and XOR. */
4033 gfc_check_and (gfc_expr *i, gfc_expr *j)
4035 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
4037 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4038 "or LOGICAL", gfc_current_intrinsic_arg[0],
4039 gfc_current_intrinsic, &i->where);
4043 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
4045 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4046 "or LOGICAL", gfc_current_intrinsic_arg[1],
4047 gfc_current_intrinsic, &j->where);
4051 if (i->ts.type != j->ts.type)
4053 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
4054 "have the same type", gfc_current_intrinsic_arg[0],
4055 gfc_current_intrinsic_arg[1], gfc_current_intrinsic,
4060 if (scalar_check (i, 0) == FAILURE)
4063 if (scalar_check (j, 1) == FAILURE)