2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught & Katherine Holcomb
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* These functions check to see if an argument list is compatible with
24 a particular intrinsic function or subroutine. Presence of
25 required arguments has already been established, the argument list
26 has been sorted into the right order and has NULL arguments in the
27 correct places for missing optional arguments. */
33 #include "intrinsic.h"
34 #include "constructor.h"
37 /* Make sure an expression is a scalar. */
40 scalar_check (gfc_expr
*e
, int n
)
45 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
46 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
53 /* Check the type of an expression. */
56 type_check (gfc_expr
*e
, int n
, bt type
)
58 if (e
->ts
.type
== type
)
61 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
62 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
63 &e
->where
, gfc_basic_typename (type
));
69 /* Check that the expression is a numeric type. */
72 numeric_check (gfc_expr
*e
, int n
)
74 if (gfc_numeric_ts (&e
->ts
))
77 /* If the expression has not got a type, check if its namespace can
78 offer a default type. */
79 if ((e
->expr_type
== EXPR_VARIABLE
|| e
->expr_type
== EXPR_VARIABLE
)
80 && e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
81 && gfc_set_default_type (e
->symtree
->n
.sym
, 0,
82 e
->symtree
->n
.sym
->ns
) == SUCCESS
83 && gfc_numeric_ts (&e
->symtree
->n
.sym
->ts
))
85 e
->ts
= e
->symtree
->n
.sym
->ts
;
89 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
90 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
97 /* Check that an expression is integer or real. */
100 int_or_real_check (gfc_expr
*e
, int n
)
102 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
)
104 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
105 "or REAL", gfc_current_intrinsic_arg
[n
]->name
,
106 gfc_current_intrinsic
, &e
->where
);
114 /* Check that an expression is real or complex. */
117 real_or_complex_check (gfc_expr
*e
, int n
)
119 if (e
->ts
.type
!= BT_REAL
&& e
->ts
.type
!= BT_COMPLEX
)
121 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
122 "or COMPLEX", gfc_current_intrinsic_arg
[n
]->name
,
123 gfc_current_intrinsic
, &e
->where
);
131 /* Check that an expression is INTEGER or PROCEDURE. */
134 int_or_proc_check (gfc_expr
*e
, int n
)
136 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_PROCEDURE
)
138 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
139 "or PROCEDURE", gfc_current_intrinsic_arg
[n
]->name
,
140 gfc_current_intrinsic
, &e
->where
);
148 /* Check that the expression is an optional constant integer
149 and that it specifies a valid kind for that type. */
152 kind_check (gfc_expr
*k
, int n
, bt type
)
159 if (type_check (k
, n
, BT_INTEGER
) == FAILURE
)
162 if (scalar_check (k
, n
) == FAILURE
)
165 if (k
->expr_type
!= EXPR_CONSTANT
)
167 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
168 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
173 if (gfc_extract_int (k
, &kind
) != NULL
174 || gfc_validate_kind (type
, kind
, true) < 0)
176 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type
),
185 /* Make sure the expression is a double precision real. */
188 double_check (gfc_expr
*d
, int n
)
190 if (type_check (d
, n
, BT_REAL
) == FAILURE
)
193 if (d
->ts
.kind
!= gfc_default_double_kind
)
195 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
196 "precision", gfc_current_intrinsic_arg
[n
]->name
,
197 gfc_current_intrinsic
, &d
->where
);
205 /* Check whether an expression is a coarray (without array designator). */
208 is_coarray (gfc_expr
*e
)
210 bool coarray
= false;
213 if (e
->expr_type
!= EXPR_VARIABLE
)
216 coarray
= e
->symtree
->n
.sym
->attr
.codimension
;
218 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
220 if (ref
->type
== REF_COMPONENT
)
221 coarray
= ref
->u
.c
.component
->attr
.codimension
;
222 else if (ref
->type
!= REF_ARRAY
|| ref
->u
.ar
.dimen
!= 0
223 || ref
->u
.ar
.codimen
!= 0)
232 coarray_check (gfc_expr
*e
, int n
)
236 gfc_error ("Expected coarray variable as '%s' argument to the %s "
237 "intrinsic at %L", gfc_current_intrinsic_arg
[n
]->name
,
238 gfc_current_intrinsic
, &e
->where
);
246 /* Make sure the expression is a logical array. */
249 logical_array_check (gfc_expr
*array
, int n
)
251 if (array
->ts
.type
!= BT_LOGICAL
|| array
->rank
== 0)
253 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
254 "array", gfc_current_intrinsic_arg
[n
]->name
,
255 gfc_current_intrinsic
, &array
->where
);
263 /* Make sure an expression is an array. */
266 array_check (gfc_expr
*e
, int n
)
271 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
272 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
279 /* If expr is a constant, then check to ensure that it is greater than
283 nonnegative_check (const char *arg
, gfc_expr
*expr
)
287 if (expr
->expr_type
== EXPR_CONSTANT
)
289 gfc_extract_int (expr
, &i
);
292 gfc_error ("'%s' at %L must be nonnegative", arg
, &expr
->where
);
301 /* If expr2 is constant, then check that the value is less than
302 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
305 less_than_bitsize1 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
306 gfc_expr
*expr2
, bool or_equal
)
310 if (expr2
->expr_type
== EXPR_CONSTANT
)
312 gfc_extract_int (expr2
, &i2
);
313 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
316 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
318 gfc_error ("'%s' at %L must be less than "
319 "or equal to BIT_SIZE('%s')",
320 arg2
, &expr2
->where
, arg1
);
326 if (i2
>= gfc_integer_kinds
[i3
].bit_size
)
328 gfc_error ("'%s' at %L must be less than BIT_SIZE('%s')",
329 arg2
, &expr2
->where
, arg1
);
339 /* If expr is constant, then check that the value is less than or equal
340 to the bit_size of the kind k. */
343 less_than_bitsizekind (const char *arg
, gfc_expr
*expr
, int k
)
347 if (expr
->expr_type
!= EXPR_CONSTANT
)
350 i
= gfc_validate_kind (BT_INTEGER
, k
, false);
351 gfc_extract_int (expr
, &val
);
353 if (val
> gfc_integer_kinds
[i
].bit_size
)
355 gfc_error ("'%s' at %L must be less than or equal to the BIT_SIZE of "
356 "INTEGER(KIND=%d)", arg
, &expr
->where
, k
);
364 /* If expr2 and expr3 are constants, then check that the value is less than
365 or equal to bit_size(expr1). */
368 less_than_bitsize2 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
369 gfc_expr
*expr2
, const char *arg3
, gfc_expr
*expr3
)
373 if (expr2
->expr_type
== EXPR_CONSTANT
&& expr3
->expr_type
== EXPR_CONSTANT
)
375 gfc_extract_int (expr2
, &i2
);
376 gfc_extract_int (expr3
, &i3
);
378 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
379 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
381 gfc_error ("'%s + %s' at %L must be less than or equal "
383 arg2
, arg3
, &expr2
->where
, arg1
);
391 /* Make sure two expressions have the same type. */
394 same_type_check (gfc_expr
*e
, int n
, gfc_expr
*f
, int m
)
396 if (gfc_compare_types (&e
->ts
, &f
->ts
))
399 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
400 "and kind as '%s'", gfc_current_intrinsic_arg
[m
]->name
,
401 gfc_current_intrinsic
, &f
->where
,
402 gfc_current_intrinsic_arg
[n
]->name
);
408 /* Make sure that an expression has a certain (nonzero) rank. */
411 rank_check (gfc_expr
*e
, int n
, int rank
)
416 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
417 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
424 /* Make sure a variable expression is not an optional dummy argument. */
427 nonoptional_check (gfc_expr
*e
, int n
)
429 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.optional
)
431 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
432 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
436 /* TODO: Recursive check on nonoptional variables? */
442 /* Check for ALLOCATABLE attribute. */
445 allocatable_check (gfc_expr
*e
, int n
)
447 symbol_attribute attr
;
449 attr
= gfc_variable_attr (e
, NULL
);
450 if (!attr
.allocatable
)
452 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
453 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
462 /* Check that an expression has a particular kind. */
465 kind_value_check (gfc_expr
*e
, int n
, int k
)
470 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
471 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
478 /* Make sure an expression is a variable. */
481 variable_check (gfc_expr
*e
, int n
)
483 if (e
->expr_type
== EXPR_VARIABLE
484 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
485 && (gfc_current_intrinsic_arg
[n
]->intent
== INTENT_OUT
486 || gfc_current_intrinsic_arg
[n
]->intent
== INTENT_INOUT
))
488 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be INTENT(IN)",
489 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
494 if ((e
->expr_type
== EXPR_VARIABLE
495 && e
->symtree
->n
.sym
->attr
.flavor
!= FL_PARAMETER
)
496 || (e
->expr_type
== EXPR_FUNCTION
497 && e
->symtree
->n
.sym
->result
== e
->symtree
->n
.sym
))
500 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
501 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
, &e
->where
);
507 /* Check the common DIM parameter for correctness. */
510 dim_check (gfc_expr
*dim
, int n
, bool optional
)
515 if (type_check (dim
, n
, BT_INTEGER
) == FAILURE
)
518 if (scalar_check (dim
, n
) == FAILURE
)
521 if (!optional
&& nonoptional_check (dim
, n
) == FAILURE
)
528 /* If a coarray DIM parameter is a constant, make sure that it is greater than
529 zero and less than or equal to the corank of the given array. */
532 dim_corank_check (gfc_expr
*dim
, gfc_expr
*array
)
537 gcc_assert (array
->expr_type
== EXPR_VARIABLE
);
539 if (dim
->expr_type
!= EXPR_CONSTANT
)
542 ar
= gfc_find_array_ref (array
);
543 corank
= ar
->as
->corank
;
545 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
546 || mpz_cmp_ui (dim
->value
.integer
, corank
) > 0)
548 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
549 "codimension index", gfc_current_intrinsic
, &dim
->where
);
558 /* If a DIM parameter is a constant, make sure that it is greater than
559 zero and less than or equal to the rank of the given array. If
560 allow_assumed is zero then dim must be less than the rank of the array
561 for assumed size arrays. */
564 dim_rank_check (gfc_expr
*dim
, gfc_expr
*array
, int allow_assumed
)
572 if (dim
->expr_type
!= EXPR_CONSTANT
)
575 if (array
->expr_type
== EXPR_FUNCTION
&& array
->value
.function
.isym
576 && array
->value
.function
.isym
->id
== GFC_ISYM_SPREAD
)
577 rank
= array
->rank
+ 1;
581 if (array
->expr_type
== EXPR_VARIABLE
)
583 ar
= gfc_find_array_ref (array
);
584 if (ar
->as
->type
== AS_ASSUMED_SIZE
586 && ar
->type
!= AR_ELEMENT
587 && ar
->type
!= AR_SECTION
)
591 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
592 || mpz_cmp_ui (dim
->value
.integer
, rank
) > 0)
594 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
595 "dimension index", gfc_current_intrinsic
, &dim
->where
);
604 /* Compare the size of a along dimension ai with the size of b along
605 dimension bi, returning 0 if they are known not to be identical,
606 and 1 if they are identical, or if this cannot be determined. */
609 identical_dimen_shape (gfc_expr
*a
, int ai
, gfc_expr
*b
, int bi
)
611 mpz_t a_size
, b_size
;
614 gcc_assert (a
->rank
> ai
);
615 gcc_assert (b
->rank
> bi
);
619 if (gfc_array_dimen_size (a
, ai
, &a_size
) == SUCCESS
)
621 if (gfc_array_dimen_size (b
, bi
, &b_size
) == SUCCESS
)
623 if (mpz_cmp (a_size
, b_size
) != 0)
634 /* Check whether two character expressions have the same length;
635 returns SUCCESS if they have or if the length cannot be determined. */
638 gfc_check_same_strlen (const gfc_expr
*a
, const gfc_expr
*b
, const char *name
)
643 if (a
->ts
.u
.cl
&& a
->ts
.u
.cl
->length
644 && a
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
645 len_a
= mpz_get_si (a
->ts
.u
.cl
->length
->value
.integer
);
646 else if (a
->expr_type
== EXPR_CONSTANT
647 && (a
->ts
.u
.cl
== NULL
|| a
->ts
.u
.cl
->length
== NULL
))
648 len_a
= a
->value
.character
.length
;
652 if (b
->ts
.u
.cl
&& b
->ts
.u
.cl
->length
653 && b
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
654 len_b
= mpz_get_si (b
->ts
.u
.cl
->length
->value
.integer
);
655 else if (b
->expr_type
== EXPR_CONSTANT
656 && (b
->ts
.u
.cl
== NULL
|| b
->ts
.u
.cl
->length
== NULL
))
657 len_b
= b
->value
.character
.length
;
664 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
665 len_a
, len_b
, name
, &a
->where
);
670 /***** Check functions *****/
672 /* Check subroutine suitable for intrinsics taking a real argument and
673 a kind argument for the result. */
676 check_a_kind (gfc_expr
*a
, gfc_expr
*kind
, bt type
)
678 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
680 if (kind_check (kind
, 1, type
) == FAILURE
)
687 /* Check subroutine suitable for ceiling, floor and nint. */
690 gfc_check_a_ikind (gfc_expr
*a
, gfc_expr
*kind
)
692 return check_a_kind (a
, kind
, BT_INTEGER
);
696 /* Check subroutine suitable for aint, anint. */
699 gfc_check_a_xkind (gfc_expr
*a
, gfc_expr
*kind
)
701 return check_a_kind (a
, kind
, BT_REAL
);
706 gfc_check_abs (gfc_expr
*a
)
708 if (numeric_check (a
, 0) == FAILURE
)
716 gfc_check_achar (gfc_expr
*a
, gfc_expr
*kind
)
718 if (type_check (a
, 0, BT_INTEGER
) == FAILURE
)
720 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
728 gfc_check_access_func (gfc_expr
*name
, gfc_expr
*mode
)
730 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
731 || scalar_check (name
, 0) == FAILURE
)
733 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
736 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
737 || scalar_check (mode
, 1) == FAILURE
)
739 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
747 gfc_check_all_any (gfc_expr
*mask
, gfc_expr
*dim
)
749 if (logical_array_check (mask
, 0) == FAILURE
)
752 if (dim_check (dim
, 1, false) == FAILURE
)
755 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
763 gfc_check_allocated (gfc_expr
*array
)
765 if (variable_check (array
, 0) == FAILURE
)
767 if (allocatable_check (array
, 0) == FAILURE
)
774 /* Common check function where the first argument must be real or
775 integer and the second argument must be the same as the first. */
778 gfc_check_a_p (gfc_expr
*a
, gfc_expr
*p
)
780 if (int_or_real_check (a
, 0) == FAILURE
)
783 if (a
->ts
.type
!= p
->ts
.type
)
785 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
786 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
787 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
792 if (a
->ts
.kind
!= p
->ts
.kind
)
794 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
795 &p
->where
) == FAILURE
)
804 gfc_check_x_yd (gfc_expr
*x
, gfc_expr
*y
)
806 if (double_check (x
, 0) == FAILURE
|| double_check (y
, 1) == FAILURE
)
814 gfc_check_associated (gfc_expr
*pointer
, gfc_expr
*target
)
816 symbol_attribute attr1
, attr2
;
821 where
= &pointer
->where
;
823 if (pointer
->expr_type
== EXPR_VARIABLE
|| pointer
->expr_type
== EXPR_FUNCTION
)
824 attr1
= gfc_expr_attr (pointer
);
825 else if (pointer
->expr_type
== EXPR_NULL
)
828 gcc_assert (0); /* Pointer must be a variable or a function. */
830 if (!attr1
.pointer
&& !attr1
.proc_pointer
)
832 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
833 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
838 /* Target argument is optional. */
842 where
= &target
->where
;
843 if (target
->expr_type
== EXPR_NULL
)
846 if (target
->expr_type
== EXPR_VARIABLE
|| target
->expr_type
== EXPR_FUNCTION
)
847 attr2
= gfc_expr_attr (target
);
850 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
851 "or target VARIABLE or FUNCTION",
852 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
857 if (attr1
.pointer
&& !attr2
.pointer
&& !attr2
.target
)
859 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
860 "or a TARGET", gfc_current_intrinsic_arg
[1]->name
,
861 gfc_current_intrinsic
, &target
->where
);
866 if (same_type_check (pointer
, 0, target
, 1) == FAILURE
)
868 if (rank_check (target
, 0, pointer
->rank
) == FAILURE
)
870 if (target
->rank
> 0)
872 for (i
= 0; i
< target
->rank
; i
++)
873 if (target
->ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
875 gfc_error ("Array section with a vector subscript at %L shall not "
876 "be the target of a pointer",
886 gfc_error ("NULL pointer at %L is not permitted as actual argument "
887 "of '%s' intrinsic function", where
, gfc_current_intrinsic
);
894 gfc_check_atan_2 (gfc_expr
*y
, gfc_expr
*x
)
896 /* gfc_notify_std would be a wast of time as the return value
897 is seemingly used only for the generic resolution. The error
898 will be: Too many arguments. */
899 if ((gfc_option
.allow_std
& GFC_STD_F2008
) == 0)
902 return gfc_check_atan2 (y
, x
);
907 gfc_check_atan2 (gfc_expr
*y
, gfc_expr
*x
)
909 if (type_check (y
, 0, BT_REAL
) == FAILURE
)
911 if (same_type_check (y
, 0, x
, 1) == FAILURE
)
918 /* BESJN and BESYN functions. */
921 gfc_check_besn (gfc_expr
*n
, gfc_expr
*x
)
923 if (type_check (n
, 0, BT_INTEGER
) == FAILURE
)
925 if (n
->expr_type
== EXPR_CONSTANT
)
928 gfc_extract_int (n
, &i
);
929 if (i
< 0 && gfc_notify_std (GFC_STD_GNU
, "Extension: Negative argument "
930 "N at %L", &n
->where
) == FAILURE
)
934 if (type_check (x
, 1, BT_REAL
) == FAILURE
)
941 /* Transformational version of the Bessel JN and YN functions. */
944 gfc_check_bessel_n2 (gfc_expr
*n1
, gfc_expr
*n2
, gfc_expr
*x
)
946 if (type_check (n1
, 0, BT_INTEGER
) == FAILURE
)
948 if (scalar_check (n1
, 0) == FAILURE
)
950 if (nonnegative_check("N1", n1
) == FAILURE
)
953 if (type_check (n2
, 1, BT_INTEGER
) == FAILURE
)
955 if (scalar_check (n2
, 1) == FAILURE
)
957 if (nonnegative_check("N2", n2
) == FAILURE
)
960 if (type_check (x
, 2, BT_REAL
) == FAILURE
)
962 if (scalar_check (x
, 2) == FAILURE
)
970 gfc_check_bge_bgt_ble_blt (gfc_expr
*i
, gfc_expr
*j
)
972 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
975 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
983 gfc_check_bitfcn (gfc_expr
*i
, gfc_expr
*pos
)
985 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
988 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
991 if (nonnegative_check ("pos", pos
) == FAILURE
)
994 if (less_than_bitsize1 ("i", i
, "pos", pos
, false) == FAILURE
)
1002 gfc_check_char (gfc_expr
*i
, gfc_expr
*kind
)
1004 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1006 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
1014 gfc_check_chdir (gfc_expr
*dir
)
1016 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
1018 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
1026 gfc_check_chdir_sub (gfc_expr
*dir
, gfc_expr
*status
)
1028 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
1030 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
1036 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
1038 if (scalar_check (status
, 1) == FAILURE
)
1046 gfc_check_chmod (gfc_expr
*name
, gfc_expr
*mode
)
1048 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
1050 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
1053 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
1055 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
1063 gfc_check_chmod_sub (gfc_expr
*name
, gfc_expr
*mode
, gfc_expr
*status
)
1065 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
1067 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
1070 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
1072 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
1078 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1081 if (scalar_check (status
, 2) == FAILURE
)
1089 gfc_check_cmplx (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
1091 if (numeric_check (x
, 0) == FAILURE
)
1096 if (numeric_check (y
, 1) == FAILURE
)
1099 if (x
->ts
.type
== BT_COMPLEX
)
1101 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1102 "present if 'x' is COMPLEX",
1103 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1108 if (y
->ts
.type
== BT_COMPLEX
)
1110 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1111 "of either REAL or INTEGER",
1112 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1119 if (kind_check (kind
, 2, BT_COMPLEX
) == FAILURE
)
1127 gfc_check_complex (gfc_expr
*x
, gfc_expr
*y
)
1129 if (int_or_real_check (x
, 0) == FAILURE
)
1131 if (scalar_check (x
, 0) == FAILURE
)
1134 if (int_or_real_check (y
, 1) == FAILURE
)
1136 if (scalar_check (y
, 1) == FAILURE
)
1144 gfc_check_count (gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
1146 if (logical_array_check (mask
, 0) == FAILURE
)
1148 if (dim_check (dim
, 1, false) == FAILURE
)
1150 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
1152 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1154 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1155 "with KIND argument at %L",
1156 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1164 gfc_check_cshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*dim
)
1166 if (array_check (array
, 0) == FAILURE
)
1169 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1172 if (dim_check (dim
, 2, true) == FAILURE
)
1175 if (dim_rank_check (dim
, array
, false) == FAILURE
)
1178 if (array
->rank
== 1 || shift
->rank
== 0)
1180 if (scalar_check (shift
, 1) == FAILURE
)
1183 else if (shift
->rank
== array
->rank
- 1)
1188 else if (dim
->expr_type
== EXPR_CONSTANT
)
1189 gfc_extract_int (dim
, &d
);
1196 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1199 if (!identical_dimen_shape (array
, i
, shift
, j
))
1201 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1202 "invalid shape in dimension %d (%ld/%ld)",
1203 gfc_current_intrinsic_arg
[1]->name
,
1204 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1205 mpz_get_si (array
->shape
[i
]),
1206 mpz_get_si (shift
->shape
[j
]));
1216 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1217 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
1218 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1227 gfc_check_ctime (gfc_expr
*time
)
1229 if (scalar_check (time
, 0) == FAILURE
)
1232 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
1239 gfc_try
gfc_check_datan2 (gfc_expr
*y
, gfc_expr
*x
)
1241 if (double_check (y
, 0) == FAILURE
|| double_check (x
, 1) == FAILURE
)
1248 gfc_check_dcmplx (gfc_expr
*x
, gfc_expr
*y
)
1250 if (numeric_check (x
, 0) == FAILURE
)
1255 if (numeric_check (y
, 1) == FAILURE
)
1258 if (x
->ts
.type
== BT_COMPLEX
)
1260 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1261 "present if 'x' is COMPLEX",
1262 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1267 if (y
->ts
.type
== BT_COMPLEX
)
1269 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1270 "of either REAL or INTEGER",
1271 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1282 gfc_check_dble (gfc_expr
*x
)
1284 if (numeric_check (x
, 0) == FAILURE
)
1292 gfc_check_digits (gfc_expr
*x
)
1294 if (int_or_real_check (x
, 0) == FAILURE
)
1302 gfc_check_dot_product (gfc_expr
*vector_a
, gfc_expr
*vector_b
)
1304 switch (vector_a
->ts
.type
)
1307 if (type_check (vector_b
, 1, BT_LOGICAL
) == FAILURE
)
1314 if (numeric_check (vector_b
, 1) == FAILURE
)
1319 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1320 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
1321 gfc_current_intrinsic
, &vector_a
->where
);
1325 if (rank_check (vector_a
, 0, 1) == FAILURE
)
1328 if (rank_check (vector_b
, 1, 1) == FAILURE
)
1331 if (! identical_dimen_shape (vector_a
, 0, vector_b
, 0))
1333 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1334 "intrinsic 'dot_product'", gfc_current_intrinsic_arg
[0]->name
,
1335 gfc_current_intrinsic_arg
[1]->name
, &vector_a
->where
);
1344 gfc_check_dprod (gfc_expr
*x
, gfc_expr
*y
)
1346 if (type_check (x
, 0, BT_REAL
) == FAILURE
1347 || type_check (y
, 1, BT_REAL
) == FAILURE
)
1350 if (x
->ts
.kind
!= gfc_default_real_kind
)
1352 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1353 "real", gfc_current_intrinsic_arg
[0]->name
,
1354 gfc_current_intrinsic
, &x
->where
);
1358 if (y
->ts
.kind
!= gfc_default_real_kind
)
1360 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1361 "real", gfc_current_intrinsic_arg
[1]->name
,
1362 gfc_current_intrinsic
, &y
->where
);
1371 gfc_check_dshift (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*shift
)
1373 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1376 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1379 if (same_type_check (i
, 0, j
, 1) == FAILURE
)
1382 if (type_check (shift
, 2, BT_INTEGER
) == FAILURE
)
1385 if (nonnegative_check ("SHIFT", shift
) == FAILURE
)
1388 if (less_than_bitsize1 ("I", i
, "SHIFT", shift
, true) == FAILURE
)
1396 gfc_check_eoshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*boundary
,
1399 if (array_check (array
, 0) == FAILURE
)
1402 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1405 if (dim_check (dim
, 3, true) == FAILURE
)
1408 if (dim_rank_check (dim
, array
, false) == FAILURE
)
1411 if (array
->rank
== 1 || shift
->rank
== 0)
1413 if (scalar_check (shift
, 1) == FAILURE
)
1416 else if (shift
->rank
== array
->rank
- 1)
1421 else if (dim
->expr_type
== EXPR_CONSTANT
)
1422 gfc_extract_int (dim
, &d
);
1429 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1432 if (!identical_dimen_shape (array
, i
, shift
, j
))
1434 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1435 "invalid shape in dimension %d (%ld/%ld)",
1436 gfc_current_intrinsic_arg
[1]->name
,
1437 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1438 mpz_get_si (array
->shape
[i
]),
1439 mpz_get_si (shift
->shape
[j
]));
1449 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1450 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
1451 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1455 if (boundary
!= NULL
)
1457 if (same_type_check (array
, 0, boundary
, 2) == FAILURE
)
1460 if (array
->rank
== 1 || boundary
->rank
== 0)
1462 if (scalar_check (boundary
, 2) == FAILURE
)
1465 else if (boundary
->rank
== array
->rank
- 1)
1467 if (gfc_check_conformance (shift
, boundary
,
1468 "arguments '%s' and '%s' for "
1470 gfc_current_intrinsic_arg
[1]->name
,
1471 gfc_current_intrinsic_arg
[2]->name
,
1472 gfc_current_intrinsic
) == FAILURE
)
1477 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1478 "rank %d or be a scalar",
1479 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1480 &shift
->where
, array
->rank
- 1);
1489 gfc_check_float (gfc_expr
*a
)
1491 if (type_check (a
, 0, BT_INTEGER
) == FAILURE
)
1494 if ((a
->ts
.kind
!= gfc_default_integer_kind
)
1495 && gfc_notify_std (GFC_STD_GNU
, "GNU extension: non-default INTEGER"
1496 "kind argument to %s intrinsic at %L",
1497 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
1503 /* A single complex argument. */
1506 gfc_check_fn_c (gfc_expr
*a
)
1508 if (type_check (a
, 0, BT_COMPLEX
) == FAILURE
)
1514 /* A single real argument. */
1517 gfc_check_fn_r (gfc_expr
*a
)
1519 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
1525 /* A single double argument. */
1528 gfc_check_fn_d (gfc_expr
*a
)
1530 if (double_check (a
, 0) == FAILURE
)
1536 /* A single real or complex argument. */
1539 gfc_check_fn_rc (gfc_expr
*a
)
1541 if (real_or_complex_check (a
, 0) == FAILURE
)
1549 gfc_check_fn_rc2008 (gfc_expr
*a
)
1551 if (real_or_complex_check (a
, 0) == FAILURE
)
1554 if (a
->ts
.type
== BT_COMPLEX
1555 && gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: COMPLEX argument '%s' "
1556 "argument of '%s' intrinsic at %L",
1557 gfc_current_intrinsic_arg
[0]->name
,
1558 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
1566 gfc_check_fnum (gfc_expr
*unit
)
1568 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
1571 if (scalar_check (unit
, 0) == FAILURE
)
1579 gfc_check_huge (gfc_expr
*x
)
1581 if (int_or_real_check (x
, 0) == FAILURE
)
1589 gfc_check_hypot (gfc_expr
*x
, gfc_expr
*y
)
1591 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
1593 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
1600 /* Check that the single argument is an integer. */
1603 gfc_check_i (gfc_expr
*i
)
1605 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1613 gfc_check_iand (gfc_expr
*i
, gfc_expr
*j
)
1615 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1618 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1621 if (i
->ts
.kind
!= j
->ts
.kind
)
1623 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1624 &i
->where
) == FAILURE
)
1633 gfc_check_ibits (gfc_expr
*i
, gfc_expr
*pos
, gfc_expr
*len
)
1635 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1638 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
1641 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
1644 if (nonnegative_check ("pos", pos
) == FAILURE
)
1647 if (nonnegative_check ("len", len
) == FAILURE
)
1650 if (less_than_bitsize2 ("i", i
, "pos", pos
, "len", len
) == FAILURE
)
1658 gfc_check_ichar_iachar (gfc_expr
*c
, gfc_expr
*kind
)
1662 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
1665 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1668 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1669 "with KIND argument at %L",
1670 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1673 if (c
->expr_type
== EXPR_VARIABLE
|| c
->expr_type
== EXPR_SUBSTRING
)
1679 /* Substring references don't have the charlength set. */
1681 while (ref
&& ref
->type
!= REF_SUBSTRING
)
1684 gcc_assert (ref
== NULL
|| ref
->type
== REF_SUBSTRING
);
1688 /* Check that the argument is length one. Non-constant lengths
1689 can't be checked here, so assume they are ok. */
1690 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
)
1692 /* If we already have a length for this expression then use it. */
1693 if (c
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
1695 i
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
1702 start
= ref
->u
.ss
.start
;
1703 end
= ref
->u
.ss
.end
;
1706 if (end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
1707 || start
->expr_type
!= EXPR_CONSTANT
)
1710 i
= mpz_get_si (end
->value
.integer
) + 1
1711 - mpz_get_si (start
->value
.integer
);
1719 gfc_error ("Argument of %s at %L must be of length one",
1720 gfc_current_intrinsic
, &c
->where
);
1729 gfc_check_idnint (gfc_expr
*a
)
1731 if (double_check (a
, 0) == FAILURE
)
1739 gfc_check_ieor (gfc_expr
*i
, gfc_expr
*j
)
1741 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1744 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1747 if (i
->ts
.kind
!= j
->ts
.kind
)
1749 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1750 &i
->where
) == FAILURE
)
1759 gfc_check_index (gfc_expr
*string
, gfc_expr
*substring
, gfc_expr
*back
,
1762 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
1763 || type_check (substring
, 1, BT_CHARACTER
) == FAILURE
)
1766 if (back
!= NULL
&& type_check (back
, 2, BT_LOGICAL
) == FAILURE
)
1769 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
1771 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1772 "with KIND argument at %L",
1773 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1776 if (string
->ts
.kind
!= substring
->ts
.kind
)
1778 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1779 "kind as '%s'", gfc_current_intrinsic_arg
[1]->name
,
1780 gfc_current_intrinsic
, &substring
->where
,
1781 gfc_current_intrinsic_arg
[0]->name
);
1790 gfc_check_int (gfc_expr
*x
, gfc_expr
*kind
)
1792 if (numeric_check (x
, 0) == FAILURE
)
1795 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1803 gfc_check_intconv (gfc_expr
*x
)
1805 if (numeric_check (x
, 0) == FAILURE
)
1813 gfc_check_ior (gfc_expr
*i
, gfc_expr
*j
)
1815 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1818 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1821 if (i
->ts
.kind
!= j
->ts
.kind
)
1823 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1824 &i
->where
) == FAILURE
)
1833 gfc_check_ishft (gfc_expr
*i
, gfc_expr
*shift
)
1835 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
1836 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1844 gfc_check_ishftc (gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
1846 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
1847 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1850 if (size
!= NULL
&& type_check (size
, 2, BT_INTEGER
) == FAILURE
)
1858 gfc_check_kill (gfc_expr
*pid
, gfc_expr
*sig
)
1860 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
1863 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
1871 gfc_check_kill_sub (gfc_expr
*pid
, gfc_expr
*sig
, gfc_expr
*status
)
1873 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
1876 if (scalar_check (pid
, 0) == FAILURE
)
1879 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
1882 if (scalar_check (sig
, 1) == FAILURE
)
1888 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1891 if (scalar_check (status
, 2) == FAILURE
)
1899 gfc_check_kind (gfc_expr
*x
)
1901 if (x
->ts
.type
== BT_DERIVED
)
1903 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1904 "non-derived type", gfc_current_intrinsic_arg
[0]->name
,
1905 gfc_current_intrinsic
, &x
->where
);
1914 gfc_check_lbound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
1916 if (array_check (array
, 0) == FAILURE
)
1919 if (dim_check (dim
, 1, false) == FAILURE
)
1922 if (dim_rank_check (dim
, array
, 1) == FAILURE
)
1925 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1927 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1928 "with KIND argument at %L",
1929 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1937 gfc_check_lcobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
1939 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
1941 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
1945 if (coarray_check (coarray
, 0) == FAILURE
)
1950 if (dim_check (dim
, 1, false) == FAILURE
)
1953 if (dim_corank_check (dim
, coarray
) == FAILURE
)
1957 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1965 gfc_check_len_lentrim (gfc_expr
*s
, gfc_expr
*kind
)
1967 if (type_check (s
, 0, BT_CHARACTER
) == FAILURE
)
1970 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1972 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1973 "with KIND argument at %L",
1974 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1982 gfc_check_lge_lgt_lle_llt (gfc_expr
*a
, gfc_expr
*b
)
1984 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
1986 if (kind_value_check (a
, 0, gfc_default_character_kind
) == FAILURE
)
1989 if (type_check (b
, 1, BT_CHARACTER
) == FAILURE
)
1991 if (kind_value_check (b
, 1, gfc_default_character_kind
) == FAILURE
)
1999 gfc_check_link (gfc_expr
*path1
, gfc_expr
*path2
)
2001 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2003 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2006 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2008 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2016 gfc_check_link_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2018 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2020 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2023 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2025 if (kind_value_check (path2
, 0, gfc_default_character_kind
) == FAILURE
)
2031 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2034 if (scalar_check (status
, 2) == FAILURE
)
2042 gfc_check_loc (gfc_expr
*expr
)
2044 return variable_check (expr
, 0);
2049 gfc_check_symlnk (gfc_expr
*path1
, gfc_expr
*path2
)
2051 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2053 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2056 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2058 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2066 gfc_check_symlnk_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2068 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2070 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2073 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2075 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2081 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2084 if (scalar_check (status
, 2) == FAILURE
)
2092 gfc_check_logical (gfc_expr
*a
, gfc_expr
*kind
)
2094 if (type_check (a
, 0, BT_LOGICAL
) == FAILURE
)
2096 if (kind_check (kind
, 1, BT_LOGICAL
) == FAILURE
)
2103 /* Min/max family. */
2106 min_max_args (gfc_actual_arglist
*arg
)
2108 if (arg
== NULL
|| arg
->next
== NULL
)
2110 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
2111 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
2120 check_rest (bt type
, int kind
, gfc_actual_arglist
*arglist
)
2122 gfc_actual_arglist
*arg
, *tmp
;
2127 if (min_max_args (arglist
) == FAILURE
)
2130 for (arg
= arglist
, n
=1; arg
; arg
= arg
->next
, n
++)
2133 if (x
->ts
.type
!= type
|| x
->ts
.kind
!= kind
)
2135 if (x
->ts
.type
== type
)
2137 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type "
2138 "kinds at %L", &x
->where
) == FAILURE
)
2143 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
2144 "%s(%d)", n
, gfc_current_intrinsic
, &x
->where
,
2145 gfc_basic_typename (type
), kind
);
2150 for (tmp
= arglist
, m
=1; tmp
!= arg
; tmp
= tmp
->next
, m
++)
2151 if (gfc_check_conformance (tmp
->expr
, x
,
2152 "arguments 'a%d' and 'a%d' for "
2153 "intrinsic '%s'", m
, n
,
2154 gfc_current_intrinsic
) == FAILURE
)
2163 gfc_check_min_max (gfc_actual_arglist
*arg
)
2167 if (min_max_args (arg
) == FAILURE
)
2172 if (x
->ts
.type
== BT_CHARACTER
)
2174 if (gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
2175 "with CHARACTER argument at %L",
2176 gfc_current_intrinsic
, &x
->where
) == FAILURE
)
2179 else if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
2181 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
2182 "REAL or CHARACTER", gfc_current_intrinsic
, &x
->where
);
2186 return check_rest (x
->ts
.type
, x
->ts
.kind
, arg
);
2191 gfc_check_min_max_integer (gfc_actual_arglist
*arg
)
2193 return check_rest (BT_INTEGER
, gfc_default_integer_kind
, arg
);
2198 gfc_check_min_max_real (gfc_actual_arglist
*arg
)
2200 return check_rest (BT_REAL
, gfc_default_real_kind
, arg
);
2205 gfc_check_min_max_double (gfc_actual_arglist
*arg
)
2207 return check_rest (BT_REAL
, gfc_default_double_kind
, arg
);
2211 /* End of min/max family. */
2214 gfc_check_malloc (gfc_expr
*size
)
2216 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
2219 if (scalar_check (size
, 0) == FAILURE
)
2227 gfc_check_matmul (gfc_expr
*matrix_a
, gfc_expr
*matrix_b
)
2229 if ((matrix_a
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_a
->ts
))
2231 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2232 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
2233 gfc_current_intrinsic
, &matrix_a
->where
);
2237 if ((matrix_b
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_b
->ts
))
2239 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2240 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
2241 gfc_current_intrinsic
, &matrix_b
->where
);
2245 if ((matrix_a
->ts
.type
== BT_LOGICAL
&& gfc_numeric_ts (&matrix_b
->ts
))
2246 || (gfc_numeric_ts (&matrix_a
->ts
) && matrix_b
->ts
.type
== BT_LOGICAL
))
2248 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2249 gfc_current_intrinsic
, &matrix_a
->where
,
2250 gfc_typename(&matrix_a
->ts
), gfc_typename(&matrix_b
->ts
));
2254 switch (matrix_a
->rank
)
2257 if (rank_check (matrix_b
, 1, 2) == FAILURE
)
2259 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2260 if (!identical_dimen_shape (matrix_a
, 0, matrix_b
, 0))
2262 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2263 "and '%s' at %L for intrinsic matmul",
2264 gfc_current_intrinsic_arg
[0]->name
,
2265 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
2271 if (matrix_b
->rank
!= 2)
2273 if (rank_check (matrix_b
, 1, 1) == FAILURE
)
2276 /* matrix_b has rank 1 or 2 here. Common check for the cases
2277 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2278 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2279 if (!identical_dimen_shape (matrix_a
, 1, matrix_b
, 0))
2281 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2282 "dimension 1 for argument '%s' at %L for intrinsic "
2283 "matmul", gfc_current_intrinsic_arg
[0]->name
,
2284 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
2290 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2291 "1 or 2", gfc_current_intrinsic_arg
[0]->name
,
2292 gfc_current_intrinsic
, &matrix_a
->where
);
2300 /* Whoever came up with this interface was probably on something.
2301 The possibilities for the occupation of the second and third
2308 NULL MASK minloc(array, mask=m)
2311 I.e. in the case of minloc(array,mask), mask will be in the second
2312 position of the argument list and we'll have to fix that up. */
2315 gfc_check_minloc_maxloc (gfc_actual_arglist
*ap
)
2317 gfc_expr
*a
, *m
, *d
;
2320 if (int_or_real_check (a
, 0) == FAILURE
|| array_check (a
, 0) == FAILURE
)
2324 m
= ap
->next
->next
->expr
;
2326 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2327 && ap
->next
->name
== NULL
)
2331 ap
->next
->expr
= NULL
;
2332 ap
->next
->next
->expr
= m
;
2335 if (dim_check (d
, 1, false) == FAILURE
)
2338 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2341 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2345 && gfc_check_conformance (a
, m
,
2346 "arguments '%s' and '%s' for intrinsic %s",
2347 gfc_current_intrinsic_arg
[0]->name
,
2348 gfc_current_intrinsic_arg
[2]->name
,
2349 gfc_current_intrinsic
) == FAILURE
)
2356 /* Similar to minloc/maxloc, the argument list might need to be
2357 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2358 difference is that MINLOC/MAXLOC take an additional KIND argument.
2359 The possibilities are:
2365 NULL MASK minval(array, mask=m)
2368 I.e. in the case of minval(array,mask), mask will be in the second
2369 position of the argument list and we'll have to fix that up. */
2372 check_reduction (gfc_actual_arglist
*ap
)
2374 gfc_expr
*a
, *m
, *d
;
2378 m
= ap
->next
->next
->expr
;
2380 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2381 && ap
->next
->name
== NULL
)
2385 ap
->next
->expr
= NULL
;
2386 ap
->next
->next
->expr
= m
;
2389 if (dim_check (d
, 1, false) == FAILURE
)
2392 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2395 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2399 && gfc_check_conformance (a
, m
,
2400 "arguments '%s' and '%s' for intrinsic %s",
2401 gfc_current_intrinsic_arg
[0]->name
,
2402 gfc_current_intrinsic_arg
[2]->name
,
2403 gfc_current_intrinsic
) == FAILURE
)
2411 gfc_check_minval_maxval (gfc_actual_arglist
*ap
)
2413 if (int_or_real_check (ap
->expr
, 0) == FAILURE
2414 || array_check (ap
->expr
, 0) == FAILURE
)
2417 return check_reduction (ap
);
2422 gfc_check_product_sum (gfc_actual_arglist
*ap
)
2424 if (numeric_check (ap
->expr
, 0) == FAILURE
2425 || array_check (ap
->expr
, 0) == FAILURE
)
2428 return check_reduction (ap
);
2432 /* For IANY, IALL and IPARITY. */
2435 gfc_check_mask (gfc_expr
*i
, gfc_expr
*kind
)
2439 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
2442 if (nonnegative_check ("I", i
) == FAILURE
)
2445 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
2449 gfc_extract_int (kind
, &k
);
2451 k
= gfc_default_integer_kind
;
2453 if (less_than_bitsizekind ("I", i
, k
) == FAILURE
)
2461 gfc_check_transf_bit_intrins (gfc_actual_arglist
*ap
)
2463 if (ap
->expr
->ts
.type
!= BT_INTEGER
)
2465 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER",
2466 gfc_current_intrinsic_arg
[0]->name
,
2467 gfc_current_intrinsic
, &ap
->expr
->where
);
2471 if (array_check (ap
->expr
, 0) == FAILURE
)
2474 return check_reduction (ap
);
2479 gfc_check_merge (gfc_expr
*tsource
, gfc_expr
*fsource
, gfc_expr
*mask
)
2481 if (same_type_check (tsource
, 0, fsource
, 1) == FAILURE
)
2484 if (type_check (mask
, 2, BT_LOGICAL
) == FAILURE
)
2487 if (tsource
->ts
.type
== BT_CHARACTER
)
2488 return gfc_check_same_strlen (tsource
, fsource
, "MERGE intrinsic");
2495 gfc_check_merge_bits (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*mask
)
2497 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
2500 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
2503 if (type_check (mask
, 2, BT_INTEGER
) == FAILURE
)
2506 if (same_type_check (i
, 0, j
, 1) == FAILURE
)
2509 if (same_type_check (i
, 0, mask
, 2) == FAILURE
)
2517 gfc_check_move_alloc (gfc_expr
*from
, gfc_expr
*to
)
2519 if (variable_check (from
, 0) == FAILURE
)
2521 if (allocatable_check (from
, 0) == FAILURE
)
2524 if (variable_check (to
, 1) == FAILURE
)
2526 if (allocatable_check (to
, 1) == FAILURE
)
2529 if (same_type_check (to
, 1, from
, 0) == FAILURE
)
2532 if (to
->rank
!= from
->rank
)
2534 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2535 "have the same rank %d/%d", gfc_current_intrinsic_arg
[0]->name
,
2536 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2537 &to
->where
, from
->rank
, to
->rank
);
2541 if (to
->ts
.kind
!= from
->ts
.kind
)
2543 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2544 "be of the same kind %d/%d",
2545 gfc_current_intrinsic_arg
[0]->name
,
2546 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2547 &to
->where
, from
->ts
.kind
, to
->ts
.kind
);
2556 gfc_check_nearest (gfc_expr
*x
, gfc_expr
*s
)
2558 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
2561 if (type_check (s
, 1, BT_REAL
) == FAILURE
)
2569 gfc_check_new_line (gfc_expr
*a
)
2571 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
2579 gfc_check_norm2 (gfc_expr
*array
, gfc_expr
*dim
)
2581 if (type_check (array
, 0, BT_REAL
) == FAILURE
)
2584 if (array_check (array
, 0) == FAILURE
)
2587 if (dim_rank_check (dim
, array
, false) == FAILURE
)
2594 gfc_check_null (gfc_expr
*mold
)
2596 symbol_attribute attr
;
2601 if (variable_check (mold
, 0) == FAILURE
)
2604 attr
= gfc_variable_attr (mold
, NULL
);
2606 if (!attr
.pointer
&& !attr
.proc_pointer
)
2608 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
2609 gfc_current_intrinsic_arg
[0]->name
,
2610 gfc_current_intrinsic
, &mold
->where
);
2619 gfc_check_pack (gfc_expr
*array
, gfc_expr
*mask
, gfc_expr
*vector
)
2621 if (array_check (array
, 0) == FAILURE
)
2624 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
2627 if (gfc_check_conformance (array
, mask
,
2628 "arguments '%s' and '%s' for intrinsic '%s'",
2629 gfc_current_intrinsic_arg
[0]->name
,
2630 gfc_current_intrinsic_arg
[1]->name
,
2631 gfc_current_intrinsic
) == FAILURE
)
2636 mpz_t array_size
, vector_size
;
2637 bool have_array_size
, have_vector_size
;
2639 if (same_type_check (array
, 0, vector
, 2) == FAILURE
)
2642 if (rank_check (vector
, 2, 1) == FAILURE
)
2645 /* VECTOR requires at least as many elements as MASK
2646 has .TRUE. values. */
2647 have_array_size
= gfc_array_size (array
, &array_size
) == SUCCESS
;
2648 have_vector_size
= gfc_array_size (vector
, &vector_size
) == SUCCESS
;
2650 if (have_vector_size
2651 && (mask
->expr_type
== EXPR_ARRAY
2652 || (mask
->expr_type
== EXPR_CONSTANT
2653 && have_array_size
)))
2655 int mask_true_values
= 0;
2657 if (mask
->expr_type
== EXPR_ARRAY
)
2659 gfc_constructor
*mask_ctor
;
2660 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
2663 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
2665 mask_true_values
= 0;
2669 if (mask_ctor
->expr
->value
.logical
)
2672 mask_ctor
= gfc_constructor_next (mask_ctor
);
2675 else if (mask
->expr_type
== EXPR_CONSTANT
&& mask
->value
.logical
)
2676 mask_true_values
= mpz_get_si (array_size
);
2678 if (mpz_get_si (vector_size
) < mask_true_values
)
2680 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2681 "provide at least as many elements as there "
2682 "are .TRUE. values in '%s' (%ld/%d)",
2683 gfc_current_intrinsic_arg
[2]->name
,
2684 gfc_current_intrinsic
, &vector
->where
,
2685 gfc_current_intrinsic_arg
[1]->name
,
2686 mpz_get_si (vector_size
), mask_true_values
);
2691 if (have_array_size
)
2692 mpz_clear (array_size
);
2693 if (have_vector_size
)
2694 mpz_clear (vector_size
);
2702 gfc_check_parity (gfc_expr
*mask
, gfc_expr
*dim
)
2704 if (type_check (mask
, 0, BT_LOGICAL
) == FAILURE
)
2707 if (array_check (mask
, 0) == FAILURE
)
2710 if (dim_rank_check (dim
, mask
, false) == FAILURE
)
2718 gfc_check_precision (gfc_expr
*x
)
2720 if (real_or_complex_check (x
, 0) == FAILURE
)
2728 gfc_check_present (gfc_expr
*a
)
2732 if (variable_check (a
, 0) == FAILURE
)
2735 sym
= a
->symtree
->n
.sym
;
2736 if (!sym
->attr
.dummy
)
2738 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2739 "dummy variable", gfc_current_intrinsic_arg
[0]->name
,
2740 gfc_current_intrinsic
, &a
->where
);
2744 if (!sym
->attr
.optional
)
2746 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2747 "an OPTIONAL dummy variable",
2748 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
2753 /* 13.14.82 PRESENT(A)
2755 Argument. A shall be the name of an optional dummy argument that is
2756 accessible in the subprogram in which the PRESENT function reference
2760 && !(a
->ref
->next
== NULL
&& a
->ref
->type
== REF_ARRAY
2761 && a
->ref
->u
.ar
.type
== AR_FULL
))
2763 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2764 "subobject of '%s'", gfc_current_intrinsic_arg
[0]->name
,
2765 gfc_current_intrinsic
, &a
->where
, sym
->name
);
2774 gfc_check_radix (gfc_expr
*x
)
2776 if (int_or_real_check (x
, 0) == FAILURE
)
2784 gfc_check_range (gfc_expr
*x
)
2786 if (numeric_check (x
, 0) == FAILURE
)
2793 /* real, float, sngl. */
2795 gfc_check_real (gfc_expr
*a
, gfc_expr
*kind
)
2797 if (numeric_check (a
, 0) == FAILURE
)
2800 if (kind_check (kind
, 1, BT_REAL
) == FAILURE
)
2808 gfc_check_rename (gfc_expr
*path1
, gfc_expr
*path2
)
2810 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2812 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2815 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2817 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2825 gfc_check_rename_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2827 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2829 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2832 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2834 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2840 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2843 if (scalar_check (status
, 2) == FAILURE
)
2851 gfc_check_repeat (gfc_expr
*x
, gfc_expr
*y
)
2853 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
2856 if (scalar_check (x
, 0) == FAILURE
)
2859 if (type_check (y
, 0, BT_INTEGER
) == FAILURE
)
2862 if (scalar_check (y
, 1) == FAILURE
)
2870 gfc_check_reshape (gfc_expr
*source
, gfc_expr
*shape
,
2871 gfc_expr
*pad
, gfc_expr
*order
)
2877 if (array_check (source
, 0) == FAILURE
)
2880 if (rank_check (shape
, 1, 1) == FAILURE
)
2883 if (type_check (shape
, 1, BT_INTEGER
) == FAILURE
)
2886 if (gfc_array_size (shape
, &size
) != SUCCESS
)
2888 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2889 "array of constant size", &shape
->where
);
2893 shape_size
= mpz_get_ui (size
);
2896 if (shape_size
<= 0)
2898 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
2899 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2903 else if (shape_size
> GFC_MAX_DIMENSIONS
)
2905 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2906 "than %d elements", &shape
->where
, GFC_MAX_DIMENSIONS
);
2909 else if (shape
->expr_type
== EXPR_ARRAY
)
2913 for (i
= 0; i
< shape_size
; ++i
)
2915 e
= gfc_constructor_lookup_expr (shape
->value
.constructor
, i
);
2916 if (e
->expr_type
!= EXPR_CONSTANT
)
2919 gfc_extract_int (e
, &extent
);
2922 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2923 "negative element (%d)",
2924 gfc_current_intrinsic_arg
[1]->name
,
2925 gfc_current_intrinsic
, &e
->where
, extent
);
2933 if (same_type_check (source
, 0, pad
, 2) == FAILURE
)
2936 if (array_check (pad
, 2) == FAILURE
)
2942 if (array_check (order
, 3) == FAILURE
)
2945 if (type_check (order
, 3, BT_INTEGER
) == FAILURE
)
2948 if (order
->expr_type
== EXPR_ARRAY
)
2950 int i
, order_size
, dim
, perm
[GFC_MAX_DIMENSIONS
];
2953 for (i
= 0; i
< GFC_MAX_DIMENSIONS
; ++i
)
2956 gfc_array_size (order
, &size
);
2957 order_size
= mpz_get_ui (size
);
2960 if (order_size
!= shape_size
)
2962 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2963 "has wrong number of elements (%d/%d)",
2964 gfc_current_intrinsic_arg
[3]->name
,
2965 gfc_current_intrinsic
, &order
->where
,
2966 order_size
, shape_size
);
2970 for (i
= 1; i
<= order_size
; ++i
)
2972 e
= gfc_constructor_lookup_expr (order
->value
.constructor
, i
-1);
2973 if (e
->expr_type
!= EXPR_CONSTANT
)
2976 gfc_extract_int (e
, &dim
);
2978 if (dim
< 1 || dim
> order_size
)
2980 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2981 "has out-of-range dimension (%d)",
2982 gfc_current_intrinsic_arg
[3]->name
,
2983 gfc_current_intrinsic
, &e
->where
, dim
);
2987 if (perm
[dim
-1] != 0)
2989 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2990 "invalid permutation of dimensions (dimension "
2992 gfc_current_intrinsic_arg
[3]->name
,
2993 gfc_current_intrinsic
, &e
->where
, dim
);
3002 if (pad
== NULL
&& shape
->expr_type
== EXPR_ARRAY
3003 && gfc_is_constant_expr (shape
)
3004 && !(source
->expr_type
== EXPR_VARIABLE
&& source
->symtree
->n
.sym
->as
3005 && source
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
))
3007 /* Check the match in size between source and destination. */
3008 if (gfc_array_size (source
, &nelems
) == SUCCESS
)
3014 mpz_init_set_ui (size
, 1);
3015 for (c
= gfc_constructor_first (shape
->value
.constructor
);
3016 c
; c
= gfc_constructor_next (c
))
3017 mpz_mul (size
, size
, c
->expr
->value
.integer
);
3019 test
= mpz_cmp (nelems
, size
) < 0 && mpz_cmp_ui (size
, 0) > 0;
3025 gfc_error ("Without padding, there are not enough elements "
3026 "in the intrinsic RESHAPE source at %L to match "
3027 "the shape", &source
->where
);
3038 gfc_check_same_type_as (gfc_expr
*a
, gfc_expr
*b
)
3041 if (a
->ts
.type
!= BT_DERIVED
&& a
->ts
.type
!= BT_CLASS
)
3043 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3044 "must be of a derived type",
3045 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3050 if (!gfc_type_is_extensible (a
->ts
.u
.derived
))
3052 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3053 "must be of an extensible type",
3054 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3059 if (b
->ts
.type
!= BT_DERIVED
&& b
->ts
.type
!= BT_CLASS
)
3061 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3062 "must be of a derived type",
3063 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3068 if (!gfc_type_is_extensible (b
->ts
.u
.derived
))
3070 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3071 "must be of an extensible type",
3072 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3082 gfc_check_scale (gfc_expr
*x
, gfc_expr
*i
)
3084 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3087 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
3095 gfc_check_scan (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
3097 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3100 if (type_check (y
, 1, BT_CHARACTER
) == FAILURE
)
3103 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
3106 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
3108 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3109 "with KIND argument at %L",
3110 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3113 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
3121 gfc_check_secnds (gfc_expr
*r
)
3123 if (type_check (r
, 0, BT_REAL
) == FAILURE
)
3126 if (kind_value_check (r
, 0, 4) == FAILURE
)
3129 if (scalar_check (r
, 0) == FAILURE
)
3137 gfc_check_selected_char_kind (gfc_expr
*name
)
3139 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3142 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3145 if (scalar_check (name
, 0) == FAILURE
)
3153 gfc_check_selected_int_kind (gfc_expr
*r
)
3155 if (type_check (r
, 0, BT_INTEGER
) == FAILURE
)
3158 if (scalar_check (r
, 0) == FAILURE
)
3166 gfc_check_selected_real_kind (gfc_expr
*p
, gfc_expr
*r
, gfc_expr
*radix
)
3168 if (p
== NULL
&& r
== NULL
3169 && gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: SELECTED_REAL_KIND with"
3170 " neither 'P' nor 'R' argument at %L",
3171 gfc_current_intrinsic_where
) == FAILURE
)
3176 if (type_check (p
, 0, BT_INTEGER
) == FAILURE
)
3179 if (scalar_check (p
, 0) == FAILURE
)
3185 if (type_check (r
, 1, BT_INTEGER
) == FAILURE
)
3188 if (scalar_check (r
, 1) == FAILURE
)
3194 if (type_check (radix
, 1, BT_INTEGER
) == FAILURE
)
3197 if (scalar_check (radix
, 1) == FAILURE
)
3200 if (gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: '%s' intrinsic with "
3201 "RADIX argument at %L", gfc_current_intrinsic
,
3202 &radix
->where
) == FAILURE
)
3211 gfc_check_set_exponent (gfc_expr
*x
, gfc_expr
*i
)
3213 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3216 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
3224 gfc_check_shape (gfc_expr
*source
)
3228 if (source
->rank
== 0 || source
->expr_type
!= EXPR_VARIABLE
)
3231 ar
= gfc_find_array_ref (source
);
3233 if (ar
->as
&& ar
->as
->type
== AS_ASSUMED_SIZE
&& ar
->type
== AR_FULL
)
3235 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
3236 "an assumed size array", &source
->where
);
3245 gfc_check_shift (gfc_expr
*i
, gfc_expr
*shift
)
3247 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
3250 if (type_check (shift
, 0, BT_INTEGER
) == FAILURE
)
3253 if (nonnegative_check ("SHIFT", shift
) == FAILURE
)
3256 if (less_than_bitsize1 ("I", i
, "SHIFT", shift
, true) == FAILURE
)
3264 gfc_check_sign (gfc_expr
*a
, gfc_expr
*b
)
3266 if (int_or_real_check (a
, 0) == FAILURE
)
3269 if (same_type_check (a
, 0, b
, 1) == FAILURE
)
3277 gfc_check_size (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
3279 if (array_check (array
, 0) == FAILURE
)
3282 if (dim_check (dim
, 1, true) == FAILURE
)
3285 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
3288 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3290 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3291 "with KIND argument at %L",
3292 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3301 gfc_check_sizeof (gfc_expr
*arg ATTRIBUTE_UNUSED
)
3308 gfc_check_c_sizeof (gfc_expr
*arg
)
3310 if (verify_c_interop (&arg
->ts
) != SUCCESS
)
3312 gfc_error ("'%s' argument of '%s' intrinsic at %L must be be an "
3313 "interoperable data entity",
3314 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3323 gfc_check_sleep_sub (gfc_expr
*seconds
)
3325 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
3328 if (scalar_check (seconds
, 0) == FAILURE
)
3335 gfc_check_sngl (gfc_expr
*a
)
3337 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
3340 if ((a
->ts
.kind
!= gfc_default_double_kind
)
3341 && gfc_notify_std (GFC_STD_GNU
, "GNU extension: non double precision"
3342 "REAL argument to %s intrinsic at %L",
3343 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
3350 gfc_check_spread (gfc_expr
*source
, gfc_expr
*dim
, gfc_expr
*ncopies
)
3352 if (source
->rank
>= GFC_MAX_DIMENSIONS
)
3354 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
3355 "than rank %d", gfc_current_intrinsic_arg
[0]->name
,
3356 gfc_current_intrinsic
, &source
->where
, GFC_MAX_DIMENSIONS
);
3364 if (dim_check (dim
, 1, false) == FAILURE
)
3367 /* dim_rank_check() does not apply here. */
3369 && dim
->expr_type
== EXPR_CONSTANT
3370 && (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
3371 || mpz_cmp_ui (dim
->value
.integer
, source
->rank
+ 1) > 0))
3373 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
3374 "dimension index", gfc_current_intrinsic_arg
[1]->name
,
3375 gfc_current_intrinsic
, &dim
->where
);
3379 if (type_check (ncopies
, 2, BT_INTEGER
) == FAILURE
)
3382 if (scalar_check (ncopies
, 2) == FAILURE
)
3389 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3393 gfc_check_fgetputc_sub (gfc_expr
*unit
, gfc_expr
*c
, gfc_expr
*status
)
3395 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3398 if (scalar_check (unit
, 0) == FAILURE
)
3401 if (type_check (c
, 1, BT_CHARACTER
) == FAILURE
)
3403 if (kind_value_check (c
, 1, gfc_default_character_kind
) == FAILURE
)
3409 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3410 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
3411 || scalar_check (status
, 2) == FAILURE
)
3419 gfc_check_fgetputc (gfc_expr
*unit
, gfc_expr
*c
)
3421 return gfc_check_fgetputc_sub (unit
, c
, NULL
);
3426 gfc_check_fgetput_sub (gfc_expr
*c
, gfc_expr
*status
)
3428 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
3430 if (kind_value_check (c
, 0, gfc_default_character_kind
) == FAILURE
)
3436 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
3437 || kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
3438 || scalar_check (status
, 1) == FAILURE
)
3446 gfc_check_fgetput (gfc_expr
*c
)
3448 return gfc_check_fgetput_sub (c
, NULL
);
3453 gfc_check_fseek_sub (gfc_expr
*unit
, gfc_expr
*offset
, gfc_expr
*whence
, gfc_expr
*status
)
3455 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3458 if (scalar_check (unit
, 0) == FAILURE
)
3461 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3464 if (scalar_check (offset
, 1) == FAILURE
)
3467 if (type_check (whence
, 2, BT_INTEGER
) == FAILURE
)
3470 if (scalar_check (whence
, 2) == FAILURE
)
3476 if (type_check (status
, 3, BT_INTEGER
) == FAILURE
)
3479 if (kind_value_check (status
, 3, 4) == FAILURE
)
3482 if (scalar_check (status
, 3) == FAILURE
)
3491 gfc_check_fstat (gfc_expr
*unit
, gfc_expr
*array
)
3493 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3496 if (scalar_check (unit
, 0) == FAILURE
)
3499 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3500 || kind_value_check (unit
, 0, gfc_default_integer_kind
) == FAILURE
)
3503 if (array_check (array
, 1) == FAILURE
)
3511 gfc_check_fstat_sub (gfc_expr
*unit
, gfc_expr
*array
, gfc_expr
*status
)
3513 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3516 if (scalar_check (unit
, 0) == FAILURE
)
3519 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3520 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3523 if (array_check (array
, 1) == FAILURE
)
3529 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3530 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
3533 if (scalar_check (status
, 2) == FAILURE
)
3541 gfc_check_ftell (gfc_expr
*unit
)
3543 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3546 if (scalar_check (unit
, 0) == FAILURE
)
3554 gfc_check_ftell_sub (gfc_expr
*unit
, gfc_expr
*offset
)
3556 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3559 if (scalar_check (unit
, 0) == FAILURE
)
3562 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3565 if (scalar_check (offset
, 1) == FAILURE
)
3573 gfc_check_stat (gfc_expr
*name
, gfc_expr
*array
)
3575 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3577 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3580 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3581 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3584 if (array_check (array
, 1) == FAILURE
)
3592 gfc_check_stat_sub (gfc_expr
*name
, gfc_expr
*array
, gfc_expr
*status
)
3594 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3596 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3599 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3600 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3603 if (array_check (array
, 1) == FAILURE
)
3609 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3610 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3613 if (scalar_check (status
, 2) == FAILURE
)
3621 gfc_check_image_index (gfc_expr
*coarray
, gfc_expr
*sub
)
3623 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3625 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3629 if (coarray_check (coarray
, 0) == FAILURE
)
3634 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3635 gfc_current_intrinsic_arg
[1]->name
, &sub
->where
);
3644 gfc_check_this_image (gfc_expr
*coarray
, gfc_expr
*dim
)
3646 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3648 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3652 if (dim
!= NULL
&& coarray
== NULL
)
3654 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3655 "intrinsic at %L", &dim
->where
);
3659 if (coarray
== NULL
)
3662 if (coarray_check (coarray
, 0) == FAILURE
)
3667 if (dim_check (dim
, 1, false) == FAILURE
)
3670 if (dim_corank_check (dim
, coarray
) == FAILURE
)
3679 gfc_check_transfer (gfc_expr
*source ATTRIBUTE_UNUSED
,
3680 gfc_expr
*mold ATTRIBUTE_UNUSED
, gfc_expr
*size
)
3682 if (mold
->ts
.type
== BT_HOLLERITH
)
3684 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3685 &mold
->where
, gfc_basic_typename (BT_HOLLERITH
));
3691 if (type_check (size
, 2, BT_INTEGER
) == FAILURE
)
3694 if (scalar_check (size
, 2) == FAILURE
)
3697 if (nonoptional_check (size
, 2) == FAILURE
)
3706 gfc_check_transpose (gfc_expr
*matrix
)
3708 if (rank_check (matrix
, 0, 2) == FAILURE
)
3716 gfc_check_ubound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
3718 if (array_check (array
, 0) == FAILURE
)
3721 if (dim_check (dim
, 1, false) == FAILURE
)
3724 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
3727 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3729 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3730 "with KIND argument at %L",
3731 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3739 gfc_check_ucobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
3741 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3743 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3747 if (coarray_check (coarray
, 0) == FAILURE
)
3752 if (dim_check (dim
, 1, false) == FAILURE
)
3755 if (dim_corank_check (dim
, coarray
) == FAILURE
)
3759 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3767 gfc_check_unpack (gfc_expr
*vector
, gfc_expr
*mask
, gfc_expr
*field
)
3771 if (rank_check (vector
, 0, 1) == FAILURE
)
3774 if (array_check (mask
, 1) == FAILURE
)
3777 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
3780 if (same_type_check (vector
, 0, field
, 2) == FAILURE
)
3783 if (mask
->expr_type
== EXPR_ARRAY
3784 && gfc_array_size (vector
, &vector_size
) == SUCCESS
)
3786 int mask_true_count
= 0;
3787 gfc_constructor
*mask_ctor
;
3788 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
3791 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
3793 mask_true_count
= 0;
3797 if (mask_ctor
->expr
->value
.logical
)
3800 mask_ctor
= gfc_constructor_next (mask_ctor
);
3803 if (mpz_get_si (vector_size
) < mask_true_count
)
3805 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
3806 "provide at least as many elements as there "
3807 "are .TRUE. values in '%s' (%ld/%d)",
3808 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3809 &vector
->where
, gfc_current_intrinsic_arg
[1]->name
,
3810 mpz_get_si (vector_size
), mask_true_count
);
3814 mpz_clear (vector_size
);
3817 if (mask
->rank
!= field
->rank
&& field
->rank
!= 0)
3819 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
3820 "the same rank as '%s' or be a scalar",
3821 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
3822 &field
->where
, gfc_current_intrinsic_arg
[1]->name
);
3826 if (mask
->rank
== field
->rank
)
3829 for (i
= 0; i
< field
->rank
; i
++)
3830 if (! identical_dimen_shape (mask
, i
, field
, i
))
3832 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
3833 "must have identical shape.",
3834 gfc_current_intrinsic_arg
[2]->name
,
3835 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3845 gfc_check_verify (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
3847 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3850 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
3853 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
3856 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
3858 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3859 "with KIND argument at %L",
3860 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3868 gfc_check_trim (gfc_expr
*x
)
3870 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3873 if (scalar_check (x
, 0) == FAILURE
)
3881 gfc_check_ttynam (gfc_expr
*unit
)
3883 if (scalar_check (unit
, 0) == FAILURE
)
3886 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3893 /* Common check function for the half a dozen intrinsics that have a
3894 single real argument. */
3897 gfc_check_x (gfc_expr
*x
)
3899 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3906 /************* Check functions for intrinsic subroutines *************/
3909 gfc_check_cpu_time (gfc_expr
*time
)
3911 if (scalar_check (time
, 0) == FAILURE
)
3914 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
3917 if (variable_check (time
, 0) == FAILURE
)
3925 gfc_check_date_and_time (gfc_expr
*date
, gfc_expr
*time
,
3926 gfc_expr
*zone
, gfc_expr
*values
)
3930 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
3932 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
3934 if (scalar_check (date
, 0) == FAILURE
)
3936 if (variable_check (date
, 0) == FAILURE
)
3942 if (type_check (time
, 1, BT_CHARACTER
) == FAILURE
)
3944 if (kind_value_check (time
, 1, gfc_default_character_kind
) == FAILURE
)
3946 if (scalar_check (time
, 1) == FAILURE
)
3948 if (variable_check (time
, 1) == FAILURE
)
3954 if (type_check (zone
, 2, BT_CHARACTER
) == FAILURE
)
3956 if (kind_value_check (zone
, 2, gfc_default_character_kind
) == FAILURE
)
3958 if (scalar_check (zone
, 2) == FAILURE
)
3960 if (variable_check (zone
, 2) == FAILURE
)
3966 if (type_check (values
, 3, BT_INTEGER
) == FAILURE
)
3968 if (array_check (values
, 3) == FAILURE
)
3970 if (rank_check (values
, 3, 1) == FAILURE
)
3972 if (variable_check (values
, 3) == FAILURE
)
3981 gfc_check_mvbits (gfc_expr
*from
, gfc_expr
*frompos
, gfc_expr
*len
,
3982 gfc_expr
*to
, gfc_expr
*topos
)
3984 if (type_check (from
, 0, BT_INTEGER
) == FAILURE
)
3987 if (type_check (frompos
, 1, BT_INTEGER
) == FAILURE
)
3990 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
3993 if (same_type_check (from
, 0, to
, 3) == FAILURE
)
3996 if (variable_check (to
, 3) == FAILURE
)
3999 if (type_check (topos
, 4, BT_INTEGER
) == FAILURE
)
4002 if (nonnegative_check ("frompos", frompos
) == FAILURE
)
4005 if (nonnegative_check ("topos", topos
) == FAILURE
)
4008 if (nonnegative_check ("len", len
) == FAILURE
)
4011 if (less_than_bitsize2 ("from", from
, "frompos", frompos
, "len", len
)
4015 if (less_than_bitsize2 ("to", to
, "topos", topos
, "len", len
) == FAILURE
)
4023 gfc_check_random_number (gfc_expr
*harvest
)
4025 if (type_check (harvest
, 0, BT_REAL
) == FAILURE
)
4028 if (variable_check (harvest
, 0) == FAILURE
)
4036 gfc_check_random_seed (gfc_expr
*size
, gfc_expr
*put
, gfc_expr
*get
)
4038 unsigned int nargs
= 0, kiss_size
;
4039 locus
*where
= NULL
;
4040 mpz_t put_size
, get_size
;
4041 bool have_gfc_real_16
; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
4043 have_gfc_real_16
= gfc_validate_kind (BT_REAL
, 16, true) != -1;
4045 /* Keep the number of bytes in sync with kiss_size in
4046 libgfortran/intrinsics/random.c. */
4047 kiss_size
= (have_gfc_real_16
? 48 : 32) / gfc_default_integer_kind
;
4051 if (size
->expr_type
!= EXPR_VARIABLE
4052 || !size
->symtree
->n
.sym
->attr
.optional
)
4055 if (scalar_check (size
, 0) == FAILURE
)
4058 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
4061 if (variable_check (size
, 0) == FAILURE
)
4064 if (kind_value_check (size
, 0, gfc_default_integer_kind
) == FAILURE
)
4070 if (put
->expr_type
!= EXPR_VARIABLE
4071 || !put
->symtree
->n
.sym
->attr
.optional
)
4074 where
= &put
->where
;
4077 if (array_check (put
, 1) == FAILURE
)
4080 if (rank_check (put
, 1, 1) == FAILURE
)
4083 if (type_check (put
, 1, BT_INTEGER
) == FAILURE
)
4086 if (kind_value_check (put
, 1, gfc_default_integer_kind
) == FAILURE
)
4089 if (gfc_array_size (put
, &put_size
) == SUCCESS
4090 && mpz_get_ui (put_size
) < kiss_size
)
4091 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4092 "too small (%i/%i)",
4093 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4094 where
, (int) mpz_get_ui (put_size
), kiss_size
);
4099 if (get
->expr_type
!= EXPR_VARIABLE
4100 || !get
->symtree
->n
.sym
->attr
.optional
)
4103 where
= &get
->where
;
4106 if (array_check (get
, 2) == FAILURE
)
4109 if (rank_check (get
, 2, 1) == FAILURE
)
4112 if (type_check (get
, 2, BT_INTEGER
) == FAILURE
)
4115 if (variable_check (get
, 2) == FAILURE
)
4118 if (kind_value_check (get
, 2, gfc_default_integer_kind
) == FAILURE
)
4121 if (gfc_array_size (get
, &get_size
) == SUCCESS
4122 && mpz_get_ui (get_size
) < kiss_size
)
4123 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4124 "too small (%i/%i)",
4125 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
4126 where
, (int) mpz_get_ui (get_size
), kiss_size
);
4129 /* RANDOM_SEED may not have more than one non-optional argument. */
4131 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
, where
);
4138 gfc_check_second_sub (gfc_expr
*time
)
4140 if (scalar_check (time
, 0) == FAILURE
)
4143 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
4146 if (kind_value_check(time
, 0, 4) == FAILURE
)
4153 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
4154 count, count_rate, and count_max are all optional arguments */
4157 gfc_check_system_clock (gfc_expr
*count
, gfc_expr
*count_rate
,
4158 gfc_expr
*count_max
)
4162 if (scalar_check (count
, 0) == FAILURE
)
4165 if (type_check (count
, 0, BT_INTEGER
) == FAILURE
)
4168 if (variable_check (count
, 0) == FAILURE
)
4172 if (count_rate
!= NULL
)
4174 if (scalar_check (count_rate
, 1) == FAILURE
)
4177 if (type_check (count_rate
, 1, BT_INTEGER
) == FAILURE
)
4180 if (variable_check (count_rate
, 1) == FAILURE
)
4184 && same_type_check (count
, 0, count_rate
, 1) == FAILURE
)
4189 if (count_max
!= NULL
)
4191 if (scalar_check (count_max
, 2) == FAILURE
)
4194 if (type_check (count_max
, 2, BT_INTEGER
) == FAILURE
)
4197 if (variable_check (count_max
, 2) == FAILURE
)
4201 && same_type_check (count
, 0, count_max
, 2) == FAILURE
)
4204 if (count_rate
!= NULL
4205 && same_type_check (count_rate
, 1, count_max
, 2) == FAILURE
)
4214 gfc_check_irand (gfc_expr
*x
)
4219 if (scalar_check (x
, 0) == FAILURE
)
4222 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4225 if (kind_value_check(x
, 0, 4) == FAILURE
)
4233 gfc_check_alarm_sub (gfc_expr
*seconds
, gfc_expr
*handler
, gfc_expr
*status
)
4235 if (scalar_check (seconds
, 0) == FAILURE
)
4237 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
4240 if (int_or_proc_check (handler
, 1) == FAILURE
)
4242 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4248 if (scalar_check (status
, 2) == FAILURE
)
4250 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
4252 if (kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
4260 gfc_check_rand (gfc_expr
*x
)
4265 if (scalar_check (x
, 0) == FAILURE
)
4268 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4271 if (kind_value_check(x
, 0, 4) == FAILURE
)
4279 gfc_check_srand (gfc_expr
*x
)
4281 if (scalar_check (x
, 0) == FAILURE
)
4284 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4287 if (kind_value_check(x
, 0, 4) == FAILURE
)
4295 gfc_check_ctime_sub (gfc_expr
*time
, gfc_expr
*result
)
4297 if (scalar_check (time
, 0) == FAILURE
)
4299 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
4302 if (type_check (result
, 1, BT_CHARACTER
) == FAILURE
)
4304 if (kind_value_check (result
, 1, gfc_default_character_kind
) == FAILURE
)
4312 gfc_check_dtime_etime (gfc_expr
*x
)
4314 if (array_check (x
, 0) == FAILURE
)
4317 if (rank_check (x
, 0, 1) == FAILURE
)
4320 if (variable_check (x
, 0) == FAILURE
)
4323 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4326 if (kind_value_check(x
, 0, 4) == FAILURE
)
4334 gfc_check_dtime_etime_sub (gfc_expr
*values
, gfc_expr
*time
)
4336 if (array_check (values
, 0) == FAILURE
)
4339 if (rank_check (values
, 0, 1) == FAILURE
)
4342 if (variable_check (values
, 0) == FAILURE
)
4345 if (type_check (values
, 0, BT_REAL
) == FAILURE
)
4348 if (kind_value_check(values
, 0, 4) == FAILURE
)
4351 if (scalar_check (time
, 1) == FAILURE
)
4354 if (type_check (time
, 1, BT_REAL
) == FAILURE
)
4357 if (kind_value_check(time
, 1, 4) == FAILURE
)
4365 gfc_check_fdate_sub (gfc_expr
*date
)
4367 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
4369 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
4377 gfc_check_gerror (gfc_expr
*msg
)
4379 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
4381 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4389 gfc_check_getcwd_sub (gfc_expr
*cwd
, gfc_expr
*status
)
4391 if (type_check (cwd
, 0, BT_CHARACTER
) == FAILURE
)
4393 if (kind_value_check (cwd
, 0, gfc_default_character_kind
) == FAILURE
)
4399 if (scalar_check (status
, 1) == FAILURE
)
4402 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4410 gfc_check_getarg (gfc_expr
*pos
, gfc_expr
*value
)
4412 if (type_check (pos
, 0, BT_INTEGER
) == FAILURE
)
4415 if (pos
->ts
.kind
> gfc_default_integer_kind
)
4417 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4418 "not wider than the default kind (%d)",
4419 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4420 &pos
->where
, gfc_default_integer_kind
);
4424 if (type_check (value
, 1, BT_CHARACTER
) == FAILURE
)
4426 if (kind_value_check (value
, 1, gfc_default_character_kind
) == FAILURE
)
4434 gfc_check_getlog (gfc_expr
*msg
)
4436 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
4438 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4446 gfc_check_exit (gfc_expr
*status
)
4451 if (type_check (status
, 0, BT_INTEGER
) == FAILURE
)
4454 if (scalar_check (status
, 0) == FAILURE
)
4462 gfc_check_flush (gfc_expr
*unit
)
4467 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4470 if (scalar_check (unit
, 0) == FAILURE
)
4478 gfc_check_free (gfc_expr
*i
)
4480 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
4483 if (scalar_check (i
, 0) == FAILURE
)
4491 gfc_check_hostnm (gfc_expr
*name
)
4493 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4495 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4503 gfc_check_hostnm_sub (gfc_expr
*name
, gfc_expr
*status
)
4505 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4507 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4513 if (scalar_check (status
, 1) == FAILURE
)
4516 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4524 gfc_check_itime_idate (gfc_expr
*values
)
4526 if (array_check (values
, 0) == FAILURE
)
4529 if (rank_check (values
, 0, 1) == FAILURE
)
4532 if (variable_check (values
, 0) == FAILURE
)
4535 if (type_check (values
, 0, BT_INTEGER
) == FAILURE
)
4538 if (kind_value_check(values
, 0, gfc_default_integer_kind
) == FAILURE
)
4546 gfc_check_ltime_gmtime (gfc_expr
*time
, gfc_expr
*values
)
4548 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
4551 if (kind_value_check(time
, 0, gfc_default_integer_kind
) == FAILURE
)
4554 if (scalar_check (time
, 0) == FAILURE
)
4557 if (array_check (values
, 1) == FAILURE
)
4560 if (rank_check (values
, 1, 1) == FAILURE
)
4563 if (variable_check (values
, 1) == FAILURE
)
4566 if (type_check (values
, 1, BT_INTEGER
) == FAILURE
)
4569 if (kind_value_check(values
, 1, gfc_default_integer_kind
) == FAILURE
)
4577 gfc_check_ttynam_sub (gfc_expr
*unit
, gfc_expr
*name
)
4579 if (scalar_check (unit
, 0) == FAILURE
)
4582 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4585 if (type_check (name
, 1, BT_CHARACTER
) == FAILURE
)
4587 if (kind_value_check (name
, 1, gfc_default_character_kind
) == FAILURE
)
4595 gfc_check_isatty (gfc_expr
*unit
)
4600 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4603 if (scalar_check (unit
, 0) == FAILURE
)
4611 gfc_check_isnan (gfc_expr
*x
)
4613 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4621 gfc_check_perror (gfc_expr
*string
)
4623 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
)
4625 if (kind_value_check (string
, 0, gfc_default_character_kind
) == FAILURE
)
4633 gfc_check_umask (gfc_expr
*mask
)
4635 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
4638 if (scalar_check (mask
, 0) == FAILURE
)
4646 gfc_check_umask_sub (gfc_expr
*mask
, gfc_expr
*old
)
4648 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
4651 if (scalar_check (mask
, 0) == FAILURE
)
4657 if (scalar_check (old
, 1) == FAILURE
)
4660 if (type_check (old
, 1, BT_INTEGER
) == FAILURE
)
4668 gfc_check_unlink (gfc_expr
*name
)
4670 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4672 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4680 gfc_check_unlink_sub (gfc_expr
*name
, gfc_expr
*status
)
4682 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4684 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4690 if (scalar_check (status
, 1) == FAILURE
)
4693 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4701 gfc_check_signal (gfc_expr
*number
, gfc_expr
*handler
)
4703 if (scalar_check (number
, 0) == FAILURE
)
4705 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
4708 if (int_or_proc_check (handler
, 1) == FAILURE
)
4710 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4718 gfc_check_signal_sub (gfc_expr
*number
, gfc_expr
*handler
, gfc_expr
*status
)
4720 if (scalar_check (number
, 0) == FAILURE
)
4722 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
4725 if (int_or_proc_check (handler
, 1) == FAILURE
)
4727 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4733 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
4735 if (scalar_check (status
, 2) == FAILURE
)
4743 gfc_check_system_sub (gfc_expr
*cmd
, gfc_expr
*status
)
4745 if (type_check (cmd
, 0, BT_CHARACTER
) == FAILURE
)
4747 if (kind_value_check (cmd
, 0, gfc_default_character_kind
) == FAILURE
)
4750 if (scalar_check (status
, 1) == FAILURE
)
4753 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4756 if (kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
)
4763 /* This is used for the GNU intrinsics AND, OR and XOR. */
4765 gfc_check_and (gfc_expr
*i
, gfc_expr
*j
)
4767 if (i
->ts
.type
!= BT_INTEGER
&& i
->ts
.type
!= BT_LOGICAL
)
4769 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4770 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
4771 gfc_current_intrinsic
, &i
->where
);
4775 if (j
->ts
.type
!= BT_INTEGER
&& j
->ts
.type
!= BT_LOGICAL
)
4777 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4778 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
4779 gfc_current_intrinsic
, &j
->where
);
4783 if (i
->ts
.type
!= j
->ts
.type
)
4785 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
4786 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
4787 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4792 if (scalar_check (i
, 0) == FAILURE
)
4795 if (scalar_check (j
, 1) == FAILURE
)
4803 gfc_check_storage_size (gfc_expr
*a ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
4808 if (type_check (kind
, 1, BT_INTEGER
) == FAILURE
)
4811 if (scalar_check (kind
, 1) == FAILURE
)
4814 if (kind
->expr_type
!= EXPR_CONSTANT
)
4816 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
4817 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,