2 Copyright (C) 2002-2016 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 ("%qs argument of %qs 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 ("%qs argument of %qs 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, e
->symtree
->n
.sym
->ns
)
83 && gfc_numeric_ts (&e
->symtree
->n
.sym
->ts
))
85 e
->ts
= e
->symtree
->n
.sym
->ts
;
89 gfc_error ("%qs argument of %qs intrinsic at %L must be a numeric type",
90 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
97 /* Check that an expression is integer or real. */
100 int_or_real_check (gfc_expr
*e
, int n
)
102 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
)
104 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
105 "or REAL", gfc_current_intrinsic_arg
[n
]->name
,
106 gfc_current_intrinsic
, &e
->where
);
114 /* Check that an expression is real or complex. */
117 real_or_complex_check (gfc_expr
*e
, int n
)
119 if (e
->ts
.type
!= BT_REAL
&& e
->ts
.type
!= BT_COMPLEX
)
121 gfc_error ("%qs argument of %qs intrinsic at %L must be REAL "
122 "or COMPLEX", gfc_current_intrinsic_arg
[n
]->name
,
123 gfc_current_intrinsic
, &e
->where
);
131 /* Check that an expression is INTEGER or PROCEDURE. */
134 int_or_proc_check (gfc_expr
*e
, int n
)
136 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_PROCEDURE
)
138 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
139 "or PROCEDURE", gfc_current_intrinsic_arg
[n
]->name
,
140 gfc_current_intrinsic
, &e
->where
);
148 /* Check that the expression is an optional constant integer
149 and that it specifies a valid kind for that type. */
152 kind_check (gfc_expr
*k
, int n
, bt type
)
159 if (!type_check (k
, n
, BT_INTEGER
))
162 if (!scalar_check (k
, n
))
165 if (!gfc_check_init_expr (k
))
167 gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
168 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
173 if (gfc_extract_int (k
, &kind
) != NULL
174 || gfc_validate_kind (type
, kind
, true) < 0)
176 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type
),
185 /* Make sure the expression is a double precision real. */
188 double_check (gfc_expr
*d
, int n
)
190 if (!type_check (d
, n
, BT_REAL
))
193 if (d
->ts
.kind
!= gfc_default_double_kind
)
195 gfc_error ("%qs argument of %qs intrinsic at %L must be double "
196 "precision", gfc_current_intrinsic_arg
[n
]->name
,
197 gfc_current_intrinsic
, &d
->where
);
206 coarray_check (gfc_expr
*e
, int n
)
208 if (e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
209 && CLASS_DATA (e
)->attr
.codimension
210 && CLASS_DATA (e
)->as
->corank
)
212 gfc_add_class_array_ref (e
);
216 if (!gfc_is_coarray (e
))
218 gfc_error ("Expected coarray variable as %qs argument to the %s "
219 "intrinsic at %L", gfc_current_intrinsic_arg
[n
]->name
,
220 gfc_current_intrinsic
, &e
->where
);
228 /* Make sure the expression is a logical array. */
231 logical_array_check (gfc_expr
*array
, int n
)
233 if (array
->ts
.type
!= BT_LOGICAL
|| array
->rank
== 0)
235 gfc_error ("%qs argument of %qs intrinsic at %L must be a logical "
236 "array", gfc_current_intrinsic_arg
[n
]->name
,
237 gfc_current_intrinsic
, &array
->where
);
245 /* Make sure an expression is an array. */
248 array_check (gfc_expr
*e
, int n
)
250 if (e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
251 && CLASS_DATA (e
)->attr
.dimension
252 && CLASS_DATA (e
)->as
->rank
)
254 gfc_add_class_array_ref (e
);
258 if (e
->rank
!= 0 && e
->ts
.type
!= BT_PROCEDURE
)
261 gfc_error ("%qs argument of %qs intrinsic at %L must be an array",
262 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
269 /* If expr is a constant, then check to ensure that it is greater than
273 nonnegative_check (const char *arg
, gfc_expr
*expr
)
277 if (expr
->expr_type
== EXPR_CONSTANT
)
279 gfc_extract_int (expr
, &i
);
282 gfc_error ("%qs at %L must be nonnegative", arg
, &expr
->where
);
291 /* If expr2 is constant, then check that the value is less than
292 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
295 less_than_bitsize1 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
296 gfc_expr
*expr2
, bool or_equal
)
300 if (expr2
->expr_type
== EXPR_CONSTANT
)
302 gfc_extract_int (expr2
, &i2
);
303 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
305 /* For ISHFT[C], check that |shift| <= bit_size(i). */
311 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
313 gfc_error ("The absolute value of SHIFT at %L must be less "
314 "than or equal to BIT_SIZE(%qs)",
315 &expr2
->where
, arg1
);
322 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
324 gfc_error ("%qs at %L must be less than "
325 "or equal to BIT_SIZE(%qs)",
326 arg2
, &expr2
->where
, arg1
);
332 if (i2
>= gfc_integer_kinds
[i3
].bit_size
)
334 gfc_error ("%qs at %L must be less than BIT_SIZE(%qs)",
335 arg2
, &expr2
->where
, arg1
);
345 /* If expr is constant, then check that the value is less than or equal
346 to the bit_size of the kind k. */
349 less_than_bitsizekind (const char *arg
, gfc_expr
*expr
, int k
)
353 if (expr
->expr_type
!= EXPR_CONSTANT
)
356 i
= gfc_validate_kind (BT_INTEGER
, k
, false);
357 gfc_extract_int (expr
, &val
);
359 if (val
> gfc_integer_kinds
[i
].bit_size
)
361 gfc_error ("%qs at %L must be less than or equal to the BIT_SIZE of "
362 "INTEGER(KIND=%d)", arg
, &expr
->where
, k
);
370 /* If expr2 and expr3 are constants, then check that the value is less than
371 or equal to bit_size(expr1). */
374 less_than_bitsize2 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
375 gfc_expr
*expr2
, const char *arg3
, gfc_expr
*expr3
)
379 if (expr2
->expr_type
== EXPR_CONSTANT
&& expr3
->expr_type
== EXPR_CONSTANT
)
381 gfc_extract_int (expr2
, &i2
);
382 gfc_extract_int (expr3
, &i3
);
384 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
385 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
387 gfc_error ("%<%s + %s%> at %L must be less than or equal "
389 arg2
, arg3
, &expr2
->where
, arg1
);
397 /* Make sure two expressions have the same type. */
400 same_type_check (gfc_expr
*e
, int n
, gfc_expr
*f
, int m
)
402 gfc_typespec
*ets
= &e
->ts
;
403 gfc_typespec
*fts
= &f
->ts
;
405 if (e
->ts
.type
== BT_PROCEDURE
&& e
->symtree
->n
.sym
)
406 ets
= &e
->symtree
->n
.sym
->ts
;
407 if (f
->ts
.type
== BT_PROCEDURE
&& f
->symtree
->n
.sym
)
408 fts
= &f
->symtree
->n
.sym
->ts
;
410 if (gfc_compare_types (ets
, fts
))
413 gfc_error ("%qs argument of %qs intrinsic at %L must be the same type "
414 "and kind as %qs", gfc_current_intrinsic_arg
[m
]->name
,
415 gfc_current_intrinsic
, &f
->where
,
416 gfc_current_intrinsic_arg
[n
]->name
);
422 /* Make sure that an expression has a certain (nonzero) rank. */
425 rank_check (gfc_expr
*e
, int n
, int rank
)
430 gfc_error ("%qs argument of %qs intrinsic at %L must be of rank %d",
431 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
438 /* Make sure a variable expression is not an optional dummy argument. */
441 nonoptional_check (gfc_expr
*e
, int n
)
443 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.optional
)
445 gfc_error ("%qs argument of %qs intrinsic at %L must not be OPTIONAL",
446 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
450 /* TODO: Recursive check on nonoptional variables? */
456 /* Check for ALLOCATABLE attribute. */
459 allocatable_check (gfc_expr
*e
, int n
)
461 symbol_attribute attr
;
463 attr
= gfc_variable_attr (e
, NULL
);
464 if (!attr
.allocatable
|| attr
.associate_var
)
466 gfc_error ("%qs argument of %qs intrinsic at %L must be ALLOCATABLE",
467 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
476 /* Check that an expression has a particular kind. */
479 kind_value_check (gfc_expr
*e
, int n
, int k
)
484 gfc_error ("%qs argument of %qs intrinsic at %L must be of kind %d",
485 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
492 /* Make sure an expression is a variable. */
495 variable_check (gfc_expr
*e
, int n
, bool allow_proc
)
497 if (e
->expr_type
== EXPR_VARIABLE
498 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
499 && (gfc_current_intrinsic_arg
[n
]->intent
== INTENT_OUT
500 || gfc_current_intrinsic_arg
[n
]->intent
== INTENT_INOUT
))
503 bool pointer
= e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
504 && CLASS_DATA (e
->symtree
->n
.sym
)
505 ? CLASS_DATA (e
->symtree
->n
.sym
)->attr
.class_pointer
506 : e
->symtree
->n
.sym
->attr
.pointer
;
508 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
510 if (pointer
&& ref
->type
== REF_COMPONENT
)
512 if (ref
->type
== REF_COMPONENT
513 && ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
514 && CLASS_DATA (ref
->u
.c
.component
)->attr
.class_pointer
)
515 || (ref
->u
.c
.component
->ts
.type
!= BT_CLASS
516 && ref
->u
.c
.component
->attr
.pointer
)))
522 gfc_error ("%qs argument of %qs intrinsic at %L cannot be "
523 "INTENT(IN)", gfc_current_intrinsic_arg
[n
]->name
,
524 gfc_current_intrinsic
, &e
->where
);
529 if (e
->expr_type
== EXPR_VARIABLE
530 && e
->symtree
->n
.sym
->attr
.flavor
!= FL_PARAMETER
531 && (allow_proc
|| !e
->symtree
->n
.sym
->attr
.function
))
534 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.function
535 && e
->symtree
->n
.sym
== e
->symtree
->n
.sym
->result
)
538 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
539 if (ns
->proc_name
== e
->symtree
->n
.sym
)
543 gfc_error ("%qs argument of %qs intrinsic at %L must be a variable",
544 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
, &e
->where
);
550 /* Check the common DIM parameter for correctness. */
553 dim_check (gfc_expr
*dim
, int n
, bool optional
)
558 if (!type_check (dim
, n
, BT_INTEGER
))
561 if (!scalar_check (dim
, n
))
564 if (!optional
&& !nonoptional_check (dim
, n
))
571 /* If a coarray DIM parameter is a constant, make sure that it is greater than
572 zero and less than or equal to the corank of the given array. */
575 dim_corank_check (gfc_expr
*dim
, gfc_expr
*array
)
579 gcc_assert (array
->expr_type
== EXPR_VARIABLE
);
581 if (dim
->expr_type
!= EXPR_CONSTANT
)
584 if (array
->ts
.type
== BT_CLASS
)
587 corank
= gfc_get_corank (array
);
589 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
590 || mpz_cmp_ui (dim
->value
.integer
, corank
) > 0)
592 gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
593 "codimension index", gfc_current_intrinsic
, &dim
->where
);
602 /* If a DIM parameter is a constant, make sure that it is greater than
603 zero and less than or equal to the rank of the given array. If
604 allow_assumed is zero then dim must be less than the rank of the array
605 for assumed size arrays. */
608 dim_rank_check (gfc_expr
*dim
, gfc_expr
*array
, int allow_assumed
)
616 if (dim
->expr_type
!= EXPR_CONSTANT
)
619 if (array
->expr_type
== EXPR_FUNCTION
&& array
->value
.function
.isym
620 && array
->value
.function
.isym
->id
== GFC_ISYM_SPREAD
)
621 rank
= array
->rank
+ 1;
625 /* Assumed-rank array. */
627 rank
= GFC_MAX_DIMENSIONS
;
629 if (array
->expr_type
== EXPR_VARIABLE
)
631 ar
= gfc_find_array_ref (array
);
632 if (ar
->as
->type
== AS_ASSUMED_SIZE
634 && ar
->type
!= AR_ELEMENT
635 && ar
->type
!= AR_SECTION
)
639 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
640 || mpz_cmp_ui (dim
->value
.integer
, rank
) > 0)
642 gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
643 "dimension index", gfc_current_intrinsic
, &dim
->where
);
652 /* Compare the size of a along dimension ai with the size of b along
653 dimension bi, returning 0 if they are known not to be identical,
654 and 1 if they are identical, or if this cannot be determined. */
657 identical_dimen_shape (gfc_expr
*a
, int ai
, gfc_expr
*b
, int bi
)
659 mpz_t a_size
, b_size
;
662 gcc_assert (a
->rank
> ai
);
663 gcc_assert (b
->rank
> bi
);
667 if (gfc_array_dimen_size (a
, ai
, &a_size
))
669 if (gfc_array_dimen_size (b
, bi
, &b_size
))
671 if (mpz_cmp (a_size
, b_size
) != 0)
681 /* Calculate the length of a character variable, including substrings.
682 Strip away parentheses if necessary. Return -1 if no length could
686 gfc_var_strlen (const gfc_expr
*a
)
690 while (a
->expr_type
== EXPR_OP
&& a
->value
.op
.op
== INTRINSIC_PARENTHESES
)
693 for (ra
= a
->ref
; ra
!= NULL
&& ra
->type
!= REF_SUBSTRING
; ra
= ra
->next
)
703 if ((!ra
->u
.ss
.start
|| ra
->u
.ss
.start
->expr_type
== EXPR_CONSTANT
)
704 && ra
->u
.ss
.end
->expr_type
== EXPR_CONSTANT
)
706 start_a
= ra
->u
.ss
.start
? mpz_get_si (ra
->u
.ss
.start
->value
.integer
)
708 end_a
= mpz_get_si (ra
->u
.ss
.end
->value
.integer
);
709 return (end_a
< start_a
) ? 0 : end_a
- start_a
+ 1;
711 else if (ra
->u
.ss
.start
712 && gfc_dep_compare_expr (ra
->u
.ss
.start
, ra
->u
.ss
.end
) == 0)
718 if (a
->ts
.u
.cl
&& a
->ts
.u
.cl
->length
719 && a
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
720 return mpz_get_si (a
->ts
.u
.cl
->length
->value
.integer
);
721 else if (a
->expr_type
== EXPR_CONSTANT
722 && (a
->ts
.u
.cl
== NULL
|| a
->ts
.u
.cl
->length
== NULL
))
723 return a
->value
.character
.length
;
729 /* Check whether two character expressions have the same length;
730 returns true if they have or if the length cannot be determined,
731 otherwise return false and raise a gfc_error. */
734 gfc_check_same_strlen (const gfc_expr
*a
, const gfc_expr
*b
, const char *name
)
738 len_a
= gfc_var_strlen(a
);
739 len_b
= gfc_var_strlen(b
);
741 if (len_a
== -1 || len_b
== -1 || len_a
== len_b
)
745 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
746 len_a
, len_b
, name
, &a
->where
);
752 /***** Check functions *****/
754 /* Check subroutine suitable for intrinsics taking a real argument and
755 a kind argument for the result. */
758 check_a_kind (gfc_expr
*a
, gfc_expr
*kind
, bt type
)
760 if (!type_check (a
, 0, BT_REAL
))
762 if (!kind_check (kind
, 1, type
))
769 /* Check subroutine suitable for ceiling, floor and nint. */
772 gfc_check_a_ikind (gfc_expr
*a
, gfc_expr
*kind
)
774 return check_a_kind (a
, kind
, BT_INTEGER
);
778 /* Check subroutine suitable for aint, anint. */
781 gfc_check_a_xkind (gfc_expr
*a
, gfc_expr
*kind
)
783 return check_a_kind (a
, kind
, BT_REAL
);
788 gfc_check_abs (gfc_expr
*a
)
790 if (!numeric_check (a
, 0))
798 gfc_check_achar (gfc_expr
*a
, gfc_expr
*kind
)
800 if (!type_check (a
, 0, BT_INTEGER
))
802 if (!kind_check (kind
, 1, BT_CHARACTER
))
810 gfc_check_access_func (gfc_expr
*name
, gfc_expr
*mode
)
812 if (!type_check (name
, 0, BT_CHARACTER
)
813 || !scalar_check (name
, 0))
815 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
818 if (!type_check (mode
, 1, BT_CHARACTER
)
819 || !scalar_check (mode
, 1))
821 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
829 gfc_check_all_any (gfc_expr
*mask
, gfc_expr
*dim
)
831 if (!logical_array_check (mask
, 0))
834 if (!dim_check (dim
, 1, false))
837 if (!dim_rank_check (dim
, mask
, 0))
845 gfc_check_allocated (gfc_expr
*array
)
847 if (!variable_check (array
, 0, false))
849 if (!allocatable_check (array
, 0))
856 /* Common check function where the first argument must be real or
857 integer and the second argument must be the same as the first. */
860 gfc_check_a_p (gfc_expr
*a
, gfc_expr
*p
)
862 if (!int_or_real_check (a
, 0))
865 if (a
->ts
.type
!= p
->ts
.type
)
867 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
868 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
869 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
874 if (a
->ts
.kind
!= p
->ts
.kind
)
876 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
886 gfc_check_x_yd (gfc_expr
*x
, gfc_expr
*y
)
888 if (!double_check (x
, 0) || !double_check (y
, 1))
896 gfc_check_associated (gfc_expr
*pointer
, gfc_expr
*target
)
898 symbol_attribute attr1
, attr2
;
903 where
= &pointer
->where
;
905 if (pointer
->expr_type
== EXPR_NULL
)
908 attr1
= gfc_expr_attr (pointer
);
910 if (!attr1
.pointer
&& !attr1
.proc_pointer
)
912 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER",
913 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
919 if (attr1
.pointer
&& gfc_is_coindexed (pointer
))
921 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
922 "coindexed", gfc_current_intrinsic_arg
[0]->name
,
923 gfc_current_intrinsic
, &pointer
->where
);
927 /* Target argument is optional. */
931 where
= &target
->where
;
932 if (target
->expr_type
== EXPR_NULL
)
935 if (target
->expr_type
== EXPR_VARIABLE
|| target
->expr_type
== EXPR_FUNCTION
)
936 attr2
= gfc_expr_attr (target
);
939 gfc_error ("%qs argument of %qs intrinsic at %L must be a pointer "
940 "or target VARIABLE or FUNCTION",
941 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
946 if (attr1
.pointer
&& !attr2
.pointer
&& !attr2
.target
)
948 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER "
949 "or a TARGET", gfc_current_intrinsic_arg
[1]->name
,
950 gfc_current_intrinsic
, &target
->where
);
955 if (attr1
.pointer
&& gfc_is_coindexed (target
))
957 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
958 "coindexed", gfc_current_intrinsic_arg
[1]->name
,
959 gfc_current_intrinsic
, &target
->where
);
964 if (!same_type_check (pointer
, 0, target
, 1))
966 if (!rank_check (target
, 0, pointer
->rank
))
968 if (target
->rank
> 0)
970 for (i
= 0; i
< target
->rank
; i
++)
971 if (target
->ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
973 gfc_error ("Array section with a vector subscript at %L shall not "
974 "be the target of a pointer",
984 gfc_error ("NULL pointer at %L is not permitted as actual argument "
985 "of %qs intrinsic function", where
, gfc_current_intrinsic
);
992 gfc_check_atan_2 (gfc_expr
*y
, gfc_expr
*x
)
994 /* gfc_notify_std would be a waste of time as the return value
995 is seemingly used only for the generic resolution. The error
996 will be: Too many arguments. */
997 if ((gfc_option
.allow_std
& GFC_STD_F2008
) == 0)
1000 return gfc_check_atan2 (y
, x
);
1005 gfc_check_atan2 (gfc_expr
*y
, gfc_expr
*x
)
1007 if (!type_check (y
, 0, BT_REAL
))
1009 if (!same_type_check (y
, 0, x
, 1))
1017 gfc_check_atomic (gfc_expr
*atom
, int atom_no
, gfc_expr
*value
, int val_no
,
1018 gfc_expr
*stat
, int stat_no
)
1020 if (!scalar_check (atom
, atom_no
) || !scalar_check (value
, val_no
))
1023 if (!(atom
->ts
.type
== BT_INTEGER
&& atom
->ts
.kind
== gfc_atomic_int_kind
)
1024 && !(atom
->ts
.type
== BT_LOGICAL
1025 && atom
->ts
.kind
== gfc_atomic_logical_kind
))
1027 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1028 "integer of ATOMIC_INT_KIND or a logical of "
1029 "ATOMIC_LOGICAL_KIND", &atom
->where
, gfc_current_intrinsic
);
1033 if (!gfc_is_coarray (atom
) && !gfc_is_coindexed (atom
))
1035 gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
1036 "coarray or coindexed", &atom
->where
, gfc_current_intrinsic
);
1040 if (atom
->ts
.type
!= value
->ts
.type
)
1042 gfc_error ("%qs argument of %qs intrinsic at %L shall have the same "
1043 "type as %qs at %L", gfc_current_intrinsic_arg
[val_no
]->name
,
1044 gfc_current_intrinsic
, &value
->where
,
1045 gfc_current_intrinsic_arg
[atom_no
]->name
, &atom
->where
);
1051 if (!type_check (stat
, stat_no
, BT_INTEGER
))
1053 if (!scalar_check (stat
, stat_no
))
1055 if (!variable_check (stat
, stat_no
, false))
1057 if (!kind_value_check (stat
, stat_no
, gfc_default_integer_kind
))
1060 if (!gfc_notify_std (GFC_STD_F2008_TS
, "STAT= argument to %s at %L",
1061 gfc_current_intrinsic
, &stat
->where
))
1070 gfc_check_atomic_def (gfc_expr
*atom
, gfc_expr
*value
, gfc_expr
*stat
)
1072 if (atom
->expr_type
== EXPR_FUNCTION
1073 && atom
->value
.function
.isym
1074 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1075 atom
= atom
->value
.function
.actual
->expr
;
1077 if (!gfc_check_vardef_context (atom
, false, false, false, NULL
))
1079 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1080 "definable", gfc_current_intrinsic
, &atom
->where
);
1084 return gfc_check_atomic (atom
, 0, value
, 1, stat
, 2);
1089 gfc_check_atomic_op (gfc_expr
*atom
, gfc_expr
*value
, gfc_expr
*stat
)
1091 if (atom
->ts
.type
!= BT_INTEGER
|| atom
->ts
.kind
!= gfc_atomic_int_kind
)
1093 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1094 "integer of ATOMIC_INT_KIND", &atom
->where
,
1095 gfc_current_intrinsic
);
1099 return gfc_check_atomic_def (atom
, value
, stat
);
1104 gfc_check_atomic_ref (gfc_expr
*value
, gfc_expr
*atom
, gfc_expr
*stat
)
1106 if (atom
->expr_type
== EXPR_FUNCTION
1107 && atom
->value
.function
.isym
1108 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1109 atom
= atom
->value
.function
.actual
->expr
;
1111 if (!gfc_check_vardef_context (value
, false, false, false, NULL
))
1113 gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1114 "definable", gfc_current_intrinsic
, &value
->where
);
1118 return gfc_check_atomic (atom
, 1, value
, 0, stat
, 2);
1123 gfc_check_atomic_cas (gfc_expr
*atom
, gfc_expr
*old
, gfc_expr
*compare
,
1124 gfc_expr
*new_val
, gfc_expr
*stat
)
1126 if (atom
->expr_type
== EXPR_FUNCTION
1127 && atom
->value
.function
.isym
1128 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1129 atom
= atom
->value
.function
.actual
->expr
;
1131 if (!gfc_check_atomic (atom
, 0, new_val
, 3, stat
, 4))
1134 if (!scalar_check (old
, 1) || !scalar_check (compare
, 2))
1137 if (!same_type_check (atom
, 0, old
, 1))
1140 if (!same_type_check (atom
, 0, compare
, 2))
1143 if (!gfc_check_vardef_context (atom
, false, false, false, NULL
))
1145 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1146 "definable", gfc_current_intrinsic
, &atom
->where
);
1150 if (!gfc_check_vardef_context (old
, false, false, false, NULL
))
1152 gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1153 "definable", gfc_current_intrinsic
, &old
->where
);
1161 gfc_check_event_query (gfc_expr
*event
, gfc_expr
*count
, gfc_expr
*stat
)
1163 if (event
->ts
.type
!= BT_DERIVED
1164 || event
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
1165 || event
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_EVENT_TYPE
)
1167 gfc_error ("EVENT argument at %L to the intrinsic EVENT_QUERY "
1168 "shall be of type EVENT_TYPE", &event
->where
);
1172 if (!scalar_check (event
, 0))
1175 if (!gfc_check_vardef_context (count
, false, false, false, NULL
))
1177 gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1178 "shall be definable", &count
->where
);
1182 if (!type_check (count
, 1, BT_INTEGER
))
1185 int i
= gfc_validate_kind (BT_INTEGER
, count
->ts
.kind
, false);
1186 int j
= gfc_validate_kind (BT_INTEGER
, gfc_default_integer_kind
, false);
1188 if (gfc_integer_kinds
[i
].range
< gfc_integer_kinds
[j
].range
)
1190 gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1191 "shall have at least the range of the default integer",
1198 if (!type_check (stat
, 2, BT_INTEGER
))
1200 if (!scalar_check (stat
, 2))
1202 if (!variable_check (stat
, 2, false))
1205 if (!gfc_notify_std (GFC_STD_F2008_TS
, "STAT= argument to %s at %L",
1206 gfc_current_intrinsic
, &stat
->where
))
1215 gfc_check_atomic_fetch_op (gfc_expr
*atom
, gfc_expr
*value
, gfc_expr
*old
,
1218 if (atom
->expr_type
== EXPR_FUNCTION
1219 && atom
->value
.function
.isym
1220 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1221 atom
= atom
->value
.function
.actual
->expr
;
1223 if (atom
->ts
.type
!= BT_INTEGER
|| atom
->ts
.kind
!= gfc_atomic_int_kind
)
1225 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1226 "integer of ATOMIC_INT_KIND", &atom
->where
,
1227 gfc_current_intrinsic
);
1231 if (!gfc_check_atomic (atom
, 0, value
, 1, stat
, 3))
1234 if (!scalar_check (old
, 2))
1237 if (!same_type_check (atom
, 0, old
, 2))
1240 if (!gfc_check_vardef_context (atom
, false, false, false, NULL
))
1242 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1243 "definable", gfc_current_intrinsic
, &atom
->where
);
1247 if (!gfc_check_vardef_context (old
, false, false, false, NULL
))
1249 gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1250 "definable", gfc_current_intrinsic
, &old
->where
);
1258 /* BESJN and BESYN functions. */
1261 gfc_check_besn (gfc_expr
*n
, gfc_expr
*x
)
1263 if (!type_check (n
, 0, BT_INTEGER
))
1265 if (n
->expr_type
== EXPR_CONSTANT
)
1268 gfc_extract_int (n
, &i
);
1269 if (i
< 0 && !gfc_notify_std (GFC_STD_GNU
, "Negative argument "
1270 "N at %L", &n
->where
))
1274 if (!type_check (x
, 1, BT_REAL
))
1281 /* Transformational version of the Bessel JN and YN functions. */
1284 gfc_check_bessel_n2 (gfc_expr
*n1
, gfc_expr
*n2
, gfc_expr
*x
)
1286 if (!type_check (n1
, 0, BT_INTEGER
))
1288 if (!scalar_check (n1
, 0))
1290 if (!nonnegative_check ("N1", n1
))
1293 if (!type_check (n2
, 1, BT_INTEGER
))
1295 if (!scalar_check (n2
, 1))
1297 if (!nonnegative_check ("N2", n2
))
1300 if (!type_check (x
, 2, BT_REAL
))
1302 if (!scalar_check (x
, 2))
1310 gfc_check_bge_bgt_ble_blt (gfc_expr
*i
, gfc_expr
*j
)
1312 if (!type_check (i
, 0, BT_INTEGER
))
1315 if (!type_check (j
, 1, BT_INTEGER
))
1323 gfc_check_bitfcn (gfc_expr
*i
, gfc_expr
*pos
)
1325 if (!type_check (i
, 0, BT_INTEGER
))
1328 if (!type_check (pos
, 1, BT_INTEGER
))
1331 if (!nonnegative_check ("pos", pos
))
1334 if (!less_than_bitsize1 ("i", i
, "pos", pos
, false))
1342 gfc_check_char (gfc_expr
*i
, gfc_expr
*kind
)
1344 if (!type_check (i
, 0, BT_INTEGER
))
1346 if (!kind_check (kind
, 1, BT_CHARACTER
))
1354 gfc_check_chdir (gfc_expr
*dir
)
1356 if (!type_check (dir
, 0, BT_CHARACTER
))
1358 if (!kind_value_check (dir
, 0, gfc_default_character_kind
))
1366 gfc_check_chdir_sub (gfc_expr
*dir
, gfc_expr
*status
)
1368 if (!type_check (dir
, 0, BT_CHARACTER
))
1370 if (!kind_value_check (dir
, 0, gfc_default_character_kind
))
1376 if (!type_check (status
, 1, BT_INTEGER
))
1378 if (!scalar_check (status
, 1))
1386 gfc_check_chmod (gfc_expr
*name
, gfc_expr
*mode
)
1388 if (!type_check (name
, 0, BT_CHARACTER
))
1390 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
1393 if (!type_check (mode
, 1, BT_CHARACTER
))
1395 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
1403 gfc_check_chmod_sub (gfc_expr
*name
, gfc_expr
*mode
, gfc_expr
*status
)
1405 if (!type_check (name
, 0, BT_CHARACTER
))
1407 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
1410 if (!type_check (mode
, 1, BT_CHARACTER
))
1412 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
1418 if (!type_check (status
, 2, BT_INTEGER
))
1421 if (!scalar_check (status
, 2))
1429 gfc_check_cmplx (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
1431 if (!numeric_check (x
, 0))
1436 if (!numeric_check (y
, 1))
1439 if (x
->ts
.type
== BT_COMPLEX
)
1441 gfc_error ("%qs argument of %qs intrinsic at %L must not be "
1442 "present if %<x%> is COMPLEX",
1443 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1448 if (y
->ts
.type
== BT_COMPLEX
)
1450 gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
1451 "of either REAL or INTEGER",
1452 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1459 if (!kind_check (kind
, 2, BT_COMPLEX
))
1462 if (!kind
&& warn_conversion
1463 && x
->ts
.type
== BT_REAL
&& x
->ts
.kind
> gfc_default_real_kind
)
1464 gfc_warning_now (OPT_Wconversion
, "Conversion from %s to default-kind "
1465 "COMPLEX(%d) at %L might lose precision, consider using "
1466 "the KIND argument", gfc_typename (&x
->ts
),
1467 gfc_default_real_kind
, &x
->where
);
1468 else if (y
&& !kind
&& warn_conversion
1469 && y
->ts
.type
== BT_REAL
&& y
->ts
.kind
> gfc_default_real_kind
)
1470 gfc_warning_now (OPT_Wconversion
, "Conversion from %s to default-kind "
1471 "COMPLEX(%d) at %L might lose precision, consider using "
1472 "the KIND argument", gfc_typename (&y
->ts
),
1473 gfc_default_real_kind
, &y
->where
);
1479 check_co_collective (gfc_expr
*a
, gfc_expr
*image_idx
, gfc_expr
*stat
,
1480 gfc_expr
*errmsg
, bool co_reduce
)
1482 if (!variable_check (a
, 0, false))
1485 if (!gfc_check_vardef_context (a
, false, false, false, "argument 'A' with "
1489 /* Fortran 2008, 12.5.2.4, paragraph 18. */
1490 if (gfc_has_vector_subscript (a
))
1492 gfc_error ("Argument %<A%> with INTENT(INOUT) at %L of the intrinsic "
1493 "subroutine %s shall not have a vector subscript",
1494 &a
->where
, gfc_current_intrinsic
);
1498 if (gfc_is_coindexed (a
))
1500 gfc_error ("The A argument at %L to the intrinsic %s shall not be "
1501 "coindexed", &a
->where
, gfc_current_intrinsic
);
1505 if (image_idx
!= NULL
)
1507 if (!type_check (image_idx
, co_reduce
? 2 : 1, BT_INTEGER
))
1509 if (!scalar_check (image_idx
, co_reduce
? 2 : 1))
1515 if (!type_check (stat
, co_reduce
? 3 : 2, BT_INTEGER
))
1517 if (!scalar_check (stat
, co_reduce
? 3 : 2))
1519 if (!variable_check (stat
, co_reduce
? 3 : 2, false))
1521 if (stat
->ts
.kind
!= 4)
1523 gfc_error ("The stat= argument at %L must be a kind=4 integer "
1524 "variable", &stat
->where
);
1531 if (!type_check (errmsg
, co_reduce
? 4 : 3, BT_CHARACTER
))
1533 if (!scalar_check (errmsg
, co_reduce
? 4 : 3))
1535 if (!variable_check (errmsg
, co_reduce
? 4 : 3, false))
1537 if (errmsg
->ts
.kind
!= 1)
1539 gfc_error ("The errmsg= argument at %L must be a default-kind "
1540 "character variable", &errmsg
->where
);
1545 if (flag_coarray
== GFC_FCOARRAY_NONE
)
1547 gfc_fatal_error ("Coarrays disabled at %L, use %<-fcoarray=%> to enable",
1557 gfc_check_co_broadcast (gfc_expr
*a
, gfc_expr
*source_image
, gfc_expr
*stat
,
1560 if (a
->ts
.type
== BT_CLASS
|| gfc_expr_attr (a
).alloc_comp
)
1562 gfc_error ("Support for the A argument at %L which is polymorphic A "
1563 "argument or has allocatable components is not yet "
1564 "implemented", &a
->where
);
1567 return check_co_collective (a
, source_image
, stat
, errmsg
, false);
1572 gfc_check_co_reduce (gfc_expr
*a
, gfc_expr
*op
, gfc_expr
*result_image
,
1573 gfc_expr
*stat
, gfc_expr
*errmsg
)
1575 symbol_attribute attr
;
1576 gfc_formal_arglist
*formal
;
1579 if (a
->ts
.type
== BT_CLASS
)
1581 gfc_error ("The A argument at %L of CO_REDUCE shall not be polymorphic",
1586 if (gfc_expr_attr (a
).alloc_comp
)
1588 gfc_error ("Support for the A argument at %L with allocatable components"
1589 " is not yet implemented", &a
->where
);
1593 if (!check_co_collective (a
, result_image
, stat
, errmsg
, true))
1596 if (!gfc_resolve_expr (op
))
1599 attr
= gfc_expr_attr (op
);
1600 if (!attr
.pure
|| !attr
.function
)
1602 gfc_error ("OPERATOR argument at %L must be a PURE function",
1609 /* None of the intrinsics fulfills the criteria of taking two arguments,
1610 returning the same type and kind as the arguments and being permitted
1611 as actual argument. */
1612 gfc_error ("Intrinsic function %s at %L is not permitted for CO_REDUCE",
1613 op
->symtree
->n
.sym
->name
, &op
->where
);
1617 if (gfc_is_proc_ptr_comp (op
))
1619 gfc_component
*comp
= gfc_get_proc_ptr_comp (op
);
1620 sym
= comp
->ts
.interface
;
1623 sym
= op
->symtree
->n
.sym
;
1625 formal
= sym
->formal
;
1627 if (!formal
|| !formal
->next
|| formal
->next
->next
)
1629 gfc_error ("The function passed as OPERATOR at %L shall have two "
1630 "arguments", &op
->where
);
1634 if (sym
->result
->ts
.type
== BT_UNKNOWN
)
1635 gfc_set_default_type (sym
->result
, 0, NULL
);
1637 if (!gfc_compare_types (&a
->ts
, &sym
->result
->ts
))
1639 gfc_error ("A argument at %L has type %s but the function passed as "
1640 "OPERATOR at %L returns %s",
1641 &a
->where
, gfc_typename (&a
->ts
), &op
->where
,
1642 gfc_typename (&sym
->result
->ts
));
1645 if (!gfc_compare_types (&a
->ts
, &formal
->sym
->ts
)
1646 || !gfc_compare_types (&a
->ts
, &formal
->next
->sym
->ts
))
1648 gfc_error ("The function passed as OPERATOR at %L has arguments of type "
1649 "%s and %s but shall have type %s", &op
->where
,
1650 gfc_typename (&formal
->sym
->ts
),
1651 gfc_typename (&formal
->next
->sym
->ts
), gfc_typename (&a
->ts
));
1654 if (op
->rank
|| attr
.allocatable
|| attr
.pointer
|| formal
->sym
->as
1655 || formal
->next
->sym
->as
|| formal
->sym
->attr
.allocatable
1656 || formal
->next
->sym
->attr
.allocatable
|| formal
->sym
->attr
.pointer
1657 || formal
->next
->sym
->attr
.pointer
)
1659 gfc_error ("The function passed as OPERATOR at %L shall have scalar "
1660 "nonallocatable nonpointer arguments and return a "
1661 "nonallocatable nonpointer scalar", &op
->where
);
1665 if (formal
->sym
->attr
.value
!= formal
->next
->sym
->attr
.value
)
1667 gfc_error ("The function passed as OPERATOR at %L shall have the VALUE "
1668 "attribute either for none or both arguments", &op
->where
);
1672 if (formal
->sym
->attr
.target
!= formal
->next
->sym
->attr
.target
)
1674 gfc_error ("The function passed as OPERATOR at %L shall have the TARGET "
1675 "attribute either for none or both arguments", &op
->where
);
1679 if (formal
->sym
->attr
.asynchronous
!= formal
->next
->sym
->attr
.asynchronous
)
1681 gfc_error ("The function passed as OPERATOR at %L shall have the "
1682 "ASYNCHRONOUS attribute either for none or both arguments",
1687 if (formal
->sym
->attr
.optional
|| formal
->next
->sym
->attr
.optional
)
1689 gfc_error ("The function passed as OPERATOR at %L shall not have the "
1690 "OPTIONAL attribute for either of the arguments", &op
->where
);
1694 if (a
->ts
.type
== BT_CHARACTER
)
1697 unsigned long actual_size
, formal_size1
, formal_size2
, result_size
;
1700 actual_size
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
1701 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
1703 cl
= formal
->sym
->ts
.u
.cl
;
1704 formal_size1
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
1705 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
1707 cl
= formal
->next
->sym
->ts
.u
.cl
;
1708 formal_size2
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
1709 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
1712 result_size
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
1713 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
1716 && ((formal_size1
&& actual_size
!= formal_size1
)
1717 || (formal_size2
&& actual_size
!= formal_size2
)))
1719 gfc_error ("The character length of the A argument at %L and of the "
1720 "arguments of the OPERATOR at %L shall be the same",
1721 &a
->where
, &op
->where
);
1724 if (actual_size
&& result_size
&& actual_size
!= result_size
)
1726 gfc_error ("The character length of the A argument at %L and of the "
1727 "function result of the OPERATOR at %L shall be the same",
1728 &a
->where
, &op
->where
);
1738 gfc_check_co_minmax (gfc_expr
*a
, gfc_expr
*result_image
, gfc_expr
*stat
,
1741 if (a
->ts
.type
!= BT_INTEGER
&& a
->ts
.type
!= BT_REAL
1742 && a
->ts
.type
!= BT_CHARACTER
)
1744 gfc_error ("%qs argument of %qs intrinsic at %L shall be of type "
1745 "integer, real or character",
1746 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
1750 return check_co_collective (a
, result_image
, stat
, errmsg
, false);
1755 gfc_check_co_sum (gfc_expr
*a
, gfc_expr
*result_image
, gfc_expr
*stat
,
1758 if (!numeric_check (a
, 0))
1760 return check_co_collective (a
, result_image
, stat
, errmsg
, false);
1765 gfc_check_complex (gfc_expr
*x
, gfc_expr
*y
)
1767 if (!int_or_real_check (x
, 0))
1769 if (!scalar_check (x
, 0))
1772 if (!int_or_real_check (y
, 1))
1774 if (!scalar_check (y
, 1))
1782 gfc_check_count (gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
1784 if (!logical_array_check (mask
, 0))
1786 if (!dim_check (dim
, 1, false))
1788 if (!dim_rank_check (dim
, mask
, 0))
1790 if (!kind_check (kind
, 2, BT_INTEGER
))
1792 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
1793 "with KIND argument at %L",
1794 gfc_current_intrinsic
, &kind
->where
))
1802 gfc_check_cshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*dim
)
1804 if (!array_check (array
, 0))
1807 if (!type_check (shift
, 1, BT_INTEGER
))
1810 if (!dim_check (dim
, 2, true))
1813 if (!dim_rank_check (dim
, array
, false))
1816 if (array
->rank
== 1 || shift
->rank
== 0)
1818 if (!scalar_check (shift
, 1))
1821 else if (shift
->rank
== array
->rank
- 1)
1826 else if (dim
->expr_type
== EXPR_CONSTANT
)
1827 gfc_extract_int (dim
, &d
);
1834 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1837 if (!identical_dimen_shape (array
, i
, shift
, j
))
1839 gfc_error ("%qs argument of %qs intrinsic at %L has "
1840 "invalid shape in dimension %d (%ld/%ld)",
1841 gfc_current_intrinsic_arg
[1]->name
,
1842 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
1843 mpz_get_si (array
->shape
[i
]),
1844 mpz_get_si (shift
->shape
[j
]));
1854 gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
1855 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
1856 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
1865 gfc_check_ctime (gfc_expr
*time
)
1867 if (!scalar_check (time
, 0))
1870 if (!type_check (time
, 0, BT_INTEGER
))
1877 bool gfc_check_datan2 (gfc_expr
*y
, gfc_expr
*x
)
1879 if (!double_check (y
, 0) || !double_check (x
, 1))
1886 gfc_check_dcmplx (gfc_expr
*x
, gfc_expr
*y
)
1888 if (!numeric_check (x
, 0))
1893 if (!numeric_check (y
, 1))
1896 if (x
->ts
.type
== BT_COMPLEX
)
1898 gfc_error ("%qs argument of %qs intrinsic at %L must not be "
1899 "present if %<x%> is COMPLEX",
1900 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1905 if (y
->ts
.type
== BT_COMPLEX
)
1907 gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
1908 "of either REAL or INTEGER",
1909 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1920 gfc_check_dble (gfc_expr
*x
)
1922 if (!numeric_check (x
, 0))
1930 gfc_check_digits (gfc_expr
*x
)
1932 if (!int_or_real_check (x
, 0))
1940 gfc_check_dot_product (gfc_expr
*vector_a
, gfc_expr
*vector_b
)
1942 switch (vector_a
->ts
.type
)
1945 if (!type_check (vector_b
, 1, BT_LOGICAL
))
1952 if (!numeric_check (vector_b
, 1))
1957 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
1958 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
1959 gfc_current_intrinsic
, &vector_a
->where
);
1963 if (!rank_check (vector_a
, 0, 1))
1966 if (!rank_check (vector_b
, 1, 1))
1969 if (! identical_dimen_shape (vector_a
, 0, vector_b
, 0))
1971 gfc_error ("Different shape for arguments %qs and %qs at %L for "
1972 "intrinsic %<dot_product%>",
1973 gfc_current_intrinsic_arg
[0]->name
,
1974 gfc_current_intrinsic_arg
[1]->name
, &vector_a
->where
);
1983 gfc_check_dprod (gfc_expr
*x
, gfc_expr
*y
)
1985 if (!type_check (x
, 0, BT_REAL
)
1986 || !type_check (y
, 1, BT_REAL
))
1989 if (x
->ts
.kind
!= gfc_default_real_kind
)
1991 gfc_error ("%qs argument of %qs intrinsic at %L must be default "
1992 "real", gfc_current_intrinsic_arg
[0]->name
,
1993 gfc_current_intrinsic
, &x
->where
);
1997 if (y
->ts
.kind
!= gfc_default_real_kind
)
1999 gfc_error ("%qs argument of %qs intrinsic at %L must be default "
2000 "real", gfc_current_intrinsic_arg
[1]->name
,
2001 gfc_current_intrinsic
, &y
->where
);
2010 gfc_check_dshift (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*shift
)
2012 if (!type_check (i
, 0, BT_INTEGER
))
2015 if (!type_check (j
, 1, BT_INTEGER
))
2018 if (i
->is_boz
&& j
->is_boz
)
2020 gfc_error ("%<I%> at %L and %<J%>' at %L cannot both be BOZ literal "
2021 "constants", &i
->where
, &j
->where
);
2025 if (!i
->is_boz
&& !j
->is_boz
&& !same_type_check (i
, 0, j
, 1))
2028 if (!type_check (shift
, 2, BT_INTEGER
))
2031 if (!nonnegative_check ("SHIFT", shift
))
2036 if (!less_than_bitsize1 ("J", j
, "SHIFT", shift
, true))
2038 i
->ts
.kind
= j
->ts
.kind
;
2042 if (!less_than_bitsize1 ("I", i
, "SHIFT", shift
, true))
2044 j
->ts
.kind
= i
->ts
.kind
;
2052 gfc_check_eoshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*boundary
,
2055 if (!array_check (array
, 0))
2058 if (!type_check (shift
, 1, BT_INTEGER
))
2061 if (!dim_check (dim
, 3, true))
2064 if (!dim_rank_check (dim
, array
, false))
2067 if (array
->rank
== 1 || shift
->rank
== 0)
2069 if (!scalar_check (shift
, 1))
2072 else if (shift
->rank
== array
->rank
- 1)
2077 else if (dim
->expr_type
== EXPR_CONSTANT
)
2078 gfc_extract_int (dim
, &d
);
2085 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
2088 if (!identical_dimen_shape (array
, i
, shift
, j
))
2090 gfc_error ("%qs argument of %qs intrinsic at %L has "
2091 "invalid shape in dimension %d (%ld/%ld)",
2092 gfc_current_intrinsic_arg
[1]->name
,
2093 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
2094 mpz_get_si (array
->shape
[i
]),
2095 mpz_get_si (shift
->shape
[j
]));
2105 gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
2106 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
2107 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
2111 if (boundary
!= NULL
)
2113 if (!same_type_check (array
, 0, boundary
, 2))
2116 if (array
->rank
== 1 || boundary
->rank
== 0)
2118 if (!scalar_check (boundary
, 2))
2121 else if (boundary
->rank
== array
->rank
- 1)
2123 if (!gfc_check_conformance (shift
, boundary
,
2124 "arguments '%s' and '%s' for "
2126 gfc_current_intrinsic_arg
[1]->name
,
2127 gfc_current_intrinsic_arg
[2]->name
,
2128 gfc_current_intrinsic
))
2133 gfc_error ("%qs argument of intrinsic %qs at %L of must have "
2134 "rank %d or be a scalar",
2135 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2136 &shift
->where
, array
->rank
- 1);
2145 gfc_check_float (gfc_expr
*a
)
2147 if (!type_check (a
, 0, BT_INTEGER
))
2150 if ((a
->ts
.kind
!= gfc_default_integer_kind
)
2151 && !gfc_notify_std (GFC_STD_GNU
, "non-default INTEGER "
2152 "kind argument to %s intrinsic at %L",
2153 gfc_current_intrinsic
, &a
->where
))
2159 /* A single complex argument. */
2162 gfc_check_fn_c (gfc_expr
*a
)
2164 if (!type_check (a
, 0, BT_COMPLEX
))
2170 /* A single real argument. */
2173 gfc_check_fn_r (gfc_expr
*a
)
2175 if (!type_check (a
, 0, BT_REAL
))
2181 /* A single double argument. */
2184 gfc_check_fn_d (gfc_expr
*a
)
2186 if (!double_check (a
, 0))
2192 /* A single real or complex argument. */
2195 gfc_check_fn_rc (gfc_expr
*a
)
2197 if (!real_or_complex_check (a
, 0))
2205 gfc_check_fn_rc2008 (gfc_expr
*a
)
2207 if (!real_or_complex_check (a
, 0))
2210 if (a
->ts
.type
== BT_COMPLEX
2211 && !gfc_notify_std (GFC_STD_F2008
, "COMPLEX argument %qs "
2212 "of %qs intrinsic at %L",
2213 gfc_current_intrinsic_arg
[0]->name
,
2214 gfc_current_intrinsic
, &a
->where
))
2222 gfc_check_fnum (gfc_expr
*unit
)
2224 if (!type_check (unit
, 0, BT_INTEGER
))
2227 if (!scalar_check (unit
, 0))
2235 gfc_check_huge (gfc_expr
*x
)
2237 if (!int_or_real_check (x
, 0))
2245 gfc_check_hypot (gfc_expr
*x
, gfc_expr
*y
)
2247 if (!type_check (x
, 0, BT_REAL
))
2249 if (!same_type_check (x
, 0, y
, 1))
2256 /* Check that the single argument is an integer. */
2259 gfc_check_i (gfc_expr
*i
)
2261 if (!type_check (i
, 0, BT_INTEGER
))
2269 gfc_check_iand (gfc_expr
*i
, gfc_expr
*j
)
2271 if (!type_check (i
, 0, BT_INTEGER
))
2274 if (!type_check (j
, 1, BT_INTEGER
))
2277 if (i
->ts
.kind
!= j
->ts
.kind
)
2279 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
2289 gfc_check_ibits (gfc_expr
*i
, gfc_expr
*pos
, gfc_expr
*len
)
2291 if (!type_check (i
, 0, BT_INTEGER
))
2294 if (!type_check (pos
, 1, BT_INTEGER
))
2297 if (!type_check (len
, 2, BT_INTEGER
))
2300 if (!nonnegative_check ("pos", pos
))
2303 if (!nonnegative_check ("len", len
))
2306 if (!less_than_bitsize2 ("i", i
, "pos", pos
, "len", len
))
2314 gfc_check_ichar_iachar (gfc_expr
*c
, gfc_expr
*kind
)
2318 if (!type_check (c
, 0, BT_CHARACTER
))
2321 if (!kind_check (kind
, 1, BT_INTEGER
))
2324 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
2325 "with KIND argument at %L",
2326 gfc_current_intrinsic
, &kind
->where
))
2329 if (c
->expr_type
== EXPR_VARIABLE
|| c
->expr_type
== EXPR_SUBSTRING
)
2335 /* Substring references don't have the charlength set. */
2337 while (ref
&& ref
->type
!= REF_SUBSTRING
)
2340 gcc_assert (ref
== NULL
|| ref
->type
== REF_SUBSTRING
);
2344 /* Check that the argument is length one. Non-constant lengths
2345 can't be checked here, so assume they are ok. */
2346 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
)
2348 /* If we already have a length for this expression then use it. */
2349 if (c
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
2351 i
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
2358 start
= ref
->u
.ss
.start
;
2359 end
= ref
->u
.ss
.end
;
2362 if (end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
2363 || start
->expr_type
!= EXPR_CONSTANT
)
2366 i
= mpz_get_si (end
->value
.integer
) + 1
2367 - mpz_get_si (start
->value
.integer
);
2375 gfc_error ("Argument of %s at %L must be of length one",
2376 gfc_current_intrinsic
, &c
->where
);
2385 gfc_check_idnint (gfc_expr
*a
)
2387 if (!double_check (a
, 0))
2395 gfc_check_ieor (gfc_expr
*i
, gfc_expr
*j
)
2397 if (!type_check (i
, 0, BT_INTEGER
))
2400 if (!type_check (j
, 1, BT_INTEGER
))
2403 if (i
->ts
.kind
!= j
->ts
.kind
)
2405 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
2415 gfc_check_index (gfc_expr
*string
, gfc_expr
*substring
, gfc_expr
*back
,
2418 if (!type_check (string
, 0, BT_CHARACTER
)
2419 || !type_check (substring
, 1, BT_CHARACTER
))
2422 if (back
!= NULL
&& !type_check (back
, 2, BT_LOGICAL
))
2425 if (!kind_check (kind
, 3, BT_INTEGER
))
2427 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
2428 "with KIND argument at %L",
2429 gfc_current_intrinsic
, &kind
->where
))
2432 if (string
->ts
.kind
!= substring
->ts
.kind
)
2434 gfc_error ("%qs argument of %qs intrinsic at %L must be the same "
2435 "kind as %qs", gfc_current_intrinsic_arg
[1]->name
,
2436 gfc_current_intrinsic
, &substring
->where
,
2437 gfc_current_intrinsic_arg
[0]->name
);
2446 gfc_check_int (gfc_expr
*x
, gfc_expr
*kind
)
2448 if (!numeric_check (x
, 0))
2451 if (!kind_check (kind
, 1, BT_INTEGER
))
2459 gfc_check_intconv (gfc_expr
*x
)
2461 if (!numeric_check (x
, 0))
2469 gfc_check_ior (gfc_expr
*i
, gfc_expr
*j
)
2471 if (!type_check (i
, 0, BT_INTEGER
))
2474 if (!type_check (j
, 1, BT_INTEGER
))
2477 if (i
->ts
.kind
!= j
->ts
.kind
)
2479 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
2489 gfc_check_ishft (gfc_expr
*i
, gfc_expr
*shift
)
2491 if (!type_check (i
, 0, BT_INTEGER
)
2492 || !type_check (shift
, 1, BT_INTEGER
))
2495 if (!less_than_bitsize1 ("I", i
, NULL
, shift
, true))
2503 gfc_check_ishftc (gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
2505 if (!type_check (i
, 0, BT_INTEGER
)
2506 || !type_check (shift
, 1, BT_INTEGER
))
2513 if (!type_check (size
, 2, BT_INTEGER
))
2516 if (!less_than_bitsize1 ("I", i
, "SIZE", size
, true))
2519 if (size
->expr_type
== EXPR_CONSTANT
)
2521 gfc_extract_int (size
, &i3
);
2524 gfc_error ("SIZE at %L must be positive", &size
->where
);
2528 if (shift
->expr_type
== EXPR_CONSTANT
)
2530 gfc_extract_int (shift
, &i2
);
2536 gfc_error ("The absolute value of SHIFT at %L must be less "
2537 "than or equal to SIZE at %L", &shift
->where
,
2544 else if (!less_than_bitsize1 ("I", i
, NULL
, shift
, true))
2552 gfc_check_kill (gfc_expr
*pid
, gfc_expr
*sig
)
2554 if (!type_check (pid
, 0, BT_INTEGER
))
2557 if (!type_check (sig
, 1, BT_INTEGER
))
2565 gfc_check_kill_sub (gfc_expr
*pid
, gfc_expr
*sig
, gfc_expr
*status
)
2567 if (!type_check (pid
, 0, BT_INTEGER
))
2570 if (!scalar_check (pid
, 0))
2573 if (!type_check (sig
, 1, BT_INTEGER
))
2576 if (!scalar_check (sig
, 1))
2582 if (!type_check (status
, 2, BT_INTEGER
))
2585 if (!scalar_check (status
, 2))
2593 gfc_check_kind (gfc_expr
*x
)
2595 if (gfc_bt_struct (x
->ts
.type
) || x
->ts
.type
== BT_CLASS
)
2597 gfc_error ("%qs argument of %qs intrinsic at %L must be of "
2598 "intrinsic type", gfc_current_intrinsic_arg
[0]->name
,
2599 gfc_current_intrinsic
, &x
->where
);
2602 if (x
->ts
.type
== BT_PROCEDURE
)
2604 gfc_error ("%qs argument of %qs intrinsic at %L must be a data entity",
2605 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
2615 gfc_check_lbound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2617 if (!array_check (array
, 0))
2620 if (!dim_check (dim
, 1, false))
2623 if (!dim_rank_check (dim
, array
, 1))
2626 if (!kind_check (kind
, 2, BT_INTEGER
))
2628 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
2629 "with KIND argument at %L",
2630 gfc_current_intrinsic
, &kind
->where
))
2638 gfc_check_lcobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
2640 if (flag_coarray
== GFC_FCOARRAY_NONE
)
2642 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
2646 if (!coarray_check (coarray
, 0))
2651 if (!dim_check (dim
, 1, false))
2654 if (!dim_corank_check (dim
, coarray
))
2658 if (!kind_check (kind
, 2, BT_INTEGER
))
2666 gfc_check_len_lentrim (gfc_expr
*s
, gfc_expr
*kind
)
2668 if (!type_check (s
, 0, BT_CHARACTER
))
2671 if (!kind_check (kind
, 1, BT_INTEGER
))
2673 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
2674 "with KIND argument at %L",
2675 gfc_current_intrinsic
, &kind
->where
))
2683 gfc_check_lge_lgt_lle_llt (gfc_expr
*a
, gfc_expr
*b
)
2685 if (!type_check (a
, 0, BT_CHARACTER
))
2687 if (!kind_value_check (a
, 0, gfc_default_character_kind
))
2690 if (!type_check (b
, 1, BT_CHARACTER
))
2692 if (!kind_value_check (b
, 1, gfc_default_character_kind
))
2700 gfc_check_link (gfc_expr
*path1
, gfc_expr
*path2
)
2702 if (!type_check (path1
, 0, BT_CHARACTER
))
2704 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2707 if (!type_check (path2
, 1, BT_CHARACTER
))
2709 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
2717 gfc_check_link_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2719 if (!type_check (path1
, 0, BT_CHARACTER
))
2721 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2724 if (!type_check (path2
, 1, BT_CHARACTER
))
2726 if (!kind_value_check (path2
, 0, gfc_default_character_kind
))
2732 if (!type_check (status
, 2, BT_INTEGER
))
2735 if (!scalar_check (status
, 2))
2743 gfc_check_loc (gfc_expr
*expr
)
2745 return variable_check (expr
, 0, true);
2750 gfc_check_symlnk (gfc_expr
*path1
, gfc_expr
*path2
)
2752 if (!type_check (path1
, 0, BT_CHARACTER
))
2754 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2757 if (!type_check (path2
, 1, BT_CHARACTER
))
2759 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
2767 gfc_check_symlnk_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2769 if (!type_check (path1
, 0, BT_CHARACTER
))
2771 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2774 if (!type_check (path2
, 1, BT_CHARACTER
))
2776 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
2782 if (!type_check (status
, 2, BT_INTEGER
))
2785 if (!scalar_check (status
, 2))
2793 gfc_check_logical (gfc_expr
*a
, gfc_expr
*kind
)
2795 if (!type_check (a
, 0, BT_LOGICAL
))
2797 if (!kind_check (kind
, 1, BT_LOGICAL
))
2804 /* Min/max family. */
2807 min_max_args (gfc_actual_arglist
*args
)
2809 gfc_actual_arglist
*arg
;
2810 int i
, j
, nargs
, *nlabels
, nlabelless
;
2811 bool a1
= false, a2
= false;
2813 if (args
== NULL
|| args
->next
== NULL
)
2815 gfc_error ("Intrinsic %qs at %L must have at least two arguments",
2816 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
2823 if (!args
->next
->name
)
2827 for (arg
= args
; arg
; arg
= arg
->next
)
2834 /* Note: Having a keywordless argument after an "arg=" is checked before. */
2836 nlabels
= XALLOCAVEC (int, nargs
);
2837 for (arg
= args
, i
= 0; arg
; arg
= arg
->next
, i
++)
2843 if (arg
->name
[0] != 'a' || arg
->name
[1] < '1' || arg
->name
[1] > '9')
2845 n
= strtol (&arg
->name
[1], &endp
, 10);
2846 if (endp
[0] != '\0')
2850 if (n
<= nlabelless
)
2863 gfc_error ("Missing %qs argument to the %s intrinsic at %L",
2864 !a1
? "a1" : "a2", gfc_current_intrinsic
,
2865 gfc_current_intrinsic_where
);
2869 /* Check for duplicates. */
2870 for (i
= 0; i
< nargs
; i
++)
2871 for (j
= i
+ 1; j
< nargs
; j
++)
2872 if (nlabels
[i
] == nlabels
[j
])
2878 gfc_error ("Duplicate argument %qs at %L to intrinsic %s", arg
->name
,
2879 &arg
->expr
->where
, gfc_current_intrinsic
);
2883 gfc_error ("Unknown argument %qs at %L to intrinsic %s", arg
->name
,
2884 &arg
->expr
->where
, gfc_current_intrinsic
);
2890 check_rest (bt type
, int kind
, gfc_actual_arglist
*arglist
)
2892 gfc_actual_arglist
*arg
, *tmp
;
2896 if (!min_max_args (arglist
))
2899 for (arg
= arglist
, n
=1; arg
; arg
= arg
->next
, n
++)
2902 if (x
->ts
.type
!= type
|| x
->ts
.kind
!= kind
)
2904 if (x
->ts
.type
== type
)
2906 if (!gfc_notify_std (GFC_STD_GNU
, "Different type "
2907 "kinds at %L", &x
->where
))
2912 gfc_error ("%<a%d%> argument of %qs intrinsic at %L must be "
2913 "%s(%d)", n
, gfc_current_intrinsic
, &x
->where
,
2914 gfc_basic_typename (type
), kind
);
2919 for (tmp
= arglist
, m
=1; tmp
!= arg
; tmp
= tmp
->next
, m
++)
2920 if (!gfc_check_conformance (tmp
->expr
, x
,
2921 "arguments 'a%d' and 'a%d' for "
2922 "intrinsic '%s'", m
, n
,
2923 gfc_current_intrinsic
))
2932 gfc_check_min_max (gfc_actual_arglist
*arg
)
2936 if (!min_max_args (arg
))
2941 if (x
->ts
.type
== BT_CHARACTER
)
2943 if (!gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
2944 "with CHARACTER argument at %L",
2945 gfc_current_intrinsic
, &x
->where
))
2948 else if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
2950 gfc_error ("%<a1%> argument of %qs intrinsic at %L must be INTEGER, "
2951 "REAL or CHARACTER", gfc_current_intrinsic
, &x
->where
);
2955 return check_rest (x
->ts
.type
, x
->ts
.kind
, arg
);
2960 gfc_check_min_max_integer (gfc_actual_arglist
*arg
)
2962 return check_rest (BT_INTEGER
, gfc_default_integer_kind
, arg
);
2967 gfc_check_min_max_real (gfc_actual_arglist
*arg
)
2969 return check_rest (BT_REAL
, gfc_default_real_kind
, arg
);
2974 gfc_check_min_max_double (gfc_actual_arglist
*arg
)
2976 return check_rest (BT_REAL
, gfc_default_double_kind
, arg
);
2980 /* End of min/max family. */
2983 gfc_check_malloc (gfc_expr
*size
)
2985 if (!type_check (size
, 0, BT_INTEGER
))
2988 if (!scalar_check (size
, 0))
2996 gfc_check_matmul (gfc_expr
*matrix_a
, gfc_expr
*matrix_b
)
2998 if ((matrix_a
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_a
->ts
))
3000 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3001 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
3002 gfc_current_intrinsic
, &matrix_a
->where
);
3006 if ((matrix_b
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_b
->ts
))
3008 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3009 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
3010 gfc_current_intrinsic
, &matrix_b
->where
);
3014 if ((matrix_a
->ts
.type
== BT_LOGICAL
&& gfc_numeric_ts (&matrix_b
->ts
))
3015 || (gfc_numeric_ts (&matrix_a
->ts
) && matrix_b
->ts
.type
== BT_LOGICAL
))
3017 gfc_error ("Argument types of %qs intrinsic at %L must match (%s/%s)",
3018 gfc_current_intrinsic
, &matrix_a
->where
,
3019 gfc_typename(&matrix_a
->ts
), gfc_typename(&matrix_b
->ts
));
3023 switch (matrix_a
->rank
)
3026 if (!rank_check (matrix_b
, 1, 2))
3028 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
3029 if (!identical_dimen_shape (matrix_a
, 0, matrix_b
, 0))
3031 gfc_error ("Different shape on dimension 1 for arguments %qs "
3032 "and %qs at %L for intrinsic matmul",
3033 gfc_current_intrinsic_arg
[0]->name
,
3034 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
3040 if (matrix_b
->rank
!= 2)
3042 if (!rank_check (matrix_b
, 1, 1))
3045 /* matrix_b has rank 1 or 2 here. Common check for the cases
3046 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
3047 - matrix_a has shape (n,m) and matrix_b has shape (m). */
3048 if (!identical_dimen_shape (matrix_a
, 1, matrix_b
, 0))
3050 gfc_error ("Different shape on dimension 2 for argument %qs and "
3051 "dimension 1 for argument %qs at %L for intrinsic "
3052 "matmul", gfc_current_intrinsic_arg
[0]->name
,
3053 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
3059 gfc_error ("%qs argument of %qs intrinsic at %L must be of rank "
3060 "1 or 2", gfc_current_intrinsic_arg
[0]->name
,
3061 gfc_current_intrinsic
, &matrix_a
->where
);
3069 /* Whoever came up with this interface was probably on something.
3070 The possibilities for the occupation of the second and third
3077 NULL MASK minloc(array, mask=m)
3080 I.e. in the case of minloc(array,mask), mask will be in the second
3081 position of the argument list and we'll have to fix that up. */
3084 gfc_check_minloc_maxloc (gfc_actual_arglist
*ap
)
3086 gfc_expr
*a
, *m
, *d
;
3089 if (!int_or_real_check (a
, 0) || !array_check (a
, 0))
3093 m
= ap
->next
->next
->expr
;
3095 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
3096 && ap
->next
->name
== NULL
)
3100 ap
->next
->expr
= NULL
;
3101 ap
->next
->next
->expr
= m
;
3104 if (!dim_check (d
, 1, false))
3107 if (!dim_rank_check (d
, a
, 0))
3110 if (m
!= NULL
&& !type_check (m
, 2, BT_LOGICAL
))
3114 && !gfc_check_conformance (a
, m
,
3115 "arguments '%s' and '%s' for intrinsic %s",
3116 gfc_current_intrinsic_arg
[0]->name
,
3117 gfc_current_intrinsic_arg
[2]->name
,
3118 gfc_current_intrinsic
))
3125 /* Similar to minloc/maxloc, the argument list might need to be
3126 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
3127 difference is that MINLOC/MAXLOC take an additional KIND argument.
3128 The possibilities are:
3134 NULL MASK minval(array, mask=m)
3137 I.e. in the case of minval(array,mask), mask will be in the second
3138 position of the argument list and we'll have to fix that up. */
3141 check_reduction (gfc_actual_arglist
*ap
)
3143 gfc_expr
*a
, *m
, *d
;
3147 m
= ap
->next
->next
->expr
;
3149 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
3150 && ap
->next
->name
== NULL
)
3154 ap
->next
->expr
= NULL
;
3155 ap
->next
->next
->expr
= m
;
3158 if (!dim_check (d
, 1, false))
3161 if (!dim_rank_check (d
, a
, 0))
3164 if (m
!= NULL
&& !type_check (m
, 2, BT_LOGICAL
))
3168 && !gfc_check_conformance (a
, m
,
3169 "arguments '%s' and '%s' for intrinsic %s",
3170 gfc_current_intrinsic_arg
[0]->name
,
3171 gfc_current_intrinsic_arg
[2]->name
,
3172 gfc_current_intrinsic
))
3180 gfc_check_minval_maxval (gfc_actual_arglist
*ap
)
3182 if (!int_or_real_check (ap
->expr
, 0)
3183 || !array_check (ap
->expr
, 0))
3186 return check_reduction (ap
);
3191 gfc_check_product_sum (gfc_actual_arglist
*ap
)
3193 if (!numeric_check (ap
->expr
, 0)
3194 || !array_check (ap
->expr
, 0))
3197 return check_reduction (ap
);
3201 /* For IANY, IALL and IPARITY. */
3204 gfc_check_mask (gfc_expr
*i
, gfc_expr
*kind
)
3208 if (!type_check (i
, 0, BT_INTEGER
))
3211 if (!nonnegative_check ("I", i
))
3214 if (!kind_check (kind
, 1, BT_INTEGER
))
3218 gfc_extract_int (kind
, &k
);
3220 k
= gfc_default_integer_kind
;
3222 if (!less_than_bitsizekind ("I", i
, k
))
3230 gfc_check_transf_bit_intrins (gfc_actual_arglist
*ap
)
3232 if (ap
->expr
->ts
.type
!= BT_INTEGER
)
3234 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER",
3235 gfc_current_intrinsic_arg
[0]->name
,
3236 gfc_current_intrinsic
, &ap
->expr
->where
);
3240 if (!array_check (ap
->expr
, 0))
3243 return check_reduction (ap
);
3248 gfc_check_merge (gfc_expr
*tsource
, gfc_expr
*fsource
, gfc_expr
*mask
)
3250 if (!same_type_check (tsource
, 0, fsource
, 1))
3253 if (!type_check (mask
, 2, BT_LOGICAL
))
3256 if (tsource
->ts
.type
== BT_CHARACTER
)
3257 return gfc_check_same_strlen (tsource
, fsource
, "MERGE intrinsic");
3264 gfc_check_merge_bits (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*mask
)
3266 if (!type_check (i
, 0, BT_INTEGER
))
3269 if (!type_check (j
, 1, BT_INTEGER
))
3272 if (!type_check (mask
, 2, BT_INTEGER
))
3275 if (!same_type_check (i
, 0, j
, 1))
3278 if (!same_type_check (i
, 0, mask
, 2))
3286 gfc_check_move_alloc (gfc_expr
*from
, gfc_expr
*to
)
3288 if (!variable_check (from
, 0, false))
3290 if (!allocatable_check (from
, 0))
3292 if (gfc_is_coindexed (from
))
3294 gfc_error ("The FROM argument to MOVE_ALLOC at %L shall not be "
3295 "coindexed", &from
->where
);
3299 if (!variable_check (to
, 1, false))
3301 if (!allocatable_check (to
, 1))
3303 if (gfc_is_coindexed (to
))
3305 gfc_error ("The TO argument to MOVE_ALLOC at %L shall not be "
3306 "coindexed", &to
->where
);
3310 if (from
->ts
.type
== BT_CLASS
&& to
->ts
.type
== BT_DERIVED
)
3312 gfc_error ("The TO arguments in MOVE_ALLOC at %L must be "
3313 "polymorphic if FROM is polymorphic",
3318 if (!same_type_check (to
, 1, from
, 0))
3321 if (to
->rank
!= from
->rank
)
3323 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
3324 "must have the same rank %d/%d", &to
->where
, from
->rank
,
3329 /* IR F08/0040; cf. 12-006A. */
3330 if (gfc_get_corank (to
) != gfc_get_corank (from
))
3332 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
3333 "must have the same corank %d/%d", &to
->where
,
3334 gfc_get_corank (from
), gfc_get_corank (to
));
3338 /* CLASS arguments: Make sure the vtab of from is present. */
3339 if (to
->ts
.type
== BT_CLASS
&& !UNLIMITED_POLY (from
))
3340 gfc_find_vtab (&from
->ts
);
3347 gfc_check_nearest (gfc_expr
*x
, gfc_expr
*s
)
3349 if (!type_check (x
, 0, BT_REAL
))
3352 if (!type_check (s
, 1, BT_REAL
))
3355 if (s
->expr_type
== EXPR_CONSTANT
)
3357 if (mpfr_sgn (s
->value
.real
) == 0)
3359 gfc_error ("Argument %<S%> of NEAREST at %L shall not be zero",
3370 gfc_check_new_line (gfc_expr
*a
)
3372 if (!type_check (a
, 0, BT_CHARACTER
))
3380 gfc_check_norm2 (gfc_expr
*array
, gfc_expr
*dim
)
3382 if (!type_check (array
, 0, BT_REAL
))
3385 if (!array_check (array
, 0))
3388 if (!dim_rank_check (dim
, array
, false))
3395 gfc_check_null (gfc_expr
*mold
)
3397 symbol_attribute attr
;
3402 if (!variable_check (mold
, 0, true))
3405 attr
= gfc_variable_attr (mold
, NULL
);
3407 if (!attr
.pointer
&& !attr
.proc_pointer
&& !attr
.allocatable
)
3409 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER, "
3410 "ALLOCATABLE or procedure pointer",
3411 gfc_current_intrinsic_arg
[0]->name
,
3412 gfc_current_intrinsic
, &mold
->where
);
3416 if (attr
.allocatable
3417 && !gfc_notify_std (GFC_STD_F2003
, "NULL intrinsic with "
3418 "allocatable MOLD at %L", &mold
->where
))
3422 if (gfc_is_coindexed (mold
))
3424 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
3425 "coindexed", gfc_current_intrinsic_arg
[0]->name
,
3426 gfc_current_intrinsic
, &mold
->where
);
3435 gfc_check_pack (gfc_expr
*array
, gfc_expr
*mask
, gfc_expr
*vector
)
3437 if (!array_check (array
, 0))
3440 if (!type_check (mask
, 1, BT_LOGICAL
))
3443 if (!gfc_check_conformance (array
, mask
,
3444 "arguments '%s' and '%s' for intrinsic '%s'",
3445 gfc_current_intrinsic_arg
[0]->name
,
3446 gfc_current_intrinsic_arg
[1]->name
,
3447 gfc_current_intrinsic
))
3452 mpz_t array_size
, vector_size
;
3453 bool have_array_size
, have_vector_size
;
3455 if (!same_type_check (array
, 0, vector
, 2))
3458 if (!rank_check (vector
, 2, 1))
3461 /* VECTOR requires at least as many elements as MASK
3462 has .TRUE. values. */
3463 have_array_size
= gfc_array_size(array
, &array_size
);
3464 have_vector_size
= gfc_array_size(vector
, &vector_size
);
3466 if (have_vector_size
3467 && (mask
->expr_type
== EXPR_ARRAY
3468 || (mask
->expr_type
== EXPR_CONSTANT
3469 && have_array_size
)))
3471 int mask_true_values
= 0;
3473 if (mask
->expr_type
== EXPR_ARRAY
)
3475 gfc_constructor
*mask_ctor
;
3476 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
3479 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
3481 mask_true_values
= 0;
3485 if (mask_ctor
->expr
->value
.logical
)
3488 mask_ctor
= gfc_constructor_next (mask_ctor
);
3491 else if (mask
->expr_type
== EXPR_CONSTANT
&& mask
->value
.logical
)
3492 mask_true_values
= mpz_get_si (array_size
);
3494 if (mpz_get_si (vector_size
) < mask_true_values
)
3496 gfc_error ("%qs argument of %qs intrinsic at %L must "
3497 "provide at least as many elements as there "
3498 "are .TRUE. values in %qs (%ld/%d)",
3499 gfc_current_intrinsic_arg
[2]->name
,
3500 gfc_current_intrinsic
, &vector
->where
,
3501 gfc_current_intrinsic_arg
[1]->name
,
3502 mpz_get_si (vector_size
), mask_true_values
);
3507 if (have_array_size
)
3508 mpz_clear (array_size
);
3509 if (have_vector_size
)
3510 mpz_clear (vector_size
);
3518 gfc_check_parity (gfc_expr
*mask
, gfc_expr
*dim
)
3520 if (!type_check (mask
, 0, BT_LOGICAL
))
3523 if (!array_check (mask
, 0))
3526 if (!dim_rank_check (dim
, mask
, false))
3534 gfc_check_precision (gfc_expr
*x
)
3536 if (!real_or_complex_check (x
, 0))
3544 gfc_check_present (gfc_expr
*a
)
3548 if (!variable_check (a
, 0, true))
3551 sym
= a
->symtree
->n
.sym
;
3552 if (!sym
->attr
.dummy
)
3554 gfc_error ("%qs argument of %qs intrinsic at %L must be of a "
3555 "dummy variable", gfc_current_intrinsic_arg
[0]->name
,
3556 gfc_current_intrinsic
, &a
->where
);
3560 if (!sym
->attr
.optional
)
3562 gfc_error ("%qs argument of %qs intrinsic at %L must be of "
3563 "an OPTIONAL dummy variable",
3564 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3569 /* 13.14.82 PRESENT(A)
3571 Argument. A shall be the name of an optional dummy argument that is
3572 accessible in the subprogram in which the PRESENT function reference
3576 && !(a
->ref
->next
== NULL
&& a
->ref
->type
== REF_ARRAY
3577 && (a
->ref
->u
.ar
.type
== AR_FULL
3578 || (a
->ref
->u
.ar
.type
== AR_ELEMENT
3579 && a
->ref
->u
.ar
.as
->rank
== 0))))
3581 gfc_error ("%qs argument of %qs intrinsic at %L must not be a "
3582 "subobject of %qs", gfc_current_intrinsic_arg
[0]->name
,
3583 gfc_current_intrinsic
, &a
->where
, sym
->name
);
3592 gfc_check_radix (gfc_expr
*x
)
3594 if (!int_or_real_check (x
, 0))
3602 gfc_check_range (gfc_expr
*x
)
3604 if (!numeric_check (x
, 0))
3612 gfc_check_rank (gfc_expr
*a ATTRIBUTE_UNUSED
)
3614 /* Any data object is allowed; a "data object" is a "constant (4.1.3),
3615 variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
3617 bool is_variable
= true;
3619 /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
3620 if (a
->expr_type
== EXPR_FUNCTION
)
3621 is_variable
= a
->value
.function
.esym
3622 ? a
->value
.function
.esym
->result
->attr
.pointer
3623 : a
->symtree
->n
.sym
->result
->attr
.pointer
;
3625 if (a
->expr_type
== EXPR_OP
|| a
->expr_type
== EXPR_NULL
3626 || a
->expr_type
== EXPR_COMPCALL
|| a
->expr_type
== EXPR_PPC
3629 gfc_error ("The argument of the RANK intrinsic at %L must be a data "
3630 "object", &a
->where
);
3638 /* real, float, sngl. */
3640 gfc_check_real (gfc_expr
*a
, gfc_expr
*kind
)
3642 if (!numeric_check (a
, 0))
3645 if (!kind_check (kind
, 1, BT_REAL
))
3653 gfc_check_rename (gfc_expr
*path1
, gfc_expr
*path2
)
3655 if (!type_check (path1
, 0, BT_CHARACTER
))
3657 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
3660 if (!type_check (path2
, 1, BT_CHARACTER
))
3662 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
3670 gfc_check_rename_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
3672 if (!type_check (path1
, 0, BT_CHARACTER
))
3674 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
3677 if (!type_check (path2
, 1, BT_CHARACTER
))
3679 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
3685 if (!type_check (status
, 2, BT_INTEGER
))
3688 if (!scalar_check (status
, 2))
3696 gfc_check_repeat (gfc_expr
*x
, gfc_expr
*y
)
3698 if (!type_check (x
, 0, BT_CHARACTER
))
3701 if (!scalar_check (x
, 0))
3704 if (!type_check (y
, 0, BT_INTEGER
))
3707 if (!scalar_check (y
, 1))
3715 gfc_check_reshape (gfc_expr
*source
, gfc_expr
*shape
,
3716 gfc_expr
*pad
, gfc_expr
*order
)
3722 if (!array_check (source
, 0))
3725 if (!rank_check (shape
, 1, 1))
3728 if (!type_check (shape
, 1, BT_INTEGER
))
3731 if (!gfc_array_size (shape
, &size
))
3733 gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L must be an "
3734 "array of constant size", &shape
->where
);
3738 shape_size
= mpz_get_ui (size
);
3741 if (shape_size
<= 0)
3743 gfc_error ("%qs argument of %qs intrinsic at %L is empty",
3744 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3748 else if (shape_size
> GFC_MAX_DIMENSIONS
)
3750 gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L has more "
3751 "than %d elements", &shape
->where
, GFC_MAX_DIMENSIONS
);
3754 else if (shape
->expr_type
== EXPR_ARRAY
&& gfc_is_constant_expr (shape
))
3758 for (i
= 0; i
< shape_size
; ++i
)
3760 e
= gfc_constructor_lookup_expr (shape
->value
.constructor
, i
);
3761 if (e
->expr_type
!= EXPR_CONSTANT
)
3764 gfc_extract_int (e
, &extent
);
3767 gfc_error ("%qs argument of %qs intrinsic at %L has "
3768 "negative element (%d)",
3769 gfc_current_intrinsic_arg
[1]->name
,
3770 gfc_current_intrinsic
, &e
->where
, extent
);
3775 else if (shape
->expr_type
== EXPR_VARIABLE
&& shape
->ref
3776 && shape
->ref
->u
.ar
.type
== AR_FULL
&& shape
->ref
->u
.ar
.dimen
== 1
3777 && shape
->ref
->u
.ar
.as
3778 && shape
->ref
->u
.ar
.as
->lower
[0]->expr_type
== EXPR_CONSTANT
3779 && shape
->ref
->u
.ar
.as
->lower
[0]->ts
.type
== BT_INTEGER
3780 && shape
->ref
->u
.ar
.as
->upper
[0]->expr_type
== EXPR_CONSTANT
3781 && shape
->ref
->u
.ar
.as
->upper
[0]->ts
.type
== BT_INTEGER
3782 && shape
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
)
3787 v
= shape
->symtree
->n
.sym
->value
;
3789 for (i
= 0; i
< shape_size
; i
++)
3791 e
= gfc_constructor_lookup_expr (v
->value
.constructor
, i
);
3795 gfc_extract_int (e
, &extent
);
3799 gfc_error ("Element %d of actual argument of RESHAPE at %L "
3800 "cannot be negative", i
+ 1, &shape
->where
);
3808 if (!same_type_check (source
, 0, pad
, 2))
3811 if (!array_check (pad
, 2))
3817 if (!array_check (order
, 3))
3820 if (!type_check (order
, 3, BT_INTEGER
))
3823 if (order
->expr_type
== EXPR_ARRAY
)
3825 int i
, order_size
, dim
, perm
[GFC_MAX_DIMENSIONS
];
3828 for (i
= 0; i
< GFC_MAX_DIMENSIONS
; ++i
)
3831 gfc_array_size (order
, &size
);
3832 order_size
= mpz_get_ui (size
);
3835 if (order_size
!= shape_size
)
3837 gfc_error ("%qs argument of %qs intrinsic at %L "
3838 "has wrong number of elements (%d/%d)",
3839 gfc_current_intrinsic_arg
[3]->name
,
3840 gfc_current_intrinsic
, &order
->where
,
3841 order_size
, shape_size
);
3845 for (i
= 1; i
<= order_size
; ++i
)
3847 e
= gfc_constructor_lookup_expr (order
->value
.constructor
, i
-1);
3848 if (e
->expr_type
!= EXPR_CONSTANT
)
3851 gfc_extract_int (e
, &dim
);
3853 if (dim
< 1 || dim
> order_size
)
3855 gfc_error ("%qs argument of %qs intrinsic at %L "
3856 "has out-of-range dimension (%d)",
3857 gfc_current_intrinsic_arg
[3]->name
,
3858 gfc_current_intrinsic
, &e
->where
, dim
);
3862 if (perm
[dim
-1] != 0)
3864 gfc_error ("%qs argument of %qs intrinsic at %L has "
3865 "invalid permutation of dimensions (dimension "
3867 gfc_current_intrinsic_arg
[3]->name
,
3868 gfc_current_intrinsic
, &e
->where
, dim
);
3877 if (pad
== NULL
&& shape
->expr_type
== EXPR_ARRAY
3878 && gfc_is_constant_expr (shape
)
3879 && !(source
->expr_type
== EXPR_VARIABLE
&& source
->symtree
->n
.sym
->as
3880 && source
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
))
3882 /* Check the match in size between source and destination. */
3883 if (gfc_array_size (source
, &nelems
))
3889 mpz_init_set_ui (size
, 1);
3890 for (c
= gfc_constructor_first (shape
->value
.constructor
);
3891 c
; c
= gfc_constructor_next (c
))
3892 mpz_mul (size
, size
, c
->expr
->value
.integer
);
3894 test
= mpz_cmp (nelems
, size
) < 0 && mpz_cmp_ui (size
, 0) > 0;
3900 gfc_error ("Without padding, there are not enough elements "
3901 "in the intrinsic RESHAPE source at %L to match "
3902 "the shape", &source
->where
);
3913 gfc_check_same_type_as (gfc_expr
*a
, gfc_expr
*b
)
3915 if (a
->ts
.type
!= BT_DERIVED
&& a
->ts
.type
!= BT_CLASS
)
3917 gfc_error ("%qs argument of %qs intrinsic at %L "
3918 "cannot be of type %s",
3919 gfc_current_intrinsic_arg
[0]->name
,
3920 gfc_current_intrinsic
,
3921 &a
->where
, gfc_typename (&a
->ts
));
3925 if (!(gfc_type_is_extensible (a
->ts
.u
.derived
) || UNLIMITED_POLY (a
)))
3927 gfc_error ("%qs argument of %qs intrinsic at %L "
3928 "must be of an extensible type",
3929 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3934 if (b
->ts
.type
!= BT_DERIVED
&& b
->ts
.type
!= BT_CLASS
)
3936 gfc_error ("%qs argument of %qs intrinsic at %L "
3937 "cannot be of type %s",
3938 gfc_current_intrinsic_arg
[0]->name
,
3939 gfc_current_intrinsic
,
3940 &b
->where
, gfc_typename (&b
->ts
));
3944 if (!(gfc_type_is_extensible (b
->ts
.u
.derived
) || UNLIMITED_POLY (b
)))
3946 gfc_error ("%qs argument of %qs intrinsic at %L "
3947 "must be of an extensible type",
3948 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
3958 gfc_check_scale (gfc_expr
*x
, gfc_expr
*i
)
3960 if (!type_check (x
, 0, BT_REAL
))
3963 if (!type_check (i
, 1, BT_INTEGER
))
3971 gfc_check_scan (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
3973 if (!type_check (x
, 0, BT_CHARACTER
))
3976 if (!type_check (y
, 1, BT_CHARACTER
))
3979 if (z
!= NULL
&& !type_check (z
, 2, BT_LOGICAL
))
3982 if (!kind_check (kind
, 3, BT_INTEGER
))
3984 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
3985 "with KIND argument at %L",
3986 gfc_current_intrinsic
, &kind
->where
))
3989 if (!same_type_check (x
, 0, y
, 1))
3997 gfc_check_secnds (gfc_expr
*r
)
3999 if (!type_check (r
, 0, BT_REAL
))
4002 if (!kind_value_check (r
, 0, 4))
4005 if (!scalar_check (r
, 0))
4013 gfc_check_selected_char_kind (gfc_expr
*name
)
4015 if (!type_check (name
, 0, BT_CHARACTER
))
4018 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
4021 if (!scalar_check (name
, 0))
4029 gfc_check_selected_int_kind (gfc_expr
*r
)
4031 if (!type_check (r
, 0, BT_INTEGER
))
4034 if (!scalar_check (r
, 0))
4042 gfc_check_selected_real_kind (gfc_expr
*p
, gfc_expr
*r
, gfc_expr
*radix
)
4044 if (p
== NULL
&& r
== NULL
4045 && !gfc_notify_std (GFC_STD_F2008
, "SELECTED_REAL_KIND with"
4046 " neither %<P%> nor %<R%> argument at %L",
4047 gfc_current_intrinsic_where
))
4052 if (!type_check (p
, 0, BT_INTEGER
))
4055 if (!scalar_check (p
, 0))
4061 if (!type_check (r
, 1, BT_INTEGER
))
4064 if (!scalar_check (r
, 1))
4070 if (!type_check (radix
, 1, BT_INTEGER
))
4073 if (!scalar_check (radix
, 1))
4076 if (!gfc_notify_std (GFC_STD_F2008
, "%qs intrinsic with "
4077 "RADIX argument at %L", gfc_current_intrinsic
,
4087 gfc_check_set_exponent (gfc_expr
*x
, gfc_expr
*i
)
4089 if (!type_check (x
, 0, BT_REAL
))
4092 if (!type_check (i
, 1, BT_INTEGER
))
4100 gfc_check_shape (gfc_expr
*source
, gfc_expr
*kind
)
4104 if (source
->rank
== 0 || source
->expr_type
!= EXPR_VARIABLE
)
4107 ar
= gfc_find_array_ref (source
);
4109 if (ar
->as
&& ar
->as
->type
== AS_ASSUMED_SIZE
&& ar
->type
== AR_FULL
)
4111 gfc_error ("%<source%> argument of %<shape%> intrinsic at %L must not be "
4112 "an assumed size array", &source
->where
);
4116 if (!kind_check (kind
, 1, BT_INTEGER
))
4118 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
4119 "with KIND argument at %L",
4120 gfc_current_intrinsic
, &kind
->where
))
4128 gfc_check_shift (gfc_expr
*i
, gfc_expr
*shift
)
4130 if (!type_check (i
, 0, BT_INTEGER
))
4133 if (!type_check (shift
, 0, BT_INTEGER
))
4136 if (!nonnegative_check ("SHIFT", shift
))
4139 if (!less_than_bitsize1 ("I", i
, "SHIFT", shift
, true))
4147 gfc_check_sign (gfc_expr
*a
, gfc_expr
*b
)
4149 if (!int_or_real_check (a
, 0))
4152 if (!same_type_check (a
, 0, b
, 1))
4160 gfc_check_size (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
4162 if (!array_check (array
, 0))
4165 if (!dim_check (dim
, 1, true))
4168 if (!dim_rank_check (dim
, array
, 0))
4171 if (!kind_check (kind
, 2, BT_INTEGER
))
4173 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
4174 "with KIND argument at %L",
4175 gfc_current_intrinsic
, &kind
->where
))
4184 gfc_check_sizeof (gfc_expr
*arg
)
4186 if (arg
->ts
.type
== BT_PROCEDURE
)
4188 gfc_error ("%qs argument of %qs intrinsic at %L shall not be a procedure",
4189 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4194 /* TYPE(*) is acceptable if and only if it uses an array descriptor. */
4195 if (arg
->ts
.type
== BT_ASSUMED
4196 && (arg
->symtree
->n
.sym
->as
== NULL
4197 || (arg
->symtree
->n
.sym
->as
->type
!= AS_ASSUMED_SHAPE
4198 && arg
->symtree
->n
.sym
->as
->type
!= AS_DEFERRED
4199 && arg
->symtree
->n
.sym
->as
->type
!= AS_ASSUMED_RANK
)))
4201 gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
4202 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4207 if (arg
->rank
&& arg
->expr_type
== EXPR_VARIABLE
4208 && arg
->symtree
->n
.sym
->as
!= NULL
4209 && arg
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
&& arg
->ref
4210 && arg
->ref
->type
== REF_ARRAY
&& arg
->ref
->u
.ar
.type
== AR_FULL
)
4212 gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
4213 "assumed-size array", gfc_current_intrinsic_arg
[0]->name
,
4214 gfc_current_intrinsic
, &arg
->where
);
4222 /* Check whether an expression is interoperable. When returning false,
4223 msg is set to a string telling why the expression is not interoperable,
4224 otherwise, it is set to NULL. The msg string can be used in diagnostics.
4225 If c_loc is true, character with len > 1 are allowed (cf. Fortran
4226 2003corr5); additionally, assumed-shape/assumed-rank/deferred-shape
4227 arrays are permitted. And if c_f_ptr is true, deferred-shape arrays
4231 is_c_interoperable (gfc_expr
*expr
, const char **msg
, bool c_loc
, bool c_f_ptr
)
4235 if (expr
->ts
.type
== BT_CLASS
)
4237 *msg
= "Expression is polymorphic";
4241 if (expr
->ts
.type
== BT_DERIVED
&& !expr
->ts
.u
.derived
->attr
.is_bind_c
4242 && !expr
->ts
.u
.derived
->ts
.is_iso_c
)
4244 *msg
= "Expression is a noninteroperable derived type";
4248 if (expr
->ts
.type
== BT_PROCEDURE
)
4250 *msg
= "Procedure unexpected as argument";
4254 if (gfc_notification_std (GFC_STD_GNU
) && expr
->ts
.type
== BT_LOGICAL
)
4257 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
4258 if (gfc_logical_kinds
[i
].kind
== expr
->ts
.kind
)
4260 *msg
= "Extension to use a non-C_Bool-kind LOGICAL";
4264 if (gfc_notification_std (GFC_STD_GNU
) && expr
->ts
.type
== BT_CHARACTER
4265 && expr
->ts
.kind
!= 1)
4267 *msg
= "Extension to use a non-C_CHAR-kind CHARACTER";
4271 if (expr
->ts
.type
== BT_CHARACTER
) {
4272 if (expr
->ts
.deferred
)
4274 /* TS 29113 allows deferred-length strings as dummy arguments,
4275 but it is not an interoperable type. */
4276 *msg
= "Expression shall not be a deferred-length string";
4280 if (expr
->ts
.u
.cl
&& expr
->ts
.u
.cl
->length
4281 && !gfc_simplify_expr (expr
, 0))
4282 gfc_internal_error ("is_c_interoperable(): gfc_simplify_expr failed");
4284 if (!c_loc
&& expr
->ts
.u
.cl
4285 && (!expr
->ts
.u
.cl
->length
4286 || expr
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
4287 || mpz_cmp_si (expr
->ts
.u
.cl
->length
->value
.integer
, 1) != 0))
4289 *msg
= "Type shall have a character length of 1";
4294 /* Note: The following checks are about interoperatable variables, Fortran
4295 15.3.5/15.3.6. In intrinsics like C_LOC or in procedure interface, more
4296 is allowed, e.g. assumed-shape arrays with TS 29113. */
4298 if (gfc_is_coarray (expr
))
4300 *msg
= "Coarrays are not interoperable";
4304 if (!c_loc
&& expr
->rank
> 0 && expr
->expr_type
!= EXPR_ARRAY
)
4306 gfc_array_ref
*ar
= gfc_find_array_ref (expr
);
4307 if (ar
->type
!= AR_FULL
)
4309 *msg
= "Only whole-arrays are interoperable";
4312 if (!c_f_ptr
&& ar
->as
->type
!= AS_EXPLICIT
4313 && ar
->as
->type
!= AS_ASSUMED_SIZE
)
4315 *msg
= "Only explicit-size and assumed-size arrays are interoperable";
4325 gfc_check_c_sizeof (gfc_expr
*arg
)
4329 if (!is_c_interoperable (arg
, &msg
, false, false))
4331 gfc_error ("%qs argument of %qs intrinsic at %L must be an "
4332 "interoperable data entity: %s",
4333 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4338 if (arg
->ts
.type
== BT_ASSUMED
)
4340 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
4342 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4347 if (arg
->rank
&& arg
->expr_type
== EXPR_VARIABLE
4348 && arg
->symtree
->n
.sym
->as
!= NULL
4349 && arg
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
&& arg
->ref
4350 && arg
->ref
->type
== REF_ARRAY
&& arg
->ref
->u
.ar
.type
== AR_FULL
)
4352 gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
4353 "assumed-size array", gfc_current_intrinsic_arg
[0]->name
,
4354 gfc_current_intrinsic
, &arg
->where
);
4363 gfc_check_c_associated (gfc_expr
*c_ptr_1
, gfc_expr
*c_ptr_2
)
4365 if (c_ptr_1
->ts
.type
!= BT_DERIVED
4366 || c_ptr_1
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
4367 || (c_ptr_1
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_PTR
4368 && c_ptr_1
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_FUNPTR
))
4370 gfc_error ("Argument C_PTR_1 at %L to C_ASSOCIATED shall have the "
4371 "type TYPE(C_PTR) or TYPE(C_FUNPTR)", &c_ptr_1
->where
);
4375 if (!scalar_check (c_ptr_1
, 0))
4379 && (c_ptr_2
->ts
.type
!= BT_DERIVED
4380 || c_ptr_2
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
4381 || (c_ptr_1
->ts
.u
.derived
->intmod_sym_id
4382 != c_ptr_2
->ts
.u
.derived
->intmod_sym_id
)))
4384 gfc_error ("Argument C_PTR_2 at %L to C_ASSOCIATED shall have the "
4385 "same type as C_PTR_1: %s instead of %s", &c_ptr_1
->where
,
4386 gfc_typename (&c_ptr_1
->ts
),
4387 gfc_typename (&c_ptr_2
->ts
));
4391 if (c_ptr_2
&& !scalar_check (c_ptr_2
, 1))
4399 gfc_check_c_f_pointer (gfc_expr
*cptr
, gfc_expr
*fptr
, gfc_expr
*shape
)
4401 symbol_attribute attr
;
4404 if (cptr
->ts
.type
!= BT_DERIVED
4405 || cptr
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
4406 || cptr
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_PTR
)
4408 gfc_error ("Argument CPTR at %L to C_F_POINTER shall have the "
4409 "type TYPE(C_PTR)", &cptr
->where
);
4413 if (!scalar_check (cptr
, 0))
4416 attr
= gfc_expr_attr (fptr
);
4420 gfc_error ("Argument FPTR at %L to C_F_POINTER must be a pointer",
4425 if (fptr
->ts
.type
== BT_CLASS
)
4427 gfc_error ("FPTR argument at %L to C_F_POINTER shall not be polymorphic",
4432 if (gfc_is_coindexed (fptr
))
4434 gfc_error ("Argument FPTR at %L to C_F_POINTER shall not be "
4435 "coindexed", &fptr
->where
);
4439 if (fptr
->rank
== 0 && shape
)
4441 gfc_error ("Unexpected SHAPE argument at %L to C_F_POINTER with scalar "
4442 "FPTR", &fptr
->where
);
4445 else if (fptr
->rank
&& !shape
)
4447 gfc_error ("Expected SHAPE argument to C_F_POINTER with array "
4448 "FPTR at %L", &fptr
->where
);
4452 if (shape
&& !rank_check (shape
, 2, 1))
4455 if (shape
&& !type_check (shape
, 2, BT_INTEGER
))
4461 if (gfc_array_size (shape
, &size
))
4463 if (mpz_cmp_ui (size
, fptr
->rank
) != 0)
4466 gfc_error ("SHAPE argument at %L to C_F_POINTER must have the same "
4467 "size as the RANK of FPTR", &shape
->where
);
4474 if (fptr
->ts
.type
== BT_CLASS
)
4476 gfc_error ("Polymorphic FPTR at %L to C_F_POINTER", &fptr
->where
);
4480 if (!is_c_interoperable (fptr
, &msg
, false, true))
4481 return gfc_notify_std (GFC_STD_F2008_TS
, "Noninteroperable array FPTR "
4482 "at %L to C_F_POINTER: %s", &fptr
->where
, msg
);
4489 gfc_check_c_f_procpointer (gfc_expr
*cptr
, gfc_expr
*fptr
)
4491 symbol_attribute attr
;
4493 if (cptr
->ts
.type
!= BT_DERIVED
4494 || cptr
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
4495 || cptr
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_FUNPTR
)
4497 gfc_error ("Argument CPTR at %L to C_F_PROCPOINTER shall have the "
4498 "type TYPE(C_FUNPTR)", &cptr
->where
);
4502 if (!scalar_check (cptr
, 0))
4505 attr
= gfc_expr_attr (fptr
);
4507 if (!attr
.proc_pointer
)
4509 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall be a procedure "
4510 "pointer", &fptr
->where
);
4514 if (gfc_is_coindexed (fptr
))
4516 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall not be "
4517 "coindexed", &fptr
->where
);
4521 if (!attr
.is_bind_c
)
4522 return gfc_notify_std (GFC_STD_F2008_TS
, "Noninteroperable procedure "
4523 "pointer at %L to C_F_PROCPOINTER", &fptr
->where
);
4530 gfc_check_c_funloc (gfc_expr
*x
)
4532 symbol_attribute attr
;
4534 if (gfc_is_coindexed (x
))
4536 gfc_error ("Argument X at %L to C_FUNLOC shall not be "
4537 "coindexed", &x
->where
);
4541 attr
= gfc_expr_attr (x
);
4543 if (attr
.function
&& !attr
.proc_pointer
&& x
->expr_type
== EXPR_VARIABLE
4544 && x
->symtree
->n
.sym
== x
->symtree
->n
.sym
->result
)
4546 gfc_namespace
*ns
= gfc_current_ns
;
4548 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
4549 if (x
->symtree
->n
.sym
== ns
->proc_name
)
4551 gfc_error ("Function result %qs at %L is invalid as X argument "
4552 "to C_FUNLOC", x
->symtree
->n
.sym
->name
, &x
->where
);
4557 if (attr
.flavor
!= FL_PROCEDURE
)
4559 gfc_error ("Argument X at %L to C_FUNLOC shall be a procedure "
4560 "or a procedure pointer", &x
->where
);
4564 if (!attr
.is_bind_c
)
4565 return gfc_notify_std (GFC_STD_F2008_TS
, "Noninteroperable procedure "
4566 "at %L to C_FUNLOC", &x
->where
);
4572 gfc_check_c_loc (gfc_expr
*x
)
4574 symbol_attribute attr
;
4577 if (gfc_is_coindexed (x
))
4579 gfc_error ("Argument X at %L to C_LOC shall not be coindexed", &x
->where
);
4583 if (x
->ts
.type
== BT_CLASS
)
4585 gfc_error ("X argument at %L to C_LOC shall not be polymorphic",
4590 attr
= gfc_expr_attr (x
);
4593 && (x
->expr_type
!= EXPR_VARIABLE
|| !attr
.target
4594 || attr
.flavor
== FL_PARAMETER
))
4596 gfc_error ("Argument X at %L to C_LOC shall have either "
4597 "the POINTER or the TARGET attribute", &x
->where
);
4601 if (x
->ts
.type
== BT_CHARACTER
4602 && gfc_var_strlen (x
) == 0)
4604 gfc_error ("Argument X at %L to C_LOC shall be not be a zero-sized "
4605 "string", &x
->where
);
4609 if (!is_c_interoperable (x
, &msg
, true, false))
4611 if (x
->ts
.type
== BT_CLASS
)
4613 gfc_error ("Argument at %L to C_LOC shall not be polymorphic",
4619 && !gfc_notify_std (GFC_STD_F2008_TS
,
4620 "Noninteroperable array at %L as"
4621 " argument to C_LOC: %s", &x
->where
, msg
))
4624 else if (x
->rank
> 0 && gfc_notification_std (GFC_STD_F2008
))
4626 gfc_array_ref
*ar
= gfc_find_array_ref (x
);
4628 if (ar
->as
->type
!= AS_EXPLICIT
&& ar
->as
->type
!= AS_ASSUMED_SIZE
4629 && !attr
.allocatable
4630 && !gfc_notify_std (GFC_STD_F2008
,
4631 "Array of interoperable type at %L "
4632 "to C_LOC which is nonallocatable and neither "
4633 "assumed size nor explicit size", &x
->where
))
4635 else if (ar
->type
!= AR_FULL
4636 && !gfc_notify_std (GFC_STD_F2008
, "Array section at %L "
4637 "to C_LOC", &x
->where
))
4646 gfc_check_sleep_sub (gfc_expr
*seconds
)
4648 if (!type_check (seconds
, 0, BT_INTEGER
))
4651 if (!scalar_check (seconds
, 0))
4658 gfc_check_sngl (gfc_expr
*a
)
4660 if (!type_check (a
, 0, BT_REAL
))
4663 if ((a
->ts
.kind
!= gfc_default_double_kind
)
4664 && !gfc_notify_std (GFC_STD_GNU
, "non double precision "
4665 "REAL argument to %s intrinsic at %L",
4666 gfc_current_intrinsic
, &a
->where
))
4673 gfc_check_spread (gfc_expr
*source
, gfc_expr
*dim
, gfc_expr
*ncopies
)
4675 if (source
->rank
>= GFC_MAX_DIMENSIONS
)
4677 gfc_error ("%qs argument of %qs intrinsic at %L must be less "
4678 "than rank %d", gfc_current_intrinsic_arg
[0]->name
,
4679 gfc_current_intrinsic
, &source
->where
, GFC_MAX_DIMENSIONS
);
4687 if (!dim_check (dim
, 1, false))
4690 /* dim_rank_check() does not apply here. */
4692 && dim
->expr_type
== EXPR_CONSTANT
4693 && (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
4694 || mpz_cmp_ui (dim
->value
.integer
, source
->rank
+ 1) > 0))
4696 gfc_error ("%qs argument of %qs intrinsic at %L is not a valid "
4697 "dimension index", gfc_current_intrinsic_arg
[1]->name
,
4698 gfc_current_intrinsic
, &dim
->where
);
4702 if (!type_check (ncopies
, 2, BT_INTEGER
))
4705 if (!scalar_check (ncopies
, 2))
4712 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
4716 gfc_check_fgetputc_sub (gfc_expr
*unit
, gfc_expr
*c
, gfc_expr
*status
)
4718 if (!type_check (unit
, 0, BT_INTEGER
))
4721 if (!scalar_check (unit
, 0))
4724 if (!type_check (c
, 1, BT_CHARACTER
))
4726 if (!kind_value_check (c
, 1, gfc_default_character_kind
))
4732 if (!type_check (status
, 2, BT_INTEGER
)
4733 || !kind_value_check (status
, 2, gfc_default_integer_kind
)
4734 || !scalar_check (status
, 2))
4742 gfc_check_fgetputc (gfc_expr
*unit
, gfc_expr
*c
)
4744 return gfc_check_fgetputc_sub (unit
, c
, NULL
);
4749 gfc_check_fgetput_sub (gfc_expr
*c
, gfc_expr
*status
)
4751 if (!type_check (c
, 0, BT_CHARACTER
))
4753 if (!kind_value_check (c
, 0, gfc_default_character_kind
))
4759 if (!type_check (status
, 1, BT_INTEGER
)
4760 || !kind_value_check (status
, 1, gfc_default_integer_kind
)
4761 || !scalar_check (status
, 1))
4769 gfc_check_fgetput (gfc_expr
*c
)
4771 return gfc_check_fgetput_sub (c
, NULL
);
4776 gfc_check_fseek_sub (gfc_expr
*unit
, gfc_expr
*offset
, gfc_expr
*whence
, gfc_expr
*status
)
4778 if (!type_check (unit
, 0, BT_INTEGER
))
4781 if (!scalar_check (unit
, 0))
4784 if (!type_check (offset
, 1, BT_INTEGER
))
4787 if (!scalar_check (offset
, 1))
4790 if (!type_check (whence
, 2, BT_INTEGER
))
4793 if (!scalar_check (whence
, 2))
4799 if (!type_check (status
, 3, BT_INTEGER
))
4802 if (!kind_value_check (status
, 3, 4))
4805 if (!scalar_check (status
, 3))
4814 gfc_check_fstat (gfc_expr
*unit
, gfc_expr
*array
)
4816 if (!type_check (unit
, 0, BT_INTEGER
))
4819 if (!scalar_check (unit
, 0))
4822 if (!type_check (array
, 1, BT_INTEGER
)
4823 || !kind_value_check (unit
, 0, gfc_default_integer_kind
))
4826 if (!array_check (array
, 1))
4834 gfc_check_fstat_sub (gfc_expr
*unit
, gfc_expr
*array
, gfc_expr
*status
)
4836 if (!type_check (unit
, 0, BT_INTEGER
))
4839 if (!scalar_check (unit
, 0))
4842 if (!type_check (array
, 1, BT_INTEGER
)
4843 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
4846 if (!array_check (array
, 1))
4852 if (!type_check (status
, 2, BT_INTEGER
)
4853 || !kind_value_check (status
, 2, gfc_default_integer_kind
))
4856 if (!scalar_check (status
, 2))
4864 gfc_check_ftell (gfc_expr
*unit
)
4866 if (!type_check (unit
, 0, BT_INTEGER
))
4869 if (!scalar_check (unit
, 0))
4877 gfc_check_ftell_sub (gfc_expr
*unit
, gfc_expr
*offset
)
4879 if (!type_check (unit
, 0, BT_INTEGER
))
4882 if (!scalar_check (unit
, 0))
4885 if (!type_check (offset
, 1, BT_INTEGER
))
4888 if (!scalar_check (offset
, 1))
4896 gfc_check_stat (gfc_expr
*name
, gfc_expr
*array
)
4898 if (!type_check (name
, 0, BT_CHARACTER
))
4900 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
4903 if (!type_check (array
, 1, BT_INTEGER
)
4904 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
4907 if (!array_check (array
, 1))
4915 gfc_check_stat_sub (gfc_expr
*name
, gfc_expr
*array
, gfc_expr
*status
)
4917 if (!type_check (name
, 0, BT_CHARACTER
))
4919 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
4922 if (!type_check (array
, 1, BT_INTEGER
)
4923 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
4926 if (!array_check (array
, 1))
4932 if (!type_check (status
, 2, BT_INTEGER
)
4933 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
4936 if (!scalar_check (status
, 2))
4944 gfc_check_image_index (gfc_expr
*coarray
, gfc_expr
*sub
)
4948 if (flag_coarray
== GFC_FCOARRAY_NONE
)
4950 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
4954 if (!coarray_check (coarray
, 0))
4959 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
4960 gfc_current_intrinsic_arg
[1]->name
, &sub
->where
);
4964 if (gfc_array_size (sub
, &nelems
))
4966 int corank
= gfc_get_corank (coarray
);
4968 if (mpz_cmp_ui (nelems
, corank
) != 0)
4970 gfc_error ("The number of array elements of the SUB argument to "
4971 "IMAGE_INDEX at %L shall be %d (corank) not %d",
4972 &sub
->where
, corank
, (int) mpz_get_si (nelems
));
4984 gfc_check_num_images (gfc_expr
*distance
, gfc_expr
*failed
)
4986 if (flag_coarray
== GFC_FCOARRAY_NONE
)
4988 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
4994 if (!type_check (distance
, 0, BT_INTEGER
))
4997 if (!nonnegative_check ("DISTANCE", distance
))
5000 if (!scalar_check (distance
, 0))
5003 if (!gfc_notify_std (GFC_STD_F2008_TS
, "DISTANCE= argument to "
5004 "NUM_IMAGES at %L", &distance
->where
))
5010 if (!type_check (failed
, 1, BT_LOGICAL
))
5013 if (!scalar_check (failed
, 1))
5016 if (!gfc_notify_std (GFC_STD_F2008_TS
, "FAILED= argument to "
5017 "NUM_IMAGES at %L", &distance
->where
))
5026 gfc_check_this_image (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*distance
)
5028 if (flag_coarray
== GFC_FCOARRAY_NONE
)
5030 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5034 if (coarray
== NULL
&& dim
== NULL
&& distance
== NULL
)
5037 if (dim
!= NULL
&& coarray
== NULL
)
5039 gfc_error ("DIM argument without COARRAY argument not allowed for "
5040 "THIS_IMAGE intrinsic at %L", &dim
->where
);
5044 if (distance
&& (coarray
|| dim
))
5046 gfc_error ("The DISTANCE argument may not be specified together with the "
5047 "COARRAY or DIM argument in intrinsic at %L",
5052 /* Assume that we have "this_image (distance)". */
5053 if (coarray
&& !gfc_is_coarray (coarray
) && coarray
->ts
.type
== BT_INTEGER
)
5057 gfc_error ("Unexpected DIM argument with noncoarray argument at %L",
5066 if (!type_check (distance
, 2, BT_INTEGER
))
5069 if (!nonnegative_check ("DISTANCE", distance
))
5072 if (!scalar_check (distance
, 2))
5075 if (!gfc_notify_std (GFC_STD_F2008_TS
, "DISTANCE= argument to "
5076 "THIS_IMAGE at %L", &distance
->where
))
5082 if (!coarray_check (coarray
, 0))
5087 if (!dim_check (dim
, 1, false))
5090 if (!dim_corank_check (dim
, coarray
))
5097 /* Calculate the sizes for transfer, used by gfc_check_transfer and also
5098 by gfc_simplify_transfer. Return false if we cannot do so. */
5101 gfc_calculate_transfer_sizes (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
,
5102 size_t *source_size
, size_t *result_size
,
5103 size_t *result_length_p
)
5105 size_t result_elt_size
;
5107 if (source
->expr_type
== EXPR_FUNCTION
)
5110 if (size
&& size
->expr_type
!= EXPR_CONSTANT
)
5113 /* Calculate the size of the source. */
5114 *source_size
= gfc_target_expr_size (source
);
5115 if (*source_size
== 0)
5118 /* Determine the size of the element. */
5119 result_elt_size
= gfc_element_size (mold
);
5120 if (result_elt_size
== 0)
5123 if (mold
->expr_type
== EXPR_ARRAY
|| mold
->rank
|| size
)
5128 result_length
= (size_t)mpz_get_ui (size
->value
.integer
);
5131 result_length
= *source_size
/ result_elt_size
;
5132 if (result_length
* result_elt_size
< *source_size
)
5136 *result_size
= result_length
* result_elt_size
;
5137 if (result_length_p
)
5138 *result_length_p
= result_length
;
5141 *result_size
= result_elt_size
;
5148 gfc_check_transfer (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
)
5153 if (mold
->ts
.type
== BT_HOLLERITH
)
5155 gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L must not be"
5156 " %s", &mold
->where
, gfc_basic_typename (BT_HOLLERITH
));
5162 if (!type_check (size
, 2, BT_INTEGER
))
5165 if (!scalar_check (size
, 2))
5168 if (!nonoptional_check (size
, 2))
5172 if (!warn_surprising
)
5175 /* If we can't calculate the sizes, we cannot check any more.
5176 Return true for that case. */
5178 if (!gfc_calculate_transfer_sizes (source
, mold
, size
, &source_size
,
5179 &result_size
, NULL
))
5182 if (source_size
< result_size
)
5183 gfc_warning (0, "Intrinsic TRANSFER at %L has partly undefined result: "
5184 "source size %ld < result size %ld", &source
->where
,
5185 (long) source_size
, (long) result_size
);
5192 gfc_check_transpose (gfc_expr
*matrix
)
5194 if (!rank_check (matrix
, 0, 2))
5202 gfc_check_ubound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
5204 if (!array_check (array
, 0))
5207 if (!dim_check (dim
, 1, false))
5210 if (!dim_rank_check (dim
, array
, 0))
5213 if (!kind_check (kind
, 2, BT_INTEGER
))
5215 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
5216 "with KIND argument at %L",
5217 gfc_current_intrinsic
, &kind
->where
))
5225 gfc_check_ucobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
5227 if (flag_coarray
== GFC_FCOARRAY_NONE
)
5229 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5233 if (!coarray_check (coarray
, 0))
5238 if (!dim_check (dim
, 1, false))
5241 if (!dim_corank_check (dim
, coarray
))
5245 if (!kind_check (kind
, 2, BT_INTEGER
))
5253 gfc_check_unpack (gfc_expr
*vector
, gfc_expr
*mask
, gfc_expr
*field
)
5257 if (!rank_check (vector
, 0, 1))
5260 if (!array_check (mask
, 1))
5263 if (!type_check (mask
, 1, BT_LOGICAL
))
5266 if (!same_type_check (vector
, 0, field
, 2))
5269 if (mask
->expr_type
== EXPR_ARRAY
5270 && gfc_array_size (vector
, &vector_size
))
5272 int mask_true_count
= 0;
5273 gfc_constructor
*mask_ctor
;
5274 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
5277 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
5279 mask_true_count
= 0;
5283 if (mask_ctor
->expr
->value
.logical
)
5286 mask_ctor
= gfc_constructor_next (mask_ctor
);
5289 if (mpz_get_si (vector_size
) < mask_true_count
)
5291 gfc_error ("%qs argument of %qs intrinsic at %L must "
5292 "provide at least as many elements as there "
5293 "are .TRUE. values in %qs (%ld/%d)",
5294 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
5295 &vector
->where
, gfc_current_intrinsic_arg
[1]->name
,
5296 mpz_get_si (vector_size
), mask_true_count
);
5300 mpz_clear (vector_size
);
5303 if (mask
->rank
!= field
->rank
&& field
->rank
!= 0)
5305 gfc_error ("%qs argument of %qs intrinsic at %L must have "
5306 "the same rank as %qs or be a scalar",
5307 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
5308 &field
->where
, gfc_current_intrinsic_arg
[1]->name
);
5312 if (mask
->rank
== field
->rank
)
5315 for (i
= 0; i
< field
->rank
; i
++)
5316 if (! identical_dimen_shape (mask
, i
, field
, i
))
5318 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L "
5319 "must have identical shape.",
5320 gfc_current_intrinsic_arg
[2]->name
,
5321 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
5331 gfc_check_verify (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
5333 if (!type_check (x
, 0, BT_CHARACTER
))
5336 if (!same_type_check (x
, 0, y
, 1))
5339 if (z
!= NULL
&& !type_check (z
, 2, BT_LOGICAL
))
5342 if (!kind_check (kind
, 3, BT_INTEGER
))
5344 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
5345 "with KIND argument at %L",
5346 gfc_current_intrinsic
, &kind
->where
))
5354 gfc_check_trim (gfc_expr
*x
)
5356 if (!type_check (x
, 0, BT_CHARACTER
))
5359 if (!scalar_check (x
, 0))
5367 gfc_check_ttynam (gfc_expr
*unit
)
5369 if (!scalar_check (unit
, 0))
5372 if (!type_check (unit
, 0, BT_INTEGER
))
5379 /* Common check function for the half a dozen intrinsics that have a
5380 single real argument. */
5383 gfc_check_x (gfc_expr
*x
)
5385 if (!type_check (x
, 0, BT_REAL
))
5392 /************* Check functions for intrinsic subroutines *************/
5395 gfc_check_cpu_time (gfc_expr
*time
)
5397 if (!scalar_check (time
, 0))
5400 if (!type_check (time
, 0, BT_REAL
))
5403 if (!variable_check (time
, 0, false))
5411 gfc_check_date_and_time (gfc_expr
*date
, gfc_expr
*time
,
5412 gfc_expr
*zone
, gfc_expr
*values
)
5416 if (!type_check (date
, 0, BT_CHARACTER
))
5418 if (!kind_value_check (date
, 0, gfc_default_character_kind
))
5420 if (!scalar_check (date
, 0))
5422 if (!variable_check (date
, 0, false))
5428 if (!type_check (time
, 1, BT_CHARACTER
))
5430 if (!kind_value_check (time
, 1, gfc_default_character_kind
))
5432 if (!scalar_check (time
, 1))
5434 if (!variable_check (time
, 1, false))
5440 if (!type_check (zone
, 2, BT_CHARACTER
))
5442 if (!kind_value_check (zone
, 2, gfc_default_character_kind
))
5444 if (!scalar_check (zone
, 2))
5446 if (!variable_check (zone
, 2, false))
5452 if (!type_check (values
, 3, BT_INTEGER
))
5454 if (!array_check (values
, 3))
5456 if (!rank_check (values
, 3, 1))
5458 if (!variable_check (values
, 3, false))
5467 gfc_check_mvbits (gfc_expr
*from
, gfc_expr
*frompos
, gfc_expr
*len
,
5468 gfc_expr
*to
, gfc_expr
*topos
)
5470 if (!type_check (from
, 0, BT_INTEGER
))
5473 if (!type_check (frompos
, 1, BT_INTEGER
))
5476 if (!type_check (len
, 2, BT_INTEGER
))
5479 if (!same_type_check (from
, 0, to
, 3))
5482 if (!variable_check (to
, 3, false))
5485 if (!type_check (topos
, 4, BT_INTEGER
))
5488 if (!nonnegative_check ("frompos", frompos
))
5491 if (!nonnegative_check ("topos", topos
))
5494 if (!nonnegative_check ("len", len
))
5497 if (!less_than_bitsize2 ("from", from
, "frompos", frompos
, "len", len
))
5500 if (!less_than_bitsize2 ("to", to
, "topos", topos
, "len", len
))
5508 gfc_check_random_number (gfc_expr
*harvest
)
5510 if (!type_check (harvest
, 0, BT_REAL
))
5513 if (!variable_check (harvest
, 0, false))
5521 gfc_check_random_seed (gfc_expr
*size
, gfc_expr
*put
, gfc_expr
*get
)
5523 unsigned int nargs
= 0, kiss_size
;
5524 locus
*where
= NULL
;
5525 mpz_t put_size
, get_size
;
5526 bool have_gfc_real_16
; /* Try and mimic HAVE_GFC_REAL_16 in libgfortran. */
5528 have_gfc_real_16
= gfc_validate_kind (BT_REAL
, 16, true) != -1;
5530 /* Keep the number of bytes in sync with kiss_size in
5531 libgfortran/intrinsics/random.c. */
5532 kiss_size
= (have_gfc_real_16
? 48 : 32) / gfc_default_integer_kind
;
5536 if (size
->expr_type
!= EXPR_VARIABLE
5537 || !size
->symtree
->n
.sym
->attr
.optional
)
5540 if (!scalar_check (size
, 0))
5543 if (!type_check (size
, 0, BT_INTEGER
))
5546 if (!variable_check (size
, 0, false))
5549 if (!kind_value_check (size
, 0, gfc_default_integer_kind
))
5555 if (put
->expr_type
!= EXPR_VARIABLE
5556 || !put
->symtree
->n
.sym
->attr
.optional
)
5559 where
= &put
->where
;
5562 if (!array_check (put
, 1))
5565 if (!rank_check (put
, 1, 1))
5568 if (!type_check (put
, 1, BT_INTEGER
))
5571 if (!kind_value_check (put
, 1, gfc_default_integer_kind
))
5574 if (gfc_array_size (put
, &put_size
)
5575 && mpz_get_ui (put_size
) < kiss_size
)
5576 gfc_error ("Size of %qs argument of %qs intrinsic at %L "
5577 "too small (%i/%i)",
5578 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
5579 where
, (int) mpz_get_ui (put_size
), kiss_size
);
5584 if (get
->expr_type
!= EXPR_VARIABLE
5585 || !get
->symtree
->n
.sym
->attr
.optional
)
5588 where
= &get
->where
;
5591 if (!array_check (get
, 2))
5594 if (!rank_check (get
, 2, 1))
5597 if (!type_check (get
, 2, BT_INTEGER
))
5600 if (!variable_check (get
, 2, false))
5603 if (!kind_value_check (get
, 2, gfc_default_integer_kind
))
5606 if (gfc_array_size (get
, &get_size
)
5607 && mpz_get_ui (get_size
) < kiss_size
)
5608 gfc_error ("Size of %qs argument of %qs intrinsic at %L "
5609 "too small (%i/%i)",
5610 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
5611 where
, (int) mpz_get_ui (get_size
), kiss_size
);
5614 /* RANDOM_SEED may not have more than one non-optional argument. */
5616 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
, where
);
5622 gfc_check_fe_runtime_error (gfc_actual_arglist
*a
)
5626 int num_percent
, nargs
;
5629 if (e
->expr_type
!= EXPR_CONSTANT
)
5632 len
= e
->value
.character
.length
;
5633 if (e
->value
.character
.string
[len
-1] != '\0')
5634 gfc_internal_error ("fe_runtime_error string must be null terminated");
5637 for (i
=0; i
<len
-1; i
++)
5638 if (e
->value
.character
.string
[i
] == '%')
5642 for (; a
; a
= a
->next
)
5645 if (nargs
-1 != num_percent
)
5646 gfc_internal_error ("fe_runtime_error: Wrong number of arguments (%d instead of %d)",
5647 nargs
, num_percent
++);
5653 gfc_check_second_sub (gfc_expr
*time
)
5655 if (!scalar_check (time
, 0))
5658 if (!type_check (time
, 0, BT_REAL
))
5661 if (!kind_value_check (time
, 0, 4))
5668 /* COUNT and COUNT_MAX of SYSTEM_CLOCK are scalar, default-kind integer
5669 variables in Fortran 95. In Fortran 2003 and later, they can be of any
5670 kind, and COUNT_RATE can be of type real. Note, count, count_rate, and
5671 count_max are all optional arguments */
5674 gfc_check_system_clock (gfc_expr
*count
, gfc_expr
*count_rate
,
5675 gfc_expr
*count_max
)
5679 if (!scalar_check (count
, 0))
5682 if (!type_check (count
, 0, BT_INTEGER
))
5685 if (count
->ts
.kind
!= gfc_default_integer_kind
5686 && !gfc_notify_std (GFC_STD_F2003
, "COUNT argument to "
5687 "SYSTEM_CLOCK at %L has non-default kind",
5691 if (!variable_check (count
, 0, false))
5695 if (count_rate
!= NULL
)
5697 if (!scalar_check (count_rate
, 1))
5700 if (!variable_check (count_rate
, 1, false))
5703 if (count_rate
->ts
.type
== BT_REAL
)
5705 if (!gfc_notify_std (GFC_STD_F2003
, "Real COUNT_RATE argument to "
5706 "SYSTEM_CLOCK at %L", &count_rate
->where
))
5711 if (!type_check (count_rate
, 1, BT_INTEGER
))
5714 if (count_rate
->ts
.kind
!= gfc_default_integer_kind
5715 && !gfc_notify_std (GFC_STD_F2003
, "COUNT_RATE argument to "
5716 "SYSTEM_CLOCK at %L has non-default kind",
5717 &count_rate
->where
))
5723 if (count_max
!= NULL
)
5725 if (!scalar_check (count_max
, 2))
5728 if (!type_check (count_max
, 2, BT_INTEGER
))
5731 if (count_max
->ts
.kind
!= gfc_default_integer_kind
5732 && !gfc_notify_std (GFC_STD_F2003
, "COUNT_MAX argument to "
5733 "SYSTEM_CLOCK at %L has non-default kind",
5737 if (!variable_check (count_max
, 2, false))
5746 gfc_check_irand (gfc_expr
*x
)
5751 if (!scalar_check (x
, 0))
5754 if (!type_check (x
, 0, BT_INTEGER
))
5757 if (!kind_value_check (x
, 0, 4))
5765 gfc_check_alarm_sub (gfc_expr
*seconds
, gfc_expr
*handler
, gfc_expr
*status
)
5767 if (!scalar_check (seconds
, 0))
5769 if (!type_check (seconds
, 0, BT_INTEGER
))
5772 if (!int_or_proc_check (handler
, 1))
5774 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
5780 if (!scalar_check (status
, 2))
5782 if (!type_check (status
, 2, BT_INTEGER
))
5784 if (!kind_value_check (status
, 2, gfc_default_integer_kind
))
5792 gfc_check_rand (gfc_expr
*x
)
5797 if (!scalar_check (x
, 0))
5800 if (!type_check (x
, 0, BT_INTEGER
))
5803 if (!kind_value_check (x
, 0, 4))
5811 gfc_check_srand (gfc_expr
*x
)
5813 if (!scalar_check (x
, 0))
5816 if (!type_check (x
, 0, BT_INTEGER
))
5819 if (!kind_value_check (x
, 0, 4))
5827 gfc_check_ctime_sub (gfc_expr
*time
, gfc_expr
*result
)
5829 if (!scalar_check (time
, 0))
5831 if (!type_check (time
, 0, BT_INTEGER
))
5834 if (!type_check (result
, 1, BT_CHARACTER
))
5836 if (!kind_value_check (result
, 1, gfc_default_character_kind
))
5844 gfc_check_dtime_etime (gfc_expr
*x
)
5846 if (!array_check (x
, 0))
5849 if (!rank_check (x
, 0, 1))
5852 if (!variable_check (x
, 0, false))
5855 if (!type_check (x
, 0, BT_REAL
))
5858 if (!kind_value_check (x
, 0, 4))
5866 gfc_check_dtime_etime_sub (gfc_expr
*values
, gfc_expr
*time
)
5868 if (!array_check (values
, 0))
5871 if (!rank_check (values
, 0, 1))
5874 if (!variable_check (values
, 0, false))
5877 if (!type_check (values
, 0, BT_REAL
))
5880 if (!kind_value_check (values
, 0, 4))
5883 if (!scalar_check (time
, 1))
5886 if (!type_check (time
, 1, BT_REAL
))
5889 if (!kind_value_check (time
, 1, 4))
5897 gfc_check_fdate_sub (gfc_expr
*date
)
5899 if (!type_check (date
, 0, BT_CHARACTER
))
5901 if (!kind_value_check (date
, 0, gfc_default_character_kind
))
5909 gfc_check_gerror (gfc_expr
*msg
)
5911 if (!type_check (msg
, 0, BT_CHARACTER
))
5913 if (!kind_value_check (msg
, 0, gfc_default_character_kind
))
5921 gfc_check_getcwd_sub (gfc_expr
*cwd
, gfc_expr
*status
)
5923 if (!type_check (cwd
, 0, BT_CHARACTER
))
5925 if (!kind_value_check (cwd
, 0, gfc_default_character_kind
))
5931 if (!scalar_check (status
, 1))
5934 if (!type_check (status
, 1, BT_INTEGER
))
5942 gfc_check_getarg (gfc_expr
*pos
, gfc_expr
*value
)
5944 if (!type_check (pos
, 0, BT_INTEGER
))
5947 if (pos
->ts
.kind
> gfc_default_integer_kind
)
5949 gfc_error ("%qs argument of %qs intrinsic at %L must be of a kind "
5950 "not wider than the default kind (%d)",
5951 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
5952 &pos
->where
, gfc_default_integer_kind
);
5956 if (!type_check (value
, 1, BT_CHARACTER
))
5958 if (!kind_value_check (value
, 1, gfc_default_character_kind
))
5966 gfc_check_getlog (gfc_expr
*msg
)
5968 if (!type_check (msg
, 0, BT_CHARACTER
))
5970 if (!kind_value_check (msg
, 0, gfc_default_character_kind
))
5978 gfc_check_exit (gfc_expr
*status
)
5983 if (!type_check (status
, 0, BT_INTEGER
))
5986 if (!scalar_check (status
, 0))
5994 gfc_check_flush (gfc_expr
*unit
)
5999 if (!type_check (unit
, 0, BT_INTEGER
))
6002 if (!scalar_check (unit
, 0))
6010 gfc_check_free (gfc_expr
*i
)
6012 if (!type_check (i
, 0, BT_INTEGER
))
6015 if (!scalar_check (i
, 0))
6023 gfc_check_hostnm (gfc_expr
*name
)
6025 if (!type_check (name
, 0, BT_CHARACTER
))
6027 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
6035 gfc_check_hostnm_sub (gfc_expr
*name
, gfc_expr
*status
)
6037 if (!type_check (name
, 0, BT_CHARACTER
))
6039 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
6045 if (!scalar_check (status
, 1))
6048 if (!type_check (status
, 1, BT_INTEGER
))
6056 gfc_check_itime_idate (gfc_expr
*values
)
6058 if (!array_check (values
, 0))
6061 if (!rank_check (values
, 0, 1))
6064 if (!variable_check (values
, 0, false))
6067 if (!type_check (values
, 0, BT_INTEGER
))
6070 if (!kind_value_check (values
, 0, gfc_default_integer_kind
))
6078 gfc_check_ltime_gmtime (gfc_expr
*time
, gfc_expr
*values
)
6080 if (!type_check (time
, 0, BT_INTEGER
))
6083 if (!kind_value_check (time
, 0, gfc_default_integer_kind
))
6086 if (!scalar_check (time
, 0))
6089 if (!array_check (values
, 1))
6092 if (!rank_check (values
, 1, 1))
6095 if (!variable_check (values
, 1, false))
6098 if (!type_check (values
, 1, BT_INTEGER
))
6101 if (!kind_value_check (values
, 1, gfc_default_integer_kind
))
6109 gfc_check_ttynam_sub (gfc_expr
*unit
, gfc_expr
*name
)
6111 if (!scalar_check (unit
, 0))
6114 if (!type_check (unit
, 0, BT_INTEGER
))
6117 if (!type_check (name
, 1, BT_CHARACTER
))
6119 if (!kind_value_check (name
, 1, gfc_default_character_kind
))
6127 gfc_check_isatty (gfc_expr
*unit
)
6132 if (!type_check (unit
, 0, BT_INTEGER
))
6135 if (!scalar_check (unit
, 0))
6143 gfc_check_isnan (gfc_expr
*x
)
6145 if (!type_check (x
, 0, BT_REAL
))
6153 gfc_check_perror (gfc_expr
*string
)
6155 if (!type_check (string
, 0, BT_CHARACTER
))
6157 if (!kind_value_check (string
, 0, gfc_default_character_kind
))
6165 gfc_check_umask (gfc_expr
*mask
)
6167 if (!type_check (mask
, 0, BT_INTEGER
))
6170 if (!scalar_check (mask
, 0))
6178 gfc_check_umask_sub (gfc_expr
*mask
, gfc_expr
*old
)
6180 if (!type_check (mask
, 0, BT_INTEGER
))
6183 if (!scalar_check (mask
, 0))
6189 if (!scalar_check (old
, 1))
6192 if (!type_check (old
, 1, BT_INTEGER
))
6200 gfc_check_unlink (gfc_expr
*name
)
6202 if (!type_check (name
, 0, BT_CHARACTER
))
6204 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
6212 gfc_check_unlink_sub (gfc_expr
*name
, gfc_expr
*status
)
6214 if (!type_check (name
, 0, BT_CHARACTER
))
6216 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
6222 if (!scalar_check (status
, 1))
6225 if (!type_check (status
, 1, BT_INTEGER
))
6233 gfc_check_signal (gfc_expr
*number
, gfc_expr
*handler
)
6235 if (!scalar_check (number
, 0))
6237 if (!type_check (number
, 0, BT_INTEGER
))
6240 if (!int_or_proc_check (handler
, 1))
6242 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
6250 gfc_check_signal_sub (gfc_expr
*number
, gfc_expr
*handler
, gfc_expr
*status
)
6252 if (!scalar_check (number
, 0))
6254 if (!type_check (number
, 0, BT_INTEGER
))
6257 if (!int_or_proc_check (handler
, 1))
6259 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
6265 if (!type_check (status
, 2, BT_INTEGER
))
6267 if (!scalar_check (status
, 2))
6275 gfc_check_system_sub (gfc_expr
*cmd
, gfc_expr
*status
)
6277 if (!type_check (cmd
, 0, BT_CHARACTER
))
6279 if (!kind_value_check (cmd
, 0, gfc_default_character_kind
))
6282 if (!scalar_check (status
, 1))
6285 if (!type_check (status
, 1, BT_INTEGER
))
6288 if (!kind_value_check (status
, 1, gfc_default_integer_kind
))
6295 /* This is used for the GNU intrinsics AND, OR and XOR. */
6297 gfc_check_and (gfc_expr
*i
, gfc_expr
*j
)
6299 if (i
->ts
.type
!= BT_INTEGER
&& i
->ts
.type
!= BT_LOGICAL
)
6301 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
6302 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
6303 gfc_current_intrinsic
, &i
->where
);
6307 if (j
->ts
.type
!= BT_INTEGER
&& j
->ts
.type
!= BT_LOGICAL
)
6309 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
6310 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
6311 gfc_current_intrinsic
, &j
->where
);
6315 if (i
->ts
.type
!= j
->ts
.type
)
6317 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
6318 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
6319 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
6324 if (!scalar_check (i
, 0))
6327 if (!scalar_check (j
, 1))
6335 gfc_check_storage_size (gfc_expr
*a
, gfc_expr
*kind
)
6338 if (a
->expr_type
== EXPR_NULL
)
6340 gfc_error ("Intrinsic function NULL at %L cannot be an actual "
6341 "argument to STORAGE_SIZE, because it returns a "
6342 "disassociated pointer", &a
->where
);
6346 if (a
->ts
.type
== BT_ASSUMED
)
6348 gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
6349 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
6354 if (a
->ts
.type
== BT_PROCEDURE
)
6356 gfc_error ("%qs argument of %qs intrinsic at %L shall not be a "
6357 "procedure", gfc_current_intrinsic_arg
[0]->name
,
6358 gfc_current_intrinsic
, &a
->where
);
6365 if (!type_check (kind
, 1, BT_INTEGER
))
6368 if (!scalar_check (kind
, 1))
6371 if (kind
->expr_type
!= EXPR_CONSTANT
)
6373 gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
6374 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,