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"
35 #include "target-memory.h"
38 /* Make sure an expression is a scalar. */
41 scalar_check (gfc_expr *e, int n)
46 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
47 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
54 /* Check the type of an expression. */
57 type_check (gfc_expr *e, int n, bt type)
59 if (e->ts.type == type)
62 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
63 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
64 &e->where, gfc_basic_typename (type));
70 /* Check that the expression is a numeric type. */
73 numeric_check (gfc_expr *e, int n)
75 if (gfc_numeric_ts (&e->ts))
78 /* If the expression has not got a type, check if its namespace can
79 offer a default type. */
80 if ((e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_VARIABLE)
81 && e->symtree->n.sym->ts.type == BT_UNKNOWN
82 && gfc_set_default_type (e->symtree->n.sym, 0,
83 e->symtree->n.sym->ns) == SUCCESS
84 && gfc_numeric_ts (&e->symtree->n.sym->ts))
86 e->ts = e->symtree->n.sym->ts;
90 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
91 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
98 /* Check that an expression is integer or real. */
101 int_or_real_check (gfc_expr *e, int n)
103 if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL)
105 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
106 "or REAL", gfc_current_intrinsic_arg[n]->name,
107 gfc_current_intrinsic, &e->where);
115 /* Check that an expression is real or complex. */
118 real_or_complex_check (gfc_expr *e, int n)
120 if (e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX)
122 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
123 "or COMPLEX", gfc_current_intrinsic_arg[n]->name,
124 gfc_current_intrinsic, &e->where);
132 /* Check that an expression is INTEGER or PROCEDURE. */
135 int_or_proc_check (gfc_expr *e, int n)
137 if (e->ts.type != BT_INTEGER && e->ts.type != BT_PROCEDURE)
139 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
140 "or PROCEDURE", gfc_current_intrinsic_arg[n]->name,
141 gfc_current_intrinsic, &e->where);
149 /* Check that the expression is an optional constant integer
150 and that it specifies a valid kind for that type. */
153 kind_check (gfc_expr *k, int n, bt type)
160 if (type_check (k, n, BT_INTEGER) == FAILURE)
163 if (scalar_check (k, n) == FAILURE)
166 if (k->expr_type != EXPR_CONSTANT)
168 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
169 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
174 if (gfc_extract_int (k, &kind) != NULL
175 || gfc_validate_kind (type, kind, true) < 0)
177 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
186 /* Make sure the expression is a double precision real. */
189 double_check (gfc_expr *d, int n)
191 if (type_check (d, n, BT_REAL) == FAILURE)
194 if (d->ts.kind != gfc_default_double_kind)
196 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
197 "precision", gfc_current_intrinsic_arg[n]->name,
198 gfc_current_intrinsic, &d->where);
206 /* Check whether an expression is a coarray (without array designator). */
209 is_coarray (gfc_expr *e)
211 bool coarray = false;
214 if (e->expr_type != EXPR_VARIABLE)
217 coarray = e->symtree->n.sym->attr.codimension;
219 for (ref = e->ref; ref; ref = ref->next)
221 if (ref->type == REF_COMPONENT)
222 coarray = ref->u.c.component->attr.codimension;
223 else if (ref->type != REF_ARRAY || ref->u.ar.dimen != 0)
225 else if (ref->type == REF_ARRAY && ref->u.ar.codimen != 0)
228 for (n = 0; n < ref->u.ar.codimen; n++)
229 if (ref->u.ar.dimen_type[n] != DIMEN_THIS_IMAGE)
239 coarray_check (gfc_expr *e, int n)
243 gfc_error ("Expected coarray variable as '%s' argument to the %s "
244 "intrinsic at %L", gfc_current_intrinsic_arg[n]->name,
245 gfc_current_intrinsic, &e->where);
253 /* Make sure the expression is a logical array. */
256 logical_array_check (gfc_expr *array, int n)
258 if (array->ts.type != BT_LOGICAL || array->rank == 0)
260 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
261 "array", gfc_current_intrinsic_arg[n]->name,
262 gfc_current_intrinsic, &array->where);
270 /* Make sure an expression is an array. */
273 array_check (gfc_expr *e, int n)
278 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
279 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
286 /* If expr is a constant, then check to ensure that it is greater than
290 nonnegative_check (const char *arg, gfc_expr *expr)
294 if (expr->expr_type == EXPR_CONSTANT)
296 gfc_extract_int (expr, &i);
299 gfc_error ("'%s' at %L must be nonnegative", arg, &expr->where);
308 /* If expr2 is constant, then check that the value is less than
309 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
312 less_than_bitsize1 (const char *arg1, gfc_expr *expr1, const char *arg2,
313 gfc_expr *expr2, bool or_equal)
317 if (expr2->expr_type == EXPR_CONSTANT)
319 gfc_extract_int (expr2, &i2);
320 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
323 if (i2 > gfc_integer_kinds[i3].bit_size)
325 gfc_error ("'%s' at %L must be less than "
326 "or equal to BIT_SIZE('%s')",
327 arg2, &expr2->where, arg1);
333 if (i2 >= gfc_integer_kinds[i3].bit_size)
335 gfc_error ("'%s' at %L must be less than BIT_SIZE('%s')",
336 arg2, &expr2->where, arg1);
346 /* If expr is constant, then check that the value is less than or equal
347 to the bit_size of the kind k. */
350 less_than_bitsizekind (const char *arg, gfc_expr *expr, int k)
354 if (expr->expr_type != EXPR_CONSTANT)
357 i = gfc_validate_kind (BT_INTEGER, k, false);
358 gfc_extract_int (expr, &val);
360 if (val > gfc_integer_kinds[i].bit_size)
362 gfc_error ("'%s' at %L must be less than or equal to the BIT_SIZE of "
363 "INTEGER(KIND=%d)", arg, &expr->where, k);
371 /* If expr2 and expr3 are constants, then check that the value is less than
372 or equal to bit_size(expr1). */
375 less_than_bitsize2 (const char *arg1, gfc_expr *expr1, const char *arg2,
376 gfc_expr *expr2, const char *arg3, gfc_expr *expr3)
380 if (expr2->expr_type == EXPR_CONSTANT && expr3->expr_type == EXPR_CONSTANT)
382 gfc_extract_int (expr2, &i2);
383 gfc_extract_int (expr3, &i3);
385 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
386 if (i2 > gfc_integer_kinds[i3].bit_size)
388 gfc_error ("'%s + %s' at %L must be less than or equal "
390 arg2, arg3, &expr2->where, arg1);
398 /* Make sure two expressions have the same type. */
401 same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
403 if (gfc_compare_types (&e->ts, &f->ts))
406 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
407 "and kind as '%s'", gfc_current_intrinsic_arg[m]->name,
408 gfc_current_intrinsic, &f->where,
409 gfc_current_intrinsic_arg[n]->name);
415 /* Make sure that an expression has a certain (nonzero) rank. */
418 rank_check (gfc_expr *e, int n, int rank)
423 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
424 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
431 /* Make sure a variable expression is not an optional dummy argument. */
434 nonoptional_check (gfc_expr *e, int n)
436 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
438 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
439 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
443 /* TODO: Recursive check on nonoptional variables? */
449 /* Check for ALLOCATABLE attribute. */
452 allocatable_check (gfc_expr *e, int n)
454 symbol_attribute attr;
456 attr = gfc_variable_attr (e, NULL);
457 if (!attr.allocatable)
459 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
460 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
469 /* Check that an expression has a particular kind. */
472 kind_value_check (gfc_expr *e, int n, int k)
477 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
478 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
485 /* Make sure an expression is a variable. */
488 variable_check (gfc_expr *e, int n, bool allow_proc)
490 if (e->expr_type == EXPR_VARIABLE
491 && e->symtree->n.sym->attr.intent == INTENT_IN
492 && (gfc_current_intrinsic_arg[n]->intent == INTENT_OUT
493 || gfc_current_intrinsic_arg[n]->intent == INTENT_INOUT))
495 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
496 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
501 if (e->expr_type == EXPR_VARIABLE
502 && e->symtree->n.sym->attr.flavor != FL_PARAMETER
504 || !e->symtree->n.sym->attr.function
505 || (e->symtree->n.sym == e->symtree->n.sym->result
506 && (e->symtree->n.sym == gfc_current_ns->proc_name
507 || (gfc_current_ns->parent
509 == gfc_current_ns->parent->proc_name)))))
512 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
513 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, &e->where);
519 /* Check the common DIM parameter for correctness. */
522 dim_check (gfc_expr *dim, int n, bool optional)
527 if (type_check (dim, n, BT_INTEGER) == FAILURE)
530 if (scalar_check (dim, n) == FAILURE)
533 if (!optional && nonoptional_check (dim, n) == FAILURE)
540 /* If a coarray DIM parameter is a constant, make sure that it is greater than
541 zero and less than or equal to the corank of the given array. */
544 dim_corank_check (gfc_expr *dim, gfc_expr *array)
549 gcc_assert (array->expr_type == EXPR_VARIABLE);
551 if (dim->expr_type != EXPR_CONSTANT)
554 ar = gfc_find_array_ref (array);
555 corank = ar->as->corank;
557 if (mpz_cmp_ui (dim->value.integer, 1) < 0
558 || mpz_cmp_ui (dim->value.integer, corank) > 0)
560 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
561 "codimension index", gfc_current_intrinsic, &dim->where);
570 /* If a DIM parameter is a constant, make sure that it is greater than
571 zero and less than or equal to the rank of the given array. If
572 allow_assumed is zero then dim must be less than the rank of the array
573 for assumed size arrays. */
576 dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
584 if (dim->expr_type != EXPR_CONSTANT)
587 if (array->expr_type == EXPR_FUNCTION && array->value.function.isym
588 && array->value.function.isym->id == GFC_ISYM_SPREAD)
589 rank = array->rank + 1;
593 if (array->expr_type == EXPR_VARIABLE)
595 ar = gfc_find_array_ref (array);
596 if (ar->as->type == AS_ASSUMED_SIZE
598 && ar->type != AR_ELEMENT
599 && ar->type != AR_SECTION)
603 if (mpz_cmp_ui (dim->value.integer, 1) < 0
604 || mpz_cmp_ui (dim->value.integer, rank) > 0)
606 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
607 "dimension index", gfc_current_intrinsic, &dim->where);
616 /* Compare the size of a along dimension ai with the size of b along
617 dimension bi, returning 0 if they are known not to be identical,
618 and 1 if they are identical, or if this cannot be determined. */
621 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
623 mpz_t a_size, b_size;
626 gcc_assert (a->rank > ai);
627 gcc_assert (b->rank > bi);
631 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
633 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
635 if (mpz_cmp (a_size, b_size) != 0)
645 /* Calculate the length of a character variable, including substrings.
646 Strip away parentheses if necessary. Return -1 if no length could
650 gfc_var_strlen (const gfc_expr *a)
654 while (a->expr_type == EXPR_OP && a->value.op.op == INTRINSIC_PARENTHESES)
657 for (ra = a->ref; ra != NULL && ra->type != REF_SUBSTRING; ra = ra->next)
664 if (ra->u.ss.start->expr_type == EXPR_CONSTANT
665 && ra->u.ss.end->expr_type == EXPR_CONSTANT)
667 start_a = mpz_get_si (ra->u.ss.start->value.integer);
668 end_a = mpz_get_si (ra->u.ss.end->value.integer);
669 return end_a - start_a + 1;
671 else if (gfc_dep_compare_expr (ra->u.ss.start, ra->u.ss.end) == 0)
677 if (a->ts.u.cl && a->ts.u.cl->length
678 && a->ts.u.cl->length->expr_type == EXPR_CONSTANT)
679 return mpz_get_si (a->ts.u.cl->length->value.integer);
680 else if (a->expr_type == EXPR_CONSTANT
681 && (a->ts.u.cl == NULL || a->ts.u.cl->length == NULL))
682 return a->value.character.length;
688 /* Check whether two character expressions have the same length;
689 returns SUCCESS if they have or if the length cannot be determined,
690 otherwise return FAILURE and raise a gfc_error. */
693 gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
697 len_a = gfc_var_strlen(a);
698 len_b = gfc_var_strlen(b);
700 if (len_a == -1 || len_b == -1 || len_a == len_b)
704 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
705 len_a, len_b, name, &a->where);
711 /***** Check functions *****/
713 /* Check subroutine suitable for intrinsics taking a real argument and
714 a kind argument for the result. */
717 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
719 if (type_check (a, 0, BT_REAL) == FAILURE)
721 if (kind_check (kind, 1, type) == FAILURE)
728 /* Check subroutine suitable for ceiling, floor and nint. */
731 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
733 return check_a_kind (a, kind, BT_INTEGER);
737 /* Check subroutine suitable for aint, anint. */
740 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
742 return check_a_kind (a, kind, BT_REAL);
747 gfc_check_abs (gfc_expr *a)
749 if (numeric_check (a, 0) == FAILURE)
757 gfc_check_achar (gfc_expr *a, gfc_expr *kind)
759 if (type_check (a, 0, BT_INTEGER) == FAILURE)
761 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
769 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
771 if (type_check (name, 0, BT_CHARACTER) == FAILURE
772 || scalar_check (name, 0) == FAILURE)
774 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
777 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
778 || scalar_check (mode, 1) == FAILURE)
780 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
788 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
790 if (logical_array_check (mask, 0) == FAILURE)
793 if (dim_check (dim, 1, false) == FAILURE)
796 if (dim_rank_check (dim, mask, 0) == FAILURE)
804 gfc_check_allocated (gfc_expr *array)
806 if (variable_check (array, 0, false) == FAILURE)
808 if (allocatable_check (array, 0) == FAILURE)
815 /* Common check function where the first argument must be real or
816 integer and the second argument must be the same as the first. */
819 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
821 if (int_or_real_check (a, 0) == FAILURE)
824 if (a->ts.type != p->ts.type)
826 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
827 "have the same type", gfc_current_intrinsic_arg[0]->name,
828 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
833 if (a->ts.kind != p->ts.kind)
835 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
836 &p->where) == FAILURE)
845 gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
847 if (double_check (x, 0) == FAILURE || double_check (y, 1) == FAILURE)
855 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
857 symbol_attribute attr1, attr2;
862 where = &pointer->where;
864 if (pointer->expr_type == EXPR_VARIABLE || pointer->expr_type == EXPR_FUNCTION)
865 attr1 = gfc_expr_attr (pointer);
866 else if (pointer->expr_type == EXPR_NULL)
869 gcc_assert (0); /* Pointer must be a variable or a function. */
871 if (!attr1.pointer && !attr1.proc_pointer)
873 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
874 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
880 if (attr1.pointer && gfc_is_coindexed (pointer))
882 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
883 "conindexed", gfc_current_intrinsic_arg[0]->name,
884 gfc_current_intrinsic, &pointer->where);
888 /* Target argument is optional. */
892 where = &target->where;
893 if (target->expr_type == EXPR_NULL)
896 if (target->expr_type == EXPR_VARIABLE || target->expr_type == EXPR_FUNCTION)
897 attr2 = gfc_expr_attr (target);
900 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
901 "or target VARIABLE or FUNCTION",
902 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
907 if (attr1.pointer && !attr2.pointer && !attr2.target)
909 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
910 "or a TARGET", gfc_current_intrinsic_arg[1]->name,
911 gfc_current_intrinsic, &target->where);
916 if (attr1.pointer && gfc_is_coindexed (target))
918 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
919 "conindexed", gfc_current_intrinsic_arg[1]->name,
920 gfc_current_intrinsic, &target->where);
925 if (same_type_check (pointer, 0, target, 1) == FAILURE)
927 if (rank_check (target, 0, pointer->rank) == FAILURE)
929 if (target->rank > 0)
931 for (i = 0; i < target->rank; i++)
932 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
934 gfc_error ("Array section with a vector subscript at %L shall not "
935 "be the target of a pointer",
945 gfc_error ("NULL pointer at %L is not permitted as actual argument "
946 "of '%s' intrinsic function", where, gfc_current_intrinsic);
953 gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
955 /* gfc_notify_std would be a wast of time as the return value
956 is seemingly used only for the generic resolution. The error
957 will be: Too many arguments. */
958 if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
961 return gfc_check_atan2 (y, x);
966 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
968 if (type_check (y, 0, BT_REAL) == FAILURE)
970 if (same_type_check (y, 0, x, 1) == FAILURE)
978 gfc_check_atomic (gfc_expr *atom, gfc_expr *value)
980 if (!(atom->ts.type == BT_INTEGER && atom->ts.kind == gfc_atomic_int_kind)
981 && !(atom->ts.type == BT_LOGICAL
982 && atom->ts.kind == gfc_atomic_logical_kind))
984 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
985 "integer of ATOMIC_INT_KIND or a logical of "
986 "ATOMIC_LOGICAL_KIND", &atom->where, gfc_current_intrinsic);
990 if (!gfc_expr_attr (atom).codimension)
992 gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
993 "coarray or coindexed", &atom->where, gfc_current_intrinsic);
997 if (atom->ts.type != value->ts.type)
999 gfc_error ("ATOM and VALUE argument of the %s intrinsic function shall "
1000 "have the same type at %L", gfc_current_intrinsic,
1010 gfc_check_atomic_def (gfc_expr *atom, gfc_expr *value)
1012 if (scalar_check (atom, 0) == FAILURE || scalar_check (value, 1) == FAILURE)
1015 if (gfc_check_vardef_context (atom, false, false, NULL) == FAILURE)
1017 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1018 "definable", gfc_current_intrinsic, &atom->where);
1022 return gfc_check_atomic (atom, value);
1027 gfc_check_atomic_ref (gfc_expr *value, gfc_expr *atom)
1029 if (scalar_check (value, 0) == FAILURE || scalar_check (atom, 1) == FAILURE)
1032 if (gfc_check_vardef_context (value, false, false, NULL) == FAILURE)
1034 gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1035 "definable", gfc_current_intrinsic, &value->where);
1039 return gfc_check_atomic (atom, value);
1043 /* BESJN and BESYN functions. */
1046 gfc_check_besn (gfc_expr *n, gfc_expr *x)
1048 if (type_check (n, 0, BT_INTEGER) == FAILURE)
1050 if (n->expr_type == EXPR_CONSTANT)
1053 gfc_extract_int (n, &i);
1054 if (i < 0 && gfc_notify_std (GFC_STD_GNU, "Extension: Negative argument "
1055 "N at %L", &n->where) == FAILURE)
1059 if (type_check (x, 1, BT_REAL) == FAILURE)
1066 /* Transformational version of the Bessel JN and YN functions. */
1069 gfc_check_bessel_n2 (gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
1071 if (type_check (n1, 0, BT_INTEGER) == FAILURE)
1073 if (scalar_check (n1, 0) == FAILURE)
1075 if (nonnegative_check("N1", n1) == FAILURE)
1078 if (type_check (n2, 1, BT_INTEGER) == FAILURE)
1080 if (scalar_check (n2, 1) == FAILURE)
1082 if (nonnegative_check("N2", n2) == FAILURE)
1085 if (type_check (x, 2, BT_REAL) == FAILURE)
1087 if (scalar_check (x, 2) == FAILURE)
1095 gfc_check_bge_bgt_ble_blt (gfc_expr *i, gfc_expr *j)
1097 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1100 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1108 gfc_check_bitfcn (gfc_expr *i, gfc_expr *pos)
1110 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1113 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1116 if (nonnegative_check ("pos", pos) == FAILURE)
1119 if (less_than_bitsize1 ("i", i, "pos", pos, false) == FAILURE)
1127 gfc_check_char (gfc_expr *i, gfc_expr *kind)
1129 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1131 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
1139 gfc_check_chdir (gfc_expr *dir)
1141 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
1143 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
1151 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
1153 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
1155 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
1161 if (type_check (status, 1, BT_INTEGER) == FAILURE)
1163 if (scalar_check (status, 1) == FAILURE)
1171 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
1173 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
1175 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
1178 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
1180 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
1188 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
1190 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
1192 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
1195 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
1197 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
1203 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1206 if (scalar_check (status, 2) == FAILURE)
1214 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
1216 if (numeric_check (x, 0) == FAILURE)
1221 if (numeric_check (y, 1) == FAILURE)
1224 if (x->ts.type == BT_COMPLEX)
1226 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1227 "present if 'x' is COMPLEX",
1228 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1233 if (y->ts.type == BT_COMPLEX)
1235 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1236 "of either REAL or INTEGER",
1237 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1244 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
1252 gfc_check_complex (gfc_expr *x, gfc_expr *y)
1254 if (int_or_real_check (x, 0) == FAILURE)
1256 if (scalar_check (x, 0) == FAILURE)
1259 if (int_or_real_check (y, 1) == FAILURE)
1261 if (scalar_check (y, 1) == FAILURE)
1269 gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
1271 if (logical_array_check (mask, 0) == FAILURE)
1273 if (dim_check (dim, 1, false) == FAILURE)
1275 if (dim_rank_check (dim, mask, 0) == FAILURE)
1277 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1279 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1280 "with KIND argument at %L",
1281 gfc_current_intrinsic, &kind->where) == FAILURE)
1289 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
1291 if (array_check (array, 0) == FAILURE)
1294 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1297 if (dim_check (dim, 2, true) == FAILURE)
1300 if (dim_rank_check (dim, array, false) == FAILURE)
1303 if (array->rank == 1 || shift->rank == 0)
1305 if (scalar_check (shift, 1) == FAILURE)
1308 else if (shift->rank == array->rank - 1)
1313 else if (dim->expr_type == EXPR_CONSTANT)
1314 gfc_extract_int (dim, &d);
1321 for (i = 0, j = 0; i < array->rank; i++)
1324 if (!identical_dimen_shape (array, i, shift, j))
1326 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1327 "invalid shape in dimension %d (%ld/%ld)",
1328 gfc_current_intrinsic_arg[1]->name,
1329 gfc_current_intrinsic, &shift->where, i + 1,
1330 mpz_get_si (array->shape[i]),
1331 mpz_get_si (shift->shape[j]));
1341 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1342 "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
1343 gfc_current_intrinsic, &shift->where, array->rank - 1);
1352 gfc_check_ctime (gfc_expr *time)
1354 if (scalar_check (time, 0) == FAILURE)
1357 if (type_check (time, 0, BT_INTEGER) == FAILURE)
1364 gfc_try gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
1366 if (double_check (y, 0) == FAILURE || double_check (x, 1) == FAILURE)
1373 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
1375 if (numeric_check (x, 0) == FAILURE)
1380 if (numeric_check (y, 1) == FAILURE)
1383 if (x->ts.type == BT_COMPLEX)
1385 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1386 "present if 'x' is COMPLEX",
1387 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1392 if (y->ts.type == BT_COMPLEX)
1394 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1395 "of either REAL or INTEGER",
1396 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1407 gfc_check_dble (gfc_expr *x)
1409 if (numeric_check (x, 0) == FAILURE)
1417 gfc_check_digits (gfc_expr *x)
1419 if (int_or_real_check (x, 0) == FAILURE)
1427 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
1429 switch (vector_a->ts.type)
1432 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
1439 if (numeric_check (vector_b, 1) == FAILURE)
1444 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1445 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
1446 gfc_current_intrinsic, &vector_a->where);
1450 if (rank_check (vector_a, 0, 1) == FAILURE)
1453 if (rank_check (vector_b, 1, 1) == FAILURE)
1456 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
1458 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1459 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0]->name,
1460 gfc_current_intrinsic_arg[1]->name, &vector_a->where);
1469 gfc_check_dprod (gfc_expr *x, gfc_expr *y)
1471 if (type_check (x, 0, BT_REAL) == FAILURE
1472 || type_check (y, 1, BT_REAL) == FAILURE)
1475 if (x->ts.kind != gfc_default_real_kind)
1477 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1478 "real", gfc_current_intrinsic_arg[0]->name,
1479 gfc_current_intrinsic, &x->where);
1483 if (y->ts.kind != gfc_default_real_kind)
1485 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1486 "real", gfc_current_intrinsic_arg[1]->name,
1487 gfc_current_intrinsic, &y->where);
1496 gfc_check_dshift (gfc_expr *i, gfc_expr *j, gfc_expr *shift)
1498 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1501 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1504 if (same_type_check (i, 0, j, 1) == FAILURE)
1507 if (type_check (shift, 2, BT_INTEGER) == FAILURE)
1510 if (nonnegative_check ("SHIFT", shift) == FAILURE)
1513 if (less_than_bitsize1 ("I", i, "SHIFT", shift, true) == FAILURE)
1521 gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
1524 if (array_check (array, 0) == FAILURE)
1527 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1530 if (dim_check (dim, 3, true) == FAILURE)
1533 if (dim_rank_check (dim, array, false) == FAILURE)
1536 if (array->rank == 1 || shift->rank == 0)
1538 if (scalar_check (shift, 1) == FAILURE)
1541 else if (shift->rank == array->rank - 1)
1546 else if (dim->expr_type == EXPR_CONSTANT)
1547 gfc_extract_int (dim, &d);
1554 for (i = 0, j = 0; i < array->rank; i++)
1557 if (!identical_dimen_shape (array, i, shift, j))
1559 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1560 "invalid shape in dimension %d (%ld/%ld)",
1561 gfc_current_intrinsic_arg[1]->name,
1562 gfc_current_intrinsic, &shift->where, i + 1,
1563 mpz_get_si (array->shape[i]),
1564 mpz_get_si (shift->shape[j]));
1574 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1575 "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
1576 gfc_current_intrinsic, &shift->where, array->rank - 1);
1580 if (boundary != NULL)
1582 if (same_type_check (array, 0, boundary, 2) == FAILURE)
1585 if (array->rank == 1 || boundary->rank == 0)
1587 if (scalar_check (boundary, 2) == FAILURE)
1590 else if (boundary->rank == array->rank - 1)
1592 if (gfc_check_conformance (shift, boundary,
1593 "arguments '%s' and '%s' for "
1595 gfc_current_intrinsic_arg[1]->name,
1596 gfc_current_intrinsic_arg[2]->name,
1597 gfc_current_intrinsic ) == FAILURE)
1602 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1603 "rank %d or be a scalar",
1604 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1605 &shift->where, array->rank - 1);
1614 gfc_check_float (gfc_expr *a)
1616 if (type_check (a, 0, BT_INTEGER) == FAILURE)
1619 if ((a->ts.kind != gfc_default_integer_kind)
1620 && gfc_notify_std (GFC_STD_GNU, "GNU extension: non-default INTEGER "
1621 "kind argument to %s intrinsic at %L",
1622 gfc_current_intrinsic, &a->where) == FAILURE )
1628 /* A single complex argument. */
1631 gfc_check_fn_c (gfc_expr *a)
1633 if (type_check (a, 0, BT_COMPLEX) == FAILURE)
1639 /* A single real argument. */
1642 gfc_check_fn_r (gfc_expr *a)
1644 if (type_check (a, 0, BT_REAL) == FAILURE)
1650 /* A single double argument. */
1653 gfc_check_fn_d (gfc_expr *a)
1655 if (double_check (a, 0) == FAILURE)
1661 /* A single real or complex argument. */
1664 gfc_check_fn_rc (gfc_expr *a)
1666 if (real_or_complex_check (a, 0) == FAILURE)
1674 gfc_check_fn_rc2008 (gfc_expr *a)
1676 if (real_or_complex_check (a, 0) == FAILURE)
1679 if (a->ts.type == BT_COMPLEX
1680 && gfc_notify_std (GFC_STD_F2008, "Fortran 2008: COMPLEX argument '%s' "
1681 "argument of '%s' intrinsic at %L",
1682 gfc_current_intrinsic_arg[0]->name,
1683 gfc_current_intrinsic, &a->where) == FAILURE)
1691 gfc_check_fnum (gfc_expr *unit)
1693 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
1696 if (scalar_check (unit, 0) == FAILURE)
1704 gfc_check_huge (gfc_expr *x)
1706 if (int_or_real_check (x, 0) == FAILURE)
1714 gfc_check_hypot (gfc_expr *x, gfc_expr *y)
1716 if (type_check (x, 0, BT_REAL) == FAILURE)
1718 if (same_type_check (x, 0, y, 1) == FAILURE)
1725 /* Check that the single argument is an integer. */
1728 gfc_check_i (gfc_expr *i)
1730 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1738 gfc_check_iand (gfc_expr *i, gfc_expr *j)
1740 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1743 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1746 if (i->ts.kind != j->ts.kind)
1748 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1749 &i->where) == FAILURE)
1758 gfc_check_ibits (gfc_expr *i, gfc_expr *pos, gfc_expr *len)
1760 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1763 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1766 if (type_check (len, 2, BT_INTEGER) == FAILURE)
1769 if (nonnegative_check ("pos", pos) == FAILURE)
1772 if (nonnegative_check ("len", len) == FAILURE)
1775 if (less_than_bitsize2 ("i", i, "pos", pos, "len", len) == FAILURE)
1783 gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
1787 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
1790 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1793 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1794 "with KIND argument at %L",
1795 gfc_current_intrinsic, &kind->where) == FAILURE)
1798 if (c->expr_type == EXPR_VARIABLE || c->expr_type == EXPR_SUBSTRING)
1804 /* Substring references don't have the charlength set. */
1806 while (ref && ref->type != REF_SUBSTRING)
1809 gcc_assert (ref == NULL || ref->type == REF_SUBSTRING);
1813 /* Check that the argument is length one. Non-constant lengths
1814 can't be checked here, so assume they are ok. */
1815 if (c->ts.u.cl && c->ts.u.cl->length)
1817 /* If we already have a length for this expression then use it. */
1818 if (c->ts.u.cl->length->expr_type != EXPR_CONSTANT)
1820 i = mpz_get_si (c->ts.u.cl->length->value.integer);
1827 start = ref->u.ss.start;
1828 end = ref->u.ss.end;
1831 if (end == NULL || end->expr_type != EXPR_CONSTANT
1832 || start->expr_type != EXPR_CONSTANT)
1835 i = mpz_get_si (end->value.integer) + 1
1836 - mpz_get_si (start->value.integer);
1844 gfc_error ("Argument of %s at %L must be of length one",
1845 gfc_current_intrinsic, &c->where);
1854 gfc_check_idnint (gfc_expr *a)
1856 if (double_check (a, 0) == FAILURE)
1864 gfc_check_ieor (gfc_expr *i, gfc_expr *j)
1866 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1869 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1872 if (i->ts.kind != j->ts.kind)
1874 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1875 &i->where) == FAILURE)
1884 gfc_check_index (gfc_expr *string, gfc_expr *substring, gfc_expr *back,
1887 if (type_check (string, 0, BT_CHARACTER) == FAILURE
1888 || type_check (substring, 1, BT_CHARACTER) == FAILURE)
1891 if (back != NULL && type_check (back, 2, BT_LOGICAL) == FAILURE)
1894 if (kind_check (kind, 3, 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)
1901 if (string->ts.kind != substring->ts.kind)
1903 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1904 "kind as '%s'", gfc_current_intrinsic_arg[1]->name,
1905 gfc_current_intrinsic, &substring->where,
1906 gfc_current_intrinsic_arg[0]->name);
1915 gfc_check_int (gfc_expr *x, gfc_expr *kind)
1917 if (numeric_check (x, 0) == FAILURE)
1920 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
1928 gfc_check_intconv (gfc_expr *x)
1930 if (numeric_check (x, 0) == FAILURE)
1938 gfc_check_ior (gfc_expr *i, gfc_expr *j)
1940 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1943 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1946 if (i->ts.kind != j->ts.kind)
1948 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
1949 &i->where) == FAILURE)
1958 gfc_check_ishft (gfc_expr *i, gfc_expr *shift)
1960 if (type_check (i, 0, BT_INTEGER) == FAILURE
1961 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1969 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1971 if (type_check (i, 0, BT_INTEGER) == FAILURE
1972 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1975 if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE)
1983 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
1985 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
1988 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
1996 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
1998 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
2001 if (scalar_check (pid, 0) == FAILURE)
2004 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
2007 if (scalar_check (sig, 1) == FAILURE)
2013 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2016 if (scalar_check (status, 2) == FAILURE)
2024 gfc_check_kind (gfc_expr *x)
2026 if (x->ts.type == BT_DERIVED)
2028 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
2029 "non-derived type", gfc_current_intrinsic_arg[0]->name,
2030 gfc_current_intrinsic, &x->where);
2039 gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2041 if (array_check (array, 0) == FAILURE)
2044 if (dim_check (dim, 1, false) == FAILURE)
2047 if (dim_rank_check (dim, array, 1) == FAILURE)
2050 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
2052 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2053 "with KIND argument at %L",
2054 gfc_current_intrinsic, &kind->where) == FAILURE)
2062 gfc_check_lcobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
2064 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
2066 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
2070 if (coarray_check (coarray, 0) == FAILURE)
2075 if (dim_check (dim, 1, false) == FAILURE)
2078 if (dim_corank_check (dim, coarray) == FAILURE)
2082 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
2090 gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
2092 if (type_check (s, 0, BT_CHARACTER) == FAILURE)
2095 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
2097 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2098 "with KIND argument at %L",
2099 gfc_current_intrinsic, &kind->where) == FAILURE)
2107 gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
2109 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2111 if (kind_value_check (a, 0, gfc_default_character_kind) == FAILURE)
2114 if (type_check (b, 1, BT_CHARACTER) == FAILURE)
2116 if (kind_value_check (b, 1, gfc_default_character_kind) == FAILURE)
2124 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
2126 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2128 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2131 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2133 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2141 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2143 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2145 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2148 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2150 if (kind_value_check (path2, 0, gfc_default_character_kind) == FAILURE)
2156 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2159 if (scalar_check (status, 2) == FAILURE)
2167 gfc_check_loc (gfc_expr *expr)
2169 return variable_check (expr, 0, true);
2174 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
2176 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2178 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2181 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2183 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2191 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2193 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2195 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2198 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2200 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2206 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2209 if (scalar_check (status, 2) == FAILURE)
2217 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
2219 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
2221 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
2228 /* Min/max family. */
2231 min_max_args (gfc_actual_arglist *arg)
2233 if (arg == NULL || arg->next == NULL)
2235 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
2236 gfc_current_intrinsic, gfc_current_intrinsic_where);
2245 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
2247 gfc_actual_arglist *arg, *tmp;
2252 if (min_max_args (arglist) == FAILURE)
2255 for (arg = arglist, n=1; arg; arg = arg->next, n++)
2258 if (x->ts.type != type || x->ts.kind != kind)
2260 if (x->ts.type == type)
2262 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
2263 "kinds at %L", &x->where) == FAILURE)
2268 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
2269 "%s(%d)", n, gfc_current_intrinsic, &x->where,
2270 gfc_basic_typename (type), kind);
2275 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
2276 if (gfc_check_conformance (tmp->expr, x,
2277 "arguments 'a%d' and 'a%d' for "
2278 "intrinsic '%s'", m, n,
2279 gfc_current_intrinsic) == FAILURE)
2288 gfc_check_min_max (gfc_actual_arglist *arg)
2292 if (min_max_args (arg) == FAILURE)
2297 if (x->ts.type == BT_CHARACTER)
2299 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2300 "with CHARACTER argument at %L",
2301 gfc_current_intrinsic, &x->where) == FAILURE)
2304 else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
2306 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
2307 "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
2311 return check_rest (x->ts.type, x->ts.kind, arg);
2316 gfc_check_min_max_integer (gfc_actual_arglist *arg)
2318 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
2323 gfc_check_min_max_real (gfc_actual_arglist *arg)
2325 return check_rest (BT_REAL, gfc_default_real_kind, arg);
2330 gfc_check_min_max_double (gfc_actual_arglist *arg)
2332 return check_rest (BT_REAL, gfc_default_double_kind, arg);
2336 /* End of min/max family. */
2339 gfc_check_malloc (gfc_expr *size)
2341 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2344 if (scalar_check (size, 0) == FAILURE)
2352 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
2354 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
2356 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2357 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
2358 gfc_current_intrinsic, &matrix_a->where);
2362 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
2364 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2365 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
2366 gfc_current_intrinsic, &matrix_b->where);
2370 if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
2371 || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
2373 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2374 gfc_current_intrinsic, &matrix_a->where,
2375 gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
2379 switch (matrix_a->rank)
2382 if (rank_check (matrix_b, 1, 2) == FAILURE)
2384 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2385 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
2387 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2388 "and '%s' at %L for intrinsic matmul",
2389 gfc_current_intrinsic_arg[0]->name,
2390 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
2396 if (matrix_b->rank != 2)
2398 if (rank_check (matrix_b, 1, 1) == FAILURE)
2401 /* matrix_b has rank 1 or 2 here. Common check for the cases
2402 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2403 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2404 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
2406 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2407 "dimension 1 for argument '%s' at %L for intrinsic "
2408 "matmul", gfc_current_intrinsic_arg[0]->name,
2409 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
2415 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2416 "1 or 2", gfc_current_intrinsic_arg[0]->name,
2417 gfc_current_intrinsic, &matrix_a->where);
2425 /* Whoever came up with this interface was probably on something.
2426 The possibilities for the occupation of the second and third
2433 NULL MASK minloc(array, mask=m)
2436 I.e. in the case of minloc(array,mask), mask will be in the second
2437 position of the argument list and we'll have to fix that up. */
2440 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
2442 gfc_expr *a, *m, *d;
2445 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
2449 m = ap->next->next->expr;
2451 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2452 && ap->next->name == NULL)
2456 ap->next->expr = NULL;
2457 ap->next->next->expr = m;
2460 if (dim_check (d, 1, false) == FAILURE)
2463 if (dim_rank_check (d, a, 0) == FAILURE)
2466 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2470 && gfc_check_conformance (a, m,
2471 "arguments '%s' and '%s' for intrinsic %s",
2472 gfc_current_intrinsic_arg[0]->name,
2473 gfc_current_intrinsic_arg[2]->name,
2474 gfc_current_intrinsic ) == FAILURE)
2481 /* Similar to minloc/maxloc, the argument list might need to be
2482 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2483 difference is that MINLOC/MAXLOC take an additional KIND argument.
2484 The possibilities are:
2490 NULL MASK minval(array, mask=m)
2493 I.e. in the case of minval(array,mask), mask will be in the second
2494 position of the argument list and we'll have to fix that up. */
2497 check_reduction (gfc_actual_arglist *ap)
2499 gfc_expr *a, *m, *d;
2503 m = ap->next->next->expr;
2505 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2506 && ap->next->name == NULL)
2510 ap->next->expr = NULL;
2511 ap->next->next->expr = m;
2514 if (dim_check (d, 1, false) == FAILURE)
2517 if (dim_rank_check (d, a, 0) == FAILURE)
2520 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2524 && gfc_check_conformance (a, m,
2525 "arguments '%s' and '%s' for intrinsic %s",
2526 gfc_current_intrinsic_arg[0]->name,
2527 gfc_current_intrinsic_arg[2]->name,
2528 gfc_current_intrinsic) == FAILURE)
2536 gfc_check_minval_maxval (gfc_actual_arglist *ap)
2538 if (int_or_real_check (ap->expr, 0) == FAILURE
2539 || array_check (ap->expr, 0) == FAILURE)
2542 return check_reduction (ap);
2547 gfc_check_product_sum (gfc_actual_arglist *ap)
2549 if (numeric_check (ap->expr, 0) == FAILURE
2550 || array_check (ap->expr, 0) == FAILURE)
2553 return check_reduction (ap);
2557 /* For IANY, IALL and IPARITY. */
2560 gfc_check_mask (gfc_expr *i, gfc_expr *kind)
2564 if (type_check (i, 0, BT_INTEGER) == FAILURE)
2567 if (nonnegative_check ("I", i) == FAILURE)
2570 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
2574 gfc_extract_int (kind, &k);
2576 k = gfc_default_integer_kind;
2578 if (less_than_bitsizekind ("I", i, k) == FAILURE)
2586 gfc_check_transf_bit_intrins (gfc_actual_arglist *ap)
2588 if (ap->expr->ts.type != BT_INTEGER)
2590 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER",
2591 gfc_current_intrinsic_arg[0]->name,
2592 gfc_current_intrinsic, &ap->expr->where);
2596 if (array_check (ap->expr, 0) == FAILURE)
2599 return check_reduction (ap);
2604 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
2606 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
2609 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
2612 if (tsource->ts.type == BT_CHARACTER)
2613 return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
2620 gfc_check_merge_bits (gfc_expr *i, gfc_expr *j, gfc_expr *mask)
2622 if (type_check (i, 0, BT_INTEGER) == FAILURE)
2625 if (type_check (j, 1, BT_INTEGER) == FAILURE)
2628 if (type_check (mask, 2, BT_INTEGER) == FAILURE)
2631 if (same_type_check (i, 0, j, 1) == FAILURE)
2634 if (same_type_check (i, 0, mask, 2) == FAILURE)
2642 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
2644 if (variable_check (from, 0, false) == FAILURE)
2646 if (allocatable_check (from, 0) == FAILURE)
2649 if (variable_check (to, 1, false) == FAILURE)
2651 if (allocatable_check (to, 1) == FAILURE)
2654 if (same_type_check (to, 1, from, 0) == FAILURE)
2657 if (to->rank != from->rank)
2659 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2660 "have the same rank %d/%d", gfc_current_intrinsic_arg[0]->name,
2661 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2662 &to->where, from->rank, to->rank);
2666 if (to->ts.kind != from->ts.kind)
2668 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2669 "be of the same kind %d/%d",
2670 gfc_current_intrinsic_arg[0]->name,
2671 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2672 &to->where, from->ts.kind, to->ts.kind);
2676 /* CLASS arguments: Make sure the vtab is present. */
2677 if (to->ts.type == BT_CLASS)
2678 gfc_find_derived_vtab (from->ts.u.derived);
2685 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
2687 if (type_check (x, 0, BT_REAL) == FAILURE)
2690 if (type_check (s, 1, BT_REAL) == FAILURE)
2698 gfc_check_new_line (gfc_expr *a)
2700 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2708 gfc_check_norm2 (gfc_expr *array, gfc_expr *dim)
2710 if (type_check (array, 0, BT_REAL) == FAILURE)
2713 if (array_check (array, 0) == FAILURE)
2716 if (dim_rank_check (dim, array, false) == FAILURE)
2723 gfc_check_null (gfc_expr *mold)
2725 symbol_attribute attr;
2730 if (variable_check (mold, 0, true) == FAILURE)
2733 attr = gfc_variable_attr (mold, NULL);
2735 if (!attr.pointer && !attr.proc_pointer && !attr.allocatable)
2737 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER, "
2738 "ALLOCATABLE or procedure pointer",
2739 gfc_current_intrinsic_arg[0]->name,
2740 gfc_current_intrinsic, &mold->where);
2744 if (attr.allocatable
2745 && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: NULL intrinsic with "
2746 "allocatable MOLD at %L", &mold->where) == FAILURE)
2750 if (gfc_is_coindexed (mold))
2752 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
2753 "conindexed", gfc_current_intrinsic_arg[0]->name,
2754 gfc_current_intrinsic, &mold->where);
2763 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
2765 if (array_check (array, 0) == FAILURE)
2768 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2771 if (gfc_check_conformance (array, mask,
2772 "arguments '%s' and '%s' for intrinsic '%s'",
2773 gfc_current_intrinsic_arg[0]->name,
2774 gfc_current_intrinsic_arg[1]->name,
2775 gfc_current_intrinsic) == FAILURE)
2780 mpz_t array_size, vector_size;
2781 bool have_array_size, have_vector_size;
2783 if (same_type_check (array, 0, vector, 2) == FAILURE)
2786 if (rank_check (vector, 2, 1) == FAILURE)
2789 /* VECTOR requires at least as many elements as MASK
2790 has .TRUE. values. */
2791 have_array_size = gfc_array_size (array, &array_size) == SUCCESS;
2792 have_vector_size = gfc_array_size (vector, &vector_size) == SUCCESS;
2794 if (have_vector_size
2795 && (mask->expr_type == EXPR_ARRAY
2796 || (mask->expr_type == EXPR_CONSTANT
2797 && have_array_size)))
2799 int mask_true_values = 0;
2801 if (mask->expr_type == EXPR_ARRAY)
2803 gfc_constructor *mask_ctor;
2804 mask_ctor = gfc_constructor_first (mask->value.constructor);
2807 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
2809 mask_true_values = 0;
2813 if (mask_ctor->expr->value.logical)
2816 mask_ctor = gfc_constructor_next (mask_ctor);
2819 else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
2820 mask_true_values = mpz_get_si (array_size);
2822 if (mpz_get_si (vector_size) < mask_true_values)
2824 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2825 "provide at least as many elements as there "
2826 "are .TRUE. values in '%s' (%ld/%d)",
2827 gfc_current_intrinsic_arg[2]->name,
2828 gfc_current_intrinsic, &vector->where,
2829 gfc_current_intrinsic_arg[1]->name,
2830 mpz_get_si (vector_size), mask_true_values);
2835 if (have_array_size)
2836 mpz_clear (array_size);
2837 if (have_vector_size)
2838 mpz_clear (vector_size);
2846 gfc_check_parity (gfc_expr *mask, gfc_expr *dim)
2848 if (type_check (mask, 0, BT_LOGICAL) == FAILURE)
2851 if (array_check (mask, 0) == FAILURE)
2854 if (dim_rank_check (dim, mask, false) == FAILURE)
2862 gfc_check_precision (gfc_expr *x)
2864 if (real_or_complex_check (x, 0) == FAILURE)
2872 gfc_check_present (gfc_expr *a)
2876 if (variable_check (a, 0, true) == FAILURE)
2879 sym = a->symtree->n.sym;
2880 if (!sym->attr.dummy)
2882 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2883 "dummy variable", gfc_current_intrinsic_arg[0]->name,
2884 gfc_current_intrinsic, &a->where);
2888 if (!sym->attr.optional)
2890 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2891 "an OPTIONAL dummy variable",
2892 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2897 /* 13.14.82 PRESENT(A)
2899 Argument. A shall be the name of an optional dummy argument that is
2900 accessible in the subprogram in which the PRESENT function reference
2904 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2905 && (a->ref->u.ar.type == AR_FULL
2906 || (a->ref->u.ar.type == AR_ELEMENT
2907 && a->ref->u.ar.as->rank == 0))))
2909 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2910 "subobject of '%s'", gfc_current_intrinsic_arg[0]->name,
2911 gfc_current_intrinsic, &a->where, sym->name);
2920 gfc_check_radix (gfc_expr *x)
2922 if (int_or_real_check (x, 0) == FAILURE)
2930 gfc_check_range (gfc_expr *x)
2932 if (numeric_check (x, 0) == FAILURE)
2940 gfc_check_rank (gfc_expr *a ATTRIBUTE_UNUSED)
2942 /* Any data object is allowed; a "data object" is a "constant (4.1.3),
2943 variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
2945 bool is_variable = true;
2947 /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
2948 if (a->expr_type == EXPR_FUNCTION)
2949 is_variable = a->value.function.esym
2950 ? a->value.function.esym->result->attr.pointer
2951 : a->symtree->n.sym->result->attr.pointer;
2953 if (a->expr_type == EXPR_OP || a->expr_type == EXPR_NULL
2954 || a->expr_type == EXPR_COMPCALL|| a->expr_type == EXPR_PPC
2957 gfc_error ("The argument of the RANK intrinsic at %L must be a data "
2958 "object", &a->where);
2966 /* real, float, sngl. */
2968 gfc_check_real (gfc_expr *a, gfc_expr *kind)
2970 if (numeric_check (a, 0) == FAILURE)
2973 if (kind_check (kind, 1, BT_REAL) == FAILURE)
2981 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
2983 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2985 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2988 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2990 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2998 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
3000 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
3002 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
3005 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
3007 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
3013 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3016 if (scalar_check (status, 2) == FAILURE)
3024 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
3026 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3029 if (scalar_check (x, 0) == FAILURE)
3032 if (type_check (y, 0, BT_INTEGER) == FAILURE)
3035 if (scalar_check (y, 1) == FAILURE)
3043 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
3044 gfc_expr *pad, gfc_expr *order)
3050 if (array_check (source, 0) == FAILURE)
3053 if (rank_check (shape, 1, 1) == FAILURE)
3056 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
3059 if (gfc_array_size (shape, &size) != SUCCESS)
3061 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
3062 "array of constant size", &shape->where);
3066 shape_size = mpz_get_ui (size);
3069 if (shape_size <= 0)
3071 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
3072 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3076 else if (shape_size > GFC_MAX_DIMENSIONS)
3078 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
3079 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
3082 else if (shape->expr_type == EXPR_ARRAY)
3086 for (i = 0; i < shape_size; ++i)
3088 e = gfc_constructor_lookup_expr (shape->value.constructor, i);
3089 if (e->expr_type != EXPR_CONSTANT)
3092 gfc_extract_int (e, &extent);
3095 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3096 "negative element (%d)",
3097 gfc_current_intrinsic_arg[1]->name,
3098 gfc_current_intrinsic, &e->where, extent);
3106 if (same_type_check (source, 0, pad, 2) == FAILURE)
3109 if (array_check (pad, 2) == FAILURE)
3115 if (array_check (order, 3) == FAILURE)
3118 if (type_check (order, 3, BT_INTEGER) == FAILURE)
3121 if (order->expr_type == EXPR_ARRAY)
3123 int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
3126 for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
3129 gfc_array_size (order, &size);
3130 order_size = mpz_get_ui (size);
3133 if (order_size != shape_size)
3135 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3136 "has wrong number of elements (%d/%d)",
3137 gfc_current_intrinsic_arg[3]->name,
3138 gfc_current_intrinsic, &order->where,
3139 order_size, shape_size);
3143 for (i = 1; i <= order_size; ++i)
3145 e = gfc_constructor_lookup_expr (order->value.constructor, i-1);
3146 if (e->expr_type != EXPR_CONSTANT)
3149 gfc_extract_int (e, &dim);
3151 if (dim < 1 || dim > order_size)
3153 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3154 "has out-of-range dimension (%d)",
3155 gfc_current_intrinsic_arg[3]->name,
3156 gfc_current_intrinsic, &e->where, dim);
3160 if (perm[dim-1] != 0)
3162 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3163 "invalid permutation of dimensions (dimension "
3165 gfc_current_intrinsic_arg[3]->name,
3166 gfc_current_intrinsic, &e->where, dim);
3175 if (pad == NULL && shape->expr_type == EXPR_ARRAY
3176 && gfc_is_constant_expr (shape)
3177 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
3178 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
3180 /* Check the match in size between source and destination. */
3181 if (gfc_array_size (source, &nelems) == SUCCESS)
3187 mpz_init_set_ui (size, 1);
3188 for (c = gfc_constructor_first (shape->value.constructor);
3189 c; c = gfc_constructor_next (c))
3190 mpz_mul (size, size, c->expr->value.integer);
3192 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
3198 gfc_error ("Without padding, there are not enough elements "
3199 "in the intrinsic RESHAPE source at %L to match "
3200 "the shape", &source->where);
3211 gfc_check_same_type_as (gfc_expr *a, gfc_expr *b)
3214 if (a->ts.type != BT_DERIVED && a->ts.type != BT_CLASS)
3216 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3217 "must be of a derived type",
3218 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3223 if (!gfc_type_is_extensible (a->ts.u.derived))
3225 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3226 "must be of an extensible type",
3227 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3232 if (b->ts.type != BT_DERIVED && b->ts.type != BT_CLASS)
3234 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3235 "must be of a derived type",
3236 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3241 if (!gfc_type_is_extensible (b->ts.u.derived))
3243 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3244 "must be of an extensible type",
3245 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3255 gfc_check_scale (gfc_expr *x, gfc_expr *i)
3257 if (type_check (x, 0, BT_REAL) == FAILURE)
3260 if (type_check (i, 1, BT_INTEGER) == FAILURE)
3268 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
3270 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3273 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
3276 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
3279 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
3281 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3282 "with KIND argument at %L",
3283 gfc_current_intrinsic, &kind->where) == FAILURE)
3286 if (same_type_check (x, 0, y, 1) == FAILURE)
3294 gfc_check_secnds (gfc_expr *r)
3296 if (type_check (r, 0, BT_REAL) == FAILURE)
3299 if (kind_value_check (r, 0, 4) == FAILURE)
3302 if (scalar_check (r, 0) == FAILURE)
3310 gfc_check_selected_char_kind (gfc_expr *name)
3312 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3315 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3318 if (scalar_check (name, 0) == FAILURE)
3326 gfc_check_selected_int_kind (gfc_expr *r)
3328 if (type_check (r, 0, BT_INTEGER) == FAILURE)
3331 if (scalar_check (r, 0) == FAILURE)
3339 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r, gfc_expr *radix)
3341 if (p == NULL && r == NULL
3342 && gfc_notify_std (GFC_STD_F2008, "Fortran 2008: SELECTED_REAL_KIND with"
3343 " neither 'P' nor 'R' argument at %L",
3344 gfc_current_intrinsic_where) == FAILURE)
3349 if (type_check (p, 0, BT_INTEGER) == FAILURE)
3352 if (scalar_check (p, 0) == FAILURE)
3358 if (type_check (r, 1, BT_INTEGER) == FAILURE)
3361 if (scalar_check (r, 1) == FAILURE)
3367 if (type_check (radix, 1, BT_INTEGER) == FAILURE)
3370 if (scalar_check (radix, 1) == FAILURE)
3373 if (gfc_notify_std (GFC_STD_F2008, "Fortran 2008: '%s' intrinsic with "
3374 "RADIX argument at %L", gfc_current_intrinsic,
3375 &radix->where) == FAILURE)
3384 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
3386 if (type_check (x, 0, BT_REAL) == FAILURE)
3389 if (type_check (i, 1, BT_INTEGER) == FAILURE)
3397 gfc_check_shape (gfc_expr *source, gfc_expr *kind)
3401 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
3404 ar = gfc_find_array_ref (source);
3406 if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
3408 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
3409 "an assumed size array", &source->where);
3413 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
3415 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3416 "with KIND argument at %L",
3417 gfc_current_intrinsic, &kind->where) == FAILURE)
3425 gfc_check_shift (gfc_expr *i, gfc_expr *shift)
3427 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3430 if (type_check (shift, 0, BT_INTEGER) == FAILURE)
3433 if (nonnegative_check ("SHIFT", shift) == FAILURE)
3436 if (less_than_bitsize1 ("I", i, "SHIFT", shift, true) == FAILURE)
3444 gfc_check_sign (gfc_expr *a, gfc_expr *b)
3446 if (int_or_real_check (a, 0) == FAILURE)
3449 if (same_type_check (a, 0, b, 1) == FAILURE)
3457 gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3459 if (array_check (array, 0) == FAILURE)
3462 if (dim_check (dim, 1, true) == FAILURE)
3465 if (dim_rank_check (dim, array, 0) == FAILURE)
3468 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3470 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3471 "with KIND argument at %L",
3472 gfc_current_intrinsic, &kind->where) == FAILURE)
3481 gfc_check_sizeof (gfc_expr *arg ATTRIBUTE_UNUSED)
3488 gfc_check_c_sizeof (gfc_expr *arg)
3490 if (verify_c_interop (&arg->ts) != SUCCESS)
3492 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an "
3493 "interoperable data entity",
3494 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3503 gfc_check_sleep_sub (gfc_expr *seconds)
3505 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3508 if (scalar_check (seconds, 0) == FAILURE)
3515 gfc_check_sngl (gfc_expr *a)
3517 if (type_check (a, 0, BT_REAL) == FAILURE)
3520 if ((a->ts.kind != gfc_default_double_kind)
3521 && gfc_notify_std (GFC_STD_GNU, "GNU extension: non double precision "
3522 "REAL argument to %s intrinsic at %L",
3523 gfc_current_intrinsic, &a->where) == FAILURE)
3530 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
3532 if (source->rank >= GFC_MAX_DIMENSIONS)
3534 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
3535 "than rank %d", gfc_current_intrinsic_arg[0]->name,
3536 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
3544 if (dim_check (dim, 1, false) == FAILURE)
3547 /* dim_rank_check() does not apply here. */
3549 && dim->expr_type == EXPR_CONSTANT
3550 && (mpz_cmp_ui (dim->value.integer, 1) < 0
3551 || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0))
3553 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
3554 "dimension index", gfc_current_intrinsic_arg[1]->name,
3555 gfc_current_intrinsic, &dim->where);
3559 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
3562 if (scalar_check (ncopies, 2) == FAILURE)
3569 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3573 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
3575 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3578 if (scalar_check (unit, 0) == FAILURE)
3581 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
3583 if (kind_value_check (c, 1, gfc_default_character_kind) == FAILURE)
3589 if (type_check (status, 2, BT_INTEGER) == FAILURE
3590 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
3591 || scalar_check (status, 2) == FAILURE)
3599 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
3601 return gfc_check_fgetputc_sub (unit, c, NULL);
3606 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
3608 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
3610 if (kind_value_check (c, 0, gfc_default_character_kind) == FAILURE)
3616 if (type_check (status, 1, BT_INTEGER) == FAILURE
3617 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
3618 || scalar_check (status, 1) == FAILURE)
3626 gfc_check_fgetput (gfc_expr *c)
3628 return gfc_check_fgetput_sub (c, NULL);
3633 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
3635 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3638 if (scalar_check (unit, 0) == FAILURE)
3641 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3644 if (scalar_check (offset, 1) == FAILURE)
3647 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
3650 if (scalar_check (whence, 2) == FAILURE)
3656 if (type_check (status, 3, BT_INTEGER) == FAILURE)
3659 if (kind_value_check (status, 3, 4) == FAILURE)
3662 if (scalar_check (status, 3) == FAILURE)
3671 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
3673 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3676 if (scalar_check (unit, 0) == FAILURE)
3679 if (type_check (array, 1, BT_INTEGER) == FAILURE
3680 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
3683 if (array_check (array, 1) == FAILURE)
3691 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
3693 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3696 if (scalar_check (unit, 0) == FAILURE)
3699 if (type_check (array, 1, BT_INTEGER) == FAILURE
3700 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3703 if (array_check (array, 1) == FAILURE)
3709 if (type_check (status, 2, BT_INTEGER) == FAILURE
3710 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3713 if (scalar_check (status, 2) == FAILURE)
3721 gfc_check_ftell (gfc_expr *unit)
3723 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3726 if (scalar_check (unit, 0) == FAILURE)
3734 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
3736 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3739 if (scalar_check (unit, 0) == FAILURE)
3742 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3745 if (scalar_check (offset, 1) == FAILURE)
3753 gfc_check_stat (gfc_expr *name, gfc_expr *array)
3755 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3757 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3760 if (type_check (array, 1, BT_INTEGER) == FAILURE
3761 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3764 if (array_check (array, 1) == FAILURE)
3772 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
3774 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3776 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3779 if (type_check (array, 1, BT_INTEGER) == FAILURE
3780 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3783 if (array_check (array, 1) == FAILURE)
3789 if (type_check (status, 2, BT_INTEGER) == FAILURE
3790 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3793 if (scalar_check (status, 2) == FAILURE)
3801 gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub)
3805 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3807 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3811 if (coarray_check (coarray, 0) == FAILURE)
3816 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3817 gfc_current_intrinsic_arg[1]->name, &sub->where);
3821 if (gfc_array_size (sub, &nelems) == SUCCESS)
3823 int corank = gfc_get_corank (coarray);
3825 if (mpz_cmp_ui (nelems, corank) != 0)
3827 gfc_error ("The number of array elements of the SUB argument to "
3828 "IMAGE_INDEX at %L shall be %d (corank) not %d",
3829 &sub->where, corank, (int) mpz_get_si (nelems));
3841 gfc_check_this_image (gfc_expr *coarray, gfc_expr *dim)
3843 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3845 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3849 if (dim != NULL && coarray == NULL)
3851 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3852 "intrinsic at %L", &dim->where);
3856 if (coarray == NULL)
3859 if (coarray_check (coarray, 0) == FAILURE)
3864 if (dim_check (dim, 1, false) == FAILURE)
3867 if (dim_corank_check (dim, coarray) == FAILURE)
3874 /* Calculate the sizes for transfer, used by gfc_check_transfer and also
3875 by gfc_simplify_transfer. Return FAILURE if we cannot do so. */
3878 gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size,
3879 size_t *source_size, size_t *result_size,
3880 size_t *result_length_p)
3883 size_t result_elt_size;
3885 gfc_expr *mold_element;
3887 if (source->expr_type == EXPR_FUNCTION)
3890 /* Calculate the size of the source. */
3891 if (source->expr_type == EXPR_ARRAY
3892 && gfc_array_size (source, &tmp) == FAILURE)
3895 *source_size = gfc_target_expr_size (source);
3897 mold_element = mold->expr_type == EXPR_ARRAY
3898 ? gfc_constructor_first (mold->value.constructor)->expr
3901 /* Determine the size of the element. */
3902 result_elt_size = gfc_target_expr_size (mold_element);
3903 if (result_elt_size == 0)
3906 if (mold->expr_type == EXPR_ARRAY || mold->rank || size)
3911 result_length = (size_t)mpz_get_ui (size->value.integer);
3914 result_length = *source_size / result_elt_size;
3915 if (result_length * result_elt_size < *source_size)
3919 *result_size = result_length * result_elt_size;
3920 if (result_length_p)
3921 *result_length_p = result_length;
3924 *result_size = result_elt_size;
3931 gfc_check_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size)
3936 if (mold->ts.type == BT_HOLLERITH)
3938 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3939 &mold->where, gfc_basic_typename (BT_HOLLERITH));
3945 if (type_check (size, 2, BT_INTEGER) == FAILURE)
3948 if (scalar_check (size, 2) == FAILURE)
3951 if (nonoptional_check (size, 2) == FAILURE)
3955 if (!gfc_option.warn_surprising)
3958 /* If we can't calculate the sizes, we cannot check any more.
3959 Return SUCCESS for that case. */
3961 if (gfc_calculate_transfer_sizes (source, mold, size, &source_size,
3962 &result_size, NULL) == FAILURE)
3965 if (source_size < result_size)
3966 gfc_warning("Intrinsic TRANSFER at %L has partly undefined result: "
3967 "source size %ld < result size %ld", &source->where,
3968 (long) source_size, (long) result_size);
3975 gfc_check_transpose (gfc_expr *matrix)
3977 if (rank_check (matrix, 0, 2) == FAILURE)
3985 gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3987 if (array_check (array, 0) == FAILURE)
3990 if (dim_check (dim, 1, false) == FAILURE)
3993 if (dim_rank_check (dim, array, 0) == FAILURE)
3996 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3998 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3999 "with KIND argument at %L",
4000 gfc_current_intrinsic, &kind->where) == FAILURE)
4008 gfc_check_ucobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
4010 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
4012 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
4016 if (coarray_check (coarray, 0) == FAILURE)
4021 if (dim_check (dim, 1, false) == FAILURE)
4024 if (dim_corank_check (dim, coarray) == FAILURE)
4028 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
4036 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
4040 if (rank_check (vector, 0, 1) == FAILURE)
4043 if (array_check (mask, 1) == FAILURE)
4046 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
4049 if (same_type_check (vector, 0, field, 2) == FAILURE)
4052 if (mask->expr_type == EXPR_ARRAY
4053 && gfc_array_size (vector, &vector_size) == SUCCESS)
4055 int mask_true_count = 0;
4056 gfc_constructor *mask_ctor;
4057 mask_ctor = gfc_constructor_first (mask->value.constructor);
4060 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
4062 mask_true_count = 0;
4066 if (mask_ctor->expr->value.logical)
4069 mask_ctor = gfc_constructor_next (mask_ctor);
4072 if (mpz_get_si (vector_size) < mask_true_count)
4074 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
4075 "provide at least as many elements as there "
4076 "are .TRUE. values in '%s' (%ld/%d)",
4077 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4078 &vector->where, gfc_current_intrinsic_arg[1]->name,
4079 mpz_get_si (vector_size), mask_true_count);
4083 mpz_clear (vector_size);
4086 if (mask->rank != field->rank && field->rank != 0)
4088 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
4089 "the same rank as '%s' or be a scalar",
4090 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
4091 &field->where, gfc_current_intrinsic_arg[1]->name);
4095 if (mask->rank == field->rank)
4098 for (i = 0; i < field->rank; i++)
4099 if (! identical_dimen_shape (mask, i, field, i))
4101 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
4102 "must have identical shape.",
4103 gfc_current_intrinsic_arg[2]->name,
4104 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4114 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
4116 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
4119 if (same_type_check (x, 0, y, 1) == FAILURE)
4122 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
4125 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
4127 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
4128 "with KIND argument at %L",
4129 gfc_current_intrinsic, &kind->where) == FAILURE)
4137 gfc_check_trim (gfc_expr *x)
4139 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
4142 if (scalar_check (x, 0) == FAILURE)
4150 gfc_check_ttynam (gfc_expr *unit)
4152 if (scalar_check (unit, 0) == FAILURE)
4155 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4162 /* Common check function for the half a dozen intrinsics that have a
4163 single real argument. */
4166 gfc_check_x (gfc_expr *x)
4168 if (type_check (x, 0, BT_REAL) == FAILURE)
4175 /************* Check functions for intrinsic subroutines *************/
4178 gfc_check_cpu_time (gfc_expr *time)
4180 if (scalar_check (time, 0) == FAILURE)
4183 if (type_check (time, 0, BT_REAL) == FAILURE)
4186 if (variable_check (time, 0, false) == FAILURE)
4194 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
4195 gfc_expr *zone, gfc_expr *values)
4199 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
4201 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
4203 if (scalar_check (date, 0) == FAILURE)
4205 if (variable_check (date, 0, false) == FAILURE)
4211 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
4213 if (kind_value_check (time, 1, gfc_default_character_kind) == FAILURE)
4215 if (scalar_check (time, 1) == FAILURE)
4217 if (variable_check (time, 1, false) == FAILURE)
4223 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
4225 if (kind_value_check (zone, 2, gfc_default_character_kind) == FAILURE)
4227 if (scalar_check (zone, 2) == FAILURE)
4229 if (variable_check (zone, 2, false) == FAILURE)
4235 if (type_check (values, 3, BT_INTEGER) == FAILURE)
4237 if (array_check (values, 3) == FAILURE)
4239 if (rank_check (values, 3, 1) == FAILURE)
4241 if (variable_check (values, 3, false) == FAILURE)
4250 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
4251 gfc_expr *to, gfc_expr *topos)
4253 if (type_check (from, 0, BT_INTEGER) == FAILURE)
4256 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
4259 if (type_check (len, 2, BT_INTEGER) == FAILURE)
4262 if (same_type_check (from, 0, to, 3) == FAILURE)
4265 if (variable_check (to, 3, false) == FAILURE)
4268 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
4271 if (nonnegative_check ("frompos", frompos) == FAILURE)
4274 if (nonnegative_check ("topos", topos) == FAILURE)
4277 if (nonnegative_check ("len", len) == FAILURE)
4280 if (less_than_bitsize2 ("from", from, "frompos", frompos, "len", len)
4284 if (less_than_bitsize2 ("to", to, "topos", topos, "len", len) == FAILURE)
4292 gfc_check_random_number (gfc_expr *harvest)
4294 if (type_check (harvest, 0, BT_REAL) == FAILURE)
4297 if (variable_check (harvest, 0, false) == FAILURE)
4305 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
4307 unsigned int nargs = 0, kiss_size;
4308 locus *where = NULL;
4309 mpz_t put_size, get_size;
4310 bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
4312 have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
4314 /* Keep the number of bytes in sync with kiss_size in
4315 libgfortran/intrinsics/random.c. */
4316 kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind;
4320 if (size->expr_type != EXPR_VARIABLE
4321 || !size->symtree->n.sym->attr.optional)
4324 if (scalar_check (size, 0) == FAILURE)
4327 if (type_check (size, 0, BT_INTEGER) == FAILURE)
4330 if (variable_check (size, 0, false) == FAILURE)
4333 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
4339 if (put->expr_type != EXPR_VARIABLE
4340 || !put->symtree->n.sym->attr.optional)
4343 where = &put->where;
4346 if (array_check (put, 1) == FAILURE)
4349 if (rank_check (put, 1, 1) == FAILURE)
4352 if (type_check (put, 1, BT_INTEGER) == FAILURE)
4355 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
4358 if (gfc_array_size (put, &put_size) == SUCCESS
4359 && mpz_get_ui (put_size) < kiss_size)
4360 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4361 "too small (%i/%i)",
4362 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4363 where, (int) mpz_get_ui (put_size), kiss_size);
4368 if (get->expr_type != EXPR_VARIABLE
4369 || !get->symtree->n.sym->attr.optional)
4372 where = &get->where;
4375 if (array_check (get, 2) == FAILURE)
4378 if (rank_check (get, 2, 1) == FAILURE)
4381 if (type_check (get, 2, BT_INTEGER) == FAILURE)
4384 if (variable_check (get, 2, false) == FAILURE)
4387 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
4390 if (gfc_array_size (get, &get_size) == SUCCESS
4391 && mpz_get_ui (get_size) < kiss_size)
4392 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4393 "too small (%i/%i)",
4394 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
4395 where, (int) mpz_get_ui (get_size), kiss_size);
4398 /* RANDOM_SEED may not have more than one non-optional argument. */
4400 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
4407 gfc_check_second_sub (gfc_expr *time)
4409 if (scalar_check (time, 0) == FAILURE)
4412 if (type_check (time, 0, BT_REAL) == FAILURE)
4415 if (kind_value_check(time, 0, 4) == FAILURE)
4422 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
4423 count, count_rate, and count_max are all optional arguments */
4426 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
4427 gfc_expr *count_max)
4431 if (scalar_check (count, 0) == FAILURE)
4434 if (type_check (count, 0, BT_INTEGER) == FAILURE)
4437 if (variable_check (count, 0, false) == FAILURE)
4441 if (count_rate != NULL)
4443 if (scalar_check (count_rate, 1) == FAILURE)
4446 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
4449 if (variable_check (count_rate, 1, false) == FAILURE)
4453 && same_type_check (count, 0, count_rate, 1) == FAILURE)
4458 if (count_max != NULL)
4460 if (scalar_check (count_max, 2) == FAILURE)
4463 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
4466 if (variable_check (count_max, 2, false) == FAILURE)
4470 && same_type_check (count, 0, count_max, 2) == FAILURE)
4473 if (count_rate != NULL
4474 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
4483 gfc_check_irand (gfc_expr *x)
4488 if (scalar_check (x, 0) == FAILURE)
4491 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4494 if (kind_value_check(x, 0, 4) == FAILURE)
4502 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
4504 if (scalar_check (seconds, 0) == FAILURE)
4506 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
4509 if (int_or_proc_check (handler, 1) == FAILURE)
4511 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4517 if (scalar_check (status, 2) == FAILURE)
4519 if (type_check (status, 2, BT_INTEGER) == FAILURE)
4521 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
4529 gfc_check_rand (gfc_expr *x)
4534 if (scalar_check (x, 0) == FAILURE)
4537 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4540 if (kind_value_check(x, 0, 4) == FAILURE)
4548 gfc_check_srand (gfc_expr *x)
4550 if (scalar_check (x, 0) == FAILURE)
4553 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4556 if (kind_value_check(x, 0, 4) == FAILURE)
4564 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
4566 if (scalar_check (time, 0) == FAILURE)
4568 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4571 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
4573 if (kind_value_check (result, 1, gfc_default_character_kind) == FAILURE)
4581 gfc_check_dtime_etime (gfc_expr *x)
4583 if (array_check (x, 0) == FAILURE)
4586 if (rank_check (x, 0, 1) == FAILURE)
4589 if (variable_check (x, 0, false) == FAILURE)
4592 if (type_check (x, 0, BT_REAL) == FAILURE)
4595 if (kind_value_check(x, 0, 4) == FAILURE)
4603 gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
4605 if (array_check (values, 0) == FAILURE)
4608 if (rank_check (values, 0, 1) == FAILURE)
4611 if (variable_check (values, 0, false) == FAILURE)
4614 if (type_check (values, 0, BT_REAL) == FAILURE)
4617 if (kind_value_check(values, 0, 4) == FAILURE)
4620 if (scalar_check (time, 1) == FAILURE)
4623 if (type_check (time, 1, BT_REAL) == FAILURE)
4626 if (kind_value_check(time, 1, 4) == FAILURE)
4634 gfc_check_fdate_sub (gfc_expr *date)
4636 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
4638 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
4646 gfc_check_gerror (gfc_expr *msg)
4648 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4650 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4658 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
4660 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
4662 if (kind_value_check (cwd, 0, gfc_default_character_kind) == FAILURE)
4668 if (scalar_check (status, 1) == FAILURE)
4671 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4679 gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
4681 if (type_check (pos, 0, BT_INTEGER) == FAILURE)
4684 if (pos->ts.kind > gfc_default_integer_kind)
4686 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4687 "not wider than the default kind (%d)",
4688 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4689 &pos->where, gfc_default_integer_kind);
4693 if (type_check (value, 1, BT_CHARACTER) == FAILURE)
4695 if (kind_value_check (value, 1, gfc_default_character_kind) == FAILURE)
4703 gfc_check_getlog (gfc_expr *msg)
4705 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4707 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4715 gfc_check_exit (gfc_expr *status)
4720 if (type_check (status, 0, BT_INTEGER) == FAILURE)
4723 if (scalar_check (status, 0) == FAILURE)
4731 gfc_check_flush (gfc_expr *unit)
4736 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4739 if (scalar_check (unit, 0) == FAILURE)
4747 gfc_check_free (gfc_expr *i)
4749 if (type_check (i, 0, BT_INTEGER) == FAILURE)
4752 if (scalar_check (i, 0) == FAILURE)
4760 gfc_check_hostnm (gfc_expr *name)
4762 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4764 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4772 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
4774 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4776 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4782 if (scalar_check (status, 1) == FAILURE)
4785 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4793 gfc_check_itime_idate (gfc_expr *values)
4795 if (array_check (values, 0) == FAILURE)
4798 if (rank_check (values, 0, 1) == FAILURE)
4801 if (variable_check (values, 0, false) == FAILURE)
4804 if (type_check (values, 0, BT_INTEGER) == FAILURE)
4807 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
4815 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
4817 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4820 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
4823 if (scalar_check (time, 0) == FAILURE)
4826 if (array_check (values, 1) == FAILURE)
4829 if (rank_check (values, 1, 1) == FAILURE)
4832 if (variable_check (values, 1, false) == FAILURE)
4835 if (type_check (values, 1, BT_INTEGER) == FAILURE)
4838 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
4846 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
4848 if (scalar_check (unit, 0) == FAILURE)
4851 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4854 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
4856 if (kind_value_check (name, 1, gfc_default_character_kind) == FAILURE)
4864 gfc_check_isatty (gfc_expr *unit)
4869 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4872 if (scalar_check (unit, 0) == FAILURE)
4880 gfc_check_isnan (gfc_expr *x)
4882 if (type_check (x, 0, BT_REAL) == FAILURE)
4890 gfc_check_perror (gfc_expr *string)
4892 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
4894 if (kind_value_check (string, 0, gfc_default_character_kind) == FAILURE)
4902 gfc_check_umask (gfc_expr *mask)
4904 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4907 if (scalar_check (mask, 0) == FAILURE)
4915 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
4917 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4920 if (scalar_check (mask, 0) == FAILURE)
4926 if (scalar_check (old, 1) == FAILURE)
4929 if (type_check (old, 1, BT_INTEGER) == FAILURE)
4937 gfc_check_unlink (gfc_expr *name)
4939 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4941 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4949 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
4951 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4953 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4959 if (scalar_check (status, 1) == FAILURE)
4962 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4970 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
4972 if (scalar_check (number, 0) == FAILURE)
4974 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4977 if (int_or_proc_check (handler, 1) == FAILURE)
4979 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4987 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
4989 if (scalar_check (number, 0) == FAILURE)
4991 if (type_check (number, 0, BT_INTEGER) == FAILURE)
4994 if (int_or_proc_check (handler, 1) == FAILURE)
4996 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
5002 if (type_check (status, 2, BT_INTEGER) == FAILURE)
5004 if (scalar_check (status, 2) == FAILURE)
5012 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
5014 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
5016 if (kind_value_check (cmd, 0, gfc_default_character_kind) == FAILURE)
5019 if (scalar_check (status, 1) == FAILURE)
5022 if (type_check (status, 1, BT_INTEGER) == FAILURE)
5025 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
5032 /* This is used for the GNU intrinsics AND, OR and XOR. */
5034 gfc_check_and (gfc_expr *i, gfc_expr *j)
5036 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
5038 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
5039 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
5040 gfc_current_intrinsic, &i->where);
5044 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
5046 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
5047 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
5048 gfc_current_intrinsic, &j->where);
5052 if (i->ts.type != j->ts.type)
5054 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
5055 "have the same type", gfc_current_intrinsic_arg[0]->name,
5056 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
5061 if (scalar_check (i, 0) == FAILURE)
5064 if (scalar_check (j, 1) == FAILURE)
5072 gfc_check_storage_size (gfc_expr *a ATTRIBUTE_UNUSED, gfc_expr *kind)
5077 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
5080 if (scalar_check (kind, 1) == FAILURE)
5083 if (kind->expr_type != EXPR_CONSTANT)
5085 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
5086 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,