2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught & Katherine Holcomb
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* These functions check to see if an argument list is compatible with
24 a particular intrinsic function or subroutine. Presence of
25 required arguments has already been established, the argument list
26 has been sorted into the right order and has NULL arguments in the
27 correct places for missing optional arguments. */
33 #include "intrinsic.h"
34 #include "constructor.h"
37 /* Make sure an expression is a scalar. */
40 scalar_check (gfc_expr *e, int n)
45 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
46 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
53 /* Check the type of an expression. */
56 type_check (gfc_expr *e, int n, bt type)
58 if (e->ts.type == type)
61 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
62 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
63 &e->where, gfc_basic_typename (type));
69 /* Check that the expression is a numeric type. */
72 numeric_check (gfc_expr *e, int n)
74 if (gfc_numeric_ts (&e->ts))
77 /* If the expression has not got a type, check if its namespace can
78 offer a default type. */
79 if ((e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_VARIABLE)
80 && e->symtree->n.sym->ts.type == BT_UNKNOWN
81 && gfc_set_default_type (e->symtree->n.sym, 0,
82 e->symtree->n.sym->ns) == SUCCESS
83 && gfc_numeric_ts (&e->symtree->n.sym->ts))
85 e->ts = e->symtree->n.sym->ts;
89 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
90 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
97 /* Check that an expression is integer or real. */
100 int_or_real_check (gfc_expr *e, int n)
102 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
104 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
105 "or REAL", gfc_current_intrinsic_arg[n]->name,
106 gfc_current_intrinsic, &e->where);
114 /* Check that an expression is real or complex. */
117 real_or_complex_check (gfc_expr *e, int n)
119 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
121 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
122 "or COMPLEX", gfc_current_intrinsic_arg[n]->name,
123 gfc_current_intrinsic, &e->where);
131 /* Check that an expression is INTEGER or PROCEDURE. */
134 int_or_proc_check (gfc_expr *e, int n)
136 if (e->ts.type != BT_INTEGER && e->ts.type != BT_PROCEDURE)
138 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
139 "or PROCEDURE", gfc_current_intrinsic_arg[n]->name,
140 gfc_current_intrinsic, &e->where);
148 /* Check that the expression is an optional constant integer
149 and that it specifies a valid kind for that type. */
152 kind_check (gfc_expr *k, int n, bt type)
159 if (type_check (k, n, BT_INTEGER) == FAILURE)
162 if (scalar_check (k, n) == FAILURE)
165 if (k->expr_type != EXPR_CONSTANT)
167 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
168 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
173 if (gfc_extract_int (k, &kind) != NULL
174 || gfc_validate_kind (type, kind, true) < 0)
176 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
185 /* Make sure the expression is a double precision real. */
188 double_check (gfc_expr *d, int n)
190 if (type_check (d, n, BT_REAL) == FAILURE)
193 if (d->ts.kind != gfc_default_double_kind)
195 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
196 "precision", gfc_current_intrinsic_arg[n]->name,
197 gfc_current_intrinsic, &d->where);
205 /* Check whether an expression is a coarray (without array designator). */
208 is_coarray (gfc_expr *e)
210 bool coarray = false;
213 if (e->expr_type != EXPR_VARIABLE)
216 coarray = e->symtree->n.sym->attr.codimension;
218 for (ref = e->ref; ref; ref = ref->next)
220 if (ref->type == REF_COMPONENT)
221 coarray = ref->u.c.component->attr.codimension;
222 else if (ref->type != REF_ARRAY || ref->u.ar.dimen != 0
223 || ref->u.ar.codimen != 0)
232 coarray_check (gfc_expr *e, int n)
236 gfc_error ("Expected coarray variable as '%s' argument to the %s "
237 "intrinsic at %L", gfc_current_intrinsic_arg[n]->name,
238 gfc_current_intrinsic, &e->where);
246 /* Make sure the expression is a logical array. */
249 logical_array_check (gfc_expr *array, int n)
251 if (array->ts.type != BT_LOGICAL || array->rank == 0)
253 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
254 "array", gfc_current_intrinsic_arg[n]->name,
255 gfc_current_intrinsic, &array->where);
263 /* Make sure an expression is an array. */
266 array_check (gfc_expr *e, int n)
271 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
272 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
279 /* If expr is a constant, then check to ensure that it is greater than
283 nonnegative_check (const char *arg, gfc_expr *expr)
287 if (expr->expr_type == EXPR_CONSTANT)
289 gfc_extract_int (expr, &i);
292 gfc_error ("'%s' at %L must be nonnegative", arg, &expr->where);
301 /* If expr2 is constant, then check that the value is less than
305 less_than_bitsize1 (const char *arg1, gfc_expr *expr1, const char *arg2,
310 if (expr2->expr_type == EXPR_CONSTANT)
312 gfc_extract_int (expr2, &i2);
313 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
314 if (i2 >= gfc_integer_kinds[i3].bit_size)
316 gfc_error ("'%s' at %L must be less than BIT_SIZE('%s')",
317 arg2, &expr2->where, arg1);
326 /* If expr2 and expr3 are constants, then check that the value is less than
327 or equal to bit_size(expr1). */
330 less_than_bitsize2 (const char *arg1, gfc_expr *expr1, const char *arg2,
331 gfc_expr *expr2, const char *arg3, gfc_expr *expr3)
335 if (expr2->expr_type == EXPR_CONSTANT && expr3->expr_type == EXPR_CONSTANT)
337 gfc_extract_int (expr2, &i2);
338 gfc_extract_int (expr3, &i3);
340 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
341 if (i2 > gfc_integer_kinds[i3].bit_size)
343 gfc_error ("'%s + %s' at %L must be less than or equal "
345 arg2, arg3, &expr2->where, arg1);
353 /* Make sure two expressions have the same type. */
356 same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
358 if (gfc_compare_types (&e->ts, &f->ts))
361 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
362 "and kind as '%s'", gfc_current_intrinsic_arg[m]->name,
363 gfc_current_intrinsic, &f->where,
364 gfc_current_intrinsic_arg[n]->name);
370 /* Make sure that an expression has a certain (nonzero) rank. */
373 rank_check (gfc_expr *e, int n, int rank)
378 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
379 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
386 /* Make sure a variable expression is not an optional dummy argument. */
389 nonoptional_check (gfc_expr *e, int n)
391 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
393 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
394 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
398 /* TODO: Recursive check on nonoptional variables? */
404 /* Check for ALLOCATABLE attribute. */
407 allocatable_check (gfc_expr *e, int n)
409 symbol_attribute attr;
411 attr = gfc_variable_attr (e, NULL);
412 if (!attr.allocatable)
414 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
415 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
424 /* Check that an expression has a particular kind. */
427 kind_value_check (gfc_expr *e, int n, int k)
432 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
433 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
440 /* Make sure an expression is a variable. */
443 variable_check (gfc_expr *e, int n)
445 if (e->expr_type == EXPR_VARIABLE
446 && e->symtree->n.sym->attr.intent == INTENT_IN
447 && (gfc_current_intrinsic_arg[n]->intent == INTENT_OUT
448 || gfc_current_intrinsic_arg[n]->intent == INTENT_INOUT))
450 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
451 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
456 if ((e->expr_type == EXPR_VARIABLE
457 && e->symtree->n.sym->attr.flavor != FL_PARAMETER)
458 || (e->expr_type == EXPR_FUNCTION
459 && e->symtree->n.sym->result == e->symtree->n.sym))
462 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
463 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, &e->where);
469 /* Check the common DIM parameter for correctness. */
472 dim_check (gfc_expr *dim, int n, bool optional)
477 if (type_check (dim, n, BT_INTEGER) == FAILURE)
480 if (scalar_check (dim, n) == FAILURE)
483 if (!optional && nonoptional_check (dim, n) == FAILURE)
490 /* If a coarray DIM parameter is a constant, make sure that it is greater than
491 zero and less than or equal to the corank of the given array. */
494 dim_corank_check (gfc_expr *dim, gfc_expr *array)
499 gcc_assert (array->expr_type == EXPR_VARIABLE);
501 if (dim->expr_type != EXPR_CONSTANT)
504 ar = gfc_find_array_ref (array);
505 corank = ar->as->corank;
507 if (mpz_cmp_ui (dim->value.integer, 1) < 0
508 || mpz_cmp_ui (dim->value.integer, corank) > 0)
510 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
511 "codimension index", gfc_current_intrinsic, &dim->where);
520 /* If a DIM parameter is a constant, make sure that it is greater than
521 zero and less than or equal to the rank of the given array. If
522 allow_assumed is zero then dim must be less than the rank of the array
523 for assumed size arrays. */
526 dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
534 if (dim->expr_type != EXPR_CONSTANT)
537 if (array->expr_type == EXPR_FUNCTION && array->value.function.isym
538 && array->value.function.isym->id == GFC_ISYM_SPREAD)
539 rank = array->rank + 1;
543 if (array->expr_type == EXPR_VARIABLE)
545 ar = gfc_find_array_ref (array);
546 if (ar->as->type == AS_ASSUMED_SIZE
548 && ar->type != AR_ELEMENT
549 && ar->type != AR_SECTION)
553 if (mpz_cmp_ui (dim->value.integer, 1) < 0
554 || mpz_cmp_ui (dim->value.integer, rank) > 0)
556 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
557 "dimension index", gfc_current_intrinsic, &dim->where);
566 /* Compare the size of a along dimension ai with the size of b along
567 dimension bi, returning 0 if they are known not to be identical,
568 and 1 if they are identical, or if this cannot be determined. */
571 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
573 mpz_t a_size, b_size;
576 gcc_assert (a->rank > ai);
577 gcc_assert (b->rank > bi);
581 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
583 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
585 if (mpz_cmp (a_size, b_size) != 0)
596 /* Check whether two character expressions have the same length;
597 returns SUCCESS if they have or if the length cannot be determined. */
600 gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
605 if (a->ts.u.cl && a->ts.u.cl->length
606 && a->ts.u.cl->length->expr_type == EXPR_CONSTANT)
607 len_a = mpz_get_si (a->ts.u.cl->length->value.integer);
608 else if (a->expr_type == EXPR_CONSTANT
609 && (a->ts.u.cl == NULL || a->ts.u.cl->length == NULL))
610 len_a = a->value.character.length;
614 if (b->ts.u.cl && b->ts.u.cl->length
615 && b->ts.u.cl->length->expr_type == EXPR_CONSTANT)
616 len_b = mpz_get_si (b->ts.u.cl->length->value.integer);
617 else if (b->expr_type == EXPR_CONSTANT
618 && (b->ts.u.cl == NULL || b->ts.u.cl->length == NULL))
619 len_b = b->value.character.length;
626 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
627 len_a, len_b, name, &a->where);
632 /***** Check functions *****/
634 /* Check subroutine suitable for intrinsics taking a real argument and
635 a kind argument for the result. */
638 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
640 if (type_check (a, 0, BT_REAL) == FAILURE)
642 if (kind_check (kind, 1, type) == FAILURE)
649 /* Check subroutine suitable for ceiling, floor and nint. */
652 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
654 return check_a_kind (a, kind, BT_INTEGER);
658 /* Check subroutine suitable for aint, anint. */
661 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
663 return check_a_kind (a, kind, BT_REAL);
668 gfc_check_abs (gfc_expr *a)
670 if (numeric_check (a, 0) == FAILURE)
678 gfc_check_achar (gfc_expr *a, gfc_expr *kind)
680 if (type_check (a, 0, BT_INTEGER) == FAILURE)
682 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
690 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
692 if (type_check (name, 0, BT_CHARACTER) == FAILURE
693 || scalar_check (name, 0) == FAILURE)
695 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
698 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
699 || scalar_check (mode, 1) == FAILURE)
701 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
709 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
711 if (logical_array_check (mask, 0) == FAILURE)
714 if (dim_check (dim, 1, false) == FAILURE)
717 if (dim_rank_check (dim, mask, 0) == FAILURE)
725 gfc_check_allocated (gfc_expr *array)
727 if (variable_check (array, 0) == FAILURE)
729 if (allocatable_check (array, 0) == FAILURE)
736 /* Common check function where the first argument must be real or
737 integer and the second argument must be the same as the first. */
740 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
742 if (int_or_real_check (a, 0) == FAILURE)
745 if (a->ts.type != p->ts.type)
747 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
748 "have the same type", gfc_current_intrinsic_arg[0]->name,
749 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
754 if (a->ts.kind != p->ts.kind)
756 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
757 &p->where) == FAILURE)
766 gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
768 if (double_check (x, 0) == FAILURE || double_check (y, 1) == FAILURE)
776 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
778 symbol_attribute attr1, attr2;
783 where = &pointer->where;
785 if (pointer->expr_type == EXPR_VARIABLE || pointer->expr_type == EXPR_FUNCTION)
786 attr1 = gfc_expr_attr (pointer);
787 else if (pointer->expr_type == EXPR_NULL)
790 gcc_assert (0); /* Pointer must be a variable or a function. */
792 if (!attr1.pointer && !attr1.proc_pointer)
794 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
795 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
800 /* Target argument is optional. */
804 where = &target->where;
805 if (target->expr_type == EXPR_NULL)
808 if (target->expr_type == EXPR_VARIABLE || target->expr_type == EXPR_FUNCTION)
809 attr2 = gfc_expr_attr (target);
812 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
813 "or target VARIABLE or FUNCTION",
814 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
819 if (attr1.pointer && !attr2.pointer && !attr2.target)
821 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
822 "or a TARGET", gfc_current_intrinsic_arg[1]->name,
823 gfc_current_intrinsic, &target->where);
828 if (same_type_check (pointer, 0, target, 1) == FAILURE)
830 if (rank_check (target, 0, pointer->rank) == FAILURE)
832 if (target->rank > 0)
834 for (i = 0; i < target->rank; i++)
835 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
837 gfc_error ("Array section with a vector subscript at %L shall not "
838 "be the target of a pointer",
848 gfc_error ("NULL pointer at %L is not permitted as actual argument "
849 "of '%s' intrinsic function", where, gfc_current_intrinsic);
856 gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
858 /* gfc_notify_std would be a wast of time as the return value
859 is seemingly used only for the generic resolution. The error
860 will be: Too many arguments. */
861 if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
864 return gfc_check_atan2 (y, x);
869 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
871 if (type_check (y, 0, BT_REAL) == FAILURE)
873 if (same_type_check (y, 0, x, 1) == FAILURE)
880 /* BESJN and BESYN functions. */
883 gfc_check_besn (gfc_expr *n, gfc_expr *x)
885 if (type_check (n, 0, BT_INTEGER) == FAILURE)
887 if (n->expr_type == EXPR_CONSTANT)
890 gfc_extract_int (n, &i);
891 if (i < 0 && gfc_notify_std (GFC_STD_GNU, "Extension: Negative argument "
892 "N at %L", &n->where) == FAILURE)
896 if (type_check (x, 1, BT_REAL) == FAILURE)
903 /* Transformational version of the Bessel JN and YN functions. */
906 gfc_check_bessel_n2 (gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
908 if (type_check (n1, 0, BT_INTEGER) == FAILURE)
910 if (scalar_check (n1, 0) == FAILURE)
912 if (nonnegative_check("N1", n1) == FAILURE)
915 if (type_check (n2, 1, BT_INTEGER) == FAILURE)
917 if (scalar_check (n2, 1) == FAILURE)
919 if (nonnegative_check("N2", n2) == FAILURE)
922 if (type_check (x, 2, BT_REAL) == FAILURE)
924 if (scalar_check (x, 2) == FAILURE)
932 gfc_check_bitfcn (gfc_expr *i, gfc_expr *pos)
934 if (type_check (i, 0, BT_INTEGER) == FAILURE)
937 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
940 if (nonnegative_check ("pos", pos) == FAILURE)
943 if (less_than_bitsize1 ("i", i, "pos", pos) == FAILURE)
951 gfc_check_char (gfc_expr *i, gfc_expr *kind)
953 if (type_check (i, 0, BT_INTEGER) == FAILURE)
955 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
963 gfc_check_chdir (gfc_expr *dir)
965 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
967 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
975 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
977 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
979 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
985 if (type_check (status, 1, BT_INTEGER) == FAILURE)
987 if (scalar_check (status, 1) == FAILURE)
995 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
997 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
999 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
1002 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
1004 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
1012 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
1014 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
1016 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
1019 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
1021 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
1027 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1030 if (scalar_check (status, 2) == FAILURE)
1038 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
1040 if (numeric_check (x, 0) == FAILURE)
1045 if (numeric_check (y, 1) == FAILURE)
1048 if (x->ts.type == BT_COMPLEX)
1050 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1051 "present if 'x' is COMPLEX",
1052 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1057 if (y->ts.type == BT_COMPLEX)
1059 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1060 "of either REAL or INTEGER",
1061 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1068 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
1076 gfc_check_complex (gfc_expr *x, gfc_expr *y)
1078 if (int_or_real_check (x, 0) == FAILURE)
1080 if (scalar_check (x, 0) == FAILURE)
1083 if (int_or_real_check (y, 1) == FAILURE)
1085 if (scalar_check (y, 1) == FAILURE)
1093 gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
1095 if (logical_array_check (mask, 0) == FAILURE)
1097 if (dim_check (dim, 1, false) == FAILURE)
1099 if (dim_rank_check (dim, mask, 0) == FAILURE)
1101 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1103 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1104 "with KIND argument at %L",
1105 gfc_current_intrinsic, &kind->where) == FAILURE)
1113 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
1115 if (array_check (array, 0) == FAILURE)
1118 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1121 if (dim_check (dim, 2, true) == FAILURE)
1124 if (dim_rank_check (dim, array, false) == FAILURE)
1127 if (array->rank == 1 || shift->rank == 0)
1129 if (scalar_check (shift, 1) == FAILURE)
1132 else if (shift->rank == array->rank - 1)
1137 else if (dim->expr_type == EXPR_CONSTANT)
1138 gfc_extract_int (dim, &d);
1145 for (i = 0, j = 0; i < array->rank; i++)
1148 if (!identical_dimen_shape (array, i, shift, j))
1150 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1151 "invalid shape in dimension %d (%ld/%ld)",
1152 gfc_current_intrinsic_arg[1]->name,
1153 gfc_current_intrinsic, &shift->where, i + 1,
1154 mpz_get_si (array->shape[i]),
1155 mpz_get_si (shift->shape[j]));
1165 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1166 "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
1167 gfc_current_intrinsic, &shift->where, array->rank - 1);
1176 gfc_check_ctime (gfc_expr *time)
1178 if (scalar_check (time, 0) == FAILURE)
1181 if (type_check (time, 0, BT_INTEGER) == FAILURE)
1188 gfc_try gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
1190 if (double_check (y, 0) == FAILURE || double_check (x, 1) == FAILURE)
1197 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
1199 if (numeric_check (x, 0) == FAILURE)
1204 if (numeric_check (y, 1) == FAILURE)
1207 if (x->ts.type == BT_COMPLEX)
1209 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1210 "present if 'x' is COMPLEX",
1211 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1216 if (y->ts.type == BT_COMPLEX)
1218 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1219 "of either REAL or INTEGER",
1220 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1231 gfc_check_dble (gfc_expr *x)
1233 if (numeric_check (x, 0) == FAILURE)
1241 gfc_check_digits (gfc_expr *x)
1243 if (int_or_real_check (x, 0) == FAILURE)
1251 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
1253 switch (vector_a->ts.type)
1256 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
1263 if (numeric_check (vector_b, 1) == FAILURE)
1268 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1269 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
1270 gfc_current_intrinsic, &vector_a->where);
1274 if (rank_check (vector_a, 0, 1) == FAILURE)
1277 if (rank_check (vector_b, 1, 1) == FAILURE)
1280 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
1282 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1283 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0]->name,
1284 gfc_current_intrinsic_arg[1]->name, &vector_a->where);
1293 gfc_check_dprod (gfc_expr *x, gfc_expr *y)
1295 if (type_check (x, 0, BT_REAL) == FAILURE
1296 || type_check (y, 1, BT_REAL) == FAILURE)
1299 if (x->ts.kind != gfc_default_real_kind)
1301 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1302 "real", gfc_current_intrinsic_arg[0]->name,
1303 gfc_current_intrinsic, &x->where);
1307 if (y->ts.kind != gfc_default_real_kind)
1309 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1310 "real", gfc_current_intrinsic_arg[1]->name,
1311 gfc_current_intrinsic, &y->where);
1320 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
1323 if (array_check (array, 0) == FAILURE)
1326 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1329 if (dim_check (dim, 3, true) == FAILURE)
1332 if (dim_rank_check (dim, array, false) == FAILURE)
1335 if (array->rank == 1 || shift->rank == 0)
1337 if (scalar_check (shift, 1) == FAILURE)
1340 else if (shift->rank == array->rank - 1)
1345 else if (dim->expr_type == EXPR_CONSTANT)
1346 gfc_extract_int (dim, &d);
1353 for (i = 0, j = 0; i < array->rank; i++)
1356 if (!identical_dimen_shape (array, i, shift, j))
1358 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1359 "invalid shape in dimension %d (%ld/%ld)",
1360 gfc_current_intrinsic_arg[1]->name,
1361 gfc_current_intrinsic, &shift->where, i + 1,
1362 mpz_get_si (array->shape[i]),
1363 mpz_get_si (shift->shape[j]));
1373 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1374 "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
1375 gfc_current_intrinsic, &shift->where, array->rank - 1);
1379 if (boundary != NULL)
1381 if (same_type_check (array, 0, boundary, 2) == FAILURE)
1384 if (array->rank == 1 || boundary->rank == 0)
1386 if (scalar_check (boundary, 2) == FAILURE)
1389 else if (boundary->rank == array->rank - 1)
1391 if (gfc_check_conformance (shift, boundary,
1392 "arguments '%s' and '%s' for "
1394 gfc_current_intrinsic_arg[1]->name,
1395 gfc_current_intrinsic_arg[2]->name,
1396 gfc_current_intrinsic ) == FAILURE)
1401 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1402 "rank %d or be a scalar",
1403 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1404 &shift->where, array->rank - 1);
1413 gfc_check_float (gfc_expr *a)
1415 if (type_check (a, 0, BT_INTEGER) == FAILURE)
1418 if ((a->ts.kind != gfc_default_integer_kind)
1419 && gfc_notify_std (GFC_STD_GNU, "GNU extension: non-default INTEGER"
1420 "kind argument to %s intrinsic at %L",
1421 gfc_current_intrinsic, &a->where) == FAILURE )
1427 /* A single complex argument. */
1430 gfc_check_fn_c (gfc_expr *a)
1432 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
1438 /* A single real argument. */
1441 gfc_check_fn_r (gfc_expr *a)
1443 if (type_check (a, 0, BT_REAL) == FAILURE)
1449 /* A single double argument. */
1452 gfc_check_fn_d (gfc_expr *a)
1454 if (double_check (a, 0) == FAILURE)
1460 /* A single real or complex argument. */
1463 gfc_check_fn_rc (gfc_expr *a)
1465 if (real_or_complex_check (a, 0) == FAILURE)
1473 gfc_check_fn_rc2008 (gfc_expr *a)
1475 if (real_or_complex_check (a, 0) == FAILURE)
1478 if (a->ts.type == BT_COMPLEX
1479 && gfc_notify_std (GFC_STD_F2008, "Fortran 2008: COMPLEX argument '%s' "
1480 "argument of '%s' intrinsic at %L",
1481 gfc_current_intrinsic_arg[0]->name,
1482 gfc_current_intrinsic, &a->where) == FAILURE)
1490 gfc_check_fnum (gfc_expr *unit)
1492 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1495 if (scalar_check (unit, 0) == FAILURE)
1503 gfc_check_huge (gfc_expr *x)
1505 if (int_or_real_check (x, 0) == FAILURE)
1513 gfc_check_hypot (gfc_expr *x, gfc_expr *y)
1515 if (type_check (x, 0, BT_REAL) == FAILURE)
1517 if (same_type_check (x, 0, y, 1) == FAILURE)
1524 /* Check that the single argument is an integer. */
1527 gfc_check_i (gfc_expr *i)
1529 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1537 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1539 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1542 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1545 if (i->ts.kind != j->ts.kind)
1547 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1548 &i->where) == FAILURE)
1557 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1559 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1562 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1565 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1568 if (nonnegative_check ("pos", pos) == FAILURE)
1571 if (nonnegative_check ("len", len) == FAILURE)
1574 if (less_than_bitsize2 ("i", i, "pos", pos, "len", len) == FAILURE)
1582 gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
1586 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1589 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1592 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1593 "with KIND argument at %L",
1594 gfc_current_intrinsic, &kind->where) == FAILURE)
1597 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1603 /* Substring references don't have the charlength set. */
1605 while (ref && ref->type != REF_SUBSTRING)
1608 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1612 /* Check that the argument is length one. Non-constant lengths
1613 can't be checked here, so assume they are ok. */
1614 if (c->ts.u.cl && c->ts.u.cl->length)
1616 /* If we already have a length for this expression then use it. */
1617 if (c->ts.u.cl->length->expr_type != EXPR_CONSTANT)
1619 i = mpz_get_si (c->ts.u.cl->length->value.integer);
1626 start = ref->u.ss.start;
1627 end = ref->u.ss.end;
1630 if (end == NULL || end->expr_type != EXPR_CONSTANT
1631 || start->expr_type != EXPR_CONSTANT)
1634 i = mpz_get_si (end->value.integer) + 1
1635 - mpz_get_si (start->value.integer);
1643 gfc_error ("Argument of %s at %L must be of length one",
1644 gfc_current_intrinsic, &c->where);
1653 gfc_check_idnint (gfc_expr *a)
1655 if (double_check (a, 0) == FAILURE)
1663 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1665 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1668 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1671 if (i->ts.kind != j->ts.kind)
1673 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1674 &i->where) == FAILURE)
1683 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back,
1686 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1687 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1690 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1693 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
1695 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1696 "with KIND argument at %L",
1697 gfc_current_intrinsic, &kind->where) == FAILURE)
1700 if (string->ts.kind != substring->ts.kind)
1702 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1703 "kind as '%s'", gfc_current_intrinsic_arg[1]->name,
1704 gfc_current_intrinsic, &substring->where,
1705 gfc_current_intrinsic_arg[0]->name);
1714 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1716 if (numeric_check (x, 0) == FAILURE)
1719 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1727 gfc_check_intconv (gfc_expr *x)
1729 if (numeric_check (x, 0) == FAILURE)
1737 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1739 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1742 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1745 if (i->ts.kind != j->ts.kind)
1747 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1748 &i->where) == FAILURE)
1757 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1759 if (type_check (i, 0, BT_INTEGER) == FAILURE
1760 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1768 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1770 if (type_check (i, 0, BT_INTEGER) == FAILURE
1771 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1774 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1782 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1784 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1787 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1795 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1797 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1800 if (scalar_check (pid, 0) == FAILURE)
1803 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1806 if (scalar_check (sig, 1) == FAILURE)
1812 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1815 if (scalar_check (status, 2) == FAILURE)
1823 gfc_check_kind (gfc_expr *x)
1825 if (x->ts.type == BT_DERIVED)
1827 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1828 "non-derived type", gfc_current_intrinsic_arg[0]->name,
1829 gfc_current_intrinsic, &x->where);
1838 gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1840 if (array_check (array, 0) == FAILURE)
1843 if (dim_check (dim, 1, false) == FAILURE)
1846 if (dim_rank_check (dim, array, 1) == FAILURE)
1849 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1851 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1852 "with KIND argument at %L",
1853 gfc_current_intrinsic, &kind->where) == FAILURE)
1861 gfc_check_lcobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
1863 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
1865 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
1869 if (coarray_check (coarray, 0) == FAILURE)
1874 if (dim_check (dim, 1, false) == FAILURE)
1877 if (dim_corank_check (dim, coarray) == FAILURE)
1881 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1889 gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
1891 if (type_check (s, 0, BT_CHARACTER) == FAILURE)
1894 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1896 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1897 "with KIND argument at %L",
1898 gfc_current_intrinsic, &kind->where) == FAILURE)
1906 gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
1908 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
1910 if (kind_value_check (a, 0, gfc_default_character_kind) == FAILURE)
1913 if (type_check (b, 1, BT_CHARACTER) == FAILURE)
1915 if (kind_value_check (b, 1, gfc_default_character_kind) == FAILURE)
1923 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
1925 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1927 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1930 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1932 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1940 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1942 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1944 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1947 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1949 if (kind_value_check (path2, 0, gfc_default_character_kind) == FAILURE)
1955 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1958 if (scalar_check (status, 2) == FAILURE)
1966 gfc_check_loc (gfc_expr *expr)
1968 return variable_check (expr, 0);
1973 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
1975 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1977 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1980 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1982 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
1990 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
1992 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
1994 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
1997 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
1999 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2005 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2008 if (scalar_check (status, 2) == FAILURE)
2016 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
2018 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
2020 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
2027 /* Min/max family. */
2030 min_max_args (gfc_actual_arglist *arg)
2032 if (arg == NULL || arg->next == NULL)
2034 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
2035 gfc_current_intrinsic, gfc_current_intrinsic_where);
2044 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
2046 gfc_actual_arglist *arg, *tmp;
2051 if (min_max_args (arglist) == FAILURE)
2054 for (arg = arglist, n=1; arg; arg = arg->next, n++)
2057 if (x->ts.type != type || x->ts.kind != kind)
2059 if (x->ts.type == type)
2061 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
2062 "kinds at %L", &x->where) == FAILURE)
2067 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
2068 "%s(%d)", n, gfc_current_intrinsic, &x->where,
2069 gfc_basic_typename (type), kind);
2074 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
2075 if (gfc_check_conformance (tmp->expr, x,
2076 "arguments 'a%d' and 'a%d' for "
2077 "intrinsic '%s'", m, n,
2078 gfc_current_intrinsic) == FAILURE)
2087 gfc_check_min_max (gfc_actual_arglist *arg)
2091 if (min_max_args (arg) == FAILURE)
2096 if (x->ts.type == BT_CHARACTER)
2098 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2099 "with CHARACTER argument at %L",
2100 gfc_current_intrinsic, &x->where) == FAILURE)
2103 else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
2105 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
2106 "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
2110 return check_rest (x->ts.type, x->ts.kind, arg);
2115 gfc_check_min_max_integer (gfc_actual_arglist *arg)
2117 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
2122 gfc_check_min_max_real (gfc_actual_arglist *arg)
2124 return check_rest (BT_REAL, gfc_default_real_kind, arg);
2129 gfc_check_min_max_double (gfc_actual_arglist *arg)
2131 return check_rest (BT_REAL, gfc_default_double_kind, arg);
2135 /* End of min/max family. */
2138 gfc_check_malloc (gfc_expr *size)
2140 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2143 if (scalar_check (size, 0) == FAILURE)
2151 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
2153 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
2155 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2156 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
2157 gfc_current_intrinsic, &matrix_a->where);
2161 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
2163 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2164 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
2165 gfc_current_intrinsic, &matrix_b->where);
2169 if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
2170 || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
2172 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2173 gfc_current_intrinsic, &matrix_a->where,
2174 gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
2178 switch (matrix_a->rank)
2181 if (rank_check (matrix_b, 1, 2) == FAILURE)
2183 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2184 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
2186 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2187 "and '%s' at %L for intrinsic matmul",
2188 gfc_current_intrinsic_arg[0]->name,
2189 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
2195 if (matrix_b->rank != 2)
2197 if (rank_check (matrix_b, 1, 1) == FAILURE)
2200 /* matrix_b has rank 1 or 2 here. Common check for the cases
2201 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2202 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2203 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
2205 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2206 "dimension 1 for argument '%s' at %L for intrinsic "
2207 "matmul", gfc_current_intrinsic_arg[0]->name,
2208 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
2214 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2215 "1 or 2", gfc_current_intrinsic_arg[0]->name,
2216 gfc_current_intrinsic, &matrix_a->where);
2224 /* Whoever came up with this interface was probably on something.
2225 The possibilities for the occupation of the second and third
2232 NULL MASK minloc(array, mask=m)
2235 I.e. in the case of minloc(array,mask), mask will be in the second
2236 position of the argument list and we'll have to fix that up. */
2239 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
2241 gfc_expr *a, *m, *d;
2244 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
2248 m = ap->next->next->expr;
2250 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2251 && ap->next->name == NULL)
2255 ap->next->expr = NULL;
2256 ap->next->next->expr = m;
2259 if (dim_check (d, 1, false) == FAILURE)
2262 if (dim_rank_check (d, a, 0) == FAILURE)
2265 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2269 && gfc_check_conformance (a, m,
2270 "arguments '%s' and '%s' for intrinsic %s",
2271 gfc_current_intrinsic_arg[0]->name,
2272 gfc_current_intrinsic_arg[2]->name,
2273 gfc_current_intrinsic ) == FAILURE)
2280 /* Similar to minloc/maxloc, the argument list might need to be
2281 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2282 difference is that MINLOC/MAXLOC take an additional KIND argument.
2283 The possibilities are:
2289 NULL MASK minval(array, mask=m)
2292 I.e. in the case of minval(array,mask), mask will be in the second
2293 position of the argument list and we'll have to fix that up. */
2296 check_reduction (gfc_actual_arglist *ap)
2298 gfc_expr *a, *m, *d;
2302 m = ap->next->next->expr;
2304 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2305 && ap->next->name == NULL)
2309 ap->next->expr = NULL;
2310 ap->next->next->expr = m;
2313 if (dim_check (d, 1, false) == FAILURE)
2316 if (dim_rank_check (d, a, 0) == FAILURE)
2319 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2323 && gfc_check_conformance (a, m,
2324 "arguments '%s' and '%s' for intrinsic %s",
2325 gfc_current_intrinsic_arg[0]->name,
2326 gfc_current_intrinsic_arg[2]->name,
2327 gfc_current_intrinsic) == FAILURE)
2335 gfc_check_minval_maxval (gfc_actual_arglist *ap)
2337 if (int_or_real_check (ap->expr, 0) == FAILURE
2338 || array_check (ap->expr, 0) == FAILURE)
2341 return check_reduction (ap);
2346 gfc_check_product_sum (gfc_actual_arglist *ap)
2348 if (numeric_check (ap->expr, 0) == FAILURE
2349 || array_check (ap->expr, 0) == FAILURE)
2352 return check_reduction (ap);
2356 /* For IANY, IALL and IPARITY. */
2359 gfc_check_transf_bit_intrins (gfc_actual_arglist *ap)
2361 if (ap->expr->ts.type != BT_INTEGER)
2363 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER",
2364 gfc_current_intrinsic_arg[0]->name,
2365 gfc_current_intrinsic, &ap->expr->where);
2369 if (array_check (ap->expr, 0) == FAILURE)
2372 return check_reduction (ap);
2377 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
2379 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
2382 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
2385 if (tsource->ts.type == BT_CHARACTER)
2386 return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
2393 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
2395 if (variable_check (from, 0) == FAILURE)
2397 if (allocatable_check (from, 0) == FAILURE)
2400 if (variable_check (to, 1) == FAILURE)
2402 if (allocatable_check (to, 1) == FAILURE)
2405 if (same_type_check (to, 1, from, 0) == FAILURE)
2408 if (to->rank != from->rank)
2410 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2411 "have the same rank %d/%d", gfc_current_intrinsic_arg[0]->name,
2412 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2413 &to->where, from->rank, to->rank);
2417 if (to->ts.kind != from->ts.kind)
2419 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2420 "be of the same kind %d/%d",
2421 gfc_current_intrinsic_arg[0]->name,
2422 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2423 &to->where, from->ts.kind, to->ts.kind);
2432 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
2434 if (type_check (x, 0, BT_REAL) == FAILURE)
2437 if (type_check (s, 1, BT_REAL) == FAILURE)
2445 gfc_check_new_line (gfc_expr *a)
2447 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2455 gfc_check_norm2 (gfc_expr *array, gfc_expr *dim)
2457 if (type_check (array, 0, BT_REAL) == FAILURE)
2460 if (array_check (array, 0) == FAILURE)
2463 if (dim_rank_check (dim, array, false) == FAILURE)
2470 gfc_check_null (gfc_expr *mold)
2472 symbol_attribute attr;
2477 if (variable_check (mold, 0) == FAILURE)
2480 attr = gfc_variable_attr (mold, NULL);
2482 if (!attr.pointer && !attr.proc_pointer)
2484 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
2485 gfc_current_intrinsic_arg[0]->name,
2486 gfc_current_intrinsic, &mold->where);
2495 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
2497 if (array_check (array, 0) == FAILURE)
2500 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2503 if (gfc_check_conformance (array, mask,
2504 "arguments '%s' and '%s' for intrinsic '%s'",
2505 gfc_current_intrinsic_arg[0]->name,
2506 gfc_current_intrinsic_arg[1]->name,
2507 gfc_current_intrinsic) == FAILURE)
2512 mpz_t array_size, vector_size;
2513 bool have_array_size, have_vector_size;
2515 if (same_type_check (array, 0, vector, 2) == FAILURE)
2518 if (rank_check (vector, 2, 1) == FAILURE)
2521 /* VECTOR requires at least as many elements as MASK
2522 has .TRUE. values. */
2523 have_array_size = gfc_array_size (array, &array_size) == SUCCESS;
2524 have_vector_size = gfc_array_size (vector, &vector_size) == SUCCESS;
2526 if (have_vector_size
2527 && (mask->expr_type == EXPR_ARRAY
2528 || (mask->expr_type == EXPR_CONSTANT
2529 && have_array_size)))
2531 int mask_true_values = 0;
2533 if (mask->expr_type == EXPR_ARRAY)
2535 gfc_constructor *mask_ctor;
2536 mask_ctor = gfc_constructor_first (mask->value.constructor);
2539 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
2541 mask_true_values = 0;
2545 if (mask_ctor->expr->value.logical)
2548 mask_ctor = gfc_constructor_next (mask_ctor);
2551 else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
2552 mask_true_values = mpz_get_si (array_size);
2554 if (mpz_get_si (vector_size) < mask_true_values)
2556 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2557 "provide at least as many elements as there "
2558 "are .TRUE. values in '%s' (%ld/%d)",
2559 gfc_current_intrinsic_arg[2]->name,
2560 gfc_current_intrinsic, &vector->where,
2561 gfc_current_intrinsic_arg[1]->name,
2562 mpz_get_si (vector_size), mask_true_values);
2567 if (have_array_size)
2568 mpz_clear (array_size);
2569 if (have_vector_size)
2570 mpz_clear (vector_size);
2578 gfc_check_parity (gfc_expr *mask, gfc_expr *dim)
2580 if (type_check (mask, 0, BT_LOGICAL) == FAILURE)
2583 if (array_check (mask, 0) == FAILURE)
2586 if (dim_rank_check (dim, mask, false) == FAILURE)
2594 gfc_check_precision (gfc_expr *x)
2596 if (real_or_complex_check (x, 0) == FAILURE)
2604 gfc_check_present (gfc_expr *a)
2608 if (variable_check (a, 0) == FAILURE)
2611 sym = a->symtree->n.sym;
2612 if (!sym->attr.dummy)
2614 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2615 "dummy variable", gfc_current_intrinsic_arg[0]->name,
2616 gfc_current_intrinsic, &a->where);
2620 if (!sym->attr.optional)
2622 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2623 "an OPTIONAL dummy variable",
2624 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2629 /* 13.14.82 PRESENT(A)
2631 Argument. A shall be the name of an optional dummy argument that is
2632 accessible in the subprogram in which the PRESENT function reference
2636 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2637 && a->ref->u.ar.type == AR_FULL))
2639 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2640 "subobject of '%s'", gfc_current_intrinsic_arg[0]->name,
2641 gfc_current_intrinsic, &a->where, sym->name);
2650 gfc_check_radix (gfc_expr *x)
2652 if (int_or_real_check (x, 0) == FAILURE)
2660 gfc_check_range (gfc_expr *x)
2662 if (numeric_check (x, 0) == FAILURE)
2669 /* real, float, sngl. */
2671 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2673 if (numeric_check (a, 0) == FAILURE)
2676 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2684 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2686 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2688 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2691 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2693 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2701 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2703 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2705 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2708 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2710 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2716 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2719 if (scalar_check (status, 2) == FAILURE)
2727 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2729 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2732 if (scalar_check (x, 0) == FAILURE)
2735 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2738 if (scalar_check (y, 1) == FAILURE)
2746 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2747 gfc_expr *pad, gfc_expr *order)
2753 if (array_check (source, 0) == FAILURE)
2756 if (rank_check (shape, 1, 1) == FAILURE)
2759 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2762 if (gfc_array_size (shape, &size) != SUCCESS)
2764 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2765 "array of constant size", &shape->where);
2769 shape_size = mpz_get_ui (size);
2772 if (shape_size <= 0)
2774 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
2775 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2779 else if (shape_size > GFC_MAX_DIMENSIONS)
2781 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2782 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2785 else if (shape->expr_type == EXPR_ARRAY)
2789 for (i = 0; i < shape_size; ++i)
2791 e = gfc_constructor_lookup_expr (shape->value.constructor, i);
2792 if (e->expr_type != EXPR_CONSTANT)
2795 gfc_extract_int (e, &extent);
2798 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2799 "negative element (%d)",
2800 gfc_current_intrinsic_arg[1]->name,
2801 gfc_current_intrinsic, &e->where, extent);
2809 if (same_type_check (source, 0, pad, 2) == FAILURE)
2812 if (array_check (pad, 2) == FAILURE)
2818 if (array_check (order, 3) == FAILURE)
2821 if (type_check (order, 3, BT_INTEGER) == FAILURE)
2824 if (order->expr_type == EXPR_ARRAY)
2826 int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
2829 for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
2832 gfc_array_size (order, &size);
2833 order_size = mpz_get_ui (size);
2836 if (order_size != shape_size)
2838 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2839 "has wrong number of elements (%d/%d)",
2840 gfc_current_intrinsic_arg[3]->name,
2841 gfc_current_intrinsic, &order->where,
2842 order_size, shape_size);
2846 for (i = 1; i <= order_size; ++i)
2848 e = gfc_constructor_lookup_expr (order->value.constructor, i-1);
2849 if (e->expr_type != EXPR_CONSTANT)
2852 gfc_extract_int (e, &dim);
2854 if (dim < 1 || dim > order_size)
2856 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2857 "has out-of-range dimension (%d)",
2858 gfc_current_intrinsic_arg[3]->name,
2859 gfc_current_intrinsic, &e->where, dim);
2863 if (perm[dim-1] != 0)
2865 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2866 "invalid permutation of dimensions (dimension "
2868 gfc_current_intrinsic_arg[3]->name,
2869 gfc_current_intrinsic, &e->where, dim);
2878 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2879 && gfc_is_constant_expr (shape)
2880 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2881 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2883 /* Check the match in size between source and destination. */
2884 if (gfc_array_size (source, &nelems) == SUCCESS)
2890 mpz_init_set_ui (size, 1);
2891 for (c = gfc_constructor_first (shape->value.constructor);
2892 c; c = gfc_constructor_next (c))
2893 mpz_mul (size, size, c->expr->value.integer);
2895 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2901 gfc_error ("Without padding, there are not enough elements "
2902 "in the intrinsic RESHAPE source at %L to match "
2903 "the shape", &source->where);
2914 gfc_check_same_type_as (gfc_expr *a, gfc_expr *b)
2917 if (a->ts.type != BT_DERIVED && a->ts.type != BT_CLASS)
2919 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2920 "must be of a derived type",
2921 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2926 if (!gfc_type_is_extensible (a->ts.u.derived))
2928 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2929 "must be of an extensible type",
2930 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2935 if (b->ts.type != BT_DERIVED && b->ts.type != BT_CLASS)
2937 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2938 "must be of a derived type",
2939 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2944 if (!gfc_type_is_extensible (b->ts.u.derived))
2946 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2947 "must be of an extensible type",
2948 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2958 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2960 if (type_check (x, 0, BT_REAL) == FAILURE)
2963 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2971 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
2973 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2976 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2979 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2982 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
2984 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2985 "with KIND argument at %L",
2986 gfc_current_intrinsic, &kind->where) == FAILURE)
2989 if (same_type_check (x, 0, y, 1) == FAILURE)
2997 gfc_check_secnds (gfc_expr *r)
2999 if (type_check (r, 0, BT_REAL) == FAILURE)
3002 if (kind_value_check (r, 0, 4) == FAILURE)
3005 if (scalar_check (r, 0) == FAILURE)
3013 gfc_check_selected_char_kind (gfc_expr *name)
3015 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3018 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3021 if (scalar_check (name, 0) == FAILURE)
3029 gfc_check_selected_int_kind (gfc_expr *r)
3031 if (type_check (r, 0, BT_INTEGER) == FAILURE)
3034 if (scalar_check (r, 0) == FAILURE)
3042 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r, gfc_expr *radix)
3044 if (p == NULL && r == NULL
3045 && gfc_notify_std (GFC_STD_F2008, "Fortran 2008: SELECTED_REAL_KIND with"
3046 " neither 'P' nor 'R' argument at %L",
3047 gfc_current_intrinsic_where) == FAILURE)
3052 if (type_check (p, 0, BT_INTEGER) == FAILURE)
3055 if (scalar_check (p, 0) == FAILURE)
3061 if (type_check (r, 1, BT_INTEGER) == FAILURE)
3064 if (scalar_check (r, 1) == FAILURE)
3070 if (type_check (radix, 1, BT_INTEGER) == FAILURE)
3073 if (scalar_check (radix, 1) == FAILURE)
3076 if (gfc_notify_std (GFC_STD_F2008, "Fortran 2008: '%s' intrinsic with "
3077 "RADIX argument at %L", gfc_current_intrinsic,
3078 &radix->where) == FAILURE)
3087 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
3089 if (type_check (x, 0, BT_REAL) == FAILURE)
3092 if (type_check (i, 1, BT_INTEGER) == FAILURE)
3100 gfc_check_shape (gfc_expr *source)
3104 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
3107 ar = gfc_find_array_ref (source);
3109 if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
3111 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
3112 "an assumed size array", &source->where);
3121 gfc_check_sign (gfc_expr *a, gfc_expr *b)
3123 if (int_or_real_check (a, 0) == FAILURE)
3126 if (same_type_check (a, 0, b, 1) == FAILURE)
3134 gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3136 if (array_check (array, 0) == FAILURE)
3139 if (dim_check (dim, 1, true) == FAILURE)
3142 if (dim_rank_check (dim, array, 0) == FAILURE)
3145 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3147 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3148 "with KIND argument at %L",
3149 gfc_current_intrinsic, &kind->where) == FAILURE)
3158 gfc_check_sizeof (gfc_expr *arg ATTRIBUTE_UNUSED)
3165 gfc_check_c_sizeof (gfc_expr *arg)
3167 if (verify_c_interop (&arg->ts) != SUCCESS)
3169 gfc_error ("'%s' argument of '%s' intrinsic at %L must be be an "
3170 "interoperable data entity",
3171 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3180 gfc_check_sleep_sub (gfc_expr *seconds)
3182 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3185 if (scalar_check (seconds, 0) == FAILURE)
3192 gfc_check_sngl (gfc_expr *a)
3194 if (type_check (a, 0, BT_REAL) == FAILURE)
3197 if ((a->ts.kind != gfc_default_double_kind)
3198 && gfc_notify_std (GFC_STD_GNU, "GNU extension: non double precision"
3199 "REAL argument to %s intrinsic at %L",
3200 gfc_current_intrinsic, &a->where) == FAILURE)
3207 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
3209 if (source->rank >= GFC_MAX_DIMENSIONS)
3211 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
3212 "than rank %d", gfc_current_intrinsic_arg[0]->name,
3213 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
3221 if (dim_check (dim, 1, false) == FAILURE)
3224 /* dim_rank_check() does not apply here. */
3226 && dim->expr_type == EXPR_CONSTANT
3227 && (mpz_cmp_ui (dim->value.integer, 1) < 0
3228 || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0))
3230 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
3231 "dimension index", gfc_current_intrinsic_arg[1]->name,
3232 gfc_current_intrinsic, &dim->where);
3236 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
3239 if (scalar_check (ncopies, 2) == FAILURE)
3246 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3250 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
3252 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3255 if (scalar_check (unit, 0) == FAILURE)
3258 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
3260 if (kind_value_check (c, 1, gfc_default_character_kind) == FAILURE)
3266 if (type_check (status, 2, BT_INTEGER) == FAILURE
3267 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
3268 || scalar_check (status, 2) == FAILURE)
3276 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
3278 return gfc_check_fgetputc_sub (unit, c, NULL);
3283 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
3285 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
3287 if (kind_value_check (c, 0, gfc_default_character_kind) == FAILURE)
3293 if (type_check (status, 1, BT_INTEGER) == FAILURE
3294 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
3295 || scalar_check (status, 1) == FAILURE)
3303 gfc_check_fgetput (gfc_expr *c)
3305 return gfc_check_fgetput_sub (c, NULL);
3310 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
3312 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3315 if (scalar_check (unit, 0) == FAILURE)
3318 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3321 if (scalar_check (offset, 1) == FAILURE)
3324 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
3327 if (scalar_check (whence, 2) == FAILURE)
3333 if (type_check (status, 3, BT_INTEGER) == FAILURE)
3336 if (kind_value_check (status, 3, 4) == FAILURE)
3339 if (scalar_check (status, 3) == FAILURE)
3348 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
3350 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3353 if (scalar_check (unit, 0) == FAILURE)
3356 if (type_check (array, 1, BT_INTEGER) == FAILURE
3357 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
3360 if (array_check (array, 1) == FAILURE)
3368 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
3370 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3373 if (scalar_check (unit, 0) == FAILURE)
3376 if (type_check (array, 1, BT_INTEGER) == FAILURE
3377 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3380 if (array_check (array, 1) == FAILURE)
3386 if (type_check (status, 2, BT_INTEGER) == FAILURE
3387 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3390 if (scalar_check (status, 2) == FAILURE)
3398 gfc_check_ftell (gfc_expr *unit)
3400 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3403 if (scalar_check (unit, 0) == FAILURE)
3411 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
3413 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3416 if (scalar_check (unit, 0) == FAILURE)
3419 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3422 if (scalar_check (offset, 1) == FAILURE)
3430 gfc_check_stat (gfc_expr *name, gfc_expr *array)
3432 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3434 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3437 if (type_check (array, 1, BT_INTEGER) == FAILURE
3438 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3441 if (array_check (array, 1) == FAILURE)
3449 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
3451 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3453 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3456 if (type_check (array, 1, BT_INTEGER) == FAILURE
3457 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3460 if (array_check (array, 1) == FAILURE)
3466 if (type_check (status, 2, BT_INTEGER) == FAILURE
3467 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3470 if (scalar_check (status, 2) == FAILURE)
3478 gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub)
3480 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3482 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3486 if (coarray_check (coarray, 0) == FAILURE)
3491 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3492 gfc_current_intrinsic_arg[1]->name, &sub->where);
3501 gfc_check_this_image (gfc_expr *coarray, gfc_expr *dim)
3503 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3505 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3509 if (dim != NULL && coarray == NULL)
3511 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3512 "intrinsic at %L", &dim->where);
3516 if (coarray == NULL)
3519 if (coarray_check (coarray, 0) == FAILURE)
3524 if (dim_check (dim, 1, false) == FAILURE)
3527 if (dim_corank_check (dim, coarray) == FAILURE)
3536 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
3537 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
3539 if (mold->ts.type == BT_HOLLERITH)
3541 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3542 &mold->where, gfc_basic_typename (BT_HOLLERITH));
3548 if (type_check (size, 2, BT_INTEGER) == FAILURE)
3551 if (scalar_check (size, 2) == FAILURE)
3554 if (nonoptional_check (size, 2) == FAILURE)
3563 gfc_check_transpose (gfc_expr *matrix)
3565 if (rank_check (matrix, 0, 2) == FAILURE)
3573 gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3575 if (array_check (array, 0) == FAILURE)
3578 if (dim_check (dim, 1, false) == FAILURE)
3581 if (dim_rank_check (dim, array, 0) == FAILURE)
3584 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3586 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3587 "with KIND argument at %L",
3588 gfc_current_intrinsic, &kind->where) == FAILURE)
3596 gfc_check_ucobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
3598 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3600 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3604 if (coarray_check (coarray, 0) == FAILURE)
3609 if (dim_check (dim, 1, false) == FAILURE)
3612 if (dim_corank_check (dim, coarray) == FAILURE)
3616 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3624 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
3628 if (rank_check (vector, 0, 1) == FAILURE)
3631 if (array_check (mask, 1) == FAILURE)
3634 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
3637 if (same_type_check (vector, 0, field, 2) == FAILURE)
3640 if (mask->expr_type == EXPR_ARRAY
3641 && gfc_array_size (vector, &vector_size) == SUCCESS)
3643 int mask_true_count = 0;
3644 gfc_constructor *mask_ctor;
3645 mask_ctor = gfc_constructor_first (mask->value.constructor);
3648 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
3650 mask_true_count = 0;
3654 if (mask_ctor->expr->value.logical)
3657 mask_ctor = gfc_constructor_next (mask_ctor);
3660 if (mpz_get_si (vector_size) < mask_true_count)
3662 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
3663 "provide at least as many elements as there "
3664 "are .TRUE. values in '%s' (%ld/%d)",
3665 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3666 &vector->where, gfc_current_intrinsic_arg[1]->name,
3667 mpz_get_si (vector_size), mask_true_count);
3671 mpz_clear (vector_size);
3674 if (mask->rank != field->rank && field->rank != 0)
3676 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
3677 "the same rank as '%s' or be a scalar",
3678 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
3679 &field->where, gfc_current_intrinsic_arg[1]->name);
3683 if (mask->rank == field->rank)
3686 for (i = 0; i < field->rank; i++)
3687 if (! identical_dimen_shape (mask, i, field, i))
3689 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
3690 "must have identical shape.",
3691 gfc_current_intrinsic_arg[2]->name,
3692 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3702 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
3704 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3707 if (same_type_check (x, 0, y, 1) == FAILURE)
3710 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
3713 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
3715 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3716 "with KIND argument at %L",
3717 gfc_current_intrinsic, &kind->where) == FAILURE)
3725 gfc_check_trim (gfc_expr *x)
3727 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3730 if (scalar_check (x, 0) == FAILURE)
3738 gfc_check_ttynam (gfc_expr *unit)
3740 if (scalar_check (unit, 0) == FAILURE)
3743 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3750 /* Common check function for the half a dozen intrinsics that have a
3751 single real argument. */
3754 gfc_check_x (gfc_expr *x)
3756 if (type_check (x, 0, BT_REAL) == FAILURE)
3763 /************* Check functions for intrinsic subroutines *************/
3766 gfc_check_cpu_time (gfc_expr *time)
3768 if (scalar_check (time, 0) == FAILURE)
3771 if (type_check (time, 0, BT_REAL) == FAILURE)
3774 if (variable_check (time, 0) == FAILURE)
3782 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
3783 gfc_expr *zone, gfc_expr *values)
3787 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3789 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
3791 if (scalar_check (date, 0) == FAILURE)
3793 if (variable_check (date, 0) == FAILURE)
3799 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
3801 if (kind_value_check (time, 1, gfc_default_character_kind) == FAILURE)
3803 if (scalar_check (time, 1) == FAILURE)
3805 if (variable_check (time, 1) == FAILURE)
3811 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
3813 if (kind_value_check (zone, 2, gfc_default_character_kind) == FAILURE)
3815 if (scalar_check (zone, 2) == FAILURE)
3817 if (variable_check (zone, 2) == FAILURE)
3823 if (type_check (values, 3, BT_INTEGER) == FAILURE)
3825 if (array_check (values, 3) == FAILURE)
3827 if (rank_check (values, 3, 1) == FAILURE)
3829 if (variable_check (values, 3) == FAILURE)
3838 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
3839 gfc_expr *to, gfc_expr *topos)
3841 if (type_check (from, 0, BT_INTEGER) == FAILURE)
3844 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
3847 if (type_check (len, 2, BT_INTEGER) == FAILURE)
3850 if (same_type_check (from, 0, to, 3) == FAILURE)
3853 if (variable_check (to, 3) == FAILURE)
3856 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
3859 if (nonnegative_check ("frompos", frompos) == FAILURE)
3862 if (nonnegative_check ("topos", topos) == FAILURE)
3865 if (nonnegative_check ("len", len) == FAILURE)
3868 if (less_than_bitsize2 ("from", from, "frompos", frompos, "len", len)
3872 if (less_than_bitsize2 ("to", to, "topos", topos, "len", len) == FAILURE)
3880 gfc_check_random_number (gfc_expr *harvest)
3882 if (type_check (harvest, 0, BT_REAL) == FAILURE)
3885 if (variable_check (harvest, 0) == FAILURE)
3893 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
3895 unsigned int nargs = 0, kiss_size;
3896 locus *where = NULL;
3897 mpz_t put_size, get_size;
3898 bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
3900 have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
3902 /* Keep the number of bytes in sync with kiss_size in
3903 libgfortran/intrinsics/random.c. */
3904 kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind;
3908 if (size->expr_type != EXPR_VARIABLE
3909 || !size->symtree->n.sym->attr.optional)
3912 if (scalar_check (size, 0) == FAILURE)
3915 if (type_check (size, 0, BT_INTEGER) == FAILURE)
3918 if (variable_check (size, 0) == FAILURE)
3921 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
3927 if (put->expr_type != EXPR_VARIABLE
3928 || !put->symtree->n.sym->attr.optional)
3931 where = &put->where;
3934 if (array_check (put, 1) == FAILURE)
3937 if (rank_check (put, 1, 1) == FAILURE)
3940 if (type_check (put, 1, BT_INTEGER) == FAILURE)
3943 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
3946 if (gfc_array_size (put, &put_size) == SUCCESS
3947 && mpz_get_ui (put_size) < kiss_size)
3948 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3949 "too small (%i/%i)",
3950 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3951 where, (int) mpz_get_ui (put_size), kiss_size);
3956 if (get->expr_type != EXPR_VARIABLE
3957 || !get->symtree->n.sym->attr.optional)
3960 where = &get->where;
3963 if (array_check (get, 2) == FAILURE)
3966 if (rank_check (get, 2, 1) == FAILURE)
3969 if (type_check (get, 2, BT_INTEGER) == FAILURE)
3972 if (variable_check (get, 2) == FAILURE)
3975 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
3978 if (gfc_array_size (get, &get_size) == SUCCESS
3979 && mpz_get_ui (get_size) < kiss_size)
3980 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3981 "too small (%i/%i)",
3982 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
3983 where, (int) mpz_get_ui (get_size), kiss_size);
3986 /* RANDOM_SEED may not have more than one non-optional argument. */
3988 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
3995 gfc_check_second_sub (gfc_expr *time)
3997 if (scalar_check (time, 0) == FAILURE)
4000 if (type_check (time, 0, BT_REAL) == FAILURE)
4003 if (kind_value_check(time, 0, 4) == FAILURE)
4010 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
4011 count, count_rate, and count_max are all optional arguments */
4014 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
4015 gfc_expr *count_max)
4019 if (scalar_check (count, 0) == FAILURE)
4022 if (type_check (count, 0, BT_INTEGER) == FAILURE)
4025 if (variable_check (count, 0) == FAILURE)
4029 if (count_rate != NULL)
4031 if (scalar_check (count_rate, 1) == FAILURE)
4034 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
4037 if (variable_check (count_rate, 1) == FAILURE)
4041 && same_type_check (count, 0, count_rate, 1) == FAILURE)
4046 if (count_max != NULL)
4048 if (scalar_check (count_max, 2) == FAILURE)
4051 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
4054 if (variable_check (count_max, 2) == FAILURE)
4058 && same_type_check (count, 0, count_max, 2) == FAILURE)
4061 if (count_rate != NULL
4062 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
4071 gfc_check_irand (gfc_expr *x)
4076 if (scalar_check (x, 0) == FAILURE)
4079 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4082 if (kind_value_check(x, 0, 4) == FAILURE)
4090 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
4092 if (scalar_check (seconds, 0) == FAILURE)
4094 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
4097 if (int_or_proc_check (handler, 1) == FAILURE)
4099 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4105 if (scalar_check (status, 2) == FAILURE)
4107 if (type_check (status, 2, BT_INTEGER) == FAILURE)
4109 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
4117 gfc_check_rand (gfc_expr *x)
4122 if (scalar_check (x, 0) == FAILURE)
4125 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4128 if (kind_value_check(x, 0, 4) == FAILURE)
4136 gfc_check_srand (gfc_expr *x)
4138 if (scalar_check (x, 0) == FAILURE)
4141 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4144 if (kind_value_check(x, 0, 4) == FAILURE)
4152 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
4154 if (scalar_check (time, 0) == FAILURE)
4156 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4159 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
4161 if (kind_value_check (result, 1, gfc_default_character_kind) == FAILURE)
4169 gfc_check_dtime_etime (gfc_expr *x)
4171 if (array_check (x, 0) == FAILURE)
4174 if (rank_check (x, 0, 1) == FAILURE)
4177 if (variable_check (x, 0) == FAILURE)
4180 if (type_check (x, 0, BT_REAL) == FAILURE)
4183 if (kind_value_check(x, 0, 4) == FAILURE)
4191 gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
4193 if (array_check (values, 0) == FAILURE)
4196 if (rank_check (values, 0, 1) == FAILURE)
4199 if (variable_check (values, 0) == FAILURE)
4202 if (type_check (values, 0, BT_REAL) == FAILURE)
4205 if (kind_value_check(values, 0, 4) == FAILURE)
4208 if (scalar_check (time, 1) == FAILURE)
4211 if (type_check (time, 1, BT_REAL) == FAILURE)
4214 if (kind_value_check(time, 1, 4) == FAILURE)
4222 gfc_check_fdate_sub (gfc_expr *date)
4224 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
4226 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
4234 gfc_check_gerror (gfc_expr *msg)
4236 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4238 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4246 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
4248 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
4250 if (kind_value_check (cwd, 0, gfc_default_character_kind) == FAILURE)
4256 if (scalar_check (status, 1) == FAILURE)
4259 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4267 gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
4269 if (type_check (pos, 0, BT_INTEGER) == FAILURE)
4272 if (pos->ts.kind > gfc_default_integer_kind)
4274 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4275 "not wider than the default kind (%d)",
4276 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4277 &pos->where, gfc_default_integer_kind);
4281 if (type_check (value, 1, BT_CHARACTER) == FAILURE)
4283 if (kind_value_check (value, 1, gfc_default_character_kind) == FAILURE)
4291 gfc_check_getlog (gfc_expr *msg)
4293 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4295 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4303 gfc_check_exit (gfc_expr *status)
4308 if (type_check (status, 0, BT_INTEGER) == FAILURE)
4311 if (scalar_check (status, 0) == FAILURE)
4319 gfc_check_flush (gfc_expr *unit)
4324 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4327 if (scalar_check (unit, 0) == FAILURE)
4335 gfc_check_free (gfc_expr *i)
4337 if (type_check (i, 0, BT_INTEGER) == FAILURE)
4340 if (scalar_check (i, 0) == FAILURE)
4348 gfc_check_hostnm (gfc_expr *name)
4350 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4352 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4360 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
4362 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4364 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4370 if (scalar_check (status, 1) == FAILURE)
4373 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4381 gfc_check_itime_idate (gfc_expr *values)
4383 if (array_check (values, 0) == FAILURE)
4386 if (rank_check (values, 0, 1) == FAILURE)
4389 if (variable_check (values, 0) == FAILURE)
4392 if (type_check (values, 0, BT_INTEGER) == FAILURE)
4395 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
4403 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
4405 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4408 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
4411 if (scalar_check (time, 0) == FAILURE)
4414 if (array_check (values, 1) == FAILURE)
4417 if (rank_check (values, 1, 1) == FAILURE)
4420 if (variable_check (values, 1) == FAILURE)
4423 if (type_check (values, 1, BT_INTEGER) == FAILURE)
4426 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
4434 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
4436 if (scalar_check (unit, 0) == FAILURE)
4439 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4442 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
4444 if (kind_value_check (name, 1, gfc_default_character_kind) == FAILURE)
4452 gfc_check_isatty (gfc_expr *unit)
4457 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4460 if (scalar_check (unit, 0) == FAILURE)
4468 gfc_check_isnan (gfc_expr *x)
4470 if (type_check (x, 0, BT_REAL) == FAILURE)
4478 gfc_check_perror (gfc_expr *string)
4480 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
4482 if (kind_value_check (string, 0, gfc_default_character_kind) == FAILURE)
4490 gfc_check_umask (gfc_expr *mask)
4492 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4495 if (scalar_check (mask, 0) == FAILURE)
4503 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
4505 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4508 if (scalar_check (mask, 0) == FAILURE)
4514 if (scalar_check (old, 1) == FAILURE)
4517 if (type_check (old, 1, BT_INTEGER) == FAILURE)
4525 gfc_check_unlink (gfc_expr *name)
4527 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4529 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4537 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
4539 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4541 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4547 if (scalar_check (status, 1) == FAILURE)
4550 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4558 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
4560 if (scalar_check (number, 0) == FAILURE)
4562 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4565 if (int_or_proc_check (handler, 1) == FAILURE)
4567 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4575 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
4577 if (scalar_check (number, 0) == FAILURE)
4579 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4582 if (int_or_proc_check (handler, 1) == FAILURE)
4584 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4590 if (type_check (status, 2, BT_INTEGER) == FAILURE)
4592 if (scalar_check (status, 2) == FAILURE)
4600 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
4602 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
4604 if (kind_value_check (cmd, 0, gfc_default_character_kind) == FAILURE)
4607 if (scalar_check (status, 1) == FAILURE)
4610 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4613 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
4620 /* This is used for the GNU intrinsics AND, OR and XOR. */
4622 gfc_check_and (gfc_expr *i, gfc_expr *j)
4624 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
4626 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4627 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
4628 gfc_current_intrinsic, &i->where);
4632 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
4634 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4635 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
4636 gfc_current_intrinsic, &j->where);
4640 if (i->ts.type != j->ts.type)
4642 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
4643 "have the same type", gfc_current_intrinsic_arg[0]->name,
4644 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4649 if (scalar_check (i, 0) == FAILURE)
4652 if (scalar_check (j, 1) == FAILURE)
4660 gfc_check_storage_size (gfc_expr *a ATTRIBUTE_UNUSED, gfc_expr *kind)
4665 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
4668 if (scalar_check (kind, 1) == FAILURE)
4671 if (kind->expr_type != EXPR_CONSTANT)
4673 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
4674 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,