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)
224 else if (ref->type == REF_ARRAY && ref->u.ar.codimen != 0)
227 for (n = 0; n < ref->u.ar.codimen; n++)
228 if (ref->u.ar.dimen_type[n] != DIMEN_THIS_IMAGE)
238 coarray_check (gfc_expr *e, int n)
242 gfc_error ("Expected coarray variable as '%s' argument to the %s "
243 "intrinsic at %L", gfc_current_intrinsic_arg[n]->name,
244 gfc_current_intrinsic, &e->where);
252 /* Make sure the expression is a logical array. */
255 logical_array_check (gfc_expr *array, int n)
257 if (array->ts.type != BT_LOGICAL || array->rank == 0)
259 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
260 "array", gfc_current_intrinsic_arg[n]->name,
261 gfc_current_intrinsic, &array->where);
269 /* Make sure an expression is an array. */
272 array_check (gfc_expr *e, int n)
277 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
278 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
285 /* If expr is a constant, then check to ensure that it is greater than
289 nonnegative_check (const char *arg, gfc_expr *expr)
293 if (expr->expr_type == EXPR_CONSTANT)
295 gfc_extract_int (expr, &i);
298 gfc_error ("'%s' at %L must be nonnegative", arg, &expr->where);
307 /* If expr2 is constant, then check that the value is less than
308 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
311 less_than_bitsize1 (const char *arg1, gfc_expr *expr1, const char *arg2,
312 gfc_expr *expr2, bool or_equal)
316 if (expr2->expr_type == EXPR_CONSTANT)
318 gfc_extract_int (expr2, &i2);
319 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
322 if (i2 > gfc_integer_kinds[i3].bit_size)
324 gfc_error ("'%s' at %L must be less than "
325 "or equal to BIT_SIZE('%s')",
326 arg2, &expr2->where, arg1);
332 if (i2 >= gfc_integer_kinds[i3].bit_size)
334 gfc_error ("'%s' at %L must be less than BIT_SIZE('%s')",
335 arg2, &expr2->where, arg1);
345 /* If expr is constant, then check that the value is less than or equal
346 to the bit_size of the kind k. */
349 less_than_bitsizekind (const char *arg, gfc_expr *expr, int k)
353 if (expr->expr_type != EXPR_CONSTANT)
356 i = gfc_validate_kind (BT_INTEGER, k, false);
357 gfc_extract_int (expr, &val);
359 if (val > gfc_integer_kinds[i].bit_size)
361 gfc_error ("'%s' at %L must be less than or equal to the BIT_SIZE of "
362 "INTEGER(KIND=%d)", arg, &expr->where, k);
370 /* If expr2 and expr3 are constants, then check that the value is less than
371 or equal to bit_size(expr1). */
374 less_than_bitsize2 (const char *arg1, gfc_expr *expr1, const char *arg2,
375 gfc_expr *expr2, const char *arg3, gfc_expr *expr3)
379 if (expr2->expr_type == EXPR_CONSTANT && expr3->expr_type == EXPR_CONSTANT)
381 gfc_extract_int (expr2, &i2);
382 gfc_extract_int (expr3, &i3);
384 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
385 if (i2 > gfc_integer_kinds[i3].bit_size)
387 gfc_error ("'%s + %s' at %L must be less than or equal "
389 arg2, arg3, &expr2->where, arg1);
397 /* Make sure two expressions have the same type. */
400 same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
402 if (gfc_compare_types (&e->ts, &f->ts))
405 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
406 "and kind as '%s'", gfc_current_intrinsic_arg[m]->name,
407 gfc_current_intrinsic, &f->where,
408 gfc_current_intrinsic_arg[n]->name);
414 /* Make sure that an expression has a certain (nonzero) rank. */
417 rank_check (gfc_expr *e, int n, int rank)
422 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
423 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
430 /* Make sure a variable expression is not an optional dummy argument. */
433 nonoptional_check (gfc_expr *e, int n)
435 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
437 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
438 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
442 /* TODO: Recursive check on nonoptional variables? */
448 /* Check for ALLOCATABLE attribute. */
451 allocatable_check (gfc_expr *e, int n)
453 symbol_attribute attr;
455 attr = gfc_variable_attr (e, NULL);
456 if (!attr.allocatable)
458 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
459 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
468 /* Check that an expression has a particular kind. */
471 kind_value_check (gfc_expr *e, int n, int k)
476 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
477 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
484 /* Make sure an expression is a variable. */
487 variable_check (gfc_expr *e, int n, bool allow_proc)
489 if (e->expr_type == EXPR_VARIABLE
490 && e->symtree->n.sym->attr.intent == INTENT_IN
491 && (gfc_current_intrinsic_arg[n]->intent == INTENT_OUT
492 || gfc_current_intrinsic_arg[n]->intent == INTENT_INOUT))
494 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
495 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
500 if (e->expr_type == EXPR_VARIABLE
501 && e->symtree->n.sym->attr.flavor != FL_PARAMETER
503 || !e->symtree->n.sym->attr.function
504 || (e->symtree->n.sym == e->symtree->n.sym->result
505 && (e->symtree->n.sym == gfc_current_ns->proc_name
506 || (gfc_current_ns->parent
508 == gfc_current_ns->parent->proc_name)))))
511 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
512 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, &e->where);
518 /* Check the common DIM parameter for correctness. */
521 dim_check (gfc_expr *dim, int n, bool optional)
526 if (type_check (dim, n, BT_INTEGER) == FAILURE)
529 if (scalar_check (dim, n) == FAILURE)
532 if (!optional && nonoptional_check (dim, n) == FAILURE)
539 /* If a coarray DIM parameter is a constant, make sure that it is greater than
540 zero and less than or equal to the corank of the given array. */
543 dim_corank_check (gfc_expr *dim, gfc_expr *array)
548 gcc_assert (array->expr_type == EXPR_VARIABLE);
550 if (dim->expr_type != EXPR_CONSTANT)
553 ar = gfc_find_array_ref (array);
554 corank = ar->as->corank;
556 if (mpz_cmp_ui (dim->value.integer, 1) < 0
557 || mpz_cmp_ui (dim->value.integer, corank) > 0)
559 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
560 "codimension index", gfc_current_intrinsic, &dim->where);
569 /* If a DIM parameter is a constant, make sure that it is greater than
570 zero and less than or equal to the rank of the given array. If
571 allow_assumed is zero then dim must be less than the rank of the array
572 for assumed size arrays. */
575 dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
583 if (dim->expr_type != EXPR_CONSTANT)
586 if (array->expr_type == EXPR_FUNCTION && array->value.function.isym
587 && array->value.function.isym->id == GFC_ISYM_SPREAD)
588 rank = array->rank + 1;
592 if (array->expr_type == EXPR_VARIABLE)
594 ar = gfc_find_array_ref (array);
595 if (ar->as->type == AS_ASSUMED_SIZE
597 && ar->type != AR_ELEMENT
598 && ar->type != AR_SECTION)
602 if (mpz_cmp_ui (dim->value.integer, 1) < 0
603 || mpz_cmp_ui (dim->value.integer, rank) > 0)
605 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
606 "dimension index", gfc_current_intrinsic, &dim->where);
615 /* Compare the size of a along dimension ai with the size of b along
616 dimension bi, returning 0 if they are known not to be identical,
617 and 1 if they are identical, or if this cannot be determined. */
620 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
622 mpz_t a_size, b_size;
625 gcc_assert (a->rank > ai);
626 gcc_assert (b->rank > bi);
630 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
632 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
634 if (mpz_cmp (a_size, b_size) != 0)
644 /* Calculate the length of a character variable, including substrings.
645 Strip away parentheses if necessary. Return -1 if no length could
649 gfc_var_strlen (const gfc_expr *a)
653 while (a->expr_type == EXPR_OP && a->value.op.op == INTRINSIC_PARENTHESES)
656 for (ra = a->ref; ra != NULL && ra->type != REF_SUBSTRING; ra = ra->next)
663 if (ra->u.ss.start->expr_type == EXPR_CONSTANT
664 && ra->u.ss.end->expr_type == EXPR_CONSTANT)
666 start_a = mpz_get_si (ra->u.ss.start->value.integer);
667 end_a = mpz_get_si (ra->u.ss.end->value.integer);
668 return end_a - start_a + 1;
670 else if (gfc_dep_compare_expr (ra->u.ss.start, ra->u.ss.end) == 0)
676 if (a->ts.u.cl && a->ts.u.cl->length
677 && a->ts.u.cl->length->expr_type == EXPR_CONSTANT)
678 return mpz_get_si (a->ts.u.cl->length->value.integer);
679 else if (a->expr_type == EXPR_CONSTANT
680 && (a->ts.u.cl == NULL || a->ts.u.cl->length == NULL))
681 return a->value.character.length;
687 /* Check whether two character expressions have the same length;
688 returns SUCCESS if they have or if the length cannot be determined,
689 otherwise return FAILURE and raise a gfc_error. */
692 gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
696 len_a = gfc_var_strlen(a);
697 len_b = gfc_var_strlen(b);
699 if (len_a == -1 || len_b == -1 || len_a == len_b)
703 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
704 len_a, len_b, name, &a->where);
710 /***** Check functions *****/
712 /* Check subroutine suitable for intrinsics taking a real argument and
713 a kind argument for the result. */
716 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
718 if (type_check (a, 0, BT_REAL) == FAILURE)
720 if (kind_check (kind, 1, type) == FAILURE)
727 /* Check subroutine suitable for ceiling, floor and nint. */
730 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
732 return check_a_kind (a, kind, BT_INTEGER);
736 /* Check subroutine suitable for aint, anint. */
739 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
741 return check_a_kind (a, kind, BT_REAL);
746 gfc_check_abs (gfc_expr *a)
748 if (numeric_check (a, 0) == FAILURE)
756 gfc_check_achar (gfc_expr *a, gfc_expr *kind)
758 if (type_check (a, 0, BT_INTEGER) == FAILURE)
760 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
768 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
770 if (type_check (name, 0, BT_CHARACTER) == FAILURE
771 || scalar_check (name, 0) == FAILURE)
773 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
776 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
777 || scalar_check (mode, 1) == FAILURE)
779 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
787 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
789 if (logical_array_check (mask, 0) == FAILURE)
792 if (dim_check (dim, 1, false) == FAILURE)
795 if (dim_rank_check (dim, mask, 0) == FAILURE)
803 gfc_check_allocated (gfc_expr *array)
805 if (variable_check (array, 0, false) == FAILURE)
807 if (allocatable_check (array, 0) == FAILURE)
814 /* Common check function where the first argument must be real or
815 integer and the second argument must be the same as the first. */
818 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
820 if (int_or_real_check (a, 0) == FAILURE)
823 if (a->ts.type != p->ts.type)
825 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
826 "have the same type", gfc_current_intrinsic_arg[0]->name,
827 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
832 if (a->ts.kind != p->ts.kind)
834 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
835 &p->where) == FAILURE)
844 gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
846 if (double_check (x, 0) == FAILURE || double_check (y, 1) == FAILURE)
854 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
856 symbol_attribute attr1, attr2;
861 where = &pointer->where;
863 if (pointer->expr_type == EXPR_VARIABLE || pointer->expr_type == EXPR_FUNCTION)
864 attr1 = gfc_expr_attr (pointer);
865 else if (pointer->expr_type == EXPR_NULL)
868 gcc_assert (0); /* Pointer must be a variable or a function. */
870 if (!attr1.pointer && !attr1.proc_pointer)
872 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
873 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
879 if (attr1.pointer && gfc_is_coindexed (pointer))
881 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
882 "conindexed", gfc_current_intrinsic_arg[0]->name,
883 gfc_current_intrinsic, &pointer->where);
887 /* Target argument is optional. */
891 where = &target->where;
892 if (target->expr_type == EXPR_NULL)
895 if (target->expr_type == EXPR_VARIABLE || target->expr_type == EXPR_FUNCTION)
896 attr2 = gfc_expr_attr (target);
899 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
900 "or target VARIABLE or FUNCTION",
901 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
906 if (attr1.pointer && !attr2.pointer && !attr2.target)
908 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
909 "or a TARGET", gfc_current_intrinsic_arg[1]->name,
910 gfc_current_intrinsic, &target->where);
915 if (attr1.pointer && gfc_is_coindexed (target))
917 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
918 "conindexed", gfc_current_intrinsic_arg[1]->name,
919 gfc_current_intrinsic, &target->where);
924 if (same_type_check (pointer, 0, target, 1) == FAILURE)
926 if (rank_check (target, 0, pointer->rank) == FAILURE)
928 if (target->rank > 0)
930 for (i = 0; i < target->rank; i++)
931 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
933 gfc_error ("Array section with a vector subscript at %L shall not "
934 "be the target of a pointer",
944 gfc_error ("NULL pointer at %L is not permitted as actual argument "
945 "of '%s' intrinsic function", where, gfc_current_intrinsic);
952 gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
954 /* gfc_notify_std would be a wast of time as the return value
955 is seemingly used only for the generic resolution. The error
956 will be: Too many arguments. */
957 if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
960 return gfc_check_atan2 (y, x);
965 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
967 if (type_check (y, 0, BT_REAL) == FAILURE)
969 if (same_type_check (y, 0, x, 1) == FAILURE)
977 gfc_check_atomic (gfc_expr *atom, gfc_expr *value)
979 if (!(atom->ts.type == BT_INTEGER && atom->ts.kind == gfc_atomic_int_kind)
980 && !(atom->ts.type == BT_LOGICAL
981 && atom->ts.kind == gfc_atomic_logical_kind))
983 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
984 "integer of ATOMIC_INT_KIND or a logical of "
985 "ATOMIC_LOGICAL_KIND", &atom->where, gfc_current_intrinsic);
989 if (!gfc_expr_attr (atom).codimension)
991 gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
992 "coarray or coindexed", &atom->where, gfc_current_intrinsic);
996 if (atom->ts.type != value->ts.type)
998 gfc_error ("ATOM and VALUE argument of the %s intrinsic function shall "
999 "have the same type at %L", gfc_current_intrinsic,
1009 gfc_check_atomic_def (gfc_expr *atom, gfc_expr *value)
1011 if (scalar_check (atom, 0) == FAILURE || scalar_check (value, 1) == FAILURE)
1014 if (gfc_check_vardef_context (atom, false, false, NULL) == FAILURE)
1016 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1017 "definable", gfc_current_intrinsic, &atom->where);
1021 return gfc_check_atomic (atom, value);
1026 gfc_check_atomic_ref (gfc_expr *value, gfc_expr *atom)
1028 if (scalar_check (value, 0) == FAILURE || scalar_check (atom, 1) == FAILURE)
1031 if (gfc_check_vardef_context (value, false, false, NULL) == FAILURE)
1033 gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1034 "definable", gfc_current_intrinsic, &value->where);
1038 return gfc_check_atomic (atom, value);
1042 /* BESJN and BESYN functions. */
1045 gfc_check_besn (gfc_expr *n, gfc_expr *x)
1047 if (type_check (n, 0, BT_INTEGER) == FAILURE)
1049 if (n->expr_type == EXPR_CONSTANT)
1052 gfc_extract_int (n, &i);
1053 if (i < 0 && gfc_notify_std (GFC_STD_GNU, "Extension: Negative argument "
1054 "N at %L", &n->where) == FAILURE)
1058 if (type_check (x, 1, BT_REAL) == FAILURE)
1065 /* Transformational version of the Bessel JN and YN functions. */
1068 gfc_check_bessel_n2 (gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
1070 if (type_check (n1, 0, BT_INTEGER) == FAILURE)
1072 if (scalar_check (n1, 0) == FAILURE)
1074 if (nonnegative_check("N1", n1) == FAILURE)
1077 if (type_check (n2, 1, BT_INTEGER) == FAILURE)
1079 if (scalar_check (n2, 1) == FAILURE)
1081 if (nonnegative_check("N2", n2) == FAILURE)
1084 if (type_check (x, 2, BT_REAL) == FAILURE)
1086 if (scalar_check (x, 2) == FAILURE)
1094 gfc_check_bge_bgt_ble_blt (gfc_expr *i, gfc_expr *j)
1096 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1099 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1107 gfc_check_bitfcn (gfc_expr *i, gfc_expr *pos)
1109 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1112 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1115 if (nonnegative_check ("pos", pos) == FAILURE)
1118 if (less_than_bitsize1 ("i", i, "pos", pos, false) == FAILURE)
1126 gfc_check_char (gfc_expr *i, gfc_expr *kind)
1128 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1130 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
1138 gfc_check_chdir (gfc_expr *dir)
1140 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
1142 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
1150 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
1152 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
1154 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
1160 if (type_check (status, 1, BT_INTEGER) == FAILURE)
1162 if (scalar_check (status, 1) == FAILURE)
1170 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
1172 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
1174 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
1177 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
1179 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
1187 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
1189 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
1191 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
1194 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
1196 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
1202 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1205 if (scalar_check (status, 2) == FAILURE)
1213 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
1215 if (numeric_check (x, 0) == FAILURE)
1220 if (numeric_check (y, 1) == FAILURE)
1223 if (x->ts.type == BT_COMPLEX)
1225 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1226 "present if 'x' is COMPLEX",
1227 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1232 if (y->ts.type == BT_COMPLEX)
1234 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1235 "of either REAL or INTEGER",
1236 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1243 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
1251 gfc_check_complex (gfc_expr *x, gfc_expr *y)
1253 if (int_or_real_check (x, 0) == FAILURE)
1255 if (scalar_check (x, 0) == FAILURE)
1258 if (int_or_real_check (y, 1) == FAILURE)
1260 if (scalar_check (y, 1) == FAILURE)
1268 gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
1270 if (logical_array_check (mask, 0) == FAILURE)
1272 if (dim_check (dim, 1, false) == FAILURE)
1274 if (dim_rank_check (dim, mask, 0) == FAILURE)
1276 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1278 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1279 "with KIND argument at %L",
1280 gfc_current_intrinsic, &kind->where) == FAILURE)
1288 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
1290 if (array_check (array, 0) == FAILURE)
1293 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1296 if (dim_check (dim, 2, true) == FAILURE)
1299 if (dim_rank_check (dim, array, false) == FAILURE)
1302 if (array->rank == 1 || shift->rank == 0)
1304 if (scalar_check (shift, 1) == FAILURE)
1307 else if (shift->rank == array->rank - 1)
1312 else if (dim->expr_type == EXPR_CONSTANT)
1313 gfc_extract_int (dim, &d);
1320 for (i = 0, j = 0; i < array->rank; i++)
1323 if (!identical_dimen_shape (array, i, shift, j))
1325 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1326 "invalid shape in dimension %d (%ld/%ld)",
1327 gfc_current_intrinsic_arg[1]->name,
1328 gfc_current_intrinsic, &shift->where, i + 1,
1329 mpz_get_si (array->shape[i]),
1330 mpz_get_si (shift->shape[j]));
1340 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1341 "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
1342 gfc_current_intrinsic, &shift->where, array->rank - 1);
1351 gfc_check_ctime (gfc_expr *time)
1353 if (scalar_check (time, 0) == FAILURE)
1356 if (type_check (time, 0, BT_INTEGER) == FAILURE)
1363 gfc_try gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
1365 if (double_check (y, 0) == FAILURE || double_check (x, 1) == FAILURE)
1372 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
1374 if (numeric_check (x, 0) == FAILURE)
1379 if (numeric_check (y, 1) == FAILURE)
1382 if (x->ts.type == BT_COMPLEX)
1384 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1385 "present if 'x' is COMPLEX",
1386 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1391 if (y->ts.type == BT_COMPLEX)
1393 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1394 "of either REAL or INTEGER",
1395 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1406 gfc_check_dble (gfc_expr *x)
1408 if (numeric_check (x, 0) == FAILURE)
1416 gfc_check_digits (gfc_expr *x)
1418 if (int_or_real_check (x, 0) == FAILURE)
1426 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
1428 switch (vector_a->ts.type)
1431 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
1438 if (numeric_check (vector_b, 1) == FAILURE)
1443 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1444 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
1445 gfc_current_intrinsic, &vector_a->where);
1449 if (rank_check (vector_a, 0, 1) == FAILURE)
1452 if (rank_check (vector_b, 1, 1) == FAILURE)
1455 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
1457 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1458 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0]->name,
1459 gfc_current_intrinsic_arg[1]->name, &vector_a->where);
1468 gfc_check_dprod (gfc_expr *x, gfc_expr *y)
1470 if (type_check (x, 0, BT_REAL) == FAILURE
1471 || type_check (y, 1, BT_REAL) == FAILURE)
1474 if (x->ts.kind != gfc_default_real_kind)
1476 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1477 "real", gfc_current_intrinsic_arg[0]->name,
1478 gfc_current_intrinsic, &x->where);
1482 if (y->ts.kind != gfc_default_real_kind)
1484 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1485 "real", gfc_current_intrinsic_arg[1]->name,
1486 gfc_current_intrinsic, &y->where);
1495 gfc_check_dshift (gfc_expr *i, gfc_expr *j, gfc_expr *shift)
1497 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1500 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1503 if (same_type_check (i, 0, j, 1) == FAILURE)
1506 if (type_check (shift, 2, BT_INTEGER) == FAILURE)
1509 if (nonnegative_check ("SHIFT", shift) == FAILURE)
1512 if (less_than_bitsize1 ("I", i, "SHIFT", shift, true) == FAILURE)
1520 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
1523 if (array_check (array, 0) == FAILURE)
1526 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1529 if (dim_check (dim, 3, true) == FAILURE)
1532 if (dim_rank_check (dim, array, false) == FAILURE)
1535 if (array->rank == 1 || shift->rank == 0)
1537 if (scalar_check (shift, 1) == FAILURE)
1540 else if (shift->rank == array->rank - 1)
1545 else if (dim->expr_type == EXPR_CONSTANT)
1546 gfc_extract_int (dim, &d);
1553 for (i = 0, j = 0; i < array->rank; i++)
1556 if (!identical_dimen_shape (array, i, shift, j))
1558 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1559 "invalid shape in dimension %d (%ld/%ld)",
1560 gfc_current_intrinsic_arg[1]->name,
1561 gfc_current_intrinsic, &shift->where, i + 1,
1562 mpz_get_si (array->shape[i]),
1563 mpz_get_si (shift->shape[j]));
1573 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1574 "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
1575 gfc_current_intrinsic, &shift->where, array->rank - 1);
1579 if (boundary != NULL)
1581 if (same_type_check (array, 0, boundary, 2) == FAILURE)
1584 if (array->rank == 1 || boundary->rank == 0)
1586 if (scalar_check (boundary, 2) == FAILURE)
1589 else if (boundary->rank == array->rank - 1)
1591 if (gfc_check_conformance (shift, boundary,
1592 "arguments '%s' and '%s' for "
1594 gfc_current_intrinsic_arg[1]->name,
1595 gfc_current_intrinsic_arg[2]->name,
1596 gfc_current_intrinsic ) == FAILURE)
1601 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1602 "rank %d or be a scalar",
1603 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1604 &shift->where, array->rank - 1);
1613 gfc_check_float (gfc_expr *a)
1615 if (type_check (a, 0, BT_INTEGER) == FAILURE)
1618 if ((a->ts.kind != gfc_default_integer_kind)
1619 && gfc_notify_std (GFC_STD_GNU, "GNU extension: non-default INTEGER "
1620 "kind argument to %s intrinsic at %L",
1621 gfc_current_intrinsic, &a->where) == FAILURE )
1627 /* A single complex argument. */
1630 gfc_check_fn_c (gfc_expr *a)
1632 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
1638 /* A single real argument. */
1641 gfc_check_fn_r (gfc_expr *a)
1643 if (type_check (a, 0, BT_REAL) == FAILURE)
1649 /* A single double argument. */
1652 gfc_check_fn_d (gfc_expr *a)
1654 if (double_check (a, 0) == FAILURE)
1660 /* A single real or complex argument. */
1663 gfc_check_fn_rc (gfc_expr *a)
1665 if (real_or_complex_check (a, 0) == FAILURE)
1673 gfc_check_fn_rc2008 (gfc_expr *a)
1675 if (real_or_complex_check (a, 0) == FAILURE)
1678 if (a->ts.type == BT_COMPLEX
1679 && gfc_notify_std (GFC_STD_F2008, "Fortran 2008: COMPLEX argument '%s' "
1680 "argument of '%s' intrinsic at %L",
1681 gfc_current_intrinsic_arg[0]->name,
1682 gfc_current_intrinsic, &a->where) == FAILURE)
1690 gfc_check_fnum (gfc_expr *unit)
1692 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1695 if (scalar_check (unit, 0) == FAILURE)
1703 gfc_check_huge (gfc_expr *x)
1705 if (int_or_real_check (x, 0) == FAILURE)
1713 gfc_check_hypot (gfc_expr *x, gfc_expr *y)
1715 if (type_check (x, 0, BT_REAL) == FAILURE)
1717 if (same_type_check (x, 0, y, 1) == FAILURE)
1724 /* Check that the single argument is an integer. */
1727 gfc_check_i (gfc_expr *i)
1729 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1737 gfc_check_iand (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_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1759 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1762 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1765 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1768 if (nonnegative_check ("pos", pos) == FAILURE)
1771 if (nonnegative_check ("len", len) == FAILURE)
1774 if (less_than_bitsize2 ("i", i, "pos", pos, "len", len) == FAILURE)
1782 gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
1786 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1789 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1792 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1793 "with KIND argument at %L",
1794 gfc_current_intrinsic, &kind->where) == FAILURE)
1797 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1803 /* Substring references don't have the charlength set. */
1805 while (ref && ref->type != REF_SUBSTRING)
1808 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1812 /* Check that the argument is length one. Non-constant lengths
1813 can't be checked here, so assume they are ok. */
1814 if (c->ts.u.cl && c->ts.u.cl->length)
1816 /* If we already have a length for this expression then use it. */
1817 if (c->ts.u.cl->length->expr_type != EXPR_CONSTANT)
1819 i = mpz_get_si (c->ts.u.cl->length->value.integer);
1826 start = ref->u.ss.start;
1827 end = ref->u.ss.end;
1830 if (end == NULL || end->expr_type != EXPR_CONSTANT
1831 || start->expr_type != EXPR_CONSTANT)
1834 i = mpz_get_si (end->value.integer) + 1
1835 - mpz_get_si (start->value.integer);
1843 gfc_error ("Argument of %s at %L must be of length one",
1844 gfc_current_intrinsic, &c->where);
1853 gfc_check_idnint (gfc_expr *a)
1855 if (double_check (a, 0) == FAILURE)
1863 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1865 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1868 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1871 if (i->ts.kind != j->ts.kind)
1873 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1874 &i->where) == FAILURE)
1883 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back,
1886 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1887 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1890 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1893 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
1895 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1896 "with KIND argument at %L",
1897 gfc_current_intrinsic, &kind->where) == FAILURE)
1900 if (string->ts.kind != substring->ts.kind)
1902 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1903 "kind as '%s'", gfc_current_intrinsic_arg[1]->name,
1904 gfc_current_intrinsic, &substring->where,
1905 gfc_current_intrinsic_arg[0]->name);
1914 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1916 if (numeric_check (x, 0) == FAILURE)
1919 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1927 gfc_check_intconv (gfc_expr *x)
1929 if (numeric_check (x, 0) == FAILURE)
1937 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1939 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1942 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1945 if (i->ts.kind != j->ts.kind)
1947 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1948 &i->where) == FAILURE)
1957 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1959 if (type_check (i, 0, BT_INTEGER) == FAILURE
1960 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1968 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1970 if (type_check (i, 0, BT_INTEGER) == FAILURE
1971 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1974 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1982 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1984 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1987 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1995 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1997 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
2000 if (scalar_check (pid, 0) == FAILURE)
2003 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
2006 if (scalar_check (sig, 1) == FAILURE)
2012 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2015 if (scalar_check (status, 2) == FAILURE)
2023 gfc_check_kind (gfc_expr *x)
2025 if (x->ts.type == BT_DERIVED)
2027 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
2028 "non-derived type", gfc_current_intrinsic_arg[0]->name,
2029 gfc_current_intrinsic, &x->where);
2038 gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2040 if (array_check (array, 0) == FAILURE)
2043 if (dim_check (dim, 1, false) == FAILURE)
2046 if (dim_rank_check (dim, array, 1) == FAILURE)
2049 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
2051 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2052 "with KIND argument at %L",
2053 gfc_current_intrinsic, &kind->where) == FAILURE)
2061 gfc_check_lcobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
2063 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
2065 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
2069 if (coarray_check (coarray, 0) == FAILURE)
2074 if (dim_check (dim, 1, false) == FAILURE)
2077 if (dim_corank_check (dim, coarray) == FAILURE)
2081 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
2089 gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
2091 if (type_check (s, 0, BT_CHARACTER) == FAILURE)
2094 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
2096 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2097 "with KIND argument at %L",
2098 gfc_current_intrinsic, &kind->where) == FAILURE)
2106 gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
2108 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2110 if (kind_value_check (a, 0, gfc_default_character_kind) == FAILURE)
2113 if (type_check (b, 1, BT_CHARACTER) == FAILURE)
2115 if (kind_value_check (b, 1, gfc_default_character_kind) == FAILURE)
2123 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
2125 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2127 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2130 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2132 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2140 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2142 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2144 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2147 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2149 if (kind_value_check (path2, 0, gfc_default_character_kind) == FAILURE)
2155 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2158 if (scalar_check (status, 2) == FAILURE)
2166 gfc_check_loc (gfc_expr *expr)
2168 return variable_check (expr, 0, true);
2173 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
2175 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2177 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2180 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2182 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2190 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2192 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2194 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2197 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2199 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2205 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2208 if (scalar_check (status, 2) == FAILURE)
2216 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
2218 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
2220 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
2227 /* Min/max family. */
2230 min_max_args (gfc_actual_arglist *arg)
2232 if (arg == NULL || arg->next == NULL)
2234 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
2235 gfc_current_intrinsic, gfc_current_intrinsic_where);
2244 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
2246 gfc_actual_arglist *arg, *tmp;
2251 if (min_max_args (arglist) == FAILURE)
2254 for (arg = arglist, n=1; arg; arg = arg->next, n++)
2257 if (x->ts.type != type || x->ts.kind != kind)
2259 if (x->ts.type == type)
2261 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
2262 "kinds at %L", &x->where) == FAILURE)
2267 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
2268 "%s(%d)", n, gfc_current_intrinsic, &x->where,
2269 gfc_basic_typename (type), kind);
2274 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
2275 if (gfc_check_conformance (tmp->expr, x,
2276 "arguments 'a%d' and 'a%d' for "
2277 "intrinsic '%s'", m, n,
2278 gfc_current_intrinsic) == FAILURE)
2287 gfc_check_min_max (gfc_actual_arglist *arg)
2291 if (min_max_args (arg) == FAILURE)
2296 if (x->ts.type == BT_CHARACTER)
2298 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2299 "with CHARACTER argument at %L",
2300 gfc_current_intrinsic, &x->where) == FAILURE)
2303 else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
2305 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
2306 "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
2310 return check_rest (x->ts.type, x->ts.kind, arg);
2315 gfc_check_min_max_integer (gfc_actual_arglist *arg)
2317 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
2322 gfc_check_min_max_real (gfc_actual_arglist *arg)
2324 return check_rest (BT_REAL, gfc_default_real_kind, arg);
2329 gfc_check_min_max_double (gfc_actual_arglist *arg)
2331 return check_rest (BT_REAL, gfc_default_double_kind, arg);
2335 /* End of min/max family. */
2338 gfc_check_malloc (gfc_expr *size)
2340 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2343 if (scalar_check (size, 0) == FAILURE)
2351 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
2353 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
2355 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2356 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
2357 gfc_current_intrinsic, &matrix_a->where);
2361 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
2363 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2364 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
2365 gfc_current_intrinsic, &matrix_b->where);
2369 if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
2370 || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
2372 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2373 gfc_current_intrinsic, &matrix_a->where,
2374 gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
2378 switch (matrix_a->rank)
2381 if (rank_check (matrix_b, 1, 2) == FAILURE)
2383 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2384 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
2386 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2387 "and '%s' at %L for intrinsic matmul",
2388 gfc_current_intrinsic_arg[0]->name,
2389 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
2395 if (matrix_b->rank != 2)
2397 if (rank_check (matrix_b, 1, 1) == FAILURE)
2400 /* matrix_b has rank 1 or 2 here. Common check for the cases
2401 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2402 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2403 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
2405 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2406 "dimension 1 for argument '%s' at %L for intrinsic "
2407 "matmul", gfc_current_intrinsic_arg[0]->name,
2408 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
2414 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2415 "1 or 2", gfc_current_intrinsic_arg[0]->name,
2416 gfc_current_intrinsic, &matrix_a->where);
2424 /* Whoever came up with this interface was probably on something.
2425 The possibilities for the occupation of the second and third
2432 NULL MASK minloc(array, mask=m)
2435 I.e. in the case of minloc(array,mask), mask will be in the second
2436 position of the argument list and we'll have to fix that up. */
2439 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
2441 gfc_expr *a, *m, *d;
2444 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
2448 m = ap->next->next->expr;
2450 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2451 && ap->next->name == NULL)
2455 ap->next->expr = NULL;
2456 ap->next->next->expr = m;
2459 if (dim_check (d, 1, false) == FAILURE)
2462 if (dim_rank_check (d, a, 0) == FAILURE)
2465 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2469 && gfc_check_conformance (a, m,
2470 "arguments '%s' and '%s' for intrinsic %s",
2471 gfc_current_intrinsic_arg[0]->name,
2472 gfc_current_intrinsic_arg[2]->name,
2473 gfc_current_intrinsic ) == FAILURE)
2480 /* Similar to minloc/maxloc, the argument list might need to be
2481 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2482 difference is that MINLOC/MAXLOC take an additional KIND argument.
2483 The possibilities are:
2489 NULL MASK minval(array, mask=m)
2492 I.e. in the case of minval(array,mask), mask will be in the second
2493 position of the argument list and we'll have to fix that up. */
2496 check_reduction (gfc_actual_arglist *ap)
2498 gfc_expr *a, *m, *d;
2502 m = ap->next->next->expr;
2504 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2505 && ap->next->name == NULL)
2509 ap->next->expr = NULL;
2510 ap->next->next->expr = m;
2513 if (dim_check (d, 1, false) == FAILURE)
2516 if (dim_rank_check (d, a, 0) == FAILURE)
2519 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2523 && gfc_check_conformance (a, m,
2524 "arguments '%s' and '%s' for intrinsic %s",
2525 gfc_current_intrinsic_arg[0]->name,
2526 gfc_current_intrinsic_arg[2]->name,
2527 gfc_current_intrinsic) == FAILURE)
2535 gfc_check_minval_maxval (gfc_actual_arglist *ap)
2537 if (int_or_real_check (ap->expr, 0) == FAILURE
2538 || array_check (ap->expr, 0) == FAILURE)
2541 return check_reduction (ap);
2546 gfc_check_product_sum (gfc_actual_arglist *ap)
2548 if (numeric_check (ap->expr, 0) == FAILURE
2549 || array_check (ap->expr, 0) == FAILURE)
2552 return check_reduction (ap);
2556 /* For IANY, IALL and IPARITY. */
2559 gfc_check_mask (gfc_expr *i, gfc_expr *kind)
2563 if (type_check (i, 0, BT_INTEGER) == FAILURE)
2566 if (nonnegative_check ("I", i) == FAILURE)
2569 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
2573 gfc_extract_int (kind, &k);
2575 k = gfc_default_integer_kind;
2577 if (less_than_bitsizekind ("I", i, k) == FAILURE)
2585 gfc_check_transf_bit_intrins (gfc_actual_arglist *ap)
2587 if (ap->expr->ts.type != BT_INTEGER)
2589 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER",
2590 gfc_current_intrinsic_arg[0]->name,
2591 gfc_current_intrinsic, &ap->expr->where);
2595 if (array_check (ap->expr, 0) == FAILURE)
2598 return check_reduction (ap);
2603 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
2605 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
2608 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
2611 if (tsource->ts.type == BT_CHARACTER)
2612 return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
2619 gfc_check_merge_bits (gfc_expr *i, gfc_expr *j, gfc_expr *mask)
2621 if (type_check (i, 0, BT_INTEGER) == FAILURE)
2624 if (type_check (j, 1, BT_INTEGER) == FAILURE)
2627 if (type_check (mask, 2, BT_INTEGER) == FAILURE)
2630 if (same_type_check (i, 0, j, 1) == FAILURE)
2633 if (same_type_check (i, 0, mask, 2) == FAILURE)
2641 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
2643 if (variable_check (from, 0, false) == FAILURE)
2645 if (allocatable_check (from, 0) == FAILURE)
2648 if (variable_check (to, 1, false) == FAILURE)
2650 if (allocatable_check (to, 1) == FAILURE)
2653 if (same_type_check (to, 1, from, 0) == FAILURE)
2656 if (to->rank != from->rank)
2658 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2659 "have the same rank %d/%d", gfc_current_intrinsic_arg[0]->name,
2660 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2661 &to->where, from->rank, to->rank);
2665 if (to->ts.kind != from->ts.kind)
2667 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2668 "be of the same kind %d/%d",
2669 gfc_current_intrinsic_arg[0]->name,
2670 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2671 &to->where, from->ts.kind, to->ts.kind);
2675 /* CLASS arguments: Make sure the vtab is present. */
2676 if (to->ts.type == BT_CLASS)
2677 gfc_find_derived_vtab (from->ts.u.derived);
2684 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
2686 if (type_check (x, 0, BT_REAL) == FAILURE)
2689 if (type_check (s, 1, BT_REAL) == FAILURE)
2697 gfc_check_new_line (gfc_expr *a)
2699 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2707 gfc_check_norm2 (gfc_expr *array, gfc_expr *dim)
2709 if (type_check (array, 0, BT_REAL) == FAILURE)
2712 if (array_check (array, 0) == FAILURE)
2715 if (dim_rank_check (dim, array, false) == FAILURE)
2722 gfc_check_null (gfc_expr *mold)
2724 symbol_attribute attr;
2729 if (variable_check (mold, 0, true) == FAILURE)
2732 attr = gfc_variable_attr (mold, NULL);
2734 if (!attr.pointer && !attr.proc_pointer)
2736 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
2737 gfc_current_intrinsic_arg[0]->name,
2738 gfc_current_intrinsic, &mold->where);
2743 if (gfc_is_coindexed (mold))
2745 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
2746 "conindexed", gfc_current_intrinsic_arg[0]->name,
2747 gfc_current_intrinsic, &mold->where);
2756 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
2758 if (array_check (array, 0) == FAILURE)
2761 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2764 if (gfc_check_conformance (array, mask,
2765 "arguments '%s' and '%s' for intrinsic '%s'",
2766 gfc_current_intrinsic_arg[0]->name,
2767 gfc_current_intrinsic_arg[1]->name,
2768 gfc_current_intrinsic) == FAILURE)
2773 mpz_t array_size, vector_size;
2774 bool have_array_size, have_vector_size;
2776 if (same_type_check (array, 0, vector, 2) == FAILURE)
2779 if (rank_check (vector, 2, 1) == FAILURE)
2782 /* VECTOR requires at least as many elements as MASK
2783 has .TRUE. values. */
2784 have_array_size = gfc_array_size (array, &array_size) == SUCCESS;
2785 have_vector_size = gfc_array_size (vector, &vector_size) == SUCCESS;
2787 if (have_vector_size
2788 && (mask->expr_type == EXPR_ARRAY
2789 || (mask->expr_type == EXPR_CONSTANT
2790 && have_array_size)))
2792 int mask_true_values = 0;
2794 if (mask->expr_type == EXPR_ARRAY)
2796 gfc_constructor *mask_ctor;
2797 mask_ctor = gfc_constructor_first (mask->value.constructor);
2800 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
2802 mask_true_values = 0;
2806 if (mask_ctor->expr->value.logical)
2809 mask_ctor = gfc_constructor_next (mask_ctor);
2812 else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
2813 mask_true_values = mpz_get_si (array_size);
2815 if (mpz_get_si (vector_size) < mask_true_values)
2817 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2818 "provide at least as many elements as there "
2819 "are .TRUE. values in '%s' (%ld/%d)",
2820 gfc_current_intrinsic_arg[2]->name,
2821 gfc_current_intrinsic, &vector->where,
2822 gfc_current_intrinsic_arg[1]->name,
2823 mpz_get_si (vector_size), mask_true_values);
2828 if (have_array_size)
2829 mpz_clear (array_size);
2830 if (have_vector_size)
2831 mpz_clear (vector_size);
2839 gfc_check_parity (gfc_expr *mask, gfc_expr *dim)
2841 if (type_check (mask, 0, BT_LOGICAL) == FAILURE)
2844 if (array_check (mask, 0) == FAILURE)
2847 if (dim_rank_check (dim, mask, false) == FAILURE)
2855 gfc_check_precision (gfc_expr *x)
2857 if (real_or_complex_check (x, 0) == FAILURE)
2865 gfc_check_present (gfc_expr *a)
2869 if (variable_check (a, 0, true) == FAILURE)
2872 sym = a->symtree->n.sym;
2873 if (!sym->attr.dummy)
2875 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2876 "dummy variable", gfc_current_intrinsic_arg[0]->name,
2877 gfc_current_intrinsic, &a->where);
2881 if (!sym->attr.optional)
2883 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2884 "an OPTIONAL dummy variable",
2885 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2890 /* 13.14.82 PRESENT(A)
2892 Argument. A shall be the name of an optional dummy argument that is
2893 accessible in the subprogram in which the PRESENT function reference
2897 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2898 && a->ref->u.ar.type == AR_FULL))
2900 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2901 "subobject of '%s'", gfc_current_intrinsic_arg[0]->name,
2902 gfc_current_intrinsic, &a->where, sym->name);
2911 gfc_check_radix (gfc_expr *x)
2913 if (int_or_real_check (x, 0) == FAILURE)
2921 gfc_check_range (gfc_expr *x)
2923 if (numeric_check (x, 0) == FAILURE)
2931 gfc_check_rank (gfc_expr *a ATTRIBUTE_UNUSED)
2933 /* Any data object is allowed; a "data object" is a "constant (4.1.3),
2934 variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
2936 bool is_variable = true;
2938 /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
2939 if (a->expr_type == EXPR_FUNCTION)
2940 is_variable = a->value.function.esym
2941 ? a->value.function.esym->result->attr.pointer
2942 : a->symtree->n.sym->result->attr.pointer;
2944 if (a->expr_type == EXPR_OP || a->expr_type == EXPR_NULL
2945 || a->expr_type == EXPR_COMPCALL|| a->expr_type == EXPR_PPC
2948 gfc_error ("The argument of the RANK intrinsic at %L must be a data "
2949 "object", &a->where);
2957 /* real, float, sngl. */
2959 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2961 if (numeric_check (a, 0) == FAILURE)
2964 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2972 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2974 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2976 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2979 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2981 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2989 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2991 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2993 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2996 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2998 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
3004 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3007 if (scalar_check (status, 2) == FAILURE)
3015 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
3017 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3020 if (scalar_check (x, 0) == FAILURE)
3023 if (type_check (y, 0, BT_INTEGER) == FAILURE)
3026 if (scalar_check (y, 1) == FAILURE)
3034 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
3035 gfc_expr *pad, gfc_expr *order)
3041 if (array_check (source, 0) == FAILURE)
3044 if (rank_check (shape, 1, 1) == FAILURE)
3047 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
3050 if (gfc_array_size (shape, &size) != SUCCESS)
3052 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
3053 "array of constant size", &shape->where);
3057 shape_size = mpz_get_ui (size);
3060 if (shape_size <= 0)
3062 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
3063 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3067 else if (shape_size > GFC_MAX_DIMENSIONS)
3069 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
3070 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
3073 else if (shape->expr_type == EXPR_ARRAY)
3077 for (i = 0; i < shape_size; ++i)
3079 e = gfc_constructor_lookup_expr (shape->value.constructor, i);
3080 if (e->expr_type != EXPR_CONSTANT)
3083 gfc_extract_int (e, &extent);
3086 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3087 "negative element (%d)",
3088 gfc_current_intrinsic_arg[1]->name,
3089 gfc_current_intrinsic, &e->where, extent);
3097 if (same_type_check (source, 0, pad, 2) == FAILURE)
3100 if (array_check (pad, 2) == FAILURE)
3106 if (array_check (order, 3) == FAILURE)
3109 if (type_check (order, 3, BT_INTEGER) == FAILURE)
3112 if (order->expr_type == EXPR_ARRAY)
3114 int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
3117 for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
3120 gfc_array_size (order, &size);
3121 order_size = mpz_get_ui (size);
3124 if (order_size != shape_size)
3126 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3127 "has wrong number of elements (%d/%d)",
3128 gfc_current_intrinsic_arg[3]->name,
3129 gfc_current_intrinsic, &order->where,
3130 order_size, shape_size);
3134 for (i = 1; i <= order_size; ++i)
3136 e = gfc_constructor_lookup_expr (order->value.constructor, i-1);
3137 if (e->expr_type != EXPR_CONSTANT)
3140 gfc_extract_int (e, &dim);
3142 if (dim < 1 || dim > order_size)
3144 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3145 "has out-of-range dimension (%d)",
3146 gfc_current_intrinsic_arg[3]->name,
3147 gfc_current_intrinsic, &e->where, dim);
3151 if (perm[dim-1] != 0)
3153 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3154 "invalid permutation of dimensions (dimension "
3156 gfc_current_intrinsic_arg[3]->name,
3157 gfc_current_intrinsic, &e->where, dim);
3166 if (pad == NULL && shape->expr_type == EXPR_ARRAY
3167 && gfc_is_constant_expr (shape)
3168 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
3169 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
3171 /* Check the match in size between source and destination. */
3172 if (gfc_array_size (source, &nelems) == SUCCESS)
3178 mpz_init_set_ui (size, 1);
3179 for (c = gfc_constructor_first (shape->value.constructor);
3180 c; c = gfc_constructor_next (c))
3181 mpz_mul (size, size, c->expr->value.integer);
3183 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
3189 gfc_error ("Without padding, there are not enough elements "
3190 "in the intrinsic RESHAPE source at %L to match "
3191 "the shape", &source->where);
3202 gfc_check_same_type_as (gfc_expr *a, gfc_expr *b)
3205 if (a->ts.type != BT_DERIVED && a->ts.type != BT_CLASS)
3207 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3208 "must be of a derived type",
3209 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3214 if (!gfc_type_is_extensible (a->ts.u.derived))
3216 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3217 "must be of an extensible type",
3218 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3223 if (b->ts.type != BT_DERIVED && b->ts.type != BT_CLASS)
3225 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3226 "must be of a derived type",
3227 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3232 if (!gfc_type_is_extensible (b->ts.u.derived))
3234 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3235 "must be of an extensible type",
3236 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3246 gfc_check_scale (gfc_expr *x, gfc_expr *i)
3248 if (type_check (x, 0, BT_REAL) == FAILURE)
3251 if (type_check (i, 1, BT_INTEGER) == FAILURE)
3259 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
3261 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3264 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
3267 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
3270 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
3272 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3273 "with KIND argument at %L",
3274 gfc_current_intrinsic, &kind->where) == FAILURE)
3277 if (same_type_check (x, 0, y, 1) == FAILURE)
3285 gfc_check_secnds (gfc_expr *r)
3287 if (type_check (r, 0, BT_REAL) == FAILURE)
3290 if (kind_value_check (r, 0, 4) == FAILURE)
3293 if (scalar_check (r, 0) == FAILURE)
3301 gfc_check_selected_char_kind (gfc_expr *name)
3303 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3306 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3309 if (scalar_check (name, 0) == FAILURE)
3317 gfc_check_selected_int_kind (gfc_expr *r)
3319 if (type_check (r, 0, BT_INTEGER) == FAILURE)
3322 if (scalar_check (r, 0) == FAILURE)
3330 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r, gfc_expr *radix)
3332 if (p == NULL && r == NULL
3333 && gfc_notify_std (GFC_STD_F2008, "Fortran 2008: SELECTED_REAL_KIND with"
3334 " neither 'P' nor 'R' argument at %L",
3335 gfc_current_intrinsic_where) == FAILURE)
3340 if (type_check (p, 0, BT_INTEGER) == FAILURE)
3343 if (scalar_check (p, 0) == FAILURE)
3349 if (type_check (r, 1, BT_INTEGER) == FAILURE)
3352 if (scalar_check (r, 1) == FAILURE)
3358 if (type_check (radix, 1, BT_INTEGER) == FAILURE)
3361 if (scalar_check (radix, 1) == FAILURE)
3364 if (gfc_notify_std (GFC_STD_F2008, "Fortran 2008: '%s' intrinsic with "
3365 "RADIX argument at %L", gfc_current_intrinsic,
3366 &radix->where) == FAILURE)
3375 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
3377 if (type_check (x, 0, BT_REAL) == FAILURE)
3380 if (type_check (i, 1, BT_INTEGER) == FAILURE)
3388 gfc_check_shape (gfc_expr *source, gfc_expr *kind)
3392 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
3395 ar = gfc_find_array_ref (source);
3397 if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
3399 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
3400 "an assumed size array", &source->where);
3404 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
3406 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3407 "with KIND argument at %L",
3408 gfc_current_intrinsic, &kind->where) == FAILURE)
3416 gfc_check_shift (gfc_expr *i, gfc_expr *shift)
3418 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3421 if (type_check (shift, 0, BT_INTEGER) == FAILURE)
3424 if (nonnegative_check ("SHIFT", shift) == FAILURE)
3427 if (less_than_bitsize1 ("I", i, "SHIFT", shift, true) == FAILURE)
3435 gfc_check_sign (gfc_expr *a, gfc_expr *b)
3437 if (int_or_real_check (a, 0) == FAILURE)
3440 if (same_type_check (a, 0, b, 1) == FAILURE)
3448 gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3450 if (array_check (array, 0) == FAILURE)
3453 if (dim_check (dim, 1, true) == FAILURE)
3456 if (dim_rank_check (dim, array, 0) == FAILURE)
3459 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3461 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3462 "with KIND argument at %L",
3463 gfc_current_intrinsic, &kind->where) == FAILURE)
3472 gfc_check_sizeof (gfc_expr *arg ATTRIBUTE_UNUSED)
3479 gfc_check_c_sizeof (gfc_expr *arg)
3481 if (verify_c_interop (&arg->ts) != SUCCESS)
3483 gfc_error ("'%s' argument of '%s' intrinsic at %L must be be an "
3484 "interoperable data entity",
3485 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3494 gfc_check_sleep_sub (gfc_expr *seconds)
3496 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3499 if (scalar_check (seconds, 0) == FAILURE)
3506 gfc_check_sngl (gfc_expr *a)
3508 if (type_check (a, 0, BT_REAL) == FAILURE)
3511 if ((a->ts.kind != gfc_default_double_kind)
3512 && gfc_notify_std (GFC_STD_GNU, "GNU extension: non double precision "
3513 "REAL argument to %s intrinsic at %L",
3514 gfc_current_intrinsic, &a->where) == FAILURE)
3521 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
3523 if (source->rank >= GFC_MAX_DIMENSIONS)
3525 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
3526 "than rank %d", gfc_current_intrinsic_arg[0]->name,
3527 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
3535 if (dim_check (dim, 1, false) == FAILURE)
3538 /* dim_rank_check() does not apply here. */
3540 && dim->expr_type == EXPR_CONSTANT
3541 && (mpz_cmp_ui (dim->value.integer, 1) < 0
3542 || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0))
3544 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
3545 "dimension index", gfc_current_intrinsic_arg[1]->name,
3546 gfc_current_intrinsic, &dim->where);
3550 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
3553 if (scalar_check (ncopies, 2) == FAILURE)
3560 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3564 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
3566 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3569 if (scalar_check (unit, 0) == FAILURE)
3572 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
3574 if (kind_value_check (c, 1, gfc_default_character_kind) == FAILURE)
3580 if (type_check (status, 2, BT_INTEGER) == FAILURE
3581 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
3582 || scalar_check (status, 2) == FAILURE)
3590 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
3592 return gfc_check_fgetputc_sub (unit, c, NULL);
3597 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
3599 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
3601 if (kind_value_check (c, 0, gfc_default_character_kind) == FAILURE)
3607 if (type_check (status, 1, BT_INTEGER) == FAILURE
3608 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
3609 || scalar_check (status, 1) == FAILURE)
3617 gfc_check_fgetput (gfc_expr *c)
3619 return gfc_check_fgetput_sub (c, NULL);
3624 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
3626 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3629 if (scalar_check (unit, 0) == FAILURE)
3632 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3635 if (scalar_check (offset, 1) == FAILURE)
3638 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
3641 if (scalar_check (whence, 2) == FAILURE)
3647 if (type_check (status, 3, BT_INTEGER) == FAILURE)
3650 if (kind_value_check (status, 3, 4) == FAILURE)
3653 if (scalar_check (status, 3) == FAILURE)
3662 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
3664 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3667 if (scalar_check (unit, 0) == FAILURE)
3670 if (type_check (array, 1, BT_INTEGER) == FAILURE
3671 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
3674 if (array_check (array, 1) == FAILURE)
3682 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
3684 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3687 if (scalar_check (unit, 0) == FAILURE)
3690 if (type_check (array, 1, BT_INTEGER) == FAILURE
3691 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3694 if (array_check (array, 1) == FAILURE)
3700 if (type_check (status, 2, BT_INTEGER) == FAILURE
3701 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3704 if (scalar_check (status, 2) == FAILURE)
3712 gfc_check_ftell (gfc_expr *unit)
3714 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3717 if (scalar_check (unit, 0) == FAILURE)
3725 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
3727 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3730 if (scalar_check (unit, 0) == FAILURE)
3733 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3736 if (scalar_check (offset, 1) == FAILURE)
3744 gfc_check_stat (gfc_expr *name, gfc_expr *array)
3746 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3748 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3751 if (type_check (array, 1, BT_INTEGER) == FAILURE
3752 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3755 if (array_check (array, 1) == FAILURE)
3763 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
3765 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3767 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3770 if (type_check (array, 1, BT_INTEGER) == FAILURE
3771 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3774 if (array_check (array, 1) == FAILURE)
3780 if (type_check (status, 2, BT_INTEGER) == FAILURE
3781 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3784 if (scalar_check (status, 2) == FAILURE)
3792 gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub)
3796 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3798 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3802 if (coarray_check (coarray, 0) == FAILURE)
3807 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3808 gfc_current_intrinsic_arg[1]->name, &sub->where);
3812 if (gfc_array_size (sub, &nelems) == SUCCESS)
3814 int corank = gfc_get_corank (coarray);
3816 if (mpz_cmp_ui (nelems, corank) != 0)
3818 gfc_error ("The number of array elements of the SUB argument to "
3819 "IMAGE_INDEX at %L shall be %d (corank) not %d",
3820 &sub->where, corank, (int) mpz_get_si (nelems));
3832 gfc_check_this_image (gfc_expr *coarray, gfc_expr *dim)
3834 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3836 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3840 if (dim != NULL && coarray == NULL)
3842 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3843 "intrinsic at %L", &dim->where);
3847 if (coarray == NULL)
3850 if (coarray_check (coarray, 0) == FAILURE)
3855 if (dim_check (dim, 1, false) == FAILURE)
3858 if (dim_corank_check (dim, coarray) == FAILURE)
3867 gfc_check_transfer (gfc_expr *source ATTRIBUTE_UNUSED,
3868 gfc_expr *mold ATTRIBUTE_UNUSED, gfc_expr *size)
3870 if (mold->ts.type == BT_HOLLERITH)
3872 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3873 &mold->where, gfc_basic_typename (BT_HOLLERITH));
3879 if (type_check (size, 2, BT_INTEGER) == FAILURE)
3882 if (scalar_check (size, 2) == FAILURE)
3885 if (nonoptional_check (size, 2) == FAILURE)
3894 gfc_check_transpose (gfc_expr *matrix)
3896 if (rank_check (matrix, 0, 2) == FAILURE)
3904 gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3906 if (array_check (array, 0) == FAILURE)
3909 if (dim_check (dim, 1, false) == FAILURE)
3912 if (dim_rank_check (dim, array, 0) == FAILURE)
3915 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3917 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3918 "with KIND argument at %L",
3919 gfc_current_intrinsic, &kind->where) == FAILURE)
3927 gfc_check_ucobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
3929 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3931 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3935 if (coarray_check (coarray, 0) == FAILURE)
3940 if (dim_check (dim, 1, false) == FAILURE)
3943 if (dim_corank_check (dim, coarray) == FAILURE)
3947 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3955 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
3959 if (rank_check (vector, 0, 1) == FAILURE)
3962 if (array_check (mask, 1) == FAILURE)
3965 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
3968 if (same_type_check (vector, 0, field, 2) == FAILURE)
3971 if (mask->expr_type == EXPR_ARRAY
3972 && gfc_array_size (vector, &vector_size) == SUCCESS)
3974 int mask_true_count = 0;
3975 gfc_constructor *mask_ctor;
3976 mask_ctor = gfc_constructor_first (mask->value.constructor);
3979 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
3981 mask_true_count = 0;
3985 if (mask_ctor->expr->value.logical)
3988 mask_ctor = gfc_constructor_next (mask_ctor);
3991 if (mpz_get_si (vector_size) < mask_true_count)
3993 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
3994 "provide at least as many elements as there "
3995 "are .TRUE. values in '%s' (%ld/%d)",
3996 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3997 &vector->where, gfc_current_intrinsic_arg[1]->name,
3998 mpz_get_si (vector_size), mask_true_count);
4002 mpz_clear (vector_size);
4005 if (mask->rank != field->rank && field->rank != 0)
4007 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
4008 "the same rank as '%s' or be a scalar",
4009 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
4010 &field->where, gfc_current_intrinsic_arg[1]->name);
4014 if (mask->rank == field->rank)
4017 for (i = 0; i < field->rank; i++)
4018 if (! identical_dimen_shape (mask, i, field, i))
4020 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
4021 "must have identical shape.",
4022 gfc_current_intrinsic_arg[2]->name,
4023 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4033 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
4035 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
4038 if (same_type_check (x, 0, y, 1) == FAILURE)
4041 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
4044 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
4046 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
4047 "with KIND argument at %L",
4048 gfc_current_intrinsic, &kind->where) == FAILURE)
4056 gfc_check_trim (gfc_expr *x)
4058 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
4061 if (scalar_check (x, 0) == FAILURE)
4069 gfc_check_ttynam (gfc_expr *unit)
4071 if (scalar_check (unit, 0) == FAILURE)
4074 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4081 /* Common check function for the half a dozen intrinsics that have a
4082 single real argument. */
4085 gfc_check_x (gfc_expr *x)
4087 if (type_check (x, 0, BT_REAL) == FAILURE)
4094 /************* Check functions for intrinsic subroutines *************/
4097 gfc_check_cpu_time (gfc_expr *time)
4099 if (scalar_check (time, 0) == FAILURE)
4102 if (type_check (time, 0, BT_REAL) == FAILURE)
4105 if (variable_check (time, 0, false) == FAILURE)
4113 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
4114 gfc_expr *zone, gfc_expr *values)
4118 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
4120 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
4122 if (scalar_check (date, 0) == FAILURE)
4124 if (variable_check (date, 0, false) == FAILURE)
4130 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
4132 if (kind_value_check (time, 1, gfc_default_character_kind) == FAILURE)
4134 if (scalar_check (time, 1) == FAILURE)
4136 if (variable_check (time, 1, false) == FAILURE)
4142 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
4144 if (kind_value_check (zone, 2, gfc_default_character_kind) == FAILURE)
4146 if (scalar_check (zone, 2) == FAILURE)
4148 if (variable_check (zone, 2, false) == FAILURE)
4154 if (type_check (values, 3, BT_INTEGER) == FAILURE)
4156 if (array_check (values, 3) == FAILURE)
4158 if (rank_check (values, 3, 1) == FAILURE)
4160 if (variable_check (values, 3, false) == FAILURE)
4169 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
4170 gfc_expr *to, gfc_expr *topos)
4172 if (type_check (from, 0, BT_INTEGER) == FAILURE)
4175 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
4178 if (type_check (len, 2, BT_INTEGER) == FAILURE)
4181 if (same_type_check (from, 0, to, 3) == FAILURE)
4184 if (variable_check (to, 3, false) == FAILURE)
4187 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
4190 if (nonnegative_check ("frompos", frompos) == FAILURE)
4193 if (nonnegative_check ("topos", topos) == FAILURE)
4196 if (nonnegative_check ("len", len) == FAILURE)
4199 if (less_than_bitsize2 ("from", from, "frompos", frompos, "len", len)
4203 if (less_than_bitsize2 ("to", to, "topos", topos, "len", len) == FAILURE)
4211 gfc_check_random_number (gfc_expr *harvest)
4213 if (type_check (harvest, 0, BT_REAL) == FAILURE)
4216 if (variable_check (harvest, 0, false) == FAILURE)
4224 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
4226 unsigned int nargs = 0, kiss_size;
4227 locus *where = NULL;
4228 mpz_t put_size, get_size;
4229 bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
4231 have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
4233 /* Keep the number of bytes in sync with kiss_size in
4234 libgfortran/intrinsics/random.c. */
4235 kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind;
4239 if (size->expr_type != EXPR_VARIABLE
4240 || !size->symtree->n.sym->attr.optional)
4243 if (scalar_check (size, 0) == FAILURE)
4246 if (type_check (size, 0, BT_INTEGER) == FAILURE)
4249 if (variable_check (size, 0, false) == FAILURE)
4252 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
4258 if (put->expr_type != EXPR_VARIABLE
4259 || !put->symtree->n.sym->attr.optional)
4262 where = &put->where;
4265 if (array_check (put, 1) == FAILURE)
4268 if (rank_check (put, 1, 1) == FAILURE)
4271 if (type_check (put, 1, BT_INTEGER) == FAILURE)
4274 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
4277 if (gfc_array_size (put, &put_size) == SUCCESS
4278 && mpz_get_ui (put_size) < kiss_size)
4279 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4280 "too small (%i/%i)",
4281 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4282 where, (int) mpz_get_ui (put_size), kiss_size);
4287 if (get->expr_type != EXPR_VARIABLE
4288 || !get->symtree->n.sym->attr.optional)
4291 where = &get->where;
4294 if (array_check (get, 2) == FAILURE)
4297 if (rank_check (get, 2, 1) == FAILURE)
4300 if (type_check (get, 2, BT_INTEGER) == FAILURE)
4303 if (variable_check (get, 2, false) == FAILURE)
4306 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
4309 if (gfc_array_size (get, &get_size) == SUCCESS
4310 && mpz_get_ui (get_size) < kiss_size)
4311 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4312 "too small (%i/%i)",
4313 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
4314 where, (int) mpz_get_ui (get_size), kiss_size);
4317 /* RANDOM_SEED may not have more than one non-optional argument. */
4319 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
4326 gfc_check_second_sub (gfc_expr *time)
4328 if (scalar_check (time, 0) == FAILURE)
4331 if (type_check (time, 0, BT_REAL) == FAILURE)
4334 if (kind_value_check(time, 0, 4) == FAILURE)
4341 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
4342 count, count_rate, and count_max are all optional arguments */
4345 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
4346 gfc_expr *count_max)
4350 if (scalar_check (count, 0) == FAILURE)
4353 if (type_check (count, 0, BT_INTEGER) == FAILURE)
4356 if (variable_check (count, 0, false) == FAILURE)
4360 if (count_rate != NULL)
4362 if (scalar_check (count_rate, 1) == FAILURE)
4365 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
4368 if (variable_check (count_rate, 1, false) == FAILURE)
4372 && same_type_check (count, 0, count_rate, 1) == FAILURE)
4377 if (count_max != NULL)
4379 if (scalar_check (count_max, 2) == FAILURE)
4382 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
4385 if (variable_check (count_max, 2, false) == FAILURE)
4389 && same_type_check (count, 0, count_max, 2) == FAILURE)
4392 if (count_rate != NULL
4393 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
4402 gfc_check_irand (gfc_expr *x)
4407 if (scalar_check (x, 0) == FAILURE)
4410 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4413 if (kind_value_check(x, 0, 4) == FAILURE)
4421 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
4423 if (scalar_check (seconds, 0) == FAILURE)
4425 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
4428 if (int_or_proc_check (handler, 1) == FAILURE)
4430 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4436 if (scalar_check (status, 2) == FAILURE)
4438 if (type_check (status, 2, BT_INTEGER) == FAILURE)
4440 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
4448 gfc_check_rand (gfc_expr *x)
4453 if (scalar_check (x, 0) == FAILURE)
4456 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4459 if (kind_value_check(x, 0, 4) == FAILURE)
4467 gfc_check_srand (gfc_expr *x)
4469 if (scalar_check (x, 0) == FAILURE)
4472 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4475 if (kind_value_check(x, 0, 4) == FAILURE)
4483 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
4485 if (scalar_check (time, 0) == FAILURE)
4487 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4490 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
4492 if (kind_value_check (result, 1, gfc_default_character_kind) == FAILURE)
4500 gfc_check_dtime_etime (gfc_expr *x)
4502 if (array_check (x, 0) == FAILURE)
4505 if (rank_check (x, 0, 1) == FAILURE)
4508 if (variable_check (x, 0, false) == FAILURE)
4511 if (type_check (x, 0, BT_REAL) == FAILURE)
4514 if (kind_value_check(x, 0, 4) == FAILURE)
4522 gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
4524 if (array_check (values, 0) == FAILURE)
4527 if (rank_check (values, 0, 1) == FAILURE)
4530 if (variable_check (values, 0, false) == FAILURE)
4533 if (type_check (values, 0, BT_REAL) == FAILURE)
4536 if (kind_value_check(values, 0, 4) == FAILURE)
4539 if (scalar_check (time, 1) == FAILURE)
4542 if (type_check (time, 1, BT_REAL) == FAILURE)
4545 if (kind_value_check(time, 1, 4) == FAILURE)
4553 gfc_check_fdate_sub (gfc_expr *date)
4555 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
4557 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
4565 gfc_check_gerror (gfc_expr *msg)
4567 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4569 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4577 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
4579 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
4581 if (kind_value_check (cwd, 0, gfc_default_character_kind) == FAILURE)
4587 if (scalar_check (status, 1) == FAILURE)
4590 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4598 gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
4600 if (type_check (pos, 0, BT_INTEGER) == FAILURE)
4603 if (pos->ts.kind > gfc_default_integer_kind)
4605 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4606 "not wider than the default kind (%d)",
4607 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4608 &pos->where, gfc_default_integer_kind);
4612 if (type_check (value, 1, BT_CHARACTER) == FAILURE)
4614 if (kind_value_check (value, 1, gfc_default_character_kind) == FAILURE)
4622 gfc_check_getlog (gfc_expr *msg)
4624 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4626 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4634 gfc_check_exit (gfc_expr *status)
4639 if (type_check (status, 0, BT_INTEGER) == FAILURE)
4642 if (scalar_check (status, 0) == FAILURE)
4650 gfc_check_flush (gfc_expr *unit)
4655 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4658 if (scalar_check (unit, 0) == FAILURE)
4666 gfc_check_free (gfc_expr *i)
4668 if (type_check (i, 0, BT_INTEGER) == FAILURE)
4671 if (scalar_check (i, 0) == FAILURE)
4679 gfc_check_hostnm (gfc_expr *name)
4681 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4683 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4691 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
4693 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4695 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4701 if (scalar_check (status, 1) == FAILURE)
4704 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4712 gfc_check_itime_idate (gfc_expr *values)
4714 if (array_check (values, 0) == FAILURE)
4717 if (rank_check (values, 0, 1) == FAILURE)
4720 if (variable_check (values, 0, false) == FAILURE)
4723 if (type_check (values, 0, BT_INTEGER) == FAILURE)
4726 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
4734 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
4736 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4739 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
4742 if (scalar_check (time, 0) == FAILURE)
4745 if (array_check (values, 1) == FAILURE)
4748 if (rank_check (values, 1, 1) == FAILURE)
4751 if (variable_check (values, 1, false) == FAILURE)
4754 if (type_check (values, 1, BT_INTEGER) == FAILURE)
4757 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
4765 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
4767 if (scalar_check (unit, 0) == FAILURE)
4770 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4773 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
4775 if (kind_value_check (name, 1, gfc_default_character_kind) == FAILURE)
4783 gfc_check_isatty (gfc_expr *unit)
4788 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4791 if (scalar_check (unit, 0) == FAILURE)
4799 gfc_check_isnan (gfc_expr *x)
4801 if (type_check (x, 0, BT_REAL) == FAILURE)
4809 gfc_check_perror (gfc_expr *string)
4811 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
4813 if (kind_value_check (string, 0, gfc_default_character_kind) == FAILURE)
4821 gfc_check_umask (gfc_expr *mask)
4823 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4826 if (scalar_check (mask, 0) == FAILURE)
4834 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
4836 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4839 if (scalar_check (mask, 0) == FAILURE)
4845 if (scalar_check (old, 1) == FAILURE)
4848 if (type_check (old, 1, BT_INTEGER) == FAILURE)
4856 gfc_check_unlink (gfc_expr *name)
4858 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4860 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4868 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
4870 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4872 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4878 if (scalar_check (status, 1) == FAILURE)
4881 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4889 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
4891 if (scalar_check (number, 0) == FAILURE)
4893 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4896 if (int_or_proc_check (handler, 1) == FAILURE)
4898 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4906 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
4908 if (scalar_check (number, 0) == FAILURE)
4910 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4913 if (int_or_proc_check (handler, 1) == FAILURE)
4915 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4921 if (type_check (status, 2, BT_INTEGER) == FAILURE)
4923 if (scalar_check (status, 2) == FAILURE)
4931 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
4933 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
4935 if (kind_value_check (cmd, 0, gfc_default_character_kind) == FAILURE)
4938 if (scalar_check (status, 1) == FAILURE)
4941 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4944 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
4951 /* This is used for the GNU intrinsics AND, OR and XOR. */
4953 gfc_check_and (gfc_expr *i, gfc_expr *j)
4955 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
4957 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4958 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
4959 gfc_current_intrinsic, &i->where);
4963 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
4965 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4966 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
4967 gfc_current_intrinsic, &j->where);
4971 if (i->ts.type != j->ts.type)
4973 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
4974 "have the same type", gfc_current_intrinsic_arg[0]->name,
4975 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4980 if (scalar_check (i, 0) == FAILURE)
4983 if (scalar_check (j, 1) == FAILURE)
4991 gfc_check_storage_size (gfc_expr *a ATTRIBUTE_UNUSED, gfc_expr *kind)
4996 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
4999 if (scalar_check (kind, 1) == FAILURE)
5002 if (kind->expr_type != EXPR_CONSTANT)
5004 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
5005 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,