2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Katherine Holcomb
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 /* These functions check to see if an argument list is compatible with
23 a particular intrinsic function or subroutine. Presence of
24 required arguments has already been established, the argument list
25 has been sorted into the right order and has NULL arguments in the
26 correct places for missing optional arguments. */
30 #include "coretypes.h"
33 #include "intrinsic.h"
34 #include "constructor.h"
35 #include "target-memory.h"
38 /* Make sure an expression is a scalar. */
41 scalar_check (gfc_expr
*e
, int n
)
46 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a scalar",
47 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
54 /* Check the type of an expression. */
57 type_check (gfc_expr
*e
, int n
, bt type
)
59 if (e
->ts
.type
== type
)
62 gfc_error ("'%s' argument of '%s' intrinsic at %L must be %s",
63 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
64 &e
->where
, gfc_basic_typename (type
));
70 /* Check that the expression is a numeric type. */
73 numeric_check (gfc_expr
*e
, int n
)
75 if (gfc_numeric_ts (&e
->ts
))
78 /* If the expression has not got a type, check if its namespace can
79 offer a default type. */
80 if ((e
->expr_type
== EXPR_VARIABLE
|| e
->expr_type
== EXPR_FUNCTION
)
81 && e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
82 && gfc_set_default_type (e
->symtree
->n
.sym
, 0,
83 e
->symtree
->n
.sym
->ns
) == SUCCESS
84 && gfc_numeric_ts (&e
->symtree
->n
.sym
->ts
))
86 e
->ts
= e
->symtree
->n
.sym
->ts
;
90 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a numeric type",
91 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
98 /* Check that an expression is integer or real. */
101 int_or_real_check (gfc_expr
*e
, int n
)
103 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
)
105 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
106 "or REAL", gfc_current_intrinsic_arg
[n
]->name
,
107 gfc_current_intrinsic
, &e
->where
);
115 /* Check that an expression is real or complex. */
118 real_or_complex_check (gfc_expr
*e
, int n
)
120 if (e
->ts
.type
!= BT_REAL
&& e
->ts
.type
!= BT_COMPLEX
)
122 gfc_error ("'%s' argument of '%s' intrinsic at %L must be REAL "
123 "or COMPLEX", gfc_current_intrinsic_arg
[n
]->name
,
124 gfc_current_intrinsic
, &e
->where
);
132 /* Check that an expression is INTEGER or PROCEDURE. */
135 int_or_proc_check (gfc_expr
*e
, int n
)
137 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_PROCEDURE
)
139 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
140 "or PROCEDURE", gfc_current_intrinsic_arg
[n
]->name
,
141 gfc_current_intrinsic
, &e
->where
);
149 /* Check that the expression is an optional constant integer
150 and that it specifies a valid kind for that type. */
153 kind_check (gfc_expr
*k
, int n
, bt type
)
160 if (type_check (k
, n
, BT_INTEGER
) == FAILURE
)
163 if (scalar_check (k
, n
) == FAILURE
)
166 if (gfc_check_init_expr (k
) != SUCCESS
)
168 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
169 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
174 if (gfc_extract_int (k
, &kind
) != NULL
175 || gfc_validate_kind (type
, kind
, true) < 0)
177 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type
),
186 /* Make sure the expression is a double precision real. */
189 double_check (gfc_expr
*d
, int n
)
191 if (type_check (d
, n
, BT_REAL
) == FAILURE
)
194 if (d
->ts
.kind
!= gfc_default_double_kind
)
196 gfc_error ("'%s' argument of '%s' intrinsic at %L must be double "
197 "precision", gfc_current_intrinsic_arg
[n
]->name
,
198 gfc_current_intrinsic
, &d
->where
);
207 coarray_check (gfc_expr
*e
, int n
)
209 if (e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
210 && CLASS_DATA (e
)->attr
.codimension
211 && CLASS_DATA (e
)->as
->corank
)
213 gfc_add_class_array_ref (e
);
217 if (!gfc_is_coarray (e
))
219 gfc_error ("Expected coarray variable as '%s' argument to the %s "
220 "intrinsic at %L", gfc_current_intrinsic_arg
[n
]->name
,
221 gfc_current_intrinsic
, &e
->where
);
229 /* Make sure the expression is a logical array. */
232 logical_array_check (gfc_expr
*array
, int n
)
234 if (array
->ts
.type
!= BT_LOGICAL
|| array
->rank
== 0)
236 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a logical "
237 "array", gfc_current_intrinsic_arg
[n
]->name
,
238 gfc_current_intrinsic
, &array
->where
);
246 /* Make sure an expression is an array. */
249 array_check (gfc_expr
*e
, int n
)
251 if (e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
252 && CLASS_DATA (e
)->attr
.dimension
253 && CLASS_DATA (e
)->as
->rank
)
255 gfc_add_class_array_ref (e
);
259 if (e
->rank
!= 0 && e
->ts
.type
!= BT_PROCEDURE
)
262 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an array",
263 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
270 /* If expr is a constant, then check to ensure that it is greater than
274 nonnegative_check (const char *arg
, gfc_expr
*expr
)
278 if (expr
->expr_type
== EXPR_CONSTANT
)
280 gfc_extract_int (expr
, &i
);
283 gfc_error ("'%s' at %L must be nonnegative", arg
, &expr
->where
);
292 /* If expr2 is constant, then check that the value is less than
293 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
296 less_than_bitsize1 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
297 gfc_expr
*expr2
, bool or_equal
)
301 if (expr2
->expr_type
== EXPR_CONSTANT
)
303 gfc_extract_int (expr2
, &i2
);
304 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
306 /* For ISHFT[C], check that |shift| <= bit_size(i). */
312 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
314 gfc_error ("The absolute value of SHIFT at %L must be less "
315 "than or equal to BIT_SIZE('%s')",
316 &expr2
->where
, arg1
);
323 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
325 gfc_error ("'%s' at %L must be less than "
326 "or equal to BIT_SIZE('%s')",
327 arg2
, &expr2
->where
, arg1
);
333 if (i2
>= gfc_integer_kinds
[i3
].bit_size
)
335 gfc_error ("'%s' at %L must be less than BIT_SIZE('%s')",
336 arg2
, &expr2
->where
, arg1
);
346 /* If expr is constant, then check that the value is less than or equal
347 to the bit_size of the kind k. */
350 less_than_bitsizekind (const char *arg
, gfc_expr
*expr
, int k
)
354 if (expr
->expr_type
!= EXPR_CONSTANT
)
357 i
= gfc_validate_kind (BT_INTEGER
, k
, false);
358 gfc_extract_int (expr
, &val
);
360 if (val
> gfc_integer_kinds
[i
].bit_size
)
362 gfc_error ("'%s' at %L must be less than or equal to the BIT_SIZE of "
363 "INTEGER(KIND=%d)", arg
, &expr
->where
, k
);
371 /* If expr2 and expr3 are constants, then check that the value is less than
372 or equal to bit_size(expr1). */
375 less_than_bitsize2 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
376 gfc_expr
*expr2
, const char *arg3
, gfc_expr
*expr3
)
380 if (expr2
->expr_type
== EXPR_CONSTANT
&& expr3
->expr_type
== EXPR_CONSTANT
)
382 gfc_extract_int (expr2
, &i2
);
383 gfc_extract_int (expr3
, &i3
);
385 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
386 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
388 gfc_error ("'%s + %s' at %L must be less than or equal "
390 arg2
, arg3
, &expr2
->where
, arg1
);
398 /* Make sure two expressions have the same type. */
401 same_type_check (gfc_expr
*e
, int n
, gfc_expr
*f
, int m
)
403 if (gfc_compare_types (&e
->ts
, &f
->ts
))
406 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same type "
407 "and kind as '%s'", gfc_current_intrinsic_arg
[m
]->name
,
408 gfc_current_intrinsic
, &f
->where
,
409 gfc_current_intrinsic_arg
[n
]->name
);
415 /* Make sure that an expression has a certain (nonzero) rank. */
418 rank_check (gfc_expr
*e
, int n
, int rank
)
423 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank %d",
424 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
431 /* Make sure a variable expression is not an optional dummy argument. */
434 nonoptional_check (gfc_expr
*e
, int n
)
436 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.optional
)
438 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be OPTIONAL",
439 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
443 /* TODO: Recursive check on nonoptional variables? */
449 /* Check for ALLOCATABLE attribute. */
452 allocatable_check (gfc_expr
*e
, int n
)
454 symbol_attribute attr
;
456 attr
= gfc_variable_attr (e
, NULL
);
457 if (!attr
.allocatable
|| attr
.associate_var
)
459 gfc_error ("'%s' argument of '%s' intrinsic at %L must be ALLOCATABLE",
460 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
469 /* Check that an expression has a particular kind. */
472 kind_value_check (gfc_expr
*e
, int n
, int k
)
477 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of kind %d",
478 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
485 /* Make sure an expression is a variable. */
488 variable_check (gfc_expr
*e
, int n
, bool allow_proc
)
490 if (e
->expr_type
== EXPR_VARIABLE
491 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
492 && (gfc_current_intrinsic_arg
[n
]->intent
== INTENT_OUT
493 || gfc_current_intrinsic_arg
[n
]->intent
== INTENT_INOUT
))
496 bool pointer
= e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
497 && CLASS_DATA (e
->symtree
->n
.sym
)
498 ? CLASS_DATA (e
->symtree
->n
.sym
)->attr
.class_pointer
499 : e
->symtree
->n
.sym
->attr
.pointer
;
501 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
503 if (pointer
&& ref
->type
== REF_COMPONENT
)
505 if (ref
->type
== REF_COMPONENT
506 && ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
507 && CLASS_DATA (ref
->u
.c
.component
)->attr
.class_pointer
)
508 || (ref
->u
.c
.component
->ts
.type
!= BT_CLASS
509 && ref
->u
.c
.component
->attr
.pointer
)))
515 gfc_error ("'%s' argument of '%s' intrinsic at %L cannot be "
516 "INTENT(IN)", gfc_current_intrinsic_arg
[n
]->name
,
517 gfc_current_intrinsic
, &e
->where
);
522 if (e
->expr_type
== EXPR_VARIABLE
523 && e
->symtree
->n
.sym
->attr
.flavor
!= FL_PARAMETER
524 && (allow_proc
|| !e
->symtree
->n
.sym
->attr
.function
))
527 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.function
528 && e
->symtree
->n
.sym
== e
->symtree
->n
.sym
->result
)
531 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
532 if (ns
->proc_name
== e
->symtree
->n
.sym
)
536 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",
537 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
, &e
->where
);
543 /* Check the common DIM parameter for correctness. */
546 dim_check (gfc_expr
*dim
, int n
, bool optional
)
551 if (type_check (dim
, n
, BT_INTEGER
) == FAILURE
)
554 if (scalar_check (dim
, n
) == FAILURE
)
557 if (!optional
&& nonoptional_check (dim
, n
) == FAILURE
)
564 /* If a coarray DIM parameter is a constant, make sure that it is greater than
565 zero and less than or equal to the corank of the given array. */
568 dim_corank_check (gfc_expr
*dim
, gfc_expr
*array
)
572 gcc_assert (array
->expr_type
== EXPR_VARIABLE
);
574 if (dim
->expr_type
!= EXPR_CONSTANT
)
577 if (array
->ts
.type
== BT_CLASS
)
580 corank
= gfc_get_corank (array
);
582 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
583 || mpz_cmp_ui (dim
->value
.integer
, corank
) > 0)
585 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
586 "codimension index", gfc_current_intrinsic
, &dim
->where
);
595 /* If a DIM parameter is a constant, make sure that it is greater than
596 zero and less than or equal to the rank of the given array. If
597 allow_assumed is zero then dim must be less than the rank of the array
598 for assumed size arrays. */
601 dim_rank_check (gfc_expr
*dim
, gfc_expr
*array
, int allow_assumed
)
609 if (dim
->expr_type
!= EXPR_CONSTANT
)
612 if (array
->ts
.type
== BT_CLASS
)
615 if (array
->expr_type
== EXPR_FUNCTION
&& array
->value
.function
.isym
616 && array
->value
.function
.isym
->id
== GFC_ISYM_SPREAD
)
617 rank
= array
->rank
+ 1;
621 /* Assumed-rank array. */
623 rank
= GFC_MAX_DIMENSIONS
;
625 if (array
->expr_type
== EXPR_VARIABLE
)
627 ar
= gfc_find_array_ref (array
);
628 if (ar
->as
->type
== AS_ASSUMED_SIZE
630 && ar
->type
!= AR_ELEMENT
631 && ar
->type
!= AR_SECTION
)
635 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
636 || mpz_cmp_ui (dim
->value
.integer
, rank
) > 0)
638 gfc_error ("'dim' argument of '%s' intrinsic at %L is not a valid "
639 "dimension index", gfc_current_intrinsic
, &dim
->where
);
648 /* Compare the size of a along dimension ai with the size of b along
649 dimension bi, returning 0 if they are known not to be identical,
650 and 1 if they are identical, or if this cannot be determined. */
653 identical_dimen_shape (gfc_expr
*a
, int ai
, gfc_expr
*b
, int bi
)
655 mpz_t a_size
, b_size
;
658 gcc_assert (a
->rank
> ai
);
659 gcc_assert (b
->rank
> bi
);
663 if (gfc_array_dimen_size (a
, ai
, &a_size
) == SUCCESS
)
665 if (gfc_array_dimen_size (b
, bi
, &b_size
) == SUCCESS
)
667 if (mpz_cmp (a_size
, b_size
) != 0)
677 /* Calculate the length of a character variable, including substrings.
678 Strip away parentheses if necessary. Return -1 if no length could
682 gfc_var_strlen (const gfc_expr
*a
)
686 while (a
->expr_type
== EXPR_OP
&& a
->value
.op
.op
== INTRINSIC_PARENTHESES
)
689 for (ra
= a
->ref
; ra
!= NULL
&& ra
->type
!= REF_SUBSTRING
; ra
= ra
->next
)
696 if (ra
->u
.ss
.start
->expr_type
== EXPR_CONSTANT
697 && ra
->u
.ss
.end
->expr_type
== EXPR_CONSTANT
)
699 start_a
= mpz_get_si (ra
->u
.ss
.start
->value
.integer
);
700 end_a
= mpz_get_si (ra
->u
.ss
.end
->value
.integer
);
701 return end_a
- start_a
+ 1;
703 else if (gfc_dep_compare_expr (ra
->u
.ss
.start
, ra
->u
.ss
.end
) == 0)
709 if (a
->ts
.u
.cl
&& a
->ts
.u
.cl
->length
710 && a
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
711 return mpz_get_si (a
->ts
.u
.cl
->length
->value
.integer
);
712 else if (a
->expr_type
== EXPR_CONSTANT
713 && (a
->ts
.u
.cl
== NULL
|| a
->ts
.u
.cl
->length
== NULL
))
714 return a
->value
.character
.length
;
720 /* Check whether two character expressions have the same length;
721 returns SUCCESS if they have or if the length cannot be determined,
722 otherwise return FAILURE and raise a gfc_error. */
725 gfc_check_same_strlen (const gfc_expr
*a
, const gfc_expr
*b
, const char *name
)
729 len_a
= gfc_var_strlen(a
);
730 len_b
= gfc_var_strlen(b
);
732 if (len_a
== -1 || len_b
== -1 || len_a
== len_b
)
736 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
737 len_a
, len_b
, name
, &a
->where
);
743 /***** Check functions *****/
745 /* Check subroutine suitable for intrinsics taking a real argument and
746 a kind argument for the result. */
749 check_a_kind (gfc_expr
*a
, gfc_expr
*kind
, bt type
)
751 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
753 if (kind_check (kind
, 1, type
) == FAILURE
)
760 /* Check subroutine suitable for ceiling, floor and nint. */
763 gfc_check_a_ikind (gfc_expr
*a
, gfc_expr
*kind
)
765 return check_a_kind (a
, kind
, BT_INTEGER
);
769 /* Check subroutine suitable for aint, anint. */
772 gfc_check_a_xkind (gfc_expr
*a
, gfc_expr
*kind
)
774 return check_a_kind (a
, kind
, BT_REAL
);
779 gfc_check_abs (gfc_expr
*a
)
781 if (numeric_check (a
, 0) == FAILURE
)
789 gfc_check_achar (gfc_expr
*a
, gfc_expr
*kind
)
791 if (type_check (a
, 0, BT_INTEGER
) == FAILURE
)
793 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
801 gfc_check_access_func (gfc_expr
*name
, gfc_expr
*mode
)
803 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
804 || scalar_check (name
, 0) == FAILURE
)
806 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
809 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
810 || scalar_check (mode
, 1) == FAILURE
)
812 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
820 gfc_check_all_any (gfc_expr
*mask
, gfc_expr
*dim
)
822 if (logical_array_check (mask
, 0) == FAILURE
)
825 if (dim_check (dim
, 1, false) == FAILURE
)
828 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
836 gfc_check_allocated (gfc_expr
*array
)
838 if (variable_check (array
, 0, false) == FAILURE
)
840 if (allocatable_check (array
, 0) == FAILURE
)
847 /* Common check function where the first argument must be real or
848 integer and the second argument must be the same as the first. */
851 gfc_check_a_p (gfc_expr
*a
, gfc_expr
*p
)
853 if (int_or_real_check (a
, 0) == FAILURE
)
856 if (a
->ts
.type
!= p
->ts
.type
)
858 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
859 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
860 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
865 if (a
->ts
.kind
!= p
->ts
.kind
)
867 if (gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
868 &p
->where
) == FAILURE
)
877 gfc_check_x_yd (gfc_expr
*x
, gfc_expr
*y
)
879 if (double_check (x
, 0) == FAILURE
|| double_check (y
, 1) == FAILURE
)
887 gfc_check_associated (gfc_expr
*pointer
, gfc_expr
*target
)
889 symbol_attribute attr1
, attr2
;
894 where
= &pointer
->where
;
896 if (pointer
->expr_type
== EXPR_NULL
)
899 attr1
= gfc_expr_attr (pointer
);
901 if (!attr1
.pointer
&& !attr1
.proc_pointer
)
903 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER",
904 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
910 if (attr1
.pointer
&& gfc_is_coindexed (pointer
))
912 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
913 "coindexed", gfc_current_intrinsic_arg
[0]->name
,
914 gfc_current_intrinsic
, &pointer
->where
);
918 /* Target argument is optional. */
922 where
= &target
->where
;
923 if (target
->expr_type
== EXPR_NULL
)
926 if (target
->expr_type
== EXPR_VARIABLE
|| target
->expr_type
== EXPR_FUNCTION
)
927 attr2
= gfc_expr_attr (target
);
930 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a pointer "
931 "or target VARIABLE or FUNCTION",
932 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
937 if (attr1
.pointer
&& !attr2
.pointer
&& !attr2
.target
)
939 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER "
940 "or a TARGET", gfc_current_intrinsic_arg
[1]->name
,
941 gfc_current_intrinsic
, &target
->where
);
946 if (attr1
.pointer
&& gfc_is_coindexed (target
))
948 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
949 "coindexed", gfc_current_intrinsic_arg
[1]->name
,
950 gfc_current_intrinsic
, &target
->where
);
955 if (same_type_check (pointer
, 0, target
, 1) == FAILURE
)
957 if (rank_check (target
, 0, pointer
->rank
) == FAILURE
)
959 if (target
->rank
> 0)
961 for (i
= 0; i
< target
->rank
; i
++)
962 if (target
->ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
964 gfc_error ("Array section with a vector subscript at %L shall not "
965 "be the target of a pointer",
975 gfc_error ("NULL pointer at %L is not permitted as actual argument "
976 "of '%s' intrinsic function", where
, gfc_current_intrinsic
);
983 gfc_check_atan_2 (gfc_expr
*y
, gfc_expr
*x
)
985 /* gfc_notify_std would be a waste of time as the return value
986 is seemingly used only for the generic resolution. The error
987 will be: Too many arguments. */
988 if ((gfc_option
.allow_std
& GFC_STD_F2008
) == 0)
991 return gfc_check_atan2 (y
, x
);
996 gfc_check_atan2 (gfc_expr
*y
, gfc_expr
*x
)
998 if (type_check (y
, 0, BT_REAL
) == FAILURE
)
1000 if (same_type_check (y
, 0, x
, 1) == FAILURE
)
1008 gfc_check_atomic (gfc_expr
*atom
, gfc_expr
*value
)
1010 if (!(atom
->ts
.type
== BT_INTEGER
&& atom
->ts
.kind
== gfc_atomic_int_kind
)
1011 && !(atom
->ts
.type
== BT_LOGICAL
1012 && atom
->ts
.kind
== gfc_atomic_logical_kind
))
1014 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1015 "integer of ATOMIC_INT_KIND or a logical of "
1016 "ATOMIC_LOGICAL_KIND", &atom
->where
, gfc_current_intrinsic
);
1020 if (!gfc_expr_attr (atom
).codimension
)
1022 gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
1023 "coarray or coindexed", &atom
->where
, gfc_current_intrinsic
);
1027 if (atom
->ts
.type
!= value
->ts
.type
)
1029 gfc_error ("ATOM and VALUE argument of the %s intrinsic function shall "
1030 "have the same type at %L", gfc_current_intrinsic
,
1040 gfc_check_atomic_def (gfc_expr
*atom
, gfc_expr
*value
)
1042 if (scalar_check (atom
, 0) == FAILURE
|| scalar_check (value
, 1) == FAILURE
)
1045 if (gfc_check_vardef_context (atom
, false, false, false, NULL
) == FAILURE
)
1047 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1048 "definable", gfc_current_intrinsic
, &atom
->where
);
1052 return gfc_check_atomic (atom
, value
);
1057 gfc_check_atomic_ref (gfc_expr
*value
, gfc_expr
*atom
)
1059 if (scalar_check (value
, 0) == FAILURE
|| scalar_check (atom
, 1) == FAILURE
)
1062 if (gfc_check_vardef_context (value
, false, false, false, NULL
) == FAILURE
)
1064 gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1065 "definable", gfc_current_intrinsic
, &value
->where
);
1069 return gfc_check_atomic (atom
, value
);
1073 /* BESJN and BESYN functions. */
1076 gfc_check_besn (gfc_expr
*n
, gfc_expr
*x
)
1078 if (type_check (n
, 0, BT_INTEGER
) == FAILURE
)
1080 if (n
->expr_type
== EXPR_CONSTANT
)
1083 gfc_extract_int (n
, &i
);
1084 if (i
< 0 && gfc_notify_std (GFC_STD_GNU
, "Negative argument "
1085 "N at %L", &n
->where
) == FAILURE
)
1089 if (type_check (x
, 1, BT_REAL
) == FAILURE
)
1096 /* Transformational version of the Bessel JN and YN functions. */
1099 gfc_check_bessel_n2 (gfc_expr
*n1
, gfc_expr
*n2
, gfc_expr
*x
)
1101 if (type_check (n1
, 0, BT_INTEGER
) == FAILURE
)
1103 if (scalar_check (n1
, 0) == FAILURE
)
1105 if (nonnegative_check("N1", n1
) == FAILURE
)
1108 if (type_check (n2
, 1, BT_INTEGER
) == FAILURE
)
1110 if (scalar_check (n2
, 1) == FAILURE
)
1112 if (nonnegative_check("N2", n2
) == FAILURE
)
1115 if (type_check (x
, 2, BT_REAL
) == FAILURE
)
1117 if (scalar_check (x
, 2) == FAILURE
)
1125 gfc_check_bge_bgt_ble_blt (gfc_expr
*i
, gfc_expr
*j
)
1127 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1130 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1138 gfc_check_bitfcn (gfc_expr
*i
, gfc_expr
*pos
)
1140 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1143 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
1146 if (nonnegative_check ("pos", pos
) == FAILURE
)
1149 if (less_than_bitsize1 ("i", i
, "pos", pos
, false) == FAILURE
)
1157 gfc_check_char (gfc_expr
*i
, gfc_expr
*kind
)
1159 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1161 if (kind_check (kind
, 1, BT_CHARACTER
) == FAILURE
)
1169 gfc_check_chdir (gfc_expr
*dir
)
1171 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
1173 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
1181 gfc_check_chdir_sub (gfc_expr
*dir
, gfc_expr
*status
)
1183 if (type_check (dir
, 0, BT_CHARACTER
) == FAILURE
)
1185 if (kind_value_check (dir
, 0, gfc_default_character_kind
) == FAILURE
)
1191 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
1193 if (scalar_check (status
, 1) == FAILURE
)
1201 gfc_check_chmod (gfc_expr
*name
, gfc_expr
*mode
)
1203 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
1205 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
1208 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
1210 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
1218 gfc_check_chmod_sub (gfc_expr
*name
, gfc_expr
*mode
, gfc_expr
*status
)
1220 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
1222 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
1225 if (type_check (mode
, 1, BT_CHARACTER
) == FAILURE
)
1227 if (kind_value_check (mode
, 1, gfc_default_character_kind
) == FAILURE
)
1233 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
1236 if (scalar_check (status
, 2) == FAILURE
)
1244 gfc_check_cmplx (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
1246 if (numeric_check (x
, 0) == FAILURE
)
1251 if (numeric_check (y
, 1) == FAILURE
)
1254 if (x
->ts
.type
== BT_COMPLEX
)
1256 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1257 "present if 'x' is COMPLEX",
1258 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1263 if (y
->ts
.type
== BT_COMPLEX
)
1265 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1266 "of either REAL or INTEGER",
1267 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1274 if (kind_check (kind
, 2, BT_COMPLEX
) == FAILURE
)
1277 if (!kind
&& gfc_option
.gfc_warn_conversion
1278 && x
->ts
.type
== BT_REAL
&& x
->ts
.kind
> gfc_default_real_kind
)
1279 gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L "
1280 "might loose precision, consider using the KIND argument",
1281 gfc_typename (&x
->ts
), gfc_default_real_kind
, &x
->where
);
1282 else if (y
&& !kind
&& gfc_option
.gfc_warn_conversion
1283 && y
->ts
.type
== BT_REAL
&& y
->ts
.kind
> gfc_default_real_kind
)
1284 gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L "
1285 "might loose precision, consider using the KIND argument",
1286 gfc_typename (&y
->ts
), gfc_default_real_kind
, &y
->where
);
1293 gfc_check_complex (gfc_expr
*x
, gfc_expr
*y
)
1295 if (int_or_real_check (x
, 0) == FAILURE
)
1297 if (scalar_check (x
, 0) == FAILURE
)
1300 if (int_or_real_check (y
, 1) == FAILURE
)
1302 if (scalar_check (y
, 1) == FAILURE
)
1310 gfc_check_count (gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
1312 if (logical_array_check (mask
, 0) == FAILURE
)
1314 if (dim_check (dim
, 1, false) == FAILURE
)
1316 if (dim_rank_check (dim
, mask
, 0) == FAILURE
)
1318 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
1320 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
1321 "with KIND argument at %L",
1322 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1330 gfc_check_cshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*dim
)
1332 if (array_check (array
, 0) == FAILURE
)
1335 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1338 if (dim_check (dim
, 2, true) == FAILURE
)
1341 if (dim_rank_check (dim
, array
, false) == FAILURE
)
1344 if (array
->rank
== 1 || shift
->rank
== 0)
1346 if (scalar_check (shift
, 1) == FAILURE
)
1349 else if (shift
->rank
== array
->rank
- 1)
1354 else if (dim
->expr_type
== EXPR_CONSTANT
)
1355 gfc_extract_int (dim
, &d
);
1362 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1365 if (!identical_dimen_shape (array
, i
, shift
, j
))
1367 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1368 "invalid shape in dimension %d (%ld/%ld)",
1369 gfc_current_intrinsic_arg
[1]->name
,
1370 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1371 mpz_get_si (array
->shape
[i
]),
1372 mpz_get_si (shift
->shape
[j
]));
1382 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1383 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
1384 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1393 gfc_check_ctime (gfc_expr
*time
)
1395 if (scalar_check (time
, 0) == FAILURE
)
1398 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
1405 gfc_try
gfc_check_datan2 (gfc_expr
*y
, gfc_expr
*x
)
1407 if (double_check (y
, 0) == FAILURE
|| double_check (x
, 1) == FAILURE
)
1414 gfc_check_dcmplx (gfc_expr
*x
, gfc_expr
*y
)
1416 if (numeric_check (x
, 0) == FAILURE
)
1421 if (numeric_check (y
, 1) == FAILURE
)
1424 if (x
->ts
.type
== BT_COMPLEX
)
1426 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be "
1427 "present if 'x' is COMPLEX",
1428 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1433 if (y
->ts
.type
== BT_COMPLEX
)
1435 gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
1436 "of either REAL or INTEGER",
1437 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1448 gfc_check_dble (gfc_expr
*x
)
1450 if (numeric_check (x
, 0) == FAILURE
)
1458 gfc_check_digits (gfc_expr
*x
)
1460 if (int_or_real_check (x
, 0) == FAILURE
)
1468 gfc_check_dot_product (gfc_expr
*vector_a
, gfc_expr
*vector_b
)
1470 switch (vector_a
->ts
.type
)
1473 if (type_check (vector_b
, 1, BT_LOGICAL
) == FAILURE
)
1480 if (numeric_check (vector_b
, 1) == FAILURE
)
1485 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
1486 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
1487 gfc_current_intrinsic
, &vector_a
->where
);
1491 if (rank_check (vector_a
, 0, 1) == FAILURE
)
1494 if (rank_check (vector_b
, 1, 1) == FAILURE
)
1497 if (! identical_dimen_shape (vector_a
, 0, vector_b
, 0))
1499 gfc_error ("Different shape for arguments '%s' and '%s' at %L for "
1500 "intrinsic 'dot_product'", gfc_current_intrinsic_arg
[0]->name
,
1501 gfc_current_intrinsic_arg
[1]->name
, &vector_a
->where
);
1510 gfc_check_dprod (gfc_expr
*x
, gfc_expr
*y
)
1512 if (type_check (x
, 0, BT_REAL
) == FAILURE
1513 || type_check (y
, 1, BT_REAL
) == FAILURE
)
1516 if (x
->ts
.kind
!= gfc_default_real_kind
)
1518 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1519 "real", gfc_current_intrinsic_arg
[0]->name
,
1520 gfc_current_intrinsic
, &x
->where
);
1524 if (y
->ts
.kind
!= gfc_default_real_kind
)
1526 gfc_error ("'%s' argument of '%s' intrinsic at %L must be default "
1527 "real", gfc_current_intrinsic_arg
[1]->name
,
1528 gfc_current_intrinsic
, &y
->where
);
1537 gfc_check_dshift (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*shift
)
1539 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1542 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1545 if (i
->is_boz
&& j
->is_boz
)
1547 gfc_error ("'I' at %L and 'J' at %L cannot both be BOZ literal "
1548 "constants", &i
->where
, &j
->where
);
1552 if (!i
->is_boz
&& !j
->is_boz
&& same_type_check (i
, 0, j
, 1) == FAILURE
)
1555 if (type_check (shift
, 2, BT_INTEGER
) == FAILURE
)
1558 if (nonnegative_check ("SHIFT", shift
) == FAILURE
)
1563 if (less_than_bitsize1 ("J", j
, "SHIFT", shift
, true) == FAILURE
)
1565 i
->ts
.kind
= j
->ts
.kind
;
1569 if (less_than_bitsize1 ("I", i
, "SHIFT", shift
, true) == FAILURE
)
1571 j
->ts
.kind
= i
->ts
.kind
;
1579 gfc_check_eoshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*boundary
,
1582 if (array_check (array
, 0) == FAILURE
)
1585 if (type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
1588 if (dim_check (dim
, 3, true) == FAILURE
)
1591 if (dim_rank_check (dim
, array
, false) == FAILURE
)
1594 if (array
->rank
== 1 || shift
->rank
== 0)
1596 if (scalar_check (shift
, 1) == FAILURE
)
1599 else if (shift
->rank
== array
->rank
- 1)
1604 else if (dim
->expr_type
== EXPR_CONSTANT
)
1605 gfc_extract_int (dim
, &d
);
1612 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1615 if (!identical_dimen_shape (array
, i
, shift
, j
))
1617 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
1618 "invalid shape in dimension %d (%ld/%ld)",
1619 gfc_current_intrinsic_arg
[1]->name
,
1620 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1621 mpz_get_si (array
->shape
[i
]),
1622 mpz_get_si (shift
->shape
[j
]));
1632 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have rank "
1633 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
1634 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1638 if (boundary
!= NULL
)
1640 if (same_type_check (array
, 0, boundary
, 2) == FAILURE
)
1643 if (array
->rank
== 1 || boundary
->rank
== 0)
1645 if (scalar_check (boundary
, 2) == FAILURE
)
1648 else if (boundary
->rank
== array
->rank
- 1)
1650 if (gfc_check_conformance (shift
, boundary
,
1651 "arguments '%s' and '%s' for "
1653 gfc_current_intrinsic_arg
[1]->name
,
1654 gfc_current_intrinsic_arg
[2]->name
,
1655 gfc_current_intrinsic
) == FAILURE
)
1660 gfc_error ("'%s' argument of intrinsic '%s' at %L of must have "
1661 "rank %d or be a scalar",
1662 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1663 &shift
->where
, array
->rank
- 1);
1672 gfc_check_float (gfc_expr
*a
)
1674 if (type_check (a
, 0, BT_INTEGER
) == FAILURE
)
1677 if ((a
->ts
.kind
!= gfc_default_integer_kind
)
1678 && gfc_notify_std (GFC_STD_GNU
, "non-default INTEGER "
1679 "kind argument to %s intrinsic at %L",
1680 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
1686 /* A single complex argument. */
1689 gfc_check_fn_c (gfc_expr
*a
)
1691 if (type_check (a
, 0, BT_COMPLEX
) == FAILURE
)
1697 /* A single real argument. */
1700 gfc_check_fn_r (gfc_expr
*a
)
1702 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
1708 /* A single double argument. */
1711 gfc_check_fn_d (gfc_expr
*a
)
1713 if (double_check (a
, 0) == FAILURE
)
1719 /* A single real or complex argument. */
1722 gfc_check_fn_rc (gfc_expr
*a
)
1724 if (real_or_complex_check (a
, 0) == FAILURE
)
1732 gfc_check_fn_rc2008 (gfc_expr
*a
)
1734 if (real_or_complex_check (a
, 0) == FAILURE
)
1737 if (a
->ts
.type
== BT_COMPLEX
1738 && gfc_notify_std (GFC_STD_F2008
, "COMPLEX argument '%s' "
1739 "argument of '%s' intrinsic at %L",
1740 gfc_current_intrinsic_arg
[0]->name
,
1741 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
1749 gfc_check_fnum (gfc_expr
*unit
)
1751 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
1754 if (scalar_check (unit
, 0) == FAILURE
)
1762 gfc_check_huge (gfc_expr
*x
)
1764 if (int_or_real_check (x
, 0) == FAILURE
)
1772 gfc_check_hypot (gfc_expr
*x
, gfc_expr
*y
)
1774 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
1776 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
1783 /* Check that the single argument is an integer. */
1786 gfc_check_i (gfc_expr
*i
)
1788 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1796 gfc_check_iand (gfc_expr
*i
, gfc_expr
*j
)
1798 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1801 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1804 if (i
->ts
.kind
!= j
->ts
.kind
)
1806 if (gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
1807 &i
->where
) == FAILURE
)
1816 gfc_check_ibits (gfc_expr
*i
, gfc_expr
*pos
, gfc_expr
*len
)
1818 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1821 if (type_check (pos
, 1, BT_INTEGER
) == FAILURE
)
1824 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
1827 if (nonnegative_check ("pos", pos
) == FAILURE
)
1830 if (nonnegative_check ("len", len
) == FAILURE
)
1833 if (less_than_bitsize2 ("i", i
, "pos", pos
, "len", len
) == FAILURE
)
1841 gfc_check_ichar_iachar (gfc_expr
*c
, gfc_expr
*kind
)
1845 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
1848 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1851 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
1852 "with KIND argument at %L",
1853 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1856 if (c
->expr_type
== EXPR_VARIABLE
|| c
->expr_type
== EXPR_SUBSTRING
)
1862 /* Substring references don't have the charlength set. */
1864 while (ref
&& ref
->type
!= REF_SUBSTRING
)
1867 gcc_assert (ref
== NULL
|| ref
->type
== REF_SUBSTRING
);
1871 /* Check that the argument is length one. Non-constant lengths
1872 can't be checked here, so assume they are ok. */
1873 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
)
1875 /* If we already have a length for this expression then use it. */
1876 if (c
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
1878 i
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
1885 start
= ref
->u
.ss
.start
;
1886 end
= ref
->u
.ss
.end
;
1889 if (end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
1890 || start
->expr_type
!= EXPR_CONSTANT
)
1893 i
= mpz_get_si (end
->value
.integer
) + 1
1894 - mpz_get_si (start
->value
.integer
);
1902 gfc_error ("Argument of %s at %L must be of length one",
1903 gfc_current_intrinsic
, &c
->where
);
1912 gfc_check_idnint (gfc_expr
*a
)
1914 if (double_check (a
, 0) == FAILURE
)
1922 gfc_check_ieor (gfc_expr
*i
, gfc_expr
*j
)
1924 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
1927 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
1930 if (i
->ts
.kind
!= j
->ts
.kind
)
1932 if (gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
1933 &i
->where
) == FAILURE
)
1942 gfc_check_index (gfc_expr
*string
, gfc_expr
*substring
, gfc_expr
*back
,
1945 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
1946 || type_check (substring
, 1, BT_CHARACTER
) == FAILURE
)
1949 if (back
!= NULL
&& type_check (back
, 2, BT_LOGICAL
) == FAILURE
)
1952 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
1954 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
1955 "with KIND argument at %L",
1956 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
1959 if (string
->ts
.kind
!= substring
->ts
.kind
)
1961 gfc_error ("'%s' argument of '%s' intrinsic at %L must be the same "
1962 "kind as '%s'", gfc_current_intrinsic_arg
[1]->name
,
1963 gfc_current_intrinsic
, &substring
->where
,
1964 gfc_current_intrinsic_arg
[0]->name
);
1973 gfc_check_int (gfc_expr
*x
, gfc_expr
*kind
)
1975 if (numeric_check (x
, 0) == FAILURE
)
1978 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
1986 gfc_check_intconv (gfc_expr
*x
)
1988 if (numeric_check (x
, 0) == FAILURE
)
1996 gfc_check_ior (gfc_expr
*i
, gfc_expr
*j
)
1998 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
2001 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
2004 if (i
->ts
.kind
!= j
->ts
.kind
)
2006 if (gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
2007 &i
->where
) == FAILURE
)
2016 gfc_check_ishft (gfc_expr
*i
, gfc_expr
*shift
)
2018 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
2019 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
2022 if (less_than_bitsize1 ("I", i
, NULL
, shift
, true) == FAILURE
)
2030 gfc_check_ishftc (gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
2032 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
2033 || type_check (shift
, 1, BT_INTEGER
) == FAILURE
)
2040 if (type_check (size
, 2, BT_INTEGER
) == FAILURE
)
2043 if (less_than_bitsize1 ("I", i
, "SIZE", size
, true) == FAILURE
)
2046 if (size
->expr_type
== EXPR_CONSTANT
)
2048 gfc_extract_int (size
, &i3
);
2051 gfc_error ("SIZE at %L must be positive", &size
->where
);
2055 if (shift
->expr_type
== EXPR_CONSTANT
)
2057 gfc_extract_int (shift
, &i2
);
2063 gfc_error ("The absolute value of SHIFT at %L must be less "
2064 "than or equal to SIZE at %L", &shift
->where
,
2071 else if (less_than_bitsize1 ("I", i
, NULL
, shift
, true) == FAILURE
)
2079 gfc_check_kill (gfc_expr
*pid
, gfc_expr
*sig
)
2081 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
2084 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
2092 gfc_check_kill_sub (gfc_expr
*pid
, gfc_expr
*sig
, gfc_expr
*status
)
2094 if (type_check (pid
, 0, BT_INTEGER
) == FAILURE
)
2097 if (scalar_check (pid
, 0) == FAILURE
)
2100 if (type_check (sig
, 1, BT_INTEGER
) == FAILURE
)
2103 if (scalar_check (sig
, 1) == FAILURE
)
2109 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2112 if (scalar_check (status
, 2) == FAILURE
)
2120 gfc_check_kind (gfc_expr
*x
)
2122 if (x
->ts
.type
== BT_DERIVED
)
2124 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a "
2125 "non-derived type", gfc_current_intrinsic_arg
[0]->name
,
2126 gfc_current_intrinsic
, &x
->where
);
2135 gfc_check_lbound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2137 if (array_check (array
, 0) == FAILURE
)
2140 if (dim_check (dim
, 1, false) == FAILURE
)
2143 if (dim_rank_check (dim
, array
, 1) == FAILURE
)
2146 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
2148 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
2149 "with KIND argument at %L",
2150 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
2158 gfc_check_lcobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
2160 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
2162 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
2166 if (coarray_check (coarray
, 0) == FAILURE
)
2171 if (dim_check (dim
, 1, false) == FAILURE
)
2174 if (dim_corank_check (dim
, coarray
) == FAILURE
)
2178 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
2186 gfc_check_len_lentrim (gfc_expr
*s
, gfc_expr
*kind
)
2188 if (type_check (s
, 0, BT_CHARACTER
) == FAILURE
)
2191 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
2193 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
2194 "with KIND argument at %L",
2195 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
2203 gfc_check_lge_lgt_lle_llt (gfc_expr
*a
, gfc_expr
*b
)
2205 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
2207 if (kind_value_check (a
, 0, gfc_default_character_kind
) == FAILURE
)
2210 if (type_check (b
, 1, BT_CHARACTER
) == FAILURE
)
2212 if (kind_value_check (b
, 1, gfc_default_character_kind
) == FAILURE
)
2220 gfc_check_link (gfc_expr
*path1
, gfc_expr
*path2
)
2222 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2224 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2227 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2229 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2237 gfc_check_link_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2239 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2241 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2244 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2246 if (kind_value_check (path2
, 0, gfc_default_character_kind
) == FAILURE
)
2252 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2255 if (scalar_check (status
, 2) == FAILURE
)
2263 gfc_check_loc (gfc_expr
*expr
)
2265 return variable_check (expr
, 0, true);
2270 gfc_check_symlnk (gfc_expr
*path1
, gfc_expr
*path2
)
2272 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2274 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2277 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2279 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2287 gfc_check_symlnk_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2289 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
2291 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
2294 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
2296 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
2302 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
2305 if (scalar_check (status
, 2) == FAILURE
)
2313 gfc_check_logical (gfc_expr
*a
, gfc_expr
*kind
)
2315 if (type_check (a
, 0, BT_LOGICAL
) == FAILURE
)
2317 if (kind_check (kind
, 1, BT_LOGICAL
) == FAILURE
)
2324 /* Min/max family. */
2327 min_max_args (gfc_actual_arglist
*arg
)
2329 if (arg
== NULL
|| arg
->next
== NULL
)
2331 gfc_error ("Intrinsic '%s' at %L must have at least two arguments",
2332 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
2341 check_rest (bt type
, int kind
, gfc_actual_arglist
*arglist
)
2343 gfc_actual_arglist
*arg
, *tmp
;
2348 if (min_max_args (arglist
) == FAILURE
)
2351 for (arg
= arglist
, n
=1; arg
; arg
= arg
->next
, n
++)
2354 if (x
->ts
.type
!= type
|| x
->ts
.kind
!= kind
)
2356 if (x
->ts
.type
== type
)
2358 if (gfc_notify_std (GFC_STD_GNU
, "Different type "
2359 "kinds at %L", &x
->where
) == FAILURE
)
2364 gfc_error ("'a%d' argument of '%s' intrinsic at %L must be "
2365 "%s(%d)", n
, gfc_current_intrinsic
, &x
->where
,
2366 gfc_basic_typename (type
), kind
);
2371 for (tmp
= arglist
, m
=1; tmp
!= arg
; tmp
= tmp
->next
, m
++)
2372 if (gfc_check_conformance (tmp
->expr
, x
,
2373 "arguments 'a%d' and 'a%d' for "
2374 "intrinsic '%s'", m
, n
,
2375 gfc_current_intrinsic
) == FAILURE
)
2384 gfc_check_min_max (gfc_actual_arglist
*arg
)
2388 if (min_max_args (arg
) == FAILURE
)
2393 if (x
->ts
.type
== BT_CHARACTER
)
2395 if (gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
2396 "with CHARACTER argument at %L",
2397 gfc_current_intrinsic
, &x
->where
) == FAILURE
)
2400 else if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
2402 gfc_error ("'a1' argument of '%s' intrinsic at %L must be INTEGER, "
2403 "REAL or CHARACTER", gfc_current_intrinsic
, &x
->where
);
2407 return check_rest (x
->ts
.type
, x
->ts
.kind
, arg
);
2412 gfc_check_min_max_integer (gfc_actual_arglist
*arg
)
2414 return check_rest (BT_INTEGER
, gfc_default_integer_kind
, arg
);
2419 gfc_check_min_max_real (gfc_actual_arglist
*arg
)
2421 return check_rest (BT_REAL
, gfc_default_real_kind
, arg
);
2426 gfc_check_min_max_double (gfc_actual_arglist
*arg
)
2428 return check_rest (BT_REAL
, gfc_default_double_kind
, arg
);
2432 /* End of min/max family. */
2435 gfc_check_malloc (gfc_expr
*size
)
2437 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
2440 if (scalar_check (size
, 0) == FAILURE
)
2448 gfc_check_matmul (gfc_expr
*matrix_a
, gfc_expr
*matrix_b
)
2450 if ((matrix_a
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_a
->ts
))
2452 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2453 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
2454 gfc_current_intrinsic
, &matrix_a
->where
);
2458 if ((matrix_b
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_b
->ts
))
2460 gfc_error ("'%s' argument of '%s' intrinsic at %L must be numeric "
2461 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
2462 gfc_current_intrinsic
, &matrix_b
->where
);
2466 if ((matrix_a
->ts
.type
== BT_LOGICAL
&& gfc_numeric_ts (&matrix_b
->ts
))
2467 || (gfc_numeric_ts (&matrix_a
->ts
) && matrix_b
->ts
.type
== BT_LOGICAL
))
2469 gfc_error ("Argument types of '%s' intrinsic at %L must match (%s/%s)",
2470 gfc_current_intrinsic
, &matrix_a
->where
,
2471 gfc_typename(&matrix_a
->ts
), gfc_typename(&matrix_b
->ts
));
2475 switch (matrix_a
->rank
)
2478 if (rank_check (matrix_b
, 1, 2) == FAILURE
)
2480 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
2481 if (!identical_dimen_shape (matrix_a
, 0, matrix_b
, 0))
2483 gfc_error ("Different shape on dimension 1 for arguments '%s' "
2484 "and '%s' at %L for intrinsic matmul",
2485 gfc_current_intrinsic_arg
[0]->name
,
2486 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
2492 if (matrix_b
->rank
!= 2)
2494 if (rank_check (matrix_b
, 1, 1) == FAILURE
)
2497 /* matrix_b has rank 1 or 2 here. Common check for the cases
2498 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
2499 - matrix_a has shape (n,m) and matrix_b has shape (m). */
2500 if (!identical_dimen_shape (matrix_a
, 1, matrix_b
, 0))
2502 gfc_error ("Different shape on dimension 2 for argument '%s' and "
2503 "dimension 1 for argument '%s' at %L for intrinsic "
2504 "matmul", gfc_current_intrinsic_arg
[0]->name
,
2505 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
2511 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of rank "
2512 "1 or 2", gfc_current_intrinsic_arg
[0]->name
,
2513 gfc_current_intrinsic
, &matrix_a
->where
);
2521 /* Whoever came up with this interface was probably on something.
2522 The possibilities for the occupation of the second and third
2529 NULL MASK minloc(array, mask=m)
2532 I.e. in the case of minloc(array,mask), mask will be in the second
2533 position of the argument list and we'll have to fix that up. */
2536 gfc_check_minloc_maxloc (gfc_actual_arglist
*ap
)
2538 gfc_expr
*a
, *m
, *d
;
2541 if (int_or_real_check (a
, 0) == FAILURE
|| array_check (a
, 0) == FAILURE
)
2545 m
= ap
->next
->next
->expr
;
2547 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2548 && ap
->next
->name
== NULL
)
2552 ap
->next
->expr
= NULL
;
2553 ap
->next
->next
->expr
= m
;
2556 if (dim_check (d
, 1, false) == FAILURE
)
2559 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2562 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2566 && gfc_check_conformance (a
, m
,
2567 "arguments '%s' and '%s' for intrinsic %s",
2568 gfc_current_intrinsic_arg
[0]->name
,
2569 gfc_current_intrinsic_arg
[2]->name
,
2570 gfc_current_intrinsic
) == FAILURE
)
2577 /* Similar to minloc/maxloc, the argument list might need to be
2578 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
2579 difference is that MINLOC/MAXLOC take an additional KIND argument.
2580 The possibilities are:
2586 NULL MASK minval(array, mask=m)
2589 I.e. in the case of minval(array,mask), mask will be in the second
2590 position of the argument list and we'll have to fix that up. */
2593 check_reduction (gfc_actual_arglist
*ap
)
2595 gfc_expr
*a
, *m
, *d
;
2599 m
= ap
->next
->next
->expr
;
2601 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
2602 && ap
->next
->name
== NULL
)
2606 ap
->next
->expr
= NULL
;
2607 ap
->next
->next
->expr
= m
;
2610 if (dim_check (d
, 1, false) == FAILURE
)
2613 if (dim_rank_check (d
, a
, 0) == FAILURE
)
2616 if (m
!= NULL
&& type_check (m
, 2, BT_LOGICAL
) == FAILURE
)
2620 && gfc_check_conformance (a
, m
,
2621 "arguments '%s' and '%s' for intrinsic %s",
2622 gfc_current_intrinsic_arg
[0]->name
,
2623 gfc_current_intrinsic_arg
[2]->name
,
2624 gfc_current_intrinsic
) == FAILURE
)
2632 gfc_check_minval_maxval (gfc_actual_arglist
*ap
)
2634 if (int_or_real_check (ap
->expr
, 0) == FAILURE
2635 || array_check (ap
->expr
, 0) == FAILURE
)
2638 return check_reduction (ap
);
2643 gfc_check_product_sum (gfc_actual_arglist
*ap
)
2645 if (numeric_check (ap
->expr
, 0) == FAILURE
2646 || array_check (ap
->expr
, 0) == FAILURE
)
2649 return check_reduction (ap
);
2653 /* For IANY, IALL and IPARITY. */
2656 gfc_check_mask (gfc_expr
*i
, gfc_expr
*kind
)
2660 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
2663 if (nonnegative_check ("I", i
) == FAILURE
)
2666 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
2670 gfc_extract_int (kind
, &k
);
2672 k
= gfc_default_integer_kind
;
2674 if (less_than_bitsizekind ("I", i
, k
) == FAILURE
)
2682 gfc_check_transf_bit_intrins (gfc_actual_arglist
*ap
)
2684 if (ap
->expr
->ts
.type
!= BT_INTEGER
)
2686 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER",
2687 gfc_current_intrinsic_arg
[0]->name
,
2688 gfc_current_intrinsic
, &ap
->expr
->where
);
2692 if (array_check (ap
->expr
, 0) == FAILURE
)
2695 return check_reduction (ap
);
2700 gfc_check_merge (gfc_expr
*tsource
, gfc_expr
*fsource
, gfc_expr
*mask
)
2702 if (same_type_check (tsource
, 0, fsource
, 1) == FAILURE
)
2705 if (type_check (mask
, 2, BT_LOGICAL
) == FAILURE
)
2708 if (tsource
->ts
.type
== BT_CHARACTER
)
2709 return gfc_check_same_strlen (tsource
, fsource
, "MERGE intrinsic");
2716 gfc_check_merge_bits (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*mask
)
2718 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
2721 if (type_check (j
, 1, BT_INTEGER
) == FAILURE
)
2724 if (type_check (mask
, 2, BT_INTEGER
) == FAILURE
)
2727 if (same_type_check (i
, 0, j
, 1) == FAILURE
)
2730 if (same_type_check (i
, 0, mask
, 2) == FAILURE
)
2738 gfc_check_move_alloc (gfc_expr
*from
, gfc_expr
*to
)
2740 if (variable_check (from
, 0, false) == FAILURE
)
2742 if (allocatable_check (from
, 0) == FAILURE
)
2744 if (gfc_is_coindexed (from
))
2746 gfc_error ("The FROM argument to MOVE_ALLOC at %L shall not be "
2747 "coindexed", &from
->where
);
2751 if (variable_check (to
, 1, false) == FAILURE
)
2753 if (allocatable_check (to
, 1) == FAILURE
)
2755 if (gfc_is_coindexed (to
))
2757 gfc_error ("The TO argument to MOVE_ALLOC at %L shall not be "
2758 "coindexed", &to
->where
);
2762 if (from
->ts
.type
== BT_CLASS
&& to
->ts
.type
== BT_DERIVED
)
2764 gfc_error ("The TO arguments in MOVE_ALLOC at %L must be "
2765 "polymorphic if FROM is polymorphic",
2770 if (same_type_check (to
, 1, from
, 0) == FAILURE
)
2773 if (to
->rank
!= from
->rank
)
2775 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
2776 "must have the same rank %d/%d", &to
->where
, from
->rank
,
2781 /* IR F08/0040; cf. 12-006A. */
2782 if (gfc_get_corank (to
) != gfc_get_corank (from
))
2784 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
2785 "must have the same corank %d/%d", &to
->where
,
2786 gfc_get_corank (from
), gfc_get_corank (to
));
2790 /* CLASS arguments: Make sure the vtab of from is present. */
2791 if (to
->ts
.type
== BT_CLASS
&& !UNLIMITED_POLY (from
))
2793 if (from
->ts
.type
== BT_CLASS
|| from
->ts
.type
== BT_DERIVED
)
2794 gfc_find_derived_vtab (from
->ts
.u
.derived
);
2796 gfc_find_intrinsic_vtab (&from
->ts
);
2804 gfc_check_nearest (gfc_expr
*x
, gfc_expr
*s
)
2806 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
2809 if (type_check (s
, 1, BT_REAL
) == FAILURE
)
2812 if (s
->expr_type
== EXPR_CONSTANT
)
2814 if (mpfr_sgn (s
->value
.real
) == 0)
2816 gfc_error ("Argument 'S' of NEAREST at %L shall not be zero",
2827 gfc_check_new_line (gfc_expr
*a
)
2829 if (type_check (a
, 0, BT_CHARACTER
) == FAILURE
)
2837 gfc_check_norm2 (gfc_expr
*array
, gfc_expr
*dim
)
2839 if (type_check (array
, 0, BT_REAL
) == FAILURE
)
2842 if (array_check (array
, 0) == FAILURE
)
2845 if (dim_rank_check (dim
, array
, false) == FAILURE
)
2852 gfc_check_null (gfc_expr
*mold
)
2854 symbol_attribute attr
;
2859 if (variable_check (mold
, 0, true) == FAILURE
)
2862 attr
= gfc_variable_attr (mold
, NULL
);
2864 if (!attr
.pointer
&& !attr
.proc_pointer
&& !attr
.allocatable
)
2866 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a POINTER, "
2867 "ALLOCATABLE or procedure pointer",
2868 gfc_current_intrinsic_arg
[0]->name
,
2869 gfc_current_intrinsic
, &mold
->where
);
2873 if (attr
.allocatable
2874 && gfc_notify_std (GFC_STD_F2003
, "NULL intrinsic with "
2875 "allocatable MOLD at %L", &mold
->where
) == FAILURE
)
2879 if (gfc_is_coindexed (mold
))
2881 gfc_error ("'%s' argument of '%s' intrinsic at %L shall not be "
2882 "coindexed", gfc_current_intrinsic_arg
[0]->name
,
2883 gfc_current_intrinsic
, &mold
->where
);
2892 gfc_check_pack (gfc_expr
*array
, gfc_expr
*mask
, gfc_expr
*vector
)
2894 if (array_check (array
, 0) == FAILURE
)
2897 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
2900 if (gfc_check_conformance (array
, mask
,
2901 "arguments '%s' and '%s' for intrinsic '%s'",
2902 gfc_current_intrinsic_arg
[0]->name
,
2903 gfc_current_intrinsic_arg
[1]->name
,
2904 gfc_current_intrinsic
) == FAILURE
)
2909 mpz_t array_size
, vector_size
;
2910 bool have_array_size
, have_vector_size
;
2912 if (same_type_check (array
, 0, vector
, 2) == FAILURE
)
2915 if (rank_check (vector
, 2, 1) == FAILURE
)
2918 /* VECTOR requires at least as many elements as MASK
2919 has .TRUE. values. */
2920 have_array_size
= gfc_array_size (array
, &array_size
) == SUCCESS
;
2921 have_vector_size
= gfc_array_size (vector
, &vector_size
) == SUCCESS
;
2923 if (have_vector_size
2924 && (mask
->expr_type
== EXPR_ARRAY
2925 || (mask
->expr_type
== EXPR_CONSTANT
2926 && have_array_size
)))
2928 int mask_true_values
= 0;
2930 if (mask
->expr_type
== EXPR_ARRAY
)
2932 gfc_constructor
*mask_ctor
;
2933 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
2936 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
2938 mask_true_values
= 0;
2942 if (mask_ctor
->expr
->value
.logical
)
2945 mask_ctor
= gfc_constructor_next (mask_ctor
);
2948 else if (mask
->expr_type
== EXPR_CONSTANT
&& mask
->value
.logical
)
2949 mask_true_values
= mpz_get_si (array_size
);
2951 if (mpz_get_si (vector_size
) < mask_true_values
)
2953 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
2954 "provide at least as many elements as there "
2955 "are .TRUE. values in '%s' (%ld/%d)",
2956 gfc_current_intrinsic_arg
[2]->name
,
2957 gfc_current_intrinsic
, &vector
->where
,
2958 gfc_current_intrinsic_arg
[1]->name
,
2959 mpz_get_si (vector_size
), mask_true_values
);
2964 if (have_array_size
)
2965 mpz_clear (array_size
);
2966 if (have_vector_size
)
2967 mpz_clear (vector_size
);
2975 gfc_check_parity (gfc_expr
*mask
, gfc_expr
*dim
)
2977 if (type_check (mask
, 0, BT_LOGICAL
) == FAILURE
)
2980 if (array_check (mask
, 0) == FAILURE
)
2983 if (dim_rank_check (dim
, mask
, false) == FAILURE
)
2991 gfc_check_precision (gfc_expr
*x
)
2993 if (real_or_complex_check (x
, 0) == FAILURE
)
3001 gfc_check_present (gfc_expr
*a
)
3005 if (variable_check (a
, 0, true) == FAILURE
)
3008 sym
= a
->symtree
->n
.sym
;
3009 if (!sym
->attr
.dummy
)
3011 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a "
3012 "dummy variable", gfc_current_intrinsic_arg
[0]->name
,
3013 gfc_current_intrinsic
, &a
->where
);
3017 if (!sym
->attr
.optional
)
3019 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of "
3020 "an OPTIONAL dummy variable",
3021 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3026 /* 13.14.82 PRESENT(A)
3028 Argument. A shall be the name of an optional dummy argument that is
3029 accessible in the subprogram in which the PRESENT function reference
3033 && !(a
->ref
->next
== NULL
&& a
->ref
->type
== REF_ARRAY
3034 && (a
->ref
->u
.ar
.type
== AR_FULL
3035 || (a
->ref
->u
.ar
.type
== AR_ELEMENT
3036 && a
->ref
->u
.ar
.as
->rank
== 0))))
3038 gfc_error ("'%s' argument of '%s' intrinsic at %L must not be a "
3039 "subobject of '%s'", gfc_current_intrinsic_arg
[0]->name
,
3040 gfc_current_intrinsic
, &a
->where
, sym
->name
);
3049 gfc_check_radix (gfc_expr
*x
)
3051 if (int_or_real_check (x
, 0) == FAILURE
)
3059 gfc_check_range (gfc_expr
*x
)
3061 if (numeric_check (x
, 0) == FAILURE
)
3069 gfc_check_rank (gfc_expr
*a ATTRIBUTE_UNUSED
)
3071 /* Any data object is allowed; a "data object" is a "constant (4.1.3),
3072 variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
3074 bool is_variable
= true;
3076 /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
3077 if (a
->expr_type
== EXPR_FUNCTION
)
3078 is_variable
= a
->value
.function
.esym
3079 ? a
->value
.function
.esym
->result
->attr
.pointer
3080 : a
->symtree
->n
.sym
->result
->attr
.pointer
;
3082 if (a
->expr_type
== EXPR_OP
|| a
->expr_type
== EXPR_NULL
3083 || a
->expr_type
== EXPR_COMPCALL
|| a
->expr_type
== EXPR_PPC
3086 gfc_error ("The argument of the RANK intrinsic at %L must be a data "
3087 "object", &a
->where
);
3095 /* real, float, sngl. */
3097 gfc_check_real (gfc_expr
*a
, gfc_expr
*kind
)
3099 if (numeric_check (a
, 0) == FAILURE
)
3102 if (kind_check (kind
, 1, BT_REAL
) == FAILURE
)
3110 gfc_check_rename (gfc_expr
*path1
, gfc_expr
*path2
)
3112 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
3114 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
3117 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
3119 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
3127 gfc_check_rename_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
3129 if (type_check (path1
, 0, BT_CHARACTER
) == FAILURE
)
3131 if (kind_value_check (path1
, 0, gfc_default_character_kind
) == FAILURE
)
3134 if (type_check (path2
, 1, BT_CHARACTER
) == FAILURE
)
3136 if (kind_value_check (path2
, 1, gfc_default_character_kind
) == FAILURE
)
3142 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
3145 if (scalar_check (status
, 2) == FAILURE
)
3153 gfc_check_repeat (gfc_expr
*x
, gfc_expr
*y
)
3155 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3158 if (scalar_check (x
, 0) == FAILURE
)
3161 if (type_check (y
, 0, BT_INTEGER
) == FAILURE
)
3164 if (scalar_check (y
, 1) == FAILURE
)
3172 gfc_check_reshape (gfc_expr
*source
, gfc_expr
*shape
,
3173 gfc_expr
*pad
, gfc_expr
*order
)
3179 if (array_check (source
, 0) == FAILURE
)
3182 if (rank_check (shape
, 1, 1) == FAILURE
)
3185 if (type_check (shape
, 1, BT_INTEGER
) == FAILURE
)
3188 if (gfc_array_size (shape
, &size
) != SUCCESS
)
3190 gfc_error ("'shape' argument of 'reshape' intrinsic at %L must be an "
3191 "array of constant size", &shape
->where
);
3195 shape_size
= mpz_get_ui (size
);
3198 if (shape_size
<= 0)
3200 gfc_error ("'%s' argument of '%s' intrinsic at %L is empty",
3201 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3205 else if (shape_size
> GFC_MAX_DIMENSIONS
)
3207 gfc_error ("'shape' argument of 'reshape' intrinsic at %L has more "
3208 "than %d elements", &shape
->where
, GFC_MAX_DIMENSIONS
);
3211 else if (shape
->expr_type
== EXPR_ARRAY
)
3215 for (i
= 0; i
< shape_size
; ++i
)
3217 e
= gfc_constructor_lookup_expr (shape
->value
.constructor
, i
);
3218 if (e
->expr_type
!= EXPR_CONSTANT
)
3221 gfc_extract_int (e
, &extent
);
3224 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3225 "negative element (%d)",
3226 gfc_current_intrinsic_arg
[1]->name
,
3227 gfc_current_intrinsic
, &e
->where
, extent
);
3235 if (same_type_check (source
, 0, pad
, 2) == FAILURE
)
3238 if (array_check (pad
, 2) == FAILURE
)
3244 if (array_check (order
, 3) == FAILURE
)
3247 if (type_check (order
, 3, BT_INTEGER
) == FAILURE
)
3250 if (order
->expr_type
== EXPR_ARRAY
)
3252 int i
, order_size
, dim
, perm
[GFC_MAX_DIMENSIONS
];
3255 for (i
= 0; i
< GFC_MAX_DIMENSIONS
; ++i
)
3258 gfc_array_size (order
, &size
);
3259 order_size
= mpz_get_ui (size
);
3262 if (order_size
!= shape_size
)
3264 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3265 "has wrong number of elements (%d/%d)",
3266 gfc_current_intrinsic_arg
[3]->name
,
3267 gfc_current_intrinsic
, &order
->where
,
3268 order_size
, shape_size
);
3272 for (i
= 1; i
<= order_size
; ++i
)
3274 e
= gfc_constructor_lookup_expr (order
->value
.constructor
, i
-1);
3275 if (e
->expr_type
!= EXPR_CONSTANT
)
3278 gfc_extract_int (e
, &dim
);
3280 if (dim
< 1 || dim
> order_size
)
3282 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3283 "has out-of-range dimension (%d)",
3284 gfc_current_intrinsic_arg
[3]->name
,
3285 gfc_current_intrinsic
, &e
->where
, dim
);
3289 if (perm
[dim
-1] != 0)
3291 gfc_error ("'%s' argument of '%s' intrinsic at %L has "
3292 "invalid permutation of dimensions (dimension "
3294 gfc_current_intrinsic_arg
[3]->name
,
3295 gfc_current_intrinsic
, &e
->where
, dim
);
3304 if (pad
== NULL
&& shape
->expr_type
== EXPR_ARRAY
3305 && gfc_is_constant_expr (shape
)
3306 && !(source
->expr_type
== EXPR_VARIABLE
&& source
->symtree
->n
.sym
->as
3307 && source
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
))
3309 /* Check the match in size between source and destination. */
3310 if (gfc_array_size (source
, &nelems
) == SUCCESS
)
3316 mpz_init_set_ui (size
, 1);
3317 for (c
= gfc_constructor_first (shape
->value
.constructor
);
3318 c
; c
= gfc_constructor_next (c
))
3319 mpz_mul (size
, size
, c
->expr
->value
.integer
);
3321 test
= mpz_cmp (nelems
, size
) < 0 && mpz_cmp_ui (size
, 0) > 0;
3327 gfc_error ("Without padding, there are not enough elements "
3328 "in the intrinsic RESHAPE source at %L to match "
3329 "the shape", &source
->where
);
3340 gfc_check_same_type_as (gfc_expr
*a
, gfc_expr
*b
)
3342 if (a
->ts
.type
!= BT_DERIVED
&& a
->ts
.type
!= BT_CLASS
)
3344 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3345 "cannot be of type %s",
3346 gfc_current_intrinsic_arg
[0]->name
,
3347 gfc_current_intrinsic
,
3348 &a
->where
, gfc_typename (&a
->ts
));
3352 if (!(gfc_type_is_extensible (a
->ts
.u
.derived
) || UNLIMITED_POLY (a
)))
3354 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3355 "must be of an extensible type",
3356 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3361 if (b
->ts
.type
!= BT_DERIVED
&& b
->ts
.type
!= BT_CLASS
)
3363 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3364 "cannot be of type %s",
3365 gfc_current_intrinsic_arg
[0]->name
,
3366 gfc_current_intrinsic
,
3367 &b
->where
, gfc_typename (&b
->ts
));
3371 if (!(gfc_type_is_extensible (b
->ts
.u
.derived
) || UNLIMITED_POLY (b
)))
3373 gfc_error ("'%s' argument of '%s' intrinsic at %L "
3374 "must be of an extensible type",
3375 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3385 gfc_check_scale (gfc_expr
*x
, gfc_expr
*i
)
3387 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3390 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
3398 gfc_check_scan (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
3400 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
3403 if (type_check (y
, 1, BT_CHARACTER
) == FAILURE
)
3406 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
3409 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
3411 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
3412 "with KIND argument at %L",
3413 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3416 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
3424 gfc_check_secnds (gfc_expr
*r
)
3426 if (type_check (r
, 0, BT_REAL
) == FAILURE
)
3429 if (kind_value_check (r
, 0, 4) == FAILURE
)
3432 if (scalar_check (r
, 0) == FAILURE
)
3440 gfc_check_selected_char_kind (gfc_expr
*name
)
3442 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3445 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3448 if (scalar_check (name
, 0) == FAILURE
)
3456 gfc_check_selected_int_kind (gfc_expr
*r
)
3458 if (type_check (r
, 0, BT_INTEGER
) == FAILURE
)
3461 if (scalar_check (r
, 0) == FAILURE
)
3469 gfc_check_selected_real_kind (gfc_expr
*p
, gfc_expr
*r
, gfc_expr
*radix
)
3471 if (p
== NULL
&& r
== NULL
3472 && gfc_notify_std (GFC_STD_F2008
, "SELECTED_REAL_KIND with"
3473 " neither 'P' nor 'R' argument at %L",
3474 gfc_current_intrinsic_where
) == FAILURE
)
3479 if (type_check (p
, 0, BT_INTEGER
) == FAILURE
)
3482 if (scalar_check (p
, 0) == FAILURE
)
3488 if (type_check (r
, 1, BT_INTEGER
) == FAILURE
)
3491 if (scalar_check (r
, 1) == FAILURE
)
3497 if (type_check (radix
, 1, BT_INTEGER
) == FAILURE
)
3500 if (scalar_check (radix
, 1) == FAILURE
)
3503 if (gfc_notify_std (GFC_STD_F2008
, "'%s' intrinsic with "
3504 "RADIX argument at %L", gfc_current_intrinsic
,
3505 &radix
->where
) == FAILURE
)
3514 gfc_check_set_exponent (gfc_expr
*x
, gfc_expr
*i
)
3516 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
3519 if (type_check (i
, 1, BT_INTEGER
) == FAILURE
)
3527 gfc_check_shape (gfc_expr
*source
, gfc_expr
*kind
)
3531 if (source
->rank
== 0 || source
->expr_type
!= EXPR_VARIABLE
)
3534 ar
= gfc_find_array_ref (source
);
3536 if (ar
->as
&& ar
->as
->type
== AS_ASSUMED_SIZE
&& ar
->type
== AR_FULL
)
3538 gfc_error ("'source' argument of 'shape' intrinsic at %L must not be "
3539 "an assumed size array", &source
->where
);
3543 if (kind_check (kind
, 1, BT_INTEGER
) == FAILURE
)
3545 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
3546 "with KIND argument at %L",
3547 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3555 gfc_check_shift (gfc_expr
*i
, gfc_expr
*shift
)
3557 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
3560 if (type_check (shift
, 0, BT_INTEGER
) == FAILURE
)
3563 if (nonnegative_check ("SHIFT", shift
) == FAILURE
)
3566 if (less_than_bitsize1 ("I", i
, "SHIFT", shift
, true) == FAILURE
)
3574 gfc_check_sign (gfc_expr
*a
, gfc_expr
*b
)
3576 if (int_or_real_check (a
, 0) == FAILURE
)
3579 if (same_type_check (a
, 0, b
, 1) == FAILURE
)
3587 gfc_check_size (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
3589 if (array_check (array
, 0) == FAILURE
)
3592 if (dim_check (dim
, 1, true) == FAILURE
)
3595 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
3598 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
3600 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
3601 "with KIND argument at %L",
3602 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
3611 gfc_check_sizeof (gfc_expr
*arg
)
3613 if (arg
->ts
.type
== BT_PROCEDURE
)
3615 gfc_error ("'%s' argument of '%s' intrinsic at %L may not be a procedure",
3616 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3625 gfc_check_c_sizeof (gfc_expr
*arg
)
3627 if (gfc_verify_c_interop (&arg
->ts
) != SUCCESS
)
3629 gfc_error ("'%s' argument of '%s' intrinsic at %L must be an "
3630 "interoperable data entity",
3631 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3640 gfc_check_sleep_sub (gfc_expr
*seconds
)
3642 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
3645 if (scalar_check (seconds
, 0) == FAILURE
)
3652 gfc_check_sngl (gfc_expr
*a
)
3654 if (type_check (a
, 0, BT_REAL
) == FAILURE
)
3657 if ((a
->ts
.kind
!= gfc_default_double_kind
)
3658 && gfc_notify_std (GFC_STD_GNU
, "non double precision "
3659 "REAL argument to %s intrinsic at %L",
3660 gfc_current_intrinsic
, &a
->where
) == FAILURE
)
3667 gfc_check_spread (gfc_expr
*source
, gfc_expr
*dim
, gfc_expr
*ncopies
)
3669 if (source
->rank
>= GFC_MAX_DIMENSIONS
)
3671 gfc_error ("'%s' argument of '%s' intrinsic at %L must be less "
3672 "than rank %d", gfc_current_intrinsic_arg
[0]->name
,
3673 gfc_current_intrinsic
, &source
->where
, GFC_MAX_DIMENSIONS
);
3681 if (dim_check (dim
, 1, false) == FAILURE
)
3684 /* dim_rank_check() does not apply here. */
3686 && dim
->expr_type
== EXPR_CONSTANT
3687 && (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
3688 || mpz_cmp_ui (dim
->value
.integer
, source
->rank
+ 1) > 0))
3690 gfc_error ("'%s' argument of '%s' intrinsic at %L is not a valid "
3691 "dimension index", gfc_current_intrinsic_arg
[1]->name
,
3692 gfc_current_intrinsic
, &dim
->where
);
3696 if (type_check (ncopies
, 2, BT_INTEGER
) == FAILURE
)
3699 if (scalar_check (ncopies
, 2) == FAILURE
)
3706 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
3710 gfc_check_fgetputc_sub (gfc_expr
*unit
, gfc_expr
*c
, gfc_expr
*status
)
3712 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3715 if (scalar_check (unit
, 0) == FAILURE
)
3718 if (type_check (c
, 1, BT_CHARACTER
) == FAILURE
)
3720 if (kind_value_check (c
, 1, gfc_default_character_kind
) == FAILURE
)
3726 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3727 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
3728 || scalar_check (status
, 2) == FAILURE
)
3736 gfc_check_fgetputc (gfc_expr
*unit
, gfc_expr
*c
)
3738 return gfc_check_fgetputc_sub (unit
, c
, NULL
);
3743 gfc_check_fgetput_sub (gfc_expr
*c
, gfc_expr
*status
)
3745 if (type_check (c
, 0, BT_CHARACTER
) == FAILURE
)
3747 if (kind_value_check (c
, 0, gfc_default_character_kind
) == FAILURE
)
3753 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
3754 || kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
3755 || scalar_check (status
, 1) == FAILURE
)
3763 gfc_check_fgetput (gfc_expr
*c
)
3765 return gfc_check_fgetput_sub (c
, NULL
);
3770 gfc_check_fseek_sub (gfc_expr
*unit
, gfc_expr
*offset
, gfc_expr
*whence
, gfc_expr
*status
)
3772 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3775 if (scalar_check (unit
, 0) == FAILURE
)
3778 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3781 if (scalar_check (offset
, 1) == FAILURE
)
3784 if (type_check (whence
, 2, BT_INTEGER
) == FAILURE
)
3787 if (scalar_check (whence
, 2) == FAILURE
)
3793 if (type_check (status
, 3, BT_INTEGER
) == FAILURE
)
3796 if (kind_value_check (status
, 3, 4) == FAILURE
)
3799 if (scalar_check (status
, 3) == FAILURE
)
3808 gfc_check_fstat (gfc_expr
*unit
, gfc_expr
*array
)
3810 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3813 if (scalar_check (unit
, 0) == FAILURE
)
3816 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3817 || kind_value_check (unit
, 0, gfc_default_integer_kind
) == FAILURE
)
3820 if (array_check (array
, 1) == FAILURE
)
3828 gfc_check_fstat_sub (gfc_expr
*unit
, gfc_expr
*array
, gfc_expr
*status
)
3830 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3833 if (scalar_check (unit
, 0) == FAILURE
)
3836 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3837 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3840 if (array_check (array
, 1) == FAILURE
)
3846 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3847 || kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
3850 if (scalar_check (status
, 2) == FAILURE
)
3858 gfc_check_ftell (gfc_expr
*unit
)
3860 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3863 if (scalar_check (unit
, 0) == FAILURE
)
3871 gfc_check_ftell_sub (gfc_expr
*unit
, gfc_expr
*offset
)
3873 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
3876 if (scalar_check (unit
, 0) == FAILURE
)
3879 if (type_check (offset
, 1, BT_INTEGER
) == FAILURE
)
3882 if (scalar_check (offset
, 1) == FAILURE
)
3890 gfc_check_stat (gfc_expr
*name
, gfc_expr
*array
)
3892 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3894 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3897 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3898 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3901 if (array_check (array
, 1) == FAILURE
)
3909 gfc_check_stat_sub (gfc_expr
*name
, gfc_expr
*array
, gfc_expr
*status
)
3911 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
3913 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
3916 if (type_check (array
, 1, BT_INTEGER
) == FAILURE
3917 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3920 if (array_check (array
, 1) == FAILURE
)
3926 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
3927 || kind_value_check (array
, 1, gfc_default_integer_kind
) == FAILURE
)
3930 if (scalar_check (status
, 2) == FAILURE
)
3938 gfc_check_image_index (gfc_expr
*coarray
, gfc_expr
*sub
)
3942 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3944 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3948 if (coarray_check (coarray
, 0) == FAILURE
)
3953 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
3954 gfc_current_intrinsic_arg
[1]->name
, &sub
->where
);
3958 if (gfc_array_size (sub
, &nelems
) == SUCCESS
)
3960 int corank
= gfc_get_corank (coarray
);
3962 if (mpz_cmp_ui (nelems
, corank
) != 0)
3964 gfc_error ("The number of array elements of the SUB argument to "
3965 "IMAGE_INDEX at %L shall be %d (corank) not %d",
3966 &sub
->where
, corank
, (int) mpz_get_si (nelems
));
3978 gfc_check_this_image (gfc_expr
*coarray
, gfc_expr
*dim
)
3980 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
3982 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
3986 if (dim
!= NULL
&& coarray
== NULL
)
3988 gfc_error ("DIM argument without ARRAY argument not allowed for THIS_IMAGE "
3989 "intrinsic at %L", &dim
->where
);
3993 if (coarray
== NULL
)
3996 if (coarray_check (coarray
, 0) == FAILURE
)
4001 if (dim_check (dim
, 1, false) == FAILURE
)
4004 if (dim_corank_check (dim
, coarray
) == FAILURE
)
4011 /* Calculate the sizes for transfer, used by gfc_check_transfer and also
4012 by gfc_simplify_transfer. Return FAILURE if we cannot do so. */
4015 gfc_calculate_transfer_sizes (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
,
4016 size_t *source_size
, size_t *result_size
,
4017 size_t *result_length_p
)
4019 size_t result_elt_size
;
4021 gfc_expr
*mold_element
;
4023 if (source
->expr_type
== EXPR_FUNCTION
)
4026 if (size
&& size
->expr_type
!= EXPR_CONSTANT
)
4029 /* Calculate the size of the source. */
4030 if (source
->expr_type
== EXPR_ARRAY
4031 && gfc_array_size (source
, &tmp
) == FAILURE
)
4034 *source_size
= gfc_target_expr_size (source
);
4035 if (*source_size
== 0)
4038 mold_element
= mold
->expr_type
== EXPR_ARRAY
4039 ? gfc_constructor_first (mold
->value
.constructor
)->expr
4042 /* Determine the size of the element. */
4043 result_elt_size
= gfc_target_expr_size (mold_element
);
4044 if (result_elt_size
== 0)
4047 if (mold
->expr_type
== EXPR_ARRAY
|| mold
->rank
|| size
)
4052 result_length
= (size_t)mpz_get_ui (size
->value
.integer
);
4055 result_length
= *source_size
/ result_elt_size
;
4056 if (result_length
* result_elt_size
< *source_size
)
4060 *result_size
= result_length
* result_elt_size
;
4061 if (result_length_p
)
4062 *result_length_p
= result_length
;
4065 *result_size
= result_elt_size
;
4072 gfc_check_transfer (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
)
4077 if (mold
->ts
.type
== BT_HOLLERITH
)
4079 gfc_error ("'MOLD' argument of 'TRANSFER' intrinsic at %L must not be %s",
4080 &mold
->where
, gfc_basic_typename (BT_HOLLERITH
));
4086 if (type_check (size
, 2, BT_INTEGER
) == FAILURE
)
4089 if (scalar_check (size
, 2) == FAILURE
)
4092 if (nonoptional_check (size
, 2) == FAILURE
)
4096 if (!gfc_option
.warn_surprising
)
4099 /* If we can't calculate the sizes, we cannot check any more.
4100 Return SUCCESS for that case. */
4102 if (gfc_calculate_transfer_sizes (source
, mold
, size
, &source_size
,
4103 &result_size
, NULL
) == FAILURE
)
4106 if (source_size
< result_size
)
4107 gfc_warning("Intrinsic TRANSFER at %L has partly undefined result: "
4108 "source size %ld < result size %ld", &source
->where
,
4109 (long) source_size
, (long) result_size
);
4116 gfc_check_transpose (gfc_expr
*matrix
)
4118 if (rank_check (matrix
, 0, 2) == FAILURE
)
4126 gfc_check_ubound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
4128 if (array_check (array
, 0) == FAILURE
)
4131 if (dim_check (dim
, 1, false) == FAILURE
)
4134 if (dim_rank_check (dim
, array
, 0) == FAILURE
)
4137 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
4139 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
4140 "with KIND argument at %L",
4141 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
4149 gfc_check_ucobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
4151 if (gfc_option
.coarray
== GFC_FCOARRAY_NONE
)
4153 gfc_fatal_error ("Coarrays disabled at %C, use -fcoarray= to enable");
4157 if (coarray_check (coarray
, 0) == FAILURE
)
4162 if (dim_check (dim
, 1, false) == FAILURE
)
4165 if (dim_corank_check (dim
, coarray
) == FAILURE
)
4169 if (kind_check (kind
, 2, BT_INTEGER
) == FAILURE
)
4177 gfc_check_unpack (gfc_expr
*vector
, gfc_expr
*mask
, gfc_expr
*field
)
4181 if (rank_check (vector
, 0, 1) == FAILURE
)
4184 if (array_check (mask
, 1) == FAILURE
)
4187 if (type_check (mask
, 1, BT_LOGICAL
) == FAILURE
)
4190 if (same_type_check (vector
, 0, field
, 2) == FAILURE
)
4193 if (mask
->expr_type
== EXPR_ARRAY
4194 && gfc_array_size (vector
, &vector_size
) == SUCCESS
)
4196 int mask_true_count
= 0;
4197 gfc_constructor
*mask_ctor
;
4198 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
4201 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
4203 mask_true_count
= 0;
4207 if (mask_ctor
->expr
->value
.logical
)
4210 mask_ctor
= gfc_constructor_next (mask_ctor
);
4213 if (mpz_get_si (vector_size
) < mask_true_count
)
4215 gfc_error ("'%s' argument of '%s' intrinsic at %L must "
4216 "provide at least as many elements as there "
4217 "are .TRUE. values in '%s' (%ld/%d)",
4218 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4219 &vector
->where
, gfc_current_intrinsic_arg
[1]->name
,
4220 mpz_get_si (vector_size
), mask_true_count
);
4224 mpz_clear (vector_size
);
4227 if (mask
->rank
!= field
->rank
&& field
->rank
!= 0)
4229 gfc_error ("'%s' argument of '%s' intrinsic at %L must have "
4230 "the same rank as '%s' or be a scalar",
4231 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
4232 &field
->where
, gfc_current_intrinsic_arg
[1]->name
);
4236 if (mask
->rank
== field
->rank
)
4239 for (i
= 0; i
< field
->rank
; i
++)
4240 if (! identical_dimen_shape (mask
, i
, field
, i
))
4242 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L "
4243 "must have identical shape.",
4244 gfc_current_intrinsic_arg
[2]->name
,
4245 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4255 gfc_check_verify (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
4257 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
4260 if (same_type_check (x
, 0, y
, 1) == FAILURE
)
4263 if (z
!= NULL
&& type_check (z
, 2, BT_LOGICAL
) == FAILURE
)
4266 if (kind_check (kind
, 3, BT_INTEGER
) == FAILURE
)
4268 if (kind
&& gfc_notify_std (GFC_STD_F2003
, "'%s' intrinsic "
4269 "with KIND argument at %L",
4270 gfc_current_intrinsic
, &kind
->where
) == FAILURE
)
4278 gfc_check_trim (gfc_expr
*x
)
4280 if (type_check (x
, 0, BT_CHARACTER
) == FAILURE
)
4283 if (scalar_check (x
, 0) == FAILURE
)
4291 gfc_check_ttynam (gfc_expr
*unit
)
4293 if (scalar_check (unit
, 0) == FAILURE
)
4296 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4303 /* Common check function for the half a dozen intrinsics that have a
4304 single real argument. */
4307 gfc_check_x (gfc_expr
*x
)
4309 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4316 /************* Check functions for intrinsic subroutines *************/
4319 gfc_check_cpu_time (gfc_expr
*time
)
4321 if (scalar_check (time
, 0) == FAILURE
)
4324 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
4327 if (variable_check (time
, 0, false) == FAILURE
)
4335 gfc_check_date_and_time (gfc_expr
*date
, gfc_expr
*time
,
4336 gfc_expr
*zone
, gfc_expr
*values
)
4340 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
4342 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
4344 if (scalar_check (date
, 0) == FAILURE
)
4346 if (variable_check (date
, 0, false) == FAILURE
)
4352 if (type_check (time
, 1, BT_CHARACTER
) == FAILURE
)
4354 if (kind_value_check (time
, 1, gfc_default_character_kind
) == FAILURE
)
4356 if (scalar_check (time
, 1) == FAILURE
)
4358 if (variable_check (time
, 1, false) == FAILURE
)
4364 if (type_check (zone
, 2, BT_CHARACTER
) == FAILURE
)
4366 if (kind_value_check (zone
, 2, gfc_default_character_kind
) == FAILURE
)
4368 if (scalar_check (zone
, 2) == FAILURE
)
4370 if (variable_check (zone
, 2, false) == FAILURE
)
4376 if (type_check (values
, 3, BT_INTEGER
) == FAILURE
)
4378 if (array_check (values
, 3) == FAILURE
)
4380 if (rank_check (values
, 3, 1) == FAILURE
)
4382 if (variable_check (values
, 3, false) == FAILURE
)
4391 gfc_check_mvbits (gfc_expr
*from
, gfc_expr
*frompos
, gfc_expr
*len
,
4392 gfc_expr
*to
, gfc_expr
*topos
)
4394 if (type_check (from
, 0, BT_INTEGER
) == FAILURE
)
4397 if (type_check (frompos
, 1, BT_INTEGER
) == FAILURE
)
4400 if (type_check (len
, 2, BT_INTEGER
) == FAILURE
)
4403 if (same_type_check (from
, 0, to
, 3) == FAILURE
)
4406 if (variable_check (to
, 3, false) == FAILURE
)
4409 if (type_check (topos
, 4, BT_INTEGER
) == FAILURE
)
4412 if (nonnegative_check ("frompos", frompos
) == FAILURE
)
4415 if (nonnegative_check ("topos", topos
) == FAILURE
)
4418 if (nonnegative_check ("len", len
) == FAILURE
)
4421 if (less_than_bitsize2 ("from", from
, "frompos", frompos
, "len", len
)
4425 if (less_than_bitsize2 ("to", to
, "topos", topos
, "len", len
) == FAILURE
)
4433 gfc_check_random_number (gfc_expr
*harvest
)
4435 if (type_check (harvest
, 0, BT_REAL
) == FAILURE
)
4438 if (variable_check (harvest
, 0, false) == FAILURE
)
4446 gfc_check_random_seed (gfc_expr
*size
, gfc_expr
*put
, gfc_expr
*get
)
4448 unsigned int nargs
= 0, kiss_size
;
4449 locus
*where
= NULL
;
4450 mpz_t put_size
, get_size
;
4451 bool have_gfc_real_16
; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
4453 have_gfc_real_16
= gfc_validate_kind (BT_REAL
, 16, true) != -1;
4455 /* Keep the number of bytes in sync with kiss_size in
4456 libgfortran/intrinsics/random.c. */
4457 kiss_size
= (have_gfc_real_16
? 48 : 32) / gfc_default_integer_kind
;
4461 if (size
->expr_type
!= EXPR_VARIABLE
4462 || !size
->symtree
->n
.sym
->attr
.optional
)
4465 if (scalar_check (size
, 0) == FAILURE
)
4468 if (type_check (size
, 0, BT_INTEGER
) == FAILURE
)
4471 if (variable_check (size
, 0, false) == FAILURE
)
4474 if (kind_value_check (size
, 0, gfc_default_integer_kind
) == FAILURE
)
4480 if (put
->expr_type
!= EXPR_VARIABLE
4481 || !put
->symtree
->n
.sym
->attr
.optional
)
4484 where
= &put
->where
;
4487 if (array_check (put
, 1) == FAILURE
)
4490 if (rank_check (put
, 1, 1) == FAILURE
)
4493 if (type_check (put
, 1, BT_INTEGER
) == FAILURE
)
4496 if (kind_value_check (put
, 1, gfc_default_integer_kind
) == FAILURE
)
4499 if (gfc_array_size (put
, &put_size
) == SUCCESS
4500 && mpz_get_ui (put_size
) < kiss_size
)
4501 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4502 "too small (%i/%i)",
4503 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4504 where
, (int) mpz_get_ui (put_size
), kiss_size
);
4509 if (get
->expr_type
!= EXPR_VARIABLE
4510 || !get
->symtree
->n
.sym
->attr
.optional
)
4513 where
= &get
->where
;
4516 if (array_check (get
, 2) == FAILURE
)
4519 if (rank_check (get
, 2, 1) == FAILURE
)
4522 if (type_check (get
, 2, BT_INTEGER
) == FAILURE
)
4525 if (variable_check (get
, 2, false) == FAILURE
)
4528 if (kind_value_check (get
, 2, gfc_default_integer_kind
) == FAILURE
)
4531 if (gfc_array_size (get
, &get_size
) == SUCCESS
4532 && mpz_get_ui (get_size
) < kiss_size
)
4533 gfc_error ("Size of '%s' argument of '%s' intrinsic at %L "
4534 "too small (%i/%i)",
4535 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
4536 where
, (int) mpz_get_ui (get_size
), kiss_size
);
4539 /* RANDOM_SEED may not have more than one non-optional argument. */
4541 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
, where
);
4548 gfc_check_second_sub (gfc_expr
*time
)
4550 if (scalar_check (time
, 0) == FAILURE
)
4553 if (type_check (time
, 0, BT_REAL
) == FAILURE
)
4556 if (kind_value_check(time
, 0, 4) == FAILURE
)
4563 /* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
4564 count, count_rate, and count_max are all optional arguments */
4567 gfc_check_system_clock (gfc_expr
*count
, gfc_expr
*count_rate
,
4568 gfc_expr
*count_max
)
4572 if (scalar_check (count
, 0) == FAILURE
)
4575 if (type_check (count
, 0, BT_INTEGER
) == FAILURE
)
4578 if (variable_check (count
, 0, false) == FAILURE
)
4582 if (count_rate
!= NULL
)
4584 if (scalar_check (count_rate
, 1) == FAILURE
)
4587 if (type_check (count_rate
, 1, BT_INTEGER
) == FAILURE
)
4590 if (variable_check (count_rate
, 1, false) == FAILURE
)
4594 && same_type_check (count
, 0, count_rate
, 1) == FAILURE
)
4599 if (count_max
!= NULL
)
4601 if (scalar_check (count_max
, 2) == FAILURE
)
4604 if (type_check (count_max
, 2, BT_INTEGER
) == FAILURE
)
4607 if (variable_check (count_max
, 2, false) == FAILURE
)
4611 && same_type_check (count
, 0, count_max
, 2) == FAILURE
)
4614 if (count_rate
!= NULL
4615 && same_type_check (count_rate
, 1, count_max
, 2) == FAILURE
)
4624 gfc_check_irand (gfc_expr
*x
)
4629 if (scalar_check (x
, 0) == FAILURE
)
4632 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4635 if (kind_value_check(x
, 0, 4) == FAILURE
)
4643 gfc_check_alarm_sub (gfc_expr
*seconds
, gfc_expr
*handler
, gfc_expr
*status
)
4645 if (scalar_check (seconds
, 0) == FAILURE
)
4647 if (type_check (seconds
, 0, BT_INTEGER
) == FAILURE
)
4650 if (int_or_proc_check (handler
, 1) == FAILURE
)
4652 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
4658 if (scalar_check (status
, 2) == FAILURE
)
4660 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
4662 if (kind_value_check (status
, 2, gfc_default_integer_kind
) == FAILURE
)
4670 gfc_check_rand (gfc_expr
*x
)
4675 if (scalar_check (x
, 0) == FAILURE
)
4678 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4681 if (kind_value_check(x
, 0, 4) == FAILURE
)
4689 gfc_check_srand (gfc_expr
*x
)
4691 if (scalar_check (x
, 0) == FAILURE
)
4694 if (type_check (x
, 0, BT_INTEGER
) == FAILURE
)
4697 if (kind_value_check(x
, 0, 4) == FAILURE
)
4705 gfc_check_ctime_sub (gfc_expr
*time
, gfc_expr
*result
)
4707 if (scalar_check (time
, 0) == FAILURE
)
4709 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
4712 if (type_check (result
, 1, BT_CHARACTER
) == FAILURE
)
4714 if (kind_value_check (result
, 1, gfc_default_character_kind
) == FAILURE
)
4722 gfc_check_dtime_etime (gfc_expr
*x
)
4724 if (array_check (x
, 0) == FAILURE
)
4727 if (rank_check (x
, 0, 1) == FAILURE
)
4730 if (variable_check (x
, 0, false) == FAILURE
)
4733 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
4736 if (kind_value_check(x
, 0, 4) == FAILURE
)
4744 gfc_check_dtime_etime_sub (gfc_expr
*values
, gfc_expr
*time
)
4746 if (array_check (values
, 0) == FAILURE
)
4749 if (rank_check (values
, 0, 1) == FAILURE
)
4752 if (variable_check (values
, 0, false) == FAILURE
)
4755 if (type_check (values
, 0, BT_REAL
) == FAILURE
)
4758 if (kind_value_check(values
, 0, 4) == FAILURE
)
4761 if (scalar_check (time
, 1) == FAILURE
)
4764 if (type_check (time
, 1, BT_REAL
) == FAILURE
)
4767 if (kind_value_check(time
, 1, 4) == FAILURE
)
4775 gfc_check_fdate_sub (gfc_expr
*date
)
4777 if (type_check (date
, 0, BT_CHARACTER
) == FAILURE
)
4779 if (kind_value_check (date
, 0, gfc_default_character_kind
) == FAILURE
)
4787 gfc_check_gerror (gfc_expr
*msg
)
4789 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
4791 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4799 gfc_check_getcwd_sub (gfc_expr
*cwd
, gfc_expr
*status
)
4801 if (type_check (cwd
, 0, BT_CHARACTER
) == FAILURE
)
4803 if (kind_value_check (cwd
, 0, gfc_default_character_kind
) == FAILURE
)
4809 if (scalar_check (status
, 1) == FAILURE
)
4812 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4820 gfc_check_getarg (gfc_expr
*pos
, gfc_expr
*value
)
4822 if (type_check (pos
, 0, BT_INTEGER
) == FAILURE
)
4825 if (pos
->ts
.kind
> gfc_default_integer_kind
)
4827 gfc_error ("'%s' argument of '%s' intrinsic at %L must be of a kind "
4828 "not wider than the default kind (%d)",
4829 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4830 &pos
->where
, gfc_default_integer_kind
);
4834 if (type_check (value
, 1, BT_CHARACTER
) == FAILURE
)
4836 if (kind_value_check (value
, 1, gfc_default_character_kind
) == FAILURE
)
4844 gfc_check_getlog (gfc_expr
*msg
)
4846 if (type_check (msg
, 0, BT_CHARACTER
) == FAILURE
)
4848 if (kind_value_check (msg
, 0, gfc_default_character_kind
) == FAILURE
)
4856 gfc_check_exit (gfc_expr
*status
)
4861 if (type_check (status
, 0, BT_INTEGER
) == FAILURE
)
4864 if (scalar_check (status
, 0) == FAILURE
)
4872 gfc_check_flush (gfc_expr
*unit
)
4877 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4880 if (scalar_check (unit
, 0) == FAILURE
)
4888 gfc_check_free (gfc_expr
*i
)
4890 if (type_check (i
, 0, BT_INTEGER
) == FAILURE
)
4893 if (scalar_check (i
, 0) == FAILURE
)
4901 gfc_check_hostnm (gfc_expr
*name
)
4903 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4905 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4913 gfc_check_hostnm_sub (gfc_expr
*name
, gfc_expr
*status
)
4915 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
4917 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
4923 if (scalar_check (status
, 1) == FAILURE
)
4926 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
4934 gfc_check_itime_idate (gfc_expr
*values
)
4936 if (array_check (values
, 0) == FAILURE
)
4939 if (rank_check (values
, 0, 1) == FAILURE
)
4942 if (variable_check (values
, 0, false) == FAILURE
)
4945 if (type_check (values
, 0, BT_INTEGER
) == FAILURE
)
4948 if (kind_value_check(values
, 0, gfc_default_integer_kind
) == FAILURE
)
4956 gfc_check_ltime_gmtime (gfc_expr
*time
, gfc_expr
*values
)
4958 if (type_check (time
, 0, BT_INTEGER
) == FAILURE
)
4961 if (kind_value_check(time
, 0, gfc_default_integer_kind
) == FAILURE
)
4964 if (scalar_check (time
, 0) == FAILURE
)
4967 if (array_check (values
, 1) == FAILURE
)
4970 if (rank_check (values
, 1, 1) == FAILURE
)
4973 if (variable_check (values
, 1, false) == FAILURE
)
4976 if (type_check (values
, 1, BT_INTEGER
) == FAILURE
)
4979 if (kind_value_check(values
, 1, gfc_default_integer_kind
) == FAILURE
)
4987 gfc_check_ttynam_sub (gfc_expr
*unit
, gfc_expr
*name
)
4989 if (scalar_check (unit
, 0) == FAILURE
)
4992 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
4995 if (type_check (name
, 1, BT_CHARACTER
) == FAILURE
)
4997 if (kind_value_check (name
, 1, gfc_default_character_kind
) == FAILURE
)
5005 gfc_check_isatty (gfc_expr
*unit
)
5010 if (type_check (unit
, 0, BT_INTEGER
) == FAILURE
)
5013 if (scalar_check (unit
, 0) == FAILURE
)
5021 gfc_check_isnan (gfc_expr
*x
)
5023 if (type_check (x
, 0, BT_REAL
) == FAILURE
)
5031 gfc_check_perror (gfc_expr
*string
)
5033 if (type_check (string
, 0, BT_CHARACTER
) == FAILURE
)
5035 if (kind_value_check (string
, 0, gfc_default_character_kind
) == FAILURE
)
5043 gfc_check_umask (gfc_expr
*mask
)
5045 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
5048 if (scalar_check (mask
, 0) == FAILURE
)
5056 gfc_check_umask_sub (gfc_expr
*mask
, gfc_expr
*old
)
5058 if (type_check (mask
, 0, BT_INTEGER
) == FAILURE
)
5061 if (scalar_check (mask
, 0) == FAILURE
)
5067 if (scalar_check (old
, 1) == FAILURE
)
5070 if (type_check (old
, 1, BT_INTEGER
) == FAILURE
)
5078 gfc_check_unlink (gfc_expr
*name
)
5080 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
5082 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
5090 gfc_check_unlink_sub (gfc_expr
*name
, gfc_expr
*status
)
5092 if (type_check (name
, 0, BT_CHARACTER
) == FAILURE
)
5094 if (kind_value_check (name
, 0, gfc_default_character_kind
) == FAILURE
)
5100 if (scalar_check (status
, 1) == FAILURE
)
5103 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
5111 gfc_check_signal (gfc_expr
*number
, gfc_expr
*handler
)
5113 if (scalar_check (number
, 0) == FAILURE
)
5115 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
5118 if (int_or_proc_check (handler
, 1) == FAILURE
)
5120 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
5128 gfc_check_signal_sub (gfc_expr
*number
, gfc_expr
*handler
, gfc_expr
*status
)
5130 if (scalar_check (number
, 0) == FAILURE
)
5132 if (type_check (number
, 0, BT_INTEGER
) == FAILURE
)
5135 if (int_or_proc_check (handler
, 1) == FAILURE
)
5137 if (handler
->ts
.type
== BT_INTEGER
&& scalar_check (handler
, 1) == FAILURE
)
5143 if (type_check (status
, 2, BT_INTEGER
) == FAILURE
)
5145 if (scalar_check (status
, 2) == FAILURE
)
5153 gfc_check_system_sub (gfc_expr
*cmd
, gfc_expr
*status
)
5155 if (type_check (cmd
, 0, BT_CHARACTER
) == FAILURE
)
5157 if (kind_value_check (cmd
, 0, gfc_default_character_kind
) == FAILURE
)
5160 if (scalar_check (status
, 1) == FAILURE
)
5163 if (type_check (status
, 1, BT_INTEGER
) == FAILURE
)
5166 if (kind_value_check (status
, 1, gfc_default_integer_kind
) == FAILURE
)
5173 /* This is used for the GNU intrinsics AND, OR and XOR. */
5175 gfc_check_and (gfc_expr
*i
, gfc_expr
*j
)
5177 if (i
->ts
.type
!= BT_INTEGER
&& i
->ts
.type
!= BT_LOGICAL
)
5179 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
5180 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
5181 gfc_current_intrinsic
, &i
->where
);
5185 if (j
->ts
.type
!= BT_INTEGER
&& j
->ts
.type
!= BT_LOGICAL
)
5187 gfc_error ("'%s' argument of '%s' intrinsic at %L must be INTEGER "
5188 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
5189 gfc_current_intrinsic
, &j
->where
);
5193 if (i
->ts
.type
!= j
->ts
.type
)
5195 gfc_error ("'%s' and '%s' arguments of '%s' intrinsic at %L must "
5196 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
5197 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
5202 if (scalar_check (i
, 0) == FAILURE
)
5205 if (scalar_check (j
, 1) == FAILURE
)
5213 gfc_check_storage_size (gfc_expr
*a ATTRIBUTE_UNUSED
, gfc_expr
*kind
)
5218 if (type_check (kind
, 1, BT_INTEGER
) == FAILURE
)
5221 if (scalar_check (kind
, 1) == FAILURE
)
5224 if (kind
->expr_type
!= EXPR_CONSTANT
)
5226 gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant",
5227 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,