2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught & Katherine Holcomb
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* These functions check to see if an argument list is compatible with
24 a particular intrinsic function or subroutine. Presence of
25 required arguments has already been established, the argument list
26 has been sorted into the right order and has NULL arguments in the
27 correct places for missing optional arguments. */
33 #include "intrinsic.h"
34 #include "constructor.h"
37 /* Make sure an expression is a scalar. */
40 scalar_check (gfc_expr
*e
, int n
)
45 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
46 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
, &e
->where
);
52 /* Check the type of an expression. */
55 type_check (gfc_expr
*e
, int n
, bt type
)
57 if (e
->ts
.type
== type
)
60 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
61 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
, &e
->where
,
62 gfc_basic_typename (type
));
68 /* Check that the expression is a numeric type. */
71 numeric_check (gfc_expr
*e
, int n
)
73 if (gfc_numeric_ts (&e
->ts
))
76 /* If the expression has not got a type, check if its namespace can
77 offer a default type. */
78 if ((e
->expr_type
== EXPR_VARIABLE
|| e
->expr_type
== EXPR_VARIABLE
)
79 && e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
80 && gfc_set_default_type (e
->symtree
->n
.sym
, 0,
81 e
->symtree
->n
.sym
->ns
) == SUCCESS
82 && gfc_numeric_ts (&e
->symtree
->n
.sym
->ts
))
84 e
->ts
= e
->symtree
->n
.sym
->ts
;
88 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
89 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
, &e
->where
);
95 /* Check that an expression is integer or real. */
98 int_or_real_check (gfc_expr
*e
, int n
)
100 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
)
102 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
103 "or REAL", gfc_current_intrinsic_arg
[n
],
104 gfc_current_intrinsic
, &e
->where
);
112 /* Check that an expression is real or complex. */
115 real_or_complex_check (gfc_expr
*e
, int n
)
117 if (e
->ts
.type
!= BT_REAL
&& e
->ts
.type
!= BT_COMPLEX
)
119 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
120 "or COMPLEX", gfc_current_intrinsic_arg
[n
],
121 gfc_current_intrinsic
, &e
->where
);
129 /* Check that the expression is an optional constant integer
130 and that it specifies a valid kind for that type. */
133 kind_check (gfc_expr
*k
, int n
, bt type
)
140 if (type_check (k
, n
, BT_INTEGER
) == FAILURE
)
143 if (scalar_check (k
, n
) == FAILURE
)
146 if (k
->expr_type
!= EXPR_CONSTANT
)
148 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
149 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
154 if (gfc_extract_int (k
, &kind
) != NULL
155 || gfc_validate_kind (type
, kind
, true) < 0)
157 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type
),
166 /* Make sure the expression is a double precision real. */
169 double_check (gfc_expr
*d
, int n
)
171 if (type_check (d
, n
, BT_REAL
) == FAILURE
)
174 if (d
->ts
.kind
!= gfc_default_double_kind
)
176 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
177 "precision", gfc_current_intrinsic_arg
[n
],
178 gfc_current_intrinsic
, &d
->where
);
186 /* Check whether an expression is a coarray (without array designator). */
189 is_coarray (gfc_expr
*e
)
191 bool coarray
= false;
194 if (e
->expr_type
!= EXPR_VARIABLE
)
197 coarray
= e
->symtree
->n
.sym
->attr
.codimension
;
199 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
201 if (ref
->type
== REF_COMPONENT
)
202 coarray
= ref
->u
.c
.component
->attr
.codimension
;
203 else if (ref
->type
!= REF_ARRAY
|| ref
->u
.ar
.dimen
!= 0
204 || ref
->u
.ar
.codimen
!= 0)
212 /* Make sure the expression is a logical array. */
215 logical_array_check (gfc_expr
*array
, int n
)
217 if (array
->ts
.type
!= BT_LOGICAL
|| array
->rank
== 0)
219 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
220 "array", gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
229 /* Make sure an expression is an array. */
232 array_check (gfc_expr
*e
, int n
)
237 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
238 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
, &e
->where
);
244 /* Make sure two expressions have the same type. */
247 same_type_check (gfc_expr
*e
, int n
, gfc_expr
*f
, int m
)
249 if (gfc_compare_types (&e
->ts
, &f
->ts
))
252 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
253 "and kind as '%s'", gfc_current_intrinsic_arg
[m
],
254 gfc_current_intrinsic
, &f
->where
, gfc_current_intrinsic_arg
[n
]);
260 /* Make sure that an expression has a certain (nonzero) rank. */
263 rank_check (gfc_expr
*e
, int n
, int rank
)
268 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
269 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
276 /* Make sure a variable expression is not an optional dummy argument. */
279 nonoptional_check (gfc_expr
*e
, int n
)
281 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.optional
)
283 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
284 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
288 /* TODO: Recursive check on nonoptional variables? */
294 /* Check that an expression has a particular kind. */
297 kind_value_check (gfc_expr
*e
, int n
, int k
)
302 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
303 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
310 /* Make sure an expression is a variable. */
313 variable_check (gfc_expr
*e
, int n
)
315 if ((e
->expr_type
== EXPR_VARIABLE
316 && e
->symtree
->n
.sym
->attr
.flavor
!= FL_PARAMETER
)
317 || (e
->expr_type
== EXPR_FUNCTION
318 && e
->symtree
->n
.sym
->result
== e
->symtree
->n
.sym
))
321 if (e
->expr_type
== EXPR_VARIABLE
322 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
324 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
325 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
330 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
331 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
, &e
->where
);
337 /* Check the common DIM parameter for correctness. */
340 dim_check (gfc_expr
*dim
, int n
, bool optional
)
345 if (type_check (dim
, n
, BT_INTEGER
) == FAILURE
)
348 if (scalar_check (dim
, n
) == FAILURE
)
351 if (!optional
&& nonoptional_check (dim
, n
) == FAILURE
)
358 /* If a coarray DIM parameter is a constant, make sure that it is greater than
359 zero and less than or equal to the corank of the given array. */
362 dim_corank_check (gfc_expr
*dim
, gfc_expr
*array
)
367 gcc_assert (array
->expr_type
== EXPR_VARIABLE
);
369 if (dim
->expr_type
!= EXPR_CONSTANT
)
372 ar
= gfc_find_array_ref (array
);
373 corank
= ar
->as
->corank
;
375 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
376 || mpz_cmp_ui (dim
->value
.integer
, corank
) > 0)
378 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
379 "codimension index", gfc_current_intrinsic
, &dim
->where
);
388 /* If a DIM parameter is a constant, make sure that it is greater than
389 zero and less than or equal to the rank of the given array. If
390 allow_assumed is zero then dim must be less than the rank of the array
391 for assumed size arrays. */
394 dim_rank_check (gfc_expr
*dim
, gfc_expr
*array
, int allow_assumed
)
402 if (dim
->expr_type
!= EXPR_CONSTANT
403 || (array
->expr_type
!= EXPR_VARIABLE
404 && array
->expr_type
!= EXPR_ARRAY
))
408 if (array
->expr_type
== EXPR_VARIABLE
)
410 ar
= gfc_find_array_ref (array
);
411 if (ar
->as
->type
== AS_ASSUMED_SIZE
413 && ar
->type
!= AR_ELEMENT
414 && ar
->type
!= AR_SECTION
)
418 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
419 || mpz_cmp_ui (dim
->value
.integer
, rank
) > 0)
421 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
422 "dimension index", gfc_current_intrinsic
, &dim
->where
);
431 /* Compare the size of a along dimension ai with the size of b along
432 dimension bi, returning 0 if they are known not to be identical,
433 and 1 if they are identical, or if this cannot be determined. */
436 identical_dimen_shape (gfc_expr
*a
, int ai
, gfc_expr
*b
, int bi
)
438 mpz_t a_size
, b_size
;
441 gcc_assert (a
->rank
> ai
);
442 gcc_assert (b
->rank
> bi
);
446 if (gfc_array_dimen_size (a
, ai
, &a_size
) == SUCCESS
)
448 if (gfc_array_dimen_size (b
, bi
, &b_size
) == SUCCESS
)
450 if (mpz_cmp (a_size
, b_size
) != 0)
461 /* Check whether two character expressions have the same length;
462 returns SUCCESS if they have or if the length cannot be determined. */
465 gfc_check_same_strlen (const gfc_expr
*a
, const gfc_expr
*b
, const char *name
)
470 if (a
->ts
.u
.cl
&& a
->ts
.u
.cl
->length
471 && a
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
472 len_a
= mpz_get_si (a
->ts
.u
.cl
->length
->value
.integer
);
473 else if (a
->expr_type
== EXPR_CONSTANT
474 && (a
->ts
.u
.cl
== NULL
|| a
->ts
.u
.cl
->length
== NULL
))
475 len_a
= a
->value
.character
.length
;
479 if (b
->ts
.u
.cl
&& b
->ts
.u
.cl
->length
480 && b
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
481 len_b
= mpz_get_si (b
->ts
.u
.cl
->length
->value
.integer
);
482 else if (b
->expr_type
== EXPR_CONSTANT
483 && (b
->ts
.u
.cl
== NULL
|| b
->ts
.u
.cl
->length
== NULL
))
484 len_b
= b
->value
.character
.length
;
491 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
492 len_a
, len_b
, name
, &a
->where
);
497 /***** Check functions *****/
499 /* Check subroutine suitable for intrinsics taking a real argument and
500 a kind argument for the result. */
503 check_a_kind (gfc_expr
*a
, gfc_expr
*kind
, bt type
)
505 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
507 if (kind_check (kind
, 1, type
) == FAILURE
)
514 /* Check subroutine suitable for ceiling, floor and nint. */
517 gfc_check_a_ikind (gfc_expr
*a
, gfc_expr
*kind
)
519 return check_a_kind (a
, kind
, BT_INTEGER
);
523 /* Check subroutine suitable for aint, anint. */
526 gfc_check_a_xkind (gfc_expr
*a
, gfc_expr
*kind
)
528 return check_a_kind (a
, kind
, BT_REAL
);
533 gfc_check_abs (gfc_expr
*a
)
535 if (numeric_check (a
, 0) == FAILURE
)
543 gfc_check_achar (gfc_expr
*a
, gfc_expr
*kind
)
545 if (type_check (a
, 0, BT_INTEGER
) == FAILURE
)
547 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
555 gfc_check_access_func (gfc_expr
*name
, gfc_expr
*mode
)
557 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
558 || scalar_check (name
, 0) == FAILURE
)
560 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
563 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
564 || scalar_check (mode
, 1) == FAILURE
)
566 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
574 gfc_check_all_any (gfc_expr
*mask
, gfc_expr
*dim
)
576 if (logical_array_check (mask
, 0) == FAILURE
)
579 if (dim_check (dim
, 1, false) == FAILURE
)
582 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
590 gfc_check_allocated (gfc_expr
*array
)
592 symbol_attribute attr
;
594 if (variable_check (array
, 0) == FAILURE
)
597 attr
= gfc_variable_attr (array
, NULL
);
598 if (!attr
.allocatable
)
600 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
601 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
610 /* Common check function where the first argument must be real or
611 integer and the second argument must be the same as the first. */
614 gfc_check_a_p (gfc_expr
*a
, gfc_expr
*p
)
616 if (int_or_real_check (a
, 0) == FAILURE
)
619 if (a
->ts
.type
!= p
->ts
.type
)
621 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
622 "have the same type", gfc_current_intrinsic_arg
[0],
623 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
628 if (a
->ts
.kind
!= p
->ts
.kind
)
630 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
631 &p
->where
) == FAILURE
)
640 gfc_check_x_yd (gfc_expr
*x
, gfc_expr
*y
)
642 if (double_check (x
, 0) == FAILURE
|| double_check (y
, 1) == FAILURE
)
650 gfc_check_associated (gfc_expr
*pointer
, gfc_expr
*target
)
652 symbol_attribute attr1
, attr2
;
657 where
= &pointer
->where
;
659 if (pointer
->expr_type
== EXPR_VARIABLE
|| pointer
->expr_type
== EXPR_FUNCTION
)
660 attr1
= gfc_expr_attr (pointer
);
661 else if (pointer
->expr_type
== EXPR_NULL
)
664 gcc_assert (0); /* Pointer must be a variable or a function. */
666 if (!attr1
.pointer
&& !attr1
.proc_pointer
)
668 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
669 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
674 /* Target argument is optional. */
678 where
= &target
->where
;
679 if (target
->expr_type
== EXPR_NULL
)
682 if (target
->expr_type
== EXPR_VARIABLE
|| target
->expr_type
== EXPR_FUNCTION
)
683 attr2
= gfc_expr_attr (target
);
686 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
687 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg
[1],
688 gfc_current_intrinsic
, &target
->where
);
692 if (attr1
.pointer
&& !attr2
.pointer
&& !attr2
.target
)
694 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
695 "or a TARGET", gfc_current_intrinsic_arg
[1],
696 gfc_current_intrinsic
, &target
->where
);
701 if (same_type_check (pointer
, 0, target
, 1) == FAILURE
)
703 if (rank_check (target
, 0, pointer
->rank
) == FAILURE
)
705 if (target
->rank
> 0)
707 for (i
= 0; i
< target
->rank
; i
++)
708 if (target
->ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
710 gfc_error ("Array section with a vector subscript at %L shall not "
711 "be the target of a pointer",
721 gfc_error ("NULL pointer at %L is not permitted as actual argument "
722 "of '%s' intrinsic function", where
, gfc_current_intrinsic
);
729 gfc_check_atan_2 (gfc_expr
*y
, gfc_expr
*x
)
731 /* gfc_notify_std would be a wast of time as the return value
732 is seemingly used only for the generic resolution. The error
733 will be: Too many arguments. */
734 if ((gfc_option
.allow_std
& GFC_STD_F2008
) == 0)
737 return gfc_check_atan2 (y
, x
);
742 gfc_check_atan2 (gfc_expr
*y
, gfc_expr
*x
)
744 if (type_check (y
, 0, BT_REAL
) == FAILURE
)
746 if (same_type_check (y
, 0, x
, 1) == FAILURE
)
753 /* BESJN and BESYN functions. */
756 gfc_check_besn (gfc_expr
*n
, gfc_expr
*x
)
758 if (type_check (n
, 0, BT_INTEGER
) == FAILURE
)
761 if (type_check (x
, 1, BT_REAL
) == FAILURE
)
769 gfc_check_btest (gfc_expr
*i
, gfc_expr
*pos
)
771 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
773 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
781 gfc_check_char (gfc_expr
*i
, gfc_expr
*kind
)
783 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
785 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
793 gfc_check_chdir (gfc_expr
*dir
)
795 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
797 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
805 gfc_check_chdir_sub (gfc_expr
*dir
, gfc_expr
*status
)
807 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
809 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
815 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
817 if (scalar_check (status
, 1) == FAILURE
)
825 gfc_check_chmod (gfc_expr
*name
, gfc_expr
*mode
)
827 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
829 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
832 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
834 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
842 gfc_check_chmod_sub (gfc_expr
*name
, gfc_expr
*mode
, gfc_expr
*status
)
844 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
846 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
849 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
851 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
857 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
860 if (scalar_check (status
, 2) == FAILURE
)
868 gfc_check_cmplx (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
870 if (numeric_check (x
, 0) == FAILURE
)
875 if (numeric_check (y
, 1) == FAILURE
)
878 if (x
->ts
.type
== BT_COMPLEX
)
880 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
881 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg
[1],
882 gfc_current_intrinsic
, &y
->where
);
886 if (y
->ts
.type
== BT_COMPLEX
)
888 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
889 "of either REAL or INTEGER", gfc_current_intrinsic_arg
[1],
890 gfc_current_intrinsic
, &y
->where
);
896 if (kind_check (kind
, 2, BT_COMPLEX
) == FAILURE
)
904 gfc_check_complex (gfc_expr
*x
, gfc_expr
*y
)
906 if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
908 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
909 "or REAL", gfc_current_intrinsic_arg
[0],
910 gfc_current_intrinsic
, &x
->where
);
913 if (scalar_check (x
, 0) == FAILURE
)
916 if (y
->ts
.type
!= BT_INTEGER
&& y
->ts
.type
!= BT_REAL
)
918 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
919 "or REAL", gfc_current_intrinsic_arg
[1],
920 gfc_current_intrinsic
, &y
->where
);
923 if (scalar_check (y
, 1) == FAILURE
)
931 gfc_check_count (gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
933 if (logical_array_check (mask
, 0) == FAILURE
)
935 if (dim_check (dim
, 1, false) == FAILURE
)
937 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
939 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
941 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
942 "with KIND argument at %L",
943 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
951 gfc_check_cshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*dim
)
953 if (array_check (array
, 0) == FAILURE
)
956 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
959 if (dim_check (dim
, 2, true) == FAILURE
)
962 if (dim_rank_check (dim
, array
, false) == FAILURE
)
965 if (array
->rank
== 1 || shift
->rank
== 0)
967 if (scalar_check (shift
, 1) == FAILURE
)
970 else if (shift
->rank
== array
->rank
- 1)
975 else if (dim
->expr_type
== EXPR_CONSTANT
)
976 gfc_extract_int (dim
, &d
);
983 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
986 if (!identical_dimen_shape (array
, i
, shift
, j
))
988 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
989 "invalid shape in dimension %d (%ld/%ld)",
990 gfc_current_intrinsic_arg
[1],
991 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
992 mpz_get_si (array
->shape
[i
]),
993 mpz_get_si (shift
->shape
[j
]));
1003 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1004 "%d or be a scalar", gfc_current_intrinsic_arg
[1],
1005 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1014 gfc_check_ctime (gfc_expr
*time
)
1016 if (scalar_check (time
, 0) == FAILURE
)
1019 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
1026 gfc_try
gfc_check_datan2 (gfc_expr
*y
, gfc_expr
*x
)
1028 if (double_check (y
, 0) == FAILURE
|| double_check (x
, 1) == FAILURE
)
1035 gfc_check_dcmplx (gfc_expr
*x
, gfc_expr
*y
)
1037 if (numeric_check (x
, 0) == FAILURE
)
1042 if (numeric_check (y
, 1) == FAILURE
)
1045 if (x
->ts
.type
== BT_COMPLEX
)
1047 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1048 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg
[1],
1049 gfc_current_intrinsic
, &y
->where
);
1053 if (y
->ts
.type
== BT_COMPLEX
)
1055 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1056 "of either REAL or INTEGER", gfc_current_intrinsic_arg
[1],
1057 gfc_current_intrinsic
, &y
->where
);
1067 gfc_check_dble (gfc_expr
*x
)
1069 if (numeric_check (x
, 0) == FAILURE
)
1077 gfc_check_digits (gfc_expr
*x
)
1079 if (int_or_real_check (x
, 0) == FAILURE
)
1087 gfc_check_dot_product (gfc_expr
*vector_a
, gfc_expr
*vector_b
)
1089 switch (vector_a
->ts
.type
)
1092 if (type_check (vector_b
, 1, BT_LOGICAL
) == FAILURE
)
1099 if (numeric_check (vector_b
, 1) == FAILURE
)
1104 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1105 "or LOGICAL", gfc_current_intrinsic_arg
[0],
1106 gfc_current_intrinsic
, &vector_a
->where
);
1110 if (rank_check (vector_a
, 0, 1) == FAILURE
)
1113 if (rank_check (vector_b
, 1, 1) == FAILURE
)
1116 if (! identical_dimen_shape (vector_a
, 0, vector_b
, 0))
1118 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1119 "intrinsic 'dot_product'", gfc_current_intrinsic_arg
[0],
1120 gfc_current_intrinsic_arg
[1], &vector_a
->where
);
1129 gfc_check_dprod (gfc_expr
*x
, gfc_expr
*y
)
1131 if (type_check (x
, 0, BT_REAL
) == FAILURE
1132 || type_check (y
, 1, BT_REAL
) == FAILURE
)
1135 if (x
->ts
.kind
!= gfc_default_real_kind
)
1137 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1138 "real", gfc_current_intrinsic_arg
[0],
1139 gfc_current_intrinsic
, &x
->where
);
1143 if (y
->ts
.kind
!= gfc_default_real_kind
)
1145 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1146 "real", gfc_current_intrinsic_arg
[1],
1147 gfc_current_intrinsic
, &y
->where
);
1156 gfc_check_eoshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*boundary
,
1159 if (array_check (array
, 0) == FAILURE
)
1162 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1165 if (dim_check (dim
, 3, true) == FAILURE
)
1168 if (dim_rank_check (dim
, array
, false) == FAILURE
)
1171 if (array
->rank
== 1 || shift
->rank
== 0)
1173 if (scalar_check (shift
, 1) == FAILURE
)
1176 else if (shift
->rank
== array
->rank
- 1)
1181 else if (dim
->expr_type
== EXPR_CONSTANT
)
1182 gfc_extract_int (dim
, &d
);
1189 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1192 if (!identical_dimen_shape (array
, i
, shift
, j
))
1194 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1195 "invalid shape in dimension %d (%ld/%ld)",
1196 gfc_current_intrinsic_arg
[1],
1197 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1198 mpz_get_si (array
->shape
[i
]),
1199 mpz_get_si (shift
->shape
[j
]));
1209 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1210 "%d or be a scalar", gfc_current_intrinsic_arg
[1],
1211 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1215 if (boundary
!= NULL
)
1217 if (same_type_check (array
, 0, boundary
, 2) == FAILURE
)
1220 if (array
->rank
== 1 || boundary
->rank
== 0)
1222 if (scalar_check (boundary
, 2) == FAILURE
)
1225 else if (boundary
->rank
== array
->rank
- 1)
1227 if (gfc_check_conformance (shift
, boundary
,
1228 "arguments '%s' and '%s' for "
1230 gfc_current_intrinsic_arg
[1],
1231 gfc_current_intrinsic_arg
[2],
1232 gfc_current_intrinsic
) == FAILURE
)
1237 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1238 "rank %d or be a scalar", gfc_current_intrinsic_arg
[1],
1239 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1248 /* A single complex argument. */
1251 gfc_check_fn_c (gfc_expr
*a
)
1253 if (type_check (a
, 0, BT_COMPLEX
) == FAILURE
)
1260 /* A single real argument. */
1263 gfc_check_fn_r (gfc_expr
*a
)
1265 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
1271 /* A single double argument. */
1274 gfc_check_fn_d (gfc_expr
*a
)
1276 if (double_check (a
, 0) == FAILURE
)
1282 /* A single real or complex argument. */
1285 gfc_check_fn_rc (gfc_expr
*a
)
1287 if (real_or_complex_check (a
, 0) == FAILURE
)
1295 gfc_check_fn_rc2008 (gfc_expr
*a
)
1297 if (real_or_complex_check (a
, 0) == FAILURE
)
1300 if (a
->ts
.type
== BT_COMPLEX
1301 && gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: COMPLEX argument '%s' "
1302 "argument of '%s' intrinsic at %L",
1303 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
1304 &a
->where
) == FAILURE
)
1312 gfc_check_fnum (gfc_expr
*unit
)
1314 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
1317 if (scalar_check (unit
, 0) == FAILURE
)
1325 gfc_check_huge (gfc_expr
*x
)
1327 if (int_or_real_check (x
, 0) == FAILURE
)
1335 gfc_check_hypot (gfc_expr
*x
, gfc_expr
*y
)
1337 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
1339 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
1346 /* Check that the single argument is an integer. */
1349 gfc_check_i (gfc_expr
*i
)
1351 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1359 gfc_check_iand (gfc_expr
*i
, gfc_expr
*j
)
1361 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1364 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1367 if (i
->ts
.kind
!= j
->ts
.kind
)
1369 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1370 &i
->where
) == FAILURE
)
1379 gfc_check_ibclr (gfc_expr
*i
, gfc_expr
*pos
)
1381 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1384 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
1392 gfc_check_ibits (gfc_expr
*i
, gfc_expr
*pos
, gfc_expr
*len
)
1394 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1397 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
1400 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
1408 gfc_check_ibset (gfc_expr
*i
, gfc_expr
*pos
)
1410 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1413 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
1421 gfc_check_ichar_iachar (gfc_expr
*c
, gfc_expr
*kind
)
1425 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
1428 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1431 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1432 "with KIND argument at %L",
1433 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1436 if (c
->expr_type
== EXPR_VARIABLE
|| c
->expr_type
== EXPR_SUBSTRING
)
1442 /* Substring references don't have the charlength set. */
1444 while (ref
&& ref
->type
!= REF_SUBSTRING
)
1447 gcc_assert (ref
== NULL
|| ref
->type
== REF_SUBSTRING
);
1451 /* Check that the argument is length one. Non-constant lengths
1452 can't be checked here, so assume they are ok. */
1453 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
)
1455 /* If we already have a length for this expression then use it. */
1456 if (c
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
1458 i
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
1465 start
= ref
->u
.ss
.start
;
1466 end
= ref
->u
.ss
.end
;
1469 if (end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
1470 || start
->expr_type
!= EXPR_CONSTANT
)
1473 i
= mpz_get_si (end
->value
.integer
) + 1
1474 - mpz_get_si (start
->value
.integer
);
1482 gfc_error ("Argument of %s at %L must be of length one",
1483 gfc_current_intrinsic
, &c
->where
);
1492 gfc_check_idnint (gfc_expr
*a
)
1494 if (double_check (a
, 0) == FAILURE
)
1502 gfc_check_ieor (gfc_expr
*i
, gfc_expr
*j
)
1504 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1507 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1510 if (i
->ts
.kind
!= j
->ts
.kind
)
1512 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1513 &i
->where
) == FAILURE
)
1522 gfc_check_index (gfc_expr
*string
, gfc_expr
*substring
, gfc_expr
*back
,
1525 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
1526 || type_check (substring
, 1, BT_CHARACTER
) == FAILURE
)
1529 if (back
!= NULL
&& type_check (back
, 2, BT_LOGICAL
) == FAILURE
)
1532 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
1534 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1535 "with KIND argument at %L",
1536 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1539 if (string
->ts
.kind
!= substring
->ts
.kind
)
1541 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1542 "kind as '%s'", gfc_current_intrinsic_arg
[1],
1543 gfc_current_intrinsic
, &substring
->where
,
1544 gfc_current_intrinsic_arg
[0]);
1553 gfc_check_int (gfc_expr
*x
, gfc_expr
*kind
)
1555 if (numeric_check (x
, 0) == FAILURE
)
1558 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1566 gfc_check_intconv (gfc_expr
*x
)
1568 if (numeric_check (x
, 0) == FAILURE
)
1576 gfc_check_ior (gfc_expr
*i
, gfc_expr
*j
)
1578 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1581 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1584 if (i
->ts
.kind
!= j
->ts
.kind
)
1586 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1587 &i
->where
) == FAILURE
)
1596 gfc_check_ishft (gfc_expr
*i
, gfc_expr
*shift
)
1598 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
1599 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1607 gfc_check_ishftc (gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
1609 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
1610 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1613 if (size
!= NULL
&& type_check (size
, 2, BT_INTEGER
) == FAILURE
)
1621 gfc_check_kill (gfc_expr
*pid
, gfc_expr
*sig
)
1623 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
1626 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
1634 gfc_check_kill_sub (gfc_expr
*pid
, gfc_expr
*sig
, gfc_expr
*status
)
1636 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
1639 if (scalar_check (pid
, 0) == FAILURE
)
1642 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
1645 if (scalar_check (sig
, 1) == FAILURE
)
1651 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1654 if (scalar_check (status
, 2) == FAILURE
)
1662 gfc_check_kind (gfc_expr
*x
)
1664 if (x
->ts
.type
== BT_DERIVED
)
1666 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1667 "non-derived type", gfc_current_intrinsic_arg
[0],
1668 gfc_current_intrinsic
, &x
->where
);
1677 gfc_check_lbound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
1679 if (array_check (array
, 0) == FAILURE
)
1682 if (dim_check (dim
, 1, false) == FAILURE
)
1685 if (dim_rank_check (dim
, array
, 1) == FAILURE
)
1688 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1690 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1691 "with KIND argument at %L",
1692 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1700 gfc_check_lcobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
1702 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
1704 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
1708 if (!is_coarray (coarray
))
1710 gfc_error ("Expected coarray variable as '%s' argument to the LCOBOUND "
1711 "intrinsic at %L", gfc_current_intrinsic_arg
[0], &coarray
->where
);
1717 if (dim_check (dim
, 1, false) == FAILURE
)
1720 if (dim_corank_check (dim
, coarray
) == FAILURE
)
1724 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1732 gfc_check_len_lentrim (gfc_expr
*s
, gfc_expr
*kind
)
1734 if (type_check (s
, 0, BT_CHARACTER
) == FAILURE
)
1737 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1739 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1740 "with KIND argument at %L",
1741 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1749 gfc_check_lge_lgt_lle_llt (gfc_expr
*a
, gfc_expr
*b
)
1751 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
1753 if (kind_value_check (a
, 0, gfc_default_character_kind
) == FAILURE
)
1756 if (type_check (b
, 1, BT_CHARACTER
) == FAILURE
)
1758 if (kind_value_check (b
, 1, gfc_default_character_kind
) == FAILURE
)
1766 gfc_check_link (gfc_expr
*path1
, gfc_expr
*path2
)
1768 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
1770 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
1773 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
1775 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
1783 gfc_check_link_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
1785 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
1787 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
1790 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
1792 if (kind_value_check (path2
, 0, gfc_default_character_kind
) == FAILURE
)
1798 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1801 if (scalar_check (status
, 2) == FAILURE
)
1809 gfc_check_loc (gfc_expr
*expr
)
1811 return variable_check (expr
, 0);
1816 gfc_check_symlnk (gfc_expr
*path1
, gfc_expr
*path2
)
1818 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
1820 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
1823 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
1825 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
1833 gfc_check_symlnk_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
1835 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
1837 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
1840 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
1842 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
1848 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1851 if (scalar_check (status
, 2) == FAILURE
)
1859 gfc_check_logical (gfc_expr
*a
, gfc_expr
*kind
)
1861 if (type_check (a
, 0, BT_LOGICAL
) == FAILURE
)
1863 if (kind_check (kind
, 1, BT_LOGICAL
) == FAILURE
)
1870 /* Min/max family. */
1873 min_max_args (gfc_actual_arglist
*arg
)
1875 if (arg
== NULL
|| arg
->next
== NULL
)
1877 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1878 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
1887 check_rest (bt type
, int kind
, gfc_actual_arglist
*arglist
)
1889 gfc_actual_arglist
*arg
, *tmp
;
1894 if (min_max_args (arglist
) == FAILURE
)
1897 for (arg
= arglist
, n
=1; arg
; arg
= arg
->next
, n
++)
1900 if (x
->ts
.type
!= type
|| x
->ts
.kind
!= kind
)
1902 if (x
->ts
.type
== type
)
1904 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type "
1905 "kinds at %L", &x
->where
) == FAILURE
)
1910 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1911 "%s(%d)", n
, gfc_current_intrinsic
, &x
->where
,
1912 gfc_basic_typename (type
), kind
);
1917 for (tmp
= arglist
, m
=1; tmp
!= arg
; tmp
= tmp
->next
, m
++)
1918 if (gfc_check_conformance (tmp
->expr
, x
,
1919 "arguments 'a%d' and 'a%d' for "
1920 "intrinsic '%s'", m
, n
,
1921 gfc_current_intrinsic
) == FAILURE
)
1930 gfc_check_min_max (gfc_actual_arglist
*arg
)
1934 if (min_max_args (arg
) == FAILURE
)
1939 if (x
->ts
.type
== BT_CHARACTER
)
1941 if (gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1942 "with CHARACTER argument at %L",
1943 gfc_current_intrinsic
, &x
->where
) == FAILURE
)
1946 else if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
1948 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
1949 "REAL or CHARACTER", gfc_current_intrinsic
, &x
->where
);
1953 return check_rest (x
->ts
.type
, x
->ts
.kind
, arg
);
1958 gfc_check_min_max_integer (gfc_actual_arglist
*arg
)
1960 return check_rest (BT_INTEGER
, gfc_default_integer_kind
, arg
);
1965 gfc_check_min_max_real (gfc_actual_arglist
*arg
)
1967 return check_rest (BT_REAL
, gfc_default_real_kind
, arg
);
1972 gfc_check_min_max_double (gfc_actual_arglist
*arg
)
1974 return check_rest (BT_REAL
, gfc_default_double_kind
, arg
);
1978 /* End of min/max family. */
1981 gfc_check_malloc (gfc_expr
*size
)
1983 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
1986 if (scalar_check (size
, 0) == FAILURE
)
1994 gfc_check_matmul (gfc_expr
*matrix_a
, gfc_expr
*matrix_b
)
1996 if ((matrix_a
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_a
->ts
))
1998 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1999 "or LOGICAL", gfc_current_intrinsic_arg
[0],
2000 gfc_current_intrinsic
, &matrix_a
->where
);
2004 if ((matrix_b
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_b
->ts
))
2006 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2007 "or LOGICAL", gfc_current_intrinsic_arg
[1],
2008 gfc_current_intrinsic
, &matrix_b
->where
);
2012 if ((matrix_a
->ts
.type
== BT_LOGICAL
&& gfc_numeric_ts (&matrix_b
->ts
))
2013 || (gfc_numeric_ts (&matrix_a
->ts
) && matrix_b
->ts
.type
== BT_LOGICAL
))
2015 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2016 gfc_current_intrinsic
, &matrix_a
->where
,
2017 gfc_typename(&matrix_a
->ts
), gfc_typename(&matrix_b
->ts
));
2021 switch (matrix_a
->rank
)
2024 if (rank_check (matrix_b
, 1, 2) == FAILURE
)
2026 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2027 if (!identical_dimen_shape (matrix_a
, 0, matrix_b
, 0))
2029 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2030 "and '%s' at %L for intrinsic matmul",
2031 gfc_current_intrinsic_arg
[0],
2032 gfc_current_intrinsic_arg
[1], &matrix_a
->where
);
2038 if (matrix_b
->rank
!= 2)
2040 if (rank_check (matrix_b
, 1, 1) == FAILURE
)
2043 /* matrix_b has rank 1 or 2 here. Common check for the cases
2044 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2045 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2046 if (!identical_dimen_shape (matrix_a
, 1, matrix_b
, 0))
2048 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2049 "dimension 1 for argument '%s' at %L for intrinsic "
2050 "matmul", gfc_current_intrinsic_arg
[0],
2051 gfc_current_intrinsic_arg
[1], &matrix_a
->where
);
2057 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2058 "1 or 2", gfc_current_intrinsic_arg
[0],
2059 gfc_current_intrinsic
, &matrix_a
->where
);
2067 /* Whoever came up with this interface was probably on something.
2068 The possibilities for the occupation of the second and third
2075 NULL MASK minloc(array, mask=m)
2078 I.e. in the case of minloc(array,mask), mask will be in the second
2079 position of the argument list and we'll have to fix that up. */
2082 gfc_check_minloc_maxloc (gfc_actual_arglist
*ap
)
2084 gfc_expr
*a
, *m
, *d
;
2087 if (int_or_real_check (a
, 0) == FAILURE
|| array_check (a
, 0) == FAILURE
)
2091 m
= ap
->next
->next
->expr
;
2093 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2094 && ap
->next
->name
== NULL
)
2098 ap
->next
->expr
= NULL
;
2099 ap
->next
->next
->expr
= m
;
2102 if (dim_check (d
, 1, false) == FAILURE
)
2105 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2108 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2112 && gfc_check_conformance (a
, m
,
2113 "arguments '%s' and '%s' for intrinsic %s",
2114 gfc_current_intrinsic_arg
[0],
2115 gfc_current_intrinsic_arg
[2],
2116 gfc_current_intrinsic
) == FAILURE
)
2123 /* Similar to minloc/maxloc, the argument list might need to be
2124 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2125 difference is that MINLOC/MAXLOC take an additional KIND argument.
2126 The possibilities are:
2132 NULL MASK minval(array, mask=m)
2135 I.e. in the case of minval(array,mask), mask will be in the second
2136 position of the argument list and we'll have to fix that up. */
2139 check_reduction (gfc_actual_arglist
*ap
)
2141 gfc_expr
*a
, *m
, *d
;
2145 m
= ap
->next
->next
->expr
;
2147 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2148 && ap
->next
->name
== NULL
)
2152 ap
->next
->expr
= NULL
;
2153 ap
->next
->next
->expr
= m
;
2156 if (dim_check (d
, 1, false) == FAILURE
)
2159 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2162 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2166 && gfc_check_conformance (a
, m
,
2167 "arguments '%s' and '%s' for intrinsic %s",
2168 gfc_current_intrinsic_arg
[0],
2169 gfc_current_intrinsic_arg
[2],
2170 gfc_current_intrinsic
) == FAILURE
)
2178 gfc_check_minval_maxval (gfc_actual_arglist
*ap
)
2180 if (int_or_real_check (ap
->expr
, 0) == FAILURE
2181 || array_check (ap
->expr
, 0) == FAILURE
)
2184 return check_reduction (ap
);
2189 gfc_check_product_sum (gfc_actual_arglist
*ap
)
2191 if (numeric_check (ap
->expr
, 0) == FAILURE
2192 || array_check (ap
->expr
, 0) == FAILURE
)
2195 return check_reduction (ap
);
2200 gfc_check_merge (gfc_expr
*tsource
, gfc_expr
*fsource
, gfc_expr
*mask
)
2202 if (same_type_check (tsource
, 0, fsource
, 1) == FAILURE
)
2205 if (type_check (mask
, 2, BT_LOGICAL
) == FAILURE
)
2208 if (tsource
->ts
.type
== BT_CHARACTER
)
2209 return gfc_check_same_strlen (tsource
, fsource
, "MERGE intrinsic");
2216 gfc_check_move_alloc (gfc_expr
*from
, gfc_expr
*to
)
2218 symbol_attribute attr
;
2220 if (variable_check (from
, 0) == FAILURE
)
2223 attr
= gfc_variable_attr (from
, NULL
);
2224 if (!attr
.allocatable
)
2226 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2227 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
2232 if (variable_check (to
, 0) == FAILURE
)
2235 attr
= gfc_variable_attr (to
, NULL
);
2236 if (!attr
.allocatable
)
2238 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2239 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
2244 if (same_type_check (to
, 1, from
, 0) == FAILURE
)
2247 if (to
->rank
!= from
->rank
)
2249 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2250 "have the same rank %d/%d", gfc_current_intrinsic_arg
[0],
2251 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
2252 &to
->where
, from
->rank
, to
->rank
);
2256 if (to
->ts
.kind
!= from
->ts
.kind
)
2258 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2259 "be of the same kind %d/%d", gfc_current_intrinsic_arg
[0],
2260 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
2261 &to
->where
, from
->ts
.kind
, to
->ts
.kind
);
2270 gfc_check_nearest (gfc_expr
*x
, gfc_expr
*s
)
2272 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
2275 if (type_check (s
, 1, BT_REAL
) == FAILURE
)
2283 gfc_check_new_line (gfc_expr
*a
)
2285 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
2293 gfc_check_null (gfc_expr
*mold
)
2295 symbol_attribute attr
;
2300 if (variable_check (mold
, 0) == FAILURE
)
2303 attr
= gfc_variable_attr (mold
, NULL
);
2305 if (!attr
.pointer
&& !attr
.proc_pointer
)
2307 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
2308 gfc_current_intrinsic_arg
[0],
2309 gfc_current_intrinsic
, &mold
->where
);
2318 gfc_check_pack (gfc_expr
*array
, gfc_expr
*mask
, gfc_expr
*vector
)
2320 if (array_check (array
, 0) == FAILURE
)
2323 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
2326 if (gfc_check_conformance (array
, mask
,
2327 "arguments '%s' and '%s' for intrinsic '%s'",
2328 gfc_current_intrinsic_arg
[0],
2329 gfc_current_intrinsic_arg
[1],
2330 gfc_current_intrinsic
) == FAILURE
)
2335 mpz_t array_size
, vector_size
;
2336 bool have_array_size
, have_vector_size
;
2338 if (same_type_check (array
, 0, vector
, 2) == FAILURE
)
2341 if (rank_check (vector
, 2, 1) == FAILURE
)
2344 /* VECTOR requires at least as many elements as MASK
2345 has .TRUE. values. */
2346 have_array_size
= gfc_array_size (array
, &array_size
) == SUCCESS
;
2347 have_vector_size
= gfc_array_size (vector
, &vector_size
) == SUCCESS
;
2349 if (have_vector_size
2350 && (mask
->expr_type
== EXPR_ARRAY
2351 || (mask
->expr_type
== EXPR_CONSTANT
2352 && have_array_size
)))
2354 int mask_true_values
= 0;
2356 if (mask
->expr_type
== EXPR_ARRAY
)
2358 gfc_constructor
*mask_ctor
;
2359 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
2362 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
2364 mask_true_values
= 0;
2368 if (mask_ctor
->expr
->value
.logical
)
2371 mask_ctor
= gfc_constructor_next (mask_ctor
);
2374 else if (mask
->expr_type
== EXPR_CONSTANT
&& mask
->value
.logical
)
2375 mask_true_values
= mpz_get_si (array_size
);
2377 if (mpz_get_si (vector_size
) < mask_true_values
)
2379 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2380 "provide at least as many elements as there "
2381 "are .TRUE. values in '%s' (%ld/%d)",
2382 gfc_current_intrinsic_arg
[2],gfc_current_intrinsic
,
2383 &vector
->where
, gfc_current_intrinsic_arg
[1],
2384 mpz_get_si (vector_size
), mask_true_values
);
2389 if (have_array_size
)
2390 mpz_clear (array_size
);
2391 if (have_vector_size
)
2392 mpz_clear (vector_size
);
2400 gfc_check_precision (gfc_expr
*x
)
2402 if (x
->ts
.type
!= BT_REAL
&& x
->ts
.type
!= BT_COMPLEX
)
2404 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
2405 "REAL or COMPLEX", gfc_current_intrinsic_arg
[0],
2406 gfc_current_intrinsic
, &x
->where
);
2415 gfc_check_present (gfc_expr
*a
)
2419 if (variable_check (a
, 0) == FAILURE
)
2422 sym
= a
->symtree
->n
.sym
;
2423 if (!sym
->attr
.dummy
)
2425 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2426 "dummy variable", gfc_current_intrinsic_arg
[0],
2427 gfc_current_intrinsic
, &a
->where
);
2431 if (!sym
->attr
.optional
)
2433 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2434 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg
[0],
2435 gfc_current_intrinsic
, &a
->where
);
2439 /* 13.14.82 PRESENT(A)
2441 Argument. A shall be the name of an optional dummy argument that is
2442 accessible in the subprogram in which the PRESENT function reference
2446 && !(a
->ref
->next
== NULL
&& a
->ref
->type
== REF_ARRAY
2447 && a
->ref
->u
.ar
.type
== AR_FULL
))
2449 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2450 "subobject of '%s'", gfc_current_intrinsic_arg
[0],
2451 gfc_current_intrinsic
, &a
->where
, sym
->name
);
2460 gfc_check_radix (gfc_expr
*x
)
2462 if (int_or_real_check (x
, 0) == FAILURE
)
2470 gfc_check_range (gfc_expr
*x
)
2472 if (numeric_check (x
, 0) == FAILURE
)
2479 /* real, float, sngl. */
2481 gfc_check_real (gfc_expr
*a
, gfc_expr
*kind
)
2483 if (numeric_check (a
, 0) == FAILURE
)
2486 if (kind_check (kind
, 1, BT_REAL
) == FAILURE
)
2494 gfc_check_rename (gfc_expr
*path1
, gfc_expr
*path2
)
2496 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2498 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2501 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2503 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2511 gfc_check_rename_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2513 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2515 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2518 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2520 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2526 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2529 if (scalar_check (status
, 2) == FAILURE
)
2537 gfc_check_repeat (gfc_expr
*x
, gfc_expr
*y
)
2539 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
2542 if (scalar_check (x
, 0) == FAILURE
)
2545 if (type_check (y
, 0, BT_INTEGER
) == FAILURE
)
2548 if (scalar_check (y
, 1) == FAILURE
)
2556 gfc_check_reshape (gfc_expr
*source
, gfc_expr
*shape
,
2557 gfc_expr
*pad
, gfc_expr
*order
)
2563 if (array_check (source
, 0) == FAILURE
)
2566 if (rank_check (shape
, 1, 1) == FAILURE
)
2569 if (type_check (shape
, 1, BT_INTEGER
) == FAILURE
)
2572 if (gfc_array_size (shape
, &size
) != SUCCESS
)
2574 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2575 "array of constant size", &shape
->where
);
2579 shape_size
= mpz_get_ui (size
);
2582 if (shape_size
<= 0)
2584 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
2585 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
2589 else if (shape_size
> GFC_MAX_DIMENSIONS
)
2591 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2592 "than %d elements", &shape
->where
, GFC_MAX_DIMENSIONS
);
2595 else if (shape
->expr_type
== EXPR_ARRAY
)
2599 for (i
= 0; i
< shape_size
; ++i
)
2601 e
= gfc_constructor_lookup_expr (shape
->value
.constructor
, i
);
2602 if (e
->expr_type
!= EXPR_CONSTANT
)
2605 gfc_extract_int (e
, &extent
);
2608 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2609 "negative element (%d)", gfc_current_intrinsic_arg
[1],
2610 gfc_current_intrinsic
, &e
->where
, extent
);
2618 if (same_type_check (source
, 0, pad
, 2) == FAILURE
)
2621 if (array_check (pad
, 2) == FAILURE
)
2627 if (array_check (order
, 3) == FAILURE
)
2630 if (type_check (order
, 3, BT_INTEGER
) == FAILURE
)
2633 if (order
->expr_type
== EXPR_ARRAY
)
2635 int i
, order_size
, dim
, perm
[GFC_MAX_DIMENSIONS
];
2638 for (i
= 0; i
< GFC_MAX_DIMENSIONS
; ++i
)
2641 gfc_array_size (order
, &size
);
2642 order_size
= mpz_get_ui (size
);
2645 if (order_size
!= shape_size
)
2647 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2648 "has wrong number of elements (%d/%d)",
2649 gfc_current_intrinsic_arg
[3],
2650 gfc_current_intrinsic
, &order
->where
,
2651 order_size
, shape_size
);
2655 for (i
= 1; i
<= order_size
; ++i
)
2657 e
= gfc_constructor_lookup_expr (order
->value
.constructor
, i
-1);
2658 if (e
->expr_type
!= EXPR_CONSTANT
)
2661 gfc_extract_int (e
, &dim
);
2663 if (dim
< 1 || dim
> order_size
)
2665 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2666 "has out-of-range dimension (%d)",
2667 gfc_current_intrinsic_arg
[3],
2668 gfc_current_intrinsic
, &e
->where
, dim
);
2672 if (perm
[dim
-1] != 0)
2674 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2675 "invalid permutation of dimensions (dimension "
2676 "'%d' duplicated)", gfc_current_intrinsic_arg
[3],
2677 gfc_current_intrinsic
, &e
->where
, dim
);
2686 if (pad
== NULL
&& shape
->expr_type
== EXPR_ARRAY
2687 && gfc_is_constant_expr (shape
)
2688 && !(source
->expr_type
== EXPR_VARIABLE
&& source
->symtree
->n
.sym
->as
2689 && source
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
))
2691 /* Check the match in size between source and destination. */
2692 if (gfc_array_size (source
, &nelems
) == SUCCESS
)
2698 mpz_init_set_ui (size
, 1);
2699 for (c
= gfc_constructor_first (shape
->value
.constructor
);
2700 c
; c
= gfc_constructor_next (c
))
2701 mpz_mul (size
, size
, c
->expr
->value
.integer
);
2703 test
= mpz_cmp (nelems
, size
) < 0 && mpz_cmp_ui (size
, 0) > 0;
2709 gfc_error ("Without padding, there are not enough elements "
2710 "in the intrinsic RESHAPE source at %L to match "
2711 "the shape", &source
->where
);
2722 gfc_check_same_type_as (gfc_expr
*a
, gfc_expr
*b
)
2725 if (a
->ts
.type
!= BT_DERIVED
&& a
->ts
.type
!= BT_CLASS
)
2727 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2728 "must be of a derived type", gfc_current_intrinsic_arg
[0],
2729 gfc_current_intrinsic
, &a
->where
);
2733 if (!gfc_type_is_extensible (a
->ts
.u
.derived
))
2735 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2736 "must be of an extensible type", gfc_current_intrinsic_arg
[0],
2737 gfc_current_intrinsic
, &a
->where
);
2741 if (b
->ts
.type
!= BT_DERIVED
&& b
->ts
.type
!= BT_CLASS
)
2743 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2744 "must be of a derived type", gfc_current_intrinsic_arg
[1],
2745 gfc_current_intrinsic
, &b
->where
);
2749 if (!gfc_type_is_extensible (b
->ts
.u
.derived
))
2751 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2752 "must be of an extensible type", gfc_current_intrinsic_arg
[1],
2753 gfc_current_intrinsic
, &b
->where
);
2762 gfc_check_scale (gfc_expr
*x
, gfc_expr
*i
)
2764 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
2767 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
2775 gfc_check_scan (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
2777 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
2780 if (type_check (y
, 1, BT_CHARACTER
) == FAILURE
)
2783 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
2786 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
2788 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
2789 "with KIND argument at %L",
2790 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
2793 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
2801 gfc_check_secnds (gfc_expr
*r
)
2803 if (type_check (r
, 0, BT_REAL
) == FAILURE
)
2806 if (kind_value_check (r
, 0, 4) == FAILURE
)
2809 if (scalar_check (r
, 0) == FAILURE
)
2817 gfc_check_selected_char_kind (gfc_expr
*name
)
2819 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
2822 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
2825 if (scalar_check (name
, 0) == FAILURE
)
2833 gfc_check_selected_int_kind (gfc_expr
*r
)
2835 if (type_check (r
, 0, BT_INTEGER
) == FAILURE
)
2838 if (scalar_check (r
, 0) == FAILURE
)
2846 gfc_check_selected_real_kind (gfc_expr
*p
, gfc_expr
*r
)
2848 if (p
== NULL
&& r
== NULL
)
2850 gfc_error ("Missing arguments to %s intrinsic at %L",
2851 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
2856 if (p
!= NULL
&& type_check (p
, 0, BT_INTEGER
) == FAILURE
)
2859 if (r
!= NULL
&& type_check (r
, 1, BT_INTEGER
) == FAILURE
)
2867 gfc_check_set_exponent (gfc_expr
*x
, gfc_expr
*i
)
2869 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
2872 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
2880 gfc_check_shape (gfc_expr
*source
)
2884 if (source
->rank
== 0 || source
->expr_type
!= EXPR_VARIABLE
)
2887 ar
= gfc_find_array_ref (source
);
2889 if (ar
->as
&& ar
->as
->type
== AS_ASSUMED_SIZE
&& ar
->type
== AR_FULL
)
2891 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2892 "an assumed size array", &source
->where
);
2901 gfc_check_sign (gfc_expr
*a
, gfc_expr
*b
)
2903 if (int_or_real_check (a
, 0) == FAILURE
)
2906 if (same_type_check (a
, 0, b
, 1) == FAILURE
)
2914 gfc_check_size (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2916 if (array_check (array
, 0) == FAILURE
)
2919 if (dim_check (dim
, 1, true) == FAILURE
)
2922 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
2925 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
2927 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
2928 "with KIND argument at %L",
2929 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
2938 gfc_check_sizeof (gfc_expr
*arg ATTRIBUTE_UNUSED
)
2945 gfc_check_sleep_sub (gfc_expr
*seconds
)
2947 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
2950 if (scalar_check (seconds
, 0) == FAILURE
)
2958 gfc_check_spread (gfc_expr
*source
, gfc_expr
*dim
, gfc_expr
*ncopies
)
2960 if (source
->rank
>= GFC_MAX_DIMENSIONS
)
2962 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
2963 "than rank %d", gfc_current_intrinsic_arg
[0],
2964 gfc_current_intrinsic
, &source
->where
, GFC_MAX_DIMENSIONS
);
2972 if (dim_check (dim
, 1, false) == FAILURE
)
2975 /* dim_rank_check() does not apply here. */
2977 && dim
->expr_type
== EXPR_CONSTANT
2978 && (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
2979 || mpz_cmp_ui (dim
->value
.integer
, source
->rank
+ 1) > 0))
2981 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
2982 "dimension index", gfc_current_intrinsic_arg
[1],
2983 gfc_current_intrinsic
, &dim
->where
);
2987 if (type_check (ncopies
, 2, BT_INTEGER
) == FAILURE
)
2990 if (scalar_check (ncopies
, 2) == FAILURE
)
2997 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3001 gfc_check_fgetputc_sub (gfc_expr
*unit
, gfc_expr
*c
, gfc_expr
*status
)
3003 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3006 if (scalar_check (unit
, 0) == FAILURE
)
3009 if (type_check (c
, 1, BT_CHARACTER
) == FAILURE
)
3011 if (kind_value_check (c
, 1, gfc_default_character_kind
) == FAILURE
)
3017 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3018 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
3019 || scalar_check (status
, 2) == FAILURE
)
3027 gfc_check_fgetputc (gfc_expr
*unit
, gfc_expr
*c
)
3029 return gfc_check_fgetputc_sub (unit
, c
, NULL
);
3034 gfc_check_fgetput_sub (gfc_expr
*c
, gfc_expr
*status
)
3036 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
3038 if (kind_value_check (c
, 0, gfc_default_character_kind
) == FAILURE
)
3044 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
3045 || kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
3046 || scalar_check (status
, 1) == FAILURE
)
3054 gfc_check_fgetput (gfc_expr
*c
)
3056 return gfc_check_fgetput_sub (c
, NULL
);
3061 gfc_check_fseek_sub (gfc_expr
*unit
, gfc_expr
*offset
, gfc_expr
*whence
, gfc_expr
*status
)
3063 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3066 if (scalar_check (unit
, 0) == FAILURE
)
3069 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3072 if (scalar_check (offset
, 1) == FAILURE
)
3075 if (type_check (whence
, 2, BT_INTEGER
) == FAILURE
)
3078 if (scalar_check (whence
, 2) == FAILURE
)
3084 if (type_check (status
, 3, BT_INTEGER
) == FAILURE
)
3087 if (kind_value_check (status
, 3, 4) == FAILURE
)
3090 if (scalar_check (status
, 3) == FAILURE
)
3099 gfc_check_fstat (gfc_expr
*unit
, gfc_expr
*array
)
3101 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3104 if (scalar_check (unit
, 0) == FAILURE
)
3107 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3108 || kind_value_check (unit
, 0, gfc_default_integer_kind
) == FAILURE
)
3111 if (array_check (array
, 1) == FAILURE
)
3119 gfc_check_fstat_sub (gfc_expr
*unit
, gfc_expr
*array
, gfc_expr
*status
)
3121 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3124 if (scalar_check (unit
, 0) == FAILURE
)
3127 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3128 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3131 if (array_check (array
, 1) == FAILURE
)
3137 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3138 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
3141 if (scalar_check (status
, 2) == FAILURE
)
3149 gfc_check_ftell (gfc_expr
*unit
)
3151 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3154 if (scalar_check (unit
, 0) == FAILURE
)
3162 gfc_check_ftell_sub (gfc_expr
*unit
, gfc_expr
*offset
)
3164 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3167 if (scalar_check (unit
, 0) == FAILURE
)
3170 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3173 if (scalar_check (offset
, 1) == FAILURE
)
3181 gfc_check_stat (gfc_expr
*name
, gfc_expr
*array
)
3183 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3185 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3188 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3189 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3192 if (array_check (array
, 1) == FAILURE
)
3200 gfc_check_stat_sub (gfc_expr
*name
, gfc_expr
*array
, gfc_expr
*status
)
3202 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3204 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3207 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3208 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3211 if (array_check (array
, 1) == FAILURE
)
3217 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3218 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3221 if (scalar_check (status
, 2) == FAILURE
)
3229 gfc_check_image_index (gfc_expr
*coarray
, gfc_expr
*sub
)
3231 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3233 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3237 if (!is_coarray (coarray
))
3239 gfc_error ("Expected coarray variable as '%s' argument to IMAGE_INDEX "
3240 "intrinsic at %L", gfc_current_intrinsic_arg
[0], &coarray
->where
);
3246 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3247 gfc_current_intrinsic_arg
[1], &sub
->where
);
3256 gfc_check_this_image (gfc_expr
*coarray
, gfc_expr
*dim
)
3258 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3260 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3264 if (dim
!= NULL
&& coarray
== NULL
)
3266 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3267 "intrinsic at %L", &dim
->where
);
3271 if (coarray
== NULL
)
3274 if (!is_coarray (coarray
))
3276 gfc_error ("Expected coarray variable as '%s' argument to THIS_IMAGE "
3277 "intrinsic at %L", gfc_current_intrinsic_arg
[0], &coarray
->where
);
3283 if (dim_check (dim
, 1, false) == FAILURE
)
3286 if (dim_corank_check (dim
, coarray
) == FAILURE
)
3295 gfc_check_transfer (gfc_expr
*source ATTRIBUTE_UNUSED
,
3296 gfc_expr
*mold ATTRIBUTE_UNUSED
, gfc_expr
*size
)
3298 if (mold
->ts
.type
== BT_HOLLERITH
)
3300 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3301 &mold
->where
, gfc_basic_typename (BT_HOLLERITH
));
3307 if (type_check (size
, 2, BT_INTEGER
) == FAILURE
)
3310 if (scalar_check (size
, 2) == FAILURE
)
3313 if (nonoptional_check (size
, 2) == FAILURE
)
3322 gfc_check_transpose (gfc_expr
*matrix
)
3324 if (rank_check (matrix
, 0, 2) == FAILURE
)
3332 gfc_check_ubound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
3334 if (array_check (array
, 0) == FAILURE
)
3337 if (dim_check (dim
, 1, false) == FAILURE
)
3340 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
3343 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3345 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3346 "with KIND argument at %L",
3347 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3355 gfc_check_ucobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
3357 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3359 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3363 if (!is_coarray (coarray
))
3365 gfc_error ("Expected coarray variable as '%s' argument to the UCOBOUND "
3366 "intrinsic at %L", gfc_current_intrinsic_arg
[0], &coarray
->where
);
3372 if (dim_check (dim
, 1, false) == FAILURE
)
3375 if (dim_corank_check (dim
, coarray
) == FAILURE
)
3379 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3387 gfc_check_unpack (gfc_expr
*vector
, gfc_expr
*mask
, gfc_expr
*field
)
3391 if (rank_check (vector
, 0, 1) == FAILURE
)
3394 if (array_check (mask
, 1) == FAILURE
)
3397 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
3400 if (same_type_check (vector
, 0, field
, 2) == FAILURE
)
3403 if (mask
->expr_type
== EXPR_ARRAY
3404 && gfc_array_size (vector
, &vector_size
) == SUCCESS
)
3406 int mask_true_count
= 0;
3407 gfc_constructor
*mask_ctor
;
3408 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
3411 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
3413 mask_true_count
= 0;
3417 if (mask_ctor
->expr
->value
.logical
)
3420 mask_ctor
= gfc_constructor_next (mask_ctor
);
3423 if (mpz_get_si (vector_size
) < mask_true_count
)
3425 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
3426 "provide at least as many elements as there "
3427 "are .TRUE. values in '%s' (%ld/%d)",
3428 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
3429 &vector
->where
, gfc_current_intrinsic_arg
[1],
3430 mpz_get_si (vector_size
), mask_true_count
);
3434 mpz_clear (vector_size
);
3437 if (mask
->rank
!= field
->rank
&& field
->rank
!= 0)
3439 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
3440 "the same rank as '%s' or be a scalar",
3441 gfc_current_intrinsic_arg
[2], gfc_current_intrinsic
,
3442 &field
->where
, gfc_current_intrinsic_arg
[1]);
3446 if (mask
->rank
== field
->rank
)
3449 for (i
= 0; i
< field
->rank
; i
++)
3450 if (! identical_dimen_shape (mask
, i
, field
, i
))
3452 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
3453 "must have identical shape.",
3454 gfc_current_intrinsic_arg
[2],
3455 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
3465 gfc_check_verify (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
3467 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3470 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
3473 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
3476 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
3478 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3479 "with KIND argument at %L",
3480 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3488 gfc_check_trim (gfc_expr
*x
)
3490 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3493 if (scalar_check (x
, 0) == FAILURE
)
3501 gfc_check_ttynam (gfc_expr
*unit
)
3503 if (scalar_check (unit
, 0) == FAILURE
)
3506 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3513 /* Common check function for the half a dozen intrinsics that have a
3514 single real argument. */
3517 gfc_check_x (gfc_expr
*x
)
3519 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3526 /************* Check functions for intrinsic subroutines *************/
3529 gfc_check_cpu_time (gfc_expr
*time
)
3531 if (scalar_check (time
, 0) == FAILURE
)
3534 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
3537 if (variable_check (time
, 0) == FAILURE
)
3545 gfc_check_date_and_time (gfc_expr
*date
, gfc_expr
*time
,
3546 gfc_expr
*zone
, gfc_expr
*values
)
3550 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
3552 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
3554 if (scalar_check (date
, 0) == FAILURE
)
3556 if (variable_check (date
, 0) == FAILURE
)
3562 if (type_check (time
, 1, BT_CHARACTER
) == FAILURE
)
3564 if (kind_value_check (time
, 1, gfc_default_character_kind
) == FAILURE
)
3566 if (scalar_check (time
, 1) == FAILURE
)
3568 if (variable_check (time
, 1) == FAILURE
)
3574 if (type_check (zone
, 2, BT_CHARACTER
) == FAILURE
)
3576 if (kind_value_check (zone
, 2, gfc_default_character_kind
) == FAILURE
)
3578 if (scalar_check (zone
, 2) == FAILURE
)
3580 if (variable_check (zone
, 2) == FAILURE
)
3586 if (type_check (values
, 3, BT_INTEGER
) == FAILURE
)
3588 if (array_check (values
, 3) == FAILURE
)
3590 if (rank_check (values
, 3, 1) == FAILURE
)
3592 if (variable_check (values
, 3) == FAILURE
)
3601 gfc_check_mvbits (gfc_expr
*from
, gfc_expr
*frompos
, gfc_expr
*len
,
3602 gfc_expr
*to
, gfc_expr
*topos
)
3604 if (type_check (from
, 0, BT_INTEGER
) == FAILURE
)
3607 if (type_check (frompos
, 1, BT_INTEGER
) == FAILURE
)
3610 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
3613 if (same_type_check (from
, 0, to
, 3) == FAILURE
)
3616 if (variable_check (to
, 3) == FAILURE
)
3619 if (type_check (topos
, 4, BT_INTEGER
) == FAILURE
)
3627 gfc_check_random_number (gfc_expr
*harvest
)
3629 if (type_check (harvest
, 0, BT_REAL
) == FAILURE
)
3632 if (variable_check (harvest
, 0) == FAILURE
)
3640 gfc_check_random_seed (gfc_expr
*size
, gfc_expr
*put
, gfc_expr
*get
)
3642 unsigned int nargs
= 0, kiss_size
;
3643 locus
*where
= NULL
;
3644 mpz_t put_size
, get_size
;
3645 bool have_gfc_real_16
; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
3647 have_gfc_real_16
= gfc_validate_kind (BT_REAL
, 16, true) != -1;
3649 /* Keep the number of bytes in sync with kiss_size in
3650 libgfortran/intrinsics/random.c. */
3651 kiss_size
= (have_gfc_real_16
? 48 : 32) / gfc_default_integer_kind
;
3655 if (size
->expr_type
!= EXPR_VARIABLE
3656 || !size
->symtree
->n
.sym
->attr
.optional
)
3659 if (scalar_check (size
, 0) == FAILURE
)
3662 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
3665 if (variable_check (size
, 0) == FAILURE
)
3668 if (kind_value_check (size
, 0, gfc_default_integer_kind
) == FAILURE
)
3674 if (put
->expr_type
!= EXPR_VARIABLE
3675 || !put
->symtree
->n
.sym
->attr
.optional
)
3678 where
= &put
->where
;
3681 if (array_check (put
, 1) == FAILURE
)
3684 if (rank_check (put
, 1, 1) == FAILURE
)
3687 if (type_check (put
, 1, BT_INTEGER
) == FAILURE
)
3690 if (kind_value_check (put
, 1, gfc_default_integer_kind
) == FAILURE
)
3693 if (gfc_array_size (put
, &put_size
) == SUCCESS
3694 && mpz_get_ui (put_size
) < kiss_size
)
3695 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3696 "too small (%i/%i)",
3697 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
, where
,
3698 (int) mpz_get_ui (put_size
), kiss_size
);
3703 if (get
->expr_type
!= EXPR_VARIABLE
3704 || !get
->symtree
->n
.sym
->attr
.optional
)
3707 where
= &get
->where
;
3710 if (array_check (get
, 2) == FAILURE
)
3713 if (rank_check (get
, 2, 1) == FAILURE
)
3716 if (type_check (get
, 2, BT_INTEGER
) == FAILURE
)
3719 if (variable_check (get
, 2) == FAILURE
)
3722 if (kind_value_check (get
, 2, gfc_default_integer_kind
) == FAILURE
)
3725 if (gfc_array_size (get
, &get_size
) == SUCCESS
3726 && mpz_get_ui (get_size
) < kiss_size
)
3727 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3728 "too small (%i/%i)",
3729 gfc_current_intrinsic_arg
[2], gfc_current_intrinsic
, where
,
3730 (int) mpz_get_ui (get_size
), kiss_size
);
3733 /* RANDOM_SEED may not have more than one non-optional argument. */
3735 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
, where
);
3742 gfc_check_second_sub (gfc_expr
*time
)
3744 if (scalar_check (time
, 0) == FAILURE
)
3747 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
3750 if (kind_value_check(time
, 0, 4) == FAILURE
)
3757 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
3758 count, count_rate, and count_max are all optional arguments */
3761 gfc_check_system_clock (gfc_expr
*count
, gfc_expr
*count_rate
,
3762 gfc_expr
*count_max
)
3766 if (scalar_check (count
, 0) == FAILURE
)
3769 if (type_check (count
, 0, BT_INTEGER
) == FAILURE
)
3772 if (variable_check (count
, 0) == FAILURE
)
3776 if (count_rate
!= NULL
)
3778 if (scalar_check (count_rate
, 1) == FAILURE
)
3781 if (type_check (count_rate
, 1, BT_INTEGER
) == FAILURE
)
3784 if (variable_check (count_rate
, 1) == FAILURE
)
3788 && same_type_check (count
, 0, count_rate
, 1) == FAILURE
)
3793 if (count_max
!= NULL
)
3795 if (scalar_check (count_max
, 2) == FAILURE
)
3798 if (type_check (count_max
, 2, BT_INTEGER
) == FAILURE
)
3801 if (variable_check (count_max
, 2) == FAILURE
)
3805 && same_type_check (count
, 0, count_max
, 2) == FAILURE
)
3808 if (count_rate
!= NULL
3809 && same_type_check (count_rate
, 1, count_max
, 2) == FAILURE
)
3818 gfc_check_irand (gfc_expr
*x
)
3823 if (scalar_check (x
, 0) == FAILURE
)
3826 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
3829 if (kind_value_check(x
, 0, 4) == FAILURE
)
3837 gfc_check_alarm_sub (gfc_expr
*seconds
, gfc_expr
*handler
, gfc_expr
*status
)
3839 if (scalar_check (seconds
, 0) == FAILURE
)
3842 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
3845 if (handler
->ts
.type
!= BT_INTEGER
&& handler
->ts
.type
!= BT_PROCEDURE
)
3847 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3848 "or PROCEDURE", gfc_current_intrinsic_arg
[1],
3849 gfc_current_intrinsic
, &handler
->where
);
3853 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
3859 if (scalar_check (status
, 2) == FAILURE
)
3862 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
3865 if (kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
3873 gfc_check_rand (gfc_expr
*x
)
3878 if (scalar_check (x
, 0) == FAILURE
)
3881 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
3884 if (kind_value_check(x
, 0, 4) == FAILURE
)
3892 gfc_check_srand (gfc_expr
*x
)
3894 if (scalar_check (x
, 0) == FAILURE
)
3897 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
3900 if (kind_value_check(x
, 0, 4) == FAILURE
)
3908 gfc_check_ctime_sub (gfc_expr
*time
, gfc_expr
*result
)
3910 if (scalar_check (time
, 0) == FAILURE
)
3912 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
3915 if (type_check (result
, 1, BT_CHARACTER
) == FAILURE
)
3917 if (kind_value_check (result
, 1, gfc_default_character_kind
) == FAILURE
)
3925 gfc_check_dtime_etime (gfc_expr
*x
)
3927 if (array_check (x
, 0) == FAILURE
)
3930 if (rank_check (x
, 0, 1) == FAILURE
)
3933 if (variable_check (x
, 0) == FAILURE
)
3936 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3939 if (kind_value_check(x
, 0, 4) == FAILURE
)
3947 gfc_check_dtime_etime_sub (gfc_expr
*values
, gfc_expr
*time
)
3949 if (array_check (values
, 0) == FAILURE
)
3952 if (rank_check (values
, 0, 1) == FAILURE
)
3955 if (variable_check (values
, 0) == FAILURE
)
3958 if (type_check (values
, 0, BT_REAL
) == FAILURE
)
3961 if (kind_value_check(values
, 0, 4) == FAILURE
)
3964 if (scalar_check (time
, 1) == FAILURE
)
3967 if (type_check (time
, 1, BT_REAL
) == FAILURE
)
3970 if (kind_value_check(time
, 1, 4) == FAILURE
)
3978 gfc_check_fdate_sub (gfc_expr
*date
)
3980 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
3982 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
3990 gfc_check_gerror (gfc_expr
*msg
)
3992 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
3994 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4002 gfc_check_getcwd_sub (gfc_expr
*cwd
, gfc_expr
*status
)
4004 if (type_check (cwd
, 0, BT_CHARACTER
) == FAILURE
)
4006 if (kind_value_check (cwd
, 0, gfc_default_character_kind
) == FAILURE
)
4012 if (scalar_check (status
, 1) == FAILURE
)
4015 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4023 gfc_check_getarg (gfc_expr
*pos
, gfc_expr
*value
)
4025 if (type_check (pos
, 0, BT_INTEGER
) == FAILURE
)
4028 if (pos
->ts
.kind
> gfc_default_integer_kind
)
4030 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4031 "not wider than the default kind (%d)",
4032 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
4033 &pos
->where
, gfc_default_integer_kind
);
4037 if (type_check (value
, 1, BT_CHARACTER
) == FAILURE
)
4039 if (kind_value_check (value
, 1, gfc_default_character_kind
) == FAILURE
)
4047 gfc_check_getlog (gfc_expr
*msg
)
4049 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
4051 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4059 gfc_check_exit (gfc_expr
*status
)
4064 if (type_check (status
, 0, BT_INTEGER
) == FAILURE
)
4067 if (scalar_check (status
, 0) == FAILURE
)
4075 gfc_check_flush (gfc_expr
*unit
)
4080 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4083 if (scalar_check (unit
, 0) == FAILURE
)
4091 gfc_check_free (gfc_expr
*i
)
4093 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
4096 if (scalar_check (i
, 0) == FAILURE
)
4104 gfc_check_hostnm (gfc_expr
*name
)
4106 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4108 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4116 gfc_check_hostnm_sub (gfc_expr
*name
, gfc_expr
*status
)
4118 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4120 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4126 if (scalar_check (status
, 1) == FAILURE
)
4129 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4137 gfc_check_itime_idate (gfc_expr
*values
)
4139 if (array_check (values
, 0) == FAILURE
)
4142 if (rank_check (values
, 0, 1) == FAILURE
)
4145 if (variable_check (values
, 0) == FAILURE
)
4148 if (type_check (values
, 0, BT_INTEGER
) == FAILURE
)
4151 if (kind_value_check(values
, 0, gfc_default_integer_kind
) == FAILURE
)
4159 gfc_check_ltime_gmtime (gfc_expr
*time
, gfc_expr
*values
)
4161 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
4164 if (kind_value_check(time
, 0, gfc_default_integer_kind
) == FAILURE
)
4167 if (scalar_check (time
, 0) == FAILURE
)
4170 if (array_check (values
, 1) == FAILURE
)
4173 if (rank_check (values
, 1, 1) == FAILURE
)
4176 if (variable_check (values
, 1) == FAILURE
)
4179 if (type_check (values
, 1, BT_INTEGER
) == FAILURE
)
4182 if (kind_value_check(values
, 1, gfc_default_integer_kind
) == FAILURE
)
4190 gfc_check_ttynam_sub (gfc_expr
*unit
, gfc_expr
*name
)
4192 if (scalar_check (unit
, 0) == FAILURE
)
4195 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4198 if (type_check (name
, 1, BT_CHARACTER
) == FAILURE
)
4200 if (kind_value_check (name
, 1, gfc_default_character_kind
) == FAILURE
)
4208 gfc_check_isatty (gfc_expr
*unit
)
4213 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4216 if (scalar_check (unit
, 0) == FAILURE
)
4224 gfc_check_isnan (gfc_expr
*x
)
4226 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4234 gfc_check_perror (gfc_expr
*string
)
4236 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
)
4238 if (kind_value_check (string
, 0, gfc_default_character_kind
) == FAILURE
)
4246 gfc_check_umask (gfc_expr
*mask
)
4248 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
4251 if (scalar_check (mask
, 0) == FAILURE
)
4259 gfc_check_umask_sub (gfc_expr
*mask
, gfc_expr
*old
)
4261 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
4264 if (scalar_check (mask
, 0) == FAILURE
)
4270 if (scalar_check (old
, 1) == FAILURE
)
4273 if (type_check (old
, 1, BT_INTEGER
) == FAILURE
)
4281 gfc_check_unlink (gfc_expr
*name
)
4283 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4285 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4293 gfc_check_unlink_sub (gfc_expr
*name
, gfc_expr
*status
)
4295 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4297 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4303 if (scalar_check (status
, 1) == FAILURE
)
4306 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4314 gfc_check_signal (gfc_expr
*number
, gfc_expr
*handler
)
4316 if (scalar_check (number
, 0) == FAILURE
)
4319 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
4322 if (handler
->ts
.type
!= BT_INTEGER
&& handler
->ts
.type
!= BT_PROCEDURE
)
4324 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4325 "or PROCEDURE", gfc_current_intrinsic_arg
[1],
4326 gfc_current_intrinsic
, &handler
->where
);
4330 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4338 gfc_check_signal_sub (gfc_expr
*number
, gfc_expr
*handler
, gfc_expr
*status
)
4340 if (scalar_check (number
, 0) == FAILURE
)
4343 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
4346 if (handler
->ts
.type
!= BT_INTEGER
&& handler
->ts
.type
!= BT_PROCEDURE
)
4348 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4349 "or PROCEDURE", gfc_current_intrinsic_arg
[1],
4350 gfc_current_intrinsic
, &handler
->where
);
4354 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4360 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
4363 if (scalar_check (status
, 2) == FAILURE
)
4371 gfc_check_system_sub (gfc_expr
*cmd
, gfc_expr
*status
)
4373 if (type_check (cmd
, 0, BT_CHARACTER
) == FAILURE
)
4375 if (kind_value_check (cmd
, 0, gfc_default_character_kind
) == FAILURE
)
4378 if (scalar_check (status
, 1) == FAILURE
)
4381 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4384 if (kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
)
4391 /* This is used for the GNU intrinsics AND, OR and XOR. */
4393 gfc_check_and (gfc_expr
*i
, gfc_expr
*j
)
4395 if (i
->ts
.type
!= BT_INTEGER
&& i
->ts
.type
!= BT_LOGICAL
)
4397 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4398 "or LOGICAL", gfc_current_intrinsic_arg
[0],
4399 gfc_current_intrinsic
, &i
->where
);
4403 if (j
->ts
.type
!= BT_INTEGER
&& j
->ts
.type
!= BT_LOGICAL
)
4405 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4406 "or LOGICAL", gfc_current_intrinsic_arg
[1],
4407 gfc_current_intrinsic
, &j
->where
);
4411 if (i
->ts
.type
!= j
->ts
.type
)
4413 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
4414 "have the same type", gfc_current_intrinsic_arg
[0],
4415 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
4420 if (scalar_check (i
, 0) == FAILURE
)
4423 if (scalar_check (j
, 1) == FAILURE
)