2 Copyright (C) 2002-2018 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 /* Users sometime use a subroutine designator as an actual argument to
76 an intrinsic subprogram that expects an argument with a numeric type. */
77 if (e
->symtree
&& e
->symtree
->n
.sym
->attr
.subroutine
)
80 if (gfc_numeric_ts (&e
->ts
))
83 /* If the expression has not got a type, check if its namespace can
84 offer a default type. */
85 if ((e
->expr_type
== EXPR_VARIABLE
|| e
->expr_type
== EXPR_FUNCTION
)
86 && e
->symtree
->n
.sym
->ts
.type
== BT_UNKNOWN
87 && gfc_set_default_type (e
->symtree
->n
.sym
, 0, e
->symtree
->n
.sym
->ns
)
88 && gfc_numeric_ts (&e
->symtree
->n
.sym
->ts
))
90 e
->ts
= e
->symtree
->n
.sym
->ts
;
96 gfc_error ("%qs argument of %qs intrinsic at %L must have a numeric type",
97 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
104 /* Check that an expression is integer or real. */
107 int_or_real_check (gfc_expr
*e
, int n
)
109 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
)
111 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
112 "or REAL", gfc_current_intrinsic_arg
[n
]->name
,
113 gfc_current_intrinsic
, &e
->where
);
120 /* Check that an expression is integer or real; allow character for
124 int_or_real_or_char_check_f2003 (gfc_expr
*e
, int n
)
126 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
)
128 if (e
->ts
.type
== BT_CHARACTER
)
129 return gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: Character for "
130 "%qs argument of %qs intrinsic at %L",
131 gfc_current_intrinsic_arg
[n
]->name
,
132 gfc_current_intrinsic
, &e
->where
);
135 if (gfc_option
.allow_std
& GFC_STD_F2003
)
136 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
137 "or REAL or CHARACTER",
138 gfc_current_intrinsic_arg
[n
]->name
,
139 gfc_current_intrinsic
, &e
->where
);
141 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
142 "or REAL", gfc_current_intrinsic_arg
[n
]->name
,
143 gfc_current_intrinsic
, &e
->where
);
151 /* Check that an expression is an intrinsic type. */
153 intrinsic_type_check (gfc_expr
*e
, int n
)
155 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_REAL
156 && e
->ts
.type
!= BT_COMPLEX
&& e
->ts
.type
!= BT_CHARACTER
157 && e
->ts
.type
!= BT_LOGICAL
)
159 gfc_error ("%qs argument of %qs intrinsic at %L must be of intrinsic type",
160 gfc_current_intrinsic_arg
[n
]->name
,
161 gfc_current_intrinsic
, &e
->where
);
167 /* Check that an expression is real or complex. */
170 real_or_complex_check (gfc_expr
*e
, int n
)
172 if (e
->ts
.type
!= BT_REAL
&& e
->ts
.type
!= BT_COMPLEX
)
174 gfc_error ("%qs argument of %qs intrinsic at %L must be REAL "
175 "or COMPLEX", gfc_current_intrinsic_arg
[n
]->name
,
176 gfc_current_intrinsic
, &e
->where
);
184 /* Check that an expression is INTEGER or PROCEDURE. */
187 int_or_proc_check (gfc_expr
*e
, int n
)
189 if (e
->ts
.type
!= BT_INTEGER
&& e
->ts
.type
!= BT_PROCEDURE
)
191 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
192 "or PROCEDURE", gfc_current_intrinsic_arg
[n
]->name
,
193 gfc_current_intrinsic
, &e
->where
);
201 /* Check that the expression is an optional constant integer
202 and that it specifies a valid kind for that type. */
205 kind_check (gfc_expr
*k
, int n
, bt type
)
212 if (!type_check (k
, n
, BT_INTEGER
))
215 if (!scalar_check (k
, n
))
218 if (!gfc_check_init_expr (k
))
220 gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
221 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
226 if (gfc_extract_int (k
, &kind
)
227 || gfc_validate_kind (type
, kind
, true) < 0)
229 gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type
),
238 /* Make sure the expression is a double precision real. */
241 double_check (gfc_expr
*d
, int n
)
243 if (!type_check (d
, n
, BT_REAL
))
246 if (d
->ts
.kind
!= gfc_default_double_kind
)
248 gfc_error ("%qs argument of %qs intrinsic at %L must be double "
249 "precision", gfc_current_intrinsic_arg
[n
]->name
,
250 gfc_current_intrinsic
, &d
->where
);
259 coarray_check (gfc_expr
*e
, int n
)
261 if (e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
262 && CLASS_DATA (e
)->attr
.codimension
263 && CLASS_DATA (e
)->as
->corank
)
265 gfc_add_class_array_ref (e
);
269 if (!gfc_is_coarray (e
))
271 gfc_error ("Expected coarray variable as %qs argument to the %s "
272 "intrinsic at %L", gfc_current_intrinsic_arg
[n
]->name
,
273 gfc_current_intrinsic
, &e
->where
);
281 /* Make sure the expression is a logical array. */
284 logical_array_check (gfc_expr
*array
, int n
)
286 if (array
->ts
.type
!= BT_LOGICAL
|| array
->rank
== 0)
288 gfc_error ("%qs argument of %qs intrinsic at %L must be a logical "
289 "array", gfc_current_intrinsic_arg
[n
]->name
,
290 gfc_current_intrinsic
, &array
->where
);
298 /* Make sure an expression is an array. */
301 array_check (gfc_expr
*e
, int n
)
303 if (e
->ts
.type
== BT_CLASS
&& gfc_expr_attr (e
).class_ok
304 && CLASS_DATA (e
)->attr
.dimension
305 && CLASS_DATA (e
)->as
->rank
)
307 gfc_add_class_array_ref (e
);
311 if (e
->rank
!= 0 && e
->ts
.type
!= BT_PROCEDURE
)
314 gfc_error ("%qs argument of %qs intrinsic at %L must be an array",
315 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
322 /* If expr is a constant, then check to ensure that it is greater than
326 nonnegative_check (const char *arg
, gfc_expr
*expr
)
330 if (expr
->expr_type
== EXPR_CONSTANT
)
332 gfc_extract_int (expr
, &i
);
335 gfc_error ("%qs at %L must be nonnegative", arg
, &expr
->where
);
344 /* If expr is a constant, then check to ensure that it is greater than zero. */
347 positive_check (int n
, gfc_expr
*expr
)
351 if (expr
->expr_type
== EXPR_CONSTANT
)
353 gfc_extract_int (expr
, &i
);
356 gfc_error ("%qs argument of %qs intrinsic at %L must be positive",
357 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
367 /* If expr2 is constant, then check that the value is less than
368 (less than or equal to, if 'or_equal' is true) bit_size(expr1). */
371 less_than_bitsize1 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
372 gfc_expr
*expr2
, bool or_equal
)
376 if (expr2
->expr_type
== EXPR_CONSTANT
)
378 gfc_extract_int (expr2
, &i2
);
379 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
381 /* For ISHFT[C], check that |shift| <= bit_size(i). */
387 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
389 gfc_error ("The absolute value of SHIFT at %L must be less "
390 "than or equal to BIT_SIZE(%qs)",
391 &expr2
->where
, arg1
);
398 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
400 gfc_error ("%qs at %L must be less than "
401 "or equal to BIT_SIZE(%qs)",
402 arg2
, &expr2
->where
, arg1
);
408 if (i2
>= gfc_integer_kinds
[i3
].bit_size
)
410 gfc_error ("%qs at %L must be less than BIT_SIZE(%qs)",
411 arg2
, &expr2
->where
, arg1
);
421 /* If expr is constant, then check that the value is less than or equal
422 to the bit_size of the kind k. */
425 less_than_bitsizekind (const char *arg
, gfc_expr
*expr
, int k
)
429 if (expr
->expr_type
!= EXPR_CONSTANT
)
432 i
= gfc_validate_kind (BT_INTEGER
, k
, false);
433 gfc_extract_int (expr
, &val
);
435 if (val
> gfc_integer_kinds
[i
].bit_size
)
437 gfc_error ("%qs at %L must be less than or equal to the BIT_SIZE of "
438 "INTEGER(KIND=%d)", arg
, &expr
->where
, k
);
446 /* If expr2 and expr3 are constants, then check that the value is less than
447 or equal to bit_size(expr1). */
450 less_than_bitsize2 (const char *arg1
, gfc_expr
*expr1
, const char *arg2
,
451 gfc_expr
*expr2
, const char *arg3
, gfc_expr
*expr3
)
455 if (expr2
->expr_type
== EXPR_CONSTANT
&& expr3
->expr_type
== EXPR_CONSTANT
)
457 gfc_extract_int (expr2
, &i2
);
458 gfc_extract_int (expr3
, &i3
);
460 i3
= gfc_validate_kind (BT_INTEGER
, expr1
->ts
.kind
, false);
461 if (i2
> gfc_integer_kinds
[i3
].bit_size
)
463 gfc_error ("%<%s + %s%> at %L must be less than or equal "
465 arg2
, arg3
, &expr2
->where
, arg1
);
473 /* Make sure two expressions have the same type. */
476 same_type_check (gfc_expr
*e
, int n
, gfc_expr
*f
, int m
, bool assoc
= false)
478 gfc_typespec
*ets
= &e
->ts
;
479 gfc_typespec
*fts
= &f
->ts
;
483 /* Procedure pointer component expressions have the type of the interface
484 procedure. If they are being tested for association with a procedure
485 pointer (ie. not a component), the type of the procedure must be
487 if (e
->ts
.type
== BT_PROCEDURE
&& e
->symtree
->n
.sym
)
488 ets
= &e
->symtree
->n
.sym
->ts
;
489 if (f
->ts
.type
== BT_PROCEDURE
&& f
->symtree
->n
.sym
)
490 fts
= &f
->symtree
->n
.sym
->ts
;
493 if (gfc_compare_types (ets
, fts
))
496 gfc_error ("%qs argument of %qs intrinsic at %L must be the same type "
497 "and kind as %qs", gfc_current_intrinsic_arg
[m
]->name
,
498 gfc_current_intrinsic
, &f
->where
,
499 gfc_current_intrinsic_arg
[n
]->name
);
505 /* Make sure that an expression has a certain (nonzero) rank. */
508 rank_check (gfc_expr
*e
, int n
, int rank
)
513 gfc_error ("%qs argument of %qs intrinsic at %L must be of rank %d",
514 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
521 /* Make sure a variable expression is not an optional dummy argument. */
524 nonoptional_check (gfc_expr
*e
, int n
)
526 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.optional
)
528 gfc_error ("%qs argument of %qs intrinsic at %L must not be OPTIONAL",
529 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
533 /* TODO: Recursive check on nonoptional variables? */
539 /* Check for ALLOCATABLE attribute. */
542 allocatable_check (gfc_expr
*e
, int n
)
544 symbol_attribute attr
;
546 attr
= gfc_variable_attr (e
, NULL
);
547 if (!attr
.allocatable
|| attr
.associate_var
)
549 gfc_error ("%qs argument of %qs intrinsic at %L must be ALLOCATABLE",
550 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
559 /* Check that an expression has a particular kind. */
562 kind_value_check (gfc_expr
*e
, int n
, int k
)
567 gfc_error ("%qs argument of %qs intrinsic at %L must be of kind %d",
568 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
,
575 /* Make sure an expression is a variable. */
578 variable_check (gfc_expr
*e
, int n
, bool allow_proc
)
580 if (e
->expr_type
== EXPR_VARIABLE
581 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
582 && (gfc_current_intrinsic_arg
[n
]->intent
== INTENT_OUT
583 || gfc_current_intrinsic_arg
[n
]->intent
== INTENT_INOUT
))
586 bool pointer
= e
->symtree
->n
.sym
->ts
.type
== BT_CLASS
587 && CLASS_DATA (e
->symtree
->n
.sym
)
588 ? CLASS_DATA (e
->symtree
->n
.sym
)->attr
.class_pointer
589 : e
->symtree
->n
.sym
->attr
.pointer
;
591 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
593 if (pointer
&& ref
->type
== REF_COMPONENT
)
595 if (ref
->type
== REF_COMPONENT
596 && ((ref
->u
.c
.component
->ts
.type
== BT_CLASS
597 && CLASS_DATA (ref
->u
.c
.component
)->attr
.class_pointer
)
598 || (ref
->u
.c
.component
->ts
.type
!= BT_CLASS
599 && ref
->u
.c
.component
->attr
.pointer
)))
605 gfc_error ("%qs argument of %qs intrinsic at %L cannot be "
606 "INTENT(IN)", gfc_current_intrinsic_arg
[n
]->name
,
607 gfc_current_intrinsic
, &e
->where
);
612 if (e
->expr_type
== EXPR_VARIABLE
613 && e
->symtree
->n
.sym
->attr
.flavor
!= FL_PARAMETER
614 && (allow_proc
|| !e
->symtree
->n
.sym
->attr
.function
))
617 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
->attr
.function
618 && e
->symtree
->n
.sym
== e
->symtree
->n
.sym
->result
)
621 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
622 if (ns
->proc_name
== e
->symtree
->n
.sym
)
626 gfc_error ("%qs argument of %qs intrinsic at %L must be a variable",
627 gfc_current_intrinsic_arg
[n
]->name
, gfc_current_intrinsic
, &e
->where
);
633 /* Check the common DIM parameter for correctness. */
636 dim_check (gfc_expr
*dim
, int n
, bool optional
)
641 if (!type_check (dim
, n
, BT_INTEGER
))
644 if (!scalar_check (dim
, n
))
647 if (!optional
&& !nonoptional_check (dim
, n
))
654 /* If a coarray DIM parameter is a constant, make sure that it is greater than
655 zero and less than or equal to the corank of the given array. */
658 dim_corank_check (gfc_expr
*dim
, gfc_expr
*array
)
662 gcc_assert (array
->expr_type
== EXPR_VARIABLE
);
664 if (dim
->expr_type
!= EXPR_CONSTANT
)
667 if (array
->ts
.type
== BT_CLASS
)
670 corank
= gfc_get_corank (array
);
672 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
673 || mpz_cmp_ui (dim
->value
.integer
, corank
) > 0)
675 gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
676 "codimension index", gfc_current_intrinsic
, &dim
->where
);
685 /* If a DIM parameter is a constant, make sure that it is greater than
686 zero and less than or equal to the rank of the given array. If
687 allow_assumed is zero then dim must be less than the rank of the array
688 for assumed size arrays. */
691 dim_rank_check (gfc_expr
*dim
, gfc_expr
*array
, int allow_assumed
)
699 if (dim
->expr_type
!= EXPR_CONSTANT
)
702 if (array
->expr_type
== EXPR_FUNCTION
&& array
->value
.function
.isym
703 && array
->value
.function
.isym
->id
== GFC_ISYM_SPREAD
)
704 rank
= array
->rank
+ 1;
708 /* Assumed-rank array. */
710 rank
= GFC_MAX_DIMENSIONS
;
712 if (array
->expr_type
== EXPR_VARIABLE
)
714 ar
= gfc_find_array_ref (array
);
715 if (ar
->as
->type
== AS_ASSUMED_SIZE
717 && ar
->type
!= AR_ELEMENT
718 && ar
->type
!= AR_SECTION
)
722 if (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
723 || mpz_cmp_ui (dim
->value
.integer
, rank
) > 0)
725 gfc_error ("%<dim%> argument of %qs intrinsic at %L is not a valid "
726 "dimension index", gfc_current_intrinsic
, &dim
->where
);
735 /* Compare the size of a along dimension ai with the size of b along
736 dimension bi, returning 0 if they are known not to be identical,
737 and 1 if they are identical, or if this cannot be determined. */
740 identical_dimen_shape (gfc_expr
*a
, int ai
, gfc_expr
*b
, int bi
)
742 mpz_t a_size
, b_size
;
745 gcc_assert (a
->rank
> ai
);
746 gcc_assert (b
->rank
> bi
);
750 if (gfc_array_dimen_size (a
, ai
, &a_size
))
752 if (gfc_array_dimen_size (b
, bi
, &b_size
))
754 if (mpz_cmp (a_size
, b_size
) != 0)
764 /* Calculate the length of a character variable, including substrings.
765 Strip away parentheses if necessary. Return -1 if no length could
769 gfc_var_strlen (const gfc_expr
*a
)
773 while (a
->expr_type
== EXPR_OP
&& a
->value
.op
.op
== INTRINSIC_PARENTHESES
)
776 for (ra
= a
->ref
; ra
!= NULL
&& ra
->type
!= REF_SUBSTRING
; ra
= ra
->next
)
786 if ((!ra
->u
.ss
.start
|| ra
->u
.ss
.start
->expr_type
== EXPR_CONSTANT
)
787 && ra
->u
.ss
.end
->expr_type
== EXPR_CONSTANT
)
789 start_a
= ra
->u
.ss
.start
? mpz_get_si (ra
->u
.ss
.start
->value
.integer
)
791 end_a
= mpz_get_si (ra
->u
.ss
.end
->value
.integer
);
792 return (end_a
< start_a
) ? 0 : end_a
- start_a
+ 1;
794 else if (ra
->u
.ss
.start
795 && gfc_dep_compare_expr (ra
->u
.ss
.start
, ra
->u
.ss
.end
) == 0)
801 if (a
->ts
.u
.cl
&& a
->ts
.u
.cl
->length
802 && a
->ts
.u
.cl
->length
->expr_type
== EXPR_CONSTANT
)
803 return mpz_get_si (a
->ts
.u
.cl
->length
->value
.integer
);
804 else if (a
->expr_type
== EXPR_CONSTANT
805 && (a
->ts
.u
.cl
== NULL
|| a
->ts
.u
.cl
->length
== NULL
))
806 return a
->value
.character
.length
;
812 /* Check whether two character expressions have the same length;
813 returns true if they have or if the length cannot be determined,
814 otherwise return false and raise a gfc_error. */
817 gfc_check_same_strlen (const gfc_expr
*a
, const gfc_expr
*b
, const char *name
)
821 len_a
= gfc_var_strlen(a
);
822 len_b
= gfc_var_strlen(b
);
824 if (len_a
== -1 || len_b
== -1 || len_a
== len_b
)
828 gfc_error ("Unequal character lengths (%ld/%ld) in %s at %L",
829 len_a
, len_b
, name
, &a
->where
);
835 /***** Check functions *****/
837 /* Check subroutine suitable for intrinsics taking a real argument and
838 a kind argument for the result. */
841 check_a_kind (gfc_expr
*a
, gfc_expr
*kind
, bt type
)
843 if (!type_check (a
, 0, BT_REAL
))
845 if (!kind_check (kind
, 1, type
))
852 /* Check subroutine suitable for ceiling, floor and nint. */
855 gfc_check_a_ikind (gfc_expr
*a
, gfc_expr
*kind
)
857 return check_a_kind (a
, kind
, BT_INTEGER
);
861 /* Check subroutine suitable for aint, anint. */
864 gfc_check_a_xkind (gfc_expr
*a
, gfc_expr
*kind
)
866 return check_a_kind (a
, kind
, BT_REAL
);
871 gfc_check_abs (gfc_expr
*a
)
873 if (!numeric_check (a
, 0))
881 gfc_check_achar (gfc_expr
*a
, gfc_expr
*kind
)
883 if (!type_check (a
, 0, BT_INTEGER
))
885 if (!kind_check (kind
, 1, BT_CHARACTER
))
893 gfc_check_access_func (gfc_expr
*name
, gfc_expr
*mode
)
895 if (!type_check (name
, 0, BT_CHARACTER
)
896 || !scalar_check (name
, 0))
898 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
901 if (!type_check (mode
, 1, BT_CHARACTER
)
902 || !scalar_check (mode
, 1))
904 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
912 gfc_check_all_any (gfc_expr
*mask
, gfc_expr
*dim
)
914 if (!logical_array_check (mask
, 0))
917 if (!dim_check (dim
, 1, false))
920 if (!dim_rank_check (dim
, mask
, 0))
928 gfc_check_allocated (gfc_expr
*array
)
930 /* Tests on allocated components of coarrays need to detour the check to
931 argument of the _caf_get. */
932 if (flag_coarray
== GFC_FCOARRAY_LIB
&& array
->expr_type
== EXPR_FUNCTION
933 && array
->value
.function
.isym
934 && array
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
936 array
= array
->value
.function
.actual
->expr
;
941 if (!variable_check (array
, 0, false))
943 if (!allocatable_check (array
, 0))
950 /* Common check function where the first argument must be real or
951 integer and the second argument must be the same as the first. */
954 gfc_check_a_p (gfc_expr
*a
, gfc_expr
*p
)
956 if (!int_or_real_check (a
, 0))
959 if (a
->ts
.type
!= p
->ts
.type
)
961 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
962 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
963 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
968 if (a
->ts
.kind
!= p
->ts
.kind
)
970 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
980 gfc_check_x_yd (gfc_expr
*x
, gfc_expr
*y
)
982 if (!double_check (x
, 0) || !double_check (y
, 1))
990 gfc_check_associated (gfc_expr
*pointer
, gfc_expr
*target
)
992 symbol_attribute attr1
, attr2
;
997 where
= &pointer
->where
;
999 if (pointer
->expr_type
== EXPR_NULL
)
1002 attr1
= gfc_expr_attr (pointer
);
1004 if (!attr1
.pointer
&& !attr1
.proc_pointer
)
1006 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER",
1007 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
1013 if (attr1
.pointer
&& gfc_is_coindexed (pointer
))
1015 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
1016 "coindexed", gfc_current_intrinsic_arg
[0]->name
,
1017 gfc_current_intrinsic
, &pointer
->where
);
1021 /* Target argument is optional. */
1025 where
= &target
->where
;
1026 if (target
->expr_type
== EXPR_NULL
)
1029 if (target
->expr_type
== EXPR_VARIABLE
|| target
->expr_type
== EXPR_FUNCTION
)
1030 attr2
= gfc_expr_attr (target
);
1033 gfc_error ("%qs argument of %qs intrinsic at %L must be a pointer "
1034 "or target VARIABLE or FUNCTION",
1035 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1040 if (attr1
.pointer
&& !attr2
.pointer
&& !attr2
.target
)
1042 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER "
1043 "or a TARGET", gfc_current_intrinsic_arg
[1]->name
,
1044 gfc_current_intrinsic
, &target
->where
);
1049 if (attr1
.pointer
&& gfc_is_coindexed (target
))
1051 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
1052 "coindexed", gfc_current_intrinsic_arg
[1]->name
,
1053 gfc_current_intrinsic
, &target
->where
);
1058 if (!same_type_check (pointer
, 0, target
, 1, true))
1060 if (!rank_check (target
, 0, pointer
->rank
))
1062 if (target
->rank
> 0)
1064 for (i
= 0; i
< target
->rank
; i
++)
1065 if (target
->ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
1067 gfc_error ("Array section with a vector subscript at %L shall not "
1068 "be the target of a pointer",
1078 gfc_error ("NULL pointer at %L is not permitted as actual argument "
1079 "of %qs intrinsic function", where
, gfc_current_intrinsic
);
1086 gfc_check_atan_2 (gfc_expr
*y
, gfc_expr
*x
)
1088 /* gfc_notify_std would be a waste of time as the return value
1089 is seemingly used only for the generic resolution. The error
1090 will be: Too many arguments. */
1091 if ((gfc_option
.allow_std
& GFC_STD_F2008
) == 0)
1094 return gfc_check_atan2 (y
, x
);
1099 gfc_check_atan2 (gfc_expr
*y
, gfc_expr
*x
)
1101 if (!type_check (y
, 0, BT_REAL
))
1103 if (!same_type_check (y
, 0, x
, 1))
1111 gfc_check_atomic (gfc_expr
*atom
, int atom_no
, gfc_expr
*value
, int val_no
,
1112 gfc_expr
*stat
, int stat_no
)
1114 if (!scalar_check (atom
, atom_no
) || !scalar_check (value
, val_no
))
1117 if (!(atom
->ts
.type
== BT_INTEGER
&& atom
->ts
.kind
== gfc_atomic_int_kind
)
1118 && !(atom
->ts
.type
== BT_LOGICAL
1119 && atom
->ts
.kind
== gfc_atomic_logical_kind
))
1121 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1122 "integer of ATOMIC_INT_KIND or a logical of "
1123 "ATOMIC_LOGICAL_KIND", &atom
->where
, gfc_current_intrinsic
);
1127 if (!gfc_is_coarray (atom
) && !gfc_is_coindexed (atom
))
1129 gfc_error ("ATOM argument at %L of the %s intrinsic function shall be a "
1130 "coarray or coindexed", &atom
->where
, gfc_current_intrinsic
);
1134 if (atom
->ts
.type
!= value
->ts
.type
)
1136 gfc_error ("%qs argument of %qs intrinsic at %L shall have the same "
1137 "type as %qs at %L", gfc_current_intrinsic_arg
[val_no
]->name
,
1138 gfc_current_intrinsic
, &value
->where
,
1139 gfc_current_intrinsic_arg
[atom_no
]->name
, &atom
->where
);
1145 if (!type_check (stat
, stat_no
, BT_INTEGER
))
1147 if (!scalar_check (stat
, stat_no
))
1149 if (!variable_check (stat
, stat_no
, false))
1151 if (!kind_value_check (stat
, stat_no
, gfc_default_integer_kind
))
1154 if (!gfc_notify_std (GFC_STD_F2018
, "STAT= argument to %s at %L",
1155 gfc_current_intrinsic
, &stat
->where
))
1164 gfc_check_atomic_def (gfc_expr
*atom
, gfc_expr
*value
, gfc_expr
*stat
)
1166 if (atom
->expr_type
== EXPR_FUNCTION
1167 && atom
->value
.function
.isym
1168 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1169 atom
= atom
->value
.function
.actual
->expr
;
1171 if (!gfc_check_vardef_context (atom
, false, false, false, NULL
))
1173 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1174 "definable", gfc_current_intrinsic
, &atom
->where
);
1178 return gfc_check_atomic (atom
, 0, value
, 1, stat
, 2);
1183 gfc_check_atomic_op (gfc_expr
*atom
, gfc_expr
*value
, gfc_expr
*stat
)
1185 if (atom
->ts
.type
!= BT_INTEGER
|| atom
->ts
.kind
!= gfc_atomic_int_kind
)
1187 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1188 "integer of ATOMIC_INT_KIND", &atom
->where
,
1189 gfc_current_intrinsic
);
1193 return gfc_check_atomic_def (atom
, value
, stat
);
1198 gfc_check_atomic_ref (gfc_expr
*value
, gfc_expr
*atom
, gfc_expr
*stat
)
1200 if (atom
->expr_type
== EXPR_FUNCTION
1201 && atom
->value
.function
.isym
1202 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1203 atom
= atom
->value
.function
.actual
->expr
;
1205 if (!gfc_check_vardef_context (value
, false, false, false, NULL
))
1207 gfc_error ("VALUE argument of the %s intrinsic function at %L shall be "
1208 "definable", gfc_current_intrinsic
, &value
->where
);
1212 return gfc_check_atomic (atom
, 1, value
, 0, stat
, 2);
1217 gfc_check_image_status (gfc_expr
*image
, gfc_expr
*team
)
1219 /* IMAGE has to be a positive, scalar integer. */
1220 if (!type_check (image
, 0, BT_INTEGER
) || !scalar_check (image
, 0)
1221 || !positive_check (0, image
))
1226 gfc_error ("%qs argument of %qs intrinsic at %L not yet supported",
1227 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1236 gfc_check_failed_or_stopped_images (gfc_expr
*team
, gfc_expr
*kind
)
1240 gfc_error ("%qs argument of %qs intrinsic at %L not yet supported",
1241 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
1250 if (!type_check (kind
, 1, BT_INTEGER
) || !scalar_check (kind
, 1)
1251 || !positive_check (1, kind
))
1254 /* Get the kind, reporting error on non-constant or overflow. */
1255 gfc_current_locus
= kind
->where
;
1256 if (gfc_extract_int (kind
, &k
, 1))
1258 if (gfc_validate_kind (BT_INTEGER
, k
, true) == -1)
1260 gfc_error ("%qs argument of %qs intrinsic at %L shall specify a "
1261 "valid integer kind", gfc_current_intrinsic_arg
[1]->name
,
1262 gfc_current_intrinsic
, &kind
->where
);
1271 gfc_check_get_team (gfc_expr
*level
)
1275 gfc_error ("%qs argument of %qs intrinsic at %L not yet supported",
1276 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
1285 gfc_check_atomic_cas (gfc_expr
*atom
, gfc_expr
*old
, gfc_expr
*compare
,
1286 gfc_expr
*new_val
, gfc_expr
*stat
)
1288 if (atom
->expr_type
== EXPR_FUNCTION
1289 && atom
->value
.function
.isym
1290 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1291 atom
= atom
->value
.function
.actual
->expr
;
1293 if (!gfc_check_atomic (atom
, 0, new_val
, 3, stat
, 4))
1296 if (!scalar_check (old
, 1) || !scalar_check (compare
, 2))
1299 if (!same_type_check (atom
, 0, old
, 1))
1302 if (!same_type_check (atom
, 0, compare
, 2))
1305 if (!gfc_check_vardef_context (atom
, false, false, false, NULL
))
1307 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1308 "definable", gfc_current_intrinsic
, &atom
->where
);
1312 if (!gfc_check_vardef_context (old
, false, false, false, NULL
))
1314 gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1315 "definable", gfc_current_intrinsic
, &old
->where
);
1323 gfc_check_event_query (gfc_expr
*event
, gfc_expr
*count
, gfc_expr
*stat
)
1325 if (event
->ts
.type
!= BT_DERIVED
1326 || event
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
1327 || event
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_EVENT_TYPE
)
1329 gfc_error ("EVENT argument at %L to the intrinsic EVENT_QUERY "
1330 "shall be of type EVENT_TYPE", &event
->where
);
1334 if (!scalar_check (event
, 0))
1337 if (!gfc_check_vardef_context (count
, false, false, false, NULL
))
1339 gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1340 "shall be definable", &count
->where
);
1344 if (!type_check (count
, 1, BT_INTEGER
))
1347 int i
= gfc_validate_kind (BT_INTEGER
, count
->ts
.kind
, false);
1348 int j
= gfc_validate_kind (BT_INTEGER
, gfc_default_integer_kind
, false);
1350 if (gfc_integer_kinds
[i
].range
< gfc_integer_kinds
[j
].range
)
1352 gfc_error ("COUNT argument of the EVENT_QUERY intrinsic function at %L "
1353 "shall have at least the range of the default integer",
1360 if (!type_check (stat
, 2, BT_INTEGER
))
1362 if (!scalar_check (stat
, 2))
1364 if (!variable_check (stat
, 2, false))
1367 if (!gfc_notify_std (GFC_STD_F2018
, "STAT= argument to %s at %L",
1368 gfc_current_intrinsic
, &stat
->where
))
1377 gfc_check_atomic_fetch_op (gfc_expr
*atom
, gfc_expr
*value
, gfc_expr
*old
,
1380 if (atom
->expr_type
== EXPR_FUNCTION
1381 && atom
->value
.function
.isym
1382 && atom
->value
.function
.isym
->id
== GFC_ISYM_CAF_GET
)
1383 atom
= atom
->value
.function
.actual
->expr
;
1385 if (atom
->ts
.type
!= BT_INTEGER
|| atom
->ts
.kind
!= gfc_atomic_int_kind
)
1387 gfc_error ("ATOM argument at %L to intrinsic function %s shall be an "
1388 "integer of ATOMIC_INT_KIND", &atom
->where
,
1389 gfc_current_intrinsic
);
1393 if (!gfc_check_atomic (atom
, 0, value
, 1, stat
, 3))
1396 if (!scalar_check (old
, 2))
1399 if (!same_type_check (atom
, 0, old
, 2))
1402 if (!gfc_check_vardef_context (atom
, false, false, false, NULL
))
1404 gfc_error ("ATOM argument of the %s intrinsic function at %L shall be "
1405 "definable", gfc_current_intrinsic
, &atom
->where
);
1409 if (!gfc_check_vardef_context (old
, false, false, false, NULL
))
1411 gfc_error ("OLD argument of the %s intrinsic function at %L shall be "
1412 "definable", gfc_current_intrinsic
, &old
->where
);
1420 /* BESJN and BESYN functions. */
1423 gfc_check_besn (gfc_expr
*n
, gfc_expr
*x
)
1425 if (!type_check (n
, 0, BT_INTEGER
))
1427 if (n
->expr_type
== EXPR_CONSTANT
)
1430 gfc_extract_int (n
, &i
);
1431 if (i
< 0 && !gfc_notify_std (GFC_STD_GNU
, "Negative argument "
1432 "N at %L", &n
->where
))
1436 if (!type_check (x
, 1, BT_REAL
))
1443 /* Transformational version of the Bessel JN and YN functions. */
1446 gfc_check_bessel_n2 (gfc_expr
*n1
, gfc_expr
*n2
, gfc_expr
*x
)
1448 if (!type_check (n1
, 0, BT_INTEGER
))
1450 if (!scalar_check (n1
, 0))
1452 if (!nonnegative_check ("N1", n1
))
1455 if (!type_check (n2
, 1, BT_INTEGER
))
1457 if (!scalar_check (n2
, 1))
1459 if (!nonnegative_check ("N2", n2
))
1462 if (!type_check (x
, 2, BT_REAL
))
1464 if (!scalar_check (x
, 2))
1472 gfc_check_bge_bgt_ble_blt (gfc_expr
*i
, gfc_expr
*j
)
1474 if (!type_check (i
, 0, BT_INTEGER
))
1477 if (!type_check (j
, 1, BT_INTEGER
))
1485 gfc_check_bitfcn (gfc_expr
*i
, gfc_expr
*pos
)
1487 if (!type_check (i
, 0, BT_INTEGER
))
1490 if (!type_check (pos
, 1, BT_INTEGER
))
1493 if (!nonnegative_check ("pos", pos
))
1496 if (!less_than_bitsize1 ("i", i
, "pos", pos
, false))
1504 gfc_check_char (gfc_expr
*i
, gfc_expr
*kind
)
1506 if (!type_check (i
, 0, BT_INTEGER
))
1508 if (!kind_check (kind
, 1, BT_CHARACTER
))
1516 gfc_check_chdir (gfc_expr
*dir
)
1518 if (!type_check (dir
, 0, BT_CHARACTER
))
1520 if (!kind_value_check (dir
, 0, gfc_default_character_kind
))
1528 gfc_check_chdir_sub (gfc_expr
*dir
, gfc_expr
*status
)
1530 if (!type_check (dir
, 0, BT_CHARACTER
))
1532 if (!kind_value_check (dir
, 0, gfc_default_character_kind
))
1538 if (!type_check (status
, 1, BT_INTEGER
))
1540 if (!scalar_check (status
, 1))
1548 gfc_check_chmod (gfc_expr
*name
, gfc_expr
*mode
)
1550 if (!type_check (name
, 0, BT_CHARACTER
))
1552 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
1555 if (!type_check (mode
, 1, BT_CHARACTER
))
1557 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
1565 gfc_check_chmod_sub (gfc_expr
*name
, gfc_expr
*mode
, gfc_expr
*status
)
1567 if (!type_check (name
, 0, BT_CHARACTER
))
1569 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
1572 if (!type_check (mode
, 1, BT_CHARACTER
))
1574 if (!kind_value_check (mode
, 1, gfc_default_character_kind
))
1580 if (!type_check (status
, 2, BT_INTEGER
))
1583 if (!scalar_check (status
, 2))
1591 gfc_check_cmplx (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*kind
)
1593 if (!numeric_check (x
, 0))
1598 if (!numeric_check (y
, 1))
1601 if (x
->ts
.type
== BT_COMPLEX
)
1603 gfc_error ("%qs argument of %qs intrinsic at %L must not be "
1604 "present if %<x%> is COMPLEX",
1605 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1610 if (y
->ts
.type
== BT_COMPLEX
)
1612 gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
1613 "of either REAL or INTEGER",
1614 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
1621 if (!kind_check (kind
, 2, BT_COMPLEX
))
1624 if (!kind
&& warn_conversion
1625 && x
->ts
.type
== BT_REAL
&& x
->ts
.kind
> gfc_default_real_kind
)
1626 gfc_warning_now (OPT_Wconversion
, "Conversion from %s to default-kind "
1627 "COMPLEX(%d) at %L might lose precision, consider using "
1628 "the KIND argument", gfc_typename (&x
->ts
),
1629 gfc_default_real_kind
, &x
->where
);
1630 else if (y
&& !kind
&& warn_conversion
1631 && y
->ts
.type
== BT_REAL
&& y
->ts
.kind
> gfc_default_real_kind
)
1632 gfc_warning_now (OPT_Wconversion
, "Conversion from %s to default-kind "
1633 "COMPLEX(%d) at %L might lose precision, consider using "
1634 "the KIND argument", gfc_typename (&y
->ts
),
1635 gfc_default_real_kind
, &y
->where
);
1641 check_co_collective (gfc_expr
*a
, gfc_expr
*image_idx
, gfc_expr
*stat
,
1642 gfc_expr
*errmsg
, bool co_reduce
)
1644 if (!variable_check (a
, 0, false))
1647 if (!gfc_check_vardef_context (a
, false, false, false, "argument 'A' with "
1651 /* Fortran 2008, 12.5.2.4, paragraph 18. */
1652 if (gfc_has_vector_subscript (a
))
1654 gfc_error ("Argument %<A%> with INTENT(INOUT) at %L of the intrinsic "
1655 "subroutine %s shall not have a vector subscript",
1656 &a
->where
, gfc_current_intrinsic
);
1660 if (gfc_is_coindexed (a
))
1662 gfc_error ("The A argument at %L to the intrinsic %s shall not be "
1663 "coindexed", &a
->where
, gfc_current_intrinsic
);
1667 if (image_idx
!= NULL
)
1669 if (!type_check (image_idx
, co_reduce
? 2 : 1, BT_INTEGER
))
1671 if (!scalar_check (image_idx
, co_reduce
? 2 : 1))
1677 if (!type_check (stat
, co_reduce
? 3 : 2, BT_INTEGER
))
1679 if (!scalar_check (stat
, co_reduce
? 3 : 2))
1681 if (!variable_check (stat
, co_reduce
? 3 : 2, false))
1683 if (stat
->ts
.kind
!= 4)
1685 gfc_error ("The stat= argument at %L must be a kind=4 integer "
1686 "variable", &stat
->where
);
1693 if (!type_check (errmsg
, co_reduce
? 4 : 3, BT_CHARACTER
))
1695 if (!scalar_check (errmsg
, co_reduce
? 4 : 3))
1697 if (!variable_check (errmsg
, co_reduce
? 4 : 3, false))
1699 if (errmsg
->ts
.kind
!= 1)
1701 gfc_error ("The errmsg= argument at %L must be a default-kind "
1702 "character variable", &errmsg
->where
);
1707 if (flag_coarray
== GFC_FCOARRAY_NONE
)
1709 gfc_fatal_error ("Coarrays disabled at %L, use %<-fcoarray=%> to enable",
1719 gfc_check_co_broadcast (gfc_expr
*a
, gfc_expr
*source_image
, gfc_expr
*stat
,
1722 if (a
->ts
.type
== BT_CLASS
|| gfc_expr_attr (a
).alloc_comp
)
1724 gfc_error ("Support for the A argument at %L which is polymorphic A "
1725 "argument or has allocatable components is not yet "
1726 "implemented", &a
->where
);
1729 return check_co_collective (a
, source_image
, stat
, errmsg
, false);
1734 gfc_check_co_reduce (gfc_expr
*a
, gfc_expr
*op
, gfc_expr
*result_image
,
1735 gfc_expr
*stat
, gfc_expr
*errmsg
)
1737 symbol_attribute attr
;
1738 gfc_formal_arglist
*formal
;
1741 if (a
->ts
.type
== BT_CLASS
)
1743 gfc_error ("The A argument at %L of CO_REDUCE shall not be polymorphic",
1748 if (gfc_expr_attr (a
).alloc_comp
)
1750 gfc_error ("Support for the A argument at %L with allocatable components"
1751 " is not yet implemented", &a
->where
);
1755 if (!check_co_collective (a
, result_image
, stat
, errmsg
, true))
1758 if (!gfc_resolve_expr (op
))
1761 attr
= gfc_expr_attr (op
);
1762 if (!attr
.pure
|| !attr
.function
)
1764 gfc_error ("OPERATOR argument at %L must be a PURE function",
1771 /* None of the intrinsics fulfills the criteria of taking two arguments,
1772 returning the same type and kind as the arguments and being permitted
1773 as actual argument. */
1774 gfc_error ("Intrinsic function %s at %L is not permitted for CO_REDUCE",
1775 op
->symtree
->n
.sym
->name
, &op
->where
);
1779 if (gfc_is_proc_ptr_comp (op
))
1781 gfc_component
*comp
= gfc_get_proc_ptr_comp (op
);
1782 sym
= comp
->ts
.interface
;
1785 sym
= op
->symtree
->n
.sym
;
1787 formal
= sym
->formal
;
1789 if (!formal
|| !formal
->next
|| formal
->next
->next
)
1791 gfc_error ("The function passed as OPERATOR at %L shall have two "
1792 "arguments", &op
->where
);
1796 if (sym
->result
->ts
.type
== BT_UNKNOWN
)
1797 gfc_set_default_type (sym
->result
, 0, NULL
);
1799 if (!gfc_compare_types (&a
->ts
, &sym
->result
->ts
))
1801 gfc_error ("The A argument at %L has type %s but the function passed as "
1802 "OPERATOR at %L returns %s",
1803 &a
->where
, gfc_typename (&a
->ts
), &op
->where
,
1804 gfc_typename (&sym
->result
->ts
));
1807 if (!gfc_compare_types (&a
->ts
, &formal
->sym
->ts
)
1808 || !gfc_compare_types (&a
->ts
, &formal
->next
->sym
->ts
))
1810 gfc_error ("The function passed as OPERATOR at %L has arguments of type "
1811 "%s and %s but shall have type %s", &op
->where
,
1812 gfc_typename (&formal
->sym
->ts
),
1813 gfc_typename (&formal
->next
->sym
->ts
), gfc_typename (&a
->ts
));
1816 if (op
->rank
|| attr
.allocatable
|| attr
.pointer
|| formal
->sym
->as
1817 || formal
->next
->sym
->as
|| formal
->sym
->attr
.allocatable
1818 || formal
->next
->sym
->attr
.allocatable
|| formal
->sym
->attr
.pointer
1819 || formal
->next
->sym
->attr
.pointer
)
1821 gfc_error ("The function passed as OPERATOR at %L shall have scalar "
1822 "nonallocatable nonpointer arguments and return a "
1823 "nonallocatable nonpointer scalar", &op
->where
);
1827 if (formal
->sym
->attr
.value
!= formal
->next
->sym
->attr
.value
)
1829 gfc_error ("The function passed as OPERATOR at %L shall have the VALUE "
1830 "attribute either for none or both arguments", &op
->where
);
1834 if (formal
->sym
->attr
.target
!= formal
->next
->sym
->attr
.target
)
1836 gfc_error ("The function passed as OPERATOR at %L shall have the TARGET "
1837 "attribute either for none or both arguments", &op
->where
);
1841 if (formal
->sym
->attr
.asynchronous
!= formal
->next
->sym
->attr
.asynchronous
)
1843 gfc_error ("The function passed as OPERATOR at %L shall have the "
1844 "ASYNCHRONOUS attribute either for none or both arguments",
1849 if (formal
->sym
->attr
.optional
|| formal
->next
->sym
->attr
.optional
)
1851 gfc_error ("The function passed as OPERATOR at %L shall not have the "
1852 "OPTIONAL attribute for either of the arguments", &op
->where
);
1856 if (a
->ts
.type
== BT_CHARACTER
)
1859 unsigned long actual_size
, formal_size1
, formal_size2
, result_size
;
1862 actual_size
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
1863 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
1865 cl
= formal
->sym
->ts
.u
.cl
;
1866 formal_size1
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
1867 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
1869 cl
= formal
->next
->sym
->ts
.u
.cl
;
1870 formal_size2
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
1871 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
1874 result_size
= cl
&& cl
->length
&& cl
->length
->expr_type
== EXPR_CONSTANT
1875 ? mpz_get_ui (cl
->length
->value
.integer
) : 0;
1878 && ((formal_size1
&& actual_size
!= formal_size1
)
1879 || (formal_size2
&& actual_size
!= formal_size2
)))
1881 gfc_error ("The character length of the A argument at %L and of the "
1882 "arguments of the OPERATOR at %L shall be the same",
1883 &a
->where
, &op
->where
);
1886 if (actual_size
&& result_size
&& actual_size
!= result_size
)
1888 gfc_error ("The character length of the A argument at %L and of the "
1889 "function result of the OPERATOR at %L shall be the same",
1890 &a
->where
, &op
->where
);
1900 gfc_check_co_minmax (gfc_expr
*a
, gfc_expr
*result_image
, gfc_expr
*stat
,
1903 if (a
->ts
.type
!= BT_INTEGER
&& a
->ts
.type
!= BT_REAL
1904 && a
->ts
.type
!= BT_CHARACTER
)
1906 gfc_error ("%qs argument of %qs intrinsic at %L shall be of type "
1907 "integer, real or character",
1908 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
1912 return check_co_collective (a
, result_image
, stat
, errmsg
, false);
1917 gfc_check_co_sum (gfc_expr
*a
, gfc_expr
*result_image
, gfc_expr
*stat
,
1920 if (!numeric_check (a
, 0))
1922 return check_co_collective (a
, result_image
, stat
, errmsg
, false);
1927 gfc_check_complex (gfc_expr
*x
, gfc_expr
*y
)
1929 if (!int_or_real_check (x
, 0))
1931 if (!scalar_check (x
, 0))
1934 if (!int_or_real_check (y
, 1))
1936 if (!scalar_check (y
, 1))
1944 gfc_check_count (gfc_expr
*mask
, gfc_expr
*dim
, gfc_expr
*kind
)
1946 if (!logical_array_check (mask
, 0))
1948 if (!dim_check (dim
, 1, false))
1950 if (!dim_rank_check (dim
, mask
, 0))
1952 if (!kind_check (kind
, 2, BT_INTEGER
))
1954 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
1955 "with KIND argument at %L",
1956 gfc_current_intrinsic
, &kind
->where
))
1964 gfc_check_cshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*dim
)
1966 if (!array_check (array
, 0))
1969 if (!type_check (shift
, 1, BT_INTEGER
))
1972 if (!dim_check (dim
, 2, true))
1975 if (!dim_rank_check (dim
, array
, false))
1978 if (array
->rank
== 1 || shift
->rank
== 0)
1980 if (!scalar_check (shift
, 1))
1983 else if (shift
->rank
== array
->rank
- 1)
1988 else if (dim
->expr_type
== EXPR_CONSTANT
)
1989 gfc_extract_int (dim
, &d
);
1996 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
1999 if (!identical_dimen_shape (array
, i
, shift
, j
))
2001 gfc_error ("%qs argument of %qs intrinsic at %L has "
2002 "invalid shape in dimension %d (%ld/%ld)",
2003 gfc_current_intrinsic_arg
[1]->name
,
2004 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
2005 mpz_get_si (array
->shape
[i
]),
2006 mpz_get_si (shift
->shape
[j
]));
2016 gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
2017 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
2018 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
2027 gfc_check_ctime (gfc_expr
*time
)
2029 if (!scalar_check (time
, 0))
2032 if (!type_check (time
, 0, BT_INTEGER
))
2039 bool gfc_check_datan2 (gfc_expr
*y
, gfc_expr
*x
)
2041 if (!double_check (y
, 0) || !double_check (x
, 1))
2048 gfc_check_dcmplx (gfc_expr
*x
, gfc_expr
*y
)
2050 if (!numeric_check (x
, 0))
2055 if (!numeric_check (y
, 1))
2058 if (x
->ts
.type
== BT_COMPLEX
)
2060 gfc_error ("%qs argument of %qs intrinsic at %L must not be "
2061 "present if %<x%> is COMPLEX",
2062 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2067 if (y
->ts
.type
== BT_COMPLEX
)
2069 gfc_error ("%qs argument of %qs intrinsic at %L must have a type "
2070 "of either REAL or INTEGER",
2071 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2082 gfc_check_dble (gfc_expr
*x
)
2084 if (!numeric_check (x
, 0))
2092 gfc_check_digits (gfc_expr
*x
)
2094 if (!int_or_real_check (x
, 0))
2102 gfc_check_dot_product (gfc_expr
*vector_a
, gfc_expr
*vector_b
)
2104 switch (vector_a
->ts
.type
)
2107 if (!type_check (vector_b
, 1, BT_LOGICAL
))
2114 if (!numeric_check (vector_b
, 1))
2119 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
2120 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
2121 gfc_current_intrinsic
, &vector_a
->where
);
2125 if (!rank_check (vector_a
, 0, 1))
2128 if (!rank_check (vector_b
, 1, 1))
2131 if (! identical_dimen_shape (vector_a
, 0, vector_b
, 0))
2133 gfc_error ("Different shape for arguments %qs and %qs at %L for "
2134 "intrinsic %<dot_product%>",
2135 gfc_current_intrinsic_arg
[0]->name
,
2136 gfc_current_intrinsic_arg
[1]->name
, &vector_a
->where
);
2145 gfc_check_dprod (gfc_expr
*x
, gfc_expr
*y
)
2147 if (!type_check (x
, 0, BT_REAL
)
2148 || !type_check (y
, 1, BT_REAL
))
2151 if (x
->ts
.kind
!= gfc_default_real_kind
)
2153 gfc_error ("%qs argument of %qs intrinsic at %L must be default "
2154 "real", gfc_current_intrinsic_arg
[0]->name
,
2155 gfc_current_intrinsic
, &x
->where
);
2159 if (y
->ts
.kind
!= gfc_default_real_kind
)
2161 gfc_error ("%qs argument of %qs intrinsic at %L must be default "
2162 "real", gfc_current_intrinsic_arg
[1]->name
,
2163 gfc_current_intrinsic
, &y
->where
);
2172 gfc_check_dshift (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*shift
)
2174 if (!type_check (i
, 0, BT_INTEGER
))
2177 if (!type_check (j
, 1, BT_INTEGER
))
2180 if (i
->is_boz
&& j
->is_boz
)
2182 gfc_error ("%<I%> at %L and %<J%>' at %L cannot both be BOZ literal "
2183 "constants", &i
->where
, &j
->where
);
2187 if (!i
->is_boz
&& !j
->is_boz
&& !same_type_check (i
, 0, j
, 1))
2190 if (!type_check (shift
, 2, BT_INTEGER
))
2193 if (!nonnegative_check ("SHIFT", shift
))
2198 if (!less_than_bitsize1 ("J", j
, "SHIFT", shift
, true))
2200 i
->ts
.kind
= j
->ts
.kind
;
2204 if (!less_than_bitsize1 ("I", i
, "SHIFT", shift
, true))
2206 j
->ts
.kind
= i
->ts
.kind
;
2214 gfc_check_eoshift (gfc_expr
*array
, gfc_expr
*shift
, gfc_expr
*boundary
,
2219 if (!array_check (array
, 0))
2222 if (!type_check (shift
, 1, BT_INTEGER
))
2225 if (!dim_check (dim
, 3, true))
2228 if (!dim_rank_check (dim
, array
, false))
2233 else if (dim
->expr_type
== EXPR_CONSTANT
)
2234 gfc_extract_int (dim
, &d
);
2238 if (array
->rank
== 1 || shift
->rank
== 0)
2240 if (!scalar_check (shift
, 1))
2243 else if (shift
->rank
== array
->rank
- 1)
2248 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
2251 if (!identical_dimen_shape (array
, i
, shift
, j
))
2253 gfc_error ("%qs argument of %qs intrinsic at %L has "
2254 "invalid shape in dimension %d (%ld/%ld)",
2255 gfc_current_intrinsic_arg
[1]->name
,
2256 gfc_current_intrinsic
, &shift
->where
, i
+ 1,
2257 mpz_get_si (array
->shape
[i
]),
2258 mpz_get_si (shift
->shape
[j
]));
2268 gfc_error ("%qs argument of intrinsic %qs at %L of must have rank "
2269 "%d or be a scalar", gfc_current_intrinsic_arg
[1]->name
,
2270 gfc_current_intrinsic
, &shift
->where
, array
->rank
- 1);
2274 if (boundary
!= NULL
)
2276 if (!same_type_check (array
, 0, boundary
, 2))
2279 /* Reject unequal string lengths and emit a better error message than
2280 gfc_check_same_strlen would. */
2281 if (array
->ts
.type
== BT_CHARACTER
)
2283 ssize_t len_a
, len_b
;
2285 len_a
= gfc_var_strlen (array
);
2286 len_b
= gfc_var_strlen (boundary
);
2287 if (len_a
!= -1 && len_b
!= -1 && len_a
!= len_b
)
2289 gfc_error ("%qs must be of same type and kind as %qs at %L in %qs",
2290 gfc_current_intrinsic_arg
[2]->name
,
2291 gfc_current_intrinsic_arg
[0]->name
,
2292 &boundary
->where
, gfc_current_intrinsic
);
2297 if (array
->rank
== 1 || boundary
->rank
== 0)
2299 if (!scalar_check (boundary
, 2))
2302 else if (boundary
->rank
== array
->rank
- 1)
2307 for (i
= 0, j
= 0; i
< array
->rank
; i
++)
2311 if (!identical_dimen_shape (array
, i
, boundary
, j
))
2313 gfc_error ("%qs argument of %qs intrinsic at %L has "
2314 "invalid shape in dimension %d (%ld/%ld)",
2315 gfc_current_intrinsic_arg
[2]->name
,
2316 gfc_current_intrinsic
, &shift
->where
, i
+1,
2317 mpz_get_si (array
->shape
[i
]),
2318 mpz_get_si (boundary
->shape
[j
]));
2328 gfc_error ("%qs argument of intrinsic %qs at %L of must have "
2329 "rank %d or be a scalar",
2330 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
2331 &shift
->where
, array
->rank
- 1);
2337 switch (array
->ts
.type
)
2347 gfc_error ("Missing %qs argument to %qs intrinsic at %L for %qs "
2348 "of type %qs", gfc_current_intrinsic_arg
[2]->name
,
2349 gfc_current_intrinsic
, &array
->where
,
2350 gfc_current_intrinsic_arg
[0]->name
,
2351 gfc_typename (&array
->ts
));
2360 gfc_check_float (gfc_expr
*a
)
2362 if (!type_check (a
, 0, BT_INTEGER
))
2365 if ((a
->ts
.kind
!= gfc_default_integer_kind
)
2366 && !gfc_notify_std (GFC_STD_GNU
, "non-default INTEGER "
2367 "kind argument to %s intrinsic at %L",
2368 gfc_current_intrinsic
, &a
->where
))
2374 /* A single complex argument. */
2377 gfc_check_fn_c (gfc_expr
*a
)
2379 if (!type_check (a
, 0, BT_COMPLEX
))
2386 /* A single real argument. */
2389 gfc_check_fn_r (gfc_expr
*a
)
2391 if (!type_check (a
, 0, BT_REAL
))
2397 /* A single double argument. */
2400 gfc_check_fn_d (gfc_expr
*a
)
2402 if (!double_check (a
, 0))
2408 /* A single real or complex argument. */
2411 gfc_check_fn_rc (gfc_expr
*a
)
2413 if (!real_or_complex_check (a
, 0))
2421 gfc_check_fn_rc2008 (gfc_expr
*a
)
2423 if (!real_or_complex_check (a
, 0))
2426 if (a
->ts
.type
== BT_COMPLEX
2427 && !gfc_notify_std (GFC_STD_F2008
, "COMPLEX argument %qs "
2428 "of %qs intrinsic at %L",
2429 gfc_current_intrinsic_arg
[0]->name
,
2430 gfc_current_intrinsic
, &a
->where
))
2438 gfc_check_fnum (gfc_expr
*unit
)
2440 if (!type_check (unit
, 0, BT_INTEGER
))
2443 if (!scalar_check (unit
, 0))
2451 gfc_check_huge (gfc_expr
*x
)
2453 if (!int_or_real_check (x
, 0))
2461 gfc_check_hypot (gfc_expr
*x
, gfc_expr
*y
)
2463 if (!type_check (x
, 0, BT_REAL
))
2465 if (!same_type_check (x
, 0, y
, 1))
2472 /* Check that the single argument is an integer. */
2475 gfc_check_i (gfc_expr
*i
)
2477 if (!type_check (i
, 0, BT_INTEGER
))
2485 gfc_check_iand (gfc_expr
*i
, gfc_expr
*j
)
2487 if (!type_check (i
, 0, BT_INTEGER
))
2490 if (!type_check (j
, 1, BT_INTEGER
))
2493 if (i
->ts
.kind
!= j
->ts
.kind
)
2495 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
2505 gfc_check_ibits (gfc_expr
*i
, gfc_expr
*pos
, gfc_expr
*len
)
2507 if (!type_check (i
, 0, BT_INTEGER
))
2510 if (!type_check (pos
, 1, BT_INTEGER
))
2513 if (!type_check (len
, 2, BT_INTEGER
))
2516 if (!nonnegative_check ("pos", pos
))
2519 if (!nonnegative_check ("len", len
))
2522 if (!less_than_bitsize2 ("i", i
, "pos", pos
, "len", len
))
2530 gfc_check_ichar_iachar (gfc_expr
*c
, gfc_expr
*kind
)
2534 if (!type_check (c
, 0, BT_CHARACTER
))
2537 if (!kind_check (kind
, 1, BT_INTEGER
))
2540 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
2541 "with KIND argument at %L",
2542 gfc_current_intrinsic
, &kind
->where
))
2545 if (c
->expr_type
== EXPR_VARIABLE
|| c
->expr_type
== EXPR_SUBSTRING
)
2551 /* Substring references don't have the charlength set. */
2553 while (ref
&& ref
->type
!= REF_SUBSTRING
)
2556 gcc_assert (ref
== NULL
|| ref
->type
== REF_SUBSTRING
);
2560 /* Check that the argument is length one. Non-constant lengths
2561 can't be checked here, so assume they are ok. */
2562 if (c
->ts
.u
.cl
&& c
->ts
.u
.cl
->length
)
2564 /* If we already have a length for this expression then use it. */
2565 if (c
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
)
2567 i
= mpz_get_si (c
->ts
.u
.cl
->length
->value
.integer
);
2574 start
= ref
->u
.ss
.start
;
2575 end
= ref
->u
.ss
.end
;
2578 if (end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
2579 || start
->expr_type
!= EXPR_CONSTANT
)
2582 i
= mpz_get_si (end
->value
.integer
) + 1
2583 - mpz_get_si (start
->value
.integer
);
2591 gfc_error ("Argument of %s at %L must be of length one",
2592 gfc_current_intrinsic
, &c
->where
);
2601 gfc_check_idnint (gfc_expr
*a
)
2603 if (!double_check (a
, 0))
2611 gfc_check_ieor (gfc_expr
*i
, gfc_expr
*j
)
2613 if (!type_check (i
, 0, BT_INTEGER
))
2616 if (!type_check (j
, 1, BT_INTEGER
))
2619 if (i
->ts
.kind
!= j
->ts
.kind
)
2621 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
2631 gfc_check_index (gfc_expr
*string
, gfc_expr
*substring
, gfc_expr
*back
,
2634 if (!type_check (string
, 0, BT_CHARACTER
)
2635 || !type_check (substring
, 1, BT_CHARACTER
))
2638 if (back
!= NULL
&& !type_check (back
, 2, BT_LOGICAL
))
2641 if (!kind_check (kind
, 3, BT_INTEGER
))
2643 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
2644 "with KIND argument at %L",
2645 gfc_current_intrinsic
, &kind
->where
))
2648 if (string
->ts
.kind
!= substring
->ts
.kind
)
2650 gfc_error ("%qs argument of %qs intrinsic at %L must be the same "
2651 "kind as %qs", gfc_current_intrinsic_arg
[1]->name
,
2652 gfc_current_intrinsic
, &substring
->where
,
2653 gfc_current_intrinsic_arg
[0]->name
);
2662 gfc_check_int (gfc_expr
*x
, gfc_expr
*kind
)
2664 if (!numeric_check (x
, 0))
2667 if (!kind_check (kind
, 1, BT_INTEGER
))
2675 gfc_check_intconv (gfc_expr
*x
)
2677 if (!numeric_check (x
, 0))
2685 gfc_check_ior (gfc_expr
*i
, gfc_expr
*j
)
2687 if (!type_check (i
, 0, BT_INTEGER
))
2690 if (!type_check (j
, 1, BT_INTEGER
))
2693 if (i
->ts
.kind
!= j
->ts
.kind
)
2695 if (!gfc_notify_std (GFC_STD_GNU
, "Different type kinds at %L",
2705 gfc_check_ishft (gfc_expr
*i
, gfc_expr
*shift
)
2707 if (!type_check (i
, 0, BT_INTEGER
)
2708 || !type_check (shift
, 1, BT_INTEGER
))
2711 if (!less_than_bitsize1 ("I", i
, NULL
, shift
, true))
2719 gfc_check_ishftc (gfc_expr
*i
, gfc_expr
*shift
, gfc_expr
*size
)
2721 if (!type_check (i
, 0, BT_INTEGER
)
2722 || !type_check (shift
, 1, BT_INTEGER
))
2729 if (!type_check (size
, 2, BT_INTEGER
))
2732 if (!less_than_bitsize1 ("I", i
, "SIZE", size
, true))
2735 if (size
->expr_type
== EXPR_CONSTANT
)
2737 gfc_extract_int (size
, &i3
);
2740 gfc_error ("SIZE at %L must be positive", &size
->where
);
2744 if (shift
->expr_type
== EXPR_CONSTANT
)
2746 gfc_extract_int (shift
, &i2
);
2752 gfc_error ("The absolute value of SHIFT at %L must be less "
2753 "than or equal to SIZE at %L", &shift
->where
,
2760 else if (!less_than_bitsize1 ("I", i
, NULL
, shift
, true))
2768 gfc_check_kill (gfc_expr
*pid
, gfc_expr
*sig
)
2770 if (!type_check (pid
, 0, BT_INTEGER
))
2773 if (!scalar_check (pid
, 0))
2776 if (!type_check (sig
, 1, BT_INTEGER
))
2779 if (!scalar_check (sig
, 1))
2787 gfc_check_kill_sub (gfc_expr
*pid
, gfc_expr
*sig
, gfc_expr
*status
)
2789 if (!type_check (pid
, 0, BT_INTEGER
))
2792 if (!scalar_check (pid
, 0))
2795 if (!type_check (sig
, 1, BT_INTEGER
))
2798 if (!scalar_check (sig
, 1))
2803 if (!type_check (status
, 2, BT_INTEGER
))
2806 if (!scalar_check (status
, 2))
2815 gfc_check_kind (gfc_expr
*x
)
2817 if (gfc_bt_struct (x
->ts
.type
) || x
->ts
.type
== BT_CLASS
)
2819 gfc_error ("%qs argument of %qs intrinsic at %L must be of "
2820 "intrinsic type", gfc_current_intrinsic_arg
[0]->name
,
2821 gfc_current_intrinsic
, &x
->where
);
2824 if (x
->ts
.type
== BT_PROCEDURE
)
2826 gfc_error ("%qs argument of %qs intrinsic at %L must be a data entity",
2827 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
2837 gfc_check_lbound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
2839 if (!array_check (array
, 0))
2842 if (!dim_check (dim
, 1, false))
2845 if (!dim_rank_check (dim
, array
, 1))
2848 if (!kind_check (kind
, 2, BT_INTEGER
))
2850 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
2851 "with KIND argument at %L",
2852 gfc_current_intrinsic
, &kind
->where
))
2860 gfc_check_lcobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
2862 if (flag_coarray
== GFC_FCOARRAY_NONE
)
2864 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
2868 if (!coarray_check (coarray
, 0))
2873 if (!dim_check (dim
, 1, false))
2876 if (!dim_corank_check (dim
, coarray
))
2880 if (!kind_check (kind
, 2, BT_INTEGER
))
2888 gfc_check_len_lentrim (gfc_expr
*s
, gfc_expr
*kind
)
2890 if (!type_check (s
, 0, BT_CHARACTER
))
2893 if (!kind_check (kind
, 1, BT_INTEGER
))
2895 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
2896 "with KIND argument at %L",
2897 gfc_current_intrinsic
, &kind
->where
))
2905 gfc_check_lge_lgt_lle_llt (gfc_expr
*a
, gfc_expr
*b
)
2907 if (!type_check (a
, 0, BT_CHARACTER
))
2909 if (!kind_value_check (a
, 0, gfc_default_character_kind
))
2912 if (!type_check (b
, 1, BT_CHARACTER
))
2914 if (!kind_value_check (b
, 1, gfc_default_character_kind
))
2922 gfc_check_link (gfc_expr
*path1
, gfc_expr
*path2
)
2924 if (!type_check (path1
, 0, BT_CHARACTER
))
2926 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2929 if (!type_check (path2
, 1, BT_CHARACTER
))
2931 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
2939 gfc_check_link_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2941 if (!type_check (path1
, 0, BT_CHARACTER
))
2943 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2946 if (!type_check (path2
, 1, BT_CHARACTER
))
2948 if (!kind_value_check (path2
, 0, gfc_default_character_kind
))
2954 if (!type_check (status
, 2, BT_INTEGER
))
2957 if (!scalar_check (status
, 2))
2965 gfc_check_loc (gfc_expr
*expr
)
2967 return variable_check (expr
, 0, true);
2972 gfc_check_symlnk (gfc_expr
*path1
, gfc_expr
*path2
)
2974 if (!type_check (path1
, 0, BT_CHARACTER
))
2976 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2979 if (!type_check (path2
, 1, BT_CHARACTER
))
2981 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
2989 gfc_check_symlnk_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
2991 if (!type_check (path1
, 0, BT_CHARACTER
))
2993 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
2996 if (!type_check (path2
, 1, BT_CHARACTER
))
2998 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
3004 if (!type_check (status
, 2, BT_INTEGER
))
3007 if (!scalar_check (status
, 2))
3015 gfc_check_logical (gfc_expr
*a
, gfc_expr
*kind
)
3017 if (!type_check (a
, 0, BT_LOGICAL
))
3019 if (!kind_check (kind
, 1, BT_LOGICAL
))
3026 /* Min/max family. */
3029 min_max_args (gfc_actual_arglist
*args
)
3031 gfc_actual_arglist
*arg
;
3032 int i
, j
, nargs
, *nlabels
, nlabelless
;
3033 bool a1
= false, a2
= false;
3035 if (args
== NULL
|| args
->next
== NULL
)
3037 gfc_error ("Intrinsic %qs at %L must have at least two arguments",
3038 gfc_current_intrinsic
, gfc_current_intrinsic_where
);
3045 if (!args
->next
->name
)
3049 for (arg
= args
; arg
; arg
= arg
->next
)
3056 /* Note: Having a keywordless argument after an "arg=" is checked before. */
3058 nlabels
= XALLOCAVEC (int, nargs
);
3059 for (arg
= args
, i
= 0; arg
; arg
= arg
->next
, i
++)
3065 if (arg
->name
[0] != 'a' || arg
->name
[1] < '1' || arg
->name
[1] > '9')
3067 n
= strtol (&arg
->name
[1], &endp
, 10);
3068 if (endp
[0] != '\0')
3072 if (n
<= nlabelless
)
3085 gfc_error ("Missing %qs argument to the %s intrinsic at %L",
3086 !a1
? "a1" : "a2", gfc_current_intrinsic
,
3087 gfc_current_intrinsic_where
);
3091 /* Check for duplicates. */
3092 for (i
= 0; i
< nargs
; i
++)
3093 for (j
= i
+ 1; j
< nargs
; j
++)
3094 if (nlabels
[i
] == nlabels
[j
])
3100 gfc_error ("Duplicate argument %qs at %L to intrinsic %s", arg
->name
,
3101 &arg
->expr
->where
, gfc_current_intrinsic
);
3105 gfc_error ("Unknown argument %qs at %L to intrinsic %s", arg
->name
,
3106 &arg
->expr
->where
, gfc_current_intrinsic
);
3112 check_rest (bt type
, int kind
, gfc_actual_arglist
*arglist
)
3114 gfc_actual_arglist
*arg
, *tmp
;
3118 if (!min_max_args (arglist
))
3121 for (arg
= arglist
, n
=1; arg
; arg
= arg
->next
, n
++)
3124 if (x
->ts
.type
!= type
|| x
->ts
.kind
!= kind
)
3126 if (x
->ts
.type
== type
)
3128 if (!gfc_notify_std (GFC_STD_GNU
, "Different type "
3129 "kinds at %L", &x
->where
))
3134 gfc_error ("%<a%d%> argument of %qs intrinsic at %L must be "
3135 "%s(%d)", n
, gfc_current_intrinsic
, &x
->where
,
3136 gfc_basic_typename (type
), kind
);
3141 for (tmp
= arglist
, m
=1; tmp
!= arg
; tmp
= tmp
->next
, m
++)
3142 if (!gfc_check_conformance (tmp
->expr
, x
,
3143 "arguments 'a%d' and 'a%d' for "
3144 "intrinsic '%s'", m
, n
,
3145 gfc_current_intrinsic
))
3154 gfc_check_min_max (gfc_actual_arglist
*arg
)
3158 if (!min_max_args (arg
))
3163 if (x
->ts
.type
== BT_CHARACTER
)
3165 if (!gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
3166 "with CHARACTER argument at %L",
3167 gfc_current_intrinsic
, &x
->where
))
3170 else if (x
->ts
.type
!= BT_INTEGER
&& x
->ts
.type
!= BT_REAL
)
3172 gfc_error ("%<a1%> argument of %qs intrinsic at %L must be INTEGER, "
3173 "REAL or CHARACTER", gfc_current_intrinsic
, &x
->where
);
3177 return check_rest (x
->ts
.type
, x
->ts
.kind
, arg
);
3182 gfc_check_min_max_integer (gfc_actual_arglist
*arg
)
3184 return check_rest (BT_INTEGER
, gfc_default_integer_kind
, arg
);
3189 gfc_check_min_max_real (gfc_actual_arglist
*arg
)
3191 return check_rest (BT_REAL
, gfc_default_real_kind
, arg
);
3196 gfc_check_min_max_double (gfc_actual_arglist
*arg
)
3198 return check_rest (BT_REAL
, gfc_default_double_kind
, arg
);
3202 /* End of min/max family. */
3205 gfc_check_malloc (gfc_expr
*size
)
3207 if (!type_check (size
, 0, BT_INTEGER
))
3210 if (!scalar_check (size
, 0))
3218 gfc_check_matmul (gfc_expr
*matrix_a
, gfc_expr
*matrix_b
)
3220 if ((matrix_a
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_a
->ts
))
3222 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3223 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
3224 gfc_current_intrinsic
, &matrix_a
->where
);
3228 if ((matrix_b
->ts
.type
!= BT_LOGICAL
) && !gfc_numeric_ts (&matrix_b
->ts
))
3230 gfc_error ("%qs argument of %qs intrinsic at %L must be numeric "
3231 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
3232 gfc_current_intrinsic
, &matrix_b
->where
);
3236 if ((matrix_a
->ts
.type
== BT_LOGICAL
&& gfc_numeric_ts (&matrix_b
->ts
))
3237 || (gfc_numeric_ts (&matrix_a
->ts
) && matrix_b
->ts
.type
== BT_LOGICAL
))
3239 gfc_error ("Argument types of %qs intrinsic at %L must match (%s/%s)",
3240 gfc_current_intrinsic
, &matrix_a
->where
,
3241 gfc_typename(&matrix_a
->ts
), gfc_typename(&matrix_b
->ts
));
3245 switch (matrix_a
->rank
)
3248 if (!rank_check (matrix_b
, 1, 2))
3250 /* Check for case matrix_a has shape(m), matrix_b has shape (m, k). */
3251 if (!identical_dimen_shape (matrix_a
, 0, matrix_b
, 0))
3253 gfc_error ("Different shape on dimension 1 for arguments %qs "
3254 "and %qs at %L for intrinsic matmul",
3255 gfc_current_intrinsic_arg
[0]->name
,
3256 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
3262 if (matrix_b
->rank
!= 2)
3264 if (!rank_check (matrix_b
, 1, 1))
3267 /* matrix_b has rank 1 or 2 here. Common check for the cases
3268 - matrix_a has shape (n,m) and matrix_b has shape (m, k)
3269 - matrix_a has shape (n,m) and matrix_b has shape (m). */
3270 if (!identical_dimen_shape (matrix_a
, 1, matrix_b
, 0))
3272 gfc_error ("Different shape on dimension 2 for argument %qs and "
3273 "dimension 1 for argument %qs at %L for intrinsic "
3274 "matmul", gfc_current_intrinsic_arg
[0]->name
,
3275 gfc_current_intrinsic_arg
[1]->name
, &matrix_a
->where
);
3281 gfc_error ("%qs argument of %qs intrinsic at %L must be of rank "
3282 "1 or 2", gfc_current_intrinsic_arg
[0]->name
,
3283 gfc_current_intrinsic
, &matrix_a
->where
);
3291 /* Whoever came up with this interface was probably on something.
3292 The possibilities for the occupation of the second and third
3299 NULL MASK minloc(array, mask=m)
3302 I.e. in the case of minloc(array,mask), mask will be in the second
3303 position of the argument list and we'll have to fix that up. Also,
3304 add the BACK argument if that isn't present. */
3307 gfc_check_minloc_maxloc (gfc_actual_arglist
*ap
)
3309 gfc_expr
*a
, *m
, *d
, *k
, *b
;
3312 if (!int_or_real_or_char_check_f2003 (a
, 0) || !array_check (a
, 0))
3316 m
= ap
->next
->next
->expr
;
3317 k
= ap
->next
->next
->next
->expr
;
3318 b
= ap
->next
->next
->next
->next
->expr
;
3322 if (!type_check (b
, 4, BT_LOGICAL
) || !scalar_check (b
,4))
3327 b
= gfc_get_logical_expr (gfc_logical_4_kind
, NULL
, 0);
3328 ap
->next
->next
->next
->next
->expr
= b
;
3331 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
3332 && ap
->next
->name
== NULL
)
3336 ap
->next
->expr
= NULL
;
3337 ap
->next
->next
->expr
= m
;
3340 if (!dim_check (d
, 1, false))
3343 if (!dim_rank_check (d
, a
, 0))
3346 if (m
!= NULL
&& !type_check (m
, 2, BT_LOGICAL
))
3350 && !gfc_check_conformance (a
, m
,
3351 "arguments '%s' and '%s' for intrinsic %s",
3352 gfc_current_intrinsic_arg
[0]->name
,
3353 gfc_current_intrinsic_arg
[2]->name
,
3354 gfc_current_intrinsic
))
3357 if (!kind_check (k
, 1, BT_INTEGER
))
3363 /* Check function for findloc. Mostly like gfc_check_minloc_maxloc
3364 above, with the additional "value" argument. */
3367 gfc_check_findloc (gfc_actual_arglist
*ap
)
3369 gfc_expr
*a
, *v
, *m
, *d
, *k
, *b
;
3372 if (!intrinsic_type_check (a
, 0) || !array_check (a
, 0))
3376 if (!scalar_check (v
,1))
3379 /* Check if the type is compatible. */
3381 if ((a
->ts
.type
== BT_LOGICAL
&& v
->ts
.type
!= BT_LOGICAL
)
3382 || (a
->ts
.type
!= BT_LOGICAL
&& v
->ts
.type
== BT_LOGICAL
))
3384 gfc_error ("Argument %qs of %qs intrinsic at %L must be in type "
3385 "conformance to argument %qs at %L",
3386 gfc_current_intrinsic_arg
[0]->name
,
3387 gfc_current_intrinsic
, &a
->where
,
3388 gfc_current_intrinsic_arg
[1]->name
, &v
->where
);
3391 d
= ap
->next
->next
->expr
;
3392 m
= ap
->next
->next
->next
->expr
;
3393 k
= ap
->next
->next
->next
->next
->expr
;
3394 b
= ap
->next
->next
->next
->next
->next
->expr
;
3398 if (!type_check (b
, 5, BT_LOGICAL
) || !scalar_check (b
,4))
3403 b
= gfc_get_logical_expr (gfc_logical_4_kind
, NULL
, 0);
3404 ap
->next
->next
->next
->next
->next
->expr
= b
;
3407 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
3408 && ap
->next
->name
== NULL
)
3412 ap
->next
->next
->expr
= NULL
;
3413 ap
->next
->next
->next
->expr
= m
;
3416 if (!dim_check (d
, 2, false))
3419 if (!dim_rank_check (d
, a
, 0))
3422 if (m
!= NULL
&& !type_check (m
, 3, BT_LOGICAL
))
3426 && !gfc_check_conformance (a
, m
,
3427 "arguments '%s' and '%s' for intrinsic %s",
3428 gfc_current_intrinsic_arg
[0]->name
,
3429 gfc_current_intrinsic_arg
[3]->name
,
3430 gfc_current_intrinsic
))
3433 if (!kind_check (k
, 1, BT_INTEGER
))
3440 /* Similar to minloc/maxloc, the argument list might need to be
3441 reordered for the MINVAL, MAXVAL, PRODUCT, and SUM intrinsics. The
3442 difference is that MINLOC/MAXLOC take an additional KIND argument.
3443 The possibilities are:
3449 NULL MASK minval(array, mask=m)
3452 I.e. in the case of minval(array,mask), mask will be in the second
3453 position of the argument list and we'll have to fix that up. */
3456 check_reduction (gfc_actual_arglist
*ap
)
3458 gfc_expr
*a
, *m
, *d
;
3462 m
= ap
->next
->next
->expr
;
3464 if (m
== NULL
&& d
!= NULL
&& d
->ts
.type
== BT_LOGICAL
3465 && ap
->next
->name
== NULL
)
3469 ap
->next
->expr
= NULL
;
3470 ap
->next
->next
->expr
= m
;
3473 if (!dim_check (d
, 1, false))
3476 if (!dim_rank_check (d
, a
, 0))
3479 if (m
!= NULL
&& !type_check (m
, 2, BT_LOGICAL
))
3483 && !gfc_check_conformance (a
, m
,
3484 "arguments '%s' and '%s' for intrinsic %s",
3485 gfc_current_intrinsic_arg
[0]->name
,
3486 gfc_current_intrinsic_arg
[2]->name
,
3487 gfc_current_intrinsic
))
3495 gfc_check_minval_maxval (gfc_actual_arglist
*ap
)
3497 if (!int_or_real_or_char_check_f2003 (ap
->expr
, 0)
3498 || !array_check (ap
->expr
, 0))
3501 return check_reduction (ap
);
3506 gfc_check_product_sum (gfc_actual_arglist
*ap
)
3508 if (!numeric_check (ap
->expr
, 0)
3509 || !array_check (ap
->expr
, 0))
3512 return check_reduction (ap
);
3516 /* For IANY, IALL and IPARITY. */
3519 gfc_check_mask (gfc_expr
*i
, gfc_expr
*kind
)
3523 if (!type_check (i
, 0, BT_INTEGER
))
3526 if (!nonnegative_check ("I", i
))
3529 if (!kind_check (kind
, 1, BT_INTEGER
))
3533 gfc_extract_int (kind
, &k
);
3535 k
= gfc_default_integer_kind
;
3537 if (!less_than_bitsizekind ("I", i
, k
))
3545 gfc_check_transf_bit_intrins (gfc_actual_arglist
*ap
)
3547 if (ap
->expr
->ts
.type
!= BT_INTEGER
)
3549 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER",
3550 gfc_current_intrinsic_arg
[0]->name
,
3551 gfc_current_intrinsic
, &ap
->expr
->where
);
3555 if (!array_check (ap
->expr
, 0))
3558 return check_reduction (ap
);
3563 gfc_check_merge (gfc_expr
*tsource
, gfc_expr
*fsource
, gfc_expr
*mask
)
3565 if (!same_type_check (tsource
, 0, fsource
, 1))
3568 if (!type_check (mask
, 2, BT_LOGICAL
))
3571 if (tsource
->ts
.type
== BT_CHARACTER
)
3572 return gfc_check_same_strlen (tsource
, fsource
, "MERGE intrinsic");
3579 gfc_check_merge_bits (gfc_expr
*i
, gfc_expr
*j
, gfc_expr
*mask
)
3581 if (!type_check (i
, 0, BT_INTEGER
))
3584 if (!type_check (j
, 1, BT_INTEGER
))
3587 if (!type_check (mask
, 2, BT_INTEGER
))
3590 if (!same_type_check (i
, 0, j
, 1))
3593 if (!same_type_check (i
, 0, mask
, 2))
3601 gfc_check_move_alloc (gfc_expr
*from
, gfc_expr
*to
)
3603 if (!variable_check (from
, 0, false))
3605 if (!allocatable_check (from
, 0))
3607 if (gfc_is_coindexed (from
))
3609 gfc_error ("The FROM argument to MOVE_ALLOC at %L shall not be "
3610 "coindexed", &from
->where
);
3614 if (!variable_check (to
, 1, false))
3616 if (!allocatable_check (to
, 1))
3618 if (gfc_is_coindexed (to
))
3620 gfc_error ("The TO argument to MOVE_ALLOC at %L shall not be "
3621 "coindexed", &to
->where
);
3625 if (from
->ts
.type
== BT_CLASS
&& to
->ts
.type
== BT_DERIVED
)
3627 gfc_error ("The TO arguments in MOVE_ALLOC at %L must be "
3628 "polymorphic if FROM is polymorphic",
3633 if (!same_type_check (to
, 1, from
, 0))
3636 if (to
->rank
!= from
->rank
)
3638 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
3639 "must have the same rank %d/%d", &to
->where
, from
->rank
,
3644 /* IR F08/0040; cf. 12-006A. */
3645 if (gfc_get_corank (to
) != gfc_get_corank (from
))
3647 gfc_error ("The FROM and TO arguments of the MOVE_ALLOC intrinsic at %L "
3648 "must have the same corank %d/%d", &to
->where
,
3649 gfc_get_corank (from
), gfc_get_corank (to
));
3653 /* This is based losely on F2003 12.4.1.7. It is intended to prevent
3654 the likes of to = sym->cmp1->cmp2 and from = sym->cmp1, where cmp1
3655 and cmp2 are allocatable. After the allocation is transferred,
3656 the 'to' chain is broken by the nullification of the 'from'. A bit
3657 of reflection reveals that this can only occur for derived types
3658 with recursive allocatable components. */
3659 if (to
->expr_type
== EXPR_VARIABLE
&& from
->expr_type
== EXPR_VARIABLE
3660 && !strcmp (to
->symtree
->n
.sym
->name
, from
->symtree
->n
.sym
->name
))
3662 gfc_ref
*to_ref
, *from_ref
;
3664 from_ref
= from
->ref
;
3665 bool aliasing
= true;
3667 for (; from_ref
&& to_ref
;
3668 from_ref
= from_ref
->next
, to_ref
= to_ref
->next
)
3670 if (to_ref
->type
!= from
->ref
->type
)
3672 else if (to_ref
->type
== REF_ARRAY
3673 && to_ref
->u
.ar
.type
!= AR_FULL
3674 && from_ref
->u
.ar
.type
!= AR_FULL
)
3675 /* Play safe; assume sections and elements are different. */
3677 else if (to_ref
->type
== REF_COMPONENT
3678 && to_ref
->u
.c
.component
!= from_ref
->u
.c
.component
)
3687 gfc_error ("The FROM and TO arguments at %L violate aliasing "
3688 "restrictions (F2003 12.4.1.7)", &to
->where
);
3693 /* CLASS arguments: Make sure the vtab of from is present. */
3694 if (to
->ts
.type
== BT_CLASS
&& !UNLIMITED_POLY (from
))
3695 gfc_find_vtab (&from
->ts
);
3702 gfc_check_nearest (gfc_expr
*x
, gfc_expr
*s
)
3704 if (!type_check (x
, 0, BT_REAL
))
3707 if (!type_check (s
, 1, BT_REAL
))
3710 if (s
->expr_type
== EXPR_CONSTANT
)
3712 if (mpfr_sgn (s
->value
.real
) == 0)
3714 gfc_error ("Argument %<S%> of NEAREST at %L shall not be zero",
3725 gfc_check_new_line (gfc_expr
*a
)
3727 if (!type_check (a
, 0, BT_CHARACTER
))
3735 gfc_check_norm2 (gfc_expr
*array
, gfc_expr
*dim
)
3737 if (!type_check (array
, 0, BT_REAL
))
3740 if (!array_check (array
, 0))
3743 if (!dim_rank_check (dim
, array
, false))
3750 gfc_check_null (gfc_expr
*mold
)
3752 symbol_attribute attr
;
3757 if (!variable_check (mold
, 0, true))
3760 attr
= gfc_variable_attr (mold
, NULL
);
3762 if (!attr
.pointer
&& !attr
.proc_pointer
&& !attr
.allocatable
)
3764 gfc_error ("%qs argument of %qs intrinsic at %L must be a POINTER, "
3765 "ALLOCATABLE or procedure pointer",
3766 gfc_current_intrinsic_arg
[0]->name
,
3767 gfc_current_intrinsic
, &mold
->where
);
3771 if (attr
.allocatable
3772 && !gfc_notify_std (GFC_STD_F2003
, "NULL intrinsic with "
3773 "allocatable MOLD at %L", &mold
->where
))
3777 if (gfc_is_coindexed (mold
))
3779 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
3780 "coindexed", gfc_current_intrinsic_arg
[0]->name
,
3781 gfc_current_intrinsic
, &mold
->where
);
3790 gfc_check_pack (gfc_expr
*array
, gfc_expr
*mask
, gfc_expr
*vector
)
3792 if (!array_check (array
, 0))
3795 if (!type_check (mask
, 1, BT_LOGICAL
))
3798 if (!gfc_check_conformance (array
, mask
,
3799 "arguments '%s' and '%s' for intrinsic '%s'",
3800 gfc_current_intrinsic_arg
[0]->name
,
3801 gfc_current_intrinsic_arg
[1]->name
,
3802 gfc_current_intrinsic
))
3807 mpz_t array_size
, vector_size
;
3808 bool have_array_size
, have_vector_size
;
3810 if (!same_type_check (array
, 0, vector
, 2))
3813 if (!rank_check (vector
, 2, 1))
3816 /* VECTOR requires at least as many elements as MASK
3817 has .TRUE. values. */
3818 have_array_size
= gfc_array_size(array
, &array_size
);
3819 have_vector_size
= gfc_array_size(vector
, &vector_size
);
3821 if (have_vector_size
3822 && (mask
->expr_type
== EXPR_ARRAY
3823 || (mask
->expr_type
== EXPR_CONSTANT
3824 && have_array_size
)))
3826 int mask_true_values
= 0;
3828 if (mask
->expr_type
== EXPR_ARRAY
)
3830 gfc_constructor
*mask_ctor
;
3831 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
3834 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
3836 mask_true_values
= 0;
3840 if (mask_ctor
->expr
->value
.logical
)
3843 mask_ctor
= gfc_constructor_next (mask_ctor
);
3846 else if (mask
->expr_type
== EXPR_CONSTANT
&& mask
->value
.logical
)
3847 mask_true_values
= mpz_get_si (array_size
);
3849 if (mpz_get_si (vector_size
) < mask_true_values
)
3851 gfc_error ("%qs argument of %qs intrinsic at %L must "
3852 "provide at least as many elements as there "
3853 "are .TRUE. values in %qs (%ld/%d)",
3854 gfc_current_intrinsic_arg
[2]->name
,
3855 gfc_current_intrinsic
, &vector
->where
,
3856 gfc_current_intrinsic_arg
[1]->name
,
3857 mpz_get_si (vector_size
), mask_true_values
);
3862 if (have_array_size
)
3863 mpz_clear (array_size
);
3864 if (have_vector_size
)
3865 mpz_clear (vector_size
);
3873 gfc_check_parity (gfc_expr
*mask
, gfc_expr
*dim
)
3875 if (!type_check (mask
, 0, BT_LOGICAL
))
3878 if (!array_check (mask
, 0))
3881 if (!dim_rank_check (dim
, mask
, false))
3889 gfc_check_precision (gfc_expr
*x
)
3891 if (!real_or_complex_check (x
, 0))
3899 gfc_check_present (gfc_expr
*a
)
3903 if (!variable_check (a
, 0, true))
3906 sym
= a
->symtree
->n
.sym
;
3907 if (!sym
->attr
.dummy
)
3909 gfc_error ("%qs argument of %qs intrinsic at %L must be of a "
3910 "dummy variable", gfc_current_intrinsic_arg
[0]->name
,
3911 gfc_current_intrinsic
, &a
->where
);
3915 if (!sym
->attr
.optional
)
3917 gfc_error ("%qs argument of %qs intrinsic at %L must be of "
3918 "an OPTIONAL dummy variable",
3919 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
3924 /* 13.14.82 PRESENT(A)
3926 Argument. A shall be the name of an optional dummy argument that is
3927 accessible in the subprogram in which the PRESENT function reference
3931 && !(a
->ref
->next
== NULL
&& a
->ref
->type
== REF_ARRAY
3932 && (a
->ref
->u
.ar
.type
== AR_FULL
3933 || (a
->ref
->u
.ar
.type
== AR_ELEMENT
3934 && a
->ref
->u
.ar
.as
->rank
== 0))))
3936 gfc_error ("%qs argument of %qs intrinsic at %L must not be a "
3937 "subobject of %qs", gfc_current_intrinsic_arg
[0]->name
,
3938 gfc_current_intrinsic
, &a
->where
, sym
->name
);
3947 gfc_check_radix (gfc_expr
*x
)
3949 if (!int_or_real_check (x
, 0))
3957 gfc_check_range (gfc_expr
*x
)
3959 if (!numeric_check (x
, 0))
3967 gfc_check_rank (gfc_expr
*a
)
3969 /* Any data object is allowed; a "data object" is a "constant (4.1.3),
3970 variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */
3972 bool is_variable
= true;
3974 /* Functions returning pointers are regarded as variable, cf. F2008, R602. */
3975 if (a
->expr_type
== EXPR_FUNCTION
)
3976 is_variable
= a
->value
.function
.esym
3977 ? a
->value
.function
.esym
->result
->attr
.pointer
3978 : a
->symtree
->n
.sym
->result
->attr
.pointer
;
3980 if (a
->expr_type
== EXPR_OP
3981 || a
->expr_type
== EXPR_NULL
3982 || a
->expr_type
== EXPR_COMPCALL
3983 || a
->expr_type
== EXPR_PPC
3984 || a
->ts
.type
== BT_PROCEDURE
3987 gfc_error ("The argument of the RANK intrinsic at %L must be a data "
3988 "object", &a
->where
);
3996 /* real, float, sngl. */
3998 gfc_check_real (gfc_expr
*a
, gfc_expr
*kind
)
4000 if (!numeric_check (a
, 0))
4003 if (!kind_check (kind
, 1, BT_REAL
))
4011 gfc_check_rename (gfc_expr
*path1
, gfc_expr
*path2
)
4013 if (!type_check (path1
, 0, BT_CHARACTER
))
4015 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
4018 if (!type_check (path2
, 1, BT_CHARACTER
))
4020 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
4028 gfc_check_rename_sub (gfc_expr
*path1
, gfc_expr
*path2
, gfc_expr
*status
)
4030 if (!type_check (path1
, 0, BT_CHARACTER
))
4032 if (!kind_value_check (path1
, 0, gfc_default_character_kind
))
4035 if (!type_check (path2
, 1, BT_CHARACTER
))
4037 if (!kind_value_check (path2
, 1, gfc_default_character_kind
))
4043 if (!type_check (status
, 2, BT_INTEGER
))
4046 if (!scalar_check (status
, 2))
4054 gfc_check_repeat (gfc_expr
*x
, gfc_expr
*y
)
4056 if (!type_check (x
, 0, BT_CHARACTER
))
4059 if (!scalar_check (x
, 0))
4062 if (!type_check (y
, 0, BT_INTEGER
))
4065 if (!scalar_check (y
, 1))
4073 gfc_check_reshape (gfc_expr
*source
, gfc_expr
*shape
,
4074 gfc_expr
*pad
, gfc_expr
*order
)
4080 if (!array_check (source
, 0))
4083 if (!rank_check (shape
, 1, 1))
4086 if (!type_check (shape
, 1, BT_INTEGER
))
4089 if (!gfc_array_size (shape
, &size
))
4091 gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L must be an "
4092 "array of constant size", &shape
->where
);
4096 shape_size
= mpz_get_ui (size
);
4099 if (shape_size
<= 0)
4101 gfc_error ("%qs argument of %qs intrinsic at %L is empty",
4102 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4106 else if (shape_size
> GFC_MAX_DIMENSIONS
)
4108 gfc_error ("%<shape%> argument of %<reshape%> intrinsic at %L has more "
4109 "than %d elements", &shape
->where
, GFC_MAX_DIMENSIONS
);
4112 else if (shape
->expr_type
== EXPR_ARRAY
&& gfc_is_constant_expr (shape
))
4116 for (i
= 0; i
< shape_size
; ++i
)
4118 e
= gfc_constructor_lookup_expr (shape
->value
.constructor
, i
);
4119 if (e
->expr_type
!= EXPR_CONSTANT
)
4122 gfc_extract_int (e
, &extent
);
4125 gfc_error ("%qs argument of %qs intrinsic at %L has "
4126 "negative element (%d)",
4127 gfc_current_intrinsic_arg
[1]->name
,
4128 gfc_current_intrinsic
, &e
->where
, extent
);
4133 else if (shape
->expr_type
== EXPR_VARIABLE
&& shape
->ref
4134 && shape
->ref
->u
.ar
.type
== AR_FULL
&& shape
->ref
->u
.ar
.dimen
== 1
4135 && shape
->ref
->u
.ar
.as
4136 && shape
->ref
->u
.ar
.as
->lower
[0]->expr_type
== EXPR_CONSTANT
4137 && shape
->ref
->u
.ar
.as
->lower
[0]->ts
.type
== BT_INTEGER
4138 && shape
->ref
->u
.ar
.as
->upper
[0]->expr_type
== EXPR_CONSTANT
4139 && shape
->ref
->u
.ar
.as
->upper
[0]->ts
.type
== BT_INTEGER
4140 && shape
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
)
4145 v
= shape
->symtree
->n
.sym
->value
;
4147 for (i
= 0; i
< shape_size
; i
++)
4149 e
= gfc_constructor_lookup_expr (v
->value
.constructor
, i
);
4153 gfc_extract_int (e
, &extent
);
4157 gfc_error ("Element %d of actual argument of RESHAPE at %L "
4158 "cannot be negative", i
+ 1, &shape
->where
);
4166 if (!same_type_check (source
, 0, pad
, 2))
4169 if (!array_check (pad
, 2))
4175 if (!array_check (order
, 3))
4178 if (!type_check (order
, 3, BT_INTEGER
))
4181 if (order
->expr_type
== EXPR_ARRAY
&& gfc_is_constant_expr (order
))
4183 int i
, order_size
, dim
, perm
[GFC_MAX_DIMENSIONS
];
4186 for (i
= 0; i
< GFC_MAX_DIMENSIONS
; ++i
)
4189 gfc_array_size (order
, &size
);
4190 order_size
= mpz_get_ui (size
);
4193 if (order_size
!= shape_size
)
4195 gfc_error ("%qs argument of %qs intrinsic at %L "
4196 "has wrong number of elements (%d/%d)",
4197 gfc_current_intrinsic_arg
[3]->name
,
4198 gfc_current_intrinsic
, &order
->where
,
4199 order_size
, shape_size
);
4203 for (i
= 1; i
<= order_size
; ++i
)
4205 e
= gfc_constructor_lookup_expr (order
->value
.constructor
, i
-1);
4206 if (e
->expr_type
!= EXPR_CONSTANT
)
4209 gfc_extract_int (e
, &dim
);
4211 if (dim
< 1 || dim
> order_size
)
4213 gfc_error ("%qs argument of %qs intrinsic at %L "
4214 "has out-of-range dimension (%d)",
4215 gfc_current_intrinsic_arg
[3]->name
,
4216 gfc_current_intrinsic
, &e
->where
, dim
);
4220 if (perm
[dim
-1] != 0)
4222 gfc_error ("%qs argument of %qs intrinsic at %L has "
4223 "invalid permutation of dimensions (dimension "
4225 gfc_current_intrinsic_arg
[3]->name
,
4226 gfc_current_intrinsic
, &e
->where
, dim
);
4235 if (pad
== NULL
&& shape
->expr_type
== EXPR_ARRAY
4236 && gfc_is_constant_expr (shape
)
4237 && !(source
->expr_type
== EXPR_VARIABLE
&& source
->symtree
->n
.sym
->as
4238 && source
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
))
4240 /* Check the match in size between source and destination. */
4241 if (gfc_array_size (source
, &nelems
))
4247 mpz_init_set_ui (size
, 1);
4248 for (c
= gfc_constructor_first (shape
->value
.constructor
);
4249 c
; c
= gfc_constructor_next (c
))
4250 mpz_mul (size
, size
, c
->expr
->value
.integer
);
4252 test
= mpz_cmp (nelems
, size
) < 0 && mpz_cmp_ui (size
, 0) > 0;
4258 gfc_error ("Without padding, there are not enough elements "
4259 "in the intrinsic RESHAPE source at %L to match "
4260 "the shape", &source
->where
);
4271 gfc_check_same_type_as (gfc_expr
*a
, gfc_expr
*b
)
4273 if (a
->ts
.type
!= BT_DERIVED
&& a
->ts
.type
!= BT_CLASS
)
4275 gfc_error ("%qs argument of %qs intrinsic at %L "
4276 "cannot be of type %s",
4277 gfc_current_intrinsic_arg
[0]->name
,
4278 gfc_current_intrinsic
,
4279 &a
->where
, gfc_typename (&a
->ts
));
4283 if (!(gfc_type_is_extensible (a
->ts
.u
.derived
) || UNLIMITED_POLY (a
)))
4285 gfc_error ("%qs argument of %qs intrinsic at %L "
4286 "must be of an extensible type",
4287 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4292 if (b
->ts
.type
!= BT_DERIVED
&& b
->ts
.type
!= BT_CLASS
)
4294 gfc_error ("%qs argument of %qs intrinsic at %L "
4295 "cannot be of type %s",
4296 gfc_current_intrinsic_arg
[0]->name
,
4297 gfc_current_intrinsic
,
4298 &b
->where
, gfc_typename (&b
->ts
));
4302 if (!(gfc_type_is_extensible (b
->ts
.u
.derived
) || UNLIMITED_POLY (b
)))
4304 gfc_error ("%qs argument of %qs intrinsic at %L "
4305 "must be of an extensible type",
4306 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
4316 gfc_check_scale (gfc_expr
*x
, gfc_expr
*i
)
4318 if (!type_check (x
, 0, BT_REAL
))
4321 if (!type_check (i
, 1, BT_INTEGER
))
4329 gfc_check_scan (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
4331 if (!type_check (x
, 0, BT_CHARACTER
))
4334 if (!type_check (y
, 1, BT_CHARACTER
))
4337 if (z
!= NULL
&& !type_check (z
, 2, BT_LOGICAL
))
4340 if (!kind_check (kind
, 3, BT_INTEGER
))
4342 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
4343 "with KIND argument at %L",
4344 gfc_current_intrinsic
, &kind
->where
))
4347 if (!same_type_check (x
, 0, y
, 1))
4355 gfc_check_secnds (gfc_expr
*r
)
4357 if (!type_check (r
, 0, BT_REAL
))
4360 if (!kind_value_check (r
, 0, 4))
4363 if (!scalar_check (r
, 0))
4371 gfc_check_selected_char_kind (gfc_expr
*name
)
4373 if (!type_check (name
, 0, BT_CHARACTER
))
4376 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
4379 if (!scalar_check (name
, 0))
4387 gfc_check_selected_int_kind (gfc_expr
*r
)
4389 if (!type_check (r
, 0, BT_INTEGER
))
4392 if (!scalar_check (r
, 0))
4400 gfc_check_selected_real_kind (gfc_expr
*p
, gfc_expr
*r
, gfc_expr
*radix
)
4402 if (p
== NULL
&& r
== NULL
4403 && !gfc_notify_std (GFC_STD_F2008
, "SELECTED_REAL_KIND with"
4404 " neither %<P%> nor %<R%> argument at %L",
4405 gfc_current_intrinsic_where
))
4410 if (!type_check (p
, 0, BT_INTEGER
))
4413 if (!scalar_check (p
, 0))
4419 if (!type_check (r
, 1, BT_INTEGER
))
4422 if (!scalar_check (r
, 1))
4428 if (!type_check (radix
, 1, BT_INTEGER
))
4431 if (!scalar_check (radix
, 1))
4434 if (!gfc_notify_std (GFC_STD_F2008
, "%qs intrinsic with "
4435 "RADIX argument at %L", gfc_current_intrinsic
,
4445 gfc_check_set_exponent (gfc_expr
*x
, gfc_expr
*i
)
4447 if (!type_check (x
, 0, BT_REAL
))
4450 if (!type_check (i
, 1, BT_INTEGER
))
4458 gfc_check_shape (gfc_expr
*source
, gfc_expr
*kind
)
4462 if (source
->rank
== 0 || source
->expr_type
!= EXPR_VARIABLE
)
4465 ar
= gfc_find_array_ref (source
);
4467 if (ar
->as
&& ar
->as
->type
== AS_ASSUMED_SIZE
&& ar
->type
== AR_FULL
)
4469 gfc_error ("%<source%> argument of %<shape%> intrinsic at %L must not be "
4470 "an assumed size array", &source
->where
);
4474 if (!kind_check (kind
, 1, BT_INTEGER
))
4476 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
4477 "with KIND argument at %L",
4478 gfc_current_intrinsic
, &kind
->where
))
4486 gfc_check_shift (gfc_expr
*i
, gfc_expr
*shift
)
4488 if (!type_check (i
, 0, BT_INTEGER
))
4491 if (!type_check (shift
, 0, BT_INTEGER
))
4494 if (!nonnegative_check ("SHIFT", shift
))
4497 if (!less_than_bitsize1 ("I", i
, "SHIFT", shift
, true))
4505 gfc_check_sign (gfc_expr
*a
, gfc_expr
*b
)
4507 if (!int_or_real_check (a
, 0))
4510 if (!same_type_check (a
, 0, b
, 1))
4518 gfc_check_size (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
4520 if (!array_check (array
, 0))
4523 if (!dim_check (dim
, 1, true))
4526 if (!dim_rank_check (dim
, array
, 0))
4529 if (!kind_check (kind
, 2, BT_INTEGER
))
4531 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
4532 "with KIND argument at %L",
4533 gfc_current_intrinsic
, &kind
->where
))
4542 gfc_check_sizeof (gfc_expr
*arg
)
4544 if (arg
->ts
.type
== BT_PROCEDURE
)
4546 gfc_error ("%qs argument of %qs intrinsic at %L shall not be a procedure",
4547 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4552 /* TYPE(*) is acceptable if and only if it uses an array descriptor. */
4553 if (arg
->ts
.type
== BT_ASSUMED
4554 && (arg
->symtree
->n
.sym
->as
== NULL
4555 || (arg
->symtree
->n
.sym
->as
->type
!= AS_ASSUMED_SHAPE
4556 && arg
->symtree
->n
.sym
->as
->type
!= AS_DEFERRED
4557 && arg
->symtree
->n
.sym
->as
->type
!= AS_ASSUMED_RANK
)))
4559 gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
4560 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4565 if (arg
->rank
&& arg
->expr_type
== EXPR_VARIABLE
4566 && arg
->symtree
->n
.sym
->as
!= NULL
4567 && arg
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
&& arg
->ref
4568 && arg
->ref
->type
== REF_ARRAY
&& arg
->ref
->u
.ar
.type
== AR_FULL
)
4570 gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
4571 "assumed-size array", gfc_current_intrinsic_arg
[0]->name
,
4572 gfc_current_intrinsic
, &arg
->where
);
4580 /* Check whether an expression is interoperable. When returning false,
4581 msg is set to a string telling why the expression is not interoperable,
4582 otherwise, it is set to NULL. The msg string can be used in diagnostics.
4583 If c_loc is true, character with len > 1 are allowed (cf. Fortran
4584 2003corr5); additionally, assumed-shape/assumed-rank/deferred-shape
4585 arrays are permitted. And if c_f_ptr is true, deferred-shape arrays
4589 is_c_interoperable (gfc_expr
*expr
, const char **msg
, bool c_loc
, bool c_f_ptr
)
4593 if (expr
->ts
.type
== BT_CLASS
)
4595 *msg
= "Expression is polymorphic";
4599 if (expr
->ts
.type
== BT_DERIVED
&& !expr
->ts
.u
.derived
->attr
.is_bind_c
4600 && !expr
->ts
.u
.derived
->ts
.is_iso_c
)
4602 *msg
= "Expression is a noninteroperable derived type";
4606 if (expr
->ts
.type
== BT_PROCEDURE
)
4608 *msg
= "Procedure unexpected as argument";
4612 if (gfc_notification_std (GFC_STD_GNU
) && expr
->ts
.type
== BT_LOGICAL
)
4615 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
4616 if (gfc_logical_kinds
[i
].kind
== expr
->ts
.kind
)
4618 *msg
= "Extension to use a non-C_Bool-kind LOGICAL";
4622 if (gfc_notification_std (GFC_STD_GNU
) && expr
->ts
.type
== BT_CHARACTER
4623 && expr
->ts
.kind
!= 1)
4625 *msg
= "Extension to use a non-C_CHAR-kind CHARACTER";
4629 if (expr
->ts
.type
== BT_CHARACTER
) {
4630 if (expr
->ts
.deferred
)
4632 /* TS 29113 allows deferred-length strings as dummy arguments,
4633 but it is not an interoperable type. */
4634 *msg
= "Expression shall not be a deferred-length string";
4638 if (expr
->ts
.u
.cl
&& expr
->ts
.u
.cl
->length
4639 && !gfc_simplify_expr (expr
->ts
.u
.cl
->length
, 0))
4640 gfc_internal_error ("is_c_interoperable(): gfc_simplify_expr failed");
4642 if (!c_loc
&& expr
->ts
.u
.cl
4643 && (!expr
->ts
.u
.cl
->length
4644 || expr
->ts
.u
.cl
->length
->expr_type
!= EXPR_CONSTANT
4645 || mpz_cmp_si (expr
->ts
.u
.cl
->length
->value
.integer
, 1) != 0))
4647 *msg
= "Type shall have a character length of 1";
4652 /* Note: The following checks are about interoperatable variables, Fortran
4653 15.3.5/15.3.6. In intrinsics like C_LOC or in procedure interface, more
4654 is allowed, e.g. assumed-shape arrays with TS 29113. */
4656 if (gfc_is_coarray (expr
))
4658 *msg
= "Coarrays are not interoperable";
4662 if (!c_loc
&& expr
->rank
> 0 && expr
->expr_type
!= EXPR_ARRAY
)
4664 gfc_array_ref
*ar
= gfc_find_array_ref (expr
);
4665 if (ar
->type
!= AR_FULL
)
4667 *msg
= "Only whole-arrays are interoperable";
4670 if (!c_f_ptr
&& ar
->as
->type
!= AS_EXPLICIT
4671 && ar
->as
->type
!= AS_ASSUMED_SIZE
)
4673 *msg
= "Only explicit-size and assumed-size arrays are interoperable";
4683 gfc_check_c_sizeof (gfc_expr
*arg
)
4687 if (!is_c_interoperable (arg
, &msg
, false, false))
4689 gfc_error ("%qs argument of %qs intrinsic at %L must be an "
4690 "interoperable data entity: %s",
4691 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4696 if (arg
->ts
.type
== BT_ASSUMED
)
4698 gfc_error ("%qs argument of %qs intrinsic at %L shall not be "
4700 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
4705 if (arg
->rank
&& arg
->expr_type
== EXPR_VARIABLE
4706 && arg
->symtree
->n
.sym
->as
!= NULL
4707 && arg
->symtree
->n
.sym
->as
->type
== AS_ASSUMED_SIZE
&& arg
->ref
4708 && arg
->ref
->type
== REF_ARRAY
&& arg
->ref
->u
.ar
.type
== AR_FULL
)
4710 gfc_error ("%qs argument of %qs intrinsic at %L shall not be an "
4711 "assumed-size array", gfc_current_intrinsic_arg
[0]->name
,
4712 gfc_current_intrinsic
, &arg
->where
);
4721 gfc_check_c_associated (gfc_expr
*c_ptr_1
, gfc_expr
*c_ptr_2
)
4723 if (c_ptr_1
->ts
.type
!= BT_DERIVED
4724 || c_ptr_1
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
4725 || (c_ptr_1
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_PTR
4726 && c_ptr_1
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_FUNPTR
))
4728 gfc_error ("Argument C_PTR_1 at %L to C_ASSOCIATED shall have the "
4729 "type TYPE(C_PTR) or TYPE(C_FUNPTR)", &c_ptr_1
->where
);
4733 if (!scalar_check (c_ptr_1
, 0))
4737 && (c_ptr_2
->ts
.type
!= BT_DERIVED
4738 || c_ptr_2
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
4739 || (c_ptr_1
->ts
.u
.derived
->intmod_sym_id
4740 != c_ptr_2
->ts
.u
.derived
->intmod_sym_id
)))
4742 gfc_error ("Argument C_PTR_2 at %L to C_ASSOCIATED shall have the "
4743 "same type as C_PTR_1: %s instead of %s", &c_ptr_1
->where
,
4744 gfc_typename (&c_ptr_1
->ts
),
4745 gfc_typename (&c_ptr_2
->ts
));
4749 if (c_ptr_2
&& !scalar_check (c_ptr_2
, 1))
4757 gfc_check_c_f_pointer (gfc_expr
*cptr
, gfc_expr
*fptr
, gfc_expr
*shape
)
4759 symbol_attribute attr
;
4762 if (cptr
->ts
.type
!= BT_DERIVED
4763 || cptr
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
4764 || cptr
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_PTR
)
4766 gfc_error ("Argument CPTR at %L to C_F_POINTER shall have the "
4767 "type TYPE(C_PTR)", &cptr
->where
);
4771 if (!scalar_check (cptr
, 0))
4774 attr
= gfc_expr_attr (fptr
);
4778 gfc_error ("Argument FPTR at %L to C_F_POINTER must be a pointer",
4783 if (fptr
->ts
.type
== BT_CLASS
)
4785 gfc_error ("FPTR argument at %L to C_F_POINTER shall not be polymorphic",
4790 if (gfc_is_coindexed (fptr
))
4792 gfc_error ("Argument FPTR at %L to C_F_POINTER shall not be "
4793 "coindexed", &fptr
->where
);
4797 if (fptr
->rank
== 0 && shape
)
4799 gfc_error ("Unexpected SHAPE argument at %L to C_F_POINTER with scalar "
4800 "FPTR", &fptr
->where
);
4803 else if (fptr
->rank
&& !shape
)
4805 gfc_error ("Expected SHAPE argument to C_F_POINTER with array "
4806 "FPTR at %L", &fptr
->where
);
4810 if (shape
&& !rank_check (shape
, 2, 1))
4813 if (shape
&& !type_check (shape
, 2, BT_INTEGER
))
4819 if (gfc_array_size (shape
, &size
))
4821 if (mpz_cmp_ui (size
, fptr
->rank
) != 0)
4824 gfc_error ("SHAPE argument at %L to C_F_POINTER must have the same "
4825 "size as the RANK of FPTR", &shape
->where
);
4832 if (fptr
->ts
.type
== BT_CLASS
)
4834 gfc_error ("Polymorphic FPTR at %L to C_F_POINTER", &fptr
->where
);
4838 if (fptr
->rank
> 0 && !is_c_interoperable (fptr
, &msg
, false, true))
4839 return gfc_notify_std (GFC_STD_F2018
, "Noninteroperable array FPTR "
4840 "at %L to C_F_POINTER: %s", &fptr
->where
, msg
);
4847 gfc_check_c_f_procpointer (gfc_expr
*cptr
, gfc_expr
*fptr
)
4849 symbol_attribute attr
;
4851 if (cptr
->ts
.type
!= BT_DERIVED
4852 || cptr
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_C_BINDING
4853 || cptr
->ts
.u
.derived
->intmod_sym_id
!= ISOCBINDING_FUNPTR
)
4855 gfc_error ("Argument CPTR at %L to C_F_PROCPOINTER shall have the "
4856 "type TYPE(C_FUNPTR)", &cptr
->where
);
4860 if (!scalar_check (cptr
, 0))
4863 attr
= gfc_expr_attr (fptr
);
4865 if (!attr
.proc_pointer
)
4867 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall be a procedure "
4868 "pointer", &fptr
->where
);
4872 if (gfc_is_coindexed (fptr
))
4874 gfc_error ("Argument FPTR at %L to C_F_PROCPOINTER shall not be "
4875 "coindexed", &fptr
->where
);
4879 if (!attr
.is_bind_c
)
4880 return gfc_notify_std (GFC_STD_F2018
, "Noninteroperable procedure "
4881 "pointer at %L to C_F_PROCPOINTER", &fptr
->where
);
4888 gfc_check_c_funloc (gfc_expr
*x
)
4890 symbol_attribute attr
;
4892 if (gfc_is_coindexed (x
))
4894 gfc_error ("Argument X at %L to C_FUNLOC shall not be "
4895 "coindexed", &x
->where
);
4899 attr
= gfc_expr_attr (x
);
4901 if (attr
.function
&& !attr
.proc_pointer
&& x
->expr_type
== EXPR_VARIABLE
4902 && x
->symtree
->n
.sym
== x
->symtree
->n
.sym
->result
)
4904 gfc_namespace
*ns
= gfc_current_ns
;
4906 for (ns
= gfc_current_ns
; ns
; ns
= ns
->parent
)
4907 if (x
->symtree
->n
.sym
== ns
->proc_name
)
4909 gfc_error ("Function result %qs at %L is invalid as X argument "
4910 "to C_FUNLOC", x
->symtree
->n
.sym
->name
, &x
->where
);
4915 if (attr
.flavor
!= FL_PROCEDURE
)
4917 gfc_error ("Argument X at %L to C_FUNLOC shall be a procedure "
4918 "or a procedure pointer", &x
->where
);
4922 if (!attr
.is_bind_c
)
4923 return gfc_notify_std (GFC_STD_F2018
, "Noninteroperable procedure "
4924 "at %L to C_FUNLOC", &x
->where
);
4930 gfc_check_c_loc (gfc_expr
*x
)
4932 symbol_attribute attr
;
4935 if (gfc_is_coindexed (x
))
4937 gfc_error ("Argument X at %L to C_LOC shall not be coindexed", &x
->where
);
4941 if (x
->ts
.type
== BT_CLASS
)
4943 gfc_error ("X argument at %L to C_LOC shall not be polymorphic",
4948 attr
= gfc_expr_attr (x
);
4951 && (x
->expr_type
!= EXPR_VARIABLE
|| !attr
.target
4952 || attr
.flavor
== FL_PARAMETER
))
4954 gfc_error ("Argument X at %L to C_LOC shall have either "
4955 "the POINTER or the TARGET attribute", &x
->where
);
4959 if (x
->ts
.type
== BT_CHARACTER
4960 && gfc_var_strlen (x
) == 0)
4962 gfc_error ("Argument X at %L to C_LOC shall be not be a zero-sized "
4963 "string", &x
->where
);
4967 if (!is_c_interoperable (x
, &msg
, true, false))
4969 if (x
->ts
.type
== BT_CLASS
)
4971 gfc_error ("Argument at %L to C_LOC shall not be polymorphic",
4977 && !gfc_notify_std (GFC_STD_F2018
,
4978 "Noninteroperable array at %L as"
4979 " argument to C_LOC: %s", &x
->where
, msg
))
4982 else if (x
->rank
> 0 && gfc_notification_std (GFC_STD_F2008
))
4984 gfc_array_ref
*ar
= gfc_find_array_ref (x
);
4986 if (ar
->as
->type
!= AS_EXPLICIT
&& ar
->as
->type
!= AS_ASSUMED_SIZE
4987 && !attr
.allocatable
4988 && !gfc_notify_std (GFC_STD_F2008
,
4989 "Array of interoperable type at %L "
4990 "to C_LOC which is nonallocatable and neither "
4991 "assumed size nor explicit size", &x
->where
))
4993 else if (ar
->type
!= AR_FULL
4994 && !gfc_notify_std (GFC_STD_F2008
, "Array section at %L "
4995 "to C_LOC", &x
->where
))
5004 gfc_check_sleep_sub (gfc_expr
*seconds
)
5006 if (!type_check (seconds
, 0, BT_INTEGER
))
5009 if (!scalar_check (seconds
, 0))
5016 gfc_check_sngl (gfc_expr
*a
)
5018 if (!type_check (a
, 0, BT_REAL
))
5021 if ((a
->ts
.kind
!= gfc_default_double_kind
)
5022 && !gfc_notify_std (GFC_STD_GNU
, "non double precision "
5023 "REAL argument to %s intrinsic at %L",
5024 gfc_current_intrinsic
, &a
->where
))
5031 gfc_check_spread (gfc_expr
*source
, gfc_expr
*dim
, gfc_expr
*ncopies
)
5033 if (source
->rank
>= GFC_MAX_DIMENSIONS
)
5035 gfc_error ("%qs argument of %qs intrinsic at %L must be less "
5036 "than rank %d", gfc_current_intrinsic_arg
[0]->name
,
5037 gfc_current_intrinsic
, &source
->where
, GFC_MAX_DIMENSIONS
);
5045 if (!dim_check (dim
, 1, false))
5048 /* dim_rank_check() does not apply here. */
5050 && dim
->expr_type
== EXPR_CONSTANT
5051 && (mpz_cmp_ui (dim
->value
.integer
, 1) < 0
5052 || mpz_cmp_ui (dim
->value
.integer
, source
->rank
+ 1) > 0))
5054 gfc_error ("%qs argument of %qs intrinsic at %L is not a valid "
5055 "dimension index", gfc_current_intrinsic_arg
[1]->name
,
5056 gfc_current_intrinsic
, &dim
->where
);
5060 if (!type_check (ncopies
, 2, BT_INTEGER
))
5063 if (!scalar_check (ncopies
, 2))
5070 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
5074 gfc_check_fgetputc_sub (gfc_expr
*unit
, gfc_expr
*c
, gfc_expr
*status
)
5076 if (!type_check (unit
, 0, BT_INTEGER
))
5079 if (!scalar_check (unit
, 0))
5082 if (!type_check (c
, 1, BT_CHARACTER
))
5084 if (!kind_value_check (c
, 1, gfc_default_character_kind
))
5090 if (!type_check (status
, 2, BT_INTEGER
)
5091 || !kind_value_check (status
, 2, gfc_default_integer_kind
)
5092 || !scalar_check (status
, 2))
5100 gfc_check_fgetputc (gfc_expr
*unit
, gfc_expr
*c
)
5102 return gfc_check_fgetputc_sub (unit
, c
, NULL
);
5107 gfc_check_fgetput_sub (gfc_expr
*c
, gfc_expr
*status
)
5109 if (!type_check (c
, 0, BT_CHARACTER
))
5111 if (!kind_value_check (c
, 0, gfc_default_character_kind
))
5117 if (!type_check (status
, 1, BT_INTEGER
)
5118 || !kind_value_check (status
, 1, gfc_default_integer_kind
)
5119 || !scalar_check (status
, 1))
5127 gfc_check_fgetput (gfc_expr
*c
)
5129 return gfc_check_fgetput_sub (c
, NULL
);
5134 gfc_check_fseek_sub (gfc_expr
*unit
, gfc_expr
*offset
, gfc_expr
*whence
, gfc_expr
*status
)
5136 if (!type_check (unit
, 0, BT_INTEGER
))
5139 if (!scalar_check (unit
, 0))
5142 if (!type_check (offset
, 1, BT_INTEGER
))
5145 if (!scalar_check (offset
, 1))
5148 if (!type_check (whence
, 2, BT_INTEGER
))
5151 if (!scalar_check (whence
, 2))
5157 if (!type_check (status
, 3, BT_INTEGER
))
5160 if (!kind_value_check (status
, 3, 4))
5163 if (!scalar_check (status
, 3))
5172 gfc_check_fstat (gfc_expr
*unit
, gfc_expr
*array
)
5174 if (!type_check (unit
, 0, BT_INTEGER
))
5177 if (!scalar_check (unit
, 0))
5180 if (!type_check (array
, 1, BT_INTEGER
)
5181 || !kind_value_check (unit
, 0, gfc_default_integer_kind
))
5184 if (!array_check (array
, 1))
5192 gfc_check_fstat_sub (gfc_expr
*unit
, gfc_expr
*array
, gfc_expr
*status
)
5194 if (!type_check (unit
, 0, BT_INTEGER
))
5197 if (!scalar_check (unit
, 0))
5200 if (!type_check (array
, 1, BT_INTEGER
)
5201 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
5204 if (!array_check (array
, 1))
5210 if (!type_check (status
, 2, BT_INTEGER
)
5211 || !kind_value_check (status
, 2, gfc_default_integer_kind
))
5214 if (!scalar_check (status
, 2))
5222 gfc_check_ftell (gfc_expr
*unit
)
5224 if (!type_check (unit
, 0, BT_INTEGER
))
5227 if (!scalar_check (unit
, 0))
5235 gfc_check_ftell_sub (gfc_expr
*unit
, gfc_expr
*offset
)
5237 if (!type_check (unit
, 0, BT_INTEGER
))
5240 if (!scalar_check (unit
, 0))
5243 if (!type_check (offset
, 1, BT_INTEGER
))
5246 if (!scalar_check (offset
, 1))
5254 gfc_check_stat (gfc_expr
*name
, gfc_expr
*array
)
5256 if (!type_check (name
, 0, BT_CHARACTER
))
5258 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
5261 if (!type_check (array
, 1, BT_INTEGER
)
5262 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
5265 if (!array_check (array
, 1))
5273 gfc_check_stat_sub (gfc_expr
*name
, gfc_expr
*array
, gfc_expr
*status
)
5275 if (!type_check (name
, 0, BT_CHARACTER
))
5277 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
5280 if (!type_check (array
, 1, BT_INTEGER
)
5281 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
5284 if (!array_check (array
, 1))
5290 if (!type_check (status
, 2, BT_INTEGER
)
5291 || !kind_value_check (array
, 1, gfc_default_integer_kind
))
5294 if (!scalar_check (status
, 2))
5302 gfc_check_image_index (gfc_expr
*coarray
, gfc_expr
*sub
)
5306 if (flag_coarray
== GFC_FCOARRAY_NONE
)
5308 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5312 if (!coarray_check (coarray
, 0))
5317 gfc_error ("%s argument to IMAGE_INDEX must be a rank one array at %L",
5318 gfc_current_intrinsic_arg
[1]->name
, &sub
->where
);
5322 if (gfc_array_size (sub
, &nelems
))
5324 int corank
= gfc_get_corank (coarray
);
5326 if (mpz_cmp_ui (nelems
, corank
) != 0)
5328 gfc_error ("The number of array elements of the SUB argument to "
5329 "IMAGE_INDEX at %L shall be %d (corank) not %d",
5330 &sub
->where
, corank
, (int) mpz_get_si (nelems
));
5342 gfc_check_num_images (gfc_expr
*distance
, gfc_expr
*failed
)
5344 if (flag_coarray
== GFC_FCOARRAY_NONE
)
5346 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5352 if (!type_check (distance
, 0, BT_INTEGER
))
5355 if (!nonnegative_check ("DISTANCE", distance
))
5358 if (!scalar_check (distance
, 0))
5361 if (!gfc_notify_std (GFC_STD_F2018
, "DISTANCE= argument to "
5362 "NUM_IMAGES at %L", &distance
->where
))
5368 if (!type_check (failed
, 1, BT_LOGICAL
))
5371 if (!scalar_check (failed
, 1))
5374 if (!gfc_notify_std (GFC_STD_F2018
, "FAILED= argument to "
5375 "NUM_IMAGES at %L", &failed
->where
))
5384 gfc_check_team_number (gfc_expr
*team
)
5386 if (flag_coarray
== GFC_FCOARRAY_NONE
)
5388 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5394 if (team
->ts
.type
!= BT_DERIVED
5395 || team
->ts
.u
.derived
->from_intmod
!= INTMOD_ISO_FORTRAN_ENV
5396 || team
->ts
.u
.derived
->intmod_sym_id
!= ISOFORTRAN_TEAM_TYPE
)
5398 gfc_error ("TEAM argument at %L to the intrinsic TEAM_NUMBER "
5399 "shall be of type TEAM_TYPE", &team
->where
);
5411 gfc_check_this_image (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*distance
)
5413 if (flag_coarray
== GFC_FCOARRAY_NONE
)
5415 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5419 if (coarray
== NULL
&& dim
== NULL
&& distance
== NULL
)
5422 if (dim
!= NULL
&& coarray
== NULL
)
5424 gfc_error ("DIM argument without COARRAY argument not allowed for "
5425 "THIS_IMAGE intrinsic at %L", &dim
->where
);
5429 if (distance
&& (coarray
|| dim
))
5431 gfc_error ("The DISTANCE argument may not be specified together with the "
5432 "COARRAY or DIM argument in intrinsic at %L",
5437 /* Assume that we have "this_image (distance)". */
5438 if (coarray
&& !gfc_is_coarray (coarray
) && coarray
->ts
.type
== BT_INTEGER
)
5442 gfc_error ("Unexpected DIM argument with noncoarray argument at %L",
5451 if (!type_check (distance
, 2, BT_INTEGER
))
5454 if (!nonnegative_check ("DISTANCE", distance
))
5457 if (!scalar_check (distance
, 2))
5460 if (!gfc_notify_std (GFC_STD_F2018
, "DISTANCE= argument to "
5461 "THIS_IMAGE at %L", &distance
->where
))
5467 if (!coarray_check (coarray
, 0))
5472 if (!dim_check (dim
, 1, false))
5475 if (!dim_corank_check (dim
, coarray
))
5482 /* Calculate the sizes for transfer, used by gfc_check_transfer and also
5483 by gfc_simplify_transfer. Return false if we cannot do so. */
5486 gfc_calculate_transfer_sizes (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
,
5487 size_t *source_size
, size_t *result_size
,
5488 size_t *result_length_p
)
5490 size_t result_elt_size
;
5492 if (source
->expr_type
== EXPR_FUNCTION
)
5495 if (size
&& size
->expr_type
!= EXPR_CONSTANT
)
5498 /* Calculate the size of the source. */
5499 *source_size
= gfc_target_expr_size (source
);
5500 if (*source_size
== 0)
5503 /* Determine the size of the element. */
5504 result_elt_size
= gfc_element_size (mold
);
5505 if (result_elt_size
== 0)
5508 if (mold
->expr_type
== EXPR_ARRAY
|| mold
->rank
|| size
)
5513 result_length
= (size_t)mpz_get_ui (size
->value
.integer
);
5516 result_length
= *source_size
/ result_elt_size
;
5517 if (result_length
* result_elt_size
< *source_size
)
5521 *result_size
= result_length
* result_elt_size
;
5522 if (result_length_p
)
5523 *result_length_p
= result_length
;
5526 *result_size
= result_elt_size
;
5533 gfc_check_transfer (gfc_expr
*source
, gfc_expr
*mold
, gfc_expr
*size
)
5538 if (mold
->ts
.type
== BT_HOLLERITH
)
5540 gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L must not be"
5541 " %s", &mold
->where
, gfc_basic_typename (BT_HOLLERITH
));
5547 if (!type_check (size
, 2, BT_INTEGER
))
5550 if (!scalar_check (size
, 2))
5553 if (!nonoptional_check (size
, 2))
5557 if (!warn_surprising
)
5560 /* If we can't calculate the sizes, we cannot check any more.
5561 Return true for that case. */
5563 if (!gfc_calculate_transfer_sizes (source
, mold
, size
, &source_size
,
5564 &result_size
, NULL
))
5567 if (source_size
< result_size
)
5568 gfc_warning (OPT_Wsurprising
,
5569 "Intrinsic TRANSFER at %L has partly undefined result: "
5570 "source size %ld < result size %ld", &source
->where
,
5571 (long) source_size
, (long) result_size
);
5578 gfc_check_transpose (gfc_expr
*matrix
)
5580 if (!rank_check (matrix
, 0, 2))
5588 gfc_check_ubound (gfc_expr
*array
, gfc_expr
*dim
, gfc_expr
*kind
)
5590 if (!array_check (array
, 0))
5593 if (!dim_check (dim
, 1, false))
5596 if (!dim_rank_check (dim
, array
, 0))
5599 if (!kind_check (kind
, 2, BT_INTEGER
))
5601 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
5602 "with KIND argument at %L",
5603 gfc_current_intrinsic
, &kind
->where
))
5611 gfc_check_ucobound (gfc_expr
*coarray
, gfc_expr
*dim
, gfc_expr
*kind
)
5613 if (flag_coarray
== GFC_FCOARRAY_NONE
)
5615 gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to enable");
5619 if (!coarray_check (coarray
, 0))
5624 if (!dim_check (dim
, 1, false))
5627 if (!dim_corank_check (dim
, coarray
))
5631 if (!kind_check (kind
, 2, BT_INTEGER
))
5639 gfc_check_unpack (gfc_expr
*vector
, gfc_expr
*mask
, gfc_expr
*field
)
5643 if (!rank_check (vector
, 0, 1))
5646 if (!array_check (mask
, 1))
5649 if (!type_check (mask
, 1, BT_LOGICAL
))
5652 if (!same_type_check (vector
, 0, field
, 2))
5655 if (mask
->expr_type
== EXPR_ARRAY
5656 && gfc_array_size (vector
, &vector_size
))
5658 int mask_true_count
= 0;
5659 gfc_constructor
*mask_ctor
;
5660 mask_ctor
= gfc_constructor_first (mask
->value
.constructor
);
5663 if (mask_ctor
->expr
->expr_type
!= EXPR_CONSTANT
)
5665 mask_true_count
= 0;
5669 if (mask_ctor
->expr
->value
.logical
)
5672 mask_ctor
= gfc_constructor_next (mask_ctor
);
5675 if (mpz_get_si (vector_size
) < mask_true_count
)
5677 gfc_error ("%qs argument of %qs intrinsic at %L must "
5678 "provide at least as many elements as there "
5679 "are .TRUE. values in %qs (%ld/%d)",
5680 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
5681 &vector
->where
, gfc_current_intrinsic_arg
[1]->name
,
5682 mpz_get_si (vector_size
), mask_true_count
);
5686 mpz_clear (vector_size
);
5689 if (mask
->rank
!= field
->rank
&& field
->rank
!= 0)
5691 gfc_error ("%qs argument of %qs intrinsic at %L must have "
5692 "the same rank as %qs or be a scalar",
5693 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
5694 &field
->where
, gfc_current_intrinsic_arg
[1]->name
);
5698 if (mask
->rank
== field
->rank
)
5701 for (i
= 0; i
< field
->rank
; i
++)
5702 if (! identical_dimen_shape (mask
, i
, field
, i
))
5704 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L "
5705 "must have identical shape.",
5706 gfc_current_intrinsic_arg
[2]->name
,
5707 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
5717 gfc_check_verify (gfc_expr
*x
, gfc_expr
*y
, gfc_expr
*z
, gfc_expr
*kind
)
5719 if (!type_check (x
, 0, BT_CHARACTER
))
5722 if (!same_type_check (x
, 0, y
, 1))
5725 if (z
!= NULL
&& !type_check (z
, 2, BT_LOGICAL
))
5728 if (!kind_check (kind
, 3, BT_INTEGER
))
5730 if (kind
&& !gfc_notify_std (GFC_STD_F2003
, "%qs intrinsic "
5731 "with KIND argument at %L",
5732 gfc_current_intrinsic
, &kind
->where
))
5740 gfc_check_trim (gfc_expr
*x
)
5742 if (!type_check (x
, 0, BT_CHARACTER
))
5745 if (!scalar_check (x
, 0))
5753 gfc_check_ttynam (gfc_expr
*unit
)
5755 if (!scalar_check (unit
, 0))
5758 if (!type_check (unit
, 0, BT_INTEGER
))
5765 /************* Check functions for intrinsic subroutines *************/
5768 gfc_check_cpu_time (gfc_expr
*time
)
5770 if (!scalar_check (time
, 0))
5773 if (!type_check (time
, 0, BT_REAL
))
5776 if (!variable_check (time
, 0, false))
5784 gfc_check_date_and_time (gfc_expr
*date
, gfc_expr
*time
,
5785 gfc_expr
*zone
, gfc_expr
*values
)
5789 if (!type_check (date
, 0, BT_CHARACTER
))
5791 if (!kind_value_check (date
, 0, gfc_default_character_kind
))
5793 if (!scalar_check (date
, 0))
5795 if (!variable_check (date
, 0, false))
5801 if (!type_check (time
, 1, BT_CHARACTER
))
5803 if (!kind_value_check (time
, 1, gfc_default_character_kind
))
5805 if (!scalar_check (time
, 1))
5807 if (!variable_check (time
, 1, false))
5813 if (!type_check (zone
, 2, BT_CHARACTER
))
5815 if (!kind_value_check (zone
, 2, gfc_default_character_kind
))
5817 if (!scalar_check (zone
, 2))
5819 if (!variable_check (zone
, 2, false))
5825 if (!type_check (values
, 3, BT_INTEGER
))
5827 if (!array_check (values
, 3))
5829 if (!rank_check (values
, 3, 1))
5831 if (!variable_check (values
, 3, false))
5840 gfc_check_mvbits (gfc_expr
*from
, gfc_expr
*frompos
, gfc_expr
*len
,
5841 gfc_expr
*to
, gfc_expr
*topos
)
5843 if (!type_check (from
, 0, BT_INTEGER
))
5846 if (!type_check (frompos
, 1, BT_INTEGER
))
5849 if (!type_check (len
, 2, BT_INTEGER
))
5852 if (!same_type_check (from
, 0, to
, 3))
5855 if (!variable_check (to
, 3, false))
5858 if (!type_check (topos
, 4, BT_INTEGER
))
5861 if (!nonnegative_check ("frompos", frompos
))
5864 if (!nonnegative_check ("topos", topos
))
5867 if (!nonnegative_check ("len", len
))
5870 if (!less_than_bitsize2 ("from", from
, "frompos", frompos
, "len", len
))
5873 if (!less_than_bitsize2 ("to", to
, "topos", topos
, "len", len
))
5880 /* Check the arguments for RANDOM_INIT. */
5883 gfc_check_random_init (gfc_expr
*repeatable
, gfc_expr
*image_distinct
)
5885 if (!type_check (repeatable
, 0, BT_LOGICAL
))
5888 if (!scalar_check (repeatable
, 0))
5891 if (!type_check (image_distinct
, 1, BT_LOGICAL
))
5894 if (!scalar_check (image_distinct
, 1))
5902 gfc_check_random_number (gfc_expr
*harvest
)
5904 if (!type_check (harvest
, 0, BT_REAL
))
5907 if (!variable_check (harvest
, 0, false))
5915 gfc_check_random_seed (gfc_expr
*size
, gfc_expr
*put
, gfc_expr
*get
)
5917 unsigned int nargs
= 0, seed_size
;
5918 locus
*where
= NULL
;
5919 mpz_t put_size
, get_size
;
5921 /* Keep the number of bytes in sync with master_state in
5922 libgfortran/intrinsics/random.c. +1 due to the integer p which is
5923 part of the state too. */
5924 seed_size
= 128 / gfc_default_integer_kind
+ 1;
5928 if (size
->expr_type
!= EXPR_VARIABLE
5929 || !size
->symtree
->n
.sym
->attr
.optional
)
5932 if (!scalar_check (size
, 0))
5935 if (!type_check (size
, 0, BT_INTEGER
))
5938 if (!variable_check (size
, 0, false))
5941 if (!kind_value_check (size
, 0, gfc_default_integer_kind
))
5947 if (put
->expr_type
!= EXPR_VARIABLE
5948 || !put
->symtree
->n
.sym
->attr
.optional
)
5951 where
= &put
->where
;
5954 if (!array_check (put
, 1))
5957 if (!rank_check (put
, 1, 1))
5960 if (!type_check (put
, 1, BT_INTEGER
))
5963 if (!kind_value_check (put
, 1, gfc_default_integer_kind
))
5966 if (gfc_array_size (put
, &put_size
)
5967 && mpz_get_ui (put_size
) < seed_size
)
5968 gfc_error ("Size of %qs argument of %qs intrinsic at %L "
5969 "too small (%i/%i)",
5970 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
5971 where
, (int) mpz_get_ui (put_size
), seed_size
);
5976 if (get
->expr_type
!= EXPR_VARIABLE
5977 || !get
->symtree
->n
.sym
->attr
.optional
)
5980 where
= &get
->where
;
5983 if (!array_check (get
, 2))
5986 if (!rank_check (get
, 2, 1))
5989 if (!type_check (get
, 2, BT_INTEGER
))
5992 if (!variable_check (get
, 2, false))
5995 if (!kind_value_check (get
, 2, gfc_default_integer_kind
))
5998 if (gfc_array_size (get
, &get_size
)
5999 && mpz_get_ui (get_size
) < seed_size
)
6000 gfc_error ("Size of %qs argument of %qs intrinsic at %L "
6001 "too small (%i/%i)",
6002 gfc_current_intrinsic_arg
[2]->name
, gfc_current_intrinsic
,
6003 where
, (int) mpz_get_ui (get_size
), seed_size
);
6006 /* RANDOM_SEED may not have more than one non-optional argument. */
6008 gfc_error ("Too many arguments to %s at %L", gfc_current_intrinsic
, where
);
6014 gfc_check_fe_runtime_error (gfc_actual_arglist
*a
)
6018 int num_percent
, nargs
;
6021 if (e
->expr_type
!= EXPR_CONSTANT
)
6024 len
= e
->value
.character
.length
;
6025 if (e
->value
.character
.string
[len
-1] != '\0')
6026 gfc_internal_error ("fe_runtime_error string must be null terminated");
6029 for (i
=0; i
<len
-1; i
++)
6030 if (e
->value
.character
.string
[i
] == '%')
6034 for (; a
; a
= a
->next
)
6037 if (nargs
-1 != num_percent
)
6038 gfc_internal_error ("fe_runtime_error: Wrong number of arguments (%d instead of %d)",
6039 nargs
, num_percent
++);
6045 gfc_check_second_sub (gfc_expr
*time
)
6047 if (!scalar_check (time
, 0))
6050 if (!type_check (time
, 0, BT_REAL
))
6053 if (!kind_value_check (time
, 0, 4))
6060 /* COUNT and COUNT_MAX of SYSTEM_CLOCK are scalar, default-kind integer
6061 variables in Fortran 95. In Fortran 2003 and later, they can be of any
6062 kind, and COUNT_RATE can be of type real. Note, count, count_rate, and
6063 count_max are all optional arguments */
6066 gfc_check_system_clock (gfc_expr
*count
, gfc_expr
*count_rate
,
6067 gfc_expr
*count_max
)
6071 if (!scalar_check (count
, 0))
6074 if (!type_check (count
, 0, BT_INTEGER
))
6077 if (count
->ts
.kind
!= gfc_default_integer_kind
6078 && !gfc_notify_std (GFC_STD_F2003
, "COUNT argument to "
6079 "SYSTEM_CLOCK at %L has non-default kind",
6083 if (!variable_check (count
, 0, false))
6087 if (count_rate
!= NULL
)
6089 if (!scalar_check (count_rate
, 1))
6092 if (!variable_check (count_rate
, 1, false))
6095 if (count_rate
->ts
.type
== BT_REAL
)
6097 if (!gfc_notify_std (GFC_STD_F2003
, "Real COUNT_RATE argument to "
6098 "SYSTEM_CLOCK at %L", &count_rate
->where
))
6103 if (!type_check (count_rate
, 1, BT_INTEGER
))
6106 if (count_rate
->ts
.kind
!= gfc_default_integer_kind
6107 && !gfc_notify_std (GFC_STD_F2003
, "COUNT_RATE argument to "
6108 "SYSTEM_CLOCK at %L has non-default kind",
6109 &count_rate
->where
))
6115 if (count_max
!= NULL
)
6117 if (!scalar_check (count_max
, 2))
6120 if (!type_check (count_max
, 2, BT_INTEGER
))
6123 if (count_max
->ts
.kind
!= gfc_default_integer_kind
6124 && !gfc_notify_std (GFC_STD_F2003
, "COUNT_MAX argument to "
6125 "SYSTEM_CLOCK at %L has non-default kind",
6129 if (!variable_check (count_max
, 2, false))
6138 gfc_check_irand (gfc_expr
*x
)
6143 if (!scalar_check (x
, 0))
6146 if (!type_check (x
, 0, BT_INTEGER
))
6149 if (!kind_value_check (x
, 0, 4))
6157 gfc_check_alarm_sub (gfc_expr
*seconds
, gfc_expr
*handler
, gfc_expr
*status
)
6159 if (!scalar_check (seconds
, 0))
6161 if (!type_check (seconds
, 0, BT_INTEGER
))
6164 if (!int_or_proc_check (handler
, 1))
6166 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
6172 if (!scalar_check (status
, 2))
6174 if (!type_check (status
, 2, BT_INTEGER
))
6176 if (!kind_value_check (status
, 2, gfc_default_integer_kind
))
6184 gfc_check_rand (gfc_expr
*x
)
6189 if (!scalar_check (x
, 0))
6192 if (!type_check (x
, 0, BT_INTEGER
))
6195 if (!kind_value_check (x
, 0, 4))
6203 gfc_check_srand (gfc_expr
*x
)
6205 if (!scalar_check (x
, 0))
6208 if (!type_check (x
, 0, BT_INTEGER
))
6211 if (!kind_value_check (x
, 0, 4))
6219 gfc_check_ctime_sub (gfc_expr
*time
, gfc_expr
*result
)
6221 if (!scalar_check (time
, 0))
6223 if (!type_check (time
, 0, BT_INTEGER
))
6226 if (!type_check (result
, 1, BT_CHARACTER
))
6228 if (!kind_value_check (result
, 1, gfc_default_character_kind
))
6236 gfc_check_dtime_etime (gfc_expr
*x
)
6238 if (!array_check (x
, 0))
6241 if (!rank_check (x
, 0, 1))
6244 if (!variable_check (x
, 0, false))
6247 if (!type_check (x
, 0, BT_REAL
))
6250 if (!kind_value_check (x
, 0, 4))
6258 gfc_check_dtime_etime_sub (gfc_expr
*values
, gfc_expr
*time
)
6260 if (!array_check (values
, 0))
6263 if (!rank_check (values
, 0, 1))
6266 if (!variable_check (values
, 0, false))
6269 if (!type_check (values
, 0, BT_REAL
))
6272 if (!kind_value_check (values
, 0, 4))
6275 if (!scalar_check (time
, 1))
6278 if (!type_check (time
, 1, BT_REAL
))
6281 if (!kind_value_check (time
, 1, 4))
6289 gfc_check_fdate_sub (gfc_expr
*date
)
6291 if (!type_check (date
, 0, BT_CHARACTER
))
6293 if (!kind_value_check (date
, 0, gfc_default_character_kind
))
6301 gfc_check_gerror (gfc_expr
*msg
)
6303 if (!type_check (msg
, 0, BT_CHARACTER
))
6305 if (!kind_value_check (msg
, 0, gfc_default_character_kind
))
6313 gfc_check_getcwd_sub (gfc_expr
*cwd
, gfc_expr
*status
)
6315 if (!type_check (cwd
, 0, BT_CHARACTER
))
6317 if (!kind_value_check (cwd
, 0, gfc_default_character_kind
))
6323 if (!scalar_check (status
, 1))
6326 if (!type_check (status
, 1, BT_INTEGER
))
6334 gfc_check_getarg (gfc_expr
*pos
, gfc_expr
*value
)
6336 if (!type_check (pos
, 0, BT_INTEGER
))
6339 if (pos
->ts
.kind
> gfc_default_integer_kind
)
6341 gfc_error ("%qs argument of %qs intrinsic at %L must be of a kind "
6342 "not wider than the default kind (%d)",
6343 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
6344 &pos
->where
, gfc_default_integer_kind
);
6348 if (!type_check (value
, 1, BT_CHARACTER
))
6350 if (!kind_value_check (value
, 1, gfc_default_character_kind
))
6358 gfc_check_getlog (gfc_expr
*msg
)
6360 if (!type_check (msg
, 0, BT_CHARACTER
))
6362 if (!kind_value_check (msg
, 0, gfc_default_character_kind
))
6370 gfc_check_exit (gfc_expr
*status
)
6375 if (!type_check (status
, 0, BT_INTEGER
))
6378 if (!scalar_check (status
, 0))
6386 gfc_check_flush (gfc_expr
*unit
)
6391 if (!type_check (unit
, 0, BT_INTEGER
))
6394 if (!scalar_check (unit
, 0))
6402 gfc_check_free (gfc_expr
*i
)
6404 if (!type_check (i
, 0, BT_INTEGER
))
6407 if (!scalar_check (i
, 0))
6415 gfc_check_hostnm (gfc_expr
*name
)
6417 if (!type_check (name
, 0, BT_CHARACTER
))
6419 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
6427 gfc_check_hostnm_sub (gfc_expr
*name
, gfc_expr
*status
)
6429 if (!type_check (name
, 0, BT_CHARACTER
))
6431 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
6437 if (!scalar_check (status
, 1))
6440 if (!type_check (status
, 1, BT_INTEGER
))
6448 gfc_check_itime_idate (gfc_expr
*values
)
6450 if (!array_check (values
, 0))
6453 if (!rank_check (values
, 0, 1))
6456 if (!variable_check (values
, 0, false))
6459 if (!type_check (values
, 0, BT_INTEGER
))
6462 if (!kind_value_check (values
, 0, gfc_default_integer_kind
))
6470 gfc_check_ltime_gmtime (gfc_expr
*time
, gfc_expr
*values
)
6472 if (!type_check (time
, 0, BT_INTEGER
))
6475 if (!kind_value_check (time
, 0, gfc_default_integer_kind
))
6478 if (!scalar_check (time
, 0))
6481 if (!array_check (values
, 1))
6484 if (!rank_check (values
, 1, 1))
6487 if (!variable_check (values
, 1, false))
6490 if (!type_check (values
, 1, BT_INTEGER
))
6493 if (!kind_value_check (values
, 1, gfc_default_integer_kind
))
6501 gfc_check_ttynam_sub (gfc_expr
*unit
, gfc_expr
*name
)
6503 if (!scalar_check (unit
, 0))
6506 if (!type_check (unit
, 0, BT_INTEGER
))
6509 if (!type_check (name
, 1, BT_CHARACTER
))
6511 if (!kind_value_check (name
, 1, gfc_default_character_kind
))
6519 gfc_check_isatty (gfc_expr
*unit
)
6524 if (!type_check (unit
, 0, BT_INTEGER
))
6527 if (!scalar_check (unit
, 0))
6535 gfc_check_isnan (gfc_expr
*x
)
6537 if (!type_check (x
, 0, BT_REAL
))
6545 gfc_check_perror (gfc_expr
*string
)
6547 if (!type_check (string
, 0, BT_CHARACTER
))
6549 if (!kind_value_check (string
, 0, gfc_default_character_kind
))
6557 gfc_check_umask (gfc_expr
*mask
)
6559 if (!type_check (mask
, 0, BT_INTEGER
))
6562 if (!scalar_check (mask
, 0))
6570 gfc_check_umask_sub (gfc_expr
*mask
, gfc_expr
*old
)
6572 if (!type_check (mask
, 0, BT_INTEGER
))
6575 if (!scalar_check (mask
, 0))
6581 if (!scalar_check (old
, 1))
6584 if (!type_check (old
, 1, BT_INTEGER
))
6592 gfc_check_unlink (gfc_expr
*name
)
6594 if (!type_check (name
, 0, BT_CHARACTER
))
6596 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
6604 gfc_check_unlink_sub (gfc_expr
*name
, gfc_expr
*status
)
6606 if (!type_check (name
, 0, BT_CHARACTER
))
6608 if (!kind_value_check (name
, 0, gfc_default_character_kind
))
6614 if (!scalar_check (status
, 1))
6617 if (!type_check (status
, 1, BT_INTEGER
))
6625 gfc_check_signal (gfc_expr
*number
, gfc_expr
*handler
)
6627 if (!scalar_check (number
, 0))
6629 if (!type_check (number
, 0, BT_INTEGER
))
6632 if (!int_or_proc_check (handler
, 1))
6634 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
6642 gfc_check_signal_sub (gfc_expr
*number
, gfc_expr
*handler
, gfc_expr
*status
)
6644 if (!scalar_check (number
, 0))
6646 if (!type_check (number
, 0, BT_INTEGER
))
6649 if (!int_or_proc_check (handler
, 1))
6651 if (handler
->ts
.type
== BT_INTEGER
&& !scalar_check (handler
, 1))
6657 if (!type_check (status
, 2, BT_INTEGER
))
6659 if (!scalar_check (status
, 2))
6667 gfc_check_system_sub (gfc_expr
*cmd
, gfc_expr
*status
)
6669 if (!type_check (cmd
, 0, BT_CHARACTER
))
6671 if (!kind_value_check (cmd
, 0, gfc_default_character_kind
))
6674 if (!scalar_check (status
, 1))
6677 if (!type_check (status
, 1, BT_INTEGER
))
6680 if (!kind_value_check (status
, 1, gfc_default_integer_kind
))
6687 /* This is used for the GNU intrinsics AND, OR and XOR. */
6689 gfc_check_and (gfc_expr
*i
, gfc_expr
*j
)
6691 if (i
->ts
.type
!= BT_INTEGER
&& i
->ts
.type
!= BT_LOGICAL
)
6693 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
6694 "or LOGICAL", gfc_current_intrinsic_arg
[0]->name
,
6695 gfc_current_intrinsic
, &i
->where
);
6699 if (j
->ts
.type
!= BT_INTEGER
&& j
->ts
.type
!= BT_LOGICAL
)
6701 gfc_error ("%qs argument of %qs intrinsic at %L must be INTEGER "
6702 "or LOGICAL", gfc_current_intrinsic_arg
[1]->name
,
6703 gfc_current_intrinsic
, &j
->where
);
6707 if (i
->ts
.type
!= j
->ts
.type
)
6709 gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "
6710 "have the same type", gfc_current_intrinsic_arg
[0]->name
,
6711 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,
6716 if (!scalar_check (i
, 0))
6719 if (!scalar_check (j
, 1))
6727 gfc_check_storage_size (gfc_expr
*a
, gfc_expr
*kind
)
6730 if (a
->expr_type
== EXPR_NULL
)
6732 gfc_error ("Intrinsic function NULL at %L cannot be an actual "
6733 "argument to STORAGE_SIZE, because it returns a "
6734 "disassociated pointer", &a
->where
);
6738 if (a
->ts
.type
== BT_ASSUMED
)
6740 gfc_error ("%qs argument of %qs intrinsic at %L shall not be TYPE(*)",
6741 gfc_current_intrinsic_arg
[0]->name
, gfc_current_intrinsic
,
6746 if (a
->ts
.type
== BT_PROCEDURE
)
6748 gfc_error ("%qs argument of %qs intrinsic at %L shall not be a "
6749 "procedure", gfc_current_intrinsic_arg
[0]->name
,
6750 gfc_current_intrinsic
, &a
->where
);
6757 if (!type_check (kind
, 1, BT_INTEGER
))
6760 if (!scalar_check (kind
, 1))
6763 if (kind
->expr_type
!= EXPR_CONSTANT
)
6765 gfc_error ("%qs argument of %qs intrinsic at %L must be a constant",
6766 gfc_current_intrinsic_arg
[1]->name
, gfc_current_intrinsic
,