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 /* If expr is a constant, then check to ensure that it is greater than
248 nonnegative_check (const char *arg
, gfc_expr
*expr
)
252 if (expr
->expr_type
== EXPR_CONSTANT
)
254 gfc_extract_int (expr
, &i
);
257 gfc_error ("'%s' at %L must be nonnegative", arg
, &expr
->where
);
266 /* If expr2 is constant, then check that the value is less than
270 less_than_bitsize1 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
275 if (expr2
->expr_type
== EXPR_CONSTANT
)
277 gfc_extract_int (expr2
, &i2
);
278 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
279 if (i2
>= gfc_integer_kinds
[i3
].bit_size
)
281 gfc_error ("'%s' at %L must be less than BIT_SIZE('%s')",
282 arg2
, &expr2
->where
, arg1
);
291 /* If expr2 and expr3 are constants, then check that the value is less than
292 or equal to bit_size(expr1). */
295 less_than_bitsize2 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
296 gfc_expr
*expr2
, const char *arg3
, gfc_expr
*expr3
)
300 if (expr2
->expr_type
== EXPR_CONSTANT
&& expr3
->expr_type
== EXPR_CONSTANT
)
302 gfc_extract_int (expr2
, &i2
);
303 gfc_extract_int (expr3
, &i3
);
305 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
306 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
308 gfc_error ("'%s + %s' at %L must be less than or equal "
310 arg2
, arg3
, &expr2
->where
, arg1
);
318 /* Make sure two expressions have the same type. */
321 same_type_check (gfc_expr
*e
, int n
, gfc_expr
*f
, int m
)
323 if (gfc_compare_types (&e
->ts
, &f
->ts
))
326 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
327 "and kind as '%s'", gfc_current_intrinsic_arg
[m
],
328 gfc_current_intrinsic
, &f
->where
, gfc_current_intrinsic_arg
[n
]);
334 /* Make sure that an expression has a certain (nonzero) rank. */
337 rank_check (gfc_expr
*e
, int n
, int rank
)
342 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
343 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
350 /* Make sure a variable expression is not an optional dummy argument. */
353 nonoptional_check (gfc_expr
*e
, int n
)
355 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.optional
)
357 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
358 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
362 /* TODO: Recursive check on nonoptional variables? */
368 /* Check that an expression has a particular kind. */
371 kind_value_check (gfc_expr
*e
, int n
, int k
)
376 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
377 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
384 /* Make sure an expression is a variable. */
387 variable_check (gfc_expr
*e
, int n
)
389 if ((e
->expr_type
== EXPR_VARIABLE
390 && e
->symtree
->n
.sym
->attr
.flavor
!= FL_PARAMETER
)
391 || (e
->expr_type
== EXPR_FUNCTION
392 && e
->symtree
->n
.sym
->result
== e
->symtree
->n
.sym
))
395 if (e
->expr_type
== EXPR_VARIABLE
396 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
398 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
399 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
,
404 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
405 gfc_current_intrinsic_arg
[n
], gfc_current_intrinsic
, &e
->where
);
411 /* Check the common DIM parameter for correctness. */
414 dim_check (gfc_expr
*dim
, int n
, bool optional
)
419 if (type_check (dim
, n
, BT_INTEGER
) == FAILURE
)
422 if (scalar_check (dim
, n
) == FAILURE
)
425 if (!optional
&& nonoptional_check (dim
, n
) == FAILURE
)
432 /* If a coarray DIM parameter is a constant, make sure that it is greater than
433 zero and less than or equal to the corank of the given array. */
436 dim_corank_check (gfc_expr
*dim
, gfc_expr
*array
)
441 gcc_assert (array
->expr_type
== EXPR_VARIABLE
);
443 if (dim
->expr_type
!= EXPR_CONSTANT
)
446 ar
= gfc_find_array_ref (array
);
447 corank
= ar
->as
->corank
;
449 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
450 || mpz_cmp_ui (dim
->value
.integer
, corank
) > 0)
452 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
453 "codimension index", gfc_current_intrinsic
, &dim
->where
);
462 /* If a DIM parameter is a constant, make sure that it is greater than
463 zero and less than or equal to the rank of the given array. If
464 allow_assumed is zero then dim must be less than the rank of the array
465 for assumed size arrays. */
468 dim_rank_check (gfc_expr
*dim
, gfc_expr
*array
, int allow_assumed
)
476 if (dim
->expr_type
!= EXPR_CONSTANT
)
479 if (array
->expr_type
== EXPR_FUNCTION
&& array
->value
.function
.isym
480 && array
->value
.function
.isym
->id
== GFC_ISYM_SPREAD
)
481 rank
= array
->rank
+ 1;
485 if (array
->expr_type
== EXPR_VARIABLE
)
487 ar
= gfc_find_array_ref (array
);
488 if (ar
->as
->type
== AS_ASSUMED_SIZE
490 && ar
->type
!= AR_ELEMENT
491 && ar
->type
!= AR_SECTION
)
495 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
496 || mpz_cmp_ui (dim
->value
.integer
, rank
) > 0)
498 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
499 "dimension index", gfc_current_intrinsic
, &dim
->where
);
508 /* Compare the size of a along dimension ai with the size of b along
509 dimension bi, returning 0 if they are known not to be identical,
510 and 1 if they are identical, or if this cannot be determined. */
513 identical_dimen_shape (gfc_expr
*a
, int ai
, gfc_expr
*b
, int bi
)
515 mpz_t a_size
, b_size
;
518 gcc_assert (a
->rank
> ai
);
519 gcc_assert (b
->rank
> bi
);
523 if (gfc_array_dimen_size (a
, ai
, &a_size
) == SUCCESS
)
525 if (gfc_array_dimen_size (b
, bi
, &b_size
) == SUCCESS
)
527 if (mpz_cmp (a_size
, b_size
) != 0)
538 /* Check whether two character expressions have the same length;
539 returns SUCCESS if they have or if the length cannot be determined. */
542 gfc_check_same_strlen (const gfc_expr
*a
, const gfc_expr
*b
, const char *name
)
547 if (a
->ts
.u
.cl
&& a
->ts
.u
.cl
->length
548 && a
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
549 len_a
= mpz_get_si (a
->ts
.u
.cl
->length
->value
.integer
);
550 else if (a
->expr_type
== EXPR_CONSTANT
551 && (a
->ts
.u
.cl
== NULL
|| a
->ts
.u
.cl
->length
== NULL
))
552 len_a
= a
->value
.character
.length
;
556 if (b
->ts
.u
.cl
&& b
->ts
.u
.cl
->length
557 && b
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
558 len_b
= mpz_get_si (b
->ts
.u
.cl
->length
->value
.integer
);
559 else if (b
->expr_type
== EXPR_CONSTANT
560 && (b
->ts
.u
.cl
== NULL
|| b
->ts
.u
.cl
->length
== NULL
))
561 len_b
= b
->value
.character
.length
;
568 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
569 len_a
, len_b
, name
, &a
->where
);
574 /***** Check functions *****/
576 /* Check subroutine suitable for intrinsics taking a real argument and
577 a kind argument for the result. */
580 check_a_kind (gfc_expr
*a
, gfc_expr
*kind
, bt type
)
582 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
584 if (kind_check (kind
, 1, type
) == FAILURE
)
591 /* Check subroutine suitable for ceiling, floor and nint. */
594 gfc_check_a_ikind (gfc_expr
*a
, gfc_expr
*kind
)
596 return check_a_kind (a
, kind
, BT_INTEGER
);
600 /* Check subroutine suitable for aint, anint. */
603 gfc_check_a_xkind (gfc_expr
*a
, gfc_expr
*kind
)
605 return check_a_kind (a
, kind
, BT_REAL
);
610 gfc_check_abs (gfc_expr
*a
)
612 if (numeric_check (a
, 0) == FAILURE
)
620 gfc_check_achar (gfc_expr
*a
, gfc_expr
*kind
)
622 if (type_check (a
, 0, BT_INTEGER
) == FAILURE
)
624 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
632 gfc_check_access_func (gfc_expr
*name
, gfc_expr
*mode
)
634 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
635 || scalar_check (name
, 0) == FAILURE
)
637 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
640 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
641 || scalar_check (mode
, 1) == FAILURE
)
643 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
651 gfc_check_all_any (gfc_expr
*mask
, gfc_expr
*dim
)
653 if (logical_array_check (mask
, 0) == FAILURE
)
656 if (dim_check (dim
, 1, false) == FAILURE
)
659 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
667 gfc_check_allocated (gfc_expr
*array
)
669 symbol_attribute attr
;
671 if (variable_check (array
, 0) == FAILURE
)
674 attr
= gfc_variable_attr (array
, NULL
);
675 if (!attr
.allocatable
)
677 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
678 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
687 /* Common check function where the first argument must be real or
688 integer and the second argument must be the same as the first. */
691 gfc_check_a_p (gfc_expr
*a
, gfc_expr
*p
)
693 if (int_or_real_check (a
, 0) == FAILURE
)
696 if (a
->ts
.type
!= p
->ts
.type
)
698 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
699 "have the same type", gfc_current_intrinsic_arg
[0],
700 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
705 if (a
->ts
.kind
!= p
->ts
.kind
)
707 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
708 &p
->where
) == FAILURE
)
717 gfc_check_x_yd (gfc_expr
*x
, gfc_expr
*y
)
719 if (double_check (x
, 0) == FAILURE
|| double_check (y
, 1) == FAILURE
)
727 gfc_check_associated (gfc_expr
*pointer
, gfc_expr
*target
)
729 symbol_attribute attr1
, attr2
;
734 where
= &pointer
->where
;
736 if (pointer
->expr_type
== EXPR_VARIABLE
|| pointer
->expr_type
== EXPR_FUNCTION
)
737 attr1
= gfc_expr_attr (pointer
);
738 else if (pointer
->expr_type
== EXPR_NULL
)
741 gcc_assert (0); /* Pointer must be a variable or a function. */
743 if (!attr1
.pointer
&& !attr1
.proc_pointer
)
745 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
746 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
751 /* Target argument is optional. */
755 where
= &target
->where
;
756 if (target
->expr_type
== EXPR_NULL
)
759 if (target
->expr_type
== EXPR_VARIABLE
|| target
->expr_type
== EXPR_FUNCTION
)
760 attr2
= gfc_expr_attr (target
);
763 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
764 "or target VARIABLE or FUNCTION", gfc_current_intrinsic_arg
[1],
765 gfc_current_intrinsic
, &target
->where
);
769 if (attr1
.pointer
&& !attr2
.pointer
&& !attr2
.target
)
771 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
772 "or a TARGET", gfc_current_intrinsic_arg
[1],
773 gfc_current_intrinsic
, &target
->where
);
778 if (same_type_check (pointer
, 0, target
, 1) == FAILURE
)
780 if (rank_check (target
, 0, pointer
->rank
) == FAILURE
)
782 if (target
->rank
> 0)
784 for (i
= 0; i
< target
->rank
; i
++)
785 if (target
->ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
787 gfc_error ("Array section with a vector subscript at %L shall not "
788 "be the target of a pointer",
798 gfc_error ("NULL pointer at %L is not permitted as actual argument "
799 "of '%s' intrinsic function", where
, gfc_current_intrinsic
);
806 gfc_check_atan_2 (gfc_expr
*y
, gfc_expr
*x
)
808 /* gfc_notify_std would be a wast of time as the return value
809 is seemingly used only for the generic resolution. The error
810 will be: Too many arguments. */
811 if ((gfc_option
.allow_std
& GFC_STD_F2008
) == 0)
814 return gfc_check_atan2 (y
, x
);
819 gfc_check_atan2 (gfc_expr
*y
, gfc_expr
*x
)
821 if (type_check (y
, 0, BT_REAL
) == FAILURE
)
823 if (same_type_check (y
, 0, x
, 1) == FAILURE
)
830 /* BESJN and BESYN functions. */
833 gfc_check_besn (gfc_expr
*n
, gfc_expr
*x
)
835 if (type_check (n
, 0, BT_INTEGER
) == FAILURE
)
838 if (type_check (x
, 1, BT_REAL
) == FAILURE
)
846 gfc_check_bitfcn (gfc_expr
*i
, gfc_expr
*pos
)
848 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
851 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
854 if (nonnegative_check ("pos", pos
) == FAILURE
)
857 if (less_than_bitsize1 ("i", i
, "pos", pos
) == FAILURE
)
865 gfc_check_char (gfc_expr
*i
, gfc_expr
*kind
)
867 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
869 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
877 gfc_check_chdir (gfc_expr
*dir
)
879 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
881 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
889 gfc_check_chdir_sub (gfc_expr
*dir
, gfc_expr
*status
)
891 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
893 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
899 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
901 if (scalar_check (status
, 1) == FAILURE
)
909 gfc_check_chmod (gfc_expr
*name
, gfc_expr
*mode
)
911 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
913 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
916 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
918 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
926 gfc_check_chmod_sub (gfc_expr
*name
, gfc_expr
*mode
, gfc_expr
*status
)
928 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
930 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
933 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
935 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
941 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
944 if (scalar_check (status
, 2) == FAILURE
)
952 gfc_check_cmplx (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
954 if (numeric_check (x
, 0) == FAILURE
)
959 if (numeric_check (y
, 1) == FAILURE
)
962 if (x
->ts
.type
== BT_COMPLEX
)
964 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
965 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg
[1],
966 gfc_current_intrinsic
, &y
->where
);
970 if (y
->ts
.type
== BT_COMPLEX
)
972 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
973 "of either REAL or INTEGER", gfc_current_intrinsic_arg
[1],
974 gfc_current_intrinsic
, &y
->where
);
980 if (kind_check (kind
, 2, BT_COMPLEX
) == FAILURE
)
988 gfc_check_complex (gfc_expr
*x
, gfc_expr
*y
)
990 if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
992 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
993 "or REAL", gfc_current_intrinsic_arg
[0],
994 gfc_current_intrinsic
, &x
->where
);
997 if (scalar_check (x
, 0) == FAILURE
)
1000 if (y
->ts
.type
!= BT_INTEGER
&& y
->ts
.type
!= BT_REAL
)
1002 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
1003 "or REAL", gfc_current_intrinsic_arg
[1],
1004 gfc_current_intrinsic
, &y
->where
);
1007 if (scalar_check (y
, 1) == FAILURE
)
1015 gfc_check_count (gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
1017 if (logical_array_check (mask
, 0) == FAILURE
)
1019 if (dim_check (dim
, 1, false) == FAILURE
)
1021 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
1023 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1025 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1026 "with KIND argument at %L",
1027 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1035 gfc_check_cshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*dim
)
1037 if (array_check (array
, 0) == FAILURE
)
1040 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1043 if (dim_check (dim
, 2, true) == FAILURE
)
1046 if (dim_rank_check (dim
, array
, false) == FAILURE
)
1049 if (array
->rank
== 1 || shift
->rank
== 0)
1051 if (scalar_check (shift
, 1) == FAILURE
)
1054 else if (shift
->rank
== array
->rank
- 1)
1059 else if (dim
->expr_type
== EXPR_CONSTANT
)
1060 gfc_extract_int (dim
, &d
);
1067 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1070 if (!identical_dimen_shape (array
, i
, shift
, j
))
1072 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1073 "invalid shape in dimension %d (%ld/%ld)",
1074 gfc_current_intrinsic_arg
[1],
1075 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1076 mpz_get_si (array
->shape
[i
]),
1077 mpz_get_si (shift
->shape
[j
]));
1087 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1088 "%d or be a scalar", gfc_current_intrinsic_arg
[1],
1089 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1098 gfc_check_ctime (gfc_expr
*time
)
1100 if (scalar_check (time
, 0) == FAILURE
)
1103 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
1110 gfc_try
gfc_check_datan2 (gfc_expr
*y
, gfc_expr
*x
)
1112 if (double_check (y
, 0) == FAILURE
|| double_check (x
, 1) == FAILURE
)
1119 gfc_check_dcmplx (gfc_expr
*x
, gfc_expr
*y
)
1121 if (numeric_check (x
, 0) == FAILURE
)
1126 if (numeric_check (y
, 1) == FAILURE
)
1129 if (x
->ts
.type
== BT_COMPLEX
)
1131 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1132 "present if 'x' is COMPLEX", gfc_current_intrinsic_arg
[1],
1133 gfc_current_intrinsic
, &y
->where
);
1137 if (y
->ts
.type
== BT_COMPLEX
)
1139 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1140 "of either REAL or INTEGER", gfc_current_intrinsic_arg
[1],
1141 gfc_current_intrinsic
, &y
->where
);
1151 gfc_check_dble (gfc_expr
*x
)
1153 if (numeric_check (x
, 0) == FAILURE
)
1161 gfc_check_digits (gfc_expr
*x
)
1163 if (int_or_real_check (x
, 0) == FAILURE
)
1171 gfc_check_dot_product (gfc_expr
*vector_a
, gfc_expr
*vector_b
)
1173 switch (vector_a
->ts
.type
)
1176 if (type_check (vector_b
, 1, BT_LOGICAL
) == FAILURE
)
1183 if (numeric_check (vector_b
, 1) == FAILURE
)
1188 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1189 "or LOGICAL", gfc_current_intrinsic_arg
[0],
1190 gfc_current_intrinsic
, &vector_a
->where
);
1194 if (rank_check (vector_a
, 0, 1) == FAILURE
)
1197 if (rank_check (vector_b
, 1, 1) == FAILURE
)
1200 if (! identical_dimen_shape (vector_a
, 0, vector_b
, 0))
1202 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1203 "intrinsic 'dot_product'", gfc_current_intrinsic_arg
[0],
1204 gfc_current_intrinsic_arg
[1], &vector_a
->where
);
1213 gfc_check_dprod (gfc_expr
*x
, gfc_expr
*y
)
1215 if (type_check (x
, 0, BT_REAL
) == FAILURE
1216 || type_check (y
, 1, BT_REAL
) == FAILURE
)
1219 if (x
->ts
.kind
!= gfc_default_real_kind
)
1221 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1222 "real", gfc_current_intrinsic_arg
[0],
1223 gfc_current_intrinsic
, &x
->where
);
1227 if (y
->ts
.kind
!= gfc_default_real_kind
)
1229 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1230 "real", gfc_current_intrinsic_arg
[1],
1231 gfc_current_intrinsic
, &y
->where
);
1240 gfc_check_eoshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*boundary
,
1243 if (array_check (array
, 0) == FAILURE
)
1246 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1249 if (dim_check (dim
, 3, true) == FAILURE
)
1252 if (dim_rank_check (dim
, array
, false) == FAILURE
)
1255 if (array
->rank
== 1 || shift
->rank
== 0)
1257 if (scalar_check (shift
, 1) == FAILURE
)
1260 else if (shift
->rank
== array
->rank
- 1)
1265 else if (dim
->expr_type
== EXPR_CONSTANT
)
1266 gfc_extract_int (dim
, &d
);
1273 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1276 if (!identical_dimen_shape (array
, i
, shift
, j
))
1278 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1279 "invalid shape in dimension %d (%ld/%ld)",
1280 gfc_current_intrinsic_arg
[1],
1281 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1282 mpz_get_si (array
->shape
[i
]),
1283 mpz_get_si (shift
->shape
[j
]));
1293 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1294 "%d or be a scalar", gfc_current_intrinsic_arg
[1],
1295 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1299 if (boundary
!= NULL
)
1301 if (same_type_check (array
, 0, boundary
, 2) == FAILURE
)
1304 if (array
->rank
== 1 || boundary
->rank
== 0)
1306 if (scalar_check (boundary
, 2) == FAILURE
)
1309 else if (boundary
->rank
== array
->rank
- 1)
1311 if (gfc_check_conformance (shift
, boundary
,
1312 "arguments '%s' and '%s' for "
1314 gfc_current_intrinsic_arg
[1],
1315 gfc_current_intrinsic_arg
[2],
1316 gfc_current_intrinsic
) == FAILURE
)
1321 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1322 "rank %d or be a scalar", gfc_current_intrinsic_arg
[1],
1323 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1332 gfc_check_float (gfc_expr
*a
)
1334 if (type_check (a
, 0, BT_INTEGER
) == FAILURE
)
1337 if ((a
->ts
.kind
!= gfc_default_integer_kind
)
1338 && gfc_notify_std (GFC_STD_GNU
, "GNU extension: non-default INTEGER"
1339 "kind argument to %s intrinsic at %L",
1340 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
1346 /* A single complex argument. */
1349 gfc_check_fn_c (gfc_expr
*a
)
1351 if (type_check (a
, 0, BT_COMPLEX
) == FAILURE
)
1357 /* A single real argument. */
1360 gfc_check_fn_r (gfc_expr
*a
)
1362 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
1368 /* A single double argument. */
1371 gfc_check_fn_d (gfc_expr
*a
)
1373 if (double_check (a
, 0) == FAILURE
)
1379 /* A single real or complex argument. */
1382 gfc_check_fn_rc (gfc_expr
*a
)
1384 if (real_or_complex_check (a
, 0) == FAILURE
)
1392 gfc_check_fn_rc2008 (gfc_expr
*a
)
1394 if (real_or_complex_check (a
, 0) == FAILURE
)
1397 if (a
->ts
.type
== BT_COMPLEX
1398 && gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: COMPLEX argument '%s' "
1399 "argument of '%s' intrinsic at %L",
1400 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
1401 &a
->where
) == FAILURE
)
1409 gfc_check_fnum (gfc_expr
*unit
)
1411 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
1414 if (scalar_check (unit
, 0) == FAILURE
)
1422 gfc_check_huge (gfc_expr
*x
)
1424 if (int_or_real_check (x
, 0) == FAILURE
)
1432 gfc_check_hypot (gfc_expr
*x
, gfc_expr
*y
)
1434 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
1436 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
1443 /* Check that the single argument is an integer. */
1446 gfc_check_i (gfc_expr
*i
)
1448 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1456 gfc_check_iand (gfc_expr
*i
, gfc_expr
*j
)
1458 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1461 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1464 if (i
->ts
.kind
!= j
->ts
.kind
)
1466 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1467 &i
->where
) == FAILURE
)
1476 gfc_check_ibits (gfc_expr
*i
, gfc_expr
*pos
, gfc_expr
*len
)
1478 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1481 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
1484 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
1487 if (nonnegative_check ("pos", pos
) == FAILURE
)
1490 if (nonnegative_check ("len", len
) == FAILURE
)
1493 if (less_than_bitsize2 ("i", i
, "pos", pos
, "len", len
) == FAILURE
)
1501 gfc_check_ichar_iachar (gfc_expr
*c
, gfc_expr
*kind
)
1505 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
1508 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1511 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1512 "with KIND argument at %L",
1513 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1516 if (c
->expr_type
== EXPR_VARIABLE
|| c
->expr_type
== EXPR_SUBSTRING
)
1522 /* Substring references don't have the charlength set. */
1524 while (ref
&& ref
->type
!= REF_SUBSTRING
)
1527 gcc_assert (ref
== NULL
|| ref
->type
== REF_SUBSTRING
);
1531 /* Check that the argument is length one. Non-constant lengths
1532 can't be checked here, so assume they are ok. */
1533 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
)
1535 /* If we already have a length for this expression then use it. */
1536 if (c
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
1538 i
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
1545 start
= ref
->u
.ss
.start
;
1546 end
= ref
->u
.ss
.end
;
1549 if (end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
1550 || start
->expr_type
!= EXPR_CONSTANT
)
1553 i
= mpz_get_si (end
->value
.integer
) + 1
1554 - mpz_get_si (start
->value
.integer
);
1562 gfc_error ("Argument of %s at %L must be of length one",
1563 gfc_current_intrinsic
, &c
->where
);
1572 gfc_check_idnint (gfc_expr
*a
)
1574 if (double_check (a
, 0) == FAILURE
)
1582 gfc_check_ieor (gfc_expr
*i
, gfc_expr
*j
)
1584 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1587 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1590 if (i
->ts
.kind
!= j
->ts
.kind
)
1592 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1593 &i
->where
) == FAILURE
)
1602 gfc_check_index (gfc_expr
*string
, gfc_expr
*substring
, gfc_expr
*back
,
1605 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
1606 || type_check (substring
, 1, BT_CHARACTER
) == FAILURE
)
1609 if (back
!= NULL
&& type_check (back
, 2, BT_LOGICAL
) == FAILURE
)
1612 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
1614 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1615 "with KIND argument at %L",
1616 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1619 if (string
->ts
.kind
!= substring
->ts
.kind
)
1621 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1622 "kind as '%s'", gfc_current_intrinsic_arg
[1],
1623 gfc_current_intrinsic
, &substring
->where
,
1624 gfc_current_intrinsic_arg
[0]);
1633 gfc_check_int (gfc_expr
*x
, gfc_expr
*kind
)
1635 if (numeric_check (x
, 0) == FAILURE
)
1638 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1646 gfc_check_intconv (gfc_expr
*x
)
1648 if (numeric_check (x
, 0) == FAILURE
)
1656 gfc_check_ior (gfc_expr
*i
, gfc_expr
*j
)
1658 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1661 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1664 if (i
->ts
.kind
!= j
->ts
.kind
)
1666 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1667 &i
->where
) == FAILURE
)
1676 gfc_check_ishft (gfc_expr
*i
, gfc_expr
*shift
)
1678 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
1679 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1687 gfc_check_ishftc (gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
1689 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
1690 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1693 if (size
!= NULL
&& type_check (size
, 2, BT_INTEGER
) == FAILURE
)
1701 gfc_check_kill (gfc_expr
*pid
, gfc_expr
*sig
)
1703 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
1706 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
1714 gfc_check_kill_sub (gfc_expr
*pid
, gfc_expr
*sig
, gfc_expr
*status
)
1716 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
1719 if (scalar_check (pid
, 0) == FAILURE
)
1722 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
1725 if (scalar_check (sig
, 1) == FAILURE
)
1731 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1734 if (scalar_check (status
, 2) == FAILURE
)
1742 gfc_check_kind (gfc_expr
*x
)
1744 if (x
->ts
.type
== BT_DERIVED
)
1746 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1747 "non-derived type", gfc_current_intrinsic_arg
[0],
1748 gfc_current_intrinsic
, &x
->where
);
1757 gfc_check_lbound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
1759 if (array_check (array
, 0) == FAILURE
)
1762 if (dim_check (dim
, 1, false) == FAILURE
)
1765 if (dim_rank_check (dim
, array
, 1) == FAILURE
)
1768 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1770 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1771 "with KIND argument at %L",
1772 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1780 gfc_check_lcobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
1782 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
1784 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
1788 if (!is_coarray (coarray
))
1790 gfc_error ("Expected coarray variable as '%s' argument to the LCOBOUND "
1791 "intrinsic at %L", gfc_current_intrinsic_arg
[0], &coarray
->where
);
1797 if (dim_check (dim
, 1, false) == FAILURE
)
1800 if (dim_corank_check (dim
, coarray
) == FAILURE
)
1804 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1812 gfc_check_len_lentrim (gfc_expr
*s
, gfc_expr
*kind
)
1814 if (type_check (s
, 0, BT_CHARACTER
) == FAILURE
)
1817 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1819 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1820 "with KIND argument at %L",
1821 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1829 gfc_check_lge_lgt_lle_llt (gfc_expr
*a
, gfc_expr
*b
)
1831 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
1833 if (kind_value_check (a
, 0, gfc_default_character_kind
) == FAILURE
)
1836 if (type_check (b
, 1, BT_CHARACTER
) == FAILURE
)
1838 if (kind_value_check (b
, 1, gfc_default_character_kind
) == FAILURE
)
1846 gfc_check_link (gfc_expr
*path1
, gfc_expr
*path2
)
1848 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
1850 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
1853 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
1855 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
1863 gfc_check_link_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
1865 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
1867 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
1870 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
1872 if (kind_value_check (path2
, 0, gfc_default_character_kind
) == FAILURE
)
1878 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1881 if (scalar_check (status
, 2) == FAILURE
)
1889 gfc_check_loc (gfc_expr
*expr
)
1891 return variable_check (expr
, 0);
1896 gfc_check_symlnk (gfc_expr
*path1
, gfc_expr
*path2
)
1898 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
1900 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
1903 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
1905 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
1913 gfc_check_symlnk_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
1915 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
1917 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
1920 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
1922 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
1928 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1931 if (scalar_check (status
, 2) == FAILURE
)
1939 gfc_check_logical (gfc_expr
*a
, gfc_expr
*kind
)
1941 if (type_check (a
, 0, BT_LOGICAL
) == FAILURE
)
1943 if (kind_check (kind
, 1, BT_LOGICAL
) == FAILURE
)
1950 /* Min/max family. */
1953 min_max_args (gfc_actual_arglist
*arg
)
1955 if (arg
== NULL
|| arg
->next
== NULL
)
1957 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
1958 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
1967 check_rest (bt type
, int kind
, gfc_actual_arglist
*arglist
)
1969 gfc_actual_arglist
*arg
, *tmp
;
1974 if (min_max_args (arglist
) == FAILURE
)
1977 for (arg
= arglist
, n
=1; arg
; arg
= arg
->next
, n
++)
1980 if (x
->ts
.type
!= type
|| x
->ts
.kind
!= kind
)
1982 if (x
->ts
.type
== type
)
1984 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type "
1985 "kinds at %L", &x
->where
) == FAILURE
)
1990 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
1991 "%s(%d)", n
, gfc_current_intrinsic
, &x
->where
,
1992 gfc_basic_typename (type
), kind
);
1997 for (tmp
= arglist
, m
=1; tmp
!= arg
; tmp
= tmp
->next
, m
++)
1998 if (gfc_check_conformance (tmp
->expr
, x
,
1999 "arguments 'a%d' and 'a%d' for "
2000 "intrinsic '%s'", m
, n
,
2001 gfc_current_intrinsic
) == FAILURE
)
2010 gfc_check_min_max (gfc_actual_arglist
*arg
)
2014 if (min_max_args (arg
) == FAILURE
)
2019 if (x
->ts
.type
== BT_CHARACTER
)
2021 if (gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
2022 "with CHARACTER argument at %L",
2023 gfc_current_intrinsic
, &x
->where
) == FAILURE
)
2026 else if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
2028 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
2029 "REAL or CHARACTER", gfc_current_intrinsic
, &x
->where
);
2033 return check_rest (x
->ts
.type
, x
->ts
.kind
, arg
);
2038 gfc_check_min_max_integer (gfc_actual_arglist
*arg
)
2040 return check_rest (BT_INTEGER
, gfc_default_integer_kind
, arg
);
2045 gfc_check_min_max_real (gfc_actual_arglist
*arg
)
2047 return check_rest (BT_REAL
, gfc_default_real_kind
, arg
);
2052 gfc_check_min_max_double (gfc_actual_arglist
*arg
)
2054 return check_rest (BT_REAL
, gfc_default_double_kind
, arg
);
2058 /* End of min/max family. */
2061 gfc_check_malloc (gfc_expr
*size
)
2063 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
2066 if (scalar_check (size
, 0) == FAILURE
)
2074 gfc_check_matmul (gfc_expr
*matrix_a
, gfc_expr
*matrix_b
)
2076 if ((matrix_a
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_a
->ts
))
2078 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2079 "or LOGICAL", gfc_current_intrinsic_arg
[0],
2080 gfc_current_intrinsic
, &matrix_a
->where
);
2084 if ((matrix_b
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_b
->ts
))
2086 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2087 "or LOGICAL", gfc_current_intrinsic_arg
[1],
2088 gfc_current_intrinsic
, &matrix_b
->where
);
2092 if ((matrix_a
->ts
.type
== BT_LOGICAL
&& gfc_numeric_ts (&matrix_b
->ts
))
2093 || (gfc_numeric_ts (&matrix_a
->ts
) && matrix_b
->ts
.type
== BT_LOGICAL
))
2095 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2096 gfc_current_intrinsic
, &matrix_a
->where
,
2097 gfc_typename(&matrix_a
->ts
), gfc_typename(&matrix_b
->ts
));
2101 switch (matrix_a
->rank
)
2104 if (rank_check (matrix_b
, 1, 2) == FAILURE
)
2106 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2107 if (!identical_dimen_shape (matrix_a
, 0, matrix_b
, 0))
2109 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2110 "and '%s' at %L for intrinsic matmul",
2111 gfc_current_intrinsic_arg
[0],
2112 gfc_current_intrinsic_arg
[1], &matrix_a
->where
);
2118 if (matrix_b
->rank
!= 2)
2120 if (rank_check (matrix_b
, 1, 1) == FAILURE
)
2123 /* matrix_b has rank 1 or 2 here. Common check for the cases
2124 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2125 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2126 if (!identical_dimen_shape (matrix_a
, 1, matrix_b
, 0))
2128 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2129 "dimension 1 for argument '%s' at %L for intrinsic "
2130 "matmul", gfc_current_intrinsic_arg
[0],
2131 gfc_current_intrinsic_arg
[1], &matrix_a
->where
);
2137 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2138 "1 or 2", gfc_current_intrinsic_arg
[0],
2139 gfc_current_intrinsic
, &matrix_a
->where
);
2147 /* Whoever came up with this interface was probably on something.
2148 The possibilities for the occupation of the second and third
2155 NULL MASK minloc(array, mask=m)
2158 I.e. in the case of minloc(array,mask), mask will be in the second
2159 position of the argument list and we'll have to fix that up. */
2162 gfc_check_minloc_maxloc (gfc_actual_arglist
*ap
)
2164 gfc_expr
*a
, *m
, *d
;
2167 if (int_or_real_check (a
, 0) == FAILURE
|| array_check (a
, 0) == FAILURE
)
2171 m
= ap
->next
->next
->expr
;
2173 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2174 && ap
->next
->name
== NULL
)
2178 ap
->next
->expr
= NULL
;
2179 ap
->next
->next
->expr
= m
;
2182 if (dim_check (d
, 1, false) == FAILURE
)
2185 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2188 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2192 && gfc_check_conformance (a
, m
,
2193 "arguments '%s' and '%s' for intrinsic %s",
2194 gfc_current_intrinsic_arg
[0],
2195 gfc_current_intrinsic_arg
[2],
2196 gfc_current_intrinsic
) == FAILURE
)
2203 /* Similar to minloc/maxloc, the argument list might need to be
2204 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2205 difference is that MINLOC/MAXLOC take an additional KIND argument.
2206 The possibilities are:
2212 NULL MASK minval(array, mask=m)
2215 I.e. in the case of minval(array,mask), mask will be in the second
2216 position of the argument list and we'll have to fix that up. */
2219 check_reduction (gfc_actual_arglist
*ap
)
2221 gfc_expr
*a
, *m
, *d
;
2225 m
= ap
->next
->next
->expr
;
2227 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2228 && ap
->next
->name
== NULL
)
2232 ap
->next
->expr
= NULL
;
2233 ap
->next
->next
->expr
= m
;
2236 if (dim_check (d
, 1, false) == FAILURE
)
2239 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2242 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2246 && gfc_check_conformance (a
, m
,
2247 "arguments '%s' and '%s' for intrinsic %s",
2248 gfc_current_intrinsic_arg
[0],
2249 gfc_current_intrinsic_arg
[2],
2250 gfc_current_intrinsic
) == FAILURE
)
2258 gfc_check_minval_maxval (gfc_actual_arglist
*ap
)
2260 if (int_or_real_check (ap
->expr
, 0) == FAILURE
2261 || array_check (ap
->expr
, 0) == FAILURE
)
2264 return check_reduction (ap
);
2269 gfc_check_product_sum (gfc_actual_arglist
*ap
)
2271 if (numeric_check (ap
->expr
, 0) == FAILURE
2272 || array_check (ap
->expr
, 0) == FAILURE
)
2275 return check_reduction (ap
);
2280 gfc_check_merge (gfc_expr
*tsource
, gfc_expr
*fsource
, gfc_expr
*mask
)
2282 if (same_type_check (tsource
, 0, fsource
, 1) == FAILURE
)
2285 if (type_check (mask
, 2, BT_LOGICAL
) == FAILURE
)
2288 if (tsource
->ts
.type
== BT_CHARACTER
)
2289 return gfc_check_same_strlen (tsource
, fsource
, "MERGE intrinsic");
2296 gfc_check_move_alloc (gfc_expr
*from
, gfc_expr
*to
)
2298 symbol_attribute attr
;
2300 if (variable_check (from
, 0) == FAILURE
)
2303 attr
= gfc_variable_attr (from
, NULL
);
2304 if (!attr
.allocatable
)
2306 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2307 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
2312 if (variable_check (to
, 0) == FAILURE
)
2315 attr
= gfc_variable_attr (to
, NULL
);
2316 if (!attr
.allocatable
)
2318 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
2319 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
2324 if (same_type_check (to
, 1, from
, 0) == FAILURE
)
2327 if (to
->rank
!= from
->rank
)
2329 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2330 "have the same rank %d/%d", gfc_current_intrinsic_arg
[0],
2331 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
2332 &to
->where
, from
->rank
, to
->rank
);
2336 if (to
->ts
.kind
!= from
->ts
.kind
)
2338 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2339 "be of the same kind %d/%d", gfc_current_intrinsic_arg
[0],
2340 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
2341 &to
->where
, from
->ts
.kind
, to
->ts
.kind
);
2350 gfc_check_nearest (gfc_expr
*x
, gfc_expr
*s
)
2352 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
2355 if (type_check (s
, 1, BT_REAL
) == FAILURE
)
2363 gfc_check_new_line (gfc_expr
*a
)
2365 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
2373 gfc_check_null (gfc_expr
*mold
)
2375 symbol_attribute attr
;
2380 if (variable_check (mold
, 0) == FAILURE
)
2383 attr
= gfc_variable_attr (mold
, NULL
);
2385 if (!attr
.pointer
&& !attr
.proc_pointer
)
2387 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
2388 gfc_current_intrinsic_arg
[0],
2389 gfc_current_intrinsic
, &mold
->where
);
2398 gfc_check_pack (gfc_expr
*array
, gfc_expr
*mask
, gfc_expr
*vector
)
2400 if (array_check (array
, 0) == FAILURE
)
2403 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
2406 if (gfc_check_conformance (array
, mask
,
2407 "arguments '%s' and '%s' for intrinsic '%s'",
2408 gfc_current_intrinsic_arg
[0],
2409 gfc_current_intrinsic_arg
[1],
2410 gfc_current_intrinsic
) == FAILURE
)
2415 mpz_t array_size
, vector_size
;
2416 bool have_array_size
, have_vector_size
;
2418 if (same_type_check (array
, 0, vector
, 2) == FAILURE
)
2421 if (rank_check (vector
, 2, 1) == FAILURE
)
2424 /* VECTOR requires at least as many elements as MASK
2425 has .TRUE. values. */
2426 have_array_size
= gfc_array_size (array
, &array_size
) == SUCCESS
;
2427 have_vector_size
= gfc_array_size (vector
, &vector_size
) == SUCCESS
;
2429 if (have_vector_size
2430 && (mask
->expr_type
== EXPR_ARRAY
2431 || (mask
->expr_type
== EXPR_CONSTANT
2432 && have_array_size
)))
2434 int mask_true_values
= 0;
2436 if (mask
->expr_type
== EXPR_ARRAY
)
2438 gfc_constructor
*mask_ctor
;
2439 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
2442 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
2444 mask_true_values
= 0;
2448 if (mask_ctor
->expr
->value
.logical
)
2451 mask_ctor
= gfc_constructor_next (mask_ctor
);
2454 else if (mask
->expr_type
== EXPR_CONSTANT
&& mask
->value
.logical
)
2455 mask_true_values
= mpz_get_si (array_size
);
2457 if (mpz_get_si (vector_size
) < mask_true_values
)
2459 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2460 "provide at least as many elements as there "
2461 "are .TRUE. values in '%s' (%ld/%d)",
2462 gfc_current_intrinsic_arg
[2],gfc_current_intrinsic
,
2463 &vector
->where
, gfc_current_intrinsic_arg
[1],
2464 mpz_get_si (vector_size
), mask_true_values
);
2469 if (have_array_size
)
2470 mpz_clear (array_size
);
2471 if (have_vector_size
)
2472 mpz_clear (vector_size
);
2480 gfc_check_precision (gfc_expr
*x
)
2482 if (x
->ts
.type
!= BT_REAL
&& x
->ts
.type
!= BT_COMPLEX
)
2484 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of type "
2485 "REAL or COMPLEX", gfc_current_intrinsic_arg
[0],
2486 gfc_current_intrinsic
, &x
->where
);
2495 gfc_check_present (gfc_expr
*a
)
2499 if (variable_check (a
, 0) == FAILURE
)
2502 sym
= a
->symtree
->n
.sym
;
2503 if (!sym
->attr
.dummy
)
2505 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2506 "dummy variable", gfc_current_intrinsic_arg
[0],
2507 gfc_current_intrinsic
, &a
->where
);
2511 if (!sym
->attr
.optional
)
2513 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2514 "an OPTIONAL dummy variable", gfc_current_intrinsic_arg
[0],
2515 gfc_current_intrinsic
, &a
->where
);
2519 /* 13.14.82 PRESENT(A)
2521 Argument. A shall be the name of an optional dummy argument that is
2522 accessible in the subprogram in which the PRESENT function reference
2526 && !(a
->ref
->next
== NULL
&& a
->ref
->type
== REF_ARRAY
2527 && a
->ref
->u
.ar
.type
== AR_FULL
))
2529 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2530 "subobject of '%s'", gfc_current_intrinsic_arg
[0],
2531 gfc_current_intrinsic
, &a
->where
, sym
->name
);
2540 gfc_check_radix (gfc_expr
*x
)
2542 if (int_or_real_check (x
, 0) == FAILURE
)
2550 gfc_check_range (gfc_expr
*x
)
2552 if (numeric_check (x
, 0) == FAILURE
)
2559 /* real, float, sngl. */
2561 gfc_check_real (gfc_expr
*a
, gfc_expr
*kind
)
2563 if (numeric_check (a
, 0) == FAILURE
)
2566 if (kind_check (kind
, 1, BT_REAL
) == FAILURE
)
2574 gfc_check_rename (gfc_expr
*path1
, gfc_expr
*path2
)
2576 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2578 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2581 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2583 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2591 gfc_check_rename_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2593 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2595 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2598 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2600 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2606 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2609 if (scalar_check (status
, 2) == FAILURE
)
2617 gfc_check_repeat (gfc_expr
*x
, gfc_expr
*y
)
2619 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
2622 if (scalar_check (x
, 0) == FAILURE
)
2625 if (type_check (y
, 0, BT_INTEGER
) == FAILURE
)
2628 if (scalar_check (y
, 1) == FAILURE
)
2636 gfc_check_reshape (gfc_expr
*source
, gfc_expr
*shape
,
2637 gfc_expr
*pad
, gfc_expr
*order
)
2643 if (array_check (source
, 0) == FAILURE
)
2646 if (rank_check (shape
, 1, 1) == FAILURE
)
2649 if (type_check (shape
, 1, BT_INTEGER
) == FAILURE
)
2652 if (gfc_array_size (shape
, &size
) != SUCCESS
)
2654 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2655 "array of constant size", &shape
->where
);
2659 shape_size
= mpz_get_ui (size
);
2662 if (shape_size
<= 0)
2664 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
2665 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
2669 else if (shape_size
> GFC_MAX_DIMENSIONS
)
2671 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2672 "than %d elements", &shape
->where
, GFC_MAX_DIMENSIONS
);
2675 else if (shape
->expr_type
== EXPR_ARRAY
)
2679 for (i
= 0; i
< shape_size
; ++i
)
2681 e
= gfc_constructor_lookup_expr (shape
->value
.constructor
, i
);
2682 if (e
->expr_type
!= EXPR_CONSTANT
)
2685 gfc_extract_int (e
, &extent
);
2688 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2689 "negative element (%d)", gfc_current_intrinsic_arg
[1],
2690 gfc_current_intrinsic
, &e
->where
, extent
);
2698 if (same_type_check (source
, 0, pad
, 2) == FAILURE
)
2701 if (array_check (pad
, 2) == FAILURE
)
2707 if (array_check (order
, 3) == FAILURE
)
2710 if (type_check (order
, 3, BT_INTEGER
) == FAILURE
)
2713 if (order
->expr_type
== EXPR_ARRAY
)
2715 int i
, order_size
, dim
, perm
[GFC_MAX_DIMENSIONS
];
2718 for (i
= 0; i
< GFC_MAX_DIMENSIONS
; ++i
)
2721 gfc_array_size (order
, &size
);
2722 order_size
= mpz_get_ui (size
);
2725 if (order_size
!= shape_size
)
2727 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2728 "has wrong number of elements (%d/%d)",
2729 gfc_current_intrinsic_arg
[3],
2730 gfc_current_intrinsic
, &order
->where
,
2731 order_size
, shape_size
);
2735 for (i
= 1; i
<= order_size
; ++i
)
2737 e
= gfc_constructor_lookup_expr (order
->value
.constructor
, i
-1);
2738 if (e
->expr_type
!= EXPR_CONSTANT
)
2741 gfc_extract_int (e
, &dim
);
2743 if (dim
< 1 || dim
> order_size
)
2745 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2746 "has out-of-range dimension (%d)",
2747 gfc_current_intrinsic_arg
[3],
2748 gfc_current_intrinsic
, &e
->where
, dim
);
2752 if (perm
[dim
-1] != 0)
2754 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2755 "invalid permutation of dimensions (dimension "
2756 "'%d' duplicated)", gfc_current_intrinsic_arg
[3],
2757 gfc_current_intrinsic
, &e
->where
, dim
);
2766 if (pad
== NULL
&& shape
->expr_type
== EXPR_ARRAY
2767 && gfc_is_constant_expr (shape
)
2768 && !(source
->expr_type
== EXPR_VARIABLE
&& source
->symtree
->n
.sym
->as
2769 && source
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
))
2771 /* Check the match in size between source and destination. */
2772 if (gfc_array_size (source
, &nelems
) == SUCCESS
)
2778 mpz_init_set_ui (size
, 1);
2779 for (c
= gfc_constructor_first (shape
->value
.constructor
);
2780 c
; c
= gfc_constructor_next (c
))
2781 mpz_mul (size
, size
, c
->expr
->value
.integer
);
2783 test
= mpz_cmp (nelems
, size
) < 0 && mpz_cmp_ui (size
, 0) > 0;
2789 gfc_error ("Without padding, there are not enough elements "
2790 "in the intrinsic RESHAPE source at %L to match "
2791 "the shape", &source
->where
);
2802 gfc_check_same_type_as (gfc_expr
*a
, gfc_expr
*b
)
2805 if (a
->ts
.type
!= BT_DERIVED
&& a
->ts
.type
!= BT_CLASS
)
2807 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2808 "must be of a derived type", gfc_current_intrinsic_arg
[0],
2809 gfc_current_intrinsic
, &a
->where
);
2813 if (!gfc_type_is_extensible (a
->ts
.u
.derived
))
2815 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2816 "must be of an extensible type", gfc_current_intrinsic_arg
[0],
2817 gfc_current_intrinsic
, &a
->where
);
2821 if (b
->ts
.type
!= BT_DERIVED
&& b
->ts
.type
!= BT_CLASS
)
2823 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2824 "must be of a derived type", gfc_current_intrinsic_arg
[1],
2825 gfc_current_intrinsic
, &b
->where
);
2829 if (!gfc_type_is_extensible (b
->ts
.u
.derived
))
2831 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2832 "must be of an extensible type", gfc_current_intrinsic_arg
[1],
2833 gfc_current_intrinsic
, &b
->where
);
2842 gfc_check_scale (gfc_expr
*x
, gfc_expr
*i
)
2844 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
2847 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
2855 gfc_check_scan (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
2857 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
2860 if (type_check (y
, 1, BT_CHARACTER
) == FAILURE
)
2863 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
2866 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
2868 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
2869 "with KIND argument at %L",
2870 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
2873 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
2881 gfc_check_secnds (gfc_expr
*r
)
2883 if (type_check (r
, 0, BT_REAL
) == FAILURE
)
2886 if (kind_value_check (r
, 0, 4) == FAILURE
)
2889 if (scalar_check (r
, 0) == FAILURE
)
2897 gfc_check_selected_char_kind (gfc_expr
*name
)
2899 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
2902 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
2905 if (scalar_check (name
, 0) == FAILURE
)
2913 gfc_check_selected_int_kind (gfc_expr
*r
)
2915 if (type_check (r
, 0, BT_INTEGER
) == FAILURE
)
2918 if (scalar_check (r
, 0) == FAILURE
)
2926 gfc_check_selected_real_kind (gfc_expr
*p
, gfc_expr
*r
, gfc_expr
*radix
)
2928 if (p
== NULL
&& r
== NULL
2929 && gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: SELECTED_REAL_KIND with"
2930 " neither 'P' nor 'R' argument at %L",
2931 gfc_current_intrinsic_where
) == FAILURE
)
2936 if (type_check (p
, 0, BT_INTEGER
) == FAILURE
)
2939 if (scalar_check (p
, 0) == FAILURE
)
2945 if (type_check (r
, 1, BT_INTEGER
) == FAILURE
)
2948 if (scalar_check (r
, 1) == FAILURE
)
2954 if (type_check (radix
, 1, BT_INTEGER
) == FAILURE
)
2957 if (scalar_check (radix
, 1) == FAILURE
)
2960 if (gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: '%s' intrinsic with "
2961 "RADIX argument at %L", gfc_current_intrinsic
,
2962 &radix
->where
) == FAILURE
)
2971 gfc_check_set_exponent (gfc_expr
*x
, gfc_expr
*i
)
2973 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
2976 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
2984 gfc_check_shape (gfc_expr
*source
)
2988 if (source
->rank
== 0 || source
->expr_type
!= EXPR_VARIABLE
)
2991 ar
= gfc_find_array_ref (source
);
2993 if (ar
->as
&& ar
->as
->type
== AS_ASSUMED_SIZE
&& ar
->type
== AR_FULL
)
2995 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
2996 "an assumed size array", &source
->where
);
3005 gfc_check_sign (gfc_expr
*a
, gfc_expr
*b
)
3007 if (int_or_real_check (a
, 0) == FAILURE
)
3010 if (same_type_check (a
, 0, b
, 1) == FAILURE
)
3018 gfc_check_size (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
3020 if (array_check (array
, 0) == FAILURE
)
3023 if (dim_check (dim
, 1, true) == FAILURE
)
3026 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
3029 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3031 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3032 "with KIND argument at %L",
3033 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3042 gfc_check_sizeof (gfc_expr
*arg ATTRIBUTE_UNUSED
)
3049 gfc_check_c_sizeof (gfc_expr
*arg
)
3051 if (verify_c_interop (&arg
->ts
) != SUCCESS
)
3053 gfc_error ("'%s' argument of '%s' intrinsic at %L must be be an "
3054 "interoperable data entity", gfc_current_intrinsic_arg
[0],
3055 gfc_current_intrinsic
, &arg
->where
);
3063 gfc_check_sleep_sub (gfc_expr
*seconds
)
3065 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
3068 if (scalar_check (seconds
, 0) == FAILURE
)
3075 gfc_check_sngl (gfc_expr
*a
)
3077 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
3080 if ((a
->ts
.kind
!= gfc_default_double_kind
)
3081 && gfc_notify_std (GFC_STD_GNU
, "GNU extension: non double precision"
3082 "REAL argument to %s intrinsic at %L",
3083 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
3090 gfc_check_spread (gfc_expr
*source
, gfc_expr
*dim
, gfc_expr
*ncopies
)
3092 if (source
->rank
>= GFC_MAX_DIMENSIONS
)
3094 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
3095 "than rank %d", gfc_current_intrinsic_arg
[0],
3096 gfc_current_intrinsic
, &source
->where
, GFC_MAX_DIMENSIONS
);
3104 if (dim_check (dim
, 1, false) == FAILURE
)
3107 /* dim_rank_check() does not apply here. */
3109 && dim
->expr_type
== EXPR_CONSTANT
3110 && (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
3111 || mpz_cmp_ui (dim
->value
.integer
, source
->rank
+ 1) > 0))
3113 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
3114 "dimension index", gfc_current_intrinsic_arg
[1],
3115 gfc_current_intrinsic
, &dim
->where
);
3119 if (type_check (ncopies
, 2, BT_INTEGER
) == FAILURE
)
3122 if (scalar_check (ncopies
, 2) == FAILURE
)
3129 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3133 gfc_check_fgetputc_sub (gfc_expr
*unit
, gfc_expr
*c
, gfc_expr
*status
)
3135 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3138 if (scalar_check (unit
, 0) == FAILURE
)
3141 if (type_check (c
, 1, BT_CHARACTER
) == FAILURE
)
3143 if (kind_value_check (c
, 1, gfc_default_character_kind
) == FAILURE
)
3149 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3150 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
3151 || scalar_check (status
, 2) == FAILURE
)
3159 gfc_check_fgetputc (gfc_expr
*unit
, gfc_expr
*c
)
3161 return gfc_check_fgetputc_sub (unit
, c
, NULL
);
3166 gfc_check_fgetput_sub (gfc_expr
*c
, gfc_expr
*status
)
3168 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
3170 if (kind_value_check (c
, 0, gfc_default_character_kind
) == FAILURE
)
3176 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
3177 || kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
3178 || scalar_check (status
, 1) == FAILURE
)
3186 gfc_check_fgetput (gfc_expr
*c
)
3188 return gfc_check_fgetput_sub (c
, NULL
);
3193 gfc_check_fseek_sub (gfc_expr
*unit
, gfc_expr
*offset
, gfc_expr
*whence
, gfc_expr
*status
)
3195 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3198 if (scalar_check (unit
, 0) == FAILURE
)
3201 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3204 if (scalar_check (offset
, 1) == FAILURE
)
3207 if (type_check (whence
, 2, BT_INTEGER
) == FAILURE
)
3210 if (scalar_check (whence
, 2) == FAILURE
)
3216 if (type_check (status
, 3, BT_INTEGER
) == FAILURE
)
3219 if (kind_value_check (status
, 3, 4) == FAILURE
)
3222 if (scalar_check (status
, 3) == FAILURE
)
3231 gfc_check_fstat (gfc_expr
*unit
, gfc_expr
*array
)
3233 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3236 if (scalar_check (unit
, 0) == FAILURE
)
3239 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3240 || kind_value_check (unit
, 0, gfc_default_integer_kind
) == FAILURE
)
3243 if (array_check (array
, 1) == FAILURE
)
3251 gfc_check_fstat_sub (gfc_expr
*unit
, gfc_expr
*array
, gfc_expr
*status
)
3253 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3256 if (scalar_check (unit
, 0) == FAILURE
)
3259 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3260 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3263 if (array_check (array
, 1) == FAILURE
)
3269 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3270 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
3273 if (scalar_check (status
, 2) == FAILURE
)
3281 gfc_check_ftell (gfc_expr
*unit
)
3283 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3286 if (scalar_check (unit
, 0) == FAILURE
)
3294 gfc_check_ftell_sub (gfc_expr
*unit
, gfc_expr
*offset
)
3296 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3299 if (scalar_check (unit
, 0) == FAILURE
)
3302 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3305 if (scalar_check (offset
, 1) == FAILURE
)
3313 gfc_check_stat (gfc_expr
*name
, gfc_expr
*array
)
3315 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3317 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3320 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3321 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3324 if (array_check (array
, 1) == FAILURE
)
3332 gfc_check_stat_sub (gfc_expr
*name
, gfc_expr
*array
, gfc_expr
*status
)
3334 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3336 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3339 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3340 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3343 if (array_check (array
, 1) == FAILURE
)
3349 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3350 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3353 if (scalar_check (status
, 2) == FAILURE
)
3361 gfc_check_image_index (gfc_expr
*coarray
, gfc_expr
*sub
)
3363 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3365 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3369 if (!is_coarray (coarray
))
3371 gfc_error ("Expected coarray variable as '%s' argument to IMAGE_INDEX "
3372 "intrinsic at %L", gfc_current_intrinsic_arg
[0], &coarray
->where
);
3378 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3379 gfc_current_intrinsic_arg
[1], &sub
->where
);
3388 gfc_check_this_image (gfc_expr
*coarray
, gfc_expr
*dim
)
3390 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3392 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3396 if (dim
!= NULL
&& coarray
== NULL
)
3398 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3399 "intrinsic at %L", &dim
->where
);
3403 if (coarray
== NULL
)
3406 if (!is_coarray (coarray
))
3408 gfc_error ("Expected coarray variable as '%s' argument to THIS_IMAGE "
3409 "intrinsic at %L", gfc_current_intrinsic_arg
[0], &coarray
->where
);
3415 if (dim_check (dim
, 1, false) == FAILURE
)
3418 if (dim_corank_check (dim
, coarray
) == FAILURE
)
3427 gfc_check_transfer (gfc_expr
*source ATTRIBUTE_UNUSED
,
3428 gfc_expr
*mold ATTRIBUTE_UNUSED
, gfc_expr
*size
)
3430 if (mold
->ts
.type
== BT_HOLLERITH
)
3432 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3433 &mold
->where
, gfc_basic_typename (BT_HOLLERITH
));
3439 if (type_check (size
, 2, BT_INTEGER
) == FAILURE
)
3442 if (scalar_check (size
, 2) == FAILURE
)
3445 if (nonoptional_check (size
, 2) == FAILURE
)
3454 gfc_check_transpose (gfc_expr
*matrix
)
3456 if (rank_check (matrix
, 0, 2) == FAILURE
)
3464 gfc_check_ubound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
3466 if (array_check (array
, 0) == FAILURE
)
3469 if (dim_check (dim
, 1, false) == FAILURE
)
3472 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
3475 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3477 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3478 "with KIND argument at %L",
3479 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3487 gfc_check_ucobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
3489 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3491 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3495 if (!is_coarray (coarray
))
3497 gfc_error ("Expected coarray variable as '%s' argument to the UCOBOUND "
3498 "intrinsic at %L", gfc_current_intrinsic_arg
[0], &coarray
->where
);
3504 if (dim_check (dim
, 1, false) == FAILURE
)
3507 if (dim_corank_check (dim
, coarray
) == FAILURE
)
3511 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3519 gfc_check_unpack (gfc_expr
*vector
, gfc_expr
*mask
, gfc_expr
*field
)
3523 if (rank_check (vector
, 0, 1) == FAILURE
)
3526 if (array_check (mask
, 1) == FAILURE
)
3529 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
3532 if (same_type_check (vector
, 0, field
, 2) == FAILURE
)
3535 if (mask
->expr_type
== EXPR_ARRAY
3536 && gfc_array_size (vector
, &vector_size
) == SUCCESS
)
3538 int mask_true_count
= 0;
3539 gfc_constructor
*mask_ctor
;
3540 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
3543 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
3545 mask_true_count
= 0;
3549 if (mask_ctor
->expr
->value
.logical
)
3552 mask_ctor
= gfc_constructor_next (mask_ctor
);
3555 if (mpz_get_si (vector_size
) < mask_true_count
)
3557 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
3558 "provide at least as many elements as there "
3559 "are .TRUE. values in '%s' (%ld/%d)",
3560 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
3561 &vector
->where
, gfc_current_intrinsic_arg
[1],
3562 mpz_get_si (vector_size
), mask_true_count
);
3566 mpz_clear (vector_size
);
3569 if (mask
->rank
!= field
->rank
&& field
->rank
!= 0)
3571 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
3572 "the same rank as '%s' or be a scalar",
3573 gfc_current_intrinsic_arg
[2], gfc_current_intrinsic
,
3574 &field
->where
, gfc_current_intrinsic_arg
[1]);
3578 if (mask
->rank
== field
->rank
)
3581 for (i
= 0; i
< field
->rank
; i
++)
3582 if (! identical_dimen_shape (mask
, i
, field
, i
))
3584 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
3585 "must have identical shape.",
3586 gfc_current_intrinsic_arg
[2],
3587 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
3597 gfc_check_verify (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
3599 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3602 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
3605 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
3608 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
3610 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3611 "with KIND argument at %L",
3612 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3620 gfc_check_trim (gfc_expr
*x
)
3622 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3625 if (scalar_check (x
, 0) == FAILURE
)
3633 gfc_check_ttynam (gfc_expr
*unit
)
3635 if (scalar_check (unit
, 0) == FAILURE
)
3638 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3645 /* Common check function for the half a dozen intrinsics that have a
3646 single real argument. */
3649 gfc_check_x (gfc_expr
*x
)
3651 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3658 /************* Check functions for intrinsic subroutines *************/
3661 gfc_check_cpu_time (gfc_expr
*time
)
3663 if (scalar_check (time
, 0) == FAILURE
)
3666 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
3669 if (variable_check (time
, 0) == FAILURE
)
3677 gfc_check_date_and_time (gfc_expr
*date
, gfc_expr
*time
,
3678 gfc_expr
*zone
, gfc_expr
*values
)
3682 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
3684 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
3686 if (scalar_check (date
, 0) == FAILURE
)
3688 if (variable_check (date
, 0) == FAILURE
)
3694 if (type_check (time
, 1, BT_CHARACTER
) == FAILURE
)
3696 if (kind_value_check (time
, 1, gfc_default_character_kind
) == FAILURE
)
3698 if (scalar_check (time
, 1) == FAILURE
)
3700 if (variable_check (time
, 1) == FAILURE
)
3706 if (type_check (zone
, 2, BT_CHARACTER
) == FAILURE
)
3708 if (kind_value_check (zone
, 2, gfc_default_character_kind
) == FAILURE
)
3710 if (scalar_check (zone
, 2) == FAILURE
)
3712 if (variable_check (zone
, 2) == FAILURE
)
3718 if (type_check (values
, 3, BT_INTEGER
) == FAILURE
)
3720 if (array_check (values
, 3) == FAILURE
)
3722 if (rank_check (values
, 3, 1) == FAILURE
)
3724 if (variable_check (values
, 3) == FAILURE
)
3733 gfc_check_mvbits (gfc_expr
*from
, gfc_expr
*frompos
, gfc_expr
*len
,
3734 gfc_expr
*to
, gfc_expr
*topos
)
3736 if (type_check (from
, 0, BT_INTEGER
) == FAILURE
)
3739 if (type_check (frompos
, 1, BT_INTEGER
) == FAILURE
)
3742 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
3745 if (same_type_check (from
, 0, to
, 3) == FAILURE
)
3748 if (variable_check (to
, 3) == FAILURE
)
3751 if (type_check (topos
, 4, BT_INTEGER
) == FAILURE
)
3754 if (nonnegative_check ("frompos", frompos
) == FAILURE
)
3757 if (nonnegative_check ("topos", topos
) == FAILURE
)
3760 if (nonnegative_check ("len", len
) == FAILURE
)
3763 if (less_than_bitsize2 ("from", from
, "frompos", frompos
, "len", len
)
3767 if (less_than_bitsize2 ("to", to
, "topos", topos
, "len", len
) == FAILURE
)
3775 gfc_check_random_number (gfc_expr
*harvest
)
3777 if (type_check (harvest
, 0, BT_REAL
) == FAILURE
)
3780 if (variable_check (harvest
, 0) == FAILURE
)
3788 gfc_check_random_seed (gfc_expr
*size
, gfc_expr
*put
, gfc_expr
*get
)
3790 unsigned int nargs
= 0, kiss_size
;
3791 locus
*where
= NULL
;
3792 mpz_t put_size
, get_size
;
3793 bool have_gfc_real_16
; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
3795 have_gfc_real_16
= gfc_validate_kind (BT_REAL
, 16, true) != -1;
3797 /* Keep the number of bytes in sync with kiss_size in
3798 libgfortran/intrinsics/random.c. */
3799 kiss_size
= (have_gfc_real_16
? 48 : 32) / gfc_default_integer_kind
;
3803 if (size
->expr_type
!= EXPR_VARIABLE
3804 || !size
->symtree
->n
.sym
->attr
.optional
)
3807 if (scalar_check (size
, 0) == FAILURE
)
3810 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
3813 if (variable_check (size
, 0) == FAILURE
)
3816 if (kind_value_check (size
, 0, gfc_default_integer_kind
) == FAILURE
)
3822 if (put
->expr_type
!= EXPR_VARIABLE
3823 || !put
->symtree
->n
.sym
->attr
.optional
)
3826 where
= &put
->where
;
3829 if (array_check (put
, 1) == FAILURE
)
3832 if (rank_check (put
, 1, 1) == FAILURE
)
3835 if (type_check (put
, 1, BT_INTEGER
) == FAILURE
)
3838 if (kind_value_check (put
, 1, gfc_default_integer_kind
) == FAILURE
)
3841 if (gfc_array_size (put
, &put_size
) == SUCCESS
3842 && mpz_get_ui (put_size
) < kiss_size
)
3843 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3844 "too small (%i/%i)",
3845 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
, where
,
3846 (int) mpz_get_ui (put_size
), kiss_size
);
3851 if (get
->expr_type
!= EXPR_VARIABLE
3852 || !get
->symtree
->n
.sym
->attr
.optional
)
3855 where
= &get
->where
;
3858 if (array_check (get
, 2) == FAILURE
)
3861 if (rank_check (get
, 2, 1) == FAILURE
)
3864 if (type_check (get
, 2, BT_INTEGER
) == FAILURE
)
3867 if (variable_check (get
, 2) == FAILURE
)
3870 if (kind_value_check (get
, 2, gfc_default_integer_kind
) == FAILURE
)
3873 if (gfc_array_size (get
, &get_size
) == SUCCESS
3874 && mpz_get_ui (get_size
) < kiss_size
)
3875 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
3876 "too small (%i/%i)",
3877 gfc_current_intrinsic_arg
[2], gfc_current_intrinsic
, where
,
3878 (int) mpz_get_ui (get_size
), kiss_size
);
3881 /* RANDOM_SEED may not have more than one non-optional argument. */
3883 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
, where
);
3890 gfc_check_second_sub (gfc_expr
*time
)
3892 if (scalar_check (time
, 0) == FAILURE
)
3895 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
3898 if (kind_value_check(time
, 0, 4) == FAILURE
)
3905 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
3906 count, count_rate, and count_max are all optional arguments */
3909 gfc_check_system_clock (gfc_expr
*count
, gfc_expr
*count_rate
,
3910 gfc_expr
*count_max
)
3914 if (scalar_check (count
, 0) == FAILURE
)
3917 if (type_check (count
, 0, BT_INTEGER
) == FAILURE
)
3920 if (variable_check (count
, 0) == FAILURE
)
3924 if (count_rate
!= NULL
)
3926 if (scalar_check (count_rate
, 1) == FAILURE
)
3929 if (type_check (count_rate
, 1, BT_INTEGER
) == FAILURE
)
3932 if (variable_check (count_rate
, 1) == FAILURE
)
3936 && same_type_check (count
, 0, count_rate
, 1) == FAILURE
)
3941 if (count_max
!= NULL
)
3943 if (scalar_check (count_max
, 2) == FAILURE
)
3946 if (type_check (count_max
, 2, BT_INTEGER
) == FAILURE
)
3949 if (variable_check (count_max
, 2) == FAILURE
)
3953 && same_type_check (count
, 0, count_max
, 2) == FAILURE
)
3956 if (count_rate
!= NULL
3957 && same_type_check (count_rate
, 1, count_max
, 2) == FAILURE
)
3966 gfc_check_irand (gfc_expr
*x
)
3971 if (scalar_check (x
, 0) == FAILURE
)
3974 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
3977 if (kind_value_check(x
, 0, 4) == FAILURE
)
3985 gfc_check_alarm_sub (gfc_expr
*seconds
, gfc_expr
*handler
, gfc_expr
*status
)
3987 if (scalar_check (seconds
, 0) == FAILURE
)
3990 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
3993 if (handler
->ts
.type
!= BT_INTEGER
&& handler
->ts
.type
!= BT_PROCEDURE
)
3995 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
3996 "or PROCEDURE", gfc_current_intrinsic_arg
[1],
3997 gfc_current_intrinsic
, &handler
->where
);
4001 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4007 if (scalar_check (status
, 2) == FAILURE
)
4010 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
4013 if (kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
4021 gfc_check_rand (gfc_expr
*x
)
4026 if (scalar_check (x
, 0) == FAILURE
)
4029 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4032 if (kind_value_check(x
, 0, 4) == FAILURE
)
4040 gfc_check_srand (gfc_expr
*x
)
4042 if (scalar_check (x
, 0) == FAILURE
)
4045 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4048 if (kind_value_check(x
, 0, 4) == FAILURE
)
4056 gfc_check_ctime_sub (gfc_expr
*time
, gfc_expr
*result
)
4058 if (scalar_check (time
, 0) == FAILURE
)
4060 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
4063 if (type_check (result
, 1, BT_CHARACTER
) == FAILURE
)
4065 if (kind_value_check (result
, 1, gfc_default_character_kind
) == FAILURE
)
4073 gfc_check_dtime_etime (gfc_expr
*x
)
4075 if (array_check (x
, 0) == FAILURE
)
4078 if (rank_check (x
, 0, 1) == FAILURE
)
4081 if (variable_check (x
, 0) == FAILURE
)
4084 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4087 if (kind_value_check(x
, 0, 4) == FAILURE
)
4095 gfc_check_dtime_etime_sub (gfc_expr
*values
, gfc_expr
*time
)
4097 if (array_check (values
, 0) == FAILURE
)
4100 if (rank_check (values
, 0, 1) == FAILURE
)
4103 if (variable_check (values
, 0) == FAILURE
)
4106 if (type_check (values
, 0, BT_REAL
) == FAILURE
)
4109 if (kind_value_check(values
, 0, 4) == FAILURE
)
4112 if (scalar_check (time
, 1) == FAILURE
)
4115 if (type_check (time
, 1, BT_REAL
) == FAILURE
)
4118 if (kind_value_check(time
, 1, 4) == FAILURE
)
4126 gfc_check_fdate_sub (gfc_expr
*date
)
4128 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
4130 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
4138 gfc_check_gerror (gfc_expr
*msg
)
4140 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
4142 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4150 gfc_check_getcwd_sub (gfc_expr
*cwd
, gfc_expr
*status
)
4152 if (type_check (cwd
, 0, BT_CHARACTER
) == FAILURE
)
4154 if (kind_value_check (cwd
, 0, gfc_default_character_kind
) == FAILURE
)
4160 if (scalar_check (status
, 1) == FAILURE
)
4163 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4171 gfc_check_getarg (gfc_expr
*pos
, gfc_expr
*value
)
4173 if (type_check (pos
, 0, BT_INTEGER
) == FAILURE
)
4176 if (pos
->ts
.kind
> gfc_default_integer_kind
)
4178 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4179 "not wider than the default kind (%d)",
4180 gfc_current_intrinsic_arg
[0], gfc_current_intrinsic
,
4181 &pos
->where
, gfc_default_integer_kind
);
4185 if (type_check (value
, 1, BT_CHARACTER
) == FAILURE
)
4187 if (kind_value_check (value
, 1, gfc_default_character_kind
) == FAILURE
)
4195 gfc_check_getlog (gfc_expr
*msg
)
4197 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
4199 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4207 gfc_check_exit (gfc_expr
*status
)
4212 if (type_check (status
, 0, BT_INTEGER
) == FAILURE
)
4215 if (scalar_check (status
, 0) == FAILURE
)
4223 gfc_check_flush (gfc_expr
*unit
)
4228 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4231 if (scalar_check (unit
, 0) == FAILURE
)
4239 gfc_check_free (gfc_expr
*i
)
4241 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
4244 if (scalar_check (i
, 0) == FAILURE
)
4252 gfc_check_hostnm (gfc_expr
*name
)
4254 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4256 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4264 gfc_check_hostnm_sub (gfc_expr
*name
, gfc_expr
*status
)
4266 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4268 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4274 if (scalar_check (status
, 1) == FAILURE
)
4277 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4285 gfc_check_itime_idate (gfc_expr
*values
)
4287 if (array_check (values
, 0) == FAILURE
)
4290 if (rank_check (values
, 0, 1) == FAILURE
)
4293 if (variable_check (values
, 0) == FAILURE
)
4296 if (type_check (values
, 0, BT_INTEGER
) == FAILURE
)
4299 if (kind_value_check(values
, 0, gfc_default_integer_kind
) == FAILURE
)
4307 gfc_check_ltime_gmtime (gfc_expr
*time
, gfc_expr
*values
)
4309 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
4312 if (kind_value_check(time
, 0, gfc_default_integer_kind
) == FAILURE
)
4315 if (scalar_check (time
, 0) == FAILURE
)
4318 if (array_check (values
, 1) == FAILURE
)
4321 if (rank_check (values
, 1, 1) == FAILURE
)
4324 if (variable_check (values
, 1) == FAILURE
)
4327 if (type_check (values
, 1, BT_INTEGER
) == FAILURE
)
4330 if (kind_value_check(values
, 1, gfc_default_integer_kind
) == FAILURE
)
4338 gfc_check_ttynam_sub (gfc_expr
*unit
, gfc_expr
*name
)
4340 if (scalar_check (unit
, 0) == FAILURE
)
4343 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4346 if (type_check (name
, 1, BT_CHARACTER
) == FAILURE
)
4348 if (kind_value_check (name
, 1, gfc_default_character_kind
) == FAILURE
)
4356 gfc_check_isatty (gfc_expr
*unit
)
4361 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4364 if (scalar_check (unit
, 0) == FAILURE
)
4372 gfc_check_isnan (gfc_expr
*x
)
4374 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4382 gfc_check_perror (gfc_expr
*string
)
4384 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
)
4386 if (kind_value_check (string
, 0, gfc_default_character_kind
) == FAILURE
)
4394 gfc_check_umask (gfc_expr
*mask
)
4396 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
4399 if (scalar_check (mask
, 0) == FAILURE
)
4407 gfc_check_umask_sub (gfc_expr
*mask
, gfc_expr
*old
)
4409 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
4412 if (scalar_check (mask
, 0) == FAILURE
)
4418 if (scalar_check (old
, 1) == FAILURE
)
4421 if (type_check (old
, 1, BT_INTEGER
) == FAILURE
)
4429 gfc_check_unlink (gfc_expr
*name
)
4431 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4433 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4441 gfc_check_unlink_sub (gfc_expr
*name
, gfc_expr
*status
)
4443 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4445 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4451 if (scalar_check (status
, 1) == FAILURE
)
4454 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4462 gfc_check_signal (gfc_expr
*number
, gfc_expr
*handler
)
4464 if (scalar_check (number
, 0) == FAILURE
)
4467 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
4470 if (handler
->ts
.type
!= BT_INTEGER
&& handler
->ts
.type
!= BT_PROCEDURE
)
4472 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4473 "or PROCEDURE", gfc_current_intrinsic_arg
[1],
4474 gfc_current_intrinsic
, &handler
->where
);
4478 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4486 gfc_check_signal_sub (gfc_expr
*number
, gfc_expr
*handler
, gfc_expr
*status
)
4488 if (scalar_check (number
, 0) == FAILURE
)
4491 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
4494 if (handler
->ts
.type
!= BT_INTEGER
&& handler
->ts
.type
!= BT_PROCEDURE
)
4496 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4497 "or PROCEDURE", gfc_current_intrinsic_arg
[1],
4498 gfc_current_intrinsic
, &handler
->where
);
4502 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4508 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
4511 if (scalar_check (status
, 2) == FAILURE
)
4519 gfc_check_system_sub (gfc_expr
*cmd
, gfc_expr
*status
)
4521 if (type_check (cmd
, 0, BT_CHARACTER
) == FAILURE
)
4523 if (kind_value_check (cmd
, 0, gfc_default_character_kind
) == FAILURE
)
4526 if (scalar_check (status
, 1) == FAILURE
)
4529 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4532 if (kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
)
4539 /* This is used for the GNU intrinsics AND, OR and XOR. */
4541 gfc_check_and (gfc_expr
*i
, gfc_expr
*j
)
4543 if (i
->ts
.type
!= BT_INTEGER
&& i
->ts
.type
!= BT_LOGICAL
)
4545 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4546 "or LOGICAL", gfc_current_intrinsic_arg
[0],
4547 gfc_current_intrinsic
, &i
->where
);
4551 if (j
->ts
.type
!= BT_INTEGER
&& j
->ts
.type
!= BT_LOGICAL
)
4553 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4554 "or LOGICAL", gfc_current_intrinsic_arg
[1],
4555 gfc_current_intrinsic
, &j
->where
);
4559 if (i
->ts
.type
!= j
->ts
.type
)
4561 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
4562 "have the same type", gfc_current_intrinsic_arg
[0],
4563 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,
4568 if (scalar_check (i
, 0) == FAILURE
)
4571 if (scalar_check (j
, 1) == FAILURE
)
4579 gfc_check_storage_size (gfc_expr
*a ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
4584 if (type_check (kind
, 1, BT_INTEGER
) == FAILURE
)
4587 if (scalar_check (kind
, 1) == FAILURE
)
4590 if (kind
->expr_type
!= EXPR_CONSTANT
)
4592 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
4593 gfc_current_intrinsic_arg
[1], gfc_current_intrinsic
,