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
, bool allow_proc
)
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
497 || !e
->symtree
->n
.sym
->attr
.function
498 || (e
->symtree
->n
.sym
== e
->symtree
->n
.sym
->result
499 && (e
->symtree
->n
.sym
== gfc_current_ns
->proc_name
500 || (gfc_current_ns
->parent
502 == gfc_current_ns
->parent
->proc_name
)))))
505 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
506 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
, &e
->where
);
512 /* Check the common DIM parameter for correctness. */
515 dim_check (gfc_expr
*dim
, int n
, bool optional
)
520 if (type_check (dim
, n
, BT_INTEGER
) == FAILURE
)
523 if (scalar_check (dim
, n
) == FAILURE
)
526 if (!optional
&& nonoptional_check (dim
, n
) == FAILURE
)
533 /* If a coarray DIM parameter is a constant, make sure that it is greater than
534 zero and less than or equal to the corank of the given array. */
537 dim_corank_check (gfc_expr
*dim
, gfc_expr
*array
)
542 gcc_assert (array
->expr_type
== EXPR_VARIABLE
);
544 if (dim
->expr_type
!= EXPR_CONSTANT
)
547 ar
= gfc_find_array_ref (array
);
548 corank
= ar
->as
->corank
;
550 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
551 || mpz_cmp_ui (dim
->value
.integer
, corank
) > 0)
553 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
554 "codimension index", gfc_current_intrinsic
, &dim
->where
);
563 /* If a DIM parameter is a constant, make sure that it is greater than
564 zero and less than or equal to the rank of the given array. If
565 allow_assumed is zero then dim must be less than the rank of the array
566 for assumed size arrays. */
569 dim_rank_check (gfc_expr
*dim
, gfc_expr
*array
, int allow_assumed
)
577 if (dim
->expr_type
!= EXPR_CONSTANT
)
580 if (array
->expr_type
== EXPR_FUNCTION
&& array
->value
.function
.isym
581 && array
->value
.function
.isym
->id
== GFC_ISYM_SPREAD
)
582 rank
= array
->rank
+ 1;
586 if (array
->expr_type
== EXPR_VARIABLE
)
588 ar
= gfc_find_array_ref (array
);
589 if (ar
->as
->type
== AS_ASSUMED_SIZE
591 && ar
->type
!= AR_ELEMENT
592 && ar
->type
!= AR_SECTION
)
596 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
597 || mpz_cmp_ui (dim
->value
.integer
, rank
) > 0)
599 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
600 "dimension index", gfc_current_intrinsic
, &dim
->where
);
609 /* Compare the size of a along dimension ai with the size of b along
610 dimension bi, returning 0 if they are known not to be identical,
611 and 1 if they are identical, or if this cannot be determined. */
614 identical_dimen_shape (gfc_expr
*a
, int ai
, gfc_expr
*b
, int bi
)
616 mpz_t a_size
, b_size
;
619 gcc_assert (a
->rank
> ai
);
620 gcc_assert (b
->rank
> bi
);
624 if (gfc_array_dimen_size (a
, ai
, &a_size
) == SUCCESS
)
626 if (gfc_array_dimen_size (b
, bi
, &b_size
) == SUCCESS
)
628 if (mpz_cmp (a_size
, b_size
) != 0)
638 /* Calculate the length of a character variable, including substrings.
639 Strip away parentheses if necessary. Return -1 if no length could
643 gfc_var_strlen (const gfc_expr
*a
)
647 while (a
->expr_type
== EXPR_OP
&& a
->value
.op
.op
== INTRINSIC_PARENTHESES
)
650 for (ra
= a
->ref
; ra
!= NULL
&& ra
->type
!= REF_SUBSTRING
; ra
= ra
->next
)
657 if (ra
->u
.ss
.start
->expr_type
== EXPR_CONSTANT
658 && ra
->u
.ss
.end
->expr_type
== EXPR_CONSTANT
)
660 start_a
= mpz_get_si (ra
->u
.ss
.start
->value
.integer
);
661 end_a
= mpz_get_si (ra
->u
.ss
.end
->value
.integer
);
662 return end_a
- start_a
+ 1;
664 else if (gfc_dep_compare_expr (ra
->u
.ss
.start
, ra
->u
.ss
.end
) == 0)
670 if (a
->ts
.u
.cl
&& a
->ts
.u
.cl
->length
671 && a
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
672 return mpz_get_si (a
->ts
.u
.cl
->length
->value
.integer
);
673 else if (a
->expr_type
== EXPR_CONSTANT
674 && (a
->ts
.u
.cl
== NULL
|| a
->ts
.u
.cl
->length
== NULL
))
675 return a
->value
.character
.length
;
681 /* Check whether two character expressions have the same length;
682 returns SUCCESS if they have or if the length cannot be determined,
683 otherwise return FAILURE and raise a gfc_error. */
686 gfc_check_same_strlen (const gfc_expr
*a
, const gfc_expr
*b
, const char *name
)
690 len_a
= gfc_var_strlen(a
);
691 len_b
= gfc_var_strlen(b
);
693 if (len_a
== -1 || len_b
== -1 || len_a
== len_b
)
697 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
698 len_a
, len_b
, name
, &a
->where
);
704 /***** Check functions *****/
706 /* Check subroutine suitable for intrinsics taking a real argument and
707 a kind argument for the result. */
710 check_a_kind (gfc_expr
*a
, gfc_expr
*kind
, bt type
)
712 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
714 if (kind_check (kind
, 1, type
) == FAILURE
)
721 /* Check subroutine suitable for ceiling, floor and nint. */
724 gfc_check_a_ikind (gfc_expr
*a
, gfc_expr
*kind
)
726 return check_a_kind (a
, kind
, BT_INTEGER
);
730 /* Check subroutine suitable for aint, anint. */
733 gfc_check_a_xkind (gfc_expr
*a
, gfc_expr
*kind
)
735 return check_a_kind (a
, kind
, BT_REAL
);
740 gfc_check_abs (gfc_expr
*a
)
742 if (numeric_check (a
, 0) == FAILURE
)
750 gfc_check_achar (gfc_expr
*a
, gfc_expr
*kind
)
752 if (type_check (a
, 0, BT_INTEGER
) == FAILURE
)
754 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
762 gfc_check_access_func (gfc_expr
*name
, gfc_expr
*mode
)
764 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
765 || scalar_check (name
, 0) == FAILURE
)
767 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
770 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
771 || scalar_check (mode
, 1) == FAILURE
)
773 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
781 gfc_check_all_any (gfc_expr
*mask
, gfc_expr
*dim
)
783 if (logical_array_check (mask
, 0) == FAILURE
)
786 if (dim_check (dim
, 1, false) == FAILURE
)
789 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
797 gfc_check_allocated (gfc_expr
*array
)
799 if (variable_check (array
, 0, false) == FAILURE
)
801 if (allocatable_check (array
, 0) == FAILURE
)
808 /* Common check function where the first argument must be real or
809 integer and the second argument must be the same as the first. */
812 gfc_check_a_p (gfc_expr
*a
, gfc_expr
*p
)
814 if (int_or_real_check (a
, 0) == FAILURE
)
817 if (a
->ts
.type
!= p
->ts
.type
)
819 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
820 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
821 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
826 if (a
->ts
.kind
!= p
->ts
.kind
)
828 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
829 &p
->where
) == FAILURE
)
838 gfc_check_x_yd (gfc_expr
*x
, gfc_expr
*y
)
840 if (double_check (x
, 0) == FAILURE
|| double_check (y
, 1) == FAILURE
)
848 gfc_check_associated (gfc_expr
*pointer
, gfc_expr
*target
)
850 symbol_attribute attr1
, attr2
;
855 where
= &pointer
->where
;
857 if (pointer
->expr_type
== EXPR_VARIABLE
|| pointer
->expr_type
== EXPR_FUNCTION
)
858 attr1
= gfc_expr_attr (pointer
);
859 else if (pointer
->expr_type
== EXPR_NULL
)
862 gcc_assert (0); /* Pointer must be a variable or a function. */
864 if (!attr1
.pointer
&& !attr1
.proc_pointer
)
866 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
867 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
872 /* Target argument is optional. */
876 where
= &target
->where
;
877 if (target
->expr_type
== EXPR_NULL
)
880 if (target
->expr_type
== EXPR_VARIABLE
|| target
->expr_type
== EXPR_FUNCTION
)
881 attr2
= gfc_expr_attr (target
);
884 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
885 "or target VARIABLE or FUNCTION",
886 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
891 if (attr1
.pointer
&& !attr2
.pointer
&& !attr2
.target
)
893 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
894 "or a TARGET", gfc_current_intrinsic_arg
[1]->name
,
895 gfc_current_intrinsic
, &target
->where
);
900 if (same_type_check (pointer
, 0, target
, 1) == FAILURE
)
902 if (rank_check (target
, 0, pointer
->rank
) == FAILURE
)
904 if (target
->rank
> 0)
906 for (i
= 0; i
< target
->rank
; i
++)
907 if (target
->ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
909 gfc_error ("Array section with a vector subscript at %L shall not "
910 "be the target of a pointer",
920 gfc_error ("NULL pointer at %L is not permitted as actual argument "
921 "of '%s' intrinsic function", where
, gfc_current_intrinsic
);
928 gfc_check_atan_2 (gfc_expr
*y
, gfc_expr
*x
)
930 /* gfc_notify_std would be a wast of time as the return value
931 is seemingly used only for the generic resolution. The error
932 will be: Too many arguments. */
933 if ((gfc_option
.allow_std
& GFC_STD_F2008
) == 0)
936 return gfc_check_atan2 (y
, x
);
941 gfc_check_atan2 (gfc_expr
*y
, gfc_expr
*x
)
943 if (type_check (y
, 0, BT_REAL
) == FAILURE
)
945 if (same_type_check (y
, 0, x
, 1) == FAILURE
)
952 /* BESJN and BESYN functions. */
955 gfc_check_besn (gfc_expr
*n
, gfc_expr
*x
)
957 if (type_check (n
, 0, BT_INTEGER
) == FAILURE
)
959 if (n
->expr_type
== EXPR_CONSTANT
)
962 gfc_extract_int (n
, &i
);
963 if (i
< 0 && gfc_notify_std (GFC_STD_GNU
, "Extension: Negative argument "
964 "N at %L", &n
->where
) == FAILURE
)
968 if (type_check (x
, 1, BT_REAL
) == FAILURE
)
975 /* Transformational version of the Bessel JN and YN functions. */
978 gfc_check_bessel_n2 (gfc_expr
*n1
, gfc_expr
*n2
, gfc_expr
*x
)
980 if (type_check (n1
, 0, BT_INTEGER
) == FAILURE
)
982 if (scalar_check (n1
, 0) == FAILURE
)
984 if (nonnegative_check("N1", n1
) == FAILURE
)
987 if (type_check (n2
, 1, BT_INTEGER
) == FAILURE
)
989 if (scalar_check (n2
, 1) == FAILURE
)
991 if (nonnegative_check("N2", n2
) == FAILURE
)
994 if (type_check (x
, 2, BT_REAL
) == FAILURE
)
996 if (scalar_check (x
, 2) == FAILURE
)
1004 gfc_check_bge_bgt_ble_blt (gfc_expr
*i
, gfc_expr
*j
)
1006 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1009 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1017 gfc_check_bitfcn (gfc_expr
*i
, gfc_expr
*pos
)
1019 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1022 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
1025 if (nonnegative_check ("pos", pos
) == FAILURE
)
1028 if (less_than_bitsize1 ("i", i
, "pos", pos
, false) == FAILURE
)
1036 gfc_check_char (gfc_expr
*i
, gfc_expr
*kind
)
1038 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1040 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
1048 gfc_check_chdir (gfc_expr
*dir
)
1050 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
1052 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
1060 gfc_check_chdir_sub (gfc_expr
*dir
, gfc_expr
*status
)
1062 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
1064 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
1070 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
1072 if (scalar_check (status
, 1) == FAILURE
)
1080 gfc_check_chmod (gfc_expr
*name
, gfc_expr
*mode
)
1082 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
1084 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
1087 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
1089 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
1097 gfc_check_chmod_sub (gfc_expr
*name
, gfc_expr
*mode
, gfc_expr
*status
)
1099 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
1101 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
1104 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
1106 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
1112 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1115 if (scalar_check (status
, 2) == FAILURE
)
1123 gfc_check_cmplx (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
1125 if (numeric_check (x
, 0) == FAILURE
)
1130 if (numeric_check (y
, 1) == FAILURE
)
1133 if (x
->ts
.type
== BT_COMPLEX
)
1135 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1136 "present if 'x' is COMPLEX",
1137 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1142 if (y
->ts
.type
== BT_COMPLEX
)
1144 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1145 "of either REAL or INTEGER",
1146 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1153 if (kind_check (kind
, 2, BT_COMPLEX
) == FAILURE
)
1161 gfc_check_complex (gfc_expr
*x
, gfc_expr
*y
)
1163 if (int_or_real_check (x
, 0) == FAILURE
)
1165 if (scalar_check (x
, 0) == FAILURE
)
1168 if (int_or_real_check (y
, 1) == FAILURE
)
1170 if (scalar_check (y
, 1) == FAILURE
)
1178 gfc_check_count (gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
1180 if (logical_array_check (mask
, 0) == FAILURE
)
1182 if (dim_check (dim
, 1, false) == FAILURE
)
1184 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
1186 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1188 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1189 "with KIND argument at %L",
1190 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1198 gfc_check_cshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*dim
)
1200 if (array_check (array
, 0) == FAILURE
)
1203 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1206 if (dim_check (dim
, 2, true) == FAILURE
)
1209 if (dim_rank_check (dim
, array
, false) == FAILURE
)
1212 if (array
->rank
== 1 || shift
->rank
== 0)
1214 if (scalar_check (shift
, 1) == FAILURE
)
1217 else if (shift
->rank
== array
->rank
- 1)
1222 else if (dim
->expr_type
== EXPR_CONSTANT
)
1223 gfc_extract_int (dim
, &d
);
1230 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1233 if (!identical_dimen_shape (array
, i
, shift
, j
))
1235 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1236 "invalid shape in dimension %d (%ld/%ld)",
1237 gfc_current_intrinsic_arg
[1]->name
,
1238 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1239 mpz_get_si (array
->shape
[i
]),
1240 mpz_get_si (shift
->shape
[j
]));
1250 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1251 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
1252 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1261 gfc_check_ctime (gfc_expr
*time
)
1263 if (scalar_check (time
, 0) == FAILURE
)
1266 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
1273 gfc_try
gfc_check_datan2 (gfc_expr
*y
, gfc_expr
*x
)
1275 if (double_check (y
, 0) == FAILURE
|| double_check (x
, 1) == FAILURE
)
1282 gfc_check_dcmplx (gfc_expr
*x
, gfc_expr
*y
)
1284 if (numeric_check (x
, 0) == FAILURE
)
1289 if (numeric_check (y
, 1) == FAILURE
)
1292 if (x
->ts
.type
== BT_COMPLEX
)
1294 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1295 "present if 'x' is COMPLEX",
1296 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1301 if (y
->ts
.type
== BT_COMPLEX
)
1303 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1304 "of either REAL or INTEGER",
1305 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1316 gfc_check_dble (gfc_expr
*x
)
1318 if (numeric_check (x
, 0) == FAILURE
)
1326 gfc_check_digits (gfc_expr
*x
)
1328 if (int_or_real_check (x
, 0) == FAILURE
)
1336 gfc_check_dot_product (gfc_expr
*vector_a
, gfc_expr
*vector_b
)
1338 switch (vector_a
->ts
.type
)
1341 if (type_check (vector_b
, 1, BT_LOGICAL
) == FAILURE
)
1348 if (numeric_check (vector_b
, 1) == FAILURE
)
1353 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1354 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
1355 gfc_current_intrinsic
, &vector_a
->where
);
1359 if (rank_check (vector_a
, 0, 1) == FAILURE
)
1362 if (rank_check (vector_b
, 1, 1) == FAILURE
)
1365 if (! identical_dimen_shape (vector_a
, 0, vector_b
, 0))
1367 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1368 "intrinsic 'dot_product'", gfc_current_intrinsic_arg
[0]->name
,
1369 gfc_current_intrinsic_arg
[1]->name
, &vector_a
->where
);
1378 gfc_check_dprod (gfc_expr
*x
, gfc_expr
*y
)
1380 if (type_check (x
, 0, BT_REAL
) == FAILURE
1381 || type_check (y
, 1, BT_REAL
) == FAILURE
)
1384 if (x
->ts
.kind
!= gfc_default_real_kind
)
1386 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1387 "real", gfc_current_intrinsic_arg
[0]->name
,
1388 gfc_current_intrinsic
, &x
->where
);
1392 if (y
->ts
.kind
!= gfc_default_real_kind
)
1394 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1395 "real", gfc_current_intrinsic_arg
[1]->name
,
1396 gfc_current_intrinsic
, &y
->where
);
1405 gfc_check_dshift (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*shift
)
1407 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1410 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1413 if (same_type_check (i
, 0, j
, 1) == FAILURE
)
1416 if (type_check (shift
, 2, BT_INTEGER
) == FAILURE
)
1419 if (nonnegative_check ("SHIFT", shift
) == FAILURE
)
1422 if (less_than_bitsize1 ("I", i
, "SHIFT", shift
, true) == FAILURE
)
1430 gfc_check_eoshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*boundary
,
1433 if (array_check (array
, 0) == FAILURE
)
1436 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1439 if (dim_check (dim
, 3, true) == FAILURE
)
1442 if (dim_rank_check (dim
, array
, false) == FAILURE
)
1445 if (array
->rank
== 1 || shift
->rank
== 0)
1447 if (scalar_check (shift
, 1) == FAILURE
)
1450 else if (shift
->rank
== array
->rank
- 1)
1455 else if (dim
->expr_type
== EXPR_CONSTANT
)
1456 gfc_extract_int (dim
, &d
);
1463 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1466 if (!identical_dimen_shape (array
, i
, shift
, j
))
1468 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1469 "invalid shape in dimension %d (%ld/%ld)",
1470 gfc_current_intrinsic_arg
[1]->name
,
1471 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1472 mpz_get_si (array
->shape
[i
]),
1473 mpz_get_si (shift
->shape
[j
]));
1483 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1484 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
1485 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1489 if (boundary
!= NULL
)
1491 if (same_type_check (array
, 0, boundary
, 2) == FAILURE
)
1494 if (array
->rank
== 1 || boundary
->rank
== 0)
1496 if (scalar_check (boundary
, 2) == FAILURE
)
1499 else if (boundary
->rank
== array
->rank
- 1)
1501 if (gfc_check_conformance (shift
, boundary
,
1502 "arguments '%s' and '%s' for "
1504 gfc_current_intrinsic_arg
[1]->name
,
1505 gfc_current_intrinsic_arg
[2]->name
,
1506 gfc_current_intrinsic
) == FAILURE
)
1511 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1512 "rank %d or be a scalar",
1513 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1514 &shift
->where
, array
->rank
- 1);
1523 gfc_check_float (gfc_expr
*a
)
1525 if (type_check (a
, 0, BT_INTEGER
) == FAILURE
)
1528 if ((a
->ts
.kind
!= gfc_default_integer_kind
)
1529 && gfc_notify_std (GFC_STD_GNU
, "GNU extension: non-default INTEGER "
1530 "kind argument to %s intrinsic at %L",
1531 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
1537 /* A single complex argument. */
1540 gfc_check_fn_c (gfc_expr
*a
)
1542 if (type_check (a
, 0, BT_COMPLEX
) == FAILURE
)
1548 /* A single real argument. */
1551 gfc_check_fn_r (gfc_expr
*a
)
1553 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
1559 /* A single double argument. */
1562 gfc_check_fn_d (gfc_expr
*a
)
1564 if (double_check (a
, 0) == FAILURE
)
1570 /* A single real or complex argument. */
1573 gfc_check_fn_rc (gfc_expr
*a
)
1575 if (real_or_complex_check (a
, 0) == FAILURE
)
1583 gfc_check_fn_rc2008 (gfc_expr
*a
)
1585 if (real_or_complex_check (a
, 0) == FAILURE
)
1588 if (a
->ts
.type
== BT_COMPLEX
1589 && gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: COMPLEX argument '%s' "
1590 "argument of '%s' intrinsic at %L",
1591 gfc_current_intrinsic_arg
[0]->name
,
1592 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
1600 gfc_check_fnum (gfc_expr
*unit
)
1602 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
1605 if (scalar_check (unit
, 0) == FAILURE
)
1613 gfc_check_huge (gfc_expr
*x
)
1615 if (int_or_real_check (x
, 0) == FAILURE
)
1623 gfc_check_hypot (gfc_expr
*x
, gfc_expr
*y
)
1625 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
1627 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
1634 /* Check that the single argument is an integer. */
1637 gfc_check_i (gfc_expr
*i
)
1639 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1647 gfc_check_iand (gfc_expr
*i
, gfc_expr
*j
)
1649 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1652 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1655 if (i
->ts
.kind
!= j
->ts
.kind
)
1657 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1658 &i
->where
) == FAILURE
)
1667 gfc_check_ibits (gfc_expr
*i
, gfc_expr
*pos
, gfc_expr
*len
)
1669 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1672 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
1675 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
1678 if (nonnegative_check ("pos", pos
) == FAILURE
)
1681 if (nonnegative_check ("len", len
) == FAILURE
)
1684 if (less_than_bitsize2 ("i", i
, "pos", pos
, "len", len
) == FAILURE
)
1692 gfc_check_ichar_iachar (gfc_expr
*c
, gfc_expr
*kind
)
1696 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
1699 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1702 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1703 "with KIND argument at %L",
1704 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1707 if (c
->expr_type
== EXPR_VARIABLE
|| c
->expr_type
== EXPR_SUBSTRING
)
1713 /* Substring references don't have the charlength set. */
1715 while (ref
&& ref
->type
!= REF_SUBSTRING
)
1718 gcc_assert (ref
== NULL
|| ref
->type
== REF_SUBSTRING
);
1722 /* Check that the argument is length one. Non-constant lengths
1723 can't be checked here, so assume they are ok. */
1724 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
)
1726 /* If we already have a length for this expression then use it. */
1727 if (c
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
1729 i
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
1736 start
= ref
->u
.ss
.start
;
1737 end
= ref
->u
.ss
.end
;
1740 if (end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
1741 || start
->expr_type
!= EXPR_CONSTANT
)
1744 i
= mpz_get_si (end
->value
.integer
) + 1
1745 - mpz_get_si (start
->value
.integer
);
1753 gfc_error ("Argument of %s at %L must be of length one",
1754 gfc_current_intrinsic
, &c
->where
);
1763 gfc_check_idnint (gfc_expr
*a
)
1765 if (double_check (a
, 0) == FAILURE
)
1773 gfc_check_ieor (gfc_expr
*i
, gfc_expr
*j
)
1775 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1778 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1781 if (i
->ts
.kind
!= j
->ts
.kind
)
1783 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1784 &i
->where
) == FAILURE
)
1793 gfc_check_index (gfc_expr
*string
, gfc_expr
*substring
, gfc_expr
*back
,
1796 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
1797 || type_check (substring
, 1, BT_CHARACTER
) == FAILURE
)
1800 if (back
!= NULL
&& type_check (back
, 2, BT_LOGICAL
) == FAILURE
)
1803 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
1805 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1806 "with KIND argument at %L",
1807 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1810 if (string
->ts
.kind
!= substring
->ts
.kind
)
1812 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1813 "kind as '%s'", gfc_current_intrinsic_arg
[1]->name
,
1814 gfc_current_intrinsic
, &substring
->where
,
1815 gfc_current_intrinsic_arg
[0]->name
);
1824 gfc_check_int (gfc_expr
*x
, gfc_expr
*kind
)
1826 if (numeric_check (x
, 0) == FAILURE
)
1829 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1837 gfc_check_intconv (gfc_expr
*x
)
1839 if (numeric_check (x
, 0) == FAILURE
)
1847 gfc_check_ior (gfc_expr
*i
, gfc_expr
*j
)
1849 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1852 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1855 if (i
->ts
.kind
!= j
->ts
.kind
)
1857 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type kinds at %L",
1858 &i
->where
) == FAILURE
)
1867 gfc_check_ishft (gfc_expr
*i
, gfc_expr
*shift
)
1869 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
1870 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1878 gfc_check_ishftc (gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
1880 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
1881 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1884 if (size
!= NULL
&& type_check (size
, 2, BT_INTEGER
) == FAILURE
)
1892 gfc_check_kill (gfc_expr
*pid
, gfc_expr
*sig
)
1894 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
1897 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
1905 gfc_check_kill_sub (gfc_expr
*pid
, gfc_expr
*sig
, gfc_expr
*status
)
1907 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
1910 if (scalar_check (pid
, 0) == FAILURE
)
1913 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
1916 if (scalar_check (sig
, 1) == FAILURE
)
1922 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1925 if (scalar_check (status
, 2) == FAILURE
)
1933 gfc_check_kind (gfc_expr
*x
)
1935 if (x
->ts
.type
== BT_DERIVED
)
1937 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
1938 "non-derived type", gfc_current_intrinsic_arg
[0]->name
,
1939 gfc_current_intrinsic
, &x
->where
);
1948 gfc_check_lbound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
1950 if (array_check (array
, 0) == FAILURE
)
1953 if (dim_check (dim
, 1, false) == FAILURE
)
1956 if (dim_rank_check (dim
, array
, 1) == FAILURE
)
1959 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1961 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
1962 "with KIND argument at %L",
1963 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1971 gfc_check_lcobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
1973 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
1975 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
1979 if (coarray_check (coarray
, 0) == FAILURE
)
1984 if (dim_check (dim
, 1, false) == FAILURE
)
1987 if (dim_corank_check (dim
, coarray
) == FAILURE
)
1991 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1999 gfc_check_len_lentrim (gfc_expr
*s
, gfc_expr
*kind
)
2001 if (type_check (s
, 0, BT_CHARACTER
) == FAILURE
)
2004 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
2006 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
2007 "with KIND argument at %L",
2008 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
2016 gfc_check_lge_lgt_lle_llt (gfc_expr
*a
, gfc_expr
*b
)
2018 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
2020 if (kind_value_check (a
, 0, gfc_default_character_kind
) == FAILURE
)
2023 if (type_check (b
, 1, BT_CHARACTER
) == FAILURE
)
2025 if (kind_value_check (b
, 1, gfc_default_character_kind
) == FAILURE
)
2033 gfc_check_link (gfc_expr
*path1
, gfc_expr
*path2
)
2035 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2037 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2040 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2042 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2050 gfc_check_link_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2052 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2054 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2057 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2059 if (kind_value_check (path2
, 0, gfc_default_character_kind
) == FAILURE
)
2065 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2068 if (scalar_check (status
, 2) == FAILURE
)
2076 gfc_check_loc (gfc_expr
*expr
)
2078 return variable_check (expr
, 0, true);
2083 gfc_check_symlnk (gfc_expr
*path1
, gfc_expr
*path2
)
2085 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2087 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2090 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2092 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2100 gfc_check_symlnk_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2102 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2104 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2107 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2109 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2115 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2118 if (scalar_check (status
, 2) == FAILURE
)
2126 gfc_check_logical (gfc_expr
*a
, gfc_expr
*kind
)
2128 if (type_check (a
, 0, BT_LOGICAL
) == FAILURE
)
2130 if (kind_check (kind
, 1, BT_LOGICAL
) == FAILURE
)
2137 /* Min/max family. */
2140 min_max_args (gfc_actual_arglist
*arg
)
2142 if (arg
== NULL
|| arg
->next
== NULL
)
2144 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
2145 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
2154 check_rest (bt type
, int kind
, gfc_actual_arglist
*arglist
)
2156 gfc_actual_arglist
*arg
, *tmp
;
2161 if (min_max_args (arglist
) == FAILURE
)
2164 for (arg
= arglist
, n
=1; arg
; arg
= arg
->next
, n
++)
2167 if (x
->ts
.type
!= type
|| x
->ts
.kind
!= kind
)
2169 if (x
->ts
.type
== type
)
2171 if (gfc_notify_std (GFC_STD_GNU
, "Extension: Different type "
2172 "kinds at %L", &x
->where
) == FAILURE
)
2177 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
2178 "%s(%d)", n
, gfc_current_intrinsic
, &x
->where
,
2179 gfc_basic_typename (type
), kind
);
2184 for (tmp
= arglist
, m
=1; tmp
!= arg
; tmp
= tmp
->next
, m
++)
2185 if (gfc_check_conformance (tmp
->expr
, x
,
2186 "arguments 'a%d' and 'a%d' for "
2187 "intrinsic '%s'", m
, n
,
2188 gfc_current_intrinsic
) == FAILURE
)
2197 gfc_check_min_max (gfc_actual_arglist
*arg
)
2201 if (min_max_args (arg
) == FAILURE
)
2206 if (x
->ts
.type
== BT_CHARACTER
)
2208 if (gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
2209 "with CHARACTER argument at %L",
2210 gfc_current_intrinsic
, &x
->where
) == FAILURE
)
2213 else if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
2215 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
2216 "REAL or CHARACTER", gfc_current_intrinsic
, &x
->where
);
2220 return check_rest (x
->ts
.type
, x
->ts
.kind
, arg
);
2225 gfc_check_min_max_integer (gfc_actual_arglist
*arg
)
2227 return check_rest (BT_INTEGER
, gfc_default_integer_kind
, arg
);
2232 gfc_check_min_max_real (gfc_actual_arglist
*arg
)
2234 return check_rest (BT_REAL
, gfc_default_real_kind
, arg
);
2239 gfc_check_min_max_double (gfc_actual_arglist
*arg
)
2241 return check_rest (BT_REAL
, gfc_default_double_kind
, arg
);
2245 /* End of min/max family. */
2248 gfc_check_malloc (gfc_expr
*size
)
2250 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
2253 if (scalar_check (size
, 0) == FAILURE
)
2261 gfc_check_matmul (gfc_expr
*matrix_a
, gfc_expr
*matrix_b
)
2263 if ((matrix_a
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_a
->ts
))
2265 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2266 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
2267 gfc_current_intrinsic
, &matrix_a
->where
);
2271 if ((matrix_b
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_b
->ts
))
2273 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2274 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
2275 gfc_current_intrinsic
, &matrix_b
->where
);
2279 if ((matrix_a
->ts
.type
== BT_LOGICAL
&& gfc_numeric_ts (&matrix_b
->ts
))
2280 || (gfc_numeric_ts (&matrix_a
->ts
) && matrix_b
->ts
.type
== BT_LOGICAL
))
2282 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2283 gfc_current_intrinsic
, &matrix_a
->where
,
2284 gfc_typename(&matrix_a
->ts
), gfc_typename(&matrix_b
->ts
));
2288 switch (matrix_a
->rank
)
2291 if (rank_check (matrix_b
, 1, 2) == FAILURE
)
2293 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2294 if (!identical_dimen_shape (matrix_a
, 0, matrix_b
, 0))
2296 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2297 "and '%s' at %L for intrinsic matmul",
2298 gfc_current_intrinsic_arg
[0]->name
,
2299 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
2305 if (matrix_b
->rank
!= 2)
2307 if (rank_check (matrix_b
, 1, 1) == FAILURE
)
2310 /* matrix_b has rank 1 or 2 here. Common check for the cases
2311 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2312 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2313 if (!identical_dimen_shape (matrix_a
, 1, matrix_b
, 0))
2315 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2316 "dimension 1 for argument '%s' at %L for intrinsic "
2317 "matmul", gfc_current_intrinsic_arg
[0]->name
,
2318 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
2324 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2325 "1 or 2", gfc_current_intrinsic_arg
[0]->name
,
2326 gfc_current_intrinsic
, &matrix_a
->where
);
2334 /* Whoever came up with this interface was probably on something.
2335 The possibilities for the occupation of the second and third
2342 NULL MASK minloc(array, mask=m)
2345 I.e. in the case of minloc(array,mask), mask will be in the second
2346 position of the argument list and we'll have to fix that up. */
2349 gfc_check_minloc_maxloc (gfc_actual_arglist
*ap
)
2351 gfc_expr
*a
, *m
, *d
;
2354 if (int_or_real_check (a
, 0) == FAILURE
|| array_check (a
, 0) == FAILURE
)
2358 m
= ap
->next
->next
->expr
;
2360 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2361 && ap
->next
->name
== NULL
)
2365 ap
->next
->expr
= NULL
;
2366 ap
->next
->next
->expr
= m
;
2369 if (dim_check (d
, 1, false) == FAILURE
)
2372 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2375 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2379 && gfc_check_conformance (a
, m
,
2380 "arguments '%s' and '%s' for intrinsic %s",
2381 gfc_current_intrinsic_arg
[0]->name
,
2382 gfc_current_intrinsic_arg
[2]->name
,
2383 gfc_current_intrinsic
) == FAILURE
)
2390 /* Similar to minloc/maxloc, the argument list might need to be
2391 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2392 difference is that MINLOC/MAXLOC take an additional KIND argument.
2393 The possibilities are:
2399 NULL MASK minval(array, mask=m)
2402 I.e. in the case of minval(array,mask), mask will be in the second
2403 position of the argument list and we'll have to fix that up. */
2406 check_reduction (gfc_actual_arglist
*ap
)
2408 gfc_expr
*a
, *m
, *d
;
2412 m
= ap
->next
->next
->expr
;
2414 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2415 && ap
->next
->name
== NULL
)
2419 ap
->next
->expr
= NULL
;
2420 ap
->next
->next
->expr
= m
;
2423 if (dim_check (d
, 1, false) == FAILURE
)
2426 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2429 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2433 && gfc_check_conformance (a
, m
,
2434 "arguments '%s' and '%s' for intrinsic %s",
2435 gfc_current_intrinsic_arg
[0]->name
,
2436 gfc_current_intrinsic_arg
[2]->name
,
2437 gfc_current_intrinsic
) == FAILURE
)
2445 gfc_check_minval_maxval (gfc_actual_arglist
*ap
)
2447 if (int_or_real_check (ap
->expr
, 0) == FAILURE
2448 || array_check (ap
->expr
, 0) == FAILURE
)
2451 return check_reduction (ap
);
2456 gfc_check_product_sum (gfc_actual_arglist
*ap
)
2458 if (numeric_check (ap
->expr
, 0) == FAILURE
2459 || array_check (ap
->expr
, 0) == FAILURE
)
2462 return check_reduction (ap
);
2466 /* For IANY, IALL and IPARITY. */
2469 gfc_check_mask (gfc_expr
*i
, gfc_expr
*kind
)
2473 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
2476 if (nonnegative_check ("I", i
) == FAILURE
)
2479 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
2483 gfc_extract_int (kind
, &k
);
2485 k
= gfc_default_integer_kind
;
2487 if (less_than_bitsizekind ("I", i
, k
) == FAILURE
)
2495 gfc_check_transf_bit_intrins (gfc_actual_arglist
*ap
)
2497 if (ap
->expr
->ts
.type
!= BT_INTEGER
)
2499 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER",
2500 gfc_current_intrinsic_arg
[0]->name
,
2501 gfc_current_intrinsic
, &ap
->expr
->where
);
2505 if (array_check (ap
->expr
, 0) == FAILURE
)
2508 return check_reduction (ap
);
2513 gfc_check_merge (gfc_expr
*tsource
, gfc_expr
*fsource
, gfc_expr
*mask
)
2515 if (same_type_check (tsource
, 0, fsource
, 1) == FAILURE
)
2518 if (type_check (mask
, 2, BT_LOGICAL
) == FAILURE
)
2521 if (tsource
->ts
.type
== BT_CHARACTER
)
2522 return gfc_check_same_strlen (tsource
, fsource
, "MERGE intrinsic");
2529 gfc_check_merge_bits (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*mask
)
2531 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
2534 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
2537 if (type_check (mask
, 2, BT_INTEGER
) == FAILURE
)
2540 if (same_type_check (i
, 0, j
, 1) == FAILURE
)
2543 if (same_type_check (i
, 0, mask
, 2) == FAILURE
)
2551 gfc_check_move_alloc (gfc_expr
*from
, gfc_expr
*to
)
2553 if (variable_check (from
, 0, false) == FAILURE
)
2555 if (allocatable_check (from
, 0) == FAILURE
)
2558 if (variable_check (to
, 1, false) == FAILURE
)
2560 if (allocatable_check (to
, 1) == FAILURE
)
2563 if (same_type_check (to
, 1, from
, 0) == FAILURE
)
2566 if (to
->rank
!= from
->rank
)
2568 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2569 "have the same rank %d/%d", gfc_current_intrinsic_arg
[0]->name
,
2570 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2571 &to
->where
, from
->rank
, to
->rank
);
2575 if (to
->ts
.kind
!= from
->ts
.kind
)
2577 gfc_error ("the '%s' and '%s' arguments of '%s' intrinsic at %L must "
2578 "be of the same kind %d/%d",
2579 gfc_current_intrinsic_arg
[0]->name
,
2580 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2581 &to
->where
, from
->ts
.kind
, to
->ts
.kind
);
2590 gfc_check_nearest (gfc_expr
*x
, gfc_expr
*s
)
2592 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
2595 if (type_check (s
, 1, BT_REAL
) == FAILURE
)
2603 gfc_check_new_line (gfc_expr
*a
)
2605 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
2613 gfc_check_norm2 (gfc_expr
*array
, gfc_expr
*dim
)
2615 if (type_check (array
, 0, BT_REAL
) == FAILURE
)
2618 if (array_check (array
, 0) == FAILURE
)
2621 if (dim_rank_check (dim
, array
, false) == FAILURE
)
2628 gfc_check_null (gfc_expr
*mold
)
2630 symbol_attribute attr
;
2635 if (variable_check (mold
, 0, true) == FAILURE
)
2638 attr
= gfc_variable_attr (mold
, NULL
);
2640 if (!attr
.pointer
&& !attr
.proc_pointer
)
2642 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
2643 gfc_current_intrinsic_arg
[0]->name
,
2644 gfc_current_intrinsic
, &mold
->where
);
2653 gfc_check_pack (gfc_expr
*array
, gfc_expr
*mask
, gfc_expr
*vector
)
2655 if (array_check (array
, 0) == FAILURE
)
2658 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
2661 if (gfc_check_conformance (array
, mask
,
2662 "arguments '%s' and '%s' for intrinsic '%s'",
2663 gfc_current_intrinsic_arg
[0]->name
,
2664 gfc_current_intrinsic_arg
[1]->name
,
2665 gfc_current_intrinsic
) == FAILURE
)
2670 mpz_t array_size
, vector_size
;
2671 bool have_array_size
, have_vector_size
;
2673 if (same_type_check (array
, 0, vector
, 2) == FAILURE
)
2676 if (rank_check (vector
, 2, 1) == FAILURE
)
2679 /* VECTOR requires at least as many elements as MASK
2680 has .TRUE. values. */
2681 have_array_size
= gfc_array_size (array
, &array_size
) == SUCCESS
;
2682 have_vector_size
= gfc_array_size (vector
, &vector_size
) == SUCCESS
;
2684 if (have_vector_size
2685 && (mask
->expr_type
== EXPR_ARRAY
2686 || (mask
->expr_type
== EXPR_CONSTANT
2687 && have_array_size
)))
2689 int mask_true_values
= 0;
2691 if (mask
->expr_type
== EXPR_ARRAY
)
2693 gfc_constructor
*mask_ctor
;
2694 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
2697 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
2699 mask_true_values
= 0;
2703 if (mask_ctor
->expr
->value
.logical
)
2706 mask_ctor
= gfc_constructor_next (mask_ctor
);
2709 else if (mask
->expr_type
== EXPR_CONSTANT
&& mask
->value
.logical
)
2710 mask_true_values
= mpz_get_si (array_size
);
2712 if (mpz_get_si (vector_size
) < mask_true_values
)
2714 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2715 "provide at least as many elements as there "
2716 "are .TRUE. values in '%s' (%ld/%d)",
2717 gfc_current_intrinsic_arg
[2]->name
,
2718 gfc_current_intrinsic
, &vector
->where
,
2719 gfc_current_intrinsic_arg
[1]->name
,
2720 mpz_get_si (vector_size
), mask_true_values
);
2725 if (have_array_size
)
2726 mpz_clear (array_size
);
2727 if (have_vector_size
)
2728 mpz_clear (vector_size
);
2736 gfc_check_parity (gfc_expr
*mask
, gfc_expr
*dim
)
2738 if (type_check (mask
, 0, BT_LOGICAL
) == FAILURE
)
2741 if (array_check (mask
, 0) == FAILURE
)
2744 if (dim_rank_check (dim
, mask
, false) == FAILURE
)
2752 gfc_check_precision (gfc_expr
*x
)
2754 if (real_or_complex_check (x
, 0) == FAILURE
)
2762 gfc_check_present (gfc_expr
*a
)
2766 if (variable_check (a
, 0, true) == FAILURE
)
2769 sym
= a
->symtree
->n
.sym
;
2770 if (!sym
->attr
.dummy
)
2772 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
2773 "dummy variable", gfc_current_intrinsic_arg
[0]->name
,
2774 gfc_current_intrinsic
, &a
->where
);
2778 if (!sym
->attr
.optional
)
2780 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
2781 "an OPTIONAL dummy variable",
2782 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
2787 /* 13.14.82 PRESENT(A)
2789 Argument. A shall be the name of an optional dummy argument that is
2790 accessible in the subprogram in which the PRESENT function reference
2794 && !(a
->ref
->next
== NULL
&& a
->ref
->type
== REF_ARRAY
2795 && a
->ref
->u
.ar
.type
== AR_FULL
))
2797 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
2798 "subobject of '%s'", gfc_current_intrinsic_arg
[0]->name
,
2799 gfc_current_intrinsic
, &a
->where
, sym
->name
);
2808 gfc_check_radix (gfc_expr
*x
)
2810 if (int_or_real_check (x
, 0) == FAILURE
)
2818 gfc_check_range (gfc_expr
*x
)
2820 if (numeric_check (x
, 0) == FAILURE
)
2827 /* real, float, sngl. */
2829 gfc_check_real (gfc_expr
*a
, gfc_expr
*kind
)
2831 if (numeric_check (a
, 0) == FAILURE
)
2834 if (kind_check (kind
, 1, BT_REAL
) == FAILURE
)
2842 gfc_check_rename (gfc_expr
*path1
, gfc_expr
*path2
)
2844 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2846 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2849 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2851 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2859 gfc_check_rename_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2861 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2863 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2866 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2868 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2874 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2877 if (scalar_check (status
, 2) == FAILURE
)
2885 gfc_check_repeat (gfc_expr
*x
, gfc_expr
*y
)
2887 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
2890 if (scalar_check (x
, 0) == FAILURE
)
2893 if (type_check (y
, 0, BT_INTEGER
) == FAILURE
)
2896 if (scalar_check (y
, 1) == FAILURE
)
2904 gfc_check_reshape (gfc_expr
*source
, gfc_expr
*shape
,
2905 gfc_expr
*pad
, gfc_expr
*order
)
2911 if (array_check (source
, 0) == FAILURE
)
2914 if (rank_check (shape
, 1, 1) == FAILURE
)
2917 if (type_check (shape
, 1, BT_INTEGER
) == FAILURE
)
2920 if (gfc_array_size (shape
, &size
) != SUCCESS
)
2922 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
2923 "array of constant size", &shape
->where
);
2927 shape_size
= mpz_get_ui (size
);
2930 if (shape_size
<= 0)
2932 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
2933 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2937 else if (shape_size
> GFC_MAX_DIMENSIONS
)
2939 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
2940 "than %d elements", &shape
->where
, GFC_MAX_DIMENSIONS
);
2943 else if (shape
->expr_type
== EXPR_ARRAY
)
2947 for (i
= 0; i
< shape_size
; ++i
)
2949 e
= gfc_constructor_lookup_expr (shape
->value
.constructor
, i
);
2950 if (e
->expr_type
!= EXPR_CONSTANT
)
2953 gfc_extract_int (e
, &extent
);
2956 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
2957 "negative element (%d)",
2958 gfc_current_intrinsic_arg
[1]->name
,
2959 gfc_current_intrinsic
, &e
->where
, extent
);
2967 if (same_type_check (source
, 0, pad
, 2) == FAILURE
)
2970 if (array_check (pad
, 2) == FAILURE
)
2976 if (array_check (order
, 3) == FAILURE
)
2979 if (type_check (order
, 3, BT_INTEGER
) == FAILURE
)
2982 if (order
->expr_type
== EXPR_ARRAY
)
2984 int i
, order_size
, dim
, perm
[GFC_MAX_DIMENSIONS
];
2987 for (i
= 0; i
< GFC_MAX_DIMENSIONS
; ++i
)
2990 gfc_array_size (order
, &size
);
2991 order_size
= mpz_get_ui (size
);
2994 if (order_size
!= shape_size
)
2996 gfc_error ("'%s' argument of '%s' intrinsic at %L "
2997 "has wrong number of elements (%d/%d)",
2998 gfc_current_intrinsic_arg
[3]->name
,
2999 gfc_current_intrinsic
, &order
->where
,
3000 order_size
, shape_size
);
3004 for (i
= 1; i
<= order_size
; ++i
)
3006 e
= gfc_constructor_lookup_expr (order
->value
.constructor
, i
-1);
3007 if (e
->expr_type
!= EXPR_CONSTANT
)
3010 gfc_extract_int (e
, &dim
);
3012 if (dim
< 1 || dim
> order_size
)
3014 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3015 "has out-of-range dimension (%d)",
3016 gfc_current_intrinsic_arg
[3]->name
,
3017 gfc_current_intrinsic
, &e
->where
, dim
);
3021 if (perm
[dim
-1] != 0)
3023 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3024 "invalid permutation of dimensions (dimension "
3026 gfc_current_intrinsic_arg
[3]->name
,
3027 gfc_current_intrinsic
, &e
->where
, dim
);
3036 if (pad
== NULL
&& shape
->expr_type
== EXPR_ARRAY
3037 && gfc_is_constant_expr (shape
)
3038 && !(source
->expr_type
== EXPR_VARIABLE
&& source
->symtree
->n
.sym
->as
3039 && source
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
))
3041 /* Check the match in size between source and destination. */
3042 if (gfc_array_size (source
, &nelems
) == SUCCESS
)
3048 mpz_init_set_ui (size
, 1);
3049 for (c
= gfc_constructor_first (shape
->value
.constructor
);
3050 c
; c
= gfc_constructor_next (c
))
3051 mpz_mul (size
, size
, c
->expr
->value
.integer
);
3053 test
= mpz_cmp (nelems
, size
) < 0 && mpz_cmp_ui (size
, 0) > 0;
3059 gfc_error ("Without padding, there are not enough elements "
3060 "in the intrinsic RESHAPE source at %L to match "
3061 "the shape", &source
->where
);
3072 gfc_check_same_type_as (gfc_expr
*a
, gfc_expr
*b
)
3075 if (a
->ts
.type
!= BT_DERIVED
&& a
->ts
.type
!= BT_CLASS
)
3077 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3078 "must be of a derived type",
3079 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3084 if (!gfc_type_is_extensible (a
->ts
.u
.derived
))
3086 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3087 "must be of an extensible type",
3088 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3093 if (b
->ts
.type
!= BT_DERIVED
&& b
->ts
.type
!= BT_CLASS
)
3095 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3096 "must be of a derived type",
3097 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3102 if (!gfc_type_is_extensible (b
->ts
.u
.derived
))
3104 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3105 "must be of an extensible type",
3106 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3116 gfc_check_scale (gfc_expr
*x
, gfc_expr
*i
)
3118 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3121 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
3129 gfc_check_scan (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
3131 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3134 if (type_check (y
, 1, BT_CHARACTER
) == FAILURE
)
3137 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
3140 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
3142 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3143 "with KIND argument at %L",
3144 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3147 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
3155 gfc_check_secnds (gfc_expr
*r
)
3157 if (type_check (r
, 0, BT_REAL
) == FAILURE
)
3160 if (kind_value_check (r
, 0, 4) == FAILURE
)
3163 if (scalar_check (r
, 0) == FAILURE
)
3171 gfc_check_selected_char_kind (gfc_expr
*name
)
3173 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3176 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3179 if (scalar_check (name
, 0) == FAILURE
)
3187 gfc_check_selected_int_kind (gfc_expr
*r
)
3189 if (type_check (r
, 0, BT_INTEGER
) == FAILURE
)
3192 if (scalar_check (r
, 0) == FAILURE
)
3200 gfc_check_selected_real_kind (gfc_expr
*p
, gfc_expr
*r
, gfc_expr
*radix
)
3202 if (p
== NULL
&& r
== NULL
3203 && gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: SELECTED_REAL_KIND with"
3204 " neither 'P' nor 'R' argument at %L",
3205 gfc_current_intrinsic_where
) == FAILURE
)
3210 if (type_check (p
, 0, BT_INTEGER
) == FAILURE
)
3213 if (scalar_check (p
, 0) == FAILURE
)
3219 if (type_check (r
, 1, BT_INTEGER
) == FAILURE
)
3222 if (scalar_check (r
, 1) == FAILURE
)
3228 if (type_check (radix
, 1, BT_INTEGER
) == FAILURE
)
3231 if (scalar_check (radix
, 1) == FAILURE
)
3234 if (gfc_notify_std (GFC_STD_F2008
, "Fortran 2008: '%s' intrinsic with "
3235 "RADIX argument at %L", gfc_current_intrinsic
,
3236 &radix
->where
) == FAILURE
)
3245 gfc_check_set_exponent (gfc_expr
*x
, gfc_expr
*i
)
3247 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3250 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
3258 gfc_check_shape (gfc_expr
*source
, gfc_expr
*kind
)
3262 if (source
->rank
== 0 || source
->expr_type
!= EXPR_VARIABLE
)
3265 ar
= gfc_find_array_ref (source
);
3267 if (ar
->as
&& ar
->as
->type
== AS_ASSUMED_SIZE
&& ar
->type
== AR_FULL
)
3269 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
3270 "an assumed size array", &source
->where
);
3274 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
3276 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3277 "with KIND argument at %L",
3278 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3286 gfc_check_shift (gfc_expr
*i
, gfc_expr
*shift
)
3288 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
3291 if (type_check (shift
, 0, BT_INTEGER
) == FAILURE
)
3294 if (nonnegative_check ("SHIFT", shift
) == FAILURE
)
3297 if (less_than_bitsize1 ("I", i
, "SHIFT", shift
, true) == FAILURE
)
3305 gfc_check_sign (gfc_expr
*a
, gfc_expr
*b
)
3307 if (int_or_real_check (a
, 0) == FAILURE
)
3310 if (same_type_check (a
, 0, b
, 1) == FAILURE
)
3318 gfc_check_size (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
3320 if (array_check (array
, 0) == FAILURE
)
3323 if (dim_check (dim
, 1, true) == FAILURE
)
3326 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
3329 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3331 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3332 "with KIND argument at %L",
3333 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3342 gfc_check_sizeof (gfc_expr
*arg ATTRIBUTE_UNUSED
)
3349 gfc_check_c_sizeof (gfc_expr
*arg
)
3351 if (verify_c_interop (&arg
->ts
) != SUCCESS
)
3353 gfc_error ("'%s' argument of '%s' intrinsic at %L must be be an "
3354 "interoperable data entity",
3355 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3364 gfc_check_sleep_sub (gfc_expr
*seconds
)
3366 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
3369 if (scalar_check (seconds
, 0) == FAILURE
)
3376 gfc_check_sngl (gfc_expr
*a
)
3378 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
3381 if ((a
->ts
.kind
!= gfc_default_double_kind
)
3382 && gfc_notify_std (GFC_STD_GNU
, "GNU extension: non double precision "
3383 "REAL argument to %s intrinsic at %L",
3384 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
3391 gfc_check_spread (gfc_expr
*source
, gfc_expr
*dim
, gfc_expr
*ncopies
)
3393 if (source
->rank
>= GFC_MAX_DIMENSIONS
)
3395 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
3396 "than rank %d", gfc_current_intrinsic_arg
[0]->name
,
3397 gfc_current_intrinsic
, &source
->where
, GFC_MAX_DIMENSIONS
);
3405 if (dim_check (dim
, 1, false) == FAILURE
)
3408 /* dim_rank_check() does not apply here. */
3410 && dim
->expr_type
== EXPR_CONSTANT
3411 && (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
3412 || mpz_cmp_ui (dim
->value
.integer
, source
->rank
+ 1) > 0))
3414 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
3415 "dimension index", gfc_current_intrinsic_arg
[1]->name
,
3416 gfc_current_intrinsic
, &dim
->where
);
3420 if (type_check (ncopies
, 2, BT_INTEGER
) == FAILURE
)
3423 if (scalar_check (ncopies
, 2) == FAILURE
)
3430 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3434 gfc_check_fgetputc_sub (gfc_expr
*unit
, gfc_expr
*c
, gfc_expr
*status
)
3436 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3439 if (scalar_check (unit
, 0) == FAILURE
)
3442 if (type_check (c
, 1, BT_CHARACTER
) == FAILURE
)
3444 if (kind_value_check (c
, 1, gfc_default_character_kind
) == FAILURE
)
3450 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3451 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
3452 || scalar_check (status
, 2) == FAILURE
)
3460 gfc_check_fgetputc (gfc_expr
*unit
, gfc_expr
*c
)
3462 return gfc_check_fgetputc_sub (unit
, c
, NULL
);
3467 gfc_check_fgetput_sub (gfc_expr
*c
, gfc_expr
*status
)
3469 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
3471 if (kind_value_check (c
, 0, gfc_default_character_kind
) == FAILURE
)
3477 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
3478 || kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
3479 || scalar_check (status
, 1) == FAILURE
)
3487 gfc_check_fgetput (gfc_expr
*c
)
3489 return gfc_check_fgetput_sub (c
, NULL
);
3494 gfc_check_fseek_sub (gfc_expr
*unit
, gfc_expr
*offset
, gfc_expr
*whence
, gfc_expr
*status
)
3496 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3499 if (scalar_check (unit
, 0) == FAILURE
)
3502 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3505 if (scalar_check (offset
, 1) == FAILURE
)
3508 if (type_check (whence
, 2, BT_INTEGER
) == FAILURE
)
3511 if (scalar_check (whence
, 2) == FAILURE
)
3517 if (type_check (status
, 3, BT_INTEGER
) == FAILURE
)
3520 if (kind_value_check (status
, 3, 4) == FAILURE
)
3523 if (scalar_check (status
, 3) == FAILURE
)
3532 gfc_check_fstat (gfc_expr
*unit
, gfc_expr
*array
)
3534 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3537 if (scalar_check (unit
, 0) == FAILURE
)
3540 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3541 || kind_value_check (unit
, 0, gfc_default_integer_kind
) == FAILURE
)
3544 if (array_check (array
, 1) == FAILURE
)
3552 gfc_check_fstat_sub (gfc_expr
*unit
, gfc_expr
*array
, gfc_expr
*status
)
3554 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3557 if (scalar_check (unit
, 0) == FAILURE
)
3560 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3561 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3564 if (array_check (array
, 1) == FAILURE
)
3570 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3571 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
3574 if (scalar_check (status
, 2) == FAILURE
)
3582 gfc_check_ftell (gfc_expr
*unit
)
3584 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3587 if (scalar_check (unit
, 0) == FAILURE
)
3595 gfc_check_ftell_sub (gfc_expr
*unit
, gfc_expr
*offset
)
3597 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3600 if (scalar_check (unit
, 0) == FAILURE
)
3603 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3606 if (scalar_check (offset
, 1) == FAILURE
)
3614 gfc_check_stat (gfc_expr
*name
, gfc_expr
*array
)
3616 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3618 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3621 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3622 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3625 if (array_check (array
, 1) == FAILURE
)
3633 gfc_check_stat_sub (gfc_expr
*name
, gfc_expr
*array
, gfc_expr
*status
)
3635 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3637 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3640 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3641 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3644 if (array_check (array
, 1) == FAILURE
)
3650 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3651 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3654 if (scalar_check (status
, 2) == FAILURE
)
3662 gfc_check_image_index (gfc_expr
*coarray
, gfc_expr
*sub
)
3664 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3666 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3670 if (coarray_check (coarray
, 0) == FAILURE
)
3675 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3676 gfc_current_intrinsic_arg
[1]->name
, &sub
->where
);
3685 gfc_check_this_image (gfc_expr
*coarray
, gfc_expr
*dim
)
3687 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3689 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3693 if (dim
!= NULL
&& coarray
== NULL
)
3695 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3696 "intrinsic at %L", &dim
->where
);
3700 if (coarray
== NULL
)
3703 if (coarray_check (coarray
, 0) == FAILURE
)
3708 if (dim_check (dim
, 1, false) == FAILURE
)
3711 if (dim_corank_check (dim
, coarray
) == FAILURE
)
3720 gfc_check_transfer (gfc_expr
*source ATTRIBUTE_UNUSED
,
3721 gfc_expr
*mold ATTRIBUTE_UNUSED
, gfc_expr
*size
)
3723 if (mold
->ts
.type
== BT_HOLLERITH
)
3725 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
3726 &mold
->where
, gfc_basic_typename (BT_HOLLERITH
));
3732 if (type_check (size
, 2, BT_INTEGER
) == FAILURE
)
3735 if (scalar_check (size
, 2) == FAILURE
)
3738 if (nonoptional_check (size
, 2) == FAILURE
)
3747 gfc_check_transpose (gfc_expr
*matrix
)
3749 if (rank_check (matrix
, 0, 2) == FAILURE
)
3757 gfc_check_ubound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
3759 if (array_check (array
, 0) == FAILURE
)
3762 if (dim_check (dim
, 1, false) == FAILURE
)
3765 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
3768 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3770 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3771 "with KIND argument at %L",
3772 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3780 gfc_check_ucobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
3782 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3784 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3788 if (coarray_check (coarray
, 0) == FAILURE
)
3793 if (dim_check (dim
, 1, false) == FAILURE
)
3796 if (dim_corank_check (dim
, coarray
) == FAILURE
)
3800 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3808 gfc_check_unpack (gfc_expr
*vector
, gfc_expr
*mask
, gfc_expr
*field
)
3812 if (rank_check (vector
, 0, 1) == FAILURE
)
3815 if (array_check (mask
, 1) == FAILURE
)
3818 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
3821 if (same_type_check (vector
, 0, field
, 2) == FAILURE
)
3824 if (mask
->expr_type
== EXPR_ARRAY
3825 && gfc_array_size (vector
, &vector_size
) == SUCCESS
)
3827 int mask_true_count
= 0;
3828 gfc_constructor
*mask_ctor
;
3829 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
3832 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
3834 mask_true_count
= 0;
3838 if (mask_ctor
->expr
->value
.logical
)
3841 mask_ctor
= gfc_constructor_next (mask_ctor
);
3844 if (mpz_get_si (vector_size
) < mask_true_count
)
3846 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
3847 "provide at least as many elements as there "
3848 "are .TRUE. values in '%s' (%ld/%d)",
3849 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3850 &vector
->where
, gfc_current_intrinsic_arg
[1]->name
,
3851 mpz_get_si (vector_size
), mask_true_count
);
3855 mpz_clear (vector_size
);
3858 if (mask
->rank
!= field
->rank
&& field
->rank
!= 0)
3860 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
3861 "the same rank as '%s' or be a scalar",
3862 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
3863 &field
->where
, gfc_current_intrinsic_arg
[1]->name
);
3867 if (mask
->rank
== field
->rank
)
3870 for (i
= 0; i
< field
->rank
; i
++)
3871 if (! identical_dimen_shape (mask
, i
, field
, i
))
3873 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
3874 "must have identical shape.",
3875 gfc_current_intrinsic_arg
[2]->name
,
3876 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3886 gfc_check_verify (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
3888 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3891 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
3894 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
3897 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
3899 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' intrinsic "
3900 "with KIND argument at %L",
3901 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3909 gfc_check_trim (gfc_expr
*x
)
3911 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3914 if (scalar_check (x
, 0) == FAILURE
)
3922 gfc_check_ttynam (gfc_expr
*unit
)
3924 if (scalar_check (unit
, 0) == FAILURE
)
3927 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3934 /* Common check function for the half a dozen intrinsics that have a
3935 single real argument. */
3938 gfc_check_x (gfc_expr
*x
)
3940 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3947 /************* Check functions for intrinsic subroutines *************/
3950 gfc_check_cpu_time (gfc_expr
*time
)
3952 if (scalar_check (time
, 0) == FAILURE
)
3955 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
3958 if (variable_check (time
, 0, false) == FAILURE
)
3966 gfc_check_date_and_time (gfc_expr
*date
, gfc_expr
*time
,
3967 gfc_expr
*zone
, gfc_expr
*values
)
3971 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
3973 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
3975 if (scalar_check (date
, 0) == FAILURE
)
3977 if (variable_check (date
, 0, false) == FAILURE
)
3983 if (type_check (time
, 1, BT_CHARACTER
) == FAILURE
)
3985 if (kind_value_check (time
, 1, gfc_default_character_kind
) == FAILURE
)
3987 if (scalar_check (time
, 1) == FAILURE
)
3989 if (variable_check (time
, 1, false) == FAILURE
)
3995 if (type_check (zone
, 2, BT_CHARACTER
) == FAILURE
)
3997 if (kind_value_check (zone
, 2, gfc_default_character_kind
) == FAILURE
)
3999 if (scalar_check (zone
, 2) == FAILURE
)
4001 if (variable_check (zone
, 2, false) == FAILURE
)
4007 if (type_check (values
, 3, BT_INTEGER
) == FAILURE
)
4009 if (array_check (values
, 3) == FAILURE
)
4011 if (rank_check (values
, 3, 1) == FAILURE
)
4013 if (variable_check (values
, 3, false) == FAILURE
)
4022 gfc_check_mvbits (gfc_expr
*from
, gfc_expr
*frompos
, gfc_expr
*len
,
4023 gfc_expr
*to
, gfc_expr
*topos
)
4025 if (type_check (from
, 0, BT_INTEGER
) == FAILURE
)
4028 if (type_check (frompos
, 1, BT_INTEGER
) == FAILURE
)
4031 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
4034 if (same_type_check (from
, 0, to
, 3) == FAILURE
)
4037 if (variable_check (to
, 3, false) == FAILURE
)
4040 if (type_check (topos
, 4, BT_INTEGER
) == FAILURE
)
4043 if (nonnegative_check ("frompos", frompos
) == FAILURE
)
4046 if (nonnegative_check ("topos", topos
) == FAILURE
)
4049 if (nonnegative_check ("len", len
) == FAILURE
)
4052 if (less_than_bitsize2 ("from", from
, "frompos", frompos
, "len", len
)
4056 if (less_than_bitsize2 ("to", to
, "topos", topos
, "len", len
) == FAILURE
)
4064 gfc_check_random_number (gfc_expr
*harvest
)
4066 if (type_check (harvest
, 0, BT_REAL
) == FAILURE
)
4069 if (variable_check (harvest
, 0, false) == FAILURE
)
4077 gfc_check_random_seed (gfc_expr
*size
, gfc_expr
*put
, gfc_expr
*get
)
4079 unsigned int nargs
= 0, kiss_size
;
4080 locus
*where
= NULL
;
4081 mpz_t put_size
, get_size
;
4082 bool have_gfc_real_16
; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
4084 have_gfc_real_16
= gfc_validate_kind (BT_REAL
, 16, true) != -1;
4086 /* Keep the number of bytes in sync with kiss_size in
4087 libgfortran/intrinsics/random.c. */
4088 kiss_size
= (have_gfc_real_16
? 48 : 32) / gfc_default_integer_kind
;
4092 if (size
->expr_type
!= EXPR_VARIABLE
4093 || !size
->symtree
->n
.sym
->attr
.optional
)
4096 if (scalar_check (size
, 0) == FAILURE
)
4099 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
4102 if (variable_check (size
, 0, false) == FAILURE
)
4105 if (kind_value_check (size
, 0, gfc_default_integer_kind
) == FAILURE
)
4111 if (put
->expr_type
!= EXPR_VARIABLE
4112 || !put
->symtree
->n
.sym
->attr
.optional
)
4115 where
= &put
->where
;
4118 if (array_check (put
, 1) == FAILURE
)
4121 if (rank_check (put
, 1, 1) == FAILURE
)
4124 if (type_check (put
, 1, BT_INTEGER
) == FAILURE
)
4127 if (kind_value_check (put
, 1, gfc_default_integer_kind
) == FAILURE
)
4130 if (gfc_array_size (put
, &put_size
) == SUCCESS
4131 && mpz_get_ui (put_size
) < kiss_size
)
4132 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4133 "too small (%i/%i)",
4134 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4135 where
, (int) mpz_get_ui (put_size
), kiss_size
);
4140 if (get
->expr_type
!= EXPR_VARIABLE
4141 || !get
->symtree
->n
.sym
->attr
.optional
)
4144 where
= &get
->where
;
4147 if (array_check (get
, 2) == FAILURE
)
4150 if (rank_check (get
, 2, 1) == FAILURE
)
4153 if (type_check (get
, 2, BT_INTEGER
) == FAILURE
)
4156 if (variable_check (get
, 2, false) == FAILURE
)
4159 if (kind_value_check (get
, 2, gfc_default_integer_kind
) == FAILURE
)
4162 if (gfc_array_size (get
, &get_size
) == SUCCESS
4163 && mpz_get_ui (get_size
) < kiss_size
)
4164 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4165 "too small (%i/%i)",
4166 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
4167 where
, (int) mpz_get_ui (get_size
), kiss_size
);
4170 /* RANDOM_SEED may not have more than one non-optional argument. */
4172 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
, where
);
4179 gfc_check_second_sub (gfc_expr
*time
)
4181 if (scalar_check (time
, 0) == FAILURE
)
4184 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
4187 if (kind_value_check(time
, 0, 4) == FAILURE
)
4194 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
4195 count, count_rate, and count_max are all optional arguments */
4198 gfc_check_system_clock (gfc_expr
*count
, gfc_expr
*count_rate
,
4199 gfc_expr
*count_max
)
4203 if (scalar_check (count
, 0) == FAILURE
)
4206 if (type_check (count
, 0, BT_INTEGER
) == FAILURE
)
4209 if (variable_check (count
, 0, false) == FAILURE
)
4213 if (count_rate
!= NULL
)
4215 if (scalar_check (count_rate
, 1) == FAILURE
)
4218 if (type_check (count_rate
, 1, BT_INTEGER
) == FAILURE
)
4221 if (variable_check (count_rate
, 1, false) == FAILURE
)
4225 && same_type_check (count
, 0, count_rate
, 1) == FAILURE
)
4230 if (count_max
!= NULL
)
4232 if (scalar_check (count_max
, 2) == FAILURE
)
4235 if (type_check (count_max
, 2, BT_INTEGER
) == FAILURE
)
4238 if (variable_check (count_max
, 2, false) == FAILURE
)
4242 && same_type_check (count
, 0, count_max
, 2) == FAILURE
)
4245 if (count_rate
!= NULL
4246 && same_type_check (count_rate
, 1, count_max
, 2) == FAILURE
)
4255 gfc_check_irand (gfc_expr
*x
)
4260 if (scalar_check (x
, 0) == FAILURE
)
4263 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4266 if (kind_value_check(x
, 0, 4) == FAILURE
)
4274 gfc_check_alarm_sub (gfc_expr
*seconds
, gfc_expr
*handler
, gfc_expr
*status
)
4276 if (scalar_check (seconds
, 0) == FAILURE
)
4278 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
4281 if (int_or_proc_check (handler
, 1) == FAILURE
)
4283 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4289 if (scalar_check (status
, 2) == FAILURE
)
4291 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
4293 if (kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
4301 gfc_check_rand (gfc_expr
*x
)
4306 if (scalar_check (x
, 0) == FAILURE
)
4309 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4312 if (kind_value_check(x
, 0, 4) == FAILURE
)
4320 gfc_check_srand (gfc_expr
*x
)
4322 if (scalar_check (x
, 0) == FAILURE
)
4325 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4328 if (kind_value_check(x
, 0, 4) == FAILURE
)
4336 gfc_check_ctime_sub (gfc_expr
*time
, gfc_expr
*result
)
4338 if (scalar_check (time
, 0) == FAILURE
)
4340 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
4343 if (type_check (result
, 1, BT_CHARACTER
) == FAILURE
)
4345 if (kind_value_check (result
, 1, gfc_default_character_kind
) == FAILURE
)
4353 gfc_check_dtime_etime (gfc_expr
*x
)
4355 if (array_check (x
, 0) == FAILURE
)
4358 if (rank_check (x
, 0, 1) == FAILURE
)
4361 if (variable_check (x
, 0, false) == FAILURE
)
4364 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4367 if (kind_value_check(x
, 0, 4) == FAILURE
)
4375 gfc_check_dtime_etime_sub (gfc_expr
*values
, gfc_expr
*time
)
4377 if (array_check (values
, 0) == FAILURE
)
4380 if (rank_check (values
, 0, 1) == FAILURE
)
4383 if (variable_check (values
, 0, false) == FAILURE
)
4386 if (type_check (values
, 0, BT_REAL
) == FAILURE
)
4389 if (kind_value_check(values
, 0, 4) == FAILURE
)
4392 if (scalar_check (time
, 1) == FAILURE
)
4395 if (type_check (time
, 1, BT_REAL
) == FAILURE
)
4398 if (kind_value_check(time
, 1, 4) == FAILURE
)
4406 gfc_check_fdate_sub (gfc_expr
*date
)
4408 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
4410 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
4418 gfc_check_gerror (gfc_expr
*msg
)
4420 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
4422 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4430 gfc_check_getcwd_sub (gfc_expr
*cwd
, gfc_expr
*status
)
4432 if (type_check (cwd
, 0, BT_CHARACTER
) == FAILURE
)
4434 if (kind_value_check (cwd
, 0, gfc_default_character_kind
) == FAILURE
)
4440 if (scalar_check (status
, 1) == FAILURE
)
4443 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4451 gfc_check_getarg (gfc_expr
*pos
, gfc_expr
*value
)
4453 if (type_check (pos
, 0, BT_INTEGER
) == FAILURE
)
4456 if (pos
->ts
.kind
> gfc_default_integer_kind
)
4458 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4459 "not wider than the default kind (%d)",
4460 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4461 &pos
->where
, gfc_default_integer_kind
);
4465 if (type_check (value
, 1, BT_CHARACTER
) == FAILURE
)
4467 if (kind_value_check (value
, 1, gfc_default_character_kind
) == FAILURE
)
4475 gfc_check_getlog (gfc_expr
*msg
)
4477 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
4479 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4487 gfc_check_exit (gfc_expr
*status
)
4492 if (type_check (status
, 0, BT_INTEGER
) == FAILURE
)
4495 if (scalar_check (status
, 0) == FAILURE
)
4503 gfc_check_flush (gfc_expr
*unit
)
4508 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4511 if (scalar_check (unit
, 0) == FAILURE
)
4519 gfc_check_free (gfc_expr
*i
)
4521 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
4524 if (scalar_check (i
, 0) == FAILURE
)
4532 gfc_check_hostnm (gfc_expr
*name
)
4534 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4536 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4544 gfc_check_hostnm_sub (gfc_expr
*name
, gfc_expr
*status
)
4546 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4548 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4554 if (scalar_check (status
, 1) == FAILURE
)
4557 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4565 gfc_check_itime_idate (gfc_expr
*values
)
4567 if (array_check (values
, 0) == FAILURE
)
4570 if (rank_check (values
, 0, 1) == FAILURE
)
4573 if (variable_check (values
, 0, false) == FAILURE
)
4576 if (type_check (values
, 0, BT_INTEGER
) == FAILURE
)
4579 if (kind_value_check(values
, 0, gfc_default_integer_kind
) == FAILURE
)
4587 gfc_check_ltime_gmtime (gfc_expr
*time
, gfc_expr
*values
)
4589 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
4592 if (kind_value_check(time
, 0, gfc_default_integer_kind
) == FAILURE
)
4595 if (scalar_check (time
, 0) == FAILURE
)
4598 if (array_check (values
, 1) == FAILURE
)
4601 if (rank_check (values
, 1, 1) == FAILURE
)
4604 if (variable_check (values
, 1, false) == FAILURE
)
4607 if (type_check (values
, 1, BT_INTEGER
) == FAILURE
)
4610 if (kind_value_check(values
, 1, gfc_default_integer_kind
) == FAILURE
)
4618 gfc_check_ttynam_sub (gfc_expr
*unit
, gfc_expr
*name
)
4620 if (scalar_check (unit
, 0) == FAILURE
)
4623 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4626 if (type_check (name
, 1, BT_CHARACTER
) == FAILURE
)
4628 if (kind_value_check (name
, 1, gfc_default_character_kind
) == FAILURE
)
4636 gfc_check_isatty (gfc_expr
*unit
)
4641 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4644 if (scalar_check (unit
, 0) == FAILURE
)
4652 gfc_check_isnan (gfc_expr
*x
)
4654 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4662 gfc_check_perror (gfc_expr
*string
)
4664 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
)
4666 if (kind_value_check (string
, 0, gfc_default_character_kind
) == FAILURE
)
4674 gfc_check_umask (gfc_expr
*mask
)
4676 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
4679 if (scalar_check (mask
, 0) == FAILURE
)
4687 gfc_check_umask_sub (gfc_expr
*mask
, gfc_expr
*old
)
4689 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
4692 if (scalar_check (mask
, 0) == FAILURE
)
4698 if (scalar_check (old
, 1) == FAILURE
)
4701 if (type_check (old
, 1, BT_INTEGER
) == FAILURE
)
4709 gfc_check_unlink (gfc_expr
*name
)
4711 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4713 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4721 gfc_check_unlink_sub (gfc_expr
*name
, gfc_expr
*status
)
4723 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4725 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4731 if (scalar_check (status
, 1) == FAILURE
)
4734 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4742 gfc_check_signal (gfc_expr
*number
, gfc_expr
*handler
)
4744 if (scalar_check (number
, 0) == FAILURE
)
4746 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
4749 if (int_or_proc_check (handler
, 1) == FAILURE
)
4751 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4759 gfc_check_signal_sub (gfc_expr
*number
, gfc_expr
*handler
, gfc_expr
*status
)
4761 if (scalar_check (number
, 0) == FAILURE
)
4763 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
4766 if (int_or_proc_check (handler
, 1) == FAILURE
)
4768 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4774 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
4776 if (scalar_check (status
, 2) == FAILURE
)
4784 gfc_check_system_sub (gfc_expr
*cmd
, gfc_expr
*status
)
4786 if (type_check (cmd
, 0, BT_CHARACTER
) == FAILURE
)
4788 if (kind_value_check (cmd
, 0, gfc_default_character_kind
) == FAILURE
)
4791 if (scalar_check (status
, 1) == FAILURE
)
4794 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4797 if (kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
)
4804 /* This is used for the GNU intrinsics AND, OR and XOR. */
4806 gfc_check_and (gfc_expr
*i
, gfc_expr
*j
)
4808 if (i
->ts
.type
!= BT_INTEGER
&& i
->ts
.type
!= BT_LOGICAL
)
4810 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4811 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
4812 gfc_current_intrinsic
, &i
->where
);
4816 if (j
->ts
.type
!= BT_INTEGER
&& j
->ts
.type
!= BT_LOGICAL
)
4818 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
4819 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
4820 gfc_current_intrinsic
, &j
->where
);
4824 if (i
->ts
.type
!= j
->ts
.type
)
4826 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
4827 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
4828 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4833 if (scalar_check (i
, 0) == FAILURE
)
4836 if (scalar_check (j
, 1) == FAILURE
)
4844 gfc_check_storage_size (gfc_expr
*a ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
4849 if (type_check (kind
, 1, BT_INTEGER
) == FAILURE
)
4852 if (scalar_check (kind
, 1) == FAILURE
)
4855 if (kind
->expr_type
!= EXPR_CONSTANT
)
4857 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
4858 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,