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);
207 coarray_check (gfc_expr *e, int n)
209 if (!gfc_is_coarray (e))
211 gfc_error ("Expected coarray variable as '%s' argument to the %s "
212 "intrinsic at %L", gfc_current_intrinsic_arg[n]->name,
213 gfc_current_intrinsic, &e->where);
221 /* Make sure the expression is a logical array. */
224 logical_array_check (gfc_expr *array, int n)
226 if (array->ts.type != BT_LOGICAL || array->rank == 0)
228 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
229 "array", gfc_current_intrinsic_arg[n]->name,
230 gfc_current_intrinsic, &array->where);
238 /* Make sure an expression is an array. */
241 array_check (gfc_expr *e, int n)
246 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
247 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
254 /* If expr is a constant, then check to ensure that it is greater than
258 nonnegative_check (const char *arg, gfc_expr *expr)
262 if (expr->expr_type == EXPR_CONSTANT)
264 gfc_extract_int (expr, &i);
267 gfc_error ("'%s' at %L must be nonnegative", arg, &expr->where);
276 /* If expr2 is constant, then check that the value is less than
277 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
280 less_than_bitsize1 (const char *arg1, gfc_expr *expr1, const char *arg2,
281 gfc_expr *expr2, bool or_equal)
285 if (expr2->expr_type == EXPR_CONSTANT)
287 gfc_extract_int (expr2, &i2);
288 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
290 /* For ISHFT[C], check that |shift| <= bit_size(i). */
296 if (i2 > gfc_integer_kinds[i3].bit_size)
298 gfc_error ("The absolute value of SHIFT at %L must be less "
299 "than or equal to BIT_SIZE('%s')",
300 &expr2->where, arg1);
307 if (i2 > gfc_integer_kinds[i3].bit_size)
309 gfc_error ("'%s' at %L must be less than "
310 "or equal to BIT_SIZE('%s')",
311 arg2, &expr2->where, arg1);
317 if (i2 >= gfc_integer_kinds[i3].bit_size)
319 gfc_error ("'%s' at %L must be less than BIT_SIZE('%s')",
320 arg2, &expr2->where, arg1);
330 /* If expr is constant, then check that the value is less than or equal
331 to the bit_size of the kind k. */
334 less_than_bitsizekind (const char *arg, gfc_expr *expr, int k)
338 if (expr->expr_type != EXPR_CONSTANT)
341 i = gfc_validate_kind (BT_INTEGER, k, false);
342 gfc_extract_int (expr, &val);
344 if (val > gfc_integer_kinds[i].bit_size)
346 gfc_error ("'%s' at %L must be less than or equal to the BIT_SIZE of "
347 "INTEGER(KIND=%d)", arg, &expr->where, k);
355 /* If expr2 and expr3 are constants, then check that the value is less than
356 or equal to bit_size(expr1). */
359 less_than_bitsize2 (const char *arg1, gfc_expr *expr1, const char *arg2,
360 gfc_expr *expr2, const char *arg3, gfc_expr *expr3)
364 if (expr2->expr_type == EXPR_CONSTANT && expr3->expr_type == EXPR_CONSTANT)
366 gfc_extract_int (expr2, &i2);
367 gfc_extract_int (expr3, &i3);
369 i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false);
370 if (i2 > gfc_integer_kinds[i3].bit_size)
372 gfc_error ("'%s + %s' at %L must be less than or equal "
374 arg2, arg3, &expr2->where, arg1);
382 /* Make sure two expressions have the same type. */
385 same_type_check (gfc_expr *e, int n, gfc_expr *f, int m)
387 if (gfc_compare_types (&e->ts, &f->ts))
390 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
391 "and kind as '%s'", gfc_current_intrinsic_arg[m]->name,
392 gfc_current_intrinsic, &f->where,
393 gfc_current_intrinsic_arg[n]->name);
399 /* Make sure that an expression has a certain (nonzero) rank. */
402 rank_check (gfc_expr *e, int n, int rank)
407 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
408 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
415 /* Make sure a variable expression is not an optional dummy argument. */
418 nonoptional_check (gfc_expr *e, int n)
420 if (e->expr_type == EXPR_VARIABLE && e->symtree->n.sym->attr.optional)
422 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
423 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
427 /* TODO: Recursive check on nonoptional variables? */
433 /* Check for ALLOCATABLE attribute. */
436 allocatable_check (gfc_expr *e, int n)
438 symbol_attribute attr;
440 attr = gfc_variable_attr (e, NULL);
441 if (!attr.allocatable)
443 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
444 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
453 /* Check that an expression has a particular kind. */
456 kind_value_check (gfc_expr *e, int n, int k)
461 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
462 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
469 /* Make sure an expression is a variable. */
472 variable_check (gfc_expr *e, int n, bool allow_proc)
474 if (e->expr_type == EXPR_VARIABLE
475 && e->symtree->n.sym->attr.intent == INTENT_IN
476 && (gfc_current_intrinsic_arg[n]->intent == INTENT_OUT
477 || gfc_current_intrinsic_arg[n]->intent == INTENT_INOUT))
479 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
480 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
485 if (e->expr_type == EXPR_VARIABLE
486 && e->symtree->n.sym->attr.flavor != FL_PARAMETER
488 || !e->symtree->n.sym->attr.function
489 || (e->symtree->n.sym == e->symtree->n.sym->result
490 && (e->symtree->n.sym == gfc_current_ns->proc_name
491 || (gfc_current_ns->parent
493 == gfc_current_ns->parent->proc_name)))))
496 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
497 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, &e->where);
503 /* Check the common DIM parameter for correctness. */
506 dim_check (gfc_expr *dim, int n, bool optional)
511 if (type_check (dim, n, BT_INTEGER) == FAILURE)
514 if (scalar_check (dim, n) == FAILURE)
517 if (!optional && nonoptional_check (dim, n) == FAILURE)
524 /* If a coarray DIM parameter is a constant, make sure that it is greater than
525 zero and less than or equal to the corank of the given array. */
528 dim_corank_check (gfc_expr *dim, gfc_expr *array)
532 gcc_assert (array->expr_type == EXPR_VARIABLE);
534 if (dim->expr_type != EXPR_CONSTANT)
537 corank = gfc_get_corank (array);
539 if (mpz_cmp_ui (dim->value.integer, 1) < 0
540 || mpz_cmp_ui (dim->value.integer, corank) > 0)
542 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
543 "codimension index", gfc_current_intrinsic, &dim->where);
552 /* If a DIM parameter is a constant, make sure that it is greater than
553 zero and less than or equal to the rank of the given array. If
554 allow_assumed is zero then dim must be less than the rank of the array
555 for assumed size arrays. */
558 dim_rank_check (gfc_expr *dim, gfc_expr *array, int allow_assumed)
566 if (dim->expr_type != EXPR_CONSTANT)
569 if (array->expr_type == EXPR_FUNCTION && array->value.function.isym
570 && array->value.function.isym->id == GFC_ISYM_SPREAD)
571 rank = array->rank + 1;
575 if (array->expr_type == EXPR_VARIABLE)
577 ar = gfc_find_array_ref (array);
578 if (ar->as->type == AS_ASSUMED_SIZE
580 && ar->type != AR_ELEMENT
581 && ar->type != AR_SECTION)
585 if (mpz_cmp_ui (dim->value.integer, 1) < 0
586 || mpz_cmp_ui (dim->value.integer, rank) > 0)
588 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
589 "dimension index", gfc_current_intrinsic, &dim->where);
598 /* Compare the size of a along dimension ai with the size of b along
599 dimension bi, returning 0 if they are known not to be identical,
600 and 1 if they are identical, or if this cannot be determined. */
603 identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi)
605 mpz_t a_size, b_size;
608 gcc_assert (a->rank > ai);
609 gcc_assert (b->rank > bi);
613 if (gfc_array_dimen_size (a, ai, &a_size) == SUCCESS)
615 if (gfc_array_dimen_size (b, bi, &b_size) == SUCCESS)
617 if (mpz_cmp (a_size, b_size) != 0)
627 /* Calculate the length of a character variable, including substrings.
628 Strip away parentheses if necessary. Return -1 if no length could
632 gfc_var_strlen (const gfc_expr *a)
636 while (a->expr_type == EXPR_OP && a->value.op.op == INTRINSIC_PARENTHESES)
639 for (ra = a->ref; ra != NULL && ra->type != REF_SUBSTRING; ra = ra->next)
646 if (ra->u.ss.start->expr_type == EXPR_CONSTANT
647 && ra->u.ss.end->expr_type == EXPR_CONSTANT)
649 start_a = mpz_get_si (ra->u.ss.start->value.integer);
650 end_a = mpz_get_si (ra->u.ss.end->value.integer);
651 return end_a - start_a + 1;
653 else if (gfc_dep_compare_expr (ra->u.ss.start, ra->u.ss.end) == 0)
659 if (a->ts.u.cl && a->ts.u.cl->length
660 && a->ts.u.cl->length->expr_type == EXPR_CONSTANT)
661 return mpz_get_si (a->ts.u.cl->length->value.integer);
662 else if (a->expr_type == EXPR_CONSTANT
663 && (a->ts.u.cl == NULL || a->ts.u.cl->length == NULL))
664 return a->value.character.length;
670 /* Check whether two character expressions have the same length;
671 returns SUCCESS if they have or if the length cannot be determined,
672 otherwise return FAILURE and raise a gfc_error. */
675 gfc_check_same_strlen (const gfc_expr *a, const gfc_expr *b, const char *name)
679 len_a = gfc_var_strlen(a);
680 len_b = gfc_var_strlen(b);
682 if (len_a == -1 || len_b == -1 || len_a == len_b)
686 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
687 len_a, len_b, name, &a->where);
693 /***** Check functions *****/
695 /* Check subroutine suitable for intrinsics taking a real argument and
696 a kind argument for the result. */
699 check_a_kind (gfc_expr *a, gfc_expr *kind, bt type)
701 if (type_check (a, 0, BT_REAL) == FAILURE)
703 if (kind_check (kind, 1, type) == FAILURE)
710 /* Check subroutine suitable for ceiling, floor and nint. */
713 gfc_check_a_ikind (gfc_expr *a, gfc_expr *kind)
715 return check_a_kind (a, kind, BT_INTEGER);
719 /* Check subroutine suitable for aint, anint. */
722 gfc_check_a_xkind (gfc_expr *a, gfc_expr *kind)
724 return check_a_kind (a, kind, BT_REAL);
729 gfc_check_abs (gfc_expr *a)
731 if (numeric_check (a, 0) == FAILURE)
739 gfc_check_achar (gfc_expr *a, gfc_expr *kind)
741 if (type_check (a, 0, BT_INTEGER) == FAILURE)
743 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
751 gfc_check_access_func (gfc_expr *name, gfc_expr *mode)
753 if (type_check (name, 0, BT_CHARACTER) == FAILURE
754 || scalar_check (name, 0) == FAILURE)
756 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
759 if (type_check (mode, 1, BT_CHARACTER) == FAILURE
760 || scalar_check (mode, 1) == FAILURE)
762 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
770 gfc_check_all_any (gfc_expr *mask, gfc_expr *dim)
772 if (logical_array_check (mask, 0) == FAILURE)
775 if (dim_check (dim, 1, false) == FAILURE)
778 if (dim_rank_check (dim, mask, 0) == FAILURE)
786 gfc_check_allocated (gfc_expr *array)
788 if (variable_check (array, 0, false) == FAILURE)
790 if (allocatable_check (array, 0) == FAILURE)
797 /* Common check function where the first argument must be real or
798 integer and the second argument must be the same as the first. */
801 gfc_check_a_p (gfc_expr *a, gfc_expr *p)
803 if (int_or_real_check (a, 0) == FAILURE)
806 if (a->ts.type != p->ts.type)
808 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
809 "have the same type", gfc_current_intrinsic_arg[0]->name,
810 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
815 if (a->ts.kind != p->ts.kind)
817 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type kinds at %L",
818 &p->where) == FAILURE)
827 gfc_check_x_yd (gfc_expr *x, gfc_expr *y)
829 if (double_check (x, 0) == FAILURE || double_check (y, 1) == FAILURE)
837 gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
839 symbol_attribute attr1, attr2;
844 where = &pointer->where;
846 if (pointer->expr_type == EXPR_VARIABLE || pointer->expr_type == EXPR_FUNCTION)
847 attr1 = gfc_expr_attr (pointer);
848 else if (pointer->expr_type == EXPR_NULL)
851 gcc_assert (0); /* Pointer must be a variable or a function. */
853 if (!attr1.pointer && !attr1.proc_pointer)
855 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
856 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
862 if (attr1.pointer && gfc_is_coindexed (pointer))
864 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
865 "conindexed", gfc_current_intrinsic_arg[0]->name,
866 gfc_current_intrinsic, &pointer->where);
870 /* Target argument is optional. */
874 where = &target->where;
875 if (target->expr_type == EXPR_NULL)
878 if (target->expr_type == EXPR_VARIABLE || target->expr_type == EXPR_FUNCTION)
879 attr2 = gfc_expr_attr (target);
882 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
883 "or target VARIABLE or FUNCTION",
884 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
889 if (attr1.pointer && !attr2.pointer && !attr2.target)
891 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
892 "or a TARGET", gfc_current_intrinsic_arg[1]->name,
893 gfc_current_intrinsic, &target->where);
898 if (attr1.pointer && gfc_is_coindexed (target))
900 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
901 "conindexed", gfc_current_intrinsic_arg[1]->name,
902 gfc_current_intrinsic, &target->where);
907 if (same_type_check (pointer, 0, target, 1) == FAILURE)
909 if (rank_check (target, 0, pointer->rank) == FAILURE)
911 if (target->rank > 0)
913 for (i = 0; i < target->rank; i++)
914 if (target->ref->u.ar.dimen_type[i] == DIMEN_VECTOR)
916 gfc_error ("Array section with a vector subscript at %L shall not "
917 "be the target of a pointer",
927 gfc_error ("NULL pointer at %L is not permitted as actual argument "
928 "of '%s' intrinsic function", where, gfc_current_intrinsic);
935 gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
937 /* gfc_notify_std would be a waste of time as the return value
938 is seemingly used only for the generic resolution. The error
939 will be: Too many arguments. */
940 if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
943 return gfc_check_atan2 (y, x);
948 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
950 if (type_check (y, 0, BT_REAL) == FAILURE)
952 if (same_type_check (y, 0, x, 1) == FAILURE)
960 gfc_check_atomic (gfc_expr *atom, gfc_expr *value)
962 if (!(atom->ts.type == BT_INTEGER && atom->ts.kind == gfc_atomic_int_kind)
963 && !(atom->ts.type == BT_LOGICAL
964 && atom->ts.kind == gfc_atomic_logical_kind))
966 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
967 "integer of ATOMIC_INT_KIND or a logical of "
968 "ATOMIC_LOGICAL_KIND", &atom->where, gfc_current_intrinsic);
972 if (!gfc_expr_attr (atom).codimension)
974 gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
975 "coarray or coindexed", &atom->where, gfc_current_intrinsic);
979 if (atom->ts.type != value->ts.type)
981 gfc_error ("ATOM and VALUE argument of the %s intrinsic function shall "
982 "have the same type at %L", gfc_current_intrinsic,
992 gfc_check_atomic_def (gfc_expr *atom, gfc_expr *value)
994 if (scalar_check (atom, 0) == FAILURE || scalar_check (value, 1) == FAILURE)
997 if (gfc_check_vardef_context (atom, false, false, NULL) == FAILURE)
999 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1000 "definable", gfc_current_intrinsic, &atom->where);
1004 return gfc_check_atomic (atom, value);
1009 gfc_check_atomic_ref (gfc_expr *value, gfc_expr *atom)
1011 if (scalar_check (value, 0) == FAILURE || scalar_check (atom, 1) == FAILURE)
1014 if (gfc_check_vardef_context (value, false, false, NULL) == FAILURE)
1016 gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1017 "definable", gfc_current_intrinsic, &value->where);
1021 return gfc_check_atomic (atom, value);
1025 /* BESJN and BESYN functions. */
1028 gfc_check_besn (gfc_expr *n, gfc_expr *x)
1030 if (type_check (n, 0, BT_INTEGER) == FAILURE)
1032 if (n->expr_type == EXPR_CONSTANT)
1035 gfc_extract_int (n, &i);
1036 if (i < 0 && gfc_notify_std (GFC_STD_GNU, "Extension: Negative argument "
1037 "N at %L", &n->where) == FAILURE)
1041 if (type_check (x, 1, BT_REAL) == FAILURE)
1048 /* Transformational version of the Bessel JN and YN functions. */
1051 gfc_check_bessel_n2 (gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
1053 if (type_check (n1, 0, BT_INTEGER) == FAILURE)
1055 if (scalar_check (n1, 0) == FAILURE)
1057 if (nonnegative_check("N1", n1) == FAILURE)
1060 if (type_check (n2, 1, BT_INTEGER) == FAILURE)
1062 if (scalar_check (n2, 1) == FAILURE)
1064 if (nonnegative_check("N2", n2) == FAILURE)
1067 if (type_check (x, 2, BT_REAL) == FAILURE)
1069 if (scalar_check (x, 2) == FAILURE)
1077 gfc_check_bge_bgt_ble_blt (gfc_expr *i, gfc_expr *j)
1079 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1082 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1090 gfc_check_bitfcn (gfc_expr *i, gfc_expr *pos)
1092 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1095 if (type_check (pos, 1, BT_INTEGER) == FAILURE)
1098 if (nonnegative_check ("pos", pos) == FAILURE)
1101 if (less_than_bitsize1 ("i", i, "pos", pos, false) == FAILURE)
1109 gfc_check_char (gfc_expr *i, gfc_expr *kind)
1111 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1113 if (kind_check (kind, 1, BT_CHARACTER) == FAILURE)
1121 gfc_check_chdir (gfc_expr *dir)
1123 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
1125 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
1133 gfc_check_chdir_sub (gfc_expr *dir, gfc_expr *status)
1135 if (type_check (dir, 0, BT_CHARACTER) == FAILURE)
1137 if (kind_value_check (dir, 0, gfc_default_character_kind) == FAILURE)
1143 if (type_check (status, 1, BT_INTEGER) == FAILURE)
1145 if (scalar_check (status, 1) == FAILURE)
1153 gfc_check_chmod (gfc_expr *name, gfc_expr *mode)
1155 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
1157 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
1160 if (type_check (mode, 1, BT_CHARACTER) == FAILURE)
1162 if (kind_value_check (mode, 1, gfc_default_character_kind) == FAILURE)
1170 gfc_check_chmod_sub (gfc_expr *name, gfc_expr *mode, gfc_expr *status)
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)
1185 if (type_check (status, 2, BT_INTEGER) == FAILURE)
1188 if (scalar_check (status, 2) == FAILURE)
1196 gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
1198 if (numeric_check (x, 0) == FAILURE)
1203 if (numeric_check (y, 1) == FAILURE)
1206 if (x->ts.type == BT_COMPLEX)
1208 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1209 "present if 'x' is COMPLEX",
1210 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1215 if (y->ts.type == BT_COMPLEX)
1217 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1218 "of either REAL or INTEGER",
1219 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1226 if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
1234 gfc_check_complex (gfc_expr *x, gfc_expr *y)
1236 if (int_or_real_check (x, 0) == FAILURE)
1238 if (scalar_check (x, 0) == FAILURE)
1241 if (int_or_real_check (y, 1) == FAILURE)
1243 if (scalar_check (y, 1) == FAILURE)
1251 gfc_check_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
1253 if (logical_array_check (mask, 0) == FAILURE)
1255 if (dim_check (dim, 1, false) == FAILURE)
1257 if (dim_rank_check (dim, mask, 0) == FAILURE)
1259 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
1261 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
1262 "with KIND argument at %L",
1263 gfc_current_intrinsic, &kind->where) == FAILURE)
1271 gfc_check_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
1273 if (array_check (array, 0) == FAILURE)
1276 if (type_check (shift, 1, BT_INTEGER) == FAILURE)
1279 if (dim_check (dim, 2, true) == FAILURE)
1282 if (dim_rank_check (dim, array, false) == FAILURE)
1285 if (array->rank == 1 || shift->rank == 0)
1287 if (scalar_check (shift, 1) == FAILURE)
1290 else if (shift->rank == array->rank - 1)
1295 else if (dim->expr_type == EXPR_CONSTANT)
1296 gfc_extract_int (dim, &d);
1303 for (i = 0, j = 0; i < array->rank; i++)
1306 if (!identical_dimen_shape (array, i, shift, j))
1308 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1309 "invalid shape in dimension %d (%ld/%ld)",
1310 gfc_current_intrinsic_arg[1]->name,
1311 gfc_current_intrinsic, &shift->where, i + 1,
1312 mpz_get_si (array->shape[i]),
1313 mpz_get_si (shift->shape[j]));
1323 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1324 "%d or be a scalar", gfc_current_intrinsic_arg[1]->name,
1325 gfc_current_intrinsic, &shift->where, array->rank - 1);
1334 gfc_check_ctime (gfc_expr *time)
1336 if (scalar_check (time, 0) == FAILURE)
1339 if (type_check (time, 0, BT_INTEGER) == FAILURE)
1346 gfc_try gfc_check_datan2 (gfc_expr *y, gfc_expr *x)
1348 if (double_check (y, 0) == FAILURE || double_check (x, 1) == FAILURE)
1355 gfc_check_dcmplx (gfc_expr *x, gfc_expr *y)
1357 if (numeric_check (x, 0) == FAILURE)
1362 if (numeric_check (y, 1) == FAILURE)
1365 if (x->ts.type == BT_COMPLEX)
1367 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1368 "present if 'x' is COMPLEX",
1369 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1374 if (y->ts.type == BT_COMPLEX)
1376 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1377 "of either REAL or INTEGER",
1378 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
1389 gfc_check_dble (gfc_expr *x)
1391 if (numeric_check (x, 0) == FAILURE)
1399 gfc_check_digits (gfc_expr *x)
1401 if (int_or_real_check (x, 0) == FAILURE)
1409 gfc_check_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
1411 switch (vector_a->ts.type)
1414 if (type_check (vector_b, 1, BT_LOGICAL) == FAILURE)
1421 if (numeric_check (vector_b, 1) == FAILURE)
1426 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1427 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
1428 gfc_current_intrinsic, &vector_a->where);
1432 if (rank_check (vector_a, 0, 1) == FAILURE)
1435 if (rank_check (vector_b, 1, 1) == FAILURE)
1438 if (! identical_dimen_shape (vector_a, 0, vector_b, 0))
1440 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1441 "intrinsic 'dot_product'", gfc_current_intrinsic_arg[0]->name,
1442 gfc_current_intrinsic_arg[1]->name, &vector_a->where);
1451 gfc_check_dprod (gfc_expr *x, gfc_expr *y)
1453 if (type_check (x, 0, BT_REAL) == FAILURE
1454 || type_check (y, 1, BT_REAL) == FAILURE)
1457 if (x->ts.kind != gfc_default_real_kind)
1459 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1460 "real", gfc_current_intrinsic_arg[0]->name,
1461 gfc_current_intrinsic, &x->where);
1465 if (y->ts.kind != gfc_default_real_kind)
1467 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1468 "real", gfc_current_intrinsic_arg[1]->name,
1469 gfc_current_intrinsic, &y->where);
1478 gfc_check_dshift (gfc_expr *i, gfc_expr *j, gfc_expr *shift)
1480 if (type_check (i, 0, BT_INTEGER) == FAILURE)
1483 if (type_check (j, 1, BT_INTEGER) == FAILURE)
1486 if (i->is_boz && j->is_boz)
1488 gfc_error ("'I' at %L and 'J' at %L cannot both be BOZ literal "
1489 "constants", &i->where, &j->where);
1493 if (!i->is_boz && !j->is_boz && same_type_check (i, 0, j, 1) == FAILURE)
1496 if (type_check (shift, 2, BT_INTEGER) == FAILURE)
1499 if (nonnegative_check ("SHIFT", shift) == FAILURE)
1504 if (less_than_bitsize1 ("J", j, "SHIFT", shift, true) == FAILURE)
1506 i->ts.kind = j->ts.kind;
1510 if (less_than_bitsize1 ("I", i, "SHIFT", shift, true) == FAILURE)
1512 j->ts.kind = i->ts.kind;
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)
1963 if (less_than_bitsize1 ("I", i, NULL, shift, true) == FAILURE)
1971 gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1973 if (type_check (i, 0, BT_INTEGER) == FAILURE
1974 || type_check (shift, 1, BT_INTEGER) == FAILURE)
1981 if (type_check (size, 2, BT_INTEGER) == FAILURE)
1984 if (less_than_bitsize1 ("I", i, "SIZE", size, true) == FAILURE)
1987 if (size->expr_type == EXPR_CONSTANT)
1989 gfc_extract_int (size, &i3);
1992 gfc_error ("SIZE at %L must be positive", &size->where);
1996 if (shift->expr_type == EXPR_CONSTANT)
1998 gfc_extract_int (shift, &i2);
2004 gfc_error ("The absolute value of SHIFT at %L must be less "
2005 "than or equal to SIZE at %L", &shift->where,
2012 else if (less_than_bitsize1 ("I", i, NULL, shift, true) == FAILURE)
2020 gfc_check_kill (gfc_expr *pid, gfc_expr *sig)
2022 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
2025 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
2033 gfc_check_kill_sub (gfc_expr *pid, gfc_expr *sig, gfc_expr *status)
2035 if (type_check (pid, 0, BT_INTEGER) == FAILURE)
2038 if (scalar_check (pid, 0) == FAILURE)
2041 if (type_check (sig, 1, BT_INTEGER) == FAILURE)
2044 if (scalar_check (sig, 1) == FAILURE)
2050 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2053 if (scalar_check (status, 2) == FAILURE)
2061 gfc_check_kind (gfc_expr *x)
2063 if (x->ts.type == BT_DERIVED)
2065 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
2066 "non-derived type", gfc_current_intrinsic_arg[0]->name,
2067 gfc_current_intrinsic, &x->where);
2076 gfc_check_lbound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2078 if (array_check (array, 0) == FAILURE)
2081 if (dim_check (dim, 1, false) == FAILURE)
2084 if (dim_rank_check (dim, array, 1) == FAILURE)
2087 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
2089 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2090 "with KIND argument at %L",
2091 gfc_current_intrinsic, &kind->where) == FAILURE)
2099 gfc_check_lcobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
2101 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
2103 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
2107 if (coarray_check (coarray, 0) == FAILURE)
2112 if (dim_check (dim, 1, false) == FAILURE)
2115 if (dim_corank_check (dim, coarray) == FAILURE)
2119 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
2127 gfc_check_len_lentrim (gfc_expr *s, gfc_expr *kind)
2129 if (type_check (s, 0, BT_CHARACTER) == FAILURE)
2132 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
2134 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2135 "with KIND argument at %L",
2136 gfc_current_intrinsic, &kind->where) == FAILURE)
2144 gfc_check_lge_lgt_lle_llt (gfc_expr *a, gfc_expr *b)
2146 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2148 if (kind_value_check (a, 0, gfc_default_character_kind) == FAILURE)
2151 if (type_check (b, 1, BT_CHARACTER) == FAILURE)
2153 if (kind_value_check (b, 1, gfc_default_character_kind) == FAILURE)
2161 gfc_check_link (gfc_expr *path1, gfc_expr *path2)
2163 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2165 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2168 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2170 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2178 gfc_check_link_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2180 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2182 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2185 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2187 if (kind_value_check (path2, 0, gfc_default_character_kind) == FAILURE)
2193 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2196 if (scalar_check (status, 2) == FAILURE)
2204 gfc_check_loc (gfc_expr *expr)
2206 return variable_check (expr, 0, true);
2211 gfc_check_symlnk (gfc_expr *path1, gfc_expr *path2)
2213 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2215 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2218 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2220 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2228 gfc_check_symlnk_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
2230 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
2232 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
2235 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
2237 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
2243 if (type_check (status, 2, BT_INTEGER) == FAILURE)
2246 if (scalar_check (status, 2) == FAILURE)
2254 gfc_check_logical (gfc_expr *a, gfc_expr *kind)
2256 if (type_check (a, 0, BT_LOGICAL) == FAILURE)
2258 if (kind_check (kind, 1, BT_LOGICAL) == FAILURE)
2265 /* Min/max family. */
2268 min_max_args (gfc_actual_arglist *arg)
2270 if (arg == NULL || arg->next == NULL)
2272 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
2273 gfc_current_intrinsic, gfc_current_intrinsic_where);
2282 check_rest (bt type, int kind, gfc_actual_arglist *arglist)
2284 gfc_actual_arglist *arg, *tmp;
2289 if (min_max_args (arglist) == FAILURE)
2292 for (arg = arglist, n=1; arg; arg = arg->next, n++)
2295 if (x->ts.type != type || x->ts.kind != kind)
2297 if (x->ts.type == type)
2299 if (gfc_notify_std (GFC_STD_GNU, "Extension: Different type "
2300 "kinds at %L", &x->where) == FAILURE)
2305 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
2306 "%s(%d)", n, gfc_current_intrinsic, &x->where,
2307 gfc_basic_typename (type), kind);
2312 for (tmp = arglist, m=1; tmp != arg; tmp = tmp->next, m++)
2313 if (gfc_check_conformance (tmp->expr, x,
2314 "arguments 'a%d' and 'a%d' for "
2315 "intrinsic '%s'", m, n,
2316 gfc_current_intrinsic) == FAILURE)
2325 gfc_check_min_max (gfc_actual_arglist *arg)
2329 if (min_max_args (arg) == FAILURE)
2334 if (x->ts.type == BT_CHARACTER)
2336 if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
2337 "with CHARACTER argument at %L",
2338 gfc_current_intrinsic, &x->where) == FAILURE)
2341 else if (x->ts.type != BT_INTEGER && x->ts.type != BT_REAL)
2343 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
2344 "REAL or CHARACTER", gfc_current_intrinsic, &x->where);
2348 return check_rest (x->ts.type, x->ts.kind, arg);
2353 gfc_check_min_max_integer (gfc_actual_arglist *arg)
2355 return check_rest (BT_INTEGER, gfc_default_integer_kind, arg);
2360 gfc_check_min_max_real (gfc_actual_arglist *arg)
2362 return check_rest (BT_REAL, gfc_default_real_kind, arg);
2367 gfc_check_min_max_double (gfc_actual_arglist *arg)
2369 return check_rest (BT_REAL, gfc_default_double_kind, arg);
2373 /* End of min/max family. */
2376 gfc_check_malloc (gfc_expr *size)
2378 if (type_check (size, 0, BT_INTEGER) == FAILURE)
2381 if (scalar_check (size, 0) == FAILURE)
2389 gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b)
2391 if ((matrix_a->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_a->ts))
2393 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2394 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
2395 gfc_current_intrinsic, &matrix_a->where);
2399 if ((matrix_b->ts.type != BT_LOGICAL) && !gfc_numeric_ts (&matrix_b->ts))
2401 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2402 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
2403 gfc_current_intrinsic, &matrix_b->where);
2407 if ((matrix_a->ts.type == BT_LOGICAL && gfc_numeric_ts (&matrix_b->ts))
2408 || (gfc_numeric_ts (&matrix_a->ts) && matrix_b->ts.type == BT_LOGICAL))
2410 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2411 gfc_current_intrinsic, &matrix_a->where,
2412 gfc_typename(&matrix_a->ts), gfc_typename(&matrix_b->ts));
2416 switch (matrix_a->rank)
2419 if (rank_check (matrix_b, 1, 2) == FAILURE)
2421 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2422 if (!identical_dimen_shape (matrix_a, 0, matrix_b, 0))
2424 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2425 "and '%s' at %L for intrinsic matmul",
2426 gfc_current_intrinsic_arg[0]->name,
2427 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
2433 if (matrix_b->rank != 2)
2435 if (rank_check (matrix_b, 1, 1) == FAILURE)
2438 /* matrix_b has rank 1 or 2 here. Common check for the cases
2439 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2440 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2441 if (!identical_dimen_shape (matrix_a, 1, matrix_b, 0))
2443 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2444 "dimension 1 for argument '%s' at %L for intrinsic "
2445 "matmul", gfc_current_intrinsic_arg[0]->name,
2446 gfc_current_intrinsic_arg[1]->name, &matrix_a->where);
2452 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2453 "1 or 2", gfc_current_intrinsic_arg[0]->name,
2454 gfc_current_intrinsic, &matrix_a->where);
2462 /* Whoever came up with this interface was probably on something.
2463 The possibilities for the occupation of the second and third
2470 NULL MASK minloc(array, mask=m)
2473 I.e. in the case of minloc(array,mask), mask will be in the second
2474 position of the argument list and we'll have to fix that up. */
2477 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
2479 gfc_expr *a, *m, *d;
2482 if (int_or_real_check (a, 0) == FAILURE || array_check (a, 0) == FAILURE)
2486 m = ap->next->next->expr;
2488 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2489 && ap->next->name == NULL)
2493 ap->next->expr = NULL;
2494 ap->next->next->expr = m;
2497 if (dim_check (d, 1, false) == FAILURE)
2500 if (dim_rank_check (d, a, 0) == FAILURE)
2503 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2507 && gfc_check_conformance (a, m,
2508 "arguments '%s' and '%s' for intrinsic %s",
2509 gfc_current_intrinsic_arg[0]->name,
2510 gfc_current_intrinsic_arg[2]->name,
2511 gfc_current_intrinsic ) == FAILURE)
2518 /* Similar to minloc/maxloc, the argument list might need to be
2519 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2520 difference is that MINLOC/MAXLOC take an additional KIND argument.
2521 The possibilities are:
2527 NULL MASK minval(array, mask=m)
2530 I.e. in the case of minval(array,mask), mask will be in the second
2531 position of the argument list and we'll have to fix that up. */
2534 check_reduction (gfc_actual_arglist *ap)
2536 gfc_expr *a, *m, *d;
2540 m = ap->next->next->expr;
2542 if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
2543 && ap->next->name == NULL)
2547 ap->next->expr = NULL;
2548 ap->next->next->expr = m;
2551 if (dim_check (d, 1, false) == FAILURE)
2554 if (dim_rank_check (d, a, 0) == FAILURE)
2557 if (m != NULL && type_check (m, 2, BT_LOGICAL) == FAILURE)
2561 && gfc_check_conformance (a, m,
2562 "arguments '%s' and '%s' for intrinsic %s",
2563 gfc_current_intrinsic_arg[0]->name,
2564 gfc_current_intrinsic_arg[2]->name,
2565 gfc_current_intrinsic) == FAILURE)
2573 gfc_check_minval_maxval (gfc_actual_arglist *ap)
2575 if (int_or_real_check (ap->expr, 0) == FAILURE
2576 || array_check (ap->expr, 0) == FAILURE)
2579 return check_reduction (ap);
2584 gfc_check_product_sum (gfc_actual_arglist *ap)
2586 if (numeric_check (ap->expr, 0) == FAILURE
2587 || array_check (ap->expr, 0) == FAILURE)
2590 return check_reduction (ap);
2594 /* For IANY, IALL and IPARITY. */
2597 gfc_check_mask (gfc_expr *i, gfc_expr *kind)
2601 if (type_check (i, 0, BT_INTEGER) == FAILURE)
2604 if (nonnegative_check ("I", i) == FAILURE)
2607 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
2611 gfc_extract_int (kind, &k);
2613 k = gfc_default_integer_kind;
2615 if (less_than_bitsizekind ("I", i, k) == FAILURE)
2623 gfc_check_transf_bit_intrins (gfc_actual_arglist *ap)
2625 if (ap->expr->ts.type != BT_INTEGER)
2627 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER",
2628 gfc_current_intrinsic_arg[0]->name,
2629 gfc_current_intrinsic, &ap->expr->where);
2633 if (array_check (ap->expr, 0) == FAILURE)
2636 return check_reduction (ap);
2641 gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
2643 if (same_type_check (tsource, 0, fsource, 1) == FAILURE)
2646 if (type_check (mask, 2, BT_LOGICAL) == FAILURE)
2649 if (tsource->ts.type == BT_CHARACTER)
2650 return gfc_check_same_strlen (tsource, fsource, "MERGE intrinsic");
2657 gfc_check_merge_bits (gfc_expr *i, gfc_expr *j, gfc_expr *mask)
2659 if (type_check (i, 0, BT_INTEGER) == FAILURE)
2662 if (type_check (j, 1, BT_INTEGER) == FAILURE)
2665 if (type_check (mask, 2, BT_INTEGER) == FAILURE)
2668 if (same_type_check (i, 0, j, 1) == FAILURE)
2671 if (same_type_check (i, 0, mask, 2) == FAILURE)
2679 gfc_check_move_alloc (gfc_expr *from, gfc_expr *to)
2681 if (variable_check (from, 0, false) == FAILURE)
2683 if (allocatable_check (from, 0) == FAILURE)
2686 if (variable_check (to, 1, false) == FAILURE)
2688 if (allocatable_check (to, 1) == FAILURE)
2691 if (same_type_check (to, 1, from, 0) == FAILURE)
2694 if (to->rank != from->rank)
2696 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2697 "have the same rank %d/%d", gfc_current_intrinsic_arg[0]->name,
2698 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2699 &to->where, from->rank, to->rank);
2703 if (to->ts.kind != from->ts.kind)
2705 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2706 "be of the same kind %d/%d",
2707 gfc_current_intrinsic_arg[0]->name,
2708 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
2709 &to->where, from->ts.kind, to->ts.kind);
2713 /* CLASS arguments: Make sure the vtab is present. */
2714 if (to->ts.type == BT_CLASS)
2715 gfc_find_derived_vtab (from->ts.u.derived);
2722 gfc_check_nearest (gfc_expr *x, gfc_expr *s)
2724 if (type_check (x, 0, BT_REAL) == FAILURE)
2727 if (type_check (s, 1, BT_REAL) == FAILURE)
2730 if (s->expr_type == EXPR_CONSTANT)
2732 if (mpfr_sgn (s->value.real) == 0)
2734 gfc_error ("Argument 'S' of NEAREST at %L shall not be zero",
2745 gfc_check_new_line (gfc_expr *a)
2747 if (type_check (a, 0, BT_CHARACTER) == FAILURE)
2755 gfc_check_norm2 (gfc_expr *array, gfc_expr *dim)
2757 if (type_check (array, 0, BT_REAL) == FAILURE)
2760 if (array_check (array, 0) == FAILURE)
2763 if (dim_rank_check (dim, array, false) == FAILURE)
2770 gfc_check_null (gfc_expr *mold)
2772 symbol_attribute attr;
2777 if (variable_check (mold, 0, true) == FAILURE)
2780 attr = gfc_variable_attr (mold, NULL);
2782 if (!attr.pointer && !attr.proc_pointer && !attr.allocatable)
2784 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER, "
2785 "ALLOCATABLE or procedure pointer",
2786 gfc_current_intrinsic_arg[0]->name,
2787 gfc_current_intrinsic, &mold->where);
2791 if (attr.allocatable
2792 && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: NULL intrinsic with "
2793 "allocatable MOLD at %L", &mold->where) == FAILURE)
2797 if (gfc_is_coindexed (mold))
2799 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
2800 "conindexed", gfc_current_intrinsic_arg[0]->name,
2801 gfc_current_intrinsic, &mold->where);
2810 gfc_check_pack (gfc_expr *array, gfc_expr *mask, gfc_expr *vector)
2812 if (array_check (array, 0) == FAILURE)
2815 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
2818 if (gfc_check_conformance (array, mask,
2819 "arguments '%s' and '%s' for intrinsic '%s'",
2820 gfc_current_intrinsic_arg[0]->name,
2821 gfc_current_intrinsic_arg[1]->name,
2822 gfc_current_intrinsic) == FAILURE)
2827 mpz_t array_size, vector_size;
2828 bool have_array_size, have_vector_size;
2830 if (same_type_check (array, 0, vector, 2) == FAILURE)
2833 if (rank_check (vector, 2, 1) == FAILURE)
2836 /* VECTOR requires at least as many elements as MASK
2837 has .TRUE. values. */
2838 have_array_size = gfc_array_size (array, &array_size) == SUCCESS;
2839 have_vector_size = gfc_array_size (vector, &vector_size) == SUCCESS;
2841 if (have_vector_size
2842 && (mask->expr_type == EXPR_ARRAY
2843 || (mask->expr_type == EXPR_CONSTANT
2844 && have_array_size)))
2846 int mask_true_values = 0;
2848 if (mask->expr_type == EXPR_ARRAY)
2850 gfc_constructor *mask_ctor;
2851 mask_ctor = gfc_constructor_first (mask->value.constructor);
2854 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
2856 mask_true_values = 0;
2860 if (mask_ctor->expr->value.logical)
2863 mask_ctor = gfc_constructor_next (mask_ctor);
2866 else if (mask->expr_type == EXPR_CONSTANT && mask->value.logical)
2867 mask_true_values = mpz_get_si (array_size);
2869 if (mpz_get_si (vector_size) < mask_true_values)
2871 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2872 "provide at least as many elements as there "
2873 "are .TRUE. values in '%s' (%ld/%d)",
2874 gfc_current_intrinsic_arg[2]->name,
2875 gfc_current_intrinsic, &vector->where,
2876 gfc_current_intrinsic_arg[1]->name,
2877 mpz_get_si (vector_size), mask_true_values);
2882 if (have_array_size)
2883 mpz_clear (array_size);
2884 if (have_vector_size)
2885 mpz_clear (vector_size);
2893 gfc_check_parity (gfc_expr *mask, gfc_expr *dim)
2895 if (type_check (mask, 0, BT_LOGICAL) == FAILURE)
2898 if (array_check (mask, 0) == FAILURE)
2901 if (dim_rank_check (dim, mask, false) == FAILURE)
2909 gfc_check_precision (gfc_expr *x)
2911 if (real_or_complex_check (x, 0) == FAILURE)
2919 gfc_check_present (gfc_expr *a)
2923 if (variable_check (a, 0, true) == FAILURE)
2926 sym = a->symtree->n.sym;
2927 if (!sym->attr.dummy)
2929 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2930 "dummy variable", gfc_current_intrinsic_arg[0]->name,
2931 gfc_current_intrinsic, &a->where);
2935 if (!sym->attr.optional)
2937 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2938 "an OPTIONAL dummy variable",
2939 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
2944 /* 13.14.82 PRESENT(A)
2946 Argument. A shall be the name of an optional dummy argument that is
2947 accessible in the subprogram in which the PRESENT function reference
2951 && !(a->ref->next == NULL && a->ref->type == REF_ARRAY
2952 && (a->ref->u.ar.type == AR_FULL
2953 || (a->ref->u.ar.type == AR_ELEMENT
2954 && a->ref->u.ar.as->rank == 0))))
2956 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2957 "subobject of '%s'", gfc_current_intrinsic_arg[0]->name,
2958 gfc_current_intrinsic, &a->where, sym->name);
2967 gfc_check_radix (gfc_expr *x)
2969 if (int_or_real_check (x, 0) == FAILURE)
2977 gfc_check_range (gfc_expr *x)
2979 if (numeric_check (x, 0) == FAILURE)
2987 gfc_check_rank (gfc_expr *a ATTRIBUTE_UNUSED)
2989 /* Any data object is allowed; a "data object" is a "constant (4.1.3),
2990 variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
2992 bool is_variable = true;
2994 /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
2995 if (a->expr_type == EXPR_FUNCTION)
2996 is_variable = a->value.function.esym
2997 ? a->value.function.esym->result->attr.pointer
2998 : a->symtree->n.sym->result->attr.pointer;
3000 if (a->expr_type == EXPR_OP || a->expr_type == EXPR_NULL
3001 || a->expr_type == EXPR_COMPCALL|| a->expr_type == EXPR_PPC
3004 gfc_error ("The argument of the RANK intrinsic at %L must be a data "
3005 "object", &a->where);
3013 /* real, float, sngl. */
3015 gfc_check_real (gfc_expr *a, gfc_expr *kind)
3017 if (numeric_check (a, 0) == FAILURE)
3020 if (kind_check (kind, 1, BT_REAL) == FAILURE)
3028 gfc_check_rename (gfc_expr *path1, gfc_expr *path2)
3030 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
3032 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
3035 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
3037 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
3045 gfc_check_rename_sub (gfc_expr *path1, gfc_expr *path2, gfc_expr *status)
3047 if (type_check (path1, 0, BT_CHARACTER) == FAILURE)
3049 if (kind_value_check (path1, 0, gfc_default_character_kind) == FAILURE)
3052 if (type_check (path2, 1, BT_CHARACTER) == FAILURE)
3054 if (kind_value_check (path2, 1, gfc_default_character_kind) == FAILURE)
3060 if (type_check (status, 2, BT_INTEGER) == FAILURE)
3063 if (scalar_check (status, 2) == FAILURE)
3071 gfc_check_repeat (gfc_expr *x, gfc_expr *y)
3073 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3076 if (scalar_check (x, 0) == FAILURE)
3079 if (type_check (y, 0, BT_INTEGER) == FAILURE)
3082 if (scalar_check (y, 1) == FAILURE)
3090 gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
3091 gfc_expr *pad, gfc_expr *order)
3097 if (array_check (source, 0) == FAILURE)
3100 if (rank_check (shape, 1, 1) == FAILURE)
3103 if (type_check (shape, 1, BT_INTEGER) == FAILURE)
3106 if (gfc_array_size (shape, &size) != SUCCESS)
3108 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
3109 "array of constant size", &shape->where);
3113 shape_size = mpz_get_ui (size);
3116 if (shape_size <= 0)
3118 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
3119 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3123 else if (shape_size > GFC_MAX_DIMENSIONS)
3125 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
3126 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
3129 else if (shape->expr_type == EXPR_ARRAY)
3133 for (i = 0; i < shape_size; ++i)
3135 e = gfc_constructor_lookup_expr (shape->value.constructor, i);
3136 if (e->expr_type != EXPR_CONSTANT)
3139 gfc_extract_int (e, &extent);
3142 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3143 "negative element (%d)",
3144 gfc_current_intrinsic_arg[1]->name,
3145 gfc_current_intrinsic, &e->where, extent);
3153 if (same_type_check (source, 0, pad, 2) == FAILURE)
3156 if (array_check (pad, 2) == FAILURE)
3162 if (array_check (order, 3) == FAILURE)
3165 if (type_check (order, 3, BT_INTEGER) == FAILURE)
3168 if (order->expr_type == EXPR_ARRAY)
3170 int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
3173 for (i = 0; i < GFC_MAX_DIMENSIONS; ++i)
3176 gfc_array_size (order, &size);
3177 order_size = mpz_get_ui (size);
3180 if (order_size != shape_size)
3182 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3183 "has wrong number of elements (%d/%d)",
3184 gfc_current_intrinsic_arg[3]->name,
3185 gfc_current_intrinsic, &order->where,
3186 order_size, shape_size);
3190 for (i = 1; i <= order_size; ++i)
3192 e = gfc_constructor_lookup_expr (order->value.constructor, i-1);
3193 if (e->expr_type != EXPR_CONSTANT)
3196 gfc_extract_int (e, &dim);
3198 if (dim < 1 || dim > order_size)
3200 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3201 "has out-of-range dimension (%d)",
3202 gfc_current_intrinsic_arg[3]->name,
3203 gfc_current_intrinsic, &e->where, dim);
3207 if (perm[dim-1] != 0)
3209 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3210 "invalid permutation of dimensions (dimension "
3212 gfc_current_intrinsic_arg[3]->name,
3213 gfc_current_intrinsic, &e->where, dim);
3222 if (pad == NULL && shape->expr_type == EXPR_ARRAY
3223 && gfc_is_constant_expr (shape)
3224 && !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
3225 && source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
3227 /* Check the match in size between source and destination. */
3228 if (gfc_array_size (source, &nelems) == SUCCESS)
3234 mpz_init_set_ui (size, 1);
3235 for (c = gfc_constructor_first (shape->value.constructor);
3236 c; c = gfc_constructor_next (c))
3237 mpz_mul (size, size, c->expr->value.integer);
3239 test = mpz_cmp (nelems, size) < 0 && mpz_cmp_ui (size, 0) > 0;
3245 gfc_error ("Without padding, there are not enough elements "
3246 "in the intrinsic RESHAPE source at %L to match "
3247 "the shape", &source->where);
3258 gfc_check_same_type_as (gfc_expr *a, gfc_expr *b)
3261 if (a->ts.type != BT_DERIVED && a->ts.type != BT_CLASS)
3263 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3264 "must be of a derived type",
3265 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3270 if (!gfc_type_is_extensible (a->ts.u.derived))
3272 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3273 "must be of an extensible type",
3274 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3279 if (b->ts.type != BT_DERIVED && b->ts.type != BT_CLASS)
3281 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3282 "must be of a derived type",
3283 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3288 if (!gfc_type_is_extensible (b->ts.u.derived))
3290 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3291 "must be of an extensible type",
3292 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
3302 gfc_check_scale (gfc_expr *x, gfc_expr *i)
3304 if (type_check (x, 0, BT_REAL) == FAILURE)
3307 if (type_check (i, 1, BT_INTEGER) == FAILURE)
3315 gfc_check_scan (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
3317 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
3320 if (type_check (y, 1, BT_CHARACTER) == FAILURE)
3323 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
3326 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
3328 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3329 "with KIND argument at %L",
3330 gfc_current_intrinsic, &kind->where) == FAILURE)
3333 if (same_type_check (x, 0, y, 1) == FAILURE)
3341 gfc_check_secnds (gfc_expr *r)
3343 if (type_check (r, 0, BT_REAL) == FAILURE)
3346 if (kind_value_check (r, 0, 4) == FAILURE)
3349 if (scalar_check (r, 0) == FAILURE)
3357 gfc_check_selected_char_kind (gfc_expr *name)
3359 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3362 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3365 if (scalar_check (name, 0) == FAILURE)
3373 gfc_check_selected_int_kind (gfc_expr *r)
3375 if (type_check (r, 0, BT_INTEGER) == FAILURE)
3378 if (scalar_check (r, 0) == FAILURE)
3386 gfc_check_selected_real_kind (gfc_expr *p, gfc_expr *r, gfc_expr *radix)
3388 if (p == NULL && r == NULL
3389 && gfc_notify_std (GFC_STD_F2008, "Fortran 2008: SELECTED_REAL_KIND with"
3390 " neither 'P' nor 'R' argument at %L",
3391 gfc_current_intrinsic_where) == FAILURE)
3396 if (type_check (p, 0, BT_INTEGER) == FAILURE)
3399 if (scalar_check (p, 0) == FAILURE)
3405 if (type_check (r, 1, BT_INTEGER) == FAILURE)
3408 if (scalar_check (r, 1) == FAILURE)
3414 if (type_check (radix, 1, BT_INTEGER) == FAILURE)
3417 if (scalar_check (radix, 1) == FAILURE)
3420 if (gfc_notify_std (GFC_STD_F2008, "Fortran 2008: '%s' intrinsic with "
3421 "RADIX argument at %L", gfc_current_intrinsic,
3422 &radix->where) == FAILURE)
3431 gfc_check_set_exponent (gfc_expr *x, gfc_expr *i)
3433 if (type_check (x, 0, BT_REAL) == FAILURE)
3436 if (type_check (i, 1, BT_INTEGER) == FAILURE)
3444 gfc_check_shape (gfc_expr *source, gfc_expr *kind)
3448 if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
3451 ar = gfc_find_array_ref (source);
3453 if (ar->as && ar->as->type == AS_ASSUMED_SIZE && ar->type == AR_FULL)
3455 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
3456 "an assumed size array", &source->where);
3460 if (kind_check (kind, 1, BT_INTEGER) == FAILURE)
3462 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3463 "with KIND argument at %L",
3464 gfc_current_intrinsic, &kind->where) == FAILURE)
3472 gfc_check_shift (gfc_expr *i, gfc_expr *shift)
3474 if (type_check (i, 0, BT_INTEGER) == FAILURE)
3477 if (type_check (shift, 0, BT_INTEGER) == FAILURE)
3480 if (nonnegative_check ("SHIFT", shift) == FAILURE)
3483 if (less_than_bitsize1 ("I", i, "SHIFT", shift, true) == FAILURE)
3491 gfc_check_sign (gfc_expr *a, gfc_expr *b)
3493 if (int_or_real_check (a, 0) == FAILURE)
3496 if (same_type_check (a, 0, b, 1) == FAILURE)
3504 gfc_check_size (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
3506 if (array_check (array, 0) == FAILURE)
3509 if (dim_check (dim, 1, true) == FAILURE)
3512 if (dim_rank_check (dim, array, 0) == FAILURE)
3515 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
3517 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
3518 "with KIND argument at %L",
3519 gfc_current_intrinsic, &kind->where) == FAILURE)
3528 gfc_check_sizeof (gfc_expr *arg)
3530 if (arg->ts.type == BT_PROCEDURE)
3532 gfc_error ("'%s' argument of '%s' intrinsic at %L may not be a procedure",
3533 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3542 gfc_check_c_sizeof (gfc_expr *arg)
3544 if (gfc_verify_c_interop (&arg->ts) != SUCCESS)
3546 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an "
3547 "interoperable data entity",
3548 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
3557 gfc_check_sleep_sub (gfc_expr *seconds)
3559 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
3562 if (scalar_check (seconds, 0) == FAILURE)
3569 gfc_check_sngl (gfc_expr *a)
3571 if (type_check (a, 0, BT_REAL) == FAILURE)
3574 if ((a->ts.kind != gfc_default_double_kind)
3575 && gfc_notify_std (GFC_STD_GNU, "GNU extension: non double precision "
3576 "REAL argument to %s intrinsic at %L",
3577 gfc_current_intrinsic, &a->where) == FAILURE)
3584 gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
3586 if (source->rank >= GFC_MAX_DIMENSIONS)
3588 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
3589 "than rank %d", gfc_current_intrinsic_arg[0]->name,
3590 gfc_current_intrinsic, &source->where, GFC_MAX_DIMENSIONS);
3598 if (dim_check (dim, 1, false) == FAILURE)
3601 /* dim_rank_check() does not apply here. */
3603 && dim->expr_type == EXPR_CONSTANT
3604 && (mpz_cmp_ui (dim->value.integer, 1) < 0
3605 || mpz_cmp_ui (dim->value.integer, source->rank + 1) > 0))
3607 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
3608 "dimension index", gfc_current_intrinsic_arg[1]->name,
3609 gfc_current_intrinsic, &dim->where);
3613 if (type_check (ncopies, 2, BT_INTEGER) == FAILURE)
3616 if (scalar_check (ncopies, 2) == FAILURE)
3623 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3627 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
3629 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3632 if (scalar_check (unit, 0) == FAILURE)
3635 if (type_check (c, 1, BT_CHARACTER) == FAILURE)
3637 if (kind_value_check (c, 1, gfc_default_character_kind) == FAILURE)
3643 if (type_check (status, 2, BT_INTEGER) == FAILURE
3644 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE
3645 || scalar_check (status, 2) == FAILURE)
3653 gfc_check_fgetputc (gfc_expr *unit, gfc_expr *c)
3655 return gfc_check_fgetputc_sub (unit, c, NULL);
3660 gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
3662 if (type_check (c, 0, BT_CHARACTER) == FAILURE)
3664 if (kind_value_check (c, 0, gfc_default_character_kind) == FAILURE)
3670 if (type_check (status, 1, BT_INTEGER) == FAILURE
3671 || kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE
3672 || scalar_check (status, 1) == FAILURE)
3680 gfc_check_fgetput (gfc_expr *c)
3682 return gfc_check_fgetput_sub (c, NULL);
3687 gfc_check_fseek_sub (gfc_expr *unit, gfc_expr *offset, gfc_expr *whence, gfc_expr *status)
3689 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3692 if (scalar_check (unit, 0) == FAILURE)
3695 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3698 if (scalar_check (offset, 1) == FAILURE)
3701 if (type_check (whence, 2, BT_INTEGER) == FAILURE)
3704 if (scalar_check (whence, 2) == FAILURE)
3710 if (type_check (status, 3, BT_INTEGER) == FAILURE)
3713 if (kind_value_check (status, 3, 4) == FAILURE)
3716 if (scalar_check (status, 3) == FAILURE)
3725 gfc_check_fstat (gfc_expr *unit, gfc_expr *array)
3727 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3730 if (scalar_check (unit, 0) == FAILURE)
3733 if (type_check (array, 1, BT_INTEGER) == FAILURE
3734 || kind_value_check (unit, 0, gfc_default_integer_kind) == FAILURE)
3737 if (array_check (array, 1) == FAILURE)
3745 gfc_check_fstat_sub (gfc_expr *unit, gfc_expr *array, gfc_expr *status)
3747 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3750 if (scalar_check (unit, 0) == FAILURE)
3753 if (type_check (array, 1, BT_INTEGER) == FAILURE
3754 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3757 if (array_check (array, 1) == FAILURE)
3763 if (type_check (status, 2, BT_INTEGER) == FAILURE
3764 || kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
3767 if (scalar_check (status, 2) == FAILURE)
3775 gfc_check_ftell (gfc_expr *unit)
3777 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3780 if (scalar_check (unit, 0) == FAILURE)
3788 gfc_check_ftell_sub (gfc_expr *unit, gfc_expr *offset)
3790 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
3793 if (scalar_check (unit, 0) == FAILURE)
3796 if (type_check (offset, 1, BT_INTEGER) == FAILURE)
3799 if (scalar_check (offset, 1) == FAILURE)
3807 gfc_check_stat (gfc_expr *name, gfc_expr *array)
3809 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3811 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3814 if (type_check (array, 1, BT_INTEGER) == FAILURE
3815 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3818 if (array_check (array, 1) == FAILURE)
3826 gfc_check_stat_sub (gfc_expr *name, gfc_expr *array, gfc_expr *status)
3828 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
3830 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
3833 if (type_check (array, 1, BT_INTEGER) == FAILURE
3834 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3837 if (array_check (array, 1) == FAILURE)
3843 if (type_check (status, 2, BT_INTEGER) == FAILURE
3844 || kind_value_check (array, 1, gfc_default_integer_kind) == FAILURE)
3847 if (scalar_check (status, 2) == FAILURE)
3855 gfc_check_image_index (gfc_expr *coarray, gfc_expr *sub)
3859 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3861 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3865 if (coarray_check (coarray, 0) == FAILURE)
3870 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3871 gfc_current_intrinsic_arg[1]->name, &sub->where);
3875 if (gfc_array_size (sub, &nelems) == SUCCESS)
3877 int corank = gfc_get_corank (coarray);
3879 if (mpz_cmp_ui (nelems, corank) != 0)
3881 gfc_error ("The number of array elements of the SUB argument to "
3882 "IMAGE_INDEX at %L shall be %d (corank) not %d",
3883 &sub->where, corank, (int) mpz_get_si (nelems));
3895 gfc_check_this_image (gfc_expr *coarray, gfc_expr *dim)
3897 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
3899 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3903 if (dim != NULL && coarray == NULL)
3905 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3906 "intrinsic at %L", &dim->where);
3910 if (coarray == NULL)
3913 if (coarray_check (coarray, 0) == FAILURE)
3918 if (dim_check (dim, 1, false) == FAILURE)
3921 if (dim_corank_check (dim, coarray) == FAILURE)
3928 /* Calculate the sizes for transfer, used by gfc_check_transfer and also
3929 by gfc_simplify_transfer. Return FAILURE if we cannot do so. */
3932 gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size,
3933 size_t *source_size, size_t *result_size,
3934 size_t *result_length_p)
3937 size_t result_elt_size;
3939 gfc_expr *mold_element;
3941 if (source->expr_type == EXPR_FUNCTION)
3944 /* Calculate the size of the source. */
3945 if (source->expr_type == EXPR_ARRAY
3946 && gfc_array_size (source, &tmp) == FAILURE)
3949 *source_size = gfc_target_expr_size (source);
3951 mold_element = mold->expr_type == EXPR_ARRAY
3952 ? gfc_constructor_first (mold->value.constructor)->expr
3955 /* Determine the size of the element. */
3956 result_elt_size = gfc_target_expr_size (mold_element);
3957 if (result_elt_size == 0)
3960 if (mold->expr_type == EXPR_ARRAY || mold->rank || size)
3965 result_length = (size_t)mpz_get_ui (size->value.integer);
3968 result_length = *source_size / result_elt_size;
3969 if (result_length * result_elt_size < *source_size)
3973 *result_size = result_length * result_elt_size;
3974 if (result_length_p)
3975 *result_length_p = result_length;
3978 *result_size = result_elt_size;
3985 gfc_check_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size)
3990 if (mold->ts.type == BT_HOLLERITH)
3992 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3993 &mold->where, gfc_basic_typename (BT_HOLLERITH));
3999 if (type_check (size, 2, BT_INTEGER) == FAILURE)
4002 if (scalar_check (size, 2) == FAILURE)
4005 if (nonoptional_check (size, 2) == FAILURE)
4009 if (!gfc_option.warn_surprising)
4012 /* If we can't calculate the sizes, we cannot check any more.
4013 Return SUCCESS for that case. */
4015 if (gfc_calculate_transfer_sizes (source, mold, size, &source_size,
4016 &result_size, NULL) == FAILURE)
4019 if (source_size < result_size)
4020 gfc_warning("Intrinsic TRANSFER at %L has partly undefined result: "
4021 "source size %ld < result size %ld", &source->where,
4022 (long) source_size, (long) result_size);
4029 gfc_check_transpose (gfc_expr *matrix)
4031 if (rank_check (matrix, 0, 2) == FAILURE)
4039 gfc_check_ubound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
4041 if (array_check (array, 0) == FAILURE)
4044 if (dim_check (dim, 1, false) == FAILURE)
4047 if (dim_rank_check (dim, array, 0) == FAILURE)
4050 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
4052 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
4053 "with KIND argument at %L",
4054 gfc_current_intrinsic, &kind->where) == FAILURE)
4062 gfc_check_ucobound (gfc_expr *coarray, gfc_expr *dim, gfc_expr *kind)
4064 if (gfc_option.coarray == GFC_FCOARRAY_NONE)
4066 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
4070 if (coarray_check (coarray, 0) == FAILURE)
4075 if (dim_check (dim, 1, false) == FAILURE)
4078 if (dim_corank_check (dim, coarray) == FAILURE)
4082 if (kind_check (kind, 2, BT_INTEGER) == FAILURE)
4090 gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
4094 if (rank_check (vector, 0, 1) == FAILURE)
4097 if (array_check (mask, 1) == FAILURE)
4100 if (type_check (mask, 1, BT_LOGICAL) == FAILURE)
4103 if (same_type_check (vector, 0, field, 2) == FAILURE)
4106 if (mask->expr_type == EXPR_ARRAY
4107 && gfc_array_size (vector, &vector_size) == SUCCESS)
4109 int mask_true_count = 0;
4110 gfc_constructor *mask_ctor;
4111 mask_ctor = gfc_constructor_first (mask->value.constructor);
4114 if (mask_ctor->expr->expr_type != EXPR_CONSTANT)
4116 mask_true_count = 0;
4120 if (mask_ctor->expr->value.logical)
4123 mask_ctor = gfc_constructor_next (mask_ctor);
4126 if (mpz_get_si (vector_size) < mask_true_count)
4128 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
4129 "provide at least as many elements as there "
4130 "are .TRUE. values in '%s' (%ld/%d)",
4131 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4132 &vector->where, gfc_current_intrinsic_arg[1]->name,
4133 mpz_get_si (vector_size), mask_true_count);
4137 mpz_clear (vector_size);
4140 if (mask->rank != field->rank && field->rank != 0)
4142 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
4143 "the same rank as '%s' or be a scalar",
4144 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
4145 &field->where, gfc_current_intrinsic_arg[1]->name);
4149 if (mask->rank == field->rank)
4152 for (i = 0; i < field->rank; i++)
4153 if (! identical_dimen_shape (mask, i, field, i))
4155 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
4156 "must have identical shape.",
4157 gfc_current_intrinsic_arg[2]->name,
4158 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4168 gfc_check_verify (gfc_expr *x, gfc_expr *y, gfc_expr *z, gfc_expr *kind)
4170 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
4173 if (same_type_check (x, 0, y, 1) == FAILURE)
4176 if (z != NULL && type_check (z, 2, BT_LOGICAL) == FAILURE)
4179 if (kind_check (kind, 3, BT_INTEGER) == FAILURE)
4181 if (kind && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' intrinsic "
4182 "with KIND argument at %L",
4183 gfc_current_intrinsic, &kind->where) == FAILURE)
4191 gfc_check_trim (gfc_expr *x)
4193 if (type_check (x, 0, BT_CHARACTER) == FAILURE)
4196 if (scalar_check (x, 0) == FAILURE)
4204 gfc_check_ttynam (gfc_expr *unit)
4206 if (scalar_check (unit, 0) == FAILURE)
4209 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4216 /* Common check function for the half a dozen intrinsics that have a
4217 single real argument. */
4220 gfc_check_x (gfc_expr *x)
4222 if (type_check (x, 0, BT_REAL) == FAILURE)
4229 /************* Check functions for intrinsic subroutines *************/
4232 gfc_check_cpu_time (gfc_expr *time)
4234 if (scalar_check (time, 0) == FAILURE)
4237 if (type_check (time, 0, BT_REAL) == FAILURE)
4240 if (variable_check (time, 0, false) == FAILURE)
4248 gfc_check_date_and_time (gfc_expr *date, gfc_expr *time,
4249 gfc_expr *zone, gfc_expr *values)
4253 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
4255 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
4257 if (scalar_check (date, 0) == FAILURE)
4259 if (variable_check (date, 0, false) == FAILURE)
4265 if (type_check (time, 1, BT_CHARACTER) == FAILURE)
4267 if (kind_value_check (time, 1, gfc_default_character_kind) == FAILURE)
4269 if (scalar_check (time, 1) == FAILURE)
4271 if (variable_check (time, 1, false) == FAILURE)
4277 if (type_check (zone, 2, BT_CHARACTER) == FAILURE)
4279 if (kind_value_check (zone, 2, gfc_default_character_kind) == FAILURE)
4281 if (scalar_check (zone, 2) == FAILURE)
4283 if (variable_check (zone, 2, false) == FAILURE)
4289 if (type_check (values, 3, BT_INTEGER) == FAILURE)
4291 if (array_check (values, 3) == FAILURE)
4293 if (rank_check (values, 3, 1) == FAILURE)
4295 if (variable_check (values, 3, false) == FAILURE)
4304 gfc_check_mvbits (gfc_expr *from, gfc_expr *frompos, gfc_expr *len,
4305 gfc_expr *to, gfc_expr *topos)
4307 if (type_check (from, 0, BT_INTEGER) == FAILURE)
4310 if (type_check (frompos, 1, BT_INTEGER) == FAILURE)
4313 if (type_check (len, 2, BT_INTEGER) == FAILURE)
4316 if (same_type_check (from, 0, to, 3) == FAILURE)
4319 if (variable_check (to, 3, false) == FAILURE)
4322 if (type_check (topos, 4, BT_INTEGER) == FAILURE)
4325 if (nonnegative_check ("frompos", frompos) == FAILURE)
4328 if (nonnegative_check ("topos", topos) == FAILURE)
4331 if (nonnegative_check ("len", len) == FAILURE)
4334 if (less_than_bitsize2 ("from", from, "frompos", frompos, "len", len)
4338 if (less_than_bitsize2 ("to", to, "topos", topos, "len", len) == FAILURE)
4346 gfc_check_random_number (gfc_expr *harvest)
4348 if (type_check (harvest, 0, BT_REAL) == FAILURE)
4351 if (variable_check (harvest, 0, false) == FAILURE)
4359 gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
4361 unsigned int nargs = 0, kiss_size;
4362 locus *where = NULL;
4363 mpz_t put_size, get_size;
4364 bool have_gfc_real_16; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
4366 have_gfc_real_16 = gfc_validate_kind (BT_REAL, 16, true) != -1;
4368 /* Keep the number of bytes in sync with kiss_size in
4369 libgfortran/intrinsics/random.c. */
4370 kiss_size = (have_gfc_real_16 ? 48 : 32) / gfc_default_integer_kind;
4374 if (size->expr_type != EXPR_VARIABLE
4375 || !size->symtree->n.sym->attr.optional)
4378 if (scalar_check (size, 0) == FAILURE)
4381 if (type_check (size, 0, BT_INTEGER) == FAILURE)
4384 if (variable_check (size, 0, false) == FAILURE)
4387 if (kind_value_check (size, 0, gfc_default_integer_kind) == FAILURE)
4393 if (put->expr_type != EXPR_VARIABLE
4394 || !put->symtree->n.sym->attr.optional)
4397 where = &put->where;
4400 if (array_check (put, 1) == FAILURE)
4403 if (rank_check (put, 1, 1) == FAILURE)
4406 if (type_check (put, 1, BT_INTEGER) == FAILURE)
4409 if (kind_value_check (put, 1, gfc_default_integer_kind) == FAILURE)
4412 if (gfc_array_size (put, &put_size) == SUCCESS
4413 && mpz_get_ui (put_size) < kiss_size)
4414 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4415 "too small (%i/%i)",
4416 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
4417 where, (int) mpz_get_ui (put_size), kiss_size);
4422 if (get->expr_type != EXPR_VARIABLE
4423 || !get->symtree->n.sym->attr.optional)
4426 where = &get->where;
4429 if (array_check (get, 2) == FAILURE)
4432 if (rank_check (get, 2, 1) == FAILURE)
4435 if (type_check (get, 2, BT_INTEGER) == FAILURE)
4438 if (variable_check (get, 2, false) == FAILURE)
4441 if (kind_value_check (get, 2, gfc_default_integer_kind) == FAILURE)
4444 if (gfc_array_size (get, &get_size) == SUCCESS
4445 && mpz_get_ui (get_size) < kiss_size)
4446 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4447 "too small (%i/%i)",
4448 gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
4449 where, (int) mpz_get_ui (get_size), kiss_size);
4452 /* RANDOM_SEED may not have more than one non-optional argument. */
4454 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic, where);
4461 gfc_check_second_sub (gfc_expr *time)
4463 if (scalar_check (time, 0) == FAILURE)
4466 if (type_check (time, 0, BT_REAL) == FAILURE)
4469 if (kind_value_check(time, 0, 4) == FAILURE)
4476 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
4477 count, count_rate, and count_max are all optional arguments */
4480 gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
4481 gfc_expr *count_max)
4485 if (scalar_check (count, 0) == FAILURE)
4488 if (type_check (count, 0, BT_INTEGER) == FAILURE)
4491 if (variable_check (count, 0, false) == FAILURE)
4495 if (count_rate != NULL)
4497 if (scalar_check (count_rate, 1) == FAILURE)
4500 if (type_check (count_rate, 1, BT_INTEGER) == FAILURE)
4503 if (variable_check (count_rate, 1, false) == FAILURE)
4507 && same_type_check (count, 0, count_rate, 1) == FAILURE)
4512 if (count_max != NULL)
4514 if (scalar_check (count_max, 2) == FAILURE)
4517 if (type_check (count_max, 2, BT_INTEGER) == FAILURE)
4520 if (variable_check (count_max, 2, false) == FAILURE)
4524 && same_type_check (count, 0, count_max, 2) == FAILURE)
4527 if (count_rate != NULL
4528 && same_type_check (count_rate, 1, count_max, 2) == FAILURE)
4537 gfc_check_irand (gfc_expr *x)
4542 if (scalar_check (x, 0) == FAILURE)
4545 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4548 if (kind_value_check(x, 0, 4) == FAILURE)
4556 gfc_check_alarm_sub (gfc_expr *seconds, gfc_expr *handler, gfc_expr *status)
4558 if (scalar_check (seconds, 0) == FAILURE)
4560 if (type_check (seconds, 0, BT_INTEGER) == FAILURE)
4563 if (int_or_proc_check (handler, 1) == FAILURE)
4565 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
4571 if (scalar_check (status, 2) == FAILURE)
4573 if (type_check (status, 2, BT_INTEGER) == FAILURE)
4575 if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
4583 gfc_check_rand (gfc_expr *x)
4588 if (scalar_check (x, 0) == FAILURE)
4591 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4594 if (kind_value_check(x, 0, 4) == FAILURE)
4602 gfc_check_srand (gfc_expr *x)
4604 if (scalar_check (x, 0) == FAILURE)
4607 if (type_check (x, 0, BT_INTEGER) == FAILURE)
4610 if (kind_value_check(x, 0, 4) == FAILURE)
4618 gfc_check_ctime_sub (gfc_expr *time, gfc_expr *result)
4620 if (scalar_check (time, 0) == FAILURE)
4622 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4625 if (type_check (result, 1, BT_CHARACTER) == FAILURE)
4627 if (kind_value_check (result, 1, gfc_default_character_kind) == FAILURE)
4635 gfc_check_dtime_etime (gfc_expr *x)
4637 if (array_check (x, 0) == FAILURE)
4640 if (rank_check (x, 0, 1) == FAILURE)
4643 if (variable_check (x, 0, false) == FAILURE)
4646 if (type_check (x, 0, BT_REAL) == FAILURE)
4649 if (kind_value_check(x, 0, 4) == FAILURE)
4657 gfc_check_dtime_etime_sub (gfc_expr *values, gfc_expr *time)
4659 if (array_check (values, 0) == FAILURE)
4662 if (rank_check (values, 0, 1) == FAILURE)
4665 if (variable_check (values, 0, false) == FAILURE)
4668 if (type_check (values, 0, BT_REAL) == FAILURE)
4671 if (kind_value_check(values, 0, 4) == FAILURE)
4674 if (scalar_check (time, 1) == FAILURE)
4677 if (type_check (time, 1, BT_REAL) == FAILURE)
4680 if (kind_value_check(time, 1, 4) == FAILURE)
4688 gfc_check_fdate_sub (gfc_expr *date)
4690 if (type_check (date, 0, BT_CHARACTER) == FAILURE)
4692 if (kind_value_check (date, 0, gfc_default_character_kind) == FAILURE)
4700 gfc_check_gerror (gfc_expr *msg)
4702 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4704 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4712 gfc_check_getcwd_sub (gfc_expr *cwd, gfc_expr *status)
4714 if (type_check (cwd, 0, BT_CHARACTER) == FAILURE)
4716 if (kind_value_check (cwd, 0, gfc_default_character_kind) == FAILURE)
4722 if (scalar_check (status, 1) == FAILURE)
4725 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4733 gfc_check_getarg (gfc_expr *pos, gfc_expr *value)
4735 if (type_check (pos, 0, BT_INTEGER) == FAILURE)
4738 if (pos->ts.kind > gfc_default_integer_kind)
4740 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4741 "not wider than the default kind (%d)",
4742 gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
4743 &pos->where, gfc_default_integer_kind);
4747 if (type_check (value, 1, BT_CHARACTER) == FAILURE)
4749 if (kind_value_check (value, 1, gfc_default_character_kind) == FAILURE)
4757 gfc_check_getlog (gfc_expr *msg)
4759 if (type_check (msg, 0, BT_CHARACTER) == FAILURE)
4761 if (kind_value_check (msg, 0, gfc_default_character_kind) == FAILURE)
4769 gfc_check_exit (gfc_expr *status)
4774 if (type_check (status, 0, BT_INTEGER) == FAILURE)
4777 if (scalar_check (status, 0) == FAILURE)
4785 gfc_check_flush (gfc_expr *unit)
4790 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4793 if (scalar_check (unit, 0) == FAILURE)
4801 gfc_check_free (gfc_expr *i)
4803 if (type_check (i, 0, BT_INTEGER) == FAILURE)
4806 if (scalar_check (i, 0) == FAILURE)
4814 gfc_check_hostnm (gfc_expr *name)
4816 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4818 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4826 gfc_check_hostnm_sub (gfc_expr *name, gfc_expr *status)
4828 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4830 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
4836 if (scalar_check (status, 1) == FAILURE)
4839 if (type_check (status, 1, BT_INTEGER) == FAILURE)
4847 gfc_check_itime_idate (gfc_expr *values)
4849 if (array_check (values, 0) == FAILURE)
4852 if (rank_check (values, 0, 1) == FAILURE)
4855 if (variable_check (values, 0, false) == FAILURE)
4858 if (type_check (values, 0, BT_INTEGER) == FAILURE)
4861 if (kind_value_check(values, 0, gfc_default_integer_kind) == FAILURE)
4869 gfc_check_ltime_gmtime (gfc_expr *time, gfc_expr *values)
4871 if (type_check (time, 0, BT_INTEGER) == FAILURE)
4874 if (kind_value_check(time, 0, gfc_default_integer_kind) == FAILURE)
4877 if (scalar_check (time, 0) == FAILURE)
4880 if (array_check (values, 1) == FAILURE)
4883 if (rank_check (values, 1, 1) == FAILURE)
4886 if (variable_check (values, 1, false) == FAILURE)
4889 if (type_check (values, 1, BT_INTEGER) == FAILURE)
4892 if (kind_value_check(values, 1, gfc_default_integer_kind) == FAILURE)
4900 gfc_check_ttynam_sub (gfc_expr *unit, gfc_expr *name)
4902 if (scalar_check (unit, 0) == FAILURE)
4905 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4908 if (type_check (name, 1, BT_CHARACTER) == FAILURE)
4910 if (kind_value_check (name, 1, gfc_default_character_kind) == FAILURE)
4918 gfc_check_isatty (gfc_expr *unit)
4923 if (type_check (unit, 0, BT_INTEGER) == FAILURE)
4926 if (scalar_check (unit, 0) == FAILURE)
4934 gfc_check_isnan (gfc_expr *x)
4936 if (type_check (x, 0, BT_REAL) == FAILURE)
4944 gfc_check_perror (gfc_expr *string)
4946 if (type_check (string, 0, BT_CHARACTER) == FAILURE)
4948 if (kind_value_check (string, 0, gfc_default_character_kind) == FAILURE)
4956 gfc_check_umask (gfc_expr *mask)
4958 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4961 if (scalar_check (mask, 0) == FAILURE)
4969 gfc_check_umask_sub (gfc_expr *mask, gfc_expr *old)
4971 if (type_check (mask, 0, BT_INTEGER) == FAILURE)
4974 if (scalar_check (mask, 0) == FAILURE)
4980 if (scalar_check (old, 1) == FAILURE)
4983 if (type_check (old, 1, BT_INTEGER) == FAILURE)
4991 gfc_check_unlink (gfc_expr *name)
4993 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
4995 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
5003 gfc_check_unlink_sub (gfc_expr *name, gfc_expr *status)
5005 if (type_check (name, 0, BT_CHARACTER) == FAILURE)
5007 if (kind_value_check (name, 0, gfc_default_character_kind) == FAILURE)
5013 if (scalar_check (status, 1) == FAILURE)
5016 if (type_check (status, 1, BT_INTEGER) == FAILURE)
5024 gfc_check_signal (gfc_expr *number, gfc_expr *handler)
5026 if (scalar_check (number, 0) == FAILURE)
5028 if (type_check (number, 0, BT_INTEGER) == FAILURE)
5031 if (int_or_proc_check (handler, 1) == FAILURE)
5033 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
5041 gfc_check_signal_sub (gfc_expr *number, gfc_expr *handler, gfc_expr *status)
5043 if (scalar_check (number, 0) == FAILURE)
5045 if (type_check (number, 0, BT_INTEGER) == FAILURE)
5048 if (int_or_proc_check (handler, 1) == FAILURE)
5050 if (handler->ts.type == BT_INTEGER && scalar_check (handler, 1) == FAILURE)
5056 if (type_check (status, 2, BT_INTEGER) == FAILURE)
5058 if (scalar_check (status, 2) == FAILURE)
5066 gfc_check_system_sub (gfc_expr *cmd, gfc_expr *status)
5068 if (type_check (cmd, 0, BT_CHARACTER) == FAILURE)
5070 if (kind_value_check (cmd, 0, gfc_default_character_kind) == FAILURE)
5073 if (scalar_check (status, 1) == FAILURE)
5076 if (type_check (status, 1, BT_INTEGER) == FAILURE)
5079 if (kind_value_check (status, 1, gfc_default_integer_kind) == FAILURE)
5086 /* This is used for the GNU intrinsics AND, OR and XOR. */
5088 gfc_check_and (gfc_expr *i, gfc_expr *j)
5090 if (i->ts.type != BT_INTEGER && i->ts.type != BT_LOGICAL)
5092 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
5093 "or LOGICAL", gfc_current_intrinsic_arg[0]->name,
5094 gfc_current_intrinsic, &i->where);
5098 if (j->ts.type != BT_INTEGER && j->ts.type != BT_LOGICAL)
5100 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
5101 "or LOGICAL", gfc_current_intrinsic_arg[1]->name,
5102 gfc_current_intrinsic, &j->where);
5106 if (i->ts.type != j->ts.type)
5108 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
5109 "have the same type", gfc_current_intrinsic_arg[0]->name,
5110 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
5115 if (scalar_check (i, 0) == FAILURE)
5118 if (scalar_check (j, 1) == FAILURE)
5126 gfc_check_storage_size (gfc_expr *a ATTRIBUTE_UNUSED, gfc_expr *kind)
5131 if (type_check (kind, 1, BT_INTEGER) == FAILURE)
5134 if (scalar_check (kind, 1) == FAILURE)
5137 if (kind->expr_type != EXPR_CONSTANT)
5139 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
5140 gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,