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);
2357 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
2359 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
2362 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
2365 if (tsource->ts.type == BT_CHARACTER)
2366 return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
2373 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
2375 if (variable_check (from, 0) == FAILURE)
2377 if (allocatable_check (from, 0) == FAILURE)
2380 if (variable_check (to, 1) == FAILURE)
2382 if (allocatable_check (to, 1) == FAILURE)
2385 if (same_type_check (to, 1, from, 0) == FAILURE)
2388 if (to->rank != from->rank)
2390 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2391 "have the same rank %d/%d", gfc_current_intrinsic_arg[0]->name,
2392 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2393 &to->where, from->rank, to->rank);
2397 if (to->ts.kind != from->ts.kind)
2399 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2400 "be of the same kind %d/%d",
2401 gfc_current_intrinsic_arg[0]->name,
2402 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2403 &to->where, from->ts.kind, to->ts.kind);
2412 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
2414 if (type_check (x, 0, BT_REAL) == FAILURE)
2417 if (type_check (s, 1, BT_REAL) == FAILURE)
2425 gfc_check_new_line (gfc_expr *a)
2427 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2435 gfc_check_norm2 (gfc_expr *array, gfc_expr *dim)
2437 if (type_check (array, 0, BT_REAL) == FAILURE)
2440 if (array_check (array, 0) == FAILURE)
2443 if (dim_rank_check (dim, array, false) == FAILURE)
2450 gfc_check_null (gfc_expr *mold)
2452 symbol_attribute attr;
2457 if (variable_check (mold, 0) == FAILURE)
2460 attr = gfc_variable_attr (mold, NULL);
2462 if (!attr.pointer && !attr.proc_pointer)
2464 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
2465 gfc_current_intrinsic_arg[0]->name,
2466 gfc_current_intrinsic, &mold->where);
2475 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
2477 if (array_check (array, 0) == FAILURE)
2480 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2483 if (gfc_check_conformance (array, mask,
2484 "arguments '%s' and '%s' for intrinsic '%s'",
2485 gfc_current_intrinsic_arg[0]->name,
2486 gfc_current_intrinsic_arg[1]->name,
2487 gfc_current_intrinsic) == FAILURE)
2492 mpz_t array_size, vector_size;
2493 bool have_array_size, have_vector_size;
2495 if (same_type_check (array, 0, vector, 2) == FAILURE)
2498 if (rank_check (vector, 2, 1) == FAILURE)
2501 /* VECTOR requires at least as many elements as MASK
2502 has .TRUE. values. */
2503 have_array_size = gfc_array_size (array, &array_size) == SUCCESS;
2504 have_vector_size = gfc_array_size (vector, &vector_size) == SUCCESS;
2506 if (have_vector_size
2507 && (mask->expr_type == EXPR_ARRAY
2508 || (mask->expr_type == EXPR_CONSTANT
2509 && have_array_size)))
2511 int mask_true_values = 0;
2513 if (mask->expr_type == EXPR_ARRAY)
2515 gfc_constructor *mask_ctor;
2516 mask_ctor = gfc_constructor_first (mask->value.constructor);
2519 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
2521 mask_true_values = 0;
2525 if (mask_ctor->expr->value.logical)
2528 mask_ctor = gfc_constructor_next (mask_ctor);
2531 else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
2532 mask_true_values = mpz_get_si (array_size);
2534 if (mpz_get_si (vector_size) < mask_true_values)
2536 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2537 "provide at least as many elements as there "
2538 "are .TRUE. values in '%s' (%ld/%d)",
2539 gfc_current_intrinsic_arg[2]->name,
2540 gfc_current_intrinsic, &vector->where,
2541 gfc_current_intrinsic_arg[1]->name,
2542 mpz_get_si (vector_size), mask_true_values);
2547 if (have_array_size)
2548 mpz_clear (array_size);
2549 if (have_vector_size)
2550 mpz_clear (vector_size);
2558 gfc_check_parity (gfc_expr *mask, gfc_expr *dim)
2560 if (type_check (mask, 0, BT_LOGICAL) == FAILURE)
2563 if (array_check (mask, 0) == FAILURE)
2566 if (dim_rank_check (dim, mask, false) == FAILURE)
2574 gfc_check_precision (gfc_expr *x)
2576 if (real_or_complex_check (x, 0) == FAILURE)
2584 gfc_check_present (gfc_expr *a)
2588 if (variable_check (a, 0) == FAILURE)
2591 sym = a->symtree->n.sym;
2592 if (!sym->attr.dummy)
2594 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2595 "dummy variable", gfc_current_intrinsic_arg[0]->name,
2596 gfc_current_intrinsic, &a->where);
2600 if (!sym->attr.optional)
2602 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2603 "an OPTIONAL dummy variable",
2604 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2609 /* 13.14.82 PRESENT(A)
2611 Argument. A shall be the name of an optional dummy argument that is
2612 accessible in the subprogram in which the PRESENT function reference
2616 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2617 && a->ref->u.ar.type == AR_FULL))
2619 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2620 "subobject of '%s'", gfc_current_intrinsic_arg[0]->name,
2621 gfc_current_intrinsic, &a->where, sym->name);
2630 gfc_check_radix (gfc_expr *x)
2632 if (int_or_real_check (x, 0) == FAILURE)
2640 gfc_check_range (gfc_expr *x)
2642 if (numeric_check (x, 0) == FAILURE)
2649 /* real, float, sngl. */
2651 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2653 if (numeric_check (a, 0) == FAILURE)
2656 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2664 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2666 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2668 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2671 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2673 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2681 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2683 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2685 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2688 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2690 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2696 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2699 if (scalar_check (status, 2) == FAILURE)
2707 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
2709 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2712 if (scalar_check (x, 0) == FAILURE)
2715 if (type_check (y, 0, BT_INTEGER) == FAILURE)
2718 if (scalar_check (y, 1) == FAILURE)
2726 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
2727 gfc_expr *pad, gfc_expr *order)
2733 if (array_check (source, 0) == FAILURE)
2736 if (rank_check (shape, 1, 1) == FAILURE)
2739 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
2742 if (gfc_array_size (shape, &size) != SUCCESS)
2744 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2745 "array of constant size", &shape->where);
2749 shape_size = mpz_get_ui (size);
2752 if (shape_size <= 0)
2754 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
2755 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2759 else if (shape_size > GFC_MAX_DIMENSIONS)
2761 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2762 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
2765 else if (shape->expr_type == EXPR_ARRAY)
2769 for (i = 0; i < shape_size; ++i)
2771 e = gfc_constructor_lookup_expr (shape->value.constructor, i);
2772 if (e->expr_type != EXPR_CONSTANT)
2775 gfc_extract_int (e, &extent);
2778 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2779 "negative element (%d)",
2780 gfc_current_intrinsic_arg[1]->name,
2781 gfc_current_intrinsic, &e->where, extent);
2789 if (same_type_check (source, 0, pad, 2) == FAILURE)
2792 if (array_check (pad, 2) == FAILURE)
2798 if (array_check (order, 3) == FAILURE)
2801 if (type_check (order, 3, BT_INTEGER) == FAILURE)
2804 if (order->expr_type == EXPR_ARRAY)
2806 int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
2809 for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
2812 gfc_array_size (order, &size);
2813 order_size = mpz_get_ui (size);
2816 if (order_size != shape_size)
2818 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2819 "has wrong number of elements (%d/%d)",
2820 gfc_current_intrinsic_arg[3]->name,
2821 gfc_current_intrinsic, &order->where,
2822 order_size, shape_size);
2826 for (i = 1; i <= order_size; ++i)
2828 e = gfc_constructor_lookup_expr (order->value.constructor, i-1);
2829 if (e->expr_type != EXPR_CONSTANT)
2832 gfc_extract_int (e, &dim);
2834 if (dim < 1 || dim > order_size)
2836 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2837 "has out-of-range dimension (%d)",
2838 gfc_current_intrinsic_arg[3]->name,
2839 gfc_current_intrinsic, &e->where, dim);
2843 if (perm[dim-1] != 0)
2845 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2846 "invalid permutation of dimensions (dimension "
2848 gfc_current_intrinsic_arg[3]->name,
2849 gfc_current_intrinsic, &e->where, dim);
2858 if (pad == NULL && shape->expr_type == EXPR_ARRAY
2859 && gfc_is_constant_expr (shape)
2860 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
2861 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
2863 /* Check the match in size between source and destination. */
2864 if (gfc_array_size (source, &nelems) == SUCCESS)
2870 mpz_init_set_ui (size, 1);
2871 for (c = gfc_constructor_first (shape->value.constructor);
2872 c; c = gfc_constructor_next (c))
2873 mpz_mul (size, size, c->expr->value.integer);
2875 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
2881 gfc_error ("Without padding, there are not enough elements "
2882 "in the intrinsic RESHAPE source at %L to match "
2883 "the shape", &source->where);
2894 gfc_check_same_type_as (gfc_expr *a, gfc_expr *b)
2897 if (a->ts.type != BT_DERIVED && a->ts.type != BT_CLASS)
2899 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2900 "must be of a derived type",
2901 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2906 if (!gfc_type_is_extensible (a->ts.u.derived))
2908 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2909 "must be of an extensible type",
2910 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2915 if (b->ts.type != BT_DERIVED && b->ts.type != BT_CLASS)
2917 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2918 "must be of a derived type",
2919 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2924 if (!gfc_type_is_extensible (b->ts.u.derived))
2926 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2927 "must be of an extensible type",
2928 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2938 gfc_check_scale (gfc_expr *x, gfc_expr *i)
2940 if (type_check (x, 0, BT_REAL) == FAILURE)
2943 if (type_check (i, 1, BT_INTEGER) == FAILURE)
2951 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
2953 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
2956 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
2959 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
2962 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
2964 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2965 "with KIND argument at %L",
2966 gfc_current_intrinsic, &kind->where) == FAILURE)
2969 if (same_type_check (x, 0, y, 1) == FAILURE)
2977 gfc_check_secnds (gfc_expr *r)
2979 if (type_check (r, 0, BT_REAL) == FAILURE)
2982 if (kind_value_check (r, 0, 4) == FAILURE)
2985 if (scalar_check (r, 0) == FAILURE)
2993 gfc_check_selected_char_kind (gfc_expr *name)
2995 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
2998 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3001 if (scalar_check (name, 0) == FAILURE)
3009 gfc_check_selected_int_kind (gfc_expr *r)
3011 if (type_check (r, 0, BT_INTEGER) == FAILURE)
3014 if (scalar_check (r, 0) == FAILURE)
3022 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r, gfc_expr *radix)
3024 if (p == NULL && r == NULL
3025 && gfc_notify_std (GFC_STD_F2008, "Fortran 2008: SELECTED_REAL_KIND with"
3026 " neither 'P' nor 'R' argument at %L",
3027 gfc_current_intrinsic_where) == FAILURE)
3032 if (type_check (p, 0, BT_INTEGER) == FAILURE)
3035 if (scalar_check (p, 0) == FAILURE)
3041 if (type_check (r, 1, BT_INTEGER) == FAILURE)
3044 if (scalar_check (r, 1) == FAILURE)
3050 if (type_check (radix, 1, BT_INTEGER) == FAILURE)
3053 if (scalar_check (radix, 1) == FAILURE)
3056 if (gfc_notify_std (GFC_STD_F2008, "Fortran 2008: '%s' intrinsic with "
3057 "RADIX argument at %L", gfc_current_intrinsic,
3058 &radix->where) == FAILURE)
3067 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
3069 if (type_check (x, 0, BT_REAL) == FAILURE)
3072 if (type_check (i, 1, BT_INTEGER) == FAILURE)
3080 gfc_check_shape (gfc_expr *source)
3084 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
3087 ar = gfc_find_array_ref (source);
3089 if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
3091 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
3092 "an assumed size array", &source->where);
3101 gfc_check_sign (gfc_expr *a, gfc_expr *b)
3103 if (int_or_real_check (a, 0) == FAILURE)
3106 if (same_type_check (a, 0, b, 1) == FAILURE)
3114 gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3116 if (array_check (array, 0) == FAILURE)
3119 if (dim_check (dim, 1, true) == FAILURE)
3122 if (dim_rank_check (dim, array, 0) == FAILURE)
3125 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3127 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3128 "with KIND argument at %L",
3129 gfc_current_intrinsic, &kind->where) == FAILURE)
3138 gfc_check_sizeof (gfc_expr *arg ATTRIBUTE_UNUSED)
3145 gfc_check_c_sizeof (gfc_expr *arg)
3147 if (verify_c_interop (&arg->ts) != SUCCESS)
3149 gfc_error ("'%s' argument of '%s' intrinsic at %L must be be an "
3150 "interoperable data entity",
3151 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3160 gfc_check_sleep_sub (gfc_expr *seconds)
3162 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3165 if (scalar_check (seconds, 0) == FAILURE)
3172 gfc_check_sngl (gfc_expr *a)
3174 if (type_check (a, 0, BT_REAL) == FAILURE)
3177 if ((a->ts.kind != gfc_default_double_kind)
3178 && gfc_notify_std (GFC_STD_GNU, "GNU extension: non double precision"
3179 "REAL argument to %s intrinsic at %L",
3180 gfc_current_intrinsic, &a->where) == FAILURE)
3187 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
3189 if (source->rank >= GFC_MAX_DIMENSIONS)
3191 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
3192 "than rank %d", gfc_current_intrinsic_arg[0]->name,
3193 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
3201 if (dim_check (dim, 1, false) == FAILURE)
3204 /* dim_rank_check() does not apply here. */
3206 && dim->expr_type == EXPR_CONSTANT
3207 && (mpz_cmp_ui (dim->value.integer, 1) < 0
3208 || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0))
3210 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
3211 "dimension index", gfc_current_intrinsic_arg[1]->name,
3212 gfc_current_intrinsic, &dim->where);
3216 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
3219 if (scalar_check (ncopies, 2) == FAILURE)
3226 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3230 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
3232 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3235 if (scalar_check (unit, 0) == FAILURE)
3238 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
3240 if (kind_value_check (c, 1, gfc_default_character_kind) == FAILURE)
3246 if (type_check (status, 2, BT_INTEGER) == FAILURE
3247 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
3248 || scalar_check (status, 2) == FAILURE)
3256 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
3258 return gfc_check_fgetputc_sub (unit, c, NULL);
3263 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
3265 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
3267 if (kind_value_check (c, 0, gfc_default_character_kind) == FAILURE)
3273 if (type_check (status, 1, BT_INTEGER) == FAILURE
3274 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
3275 || scalar_check (status, 1) == FAILURE)
3283 gfc_check_fgetput (gfc_expr *c)
3285 return gfc_check_fgetput_sub (c, NULL);
3290 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
3292 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3295 if (scalar_check (unit, 0) == FAILURE)
3298 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3301 if (scalar_check (offset, 1) == FAILURE)
3304 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
3307 if (scalar_check (whence, 2) == FAILURE)
3313 if (type_check (status, 3, BT_INTEGER) == FAILURE)
3316 if (kind_value_check (status, 3, 4) == FAILURE)
3319 if (scalar_check (status, 3) == FAILURE)
3328 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
3330 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3333 if (scalar_check (unit, 0) == FAILURE)
3336 if (type_check (array, 1, BT_INTEGER) == FAILURE
3337 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
3340 if (array_check (array, 1) == FAILURE)
3348 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
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 (array, 1, gfc_default_integer_kind) == FAILURE)
3360 if (array_check (array, 1) == FAILURE)
3366 if (type_check (status, 2, BT_INTEGER) == FAILURE
3367 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3370 if (scalar_check (status, 2) == FAILURE)
3378 gfc_check_ftell (gfc_expr *unit)
3380 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3383 if (scalar_check (unit, 0) == FAILURE)
3391 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
3393 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3396 if (scalar_check (unit, 0) == FAILURE)
3399 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3402 if (scalar_check (offset, 1) == FAILURE)
3410 gfc_check_stat (gfc_expr *name, gfc_expr *array)
3412 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3414 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3417 if (type_check (array, 1, BT_INTEGER) == FAILURE
3418 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3421 if (array_check (array, 1) == FAILURE)
3429 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
3431 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3433 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3436 if (type_check (array, 1, BT_INTEGER) == FAILURE
3437 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3440 if (array_check (array, 1) == FAILURE)
3446 if (type_check (status, 2, BT_INTEGER) == FAILURE
3447 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3450 if (scalar_check (status, 2) == FAILURE)
3458 gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub)
3460 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3462 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3466 if (coarray_check (coarray, 0) == FAILURE)
3471 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3472 gfc_current_intrinsic_arg[1]->name, &sub->where);
3481 gfc_check_this_image (gfc_expr *coarray, gfc_expr *dim)
3483 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3485 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3489 if (dim != NULL && coarray == NULL)
3491 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3492 "intrinsic at %L", &dim->where);
3496 if (coarray == NULL)
3499 if (coarray_check (coarray, 0) == FAILURE)
3504 if (dim_check (dim, 1, false) == FAILURE)
3507 if (dim_corank_check (dim, coarray) == FAILURE)
3516 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
3517 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
3519 if (mold->ts.type == BT_HOLLERITH)
3521 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3522 &mold->where, gfc_basic_typename (BT_HOLLERITH));
3528 if (type_check (size, 2, BT_INTEGER) == FAILURE)
3531 if (scalar_check (size, 2) == FAILURE)
3534 if (nonoptional_check (size, 2) == FAILURE)
3543 gfc_check_transpose (gfc_expr *matrix)
3545 if (rank_check (matrix, 0, 2) == FAILURE)
3553 gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3555 if (array_check (array, 0) == FAILURE)
3558 if (dim_check (dim, 1, false) == FAILURE)
3561 if (dim_rank_check (dim, array, 0) == FAILURE)
3564 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3566 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3567 "with KIND argument at %L",
3568 gfc_current_intrinsic, &kind->where) == FAILURE)
3576 gfc_check_ucobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
3578 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3580 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3584 if (coarray_check (coarray, 0) == FAILURE)
3589 if (dim_check (dim, 1, false) == FAILURE)
3592 if (dim_corank_check (dim, coarray) == FAILURE)
3596 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3604 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
3608 if (rank_check (vector, 0, 1) == FAILURE)
3611 if (array_check (mask, 1) == FAILURE)
3614 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
3617 if (same_type_check (vector, 0, field, 2) == FAILURE)
3620 if (mask->expr_type == EXPR_ARRAY
3621 && gfc_array_size (vector, &vector_size) == SUCCESS)
3623 int mask_true_count = 0;
3624 gfc_constructor *mask_ctor;
3625 mask_ctor = gfc_constructor_first (mask->value.constructor);
3628 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
3630 mask_true_count = 0;
3634 if (mask_ctor->expr->value.logical)
3637 mask_ctor = gfc_constructor_next (mask_ctor);
3640 if (mpz_get_si (vector_size) < mask_true_count)
3642 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
3643 "provide at least as many elements as there "
3644 "are .TRUE. values in '%s' (%ld/%d)",
3645 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3646 &vector->where, gfc_current_intrinsic_arg[1]->name,
3647 mpz_get_si (vector_size), mask_true_count);
3651 mpz_clear (vector_size);
3654 if (mask->rank != field->rank && field->rank != 0)
3656 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
3657 "the same rank as '%s' or be a scalar",
3658 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
3659 &field->where, gfc_current_intrinsic_arg[1]->name);
3663 if (mask->rank == field->rank)
3666 for (i = 0; i < field->rank; i++)
3667 if (! identical_dimen_shape (mask, i, field, i))
3669 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
3670 "must have identical shape.",
3671 gfc_current_intrinsic_arg[2]->name,
3672 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3682 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
3684 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3687 if (same_type_check (x, 0, y, 1) == FAILURE)
3690 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
3693 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
3695 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3696 "with KIND argument at %L",
3697 gfc_current_intrinsic, &kind->where) == FAILURE)
3705 gfc_check_trim (gfc_expr *x)
3707 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3710 if (scalar_check (x, 0) == FAILURE)
3718 gfc_check_ttynam (gfc_expr *unit)
3720 if (scalar_check (unit, 0) == FAILURE)
3723 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3730 /* Common check function for the half a dozen intrinsics that have a
3731 single real argument. */
3734 gfc_check_x (gfc_expr *x)
3736 if (type_check (x, 0, BT_REAL) == FAILURE)
3743 /************* Check functions for intrinsic subroutines *************/
3746 gfc_check_cpu_time (gfc_expr *time)
3748 if (scalar_check (time, 0) == FAILURE)
3751 if (type_check (time, 0, BT_REAL) == FAILURE)
3754 if (variable_check (time, 0) == FAILURE)
3762 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
3763 gfc_expr *zone, gfc_expr *values)
3767 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
3769 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
3771 if (scalar_check (date, 0) == FAILURE)
3773 if (variable_check (date, 0) == FAILURE)
3779 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
3781 if (kind_value_check (time, 1, gfc_default_character_kind) == FAILURE)
3783 if (scalar_check (time, 1) == FAILURE)
3785 if (variable_check (time, 1) == FAILURE)
3791 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
3793 if (kind_value_check (zone, 2, gfc_default_character_kind) == FAILURE)
3795 if (scalar_check (zone, 2) == FAILURE)
3797 if (variable_check (zone, 2) == FAILURE)
3803 if (type_check (values, 3, BT_INTEGER) == FAILURE)
3805 if (array_check (values, 3) == FAILURE)
3807 if (rank_check (values, 3, 1) == FAILURE)
3809 if (variable_check (values, 3) == FAILURE)
3818 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
3819 gfc_expr *to, gfc_expr *topos)
3821 if (type_check (from, 0, BT_INTEGER) == FAILURE)
3824 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
3827 if (type_check (len, 2, BT_INTEGER) == FAILURE)
3830 if (same_type_check (from, 0, to, 3) == FAILURE)
3833 if (variable_check (to, 3) == FAILURE)
3836 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
3839 if (nonnegative_check ("frompos", frompos) == FAILURE)
3842 if (nonnegative_check ("topos", topos) == FAILURE)
3845 if (nonnegative_check ("len", len) == FAILURE)
3848 if (less_than_bitsize2 ("from", from, "frompos", frompos, "len", len)
3852 if (less_than_bitsize2 ("to", to, "topos", topos, "len", len) == FAILURE)
3860 gfc_check_random_number (gfc_expr *harvest)
3862 if (type_check (harvest, 0, BT_REAL) == FAILURE)
3865 if (variable_check (harvest, 0) == FAILURE)
3873 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
3875 unsigned int nargs = 0, kiss_size;
3876 locus *where = NULL;
3877 mpz_t put_size, get_size;
3878 bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
3880 have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
3882 /* Keep the number of bytes in sync with kiss_size in
3883 libgfortran/intrinsics/random.c. */
3884 kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind;
3888 if (size->expr_type != EXPR_VARIABLE
3889 || !size->symtree->n.sym->attr.optional)
3892 if (scalar_check (size, 0) == FAILURE)
3895 if (type_check (size, 0, BT_INTEGER) == FAILURE)
3898 if (variable_check (size, 0) == FAILURE)
3901 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
3907 if (put->expr_type != EXPR_VARIABLE
3908 || !put->symtree->n.sym->attr.optional)
3911 where = &put->where;
3914 if (array_check (put, 1) == FAILURE)
3917 if (rank_check (put, 1, 1) == FAILURE)
3920 if (type_check (put, 1, BT_INTEGER) == FAILURE)
3923 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
3926 if (gfc_array_size (put, &put_size) == SUCCESS
3927 && mpz_get_ui (put_size) < kiss_size)
3928 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3929 "too small (%i/%i)",
3930 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3931 where, (int) mpz_get_ui (put_size), kiss_size);
3936 if (get->expr_type != EXPR_VARIABLE
3937 || !get->symtree->n.sym->attr.optional)
3940 where = &get->where;
3943 if (array_check (get, 2) == FAILURE)
3946 if (rank_check (get, 2, 1) == FAILURE)
3949 if (type_check (get, 2, BT_INTEGER) == FAILURE)
3952 if (variable_check (get, 2) == FAILURE)
3955 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
3958 if (gfc_array_size (get, &get_size) == SUCCESS
3959 && mpz_get_ui (get_size) < kiss_size)
3960 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3961 "too small (%i/%i)",
3962 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
3963 where, (int) mpz_get_ui (get_size), kiss_size);
3966 /* RANDOM_SEED may not have more than one non-optional argument. */
3968 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
3975 gfc_check_second_sub (gfc_expr *time)
3977 if (scalar_check (time, 0) == FAILURE)
3980 if (type_check (time, 0, BT_REAL) == FAILURE)
3983 if (kind_value_check(time, 0, 4) == FAILURE)
3990 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
3991 count, count_rate, and count_max are all optional arguments */
3994 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
3995 gfc_expr *count_max)
3999 if (scalar_check (count, 0) == FAILURE)
4002 if (type_check (count, 0, BT_INTEGER) == FAILURE)
4005 if (variable_check (count, 0) == FAILURE)
4009 if (count_rate != NULL)
4011 if (scalar_check (count_rate, 1) == FAILURE)
4014 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
4017 if (variable_check (count_rate, 1) == FAILURE)
4021 && same_type_check (count, 0, count_rate, 1) == FAILURE)
4026 if (count_max != NULL)
4028 if (scalar_check (count_max, 2) == FAILURE)
4031 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
4034 if (variable_check (count_max, 2) == FAILURE)
4038 && same_type_check (count, 0, count_max, 2) == FAILURE)
4041 if (count_rate != NULL
4042 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
4051 gfc_check_irand (gfc_expr *x)
4056 if (scalar_check (x, 0) == FAILURE)
4059 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4062 if (kind_value_check(x, 0, 4) == FAILURE)
4070 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
4072 if (scalar_check (seconds, 0) == FAILURE)
4074 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
4077 if (int_or_proc_check (handler, 1) == FAILURE)
4079 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4085 if (scalar_check (status, 2) == FAILURE)
4087 if (type_check (status, 2, BT_INTEGER) == FAILURE)
4089 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
4097 gfc_check_rand (gfc_expr *x)
4102 if (scalar_check (x, 0) == FAILURE)
4105 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4108 if (kind_value_check(x, 0, 4) == FAILURE)
4116 gfc_check_srand (gfc_expr *x)
4118 if (scalar_check (x, 0) == FAILURE)
4121 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4124 if (kind_value_check(x, 0, 4) == FAILURE)
4132 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
4134 if (scalar_check (time, 0) == FAILURE)
4136 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4139 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
4141 if (kind_value_check (result, 1, gfc_default_character_kind) == FAILURE)
4149 gfc_check_dtime_etime (gfc_expr *x)
4151 if (array_check (x, 0) == FAILURE)
4154 if (rank_check (x, 0, 1) == FAILURE)
4157 if (variable_check (x, 0) == FAILURE)
4160 if (type_check (x, 0, BT_REAL) == FAILURE)
4163 if (kind_value_check(x, 0, 4) == FAILURE)
4171 gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
4173 if (array_check (values, 0) == FAILURE)
4176 if (rank_check (values, 0, 1) == FAILURE)
4179 if (variable_check (values, 0) == FAILURE)
4182 if (type_check (values, 0, BT_REAL) == FAILURE)
4185 if (kind_value_check(values, 0, 4) == FAILURE)
4188 if (scalar_check (time, 1) == FAILURE)
4191 if (type_check (time, 1, BT_REAL) == FAILURE)
4194 if (kind_value_check(time, 1, 4) == FAILURE)
4202 gfc_check_fdate_sub (gfc_expr *date)
4204 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
4206 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
4214 gfc_check_gerror (gfc_expr *msg)
4216 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4218 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4226 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
4228 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
4230 if (kind_value_check (cwd, 0, gfc_default_character_kind) == FAILURE)
4236 if (scalar_check (status, 1) == FAILURE)
4239 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4247 gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
4249 if (type_check (pos, 0, BT_INTEGER) == FAILURE)
4252 if (pos->ts.kind > gfc_default_integer_kind)
4254 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4255 "not wider than the default kind (%d)",
4256 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4257 &pos->where, gfc_default_integer_kind);
4261 if (type_check (value, 1, BT_CHARACTER) == FAILURE)
4263 if (kind_value_check (value, 1, gfc_default_character_kind) == FAILURE)
4271 gfc_check_getlog (gfc_expr *msg)
4273 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4275 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4283 gfc_check_exit (gfc_expr *status)
4288 if (type_check (status, 0, BT_INTEGER) == FAILURE)
4291 if (scalar_check (status, 0) == FAILURE)
4299 gfc_check_flush (gfc_expr *unit)
4304 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4307 if (scalar_check (unit, 0) == FAILURE)
4315 gfc_check_free (gfc_expr *i)
4317 if (type_check (i, 0, BT_INTEGER) == FAILURE)
4320 if (scalar_check (i, 0) == FAILURE)
4328 gfc_check_hostnm (gfc_expr *name)
4330 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4332 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4340 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
4342 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4344 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4350 if (scalar_check (status, 1) == FAILURE)
4353 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4361 gfc_check_itime_idate (gfc_expr *values)
4363 if (array_check (values, 0) == FAILURE)
4366 if (rank_check (values, 0, 1) == FAILURE)
4369 if (variable_check (values, 0) == FAILURE)
4372 if (type_check (values, 0, BT_INTEGER) == FAILURE)
4375 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
4383 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
4385 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4388 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
4391 if (scalar_check (time, 0) == FAILURE)
4394 if (array_check (values, 1) == FAILURE)
4397 if (rank_check (values, 1, 1) == FAILURE)
4400 if (variable_check (values, 1) == FAILURE)
4403 if (type_check (values, 1, BT_INTEGER) == FAILURE)
4406 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
4414 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
4416 if (scalar_check (unit, 0) == FAILURE)
4419 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4422 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
4424 if (kind_value_check (name, 1, gfc_default_character_kind) == FAILURE)
4432 gfc_check_isatty (gfc_expr *unit)
4437 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4440 if (scalar_check (unit, 0) == FAILURE)
4448 gfc_check_isnan (gfc_expr *x)
4450 if (type_check (x, 0, BT_REAL) == FAILURE)
4458 gfc_check_perror (gfc_expr *string)
4460 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
4462 if (kind_value_check (string, 0, gfc_default_character_kind) == FAILURE)
4470 gfc_check_umask (gfc_expr *mask)
4472 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4475 if (scalar_check (mask, 0) == FAILURE)
4483 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
4485 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4488 if (scalar_check (mask, 0) == FAILURE)
4494 if (scalar_check (old, 1) == FAILURE)
4497 if (type_check (old, 1, BT_INTEGER) == FAILURE)
4505 gfc_check_unlink (gfc_expr *name)
4507 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4509 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4517 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
4519 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4521 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4527 if (scalar_check (status, 1) == FAILURE)
4530 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4538 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
4540 if (scalar_check (number, 0) == FAILURE)
4542 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4545 if (int_or_proc_check (handler, 1) == FAILURE)
4547 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4555 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
4557 if (scalar_check (number, 0) == FAILURE)
4559 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4562 if (int_or_proc_check (handler, 1) == FAILURE)
4564 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4570 if (type_check (status, 2, BT_INTEGER) == FAILURE)
4572 if (scalar_check (status, 2) == FAILURE)
4580 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
4582 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
4584 if (kind_value_check (cmd, 0, gfc_default_character_kind) == FAILURE)
4587 if (scalar_check (status, 1) == FAILURE)
4590 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4593 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
4600 /* This is used for the GNU intrinsics AND, OR and XOR. */
4602 gfc_check_and (gfc_expr *i, gfc_expr *j)
4604 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
4606 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4607 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
4608 gfc_current_intrinsic, &i->where);
4612 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
4614 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4615 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
4616 gfc_current_intrinsic, &j->where);
4620 if (i->ts.type != j->ts.type)
4622 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
4623 "have the same type", gfc_current_intrinsic_arg[0]->name,
4624 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4629 if (scalar_check (i, 0) == FAILURE)
4632 if (scalar_check (j, 1) == FAILURE)
4640 gfc_check_storage_size (gfc_expr *a ATTRIBUTE_UNUSED, gfc_expr *kind)
4645 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
4648 if (scalar_check (kind, 1) == FAILURE)
4651 if (kind->expr_type != EXPR_CONSTANT)
4653 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
4654 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,